import {z} from 'zod' export type GetApiApiV1AccountsAccountIdSoftwareinventoryArgs = {accountId: string, top?: number | undefined, skip?: number | undefined, count?: boolean | undefined, filter?: string | undefined}; export type GetApiApiV1AccountsAccountIdSoftwareinventoryOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const softwareInventoryOutput = z.object({site_id: z.string().optional(), site_name: z.string().optional(), device_id: z.string().optional(), host_name: z.string().optional(), description: z.string().optional(), device_type: z.union([z.literal(1), z.literal(2), z.literal(3), z.literal(4)]).optional(), platform_id: z.union([z.literal(1), z.literal(2), z.literal(3), z.literal(4), z.literal(5)]).optional(), ip_address: z.string().optional(), domain: z.string().optional(), operating_system: z.string().optional(), custom_group_folder_id: z.string().optional(), name: z.string().optional(), publisher: z.string().optional(), version: z.string().optional(), size: z.number().int().nullable().optional(), installation_date: z.string().nullable().optional(), is_patch: z.boolean().optional()}); export const softwareInventoryOutputFindResponse = z.object({data: softwareInventoryOutput.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 installed software. * * GET /api/v1/accounts/{accountId}/softwareinventory */ export const getApiApiV1AccountsAccountIdSoftwareinventory = async (args: GetApiApiV1AccountsAccountIdSoftwareinventoryArgs, options?: GetApiApiV1AccountsAccountIdSoftwareinventoryOptions) => { 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.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))}/softwareinventory${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(softwareInventoryOutputFindResponse, await res.json()) };