diff --git a/packages/app-store-cli/src/build.ts b/packages/app-store-cli/src/build.ts index d8f1e3bbaa..1d9c5d208c 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.ts index e7710ef0dd..b17804640d 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 = new (...args: Args) => I; - -type CrmClass = Class; +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.ts index c29b3128ce..e2cecde581 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.ts new file mode 100644 index 0000000000..94392d5ee5 --- /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.ts index ecedcfb690..6b1a124c03 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.ts index b7e88d30f6..b9203756f1 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.ts index 8a7710b32d..9bb099c8c5 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.ts index a1d498d06b..eef208addd 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.ts index 91cbb492c3..01e8f290d3 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 create const contactsToCreate = eventAttendees.filter((attendee) => !contactSet.has(attendee.email)); const createdContacts = await this.createContacts(