import {z} from 'zod' export type AllQuietApiPublicIncidentsIncidentResourceCreateUserAssignment = {userId?: string | undefined}; export type AllQuietApiIncidentsUpdateAttributesOperationAttribute = {name: string, value: string, isImage?: (boolean | null) | undefined, hideInPreviews?: (boolean | null) | undefined}; export type AllQuietApiPublicIncidentsIncidentResourceCreateRequest = {title: string, message?: (string | null) | undefined, messageIsPublic?: (boolean | null) | undefined, integrationId?: (string | null) | undefined, teamIds?: (Array | null) | undefined, status: string, severity: string, serviceIds?: (Array | null) | undefined, excludeFromUptimeCalculation?: (boolean | null) | undefined, statusPageStartOverride?: (string | null) | undefined, statusPageEndOverride?: (string | null) | undefined, userAssignments?: (Array | null) | undefined, attributes?: (Array | null) | undefined, publicComment?: (string | null) | undefined}; export type CreateApiApiPublicV1IncidentArgs = {organizationId?: string | undefined, body: AllQuietApiPublicIncidentsIncidentResourceCreateRequest}; export type CreateApiApiPublicV1IncidentOptions = {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 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 }; /** * Create an incident * * POST /api/public/v1/incident */ export const createApiApiPublicV1Incident = async (args: CreateApiApiPublicV1IncidentArgs, options: CreateApiApiPublicV1IncidentOptions) => { const {baseUrl, fetch: fetchFn = fetch, ApiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.organizationId != null) query.append("organizationId", String(args.organizationId)) if (ApiKey !== undefined) headers.set("Authorization", ApiKey) const url = `${baseUrl.replace(/\/+$/, '')}/api/public/v1/incident${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(allQuietApiPublicIncidentsIncidentResource, await res.json()) };