gt-next 11.0.13 → 11.1.1

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 (74) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/dist/config.d.ts.map +1 -1
  3. package/dist/config.js +28 -3
  4. package/dist/config.js.map +1 -1
  5. package/dist/config.mjs +28 -3
  6. package/dist/config.mjs.map +1 -1
  7. package/dist/errors/client.d.ts +2 -0
  8. package/dist/errors/client.d.ts.map +1 -0
  9. package/dist/errors/client.js +13 -0
  10. package/dist/errors/client.js.map +1 -0
  11. package/dist/errors/client.mjs +12 -0
  12. package/dist/errors/client.mjs.map +1 -0
  13. package/dist/errors/createErrors.d.ts +0 -6
  14. package/dist/errors/createErrors.d.ts.map +1 -1
  15. package/dist/errors/createErrors.js +0 -41
  16. package/dist/errors/createErrors.js.map +1 -1
  17. package/dist/errors/createErrors.mjs +2 -35
  18. package/dist/errors/createErrors.mjs.map +1 -1
  19. package/dist/errors/loaders.d.ts +3 -0
  20. package/dist/errors/loaders.d.ts.map +1 -0
  21. package/dist/errors/loaders.js +18 -0
  22. package/dist/errors/loaders.js.map +1 -0
  23. package/dist/errors/loaders.mjs +16 -0
  24. package/dist/errors/loaders.mjs.map +1 -0
  25. package/dist/errors/middleware.d.ts +2 -0
  26. package/dist/errors/middleware.d.ts.map +1 -0
  27. package/dist/errors/middleware.js +12 -0
  28. package/dist/errors/middleware.js.map +1 -0
  29. package/dist/errors/middleware.mjs +10 -0
  30. package/dist/errors/middleware.mjs.map +1 -0
  31. package/dist/errors/pathRegex.d.ts +2 -0
  32. package/dist/errors/pathRegex.d.ts.map +1 -0
  33. package/dist/errors/pathRegex.js +15 -0
  34. package/dist/errors/pathRegex.js.map +1 -0
  35. package/dist/errors/pathRegex.mjs +12 -0
  36. package/dist/errors/pathRegex.mjs.map +1 -0
  37. package/dist/errors/request.d.ts +2 -0
  38. package/dist/errors/request.d.ts.map +1 -0
  39. package/dist/errors/request.js +13 -0
  40. package/dist/errors/request.js.map +1 -0
  41. package/dist/errors/request.mjs +12 -0
  42. package/dist/errors/request.mjs.map +1 -0
  43. package/dist/index.client.js +2 -2
  44. package/dist/index.client.js.map +1 -1
  45. package/dist/index.client.mjs +2 -2
  46. package/dist/index.client.mjs.map +1 -1
  47. package/dist/middleware-dir/createNextMiddleware.js +2 -2
  48. package/dist/middleware-dir/createNextMiddleware.js.map +1 -1
  49. package/dist/middleware-dir/createNextMiddleware.mjs +1 -1
  50. package/dist/middleware-dir/createNextMiddleware.mjs.map +1 -1
  51. package/dist/request/localeValidation.js +2 -2
  52. package/dist/request/localeValidation.js.map +1 -1
  53. package/dist/request/localeValidation.mjs +1 -1
  54. package/dist/request/localeValidation.mjs.map +1 -1
  55. package/dist/resolvers/resolveDictionaryLoader.d.ts.map +1 -1
  56. package/dist/resolvers/resolveDictionaryLoader.js +4 -3
  57. package/dist/resolvers/resolveDictionaryLoader.js.map +1 -1
  58. package/dist/resolvers/resolveDictionaryLoader.mjs +2 -1
  59. package/dist/resolvers/resolveDictionaryLoader.mjs.map +1 -1
  60. package/dist/resolvers/resolveTranslationLoader.d.ts.map +1 -1
  61. package/dist/resolvers/resolveTranslationLoader.js +4 -3
  62. package/dist/resolvers/resolveTranslationLoader.js.map +1 -1
  63. package/dist/resolvers/resolveTranslationLoader.mjs +2 -1
  64. package/dist/resolvers/resolveTranslationLoader.mjs.map +1 -1
  65. package/dist/setup/shared.d.ts.map +1 -1
  66. package/dist/setup/shared.js +18 -19
  67. package/dist/setup/shared.js.map +1 -1
  68. package/dist/setup/shared.mjs +18 -19
  69. package/dist/setup/shared.mjs.map +1 -1
  70. package/dist/utils/pathRegex.js +2 -2
  71. package/dist/utils/pathRegex.js.map +1 -1
  72. package/dist/utils/pathRegex.mjs +1 -1
  73. package/dist/utils/pathRegex.mjs.map +1 -1
  74. package/package.json +8 -8
@@ -2,8 +2,8 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  require("../_virtual/_rolldown/runtime.js");
3
3
  require("../utils/headers.js");
4
4
  require("../utils/cookies.js");
5
- const require_errors_createErrors = require("../errors/createErrors.js");
6
5
  const require_utils_pathRegex = require("../utils/pathRegex.js");
6
+ const require_errors_middleware = require("../errors/middleware.js");
7
7
  const require_middleware_dir_utils = require("./utils.js");
8
8
  let generaltranslation_internal = require("generaltranslation/internal");
9
9
  let _generaltranslation_react_core_pure = require("@generaltranslation/react-core/pure");
