import {z} from 'zod' export type GetApiV1ReportAccountIdSecurityArgs = {accountId: string, view: 'top_blocked_countries' | 'top_blocked_advanced_malware_apt' | 'top_blocked_botnet_sites' | 'top_blocked_clients' | 'top_blocked_mobile_devices' | 'top_blocked_destinations' | 'top_blocked_url_categories' | 'top_blocked_applications' | 'top_blocked_application_categories' | 'top_blocked_protocols' | 'top_blocked_attacks' | 'top_blocked_malware', startDate: string, endDate: string, devices?: string | undefined, rowCount?: number | undefined, filter?: ('top_blocked_countries' | 'top_blocked_advanced_malware_apt' | 'top_blocked_botnet_sites' | 'top_blocked_clients' | 'top_blocked_mobile_devices' | 'top_blocked_destinations' | 'top_blocked_url_categories' | 'top_blocked_applications' | 'top_blocked_application_categories' | 'top_blocked_protocols' | 'top_blocked_attacks' | 'top_blocked_malware') | undefined, filterValue?: string | undefined}; export type GetApiV1ReportAccountIdSecurityOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const successResponse = z.object({status: z.string().optional(), view: z.string().optional(), data: z.object({records: z.array(z.object({bytes: z.string().optional(), connections: z.string().optional(), detail: z.string().optional(), name: z.string().optional()})).optional()}).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 data from the Firebox Security Dashboard report. * * GET /v1/report/{accountId}/security */ export const getApiV1ReportAccountIdSecurity = async (args: GetApiV1ReportAccountIdSecurityArgs, options?: GetApiV1ReportAccountIdSecurityOptions) => { const {baseUrl = "https://api.usa.cloud.watchguard.com/rest/firebox/reports", fetch: fetchFn = fetch, ApiKeyAuth, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.view != null) query.append("view", String(args.view)) if (args.startDate != null) query.append("startDate", String(args.startDate)) if (args.endDate != null) query.append("endDate", String(args.endDate)) if (args.devices != null) query.append("devices", String(args.devices)) if (args.rowCount != null) query.append("rowCount", String(args.rowCount)) if (args.filter != null) query.append("filter", String(args.filter)) if (args.filterValue != null) query.append("filterValue", String(args.filterValue)) if (ApiKeyAuth !== undefined) headers.set("WatchGuard-API-Key", ApiKeyAuth) if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/report/${encodeURIComponent(String(args.accountId))}/security${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(successResponse, await res.json()) };