import {z} from 'zod' export type GetApiV2EscalationPathsIdArgs = {id: string}; export type GetApiV2EscalationPathsIdOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const conditionOperationV2 = z.object({label: z.string(), value: z.string()}); export const engineParamBindingValueV2 = z.object({label: z.string(), literal: z.string().optional(), reference: z.string().optional()}); export const engineParamBindingV2 = z.object({array_value: z.array(engineParamBindingValueV2).optional(), value: engineParamBindingValueV2.optional()}); export const conditionSubjectV2 = z.object({label: z.string(), reference: z.string()}); export const conditionV2 = z.object({operation: conditionOperationV2, param_bindings: z.array(engineParamBindingV2), subject: conditionSubjectV2}); export const escalationPathNodeIfElseV2 = z.object({conditions: z.array(conditionV2), else_path: z.array(z.lazy(() => escalationPathNodeV2)), then_path: z.array(z.lazy(() => escalationPathNodeV2))}); export const escalationPathRoundRobinConfigV2 = z.object({enabled: z.boolean(), rotate_after_seconds: z.number().int().optional()}); export const escalationPathTargetV2 = z.object({id: z.string(), schedule_mode: z.enum(["currently_on_call", "all_users_for_rota", "all_users", ""]).optional(), type: z.enum(["schedule", "user", "slack_channel"]), urgency: z.enum(["high", "low"])}); export const escalationPathNodeLevelV2 = z.object({round_robin_config: escalationPathRoundRobinConfigV2.optional(), targets: z.array(escalationPathTargetV2), time_to_ack_interval_condition: z.enum(["active", "inactive"]).optional(), time_to_ack_seconds: z.number().int().optional(), time_to_ack_weekday_interval_config_id: z.string().optional()}); export const escalationPathNodeNotifyChannelV2 = z.object({targets: z.array(escalationPathTargetV2), time_to_ack_interval_condition: z.enum(["active", "inactive"]).optional(), time_to_ack_seconds: z.number().int().optional(), time_to_ack_weekday_interval_config_id: z.string().optional()}); export const escalationPathNodeRepeatV2 = z.object({repeat_times: z.number().int(), to_node: z.string()}); export const escalationPathNodeV2: z.ZodType = z.object({id: z.string(), if_else: escalationPathNodeIfElseV2.optional(), level: escalationPathNodeLevelV2.optional(), notify_channel: escalationPathNodeNotifyChannelV2.optional(), repeat: escalationPathNodeRepeatV2.optional(), type: z.enum(["if_else", "repeat", "level", "notify_channel"])}); export const weekdayIntervalV2 = z.object({end_time: z.string(), start_time: z.string(), weekday: z.string()}); export const weekdayIntervalConfigV2 = z.object({id: z.string(), name: z.string(), timezone: z.string(), weekday_intervals: z.array(weekdayIntervalV2)}); export const escalationPathV2 = z.object({id: z.string(), name: z.string(), path: z.array(escalationPathNodeV2), working_hours: z.array(weekdayIntervalConfigV2).optional()}); export const escalationsV2ShowPathResponseBody = z.object({escalation_path: escalationPathV2}); 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 }; /** * ShowPath Escalations V2 * * GET /v2/escalation_paths/{id} */ export const getApiV2EscalationPathsId = async (args: GetApiV2EscalationPathsIdArgs, options?: GetApiV2EscalationPathsIdOptions) => { const {baseUrl = "https:////api.incident.io", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/v2/escalation_paths/${encodeURIComponent(String(args.id))}${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(escalationsV2ShowPathResponseBody, await res.json()) };