import {z} from 'zod' export type GetApiV1AdminAgentAgentsArgs = {status?: number | undefined, page?: number | undefined, pageSize?: number | undefined}; export type GetApiV1AdminAgentAgentsOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const agentV1AgentInfo = z.object({activatedAt: z.string().optional(), agentCode: z.string().optional(), consumeCommissionBps: z.number().int().optional(), createdAt: z.string().optional(), id: z.string().optional(), settlementCurrency: z.string().optional(), status: z.number().int().optional(), tier: z.number().int().optional(), topupCommissionBps: z.number().int().optional(), updatedAt: z.string().optional(), userId: z.string().optional()}); export const agentV1ListAgentsReply = z.object({agents: z.array(agentV1AgentInfo).optional(), total: 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 }; /** * ListAgents 列出代理商 * * GET /v1/admin/agent/agents */ export const getApiV1AdminAgentAgents = async (args: GetApiV1AdminAgentAgentsArgs, options: GetApiV1AdminAgentAgentsOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.status != null) query.append("status", String(args.status)) if (args.page != null) query.append("page", String(args.page)) if (args.pageSize != null) query.append("pageSize", String(args.pageSize)) const url = `${baseUrl.replace(/\/+$/, '')}/v1/admin/agent/agents${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(agentV1ListAgentsReply, await res.json()) };