@arcjet/bun 1.0.0-alpha.24 → 1.0.0-alpha.25
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 +10 -7
- package/index.js +1 -1
- package/package.json +13 -13
package/README.md
CHANGED
|
@@ -37,7 +37,7 @@ Try an Arcjet protected app live at [https://example.arcjet.com][example-url]
|
|
|
37
37
|
bun add @arcjet/bun
|
|
38
38
|
```
|
|
39
39
|
|
|
40
|
-
## Rate limit example
|
|
40
|
+
## Rate limit + bot detection example
|
|
41
41
|
|
|
42
42
|
The [Arcjet rate limit][rate-limit-concepts-docs] example below applies a token
|
|
43
43
|
bucket rate limit rule to a route where we identify the user based on their ID
|
|
@@ -46,19 +46,25 @@ e.g. if they are logged in. The bucket is configured with a maximum capacity of
|
|
|
46
46
|
tokens.
|
|
47
47
|
|
|
48
48
|
```ts
|
|
49
|
-
import arcjet, { tokenBucket } from "@arcjet/bun";
|
|
49
|
+
import arcjet, { tokenBucket, detectBot } from "@arcjet/bun";
|
|
50
50
|
|
|
51
51
|
const aj = arcjet({
|
|
52
52
|
key: Bun.env.ARCJET_KEY!, // Get your site key from https://app.arcjet.com
|
|
53
|
+
characteristics: ["userId"], // track requests by a custom user ID
|
|
53
54
|
rules: [
|
|
54
55
|
// Create a token bucket rate limit. Other algorithms are supported.
|
|
55
56
|
tokenBucket({
|
|
56
57
|
mode: "LIVE", // will block requests. Use "DRY_RUN" to log only
|
|
57
|
-
characteristics: ["userId"], // track requests by a custom user ID
|
|
58
58
|
refillRate: 5, // refill 5 tokens per interval
|
|
59
59
|
interval: 10, // refill every 10 seconds
|
|
60
60
|
capacity: 10, // bucket maximum capacity of 10 tokens
|
|
61
61
|
}),
|
|
62
|
+
detectBot({
|
|
63
|
+
mode: "LIVE", // will block requests. Use "DRY_RUN" to log only
|
|
64
|
+
// configured with a list of bots to allow from
|
|
65
|
+
// https://arcjet.com/bot-list
|
|
66
|
+
allow: [], // "allow none" will block all detected bots
|
|
67
|
+
}),
|
|
62
68
|
],
|
|
63
69
|
});
|
|
64
70
|
|
|
@@ -70,10 +76,7 @@ export default {
|
|
|
70
76
|
console.log("Arcjet decision", decision);
|
|
71
77
|
|
|
72
78
|
if (decision.isDenied()) {
|
|
73
|
-
return Response.json(
|
|
74
|
-
{ error: "Too Many Requests", reason: decision.reason },
|
|
75
|
-
{ status: 429 },
|
|
76
|
-
);
|
|
79
|
+
return Response.json({ error: "Forbidden" }, { status: 403 });
|
|
77
80
|
} else {
|
|
78
81
|
return Response.json({ message: "Hello world" });
|
|
79
82
|
}
|
package/index.js
CHANGED
|
@@ -33,7 +33,7 @@ function createRemoteClient(options) {
|
|
|
33
33
|
// Transport is the HTTP client that the client uses to make requests.
|
|
34
34
|
const transport = createTransport(url);
|
|
35
35
|
const sdkStack = "BUN";
|
|
36
|
-
const sdkVersion = "1.0.0-alpha.
|
|
36
|
+
const sdkVersion = "1.0.0-alpha.25";
|
|
37
37
|
return createClient({
|
|
38
38
|
transport,
|
|
39
39
|
baseUrl: url,
|
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.25",
|
|
4
4
|
"description": "Arcjet SDK for Bun.sh",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"homepage": "https://arcjet.com",
|
|
@@ -38,24 +38,24 @@
|
|
|
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
|
-
"@arcjet/transport": "1.0.0-alpha.
|
|
47
|
-
"arcjet": "1.0.0-alpha.
|
|
41
|
+
"@arcjet/env": "1.0.0-alpha.25",
|
|
42
|
+
"@arcjet/headers": "1.0.0-alpha.25",
|
|
43
|
+
"@arcjet/ip": "1.0.0-alpha.25",
|
|
44
|
+
"@arcjet/logger": "1.0.0-alpha.25",
|
|
45
|
+
"@arcjet/protocol": "1.0.0-alpha.25",
|
|
46
|
+
"@arcjet/transport": "1.0.0-alpha.25",
|
|
47
|
+
"arcjet": "1.0.0-alpha.25"
|
|
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.25",
|
|
51
|
+
"@arcjet/rollup-config": "1.0.0-alpha.25",
|
|
52
|
+
"@arcjet/tsconfig": "1.0.0-alpha.25",
|
|
53
53
|
"@jest/globals": "29.7.0",
|
|
54
54
|
"@types/node": "20.12.12",
|
|
55
55
|
"@rollup/wasm-node": "4.21.2",
|
|
56
|
-
"bun-types": "1.1.
|
|
56
|
+
"bun-types": "1.1.27",
|
|
57
57
|
"jest": "29.7.0",
|
|
58
|
-
"typescript": "5.
|
|
58
|
+
"typescript": "5.6.2"
|
|
59
59
|
},
|
|
60
60
|
"publishConfig": {
|
|
61
61
|
"access": "public",
|