import {z} from 'zod' export type AccountUpdateRequest = {name?: (string | null) | undefined, email?: (string | null) | undefined, phone?: (string | null) | undefined, source?: (string | null) | undefined, status?: (string | null) | undefined, relationship_type?: ('customer' | 'vendor' | 'partner' | 'prospect' | 'other' | null) | undefined, tags?: (Array | null) | undefined, website?: (string | null) | undefined, company_name?: (string | null) | undefined, description?: (string | null) | undefined, industry?: (string | null) | undefined, num_employees?: (number | null) | undefined, social_dict_list?: (Array<{[key: string]: unknown}> | null) | undefined}; export type PatchApiCrmAccountsAccountIdArgs = {account_id: string, body: AccountUpdateRequest}; export type PatchApiCrmAccountsAccountIdOptions = {baseUrl: string, APIKeyHeader?: string | undefined, fetch?: typeof fetch | undefined}; export const accountResponse = z.object({id: z.string(), name: z.string(), phone_list: z.array(z.unknown()).nullable().optional(), email_list: z.array(z.unknown()).nullable().optional(), status: z.string().nullable().optional(), source: z.string().nullable().optional(), relationship_type: z.string().nullable().optional(), website: z.string().nullable().optional(), company_name: z.string().nullable().optional(), description: z.string().nullable().optional(), industry: z.string().nullable().optional(), num_employees: z.number().int().nullable().optional(), tags: z.array(z.string()).nullable().optional(), social_dict_list: z.array(z.record(z.string(), z.unknown())).nullable().optional(), created_date: z.string().nullable().optional(), updated_date: 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 }; /** * Patch Account * * PATCH /crm/accounts/{account_id} */ export const patchApiCrmAccountsAccountId = async (args: PatchApiCrmAccountsAccountIdArgs, options: PatchApiCrmAccountsAccountIdOptions) => { const {baseUrl, fetch: fetchFn = fetch, APIKeyHeader} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (APIKeyHeader !== undefined) headers.set("Authorization", APIKeyHeader) const url = `${baseUrl.replace(/\/+$/, '')}/crm/accounts/${encodeURIComponent(String(args.account_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PATCH", 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(accountResponse, await res.json()) };