import {z} from 'zod' export type GetApiApiReportingV1TeamTeamOncallLogArgs = {'X-VO-Api-Id': string, 'X-VO-Api-Key': string, team: string, start?: string | undefined, end?: string | undefined, userName?: string | undefined}; export type GetApiApiReportingV1TeamTeamOncallLogOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const escalationPolicySummary = z.object({name: z.string(), slug: z.string(), _selfUrl: z.string()}); export const onCallInterval = z.object({on: z.string().optional(), off: z.string().optional(), duration: z.object({hours: z.number().optional(), minutes: z.number().optional()}).optional(), escalationPolicy: escalationPolicySummary.optional()}); export const userLog = z.object({userId: z.string().optional(), total: z.object({hours: z.number().optional(), minutes: z.number().optional()}).optional(), adjustedTotal: z.object({hours: z.number().optional(), minutes: z.number().optional()}).optional(), log: z.array(onCallInterval).optional()}); export const onCallLog = z.object({teamSlug: z.string().optional(), start: z.string().optional(), end: z.string().optional(), userLogs: z.array(userLog).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 }; /** * A list of shift changes for a team * * GET /api-reporting/v1/team/{team}/oncall/log */ export const getApiApiReportingV1TeamTeamOncallLog = async (args: GetApiApiReportingV1TeamTeamOncallLogArgs, options?: GetApiApiReportingV1TeamTeamOncallLogOptions) => { const {baseUrl = "https://api.victorops.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args['X-VO-Api-Id'] != null) headers.set("X-VO-Api-Id", String(args['X-VO-Api-Id'])) if (args['X-VO-Api-Key'] != null) headers.set("X-VO-Api-Key", String(args['X-VO-Api-Key'])) if (args.start != null) query.append("start", String(args.start)) if (args.end != null) query.append("end", String(args.end)) if (args.userName != null) query.append("userName", String(args.userName)) const url = `${baseUrl.replace(/\/+$/, '')}/api-reporting/v1/team/${encodeURIComponent(String(args.team))}/oncall/log${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(onCallLog, await res.json()) };