import {z} from 'zod' export type GetApiApiV1AccountsAccountIdSecurityoverviewPeriodArgs = {accountId: string, period: 1 | 7 | 30}; export type GetApiApiV1AccountsAccountIdSecurityoverviewPeriodOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const securityOverviewAggregatedCounters = z.object({total_alerts: z.number().int().nullable().optional(), total_executed: z.number().int().nullable().optional(), total_data_access: z.number().int().nullable().optional(), total_external_communications: z.number().int().nullable().optional(), total_affected_devices: z.number().int().nullable().optional()}); export const programBlockedOverviewCounters = z.object({total_programs_blocked: z.number().int().nullable().optional()}); export const threatsByAvOverviewCounters = z.object({total_phishing_detected_by_av: z.number().int().nullable().optional(), total_tracking_cookies_detected_by_av: z.number().int().nullable().optional(), total_devices_blocked_by_av: z.number().int().nullable().optional(), total_malware_urls_blocked_by_av: z.number().int().nullable().optional(), total_intrusion_attempted_blocked_by_av: z.number().int().nullable().optional(), total_dangerous_actions_blocked_by_av: z.number().int().nullable().optional(), total_hacking_tools_by_av: z.number().int().nullable().optional(), total_spyware_by_av: z.number().int().nullable().optional(), total_virus_by_av: z.number().int().nullable().optional()}); export const indicatorsOfAttackCounters = z.object({total_indicators_of_attack: z.number().int().nullable().optional()}); export const networkAttackAggregatedCounters = z.object({total_alerts: z.number().int().nullable().optional(), total_affected_devices: z.number().int().nullable().optional()}); export const securityOverviewCountersResult = z.object({total_devices: z.number().int().optional(), total_unmanaged_devices: z.number().int().optional(), malware: securityOverviewAggregatedCounters.optional(), pups: securityOverviewAggregatedCounters.optional(), exploits: securityOverviewAggregatedCounters.optional(), programs_blocked: programBlockedOverviewCounters.optional(), threats_by_av_counters: threatsByAvOverviewCounters.optional(), indicators_of_attack_counters: indicatorsOfAttackCounters.optional(), network_attack_counters: networkAttackAggregatedCounters.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 }; /** * Retrieves security overview information. * * GET /api/v1/accounts/{accountId}/securityoverview/{period} */ export const getApiApiV1AccountsAccountIdSecurityoverviewPeriod = async (args: GetApiApiV1AccountsAccountIdSecurityoverviewPeriodArgs, options?: GetApiApiV1AccountsAccountIdSecurityoverviewPeriodOptions) => { const {baseUrl = "https://api.usa.cloud.watchguard.com/rest/aether-endpoint-security/aether-mgmt", fetch: fetchFn = fetch, ApiKeyAuth, BearerAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (ApiKeyAuth !== undefined) headers.set("WatchGuard-API-Key", ApiKeyAuth) if (BearerAuth !== undefined) headers.set('authorization', `Bearer ${BearerAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/api/v1/accounts/${encodeURIComponent(String(args.accountId))}/securityoverview/${encodeURIComponent(String(args.period))}${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(securityOverviewCountersResult, await res.json()) };