@arcjet/astro 1.0.0-beta.11 → 1.0.0-beta.13

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/index.d.ts +51 -29
  2. package/index.js +81 -57
  3. package/internal.js +1 -1
  4. package/package.json +16 -14
package/index.d.ts CHANGED
@@ -2,31 +2,31 @@ import type { BotOptions, EmailOptions, FilterOptions, FixedWindowRateLimitOptio
2
2
  import type { AstroIntegration } from "astro";
3
3
  type IntegrationRule<Characteristics extends readonly string[]> = {
4
4
  type: "shield";
5
- options?: ShieldOptions;
5
+ options: ShieldOptions;
6
6
  } | {
7
7
  type: "bot";
8
- options?: BotOptions;
8
+ options: BotOptions;
9
9
  } | {
10
10
  type: "email";
11
- options?: EmailOptions;
11
+ options: EmailOptions;
12
12
  } | {
13
13
  type: "filter";
14
14
  options: FilterOptions;
15
15
  } | {
16
16
  type: "sensitiveInfo";
17
- options?: SensitiveInfoOptions<never>;
17
+ options: SensitiveInfoOptions<never>;
18
18
  } | {
19
19
  type: "fixedWindow";
20
- options?: FixedWindowRateLimitOptions<Characteristics>;
20
+ options: FixedWindowRateLimitOptions<Characteristics>;
21
21
  } | {
22
22
  type: "slidingWindow";
23
- options?: SlidingWindowRateLimitOptions<Characteristics>;
23
+ options: SlidingWindowRateLimitOptions<Characteristics>;
24
24
  } | {
25
25
  type: "tokenBucket";
26
- options?: TokenBucketRateLimitOptions<Characteristics>;
26
+ options: TokenBucketRateLimitOptions<Characteristics>;
27
27
  } | {
28
28
  type: "protectSignup";
29
- options?: ProtectSignupOptions<Characteristics>;
29
+ options: ProtectSignupOptions<Characteristics>;
30
30
  };
31
31
  /**
32
32
  * Configuration for the Astro integration of Arcjet.
@@ -74,9 +74,9 @@ type ArcjetIntegrationOptions<Characteristics extends readonly string[]> = {
74
74
  * @returns
75
75
  * Astro integration Shield rule to provide to the SDK in the `rules` field.
76
76
  */
77
- export declare function shield(options?: ShieldOptions): {
77
+ export declare function shield(options: ShieldOptions): {
78
78
  readonly type: "shield";
79
- readonly options: ShieldOptions | undefined;
79
+ readonly options: ShieldOptions;
80
80
  };
81
81
  /**
82
82
  * Arcjet bot detection rule.
@@ -98,9 +98,9 @@ export declare function shield(options?: ShieldOptions): {
98
98
  * @returns
99
99
  * Astro integration Bot rule to provide to the SDK in the `rules` field.
100
100
  */
101
- export declare function detectBot(options?: BotOptions): {
101
+ export declare function detectBot(options: BotOptions): {
102
102
  readonly type: "bot";
103
- readonly options: BotOptions | undefined;
103
+ readonly options: BotOptions;
104
104
  };
105
105
  /**
106
106
  * Arcjet email validation rule.
@@ -119,19 +119,41 @@ export declare function detectBot(options?: BotOptions): {
119
119
  * @returns
120
120
  * Astro integration Email rule to provide to the SDK in the `rules` field.
121
121
  */
122
- export declare function validateEmail(options?: EmailOptions): {
122
+ export declare function validateEmail(options: EmailOptions): {
123
123
  readonly type: "email";
124
- readonly options: EmailOptions | undefined;
124
+ readonly options: EmailOptions;
125
125
  };
126
126
  /**
127
127
  * Arcjet filter rule.
128
128
  *
129
- * Applying this rule lets you write expressions to match against requests.
129
+ * Applying this rule lets you block requests using Wireshark-like display
130
+ * filter expressions over HTTP headers, IP addresses, and other request
131
+ * fields.
132
+ * You can quickly enforce rules like allow/deny by country, network, or
133
+ * `user-agent` pattern.
134
+ *
135
+ * See the [reference guide](https://docs.arcjet.com/filters/reference) for
136
+ * more info on the expression language fields, functions, and values.
130
137
  *
131
138
  * @param options
132
- * Configuration for the filter rule (required).
139
+ * Configuration (required).
133
140
  * @returns
134
141
  * Astro integration Filter rule to provide to the SDK in the `rules` field.
142
+ *
143
+ * @example
144
+ * In this example, the expression matches non-VPN GET requests from the US.
145
+ * Requests matching the expression are allowed, all others are denied.
146
+ *
147
+ * ```ts
148
+ * filter({
149
+ * allow: [
150
+ * 'http.request.method eq "GET" and ip.src.country eq "US" and not ip.src.vpn',
151
+ * ],
152
+ * mode: "LIVE",
153
+ * })
154
+ * ```
155
+ *
156
+ * @link https://docs.arcjet.com/filters/reference
135
157
  */
136
158
  export declare function filter(options: FilterOptions): {
137
159
  readonly type: "filter";
@@ -155,9 +177,9 @@ export declare function filter(options: FilterOptions): {
155
177
  * @returns
156
178
  * Astro integration Sensitive information rule to provide to the SDK in the `rules` field.
157
179
  */
158
- export declare function sensitiveInfo(options?: SensitiveInfoOptions<never>): {
180
+ export declare function sensitiveInfo(options: SensitiveInfoOptions<never>): {
159
181
  readonly type: "sensitiveInfo";
160
- readonly options: SensitiveInfoOptions<never> | undefined;
182
+ readonly options: SensitiveInfoOptions<never>;
161
183
  };
162
184
  /**
163
185
  * Arcjet fixed window rate limiting rule.
@@ -185,9 +207,9 @@ export declare function sensitiveInfo(options?: SensitiveInfoOptions<never>): {
185
207
  * @returns
186
208
  * Astro integration Fixed window rule to provide to the SDK in the `rules` field.
187
209
  */
188
- export declare function fixedWindow<Characteristics extends readonly string[]>(options?: FixedWindowRateLimitOptions<Characteristics>): {
210
+ export declare function fixedWindow<Characteristics extends readonly string[]>(options: FixedWindowRateLimitOptions<Characteristics>): {
189
211
  readonly type: "fixedWindow";
190
- readonly options: FixedWindowRateLimitOptions<Characteristics> | undefined;
212
+ readonly options: FixedWindowRateLimitOptions<Characteristics>;
191
213
  };
192
214
  /**
193
215
  * Arcjet sliding window rate limiting rule.
@@ -208,9 +230,9 @@ export declare function fixedWindow<Characteristics extends readonly string[]>(o
208
230
  * @returns
209
231
  * Astro integration Sliding window rule to provide to the SDK in the `rules` field.
210
232
  */
211
- export declare function slidingWindow<Characteristics extends readonly string[]>(options?: SlidingWindowRateLimitOptions<Characteristics>): {
233
+ export declare function slidingWindow<Characteristics extends readonly string[]>(options: SlidingWindowRateLimitOptions<Characteristics>): {
212
234
  readonly type: "slidingWindow";
213
- readonly options: SlidingWindowRateLimitOptions<Characteristics> | undefined;
235
+ readonly options: SlidingWindowRateLimitOptions<Characteristics>;
214
236
  };
215
237
  /**
216
238
  * Arcjet token bucket rate limiting rule.
@@ -232,9 +254,9 @@ export declare function slidingWindow<Characteristics extends readonly string[]>
232
254
  * @returns
233
255
  * Astro integration Token bucket rule to provide to the SDK in the `rules` field.
234
256
  */
235
- export declare function tokenBucket<Characteristics extends readonly string[]>(options?: TokenBucketRateLimitOptions<Characteristics>): {
257
+ export declare function tokenBucket<Characteristics extends readonly string[]>(options: TokenBucketRateLimitOptions<Characteristics>): {
236
258
  readonly type: "tokenBucket";
237
- readonly options: TokenBucketRateLimitOptions<Characteristics> | undefined;
259
+ readonly options: TokenBucketRateLimitOptions<Characteristics>;
238
260
  };
239
261
  /**
240
262
  * Arcjet signup form protection rule.
@@ -260,9 +282,9 @@ export declare function tokenBucket<Characteristics extends readonly string[]>(o
260
282
  * @returns
261
283
  * Astro integration Signup form protection rule to provide to the SDK in the `rules` field.
262
284
  */
263
- export declare function protectSignup<Characteristics extends readonly string[]>(options?: ProtectSignupOptions<Characteristics>): {
285
+ export declare function protectSignup<Characteristics extends readonly string[]>(options: ProtectSignupOptions<Characteristics>): {
264
286
  readonly type: "protectSignup";
265
- readonly options: ProtectSignupOptions<Characteristics> | undefined;
287
+ readonly options: ProtectSignupOptions<Characteristics>;
266
288
  };
267
289
  /**
268
290
  * Configuration for {@linkcode createRemoteClient}.
@@ -274,13 +296,13 @@ export type RemoteClientOptions = {
274
296
  * Defaults to the environment variable `ARCJET_BASE_URL` (if that value
275
297
  * is known and allowed) and the standard production API otherwise.
276
298
  */
277
- baseUrl?: string;
299
+ baseUrl?: string | undefined;
278
300
  /**
279
301
  * Timeout in milliseconds for the Decide API (optional).
280
302
  *
281
303
  * Defaults to `500` in production and `1000` in development.
282
304
  */
283
- timeout?: number;
305
+ timeout?: number | undefined;
284
306
  };
285
307
  /**
286
308
  * Create a remote client.
@@ -290,7 +312,7 @@ export type RemoteClientOptions = {
290
312
  * @returns
291
313
  * Client.
292
314
  */
293
- export declare function createRemoteClient({ baseUrl, timeout }: RemoteClientOptions): {
315
+ export declare function createRemoteClient(options?: RemoteClientOptions | undefined): {
294
316
  readonly baseUrl: string | undefined;
295
317
  readonly timeout: number | undefined;
296
318
  };
package/index.js CHANGED
@@ -7,123 +7,112 @@ const validateProxies = z.array(z.string());
7
7
  const validateCharacteristics = z.array(z.string());
8
8
  const validateClientOptions = z
9
9
  .object({
10
- baseUrl: z.string(),
11
- timeout: z.number(),
10
+ baseUrl: z.string().optional(),
11
+ timeout: z.number().optional(),
12
12
  })
13
13
  .strict()
14
14
  .optional();
15
+ // TODO: once `arcjet` core has `exactOptionalProperties` we can use
16
+ // `satisfies z.ZodType<ShieldOptions>` and such here.
15
17
  const validateShieldOptions = z
16
18
  .object({
17
- mode: validateMode,
19
+ mode: validateMode.optional(),
18
20
  })
19
- .strict()
20
- .optional();
21
- const validateBotOptions = z
22
- .union([
21
+ .strict();
22
+ const validateBotOptions = z.union([
23
23
  z
24
24
  .object({
25
- mode: validateMode,
25
+ mode: validateMode.optional(),
26
26
  allow: z.array(z.string()),
27
27
  })
28
28
  .strict(),
29
29
  z
30
30
  .object({
31
- mode: validateMode,
31
+ mode: validateMode.optional(),
32
32
  deny: z.array(z.string()),
33
33
  })
34
34
  .strict(),
35
- ])
36
- .optional();
37
- const validateEmailOptions = z
38
- .union([
35
+ ]);
36
+ const validateEmailOptions = z.union([
39
37
  z
40
38
  .object({
41
- mode: validateMode,
39
+ mode: validateMode.optional(),
42
40
  allow: z.array(z.string()),
43
- requireTopLevelDomain: z.boolean(),
44
- allowDomainLiteral: z.boolean(),
41
+ requireTopLevelDomain: z.boolean().optional(),
42
+ allowDomainLiteral: z.boolean().optional(),
45
43
  })
46
44
  .strict(),
47
45
  z
48
46
  .object({
49
- mode: validateMode,
47
+ mode: validateMode.optional(),
50
48
  deny: z.array(z.string()),
51
- requireTopLevelDomain: z.boolean(),
52
- allowDomainLiteral: z.boolean(),
49
+ requireTopLevelDomain: z.boolean().optional(),
50
+ allowDomainLiteral: z.boolean().optional(),
53
51
  })
54
52
  .strict(),
55
- ])
56
- .optional();
57
- const validateFilterOptions = z
58
- .union([
53
+ ]);
54
+ const validateFilterOptions = z.union([
59
55
  z
60
56
  .object({
61
- mode: validateMode,
57
+ mode: validateMode.optional(),
62
58
  allow: z.array(z.string()),
63
59
  })
64
60
  .strict(),
65
61
  z
66
62
  .object({
67
- mode: validateMode,
63
+ mode: validateMode.optional(),
68
64
  deny: z.array(z.string()),
69
65
  })
70
66
  .strict(),
71
- ])
72
- .optional();
73
- const validateSensitiveInfoOptions = z
74
- .union([
67
+ ]);
68
+ const validateSensitiveInfoOptions = z.union([
75
69
  z
76
70
  .object({
77
- mode: validateMode,
71
+ mode: validateMode.optional(),
78
72
  allow: z.array(z.string()),
79
- contextWindowSize: z.number(),
73
+ contextWindowSize: z.number().optional(),
80
74
  })
81
75
  .strict(),
82
76
  z
83
77
  .object({
84
- mode: validateMode,
78
+ mode: validateMode.optional(),
85
79
  deny: z.array(z.string()),
86
- contextWindowSize: z.number(),
80
+ contextWindowSize: z.number().optional(),
87
81
  })
88
82
  .strict(),
89
- ])
90
- .optional();
83
+ ]);
91
84
  const validateFixedWindowOptions = z
92
85
  .object({
93
- mode: validateMode,
94
- characteristics: validateCharacteristics,
86
+ mode: validateMode.optional(),
87
+ characteristics: validateCharacteristics.optional(),
95
88
  window: z.union([z.string(), z.number()]),
96
89
  max: z.number(),
97
90
  })
98
- .strict()
99
- .optional();
91
+ .strict();
100
92
  const validateSlidingWindowOptions = z
101
93
  .object({
102
- mode: validateMode,
103
- characteristics: validateCharacteristics,
94
+ mode: validateMode.optional(),
95
+ characteristics: validateCharacteristics.optional(),
104
96
  interval: z.union([z.string(), z.number()]),
105
97
  max: z.number(),
106
98
  })
107
- .strict()
108
- .optional();
99
+ .strict();
109
100
  const validateTokenBucketOptions = z
110
101
  .object({
111
- mode: validateMode,
112
- characteristics: validateCharacteristics,
102
+ mode: validateMode.optional(),
103
+ characteristics: validateCharacteristics.optional(),
113
104
  refillRate: z.number(),
114
105
  interval: z.union([z.string(), z.number()]),
115
106
  capacity: z.number(),
116
107
  })
117
- .strict()
118
- .optional();
108
+ .strict();
119
109
  const validateProtectSignupOptions = z
120
110
  .object({
121
111
  rateLimit: validateSlidingWindowOptions,
122
112
  bots: validateBotOptions,
123
113
  email: validateEmailOptions,
124
114
  })
125
- .strict()
126
- .optional();
115
+ .strict();
127
116
  function validateAndSerialize(schema, value) {
128
117
  const v = schema.parse(value);
129
118
  return v ? JSON.stringify(v) : "";
@@ -268,12 +257,34 @@ function validateEmail(options) {
268
257
  /**
269
258
  * Arcjet filter rule.
270
259
  *
271
- * Applying this rule lets you write expressions to match against requests.
260
+ * Applying this rule lets you block requests using Wireshark-like display
261
+ * filter expressions over HTTP headers, IP addresses, and other request
262
+ * fields.
263
+ * You can quickly enforce rules like allow/deny by country, network, or
264
+ * `user-agent` pattern.
265
+ *
266
+ * See the [reference guide](https://docs.arcjet.com/filters/reference) for
267
+ * more info on the expression language fields, functions, and values.
272
268
  *
273
269
  * @param options
274
- * Configuration for the filter rule (required).
270
+ * Configuration (required).
275
271
  * @returns
276
272
  * Astro integration Filter rule to provide to the SDK in the `rules` field.
273
+ *
274
+ * @example
275
+ * In this example, the expression matches non-VPN GET requests from the US.
276
+ * Requests matching the expression are allowed, all others are denied.
277
+ *
278
+ * ```ts
279
+ * filter({
280
+ * allow: [
281
+ * 'http.request.method eq "GET" and ip.src.country eq "US" and not ip.src.vpn',
282
+ * ],
283
+ * mode: "LIVE",
284
+ * })
285
+ * ```
286
+ *
287
+ * @link https://docs.arcjet.com/filters/reference
277
288
  */
278
289
  function filter(options) {
279
290
  return { type: "filter", options };
@@ -328,7 +339,10 @@ function sensitiveInfo(options) {
328
339
  * Astro integration Fixed window rule to provide to the SDK in the `rules` field.
329
340
  */
330
341
  function fixedWindow(options) {
331
- return { type: "fixedWindow", options };
342
+ return {
343
+ type: "fixedWindow",
344
+ options,
345
+ };
332
346
  }
333
347
  // Note: please keep JSDocs in sync with `arcjet` core.
334
348
  /**
@@ -351,7 +365,10 @@ function fixedWindow(options) {
351
365
  * Astro integration Sliding window rule to provide to the SDK in the `rules` field.
352
366
  */
353
367
  function slidingWindow(options) {
354
- return { type: "slidingWindow", options };
368
+ return {
369
+ type: "slidingWindow",
370
+ options,
371
+ };
355
372
  }
356
373
  // Note: please keep JSDocs in sync with `arcjet` core.
357
374
  /**
@@ -375,7 +392,10 @@ function slidingWindow(options) {
375
392
  * Astro integration Token bucket rule to provide to the SDK in the `rules` field.
376
393
  */
377
394
  function tokenBucket(options) {
378
- return { type: "tokenBucket", options };
395
+ return {
396
+ type: "tokenBucket",
397
+ options,
398
+ };
379
399
  }
380
400
  // Note: please keep JSDocs in sync with `arcjet` core.
381
401
  /**
@@ -403,7 +423,10 @@ function tokenBucket(options) {
403
423
  * Astro integration Signup form protection rule to provide to the SDK in the `rules` field.
404
424
  */
405
425
  function protectSignup(options) {
406
- return { type: "protectSignup", options };
426
+ return {
427
+ type: "protectSignup",
428
+ options,
429
+ };
407
430
  }
408
431
  /**
409
432
  * Create a remote client.
@@ -413,8 +436,9 @@ function protectSignup(options) {
413
436
  * @returns
414
437
  * Client.
415
438
  */
416
- function createRemoteClient({ baseUrl, timeout }) {
417
- return { baseUrl, timeout };
439
+ function createRemoteClient(options) {
440
+ const settings = options ?? {};
441
+ return { baseUrl: settings.baseUrl, timeout: settings.timeout };
418
442
  }
419
443
  /**
420
444
  * Create a new Astro integration of Arcjet.
package/internal.js CHANGED
@@ -50,7 +50,7 @@ function createRemoteClient(options) {
50
50
  // Transport is the HTTP client that the client uses to make requests.
51
51
  const transport = createTransport(url);
52
52
  const sdkStack = "ASTRO";
53
- const sdkVersion = "1.0.0-beta.11";
53
+ const sdkVersion = "1.0.0-beta.13";
54
54
  return createClient({
55
55
  transport,
56
56
  baseUrl: url,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arcjet/astro",
3
- "version": "1.0.0-beta.11",
3
+ "version": "1.0.0-beta.13",
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",
@@ -47,26 +47,28 @@
47
47
  "build": "rollup --config rollup.config.js",
48
48
  "lint": "eslint .",
49
49
  "prepublishOnly": "npm run build",
50
- "test": "npm run build && npm run lint"
50
+ "test-api": "node --test",
51
+ "test-coverage": "node --experimental-test-coverage --test",
52
+ "test": "npm run build && npm run lint && npm run test-coverage"
51
53
  },
52
54
  "dependencies": {
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"
55
+ "@arcjet/env": "1.0.0-beta.13",
56
+ "@arcjet/headers": "1.0.0-beta.13",
57
+ "@arcjet/ip": "1.0.0-beta.13",
58
+ "@arcjet/logger": "1.0.0-beta.13",
59
+ "@arcjet/protocol": "1.0.0-beta.13",
60
+ "@arcjet/transport": "1.0.0-beta.13",
61
+ "arcjet": "1.0.0-beta.13"
60
62
  },
61
63
  "peerDependencies": {
62
64
  "astro": "^5.9.3"
63
65
  },
64
66
  "devDependencies": {
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",
67
+ "@arcjet/eslint-config": "1.0.0-beta.13",
68
+ "@arcjet/rollup-config": "1.0.0-beta.13",
69
+ "@rollup/wasm-node": "4.52.3",
70
+ "astro": "5.14.1",
71
+ "eslint": "9.36.0",
70
72
  "typescript": "5.9.2"
71
73
  },
72
74
  "publishConfig": {