import {z} from 'zod' export type GetApiApiOrgIdOncallIncidentsIncidentIdResponsesArgs = {org_id: string, incident_id: string}; export type GetApiApiOrgIdOncallIncidentsIncidentIdResponsesOptions = {baseUrl: string, Authorization?: string | undefined, fetch?: typeof fetch | undefined}; export const resolutionCause = z.enum(["config_change_or_deploy", "capacity_or_load", "dependency_failure", "expected_or_maintenance", "noisy_threshold", "data_or_ingestion_issue", "genuine_defect", "still_unknown"]); export const responderRole = z.enum(["owner", "impacted"]); export const responseState = z.enum(["triggered", "triaged", "acknowledged", "resolved"]); export const subjectType = z.enum(["alert", "incident"]); export const subjectRef = z.object({firing: z.number().int().gte(0), source_id: z.string(), subject_type: subjectType}); export const onCallResponse = z.object({acked_at: z.number().int().nullable().optional(), acked_by: z.string().nullable().optional(), cause: resolutionCause.nullable().optional(), cause_note: z.string().nullable().optional(), closed_at: z.number().int().nullable().optional(), exhausted_at: z.number().int().nullable().optional(), id: z.string(), incident_id: z.string().nullable().optional(), ladder_anchor: z.number().int().nullable().optional(), ladder_run: z.number().int().nullable().optional(), opened_at: z.number().int(), org_id: z.string(), origin_response_id: z.string().nullable().optional(), priority: z.number().int(), responder_role: responderRole.optional(), snoozed_until: z.number().int().nullable().optional(), state: responseState, subject: subjectRef, team_id: z.string().nullable().optional(), title: z.string().nullable().optional(), updated_at: z.number().int().optional()}); export const getApiApiOrgIdOncallIncidentsIncidentIdResponsesResponse = z.array(onCallResponse); 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 }; /** * The on-call records that paged for an incident * * GET /api/{org_id}/oncall/incidents/{incident_id}/responses */ export const getApiApiOrgIdOncallIncidentsIncidentIdResponses = async (args: GetApiApiOrgIdOncallIncidentsIncidentIdResponsesArgs, options: GetApiApiOrgIdOncallIncidentsIncidentIdResponsesOptions) => { const {baseUrl, fetch: fetchFn = fetch, Authorization} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (Authorization !== undefined) headers.set("Authorization", Authorization) const url = `${baseUrl.replace(/\/+$/, '')}/api/${encodeURIComponent(String(args.org_id))}/oncall/incidents/${encodeURIComponent(String(args.incident_id))}/responses${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(getApiApiOrgIdOncallIncidentsIncidentIdResponsesResponse, await res.json()) };