@@ -48,7 +48,7 @@ function createNextMiddleware({ localeRouting = true, prefixDefaultLocale = fals
48
48
  const localeHeaderName = headersAndCookies?.localeHeaderName || "x-generaltranslation-locale";
49
49
  if (!gt.isValidLocale(defaultLocale)) throw new Error(`gt-next middleware: defaultLocale "${defaultLocale}" is not a valid locale.`);
50
50
  const warningLocales = locales.filter((locale) => !gt.isValidLocale(locale));
51
- if (warningLocales.length) console.warn(require_errors_createErrors.createUnsupportedLocalesWarning(warningLocales));
51
+ if (warningLocales.length) console.warn(require_errors_middleware.createUnsupportedLocalesWarning(warningLocales));
52
52
  pathConfig = Object.entries(pathConfig).reduce((acc, [sharedPath, localizedPath]) => {
53
53
  if (typeof localizedPath === "string") acc[sharedPath] = localizedPath;
54
54
  else acc[sharedPath] = Object.entries(localizedPath).reduce((acc, [locale, localizedPath]) => {
@@ -1 +1 @@
1
- {"version":3,"file":"createNextMiddleware.js","names":["compilePathRegex","GTRuntime","libraryDefaultLocale","defaultLocaleCookieName","defaultResetLocaleCookieName","createUnsupportedLocalesWarning","createPathToSharedPathMap","pathnameMatchesRegex","NextResponse","getLocaleFromRequest","getResponse","getSharedPath","replaceDynamicSegments","getLocalizedPath"],"sources":["../../src/middleware-dir/createNextMiddleware.ts"],"sourcesContent":["import { isSameDialect, standardizeLocale } from '@generaltranslation/format';\nimport { GTRuntime } from 'generaltranslation/runtime';\nimport { libraryDefaultLocale } from 'generaltranslation/internal';\nimport { createUnsupportedLocalesWarning } from '../errors/createErrors';\nimport { NextRequest, NextResponse } from 'next/server';\nimport {\n defaultLocaleRoutingEnabledCookieName,\n defaultReferrerLocaleCookieName,\n} from '../utils/cookies';\nimport {\n defaultLocaleCookieName,\n defaultResetLocaleCookieName,\n} from '@generaltranslation/react-core/pure';\nimport {\n PathConfig,\n getSharedPath,\n replaceDynamicSegments,\n getLocalizedPath,\n createPathToSharedPathMap,\n getLocaleFromRequest,\n getResponse,\n ResponseConfig,\n} from './utils';\nimport { defaultLocaleHeaderName } from '../utils/headers';\nimport type { CustomMapping } from '@generaltranslation/format/types';\nimport type { HeadersAndCookies } from '../config-dir/props/withGTConfigProps';\nimport { compilePathRegex, pathnameMatchesRegex } from '../utils/pathRegex';\n\nconst NEXT_JS_SOURCE_MAP_PATH = '/__nextjs_source-map';\n\ntype MiddlewareEnvConfig = {\n customMapping?: CustomMapping;\n defaultLocale?: string;\n locales?: string[];\n headersAndCookies?: HeadersAndCookies;\n};\n\n/**\n * Middleware factory to create a Next.js middleware for i18n routing and locale detection.\n *\n * This middleware sets a cookie based on the locale derived from several sources\n * such as the request pathname, referer, or 'Accept-Language' header.\n * If locale routing is enabled, it redirects to the localized pathname and\n * updates the locale cookie.\n *\n * @param {boolean} [config.localeRouting=true] - Flag to enable or disable automatic locale-based routing.\n * @param {boolean} [config.prefixDefaultLocale=false] - Flag to enable or disable prefixing the default locale to the pathname, i.e., /en/about -> /about\n * @param {boolean} [config.ignoreSourceMaps=true] - Flag to enable or disable ignoring source maps\n * @param {PathConfig} [config.pathConfig] - Path configuration for locale routing\n * @returns {function} - A middleware function that processes the request and response.\n */\nexport function createNextMiddleware({\n localeRouting = true,\n prefixDefaultLocale = false,\n ignoreSourceMaps = true,\n pathConfig = {},\n}: {\n localeRouting?: boolean;\n prefixDefaultLocale?: boolean;\n ignoreSourceMaps?: boolean;\n pathConfig?: PathConfig;\n} = {}) {\n const pathRegex = compilePathRegex(\n process.env._GENERALTRANSLATION_PATH_REGEX\n );\n\n // i18n config\n let envParams: MiddlewareEnvConfig | undefined;\n if (process.env._GENERALTRANSLATION_I18N_CONFIG_PARAMS) {\n try {\n envParams = JSON.parse(\n process.env._GENERALTRANSLATION_I18N_CONFIG_PARAMS\n );\n } catch (error) {\n console.error(`gt-next middleware:`, error);\n }\n }\n\n // gt instance\n const gt = new GTRuntime({\n customMapping: envParams?.customMapping,\n });\n\n // using gt services\n const gtServicesEnabled =\n process.env._GENERALTRANSLATION_GT_SERVICES_ENABLED === 'true';\n\n // i18n config\n const defaultLocale: string =\n envParams?.defaultLocale || libraryDefaultLocale;\n const locales: string[] = envParams?.locales || [defaultLocale];\n\n // add canonical locales\n const canonicalLocales = Object.values(envParams?.customMapping || {})\n .filter(\n (locale): locale is { code: string } =>\n typeof locale === 'object' &&\n locale !== null &&\n 'code' in locale &&\n typeof locale.code === 'string' &&\n locale.code.length > 0\n )\n .map((locale) => locale.code);\n locales.push(...canonicalLocales);\n\n // cookies and header names\n const headersAndCookies = envParams?.headersAndCookies || {};\n const localeRoutingEnabledCookieName =\n headersAndCookies?.localeRoutingEnabledCookieName ||\n defaultLocaleRoutingEnabledCookieName;\n const referrerLocaleCookieName =\n headersAndCookies?.referrerLocaleCookieName ||\n defaultReferrerLocaleCookieName;\n const localeCookieName =\n headersAndCookies?.localeCookieName || defaultLocaleCookieName;\n const resetLocaleCookieName =\n headersAndCookies?.resetLocaleCookieName || defaultResetLocaleCookieName;\n const localeHeaderName =\n headersAndCookies?.localeHeaderName || defaultLocaleHeaderName;\n\n if (!gt.isValidLocale(defaultLocale))\n throw new Error(\n `gt-next middleware: defaultLocale \"${defaultLocale}\" is not a valid locale.`\n );\n\n const warningLocales = locales.filter((locale) => !gt.isValidLocale(locale));\n if (warningLocales.length)\n console.warn(createUnsupportedLocalesWarning(warningLocales));\n\n // ---------- PRE-PROCESSING PATHS ---------- //\n\n // Standardize pathConfig paths\n pathConfig = Object.entries(pathConfig).reduce<PathConfig>(\n (acc, [sharedPath, localizedPath]) => {\n if (typeof localizedPath === 'string') {\n acc[sharedPath] = localizedPath;\n } else {\n acc[sharedPath] = Object.entries(localizedPath).reduce<{\n [key: string]: string;\n }>((acc, [locale, localizedPath]) => {\n acc[gtServicesEnabled ? standardizeLocale(locale) : locale] =\n localizedPath;\n return acc;\n }, {});\n }\n return acc;\n },\n {}\n );\n\n // Create the path mapping\n const { pathToSharedPath, defaultLocalePaths } = createPathToSharedPathMap(\n pathConfig,\n prefixDefaultLocale,\n defaultLocale\n );\n\n /**\n * Processes the incoming request to determine the user's locale and sets a locale cookie.\n * Optionally redirects the user based on the locale if locale-based routing is enabled.\n *\n * - Checks if the request URL contains a locale.\n * - Falls back to the referer URL for locale if needed.\n * - If no locale is found in the URL or referer, it checks the 'Accept-Language' header.\n * - Sets a cookie with the detected or default locale.\n * - Redirects to the correct locale route if locale routing is enabled.\n *\n * @param {NextRequest} req - The incoming request object, containing URL and headers.\n * @returns {NextResponse} - The Next.js response, either continuing the request or redirecting to the localized URL.\n */\n function middleware(req: NextRequest) {\n if (!pathnameMatchesRegex(req.nextUrl.pathname, pathRegex)) {\n return NextResponse.next();\n }\n\n // Ignore source maps\n if (\n ignoreSourceMaps &&\n req.nextUrl.pathname.startsWith(NEXT_JS_SOURCE_MAP_PATH)\n ) {\n return NextResponse.next();\n }\n\n // ---------- LOCALE DETECTION ---------- //\n\n const {\n userLocale,\n pathnameLocale,\n unstandardizedPathnameLocale,\n clearResetCookie,\n } = getLocaleFromRequest(\n req,\n defaultLocale,\n locales,\n localeRouting,\n gtServicesEnabled,\n prefixDefaultLocale,\n defaultLocalePaths,\n referrerLocaleCookieName,\n localeCookieName,\n resetLocaleCookieName,\n gt\n );\n\n const headerList = new Headers(req.headers);\n\n const responseConfig: Omit<ResponseConfig, 'type'> = {\n originalUrl: req.nextUrl,\n headerList,\n userLocale,\n clearResetCookie,\n localeRouting,\n localeRoutingEnabledCookieName,\n resetLocaleCookieName,\n localeHeaderName,\n };\n\n const getRewriteResponse = (responsePath: string) =>\n getResponse({ responsePath, type: 'rewrite', ...responseConfig });\n\n const getRedirectResponse = (responsePath: string) =>\n getResponse({ responsePath, type: 'redirect', ...responseConfig });\n\n const getNextResponse = () =>\n getResponse({ type: 'next', ...responseConfig });\n\n if (localeRouting) {\n // ---------- GET PATHS ---------- //\n\n // get pathname\n const { pathname } = req.nextUrl;\n\n // standardize pathname (ie, /tg/welcome -> /fil/welcome), (/blog -> /blog)\n const standardizedPathname =\n pathnameLocale && pathnameLocale !== unstandardizedPathnameLocale\n ? pathname.replace(\n new RegExp(`^/${unstandardizedPathnameLocale}`),\n `/${userLocale}`\n )\n : pathname;\n\n // Get the shared path for the unprefixed pathname\n const sharedPath = getSharedPath(\n standardizedPathname,\n pathToSharedPath,\n pathnameLocale\n );\n\n // Get shared path with parameters (/en/dashboard/1/custom), for rewriting localized paths\n const sharedPathWithParameters =\n sharedPath !== undefined\n ? replaceDynamicSegments(\n pathnameLocale\n ? standardizedPathname\n : `/${userLocale}${standardizedPathname}`,\n `/${userLocale}${sharedPath}`\n )\n : undefined;\n\n // Localized path (/en/blog, /fr/fr-about, /fr/dashboard/[id]/custom)\n const localizedPath =\n sharedPath !== undefined\n ? getLocalizedPath(sharedPath, userLocale, pathConfig)\n : undefined;\n\n // Combine localized path with dynamic parameters (/en/blog, /fr/fr-about, /fr/dashboard/1/fr-custom)\n const localizedPathWithParameters =\n localizedPath !== undefined\n ? replaceDynamicSegments(\n pathnameLocale\n ? standardizedPathname\n : `/${userLocale}${standardizedPathname}`,\n localizedPath\n )\n : undefined;\n\n // ---------- ROUTING LOGIC ---------- //\n\n // ----- CASE: no localized path exists ----- //\n\n if (localizedPathWithParameters === undefined) {\n // --- CASE: remove defaultLocale prefix --- //\n\n if (!prefixDefaultLocale && isSameDialect(userLocale, defaultLocale)) {\n if (pathnameLocale) {\n // REDIRECT CASE: used setLocale (/fr/customers -> /customers) (/en/customers -> /customers)\n if (clearResetCookie) {\n return getRedirectResponse(\n pathname.replace(\n new RegExp(`^/${unstandardizedPathnameLocale}`),\n ``\n ) || '/'\n );\n }\n } else {\n // REWRITE CASE: no pathnameLocale (/customers -> /en/customers)\n return getRewriteResponse(`/${userLocale}${pathname}`);\n }\n }\n\n // --- CASE: defaultLocale prefix --- //\n // REDIRECT CASE: no pathnameLocale (ie, /customers -> /fr/customers)\n else if (!pathnameLocale) {\n return getRedirectResponse(`/${userLocale}${pathname}`);\n }\n\n // REDIRECT CASE: wrong pathnameLocale (ie, /fr/customers -> /en/customers) (this usually happens after a locale switch)\n if (pathnameLocale && userLocale !== unstandardizedPathnameLocale) {\n return getRedirectResponse(\n pathname.replace(\n new RegExp(`^/${unstandardizedPathnameLocale}`),\n `/${userLocale}`\n )\n );\n }\n\n // BASE CASE: has pathnameLocale and it's correct\n return getNextResponse();\n }\n\n // ----- CASE: localized path exists ----- //\n\n if (!prefixDefaultLocale && isSameDialect(userLocale, defaultLocale)) {\n // --- CASE: remove defaultLocale prefix --- //\n\n if (pathnameLocale) {\n // REDIRECT CASE: remove locale prefix when setLocale is used (/en/blog -> /blog) (/fr/fr-about -> /en-about)\n if (clearResetCookie) {\n return getRedirectResponse(\n localizedPathWithParameters.replace(\n new RegExp(`^/${unstandardizedPathnameLocale}`),\n ``\n ) || '/'\n );\n }\n } else {\n // REDIRECT CASE: unprefixed pathname is wrong (/about -> /en-about)\n if (\n !pathnameLocale &&\n localizedPathWithParameters !== `/${userLocale}${pathname}`\n ) {\n return getRedirectResponse(\n localizedPathWithParameters.replace(\n new RegExp(`^/${userLocale}`),\n ''\n ) || '/'\n );\n }\n\n // REWRITE CASE: displaying correct path (/blog -> /en/blog)\n return getRewriteResponse(sharedPathWithParameters as string);\n }\n }\n\n // --- CASE: add defaultLocale prefix --- //\n\n // REDIRECT CASE: incorrect pathnameLocale\n if (pathname !== localizedPathWithParameters) {\n return getRedirectResponse(localizedPathWithParameters);\n }\n\n // REWRITE CASE: displaying correct localized path, which is the same as the shared path (/fil/blog => /fil/blog) (/fr/fr-dashboard/1/fr-custom => /fr/dashboard/1/custom)\n if (\n standardizedPathname !== sharedPathWithParameters // no rewrite needed if it's already the shared path\n ) {\n // convert to shared path with dynamic parameters\n return getRewriteResponse(sharedPathWithParameters as string);\n }\n }\n\n // BASE CASE\n return getNextResponse();\n }\n\n return middleware;\n}\n"],"mappings":";;;;;;;;;;;;;AA4BA,MAAM,0BAA0B;;;;;;;;;;;;;;;AAuBhC,SAAgB,qBAAqB,EACnC,gBAAgB,MAChB,sBAAsB,OACtB,mBAAmB,MACnB,aAAa,EAAE,KAMb,EAAE,EAAE;CACN,MAAM,YAAYA,wBAAAA,iBAChB,QAAQ,IAAI,+BACb;CAGD,IAAI;AACJ,KAAI,QAAQ,IAAI,uCACd,KAAI;AACF,cAAY,KAAK,MACf,QAAQ,IAAI,uCACb;UACM,OAAO;AACd,UAAQ,MAAM,uBAAuB,MAAM;;CAK/C,MAAM,KAAK,IAAIC,2BAAAA,UAAU,EACvB,eAAe,WAAW,eAC3B,CAAC;CAGF,MAAM,oBACJ,QAAQ,IAAI,4CAA4C;CAG1D,MAAM,gBACJ,WAAW,iBAAiBC,4BAAAA;CAC9B,MAAM,UAAoB,WAAW,WAAW,CAAC,cAAc;CAG/D,MAAM,mBAAmB,OAAO,OAAO,WAAW,iBAAiB,EAAE,CAAC,CACnE,QACE,WACC,OAAO,WAAW,YAClB,WAAW,QACX,UAAU,UACV,OAAO,OAAO,SAAS,YACvB,OAAO,KAAK,SAAS,EACxB,CACA,KAAK,WAAW,OAAO,KAAK;AAC/B,SAAQ,KAAK,GAAG,iBAAiB;CAGjC,MAAM,oBAAoB,WAAW,qBAAqB,EAAE;CAC5D,MAAM,iCACJ,mBAAmB,kCAAA;CAErB,MAAM,2BACJ,mBAAmB,4BAAA;CAErB,MAAM,mBACJ,mBAAmB,oBAAoBC,oCAAAA;CACzC,MAAM,wBACJ,mBAAmB,yBAAyBC,oCAAAA;CAC9C,MAAM,mBACJ,mBAAmB,oBAAA;AAErB,KAAI,CAAC,GAAG,cAAc,cAAc,CAClC,OAAM,IAAI,MACR,sCAAsC,cAAc,0BACrD;CAEH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Aa,4BACf,QAAO,oBAAoB,4BAA4B;AAIzD,OACE,yBAAyB,yBAGzB,QAAO,mBAAmB,yBAAmC;;AAKjE,SAAO,iBAAiB;;AAG1B,QAAO"}
1
+ {"version":3,"file":"createNextMiddleware.js","names":["compilePathRegex","GTRuntime","libraryDefaultLocale","defaultLocaleCookieName","defaultResetLocaleCookieName","createUnsupportedLocalesWarning","createPathToSharedPathMap","pathnameMatchesRegex","NextResponse","getLocaleFromRequest","getResponse","getSharedPath","replaceDynamicSegments","getLocalizedPath"],"sources":["../../src/middleware-dir/createNextMiddleware.ts"],"sourcesContent":["import { isSameDialect, standardizeLocale } from '@generaltranslation/format';\nimport { GTRuntime } from 'generaltranslation/runtime';\nimport { libraryDefaultLocale } from 'generaltranslation/internal';\nimport { createUnsupportedLocalesWarning } from '../errors/middleware';\nimport { NextRequest, NextResponse } from 'next/server';\nimport {\n defaultLocaleRoutingEnabledCookieName,\n defaultReferrerLocaleCookieName,\n} from '../utils/cookies';\nimport {\n defaultLocaleCookieName,\n defaultResetLocaleCookieName,\n} from '@generaltranslation/react-core/pure';\nimport {\n PathConfig,\n getSharedPath,\n replaceDynamicSegments,\n getLocalizedPath,\n createPathToSharedPathMap,\n getLocaleFromRequest,\n getResponse,\n ResponseConfig,\n} from './utils';\nimport { defaultLocaleHeaderName } from '../utils/headers';\nimport type { CustomMapping } from '@generaltranslation/format/types';\nimport type { HeadersAndCookies } from '../config-dir/props/withGTConfigProps';\nimport { compilePathRegex, pathnameMatchesRegex } from '../utils/pathRegex';\n\nconst NEXT_JS_SOURCE_MAP_PATH = '/__nextjs_source-map';\n\ntype MiddlewareEnvConfig = {\n customMapping?: CustomMapping;\n defaultLocale?: string;\n locales?: string[];\n headersAndCookies?: HeadersAndCookies;\n};\n\n/**\n * Middleware factory to create a Next.js middleware for i18n routing and locale detection.\n *\n * This middleware sets a cookie based on the locale derived from several sources\n * such as the request pathname, referer, or 'Accept-Language' header.\n * If locale routing is enabled, it redirects to the localized pathname and\n * updates the locale cookie.\n *\n * @param {boolean} [config.localeRouting=true] - Flag to enable or disable automatic locale-based routing.\n * @param {boolean} [config.prefixDefaultLocale=false] - Flag to enable or disable prefixing the default locale to the pathname, i.e., /en/about -> /about\n * @param {boolean} [config.ignoreSourceMaps=true] - Flag to enable or disable ignoring source maps\n * @param {PathConfig} [config.pathConfig] - Path configuration for locale routing\n * @returns {function} - A middleware function that processes the request and response.\n */\nexport function createNextMiddleware({\n localeRouting = true,\n prefixDefaultLocale = false,\n ignoreSourceMaps = true,\n pathConfig = {},\n}: {\n localeRouting?: boolean;\n prefixDefaultLocale?: boolean;\n ignoreSourceMaps?: boolean;\n pathConfig?: PathConfig;\n} = {}) {\n const pathRegex = compilePathRegex(\n process.env._GENERALTRANSLATION_PATH_REGEX\n );\n\n // i18n config\n let envParams: MiddlewareEnvConfig | undefined;\n if (process.env._GENERALTRANSLATION_I18N_CONFIG_PARAMS) {\n try {\n envParams = JSON.parse(\n process.env._GENERALTRANSLATION_I18N_CONFIG_PARAMS\n );\n } catch (error) {\n console.error(`gt-next middleware:`, error);\n }\n }\n\n // gt instance\n const gt = new GTRuntime({\n customMapping: envParams?.customMapping,\n });\n\n // using gt services\n const gtServicesEnabled =\n process.env._GENERALTRANSLATION_GT_SERVICES_ENABLED === 'true';\n\n // i18n config\n const defaultLocale: string =\n envParams?.defaultLocale || libraryDefaultLocale;\n const locales: string[] = envParams?.locales || [defaultLocale];\n\n // add canonical locales\n const canonicalLocales = Object.values(envParams?.customMapping || {})\n .filter(\n (locale): locale is { code: string } =>\n typeof locale === 'object' &&\n locale !== null &&\n 'code' in locale &&\n typeof locale.code === 'string' &&\n locale.code.length > 0\n )\n .map((locale) => locale.code);\n locales.push(...canonicalLocales);\n\n // cookies and header names\n const headersAndCookies = envParams?.headersAndCookies || {};\n const localeRoutingEnabledCookieName =\n headersAndCookies?.localeRoutingEnabledCookieName ||\n defaultLocaleRoutingEnabledCookieName;\n const referrerLocaleCookieName =\n headersAndCookies?.referrerLocaleCookieName ||\n defaultReferrerLocaleCookieName;\n const localeCookieName =\n headersAndCookies?.localeCookieName || defaultLocaleCookieName;\n const resetLocaleCookieName =\n headersAndCookies?.resetLocaleCookieName || defaultResetLocaleCookieName;\n const localeHeaderName =\n headersAndCookies?.localeHeaderName || defaultLocaleHeaderName;\n\n if (!gt.isValidLocale(defaultLocale))\n throw new Error(\n `gt-next middleware: defaultLocale \"${defaultLocale}\" is not a valid locale.`\n );\n\n const warningLocales = locales.filter((locale) => !gt.isValidLocale(locale));\n if (warningLocales.length)\n console.warn(createUnsupportedLocalesWarning(warningLocales));\n\n // ---------- PRE-PROCESSING PATHS ---------- //\n\n // Standardize pathConfig paths\n pathConfig = Object.entries(pathConfig).reduce<PathConfig>(\n (acc, [sharedPath, localizedPath]) => {\n if (typeof localizedPath === 'string') {\n acc[sharedPath] = localizedPath;\n } else {\n acc[sharedPath] = Object.entries(localizedPath).reduce<{\n [key: string]: string;\n }>((acc, [locale, localizedPath]) => {\n acc[gtServicesEnabled ? standardizeLocale(locale) : locale] =\n localizedPath;\n return acc;\n }, {});\n }\n return acc;\n },\n {}\n );\n\n // Create the path mapping\n const { pathToSharedPath, defaultLocalePaths } = createPathToSharedPathMap(\n pathConfig,\n prefixDefaultLocale,\n defaultLocale\n );\n\n /**\n * Processes the incoming request to determine the user's locale and sets a locale cookie.\n * Optionally redirects the user based on the locale if locale-based routing is enabled.\n *\n * - Checks if the request URL contains a locale.\n * - Falls back to the referer URL for locale if needed.\n * - If no locale is found in the URL or referer, it checks the 'Accept-Language' header.\n * - Sets a cookie with the detected or default locale.\n * - Redirects to the correct locale route if locale routing is enabled.\n *\n * @param {NextRequest} req - The incoming request object, containing URL and headers.\n * @returns {NextResponse} - The Next.js response, either continuing the request or redirecting to the localized URL.\n */\n function middleware(req: NextRequest) {\n if (!pathnameMatchesRegex(req.nextUrl.pathname, pathRegex)) {\n return NextResponse.next();\n }\n\n // Ignore source maps\n if (\n ignoreSourceMaps &&\n req.nextUrl.pathname.startsWith(NEXT_JS_SOURCE_MAP_PATH)\n ) {\n return NextResponse.next();\n }\n\n // ---------- LOCALE DETECTION ---------- //\n\n const {\n userLocale,\n pathnameLocale,\n unstandardizedPathnameLocale,\n clearResetCookie,\n } = getLocaleFromRequest(\n req,\n defaultLocale,\n locales,\n localeRouting,\n gtServicesEnabled,\n prefixDefaultLocale,\n defaultLocalePaths,\n referrerLocaleCookieName,\n localeCookieName,\n resetLocaleCookieName,\n gt\n );\n\n const headerList = new Headers(req.headers);\n\n const responseConfig: Omit<ResponseConfig, 'type'> = {\n originalUrl: req.nextUrl,\n headerList,\n userLocale,\n clearResetCookie,\n localeRouting,\n localeRoutingEnabledCookieName,\n resetLocaleCookieName,\n localeHeaderName,\n };\n\n const getRewriteResponse = (responsePath: string) =>\n getResponse({ responsePath, type: 'rewrite', ...responseConfig });\n\n const getRedirectResponse = (responsePath: string) =>\n getResponse({ responsePath, type: 'redirect', ...responseConfig });\n\n const getNextResponse = () =>\n getResponse({ type: 'next', ...responseConfig });\n\n if (localeRouting) {\n // ---------- GET PATHS ---------- //\n\n // get pathname\n const { pathname } = req.nextUrl;\n\n // standardize pathname (ie, /tg/welcome -> /fil/welcome), (/blog -> /blog)\n const standardizedPathname =\n pathnameLocale && pathnameLocale !== unstandardizedPathnameLocale\n ? pathname.replace(\n new RegExp(`^/${unstandardizedPathnameLocale}`),\n `/${userLocale}`\n )\n : pathname;\n\n // Get the shared path for the unprefixed pathname\n const sharedPath = getSharedPath(\n standardizedPathname,\n pathToSharedPath,\n pathnameLocale\n );\n\n // Get shared path with parameters (/en/dashboard/1/custom), for rewriting localized paths\n const sharedPathWithParameters =\n sharedPath !== undefined\n ? replaceDynamicSegments(\n pathnameLocale\n ? standardizedPathname\n : `/${userLocale}${standardizedPathname}`,\n `/${userLocale}${sharedPath}`\n )\n : undefined;\n\n // Localized path (/en/blog, /fr/fr-about, /fr/dashboard/[id]/custom)\n const localizedPath =\n sharedPath !== undefined\n ? getLocalizedPath(sharedPath, userLocale, pathConfig)\n : undefined;\n\n // Combine localized path with dynamic parameters (/en/blog, /fr/fr-about, /fr/dashboard/1/fr-custom)\n const localizedPathWithParameters =\n localizedPath !== undefined\n ? replaceDynamicSegments(\n pathnameLocale\n ? standardizedPathname\n : `/${userLocale}${standardizedPathname}`,\n localizedPath\n )\n : undefined;\n\n // ---------- ROUTING LOGIC ---------- //\n\n // ----- CASE: no localized path exists ----- //\n\n if (localizedPathWithParameters === undefined) {\n // --- CASE: remove defaultLocale prefix --- //\n\n if (!prefixDefaultLocale && isSameDialect(userLocale, defaultLocale)) {\n if (pathnameLocale) {\n // REDIRECT CASE: used setLocale (/fr/customers -> /customers) (/en/customers -> /customers)\n if (clearResetCookie) {\n return getRedirectResponse(\n pathname.replace(\n new RegExp(`^/${unstandardizedPathnameLocale}`),\n ``\n ) || '/'\n );\n }\n } else {\n // REWRITE CASE: no pathnameLocale (/customers -> /en/customers)\n return getRewriteResponse(`/${userLocale}${pathname}`);\n }\n }\n\n // --- CASE: defaultLocale prefix --- //\n // REDIRECT CASE: no pathnameLocale (ie, /customers -> /fr/customers)\n else if (!pathnameLocale) {\n return getRedirectResponse(`/${userLocale}${pathname}`);\n }\n\n // REDIRECT CASE: wrong pathnameLocale (ie, /fr/customers -> /en/customers) (this usually happens after a locale switch)\n if (pathnameLocale && userLocale !== unstandardizedPathnameLocale) {\n return getRedirectResponse(\n pathname.replace(\n new RegExp(`^/${unstandardizedPathnameLocale}`),\n `/${userLocale}`\n )\n );\n }\n\n // BASE CASE: has pathnameLocale and it's correct\n return getNextResponse();\n }\n\n // ----- CASE: localized path exists ----- //\n\n if (!prefixDefaultLocale && isSameDialect(userLocale, defaultLocale)) {\n // --- CASE: remove defaultLocale prefix --- //\n\n if (pathnameLocale) {\n // REDIRECT CASE: remove locale prefix when setLocale is used (/en/blog -> /blog) (/fr/fr-about -> /en-about)\n if (clearResetCookie) {\n return getRedirectResponse(\n localizedPathWithParameters.replace(\n new RegExp(`^/${unstandardizedPathnameLocale}`),\n ``\n ) || '/'\n );\n }\n } else {\n // REDIRECT CASE: unprefixed pathname is wrong (/about -> /en-about)\n if (\n !pathnameLocale &&\n localizedPathWithParameters !== `/${userLocale}${pathname}`\n ) {\n return getRedirectResponse(\n localizedPathWithParameters.replace(\n new RegExp(`^/${userLocale}`),\n ''\n ) || '/'\n );\n }\n\n // REWRITE CASE: displaying correct path (/blog -> /en/blog)\n return getRewriteResponse(sharedPathWithParameters as string);\n }\n }\n\n // --- CASE: add defaultLocale prefix --- //\n\n // REDIRECT CASE: incorrect pathnameLocale\n if (pathname !== localizedPathWithParameters) {\n return getRedirectResponse(localizedPathWithParameters);\n }\n\n // REWRITE CASE: displaying correct localized path, which is the same as the shared path (/fil/blog => /fil/blog) (/fr/fr-dashboard/1/fr-custom => /fr/dashboard/1/custom)\n if (\n standardizedPathname !== sharedPathWithParameters // no rewrite needed if it's already the shared path\n ) {\n // convert to shared path with dynamic parameters\n return getRewriteResponse(sharedPathWithParameters as string);\n }\n }\n\n // BASE CASE\n return getNextResponse();\n }\n\n return middleware;\n}\n"],"mappings":";;;;;;;;;;;;;AA4BA,MAAM,0BAA0B;;;;;;;;;;;;;;;AAuBhC,SAAgB,qBAAqB,EACnC,gBAAgB,MAChB,sBAAsB,OACtB,mBAAmB,MACnB,aAAa,EAAE,KAMb,EAAE,EAAE;CACN,MAAM,YAAYA,wBAAAA,iBAChB,QAAQ,IAAI,+BACb;CAGD,IAAI;AACJ,KAAI,QAAQ,IAAI,uCACd,KAAI;AACF,cAAY,KAAK,MACf,QAAQ,IAAI,uCACb;UACM,OAAO;AACd,UAAQ,MAAM,uBAAuB,MAAM;;CAK/C,MAAM,KAAK,IAAIC,2BAAAA,UAAU,EACvB,eAAe,WAAW,eAC3B,CAAC;CAGF,MAAM,oBACJ,QAAQ,IAAI,4CAA4C;CAG1D,MAAM,gBACJ,WAAW,iBAAiBC,4BAAAA;CAC9B,MAAM,UAAoB,WAAW,WAAW,CAAC,cAAc;CAG/D,MAAM,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AmB,IAAI,aAAa,WAAW;aAMjD,CAAC,eACR,QAAO,oBAAoB,IAAI,aAAa,WAAW;AAIzD,QAAI,kBAAkB,eAAe,6BACnC,QAAO,oBACL,SAAS,QACP,IAAI,OAAO,KAAK,+BAA+B,EAC/C,IAAI,aACL,CACF;AAIH,WAAO,iBAAiB;;AAK1B,OAAI,CAAC,wBAAA,GAAA,2BAAA,eAAqC,YAAY,cAAc,CAGlE,KAAI;QAEE,iBACF,QAAO,oBACL,4BAA4B,QAC1B,IAAI,OAAO,KAAK,+BAA+B,EAC/C,GACD,IAAI,IACN;UAEE;AAEL,QACE,CAAC,kBACD,gCAAgC,IAAI,aAAa,WAEjD,QAAO,oBACL,4BAA4B,QAC1B,IAAI,OAAO,KAAK,aAAa,EAC7B,GACD,IAAI,IACN;AAIH,WAAO,mBAAmB,yBAAmC;;AAOjE,OAAI,aAAa,4BACf,QAAO,oBAAoB,4BAA4B;AAIzD,OACE,yBAAyB,yBAGzB,QAAO,mBAAmB,yBAAmC;;AAKjE,SAAO,iBAAiB;;AAG1B,QAAO"}
@@ -1,7 +1,7 @@
1
1
  import "../utils/headers.mjs";
2
2
  import "../utils/cookies.mjs";
3
- import { createUnsupportedLocalesWarning } from "../errors/createErrors.mjs";
4
3
  import { compilePathRegex, pathnameMatchesRegex } from "../utils/pathRegex.mjs";
4
+ import { createUnsupportedLocalesWarning } from "../errors/middleware.mjs";
5
5
  import { createPathToSharedPathMap, getLocaleFromRequest, getLocalizedPath, getResponse, getSharedPath, replaceDynamicSegments } from "./utils.mjs";
6
6
  import { libraryDefaultLocale } from "generaltranslation/internal";
7
7
  import { defaultLocaleCookieName, defaultResetLocaleCookieName } from "@generaltranslation/react-core/pure";
@@ -1 +1 @@
1
- {"version":3,"file":"createNextMiddleware.mjs","names":[],"sources":["../../src/middleware-dir/createNextMiddleware.ts"],"sourcesContent":["import { isSameDialect, standardizeLocale } from '@generaltranslation/format';\nimport { GTRuntime } from 'generaltranslation/runtime';\nimport { libraryDefaultLocale } from 'generaltranslation/internal';\nimport { createUnsupportedLocalesWarning } from '../errors/createErrors';\nimport { NextRequest, NextResponse } from 'next/server';\nimport {\n defaultLocaleRoutingEnabledCookieName,\n defaultReferrerLocaleCookieName,\n} from '../utils/cookies';\nimport {\n defaultLocaleCookieName,\n defaultResetLocaleCookieName,\n} from '@generaltranslation/react-core/pure';\nimport {\n PathConfig,\n getSharedPath,\n replaceDynamicSegments,\n getLocalizedPath,\n createPathToSharedPathMap,\n getLocaleFromRequest,\n getResponse,\n ResponseConfig,\n} from './utils';\nimport { defaultLocaleHeaderName } from '../utils/headers';\nimport type { CustomMapping } from '@generaltranslation/format/types';\nimport type { HeadersAndCookies } from '../config-dir/props/withGTConfigProps';\nimport { compilePathRegex, pathnameMatchesRegex } from '../utils/pathRegex';\n\nconst NEXT_JS_SOURCE_MAP_PATH = '/__nextjs_source-map';\n\ntype MiddlewareEnvConfig = {\n customMapping?: CustomMapping;\n defaultLocale?: string;\n locales?: string[];\n headersAndCookies?: HeadersAndCookies;\n};\n\n/**\n * Middleware factory to create a Next.js middleware for i18n routing and locale detection.\n *\n * This middleware sets a cookie based on the locale derived from several sources\n * such as the request pathname, referer, or 'Accept-Language' header.\n * If locale routing is enabled, it redirects to the localized pathname and\n * updates the locale cookie.\n *\n * @param {boolean} [config.localeRouting=true] - Flag to enable or disable automatic locale-based routing.\n * @param {boolean} [config.prefixDefaultLocale=false] - Flag to enable or disable prefixing the default locale to the pathname, i.e., /en/about -> /about\n * @param {boolean} [config.ignoreSourceMaps=true] - Flag to enable or disable ignoring source maps\n * @param {PathConfig} [config.pathConfig] - Path configuration for locale routing\n * @returns {function} - A middleware function that processes the request and response.\n */\nexport function createNextMiddleware({\n localeRouting = true,\n prefixDefaultLocale = false,\n ignoreSourceMaps = true,\n pathConfig = {},\n}: {\n localeRouting?: boolean;\n prefixDefaultLocale?: boolean;\n ignoreSourceMaps?: boolean;\n pathConfig?: PathConfig;\n} = {}) {\n const pathRegex = compilePathRegex(\n process.env._GENERALTRANSLATION_PATH_REGEX\n );\n\n // i18n config\n let envParams: MiddlewareEnvConfig | undefined;\n if (process.env._GENERALTRANSLATION_I18N_CONFIG_PARAMS) {\n try {\n envParams = JSON.parse(\n process.env._GENERALTRANSLATION_I18N_CONFIG_PARAMS\n );\n } catch (error) {\n console.error(`gt-next middleware:`, error);\n }\n }\n\n // gt instance\n const gt = new GTRuntime({\n customMapping: envParams?.customMapping,\n });\n\n // using gt services\n const gtServicesEnabled =\n process.env._GENERALTRANSLATION_GT_SERVICES_ENABLED === 'true';\n\n // i18n config\n const defaultLocale: string =\n envParams?.defaultLocale || libraryDefaultLocale;\n const locales: string[] = envParams?.locales || [defaultLocale];\n\n // add canonical locales\n const canonicalLocales = Object.values(envParams?.customMapping || {})\n .filter(\n (locale): locale is { code: string } =>\n typeof locale === 'object' &&\n locale !== null &&\n 'code' in locale &&\n typeof locale.code === 'string' &&\n locale.code.length > 0\n )\n .map((locale) => locale.code);\n locales.push(...canonicalLocales);\n\n // cookies and header names\n const headersAndCookies = envParams?.headersAndCookies || {};\n const localeRoutingEnabledCookieName =\n headersAndCookies?.localeRoutingEnabledCookieName ||\n defaultLocaleRoutingEnabledCookieName;\n const referrerLocaleCookieName =\n headersAndCookies?.referrerLocaleCookieName ||\n defaultReferrerLocaleCookieName;\n const localeCookieName =\n headersAndCookies?.localeCookieName || defaultLocaleCookieName;\n const resetLocaleCookieName =\n headersAndCookies?.resetLocaleCookieName || defaultResetLocaleCookieName;\n const localeHeaderName =\n headersAndCookies?.localeHeaderName || defaultLocaleHeaderName;\n\n if (!gt.isValidLocale(defaultLocale))\n throw new Error(\n `gt-next middleware: defaultLocale \"${defaultLocale}\" is not a valid locale.`\n );\n\n const warningLocales = locales.filter((locale) => !gt.isValidLocale(locale));\n if (warningLocales.length)\n console.warn(createUnsupportedLocalesWarning(warningLocales));\n\n // ---------- PRE-PROCESSING PATHS ---------- //\n\n // Standardize pathConfig paths\n pathConfig = Object.entries(pathConfig).reduce<PathConfig>(\n (acc, [sharedPath, localizedPath]) => {\n if (typeof localizedPath === 'string') {\n acc[sharedPath] = localizedPath;\n } else {\n acc[sharedPath] = Object.entries(localizedPath).reduce<{\n [key: string]: string;\n }>((acc, [locale, localizedPath]) => {\n acc[gtServicesEnabled ? standardizeLocale(locale) : locale] =\n localizedPath;\n return acc;\n }, {});\n }\n return acc;\n },\n {}\n );\n\n // Create the path mapping\n const { pathToSharedPath, defaultLocalePaths } = createPathToSharedPathMap(\n pathConfig,\n prefixDefaultLocale,\n defaultLocale\n );\n\n /**\n * Processes the incoming request to determine the user's locale and sets a locale cookie.\n * Optionally redirects the user based on the locale if locale-based routing is enabled.\n *\n * - Checks if the request URL contains a locale.\n * - Falls back to the referer URL for locale if needed.\n * - If no locale is found in the URL or referer, it checks the 'Accept-Language' header.\n * - Sets a cookie with the detected or default locale.\n * - Redirects to the correct locale route if locale routing is enabled.\n *\n * @param {NextRequest} req - The incoming request object, containing URL and headers.\n * @returns {NextResponse} - The Next.js response, either continuing the request or redirecting to the localized URL.\n */\n function middleware(req: NextRequest) {\n if (!pathnameMatchesRegex(req.nextUrl.pathname, pathRegex)) {\n return NextResponse.next();\n }\n\n // Ignore source maps\n if (\n ignoreSourceMaps &&\n req.nextUrl.pathname.startsWith(NEXT_JS_SOURCE_MAP_PATH)\n ) {\n return NextResponse.next();\n }\n\n // ---------- LOCALE DETECTION ---------- //\n\n const {\n userLocale,\n pathnameLocale,\n unstandardizedPathnameLocale,\n clearResetCookie,\n } = getLocaleFromRequest(\n req,\n defaultLocale,\n locales,\n localeRouting,\n gtServicesEnabled,\n prefixDefaultLocale,\n defaultLocalePaths,\n referrerLocaleCookieName,\n localeCookieName,\n resetLocaleCookieName,\n gt\n );\n\n const headerList = new Headers(req.headers);\n\n const responseConfig: Omit<ResponseConfig, 'type'> = {\n originalUrl: req.nextUrl,\n headerList,\n userLocale,\n clearResetCookie,\n localeRouting,\n localeRoutingEnabledCookieName,\n resetLocaleCookieName,\n localeHeaderName,\n };\n\n const getRewriteResponse = (responsePath: string) =>\n getResponse({ responsePath, type: 'rewrite', ...responseConfig });\n\n const getRedirectResponse = (responsePath: string) =>\n getResponse({ responsePath, type: 'redirect', ...responseConfig });\n\n const getNextResponse = () =>\n getResponse({ type: 'next', ...responseConfig });\n\n if (localeRouting) {\n // ---------- GET PATHS ---------- //\n\n // get pathname\n const { pathname } = req.nextUrl;\n\n // standardize pathname (ie, /tg/welcome -> /fil/welcome), (/blog -> /blog)\n const standardizedPathname =\n pathnameLocale && pathnameLocale !== unstandardizedPathnameLocale\n ? pathname.replace(\n new RegExp(`^/${unstandardizedPathnameLocale}`),\n `/${userLocale}`\n )\n : pathname;\n\n // Get the shared path for the unprefixed pathname\n const sharedPath = getSharedPath(\n standardizedPathname,\n pathToSharedPath,\n pathnameLocale\n );\n\n // Get shared path with parameters (/en/dashboard/1/custom), for rewriting localized paths\n const sharedPathWithParameters =\n sharedPath !== undefined\n ? replaceDynamicSegments(\n pathnameLocale\n ? standardizedPathname\n : `/${userLocale}${standardizedPathname}`,\n `/${userLocale}${sharedPath}`\n )\n : undefined;\n\n // Localized path (/en/blog, /fr/fr-about, /fr/dashboard/[id]/custom)\n const localizedPath =\n sharedPath !== undefined\n ? getLocalizedPath(sharedPath, userLocale, pathConfig)\n : undefined;\n\n // Combine localized path with dynamic parameters (/en/blog, /fr/fr-about, /fr/dashboard/1/fr-custom)\n const localizedPathWithParameters =\n localizedPath !== undefined\n ? replaceDynamicSegments(\n pathnameLocale\n ? standardizedPathname\n : `/${userLocale}${standardizedPathname}`,\n localizedPath\n )\n : undefined;\n\n // ---------- ROUTING LOGIC ---------- //\n\n // ----- CASE: no localized path exists ----- //\n\n if (localizedPathWithParameters === undefined) {\n // --- CASE: remove defaultLocale prefix --- //\n\n if (!prefixDefaultLocale && isSameDialect(userLocale, defaultLocale)) {\n if (pathnameLocale) {\n // REDIRECT CASE: used setLocale (/fr/customers -> /customers) (/en/customers -> /customers)\n if (clearResetCookie) {\n return getRedirectResponse(\n pathname.replace(\n new RegExp(`^/${unstandardizedPathnameLocale}`),\n ``\n ) || '/'\n );\n }\n } else {\n // REWRITE CASE: no pathnameLocale (/customers -> /en/customers)\n return getRewriteResponse(`/${userLocale}${pathname}`);\n }\n }\n\n // --- CASE: defaultLocale prefix --- //\n // REDIRECT CASE: no pathnameLocale (ie, /customers -> /fr/customers)\n else if (!pathnameLocale) {\n return getRedirectResponse(`/${userLocale}${pathname}`);\n }\n\n // REDIRECT CASE: wrong pathnameLocale (ie, /fr/customers -> /en/customers) (this usually happens after a locale switch)\n if (pathnameLocale && userLocale !== unstandardizedPathnameLocale) {\n return getRedirectResponse(\n pathname.replace(\n new RegExp(`^/${unstandardizedPathnameLocale}`),\n `/${userLocale}`\n )\n );\n }\n\n // BASE CASE: has pathnameLocale and it's correct\n return getNextResponse();\n }\n\n // ----- CASE: localized path exists ----- //\n\n if (!prefixDefaultLocale && isSameDialect(userLocale, defaultLocale)) {\n // --- CASE: remove defaultLocale prefix --- //\n\n if (pathnameLocale) {\n // REDIRECT CASE: remove locale prefix when setLocale is used (/en/blog -> /blog) (/fr/fr-about -> /en-about)\n if (clearResetCookie) {\n return getRedirectResponse(\n localizedPathWithParameters.replace(\n new RegExp(`^/${unstandardizedPathnameLocale}`),\n ``\n ) || '/'\n );\n }\n } else {\n // REDIRECT CASE: unprefixed pathname is wrong (/about -> /en-about)\n if (\n !pathnameLocale &&\n localizedPathWithParameters !== `/${userLocale}${pathname}`\n ) {\n return getRedirectResponse(\n localizedPathWithParameters.replace(\n new RegExp(`^/${userLocale}`),\n ''\n ) || '/'\n );\n }\n\n // REWRITE CASE: displaying correct path (/blog -> /en/blog)\n return getRewriteResponse(sharedPathWithParameters as string);\n }\n }\n\n // --- CASE: add defaultLocale prefix --- //\n\n // REDIRECT CASE: incorrect pathnameLocale\n if (pathname !== localizedPathWithParameters) {\n return getRedirectResponse(localizedPathWithParameters);\n }\n\n // REWRITE CASE: displaying correct localized path, which is the same as the shared path (/fil/blog => /fil/blog) (/fr/fr-dashboard/1/fr-custom => /fr/dashboard/1/custom)\n if (\n standardizedPathname !== sharedPathWithParameters // no rewrite needed if it's already the shared path\n ) {\n // convert to shared path with dynamic parameters\n return getRewriteResponse(sharedPathWithParameters as string);\n }\n }\n\n // BASE CASE\n return getNextResponse();\n }\n\n return middleware;\n}\n"],"mappings":";;;;;;;;;;;AA4BA,MAAM,0BAA0B;;;;;;;;;;;;;;;AAuBhC,SAAgB,qBAAqB,EACnC,gBAAgB,MAChB,sBAAsB,OACtB,mBAAmB,MACnB,aAAa,EAAE,KAMb,EAAE,EAAE;CACN,MAAM,YAAY,iBAChB,QAAQ,IAAI,+BACb;CAGD,IAAI;AACJ,KAAI,QAAQ,IAAI,uCACd,KAAI;AACF,cAAY,KAAK,MACf,QAAQ,IAAI,uCACb;UACM,OAAO;AACd,UAAQ,MAAM,uBAAuB,MAAM;;CAK/C,MAAM,KAAK,IAAI,UAAU,EACvB,eAAe,WAAW,eAC3B,CAAC;CAGF,MAAM,oBACJ,QAAQ,IAAI,4CAA4C;CAG1D,MAAM,gBACJ,WAAW,iBAAiB;CAC9B,MAAM,UAAoB,WAAW,WAAW,CAAC,cAAc;CAG/D,MAAM,mBAAmB,OAAO,OAAO,WAAW,iBAAiB,EAAE,CAAC,CACnE,QACE,WACC,OAAO,WAAW,YAClB,WAAW,QACX,UAAU,UACV,OAAO,OAAO,SAAS,YACvB,OAAO,KAAK,SAAS,EACxB,CACA,KAAK,WAAW,OAAO,KAAK;AAC/B,SAAQ,KAAK,GAAG,iBAAiB;CAGjC,MAAM,oBAAoB,WAAW,qBAAqB,EAAE;CAC5D,MAAM,iCACJ,mBAAmB,kCAAA;CAErB,MAAM,2BACJ,mBAAmB,4BAAA;CAErB,MAAM,mBACJ,mBAAmB,oBAAoB;CACzC,MAAM,wBACJ,mBAAmB,yBAAyB;CAC9C,MAAM,mBACJ,mBAAmB,oBAAA;AAErB,KAAI,CAAC,GAAG,cAAc,cAAc,CAClC,OAAM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"}
1
+ {"version":3,"file":"createNextMiddleware.mjs","names":[],"sources":["../../src/middleware-dir/createNextMiddleware.ts"],"sourcesContent":["import { isSameDialect, standardizeLocale } from '@generaltranslation/format';\nimport { GTRuntime } from 'generaltranslation/runtime';\nimport { libraryDefaultLocale } from 'generaltranslation/internal';\nimport { createUnsupportedLocalesWarning } from '../errors/middleware';\nimport { NextRequest, NextResponse } from 'next/server';\nimport {\n defaultLocaleRoutingEnabledCookieName,\n defaultReferrerLocaleCookieName,\n} from '../utils/cookies';\nimport {\n defaultLocaleCookieName,\n defaultResetLocaleCookieName,\n} from '@generaltranslation/react-core/pure';\nimport {\n PathConfig,\n getSharedPath,\n replaceDynamicSegments,\n getLocalizedPath,\n createPathToSharedPathMap,\n getLocaleFromRequest,\n getResponse,\n ResponseConfig,\n} from './utils';\nimport { defaultLocaleHeaderName } from '../utils/headers';\nimport type { CustomMapping } from '@generaltranslation/format/types';\nimport type { HeadersAndCookies } from '../config-dir/props/withGTConfigProps';\nimport { compilePathRegex, pathnameMatchesRegex } from '../utils/pathRegex';\n\nconst NEXT_JS_SOURCE_MAP_PATH = '/__nextjs_source-map';\n\ntype MiddlewareEnvConfig = {\n customMapping?: CustomMapping;\n defaultLocale?: string;\n locales?: string[];\n headersAndCookies?: HeadersAndCookies;\n};\n\n/**\n * Middleware factory to create a Next.js middleware for i18n routing and locale detection.\n *\n * This middleware sets a cookie based on the locale derived from several sources\n * such as the request pathname, referer, or 'Accept-Language' header.\n * If locale routing is enabled, it redirects to the localized pathname and\n * updates the locale cookie.\n *\n * @param {boolean} [config.localeRouting=true] - Flag to enable or disable automatic locale-based routing.\n * @param {boolean} [config.prefixDefaultLocale=false] - Flag to enable or disable prefixing the default locale to the pathname, i.e., /en/about -> /about\n * @param {boolean} [config.ignoreSourceMaps=true] - Flag to enable or disable ignoring source maps\n * @param {PathConfig} [config.pathConfig] - Path configuration for locale routing\n * @returns {function} - A middleware function that processes the request and response.\n */\nexport function createNextMiddleware({\n localeRouting = true,\n prefixDefaultLocale = false,\n ignoreSourceMaps = true,\n pathConfig = {},\n}: {\n localeRouting?: boolean;\n prefixDefaultLocale?: boolean;\n ignoreSourceMaps?: boolean;\n pathConfig?: PathConfig;\n} = {}) {\n const pathRegex = compilePathRegex(\n process.env._GENERALTRANSLATION_PATH_REGEX\n );\n\n // i18n config\n let envParams: MiddlewareEnvConfig | undefined;\n if (process.env._GENERALTRANSLATION_I18N_CONFIG_PARAMS) {\n try {\n envParams = JSON.parse(\n process.env._GENERALTRANSLATION_I18N_CONFIG_PARAMS\n );\n } catch (error) {\n console.error(`gt-next middleware:`, error);\n }\n }\n\n // gt instance\n const gt = new GTRuntime({\n customMapping: envParams?.customMapping,\n });\n\n // using gt services\n const gtServicesEnabled =\n process.env._GENERALTRANSLATION_GT_SERVICES_ENABLED === 'true';\n\n // i18n config\n const defaultLocale: string =\n envParams?.defaultLocale || libraryDefaultLocale;\n const locales: string[] = envParams?.locales || [defaultLocale];\n\n // add canonical locales\n const canonicalLocales = Object.values(envParams?.customMapping || {})\n .filter(\n (locale): locale is { code: string } =>\n typeof locale === 'object' &&\n locale !== null &&\n 'code' in locale &&\n typeof locale.code === 'string' &&\n locale.code.length > 0\n )\n .map((locale) => locale.code);\n locales.push(...canonicalLocales);\n\n // cookies and header names\n const headersAndCookies = envParams?.headersAndCookies || {};\n const localeRoutingEnabledCookieName =\n headersAndCookies?.localeRoutingEnabledCookieName ||\n defaultLocaleRoutingEnabledCookieName;\n const referrerLocaleCookieName =\n headersAndCookies?.referrerLocaleCookieName ||\n defaultReferrerLocaleCookieName;\n const localeCookieName =\n headersAndCookies?.localeCookieName || defaultLocaleCookieName;\n const resetLocaleCookieName =\n headersAndCookies?.resetLocaleCookieName || defaultResetLocaleCookieName;\n const localeHeaderName =\n headersAndCookies?.localeHeaderName || defaultLocaleHeaderName;\n\n if (!gt.isValidLocale(defaultLocale))\n throw new Error(\n `gt-next middleware: defaultLocale \"${defaultLocale}\" is not a valid locale.`\n );\n\n const warningLocales = locales.filter((locale) => !gt.isValidLocale(locale));\n if (warningLocales.length)\n console.warn(createUnsupportedLocalesWarning(warningLocales));\n\n // ---------- PRE-PROCESSING PATHS ---------- //\n\n // Standardize pathConfig paths\n pathConfig = Object.entries(pathConfig).reduce<PathConfig>(\n (acc, [sharedPath, localizedPath]) => {\n if (typeof localizedPath === 'string') {\n acc[sharedPath] = localizedPath;\n } else {\n acc[sharedPath] = Object.entries(localizedPath).reduce<{\n [key: string]: string;\n }>((acc, [locale, localizedPath]) => {\n acc[gtServicesEnabled ? standardizeLocale(locale) : locale] =\n localizedPath;\n return acc;\n }, {});\n }\n return acc;\n },\n {}\n );\n\n // Create the path mapping\n const { pathToSharedPath, defaultLocalePaths } = createPathToSharedPathMap(\n pathConfig,\n prefixDefaultLocale,\n defaultLocale\n );\n\n /**\n * Processes the incoming request to determine the user's locale and sets a locale cookie.\n * Optionally redirects the user based on the locale if locale-based routing is enabled.\n *\n * - Checks if the request URL contains a locale.\n * - Falls back to the referer URL for locale if needed.\n * - If no locale is found in the URL or referer, it checks the 'Accept-Language' header.\n * - Sets a cookie with the detected or default locale.\n * - Redirects to the correct locale route if locale routing is enabled.\n *\n * @param {NextRequest} req - The incoming request object, containing URL and headers.\n * @returns {NextResponse} - The Next.js response, either continuing the request or redirecting to the localized URL.\n */\n function middleware(req: NextRequest) {\n if (!pathnameMatchesRegex(req.nextUrl.pathname, pathRegex)) {\n return NextResponse.next();\n }\n\n // Ignore source maps\n if (\n ignoreSourceMaps &&\n req.nextUrl.pathname.startsWith(NEXT_JS_SOURCE_MAP_PATH)\n ) {\n return NextResponse.next();\n }\n\n // ---------- LOCALE DETECTION ---------- //\n\n const {\n userLocale,\n pathnameLocale,\n unstandardizedPathnameLocale,\n clearResetCookie,\n } = getLocaleFromRequest(\n req,\n defaultLocale,\n locales,\n localeRouting,\n gtServicesEnabled,\n prefixDefaultLocale,\n defaultLocalePaths,\n referrerLocaleCookieName,\n localeCookieName,\n resetLocaleCookieName,\n gt\n );\n\n const headerList = new Headers(req.headers);\n\n const responseConfig: Omit<ResponseConfig, 'type'> = {\n originalUrl: req.nextUrl,\n headerList,\n userLocale,\n clearResetCookie,\n localeRouting,\n localeRoutingEnabledCookieName,\n resetLocaleCookieName,\n localeHeaderName,\n };\n\n const getRewriteResponse = (responsePath: string) =>\n getResponse({ responsePath, type: 'rewrite', ...responseConfig });\n\n const getRedirectResponse = (responsePath: string) =>\n getResponse({ responsePath, type: 'redirect', ...responseConfig });\n\n const getNextResponse = () =>\n getResponse({ type: 'next', ...responseConfig });\n\n if (localeRouting) {\n // ---------- GET PATHS ---------- //\n\n // get pathname\n const { pathname } = req.nextUrl;\n\n // standardize pathname (ie, /tg/welcome -> /fil/welcome), (/blog -> /blog)\n const standardizedPathname =\n pathnameLocale && pathnameLocale !== unstandardizedPathnameLocale\n ? pathname.replace(\n new RegExp(`^/${unstandardizedPathnameLocale}`),\n `/${userLocale}`\n )\n : pathname;\n\n // Get the shared path for the unprefixed pathname\n const sharedPath = getSharedPath(\n standardizedPathname,\n pathToSharedPath,\n pathnameLocale\n );\n\n // Get shared path with parameters (/en/dashboard/1/custom), for rewriting localized paths\n const sharedPathWithParameters =\n sharedPath !== undefined\n ? replaceDynamicSegments(\n pathnameLocale\n ? standardizedPathname\n : `/${userLocale}${standardizedPathname}`,\n `/${userLocale}${sharedPath}`\n )\n : undefined;\n\n // Localized path (/en/blog, /fr/fr-about, /fr/dashboard/[id]/custom)\n const localizedPath =\n sharedPath !== undefined\n ? getLocalizedPath(sharedPath, userLocale, pathConfig)\n : undefined;\n\n // Combine localized path with dynamic parameters (/en/blog, /fr/fr-about, /fr/dashboard/1/fr-custom)\n const localizedPathWithParameters =\n localizedPath !== undefined\n ? replaceDynamicSegments(\n pathnameLocale\n ? standardizedPathname\n : `/${userLocale}${standardizedPathname}`,\n localizedPath\n )\n : undefined;\n\n // ---------- ROUTING LOGIC ---------- //\n\n // ----- CASE: no localized path exists ----- //\n\n if (localizedPathWithParameters === undefined) {\n // --- CASE: remove defaultLocale prefix --- //\n\n if (!prefixDefaultLocale && isSameDialect(userLocale, defaultLocale)) {\n if (pathnameLocale) {\n // REDIRECT CASE: used setLocale (/fr/customers -> /customers) (/en/customers -> /customers)\n if (clearResetCookie) {\n return getRedirectResponse(\n pathname.replace(\n new RegExp(`^/${unstandardizedPathnameLocale}`),\n ``\n ) || '/'\n );\n }\n } else {\n // REWRITE CASE: no pathnameLocale (/customers -> /en/customers)\n return getRewriteResponse(`/${userLocale}${pathname}`);\n }\n }\n\n // --- CASE: defaultLocale prefix --- //\n // REDIRECT CASE: no pathnameLocale (ie, /customers -> /fr/customers)\n else if (!pathnameLocale) {\n return getRedirectResponse(`/${userLocale}${pathname}`);\n }\n\n // REDIRECT CASE: wrong pathnameLocale (ie, /fr/customers -> /en/customers) (this usually happens after a locale switch)\n if (pathnameLocale && userLocale !== unstandardizedPathnameLocale) {\n return getRedirectResponse(\n pathname.replace(\n new RegExp(`^/${unstandardizedPathnameLocale}`),\n `/${userLocale}`\n )\n );\n }\n\n // BASE CASE: has pathnameLocale and it's correct\n return getNextResponse();\n }\n\n // ----- CASE: localized path exists ----- //\n\n if (!prefixDefaultLocale && isSameDialect(userLocale, defaultLocale)) {\n // --- CASE: remove defaultLocale prefix --- //\n\n if (pathnameLocale) {\n // REDIRECT CASE: remove locale prefix when setLocale is used (/en/blog -> /blog) (/fr/fr-about -> /en-about)\n if (clearResetCookie) {\n return getRedirectResponse(\n localizedPathWithParameters.replace(\n new RegExp(`^/${unstandardizedPathnameLocale}`),\n ``\n ) || '/'\n );\n }\n } else {\n // REDIRECT CASE: unprefixed pathname is wrong (/about -> /en-about)\n if (\n !pathnameLocale &&\n localizedPathWithParameters !== `/${userLocale}${pathname}`\n ) {\n return getRedirectResponse(\n localizedPathWithParameters.replace(\n new RegExp(`^/${userLocale}`),\n ''\n ) || '/'\n );\n }\n\n // REWRITE CASE: displaying correct path (/blog -> /en/blog)\n return getRewriteResponse(sharedPathWithParameters as string);\n }\n }\n\n // --- CASE: add defaultLocale prefix --- //\n\n // REDIRECT CASE: incorrect pathnameLocale\n if (pathname !== localizedPathWithParameters) {\n return getRedirectResponse(localizedPathWithParameters);\n }\n\n // REWRITE CASE: displaying correct localized path, which is the same as the shared path (/fil/blog => /fil/blog) (/fr/fr-dashboard/1/fr-custom => /fr/dashboard/1/custom)\n if (\n standardizedPathname !== sharedPathWithParameters // no rewrite needed if it's already the shared path\n ) {\n // convert to shared path with dynamic parameters\n return getRewriteResponse(sharedPathWithParameters as string);\n }\n }\n\n // BASE CASE\n return getNextResponse();\n }\n\n return middleware;\n}\n"],"mappings":";;;;;;;;;;;AA4BA,MAAM,0BAA0B;;;;;;;;;;;;;;;AAuBhC,SAAgB,qBAAqB,EACnC,gBAAgB,MAChB,sBAAsB,OACtB,mBAAmB,MACnB,aAAa,EAAE,KAMb,EAAE,EAAE;CACN,MAAM,YAAY,iBAChB,QAAQ,IAAI,+BACb;CAGD,IAAI;AACJ,KAAI,QAAQ,IAAI,uCACd,KAAI;AACF,cAAY,KAAK,MACf,QAAQ,IAAI,uCACb;UACM,OAAO;AACd,UAAQ,MAAM,uBAAuB,MAAM;;CAK/C,MAAM,KAAK,IAAI,UAAU,EACvB,eAAe,WAAW,eAC3B,CAAC;CAGF,MAAM,oBACJ,QAAQ,IAAI,4CAA4C;CAG1D,MAAM,gBACJ,WAAW,iBAAiB;CAC9B,MAAM,UAAoB,WAAW,WAAW,CAAC,cAAc;CAG/D,MAAM,mBAAmB,OAAO,OAAO,WAAW,iBAAiB,EAAE,CAAC,CACnE,QACE,WACC,OAAO,WAAW,YAClB,WAAW,QACX,UAAU,UACV,OAAO,OAAO,SAAS,YACvB,OAAO,KAAK,SAAS,EACxB,CACA,KAAK,WAAW,OAAO,KAAK;AAC/B,SAAQ,KAAK,GAAG,iBAAiB;CAGjC,MAAM,oBAAoB,WAAW,qBAAqB,EAAE;CAC5D,MAAM,iCACJ,mBAAmB,kCAAA;CAErB,MAAM,2BACJ,mBAAm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AIH,WAAO,mBAAmB,yBAAmC;;AAOjE,OAAI,aAAa,4BACf,QAAO,oBAAoB,4BAA4B;AAIzD,OACE,yBAAyB,yBAGzB,QAAO,mBAAmB,yBAAmC;;AAKjE,SAAO,iBAAiB;;AAG1B,QAAO"}
@@ -1,6 +1,6 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  require("../_virtual/_rolldown/runtime.js");
3
- const require_errors_createErrors = require("../errors/createErrors.js");
3
+ const require_errors_request = require("../errors/request.js");
4
4
  let gt_i18n_internal = require("gt-i18n/internal");
5
5
  //#region src/request/localeValidation.ts
6
6
  function determineSupportedLocale(locale) {
@@ -9,7 +9,7 @@ function determineSupportedLocale(locale) {
9
9
  }
10
10
  function warnInvalidLocale(locale, defaultLocale) {
11
11
  if (process.env._GENERALTRANSLATION_DISABLE_INVALID_LOCALE_WARNING === "true") return;
12
- console.warn(require_errors_createErrors.createInvalidRequestLocaleWarning(locale, defaultLocale));
12
+ console.warn(require_errors_request.createInvalidRequestLocaleWarning(locale, defaultLocale));
13
13
  }
14
14
  function resolveLocaleOrDefault(locale) {
15
15
  const i18nConfig = (0, gt_i18n_internal.getI18nConfig)();
@@ -1 +1 @@
1
- {"version":3,"file":"localeValidation.js","names":["createInvalidRequestLocaleWarning"],"sources":["../../src/request/localeValidation.ts"],"sourcesContent":["import { getI18nConfig } from 'gt-i18n/internal';\nimport { createInvalidRequestLocaleWarning } from '../errors/createErrors';\n\nfunction determineSupportedLocale(locale: unknown): string | undefined {\n if (typeof locale !== 'string' || locale.length === 0) return undefined;\n return getI18nConfig().determineSupportedLocale(locale);\n}\n\nfunction warnInvalidLocale(locale: string, defaultLocale: string) {\n if (\n process.env._GENERALTRANSLATION_DISABLE_INVALID_LOCALE_WARNING === 'true'\n ) {\n return;\n }\n\n console.warn(createInvalidRequestLocaleWarning(locale, defaultLocale));\n}\n\nexport function resolveLocaleOrDefault(locale: unknown): string {\n const i18nConfig = getI18nConfig();\n const defaultLocale = i18nConfig.getDefaultLocale();\n const supportedLocale =\n typeof locale === 'string' && locale.length > 0\n ? i18nConfig.determineSupportedLocale(locale)\n : undefined;\n\n if (supportedLocale) return i18nConfig.resolveAliasLocale(supportedLocale);\n\n if (typeof locale === 'string' && locale.length > 0) {\n warnInvalidLocale(locale, defaultLocale);\n }\n\n return i18nConfig.resolveAliasLocale(defaultLocale);\n}\n\n/**\n * Checks whether a locale is valid and supported by the current gt-next config.\n *\n * Use this when route params or other request inputs should be rejected instead\n * of falling back to the default locale.\n *\n * @param locale - The locale candidate to validate.\n * @returns True when the locale resolves to one of the configured locales.\n */\nexport function isLocaleSupported(locale: unknown): locale is string {\n return determineSupportedLocale(locale) !== undefined;\n}\n"],"mappings":";;;;;AAGA,SAAS,yBAAyB,QAAqC;AACrE,KAAI,OAAO,WAAW,YAAY,OAAO,WAAW,EAAG,QAAO,KAAA;AAC9D,SAAA,GAAA,iBAAA,gBAAsB,CAAC,yBAAyB,OAAO;;AAGzD,SAAS,kBAAkB,QAAgB,eAAuB;AAChE,KACE,QAAQ,IAAI,uDAAuD,OAEnE;AAGF,SAAQ,KAAKA,4BAAAA,kCAAkC,QAAQ,cAAc,CAAC;;AAGxE,SAAgB,uBAAuB,QAAyB;CAC9D,MAAM,cAAA,GAAA,iBAAA,gBAA4B;CAClC,MAAM,gBAAgB,WAAW,kBAAkB;CACnD,MAAM,kBACJ,OAAO,WAAW,YAAY,OAAO,SAAS,IAC1C,WAAW,yBAAyB,OAAO,GAC3C,KAAA;AAEN,KAAI,gBAAiB,QAAO,WAAW,mBAAmB,gBAAgB;AAE1E,KAAI,OAAO,WAAW,YAAY,OAAO,SAAS,EAChD,mBAAkB,QAAQ,cAAc;AAG1C,QAAO,WAAW,mBAAmB,cAAc;;;;;;;;;;;AAYrD,SAAgB,kBAAkB,QAAmC;AACnE,QAAO,yBAAyB,OAAO,KAAK,KAAA"}
1
+ {"version":3,"file":"localeValidation.js","names":["createInvalidRequestLocaleWarning"],"sources":["../../src/request/localeValidation.ts"],"sourcesContent":["import { getI18nConfig } from 'gt-i18n/internal';\nimport { createInvalidRequestLocaleWarning } from '../errors/request';\n\nfunction determineSupportedLocale(locale: unknown): string | undefined {\n if (typeof locale !== 'string' || locale.length === 0) return undefined;\n return getI18nConfig().determineSupportedLocale(locale);\n}\n\nfunction warnInvalidLocale(locale: string, defaultLocale: string) {\n if (\n process.env._GENERALTRANSLATION_DISABLE_INVALID_LOCALE_WARNING === 'true'\n ) {\n return;\n }\n\n console.warn(createInvalidRequestLocaleWarning(locale, defaultLocale));\n}\n\nexport function resolveLocaleOrDefault(locale: unknown): string {\n const i18nConfig = getI18nConfig();\n const defaultLocale = i18nConfig.getDefaultLocale();\n const supportedLocale =\n typeof locale === 'string' && locale.length > 0\n ? i18nConfig.determineSupportedLocale(locale)\n : undefined;\n\n if (supportedLocale) return i18nConfig.resolveAliasLocale(supportedLocale);\n\n if (typeof locale === 'string' && locale.length > 0) {\n warnInvalidLocale(locale, defaultLocale);\n }\n\n return i18nConfig.resolveAliasLocale(defaultLocale);\n}\n\n/**\n * Checks whether a locale is valid and supported by the current gt-next config.\n *\n * Use this when route params or other request inputs should be rejected instead\n * of falling back to the default locale.\n *\n * @param locale - The locale candidate to validate.\n * @returns True when the locale resolves to one of the configured locales.\n */\nexport function isLocaleSupported(locale: unknown): locale is string {\n return determineSupportedLocale(locale) !== undefined;\n}\n"],"mappings":";;;;;AAGA,SAAS,yBAAyB,QAAqC;AACrE,KAAI,OAAO,WAAW,YAAY,OAAO,WAAW,EAAG,QAAO,KAAA;AAC9D,SAAA,GAAA,iBAAA,gBAAsB,CAAC,yBAAyB,OAAO;;AAGzD,SAAS,kBAAkB,QAAgB,eAAuB;AAChE,KACE,QAAQ,IAAI,uDAAuD,OAEnE;AAGF,SAAQ,KAAKA,uBAAAA,kCAAkC,QAAQ,cAAc,CAAC;;AAGxE,SAAgB,uBAAuB,QAAyB;CAC9D,MAAM,cAAA,GAAA,iBAAA,gBAA4B;CAClC,MAAM,gBAAgB,WAAW,kBAAkB;CACnD,MAAM,kBACJ,OAAO,WAAW,YAAY,OAAO,SAAS,IAC1C,WAAW,yBAAyB,OAAO,GAC3C,KAAA;AAEN,KAAI,gBAAiB,QAAO,WAAW,mBAAmB,gBAAgB;AAE1E,KAAI,OAAO,WAAW,YAAY,OAAO,SAAS,EAChD,mBAAkB,QAAQ,cAAc;AAG1C,QAAO,WAAW,mBAAmB,cAAc;;;;;;;;;;;AAYrD,SAAgB,kBAAkB,QAAmC;AACnE,QAAO,yBAAyB,OAAO,KAAK,KAAA"}
@@ -1,4 +1,4 @@
1
- import { createInvalidRequestLocaleWarning } from "../errors/createErrors.mjs";
1
+ import { createInvalidRequestLocaleWarning } from "../errors/request.mjs";
2
2
  import { getI18nConfig } from "gt-i18n/internal";
3
3
  //#region src/request/localeValidation.ts
4
4
  function determineSupportedLocale(locale) {
@@ -1 +1 @@
1
- {"version":3,"file":"localeValidation.mjs","names":[],"sources":["../../src/request/localeValidation.ts"],"sourcesContent":["import { getI18nConfig } from 'gt-i18n/internal';\nimport { createInvalidRequestLocaleWarning } from '../errors/createErrors';\n\nfunction determineSupportedLocale(locale: unknown): string | undefined {\n if (typeof locale !== 'string' || locale.length === 0) return undefined;\n return getI18nConfig().determineSupportedLocale(locale);\n}\n\nfunction warnInvalidLocale(locale: string, defaultLocale: string) {\n if (\n process.env._GENERALTRANSLATION_DISABLE_INVALID_LOCALE_WARNING === 'true'\n ) {\n return;\n }\n\n console.warn(createInvalidRequestLocaleWarning(locale, defaultLocale));\n}\n\nexport function resolveLocaleOrDefault(locale: unknown): string {\n const i18nConfig = getI18nConfig();\n const defaultLocale = i18nConfig.getDefaultLocale();\n const supportedLocale =\n typeof locale === 'string' && locale.length > 0\n ? i18nConfig.determineSupportedLocale(locale)\n : undefined;\n\n if (supportedLocale) return i18nConfig.resolveAliasLocale(supportedLocale);\n\n if (typeof locale === 'string' && locale.length > 0) {\n warnInvalidLocale(locale, defaultLocale);\n }\n\n return i18nConfig.resolveAliasLocale(defaultLocale);\n}\n\n/**\n * Checks whether a locale is valid and supported by the current gt-next config.\n *\n * Use this when route params or other request inputs should be rejected instead\n * of falling back to the default locale.\n *\n * @param locale - The locale candidate to validate.\n * @returns True when the locale resolves to one of the configured locales.\n */\nexport function isLocaleSupported(locale: unknown): locale is string {\n return determineSupportedLocale(locale) !== undefined;\n}\n"],"mappings":";;;AAGA,SAAS,yBAAyB,QAAqC;AACrE,KAAI,OAAO,WAAW,YAAY,OAAO,WAAW,EAAG,QAAO,KAAA;AAC9D,QAAO,eAAe,CAAC,yBAAyB,OAAO;;AAGzD,SAAS,kBAAkB,QAAgB,eAAuB;AAChE,KACE,QAAQ,IAAI,uDAAuD,OAEnE;AAGF,SAAQ,KAAK,kCAAkC,QAAQ,cAAc,CAAC;;AAGxE,SAAgB,uBAAuB,QAAyB;CAC9D,MAAM,aAAa,eAAe;CAClC,MAAM,gBAAgB,WAAW,kBAAkB;CACnD,MAAM,kBACJ,OAAO,WAAW,YAAY,OAAO,SAAS,IAC1C,WAAW,yBAAyB,OAAO,GAC3C,KAAA;AAEN,KAAI,gBAAiB,QAAO,WAAW,mBAAmB,gBAAgB;AAE1E,KAAI,OAAO,WAAW,YAAY,OAAO,SAAS,EAChD,mBAAkB,QAAQ,cAAc;AAG1C,QAAO,WAAW,mBAAmB,cAAc;;;;;;;;;;;AAYrD,SAAgB,kBAAkB,QAAmC;AACnE,QAAO,yBAAyB,OAAO,KAAK,KAAA"}
1
+ {"version":3,"file":"localeValidation.mjs","names":[],"sources":["../../src/request/localeValidation.ts"],"sourcesContent":["import { getI18nConfig } from 'gt-i18n/internal';\nimport { createInvalidRequestLocaleWarning } from '../errors/request';\n\nfunction determineSupportedLocale(locale: unknown): string | undefined {\n if (typeof locale !== 'string' || locale.length === 0) return undefined;\n return getI18nConfig().determineSupportedLocale(locale);\n}\n\nfunction warnInvalidLocale(locale: string, defaultLocale: string) {\n if (\n process.env._GENERALTRANSLATION_DISABLE_INVALID_LOCALE_WARNING === 'true'\n ) {\n return;\n }\n\n console.warn(createInvalidRequestLocaleWarning(locale, defaultLocale));\n}\n\nexport function resolveLocaleOrDefault(locale: unknown): string {\n const i18nConfig = getI18nConfig();\n const defaultLocale = i18nConfig.getDefaultLocale();\n const supportedLocale =\n typeof locale === 'string' && locale.length > 0\n ? i18nConfig.determineSupportedLocale(locale)\n : undefined;\n\n if (supportedLocale) return i18nConfig.resolveAliasLocale(supportedLocale);\n\n if (typeof locale === 'string' && locale.length > 0) {\n warnInvalidLocale(locale, defaultLocale);\n }\n\n return i18nConfig.resolveAliasLocale(defaultLocale);\n}\n\n/**\n * Checks whether a locale is valid and supported by the current gt-next config.\n *\n * Use this when route params or other request inputs should be rejected instead\n * of falling back to the default locale.\n *\n * @param locale - The locale candidate to validate.\n * @returns True when the locale resolves to one of the configured locales.\n */\nexport function isLocaleSupported(locale: unknown): locale is string {\n return determineSupportedLocale(locale) !== undefined;\n}\n"],"mappings":";;;AAGA,SAAS,yBAAyB,QAAqC;AACrE,KAAI,OAAO,WAAW,YAAY,OAAO,WAAW,EAAG,QAAO,KAAA;AAC9D,QAAO,eAAe,CAAC,yBAAyB,OAAO;;AAGzD,SAAS,kBAAkB,QAAgB,eAAuB;AAChE,KACE,QAAQ,IAAI,uDAAuD,OAEnE;AAGF,SAAQ,KAAK,kCAAkC,QAAQ,cAAc,CAAC;;AAGxE,SAAgB,uBAAuB,QAAyB;CAC9D,MAAM,aAAa,eAAe;CAClC,MAAM,gBAAgB,WAAW,kBAAkB;CACnD,MAAM,kBACJ,OAAO,WAAW,YAAY,OAAO,SAAS,IAC1C,WAAW,yBAAyB,OAAO,GAC3C,KAAA;AAEN,KAAI,gBAAiB,QAAO,WAAW,mBAAmB,gBAAgB;AAE1E,KAAI,OAAO,WAAW,YAAY,OAAO,SAAS,EAChD,mBAAkB,QAAQ,cAAc;AAG1C,QAAO,WAAW,mBAAmB,cAAc;;;;;;;;;;;AAYrD,SAAgB,kBAAkB,QAAmC;AACnE,QAAO,yBAAyB,OAAO,KAAK,KAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"resolveDictionaryLoader.d.ts","sourceRoot":"","sources":["../../src/resolvers/resolveDictionaryLoader.ts"],"names":[],"mappings":"AAEA,KAAK,YAAY,GAAG,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;AAIzD,wBAAgB,uBAAuB,IAAI,YAAY,GAAG,SAAS,CAoClE"}
1
+ {"version":3,"file":"resolveDictionaryLoader.d.ts","sourceRoot":"","sources":["../../src/resolvers/resolveDictionaryLoader.ts"],"names":[],"mappings":"AAEA,KAAK,YAAY,GAAG,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;AAIzD,wBAAgB,uBAAuB,IAAI,YAAY,GAAG,SAAS,CAsClE"}
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_errors_createErrors = require("../errors/createErrors.js");
2
+ const require_errors_loaders = require("../errors/loaders.js");
3
3
  //#region src/resolvers/resolveDictionaryLoader.ts
4
4
  let customLoadDictionary = void 0;
5
5
  function resolveDictionaryLoader() {
@@ -12,8 +12,9 @@ function resolveDictionaryLoader() {
12
12
  customLoadDictionary = customLoadDictionaryConfig?.default || customLoadDictionaryConfig?.loadDictionary;
13
13
  if (!customLoadDictionary) {
14
14
  customLoadDictionary = async (_) => void 0;
15
- if (process.env.NODE_ENV !== "production") throw new Error(require_errors_createErrors.unresolvedCustomLoadDictionaryError);
16
- console.error(require_errors_createErrors.unresolvedCustomLoadDictionaryError);
15
+ const unresolvedCustomLoadDictionaryError = require_errors_loaders.createUnresolvedCustomLoadDictionaryError();
16
+ if (process.env.NODE_ENV !== "production") throw new Error(unresolvedCustomLoadDictionaryError);
17
+ console.error(unresolvedCustomLoadDictionaryError);
17
18
  }
18
19
  return customLoadDictionary;
19
20
  }
@@ -1 +1 @@
1
- {"version":3,"file":"resolveDictionaryLoader.js","names":["unresolvedCustomLoadDictionaryError"],"sources":["../../src/resolvers/resolveDictionaryLoader.ts"],"sourcesContent":["import { unresolvedCustomLoadDictionaryError } from '../errors/createErrors';\n\ntype CustomLoader = (locale: string) => Promise<unknown>;\n\nlet customLoadDictionary: CustomLoader | undefined = undefined;\n\nexport function resolveDictionaryLoader(): CustomLoader | undefined {\n // Singleton pattern\n if (customLoadDictionary !== undefined) return customLoadDictionary;\n\n // Check: local dictionary loader is enabled\n if (process.env._GENERALTRANSLATION_LOCAL_DICTIONARY_ENABLED !== 'true')\n return;\n\n // get load dictionary file\n let customLoadDictionaryConfig;\n try {\n customLoadDictionaryConfig = require('gt-next/internal/_load-dictionary');\n } catch {\n // No custom dictionary loader module was generated.\n }\n\n // Get custom loader\n customLoadDictionary =\n customLoadDictionaryConfig?.default ||\n customLoadDictionaryConfig?.loadDictionary;\n\n // Check: custom loader is exported\n if (!customLoadDictionary) {\n // So the custom loader doesnt eval to falsey\n customLoadDictionary = async (_: string) => undefined;\n\n // Throw error in dev\n if (process.env.NODE_ENV !== 'production') {\n throw new Error(unresolvedCustomLoadDictionaryError);\n }\n\n // Custom loader file was defined but not exported\n console.error(unresolvedCustomLoadDictionaryError);\n }\n\n return customLoadDictionary;\n}\n"],"mappings":";;;AAIA,IAAI,uBAAiD,KAAA;AAErD,SAAgB,0BAAoD;AAElE,KAAI,yBAAyB,KAAA,EAAW,QAAO;AAG/C,KAAI,QAAQ,IAAI,iDAAiD,OAC/D;CAGF,IAAI;AACJ,KAAI;AACF,+BAA6B,QAAQ,oCAAoC;SACnE;AAKR,wBACE,4BAA4B,WAC5B,4BAA4B;AAG9B,KAAI,CAAC,sBAAsB;AAEzB,yBAAuB,OAAO,MAAc,KAAA;AAG5C,MAAI,QAAQ,IAAI,aAAa,aAC3B,OAAM,IAAI,MAAMA,4BAAAA,oCAAoC;AAItD,UAAQ,MAAMA,4BAAAA,oCAAoC;;AAGpD,QAAO"}
1
+ {"version":3,"file":"resolveDictionaryLoader.js","names":["createUnresolvedCustomLoadDictionaryError"],"sources":["../../src/resolvers/resolveDictionaryLoader.ts"],"sourcesContent":["import { createUnresolvedCustomLoadDictionaryError } from '../errors/loaders';\n\ntype CustomLoader = (locale: string) => Promise<unknown>;\n\nlet customLoadDictionary: CustomLoader | undefined = undefined;\n\nexport function resolveDictionaryLoader(): CustomLoader | undefined {\n // Singleton pattern\n if (customLoadDictionary !== undefined) return customLoadDictionary;\n\n // Check: local dictionary loader is enabled\n if (process.env._GENERALTRANSLATION_LOCAL_DICTIONARY_ENABLED !== 'true')\n return;\n\n // get load dictionary file\n let customLoadDictionaryConfig;\n try {\n customLoadDictionaryConfig = require('gt-next/internal/_load-dictionary');\n } catch {\n // No custom dictionary loader module was generated.\n }\n\n // Get custom loader\n customLoadDictionary =\n customLoadDictionaryConfig?.default ||\n customLoadDictionaryConfig?.loadDictionary;\n\n // Check: custom loader is exported\n if (!customLoadDictionary) {\n // So the custom loader doesnt eval to falsey\n customLoadDictionary = async (_: string) => undefined;\n const unresolvedCustomLoadDictionaryError =\n createUnresolvedCustomLoadDictionaryError();\n\n // Throw error in dev\n if (process.env.NODE_ENV !== 'production') {\n throw new Error(unresolvedCustomLoadDictionaryError);\n }\n\n // Custom loader file was defined but not exported\n console.error(unresolvedCustomLoadDictionaryError);\n }\n\n return customLoadDictionary;\n}\n"],"mappings":";;;AAIA,IAAI,uBAAiD,KAAA;AAErD,SAAgB,0BAAoD;AAElE,KAAI,yBAAyB,KAAA,EAAW,QAAO;AAG/C,KAAI,QAAQ,IAAI,iDAAiD,OAC/D;CAGF,IAAI;AACJ,KAAI;AACF,+BAA6B,QAAQ,oCAAoC;SACnE;AAKR,wBACE,4BAA4B,WAC5B,4BAA4B;AAG9B,KAAI,CAAC,sBAAsB;AAEzB,yBAAuB,OAAO,MAAc,KAAA;EAC5C,MAAM,sCACJA,uBAAAA,2CAA2C;AAG7C,MAAI,QAAQ,IAAI,aAAa,aAC3B,OAAM,IAAI,MAAM,oCAAoC;AAItD,UAAQ,MAAM,oCAAoC;;AAGpD,QAAO"}
@@ -1,4 +1,4 @@
1
- import { unresolvedCustomLoadDictionaryError } from "../errors/createErrors.mjs";
1
+ import { createUnresolvedCustomLoadDictionaryError } from "../errors/loaders.mjs";
2
2
  //#region src/resolvers/resolveDictionaryLoader.ts
3
3
  let customLoadDictionary = void 0;
4
4
  function resolveDictionaryLoader() {
@@ -11,6 +11,7 @@ function resolveDictionaryLoader() {
11
11
  customLoadDictionary = customLoadDictionaryConfig?.default || customLoadDictionaryConfig?.loadDictionary;
12
12
  if (!customLoadDictionary) {
13
13
  customLoadDictionary = async (_) => void 0;
14
+ const unresolvedCustomLoadDictionaryError = createUnresolvedCustomLoadDictionaryError();
14
15
  if (process.env.NODE_ENV !== "production") throw new Error(unresolvedCustomLoadDictionaryError);
15
16
  console.error(unresolvedCustomLoadDictionaryError);
16
17
  }
@@ -1 +1 @@
1
- {"version":3,"file":"resolveDictionaryLoader.mjs","names":[],"sources":["../../src/resolvers/resolveDictionaryLoader.ts"],"sourcesContent":["import { unresolvedCustomLoadDictionaryError } from '../errors/createErrors';\n\ntype CustomLoader = (locale: string) => Promise<unknown>;\n\nlet customLoadDictionary: CustomLoader | undefined = undefined;\n\nexport function resolveDictionaryLoader(): CustomLoader | undefined {\n // Singleton pattern\n if (customLoadDictionary !== undefined) return customLoadDictionary;\n\n // Check: local dictionary loader is enabled\n if (process.env._GENERALTRANSLATION_LOCAL_DICTIONARY_ENABLED !== 'true')\n return;\n\n // get load dictionary file\n let customLoadDictionaryConfig;\n try {\n customLoadDictionaryConfig = require('gt-next/internal/_load-dictionary');\n } catch {\n // No custom dictionary loader module was generated.\n }\n\n // Get custom loader\n customLoadDictionary =\n customLoadDictionaryConfig?.default ||\n customLoadDictionaryConfig?.loadDictionary;\n\n // Check: custom loader is exported\n if (!customLoadDictionary) {\n // So the custom loader doesnt eval to falsey\n customLoadDictionary = async (_: string) => undefined;\n\n // Throw error in dev\n if (process.env.NODE_ENV !== 'production') {\n throw new Error(unresolvedCustomLoadDictionaryError);\n }\n\n // Custom loader file was defined but not exported\n console.error(unresolvedCustomLoadDictionaryError);\n }\n\n return customLoadDictionary;\n}\n"],"mappings":";;AAIA,IAAI,uBAAiD,KAAA;AAErD,SAAgB,0BAAoD;AAElE,KAAI,yBAAyB,KAAA,EAAW,QAAO;AAG/C,KAAI,QAAQ,IAAI,iDAAiD,OAC/D;CAGF,IAAI;AACJ,KAAI;AACF,+BAA6B,QAAQ,oCAAoC;SACnE;AAKR,wBACE,4BAA4B,WAC5B,4BAA4B;AAG9B,KAAI,CAAC,sBAAsB;AAEzB,yBAAuB,OAAO,MAAc,KAAA;AAG5C,MAAI,QAAQ,IAAI,aAAa,aAC3B,OAAM,IAAI,MAAM,oCAAoC;AAItD,UAAQ,MAAM,oCAAoC;;AAGpD,QAAO"}
1
+ {"version":3,"file":"resolveDictionaryLoader.mjs","names":[],"sources":["../../src/resolvers/resolveDictionaryLoader.ts"],"sourcesContent":["import { createUnresolvedCustomLoadDictionaryError } from '../errors/loaders';\n\ntype CustomLoader = (locale: string) => Promise<unknown>;\n\nlet customLoadDictionary: CustomLoader | undefined = undefined;\n\nexport function resolveDictionaryLoader(): CustomLoader | undefined {\n // Singleton pattern\n if (customLoadDictionary !== undefined) return customLoadDictionary;\n\n // Check: local dictionary loader is enabled\n if (process.env._GENERALTRANSLATION_LOCAL_DICTIONARY_ENABLED !== 'true')\n return;\n\n // get load dictionary file\n let customLoadDictionaryConfig;\n try {\n customLoadDictionaryConfig = require('gt-next/internal/_load-dictionary');\n } catch {\n // No custom dictionary loader module was generated.\n }\n\n // Get custom loader\n customLoadDictionary =\n customLoadDictionaryConfig?.default ||\n customLoadDictionaryConfig?.loadDictionary;\n\n // Check: custom loader is exported\n if (!customLoadDictionary) {\n // So the custom loader doesnt eval to falsey\n customLoadDictionary = async (_: string) => undefined;\n const unresolvedCustomLoadDictionaryError =\n createUnresolvedCustomLoadDictionaryError();\n\n // Throw error in dev\n if (process.env.NODE_ENV !== 'production') {\n throw new Error(unresolvedCustomLoadDictionaryError);\n }\n\n // Custom loader file was defined but not exported\n console.error(unresolvedCustomLoadDictionaryError);\n }\n\n return customLoadDictionary;\n}\n"],"mappings":";;AAIA,IAAI,uBAAiD,KAAA;AAErD,SAAgB,0BAAoD;AAElE,KAAI,yBAAyB,KAAA,EAAW,QAAO;AAG/C,KAAI,QAAQ,IAAI,iDAAiD,OAC/D;CAGF,IAAI;AACJ,KAAI;AACF,+BAA6B,QAAQ,oCAAoC;SACnE;AAKR,wBACE,4BAA4B,WAC5B,4BAA4B;AAG9B,KAAI,CAAC,sBAAsB;AAEzB,yBAAuB,OAAO,MAAc,KAAA;EAC5C,MAAM,sCACJ,2CAA2C;AAG7C,MAAI,QAAQ,IAAI,aAAa,aAC3B,OAAM,IAAI,MAAM,oCAAoC;AAItD,UAAQ,MAAM,oCAAoC;;AAGpD,QAAO"}
@@ -1 +1 @@
1
- {"version":3,"file":"resolveTranslationLoader.d.ts","sourceRoot":"","sources":["../../src/resolvers/resolveTranslationLoader.ts"],"names":[],"mappings":"AAEA,KAAK,YAAY,GAAG,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;AAIzD,wBAAgB,wBAAwB,IAAI,YAAY,GAAG,SAAS,CAoCnE"}
1
+ {"version":3,"file":"resolveTranslationLoader.d.ts","sourceRoot":"","sources":["../../src/resolvers/resolveTranslationLoader.ts"],"names":[],"mappings":"AAEA,KAAK,YAAY,GAAG,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;AAIzD,wBAAgB,wBAAwB,IAAI,YAAY,GAAG,SAAS,CAsCnE"}
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_errors_createErrors = require("../errors/createErrors.js");
2
+ const require_errors_loaders = require("../errors/loaders.js");
3
3
  //#region src/resolvers/resolveTranslationLoader.ts
4
4
  let customLoadTranslations = void 0;
5
5
  function resolveTranslationLoader() {
@@ -12,8 +12,9 @@ function resolveTranslationLoader() {
12
12
  customLoadTranslations = customLoadTranslationsConfig?.default || customLoadTranslationsConfig?.loadTranslations;
13
13
  if (!customLoadTranslations) {
14
14
  customLoadTranslations = async (_) => void 0;
15
- if (process.env.NODE_ENV !== "production") throw new Error(require_errors_createErrors.unresolvedCustomLoadTranslationsError);
16
- console.error(require_errors_createErrors.unresolvedCustomLoadTranslationsError);
15
+ const unresolvedCustomLoadTranslationsError = require_errors_loaders.createUnresolvedCustomLoadTranslationsError();
16
+ if (process.env.NODE_ENV !== "production") throw new Error(unresolvedCustomLoadTranslationsError);
17
+ console.error(unresolvedCustomLoadTranslationsError);
17
18
  }
18
19
  return customLoadTranslations;
19
20
  }
@@ -1 +1 @@
1
- {"version":3,"file":"resolveTranslationLoader.js","names":["unresolvedCustomLoadTranslationsError"],"sources":["../../src/resolvers/resolveTranslationLoader.ts"],"sourcesContent":["import { unresolvedCustomLoadTranslationsError } from '../errors/createErrors';\n\ntype CustomLoader = (locale: string) => Promise<unknown>;\n\nlet customLoadTranslations: CustomLoader | undefined = undefined;\n\nexport function resolveTranslationLoader(): CustomLoader | undefined {\n // Singleton pattern\n if (customLoadTranslations !== undefined) return customLoadTranslations;\n\n // Check: local translation loader is enabled\n if (process.env._GENERALTRANSLATION_LOCAL_TRANSLATION_ENABLED !== 'true')\n return undefined;\n\n // get load translation file\n let customLoadTranslationsConfig;\n try {\n customLoadTranslationsConfig = require('gt-next/internal/_load-translations');\n } catch {\n // No custom translation loader module was generated.\n }\n\n // Get custom loader\n customLoadTranslations =\n customLoadTranslationsConfig?.default ||\n customLoadTranslationsConfig?.loadTranslations;\n\n // Check: custom loader is exported\n if (!customLoadTranslations) {\n // So the custom loader doesnt eval to falsey\n customLoadTranslations = async (_: string) => undefined;\n\n // Throw error in dev\n if (process.env.NODE_ENV !== 'production') {\n throw new Error(unresolvedCustomLoadTranslationsError);\n }\n\n // Custom loader file was defined but not exported\n console.error(unresolvedCustomLoadTranslationsError);\n }\n\n return customLoadTranslations;\n}\n"],"mappings":";;;AAIA,IAAI,yBAAmD,KAAA;AAEvD,SAAgB,2BAAqD;AAEnE,KAAI,2BAA2B,KAAA,EAAW,QAAO;AAGjD,KAAI,QAAQ,IAAI,kDAAkD,OAChE,QAAO,KAAA;CAGT,IAAI;AACJ,KAAI;AACF,iCAA+B,QAAQ,sCAAsC;SACvE;AAKR,0BACE,8BAA8B,WAC9B,8BAA8B;AAGhC,KAAI,CAAC,wBAAwB;AAE3B,2BAAyB,OAAO,MAAc,KAAA;AAG9C,MAAI,QAAQ,IAAI,aAAa,aAC3B,OAAM,IAAI,MAAMA,4BAAAA,sCAAsC;AAIxD,UAAQ,MAAMA,4BAAAA,sCAAsC;;AAGtD,QAAO"}
1
+ {"version":3,"file":"resolveTranslationLoader.js","names":["createUnresolvedCustomLoadTranslationsError"],"sources":["../../src/resolvers/resolveTranslationLoader.ts"],"sourcesContent":["import { createUnresolvedCustomLoadTranslationsError } from '../errors/loaders';\n\ntype CustomLoader = (locale: string) => Promise<unknown>;\n\nlet customLoadTranslations: CustomLoader | undefined = undefined;\n\nexport function resolveTranslationLoader(): CustomLoader | undefined {\n // Singleton pattern\n if (customLoadTranslations !== undefined) return customLoadTranslations;\n\n // Check: local translation loader is enabled\n if (process.env._GENERALTRANSLATION_LOCAL_TRANSLATION_ENABLED !== 'true')\n return undefined;\n\n // get load translation file\n let customLoadTranslationsConfig;\n try {\n customLoadTranslationsConfig = require('gt-next/internal/_load-translations');\n } catch {\n // No custom translation loader module was generated.\n }\n\n // Get custom loader\n customLoadTranslations =\n customLoadTranslationsConfig?.default ||\n customLoadTranslationsConfig?.loadTranslations;\n\n // Check: custom loader is exported\n if (!customLoadTranslations) {\n // So the custom loader doesnt eval to falsey\n customLoadTranslations = async (_: string) => undefined;\n const unresolvedCustomLoadTranslationsError =\n createUnresolvedCustomLoadTranslationsError();\n\n // Throw error in dev\n if (process.env.NODE_ENV !== 'production') {\n throw new Error(unresolvedCustomLoadTranslationsError);\n }\n\n // Custom loader file was defined but not exported\n console.error(unresolvedCustomLoadTranslationsError);\n }\n\n return customLoadTranslations;\n}\n"],"mappings":";;;AAIA,IAAI,yBAAmD,KAAA;AAEvD,SAAgB,2BAAqD;AAEnE,KAAI,2BAA2B,KAAA,EAAW,QAAO;AAGjD,KAAI,QAAQ,IAAI,kDAAkD,OAChE,QAAO,KAAA;CAGT,IAAI;AACJ,KAAI;AACF,iCAA+B,QAAQ,sCAAsC;SACvE;AAKR,0BACE,8BAA8B,WAC9B,8BAA8B;AAGhC,KAAI,CAAC,wBAAwB;AAE3B,2BAAyB,OAAO,MAAc,KAAA;EAC9C,MAAM,wCACJA,uBAAAA,6CAA6C;AAG/C,MAAI,QAAQ,IAAI,aAAa,aAC3B,OAAM,IAAI,MAAM,sCAAsC;AAIxD,UAAQ,MAAM,sCAAsC;;AAGtD,QAAO"}
@@ -1,4 +1,4 @@
1
- import { unresolvedCustomLoadTranslationsError } from "../errors/createErrors.mjs";
1
+ import { createUnresolvedCustomLoadTranslationsError } from "../errors/loaders.mjs";
2
2
  //#region src/resolvers/resolveTranslationLoader.ts
3
3
  let customLoadTranslations = void 0;
4
4
  function resolveTranslationLoader() {
@@ -11,6 +11,7 @@ function resolveTranslationLoader() {
11
11
  customLoadTranslations = customLoadTranslationsConfig?.default || customLoadTranslationsConfig?.loadTranslations;
12
12
  if (!customLoadTranslations) {
13
13
  customLoadTranslations = async (_) => void 0;
14
+ const unresolvedCustomLoadTranslationsError = createUnresolvedCustomLoadTranslationsError();
14
15
  if (process.env.NODE_ENV !== "production") throw new Error(unresolvedCustomLoadTranslationsError);
15
16
  console.error(unresolvedCustomLoadTranslationsError);
16
17
  }
@@ -1 +1 @@
1
- {"version":3,"file":"resolveTranslationLoader.mjs","names":[],"sources":["../../src/resolvers/resolveTranslationLoader.ts"],"sourcesContent":["import { unresolvedCustomLoadTranslationsError } from '../errors/createErrors';\n\ntype CustomLoader = (locale: string) => Promise<unknown>;\n\nlet customLoadTranslations: CustomLoader | undefined = undefined;\n\nexport function resolveTranslationLoader(): CustomLoader | undefined {\n // Singleton pattern\n if (customLoadTranslations !== undefined) return customLoadTranslations;\n\n // Check: local translation loader is enabled\n if (process.env._GENERALTRANSLATION_LOCAL_TRANSLATION_ENABLED !== 'true')\n return undefined;\n\n // get load translation file\n let customLoadTranslationsConfig;\n try {\n customLoadTranslationsConfig = require('gt-next/internal/_load-translations');\n } catch {\n // No custom translation loader module was generated.\n }\n\n // Get custom loader\n customLoadTranslations =\n customLoadTranslationsConfig?.default ||\n customLoadTranslationsConfig?.loadTranslations;\n\n // Check: custom loader is exported\n if (!customLoadTranslations) {\n // So the custom loader doesnt eval to falsey\n customLoadTranslations = async (_: string) => undefined;\n\n // Throw error in dev\n if (process.env.NODE_ENV !== 'production') {\n throw new Error(unresolvedCustomLoadTranslationsError);\n }\n\n // Custom loader file was defined but not exported\n console.error(unresolvedCustomLoadTranslationsError);\n }\n\n return customLoadTranslations;\n}\n"],"mappings":";;AAIA,IAAI,yBAAmD,KAAA;AAEvD,SAAgB,2BAAqD;AAEnE,KAAI,2BAA2B,KAAA,EAAW,QAAO;AAGjD,KAAI,QAAQ,IAAI,kDAAkD,OAChE,QAAO,KAAA;CAGT,IAAI;AACJ,KAAI;AACF,iCAA+B,QAAQ,sCAAsC;SACvE;AAKR,0BACE,8BAA8B,WAC9B,8BAA8B;AAGhC,KAAI,CAAC,wBAAwB;AAE3B,2BAAyB,OAAO,MAAc,KAAA;AAG9C,MAAI,QAAQ,IAAI,aAAa,aAC3B,OAAM,IAAI,MAAM,sCAAsC;AAIxD,UAAQ,MAAM,sCAAsC;;AAGtD,QAAO"}
1
+ {"version":3,"file":"resolveTranslationLoader.mjs","names":[],"sources":["../../src/resolvers/resolveTranslationLoader.ts"],"sourcesContent":["import { createUnresolvedCustomLoadTranslationsError } from '../errors/loaders';\n\ntype CustomLoader = (locale: string) => Promise<unknown>;\n\nlet customLoadTranslations: CustomLoader | undefined = undefined;\n\nexport function resolveTranslationLoader(): CustomLoader | undefined {\n // Singleton pattern\n if (customLoadTranslations !== undefined) return customLoadTranslations;\n\n // Check: local translation loader is enabled\n if (process.env._GENERALTRANSLATION_LOCAL_TRANSLATION_ENABLED !== 'true')\n return undefined;\n\n // get load translation file\n let customLoadTranslationsConfig;\n try {\n customLoadTranslationsConfig = require('gt-next/internal/_load-translations');\n } catch {\n // No custom translation loader module was generated.\n }\n\n // Get custom loader\n customLoadTranslations =\n customLoadTranslationsConfig?.default ||\n customLoadTranslationsConfig?.loadTranslations;\n\n // Check: custom loader is exported\n if (!customLoadTranslations) {\n // So the custom loader doesnt eval to falsey\n customLoadTranslations = async (_: string) => undefined;\n const unresolvedCustomLoadTranslationsError =\n createUnresolvedCustomLoadTranslationsError();\n\n // Throw error in dev\n if (process.env.NODE_ENV !== 'production') {\n throw new Error(unresolvedCustomLoadTranslationsError);\n }\n\n // Custom loader file was defined but not exported\n console.error(unresolvedCustomLoadTranslationsError);\n }\n\n return customLoadTranslations;\n}\n"],"mappings":";;AAIA,IAAI,yBAAmD,KAAA;AAEvD,SAAgB,2BAAqD;AAEnE,KAAI,2BAA2B,KAAA,EAAW,QAAO;AAGjD,KAAI,QAAQ,IAAI,kDAAkD,OAChE,QAAO,KAAA;CAGT,IAAI;AACJ,KAAI;AACF,iCAA+B,QAAQ,sCAAsC;SACvE;AAKR,0BACE,8BAA8B,WAC9B,8BAA8B;AAGhC,KAAI,CAAC,wBAAwB;AAE3B,2BAAyB,OAAO,MAAc,KAAA;EAC9C,MAAM,wCACJ,6CAA6C;AAG/C,MAAI,QAAQ,IAAI,aAAa,aAC3B,OAAM,IAAI,MAAM,sCAAsC;AAIxD,UAAQ,MAAM,sCAAsC;;AAGtD,QAAO"}
@@ -1 +1 @@
1
- {"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../src/setup/shared.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,gBAAgB,EAAE,MAAM,qCAAqC,CAAC;AAC5E,OAAO,EAAE,KAAK,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAIvE,MAAM,MAAM,yBAAyB,GAAG,gBAAgB,GAAG;IACzD,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,oBAAoB,CAAC,EAAE,OAAO,CAAC;CAChC,CAAC;AAGF,wBAAgB,SAAS,IAAI;IAC3B,gBAAgB,EAAE,yBAAyB,CAAC;IAC5C,mBAAmB,EAAE,mBAAmB,CAAC;CAC1C,CA6DA"}
1
+ {"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../src/setup/shared.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,gBAAgB,EAAE,MAAM,qCAAqC,CAAC;AAC5E,OAAO,EAAE,KAAK,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAIvE,MAAM,MAAM,yBAAyB,GAAG,gBAAgB,GAAG;IACzD,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,oBAAoB,CAAC,EAAE,OAAO,CAAC;CAChC,CAAC;AAGF,wBAAgB,SAAS,IAAI;IAC3B,gBAAgB,EAAE,yBAAyB,CAAC;IAC5C,mBAAmB,EAAE,mBAAmB,CAAC;CAC1C,CA0DA"}
@@ -3,42 +3,41 @@ const require_setup_runtimeCredentials = require("./runtimeCredentials.js");
3
3
  const require_resolvers_resolveTranslationLoader = require("../resolvers/resolveTranslationLoader.js");
4
4
  //#region src/setup/shared.ts
5
5
  function getParams() {
6
- const publicConfig = JSON.parse(process.env.NEXT_PUBLIC_GENERALTRANSLATION_I18N_CONFIG_PARAMS || "{}");
7
- const privateConfig = JSON.parse(process.env._GENERALTRANSLATION_I18N_CONFIG_PARAMS || "{}");
6
+ const clientConfig = JSON.parse(process.env.NEXT_PUBLIC_GENERALTRANSLATION_I18N_CONFIG_PARAMS || "{}");
8
7
  const { projectId, devApiKey, apiKey } = require_setup_runtimeCredentials.getRuntimeCredentials();
9
8
  const i18nConfigParams = {
10
- defaultLocale: publicConfig.defaultLocale,
11
- locales: publicConfig.locales,
12
- customMapping: publicConfig.customMapping,
13
- runtimeUrl: publicConfig.runtimeUrl,
9
+ defaultLocale: clientConfig.defaultLocale,
10
+ locales: clientConfig.locales,
11
+ customMapping: clientConfig.customMapping,
12
+ runtimeUrl: clientConfig.runtimeUrl,
14
13
  projectId,
15
14
  devApiKey,
16
15
  apiKey,
17
- cacheUrl: privateConfig.cacheUrl,
18
- _disableDevHotReload: privateConfig._disableDevHotReload,
19
- localeCookieName: privateConfig.headersAndCookies?.localeCookieName,
20
- enableI18nCookieName: privateConfig.headersAndCookies?.enableI18nCookieName
16
+ cacheUrl: clientConfig.cacheUrl,
17
+ _disableDevHotReload: clientConfig._disableDevHotReload,
18
+ localeCookieName: clientConfig.headersAndCookies?.localeCookieName,
19
+ enableI18nCookieName: clientConfig.headersAndCookies?.enableI18nCookieName
21
20
  };
22
- const timeout = privateConfig.renderSettings?.timeout;
21
+ const timeout = clientConfig.renderSettings?.timeout;
23
22
  return {
24
23
  i18nConfigParams,
25
24
  nextI18nCacheParams: {
26
25
  apiKey,
27
26
  devApiKey,
28
27
  projectId,
29
- runtimeUrl: publicConfig.runtimeUrl,
30
- cacheUrl: privateConfig.cacheUrl,
31
- _versionId: privateConfig._versionId,
32
- cacheExpiryTime: privateConfig.cacheExpiryTime,
28
+ runtimeUrl: clientConfig.runtimeUrl,
29
+ cacheUrl: clientConfig.cacheUrl,
30
+ _versionId: clientConfig._versionId,
31
+ cacheExpiryTime: clientConfig.cacheExpiryTime,
33
32
  batchConfig: {
34
- maxConcurrentRequests: privateConfig.maxConcurrentRequests,
35
- maxBatchSize: privateConfig.maxBatchSize,
36
- batchInterval: privateConfig.batchInterval
33
+ maxConcurrentRequests: clientConfig.maxConcurrentRequests,
34
+ maxBatchSize: clientConfig.maxBatchSize,
35
+ batchInterval: clientConfig.batchInterval
37
36
  },
38
37
  runtimeTranslation: {
39
38
  timeout,
40
39
  metadata: {
41
- sourceLocale: publicConfig.defaultLocale,
40
+ sourceLocale: clientConfig.defaultLocale,
42
41
  timeout,
43
42
  projectId,
44
43
  publish: true,
@@ -1 +1 @@
1
- {"version":3,"file":"shared.js","names":["getRuntimeCredentials","resolveTranslationLoader"],"sources":["../../src/setup/shared.ts"],"sourcesContent":["import { type I18nConfigParams } from '@generaltranslation/react-core/pure';\nimport { type NextI18nCacheParams } from '../i18n-cache/NextI18nCache';\nimport { resolveTranslationLoader } from '../resolvers/resolveTranslationLoader';\nimport { getRuntimeCredentials } from './runtimeCredentials';\n\nexport type NextSetupI18nConfigParams = I18nConfigParams & {\n cacheUrl?: string | null;\n _disableDevHotReload?: boolean;\n};\n\n// TODO: better way of communicating from build to runtime\nexport function getParams(): {\n i18nConfigParams: NextSetupI18nConfigParams;\n nextI18nCacheParams: NextI18nCacheParams;\n} {\n // Read from build output\n const publicConfig = JSON.parse(\n process.env.NEXT_PUBLIC_GENERALTRANSLATION_I18N_CONFIG_PARAMS || '{}'\n );\n const privateConfig = JSON.parse(\n process.env._GENERALTRANSLATION_I18N_CONFIG_PARAMS || '{}'\n );\n const { projectId, devApiKey, apiKey } = getRuntimeCredentials();\n\n // I18nConfigParams\n const i18nConfigParams: NextSetupI18nConfigParams = {\n defaultLocale: publicConfig.defaultLocale,\n locales: publicConfig.locales,\n customMapping: publicConfig.customMapping,\n runtimeUrl: publicConfig.runtimeUrl,\n projectId,\n devApiKey,\n apiKey,\n cacheUrl: privateConfig.cacheUrl,\n _disableDevHotReload: privateConfig._disableDevHotReload,\n localeCookieName: privateConfig.headersAndCookies?.localeCookieName,\n enableI18nCookieName: privateConfig.headersAndCookies?.enableI18nCookieName,\n };\n\n // NextI18nCacheParams\n const timeout = privateConfig.renderSettings?.timeout;\n const nextI18nCacheParams: NextI18nCacheParams = {\n apiKey,\n devApiKey,\n projectId,\n runtimeUrl: publicConfig.runtimeUrl,\n cacheUrl: privateConfig.cacheUrl,\n _versionId: privateConfig._versionId,\n cacheExpiryTime: privateConfig.cacheExpiryTime,\n // batching config\n batchConfig: {\n maxConcurrentRequests: privateConfig.maxConcurrentRequests,\n maxBatchSize: privateConfig.maxBatchSize,\n batchInterval: privateConfig.batchInterval,\n },\n // runtime translation config\n runtimeTranslation: {\n // TODO: reduce redundancy in this config\n timeout,\n metadata: {\n sourceLocale: publicConfig.defaultLocale,\n timeout,\n projectId,\n publish: true,\n fast: true,\n },\n },\n // loader\n loadTranslations: createLoadTranslations(),\n };\n\n return {\n i18nConfigParams,\n nextI18nCacheParams,\n };\n}\n\nfunction createLoadTranslations() {\n if (typeof window !== 'undefined') return;\n return resolveTranslationLoader();\n}\n"],"mappings":";;;;AAWA,SAAgB,YAGd;CAEA,MAAM,eAAe,KAAK,MACxB,QAAQ,IAAI,qDAAqD,KAClE;CACD,MAAM,gBAAgB,KAAK,MACzB,QAAQ,IAAI,0CAA0C,KACvD;CACD,MAAM,EAAE,WAAW,WAAW,WAAWA,iCAAAA,uBAAuB;CAGhE,MAAM,mBAA8C;EAClD,eAAe,aAAa;EAC5B,SAAS,aAAa;EACtB,eAAe,aAAa;EAC5B,YAAY,aAAa;EACzB;EACA;EACA;EACA,UAAU,cAAc;EACxB,sBAAsB,cAAc;EACpC,kBAAkB,cAAc,mBAAmB;EACnD,sBAAsB,cAAc,mBAAmB;EACxD;CAGD,MAAM,UAAU,cAAc,gBAAgB;AA+B9C,QAAO;EACL;EACA,qBAAA;GA/BA;GACA;GACA;GACA,YAAY,aAAa;GACzB,UAAU,cAAc;GACxB,YAAY,cAAc;GAC1B,iBAAiB,cAAc;GAE/B,aAAa;IACX,uBAAuB,cAAc;IACrC,cAAc,cAAc;IAC5B,eAAe,cAAc;IAC9B;GAED,oBAAoB;IAElB;IACA,UAAU;KACR,cAAc,aAAa;KAC3B;KACA;KACA,SAAS;KACT,MAAM;KACP;IACF;GAED,kBAAkB,wBAAwB;GAKvB;EACpB;;AAGH,SAAS,yBAAyB;AAChC,KAAI,OAAO,WAAW,YAAa;AACnC,QAAOC,2CAAAA,0BAA0B"}
1
+ {"version":3,"file":"shared.js","names":["getRuntimeCredentials","resolveTranslationLoader"],"sources":["../../src/setup/shared.ts"],"sourcesContent":["import { type I18nConfigParams } from '@generaltranslation/react-core/pure';\nimport { type NextI18nCacheParams } from '../i18n-cache/NextI18nCache';\nimport { resolveTranslationLoader } from '../resolvers/resolveTranslationLoader';\nimport { getRuntimeCredentials } from './runtimeCredentials';\n\nexport type NextSetupI18nConfigParams = I18nConfigParams & {\n cacheUrl?: string | null;\n _disableDevHotReload?: boolean;\n};\n\n// TODO: better way of communicating from build to runtime\nexport function getParams(): {\n i18nConfigParams: NextSetupI18nConfigParams;\n nextI18nCacheParams: NextI18nCacheParams;\n} {\n // Read from build output\n const clientConfig = JSON.parse(\n process.env.NEXT_PUBLIC_GENERALTRANSLATION_I18N_CONFIG_PARAMS || '{}'\n );\n const { projectId, devApiKey, apiKey } = getRuntimeCredentials();\n\n // I18nConfigParams\n const i18nConfigParams: NextSetupI18nConfigParams = {\n defaultLocale: clientConfig.defaultLocale,\n locales: clientConfig.locales,\n customMapping: clientConfig.customMapping,\n runtimeUrl: clientConfig.runtimeUrl,\n projectId,\n devApiKey,\n apiKey,\n cacheUrl: clientConfig.cacheUrl,\n _disableDevHotReload: clientConfig._disableDevHotReload,\n localeCookieName: clientConfig.headersAndCookies?.localeCookieName,\n enableI18nCookieName: clientConfig.headersAndCookies?.enableI18nCookieName,\n };\n\n // NextI18nCacheParams\n const timeout = clientConfig.renderSettings?.timeout;\n const nextI18nCacheParams: NextI18nCacheParams = {\n apiKey,\n devApiKey,\n projectId,\n runtimeUrl: clientConfig.runtimeUrl,\n cacheUrl: clientConfig.cacheUrl,\n _versionId: clientConfig._versionId,\n cacheExpiryTime: clientConfig.cacheExpiryTime,\n // batching config\n batchConfig: {\n maxConcurrentRequests: clientConfig.maxConcurrentRequests,\n maxBatchSize: clientConfig.maxBatchSize,\n batchInterval: clientConfig.batchInterval,\n },\n // runtime translation config\n runtimeTranslation: {\n // TODO: reduce redundancy in this config\n timeout,\n metadata: {\n sourceLocale: clientConfig.defaultLocale,\n timeout,\n projectId,\n publish: true,\n fast: true,\n },\n },\n // loader\n loadTranslations: createLoadTranslations(),\n };\n\n return {\n i18nConfigParams,\n nextI18nCacheParams,\n };\n}\n\nfunction createLoadTranslations() {\n if (typeof window !== 'undefined') return;\n return resolveTranslationLoader();\n}\n"],"mappings":";;;;AAWA,SAAgB,YAGd;CAEA,MAAM,eAAe,KAAK,MACxB,QAAQ,IAAI,qDAAqD,KAClE;CACD,MAAM,EAAE,WAAW,WAAW,WAAWA,iCAAAA,uBAAuB;CAGhE,MAAM,mBAA8C;EAClD,eAAe,aAAa;EAC5B,SAAS,aAAa;EACtB,eAAe,aAAa;EAC5B,YAAY,aAAa;EACzB;EACA;EACA;EACA,UAAU,aAAa;EACvB,sBAAsB,aAAa;EACnC,kBAAkB,aAAa,mBAAmB;EAClD,sBAAsB,aAAa,mBAAmB;EACvD;CAGD,MAAM,UAAU,aAAa,gBAAgB;AA+B7C,QAAO;EACL;EACA,qBAAA;GA/BA;GACA;GACA;GACA,YAAY,aAAa;GACzB,UAAU,aAAa;GACvB,YAAY,aAAa;GACzB,iBAAiB,aAAa;GAE9B,aAAa;IACX,uBAAuB,aAAa;IACpC,cAAc,aAAa;IAC3B,eAAe,aAAa;IAC7B;GAED,oBAAoB;IAElB;IACA,UAAU;KACR,cAAc,aAAa;KAC3B;KACA;KACA,SAAS;KACT,MAAM;KACP;IACF;GAED,kBAAkB,wBAAwB;GAKvB;EACpB;;AAGH,SAAS,yBAAyB;AAChC,KAAI,OAAO,WAAW,YAAa;AACnC,QAAOC,2CAAAA,0BAA0B"}
@@ -2,42 +2,41 @@ import { getRuntimeCredentials } from "./runtimeCredentials.mjs";
2
2
  import { resolveTranslationLoader } from "../resolvers/resolveTranslationLoader.mjs";
3
3
  //#region src/setup/shared.ts
4
4
  function getParams() {
5
- const publicConfig = JSON.parse(process.env.NEXT_PUBLIC_GENERALTRANSLATION_I18N_CONFIG_PARAMS || "{}");
6
- const privateConfig = JSON.parse(process.env._GENERALTRANSLATION_I18N_CONFIG_PARAMS || "{}");
5
+ const clientConfig = JSON.parse(process.env.NEXT_PUBLIC_GENERALTRANSLATION_I18N_CONFIG_PARAMS || "{}");
7
6
  const { projectId, devApiKey, apiKey } = getRuntimeCredentials();
8
7
  const i18nConfigParams = {
9
- defaultLocale: publicConfig.defaultLocale,
10
- locales: publicConfig.locales,
11
- customMapping: publicConfig.customMapping,
12
- runtimeUrl: publicConfig.runtimeUrl,
8
+ defaultLocale: clientConfig.defaultLocale,
9
+ locales: clientConfig.locales,
10
+ customMapping: clientConfig.customMapping,
11
+ runtimeUrl: clientConfig.runtimeUrl,
13
12
  projectId,
14
13
  devApiKey,
15
14
  apiKey,
16
- cacheUrl: privateConfig.cacheUrl,
17
- _disableDevHotReload: privateConfig._disableDevHotReload,
18
- localeCookieName: privateConfig.headersAndCookies?.localeCookieName,
19
- enableI18nCookieName: privateConfig.headersAndCookies?.enableI18nCookieName
15
+ cacheUrl: clientConfig.cacheUrl,
16
+ _disableDevHotReload: clientConfig._disableDevHotReload,
17
+ localeCookieName: clientConfig.headersAndCookies?.localeCookieName,
18
+ enableI18nCookieName: clientConfig.headersAndCookies?.enableI18nCookieName
20
19
  };
21
- const timeout = privateConfig.renderSettings?.timeout;
20
+ const timeout = clientConfig.renderSettings?.timeout;
22
21
  return {
23
22
  i18nConfigParams,
24
23
  nextI18nCacheParams: {
25
24
  apiKey,
26
25
  devApiKey,
27
26
  projectId,
28
- runtimeUrl: publicConfig.runtimeUrl,
29
- cacheUrl: privateConfig.cacheUrl,
30
- _versionId: privateConfig._versionId,
31
- cacheExpiryTime: privateConfig.cacheExpiryTime,
27
+ runtimeUrl: clientConfig.runtimeUrl,
28
+ cacheUrl: clientConfig.cacheUrl,
29
+ _versionId: clientConfig._versionId,
30
+ cacheExpiryTime: clientConfig.cacheExpiryTime,
32
31
  batchConfig: {
33
- maxConcurrentRequests: privateConfig.maxConcurrentRequests,
34
- maxBatchSize: privateConfig.maxBatchSize,
35
- batchInterval: privateConfig.batchInterval
32
+ maxConcurrentRequests: clientConfig.maxConcurrentRequests,
33
+ maxBatchSize: clientConfig.maxBatchSize,
34
+ batchInterval: clientConfig.batchInterval
36
35
  },
37
36
  runtimeTranslation: {
38
37
  timeout,
39
38
  metadata: {
40
- sourceLocale: publicConfig.defaultLocale,
39
+ sourceLocale: clientConfig.defaultLocale,
41
40
  timeout,
42
41
  projectId,
43
42
  publish: true,
@@ -1 +1 @@
1
- {"version":3,"file":"shared.mjs","names":[],"sources":["../../src/setup/shared.ts"],"sourcesContent":["import { type I18nConfigParams } from '@generaltranslation/react-core/pure';\nimport { type NextI18nCacheParams } from '../i18n-cache/NextI18nCache';\nimport { resolveTranslationLoader } from '../resolvers/resolveTranslationLoader';\nimport { getRuntimeCredentials } from './runtimeCredentials';\n\nexport type NextSetupI18nConfigParams = I18nConfigParams & {\n cacheUrl?: string | null;\n _disableDevHotReload?: boolean;\n};\n\n// TODO: better way of communicating from build to runtime\nexport function getParams(): {\n i18nConfigParams: NextSetupI18nConfigParams;\n nextI18nCacheParams: NextI18nCacheParams;\n} {\n // Read from build output\n const publicConfig = JSON.parse(\n process.env.NEXT_PUBLIC_GENERALTRANSLATION_I18N_CONFIG_PARAMS || '{}'\n );\n const privateConfig = JSON.parse(\n process.env._GENERALTRANSLATION_I18N_CONFIG_PARAMS || '{}'\n );\n const { projectId, devApiKey, apiKey } = getRuntimeCredentials();\n\n // I18nConfigParams\n const i18nConfigParams: NextSetupI18nConfigParams = {\n defaultLocale: publicConfig.defaultLocale,\n locales: publicConfig.locales,\n customMapping: publicConfig.customMapping,\n runtimeUrl: publicConfig.runtimeUrl,\n projectId,\n devApiKey,\n apiKey,\n cacheUrl: privateConfig.cacheUrl,\n _disableDevHotReload: privateConfig._disableDevHotReload,\n localeCookieName: privateConfig.headersAndCookies?.localeCookieName,\n enableI18nCookieName: privateConfig.headersAndCookies?.enableI18nCookieName,\n };\n\n // NextI18nCacheParams\n const timeout = privateConfig.renderSettings?.timeout;\n const nextI18nCacheParams: NextI18nCacheParams = {\n apiKey,\n devApiKey,\n projectId,\n runtimeUrl: publicConfig.runtimeUrl,\n cacheUrl: privateConfig.cacheUrl,\n _versionId: privateConfig._versionId,\n cacheExpiryTime: privateConfig.cacheExpiryTime,\n // batching config\n batchConfig: {\n maxConcurrentRequests: privateConfig.maxConcurrentRequests,\n maxBatchSize: privateConfig.maxBatchSize,\n batchInterval: privateConfig.batchInterval,\n },\n // runtime translation config\n runtimeTranslation: {\n // TODO: reduce redundancy in this config\n timeout,\n metadata: {\n sourceLocale: publicConfig.defaultLocale,\n timeout,\n projectId,\n publish: true,\n fast: true,\n },\n },\n // loader\n loadTranslations: createLoadTranslations(),\n };\n\n return {\n i18nConfigParams,\n nextI18nCacheParams,\n };\n}\n\nfunction createLoadTranslations() {\n if (typeof window !== 'undefined') return;\n return resolveTranslationLoader();\n}\n"],"mappings":";;;AAWA,SAAgB,YAGd;CAEA,MAAM,eAAe,KAAK,MACxB,QAAQ,IAAI,qDAAqD,KAClE;CACD,MAAM,gBAAgB,KAAK,MACzB,QAAQ,IAAI,0CAA0C,KACvD;CACD,MAAM,EAAE,WAAW,WAAW,WAAW,uBAAuB;CAGhE,MAAM,mBAA8C;EAClD,eAAe,aAAa;EAC5B,SAAS,aAAa;EACtB,eAAe,aAAa;EAC5B,YAAY,aAAa;EACzB;EACA;EACA;EACA,UAAU,cAAc;EACxB,sBAAsB,cAAc;EACpC,kBAAkB,cAAc,mBAAmB;EACnD,sBAAsB,cAAc,mBAAmB;EACxD;CAGD,MAAM,UAAU,cAAc,gBAAgB;AA+B9C,QAAO;EACL;EACA,qBAAA;GA/BA;GACA;GACA;GACA,YAAY,aAAa;GACzB,UAAU,cAAc;GACxB,YAAY,cAAc;GAC1B,iBAAiB,cAAc;GAE/B,aAAa;IACX,uBAAuB,cAAc;IACrC,cAAc,cAAc;IAC5B,eAAe,cAAc;IAC9B;GAED,oBAAoB;IAElB;IACA,UAAU;KACR,cAAc,aAAa;KAC3B;KACA;KACA,SAAS;KACT,MAAM;KACP;IACF;GAED,kBAAkB,wBAAwB;GAKvB;EACpB;;AAGH,SAAS,yBAAyB;AAChC,KAAI,OAAO,WAAW,YAAa;AACnC,QAAO,0BAA0B"}
1
+ {"version":3,"file":"shared.mjs","names":[],"sources":["../../src/setup/shared.ts"],"sourcesContent":["import { type I18nConfigParams } from '@generaltranslation/react-core/pure';\nimport { type NextI18nCacheParams } from '../i18n-cache/NextI18nCache';\nimport { resolveTranslationLoader } from '../resolvers/resolveTranslationLoader';\nimport { getRuntimeCredentials } from './runtimeCredentials';\n\nexport type NextSetupI18nConfigParams = I18nConfigParams & {\n cacheUrl?: string | null;\n _disableDevHotReload?: boolean;\n};\n\n// TODO: better way of communicating from build to runtime\nexport function getParams(): {\n i18nConfigParams: NextSetupI18nConfigParams;\n nextI18nCacheParams: NextI18nCacheParams;\n} {\n // Read from build output\n const clientConfig = JSON.parse(\n process.env.NEXT_PUBLIC_GENERALTRANSLATION_I18N_CONFIG_PARAMS || '{}'\n );\n const { projectId, devApiKey, apiKey } = getRuntimeCredentials();\n\n // I18nConfigParams\n const i18nConfigParams: NextSetupI18nConfigParams = {\n defaultLocale: clientConfig.defaultLocale,\n locales: clientConfig.locales,\n customMapping: clientConfig.customMapping,\n runtimeUrl: clientConfig.runtimeUrl,\n projectId,\n devApiKey,\n apiKey,\n cacheUrl: clientConfig.cacheUrl,\n _disableDevHotReload: clientConfig._disableDevHotReload,\n localeCookieName: clientConfig.headersAndCookies?.localeCookieName,\n enableI18nCookieName: clientConfig.headersAndCookies?.enableI18nCookieName,\n };\n\n // NextI18nCacheParams\n const timeout = clientConfig.renderSettings?.timeout;\n const nextI18nCacheParams: NextI18nCacheParams = {\n apiKey,\n devApiKey,\n projectId,\n runtimeUrl: clientConfig.runtimeUrl,\n cacheUrl: clientConfig.cacheUrl,\n _versionId: clientConfig._versionId,\n cacheExpiryTime: clientConfig.cacheExpiryTime,\n // batching config\n batchConfig: {\n maxConcurrentRequests: clientConfig.maxConcurrentRequests,\n maxBatchSize: clientConfig.maxBatchSize,\n batchInterval: clientConfig.batchInterval,\n },\n // runtime translation config\n runtimeTranslation: {\n // TODO: reduce redundancy in this config\n timeout,\n metadata: {\n sourceLocale: clientConfig.defaultLocale,\n timeout,\n projectId,\n publish: true,\n fast: true,\n },\n },\n // loader\n loadTranslations: createLoadTranslations(),\n };\n\n return {\n i18nConfigParams,\n nextI18nCacheParams,\n };\n}\n\nfunction createLoadTranslations() {\n if (typeof window !== 'undefined') return;\n return resolveTranslationLoader();\n}\n"],"mappings":";;;AAWA,SAAgB,YAGd;CAEA,MAAM,eAAe,KAAK,MACxB,QAAQ,IAAI,qDAAqD,KAClE;CACD,MAAM,EAAE,WAAW,WAAW,WAAW,uBAAuB;CAGhE,MAAM,mBAA8C;EAClD,eAAe,aAAa;EAC5B,SAAS,aAAa;EACtB,eAAe,aAAa;EAC5B,YAAY,aAAa;EACzB;EACA;EACA;EACA,UAAU,aAAa;EACvB,sBAAsB,aAAa;EACnC,kBAAkB,aAAa,mBAAmB;EAClD,sBAAsB,aAAa,mBAAmB;EACvD;CAGD,MAAM,UAAU,aAAa,gBAAgB;AA+B7C,QAAO;EACL;EACA,qBAAA;GA/BA;GACA;GACA;GACA,YAAY,aAAa;GACzB,UAAU,aAAa;GACvB,YAAY,aAAa;GACzB,iBAAiB,aAAa;GAE9B,aAAa;IACX,uBAAuB,aAAa;IACpC,cAAc,aAAa;IAC3B,eAAe,aAAa;IAC7B;GAED,oBAAoB;IAElB;IACA,UAAU;KACR,cAAc,aAAa;KAC3B;KACA;KACA,SAAS;KACT,MAAM;KACP;IACF;GAED,kBAAkB,wBAAwB;GAKvB;EACpB;;AAGH,SAAS,yBAAyB;AAChC,KAAI,OAAO,WAAW,YAAa;AACnC,QAAO,0BAA0B"}
@@ -1,12 +1,12 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_errors_createErrors = require("../errors/createErrors.js");
2
+ const require_errors_pathRegex = require("../errors/pathRegex.js");
3
3
  //#region src/utils/pathRegex.ts
4
4
  function compilePathRegex(pathRegex) {
5
5
  if (pathRegex === void 0) return void 0;
6
6
  try {
7
7
  return new RegExp(pathRegex);
8
8
  } catch (error) {
9
- throw new Error(require_errors_createErrors.createInvalidPathRegexError(pathRegex, error));
9
+ throw new Error(require_errors_pathRegex.createInvalidPathRegexError(pathRegex, error));
10
10
  }
11
11
  }
12
12
  function pathnameMatchesRegex(pathname, pathRegex) {
@@ -1 +1 @@
1
- {"version":3,"file":"pathRegex.js","names":["createInvalidPathRegexError"],"sources":["../../src/utils/pathRegex.ts"],"sourcesContent":["import { createInvalidPathRegexError } from '../errors/createErrors';\n\nexport function compilePathRegex(pathRegex?: string): RegExp | undefined {\n if (pathRegex === undefined) return undefined;\n\n try {\n return new RegExp(pathRegex);\n } catch (error) {\n throw new Error(createInvalidPathRegexError(pathRegex, error));\n }\n}\n\nexport function pathnameMatchesRegex(\n pathname: string,\n pathRegex?: RegExp\n): boolean {\n return pathRegex?.test(pathname) ?? true;\n}\n"],"mappings":";;;AAEA,SAAgB,iBAAiB,WAAwC;AACvE,KAAI,cAAc,KAAA,EAAW,QAAO,KAAA;AAEpC,KAAI;AACF,SAAO,IAAI,OAAO,UAAU;UACrB,OAAO;AACd,QAAM,IAAI,MAAMA,4BAAAA,4BAA4B,WAAW,MAAM,CAAC;;;AAIlE,SAAgB,qBACd,UACA,WACS;AACT,QAAO,WAAW,KAAK,SAAS,IAAI"}
1
+ {"version":3,"file":"pathRegex.js","names":["createInvalidPathRegexError"],"sources":["../../src/utils/pathRegex.ts"],"sourcesContent":["import { createInvalidPathRegexError } from '../errors/pathRegex';\n\nexport function compilePathRegex(pathRegex?: string): RegExp | undefined {\n if (pathRegex === undefined) return undefined;\n\n try {\n return new RegExp(pathRegex);\n } catch (error) {\n throw new Error(createInvalidPathRegexError(pathRegex, error));\n }\n}\n\nexport function pathnameMatchesRegex(\n pathname: string,\n pathRegex?: RegExp\n): boolean {\n return pathRegex?.test(pathname) ?? true;\n}\n"],"mappings":";;;AAEA,SAAgB,iBAAiB,WAAwC;AACvE,KAAI,cAAc,KAAA,EAAW,QAAO,KAAA;AAEpC,KAAI;AACF,SAAO,IAAI,OAAO,UAAU;UACrB,OAAO;AACd,QAAM,IAAI,MAAMA,yBAAAA,4BAA4B,WAAW,MAAM,CAAC;;;AAIlE,SAAgB,qBACd,UACA,WACS;AACT,QAAO,WAAW,KAAK,SAAS,IAAI"}