@arcjet/analyze 1.6.0 → 1.7.0-rc.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.
@@ -0,0 +1,133 @@
1
+ import { BotConfig, BotResult, DetectSensitiveInfoFunction, DetectedSensitiveInfoEntity, EmailValidationConfig, EmailValidationResult, FilterResult, SensitiveInfoEntities, SensitiveInfoEntity, SensitiveInfoResult } from "@arcjet/analyze-wasm";
2
+ import { ArcjetLogger } from "@arcjet/protocol";
3
+
4
+ //#region src/index.d.ts
5
+ interface AnalyzeContext {
6
+ log: ArcjetLogger;
7
+ characteristics: string[];
8
+ }
9
+ /**
10
+ * Request passed as a JSON string into WebAssembly.
11
+ *
12
+ * This is like `ArcjetRequestDetails` from `@arcjet/protocol`,
13
+ * but fields are often optional across the boundary.
14
+ */
15
+ interface AnalyzeRequest {
16
+ /**
17
+ * IP address (IPv4 or IPv6).
18
+ */
19
+ ip?: string | undefined;
20
+ /**
21
+ * HTTP method (such as `GET`).
22
+ */
23
+ method?: string | undefined;
24
+ /**
25
+ * Protocol (such as `"http:"`).
26
+ */
27
+ protocol?: string | undefined;
28
+ /**
29
+ * Hostname (such as `"example.com"`).
30
+ */
31
+ host?: string | undefined;
32
+ /**
33
+ * Path (such as `"/path/to/resource"`).
34
+ */
35
+ path?: string | undefined;
36
+ /**
37
+ * Headers of the request.
38
+ */
39
+ headers?: Record<string, string> | undefined;
40
+ /**
41
+ * Cookies of the request (such as `"cookie1=value1; cookie2=value2"`).
42
+ */
43
+ cookies?: string | undefined;
44
+ /**
45
+ * Query string of the request (such as `"?q=alpha"`).
46
+ */
47
+ query?: string | undefined;
48
+ /**
49
+ * Extra info.
50
+ */
51
+ extra?: Record<string, string> | undefined;
52
+ }
53
+ /**
54
+ * Generate a fingerprint.
55
+ *
56
+ * Fingerprints can be used to identify the client across multiple requests.
57
+ *
58
+ * This considers different things on the `request` based on the passed
59
+ * `context.characteristics`.
60
+ *
61
+ * See [*Fingerprints* on
62
+ * `docs.arcjet.com`](https://docs.arcjet.com/fingerprints/) for more info.
63
+ *
64
+ * @param context
65
+ * Context.
66
+ * @param request
67
+ * Request.
68
+ * @returns
69
+ * Promise for a SHA-256 fingerprint.
70
+ */
71
+ declare function generateFingerprint(context: AnalyzeContext, request: AnalyzeRequest): Promise<string>;
72
+ /**
73
+ * Check whether an email is valid.
74
+ *
75
+ * @param context
76
+ * Context.
77
+ * @param value
78
+ * Value.
79
+ * @param options
80
+ * Configuration.
81
+ * @returns
82
+ * Promise for a result.
83
+ */
84
+ declare function isValidEmail(context: AnalyzeContext, value: string, options: EmailValidationConfig): Promise<EmailValidationResult>;
85
+ /**
86
+ * Detect whether a request is by a bot.
87
+ *
88
+ * @param context
89
+ * Context.
90
+ * @param request
91
+ * Request.
92
+ * @param options
93
+ * Configuration.
94
+ * @returns
95
+ * Promise for a result.
96
+ */
97
+ declare function detectBot(context: AnalyzeContext, request: AnalyzeRequest, options: BotConfig): Promise<BotResult>;
98
+ /**
99
+ * Detect sensitive info in a value.
100
+ *
101
+ * @param context
102
+ * Context.
103
+ * @param value
104
+ * Value.
105
+ * @param entities
106
+ * Strategy to use for detecting sensitive info;
107
+ * either by denying everything and allowing certain tags or by allowing
108
+ * everything and denying certain tags.
109
+ * @param contextWindowSize
110
+ * Number of tokens to pass to `detect`.
111
+ * @param detect
112
+ * Function to detect sensitive info (optional).
113
+ * @returns
114
+ * Promise for a result.
115
+ */
116
+ declare function detectSensitiveInfo(context: AnalyzeContext, value: string, entities: SensitiveInfoEntities, contextWindowSize: number, detect?: DetectSensitiveInfoFunction): Promise<SensitiveInfoResult>;
117
+ /**
118
+ * Check if a filter matches a request.
119
+ *
120
+ * @param context
121
+ * Arcjet context.
122
+ * @param request
123
+ * Request.
124
+ * @param localFields
125
+ * Fields to use as `local` in the expressions, as serialized JSON.
126
+ * @param expressions
127
+ * Filter expressions.
128
+ * @returns
129
+ * Promise to whether the filter matches the request.
130
+ */
131
+ declare function matchFilters(context: AnalyzeContext, request: AnalyzeRequest, localFields: string, expressions: ReadonlyArray<string>, allowIfMatch: boolean): Promise<FilterResult>;
132
+ //#endregion
133
+ export { AnalyzeRequest, type BotConfig, type DetectedSensitiveInfoEntity, type EmailValidationConfig, type FilterResult, type SensitiveInfoEntity, detectBot, detectSensitiveInfo, generateFingerprint, isValidEmail, matchFilters };
package/dist/index.js ADDED
@@ -0,0 +1,166 @@
1
+ import { initializeWasm } from "@arcjet/analyze-wasm";
2
+ //#region src/index.ts
3
+ const FREE_EMAIL_PROVIDERS = [
4
+ "gmail.com",
5
+ "yahoo.com",
6
+ "hotmail.com",
7
+ "aol.com",
8
+ "hotmail.co.uk"
9
+ ];
10
+ function noOpSensitiveInfoDetect() {
11
+ return [];
12
+ }
13
+ function noOpBotsDetect() {
14
+ return [];
15
+ }
16
+ function createCoreImports(detect) {
17
+ if (typeof detect !== "function") detect = noOpSensitiveInfoDetect;
18
+ return {
19
+ "arcjet:js-req/bot-identifier": { detect: noOpBotsDetect },
20
+ "arcjet:js-req/email-validator-overrides": {
21
+ isFreeEmail(domain) {
22
+ if (FREE_EMAIL_PROVIDERS.includes(domain)) return "yes";
23
+ return "unknown";
24
+ },
25
+ isDisposableEmail() {
26
+ return "unknown";
27
+ },
28
+ hasMxRecords() {
29
+ return "unknown";
30
+ },
31
+ hasGravatar() {
32
+ return "unknown";
33
+ }
34
+ },
35
+ "arcjet:js-req/filter-overrides": { ipLookup() {} },
36
+ "arcjet:js-req/sensitive-information-identifier": { detect },
37
+ "arcjet:js-req/verify-bot": { verify() {
38
+ return "unverifiable";
39
+ } }
40
+ };
41
+ }
42
+ /**
43
+ * Generate a fingerprint.
44
+ *
45
+ * Fingerprints can be used to identify the client across multiple requests.
46
+ *
47
+ * This considers different things on the `request` based on the passed
48
+ * `context.characteristics`.
49
+ *
50
+ * See [*Fingerprints* on
51
+ * `docs.arcjet.com`](https://docs.arcjet.com/fingerprints/) for more info.
52
+ *
53
+ * @param context
54
+ * Context.
55
+ * @param request
56
+ * Request.
57
+ * @returns
58
+ * Promise for a SHA-256 fingerprint.
59
+ */
60
+ async function generateFingerprint(context, request) {
61
+ const { log } = context;
62
+ const analyze = await initializeWasm(createCoreImports());
63
+ if (typeof analyze !== "undefined") return analyze.generateFingerprint(JSON.stringify(request), context.characteristics);
64
+ log.debug("WebAssembly is not supported in this runtime");
65
+ return "";
66
+ }
67
+ /**
68
+ * Check whether an email is valid.
69
+ *
70
+ * @param context
71
+ * Context.
72
+ * @param value
73
+ * Value.
74
+ * @param options
75
+ * Configuration.
76
+ * @returns
77
+ * Promise for a result.
78
+ */
79
+ async function isValidEmail(context, value, options) {
80
+ const { log } = context;
81
+ const analyze = await initializeWasm(createCoreImports());
82
+ if (typeof analyze !== "undefined") return analyze.isValidEmail(value, options);
83
+ log.debug("WebAssembly is not supported in this runtime");
84
+ return {
85
+ blocked: [],
86
+ validity: "valid"
87
+ };
88
+ }
89
+ /**
90
+ * Detect whether a request is by a bot.
91
+ *
92
+ * @param context
93
+ * Context.
94
+ * @param request
95
+ * Request.
96
+ * @param options
97
+ * Configuration.
98
+ * @returns
99
+ * Promise for a result.
100
+ */
101
+ async function detectBot(context, request, options) {
102
+ const { log } = context;
103
+ const analyze = await initializeWasm(createCoreImports());
104
+ if (typeof analyze !== "undefined") return analyze.detectBot(JSON.stringify(request), options);
105
+ log.debug("WebAssembly is not supported in this runtime");
106
+ return {
107
+ allowed: [],
108
+ denied: [],
109
+ spoofed: false,
110
+ verified: false
111
+ };
112
+ }
113
+ /**
114
+ * Detect sensitive info in a value.
115
+ *
116
+ * @param context
117
+ * Context.
118
+ * @param value
119
+ * Value.
120
+ * @param entities
121
+ * Strategy to use for detecting sensitive info;
122
+ * either by denying everything and allowing certain tags or by allowing
123
+ * everything and denying certain tags.
124
+ * @param contextWindowSize
125
+ * Number of tokens to pass to `detect`.
126
+ * @param detect
127
+ * Function to detect sensitive info (optional).
128
+ * @returns
129
+ * Promise for a result.
130
+ */
131
+ async function detectSensitiveInfo(context, value, entities, contextWindowSize, detect) {
132
+ const { log } = context;
133
+ const analyze = await initializeWasm(createCoreImports(detect));
134
+ if (typeof analyze !== "undefined") {
135
+ const skipCustomDetect = typeof detect !== "function";
136
+ return analyze.detectSensitiveInfo(value, {
137
+ entities,
138
+ contextWindowSize,
139
+ skipCustomDetect
140
+ });
141
+ }
142
+ log.debug("WebAssembly is not supported in this runtime");
143
+ throw new Error("SENSITIVE_INFO rule failed to run because Wasm is not supported in this environment.");
144
+ }
145
+ /**
146
+ * Check if a filter matches a request.
147
+ *
148
+ * @param context
149
+ * Arcjet context.
150
+ * @param request
151
+ * Request.
152
+ * @param localFields
153
+ * Fields to use as `local` in the expressions, as serialized JSON.
154
+ * @param expressions
155
+ * Filter expressions.
156
+ * @returns
157
+ * Promise to whether the filter matches the request.
158
+ */
159
+ async function matchFilters(context, request, localFields, expressions, allowIfMatch) {
160
+ const analyze = await initializeWasm(createCoreImports());
161
+ if (typeof analyze !== "undefined") return analyze.matchFilters(JSON.stringify(request), localFields, expressions, allowIfMatch);
162
+ context.log.debug("WebAssembly is not supported in this runtime");
163
+ throw new Error("FILTER rule failed to run because Wasm is not supported in this environment.");
164
+ }
165
+ //#endregion
166
+ export { detectBot, detectSensitiveInfo, generateFingerprint, isValidEmail, matchFilters };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arcjet/analyze",
3
- "version": "1.6.0",
3
+ "version": "1.7.0-rc.0",
4
4
  "description": "Arcjet local analysis engine",
