import {z} from 'zod' export type GetApiV1ConfigurationAccountidExceptionsGeolocationObjectidArgs = {objectid: string}; export type GetApiV1ConfigurationAccountidExceptionsGeolocationObjectidOptions = {baseUrl?: string | undefined, ApiKeyAuth?: string | undefined, BearerAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const ipv4AddressString = z.string(); export const ipv4HostType = z.object({type: z.literal("ipv4_host"), value: ipv4AddressString}); export const ipv4RangeType = z.object({type: z.literal("ipv4_range"), value: z.string()}); export const ipv4CidrString = z.string(); export const ipv4NetworkType = z.object({type: z.literal("ipv4_network"), value: ipv4CidrString}); export const ipv4AddrType = z.union([ipv4HostType, ipv4RangeType, ipv4NetworkType]); export const fqdnType = z.object({type: z.literal("fqdn"), value: z.string()}); export const geolocationException = z.object({id: z.string(), object: z.string(), version: z.number().int(), account: z.string(), created: z.number().int(), device: z.literal("firewan"), author: z.string(), description: z.string().max(127).optional(), address: z.union([ipv4AddrType, fqdnType]), action: z.literal("allow").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 the specified Geolocation exception. * * GET /v1/configuration/{accountid}/exceptions/geolocation/{objectid} */ export const getApiV1ConfigurationAccountidExceptionsGeolocationObjectid = async (args: GetApiV1ConfigurationAccountidExceptionsGeolocationObjectidArgs, options?: GetApiV1ConfigurationAccountidExceptionsGeolocationObjectidOptions) => { const {baseUrl = "https://api.usa.cloud.watchguard.com/rest/firecloud/management", 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(/\/+$/, '')}/v1/configuration/${encodeURIComponent(String(args.accountid))}/exceptions/geolocation/${encodeURIComponent(String(args.objectid))}${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(geolocationException, await res.json()) };