@arcjet/bun 1.0.0-beta.10 → 1.0.0-beta.11

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/index.d.ts +76 -23
  2. package/index.js +21 -13
  3. package/package.json +15 -16
package/index.d.ts CHANGED
@@ -11,58 +11,111 @@ type WithoutCustomProps = {
11
11
  type PlainObject = {
12
12
  [key: string]: unknown;
13
13
  };
14
+ /**
15
+ * Configuration for {@linkcode createRemoteClient}.
16
+ */
14
17
  export type RemoteClientOptions = {
18
+ /**
19
+ * Base URI for HTTP requests to Decide API (optional).
20
+ *
21
+ * Defaults to the environment variable `ARCJET_BASE_URL` (if that value
22
+ * is known and allowed) and the standard production API otherwise.
23
+ */
15
24
  baseUrl?: string;
25
+ /**
26
+ * Timeout in milliseconds for the Decide API (optional).
27
+ *
28
+ * Defaults to `500` in production and `1000` in development.
29
+ */
16
30
  timeout?: number;
17
31
  };
32
+ /**
33
+ * Create a remote client.
34
+ *
35
+ * @param options
36
+ * Configuration (optional).
37
+ * @returns
38
+ * Client.
39
+ */
18
40
  export declare function createRemoteClient(options?: RemoteClientOptions): import("@arcjet/protocol/client.js").Client;
19
41
  /**
20
- * The options used to configure an {@link ArcjetBun} client.
42
+ * Configuration for the Bun integration of Arcjet.
43
+ *
44
+ * @template Rules
45
+ * List of rules.
46
+ * @template Characteristics
47
+ * Characteristics to track a user by.
21
48
  */
22
49
  export type ArcjetOptions<Rules extends [...Array<Primitive | Product>], Characteristics extends readonly string[]> = Simplify<CoreOptions<Rules, Characteristics> & {
23
50
  /**
24
- * One or more IP Address of trusted proxies in front of the application.
25
- * These addresses will be excluded when Arcjet detects a public IP address.
51
+ * IP addresses and CIDR ranges of trusted load balancers and proxies
52
+ * (optional, example: `["100.100.100.100", "100.100.100.0/24"]`).
26
53
  */
27
54
  proxies?: Array<string>;
28
55
  }>;
29
56
  /**
30
- * The ArcjetBun client provides a public `protect()` method to
31
- * make a decision about how a Bun.sh request should be handled.
57
+ * Instance of the Bun integration of Arcjet.
58
+ *
59
+ * Primarily has a `protect()` method to make a decision about how a Bun request
60
+ * should be handled.
61
+ *
62
+ * @template Props
63
+ * Configuration.
32
64
  */
33
65
  export interface ArcjetBun<Props extends PlainObject> {
34
66
  /**
35
- * Runs a request through the configured protections. The request is
36
- * analyzed and then a decision made on whether to allow, deny, or challenge
37
- * the request.
67
+ * Make a decision about how to handle a request.
38
68
  *
39
- * @param request - A `Request` provided to the fetch handler.
40
- * @param props - Additonal properties required for running rules against a request.
41
- * @returns An {@link ArcjetDecision} indicating Arcjet's decision about the request.
69
+ * This will analyze the request locally where possible and otherwise call
70
+ * the Arcjet decision API.
71
+ *
72
+ * @param ctx
73
+ * Additional context for this function call.
74
+ * @param request
75
+ * Details about the {@linkcode Request} that Arcjet needs to make a
76
+ * decision.
77
+ * @param props
78
+ * Additional properties required for running rules against a request.
79
+ * @returns
80
+ * Promise that resolves to an {@linkcode ArcjetDecision} indicating
81
+ * Arcjet’s decision about the request.
42
82
  */
43
83
  protect(request: Request, ...props: Props extends WithoutCustomProps ? [] : [Props]): Promise<ArcjetDecision>;
44
84
  /**
45
- * Augments the client with another rule. Useful for varying rules based on
46
- * criteria in your handler—e.g. different rate limit for logged in users.
85
+ * Augment the client with another rule.
86
+ *
87
+ * Useful for varying rules based on criteria in your handler such as
88
+ * different rate limit for logged in users.
47
89
  *
48
- * @param rule The rule to add to this execution.
49
- * @returns An augmented {@link ArcjetBun} client.
90
+ * @template Rule
91
+ * Type of rule.
92
+ * @param rule
93
+ * Rule to add to Arcjet.
94
+ * @returns
95
+ * Arcjet instance augmented with the given rule.
50
96
  */
51
97
  withRule<Rule extends Primitive | Product>(rule: Rule): ArcjetBun<Simplify<Props & ExtraProps<Rule>>>;
52
98
  /**
53
- * Wraps the Bun.sh `fetch` handler to provide additional Request details
54
- * when calling the SDK's `protect()` function.
99
+ * Wrap the Bun `fetch` handler to provide additional details when calling
100
+ * the `protect()` method.
55
101
  *
56
- * @param fetch: The user provided `fetch` handler
102
+ * @param fetch
103
+ * Original `fetch` from Bun.
104
+ * @returns
105
+ * Wrapped `fetch` handler.
57
106
  */
58
107
  handler(fetch: (this: Server, request: Request, server: Server) => Response | Promise<Response>): (this: Server, request: Request, server: Server) => Response | Promise<Response>;
59
108
  }
60
109
  /**
61
- * Create a new {@link ArcjetBun} client. Always build your initial client
62
- * outside of a request handler so it persists across requests. If you need to
63
- * augment a client inside a handler, call the `withRule()` function on the base
64
- * client.
110
+ * Create a new Bun integration of Arcjet.
65
111
  *
66
- * @param options - Arcjet configuration options to apply to all requests.
112
+ * @template Rules
113
+ * List of rules.
114
+ * @template Characteristics
115
+ * Characteristics to track a user by.
116
+ * @param options
117
+ * Configuration.
118
+ * @returns
119
+ * Bun integration of Arcjet.
67
120
  */
68
121
  export default function arcjet<const Rules extends (Primitive | Product)[], const Characteristics extends readonly string[]>(options: ArcjetOptions<Rules, Characteristics>): ArcjetBun<Simplify<ExtraProps<Rules> & CharacteristicProps<Characteristics>>>;
package/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import core__default from 'arcjet';
2
2
  export * from 'arcjet';
3
- import findIP, { parseProxy } from '@arcjet/ip';
4
- import ArcjetHeaders from '@arcjet/headers';
3
+ import findIp, { parseProxy } from '@arcjet/ip';
4
+ import { ArcjetHeaders } from '@arcjet/headers';
5
5
  import { env } from 'bun';
6
6
  import { logLevel, isDevelopment, baseUrl, platform } from '@arcjet/env';
7
7
  import { Logger } from '@arcjet/logger';
@@ -23,17 +23,21 @@ function errorMessage(err) {
23
23
  }
24
24
  return "Unknown problem";
25
25
  }
