@arcjet/redact-wasm 1.7.0 → 1.8.0

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 (29) hide show
  1. package/{_virtual → dist/_virtual/_./wasm}/arcjet_analyze_bindings_redact.component.core.js +7 -37
  2. package/dist/_virtual/_./wasm/arcjet_analyze_bindings_redact.component.core2.js +12 -0
  3. package/dist/_virtual/_./wasm/arcjet_analyze_bindings_redact.component.core3.js +12 -0
  4. package/dist/edge-light.d.ts +9 -0
  5. package/dist/edge-light.js +24 -0
  6. package/dist/index.d.ts +37 -0
  7. package/dist/index.js +37 -0
  8. package/dist/wasm/arcjet_analyze_bindings_redact.component.d.ts +45 -0
  9. package/dist/wasm/arcjet_analyze_bindings_redact.component.js +273 -0
  10. package/dist/wasm/interfaces/arcjet-redact-custom-redact.d.ts +24 -0
  11. package/dist/wasm.d.ts +52 -0
  12. package/dist/workerd.d.ts +9 -0
  13. package/dist/workerd.js +24 -0
  14. package/package.json +41 -40
  15. package/_virtual/arcjet_analyze_bindings_redact.component.core2.js +0 -42
  16. package/_virtual/arcjet_analyze_bindings_redact.component.core3.js +0 -42
  17. package/edge-light.d.ts +0 -6
  18. package/edge-light.js +0 -34
  19. package/index.d.ts +0 -33
  20. package/index.js +0 -50
  21. package/wasm/arcjet_analyze_bindings_redact.component.d.ts +0 -53
  22. package/wasm/arcjet_analyze_bindings_redact.component.js +0 -334
  23. package/wasm/arcjet_analyze_bindings_redact.component.wasm +0 -0
  24. package/wasm/interfaces/arcjet-redact-custom-redact.d.ts +0 -21
  25. package/workerd.d.ts +0 -6
  26. package/workerd.js +0 -34
  27. /package/{wasm → dist/wasm}/arcjet_analyze_bindings_redact.component.core.wasm +0 -0
  28. /package/{wasm → dist/wasm}/arcjet_analyze_bindings_redact.component.core2.wasm +0 -0
  29. /package/{wasm → dist/wasm}/arcjet_analyze_bindings_redact.component.core3.wasm +0 -0
