@arcjet/decorate 1.1.0-rc → 1.1.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/index.js +9 -9
- package/package.json +6 -6
package/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { sprintf } from '@arcjet/sprintf';
|
|
2
2
|
import '@arcjet/protocol';
|
|
3
3
|
|
|
4
4
|
function isHeaderLike(value) {
|
|
@@ -103,7 +103,7 @@ function setRateLimitHeaders(value, decision) {
|
|
|
103
103
|
typeof reason.window !== "number" ||
|
|
104
104
|
typeof reason.remaining !== "number" ||
|
|
105
105
|
typeof reason.reset !== "number") {
|
|
106
|
-
console.error(
|
|
106
|
+
console.error(sprintf("Invalid rate limit encountered: %o", reason));
|
|
107
107
|
return;
|
|
108
108
|
}
|
|
109
109
|
policies.set(reason.max, reason.window);
|
|
@@ -123,7 +123,7 @@ function setRateLimitHeaders(value, decision) {
|
|
|
123
123
|
typeof decision.reason.window !== "number" ||
|
|
124
124
|
typeof decision.reason.remaining !== "number" ||
|
|
125
125
|
typeof decision.reason.reset !== "number") {
|
|
126
|
-
console.error(
|
|
126
|
+
console.error(sprintf("Invalid rate limit encountered: %o", decision.reason));
|
|
127
127
|
return;
|
|
128
128
|
}
|
|
129
129
|
limit = toLimitString(decision.reason);
|
|
@@ -135,10 +135,10 @@ function setRateLimitHeaders(value, decision) {
|
|
|
135
135
|
}
|
|
136
136
|
if (isHeaderLike(value)) {
|
|
137
137
|
if (value.has("RateLimit")) {
|
|
138
|
-
console.warn(
|
|
138
|
+
console.warn(sprintf("Response already contains `RateLimit` header\n Original: %s\n New: %s", value.get("RateLimit"), limit));
|
|
139
139
|
}
|
|
140
140
|
if (value.has("RateLimit-Policy")) {
|
|
141
|
-
console.warn(
|
|
141
|
+
console.warn(sprintf("Response already contains `RateLimit-Policy` header\n Original: %s\n New: %s", value.get("RateLimit-Policy"), limit));
|
|
142
142
|
}
|
|
143
143
|
value.set("RateLimit", limit);
|
|
144
144
|
value.set("RateLimit-Policy", policy);
|
|
@@ -147,10 +147,10 @@ function setRateLimitHeaders(value, decision) {
|
|
|
147
147
|
}
|
|
148
148
|
if (isResponseLike(value)) {
|
|
149
149
|
if (value.headers.has("RateLimit")) {
|
|
150
|
-
console.warn(
|
|
150
|
+
console.warn(sprintf("Response already contains `RateLimit` header\n Original: %s\n New: %s", value.headers.get("RateLimit"), limit));
|
|
151
151
|
}
|
|
152
152
|
if (value.headers.has("RateLimit-Policy")) {
|
|
153
|
-
console.warn(
|
|
153
|
+
console.warn(sprintf("Response already contains `RateLimit-Policy` header\n Original: %s\n New: %s", value.headers.get("RateLimit-Policy"), limit));
|
|
154
154
|
}
|
|
155
155
|
value.headers.set("RateLimit", limit);
|
|
156
156
|
value.headers.set("RateLimit-Policy", policy);
|
|
@@ -163,10 +163,10 @@ function setRateLimitHeaders(value, decision) {
|
|
|
163
163
|
return;
|
|
164
164
|
}
|
|
165
165
|
if (value.hasHeader("RateLimit")) {
|
|
166
|
-
console.warn(
|
|
166
|
+
console.warn(sprintf("Response already contains `RateLimit` header\n Original: %s\n New: %s", value.getHeader("RateLimit"), limit));
|
|
167
167
|
}
|
|
168
168
|
if (value.hasHeader("RateLimit-Policy")) {
|
|
169
|
-
console.warn(
|
|
169
|
+
console.warn(sprintf("Response already contains `RateLimit-Policy` header\n Original: %s\n New: %s", value.getHeader("RateLimit-Policy"), limit));
|
|
170
170
|
}
|
|
171
171
|
value.setHeader("RateLimit", limit);
|
|
172
172
|
value.setHeader("RateLimit-Policy", policy);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@arcjet/decorate",
|
|
3
|
-
"version": "1.1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Arcjet utilities for decorating responses with information",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"arcjet",
|
|
@@ -42,14 +42,14 @@
|
|
|
42
42
|
"test": "npm run build && npm run lint && npm run test-coverage"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
|
-
"@arcjet/protocol": "1.1.0
|
|
46
|
-
"@arcjet/sprintf": "1.1.0
|
|
45
|
+
"@arcjet/protocol": "1.1.0",
|
|
46
|
+
"@arcjet/sprintf": "1.1.0"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
|
-
"@arcjet/eslint-config": "1.1.0
|
|
50
|
-
"@arcjet/rollup-config": "1.1.0
|
|
49
|
+
"@arcjet/eslint-config": "1.1.0",
|
|
50
|
+
"@arcjet/rollup-config": "1.1.0",
|
|
51
51
|
"@rollup/wasm-node": "4.57.0",
|
|
52
|
-
"@types/node": "25.0
|
|
52
|
+
"@types/node": "25.1.0",
|
|
53
53
|
"eslint": "9.39.2",
|
|
54
54
|
"typescript": "5.9.3"
|
|
55
55
|
},
|