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

Commit

Permalink
fixed mappers
Browse files Browse the repository at this point in the history
  • Loading branch information
sumanthreddyc committed Feb 29, 2024
1 parent 927558d commit 12f2d74
Show file tree
Hide file tree
Showing 5 changed files with 222 additions and 115 deletions.
120 changes: 77 additions & 43 deletions verticals/vertical-crm/commonModels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ export const account = zBaseRecord
id: z.string().nullish(),
name: z.string().nullish(),
updated_at: z.date().nullish(),
isDeleted: z.boolean().nullish(),
is_deleted: z.boolean().nullish(),
website: z.string().nullish(),
industry: z.string().nullish(),
numberOfEmployees: z.number().nullish(),
ownerId: z.string().nullish(),
createdAt: z.date().nullish(),
updatedAt: z.date().nullish(),
number_of_employees: z.number().nullish(),
owner_id: z.string().nullish(),
created_at: z.date().nullish(),
})
.openapi({ref: 'crm.account'})

Expand All @@ -26,15 +25,15 @@ export const lead = zBaseRecord
.extend({
id: z.string().nullish(),
name: z.string().nullish(),
firstName: z.string().nullish(),
lastName: z.string().nullish(),
ownerId: z.string().nullish(),
first_name: z.string().nullish(),
last_name: z.string().nullish(),
owner_id: z.string().nullish(),
title: z.string().nullish(),
company: z.string().nullish(),
convertedDate: z.date().nullish(),
leadSource: z.string().nullish(),
convertedAccountId: z.string().nullish(),
convertedContactId: z.string().nullish(),
converted_date: z.date().nullish(),
lead_source: z.string().nullish(),
converted_account_id: z.string().nullish(),
converted_contact_id: z.string().nullish(),
addresses: z
.array(
z.object({
Expand All @@ -43,32 +42,32 @@ export const lead = zBaseRecord
city: z.string().nullish(),
state: z.string().nullish(),
country: z.string().nullish(),
postalCode: z.string().nullish(),
addressType: z.string().nullish(),
postal_code: z.string().nullish(),
address_type: z.string().nullish(),
}),
)
.nullish(),
emailAddresses: z
email_addresses: z
.array(
z.object({
emailAddress: z.string().nullish(),
emailAddressType: z.string().nullish(),
email_address: z.string().nullish(),
email_address_type: z.string().nullish(),
}),
)
.nullish(),
phoneNumbers: z
phone_numbers: z
.array(
z.object({
phoneNumber: z.string().nullish(),
phoneNumberType: z.string().nullish(),
phone_number: z.string().nullish(),
phone_number_type: z.string().nullish(),
}),
)
.nullish(),
createdAt: z.date().nullish(),
updatedAt: z.date().nullish(),
isDeleted: z.boolean().nullish(),
lastModifiedAt: z.date().nullish(),
rawData: z.record(z.unknown()).nullish(),
created_at: z.date().nullish(),
updated_at: z.date().nullish(),
is_deleted: z.boolean().nullish(),
last_modified_at: z.date().nullish(),
raw_data: z.record(z.unknown()).nullish(),
})
.openapi({ref: 'crm.lead'})

Expand All @@ -78,21 +77,18 @@ export const opportunity = zBaseRecord
name: z.string().nullish(),
updated_at: z.date().nullish(),
description: z.string().nullish(),
ownerId: z.string().nullish(),
owner_id: z.string().nullish(),
status: z.string().nullish(),
stage: z.string().nullish(),
closeDate: z.date().nullish(),
accountId: z.string().nullish(),
// pipeline is not supported in salesforce
close_date: z.date().nullish(),
account_id: z.string().nullish(),
pipeline: z.string().nullish(),
// TODO: This should be parseFloat, but we need to migrate our customers
amount: z.string().nullish(),
lastActivityAt: z.date().nullish(),
createdAt: z.date().nullish(),
updatedAt: z.date().nullish(),
isDeleted: z.boolean().nullish(),
lastModifiedAt: z.date().nullish(),
rawData: z.record(z.unknown()).nullish(),
amount: z.number().nullish(),
last_activity_at: z.date().nullish(),
created_at: z.date().nullish(),
is_deleted: z.boolean().nullish(),
last_modified_at: z.date().nullish(),
raw_data: z.record(z.unknown()).nullish(),
})
.openapi({ref: 'crm.opportunity'})

