@netlify/plugin-nextjs 5.10.0 → 5.10.2

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 (48) hide show
  1. package/LICENSE +22 -0
  2. package/dist/build/advanced-api-routes.js +136 -4
  3. package/dist/build/cache.js +25 -4
  4. package/dist/build/content/prerendered.js +293 -11
  5. package/dist/build/content/server.js +219 -11
  6. package/dist/build/content/static.js +112 -15
  7. package/dist/build/functions/edge.js +540 -7
  8. package/dist/build/functions/server.js +130 -11
  9. package/dist/build/image-cdn.js +1599 -3
  10. package/dist/build/plugin-context.js +292 -6
  11. package/dist/build/verification.js +104 -9
  12. package/dist/esm-chunks/{package-F536DQ6H.js → package-7HACW4PO.js} +11 -10
  13. package/dist/index.js +19 -40
  14. package/dist/run/config.js +6 -7
  15. package/dist/run/constants.js +7 -5
  16. package/dist/run/handlers/cache.cjs +93 -1713
  17. package/dist/run/handlers/request-context.cjs +10 -3
  18. package/dist/run/handlers/server.js +14 -34
  19. package/dist/run/handlers/tracer.cjs +17 -116
  20. package/dist/run/handlers/tracing.js +2 -4
  21. package/dist/run/handlers/wait-until.cjs +2 -116
  22. package/dist/run/headers.js +183 -10
  23. package/dist/run/next.cjs +10 -1625
  24. package/dist/run/revalidate.js +24 -3
  25. package/dist/run/{regional-blob-store.cjs → storage/regional-blob-store.cjs} +44 -8
  26. package/dist/run/storage/request-scoped-in-memory-cache.cjs +1475 -0
  27. package/dist/run/storage/storage.cjs +84 -0
  28. package/dist/shared/blob-types.cjs +37 -0
  29. package/dist/shared/blobkey.js +15 -3
  30. package/package.json +1 -1
  31. package/dist/esm-chunks/chunk-3RQSTU2O.js +0 -554
  32. package/dist/esm-chunks/chunk-72ZI2IVI.js +0 -36
  33. package/dist/esm-chunks/chunk-AMY4NOT5.js +0 -1610
  34. package/dist/esm-chunks/chunk-DLBTTDNJ.js +0 -309
  35. package/dist/esm-chunks/chunk-DLVROEVU.js +0 -144
  36. package/dist/esm-chunks/chunk-GFYWJNQR.js +0 -305
  37. package/dist/esm-chunks/chunk-IJZEDP6B.js +0 -235
  38. package/dist/esm-chunks/chunk-K4RDUZYO.js +0 -609
  39. package/dist/esm-chunks/chunk-SGXRYMYQ.js +0 -127
  40. package/dist/esm-chunks/chunk-TYCYFZ22.js +0 -25
  41. package/dist/esm-chunks/chunk-UYKENJEU.js +0 -19
  42. package/dist/esm-chunks/chunk-VTKZZRGT.js +0 -132
  43. package/dist/esm-chunks/chunk-WHUPSPWV.js +0 -73
  44. package/dist/esm-chunks/chunk-XS27YRA5.js +0 -34
  45. package/dist/esm-chunks/chunk-YMNWVS6T.js +0 -218
  46. package/dist/esm-chunks/chunk-ZENB67PD.js +0 -148
  47. package/dist/esm-chunks/chunk-ZSVHJNNY.js +0 -120
  48. package/dist/esm-chunks/next-7JK63CHT.js +0 -567
package/dist/run/next.cjs CHANGED
@@ -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
  };
@@ -485,31 +482,6 @@ var require_lib = __commonJS({
485
482
  }
486
483
  });
487
484
 
488
- // src/shared/blobkey.ts
489
- var blobkey_exports = {};
490
- __export(blobkey_exports, {
491
- encodeBlobKey: () => encodeBlobKey
492
- });
493
- async function encodeBlobKey(key) {
494
- const buffer = import_node_buffer.Buffer.from(key);
495
- const base64 = buffer.toString("base64url");
496
- if (base64.length <= maxLength) {
497
- return base64;
498
- }
499
- const digest = await import_node_crypto.webcrypto.subtle.digest("SHA-256", buffer);
500
- const hash = import_node_buffer.Buffer.from(digest).toString("base64url");
501
- return `${base64.slice(0, maxLength - hash.length - 1)}-${hash}`;
502
- }
503
- var import_node_buffer, import_node_crypto, maxLength;
504
- var init_blobkey = __esm({
505
- "src/shared/blobkey.ts"() {
506
- "use strict";
507
- import_node_buffer = require("node:buffer");
508
- import_node_crypto = require("node:crypto");
509
- maxLength = 180;
510
- }
511
- });
512
-
513
485
  // src/run/next.cts
514
486
  var next_exports = {};
