@arcjet/bun 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 +14 -23
  2. package/package.json +13 -12
package/index.js CHANGED
@@ -4,26 +4,13 @@ export * from 'arcjet';
4
4
  import findIp, { parseProxy } from '@arcjet/ip';
5
5
  import { ArcjetHeaders } from '@arcjet/headers';
6
6
  import { env } from 'bun';
7
+ import { readBodyWeb } from '@arcjet/body';
7
8
  import { logLevel, isDevelopment, baseUrl, platform } from '@arcjet/env';
8
9
  import { Logger } from '@arcjet/logger';
9
10
  import { createClient } from '@arcjet/protocol/client.js';
10
11
  import { createTransport } from '@arcjet/transport';
11
12
 
12
13
  /// <reference types="bun-types" />
13
- // TODO: Deduplicate with other packages
14
- function errorMessage(err) {
15
- if (err) {
16
- if (typeof err === "string") {
17
- return err;
18
- }
19
- if (typeof err === "object" &&
20
- "message" in err &&
21
- typeof err.message === "string") {
22
- return err.message;
23
- }
24
- }
25
- return "Unknown problem";
26
- }
27
14
  /**
28
15
  * Create a remote client.
29
16
  *
@@ -38,7 +25,7 @@ function createRemoteClient(options) {
38
25
  // Transport is the HTTP client that the client uses to make requests.
39
26
  const transport = createTransport(url);
40
27
  const sdkStack = "BUN";
41
- const sdkVersion = "1.0.0-beta.16";
28
+ const sdkVersion = "1.0.0-beta.17";
42
29
  return createClient({
43
30
  transport,
44
31
  baseUrl: url,
@@ -126,16 +113,20 @@ function arcjet(options) {
126
113
  // the definition of `props` in the signature but it's hard to track down
127
114
  const req = toArcjetRequest(request, props ?? {});
128
115
  const getBody = async () => {
129
- try {
130
- const clonedRequest = request.clone();
131
- // Awaited to throw if it rejects and we'll just return undefined
132
- const body = await clonedRequest.text();
133
- return body;
116
+ if (request.bodyUsed) {
117
+ throw new Error("Cannot read body: already read");
118
+ }
119
+ const clonedRequest = request.clone();
120
+ let expectedLength;
121
+ const expectedLengthString = request.headers.get("content-length");
122
+ if (typeof expectedLengthString === "string") {
123
+ expectedLength = parseInt(expectedLengthString, 10);
134
124
  }
135
- catch (e) {
136
- log.error("failed to get request body: %s", errorMessage(e));
137
- return;
125
+ // HEAD and GET requests do not have a body.
126
+ if (!clonedRequest.body) {
127
+ throw new Error("Cannot read body: body is missing");
138
128
  }
129
+ return readBodyWeb(clonedRequest.body, { expectedLength });
139
130
  };
140
131
  return aj.protect({ getBody }, req);
141
132
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arcjet/bun",
3
- "version": "1.0.0-beta.16",
3
+ "version": "1.0.0-beta.17",
4
4
  "description": "Arcjet SDK for Bun",
5
5
  "keywords": [
6
6
  "analyze",
@@ -45,22 +45,23 @@
45
45
  "test": "npm run build && npm run lint"
46
46
  },
47
47
  "dependencies": {
48
- "@arcjet/env": "1.0.0-beta.16",
49
- "@arcjet/headers": "1.0.0-beta.16",
50
- "@arcjet/ip": "1.0.0-beta.16",
51
- "@arcjet/logger": "1.0.0-beta.16",
52
- "@arcjet/protocol": "1.0.0-beta.16",
53
- "@arcjet/transport": "1.0.0-beta.16",
54
- "arcjet": "1.0.0-beta.16"
48
+ "@arcjet/body": "1.0.0-beta.17",
49
+ "@arcjet/env": "1.0.0-beta.17",
50
+ "@arcjet/headers": "1.0.0-beta.17",
51
+ "@arcjet/ip": "1.0.0-beta.17",
52
+ "@arcjet/logger": "1.0.0-beta.17",
53
+ "@arcjet/protocol": "1.0.0-beta.17",
54
+ "@arcjet/transport": "1.0.0-beta.17",
55
+ "arcjet": "1.0.0-beta.17"
55
56
  },
56
57
  "devDependencies": {
57
- "@arcjet/eslint-config": "1.0.0-beta.16",
58
- "@arcjet/rollup-config": "1.0.0-beta.16",
59
- "@rollup/wasm-node": "4.54.0",
58
+ "@arcjet/eslint-config": "1.0.0-beta.17",
59
+ "@arcjet/rollup-config": "1.0.0-beta.17",
60
+ "@rollup/wasm-node": "4.55.1",
60
61
  "bun-types": "1.3.5",
61
62
  "eslint": "9.39.2",
62
63
  "typescript": "5.9.3",
63
- "undici-types": "7.15.0"
64
+ "undici-types": "7.18.0"
64
65
  },
65
66
  "publishConfig": {
66
67
  "access": "public",