import {z} from 'zod' export type GetApiApiPublicV1OnCallReportSumArgs = {Start: string, End: string, UserId?: string | undefined, TeamId?: string | undefined, MaxTier?: number | undefined, organizationId?: string | undefined}; export type GetApiApiPublicV1OnCallReportSumOptions = {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 allQuietApiPublicOnCallReportOnCallReportUserSumResponse = z.object({user: allQuietApiPublicOnCallReportOnCallReportUserResponse, netOnCallMinutes: z.number().int()}); export const allQuietApiPublicOnCallReportOnCallReportSumResponse = z.object({userSums: z.array(allQuietApiPublicOnCallReportOnCallReportUserSumResponse).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 aggregated on-call hours for a date range * * GET /api/public/v1/on-call-report/sum */ export const getApiApiPublicV1OnCallReportSum = async (args: GetApiApiPublicV1OnCallReportSumArgs, options: GetApiApiPublicV1OnCallReportSumOptions) => { 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)) if (args.UserId != null) query.append("UserId", String(args.UserId)) if (args.TeamId != null) query.append("TeamId", String(args.TeamId)) if (args.MaxTier != null) query.append("MaxTier", String(args.MaxTier)) 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/sum${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(allQuietApiPublicOnCallReportOnCallReportSumResponse, await res.json()) };