@netlify/plugin-nextjs 5.2.1 → 5.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/dist/build/advanced-api-routes.js +1 -1
  2. package/dist/build/cache.js +1 -1
  3. package/dist/build/content/prerendered.js +4 -4
  4. package/dist/build/content/server.js +10 -9
  5. package/dist/build/content/static.js +4 -4
  6. package/dist/build/functions/edge.js +2 -2
  7. package/dist/build/functions/server.js +4 -4
  8. package/dist/build/image-cdn.js +17 -33
  9. package/dist/build/plugin-context.js +17 -5
  10. package/dist/build/templates/handler-monorepo.tmpl.js +1 -3
  11. package/dist/build/templates/handler.tmpl.js +1 -3
  12. package/dist/build/verification.js +2 -2
  13. package/dist/esm-chunks/{chunk-PDPDW32D.js → chunk-5QSXBV7L.js} +1 -1
  14. package/dist/esm-chunks/{chunk-PJG75HGC.js → chunk-EFGWM7RS.js} +38 -655
  15. package/dist/esm-chunks/{chunk-VZNKO4OO.js → chunk-FHR56UHE.js} +56 -111
  16. package/dist/esm-chunks/{chunk-Y3K5Q6FP.js → chunk-GNGHTHMQ.js} +51 -86
  17. package/dist/esm-chunks/{chunk-5JVNISGM.js → chunk-OEQOKJGE.js} +1 -2
  18. package/dist/esm-chunks/{package-SCUAWNXR.js → package-HC2KHZCZ.js} +10 -10
  19. package/dist/index.js +3 -3
  20. package/dist/run/config.js +1 -1
  21. package/dist/run/constants.js +1 -1
  22. package/dist/run/handlers/cache.cjs +74 -230
  23. package/dist/run/handlers/server.js +353 -501
  24. package/dist/run/handlers/tracer.cjs +36 -60
  25. package/dist/run/handlers/tracing.js +1192 -1592
  26. package/dist/run/headers.js +2 -2
  27. package/dist/run/next.cjs +42 -78
  28. package/dist/run/revalidate.js +1 -1
  29. package/dist/run/systemlog.cjs +98 -0
  30. package/dist/shared/blobkey.js +1 -1
  31. package/edge-runtime/lib/response.ts +6 -3
  32. package/package.json +1 -1
  33. package/dist/run/systemlog.js +0 -107
@@ -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 __commonJS = (cb, mod) => function __require() {
9
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
10
- };
11
8
  var __export = (target, all) => {
12
9
  for (var name in all)
13
10
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -30,232 +27,74 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
30
27
  ));
31
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
32
29
 
