import {z} from 'zod' export type GetApiApiV1ReconciliationRulesArgs = {bank_account_id?: string | undefined, limit?: number | undefined, cursor?: string | undefined}; export type GetApiApiV1ReconciliationRulesOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const apiSharedEnum1d20f1f7e9 = z.enum(["debit", "credit"]); export const apiSharedEnum2a6c2e1246 = z.enum(["active", "paused"]); export const apiSharedObjectba292d6681 = z.object({object: z.literal("reconciliation_rule"), id: z.string(), bank_account_id: z.string(), text: z.string(), direction: apiSharedEnum1d20f1f7e9, account_id: z.string(), contact_id: z.string().nullable(), cost_center1_id: z.string().nullable(), cost_center2_id: z.string().nullable(), cost_center3_id: z.string().nullable(), status: apiSharedEnum2a6c2e1246, resolved_line_count: z.number().int().gte(0), created_at: z.string(), updated_at: z.string()}); export const getApiApiV1ReconciliationRulesResponse = z.object({request_id: z.string(), data: z.array(apiSharedObjectba292d6681), object: z.literal("list"), url: z.string(), has_more: z.boolean(), next_cursor: z.string().nullable()}); 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 reconciliation rules * * GET /api/v1/reconciliation-rules */ export const getApiApiV1ReconciliationRules = async (args: GetApiApiV1ReconciliationRulesArgs, options?: GetApiApiV1ReconciliationRulesOptions) => { const {baseUrl = "https://api.lapyme.com.ar", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.bank_account_id != null) query.append("bank_account_id", String(args.bank_account_id)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.cursor != null) query.append("cursor", String(args.cursor)) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/reconciliation-rules${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(getApiApiV1ReconciliationRulesResponse, await res.json()) };