UNPKG

@arcjet/analyze

Version:

Arcjet local analysis engine

133 lines (132 loc) 3.91 kB
import { BotConfig, BotResult, DetectSensitiveInfoFunction, DetectedSensitiveInfoEntity, EmailValidationConfig, EmailValidationResult, FilterResult, SensitiveInfoEntities, SensitiveInfoEntity, SensitiveInfoResult } from "@arcjet/analyze-wasm"; import { ArcjetLogger } from "@arcjet/protocol"; //#region src/index.d.ts interface AnalyzeContext { log: ArcjetLogger; characteristics: string[]; } /** * Request passed as a JSON string into WebAssembly. * * This is like `ArcjetRequestDetails` from `@arcjet/protocol`, * but fields are often optional across the boundary. */ interface AnalyzeRequest { /** * IP address (IPv4 or IPv6). */ ip?: string | undefined; /** * HTTP method (such as `GET`). */ method?: string | undefined; /** * Protocol (such as `"http:"`). */ protocol?: string | undefined; /** * Hostname (such as `"example.com"`). */ host?: string | undefined; /** * Path (such as `"/path/to/resource"`). */ path?: string | undefined; /** * Headers of the request. */ headers?: Record<string, string> | undefined; /** * Cookies of the request (such as `"cookie1=value1; cookie2=value2"`). */ cookies?: string | undefined; /** * Query string of the request (such as `"?q=alpha"`). */ query?: string | undefined; /** * Extra info. */ extra?: Record<string, string> | undefined; } /** * Generate a fingerprint. * * Fingerprints can be used to identify the client across multiple requests. * * This considers different things on the `request` based on the passed * `context.characteristics`. * * See [*Fingerprints* on * `docs.arcjet.com`](https://docs.arcjet.com/fingerprints/) for more info. * * @param context * Context. * @param request * Request. * @returns * Promise for a SHA-256 fingerprint. */ declare function generateFingerprint(context: AnalyzeContext, request: AnalyzeRequest): Promise<string>; /** * Check whether an email is valid. * * @param context * Context. * @param value * Value. * @param options * Configuration. * @returns * Promise for a result. */ declare function isValidEmail(context: AnalyzeContext, value: string, options: EmailValidationConfig): Promise<EmailValidationResult>; /** * Detect whether a request is by a bot. * * @param context * Context. * @param request * Request. * @param options * Configuration. * @returns * Promise for a result. */ declare function detectBot(context: AnalyzeContext, request: AnalyzeRequest, options: BotConfig): Promise<BotResult>; /** * Detect sensitive info in a value. * * @param context * Context. * @param value * Value. * @param entities * Strategy to use for detecting sensitive info; * either by denying everything and allowing certain tags or by allowing * everything and denying certain tags. * @param contextWindowSize * Number of tokens to pass to `detect`. * @param detect * Function to detect sensitive info (optional). * @returns * Promise for a result. */ declare function detectSensitiveInfo(context: AnalyzeContext, value: string, entities: SensitiveInfoEntities, contextWindowSize: number, detect?: DetectSensitiveInfoFunction): Promise<SensitiveInfoResult>; /** * Check if a filter matches a request. * * @param context * Arcjet context. * @param request * Request. * @param localFields * Fields to use as `local` in the expressions, as serialized JSON. * @param expressions * Filter expressions. * @returns * Promise to whether the filter matches the request. */ declare function matchFilters(context: AnalyzeContext, request: AnalyzeRequest, localFields: string, expressions: ReadonlyArray<string>, allowIfMatch: boolean): Promise<FilterResult>; //#endregion export { AnalyzeRequest, type BotConfig, type DetectedSensitiveInfoEntity, type EmailValidationConfig, type FilterResult, type SensitiveInfoEntity, detectBot, detectSensitiveInfo, generateFingerprint, isValidEmail, matchFilters };