Files
calendar/packages/app-store/_utils/getCrm.ts
T
b1d9e2b84c feat: Salesforce choose how to save attendees & other options (#17009)
* Refactor get SF user and create event

* Add new Salesforce options

* Pass app options to CrmService

* Add record enum

* Add creating new lead and contact under an account

* Handle if the contact already exists but not connected to account

* Create a lead if an account doesn't exist

* Merge fix

* Refactor - add generateCreateRecordBody

* Type fix

* Clean up

* Add getAppOptions to other CRM services

* Type fixes

* Fix typo

* feat: Salesforce round robin skip - choose which entity to search on (#17038)

* Add option to search which entity for the owner

* Add logic to search entity for skipping RR assignment

* Type fixes

* Disable license

* Skip license check in component

* Revert license changes

---------

Co-authored-by: Udit Takkar <53316345+Udit-takkar@users.noreply.github.com>
2024-10-12 10:02:27 +00:00

34 lines
1016 B
TypeScript

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]>;
const log = logger.getSubLogger({ prefix: ["CrmManager"] });
export const getCrm = async (credential: CredentialPayload, appOptions: any) => {
if (!credential || !credential.key) return null;
const { type: crmType } = credential;
const crmName = crmType.split("_")[0];
const crmAppImportFn = appStore[crmName as keyof typeof appStore];
if (!crmAppImportFn) {
log.warn(`crm of type ${crmType} is not implemented`);
return null;
}
const crmApp = await crmAppImportFn();
if (crmApp && "lib" in crmApp && "CrmService" in crmApp.lib) {
const CrmService = crmApp.lib.CrmService as CrmClass;
return new CrmService(credential, appOptions);
}
};
export default getCrm;