@arcjet/redact-wasm 1.0.0-alpha.23

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.
@@ -0,0 +1,42 @@
1
+ // @generated by wasm2module - DO NOT EDIT
2
+ /* eslint-disable */
3
+ // @ts-nocheck
4
+
5
+ /**
6
+ * This file contains an Arcjet Wasm binary inlined as a base64
7
+ * [Data URL](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URLs)
8
+ * with the application/wasm MIME type.
9
+ *
10
+ * This was chosen to save on storage space over inlining the file directly as
11
+ * a Uint8Array, which would take up ~3x the space of the Wasm file. See
12
+ * https://blobfolio.com/2019/better-binary-batter-mixing-base64-and-uint8array/
13
+ * for more details.
14
+ *
15
+ * It is then decoded into an ArrayBuffer to be used directly via WebAssembly's
16
+ * `compile()` function in our entry point file.
17
+ *
18
+ * This is all done to avoid trying to read or bundle the Wasm asset in various
19
+ * ways based on the platform or bundler a user is targeting. One example being
20
+ * that Next.js requires special `asyncWebAssembly` webpack config to load our
21
+ * Wasm file if we don't do this.
22
+ *
23
+ * In the future, we hope to do away with this workaround when all bundlers
24
+ * properly support consistent asset bundling techniques.
25
+ */
26
+
27
+ const wasmBase64 = "data:application/wasm;base64,AGFzbQEAAAABDgJgA39/fwBgBH9/f38AAwMCAAEEBQFwAQICBxQDATAAAAExAAEIJGltcG9ydHMBAAofAg0AIAAgASACQQARAAALDwAgACABIAIgA0EBEQEACwAvCXByb2R1Y2VycwEMcHJvY2Vzc2VkLWJ5AQ13aXQtY29tcG9uZW50BzAuMjEwLjAAlQEEbmFtZQATEndpdC1jb21wb25lbnQ6c2hpbQF5AgA6aW5kaXJlY3QtYXJjamV0OnJlZGFjdC9jdXN0b20tcmVkYWN0LWRldGVjdC1zZW5zaXRpdmUtaW5mbwE6aW5kaXJlY3QtYXJjamV0OnJlZGFjdC9jdXN0b20tcmVkYWN0LXJlZGFjdC1zZW5zaXRpdmUtaW5mbw==";
28
+ /**
29
+ * Returns a WebAssembly.Module for an Arcjet Wasm binary, decoded from a base64
30
+ * Data URL.
31
+ */
32
+ // TODO: Switch back to top-level await when our platforms all support it
33
+ async function wasm() {
34
+ // This uses fetch to decode the wasm data url, but disabling cache so files
35
+ // larger than 2mb don't fail to parse in the Next.js App Router
36
+ const wasmDecode = await fetch(wasmBase64, { cache: "no-store" });
37
+ const buf = await wasmDecode.arrayBuffer();
38
+ // And then we return it as a WebAssembly.Module
39
+ return WebAssembly.compile(buf);
40
+ }
41
+
42
+ export { wasm };
@@ -0,0 +1,42 @@
1
+ // @generated by wasm2module - DO NOT EDIT
2
+ /* eslint-disable */
3
+ // @ts-nocheck
4
+
5
+ /**
6
+ * This file contains an Arcjet Wasm binary inlined as a base64
7
+ * [Data URL](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URLs)
8
+ * with the application/wasm MIME type.
9
+ *
10
+ * This was chosen to save on storage space over inlining the file directly as
11
+ * a Uint8Array, which would take up ~3x the space of the Wasm file. See
12
+ * https://blobfolio.com/2019/better-binary-batter-mixing-base64-and-uint8array/
13
+ * for more details.
14
+ *
15
+ * It is then decoded into an ArrayBuffer to be used directly via WebAssembly's
16
+ * `compile()` function in our entry point file.
17
+ *
18
+ * This is all done to avoid trying to read or bundle the Wasm asset in various
19
+ * ways based on the platform or bundler a user is targeting. One example being
20
+ * that Next.js requires special `asyncWebAssembly` webpack config to load our
21
+ * Wasm file if we don't do this.
22
+ *
23
+ * In the future, we hope to do away with this workaround when all bundlers
24
+ * properly support consistent asset bundling techniques.
25
+ */
26
+
27
+ const wasmBase64 = "data:application/wasm;base64,AGFzbQEAAAABDgJgA39/fwBgBH9/f38AAhoDAAEwAAAAATEAAQAIJGltcG9ydHMBcAECAgkIAQBBAAsCAAEALwlwcm9kdWNlcnMBDHByb2Nlc3NlZC1ieQENd2l0LWNvbXBvbmVudAcwLjIxMC4wABwEbmFtZQAVFHdpdC1jb21wb25lbnQ6Zml4dXBz";
28
+ /**
29
+ * Returns a WebAssembly.Module for an Arcjet Wasm binary, decoded from a base64
30
+ * Data URL.
31
+ */
32
+ // TODO: Switch back to top-level await when our platforms all support it
33
+ async function wasm() {
34
+ // This uses fetch to decode the wasm data url, but disabling cache so files
35
+ // larger than 2mb don't fail to parse in the Next.js App Router
36
+ const wasmDecode = await fetch(wasmBase64, { cache: "no-store" });
37
+ const buf = await wasmDecode.arrayBuffer();
38
+ // And then we return it as a WebAssembly.Module
39
+ return WebAssembly.compile(buf);
40
+ }
41
+
42
+ export { wasm };
@@ -0,0 +1,6 @@
1
+ import type { RedactedSensitiveInfoEntity, RedactSensitiveInfoConfig, SensitiveInfoEntity } from "./wasm/arcjet_analyze_bindings_redact.component.js";
2
+ import type { ArcjetRedactCustomRedact } from "./wasm/interfaces/arcjet-redact-custom-redact.js";
3
+ export declare function initializeWasm(detect: CustomDetect, replace: CustomRedact): Promise<import("./wasm/arcjet_analyze_bindings_redact.component.js").Root | undefined>;
4
+ type CustomDetect = typeof ArcjetRedactCustomRedact.detectSensitiveInfo;
5
+ type CustomRedact = typeof ArcjetRedactCustomRedact.redactSensitiveInfo;
6
+ export { type CustomDetect, type CustomRedact, type RedactedSensitiveInfoEntity, type RedactSensitiveInfoConfig, type SensitiveInfoEntity, };
package/edge-light.js ADDED
@@ -0,0 +1,34 @@
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
+
6
+ async function moduleFromPath(path) {
7
+ if (path === "arcjet_analyze_bindings_redact.component.core.wasm") {
8
+ return componentCoreWasm;
9
+ }
10
+ if (path === "arcjet_analyze_bindings_redact.component.core2.wasm") {
11
+ return componentCore2Wasm;
12
+ }
13
+ if (path === "arcjet_analyze_bindings_redact.component.core3.wasm") {
14
+ return componentCore3Wasm;
15
+ }
16
+ throw new Error(`Unknown path: ${path}`);
17
+ }
18
+ async function initializeWasm(detect, replace) {
19
+ const coreImports = {
20
+ "arcjet:redact/custom-redact": {
21
+ detectSensitiveInfo: detect,
22
+ redactSensitiveInfo: replace,
23
+ },
24
+ };
25
+ try {
26
+ // Await the instantiation to catch the failure
27
+ return await instantiate(moduleFromPath, coreImports);
28
+ }
29
+ catch {
30
+ console.debug("WebAssembly is not supported in this runtime");
31
+ }
32
+ }
33
+
34
+ export { initializeWasm };
package/edge-light.ts ADDED
@@ -0,0 +1,56 @@
1
+ import { instantiate } from "./wasm/arcjet_analyze_bindings_redact.component.js";
2
+ import type {
3
+ ImportObject,
4
+ RedactedSensitiveInfoEntity,
5
+ RedactSensitiveInfoConfig,
6
+ SensitiveInfoEntity,
7
+ } from "./wasm/arcjet_analyze_bindings_redact.component.js";
8
+ import type { ArcjetRedactCustomRedact } from "./wasm/interfaces/arcjet-redact-custom-redact.js";
9
+
10
+ import componentCoreWasm from "./wasm/arcjet_analyze_bindings_redact.component.core.wasm?module";
11
+ import componentCore2Wasm from "./wasm/arcjet_analyze_bindings_redact.component.core2.wasm?module";
12
+ import componentCore3Wasm from "./wasm/arcjet_analyze_bindings_redact.component.core3.wasm?module";
13
+
14
+ async function moduleFromPath(path: string): Promise<WebAssembly.Module> {
15
+ if (path === "arcjet_analyze_bindings_redact.component.core.wasm") {
16
+ return componentCoreWasm;
17
+ }
18
+ if (path === "arcjet_analyze_bindings_redact.component.core2.wasm") {
19
+ return componentCore2Wasm;
20
+ }
21
+ if (path === "arcjet_analyze_bindings_redact.component.core3.wasm") {
22
+ return componentCore3Wasm;
23
+ }
24
+
25
+ throw new Error(`Unknown path: ${path}`);
26
+ }
27
+
28
+ export async function initializeWasm(
29
+ detect: CustomDetect,
30
+ replace: CustomRedact,
31
+ ) {
32
+ const coreImports: ImportObject = {
33
+ "arcjet:redact/custom-redact": {
34
+ detectSensitiveInfo: detect,
35
+ redactSensitiveInfo: replace,
36
+ },
37
+ };
38
+
39
+ try {
40
+ // Await the instantiation to catch the failure
41
+ return await instantiate(moduleFromPath, coreImports);
42
+ } catch {
43
+ console.debug("WebAssembly is not supported in this runtime");
44
+ }
45
+ }
46
+
47
+ type CustomDetect = typeof ArcjetRedactCustomRedact.detectSensitiveInfo;
48
+ type CustomRedact = typeof ArcjetRedactCustomRedact.redactSensitiveInfo;
49
+
50
+ export {
51
+ type CustomDetect,
52
+ type CustomRedact,
53
+ type RedactedSensitiveInfoEntity,
54
+ type RedactSensitiveInfoConfig,
55
+ type SensitiveInfoEntity,
56
+ };
package/index.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ import type { RedactedSensitiveInfoEntity, RedactSensitiveInfoConfig, SensitiveInfoEntity } from "./wasm/arcjet_analyze_bindings_redact.component.js";
2
+ import type { ArcjetRedactCustomRedact } from "./wasm/interfaces/arcjet-redact-custom-redact.js";
3
+ export declare function initializeWasm(detect: CustomDetect, replace: CustomRedact): Promise<import("./wasm/arcjet_analyze_bindings_redact.component.js").Root | undefined>;
4
+ type CustomDetect = typeof ArcjetRedactCustomRedact.detectSensitiveInfo;
5
+ type CustomRedact = typeof ArcjetRedactCustomRedact.redactSensitiveInfo;
6
+ export { type CustomDetect, type CustomRedact, type RedactedSensitiveInfoEntity, type RedactSensitiveInfoConfig, type SensitiveInfoEntity, };
package/index.js ADDED
@@ -0,0 +1,45 @@
1
+ import { instantiate } from './wasm/arcjet_analyze_bindings_redact.component.js';
2
+ import { wasm } from './_virtual/arcjet_analyze_bindings_redact.component.core.js';
3
+ import { wasm as wasm$1 } from './_virtual/arcjet_analyze_bindings_redact.component.core2.js';
4
+ import { wasm as wasm$2 } from './_virtual/arcjet_analyze_bindings_redact.component.core3.js';
5
+
6
+ const wasmCache = new Map();
7
+ async function moduleFromPath(path) {
8
+ const cachedModule = wasmCache.get(path);
9
+ if (typeof cachedModule !== "undefined") {
10
+ return cachedModule;
11
+ }
12
+ if (path === "arcjet_analyze_bindings_redact.component.core.wasm") {
13
+ const mod = await wasm();
14
+ wasmCache.set(path, mod);
15
+ return mod;
16
+ }
17
+ if (path === "arcjet_analyze_bindings_redact.component.core2.wasm") {
18
+ const mod = await wasm$1();
19
+ wasmCache.set(path, mod);
20
+ return mod;
21
+ }
22
+ if (path === "arcjet_analyze_bindings_redact.component.core3.wasm") {
23
+ const mod = await wasm$2();
24
+ wasmCache.set(path, mod);
25
+ return mod;
26
+ }
27
+ throw new Error(`Unknown path: ${path}`);
28
+ }
29
+ async function initializeWasm(detect, replace) {
30
+ const coreImports = {
31
+ "arcjet:redact/custom-redact": {
32
+ detectSensitiveInfo: detect,
33
+ redactSensitiveInfo: replace,
34
+ },
35
+ };
36
+ try {
37
+ // Await the instantiation to catch the failure
38
+ return await instantiate(moduleFromPath, coreImports);
39
+ }
40
+ catch {
41
+ console.debug("WebAssembly is not supported in this runtime");
42
+ }
43
+ }
44
+
45
+ export { initializeWasm };
package/index.ts ADDED
@@ -0,0 +1,69 @@
1
+ import { instantiate } from "./wasm/arcjet_analyze_bindings_redact.component.js";
2
+ import type {
3
+ ImportObject,
4
+ RedactedSensitiveInfoEntity,
5
+ RedactSensitiveInfoConfig,
6
+ SensitiveInfoEntity,
7
+ } from "./wasm/arcjet_analyze_bindings_redact.component.js";
8
+ import type { ArcjetRedactCustomRedact } from "./wasm/interfaces/arcjet-redact-custom-redact.js";
9
+
10
+ import { wasm as componentCoreWasm } from "./wasm/arcjet_analyze_bindings_redact.component.core.wasm?js";
11
+ import { wasm as componentCore2Wasm } from "./wasm/arcjet_analyze_bindings_redact.component.core2.wasm?js";
12
+ import { wasm as componentCore3Wasm } from "./wasm/arcjet_analyze_bindings_redact.component.core3.wasm?js";
13
+
14
+ const wasmCache = new Map<string, WebAssembly.Module>();
15
+
16
+ async function moduleFromPath(path: string): Promise<WebAssembly.Module> {
17
+ const cachedModule = wasmCache.get(path);
18
+ if (typeof cachedModule !== "undefined") {
19
+ return cachedModule;
20
+ }
21
+
22
+ if (path === "arcjet_analyze_bindings_redact.component.core.wasm") {
23
+ const mod = await componentCoreWasm();
24
+ wasmCache.set(path, mod);
25
+ return mod;
26
+ }
27
+ if (path === "arcjet_analyze_bindings_redact.component.core2.wasm") {
28
+ const mod = await componentCore2Wasm();
29
+ wasmCache.set(path, mod);
30
+ return mod;
31
+ }
32
+ if (path === "arcjet_analyze_bindings_redact.component.core3.wasm") {
33
+ const mod = await componentCore3Wasm();
34
+ wasmCache.set(path, mod);
35
+ return mod;
36
+ }
37
+
38
+ throw new Error(`Unknown path: ${path}`);
39
+ }
40
+
41
+ export async function initializeWasm(
42
+ detect: CustomDetect,
43
+ replace: CustomRedact,
44
+ ) {
45
+ const coreImports: ImportObject = {
46
+ "arcjet:redact/custom-redact": {
47
+ detectSensitiveInfo: detect,
48
+ redactSensitiveInfo: replace,
49
+ },
50
+ };
51
+
52
+ try {
53
+ // Await the instantiation to catch the failure
54
+ return await instantiate(moduleFromPath, coreImports);
55
+ } catch {
56
+ console.debug("WebAssembly is not supported in this runtime");
57
+ }
58
+ }
59
+
60
+ type CustomDetect = typeof ArcjetRedactCustomRedact.detectSensitiveInfo;
61
+ type CustomRedact = typeof ArcjetRedactCustomRedact.redactSensitiveInfo;
62
+
63
+ export {
64
+ type CustomDetect,
65
+ type CustomRedact,
66
+ type RedactedSensitiveInfoEntity,
67
+ type RedactSensitiveInfoConfig,
68
+ type SensitiveInfoEntity,
69
+ };
package/package.json ADDED
@@ -0,0 +1,66 @@
1
+ {
2
+ "name": "@arcjet/redact-wasm",
3
+ "version": "1.0.0-alpha.23",
4
+ "description": "Arcjet sensitive information redaction detection engine",
5
+ "license": "Apache-2.0",
6
+ "homepage": "https://arcjet.com",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/arcjet/arcjet-js.git",
10
+ "directory": "redact-wasm"
11
+ },
12
+ "bugs": {
13
+ "url": "https://github.com/arcjet/arcjet-js/issues",
14
+ "email": "support@arcjet.com"
15
+ },
16
+ "author": {
17
+ "name": "Arcjet",
18
+ "email": "support@arcjet.com",
19
+ "url": "https://arcjet.com"
20
+ },
21
+ "engines": {
22
+ "node": ">=18"
23
+ },
24
+ "type": "module",
25
+ "main": "./index.js",
26
+ "types": "./index.d.ts",
27
+ "exports": {
28
+ "edge-light": "./edge-light.js",
29
+ "workerd": "./workerd.js",
30
+ "default": "./index.js"
31
+ },
32
+ "files": [
33
+ "LICENSE",
34
+ "README.md",
35
+ "_virtual/",
36
+ "wasm/",
37
+ "*.js",
38
+ "*.d.ts",
39
+ "*.ts",
40
+ "!*.config.js"
41
+ ],
42
+ "scripts": {
43
+ "prepublishOnly": "npm run build",
44
+ "jco": "jco transpile wasm/arcjet_analyze_bindings_redact.component.wasm --no-wasi-shim --instantiation async -o wasm",
45
+ "build": "npm run jco; rollup --config rollup.config.js",
46
+ "lint": "eslint .",
47
+ "pretest": "npm run build",
48
+ "test": "NODE_OPTIONS=--experimental-vm-modules jest --passWithNoTests"
49
+ },
50
+ "dependencies": {},
51
+ "devDependencies": {
52
+ "@arcjet/eslint-config": "1.0.0-alpha.23",
53
+ "@arcjet/rollup-config": "1.0.0-alpha.23",
54
+ "@arcjet/tsconfig": "1.0.0-alpha.23",
55
+ "@bytecodealliance/jco": "1.5.0",
56
+ "@jest/globals": "29.7.0",
57
+ "@rollup/wasm-node": "4.21.2",
58
+ "@types/node": "18.18.0",
59
+ "jest": "29.7.0",
60
+ "typescript": "5.5.4"
61
+ },
62
+ "publishConfig": {
63
+ "access": "public",
64
+ "tag": "latest"
65
+ }
66
+ }
@@ -0,0 +1,53 @@
1
+ import type { SensitiveInfoEntity } from './interfaces/arcjet-redact-custom-redact.js';
2
+ export { SensitiveInfoEntity };
3
+ export interface RedactSensitiveInfoConfig {
4
+ entities?: Array<SensitiveInfoEntity>,
5
+ contextWindowSize?: number,
6
+ skipCustomDetect: boolean,
7
+ skipCustomRedact: boolean,
8
+ }
9
+ export interface RedactedSensitiveInfoEntity {
10
+ original: string,
11
+ redacted: string,
12
+ start: number,
13
+ end: number,
14
+ identifiedType: SensitiveInfoEntity,
15
+ }
16
+ import { ArcjetRedactCustomRedact } from './interfaces/arcjet-redact-custom-redact.js';
17
+ export interface ImportObject {
18
+ 'arcjet:redact/custom-redact': typeof ArcjetRedactCustomRedact,
19
+ }
20
+ export interface Root {
21
+ redact(content: string, options: RedactSensitiveInfoConfig): Array<RedactedSensitiveInfoEntity>,
22
+ }
23
+
24
+ /**
25
+ * Instantiates this component with the provided imports and
26
+ * returns a map of all the exports of the component.
27
+ *
28
+ * This function is intended to be similar to the
29
+ * `WebAssembly.instantiate` function. The second `imports`
30
+ * argument is the "import object" for wasm, except here it
31
+ * uses component-model-layer types instead of core wasm
32
+ * integers/numbers/etc.
33
+ *
34
+ * The first argument to this function, `getCoreModule`, is
35
+ * used to compile core wasm modules within the component.
36
+ * Components are composed of core wasm modules and this callback
37
+ * will be invoked per core wasm module. The caller of this
38
+ * function is responsible for reading the core wasm module
39
+ * identified by `path` and returning its compiled
40
+ * `WebAssembly.Module` object. This would use `compileStreaming`
41
+ * on the web, for example.
42
+ */
43
+ export function instantiate(
44
+ getCoreModule: (path: string) => WebAssembly.Module,
45
+ imports: ImportObject,
46
+ instantiateCore?: (module: WebAssembly.Module, imports: Record<string, any>) => WebAssembly.Instance
47
+ ): Root;
48
+ export function instantiate(
49
+ getCoreModule: (path: string) => WebAssembly.Module | Promise<WebAssembly.Module>,
50
+ imports: ImportObject,
51
+ instantiateCore?: (module: WebAssembly.Module, imports: Record<string, any>) => WebAssembly.Instance | Promise<WebAssembly.Instance>
52
+ ): Root | Promise<Root>;
53
+