import {z} from 'zod' export type GetApiUsersIdActionsArgs = {id: number, page?: number | undefined, limit?: number | undefined, wallet?: string | undefined, actions?: Array | undefined, withdrawalType?: number | undefined, assets?: Array | undefined, assetSymbols?: Array | undefined, startTimestamp?: number | undefined, endTimestamp?: number | undefined, status?: number | undefined}; export type GetApiUsersIdActionsOptions = {baseUrl: string, bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const userActionEntity = z.object({}); export const getApiUsersIdActionsResponse = z.array(userActionEntity); 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 actions for a user * * GET /users/{id}/actions */ export const getApiUsersIdActions = async (args: GetApiUsersIdActionsArgs, options: GetApiUsersIdActionsOptions) => { const {baseUrl, fetch: fetchFn = fetch, bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.page != null) query.append("page", String(args.page)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.wallet != null) query.append("wallet", String(args.wallet)) for (const item of args.actions ?? []) query.append("actions", String(item)) if (args.withdrawalType != null) query.append("withdrawalType", String(args.withdrawalType)) for (const item of args.assets ?? []) query.append("assets", String(item)) for (const item of args.assetSymbols ?? []) query.append("assetSymbols", String(item)) if (args.startTimestamp != null) query.append("startTimestamp", String(args.startTimestamp)) if (args.endTimestamp != null) query.append("endTimestamp", String(args.endTimestamp)) if (args.status != null) query.append("status", String(args.status)) if (bearer !== undefined) headers.set('authorization', `Bearer ${bearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/users/${encodeURIComponent(String(args.id))}/actions${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(getApiUsersIdActionsResponse, await res.json()) };