import {z} from 'zod' export type UpdateCompanyRequest = {name?: (string | null) | undefined, domain?: (string | null) | undefined, description?: (string | null) | undefined, phone?: (string | null) | undefined, address?: (string | null) | undefined, city?: (string | null) | undefined, state?: (string | null) | undefined, zip?: (string | null) | undefined, country?: (string | null) | undefined, website?: (string | null) | undefined, industry?: (string | null) | undefined, numberofemployees?: (string | null) | undefined, annualrevenue?: (string | null) | undefined, lifecyclestage?: (string | null) | undefined, hubspot_owner_id?: (string | null) | undefined}; export type AppRoutesV3CrmCompaniesBatchUpdateItem = {id: string, properties: UpdateCompanyRequest}; export type AppRoutesV3CrmCompaniesBatchUpdateRequest = {companies: Array}; export type CreateApiApiV3CrmIntegrationIdCompaniesBatchUpdateArgs = {integration_id: string, body: AppRoutesV3CrmCompaniesBatchUpdateRequest}; export type CreateApiApiV3CrmIntegrationIdCompaniesBatchUpdateOptions = {baseUrl: string, HTTPBearer?: string | undefined, fetch?: typeof fetch | undefined}; export const companyResponse = z.object({id: z.string(), properties: z.record(z.string(), z.unknown()), created_at: z.string().nullable().optional(), updated_at: z.string().nullable().optional()}); export const companyListResponse = z.object({results: z.array(companyResponse), has_more: z.boolean().optional(), next_cursor: 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 }; /** * Batch Update Companies * * POST /api/v3/crm/{integration_id}/companies/batch/update */ export const createApiApiV3CrmIntegrationIdCompaniesBatchUpdate = async (args: CreateApiApiV3CrmIntegrationIdCompaniesBatchUpdateArgs, options: CreateApiApiV3CrmIntegrationIdCompaniesBatchUpdateOptions) => { const {baseUrl, fetch: fetchFn = fetch, HTTPBearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (HTTPBearer !== undefined) headers.set('authorization', `Bearer ${HTTPBearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v3/crm/${encodeURIComponent(String(args.integration_id))}/companies/batch/update${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(companyListResponse, await res.json()) };