@arcjet/node 1.0.0-alpha.24 → 1.0.0-alpha.26

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/README.md +16 -12
  2. package/index.js +1 -1
  3. package/package.json +14 -14
package/README.md CHANGED
@@ -42,27 +42,34 @@ npm install -S @arcjet/node
42
42
 
43
43
  ## Rate limit example
44
44
 
45
- The [Arcjet rate limit][rate-limit-concepts-docs] example below applies a token
46
- bucket rate limit rule to a route where we identify the user based on their ID
47
- e.g. if they are logged in. The bucket is configured with a maximum capacity of
48
- 10 tokens and refills by 5 tokens every 10 seconds. Each request consumes 5
49
- tokens.
45
+ The example below applies a token bucket rate limit rule to a route where we
46
+ identify the user based on their ID e.g. if they are logged in. The bucket is
47
+ configured with a maximum capacity of 10 tokens and refills by 5 tokens every 10
48
+ seconds. Each request consumes 5 tokens.
49
+
50
+ Bot detection is also enabled to block requests from known bots.
50
51
 
51
52
  ```ts
52
- import arcjet, { tokenBucket } from "@arcjet/node";
53
+ import arcjet, { tokenBucket, detectBot } from "@arcjet/node";
53
54
  import http from "node:http";
54
55
 
55
56
  const aj = arcjet({
56
57
  key: process.env.ARCJET_KEY!, // Get your site key from https://app.arcjet.com
58
+ characteristics: ["userId"], // track requests by a custom user ID
57
59
  rules: [
58
60
  // Create a token bucket rate limit. Other algorithms are supported.
59
61
  tokenBucket({
60
62
  mode: "LIVE", // will block requests. Use "DRY_RUN" to log only
61
- characteristics: ["userId"], // track requests by a custom user ID
62
63
  refillRate: 5, // refill 5 tokens per interval
63
64
  interval: 10, // refill every 10 seconds
64
65
  capacity: 10, // bucket maximum capacity of 10 tokens
65
66
  }),
67
+ detectBot({
68
+ mode: "LIVE", // will block requests. Use "DRY_RUN" to log only
69
+ // configured with a list of bots to allow from
70
+ // https://arcjet.com/bot-list
71
+ allow: [], // "allow none" will block all detected bots
72
+ }),
66
73
  ],
67
74
  });
68
75
 
@@ -75,10 +82,8 @@ const server = http.createServer(async function (
75
82
  console.log("Arcjet decision", decision);
76
83
 
77
84
  if (decision.isDenied()) {
78
- res.writeHead(429, { "Content-Type": "application/json" });
79
- res.end(
80
- JSON.stringify({ error: "Too Many Requests", reason: decision.reason }),
81
- );
85
+ res.writeHead(403, { "Content-Type": "application/json" });
86
+ res.end(JSON.stringify({ error: "Forbidden" }));
82
87
  } else {
83
88
  res.writeHead(200, { "Content-Type": "application/json" });
84
89
  res.end(JSON.stringify({ message: "Hello world" }));
@@ -135,6 +140,5 @@ Licensed under the [Apache License, Version 2.0][apache-license].
135
140
  [example-url]: https://example.arcjet.com
136
141
  [quick-start]: https://docs.arcjet.com/get-started/nodejs
137
142
  [example-source]: https://github.com/arcjet/arcjet-js-example
138
- [rate-limit-concepts-docs]: https://docs.arcjet.com/rate-limiting/concepts
139
143
  [shield-concepts-docs]: https://docs.arcjet.com/shield/concepts
140
144
  [apache-license]: http://www.apache.org/licenses/LICENSE-2.0
package/index.js CHANGED
@@ -32,7 +32,7 @@ function createRemoteClient(options) {
32
32
  // Transport is the HTTP client that the client uses to make requests.
33
33
  const transport = createTransport(url);
34
34
  const sdkStack = "NODEJS";
35
- const sdkVersion = "1.0.0-alpha.24";
35
+ const sdkVersion = "1.0.0-alpha.26";
36
36
  return createClient({
37
37
  transport,
38
38
  baseUrl: url,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arcjet/node",
3
- "version": "1.0.0-alpha.24",
3
+ "version": "1.0.0-alpha.26",
4
4
  "description": "Arcjet SDK for Node.js",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://arcjet.com",
@@ -40,24 +40,24 @@
40
40
  "test": "NODE_OPTIONS=--experimental-vm-modules jest --passWithNoTests"
41
41
  },
42
42
  "dependencies": {
43
- "@arcjet/env": "1.0.0-alpha.24",
44
- "@arcjet/headers": "1.0.0-alpha.24",
45
- "@arcjet/ip": "1.0.0-alpha.24",
46
- "@arcjet/logger": "1.0.0-alpha.24",
47
- "@arcjet/protocol": "1.0.0-alpha.24",
48
- "@arcjet/transport": "1.0.0-alpha.24",
49
- "@arcjet/body": "1.0.0-alpha.24",
50
- "arcjet": "1.0.0-alpha.24"
43
+ "@arcjet/env": "1.0.0-alpha.26",
44
+ "@arcjet/headers": "1.0.0-alpha.26",
45
+ "@arcjet/ip": "1.0.0-alpha.26",
46
+ "@arcjet/logger": "1.0.0-alpha.26",
47
+ "@arcjet/protocol": "1.0.0-alpha.26",
48
+ "@arcjet/transport": "1.0.0-alpha.26",
49
+ "@arcjet/body": "1.0.0-alpha.26",
50
+ "arcjet": "1.0.0-alpha.26"
51
51
  },
52
52
  "devDependencies": {
53
- "@arcjet/eslint-config": "1.0.0-alpha.24",
54
- "@arcjet/rollup-config": "1.0.0-alpha.24",
55
- "@arcjet/tsconfig": "1.0.0-alpha.24",
53
+ "@arcjet/eslint-config": "1.0.0-alpha.26",
54
+ "@arcjet/rollup-config": "1.0.0-alpha.26",
55
+ "@arcjet/tsconfig": "1.0.0-alpha.26",
56
56
  "@jest/globals": "29.7.0",
57
57
  "@types/node": "18.18.0",
58
- "@rollup/wasm-node": "4.21.2",
58
+ "@rollup/wasm-node": "4.21.3",
59
59
  "jest": "29.7.0",
60
- "typescript": "5.5.4"
60
+ "typescript": "5.6.2"
61
61
  },
62
62
  "publishConfig": {
63
63
  "access": "public",