import {z} from 'zod' export type GetApiApiOrgIdOncallTeamsTeamIdEscalationPreviewArgs = {org_id: string, team_id: string, priority?: string | undefined, at?: number | undefined}; export type GetApiApiOrgIdOncallTeamsTeamIdEscalationPreviewOptions = {baseUrl: string, Authorization?: string | undefined, fetch?: typeof fetch | undefined}; export const channel = z.enum(["email", "webhook", "sms", "voice", "slack"]); export const previewL0 = z.object({allow_downgrade: z.boolean(), allow_promotion: z.boolean(), allow_suppress: z.boolean(), available: z.boolean(), mode: z.string(), summary: z.string(), triage_budget_seconds: z.number().int()}); export const previewRecipient = z.object({deliverable_channels: z.array(channel), reason: z.string(), user_email: z.string(), why_not: z.string().nullable().optional(), would_a_page_land: z.boolean()}); export const previewRung = z.object({after_micros: z.number().int(), recipients: z.array(previewRecipient), resolves_to_nobody: z.boolean(), targets: z.array(z.string())}); export const escalationPreview = z.object({at: z.number().int(), channels: z.array(channel), cross_team_moves: z.array(z.string()), ends_with: z.string(), l0: previewL0, pages_anyone: z.boolean(), priority: z.string(), reaches_nobody: z.boolean(), rungs: z.array(previewRung), team_id: z.string(), team_name: z.string()}); 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 }; /** * Resolve a team's ladder against right now, sending nothing * * GET /api/{org_id}/oncall/teams/{team_id}/escalation-preview */ export const getApiApiOrgIdOncallTeamsTeamIdEscalationPreview = async (args: GetApiApiOrgIdOncallTeamsTeamIdEscalationPreviewArgs, options: GetApiApiOrgIdOncallTeamsTeamIdEscalationPreviewOptions) => { const {baseUrl, fetch: fetchFn = fetch, Authorization} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.priority != null) query.append("priority", String(args.priority)) if (args.at != null) query.append("at", String(args.at)) if (Authorization !== undefined) headers.set("Authorization", Authorization) const url = `${baseUrl.replace(/\/+$/, '')}/api/${encodeURIComponent(String(args.org_id))}/oncall/teams/${encodeURIComponent(String(args.team_id))}/escalation-preview${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(escalationPreview, await res.json()) };