Skip to content
This repository has been archived by the owner on Mar 10, 2024. It is now read-only.

Commit

Permalink
feat: sfdc sync for lead, opportunity and user
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyxiao committed Feb 21, 2024
1 parent c2abad6 commit 77607d2
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 14 deletions.
4 changes: 3 additions & 1 deletion packages/worker/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
},
Expand Down
83 changes: 70 additions & 13 deletions verticals/vertical-crm/providers/salesforce-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,25 @@ const mappers = {
updated_at: 'SystemModstamp',
name: 'Name',
}),
opportunity: mapper(
zCast<SFDC['OpportunitySObject']>(),
commonModels.opportunity,
{
id: 'Id',
updated_at: 'SystemModstamp',
name: 'Name',
},
),
lead: mapper(zCast<SFDC['LeadSObject']>(), commonModels.lead, {
id: 'Id',
updated_at: 'SystemModstamp',
name: 'Name',
}),
user: mapper(zCast<SFDC['UserSObject']>(), commonModels.user, {
id: 'Id',
updated_at: 'SystemModstamp',
name: 'Name',
}),
}

/**
Expand Down Expand Up @@ -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',
Expand All @@ -139,25 +151,70 @@ 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 {
record: mappers.contact.parse(res.data),
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 {
record: mappers.contact.parse(res.data),
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}) => {
Expand Down

0 comments on commit 77607d2

Please sign in to comment.