@netlify/plugin-nextjs 5.10.7 → 5.11.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 +5 -9
  4. package/dist/build/content/server.js +22 -15
  5. package/dist/build/content/static.js +4 -8
  6. package/dist/build/functions/edge.js +2 -2
  7. package/dist/build/functions/server.js +4 -8
  8. package/dist/build/image-cdn.js +1 -1
  9. package/dist/build/plugin-context.js +2 -2
  10. package/dist/build/templates/handler-monorepo.tmpl.js +0 -5
  11. package/dist/build/templates/handler.tmpl.js +0 -4
  12. package/dist/build/verification.js +3 -3
  13. package/dist/esm-chunks/{chunk-OEQOKJGE.js → chunk-6BT4RYQJ.js} +1 -12
  14. package/dist/esm-chunks/chunk-FKDTZJRV.js +832 -0
  15. package/dist/esm-chunks/{chunk-APO262HE.js → chunk-PFLHY2KD.js} +1 -1
  16. package/dist/esm-chunks/{chunk-NFOLXH6F.js → chunk-YUXQHOYO.js} +1 -1
  17. package/dist/index.js +3 -7
  18. package/dist/run/config.js +3 -3
  19. package/dist/run/constants.js +3 -3
  20. package/dist/run/handlers/cache.cjs +24 -234
  21. package/dist/run/handlers/request-context.cjs +63 -88
  22. package/dist/run/handlers/server.js +9 -6
  23. package/dist/run/handlers/tags-handler.cjs +192 -0
  24. package/dist/run/handlers/tracer.cjs +4 -4
  25. package/dist/run/handlers/use-cache-handler.js +1553 -0
  26. package/dist/run/headers.js +1 -1
  27. package/dist/run/revalidate.js +1 -1
  28. package/dist/shared/blobkey.js +1 -1
  29. package/package.json +1 -1
  30. package/dist/esm-chunks/chunk-5QSXBV7L.js +0 -89
  31. package/dist/esm-chunks/chunk-GNGHTHMQ.js +0 -1624
  32. package/dist/esm-chunks/package-SGSU42JZ.js +0 -148
  33. package/dist/run/handlers/tracing.js +0 -68968
