@netlify/plugin-nextjs 5.0.0-beta.6 → 5.0.0-beta.8

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 (40) hide show
  1. package/dist/build/cache.js +1 -1
  2. package/dist/build/content/prerendered.js +3 -3
  3. package/dist/build/content/server.js +3 -3
  4. package/dist/build/content/static.js +3 -3
  5. package/dist/build/functions/edge.js +3 -3
  6. package/dist/build/functions/server.js +4 -4
  7. package/dist/build/image-cdn.js +1 -1
  8. package/dist/build/plugin-context.js +1 -1
  9. package/dist/build/templates/handler-monorepo.tmpl.js +46 -0
  10. package/dist/build/templates/handler.tmpl.js +37 -0
  11. package/dist/esm-chunks/{chunk-WELZ7LFO.js → chunk-5JVNISGM.js} +12 -1
  12. package/dist/esm-chunks/{chunk-PCJY2SS7.js → chunk-ETPYUOBQ.js} +4 -4
  13. package/dist/esm-chunks/{chunk-X7XIMV6B.js → chunk-HYBEXB2Z.js} +1 -1
  14. package/dist/esm-chunks/{chunk-W5TLWQMF.js → chunk-N23TUUXK.js} +69 -17
  15. package/dist/esm-chunks/chunk-VDDK7MXY.js +1661 -0
  16. package/dist/esm-chunks/{chunk-MFN4GH7U.js → chunk-VZNKO4OO.js} +1 -1
  17. package/dist/esm-chunks/{chunk-KDRFBPAR.js → chunk-WSPFUAK4.js} +17 -29
  18. package/dist/esm-chunks/{chunk-NE4HYI2D.js → chunk-WT2HN3M6.js} +1 -1
  19. package/dist/esm-chunks/{chunk-UDWVXRI2.js → chunk-XFDUV7DP.js} +3 -3
  20. package/dist/esm-chunks/{chunk-COJ526HO.js → chunk-YMFYCTRI.js} +4 -4
  21. package/dist/esm-chunks/{chunk-AMJYZZKR.js → chunk-ZWFKLYLH.js} +6 -3
  22. package/dist/esm-chunks/package-2CI3IXK3.js +131 -0
  23. package/dist/index.js +12 -12
  24. package/dist/run/config.js +1 -1
  25. package/dist/run/constants.js +1 -1
  26. package/dist/run/handlers/cache.cjs +1765 -79
  27. package/dist/run/handlers/server.js +60 -38
  28. package/dist/run/handlers/tracing.js +52883 -0
  29. package/dist/run/headers.js +2 -2
  30. package/dist/run/next.cjs +1722 -34
  31. package/dist/run/revalidate.js +2 -2
  32. package/dist/run/systemlog.js +2 -2
  33. package/dist/shared/blobkey.js +1 -1
  34. package/edge-runtime/lib/headers.ts +18 -4
  35. package/edge-runtime/lib/next-request.ts +6 -1
  36. package/edge-runtime/lib/response.ts +56 -13
  37. package/edge-runtime/lib/util.ts +13 -3
  38. package/edge-runtime/middleware.ts +1 -0
  39. package/edge-runtime/shim/index.js +27 -0
  40. package/package.json +1 -1
@@ -8,7 +8,7 @@ import {
8
8
  restoreBuildCache,
9
9
  saveBuildCache
10
10
  } from "../esm-chunks/chunk-XA2CZH5Y.js";
