@arcjet/bun 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/README.md +9 -0
- package/index.js +16 -24
- package/package.json +15 -14
package/README.md
CHANGED
|
@@ -95,6 +95,15 @@ export default {
|
|
|
95
95
|
For more on how to configure Arcjet with Bun and how to protect Bun,
|
|
96
96
|
see the [Arcjet Bun SDK reference][arcjet-reference-bun] on our website.
|
|
97
97
|
|
|
98
|
+
## Test
|
|
99
|
+
|
|
100
|
+
This monorepo is tested with Node.js but this package targets Bun.
|
|
101
|
+
Run the tests from this package folder with:
|
|
102
|
+
|
|
103
|
+
```sh
|
|
104
|
+
bun test
|
|
105
|
+
```
|
|
106
|
+
|
|
98
107
|
## License
|
|
99
108
|
|
|
100
109
|
[Apache License, Version 2.0][apache-license] © [Arcjet Labs, Inc.][arcjet]
|
package/index.js
CHANGED
|
@@ -1,28 +1,16 @@
|
|
|
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';
|
|
4
5
|
import { ArcjetHeaders } from '@arcjet/headers';
|
|
5
6
|
import { env } from 'bun';
|
|
7
|
+
import { readBodyWeb } from '@arcjet/body';
|
|
6
8
|
import { logLevel, isDevelopment, baseUrl, platform } from '@arcjet/env';
|
|
7
9
|
import { Logger } from '@arcjet/logger';
|
|
8
10
|
import { createClient } from '@arcjet/protocol/client.js';
|
|
9
11
|
import { createTransport } from '@arcjet/transport';
|
|
10
12
|
|
|
11
13
|
/// <reference types="bun-types" />
|
|
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
|
-
}
|
|
26
14
|
/**
|
|
27
15
|
* Create a remote client.
|
|
28
16
|
*
|
|
@@ -37,7 +25,7 @@ function createRemoteClient(options) {
|
|
|
37
25
|
// Transport is the HTTP client that the client uses to make requests.
|
|
38
26
|
const transport = createTransport(url);
|
|
39
27
|
const sdkStack = "BUN";
|
|
40
|
-
const sdkVersion = "1.0.0-beta.
|
|
28
|
+
const sdkVersion = "1.0.0-beta.17";
|
|
41
29
|
return createClient({
|
|
42
30
|
transport,
|
|
43
31
|
baseUrl: url,
|
|
@@ -72,7 +60,7 @@ function arcjet(options) {
|
|
|
72
60
|
const proxies = Array.isArray(options.proxies)
|
|
73
61
|
? options.proxies.map(parseProxy)
|
|
74
62
|
: undefined;
|
|
75
|
-
if (isDevelopment(
|
|
63
|
+
if (isDevelopment(env)) {
|
|
76
64
|
log.warn("Arcjet will use 127.0.0.1 when missing public IP address in development mode");
|
|
77
65
|
}
|
|
78
66
|
function toArcjetRequest(request, props) {
|
|
@@ -125,16 +113,20 @@ function arcjet(options) {
|
|
|
125
113
|
// the definition of `props` in the signature but it's hard to track down
|
|
126
114
|
const req = toArcjetRequest(request, props ?? {});
|
|
127
115
|
const getBody = async () => {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
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);
|
|
133
124
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
125
|
+
// HEAD and GET requests do not have a body.
|
|
126
|
+
if (!clonedRequest.body) {
|
|
127
|
+
throw new Error("Cannot read body: body is missing");
|
|
137
128
|
}
|
|
129
|
+
return readBodyWeb(clonedRequest.body, { expectedLength });
|
|
138
130
|
};
|
|
139
131
|
return aj.protect({ getBody }, req);
|
|
140
132
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arcjet/bun",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
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/
|
|
49
|
-
"@arcjet/
|
|
50
|
-
"@arcjet/
|
|
51
|
-
"@arcjet/
|
|
52
|
-
"@arcjet/
|
|
53
|
-
"@arcjet/
|
|
54
|
-
"arcjet": "1.0.0-beta.
|
|
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.
|
|
58
|
-
"@arcjet/rollup-config": "1.0.0-beta.
|
|
59
|
-
"@rollup/wasm-node": "4.
|
|
60
|
-
"bun-types": "1.3.
|
|
61
|
-
"eslint": "9.
|
|
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",
|
|
61
|
+
"bun-types": "1.3.5",
|
|
62
|
+
"eslint": "9.39.2",
|
|
62
63
|
"typescript": "5.9.3",
|
|
63
|
-
"undici-types": "7.
|
|
64
|
+
"undici-types": "7.18.0"
|
|
64
65
|
},
|
|
65
66
|
"publishConfig": {
|
|
66
67
|
"access": "public",
|