import {z} from 'zod' export type GetApiWalletAllInOneOrgWalletRefArgs = {org_wallet_ref: number, from: string, to: string, page?: number | undefined, limit?: number | undefined}; export type GetApiWalletAllInOneOrgWalletRefOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const expense = z.object({_id: z.string().optional(), amount: z.number().optional(), fees: z.number().optional(), charge: z.number().optional(), original_currency: z.string().optional(), currency: z.string().optional(), original_amount: z.number().optional(), transaction_ref: z.string().optional(), provider_ref: z.string().optional(), employee_id: z.string().optional(), person: z.string().optional(), transaction_date: z.string().optional(), MerchantCategoryCode: z.string().optional(), MerchantIdentifier: z.string().optional(), fx_rate: z.number().optional(), card_vcn: z.string().optional(), receiver: z.string().optional(), payment_type: z.string().optional(), channel: z.string().optional(), subcategory: z.object({}).nullable().optional(), team: z.object({_id: z.string().optional(), name: z.string().optional(), code: z.string().optional()}).optional(), tag: z.array(z.string()).optional(), notes: z.string().optional(), risk: z.string().optional(), risk_notes: z.string().optional(), attachments: z.array(z.string()).optional(), payment_status: z.string().optional(), status: z.string().optional(), review_participants: z.array(z.string()).optional(), review_mandate: z.number().int().optional(), review_level: z.number().int().optional(), events: z.array(z.object({})).optional(), exported: z.boolean().optional(), sync_successful: z.boolean().optional(), org_wallet_ref: z.string().optional(), vendor: z.string().optional(), customer: z.object({}).nullable().optional(), subscription_id: z.string().optional(), account_number: z.string().optional(), reviews: z.array(z.object({})).optional(), createdAt: z.string().optional(), updatedAt: z.string().optional()}); export const topup = z.object({_id: z.string().optional(), ref: z.string().optional(), description: z.string().optional(), amount: z.number().optional(), account: z.string().optional(), channel: z.string().optional(), is_employee_topup: z.boolean().optional(), exported: z.boolean().optional(), sync_successful: z.boolean().optional(), created_by: z.string().optional(), status: z.string().optional(), createdAt: z.string().optional(), updatedAt: z.string().optional()}); export const refund = z.object({_id: z.string().optional(), ref: z.string().optional(), transaction_ref: z.string().optional(), description: z.string().optional(), amount: z.number().optional(), account: z.string().optional(), employee_id: z.string().optional(), status: z.string().optional(), org_wallet_ref: z.string().optional(), currency: z.string().optional(), createdAt: z.string().optional(), updatedAt: z.string().optional()}); export const statementEntry = z.object({_id: z.string().optional(), currency: z.string().optional(), org_wallet_ref: z.string().optional(), account: z.string().optional(), credit: z.number().optional(), debit: z.number().optional(), counter: z.number().int().optional(), description: z.string().optional(), ref: z.string().optional(), created_by: z.string().optional(), transaction_type: z.enum(["EXPENSE", "TOPUP", "REFUND", "REVERSAL"]).optional(), running_balance: z.number().optional(), business_running_balance: z.number().optional(), createdAt: z.string().optional(), updatedAt: z.string().optional(), expense: expense.optional(), topup: topup.optional(), refund: refund.optional()}); export const statementResponse = z.object({docs: z.array(statementEntry).optional(), total: z.number().int().optional(), limit: z.string().optional(), page: z.string().optional(), pages: z.number().int().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 }; /** * Retrieve Business Statements * * GET /wallet/all-in-one/{org_wallet_ref} */ export const getApiWalletAllInOneOrgWalletRef = async (args: GetApiWalletAllInOneOrgWalletRefArgs, options?: GetApiWalletAllInOneOrgWalletRefOptions) => { const {baseUrl = "https://api.boyahq.com/v1", fetch: fetchFn = fetch, ApiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.from != null) query.append("from", String(args.from)) if (args.to != null) query.append("to", String(args.to)) if (args.page != null) query.append("page", String(args.page)) if (args.limit != null) query.append("limit", String(args.limit)) if (ApiKeyAuth !== undefined) headers.set("X-API-KEY", ApiKeyAuth) const url = `${baseUrl.replace(/\/+$/, '')}/wallet/all-in-one/${encodeURIComponent(String(args.org_wallet_ref))}${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(statementResponse, await res.json()) };