import {z} from 'zod' export type GetApiWalletsLagoIdWalletTransactionsArgs = {lago_id: string, page?: number | undefined, per_page?: number | undefined, status?: string | undefined, transaction_status?: string | undefined, transaction_type?: string | undefined, 'metadata[key]'?: string | undefined}; export type GetApiWalletsLagoIdWalletTransactionsOptions = {baseUrl?: string | undefined, bearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const invoiceCustomSectionObject = z.object({lago_id: z.string(), name: z.string(), code: z.string(), description: z.string().optional(), details: z.string().optional(), display_name: z.string().optional(), applied_to_organization: z.boolean().optional(), organization_id: z.string().optional(), created_at: z.string().optional()}); export const appliedInvoiceCustomSectionObject = z.object({lago_id: z.string(), created_at: z.string(), invoice_custom_section_id: z.string().optional(), invoice_custom_section: invoiceCustomSectionObject}); export const paymentMethodReference = z.object({payment_method_type: z.enum(["provider", "manual"]).optional(), payment_method_id: z.string().optional()}); export const walletTransactionObject = z.object({lago_id: z.string(), lago_wallet_id: z.string(), billing_entity_code: z.string(), lago_invoice_id: z.string().nullable(), lago_credit_note_id: z.string().nullable(), lago_voided_invoice_id: z.string().nullable(), status: z.enum(["pending", "settled", "failed"]), source: z.enum(["manual", "interval", "threshold"]), transaction_status: z.enum(["purchased", "granted", "voided", "invoiced"]), transaction_type: z.enum(["inbound", "outbound"]), amount: z.string(), credit_amount: z.string(), invoice_requires_successful_payment: z.boolean(), metadata: z.array(z.object({key: z.string().optional(), value: z.string().optional()})), remaining_amount_cents: z.number().int().nullable(), remaining_credit_amount: z.string().nullable(), priority: z.number().int(), settled_at: z.string().nullable(), failed_at: z.string().nullable(), created_at: z.string(), name: z.string().nullable(), applied_invoice_custom_sections: z.array(appliedInvoiceCustomSectionObject).optional(), payment_method: paymentMethodReference, purchase_order_number: z.string().nullable()}); export const paginationMeta = z.object({current_page: z.number().int(), next_page: z.number().int().nullable().optional(), prev_page: z.number().int().nullable().optional(), total_pages: z.number().int(), total_count: z.number().int()}); export const walletTransactionsPaginated = z.object({wallet_transactions: z.array(walletTransactionObject), meta: paginationMeta}); 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 all wallet transactions * * GET /wallets/{lago_id}/wallet_transactions */ export const getApiWalletsLagoIdWalletTransactions = async (args: GetApiWalletsLagoIdWalletTransactionsArgs, options?: GetApiWalletsLagoIdWalletTransactionsOptions) => { const {baseUrl = "https://api.getlago.com/api/v1", fetch: fetchFn = fetch, bearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.page != null) query.append("page", String(args.page)) if (args.per_page != null) query.append("per_page", String(args.per_page)) if (args.status != null) query.append("status", String(args.status)) if (args.transaction_status != null) query.append("transaction_status", String(args.transaction_status)) if (args.transaction_type != null) query.append("transaction_type", String(args.transaction_type)) if (args['metadata[key]'] != null) query.append("metadata[key]", String(args['metadata[key]'])) if (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/wallets/${encodeURIComponent(String(args.lago_id))}/wallet_transactions${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(walletTransactionsPaginated, await res.json()) };