@netlify/plugin-nextjs 5.7.2 → 5.7.3

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.
@@ -24,7 +24,7 @@ __export(regional_blob_store_exports, {
24
24
  });
25
25
  module.exports = __toCommonJS(regional_blob_store_exports);
26
26
 
27
- // node_modules/@netlify/blobs/dist/chunk-SGXOM2EY.js
27
+ // node_modules/@netlify/blobs/dist/chunk-GUEW34CP.js
28
28
  var NF_ERROR = "x-nf-error";
29
29
  var NF_REQUEST_ID = "x-nf-request-id";
30
30
  var BlobsInternalError = class extends Error {
@@ -139,6 +139,20 @@ var BlobsConsistencyError = class extends Error {
139
139
  this.name = "BlobsConsistencyError";
140
140
  }
141
141
  };
142
+ var REGION_AUTO = "auto";
143
+ var regions = {
144
+ "us-east-1": true,
145
+ "us-east-2": true
146
+ };
147
+ var isValidRegion = (input) => Object.keys(regions).includes(input);
148
+ var InvalidBlobsRegionError = class extends Error {
149
+ constructor(region) {
150
+ super(
151
+ `${region} is not a supported Netlify Blobs region. Supported values are: ${Object.keys(regions).join(", ")}.`
152
+ );
153
+ this.name = "InvalidBlobsRegionError";
154
+ }
155
+ };
142
156
  var DEFAULT_RETRY_DELAY = getEnvironment().get("NODE_ENV") === "test" ? 1 : 5e3;
143
157
  var MIN_RETRY_DELAY = 1e3;
144
158
  var MAX_RETRY = 5;
