@arcjet/node 1.0.0-beta.16 → 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.
Files changed (2) hide show
  1. package/index.js +15 -53
  2. package/package.json +12 -12
package/index.js CHANGED
@@ -41,20 +41,6 @@ const env = {
41
41
  return process.env.FIREBASE_CONFIG;
42
42
  },
43
43
  };
44
- // TODO: Deduplicate with other packages
45
- function errorMessage(err) {
46
- if (err) {
47
- if (typeof err === "string") {
48
- return err;
49
- }
50
- if (typeof err === "object" &&
51
- "message" in err &&
52
- typeof err.message === "string") {
53
- return err.message;
54
- }
55
- }
56
- return "Unknown problem";
57
- }
58
44
  /**
59
45
  * Create a remote client.
60
46
  *
@@ -69,7 +55,7 @@ function createRemoteClient(options) {
69
55
  // Transport is the HTTP client that the client uses to make requests.
70
56
  const transport = createTransport(url);
71
57
  const sdkStack = "NODEJS";
72
- const sdkVersion = "1.0.0-beta.16";
58
+ const sdkVersion = "1.0.0-beta.17";
73
59
  return createClient({
74
60
  transport,
75
61
  baseUrl: url,
@@ -197,47 +183,23 @@ function arcjet(options) {
197
183
  // the definition of `props` in the signature but it's hard to track down
198
184
  const req = toArcjetRequest(request, props ?? {});
199
185
  const getBody = async () => {
200
- try {
201
- // If request.body is present then the body was likely read by a package like express' `body-parser`.
202
- // If it's not present then we attempt to read the bytes from the IncomingMessage ourselves.
203
- if (typeof request.body === "string") {
204
- return request.body;
205
- }
206
- else if (typeof request.body !== "undefined" &&
207
- // BigInt cannot be serialized with JSON.stringify
208
- typeof request.body !== "bigint") {
209
- return JSON.stringify(request.body);
210
- }
211
- if (typeof request.on === "function" &&
212
- typeof request.removeListener === "function") {
213
- let expectedLength;
214
- // TODO: This shouldn't need to build headers again but the type
215
- // for `req` above is overly relaxed
216
- const headers = new ArcjetHeaders(request.headers);
217
- const expectedLengthStr = headers.get("content-length");
218
- if (typeof expectedLengthStr === "string") {
219
- try {
220
- expectedLength = parseInt(expectedLengthStr, 10);
221
- }
222
- catch {
223
- // If the expected length couldn't be parsed we'll just not set one.
224
- }
225
- }
226
- // Awaited to throw if it rejects and we'll just return undefined
227
- const body = await readBody(request, {
228
- // We will process 1mb bodies
229
- limit: 1048576,
230
- expectedLength,
231
- });
232
- 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);
233
195
  }
234
- log.warn("no body available");
235
- return;
196
+ return readBody(request, { expectedLength });
236
197
  }
237
- catch (e) {
238
- log.error("failed to get request body: %s", errorMessage(e));
239
- return;
198
+ // A package like `body-parser` was used to read the stream.
199
+ if (typeof request.body === "string") {
200
+ return request.body;
240
201
  }
202
+ return JSON.stringify(request.body);
241
203
  };
242
204
  return aj.protect({ getBody }, req);
243
205
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arcjet/node",
3
- "version": "1.0.0-beta.16",
3
+ "version": "1.0.0-beta.17",
4
4
  "description": "Arcjet SDK for Node.js",
5
5
  "keywords": [
6
6
  "analyze",
@@ -50,20 +50,20 @@
50
50
  "test": "npm run build && npm run lint && npm run test-coverage"
51
51
  },
52
52
  "dependencies": {
53
- "@arcjet/env": "1.0.0-beta.16",
54
- "@arcjet/headers": "1.0.0-beta.16",
55
- "@arcjet/ip": "1.0.0-beta.16",
56
- "@arcjet/logger": "1.0.0-beta.16",
57
- "@arcjet/protocol": "1.0.0-beta.16",
58
- "@arcjet/transport": "1.0.0-beta.16",
59
- "@arcjet/body": "1.0.0-beta.16",
60
- "arcjet": "1.0.0-beta.16"
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"
61
61
  },
62
62
  "devDependencies": {
63
- "@arcjet/eslint-config": "1.0.0-beta.16",
64
- "@arcjet/rollup-config": "1.0.0-beta.16",
63
+ "@arcjet/eslint-config": "1.0.0-beta.17",
64
+ "@arcjet/rollup-config": "1.0.0-beta.17",
65
65
  "@types/node": "25.0.3",
66
- "@rollup/wasm-node": "4.54.0",
66
+ "@rollup/wasm-node": "4.55.1",
67
67
  "eslint": "9.39.2",
68
68
  "typescript": "5.9.3"
69
69
  },