import {z} from 'zod' export type GetApiUsersIdTransactionsUsdcArgs = {id: string, offset?: number | undefined, limit?: number | undefined, sort_method?: ('date' | 'transaction_type') | undefined, sort_direction?: ('asc' | 'desc') | undefined, 'Encoded-Data-Message'?: string | undefined, 'Encoded-Data-Signature'?: string | undefined, type?: (Array<'purchase_content' | 'transfer' | 'internal_transfer' | 'prepare_withdrawal' | 'recover_withdrawal' | 'withdrawal' | 'purchase_stripe'>) | undefined, include_system_transactions?: boolean | undefined, method?: ('send' | 'receive') | undefined}; export type GetApiUsersIdTransactionsUsdcOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const versionMetadata = z.object({service: z.string(), version: z.string()}); export const transactionDetails = z.object({transaction_date: z.string(), transaction_type: z.string(), method: z.string(), signature: z.string(), user_bank: z.string(), change: z.string(), balance: z.string(), metadata: z.object({})}); export const transactionHistoryResponse = z.object({latest_chain_block: z.number().int(), latest_indexed_block: z.number().int(), latest_chain_slot_plays: z.number().int(), latest_indexed_slot_plays: z.number().int(), signature: z.string(), timestamp: z.string(), version: versionMetadata, data: z.array(transactionDetails).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 }; /** * Gets the user's $USDC transaction history within the App * * GET /users/{id}/transactions/usdc */ export const getApiUsersIdTransactionsUsdc = async (args: GetApiUsersIdTransactionsUsdcArgs, options: GetApiUsersIdTransactionsUsdcOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.offset != null) query.append("offset", String(args.offset)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.sort_method != null) query.append("sort_method", String(args.sort_method)) if (args.sort_direction != null) query.append("sort_direction", String(args.sort_direction)) if (args['Encoded-Data-Message'] != null) headers.set("Encoded-Data-Message", String(args['Encoded-Data-Message'])) if (args['Encoded-Data-Signature'] != null) headers.set("Encoded-Data-Signature", String(args['Encoded-Data-Signature'])) for (const item of args.type ?? []) query.append("type", String(item)) if (args.include_system_transactions != null) query.append("include_system_transactions", String(args.include_system_transactions)) if (args.method != null) query.append("method", String(args.method)) const url = `${baseUrl.replace(/\/+$/, '')}/users/${encodeURIComponent(String(args.id))}/transactions/usdc${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(transactionHistoryResponse, await res.json()) };