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

Commit

Permalink
fix: type errors
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyxiao committed Feb 29, 2024
1 parent 19ae326 commit a4cab63
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 39 deletions.
2 changes: 1 addition & 1 deletion verticals/vertical-crm/providers/hubspot-provider.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type {BaseRecord} from '@supaglue/vdk'
import {LastUpdatedAtNextOffset, mapper, z, zCast} from '@supaglue/vdk'
import {LastUpdatedAtNextOffset, mapper, z} from '@supaglue/vdk'
import type {Oas_crm_contacts, Oas_crm_owners} from '@opensdks/sdk-hubspot'
import {initHubspotSDK, type HubspotSDK} from '@opensdks/sdk-hubspot'
import type {CRMProvider} from '../router'
Expand Down
83 changes: 55 additions & 28 deletions verticals/vertical-crm/providers/salesforce-provider.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
/* eslint-disable @typescript-eslint/no-unsafe-call */
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
/* eslint-disable @typescript-eslint/no-unsafe-argument */
import type {BaseRecord} from '@supaglue/vdk'
import {
LastUpdatedAtId,
mapper,
modifyRequest,
PLACEHOLDER_BASE_URL,
z,
zCast,
} from '@supaglue/vdk'
import * as jsforce from 'jsforce'
import type {
CustomField as SalesforceCustomField,
CustomObject as SalesforceCustomObject,
} from 'jsforce/lib/api/metadata/schema'
import type {CustomField as SalesforceCustomField} from 'jsforce/lib/api/metadata/schema'
import type {SalesforceSDKTypes} from '@opensdks/sdk-salesforce'
import {
initSalesforceSDK,
type SalesforceSDK as _SalesforceSDK,
} from '@opensdks/sdk-salesforce'
import type {CustomObjectSchemaCreateParams} from '../../types/custom_object'
import type {PropertyType, PropertyUnified} from '../../types/property'
import type {CRMProvider} from '../router'
import {commonModels} from '../router'
import {SALESFORCE_STANDARD_OBJECTS} from './salesforce/constants'
Expand All @@ -27,6 +25,54 @@ import {SALESFORCE_STANDARD_OBJECTS} from './salesforce/constants'

export type SFDC = SalesforceSDKTypes['oas']['components']['schemas']

type PropertyType =
| 'text'
| 'textarea'
| 'number'
| 'picklist'
| 'multipicklist'
| 'date'
| 'datetime'
| 'boolean'
| 'url'
| 'other'

type PicklistOption = {
label: string
value: string
description?: string
hidden?: boolean
}

type PropertyUnified = {
id: string
customName?: string
label: string
description?: string
isRequired?: boolean
defaultValue?: string | number | boolean
groupName?: string
type: PropertyType
precision?: number
scale?: number
options?: PicklistOption[]
rawDetails?: Record<string, unknown>
}

type CustomObjectSchema = {
name: string
description: string | null
labels: {
singular: string
plural: string
}
primaryFieldId: string
fields: PropertyUnified[]
// TODO: timestamps?
}

type CustomObjectSchemaCreateParams = CustomObjectSchema

const mappers = {
contact: mapper(zCast<SFDC['ContactSObject']>(), commonModels.contact, {
id: 'Id',
Expand Down Expand Up @@ -183,7 +229,7 @@ type ToolingAPIValueSet = {
restricted: boolean
valueSetDefinition: {
sorted: boolean
value: {label: string; valueName: string; description: string}[]
value: Array<{label: string; valueName: string; description: string}>
}
}
type ToolingAPICustomField = {
Expand Down Expand Up @@ -282,25 +328,6 @@ type OpportunityFields =
| 'CloseDate'
| 'CreatedDate'
| 'AccountId'
type LeadFields =
| 'OwnerId'
| 'Title'
| 'FirstName'
| 'LastName'
| 'ConvertedDate'
| 'CreatedDate'
| 'SystemModstamp'
| 'ConvertedContactId'
| 'ConvertedAccountId'
| 'Company'
| 'City'
| 'State'
| 'Street'
| 'Country'
| 'PostalCode'
| 'Phone'
| 'Email'
| 'IsDeleted'
type UserFields = 'Name' | 'Email' | 'IsActive' | 'CreatedDate'

export const CRM_COMMON_OBJECT_TYPES = [
Expand Down Expand Up @@ -805,7 +832,7 @@ export const salesforceProvider = {
'CustomObject',
toSalesforceCustomObjectCreateParams(
objectName,
input.label,
input.labels,
input.description || null,
primaryFieldMapped,
nonPrimaryFieldsMapped,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import * as jsforce from 'jsforce'
import type * as jsforce from 'jsforce'
import {API_VERSION} from '../salesforce-provider'

interface SalesforceInstance {
getJsForce: () => Promise<jsforce.Connection>
}

export async function updateFieldPermissions(
sfdc: jsforce.Connection,
objectName: string,
Expand Down
10 changes: 5 additions & 5 deletions verticals/vertical-crm/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,21 +117,21 @@ export const crmRouter = trpc.router({
.input(
z.object({
name: z.string(),
description: z.string().nullish(),
label: z.object({
description: z.string().nullable(),
labels: z.object({
singular: z.string(),
plural: z.string(),
}),
primaryFieldId: z.string(),
fields: z.array(
z.object({
id: z.string(),
description: z.string().nullish(),
description: z.string().optional(),
type: z.string(),
label: z.string(),
isRequired: z.boolean(),
default_value: z.string().nullish(),
group_name: z.string().nullish(),
default_value: z.string().optional(),
group_name: z.string().optional(),
}),
),
}),
Expand Down

0 comments on commit a4cab63

Please sign in to comment.