@arcjet/bun 1.4.0 → 1.6.0

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 (4) hide show
  1. package/README.md +40 -3
  2. package/index.d.ts +11 -2
  3. package/index.js +9 -5
  4. package/package.json +15 -15
package/README.md CHANGED
@@ -18,11 +18,31 @@
18
18
 
19
19
  [Arcjet][arcjet] is the runtime security platform that ships with your AI code. Stop bots and automated attacks from burning your AI budget, leaking data, or misusing tools with Arcjet's AI security building blocks. Every feature works with any Bun application.
20
20
 
21
- This is the [Arcjet][arcjet] SDK for [Bun][bun-sh].
21
+ This is the [Arcjet][arcjet] SDK for [Bun][bun-sh] **request protection** —
22
+ use it to protect HTTP route handlers and API endpoints. If you need to protect
23
+ AI agent tool calls, MCP server handlers, or background jobs (anything without
24
+ an HTTP request), see [`@arcjet/guard`](https://github.com/arcjet/arcjet-js/tree/main/arcjet-guard).
22
25
 
23
26
  ## Getting started
24
27
 
25
- 1. Get your API key at [`app.arcjet.com`](https://app.arcjet.com)
28
+ ### Quick setup with an AI agent
29
+
30
+ 1. Log in with the CLI:
31
+ ```sh
32
+ npx @arcjet/cli auth login
33
+ ```
34
+ 2. Install the Arcjet skill to give your coding agent the docs it needs:
35
+ ```sh
36
+ npx skills add arcjet/skills
37
+ ```
38
+ 3. Tell your agent what to protect — it handles the rest.
39
+
40
+ ### Manual setup
41
+
42
+ 1. **Log in** with the CLI (or at [`app.arcjet.com`](https://app.arcjet.com?utm_campaign=arcjet-js)):
43
+ ```sh
44
+ npx @arcjet/cli auth login
45
+ ```
26
46
  2. `bun add @arcjet/bun`
27
47
  3. Set `ARCJET_KEY=ajkey_yourkey` in your environment
28
48
  4. Add Arcjet to your server — see the [quick start](#quick-start) below
@@ -34,6 +54,23 @@ This is the [Arcjet][arcjet] SDK for [Bun][bun-sh].
34
54
 
35
55
  ## Features
36
56
 
57
+ All features below are available with `@arcjet/bun` for request protection.
58
+ For guard protection (tool calls, MCP servers, queues) see
59
+ [`@arcjet/guard`](https://github.com/arcjet/arcjet-js/tree/main/arcjet-guard).
60
+
61
+ | Feature | `@arcjet/bun` | `@arcjet/guard` |
62
+ | ------------------------------- | :-----------: | :-------------: |
63
+ | Rate Limiting | ✅ | ✅ |
64
+ | Prompt Injection Detection | ✅ | ✅ |
65
+ | Sensitive Information Detection | ✅ | ✅ |
66
+ | Bot Protection | ✅ | — |
67
+ | Shield WAF | ✅ | — |
68
+ | Email Validation | ✅ | — |
69
+ | Signup Form Protection | ✅ | — |
70
+ | Request Filters | ✅ | — |
71
+ | IP Analysis | ✅ | — |
72
+ | Custom Rules | — | ✅ |
73
+
37
74
  - 🔒 [Prompt Injection Detection](#prompt-injection-detection) — detect and block
38
75
  prompt injection attacks before they reach your LLM.
39
76
  - 🤖 [Bot Protection](#bot-protection) — stop scrapers, credential stuffers, and
@@ -65,7 +102,7 @@ import { isSpoofedBot } from "@arcjet/inspect";
65
102
  import { env } from "bun";
66
103
 
67
104
  const aj = arcjet({
68
- key: env.ARCJET_KEY!, // Get your site key from https://app.arcjet.com
105
+ key: env.ARCJET_KEY!, // Get your key with: npx @arcjet/cli sites get-key
69
106
  rules: [
70
107
  // Shield protects your app from common attacks e.g. SQL injection
71
108
  shield({ mode: "LIVE" }),
package/index.d.ts CHANGED
@@ -1,4 +1,7 @@
1
1
  import type { ArcjetDecision, ArcjetOptions as CoreOptions, ArcjetRule, Primitive, Product, ExtraProps, CharacteristicProps } from "arcjet";
2
+ import { type ProxyService } from "@arcjet/ip";
3
+ export { cloudflare } from "@arcjet/ip";
4
+ export type { ProxyService } from "@arcjet/ip";
2
5
  import type { Server } from "bun";
3
6
  export * from "arcjet";
4
7
  type Simplify<T> = {
@@ -60,8 +63,12 @@ export type ArcjetOptions<Rules extends [...Array<Primitive | Product>], Charact
60
63
  /**
61
64
  * IP addresses and CIDR ranges of trusted load balancers and proxies
62
65
  * (optional, example: `["100.100.100.100", "100.100.100.0/24"]`).
66
+ *
67
+ * Proxy services such as {@linkcode cloudflare} can also be included to read
68
+ * the real client IP from a service-specific header when the request comes
69
+ * from that service.
63
70
  */
64
- proxies?: Array<string>;
71
+ proxies?: Array<string | ProxyService>;
65
72
  }>;
66
73
  /**
67
74
  * Instance of the Bun integration of Arcjet.
@@ -90,7 +97,9 @@ export interface ArcjetBun<Props extends PlainObject> {
90
97
  * Promise that resolves to an {@linkcode ArcjetDecision} indicating
91
98
  * Arcjet’s decision about the request.
92
99
  */
93
- protect(request: Request, ...properties: MaybeProperties<Props>): Promise<ArcjetDecision>;
100
+ protect(request: Request, ...properties: MaybeProperties<Props & {
101
+ correlationId?: string;
102
+ }>): Promise<ArcjetDecision>;
94
103
  /**
95
104
  * Augment the client with another rule.
96
105
  *
package/index.js CHANGED
@@ -1,7 +1,8 @@
1
1
  import * as core from 'arcjet';
2
2
  import core__default from 'arcjet';
3
3
  export * from 'arcjet';
4
- import { parseProxy, findIp } from '@arcjet/ip';
4
+ import { parseProxies, findIp } from '@arcjet/ip';
5
+ export { cloudflare } from '@arcjet/ip';
5
6
  import { ArcjetHeaders } from '@arcjet/headers';
6
7
  import { env } from 'bun';
7
8
  import { readBodyWeb } from '@arcjet/body';
@@ -26,7 +27,7 @@ function createRemoteClient(options) {
26
27
  // Transport is the HTTP client that the client uses to make requests.
27
28
  const transport = createTransport(url);
28
29
  const sdkStack = "BUN";
29
- const sdkVersion = "1.4.0";
30
+ const sdkVersion = "1.6.0";
30
31
  return createClient({
31
32
  transport,
32
33
  baseUrl: url,
@@ -59,7 +60,7 @@ function arcjet(options) {
59
60
  level: logLevel(env),
60
61
  });
61
62
  const proxies = Array.isArray(options.proxies)
62
- ? options.proxies.map(parseProxy)
63
+ ? parseProxies(options.proxies)
63
64
  : undefined;
64
65
  if (isDevelopment(env)) {
65
66
  log.warn("Arcjet will use 127.0.0.1 when missing public IP address in development mode");
@@ -109,8 +110,11 @@ function arcjet(options) {
109
110
  return withClient(client);
110
111
  },
111
112
  async protect(request, props) {
113
+ // `correlationId` is a request-independent option, not a rule prop, so
114
+ // pull it out before building the request from the rule properties.
115
+ const { correlationId, ...properties } = props ?? {};
112
116
  // Cast of `{}` because here we switch from `undefined` to `Properties`.
113
- const req = toArcjetRequest(request, props || {});
117
+ const req = toArcjetRequest(request, (properties || {}));
114
118
  const getBody = async () => {
115
119
  if (request.bodyUsed) {
116
120
  throw new Error("Cannot read body: already read");
@@ -131,7 +135,7 @@ function arcjet(options) {
131
135
  }
132
136
  return readBodyWeb(clonedRequest.body, { expectedLength });
133
137
  };
134
- return aj.protect({ getBody }, req);
138
+ return aj.protect({ getBody }, { ...req, correlationId });
135
139
  },
136
140
  handler(fetch) {
137
141
  return async function (request, server) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arcjet/bun",
3
- "version": "1.4.0",
3
+ "version": "1.6.0",
4
4
  "description": "Arcjet runtime security SDK for Bun — bot protection, rate limiting, prompt injection detection, PII blocking, and WAF",
5
5
  "keywords": [
6
6
  "ai",
@@ -51,23 +51,23 @@
51
51
  "test": "npm run build && npm run lint"
52
52
  },
53
53
  "dependencies": {
54
- "@arcjet/body": "1.4.0",
55
- "@arcjet/env": "1.4.0",
56
- "@arcjet/headers": "1.4.0",
57
- "@arcjet/ip": "1.4.0",
58
- "@arcjet/logger": "1.4.0",
59
- "@arcjet/protocol": "1.4.0",
60
- "@arcjet/transport": "1.4.0",
61
- "arcjet": "1.4.0"
54
+ "@arcjet/body": "1.6.0",
55
+ "@arcjet/env": "1.6.0",
56
+ "@arcjet/headers": "1.6.0",
57
+ "@arcjet/ip": "1.6.0",
58
+ "@arcjet/logger": "1.6.0",
59
+ "@arcjet/protocol": "1.6.0",
60
+ "@arcjet/transport": "1.6.0",
61
+ "arcjet": "1.6.0"
62
62
  },
63
63
  "devDependencies": {
64
- "@arcjet/eslint-config": "1.4.0",
65
- "@arcjet/rollup-config": "1.4.0",
66
- "@rollup/wasm-node": "4.59.0",
67
- "bun-types": "1.3.10",
68
- "eslint": "9.39.3",
64
+ "@arcjet/eslint-config": "1.6.0",
65
+ "@arcjet/rollup-config": "1.6.0",
66
+ "@rollup/wasm-node": "4.62.2",
67
+ "bun-types": "1.3.14",
68
+ "eslint": "9.39.4",
69
69
  "typescript": "5.9.3",
70
- "undici-types": "7.22.0"
70
+ "undici-types": "7.28.0"
71
71
  },
72
72
  "publishConfig": {
73
73
  "access": "public",