@netlify/plugin-nextjs 5.8.0 → 5.9.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.
Files changed (47) hide show
  1. package/README.md +3 -2
  2. package/dist/build/advanced-api-routes.js +4 -136
  3. package/dist/build/cache.js +4 -25
  4. package/dist/build/content/prerendered.js +11 -272
  5. package/dist/build/content/server.js +11 -219
  6. package/dist/build/content/static.js +14 -97
  7. package/dist/build/functions/edge.js +7 -534
  8. package/dist/build/functions/server.js +11 -130
  9. package/dist/build/image-cdn.js +3 -1599
  10. package/dist/build/plugin-context.js +6 -266
  11. package/dist/build/templates/handler-monorepo.tmpl.js +1 -1
  12. package/dist/build/templates/handler.tmpl.js +1 -1
  13. package/dist/build/verification.js +9 -104
  14. package/dist/esm-chunks/chunk-72ZI2IVI.js +36 -0
  15. package/dist/esm-chunks/chunk-AMY4NOT5.js +1610 -0
  16. package/dist/esm-chunks/chunk-BEIUVQZK.js +212 -0
  17. package/dist/esm-chunks/chunk-BFYMHE3E.js +548 -0
  18. package/dist/esm-chunks/chunk-BVYZSEV6.js +306 -0
  19. package/dist/esm-chunks/chunk-DLVROEVU.js +144 -0
  20. package/dist/esm-chunks/chunk-GFYWJNQR.js +305 -0
  21. package/dist/esm-chunks/chunk-HWMLYAVP.js +122 -0
  22. package/dist/esm-chunks/chunk-IJZEDP6B.js +235 -0
  23. package/dist/esm-chunks/chunk-K4RDUZYO.js +609 -0
  24. package/dist/esm-chunks/chunk-KBX7SJLC.js +73 -0
  25. package/dist/esm-chunks/chunk-NDSDIXRD.js +122 -0
  26. package/dist/esm-chunks/chunk-TYCYFZ22.js +25 -0
  27. package/dist/esm-chunks/chunk-UYKENJEU.js +19 -0
  28. package/dist/esm-chunks/chunk-XS27YRA5.js +34 -0
  29. package/dist/esm-chunks/chunk-ZENB67PD.js +148 -0
  30. package/dist/esm-chunks/chunk-ZSVHJNNY.js +120 -0
  31. package/dist/esm-chunks/next-4L47PQSM.js +569 -0
  32. package/dist/esm-chunks/{package-4GFWM3PF.js → package-LCNINN36.js} +8 -7
  33. package/dist/index.js +39 -18
  34. package/dist/run/config.js +4 -1
  35. package/dist/run/constants.js +5 -7
  36. package/dist/run/handlers/cache.cjs +1618 -31
  37. package/dist/run/handlers/request-context.cjs +6 -2
  38. package/dist/run/handlers/server.js +40 -20
  39. package/dist/run/handlers/tracer.cjs +83 -2
  40. package/dist/run/handlers/tracing.js +4 -2
  41. package/dist/run/handlers/wait-until.cjs +122 -0
  42. package/dist/run/headers.js +9 -194
  43. package/dist/run/next.cjs +1604 -18
  44. package/dist/run/regional-blob-store.cjs +1 -1
  45. package/dist/run/revalidate.js +3 -24
  46. package/dist/shared/blobkey.js +3 -15
  47. package/package.json +4 -4
@@ -5,6 +5,9 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
6
  var __getProtoOf = Object.getPrototypeOf;
7
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __esm = (fn, res) => function __init() {
9
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
10
+ };
8
11
  var __export = (target, all) => {
9
12
  for (var name in all)
10
13
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -27,6 +30,31 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
27
30
  ));
28
31
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
32
 
33
+ // src/shared/blobkey.ts
34
+ var blobkey_exports = {};
35
+ __export(blobkey_exports, {
36
+ encodeBlobKey: () => encodeBlobKey
37
+ });
38
+ async function encodeBlobKey(key) {
39
+ const buffer = import_node_buffer.Buffer.from(key);
40
+ const base64 = buffer.toString("base64url");
41
+ if (base64.length <= maxLength) {
42
+ return base64;
43
+ }
44
+ const digest = await import_node_crypto.webcrypto.subtle.digest("SHA-256", buffer);
45
+ const hash = import_node_buffer.Buffer.from(digest).toString("base64url");
46
+ return `${base64.slice(0, maxLength - hash.length - 1)}-${hash}`;
47
+ }
48
+ var import_node_buffer, import_node_crypto, maxLength;
49
+ var init_blobkey = __esm({
50
+ "src/shared/blobkey.ts"() {
51
+ "use strict";
52
+ import_node_buffer = require("node:buffer");
53
+ import_node_crypto = require("node:crypto");
54
+ maxLength = 180;
55
+ }
56
+ });
57
+
30
58
  // src/run/handlers/cache.cts
31
59
  var cache_exports = {};
