import {z} from 'zod' export type ApiSharedEnum1d20f1f7e9 = 'debit' | 'credit'; export type CreateApiApiV1ReconciliationRulesArgs = {'Idempotency-Key': string, body: {bank_account_id: string, text: string, direction: ApiSharedEnum1d20f1f7e9, account_id: string, contact_id?: (string | null) | undefined, cost_center1_id?: (string | null) | undefined, cost_center2_id?: (string | null) | undefined, cost_center3_id?: (string | null) | undefined, paused?: boolean | undefined}}; export type CreateApiApiV1ReconciliationRulesOptions = {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 apiSharedObjectaa73c77263 = z.object({request_id: z.string(), data: apiSharedObjectba292d6681}); 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 }; /** * Create reconciliation rule * * POST /api/v1/reconciliation-rules */ export const createApiApiV1ReconciliationRules = async (args: CreateApiApiV1ReconciliationRulesArgs, options?: CreateApiApiV1ReconciliationRulesOptions) => { const {baseUrl = "https://api.lapyme.com.ar", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args['Idempotency-Key'] != null) headers.set("Idempotency-Key", String(args['Idempotency-Key'])) 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: "POST", 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(apiSharedObjectaa73c77263, await res.json()) };