perf: Add CrmServiceMap (#19718)
* Generate crm apps map * Remove .tsx file * Use `CrmServiceMap` in `getCrm` * Remove unused types * Type fixes * Type fixes
This commit is contained in:
@@ -37,6 +37,7 @@ function generateFiles() {
|
||||
const schemasOutput = [];
|
||||
const appKeysSchemasOutput = [];
|
||||
const serverOutput = [];
|
||||
const crmOutput = [];
|
||||
const appDirs: { name: string; path: string }[] = [];
|
||||
|
||||
fs.readdirSync(`${APP_STORE_PATH}`).forEach(function (dir) {
|
||||
@@ -330,6 +331,20 @@ function generateFiles() {
|
||||
})
|
||||
);
|
||||
|
||||
crmOutput.push(
|
||||
...getExportedObject(
|
||||
"CrmServiceMap",
|
||||
{
|
||||
importConfig: {
|
||||
fileToBeImported: "lib/CrmService.ts",
|
||||
importName: "default",
|
||||
},
|
||||
lazyImport: true,
|
||||
},
|
||||
isCrmApp
|
||||
)
|
||||
);
|
||||
|
||||
const banner = `/**
|
||||
This file is autogenerated using the command \`yarn app-store:build --watch\`.
|
||||
Don't modify this file manually.
|
||||
@@ -342,6 +357,7 @@ function generateFiles() {
|
||||
["apps.schemas.generated.ts", schemasOutput],
|
||||
["apps.keys-schemas.generated.ts", appKeysSchemasOutput],
|
||||
["bookerApps.metadata.generated.ts", bookerMetadataOutput],
|
||||
["crm.apps.generated.ts", crmOutput],
|
||||
];
|
||||
filesToGenerate.forEach(([fileName, output]) => {
|
||||
fs.writeFileSync(`${APP_STORE_PATH}/${fileName}`, formatOutput(`${banner}${output.join("\n")}`));
|
||||
@@ -385,3 +401,7 @@ function isBookerApp(app: App) {
|
||||
// 2. It is a tag manager app(e.g. Google Analytics, GTM, Fathom)
|
||||
return !!(app.appData?.location || app.appData?.tag);
|
||||
}
|
||||
|
||||
function isCrmApp(app: App) {
|
||||
return !!app.categories?.includes("crm");
|
||||
}
|
||||
|
||||
@@ -1,12 +1,7 @@
|
||||
import logger from "@calcom/lib/logger";
|
||||
import type { CredentialPayload } from "@calcom/types/Credential";
|
||||
import type { CRM } from "@calcom/types/CrmService";
|
||||
|
||||
import appStore from "..";
|
||||
|
||||
type Class<I, Args extends any[] = any[]> = new (...args: Args) => I;
|
||||
|
||||
type CrmClass = Class<CRM, [CredentialPayload, any]>;
|
||||
import { CrmServiceMap } from "../crm.apps.generated";
|
||||
|
||||
const log = logger.getSubLogger({ prefix: ["CrmManager"] });
|
||||
export const getCrm = async (credential: CredentialPayload, appOptions: any) => {
|
||||
@@ -15,19 +10,21 @@ export const getCrm = async (credential: CredentialPayload, appOptions: any) =>
|
||||
|
||||
const crmName = crmType.split("_")[0];
|
||||
|
||||
const crmAppImportFn = appStore[crmName as keyof typeof appStore];
|
||||
const crmServiceImportFn = await CrmServiceMap[crmName as keyof typeof CrmServiceMap];
|
||||
|
||||
if (!crmAppImportFn) {
|
||||
if (!crmServiceImportFn) {
|
||||
log.warn(`crm of type ${crmType} is not implemented`);
|
||||
return null;
|
||||
}
|
||||
|
||||
const crmApp = await crmAppImportFn();
|
||||
const CrmService = crmServiceImportFn.default;
|
||||
|
||||
if (crmApp && "lib" in crmApp && "CrmService" in crmApp.lib) {
|
||||
const CrmService = crmApp.lib.CrmService as CrmClass;
|
||||
return new CrmService(credential, appOptions);
|
||||
if (!CrmService) {
|
||||
log.warn(`crm of type ${crmType} is not implemented`);
|
||||
return null;
|
||||
}
|
||||
|
||||
return new CrmService(credential, appOptions);
|
||||
};
|
||||
|
||||
export default getCrm;
|
||||
|
||||
@@ -205,4 +205,8 @@ export default class CloseComCRMService implements CRM {
|
||||
getAppOptions() {
|
||||
console.log("No options implemented");
|
||||
}
|
||||
|
||||
async handleAttendeeNoShow() {
|
||||
console.log("Not implemented");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
/**
|
||||
This file is autogenerated using the command `yarn app-store:build --watch`.
|
||||
Don't modify this file manually.
|
||||
**/
|
||||
export const CrmServiceMap = {
|
||||
closecom: import("./closecom/lib/CrmService"),
|
||||
hubspot: import("./hubspot/lib/CrmService"),
|
||||
"pipedrive-crm": import("./pipedrive-crm/lib/CrmService"),
|
||||
salesforce: import("./salesforce/lib/CrmService"),
|
||||
"zoho-bigin": import("./zoho-bigin/lib/CrmService"),
|
||||
zohocrm: import("./zohocrm/lib/CrmService"),
|
||||
};
|
||||
@@ -273,4 +273,8 @@ export default class HubspotCalendarService implements CRM {
|
||||
getAppOptions() {
|
||||
console.log("No options implemented");
|
||||
}
|
||||
|
||||
async handleAttendeeNoShow() {
|
||||
console.log("Not implemented");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -234,4 +234,8 @@ export default class PipedriveCrmService implements CRM {
|
||||
getAppOptions() {
|
||||
console.log("No options implemented");
|
||||
}
|
||||
|
||||
async handleAttendeeNoShow() {
|
||||
console.log("Not implemented");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -293,6 +293,10 @@ export default class BiginCrmService implements CRM {
|
||||
getAppOptions() {
|
||||
console.log("No options implemented");
|
||||
}
|
||||
|
||||
async handleAttendeeNoShow() {
|
||||
console.log("Not implemented");
|
||||
}
|
||||
}
|
||||
|
||||
const toISO8601String = (date: Date) => {
|
||||
|
||||
@@ -293,4 +293,8 @@ export default class ZohoCrmCrmService implements CRM {
|
||||
getAppOptions() {
|
||||
console.log("No options implemented");
|
||||
}
|
||||
|
||||
async handleAttendeeNoShow() {
|
||||
console.log("Not implemented");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ export default class CrmManager {
|
||||
}
|
||||
|
||||
if (skipContactCreation) return;
|
||||
const contactSet = new Set(contacts.map((c) => c.email));
|
||||
const contactSet = new Set(contacts.map((c: { email: string }) => c.email));
|
||||
// Figure out which contacts to create
|
||||
const contactsToCreate = eventAttendees.filter((attendee) => !contactSet.has(attendee.email));
|
||||
const createdContacts = await this.createContacts(
|
||||
|
||||
Reference in New Issue
Block a user