import {z} from 'zod' export type GetApiApiV1StatementsStatementIdArgs = {statement_id: string}; export type GetApiApiV1StatementsStatementIdOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const apiSharedEnumffb4886f2b = z.enum(["ARS", "USD"]); export const apiSharedEnum6527b55801 = z.enum(["spreadsheet", "normalized", "mercadopago_release"]); export const apiSharedObjectadb8c61c7c = z.object({object: z.literal("statement"), id: z.string(), bank_account_id: z.string(), period_start: z.string(), period_end: z.string(), opening_balance: z.number().int(), closing_balance: z.number().int(), currency: apiSharedEnumffb4886f2b, source: apiSharedEnum6527b55801, created_at: z.string(), updated_at: z.string()}); export const apiSharedObject11052f1fc2 = z.object({request_id: z.string(), data: apiSharedObjectadb8c61c7c}); 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 }; /** * Get statement * * GET /api/v1/statements/{statement_id} */ export const getApiApiV1StatementsStatementId = async (args: GetApiApiV1StatementsStatementIdArgs, options?: GetApiApiV1StatementsStatementIdOptions) => { 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 (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/statements/${encodeURIComponent(String(args.statement_id))}${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(apiSharedObject11052f1fc2, await res.json()) };