import {z} from 'zod' export type PatchedFixedAssetAutomationRule = {id?: number | undefined, name?: string | undefined, entity?: number | undefined, entity_name?: string | undefined, currency?: string | undefined, account?: number | undefined, account_name?: string | undefined, account_number?: string | undefined, amount_threshold?: number | undefined, asset_class?: number | undefined, asset_class_name?: string | undefined, needs_review?: boolean | undefined, forward_looking?: boolean | undefined, created_at?: string | undefined, last_modified_at?: string | undefined}; export type PatchApiCoaApiFixedAssetAutomationIdArgs = {id: number, body: PatchedFixedAssetAutomationRule}; export type PatchApiCoaApiFixedAssetAutomationIdOptions = {baseUrl?: string | undefined, knoxApiToken?: string | undefined, fetch?: typeof fetch | undefined}; export const fixedAssetAutomationRule = z.object({id: z.number().int(), name: z.string().max(255), entity: z.number().int(), entity_name: z.string(), currency: z.string(), account: z.number().int(), account_name: z.string(), account_number: z.string(), amount_threshold: z.number().gt(-1000000000000000000).lt(1000000000000000000), asset_class: z.number().int(), asset_class_name: z.string(), needs_review: z.boolean().optional(), forward_looking: z.boolean().optional(), created_at: z.string(), last_modified_at: z.string()}); 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 }; /** * Partial Update Fixed Asset Automation * * PATCH /coa/api/fixed-asset-automation/{id}/ */ export const patchApiCoaApiFixedAssetAutomationId = async (args: PatchApiCoaApiFixedAssetAutomationIdArgs, options?: PatchApiCoaApiFixedAssetAutomationIdOptions) => { const {baseUrl = "https://api.meetcampfire.com", fetch: fetchFn = fetch, knoxApiToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (knoxApiToken !== undefined) headers.set("Authorization", knoxApiToken) const url = `${baseUrl.replace(/\/+$/, '')}/coa/api/fixed-asset-automation/${encodeURIComponent(String(args.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(fixedAssetAutomationRule, await res.json()) };