import {z} from 'zod' export type ScanEvents = {failed: boolean, paused: boolean, resumed?: boolean | undefined, started: boolean, stopped: boolean}; export type VulnerabilityEvents = {confirmedVulnerabilities: boolean, potentialVulnerabilities: boolean, unconfirmedVulnerabilities: boolean, vulnerabilitySeverity: 'any_severity' | 'severe_and_critical' | 'only_critical'}; export type Link = {deprecation?: string | undefined, href?: string | undefined, hreflang?: string | undefined, media?: string | undefined, rel?: string | undefined, title?: string | undefined, type?: string | undefined}; export type SyslogAlert = {enabled: boolean, enabledScanEvents?: ScanEvents | undefined, enabledVulnerabilityEvents?: VulnerabilityEvents | undefined, id?: number | undefined, links: Array, maximumAlerts?: number | undefined, name: string, notification: 'SMTP' | 'SNMP' | 'Syslog', server: string}; export type CreateApiApi3SitesIdAlertsSyslogArgs = {id: number, body: SyslogAlert}; export type CreateApiApi3SitesIdAlertsSyslogOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const link = z.object({deprecation: z.string().optional(), href: z.string().optional(), hreflang: z.string().optional(), media: z.string().optional(), rel: z.string().optional(), title: z.string().optional(), type: z.string().optional()}); export const referenceResourceAlertIDLink = z.object({id: z.object({}).optional(), links: z.array(link)}); 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 }; /** * Site Syslog Alerts * * POST /api/3/sites/{id}/alerts/syslog */ export const createApiApi3SitesIdAlertsSyslog = async (args: CreateApiApi3SitesIdAlertsSyslogArgs, options?: CreateApiApi3SitesIdAlertsSyslogOptions) => { const {baseUrl = "https://:", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json;charset=UTF-8") const url = `${baseUrl.replace(/\/+$/, '')}/api/3/sites/${encodeURIComponent(String(args.id))}/alerts/syslog${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(referenceResourceAlertIDLink, await res.json()) };