import {z} from 'zod' export type Table = 0 | 1 | 2 | 5 | 6 | 7 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 19 | 20 | 21 | 22 | 23 | 25 | 26 | 27 | 31 | 32 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 50 | 51 | 52 | 53 | 55 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 72; export type ChannelType = 1 | 2 | 3 | 4 | 5 | 8 | 10 | 11 | 13 | 14 | 15 | 16; export type GetApiV1ReportSlasBreachesByhourArgs = {fromDate: string, toDate: string, linkedType: Table, pipelineIds?: string | undefined, channel?: ChannelType | undefined}; export type GetApiV1ReportSlasBreachesByhourOptions = {baseUrl: string, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const reportSlaBreachesTimeModel = z.object({forDate: z.string().nullable().optional(), fr: z.number().int().optional(), nr: z.number().int().optional(), resolution: z.number().int().optional(), total: z.number().int().optional()}); export const reportSlaBreachesTimeModelQueryResult = z.object({totalItems: z.number().int().optional(), items: z.array(reportSlaBreachesTimeModel).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 }; /** * SLA breaches by hour * * GET /v1/report/slas/breaches/byhour * * Also accepts auth: API Key */ export const getApiV1ReportSlasBreachesByhour = async (args: GetApiV1ReportSlasBreachesByhourArgs, options: GetApiV1ReportSlasBreachesByhourOptions) => { const {baseUrl, fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.fromDate != null) query.append("fromDate", String(args.fromDate)) if (args.toDate != null) query.append("toDate", String(args.toDate)) if (args.linkedType != null) query.append("linkedType", String(args.linkedType)) if (args.pipelineIds != null) query.append("pipelineIds", String(args.pipelineIds)) if (args.channel != null) query.append("channel", String(args.channel)) if (Bearer !== undefined) headers.set('authorization', `Bearer ${Bearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/report/slas/breaches/byhour${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(reportSlaBreachesTimeModelQueryResult, await res.json()) };