import {z} from 'zod' export type FixedAssetAutomationMatch = {id: number, rule: number, rule_name: string, rule_account_name: string, rule_threshold: number, rule_needs_review: boolean, transaction: number, transaction_description: string, transaction_date: string, transaction_amount: string, proposed_name: string, proposed_asset_class: number, proposed_initial_value: number, proposed_salvage_value?: number | undefined, proposed_purchase_date: string, proposed_depreciation_start_date: string, proposed_entity?: (number | null) | undefined, proposed_department?: (number | null) | undefined, proposed_vendor?: (number | null) | undefined, created_asset: number | null, created_at: string}; export type UpdateApiCoaApiFixedAssetAutomationMatchIdArgs = {id: number, body: FixedAssetAutomationMatch}; export type UpdateApiCoaApiFixedAssetAutomationMatchIdOptions = {baseUrl?: string | undefined, knoxApiToken?: string | undefined, fetch?: typeof fetch | undefined}; export const fixedAssetAutomationMatch = z.object({id: z.number().int(), rule: z.number().int(), rule_name: z.string(), rule_account_name: z.string(), rule_threshold: z.number().gt(-10000000000000).lt(10000000000000), rule_needs_review: z.boolean(), transaction: z.number().int(), transaction_description: z.string(), transaction_date: z.string(), transaction_amount: z.string(), proposed_name: z.string().max(250), proposed_asset_class: z.number().int(), proposed_initial_value: z.number().gt(-1000000000000000000).lt(1000000000000000000), proposed_salvage_value: z.number().gt(-1000000000000000000).lt(1000000000000000000).optional(), proposed_purchase_date: z.string(), proposed_depreciation_start_date: z.string(), proposed_entity: z.number().int().nullable().optional(), proposed_department: z.number().int().nullable().optional(), proposed_vendor: z.number().int().nullable().optional(), created_asset: z.number().int().nullable(), created_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 }; /** * Update Fixed Asset Automation Match * * PUT /coa/api/fixed-asset-automation-match/{id}/ */ export const updateApiCoaApiFixedAssetAutomationMatchId = async (args: UpdateApiCoaApiFixedAssetAutomationMatchIdArgs, options?: UpdateApiCoaApiFixedAssetAutomationMatchIdOptions) => { 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-match/${encodeURIComponent(String(args.id))}/${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(fixedAssetAutomationMatch, await res.json()) };