Scheduling infrastructure for absolutely everyone.
perf: Add `CrmServiceMap` (#19718)
Joe Au-Yeung07969f528752
diff --git a/packages/app-store-cli/src/build.ts b/packages/app-store-cli/src/build.tsindex d8f1e3bbaa3..1d9c5d208cc 100644--- a/packages/app-store-cli/src/build.ts+++ b/packages/app-store-cli/src/build.ts@@ -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");+}diff --git a/packages/app-store/_utils/getCrm.ts b/packages/app-store/_utils/getCrm.tsindex e7710ef0dd8..b17804640d6 100644--- a/packages/app-store/_utils/getCrm.ts+++ b/packages/app-store/_utils/getCrm.ts@@ -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;diff --git a/packages/app-store/closecom/lib/CrmService.ts b/packages/app-store/closecom/lib/CrmService.tsindex c29b3128ce9..e2cecde581a 100644--- a/packages/app-store/closecom/lib/CrmService.ts+++ b/packages/app-store/closecom/lib/CrmService.ts@@ -205,4 +205,8 @@ export default class CloseComCRMService implements CRM {getAppOptions() {console.log("No options implemented");}++ async handleAttendeeNoShow() {+ console.log("Not implemented");+ }}diff --git a/packages/app-store/crm.apps.generated.ts b/packages/app-store/crm.apps.generated.tsnew file mode 100644index 00000000000..94392d5ee50--- /dev/null+++ b/packages/app-store/crm.apps.generated.ts@@ -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"),+};diff --git a/packages/app-store/hubspot/lib/CrmService.ts b/packages/app-store/hubspot/lib/CrmService.tsindex ecedcfb6906..6b1a124c03f 100644--- a/packages/app-store/hubspot/lib/CrmService.ts+++ b/packages/app-store/hubspot/lib/CrmService.ts@@ -273,4 +273,8 @@ export default class HubspotCalendarService implements CRM {getAppOptions() {console.log("No options implemented");}++ async handleAttendeeNoShow() {+ console.log("Not implemented");+ }}diff --git a/packages/app-store/pipedrive-crm/lib/CrmService.ts b/packages/app-store/pipedrive-crm/lib/CrmService.tsindex b7e88d30f65..b9203756f1e 100644--- a/packages/app-store/pipedrive-crm/lib/CrmService.ts+++ b/packages/app-store/pipedrive-crm/lib/CrmService.ts@@ -234,4 +234,8 @@ export default class PipedriveCrmService implements CRM {getAppOptions() {console.log("No options implemented");}++ async handleAttendeeNoShow() {+ console.log("Not implemented");+ }}diff --git a/packages/app-store/zoho-bigin/lib/CrmService.ts b/packages/app-store/zoho-bigin/lib/CrmService.tsindex 8a7710b32dc..9bb099c8c5e 100644--- a/packages/app-store/zoho-bigin/lib/CrmService.ts+++ b/packages/app-store/zoho-bigin/lib/CrmService.ts@@ -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) => {diff --git a/packages/app-store/zohocrm/lib/CrmService.ts b/packages/app-store/zohocrm/lib/CrmService.tsindex a1d498d06b1..eef208addd8 100644--- a/packages/app-store/zohocrm/lib/CrmService.ts+++ b/packages/app-store/zohocrm/lib/CrmService.ts@@ -293,4 +293,8 @@ export default class ZohoCrmCrmService implements CRM {getAppOptions() {console.log("No options implemented");}++ async handleAttendeeNoShow() {+ console.log("Not implemented");+ }}diff --git a/packages/lib/crmManager/crmManager.ts b/packages/lib/crmManager/crmManager.tsindex 91cbb492c3f..01e8f290d30 100644--- a/packages/lib/crmManager/crmManager.ts+++ b/packages/lib/crmManager/crmManager.ts@@ -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 createconst contactsToCreate = eventAttendees.filter((attendee) => !contactSet.has(attendee.email));const createdContacts = await this.createContacts(