import {z} from 'zod' export type GetApiV1IncidentAttachmentsArgs = {incident_id?: string | undefined, external_id?: string | undefined, resource_type?: ('pager_duty_incident' | 'opsgenie_alert' | 'datadog_monitor_alert' | 'github_pull_request' | 'gitlab_merge_request' | 'sentry_issue' | 'jira_issue' | 'atlassian_statuspage_incident' | 'zendesk_ticket' | 'google_calendar_event' | 'outlook_calendar_event' | 'scrubbed' | 'statuspage_incident') | undefined}; export type GetApiV1IncidentAttachmentsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const externalResourceV1 = z.object({external_id: z.string(), permalink: z.string(), resource_type: z.enum(["pager_duty_incident", "opsgenie_alert", "datadog_monitor_alert", "github_pull_request", "gitlab_merge_request", "sentry_issue", "jira_issue", "atlassian_statuspage_incident", "zendesk_ticket", "google_calendar_event", "outlook_calendar_event", "scrubbed", "statuspage_incident"]), title: z.string()}); export const incidentAttachmentV1 = z.object({id: z.string(), incident_id: z.string(), resource: externalResourceV1}); export const incidentAttachmentsV1ListResponseBody = z.object({incident_attachments: z.array(incidentAttachmentV1)}); 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 }; /** * List Incident Attachments V1 * * GET /v1/incident_attachments */ export const getApiV1IncidentAttachments = async (args: GetApiV1IncidentAttachmentsArgs, options?: GetApiV1IncidentAttachmentsOptions) => { const {baseUrl = "https:////api.incident.io", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.incident_id != null) query.append("incident_id", String(args.incident_id)) if (args.external_id != null) query.append("external_id", String(args.external_id)) if (args.resource_type != null) query.append("resource_type", String(args.resource_type)) const url = `${baseUrl.replace(/\/+$/, '')}/v1/incident_attachments${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(incidentAttachmentsV1ListResponseBody, await res.json()) };