import {z} from 'zod' export type CreateApiApiV1AlarmLogMonitorAddArgs = {grp_id?: number | undefined, endpoint_id?: number | undefined, path: string, strategy: string}; export type CreateApiApiV1AlarmLogMonitorAddOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const createApiApiV1AlarmLogMonitorAddResponse = z.string(); 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 }; /** * 日志告警配置接口 : 新增 * * POST /api/v1/alarm/log/monitor/add */ export const createApiApiV1AlarmLogMonitorAdd = async (args: CreateApiApiV1AlarmLogMonitorAddArgs, options: CreateApiApiV1AlarmLogMonitorAddOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.grp_id != null) query.append("grp_id", String(args.grp_id)) if (args.endpoint_id != null) query.append("endpoint_id", String(args.endpoint_id)) if (args.path != null) query.append("path", String(args.path)) if (args.strategy != null) query.append("strategy", String(args.strategy)) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/alarm/log/monitor/add${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(createApiApiV1AlarmLogMonitorAddResponse, await res.json()) };