import {z} from 'zod' export type GetApiShieldShieldZoneShieldZoneIdArgs = {shieldZoneId: number}; export type GetApiShieldShieldZoneShieldZoneIdOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const wAFExecutionMode = z.union([z.literal(0), z.literal(1)]); export const pullZoneWafConfigVariableModel = z.object({name: z.string().nullable(), valueEncoded: z.string().nullable()}); export const wAFPayloadLimitAction = z.union([z.literal(0), z.literal(1), z.literal(2)]); export const shieldPlanType = z.union([z.literal(0), z.literal(1), z.literal(2), z.literal(3)]); export const dDoSShieldSensitivity = z.union([z.literal(0), z.literal(1), z.literal(2), z.literal(3), z.literal(4), z.literal(5)]); export const dDoSExecutionMode = z.union([z.literal(0), z.literal(1)]); export const shieldZoneResponse = z.object({shieldZoneId: z.number().int().optional(), pullZoneId: z.number().int().nullable().optional(), learningMode: z.boolean().nullable().optional(), learningModeUntil: z.string().nullable().optional(), wafEnabled: z.boolean().nullable().optional(), wafExecutionMode: wAFExecutionMode.optional(), wafDisabledRules: z.array(z.string()).nullable().optional(), wafLogOnlyRules: z.array(z.string()).nullable().optional(), wafCustomRuleOrder: z.array(z.number().int()).nullable().optional(), wafRequestHeaderLoggingEnabled: z.boolean().optional(), requestBodyLoggingEnabled: z.boolean().optional(), wafRequestIgnoredHeaders: z.array(z.string()).nullable().optional(), wafRealtimeThreatIntelligenceEnabled: z.boolean().nullable().optional(), wafProfileId: z.number().int().nullable().optional(), wafEngineConfig: z.array(pullZoneWafConfigVariableModel).nullable().optional(), wafRequestBodyLimitAction: wAFPayloadLimitAction.optional(), wafResponseBodyLimitAction: wAFPayloadLimitAction.optional(), rateLimitRulesLimit: z.number().int().optional(), customWafRulesLimit: z.number().int().optional(), planType: shieldPlanType.optional(), dDoSShieldSensitivity: dDoSShieldSensitivity.optional(), dDoSExecutionMode: dDoSExecutionMode.optional(), dDoSChallengeWindow: z.number().int().nullable().optional(), whitelabelResponsePages: z.boolean().nullable().optional()}); export const getShieldZoneResponse = z.object({data: shieldZoneResponse.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 }; /** * Get Singular Shield Zone Configuration * * GET /shield/shield-zone/{shieldZoneId} */ export const getApiShieldShieldZoneShieldZoneId = async (args: GetApiShieldShieldZoneShieldZoneIdArgs, options?: GetApiShieldShieldZoneShieldZoneIdOptions) => { const {baseUrl = "https://api.bunny.net", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") const url = `${baseUrl.replace(/\/+$/, '')}/shield/shield-zone/${encodeURIComponent(String(args.shieldZoneId))}${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(getShieldZoneResponse, await res.json()) };