import {z} from 'zod' export type GetApiApiV2NotificationsIdArgs = {id: number}; export type GetApiApiV2NotificationsIdOptions = {baseUrl?: string | undefined, OAuthv2?: string | undefined, fetch?: typeof fetch | undefined}; export const notification = z.object({NotificationId: z.number().int(), WorkflowId: z.number().int().nullable().optional(), CompanyId: z.number().int().nullable().optional(), Company: z.string().nullable().optional(), Title: z.string().optional(), Status: z.enum(["Open", "Reviewed", "Closed", "False Positive", "Suppress"]).optional(), InsertDate: z.string().optional(), Detail: z.string().optional(), NotificationType: z.enum(["findings", "tickets", "tags", "ratings", "tags_update", "tags_subsidiary", "other"]).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 details of a notification. * * GET /api/v2/notifications/{id} */ export const getApiApiV2NotificationsId = async (args: GetApiApiV2NotificationsIdArgs, options?: GetApiApiV2NotificationsIdOptions) => { const {baseUrl = "https://app.blackkitetech.com", fetch: fetchFn = fetch, OAuthv2} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (OAuthv2 !== undefined) headers.set('authorization', `Bearer ${OAuthv2}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v2/notifications/${encodeURIComponent(String(args.id))}${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(notification, await res.json()) };