@netlify/plugin-nextjs 5.1.2 → 5.2.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.
Files changed (43) hide show
  1. package/dist/build/advanced-api-routes.js +121 -4
  2. package/dist/build/cache.js +25 -4
  3. package/dist/build/content/prerendered.js +237 -8
  4. package/dist/build/content/server.js +259 -14
  5. package/dist/build/content/static.js +96 -11
  6. package/dist/build/functions/edge.js +511 -5
  7. package/dist/build/functions/server.js +131 -12
  8. package/dist/build/image-cdn.js +1615 -3
  9. package/dist/build/plugin-context.js +236 -5
  10. package/dist/build/templates/handler-monorepo.tmpl.js +3 -0
  11. package/dist/build/templates/handler.tmpl.js +3 -0
  12. package/dist/build/verification.js +81 -8
  13. package/dist/esm-chunks/{package-RVJOBSMH.js → package-SCUAWNXR.js} +23 -23
  14. package/dist/index.js +25 -36
  15. package/dist/run/config.js +25 -6
  16. package/dist/run/constants.js +7 -5
  17. package/dist/run/handlers/cache.cjs +6 -567
  18. package/dist/run/handlers/request-context.cjs +8 -1
  19. package/dist/run/handlers/server.js +20 -22
  20. package/dist/run/handlers/tracing.js +27022 -10456
  21. package/dist/run/headers.js +198 -8
  22. package/dist/run/next.cjs +106 -655
  23. package/dist/{esm-chunks/chunk-PMRBBOBY.js → run/regional-blob-store.cjs} +117 -263
  24. package/dist/run/revalidate.js +17 -3
  25. package/dist/run/systemlog.js +94 -3
  26. package/dist/shared/blobkey.js +15 -3
  27. package/edge-runtime/lib/response.ts +3 -2
  28. package/package.json +1 -1
  29. package/dist/esm-chunks/chunk-3SUDZQ7L.js +0 -40
  30. package/dist/esm-chunks/chunk-4BNHE6TP.js +0 -278
  31. package/dist/esm-chunks/chunk-72ZI2IVI.js +0 -36
  32. package/dist/esm-chunks/chunk-BG455SFE.js +0 -133
  33. package/dist/esm-chunks/chunk-HESS57SH.js +0 -127
  34. package/dist/esm-chunks/chunk-HYBEXB2Z.js +0 -105
  35. package/dist/esm-chunks/chunk-K7BTUM7O.js +0 -97
  36. package/dist/esm-chunks/chunk-L6OM53B6.js +0 -238
  37. package/dist/esm-chunks/chunk-MCEOSJH6.js +0 -1637
  38. package/dist/esm-chunks/chunk-MRD3XSKD.js +0 -248
  39. package/dist/esm-chunks/chunk-RL4K4CVH.js +0 -27
  40. package/dist/esm-chunks/chunk-TYCYFZ22.js +0 -25
  41. package/dist/esm-chunks/chunk-UTQSBE5O.js +0 -524
  42. package/dist/esm-chunks/chunk-UYKENJEU.js +0 -19
  43. package/dist/esm-chunks/chunk-V2T6NUOM.js +0 -113
@@ -5,9 +5,6 @@ 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
- };
11
8
  var __commonJS = (cb, mod) => function __require() {
12
9
  return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
13
10
  };
@@ -248,31 +245,6 @@ var require_main = __commonJS({
248
245
  }
249
246
  });
250
247
 
251
- // src/shared/blobkey.ts
252
- var blobkey_exports = {};
253
- __export(blobkey_exports, {
254
- encodeBlobKey: () => encodeBlobKey
255
- });
256
- async function encodeBlobKey(key) {
257
- const buffer = import_node_buffer.Buffer.from(key);
258
- const base64 = buffer.toString("base64url");
259
- if (base64.length <= maxLength) {
260
- return base64;
261
- }
262
- const digest = await import_node_crypto.webcrypto.subtle.digest("SHA-256", buffer);
263
- const hash = import_node_buffer.Buffer.from(digest).toString("base64url");
264
- return `${base64.slice(0, maxLength - hash.length - 1)}-${hash}`;
265
- }
266
- var import_node_buffer, import_node_crypto, maxLength;
267
- var init_blobkey = __esm({
268
- "src/shared/blobkey.ts"() {
269
- "use strict";
270
- import_node_buffer = require("node:buffer");
271
- import_node_crypto = require("node:crypto");
272
- maxLength = 180;
273
- }
274
- });
275
-
276
248
  // src/run/handlers/cache.cts
