import {z} from 'zod' export type TransactionMatchStatusEnum = 'pending' | 'draft' | 'accepted' | 'rejected'; export type PatchedTransactionMatch = {id?: number | undefined, matched_object?: string | undefined, app_label?: string | undefined, model?: string | undefined, drafts?: string | undefined, object_id?: number | undefined, created_at?: string | undefined, reviewed_at?: (string | null) | undefined, status?: TransactionMatchStatusEnum | undefined, confidence_score?: (number | null) | undefined, reason?: (string | null) | undefined, snapshot: unknown, customer?: number | undefined, transaction?: (number | null) | undefined, content_type?: number | undefined, reviewed_by?: (number | null) | undefined}; export type PatchApiCoaApiTransactionMatchesIdArgs = {id: number, body: PatchedTransactionMatch}; export type PatchApiCoaApiTransactionMatchesIdOptions = {baseUrl?: string | undefined, knoxApiToken?: string | undefined, fetch?: typeof fetch | undefined}; export const transactionMatchStatusEnum = z.enum(["pending", "draft", "accepted", "rejected"]); export const transactionMatch = z.object({id: z.number().int(), matched_object: z.string(), app_label: z.string(), model: z.string(), drafts: z.string(), object_id: z.number().int().gte(0).lte(2147483647), created_at: z.string(), reviewed_at: z.string().nullable().optional(), status: transactionMatchStatusEnum.optional(), confidence_score: z.number().gte(0).lte(1).nullable().optional(), reason: z.string().max(64).nullable().optional(), snapshot: z.unknown(), customer: z.number().int(), transaction: z.number().int().nullable(), content_type: z.number().int(), reviewed_by: z.number().int().nullable().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 }; /** * Partial Update Transaction Match * * PATCH /coa/api/transaction-matches/{id} */ export const patchApiCoaApiTransactionMatchesId = async (args: PatchApiCoaApiTransactionMatchesIdArgs, options?: PatchApiCoaApiTransactionMatchesIdOptions) => { 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/transaction-matches/${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(transactionMatch, await res.json()) };