@netlify/plugin-nextjs 5.10.0-fetch-patch-logs → 5.10.1
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/build/advanced-api-routes.js +136 -4
- package/dist/build/cache.js +25 -4
- package/dist/build/content/prerendered.js +293 -11
- package/dist/build/content/server.js +219 -11
- package/dist/build/content/static.js +112 -15
- package/dist/build/functions/edge.js +540 -7
- package/dist/build/functions/server.js +130 -11
- package/dist/build/image-cdn.js +1599 -3
- package/dist/build/plugin-context.js +292 -6
- package/dist/build/verification.js +104 -9
- package/dist/esm-chunks/{package-F536DQ6H.js → package-UN6EVEHD.js} +1 -1
- package/dist/index.js +18 -39
- package/dist/run/config.js +1 -4
- package/dist/run/constants.js +7 -5
- package/dist/run/handlers/cache.cjs +44 -1655
- package/dist/run/handlers/server.js +14 -33
- package/dist/run/handlers/tracer.cjs +2 -114
- package/dist/run/handlers/tracing.js +2 -4
- package/dist/run/handlers/wait-until.cjs +2 -116
- package/dist/run/headers.js +198 -10
- package/dist/run/next.cjs +11 -1624
- package/dist/run/regional-blob-store.cjs +37 -5
- package/dist/run/revalidate.js +24 -3
- package/dist/shared/blobkey.js +15 -3
- package/package.json +1 -1
- package/dist/esm-chunks/chunk-3RQSTU2O.js +0 -554
- package/dist/esm-chunks/chunk-72ZI2IVI.js +0 -36
- package/dist/esm-chunks/chunk-AMY4NOT5.js +0 -1610
- package/dist/esm-chunks/chunk-DLVROEVU.js +0 -144
- package/dist/esm-chunks/chunk-GFYWJNQR.js +0 -305
- package/dist/esm-chunks/chunk-HXVWGXWM.js +0 -218
- package/dist/esm-chunks/chunk-IJZEDP6B.js +0 -235
- package/dist/esm-chunks/chunk-JPTD4GEB.js +0 -309
- package/dist/esm-chunks/chunk-MKMK7FBF.js +0 -132
- package/dist/esm-chunks/chunk-RYJYZQ4X.js +0 -610
- package/dist/esm-chunks/chunk-SGXRYMYQ.js +0 -127
- package/dist/esm-chunks/chunk-TYCYFZ22.js +0 -25
- package/dist/esm-chunks/chunk-UYKENJEU.js +0 -19
- package/dist/esm-chunks/chunk-WHUPSPWV.js +0 -73
- package/dist/esm-chunks/chunk-XS27YRA5.js +0 -34
- package/dist/esm-chunks/chunk-ZENB67PD.js +0 -148
- package/dist/esm-chunks/chunk-ZSVHJNNY.js +0 -120
- package/dist/esm-chunks/next-LDOXJ7XH.js +0 -567
|
@@ -1,610 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
var require = await (async () => {
|
|
3
|
-
var { createRequire } = await import("node:module");
|
|
4
|
-
return createRequire(import.meta.url);
|
|
5
|
-
})();
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
// node_modules/@netlify/blobs/dist/chunk-GUEW34CP.js
|
|
9
|
-
var NF_ERROR = "x-nf-error";
|
|
10
|
-
var NF_REQUEST_ID = "x-nf-request-id";
|
|
11
|
-
var BlobsInternalError = class extends Error {
|
|
12
|
-
constructor(res) {
|
|
13
|
-
let details = res.headers.get(NF_ERROR) || `${res.status} status code`;
|
|
14
|
-
if (res.headers.has(NF_REQUEST_ID)) {
|
|
15
|
-
details += `, ID: ${res.headers.get(NF_REQUEST_ID)}`;
|
|
16
|
-
}
|
|
17
|
-
super(`Netlify Blobs has generated an internal error (${details})`);
|
|
18
|
-
this.name = "BlobsInternalError";
|
|
19
|
-
}
|
|
20
|
-
};
|
|
21
|
-
var collectIterator = async (iterator) => {
|
|
22
|
-
const result = [];
|
|
23
|
-
for await (const item of iterator) {
|
|
24
|
-
result.push(item);
|
|
25
|
-
}
|
|
26
|
-
return result;
|
|
27
|
-
};
|
|
28
|
-
var base64Decode = (input) => {
|
|
29
|
-
const { Buffer } = globalThis;
|
|
30
|
-
if (Buffer) {
|
|
31
|
-
return Buffer.from(input, "base64").toString();
|
|
32
|
-
}
|
|
33
|
-
return atob(input);
|
|
34
|
-
};
|
|
35
|
-
var base64Encode = (input) => {
|
|
36
|
-
const { Buffer } = globalThis;
|
|
37
|
-
if (Buffer) {
|
|
38
|
-
return Buffer.from(input).toString("base64");
|
|
39
|
-
}
|
|
40
|
-
return btoa(input);
|
|
41
|
-
};
|
|
42
|
-
var getEnvironment = () => {
|
|
43
|
-
const { Deno, Netlify, process: process2 } = globalThis;
|
|
44
|
-
return Netlify?.env ?? Deno?.env ?? {
|
|
45
|
-
delete: (key) => delete process2?.env[key],
|
|
46
|
-
get: (key) => process2?.env[key],
|
|
47
|
-
has: (key) => Boolean(process2?.env[key]),
|
|
48
|
-
set: (key, value) => {
|
|
49
|
-
if (process2?.env) {
|
|
50
|
-
process2.env[key] = value;
|
|
51
|
-
}
|
|
52
|
-
},
|
|
53
|
-
toObject: () => process2?.env ?? {}
|
|
54
|
-
};
|
|
55
|
-
};
|
|
56
|
-
var getEnvironmentContext = () => {
|
|
57
|
-
const context = globalThis.netlifyBlobsContext || getEnvironment().get("NETLIFY_BLOBS_CONTEXT");
|
|
58
|
-
if (typeof context !== "string" || !context) {
|
|
59
|
-
return {};
|
|
60
|
-
}
|
|
61
|
-
const data = base64Decode(context);
|
|
62
|
-
try {
|
|
63
|
-
return JSON.parse(data);
|
|
64
|
-
} catch {
|
|
65
|
-
}
|
|
66
|
-
return {};
|
|
67
|
-
};
|
|
68
|
-
var MissingBlobsEnvironmentError = class extends Error {
|
|
69
|
-
constructor(requiredProperties) {
|
|
70
|
-
super(
|
|
71
|
-
`The environment has not been configured to use Netlify Blobs. To use it manually, supply the following properties when creating a store: ${requiredProperties.join(
|
|
72
|
-
", "
|
|
73
|
-
)}`
|
|
74
|
-
);
|
|
75
|
-
this.name = "MissingBlobsEnvironmentError";
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
var BASE64_PREFIX = "b64;";
|
|
79
|
-
var METADATA_HEADER_INTERNAL = "x-amz-meta-user";
|
|
80
|
-
var METADATA_HEADER_EXTERNAL = "netlify-blobs-metadata";
|
|
81
|
-
var METADATA_MAX_SIZE = 2 * 1024;
|
|
82
|
-
var encodeMetadata = (metadata) => {
|
|
83
|
-
if (!metadata) {
|
|
84
|
-
return null;
|
|
85
|
-
}
|
|
86
|
-
const encodedObject = base64Encode(JSON.stringify(metadata));
|
|
87
|
-
const payload = `b64;${encodedObject}`;
|
|
88
|
-
if (METADATA_HEADER_EXTERNAL.length + payload.length > METADATA_MAX_SIZE) {
|
|
89
|
-
throw new Error("Metadata object exceeds the maximum size");
|
|
90
|
-
}
|
|
91
|
-
return payload;
|
|
92
|
-
};
|
|
93
|
-
var decodeMetadata = (header) => {
|
|
94
|
-
if (!header || !header.startsWith(BASE64_PREFIX)) {
|
|
95
|
-
return {};
|
|
96
|
-
}
|
|
97
|
-
const encodedData = header.slice(BASE64_PREFIX.length);
|
|
98
|
-
const decodedData = base64Decode(encodedData);
|
|
99
|
-
const metadata = JSON.parse(decodedData);
|
|
100
|
-
return metadata;
|
|
101
|
-
};
|
|
102
|
-
var getMetadataFromResponse = (response) => {
|
|
103
|
-
if (!response.headers) {
|
|
104
|
-
return {};
|
|
105
|
-
}
|
|
106
|
-
const value = response.headers.get(METADATA_HEADER_EXTERNAL) || response.headers.get(METADATA_HEADER_INTERNAL);
|
|
107
|
-
try {
|
|
108
|
-
return decodeMetadata(value);
|
|
109
|
-
} catch {
|
|
110
|
-
throw new Error(
|
|
111
|
-
"An internal error occurred while trying to retrieve the metadata for an entry. Please try updating to the latest version of the Netlify Blobs client."
|
|
112
|
-
);
|
|
113
|
-
}
|
|
114
|
-
};
|
|
115
|
-
var BlobsConsistencyError = class extends Error {
|
|
116
|
-
constructor() {
|
|
117
|
-
super(
|
|
118
|
-
`Netlify Blobs has failed to perform a read using strong consistency because the environment has not been configured with a 'uncachedEdgeURL' property`
|
|
119
|
-
);
|
|
120
|
-
this.name = "BlobsConsistencyError";
|
|
121
|
-
}
|
|
122
|
-
};
|
|
123
|
-
var REGION_AUTO = "auto";
|
|
124
|
-
var regions = {
|
|
125
|
-
"us-east-1": true,
|
|
126
|
-
"us-east-2": true
|
|
127
|
-
};
|
|
128
|
-
var isValidRegion = (input) => Object.keys(regions).includes(input);
|
|
129
|
-
var InvalidBlobsRegionError = class extends Error {
|
|
130
|
-
constructor(region) {
|
|
131
|
-
super(
|
|
132
|
-
`${region} is not a supported Netlify Blobs region. Supported values are: ${Object.keys(regions).join(", ")}.`
|
|
133
|
-
);
|
|
134
|
-
this.name = "InvalidBlobsRegionError";
|
|
135
|
-
}
|
|
136
|
-
};
|
|
137
|
-
var DEFAULT_RETRY_DELAY = getEnvironment().get("NODE_ENV") === "test" ? 1 : 5e3;
|
|
138
|
-
var MIN_RETRY_DELAY = 1e3;
|
|
139
|
-
var MAX_RETRY = 5;
|
|
140
|
-
var RATE_LIMIT_HEADER = "X-RateLimit-Reset";
|
|
141
|
-
var fetchAndRetry = async (fetch, url, options, attemptsLeft = MAX_RETRY) => {
|
|
142
|
-
try {
|
|
143
|
-
const res = await fetch(url, options);
|
|
144
|
-
if (attemptsLeft > 0 && (res.status === 429 || res.status >= 500)) {
|
|
145
|
-
const delay = getDelay(res.headers.get(RATE_LIMIT_HEADER));
|
|
146
|
-
await sleep(delay);
|
|
147
|
-
return fetchAndRetry(fetch, url, options, attemptsLeft - 1);
|
|
148
|
-
}
|
|
149
|
-
return res;
|
|
150
|
-
} catch (error) {
|
|
151
|
-
if (attemptsLeft === 0) {
|
|
152
|
-
throw error;
|
|
153
|
-
}
|
|
154
|
-
const delay = getDelay();
|
|
155
|
-
await sleep(delay);
|
|
156
|
-
return fetchAndRetry(fetch, url, options, attemptsLeft - 1);
|
|
157
|
-
}
|
|
158
|
-
};
|
|
159
|
-
var getDelay = (rateLimitReset) => {
|
|
160
|
-
if (!rateLimitReset) {
|
|
161
|
-
return DEFAULT_RETRY_DELAY;
|
|
162
|
-
}
|
|
163
|
-
return Math.max(Number(rateLimitReset) * 1e3 - Date.now(), MIN_RETRY_DELAY);
|
|
164
|
-
};
|
|
165
|
-
var sleep = (ms) => new Promise((resolve) => {
|
|
166
|
-
setTimeout(resolve, ms);
|
|
167
|
-
});
|
|
168
|
-
var SIGNED_URL_ACCEPT_HEADER = "application/json;type=signed-url";
|
|
169
|
-
var Client = class {
|
|
170
|
-
constructor({ apiURL, consistency, edgeURL, fetch, region, siteID, token, uncachedEdgeURL }) {
|
|
171
|
-
this.apiURL = apiURL;
|
|
172
|
-
this.consistency = consistency ?? "eventual";
|
|
173
|
-
this.edgeURL = edgeURL;
|
|
174
|
-
this.fetch = fetch ?? globalThis.fetch;
|
|
175
|
-
this.region = region;
|
|
176
|
-
this.siteID = siteID;
|
|
177
|
-
this.token = token;
|
|
178
|
-
this.uncachedEdgeURL = uncachedEdgeURL;
|
|
179
|
-
if (!this.fetch) {
|
|
180
|
-
throw new Error(
|
|
181
|
-
"Netlify Blobs could not find a `fetch` client in the global scope. You can either update your runtime to a version that includes `fetch` (like Node.js 18.0.0 or above), or you can supply your own implementation using the `fetch` property."
|
|
182
|
-
);
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
async getFinalRequest({
|
|
186
|
-
consistency: opConsistency,
|
|
187
|
-
key,
|
|
188
|
-
metadata,
|
|
189
|
-
method,
|
|
190
|
-
parameters = {},
|
|
191
|
-
storeName
|
|
192
|
-
}) {
|
|
193
|
-
const encodedMetadata = encodeMetadata(metadata);
|
|
194
|
-
const consistency = opConsistency ?? this.consistency;
|
|
195
|
-
let urlPath = `/${this.siteID}`;
|
|
196
|
-
if (storeName) {
|
|
197
|
-
urlPath += `/${storeName}`;
|
|
198
|
-
}
|
|
199
|
-
if (key) {
|
|
200
|
-
urlPath += `/${key}`;
|
|
201
|
-
}
|
|
202
|
-
if (this.edgeURL) {
|
|
203
|
-
if (consistency === "strong" && !this.uncachedEdgeURL) {
|
|
204
|
-
throw new BlobsConsistencyError();
|
|
205
|
-
}
|
|
206
|
-
const headers = {
|
|
207
|
-
authorization: `Bearer ${this.token}`
|
|
208
|
-
};
|
|
209
|
-
if (encodedMetadata) {
|
|
210
|
-
headers[METADATA_HEADER_INTERNAL] = encodedMetadata;
|
|
211
|
-
}
|
|
212
|
-
if (this.region) {
|
|
213
|
-
urlPath = `/region:${this.region}${urlPath}`;
|
|
214
|
-
}
|
|
215
|
-
const url2 = new URL(urlPath, consistency === "strong" ? this.uncachedEdgeURL : this.edgeURL);
|
|
216
|
-
for (const key2 in parameters) {
|
|
217
|
-
url2.searchParams.set(key2, parameters[key2]);
|
|
218
|
-
}
|
|
219
|
-
return {
|
|
220
|
-
headers,
|
|
221
|
-
url: url2.toString()
|
|
222
|
-
};
|
|
223
|
-
}
|
|
224
|
-
const apiHeaders = { authorization: `Bearer ${this.token}` };
|
|
225
|
-
const url = new URL(`/api/v1/blobs${urlPath}`, this.apiURL ?? "https://api.netlify.com");
|
|
226
|
-
for (const key2 in parameters) {
|
|
227
|
-
url.searchParams.set(key2, parameters[key2]);
|
|
228
|
-
}
|
|
229
|
-
if (this.region) {
|
|
230
|
-
url.searchParams.set("region", this.region);
|
|
231
|
-
}
|
|
232
|
-
if (storeName === void 0 || key === void 0) {
|
|
233
|
-
return {
|
|
234
|
-
headers: apiHeaders,
|
|
235
|
-
url: url.toString()
|
|
236
|
-
};
|
|
237
|
-
}
|
|
238
|
-
if (encodedMetadata) {
|
|
239
|
-
apiHeaders[METADATA_HEADER_EXTERNAL] = encodedMetadata;
|
|
240
|
-
}
|
|
241
|
-
if (method === "head" || method === "delete") {
|
|
242
|
-
return {
|
|
243
|
-
headers: apiHeaders,
|
|
244
|
-
url: url.toString()
|
|
245
|
-
};
|
|
246
|
-
}
|
|
247
|
-
const res = await this.fetch(url.toString(), {
|
|
248
|
-
headers: { ...apiHeaders, accept: SIGNED_URL_ACCEPT_HEADER },
|
|
249
|
-
method
|
|
250
|
-
});
|
|
251
|
-
if (res.status !== 200) {
|
|
252
|
-
throw new BlobsInternalError(res);
|
|
253
|
-
}
|
|
254
|
-
const { url: signedURL } = await res.json();
|
|
255
|
-
const userHeaders = encodedMetadata ? { [METADATA_HEADER_INTERNAL]: encodedMetadata } : void 0;
|
|
256
|
-
return {
|
|
257
|
-
headers: userHeaders,
|
|
258
|
-
url: signedURL
|
|
259
|
-
};
|
|
260
|
-
}
|
|
261
|
-
async makeRequest({
|
|
262
|
-
body,
|
|
263
|
-
consistency,
|
|
264
|
-
headers: extraHeaders,
|
|
265
|
-
key,
|
|
266
|
-
metadata,
|
|
267
|
-
method,
|
|
268
|
-
parameters,
|
|
269
|
-
storeName
|
|
270
|
-
}) {
|
|
271
|
-
const { headers: baseHeaders = {}, url } = await this.getFinalRequest({
|
|
272
|
-
consistency,
|
|
273
|
-
key,
|
|
274
|
-
metadata,
|
|
275
|
-
method,
|
|
276
|
-
parameters,
|
|
277
|
-
storeName
|
|
278
|
-
});
|
|
279
|
-
const headers = {
|
|
280
|
-
...baseHeaders,
|
|
281
|
-
...extraHeaders
|
|
282
|
-
};
|
|
283
|
-
if (method === "put") {
|
|
284
|
-
headers["cache-control"] = "max-age=0, stale-while-revalidate=60";
|
|
285
|
-
}
|
|
286
|
-
const options = {
|
|
287
|
-
body,
|
|
288
|
-
headers,
|
|
289
|
-
method
|
|
290
|
-
};
|
|
291
|
-
if (body instanceof ReadableStream) {
|
|
292
|
-
options.duplex = "half";
|
|
293
|
-
}
|
|
294
|
-
return fetchAndRetry(this.fetch, url, options);
|
|
295
|
-
}
|
|
296
|
-
};
|
|
297
|
-
var getClientOptions = (options, contextOverride) => {
|
|
298
|
-
const context = contextOverride ?? getEnvironmentContext();
|
|
299
|
-
const siteID = context.siteID ?? options.siteID;
|
|
300
|
-
const token = context.token ?? options.token;
|
|
301
|
-
if (!siteID || !token) {
|
|
302
|
-
throw new MissingBlobsEnvironmentError(["siteID", "token"]);
|
|
303
|
-
}
|
|
304
|
-
if (options.region !== void 0 && !isValidRegion(options.region)) {
|
|
305
|
-
throw new InvalidBlobsRegionError(options.region);
|
|
306
|
-
}
|
|
307
|
-
const clientOptions = {
|
|
308
|
-
apiURL: context.apiURL ?? options.apiURL,
|
|
309
|
-
consistency: options.consistency,
|
|
310
|
-
edgeURL: context.edgeURL ?? options.edgeURL,
|
|
311
|
-
fetch: options.fetch,
|
|
312
|
-
region: options.region,
|
|
313
|
-
siteID,
|
|
314
|
-
token,
|
|
315
|
-
uncachedEdgeURL: context.uncachedEdgeURL ?? options.uncachedEdgeURL
|
|
316
|
-
};
|
|
317
|
-
return clientOptions;
|
|
318
|
-
};
|
|
319
|
-
|
|
320
|
-
// node_modules/@netlify/blobs/dist/main.js
|
|
321
|
-
var DEPLOY_STORE_PREFIX = "deploy:";
|
|
322
|
-
var LEGACY_STORE_INTERNAL_PREFIX = "netlify-internal/legacy-namespace/";
|
|
323
|
-
var SITE_STORE_PREFIX = "site:";
|
|
324
|
-
var Store = class _Store {
|
|
325
|
-
constructor(options) {
|
|
326
|
-
this.client = options.client;
|
|
327
|
-
if ("deployID" in options) {
|
|
328
|
-
_Store.validateDeployID(options.deployID);
|
|
329
|
-
let name = DEPLOY_STORE_PREFIX + options.deployID;
|
|
330
|
-
if (options.name) {
|
|
331
|
-
name += `:${options.name}`;
|
|
332
|
-
}
|
|
333
|
-
this.name = name;
|
|
334
|
-
} else if (options.name.startsWith(LEGACY_STORE_INTERNAL_PREFIX)) {
|
|
335
|
-
const storeName = options.name.slice(LEGACY_STORE_INTERNAL_PREFIX.length);
|
|
336
|
-
_Store.validateStoreName(storeName);
|
|
337
|
-
this.name = storeName;
|
|
338
|
-
} else {
|
|
339
|
-
_Store.validateStoreName(options.name);
|
|
340
|
-
this.name = SITE_STORE_PREFIX + options.name;
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
async delete(key) {
|
|
344
|
-
const res = await this.client.makeRequest({ key, method: "delete", storeName: this.name });
|
|
345
|
-
if (![200, 204, 404].includes(res.status)) {
|
|
346
|
-
throw new BlobsInternalError(res);
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
async get(key, options) {
|
|
350
|
-
const { consistency, type } = options ?? {};
|
|
351
|
-
const res = await this.client.makeRequest({ consistency, key, method: "get", storeName: this.name });
|
|
352
|
-
if (res.status === 404) {
|
|
353
|
-
return null;
|
|
354
|
-
}
|
|
355
|
-
if (res.status !== 200) {
|
|
356
|
-
throw new BlobsInternalError(res);
|
|
357
|
-
}
|
|
358
|
-
if (type === void 0 || type === "text") {
|
|
359
|
-
return res.text();
|
|
360
|
-
}
|
|
361
|
-
if (type === "arrayBuffer") {
|
|
362
|
-
return res.arrayBuffer();
|
|
363
|
-
}
|
|
364
|
-
if (type === "blob") {
|
|
365
|
-
return res.blob();
|
|
366
|
-
}
|
|
367
|
-
if (type === "json") {
|
|
368
|
-
return res.json();
|
|
369
|
-
}
|
|
370
|
-
if (type === "stream") {
|
|
371
|
-
return res.body;
|
|
372
|
-
}
|
|
373
|
-
throw new BlobsInternalError(res);
|
|
374
|
-
}
|
|
375
|
-
async getMetadata(key, { consistency } = {}) {
|
|
376
|
-
const res = await this.client.makeRequest({ consistency, key, method: "head", storeName: this.name });
|
|
377
|
-
if (res.status === 404) {
|
|
378
|
-
return null;
|
|
379
|
-
}
|
|
380
|
-
if (res.status !== 200 && res.status !== 304) {
|
|
381
|
-
throw new BlobsInternalError(res);
|
|
382
|
-
}
|
|
383
|
-
const etag = res?.headers.get("etag") ?? void 0;
|
|
384
|
-
const metadata = getMetadataFromResponse(res);
|
|
385
|
-
const result = {
|
|
386
|
-
etag,
|
|
387
|
-
metadata
|
|
388
|
-
};
|
|
389
|
-
return result;
|
|
390
|
-
}
|
|
391
|
-
async getWithMetadata(key, options) {
|
|
392
|
-
const { consistency, etag: requestETag, type } = options ?? {};
|
|
393
|
-
const headers = requestETag ? { "if-none-match": requestETag } : void 0;
|
|
394
|
-
const res = await this.client.makeRequest({
|
|
395
|
-
consistency,
|
|
396
|
-
headers,
|
|
397
|
-
key,
|
|
398
|
-
method: "get",
|
|
399
|
-
storeName: this.name
|
|
400
|
-
});
|
|
401
|
-
if (res.status === 404) {
|
|
402
|
-
return null;
|
|
403
|
-
}
|
|
404
|
-
if (res.status !== 200 && res.status !== 304) {
|
|
405
|
-
throw new BlobsInternalError(res);
|
|
406
|
-
}
|
|
407
|
-
const responseETag = res?.headers.get("etag") ?? void 0;
|
|
408
|
-
const metadata = getMetadataFromResponse(res);
|
|
409
|
-
const result = {
|
|
410
|
-
etag: responseETag,
|
|
411
|
-
metadata
|
|
412
|
-
};
|
|
413
|
-
if (res.status === 304 && requestETag) {
|
|
414
|
-
return { data: null, ...result };
|
|
415
|
-
}
|
|
416
|
-
if (type === void 0 || type === "text") {
|
|
417
|
-
return { data: await res.text(), ...result };
|
|
418
|
-
}
|
|
419
|
-
if (type === "arrayBuffer") {
|
|
420
|
-
return { data: await res.arrayBuffer(), ...result };
|
|
421
|
-
}
|
|
422
|
-
if (type === "blob") {
|
|
423
|
-
return { data: await res.blob(), ...result };
|
|
424
|
-
}
|
|
425
|
-
if (type === "json") {
|
|
426
|
-
return { data: await res.json(), ...result };
|
|
427
|
-
}
|
|
428
|
-
if (type === "stream") {
|
|
429
|
-
return { data: res.body, ...result };
|
|
430
|
-
}
|
|
431
|
-
throw new Error(`Invalid 'type' property: ${type}. Expected: arrayBuffer, blob, json, stream, or text.`);
|
|
432
|
-
}
|
|
433
|
-
list(options = {}) {
|
|
434
|
-
const iterator = this.getListIterator(options);
|
|
435
|
-
if (options.paginate) {
|
|
436
|
-
return iterator;
|
|
437
|
-
}
|
|
438
|
-
return collectIterator(iterator).then(
|
|
439
|
-
(items) => items.reduce(
|
|
440
|
-
(acc, item) => ({
|
|
441
|
-
blobs: [...acc.blobs, ...item.blobs],
|
|
442
|
-
directories: [...acc.directories, ...item.directories]
|
|
443
|
-
}),
|
|
444
|
-
{ blobs: [], directories: [] }
|
|
445
|
-
)
|
|
446
|
-
);
|
|
447
|
-
}
|
|
448
|
-
async set(key, data, { metadata } = {}) {
|
|
449
|
-
_Store.validateKey(key);
|
|
450
|
-
const res = await this.client.makeRequest({
|
|
451
|
-
body: data,
|
|
452
|
-
key,
|
|
453
|
-
metadata,
|
|
454
|
-
method: "put",
|
|
455
|
-
storeName: this.name
|
|
456
|
-
});
|
|
457
|
-
if (res.status !== 200) {
|
|
458
|
-
throw new BlobsInternalError(res);
|
|
459
|
-
}
|
|
460
|
-
}
|
|
461
|
-
async setJSON(key, data, { metadata } = {}) {
|
|
462
|
-
_Store.validateKey(key);
|
|
463
|
-
const payload = JSON.stringify(data);
|
|
464
|
-
const headers = {
|
|
465
|
-
"content-type": "application/json"
|
|
466
|
-
};
|
|
467
|
-
const res = await this.client.makeRequest({
|
|
468
|
-
body: payload,
|
|
469
|
-
headers,
|
|
470
|
-
key,
|
|
471
|
-
metadata,
|
|
472
|
-
method: "put",
|
|
473
|
-
storeName: this.name
|
|
474
|
-
});
|
|
475
|
-
if (res.status !== 200) {
|
|
476
|
-
throw new BlobsInternalError(res);
|
|
477
|
-
}
|
|
478
|
-
}
|
|
479
|
-
static formatListResultBlob(result) {
|
|
480
|
-
if (!result.key) {
|
|
481
|
-
return null;
|
|
482
|
-
}
|
|
483
|
-
return {
|
|
484
|
-
etag: result.etag,
|
|
485
|
-
key: result.key
|
|
486
|
-
};
|
|
487
|
-
}
|
|
488
|
-
static validateKey(key) {
|
|
489
|
-
if (key === "") {
|
|
490
|
-
throw new Error("Blob key must not be empty.");
|
|
491
|
-
}
|
|
492
|
-
if (key.startsWith("/") || key.startsWith("%2F")) {
|
|
493
|
-
throw new Error("Blob key must not start with forward slash (/).");
|
|
494
|
-
}
|
|
495
|
-
if (new TextEncoder().encode(key).length > 600) {
|
|
496
|
-
throw new Error(
|
|
497
|
-
"Blob key must be a sequence of Unicode characters whose UTF-8 encoding is at most 600 bytes long."
|
|
498
|
-
);
|
|
499
|
-
}
|
|
500
|
-
}
|
|
501
|
-
static validateDeployID(deployID) {
|
|
502
|
-
if (!/^\w{1,24}$/.test(deployID)) {
|
|
503
|
-
throw new Error(`'${deployID}' is not a valid Netlify deploy ID.`);
|
|
504
|
-
}
|
|
505
|
-
}
|
|
506
|
-
static validateStoreName(name) {
|
|
507
|
-
if (name.includes("/") || name.includes("%2F")) {
|
|
508
|
-
throw new Error("Store name must not contain forward slashes (/).");
|
|
509
|
-
}
|
|
510
|
-
if (new TextEncoder().encode(name).length > 64) {
|
|
511
|
-
throw new Error(
|
|
512
|
-
"Store name must be a sequence of Unicode characters whose UTF-8 encoding is at most 64 bytes long."
|
|
513
|
-
);
|
|
514
|
-
}
|
|
515
|
-
}
|
|
516
|
-
getListIterator(options) {
|
|
517
|
-
const { client, name: storeName } = this;
|
|
518
|
-
const parameters = {};
|
|
519
|
-
if (options?.prefix) {
|
|
520
|
-
parameters.prefix = options.prefix;
|
|
521
|
-
}
|
|
522
|
-
if (options?.directories) {
|
|
523
|
-
parameters.directories = "true";
|
|
524
|
-
}
|
|
525
|
-
return {
|
|
526
|
-
[Symbol.asyncIterator]() {
|
|
527
|
-
let currentCursor = null;
|
|
528
|
-
let done = false;
|
|
529
|
-
return {
|
|
530
|
-
async next() {
|
|
531
|
-
if (done) {
|
|
532
|
-
return { done: true, value: void 0 };
|
|
533
|
-
}
|
|
534
|
-
const nextParameters = { ...parameters };
|
|
535
|
-
if (currentCursor !== null) {
|
|
536
|
-
nextParameters.cursor = currentCursor;
|
|
537
|
-
}
|
|
538
|
-
const res = await client.makeRequest({
|
|
539
|
-
method: "get",
|
|
540
|
-
parameters: nextParameters,
|
|
541
|
-
storeName
|
|
542
|
-
});
|
|
543
|
-
let blobs = [];
|
|
544
|
-
let directories = [];
|
|
545
|
-
if (![200, 204, 404].includes(res.status)) {
|
|
546
|
-
throw new BlobsInternalError(res);
|
|
547
|
-
}
|
|
548
|
-
if (res.status === 404) {
|
|
549
|
-
done = true;
|
|
550
|
-
} else {
|
|
551
|
-
const page = await res.json();
|
|
552
|
-
if (page.next_cursor) {
|
|
553
|
-
currentCursor = page.next_cursor;
|
|
554
|
-
} else {
|
|
555
|
-
done = true;
|
|
556
|
-
}
|
|
557
|
-
blobs = (page.blobs ?? []).map(_Store.formatListResultBlob).filter(Boolean);
|
|
558
|
-
directories = page.directories ?? [];
|
|
559
|
-
}
|
|
560
|
-
return {
|
|
561
|
-
done: false,
|
|
562
|
-
value: {
|
|
563
|
-
blobs,
|
|
564
|
-
directories
|
|
565
|
-
}
|
|
566
|
-
};
|
|
567
|
-
}
|
|
568
|
-
};
|
|
569
|
-
}
|
|
570
|
-
};
|
|
571
|
-
}
|
|
572
|
-
};
|
|
573
|
-
var getDeployStore = (input = {}) => {
|
|
574
|
-
const context = getEnvironmentContext();
|
|
575
|
-
const options = typeof input === "string" ? { name: input } : input;
|
|
576
|
-
const deployID = options.deployID ?? context.deployID;
|
|
577
|
-
if (!deployID) {
|
|
578
|
-
throw new MissingBlobsEnvironmentError(["deployID"]);
|
|
579
|
-
}
|
|
580
|
-
const clientOptions = getClientOptions(options, context);
|
|
581
|
-
if (!clientOptions.region) {
|
|
582
|
-
if (clientOptions.edgeURL || clientOptions.uncachedEdgeURL) {
|
|
583
|
-
if (!context.primaryRegion) {
|
|
584
|
-
throw new Error(
|
|
585
|
-
"When accessing a deploy store, the Netlify Blobs client needs to be configured with a region, and one was not found in the environment. To manually set the region, set the `region` property in the `getDeployStore` options. If you are using the Netlify CLI, you may have an outdated version; run `npm install -g netlify-cli@latest` to update and try again."
|
|
586
|
-
);
|
|
587
|
-
}
|
|
588
|
-
clientOptions.region = context.primaryRegion;
|
|
589
|
-
} else {
|
|
590
|
-
clientOptions.region = REGION_AUTO;
|
|
591
|
-
}
|
|
592
|
-
}
|
|
593
|
-
const client = new Client(clientOptions);
|
|
594
|
-
return new Store({ client, deployID, name: options.name });
|
|
595
|
-
};
|
|
596
|
-
|
|
597
|
-
// src/run/regional-blob-store.cts
|
|
598
|
-
var fetchBeforeNextPatchedIt = globalThis.fetch;
|
|
599
|
-
var getRegionalBlobStore = (args = {}) => {
|
|
600
|
-
console.log("Blob store fetch patched", fetchBeforeNextPatchedIt.__nextPatched);
|
|
601
|
-
return getDeployStore({
|
|
602
|
-
...args,
|
|
603
|
-
fetch: fetchBeforeNextPatchedIt,
|
|
604
|
-
region: process.env.USE_REGIONAL_BLOBS?.toUpperCase() === "TRUE" ? void 0 : "us-east-2"
|
|
605
|
-
});
|
|
606
|
-
};
|
|
607
|
-
|
|
608
|
-
export {
|
|
609
|
-
getRegionalBlobStore
|
|
610
|
-
};
|