import {z} from 'zod' export type GetApiWalletTransactionsLagoIdOptions = {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 walletTransaction = z.object({wallet_transaction: walletTransactionObject}); 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 }; /** * Retrieve a wallet transaction * * GET /wallet_transactions/{lago_id} */ export const getApiWalletTransactionsLagoId = async (options?: GetApiWalletTransactionsLagoIdOptions) => { 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 (bearerAuth !== undefined) headers.set('authorization', `Bearer ${bearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/wallet_transactions/${encodeURIComponent(String(args.lago_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(walletTransaction, await res.json()) };