import {z} from 'zod' export type GetApiAdminInviteAccountsArgs = {address?: string | undefined, description?: string | undefined, status?: string | undefined, sort?: string | undefined, limit?: number | undefined, page?: number | undefined, flagged?: boolean | undefined, invited_by?: string | undefined, created_by?: string | undefined, code?: string | undefined}; export type GetApiAdminInviteAccountsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const apiAccountItem = z.object({address: z.string().optional(), status: z.string().optional(), invited_by: z.string().optional(), invite_code: z.string().optional(), description: z.string().optional(), flagged: z.boolean().optional(), created_at: z.string().optional(), activated_at: z.string().optional(), invitee_count: z.string().optional(), code_count: z.string().optional(), volume: z.string().optional(), created_by: z.string().optional()}); export const apiListAccountsResponse = z.object({accounts: z.array(apiAccountItem).optional(), total: 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 }; /** * List invite accounts * * GET /admin/invite/accounts */ export const getApiAdminInviteAccounts = async (args: GetApiAdminInviteAccountsArgs, options?: GetApiAdminInviteAccountsOptions) => { const {baseUrl = "https://api.testnet.rise.trade", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.address != null) query.append("address", String(args.address)) if (args.description != null) query.append("description", String(args.description)) if (args.status != null) query.append("status", String(args.status)) if (args.sort != null) query.append("sort", String(args.sort)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.page != null) query.append("page", String(args.page)) if (args.flagged != null) query.append("flagged", String(args.flagged)) if (args.invited_by != null) query.append("invited_by", String(args.invited_by)) if (args.created_by != null) query.append("created_by", String(args.created_by)) if (args.code != null) query.append("code", String(args.code)) const url = `${baseUrl.replace(/\/+$/, '')}/admin/invite/accounts${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(apiListAccountsResponse, await res.json()) };