import {z} from 'zod' export type CompanyCanonicalParameter = {linkedin_url?: (string | null) | undefined, crunchbase_url?: (string | null) | undefined, pitchbook_url?: (string | null) | undefined, website_url?: (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 CompanyFieldInputValue = {custom_field_urn: string | string | string | string, data: CheckboxListCustomFieldValue | NumberListCustomFieldValue | TextListCustomFieldValue | SingleListSelectCustomFieldValue | MultiSelectListCustomFieldValue | PersonSelectCustomFieldValue | DateListCustomFieldValue | WebsiteListCustomFieldValue | StatusListCustomFieldValue | PersonSelectCustomFieldValueInput | RecordReferenceListCustomFieldValue}; export type UnifiedExternalCompanyListEntryModel = {id?: (string | null) | undefined, list_id: string, target_list_urn: string, entity_id?: (string | null) | undefined, entity_type?: (string | null) | undefined, added_at?: (string | null) | undefined, updated_at?: (string | null) | undefined, canonical?: (CompanyCanonicalParameter | null) | undefined, label?: (string | null) | undefined, integration_provider: string}; export type CompanyListEntryInput = {company_urn?: (string | null) | undefined, canonical?: (CompanyCanonicalParameter | null) | undefined, values?: Array | undefined, external_display_name?: (string | null) | undefined, external_id?: (string | null) | undefined, external_entry?: (UnifiedExternalCompanyListEntryModel | null) | undefined}; export type CompanyListEntriesBatchImportInput = {entries: Array}; export type CreateApiCompaniesEntriesArgs = {body: CompanyListEntriesBatchImportInput}; export type CreateApiCompaniesEntriesOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const importCompaniesCanonicalsOutput = z.object({user_companies_import_urn: z.string(), total_companies_count: z.number().int(), companies_found_count: z.number().int(), companies_not_found_count: z.number().int(), companies_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 Companies * * POST /companies/entries */ export const createApiCompaniesEntries = async (args: CreateApiCompaniesEntriesArgs, options: CreateApiCompaniesEntriesOptions) => { 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(/\/+$/, '')}/companies/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(importCompaniesCanonicalsOutput, await res.json()) };