@arcjet/astro 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.
package/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { BotOptions, EmailOptions, FixedWindowRateLimitOptions, ProtectSignupOptions, SensitiveInfoOptions, ShieldOptions, SlidingWindowRateLimitOptions, TokenBucketRateLimitOptions } from "arcjet";
1
+ import type { BotOptions, EmailOptions, FilterOptions, FixedWindowRateLimitOptions, ProtectSignupOptions, SensitiveInfoOptions, ShieldOptions, SlidingWindowRateLimitOptions, TokenBucketRateLimitOptions } from "arcjet";
2
2
  import type { AstroIntegration } from "astro";
3
3
  type IntegrationRule<Characteristics extends readonly string[]> = {
4
4
  type: "shield";
@@ -9,6 +9,9 @@ type IntegrationRule<Characteristics extends readonly string[]> = {
9
9
  } | {
10
10
  type: "email";
11
11
  options?: EmailOptions;
12
+ } | {
13
+ type: "filter";
14
+ options: FilterOptions;
12
15
  } | {
13
16
  type: "sensitiveInfo";
14
17
  options?: SensitiveInfoOptions<never>;
@@ -25,51 +28,281 @@ type IntegrationRule<Characteristics extends readonly string[]> = {
25
28
  type: "protectSignup";
26
29
  options?: ProtectSignupOptions<Characteristics>;
27
30
  };
31
+ /**
32
+ * Configuration for the Astro integration of Arcjet.
33
+ *
34
+ * @template Characteristics
35
+ * Characteristics to track a user by.
36
+ */
28
37
  type ArcjetIntegrationOptions<Characteristics extends readonly string[]> = {
38
+ /**
39
+ * Integration rules to apply when protecting a request (required).
40
+ *
41
+ * These rules are *different* from those exposed from `arcjet` core.
42
+ * You have to import them from this integration (`@arcjet/astro`) instead.
43
+ */
29
44
  rules: IntegrationRule<Characteristics>[];
45
+ /**
46
+ * Characteristics to track a user by (default: `["src.ip"]`).
47
+ *
48
+ * Can also be passed to rules.
49
+ */
30
50
  characteristics?: Characteristics;
51
+ /**
52
+ * Configuration for the default client (optional).
53
+ */
31
54
  client?: RemoteClientOptions;
55
+ /**
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
+ */
32
59
  proxies?: string[];
33
60
  };
61
+ /**
62
+ * Arcjet Shield WAF rule.
63
+ *
64
+ * Applying this rule protects your application against common attacks,
65
+ * including the OWASP Top 10.
66
+ *
67
+ * The Arcjet Shield WAF analyzes every request to your application to detect
68
+ * suspicious activity.
69
+ * Once a certain suspicion threshold is reached,
70
+ * subsequent requests from that client are blocked for a period of time.
71
+ *
72
+ * @param options
73
+ * Configuration for the Shield rule.
74
+ * @returns
75
+ * Astro integration Shield rule to provide to the SDK in the `rules` field.
76
+ */
34
77
  export declare function shield(options?: ShieldOptions): {
35
78
  readonly type: "shield";
36
79
  readonly options: ShieldOptions | undefined;
37
80
  };
81
+ /**
82
+ * Arcjet bot detection rule.
83
+ *
84
+ * Applying this rule allows you to manage traffic by automated clients and
85
+ * bots.
86
+ *
87
+ * Bots can be good (such as search engine crawlers or monitoring agents) or bad
88
+ * (such as scrapers or automated scripts).
89
+ * Arcjet allows you to configure which bots you want to allow or deny by
90
+ * specific bot names such as curl, as well as by category such as search
91
+ * engine bots.
92
+ *
93
+ * Bots are detected based on various signals such as the user agent, IP
94
+ * address, DNS records, and more.
95
+ *
96
+ * @param options
97
+ * Configuration for the bot rule (required).
98
+ * @returns
99
+ * Astro integration Bot rule to provide to the SDK in the `rules` field.
100
+ */
38
101
  export declare function detectBot(options?: BotOptions): {
39
102
  readonly type: "bot";
40
103
  readonly options: BotOptions | undefined;
41
104
  };
105
+ /**
106
+ * Arcjet email validation rule.
107
+ *
108
+ * Applying this rule allows you to validate and verify an email address.
109
+ *
110
+ * The first step of the analysis is to validate the email address syntax.
111
+ * This runs locally within the SDK and validates the email address is in the
112
+ * correct format.
113
+ * If the email syntax is valid, the SDK will pass the email address to the
114
+ * Arcjet cloud API to verify the email address.
115
+ * This performs several checks, depending on the rule configuration.
116
+ *
117
+ * @param options
118
+ * Configuration for the email validation rule (required).
119
+ * @returns
120
+ * Astro integration Email rule to provide to the SDK in the `rules` field.
121
+ */
42
122
  export declare function validateEmail(options?: EmailOptions): {
43
123
  readonly type: "email";
44
124
  readonly options: EmailOptions | undefined;
45
125
  };
126
+ /**
127
+ * Arcjet filter rule.
128
+ *
129
+ * Applying this rule lets you write expressions to match against requests.
130
+ *
131
+ * @param options
132
+ * Configuration for the filter rule (required).
133
+ * @returns
134
+ * Astro integration Filter rule to provide to the SDK in the `rules` field.
135
+ */
136
+ export declare function filter(options: FilterOptions): {
137
+ readonly type: "filter";
138
+ readonly options: FilterOptions;
139
+ };
140
+ /**
141
+ * Arcjet sensitive information detection rule.
142
+ *
143
+ * Applying this rule protects against clients sending you sensitive information
144
+ * such as personally identifiable information (PII) that you do not wish to
145
+ * handle.
146
+ * The rule runs entirely locally so no data ever leaves your environment.
147
+ *
148
+ * This rule includes built-in detections for email addresses, credit/debit card
149
+ * numbers, IP addresses, and phone numbers.
150
+ * You can also provide a custom detection function to identify additional
151
+ * sensitive information.
152
+ *
153
+ * @param options
154
+ * Configuration for the sensitive information detection rule (required).
155
+ * @returns
156
+ * Astro integration Sensitive information rule to provide to the SDK in the `rules` field.
157
+ */
46
158
  export declare function sensitiveInfo(options?: SensitiveInfoOptions<never>): {
47
159
  readonly type: "sensitiveInfo";
48
160
  readonly options: SensitiveInfoOptions<never> | undefined;
49
161
  };
162
+ /**
163
+ * Arcjet fixed window rate limiting rule.
164
+ *
165
+ * Applying this rule sets a fixed window rate limit which tracks the number of
166
+ * requests made by a client over a fixed time window.
167
+ *
168
+ * This is the simplest algorithm.
169
+ * It tracks the number of requests made by a client over a fixed time window
170
+ * such as 60 seconds.
171
+ * If the client exceeds the limit, they are blocked until the window expires.
172
+ *
173
+ * This algorithm is useful when you want to apply a simple fixed limit in a
174
+ * fixed time window.
175
+ * For example, a simple limit on the total number of requests a client can make.
176
+ * However, it can be susceptible to the stampede problem where a client makes
177
+ * a burst of requests at the start of a window and then is blocked for the rest
178
+ * of the window.
179
+ * The sliding window algorithm can be used to avoid this.
180
+ *
181
+ * @template Characteristics
182
+ * Characteristics to track a user by.
183
+ * @param options
184
+ * Configuration for the fixed window rate limiting rule (required).
185
+ * @returns
186
+ * Astro integration Fixed window rule to provide to the SDK in the `rules` field.
187
+ */
50
188
  export declare function fixedWindow<Characteristics extends readonly string[]>(options?: FixedWindowRateLimitOptions<Characteristics>): {
51
189
  readonly type: "fixedWindow";
52
190
  readonly options: FixedWindowRateLimitOptions<Characteristics> | undefined;
53
191
  };
192
+ /**
193
+ * Arcjet sliding window rate limiting rule.
194
+ *
195
+ * Applying this rule sets a sliding window rate limit which tracks the number
196
+ * of requests made by a client over a sliding window so that the window moves
197
+ * with time.
198
+ *
199
+ * This algorithm is useful to avoid the stampede problem of the fixed window.
200
+ * It provides smoother rate limiting over time and can prevent a client from
201
+ * making a burst of requests at the start of a window and then being blocked
202
+ * for the rest of the window.
203
+ *
204
+ * @template Characteristics
205
+ * Characteristics to track a user by.
206
+ * @param options
207
+ * Configuration for the sliding window rate limiting rule (required).
208
+ * @returns
209
+ * Astro integration Sliding window rule to provide to the SDK in the `rules` field.
210
+ */
54
211
  export declare function slidingWindow<Characteristics extends readonly string[]>(options?: SlidingWindowRateLimitOptions<Characteristics>): {
55
212
  readonly type: "slidingWindow";
56
213
  readonly options: SlidingWindowRateLimitOptions<Characteristics> | undefined;
57
214
  };
215
+ /**
216
+ * Arcjet token bucket rate limiting rule.
217
+ *
218
+ * Applying this rule sets a token bucket rate limit.
219
+ *
220
+ * This algorithm is based on a bucket filled with a specific number of tokens.
221
+ * Each request withdraws some amount of tokens from the bucket and the bucket
222
+ * is refilled at a fixed rate.
223
+ * Once the bucket is empty, the client is blocked until the bucket refills.
224
+ *
225
+ * This algorithm is useful when you want to allow clients to make a burst of
226
+ * requests and then still be able to make requests at a slower rate.
227
+ *
228
+ * @template Characteristics
229
+ * Characteristics to track a user by.
230
+ * @param options
231
+ * Configuration for the token bucket rate limiting rule (required).
232
+ * @returns
233
+ * Astro integration Token bucket rule to provide to the SDK in the `rules` field.
234
+ */
58
235
  export declare function tokenBucket<Characteristics extends readonly string[]>(options?: TokenBucketRateLimitOptions<Characteristics>): {
59
236
  readonly type: "tokenBucket";
60
237
  readonly options: TokenBucketRateLimitOptions<Characteristics> | undefined;
61
238
  };
239
+ /**
240
+ * Arcjet signup form protection rule.
241
+ *
242
+ * Applying this rule combines rate limiting, bot protection, and email
243
+ * validation to protect your signup forms from abuse.
244
+ * Using this rule will configure the following:
245
+ *
246
+ * - Rate limiting - signup forms are a common target for bots. Arcjet’s rate
247
+ * limiting helps to prevent bots and other automated or malicious clients
248
+ * from submitting your signup form too many times in a short period of time.
249
+ * - Bot protection - signup forms are usually exclusively used by humans, which
250
+ * means that any automated submissions to the form are likely to be
251
+ * fraudulent.
252
+ * - Email validation - email addresses should be validated to ensure the signup
253
+ * is coming from a legitimate user with a real email address that can
254
+ * actually receive messages.
255
+ *
256
+ * @template Characteristics
257
+ * Characteristics to track a user by.
258
+ * @param options
259
+ * Configuration for the signup form protection rule.
260
+ * @returns
261
+ * Astro integration Signup form protection rule to provide to the SDK in the `rules` field.
262
+ */
62
263
  export declare function protectSignup<Characteristics extends readonly string[]>(options?: ProtectSignupOptions<Characteristics>): {
63
264
  readonly type: "protectSignup";
64
265
  readonly options: ProtectSignupOptions<Characteristics> | undefined;
65
266
  };
267
+ /**
268
+ * Configuration for {@linkcode createRemoteClient}.
269
+ */
66
270
  export type RemoteClientOptions = {
271
+ /**
272
+ * Base URI for HTTP requests to Decide API (optional).
273
+ *
274
+ * Defaults to the environment variable `ARCJET_BASE_URL` (if that value
275
+ * is known and allowed) and the standard production API otherwise.
276
+ */
67
277
  baseUrl?: string;
278
+ /**
279
+ * Timeout in milliseconds for the Decide API (optional).
280
+ *
281
+ * Defaults to `500` in production and `1000` in development.
282
+ */
68
283
  timeout?: number;
69
284
  };
285
+ /**
286
+ * Create a remote client.
287
+ *
288
+ * @param options
289
+ * Configuration (optional).
290
+ * @returns
291
+ * Client.
292
+ */
70
293
  export declare function createRemoteClient({ baseUrl, timeout }: RemoteClientOptions): {
71
294
  readonly baseUrl: string | undefined;
72
295
  readonly timeout: number | undefined;
73
296
  };
74
- export default function arcjet<Characteristics extends readonly string[]>({ rules, characteristics, client, proxies, }?: ArcjetIntegrationOptions<Characteristics>): AstroIntegration;
297
+ /**
298
+ * Create a new Astro integration of Arcjet.
299
+ *
300
+ * @template Characteristics
301
+ * Characteristics to track a user by.
302
+ * @param options
303
+ * Configuration.
304
+ * @returns
305
+ * Astro integration of Arcjet.
306
+ */
307
+ export default function arcjet<Characteristics extends readonly string[]>(options?: ArcjetIntegrationOptions<Characteristics>): AstroIntegration;
75
308
  export {};
package/index.js CHANGED
@@ -54,6 +54,22 @@ const validateEmailOptions = z
54
54
  .strict(),
55
55
  ])
