import {z} from 'zod' export type GetApiV1AdminRateLimitsArgs = {scopeType?: string | undefined, scopeId?: string | undefined, limitType?: string | undefined, enabled?: boolean | undefined, page?: number | undefined, size?: number | undefined}; export type GetApiV1AdminRateLimitsOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const adminV1RateLimitConfig = z.object({createdAt: z.string().optional(), createdBy: z.string().optional(), description: z.string().optional(), enabled: z.boolean().optional(), id: z.string().optional(), limitType: z.string().optional(), limitValue: z.number().int().optional(), scopeId: z.string().optional(), scopeType: z.string().optional(), updatedAt: z.string().optional(), updatedBy: z.string().optional()}); export const adminV1ListRateLimitConfigsReply = z.object({items: z.array(adminV1RateLimitConfig).optional(), page: z.number().int().optional(), size: z.number().int().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 }; /** * ListRateLimitConfigs 列出限流配置 * * GET /v1/admin/rate-limits */ export const getApiV1AdminRateLimits = async (args: GetApiV1AdminRateLimitsArgs, options: GetApiV1AdminRateLimitsOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.scopeType != null) query.append("scopeType", String(args.scopeType)) if (args.scopeId != null) query.append("scopeId", String(args.scopeId)) if (args.limitType != null) query.append("limitType", String(args.limitType)) if (args.enabled != null) query.append("enabled", String(args.enabled)) if (args.page != null) query.append("page", String(args.page)) if (args.size != null) query.append("size", String(args.size)) const url = `${baseUrl.replace(/\/+$/, '')}/v1/admin/rate-limits${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(adminV1ListRateLimitConfigsReply, await res.json()) };