import {z} from 'zod' export type GetApiApiV1AccountsAccountIdLicensesArgs = {accountId: string}; export type GetApiApiV1AccountsAccountIdLicensesOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const productMaintenance = z.object({product_id: z.number().int().optional(), license_type: z.union([z.literal(1), z.literal(2), z.literal(3), z.literal(4)]).optional(), amount: z.number().int().optional(), expiration_date: z.string().optional()}); export const productLicenseCounters = z.object({product_id: z.number().int().optional(), license_type: z.union([z.literal(1), z.literal(2), z.literal(3), z.literal(4)]).optional(), product_name: z.string().optional(), assigned_licenses: z.number().int().optional(), unassigned_licenses: z.number().int().optional(), without_license_devices: z.number().int().optional(), expiration_date: z.string().optional(), license_items: z.array(productMaintenance).optional()}); export const licenseCounters = z.object({product_license_counter: z.array(productLicenseCounters).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 account license information. * * GET /api/v1/accounts/{accountId}/licenses */ export const getApiApiV1AccountsAccountIdLicenses = async (args: GetApiApiV1AccountsAccountIdLicensesArgs, options?: GetApiApiV1AccountsAccountIdLicensesOptions) => { 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))}/licenses${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(licenseCounters, await res.json()) };