import {z} from 'zod' export type GetApiApiPublicV1IncidentSearchChangesArgs = {Cursor?: string | undefined, Limit?: number | undefined, Since?: string | undefined, IncidentIds?: Array | undefined, Statuses?: Array | undefined, Severities?: Array | undefined, IntegrationIds?: Array | undefined, TeamIds?: Array | undefined, IsArchived?: boolean | undefined, IncludeSnoozed?: boolean | undefined}; export type GetApiApiPublicV1IncidentSearchChangesOptions = {baseUrl: string, ApiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const allQuietApiPublicIncidentsIncidentResourceEntityDto = z.object({id: z.string(), displayName: z.string().nullable()}); export const allQuietApiPublicIncidentsIncidentResourceVoiceMail = z.object({downloadUrl: z.string().nullable(), privateDownloadUrl: z.string().nullable()}); export const allQuietApiPublicIncidentsIncidentResourceAttribute = z.object({name: z.string().nullable(), value: z.string().nullable(), isImage: z.boolean(), isGroupingKey: z.boolean(), hideInPreviews: z.boolean(), voiceMail: allQuietApiPublicIncidentsIncidentResourceVoiceMail.optional()}); export const allQuietApiPublicIncidentsIncidentResourceUser = z.object({id: z.string().optional(), displayName: z.string().nullable(), avatarUrl: z.string().nullable(), email: z.string().nullable()}); export const allQuietApiPublicIncidentsIncidentResourceUserExternal = z.object({id: z.string().nullable(), displayName: z.string().nullable(), avatarUrl: z.string().nullable(), provider: z.string().nullable()}); export const allQuietApiPublicIncidentsIncidentResourceModification = z.object({timestamp: z.string(), intent: z.string().nullable(), user: allQuietApiPublicIncidentsIncidentResourceUser, externalUser: allQuietApiPublicIncidentsIncidentResourceUserExternal}); export const allQuietApiPublicIncidentsIncidentResourceAttributeChange = z.object({name: z.string().nullable(), newValue: z.string().nullable(), oldValue: z.string().nullable()}); export const allQuietApiPublicIncidentsIncidentResourceEvent = z.object({severity: z.string().nullable(), status: z.string().nullable(), modification: allQuietApiPublicIncidentsIncidentResourceModification, userAssignments: z.array(allQuietApiPublicIncidentsIncidentResourceUser).nullable(), onCallUsers: z.array(allQuietApiPublicIncidentsIncidentResourceUser).nullable(), message: z.string().nullable(), messageIsPublic: z.boolean().nullable(), unattended: z.boolean(), teams: z.array(allQuietApiPublicIncidentsIncidentResourceEntityDto).nullable(), attributeChanges: z.array(allQuietApiPublicIncidentsIncidentResourceAttributeChange).nullable()}); export const allQuietApiPublicIncidentsIncidentResourceSnoozingProperties = z.object({snoozedUntil: z.string().nullable()}); export const allQuietApiPublicIncidentsIncidentResourceSubIncidentEvent = z.object({severity: z.string().nullable(), status: z.string().nullable(), modification: allQuietApiPublicIncidentsIncidentResourceModification, attributeChanges: z.array(allQuietApiPublicIncidentsIncidentResourceAttributeChange).nullable()}); export const allQuietApiPublicIncidentsIncidentResourceSubIncident = z.object({id: z.string(), title: z.string().nullable(), events: z.array(allQuietApiPublicIncidentsIncidentResourceSubIncidentEvent).nullable(), attributes: z.array(allQuietApiPublicIncidentsIncidentResourceAttribute).nullable(), lastUpdatedAt: z.string(), createdAt: z.string().nullable()}); export const allQuietApiPublicIncidentsIncidentResource = z.object({id: z.string(), title: z.string().nullable(), integration: allQuietApiPublicIncidentsIncidentResourceEntityDto, createdAt: z.string().nullable(), lastUpdatedAt: z.string(), attributes: z.array(allQuietApiPublicIncidentsIncidentResourceAttribute).nullable(), events: z.array(allQuietApiPublicIncidentsIncidentResourceEvent).nullable(), eventsTotalCount: z.number().int(), services: z.array(allQuietApiPublicIncidentsIncidentResourceEntityDto).nullable(), sourceUser: allQuietApiPublicIncidentsIncidentResourceUser, unattended: z.boolean(), isArchived: z.boolean(), onCallUsers: z.array(allQuietApiPublicIncidentsIncidentResourceUser).nullable(), teams: z.array(allQuietApiPublicIncidentsIncidentResourceEntityDto).nullable(), snoozed: allQuietApiPublicIncidentsIncidentResourceSnoozingProperties, subIncidents: z.array(allQuietApiPublicIncidentsIncidentResourceSubIncident).nullable(), allowedIntents: z.array(z.string()).nullable(), canDelete: z.boolean().nullable().optional(), excludeFromUptimeCalculation: z.boolean().optional(), statusPageStartOverride: z.string().nullable().optional(), statusPageEndOverride: z.string().nullable().optional()}); export const allQuietApiPublicIncidentsIncidentResourceChangesResponse = z.object({incidents: z.array(allQuietApiPublicIncidentsIncidentResource).nullable().optional(), hasMore: z.boolean().optional(), nextCursor: z.string().nullable()}); 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 }; /** * Poll incident changes * * GET /api/public/v1/incident/search/changes */ export const getApiApiPublicV1IncidentSearchChanges = async (args: GetApiApiPublicV1IncidentSearchChangesArgs, options: GetApiApiPublicV1IncidentSearchChangesOptions) => { const {baseUrl, fetch: fetchFn = fetch, ApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.Cursor != null) query.append("Cursor", String(args.Cursor)) if (args.Limit != null) query.append("Limit", String(args.Limit)) if (args.Since != null) query.append("Since", String(args.Since)) for (const item of args.IncidentIds ?? []) query.append("IncidentIds", String(item)) for (const item of args.Statuses ?? []) query.append("Statuses", String(item)) for (const item of args.Severities ?? []) query.append("Severities", String(item)) for (const item of args.IntegrationIds ?? []) query.append("IntegrationIds", String(item)) for (const item of args.TeamIds ?? []) query.append("TeamIds", String(item)) if (args.IsArchived != null) query.append("IsArchived", String(args.IsArchived)) if (args.IncludeSnoozed != null) query.append("IncludeSnoozed", String(args.IncludeSnoozed)) if (ApiKey !== undefined) headers.set("Authorization", ApiKey) const url = `${baseUrl.replace(/\/+$/, '')}/api/public/v1/incident/search/changes${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(allQuietApiPublicIncidentsIncidentResourceChangesResponse, await res.json()) };