import {z} from 'zod' export type GetApiApiV1SlaReportsPkArgs = {pk: string}; export type GetApiApiV1SlaReportsPkOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const sLAReport = z.object({pk: z.number().int().optional(), url: z.string().optional(), stats_url: z.string().optional(), services_tags: z.array(z.string()).optional(), services_selected: z.array(z.string()).optional(), reporting_groups: z.array(z.object({id: z.number().int().optional(), group_services: z.array(z.string()), created_at: z.string().optional(), modified_at: z.string().optional(), name: z.string().max(100)})).optional(), created_at: z.string().optional(), name: z.string().max(100), default_date_range: z.enum(["TODAY", "YESTERDAY", "LAST_7D", "LAST_30D", "THIS_WEEK", "LAST_WEEK", "THIS_MONTH", "LAST_MONTH"]).optional(), show_uptime_section: z.boolean().optional(), show_uptime_sla: z.boolean().optional(), filter_with_downtime: z.boolean().optional(), filter_uptime_sla_violations: z.boolean().optional(), uptime_section_sort: z.enum(["BY_UPTIME", "BY_SLA"]).optional(), show_response_time_section: z.boolean().optional(), show_response_time_sla: z.boolean().optional(), filter_slowest: z.boolean().optional(), filter_response_time_sla_violations: z.boolean().optional(), response_time_section_sort: z.enum(["BY_RESPONSE_TIME", "BY_SLA"]).optional(), logo: z.string().nullable().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 a single SLA report * * GET /api/v1/sla-reports/{pk}/ */ export const getApiApiV1SlaReportsPk = async (args: GetApiApiV1SlaReportsPkArgs, options: GetApiApiV1SlaReportsPkOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/sla-reports/${encodeURIComponent(String(args.pk))}/${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(sLAReport, await res.json()) };