import {z} from 'zod' export type AllQuietApiPublicOnCallOverrideOnCallOverrideResourceRequest = {userId: string, teamId?: (string | null) | undefined, escalationTier?: (number | null) | undefined, replacementUserIds?: (Array | null) | undefined, start?: (string | null) | undefined, end?: (string | null) | undefined, type: string}; export type CreateApiApiPublicV1OnCallOverrideArgs = {provision?: boolean | undefined, body: AllQuietApiPublicOnCallOverrideOnCallOverrideResourceRequest}; export type CreateApiApiPublicV1OnCallOverrideOptions = {baseUrl: string, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const allQuietApiPublicOnCallOverrideOnCallOverrideResourceResponse = z.object({id: z.string().optional(), userId: z.string().optional(), teamId: z.string().nullable().optional(), replacementUserIds: z.array(z.string()).nullable().optional(), type: z.string().nullable().optional(), start: z.string().nullable().optional(), end: z.string().nullable().optional(), isProvisioned: z.boolean().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 }; /** * Create an on-call override * * POST /api/public/v1/on-call-override */ export const createApiApiPublicV1OnCallOverride = async (args: CreateApiApiPublicV1OnCallOverrideArgs, options: CreateApiApiPublicV1OnCallOverrideOptions) => { const {baseUrl, fetch: fetchFn = fetch, ApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.provision != null) query.append("provision", String(args.provision)) if (ApiKey !== undefined) headers.set("Authorization", ApiKey) const url = `${baseUrl.replace(/\/+$/, '')}/api/public/v1/on-call-override${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(allQuietApiPublicOnCallOverrideOnCallOverrideResourceResponse, await res.json()) };