11import { initializeWasm } from "@arcjet/redact-wasm" ;
22import type { SensitiveInfoEntity } from "@arcjet/redact-wasm" ;
33
4+ /**
5+ * Types of sensitive information.
6+ */
47export type ArcjetSensitiveInfoType =
58 | "email"
69 | "phone-number"
@@ -25,14 +28,41 @@ type ValidEntities<Detect> = Array<
2528 : never
2629> ;
2730
31+ /**
32+ * Redact sensitive information.
33+ *
34+ * @param entity
35+ * Entity to redact.
36+ * @param plaintext
37+ * The plaintext string to redact.
38+ * @returns
39+ * Redacted string or nothing.
40+ */
41+ type Replace < Detect > = (
42+ entity : ValidEntities < Detect > [ number ] ,
43+ plaintext : string ,
44+ ) => string | undefined ;
45+
46+ /**
47+ * Options for the `redact` function.
48+ */
2849export type RedactOptions < Detect > = {
50+ /**
51+ * Entities to redact.
52+ */
2953 entities ?: ValidEntities < Detect > ;
54+ /**
55+ * Size of tokens to consider.
56+ */
3057 contextWindowSize ?: number ;
58+ /**
59+ * Custom detection function to identify sensitive information.
60+ */
3161 detect ?: Detect ;
32- replace ?: (
33- entity : ValidEntities < Detect > [ number ] ,
34- plaintext : string ,
35- ) => string | undefined ;
62+ /**
63+ * Custom replace function to redact sensitive information.
64+ */
65+ replace ?: Replace < Detect > ;
3666} ;
3767
3868function userEntitiesToWasm ( entity : unknown ) {
@@ -196,6 +226,16 @@ async function callRedactWasm<
196226
197227type Unredact = ( input : string ) => string ;
198228
229+ /**
230+ * Redact sensitive info.
231+ *
232+ * @param candidate
233+ * Value to redact.
234+ * @param options
235+ * Configuration.
236+ * @returns
237+ * Promise to a tuple with the redacted string and a function to unredact it.
238+ */
199239export async function redact <
200240 const Detect extends DetectSensitiveInfoEntities < CustomEntities > | undefined ,
201241 const CustomEntities extends string ,
0 commit comments