next-intl 3.15.3 → 3.15.5

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.
@@ -22,7 +22,7 @@ function createMiddleware(input) {
22
22
  locale
23
23
  } = resolveLocale.default(config$1, request.headers, request.cookies, externalPathname);
24
24
  const hasMatchedDefaultLocale = domain ? domain.defaultLocale === locale : locale === config$1.defaultLocale;
25
- const domainConfigs = ((_config$domains = config$1.domains) === null || _config$domains === void 0 ? void 0 : _config$domains.filter(curDomain => utils.isLocaleSupportedOnDomain(locale, curDomain))) || [];
25
+ const domainsConfig = ((_config$domains = config$1.domains) === null || _config$domains === void 0 ? void 0 : _config$domains.filter(curDomain => utils.isLocaleSupportedOnDomain(locale, curDomain))) || [];
26
26
  const hasUnknownHost = config$1.domains != null && !domain;
27
27
  function rewrite(url) {
28
28
  const urlObj = new URL(url, request.url);
@@ -39,8 +39,8 @@ function createMiddleware(input) {
39
39
  }
40
40
  function redirect(url, redirectDomain) {
41
41
  const urlObj = new URL(utils.normalizeTrailingSlash(url), request.url);
42
- if (domainConfigs.length > 0 && !redirectDomain) {
43
- const bestMatchingDomain = utils.getBestMatchingDomain(domain, locale, domainConfigs);
42
+ if (domainsConfig.length > 0 && !redirectDomain) {
43
+ const bestMatchingDomain = utils.getBestMatchingDomain(domain, locale, domainsConfig);
44
44
  if (bestMatchingDomain) {
45
45
  redirectDomain = bestMatchingDomain.domain;
46
46
  if (bestMatchingDomain.defaultLocale === locale && config$1.localePrefix.mode === 'as-needed') {
@@ -114,7 +114,7 @@ function createMiddleware(input) {
114
114
  response = redirect(utils.formatPathname(unprefixedExternalPathname, undefined, request.nextUrl.search));
115
115
  } else {
116
116
  if (config$1.domains) {
117
- const pathDomain = utils.getBestMatchingDomain(domain, pathnameMatch.locale, domainConfigs);
117
+ const pathDomain = utils.getBestMatchingDomain(domain, pathnameMatch.locale, domainsConfig);
118
118
  if ((domain === null || domain === void 0 ? void 0 : domain.domain) !== (pathDomain === null || pathDomain === void 0 ? void 0 : pathDomain.domain) && !hasUnknownHost) {
119
119
  response = redirect(externalHref, pathDomain === null || pathDomain === void 0 ? void 0 : pathDomain.domain);
120
120
  } else {
@@ -143,7 +143,7 @@ function getHost(requestHeaders) {
143
143
  function isLocaleSupportedOnDomain(locale, domain) {
144
144
  return domain.defaultLocale === locale || !domain.locales || domain.locales.includes(locale);
145
145
  }
146
- function getBestMatchingDomain(curHostDomain, locale, domainConfigs) {
146
+ function getBestMatchingDomain(curHostDomain, locale, domainsConfig) {
147
147
  let domainConfig;
148
148
 
149
149
  // Prio 1: Stay on current domain
@@ -153,12 +153,12 @@ function getBestMatchingDomain(curHostDomain, locale, domainConfigs) {
153
153
 
154
154
  // Prio 2: Use alternative domain with matching default locale
155
155
  if (!domainConfig) {
156
- domainConfig = domainConfigs.find(cur => cur.defaultLocale === locale);
156
+ domainConfig = domainsConfig.find(cur => cur.defaultLocale === locale);
157
157
  }
158
158
 
159
159
  // Prio 3: Use alternative domain with restricted matching locale
160
160
  if (!domainConfig) {
161
- domainConfig = domainConfigs.find(cur => cur.locales != null && cur.locales.includes(locale));
161
+ domainConfig = domainsConfig.find(cur => cur.locales != null && cur.locales.includes(locale));
162
162
  }
163
163
 
164
164
  // Prio 4: Stay on the current domain if it supports all locales
@@ -168,7 +168,7 @@ function getBestMatchingDomain(curHostDomain, locale, domainConfigs) {
168
168
 
169
169
  // Prio 5: Use alternative domain that supports all locales
170
170
  if (!domainConfig) {
171
- domainConfig = domainConfigs.find(cur => !cur.locales);
171
+ domainConfig = domainsConfig.find(cur => !cur.locales);
172
172
  }
173
173
  return domainConfig;
174
174
  }
@@ -8,7 +8,7 @@ var utils = require('../../shared/utils.js');
8
8
  function createRedirectFn(redirectFn) {
9
9
  return function baseRedirect(params) {
10
10
  const prefix = utils.getLocalePrefix(params.locale, params.localePrefix);
11
- const localizedPathname = params.localePrefix.mode === 'never' || !utils.isLocalHref(params.pathname) ? params.pathname : utils.prefixPathname(prefix, params.pathname);
11
+ const localizedPathname = params.localePrefix.mode === 'never' || !utils.isLocalizableHref(params.pathname) ? params.pathname : utils.prefixPathname(prefix, params.pathname);
12
12
  for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
13
13
  args[_key - 1] = arguments[_key];
14
14
  }
@@ -134,9 +134,7 @@ function getSortedPathnames(pathnames) {
134
134
  exports.getLocalePrefix = getLocalePrefix;
135
135
  exports.getSortedPathnames = getSortedPathnames;
136
136
  exports.hasPathnamePrefixed = hasPathnamePrefixed;
137
- exports.isLocalHref = isLocalHref;
138
137
  exports.isLocalizableHref = isLocalizableHref;
139
- exports.isRelativeHref = isRelativeHref;
140
138
  exports.localizeHref = localizeHref;
141
139
  exports.matchesPathname = matchesPathname;
142
140
  exports.prefixHref = prefixHref;
@@ -1 +1 @@
1
- import{redirect as e,permanentRedirect as n}from"next/navigation";import{getLocalePrefix as r,isLocalHref as t,prefixPathname as o}from"../../shared/utils.js";function a(e){return function(n){const a=r(n.locale,n.localePrefix),i="never"!==n.localePrefix.mode&&t(n.pathname)?o(a,n.pathname):n.pathname;for(var l=arguments.length,m=new Array(l>1?l-1:0),c=1;c<l;c++)m[c-1]=arguments[c];return e(i,...m)}}const i=a(e),l=a(n);export{l as basePermanentRedirect,i as baseRedirect};
1
+ import{redirect as e,permanentRedirect as n}from"next/navigation";import{getLocalePrefix as r,isLocalizableHref as t,prefixPathname as o}from"../../shared/utils.js";function a(e){return function(n){const a=r(n.locale,n.localePrefix),i="never"!==n.localePrefix.mode&&t(n.pathname)?o(a,n.pathname):n.pathname;for(var l=arguments.length,m=new Array(l>1?l-1:0),c=1;c<l;c++)m[c-1]=arguments[c];return e(i,...m)}}const i=a(e),l=a(n);export{l as basePermanentRedirect,i as baseRedirect};
@@ -1 +1 @@
1
- function n(n){const t="object"==typeof n?n.pathname:n;return null!=t&&!t.startsWith("/")}function t(n){if("object"==typeof n)return null==n.host&&null==n.hostname;return!/^[a-z]+:/i.test(n)}function e(e){return t(e)&&!n(e)}function r(n,t){let r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t,i=arguments.length>3?arguments[3]:void 0,o=arguments.length>4?arguments[4]:void 0;if(!e(n))return n;const f=t!==r,l=c(o,i);return(f||l)&&null!=o?u(n,o):n}function u(n,t){let e;return"string"==typeof n?e=o(t,n):(e={...n},n.pathname&&(e.pathname=o(t,n.pathname))),e}function i(n,t){return n.replace(new RegExp("^".concat(t)),"")||"/"}function o(n,t){let e=n;return/^\/(\?.*)?$/.test(t)&&(t=t.slice(1)),e+=t,e}function c(n,t){return t===n||t.startsWith("".concat(n,"/"))}function f(n,t){return s(n).test(t)}function l(n,t){var e;return"never"!==t.mode&&(null===(e=t.prefixes)||void 0===e?void 0:e[n])||"/"+n}function s(n){const t=n.replace(/\[\[(\.\.\.[^\]]+)\]\]/g,"?(.*)").replace(/\[(\.\.\.[^\]]+)\]/g,"(.+)").replace(/\[([^\]]+)\]/g,"([^/]+)");return new RegExp("^".concat(t,"$"))}function a(n){return n.includes("[[...")}function p(n){return n.includes("[...")}function h(n){return n.includes("[")}function g(n,t){const e=n.split("/"),r=t.split("/"),u=Math.max(e.length,r.length);for(let n=0;n<u;n++){const t=e[n],u=r[n];if(!t&&u)return-1;if(t&&!u)return 1;if(!h(t)&&h(u))return-1;if(h(t)&&!h(u))return 1;if(!p(t)&&p(u))return-1;if(p(t)&&!p(u))return 1;if(!a(t)&&a(u))return-1;if(a(t)&&!a(u))return 1}return 0}function d(n){return n.sort(g)}export{l as getLocalePrefix,d as getSortedPathnames,c as hasPathnamePrefixed,t as isLocalHref,e as isLocalizableHref,n as isRelativeHref,r as localizeHref,f as matchesPathname,u as prefixHref,o as prefixPathname,s as templateToRegex,i as unprefixPathname};
1
+ function n(n){return function(n){return"object"==typeof n?null==n.host&&null==n.hostname:!/^[a-z]+:/i.test(n)}(n)&&!function(n){const t="object"==typeof n?n.pathname:n;return null!=t&&!t.startsWith("/")}(n)}function t(t,r){let u=arguments.length>2&&void 0!==arguments[2]?arguments[2]:r,o=arguments.length>3?arguments[3]:void 0,c=arguments.length>4?arguments[4]:void 0;if(!n(t))return t;const f=r!==u,l=i(c,o);return(f||l)&&null!=c?e(t,c):t}function e(n,t){let e;return"string"==typeof n?e=u(t,n):(e={...n},n.pathname&&(e.pathname=u(t,n.pathname))),e}function r(n,t){return n.replace(new RegExp("^".concat(t)),"")||"/"}function u(n,t){let e=n;return/^\/(\?.*)?$/.test(t)&&(t=t.slice(1)),e+=t,e}function i(n,t){return t===n||t.startsWith("".concat(n,"/"))}function o(n,t){return f(n).test(t)}function c(n,t){var e;return"never"!==t.mode&&(null===(e=t.prefixes)||void 0===e?void 0:e[n])||"/"+n}function f(n){const t=n.replace(/\[\[(\.\.\.[^\]]+)\]\]/g,"?(.*)").replace(/\[(\.\.\.[^\]]+)\]/g,"(.+)").replace(/\[([^\]]+)\]/g,"([^/]+)");return new RegExp("^".concat(t,"$"))}function l(n){return n.includes("[[...")}function s(n){return n.includes("[...")}function a(n){return n.includes("[")}function p(n,t){const e=n.split("/"),r=t.split("/"),u=Math.max(e.length,r.length);for(let n=0;n<u;n++){const t=e[n],u=r[n];if(!t&&u)return-1;if(t&&!u)return 1;if(!a(t)&&a(u))return-1;if(a(t)&&!a(u))return 1;if(!s(t)&&s(u))return-1;if(s(t)&&!s(u))return 1;if(!l(t)&&l(u))return-1;if(l(t)&&!l(u))return 1}return 0}function h(n){return n.sort(p)}export{c as getLocalePrefix,h as getSortedPathnames,i as hasPathnamePrefixed,n as isLocalizableHref,t as localizeHref,o as matchesPathname,e as prefixHref,u as prefixPathname,f as templateToRegex,r as unprefixPathname};
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("next/navigation"),r=require("../../shared/utils.js");function t(e){return function(t){const a=r.getLocalePrefix(t.locale,t.localePrefix),n="never"!==t.localePrefix.mode&&r.isLocalHref(t.pathname)?r.prefixPathname(a,t.pathname):t.pathname;for(var i=arguments.length,o=new Array(i>1?i-1:0),c=1;c<i;c++)o[c-1]=arguments[c];return e(n,...o)}}const a=t(e.redirect),n=t(e.permanentRedirect);exports.basePermanentRedirect=n,exports.baseRedirect=a;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("next/navigation"),r=require("../../shared/utils.js");function t(e){return function(t){const a=r.getLocalePrefix(t.locale,t.localePrefix),n="never"!==t.localePrefix.mode&&r.isLocalizableHref(t.pathname)?r.prefixPathname(a,t.pathname):t.pathname;for(var i=arguments.length,o=new Array(i>1?i-1:0),c=1;c<i;c++)o[c-1]=arguments[c];return e(n,...o)}}const a=t(e.redirect),n=t(e.permanentRedirect);exports.basePermanentRedirect=n,exports.baseRedirect=a;
@@ -1 +1 @@
1
- "use strict";function e(e){const t="object"==typeof e?e.pathname:e;return null!=t&&!t.startsWith("/")}function t(e){if("object"==typeof e)return null==e.host&&null==e.hostname;return!/^[a-z]+:/i.test(e)}function n(n){return t(n)&&!e(n)}function r(e,t){let n;return"string"==typeof e?n=o(t,e):(n={...e},e.pathname&&(n.pathname=o(t,e.pathname))),n}function o(e,t){let n=e;return/^\/(\?.*)?$/.test(t)&&(t=t.slice(1)),n+=t,n}function i(e,t){return t===e||t.startsWith("".concat(e,"/"))}function u(e){const t=e.replace(/\[\[(\.\.\.[^\]]+)\]\]/g,"?(.*)").replace(/\[(\.\.\.[^\]]+)\]/g,"(.+)").replace(/\[([^\]]+)\]/g,"([^/]+)");return new RegExp("^".concat(t,"$"))}function s(e){return e.includes("[[...")}function c(e){return e.includes("[...")}function a(e){return e.includes("[")}function f(e,t){const n=e.split("/"),r=t.split("/"),o=Math.max(n.length,r.length);for(let e=0;e<o;e++){const t=n[e],o=r[e];if(!t&&o)return-1;if(t&&!o)return 1;if(!a(t)&&a(o))return-1;if(a(t)&&!a(o))return 1;if(!c(t)&&c(o))return-1;if(c(t)&&!c(o))return 1;if(!s(t)&&s(o))return-1;if(s(t)&&!s(o))return 1}return 0}Object.defineProperty(exports,"__esModule",{value:!0}),exports.getLocalePrefix=function(e,t){var n;return"never"!==t.mode&&(null===(n=t.prefixes)||void 0===n?void 0:n[e])||"/"+e},exports.getSortedPathnames=function(e){return e.sort(f)},exports.hasPathnamePrefixed=i,exports.isLocalHref=t,exports.isLocalizableHref=n,exports.isRelativeHref=e,exports.localizeHref=function(e,t){let o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:t,u=arguments.length>3?arguments[3]:void 0,s=arguments.length>4?arguments[4]:void 0;if(!n(e))return e;const c=t!==o,a=i(s,u);return(c||a)&&null!=s?r(e,s):e},exports.matchesPathname=function(e,t){return u(e).test(t)},exports.prefixHref=r,exports.prefixPathname=o,exports.templateToRegex=u,exports.unprefixPathname=function(e,t){return e.replace(new RegExp("^".concat(t)),"")||"/"};
1
+ "use strict";function e(e){return function(e){return"object"==typeof e?null==e.host&&null==e.hostname:!/^[a-z]+:/i.test(e)}(e)&&!function(e){const t="object"==typeof e?e.pathname:e;return null!=t&&!t.startsWith("/")}(e)}function t(e,t){let r;return"string"==typeof e?r=n(t,e):(r={...e},e.pathname&&(r.pathname=n(t,e.pathname))),r}function n(e,t){let n=e;return/^\/(\?.*)?$/.test(t)&&(t=t.slice(1)),n+=t,n}function r(e,t){return t===e||t.startsWith("".concat(e,"/"))}function o(e){const t=e.replace(/\[\[(\.\.\.[^\]]+)\]\]/g,"?(.*)").replace(/\[(\.\.\.[^\]]+)\]/g,"(.+)").replace(/\[([^\]]+)\]/g,"([^/]+)");return new RegExp("^".concat(t,"$"))}function u(e){return e.includes("[[...")}function i(e){return e.includes("[...")}function c(e){return e.includes("[")}function s(e,t){const n=e.split("/"),r=t.split("/"),o=Math.max(n.length,r.length);for(let e=0;e<o;e++){const t=n[e],o=r[e];if(!t&&o)return-1;if(t&&!o)return 1;if(!c(t)&&c(o))return-1;if(c(t)&&!c(o))return 1;if(!i(t)&&i(o))return-1;if(i(t)&&!i(o))return 1;if(!u(t)&&u(o))return-1;if(u(t)&&!u(o))return 1}return 0}Object.defineProperty(exports,"__esModule",{value:!0}),exports.getLocalePrefix=function(e,t){var n;return"never"!==t.mode&&(null===(n=t.prefixes)||void 0===n?void 0:n[e])||"/"+e},exports.getSortedPathnames=function(e){return e.sort(s)},exports.hasPathnamePrefixed=r,exports.isLocalizableHref=e,exports.localizeHref=function(n,o){let u=arguments.length>2&&void 0!==arguments[2]?arguments[2]:o,i=arguments.length>3?arguments[3]:void 0,c=arguments.length>4?arguments[4]:void 0;if(!e(n))return n;const s=o!==u,a=r(c,i);return(s||a)&&null!=c?t(n,c):n},exports.matchesPathname=function(e,t){return o(e).test(t)},exports.prefixHref=t,exports.prefixPathname=n,exports.templateToRegex=o,exports.unprefixPathname=function(e,t){return e.replace(new RegExp("^".concat(t)),"")||"/"};
@@ -1,5 +1,5 @@
1
1
  import { RequestCookies } from 'next/dist/server/web/spec-extension/cookies';
2
- import { Locales, DomainConfig, Pathnames } from '../routing/types';
2
+ import { Locales, Pathnames, DomainConfig } from '../routing/types';
3
3
  import { MiddlewareRoutingConfig } from './config';
4
4
  export declare function getAcceptLanguageLocale<AppLocales extends Locales>(requestHeaders: Headers, locales: AppLocales, defaultLocale: string): string | undefined;
5
5
  export default function resolveLocale<AppLocales extends Locales, AppPathnames extends Pathnames<AppLocales>>(config: MiddlewareRoutingConfig<AppLocales, AppPathnames>, requestHeaders: Headers, requestCookies: RequestCookies, pathname: string): {
@@ -1,4 +1,4 @@
1
- import { Locales, LocalePrefixConfigVerbose, DomainConfig, Pathnames } from '../routing/types';
1
+ import { Locales, LocalePrefixConfigVerbose, DomainConfig, Pathnames, DomainsConfig } from '../routing/types';
2
2
  export declare function getFirstPathnameSegment(pathname: string): string;
3
3
  export declare function getInternalTemplate<AppLocales extends Locales, AppPathnames extends Pathnames<AppLocales>>(pathnames: AppPathnames, pathname: string, locale: AppLocales[number]): [AppLocales[number] | undefined, keyof AppPathnames | undefined];
4
4
  export declare function formatTemplatePathname(sourcePathname: string, sourceTemplate: string, targetTemplate: string, prefix?: string): string;
@@ -19,7 +19,7 @@ export declare function formatPathnameTemplate(template: string, params?: object
19
19
  export declare function formatPathname(pathname: string, prefix: string | undefined, search: string | undefined): string;
20
20
  export declare function getHost(requestHeaders: Headers): string | undefined;
21
21
  export declare function isLocaleSupportedOnDomain<AppLocales extends Locales>(locale: string, domain: DomainConfig<AppLocales>): boolean;
22
- export declare function getBestMatchingDomain<AppLocales extends Locales>(curHostDomain: DomainConfig<AppLocales> | undefined, locale: string, domainConfigs: Array<DomainConfig<AppLocales>>): DomainConfig<AppLocales> | undefined;
22
+ export declare function getBestMatchingDomain<AppLocales extends Locales>(curHostDomain: DomainConfig<AppLocales> | undefined, locale: string, domainsConfig: DomainsConfig<AppLocales>): DomainConfig<AppLocales> | undefined;
23
23
  export declare function applyBasePath(pathname: string, basePath: string): string;
24
24
  export declare function normalizeTrailingSlash(pathname: string): string;
25
25
  export declare function getLocaleAsPrefix<AppLocales extends Locales>(locale: AppLocales[number]): string;
@@ -1,4 +1,4 @@
1
- import { Locales, DomainConfig, LocalePrefix, LocalePrefixConfigVerbose } from './types';
1
+ import { Locales, LocalePrefix, LocalePrefixConfigVerbose, DomainsConfig } from './types';
2
2
  /**
3
3
  * Maintainer note: The config that is accepted by the middleware, the shared
4
4
  * and the localized pathnames navigation factory function is slightly
@@ -9,6 +9,6 @@ export type RoutingBaseConfigInput<AppLocales extends Locales> = {
9
9
  /** @see https://next-intl-docs.vercel.app/docs/routing#locale-prefix */
10
10
  localePrefix?: LocalePrefix<AppLocales>;
11
11
  /** Can be used to change the locale handling per domain. */
12
- domains?: Array<DomainConfig<AppLocales>>;
12
+ domains?: DomainsConfig<AppLocales>;
13
13
  };
14
14
  export declare function receiveLocalePrefixConfig<AppLocales extends Locales>(localePrefix?: LocalePrefix<AppLocales>): LocalePrefixConfigVerbose<AppLocales>;
@@ -1,2 +1 @@
1
- export type { LocalePrefix } from './types';
2
- export type { Pathnames } from './types';
1
+ export type { Pathnames, LocalePrefix, DomainsConfig } from './types';
@@ -18,6 +18,7 @@ export type DomainConfig<AppLocales extends Locales> = {
18
18
  /** The domain name (e.g. "example.com", "www.example.com" or "fr.example.com"). Note that the `x-forwarded-host` or alternatively the `host` header will be used to determine the requested domain. */
19
19
  domain: string;
20
20
  /** Optionally restrict which locales are available on this domain. */
21
- locales?: AppLocales;
21
+ locales?: Array<AppLocales[number]>;
22
22
  };
23
+ export type DomainsConfig<AppLocales extends Locales> = Array<DomainConfig<AppLocales>>;
23
24
  export {};
@@ -4,8 +4,6 @@ import NextLink from 'next/link';
4
4
  import { ComponentProps } from 'react';
5
5
  import { Locales, LocalePrefixConfigVerbose } from '../routing/types';
6
6
  type Href = ComponentProps<typeof NextLink>['href'];
7
- export declare function isRelativeHref(href: Href): boolean;
8
- export declare function isLocalHref(href: Href): boolean;
9
7
  export declare function isLocalizableHref(href: Href): boolean;
10
8
  export declare function localizeHref(href: string, locale: string, curLocale: string, curPathname: string, prefix: string): string;
11
9
  export declare function localizeHref(href: UrlObject | string, locale: string, curLocale: string, curPathname: string, prefix: string): UrlObject | string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-intl",
3
- "version": "3.15.3",
3
+ "version": "3.15.5",
4
4
  "sideEffects": false,
5
5
  "author": "Jan Amann <jan@amann.work>",
6
6
  "funding": [
@@ -87,7 +87,7 @@
87
87
  "dependencies": {
88
88
  "@formatjs/intl-localematcher": "^0.2.32",
89
89
  "negotiator": "^0.6.3",
90
- "use-intl": "^3.15.3"
90
+ "use-intl": "^3.15.5"
91
91
  },
92
92
  "peerDependencies": {
93
93
  "next": "^10.0.0 || ^11.0.0 || ^12.0.0 || ^13.0.0 || ^14.0.0",
@@ -127,5 +127,5 @@
127
127
  "limit": "0 KB"
128
128
  }
129
129
  ],
130
- "gitHead": "5596ae873df9b558a564f7b73da64105da7fb2bb"
130
+ "gitHead": "fba276245b20db29691417609a01ed5f7a9b9fc8"
131
131
  }