import {z} from 'zod' export type GetApiApiPublicV1OnCallReportArgs = {Start: string, End: string, TeamIds?: Array | undefined, organizationId?: string | undefined}; export type GetApiApiPublicV1OnCallReportOptions = {baseUrl: string, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const allQuietApiPublicOnCallReportOnCallReportUserResponse = z.object({id: z.string(), displayName: z.string().nullable().optional(), email: z.string().nullable().optional(), userName: z.string().nullable().optional(), timeZoneId: z.string().nullable().optional()}); export const allQuietApiPublicOnCallReportOnCallReportTeamResponse = z.object({id: z.string(), displayName: z.string().nullable().optional(), timeZoneId: z.string().nullable().optional()}); export const allQuietApiPublicOnCallReportOnCallReportOnCallHistoryItemResponse = z.object({user: allQuietApiPublicOnCallReportOnCallReportUserResponse, team: allQuietApiPublicOnCallReportOnCallReportTeamResponse, start: z.string(), end: z.string(), tier: z.number().int()}); export const allQuietApiPublicOnCallReportOnCallReportResponse = z.object({onCallHistoryItems: z.array(allQuietApiPublicOnCallReportOnCallReportOnCallHistoryItemResponse).nullable()}); 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 on-call report for a date range * * GET /api/public/v1/on-call-report */ export const getApiApiPublicV1OnCallReport = async (args: GetApiApiPublicV1OnCallReportArgs, options: GetApiApiPublicV1OnCallReportOptions) => { const {baseUrl, fetch: fetchFn = fetch, ApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.Start != null) query.append("Start", String(args.Start)) if (args.End != null) query.append("End", String(args.End)) for (const item of args.TeamIds ?? []) query.append("TeamIds", String(item)) if (args.organizationId != null) query.append("organizationId", String(args.organizationId)) if (ApiKey !== undefined) headers.set("Authorization", ApiKey) const url = `${baseUrl.replace(/\/+$/, '')}/api/public/v1/on-call-report${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(allQuietApiPublicOnCallReportOnCallReportResponse, await res.json()) };