@arcjet/astro 1.0.0-beta.8 → 1.0.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.
- package/README.md +35 -161
- package/index.d.ts +285 -30
- package/index.js +336 -52
- package/internal.d.ts +84 -26
- package/internal.js +51 -48
- package/package.json +41 -30
- package/astro-env.d.ts +0 -16
package/README.md
CHANGED
|
@@ -22,6 +22,9 @@ against common attacks.
|
|
|
22
22
|
|
|
23
23
|
This is the [Arcjet][arcjet] SDK integration for [Astro][astro].
|
|
24
24
|
|
|
25
|
+
- [npm package (`@arcjet/astro`)](https://www.npmjs.com/package/@arcjet/astro)
|
|
26
|
+
- [GitHub source code (`arcjet-astro/` in `arcjet/arcjet-js`)](https://github.com/arcjet/arcjet-js/tree/main/arcjet-astro)
|
|
27
|
+
|
|
25
28
|
## Getting started
|
|
26
29
|
|
|
27
30
|
Visit the [quick start guide][quick-start] to get started.
|
|
@@ -31,187 +34,55 @@ Visit the [quick start guide][quick-start] to get started.
|
|
|
31
34
|
Try an Arcjet protected app live at [https://example.arcjet.com][example-url]
|
|
32
35
|
([source code][example-source]).
|
|
33
36
|
|
|
34
|
-
##
|
|
35
|
-
|
|
36
|
-
```shell
|
|
37
|
-
npx astro add @arcjet/astro
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
## Usage
|
|
37
|
+
## What is this?
|
|
41
38
|
|
|
42
|
-
|
|
43
|
-
|
|
39
|
+
This is our adapter to integrate Arcjet into Astro.
|
|
40
|
+
Arcjet helps you secure your Astro website.
|
|
41
|
+
This package exists so that we can provide the best possible experience to
|
|
42
|
+
Astro users.
|
|
44
43
|
|
|
45
|
-
|
|
46
|
-
// @ts-check
|
|
47
|
-
import { defineConfig } from "astro/config";
|
|
48
|
-
+ import arcjet from "@arcjet/astro";
|
|
44
|
+
## When should I use this?
|
|
49
45
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
+ arcjet(),
|
|
54
|
-
+ ],
|
|
55
|
-
});
|
|
56
|
-
```
|
|
46
|
+
You can use this if you are using Astro.
|
|
47
|
+
See our [_Get started_ guide][arcjet-get-started] for other supported
|
|
48
|
+
frameworks.
|
|
57
49
|
|
|
58
|
-
|
|
59
|
-
configuration.
|
|
60
|
-
|
|
61
|
-
We also recommended validating your environment variables at build time. To do
|
|
62
|
-
this, update your `astro.config.mjs` to add the option:
|
|
63
|
-
|
|
64
|
-
```diff
|
|
65
|
-
// @ts-check
|
|
66
|
-
import { defineConfig } from "astro/config";
|
|
67
|
-
import arcjet from "@arcjet/astro";
|
|
68
|
-
|
|
69
|
-
// https://astro.build/config
|
|
70
|
-
export default defineConfig({
|
|
71
|
-
+ env: {
|
|
72
|
-
+ validateSecrets: true
|
|
73
|
-
+ },
|
|
74
|
-
integrations: [
|
|
75
|
-
arcjet(),
|
|
76
|
-
],
|
|
77
|
-
});
|
|
78
|
-
```
|
|
50
|
+
## Install
|
|
79
51
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
run:
|
|
52
|
+
This package is ESM only.
|
|
53
|
+
Install with npm and the Astro CLI in Node.js:
|
|
83
54
|
|
|
84
55
|
```sh
|
|
85
|
-
npx astro
|
|
86
|
-
```
|
|
87
|
-
|
|
88
|
-
You can now import from the `arcjet:client` module within your Astro project!
|
|
89
|
-
|
|
90
|
-
This example adds Arcjet to your middleware, but note this only works for
|
|
91
|
-
non-prerendered pages:
|
|
92
|
-
|
|
93
|
-
```ts
|
|
94
|
-
// src/middleware.ts
|
|
95
|
-
import { defineMiddleware } from "astro:middleware";
|
|
96
|
-
import aj from "arcjet:client";
|
|
97
|
-
|
|
98
|
-
export const onRequest = defineMiddleware(
|
|
99
|
-
async ({ isPrerendered, request }, next) => {
|
|
100
|
-
// Arcjet can be run in your middleware; however, Arcjet can only process a
|
|
101
|
-
// request when the page is NOT prerendered.
|
|
102
|
-
if (!isPrerendered) {
|
|
103
|
-
// console.log(request);
|
|
104
|
-
const decision = await aj.protect(request);
|
|
105
|
-
|
|
106
|
-
// Deny decisions respond immediately to avoid any additional server
|
|
107
|
-
// processing.
|
|
108
|
-
if (decision.isDenied()) {
|
|
109
|
-
return new Response(null, { status: 403, statusText: "Forbidden" });
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
return next();
|
|
114
|
-
},
|
|
115
|
-
);
|
|
116
|
-
```
|
|
117
|
-
|
|
118
|
-
## Rate limit + bot detection example
|
|
119
|
-
|
|
120
|
-
The [Arcjet rate limit][rate-limit-concepts-docs] example below applies a token
|
|
121
|
-
bucket rate limit rule to a route where we identify the user based on their ID
|
|
122
|
-
e.g. if they are logged in. The bucket is configured with a maximum capacity of
|
|
123
|
-
10 tokens and refills by 5 tokens every 10 seconds. Each request consumes 5
|
|
124
|
-
tokens.
|
|
125
|
-
|
|
126
|
-
The rule is defined in your `astro.config.mjs` file:
|
|
127
|
-
|
|
128
|
-
```js
|
|
129
|
-
// @ts-check
|
|
130
|
-
import { defineConfig } from "astro/config";
|
|
131
|
-
import arcjet, { tokenBucket, detectBot } from "@arcjet/astro";
|
|
132
|
-
|
|
133
|
-
// https://astro.build/config
|
|
134
|
-
export default defineConfig({
|
|
135
|
-
env: {
|
|
136
|
-
validateSecrets: true,
|
|
137
|
-
},
|
|
138
|
-
integrations: [
|
|
139
|
-
arcjet({
|
|
140
|
-
characteristics: ["userId"], // track requests by a custom user ID
|
|
141
|
-
rules: [
|
|
142
|
-
// Create a token bucket rate limit. Other algorithms are supported.
|
|
143
|
-
tokenBucket({
|
|
144
|
-
mode: "LIVE", // will block requests. Use "DRY_RUN" to log only
|
|
145
|
-
refillRate: 5, // refill 5 tokens per interval
|
|
146
|
-
interval: 10, // refill every 10 seconds
|
|
147
|
-
capacity: 10, // bucket maximum capacity of 10 tokens
|
|
148
|
-
}),
|
|
149
|
-
detectBot({
|
|
150
|
-
mode: "LIVE", // will block requests. Use "DRY_RUN" to log only
|
|
151
|
-
// configured with a list of bots to allow from
|
|
152
|
-
// https://arcjet.com/bot-list
|
|
153
|
-
allow: [], // "allow none" will block all detected bots
|
|
154
|
-
}),
|
|
155
|
-
],
|
|
156
|
-
}),
|
|
157
|
-
],
|
|
158
|
-
});
|
|
159
|
-
```
|
|
160
|
-
|
|
161
|
-
Then Arcjet is called from within this page route:
|
|
162
|
-
|
|
163
|
-
```ts
|
|
164
|
-
// src/pages/api.json.ts
|
|
165
|
-
import type { APIRoute } from "astro";
|
|
166
|
-
import aj from "arcjet:client";
|
|
167
|
-
|
|
168
|
-
export const GET: APIRoute = async ({ request }) => {
|
|
169
|
-
const userId = "user123"; // Replace with your authenticated user ID
|
|
170
|
-
const decision = await aj.protect(request, { userId, requested: 5 }); // Deduct 5 tokens from the bucket
|
|
171
|
-
console.log("Arcjet decision", decision);
|
|
172
|
-
|
|
173
|
-
if (decision.isDenied()) {
|
|
174
|
-
return Response.json({ error: "Forbidden" }, { status: 403 });
|
|
175
|
-
} else {
|
|
176
|
-
return Response.json({ message: "Hello world" });
|
|
177
|
-
}
|
|
178
|
-
};
|
|
56
|
+
npx astro add @arcjet/astro
|
|
179
57
|
```
|
|
180
58
|
|
|
181
|
-
##
|
|
182
|
-
|
|
183
|
-
[Arcjet Shield][shield-concepts-docs] protects your application against common
|
|
184
|
-
attacks, including the OWASP Top 10. You can run Shield on every request with
|
|
185
|
-
negligible performance impact.
|
|
59
|
+
## Use
|
|
186
60
|
|
|
187
|
-
|
|
61
|
+
Configure Arcjet in `astro.config.mjs`:
|
|
188
62
|
|
|
189
63
|
```js
|
|
190
|
-
// @ts-check
|
|
191
|
-
import { defineConfig } from "astro/config";
|
|
192
64
|
import arcjet, { shield } from "@arcjet/astro";
|
|
65
|
+
import { defineConfig } from "astro/config";
|
|
193
66
|
|
|
194
|
-
// https://astro.build/config
|
|
195
67
|
export default defineConfig({
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
},
|
|
68
|
+
// We recommend setting
|
|
69
|
+
// [`validateSecrets`](https://docs.astro.build/en/reference/configuration-reference/#envvalidatesecrets).
|
|
70
|
+
env: { validateSecrets: true },
|
|
199
71
|
integrations: [
|
|
200
72
|
arcjet({
|
|
201
73
|
rules: [
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
}),
|
|
74
|
+
// Shield protects your app from common attacks.
|
|
75
|
+
// Use `DRY_RUN` instead of `LIVE` to only log.
|
|
76
|
+
shield({ mode: "LIVE" }),
|
|
205
77
|
],
|
|
206
78
|
}),
|
|
207
79
|
],
|
|
208
80
|
});
|
|
209
81
|
```
|
|
210
82
|
|
|
211
|
-
|
|
83
|
+
…then use Arcjet in on-demand routes (such as `src/pages/api.json.ts`):
|
|
212
84
|
|
|
213
85
|
```ts
|
|
214
|
-
// src/pages/api.json.ts
|
|
215
86
|
import type { APIRoute } from "astro";
|
|
216
87
|
import aj from "arcjet:client";
|
|
217
88
|
|
|
@@ -219,22 +90,25 @@ export const GET: APIRoute = async ({ request }) => {
|
|
|
219
90
|
const decision = await aj.protect(request);
|
|
220
91
|
|
|
221
92
|
if (decision.isDenied()) {
|
|
222
|
-
return Response.json({
|
|
223
|
-
} else {
|
|
224
|
-
return Response.json({ message: "Hello world" });
|
|
93
|
+
return Response.json({ message: "Forbidden" }, { status: 403 });
|
|
225
94
|
}
|
|
95
|
+
|
|
96
|
+
return Response.json({ message: "Hello world" });
|
|
226
97
|
};
|
|
227
98
|
```
|
|
228
99
|
|
|
100
|
+
For more on how to configure Arcjet with Astro and how to protect Astro,
|
|
101
|
+
see the [Arcjet Astro SDK reference][arcjet-reference-astro] on our website.
|
|
102
|
+
|
|
229
103
|
## License
|
|
230
104
|
|
|
231
|
-
|
|
105
|
+
[Apache License, Version 2.0][apache-license] © [Arcjet Labs, Inc.][arcjet]
|
|
232
106
|
|
|
107
|
+
[arcjet-get-started]: https://docs.arcjet.com/get-started
|
|
108
|
+
[arcjet-reference-astro]: https://docs.arcjet.com/reference/astro
|
|
233
109
|
[arcjet]: https://arcjet.com
|
|
234
110
|
[astro]: https://astro.build/
|
|
235
111
|
[example-url]: https://example.arcjet.com
|
|
236
112
|
[quick-start]: https://docs.arcjet.com/get-started/astro
|
|
237
113
|
[example-source]: https://github.com/arcjet/arcjet-js-example
|
|
238
|
-
[rate-limit-concepts-docs]: https://docs.arcjet.com/rate-limiting/concepts
|
|
239
|
-
[shield-concepts-docs]: https://docs.arcjet.com/shield/concepts
|
|
240
114
|
[apache-license]: http://www.apache.org/licenses/LICENSE-2.0
|
package/index.d.ts
CHANGED
|
@@ -1,75 +1,330 @@
|
|
|
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";
|
|
5
|
-
options
|
|
5
|
+
options: ShieldOptions;
|
|
6
6
|
} | {
|
|
7
7
|
type: "bot";
|
|
8
|
-
options
|
|
8
|
+
options: BotOptions;
|
|
9
9
|
} | {
|
|
10
10
|
type: "email";
|
|
11
|
-
options
|
|
11
|
+
options: EmailOptions;
|
|
12
|
+
} | {
|
|
13
|
+
type: "filter";
|
|
14
|
+
options: FilterOptions;
|
|
12
15
|
} | {
|
|
13
16
|
type: "sensitiveInfo";
|
|
14
|
-
options
|
|
17
|
+
options: SensitiveInfoOptions<undefined>;
|
|
15
18
|
} | {
|
|
16
19
|
type: "fixedWindow";
|
|
17
|
-
options
|
|
20
|
+
options: FixedWindowRateLimitOptions<Characteristics>;
|
|
18
21
|
} | {
|
|
19
22
|
type: "slidingWindow";
|
|
20
|
-
options
|
|
23
|
+
options: SlidingWindowRateLimitOptions<Characteristics>;
|
|
21
24
|
} | {
|
|
22
25
|
type: "tokenBucket";
|
|
23
|
-
options
|
|
26
|
+
options: TokenBucketRateLimitOptions<Characteristics>;
|
|
24
27
|
} | {
|
|
25
28
|
type: "protectSignup";
|
|
26
|
-
options
|
|
29
|
+
options: ProtectSignupOptions<Characteristics>;
|
|
27
30
|
};
|
|
28
|
-
|
|
31
|
+
/**
|
|
32
|
+
* Configuration for the Astro integration of Arcjet.
|
|
33
|
+
*
|
|
34
|
+
* @template Characteristics
|
|
35
|
+
* Characteristics to track a user by.
|
|
36
|
+
*/
|
|
37
|
+
export type ArcjetOptions<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
|
};
|
|
34
|
-
|
|
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
|
+
*/
|
|
77
|
+
export declare function shield(options: ShieldOptions): {
|
|
35
78
|
readonly type: "shield";
|
|
36
|
-
readonly options: ShieldOptions
|
|
79
|
+
readonly options: ShieldOptions;
|
|
37
80
|
};
|
|
38
|
-
|
|
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
|
+
*/
|
|
101
|
+
export declare function detectBot(options: BotOptions): {
|
|
39
102
|
readonly type: "bot";
|
|
40
|
-
readonly options: BotOptions
|
|
103
|
+
readonly options: BotOptions;
|
|
41
104
|
};
|
|
42
|
-
|
|
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
|
+
*/
|
|
122
|
+
export declare function validateEmail(options: EmailOptions): {
|
|
43
123
|
readonly type: "email";
|
|
44
|
-
readonly options: EmailOptions
|
|
124
|
+
readonly options: EmailOptions;
|
|
125
|
+
};
|
|
126
|
+
/**
|
|
127
|
+
* Arcjet filter rule.
|
|
128
|
+
*
|
|
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.
|
|
137
|
+
*
|
|
138
|
+
* @param options
|
|
139
|
+
* Configuration (required).
|
|
140
|
+
* @returns
|
|
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
|
|
157
|
+
*/
|
|
158
|
+
export declare function filter(options: FilterOptions): {
|
|
159
|
+
readonly type: "filter";
|
|
160
|
+
readonly options: FilterOptions;
|
|
45
161
|
};
|
|
46
|
-
|
|
162
|
+
/**
|
|
163
|
+
* Arcjet sensitive information detection rule.
|
|
164
|
+
*
|
|
165
|
+
* Applying this rule protects against clients sending you sensitive information
|
|
166
|
+
* such as personally identifiable information (PII) that you do not wish to
|
|
167
|
+
* handle.
|
|
168
|
+
* The rule runs entirely locally so no data ever leaves your environment.
|
|
169
|
+
*
|
|
170
|
+
* This rule includes built-in detections for email addresses, credit/debit card
|
|
171
|
+
* numbers, IP addresses, and phone numbers.
|
|
172
|
+
* You can also provide a custom detection function to identify additional
|
|
173
|
+
* sensitive information.
|
|
174
|
+
*
|
|
175
|
+
* @param options
|
|
176
|
+
* Configuration for the sensitive information detection rule (required).
|
|
177
|
+
* @returns
|
|
178
|
+
* Astro integration Sensitive information rule to provide to the SDK in the `rules` field.
|
|
179
|
+
*/
|
|
180
|
+
export declare function sensitiveInfo(options: SensitiveInfoOptions<never>): {
|
|
47
181
|
readonly type: "sensitiveInfo";
|
|
48
|
-
readonly options: SensitiveInfoOptions<never
|
|
182
|
+
readonly options: SensitiveInfoOptions<never>;
|
|
49
183
|
};
|
|
50
|
-
|
|
184
|
+
/**
|
|
185
|
+
* Arcjet fixed window rate limiting rule.
|
|
186
|
+
*
|
|
187
|
+
* Applying this rule sets a fixed window rate limit which tracks the number of
|
|
188
|
+
* requests made by a client over a fixed time window.
|
|
189
|
+
*
|
|
190
|
+
* This is the simplest algorithm.
|
|
191
|
+
* It tracks the number of requests made by a client over a fixed time window
|
|
192
|
+
* such as 60 seconds.
|
|
193
|
+
* If the client exceeds the limit, they are blocked until the window expires.
|
|
194
|
+
*
|
|
195
|
+
* This algorithm is useful when you want to apply a simple fixed limit in a
|
|
196
|
+
* fixed time window.
|
|
197
|
+
* For example, a simple limit on the total number of requests a client can make.
|
|
198
|
+
* However, it can be susceptible to the stampede problem where a client makes
|
|
199
|
+
* a burst of requests at the start of a window and then is blocked for the rest
|
|
200
|
+
* of the window.
|
|
201
|
+
* The sliding window algorithm can be used to avoid this.
|
|
202
|
+
*
|
|
203
|
+
* @template Characteristics
|
|
204
|
+
* Characteristics to track a user by.
|
|
205
|
+
* @param options
|
|
206
|
+
* Configuration for the fixed window rate limiting rule (required).
|
|
207
|
+
* @returns
|
|
208
|
+
* Astro integration Fixed window rule to provide to the SDK in the `rules` field.
|
|
209
|
+
*/
|
|
210
|
+
export declare function fixedWindow<Characteristics extends readonly string[]>(options: FixedWindowRateLimitOptions<Characteristics>): {
|
|
51
211
|
readonly type: "fixedWindow";
|
|
52
|
-
readonly options: FixedWindowRateLimitOptions<Characteristics
|
|
212
|
+
readonly options: FixedWindowRateLimitOptions<Characteristics>;
|
|
53
213
|
};
|
|
54
|
-
|
|
214
|
+
/**
|
|
215
|
+
* Arcjet sliding window rate limiting rule.
|
|
216
|
+
*
|
|
217
|
+
* Applying this rule sets a sliding window rate limit which tracks the number
|
|
218
|
+
* of requests made by a client over a sliding window so that the window moves
|
|
219
|
+
* with time.
|
|
220
|
+
*
|
|
221
|
+
* This algorithm is useful to avoid the stampede problem of the fixed window.
|
|
222
|
+
* It provides smoother rate limiting over time and can prevent a client from
|
|
223
|
+
* making a burst of requests at the start of a window and then being blocked
|
|
224
|
+
* for the rest of the window.
|
|
225
|
+
*
|
|
226
|
+
* @template Characteristics
|
|
227
|
+
* Characteristics to track a user by.
|
|
228
|
+
* @param options
|
|
229
|
+
* Configuration for the sliding window rate limiting rule (required).
|
|
230
|
+
* @returns
|
|
231
|
+
* Astro integration Sliding window rule to provide to the SDK in the `rules` field.
|
|
232
|
+
*/
|
|
233
|
+
export declare function slidingWindow<Characteristics extends readonly string[]>(options: SlidingWindowRateLimitOptions<Characteristics>): {
|
|
55
234
|
readonly type: "slidingWindow";
|
|
56
|
-
readonly options: SlidingWindowRateLimitOptions<Characteristics
|
|
235
|
+
readonly options: SlidingWindowRateLimitOptions<Characteristics>;
|
|
57
236
|
};
|
|
58
|
-
|
|
237
|
+
/**
|
|
238
|
+
* Arcjet token bucket rate limiting rule.
|
|
239
|
+
*
|
|
240
|
+
* Applying this rule sets a token bucket rate limit.
|
|
241
|
+
*
|
|
242
|
+
* This algorithm is based on a bucket filled with a specific number of tokens.
|
|
243
|
+
* Each request withdraws some amount of tokens from the bucket and the bucket
|
|
244
|
+
* is refilled at a fixed rate.
|
|
245
|
+
* Once the bucket is empty, the client is blocked until the bucket refills.
|
|
246
|
+
*
|
|
247
|
+
* This algorithm is useful when you want to allow clients to make a burst of
|
|
248
|
+
* requests and then still be able to make requests at a slower rate.
|
|
249
|
+
*
|
|
250
|
+
* @template Characteristics
|
|
251
|
+
* Characteristics to track a user by.
|
|
252
|
+
* @param options
|
|
253
|
+
* Configuration for the token bucket rate limiting rule (required).
|
|
254
|
+
* @returns
|
|
255
|
+
* Astro integration Token bucket rule to provide to the SDK in the `rules` field.
|
|
256
|
+
*/
|
|
257
|
+
export declare function tokenBucket<Characteristics extends readonly string[]>(options: TokenBucketRateLimitOptions<Characteristics>): {
|
|
59
258
|
readonly type: "tokenBucket";
|
|
60
|
-
readonly options: TokenBucketRateLimitOptions<Characteristics
|
|
259
|
+
readonly options: TokenBucketRateLimitOptions<Characteristics>;
|
|
61
260
|
};
|
|
62
|
-
|
|
261
|
+
/**
|
|
262
|
+
* Arcjet signup form protection rule.
|
|
263
|
+
*
|
|
264
|
+
* Applying this rule combines rate limiting, bot protection, and email
|
|
265
|
+
* validation to protect your signup forms from abuse.
|
|
266
|
+
* Using this rule will configure the following:
|
|
267
|
+
*
|
|
268
|
+
* - Rate limiting - signup forms are a common target for bots. Arcjet’s rate
|
|
269
|
+
* limiting helps to prevent bots and other automated or malicious clients
|
|
270
|
+
* from submitting your signup form too many times in a short period of time.
|
|
271
|
+
* - Bot protection - signup forms are usually exclusively used by humans, which
|
|
272
|
+
* means that any automated submissions to the form are likely to be
|
|
273
|
+
* fraudulent.
|
|
274
|
+
* - Email validation - email addresses should be validated to ensure the signup
|
|
275
|
+
* is coming from a legitimate user with a real email address that can
|
|
276
|
+
* actually receive messages.
|
|
277
|
+
*
|
|
278
|
+
* @template Characteristics
|
|
279
|
+
* Characteristics to track a user by.
|
|
280
|
+
* @param options
|
|
281
|
+
* Configuration for the signup form protection rule.
|
|
282
|
+
* @returns
|
|
283
|
+
* Astro integration Signup form protection rule to provide to the SDK in the `rules` field.
|
|
284
|
+
*/
|
|
285
|
+
export declare function protectSignup<Characteristics extends readonly string[]>(options: ProtectSignupOptions<Characteristics>): {
|
|
63
286
|
readonly type: "protectSignup";
|
|
64
|
-
readonly options: ProtectSignupOptions<Characteristics
|
|
287
|
+
readonly options: ProtectSignupOptions<Characteristics>;
|
|
65
288
|
};
|
|
289
|
+
/**
|
|
290
|
+
* Configuration for {@linkcode createRemoteClient}.
|
|
291
|
+
*/
|
|
66
292
|
export type RemoteClientOptions = {
|
|
67
|
-
|
|
68
|
-
|
|
293
|
+
/**
|
|
294
|
+
* Base URI for HTTP requests to Decide API (optional).
|
|
295
|
+
*
|
|
296
|
+
* Defaults to the environment variable `ARCJET_BASE_URL` (if that value
|
|
297
|
+
* is known and allowed) and the standard production API otherwise.
|
|
298
|
+
*/
|
|
299
|
+
baseUrl?: string | undefined;
|
|
300
|
+
/**
|
|
301
|
+
* Timeout in milliseconds for the Decide API (optional).
|
|
302
|
+
*
|
|
303
|
+
* Defaults to `500` in production and `1000` in development.
|
|
304
|
+
*/
|
|
305
|
+
timeout?: number | undefined;
|
|
69
306
|
};
|
|
70
|
-
|
|
307
|
+
/**
|
|
308
|
+
* Create a remote client.
|
|
309
|
+
*
|
|
310
|
+
* @param options
|
|
311
|
+
* Configuration (optional).
|
|
312
|
+
* @returns
|
|
313
|
+
* Client.
|
|
314
|
+
*/
|
|
315
|
+
export declare function createRemoteClient(options?: RemoteClientOptions | undefined): {
|
|
71
316
|
readonly baseUrl: string | undefined;
|
|
72
317
|
readonly timeout: number | undefined;
|
|
73
318
|
};
|
|
74
|
-
|
|
319
|
+
/**
|
|
320
|
+
* Create a new Astro integration of Arcjet.
|
|
321
|
+
*
|
|
322
|
+
* @template Characteristics
|
|
323
|
+
* Characteristics to track a user by.
|
|
324
|
+
* @param options
|
|
325
|
+
* Configuration.
|
|
326
|
+
* @returns
|
|
327
|
+
* Astro integration of Arcjet.
|
|
328
|
+
*/
|
|
329
|
+
export default function arcjet<Characteristics extends readonly string[]>(options?: ArcjetOptions<Characteristics>): AstroIntegration;
|
|
75
330
|
export {};
|