@arcjet/astro 1.0.0-beta.16 → 1.0.0-beta.18
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 +1 -1
- package/internal.d.ts +16 -6
- package/internal.js +23 -31
- package/package.json +15 -14
package/index.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ type IntegrationRule<Characteristics extends readonly string[]> = {
|
|
|
14
14
|
options: FilterOptions;
|
|
15
15
|
} | {
|
|
16
16
|
type: "sensitiveInfo";
|
|
17
|
-
options: SensitiveInfoOptions<
|
|
17
|
+
options: SensitiveInfoOptions<undefined>;
|
|
18
18
|
} | {
|
|
19
19
|
type: "fixedWindow";
|
|
20
20
|
options: FixedWindowRateLimitOptions<Characteristics>;
|
package/internal.d.ts
CHANGED
|
@@ -4,12 +4,22 @@ type Simplify<T> = {
|
|
|
4
4
|
[KeyType in keyof T]: T[KeyType];
|
|
5
5
|
} & {};
|
|
6
6
|
declare const emptyObjectSymbol: unique symbol;
|
|
7
|
-
type WithoutCustomProps = {
|
|
8
|
-
[emptyObjectSymbol]?: never;
|
|
9
|
-
};
|
|
10
7
|
type PlainObject = {
|
|
11
8
|
[key: string]: unknown;
|
|
12
9
|
};
|
|
10
|
+
/**
|
|
11
|
+
* Dynamically generate whether zero or one `properties` object must or can be passed.
|
|
12
|
+
*/
|
|
13
|
+
type MaybeProperties<T> = {
|
|
14
|
+
[P in keyof T]?: T[P];
|
|
15
|
+
} extends T ? T extends {
|
|
16
|
+
[emptyObjectSymbol]?: never;
|
|
17
|
+
} ? [
|
|
18
|
+
] : [
|
|
19
|
+
properties?: T
|
|
20
|
+
] : [
|
|
21
|
+
properties: T
|
|
22
|
+
];
|
|
13
23
|
/**
|
|
14
24
|
* Configuration for {@linkcode createRemoteClient}.
|
|
15
25
|
*/
|
|
@@ -77,7 +87,7 @@ export interface ArcjetAstro<Props extends PlainObject> {
|
|
|
77
87
|
* Promise that resolves to an {@linkcode ArcjetDecision} indicating
|
|
78
88
|
* Arcjet’s decision about the request.
|
|
79
89
|
*/
|
|
80
|
-
protect(request: Request, ...props: Props
|
|
90
|
+
protect(request: Request, ...props: MaybeProperties<Props>): Promise<ArcjetDecision>;
|
|
81
91
|
/**
|
|
82
92
|
* Augment the client with another rule.
|
|
83
93
|
*
|
|
@@ -91,7 +101,7 @@ export interface ArcjetAstro<Props extends PlainObject> {
|
|
|
91
101
|
* @returns
|
|
92
102
|
* Arcjet instance augmented with the given rule.
|
|
93
103
|
*/
|
|
94
|
-
withRule<
|
|
104
|
+
withRule<ChildProperties extends PlainObject>(rule: Primitive<ChildProperties> | Product<ChildProperties>): ArcjetAstro<Props & ChildProperties>;
|
|
95
105
|
}
|
|
96
106
|
/**
|
|
97
107
|
* Create a new Astro integration of Arcjet.
|
|
@@ -105,4 +115,4 @@ export interface ArcjetAstro<Props extends PlainObject> {
|
|
|
105
115
|
* @returns
|
|
106
116
|
* Astro integration of Arcjet.
|
|
107
117
|
*/
|
|
108
|
-
export declare function createArcjetClient<const Rules extends (Primitive | Product)[], const Characteristics extends readonly string[]>(options: ArcjetOptions<Rules, Characteristics>): ArcjetAstro<
|
|
118
|
+
export declare function createArcjetClient<const Rules extends (Primitive | Product)[], const Characteristics extends readonly string[]>(options: ArcjetOptions<Rules, Characteristics>): ArcjetAstro<ExtraProps<Rules> & CharacteristicProps<Characteristics>>;
|
package/internal.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import core__default from 'arcjet';
|
|
2
2
|
export * from 'arcjet';
|
|
3
|
+
import { readBodyWeb } from '@arcjet/body';
|
|
3
4
|
import findIp, { parseProxy } from '@arcjet/ip';
|
|
4
5
|
import { ArcjetHeaders } from '@arcjet/headers';
|
|
5
6
|
import { baseUrl, isDevelopment, logLevel, platform } from '@arcjet/env';
|
|
@@ -8,6 +9,7 @@ import { createClient } from '@arcjet/protocol/client.js';
|
|
|
8
9
|
import { createTransport } from '@arcjet/transport';
|
|
9
10
|
import { VERCEL, RENDER, FLY_APP_NAME, FIREBASE_CONFIG, ARCJET_LOG_LEVEL, ARCJET_KEY, ARCJET_ENV, ARCJET_BASE_URL } from 'astro:env/server';
|
|
10
11
|
|
|
12
|
+
let warnedForAutomaticBodyRead = false;
|
|
11
13
|
// We use a middleware to store the IP address on a `Request` with this symbol.
|
|
12
14
|
// This is due to Astro inconsistently using `Symbol.for("astro.clientAddress")`
|
|
13
15
|
// to store the client address and not exporting it from their module.
|
|
@@ -24,20 +26,6 @@ const env = {
|
|
|
24
26
|
RENDER,
|
|
25
27
|
VERCEL,
|
|
26
28
|
};
|
|
27
|
-
// TODO: Deduplicate with other packages
|
|
28
|
-
function errorMessage(err) {
|
|
29
|
-
if (err) {
|
|
30
|
-
if (typeof err === "string") {
|
|
31
|
-
return err;
|
|
32
|
-
}
|
|
33
|
-
if (typeof err === "object" &&
|
|
34
|
-
"message" in err &&
|
|
35
|
-
typeof err.message === "string") {
|
|
36
|
-
return err.message;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
return "Unknown problem";
|
|
40
|
-
}
|
|
41
29
|
/**
|
|
42
30
|
* Create a remote client.
|
|
43
31
|
*
|
|
@@ -52,7 +40,7 @@ function createRemoteClient(options) {
|
|
|
52
40
|
// Transport is the HTTP client that the client uses to make requests.
|
|
53
41
|
const transport = createTransport(url);
|
|
54
42
|
const sdkStack = "ASTRO";
|
|
55
|
-
const sdkVersion = "1.0.0-beta.
|
|
43
|
+
const sdkVersion = "1.0.0-beta.18";
|
|
56
44
|
return createClient({
|
|
57
45
|
transport,
|
|
58
46
|
baseUrl: url,
|
|
@@ -91,7 +79,7 @@ function createArcjetClient(options) {
|
|
|
91
79
|
if (!clientAddress) {
|
|
92
80
|
throw new Error("`protect()` cannot be used in prerendered pages");
|
|
93
81
|
}
|
|
94
|
-
const cookies = request.headers.get("cookie") ??
|
|
82
|
+
const cookies = request.headers.get("cookie") ?? "";
|
|
95
83
|
// We construct an ArcjetHeaders to normalize over Headers
|
|
96
84
|
const headers = new ArcjetHeaders(request.headers);
|
|
97
85
|
const url = new URL(request.url);
|
|
@@ -123,31 +111,35 @@ function createArcjetClient(options) {
|
|
|
123
111
|
};
|
|
124
112
|
}
|
|
125
113
|
function withClient(aj) {
|
|
126
|
-
|
|
114
|
+
const client = {
|
|
127
115
|
withRule(rule) {
|
|
128
116
|
const client = aj.withRule(rule);
|
|
129
117
|
return withClient(client);
|
|
130
118
|
},
|
|
131
|
-
async protect(request,
|
|
132
|
-
//
|
|
133
|
-
|
|
134
|
-
// the definition of `props` in the signature but it's hard to track down
|
|
135
|
-
const req = toArcjetRequest(request, props ?? {});
|
|
119
|
+
async protect(request, props) {
|
|
120
|
+
// Cast of `{}` because here we switch from `undefined` to `Properties`.
|
|
121
|
+
const req = toArcjetRequest(request, props || {});
|
|
136
122
|
const getBody = async () => {
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
123
|
+
const clonedRequest = request.clone();
|
|
124
|
+
let expectedLength;
|
|
125
|
+
const expectedLengthString = request.headers.get("content-length");
|
|
126
|
+
if (typeof expectedLengthString === "string") {
|
|
127
|
+
expectedLength = parseInt(expectedLengthString, 10);
|
|
142
128
|
}
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
129
|
+
// HEAD and GET requests do not have a body.
|
|
130
|
+
if (!clonedRequest.body) {
|
|
131
|
+
throw new Error("Cannot read body: body is missing");
|
|
146
132
|
}
|
|
133
|
+
if (!warnedForAutomaticBodyRead) {
|
|
134
|
+
warnedForAutomaticBodyRead = true;
|
|
135
|
+
log.warn("Automatically reading the request body is deprecated; please pass an explicit `sensitiveInfoValue` field. See <https://docs.arcjet.com/upgrading/sdk-migration>.");
|
|
136
|
+
}
|
|
137
|
+
return readBodyWeb(clonedRequest.body, { expectedLength });
|
|
147
138
|
};
|
|
148
139
|
return aj.protect({ getBody }, req);
|
|
149
140
|
},
|
|
150
|
-
}
|
|
141
|
+
};
|
|
142
|
+
return Object.freeze(client);
|
|
151
143
|
}
|
|
152
144
|
const aj = core__default({ ...options, client, log });
|
|
153
145
|
return withClient(aj);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arcjet/astro",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.18",
|
|
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,27 +47,28 @@
|
|
|
47
47
|
"build": "rollup --config rollup.config.js",
|
|
48
48
|
"lint": "eslint .",
|
|
49
49
|
"prepublishOnly": "npm run build",
|
|
50
|
-
"test-api": "node --test",
|
|
51
|
-
"test-coverage": "node --experimental-test-coverage --test",
|
|
50
|
+
"test-api": "node --test -- test/*.test.js",
|
|
51
|
+
"test-coverage": "node --experimental-test-coverage --test -- test/*.test.js",
|
|
52
52
|
"test": "npm run build && npm run lint && npm run test-coverage"
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@arcjet/
|
|
56
|
-
"@arcjet/
|
|
57
|
-
"@arcjet/
|
|
58
|
-
"@arcjet/
|
|
59
|
-
"@arcjet/
|
|
60
|
-
"@arcjet/
|
|
61
|
-
"arcjet": "1.0.0-beta.
|
|
55
|
+
"@arcjet/body": "1.0.0-beta.18",
|
|
56
|
+
"@arcjet/env": "1.0.0-beta.18",
|
|
57
|
+
"@arcjet/headers": "1.0.0-beta.18",
|
|
58
|
+
"@arcjet/ip": "1.0.0-beta.18",
|
|
59
|
+
"@arcjet/logger": "1.0.0-beta.18",
|
|
60
|
+
"@arcjet/protocol": "1.0.0-beta.18",
|
|
61
|
+
"@arcjet/transport": "1.0.0-beta.18",
|
|
62
|
+
"arcjet": "1.0.0-beta.18"
|
|
62
63
|
},
|
|
63
64
|
"peerDependencies": {
|
|
64
65
|
"astro": "^5.9.3"
|
|
65
66
|
},
|
|
66
67
|
"devDependencies": {
|
|
67
|
-
"@arcjet/eslint-config": "1.0.0-beta.
|
|
68
|
-
"@arcjet/rollup-config": "1.0.0-beta.
|
|
69
|
-
"@rollup/wasm-node": "4.
|
|
70
|
-
"astro": "5.16.
|
|
68
|
+
"@arcjet/eslint-config": "1.0.0-beta.18",
|
|
69
|
+
"@arcjet/rollup-config": "1.0.0-beta.18",
|
|
70
|
+
"@rollup/wasm-node": "4.55.1",
|
|
71
|
+
"astro": "5.16.9",
|
|
71
72
|
"eslint": "9.39.2",
|
|
72
73
|
"typescript": "5.9.3"
|
|
73
74
|
},
|