515
487
  __export(next_exports, {
@@ -519,1593 +491,9 @@ module.exports = __toCommonJS(next_exports);
519
491
  var import_promises = __toESM(require("fs/promises"));
520
492
  var import_path = require("path");
521
493
  var import_fs_monkey = __toESM(require_lib());
522
-
523
- // src/run/handlers/request-context.cts
524
- var import_node_async_hooks = require("node:async_hooks");
525
-
526
- // node_modules/@netlify/functions/dist/chunk-C6P2IO65.mjs
527
- var __getOwnPropNames2 = Object.getOwnPropertyNames;
528
- var __esm2 = (fn, res) => function __init() {
529
- return fn && (res = (0, fn[__getOwnPropNames2(fn)[0]])(fn = 0)), res;
530
- };
531
-
532
- // node_modules/@netlify/functions/dist/chunk-ATZ7N7EG.mjs
533
- var import_process = require("process");
534
- var systemLogTag;
535
- var serializeError;
536
- var LogLevel;
537
- var SystemLogger;
538
- var systemLogger;
539
- var init_system_logger = __esm2({
540
- "src/lib/system_logger.ts"() {
541
- systemLogTag = "__nfSystemLog";
542
- serializeError = (error) => {
543
- const cause = error?.cause instanceof Error ? serializeError(error.cause) : error.cause;
544
- return {
545
- error: error.message,
546
- error_cause: cause,
547
- error_stack: error.stack
548
- };
549
- };
550
- LogLevel = /* @__PURE__ */ ((LogLevel2) => {
551
- LogLevel2[LogLevel2["Debug"] = 1] = "Debug";
552
- LogLevel2[LogLevel2["Log"] = 2] = "Log";
553
- LogLevel2[LogLevel2["Error"] = 3] = "Error";
554
- return LogLevel2;
555
- })(LogLevel || {});
556
- SystemLogger = class _SystemLogger {
557
- fields;
558
- logLevel;
559
- constructor(fields = {}, logLevel = 2) {
560
- this.fields = fields;
561
- this.logLevel = logLevel;
562
- }
563
- doLog(logger, message) {
564
- if (import_process.env.NETLIFY_DEV && !import_process.env.NETLIFY_ENABLE_SYSTEM_LOGGING) {
565
- return;
566
- }
567
- logger(systemLogTag, JSON.stringify({ msg: message, fields: this.fields }));
568
- }
569
- log(message) {
570
- if (this.logLevel > 2) {
571
- return;
572
- }
573
- this.doLog(console.log, message);
574
- }
575
- debug(message) {
576
- if (this.logLevel > 1) {
577
- return;
578
- }
579
- this.doLog(console.debug, message);
580
- }
581
- error(message) {
582
- if (this.logLevel > 3) {
583
- return;
584
- }
585
- this.doLog(console.error, message);
586
- }
587
- withLogLevel(level) {
588
- return new _SystemLogger(this.fields, level);
589
- }
590
- withFields(fields) {
591
- return new _SystemLogger(
592
- {
593
- ...this.fields,
594
- ...fields
595
- },
596
- this.logLevel
597
- );
598
- }
599
- withError(error) {
600
- const fields = error instanceof Error ? serializeError(error) : { error };
601
- return this.withFields(fields);
602
- }
603
- };
604
- systemLogger = new SystemLogger();
605
- }
606
- });
607
-
608
- // node_modules/@netlify/functions/dist/chunk-7ANA32NV.mjs
609
- var init_internal = __esm2({
610
- "src/internal.ts"() {
611
- init_system_logger();
612
- }
613
- });
614
-
615
- // node_modules/@netlify/functions/dist/internal.mjs
616
- init_internal();
617
-
618
- // src/run/handlers/request-context.cts
619
- var REQUEST_CONTEXT_GLOBAL_KEY = Symbol.for("nf-request-context-async-local-storage");
620
- var requestContextAsyncLocalStorage;
621
- function getRequestContextAsyncLocalStorage() {
622
- if (requestContextAsyncLocalStorage) {
623
- return requestContextAsyncLocalStorage;
624
- }
625
- const extendedGlobalThis = globalThis;
626
- if (extendedGlobalThis[REQUEST_CONTEXT_GLOBAL_KEY]) {
627
- return extendedGlobalThis[REQUEST_CONTEXT_GLOBAL_KEY];
628
- }
629
- const storage = new import_node_async_hooks.AsyncLocalStorage();
630
- requestContextAsyncLocalStorage = storage;
631
- extendedGlobalThis[REQUEST_CONTEXT_GLOBAL_KEY] = storage;
632
- return storage;
633
- }
634
- var getRequestContext = () => getRequestContextAsyncLocalStorage().getStore();
635
-
636
- // node_modules/@opentelemetry/api/build/esm/platform/node/globalThis.js
637
- var _globalThis = typeof globalThis === "object" ? globalThis : global;
638
-
639
- // node_modules/@opentelemetry/api/build/esm/version.js
640
- var VERSION = "1.8.0";
641
-
642
- // node_modules/@opentelemetry/api/build/esm/internal/semver.js
643
- var re = /^(\d+)\.(\d+)\.(\d+)(-(.+))?$/;
644
- function _makeCompatibilityCheck(ownVersion) {
645
- var acceptedVersions = /* @__PURE__ */ new Set([ownVersion]);
646
- var rejectedVersions = /* @__PURE__ */ new Set();
647
- var myVersionMatch = ownVersion.match(re);
648
- if (!myVersionMatch) {
649
- return function() {
650
- return false;
651
- };
652
- }
653
- var ownVersionParsed = {
654
- major: +myVersionMatch[1],
655
- minor: +myVersionMatch[2],
656
- patch: +myVersionMatch[3],
657
- prerelease: myVersionMatch[4]
658
- };
659
- if (ownVersionParsed.prerelease != null) {
660
- return function isExactmatch(globalVersion) {
661
- return globalVersion === ownVersion;
662
- };
663
- }
664
- function _reject(v) {
665
- rejectedVersions.add(v);
666
- return false;
667
- }
668
- function _accept(v) {
669
- acceptedVersions.add(v);
670
- return true;
671
- }
672
- return function isCompatible2(globalVersion) {
673
- if (acceptedVersions.has(globalVersion)) {
674
- return true;
675
- }
676
- if (rejectedVersions.has(globalVersion)) {
677
- return false;
678
- }
679
- var globalVersionMatch = globalVersion.match(re);
680
- if (!globalVersionMatch) {
681
- return _reject(globalVersion);
682
- }
683
- var globalVersionParsed = {
684
- major: +globalVersionMatch[1],
685
- minor: +globalVersionMatch[2],
686
- patch: +globalVersionMatch[3],
687
- prerelease: globalVersionMatch[4]
688
- };
689
- if (globalVersionParsed.prerelease != null) {
690
- return _reject(globalVersion);
691
- }
692
- if (ownVersionParsed.major !== globalVersionParsed.major) {
693
- return _reject(globalVersion);
694
- }
695
- if (ownVersionParsed.major === 0) {
696
- if (ownVersionParsed.minor === globalVersionParsed.minor && ownVersionParsed.patch <= globalVersionParsed.patch) {
697
- return _accept(globalVersion);
698
- }
699
- return _reject(globalVersion);
700
- }
701
- if (ownVersionParsed.minor <= globalVersionParsed.minor) {
702
- return _accept(globalVersion);
703
- }
704
- return _reject(globalVersion);
705
- };
706
- }
707
- var isCompatible = _makeCompatibilityCheck(VERSION);
708
-
709
- // node_modules/@opentelemetry/api/build/esm/internal/global-utils.js
710
- var major = VERSION.split(".")[0];
711
- var GLOBAL_OPENTELEMETRY_API_KEY = Symbol.for("opentelemetry.js.api." + major);
712
- var _global = _globalThis;
713
- function registerGlobal(type, instance, diag, allowOverride) {
714
- var _a;
715
- if (allowOverride === void 0) {
716
- allowOverride = false;
717
- }
718
- var api = _global[GLOBAL_OPENTELEMETRY_API_KEY] = (_a = _global[GLOBAL_OPENTELEMETRY_API_KEY]) !== null && _a !== void 0 ? _a : {
719
- version: VERSION
720
- };
721
- if (!allowOverride && api[type]) {
722
- var err = new Error("@opentelemetry/api: Attempted duplicate registration of API: " + type);
723
- diag.error(err.stack || err.message);
724
- return false;
725
- }
726
- if (api.version !== VERSION) {
727
- var err = new Error("@opentelemetry/api: Registration of version v" + api.version + " for " + type + " does not match previously registered API v" + VERSION);
728
- diag.error(err.stack || err.message);
729
- return false;
730
- }
731
- api[type] = instance;
732
- diag.debug("@opentelemetry/api: Registered a global for " + type + " v" + VERSION + ".");
733
- return true;
734
- }
735
- function getGlobal(type) {
736
- var _a, _b;
737
- var globalVersion = (_a = _global[GLOBAL_OPENTELEMETRY_API_KEY]) === null || _a === void 0 ? void 0 : _a.version;
738
- if (!globalVersion || !isCompatible(globalVersion)) {
739
- return;
740
- }
741
- return (_b = _global[GLOBAL_OPENTELEMETRY_API_KEY]) === null || _b === void 0 ? void 0 : _b[type];
742
- }
743
- function unregisterGlobal(type, diag) {
744
- diag.debug("@opentelemetry/api: Unregistering a global for " + type + " v" + VERSION + ".");
745
- var api = _global[GLOBAL_OPENTELEMETRY_API_KEY];
746
- if (api) {
747
- delete api[type];
748
- }
749
- }
750
-
751
- // node_modules/@opentelemetry/api/build/esm/diag/ComponentLogger.js
752
- var __read = function(o, n) {
753
- var m = typeof Symbol === "function" && o[Symbol.iterator];
754
- if (!m) return o;
755
- var i = m.call(o), r, ar = [], e;
756
- try {
757
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
758
- } catch (error) {
759
- e = { error };
760
- } finally {
761
- try {
762
- if (r && !r.done && (m = i["return"])) m.call(i);
763
- } finally {
764
- if (e) throw e.error;
765
- }
766
- }
767
- return ar;
768
- };
769
- var __spreadArray = function(to, from, pack) {
770
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
771
- if (ar || !(i in from)) {
772
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
773
- ar[i] = from[i];
774
- }
775
- }
776
- return to.concat(ar || Array.prototype.slice.call(from));
777
- };
778
- var DiagComponentLogger = (
779
- /** @class */
780
- function() {
781
- function DiagComponentLogger2(props) {
782
- this._namespace = props.namespace || "DiagComponentLogger";
783
- }
784
- DiagComponentLogger2.prototype.debug = function() {
785
- var args = [];
786
- for (var _i = 0; _i < arguments.length; _i++) {
787
- args[_i] = arguments[_i];
788
- }
789
- return logProxy("debug", this._namespace, args);
790
- };
791
- DiagComponentLogger2.prototype.error = function() {
792
- var args = [];
793
- for (var _i = 0; _i < arguments.length; _i++) {
794
- args[_i] = arguments[_i];
795
- }
796
- return logProxy("error", this._namespace, args);
797
- };
798
- DiagComponentLogger2.prototype.info = function() {
799
- var args = [];
800
- for (var _i = 0; _i < arguments.length; _i++) {
801
- args[_i] = arguments[_i];
802
- }
803
- return logProxy("info", this._namespace, args);
804
- };
805
- DiagComponentLogger2.prototype.warn = function() {
806
- var args = [];
807
- for (var _i = 0; _i < arguments.length; _i++) {
808
- args[_i] = arguments[_i];
809
- }
810
- return logProxy("warn", this._namespace, args);
811
- };
812
- DiagComponentLogger2.prototype.verbose = function() {
813
- var args = [];
814
- for (var _i = 0; _i < arguments.length; _i++) {
815
- args[_i] = arguments[_i];
816
- }
817
- return logProxy("verbose", this._namespace, args);
818
- };
819
- return DiagComponentLogger2;
820
- }()
821
- );
822
- function logProxy(funcName, namespace, args) {
823
- var logger = getGlobal("diag");
824
- if (!logger) {
825
- return;
826
- }
827
- args.unshift(namespace);
828
- return logger[funcName].apply(logger, __spreadArray([], __read(args), false));
829
- }
830
-
831
- // node_modules/@opentelemetry/api/build/esm/diag/types.js
832
- var DiagLogLevel;
833
- (function(DiagLogLevel2) {
834
- DiagLogLevel2[DiagLogLevel2["NONE"] = 0] = "NONE";
835
- DiagLogLevel2[DiagLogLevel2["ERROR"] = 30] = "ERROR";
836
- DiagLogLevel2[DiagLogLevel2["WARN"] = 50] = "WARN";
837
- DiagLogLevel2[DiagLogLevel2["INFO"] = 60] = "INFO";
838
- DiagLogLevel2[DiagLogLevel2["DEBUG"] = 70] = "DEBUG";
839
- DiagLogLevel2[DiagLogLevel2["VERBOSE"] = 80] = "VERBOSE";
840
- DiagLogLevel2[DiagLogLevel2["ALL"] = 9999] = "ALL";
841
- })(DiagLogLevel || (DiagLogLevel = {}));
842
-
843
- // node_modules/@opentelemetry/api/build/esm/diag/internal/logLevelLogger.js
844
- function createLogLevelDiagLogger(maxLevel, logger) {
845
- if (maxLevel < DiagLogLevel.NONE) {
846
- maxLevel = DiagLogLevel.NONE;
847
- } else if (maxLevel > DiagLogLevel.ALL) {
848
- maxLevel = DiagLogLevel.ALL;
849
- }
850
- logger = logger || {};
851
- function _filterFunc(funcName, theLevel) {
852
- var theFunc = logger[funcName];
853
- if (typeof theFunc === "function" && maxLevel >= theLevel) {
854
- return theFunc.bind(logger);
855
- }
856
- return function() {
857
- };
858
- }
859
- return {
860
- error: _filterFunc("error", DiagLogLevel.ERROR),
861
- warn: _filterFunc("warn", DiagLogLevel.WARN),
862
- info: _filterFunc("info", DiagLogLevel.INFO),
863
- debug: _filterFunc("debug", DiagLogLevel.DEBUG),
864
- verbose: _filterFunc("verbose", DiagLogLevel.VERBOSE)
865
- };
866
- }
867
-
868
- // node_modules/@opentelemetry/api/build/esm/api/diag.js
869
- var __read2 = function(o, n) {
870
- var m = typeof Symbol === "function" && o[Symbol.iterator];
871
- if (!m) return o;
872
- var i = m.call(o), r, ar = [], e;
873
- try {
874
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
875
- } catch (error) {
876
- e = { error };
877
- } finally {
878
- try {
879
- if (r && !r.done && (m = i["return"])) m.call(i);
880
- } finally {
881
- if (e) throw e.error;
882
- }
883
- }
884
- return ar;
885
- };
886
- var __spreadArray2 = function(to, from, pack) {
887
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
888
- if (ar || !(i in from)) {
889
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
890
- ar[i] = from[i];
891
- }
892
- }
893
- return to.concat(ar || Array.prototype.slice.call(from));
894
- };
895
- var API_NAME = "diag";
896
- var DiagAPI = (
897
- /** @class */
898
- function() {
899
- function DiagAPI2() {
900
- function _logProxy(funcName) {
901
- return function() {
902
- var args = [];
903
- for (var _i = 0; _i < arguments.length; _i++) {
904
- args[_i] = arguments[_i];
905
- }
906
- var logger = getGlobal("diag");
907
- if (!logger)
908
- return;
909
- return logger[funcName].apply(logger, __spreadArray2([], __read2(args), false));
910
- };
911
- }
912
- var self = this;
913
- var setLogger = function(logger, optionsOrLogLevel) {
914
- var _a, _b, _c;
915
- if (optionsOrLogLevel === void 0) {
916
- optionsOrLogLevel = { logLevel: DiagLogLevel.INFO };
917
- }
918
- if (logger === self) {
919
- var err = new Error("Cannot use diag as the logger for itself. Please use a DiagLogger implementation like ConsoleDiagLogger or a custom implementation");
920
- self.error((_a = err.stack) !== null && _a !== void 0 ? _a : err.message);
921
- return false;
922
- }
923
- if (typeof optionsOrLogLevel === "number") {
924
- optionsOrLogLevel = {
925
- logLevel: optionsOrLogLevel
926
- };
927
- }
928
- var oldLogger = getGlobal("diag");
929
- var newLogger = createLogLevelDiagLogger((_b = optionsOrLogLevel.logLevel) !== null && _b !== void 0 ? _b : DiagLogLevel.INFO, logger);
930
- if (oldLogger && !optionsOrLogLevel.suppressOverrideMessage) {
931
- var stack = (_c = new Error().stack) !== null && _c !== void 0 ? _c : "<failed to generate stacktrace>";
932
- oldLogger.warn("Current logger will be overwritten from " + stack);
933
- newLogger.warn("Current logger will overwrite one already registered from " + stack);
934
- }
935
- return registerGlobal("diag", newLogger, self, true);
936
- };
937
- self.setLogger = setLogger;
938
- self.disable = function() {
939
- unregisterGlobal(API_NAME, self);
940
- };
941
- self.createComponentLogger = function(options) {
942
- return new DiagComponentLogger(options);
943
- };
944
- self.verbose = _logProxy("verbose");
945
- self.debug = _logProxy("debug");
946
- self.info = _logProxy("info");
947
- self.warn = _logProxy("warn");
948
- self.error = _logProxy("error");
949
- }
950
- DiagAPI2.instance = function() {
951
- if (!this._instance) {
952
- this._instance = new DiagAPI2();
953
- }
954
- return this._instance;
955
- };
956
- return DiagAPI2;
957
- }()
958
- );
959
-
960
- // node_modules/@opentelemetry/api/build/esm/context/context.js
961
- function createContextKey(description) {
962
- return Symbol.for(description);
963
- }
964
- var BaseContext = (
965
- /** @class */
966
- /* @__PURE__ */ function() {
967
- function BaseContext2(parentContext) {
968
- var self = this;
969
- self._currentContext = parentContext ? new Map(parentContext) : /* @__PURE__ */ new Map();
970
- self.getValue = function(key) {
971
- return self._currentContext.get(key);
972
- };
973
- self.setValue = function(key, value) {
974
- var context2 = new BaseContext2(self._currentContext);
975
- context2._currentContext.set(key, value);
976
- return context2;
977
- };
978
- self.deleteValue = function(key) {
979
- var context2 = new BaseContext2(self._currentContext);
980
- context2._currentContext.delete(key);
981
- return context2;
982
- };
983
- }
984
- return BaseContext2;
985
- }()
986
- );
987
- var ROOT_CONTEXT = new BaseContext();
988
-
989
- // node_modules/@opentelemetry/api/build/esm/context/NoopContextManager.js
990
- var __read3 = function(o, n) {
991
- var m = typeof Symbol === "function" && o[Symbol.iterator];
992
- if (!m) return o;
993
- var i = m.call(o), r, ar = [], e;
994
- try {
995
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
996
- } catch (error) {
997
- e = { error };
998
- } finally {
999
- try {
1000
- if (r && !r.done && (m = i["return"])) m.call(i);
1001
- } finally {
1002
- if (e) throw e.error;
1003
- }
1004
- }
1005
- return ar;
1006
- };
1007
- var __spreadArray3 = function(to, from, pack) {
1008
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
1009
- if (ar || !(i in from)) {
1010
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
1011
- ar[i] = from[i];
1012
- }
1013
- }
1014
- return to.concat(ar || Array.prototype.slice.call(from));
1015
- };
1016
- var NoopContextManager = (
1017
- /** @class */
1018
- function() {
1019
- function NoopContextManager2() {
1020
- }
1021
- NoopContextManager2.prototype.active = function() {
1022
- return ROOT_CONTEXT;
1023
- };
1024
- NoopContextManager2.prototype.with = function(_context, fn, thisArg) {
1025
- var args = [];
1026
- for (var _i = 3; _i < arguments.length; _i++) {
1027
- args[_i - 3] = arguments[_i];
1028
- }
1029
- return fn.call.apply(fn, __spreadArray3([thisArg], __read3(args), false));
1030
- };
1031
- NoopContextManager2.prototype.bind = function(_context, target) {
1032
- return target;
1033
- };
1034
- NoopContextManager2.prototype.enable = function() {
1035
- return this;
1036
- };
1037
- NoopContextManager2.prototype.disable = function() {
1038
- return this;
1039
- };
1040
- return NoopContextManager2;
1041
- }()
1042
- );
1043
-
1044
- // node_modules/@opentelemetry/api/build/esm/api/context.js
1045
- var __read4 = function(o, n) {
1046
- var m = typeof Symbol === "function" && o[Symbol.iterator];
1047
- if (!m) return o;
1048
- var i = m.call(o), r, ar = [], e;
1049
- try {
1050
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
1051
- } catch (error) {
1052
- e = { error };
1053
- } finally {
1054
- try {
1055
- if (r && !r.done && (m = i["return"])) m.call(i);
1056
- } finally {
1057
- if (e) throw e.error;
1058
- }
1059
- }
1060
- return ar;
1061
- };
1062
- var __spreadArray4 = function(to, from, pack) {
1063
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
1064
- if (ar || !(i in from)) {
1065
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
1066
- ar[i] = from[i];
1067
- }
1068
- }
1069
- return to.concat(ar || Array.prototype.slice.call(from));
1070
- };
1071
- var API_NAME2 = "context";
1072
- var NOOP_CONTEXT_MANAGER = new NoopContextManager();
1073
- var ContextAPI = (
1074
- /** @class */
1075
- function() {
1076
- function ContextAPI2() {
1077
- }
1078
- ContextAPI2.getInstance = function() {
1079
- if (!this._instance) {
1080
- this._instance = new ContextAPI2();
1081
- }
1082
- return this._instance;
1083
- };
1084
- ContextAPI2.prototype.setGlobalContextManager = function(contextManager) {
1085
- return registerGlobal(API_NAME2, contextManager, DiagAPI.instance());
1086
- };
1087
- ContextAPI2.prototype.active = function() {
1088
- return this._getContextManager().active();
1089
- };
1090
- ContextAPI2.prototype.with = function(context2, fn, thisArg) {
1091
- var _a;
1092
- var args = [];
1093
- for (var _i = 3; _i < arguments.length; _i++) {
1094
- args[_i - 3] = arguments[_i];
1095
- }
1096
- return (_a = this._getContextManager()).with.apply(_a, __spreadArray4([context2, fn, thisArg], __read4(args), false));
1097
- };
1098
- ContextAPI2.prototype.bind = function(context2, target) {
1099
- return this._getContextManager().bind(context2, target);
1100
- };
1101
- ContextAPI2.prototype._getContextManager = function() {
1102
- return getGlobal(API_NAME2) || NOOP_CONTEXT_MANAGER;
1103
- };
1104
- ContextAPI2.prototype.disable = function() {
1105
- this._getContextManager().disable();
1106
- unregisterGlobal(API_NAME2, DiagAPI.instance());
1107
- };
1108
- return ContextAPI2;
1109
- }()
1110
- );
1111
-
1112
- // node_modules/@opentelemetry/api/build/esm/trace/trace_flags.js
1113
- var TraceFlags;
1114
- (function(TraceFlags2) {
1115
- TraceFlags2[TraceFlags2["NONE"] = 0] = "NONE";
1116
- TraceFlags2[TraceFlags2["SAMPLED"] = 1] = "SAMPLED";
1117
- })(TraceFlags || (TraceFlags = {}));
1118
-
1119
- // node_modules/@opentelemetry/api/build/esm/trace/invalid-span-constants.js
1120
- var INVALID_SPANID = "0000000000000000";
1121
- var INVALID_TRACEID = "00000000000000000000000000000000";
1122
- var INVALID_SPAN_CONTEXT = {
1123
- traceId: INVALID_TRACEID,
1124
- spanId: INVALID_SPANID,
1125
- traceFlags: TraceFlags.NONE
1126
- };
1127
-
1128
- // node_modules/@opentelemetry/api/build/esm/trace/NonRecordingSpan.js
1129
- var NonRecordingSpan = (
1130
- /** @class */
1131
- function() {
1132
- function NonRecordingSpan2(_spanContext) {
1133
- if (_spanContext === void 0) {
1134
- _spanContext = INVALID_SPAN_CONTEXT;
1135
- }
1136
- this._spanContext = _spanContext;
1137
- }
1138
- NonRecordingSpan2.prototype.spanContext = function() {
1139
- return this._spanContext;
1140
- };
1141
- NonRecordingSpan2.prototype.setAttribute = function(_key, _value) {
1142
- return this;
1143
- };
1144
- NonRecordingSpan2.prototype.setAttributes = function(_attributes) {
1145
- return this;
1146
- };
1147
- NonRecordingSpan2.prototype.addEvent = function(_name, _attributes) {
1148
- return this;
1149
- };
1150
- NonRecordingSpan2.prototype.setStatus = function(_status) {
1151
- return this;
1152
- };
1153
- NonRecordingSpan2.prototype.updateName = function(_name) {
1154
- return this;
1155
- };
1156
- NonRecordingSpan2.prototype.end = function(_endTime) {
1157
- };
1158
- NonRecordingSpan2.prototype.isRecording = function() {
1159
- return false;
1160
- };
1161
- NonRecordingSpan2.prototype.recordException = function(_exception, _time) {
1162
- };
1163
- return NonRecordingSpan2;
1164
- }()
1165
- );
1166
-
1167
- // node_modules/@opentelemetry/api/build/esm/trace/context-utils.js
1168
- var SPAN_KEY = createContextKey("OpenTelemetry Context Key SPAN");
1169
- function getSpan(context2) {
1170
- return context2.getValue(SPAN_KEY) || void 0;
1171
- }
1172
- function getActiveSpan() {
1173
- return getSpan(ContextAPI.getInstance().active());
1174
- }
1175
- function setSpan(context2, span) {
1176
- return context2.setValue(SPAN_KEY, span);
1177
- }
1178
- function deleteSpan(context2) {
1179
- return context2.deleteValue(SPAN_KEY);
1180
- }
1181
- function setSpanContext(context2, spanContext) {
1182
- return setSpan(context2, new NonRecordingSpan(spanContext));
1183
- }
1184
- function getSpanContext(context2) {
1185
- var _a;
1186
- return (_a = getSpan(context2)) === null || _a === void 0 ? void 0 : _a.spanContext();
1187
- }
1188
-
1189
- // node_modules/@opentelemetry/api/build/esm/trace/spancontext-utils.js
1190
- var VALID_TRACEID_REGEX = /^([0-9a-f]{32})$/i;
1191
- var VALID_SPANID_REGEX = /^[0-9a-f]{16}$/i;
1192
- function isValidTraceId(traceId) {
1193
- return VALID_TRACEID_REGEX.test(traceId) && traceId !== INVALID_TRACEID;
1194
- }
1195
- function isValidSpanId(spanId) {
1196
- return VALID_SPANID_REGEX.test(spanId) && spanId !== INVALID_SPANID;
1197
- }
1198
- function isSpanContextValid(spanContext) {
1199
- return isValidTraceId(spanContext.traceId) && isValidSpanId(spanContext.spanId);
1200
- }
1201
- function wrapSpanContext(spanContext) {
1202
- return new NonRecordingSpan(spanContext);
1203
- }
1204
-
1205
- // node_modules/@opentelemetry/api/build/esm/trace/NoopTracer.js
1206
- var contextApi = ContextAPI.getInstance();
1207
- var NoopTracer = (
1208
- /** @class */
1209
- function() {
1210
- function NoopTracer2() {
1211
- }
1212
- NoopTracer2.prototype.startSpan = function(name, options, context2) {
1213
- if (context2 === void 0) {
1214
- context2 = contextApi.active();
1215
- }
1216
- var root = Boolean(options === null || options === void 0 ? void 0 : options.root);
1217
- if (root) {
1218
- return new NonRecordingSpan();
1219
- }
1220
- var parentFromContext = context2 && getSpanContext(context2);
1221
- if (isSpanContext(parentFromContext) && isSpanContextValid(parentFromContext)) {
1222
- return new NonRecordingSpan(parentFromContext);
1223
- } else {
1224
- return new NonRecordingSpan();
1225
- }
1226
- };
1227
- NoopTracer2.prototype.startActiveSpan = function(name, arg2, arg3, arg4) {
1228
- var opts;
1229
- var ctx;
1230
- var fn;
1231
- if (arguments.length < 2) {
1232
- return;
1233
- } else if (arguments.length === 2) {
1234
- fn = arg2;
1235
- } else if (arguments.length === 3) {
1236
- opts = arg2;
1237
- fn = arg3;
1238
- } else {
1239
- opts = arg2;
1240
- ctx = arg3;
1241
- fn = arg4;
1242
- }
1243
- var parentContext = ctx !== null && ctx !== void 0 ? ctx : contextApi.active();
1244
- var span = this.startSpan(name, opts, parentContext);
1245
- var contextWithSpanSet = setSpan(parentContext, span);
1246
- return contextApi.with(contextWithSpanSet, fn, void 0, span);
1247
- };
1248
- return NoopTracer2;
1249
- }()
1250
- );
1251
- function isSpanContext(spanContext) {
1252
- return typeof spanContext === "object" && typeof spanContext["spanId"] === "string" && typeof spanContext["traceId"] === "string" && typeof spanContext["traceFlags"] === "number";
1253
- }
1254
-
1255
- // node_modules/@opentelemetry/api/build/esm/trace/ProxyTracer.js
1256
- var NOOP_TRACER = new NoopTracer();
1257
- var ProxyTracer = (
1258
- /** @class */
1259
- function() {
1260
- function ProxyTracer2(_provider, name, version, options) {
1261
- this._provider = _provider;
1262
- this.name = name;
1263
- this.version = version;
1264
- this.options = options;
1265
- }
1266
- ProxyTracer2.prototype.startSpan = function(name, options, context2) {
1267
- return this._getTracer().startSpan(name, options, context2);
1268
- };
1269
- ProxyTracer2.prototype.startActiveSpan = function(_name, _options, _context, _fn) {
1270
- var tracer2 = this._getTracer();
1271
- return Reflect.apply(tracer2.startActiveSpan, tracer2, arguments);
1272
- };
1273
- ProxyTracer2.prototype._getTracer = function() {
1274
- if (this._delegate) {
1275
- return this._delegate;
1276
- }
1277
- var tracer2 = this._provider.getDelegateTracer(this.name, this.version, this.options);
1278
- if (!tracer2) {
1279
- return NOOP_TRACER;
1280
- }
1281
- this._delegate = tracer2;
1282
- return this._delegate;
1283
- };
1284
- return ProxyTracer2;
1285
- }()
1286
- );
1287
-
1288
- // node_modules/@opentelemetry/api/build/esm/trace/NoopTracerProvider.js
1289
- var NoopTracerProvider = (
1290
- /** @class */
1291
- function() {
1292
- function NoopTracerProvider2() {
1293
- }
1294
- NoopTracerProvider2.prototype.getTracer = function(_name, _version, _options) {
1295
- return new NoopTracer();
1296
- };
1297
- return NoopTracerProvider2;
1298
- }()
1299
- );
1300
-
1301
- // node_modules/@opentelemetry/api/build/esm/trace/ProxyTracerProvider.js
1302
- var NOOP_TRACER_PROVIDER = new NoopTracerProvider();
1303
- var ProxyTracerProvider = (
1304
- /** @class */
1305
- function() {
1306
- function ProxyTracerProvider2() {
1307
- }
1308
- ProxyTracerProvider2.prototype.getTracer = function(name, version, options) {
1309
- var _a;
1310
- return (_a = this.getDelegateTracer(name, version, options)) !== null && _a !== void 0 ? _a : new ProxyTracer(this, name, version, options);
1311
- };
1312
- ProxyTracerProvider2.prototype.getDelegate = function() {
1313
- var _a;
1314
- return (_a = this._delegate) !== null && _a !== void 0 ? _a : NOOP_TRACER_PROVIDER;
1315
- };
1316
- ProxyTracerProvider2.prototype.setDelegate = function(delegate) {
1317
- this._delegate = delegate;
1318
- };
1319
- ProxyTracerProvider2.prototype.getDelegateTracer = function(name, version, options) {
1320
- var _a;
1321
- return (_a = this._delegate) === null || _a === void 0 ? void 0 : _a.getTracer(name, version, options);
1322
- };
1323
- return ProxyTracerProvider2;
1324
- }()
1325
- );
1326
-
1327
- // node_modules/@opentelemetry/api/build/esm/trace/status.js
1328
- var SpanStatusCode;
1329
- (function(SpanStatusCode2) {
1330
- SpanStatusCode2[SpanStatusCode2["UNSET"] = 0] = "UNSET";
1331
- SpanStatusCode2[SpanStatusCode2["OK"] = 1] = "OK";
1332
- SpanStatusCode2[SpanStatusCode2["ERROR"] = 2] = "ERROR";
1333
- })(SpanStatusCode || (SpanStatusCode = {}));
1334
-
1335
- // node_modules/@opentelemetry/api/build/esm/context-api.js
1336
- var context = ContextAPI.getInstance();
1337
-
1338
- // node_modules/@opentelemetry/api/build/esm/api/trace.js
1339
- var API_NAME3 = "trace";
1340
- var TraceAPI = (
1341
- /** @class */
1342
- function() {
1343
- function TraceAPI2() {
1344
- this._proxyTracerProvider = new ProxyTracerProvider();
1345
- this.wrapSpanContext = wrapSpanContext;
1346
- this.isSpanContextValid = isSpanContextValid;
1347
- this.deleteSpan = deleteSpan;
1348
- this.getSpan = getSpan;
1349
- this.getActiveSpan = getActiveSpan;
1350
- this.getSpanContext = getSpanContext;
1351
- this.setSpan = setSpan;
1352
- this.setSpanContext = setSpanContext;
1353
- }
1354
- TraceAPI2.getInstance = function() {
1355
- if (!this._instance) {
1356
- this._instance = new TraceAPI2();
1357
- }
1358
- return this._instance;
1359
- };
1360
- TraceAPI2.prototype.setGlobalTracerProvider = function(provider) {
1361
- var success = registerGlobal(API_NAME3, this._proxyTracerProvider, DiagAPI.instance());
1362
- if (success) {
1363
- this._proxyTracerProvider.setDelegate(provider);
1364
- }
1365
- return success;
1366
- };
1367
- TraceAPI2.prototype.getTracerProvider = function() {
1368
- return getGlobal(API_NAME3) || this._proxyTracerProvider;
1369
- };
1370
- TraceAPI2.prototype.getTracer = function(name, version) {
1371
- return this.getTracerProvider().getTracer(name, version);
1372
- };
1373
- TraceAPI2.prototype.disable = function() {
1374
- unregisterGlobal(API_NAME3, DiagAPI.instance());
1375
- this._proxyTracerProvider = new ProxyTracerProvider();
1376
- };
1377
- return TraceAPI2;
1378
- }()
1379
- );
1380
-
1381
- // node_modules/@opentelemetry/api/build/esm/trace-api.js
1382
- var trace = TraceAPI.getInstance();
1383
-
1384
- // node_modules/@opentelemetry/api/build/esm/experimental/trace/SugaredTracer.js
1385
- var defaultOnException = function(e, span) {
1386
- span.recordException(e);
1387
- span.setStatus({
1388
- code: SpanStatusCode.ERROR
1389
- });
1390
- };
1391
- function wrapTracer(tracer2) {
1392
- return new SugaredTracer(tracer2);
1393
- }
1394
- var SugaredTracer = (
1395
- /** @class */
1396
- function() {
1397
- function SugaredTracer3(tracer2) {
1398
- this._tracer = tracer2;
1399
- this.startSpan = tracer2.startSpan.bind(this._tracer);
1400
- this.startActiveSpan = tracer2.startActiveSpan.bind(this._tracer);
1401
- }
1402
- SugaredTracer3.prototype.withActiveSpan = function(name, arg2, arg3, arg4) {
1403
- var _a = massageParams(arg2, arg3, arg4), opts = _a.opts, ctx = _a.ctx, fn = _a.fn;
1404
- return this._tracer.startActiveSpan(name, opts, ctx, function(span) {
1405
- return handleFn(span, opts, fn);
1406
- });
1407
- };
1408
- SugaredTracer3.prototype.withSpan = function(name, arg2, arg3, arg4) {
1409
- var _a = massageParams(arg2, arg3, arg4), opts = _a.opts, ctx = _a.ctx, fn = _a.fn;
1410
- var span = this._tracer.startSpan(name, opts, ctx);
1411
- return handleFn(span, opts, fn);
1412
- };
1413
- return SugaredTracer3;
1414
- }()
1415
- );
1416
- function massageParams(arg, arg2, arg3) {
1417
- var opts;
1418
- var ctx;
1419
- var fn;
1420
- if (!arg2 && !arg3) {
1421
- fn = arg;
1422
- } else if (!arg3) {
1423
- opts = arg;
1424
- fn = arg2;
1425
- } else {
1426
- opts = arg;
1427
- ctx = arg2;
1428
- fn = arg3;
1429
- }
1430
- opts = opts !== null && opts !== void 0 ? opts : {};
1431
- ctx = ctx !== null && ctx !== void 0 ? ctx : context.active();
1432
- return { opts, ctx, fn };
1433
- }
1434
- function handleFn(span, opts, fn) {
1435
- var _a;
1436
- var onException = (_a = opts.onException) !== null && _a !== void 0 ? _a : defaultOnException;
1437
- var errorHandler = function(e) {
1438
- onException(e, span);
1439
- span.end();
1440
- throw e;
1441
- };
1442
- try {
1443
- var ret = fn(span);
1444
- if (typeof (ret === null || ret === void 0 ? void 0 : ret.then) === "function") {
1445
- return ret.then(function(val) {
1446
- span.end();
1447
- return val;
1448
- }, errorHandler);
1449
- }
1450
- span.end();
1451
- return ret;
1452
- } catch (e) {
1453
- throw errorHandler(e);
1454
- }
1455
- }
1456
-
1457
- // src/run/handlers/tracer.cts
1458
- var spanMeta = /* @__PURE__ */ new WeakMap();
1459
- var spanCounter = /* @__PURE__ */ new WeakMap();
1460
- function spanHook(span) {
1461
- const originalEnd = span.end.bind(span);
1462
- span.end = (endTime) => {
1463
- originalEnd(endTime);
1464
- const meta = spanMeta.get(span);
1465
- if (meta) {
1466
- const requestContext = getRequestContext();
1467
- if (requestContext?.captureServerTiming) {
1468
- const duration = (typeof endTime === "number" ? endTime : performance.now()) - meta.start;
1469
- const serverTiming = requestContext.serverTiming ?? "";
1470
- const currentRequestSpanCounter = spanCounter.get(requestContext) ?? 1;
1471
- requestContext.serverTiming = `${serverTiming}${serverTiming.length === 0 ? "" : ", "}s${currentRequestSpanCounter};dur=${duration};desc="${meta.name}"`;
1472
- spanCounter.set(requestContext, currentRequestSpanCounter + 1);
1473
- }
1474
- }
1475
- spanMeta.delete(span);
1476
- };
1477
- return span;
1478
- }
1479
- var tracer;
1480
- function getTracer() {
1481
- if (!tracer) {
1482
- const baseTracer = trace.getTracer("Next.js Runtime");
1483
- const startSpan = baseTracer.startSpan.bind(baseTracer);
1484
- baseTracer.startSpan = (...args) => {
1485
- const span = startSpan(...args);
1486
- spanMeta.set(span, { start: performance.now(), name: args[0] });
1487
- return spanHook(span);
1488
- };
1489
- const startActiveSpan = baseTracer.startActiveSpan.bind(baseTracer);
1490
- baseTracer.startActiveSpan = (...args) => {
1491
- const [name, ...restOfArgs] = args;
1492
- const augmentedArgs = restOfArgs.map((arg) => {
1493
- if (typeof arg === "function") {
1494
- return (span) => {
1495
- spanMeta.set(span, { start: performance.now(), name: args[0] });
1496
- spanHook(span);
1497
- return arg(span);
1498
- };
1499
- }
1500
- return arg;
1501
- });
1502
- return startActiveSpan(name, ...augmentedArgs);
1503
- };
1504
- tracer = wrapTracer(baseTracer);
1505
- }
1506
- return tracer;
1507
- }
1508
-
1509
- // node_modules/@netlify/blobs/dist/chunk-GUEW34CP.js
1510
- var NF_ERROR = "x-nf-error";
1511
- var NF_REQUEST_ID = "x-nf-request-id";
1512
- var BlobsInternalError = class extends Error {
1513
- constructor(res) {
1514
- let details = res.headers.get(NF_ERROR) || `${res.status} status code`;
1515
- if (res.headers.has(NF_REQUEST_ID)) {
1516
- details += `, ID: ${res.headers.get(NF_REQUEST_ID)}`;
1517
- }
1518
- super(`Netlify Blobs has generated an internal error (${details})`);
1519
- this.name = "BlobsInternalError";
1520
- }
1521
- };
1522
- var collectIterator = async (iterator) => {
1523
- const result = [];
1524
- for await (const item of iterator) {
1525
- result.push(item);
1526
- }
1527
- return result;
1528
- };
1529
- var base64Decode = (input) => {
1530
- const { Buffer: Buffer3 } = globalThis;
1531
- if (Buffer3) {
1532
- return Buffer3.from(input, "base64").toString();
1533
- }
1534
- return atob(input);
1535
- };
1536
- var base64Encode = (input) => {
1537
- const { Buffer: Buffer3 } = globalThis;
1538
- if (Buffer3) {
1539
- return Buffer3.from(input).toString("base64");
1540
- }
1541
- return btoa(input);
1542
- };
1543
- var getEnvironment = () => {
1544
- const { Deno, Netlify, process: process2 } = globalThis;
1545
- return Netlify?.env ?? Deno?.env ?? {
1546
- delete: (key) => delete process2?.env[key],
1547
- get: (key) => process2?.env[key],
1548
- has: (key) => Boolean(process2?.env[key]),
1549
- set: (key, value) => {
1550
- if (process2?.env) {
1551
- process2.env[key] = value;
1552
- }
1553
- },
1554
- toObject: () => process2?.env ?? {}
1555
- };
1556
- };
1557
- var getEnvironmentContext = () => {
1558
- const context2 = globalThis.netlifyBlobsContext || getEnvironment().get("NETLIFY_BLOBS_CONTEXT");
1559
- if (typeof context2 !== "string" || !context2) {
1560
- return {};
1561
- }
1562
- const data = base64Decode(context2);
1563
- try {
1564
- return JSON.parse(data);
1565
- } catch {
1566
- }
1567
- return {};
1568
- };
1569
- var MissingBlobsEnvironmentError = class extends Error {
1570
- constructor(requiredProperties) {
1571
- super(
1572
- `The environment has not been configured to use Netlify Blobs. To use it manually, supply the following properties when creating a store: ${requiredProperties.join(
1573
- ", "
1574
- )}`
1575
- );
1576
- this.name = "MissingBlobsEnvironmentError";
1577
- }
1578
- };
1579
- var BASE64_PREFIX = "b64;";
1580
- var METADATA_HEADER_INTERNAL = "x-amz-meta-user";
1581
- var METADATA_HEADER_EXTERNAL = "netlify-blobs-metadata";
1582
- var METADATA_MAX_SIZE = 2 * 1024;
1583
- var encodeMetadata = (metadata) => {
1584
- if (!metadata) {
1585
- return null;
1586
- }
1587
- const encodedObject = base64Encode(JSON.stringify(metadata));
1588
- const payload = `b64;${encodedObject}`;
1589
- if (METADATA_HEADER_EXTERNAL.length + payload.length > METADATA_MAX_SIZE) {
1590
- throw new Error("Metadata object exceeds the maximum size");
1591
- }
1592
- return payload;
1593
- };
1594
- var decodeMetadata = (header) => {
1595
- if (!header || !header.startsWith(BASE64_PREFIX)) {
1596
- return {};
1597
- }
1598
- const encodedData = header.slice(BASE64_PREFIX.length);
1599
- const decodedData = base64Decode(encodedData);
1600
- const metadata = JSON.parse(decodedData);
1601
- return metadata;
1602
- };
1603
- var getMetadataFromResponse = (response) => {
1604
- if (!response.headers) {
1605
- return {};
1606
- }
1607
- const value = response.headers.get(METADATA_HEADER_EXTERNAL) || response.headers.get(METADATA_HEADER_INTERNAL);
1608
- try {
1609
- return decodeMetadata(value);
1610
- } catch {
1611
- throw new Error(
1612
- "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."
1613
- );
1614
- }
1615
- };
1616
- var BlobsConsistencyError = class extends Error {
1617
- constructor() {
1618
- super(
1619
- `Netlify Blobs has failed to perform a read using strong consistency because the environment has not been configured with a 'uncachedEdgeURL' property`
1620
- );
1621
- this.name = "BlobsConsistencyError";
1622
- }
1623
- };
1624
- var REGION_AUTO = "auto";
1625
- var regions = {
1626
- "us-east-1": true,
1627
- "us-east-2": true
1628
- };
1629
- var isValidRegion = (input) => Object.keys(regions).includes(input);
1630
- var InvalidBlobsRegionError = class extends Error {
1631
- constructor(region) {
1632
- super(
1633
- `${region} is not a supported Netlify Blobs region. Supported values are: ${Object.keys(regions).join(", ")}.`
1634
- );
1635
- this.name = "InvalidBlobsRegionError";
1636
- }
1637
- };
1638
- var DEFAULT_RETRY_DELAY = getEnvironment().get("NODE_ENV") === "test" ? 1 : 5e3;
1639
- var MIN_RETRY_DELAY = 1e3;
1640
- var MAX_RETRY = 5;
1641
- var RATE_LIMIT_HEADER = "X-RateLimit-Reset";
1642
- var fetchAndRetry = async (fetch, url, options, attemptsLeft = MAX_RETRY) => {
1643
- try {
1644
- const res = await fetch(url, options);
1645
- if (attemptsLeft > 0 && (res.status === 429 || res.status >= 500)) {
1646
- const delay = getDelay(res.headers.get(RATE_LIMIT_HEADER));
1647
- await sleep(delay);
1648
- return fetchAndRetry(fetch, url, options, attemptsLeft - 1);
1649
- }
1650
- return res;
1651
- } catch (error) {
1652
- if (attemptsLeft === 0) {
1653
- throw error;
1654
- }
1655
- const delay = getDelay();
1656
- await sleep(delay);
1657
- return fetchAndRetry(fetch, url, options, attemptsLeft - 1);
1658
- }
1659
- };
1660
- var getDelay = (rateLimitReset) => {
1661
- if (!rateLimitReset) {
1662
- return DEFAULT_RETRY_DELAY;
1663
- }
1664
- return Math.max(Number(rateLimitReset) * 1e3 - Date.now(), MIN_RETRY_DELAY);
1665
- };
1666
- var sleep = (ms) => new Promise((resolve2) => {
1667
- setTimeout(resolve2, ms);
1668
- });
1669
- var SIGNED_URL_ACCEPT_HEADER = "application/json;type=signed-url";
1670
- var Client = class {
1671
- constructor({ apiURL, consistency, edgeURL, fetch, region, siteID, token, uncachedEdgeURL }) {
1672
- this.apiURL = apiURL;
1673
- this.consistency = consistency ?? "eventual";
1674
- this.edgeURL = edgeURL;
1675
- this.fetch = fetch ?? globalThis.fetch;
1676
- this.region = region;
1677
- this.siteID = siteID;
1678
- this.token = token;
1679
- this.uncachedEdgeURL = uncachedEdgeURL;
1680
- if (!this.fetch) {
1681
- throw new Error(
1682
- "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."
1683
- );
1684
- }
1685
- }
1686
- async getFinalRequest({
1687
- consistency: opConsistency,
1688
- key,
1689
- metadata,
1690
- method,
1691
- parameters = {},
1692
- storeName
1693
- }) {
1694
- const encodedMetadata = encodeMetadata(metadata);
1695
- const consistency = opConsistency ?? this.consistency;
1696
- let urlPath = `/${this.siteID}`;
1697
- if (storeName) {
1698
- urlPath += `/${storeName}`;
1699
- }
1700
- if (key) {
1701
- urlPath += `/${key}`;
1702
- }
1703
- if (this.edgeURL) {
1704
- if (consistency === "strong" && !this.uncachedEdgeURL) {
1705
- throw new BlobsConsistencyError();
1706
- }
1707
- const headers = {
1708
- authorization: `Bearer ${this.token}`
1709
- };
1710
- if (encodedMetadata) {
1711
- headers[METADATA_HEADER_INTERNAL] = encodedMetadata;
1712
- }
1713
- if (this.region) {
1714
- urlPath = `/region:${this.region}${urlPath}`;
1715
- }
1716
- const url2 = new URL(urlPath, consistency === "strong" ? this.uncachedEdgeURL : this.edgeURL);
1717
- for (const key2 in parameters) {
1718
- url2.searchParams.set(key2, parameters[key2]);
1719
- }
1720
- return {
1721
- headers,
1722
- url: url2.toString()
1723
- };
1724
- }
1725
- const apiHeaders = { authorization: `Bearer ${this.token}` };
1726
- const url = new URL(`/api/v1/blobs${urlPath}`, this.apiURL ?? "https://api.netlify.com");
1727
- for (const key2 in parameters) {
1728
- url.searchParams.set(key2, parameters[key2]);
1729
- }
1730
- if (this.region) {
1731
- url.searchParams.set("region", this.region);
1732
- }
1733
- if (storeName === void 0 || key === void 0) {
1734
- return {
1735
- headers: apiHeaders,
1736
- url: url.toString()
1737
- };
1738
- }
1739
- if (encodedMetadata) {
1740
- apiHeaders[METADATA_HEADER_EXTERNAL] = encodedMetadata;
1741
- }
1742
- if (method === "head" || method === "delete") {
1743
- return {
1744
- headers: apiHeaders,
1745
- url: url.toString()
1746
- };
1747
- }
1748
- const res = await this.fetch(url.toString(), {
1749
- headers: { ...apiHeaders, accept: SIGNED_URL_ACCEPT_HEADER },
1750
- method
1751
- });
1752
- if (res.status !== 200) {
1753
- throw new BlobsInternalError(res);
1754
- }
1755
- const { url: signedURL } = await res.json();
1756
- const userHeaders = encodedMetadata ? { [METADATA_HEADER_INTERNAL]: encodedMetadata } : void 0;
1757
- return {
1758
- headers: userHeaders,
1759
- url: signedURL
1760
- };
1761
- }
1762
- async makeRequest({
1763
- body,
1764
- consistency,
1765
- headers: extraHeaders,
1766
- key,
1767
- metadata,
1768
- method,
1769
- parameters,
1770
- storeName
1771
- }) {
1772
- const { headers: baseHeaders = {}, url } = await this.getFinalRequest({
1773
- consistency,
1774
- key,
1775
- metadata,
1776
- method,
1777
- parameters,
1778
- storeName
1779
- });
1780
- const headers = {
1781
- ...baseHeaders,
1782
- ...extraHeaders
1783
- };
1784
- if (method === "put") {
1785
- headers["cache-control"] = "max-age=0, stale-while-revalidate=60";
1786
- }
1787
- const options = {
1788
- body,
1789
- headers,
1790
- method
1791
- };
1792
- if (body instanceof ReadableStream) {
1793
- options.duplex = "half";
1794
- }
1795
- return fetchAndRetry(this.fetch, url, options);
1796
- }
1797
- };
1798
- var getClientOptions = (options, contextOverride) => {
1799
- const context2 = contextOverride ?? getEnvironmentContext();
1800
- const siteID = context2.siteID ?? options.siteID;
1801
- const token = context2.token ?? options.token;
1802
- if (!siteID || !token) {
1803
- throw new MissingBlobsEnvironmentError(["siteID", "token"]);
1804
- }
1805
- if (options.region !== void 0 && !isValidRegion(options.region)) {
1806
- throw new InvalidBlobsRegionError(options.region);
1807
- }
1808
- const clientOptions = {
1809
- apiURL: context2.apiURL ?? options.apiURL,
1810
- consistency: options.consistency,
1811
- edgeURL: context2.edgeURL ?? options.edgeURL,
1812
- fetch: options.fetch,
1813
- region: options.region,
1814
- siteID,
1815
- token,
1816
- uncachedEdgeURL: context2.uncachedEdgeURL ?? options.uncachedEdgeURL
1817
- };
1818
- return clientOptions;
1819
- };
1820
-
1821
- // node_modules/@netlify/blobs/dist/main.js
1822
- var DEPLOY_STORE_PREFIX = "deploy:";
1823
- var LEGACY_STORE_INTERNAL_PREFIX = "netlify-internal/legacy-namespace/";
1824
- var SITE_STORE_PREFIX = "site:";
1825
- var Store = class _Store {
1826
- constructor(options) {
1827
- this.client = options.client;
1828
- if ("deployID" in options) {
1829
- _Store.validateDeployID(options.deployID);
1830
- let name = DEPLOY_STORE_PREFIX + options.deployID;
1831
- if (options.name) {
1832
- name += `:${options.name}`;
1833
- }
1834
- this.name = name;
1835
- } else if (options.name.startsWith(LEGACY_STORE_INTERNAL_PREFIX)) {
1836
- const storeName = options.name.slice(LEGACY_STORE_INTERNAL_PREFIX.length);
1837
- _Store.validateStoreName(storeName);
1838
- this.name = storeName;
1839
- } else {
1840
- _Store.validateStoreName(options.name);
1841
- this.name = SITE_STORE_PREFIX + options.name;
1842
- }
1843
- }
1844
- async delete(key) {
1845
- const res = await this.client.makeRequest({ key, method: "delete", storeName: this.name });
1846
- if (![200, 204, 404].includes(res.status)) {
1847
- throw new BlobsInternalError(res);
1848
- }
1849
- }
1850
- async get(key, options) {
1851
- const { consistency, type } = options ?? {};
1852
- const res = await this.client.makeRequest({ consistency, key, method: "get", storeName: this.name });
1853
- if (res.status === 404) {
1854
- return null;
1855
- }
1856
- if (res.status !== 200) {
1857
- throw new BlobsInternalError(res);
1858
- }
1859
- if (type === void 0 || type === "text") {
1860
- return res.text();
1861
- }
1862
- if (type === "arrayBuffer") {
1863
- return res.arrayBuffer();
1864
- }
1865
- if (type === "blob") {
1866
- return res.blob();
1867
- }
1868
- if (type === "json") {
1869
- return res.json();
1870
- }
1871
- if (type === "stream") {
1872
- return res.body;
1873
- }
1874
- throw new BlobsInternalError(res);
1875
- }
1876
- async getMetadata(key, { consistency } = {}) {
1877
- const res = await this.client.makeRequest({ consistency, key, method: "head", storeName: this.name });
1878
- if (res.status === 404) {
1879
- return null;
1880
- }
1881
- if (res.status !== 200 && res.status !== 304) {
1882
- throw new BlobsInternalError(res);
1883
- }
1884
- const etag = res?.headers.get("etag") ?? void 0;
1885
- const metadata = getMetadataFromResponse(res);
1886
- const result = {
1887
- etag,
1888
- metadata
1889
- };
1890
- return result;
1891
- }
1892
- async getWithMetadata(key, options) {
1893
- const { consistency, etag: requestETag, type } = options ?? {};
1894
- const headers = requestETag ? { "if-none-match": requestETag } : void 0;
1895
- const res = await this.client.makeRequest({
1896
- consistency,
1897
- headers,
1898
- key,
1899
- method: "get",
1900
- storeName: this.name
1901
- });
1902
- if (res.status === 404) {
1903
- return null;
1904
- }
1905
- if (res.status !== 200 && res.status !== 304) {
1906
- throw new BlobsInternalError(res);
1907
- }
1908
- const responseETag = res?.headers.get("etag") ?? void 0;
1909
- const metadata = getMetadataFromResponse(res);
1910
- const result = {
1911
- etag: responseETag,
1912
- metadata
1913
- };
1914
- if (res.status === 304 && requestETag) {
1915
- return { data: null, ...result };
1916
- }
1917
- if (type === void 0 || type === "text") {
1918
- return { data: await res.text(), ...result };
1919
- }
1920
- if (type === "arrayBuffer") {
1921
- return { data: await res.arrayBuffer(), ...result };
1922
- }
1923
- if (type === "blob") {
1924
- return { data: await res.blob(), ...result };
1925
- }
1926
- if (type === "json") {
1927
- return { data: await res.json(), ...result };
1928
- }
1929
- if (type === "stream") {
1930
- return { data: res.body, ...result };
1931
- }
1932
- throw new Error(`Invalid 'type' property: ${type}. Expected: arrayBuffer, blob, json, stream, or text.`);
1933
- }
1934
- list(options = {}) {
1935
- const iterator = this.getListIterator(options);
1936
- if (options.paginate) {
1937
- return iterator;
1938
- }
1939
- return collectIterator(iterator).then(
1940
- (items) => items.reduce(
1941
- (acc, item) => ({
1942
- blobs: [...acc.blobs, ...item.blobs],
1943
- directories: [...acc.directories, ...item.directories]
1944
- }),
1945
- { blobs: [], directories: [] }
1946
- )
1947
- );
1948
- }
1949
- async set(key, data, { metadata } = {}) {
1950
- _Store.validateKey(key);
1951
- const res = await this.client.makeRequest({
1952
- body: data,
1953
- key,
1954
- metadata,
1955
- method: "put",
1956
- storeName: this.name
1957
- });
1958
- if (res.status !== 200) {
1959
- throw new BlobsInternalError(res);
1960
- }
1961
- }
1962
- async setJSON(key, data, { metadata } = {}) {
1963
- _Store.validateKey(key);
1964
- const payload = JSON.stringify(data);
1965
- const headers = {
1966
- "content-type": "application/json"
1967
- };
1968
- const res = await this.client.makeRequest({
1969
- body: payload,
1970
- headers,
1971
- key,
1972
- metadata,
1973
- method: "put",
1974
- storeName: this.name
1975
- });
1976
- if (res.status !== 200) {
1977
- throw new BlobsInternalError(res);
1978
- }
1979
- }
1980
- static formatListResultBlob(result) {
1981
- if (!result.key) {
1982
- return null;
1983
- }
1984
- return {
1985
- etag: result.etag,
1986
- key: result.key
1987
- };
1988
- }
1989
- static validateKey(key) {
1990
- if (key === "") {
1991
- throw new Error("Blob key must not be empty.");
1992
- }
1993
- if (key.startsWith("/") || key.startsWith("%2F")) {
1994
- throw new Error("Blob key must not start with forward slash (/).");
1995
- }
1996
- if (new TextEncoder().encode(key).length > 600) {
1997
- throw new Error(
1998
- "Blob key must be a sequence of Unicode characters whose UTF-8 encoding is at most 600 bytes long."
1999
- );
2000
- }
2001
- }
2002
- static validateDeployID(deployID) {
2003
- if (!/^\w{1,24}$/.test(deployID)) {
2004
- throw new Error(`'${deployID}' is not a valid Netlify deploy ID.`);
2005
- }
2006
- }
2007
- static validateStoreName(name) {
2008
- if (name.includes("/") || name.includes("%2F")) {
2009
- throw new Error("Store name must not contain forward slashes (/).");
2010
- }
2011
- if (new TextEncoder().encode(name).length > 64) {
2012
- throw new Error(
2013
- "Store name must be a sequence of Unicode characters whose UTF-8 encoding is at most 64 bytes long."
2014
- );
2015
- }
2016
- }
2017
- getListIterator(options) {
2018
- const { client, name: storeName } = this;
2019
- const parameters = {};
2020
- if (options?.prefix) {
2021
- parameters.prefix = options.prefix;
2022
- }
2023
- if (options?.directories) {
2024
- parameters.directories = "true";
2025
- }
2026
- return {
2027
- [Symbol.asyncIterator]() {
2028
- let currentCursor = null;
2029
- let done = false;
2030
- return {
2031
- async next() {
2032
- if (done) {
2033
- return { done: true, value: void 0 };
2034
- }
2035
- const nextParameters = { ...parameters };
2036
- if (currentCursor !== null) {
2037
- nextParameters.cursor = currentCursor;
2038
- }
2039
- const res = await client.makeRequest({
2040
- method: "get",
2041
- parameters: nextParameters,
2042
- storeName
2043
- });
2044
- let blobs = [];
2045
- let directories = [];
2046
- if (![200, 204, 404].includes(res.status)) {
2047
- throw new BlobsInternalError(res);
2048
- }
2049
- if (res.status === 404) {
2050
- done = true;
2051
- } else {
2052
- const page = await res.json();
2053
- if (page.next_cursor) {
2054
- currentCursor = page.next_cursor;
2055
- } else {
2056
- done = true;
2057
- }
2058
- blobs = (page.blobs ?? []).map(_Store.formatListResultBlob).filter(Boolean);
2059
- directories = page.directories ?? [];
2060
- }
2061
- return {
2062
- done: false,
2063
- value: {
2064
- blobs,
2065
- directories
2066
- }
2067
- };
2068
- }
2069
- };
2070
- }
2071
- };
2072
- }
2073
- };
2074
- var getDeployStore = (input = {}) => {
2075
- const context2 = getEnvironmentContext();
2076
- const options = typeof input === "string" ? { name: input } : input;
2077
- const deployID = options.deployID ?? context2.deployID;
2078
- if (!deployID) {
2079
- throw new MissingBlobsEnvironmentError(["deployID"]);
2080
- }
2081
- const clientOptions = getClientOptions(options, context2);
2082
- if (!clientOptions.region) {
2083
- if (clientOptions.edgeURL || clientOptions.uncachedEdgeURL) {
2084
- if (!context2.primaryRegion) {
2085
- throw new Error(
2086
- "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."
2087
- );
2088
- }
2089
- clientOptions.region = context2.primaryRegion;
2090
- } else {
2091
- clientOptions.region = REGION_AUTO;
2092
- }
2093
- }
2094
- const client = new Client(clientOptions);
2095
- return new Store({ client, deployID, name: options.name });
2096
- };
2097
-
2098
- // src/run/regional-blob-store.cts
2099
- var fetchBeforeNextPatchedIt = globalThis.fetch;
2100
- var getRegionalBlobStore = (args = {}) => {
2101
- return getDeployStore({
2102
- ...args,
2103
- fetch: fetchBeforeNextPatchedIt,
2104
- region: process.env.USE_REGIONAL_BLOBS?.toUpperCase() === "TRUE" ? void 0 : "us-east-2"
2105
- });
2106
- };
2107
-
2108
- // src/run/next.cts
494
+ var import_request_context = require("./handlers/request-context.cjs");
495
+ var import_tracer = require("./handlers/tracer.cjs");
496
+ var import_storage = require("./storage/storage.cjs");
2109
497
  process.env.NODE_ENV = "production";
