@arcjet/node 1.0.0-beta.15 → 1.0.0-beta.17
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.js +19 -56
- package/package.json +18 -15
package/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import * as core from 'arcjet';
|
|
1
2
|
import core__default from 'arcjet';
|
|
2
3
|
export * from 'arcjet';
|
|
3
4
|
import findIp, { parseProxy } from '@arcjet/ip';
|
|
@@ -27,9 +28,6 @@ const env = {
|
|
|
27
28
|
get NODE_ENV() {
|
|
28
29
|
return process.env.NODE_ENV;
|
|
29
30
|
},
|
|
30
|
-
get ARCJET_KEY() {
|
|
31
|
-
return process.env.ARCJET_KEY;
|
|
32
|
-
},
|
|
33
31
|
get ARCJET_ENV() {
|
|
34
32
|
return process.env.ARCJET_ENV;
|
|
35
33
|
},
|
|
@@ -39,21 +37,10 @@ const env = {
|
|
|
39
37
|
get ARCJET_BASE_URL() {
|
|
40
38
|
return process.env.ARCJET_BASE_URL;
|
|
41
39
|
},
|
|
40
|
+
get FIREBASE_CONFIG() {
|
|
41
|
+
return process.env.FIREBASE_CONFIG;
|
|
42
|
+
},
|
|
42
43
|
};
|
|
43
|
-
// TODO: Deduplicate with other packages
|
|
44
|
-
function errorMessage(err) {
|
|
45
|
-
if (err) {
|
|
46
|
-
if (typeof err === "string") {
|
|
47
|
-
return err;
|
|
48
|
-
}
|
|
49
|
-
if (typeof err === "object" &&
|
|
50
|
-
"message" in err &&
|
|
51
|
-
typeof err.message === "string") {
|
|
52
|
-
return err.message;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
return "Unknown problem";
|
|
56
|
-
}
|
|
57
44
|
/**
|
|
58
45
|
* Create a remote client.
|
|
59
46
|
*
|
|
@@ -68,7 +55,7 @@ function createRemoteClient(options) {
|
|
|
68
55
|
// Transport is the HTTP client that the client uses to make requests.
|
|
69
56
|
const transport = createTransport(url);
|
|
70
57
|
const sdkStack = "NODEJS";
|
|
71
|
-
const sdkVersion = "1.0.0-beta.
|
|
58
|
+
const sdkVersion = "1.0.0-beta.17";
|
|
72
59
|
return createClient({
|
|
73
60
|
transport,
|
|
74
61
|
baseUrl: url,
|
|
@@ -196,47 +183,23 @@ function arcjet(options) {
|
|
|
196
183
|
// the definition of `props` in the signature but it's hard to track down
|
|
197
184
|
const req = toArcjetRequest(request, props ?? {});
|
|
198
185
|
const getBody = async () => {
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
return JSON.stringify(request.body);
|
|
209
|
-
}
|
|
210
|
-
if (typeof request.on === "function" &&
|
|
211
|
-
typeof request.removeListener === "function") {
|
|
212
|
-
let expectedLength;
|
|
213
|
-
// TODO: This shouldn't need to build headers again but the type
|
|
214
|
-
// for `req` above is overly relaxed
|
|
215
|
-
const headers = new ArcjetHeaders(request.headers);
|
|
216
|
-
const expectedLengthStr = headers.get("content-length");
|
|
217
|
-
if (typeof expectedLengthStr === "string") {
|
|
218
|
-
try {
|
|
219
|
-
expectedLength = parseInt(expectedLengthStr, 10);
|
|
220
|
-
}
|
|
221
|
-
catch {
|
|
222
|
-
// If the expected length couldn't be parsed we'll just not set one.
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
// Awaited to throw if it rejects and we'll just return undefined
|
|
226
|
-
const body = await readBody(request, {
|
|
227
|
-
// We will process 1mb bodies
|
|
228
|
-
limit: 1048576,
|
|
229
|
-
expectedLength,
|
|
230
|
-
});
|
|
231
|
-
return body;
|
|
186
|
+
// Read the stream if the body is not present.
|
|
187
|
+
if (request.body === null || request.body === undefined) {
|
|
188
|
+
let expectedLength;
|
|
189
|
+
// TODO: This shouldn't need to build headers again but the type
|
|
190
|
+
// for `req` above is overly relaxed
|
|
191
|
+
const headers = new ArcjetHeaders(request.headers);
|
|
192
|
+
const expectedLengthStr = headers.get("content-length");
|
|
193
|
+
if (typeof expectedLengthStr === "string") {
|
|
194
|
+
expectedLength = parseInt(expectedLengthStr, 10);
|
|
232
195
|
}
|
|
233
|
-
|
|
234
|
-
return;
|
|
196
|
+
return readBody(request, { expectedLength });
|
|
235
197
|
}
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
return;
|
|
198
|
+
// A package like `body-parser` was used to read the stream.
|
|
199
|
+
if (typeof request.body === "string") {
|
|
200
|
+
return request.body;
|
|
239
201
|
}
|
|
202
|
+
return JSON.stringify(request.body);
|
|
240
203
|
};
|
|
241
204
|
return aj.protect({ getBody }, req);
|
|
242
205
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arcjet/node",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.17",
|
|
4
4
|
"description": "Arcjet SDK for Node.js",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"analyze",
|
|
@@ -44,24 +44,27 @@
|
|
|
44
44
|
"build": "rollup --config rollup.config.js",
|
|
45
45
|
"lint": "eslint .",
|
|
46
46
|
"prepublishOnly": "npm run build",
|
|
47
|
-
"test": "
|
|
47
|
+
"test-api": "node --test -- test/*.test.js",
|
|
48
|
+
"test-coverage#": "TODO: after node 20, use: ` --test-coverage-branches=100 --test-coverage-exclude \"../{analyze-wasm,analyze,arcjet,cache,duration,env,headers,ip,logger,protocol,runtime,sprintf,stable-hash,transport}/**/*.{js,ts}\" --test-coverage-exclude \"test/**/*.{js,ts}\" --test-coverage-functions=100 --test-coverage-lines=100`",
|
|
49
|
+
"test-coverage": "node --experimental-test-coverage --test -- test/*.test.js",
|
|
50
|
+
"test": "npm run build && npm run lint && npm run test-coverage"
|
|
48
51
|
},
|
|
49
52
|
"dependencies": {
|
|
50
|
-
"@arcjet/env": "1.0.0-beta.
|
|
51
|
-
"@arcjet/headers": "1.0.0-beta.
|
|
52
|
-
"@arcjet/ip": "1.0.0-beta.
|
|
53
|
-
"@arcjet/logger": "1.0.0-beta.
|
|
54
|
-
"@arcjet/protocol": "1.0.0-beta.
|
|
55
|
-
"@arcjet/transport": "1.0.0-beta.
|
|
56
|
-
"@arcjet/body": "1.0.0-beta.
|
|
57
|
-
"arcjet": "1.0.0-beta.
|
|
53
|
+
"@arcjet/env": "1.0.0-beta.17",
|
|
54
|
+
"@arcjet/headers": "1.0.0-beta.17",
|
|
55
|
+
"@arcjet/ip": "1.0.0-beta.17",
|
|
56
|
+
"@arcjet/logger": "1.0.0-beta.17",
|
|
57
|
+
"@arcjet/protocol": "1.0.0-beta.17",
|
|
58
|
+
"@arcjet/transport": "1.0.0-beta.17",
|
|
59
|
+
"@arcjet/body": "1.0.0-beta.17",
|
|
60
|
+
"arcjet": "1.0.0-beta.17"
|
|
58
61
|
},
|
|
59
62
|
"devDependencies": {
|
|
60
|
-
"@arcjet/eslint-config": "1.0.0-beta.
|
|
61
|
-
"@arcjet/rollup-config": "1.0.0-beta.
|
|
62
|
-
"@types/node": "
|
|
63
|
-
"@rollup/wasm-node": "4.
|
|
64
|
-
"eslint": "9.
|
|
63
|
+
"@arcjet/eslint-config": "1.0.0-beta.17",
|
|
64
|
+
"@arcjet/rollup-config": "1.0.0-beta.17",
|
|
65
|
+
"@types/node": "25.0.3",
|
|
66
|
+
"@rollup/wasm-node": "4.55.1",
|
|
67
|
+
"eslint": "9.39.2",
|
|
65
68
|
"typescript": "5.9.3"
|
|
66
69
|
},
|
|
67
70
|
"publishConfig": {
|