@arcjet/analyze 1.0.0-beta.10 → 1.0.0-beta.11
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.
- package/index.d.ts +75 -9
- package/index.js +88 -14
- package/package.json +8 -9
package/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { BotConfig, BotResult, DetectedSensitiveInfoEntity, DetectSensitiveInfoFunction, EmailValidationConfig, EmailValidationResult, SensitiveInfoEntities, SensitiveInfoEntity, SensitiveInfoResult } from "@arcjet/analyze-wasm";
|
|
1
|
+
import type { BotConfig, BotResult, DetectedSensitiveInfoEntity, DetectSensitiveInfoFunction, EmailValidationConfig, EmailValidationResult, FilterResult, SensitiveInfoEntities, SensitiveInfoEntity, SensitiveInfoResult } from "@arcjet/analyze-wasm";
|
|
2
2
|
import type { ArcjetLogger } from "@arcjet/protocol";
|
|
3
3
|
interface AnalyzeContext {
|
|
4
4
|
log: ArcjetLogger;
|
|
@@ -15,15 +15,81 @@ type AnalyzeRequest = {
|
|
|
15
15
|
query?: string;
|
|
16
16
|
extra?: Record<string, string>;
|
|
17
17
|
};
|
|
18
|
-
export { type EmailValidationConfig, type BotConfig, type SensitiveInfoEntity, type DetectedSensitiveInfoEntity, };
|
|
18
|
+
export { type EmailValidationConfig, type BotConfig, type FilterResult, type SensitiveInfoEntity, type DetectedSensitiveInfoEntity, };
|
|
19
19
|
/**
|
|
20
|
-
* Generate a fingerprint
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
20
|
+
* Generate a fingerprint.
|
|
21
|
+
*
|
|
22
|
+
* Fingerprints can be used to identify the client across multiple requests.
|
|
23
|
+
*
|
|
24
|
+
* This considers different things on the `request` based on the passed
|
|
25
|
+
* `context.characteristics`.
|
|
26
|
+
*
|
|
27
|
+
* See [*Fingerprints* on
|
|
28
|
+
* `docs.arcjet.com`](https://docs.arcjet.com/fingerprints/) for more info.
|
|
29
|
+
*
|
|
30
|
+
* @param context
|
|
31
|
+
* Context.
|
|
32
|
+
* @param request
|
|
33
|
+
* Request.
|
|
34
|
+
* @returns
|
|
35
|
+
* Promise for a SHA-256 fingerprint.
|
|
25
36
|
*/
|
|
26
37
|
export declare function generateFingerprint(context: AnalyzeContext, request: AnalyzeRequest): Promise<string>;
|
|
27
|
-
|
|
38
|
+
/**
|
|
39
|
+
* Check whether an email is valid.
|
|
40
|
+
*
|
|
41
|
+
* @param context
|
|
42
|
+
* Context.
|
|
43
|
+
* @param value
|
|
44
|
+
* Value.
|
|
45
|
+
* @param options
|
|
46
|
+
* Configuration.
|
|
47
|
+
* @returns
|
|
48
|
+
* Promise for a result.
|
|
49
|
+
*/
|
|
50
|
+
export declare function isValidEmail(context: AnalyzeContext, value: string, options: EmailValidationConfig): Promise<EmailValidationResult>;
|
|
51
|
+
/**
|
|
52
|
+
* Detect whether a request is by a bot.
|
|
53
|
+
*
|
|
54
|
+
* @param context
|
|
55
|
+
* Context.
|
|
56
|
+
* @param request
|
|
57
|
+
* Request.
|
|
58
|
+
* @param options
|
|
59
|
+
* Configuration.
|
|
60
|
+
* @returns
|
|
61
|
+
* Promise for a result.
|
|
62
|
+
*/
|
|
28
63
|
export declare function detectBot(context: AnalyzeContext, request: AnalyzeRequest, options: BotConfig): Promise<BotResult>;
|
|
29
|
-
|
|
64
|
+
/**
|
|
65
|
+
* Detect sensitive info in a value.
|
|
66
|
+
*
|
|
67
|
+
* @param context
|
|
68
|
+
* Context.
|
|
69
|
+
* @param value
|
|
70
|
+
* Value.
|
|
71
|
+
* @param entities
|
|
72
|
+
* Strategy to use for detecting sensitive info;
|
|
73
|
+
* either by denying everything and allowing certain tags or by allowing
|
|
74
|
+
* everything and denying certain tags.
|
|
75
|
+
* @param contextWindowSize
|
|
76
|
+
* Number of tokens to pass to `detect`.
|
|
77
|
+
* @param detect
|
|
78
|
+
* Function to detect sensitive info (optional).
|
|
79
|
+
* @returns
|
|
80
|
+
* Promise for a result.
|
|
81
|
+
*/
|
|
82
|
+
export declare function detectSensitiveInfo(context: AnalyzeContext, value: string, entities: SensitiveInfoEntities, contextWindowSize: number, detect?: DetectSensitiveInfoFunction): Promise<SensitiveInfoResult>;
|
|
83
|
+
/**
|
|
84
|
+
* Check if a filter matches a request.
|
|
85
|
+
*
|
|
86
|
+
* @param context
|
|
87
|
+
* Arcjet context.
|
|
88
|
+
* @param request
|
|
89
|
+
* Request.
|
|
90
|
+
* @param expressions
|
|
91
|
+
* Filter expressions.
|
|
92
|
+
* @returns
|
|
93
|
+
* Promise to whether the filter matches the request.
|
|
94
|
+
*/
|
|
95
|
+
export declare function matchFilters(context: AnalyzeContext, request: AnalyzeRequest, expressions: ReadonlyArray<string>, allowIfMatch: boolean): Promise<FilterResult>;
|
package/index.js
CHANGED
|
@@ -50,13 +50,23 @@ function createCoreImports(detect) {
|
|
|
50
50
|
},
|
|
51
51
|
};
|
|
52
52
|
}
|
|
53
|
-
// TODO(@wooorm-arcjet): document what is used to fingerprint.
|
|
54
53
|
/**
|
|
55
|
-
* Generate a fingerprint
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
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.
|
|
60
70
|
*/
|
|
61
71
|
async function generateFingerprint(context, request) {
|
|
62
72
|
const { log } = context;
|
|
@@ -70,20 +80,42 @@ async function generateFingerprint(context, request) {
|
|
|
70
80
|
log.debug("WebAssembly is not supported in this runtime");
|
|
71
81
|
return "";
|
|
72
82
|
}
|
|
73
|
-
|
|
74
|
-
|
|
83
|
+
/**
|
|
84
|
+
* Check whether an email is valid.
|
|
85
|
+
*
|
|
86
|
+
* @param context
|
|
87
|
+
* Context.
|
|
88
|
+
* @param value
|
|
89
|
+
* Value.
|
|
90
|
+
* @param options
|
|
91
|
+
* Configuration.
|
|
92
|
+
* @returns
|
|
93
|
+
* Promise for a result.
|
|
94
|
+
*/
|
|
95
|
+
async function isValidEmail(context, value, options) {
|
|
75
96
|
const { log } = context;
|
|
76
97
|
const coreImports = createCoreImports();
|
|
77
98
|
const analyze = await initializeWasm(coreImports);
|
|
78
99
|
if (typeof analyze !== "undefined") {
|
|
79
|
-
return analyze.isValidEmail(
|
|
100
|
+
return analyze.isValidEmail(value, options);
|
|
80
101
|
// Ignore the `else` branch as we test in places that have WebAssembly.
|
|
81
102
|
/* node:coverage ignore next 4 */
|
|
82
103
|
}
|
|
83
104
|
log.debug("WebAssembly is not supported in this runtime");
|
|
84
105
|
return { blocked: [], validity: "valid" };
|
|
85
106
|
}
|
|
86
|
-
|
|
107
|
+
/**
|
|
108
|
+
* Detect whether a request is by a bot.
|
|
109
|
+
*
|
|
110
|
+
* @param context
|
|
111
|
+
* Context.
|
|
112
|
+
* @param request
|
|
113
|
+
* Request.
|
|
114
|
+
* @param options
|
|
115
|
+
* Configuration.
|
|
116
|
+
* @returns
|
|
117
|
+
* Promise for a result.
|
|
118
|
+
*/
|
|
87
119
|
async function detectBot(context, request, options) {
|
|
88
120
|
const { log } = context;
|
|
89
121
|
const coreImports = createCoreImports();
|
|
@@ -96,14 +128,31 @@ async function detectBot(context, request, options) {
|
|
|
96
128
|
log.debug("WebAssembly is not supported in this runtime");
|
|
97
129
|
return { allowed: [], denied: [], spoofed: false, verified: false };
|
|
98
130
|
}
|
|
99
|
-
|
|
100
|
-
|
|
131
|
+
/**
|
|
132
|
+
* Detect sensitive info in a value.
|
|
133
|
+
*
|
|
134
|
+
* @param context
|
|
135
|
+
* Context.
|
|
136
|
+
* @param value
|
|
137
|
+
* Value.
|
|
138
|
+
* @param entities
|
|
139
|
+
* Strategy to use for detecting sensitive info;
|
|
140
|
+
* either by denying everything and allowing certain tags or by allowing
|
|
141
|
+
* everything and denying certain tags.
|
|
142
|
+
* @param contextWindowSize
|
|
143
|
+
* Number of tokens to pass to `detect`.
|
|
144
|
+
* @param detect
|
|
145
|
+
* Function to detect sensitive info (optional).
|
|
146
|
+
* @returns
|
|
147
|
+
* Promise for a result.
|
|
148
|
+
*/
|
|
149
|
+
async function detectSensitiveInfo(context, value, entities, contextWindowSize, detect) {
|
|
101
150
|
const { log } = context;
|
|
102
151
|
const coreImports = createCoreImports(detect);
|
|
103
152
|
const analyze = await initializeWasm(coreImports);
|
|
104
153
|
if (typeof analyze !== "undefined") {
|
|
105
154
|
const skipCustomDetect = typeof detect !== "function";
|
|
106
|
-
return analyze.detectSensitiveInfo(
|
|
155
|
+
return analyze.detectSensitiveInfo(value, {
|
|
107
156
|
entities,
|
|
108
157
|
contextWindowSize,
|
|
109
158
|
skipCustomDetect,
|
|
@@ -114,5 +163,30 @@ async function detectSensitiveInfo(context, candidate, entities, contextWindowSi
|
|
|
114
163
|
log.debug("WebAssembly is not supported in this runtime");
|
|
115
164
|
throw new Error("SENSITIVE_INFO rule failed to run because Wasm is not supported in this environment.");
|
|
116
165
|
}
|
|
166
|
+
/**
|
|
167
|
+
* Check if a filter matches a request.
|
|
168
|
+
*
|
|
169
|
+
* @param context
|
|
170
|
+
* Arcjet context.
|
|
171
|
+
* @param request
|
|
172
|
+
* Request.
|
|
173
|
+
* @param expressions
|
|
174
|
+
* Filter expressions.
|
|
175
|
+
* @returns
|
|
176
|
+
* Promise to whether the filter matches the request.
|
|
177
|
+
*/
|
|
178
|
+
async function matchFilters(context, request, expressions, allowIfMatch) {
|
|
179
|
+
const coreImports = createCoreImports();
|
|
180
|
+
const analyze = await initializeWasm(coreImports);
|
|
181
|
+
if (typeof analyze !== "undefined") {
|
|
182
|
+
return analyze.matchFilters(JSON.stringify(request),
|
|
183
|
+
// @ts-expect-error: WebAssembly does not support readonly values.
|
|
184
|
+
expressions, allowIfMatch);
|
|
185
|
+
// Ignore the `else` branch as we test in places that have WebAssembly.
|
|
186
|
+
/* node:coverage ignore next 4 */
|
|
187
|
+
}
|
|
188
|
+
context.log.debug("WebAssembly is not supported in this runtime");
|
|
189
|
+
throw new Error("FILTER rule failed to run because Wasm is not supported in this environment.");
|
|
190
|
+
}
|
|
117
191
|
|
|
118
|
-
export { detectBot, detectSensitiveInfo, generateFingerprint, isValidEmail };
|
|
192
|
+
export { detectBot, detectSensitiveInfo, generateFingerprint, isValidEmail, matchFilters };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arcjet/analyze",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.11",
|
|
4
4
|
"description": "Arcjet local analysis engine",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"analyze",
|
|
@@ -45,17 +45,16 @@
|
|
|
45
45
|
"test": "npm run build && npm run lint && npm run test-coverage"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@arcjet/analyze-wasm": "1.0.0-beta.
|
|
49
|
-
"@arcjet/protocol": "1.0.0-beta.
|
|
48
|
+
"@arcjet/analyze-wasm": "1.0.0-beta.11",
|
|
49
|
+
"@arcjet/protocol": "1.0.0-beta.11"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
|
-
"@arcjet/eslint-config": "1.0.0-beta.
|
|
53
|
-
"@arcjet/rollup-config": "1.0.0-beta.
|
|
54
|
-
"@arcjet/tsconfig": "1.0.0-beta.10",
|
|
52
|
+
"@arcjet/eslint-config": "1.0.0-beta.11",
|
|
53
|
+
"@arcjet/rollup-config": "1.0.0-beta.11",
|
|
55
54
|
"@bytecodealliance/jco": "1.5.0",
|
|
56
|
-
"@rollup/wasm-node": "4.
|
|
57
|
-
"@types/node": "
|
|
58
|
-
"eslint": "9.
|
|
55
|
+
"@rollup/wasm-node": "4.50.0",
|
|
56
|
+
"@types/node": "24.3.0",
|
|
57
|
+
"eslint": "9.34.0",
|
|
59
58
|
"typescript": "5.9.2"
|
|
60
59
|
},
|
|
61
60
|
"publishConfig": {
|