import {z} from 'zod' export type V2PagedResultsPublicContinuationTokenObsolete = {nextPartitionKey?: (string | null) | undefined, nextRowKey?: (string | null) | undefined, nextTableName?: (string | null) | undefined}; export type V1UserCreatedAlertsFilterMode = 0 | 1 | 2; export type V1AlertStatusCodesV1 = 0 | 1 | 2 | 4 | 8 | 16 | 32; export type V1AlertFilterPublic = {teamid?: (string | null) | undefined, alertIds?: (Array | null) | undefined, afterId?: (string | null) | undefined, categoryIds?: (Array | null) | undefined, continuationToken?: V2PagedResultsPublicContinuationTokenObsolete | undefined, maxCreated?: (string | null) | undefined, minCreated?: (string | null) | undefined, modSince?: (string | null) | undefined, showPersonalHiddenCategories?: boolean | undefined, userCreatedAlertsFilterMode?: V1UserCreatedAlertsFilterMode | undefined, alertStatusCodes?: V1AlertStatusCodesV1 | undefined, textToSearch?: (string | null) | undefined}; export type CreateApiAlertsPagedArgs = {maxResults?: number | undefined, userId?: string | undefined, body: V1AlertFilterPublic}; export type CreateApiAlertsPagedOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const v2PagedResultsPublicContinuationTokenObsolete = z.object({nextPartitionKey: z.string().nullable().optional(), nextRowKey: z.string().nullable().optional(), nextTableName: z.string().nullable().optional()}); export const alertDeliveryStatusCodes = z.union([z.literal(0), z.literal(1), z.literal(2), z.literal(4), z.literal(6), z.literal(8), z.literal(9), z.literal(22), z.literal(24), z.literal(26), z.literal(30), z.literal(31)]); export const v1UserDeliveryStatusInfoCodes = z.union([z.literal(0), z.literal(1), z.literal(2), z.literal(4), z.literal(6), z.literal(8), z.literal(9), z.literal(24), z.literal(26), z.literal(30), z.literal(31), z.literal(32)]); export const v1UserType = z.union([z.literal(0), z.literal(1)]); export const v1UserDeliveryStatusInfo = z.object({statusCode: v1UserDeliveryStatusInfoCodes.optional(), userId: z.string().nullable().optional(), userType: v1UserType.optional()}); export const v1AlertDeliveryStatusInfo = z.object({alertDeliveryStatusCode: alertDeliveryStatusCodes.optional(), userDeliveryStatusInfos: z.array(v1UserDeliveryStatusInfo).nullable().optional()}); export const v1AlertHistoryInfoUserEntryType = z.union([z.literal(0), z.literal(1), z.literal(2), z.literal(3), z.literal(4), z.literal(5), z.literal(6), z.literal(7), z.literal(8), z.literal(9), z.literal(10), z.literal(11), z.literal(12), z.literal(13)]); export const v1AlertHistoryInfoEntry = z.object({id: z.string().nullable().optional(), timestamp: z.string().optional(), type: v1AlertHistoryInfoUserEntryType.optional(), userId: z.string().nullable().optional()}); export const v1AlertHistoryInfoDetailed = z.object({alertHistoryEntries: z.array(v1AlertHistoryInfoEntry).nullable().optional(), acknowledgedgements: z.array(z.string()).nullable().optional(), closed: z.string().nullable().optional(), closedBy: z.string().nullable().optional(), acknowledged: z.string().nullable().optional(), created: z.string().optional(), createdBy: z.string().nullable().optional()}); export const v1AlertStatusCodesV1 = z.union([z.literal(0), z.literal(1), z.literal(2), z.literal(4), z.literal(8), z.literal(16), z.literal(32)]); export const v2AlertDestinationTypeDetails = z.union([z.literal(2), z.literal(3)]); export const v2AlertDestinationDetails = z.object({value: z.string().nullable().optional(), type: v2AlertDestinationTypeDetails.optional()}); export const v1AlertAnnotationInfoV1 = z.object({type: z.number().int().optional(), text: z.string().nullable().optional(), timestamp: z.string().optional(), userId: z.string().nullable().optional(), id: z.string().nullable().optional(), teamId: z.string().nullable().optional()}); export const v1OverviewAlert = z.object({alertDeliveryStatus: v1AlertDeliveryStatusInfo.optional(), detailedHistory: v1AlertHistoryInfoDetailed.optional(), requiredAcknowledgements: z.number().int().optional(), categoryId: z.string().nullable().optional(), externalId: z.string().nullable().optional(), eventId: z.string().nullable().optional(), flags: z.number().int().optional(), id: z.string().nullable().optional(), lastModified: z.string().optional(), status: v1AlertStatusCodesV1.optional(), subscriptionId: z.string().nullable().optional(), destination: v2AlertDestinationDetails.optional(), text: z.string().nullable().optional(), title: z.string().nullable().optional(), annotations: z.array(v1AlertAnnotationInfoV1).nullable().optional()}); export const pagedResultsPublicObsolete1V1OverviewAlert = z.object({continuationToken: v2PagedResultsPublicContinuationTokenObsolete.optional(), hasMore: z.boolean().optional(), results: z.array(v1OverviewAlert).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 }; /** * Gets alerts paged * * POST /alerts/paged */ export const createApiAlertsPaged = async (args: CreateApiAlertsPagedArgs, options?: CreateApiAlertsPagedOptions) => { const {baseUrl = "https://connect.signl4.com/api", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.maxResults != null) query.append("maxResults", String(args.maxResults)) if (args.userId != null) query.append("userId", String(args.userId)) const url = `${baseUrl.replace(/\/+$/, '')}/alerts/paged${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(pagedResultsPublicObsolete1V1OverviewAlert, await res.json()) };