@arcjet/astro 1.10.0-rc.1 → 1.10.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/dist/internal.d.ts +2 -0
- package/dist/internal.js +12 -7
- package/package.json +9 -9
package/dist/internal.d.ts
CHANGED
|
@@ -82,6 +82,8 @@ interface ArcjetAstro<Props extends PlainObject> {
|
|
|
82
82
|
* Arcjet’s decision about the request.
|
|
83
83
|
*/
|
|
84
84
|
protect(request: Request, ...props: MaybeProperties<Props & {
|
|
85
|
+
/** Application-provided client IP address, used instead of automatic detection. */
|
|
86
|
+
ipSrc?: string;
|
|
85
87
|
metadata?: ArcjetMetadata;
|
|
86
88
|
}>): Promise<ArcjetDecision>;
|
|
87
89
|
/**
|
package/dist/internal.js
CHANGED
|
@@ -10,7 +10,7 @@ import { ARCJET_BASE_URL, ARCJET_ENV, ARCJET_KEY, ARCJET_LOG_LEVEL, FIREBASE_CON
|
|
|
10
10
|
export * from "arcjet";
|
|
11
11
|
//#region src/internal.ts
|
|
12
12
|
/** SDK version. Updated by the release process. */
|
|
13
|
-
const VERSION = "1.10.0
|
|
13
|
+
const VERSION = "1.10.0";
|
|
14
14
|
let warnedForAutomaticBodyRead = false;
|
|
15
15
|
const ipSymbol = Symbol.for("arcjet.ip");
|
|
16
16
|
const env = {
|
|
@@ -60,13 +60,14 @@ function createArcjetClient(options) {
|
|
|
60
60
|
const log = options.log ? options.log : new Logger({ level: logLevel(env) });
|
|
61
61
|
const proxies = Array.isArray(options.proxies) ? parseProxies(options.proxies) : void 0;
|
|
62
62
|
if (isDevelopment(process.env)) log.warn("Arcjet will use 127.0.0.1 when missing public IP address in development mode");
|
|
63
|
-
function toArcjetRequest(request, props) {
|
|
64
|
-
const clientAddress = Reflect.get(request, ipSymbol);
|
|
65
|
-
if (!clientAddress) throw new Error("`protect()` cannot be used in prerendered pages");
|
|
63
|
+
function toArcjetRequest(request, props, ipSrc) {
|
|
64
|
+
const clientAddress = ipSrc ? void 0 : Reflect.get(request, ipSymbol);
|
|
65
|
+
if (!ipSrc && !clientAddress) throw new Error("`protect()` cannot be used in prerendered pages");
|
|
66
66
|
const cookies = request.headers.get("cookie") ?? "";
|
|
67
67
|
const headers = new ArcjetHeaders(request.headers);
|
|
68
68
|
const url = new URL(request.url);
|
|
69
|
-
|
|
69
|
+
const xArcjetIp = isDevelopment(env) ? headers.get("x-arcjet-ip") : void 0;
|
|
70
|
+
let ip = ipSrc || xArcjetIp || findIp({
|
|
70
71
|
ip: clientAddress,
|
|
71
72
|
headers
|
|
72
73
|
}, {
|
|
@@ -93,7 +94,8 @@ function createArcjetClient(options) {
|
|
|
93
94
|
return withClient(aj.withRule(rule));
|
|
94
95
|
},
|
|
95
96
|
async protect(request, props) {
|
|
96
|
-
const
|
|
97
|
+
const { ipSrc, metadata, ...properties } = props ?? {};
|
|
98
|
+
const req = toArcjetRequest(request, properties, ipSrc);
|
|
97
99
|
const getBody = async () => {
|
|
98
100
|
const clonedRequest = request.clone();
|
|
99
101
|
let expectedLength;
|
|
@@ -106,7 +108,10 @@ function createArcjetClient(options) {
|
|
|
106
108
|
}
|
|
107
109
|
return readBodyWeb(clonedRequest.body, { expectedLength });
|
|
108
110
|
};
|
|
109
|
-
return aj.protect({ getBody },
|
|
111
|
+
return aj.protect({ getBody }, {
|
|
112
|
+
...req,
|
|
113
|
+
metadata
|
|
114
|
+
});
|
|
110
115
|
}
|
|
111
116
|
});
|
|
112
117
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arcjet/astro",
|
|
3
|
-
"version": "1.10.0
|
|
3
|
+
"version": "1.10.0",
|
|
4
4
|
"description": "Arcjet runtime security SDK for Astro — bot protection, rate limiting, prompt injection detection, PII blocking, and WAF",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ai",
|
|
@@ -62,14 +62,14 @@
|
|
|
62
62
|
"test": "npm run build && npm run test-coverage"
|
|
63
63
|
},
|
|
64
64
|
"dependencies": {
|
|
65
|
-
"@arcjet/body": "1.10.0
|
|
66
|
-
"@arcjet/env": "1.10.0
|
|
67
|
-
"@arcjet/headers": "1.10.0
|
|
68
|
-
"@arcjet/ip": "1.10.0
|
|
69
|
-
"@arcjet/logger": "1.10.0
|
|
70
|
-
"@arcjet/protocol": "1.10.0
|
|
71
|
-
"@arcjet/transport": "1.10.0
|
|
72
|
-
"arcjet": "1.10.0
|
|
65
|
+
"@arcjet/body": "1.10.0",
|
|
66
|
+
"@arcjet/env": "1.10.0",
|
|
67
|
+
"@arcjet/headers": "1.10.0",
|
|
68
|
+
"@arcjet/ip": "1.10.0",
|
|
69
|
+
"@arcjet/logger": "1.10.0",
|
|
70
|
+
"@arcjet/protocol": "1.10.0",
|
|
71
|
+
"@arcjet/transport": "1.10.0",
|
|
72
|
+
"arcjet": "1.10.0"
|
|
73
73
|
},
|
|
74
74
|
"devDependencies": {
|
|
75
75
|
"astro": "7.1.0",
|