11
- import "../esm-chunks/chunk-WELZ7LFO.js";
11
+ import "../esm-chunks/chunk-5JVNISGM.js";
12
12
  export {
13
13
  restoreBuildCache,
14
14
  saveBuildCache
@@ -7,9 +7,9 @@
7
7
  import {
8
8
  copyFetchContent,
9
9
  copyPrerenderedContent
10
- } from "../../esm-chunks/chunk-UDWVXRI2.js";
11
- import "../../esm-chunks/chunk-MFN4GH7U.js";
12
- import "../../esm-chunks/chunk-WELZ7LFO.js";
10
+ } from "../../esm-chunks/chunk-XFDUV7DP.js";
11
+ import "../../esm-chunks/chunk-VZNKO4OO.js";
12
+ import "../../esm-chunks/chunk-5JVNISGM.js";
13
13
  export {
14
14
  copyFetchContent,
15
15
  copyPrerenderedContent
@@ -8,9 +8,9 @@ import {
8
8
  copyNextDependencies,
9
9
  copyNextServerCode,
10
10
  writeTagsManifest
11
- } from "../../esm-chunks/chunk-COJ526HO.js";
12
- import "../../esm-chunks/chunk-MFN4GH7U.js";
13
- import "../../esm-chunks/chunk-WELZ7LFO.js";
11
+ } from "../../esm-chunks/chunk-YMFYCTRI.js";
12
+ import "../../esm-chunks/chunk-VZNKO4OO.js";
13
+ import "../../esm-chunks/chunk-5JVNISGM.js";
14
14
  export {
15
15
  copyNextDependencies,
16
16
  copyNextServerCode,
@@ -9,10 +9,10 @@ import {
9
9
  copyStaticContent,
10
10
  publishStaticDir,
11
11
  unpublishStaticDir
12
- } from "../../esm-chunks/chunk-AMJYZZKR.js";
13
- import "../../esm-chunks/chunk-MFN4GH7U.js";
12
+ } from "../../esm-chunks/chunk-ZWFKLYLH.js";
13
+ import "../../esm-chunks/chunk-VZNKO4OO.js";
14
14
  import "../../esm-chunks/chunk-TYCYFZ22.js";
15
- import "../../esm-chunks/chunk-WELZ7LFO.js";
15
+ import "../../esm-chunks/chunk-5JVNISGM.js";
16
16
  export {
17
17
  copyStaticAssets,
18
18
  copyStaticContent,
@@ -6,11 +6,11 @@
6
6
 
7
7
  import {
8
8
  createEdgeHandlers
9
- } from "../../esm-chunks/chunk-PCJY2SS7.js";
10
- import "../../esm-chunks/chunk-MFN4GH7U.js";
9
+ } from "../../esm-chunks/chunk-ETPYUOBQ.js";
11
10
  import "../../esm-chunks/chunk-IZ2AVCVF.js";
11
+ import "../../esm-chunks/chunk-VZNKO4OO.js";
12
12
  import "../../esm-chunks/chunk-TYCYFZ22.js";
13
- import "../../esm-chunks/chunk-WELZ7LFO.js";
13
+ import "../../esm-chunks/chunk-5JVNISGM.js";
14
14
  export {
15
15
  createEdgeHandlers
16
16
  };
@@ -6,12 +6,12 @@
6
6
 
7
7
  import {
8
8
  createServerHandler
9
- } from "../../esm-chunks/chunk-KDRFBPAR.js";
10
- import "../../esm-chunks/chunk-COJ526HO.js";
11
- import "../../esm-chunks/chunk-MFN4GH7U.js";
9
+ } from "../../esm-chunks/chunk-WSPFUAK4.js";
10
+ import "../../esm-chunks/chunk-YMFYCTRI.js";
12
11
  import "../../esm-chunks/chunk-IZ2AVCVF.js";
12
+ import "../../esm-chunks/chunk-VZNKO4OO.js";
13
13
  import "../../esm-chunks/chunk-TYCYFZ22.js";
14
- import "../../esm-chunks/chunk-WELZ7LFO.js";
14
+ import "../../esm-chunks/chunk-5JVNISGM.js";
15
15
  export {
16
16
  createServerHandler
17
17
  };
@@ -7,7 +7,7 @@
7
7
  import {
8
8
  setImageConfig
9
9
  } from "../esm-chunks/chunk-EPSI5TTB.js";
10
- import "../esm-chunks/chunk-WELZ7LFO.js";
10
+ import "../esm-chunks/chunk-5JVNISGM.js";
11
11
  export {
12
12
  setImageConfig
13
13
  };
@@ -10,7 +10,7 @@ import {
10
10
  SERVER_HANDLER_NAME
11
11
  } from "../esm-chunks/chunk-IZ2AVCVF.js";
12
12
  import "../esm-chunks/chunk-TYCYFZ22.js";
