import {z} from 'zod' export type PersonCanonicalParameter = {linkedin_url?: (string | null) | undefined, email?: (string | null) | undefined}; export type CheckboxListCustomFieldValue = {value?: (boolean | null) | undefined}; export type NumberListCustomFieldValue = {value?: (number | null) | undefined}; export type TextListCustomFieldValue = {value?: (string | null) | undefined}; export type SingleListSelectCustomFieldValue = {value?: (string | null) | undefined}; export type MultiSelectListCustomFieldValue = {value?: Array | undefined}; export type PersonSelectCustomFieldValue = {value?: Array | undefined}; export type DateListCustomFieldValue = {value?: (string | null) | undefined}; export type WebsiteListCustomFieldValue = {value?: (string | null) | undefined}; export type StatusListCustomFieldValue = {value?: (string | null) | undefined}; export type PersonSelectCustomFieldValueInput = {value?: (Array) | undefined}; export type RecordReferenceListCustomFieldValue = {value?: Array | undefined}; export type PersonFieldInputValue = {custom_field_urn: string | string | string, data: CheckboxListCustomFieldValue | NumberListCustomFieldValue | TextListCustomFieldValue | SingleListSelectCustomFieldValue | MultiSelectListCustomFieldValue | PersonSelectCustomFieldValue | DateListCustomFieldValue | WebsiteListCustomFieldValue | StatusListCustomFieldValue | PersonSelectCustomFieldValueInput | RecordReferenceListCustomFieldValue}; export type PersonListEntryInput = {person_urn?: (string | null) | undefined, canonical?: (PersonCanonicalParameter | null) | undefined, values?: Array | undefined, created_at?: (string | null) | undefined}; export type PersonListEntriesBatchImportInput = {entries: Array}; export type CreateApiPersonsEntriesArgs = {body: PersonListEntriesBatchImportInput}; export type CreateApiPersonsEntriesOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const importPeopleCanonicalsOutput = z.object({user_people_import_urn: z.string(), total_people_count: z.number().int(), people_found_count: z.number().int(), people_not_found_count: z.number().int(), people_invalid_count: z.number().int()}); 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 }; /** * Global Import People * * POST /persons/entries */ export const createApiPersonsEntries = async (args: CreateApiPersonsEntriesArgs, options: CreateApiPersonsEntriesOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/persons/entries${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(importPeopleCanonicalsOutput, await res.json()) };