@@ -306,6 +320,9 @@ var getClientOptions = (options, contextOverride) => {
306
320
  if (!siteID || !token) {
307
321
  throw new MissingBlobsEnvironmentError(["siteID", "token"]);
308
322
  }
323
+ if (options.region !== void 0 && !isValidRegion(options.region)) {
324
+ throw new InvalidBlobsRegionError(options.region);
325
+ }
309
326
  const clientOptions = {
310
327
  apiURL: context.apiURL ?? options.apiURL,
311
328
  consistency: options.consistency,
@@ -542,18 +559,28 @@ var Store = class _Store {
542
559
  parameters: nextParameters,
543
560
  storeName
544
561
  });
545
- const page = await res.json();
546
- if (page.next_cursor) {
547
- currentCursor = page.next_cursor;
548
- } else {
562
+ let blobs = [];
563
+ let directories = [];
564
+ if (![200, 204, 404].includes(res.status)) {
565
+ throw new BlobsInternalError(res);
566
+ }
567
+ if (res.status === 404) {
549
568
  done = true;
569
+ } else {
570
+ const page = await res.json();
571
+ if (page.next_cursor) {
572
+ currentCursor = page.next_cursor;
573
+ } else {
574
+ done = true;
575
+ }
576
+ blobs = (page.blobs ?? []).map(_Store.formatListResultBlob).filter(Boolean);
577
+ directories = page.directories ?? [];
550
578
  }
551
- const blobs = (page.blobs ?? []).map(_Store.formatListResultBlob).filter(Boolean);
552
579
  return {
553
580
  done: false,
554
581
  value: {
555
582
  blobs,
556
- directories: page.directories ?? []
583
+ directories
557
584
  }
558
585
  };
559
586
  }
@@ -570,20 +597,17 @@ var getDeployStore = (input = {}) => {
570
597
  throw new MissingBlobsEnvironmentError(["deployID"]);
571
598
  }
572
599
  const clientOptions = getClientOptions(options, context);
573
- if (options.experimentalRegion === "context") {
574
- if (!context.primaryRegion) {
575
- throw new Error(
576
- 'The Netlify Blobs client was initialized with `experimentalRegion: "context"` but there is no region configured in the environment'
577
- );
578
- }
579
- clientOptions.region = context.primaryRegion;
580
- } else if (options.experimentalRegion === "auto") {
581
- if (clientOptions.edgeURL) {
582
- throw new Error(
583
- 'The Netlify Blobs client was initialized with `experimentalRegion: "auto"` which is not compatible with the `edgeURL` property; consider using `apiURL` instead'
584
- );
600
+ if (!clientOptions.region) {
601
+ if (clientOptions.edgeURL || clientOptions.uncachedEdgeURL) {
602
+ if (!context.primaryRegion) {
603
+ throw new Error(
604
+ "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."
605
+ );
606
+ }
607
+ clientOptions.region = context.primaryRegion;
608
+ } else {
609
+ clientOptions.region = REGION_AUTO;
585
610
  }
586
- clientOptions.region = options.experimentalRegion;
587
611
  }
588
612
  const client = new Client(clientOptions);
589
613
  return new Store({ client, deployID, name: options.name });
@@ -592,11 +616,10 @@ var getDeployStore = (input = {}) => {
592
616
  // src/run/regional-blob-store.cts
593
617
  var fetchBeforeNextPatchedIt = globalThis.fetch;
594
618
  var getRegionalBlobStore = (args = {}) => {
595
- const options = typeof args === "string" ? { name: args } : args;
596
619
  return getDeployStore({
597
- ...options,
620
+ ...args,
598
621
  fetch: fetchBeforeNextPatchedIt,
599
- experimentalRegion: process.env.USE_REGIONAL_BLOBS?.toUpperCase() === "TRUE" ? "context" : void 0
622
+ region: process.env.USE_REGIONAL_BLOBS?.toUpperCase() === "TRUE" ? void 0 : "us-east-2"
600
623
  });
601
624
  };
602
625
  // Annotate the CommonJS export names for ESM import in node:
@@ -24,7 +24,6 @@ interface BuildResponseOptions {
24
24
  request: Request
25
25
  result: FetchEventResult
26
26
  nextConfig?: RequestData['nextConfig']
27
- requestLocale?: string
28
27
  }
29
28
 
30
29
  export const buildResponse = async ({
@@ -33,7 +32,6 @@ export const buildResponse = async ({
33
32
  request,
34
33
  result,
35
34
  nextConfig,
36
- requestLocale,
37
35
  }: BuildResponseOptions): Promise<Response | void> => {
38
36
  logger
39
37
  .withFields({ is_nextresponse_next: result.response.headers.has('x-middleware-next') })
@@ -197,11 +195,10 @@ export const buildResponse = async ({
197
195
  return addMiddlewareHeaders(context.rewrite(target), res)
198
196
  }
199
197
 
200
- // If we are redirecting a request that had a locale in the URL, we need to add it back in
201
- if (redirect && requestLocale) {
202
- redirect = normalizeLocalizedTarget({ target: redirect, request, nextConfig, requestLocale })
198
+ if (redirect) {
199
+ redirect = normalizeLocalizedTarget({ target: redirect, request, nextConfig })
203
200
  if (redirect === request.url) {
204
- logger.withFields({ rewrite_url: rewrite }).debug('Rewrite url is same as original url')
201
+ logger.withFields({ redirect_url: redirect }).debug('Redirect url is same as original url')
205
202
  return
206
203
  }
207
204
  res.headers.set('location', redirect)
@@ -234,25 +231,25 @@ function normalizeLocalizedTarget({
234
231
  target,
235
232
  request,
236
233
  nextConfig,
237
- requestLocale,
238
234
  }: {
239
235
  target: string
240
236
  request: Request
241
237
  nextConfig?: RequestData['nextConfig']
242
- requestLocale?: string
243
- }) {
238
+ }): string {
244
239
  const targetUrl = new URL(target, request.url)
245
240
 
246
241
  const normalizedTarget = normalizeLocalePath(targetUrl.pathname, nextConfig?.i18n?.locales)
247
242
 
248
- const locale = normalizedTarget.detectedLocale ?? requestLocale
249
243
  if (
250
- locale &&
244
+ normalizedTarget.detectedLocale &&
251
245
  !normalizedTarget.pathname.startsWith(`/api/`) &&
252
246
  !normalizedTarget.pathname.startsWith(`/_next/static/`)
253
247
  ) {
254
248
  targetUrl.pathname =
255
- addBasePath(`/${locale}${normalizedTarget.pathname}`, nextConfig?.basePath) || `/`
249
+ addBasePath(
250
+ `/${normalizedTarget.detectedLocale}${normalizedTarget.pathname}`,
251
+ nextConfig?.basePath,
252
+ ) || `/`
256
253
  } else {
257
254
  targetUrl.pathname = addBasePath(normalizedTarget.pathname, nextConfig?.basePath) || `/`
258
255
  }
@@ -61,7 +61,6 @@ export async function handleMiddleware(
61
61
  logger: reqLogger,
62
62
  request,
63
63
  result,
64
- requestLocale: nextRequest.detectedLocale,
65
64
  nextConfig,
66
65
  })
67
66
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netlify/plugin-nextjs",
3
- "version": "5.7.2",
3
+ "version": "5.7.3",
4
4
  "description": "Run Next.js seamlessly on Netlify",
5
5
  "main": "./dist/index.js",
6
6
  "type": "module",