56
56
  .optional();
57
+ const validateFilterOptions = z
58
+ .union([
59
+ z
60
+ .object({
61
+ mode: validateMode,
62
+ allow: z.array(z.string()),
63
+ })
64
+ .strict(),
65
+ z
66
+ .object({
67
+ mode: validateMode,
68
+ deny: z.array(z.string()),
69
+ })
70
+ .strict(),
71
+ ])
72
+ .optional();
57
73
  const validateSensitiveInfoOptions = z
58
74
  .union([
59
75
  z
@@ -135,6 +151,13 @@ function integrationRuleToClientRule(rule) {
135
151
  code: `validateEmail(${serializedOpts})`,
136
152
  };
137
153
  }
154
+ case "filter": {
155
+ const serializedOpts = validateAndSerialize(validateFilterOptions, rule.options);
156
+ return {
157
+ importName: `filter`,
158
+ code: `filter(${serializedOpts})`,
159
+ };
160
+ }
138
161
  case "sensitiveInfo": {
139
162
  const serializedOpts = validateAndSerialize(validateSensitiveInfoOptions, rule.options);
140
163
  return {
@@ -176,34 +199,235 @@ function integrationRuleToClientRule(rule) {
176
199
  }
177
200
  }
178
201
  // Mirror the rule functions in the SDK but produce serializable rules
202
+ // Note: please keep JSDocs in sync with `arcjet` core.
203
+ /**
204
+ * Arcjet Shield WAF rule.
205
+ *
206
+ * Applying this rule protects your application against common attacks,
207
+ * including the OWASP Top 10.
208
+ *
209
+ * The Arcjet Shield WAF analyzes every request to your application to detect
210
+ * suspicious activity.
211
+ * Once a certain suspicion threshold is reached,
212
+ * subsequent requests from that client are blocked for a period of time.
213
+ *
214
+ * @param options
215
+ * Configuration for the Shield rule.
216
+ * @returns
217
+ * Astro integration Shield rule to provide to the SDK in the `rules` field.
218
+ */
179
219
  function shield(options) {
180
220
  return { type: "shield", options };
181
221
  }
222
+ // Note: please keep JSDocs in sync with `arcjet` core.
223
+ /**
224
+ * Arcjet bot detection rule.
225
+ *
226
+ * Applying this rule allows you to manage traffic by automated clients and
227
+ * bots.
228
+ *
229
+ * Bots can be good (such as search engine crawlers or monitoring agents) or bad
230
+ * (such as scrapers or automated scripts).
231
+ * Arcjet allows you to configure which bots you want to allow or deny by
232
+ * specific bot names such as curl, as well as by category such as search
233
+ * engine bots.
234
+ *
235
+ * Bots are detected based on various signals such as the user agent, IP
236
+ * address, DNS records, and more.
237
+ *
238
+ * @param options
239
+ * Configuration for the bot rule (required).
240
+ * @returns
241
+ * Astro integration Bot rule to provide to the SDK in the `rules` field.
242
+ */
182
243
  function detectBot(options) {
183
244
  return { type: "bot", options };
184
245
  }
246
+ // Note: please keep JSDocs in sync with `arcjet` core.
247
+ /**
248
+ * Arcjet email validation rule.
249
+ *
250
+ * Applying this rule allows you to validate and verify an email address.
251
+ *
252
+ * The first step of the analysis is to validate the email address syntax.
253
+ * This runs locally within the SDK and validates the email address is in the
254
+ * correct format.
255
+ * If the email syntax is valid, the SDK will pass the email address to the
256
+ * Arcjet cloud API to verify the email address.
257
+ * This performs several checks, depending on the rule configuration.
258
+ *
259
+ * @param options
260
+ * Configuration for the email validation rule (required).
261
+ * @returns
262
+ * Astro integration Email rule to provide to the SDK in the `rules` field.
263
+ */
185
264
  function validateEmail(options) {
186
265
  return { type: "email", options };
187
266
  }
267
+ // Note: please keep JSDocs in sync with `arcjet` core.
268
+ /**
269
+ * Arcjet filter rule.
270
+ *
271
+ * Applying this rule lets you write expressions to match against requests.
272
+ *
273
+ * @param options
274
+ * Configuration for the filter rule (required).
275
+ * @returns
276
+ * Astro integration Filter rule to provide to the SDK in the `rules` field.
277
+ */
278
+ function filter(options) {
279
+ return { type: "filter", options };
280
+ }
281
+ // Note: please keep JSDocs in sync with `arcjet` core.
282
+ /**
283
+ * Arcjet sensitive information detection rule.
284
+ *
285
+ * Applying this rule protects against clients sending you sensitive information
286
+ * such as personally identifiable information (PII) that you do not wish to
287
+ * handle.
288
+ * The rule runs entirely locally so no data ever leaves your environment.
289
+ *
290
+ * This rule includes built-in detections for email addresses, credit/debit card
291
+ * numbers, IP addresses, and phone numbers.
292
+ * You can also provide a custom detection function to identify additional
293
+ * sensitive information.
294
+ *
295
+ * @param options
296
+ * Configuration for the sensitive information detection rule (required).
297
+ * @returns
298
+ * Astro integration Sensitive information rule to provide to the SDK in the `rules` field.
299
+ */
188
300
  function sensitiveInfo(options) {
189
301
  return { type: "sensitiveInfo", options };
190
302
  }
303
+ // Note: please keep JSDocs in sync with `arcjet` core.
304
+ /**
305
+ * Arcjet fixed window rate limiting rule.
306
+ *
307
+ * Applying this rule sets a fixed window rate limit which tracks the number of
308
+ * requests made by a client over a fixed time window.
309
+ *
310
+ * This is the simplest algorithm.
311
+ * It tracks the number of requests made by a client over a fixed time window
312
+ * such as 60 seconds.
313
+ * If the client exceeds the limit, they are blocked until the window expires.
314
+ *
315
+ * This algorithm is useful when you want to apply a simple fixed limit in a
316
+ * fixed time window.
317
+ * For example, a simple limit on the total number of requests a client can make.
318
+ * However, it can be susceptible to the stampede problem where a client makes
319
+ * a burst of requests at the start of a window and then is blocked for the rest
320
+ * of the window.
321
+ * The sliding window algorithm can be used to avoid this.
322
+ *
323
+ * @template Characteristics
324
+ * Characteristics to track a user by.
325
+ * @param options
326
+ * Configuration for the fixed window rate limiting rule (required).
327
+ * @returns
328
+ * Astro integration Fixed window rule to provide to the SDK in the `rules` field.
329
+ */
191
330
  function fixedWindow(options) {
192
331
  return { type: "fixedWindow", options };
193
332
  }
333
+ // Note: please keep JSDocs in sync with `arcjet` core.
334
+ /**
335
+ * Arcjet sliding window rate limiting rule.
336
+ *
337
+ * Applying this rule sets a sliding window rate limit which tracks the number
338
+ * of requests made by a client over a sliding window so that the window moves
339
+ * with time.
340
+ *
341
+ * This algorithm is useful to avoid the stampede problem of the fixed window.
342
+ * It provides smoother rate limiting over time and can prevent a client from
343
+ * making a burst of requests at the start of a window and then being blocked
344
+ * for the rest of the window.
345
+ *
346
+ * @template Characteristics
347
+ * Characteristics to track a user by.
348
+ * @param options
349
+ * Configuration for the sliding window rate limiting rule (required).
350
+ * @returns
351
+ * Astro integration Sliding window rule to provide to the SDK in the `rules` field.
352
+ */
194
353
  function slidingWindow(options) {
195
354
  return { type: "slidingWindow", options };
196
355
  }
356
+ // Note: please keep JSDocs in sync with `arcjet` core.
357
+ /**
358
+ * Arcjet token bucket rate limiting rule.
359
+ *
360
+ * Applying this rule sets a token bucket rate limit.
361
+ *
362
+ * This algorithm is based on a bucket filled with a specific number of tokens.
363
+ * Each request withdraws some amount of tokens from the bucket and the bucket
364
+ * is refilled at a fixed rate.
365
+ * Once the bucket is empty, the client is blocked until the bucket refills.
366
+ *
367
+ * This algorithm is useful when you want to allow clients to make a burst of
368
+ * requests and then still be able to make requests at a slower rate.
369
+ *
370
+ * @template Characteristics
371
+ * Characteristics to track a user by.
372
+ * @param options
373
+ * Configuration for the token bucket rate limiting rule (required).
374
+ * @returns
375
+ * Astro integration Token bucket rule to provide to the SDK in the `rules` field.
376
+ */
197
377
  function tokenBucket(options) {
198
378
  return { type: "tokenBucket", options };
199
379
  }
380
+ // Note: please keep JSDocs in sync with `arcjet` core.
381
+ /**
382
+ * Arcjet signup form protection rule.
383
+ *
384
+ * Applying this rule combines rate limiting, bot protection, and email
385
+ * validation to protect your signup forms from abuse.
386
+ * Using this rule will configure the following:
387
+ *
388
+ * - Rate limiting - signup forms are a common target for bots. Arcjet’s rate
389
+ * limiting helps to prevent bots and other automated or malicious clients
390
+ * from submitting your signup form too many times in a short period of time.
391
+ * - Bot protection - signup forms are usually exclusively used by humans, which
392
+ * means that any automated submissions to the form are likely to be
393
+ * fraudulent.
394
+ * - Email validation - email addresses should be validated to ensure the signup
395
+ * is coming from a legitimate user with a real email address that can
396
+ * actually receive messages.
397
+ *
398
+ * @template Characteristics
399
+ * Characteristics to track a user by.
400
+ * @param options
401
+ * Configuration for the signup form protection rule.
402
+ * @returns
403
+ * Astro integration Signup form protection rule to provide to the SDK in the `rules` field.
404
+ */
200
405
  function protectSignup(options) {
201
406
  return { type: "protectSignup", options };
202
407
  }
408
+ /**
409
+ * Create a remote client.
410
+ *
411
+ * @param options
412
+ * Configuration (optional).
413
+ * @returns
414
+ * Client.
415
+ */
203
416
  function createRemoteClient({ baseUrl, timeout }) {
204
417
  return { baseUrl, timeout };
205
418
  }
206
- function arcjet({ rules, characteristics, client, proxies, } = { rules: [] }) {
419
+ /**
420
+ * Create a new Astro integration of Arcjet.
421
+ *
422
+ * @template Characteristics
423
+ * Characteristics to track a user by.
424
+ * @param options
425
+ * Configuration.
426
+ * @returns
427
+ * Astro integration of Arcjet.
428
+ */
429
+ function arcjet(options = { rules: [] }) {
430
+ const { rules, characteristics, client, proxies } = options;
207
431
  const arcjetImports = new Set();
208
432
  const arcjetRules = [];
209
433
  for (const rule of rules) {
@@ -331,6 +555,21 @@ function arcjet({ rules, characteristics, client, proxies, } = { rules: [] }) {
331
555
  ${Array.from(arcjetImports).join(",\n")}
332
556
  } from "arcjet"
333
557
 
558
+ /**
559
+ * Instance of the Astro integration of Arcjet.
560
+ *
561
+ * Primarily has a \`protect()\` method to make a decision about how a request
562
+ * should be handled.
563
+ *
564
+ * > 👉 **Note**: this is generated by \`@arcjet/astro\` based on how you configure
565
+ * > Arcjet in your \`astro.config.mjs\` file.
566
+ * > In that configuration file, you can pass the (serializable) options that apply
567
+ * > to all requests.
568
+ * > You can call \`aj.withRule\` *on* this default client to extend its behavior.
569
+ *
570
+ * @template Props
571
+ * Configuration.
572
+ */
334
573
  const client = createArcjetClient({
335
574
  rules: [
336
575
  ${arcjetRules.join(",\n")}
@@ -348,4 +587,4 @@ function arcjet({ rules, characteristics, client, proxies, } = { rules: [] }) {
348
587
  };
349
588
  }
350
589
 
351
- export { createRemoteClient, arcjet as default, detectBot, fixedWindow, protectSignup, sensitiveInfo, shield, slidingWindow, tokenBucket, validateEmail };
590
+ export { createRemoteClient, arcjet as default, detectBot, filter, fixedWindow, protectSignup, sensitiveInfo, shield, slidingWindow, tokenBucket, validateEmail };
package/internal.d.ts CHANGED
@@ -10,51 +10,99 @@ type WithoutCustomProps = {
10
10
  type PlainObject = {
11
11
  [key: string]: unknown;
12
12
  };
13
+ /**
14
+ * Configuration for {@linkcode createRemoteClient}.
15
+ */
13
16
  export type RemoteClientOptions = {
17
+ /**
18
+ * Base URI for HTTP requests to Decide API (optional).
19
+ *
20
+ * Defaults to the environment variable `ARCJET_BASE_URL` (if that value
21
+ * is known and allowed) and the standard production API otherwise.
22
+ */
14
23
  baseUrl?: string;
24
+ /**
25
+ * Timeout in milliseconds for the Decide API (optional).
26
+ *
27
+ * Defaults to `500` in production and `1000` in development.
28
+ */
15
29
  timeout?: number;
16
30
  };
31
+ /**
32
+ * Create a remote client.
33
+ *
34
+ * @param options
35
+ * Configuration (optional).
36
+ * @returns
37
+ * Client.
38
+ */
17
39
  export declare function createRemoteClient(options?: RemoteClientOptions): import("@arcjet/protocol/client.js").Client;
18
40
  /**
19
- * The options used to configure an {@link ArcjetAstro} client.
41
+ * Configuration for the Astro integration of Arcjet.
42
+ *
43
+ * @template Rules
44
+ * List of rules.
45
+ * @template Characteristics
46
+ * Characteristics to track a user by.
20
47
  */
21
48
  export type ArcjetOptions<Rules extends [...Array<Primitive | Product>], Characteristics extends readonly string[]> = Simplify<CoreOptions<Rules, Characteristics> & {
22
49
  /**
23
- * One or more IP Address of trusted proxies in front of the application.
24
- * These addresses will be excluded when Arcjet detects a public IP address.
50
+ * IP addresses and CIDR ranges of trusted load balancers and proxies
51
+ * (optional, example: `["100.100.100.100", "100.100.100.0/24"]`).
25
52
  */
26
53
  proxies?: Array<string>;
27
54
  }>;
28
55
  /**
29
- * The ArcjetAstro client provides a public `protect()` method to
30
- * make a decision about how an Astro request should be handled.
56
+ * Instance of the Astro integration of Arcjet.
57
+ *
58
+ * Primarily has a `protect()` method to make a decision about how a request
59
+ * should be handled.
60
+ *
61
+ * @template Props
62
+ * Configuration.
31
63
  */
32
64
  export interface ArcjetAstro<Props extends PlainObject> {
33
65
  /**
34
- * Runs a request through the configured protections. The request is
35
- * analyzed and then a decision made on whether to allow, deny, or challenge
36
- * the request.
66
+ * Make a decision about how to handle a request.
37
67
  *
38
- * @param request - A `Request` provided to the fetch handler.
39
- * @param props - Additonal properties required for running rules against a request.
40
- * @returns An {@link ArcjetDecision} indicating Arcjet's decision about the request.
68
+ * This will analyze the request locally where possible and otherwise call
69
+ * the Arcjet decision API.
70
+ *
71
+ * @param ctx
72
+ * Additional context for this function call.
73
+ * @param request
74
+ * Details about the {@linkcode ArcjetRequest} that Arcjet needs to make a
75
+ * decision.
76
+ * @returns
77
+ * Promise that resolves to an {@linkcode ArcjetDecision} indicating
78
+ * Arcjet’s decision about the request.
41
79
  */
42
80
  protect(request: Request, ...props: Props extends WithoutCustomProps ? [] : [Props]): Promise<ArcjetDecision>;
43
81
  /**
44
- * Augments the client with another rule. Useful for varying rules based on
45
- * criteria in your handler—e.g. different rate limit for logged in users.
82
+ * Augment the client with another rule.
83
+ *
84
+ * Useful for varying rules based on criteria in your handler such as
85
+ * different rate limit for logged in users.
46
86
  *
47
- * @param rule The rule to add to this execution.
48
- * @returns An augmented {@link ArcjetAstro} client.
87
+ * @template Rule
88
+ * Type of rule.
89
+ * @param rule
90
+ * Rule to add to Arcjet.
91
+ * @returns
92
+ * Arcjet instance augmented with the given rule.
49
93
  */
50
94
  withRule<Rule extends Primitive | Product>(rule: Rule): ArcjetAstro<Simplify<Props & ExtraProps<Rule>>>;
51
95
  }
52
96
  /**
53
- * Create a new {@link ArcjetAstro} client. Always build your initial client
54
- * outside of a request handler so it persists across requests. If you need to
55
- * augment a client inside a handler, call the `withRule()` function on the base
56
- * client.
97
+ * Create a new Astro integration of Arcjet.
57
98
  *
58
- * @param options - Arcjet configuration options to apply to all requests.
99
+ * @template Rules
100
+ * List of rules.
101
+ * @template Characteristics
102
+ * Characteristics to track a user by.
103
+ * @param options
104
+ * Configuration.
105
+ * @returns
106
+ * Astro integration of Arcjet.
59
107
  */
60
108
  export declare function createArcjetClient<const Rules extends (Primitive | Product)[], const Characteristics extends readonly string[]>(options: ArcjetOptions<Rules, Characteristics>): ArcjetAstro<Simplify<ExtraProps<Rules> & CharacteristicProps<Characteristics>>>;
package/internal.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 { baseUrl, isDevelopment, logLevel, platform } from '@arcjet/env';
6
6
  import { Logger } from '@arcjet/logger';
7
7
  import { createClient } from '@arcjet/protocol/client.js';
@@ -36,17 +36,21 @@ function errorMessage(err) {
36
36
  }
37
37
  return "Unknown problem";
38
38
  }
39
+ /**
40
+ * Create a remote client.
41
+ *
42
+ * @param options
43
+ * Configuration (optional).
44
+ * @returns
45
+ * Client.
46
+ */
39
47
  function createRemoteClient(options) {
40
- // The base URL for the Arcjet API. Will default to the standard production
41
- // API unless environment variable `ARCJET_BASE_URL` is set.
42
48
  const url = options?.baseUrl ?? baseUrl(env);
43
- // The timeout for the Arcjet API in milliseconds. This is set to a low value
44
- // in production so calls fail open.
45
49
  const timeout = options?.timeout ?? (isDevelopment(env) ? 1000 : 500);
46
50
  // Transport is the HTTP client that the client uses to make requests.
47
51
  const transport = createTransport(url);
48
52
  const sdkStack = "ASTRO";
49
- const sdkVersion = "1.0.0-beta.10";
53
+ const sdkVersion = "1.0.0-beta.11";
50
54
  return createClient({
51
55
  transport,
52
56
  baseUrl: url,
@@ -56,12 +60,16 @@ function createRemoteClient(options) {
56
60
  });
57
61
  }
58
62
  /**
59
- * Create a new {@link ArcjetAstro} client. Always build your initial client
60
- * outside of a request handler so it persists across requests. If you need to
61
- * augment a client inside a handler, call the `withRule()` function on the base
62
- * client.
63
+ * Create a new Astro integration of Arcjet.
63
64
  *
64
- * @param options - Arcjet configuration options to apply to all requests.
65
+ * @template Rules
66
+ * List of rules.
67
+ * @template Characteristics
68
+ * Characteristics to track a user by.
69
+ * @param options
70
+ * Configuration.
71
+ * @returns
72
+ * Astro integration of Arcjet.
65
73
  */
66
74
  function createArcjetClient(options) {
67
75
  const client = options.client ?? createRemoteClient();
@@ -85,7 +93,7 @@ function createArcjetClient(options) {
85
93
  // We construct an ArcjetHeaders to normalize over Headers
86
94
  const headers = new ArcjetHeaders(request.headers);
87
95
  const url = new URL(request.url);
88
- let ip = findIP({
96
+ let ip = findIp({
89
97
  ip: clientAddress,
90
98
  headers,
91
99
  }, { platform: platform(env), proxies });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arcjet/astro",
3
- "version": "1.0.0-beta.10",
3
+ "version": "1.0.0-beta.11",
4
4
  "description": "Arcjet helps developers protect their Astro sites in just a few lines of code. Bot detection. Rate limiting. Email validation. Attack protection. Data redaction. A developer-first approach to security.",
5
5
  "keywords": [
6
6
  "analyze",
@@ -50,24 +50,23 @@
50
50
  "test": "npm run build && npm run lint"
51
51
  },
52
52
  "dependencies": {
53
- "@arcjet/env": "1.0.0-beta.10",
54
- "@arcjet/headers": "1.0.0-beta.10",
55
- "@arcjet/ip": "1.0.0-beta.10",
56
- "@arcjet/logger": "1.0.0-beta.10",
57
- "@arcjet/protocol": "1.0.0-beta.10",
58
- "@arcjet/transport": "1.0.0-beta.10",
59
- "arcjet": "1.0.0-beta.10"
53
+ "@arcjet/env": "1.0.0-beta.11",
54
+ "@arcjet/headers": "1.0.0-beta.11",
55
+ "@arcjet/ip": "1.0.0-beta.11",
56
+ "@arcjet/logger": "1.0.0-beta.11",
57
+ "@arcjet/protocol": "1.0.0-beta.11",
58
+ "@arcjet/transport": "1.0.0-beta.11",
59
+ "arcjet": "1.0.0-beta.11"
60
60
  },
61
61
  "peerDependencies": {
62
62
  "astro": "^5.9.3"
63
63
  },
64
64
  "devDependencies": {
65
- "@arcjet/eslint-config": "1.0.0-beta.10",
66
- "@arcjet/rollup-config": "1.0.0-beta.10",
67
- "@arcjet/tsconfig": "1.0.0-beta.10",
68
- "@rollup/wasm-node": "4.46.2",
69
- "astro": "5.12.8",
70
- "eslint": "9.32.0",
65
+ "@arcjet/eslint-config": "1.0.0-beta.11",
66
+ "@arcjet/rollup-config": "1.0.0-beta.11",
67
+ "@rollup/wasm-node": "4.50.0",
68
+ "astro": "5.13.5",
69
+ "eslint": "9.34.0",
71
70
  "typescript": "5.9.2"
72
71
  },
73
72
  "publishConfig": {