diff --git a/packages/worker/cli.ts b/packages/worker/cli.ts index ac274a1..7c333a0 100644 --- a/packages/worker/cli.ts +++ b/packages/worker/cli.ts @@ -34,7 +34,9 @@ switch (cmd) { customer_id: process.env['CUSTOMER_ID']!, provider_name: process.env['PROVIDER_NAME']!, vertical: process.env['VERTICAL']! as 'crm', - common_objects: [process.env['COMMON_OBJECT'] ?? 'contact'], + common_objects: process.env['COMMON_OBJECT'] + ? [process.env['COMMON_OBJECT']] + : ['account', 'contact', 'opportunity', 'lead', 'user'], sync_mode: process.env['SYNC_MODE']! as 'incremental', destination_schema: process.env['DESTINATION_SCHEMA'], }, diff --git a/verticals/vertical-crm/providers/salesforce-provider.ts b/verticals/vertical-crm/providers/salesforce-provider.ts index c02c868..60c97d0 100644 --- a/verticals/vertical-crm/providers/salesforce-provider.ts +++ b/verticals/vertical-crm/providers/salesforce-provider.ts @@ -26,6 +26,25 @@ const mappers = { updated_at: 'SystemModstamp', name: 'Name', }), + opportunity: mapper( + zCast(), + commonModels.opportunity, + { + id: 'Id', + updated_at: 'SystemModstamp', + name: 'Name', + }, + ), + lead: mapper(zCast(), commonModels.lead, { + id: 'Id', + updated_at: 'SystemModstamp', + name: 'Name', + }), + user: mapper(zCast(), commonModels.user, { + id: 'Id', + updated_at: 'SystemModstamp', + name: 'Name', + }), } /** @@ -123,14 +142,7 @@ export const salesforceProvider = { const res = await instance.query(`SELECT COUNT() FROM ${input.entity}`) return {count: res.totalSize} }, - listContacts: async ({instance, input}) => - sdkExt(instance)._listEntityThenMap({ - entity: 'Contact', - fields: ['FirstName', 'LastName'], - mapper: mappers.contact, - cursor: input?.cursor, - page_size: input?.page_size, - }), + // MARK: - Account listAccounts: async ({instance, input}) => sdkExt(instance)._listEntityThenMap({ entity: 'Account', @@ -139,9 +151,8 @@ export const salesforceProvider = { cursor: input?.cursor, page_size: input?.page_size, }), - - getContact: async ({instance, input}) => { - const res = await instance.GET('/sobjects/Contact/{id}', { + getAccount: async ({instance, input}) => { + const res = await instance.GET('/sobjects/Account/{id}', { params: {path: {id: input.id}}, }) return { @@ -149,8 +160,19 @@ export const salesforceProvider = { raw: res.data, } }, - getAccount: async ({instance, input}) => { - const res = await instance.GET('/sobjects/Account/{id}', { + + // MARK: - Contact + + listContacts: async ({instance, input}) => + sdkExt(instance)._listEntityThenMap({ + entity: 'Contact', + fields: ['FirstName', 'LastName'], + mapper: mappers.contact, + cursor: input?.cursor, + page_size: input?.page_size, + }), + getContact: async ({instance, input}) => { + const res = await instance.GET('/sobjects/Contact/{id}', { params: {path: {id: input.id}}, }) return { @@ -158,6 +180,41 @@ export const salesforceProvider = { raw: res.data, } }, + + // MARK: - Opportunity + + listOpportunities: async ({instance, input}) => + sdkExt(instance)._listEntityThenMap({ + entity: 'Opportunity', + fields: ['Name'], + mapper: mappers.opportunity, + cursor: input?.cursor, + page_size: input?.page_size, + }), + + // MARK: - Lead + + listLeads: async ({instance, input}) => + sdkExt(instance)._listEntityThenMap({ + entity: 'Lead', + fields: ['Name'], + mapper: mappers.lead, + cursor: input?.cursor, + page_size: input?.page_size, + }), + + // MARK: - User + + listUsers: async ({instance, input}) => + sdkExt(instance)._listEntityThenMap({ + entity: 'User', + fields: ['Name'], + mapper: mappers.user, + cursor: input?.cursor, + page_size: input?.page_size, + }), + + // MARK: - Metadata metadataListStandardObjects: () => SALESFORCE_STANDARD_OBJECTS.map((name) => ({name})), metadataListCustomObjects: async ({instance}) => {