@google-cloud/recaptcha-edge
Version:
A reCAPTCHA Enterprise Typescript library for Edge Compute Platforms.
81 lines (80 loc) • 3.72 kB
TypeScript
/**
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import * as action from "./action";
import { FirewallPolicy } from "./assessment";
import { RecaptchaContext, EdgeRequest, EdgeResponse, ListFirewallPoliciesResponse } from "./index";
type LocalAssessment = action.Action[] | "recaptcha-required";
/**
* Path to the hosted reCAPTCHA Enterprise Javascript.
* This path may be injected into the response.
*/
export declare const RECAPTCHA_JS = "https://www.google.com/recaptcha/enterprise.js";
/**
* Checks whether a particular policy path pattern matches the incoming request.
*/
export declare function policyPathMatch(req: EdgeRequest, policy: FirewallPolicy): boolean;
/**
* Checks whether a particular incoming request matching a set of glob path patterns.
* An empty string is considered a 'wildcard' and matches all paths.
* @param req the incoming request to match against
* @param patterns the path glob pattern(s) to try matching
* @param method (optional) A HTTP method (GET, POST,...) to check against the request
* @returns true if any path pattern (and method) matches the request.
*/
export declare function pathMatch(req: EdgeRequest, patterns: [string] | string, method?: string): boolean;
/**
* Evaluate the condition of a policy locally, to the best of our ability.
*
* @return true if the condition matches, false if it doesn't match, or
* 'unknown' if we can't evaluate the condition locally.
*/
export declare function policyConditionMatch(req: EdgeRequest, policy: FirewallPolicy): boolean | "unknown";
/**
* Call the reCAPTCHA API to list firewall policies.
*/
export declare function callListFirewallPolicies(context: RecaptchaContext): Promise<ListFirewallPoliciesResponse>;
/**
* Check if a request can be locally accessed,
* with amortized caching of policies.
*/
export declare function localPolicyAssessment(context: RecaptchaContext, req: EdgeRequest): Promise<LocalAssessment>;
/**
* Evaluate the policy assessment for a request.
*/
export declare function evaluatePolicyAssessment(context: RecaptchaContext, req: EdgeRequest): Promise<action.Action[]>;
/**
* Apply pre-request actions. If a terminal action is applied it will generate a response
* which will be returned. Non terminal actions will modify the request and return null;
*/
export declare function applyPreRequestActions(context: RecaptchaContext, req: EdgeRequest, actions: action.Action[]): Promise<EdgeResponse | null>;
/**
* Apply post response actions. Returns a (possibly modified) response.
*/
export declare function applyPostResponseActions(context: RecaptchaContext, resp: EdgeResponse, actions: action.Action[]): Promise<EdgeResponse>;
/**
* Apply actions to a request.
*/
export declare function applyActions(context: RecaptchaContext, req: EdgeRequest, actions: action.Action[]): Promise<EdgeResponse>;
/**
*
* Fetches a list of the applicable actions, given a request.
*/
export declare function fetchActions(context: RecaptchaContext, req: EdgeRequest): Promise<action.Action[]>;
/**
* Process reCAPTCHA request.
*/
export declare function processRequest(context: RecaptchaContext, req: EdgeRequest): Promise<EdgeResponse>;
export {};