import {z} from 'zod' export type ApiSharedEnumed1129741e = 'sale' | 'purchase'; export type ApiSharedEnum53162db3eb = 'bank_account' | 'register' | 'safe'; export type CreateApiApiV1StatementsLinesStatementLineIdResolveArgs = {'Idempotency-Key': string, statement_line_id: string, body: {action: 'link', targets?: (Array<{type: 'payment', payment_id: string, amount: number} | {type: 'journal_entry', journal_entry_id: string, amount: number} | {type: ApiSharedEnumed1129741e, document_id: string, amount: number}>) | undefined, adjustments?: (Array<{account_id: string, amount: number, note?: string | undefined, cost_center1_id?: string | undefined, cost_center2_id?: string | undefined, cost_center3_id?: string | undefined}>) | undefined, reason?: string | undefined} | {action: 'movement', account_id?: string | undefined, contact_id?: string | undefined, cost_center1_id?: string | undefined, cost_center2_id?: string | undefined, cost_center3_id?: string | undefined, note?: string | undefined, reason?: string | undefined, remember?: {text: string} | undefined} | {action: 'transfer', counterpart_type: ApiSharedEnum53162db3eb, counterpart_id: string} | {action: 'exclude', reason: string} | {action: 'undo', reason: string}}; export type CreateApiApiV1StatementsLinesStatementLineIdResolveOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const apiSharedEnume7b34c7d75 = z.enum(["pending", "linked", "excluded"]); export const createApiApiV1StatementsLinesStatementLineIdResolveResponse = z.object({request_id: z.string(), data: z.object({object: z.literal("statement_line_resolution"), statement_line_id: z.string(), statement_id: z.string(), status: apiSharedEnume7b34c7d75, reconciliation_id: z.string().nullable(), created_record_id: z.string().nullable(), created_records: z.array(z.object({type: z.enum(["customer_payment", "supplier_payment", "treasury_movement", "funds_transfer"]), id: z.string()})).optional(), remembered_rule_id: z.string().nullable().optional(), paired_statement_line_id: z.string().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 }; /** * Resolve statement line * * POST /api/v1/statements/lines/{statement_line_id}/resolve */ export const createApiApiV1StatementsLinesStatementLineIdResolve = async (args: CreateApiApiV1StatementsLinesStatementLineIdResolveArgs, options?: CreateApiApiV1StatementsLinesStatementLineIdResolveOptions) => { 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/statements/lines/${encodeURIComponent(String(args.statement_line_id))}/resolve${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(createApiApiV1StatementsLinesStatementLineIdResolveResponse, await res.json()) };