@netlify/plugin-nextjs 5.1.2 → 5.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/build/advanced-api-routes.js +121 -4
- package/dist/build/cache.js +25 -4
- package/dist/build/content/prerendered.js +234 -8
- package/dist/build/content/server.js +259 -14
- package/dist/build/content/static.js +96 -11
- package/dist/build/functions/edge.js +511 -5
- package/dist/build/functions/server.js +131 -12
- package/dist/build/image-cdn.js +1626 -3
- package/dist/build/plugin-context.js +236 -5
- package/dist/build/templates/handler-monorepo.tmpl.js +3 -0
- package/dist/build/templates/handler.tmpl.js +3 -0
- package/dist/build/verification.js +81 -8
- package/dist/esm-chunks/{package-RVJOBSMH.js → package-ZBRSUKN7.js} +5 -5
- package/dist/index.js +25 -36
- package/dist/run/config.js +25 -6
- package/dist/run/constants.js +7 -5
- package/dist/run/handlers/cache.cjs +6 -567
- package/dist/run/handlers/request-context.cjs +8 -1
- package/dist/run/handlers/server.js +20 -22
- package/dist/run/handlers/tracing.js +1 -1
- package/dist/run/headers.js +198 -8
- package/dist/run/next.cjs +49 -567
- package/dist/{esm-chunks/chunk-PMRBBOBY.js → run/regional-blob-store.cjs} +117 -263
- package/dist/run/revalidate.js +17 -3
- package/dist/run/systemlog.js +94 -3
- package/dist/shared/blobkey.js +15 -3
- package/package.json +1 -1
- package/dist/esm-chunks/chunk-3SUDZQ7L.js +0 -40
- package/dist/esm-chunks/chunk-4BNHE6TP.js +0 -278
- package/dist/esm-chunks/chunk-72ZI2IVI.js +0 -36
- package/dist/esm-chunks/chunk-BG455SFE.js +0 -133
- package/dist/esm-chunks/chunk-HESS57SH.js +0 -127
- package/dist/esm-chunks/chunk-HYBEXB2Z.js +0 -105
- package/dist/esm-chunks/chunk-K7BTUM7O.js +0 -97
- package/dist/esm-chunks/chunk-L6OM53B6.js +0 -238
- package/dist/esm-chunks/chunk-MCEOSJH6.js +0 -1637
- package/dist/esm-chunks/chunk-MRD3XSKD.js +0 -248
- package/dist/esm-chunks/chunk-RL4K4CVH.js +0 -27
- package/dist/esm-chunks/chunk-TYCYFZ22.js +0 -25
- package/dist/esm-chunks/chunk-UTQSBE5O.js +0 -524
- package/dist/esm-chunks/chunk-UYKENJEU.js +0 -19
- package/dist/esm-chunks/chunk-V2T6NUOM.js +0 -113
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
|
};
|
|
@@ -486,19 +483,19 @@ var require_lib = __commonJS({
|
|
|
486
483
|
});
|
|
487
484
|
Object.defineProperty(exports2, "patchFs", {
|
|
488
485
|
enumerable: true,
|
|
489
|
-
get: function
|
|
486
|
+
get: function get2() {
|
|
490
487
|
return _patchFs["default"];
|
|
491
488
|
}
|
|
492
489
|
});
|
|
493
490
|
Object.defineProperty(exports2, "patchRequire", {
|
|
494
491
|
enumerable: true,
|
|
495
|
-
get: function
|
|
492
|
+
get: function get2() {
|
|
496
493
|
return _patchRequire["default"];
|
|
497
494
|
}
|
|
498
495
|
});
|
|
499
496
|
Object.defineProperty(exports2, "unixify", {
|
|
500
497
|
enumerable: true,
|
|
501
|
-
get: function
|
|
498
|
+
get: function get2() {
|
|
502
499
|
return _correctPath.unixify;
|
|
503
500
|
}
|
|
504
501
|
});
|
|
@@ -552,31 +549,6 @@ var require_lib = __commonJS({
|
|
|
552
549
|
}
|
|
553
550
|
});
|
|
554
551
|
|
|
555
|
-
// src/shared/blobkey.ts
|
|
556
|
-
var blobkey_exports = {};
|
|
557
|
-
__export(blobkey_exports, {
|
|
558
|
-
encodeBlobKey: () => encodeBlobKey
|
|
559
|
-
});
|
|
560
|
-
async function encodeBlobKey(key) {
|
|
561
|
-
const buffer = import_node_buffer.Buffer.from(key);
|
|
562
|
-
const base64 = buffer.toString("base64url");
|
|
563
|
-
if (base64.length <= maxLength) {
|
|
564
|
-
return base64;
|
|
565
|
-
}
|
|
566
|
-
const digest = await import_node_crypto.webcrypto.subtle.digest("SHA-256", buffer);
|
|
567
|
-
const hash = import_node_buffer.Buffer.from(digest).toString("base64url");
|
|
568
|
-
return `${base64.slice(0, maxLength - hash.length - 1)}-${hash}`;
|
|
569
|
-
}
|
|
570
|
-
var import_node_buffer, import_node_crypto, maxLength;
|
|
571
|
-
var init_blobkey = __esm({
|
|
572
|
-
"src/shared/blobkey.ts"() {
|
|
573
|
-
"use strict";
|
|
574
|
-
import_node_buffer = require("node:buffer");
|
|
575
|
-
import_node_crypto = require("node:crypto");
|
|
576
|
-
maxLength = 180;
|
|
577
|
-
}
|
|
578
|
-
});
|
|
579
|
-
|
|
580
552
|
// src/run/next.cts
|
|
581
553
|
var next_exports = {};
|
|
582
554
|
__export(next_exports, {
|
|
@@ -585,560 +557,70 @@ __export(next_exports, {
|
|
|
585
557
|
module.exports = __toCommonJS(next_exports);
|
|
586
558
|
var import_promises = __toESM(require("fs/promises"));
|
|
587
559
|
var import_path = require("path");
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
var
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
var base64Encode = (input) => {
|
|
611
|
-
const { Buffer: Buffer3 } = globalThis;
|
|
612
|
-
if (Buffer3) {
|
|
613
|
-
return Buffer3.from(input).toString("base64");
|
|
614
|
-
}
|
|
615
|
-
return btoa(input);
|
|
616
|
-
};
|
|
617
|
-
var BASE64_PREFIX = "b64;";
|
|
618
|
-
var METADATA_HEADER_INTERNAL = "x-amz-meta-user";
|
|
619
|
-
var METADATA_HEADER_EXTERNAL = "netlify-blobs-metadata";
|
|
620
|
-
var METADATA_MAX_SIZE = 2 * 1024;
|
|
621
|
-
var encodeMetadata = (metadata) => {
|
|
622
|
-
if (!metadata) {
|
|
623
|
-
return null;
|
|
624
|
-
}
|
|
625
|
-
const encodedObject = base64Encode(JSON.stringify(metadata));
|
|
626
|
-
const payload = `b64;${encodedObject}`;
|
|
627
|
-
if (METADATA_HEADER_EXTERNAL.length + payload.length > METADATA_MAX_SIZE) {
|
|
628
|
-
throw new Error("Metadata object exceeds the maximum size");
|
|
629
|
-
}
|
|
630
|
-
return payload;
|
|
631
|
-
};
|
|
632
|
-
var decodeMetadata = (header) => {
|
|
633
|
-
if (!header || !header.startsWith(BASE64_PREFIX)) {
|
|
634
|
-
return {};
|
|
635
|
-
}
|
|
636
|
-
const encodedData = header.slice(BASE64_PREFIX.length);
|
|
637
|
-
const decodedData = base64Decode(encodedData);
|
|
638
|
-
const metadata = JSON.parse(decodedData);
|
|
639
|
-
return metadata;
|
|
640
|
-
};
|
|
641
|
-
var getMetadataFromResponse = (response) => {
|
|
642
|
-
if (!response.headers) {
|
|
643
|
-
return {};
|
|
644
|
-
}
|
|
645
|
-
const value = response.headers.get(METADATA_HEADER_EXTERNAL) || response.headers.get(METADATA_HEADER_INTERNAL);
|
|
646
|
-
try {
|
|
647
|
-
return decodeMetadata(value);
|
|
648
|
-
} catch {
|
|
649
|
-
throw new Error(
|
|
650
|
-
"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."
|
|
651
|
-
);
|
|
652
|
-
}
|
|
653
|
-
};
|
|
654
|
-
var BlobsConsistencyError = class extends Error {
|
|
655
|
-
constructor() {
|
|
656
|
-
super(
|
|
657
|
-
`Netlify Blobs has failed to perform a read using strong consistency because the environment has not been configured with a 'uncachedEdgeURL' property`
|
|
658
|
-
);
|
|
659
|
-
this.name = "BlobsConsistencyError";
|
|
660
|
-
}
|
|
661
|
-
};
|
|
662
|
-
var getEnvironment = () => {
|
|
663
|
-
const { Deno, Netlify, process: process2 } = globalThis;
|
|
664
|
-
return Netlify?.env ?? Deno?.env ?? {
|
|
665
|
-
delete: (key) => delete process2?.env[key],
|
|
666
|
-
get: (key) => process2?.env[key],
|
|
667
|
-
has: (key) => Boolean(process2?.env[key]),
|
|
668
|
-
set: (key, value) => {
|
|
669
|
-
if (process2?.env) {
|
|
670
|
-
process2.env[key] = value;
|
|
671
|
-
}
|
|
672
|
-
},
|
|
673
|
-
toObject: () => process2?.env ?? {}
|
|
674
|
-
};
|
|
675
|
-
};
|
|
676
|
-
var getEnvironmentContext = () => {
|
|
677
|
-
const context = globalThis.netlifyBlobsContext || getEnvironment().get("NETLIFY_BLOBS_CONTEXT");
|
|
678
|
-
if (typeof context !== "string" || !context) {
|
|
679
|
-
return {};
|
|
680
|
-
}
|
|
681
|
-
const data = base64Decode(context);
|
|
682
|
-
try {
|
|
683
|
-
return JSON.parse(data);
|
|
684
|
-
} catch {
|
|
685
|
-
}
|
|
686
|
-
return {};
|
|
687
|
-
};
|
|
688
|
-
var MissingBlobsEnvironmentError = class extends Error {
|
|
689
|
-
constructor(requiredProperties) {
|
|
690
|
-
super(
|
|
691
|
-
`The environment has not been configured to use Netlify Blobs. To use it manually, supply the following properties when creating a store: ${requiredProperties.join(
|
|
692
|
-
", "
|
|
693
|
-
)}`
|
|
694
|
-
);
|
|
695
|
-
this.name = "MissingBlobsEnvironmentError";
|
|
696
|
-
}
|
|
697
|
-
};
|
|
698
|
-
var DEFAULT_RETRY_DELAY = getEnvironment().get("NODE_ENV") === "test" ? 1 : 5e3;
|
|
699
|
-
var MIN_RETRY_DELAY = 1e3;
|
|
700
|
-
var MAX_RETRY = 5;
|
|
701
|
-
var RATE_LIMIT_HEADER = "X-RateLimit-Reset";
|
|
702
|
-
var fetchAndRetry = async (fetch, url, options, attemptsLeft = MAX_RETRY) => {
|
|
703
|
-
try {
|
|
704
|
-
const res = await fetch(url, options);
|
|
705
|
-
if (attemptsLeft > 0 && (res.status === 429 || res.status >= 500)) {
|
|
706
|
-
const delay = getDelay(res.headers.get(RATE_LIMIT_HEADER));
|
|
707
|
-
await sleep(delay);
|
|
708
|
-
return fetchAndRetry(fetch, url, options, attemptsLeft - 1);
|
|
709
|
-
}
|
|
710
|
-
return res;
|
|
711
|
-
} catch (error) {
|
|
712
|
-
if (attemptsLeft === 0) {
|
|
713
|
-
throw error;
|
|
714
|
-
}
|
|
715
|
-
const delay = getDelay();
|
|
716
|
-
await sleep(delay);
|
|
717
|
-
return fetchAndRetry(fetch, url, options, attemptsLeft - 1);
|
|
718
|
-
}
|
|
719
|
-
};
|
|
720
|
-
var getDelay = (rateLimitReset) => {
|
|
721
|
-
if (!rateLimitReset) {
|
|
722
|
-
return DEFAULT_RETRY_DELAY;
|
|
723
|
-
}
|
|
724
|
-
return Math.max(Number(rateLimitReset) * 1e3 - Date.now(), MIN_RETRY_DELAY);
|
|
725
|
-
};
|
|
726
|
-
var sleep = (ms) => new Promise((resolve2) => {
|
|
727
|
-
setTimeout(resolve2, ms);
|
|
728
|
-
});
|
|
729
|
-
var SIGNED_URL_ACCEPT_HEADER = "application/json;type=signed-url";
|
|
730
|
-
var Client = class {
|
|
731
|
-
constructor({ apiURL, consistency, edgeURL, fetch, siteID, token, uncachedEdgeURL }) {
|
|
732
|
-
this.apiURL = apiURL;
|
|
733
|
-
this.consistency = consistency ?? "eventual";
|
|
734
|
-
this.edgeURL = edgeURL;
|
|
735
|
-
this.fetch = fetch ?? globalThis.fetch;
|
|
736
|
-
this.siteID = siteID;
|
|
737
|
-
this.token = token;
|
|
738
|
-
this.uncachedEdgeURL = uncachedEdgeURL;
|
|
739
|
-
if (!this.fetch) {
|
|
740
|
-
throw new Error(
|
|
741
|
-
"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."
|
|
742
|
-
);
|
|
743
|
-
}
|
|
744
|
-
}
|
|
745
|
-
async getFinalRequest({
|
|
746
|
-
consistency: opConsistency,
|
|
747
|
-
key,
|
|
748
|
-
metadata,
|
|
749
|
-
method,
|
|
750
|
-
parameters = {},
|
|
751
|
-
storeName
|
|
752
|
-
}) {
|
|
753
|
-
const encodedMetadata = encodeMetadata(metadata);
|
|
754
|
-
const consistency = opConsistency ?? this.consistency;
|
|
755
|
-
let urlPath = `/${this.siteID}`;
|
|
756
|
-
if (storeName) {
|
|
757
|
-
urlPath += `/${storeName}`;
|
|
758
|
-
}
|
|
759
|
-
if (key) {
|
|
760
|
-
urlPath += `/${key}`;
|
|
761
|
-
}
|
|
762
|
-
if (this.edgeURL) {
|
|
763
|
-
if (consistency === "strong" && !this.uncachedEdgeURL) {
|
|
764
|
-
throw new BlobsConsistencyError();
|
|
765
|
-
}
|
|
766
|
-
const headers = {
|
|
767
|
-
authorization: `Bearer ${this.token}`
|
|
768
|
-
};
|
|
769
|
-
if (encodedMetadata) {
|
|
770
|
-
headers[METADATA_HEADER_INTERNAL] = encodedMetadata;
|
|
771
|
-
}
|
|
772
|
-
const url2 = new URL(urlPath, consistency === "strong" ? this.uncachedEdgeURL : this.edgeURL);
|
|
773
|
-
for (const key2 in parameters) {
|
|
774
|
-
url2.searchParams.set(key2, parameters[key2]);
|
|
775
|
-
}
|
|
776
|
-
return {
|
|
777
|
-
headers,
|
|
778
|
-
url: url2.toString()
|
|
560
|
+
var import_fs_monkey = __toESM(require_lib());
|
|
561
|
+
var import_request_context = require("./handlers/request-context.cjs");
|
|
562
|
+
var import_tracer = require("./handlers/tracer.cjs");
|
|
563
|
+
var import_regional_blob_store = require("./regional-blob-store.cjs");
|
|
564
|
+
console.time("import next server");
|
|
565
|
+
var { getRequestHandlers } = require("next/dist/server/lib/start-server.js");
|
|
566
|
+
var ResponseCache = require("next/dist/server/response-cache/index.js").default;
|
|
567
|
+
var originalGet = ResponseCache.prototype.get;
|
|
568
|
+
ResponseCache.prototype.get = function get(...getArgs) {
|
|
569
|
+
if (!this.didAddBackgroundWorkTracking) {
|
|
570
|
+
if (typeof this.batcher !== "undefined") {
|
|
571
|
+
const originalBatcherBatch = this.batcher.batch;
|
|
572
|
+
this.batcher.batch = async (key, fn) => {
|
|
573
|
+
const trackedFn = async (...workFnArgs) => {
|
|
574
|
+
const workPromise = fn(...workFnArgs);
|
|
575
|
+
const requestContext = (0, import_request_context.getRequestContext)();
|
|
576
|
+
if (requestContext && workPromise instanceof Promise) {
|
|
577
|
+
requestContext.trackBackgroundWork(workPromise);
|
|
578
|
+
}
|
|
579
|
+
return await workPromise;
|
|
580
|
+
};
|
|
581
|
+
return originalBatcherBatch.call(this.batcher, key, trackedFn);
|
|
779
582
|
};
|
|
780
|
-
}
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
583
|
+
} else if (typeof this.pendingResponses !== "undefined") {
|
|
584
|
+
const backgroundWork = /* @__PURE__ */ new Map();
|
|
585
|
+
const originalPendingResponsesSet = this.pendingResponses.set;
|
|
586
|
+
this.pendingResponses.set = async (key, value) => {
|
|
587
|
+
const requestContext = (0, import_request_context.getRequestContext)();
|
|
588
|
+
if (requestContext && !this.pendingResponses.has(key)) {
|
|
589
|
+
const workPromise = new Promise((_resolve) => {
|
|
590
|
+
backgroundWork.set(key, _resolve);
|
|
591
|
+
});
|
|
592
|
+
requestContext.trackBackgroundWork(workPromise);
|
|
593
|
+
}
|
|
594
|
+
return originalPendingResponsesSet.call(this.pendingResponses, key, value);
|
|
790
595
|
};
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
url: url.toString()
|
|
596
|
+
const originalPendingResponsesDelete = this.pendingResponses.delete;
|
|
597
|
+
this.pendingResponses.delete = async (key) => {
|
|
598
|
+
const _resolve = backgroundWork.get(key);
|
|
599
|
+
if (_resolve) {
|
|
600
|
+
_resolve();
|
|
601
|
+
}
|
|
602
|
+
return originalPendingResponsesDelete.call(this.pendingResponses, key);
|
|
799
603
|
};
|
|
800
604
|
}
|
|
801
|
-
|
|
802
|
-
headers: { ...apiHeaders, accept: SIGNED_URL_ACCEPT_HEADER },
|
|
803
|
-
method
|
|
804
|
-
});
|
|
805
|
-
if (res.status !== 200) {
|
|
806
|
-
throw new Error(`Netlify Blobs has generated an internal error: ${res.status} response`);
|
|
807
|
-
}
|
|
808
|
-
const { url: signedURL } = await res.json();
|
|
809
|
-
const userHeaders = encodedMetadata ? { [METADATA_HEADER_INTERNAL]: encodedMetadata } : void 0;
|
|
810
|
-
return {
|
|
811
|
-
headers: userHeaders,
|
|
812
|
-
url: signedURL
|
|
813
|
-
};
|
|
814
|
-
}
|
|
815
|
-
async makeRequest({
|
|
816
|
-
body,
|
|
817
|
-
consistency,
|
|
818
|
-
headers: extraHeaders,
|
|
819
|
-
key,
|
|
820
|
-
metadata,
|
|
821
|
-
method,
|
|
822
|
-
parameters,
|
|
823
|
-
storeName
|
|
824
|
-
}) {
|
|
825
|
-
const { headers: baseHeaders = {}, url } = await this.getFinalRequest({
|
|
826
|
-
consistency,
|
|
827
|
-
key,
|
|
828
|
-
metadata,
|
|
829
|
-
method,
|
|
830
|
-
parameters,
|
|
831
|
-
storeName
|
|
832
|
-
});
|
|
833
|
-
const headers = {
|
|
834
|
-
...baseHeaders,
|
|
835
|
-
...extraHeaders
|
|
836
|
-
};
|
|
837
|
-
if (method === "put") {
|
|
838
|
-
headers["cache-control"] = "max-age=0, stale-while-revalidate=60";
|
|
839
|
-
}
|
|
840
|
-
const options = {
|
|
841
|
-
body,
|
|
842
|
-
headers,
|
|
843
|
-
method
|
|
844
|
-
};
|
|
845
|
-
if (body instanceof ReadableStream) {
|
|
846
|
-
options.duplex = "half";
|
|
847
|
-
}
|
|
848
|
-
return fetchAndRetry(this.fetch, url, options);
|
|
605
|
+
this.didAddBackgroundWorkTracking = true;
|
|
849
606
|
}
|
|
607
|
+
return originalGet.apply(this, getArgs);
|
|
850
608
|
};
|
|
851
|
-
var getClientOptions = (options, contextOverride) => {
|
|
852
|
-
const context = contextOverride ?? getEnvironmentContext();
|
|
853
|
-
const siteID = context.siteID ?? options.siteID;
|
|
854
|
-
const token = context.token ?? options.token;
|
|
855
|
-
if (!siteID || !token) {
|
|
856
|
-
throw new MissingBlobsEnvironmentError(["siteID", "token"]);
|
|
857
|
-
}
|
|
858
|
-
const clientOptions = {
|
|
859
|
-
apiURL: context.apiURL ?? options.apiURL,
|
|
860
|
-
consistency: options.consistency,
|
|
861
|
-
edgeURL: context.edgeURL ?? options.edgeURL,
|
|
862
|
-
fetch: options.fetch,
|
|
863
|
-
siteID,
|
|
864
|
-
token,
|
|
865
|
-
uncachedEdgeURL: context.uncachedEdgeURL ?? options.uncachedEdgeURL
|
|
866
|
-
};
|
|
867
|
-
return clientOptions;
|
|
868
|
-
};
|
|
869
|
-
|
|
870
|
-
// node_modules/@netlify/blobs/dist/main.js
|
|
871
|
-
var DEPLOY_STORE_PREFIX = "deploy:";
|
|
872
|
-
var LEGACY_STORE_INTERNAL_PREFIX = "netlify-internal/legacy-namespace/";
|
|
873
|
-
var SITE_STORE_PREFIX = "site:";
|
|
874
|
-
var Store = class _Store {
|
|
875
|
-
constructor(options) {
|
|
876
|
-
this.client = options.client;
|
|
877
|
-
if ("deployID" in options) {
|
|
878
|
-
_Store.validateDeployID(options.deployID);
|
|
879
|
-
this.name = DEPLOY_STORE_PREFIX + options.deployID;
|
|
880
|
-
} else if (options.name.startsWith(LEGACY_STORE_INTERNAL_PREFIX)) {
|
|
881
|
-
const storeName = options.name.slice(LEGACY_STORE_INTERNAL_PREFIX.length);
|
|
882
|
-
_Store.validateStoreName(storeName);
|
|
883
|
-
this.name = storeName;
|
|
884
|
-
} else {
|
|
885
|
-
_Store.validateStoreName(options.name);
|
|
886
|
-
this.name = SITE_STORE_PREFIX + options.name;
|
|
887
|
-
}
|
|
888
|
-
}
|
|
889
|
-
async delete(key) {
|
|
890
|
-
const res = await this.client.makeRequest({ key, method: "delete", storeName: this.name });
|
|
891
|
-
if (![200, 204, 404].includes(res.status)) {
|
|
892
|
-
throw new BlobsInternalError(res.status);
|
|
893
|
-
}
|
|
894
|
-
}
|
|
895
|
-
async get(key, options) {
|
|
896
|
-
const { consistency, type } = options ?? {};
|
|
897
|
-
const res = await this.client.makeRequest({ consistency, key, method: "get", storeName: this.name });
|
|
898
|
-
if (res.status === 404) {
|
|
899
|
-
return null;
|
|
900
|
-
}
|
|
901
|
-
if (res.status !== 200) {
|
|
902
|
-
throw new BlobsInternalError(res.status);
|
|
903
|
-
}
|
|
904
|
-
if (type === void 0 || type === "text") {
|
|
905
|
-
return res.text();
|
|
906
|
-
}
|
|
907
|
-
if (type === "arrayBuffer") {
|
|
908
|
-
return res.arrayBuffer();
|
|
909
|
-
}
|
|
910
|
-
if (type === "blob") {
|
|
911
|
-
return res.blob();
|
|
912
|
-
}
|
|
913
|
-
if (type === "json") {
|
|
914
|
-
return res.json();
|
|
915
|
-
}
|
|
916
|
-
if (type === "stream") {
|
|
917
|
-
return res.body;
|
|
918
|
-
}
|
|
919
|
-
throw new BlobsInternalError(res.status);
|
|
920
|
-
}
|
|
921
|
-
async getMetadata(key, { consistency } = {}) {
|
|
922
|
-
const res = await this.client.makeRequest({ consistency, key, method: "head", storeName: this.name });
|
|
923
|
-
if (res.status === 404) {
|
|
924
|
-
return null;
|
|
925
|
-
}
|
|
926
|
-
if (res.status !== 200 && res.status !== 304) {
|
|
927
|
-
throw new BlobsInternalError(res.status);
|
|
928
|
-
}
|
|
929
|
-
const etag = res?.headers.get("etag") ?? void 0;
|
|
930
|
-
const metadata = getMetadataFromResponse(res);
|
|
931
|
-
const result = {
|
|
932
|
-
etag,
|
|
933
|
-
metadata
|
|
934
|
-
};
|
|
935
|
-
return result;
|
|
936
|
-
}
|
|
937
|
-
async getWithMetadata(key, options) {
|
|
938
|
-
const { consistency, etag: requestETag, type } = options ?? {};
|
|
939
|
-
const headers = requestETag ? { "if-none-match": requestETag } : void 0;
|
|
940
|
-
const res = await this.client.makeRequest({
|
|
941
|
-
consistency,
|
|
942
|
-
headers,
|
|
943
|
-
key,
|
|
944
|
-
method: "get",
|
|
945
|
-
storeName: this.name
|
|
946
|
-
});
|
|
947
|
-
if (res.status === 404) {
|
|
948
|
-
return null;
|
|
949
|
-
}
|
|
950
|
-
if (res.status !== 200 && res.status !== 304) {
|
|
951
|
-
throw new BlobsInternalError(res.status);
|
|
952
|
-
}
|
|
953
|
-
const responseETag = res?.headers.get("etag") ?? void 0;
|
|
954
|
-
const metadata = getMetadataFromResponse(res);
|
|
955
|
-
const result = {
|
|
956
|
-
etag: responseETag,
|
|
957
|
-
metadata
|
|
958
|
-
};
|
|
959
|
-
if (res.status === 304 && requestETag) {
|
|
960
|
-
return { data: null, ...result };
|
|
961
|
-
}
|
|
962
|
-
if (type === void 0 || type === "text") {
|
|
963
|
-
return { data: await res.text(), ...result };
|
|
964
|
-
}
|
|
965
|
-
if (type === "arrayBuffer") {
|
|
966
|
-
return { data: await res.arrayBuffer(), ...result };
|
|
967
|
-
}
|
|
968
|
-
if (type === "blob") {
|
|
969
|
-
return { data: await res.blob(), ...result };
|
|
970
|
-
}
|
|
971
|
-
if (type === "json") {
|
|
972
|
-
return { data: await res.json(), ...result };
|
|
973
|
-
}
|
|
974
|
-
if (type === "stream") {
|
|
975
|
-
return { data: res.body, ...result };
|
|
976
|
-
}
|
|
977
|
-
throw new Error(`Invalid 'type' property: ${type}. Expected: arrayBuffer, blob, json, stream, or text.`);
|
|
978
|
-
}
|
|
979
|
-
list(options = {}) {
|
|
980
|
-
const iterator = this.getListIterator(options);
|
|
981
|
-
if (options.paginate) {
|
|
982
|
-
return iterator;
|
|
983
|
-
}
|
|
984
|
-
return collectIterator(iterator).then(
|
|
985
|
-
(items) => items.reduce(
|
|
986
|
-
(acc, item) => ({
|
|
987
|
-
blobs: [...acc.blobs, ...item.blobs],
|
|
988
|
-
directories: [...acc.directories, ...item.directories]
|
|
989
|
-
}),
|
|
990
|
-
{ blobs: [], directories: [] }
|
|
991
|
-
)
|
|
992
|
-
);
|
|
993
|
-
}
|
|
994
|
-
async set(key, data, { metadata } = {}) {
|
|
995
|
-
_Store.validateKey(key);
|
|
996
|
-
const res = await this.client.makeRequest({
|
|
997
|
-
body: data,
|
|
998
|
-
key,
|
|
999
|
-
metadata,
|
|
1000
|
-
method: "put",
|
|
1001
|
-
storeName: this.name
|
|
1002
|
-
});
|
|
1003
|
-
if (res.status !== 200) {
|
|
1004
|
-
throw new BlobsInternalError(res.status);
|
|
1005
|
-
}
|
|
1006
|
-
}
|
|
1007
|
-
async setJSON(key, data, { metadata } = {}) {
|
|
1008
|
-
_Store.validateKey(key);
|
|
1009
|
-
const payload = JSON.stringify(data);
|
|
1010
|
-
const headers = {
|
|
1011
|
-
"content-type": "application/json"
|
|
1012
|
-
};
|
|
1013
|
-
const res = await this.client.makeRequest({
|
|
1014
|
-
body: payload,
|
|
1015
|
-
headers,
|
|
1016
|
-
key,
|
|
1017
|
-
metadata,
|
|
1018
|
-
method: "put",
|
|
1019
|
-
storeName: this.name
|
|
1020
|
-
});
|
|
1021
|
-
if (res.status !== 200) {
|
|
1022
|
-
throw new BlobsInternalError(res.status);
|
|
1023
|
-
}
|
|
1024
|
-
}
|
|
1025
|
-
static formatListResultBlob(result) {
|
|
1026
|
-
if (!result.key) {
|
|
1027
|
-
return null;
|
|
1028
|
-
}
|
|
1029
|
-
return {
|
|
1030
|
-
etag: result.etag,
|
|
1031
|
-
key: result.key
|
|
1032
|
-
};
|
|
1033
|
-
}
|
|
1034
|
-
static validateKey(key) {
|
|
1035
|
-
if (key === "") {
|
|
1036
|
-
throw new Error("Blob key must not be empty.");
|
|
1037
|
-
}
|
|
1038
|
-
if (key.startsWith("/") || key.startsWith("%2F")) {
|
|
1039
|
-
throw new Error("Blob key must not start with forward slash (/).");
|
|
1040
|
-
}
|
|
1041
|
-
if (new TextEncoder().encode(key).length > 600) {
|
|
1042
|
-
throw new Error(
|
|
1043
|
-
"Blob key must be a sequence of Unicode characters whose UTF-8 encoding is at most 600 bytes long."
|
|
1044
|
-
);
|
|
1045
|
-
}
|
|
1046
|
-
}
|
|
1047
|
-
static validateDeployID(deployID) {
|
|
1048
|
-
if (!/^\w{1,24}$/.test(deployID)) {
|
|
1049
|
-
throw new Error(`'${deployID}' is not a valid Netlify deploy ID.`);
|
|
1050
|
-
}
|
|
1051
|
-
}
|
|
1052
|
-
static validateStoreName(name) {
|
|
1053
|
-
if (name.includes("/") || name.includes("%2F")) {
|
|
1054
|
-
throw new Error("Store name must not contain forward slashes (/).");
|
|
1055
|
-
}
|
|
1056
|
-
if (new TextEncoder().encode(name).length > 64) {
|
|
1057
|
-
throw new Error(
|
|
1058
|
-
"Store name must be a sequence of Unicode characters whose UTF-8 encoding is at most 64 bytes long."
|
|
1059
|
-
);
|
|
1060
|
-
}
|
|
1061
|
-
}
|
|
1062
|
-
getListIterator(options) {
|
|
1063
|
-
const { client, name: storeName } = this;
|
|
1064
|
-
const parameters = {};
|
|
1065
|
-
if (options?.prefix) {
|
|
1066
|
-
parameters.prefix = options.prefix;
|
|
1067
|
-
}
|
|
1068
|
-
if (options?.directories) {
|
|
1069
|
-
parameters.directories = "true";
|
|
1070
|
-
}
|
|
1071
|
-
return {
|
|
1072
|
-
[Symbol.asyncIterator]() {
|
|
1073
|
-
let currentCursor = null;
|
|
1074
|
-
let done = false;
|
|
1075
|
-
return {
|
|
1076
|
-
async next() {
|
|
1077
|
-
if (done) {
|
|
1078
|
-
return { done: true, value: void 0 };
|
|
1079
|
-
}
|
|
1080
|
-
const nextParameters = { ...parameters };
|
|
1081
|
-
if (currentCursor !== null) {
|
|
1082
|
-
nextParameters.cursor = currentCursor;
|
|
1083
|
-
}
|
|
1084
|
-
const res = await client.makeRequest({
|
|
1085
|
-
method: "get",
|
|
1086
|
-
parameters: nextParameters,
|
|
1087
|
-
storeName
|
|
1088
|
-
});
|
|
1089
|
-
const page = await res.json();
|
|
1090
|
-
if (page.next_cursor) {
|
|
1091
|
-
currentCursor = page.next_cursor;
|
|
1092
|
-
} else {
|
|
1093
|
-
done = true;
|
|
1094
|
-
}
|
|
1095
|
-
const blobs = (page.blobs ?? []).map(_Store.formatListResultBlob).filter(Boolean);
|
|
1096
|
-
return {
|
|
1097
|
-
done: false,
|
|
1098
|
-
value: {
|
|
1099
|
-
blobs,
|
|
1100
|
-
directories: page.directories ?? []
|
|
1101
|
-
}
|
|
1102
|
-
};
|
|
1103
|
-
}
|
|
1104
|
-
};
|
|
1105
|
-
}
|
|
1106
|
-
};
|
|
1107
|
-
}
|
|
1108
|
-
};
|
|
1109
|
-
var getDeployStore = (options = {}) => {
|
|
1110
|
-
const context = getEnvironmentContext();
|
|
1111
|
-
const deployID = options.deployID ?? context.deployID;
|
|
1112
|
-
if (!deployID) {
|
|
1113
|
-
throw new MissingBlobsEnvironmentError(["deployID"]);
|
|
1114
|
-
}
|
|
1115
|
-
const clientOptions = getClientOptions(options, context);
|
|
1116
|
-
const client = new Client(clientOptions);
|
|
1117
|
-
return new Store({ client, deployID });
|
|
1118
|
-
};
|
|
1119
|
-
|
|
1120
|
-
// src/run/next.cts
|
|
1121
|
-
var import_fs_monkey = __toESM(require_lib());
|
|
1122
|
-
var import_request_context = require("./handlers/request-context.cjs");
|
|
1123
|
-
var import_tracer = require("./handlers/tracer.cjs");
|
|
1124
|
-
console.time("import next server");
|
|
1125
|
-
var { getRequestHandlers } = require("next/dist/server/lib/start-server.js");
|
|
1126
609
|
console.timeEnd("import next server");
|
|
1127
|
-
var fetchBeforeNextPatchedIt = globalThis.fetch;
|
|
1128
610
|
async function getMockedRequestHandlers(...args) {
|
|
1129
611
|
const tracer = (0, import_tracer.getTracer)();
|
|
1130
612
|
return tracer.withActiveSpan("mocked request handler", async () => {
|
|
1131
613
|
const ofs = { ...import_promises.default };
|
|
1132
|
-
const { encodeBlobKey
|
|
614
|
+
const { encodeBlobKey } = await import("../shared/blobkey.js");
|
|
1133
615
|
async function readFileFallbackBlobStore(...fsargs) {
|
|
1134
616
|
const [path, options] = fsargs;
|
|
1135
617
|
try {
|
|
1136
618
|
return await ofs.readFile(path, options);
|
|
1137
619
|
} catch (error) {
|
|
1138
620
|
if (typeof path === "string" && path.endsWith(".html")) {
|
|
1139
|
-
const store =
|
|
621
|
+
const store = (0, import_regional_blob_store.getRegionalBlobStore)();
|
|
1140
622
|
const relPath = (0, import_path.relative)((0, import_path.resolve)(".next/server/pages"), path);
|
|
1141
|
-
const file = await store.get(await
|
|
623
|
+
const file = await store.get(await encodeBlobKey(relPath));
|
|
1142
624
|
if (file !== null) {
|
|
1143
625
|
const requestContext = (0, import_request_context.getRequestContext)();
|
|
1144
626
|
if (requestContext) {
|