2110
498
  var { getRequestHandlers } = require("next/dist/server/lib/start-server.js");
2111
499
  var ResponseCache = require("next/dist/server/response-cache/index.js").default;
@@ -2117,7 +505,7 @@ ResponseCache.prototype.get = function get(...getArgs) {
2117
505
  this.batcher.batch = async (key, fn) => {
2118
506
  const trackedFn = async (...workFnArgs) => {
2119
507
  const workPromise = fn(...workFnArgs);
2120
- const requestContext = getRequestContext();
508
+ const requestContext = (0, import_request_context.getRequestContext)();
2121
509
  if (requestContext && workPromise instanceof Promise) {
2122
510
  requestContext.trackBackgroundWork(workPromise);
2123
511
  }
@@ -2129,7 +517,7 @@ ResponseCache.prototype.get = function get(...getArgs) {
2129
517
  const backgroundWork = /* @__PURE__ */ new Map();
2130
518
  const originalPendingResponsesSet = this.pendingResponses.set;
2131
519
  this.pendingResponses.set = async (key, value) => {
2132
- const requestContext = getRequestContext();
520
+ const requestContext = (0, import_request_context.getRequestContext)();
2133
521
  if (requestContext && !this.pendingResponses.has(key)) {
2134
522
  const workPromise = new Promise((_resolve) => {
2135
523
  backgroundWork.set(key, _resolve);
@@ -2152,24 +540,21 @@ ResponseCache.prototype.get = function get(...getArgs) {
2152
540
  return originalGet.apply(this, getArgs);
2153
541
  };
2154
542
  async function getMockedRequestHandler(...args) {
2155
- const tracer2 = getTracer();
2156
- return tracer2.withActiveSpan("mocked request handler", async () => {
543
+ const tracer = (0, import_tracer.getTracer)();
544
+ return tracer.withActiveSpan("mocked request handler", async () => {
2157
545
  const ofs = { ...import_promises.default };
2158
- const { encodeBlobKey: encodeBlobKey2 } = await Promise.resolve().then(() => (init_blobkey(), blobkey_exports));
2159
546
  async function readFileFallbackBlobStore(...fsargs) {
2160
547
  const [path, options] = fsargs;
2161
548
  try {
2162
549
  return await ofs.readFile(path, options);
2163
550
  } catch (error) {
2164
551
  if (typeof path === "string" && path.endsWith(".html")) {
2165
- const store = getRegionalBlobStore();
552
+ const cacheStore = (0, import_storage.getMemoizedKeyValueStoreBackedByRegionalBlobStore)();
2166
553
  const relPath = (0, import_path.relative)((0, import_path.resolve)(".next/server/pages"), path);
2167
- const file = await store.get(await encodeBlobKey2(relPath), {
2168
- type: "json"
2169
- });
554
+ const file = await cacheStore.get(relPath, "staticHtml.get");
2170
555
  if (file !== null) {
2171
556
  if (!file.isFallback) {
2172
- const requestContext = getRequestContext();
557
+ const requestContext = (0, import_request_context.getRequestContext)();
2173
558
  if (requestContext) {
2174
559
  requestContext.usedFsReadForNonFallback = true;
2175
560
  }