import {z} from 'zod' export type V2AlertDestinationTypeDetails = 2 | 3; export type V2AlertDestinationDetails = {value?: (string | null) | undefined, type?: V2AlertDestinationTypeDetails | undefined}; export type V2PagedResultsPublicContinuationTokenObsolete = {nextPartitionKey?: (string | null) | undefined, nextRowKey?: (string | null) | undefined, nextTableName?: (string | null) | undefined}; export type EventStatusCodes = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 21 | 22 | 23 | 30 | 1000; export type UserCreatedEventsFilterMode = 0 | 1 | 2; export type EventCreatorFilterDetails = {userId: string | null, userCreatedFilterMode?: UserCreatedEventsFilterMode | undefined}; export type V2EventFilter = {teamid?: (string | null) | undefined, alertDestinations?: (Array | null) | undefined, continuationToken?: V2PagedResultsPublicContinuationTokenObsolete | undefined, eventStatusCode?: EventStatusCodes | undefined, maxCreationDate?: (string | null) | undefined, minCreationDate?: (string | null) | undefined, modifiedSince?: (string | null) | undefined, textToSearch?: (string | null) | undefined, eventSourceId?: (string | null) | undefined, eventCreatorFilter?: EventCreatorFilterDetails | undefined}; export type CreateApiEventsPagedArgs = {maxResults?: number | undefined, body: V2EventFilter}; export type CreateApiEventsPagedOptions = {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 v2AlertDestinationTypeDetails = z.union([z.literal(2), z.literal(3)]); export const v2AlertDestinationDetails = z.object({value: z.string().nullable().optional(), type: v2AlertDestinationTypeDetails.optional()}); export const eventSourceTypes = 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)]); export const eventStatusCodes = 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(21), z.literal(22), z.literal(23), z.literal(30), z.literal(1000)]); export const v2EventSeverities = z.union([z.literal(0), z.literal(1), z.literal(2)]); export const v2OverviewEvent = z.object({alertDestination: v2AlertDestinationDetails.optional(), alertId: z.string().nullable().optional(), categoryId: z.string().nullable().optional(), acknowledgedAlerts: z.array(z.string()).nullable().optional(), closedAlerts: z.array(z.string()).nullable().optional(), creationTime: z.string().optional(), createdByUserId: z.string().nullable().optional(), eventSourceType: eventSourceTypes.optional(), eventSourceGroupId: z.string().nullable().optional(), eventSourceId: z.string().nullable().optional(), eventSourceTeamId: z.string().nullable().optional(), eventStatus: eventStatusCodes.optional(), id: z.string().nullable().optional(), lastModified: z.string().optional(), severity: v2EventSeverities.optional(), text: z.string().nullable().optional(), title: z.string().nullable().optional()}); export const pagedResultsPublicObsolete1V2OverviewEvent = z.object({continuationToken: v2PagedResultsPublicContinuationTokenObsolete.optional(), hasMore: z.boolean().optional(), results: z.array(v2OverviewEvent).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 }; /** * Get overview event paged. * * POST /events/paged */ export const createApiEventsPaged = async (args: CreateApiEventsPagedArgs, options?: CreateApiEventsPagedOptions) => { 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)) const url = `${baseUrl.replace(/\/+$/, '')}/events/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(pagedResultsPublicObsolete1V2OverviewEvent, await res.json()) };