5
5
  "keywords": [
6
6
  "analyze",
@@ -10,54 +10,56 @@
10
10
  "protect",
11
11
  "verify"
12
12
  ],
13
- "license": "Apache-2.0",
14
13
  "homepage": "https://arcjet.com",
15
- "repository": {
16
- "type": "git",
17
- "url": "git+https://github.com/arcjet/arcjet-js.git",
18
- "directory": "analyze"
19
- },
20
14
  "bugs": {
21
15
  "url": "https://github.com/arcjet/arcjet-js/issues",
22
16
  "email": "support@arcjet.com"
23
17
  },
18
+ "license": "Apache-2.0",
24
19
  "author": {
25
20
  "name": "Arcjet",
26
21
  "email": "support@arcjet.com",
27
22
  "url": "https://arcjet.com"
28
23
  },
29
- "engines": {
30
- "node": ">=22.21.0 <23 || >=24.5.0"
24
+ "repository": {
25
+ "type": "git",
26
+ "url": "git+https://github.com/arcjet/arcjet-js.git",
27
+ "directory": "analyze"
31
28
  },
32
- "type": "module",
33
- "main": "./index.js",
34
- "types": "./index.d.ts",
35
29
  "files": [
36
- "index.d.ts",
37
- "index.js"
30
+ "dist"
38
31
  ],
32
+ "type": "module",
33
+ "main": "./dist/index.js",
34
+ "types": "./dist/index.d.ts",
35
+ "exports": {
36
+ ".": {
37
+ "types": "./dist/index.d.ts",
38
+ "default": "./dist/index.js"
39
+ },
40
+ "./package.json": "./package.json"
41
+ },
42
+ "publishConfig": {
43
+ "access": "public",
44
+ "tag": "latest"
45
+ },
39
46
  "scripts": {
40
- "build": "rollup --config rollup.config.js",
41
- "lint": "eslint .",
42
- "test-api": "node --test -- test/*.test.js",
43
- "test-coverage": "node --experimental-test-coverage --test -- test/*.test.js",
44
- "test": "npm run build && npm run lint && npm run test-coverage"
47
+ "build": "tsdown",
48
+ "typecheck": "tsgo --noEmit",
49
+ "test-api": "node --test -- test/*.test.ts",
50
+ "test-coverage": "node --experimental-test-coverage --test -- test/*.test.ts",
51
+ "test": "npm run build && npm run test-coverage"
45
52
  },
46
53
  "dependencies": {
47
- "@arcjet/analyze-wasm": "1.6.0",
48
- "@arcjet/protocol": "1.6.0"
54
+ "@arcjet/analyze-wasm": "1.7.0-rc.0",
55
+ "@arcjet/protocol": "1.7.0-rc.0"
49
56
  },
50
57
  "devDependencies": {
51
- "@arcjet/eslint-config": "1.6.0",
52
- "@arcjet/rollup-config": "1.6.0",
53
- "@bytecodealliance/jco": "1.5.0",
54
- "@rollup/wasm-node": "4.62.2",
55
58
  "@types/node": "22.19.21",
56
- "eslint": "9.39.4",
57
- "typescript": "5.9.3"
59
+ "tsdown": "0.22.3",
60
+ "typescript": "6.0.3"
58
61
  },
59
- "publishConfig": {
60
- "access": "public",
61
- "tag": "latest"
62
+ "engines": {
63
+ "node": ">=22.21.0 <23 || >=24.5.0"
62
64
  }
63
65
  }
package/index.d.ts DELETED
@@ -1,130 +0,0 @@
1
- import type { BotConfig, BotResult, DetectedSensitiveInfoEntity, DetectSensitiveInfoFunction, EmailValidationConfig, EmailValidationResult, FilterResult, SensitiveInfoEntities, SensitiveInfoEntity, SensitiveInfoResult } from "@arcjet/analyze-wasm";
2
- import type { ArcjetLogger } from "@arcjet/protocol";
3
- interface AnalyzeContext {
4
- log: ArcjetLogger;
5
- characteristics: string[];
6
- }
7
- /**
8
- * Request passed as a JSON string into WebAssembly.
9
- *
10
- * This is like `ArcjetRequestDetails` from `@arcjet/protocol`,
11
- * but fields are often optional across the boundary.
12
- */
13
- export interface AnalyzeRequest {
14
- /**
15
- * IP address (IPv4 or IPv6).
16
- */
17
- ip?: string | undefined;
18
- /**
19
- * HTTP method (such as `GET`).
20
- */
21
- method?: string | undefined;
22
- /**
23
- * Protocol (such as `"http:"`).
24
- */
25
- protocol?: string | undefined;
26
- /**
27
- * Hostname (such as `"example.com"`).
28
- */
29
- host?: string | undefined;
30
- /**
31
- * Path (such as `"/path/to/resource"`).
32
- */
33
- path?: string | undefined;
34
- /**
35
- * Headers of the request.
36
- */
37
- headers?: Record<string, string> | undefined;
38
- /**
39
- * Cookies of the request (such as `"cookie1=value1; cookie2=value2"`).
40
- */
41
- cookies?: string | undefined;
42
- /**
43
- * Query string of the request (such as `"?q=alpha"`).
44
- */
45
- query?: string | undefined;
46
- /**
47
- * Extra info.
48
- */
49
- extra?: Record<string, string> | undefined;
50
- }
51
- export { type EmailValidationConfig, type BotConfig, type FilterResult, type SensitiveInfoEntity, type DetectedSensitiveInfoEntity, };
52
- /**
53
- * Generate a fingerprint.
54
- *
55
- * Fingerprints can be used to identify the client across multiple requests.
56
- *
57
- * This considers different things on the `request` based on the passed
58
- * `context.characteristics`.
59
- *
60
- * See [*Fingerprints* on
61
- * `docs.arcjet.com`](https://docs.arcjet.com/fingerprints/) for more info.
62
- *
63
- * @param context
64
- * Context.
65
- * @param request
66
- * Request.
67
- * @returns
68
- * Promise for a SHA-256 fingerprint.
69
- */
70
- export declare function generateFingerprint(context: AnalyzeContext, request: AnalyzeRequest): Promise<string>;
71
- /**
72
- * Check whether an email is valid.
73
- *
74
- * @param context
75
- * Context.
76
- * @param value
77
- * Value.
78
- * @param options
79
- * Configuration.
80
- * @returns
81
- * Promise for a result.
82
- */
83
- export declare function isValidEmail(context: AnalyzeContext, value: string, options: EmailValidationConfig): Promise<EmailValidationResult>;
84
- /**
85
- * Detect whether a request is by a bot.
86
- *
87
- * @param context
88
- * Context.
89
- * @param request
90
- * Request.
91
- * @param options
92
- * Configuration.
93
- * @returns
94
- * Promise for a result.
95
- */
96
- export declare function detectBot(context: AnalyzeContext, request: AnalyzeRequest, options: BotConfig): Promise<BotResult>;
97
- /**
98
- * Detect sensitive info in a value.
99
- *
100
- * @param context
101
- * Context.
102
- * @param value
103
- * Value.
104
- * @param entities
105
- * Strategy to use for detecting sensitive info;
106
- * either by denying everything and allowing certain tags or by allowing
107
- * everything and denying certain tags.
108
- * @param contextWindowSize
109
- * Number of tokens to pass to `detect`.
110
- * @param detect
111
- * Function to detect sensitive info (optional).
112
- * @returns
113
- * Promise for a result.
114
- */
115
- export declare function detectSensitiveInfo(context: AnalyzeContext, value: string, entities: SensitiveInfoEntities, contextWindowSize: number, detect?: DetectSensitiveInfoFunction): Promise<SensitiveInfoResult>;
116
- /**
117
- * Check if a filter matches a request.
118
- *
119
- * @param context
120
- * Arcjet context.
121
- * @param request
122
- * Request.
123
- * @param localFields
124
- * Fields to use as `local` in the expressions, as serialized JSON.
125
- * @param expressions
126
- * Filter expressions.
127
- * @returns
128
- * Promise to whether the filter matches the request.
129
- */
130
- export declare function matchFilters(context: AnalyzeContext, request: AnalyzeRequest, localFields: string, expressions: ReadonlyArray<string>, allowIfMatch: boolean): Promise<FilterResult>;
package/index.js DELETED
@@ -1,199 +0,0 @@
1
- import { initializeWasm } from '@arcjet/analyze-wasm';
2
-
3
- const FREE_EMAIL_PROVIDERS = [
4
- "gmail.com",
5
- "yahoo.com",
6
- "hotmail.com",
7
- "aol.com",
8
- "hotmail.co.uk",
9
- ];
10
- function noOpSensitiveInfoDetect() {
11
- return [];
12
- }
13
- function noOpBotsDetect() {
14
- return [];
15
- }
16
- function createCoreImports(detect) {
17
- if (typeof detect !== "function") {
18
- detect = noOpSensitiveInfoDetect;
19
- }
20
- return {
21
- "arcjet:js-req/bot-identifier": {
22
- detect: noOpBotsDetect,
23
- },
24
- "arcjet:js-req/email-validator-overrides": {
25
- isFreeEmail(domain) {
26
- if (FREE_EMAIL_PROVIDERS.includes(domain)) {
27
- return "yes";
28
- }
29
- return "unknown";
30
- },
31
- isDisposableEmail() {
32
- return "unknown";
33
- },
34
- hasMxRecords() {
35
- return "unknown";
36
- },
37
- hasGravatar() {
38
- return "unknown";
39
- },
40
- },
41
- "arcjet:js-req/filter-overrides": {
42
- ipLookup() {
43
- return undefined;
44
- },
45
- },
46
- // TODO(@wooorm-arcjet): figure out a test case for this with the default `detect`.
47
- "arcjet:js-req/sensitive-information-identifier": {
48
- detect,
49
- },
50
- // TODO(@wooorm-arcjet): figure out a test case for this that calls `verify`.
51
- "arcjet:js-req/verify-bot": {
52
- verify() {
53
- return "unverifiable";
54
- },
55
- },
56
- };
57
- }
58
- /**
59
- * Generate a fingerprint.
60
- *
61
- * Fingerprints can be used to identify the client across multiple requests.
62
- *
63
- * This considers different things on the `request` based on the passed
64
- * `context.characteristics`.
65
- *
66
- * See [*Fingerprints* on
67
- * `docs.arcjet.com`](https://docs.arcjet.com/fingerprints/) for more info.
68
- *
69
- * @param context
70
- * Context.
71
- * @param request
72
- * Request.
73
- * @returns
74
- * Promise for a SHA-256 fingerprint.
75
- */
76
- async function generateFingerprint(context, request) {
77
- const { log } = context;
78
- const coreImports = createCoreImports();
79
- const analyze = await initializeWasm(coreImports);
80
- if (typeof analyze !== "undefined") {
81
- return analyze.generateFingerprint(JSON.stringify(request), context.characteristics);
82
- // Ignore the `else` branch as we test in places that have WebAssembly.
83
- /* node:coverage ignore next 4 */
84
- }
85
- log.debug("WebAssembly is not supported in this runtime");
86
- return "";
87
- }
88
- /**
89
- * Check whether an email is valid.
90
- *
91
- * @param context
92
- * Context.
93
- * @param value
94
- * Value.
95
- * @param options
96
- * Configuration.
97
- * @returns
98
- * Promise for a result.
99
- */
100
- async function isValidEmail(context, value, options) {
101
- const { log } = context;
102
- const coreImports = createCoreImports();
103
- const analyze = await initializeWasm(coreImports);
104
- if (typeof analyze !== "undefined") {
105
- return analyze.isValidEmail(value, options);
106
- // Ignore the `else` branch as we test in places that have WebAssembly.
107
- /* node:coverage ignore next 4 */
108
- }
109
- log.debug("WebAssembly is not supported in this runtime");
110
- return { blocked: [], validity: "valid" };
111
- }
112
- /**
113
- * Detect whether a request is by a bot.
114
- *
115
- * @param context
116
- * Context.
117
- * @param request
118
- * Request.
119
- * @param options
120
- * Configuration.
121
- * @returns
122
- * Promise for a result.
123
- */
124
- async function detectBot(context, request, options) {
125
- const { log } = context;
126
- const coreImports = createCoreImports();
127
- const analyze = await initializeWasm(coreImports);
128
- if (typeof analyze !== "undefined") {
129
- return analyze.detectBot(JSON.stringify(request), options);
130
- // Ignore the `else` branch as we test in places that have WebAssembly.
131
- /* node:coverage ignore next 4 */
132
- }
133
- log.debug("WebAssembly is not supported in this runtime");
134
- return { allowed: [], denied: [], spoofed: false, verified: false };
135
- }
136
- /**
137
- * Detect sensitive info in a value.
138
- *
139
- * @param context
140
- * Context.
141
- * @param value
142
- * Value.
143
- * @param entities
144
- * Strategy to use for detecting sensitive info;
145
- * either by denying everything and allowing certain tags or by allowing
146
- * everything and denying certain tags.
147
- * @param contextWindowSize
148
- * Number of tokens to pass to `detect`.
149
- * @param detect
150
- * Function to detect sensitive info (optional).
151
- * @returns
152
- * Promise for a result.
153
- */
154
- async function detectSensitiveInfo(context, value, entities, contextWindowSize, detect) {
155
- const { log } = context;
156
- const coreImports = createCoreImports(detect);
157
- const analyze = await initializeWasm(coreImports);
158
- if (typeof analyze !== "undefined") {
159
- const skipCustomDetect = typeof detect !== "function";
160
- return analyze.detectSensitiveInfo(value, {
161
- entities,
162
- contextWindowSize,
163
- skipCustomDetect,
164
- });
165
- // Ignore the `else` branch as we test in places that have WebAssembly.
166
- /* node:coverage ignore next 4 */
167
- }
168
- log.debug("WebAssembly is not supported in this runtime");
169
- throw new Error("SENSITIVE_INFO rule failed to run because Wasm is not supported in this environment.");
170
- }
171
- /**
172
- * Check if a filter matches a request.
173
- *
174
- * @param context
175
- * Arcjet context.
176
- * @param request
177
- * Request.
178
- * @param localFields
179
- * Fields to use as `local` in the expressions, as serialized JSON.
180
- * @param expressions
181
- * Filter expressions.
182
- * @returns
183
- * Promise to whether the filter matches the request.
184
- */
185
- async function matchFilters(context, request, localFields, expressions, allowIfMatch) {
186
- const coreImports = createCoreImports();
187
- const analyze = await initializeWasm(coreImports);
188
- if (typeof analyze !== "undefined") {
189
- return analyze.matchFilters(JSON.stringify(request), localFields,
190
- // @ts-expect-error: WebAssembly does not support readonly values.
191
- expressions, allowIfMatch);
192
- // Ignore the `else` branch as we test in places that have WebAssembly.
193
- /* node:coverage ignore next 4 */
194
- }
195
- context.log.debug("WebAssembly is not supported in this runtime");
196
- throw new Error("FILTER rule failed to run because Wasm is not supported in this environment.");
197
- }
198
-
199
- export { detectBot, detectSensitiveInfo, generateFingerprint, isValidEmail, matchFilters };