@arcjet/bun 1.0.0-alpha.20 → 1.0.0-alpha.22
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 +30 -7
- package/index.ts +34 -6
- package/package.json +13 -13
package/index.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { createConnectTransport } from '@connectrpc/connect-node';
|
|
2
1
|
import core__default from 'arcjet';
|
|
3
2
|
export * from 'arcjet';
|
|
4
3
|
import findIP from '@arcjet/ip';
|
|
@@ -7,8 +6,23 @@ import { env } from 'bun';
|
|
|
7
6
|
import { logLevel, baseUrl, isDevelopment, platform } from '@arcjet/env';
|
|
8
7
|
import { Logger } from '@arcjet/logger';
|
|
9
8
|
import { createClient } from '@arcjet/protocol/client.js';
|
|
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.
|
|
@@ -17,12 +31,9 @@ function createRemoteClient(options) {
|
|
|
17
31
|
// in production so calls fail open.
|
|
18
32
|
const timeout = options?.timeout ?? (isDevelopment(env) ? 1000 : 500);
|
|
19
33
|
// Transport is the HTTP client that the client uses to make requests.
|
|
20
|
-
const transport =
|
|
21
|
-
baseUrl: url,
|
|
22
|
-
httpVersion: "1.1",
|
|
23
|
-
});
|
|
34
|
+
const transport = createTransport(url);
|
|
24
35
|
const sdkStack = "BUN";
|
|
25
|
-
const sdkVersion = "1.0.0-alpha.
|
|
36
|
+
const sdkVersion = "1.0.0-alpha.22";
|
|
26
37
|
return createClient({
|
|
27
38
|
transport,
|
|
28
39
|
baseUrl: url,
|
|
@@ -95,7 +106,19 @@ function arcjet(options) {
|
|
|
95
106
|
// Further investigation makes it seem like it has something to do with
|
|
96
107
|
// the definition of `props` in the signature but it's hard to track down
|
|
97
108
|
const req = toArcjetRequest(request, props ?? {});
|
|
98
|
-
|
|
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);
|
|
99
122
|
},
|
|
100
123
|
handler(fetch) {
|
|
101
124
|
return async function (request, server) {
|
package/index.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
/// <reference types="bun-types/bun.d.ts" />
|
|
2
|
-
import { createConnectTransport } from "@connectrpc/connect-node";
|
|
3
2
|
import core from "arcjet";
|
|
4
3
|
import type {
|
|
5
4
|
ArcjetDecision,
|
|
@@ -18,10 +17,30 @@ import { env } from "bun";
|
|
|
18
17
|
import { baseUrl, isDevelopment, logLevel, platform } from "@arcjet/env";
|
|
19
18
|
import { Logger } from "@arcjet/logger";
|
|
20
19
|
import { createClient } from "@arcjet/protocol/client.js";
|
|
20
|
+
import { createTransport } from "@arcjet/transport";
|
|
21
21
|
|
|
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
|
//
|
|
@@ -74,10 +93,7 @@ export function createRemoteClient(options?: RemoteClientOptions) {
|
|
|
74
93
|
const timeout = options?.timeout ?? (isDevelopment(env) ? 1000 : 500);
|
|
75
94
|
|
|
76
95
|
// Transport is the HTTP client that the client uses to make requests.
|
|
77
|
-
const transport =
|
|
78
|
-
baseUrl: url,
|
|
79
|
-
httpVersion: "1.1",
|
|
80
|
-
});
|
|
96
|
+
const transport = createTransport(url);
|
|
81
97
|
|
|
82
98
|
const sdkStack = "BUN";
|
|
83
99
|
const sdkVersion = "__ARCJET_SDK_VERSION__";
|
|
@@ -238,7 +254,19 @@ export default function arcjet<
|
|
|
238
254
|
ExtraProps<Rules>
|
|
239
255
|
>;
|
|
240
256
|
|
|
241
|
-
|
|
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);
|
|
242
270
|
},
|
|
243
271
|
handler(
|
|
244
272
|
fetch: (
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arcjet/bun",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.22",
|
|
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.
|
|
42
|
-
"@arcjet/headers": "1.0.0-alpha.
|
|
43
|
-
"@arcjet/ip": "1.0.0-alpha.
|
|
44
|
-
"@arcjet/logger": "1.0.0-alpha.
|
|
45
|
-
"@arcjet/protocol": "1.0.0-alpha.
|
|
46
|
-
"@
|
|
47
|
-
"arcjet": "1.0.0-alpha.
|
|
41
|
+
"@arcjet/env": "1.0.0-alpha.22",
|
|
42
|
+
"@arcjet/headers": "1.0.0-alpha.22",
|
|
43
|
+
"@arcjet/ip": "1.0.0-alpha.22",
|
|
44
|
+
"@arcjet/logger": "1.0.0-alpha.22",
|
|
45
|
+
"@arcjet/protocol": "1.0.0-alpha.22",
|
|
46
|
+
"@arcjet/transport": "1.0.0-alpha.22",
|
|
47
|
+
"arcjet": "1.0.0-alpha.22"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
|
-
"@arcjet/eslint-config": "1.0.0-alpha.
|
|
51
|
-
"@arcjet/rollup-config": "1.0.0-alpha.
|
|
52
|
-
"@arcjet/tsconfig": "1.0.0-alpha.
|
|
50
|
+
"@arcjet/eslint-config": "1.0.0-alpha.22",
|
|
51
|
+
"@arcjet/rollup-config": "1.0.0-alpha.22",
|
|
52
|
+
"@arcjet/tsconfig": "1.0.0-alpha.22",
|
|
53
53
|
"@jest/globals": "29.7.0",
|
|
54
54
|
"@types/node": "20.12.12",
|
|
55
|
-
"@rollup/wasm-node": "4.
|
|
56
|
-
"bun-types": "1.1.
|
|
55
|
+
"@rollup/wasm-node": "4.21.0",
|
|
56
|
+
"bun-types": "1.1.26",
|
|
57
57
|
"jest": "29.7.0",
|
|
58
58
|
"typescript": "5.5.4"
|
|
59
59
|
},
|