import {z} from 'zod' export type GetApiApiV1PartnerAccountsCustomerAuthIdTransactionsArgs = {customer_auth_id: string, from_date?: string | undefined, to_date?: string | undefined, transaction_type?: ('recharge' | 'debit' | 'refund' | 'transfer') | undefined, page?: number | undefined, per_page?: number | undefined}; export type GetApiApiV1PartnerAccountsCustomerAuthIdTransactionsOptions = {baseUrl?: string | undefined, AuthID?: string | undefined, AuthToken?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiApiV1PartnerAccountsCustomerAuthIdTransactionsResponse = z.object({transactions: z.array(z.object({id: z.string(), account_id: z.string(), balance_id: z.string(), type: z.string(), amount: z.number().int(), currency: z.string(), description: z.string(), reference: z.string(), status: z.string(), processed_at: z.string(), created_at: z.string(), updated_at: z.string()})), summary: z.object({total_transactions: z.number().int(), total_debit: z.number().int(), total_credit: z.number().int(), net_amount: z.number().int(), by_reference_type: z.array(z.object({reference_type: z.string(), total_debit: z.number().int(), total_credit: z.number().int(), count: z.number().int()}))}), total: z.number().int(), page: z.number().int(), per_page: z.number().int(), total_pages: z.number().int(), account_auth_id: z.string()}); 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 customer transactions * * GET /api/v1/partner/accounts/{customer_auth_id}/transactions */ export const getApiApiV1PartnerAccountsCustomerAuthIdTransactions = async (args: GetApiApiV1PartnerAccountsCustomerAuthIdTransactionsArgs, options?: GetApiApiV1PartnerAccountsCustomerAuthIdTransactionsOptions) => { const {baseUrl = "https://api.vobiz.ai", fetch: fetchFn = fetch, AuthID, AuthToken} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.from_date != null) query.append("from_date", String(args.from_date)) if (args.to_date != null) query.append("to_date", String(args.to_date)) if (args.transaction_type != null) query.append("transaction_type", String(args.transaction_type)) if (args.page != null) query.append("page", String(args.page)) if (args.per_page != null) query.append("per_page", String(args.per_page)) if (AuthID !== undefined) headers.set("X-Auth-ID", AuthID) if (AuthToken !== undefined) headers.set("X-Auth-Token", AuthToken) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/partner/accounts/${encodeURIComponent(String(args.customer_auth_id))}/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(getApiApiV1PartnerAccountsCustomerAuthIdTransactionsResponse, await res.json()) };