1d927a8b33
* WIP close.com app * Removing leaked dev key (now invalid) * Misspelled env variable * Making progress still WIP * Progress + tests * Final touches * More unit tests * Finished up tests * Merge main * Removing unneeded stuff + submodules * Removing static props, fields fix * Removing unneeded stuff p2 * Commenting * Refactoring Close.com Calendar Service + initial structure * Progress con CloseComService * Standarizing APIs * Zodifying * Expanding sync services * Sendgrid Sync Service * using own request for sendgrid + debug logs * Making get last booking work for console * Helpscout dynamic app API * Standarizing calls + adding call from booking creation * Strategy change for last booking * Strategy change for last booking on help scout api * Fixing failing build * Implementing user deletion * Fix linting + slight cleaning * Undoing eslint disable * Removing more unsupported eslint properties * Closecom as non-standard sync service * Finishing closecom lead operations * Fixing lint * Guarding app from sync services * Reverting submodules * Applying PR feedback * Reverting API to be plain handler * Cleaning notes Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> Co-authored-by: zomars <zomars@me.com>
96 lines
2.1 KiB
TypeScript
96 lines
2.1 KiB
TypeScript
// import { DeploymentType } from "@prisma/admin-client";
|
|
import { User } from "@prisma/client";
|
|
|
|
import logger from "@calcom/lib/logger";
|
|
import { default as webPrisma } from "@calcom/prisma";
|
|
|
|
export type UserInfo = {
|
|
email: string;
|
|
name: string | null;
|
|
id: number;
|
|
username: string | null;
|
|
createdDate: Date;
|
|
};
|
|
|
|
export type TeamInfoType = {
|
|
name: string | undefined | null;
|
|
};
|
|
|
|
export type WebUserInfoType = UserInfo & {
|
|
plan: User["plan"];
|
|
};
|
|
|
|
export type ConsoleUserInfoType = UserInfo & {
|
|
plan: "CLOUD" | "SELFHOSTED"; // DeploymentType;
|
|
};
|
|
|
|
export interface IUserDeletion<T> {
|
|
delete(info: T): Promise<any>;
|
|
}
|
|
|
|
export interface IUserCreation<T> {
|
|
create(info: T): Promise<any>;
|
|
update(info: T): Promise<any>;
|
|
upsert?: never;
|
|
}
|
|
|
|
export interface IUserUpsertion<T> {
|
|
create?: never;
|
|
update?: never;
|
|
upsert(info: T): Promise<any>;
|
|
}
|
|
|
|
export interface ISyncService {
|
|
ready(): boolean;
|
|
web: {
|
|
user: (IUserCreation<WebUserInfoType> | IUserUpsertion<WebUserInfoType>) & IUserDeletion<WebUserInfoType>;
|
|
};
|
|
console: {
|
|
user: IUserCreation<ConsoleUserInfoType> | IUserUpsertion<ConsoleUserInfoType>;
|
|
};
|
|
}
|
|
|
|
export default class SyncServiceCore {
|
|
protected serviceName: string;
|
|
protected service: any;
|
|
protected log: typeof logger;
|
|
|
|
constructor(serviceName: string, service: any, log: typeof logger) {
|
|
this.serviceName = serviceName;
|
|
this.log = log;
|
|
try {
|
|
this.service = new service();
|
|
} catch (e) {
|
|
this.log.warn("Couldn't instantiate sync service:", (e as Error).message);
|
|
}
|
|
}
|
|
|
|
ready() {
|
|
return this.service !== undefined;
|
|
}
|
|
|
|
async getUserLastBooking(user: { email: string }): Promise<{ booking: { createdAt: Date } | null } | null> {
|
|
return await webPrisma.attendee.findFirst({
|
|
where: {
|
|
email: user.email,
|
|
},
|
|
select: {
|
|
booking: {
|
|
select: {
|
|
createdAt: true,
|
|
},
|
|
},
|
|
},
|
|
orderBy: {
|
|
booking: {
|
|
createdAt: "desc",
|
|
},
|
|
},
|
|
});
|
|
}
|
|
}
|
|
|
|
export interface ISyncServices {
|
|
new (): ISyncService;
|
|
}
|