import {z} from 'zod' export type GetApiRestOperations10IncidentsIncidentIdArgs = {incidentId: string}; export type GetApiRestOperations10IncidentsIncidentIdOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiRestOperations10IncidentsIncidentIdResponse = z.object({schemaVersion: z.literal("1.0"), id: z.string().max(255), updateSequenceNumber: z.number().int(), affectedComponents: z.array(z.string()), summary: z.string().max(255), description: z.string().max(5000), url: z.string().max(2000), createdDate: z.string(), lastUpdated: z.string(), severity: z.object({level: z.enum(["P1", "P2", "P3", "P4", "P5", "unknown"])}).optional(), status: z.enum(["open", "resolved", "unknown"]), associations: z.array(z.object({associationType: z.enum(["issueIdOrKeys", "serviceIdOrKeys", "ati:cloud:compass:event-source"]).optional(), values: z.array(z.string()).optional()})).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 a Incident by ID * * GET /rest/operations/1.0/incidents/{incidentId} */ export const getApiRestOperations10IncidentsIncidentId = async (args: GetApiRestOperations10IncidentsIncidentIdArgs, options?: GetApiRestOperations10IncidentsIncidentIdOptions) => { const {baseUrl = "https://your-domain.atlassian.net", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/rest/operations/1.0/incidents/${encodeURIComponent(String(args.incidentId))}${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(getApiRestOperations10IncidentsIncidentIdResponse, await res.json()) };