@netlify/cache 1.11.1 → 2.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/dist/bootstrap/main.cjs +22 -4
- package/dist/bootstrap/main.d.cts +2 -2
- package/dist/bootstrap/main.d.ts +2 -2
- package/dist/bootstrap/main.js +22 -4
- package/dist/{cache-Boq7iRAh.d.cts → cache-B9TsVKLp.d.cts} +4 -2
- package/dist/{cache-Boq7iRAh.d.ts → cache-B9TsVKLp.d.ts} +4 -2
- package/dist/main.cjs +14 -16
- package/dist/main.d.cts +1 -1
- package/dist/main.d.ts +1 -1
- package/dist/main.js +14 -16
- package/package.json +7 -9
package/dist/bootstrap/main.cjs
CHANGED
|
@@ -68,8 +68,10 @@ var UserAgent = "user-agent";
|
|
|
68
68
|
// src/bootstrap/cache.ts
|
|
69
69
|
var allowedProtocols = /* @__PURE__ */ new Set(["http:", "https:"]);
|
|
70
70
|
var discardedHeaders = /* @__PURE__ */ new Set(["cookie", "content-encoding", "content-length"]);
|
|
71
|
+
var forbiddenHeaderPrefixes = ["netlify-programmable-", "x-nf-"];
|
|
71
72
|
var getInternalHeaders = Symbol("getInternalHeaders");
|
|
72
|
-
var
|
|
73
|
+
var serializeRequestHeaders = Symbol("serializeRequestHeaders");
|
|
74
|
+
var serializeResponseHeaders = Symbol("serializeResponseHeaders");
|
|
73
75
|
var _getContext, _name, _userAgent;
|
|
74
76
|
var NetlifyCache = class {
|
|
75
77
|
constructor({ getContext, name, userAgent }) {
|
|
@@ -94,7 +96,20 @@ var NetlifyCache = class {
|
|
|
94
96
|
}
|
|
95
97
|
return headers;
|
|
96
98
|
}
|
|
97
|
-
[
|
|
99
|
+
[serializeRequestHeaders](headers) {
|
|
100
|
+
const headersMap = {};
|
|
101
|
+
headers.forEach((value, key) => {
|
|
102
|
+
const normalizedKey = key.toLowerCase();
|
|
103
|
+
for (const prefix of forbiddenHeaderPrefixes) {
|
|
104
|
+
if (normalizedKey.startsWith(prefix)) {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
headersMap[normalizedKey] = value;
|
|
109
|
+
});
|
|
110
|
+
return headersMap;
|
|
111
|
+
}
|
|
112
|
+
[serializeResponseHeaders](headers) {
|
|
98
113
|
const headersMap = {};
|
|
99
114
|
headers.forEach((value, key) => {
|
|
100
115
|
if (discardedHeaders.has(key)) {
|
|
@@ -140,7 +155,10 @@ var NetlifyCache = class {
|
|
|
140
155
|
const resourceURL = extractAndValidateURL(request);
|
|
141
156
|
const cacheURL = `${context.url}/${toCacheKey(resourceURL)}`;
|
|
142
157
|
const response = await fetch(cacheURL, {
|
|
143
|
-
headers:
|
|
158
|
+
headers: {
|
|
159
|
+
...request instanceof Request ? this[serializeRequestHeaders](request.headers) : {},
|
|
160
|
+
...this[getInternalHeaders](context)
|
|
161
|
+
},
|
|
144
162
|
method: "GET"
|
|
145
163
|
});
|
|
146
164
|
if (!response.ok) {
|
|
@@ -180,7 +198,7 @@ var NetlifyCache = class {
|
|
|
180
198
|
body: response.body,
|
|
181
199
|
headers: {
|
|
182
200
|
...this[getInternalHeaders](context),
|
|
183
|
-
[ResourceHeaders]: this[
|
|
201
|
+
[ResourceHeaders]: this[serializeResponseHeaders](response.headers),
|
|
184
202
|
[ResourceStatus]: response.status.toString()
|
|
185
203
|
},
|
|
186
204
|
// @ts-expect-error https://github.com/whatwg/fetch/pull/1457
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { E as EnvironmentOptions } from '../cache-
|
|
2
|
-
export { N as NetlifyCache, O as Operation, R as RequestContextFactory } from '../cache-
|
|
1
|
+
import { E as EnvironmentOptions } from '../cache-B9TsVKLp.cjs';
|
|
2
|
+
export { N as NetlifyCache, O as Operation, R as RequestContextFactory } from '../cache-B9TsVKLp.cjs';
|
|
3
3
|
|
|
4
4
|
declare class NetlifyCacheStorage {
|
|
5
5
|
#private;
|
package/dist/bootstrap/main.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { E as EnvironmentOptions } from '../cache-
|
|
2
|
-
export { N as NetlifyCache, O as Operation, R as RequestContextFactory } from '../cache-
|
|
1
|
+
import { E as EnvironmentOptions } from '../cache-B9TsVKLp.js';
|
|
2
|
+
export { N as NetlifyCache, O as Operation, R as RequestContextFactory } from '../cache-B9TsVKLp.js';
|
|
3
3
|
|
|
4
4
|
declare class NetlifyCacheStorage {
|
|
5
5
|
#private;
|
package/dist/bootstrap/main.js
CHANGED
|
@@ -41,8 +41,10 @@ var UserAgent = "user-agent";
|
|
|
41
41
|
// src/bootstrap/cache.ts
|
|
42
42
|
var allowedProtocols = /* @__PURE__ */ new Set(["http:", "https:"]);
|
|
43
43
|
var discardedHeaders = /* @__PURE__ */ new Set(["cookie", "content-encoding", "content-length"]);
|
|
44
|
+
var forbiddenHeaderPrefixes = ["netlify-programmable-", "x-nf-"];
|
|
44
45
|
var getInternalHeaders = Symbol("getInternalHeaders");
|
|
45
|
-
var
|
|
46
|
+
var serializeRequestHeaders = Symbol("serializeRequestHeaders");
|
|
47
|
+
var serializeResponseHeaders = Symbol("serializeResponseHeaders");
|
|
46
48
|
var _getContext, _name, _userAgent;
|
|
47
49
|
var NetlifyCache = class {
|
|
48
50
|
constructor({ getContext, name, userAgent }) {
|
|
@@ -67,7 +69,20 @@ var NetlifyCache = class {
|
|
|
67
69
|
}
|
|
68
70
|
return headers;
|
|
69
71
|
}
|
|
70
|
-
[
|
|
72
|
+
[serializeRequestHeaders](headers) {
|
|
73
|
+
const headersMap = {};
|
|
74
|
+
headers.forEach((value, key) => {
|
|
75
|
+
const normalizedKey = key.toLowerCase();
|
|
76
|
+
for (const prefix of forbiddenHeaderPrefixes) {
|
|
77
|
+
if (normalizedKey.startsWith(prefix)) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
headersMap[normalizedKey] = value;
|
|
82
|
+
});
|
|
83
|
+
return headersMap;
|
|
84
|
+
}
|
|
85
|
+
[serializeResponseHeaders](headers) {
|
|
71
86
|
const headersMap = {};
|
|
72
87
|
headers.forEach((value, key) => {
|
|
73
88
|
if (discardedHeaders.has(key)) {
|
|
@@ -113,7 +128,10 @@ var NetlifyCache = class {
|
|
|
113
128
|
const resourceURL = extractAndValidateURL(request);
|
|
114
129
|
const cacheURL = `${context.url}/${toCacheKey(resourceURL)}`;
|
|
115
130
|
const response = await fetch(cacheURL, {
|
|
116
|
-
headers:
|
|
131
|
+
headers: {
|
|
132
|
+
...request instanceof Request ? this[serializeRequestHeaders](request.headers) : {},
|
|
133
|
+
...this[getInternalHeaders](context)
|
|
134
|
+
},
|
|
117
135
|
method: "GET"
|
|
118
136
|
});
|
|
119
137
|
if (!response.ok) {
|
|
@@ -153,7 +171,7 @@ var NetlifyCache = class {
|
|
|
153
171
|
body: response.body,
|
|
154
172
|
headers: {
|
|
155
173
|
...this[getInternalHeaders](context),
|
|
156
|
-
[ResourceHeaders]: this[
|
|
174
|
+
[ResourceHeaders]: this[serializeResponseHeaders](response.headers),
|
|
157
175
|
[ResourceStatus]: response.status.toString()
|
|
158
176
|
},
|
|
159
177
|
// @ts-expect-error https://github.com/whatwg/fetch/pull/1457
|
|
@@ -22,12 +22,14 @@ type NetlifyCacheOptions = EnvironmentOptions & {
|
|
|
22
22
|
name: string;
|
|
23
23
|
};
|
|
24
24
|
declare const getInternalHeaders: unique symbol;
|
|
25
|
-
declare const
|
|
25
|
+
declare const serializeRequestHeaders: unique symbol;
|
|
26
|
+
declare const serializeResponseHeaders: unique symbol;
|
|
26
27
|
declare class NetlifyCache implements Cache {
|
|
27
28
|
#private;
|
|
28
29
|
constructor({ getContext, name, userAgent }: NetlifyCacheOptions);
|
|
29
30
|
private [getInternalHeaders];
|
|
30
|
-
private [
|
|
31
|
+
private [serializeRequestHeaders];
|
|
32
|
+
private [serializeResponseHeaders];
|
|
31
33
|
add(request: RequestInfo | URL): Promise<void>;
|
|
32
34
|
addAll(requests: RequestInfo[]): Promise<void>;
|
|
33
35
|
delete(request: RequestInfo | URL): Promise<boolean>;
|
|
@@ -22,12 +22,14 @@ type NetlifyCacheOptions = EnvironmentOptions & {
|
|
|
22
22
|
name: string;
|
|
23
23
|
};
|
|
24
24
|
declare const getInternalHeaders: unique symbol;
|
|
25
|
-
declare const
|
|
25
|
+
declare const serializeRequestHeaders: unique symbol;
|
|
26
|
+
declare const serializeResponseHeaders: unique symbol;
|
|
26
27
|
declare class NetlifyCache implements Cache {
|
|
27
28
|
#private;
|
|
28
29
|
constructor({ getContext, name, userAgent }: NetlifyCacheOptions);
|
|
29
30
|
private [getInternalHeaders];
|
|
30
|
-
private [
|
|
31
|
+
private [serializeRequestHeaders];
|
|
32
|
+
private [serializeResponseHeaders];
|
|
31
33
|
add(request: RequestInfo | URL): Promise<void>;
|
|
32
34
|
addAll(requests: RequestInfo[]): Promise<void>;
|
|
33
35
|
delete(request: RequestInfo | URL): Promise<boolean>;
|
package/dist/main.cjs
CHANGED
|
@@ -210,13 +210,16 @@ var parseCacheStatusValue = (value) => {
|
|
|
210
210
|
const parts = value.split(";").map((part) => part.trim());
|
|
211
211
|
const [namePart, ...attributeParts] = parts;
|
|
212
212
|
const name = (namePart ?? "").replace(/"/g, "").toLowerCase();
|
|
213
|
-
const attributes = attributeParts.reduce(
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
213
|
+
const attributes = attributeParts.reduce(
|
|
214
|
+
(acc, part) => {
|
|
215
|
+
const [key, value2 = ""] = part.split("=");
|
|
216
|
+
return {
|
|
217
|
+
...acc,
|
|
218
|
+
[key]: value2
|
|
219
|
+
};
|
|
220
|
+
},
|
|
221
|
+
{}
|
|
222
|
+
);
|
|
220
223
|
return {
|
|
221
224
|
attributes,
|
|
222
225
|
name
|
|
@@ -303,7 +306,7 @@ var isRequestInit = (input) => {
|
|
|
303
306
|
}
|
|
304
307
|
return false;
|
|
305
308
|
};
|
|
306
|
-
var fetchWithCache = async (
|
|
309
|
+
var fetchWithCache = async (requestOrURL, optionsOrCacheSettings, cacheOptionsParam) => {
|
|
307
310
|
let cacheOptions;
|
|
308
311
|
let requestInit;
|
|
309
312
|
if (isRequestInit(optionsOrCacheSettings)) {
|
|
@@ -313,13 +316,8 @@ var fetchWithCache = async (request, optionsOrCacheSettings, cacheOptionsParam)
|
|
|
313
316
|
cacheOptions = optionsOrCacheSettings || {};
|
|
314
317
|
requestInit = {};
|
|
315
318
|
}
|
|
316
|
-
|
|
317
|
-
if (request
|
|
318
|
-
method = request.method;
|
|
319
|
-
} else {
|
|
320
|
-
method = requestInit?.method;
|
|
321
|
-
}
|
|
322
|
-
if (method && method?.toLowerCase() !== "get") {
|
|
319
|
+
const request = new Request(requestOrURL, requestInit);
|
|
320
|
+
if (request.method.toLowerCase() !== "get") {
|
|
323
321
|
throw new TypeError("`fetchWithCache` only supports GET requests.");
|
|
324
322
|
}
|
|
325
323
|
let cache;
|
|
@@ -339,7 +337,7 @@ var fetchWithCache = async (request, optionsOrCacheSettings, cacheOptionsParam)
|
|
|
339
337
|
if (cached) {
|
|
340
338
|
return cached;
|
|
341
339
|
}
|
|
342
|
-
const fresh = await fetch(request
|
|
340
|
+
const fresh = await fetch(request);
|
|
343
341
|
if (!fresh.body) {
|
|
344
342
|
return fresh;
|
|
345
343
|
}
|
package/dist/main.d.cts
CHANGED
package/dist/main.d.ts
CHANGED
package/dist/main.js
CHANGED
|
@@ -176,13 +176,16 @@ var parseCacheStatusValue = (value) => {
|
|
|
176
176
|
const parts = value.split(";").map((part) => part.trim());
|
|
177
177
|
const [namePart, ...attributeParts] = parts;
|
|
178
178
|
const name = (namePart ?? "").replace(/"/g, "").toLowerCase();
|
|
179
|
-
const attributes = attributeParts.reduce(
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
179
|
+
const attributes = attributeParts.reduce(
|
|
180
|
+
(acc, part) => {
|
|
181
|
+
const [key, value2 = ""] = part.split("=");
|
|
182
|
+
return {
|
|
183
|
+
...acc,
|
|
184
|
+
[key]: value2
|
|
185
|
+
};
|
|
186
|
+
},
|
|
187
|
+
{}
|
|
188
|
+
);
|
|
186
189
|
return {
|
|
187
190
|
attributes,
|
|
188
191
|
name
|
|
@@ -269,7 +272,7 @@ var isRequestInit = (input) => {
|
|
|
269
272
|
}
|
|
270
273
|
return false;
|
|
271
274
|
};
|
|
272
|
-
var fetchWithCache = async (
|
|
275
|
+
var fetchWithCache = async (requestOrURL, optionsOrCacheSettings, cacheOptionsParam) => {
|
|
273
276
|
let cacheOptions;
|
|
274
277
|
let requestInit;
|
|
275
278
|
if (isRequestInit(optionsOrCacheSettings)) {
|
|
@@ -279,13 +282,8 @@ var fetchWithCache = async (request, optionsOrCacheSettings, cacheOptionsParam)
|
|
|
279
282
|
cacheOptions = optionsOrCacheSettings || {};
|
|
280
283
|
requestInit = {};
|
|
281
284
|
}
|
|
282
|
-
|
|
283
|
-
if (request
|
|
284
|
-
method = request.method;
|
|
285
|
-
} else {
|
|
286
|
-
method = requestInit?.method;
|
|
287
|
-
}
|
|
288
|
-
if (method && method?.toLowerCase() !== "get") {
|
|
285
|
+
const request = new Request(requestOrURL, requestInit);
|
|
286
|
+
if (request.method.toLowerCase() !== "get") {
|
|
289
287
|
throw new TypeError("`fetchWithCache` only supports GET requests.");
|
|
290
288
|
}
|
|
291
289
|
let cache;
|
|
@@ -305,7 +303,7 @@ var fetchWithCache = async (request, optionsOrCacheSettings, cacheOptionsParam)
|
|
|
305
303
|
if (cached) {
|
|
306
304
|
return cached;
|
|
307
305
|
}
|
|
308
|
-
const fresh = await fetch(request
|
|
306
|
+
const fresh = await fetch(request);
|
|
309
307
|
if (!fresh.body) {
|
|
310
308
|
return fresh;
|
|
311
309
|
}
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@netlify/cache",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "TypeScript utilities for interacting with the Netlify cache",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
7
|
-
"node": "^14.
|
|
7
|
+
"node": "^18.14.0 || >=20"
|
|
8
8
|
},
|
|
9
9
|
"main": "./dist/main.cjs",
|
|
10
10
|
"module": "./dist/main.js",
|
|
@@ -47,10 +47,10 @@
|
|
|
47
47
|
"build": "tsup-node",
|
|
48
48
|
"dev": "tsup-node --watch",
|
|
49
49
|
"prepack": "npm run build",
|
|
50
|
-
"test": "run-s build test:
|
|
50
|
+
"test": "run-s build test:ci",
|
|
51
51
|
"test:dev": "run-s build test:dev:*",
|
|
52
52
|
"test:ci": "run-s build test:ci:*",
|
|
53
|
-
"test:dev:vitest": "vitest
|
|
53
|
+
"test:dev:vitest": "vitest",
|
|
54
54
|
"test:dev:vitest:watch": "vitest watch",
|
|
55
55
|
"test:ci:vitest": "vitest run",
|
|
56
56
|
"publint": "npx -y publint --strict"
|
|
@@ -68,15 +68,13 @@
|
|
|
68
68
|
},
|
|
69
69
|
"author": "Netlify Inc.",
|
|
70
70
|
"devDependencies": {
|
|
71
|
-
"@netlify/dev-utils": "
|
|
72
|
-
"@netlify/types": "
|
|
71
|
+
"@netlify/dev-utils": "3.0.0",
|
|
72
|
+
"@netlify/types": "2.0.0",
|
|
73
73
|
"npm-run-all2": "^7.0.2",
|
|
74
|
-
"semver": "^7.5.3",
|
|
75
|
-
"tmp-promise": "^3.0.3",
|
|
76
74
|
"tsup": "^8.0.0",
|
|
77
75
|
"vitest": "^3.0.0"
|
|
78
76
|
},
|
|
79
77
|
"dependencies": {
|
|
80
|
-
"@netlify/runtime-utils": "
|
|
78
|
+
"@netlify/runtime-utils": "2.0.0"
|
|
81
79
|
}
|
|
82
80
|
}
|