import {z} from 'zod' export type GetApiApiV14CustomersCustomerUuidTransactionsArgs = {customer_uuid: string, detailed?: boolean | undefined, limit?: number | undefined, offset?: number | undefined}; export type GetApiApiV14CustomersCustomerUuidTransactionsOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const billingDataSerializerField = z.object({name: z.string().max(100).nullable().optional(), first_name: z.string().max(100).nullable().optional(), last_name: z.string().max(150).nullable().optional(), email: z.string().nullable().optional(), phone_number: z.string().nullable().optional(), address: z.string().max(500).optional(), address1: z.string().max(500).optional(), apartment: z.string().max(10).optional(), floor: z.string().max(10).optional(), building: z.string().max(255).optional(), street: z.string().max(500).optional(), city: z.string().max(255).optional(), state: z.string().max(255).nullable().optional(), country: z.string().max(255).optional(), postal_code: z.string().max(10).optional(), mobile_wallet_number: z.string().nullable().optional()}); export const transaction = z.object({id: z.string(), custom_fields: z.unknown(), status: z.string().max(50).optional(), amount: z.union([z.number(), z.record(z.string(), z.unknown())]), amount_currency: z.string(), payment_method: z.string(), payment_method_name: z.string(), service_provider: z.string().nullable(), account: z.string(), billing_data: billingDataSerializerField, is_retry: z.boolean(), authentication_data: z.unknown(), authentication: z.unknown(), full_capture: z.boolean(), created: z.string(), modified: z.string()}); export const paginatedTransactionList = z.object({count: z.number().int().optional(), next: z.string().nullable().optional(), previous: z.string().nullable().optional(), results: z.array(transaction).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 }; /** * List transactions * * GET /api/v1.4/customers/{customer_uuid}/transactions/ * * Also accepts auth: AccessTokenAuth */ export const getApiApiV14CustomersCustomerUuidTransactions = async (args: GetApiApiV14CustomersCustomerUuidTransactionsArgs, options?: GetApiApiV14CustomersCustomerUuidTransactionsOptions) => { const {baseUrl = "https://web.moneyhash.io", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.detailed != null) query.append("detailed", String(args.detailed)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.offset != null) query.append("offset", String(args.offset)) if (ApiKeyAuth !== undefined) headers.set("X-Api-Key", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1.4/customers/${encodeURIComponent(String(args.customer_uuid))}/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(paginatedTransactionList, await res.json()) };