@arcjet/redact
Version:
Arcjet sensitive information redaction library
69 lines (68 loc) • 2.83 kB
TypeScript
import type { SensitiveInfoEntity } from "@arcjet/redact-wasm";
/**
* Types of standard sensitive information that can be detected.
*/
export type ArcjetSensitiveInfoType = Exclude<SensitiveInfoEntity["tag"], "custom">;
/**
* Options for the `redact` function.
*
* @template DetectedEntities
* Custom entity names that are returned from `detect` and optionally listed in `entities`.
* @template ListedEntities
* Entity names that can be listed in the `entities` option.
*/
export type RedactOptions<DetectedEntities extends string | undefined = undefined, ListedEntities extends ArcjetSensitiveInfoType | Exclude<DetectedEntities, undefined> = ArcjetSensitiveInfoType | Exclude<DetectedEntities, undefined>> = {
/**
* Entities to redact.
*/
entities?: ReadonlyArray<ListedEntities | Exclude<DetectedEntities, undefined>>;
/**
* Size of tokens to consider.
*/
contextWindowSize?: number;
/**
* Custom detection function to identify sensitive information.
*
* @template DetectedEntities
* Custom entity names that are returned from `detect` and optionally listed in `entities`.
* @template ListedEntities
* Entity names that can be listed in the `entities` option.
* @param tokens
* Tokens.
* @returns
* List of entities (or undefined).
*/
detect?: (tokens: string[]) => ReadonlyArray<DetectedEntities>;
/**
* Custom replace function to redact sensitive information.
*
* @template DetectedEntities
* Custom entity names that are returned from `detect` and optionally listed in `entities`.
* @template ListedEntities
* Entity names that can be listed in the `entities` option.
* @param entity
* Entity to redact.
* @param plaintext
* The plaintext string to redact.
* @returns
* Redacted string or nothing.
*/
replace?: (entity: ListedEntities, plaintext: string) => string | undefined;
};
type Unredact = (input: string) => string;
/**
* Redact sensitive info.
*
* @template DetectedEntities
* Custom entity names that are returned from `detect` and optionally listed in `entities`.
* @template ListedEntities
* Entity names that can be listed in the `entities` option.
* @param candidate
* Value to redact.
* @param options
* Configuration.
* @returns
* Promise to a tuple with the redacted string and a function to unredact it.
*/
export declare function redact<const DetectedEntities extends string | undefined = undefined, const ListedEntities extends ArcjetSensitiveInfoType | Exclude<DetectedEntities, undefined> = ArcjetSensitiveInfoType | Exclude<DetectedEntities, undefined>>(candidate: string, options?: RedactOptions<DetectedEntities, ListedEntities>): Promise<[string, Unredact]>;
export {};