import {z} from 'zod' export type CrmObjectsSimplePublicObjectInput = {properties: {[key: string]: string}}; export type PatchApiCrmObjects202603TaxesTaxIdArgs = {taxId: string, idProperty?: string | undefined, body: CrmObjectsSimplePublicObjectInput}; export type PatchApiCrmObjects202603TaxesTaxIdOptions = {baseUrl?: string | undefined, privateApps?: string | undefined, fetch?: typeof fetch | undefined}; export const crmValueWithTimestamp = z.object({sourceId: z.string().optional(), sourceLabel: z.string().optional(), sourceType: z.string(), timestamp: z.string(), updatedByUserId: z.number().int().optional(), value: z.string()}); export const crmSimplePublicObject = z.object({archived: z.boolean(), archivedAt: z.string().optional(), createdAt: z.string(), id: z.string(), objectWriteTraceId: z.string().optional(), properties: z.record(z.string(), z.string()), propertiesWithHistory: z.record(z.string(), z.array(crmValueWithTimestamp)).optional(), updatedAt: z.string(), url: z.string().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 }; /** * Update * * PATCH /crm/objects/2026-03/taxes/{taxId} * * Also accepts auth: developer_hapikey */ export const patchApiCrmObjects202603TaxesTaxId = async (args: PatchApiCrmObjects202603TaxesTaxIdArgs, options?: PatchApiCrmObjects202603TaxesTaxIdOptions) => { const {baseUrl = "https://api.hubapi.com", fetch: fetchFn = fetch, privateApps} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.idProperty != null) query.append("idProperty", String(args.idProperty)) if (privateApps !== undefined) headers.set('authorization', `Bearer ${privateApps}`) const url = `${baseUrl.replace(/\/+$/, '')}/crm/objects/2026-03/taxes/${encodeURIComponent(String(args.taxId))}${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(crmSimplePublicObject, await res.json()) };