Expand All @@ -101,15 +97,53 @@ export const user = zBaseRecord
id: z.string().nullish(),
name: z.string().nullish(),
email: z.string().nullish(),
isActive: z.boolean().nullish(),
createdAt: z.date().nullish(),
updatedAt: z.date().nullish(),
isDeleted: z.boolean().nullish(),
lastModifiedAt: z.date().nullish(),
rawData: z.record(z.unknown()).nullish(),
is_active: z.boolean().nullish(),
created_at: z.date().nullish(),
updated_at: z.date().nullish(),
is_deleted: z.boolean().nullish(),
last_modified_at: z.date().nullish(),
raw_data: z.record(z.unknown()).nullish(),
})
.openapi({ref: 'crm.user'})

export const meta_standard_object = z
.object({
name: z.string(),
})
.openapi({ref: 'crm.meta_standard_object'})

export const meta_custom_object = z
.object({
id: z.string(),
name: z.string(),
})
.openapi({ref: 'crm.meta_custom_object'})

export const meta_property = z
.object({
id: z.string().openapi({
description:
'The machine name of the property as it appears in the third-party Provider',
example: 'FirstName',
}),
label: z.string().openapi({
description:
'The human-readable name of the property as provided by the third-party Provider.',
example: 'First Name',
}),
type: z.string().optional().openapi({
description:
'The type of the property as provided by the third-party Provider. These types are not unified by Supaglue. For Intercom, this is string, integer, boolean, or object. For Outreach, this is integer, boolean, number, array, or string.',
example: 'string',
}),
raw_details: z.record(z.unknown()).optional().openapi({
description:
'The raw details of the property as provided by the third-party Provider, if available.',
example: {},
}),
})
.openapi({ref: 'crm.meta_property'})

export const metaStandardObject = z
.object({
name: z.string(),
Expand Down
73 changes: 73 additions & 0 deletions verticals/vertical-crm/providers/hubspot-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,26 @@ export type SimplePublicObject =
Oas_crm_contacts['components']['schemas']['SimplePublicObject']
export type Owner = Oas_crm_owners['components']['schemas']['PublicOwner']

// // In certain cases, Hubspot cannot determine the object type based on just the name for custom objects,
// // so we need to get the ID.
// const getObjectTypeIdFromNameOrId = async(nameOrId: string): Promise<string> => {
// // Standard objects can be referred by name no problem
// if (isStandardObjectType(nameOrId)) {
// return nameOrId;
// }
// if (this.#isAlreadyObjectTypeId(nameOrId)) {
// return nameOrId;
// }
// await this.maybeRefreshAccessToken();
// const schemas = await this.#client.crm.schemas.coreApi.getAll();
// const schemaId = schemas.results.find((schema) => schema.name === nameOrId || schema.objectTypeId === nameOrId)
// ?.objectTypeId;
// if (!schemaId) {
// throw new NotFoundError(`Could not find custom object schema with name or id ${nameOrId}`);
// }
// return schemaId;
// }

export const HUBSPOT_STANDARD_OBJECTS = [
'company',
'contact',
Expand Down Expand Up @@ -427,4 +447,57 @@ export const hubspotProvider = {
const res = await instance.crm_schemas.GET('/crm/v3/schemas')
return res.data.results.map((obj) => ({id: obj.id, name: obj.name}))
},
metadataListProperties: async ({instance, input}) => {
const res = await instance.crm_properties.GET(
'/crm/v3/properties/{objectType}',
{
params: {path: {objectType: input.name}},
},
)
return res.data.results.map((obj) => ({id: obj.name, label: obj.label}))
},
// metadataCreateObjectsSchema: async ({instance, input}) => {
// const res = await instance.crm_schemas.POST('/crm/v3/schemas', {
// body: {
// name: input.name,
// labels: input.label.singular,
// description: input.description || '',
// properties: input.fields.map((p) => ({
// type: p.type || 'string',
// label: p.label,
// name: p.label,
// fieldType: p.type || 'string',
// })),
// primaryFieldId: input.primaryFieldId,
// },
// })
// console.log('input:', input)
// // console.log('res:', res)
// return [{id: '123', name: input.name}]
// },
metadataCreateAssociation: async ({instance, input}) => {
const res = await instance.crm_associations.POST(
'/crm/v3/associations/{fromObjectType}/{toObjectType}/batch/create',
{
params: {
path: {
fromObjectType: input.sourceObject,
toObjectType: input.targetObject,
},
},
body: {
inputs: [
{
from: {id: input.sourceObject},
to: {id: input.targetObject},
type: `${input.sourceObject}_${input.targetObject}`,
},
],
},
},
)
console.log('res:', res.data.errors[0])
console.log('res:', res.data.errors[1])
return res.data
},
} satisfies CRMProvider<HubspotSDK>
Loading

0 comments on commit 12f2d74

Please sign in to comment.