import {z} from 'zod' export type GetApiCoaApiFixedAssetAutomationMatchesArgs = {limit?: number | undefined, offset?: number | undefined, ordering?: string | undefined}; export type GetApiCoaApiFixedAssetAutomationMatchesOptions = {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 paginatedFixedAssetAutomationMatchList = z.object({count: z.number().int(), next: z.string().nullable().optional(), previous: z.string().nullable().optional(), results: z.array(fixedAssetAutomationMatch)}); 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 }; /** * List Fixed Asset Automation Matches * * GET /coa/api/fixed-asset-automation/matches */ export const getApiCoaApiFixedAssetAutomationMatches = async (args: GetApiCoaApiFixedAssetAutomationMatchesArgs, options?: GetApiCoaApiFixedAssetAutomationMatchesOptions) => { const {baseUrl = "https://api.meetcampfire.com", fetch: fetchFn = fetch, knoxApiToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.limit != null) query.append("limit", String(args.limit)) if (args.offset != null) query.append("offset", String(args.offset)) if (args.ordering != null) query.append("ordering", String(args.ordering)) if (knoxApiToken !== undefined) headers.set("Authorization", knoxApiToken) const url = `${baseUrl.replace(/\/+$/, '')}/coa/api/fixed-asset-automation/matches${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(paginatedFixedAssetAutomationMatchList, await res.json()) };