import {z} from 'zod' export type GetApiV1ActionsIdArgs = {id: string}; export type GetApiV1ActionsIdOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const userV1 = z.object({email: z.string().optional(), id: z.string(), name: z.string(), role: z.enum(["viewer", "responder", "administrator", "owner", "unset"]), slack_user_id: z.string().optional()}); export const externalIssueReferenceV1 = z.object({issue_name: z.string().optional(), issue_permalink: z.string().optional(), provider: z.enum(["asana", "click_up", "linear", "jira", "jira_server", "github", "gitlab", "shortcut"]).optional()}); export const actionV1 = z.object({assignee: userV1.optional(), completed_at: z.string().optional(), created_at: z.string(), description: z.string().optional(), external_issue_reference: externalIssueReferenceV1.optional(), follow_up: z.boolean(), id: z.string(), incident_id: z.string(), status: z.enum(["outstanding", "completed", "deleted", "not_doing"]), updated_at: z.string()}); export const actionsV1ShowResponseBody = z.object({action: actionV1}); 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 }; /** * Show Actions V1 * * GET /v1/actions/{id} */ export const getApiV1ActionsId = async (args: GetApiV1ActionsIdArgs, options?: GetApiV1ActionsIdOptions) => { 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(/\/+$/, '')}/v1/actions/${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(actionsV1ShowResponseBody, await res.json()) };