import {z} from 'zod' export type SelectListCustomFieldValueOptionInputSchema = {urn?: string | undefined, name: string, color: string, default?: (boolean | null) | undefined}; export type SelectListCustomFieldMetadataInputSchema = {options?: Array | undefined}; export type NumberListCustomFieldValueFormat = 'NUMBER' | 'PERCENT' | 'US_DOLLAR'; export type NumberListCustomFieldMetadata = {format?: NumberListCustomFieldValueFormat | undefined}; export type DateListCustomFieldValueFormat = 'MM_DD_YYYY' | 'DD_MM_YYYY' | 'YYYY_MM_DD'; export type DateListCustomFieldMetadata = {format?: DateListCustomFieldValueFormat | undefined}; export type PersonListCustomFieldValueMode = 'SINGLE' | 'MULTIPLE'; export type PersonListCustomFieldMetadata = {mode: PersonListCustomFieldValueMode}; export type RecordReferenceListCustomFieldMetadata = {record_type_urn: string, allow_multiple: boolean, mode?: (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 PersonListCustomFieldDefaultValueMode = 'FIXED_URN' | 'ADDED_BY_USER'; export type PersonListCustomFieldDefaultValue = {value?: Array | undefined, mode: PersonListCustomFieldDefaultValueMode}; export type DateListCustomFieldDefaultValueMode = 'FIXED_DATE' | 'CREATED_AT'; export type DateListCustomFieldDefaultValue = {value?: (string | null) | undefined, mode: DateListCustomFieldDefaultValueMode}; export type WebsiteListCustomFieldValue = {value?: (string | null) | undefined}; export type UpdateCompanyListCustomFieldInput = {name: string, metadata?: (SelectListCustomFieldMetadataInputSchema | NumberListCustomFieldMetadata | DateListCustomFieldMetadata | PersonListCustomFieldMetadata | RecordReferenceListCustomFieldMetadata | null) | undefined, default_value?: (CheckboxListCustomFieldValue | NumberListCustomFieldValue | TextListCustomFieldValue | PersonListCustomFieldDefaultValue | DateListCustomFieldDefaultValue | WebsiteListCustomFieldValue | null) | undefined}; export type UpdateApiCompaniesCustomFieldArgs = {custom_field_urn: string | string | string | string, body: UpdateCompanyListCustomFieldInput}; export type UpdateApiCompaniesCustomFieldOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const updateApiCompaniesCustomFieldResponse = z.unknown(); 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 Global Custom Field * * PUT /companies/custom_field */ export const updateApiCompaniesCustomField = async (args: UpdateApiCompaniesCustomFieldArgs, options: UpdateApiCompaniesCustomFieldOptions) => { 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") if (args.custom_field_urn != null) query.append("custom_field_urn", String(args.custom_field_urn)) const url = `${baseUrl.replace(/\/+$/, '')}/companies/custom_field${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", 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(updateApiCompaniesCustomFieldResponse, await res.json()) };