33
- // node_modules/is-promise/index.js
34
- var require_is_promise = __commonJS({
35
- "node_modules/is-promise/index.js"(exports2, module2) {
36
- module2.exports = isPromise;
37
- module2.exports.default = isPromise;
38
- function isPromise(obj) {
39
- return !!obj && (typeof obj === "object" || typeof obj === "function") && typeof obj.then === "function";
40
- }
41
- }
42
- });
43
-
44
- // node_modules/@netlify/functions/dist/lib/consts.js
45
- var require_consts = __commonJS({
46
- "node_modules/@netlify/functions/dist/lib/consts.js"(exports2) {
47
- "use strict";
48
- Object.defineProperty(exports2, "__esModule", { value: true });
49
- exports2.METADATA_VERSION = exports2.HTTP_STATUS_OK = exports2.HTTP_STATUS_METHOD_NOT_ALLOWED = exports2.BUILDER_FUNCTIONS_FLAG = void 0;
50
- var BUILDER_FUNCTIONS_FLAG = true;
51
- exports2.BUILDER_FUNCTIONS_FLAG = BUILDER_FUNCTIONS_FLAG;
52
- var HTTP_STATUS_METHOD_NOT_ALLOWED = 405;
53
- exports2.HTTP_STATUS_METHOD_NOT_ALLOWED = HTTP_STATUS_METHOD_NOT_ALLOWED;
54
- var HTTP_STATUS_OK = 200;
55
- exports2.HTTP_STATUS_OK = HTTP_STATUS_OK;
56
- var METADATA_VERSION = 1;
57
- exports2.METADATA_VERSION = METADATA_VERSION;
58
- }
30
+ // src/run/handlers/cache.cts
31
+ var cache_exports = {};
32
+ __export(cache_exports, {
33
+ NetlifyCacheHandler: () => NetlifyCacheHandler,
34
+ default: () => cache_default
59
35
  });
36
+ module.exports = __toCommonJS(cache_exports);
37
+ var import_node_buffer = require("node:buffer");
60
38
 
61
- // node_modules/@netlify/functions/dist/lib/builder.js
62
- var require_builder = __commonJS({
63
- "node_modules/@netlify/functions/dist/lib/builder.js"(exports2) {
64
- "use strict";
65
- var __importDefault = exports2 && exports2.__importDefault || function(mod) {
66
- return mod && mod.__esModule ? mod : { "default": mod };
67
- };
68
- Object.defineProperty(exports2, "__esModule", { value: true });
69
- exports2.builder = void 0;
70
- var is_promise_1 = __importDefault(require_is_promise());
71
- var consts_js_1 = require_consts();
72
- var augmentResponse = (response) => {
73
- if (!response) {
74
- return response;
75
- }
76
- const metadata = { version: consts_js_1.METADATA_VERSION, builder_function: consts_js_1.BUILDER_FUNCTIONS_FLAG, ttl: response.ttl || 0 };
77
- return {
78
- ...response,
79
- metadata
80
- };
81
- };
82
- var wrapHandler = (handler) => (
83
- // eslint-disable-next-line promise/prefer-await-to-callbacks
84
- (event, context, callback) => {
85
- if (event.httpMethod !== "GET" && event.httpMethod !== "HEAD") {
86
- return Promise.resolve({
87
- body: "Method Not Allowed",
88
- statusCode: consts_js_1.HTTP_STATUS_METHOD_NOT_ALLOWED
89
- });
90
- }
91
- const modifiedEvent = {
92
- ...event,
93
- multiValueQueryStringParameters: {},
94
- queryStringParameters: {}
95
- };
96
- const wrappedCallback = (error, response) => (
97
- // eslint-disable-next-line promise/prefer-await-to-callbacks
98
- callback ? callback(error, augmentResponse(response)) : null
99
- );
100
- const execution = handler(modifiedEvent, context, wrappedCallback);
101
- if ((0, is_promise_1.default)(execution)) {
102
- return execution.then(augmentResponse);
103
- }
104
- return execution;
105
- }
39
+ // node_modules/@netlify/functions/dist/chunk-COIAWFHF.mjs
40
+ var import_process = require("process");
41
+ var purgeCache = async (options = {}) => {
42
+ if (globalThis.fetch === void 0) {
43
+ throw new Error(
44
+ "`fetch` is not available. Please ensure you're using Node.js version 18.0.0 or above. Refer to https://ntl.fyi/functions-runtime for more information."
106
45
  );
107
- exports2.builder = wrapHandler;
108
46
  }
109
- });
110
-
111
- // node_modules/@netlify/functions/dist/lib/purge_cache.js
112
- var require_purge_cache = __commonJS({
113
- "node_modules/@netlify/functions/dist/lib/purge_cache.js"(exports2) {
114
- "use strict";
115
- Object.defineProperty(exports2, "__esModule", { value: true });
116
- exports2.purgeCache = void 0;
117
- var process_1 = require("process");
118
- var purgeCache2 = async (options = {}) => {
119
- if (globalThis.fetch === void 0) {
120
- throw new Error("`fetch` is not available. Please ensure you're using Node.js version 18.0.0 or above. Refer to https://ntl.fyi/functions-runtime for more information.");
121
- }
122
- const payload = {
123
- cache_tags: options.tags,
124
- deploy_alias: options.deployAlias
125
- };
126
- const token = process_1.env.NETLIFY_PURGE_API_TOKEN || options.token;
127
- if ("siteSlug" in options) {
128
- payload.site_slug = options.siteSlug;
129
- } else if ("domain" in options) {
130
- payload.domain = options.domain;
131
- } else {
132
- const siteID = options.siteID || process_1.env.SITE_ID;
133
- if (!siteID) {
134
- throw new Error("The Netlify site ID was not found in the execution environment. Please supply it manually using the `siteID` property.");
135
- }
136
- payload.site_id = siteID;
137
- }
138
- if (!token) {
139
- throw new Error("The cache purge API token was not found in the execution environment. Please supply it manually using the `token` property.");
140
- }
141
- const apiURL = options.apiURL || "https://api.netlify.com";
142
- const response = await fetch(`${apiURL}/api/v1/purge`, {
143
- method: "POST",
144
- headers: {
145
- "Content-Type": "application/json; charset=utf8",
146
- Authorization: `Bearer ${token}`
147
- },
148
- body: JSON.stringify(payload)
149
- });
150
- if (!response.ok) {
151
- throw new Error(`Cache purge API call returned an unexpected status code: ${response.status}`);
152
- }
153
- };
154
- exports2.purgeCache = purgeCache2;
47
+ const payload = {
48
+ cache_tags: options.tags,
49
+ deploy_alias: options.deployAlias
50
+ };
51
+ const token = import_process.env.NETLIFY_PURGE_API_TOKEN || options.token;
52
+ if (import_process.env.NETLIFY_LOCAL && !token) {
53
+ const scope = options.tags?.length ? ` for tags ${options.tags?.join(", ")}` : "";
54
+ console.log(`Skipping purgeCache${scope} in local development.`);
55
+ return;
155
56
  }
156
- });
157
-
158
- // node_modules/@netlify/functions/dist/lib/schedule.js
159
- var require_schedule = __commonJS({
160
- "node_modules/@netlify/functions/dist/lib/schedule.js"(exports2) {
161
- "use strict";
162
- Object.defineProperty(exports2, "__esModule", { value: true });
163
- exports2.schedule = void 0;
164
- var schedule = (cron, handler) => handler;
165
- exports2.schedule = schedule;
57
+ if ("siteSlug" in options) {
58
+ payload.site_slug = options.siteSlug;
59
+ } else if ("domain" in options) {
60
+ payload.domain = options.domain;
61
+ } else {
62
+ const siteID = options.siteID || import_process.env.SITE_ID;
63
+ if (!siteID) {
64
+ throw new Error(
65
+ "The Netlify site ID was not found in the execution environment. Please supply it manually using the `siteID` property."
66
+ );
67
+ }
68
+ payload.site_id = siteID;
166
69
  }
167
- });
168
-
169
- // node_modules/@netlify/functions/dist/lib/stream.js
170
- var require_stream = __commonJS({
171
- "node_modules/@netlify/functions/dist/lib/stream.js"(exports2) {
172
- "use strict";
173
- Object.defineProperty(exports2, "__esModule", { value: true });
174
- exports2.stream = void 0;
175
- var node_stream_1 = require("node:stream");
176
- var node_util_1 = require("node:util");
177
- var pipeline = (0, node_util_1.promisify)(node_stream_1.pipeline);
178
- var stream = (handler) => awslambda.streamifyResponse(async (event, responseStream, context) => {
179
- const { body, ...httpResponseMetadata } = await handler(event, context);
180
- const responseBody = awslambda.HttpResponseStream.from(responseStream, httpResponseMetadata);
181
- if (typeof body === "undefined") {
182
- responseBody.end();
183
- } else if (typeof body === "string") {
184
- responseBody.write(body);
185
- responseBody.end();
186
- } else {
187
- await pipeline(body, responseBody);
188
- }
189
- });
190
- exports2.stream = stream;
70
+ if (!token) {
71
+ throw new Error(
72
+ "The cache purge API token was not found in the execution environment. Please supply it manually using the `token` property."
73
+ );
191
74
  }
192
- });
193
-
194
- // node_modules/@netlify/functions/dist/function/index.js
195
- var require_function = __commonJS({
196
- "node_modules/@netlify/functions/dist/function/index.js"(exports2) {
197
- "use strict";
198
- Object.defineProperty(exports2, "__esModule", { value: true });
75
+ const apiURL = options.apiURL || "https://api.netlify.com";
76
+ const response = await fetch(`${apiURL}/api/v1/purge`, {
77
+ method: "POST",
78
+ headers: {
79
+ "Content-Type": "application/json; charset=utf8",
80
+ Authorization: `Bearer ${token}`
81
+ },
82
+ body: JSON.stringify(payload)
83
+ });
84
+ if (!response.ok) {
85
+ throw new Error(`Cache purge API call returned an unexpected status code: ${response.status}`);
199
86
  }
200
- });
87
+ };
201
88
 
202
- // node_modules/@netlify/functions/dist/main.js
203
- var require_main = __commonJS({
204
- "node_modules/@netlify/functions/dist/main.js"(exports2) {
205
- "use strict";
206
- var __createBinding = exports2 && exports2.__createBinding || (Object.create ? function(o, m, k, k2) {
207
- if (k2 === void 0)
208
- k2 = k;
209
- var desc = Object.getOwnPropertyDescriptor(m, k);
210
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
211
- desc = { enumerable: true, get: function() {
212
- return m[k];
213
- } };
214
- }
215
- Object.defineProperty(o, k2, desc);
216
- } : function(o, m, k, k2) {
217
- if (k2 === void 0)
218
- k2 = k;
219
- o[k2] = m[k];
220
- });
221
- var __exportStar = exports2 && exports2.__exportStar || function(m, exports3) {
222
- for (var p in m)
223
- if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports3, p))
224
- __createBinding(exports3, m, p);
225
- };
226
- Object.defineProperty(exports2, "__esModule", { value: true });
227
- exports2.stream = exports2.schedule = exports2.purgeCache = exports2.builder = void 0;
228
- var builder_js_1 = require_builder();
229
- Object.defineProperty(exports2, "builder", { enumerable: true, get: function() {
230
- return builder_js_1.builder;
231
- } });
232
- var purge_cache_js_1 = require_purge_cache();
233
- Object.defineProperty(exports2, "purgeCache", { enumerable: true, get: function() {
234
- return purge_cache_js_1.purgeCache;
235
- } });
236
- var schedule_js_1 = require_schedule();
237
- Object.defineProperty(exports2, "schedule", { enumerable: true, get: function() {
238
- return schedule_js_1.schedule;
239
- } });
240
- var stream_js_1 = require_stream();
241
- Object.defineProperty(exports2, "stream", { enumerable: true, get: function() {
242
- return stream_js_1.stream;
243
- } });
244
- __exportStar(require_function(), exports2);
245
- }
246
- });
89
+ // node_modules/@netlify/functions/dist/chunk-XSZVKDJB.mjs
90
+ var import_stream = require("stream");
91
+ var import_util = require("util");
92
+ var pipeline = (0, import_util.promisify)(import_stream.pipeline);
247
93
 
248
94
  // src/run/handlers/cache.cts
249
- var cache_exports = {};
250
- __export(cache_exports, {
251
- NetlifyCacheHandler: () => NetlifyCacheHandler,
252
- default: () => cache_default
253
- });
254
- module.exports = __toCommonJS(cache_exports);
255
- var import_node_buffer = require("node:buffer");
256
- var import_functions = __toESM(require_main());
257
95
  var import_constants = require("next/dist/lib/constants.js");
258
96
  var import_regional_blob_store = require("../regional-blob-store.cjs");
97
+ var import_systemlog = require("../systemlog.cjs");
259
98
  var import_request_context = require("./request-context.cjs");
260
99
  var import_tracer = require("./tracer.cjs");
261
100
  var NetlifyCacheHandler = class {
@@ -318,7 +157,7 @@ var NetlifyCacheHandler = class {
318
157
  async get(...args) {
319
158
  return this.tracer.withActiveSpan("get cache key", async (span) => {
320
159
  const [key, ctx = {}] = args;
321
- console.debug(`[NetlifyCacheHandler.get]: ${key}`);
160
+ import_systemlog.logger.debug(`[NetlifyCacheHandler.get]: ${key}`);
322
161
  const blobKey = await this.encodeBlobKey(key);
323
162
  span.setAttributes({ key, blobKey });
324
163
  const blob = await this.tracer.withActiveSpan("blobStore.get", async (blobGetSpan) => {
@@ -373,7 +212,7 @@ var NetlifyCacheHandler = class {
373
212
  const blobKey = await this.encodeBlobKey(key);
374
213
  const lastModified = Date.now();
375
214
  span.setAttributes({ key, lastModified, blobKey });
376
- console.debug(`[NetlifyCacheHandler.set]: ${key}`);
215
+ import_systemlog.logger.debug(`[NetlifyCacheHandler.set]: ${key}`);
377
216
  const value = data?.kind === "ROUTE" ? (
378
217
  // don't mutate data, as it's used for the initial response - instead create a new object
379
218
  {
@@ -390,27 +229,32 @@ var NetlifyCacheHandler = class {
390
229
  const requestContext = (0, import_request_context.getRequestContext)();
391
230
  if (requestContext?.didPagesRouterOnDemandRevalidate) {
392
231
  const tag = `_N_T_${key === "/index" ? "/" : key}`;
393
- console.debug("Purging CDN cache for:", [tag]);
394
- (0, import_functions.purgeCache)({ tags: [tag] }).catch((error) => {
395
- console.error(`[NetlifyCacheHandler]: Purging the cache for tag ${tag} failed`, error);
232
+ import_systemlog.logger.debug(`Purging CDN cache for: [${tag}]`);
233
+ purgeCache({ tags: [tag] }).catch((error) => {
234
+ import_systemlog.logger.withError(error).error(`[NetlifyCacheHandler]: Purging the cache for tag ${tag} failed`);
396
235
  });
397
236
  }
398
237
  }
399
238
  });
400
239
  }
401
240
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
402
- async revalidateTag(tag, ...args) {
403
- console.debug("NetlifyCacheHandler.revalidateTag", tag, args);
241
+ async revalidateTag(tagOrTags, ...args) {
242
+ import_systemlog.logger.withFields({ tagOrTags, args }).debug("NetlifyCacheHandler.revalidateTag");
243
+ const tags = Array.isArray(tagOrTags) ? tagOrTags : [tagOrTags];
404
244
  const data = {
405
245
  revalidatedAt: Date.now()
406
246
  };
407
- try {
408
- await this.blobStore.setJSON(await this.encodeBlobKey(tag), data);
409
- } catch (error) {
410
- console.warn(`Failed to update tag manifest for ${tag}`, error);
411
- }
412
- (0, import_functions.purgeCache)({ tags: [tag] }).catch((error) => {
413
- console.error(`[NetlifyCacheHandler]: Purging the cache for tag ${tag} failed`, error);
247
+ await Promise.all(
248
+ tags.map(async (tag) => {
249
+ try {
250
+ await this.blobStore.setJSON(await this.encodeBlobKey(tag), data);
251
+ } catch (error) {
252
+ import_systemlog.logger.withError(error).log(`Failed to update tag manifest for ${tag}`);
253
+ }
254
+ })
255
+ );
256
+ purgeCache({ tags }).catch((error) => {
257
+ import_systemlog.logger.withError(error).error(`[NetlifyCacheHandler]: Purging the cache for tags ${tags.join(", ")} failed`);
414
258
  });
415
259
  }
416
260
  resetRequestCache() {