import {z} from 'zod' export type GetApiAlertsAlertIdNotificationsArgs = {alertId: string}; export type GetApiAlertsAlertIdNotificationsOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const v2AlertNotificationInfoChannelType = z.union([z.literal(0), z.literal(1), z.literal(2), z.literal(4), z.literal(8), z.literal(16)]); export const v2AlertNotificationInfoMessageStatus = 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)]); export const v2AlertNotificationInfoUserStatus = z.union([z.literal(0), z.literal(1), z.literal(2), z.literal(3), z.literal(4), z.literal(5), z.literal(6)]); export const v2AlertNotificationInfo = z.object({address: z.string().nullable().optional(), notificationChannelType: v2AlertNotificationInfoChannelType.optional(), deviceName: z.string().nullable().optional(), lastUpdate: z.string().optional(), messageStatus: v2AlertNotificationInfoMessageStatus.optional(), messageStatusErrorCode: z.number().int().optional(), userId: z.string().nullable().optional(), userStatus: v2AlertNotificationInfoUserStatus.optional()}); export const getApiAlertsAlertIdNotificationsResponse = z.array(v2AlertNotificationInfo); 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 alert notifications * * GET /alerts/{alertId}/notifications */ export const getApiAlertsAlertIdNotifications = async (args: GetApiAlertsAlertIdNotificationsArgs, options?: GetApiAlertsAlertIdNotificationsOptions) => { const {baseUrl = "https://connect.signl4.com/api", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/alerts/${encodeURIComponent(String(args.alertId))}/notifications${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(getApiAlertsAlertIdNotificationsResponse, await res.json()) };