import {z} from 'zod' export type GetApiApiPublicV1OnCallArgs = {TeamIds?: Array | undefined, UserIds?: Array | undefined, Timestamp?: string | undefined}; export type GetApiApiPublicV1OnCallOptions = {baseUrl: string, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const allQuietApiPublicOnCallOnCallResponseUser = z.object({id: z.string().optional(), displayName: z.string().nullable().optional(), avatarUrl: z.string().nullable().optional(), email: z.string().nullable().optional()}); export const allQuietApiPublicOnCallOnCallResponseTeam = z.object({id: z.string().optional(), displayName: z.string().nullable().optional(), timeZoneId: z.string().nullable()}); export const allQuietApiPublicOnCallOnCallResponseAvailability = z.object({tier: z.number().int().optional(), isOnline: z.boolean().optional(), fillUp: z.boolean().optional()}); export const allQuietApiPublicOnCallOnCallResponseMembership = z.object({user: allQuietApiPublicOnCallOnCallResponseUser.optional(), team: allQuietApiPublicOnCallOnCallResponseTeam.optional(), availabilities: z.array(allQuietApiPublicOnCallOnCallResponseAvailability).nullable().optional()}); export const allQuietApiPublicOnCallOnCallResponse = z.object({memberships: z.array(allQuietApiPublicOnCallOnCallResponseMembership).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 current on-call assignments * * GET /api/public/v1/on-call */ export const getApiApiPublicV1OnCall = async (args: GetApiApiPublicV1OnCallArgs, options: GetApiApiPublicV1OnCallOptions) => { const {baseUrl, fetch: fetchFn = fetch, ApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") for (const item of args.TeamIds ?? []) query.append("TeamIds", String(item)) for (const item of args.UserIds ?? []) query.append("UserIds", String(item)) if (args.Timestamp != null) query.append("Timestamp", String(args.Timestamp)) if (ApiKey !== undefined) headers.set("Authorization", ApiKey) const url = `${baseUrl.replace(/\/+$/, '')}/api/public/v1/on-call${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(allQuietApiPublicOnCallOnCallResponse, await res.json()) };