277
249
  var cache_exports = {};
278
250
  __export(cache_exports, {
@@ -280,545 +252,12 @@ __export(cache_exports, {
280
252
  default: () => cache_default
281
253
  });
282
254
  module.exports = __toCommonJS(cache_exports);
283
- var import_node_buffer2 = require("node:buffer");
284
-
285
- // node_modules/@netlify/blobs/dist/chunk-6TGYNZGH.js
286
- var BlobsInternalError = class extends Error {
287
- constructor(statusCode) {
288
- super(`Netlify Blobs has generated an internal error: ${statusCode} response`);
289
- this.name = "BlobsInternalError";
290
- }
291
- };
292
- var collectIterator = async (iterator) => {
293
- const result = [];
294
- for await (const item of iterator) {
295
- result.push(item);
296
- }
297
- return result;
298
- };
299
- var base64Decode = (input) => {
300
- const { Buffer: Buffer4 } = globalThis;
301
- if (Buffer4) {
302
- return Buffer4.from(input, "base64").toString();
303
- }
304
- return atob(input);
305
- };
306
- var base64Encode = (input) => {
307
- const { Buffer: Buffer4 } = globalThis;
308
- if (Buffer4) {
309
- return Buffer4.from(input).toString("base64");
310
- }
311
- return btoa(input);
312
- };
313
- var BASE64_PREFIX = "b64;";
314
- var METADATA_HEADER_INTERNAL = "x-amz-meta-user";
315
- var METADATA_HEADER_EXTERNAL = "netlify-blobs-metadata";
316
- var METADATA_MAX_SIZE = 2 * 1024;
317
- var encodeMetadata = (metadata) => {
318
- if (!metadata) {
319
- return null;
320
- }
321
- const encodedObject = base64Encode(JSON.stringify(metadata));
322
- const payload = `b64;${encodedObject}`;
323
- if (METADATA_HEADER_EXTERNAL.length + payload.length > METADATA_MAX_SIZE) {
324
- throw new Error("Metadata object exceeds the maximum size");
325
- }
326
- return payload;
327
- };
328
- var decodeMetadata = (header) => {
329
- if (!header || !header.startsWith(BASE64_PREFIX)) {
330
- return {};
331
- }
332
- const encodedData = header.slice(BASE64_PREFIX.length);
333
- const decodedData = base64Decode(encodedData);
334
- const metadata = JSON.parse(decodedData);
335
- return metadata;
336
- };
337
- var getMetadataFromResponse = (response) => {
338
- if (!response.headers) {
339
- return {};
340
- }
341
- const value = response.headers.get(METADATA_HEADER_EXTERNAL) || response.headers.get(METADATA_HEADER_INTERNAL);
342
- try {
343
- return decodeMetadata(value);
344
- } catch {
345
- throw new Error(
346
- "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."
347
- );
348
- }
349
- };
350
- var BlobsConsistencyError = class extends Error {
351
- constructor() {
352
- super(
353
- `Netlify Blobs has failed to perform a read using strong consistency because the environment has not been configured with a 'uncachedEdgeURL' property`
354
- );
355
- this.name = "BlobsConsistencyError";
356
- }
357
- };
358
- var getEnvironment = () => {
359
- const { Deno, Netlify, process } = globalThis;
360
- return Netlify?.env ?? Deno?.env ?? {
361
- delete: (key) => delete process?.env[key],
362
- get: (key) => process?.env[key],
363
- has: (key) => Boolean(process?.env[key]),
364
- set: (key, value) => {
365
- if (process?.env) {
366
- process.env[key] = value;
367
- }
368
- },
369
- toObject: () => process?.env ?? {}
370
- };
371
- };
372
- var getEnvironmentContext = () => {
373
- const context = globalThis.netlifyBlobsContext || getEnvironment().get("NETLIFY_BLOBS_CONTEXT");
374
- if (typeof context !== "string" || !context) {
375
- return {};
376
- }
377
- const data = base64Decode(context);
378
- try {
379
- return JSON.parse(data);
380
- } catch {
381
- }
382
- return {};
383
- };
384
- var MissingBlobsEnvironmentError = class extends Error {
385
- constructor(requiredProperties) {
386
- super(
387
- `The environment has not been configured to use Netlify Blobs. To use it manually, supply the following properties when creating a store: ${requiredProperties.join(
388
- ", "
389
- )}`
390
- );
391
- this.name = "MissingBlobsEnvironmentError";
392
- }
393
- };
394
- var DEFAULT_RETRY_DELAY = getEnvironment().get("NODE_ENV") === "test" ? 1 : 5e3;
395
- var MIN_RETRY_DELAY = 1e3;
396
- var MAX_RETRY = 5;
397
- var RATE_LIMIT_HEADER = "X-RateLimit-Reset";
398
- var fetchAndRetry = async (fetch2, url, options, attemptsLeft = MAX_RETRY) => {
399
- try {
400
- const res = await fetch2(url, options);
401
- if (attemptsLeft > 0 && (res.status === 429 || res.status >= 500)) {
402
- const delay = getDelay(res.headers.get(RATE_LIMIT_HEADER));
403
- await sleep(delay);
404
- return fetchAndRetry(fetch2, url, options, attemptsLeft - 1);
405
- }
406
- return res;
407
- } catch (error) {
408
- if (attemptsLeft === 0) {
409
- throw error;
410
- }
411
- const delay = getDelay();
412
- await sleep(delay);
413
- return fetchAndRetry(fetch2, url, options, attemptsLeft - 1);
414
- }
415
- };
416
- var getDelay = (rateLimitReset) => {
417
- if (!rateLimitReset) {
418
- return DEFAULT_RETRY_DELAY;
419
- }
420
- return Math.max(Number(rateLimitReset) * 1e3 - Date.now(), MIN_RETRY_DELAY);
421
- };
422
- var sleep = (ms) => new Promise((resolve) => {
423
- setTimeout(resolve, ms);
424
- });
425
- var SIGNED_URL_ACCEPT_HEADER = "application/json;type=signed-url";
426
- var Client = class {
427
- constructor({ apiURL, consistency, edgeURL, fetch: fetch2, siteID, token, uncachedEdgeURL }) {
428
- this.apiURL = apiURL;
429
- this.consistency = consistency ?? "eventual";
430
- this.edgeURL = edgeURL;
431
- this.fetch = fetch2 ?? globalThis.fetch;
432
- this.siteID = siteID;
433
- this.token = token;
434
- this.uncachedEdgeURL = uncachedEdgeURL;
435
- if (!this.fetch) {
436
- throw new Error(
437
- "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."
438
- );
439
- }
440
- }
441
- async getFinalRequest({
442
- consistency: opConsistency,
443
- key,
444
- metadata,
445
- method,
446
- parameters = {},
447
- storeName
448
- }) {
449
- const encodedMetadata = encodeMetadata(metadata);
450
- const consistency = opConsistency ?? this.consistency;
451
- let urlPath = `/${this.siteID}`;
452
- if (storeName) {
453
- urlPath += `/${storeName}`;
454
- }
455
- if (key) {
456
- urlPath += `/${key}`;
457
- }
458
- if (this.edgeURL) {
459
- if (consistency === "strong" && !this.uncachedEdgeURL) {
460
- throw new BlobsConsistencyError();
461
- }
462
- const headers = {
463
- authorization: `Bearer ${this.token}`
464
- };
465
- if (encodedMetadata) {
466
- headers[METADATA_HEADER_INTERNAL] = encodedMetadata;
467
- }
468
- const url2 = new URL(urlPath, consistency === "strong" ? this.uncachedEdgeURL : this.edgeURL);
469
- for (const key2 in parameters) {
470
- url2.searchParams.set(key2, parameters[key2]);
471
- }
472
- return {
473
- headers,
474
- url: url2.toString()
475
- };
476
- }
477
- const apiHeaders = { authorization: `Bearer ${this.token}` };
478
- const url = new URL(`/api/v1/blobs${urlPath}`, this.apiURL ?? "https://api.netlify.com");
479
- for (const key2 in parameters) {
480
- url.searchParams.set(key2, parameters[key2]);
481
- }
482
- if (storeName === void 0 || key === void 0) {
483
- return {
484
- headers: apiHeaders,
485
- url: url.toString()
486
- };
487
- }
488
- if (encodedMetadata) {
489
- apiHeaders[METADATA_HEADER_EXTERNAL] = encodedMetadata;
490
- }
491
- if (method === "head" || method === "delete") {
492
- return {
493
- headers: apiHeaders,
494
- url: url.toString()
495
- };
496
- }
497
- const res = await this.fetch(url.toString(), {
498
- headers: { ...apiHeaders, accept: SIGNED_URL_ACCEPT_HEADER },
499
- method
500
- });
501
- if (res.status !== 200) {
502
- throw new Error(`Netlify Blobs has generated an internal error: ${res.status} response`);
503
- }
504
- const { url: signedURL } = await res.json();
505
- const userHeaders = encodedMetadata ? { [METADATA_HEADER_INTERNAL]: encodedMetadata } : void 0;
506
- return {
507
- headers: userHeaders,
508
- url: signedURL
509
- };
510
- }
511
- async makeRequest({
512
- body,
513
- consistency,
514
- headers: extraHeaders,
515
- key,
516
- metadata,
517
- method,
518
- parameters,
519
- storeName
520
- }) {
521
- const { headers: baseHeaders = {}, url } = await this.getFinalRequest({
522
- consistency,
523
- key,
524
- metadata,
525
- method,
526
- parameters,
527
- storeName
528
- });
529
- const headers = {
530
- ...baseHeaders,
531
- ...extraHeaders
532
- };
533
- if (method === "put") {
534
- headers["cache-control"] = "max-age=0, stale-while-revalidate=60";
535
- }
536
- const options = {
537
- body,
538
- headers,
539
- method
540
- };
541
- if (body instanceof ReadableStream) {
542
- options.duplex = "half";
543
- }
544
- return fetchAndRetry(this.fetch, url, options);
545
- }
546
- };
547
- var getClientOptions = (options, contextOverride) => {
548
- const context = contextOverride ?? getEnvironmentContext();
549
- const siteID = context.siteID ?? options.siteID;
550
- const token = context.token ?? options.token;
551
- if (!siteID || !token) {
552
- throw new MissingBlobsEnvironmentError(["siteID", "token"]);
553
- }
554
- const clientOptions = {
555
- apiURL: context.apiURL ?? options.apiURL,
556
- consistency: options.consistency,
557
- edgeURL: context.edgeURL ?? options.edgeURL,
558
- fetch: options.fetch,
559
- siteID,
560
- token,
561
- uncachedEdgeURL: context.uncachedEdgeURL ?? options.uncachedEdgeURL
562
- };
563
- return clientOptions;
564
- };
565
-
566
- // node_modules/@netlify/blobs/dist/main.js
567
- var DEPLOY_STORE_PREFIX = "deploy:";
568
- var LEGACY_STORE_INTERNAL_PREFIX = "netlify-internal/legacy-namespace/";
569
- var SITE_STORE_PREFIX = "site:";
570
- var Store = class _Store {
571
- constructor(options) {
572
- this.client = options.client;
573
- if ("deployID" in options) {
574
- _Store.validateDeployID(options.deployID);
575
- this.name = DEPLOY_STORE_PREFIX + options.deployID;
576
- } else if (options.name.startsWith(LEGACY_STORE_INTERNAL_PREFIX)) {
577
- const storeName = options.name.slice(LEGACY_STORE_INTERNAL_PREFIX.length);
578
- _Store.validateStoreName(storeName);
579
- this.name = storeName;
580
- } else {
581
- _Store.validateStoreName(options.name);
582
- this.name = SITE_STORE_PREFIX + options.name;
583
- }
584
- }
585
- async delete(key) {
586
- const res = await this.client.makeRequest({ key, method: "delete", storeName: this.name });
587
- if (![200, 204, 404].includes(res.status)) {
588
- throw new BlobsInternalError(res.status);
589
- }
590
- }
591
- async get(key, options) {
592
- const { consistency, type } = options ?? {};
593
- const res = await this.client.makeRequest({ consistency, key, method: "get", storeName: this.name });
594
- if (res.status === 404) {
595
- return null;
596
- }
597
- if (res.status !== 200) {
598
- throw new BlobsInternalError(res.status);
599
- }
600
- if (type === void 0 || type === "text") {
601
- return res.text();
602
- }
603
- if (type === "arrayBuffer") {
604
- return res.arrayBuffer();
605
- }
606
- if (type === "blob") {
607
- return res.blob();
608
- }
609
- if (type === "json") {
610
- return res.json();
611
- }
612
- if (type === "stream") {
613
- return res.body;
614
- }
615
- throw new BlobsInternalError(res.status);
616
- }
617
- async getMetadata(key, { consistency } = {}) {
618
- const res = await this.client.makeRequest({ consistency, key, method: "head", storeName: this.name });
619
- if (res.status === 404) {
620
- return null;
621
- }
622
- if (res.status !== 200 && res.status !== 304) {
623
- throw new BlobsInternalError(res.status);
624
- }
625
- const etag = res?.headers.get("etag") ?? void 0;
626
- const metadata = getMetadataFromResponse(res);
627
- const result = {
628
- etag,
629
- metadata
630
- };
631
- return result;
632
- }
633
- async getWithMetadata(key, options) {
634
- const { consistency, etag: requestETag, type } = options ?? {};
635
- const headers = requestETag ? { "if-none-match": requestETag } : void 0;
636
- const res = await this.client.makeRequest({
637
- consistency,
638
- headers,
639
- key,
640
- method: "get",
641
- storeName: this.name
642
- });
643
- if (res.status === 404) {
644
- return null;
645
- }
646
- if (res.status !== 200 && res.status !== 304) {
647
- throw new BlobsInternalError(res.status);
648
- }
649
- const responseETag = res?.headers.get("etag") ?? void 0;
650
- const metadata = getMetadataFromResponse(res);
651
- const result = {
652
- etag: responseETag,
653
- metadata
654
- };
655
- if (res.status === 304 && requestETag) {
656
- return { data: null, ...result };
657
- }
658
- if (type === void 0 || type === "text") {
659
- return { data: await res.text(), ...result };
660
- }
661
- if (type === "arrayBuffer") {
662
- return { data: await res.arrayBuffer(), ...result };
663
- }
664
- if (type === "blob") {
665
- return { data: await res.blob(), ...result };
666
- }
667
- if (type === "json") {
668
- return { data: await res.json(), ...result };
669
- }
670
- if (type === "stream") {
671
- return { data: res.body, ...result };
672
- }
673
- throw new Error(`Invalid 'type' property: ${type}. Expected: arrayBuffer, blob, json, stream, or text.`);
674
- }
675
- list(options = {}) {
676
- const iterator = this.getListIterator(options);
677
- if (options.paginate) {
678
- return iterator;
679
- }
680
- return collectIterator(iterator).then(
681
- (items) => items.reduce(
682
- (acc, item) => ({
683
- blobs: [...acc.blobs, ...item.blobs],
684
- directories: [...acc.directories, ...item.directories]
685
- }),
686
- { blobs: [], directories: [] }
687
- )
688
- );
689
- }
690
- async set(key, data, { metadata } = {}) {
691
- _Store.validateKey(key);
692
- const res = await this.client.makeRequest({
693
- body: data,
694
- key,
695
- metadata,
696
- method: "put",
697
- storeName: this.name
698
- });
699
- if (res.status !== 200) {
700
- throw new BlobsInternalError(res.status);
701
- }
702
- }
703
- async setJSON(key, data, { metadata } = {}) {
704
- _Store.validateKey(key);
705
- const payload = JSON.stringify(data);
706
- const headers = {
707
- "content-type": "application/json"
708
- };
709
- const res = await this.client.makeRequest({
710
- body: payload,
711
- headers,
712
- key,
713
- metadata,
714
- method: "put",
715
- storeName: this.name
716
- });
717
- if (res.status !== 200) {
718
- throw new BlobsInternalError(res.status);
719
- }
720
- }
721
- static formatListResultBlob(result) {
722
- if (!result.key) {
723
- return null;
724
- }
725
- return {
726
- etag: result.etag,
727
- key: result.key
728
- };
729
- }
730
- static validateKey(key) {
731
- if (key === "") {
732
- throw new Error("Blob key must not be empty.");
733
- }
734
- if (key.startsWith("/") || key.startsWith("%2F")) {
735
- throw new Error("Blob key must not start with forward slash (/).");
736
- }
737
- if (new TextEncoder().encode(key).length > 600) {
738
- throw new Error(
739
- "Blob key must be a sequence of Unicode characters whose UTF-8 encoding is at most 600 bytes long."
740
- );
741
- }
742
- }
743
- static validateDeployID(deployID) {
744
- if (!/^\w{1,24}$/.test(deployID)) {
745
- throw new Error(`'${deployID}' is not a valid Netlify deploy ID.`);
746
- }
747
- }
748
- static validateStoreName(name) {
749
- if (name.includes("/") || name.includes("%2F")) {
750
- throw new Error("Store name must not contain forward slashes (/).");
751
- }
752
- if (new TextEncoder().encode(name).length > 64) {
753
- throw new Error(
754
- "Store name must be a sequence of Unicode characters whose UTF-8 encoding is at most 64 bytes long."
755
- );
756
- }
757
- }
758
- getListIterator(options) {
759
- const { client, name: storeName } = this;
760
- const parameters = {};
761
- if (options?.prefix) {
762
- parameters.prefix = options.prefix;
763
- }
764
- if (options?.directories) {
765
- parameters.directories = "true";
766
- }
767
- return {
768
- [Symbol.asyncIterator]() {
769
- let currentCursor = null;
770
- let done = false;
771
- return {
772
- async next() {
773
- if (done) {
774
- return { done: true, value: void 0 };
775
- }
776
- const nextParameters = { ...parameters };
777
- if (currentCursor !== null) {
778
- nextParameters.cursor = currentCursor;
779
- }
780
- const res = await client.makeRequest({
781
- method: "get",
782
- parameters: nextParameters,
783
- storeName
784
- });
785
- const page = await res.json();
786
- if (page.next_cursor) {
787
- currentCursor = page.next_cursor;
788
- } else {
789
- done = true;
790
- }
791
- const blobs = (page.blobs ?? []).map(_Store.formatListResultBlob).filter(Boolean);
792
- return {
793
- done: false,
794
- value: {
795
- blobs,
796
- directories: page.directories ?? []
797
- }
798
- };
799
- }
800
- };
801
- }
802
- };
803
- }
804
- };
805
- var getDeployStore = (options = {}) => {
806
- const context = getEnvironmentContext();
807
- const deployID = options.deployID ?? context.deployID;
808
- if (!deployID) {
809
- throw new MissingBlobsEnvironmentError(["deployID"]);
810
- }
811
- const clientOptions = getClientOptions(options, context);
812
- const client = new Client(clientOptions);
813
- return new Store({ client, deployID });
814
- };
815
-
816
- // src/run/handlers/cache.cts
255
+ var import_node_buffer = require("node:buffer");
817
256
  var import_functions = __toESM(require_main());
818
257
  var import_constants = require("next/dist/lib/constants.js");
258
+ var import_regional_blob_store = require("../regional-blob-store.cjs");
819
259
  var import_request_context = require("./request-context.cjs");
820
260
  var import_tracer = require("./tracer.cjs");
821
- var fetchBeforeNextPatchedIt = globalThis.fetch;
822
261
  var NetlifyCacheHandler = class {
823
262
  options;
824
263
  revalidatedTags;
@@ -828,12 +267,12 @@ var NetlifyCacheHandler = class {
828
267
  constructor(options) {
829
268
  this.options = options;
830
269
  this.revalidatedTags = options.revalidatedTags;
831
- this.blobStore = getDeployStore({ fetch: fetchBeforeNextPatchedIt, consistency: "strong" });
270
+ this.blobStore = (0, import_regional_blob_store.getRegionalBlobStore)({ consistency: "strong" });
832
271
  this.tagManifestsFetchedFromBlobStoreInCurrentRequest = {};
833
272
  }
834
273
  async encodeBlobKey(key) {
835
- const { encodeBlobKey: encodeBlobKey2 } = await Promise.resolve().then(() => (init_blobkey(), blobkey_exports));
836
- return await encodeBlobKey2(key);
274
+ const { encodeBlobKey } = await import("../../shared/blobkey.js");
275
+ return await encodeBlobKey(key);
837
276
  }
838
277
  captureResponseCacheLastModified(cacheValue, key, getCacheKeySpan) {
839
278
  if (cacheValue.value?.kind === "FETCH") {
@@ -912,7 +351,7 @@ var NetlifyCacheHandler = class {
912
351
  lastModified: blob.lastModified,
913
352
  value: {
914
353
  ...valueWithoutRevalidate,
915
- body: import_node_buffer2.Buffer.from(valueWithoutRevalidate.body, "base64")
354
+ body: import_node_buffer.Buffer.from(valueWithoutRevalidate.body, "base64")
916
355
  }
917
356
  };
918
357
  }
@@ -27,8 +27,15 @@ __export(request_context_exports, {
27
27
  module.exports = __toCommonJS(request_context_exports);
28
28
  var import_node_async_hooks = require("node:async_hooks");
29
29
  function createRequestContext(debug = false) {
30
+ const backgroundWorkPromises = [];
30
31
  return {
31
- debug
32
+ debug,
33
+ trackBackgroundWork: (promise) => {
34
+ backgroundWorkPromises.push(promise);
35
+ },
36
+ get backgroundWorkPromise() {
37
+ return Promise.allSettled(backgroundWorkPromises);
38
+ }
32
39
  };
33
40
  }
34
41
  var REQUEST_CONTEXT_GLOBAL_KEY = Symbol.for("nf-request-context-async-local-storage");
@@ -4,24 +4,6 @@
4
4
  return createRequire(import.meta.url);
5
5
  })();
6
6
 
7
- import {
8
- adjustDateHeader,
9
- setCacheControlHeaders,
10
- setCacheStatusHeader,
11
- setCacheTagsHeaders,
12
- setVaryHeaders
13
- } from "../../esm-chunks/chunk-PMRBBOBY.js";
14
- import {
15
- nextResponseProxy
16
- } from "../../esm-chunks/chunk-RL4K4CVH.js";
17
- import {
18
- import_internal
19
- } from "../../esm-chunks/chunk-HYBEXB2Z.js";
20
- import "../../esm-chunks/chunk-TYCYFZ22.js";
21
- import {
22
- getTagsManifest
23
- } from "../../esm-chunks/chunk-3SUDZQ7L.js";
24
- import "../../esm-chunks/chunk-UYKENJEU.js";
25
7
  import {
26
8
  __commonJS,
27
9
  __toESM
@@ -3257,6 +3239,16 @@ function toComputeResponse(res) {
3257
3239
  }
3258
3240
 
3259
3241
  // src/run/handlers/server.ts
3242
+ import { getTagsManifest } from "../config.js";
3243
+ import {
3244
+ adjustDateHeader,
3245
+ setCacheStatusHeader,
3246
+ setCacheControlHeaders,
3247
+ setCacheTagsHeaders,
3248
+ setVaryHeaders
3249
+ } from "../headers.js";
3250
+ import { nextResponseProxy } from "../revalidate.js";
3251
+ import { logger } from "../systemlog.js";
3260
3252
  import { createRequestContext, getRequestContext } from "./request-context.cjs";
3261
3253
  import { getTracer } from "./tracer.cjs";
3262
3254
  var nextImportPromise = import("../next.cjs");
@@ -3276,7 +3268,7 @@ var disableFaultyTransferEncodingHandling = (res) => {
3276
3268
  return originalStoreHeader.call(this, firstLine, headers);
3277
3269
  };
3278
3270
  };
3279
- var server_default = async (request) => {
3271
+ var server_default = async (request, context) => {
3280
3272
  const tracer = getTracer();
3281
3273
  if (!nextHandler) {
3282
3274
  await tracer.withActiveSpan("initialize next server", async (span) => {
@@ -3319,7 +3311,7 @@ var server_default = async (request) => {
3319
3311
  const requestContext = getRequestContext() ?? createRequestContext();
3320
3312
  const resProxy = nextResponseProxy(res, requestContext);
3321
3313
  const nextHandlerPromise = nextHandler(req, resProxy).catch((error) => {
3322
- import_internal.systemLogger.withError(error).error("next handler error");
3314
+ logger.withError(error).error("next handler error");
3323
3315
  console.error(error);
3324
3316
  resProxy.statusCode = 500;
3325
3317
  span.setAttribute("http.status_code", 500);
@@ -3338,9 +3330,15 @@ var server_default = async (request) => {
3338
3330
  const body = await response.text();
3339
3331
  return new Response(body || null, response);
3340
3332
  }
3333
+ if (context.waitUntil) {
3334
+ context.waitUntil(requestContext.backgroundWorkPromise);
3335
+ }
3341
3336
  const keepOpenUntilNextFullyRendered = new TransformStream({
3342
- flush() {
3343
- return nextHandlerPromise;
3337
+ async flush() {
3338
+ await nextHandlerPromise;
3339
+ if (!context.waitUntil) {
3340
+ await requestContext.backgroundWorkPromise;
3341
+ }
3344
3342
  }
3345
3343
  });
3346
3344
  return new Response(response.body?.pipeThrough(keepOpenUntilNextFullyRendered), response);