13
- import "../esm-chunks/chunk-WELZ7LFO.js";
13
+ import "../esm-chunks/chunk-5JVNISGM.js";
14
14
  export {
15
15
  EDGE_HANDLER_NAME,
16
16
  PluginContext,
@@ -0,0 +1,46 @@
1
+ import tracing, { trace } from '{{cwd}}/dist/run/handlers/tracing.js'
2
+
3
+ process.chdir('{{cwd}}')
4
+
5
+ let cachedHandler
6
+ export default async function (req, context) {
7
+ if (process.env.NETLIFY_OTLP_TRACE_EXPORTER_URL) {
8
+ tracing.start()
9
+ }
10
+
11
+ return trace
12
+ .getTracer('Next.js Runtime')
13
+ .startActiveSpan('Next.js Server Handler', async (span) => {
14
+ try {
15
+ span.setAttributes({
16
+ 'account.id': context.account.id,
17
+ 'deploy.id': context.deploy.id,
18
+ 'request.id': context.requestId,
19
+ 'site.id': context.site.id,
20
+ 'http.method': req.method,
21
+ 'http.target': req.url,
22
+ monorepo: true,
23
+ cwd: '{{cwd}}',
24
+ })
25
+ if (!cachedHandler) {
26
+ const { default: handler } = await import('./{{nextServerHandler}}')
27
+ cachedHandler = handler
28
+ }
29
+ const response = await cachedHandler(req, context)
30
+ span.setAttributes({
31
+ 'http.status_code': response.status,
32
+ })
33
+ return response
34
+ } catch (error) {
35
+ span.recordException(error)
36
+ throw error
37
+ } finally {
38
+ span.end()
39
+ }
40
+ })
41
+ }
42
+
43
+ export const config = {
44
+ path: '/*',
45
+ preferStatic: true,
46
+ }
@@ -0,0 +1,37 @@
1
+ import serverHandler from './dist/run/handlers/server.js'
2
+ import tracing, { trace } from './dist/run/handlers/tracing.js'
3
+
4
+ export default async function handler(req, context) {
5
+ if (process.env.NETLIFY_OTLP_TRACE_EXPORTER_URL) {
6
+ tracing.start()
7
+ }
8
+ return trace
9
+ .getTracer('Next.js Runtime')
10
+ .startActiveSpan('Next.js Server Handler', async (span) => {
11
+ try {
12
+ span.setAttributes({
13
+ 'account.id': context.account.id,
14
+ 'deploy.id': context.deploy.id,
15
+ 'request.id': context.requestId,
16
+ 'site.id': context.site.id,
17
+ 'http.method': req.method,
18
+ 'http.target': req.url,
19
+ })
20
+ const response = await serverHandler(req, context)
21
+ span.setAttributes({
22
+ 'http.status_code': response.status,
23
+ })
24
+ return response
25
+ } catch (error) {
26
+ span.recordException(error)
27
+ throw error
28
+ } finally {
29
+ span.end()
30
+ }
31
+ })
32
+ }
33
+
34
+ export const config = {
35
+ path: '/*',
36
+ preferStatic: true,
37
+ }
@@ -17,9 +17,16 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
17
17
  return require.apply(this, arguments);
18
18
  throw Error('Dynamic require of "' + x + '" is not supported');
19
19
  });
20
+ var __esm = (fn, res) => function __init() {
21
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
22
+ };
20
23
  var __commonJS = (cb, mod) => function __require2() {
21
24
  return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
22
25
  };
26
+ var __export = (target, all) => {
27
+ for (var name in all)
28
+ __defProp(target, name, { get: all[name], enumerable: true });
29
+ };
23
30
  var __copyProps = (to, from, except, desc) => {
24
31
  if (from && typeof from === "object" || typeof from === "function") {
25
32
  for (let key of __getOwnPropNames(from))
@@ -36,9 +43,13 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
36
43
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
37
44
  mod
38
45
  ));
46
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
39
47
 
40
48
  export {
41
49
  __require,
50
+ __esm,
42
51
  __commonJS,
43
- __toESM
52
+ __export,
53
+ __toESM,
54
+ __toCommonJS
44
55
  };
@@ -4,15 +4,15 @@
4
4
  return createRequire(import.meta.url);
5
5
  })();
6
6
 
7
- import {
8
- require_out
9
- } from "./chunk-MFN4GH7U.js";
10
7
  import {
11
8
  EDGE_HANDLER_NAME
12
9
  } from "./chunk-IZ2AVCVF.js";
10
+ import {
11
+ require_out
12
+ } from "./chunk-VZNKO4OO.js";
13
13
  import {
14
14
  __toESM
15
- } from "./chunk-WELZ7LFO.js";
15
+ } from "./chunk-5JVNISGM.js";
16
16
 
17
17
  // src/build/functions/edge.ts
18
18
  var import_fast_glob = __toESM(require_out(), 1);
@@ -8,7 +8,7 @@ import {
8
8
  __commonJS,
9
9
  __require,
10
10
  __toESM
11
- } from "./chunk-WELZ7LFO.js";
11
+ } from "./chunk-5JVNISGM.js";
12
12
 
