import {z} from 'zod' export type GetApiAdminProviderTrafficMonitorTasksArgs = {page?: number | undefined, pageSize?: number | undefined, providerId?: number | undefined, taskType?: string | undefined, status?: string | undefined}; export type GetApiAdminProviderTrafficMonitorTasksOptions = {baseUrl?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiAdminProviderTrafficMonitorTasksResponse = z.object({code: z.number().int().optional(), data: z.object({}).optional(), message: z.string().optional(), msg: 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 }; /** * 获取流量监控任务列表 * * GET /admin/provider/traffic-monitor/tasks */ export const getApiAdminProviderTrafficMonitorTasks = async (args: GetApiAdminProviderTrafficMonitorTasksArgs, options?: GetApiAdminProviderTrafficMonitorTasksOptions) => { const {baseUrl = "http://localhost:8888/api/v1", fetch: fetchFn = fetch, BearerAuth} = 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.pageSize != null) query.append("pageSize", String(args.pageSize)) if (args.providerId != null) query.append("providerId", String(args.providerId)) if (args.taskType != null) query.append("taskType", String(args.taskType)) if (args.status != null) query.append("status", String(args.status)) if (BearerAuth !== undefined) headers.set("Authorization", BearerAuth) const url = `${baseUrl.replace(/\/+$/, '')}/admin/provider/traffic-monitor/tasks${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(getApiAdminProviderTrafficMonitorTasksResponse, await res.json()) };