@arcjet/redact 1.0.0-beta.1 → 1.0.0-beta.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. package/README.md +47 -13
  2. package/index.d.ts +1 -1
  3. package/index.js +3 -3
  4. package/package.json +20 -16
package/README.md CHANGED
@@ -20,31 +20,65 @@
20
20
  code. Implement rate limiting, bot protection, email verification, and defense
21
21
  against common attacks.
22
22
 
23
- This is the [Arcjet][arcjet] TypeScript and JavaScript sensitive information redaction library.
23
+ This is the [Arcjet][arcjet] TypeScript and JavaScript sensitive information
24
+ redaction library.
24
25
 
25
- ## Installation
26
+ - [npm package (`@arcjet/redact`)](https://www.npmjs.com/package/@arcjet/redact)
27
+ - [GitHub source code (`redact/` in `arcjet/arcjet-js`)](https://github.com/arcjet/arcjet-js/tree/main/redact)
26
28
 
27
- ```shell
28
- npm install -S @arcjet/redact
29
+ ## What is this?
30
+
31
+ This package provides functionality to redact sensitive info.
32
+ The work is done in WebAssembly but is called here from JavaScript.
33
+
34
+ The WebAssembly files are in [`@arcjet/redact-wasm`][github-arcjet-redact-wasm].
35
+ For more info on why we maintain our WebAssembly and JavaScript projects like
36
+ this,
37
+ see [“What is this?” in the readme of
38
+ `@arcjet/analyze-wasm`][github-arcjet-analyze-wasm-what].
39
+
40
+ ## When should I use this?
41
+
42
+ You can use this package to redact sensitive information locally.
43
+ You can redact email addresses, credit card numbers, and more.
44
+ It is also possible to reverse the process: to un-redact what was found.
45
+
46
+ ## Install
47
+
48
+ This package is ESM only.
49
+ Install with npm in Node.js:
50
+
51
+ ```sh
52
+ npm install @arcjet/redact
29
53
  ```
30
54
 
31
- ## Example
55
+ ## Reference
32
56
 
33
- ```typescript
34
- const text = "Hi, my name is John and my email adress is john@example.com";
35
- const [redacted, unredact] = await redact(text, {
36
- redact: ["email", "phone-number"],
57
+ The full reference documentation can be found in the [Arcjet docs][redact-ref].
58
+
59
+ ## Use
60
+
61
+ ```ts
62
+ import { redact } from "@arcjet/redact";
63
+
64
+ const value = "Hi, my name is John and my email adress is john@example.com";
65
+
66
+ const [redacted, unredact] = await redact(value, {
67
+ entities: ["email", "phone-number"],
37
68
  });
38
69
  console.log(redacted);
39
- // Hi, my name is John and my email address is <Redacted email #0>
70
+ // => "Hi, my name is John and my email adress is <Redacted email #0>"
40
71
 
41
72
  const unredacted = unredact("Your email address is <Redacted email #0>");
42
- console.log(unredacted); // Your email address is john@example.com
73
+ console.log(unredacted); // "Your email address is john@example.com"
43
74
  ```
44
75
 
45
76
  ## License
46
77
 
47
- Licensed under the [Apache License, Version 2.0][apache-license].
78
+ [Apache License, Version 2.0][apache-license] © [Arcjet Labs, Inc.][arcjet]
48
79
 
49
- [arcjet]: https://arcjet.com
50
80
  [apache-license]: http://www.apache.org/licenses/LICENSE-2.0
81
+ [arcjet]: https://arcjet.com
82
+ [redact-ref]: https://docs.arcjet.com/redact/reference
83
+ [github-arcjet-analyze-wasm-what]: https://github.com/arcjet/arcjet-js/tree/main/analyze-wasm#what-is-this
84
+ [github-arcjet-redact-wasm]: https://github.com/arcjet/arcjet-js/tree/main/redact-wasm
package/index.d.ts CHANGED
@@ -5,7 +5,7 @@ export type RedactOptions<Detect> = {
5
5
  entities?: ValidEntities<Detect>;
6
6
  contextWindowSize?: number;
7
7
  detect?: Detect;
8
- replace?: (entity: ValidEntities<Detect>[number]) => string | undefined;
8
+ replace?: (entity: ValidEntities<Detect>[number], plaintext: string) => string | undefined;
9
9
  };
10
10
  type Unredact = (input: string) => string;
11
11
  export declare function redact<const Detect extends DetectSensitiveInfoEntities<CustomEntities> | undefined, const CustomEntities extends string>(candidate: string, options?: RedactOptions<Detect>): Promise<[string, Unredact]>;
package/index.js CHANGED
@@ -45,7 +45,7 @@ function performReplacementInText(text, replacement, start, end) {
45
45
  function noOpDetect(_tokens) {
46
46
  return [];
47
47
  }
48
- function noOpReplace(_input) {
48
+ function noOpReplace(_input, _plaintext) {
49
49
  return undefined;
50
50
  }
51
51
  function getWasmOptions(options) {
@@ -89,10 +89,10 @@ async function callRedactWasm(candidate, options) {
89
89
  let convertedReplace = noOpReplace;
90
90
  if (typeof options?.replace === "function") {
91
91
  const replace = options.replace;
92
- convertedReplace = (identifiedType) => {
92
+ convertedReplace = (identifiedType, plaintext) => {
93
93
  return replace(
94
94
  // @ts-ignore because we know this is coming from Wasm
95
- wasmEntitiesToString(identifiedType));
95
+ wasmEntitiesToString(identifiedType), plaintext);
96
96
  };
97
97
  }
98
98
  const wasm = await initializeWasm(convertedDetect, convertedReplace);
package/package.json CHANGED
@@ -1,7 +1,13 @@
1
1
  {
2
2
  "name": "@arcjet/redact",
3
- "version": "1.0.0-beta.1",
3
+ "version": "1.0.0-beta.10",
4
4
  "description": "Arcjet sensitive information redaction library",
5
+ "keywords": [
6
+ "arcjet",
7
+ "redact",
8
+ "utility",
9
+ "util"
10
+ ],
5
11
  "license": "Apache-2.0",
6
12
  "homepage": "https://arcjet.com",
7
13
  "repository": {
@@ -25,30 +31,28 @@
25
31
  "main": "./index.js",
26
32
  "types": "./index.d.ts",
27
33
  "files": [
28
- "LICENSE",
29
- "README.md",
30
- "*.js",
31
- "*.d.ts",
32
- "!*.config.js"
34
+ "index.d.ts",
35
+ "index.js"
33
36
  ],
34
37
  "scripts": {
35
- "prepublishOnly": "npm run build",
36
38
  "build": "rollup --config rollup.config.js",
37
39
  "lint": "eslint .",
38
- "pretest": "npm run build",
39
- "test": "node --test --experimental-test-coverage"
40
+ "prepublishOnly": "npm run build",
41
+ "test-api": "node --test",
42
+ "test-coverage": "node --experimental-test-coverage --test",
43
+ "test": "npm run build && npm run lint && npm run test-coverage"
40
44
  },
41
45
  "dependencies": {
42
- "@arcjet/redact-wasm": "1.0.0-beta.1"
46
+ "@arcjet/redact-wasm": "1.0.0-beta.10"
43
47
  },
44
48
  "devDependencies": {
45
- "@arcjet/eslint-config": "1.0.0-beta.1",
46
- "@arcjet/rollup-config": "1.0.0-beta.1",
47
- "@arcjet/tsconfig": "1.0.0-beta.1",
48
- "@rollup/wasm-node": "4.30.1",
49
+ "@arcjet/eslint-config": "1.0.0-beta.10",
50
+ "@arcjet/rollup-config": "1.0.0-beta.10",
51
+ "@arcjet/tsconfig": "1.0.0-beta.10",
52
+ "@rollup/wasm-node": "4.46.2",
49
53
  "@types/node": "18.18.0",
50
- "expect": "29.7.0",
51
- "typescript": "5.7.3"
54
+ "eslint": "9.32.0",
55
+ "typescript": "5.9.2"
52
56
  },
53
57
  "publishConfig": {
54
58
  "access": "public",