import {z} from 'zod' export type GetApiCollectIdArgs = {id: string}; export type GetApiCollectIdOptions = {baseUrl?: string | undefined, sec0?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; export const getApiCollectIdResponse = z.object({amount: z.number().optional(), balance_transaction: z.string().optional(), created_at: z.string().optional(), currency: z.string().optional(), destination: z.string().optional(), destination_details: z.string().optional(), holding_currency: z.string().optional(), id: z.string().optional(), metadata: z.string().optional(), payer_details: z.object({name: z.string().optional(), payer_bank: z.object({account_number: z.string().optional(), address: z.string().optional(), bank_codes: z.string().optional(), name: z.string().optional()}).optional(), additional_information: z.string().optional(), reference_id: z.string().optional(), payer_wallet: z.object({desposit_address: z.string().optional(), type: z.string().optional()}).optional()}).optional(), status: z.string().optional(), tracking_details: z.string().optional(), type: z.enum(["wire_transfer", "local_bank_transfer", "stablecoin_usdc", "stablecoin_usdt"]).optional(), on_behalf_of: z.string().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 }; /** * GET /collect/{id} */ export const getApiCollectId = async (args: GetApiCollectIdArgs, options?: GetApiCollectIdOptions) => { const {baseUrl = "https://service-sandbox.tazapay.com", fetch: fetchFn = fetch, sec0} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (sec0 !== undefined) headers.set('authorization', `Basic ${btoa(`${sec0.username}:${sec0.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/collect/${encodeURIComponent(String(args.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(getApiCollectIdResponse, await res.json()) };