@arcjet/bun 1.0.0-alpha.21 → 1.0.0-alpha.23

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 (3) hide show
  1. package/index.js +28 -2
  2. package/index.ts +32 -1
  3. package/package.json +13 -13
package/index.js CHANGED
@@ -9,6 +9,20 @@ import { createClient } from '@arcjet/protocol/client.js';
9
9
  import { createTransport } from '@arcjet/transport';
10
10
 
11
11
  /// <reference types="bun-types/bun.d.ts" />
12
+ // TODO: Deduplicate with other packages
13
+ function errorMessage(err) {
14
+ if (err) {
15
+ if (typeof err === "string") {
16
+ return err;
17
+ }
18
+ if (typeof err === "object" &&
19
+ "message" in err &&
20
+ typeof err.message === "string") {
21
+ return err.message;
22
+ }
23
+ }
24
+ return "Unknown problem";
25
+ }
12
26
  function createRemoteClient(options) {
13
27
  // The base URL for the Arcjet API. Will default to the standard production
14
28
  // API unless environment variable `ARCJET_BASE_URL` is set.
@@ -19,7 +33,7 @@ function createRemoteClient(options) {
19
33
  // Transport is the HTTP client that the client uses to make requests.
20
34
  const transport = createTransport(url);
21
35
  const sdkStack = "BUN";
22
- const sdkVersion = "1.0.0-alpha.21";
36
+ const sdkVersion = "1.0.0-alpha.23";
23
37
  return createClient({
24
38
  transport,
25
39
  baseUrl: url,
@@ -92,7 +106,19 @@ function arcjet(options) {
92
106
  // Further investigation makes it seem like it has something to do with
93
107
  // the definition of `props` in the signature but it's hard to track down
94
108
  const req = toArcjetRequest(request, props ?? {});
95
- return aj.protect({}, req);
109
+ const getBody = async () => {
110
+ try {
111
+ const clonedRequest = request.clone();
112
+ // Awaited to throw if it rejects and we'll just return undefined
113
+ const body = await clonedRequest.text();
114
+ return body;
115
+ }
116
+ catch (e) {
117
+ log.error("failed to get request body: %s", errorMessage(e));
118
+ return;
119
+ }
120
+ };
121
+ return aj.protect({ getBody }, req);
96
122
  },
97
123
  handler(fetch) {
98
124
  return async function (request, server) {
package/index.ts CHANGED
@@ -22,6 +22,25 @@ import { createTransport } from "@arcjet/transport";
22
22
  // Re-export all named exports from the generic SDK
23
23
  export * from "arcjet";
24
24
 
25
+ // TODO: Deduplicate with other packages
26
+ function errorMessage(err: unknown): string {
27
+ if (err) {
28
+ if (typeof err === "string") {
29
+ return err;
30
+ }
31
+
32
+ if (
33
+ typeof err === "object" &&
34
+ "message" in err &&
35
+ typeof err.message === "string"
36
+ ) {
37
+ return err.message;
38
+ }
39
+ }
40
+
41
+ return "Unknown problem";
42
+ }
43
+
25
44
  // Type helpers from https://github.com/sindresorhus/type-fest but adjusted for
26
45
  // our use.
27
46
  //
@@ -235,7 +254,19 @@ export default function arcjet<
235
254
  ExtraProps<Rules>
236
255
  >;
237
256
 
238
- return aj.protect({}, req);
257
+ const getBody = async () => {
258
+ try {
259
+ const clonedRequest = request.clone();
260
+ // Awaited to throw if it rejects and we'll just return undefined
261
+ const body = await clonedRequest.text();
262
+ return body;
263
+ } catch (e) {
264
+ log.error("failed to get request body: %s", errorMessage(e));
265
+ return;
266
+ }
267
+ };
268
+
269
+ return aj.protect({ getBody }, req);
239
270
  },
240
271
  handler(
241
272
  fetch: (
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arcjet/bun",
3
- "version": "1.0.0-alpha.21",
3
+ "version": "1.0.0-alpha.23",
4
4
  "description": "Arcjet SDK for Bun.sh",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://arcjet.com",
@@ -38,22 +38,22 @@
38
38
  "test": "NODE_OPTIONS=--experimental-vm-modules jest --passWithNoTests"
39
39
  },
40
40
  "dependencies": {
41
- "@arcjet/env": "1.0.0-alpha.21",
42
- "@arcjet/headers": "1.0.0-alpha.21",
43
- "@arcjet/ip": "1.0.0-alpha.21",
44
- "@arcjet/logger": "1.0.0-alpha.21",
45
- "@arcjet/protocol": "1.0.0-alpha.21",
46
- "@arcjet/transport": "1.0.0-alpha.21",
47
- "arcjet": "1.0.0-alpha.21"
41
+ "@arcjet/env": "1.0.0-alpha.23",
42
+ "@arcjet/headers": "1.0.0-alpha.23",
43
+ "@arcjet/ip": "1.0.0-alpha.23",
44
+ "@arcjet/logger": "1.0.0-alpha.23",
45
+ "@arcjet/protocol": "1.0.0-alpha.23",
46
+ "@arcjet/transport": "1.0.0-alpha.23",
47
+ "arcjet": "1.0.0-alpha.23"
48
48
  },
49
49
  "devDependencies": {
50
- "@arcjet/eslint-config": "1.0.0-alpha.21",
51
- "@arcjet/rollup-config": "1.0.0-alpha.21",
52
- "@arcjet/tsconfig": "1.0.0-alpha.21",
50
+ "@arcjet/eslint-config": "1.0.0-alpha.23",
51
+ "@arcjet/rollup-config": "1.0.0-alpha.23",
52
+ "@arcjet/tsconfig": "1.0.0-alpha.23",
53
53
  "@jest/globals": "29.7.0",
54
54
  "@types/node": "20.12.12",
55
- "@rollup/wasm-node": "4.20.0",
56
- "bun-types": "1.1.21",
55
+ "@rollup/wasm-node": "4.21.2",
56
+ "bun-types": "1.1.26",
57
57
  "jest": "29.7.0",
58
58
  "typescript": "5.5.4"
59
59
  },