32
60
  __export(cache_exports, {
@@ -34,7 +62,7 @@ __export(cache_exports, {
34
62
  default: () => cache_default
35
63
  });
36
64
  module.exports = __toCommonJS(cache_exports);
37
- var import_node_buffer = require("node:buffer");
65
+ var import_node_buffer2 = require("node:buffer");
38
66
  var import_node_path = require("node:path");
39
67
  var import_posix = require("node:path/posix");
40
68
 
@@ -95,31 +123,1590 @@ var pipeline = (0, import_util.promisify)(import_stream.pipeline);
95
123
 
96
124
  // src/run/handlers/cache.cts
97
125
  var import_constants = require("next/dist/lib/constants.js");
98
- var import_cache_types = require("../../shared/cache-types.cjs");
99
- var import_regional_blob_store = require("../regional-blob-store.cjs");
100
- var import_request_context = require("./request-context.cjs");
101
- var import_tracer = require("./tracer.cjs");
126
+
127
+ // src/shared/cache-types.cts
128
+ var isCachedPageValue = (value) => value.kind === "PAGE" || value.kind === "PAGES";
129
+ var isCachedRouteValue = (value) => value.kind === "ROUTE" || value.kind === "APP_ROUTE";
130
+
131
+ // node_modules/@netlify/blobs/dist/chunk-GUEW34CP.js
132
+ var NF_ERROR = "x-nf-error";
133
+ var NF_REQUEST_ID = "x-nf-request-id";
134
+ var BlobsInternalError = class extends Error {
135
+ constructor(res) {
136
+ let details = res.headers.get(NF_ERROR) || `${res.status} status code`;
137
+ if (res.headers.has(NF_REQUEST_ID)) {
138
+ details += `, ID: ${res.headers.get(NF_REQUEST_ID)}`;
139
+ }
140
+ super(`Netlify Blobs has generated an internal error (${details})`);
141
+ this.name = "BlobsInternalError";
142
+ }
143
+ };
144
+ var collectIterator = async (iterator) => {
145
+ const result = [];
146
+ for await (const item of iterator) {
147
+ result.push(item);
148
+ }
149
+ return result;
150
+ };
151
+ var base64Decode = (input) => {
152
+ const { Buffer: Buffer4 } = globalThis;
153
+ if (Buffer4) {
154
+ return Buffer4.from(input, "base64").toString();
155
+ }
156
+ return atob(input);
157
+ };
158
+ var base64Encode = (input) => {
159
+ const { Buffer: Buffer4 } = globalThis;
160
+ if (Buffer4) {
161
+ return Buffer4.from(input).toString("base64");
162
+ }
163
+ return btoa(input);
164
+ };
165
+ var getEnvironment = () => {
166
+ const { Deno, Netlify, process: process2 } = globalThis;
167
+ return Netlify?.env ?? Deno?.env ?? {
168
+ delete: (key) => delete process2?.env[key],
169
+ get: (key) => process2?.env[key],
170
+ has: (key) => Boolean(process2?.env[key]),
171
+ set: (key, value) => {
172
+ if (process2?.env) {
173
+ process2.env[key] = value;
174
+ }
175
+ },
176
+ toObject: () => process2?.env ?? {}
177
+ };
178
+ };
179
+ var getEnvironmentContext = () => {
180
+ const context2 = globalThis.netlifyBlobsContext || getEnvironment().get("NETLIFY_BLOBS_CONTEXT");
181
+ if (typeof context2 !== "string" || !context2) {
182
+ return {};
183
+ }
184
+ const data = base64Decode(context2);
185
+ try {
186
+ return JSON.parse(data);
187
+ } catch {
188
+ }
189
+ return {};
190
+ };
191
+ var MissingBlobsEnvironmentError = class extends Error {
192
+ constructor(requiredProperties) {
193
+ super(
194
+ `The environment has not been configured to use Netlify Blobs. To use it manually, supply the following properties when creating a store: ${requiredProperties.join(
195
+ ", "
196
+ )}`
197
+ );
198
+ this.name = "MissingBlobsEnvironmentError";
199
+ }
200
+ };
201
+ var BASE64_PREFIX = "b64;";
202
+ var METADATA_HEADER_INTERNAL = "x-amz-meta-user";
203
+ var METADATA_HEADER_EXTERNAL = "netlify-blobs-metadata";
204
+ var METADATA_MAX_SIZE = 2 * 1024;
205
+ var encodeMetadata = (metadata) => {
206
+ if (!metadata) {
207
+ return null;
208
+ }
209
+ const encodedObject = base64Encode(JSON.stringify(metadata));
210
+ const payload = `b64;${encodedObject}`;
211
+ if (METADATA_HEADER_EXTERNAL.length + payload.length > METADATA_MAX_SIZE) {
212
+ throw new Error("Metadata object exceeds the maximum size");
213
+ }
214
+ return payload;
215
+ };
216
+ var decodeMetadata = (header) => {
217
+ if (!header || !header.startsWith(BASE64_PREFIX)) {
218
+ return {};
219
+ }
220
+ const encodedData = header.slice(BASE64_PREFIX.length);
221
+ const decodedData = base64Decode(encodedData);
222
+ const metadata = JSON.parse(decodedData);
223
+ return metadata;
224
+ };
225
+ var getMetadataFromResponse = (response) => {
226
+ if (!response.headers) {
227
+ return {};
228
+ }
229
+ const value = response.headers.get(METADATA_HEADER_EXTERNAL) || response.headers.get(METADATA_HEADER_INTERNAL);
230
+ try {
231
+ return decodeMetadata(value);
232
+ } catch {
233
+ throw new Error(
234
+ "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."
235
+ );
236
+ }
237
+ };
238
+ var BlobsConsistencyError = class extends Error {
239
+ constructor() {
240
+ super(
241
+ `Netlify Blobs has failed to perform a read using strong consistency because the environment has not been configured with a 'uncachedEdgeURL' property`
242
+ );
243
+ this.name = "BlobsConsistencyError";
244
+ }
245
+ };
246
+ var REGION_AUTO = "auto";
247
+ var regions = {
248
+ "us-east-1": true,
249
+ "us-east-2": true
250
+ };
251
+ var isValidRegion = (input) => Object.keys(regions).includes(input);
252
+ var InvalidBlobsRegionError = class extends Error {
253
+ constructor(region) {
254
+ super(
255
+ `${region} is not a supported Netlify Blobs region. Supported values are: ${Object.keys(regions).join(", ")}.`
256
+ );
257
+ this.name = "InvalidBlobsRegionError";
258
+ }
259
+ };
260
+ var DEFAULT_RETRY_DELAY = getEnvironment().get("NODE_ENV") === "test" ? 1 : 5e3;
261
+ var MIN_RETRY_DELAY = 1e3;
262
+ var MAX_RETRY = 5;
263
+ var RATE_LIMIT_HEADER = "X-RateLimit-Reset";
264
+ var fetchAndRetry = async (fetch2, url, options, attemptsLeft = MAX_RETRY) => {
265
+ try {
266
+ const res = await fetch2(url, options);
267
+ if (attemptsLeft > 0 && (res.status === 429 || res.status >= 500)) {
268
+ const delay = getDelay(res.headers.get(RATE_LIMIT_HEADER));
269
+ await sleep(delay);
270
+ return fetchAndRetry(fetch2, url, options, attemptsLeft - 1);
271
+ }
272
+ return res;
273
+ } catch (error) {
274
+ if (attemptsLeft === 0) {
275
+ throw error;
276
+ }
277
+ const delay = getDelay();
278
+ await sleep(delay);
279
+ return fetchAndRetry(fetch2, url, options, attemptsLeft - 1);
280
+ }
281
+ };
282
+ var getDelay = (rateLimitReset) => {
283
+ if (!rateLimitReset) {
284
+ return DEFAULT_RETRY_DELAY;
285
+ }
286
+ return Math.max(Number(rateLimitReset) * 1e3 - Date.now(), MIN_RETRY_DELAY);
287
+ };
288
+ var sleep = (ms) => new Promise((resolve) => {
289
+ setTimeout(resolve, ms);
290
+ });
291
+ var SIGNED_URL_ACCEPT_HEADER = "application/json;type=signed-url";
292
+ var Client = class {
293
+ constructor({ apiURL, consistency, edgeURL, fetch: fetch2, region, siteID, token, uncachedEdgeURL }) {
294
+ this.apiURL = apiURL;
295
+ this.consistency = consistency ?? "eventual";
296
+ this.edgeURL = edgeURL;
297
+ this.fetch = fetch2 ?? globalThis.fetch;
298
+ this.region = region;
299
+ this.siteID = siteID;
300
+ this.token = token;
301
+ this.uncachedEdgeURL = uncachedEdgeURL;
302
+ if (!this.fetch) {
303
+ throw new Error(
304
+ "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."
305
+ );
306
+ }
307
+ }
308
+ async getFinalRequest({
309
+ consistency: opConsistency,
310
+ key,
311
+ metadata,
312
+ method,
313
+ parameters = {},
314
+ storeName
315
+ }) {
316
+ const encodedMetadata = encodeMetadata(metadata);
317
+ const consistency = opConsistency ?? this.consistency;
318
+ let urlPath = `/${this.siteID}`;
319
+ if (storeName) {
320
+ urlPath += `/${storeName}`;
321
+ }
322
+ if (key) {
323
+ urlPath += `/${key}`;
324
+ }
325
+ if (this.edgeURL) {
326
+ if (consistency === "strong" && !this.uncachedEdgeURL) {
327
+ throw new BlobsConsistencyError();
328
+ }
329
+ const headers = {
330
+ authorization: `Bearer ${this.token}`
331
+ };
332
+ if (encodedMetadata) {
333
+ headers[METADATA_HEADER_INTERNAL] = encodedMetadata;
334
+ }
335
+ if (this.region) {
336
+ urlPath = `/region:${this.region}${urlPath}`;
337
+ }
338
+ const url2 = new URL(urlPath, consistency === "strong" ? this.uncachedEdgeURL : this.edgeURL);
339
+ for (const key2 in parameters) {
340
+ url2.searchParams.set(key2, parameters[key2]);
341
+ }
342
+ return {
343
+ headers,
344
+ url: url2.toString()
345
+ };
346
+ }
347
+ const apiHeaders = { authorization: `Bearer ${this.token}` };
348
+ const url = new URL(`/api/v1/blobs${urlPath}`, this.apiURL ?? "https://api.netlify.com");
349
+ for (const key2 in parameters) {
350
+ url.searchParams.set(key2, parameters[key2]);
351
+ }
352
+ if (this.region) {
353
+ url.searchParams.set("region", this.region);
354
+ }
355
+ if (storeName === void 0 || key === void 0) {
356
+ return {
357
+ headers: apiHeaders,
358
+ url: url.toString()
359
+ };
360
+ }
361
+ if (encodedMetadata) {
362
+ apiHeaders[METADATA_HEADER_EXTERNAL] = encodedMetadata;
363
+ }
364
+ if (method === "head" || method === "delete") {
365
+ return {
366
+ headers: apiHeaders,
367
+ url: url.toString()
368
+ };
369
+ }
370
+ const res = await this.fetch(url.toString(), {
371
+ headers: { ...apiHeaders, accept: SIGNED_URL_ACCEPT_HEADER },
372
+ method
373
+ });
374
+ if (res.status !== 200) {
375
+ throw new BlobsInternalError(res);
376
+ }
377
+ const { url: signedURL } = await res.json();
378
+ const userHeaders = encodedMetadata ? { [METADATA_HEADER_INTERNAL]: encodedMetadata } : void 0;
379
+ return {
380
+ headers: userHeaders,
381
+ url: signedURL
382
+ };
383
+ }
384
+ async makeRequest({
385
+ body,
386
+ consistency,
387
+ headers: extraHeaders,
388
+ key,
389
+ metadata,
390
+ method,
391
+ parameters,
392
+ storeName
393
+ }) {
394
+ const { headers: baseHeaders = {}, url } = await this.getFinalRequest({
395
+ consistency,
396
+ key,
397
+ metadata,
398
+ method,
399
+ parameters,
400
+ storeName
401
+ });
402
+ const headers = {
403
+ ...baseHeaders,
404
+ ...extraHeaders
405
+ };
406
+ if (method === "put") {
407
+ headers["cache-control"] = "max-age=0, stale-while-revalidate=60";
408
+ }
409
+ const options = {
410
+ body,
411
+ headers,
412
+ method
413
+ };
414
+ if (body instanceof ReadableStream) {
415
+ options.duplex = "half";
416
+ }
417
+ return fetchAndRetry(this.fetch, url, options);
418
+ }
419
+ };
420
+ var getClientOptions = (options, contextOverride) => {
421
+ const context2 = contextOverride ?? getEnvironmentContext();
422
+ const siteID = context2.siteID ?? options.siteID;
423
+ const token = context2.token ?? options.token;
424
+ if (!siteID || !token) {
425
+ throw new MissingBlobsEnvironmentError(["siteID", "token"]);
426
+ }
427
+ if (options.region !== void 0 && !isValidRegion(options.region)) {
428
+ throw new InvalidBlobsRegionError(options.region);
429
+ }
430
+ const clientOptions = {
431
+ apiURL: context2.apiURL ?? options.apiURL,
432
+ consistency: options.consistency,
433
+ edgeURL: context2.edgeURL ?? options.edgeURL,
434
+ fetch: options.fetch,
435
+ region: options.region,
436
+ siteID,
437
+ token,
438
+ uncachedEdgeURL: context2.uncachedEdgeURL ?? options.uncachedEdgeURL
439
+ };
440
+ return clientOptions;
441
+ };
442
+
443
+ // node_modules/@netlify/blobs/dist/main.js
444
+ var DEPLOY_STORE_PREFIX = "deploy:";
445
+ var LEGACY_STORE_INTERNAL_PREFIX = "netlify-internal/legacy-namespace/";
446
+ var SITE_STORE_PREFIX = "site:";
447
+ var Store = class _Store {
448
+ constructor(options) {
449
+ this.client = options.client;
450
+ if ("deployID" in options) {
451
+ _Store.validateDeployID(options.deployID);
452
+ let name = DEPLOY_STORE_PREFIX + options.deployID;
453
+ if (options.name) {
454
+ name += `:${options.name}`;
455
+ }
456
+ this.name = name;
457
+ } else if (options.name.startsWith(LEGACY_STORE_INTERNAL_PREFIX)) {
458
+ const storeName = options.name.slice(LEGACY_STORE_INTERNAL_PREFIX.length);
459
+ _Store.validateStoreName(storeName);
460
+ this.name = storeName;
461
+ } else {
462
+ _Store.validateStoreName(options.name);
463
+ this.name = SITE_STORE_PREFIX + options.name;
464
+ }
465
+ }
466
+ async delete(key) {
467
+ const res = await this.client.makeRequest({ key, method: "delete", storeName: this.name });
468
+ if (![200, 204, 404].includes(res.status)) {
469
+ throw new BlobsInternalError(res);
470
+ }
471
+ }
472
+ async get(key, options) {
473
+ const { consistency, type } = options ?? {};
474
+ const res = await this.client.makeRequest({ consistency, key, method: "get", storeName: this.name });
475
+ if (res.status === 404) {
476
+ return null;
477
+ }
478
+ if (res.status !== 200) {
479
+ throw new BlobsInternalError(res);
480
+ }
481
+ if (type === void 0 || type === "text") {
482
+ return res.text();
483
+ }
484
+ if (type === "arrayBuffer") {
485
+ return res.arrayBuffer();
486
+ }
487
+ if (type === "blob") {
488
+ return res.blob();
489
+ }
490
+ if (type === "json") {
491
+ return res.json();
492
+ }
493
+ if (type === "stream") {
494
+ return res.body;
495
+ }
496
+ throw new BlobsInternalError(res);
497
+ }
498
+ async getMetadata(key, { consistency } = {}) {
499
+ const res = await this.client.makeRequest({ consistency, key, method: "head", storeName: this.name });
500
+ if (res.status === 404) {
501
+ return null;
502
+ }
503
+ if (res.status !== 200 && res.status !== 304) {
504
+ throw new BlobsInternalError(res);
505
+ }
506
+ const etag = res?.headers.get("etag") ?? void 0;
507
+ const metadata = getMetadataFromResponse(res);
508
+ const result = {
509
+ etag,
510
+ metadata
511
+ };
512
+ return result;
513
+ }
514
+ async getWithMetadata(key, options) {
515
+ const { consistency, etag: requestETag, type } = options ?? {};
516
+ const headers = requestETag ? { "if-none-match": requestETag } : void 0;
517
+ const res = await this.client.makeRequest({
518
+ consistency,
519
+ headers,
520
+ key,
521
+ method: "get",
522
+ storeName: this.name
523
+ });
524
+ if (res.status === 404) {
525
+ return null;
526
+ }
527
+ if (res.status !== 200 && res.status !== 304) {
528
+ throw new BlobsInternalError(res);
529
+ }
530
+ const responseETag = res?.headers.get("etag") ?? void 0;
531
+ const metadata = getMetadataFromResponse(res);
532
+ const result = {
533
+ etag: responseETag,
534
+ metadata
535
+ };
536
+ if (res.status === 304 && requestETag) {
537
+ return { data: null, ...result };
538
+ }
539
+ if (type === void 0 || type === "text") {
540
+ return { data: await res.text(), ...result };
541
+ }
542
+ if (type === "arrayBuffer") {
543
+ return { data: await res.arrayBuffer(), ...result };
544
+ }
545
+ if (type === "blob") {
546
+ return { data: await res.blob(), ...result };
547
+ }
548
+ if (type === "json") {
549
+ return { data: await res.json(), ...result };
550
+ }
551
+ if (type === "stream") {
552
+ return { data: res.body, ...result };
553
+ }
554
+ throw new Error(`Invalid 'type' property: ${type}. Expected: arrayBuffer, blob, json, stream, or text.`);
555
+ }
556
+ list(options = {}) {
557
+ const iterator = this.getListIterator(options);
558
+ if (options.paginate) {
559
+ return iterator;
560
+ }
561
+ return collectIterator(iterator).then(
562
+ (items) => items.reduce(
563
+ (acc, item) => ({
564
+ blobs: [...acc.blobs, ...item.blobs],
565
+ directories: [...acc.directories, ...item.directories]
566
+ }),
567
+ { blobs: [], directories: [] }
568
+ )
569
+ );
570
+ }
571
+ async set(key, data, { metadata } = {}) {
572
+ _Store.validateKey(key);
573
+ const res = await this.client.makeRequest({
574
+ body: data,
575
+ key,
576
+ metadata,
577
+ method: "put",
578
+ storeName: this.name
579
+ });
580
+ if (res.status !== 200) {
581
+ throw new BlobsInternalError(res);
582
+ }
583
+ }
584
+ async setJSON(key, data, { metadata } = {}) {
585
+ _Store.validateKey(key);
586
+ const payload = JSON.stringify(data);
587
+ const headers = {
588
+ "content-type": "application/json"
589
+ };
590
+ const res = await this.client.makeRequest({
591
+ body: payload,
592
+ headers,
593
+ key,
594
+ metadata,
595
+ method: "put",
596
+ storeName: this.name
597
+ });
598
+ if (res.status !== 200) {
599
+ throw new BlobsInternalError(res);
600
+ }
601
+ }
602
+ static formatListResultBlob(result) {
603
+ if (!result.key) {
604
+ return null;
605
+ }
606
+ return {
607
+ etag: result.etag,
608
+ key: result.key
609
+ };
610
+ }
611
+ static validateKey(key) {
612
+ if (key === "") {
613
+ throw new Error("Blob key must not be empty.");
614
+ }
615
+ if (key.startsWith("/") || key.startsWith("%2F")) {
616
+ throw new Error("Blob key must not start with forward slash (/).");
617
+ }
618
+ if (new TextEncoder().encode(key).length > 600) {
619
+ throw new Error(
620
+ "Blob key must be a sequence of Unicode characters whose UTF-8 encoding is at most 600 bytes long."
621
+ );
622
+ }
623
+ }
624
+ static validateDeployID(deployID) {
625
+ if (!/^\w{1,24}$/.test(deployID)) {
626
+ throw new Error(`'${deployID}' is not a valid Netlify deploy ID.`);
627
+ }
628
+ }
629
+ static validateStoreName(name) {
630
+ if (name.includes("/") || name.includes("%2F")) {
631
+ throw new Error("Store name must not contain forward slashes (/).");
632
+ }
633
+ if (new TextEncoder().encode(name).length > 64) {
634
+ throw new Error(
635
+ "Store name must be a sequence of Unicode characters whose UTF-8 encoding is at most 64 bytes long."
636
+ );
637
+ }
638
+ }
639
+ getListIterator(options) {
640
+ const { client, name: storeName } = this;
641
+ const parameters = {};
642
+ if (options?.prefix) {
643
+ parameters.prefix = options.prefix;
644
+ }
645
+ if (options?.directories) {
646
+ parameters.directories = "true";
647
+ }
648
+ return {
649
+ [Symbol.asyncIterator]() {
650
+ let currentCursor = null;
651
+ let done = false;
652
+ return {
653
+ async next() {
654
+ if (done) {
655
+ return { done: true, value: void 0 };
656
+ }
657
+ const nextParameters = { ...parameters };
658
+ if (currentCursor !== null) {
659
+ nextParameters.cursor = currentCursor;
660
+ }
661
+ const res = await client.makeRequest({
662
+ method: "get",
663
+ parameters: nextParameters,
664
+ storeName
665
+ });
666
+ let blobs = [];
667
+ let directories = [];
668
+ if (![200, 204, 404].includes(res.status)) {
669
+ throw new BlobsInternalError(res);
670
+ }
671
+ if (res.status === 404) {
672
+ done = true;
673
+ } else {
674
+ const page = await res.json();
675
+ if (page.next_cursor) {
676
+ currentCursor = page.next_cursor;
677
+ } else {
678
+ done = true;
679
+ }
680
+ blobs = (page.blobs ?? []).map(_Store.formatListResultBlob).filter(Boolean);
681
+ directories = page.directories ?? [];
682
+ }
683
+ return {
684
+ done: false,
685
+ value: {
686
+ blobs,
687
+ directories
688
+ }
689
+ };
690
+ }
691
+ };
692
+ }
693
+ };
694
+ }
695
+ };
696
+ var getDeployStore = (input = {}) => {
697
+ const context2 = getEnvironmentContext();
698
+ const options = typeof input === "string" ? { name: input } : input;
699
+ const deployID = options.deployID ?? context2.deployID;
700
+ if (!deployID) {
701
+ throw new MissingBlobsEnvironmentError(["deployID"]);
702
+ }
703
+ const clientOptions = getClientOptions(options, context2);
704
+ if (!clientOptions.region) {
705
+ if (clientOptions.edgeURL || clientOptions.uncachedEdgeURL) {
706
+ if (!context2.primaryRegion) {
707
+ throw new Error(
708
+ "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."
709
+ );
710
+ }
711
+ clientOptions.region = context2.primaryRegion;
712
+ } else {
713
+ clientOptions.region = REGION_AUTO;
714
+ }
715
+ }
716
+ const client = new Client(clientOptions);
717
+ return new Store({ client, deployID, name: options.name });
718
+ };
719
+
720
+ // src/run/regional-blob-store.cts
721
+ var fetchBeforeNextPatchedIt = globalThis.fetch;
722
+ var getRegionalBlobStore = (args = {}) => {
723
+ return getDeployStore({
724
+ ...args,
725
+ fetch: fetchBeforeNextPatchedIt,
726
+ region: process.env.USE_REGIONAL_BLOBS?.toUpperCase() === "TRUE" ? void 0 : "us-east-2"
727
+ });
728
+ };
729
+
730
+ // src/run/handlers/request-context.cts
731
+ var import_node_async_hooks = require("node:async_hooks");
732
+
733
+ // node_modules/@netlify/functions/dist/chunk-HYMERDCV.mjs
734
+ var import_process2 = require("process");
735
+ var systemLogTag = "__nfSystemLog";
736
+ var serializeError = (error) => {
737
+ const cause = error?.cause instanceof Error ? serializeError(error.cause) : error.cause;
738
+ return {
739
+ error: error.message,
740
+ error_cause: cause,
741
+ error_stack: error.stack
742
+ };
743
+ };
744
+ var SystemLogger = class _SystemLogger {
745
+ fields;
746
+ logLevel;
747
+ constructor(fields = {}, logLevel = 2) {
748
+ this.fields = fields;
749
+ this.logLevel = logLevel;
750
+ }
751
+ doLog(logger, message) {
752
+ if (import_process2.env.NETLIFY_DEV && !import_process2.env.NETLIFY_ENABLE_SYSTEM_LOGGING) {
753
+ return;
754
+ }
755
+ logger(systemLogTag, JSON.stringify({ msg: message, fields: this.fields }));
756
+ }
757
+ log(message) {
758
+ if (this.logLevel > 2) {
759
+ return;
760
+ }
761
+ this.doLog(console.log, message);
762
+ }
763
+ debug(message) {
764
+ if (this.logLevel > 1) {
765
+ return;
766
+ }
767
+ this.doLog(console.debug, message);
768
+ }
769
+ error(message) {
770
+ if (this.logLevel > 3) {
771
+ return;
772
+ }
773
+ this.doLog(console.error, message);
774
+ }
775
+ withLogLevel(level) {
776
+ return new _SystemLogger(this.fields, level);
777
+ }
778
+ withFields(fields) {
779
+ return new _SystemLogger(
780
+ {
781
+ ...this.fields,
782
+ ...fields
783
+ },
784
+ this.logLevel
785
+ );
786
+ }
787
+ withError(error) {
788
+ const fields = error instanceof Error ? serializeError(error) : { error };
789
+ return this.withFields(fields);
790
+ }
791
+ };
792
+ var systemLogger = new SystemLogger();
793
+
794
+ // src/run/handlers/request-context.cts
795
+ var REQUEST_CONTEXT_GLOBAL_KEY = Symbol.for("nf-request-context-async-local-storage");
796
+ var requestContextAsyncLocalStorage;
797
+ function getRequestContextAsyncLocalStorage() {
798
+ if (requestContextAsyncLocalStorage) {
799
+ return requestContextAsyncLocalStorage;
800
+ }
801
+ const extendedGlobalThis = globalThis;
802
+ if (extendedGlobalThis[REQUEST_CONTEXT_GLOBAL_KEY]) {
803
+ return extendedGlobalThis[REQUEST_CONTEXT_GLOBAL_KEY];
804
+ }
805
+ const storage = new import_node_async_hooks.AsyncLocalStorage();
806
+ requestContextAsyncLocalStorage = storage;
807
+ extendedGlobalThis[REQUEST_CONTEXT_GLOBAL_KEY] = storage;
808
+ return storage;
809
+ }
810
+ var getRequestContext = () => getRequestContextAsyncLocalStorage().getStore();
811
+ function getLogger() {
812
+ return getRequestContext()?.logger ?? systemLogger;
813
+ }
814
+
815
+ // node_modules/@opentelemetry/api/build/esm/platform/node/globalThis.js
816
+ var _globalThis = typeof globalThis === "object" ? globalThis : global;
817
+
818
+ // node_modules/@opentelemetry/api/build/esm/version.js
819
+ var VERSION = "1.8.0";
820
+
821
+ // node_modules/@opentelemetry/api/build/esm/internal/semver.js
822
+ var re = /^(\d+)\.(\d+)\.(\d+)(-(.+))?$/;
823
+ function _makeCompatibilityCheck(ownVersion) {
824
+ var acceptedVersions = /* @__PURE__ */ new Set([ownVersion]);
825
+ var rejectedVersions = /* @__PURE__ */ new Set();
826
+ var myVersionMatch = ownVersion.match(re);
827
+ if (!myVersionMatch) {
828
+ return function() {
829
+ return false;
830
+ };
831
+ }
832
+ var ownVersionParsed = {
833
+ major: +myVersionMatch[1],
834
+ minor: +myVersionMatch[2],
835
+ patch: +myVersionMatch[3],
836
+ prerelease: myVersionMatch[4]
837
+ };
838
+ if (ownVersionParsed.prerelease != null) {
839
+ return function isExactmatch(globalVersion) {
840
+ return globalVersion === ownVersion;
841
+ };
842
+ }
843
+ function _reject(v) {
844
+ rejectedVersions.add(v);
845
+ return false;
846
+ }
847
+ function _accept(v) {
848
+ acceptedVersions.add(v);
849
+ return true;
850
+ }
851
+ return function isCompatible2(globalVersion) {
852
+ if (acceptedVersions.has(globalVersion)) {
853
+ return true;
854
+ }
855
+ if (rejectedVersions.has(globalVersion)) {
856
+ return false;
857
+ }
858
+ var globalVersionMatch = globalVersion.match(re);
859
+ if (!globalVersionMatch) {
860
+ return _reject(globalVersion);
861
+ }
862
+ var globalVersionParsed = {
863
+ major: +globalVersionMatch[1],
864
+ minor: +globalVersionMatch[2],
865
+ patch: +globalVersionMatch[3],
866
+ prerelease: globalVersionMatch[4]
867
+ };
868
+ if (globalVersionParsed.prerelease != null) {
869
+ return _reject(globalVersion);
870
+ }
871
+ if (ownVersionParsed.major !== globalVersionParsed.major) {
872
+ return _reject(globalVersion);
873
+ }
874
+ if (ownVersionParsed.major === 0) {
875
+ if (ownVersionParsed.minor === globalVersionParsed.minor && ownVersionParsed.patch <= globalVersionParsed.patch) {
876
+ return _accept(globalVersion);
877
+ }
878
+ return _reject(globalVersion);
879
+ }
880
+ if (ownVersionParsed.minor <= globalVersionParsed.minor) {
881
+ return _accept(globalVersion);
882
+ }
883
+ return _reject(globalVersion);
884
+ };
885
+ }
886
+ var isCompatible = _makeCompatibilityCheck(VERSION);
887
+
888
+ // node_modules/@opentelemetry/api/build/esm/internal/global-utils.js
889
+ var major = VERSION.split(".")[0];
890
+ var GLOBAL_OPENTELEMETRY_API_KEY = Symbol.for("opentelemetry.js.api." + major);
891
+ var _global = _globalThis;
892
+ function registerGlobal(type, instance, diag, allowOverride) {
893
+ var _a;
894
+ if (allowOverride === void 0) {
895
+ allowOverride = false;
896
+ }
897
+ var api = _global[GLOBAL_OPENTELEMETRY_API_KEY] = (_a = _global[GLOBAL_OPENTELEMETRY_API_KEY]) !== null && _a !== void 0 ? _a : {
898
+ version: VERSION
899
+ };
900
+ if (!allowOverride && api[type]) {
901
+ var err = new Error("@opentelemetry/api: Attempted duplicate registration of API: " + type);
902
+ diag.error(err.stack || err.message);
903
+ return false;
904
+ }
905
+ if (api.version !== VERSION) {
906
+ var err = new Error("@opentelemetry/api: Registration of version v" + api.version + " for " + type + " does not match previously registered API v" + VERSION);
907
+ diag.error(err.stack || err.message);
908
+ return false;
909
+ }
910
+ api[type] = instance;
911
+ diag.debug("@opentelemetry/api: Registered a global for " + type + " v" + VERSION + ".");
912
+ return true;
913
+ }
914
+ function getGlobal(type) {
915
+ var _a, _b;
916
+ var globalVersion = (_a = _global[GLOBAL_OPENTELEMETRY_API_KEY]) === null || _a === void 0 ? void 0 : _a.version;
917
+ if (!globalVersion || !isCompatible(globalVersion)) {
918
+ return;
919
+ }
920
+ return (_b = _global[GLOBAL_OPENTELEMETRY_API_KEY]) === null || _b === void 0 ? void 0 : _b[type];
921
+ }
922
+ function unregisterGlobal(type, diag) {
923
+ diag.debug("@opentelemetry/api: Unregistering a global for " + type + " v" + VERSION + ".");
924
+ var api = _global[GLOBAL_OPENTELEMETRY_API_KEY];
925
+ if (api) {
926
+ delete api[type];
927
+ }
928
+ }
929
+
930
+ // node_modules/@opentelemetry/api/build/esm/diag/ComponentLogger.js
931
+ var __read = function(o, n) {
932
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
933
+ if (!m) return o;
934
+ var i = m.call(o), r, ar = [], e;
935
+ try {
936
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
937
+ } catch (error) {
938
+ e = { error };
939
+ } finally {
940
+ try {
941
+ if (r && !r.done && (m = i["return"])) m.call(i);
942
+ } finally {
943
+ if (e) throw e.error;
944
+ }
945
+ }
946
+ return ar;
947
+ };
948
+ var __spreadArray = function(to, from, pack) {
949
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
950
+ if (ar || !(i in from)) {
951
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
952
+ ar[i] = from[i];
953
+ }
954
+ }
955
+ return to.concat(ar || Array.prototype.slice.call(from));
956
+ };
957
+ var DiagComponentLogger = (
958
+ /** @class */
959
+ function() {
960
+ function DiagComponentLogger2(props) {
961
+ this._namespace = props.namespace || "DiagComponentLogger";
962
+ }
963
+ DiagComponentLogger2.prototype.debug = function() {
964
+ var args = [];
965
+ for (var _i = 0; _i < arguments.length; _i++) {
966
+ args[_i] = arguments[_i];
967
+ }
968
+ return logProxy("debug", this._namespace, args);
969
+ };
970
+ DiagComponentLogger2.prototype.error = function() {
971
+ var args = [];
972
+ for (var _i = 0; _i < arguments.length; _i++) {
973
+ args[_i] = arguments[_i];
974
+ }
975
+ return logProxy("error", this._namespace, args);
976
+ };
977
+ DiagComponentLogger2.prototype.info = function() {
978
+ var args = [];
979
+ for (var _i = 0; _i < arguments.length; _i++) {
980
+ args[_i] = arguments[_i];
981
+ }
982
+ return logProxy("info", this._namespace, args);
983
+ };
984
+ DiagComponentLogger2.prototype.warn = function() {
985
+ var args = [];
986
+ for (var _i = 0; _i < arguments.length; _i++) {
987
+ args[_i] = arguments[_i];
988
+ }
989
+ return logProxy("warn", this._namespace, args);
990
+ };
991
+ DiagComponentLogger2.prototype.verbose = function() {
992
+ var args = [];
993
+ for (var _i = 0; _i < arguments.length; _i++) {
994
+ args[_i] = arguments[_i];
995
+ }
996
+ return logProxy("verbose", this._namespace, args);
997
+ };
998
+ return DiagComponentLogger2;
999
+ }()
1000
+ );
1001
+ function logProxy(funcName, namespace, args) {
1002
+ var logger = getGlobal("diag");
1003
+ if (!logger) {
1004
+ return;
1005
+ }
1006
+ args.unshift(namespace);
1007
+ return logger[funcName].apply(logger, __spreadArray([], __read(args), false));
1008
+ }
1009
+
1010
+ // node_modules/@opentelemetry/api/build/esm/diag/types.js
1011
+ var DiagLogLevel;
1012
+ (function(DiagLogLevel2) {
1013
+ DiagLogLevel2[DiagLogLevel2["NONE"] = 0] = "NONE";
1014
+ DiagLogLevel2[DiagLogLevel2["ERROR"] = 30] = "ERROR";
1015
+ DiagLogLevel2[DiagLogLevel2["WARN"] = 50] = "WARN";
1016
+ DiagLogLevel2[DiagLogLevel2["INFO"] = 60] = "INFO";
1017
+ DiagLogLevel2[DiagLogLevel2["DEBUG"] = 70] = "DEBUG";
1018
+ DiagLogLevel2[DiagLogLevel2["VERBOSE"] = 80] = "VERBOSE";
1019
+ DiagLogLevel2[DiagLogLevel2["ALL"] = 9999] = "ALL";
1020
+ })(DiagLogLevel || (DiagLogLevel = {}));
1021
+
1022
+ // node_modules/@opentelemetry/api/build/esm/diag/internal/logLevelLogger.js
1023
+ function createLogLevelDiagLogger(maxLevel, logger) {
1024
+ if (maxLevel < DiagLogLevel.NONE) {
1025
+ maxLevel = DiagLogLevel.NONE;
1026
+ } else if (maxLevel > DiagLogLevel.ALL) {
1027
+ maxLevel = DiagLogLevel.ALL;
1028
+ }
1029
+ logger = logger || {};
1030
+ function _filterFunc(funcName, theLevel) {
1031
+ var theFunc = logger[funcName];
1032
+ if (typeof theFunc === "function" && maxLevel >= theLevel) {
1033
+ return theFunc.bind(logger);
1034
+ }
1035
+ return function() {
1036
+ };
1037
+ }
1038
+ return {
1039
+ error: _filterFunc("error", DiagLogLevel.ERROR),
1040
+ warn: _filterFunc("warn", DiagLogLevel.WARN),
1041
+ info: _filterFunc("info", DiagLogLevel.INFO),
1042
+ debug: _filterFunc("debug", DiagLogLevel.DEBUG),
1043
+ verbose: _filterFunc("verbose", DiagLogLevel.VERBOSE)
1044
+ };
1045
+ }
1046
+
1047
+ // node_modules/@opentelemetry/api/build/esm/api/diag.js
1048
+ var __read2 = function(o, n) {
1049
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
1050
+ if (!m) return o;
1051
+ var i = m.call(o), r, ar = [], e;
1052
+ try {
1053
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
1054
+ } catch (error) {
1055
+ e = { error };
1056
+ } finally {
1057
+ try {
1058
+ if (r && !r.done && (m = i["return"])) m.call(i);
1059
+ } finally {
1060
+ if (e) throw e.error;
1061
+ }
1062
+ }
1063
+ return ar;
1064
+ };
1065
+ var __spreadArray2 = function(to, from, pack) {
1066
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
1067
+ if (ar || !(i in from)) {
1068
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
1069
+ ar[i] = from[i];
1070
+ }
1071
+ }
1072
+ return to.concat(ar || Array.prototype.slice.call(from));
1073
+ };
1074
+ var API_NAME = "diag";
1075
+ var DiagAPI = (
1076
+ /** @class */
1077
+ function() {
1078
+ function DiagAPI2() {
1079
+ function _logProxy(funcName) {
1080
+ return function() {
1081
+ var args = [];
1082
+ for (var _i = 0; _i < arguments.length; _i++) {
1083
+ args[_i] = arguments[_i];
1084
+ }
1085
+ var logger = getGlobal("diag");
1086
+ if (!logger)
1087
+ return;
1088
+ return logger[funcName].apply(logger, __spreadArray2([], __read2(args), false));
1089
+ };
1090
+ }
1091
+ var self = this;
1092
+ var setLogger = function(logger, optionsOrLogLevel) {
1093
+ var _a, _b, _c;
1094
+ if (optionsOrLogLevel === void 0) {
1095
+ optionsOrLogLevel = { logLevel: DiagLogLevel.INFO };
1096
+ }
1097
+ if (logger === self) {
1098
+ var err = new Error("Cannot use diag as the logger for itself. Please use a DiagLogger implementation like ConsoleDiagLogger or a custom implementation");
1099
+ self.error((_a = err.stack) !== null && _a !== void 0 ? _a : err.message);
1100
+ return false;
1101
+ }
1102
+ if (typeof optionsOrLogLevel === "number") {
1103
+ optionsOrLogLevel = {
1104
+ logLevel: optionsOrLogLevel
1105
+ };
1106
+ }
1107
+ var oldLogger = getGlobal("diag");
1108
+ var newLogger = createLogLevelDiagLogger((_b = optionsOrLogLevel.logLevel) !== null && _b !== void 0 ? _b : DiagLogLevel.INFO, logger);
1109
+ if (oldLogger && !optionsOrLogLevel.suppressOverrideMessage) {
1110
+ var stack = (_c = new Error().stack) !== null && _c !== void 0 ? _c : "<failed to generate stacktrace>";
1111
+ oldLogger.warn("Current logger will be overwritten from " + stack);
1112
+ newLogger.warn("Current logger will overwrite one already registered from " + stack);
1113
+ }
1114
+ return registerGlobal("diag", newLogger, self, true);
1115
+ };
1116
+ self.setLogger = setLogger;
1117
+ self.disable = function() {
1118
+ unregisterGlobal(API_NAME, self);
1119
+ };
1120
+ self.createComponentLogger = function(options) {
1121
+ return new DiagComponentLogger(options);
1122
+ };
1123
+ self.verbose = _logProxy("verbose");
1124
+ self.debug = _logProxy("debug");
1125
+ self.info = _logProxy("info");
1126
+ self.warn = _logProxy("warn");
1127
+ self.error = _logProxy("error");
1128
+ }
1129
+ DiagAPI2.instance = function() {
1130
+ if (!this._instance) {
1131
+ this._instance = new DiagAPI2();
1132
+ }
1133
+ return this._instance;
1134
+ };
1135
+ return DiagAPI2;
1136
+ }()
1137
+ );
1138
+
1139
+ // node_modules/@opentelemetry/api/build/esm/context/context.js
1140
+ function createContextKey(description) {
1141
+ return Symbol.for(description);
1142
+ }
1143
+ var BaseContext = (
1144
+ /** @class */
1145
+ /* @__PURE__ */ function() {
1146
+ function BaseContext2(parentContext) {
1147
+ var self = this;
1148
+ self._currentContext = parentContext ? new Map(parentContext) : /* @__PURE__ */ new Map();
1149
+ self.getValue = function(key) {
1150
+ return self._currentContext.get(key);
1151
+ };
1152
+ self.setValue = function(key, value) {
1153
+ var context2 = new BaseContext2(self._currentContext);
1154
+ context2._currentContext.set(key, value);
1155
+ return context2;
1156
+ };
1157
+ self.deleteValue = function(key) {
1158
+ var context2 = new BaseContext2(self._currentContext);
1159
+ context2._currentContext.delete(key);
1160
+ return context2;
1161
+ };
1162
+ }
1163
+ return BaseContext2;
1164
+ }()
1165
+ );
1166
+ var ROOT_CONTEXT = new BaseContext();
1167
+
1168
+ // node_modules/@opentelemetry/api/build/esm/context/NoopContextManager.js
1169
+ var __read3 = function(o, n) {
1170
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
1171
+ if (!m) return o;
1172
+ var i = m.call(o), r, ar = [], e;
1173
+ try {
1174
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
1175
+ } catch (error) {
1176
+ e = { error };
1177
+ } finally {
1178
+ try {
1179
+ if (r && !r.done && (m = i["return"])) m.call(i);
1180
+ } finally {
1181
+ if (e) throw e.error;
1182
+ }
1183
+ }
1184
+ return ar;
1185
+ };
1186
+ var __spreadArray3 = function(to, from, pack) {
1187
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
1188
+ if (ar || !(i in from)) {
1189
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
1190
+ ar[i] = from[i];
1191
+ }
1192
+ }
1193
+ return to.concat(ar || Array.prototype.slice.call(from));
1194
+ };
1195
+ var NoopContextManager = (
1196
+ /** @class */
1197
+ function() {
1198
+ function NoopContextManager2() {
1199
+ }
1200
+ NoopContextManager2.prototype.active = function() {
1201
+ return ROOT_CONTEXT;
1202
+ };
1203
+ NoopContextManager2.prototype.with = function(_context, fn, thisArg) {
1204
+ var args = [];
1205
+ for (var _i = 3; _i < arguments.length; _i++) {
1206
+ args[_i - 3] = arguments[_i];
1207
+ }
1208
+ return fn.call.apply(fn, __spreadArray3([thisArg], __read3(args), false));
1209
+ };
1210
+ NoopContextManager2.prototype.bind = function(_context, target) {
1211
+ return target;
1212
+ };
1213
+ NoopContextManager2.prototype.enable = function() {
1214
+ return this;
1215
+ };
1216
+ NoopContextManager2.prototype.disable = function() {
1217
+ return this;
1218
+ };
1219
+ return NoopContextManager2;
1220
+ }()
1221
+ );
1222
+
1223
+ // node_modules/@opentelemetry/api/build/esm/api/context.js
1224
+ var __read4 = function(o, n) {
1225
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
1226
+ if (!m) return o;
1227
+ var i = m.call(o), r, ar = [], e;
1228
+ try {
1229
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
1230
+ } catch (error) {
1231
+ e = { error };
1232
+ } finally {
1233
+ try {
1234
+ if (r && !r.done && (m = i["return"])) m.call(i);
1235
+ } finally {
1236
+ if (e) throw e.error;
1237
+ }
1238
+ }
1239
+ return ar;
1240
+ };
1241
+ var __spreadArray4 = function(to, from, pack) {
1242
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
1243
+ if (ar || !(i in from)) {
1244
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
1245
+ ar[i] = from[i];
1246
+ }
1247
+ }
1248
+ return to.concat(ar || Array.prototype.slice.call(from));
1249
+ };
1250
+ var API_NAME2 = "context";
1251
+ var NOOP_CONTEXT_MANAGER = new NoopContextManager();
1252
+ var ContextAPI = (
1253
+ /** @class */
1254
+ function() {
1255
+ function ContextAPI2() {
1256
+ }
1257
+ ContextAPI2.getInstance = function() {
1258
+ if (!this._instance) {
1259
+ this._instance = new ContextAPI2();
1260
+ }
1261
+ return this._instance;
1262
+ };
1263
+ ContextAPI2.prototype.setGlobalContextManager = function(contextManager) {
1264
+ return registerGlobal(API_NAME2, contextManager, DiagAPI.instance());
1265
+ };
1266
+ ContextAPI2.prototype.active = function() {
1267
+ return this._getContextManager().active();
1268
+ };
1269
+ ContextAPI2.prototype.with = function(context2, fn, thisArg) {
1270
+ var _a;
1271
+ var args = [];
1272
+ for (var _i = 3; _i < arguments.length; _i++) {
1273
+ args[_i - 3] = arguments[_i];
1274
+ }
1275
+ return (_a = this._getContextManager()).with.apply(_a, __spreadArray4([context2, fn, thisArg], __read4(args), false));
1276
+ };
1277
+ ContextAPI2.prototype.bind = function(context2, target) {
1278
+ return this._getContextManager().bind(context2, target);
1279
+ };
1280
+ ContextAPI2.prototype._getContextManager = function() {
1281
+ return getGlobal(API_NAME2) || NOOP_CONTEXT_MANAGER;
1282
+ };
1283
+ ContextAPI2.prototype.disable = function() {
1284
+ this._getContextManager().disable();
1285
+ unregisterGlobal(API_NAME2, DiagAPI.instance());
1286
+ };
1287
+ return ContextAPI2;
1288
+ }()
1289
+ );
1290
+
1291
+ // node_modules/@opentelemetry/api/build/esm/trace/trace_flags.js
1292
+ var TraceFlags;
1293
+ (function(TraceFlags2) {
1294
+ TraceFlags2[TraceFlags2["NONE"] = 0] = "NONE";
1295
+ TraceFlags2[TraceFlags2["SAMPLED"] = 1] = "SAMPLED";
1296
+ })(TraceFlags || (TraceFlags = {}));
1297
+
1298
+ // node_modules/@opentelemetry/api/build/esm/trace/invalid-span-constants.js
1299
+ var INVALID_SPANID = "0000000000000000";
1300
+ var INVALID_TRACEID = "00000000000000000000000000000000";
1301
+ var INVALID_SPAN_CONTEXT = {
1302
+ traceId: INVALID_TRACEID,
1303
+ spanId: INVALID_SPANID,
1304
+ traceFlags: TraceFlags.NONE
1305
+ };
1306
+
1307
+ // node_modules/@opentelemetry/api/build/esm/trace/NonRecordingSpan.js
1308
+ var NonRecordingSpan = (
1309
+ /** @class */
1310
+ function() {
1311
+ function NonRecordingSpan2(_spanContext) {
1312
+ if (_spanContext === void 0) {
1313
+ _spanContext = INVALID_SPAN_CONTEXT;
1314
+ }
1315
+ this._spanContext = _spanContext;
1316
+ }
1317
+ NonRecordingSpan2.prototype.spanContext = function() {
1318
+ return this._spanContext;
1319
+ };
1320
+ NonRecordingSpan2.prototype.setAttribute = function(_key, _value) {
1321
+ return this;
1322
+ };
1323
+ NonRecordingSpan2.prototype.setAttributes = function(_attributes) {
1324
+ return this;
1325
+ };
1326
+ NonRecordingSpan2.prototype.addEvent = function(_name, _attributes) {
1327
+ return this;
1328
+ };
1329
+ NonRecordingSpan2.prototype.setStatus = function(_status) {
1330
+ return this;
1331
+ };
1332
+ NonRecordingSpan2.prototype.updateName = function(_name) {
1333
+ return this;
1334
+ };
1335
+ NonRecordingSpan2.prototype.end = function(_endTime) {
1336
+ };
1337
+ NonRecordingSpan2.prototype.isRecording = function() {
1338
+ return false;
1339
+ };
1340
+ NonRecordingSpan2.prototype.recordException = function(_exception, _time) {
1341
+ };
1342
+ return NonRecordingSpan2;
1343
+ }()
1344
+ );
1345
+
1346
+ // node_modules/@opentelemetry/api/build/esm/trace/context-utils.js
1347
+ var SPAN_KEY = createContextKey("OpenTelemetry Context Key SPAN");
1348
+ function getSpan(context2) {
1349
+ return context2.getValue(SPAN_KEY) || void 0;
1350
+ }
1351
+ function getActiveSpan() {
1352
+ return getSpan(ContextAPI.getInstance().active());
1353
+ }
1354
+ function setSpan(context2, span) {
1355
+ return context2.setValue(SPAN_KEY, span);
1356
+ }
1357
+ function deleteSpan(context2) {
1358
+ return context2.deleteValue(SPAN_KEY);
1359
+ }
1360
+ function setSpanContext(context2, spanContext) {
1361
+ return setSpan(context2, new NonRecordingSpan(spanContext));
1362
+ }
1363
+ function getSpanContext(context2) {
1364
+ var _a;
1365
+ return (_a = getSpan(context2)) === null || _a === void 0 ? void 0 : _a.spanContext();
1366
+ }
1367
+
1368
+ // node_modules/@opentelemetry/api/build/esm/trace/spancontext-utils.js
1369
+ var VALID_TRACEID_REGEX = /^([0-9a-f]{32})$/i;
1370
+ var VALID_SPANID_REGEX = /^[0-9a-f]{16}$/i;
1371
+ function isValidTraceId(traceId) {
1372
+ return VALID_TRACEID_REGEX.test(traceId) && traceId !== INVALID_TRACEID;
1373
+ }
1374
+ function isValidSpanId(spanId) {
1375
+ return VALID_SPANID_REGEX.test(spanId) && spanId !== INVALID_SPANID;
1376
+ }
1377
+ function isSpanContextValid(spanContext) {
1378
+ return isValidTraceId(spanContext.traceId) && isValidSpanId(spanContext.spanId);
1379
+ }
1380
+ function wrapSpanContext(spanContext) {
1381
+ return new NonRecordingSpan(spanContext);
1382
+ }
1383
+
1384
+ // node_modules/@opentelemetry/api/build/esm/trace/NoopTracer.js
1385
+ var contextApi = ContextAPI.getInstance();
1386
+ var NoopTracer = (
1387
+ /** @class */
1388
+ function() {
1389
+ function NoopTracer2() {
1390
+ }
1391
+ NoopTracer2.prototype.startSpan = function(name, options, context2) {
1392
+ if (context2 === void 0) {
1393
+ context2 = contextApi.active();
1394
+ }
1395
+ var root = Boolean(options === null || options === void 0 ? void 0 : options.root);
1396
+ if (root) {
1397
+ return new NonRecordingSpan();
1398
+ }
1399
+ var parentFromContext = context2 && getSpanContext(context2);
1400
+ if (isSpanContext(parentFromContext) && isSpanContextValid(parentFromContext)) {
1401
+ return new NonRecordingSpan(parentFromContext);
1402
+ } else {
1403
+ return new NonRecordingSpan();
1404
+ }
1405
+ };
1406
+ NoopTracer2.prototype.startActiveSpan = function(name, arg2, arg3, arg4) {
1407
+ var opts;
1408
+ var ctx;
1409
+ var fn;
1410
+ if (arguments.length < 2) {
1411
+ return;
1412
+ } else if (arguments.length === 2) {
1413
+ fn = arg2;
1414
+ } else if (arguments.length === 3) {
1415
+ opts = arg2;
1416
+ fn = arg3;
1417
+ } else {
1418
+ opts = arg2;
1419
+ ctx = arg3;
1420
+ fn = arg4;
1421
+ }
1422
+ var parentContext = ctx !== null && ctx !== void 0 ? ctx : contextApi.active();
1423
+ var span = this.startSpan(name, opts, parentContext);
1424
+ var contextWithSpanSet = setSpan(parentContext, span);
1425
+ return contextApi.with(contextWithSpanSet, fn, void 0, span);
1426
+ };
1427
+ return NoopTracer2;
1428
+ }()
1429
+ );
1430
+ function isSpanContext(spanContext) {
1431
+ return typeof spanContext === "object" && typeof spanContext["spanId"] === "string" && typeof spanContext["traceId"] === "string" && typeof spanContext["traceFlags"] === "number";
1432
+ }
1433
+
1434
+ // node_modules/@opentelemetry/api/build/esm/trace/ProxyTracer.js
1435
+ var NOOP_TRACER = new NoopTracer();
1436
+ var ProxyTracer = (
1437
+ /** @class */
1438
+ function() {
1439
+ function ProxyTracer2(_provider, name, version, options) {
1440
+ this._provider = _provider;
1441
+ this.name = name;
1442
+ this.version = version;
1443
+ this.options = options;
1444
+ }
1445
+ ProxyTracer2.prototype.startSpan = function(name, options, context2) {
1446
+ return this._getTracer().startSpan(name, options, context2);
1447
+ };
1448
+ ProxyTracer2.prototype.startActiveSpan = function(_name, _options, _context, _fn) {
1449
+ var tracer2 = this._getTracer();
1450
+ return Reflect.apply(tracer2.startActiveSpan, tracer2, arguments);
1451
+ };
1452
+ ProxyTracer2.prototype._getTracer = function() {
1453
+ if (this._delegate) {
1454
+ return this._delegate;
1455
+ }
1456
+ var tracer2 = this._provider.getDelegateTracer(this.name, this.version, this.options);
1457
+ if (!tracer2) {
1458
+ return NOOP_TRACER;
1459
+ }
1460
+ this._delegate = tracer2;
1461
+ return this._delegate;
1462
+ };
1463
+ return ProxyTracer2;
1464
+ }()
1465
+ );
1466
+
1467
+ // node_modules/@opentelemetry/api/build/esm/trace/NoopTracerProvider.js
1468
+ var NoopTracerProvider = (
1469
+ /** @class */
1470
+ function() {
1471
+ function NoopTracerProvider2() {
1472
+ }
1473
+ NoopTracerProvider2.prototype.getTracer = function(_name, _version, _options) {
1474
+ return new NoopTracer();
1475
+ };
1476
+ return NoopTracerProvider2;
1477
+ }()
1478
+ );
1479
+
1480
+ // node_modules/@opentelemetry/api/build/esm/trace/ProxyTracerProvider.js
1481
+ var NOOP_TRACER_PROVIDER = new NoopTracerProvider();
1482
+ var ProxyTracerProvider = (
1483
+ /** @class */
1484
+ function() {
1485
+ function ProxyTracerProvider2() {
1486
+ }
1487
+ ProxyTracerProvider2.prototype.getTracer = function(name, version, options) {
1488
+ var _a;
1489
+ return (_a = this.getDelegateTracer(name, version, options)) !== null && _a !== void 0 ? _a : new ProxyTracer(this, name, version, options);
1490
+ };
1491
+ ProxyTracerProvider2.prototype.getDelegate = function() {
1492
+ var _a;
1493
+ return (_a = this._delegate) !== null && _a !== void 0 ? _a : NOOP_TRACER_PROVIDER;
1494
+ };
1495
+ ProxyTracerProvider2.prototype.setDelegate = function(delegate) {
1496
+ this._delegate = delegate;
1497
+ };
1498
+ ProxyTracerProvider2.prototype.getDelegateTracer = function(name, version, options) {
1499
+ var _a;
1500
+ return (_a = this._delegate) === null || _a === void 0 ? void 0 : _a.getTracer(name, version, options);
1501
+ };
1502
+ return ProxyTracerProvider2;
1503
+ }()
1504
+ );
1505
+
1506
+ // node_modules/@opentelemetry/api/build/esm/trace/status.js
1507
+ var SpanStatusCode;
1508
+ (function(SpanStatusCode2) {
1509
+ SpanStatusCode2[SpanStatusCode2["UNSET"] = 0] = "UNSET";
1510
+ SpanStatusCode2[SpanStatusCode2["OK"] = 1] = "OK";
1511
+ SpanStatusCode2[SpanStatusCode2["ERROR"] = 2] = "ERROR";
1512
+ })(SpanStatusCode || (SpanStatusCode = {}));
1513
+
1514
+ // node_modules/@opentelemetry/api/build/esm/context-api.js
1515
+ var context = ContextAPI.getInstance();
1516
+
1517
+ // node_modules/@opentelemetry/api/build/esm/api/trace.js
1518
+ var API_NAME3 = "trace";
1519
+ var TraceAPI = (
1520
+ /** @class */
1521
+ function() {
1522
+ function TraceAPI2() {
1523
+ this._proxyTracerProvider = new ProxyTracerProvider();
1524
+ this.wrapSpanContext = wrapSpanContext;
1525
+ this.isSpanContextValid = isSpanContextValid;
1526
+ this.deleteSpan = deleteSpan;
1527
+ this.getSpan = getSpan;
1528
+ this.getActiveSpan = getActiveSpan;
1529
+ this.getSpanContext = getSpanContext;
1530
+ this.setSpan = setSpan;
1531
+ this.setSpanContext = setSpanContext;
1532
+ }
1533
+ TraceAPI2.getInstance = function() {
1534
+ if (!this._instance) {
1535
+ this._instance = new TraceAPI2();
1536
+ }
1537
+ return this._instance;
1538
+ };
1539
+ TraceAPI2.prototype.setGlobalTracerProvider = function(provider) {
1540
+ var success = registerGlobal(API_NAME3, this._proxyTracerProvider, DiagAPI.instance());
1541
+ if (success) {
1542
+ this._proxyTracerProvider.setDelegate(provider);
1543
+ }
1544
+ return success;
1545
+ };
1546
+ TraceAPI2.prototype.getTracerProvider = function() {
1547
+ return getGlobal(API_NAME3) || this._proxyTracerProvider;
1548
+ };
1549
+ TraceAPI2.prototype.getTracer = function(name, version) {
1550
+ return this.getTracerProvider().getTracer(name, version);
1551
+ };
1552
+ TraceAPI2.prototype.disable = function() {
1553
+ unregisterGlobal(API_NAME3, DiagAPI.instance());
1554
+ this._proxyTracerProvider = new ProxyTracerProvider();
1555
+ };
1556
+ return TraceAPI2;
1557
+ }()
1558
+ );
1559
+
1560
+ // node_modules/@opentelemetry/api/build/esm/trace-api.js
1561
+ var trace = TraceAPI.getInstance();
1562
+
1563
+ // node_modules/@opentelemetry/api/build/esm/experimental/trace/SugaredTracer.js
1564
+ var defaultOnException = function(e, span) {
1565
+ span.recordException(e);
1566
+ span.setStatus({
1567
+ code: SpanStatusCode.ERROR
1568
+ });
1569
+ };
1570
+ function wrapTracer(tracer2) {
1571
+ return new SugaredTracer(tracer2);
1572
+ }
1573
+ var SugaredTracer = (
1574
+ /** @class */
1575
+ function() {
1576
+ function SugaredTracer3(tracer2) {
1577
+ this._tracer = tracer2;
1578
+ this.startSpan = tracer2.startSpan.bind(this._tracer);
1579
+ this.startActiveSpan = tracer2.startActiveSpan.bind(this._tracer);
1580
+ }
1581
+ SugaredTracer3.prototype.withActiveSpan = function(name, arg2, arg3, arg4) {
1582
+ var _a = massageParams(arg2, arg3, arg4), opts = _a.opts, ctx = _a.ctx, fn = _a.fn;
1583
+ return this._tracer.startActiveSpan(name, opts, ctx, function(span) {
1584
+ return handleFn(span, opts, fn);
1585
+ });
1586
+ };
1587
+ SugaredTracer3.prototype.withSpan = function(name, arg2, arg3, arg4) {
1588
+ var _a = massageParams(arg2, arg3, arg4), opts = _a.opts, ctx = _a.ctx, fn = _a.fn;
1589
+ var span = this._tracer.startSpan(name, opts, ctx);
1590
+ return handleFn(span, opts, fn);
1591
+ };
1592
+ return SugaredTracer3;
1593
+ }()
1594
+ );
1595
+ function massageParams(arg, arg2, arg3) {
1596
+ var opts;
1597
+ var ctx;
1598
+ var fn;
1599
+ if (!arg2 && !arg3) {
1600
+ fn = arg;
1601
+ } else if (!arg3) {
1602
+ opts = arg;
1603
+ fn = arg2;
1604
+ } else {
1605
+ opts = arg;
1606
+ ctx = arg2;
1607
+ fn = arg3;
1608
+ }
1609
+ opts = opts !== null && opts !== void 0 ? opts : {};
1610
+ ctx = ctx !== null && ctx !== void 0 ? ctx : context.active();
1611
+ return { opts, ctx, fn };
1612
+ }
1613
+ function handleFn(span, opts, fn) {
1614
+ var _a;
1615
+ var onException = (_a = opts.onException) !== null && _a !== void 0 ? _a : defaultOnException;
1616
+ var errorHandler = function(e) {
1617
+ onException(e, span);
1618
+ span.end();
1619
+ throw e;
1620
+ };
1621
+ try {
1622
+ var ret = fn(span);
1623
+ if (typeof (ret === null || ret === void 0 ? void 0 : ret.then) === "function") {
1624
+ return ret.then(function(val) {
1625
+ span.end();
1626
+ return val;
1627
+ }, errorHandler);
1628
+ }
1629
+ span.end();
1630
+ return ret;
1631
+ } catch (e) {
1632
+ throw errorHandler(e);
1633
+ }
1634
+ }
1635
+
1636
+ // src/run/handlers/tracer.cts
1637
+ var spanMeta = /* @__PURE__ */ new WeakMap();
1638
+ var spanCounter = /* @__PURE__ */ new WeakMap();
1639
+ function spanHook(span) {
1640
+ const originalEnd = span.end.bind(span);
1641
+ span.end = (endTime) => {
1642
+ originalEnd(endTime);
1643
+ const meta = spanMeta.get(span);
1644
+ if (meta) {
1645
+ const requestContext = getRequestContext();
1646
+ if (requestContext?.captureServerTiming) {
1647
+ const duration = (typeof endTime === "number" ? endTime : performance.now()) - meta.start;
1648
+ const serverTiming = requestContext.serverTiming ?? "";
1649
+ const currentRequestSpanCounter = spanCounter.get(requestContext) ?? 1;
1650
+ requestContext.serverTiming = `${serverTiming}${serverTiming.length === 0 ? "" : ", "}s${currentRequestSpanCounter};dur=${duration};desc="${meta.name}"`;
1651
+ spanCounter.set(requestContext, currentRequestSpanCounter + 1);
1652
+ }
1653
+ }
1654
+ spanMeta.delete(span);
1655
+ };
1656
+ return span;
1657
+ }
1658
+ var tracer;
1659
+ function getTracer() {
1660
+ if (!tracer) {
1661
+ const baseTracer = trace.getTracer("Next.js Runtime");
1662
+ const startSpan = baseTracer.startSpan.bind(baseTracer);
1663
+ baseTracer.startSpan = (...args) => {
1664
+ const span = startSpan(...args);
1665
+ spanMeta.set(span, { start: performance.now(), name: args[0] });
1666
+ return spanHook(span);
1667
+ };
1668
+ const startActiveSpan = baseTracer.startActiveSpan.bind(baseTracer);
1669
+ baseTracer.startActiveSpan = (...args) => {
1670
+ const [name, ...restOfArgs] = args;
1671
+ const augmentedArgs = restOfArgs.map((arg) => {
1672
+ if (typeof arg === "function") {
1673
+ return (span) => {
1674
+ spanMeta.set(span, { start: performance.now(), name: args[0] });
1675
+ spanHook(span);
1676
+ return arg(span);
1677
+ };
1678
+ }
1679
+ return arg;
1680
+ });
1681
+ return startActiveSpan(name, ...augmentedArgs);
1682
+ };
1683
+ tracer = wrapTracer(baseTracer);
1684
+ }
1685
+ return tracer;
1686
+ }
1687
+
1688
+ // src/run/handlers/cache.cts
102
1689
  var NetlifyCacheHandler = class {
103
1690
  options;
104
1691
  revalidatedTags;
105
1692
  blobStore;
106
- tracer = (0, import_tracer.getTracer)();
1693
+ tracer = getTracer();
107
1694
  tagManifestsFetchedFromBlobStoreInCurrentRequest;
108
1695
  constructor(options) {
109
1696
  this.options = options;
110
1697
  this.revalidatedTags = options.revalidatedTags;
111
- this.blobStore = (0, import_regional_blob_store.getRegionalBlobStore)({ consistency: "strong" });
1698
+ this.blobStore = getRegionalBlobStore({ consistency: "strong" });
112
1699
  this.tagManifestsFetchedFromBlobStoreInCurrentRequest = {};
113
1700
  }
114
1701
  async encodeBlobKey(key) {
115
- const { encodeBlobKey } = await import("../../shared/blobkey.js");
116
- return await encodeBlobKey(key);
1702
+ const { encodeBlobKey: encodeBlobKey2 } = await Promise.resolve().then(() => (init_blobkey(), blobkey_exports));
1703
+ return await encodeBlobKey2(key);
117
1704
  }
118
1705
  captureResponseCacheLastModified(cacheValue, key, getCacheKeySpan) {
119
1706
  if (cacheValue.value?.kind === "FETCH") {
120
1707
  return;
121
1708
  }
122
- const requestContext = (0, import_request_context.getRequestContext)();
1709
+ const requestContext = getRequestContext();
123
1710
  if (!requestContext) {
124
1711
  getCacheKeySpan.recordException(
125
1712
  new Error("CacheHandler was called without a request context")
@@ -150,7 +1737,7 @@ var NetlifyCacheHandler = class {
150
1737
  }
151
1738
  captureRouteRevalidateAndRemoveFromObject(cacheValue) {
152
1739
  const { revalidate, ...restOfRouteValue } = cacheValue;
153
- const requestContext = (0, import_request_context.getRequestContext)();
1740
+ const requestContext = getRequestContext();
154
1741
  if (requestContext) {
155
1742
  requestContext.routeHandlerRevalidate = revalidate;
156
1743
  }
@@ -160,7 +1747,7 @@ var NetlifyCacheHandler = class {
160
1747
  if (!cacheValue) {
161
1748
  return;
162
1749
  }
163
- const requestContext = (0, import_request_context.getRequestContext)();
1750
+ const requestContext = getRequestContext();
164
1751
  if (!requestContext) {
165
1752
  return;
166
1753
  }
@@ -207,7 +1794,7 @@ var NetlifyCacheHandler = class {
207
1794
  async get(...args) {
208
1795
  return this.tracer.withActiveSpan("get cache key", async (span) => {
209
1796
  const [key, ctx = {}] = args;
210
- (0, import_request_context.getLogger)().debug(`[NetlifyCacheHandler.get]: ${key}`);
1797
+ getLogger().debug(`[NetlifyCacheHandler.get]: ${key}`);
211
1798
  const blobKey = await this.encodeBlobKey(key);
212
1799
  span.setAttributes({ key, blobKey });
213
1800
  const blob = await this.tracer.withActiveSpan("blobStore.get", async (blobGetSpan) => {
@@ -245,7 +1832,7 @@ var NetlifyCacheHandler = class {
245
1832
  lastModified: blob.lastModified,
246
1833
  value: {
247
1834
  ...valueWithoutRevalidate,
248
- body: import_node_buffer.Buffer.from(valueWithoutRevalidate.body, "base64")
1835
+ body: import_node_buffer2.Buffer.from(valueWithoutRevalidate.body, "base64")
249
1836
  }
250
1837
  };
251
1838
  }
@@ -267,7 +1854,7 @@ var NetlifyCacheHandler = class {
267
1854
  lastModified: blob.lastModified,
268
1855
  value: {
269
1856
  ...restOfPageValue,
270
- rscData: rscData ? import_node_buffer.Buffer.from(rscData, "base64") : void 0
1857
+ rscData: rscData ? import_node_buffer2.Buffer.from(rscData, "base64") : void 0
271
1858
  }
272
1859
  };
273
1860
  }
@@ -277,27 +1864,27 @@ var NetlifyCacheHandler = class {
277
1864
  return null;
278
1865
  });
279
1866
  }
280
- transformToStorableObject(data, context) {
1867
+ transformToStorableObject(data, context2) {
281
1868
  if (!data) {
282
1869
  return null;
283
1870
  }
284
- if ((0, import_cache_types.isCachedRouteValue)(data)) {
1871
+ if (isCachedRouteValue(data)) {
285
1872
  return {
286
1873
  ...data,
287
- revalidate: context.revalidate,
1874
+ revalidate: context2.revalidate,
288
1875
  body: data.body.toString("base64")
289
1876
  };
290
1877
  }
291
- if ((0, import_cache_types.isCachedPageValue)(data)) {
1878
+ if (isCachedPageValue(data)) {
292
1879
  return {
293
1880
  ...data,
294
- revalidate: context.revalidate
1881
+ revalidate: context2.revalidate
295
1882
  };
296
1883
  }
297
1884
  if (data?.kind === "APP_PAGE") {
298
1885
  return {
299
1886
  ...data,
300
- revalidate: context.revalidate,
1887
+ revalidate: context2.revalidate,
301
1888
  rscData: data.rscData?.toString("base64")
302
1889
  };
303
1890
  }
@@ -305,25 +1892,25 @@ var NetlifyCacheHandler = class {
305
1892
  }
306
1893
  async set(...args) {
307
1894
  return this.tracer.withActiveSpan("set cache key", async (span) => {
308
- const [key, data, context] = args;
1895
+ const [key, data, context2] = args;
309
1896
  const blobKey = await this.encodeBlobKey(key);
310
1897
  const lastModified = Date.now();
311
1898
  span.setAttributes({ key, lastModified, blobKey });
312
- (0, import_request_context.getLogger)().debug(`[NetlifyCacheHandler.set]: ${key}`);
313
- const value = this.transformToStorableObject(data, context);
1899
+ getLogger().debug(`[NetlifyCacheHandler.set]: ${key}`);
1900
+ const value = this.transformToStorableObject(data, context2);
314
1901
  this.captureCacheTags(value, key);
315
1902
  await this.blobStore.setJSON(blobKey, {
316
1903
  lastModified,
317
1904
  value
318
1905
  });
319
1906
  if (data?.kind === "PAGE" || data?.kind === "PAGES") {
320
- const requestContext = (0, import_request_context.getRequestContext)();
1907
+ const requestContext = getRequestContext();
321
1908
  if (requestContext?.didPagesRouterOnDemandRevalidate) {
322
1909
  const tag = `_N_T_${key === "/index" ? "/" : encodeURI(key)}`;
323
- (0, import_request_context.getLogger)().debug(`Purging CDN cache for: [${tag}]`);
1910
+ getLogger().debug(`Purging CDN cache for: [${tag}]`);
324
1911
  requestContext.trackBackgroundWork(
325
1912
  purgeCache({ tags: tag.split(/,|%2c/gi) }).catch((error) => {
326
- (0, import_request_context.getLogger)().withError(error).error(`[NetlifyCacheHandler]: Purging the cache for tag ${tag} failed`);
1913
+ getLogger().withError(error).error(`[NetlifyCacheHandler]: Purging the cache for tag ${tag} failed`);
327
1914
  })
328
1915
  );
329
1916
  }
@@ -333,7 +1920,7 @@ var NetlifyCacheHandler = class {
333
1920
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
334
1921
  async revalidateTag(tagOrTags, ...args) {
335
1922
  const revalidateTagPromise = this.doRevalidateTag(tagOrTags, ...args);
336
- const requestContext = (0, import_request_context.getRequestContext)();
1923
+ const requestContext = getRequestContext();
337
1924
  if (requestContext) {
338
1925
  requestContext.trackBackgroundWork(revalidateTagPromise);
339
1926
  }
@@ -341,7 +1928,7 @@ var NetlifyCacheHandler = class {
341
1928
  }
342
1929
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
343
1930
  async doRevalidateTag(tagOrTags, ...args) {
344
- (0, import_request_context.getLogger)().withFields({ tagOrTags, args }).debug("NetlifyCacheHandler.revalidateTag");
1931
+ getLogger().withFields({ tagOrTags, args }).debug("NetlifyCacheHandler.revalidateTag");
345
1932
  const tags = (Array.isArray(tagOrTags) ? tagOrTags : [tagOrTags]).flatMap(
346
1933
  (tag) => tag.split(/,|%2c/gi)
347
1934
  );
@@ -353,12 +1940,12 @@ var NetlifyCacheHandler = class {
353
1940
  try {
354
1941
  await this.blobStore.setJSON(await this.encodeBlobKey(tag), data);
355
1942
  } catch (error) {
356
- (0, import_request_context.getLogger)().withError(error).log(`Failed to update tag manifest for ${tag}`);
1943
+ getLogger().withError(error).log(`Failed to update tag manifest for ${tag}`);
357
1944
  }
358
1945
  })
359
1946
  );
360
1947
  await purgeCache({ tags }).catch((error) => {
361
- (0, import_request_context.getLogger)().withError(error).error(`[NetlifyCacheHandler]: Purging the cache for tags ${tags.join(", ")} failed`);
1948
+ getLogger().withError(error).error(`[NetlifyCacheHandler]: Purging the cache for tags ${tags.join(", ")} failed`);
362
1949
  });
363
1950
  }
364
1951
  resetRequestCache() {