@@ -0,0 +1,12 @@
1
+ //#region \0./wasm/arcjet_analyze_bindings_redact.component.core2.js
2
+ /**
3
+ * This file contains an Arcjet Wasm binary inlined as a base64 Data URL with
4
+ * the application/wasm MIME type, then decoded into a WebAssembly.Module.
5
+ */
6
+ const wasmBase64 = "data:application/wasm;base64,AGFzbQEAAAABEAJgA39/fwBgBn9/f39/fwADAwIAAQQFAXABAgIHFAMBMAAAATEAAQgkaW1wb3J0cwEACiMCDQAgACABIAJBABEAAAsTACAAIAEgAiADIAQgBUEBEQEACwAvCXByb2R1Y2VycwEMcHJvY2Vzc2VkLWJ5AQ13aXQtY29tcG9uZW50BzAuMjQ0LjA=";
7
+ async function wasm() {
8
+ const buf = await (await fetch(wasmBase64, { cache: "no-store" })).arrayBuffer();
9
+ return WebAssembly.compile(buf);
10
+ }
11
+ //#endregion
12
+ export { wasm };
@@ -0,0 +1,12 @@
1
+ //#region \0./wasm/arcjet_analyze_bindings_redact.component.core3.js
2
+ /**
3
+ * This file contains an Arcjet Wasm binary inlined as a base64 Data URL with
4
+ * the application/wasm MIME type, then decoded into a WebAssembly.Module.
5
+ */
6
+ const wasmBase64 = "data:application/wasm;base64,AGFzbQEAAAABEAJgA39/fwBgBn9/f39/fwACGgMAATAAAAABMQABAAgkaW1wb3J0cwFwAQICCQgBAEEACwIAAQAvCXByb2R1Y2VycwEMcHJvY2Vzc2VkLWJ5AQ13aXQtY29tcG9uZW50BzAuMjQ0LjA=";
7
+ async function wasm() {
8
+ const buf = await (await fetch(wasmBase64, { cache: "no-store" })).arrayBuffer();
9
+ return WebAssembly.compile(buf);
10
+ }
11
+ //#endregion
12
+ export { wasm };
@@ -0,0 +1,9 @@
1
+ import { ArcjetRedactCustomRedact, SensitiveInfoEntity } from "./wasm/interfaces/arcjet-redact-custom-redact.js";
2
+ import { RedactSensitiveInfoConfig, RedactedSensitiveInfoEntity, instantiate } from "./wasm/arcjet_analyze_bindings_redact.component.js";
3
+
4
+ //#region src/edge-light.d.ts
5
+ declare function initializeWasm(detect: CustomDetect, replace: CustomRedact): Promise<Awaited<ReturnType<typeof instantiate>> | undefined>;
6
+ type CustomDetect = typeof ArcjetRedactCustomRedact.detectSensitiveInfo;
7
+ type CustomRedact = typeof ArcjetRedactCustomRedact.redactSensitiveInfo;
8
+ //#endregion
9
+ export { type CustomDetect, type CustomRedact, type RedactSensitiveInfoConfig, type RedactedSensitiveInfoEntity, type SensitiveInfoEntity, initializeWasm };
@@ -0,0 +1,24 @@
1
+ import { instantiate } from "./wasm/arcjet_analyze_bindings_redact.component.js";
2
+ import componentCoreWasm from "./wasm/arcjet_analyze_bindings_redact.component.core.wasm?module";
3
+ import componentCore2Wasm from "./wasm/arcjet_analyze_bindings_redact.component.core2.wasm?module";
4
+ import componentCore3Wasm from "./wasm/arcjet_analyze_bindings_redact.component.core3.wasm?module";
5
+ //#region src/edge-light.ts
6
+ async function moduleFromPath(path) {
7
+ if (path === "arcjet_analyze_bindings_redact.component.core.wasm") return componentCoreWasm;
8
+ if (path === "arcjet_analyze_bindings_redact.component.core2.wasm") return componentCore2Wasm;
9
+ if (path === "arcjet_analyze_bindings_redact.component.core3.wasm") return componentCore3Wasm;
10
+ throw new Error(`Unknown path: ${path}`);
11
+ }
12
+ async function initializeWasm(detect, replace) {
13
+ const coreImports = { "arcjet:redact/custom-redact": {
14
+ detectSensitiveInfo: detect,
15
+ redactSensitiveInfo: replace
16
+ } };
17
+ try {
18
+ return await instantiate(moduleFromPath, coreImports);
19
+ } catch {
20
+ console.debug("WebAssembly is not supported in this runtime");
21
+ }
22
+ }
23
+ //#endregion
24
+ export { initializeWasm };
@@ -0,0 +1,37 @@
1
+ import { ArcjetRedactCustomRedact, SensitiveInfoEntity } from "./wasm/interfaces/arcjet-redact-custom-redact.js";
2
+ import { RedactSensitiveInfoConfig, RedactedSensitiveInfoEntity, instantiate } from "./wasm/arcjet_analyze_bindings_redact.component.js";
3
+
4
+ //#region src/index.d.ts
5
+ /**
6
+ * Initialize the WebAssembly.
7
+ *
8
+ * @param detect
9
+ * Custom detection function.
10
+ * @param replace
11
+ * Custom replacement function.
12
+ * @returns
13
+ * Promise to the initialized WebAssembly instance.
14
+ */
15
+ declare function initializeWasm(detect: CustomDetect, replace: CustomRedact): Promise<Awaited<ReturnType<typeof instantiate>> | undefined>;
16
+ /**
17
+ * Detect sensitive info.
18
+ *
19
+ * @param tokens
20
+ * Tokens to detect in.
21
+ * @returns
22
+ * Array of detected entities.
23
+ */
24
+ type CustomDetect = typeof ArcjetRedactCustomRedact.detectSensitiveInfo;
25
+ /**
26
+ * Redact sensitive info.
27
+ *
28
+ * @param entityType
29
+ * Entity to redact.
30
+ * @param plaintext
31
+ * The plaintext string to redact.
32
+ * @returns
33
+ * Redacted string.
34
+ */
35
+ type CustomRedact = typeof ArcjetRedactCustomRedact.redactSensitiveInfo;
36
+ //#endregion
37
+ export { type RedactSensitiveInfoConfig, type RedactedSensitiveInfoEntity, type SensitiveInfoEntity, initializeWasm };
package/dist/index.js ADDED
@@ -0,0 +1,37 @@
1
+ import { instantiate } from "./wasm/arcjet_analyze_bindings_redact.component.js";
2
+ import { wasm } from "./_virtual/_./wasm/arcjet_analyze_bindings_redact.component.core.js";
3
+ import { wasm as wasm$1 } from "./_virtual/_./wasm/arcjet_analyze_bindings_redact.component.core2.js";
4
+ import { wasm as wasm$2 } from "./_virtual/_./wasm/arcjet_analyze_bindings_redact.component.core3.js";
5
+ //#region src/index.ts
6
+ const componentCoreWasmPromise = wasm();
7
+ const componentCore2WasmPromise = wasm$1();
8
+ const componentCore3WasmPromise = wasm$2();
9
+ async function moduleFromPath(path) {
10
+ if (path === "arcjet_analyze_bindings_redact.component.core.wasm") return componentCoreWasmPromise;
11
+ if (path === "arcjet_analyze_bindings_redact.component.core2.wasm") return componentCore2WasmPromise;
12
+ if (path === "arcjet_analyze_bindings_redact.component.core3.wasm") return componentCore3WasmPromise;
13
+ throw new Error(`Unknown path: ${path}`);
14
+ }
15
+ /**
16
+ * Initialize the WebAssembly.
17
+ *
18
+ * @param detect
19
+ * Custom detection function.
20
+ * @param replace
21
+ * Custom replacement function.
22
+ * @returns
23
+ * Promise to the initialized WebAssembly instance.
24
+ */
25
+ async function initializeWasm(detect, replace) {
26
+ const coreImports = { "arcjet:redact/custom-redact": {
27
+ detectSensitiveInfo: detect,
28
+ redactSensitiveInfo: replace
29
+ } };
30
+ try {
31
+ return await instantiate(moduleFromPath, coreImports);
32
+ } catch {
33
+ console.debug("WebAssembly is not supported in this runtime");
34
+ }
35
+ }
36
+ //#endregion
37
+ export { initializeWasm };
@@ -0,0 +1,45 @@
1
+ import { ArcjetRedactCustomRedact, SensitiveInfoEntity } from "./interfaces/arcjet-redact-custom-redact.js";
2
+
3
+ //#region src/wasm/arcjet_analyze_bindings_redact.component.d.ts
4
+ interface RedactSensitiveInfoConfig {
5
+ entities?: Array<SensitiveInfoEntity>;
6
+ contextWindowSize?: number;
7
+ skipCustomDetect: boolean;
8
+ skipCustomRedact: boolean;
9
+ }
10
+ interface RedactedSensitiveInfoEntity {
11
+ original: string;
12
+ redacted: string;
13
+ start: number;
14
+ end: number;
15
+ identifiedType: SensitiveInfoEntity;
16
+ }
17
+ interface ImportObject {
18
+ 'arcjet:redact/custom-redact': typeof ArcjetRedactCustomRedact;
19
+ }
20
+ interface Root {
21
+ redact(content: string, options: RedactSensitiveInfoConfig): Array<RedactedSensitiveInfoEntity>;
22
+ }
23
+ /**
24
+ * Instantiates this component with the provided imports and
25
+ * returns a map of all the exports of the component.
26
+ *
27
+ * This function is intended to be similar to the
28
+ * `WebAssembly.instantiate` function. The second `imports`
29
+ * argument is the "import object" for wasm, except here it
30
+ * uses component-model-layer types instead of core wasm
31
+ * integers/numbers/etc.
32
+ *
33
+ * The first argument to this function, `getCoreModule`, is
34
+ * used to compile core wasm modules within the component.
35
+ * Components are composed of core wasm modules and this callback
36
+ * will be invoked per core wasm module. The caller of this
37
+ * function is responsible for reading the core wasm module
38
+ * identified by `path` and returning its compiled
39
+ * `WebAssembly.Module` object. This would use `compileStreaming`
40
+ * on the web, for example.
41
+ */
42
+ declare function instantiate(getCoreModule: (path: string) => WebAssembly.Module, imports: ImportObject, instantiateCore?: (module: WebAssembly.Module, imports: Record<string, any>) => WebAssembly.Instance): Root;
43
+ declare function instantiate(getCoreModule: (path: string) => WebAssembly.Module | Promise<WebAssembly.Module>, imports: ImportObject, instantiateCore?: (module: WebAssembly.Module, imports: Record<string, any>) => WebAssembly.Instance | Promise<WebAssembly.Instance>): Root | Promise<Root>;
44
+ //#endregion
45
+ export { ImportObject, RedactSensitiveInfoConfig, RedactedSensitiveInfoEntity, Root, type SensitiveInfoEntity, instantiate };
@@ -0,0 +1,273 @@
1
+ //#region src/wasm/arcjet_analyze_bindings_redact.component.js
2
+ function instantiate(getCoreModule, imports, instantiateCore = WebAssembly.instantiate) {
3
+ let dv = /* @__PURE__ */ new DataView(/* @__PURE__ */ new ArrayBuffer());
4
+ const dataView = (mem) => dv.buffer === mem.buffer ? dv : dv = new DataView(mem.buffer);
5
+ function toUint32(val) {
6
+ return val >>> 0;
7
+ }
8
+ const utf8Decoder = new TextDecoder();
9
+ const utf8Encoder = new TextEncoder();
10
+ let utf8EncodedLen = 0;
11
+ function utf8Encode(s, realloc, memory) {
12
+ if (typeof s !== "string") throw new TypeError("expected a string");
13
+ if (s.length === 0) {
14
+ utf8EncodedLen = 0;
15
+ return 1;
16
+ }
17
+ let buf = utf8Encoder.encode(s);
18
+ let ptr = realloc(0, 0, 1, buf.length);
19
+ new Uint8Array(memory.buffer).set(buf, ptr);
20
+ utf8EncodedLen = buf.length;
21
+ return ptr;
22
+ }
23
+ const module0 = getCoreModule("arcjet_analyze_bindings_redact.component.core.wasm");
24
+ const module1 = getCoreModule("arcjet_analyze_bindings_redact.component.core2.wasm");
25
+ const module2 = getCoreModule("arcjet_analyze_bindings_redact.component.core3.wasm");
26
+ const { detectSensitiveInfo, redactSensitiveInfo } = imports["arcjet:redact/custom-redact"];
27
+ let gen = (function* init() {
28
+ let exports0;
29
+ let exports1;
30
+ let memory0;
31
+ let realloc0;
32
+ function trampoline0(arg0, arg1, arg2) {
33
+ var len1 = arg1;
34
+ var base1 = arg0;
35
+ var result1 = [];
36
+ for (let i = 0; i < len1; i++) {
37
+ const base = base1 + i * 8;
38
+ var ptr0 = dataView(memory0).getInt32(base + 0, true);
39
+ var len0 = dataView(memory0).getInt32(base + 4, true);
40
+ var result0 = utf8Decoder.decode(new Uint8Array(memory0.buffer, ptr0, len0));
41
+ result1.push(result0);
42
+ }
43
+ var vec5 = detectSensitiveInfo(result1);
44
+ var len5 = vec5.length;
45
+ var result5 = realloc0(0, 0, 4, len5 * 16);
46
+ for (let i = 0; i < vec5.length; i++) {
47
+ const e = vec5[i];
48
+ const base = result5 + i * 16;
49
+ var variant4 = e;
50
+ if (variant4 === null || variant4 === void 0) dataView(memory0).setInt8(base + 0, 0, true);
51
+ else {
52
+ const e = variant4;
53
+ dataView(memory0).setInt8(base + 0, 1, true);
54
+ var variant3 = e;
55
+ switch (variant3.tag) {
56
+ case "email":
57
+ dataView(memory0).setInt8(base + 4, 0, true);
58
+ break;
59
+ case "phone-number":
60
+ dataView(memory0).setInt8(base + 4, 1, true);
61
+ break;
62
+ case "ip-address":
63
+ dataView(memory0).setInt8(base + 4, 2, true);
64
+ break;
65
+ case "credit-card-number":
66
+ dataView(memory0).setInt8(base + 4, 3, true);
67
+ break;
68
+ case "custom": {
69
+ const e = variant3.val;
70
+ dataView(memory0).setInt8(base + 4, 4, true);
71
+ var ptr2 = utf8Encode(e, realloc0, memory0);
72
+ var len2 = utf8EncodedLen;
73
+ dataView(memory0).setInt32(base + 12, len2, true);
74
+ dataView(memory0).setInt32(base + 8, ptr2, true);
75
+ break;
76
+ }
77
+ default: throw new TypeError(`invalid variant tag value \`${JSON.stringify(variant3.tag)}\` (received \`${variant3}\`) specified for \`SensitiveInfoEntity\``);
78
+ }
79
+ }
80
+ }
81
+ dataView(memory0).setInt32(arg2 + 4, len5, true);
82
+ dataView(memory0).setInt32(arg2 + 0, result5, true);
83
+ }
84
+ function trampoline1(arg0, arg1, arg2, arg3, arg4, arg5) {
85
+ let variant1;
86
+ switch (arg0) {
87
+ case 0:
88
+ variant1 = { tag: "email" };
89
+ break;
90
+ case 1:
91
+ variant1 = { tag: "phone-number" };
92
+ break;
93
+ case 2:
94
+ variant1 = { tag: "ip-address" };
95
+ break;
96
+ case 3:
97
+ variant1 = { tag: "credit-card-number" };
98
+ break;
99
+ case 4:
100
+ var ptr0 = arg1;
101
+ var len0 = arg2;
102
+ variant1 = {
103
+ tag: "custom",
104
+ val: utf8Decoder.decode(new Uint8Array(memory0.buffer, ptr0, len0))
105
+ };
106
+ break;
107
+ default: throw new TypeError("invalid variant discriminant for SensitiveInfoEntity");
108
+ }
109
+ var ptr2 = arg3;
110
+ var len2 = arg4;
111
+ var result2 = utf8Decoder.decode(new Uint8Array(memory0.buffer, ptr2, len2));
112
+ var variant4 = redactSensitiveInfo(variant1, result2);
113
+ if (variant4 === null || variant4 === void 0) dataView(memory0).setInt8(arg5 + 0, 0, true);
114
+ else {
115
+ const e = variant4;
116
+ dataView(memory0).setInt8(arg5 + 0, 1, true);
117
+ var ptr3 = utf8Encode(e, realloc0, memory0);
118
+ var len3 = utf8EncodedLen;
119
+ dataView(memory0).setInt32(arg5 + 8, len3, true);
120
+ dataView(memory0).setInt32(arg5 + 4, ptr3, true);
121
+ }
122
+ }
123
+ let exports2;
124
+ let postReturn0;
125
+ Promise.all([
126
+ module0,
127
+ module1,
128
+ module2
129
+ ]).catch(() => {});
130
+ ({exports: exports0} = yield instantiateCore(yield module1));
131
+ ({exports: exports1} = yield instantiateCore(yield module0, { "arcjet:redact/custom-redact": {
132
+ "detect-sensitive-info": exports0["0"],
133
+ "redact-sensitive-info": exports0["1"]
134
+ } }));
135
+ memory0 = exports1.memory;
136
+ realloc0 = exports1.cabi_realloc;
137
+ ({exports: exports2} = yield instantiateCore(yield module2, { "": {
138
+ $imports: exports0.$imports,
139
+ "0": trampoline0,
140
+ "1": trampoline1
141
+ } }));
142
+ postReturn0 = exports1.cabi_post_redact;
143
+ function redact(arg0, arg1) {
144
+ var ptr0 = utf8Encode(arg0, realloc0, memory0);
145
+ var len0 = utf8EncodedLen;
146
+ var { entities: v1_0, contextWindowSize: v1_1, skipCustomDetect: v1_2, skipCustomRedact: v1_3 } = arg1;
147
+ var variant5 = v1_0;
148
+ let variant5_0;
149
+ let variant5_1;
150
+ let variant5_2;
151
+ if (variant5 === null || variant5 === void 0) {
152
+ variant5_0 = 0;
153
+ variant5_1 = 0;
154
+ variant5_2 = 0;
155
+ } else {
156
+ var vec4 = variant5;
157
+ var len4 = vec4.length;
158
+ var result4 = realloc0(0, 0, 4, len4 * 12);
159
+ for (let i = 0; i < vec4.length; i++) {
160
+ const e = vec4[i];
161
+ const base = result4 + i * 12;
162
+ var variant3 = e;
163
+ switch (variant3.tag) {
164
+ case "email":
165
+ dataView(memory0).setInt8(base + 0, 0, true);
166
+ break;
167
+ case "phone-number":
168
+ dataView(memory0).setInt8(base + 0, 1, true);
169
+ break;
170
+ case "ip-address":
171
+ dataView(memory0).setInt8(base + 0, 2, true);
172
+ break;
173
+ case "credit-card-number":
174
+ dataView(memory0).setInt8(base + 0, 3, true);
175
+ break;
176
+ case "custom": {
177
+ const e = variant3.val;
178
+ dataView(memory0).setInt8(base + 0, 4, true);
179
+ var ptr2 = utf8Encode(e, realloc0, memory0);
180
+ var len2 = utf8EncodedLen;
181
+ dataView(memory0).setInt32(base + 8, len2, true);
182
+ dataView(memory0).setInt32(base + 4, ptr2, true);
183
+ break;
184
+ }
185
+ default: throw new TypeError(`invalid variant tag value \`${JSON.stringify(variant3.tag)}\` (received \`${variant3}\`) specified for \`SensitiveInfoEntity\``);
186
+ }
187
+ }
188
+ variant5_0 = 1;
189
+ variant5_1 = result4;
190
+ variant5_2 = len4;
191
+ }
192
+ var variant6 = v1_1;
193
+ let variant6_0;
194
+ let variant6_1;
195
+ if (variant6 === null || variant6 === void 0) {
196
+ variant6_0 = 0;
197
+ variant6_1 = 0;
198
+ } else {
199
+ const e = variant6;
200
+ variant6_0 = 1;
201
+ variant6_1 = toUint32(e);
202
+ }
203
+ const ret = exports1.redact(ptr0, len0, variant5_0, variant5_1, variant5_2, variant6_0, variant6_1, v1_2 ? 1 : 0, v1_3 ? 1 : 0);
204
+ var len11 = dataView(memory0).getInt32(ret + 4, true);
205
+ var base11 = dataView(memory0).getInt32(ret + 0, true);
206
+ var result11 = [];
207
+ for (let i = 0; i < len11; i++) {
208
+ const base = base11 + i * 36;
209
+ var ptr7 = dataView(memory0).getInt32(base + 0, true);
210
+ var len7 = dataView(memory0).getInt32(base + 4, true);
211
+ var result7 = utf8Decoder.decode(new Uint8Array(memory0.buffer, ptr7, len7));
212
+ var ptr8 = dataView(memory0).getInt32(base + 8, true);
213
+ var len8 = dataView(memory0).getInt32(base + 12, true);
214
+ var result8 = utf8Decoder.decode(new Uint8Array(memory0.buffer, ptr8, len8));
215
+ let variant10;
216
+ switch (dataView(memory0).getUint8(base + 24, true)) {
217
+ case 0:
218
+ variant10 = { tag: "email" };
219
+ break;
220
+ case 1:
221
+ variant10 = { tag: "phone-number" };
222
+ break;
223
+ case 2:
224
+ variant10 = { tag: "ip-address" };
225
+ break;
226
+ case 3:
227
+ variant10 = { tag: "credit-card-number" };
228
+ break;
229
+ case 4:
230
+ var ptr9 = dataView(memory0).getInt32(base + 28, true);
231
+ var len9 = dataView(memory0).getInt32(base + 32, true);
232
+ variant10 = {
233
+ tag: "custom",
234
+ val: utf8Decoder.decode(new Uint8Array(memory0.buffer, ptr9, len9))
235
+ };
236
+ break;
237
+ default: throw new TypeError("invalid variant discriminant for SensitiveInfoEntity");
238
+ }
239
+ result11.push({
240
+ original: result7,
241
+ redacted: result8,
242
+ start: dataView(memory0).getInt32(base + 16, true) >>> 0,
243
+ end: dataView(memory0).getInt32(base + 20, true) >>> 0,
244
+ identifiedType: variant10
245
+ });
246
+ }
247
+ const retVal = result11;
248
+ postReturn0(ret);
249
+ return retVal;
250
+ }
251
+ return { redact };
252
+ })();
253
+ let promise, resolve, reject;
254
+ function runNext(value) {
255
+ try {
256
+ let done;
257
+ do
258
+ ({value, done} = gen.next(value));
259
+ while (!(value instanceof Promise) && !done);
260
+ if (done) if (resolve) resolve(value);
261
+ else return value;
262
+ if (!promise) promise = new Promise((_resolve, _reject) => (resolve = _resolve, reject = _reject));
263
+ value.then((nextVal) => done ? resolve() : runNext(nextVal), reject);
264
+ } catch (e) {
265
+ if (reject) reject(e);
266
+ else throw e;
267
+ }
268
+ }
269
+ const maybeSyncReturn = runNext(null);
270
+ return promise || maybeSyncReturn;
271
+ }
272
+ //#endregion
273
+ export { instantiate };
@@ -0,0 +1,24 @@
1
+ //#region src/wasm/interfaces/arcjet-redact-custom-redact.d.ts
2
+ declare namespace ArcjetRedactCustomRedact {
3
+ export function detectSensitiveInfo(tokens: Array<string>): Array<SensitiveInfoEntity | undefined>;
4
+ export function redactSensitiveInfo(entityType: SensitiveInfoEntity, plaintext: string): string | undefined;
5
+ }
6
+ type SensitiveInfoEntity = SensitiveInfoEntityEmail | SensitiveInfoEntityPhoneNumber | SensitiveInfoEntityIpAddress | SensitiveInfoEntityCreditCardNumber | SensitiveInfoEntityCustom;
7
+ interface SensitiveInfoEntityEmail {
8
+ tag: 'email';
9
+ }
10
+ interface SensitiveInfoEntityPhoneNumber {
11
+ tag: 'phone-number';
12
+ }
13
+ interface SensitiveInfoEntityIpAddress {
14
+ tag: 'ip-address';
15
+ }
16
+ interface SensitiveInfoEntityCreditCardNumber {
17
+ tag: 'credit-card-number';
18
+ }
19
+ interface SensitiveInfoEntityCustom {
20
+ tag: 'custom';
21
+ val: string;
22
+ }
23
+ //#endregion
24
+ export { ArcjetRedactCustomRedact, SensitiveInfoEntity, SensitiveInfoEntityCreditCardNumber, SensitiveInfoEntityCustom, SensitiveInfoEntityEmail, SensitiveInfoEntityIpAddress, SensitiveInfoEntityPhoneNumber };
package/dist/wasm.d.ts ADDED
@@ -0,0 +1,52 @@
1
+ //#region src/wasm.d.ts
2
+ // Basic interface of WebAssembly that we use.
3
+ // See:
4
+ // <https://github.com/microsoft/TypeScript/blob/7956c0016/src/lib/dom.generated.d.ts#L37654>.
5
+ // This only includes `Module` which we use here.
6
+ // This can be removed when WebAssembly is in `@types/node` as we use that here.
7
+ declare namespace WebAssemblyLike {
8
+ type ImportExportKind = "function" | "global" | "memory" | "table";
9
+ interface ModuleExportDescriptor {
10
+ kind: ImportExportKind;
11
+ name: string;
12
+ }
13
+ interface ModuleImportDescriptor {
14
+ kind: ImportExportKind;
15
+ module: string;
16
+ name: string;
17
+ }
18
+ interface Module {}
19
+ const Module: {
20
+ prototype: Module;
21
+ new (bytes: ArrayBufferView<ArrayBuffer> | ArrayBuffer): Module;
22
+ customSections(moduleObject: Module, sectionName: string): ArrayBuffer[];
23
+ exports(moduleObject: Module): ModuleExportDescriptor[];
24
+ imports(moduleObject: Module): ModuleImportDescriptor[];
25
+ };
26
+ }
27
+ /**
28
+ * Vercel uses the `.wasm?module` suffix to make WebAssembly available in their
29
+ * Vercel Functions product.
30
+ *
31
+ * https://vercel.com/docs/functions/wasm#using-a-webassembly-file
32
+ */
33
+ declare module "*.wasm?module" {
34
+ export default WebAssemblyLike.Module;
35
+ }
36
+ /**
37
+ * The Cloudflare docs say they support the `.wasm?module` suffix, but that
38
+ * seems to no longer be the case with Wrangler 2 so we need to have separate
39
+ * imports for just the `.wasm` files.
40
+ *
41
+ * https://developers.cloudflare.com/workers/runtime-apis/webassembly/javascript/#bundling
42
+ */
43
+ declare module "*.wasm" {
44
+ export default WebAssemblyLike.Module;
45
+ }
46
+ /**
47
+ * Our Rollup build turns `.wasm?js` imports into JS imports that provide the
48
+ * `wasm()` function which decodes a base64 Data URL into a WebAssembly Module
49
+ */
50
+ declare module "*.wasm?js" {
51
+ export function wasm(): Promise<WebAssemblyLike.Module>;
52
+ }
@@ -0,0 +1,9 @@
1
+ import { ArcjetRedactCustomRedact, SensitiveInfoEntity } from "./wasm/interfaces/arcjet-redact-custom-redact.js";
2
+ import { RedactSensitiveInfoConfig, RedactedSensitiveInfoEntity, instantiate } from "./wasm/arcjet_analyze_bindings_redact.component.js";
3
+
4
+ //#region src/workerd.d.ts
5
+ declare function initializeWasm(detect: CustomDetect, replace: CustomRedact): Promise<Awaited<ReturnType<typeof instantiate>> | undefined>;
6
+ type CustomDetect = typeof ArcjetRedactCustomRedact.detectSensitiveInfo;
7
+ type CustomRedact = typeof ArcjetRedactCustomRedact.redactSensitiveInfo;
8
+ //#endregion
9
+ export { type CustomDetect, type CustomRedact, type RedactSensitiveInfoConfig, type RedactedSensitiveInfoEntity, type SensitiveInfoEntity, initializeWasm };
@@ -0,0 +1,24 @@
1
+ import { instantiate } from "./wasm/arcjet_analyze_bindings_redact.component.js";
2
+ import componentCoreWasm from "./wasm/arcjet_analyze_bindings_redact.component.core.wasm";
3
+ import componentCore2Wasm from "./wasm/arcjet_analyze_bindings_redact.component.core2.wasm";
4
+ import componentCore3Wasm from "./wasm/arcjet_analyze_bindings_redact.component.core3.wasm";
5
+ //#region src/workerd.ts
6
+ async function moduleFromPath(path) {
7
+ if (path === "arcjet_analyze_bindings_redact.component.core.wasm") return componentCoreWasm;
8
+ if (path === "arcjet_analyze_bindings_redact.component.core2.wasm") return componentCore2Wasm;
9
+ if (path === "arcjet_analyze_bindings_redact.component.core3.wasm") return componentCore3Wasm;
10
+ throw new Error(`Unknown path: ${path}`);
11
+ }
12
+ async function initializeWasm(detect, replace) {
13
+ const coreImports = { "arcjet:redact/custom-redact": {
14
+ detectSensitiveInfo: detect,
15
+ redactSensitiveInfo: replace
16
+ } };
17
+ try {
18
+ return await instantiate(moduleFromPath, coreImports);
19
+ } catch {
20
+ console.debug("WebAssembly is not supported in this runtime");
21
+ }
22
+ }
23
+ //#endregion
24
+ export { initializeWasm };