import {z} from 'zod' export type GetApiApiV1AccountsAccountIdRiskassessmentDevicesriskArgs = {accountId: string, top?: number | undefined, skip?: number | undefined, search?: string | undefined, count?: boolean | undefined, filter?: string | undefined}; export type GetApiApiV1AccountsAccountIdRiskassessmentDevicesriskOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const riskStatusCountersType = z.object({total_critical_risk: z.number().int().optional(), total_high_risk: z.number().int().optional(), total_medium_risk: z.number().int().optional(), total_without_risk: z.number().int().optional(), total_not_applicable_by_platform: z.number().int().optional(), total_not_evaluated_on_device: z.number().int().optional()}); export const riskAssessmentDevicesRiskResult = z.object({host_name: z.string().optional(), device_id: z.string().optional(), last_connection_date: z.string().optional(), device_risk_severity: z.union([z.literal(0), z.literal(5), z.literal(20), z.literal(30), z.literal(40)]).optional(), risk_status_counters: riskStatusCountersType.optional()}); export const riskAssessmentDevicesRiskResultFindResponse = z.object({data: riskAssessmentDevicesRiskResult.optional(), total_items: z.number().int().nullable().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 }; /** * Retrieve risks detected for devices. * * GET /api/v1/accounts/{accountId}/riskassessment/devicesrisk */ export const getApiApiV1AccountsAccountIdRiskassessmentDevicesrisk = async (args: GetApiApiV1AccountsAccountIdRiskassessmentDevicesriskArgs, options?: GetApiApiV1AccountsAccountIdRiskassessmentDevicesriskOptions) => { 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 (args.top != null) query.append("top", String(args.top)) if (args.skip != null) query.append("skip", String(args.skip)) if (args.search != null) query.append("search", String(args.search)) if (args.count != null) query.append("count", String(args.count)) if (args.filter != null) query.append("filter", String(args.filter)) 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))}/riskassessment/devicesrisk${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(riskAssessmentDevicesRiskResultFindResponse, await res.json()) };