import {z} from 'zod' export type AdaptekApiCommonConstantsPeopleGenderType = 0 | 1 | 2; export type AdaptekApiCommonConstantsPeopleMaritalStatusType = 1 | 2 | 3 | 4; export type AdaptekApiApplicationPersonEmailAddressesCommandsUpsertPersonEmailAddressUpsertPersonEmailAddressCommand = {emailId?: (number | null) | undefined, personId?: number | undefined, emailAddress?: (string | null) | undefined, isPreferred?: boolean | undefined}; export type AdaptekApiCommonConstantsCommonStateOrProvinceType = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56; export type AdaptekApiApplicationPersonPhysicalAddressesCommandsUpsertPersonPhysicalAddressUpsertPersonPhysicalAddressCommand = {addressId?: (number | null) | undefined, personId?: number | undefined, street?: (string | null) | undefined, street2?: (string | null) | undefined, city?: (string | null) | undefined, zipCode?: number | undefined, isPreferred?: boolean | undefined, addressType?: number | undefined, stateOrProvinceId?: AdaptekApiCommonConstantsCommonStateOrProvinceType | undefined, salesforceId?: (string | null) | undefined}; export type AdaptekApiApplicationPersonPhoneNumbersCommandsUpsertPersonPhoneNumberUpsertPersonPhoneNumberCommand = {phoneNumberId?: (number | null) | undefined, personId?: number | undefined, phoneNumber?: number | undefined, phoneNumberTypeId?: number | undefined, isPreferred?: boolean | undefined, salesforceId?: (string | null) | undefined}; export type AdaptekApiApplicationPeopleCommandsUpsertFullPersonUpsertFullPersonCommand = {personId?: (number | null) | undefined, agentId?: number | undefined, salesforcePersonId?: (string | null) | undefined, firstName?: (string | null) | undefined, middleName?: (string | null) | undefined, lastName?: (string | null) | undefined, genderTypeId?: AdaptekApiCommonConstantsPeopleGenderType | undefined, dateOfBirth?: (string | null) | undefined, ssn?: (string | null) | undefined, greeting?: (string | null) | undefined, driversLicenseNumber?: (string | null) | undefined, driversLicenseExpiration?: (string | null) | undefined, driversLicenseState?: (number | null) | undefined, driversLicenseIssueDate?: (string | null) | undefined, age?: (number | null) | undefined, maritalStatusTypeId?: AdaptekApiCommonConstantsPeopleMaritalStatusType | undefined, personStatus?: (number | null) | undefined, lifecycleStatus?: (string | null) | undefined, service?: (string | null) | undefined, emailAddresses?: (Array | null) | undefined, physicalAddresses?: (Array | null) | undefined, phoneNumbers?: (Array | null) | undefined}; export type CreateApiV1SalesForceConsumerArgs = {body: AdaptekApiApplicationPeopleCommandsUpsertFullPersonUpsertFullPersonCommand}; export type CreateApiV1SalesForceConsumerOptions = {baseUrl: string, oauth2?: string | undefined, fetch?: typeof fetch | undefined}; export const adaptekApiApplicationPeopleCommandsUpsertFullPersonUpsertFullPersonResponseStatus = z.union([z.literal(0), z.literal(1), z.literal(2), z.literal(3)]); export const adaptekApiApplicationPeopleCommandsUpsertFullPersonUpsertFullPersonResponse = z.object({status: adaptekApiApplicationPeopleCommandsUpsertFullPersonUpsertFullPersonResponseStatus.optional(), id: z.string().nullable().optional(), vaultUsername: z.string().nullable().optional(), vaultLastLogin: z.string().nullable().optional()}); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Create/Update a consumer record from Salesforce * * POST /v1/SalesForce/consumer */ export const createApiV1SalesForceConsumer = async (args: CreateApiV1SalesForceConsumerArgs, options: CreateApiV1SalesForceConsumerOptions) => { const {baseUrl, fetch: fetchFn = fetch, oauth2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (oauth2 !== undefined) headers.set('authorization', `Bearer ${oauth2}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/SalesForce/consumer${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(adaptekApiApplicationPeopleCommandsUpsertFullPersonUpsertFullPersonResponse, await res.json()) };