@@ -0,0 +1,192 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name2 in all)
8
+ __defProp(target, name2, { get: all[name2], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/run/handlers/tags-handler.cts
21
+ var tags_handler_exports = {};
22
+ __export(tags_handler_exports, {
23
+ getMostRecentTagRevalidationTimestamp: () => getMostRecentTagRevalidationTimestamp,
24
+ isAnyTagStale: () => isAnyTagStale,
25
+ markTagsAsStaleAndPurgeEdgeCache: () => markTagsAsStaleAndPurgeEdgeCache,
26
+ purgeEdgeCache: () => purgeEdgeCache
27
+ });
28
+ module.exports = __toCommonJS(tags_handler_exports);
29
+
30
+ // node_modules/@netlify/functions/dist/main.js
31
+ var import_process = require("process");
32
+ var import_node_stream = require("node:stream");
33
+ var import_node_util = require("node:util");
34
+ var purgeCache = async (options = {}) => {
35
+ if (globalThis.fetch === void 0) {
36
+ throw new Error(
37
+ "`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."
38
+ );
39
+ }
40
+ const payload = {
41
+ cache_tags: options.tags,
42
+ deploy_alias: options.deployAlias
43
+ };
44
+ const token = import_process.env.NETLIFY_PURGE_API_TOKEN || options.token;
45
+ if (import_process.env.NETLIFY_LOCAL && !token) {
46
+ const scope = options.tags?.length ? ` for tags ${options.tags?.join(", ")}` : "";
47
+ console.log(`Skipping purgeCache${scope} in local development.`);
48
+ return;
49
+ }
50
+ if ("siteSlug" in options) {
51
+ payload.site_slug = options.siteSlug;
52
+ } else if ("domain" in options) {
53
+ payload.domain = options.domain;
54
+ } else {
55
+ const siteID = options.siteID || import_process.env.SITE_ID;
56
+ if (!siteID) {
57
+ throw new Error(
58
+ "The Netlify site ID was not found in the execution environment. Please supply it manually using the `siteID` property."
59
+ );
60
+ }
61
+ payload.site_id = siteID;
62
+ }
63
+ if (!token) {
64
+ throw new Error(
65
+ "The cache purge API token was not found in the execution environment. Please supply it manually using the `token` property."
66
+ );
67
+ }
68
+ const headers = {
69
+ "Content-Type": "application/json; charset=utf8",
70
+ Authorization: `Bearer ${token}`
71
+ };
72
+ if (options.userAgent) {
73
+ headers["user-agent"] = options.userAgent;
74
+ }
75
+ const apiURL = options.apiURL || "https://api.netlify.com";
76
+ const response = await fetch(`${apiURL}/api/v1/purge`, {
77
+ method: "POST",
78
+ headers,
79
+ body: JSON.stringify(payload)
80
+ });
81
+ if (!response.ok) {
82
+ throw new Error(`Cache purge API call returned an unexpected status code: ${response.status}`);
83
+ }
84
+ };
85
+ var pipeline = (0, import_node_util.promisify)(import_node_stream.pipeline);
86
+
87
+ // package.json
88
+ var name = "@netlify/plugin-nextjs";
89
+ var version = "5.11.0";
90
+
91
+ // src/run/handlers/tags-handler.cts
92
+ var import_storage = require("../storage/storage.cjs");
93
+ var import_request_context = require("./request-context.cjs");
94
+ var purgeCacheUserAgent = `${name}@${version}`;
95
+ async function getTagRevalidatedAt(tag, cacheStore) {
96
+ const tagManifest = await cacheStore.get(tag, "tagManifest.get");
97
+ if (!tagManifest) {
98
+ return null;
99
+ }
100
+ return tagManifest.revalidatedAt;
101
+ }
102
+ async function getMostRecentTagRevalidationTimestamp(tags) {
103
+ if (tags.length === 0) {
104
+ return 0;
105
+ }
106
+ const cacheStore = (0, import_storage.getMemoizedKeyValueStoreBackedByRegionalBlobStore)({ consistency: "strong" });
107
+ const timestampsOrNulls = await Promise.all(
108
+ tags.map((tag) => getTagRevalidatedAt(tag, cacheStore))
109
+ );
110
+ const timestamps = timestampsOrNulls.filter((timestamp) => timestamp !== null);
111
+ if (timestamps.length === 0) {
112
+ return 0;
113
+ }
114
+ return Math.max(...timestamps);
115
+ }
116
+ function isAnyTagStale(tags, timestamp) {
117
+ if (tags.length === 0 || !timestamp) {
118
+ return Promise.resolve(false);
119
+ }
120
+ const cacheStore = (0, import_storage.getMemoizedKeyValueStoreBackedByRegionalBlobStore)({ consistency: "strong" });
121
+ return new Promise((resolve, reject) => {
122
+ const tagManifestPromises = [];
123
+ for (const tag of tags) {
124
+ const lastRevalidationTimestampPromise = getTagRevalidatedAt(tag, cacheStore);
125
+ tagManifestPromises.push(
126
+ lastRevalidationTimestampPromise.then((lastRevalidationTimestamp) => {
127
+ if (!lastRevalidationTimestamp) {
128
+ return false;
129
+ }
130
+ const isStale = lastRevalidationTimestamp >= timestamp;
131
+ if (isStale) {
132
+ resolve(true);
133
+ return true;
134
+ }
135
+ return false;
136
+ })
137
+ );
138
+ }
139
+ Promise.all(tagManifestPromises).then((tagManifestAreStale) => {
140
+ resolve(tagManifestAreStale.some((tagIsStale) => tagIsStale));
141
+ }).catch(reject);
142
+ });
143
+ }
144
+ function getCacheTagsFromTagOrTags(tagOrTags) {
145
+ return (Array.isArray(tagOrTags) ? tagOrTags : [tagOrTags]).flatMap((tag) => tag.split(/,|%2c/gi)).filter(Boolean);
146
+ }
147
+ function purgeEdgeCache(tagOrTags) {
148
+ const tags = getCacheTagsFromTagOrTags(tagOrTags);
149
+ if (tags.length === 0) {
150
+ return Promise.resolve();
151
+ }
152
+ (0, import_request_context.getLogger)().debug(`[NextRuntime] Purging CDN cache for: [${tags}.join(', ')]`);
153
+ return purgeCache({ tags, userAgent: purgeCacheUserAgent }).catch((error) => {
154
+ (0, import_request_context.getLogger)().withError(error).error(`[NextRuntime] Purging the cache for tags [${tags.join(",")}] failed`);
155
+ });
156
+ }
157
+ async function doRevalidateTagAndPurgeEdgeCache(tags) {
158
+ (0, import_request_context.getLogger)().withFields({ tags }).debug("doRevalidateTagAndPurgeEdgeCache");
159
+ if (tags.length === 0) {
160
+ return;
161
+ }
162
+ const tagManifest = {
163
+ revalidatedAt: Date.now()
164
+ };
165
+ const cacheStore = (0, import_storage.getMemoizedKeyValueStoreBackedByRegionalBlobStore)({ consistency: "strong" });
166
+ await Promise.all(
167
+ tags.map(async (tag) => {
168
+ try {
169
+ await cacheStore.set(tag, tagManifest, "tagManifest.set");
170
+ } catch (error) {
171
+ (0, import_request_context.getLogger)().withError(error).log(`[NextRuntime] Failed to update tag manifest for ${tag}`);
172
+ }
173
+ })
174
+ );
175
+ await purgeEdgeCache(tags);
176
+ }
177
+ function markTagsAsStaleAndPurgeEdgeCache(tagOrTags) {
178
+ const tags = getCacheTagsFromTagOrTags(tagOrTags);
179
+ const revalidateTagPromise = doRevalidateTagAndPurgeEdgeCache(tags);
180
+ const requestContext = (0, import_request_context.getRequestContext)();
181
+ if (requestContext) {
182
+ requestContext.trackBackgroundWork(revalidateTagPromise);
183
+ }
184
+ return revalidateTagPromise;
185
+ }
186
+ // Annotate the CommonJS export names for ESM import in node:
187
+ 0 && (module.exports = {
188
+ getMostRecentTagRevalidationTimestamp,
189
+ isAnyTagStale,
190
+ markTagsAsStaleAndPurgeEdgeCache,
191
+ purgeEdgeCache
192
+ });
@@ -786,23 +786,23 @@ function wrapTracer(tracer2) {
786
786
  var SugaredTracer = (
787
787
  /** @class */
788
788
  function() {
789
- function SugaredTracer3(tracer2) {
789
+ function SugaredTracer2(tracer2) {
790
790
  this._tracer = tracer2;
791
791
  this.startSpan = tracer2.startSpan.bind(this._tracer);
792
792
  this.startActiveSpan = tracer2.startActiveSpan.bind(this._tracer);
793
793
  }
794
- SugaredTracer3.prototype.withActiveSpan = function(name, arg2, arg3, arg4) {
794
+ SugaredTracer2.prototype.withActiveSpan = function(name, arg2, arg3, arg4) {
795
795
  var _a = massageParams(arg2, arg3, arg4), opts = _a.opts, ctx = _a.ctx, fn = _a.fn;
796
796
  return this._tracer.startActiveSpan(name, opts, ctx, function(span) {
797
797
  return handleFn(span, opts, fn);
798
798
  });
799
799
  };
800
- SugaredTracer3.prototype.withSpan = function(name, arg2, arg3, arg4) {
800
+ SugaredTracer2.prototype.withSpan = function(name, arg2, arg3, arg4) {
801
801
  var _a = massageParams(arg2, arg3, arg4), opts = _a.opts, ctx = _a.ctx, fn = _a.fn;
802
802
  var span = this._tracer.startSpan(name, opts, ctx);
803
803
  return handleFn(span, opts, fn);
804
804
  };
805
- return SugaredTracer3;
805
+ return SugaredTracer2;
806
806
  }()
807
807
  );
808
808
  function massageParams(arg, arg2, arg3) {