26
+ /**
27
+ * Create a remote client.
28
+ *
29
+ * @param options
30
+ * Configuration (optional).
31
+ * @returns
32
+ * Client.
33
+ */
26
34
  function createRemoteClient(options) {
27
- // The base URL for the Arcjet API. Will default to the standard production
28
- // API unless environment variable `ARCJET_BASE_URL` is set.
29
35
  const url = options?.baseUrl ?? baseUrl(env);
30
- // The timeout for the Arcjet API in milliseconds. This is set to a low value
31
- // in production so calls fail open.
32
36
  const timeout = options?.timeout ?? (isDevelopment(env) ? 1000 : 500);
33
37
  // Transport is the HTTP client that the client uses to make requests.
34
38
  const transport = createTransport(url);
35
39
  const sdkStack = "BUN";
36
- const sdkVersion = "1.0.0-beta.10";
40
+ const sdkVersion = "1.0.0-beta.11";
37
41
  return createClient({
38
42
  transport,
39
43
  baseUrl: url,
@@ -43,12 +47,16 @@ function createRemoteClient(options) {
43
47
  });
44
48
  }
45
49
  /**
46
- * Create a new {@link ArcjetBun} client. Always build your initial client
47
- * outside of a request handler so it persists across requests. If you need to
48
- * augment a client inside a handler, call the `withRule()` function on the base
49
- * client.
50
+ * Create a new Bun integration of Arcjet.
50
51
  *
51
- * @param options - Arcjet configuration options to apply to all requests.
52
+ * @template Rules
53
+ * List of rules.
54
+ * @template Characteristics
55
+ * Characteristics to track a user by.
56
+ * @param options
57
+ * Configuration.
58
+ * @returns
59
+ * Bun integration of Arcjet.
52
60
  */
53
61
  function arcjet(options) {
54
62
  const client = options.client ?? createRemoteClient();
@@ -72,7 +80,7 @@ function arcjet(options) {
72
80
  // We construct an ArcjetHeaders to normalize over Headers
73
81
  const headers = new ArcjetHeaders(request.headers);
74
82
  const url = new URL(request.url);
75
- let ip = findIP({
83
+ let ip = findIp({
76
84
  // This attempts to lookup the IP in the `ipCache`. This is primarily a
77
85
  // workaround to the API design in Bun that requires access to the
78
86
  // `Server` to lookup an IP.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arcjet/bun",
3
- "version": "1.0.0-beta.10",
3
+ "version": "1.0.0-beta.11",
4
4
  "description": "Arcjet SDK for Bun",
5
5
  "keywords": [
6
6
  "analyze",
@@ -45,23 +45,22 @@
45
45
  "test": "npm run build && npm run lint"
46
46
  },
47
47
  "dependencies": {
48
- "@arcjet/env": "1.0.0-beta.10",
49
- "@arcjet/headers": "1.0.0-beta.10",
50
- "@arcjet/ip": "1.0.0-beta.10",
51
- "@arcjet/logger": "1.0.0-beta.10",
52
- "@arcjet/protocol": "1.0.0-beta.10",
53
- "@arcjet/transport": "1.0.0-beta.10",
54
- "arcjet": "1.0.0-beta.10"
48
+ "@arcjet/env": "1.0.0-beta.11",
49
+ "@arcjet/headers": "1.0.0-beta.11",
50
+ "@arcjet/ip": "1.0.0-beta.11",
51
+ "@arcjet/logger": "1.0.0-beta.11",
52
+ "@arcjet/protocol": "1.0.0-beta.11",
53
+ "@arcjet/transport": "1.0.0-beta.11",
54
+ "arcjet": "1.0.0-beta.11"
55
55
  },
56
56
  "devDependencies": {
57
- "@arcjet/eslint-config": "1.0.0-beta.10",
58
- "@arcjet/rollup-config": "1.0.0-beta.10",
59
- "@arcjet/tsconfig": "1.0.0-beta.10",
60
- "@types/node": "20.12.12",
61
- "@rollup/wasm-node": "4.46.2",
62
- "bun-types": "1.2.19",
63
- "eslint": "9.32.0",
64
- "typescript": "5.9.2"
57
+ "@arcjet/eslint-config": "1.0.0-beta.11",
58
+ "@arcjet/rollup-config": "1.0.0-beta.11",
59
+ "@rollup/wasm-node": "4.50.0",
60
+ "bun-types": "1.2.21",
61
+ "eslint": "9.34.0",
62
+ "typescript": "5.9.2",
63
+ "undici-types": "7.15.0"
65
64
  },
66
65
  "publishConfig": {
67
66
  "access": "public",