13
13
  // node_modules/@netlify/functions/dist/lib/system_logger.js
14
14
  var require_system_logger = __commonJS({
@@ -15,6 +15,14 @@ import { Buffer as Buffer2 } from "buffer";
15
15
  import { Buffer as Buffer3 } from "buffer";
16
16
  import stream from "stream";
17
17
  import { promisify } from "util";
18
+ var BlobsConsistencyError = class extends Error {
19
+ constructor() {
20
+ super(
21
+ `Netlify Blobs has failed to perform a read using strong consistency because the environment has not been configured with a 'uncachedEdgeURL' property`
22
+ );
23
+ this.name = "BlobsConsistencyError";
24
+ }
25
+ };
18
26
  var getEnvironmentContext = () => {
19
27
  const context = globalThis.netlifyBlobsContext || env.NETLIFY_BLOBS_CONTEXT;
20
28
  if (typeof context !== "string" || !context) {
@@ -106,21 +114,34 @@ var sleep = (ms) => new Promise((resolve2) => {
106
114
  setTimeout(resolve2, ms);
107
115
  });
108
116
  var Client = class {
109
- constructor({ apiURL, edgeURL, fetch, siteID, token }) {
117
+ constructor({ apiURL, consistency, edgeURL, fetch, siteID, token, uncachedEdgeURL }) {
110
118
  this.apiURL = apiURL;
119
+ this.consistency = consistency ?? "eventual";
111
120
  this.edgeURL = edgeURL;
112
121
  this.fetch = fetch ?? globalThis.fetch;
113
122
  this.siteID = siteID;
114
123
  this.token = token;
124
+ this.uncachedEdgeURL = uncachedEdgeURL;
115
125
  if (!this.fetch) {
116
126
  throw new Error(
117
127
  "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."
118
128
  );
119
129
  }
120
130
  }
121
- async getFinalRequest({ key, metadata, method, parameters = {}, storeName }) {
131
+ async getFinalRequest({
132
+ consistency: opConsistency,
133
+ key,
134
+ metadata,
135
+ method,
136
+ parameters = {},
137
+ storeName
138
+ }) {
122
139
  const encodedMetadata = encodeMetadata(metadata);
140
+ const consistency = opConsistency ?? this.consistency;
123
141
  if (this.edgeURL) {
142
+ if (consistency === "strong" && !this.uncachedEdgeURL) {
143
+ throw new BlobsConsistencyError();
144
+ }
124
145
  const headers = {
125
146
  authorization: `Bearer ${this.token}`
126
147
  };
@@ -128,7 +149,7 @@ var Client = class {
128
149
  headers[METADATA_HEADER_INTERNAL] = encodedMetadata;
129
150
  }
130
151
  const path = key ? `/${this.siteID}/${storeName}/${key}` : `/${this.siteID}/${storeName}`;
131
- const url2 = new URL(path, this.edgeURL);
152
+ const url2 = new URL(path, consistency === "strong" ? this.uncachedEdgeURL : this.edgeURL);
132
153
  for (const key2 in parameters) {
133
154
  url2.searchParams.set(key2, parameters[key2]);
134
155
  }
@@ -172,6 +193,7 @@ var Client = class {
172
193
  }
173
194
  async makeRequest({
174
195
  body,
196
+ consistency,
175
197
  headers: extraHeaders,
176
198
  key,
177
199
  metadata,
@@ -180,6 +202,7 @@ var Client = class {
180
202
  storeName
181
203
  }) {
182
204
  const { headers: baseHeaders = {}, url } = await this.getFinalRequest({
205
+ consistency,
183
206
  key,
184
207
  metadata,
185
208
  method,
@@ -213,10 +236,12 @@ var getClientOptions = (options, contextOverride) => {
213
236
  }
214
237
  const clientOptions = {
215
238
  apiURL: context.apiURL ?? options.apiURL,
239
+ consistency: options.consistency,
216
240
  edgeURL: context.edgeURL ?? options.edgeURL,
217
241
  fetch: options.fetch,
218
242
  siteID,
219
- token
243
+ token,
244
+ uncachedEdgeURL: context.uncachedEdgeURL ?? options.uncachedEdgeURL
220
245
  };
221
246
  return clientOptions;
222
247
  };
@@ -236,6 +261,7 @@ var collectIterator = async (iterator) => {
236
261
  var Store = class _Store {
237
262
  constructor(options) {
238
263
  this.client = options.client;
264
+ this.consistency = options.consistency ?? "eventual";
239
265
  if ("deployID" in options) {
240
266
  _Store.validateDeployID(options.deployID);
241
267
  this.name = `deploy:${options.deployID}`;
@@ -251,8 +277,8 @@ var Store = class _Store {
251
277
  }
252
278
  }
253
279
  async get(key, options) {
254
- const { type } = options ?? {};
255
- const res = await this.client.makeRequest({ key, method: "get", storeName: this.name });
280
+ const { consistency, type } = options ?? {};
281
+ const res = await this.client.makeRequest({ consistency, key, method: "get", storeName: this.name });
256
282
  if (res.status === 404) {
257
283
  return null;
258
284
  }
@@ -276,8 +302,8 @@ var Store = class _Store {
276
302
  }
277
303
  throw new BlobsInternalError(res.status);
278
304
  }
279
- async getMetadata(key) {
280
- const res = await this.client.makeRequest({ key, method: "head", storeName: this.name });
305
+ async getMetadata(key, { consistency } = {}) {
306
+ const res = await this.client.makeRequest({ consistency, key, method: "head", storeName: this.name });
281
307
  if (res.status === 404) {
282
308
  return null;
283
309
  }
@@ -293,9 +319,15 @@ var Store = class _Store {
293
319
  return result;
294
320
  }
295
321
  async getWithMetadata(key, options) {
296
- const { etag: requestETag, type } = options ?? {};
322
+ const { consistency, etag: requestETag, type } = options ?? {};
297
323
  const headers = requestETag ? { "if-none-match": requestETag } : void 0;
298
- const res = await this.client.makeRequest({ headers, key, method: "get", storeName: this.name });
324
+ const res = await this.client.makeRequest({
325
+ consistency,
326
+ headers,
327
+ key,
328
+ method: "get",
329
+ storeName: this.name
330
+ });
299
331
  if (res.status === 404) {
300
332
  return null;
301
333
  }
@@ -520,14 +552,33 @@ var setVaryHeaders = (headers, request, { basePath, i18n }) => {
520
552
  }
521
553
  headers.set(`netlify-vary`, generateNetlifyVaryValues(netlifyVaryValues));
522
554
  };
523
- var adjustDateHeader = async (headers, request) => {
524
- if (headers.get("x-nextjs-cache") !== "HIT") {
555
+ var fetchBeforeNextPatchedIt = globalThis.fetch;
556
+ var adjustDateHeader = async (headers, request, span, tracer) => {
557
+ const cacheState = headers.get("x-nextjs-cache");
558
+ const isServedFromCache = cacheState === "HIT" || cacheState === "STALE";
559
+ span.setAttributes({
560
+ "x-nextjs-cache": cacheState ?? void 0,
561
+ isServedFromCache
562
+ });
563
+ if (!isServedFromCache) {
525
564
  return;
526
565
  }
527
- const path = new URL(request.url).pathname;
528
- const key = await encodeBlobKey(path);
529
- const blobStore = getDeployStore();
530
- const { lastModified } = await blobStore.get(key, { type: "json" }) ?? {};
566
+ const key = new URL(request.url).pathname;
567
+ const blobKey = await encodeBlobKey(key);
568
+ const blobStore = getDeployStore({ fetch: fetchBeforeNextPatchedIt });
569
+ const { lastModified } = await tracer.startActiveSpan(
570
+ "get cache to calculate date header",
571
+ async (getBlobForDateSpan) => {
572
+ getBlobForDateSpan.setAttributes({
573
+ key,
574
+ blobKey
575
+ });
576
+ const blob = await blobStore.get(blobKey, { type: "json" }) ?? {};
577
+ getBlobForDateSpan.addEvent(blob ? "Cache hit" : "Cache miss");
578
+ getBlobForDateSpan.end();
579
+ return blob;
580
+ }
581
+ );
531
582
  if (!lastModified) {
532
583
  return;
533
584
  }
@@ -557,7 +608,8 @@ var setCacheTagsHeaders = (headers, request, manifest) => {
557
608
  };
558
609
  var NEXT_CACHE_TO_CACHE_STATUS = {
559
610
  HIT: `hit`,
560
- MISS: `miss,`
611
+ MISS: `fwd=miss`,
612
+ STALE: `hit; fwd=stale`
561
613
  };
562
614
  var handleNextCacheHeader = (headers) => {
563
615
  const nextCache = headers.get("x-nextjs-cache");