import {z} from 'zod' export type GetApiUsersIdTransactionsUsdcCountArgs = {id: string, type?: (Array<'purchase_content' | 'transfer' | 'internal_transfer' | 'prepare_withdrawal' | 'recover_withdrawal' | 'withdrawal' | 'purchase_stripe'>) | undefined, include_system_transactions?: boolean | undefined, method?: ('send' | 'receive') | undefined, 'Encoded-Data-Message'?: string | undefined, 'Encoded-Data-Signature'?: string | undefined}; export type GetApiUsersIdTransactionsUsdcCountOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const versionMetadata = z.object({service: z.string(), version: z.string()}); export const transactionHistoryCountResponse = 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.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 }; /** * Gets the count of the user's $USDC transaction history within the App * * GET /users/{id}/transactions/usdc/count */ export const getApiUsersIdTransactionsUsdcCount = async (args: GetApiUsersIdTransactionsUsdcCountArgs, options: GetApiUsersIdTransactionsUsdcCountOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") 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)) 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'])) const url = `${baseUrl.replace(/\/+$/, '')}/users/${encodeURIComponent(String(args.id))}/transactions/usdc/count${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(transactionHistoryCountResponse, await res.json()) };