@arcjet/bun 1.9.1 → 1.10.0-rc.1

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 CHANGED
@@ -16,13 +16,17 @@
16
16
  </a>
17
17
  </p>
18
18
 
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.
19
+ [Arcjet][arcjet] is the runtime security platform that ships in your AI code. Detect prompt injection, authorize agent tool calls, redact sensitive data, and block bots and abuse. Real-time security building blocks you call inside your app, before an action happens.
20
20
 
21
21
  This is the [Arcjet][arcjet] SDK for [Bun][bun-sh] **request protection** —
22
22
  use it to protect HTTP route handlers and API endpoints. If you need to protect
23
23
  AI agent tool calls, MCP server handlers, or background jobs (anything without
24
24
  an HTTP request), see [`@arcjet/guard`](https://github.com/arcjet/arcjet-js/tree/main/arcjet-guard).
25
25
 
26
+ ## Why Arcjet?
27
+
28
+ Your app's AI features and agents take real actions, calling tools, reading data, hitting APIs. Arcjet runs inside that code and lets you enforce security on each action in real time, then audit what happened
29
+
26
30
  ## Getting started
27
31
 
28
32
  ### Quick setup with an AI agent
package/dist/index.d.ts CHANGED
@@ -1,134 +1,132 @@
1
1
  import { ProxyService, ProxyService as ProxyService$1, cloudflare } from "@arcjet/ip";
2
- import { ArcjetDecision, ArcjetOptions as ArcjetOptions$1, ArcjetRule, CharacteristicProps, ExtraProps, Primitive, Product } from "arcjet";
2
+ import { ArcjetDecision, ArcjetMetadata, ArcjetOptions as ArcjetOptions$1, ArcjetRule, CharacteristicProps, ExtraProps, Primitive, Product } from "arcjet";
3
3
  import { createClient } from "@arcjet/protocol/client.js";
4
4
  import { Server } from "bun";
5
5
  export * from "arcjet";
6
-
7
6
  //#region src/index.d.ts
8
- type Simplify<T> = { [KeyType in keyof T]: T[KeyType] } & {};
9
- declare const emptyObjectSymbol: unique symbol;
7
+ type Simplify<T> = { [KeyType in keyof T]: T[KeyType]; } & {};
10
8
  type PlainObject = {
11
9
  [key: string]: unknown;
12
10
  };
13
11
  /**
14
- * Dynamically generate whether zero or one `properties` object must or can be passed.
15
- */
16
- type MaybeProperties<T> = { [P in keyof T]?: T[P] } extends T ? T extends {
17
- [emptyObjectSymbol]?: never;
18
- } ? [] : [properties?: T] : [properties: T];
12
+ * Dynamically generate whether zero or one `properties` object must or can be passed.
13
+ */
14
+ type MaybeProperties<T> = { [P in keyof T]?: T[P]; } extends T ? [properties?: T] : [properties: T];
19
15
  /**
20
- * Configuration for {@linkcode createRemoteClient}.
21
- */
16
+ * Configuration for {@linkcode createRemoteClient}.
17
+ */
22
18
  type RemoteClientOptions = {
23
19
  /**
24
- * Base URI for HTTP requests to Decide API (optional).
25
- *
26
- * Defaults to the environment variable `ARCJET_BASE_URL` (if that value
27
- * is known and allowed) and the standard production API otherwise.
28
- */
20
+ * Base URI for HTTP requests to Decide API (optional).
21
+ *
22
+ * Defaults to the environment variable `ARCJET_BASE_URL` (if that value
23
+ * is known and allowed) and the standard production API otherwise.
24
+ */
29
25
  baseUrl?: string;
30
26
  /**
31
- * Timeout in milliseconds for the Decide API (optional).
32
- *
33
- * Defaults to `500` in production and `1000` in development.
34
- */
27
+ * Timeout in milliseconds for the Decide API (optional).
28
+ *
29
+ * Defaults to `500` in production and `1000` in development.
30
+ */
35
31
  timeout?: number;
36
32
  };
37
33
  /**
38
- * Create a remote client.
39
- *
40
- * @param options
41
- * Configuration (optional).
42
- * @returns
43
- * Client.
44
- */
34
+ * Create a remote client.
35
+ *
36
+ * @param options
37
+ * Configuration (optional).
38
+ * @returns
39
+ * Client.
40
+ */
45
41
  declare function createRemoteClient(options?: RemoteClientOptions): ReturnType<typeof createClient>;
46
42
  /**
47
- * Configuration for the Bun integration of Arcjet.
48
- *
49
- * @template Rules
50
- * List of rules.
51
- * @template Characteristics
52
- * Characteristics to track a user by.
53
- */
43
+ * Configuration for the Bun integration of Arcjet.
44
+ *
45
+ * @template Rules
46
+ * List of rules.
47
+ * @template Characteristics
48
+ * Characteristics to track a user by.
49
+ */
54
50
  type ArcjetOptions<Rules extends [...Array<Primitive | Product>], Characteristics extends readonly string[]> = Simplify<ArcjetOptions$1<Rules, Characteristics> & {
55
51
  /**
56
- * IP addresses and CIDR ranges of trusted load balancers and proxies
57
- * (optional, example: `["100.100.100.100", "100.100.100.0/24"]`).
58
- *
59
- * Proxy services such as {@linkcode cloudflare} can also be included to read
60
- * the real client IP from a service-specific header when the request comes
61
- * from that service.
62
- */
52
+ * IP addresses and CIDR ranges of trusted load balancers and proxies
53
+ * (optional, example: `["100.100.100.100", "100.100.100.0/24"]`).
54
+ *
55
+ * Proxy services such as {@linkcode cloudflare} can also be included to read
56
+ * the real client IP from a service-specific header when the request comes
57
+ * from that service.
58
+ */
63
59
  proxies?: Array<string | ProxyService$1>;
64
60
  }>;
65
61
  /**
66
- * Instance of the Bun integration of Arcjet.
67
- *
68
- * Primarily has a `protect()` method to make a decision about how a Bun request
69
- * should be handled.
70
- *
71
- * @template Props
72
- * Configuration.
73
- */
62
+ * Instance of the Bun integration of Arcjet.
63
+ *
64
+ * Primarily has a `protect()` method to make a decision about how a Bun request
65
+ * should be handled.
66
+ *
67
+ * @template Props
68
+ * Configuration.
69
+ */
74
70
  interface ArcjetBun<Props extends PlainObject> {
75
71
  /**
76
- * Make a decision about how to handle a request.
77
- *
78
- * This will analyze the request locally where possible and otherwise call
79
- * the Arcjet decision API.
80
- *
81
- * @param ctx
82
- * Additional context for this function call.
83
- * @param request
84
- * Details about the {@linkcode Request} that Arcjet needs to make a
85
- * decision.
86
- * @param props
87
- * Additional properties required for running rules against a request.
88
- * @returns
89
- * Promise that resolves to an {@linkcode ArcjetDecision} indicating
90
- * Arcjet’s decision about the request.
91
- */
72
+ * Make a decision about how to handle a request.
73
+ *
74
+ * This will analyze the request locally where possible and otherwise call
75
+ * the Arcjet decision API.
76
+ *
77
+ * @param ctx
78
+ * Additional context for this function call.
79
+ * @param request
80
+ * Details about the {@linkcode Request} that Arcjet needs to make a
81
+ * decision.
82
+ * @param props
83
+ * Additional properties required for running rules against a request,
84
+ * plus request-independent options such as `metadata`.
85
+ * @returns
86
+ * Promise that resolves to an {@linkcode ArcjetDecision} indicating
87
+ * Arcjet’s decision about the request.
88
+ */
92
89
  protect(request: Request, ...properties: MaybeProperties<Props & {
93
90
  correlationId?: string;
91
+ metadata?: ArcjetMetadata;
94
92
  }>): Promise<ArcjetDecision>;
95
93
  /**
96
- * Augment the client with another rule.
97
- *
98
- * Useful for varying rules based on criteria in your handler such as
99
- * different rate limit for logged in users.
100
- *
101
- * @template Rule
102
- * Type of rule.
103
- * @param rule
104
- * Rule to add to Arcjet.
105
- * @returns
106
- * Arcjet instance augmented with the given rule.
107
- */
94
+ * Augment the client with another rule.
95
+ *
96
+ * Useful for varying rules based on criteria in your handler such as
97
+ * different rate limit for logged in users.
98
+ *
99
+ * @template Rule
100
+ * Type of rule.
101
+ * @param rule
102
+ * Rule to add to Arcjet.
103
+ * @returns
104
+ * Arcjet instance augmented with the given rule.
105
+ */
108
106
  withRule<Rule extends ArcjetRule>(rule: Array<Rule>): ArcjetBun<Props & (Rule extends ArcjetRule<infer P> ? P : {})>;
109
107
  /**
110
- * Wrap the Bun `fetch` handler to provide additional details when calling
111
- * the `protect()` method.
112
- *
113
- * @param fetch
114
- * Original `fetch` from Bun.
115
- * @returns
116
- * Wrapped `fetch` handler.
117
- */
108
+ * Wrap the Bun `fetch` handler to provide additional details when calling
109
+ * the `protect()` method.
110
+ *
111
+ * @param fetch
112
+ * Original `fetch` from Bun.
113
+ * @returns
114
+ * Wrapped `fetch` handler.
115
+ */
118
116
  handler(fetch: (this: Server<any>, request: Request, server: Server<any>) => Response | Promise<Response>): (this: Server<any>, request: Request, server: Server<any>) => Response | Promise<Response>;
119
117
  }
120
118
  /**
121
- * Create a new Bun integration of Arcjet.
122
- *
123
- * @template Rules
124
- * List of rules.
125
- * @template Characteristics
126
- * Characteristics to track a user by.
127
- * @param options
128
- * Configuration.
129
- * @returns
130
- * Bun integration of Arcjet.
131
- */
119
+ * Create a new Bun integration of Arcjet.
120
+ *
121
+ * @template Rules
122
+ * List of rules.
123
+ * @template Characteristics
124
+ * Characteristics to track a user by.
125
+ * @param options
126
+ * Configuration.
127
+ * @returns
128
+ * Bun integration of Arcjet.
129
+ */
132
130
  declare function arcjet<const Rules extends (Primitive | Product)[], const Characteristics extends readonly string[]>(options: ArcjetOptions<Rules, Characteristics>): ArcjetBun<ExtraProps<Rules> & CharacteristicProps<Characteristics>>;
133
131
  //#endregion
134
132
  export { ArcjetBun, ArcjetOptions, type ProxyService, RemoteClientOptions, cloudflare, createRemoteClient, arcjet as default };
package/dist/index.js CHANGED
@@ -10,7 +10,7 @@ import { env } from "bun";
10
10
  export * from "arcjet";
11
11
  //#region src/index.ts
12
12
  /** SDK version. Updated by the release process. */
13
- const VERSION = "1.9.1";
13
+ const VERSION = "1.10.0-rc.1";
14
14
  let warnedForAutomaticBodyRead = false;
15
15
  /**
16
16
  * Create a remote client.
@@ -80,7 +80,7 @@ function arcjet(options) {
80
80
  return withClient(aj.withRule(rule));
81
81
  },
82
82
  async protect(request, props) {
83
- const { correlationId, ...properties } = props ?? {};
83
+ const { correlationId, metadata, ...properties } = props ?? {};
84
84
  const req = toArcjetRequest(request, properties || {});
85
85
  const getBody = async () => {
86
86
  if (request.bodyUsed) throw new Error("Cannot read body: already read");
@@ -97,7 +97,8 @@ function arcjet(options) {
97
97
  };
98
98
  return aj.protect({ getBody }, {
99
99
  ...req,
100
- correlationId
100
+ correlationId,
101
+ metadata
101
102
  });
102
103
  },
103
104
  handler(fetch) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arcjet/bun",
3
- "version": "1.9.1",
3
+ "version": "1.10.0-rc.1",
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",
@@ -55,23 +55,23 @@
55
55
  },
56
56
  "scripts": {
57
57
  "build": "tsdown",
58
- "typecheck": "tsgo --noEmit",
58
+ "typecheck": "tsc --noEmit",
59
59
  "test": "npm run build"
60
60
  },
61
61
  "dependencies": {
62
- "@arcjet/body": "1.9.1",
63
- "@arcjet/env": "1.9.1",
64
- "@arcjet/headers": "1.9.1",
65
- "@arcjet/ip": "1.9.1",
66
- "@arcjet/logger": "1.9.1",
67
- "@arcjet/protocol": "1.9.1",
68
- "@arcjet/transport": "1.9.1",
69
- "arcjet": "1.9.1"
62
+ "@arcjet/body": "1.10.0-rc.1",
63
+ "@arcjet/env": "1.10.0-rc.1",
64
+ "@arcjet/headers": "1.10.0-rc.1",
65
+ "@arcjet/ip": "1.10.0-rc.1",
66
+ "@arcjet/logger": "1.10.0-rc.1",
67
+ "@arcjet/protocol": "1.10.0-rc.1",
68
+ "@arcjet/transport": "1.10.0-rc.1",
69
+ "arcjet": "1.10.0-rc.1"
70
70
  },
71
71
  "devDependencies": {
72
72
  "bun-types": "1.3.14",
73
- "tsdown": "0.22.3",
74
- "typescript": "6.0.3",
73
+ "tsdown": "0.22.7",
74
+ "typescript": "7.0.2",
75
75
  "undici-types": "7.28.0"
76
76
  },
77
77
  "engines": {}