@intlayer/config 8.5.2 → 8.6.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 (37) hide show
  1. package/dist/cjs/configFile/buildBrowserConfiguration.cjs +11 -7
  2. package/dist/cjs/configFile/buildBrowserConfiguration.cjs.map +1 -1
  3. package/dist/cjs/defaultValues/index.cjs +1 -1
  4. package/dist/cjs/defaultValues/routing.cjs.map +1 -1
  5. package/dist/cjs/logger.cjs +10 -26
  6. package/dist/cjs/logger.cjs.map +1 -1
  7. package/dist/cjs/utils/getStorageAttributes.cjs +84 -0
  8. package/dist/cjs/utils/getStorageAttributes.cjs.map +1 -0
  9. package/dist/cjs/utils/index.cjs +2 -0
  10. package/dist/cjs/utils/stringFormatter/camelCaseToKebabCase.cjs +1 -1
  11. package/dist/cjs/utils/stringFormatter/camelCaseToKebabCase.cjs.map +1 -1
  12. package/dist/esm/configFile/buildBrowserConfiguration.mjs +11 -7
  13. package/dist/esm/configFile/buildBrowserConfiguration.mjs.map +1 -1
  14. package/dist/esm/defaultValues/index.mjs +1 -1
  15. package/dist/esm/defaultValues/routing.mjs.map +1 -1
  16. package/dist/esm/logger.mjs +10 -26
  17. package/dist/esm/logger.mjs.map +1 -1
  18. package/dist/esm/utils/getStorageAttributes.mjs +83 -0
  19. package/dist/esm/utils/getStorageAttributes.mjs.map +1 -0
  20. package/dist/esm/utils/index.mjs +2 -1
  21. package/dist/esm/utils/stringFormatter/camelCaseToKebabCase.mjs +1 -1
  22. package/dist/esm/utils/stringFormatter/camelCaseToKebabCase.mjs.map +1 -1
  23. package/dist/types/configFile/buildBrowserConfiguration.d.ts +2 -2
  24. package/dist/types/configFile/buildBrowserConfiguration.d.ts.map +1 -1
  25. package/dist/types/configFile/configurationSchema.d.ts +7 -7
  26. package/dist/types/defaultValues/routing.d.ts +2 -2
  27. package/dist/types/defaultValues/routing.d.ts.map +1 -1
  28. package/dist/types/loadExternalFile/bundleJSFile.d.ts +13 -13
  29. package/dist/types/loadExternalFile/bundleJSFile.d.ts.map +1 -1
  30. package/dist/types/loadExternalFile/transpileTSToCJS.d.ts +2 -2
  31. package/dist/types/loadExternalFile/transpileTSToCJS.d.ts.map +1 -1
  32. package/dist/types/logger.d.ts +3 -9
  33. package/dist/types/logger.d.ts.map +1 -1
  34. package/dist/types/utils/getStorageAttributes.d.ts +14 -0
  35. package/dist/types/utils/getStorageAttributes.d.ts.map +1 -0
  36. package/dist/types/utils/index.d.ts +2 -1
  37. package/package.json +4 -4
@@ -1,9 +1,10 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
2
  const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
3
+ const require_defaultValues_routing = require('../defaultValues/routing.cjs');
4
+ const require_utils_getStorageAttributes = require('../utils/getStorageAttributes.cjs');
3
5
  const require_defaultValues_editor = require('../defaultValues/editor.cjs');
4
6
  const require_defaultValues_internationalization = require('../defaultValues/internationalization.cjs');
5
7
  const require_defaultValues_log = require('../defaultValues/log.cjs');
6
- const require_defaultValues_routing = require('../defaultValues/routing.cjs');
7
8
  let _intlayer_types_package_json = require("@intlayer/types/package.json");
8
9
  _intlayer_types_package_json = require_runtime.__toESM(_intlayer_types_package_json);
9
10
 
@@ -26,12 +27,15 @@ const buildInternationalizationFields = (customConfiguration) => ({
26
27
  * @param customConfiguration - Partial user-supplied routing config.
27
28
  * @returns A fully-defaulted {@link RoutingConfig}.
28
29
  */
29
- const buildRoutingFields = (customConfiguration) => ({
30
- mode: customConfiguration?.mode ?? "prefix-no-default",
31
- storage: customConfiguration?.storage ?? require_defaultValues_routing.STORAGE,
32
- basePath: customConfiguration?.basePath ?? "",
33
- rewrite: customConfiguration?.rewrite
34
- });
30
+ const buildRoutingFields = (customConfiguration) => {
31
+ const storage = customConfiguration?.storage ?? require_defaultValues_routing.STORAGE;
32
+ return {
33
+ mode: customConfiguration?.mode ?? "prefix-no-default",
34
+ storage: require_utils_getStorageAttributes.getStorageAttributes(storage),
35
+ basePath: customConfiguration?.basePath ?? "",
36
+ rewrite: customConfiguration?.rewrite
37
+ };
38
+ };
35
39
  /**
36
40
  * Build the editor section of the Intlayer configuration.
37
41
  *
@@ -1 +1 @@
1
- {"version":3,"file":"buildBrowserConfiguration.cjs","names":["LOCALES","REQUIRED_LOCALES","DEFAULT_LOCALE","STORAGE","PREFIX","packageJson"],"sources":["../../../src/configFile/buildBrowserConfiguration.ts"],"sourcesContent":["import type {\n CustomIntlayerConfig,\n EditorConfig,\n InternationalizationConfig,\n IntlayerConfig,\n LogConfig,\n LogFunctions,\n RoutingConfig,\n} from '@intlayer/types/config';\nimport packageJson from '@intlayer/types/package.json' with { type: 'json' };\nimport {\n APPLICATION_URL,\n BACKEND_URL,\n CMS_URL,\n DICTIONARY_PRIORITY_STRATEGY,\n EDITOR_URL,\n IS_ENABLED,\n LIVE_SYNC,\n LIVE_SYNC_PORT,\n PORT,\n} from '../defaultValues/editor';\nimport {\n DEFAULT_LOCALE,\n LOCALES,\n REQUIRED_LOCALES,\n STRICT_MODE,\n} from '../defaultValues/internationalization';\nimport { MODE, PREFIX } from '../defaultValues/log';\nimport { BASE_PATH, ROUTING_MODE, STORAGE } from '../defaultValues/routing';\n\n// ---------------------------------------------------------------------------\n// Type\n// ---------------------------------------------------------------------------\n\n/**\n * Browser-safe subset of {@link IntlayerConfig}.\n *\n * Excludes server-only fields (`system`, `content`, `build`, `compiler`,\n * `dictionary`, `ai`) and sensitive editor credentials (`clientId`,\n * `clientSecret`) that must never be shipped to the browser.\n */\nexport type BrowserIntlayerConfig = {\n internationalization: Pick<\n InternationalizationConfig,\n 'locales' | 'defaultLocale'\n >;\n routing: RoutingConfig;\n editor: Omit<EditorConfig, 'clientId' | 'clientSecret'>;\n log: Pick<LogConfig, 'mode' | 'prefix'>;\n metadata: IntlayerConfig['metadata'];\n};\n\ndeclare global {\n interface Window {\n /** Browser-safe Intlayer configuration injected by a build plugin or `installIntlayer`. */\n INTLAYER_CONFIG?: BrowserIntlayerConfig;\n }\n}\n\n// ---------------------------------------------------------------------------\n// Shared field builders (browser-safe — no Node.js APIs)\n//\n// These functions are re-used by both `buildBrowserConfiguration` (browser)\n// and `buildConfigurationFields` (server) to avoid duplication.\n// ---------------------------------------------------------------------------\n\n/**\n * Build the internationalization section of the Intlayer configuration.\n *\n * @param customConfiguration - Partial user-supplied internationalization config.\n * @returns A fully-defaulted {@link InternationalizationConfig}.\n */\nexport const buildInternationalizationFields = (\n customConfiguration?: Partial<InternationalizationConfig>\n): InternationalizationConfig => ({\n /**\n * Locales available in the application\n *\n * Default: ['en']\n *\n */\n locales: customConfiguration?.locales ?? LOCALES,\n\n /**\n * Locales required by TypeScript to ensure strong implementations of internationalized content using typescript.\n *\n * Default: []\n *\n * If empty, all locales are required in `strict` mode.\n *\n * Ensure required locales are also defined in the `locales` field.\n */\n requiredLocales:\n customConfiguration?.requiredLocales ??\n customConfiguration?.locales ??\n REQUIRED_LOCALES,\n\n /**\n * Ensure strong implementations of internationalized content using typescript.\n * - If set to \"strict\", the translation `t` function will require each declared locales to be defined. If one locale is missing, or if a locale is not declared in your config, it will throw an error.\n * - If set to \"inclusive\", the translation `t` function will require each declared locales to be defined. If one locale is missing, it will throw a warning. But will accept if a locale is not declared in your config, but exist.\n * - If set to \"loose\", the translation `t` function will accept any existing locale.\n *\n * Default: \"inclusive\"\n */\n strictMode: customConfiguration?.strictMode ?? STRICT_MODE,\n\n /**\n * Default locale of the application for fallback\n *\n * Default: 'en'\n */\n defaultLocale: customConfiguration?.defaultLocale ?? DEFAULT_LOCALE,\n});\n\n/**\n * Build the routing section of the Intlayer configuration.\n *\n * @param customConfiguration - Partial user-supplied routing config.\n * @returns A fully-defaulted {@link RoutingConfig}.\n */\nexport const buildRoutingFields = (\n customConfiguration?: Partial<RoutingConfig>\n): RoutingConfig => ({\n /**\n * URL routing mode for locale handling\n *\n * Controls how locales are represented in application URLs:\n * - 'prefix-no-default': Prefix all locales except the default locale (default)\n * - en → /dashboard\n * - fr → /fr/dashboard\n *\n * - 'prefix-all': Prefix all locales including the default locale\n * - en → /en/dashboard\n * - fr → /fr/dashboard\n *\n * - 'search-params': Use search parameters for locale handling\n * - en → /dashboard?locale=en\n * - fr → /fr/dashboard?locale=fr\n *\n * - 'no-prefix': No locale prefixing in URLs\n * - en → /dashboard\n * - fr → /dashboard\n *\n * Default: 'prefix-no-default'\n */\n mode: customConfiguration?.mode ?? ROUTING_MODE,\n\n /**\n * Configuration for storing the locale in the client (localStorage or sessionStorage)\n *\n * If false, the locale will not be stored by the middleware.\n * If true, the locale storage will consider all default values. (cookie and header)\n *\n * Default: ['cookie', 'header']\n *\n */\n storage: customConfiguration?.storage ?? STORAGE,\n\n /**\n * Base path of the application URL\n *\n * Default: ''\n *\n * Example:\n * - If the application is hosted at https://example.com/my-app\n * - The base path is '/my-app'\n * - The URL will be https://example.com/my-app/en\n * - If the base path is not set, the URL will be https://example.com/en\n */\n basePath: customConfiguration?.basePath ?? BASE_PATH,\n\n /**\n * Custom URL rewriting rules that override the default routing mode for specific paths.\n * Allows you to define locale-specific paths that differ from the standard routing behavior.\n * Supports dynamic route parameters using `[param]` syntax.\n *\n * Default: undefined\n *\n * Example:\n * ```typescript\n * rewrite: {\n * \"/about\": {\n * en: \"/about\",\n * fr: \"/a-propos\",\n * },\n * \"/product/[slug]\": {\n * en: \"/product/[slug]\",\n * fr: \"/produit/[slug]\",\n * },\n * }\n * ```\n *\n * Note:\n * - The rewrite rules take precedence over the default `mode` behavior.\n * - If a path matches a rewrite rule, the localized path from the rewrite configuration will be used.\n * - Dynamic route parameters are supported using bracket notation (e.g., `[slug]`, `[id]`).\n * - Works with both Next.js and Vite applications.\n */\n rewrite: customConfiguration?.rewrite,\n});\n\n/**\n * Build the editor section of the Intlayer configuration.\n *\n * Returns the **full** {@link EditorConfig} including sensitive fields\n * (`clientId`, `clientSecret`). The browser-safe {@link BrowserIntlayerConfig}\n * omits those fields when exposing config to the client.\n *\n * @param customConfiguration - Partial user-supplied editor config.\n * @returns A fully-defaulted {@link EditorConfig}.\n */\nexport const buildEditorFields = (\n customConfiguration?: Partial<EditorConfig>\n): EditorConfig => {\n const liveSyncPort = customConfiguration?.liveSyncPort ?? LIVE_SYNC_PORT;\n return {\n /**\n * URL of the application. Used to restrict the origin of the editor for security reasons.\n *\n * > '*' means that the editor is accessible from any origin\n *\n * Default: '*'\n */\n applicationURL: customConfiguration?.applicationURL || APPLICATION_URL,\n\n /**\n * URL of the editor server. Used to restrict the origin of the editor for security reasons.\n *\n * > '*' means that the editor is accessible from any origin\n *\n * Default: '*'\n */\n editorURL: customConfiguration?.editorURL || EDITOR_URL,\n\n /**\n * URL of the CMS server. Used to restrict the origin of the editor for security reasons.\n */\n cmsURL: customConfiguration?.cmsURL || CMS_URL,\n\n /**\n * URL of the editor server\n *\n * Default: 'https://back.intlayer.org'\n */\n backendURL: customConfiguration?.backendURL || BACKEND_URL,\n\n /** Port of the editor server\n *\n * Default: 8000\n */\n port: customConfiguration?.port ?? PORT,\n\n /**\n * Indicates if the application interact with the visual editor\n *\n * Default: false;\n *\n * If true, the editor will be able to interact with the application.\n * If false, the editor will not be able to interact with the application.\n * In any case, the editor can only be enabled by the visual editor.\n * Disabling the editor for specific environments is a way to enforce the security.\n *\n * Usage:\n * ```js\n * {\n * // Other configurations\n * editor: {\n * enabled: process.env.NODE_ENV !== 'production',\n * }\n * };\n * ```\n */\n enabled: customConfiguration?.enabled ?? IS_ENABLED,\n\n /**\n * clientId and clientSecret allow the intlayer packages to authenticate with the backend using oAuth2 authentication.\n * An access token is use to authenticate the user related to the project.\n * To get an access token, go to https://app.intlayer.org/project and create an account.\n *\n * Default: undefined\n *\n * > Important: The clientId and clientSecret should be kept secret and not shared publicly. Please ensure to keep them in a secure location, such as environment variables.\n */\n clientId: customConfiguration?.clientId ?? undefined,\n\n /**\n * clientId and clientSecret allow the intlayer packages to authenticate with the backend using oAuth2 authentication.\n * An access token is use to authenticate the user related to the project.\n * To get an access token, go to https://app.intlayer.org/project and create an account.\n *\n * Default: undefined\n *\n * > Important: The clientId and clientSecret should be kept secret and not shared publicly. Please ensure to keep them in a secure location, such as environment variables.\n */\n clientSecret: customConfiguration?.clientSecret ?? undefined,\n\n /**\n * Strategy for prioritizing dictionaries. If a dictionary is both present online and locally, the content will be merge.\n * However, is a field is defined in both dictionary, this setting determines which fields takes the priority over the other.\n *\n * Default: 'local_first'\n *\n * The strategy for prioritizing dictionaries. It can be either 'local_first' or 'distant_first'.\n * - 'local_first': The first dictionary found in the locale is used.\n * - 'distant_first': The first dictionary found in the distant locales is used.\n */\n dictionaryPriorityStrategy:\n customConfiguration?.dictionaryPriorityStrategy ??\n DICTIONARY_PRIORITY_STRATEGY,\n\n /**\n * Indicates if the application should hot reload the locale configurations when a change is detected.\n * For example, when a new dictionary is added or updated, the application will update the content tu display in the page.\n *\n * The hot reload is only available for clients of the `enterprise` plan.\n *\n * Default: false\n */\n liveSync: customConfiguration?.liveSync ?? LIVE_SYNC,\n\n /**\n * Port of the live sync server\n *\n * Default: 4000\n */\n liveSyncPort,\n\n /**\n * URL of the live sync server in case of remote live sync server\n *\n * Default: `http://localhost:${LIVE_SYNC_PORT}`\n */\n liveSyncURL:\n customConfiguration?.liveSyncURL ?? `http://localhost:${liveSyncPort}`,\n };\n};\n\n/**\n * Build the log section of the Intlayer configuration.\n *\n * @param customConfiguration - Partial user-supplied log config.\n * @param logFunctions - Optional custom log function overrides (server-only).\n * @returns A fully-defaulted {@link LogConfig}.\n */\nexport const buildLogFields = (\n customConfiguration?: Partial<LogConfig>,\n logFunctions?: LogFunctions\n): LogConfig => ({\n /**\n * Indicates if the logger is enabled\n *\n * Default: 'prefix-no-default'\n *\n * If 'default', the logger is enabled and can be used.\n * If 'verbose', the logger will be enabled and can be used, but will log more information.\n * If 'disabled', the logger is disabled and cannot be used.\n */\n mode: customConfiguration?.mode ?? MODE,\n\n /**\n * Prefix of the logger\n *\n * Default: '[intlayer]'\n *\n * The prefix of the logger.\n */\n prefix: customConfiguration?.prefix ?? PREFIX,\n\n /**\n * Functions to log\n */\n error: logFunctions?.error,\n log: logFunctions?.log,\n info: logFunctions?.info,\n warn: logFunctions?.warn,\n});\n\n// ---------------------------------------------------------------------------\n// Browser configuration builders\n// ---------------------------------------------------------------------------\n\n/**\n * Build a browser-safe {@link BrowserIntlayerConfig} from a raw user config.\n *\n * Applies defaults for every field and strips all server-only or sensitive\n * information (`system`, `content`, `build`, `compiler`, `dictionary`, `ai`,\n * `editor.clientId`, `editor.clientSecret`).\n *\n * This is the browser counterpart of `buildConfigurationFields`. It is safe\n * to call in browser environments because it has no Node.js dependencies.\n *\n * @param customConfig - Optional partial user-supplied Intlayer config.\n * @returns A browser-safe configuration object ready for `window.INTLAYER_CONFIG`.\n *\n * @example\n * ```ts\n * import { buildBrowserConfiguration } from '@intlayer/config/client';\n *\n * window.INTLAYER_CONFIG = buildBrowserConfiguration({\n * internationalization: { locales: ['en', 'fr'], defaultLocale: 'en' },\n * });\n * ```\n */\nexport const buildBrowserConfiguration = (\n customConfig?: CustomIntlayerConfig\n): BrowserIntlayerConfig => {\n const { locales, defaultLocale } = buildInternationalizationFields(\n customConfig?.internationalization\n );\n const routing = buildRoutingFields(customConfig?.routing);\n const {\n clientId: _clientId,\n clientSecret: _clientSecret,\n ...editorPublic\n } = buildEditorFields(customConfig?.editor);\n const { mode, prefix } = buildLogFields(customConfig?.log);\n\n return {\n internationalization: { locales, defaultLocale },\n routing,\n editor: editorPublic,\n log: { mode, prefix },\n metadata: {\n name: 'Intlayer',\n version: packageJson.version,\n doc: 'https://intlayer.org/docs',\n },\n };\n};\n\n/**\n * Extract a {@link BrowserIntlayerConfig} from an already-built full\n * {@link IntlayerConfig}.\n *\n * Used by build plugins (`vite-intlayer`, `withIntlayer`) which already hold\n * the full server-side config and need to inject the browser-safe subset at\n * compile time via a bundler `define`.\n *\n * @param config - A fully-built server-side Intlayer configuration.\n * @returns The browser-safe subset of that configuration.\n */\nexport const extractBrowserConfiguration = (\n config: IntlayerConfig\n): BrowserIntlayerConfig => ({\n internationalization: {\n locales: config.internationalization.locales,\n defaultLocale: config.internationalization.defaultLocale,\n },\n routing: {\n mode: config.routing.mode,\n storage: config.routing.storage,\n basePath: config.routing.basePath,\n rewrite: config.routing.rewrite,\n },\n editor: {\n applicationURL: config.editor.applicationURL,\n editorURL: config.editor.editorURL,\n cmsURL: config.editor.cmsURL,\n backendURL: config.editor.backendURL,\n port: config.editor.port,\n enabled: config.editor.enabled,\n dictionaryPriorityStrategy: config.editor.dictionaryPriorityStrategy,\n liveSync: config.editor.liveSync,\n liveSyncPort: config.editor.liveSyncPort,\n liveSyncURL: config.editor.liveSyncURL,\n },\n log: {\n mode: config.log.mode,\n prefix: config.log.prefix,\n },\n metadata: config.metadata,\n});\n"],"mappings":";;;;;;;;;;;;;;;;AAwEA,MAAa,mCACX,yBACgC;CAOhC,SAAS,qBAAqB,WAAWA;CAWzC,iBACE,qBAAqB,mBACrB,qBAAqB,WACrBC;CAUF,YAAY,qBAAqB;CAOjC,eAAe,qBAAqB,iBAAiBC;CACtD;;;;;;;AAQD,MAAa,sBACX,yBACmB;CAuBnB,MAAM,qBAAqB;CAW3B,SAAS,qBAAqB,WAAWC;CAazC,UAAU,qBAAqB;CA6B/B,SAAS,qBAAqB;CAC/B;;;;;;;;;;;AAYD,MAAa,qBACX,wBACiB;CACjB,MAAM,eAAe,qBAAqB;AAC1C,QAAO;EAQL,gBAAgB,qBAAqB;EASrC,WAAW,qBAAqB;EAKhC,QAAQ,qBAAqB;EAO7B,YAAY,qBAAqB;EAMjC,MAAM,qBAAqB;EAsB3B,SAAS,qBAAqB;EAW9B,UAAU,qBAAqB,YAAY;EAW3C,cAAc,qBAAqB,gBAAgB;EAYnD,4BACE,qBAAqB;EAWvB,UAAU,qBAAqB;EAO/B;EAOA,aACE,qBAAqB,eAAe,oBAAoB;EAC3D;;;;;;;;;AAUH,MAAa,kBACX,qBACA,kBACe;CAUf,MAAM,qBAAqB;CAS3B,QAAQ,qBAAqB,UAAUC;CAKvC,OAAO,cAAc;CACrB,KAAK,cAAc;CACnB,MAAM,cAAc;CACpB,MAAM,cAAc;CACrB;;;;;;;;;;;;;;;;;;;;;;;AA4BD,MAAa,6BACX,iBAC0B;CAC1B,MAAM,EAAE,SAAS,kBAAkB,gCACjC,cAAc,qBACf;CACD,MAAM,UAAU,mBAAmB,cAAc,QAAQ;CACzD,MAAM,EACJ,UAAU,WACV,cAAc,eACd,GAAG,iBACD,kBAAkB,cAAc,OAAO;CAC3C,MAAM,EAAE,MAAM,WAAW,eAAe,cAAc,IAAI;AAE1D,QAAO;EACL,sBAAsB;GAAE;GAAS;GAAe;EAChD;EACA,QAAQ;EACR,KAAK;GAAE;GAAM;GAAQ;EACrB,UAAU;GACR,MAAM;GACN,SAASC,qCAAY;GACrB,KAAK;GACN;EACF;;;;;;;;;;;;;AAcH,MAAa,+BACX,YAC2B;CAC3B,sBAAsB;EACpB,SAAS,OAAO,qBAAqB;EACrC,eAAe,OAAO,qBAAqB;EAC5C;CACD,SAAS;EACP,MAAM,OAAO,QAAQ;EACrB,SAAS,OAAO,QAAQ;EACxB,UAAU,OAAO,QAAQ;EACzB,SAAS,OAAO,QAAQ;EACzB;CACD,QAAQ;EACN,gBAAgB,OAAO,OAAO;EAC9B,WAAW,OAAO,OAAO;EACzB,QAAQ,OAAO,OAAO;EACtB,YAAY,OAAO,OAAO;EAC1B,MAAM,OAAO,OAAO;EACpB,SAAS,OAAO,OAAO;EACvB,4BAA4B,OAAO,OAAO;EAC1C,UAAU,OAAO,OAAO;EACxB,cAAc,OAAO,OAAO;EAC5B,aAAa,OAAO,OAAO;EAC5B;CACD,KAAK;EACH,MAAM,OAAO,IAAI;EACjB,QAAQ,OAAO,IAAI;EACpB;CACD,UAAU,OAAO;CAClB"}
1
+ {"version":3,"file":"buildBrowserConfiguration.cjs","names":["LOCALES","REQUIRED_LOCALES","DEFAULT_LOCALE","STORAGE","getStorageAttributes","PREFIX","packageJson"],"sources":["../../../src/configFile/buildBrowserConfiguration.ts"],"sourcesContent":["import type {\n CustomIntlayerConfig,\n CustomRoutingConfig,\n EditorConfig,\n InternationalizationConfig,\n IntlayerConfig,\n LogConfig,\n LogFunctions,\n RoutingConfig,\n} from '@intlayer/types/config';\nimport packageJson from '@intlayer/types/package.json' with { type: 'json' };\nimport {\n APPLICATION_URL,\n BACKEND_URL,\n CMS_URL,\n DICTIONARY_PRIORITY_STRATEGY,\n EDITOR_URL,\n IS_ENABLED,\n LIVE_SYNC,\n LIVE_SYNC_PORT,\n PORT,\n} from '../defaultValues/editor';\nimport {\n DEFAULT_LOCALE,\n LOCALES,\n REQUIRED_LOCALES,\n STRICT_MODE,\n} from '../defaultValues/internationalization';\nimport { MODE, PREFIX } from '../defaultValues/log';\nimport { BASE_PATH, ROUTING_MODE, STORAGE } from '../defaultValues/routing';\nimport { getStorageAttributes } from '../utils/getStorageAttributes';\n\n// ---------------------------------------------------------------------------\n// Type\n// ---------------------------------------------------------------------------\n\n/**\n * Browser-safe subset of {@link IntlayerConfig}.\n *\n * Excludes server-only fields (`system`, `content`, `build`, `compiler`,\n * `dictionary`, `ai`) and sensitive editor credentials (`clientId`,\n * `clientSecret`) that must never be shipped to the browser.\n */\nexport type BrowserIntlayerConfig = {\n internationalization: Pick<\n InternationalizationConfig,\n 'locales' | 'defaultLocale'\n >;\n routing: RoutingConfig;\n editor: Omit<EditorConfig, 'clientId' | 'clientSecret'>;\n log: Pick<LogConfig, 'mode' | 'prefix'>;\n metadata: IntlayerConfig['metadata'];\n};\n\ndeclare global {\n interface Window {\n /** Browser-safe Intlayer configuration injected by a build plugin or `installIntlayer`. */\n INTLAYER_CONFIG?: BrowserIntlayerConfig;\n }\n}\n\n// ---------------------------------------------------------------------------\n// Shared field builders (browser-safe — no Node.js APIs)\n//\n// These functions are re-used by both `buildBrowserConfiguration` (browser)\n// and `buildConfigurationFields` (server) to avoid duplication.\n// ---------------------------------------------------------------------------\n\n/**\n * Build the internationalization section of the Intlayer configuration.\n *\n * @param customConfiguration - Partial user-supplied internationalization config.\n * @returns A fully-defaulted {@link InternationalizationConfig}.\n */\nexport const buildInternationalizationFields = (\n customConfiguration?: Partial<InternationalizationConfig>\n): InternationalizationConfig => ({\n /**\n * Locales available in the application\n *\n * Default: ['en']\n *\n */\n locales: customConfiguration?.locales ?? LOCALES,\n\n /**\n * Locales required by TypeScript to ensure strong implementations of internationalized content using typescript.\n *\n * Default: []\n *\n * If empty, all locales are required in `strict` mode.\n *\n * Ensure required locales are also defined in the `locales` field.\n */\n requiredLocales:\n customConfiguration?.requiredLocales ??\n customConfiguration?.locales ??\n REQUIRED_LOCALES,\n\n /**\n * Ensure strong implementations of internationalized content using typescript.\n * - If set to \"strict\", the translation `t` function will require each declared locales to be defined. If one locale is missing, or if a locale is not declared in your config, it will throw an error.\n * - If set to \"inclusive\", the translation `t` function will require each declared locales to be defined. If one locale is missing, it will throw a warning. But will accept if a locale is not declared in your config, but exist.\n * - If set to \"loose\", the translation `t` function will accept any existing locale.\n *\n * Default: \"inclusive\"\n */\n strictMode: customConfiguration?.strictMode ?? STRICT_MODE,\n\n /**\n * Default locale of the application for fallback\n *\n * Default: 'en'\n */\n defaultLocale: customConfiguration?.defaultLocale ?? DEFAULT_LOCALE,\n});\n\n/**\n * Build the routing section of the Intlayer configuration.\n *\n * @param customConfiguration - Partial user-supplied routing config.\n * @returns A fully-defaulted {@link RoutingConfig}.\n */\nexport const buildRoutingFields = (\n customConfiguration?: Partial<CustomRoutingConfig>\n): RoutingConfig => {\n const storage = customConfiguration?.storage ?? STORAGE;\n\n return {\n /**\n * URL routing mode for locale handling\n *\n * Controls how locales are represented in application URLs:\n * - 'prefix-no-default': Prefix all locales except the default locale (default)\n * - en → /dashboard\n * - fr → /fr/dashboard\n *\n * - 'prefix-all': Prefix all locales including the default locale\n * - en → /en/dashboard\n * - fr → /fr/dashboard\n *\n * - 'search-params': Use search parameters for locale handling\n * - en → /dashboard?locale=en\n * - fr → /fr/dashboard?locale=fr\n *\n * - 'no-prefix': No locale prefixing in URLs\n * - en → /dashboard\n * - fr → /dashboard\n *\n * Default: 'prefix-no-default'\n */\n mode: customConfiguration?.mode ?? ROUTING_MODE,\n\n /**\n * Configuration for storing the locale in the client (localStorage or sessionStorage)\n *\n * If false, the locale will not be stored by the middleware.\n * If true, the locale storage will consider all default values. (cookie and header)\n *\n * Default: ['cookie', 'header']\n *\n */\n storage: getStorageAttributes(storage),\n\n /**\n * Base path of the application URL\n *\n * Default: ''\n *\n * Example:\n * - If the application is hosted at https://example.com/my-app\n * - The base path is '/my-app'\n * - The URL will be https://example.com/my-app/en\n * - If the base path is not set, the URL will be https://example.com/en\n */\n basePath: customConfiguration?.basePath ?? BASE_PATH,\n\n /**\n * Custom URL rewriting rules that override the default routing mode for specific paths.\n * Allows you to define locale-specific paths that differ from the standard routing behavior.\n * Supports dynamic route parameters using `[param]` syntax.\n *\n * Default: undefined\n *\n * Example:\n * ```typescript\n * rewrite: {\n * \"/about\": {\n * en: \"/about\",\n * fr: \"/a-propos\",\n * },\n * \"/product/[slug]\": {\n * en: \"/product/[slug]\",\n * fr: \"/produit/[slug]\",\n * },\n * }\n * ```\n *\n * Note:\n * - The rewrite rules take precedence over the default `mode` behavior.\n * - If a path matches a rewrite rule, the localized path from the rewrite configuration will be used.\n * - Dynamic route parameters are supported using bracket notation (e.g., `[slug]`, `[id]`).\n * - Works with both Next.js and Vite applications.\n */\n rewrite: customConfiguration?.rewrite,\n };\n};\n\n/**\n * Build the editor section of the Intlayer configuration.\n *\n * Returns the **full** {@link EditorConfig} including sensitive fields\n * (`clientId`, `clientSecret`). The browser-safe {@link BrowserIntlayerConfig}\n * omits those fields when exposing config to the client.\n *\n * @param customConfiguration - Partial user-supplied editor config.\n * @returns A fully-defaulted {@link EditorConfig}.\n */\nexport const buildEditorFields = (\n customConfiguration?: Partial<EditorConfig>\n): EditorConfig => {\n const liveSyncPort = customConfiguration?.liveSyncPort ?? LIVE_SYNC_PORT;\n return {\n /**\n * URL of the application. Used to restrict the origin of the editor for security reasons.\n *\n * > '*' means that the editor is accessible from any origin\n *\n * Default: '*'\n */\n applicationURL: customConfiguration?.applicationURL || APPLICATION_URL,\n\n /**\n * URL of the editor server. Used to restrict the origin of the editor for security reasons.\n *\n * > '*' means that the editor is accessible from any origin\n *\n * Default: '*'\n */\n editorURL: customConfiguration?.editorURL || EDITOR_URL,\n\n /**\n * URL of the CMS server. Used to restrict the origin of the editor for security reasons.\n */\n cmsURL: customConfiguration?.cmsURL || CMS_URL,\n\n /**\n * URL of the editor server\n *\n * Default: 'https://back.intlayer.org'\n */\n backendURL: customConfiguration?.backendURL || BACKEND_URL,\n\n /** Port of the editor server\n *\n * Default: 8000\n */\n port: customConfiguration?.port ?? PORT,\n\n /**\n * Indicates if the application interact with the visual editor\n *\n * Default: false;\n *\n * If true, the editor will be able to interact with the application.\n * If false, the editor will not be able to interact with the application.\n * In any case, the editor can only be enabled by the visual editor.\n * Disabling the editor for specific environments is a way to enforce the security.\n *\n * Usage:\n * ```js\n * {\n * // Other configurations\n * editor: {\n * enabled: process.env.NODE_ENV !== 'production',\n * }\n * };\n * ```\n */\n enabled: customConfiguration?.enabled ?? IS_ENABLED,\n\n /**\n * clientId and clientSecret allow the intlayer packages to authenticate with the backend using oAuth2 authentication.\n * An access token is use to authenticate the user related to the project.\n * To get an access token, go to https://app.intlayer.org/project and create an account.\n *\n * Default: undefined\n *\n * > Important: The clientId and clientSecret should be kept secret and not shared publicly. Please ensure to keep them in a secure location, such as environment variables.\n */\n clientId: customConfiguration?.clientId ?? undefined,\n\n /**\n * clientId and clientSecret allow the intlayer packages to authenticate with the backend using oAuth2 authentication.\n * An access token is use to authenticate the user related to the project.\n * To get an access token, go to https://app.intlayer.org/project and create an account.\n *\n * Default: undefined\n *\n * > Important: The clientId and clientSecret should be kept secret and not shared publicly. Please ensure to keep them in a secure location, such as environment variables.\n */\n clientSecret: customConfiguration?.clientSecret ?? undefined,\n\n /**\n * Strategy for prioritizing dictionaries. If a dictionary is both present online and locally, the content will be merge.\n * However, is a field is defined in both dictionary, this setting determines which fields takes the priority over the other.\n *\n * Default: 'local_first'\n *\n * The strategy for prioritizing dictionaries. It can be either 'local_first' or 'distant_first'.\n * - 'local_first': The first dictionary found in the locale is used.\n * - 'distant_first': The first dictionary found in the distant locales is used.\n */\n dictionaryPriorityStrategy:\n customConfiguration?.dictionaryPriorityStrategy ??\n DICTIONARY_PRIORITY_STRATEGY,\n\n /**\n * Indicates if the application should hot reload the locale configurations when a change is detected.\n * For example, when a new dictionary is added or updated, the application will update the content tu display in the page.\n *\n * The hot reload is only available for clients of the `enterprise` plan.\n *\n * Default: false\n */\n liveSync: customConfiguration?.liveSync ?? LIVE_SYNC,\n\n /**\n * Port of the live sync server\n *\n * Default: 4000\n */\n liveSyncPort,\n\n /**\n * URL of the live sync server in case of remote live sync server\n *\n * Default: `http://localhost:${LIVE_SYNC_PORT}`\n */\n liveSyncURL:\n customConfiguration?.liveSyncURL ?? `http://localhost:${liveSyncPort}`,\n };\n};\n\n/**\n * Build the log section of the Intlayer configuration.\n *\n * @param customConfiguration - Partial user-supplied log config.\n * @param logFunctions - Optional custom log function overrides (server-only).\n * @returns A fully-defaulted {@link LogConfig}.\n */\nexport const buildLogFields = (\n customConfiguration?: Partial<LogConfig>,\n logFunctions?: LogFunctions\n): LogConfig => ({\n /**\n * Indicates if the logger is enabled\n *\n * Default: 'prefix-no-default'\n *\n * If 'default', the logger is enabled and can be used.\n * If 'verbose', the logger will be enabled and can be used, but will log more information.\n * If 'disabled', the logger is disabled and cannot be used.\n */\n mode: customConfiguration?.mode ?? MODE,\n\n /**\n * Prefix of the logger\n *\n * Default: '[intlayer]'\n *\n * The prefix of the logger.\n */\n prefix: customConfiguration?.prefix ?? PREFIX,\n\n /**\n * Functions to log\n */\n error: logFunctions?.error,\n log: logFunctions?.log,\n info: logFunctions?.info,\n warn: logFunctions?.warn,\n});\n\n// ---------------------------------------------------------------------------\n// Browser configuration builders\n// ---------------------------------------------------------------------------\n\n/**\n * Build a browser-safe {@link BrowserIntlayerConfig} from a raw user config.\n *\n * Applies defaults for every field and strips all server-only or sensitive\n * information (`system`, `content`, `build`, `compiler`, `dictionary`, `ai`,\n * `editor.clientId`, `editor.clientSecret`).\n *\n * This is the browser counterpart of `buildConfigurationFields`. It is safe\n * to call in browser environments because it has no Node.js dependencies.\n *\n * @param customConfig - Optional partial user-supplied Intlayer config.\n * @returns A browser-safe configuration object ready for `window.INTLAYER_CONFIG`.\n *\n * @example\n * ```ts\n * import { buildBrowserConfiguration } from '@intlayer/config/client';\n *\n * window.INTLAYER_CONFIG = buildBrowserConfiguration({\n * internationalization: { locales: ['en', 'fr'], defaultLocale: 'en' },\n * });\n * ```\n */\nexport const buildBrowserConfiguration = (\n customConfig?: CustomIntlayerConfig\n): BrowserIntlayerConfig => {\n const { locales, defaultLocale } = buildInternationalizationFields(\n customConfig?.internationalization\n );\n const routing = buildRoutingFields(customConfig?.routing);\n const {\n clientId: _clientId,\n clientSecret: _clientSecret,\n ...editorPublic\n } = buildEditorFields(customConfig?.editor);\n const { mode, prefix } = buildLogFields(customConfig?.log);\n\n return {\n internationalization: { locales, defaultLocale },\n routing,\n editor: editorPublic,\n log: { mode, prefix },\n metadata: {\n name: 'Intlayer',\n version: packageJson.version,\n doc: 'https://intlayer.org/docs',\n },\n };\n};\n\n/**\n * Extract a {@link BrowserIntlayerConfig} from an already-built full\n * {@link IntlayerConfig}.\n *\n * Used by build plugins (`vite-intlayer`, `withIntlayer`) which already hold\n * the full server-side config and need to inject the browser-safe subset at\n * compile time via a bundler `define`.\n *\n * @param config - A fully-built server-side Intlayer configuration.\n * @returns The browser-safe subset of that configuration.\n */\nexport const extractBrowserConfiguration = (\n config: IntlayerConfig\n): BrowserIntlayerConfig => ({\n internationalization: {\n locales: config.internationalization.locales,\n defaultLocale: config.internationalization.defaultLocale,\n },\n routing: {\n mode: config.routing.mode,\n storage: config.routing.storage,\n basePath: config.routing.basePath,\n rewrite: config.routing.rewrite,\n },\n editor: {\n applicationURL: config.editor.applicationURL,\n editorURL: config.editor.editorURL,\n cmsURL: config.editor.cmsURL,\n backendURL: config.editor.backendURL,\n port: config.editor.port,\n enabled: config.editor.enabled,\n dictionaryPriorityStrategy: config.editor.dictionaryPriorityStrategy,\n liveSync: config.editor.liveSync,\n liveSyncPort: config.editor.liveSyncPort,\n liveSyncURL: config.editor.liveSyncURL,\n },\n log: {\n mode: config.log.mode,\n prefix: config.log.prefix,\n },\n metadata: config.metadata,\n});\n"],"mappings":";;;;;;;;;;;;;;;;;AA0EA,MAAa,mCACX,yBACgC;CAOhC,SAAS,qBAAqB,WAAWA;CAWzC,iBACE,qBAAqB,mBACrB,qBAAqB,WACrBC;CAUF,YAAY,qBAAqB;CAOjC,eAAe,qBAAqB,iBAAiBC;CACtD;;;;;;;AAQD,MAAa,sBACX,wBACkB;CAClB,MAAM,UAAU,qBAAqB,WAAWC;AAEhD,QAAO;EAuBL,MAAM,qBAAqB;EAW3B,SAASC,wDAAqB,QAAQ;EAatC,UAAU,qBAAqB;EA6B/B,SAAS,qBAAqB;EAC/B;;;;;;;;;;;;AAaH,MAAa,qBACX,wBACiB;CACjB,MAAM,eAAe,qBAAqB;AAC1C,QAAO;EAQL,gBAAgB,qBAAqB;EASrC,WAAW,qBAAqB;EAKhC,QAAQ,qBAAqB;EAO7B,YAAY,qBAAqB;EAMjC,MAAM,qBAAqB;EAsB3B,SAAS,qBAAqB;EAW9B,UAAU,qBAAqB,YAAY;EAW3C,cAAc,qBAAqB,gBAAgB;EAYnD,4BACE,qBAAqB;EAWvB,UAAU,qBAAqB;EAO/B;EAOA,aACE,qBAAqB,eAAe,oBAAoB;EAC3D;;;;;;;;;AAUH,MAAa,kBACX,qBACA,kBACe;CAUf,MAAM,qBAAqB;CAS3B,QAAQ,qBAAqB,UAAUC;CAKvC,OAAO,cAAc;CACrB,KAAK,cAAc;CACnB,MAAM,cAAc;CACpB,MAAM,cAAc;CACrB;;;;;;;;;;;;;;;;;;;;;;;AA4BD,MAAa,6BACX,iBAC0B;CAC1B,MAAM,EAAE,SAAS,kBAAkB,gCACjC,cAAc,qBACf;CACD,MAAM,UAAU,mBAAmB,cAAc,QAAQ;CACzD,MAAM,EACJ,UAAU,WACV,cAAc,eACd,GAAG,iBACD,kBAAkB,cAAc,OAAO;CAC3C,MAAM,EAAE,MAAM,WAAW,eAAe,cAAc,IAAI;AAE1D,QAAO;EACL,sBAAsB;GAAE;GAAS;GAAe;EAChD;EACA,QAAQ;EACR,KAAK;GAAE;GAAM;GAAQ;EACrB,UAAU;GACR,MAAM;GACN,SAASC,qCAAY;GACrB,KAAK;GACN;EACF;;;;;;;;;;;;;AAcH,MAAa,+BACX,YAC2B;CAC3B,sBAAsB;EACpB,SAAS,OAAO,qBAAqB;EACrC,eAAe,OAAO,qBAAqB;EAC5C;CACD,SAAS;EACP,MAAM,OAAO,QAAQ;EACrB,SAAS,OAAO,QAAQ;EACxB,UAAU,OAAO,QAAQ;EACzB,SAAS,OAAO,QAAQ;EACzB;CACD,QAAQ;EACN,gBAAgB,OAAO,OAAO;EAC9B,WAAW,OAAO,OAAO;EACzB,QAAQ,OAAO,OAAO;EACtB,YAAY,OAAO,OAAO;EAC1B,MAAM,OAAO,OAAO;EACpB,SAAS,OAAO,OAAO;EACvB,4BAA4B,OAAO,OAAO;EAC1C,UAAU,OAAO,OAAO;EACxB,cAAc,OAAO,OAAO;EAC5B,aAAa,OAAO,OAAO;EAC5B;CACD,KAAK;EACH,MAAM,OAAO,IAAI;EACjB,QAAQ,OAAO,IAAI;EACpB;CACD,UAAU,OAAO;CAClB"}
@@ -4,10 +4,10 @@ const require_defaultValues_compiler = require('./compiler.cjs');
4
4
  const require_defaultValues_content = require('./content.cjs');
5
5
  const require_defaultValues_dictionary = require('./dictionary.cjs');
6
6
  const require_defaultValues_system = require('./system.cjs');
7
+ const require_defaultValues_routing = require('./routing.cjs');
7
8
  const require_defaultValues_editor = require('./editor.cjs');
8
9
  const require_defaultValues_internationalization = require('./internationalization.cjs');
9
10
  const require_defaultValues_log = require('./log.cjs');
10
- const require_defaultValues_routing = require('./routing.cjs');
11
11
 
12
12
  exports.APPLICATION_URL = require_defaultValues_editor.APPLICATION_URL;
13
13
  exports.BACKEND_URL = require_defaultValues_editor.BACKEND_URL;
@@ -1 +1 @@
1
- {"version":3,"file":"routing.cjs","names":[],"sources":["../../../src/defaultValues/routing.ts"],"sourcesContent":["import type { RoutingConfig } from '@intlayer/types/config';\n\nexport const HEADER_NAME = 'x-intlayer-locale';\n\nexport const COOKIE_NAME = 'INTLAYER_LOCALE';\nexport const LOCALE_STORAGE_NAME = 'INTLAYER_LOCALE';\n\nexport const BASE_PATH = '';\n\nexport const SERVER_SET_COOKIE = 'always';\n\nexport const ROUTING_MODE = 'prefix-no-default';\n\nexport const STORAGE: RoutingConfig['storage'] = ['cookie', 'header'];\n"],"mappings":";;;AAEA,MAAa,cAAc;AAE3B,MAAa,cAAc;AAC3B,MAAa,sBAAsB;AAEnC,MAAa,YAAY;AAEzB,MAAa,oBAAoB;AAEjC,MAAa,eAAe;AAE5B,MAAa,UAAoC,CAAC,UAAU,SAAS"}
1
+ {"version":3,"file":"routing.cjs","names":[],"sources":["../../../src/defaultValues/routing.ts"],"sourcesContent":["import type { RoutingStorageInput } from '@intlayer/types/config';\n\nexport const HEADER_NAME = 'x-intlayer-locale';\n\nexport const COOKIE_NAME = 'INTLAYER_LOCALE';\nexport const LOCALE_STORAGE_NAME = 'INTLAYER_LOCALE';\n\nexport const BASE_PATH = '';\n\nexport const SERVER_SET_COOKIE = 'always';\n\nexport const ROUTING_MODE = 'prefix-no-default';\n\nexport const STORAGE: RoutingStorageInput = ['cookie', 'header'];\n"],"mappings":";;;AAEA,MAAa,cAAc;AAE3B,MAAa,cAAc;AAC3B,MAAa,sBAAsB;AAEnC,MAAa,YAAY;AAEzB,MAAa,oBAAoB;AAEjC,MAAa,eAAe;AAE5B,MAAa,UAA+B,CAAC,UAAU,SAAS"}
@@ -11,23 +11,13 @@ const getPrefix = (configPrefix) => {
11
11
  return configPrefix;
12
12
  };
13
13
  const logger = (content, details) => {
14
- const isVerbose = details?.isVerbose ?? false;
15
- const mode = details?.config?.mode ?? "default";
16
- const level = details?.level ?? "info";
17
- const prefix = getPrefix(details?.config?.prefix);
18
- const log = details?.config?.log ?? console.log;
19
- const info = details?.config?.info ?? console.info;
20
- const warn = details?.config?.warn ?? console.warn;
21
- const error = details?.config?.error ?? console.error;
22
- const debug = details?.config?.debug ?? console.debug;
23
- if (mode === "disabled") return;
24
- if (isVerbose && mode !== "verbose") return;
14
+ const config = details?.config ?? {};
15
+ const mode = config.mode ?? "default";
16
+ if (mode === "disabled" || details?.isVerbose && mode !== "verbose") return;
17
+ const prefix = getPrefix(config.prefix);
25
18
  const flatContent = prefix ? [prefix, ...[content].flat()] : [content].flat();
26
- if (level === "debug") return debug(...flatContent);
27
- if (level === "info") return info(...flatContent);
28
- if (level === "warn") return warn(...flatContent);
29
- if (level === "error") return error(...flatContent);
30
- log(...flatContent);
19
+ const level = details?.level ?? "info";
20
+ (config[level] ?? console[level] ?? config.log ?? console.log)(...flatContent);
31
21
  };
32
22
  const spinnerFrames = [
33
23
  "⠋",
@@ -54,16 +44,10 @@ const getAppLogger = (configuration, globalDetails) => (content, details) => log
54
44
  ...details?.config ?? {}
55
45
  }
56
46
  });
57
- const colorize = (s, color, reset) => color ? `${color}${s}${reset ? typeof reset === "boolean" ? require_colors.RESET : reset : require_colors.RESET}` : s;
47
+ const colorize = (string, color, reset) => color ? `${color}${string}${reset ? typeof reset === "boolean" ? require_colors.RESET : reset : require_colors.RESET}` : string;
58
48
  const colorizeLocales = (locales, color = require_colors.GREEN, reset = require_colors.RESET) => [locales].flat().map((locale) => colorize(locale, color, reset)).join(`, `);
59
49
  const colorizeKey = (keyPath, color = require_colors.BEIGE, reset = require_colors.RESET) => [keyPath].flat().map((key) => colorize(key, color, reset)).join(`, `);
60
50
  const colorizePath = (path, color = require_colors.GREY, reset = require_colors.RESET) => [path].flat().map((path) => colorize(path, color, reset)).join(`, `);
61
- /**
62
- * Colorize numeric value using Intl.NumberFormat and optional ANSI colors.
63
- *
64
- * Examples:
65
- * colorizeNumber(2, [{ pluralRule: 'one' , color: ANSIColors.GREEN}, { pluralRule: 'other' , color: ANSIColors.RED}]) // "'\x1b[31m2\x1b[0m"
66
- */
67
51
  const colorizeNumber = (number, options = {
68
52
  zero: require_colors.BLUE,
69
53
  one: require_colors.BLUE,
@@ -72,7 +56,7 @@ const colorizeNumber = (number, options = {
72
56
  many: require_colors.BLUE,
73
57
  other: require_colors.BLUE
74
58
  }) => {
75
- if (number === 0) {
59
+ if (number === 0 || number === "0") {
76
60
  const color = options.zero ?? "\x1B[32m";
77
61
  return colorize(number.toString(), color);
78
62
  }
@@ -84,8 +68,8 @@ const getLength = (length) => {
84
68
  let value = 0;
85
69
  if (typeof length === "number") value = length;
86
70
  if (typeof length === "string") value = length.length;
87
- if (Array.isArray(length) && length.every((l) => typeof l === "string")) value = Math.max(...length.map((str) => str.length));
88
- if (Array.isArray(length) && length.every((l) => typeof l === "number")) value = Math.max(...length);
71
+ if (Array.isArray(length) && length.every((locale) => typeof locale === "string")) value = Math.max(...length.map((str) => str.length));
72
+ if (Array.isArray(length) && length.every((locale) => typeof locale === "number")) value = Math.max(...length);
89
73
  return Math.max(value, 0);
90
74
  };
91
75
  const defaultColonOptions = {
@@ -1 +1 @@
1
- {"version":3,"file":"logger.cjs","names":[],"sources":["../../src/logger.ts"],"sourcesContent":["import type { Locale } from '@intlayer/types/allLocales';\nimport type { CustomIntlayerConfig } from '@intlayer/types/config';\nimport * as ANSIColors from './colors';\n\nexport type ANSIColorsType = (typeof ANSIColors)[keyof typeof ANSIColors];\n\nexport type Details = {\n isVerbose?: boolean;\n level?: 'info' | 'warn' | 'error' | 'debug';\n config?: CustomIntlayerConfig['log'];\n};\n\nexport type Logger = (content: any, details?: Details) => void;\n\nlet loggerPrefix: string | undefined;\n\nexport const setPrefix = (prefix: string | undefined) => {\n loggerPrefix = prefix;\n};\n\nexport const getPrefix = (configPrefix?: string): string | undefined => {\n if (typeof loggerPrefix !== 'undefined') {\n return loggerPrefix;\n }\n\n return configPrefix;\n};\n\nexport const logger: Logger = (content, details) => {\n const isVerbose = details?.isVerbose ?? false;\n const mode = details?.config?.mode ?? 'default';\n const level = details?.level ?? 'info';\n const prefix = getPrefix(details?.config?.prefix);\n const log = details?.config?.log ?? console.log;\n const info = details?.config?.info ?? console.info;\n const warn = details?.config?.warn ?? console.warn;\n const error = details?.config?.error ?? console.error;\n const debug = details?.config?.debug ?? console.debug;\n\n if (mode === 'disabled') return;\n\n if (isVerbose && mode !== 'verbose') return;\n\n const flatContent = prefix ? [prefix, ...[content].flat()] : [content].flat();\n\n if (level === 'debug') {\n return debug(...flatContent);\n }\n\n if (level === 'info') {\n return info(...flatContent);\n }\n\n if (level === 'warn') {\n return warn(...flatContent);\n }\n\n if (level === 'error') {\n return error(...flatContent);\n }\n\n log(...flatContent);\n};\n\nexport const spinnerFrames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];\n\n/**\n * The appLogger function takes the logger and merges it with the configuration from the intlayer config file.\n * It allows overriding the default configuration by passing a config object in the details parameter.\n * The configuration is merged with the default configuration from the intlayer config file.\n */\nexport const getAppLogger =\n (configuration?: CustomIntlayerConfig, globalDetails?: Details) =>\n (content: any, details?: Details) =>\n logger(content, {\n ...(details ?? {}),\n config: {\n ...configuration?.log,\n ...globalDetails?.config,\n ...(details?.config ?? {}),\n },\n });\n\nexport const colorize = (\n s: string,\n color?: ANSIColorsType,\n reset?: boolean | ANSIColorsType\n): string =>\n color\n ? `${color}${s}${reset ? (typeof reset === 'boolean' ? ANSIColors.RESET : reset) : ANSIColors.RESET}`\n : s;\n\nexport const colorizeLocales = (\n locales: Locale | Locale[],\n color: ANSIColorsType = ANSIColors.GREEN,\n reset: boolean | ANSIColorsType = ANSIColors.RESET\n) =>\n [locales]\n .flat()\n .map((locale) => colorize(locale, color, reset))\n .join(`, `);\n\nexport const colorizeKey = (\n keyPath: string | string[],\n color: ANSIColorsType = ANSIColors.BEIGE,\n reset: boolean | ANSIColorsType = ANSIColors.RESET\n) =>\n [keyPath]\n .flat()\n .map((key) => colorize(key, color, reset))\n .join(`, `);\n\nexport const colorizePath = (\n path: string | string[],\n color: ANSIColorsType = ANSIColors.GREY,\n reset: boolean | ANSIColorsType = ANSIColors.RESET\n) =>\n [path]\n .flat()\n .map((path) => colorize(path, color, reset))\n .join(`, `);\n\n/**\n * Colorize numeric value using Intl.NumberFormat and optional ANSI colors.\n *\n * Examples:\n * colorizeNumber(2, [{ pluralRule: 'one' , color: ANSIColors.GREEN}, { pluralRule: 'other' , color: ANSIColors.RED}]) // \"'\\x1b[31m2\\x1b[0m\"\n */\nexport const colorizeNumber = (\n number: number | string,\n options: Partial<Record<Intl.LDMLPluralRule, ANSIColorsType>> = {\n zero: ANSIColors.BLUE,\n one: ANSIColors.BLUE,\n two: ANSIColors.BLUE,\n few: ANSIColors.BLUE,\n many: ANSIColors.BLUE,\n other: ANSIColors.BLUE,\n }\n): string => {\n if (number === 0) {\n const color = options.zero ?? ANSIColors.GREEN;\n return colorize(number.toString(), color);\n }\n\n const rule = new Intl.PluralRules('en').select(Number(number));\n const color = options[rule];\n return colorize(number.toString(), color);\n};\n\nexport const removeColor = (text: string) =>\n // biome-ignore lint/suspicious/noControlCharactersInRegex: we need to remove the color codes\n text.replace(/\\x1b\\[[0-9;]*m/g, '');\n\nconst getLength = (length: number | number[] | string | string[]): number => {\n let value: number = 0;\n if (typeof length === 'number') {\n value = length;\n }\n if (typeof length === 'string') {\n value = length.length;\n }\n if (Array.isArray(length) && length.every((l) => typeof l === 'string')) {\n value = Math.max(...length.map((str) => str.length));\n }\n if (Array.isArray(length) && length.every((l) => typeof l === 'number')) {\n value = Math.max(...length);\n }\n return Math.max(value, 0);\n};\n\nconst defaultColonOptions = {\n colSize: 0,\n minSize: 0,\n maxSize: Infinity,\n pad: 'right',\n padChar: '0',\n};\n\n/**\n * Create a string of spaces of a given length.\n *\n * @param colSize - The length of the string to create.\n * @returns A string of spaces.\n */\nexport const colon = (\n text: string | string[],\n options?: {\n colSize?: number | number[] | string | string[];\n minSize?: number;\n maxSize?: number;\n pad?: 'left' | 'right';\n padChar?: string;\n }\n): string =>\n [text]\n .flat()\n .map((text) => {\n const { colSize, minSize, maxSize, pad } = {\n ...defaultColonOptions,\n ...(options ?? {}),\n };\n\n const length = getLength(colSize);\n const spacesLength = Math.max(\n minSize!,\n Math.min(maxSize!, length - removeColor(text).length)\n );\n\n if (pad === 'left') {\n return `${' '.repeat(spacesLength)}${text}`;\n }\n\n return `${text}${' '.repeat(spacesLength)}`;\n })\n .join('');\n\nexport const x = colorize('✗', ANSIColors.RED);\nexport const v = colorize('✓', ANSIColors.GREEN);\nexport const clock = colorize('⏲', ANSIColors.BLUE);\n"],"mappings":"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"}
1
+ {"version":3,"file":"logger.cjs","names":["RESET","GREEN","BEIGE","GREY","BLUE","RED"],"sources":["../../src/logger.ts"],"sourcesContent":["import type { Locale } from '@intlayer/types/allLocales';\nimport type {\n CustomIntlayerConfig,\n IntlayerConfig,\n} from '@intlayer/types/config';\nimport type * as ANSIColorsTypes from './colors';\nimport { BEIGE, BLUE, GREEN, GREY, RED, RESET } from './colors';\n\nexport type ANSIColorsType =\n (typeof ANSIColorsTypes)[keyof typeof ANSIColorsTypes];\n\nexport type Details = {\n isVerbose?: boolean;\n level?: 'info' | 'warn' | 'error' | 'debug';\n config?: CustomIntlayerConfig['log'];\n};\n\nexport type Logger = (content: any, details?: Details) => void;\n\nlet loggerPrefix: string | undefined;\n\nexport const setPrefix = (prefix: string | undefined) => {\n loggerPrefix = prefix;\n};\n\nexport const getPrefix = (configPrefix?: string): string | undefined => {\n if (typeof loggerPrefix !== 'undefined') {\n return loggerPrefix;\n }\n\n return configPrefix;\n};\n\nexport const logger: Logger = (content, details) => {\n const config = details?.config ?? {};\n const mode = config.mode ?? 'default';\n\n if (mode === 'disabled' || (details?.isVerbose && mode !== 'verbose')) return;\n\n const prefix = getPrefix(config.prefix);\n const flatContent = prefix ? [prefix, ...[content].flat()] : [content].flat();\n const level = details?.level ?? 'info';\n\n const logMethod =\n config[level] ?? console[level] ?? config.log ?? console.log;\n\n logMethod(...flatContent);\n};\n\nexport const spinnerFrames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];\n\n/**\n * The appLogger function takes the logger and merges it with the configuration from the intlayer config file.\n * It allows overriding the default configuration by passing a config object in the details parameter.\n * The configuration is merged with the default configuration from the intlayer config file.\n */\nexport const getAppLogger =\n (configuration?: IntlayerConfig, globalDetails?: Details) =>\n (content: any, details?: Details) =>\n logger(content, {\n ...(details ?? {}),\n config: {\n ...configuration?.log,\n ...globalDetails?.config,\n ...(details?.config ?? {}),\n },\n });\n\nexport const colorize = (\n string: string,\n color?: ANSIColorsType,\n reset?: boolean | ANSIColorsType\n): string =>\n color\n ? `${color}${string}${reset ? (typeof reset === 'boolean' ? RESET : reset) : RESET}`\n : string;\n\nexport const colorizeLocales = (\n locales: Locale | Locale[],\n color: ANSIColorsType = GREEN,\n reset: boolean | ANSIColorsType = RESET\n) =>\n [locales]\n .flat()\n .map((locale) => colorize(locale, color, reset))\n .join(`, `);\n\nexport const colorizeKey = (\n keyPath: string | string[],\n color: ANSIColorsType = BEIGE,\n reset: boolean | ANSIColorsType = RESET\n) =>\n [keyPath]\n .flat()\n .map((key) => colorize(key, color, reset))\n .join(`, `);\n\nexport const colorizePath = (\n path: string | string[],\n color: ANSIColorsType = GREY,\n reset: boolean | ANSIColorsType = RESET\n) =>\n [path]\n .flat()\n .map((path) => colorize(path, color, reset))\n .join(`, `);\n\nexport const colorizeNumber = (\n number: number | string,\n options: Partial<Record<Intl.LDMLPluralRule, ANSIColorsType>> = {\n zero: BLUE,\n one: BLUE,\n two: BLUE,\n few: BLUE,\n many: BLUE,\n other: BLUE,\n }\n): string => {\n if (number === 0 || number === '0') {\n const color = options.zero ?? GREEN;\n return colorize(number.toString(), color);\n }\n\n // Kept inside the function. Top-level instantiation of classes/APIs\n // is treated as a side-effect and prevents tree-shaking if the function is unused.\n const rule = new Intl.PluralRules('en').select(Number(number));\n const color = options[rule];\n return colorize(number.toString(), color);\n};\n\nexport const removeColor = (text: string) =>\n // biome-ignore lint/suspicious/noControlCharactersInRegex: we need to remove the color codes\n text.replace(/\\x1b\\[[0-9;]*m/g, '');\n\nconst getLength = (length: number | number[] | string | string[]): number => {\n let value: number = 0;\n if (typeof length === 'number') {\n value = length;\n }\n if (typeof length === 'string') {\n value = length.length;\n }\n if (\n Array.isArray(length) &&\n length.every((locale) => typeof locale === 'string')\n ) {\n value = Math.max(...length.map((str) => str.length));\n }\n if (\n Array.isArray(length) &&\n length.every((locale) => typeof locale === 'number')\n ) {\n value = Math.max(...length);\n }\n return Math.max(value, 0);\n};\n\nconst defaultColonOptions = {\n colSize: 0,\n minSize: 0,\n maxSize: Infinity,\n pad: 'right',\n padChar: '0',\n};\n\n/**\n * Create a string of spaces of a given length.\n *\n * @param colSize - The length of the string to create.\n * @returns A string of spaces.\n */\nexport const colon = (\n text: string | string[],\n options?: {\n colSize?: number | number[] | string | string[];\n minSize?: number;\n maxSize?: number;\n pad?: 'left' | 'right';\n padChar?: string;\n }\n): string =>\n [text]\n .flat()\n .map((text) => {\n const { colSize, minSize, maxSize, pad } = {\n ...defaultColonOptions,\n ...(options ?? {}),\n };\n\n const length = getLength(colSize);\n const spacesLength = Math.max(\n minSize!,\n Math.min(maxSize!, length - removeColor(text).length)\n );\n\n if (pad === 'left') {\n return `${' '.repeat(spacesLength)}${text}`;\n }\n\n return `${text}${' '.repeat(spacesLength)}`;\n })\n .join('');\n\nexport const x = colorize('✗', RED);\nexport const v = colorize('✓', GREEN);\nexport const clock = colorize('⏲', BLUE);\n"],"mappings":"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"}
@@ -0,0 +1,84 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_defaultValues_routing = require('../defaultValues/routing.cjs');
3
+
4
+ //#region src/utils/getStorageAttributes.ts
5
+ const createCookieEntry = (options) => {
6
+ const { name, path, expires, domain, secure, sameSite, httpOnly } = options ?? {};
7
+ return {
8
+ name: name ?? "INTLAYER_LOCALE",
9
+ attributes: {
10
+ path,
11
+ expires,
12
+ domain,
13
+ secure,
14
+ sameSite,
15
+ httpOnly
16
+ }
17
+ };
18
+ };
19
+ const createWebStorageEntry = (options) => ({ name: options?.name ?? "INTLAYER_LOCALE" });
20
+ const createHeaderEntry = (options) => ({ name: options?.name ?? "x-intlayer-locale" });
21
+ const isCookieEntry = (entry) => {
22
+ if (typeof entry !== "object" || entry === null) return false;
23
+ const e = entry;
24
+ return e["type"] === "cookie" || "sameSite" in e || "httpOnly" in e || "secure" in e;
25
+ };
26
+ const isStorageType = (value) => value === "cookie" || value === "localStorage" || value === "sessionStorage" || value === "header";
27
+ const processStorageEntry = (entry) => {
28
+ if (typeof entry === "string") {
29
+ if (!isStorageType(entry)) return {
30
+ cookies: [],
31
+ localStorage: [],
32
+ sessionStorage: [],
33
+ headers: []
34
+ };
35
+ if (entry === "cookie") return { cookies: [createCookieEntry()] };
36
+ if (entry === "localStorage") return { localStorage: [createWebStorageEntry()] };
37
+ if (entry === "sessionStorage") return { sessionStorage: [createWebStorageEntry()] };
38
+ if (entry === "header") return { headers: [createHeaderEntry()] };
39
+ }
40
+ if (typeof entry === "object" && entry !== null) {
41
+ const typedEntry = entry;
42
+ if (isCookieEntry(typedEntry)) return { cookies: [createCookieEntry(typedEntry)] };
43
+ if ("type" in typedEntry && typedEntry.type === "localStorage") return { localStorage: [createWebStorageEntry(typedEntry)] };
44
+ if ("type" in typedEntry && typedEntry.type === "sessionStorage") return { sessionStorage: [createWebStorageEntry(typedEntry)] };
45
+ if ("type" in typedEntry && typedEntry.type === "header") return { headers: [createHeaderEntry(typedEntry)] };
46
+ return { localStorage: [createWebStorageEntry(typedEntry)] };
47
+ }
48
+ return {
49
+ cookies: [],
50
+ localStorage: [],
51
+ sessionStorage: [],
52
+ headers: []
53
+ };
54
+ };
55
+ const mergeStorageAttributes = (accumulated, partial) => ({
56
+ cookies: [...accumulated.cookies, ...partial.cookies ?? []],
57
+ localStorage: [...accumulated.localStorage, ...partial.localStorage ?? []],
58
+ sessionStorage: [...accumulated.sessionStorage, ...partial.sessionStorage ?? []],
59
+ headers: [...accumulated.headers, ...partial.headers ?? []]
60
+ });
61
+ /**
62
+ * Extracts and normalizes storage configuration into separate arrays for each storage type.
63
+ * Called at config-build time so the result is pre-computed and stored in the config.
64
+ *
65
+ * @param options - The storage configuration from IntlayerConfig
66
+ * @returns An object containing arrays for cookies, localStorage, sessionStorage and headers
67
+ */
68
+ const getStorageAttributes = (options) => {
69
+ const emptyResult = {
70
+ cookies: [],
71
+ localStorage: [],
72
+ sessionStorage: [],
73
+ headers: []
74
+ };
75
+ if (options === false || options === void 0) return emptyResult;
76
+ if (Array.isArray(options)) return options.reduce((acc, entry) => {
77
+ return mergeStorageAttributes(acc, processStorageEntry(entry));
78
+ }, emptyResult);
79
+ return mergeStorageAttributes(emptyResult, processStorageEntry(options));
80
+ };
81
+
82
+ //#endregion
83
+ exports.getStorageAttributes = getStorageAttributes;
84
+ //# sourceMappingURL=getStorageAttributes.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getStorageAttributes.cjs","names":[],"sources":["../../../src/utils/getStorageAttributes.ts"],"sourcesContent":["import type {\n CookiesAttributes,\n ProcessedStorageAttributes,\n RoutingStorageInput,\n StorageAttributes,\n} from '@intlayer/types/config';\nimport {\n COOKIE_NAME,\n HEADER_NAME,\n LOCALE_STORAGE_NAME,\n} from '../defaultValues/routing';\n\n// ============================================================================\n// Types\n// ============================================================================\n\ntype CookieEntry = {\n name: string;\n attributes: Omit<CookiesAttributes, 'type' | 'name'>;\n};\n\ntype WebStorageEntry = {\n name: string;\n};\n\ntype HeaderEntry = {\n name: string;\n};\n\ntype StorageEntry =\n | 'cookie'\n | 'localStorage'\n | 'sessionStorage'\n | 'header'\n | CookiesAttributes\n | StorageAttributes;\n\n// ============================================================================\n// Helper Functions\n// ============================================================================\n\nconst createCookieEntry = (\n options?: Partial<CookiesAttributes>\n): CookieEntry => {\n const { name, path, expires, domain, secure, sameSite, httpOnly } =\n options ?? {};\n return {\n name: name ?? COOKIE_NAME,\n attributes: { path, expires, domain, secure, sameSite, httpOnly },\n };\n};\n\nconst createWebStorageEntry = (\n options?: Partial<StorageAttributes>\n): WebStorageEntry => ({\n name: options?.name ?? LOCALE_STORAGE_NAME,\n});\n\nconst createHeaderEntry = (\n options?: Partial<StorageAttributes>\n): HeaderEntry => ({\n name: options?.name ?? HEADER_NAME,\n});\n\nconst isCookieEntry = (entry: unknown): boolean => {\n if (typeof entry !== 'object' || entry === null) return false;\n const e = entry as Record<string, unknown>;\n return (\n e['type'] === 'cookie' ||\n 'sameSite' in e ||\n 'httpOnly' in e ||\n 'secure' in e\n );\n};\n\nconst isStorageType = (\n value: string\n): value is 'cookie' | 'localStorage' | 'sessionStorage' | 'header' =>\n value === 'cookie' ||\n value === 'localStorage' ||\n value === 'sessionStorage' ||\n value === 'header';\n\n// ============================================================================\n// Main Function\n// ============================================================================\n\nconst processStorageEntry = (\n entry: StorageEntry\n): Partial<ProcessedStorageAttributes> => {\n if (typeof entry === 'string') {\n if (!isStorageType(entry)) {\n return { cookies: [], localStorage: [], sessionStorage: [], headers: [] };\n }\n if (entry === 'cookie') return { cookies: [createCookieEntry()] };\n if (entry === 'localStorage')\n return { localStorage: [createWebStorageEntry()] };\n if (entry === 'sessionStorage')\n return { sessionStorage: [createWebStorageEntry()] };\n if (entry === 'header') return { headers: [createHeaderEntry()] };\n }\n\n if (typeof entry === 'object' && entry !== null) {\n const typedEntry = entry as CookiesAttributes | StorageAttributes;\n\n if (isCookieEntry(typedEntry)) {\n return { cookies: [createCookieEntry(typedEntry as CookiesAttributes)] };\n }\n if ('type' in typedEntry && typedEntry.type === 'localStorage') {\n return {\n localStorage: [createWebStorageEntry(typedEntry as StorageAttributes)],\n };\n }\n if ('type' in typedEntry && typedEntry.type === 'sessionStorage') {\n return {\n sessionStorage: [\n createWebStorageEntry(typedEntry as StorageAttributes),\n ],\n };\n }\n if ('type' in typedEntry && typedEntry.type === 'header') {\n return { headers: [createHeaderEntry(typedEntry as StorageAttributes)] };\n }\n // Default to localStorage for ambiguous objects\n return {\n localStorage: [\n createWebStorageEntry(typedEntry as Omit<StorageAttributes, 'type'>),\n ],\n };\n }\n\n return { cookies: [], localStorage: [], sessionStorage: [], headers: [] };\n};\n\nconst mergeStorageAttributes = (\n accumulated: ProcessedStorageAttributes,\n partial: Partial<ProcessedStorageAttributes>\n): ProcessedStorageAttributes => ({\n cookies: [...accumulated.cookies, ...(partial.cookies ?? [])],\n localStorage: [...accumulated.localStorage, ...(partial.localStorage ?? [])],\n sessionStorage: [\n ...accumulated.sessionStorage,\n ...(partial.sessionStorage ?? []),\n ],\n headers: [...accumulated.headers, ...(partial.headers ?? [])],\n});\n\n/**\n * Extracts and normalizes storage configuration into separate arrays for each storage type.\n * Called at config-build time so the result is pre-computed and stored in the config.\n *\n * @param options - The storage configuration from IntlayerConfig\n * @returns An object containing arrays for cookies, localStorage, sessionStorage and headers\n */\nexport const getStorageAttributes = (\n options: RoutingStorageInput\n): ProcessedStorageAttributes => {\n const emptyResult: ProcessedStorageAttributes = {\n cookies: [],\n localStorage: [],\n sessionStorage: [],\n headers: [],\n };\n\n if (options === false || options === undefined) return emptyResult;\n\n if (Array.isArray(options)) {\n return options.reduce<ProcessedStorageAttributes>((acc, entry) => {\n const partial = processStorageEntry(entry);\n return mergeStorageAttributes(acc, partial);\n }, emptyResult);\n }\n\n return mergeStorageAttributes(emptyResult, processStorageEntry(options));\n};\n"],"mappings":";;;;AAyCA,MAAM,qBACJ,YACgB;CAChB,MAAM,EAAE,MAAM,MAAM,SAAS,QAAQ,QAAQ,UAAU,aACrD,WAAW,EAAE;AACf,QAAO;EACL,MAAM;EACN,YAAY;GAAE;GAAM;GAAS;GAAQ;GAAQ;GAAU;GAAU;EAClE;;AAGH,MAAM,yBACJ,aACqB,EACrB,MAAM,SAAS,2BAChB;AAED,MAAM,qBACJ,aACiB,EACjB,MAAM,SAAS,6BAChB;AAED,MAAM,iBAAiB,UAA4B;AACjD,KAAI,OAAO,UAAU,YAAY,UAAU,KAAM,QAAO;CACxD,MAAM,IAAI;AACV,QACE,EAAE,YAAY,YACd,cAAc,KACd,cAAc,KACd,YAAY;;AAIhB,MAAM,iBACJ,UAEA,UAAU,YACV,UAAU,kBACV,UAAU,oBACV,UAAU;AAMZ,MAAM,uBACJ,UACwC;AACxC,KAAI,OAAO,UAAU,UAAU;AAC7B,MAAI,CAAC,cAAc,MAAM,CACvB,QAAO;GAAE,SAAS,EAAE;GAAE,cAAc,EAAE;GAAE,gBAAgB,EAAE;GAAE,SAAS,EAAE;GAAE;AAE3E,MAAI,UAAU,SAAU,QAAO,EAAE,SAAS,CAAC,mBAAmB,CAAC,EAAE;AACjE,MAAI,UAAU,eACZ,QAAO,EAAE,cAAc,CAAC,uBAAuB,CAAC,EAAE;AACpD,MAAI,UAAU,iBACZ,QAAO,EAAE,gBAAgB,CAAC,uBAAuB,CAAC,EAAE;AACtD,MAAI,UAAU,SAAU,QAAO,EAAE,SAAS,CAAC,mBAAmB,CAAC,EAAE;;AAGnE,KAAI,OAAO,UAAU,YAAY,UAAU,MAAM;EAC/C,MAAM,aAAa;AAEnB,MAAI,cAAc,WAAW,CAC3B,QAAO,EAAE,SAAS,CAAC,kBAAkB,WAAgC,CAAC,EAAE;AAE1E,MAAI,UAAU,cAAc,WAAW,SAAS,eAC9C,QAAO,EACL,cAAc,CAAC,sBAAsB,WAAgC,CAAC,EACvE;AAEH,MAAI,UAAU,cAAc,WAAW,SAAS,iBAC9C,QAAO,EACL,gBAAgB,CACd,sBAAsB,WAAgC,CACvD,EACF;AAEH,MAAI,UAAU,cAAc,WAAW,SAAS,SAC9C,QAAO,EAAE,SAAS,CAAC,kBAAkB,WAAgC,CAAC,EAAE;AAG1E,SAAO,EACL,cAAc,CACZ,sBAAsB,WAA8C,CACrE,EACF;;AAGH,QAAO;EAAE,SAAS,EAAE;EAAE,cAAc,EAAE;EAAE,gBAAgB,EAAE;EAAE,SAAS,EAAE;EAAE;;AAG3E,MAAM,0BACJ,aACA,aACgC;CAChC,SAAS,CAAC,GAAG,YAAY,SAAS,GAAI,QAAQ,WAAW,EAAE,CAAE;CAC7D,cAAc,CAAC,GAAG,YAAY,cAAc,GAAI,QAAQ,gBAAgB,EAAE,CAAE;CAC5E,gBAAgB,CACd,GAAG,YAAY,gBACf,GAAI,QAAQ,kBAAkB,EAAE,CACjC;CACD,SAAS,CAAC,GAAG,YAAY,SAAS,GAAI,QAAQ,WAAW,EAAE,CAAE;CAC9D;;;;;;;;AASD,MAAa,wBACX,YAC+B;CAC/B,MAAM,cAA0C;EAC9C,SAAS,EAAE;EACX,cAAc,EAAE;EAChB,gBAAgB,EAAE;EAClB,SAAS,EAAE;EACZ;AAED,KAAI,YAAY,SAAS,YAAY,OAAW,QAAO;AAEvD,KAAI,MAAM,QAAQ,QAAQ,CACxB,QAAO,QAAQ,QAAoC,KAAK,UAAU;AAEhE,SAAO,uBAAuB,KADd,oBAAoB,MAAM,CACC;IAC1C,YAAY;AAGjB,QAAO,uBAAuB,aAAa,oBAAoB,QAAQ,CAAC"}
@@ -9,6 +9,7 @@ const require_utils_ESMxCJSHelpers = require('./ESMxCJSHelpers.cjs');
9
9
  const require_utils_clearModuleCache = require('./clearModuleCache.cjs');
10
10
  const require_utils_compareVersions = require('./compareVersions.cjs');
11
11
  const require_utils_extractErrorMessage = require('./extractErrorMessage.cjs');
12
+ const require_utils_getStorageAttributes = require('./getStorageAttributes.cjs');
12
13
  const require_utils_logStack = require('./logStack.cjs');
13
14
  const require_utils_parseFilePathPattern = require('./parseFilePathPattern.cjs');
14
15
  const require_utils_retryManager = require('./retryManager.cjs');
@@ -34,6 +35,7 @@ exports.getCache = require_utils_cacheMemory.getCache;
34
35
  exports.getExtension = require_utils_getExtension.getExtension;
35
36
  exports.getPackageJsonPath = require_utils_getPackageJsonPath.getPackageJsonPath;
36
37
  exports.getProjectRequire = require_utils_ESMxCJSHelpers.getProjectRequire;
38
+ exports.getStorageAttributes = require_utils_getStorageAttributes.getStorageAttributes;
37
39
  exports.isESModule = require_utils_ESMxCJSHelpers.isESModule;
38
40
  exports.kebabCaseToCamelCase = require_utils_stringFormatter_kebabCaseToCamelCase.kebabCaseToCamelCase;
39
41
  exports.logStack = require_utils_logStack.logStack;
@@ -6,7 +6,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
6
6
  * e.g. "MyNewComponent" => "my-new-component"
7
7
  */
8
8
  const camelCaseToKebabCase = (str) => {
9
- return str.replace(/([a-z])([A-Z])/g, "$1-$2").replace(/([A-Z])([A-Z][a-z])/g, "$1-$2").toLowerCase();
9
+ return str.replace(/([a-z])([A-Z])/g, "$1-$2").replace(/([A-Z])([A-Z][a-z])/g, "$1-$2").replace(/[\s_]+/g, "-").toLowerCase();
10
10
  };
11
11
 
12
12
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"camelCaseToKebabCase.cjs","names":[],"sources":["../../../../src/utils/stringFormatter/camelCaseToKebabCase.ts"],"sourcesContent":["/**\n * Convert a string to kebab-case\n * e.g. \"MyNewComponent\" => \"my-new-component\"\n */\nexport const camelCaseToKebabCase = (str: string): string => {\n // Split on transition from lower->upper: \"MyNewComponent\" => [\"My\", \"New\", \"Component\"]\n // Then lowercase each chunk and join by \"-\"\n return str\n .replace(/([a-z])([A-Z])/g, '$1-$2')\n .replace(/([A-Z])([A-Z][a-z])/g, '$1-$2')\n .toLowerCase();\n};\n"],"mappings":";;;;;;;AAIA,MAAa,wBAAwB,QAAwB;AAG3D,QAAO,IACJ,QAAQ,mBAAmB,QAAQ,CACnC,QAAQ,wBAAwB,QAAQ,CACxC,aAAa"}
1
+ {"version":3,"file":"camelCaseToKebabCase.cjs","names":[],"sources":["../../../../src/utils/stringFormatter/camelCaseToKebabCase.ts"],"sourcesContent":["/**\n * Convert a string to kebab-case\n * e.g. \"MyNewComponent\" => \"my-new-component\"\n */\nexport const camelCaseToKebabCase = (str: string): string => {\n // Split on transition from lower->upper: \"MyNewComponent\" => [\"My\", \"New\", \"Component\"]\n // Then lowercase each chunk and join by \"-\"\n return str\n .replace(/([a-z])([A-Z])/g, '$1-$2')\n .replace(/([A-Z])([A-Z][a-z])/g, '$1-$2')\n .replace(/[\\s_]+/g, '-')\n .toLowerCase();\n};\n"],"mappings":";;;;;;;AAIA,MAAa,wBAAwB,QAAwB;AAG3D,QAAO,IACJ,QAAQ,mBAAmB,QAAQ,CACnC,QAAQ,wBAAwB,QAAQ,CACxC,QAAQ,WAAW,IAAI,CACvB,aAAa"}
@@ -1,7 +1,8 @@
1
+ import { BASE_PATH, ROUTING_MODE, STORAGE } from "../defaultValues/routing.mjs";
2
+ import { getStorageAttributes } from "../utils/getStorageAttributes.mjs";
1
3
  import { APPLICATION_URL, BACKEND_URL, CMS_URL, DICTIONARY_PRIORITY_STRATEGY, EDITOR_URL, IS_ENABLED, LIVE_SYNC, LIVE_SYNC_PORT, PORT } from "../defaultValues/editor.mjs";
2
4
  import { DEFAULT_LOCALE, LOCALES, REQUIRED_LOCALES, STRICT_MODE } from "../defaultValues/internationalization.mjs";
3
5
  import { MODE, PREFIX } from "../defaultValues/log.mjs";
4
- import { BASE_PATH, ROUTING_MODE, STORAGE } from "../defaultValues/routing.mjs";
5
6
  import packageJson from "@intlayer/types/package.json" with { type: "json" };
6
7
 
7
8
  //#region src/configFile/buildBrowserConfiguration.ts
@@ -23,12 +24,15 @@ const buildInternationalizationFields = (customConfiguration) => ({
23
24
  * @param customConfiguration - Partial user-supplied routing config.
24
25
  * @returns A fully-defaulted {@link RoutingConfig}.
25
26
  */
26
- const buildRoutingFields = (customConfiguration) => ({
27
- mode: customConfiguration?.mode ?? "prefix-no-default",
28
- storage: customConfiguration?.storage ?? STORAGE,
29
- basePath: customConfiguration?.basePath ?? "",
30
- rewrite: customConfiguration?.rewrite
31
- });
27
+ const buildRoutingFields = (customConfiguration) => {
28
+ const storage = customConfiguration?.storage ?? STORAGE;
29
+ return {
30
+ mode: customConfiguration?.mode ?? "prefix-no-default",
31
+ storage: getStorageAttributes(storage),
32
+ basePath: customConfiguration?.basePath ?? "",
33
+ rewrite: customConfiguration?.rewrite
34
+ };
35
+ };
32
36
  /**
33
37
  * Build the editor section of the Intlayer configuration.
34
38
  *
@@ -1 +1 @@
1
- {"version":3,"file":"buildBrowserConfiguration.mjs","names":[],"sources":["../../../src/configFile/buildBrowserConfiguration.ts"],"sourcesContent":["import type {\n CustomIntlayerConfig,\n EditorConfig,\n InternationalizationConfig,\n IntlayerConfig,\n LogConfig,\n LogFunctions,\n RoutingConfig,\n} from '@intlayer/types/config';\nimport packageJson from '@intlayer/types/package.json' with { type: 'json' };\nimport {\n APPLICATION_URL,\n BACKEND_URL,\n CMS_URL,\n DICTIONARY_PRIORITY_STRATEGY,\n EDITOR_URL,\n IS_ENABLED,\n LIVE_SYNC,\n LIVE_SYNC_PORT,\n PORT,\n} from '../defaultValues/editor';\nimport {\n DEFAULT_LOCALE,\n LOCALES,\n REQUIRED_LOCALES,\n STRICT_MODE,\n} from '../defaultValues/internationalization';\nimport { MODE, PREFIX } from '../defaultValues/log';\nimport { BASE_PATH, ROUTING_MODE, STORAGE } from '../defaultValues/routing';\n\n// ---------------------------------------------------------------------------\n// Type\n// ---------------------------------------------------------------------------\n\n/**\n * Browser-safe subset of {@link IntlayerConfig}.\n *\n * Excludes server-only fields (`system`, `content`, `build`, `compiler`,\n * `dictionary`, `ai`) and sensitive editor credentials (`clientId`,\n * `clientSecret`) that must never be shipped to the browser.\n */\nexport type BrowserIntlayerConfig = {\n internationalization: Pick<\n InternationalizationConfig,\n 'locales' | 'defaultLocale'\n >;\n routing: RoutingConfig;\n editor: Omit<EditorConfig, 'clientId' | 'clientSecret'>;\n log: Pick<LogConfig, 'mode' | 'prefix'>;\n metadata: IntlayerConfig['metadata'];\n};\n\ndeclare global {\n interface Window {\n /** Browser-safe Intlayer configuration injected by a build plugin or `installIntlayer`. */\n INTLAYER_CONFIG?: BrowserIntlayerConfig;\n }\n}\n\n// ---------------------------------------------------------------------------\n// Shared field builders (browser-safe — no Node.js APIs)\n//\n// These functions are re-used by both `buildBrowserConfiguration` (browser)\n// and `buildConfigurationFields` (server) to avoid duplication.\n// ---------------------------------------------------------------------------\n\n/**\n * Build the internationalization section of the Intlayer configuration.\n *\n * @param customConfiguration - Partial user-supplied internationalization config.\n * @returns A fully-defaulted {@link InternationalizationConfig}.\n */\nexport const buildInternationalizationFields = (\n customConfiguration?: Partial<InternationalizationConfig>\n): InternationalizationConfig => ({\n /**\n * Locales available in the application\n *\n * Default: ['en']\n *\n */\n locales: customConfiguration?.locales ?? LOCALES,\n\n /**\n * Locales required by TypeScript to ensure strong implementations of internationalized content using typescript.\n *\n * Default: []\n *\n * If empty, all locales are required in `strict` mode.\n *\n * Ensure required locales are also defined in the `locales` field.\n */\n requiredLocales:\n customConfiguration?.requiredLocales ??\n customConfiguration?.locales ??\n REQUIRED_LOCALES,\n\n /**\n * Ensure strong implementations of internationalized content using typescript.\n * - If set to \"strict\", the translation `t` function will require each declared locales to be defined. If one locale is missing, or if a locale is not declared in your config, it will throw an error.\n * - If set to \"inclusive\", the translation `t` function will require each declared locales to be defined. If one locale is missing, it will throw a warning. But will accept if a locale is not declared in your config, but exist.\n * - If set to \"loose\", the translation `t` function will accept any existing locale.\n *\n * Default: \"inclusive\"\n */\n strictMode: customConfiguration?.strictMode ?? STRICT_MODE,\n\n /**\n * Default locale of the application for fallback\n *\n * Default: 'en'\n */\n defaultLocale: customConfiguration?.defaultLocale ?? DEFAULT_LOCALE,\n});\n\n/**\n * Build the routing section of the Intlayer configuration.\n *\n * @param customConfiguration - Partial user-supplied routing config.\n * @returns A fully-defaulted {@link RoutingConfig}.\n */\nexport const buildRoutingFields = (\n customConfiguration?: Partial<RoutingConfig>\n): RoutingConfig => ({\n /**\n * URL routing mode for locale handling\n *\n * Controls how locales are represented in application URLs:\n * - 'prefix-no-default': Prefix all locales except the default locale (default)\n * - en → /dashboard\n * - fr → /fr/dashboard\n *\n * - 'prefix-all': Prefix all locales including the default locale\n * - en → /en/dashboard\n * - fr → /fr/dashboard\n *\n * - 'search-params': Use search parameters for locale handling\n * - en → /dashboard?locale=en\n * - fr → /fr/dashboard?locale=fr\n *\n * - 'no-prefix': No locale prefixing in URLs\n * - en → /dashboard\n * - fr → /dashboard\n *\n * Default: 'prefix-no-default'\n */\n mode: customConfiguration?.mode ?? ROUTING_MODE,\n\n /**\n * Configuration for storing the locale in the client (localStorage or sessionStorage)\n *\n * If false, the locale will not be stored by the middleware.\n * If true, the locale storage will consider all default values. (cookie and header)\n *\n * Default: ['cookie', 'header']\n *\n */\n storage: customConfiguration?.storage ?? STORAGE,\n\n /**\n * Base path of the application URL\n *\n * Default: ''\n *\n * Example:\n * - If the application is hosted at https://example.com/my-app\n * - The base path is '/my-app'\n * - The URL will be https://example.com/my-app/en\n * - If the base path is not set, the URL will be https://example.com/en\n */\n basePath: customConfiguration?.basePath ?? BASE_PATH,\n\n /**\n * Custom URL rewriting rules that override the default routing mode for specific paths.\n * Allows you to define locale-specific paths that differ from the standard routing behavior.\n * Supports dynamic route parameters using `[param]` syntax.\n *\n * Default: undefined\n *\n * Example:\n * ```typescript\n * rewrite: {\n * \"/about\": {\n * en: \"/about\",\n * fr: \"/a-propos\",\n * },\n * \"/product/[slug]\": {\n * en: \"/product/[slug]\",\n * fr: \"/produit/[slug]\",\n * },\n * }\n * ```\n *\n * Note:\n * - The rewrite rules take precedence over the default `mode` behavior.\n * - If a path matches a rewrite rule, the localized path from the rewrite configuration will be used.\n * - Dynamic route parameters are supported using bracket notation (e.g., `[slug]`, `[id]`).\n * - Works with both Next.js and Vite applications.\n */\n rewrite: customConfiguration?.rewrite,\n});\n\n/**\n * Build the editor section of the Intlayer configuration.\n *\n * Returns the **full** {@link EditorConfig} including sensitive fields\n * (`clientId`, `clientSecret`). The browser-safe {@link BrowserIntlayerConfig}\n * omits those fields when exposing config to the client.\n *\n * @param customConfiguration - Partial user-supplied editor config.\n * @returns A fully-defaulted {@link EditorConfig}.\n */\nexport const buildEditorFields = (\n customConfiguration?: Partial<EditorConfig>\n): EditorConfig => {\n const liveSyncPort = customConfiguration?.liveSyncPort ?? LIVE_SYNC_PORT;\n return {\n /**\n * URL of the application. Used to restrict the origin of the editor for security reasons.\n *\n * > '*' means that the editor is accessible from any origin\n *\n * Default: '*'\n */\n applicationURL: customConfiguration?.applicationURL || APPLICATION_URL,\n\n /**\n * URL of the editor server. Used to restrict the origin of the editor for security reasons.\n *\n * > '*' means that the editor is accessible from any origin\n *\n * Default: '*'\n */\n editorURL: customConfiguration?.editorURL || EDITOR_URL,\n\n /**\n * URL of the CMS server. Used to restrict the origin of the editor for security reasons.\n */\n cmsURL: customConfiguration?.cmsURL || CMS_URL,\n\n /**\n * URL of the editor server\n *\n * Default: 'https://back.intlayer.org'\n */\n backendURL: customConfiguration?.backendURL || BACKEND_URL,\n\n /** Port of the editor server\n *\n * Default: 8000\n */\n port: customConfiguration?.port ?? PORT,\n\n /**\n * Indicates if the application interact with the visual editor\n *\n * Default: false;\n *\n * If true, the editor will be able to interact with the application.\n * If false, the editor will not be able to interact with the application.\n * In any case, the editor can only be enabled by the visual editor.\n * Disabling the editor for specific environments is a way to enforce the security.\n *\n * Usage:\n * ```js\n * {\n * // Other configurations\n * editor: {\n * enabled: process.env.NODE_ENV !== 'production',\n * }\n * };\n * ```\n */\n enabled: customConfiguration?.enabled ?? IS_ENABLED,\n\n /**\n * clientId and clientSecret allow the intlayer packages to authenticate with the backend using oAuth2 authentication.\n * An access token is use to authenticate the user related to the project.\n * To get an access token, go to https://app.intlayer.org/project and create an account.\n *\n * Default: undefined\n *\n * > Important: The clientId and clientSecret should be kept secret and not shared publicly. Please ensure to keep them in a secure location, such as environment variables.\n */\n clientId: customConfiguration?.clientId ?? undefined,\n\n /**\n * clientId and clientSecret allow the intlayer packages to authenticate with the backend using oAuth2 authentication.\n * An access token is use to authenticate the user related to the project.\n * To get an access token, go to https://app.intlayer.org/project and create an account.\n *\n * Default: undefined\n *\n * > Important: The clientId and clientSecret should be kept secret and not shared publicly. Please ensure to keep them in a secure location, such as environment variables.\n */\n clientSecret: customConfiguration?.clientSecret ?? undefined,\n\n /**\n * Strategy for prioritizing dictionaries. If a dictionary is both present online and locally, the content will be merge.\n * However, is a field is defined in both dictionary, this setting determines which fields takes the priority over the other.\n *\n * Default: 'local_first'\n *\n * The strategy for prioritizing dictionaries. It can be either 'local_first' or 'distant_first'.\n * - 'local_first': The first dictionary found in the locale is used.\n * - 'distant_first': The first dictionary found in the distant locales is used.\n */\n dictionaryPriorityStrategy:\n customConfiguration?.dictionaryPriorityStrategy ??\n DICTIONARY_PRIORITY_STRATEGY,\n\n /**\n * Indicates if the application should hot reload the locale configurations when a change is detected.\n * For example, when a new dictionary is added or updated, the application will update the content tu display in the page.\n *\n * The hot reload is only available for clients of the `enterprise` plan.\n *\n * Default: false\n */\n liveSync: customConfiguration?.liveSync ?? LIVE_SYNC,\n\n /**\n * Port of the live sync server\n *\n * Default: 4000\n */\n liveSyncPort,\n\n /**\n * URL of the live sync server in case of remote live sync server\n *\n * Default: `http://localhost:${LIVE_SYNC_PORT}`\n */\n liveSyncURL:\n customConfiguration?.liveSyncURL ?? `http://localhost:${liveSyncPort}`,\n };\n};\n\n/**\n * Build the log section of the Intlayer configuration.\n *\n * @param customConfiguration - Partial user-supplied log config.\n * @param logFunctions - Optional custom log function overrides (server-only).\n * @returns A fully-defaulted {@link LogConfig}.\n */\nexport const buildLogFields = (\n customConfiguration?: Partial<LogConfig>,\n logFunctions?: LogFunctions\n): LogConfig => ({\n /**\n * Indicates if the logger is enabled\n *\n * Default: 'prefix-no-default'\n *\n * If 'default', the logger is enabled and can be used.\n * If 'verbose', the logger will be enabled and can be used, but will log more information.\n * If 'disabled', the logger is disabled and cannot be used.\n */\n mode: customConfiguration?.mode ?? MODE,\n\n /**\n * Prefix of the logger\n *\n * Default: '[intlayer]'\n *\n * The prefix of the logger.\n */\n prefix: customConfiguration?.prefix ?? PREFIX,\n\n /**\n * Functions to log\n */\n error: logFunctions?.error,\n log: logFunctions?.log,\n info: logFunctions?.info,\n warn: logFunctions?.warn,\n});\n\n// ---------------------------------------------------------------------------\n// Browser configuration builders\n// ---------------------------------------------------------------------------\n\n/**\n * Build a browser-safe {@link BrowserIntlayerConfig} from a raw user config.\n *\n * Applies defaults for every field and strips all server-only or sensitive\n * information (`system`, `content`, `build`, `compiler`, `dictionary`, `ai`,\n * `editor.clientId`, `editor.clientSecret`).\n *\n * This is the browser counterpart of `buildConfigurationFields`. It is safe\n * to call in browser environments because it has no Node.js dependencies.\n *\n * @param customConfig - Optional partial user-supplied Intlayer config.\n * @returns A browser-safe configuration object ready for `window.INTLAYER_CONFIG`.\n *\n * @example\n * ```ts\n * import { buildBrowserConfiguration } from '@intlayer/config/client';\n *\n * window.INTLAYER_CONFIG = buildBrowserConfiguration({\n * internationalization: { locales: ['en', 'fr'], defaultLocale: 'en' },\n * });\n * ```\n */\nexport const buildBrowserConfiguration = (\n customConfig?: CustomIntlayerConfig\n): BrowserIntlayerConfig => {\n const { locales, defaultLocale } = buildInternationalizationFields(\n customConfig?.internationalization\n );\n const routing = buildRoutingFields(customConfig?.routing);\n const {\n clientId: _clientId,\n clientSecret: _clientSecret,\n ...editorPublic\n } = buildEditorFields(customConfig?.editor);\n const { mode, prefix } = buildLogFields(customConfig?.log);\n\n return {\n internationalization: { locales, defaultLocale },\n routing,\n editor: editorPublic,\n log: { mode, prefix },\n metadata: {\n name: 'Intlayer',\n version: packageJson.version,\n doc: 'https://intlayer.org/docs',\n },\n };\n};\n\n/**\n * Extract a {@link BrowserIntlayerConfig} from an already-built full\n * {@link IntlayerConfig}.\n *\n * Used by build plugins (`vite-intlayer`, `withIntlayer`) which already hold\n * the full server-side config and need to inject the browser-safe subset at\n * compile time via a bundler `define`.\n *\n * @param config - A fully-built server-side Intlayer configuration.\n * @returns The browser-safe subset of that configuration.\n */\nexport const extractBrowserConfiguration = (\n config: IntlayerConfig\n): BrowserIntlayerConfig => ({\n internationalization: {\n locales: config.internationalization.locales,\n defaultLocale: config.internationalization.defaultLocale,\n },\n routing: {\n mode: config.routing.mode,\n storage: config.routing.storage,\n basePath: config.routing.basePath,\n rewrite: config.routing.rewrite,\n },\n editor: {\n applicationURL: config.editor.applicationURL,\n editorURL: config.editor.editorURL,\n cmsURL: config.editor.cmsURL,\n backendURL: config.editor.backendURL,\n port: config.editor.port,\n enabled: config.editor.enabled,\n dictionaryPriorityStrategy: config.editor.dictionaryPriorityStrategy,\n liveSync: config.editor.liveSync,\n liveSyncPort: config.editor.liveSyncPort,\n liveSyncURL: config.editor.liveSyncURL,\n },\n log: {\n mode: config.log.mode,\n prefix: config.log.prefix,\n },\n metadata: config.metadata,\n});\n"],"mappings":";;;;;;;;;;;;;AAwEA,MAAa,mCACX,yBACgC;CAOhC,SAAS,qBAAqB,WAAW;CAWzC,iBACE,qBAAqB,mBACrB,qBAAqB,WACrB;CAUF,YAAY,qBAAqB;CAOjC,eAAe,qBAAqB,iBAAiB;CACtD;;;;;;;AAQD,MAAa,sBACX,yBACmB;CAuBnB,MAAM,qBAAqB;CAW3B,SAAS,qBAAqB,WAAW;CAazC,UAAU,qBAAqB;CA6B/B,SAAS,qBAAqB;CAC/B;;;;;;;;;;;AAYD,MAAa,qBACX,wBACiB;CACjB,MAAM,eAAe,qBAAqB;AAC1C,QAAO;EAQL,gBAAgB,qBAAqB;EASrC,WAAW,qBAAqB;EAKhC,QAAQ,qBAAqB;EAO7B,YAAY,qBAAqB;EAMjC,MAAM,qBAAqB;EAsB3B,SAAS,qBAAqB;EAW9B,UAAU,qBAAqB,YAAY;EAW3C,cAAc,qBAAqB,gBAAgB;EAYnD,4BACE,qBAAqB;EAWvB,UAAU,qBAAqB;EAO/B;EAOA,aACE,qBAAqB,eAAe,oBAAoB;EAC3D;;;;;;;;;AAUH,MAAa,kBACX,qBACA,kBACe;CAUf,MAAM,qBAAqB;CAS3B,QAAQ,qBAAqB,UAAU;CAKvC,OAAO,cAAc;CACrB,KAAK,cAAc;CACnB,MAAM,cAAc;CACpB,MAAM,cAAc;CACrB;;;;;;;;;;;;;;;;;;;;;;;AA4BD,MAAa,6BACX,iBAC0B;CAC1B,MAAM,EAAE,SAAS,kBAAkB,gCACjC,cAAc,qBACf;CACD,MAAM,UAAU,mBAAmB,cAAc,QAAQ;CACzD,MAAM,EACJ,UAAU,WACV,cAAc,eACd,GAAG,iBACD,kBAAkB,cAAc,OAAO;CAC3C,MAAM,EAAE,MAAM,WAAW,eAAe,cAAc,IAAI;AAE1D,QAAO;EACL,sBAAsB;GAAE;GAAS;GAAe;EAChD;EACA,QAAQ;EACR,KAAK;GAAE;GAAM;GAAQ;EACrB,UAAU;GACR,MAAM;GACN,SAAS,YAAY;GACrB,KAAK;GACN;EACF;;;;;;;;;;;;;AAcH,MAAa,+BACX,YAC2B;CAC3B,sBAAsB;EACpB,SAAS,OAAO,qBAAqB;EACrC,eAAe,OAAO,qBAAqB;EAC5C;CACD,SAAS;EACP,MAAM,OAAO,QAAQ;EACrB,SAAS,OAAO,QAAQ;EACxB,UAAU,OAAO,QAAQ;EACzB,SAAS,OAAO,QAAQ;EACzB;CACD,QAAQ;EACN,gBAAgB,OAAO,OAAO;EAC9B,WAAW,OAAO,OAAO;EACzB,QAAQ,OAAO,OAAO;EACtB,YAAY,OAAO,OAAO;EAC1B,MAAM,OAAO,OAAO;EACpB,SAAS,OAAO,OAAO;EACvB,4BAA4B,OAAO,OAAO;EAC1C,UAAU,OAAO,OAAO;EACxB,cAAc,OAAO,OAAO;EAC5B,aAAa,OAAO,OAAO;EAC5B;CACD,KAAK;EACH,MAAM,OAAO,IAAI;EACjB,QAAQ,OAAO,IAAI;EACpB;CACD,UAAU,OAAO;CAClB"}
1
+ {"version":3,"file":"buildBrowserConfiguration.mjs","names":[],"sources":["../../../src/configFile/buildBrowserConfiguration.ts"],"sourcesContent":["import type {\n CustomIntlayerConfig,\n CustomRoutingConfig,\n EditorConfig,\n InternationalizationConfig,\n IntlayerConfig,\n LogConfig,\n LogFunctions,\n RoutingConfig,\n} from '@intlayer/types/config';\nimport packageJson from '@intlayer/types/package.json' with { type: 'json' };\nimport {\n APPLICATION_URL,\n BACKEND_URL,\n CMS_URL,\n DICTIONARY_PRIORITY_STRATEGY,\n EDITOR_URL,\n IS_ENABLED,\n LIVE_SYNC,\n LIVE_SYNC_PORT,\n PORT,\n} from '../defaultValues/editor';\nimport {\n DEFAULT_LOCALE,\n LOCALES,\n REQUIRED_LOCALES,\n STRICT_MODE,\n} from '../defaultValues/internationalization';\nimport { MODE, PREFIX } from '../defaultValues/log';\nimport { BASE_PATH, ROUTING_MODE, STORAGE } from '../defaultValues/routing';\nimport { getStorageAttributes } from '../utils/getStorageAttributes';\n\n// ---------------------------------------------------------------------------\n// Type\n// ---------------------------------------------------------------------------\n\n/**\n * Browser-safe subset of {@link IntlayerConfig}.\n *\n * Excludes server-only fields (`system`, `content`, `build`, `compiler`,\n * `dictionary`, `ai`) and sensitive editor credentials (`clientId`,\n * `clientSecret`) that must never be shipped to the browser.\n */\nexport type BrowserIntlayerConfig = {\n internationalization: Pick<\n InternationalizationConfig,\n 'locales' | 'defaultLocale'\n >;\n routing: RoutingConfig;\n editor: Omit<EditorConfig, 'clientId' | 'clientSecret'>;\n log: Pick<LogConfig, 'mode' | 'prefix'>;\n metadata: IntlayerConfig['metadata'];\n};\n\ndeclare global {\n interface Window {\n /** Browser-safe Intlayer configuration injected by a build plugin or `installIntlayer`. */\n INTLAYER_CONFIG?: BrowserIntlayerConfig;\n }\n}\n\n// ---------------------------------------------------------------------------\n// Shared field builders (browser-safe — no Node.js APIs)\n//\n// These functions are re-used by both `buildBrowserConfiguration` (browser)\n// and `buildConfigurationFields` (server) to avoid duplication.\n// ---------------------------------------------------------------------------\n\n/**\n * Build the internationalization section of the Intlayer configuration.\n *\n * @param customConfiguration - Partial user-supplied internationalization config.\n * @returns A fully-defaulted {@link InternationalizationConfig}.\n */\nexport const buildInternationalizationFields = (\n customConfiguration?: Partial<InternationalizationConfig>\n): InternationalizationConfig => ({\n /**\n * Locales available in the application\n *\n * Default: ['en']\n *\n */\n locales: customConfiguration?.locales ?? LOCALES,\n\n /**\n * Locales required by TypeScript to ensure strong implementations of internationalized content using typescript.\n *\n * Default: []\n *\n * If empty, all locales are required in `strict` mode.\n *\n * Ensure required locales are also defined in the `locales` field.\n */\n requiredLocales:\n customConfiguration?.requiredLocales ??\n customConfiguration?.locales ??\n REQUIRED_LOCALES,\n\n /**\n * Ensure strong implementations of internationalized content using typescript.\n * - If set to \"strict\", the translation `t` function will require each declared locales to be defined. If one locale is missing, or if a locale is not declared in your config, it will throw an error.\n * - If set to \"inclusive\", the translation `t` function will require each declared locales to be defined. If one locale is missing, it will throw a warning. But will accept if a locale is not declared in your config, but exist.\n * - If set to \"loose\", the translation `t` function will accept any existing locale.\n *\n * Default: \"inclusive\"\n */\n strictMode: customConfiguration?.strictMode ?? STRICT_MODE,\n\n /**\n * Default locale of the application for fallback\n *\n * Default: 'en'\n */\n defaultLocale: customConfiguration?.defaultLocale ?? DEFAULT_LOCALE,\n});\n\n/**\n * Build the routing section of the Intlayer configuration.\n *\n * @param customConfiguration - Partial user-supplied routing config.\n * @returns A fully-defaulted {@link RoutingConfig}.\n */\nexport const buildRoutingFields = (\n customConfiguration?: Partial<CustomRoutingConfig>\n): RoutingConfig => {\n const storage = customConfiguration?.storage ?? STORAGE;\n\n return {\n /**\n * URL routing mode for locale handling\n *\n * Controls how locales are represented in application URLs:\n * - 'prefix-no-default': Prefix all locales except the default locale (default)\n * - en → /dashboard\n * - fr → /fr/dashboard\n *\n * - 'prefix-all': Prefix all locales including the default locale\n * - en → /en/dashboard\n * - fr → /fr/dashboard\n *\n * - 'search-params': Use search parameters for locale handling\n * - en → /dashboard?locale=en\n * - fr → /fr/dashboard?locale=fr\n *\n * - 'no-prefix': No locale prefixing in URLs\n * - en → /dashboard\n * - fr → /dashboard\n *\n * Default: 'prefix-no-default'\n */\n mode: customConfiguration?.mode ?? ROUTING_MODE,\n\n /**\n * Configuration for storing the locale in the client (localStorage or sessionStorage)\n *\n * If false, the locale will not be stored by the middleware.\n * If true, the locale storage will consider all default values. (cookie and header)\n *\n * Default: ['cookie', 'header']\n *\n */\n storage: getStorageAttributes(storage),\n\n /**\n * Base path of the application URL\n *\n * Default: ''\n *\n * Example:\n * - If the application is hosted at https://example.com/my-app\n * - The base path is '/my-app'\n * - The URL will be https://example.com/my-app/en\n * - If the base path is not set, the URL will be https://example.com/en\n */\n basePath: customConfiguration?.basePath ?? BASE_PATH,\n\n /**\n * Custom URL rewriting rules that override the default routing mode for specific paths.\n * Allows you to define locale-specific paths that differ from the standard routing behavior.\n * Supports dynamic route parameters using `[param]` syntax.\n *\n * Default: undefined\n *\n * Example:\n * ```typescript\n * rewrite: {\n * \"/about\": {\n * en: \"/about\",\n * fr: \"/a-propos\",\n * },\n * \"/product/[slug]\": {\n * en: \"/product/[slug]\",\n * fr: \"/produit/[slug]\",\n * },\n * }\n * ```\n *\n * Note:\n * - The rewrite rules take precedence over the default `mode` behavior.\n * - If a path matches a rewrite rule, the localized path from the rewrite configuration will be used.\n * - Dynamic route parameters are supported using bracket notation (e.g., `[slug]`, `[id]`).\n * - Works with both Next.js and Vite applications.\n */\n rewrite: customConfiguration?.rewrite,\n };\n};\n\n/**\n * Build the editor section of the Intlayer configuration.\n *\n * Returns the **full** {@link EditorConfig} including sensitive fields\n * (`clientId`, `clientSecret`). The browser-safe {@link BrowserIntlayerConfig}\n * omits those fields when exposing config to the client.\n *\n * @param customConfiguration - Partial user-supplied editor config.\n * @returns A fully-defaulted {@link EditorConfig}.\n */\nexport const buildEditorFields = (\n customConfiguration?: Partial<EditorConfig>\n): EditorConfig => {\n const liveSyncPort = customConfiguration?.liveSyncPort ?? LIVE_SYNC_PORT;\n return {\n /**\n * URL of the application. Used to restrict the origin of the editor for security reasons.\n *\n * > '*' means that the editor is accessible from any origin\n *\n * Default: '*'\n */\n applicationURL: customConfiguration?.applicationURL || APPLICATION_URL,\n\n /**\n * URL of the editor server. Used to restrict the origin of the editor for security reasons.\n *\n * > '*' means that the editor is accessible from any origin\n *\n * Default: '*'\n */\n editorURL: customConfiguration?.editorURL || EDITOR_URL,\n\n /**\n * URL of the CMS server. Used to restrict the origin of the editor for security reasons.\n */\n cmsURL: customConfiguration?.cmsURL || CMS_URL,\n\n /**\n * URL of the editor server\n *\n * Default: 'https://back.intlayer.org'\n */\n backendURL: customConfiguration?.backendURL || BACKEND_URL,\n\n /** Port of the editor server\n *\n * Default: 8000\n */\n port: customConfiguration?.port ?? PORT,\n\n /**\n * Indicates if the application interact with the visual editor\n *\n * Default: false;\n *\n * If true, the editor will be able to interact with the application.\n * If false, the editor will not be able to interact with the application.\n * In any case, the editor can only be enabled by the visual editor.\n * Disabling the editor for specific environments is a way to enforce the security.\n *\n * Usage:\n * ```js\n * {\n * // Other configurations\n * editor: {\n * enabled: process.env.NODE_ENV !== 'production',\n * }\n * };\n * ```\n */\n enabled: customConfiguration?.enabled ?? IS_ENABLED,\n\n /**\n * clientId and clientSecret allow the intlayer packages to authenticate with the backend using oAuth2 authentication.\n * An access token is use to authenticate the user related to the project.\n * To get an access token, go to https://app.intlayer.org/project and create an account.\n *\n * Default: undefined\n *\n * > Important: The clientId and clientSecret should be kept secret and not shared publicly. Please ensure to keep them in a secure location, such as environment variables.\n */\n clientId: customConfiguration?.clientId ?? undefined,\n\n /**\n * clientId and clientSecret allow the intlayer packages to authenticate with the backend using oAuth2 authentication.\n * An access token is use to authenticate the user related to the project.\n * To get an access token, go to https://app.intlayer.org/project and create an account.\n *\n * Default: undefined\n *\n * > Important: The clientId and clientSecret should be kept secret and not shared publicly. Please ensure to keep them in a secure location, such as environment variables.\n */\n clientSecret: customConfiguration?.clientSecret ?? undefined,\n\n /**\n * Strategy for prioritizing dictionaries. If a dictionary is both present online and locally, the content will be merge.\n * However, is a field is defined in both dictionary, this setting determines which fields takes the priority over the other.\n *\n * Default: 'local_first'\n *\n * The strategy for prioritizing dictionaries. It can be either 'local_first' or 'distant_first'.\n * - 'local_first': The first dictionary found in the locale is used.\n * - 'distant_first': The first dictionary found in the distant locales is used.\n */\n dictionaryPriorityStrategy:\n customConfiguration?.dictionaryPriorityStrategy ??\n DICTIONARY_PRIORITY_STRATEGY,\n\n /**\n * Indicates if the application should hot reload the locale configurations when a change is detected.\n * For example, when a new dictionary is added or updated, the application will update the content tu display in the page.\n *\n * The hot reload is only available for clients of the `enterprise` plan.\n *\n * Default: false\n */\n liveSync: customConfiguration?.liveSync ?? LIVE_SYNC,\n\n /**\n * Port of the live sync server\n *\n * Default: 4000\n */\n liveSyncPort,\n\n /**\n * URL of the live sync server in case of remote live sync server\n *\n * Default: `http://localhost:${LIVE_SYNC_PORT}`\n */\n liveSyncURL:\n customConfiguration?.liveSyncURL ?? `http://localhost:${liveSyncPort}`,\n };\n};\n\n/**\n * Build the log section of the Intlayer configuration.\n *\n * @param customConfiguration - Partial user-supplied log config.\n * @param logFunctions - Optional custom log function overrides (server-only).\n * @returns A fully-defaulted {@link LogConfig}.\n */\nexport const buildLogFields = (\n customConfiguration?: Partial<LogConfig>,\n logFunctions?: LogFunctions\n): LogConfig => ({\n /**\n * Indicates if the logger is enabled\n *\n * Default: 'prefix-no-default'\n *\n * If 'default', the logger is enabled and can be used.\n * If 'verbose', the logger will be enabled and can be used, but will log more information.\n * If 'disabled', the logger is disabled and cannot be used.\n */\n mode: customConfiguration?.mode ?? MODE,\n\n /**\n * Prefix of the logger\n *\n * Default: '[intlayer]'\n *\n * The prefix of the logger.\n */\n prefix: customConfiguration?.prefix ?? PREFIX,\n\n /**\n * Functions to log\n */\n error: logFunctions?.error,\n log: logFunctions?.log,\n info: logFunctions?.info,\n warn: logFunctions?.warn,\n});\n\n// ---------------------------------------------------------------------------\n// Browser configuration builders\n// ---------------------------------------------------------------------------\n\n/**\n * Build a browser-safe {@link BrowserIntlayerConfig} from a raw user config.\n *\n * Applies defaults for every field and strips all server-only or sensitive\n * information (`system`, `content`, `build`, `compiler`, `dictionary`, `ai`,\n * `editor.clientId`, `editor.clientSecret`).\n *\n * This is the browser counterpart of `buildConfigurationFields`. It is safe\n * to call in browser environments because it has no Node.js dependencies.\n *\n * @param customConfig - Optional partial user-supplied Intlayer config.\n * @returns A browser-safe configuration object ready for `window.INTLAYER_CONFIG`.\n *\n * @example\n * ```ts\n * import { buildBrowserConfiguration } from '@intlayer/config/client';\n *\n * window.INTLAYER_CONFIG = buildBrowserConfiguration({\n * internationalization: { locales: ['en', 'fr'], defaultLocale: 'en' },\n * });\n * ```\n */\nexport const buildBrowserConfiguration = (\n customConfig?: CustomIntlayerConfig\n): BrowserIntlayerConfig => {\n const { locales, defaultLocale } = buildInternationalizationFields(\n customConfig?.internationalization\n );\n const routing = buildRoutingFields(customConfig?.routing);\n const {\n clientId: _clientId,\n clientSecret: _clientSecret,\n ...editorPublic\n } = buildEditorFields(customConfig?.editor);\n const { mode, prefix } = buildLogFields(customConfig?.log);\n\n return {\n internationalization: { locales, defaultLocale },\n routing,\n editor: editorPublic,\n log: { mode, prefix },\n metadata: {\n name: 'Intlayer',\n version: packageJson.version,\n doc: 'https://intlayer.org/docs',\n },\n };\n};\n\n/**\n * Extract a {@link BrowserIntlayerConfig} from an already-built full\n * {@link IntlayerConfig}.\n *\n * Used by build plugins (`vite-intlayer`, `withIntlayer`) which already hold\n * the full server-side config and need to inject the browser-safe subset at\n * compile time via a bundler `define`.\n *\n * @param config - A fully-built server-side Intlayer configuration.\n * @returns The browser-safe subset of that configuration.\n */\nexport const extractBrowserConfiguration = (\n config: IntlayerConfig\n): BrowserIntlayerConfig => ({\n internationalization: {\n locales: config.internationalization.locales,\n defaultLocale: config.internationalization.defaultLocale,\n },\n routing: {\n mode: config.routing.mode,\n storage: config.routing.storage,\n basePath: config.routing.basePath,\n rewrite: config.routing.rewrite,\n },\n editor: {\n applicationURL: config.editor.applicationURL,\n editorURL: config.editor.editorURL,\n cmsURL: config.editor.cmsURL,\n backendURL: config.editor.backendURL,\n port: config.editor.port,\n enabled: config.editor.enabled,\n dictionaryPriorityStrategy: config.editor.dictionaryPriorityStrategy,\n liveSync: config.editor.liveSync,\n liveSyncPort: config.editor.liveSyncPort,\n liveSyncURL: config.editor.liveSyncURL,\n },\n log: {\n mode: config.log.mode,\n prefix: config.log.prefix,\n },\n metadata: config.metadata,\n});\n"],"mappings":";;;;;;;;;;;;;;AA0EA,MAAa,mCACX,yBACgC;CAOhC,SAAS,qBAAqB,WAAW;CAWzC,iBACE,qBAAqB,mBACrB,qBAAqB,WACrB;CAUF,YAAY,qBAAqB;CAOjC,eAAe,qBAAqB,iBAAiB;CACtD;;;;;;;AAQD,MAAa,sBACX,wBACkB;CAClB,MAAM,UAAU,qBAAqB,WAAW;AAEhD,QAAO;EAuBL,MAAM,qBAAqB;EAW3B,SAAS,qBAAqB,QAAQ;EAatC,UAAU,qBAAqB;EA6B/B,SAAS,qBAAqB;EAC/B;;;;;;;;;;;;AAaH,MAAa,qBACX,wBACiB;CACjB,MAAM,eAAe,qBAAqB;AAC1C,QAAO;EAQL,gBAAgB,qBAAqB;EASrC,WAAW,qBAAqB;EAKhC,QAAQ,qBAAqB;EAO7B,YAAY,qBAAqB;EAMjC,MAAM,qBAAqB;EAsB3B,SAAS,qBAAqB;EAW9B,UAAU,qBAAqB,YAAY;EAW3C,cAAc,qBAAqB,gBAAgB;EAYnD,4BACE,qBAAqB;EAWvB,UAAU,qBAAqB;EAO/B;EAOA,aACE,qBAAqB,eAAe,oBAAoB;EAC3D;;;;;;;;;AAUH,MAAa,kBACX,qBACA,kBACe;CAUf,MAAM,qBAAqB;CAS3B,QAAQ,qBAAqB,UAAU;CAKvC,OAAO,cAAc;CACrB,KAAK,cAAc;CACnB,MAAM,cAAc;CACpB,MAAM,cAAc;CACrB;;;;;;;;;;;;;;;;;;;;;;;AA4BD,MAAa,6BACX,iBAC0B;CAC1B,MAAM,EAAE,SAAS,kBAAkB,gCACjC,cAAc,qBACf;CACD,MAAM,UAAU,mBAAmB,cAAc,QAAQ;CACzD,MAAM,EACJ,UAAU,WACV,cAAc,eACd,GAAG,iBACD,kBAAkB,cAAc,OAAO;CAC3C,MAAM,EAAE,MAAM,WAAW,eAAe,cAAc,IAAI;AAE1D,QAAO;EACL,sBAAsB;GAAE;GAAS;GAAe;EAChD;EACA,QAAQ;EACR,KAAK;GAAE;GAAM;GAAQ;EACrB,UAAU;GACR,MAAM;GACN,SAAS,YAAY;GACrB,KAAK;GACN;EACF;;;;;;;;;;;;;AAcH,MAAa,+BACX,YAC2B;CAC3B,sBAAsB;EACpB,SAAS,OAAO,qBAAqB;EACrC,eAAe,OAAO,qBAAqB;EAC5C;CACD,SAAS;EACP,MAAM,OAAO,QAAQ;EACrB,SAAS,OAAO,QAAQ;EACxB,UAAU,OAAO,QAAQ;EACzB,SAAS,OAAO,QAAQ;EACzB;CACD,QAAQ;EACN,gBAAgB,OAAO,OAAO;EAC9B,WAAW,OAAO,OAAO;EACzB,QAAQ,OAAO,OAAO;EACtB,YAAY,OAAO,OAAO;EAC1B,MAAM,OAAO,OAAO;EACpB,SAAS,OAAO,OAAO;EACvB,4BAA4B,OAAO,OAAO;EAC1C,UAAU,OAAO,OAAO;EACxB,cAAc,OAAO,OAAO;EAC5B,aAAa,OAAO,OAAO;EAC5B;CACD,KAAK;EACH,MAAM,OAAO,IAAI;EACjB,QAAQ,OAAO,IAAI;EACpB;CACD,UAAU,OAAO;CAClB"}
@@ -3,9 +3,9 @@ import { COMPILER_DICTIONARY_KEY_PREFIX, COMPILER_ENABLED, COMPILER_NO_METADATA,
3
3
  import { CODE_DIR, CONTENT_DIR, EXCLUDED_PATHS, FILE_EXTENSIONS, I18NEXT_DICTIONARIES_DIR, REACT_INTL_MESSAGES_DIR, WATCH } from "./content.mjs";
4
4
  import { CONTENT_AUTO_TRANSFORMATION, FILL, IMPORT_MODE, LOCATION } from "./dictionary.mjs";
5
5
  import { CACHE_DIR, CONFIG_DIR, DICTIONARIES_DIR, DYNAMIC_DICTIONARIES_DIR, FETCH_DICTIONARIES_DIR, MAIN_DIR, MASKS_DIR, MODULE_AUGMENTATION_DIR, REMOTE_DICTIONARIES_DIR, TEMP_DIR, TYPES_DIR, UNMERGED_DICTIONARIES_DIR } from "./system.mjs";
6
+ import { BASE_PATH, COOKIE_NAME, HEADER_NAME, LOCALE_STORAGE_NAME, ROUTING_MODE, SERVER_SET_COOKIE, STORAGE } from "./routing.mjs";
6
7
  import { APPLICATION_URL, BACKEND_URL, CMS_URL, DICTIONARY_PRIORITY_STRATEGY, EDITOR_URL, IS_ENABLED, LIVE_SYNC, LIVE_SYNC_PORT, PORT } from "./editor.mjs";
7
8
  import { DEFAULT_LOCALE, LOCALES, REQUIRED_LOCALES, STRICT_MODE } from "./internationalization.mjs";
8
9
  import { MODE, PREFIX } from "./log.mjs";
9
- import { BASE_PATH, COOKIE_NAME, HEADER_NAME, LOCALE_STORAGE_NAME, ROUTING_MODE, SERVER_SET_COOKIE, STORAGE } from "./routing.mjs";
10
10
 
11
11
  export { APPLICATION_URL, BACKEND_URL, BASE_PATH, BUILD_MODE, CACHE, CACHE_DIR, CMS_URL, CODE_DIR, COMPILER_DICTIONARY_KEY_PREFIX, COMPILER_ENABLED, COMPILER_NO_METADATA, COMPILER_SAVE_COMPONENTS, CONFIG_DIR, CONTENT_AUTO_TRANSFORMATION, CONTENT_DIR, COOKIE_NAME, DEFAULT_LOCALE, DICTIONARIES_DIR, DICTIONARY_PRIORITY_STRATEGY, DYNAMIC_DICTIONARIES_DIR, EDITOR_URL, EXCLUDED_PATHS, FETCH_DICTIONARIES_DIR, FILE_EXTENSIONS, FILL, HEADER_NAME, I18NEXT_DICTIONARIES_DIR, IMPORT_MODE, IS_ENABLED, LIVE_SYNC, LIVE_SYNC_PORT, LOCALES, LOCALE_STORAGE_NAME, LOCATION, MAIN_DIR, MASKS_DIR, MODE, MODULE_AUGMENTATION_DIR, OPTIMIZE, OUTPUT_FORMAT, PORT, PREFIX, REACT_INTL_MESSAGES_DIR, REMOTE_DICTIONARIES_DIR, REQUIRED_LOCALES, ROUTING_MODE, SERVER_SET_COOKIE, STORAGE, STRICT_MODE, TEMP_DIR, TRAVERSE_PATTERN, TYPES_DIR, TYPE_CHECKING, UNMERGED_DICTIONARIES_DIR, WATCH };
@@ -1 +1 @@
1
- {"version":3,"file":"routing.mjs","names":[],"sources":["../../../src/defaultValues/routing.ts"],"sourcesContent":["import type { RoutingConfig } from '@intlayer/types/config';\n\nexport const HEADER_NAME = 'x-intlayer-locale';\n\nexport const COOKIE_NAME = 'INTLAYER_LOCALE';\nexport const LOCALE_STORAGE_NAME = 'INTLAYER_LOCALE';\n\nexport const BASE_PATH = '';\n\nexport const SERVER_SET_COOKIE = 'always';\n\nexport const ROUTING_MODE = 'prefix-no-default';\n\nexport const STORAGE: RoutingConfig['storage'] = ['cookie', 'header'];\n"],"mappings":";AAEA,MAAa,cAAc;AAE3B,MAAa,cAAc;AAC3B,MAAa,sBAAsB;AAEnC,MAAa,YAAY;AAEzB,MAAa,oBAAoB;AAEjC,MAAa,eAAe;AAE5B,MAAa,UAAoC,CAAC,UAAU,SAAS"}
1
+ {"version":3,"file":"routing.mjs","names":[],"sources":["../../../src/defaultValues/routing.ts"],"sourcesContent":["import type { RoutingStorageInput } from '@intlayer/types/config';\n\nexport const HEADER_NAME = 'x-intlayer-locale';\n\nexport const COOKIE_NAME = 'INTLAYER_LOCALE';\nexport const LOCALE_STORAGE_NAME = 'INTLAYER_LOCALE';\n\nexport const BASE_PATH = '';\n\nexport const SERVER_SET_COOKIE = 'always';\n\nexport const ROUTING_MODE = 'prefix-no-default';\n\nexport const STORAGE: RoutingStorageInput = ['cookie', 'header'];\n"],"mappings":";AAEA,MAAa,cAAc;AAE3B,MAAa,cAAc;AAC3B,MAAa,sBAAsB;AAEnC,MAAa,YAAY;AAEzB,MAAa,oBAAoB;AAEjC,MAAa,eAAe;AAE5B,MAAa,UAA+B,CAAC,UAAU,SAAS"}
@@ -10,23 +10,13 @@ const getPrefix = (configPrefix) => {
10
10
  return configPrefix;
11
11
  };
12
12
  const logger = (content, details) => {
13
- const isVerbose = details?.isVerbose ?? false;
14
- const mode = details?.config?.mode ?? "default";
15
- const level = details?.level ?? "info";
16
- const prefix = getPrefix(details?.config?.prefix);
17
- const log = details?.config?.log ?? console.log;
18
- const info = details?.config?.info ?? console.info;
19
- const warn = details?.config?.warn ?? console.warn;
20
- const error = details?.config?.error ?? console.error;
21
- const debug = details?.config?.debug ?? console.debug;
22
- if (mode === "disabled") return;
23
- if (isVerbose && mode !== "verbose") return;
13
+ const config = details?.config ?? {};
14
+ const mode = config.mode ?? "default";
15
+ if (mode === "disabled" || details?.isVerbose && mode !== "verbose") return;
16
+ const prefix = getPrefix(config.prefix);
24
17
  const flatContent = prefix ? [prefix, ...[content].flat()] : [content].flat();
25
- if (level === "debug") return debug(...flatContent);
26
- if (level === "info") return info(...flatContent);
27
- if (level === "warn") return warn(...flatContent);
28
- if (level === "error") return error(...flatContent);
29
- log(...flatContent);
18
+ const level = details?.level ?? "info";
19
+ (config[level] ?? console[level] ?? config.log ?? console.log)(...flatContent);
30
20
  };
31
21
  const spinnerFrames = [
32
22
  "⠋",
@@ -53,16 +43,10 @@ const getAppLogger = (configuration, globalDetails) => (content, details) => log
53
43
  ...details?.config ?? {}
54
44
  }
55
45
  });
56
- const colorize = (s, color, reset) => color ? `${color}${s}${reset ? typeof reset === "boolean" ? RESET : reset : RESET}` : s;
46
+ const colorize = (string, color, reset) => color ? `${color}${string}${reset ? typeof reset === "boolean" ? RESET : reset : RESET}` : string;
57
47
  const colorizeLocales = (locales, color = GREEN, reset = RESET) => [locales].flat().map((locale) => colorize(locale, color, reset)).join(`, `);
58
48
  const colorizeKey = (keyPath, color = BEIGE, reset = RESET) => [keyPath].flat().map((key) => colorize(key, color, reset)).join(`, `);
59
49
  const colorizePath = (path, color = GREY, reset = RESET) => [path].flat().map((path) => colorize(path, color, reset)).join(`, `);
60
- /**
61
- * Colorize numeric value using Intl.NumberFormat and optional ANSI colors.
62
- *
63
- * Examples:
64
- * colorizeNumber(2, [{ pluralRule: 'one' , color: ANSIColors.GREEN}, { pluralRule: 'other' , color: ANSIColors.RED}]) // "'\x1b[31m2\x1b[0m"
65
- */
66
50
  const colorizeNumber = (number, options = {
67
51
  zero: BLUE,
68
52
  one: BLUE,
@@ -71,7 +55,7 @@ const colorizeNumber = (number, options = {
71
55
  many: BLUE,
72
56
  other: BLUE
73
57
  }) => {
74
- if (number === 0) {
58
+ if (number === 0 || number === "0") {
75
59
  const color = options.zero ?? "\x1B[32m";
76
60
  return colorize(number.toString(), color);
77
61
  }
@@ -83,8 +67,8 @@ const getLength = (length) => {
83
67
  let value = 0;
84
68
  if (typeof length === "number") value = length;
85
69
  if (typeof length === "string") value = length.length;
86
- if (Array.isArray(length) && length.every((l) => typeof l === "string")) value = Math.max(...length.map((str) => str.length));
87
- if (Array.isArray(length) && length.every((l) => typeof l === "number")) value = Math.max(...length);
70
+ if (Array.isArray(length) && length.every((locale) => typeof locale === "string")) value = Math.max(...length.map((str) => str.length));
71
+ if (Array.isArray(length) && length.every((locale) => typeof locale === "number")) value = Math.max(...length);
88
72
  return Math.max(value, 0);
89
73
  };
90
74
  const defaultColonOptions = {
@@ -1 +1 @@
1
- {"version":3,"file":"logger.mjs","names":["ANSIColors.RESET","ANSIColors.GREEN","ANSIColors.BEIGE","ANSIColors.GREY","ANSIColors.BLUE","ANSIColors.RED"],"sources":["../../src/logger.ts"],"sourcesContent":["import type { Locale } from '@intlayer/types/allLocales';\nimport type { CustomIntlayerConfig } from '@intlayer/types/config';\nimport * as ANSIColors from './colors';\n\nexport type ANSIColorsType = (typeof ANSIColors)[keyof typeof ANSIColors];\n\nexport type Details = {\n isVerbose?: boolean;\n level?: 'info' | 'warn' | 'error' | 'debug';\n config?: CustomIntlayerConfig['log'];\n};\n\nexport type Logger = (content: any, details?: Details) => void;\n\nlet loggerPrefix: string | undefined;\n\nexport const setPrefix = (prefix: string | undefined) => {\n loggerPrefix = prefix;\n};\n\nexport const getPrefix = (configPrefix?: string): string | undefined => {\n if (typeof loggerPrefix !== 'undefined') {\n return loggerPrefix;\n }\n\n return configPrefix;\n};\n\nexport const logger: Logger = (content, details) => {\n const isVerbose = details?.isVerbose ?? false;\n const mode = details?.config?.mode ?? 'default';\n const level = details?.level ?? 'info';\n const prefix = getPrefix(details?.config?.prefix);\n const log = details?.config?.log ?? console.log;\n const info = details?.config?.info ?? console.info;\n const warn = details?.config?.warn ?? console.warn;\n const error = details?.config?.error ?? console.error;\n const debug = details?.config?.debug ?? console.debug;\n\n if (mode === 'disabled') return;\n\n if (isVerbose && mode !== 'verbose') return;\n\n const flatContent = prefix ? [prefix, ...[content].flat()] : [content].flat();\n\n if (level === 'debug') {\n return debug(...flatContent);\n }\n\n if (level === 'info') {\n return info(...flatContent);\n }\n\n if (level === 'warn') {\n return warn(...flatContent);\n }\n\n if (level === 'error') {\n return error(...flatContent);\n }\n\n log(...flatContent);\n};\n\nexport const spinnerFrames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];\n\n/**\n * The appLogger function takes the logger and merges it with the configuration from the intlayer config file.\n * It allows overriding the default configuration by passing a config object in the details parameter.\n * The configuration is merged with the default configuration from the intlayer config file.\n */\nexport const getAppLogger =\n (configuration?: CustomIntlayerConfig, globalDetails?: Details) =>\n (content: any, details?: Details) =>\n logger(content, {\n ...(details ?? {}),\n config: {\n ...configuration?.log,\n ...globalDetails?.config,\n ...(details?.config ?? {}),\n },\n });\n\nexport const colorize = (\n s: string,\n color?: ANSIColorsType,\n reset?: boolean | ANSIColorsType\n): string =>\n color\n ? `${color}${s}${reset ? (typeof reset === 'boolean' ? ANSIColors.RESET : reset) : ANSIColors.RESET}`\n : s;\n\nexport const colorizeLocales = (\n locales: Locale | Locale[],\n color: ANSIColorsType = ANSIColors.GREEN,\n reset: boolean | ANSIColorsType = ANSIColors.RESET\n) =>\n [locales]\n .flat()\n .map((locale) => colorize(locale, color, reset))\n .join(`, `);\n\nexport const colorizeKey = (\n keyPath: string | string[],\n color: ANSIColorsType = ANSIColors.BEIGE,\n reset: boolean | ANSIColorsType = ANSIColors.RESET\n) =>\n [keyPath]\n .flat()\n .map((key) => colorize(key, color, reset))\n .join(`, `);\n\nexport const colorizePath = (\n path: string | string[],\n color: ANSIColorsType = ANSIColors.GREY,\n reset: boolean | ANSIColorsType = ANSIColors.RESET\n) =>\n [path]\n .flat()\n .map((path) => colorize(path, color, reset))\n .join(`, `);\n\n/**\n * Colorize numeric value using Intl.NumberFormat and optional ANSI colors.\n *\n * Examples:\n * colorizeNumber(2, [{ pluralRule: 'one' , color: ANSIColors.GREEN}, { pluralRule: 'other' , color: ANSIColors.RED}]) // \"'\\x1b[31m2\\x1b[0m\"\n */\nexport const colorizeNumber = (\n number: number | string,\n options: Partial<Record<Intl.LDMLPluralRule, ANSIColorsType>> = {\n zero: ANSIColors.BLUE,\n one: ANSIColors.BLUE,\n two: ANSIColors.BLUE,\n few: ANSIColors.BLUE,\n many: ANSIColors.BLUE,\n other: ANSIColors.BLUE,\n }\n): string => {\n if (number === 0) {\n const color = options.zero ?? ANSIColors.GREEN;\n return colorize(number.toString(), color);\n }\n\n const rule = new Intl.PluralRules('en').select(Number(number));\n const color = options[rule];\n return colorize(number.toString(), color);\n};\n\nexport const removeColor = (text: string) =>\n // biome-ignore lint/suspicious/noControlCharactersInRegex: we need to remove the color codes\n text.replace(/\\x1b\\[[0-9;]*m/g, '');\n\nconst getLength = (length: number | number[] | string | string[]): number => {\n let value: number = 0;\n if (typeof length === 'number') {\n value = length;\n }\n if (typeof length === 'string') {\n value = length.length;\n }\n if (Array.isArray(length) && length.every((l) => typeof l === 'string')) {\n value = Math.max(...length.map((str) => str.length));\n }\n if (Array.isArray(length) && length.every((l) => typeof l === 'number')) {\n value = Math.max(...length);\n }\n return Math.max(value, 0);\n};\n\nconst defaultColonOptions = {\n colSize: 0,\n minSize: 0,\n maxSize: Infinity,\n pad: 'right',\n padChar: '0',\n};\n\n/**\n * Create a string of spaces of a given length.\n *\n * @param colSize - The length of the string to create.\n * @returns A string of spaces.\n */\nexport const colon = (\n text: string | string[],\n options?: {\n colSize?: number | number[] | string | string[];\n minSize?: number;\n maxSize?: number;\n pad?: 'left' | 'right';\n padChar?: string;\n }\n): string =>\n [text]\n .flat()\n .map((text) => {\n const { colSize, minSize, maxSize, pad } = {\n ...defaultColonOptions,\n ...(options ?? {}),\n };\n\n const length = getLength(colSize);\n const spacesLength = Math.max(\n minSize!,\n Math.min(maxSize!, length - removeColor(text).length)\n );\n\n if (pad === 'left') {\n return `${' '.repeat(spacesLength)}${text}`;\n }\n\n return `${text}${' '.repeat(spacesLength)}`;\n })\n .join('');\n\nexport const x = colorize('✗', ANSIColors.RED);\nexport const v = colorize('✓', ANSIColors.GREEN);\nexport const clock = colorize('⏲', ANSIColors.BLUE);\n"],"mappings":"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"}
1
+ {"version":3,"file":"logger.mjs","names":[],"sources":["../../src/logger.ts"],"sourcesContent":["import type { Locale } from '@intlayer/types/allLocales';\nimport type {\n CustomIntlayerConfig,\n IntlayerConfig,\n} from '@intlayer/types/config';\nimport type * as ANSIColorsTypes from './colors';\nimport { BEIGE, BLUE, GREEN, GREY, RED, RESET } from './colors';\n\nexport type ANSIColorsType =\n (typeof ANSIColorsTypes)[keyof typeof ANSIColorsTypes];\n\nexport type Details = {\n isVerbose?: boolean;\n level?: 'info' | 'warn' | 'error' | 'debug';\n config?: CustomIntlayerConfig['log'];\n};\n\nexport type Logger = (content: any, details?: Details) => void;\n\nlet loggerPrefix: string | undefined;\n\nexport const setPrefix = (prefix: string | undefined) => {\n loggerPrefix = prefix;\n};\n\nexport const getPrefix = (configPrefix?: string): string | undefined => {\n if (typeof loggerPrefix !== 'undefined') {\n return loggerPrefix;\n }\n\n return configPrefix;\n};\n\nexport const logger: Logger = (content, details) => {\n const config = details?.config ?? {};\n const mode = config.mode ?? 'default';\n\n if (mode === 'disabled' || (details?.isVerbose && mode !== 'verbose')) return;\n\n const prefix = getPrefix(config.prefix);\n const flatContent = prefix ? [prefix, ...[content].flat()] : [content].flat();\n const level = details?.level ?? 'info';\n\n const logMethod =\n config[level] ?? console[level] ?? config.log ?? console.log;\n\n logMethod(...flatContent);\n};\n\nexport const spinnerFrames = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];\n\n/**\n * The appLogger function takes the logger and merges it with the configuration from the intlayer config file.\n * It allows overriding the default configuration by passing a config object in the details parameter.\n * The configuration is merged with the default configuration from the intlayer config file.\n */\nexport const getAppLogger =\n (configuration?: IntlayerConfig, globalDetails?: Details) =>\n (content: any, details?: Details) =>\n logger(content, {\n ...(details ?? {}),\n config: {\n ...configuration?.log,\n ...globalDetails?.config,\n ...(details?.config ?? {}),\n },\n });\n\nexport const colorize = (\n string: string,\n color?: ANSIColorsType,\n reset?: boolean | ANSIColorsType\n): string =>\n color\n ? `${color}${string}${reset ? (typeof reset === 'boolean' ? RESET : reset) : RESET}`\n : string;\n\nexport const colorizeLocales = (\n locales: Locale | Locale[],\n color: ANSIColorsType = GREEN,\n reset: boolean | ANSIColorsType = RESET\n) =>\n [locales]\n .flat()\n .map((locale) => colorize(locale, color, reset))\n .join(`, `);\n\nexport const colorizeKey = (\n keyPath: string | string[],\n color: ANSIColorsType = BEIGE,\n reset: boolean | ANSIColorsType = RESET\n) =>\n [keyPath]\n .flat()\n .map((key) => colorize(key, color, reset))\n .join(`, `);\n\nexport const colorizePath = (\n path: string | string[],\n color: ANSIColorsType = GREY,\n reset: boolean | ANSIColorsType = RESET\n) =>\n [path]\n .flat()\n .map((path) => colorize(path, color, reset))\n .join(`, `);\n\nexport const colorizeNumber = (\n number: number | string,\n options: Partial<Record<Intl.LDMLPluralRule, ANSIColorsType>> = {\n zero: BLUE,\n one: BLUE,\n two: BLUE,\n few: BLUE,\n many: BLUE,\n other: BLUE,\n }\n): string => {\n if (number === 0 || number === '0') {\n const color = options.zero ?? GREEN;\n return colorize(number.toString(), color);\n }\n\n // Kept inside the function. Top-level instantiation of classes/APIs\n // is treated as a side-effect and prevents tree-shaking if the function is unused.\n const rule = new Intl.PluralRules('en').select(Number(number));\n const color = options[rule];\n return colorize(number.toString(), color);\n};\n\nexport const removeColor = (text: string) =>\n // biome-ignore lint/suspicious/noControlCharactersInRegex: we need to remove the color codes\n text.replace(/\\x1b\\[[0-9;]*m/g, '');\n\nconst getLength = (length: number | number[] | string | string[]): number => {\n let value: number = 0;\n if (typeof length === 'number') {\n value = length;\n }\n if (typeof length === 'string') {\n value = length.length;\n }\n if (\n Array.isArray(length) &&\n length.every((locale) => typeof locale === 'string')\n ) {\n value = Math.max(...length.map((str) => str.length));\n }\n if (\n Array.isArray(length) &&\n length.every((locale) => typeof locale === 'number')\n ) {\n value = Math.max(...length);\n }\n return Math.max(value, 0);\n};\n\nconst defaultColonOptions = {\n colSize: 0,\n minSize: 0,\n maxSize: Infinity,\n pad: 'right',\n padChar: '0',\n};\n\n/**\n * Create a string of spaces of a given length.\n *\n * @param colSize - The length of the string to create.\n * @returns A string of spaces.\n */\nexport const colon = (\n text: string | string[],\n options?: {\n colSize?: number | number[] | string | string[];\n minSize?: number;\n maxSize?: number;\n pad?: 'left' | 'right';\n padChar?: string;\n }\n): string =>\n [text]\n .flat()\n .map((text) => {\n const { colSize, minSize, maxSize, pad } = {\n ...defaultColonOptions,\n ...(options ?? {}),\n };\n\n const length = getLength(colSize);\n const spacesLength = Math.max(\n minSize!,\n Math.min(maxSize!, length - removeColor(text).length)\n );\n\n if (pad === 'left') {\n return `${' '.repeat(spacesLength)}${text}`;\n }\n\n return `${text}${' '.repeat(spacesLength)}`;\n })\n .join('');\n\nexport const x = colorize('✗', RED);\nexport const v = colorize('✓', GREEN);\nexport const clock = colorize('⏲', BLUE);\n"],"mappings":"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"}
@@ -0,0 +1,83 @@
1
+ import { COOKIE_NAME, HEADER_NAME, LOCALE_STORAGE_NAME } from "../defaultValues/routing.mjs";
2
+
3
+ //#region src/utils/getStorageAttributes.ts
4
+ const createCookieEntry = (options) => {
5
+ const { name, path, expires, domain, secure, sameSite, httpOnly } = options ?? {};
6
+ return {
7
+ name: name ?? "INTLAYER_LOCALE",
8
+ attributes: {
9
+ path,
10
+ expires,
11
+ domain,
12
+ secure,
13
+ sameSite,
14
+ httpOnly
15
+ }
16
+ };
17
+ };
18
+ const createWebStorageEntry = (options) => ({ name: options?.name ?? "INTLAYER_LOCALE" });
19
+ const createHeaderEntry = (options) => ({ name: options?.name ?? "x-intlayer-locale" });
20
+ const isCookieEntry = (entry) => {
21
+ if (typeof entry !== "object" || entry === null) return false;
22
+ const e = entry;
23
+ return e["type"] === "cookie" || "sameSite" in e || "httpOnly" in e || "secure" in e;
24
+ };
25
+ const isStorageType = (value) => value === "cookie" || value === "localStorage" || value === "sessionStorage" || value === "header";
26
+ const processStorageEntry = (entry) => {
27
+ if (typeof entry === "string") {
28
+ if (!isStorageType(entry)) return {
29
+ cookies: [],
30
+ localStorage: [],
31
+ sessionStorage: [],
32
+ headers: []
33
+ };
34
+ if (entry === "cookie") return { cookies: [createCookieEntry()] };
35
+ if (entry === "localStorage") return { localStorage: [createWebStorageEntry()] };
36
+ if (entry === "sessionStorage") return { sessionStorage: [createWebStorageEntry()] };
37
+ if (entry === "header") return { headers: [createHeaderEntry()] };
38
+ }
39
+ if (typeof entry === "object" && entry !== null) {
40
+ const typedEntry = entry;
41
+ if (isCookieEntry(typedEntry)) return { cookies: [createCookieEntry(typedEntry)] };
42
+ if ("type" in typedEntry && typedEntry.type === "localStorage") return { localStorage: [createWebStorageEntry(typedEntry)] };
43
+ if ("type" in typedEntry && typedEntry.type === "sessionStorage") return { sessionStorage: [createWebStorageEntry(typedEntry)] };
44
+ if ("type" in typedEntry && typedEntry.type === "header") return { headers: [createHeaderEntry(typedEntry)] };
45
+ return { localStorage: [createWebStorageEntry(typedEntry)] };
46
+ }
47
+ return {
48
+ cookies: [],
49
+ localStorage: [],
50
+ sessionStorage: [],
51
+ headers: []
52
+ };
53
+ };
54
+ const mergeStorageAttributes = (accumulated, partial) => ({
55
+ cookies: [...accumulated.cookies, ...partial.cookies ?? []],
56
+ localStorage: [...accumulated.localStorage, ...partial.localStorage ?? []],
57
+ sessionStorage: [...accumulated.sessionStorage, ...partial.sessionStorage ?? []],
58
+ headers: [...accumulated.headers, ...partial.headers ?? []]
59
+ });
60
+ /**
61
+ * Extracts and normalizes storage configuration into separate arrays for each storage type.
62
+ * Called at config-build time so the result is pre-computed and stored in the config.
63
+ *
64
+ * @param options - The storage configuration from IntlayerConfig
65
+ * @returns An object containing arrays for cookies, localStorage, sessionStorage and headers
66
+ */
67
+ const getStorageAttributes = (options) => {
68
+ const emptyResult = {
69
+ cookies: [],
70
+ localStorage: [],
71
+ sessionStorage: [],
72
+ headers: []
73
+ };
74
+ if (options === false || options === void 0) return emptyResult;
75
+ if (Array.isArray(options)) return options.reduce((acc, entry) => {
76
+ return mergeStorageAttributes(acc, processStorageEntry(entry));
77
+ }, emptyResult);
78
+ return mergeStorageAttributes(emptyResult, processStorageEntry(options));
79
+ };
80
+
81
+ //#endregion
82
+ export { getStorageAttributes };
83
+ //# sourceMappingURL=getStorageAttributes.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getStorageAttributes.mjs","names":[],"sources":["../../../src/utils/getStorageAttributes.ts"],"sourcesContent":["import type {\n CookiesAttributes,\n ProcessedStorageAttributes,\n RoutingStorageInput,\n StorageAttributes,\n} from '@intlayer/types/config';\nimport {\n COOKIE_NAME,\n HEADER_NAME,\n LOCALE_STORAGE_NAME,\n} from '../defaultValues/routing';\n\n// ============================================================================\n// Types\n// ============================================================================\n\ntype CookieEntry = {\n name: string;\n attributes: Omit<CookiesAttributes, 'type' | 'name'>;\n};\n\ntype WebStorageEntry = {\n name: string;\n};\n\ntype HeaderEntry = {\n name: string;\n};\n\ntype StorageEntry =\n | 'cookie'\n | 'localStorage'\n | 'sessionStorage'\n | 'header'\n | CookiesAttributes\n | StorageAttributes;\n\n// ============================================================================\n// Helper Functions\n// ============================================================================\n\nconst createCookieEntry = (\n options?: Partial<CookiesAttributes>\n): CookieEntry => {\n const { name, path, expires, domain, secure, sameSite, httpOnly } =\n options ?? {};\n return {\n name: name ?? COOKIE_NAME,\n attributes: { path, expires, domain, secure, sameSite, httpOnly },\n };\n};\n\nconst createWebStorageEntry = (\n options?: Partial<StorageAttributes>\n): WebStorageEntry => ({\n name: options?.name ?? LOCALE_STORAGE_NAME,\n});\n\nconst createHeaderEntry = (\n options?: Partial<StorageAttributes>\n): HeaderEntry => ({\n name: options?.name ?? HEADER_NAME,\n});\n\nconst isCookieEntry = (entry: unknown): boolean => {\n if (typeof entry !== 'object' || entry === null) return false;\n const e = entry as Record<string, unknown>;\n return (\n e['type'] === 'cookie' ||\n 'sameSite' in e ||\n 'httpOnly' in e ||\n 'secure' in e\n );\n};\n\nconst isStorageType = (\n value: string\n): value is 'cookie' | 'localStorage' | 'sessionStorage' | 'header' =>\n value === 'cookie' ||\n value === 'localStorage' ||\n value === 'sessionStorage' ||\n value === 'header';\n\n// ============================================================================\n// Main Function\n// ============================================================================\n\nconst processStorageEntry = (\n entry: StorageEntry\n): Partial<ProcessedStorageAttributes> => {\n if (typeof entry === 'string') {\n if (!isStorageType(entry)) {\n return { cookies: [], localStorage: [], sessionStorage: [], headers: [] };\n }\n if (entry === 'cookie') return { cookies: [createCookieEntry()] };\n if (entry === 'localStorage')\n return { localStorage: [createWebStorageEntry()] };\n if (entry === 'sessionStorage')\n return { sessionStorage: [createWebStorageEntry()] };\n if (entry === 'header') return { headers: [createHeaderEntry()] };\n }\n\n if (typeof entry === 'object' && entry !== null) {\n const typedEntry = entry as CookiesAttributes | StorageAttributes;\n\n if (isCookieEntry(typedEntry)) {\n return { cookies: [createCookieEntry(typedEntry as CookiesAttributes)] };\n }\n if ('type' in typedEntry && typedEntry.type === 'localStorage') {\n return {\n localStorage: [createWebStorageEntry(typedEntry as StorageAttributes)],\n };\n }\n if ('type' in typedEntry && typedEntry.type === 'sessionStorage') {\n return {\n sessionStorage: [\n createWebStorageEntry(typedEntry as StorageAttributes),\n ],\n };\n }\n if ('type' in typedEntry && typedEntry.type === 'header') {\n return { headers: [createHeaderEntry(typedEntry as StorageAttributes)] };\n }\n // Default to localStorage for ambiguous objects\n return {\n localStorage: [\n createWebStorageEntry(typedEntry as Omit<StorageAttributes, 'type'>),\n ],\n };\n }\n\n return { cookies: [], localStorage: [], sessionStorage: [], headers: [] };\n};\n\nconst mergeStorageAttributes = (\n accumulated: ProcessedStorageAttributes,\n partial: Partial<ProcessedStorageAttributes>\n): ProcessedStorageAttributes => ({\n cookies: [...accumulated.cookies, ...(partial.cookies ?? [])],\n localStorage: [...accumulated.localStorage, ...(partial.localStorage ?? [])],\n sessionStorage: [\n ...accumulated.sessionStorage,\n ...(partial.sessionStorage ?? []),\n ],\n headers: [...accumulated.headers, ...(partial.headers ?? [])],\n});\n\n/**\n * Extracts and normalizes storage configuration into separate arrays for each storage type.\n * Called at config-build time so the result is pre-computed and stored in the config.\n *\n * @param options - The storage configuration from IntlayerConfig\n * @returns An object containing arrays for cookies, localStorage, sessionStorage and headers\n */\nexport const getStorageAttributes = (\n options: RoutingStorageInput\n): ProcessedStorageAttributes => {\n const emptyResult: ProcessedStorageAttributes = {\n cookies: [],\n localStorage: [],\n sessionStorage: [],\n headers: [],\n };\n\n if (options === false || options === undefined) return emptyResult;\n\n if (Array.isArray(options)) {\n return options.reduce<ProcessedStorageAttributes>((acc, entry) => {\n const partial = processStorageEntry(entry);\n return mergeStorageAttributes(acc, partial);\n }, emptyResult);\n }\n\n return mergeStorageAttributes(emptyResult, processStorageEntry(options));\n};\n"],"mappings":";;;AAyCA,MAAM,qBACJ,YACgB;CAChB,MAAM,EAAE,MAAM,MAAM,SAAS,QAAQ,QAAQ,UAAU,aACrD,WAAW,EAAE;AACf,QAAO;EACL,MAAM;EACN,YAAY;GAAE;GAAM;GAAS;GAAQ;GAAQ;GAAU;GAAU;EAClE;;AAGH,MAAM,yBACJ,aACqB,EACrB,MAAM,SAAS,2BAChB;AAED,MAAM,qBACJ,aACiB,EACjB,MAAM,SAAS,6BAChB;AAED,MAAM,iBAAiB,UAA4B;AACjD,KAAI,OAAO,UAAU,YAAY,UAAU,KAAM,QAAO;CACxD,MAAM,IAAI;AACV,QACE,EAAE,YAAY,YACd,cAAc,KACd,cAAc,KACd,YAAY;;AAIhB,MAAM,iBACJ,UAEA,UAAU,YACV,UAAU,kBACV,UAAU,oBACV,UAAU;AAMZ,MAAM,uBACJ,UACwC;AACxC,KAAI,OAAO,UAAU,UAAU;AAC7B,MAAI,CAAC,cAAc,MAAM,CACvB,QAAO;GAAE,SAAS,EAAE;GAAE,cAAc,EAAE;GAAE,gBAAgB,EAAE;GAAE,SAAS,EAAE;GAAE;AAE3E,MAAI,UAAU,SAAU,QAAO,EAAE,SAAS,CAAC,mBAAmB,CAAC,EAAE;AACjE,MAAI,UAAU,eACZ,QAAO,EAAE,cAAc,CAAC,uBAAuB,CAAC,EAAE;AACpD,MAAI,UAAU,iBACZ,QAAO,EAAE,gBAAgB,CAAC,uBAAuB,CAAC,EAAE;AACtD,MAAI,UAAU,SAAU,QAAO,EAAE,SAAS,CAAC,mBAAmB,CAAC,EAAE;;AAGnE,KAAI,OAAO,UAAU,YAAY,UAAU,MAAM;EAC/C,MAAM,aAAa;AAEnB,MAAI,cAAc,WAAW,CAC3B,QAAO,EAAE,SAAS,CAAC,kBAAkB,WAAgC,CAAC,EAAE;AAE1E,MAAI,UAAU,cAAc,WAAW,SAAS,eAC9C,QAAO,EACL,cAAc,CAAC,sBAAsB,WAAgC,CAAC,EACvE;AAEH,MAAI,UAAU,cAAc,WAAW,SAAS,iBAC9C,QAAO,EACL,gBAAgB,CACd,sBAAsB,WAAgC,CACvD,EACF;AAEH,MAAI,UAAU,cAAc,WAAW,SAAS,SAC9C,QAAO,EAAE,SAAS,CAAC,kBAAkB,WAAgC,CAAC,EAAE;AAG1E,SAAO,EACL,cAAc,CACZ,sBAAsB,WAA8C,CACrE,EACF;;AAGH,QAAO;EAAE,SAAS,EAAE;EAAE,cAAc,EAAE;EAAE,gBAAgB,EAAE;EAAE,SAAS,EAAE;EAAE;;AAG3E,MAAM,0BACJ,aACA,aACgC;CAChC,SAAS,CAAC,GAAG,YAAY,SAAS,GAAI,QAAQ,WAAW,EAAE,CAAE;CAC7D,cAAc,CAAC,GAAG,YAAY,cAAc,GAAI,QAAQ,gBAAgB,EAAE,CAAE;CAC5E,gBAAgB,CACd,GAAG,YAAY,gBACf,GAAI,QAAQ,kBAAkB,EAAE,CACjC;CACD,SAAS,CAAC,GAAG,YAAY,SAAS,GAAI,QAAQ,WAAW,EAAE,CAAE;CAC9D;;;;;;;;AASD,MAAa,wBACX,YAC+B;CAC/B,MAAM,cAA0C;EAC9C,SAAS,EAAE;EACX,cAAc,EAAE;EAChB,gBAAgB,EAAE;EAClB,SAAS,EAAE;EACZ;AAED,KAAI,YAAY,SAAS,YAAY,OAAW,QAAO;AAEvD,KAAI,MAAM,QAAQ,QAAQ,CACxB,QAAO,QAAQ,QAAoC,KAAK,UAAU;AAEhE,SAAO,uBAAuB,KADd,oBAAoB,MAAM,CACC;IAC1C,YAAY;AAGjB,QAAO,uBAAuB,aAAa,oBAAoB,QAAQ,CAAC"}
@@ -8,6 +8,7 @@ import { configESMxCJSRequire, getProjectRequire, isESModule } from "./ESMxCJSHe
8
8
  import { clearModuleCache } from "./clearModuleCache.mjs";
9
9
  import { compareVersions } from "./compareVersions.mjs";
10
10
  import { extractErrorMessage } from "./extractErrorMessage.mjs";
11
+ import { getStorageAttributes } from "./getStorageAttributes.mjs";
11
12
  import { logStack } from "./logStack.mjs";
12
13
  import { parseFilePathPattern, parseStringPattern } from "./parseFilePathPattern.mjs";
13
14
  import { retryManager } from "./retryManager.mjs";
@@ -16,4 +17,4 @@ import { camelCaseToSentence } from "./stringFormatter/camelCaseToSentence.mjs";
16
17
  import { kebabCaseToCamelCase } from "./stringFormatter/kebabCaseToCamelCase.mjs";
17
18
  import { toLowerCamelCase } from "./stringFormatter/toLowerCamelCase.mjs";
18
19
 
19
- export { cacheDisk, cacheMemory, camelCaseToKebabCase, camelCaseToSentence, clearAllCache, clearCache, clearDiskCacheMemory, clearModuleCache, compareVersions, computeKeyId, configESMxCJSRequire, extractErrorMessage, getAlias, getCache, getExtension, getPackageJsonPath, getProjectRequire, isESModule, kebabCaseToCamelCase, logStack, normalizePath, parseFilePathPattern, parseStringPattern, retryManager, setCache, stableStringify, toLowerCamelCase };
20
+ export { cacheDisk, cacheMemory, camelCaseToKebabCase, camelCaseToSentence, clearAllCache, clearCache, clearDiskCacheMemory, clearModuleCache, compareVersions, computeKeyId, configESMxCJSRequire, extractErrorMessage, getAlias, getCache, getExtension, getPackageJsonPath, getProjectRequire, getStorageAttributes, isESModule, kebabCaseToCamelCase, logStack, normalizePath, parseFilePathPattern, parseStringPattern, retryManager, setCache, stableStringify, toLowerCamelCase };
@@ -4,7 +4,7 @@
4
4
  * e.g. "MyNewComponent" => "my-new-component"
5
5
  */
6
6
  const camelCaseToKebabCase = (str) => {
7
- return str.replace(/([a-z])([A-Z])/g, "$1-$2").replace(/([A-Z])([A-Z][a-z])/g, "$1-$2").toLowerCase();
7
+ return str.replace(/([a-z])([A-Z])/g, "$1-$2").replace(/([A-Z])([A-Z][a-z])/g, "$1-$2").replace(/[\s_]+/g, "-").toLowerCase();
8
8
  };
9
9
 
10
10
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"camelCaseToKebabCase.mjs","names":[],"sources":["../../../../src/utils/stringFormatter/camelCaseToKebabCase.ts"],"sourcesContent":["/**\n * Convert a string to kebab-case\n * e.g. \"MyNewComponent\" => \"my-new-component\"\n */\nexport const camelCaseToKebabCase = (str: string): string => {\n // Split on transition from lower->upper: \"MyNewComponent\" => [\"My\", \"New\", \"Component\"]\n // Then lowercase each chunk and join by \"-\"\n return str\n .replace(/([a-z])([A-Z])/g, '$1-$2')\n .replace(/([A-Z])([A-Z][a-z])/g, '$1-$2')\n .toLowerCase();\n};\n"],"mappings":";;;;;AAIA,MAAa,wBAAwB,QAAwB;AAG3D,QAAO,IACJ,QAAQ,mBAAmB,QAAQ,CACnC,QAAQ,wBAAwB,QAAQ,CACxC,aAAa"}
1
+ {"version":3,"file":"camelCaseToKebabCase.mjs","names":[],"sources":["../../../../src/utils/stringFormatter/camelCaseToKebabCase.ts"],"sourcesContent":["/**\n * Convert a string to kebab-case\n * e.g. \"MyNewComponent\" => \"my-new-component\"\n */\nexport const camelCaseToKebabCase = (str: string): string => {\n // Split on transition from lower->upper: \"MyNewComponent\" => [\"My\", \"New\", \"Component\"]\n // Then lowercase each chunk and join by \"-\"\n return str\n .replace(/([a-z])([A-Z])/g, '$1-$2')\n .replace(/([A-Z])([A-Z][a-z])/g, '$1-$2')\n .replace(/[\\s_]+/g, '-')\n .toLowerCase();\n};\n"],"mappings":";;;;;AAIA,MAAa,wBAAwB,QAAwB;AAG3D,QAAO,IACJ,QAAQ,mBAAmB,QAAQ,CACnC,QAAQ,wBAAwB,QAAQ,CACxC,QAAQ,WAAW,IAAI,CACvB,aAAa"}
@@ -1,4 +1,4 @@
1
- import { CustomIntlayerConfig, EditorConfig, InternationalizationConfig, IntlayerConfig, LogConfig, LogFunctions, RoutingConfig } from "@intlayer/types/config";
1
+ import { CustomIntlayerConfig, CustomRoutingConfig, EditorConfig, InternationalizationConfig, IntlayerConfig, LogConfig, LogFunctions, RoutingConfig } from "@intlayer/types/config";
2
2
 
3
3
  //#region src/configFile/buildBrowserConfiguration.d.ts
4
4
  /**
@@ -34,7 +34,7 @@ declare const buildInternationalizationFields: (customConfiguration?: Partial<In
34
34
  * @param customConfiguration - Partial user-supplied routing config.
35
35
  * @returns A fully-defaulted {@link RoutingConfig}.
36
36
  */
37
- declare const buildRoutingFields: (customConfiguration?: Partial<RoutingConfig>) => RoutingConfig;
37
+ declare const buildRoutingFields: (customConfiguration?: Partial<CustomRoutingConfig>) => RoutingConfig;
38
38
  /**
39
39
  * Build the editor section of the Intlayer configuration.
40
40
  *
@@ -1 +1 @@
1
- {"version":3,"file":"buildBrowserConfiguration.d.ts","names":[],"sources":["../../../src/configFile/buildBrowserConfiguration.ts"],"mappings":";;;;;AAyCA;;;;;KAAY,qBAAA;EACV,oBAAA,EAAsB,IAAA,CACpB,0BAAA;EAGF,OAAA,EAAS,aAAA;EACT,MAAA,EAAQ,IAAA,CAAK,YAAA;EACb,GAAA,EAAK,IAAA,CAAK,SAAA;EACV,QAAA,EAAU,cAAA;AAAA;AAAA,QAGJ,MAAA;EAAA,UACI,MAAA;IAXY;IAapB,eAAA,GAAkB,qBAAA;EAAA;AAAA;;;;;;;cAiBT,+BAAA,GACX,mBAAA,GAAsB,OAAA,CAAQ,0BAAA,MAC7B,0BAAA;;;;AAxBD;;;cAuEW,kBAAA,GACX,mBAAA,GAAsB,OAAA,CAAQ,aAAA,MAC7B,aAAA;;;;;;;;AAnDH;;;cA4Ia,iBAAA,GACX,mBAAA,GAAsB,OAAA,CAAQ,YAAA,MAC7B,YAAA;;;;;;;;cAmIU,cAAA,GACX,mBAAA,GAAsB,OAAA,CAAQ,SAAA,GAC9B,YAAA,GAAe,YAAA,KACd,SAAA;;;AAnOH;;;;;;;;;;;;;;AA2FA;;;;;;cAgMa,yBAAA,GACX,YAAA,GAAe,oBAAA,KACd,qBAAA;;;;;;;;AA7DH;;;;cAiGa,2BAAA,GACX,MAAA,EAAQ,cAAA,KACP,qBAAA"}
1
+ {"version":3,"file":"buildBrowserConfiguration.d.ts","names":[],"sources":["../../../src/configFile/buildBrowserConfiguration.ts"],"mappings":";;;;;AA2CA;;;;;KAAY,qBAAA;EACV,oBAAA,EAAsB,IAAA,CACpB,0BAAA;EAGF,OAAA,EAAS,aAAA;EACT,MAAA,EAAQ,IAAA,CAAK,YAAA;EACb,GAAA,EAAK,IAAA,CAAK,SAAA;EACV,QAAA,EAAU,cAAA;AAAA;AAAA,QAGJ,MAAA;EAAA,UACI,MAAA;IAXY;IAapB,eAAA,GAAkB,qBAAA;EAAA;AAAA;;;;;;;cAiBT,+BAAA,GACX,mBAAA,GAAsB,OAAA,CAAQ,0BAAA,MAC7B,0BAAA;;;;AAxBD;;;cAuEW,kBAAA,GACX,mBAAA,GAAsB,OAAA,CAAQ,mBAAA,MAC7B,aAAA;;;;;;;;AAnDH;;;cAgJa,iBAAA,GACX,mBAAA,GAAsB,OAAA,CAAQ,YAAA,MAC7B,YAAA;;;;;;;;cAmIU,cAAA,GACX,mBAAA,GAAsB,OAAA,CAAQ,SAAA,GAC9B,YAAA,GAAe,YAAA,KACd,SAAA;;;AAvOH;;;;;;;;;;;;;;AA+FA;;;;;;cAgMa,yBAAA,GACX,YAAA,GAAe,oBAAA,KACd,qBAAA;;;;;;;;AA7DH;;;;cAiGa,2BAAA,GACX,MAAA,EAAQ,cAAA,KACP,qBAAA"}
@@ -20,9 +20,9 @@ declare const cookiesAttributesSchema: z.ZodObject<{
20
20
  secure: z.ZodOptional<z.ZodBoolean>;
21
21
  httpOnly: z.ZodOptional<z.ZodBoolean>;
22
22
  sameSite: z.ZodOptional<z.ZodEnum<{
23
+ none: "none";
23
24
  strict: "strict";
24
25
  lax: "lax";
25
- none: "none";
26
26
  }>>;
27
27
  expires: z.ZodOptional<z.ZodUnion<readonly [z.ZodDate, z.ZodNumber]>>;
28
28
  }, z.core.$strip>;
@@ -47,9 +47,9 @@ declare const storageSchema: z.ZodUnion<readonly [z.ZodLiteral<false>, z.ZodEnum
47
47
  secure: z.ZodOptional<z.ZodBoolean>;
48
48
  httpOnly: z.ZodOptional<z.ZodBoolean>;
49
49
  sameSite: z.ZodOptional<z.ZodEnum<{
50
+ none: "none";
50
51
  strict: "strict";
51
52
  lax: "lax";
52
- none: "none";
53
53
  }>>;
54
54
  expires: z.ZodOptional<z.ZodUnion<readonly [z.ZodDate, z.ZodNumber]>>;
55
55
  }, z.core.$strip>, z.ZodObject<{
@@ -72,9 +72,9 @@ declare const storageSchema: z.ZodUnion<readonly [z.ZodLiteral<false>, z.ZodEnum
72
72
  secure: z.ZodOptional<z.ZodBoolean>;
73
73
  httpOnly: z.ZodOptional<z.ZodBoolean>;
74
74
  sameSite: z.ZodOptional<z.ZodEnum<{
75
+ none: "none";
75
76
  strict: "strict";
76
77
  lax: "lax";
77
- none: "none";
78
78
  }>>;
79
79
  expires: z.ZodOptional<z.ZodUnion<readonly [z.ZodDate, z.ZodNumber]>>;
80
80
  }, z.core.$strip>, z.ZodObject<{
@@ -155,9 +155,9 @@ declare const routingSchema: z.ZodObject<{
155
155
  secure: z.ZodOptional<z.ZodBoolean>;
156
156
  httpOnly: z.ZodOptional<z.ZodBoolean>;
157
157
  sameSite: z.ZodOptional<z.ZodEnum<{
158
+ none: "none";
158
159
  strict: "strict";
159
160
  lax: "lax";
160
- none: "none";
161
161
  }>>;
162
162
  expires: z.ZodOptional<z.ZodUnion<readonly [z.ZodDate, z.ZodNumber]>>;
163
163
  }, z.core.$strip>, z.ZodObject<{
@@ -180,9 +180,9 @@ declare const routingSchema: z.ZodObject<{
180
180
  secure: z.ZodOptional<z.ZodBoolean>;
181
181
  httpOnly: z.ZodOptional<z.ZodBoolean>;
182
182
  sameSite: z.ZodOptional<z.ZodEnum<{
183
+ none: "none";
183
184
  strict: "strict";
184
185
  lax: "lax";
185
- none: "none";
186
186
  }>>;
187
187
  expires: z.ZodOptional<z.ZodUnion<readonly [z.ZodDate, z.ZodNumber]>>;
188
188
  }, z.core.$strip>, z.ZodObject<{
@@ -349,9 +349,9 @@ declare const intlayerConfigSchema: z.ZodObject<{
349
349
  secure: z.ZodOptional<z.ZodBoolean>;
350
350
  httpOnly: z.ZodOptional<z.ZodBoolean>;
351
351
  sameSite: z.ZodOptional<z.ZodEnum<{
352
+ none: "none";
352
353
  strict: "strict";
353
354
  lax: "lax";
354
- none: "none";
355
355
  }>>;
356
356
  expires: z.ZodOptional<z.ZodUnion<readonly [z.ZodDate, z.ZodNumber]>>;
357
357
  }, z.core.$strip>, z.ZodObject<{
@@ -374,9 +374,9 @@ declare const intlayerConfigSchema: z.ZodObject<{
374
374
  secure: z.ZodOptional<z.ZodBoolean>;
375
375
  httpOnly: z.ZodOptional<z.ZodBoolean>;
376
376
  sameSite: z.ZodOptional<z.ZodEnum<{
377
+ none: "none";
377
378
  strict: "strict";
378
379
  lax: "lax";
379
- none: "none";
380
380
  }>>;
381
381
  expires: z.ZodOptional<z.ZodUnion<readonly [z.ZodDate, z.ZodNumber]>>;
382
382
  }, z.core.$strip>, z.ZodObject<{
@@ -1,4 +1,4 @@
1
- import { RoutingConfig } from "@intlayer/types/config";
1
+ import { RoutingStorageInput } from "@intlayer/types/config";
2
2
 
3
3
  //#region src/defaultValues/routing.d.ts
4
4
  declare const HEADER_NAME = "x-intlayer-locale";
@@ -7,7 +7,7 @@ declare const LOCALE_STORAGE_NAME = "INTLAYER_LOCALE";
7
7
  declare const BASE_PATH = "";
8
8
  declare const SERVER_SET_COOKIE = "always";
9
9
  declare const ROUTING_MODE = "prefix-no-default";
10
- declare const STORAGE: RoutingConfig['storage'];
10
+ declare const STORAGE: RoutingStorageInput;
11
11
  //#endregion
12
12
  export { BASE_PATH, COOKIE_NAME, HEADER_NAME, LOCALE_STORAGE_NAME, ROUTING_MODE, SERVER_SET_COOKIE, STORAGE };
13
13
  //# sourceMappingURL=routing.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"routing.d.ts","names":[],"sources":["../../../src/defaultValues/routing.ts"],"mappings":";;;cAEa,WAAA;AAAA,cAEA,WAAA;AAAA,cACA,mBAAA;AAAA,cAEA,SAAA;AAAA,cAEA,iBAAA;AAAA,cAEA,YAAA;AAAA,cAEA,OAAA,EAAS,aAAA"}
1
+ {"version":3,"file":"routing.d.ts","names":[],"sources":["../../../src/defaultValues/routing.ts"],"mappings":";;;cAEa,WAAA;AAAA,cAEA,WAAA;AAAA,cACA,mBAAA;AAAA,cAEA,SAAA;AAAA,cAEA,iBAAA;AAAA,cAEA,YAAA;AAAA,cAEA,OAAA,EAAS,mBAAA"}
@@ -1,8 +1,8 @@
1
- import * as esbuild from "esbuild";
1
+ import * as _$esbuild from "esbuild";
2
2
  import { BuildOptions } from "esbuild";
3
3
 
4
4
  //#region src/loadExternalFile/bundleJSFile.d.ts
5
- declare const bundleJSFile: (buildOptions: BuildOptions) => Promise<esbuild.BuildResult<{
5
+ declare const bundleJSFile: (buildOptions: BuildOptions) => Promise<_$esbuild.BuildResult<{
6
6
  bundle: boolean;
7
7
  splitting?: boolean;
8
8
  preserveSymlinks?: boolean;
@@ -24,7 +24,7 @@ declare const bundleJSFile: (buildOptions: BuildOptions) => Promise<esbuild.Buil
24
24
  readonly '.md': "text";
25
25
  readonly '.mdx': "text";
26
26
  } | {
27
- [ext: string]: esbuild.Loader;
27
+ [ext: string]: _$esbuild.Loader;
28
28
  };
29
29
  resolveExtensions?: string[];
30
30
  mainFields?: string[];
@@ -50,31 +50,31 @@ declare const bundleJSFile: (buildOptions: BuildOptions) => Promise<esbuild.Buil
50
50
  in: string;
51
51
  out: string;
52
52
  })[] | Record<string, string>;
53
- stdin?: esbuild.StdinOptions;
54
- plugins?: esbuild.Plugin[];
53
+ stdin?: _$esbuild.StdinOptions;
54
+ plugins?: _$esbuild.Plugin[];
55
55
  absWorkingDir?: string;
56
56
  nodePaths?: string[];
57
57
  sourcemap: boolean | "linked" | "inline" | "external" | "both";
58
58
  legalComments?: "none" | "inline" | "eof" | "linked" | "external";
59
59
  sourceRoot?: string;
60
60
  sourcesContent?: boolean;
61
- format: esbuild.Format;
61
+ format: _$esbuild.Format;
62
62
  globalName?: string;
63
63
  target: string | string[];
64
64
  supported?: Record<string, boolean>;
65
- platform: esbuild.Platform;
65
+ platform: _$esbuild.Platform;
66
66
  mangleProps?: RegExp;
67
67
  reserveProps?: RegExp;
68
68
  mangleQuoted?: boolean;
69
69
  mangleCache?: Record<string, string | false>;
70
- drop?: esbuild.Drop[];
70
+ drop?: _$esbuild.Drop[];
71
71
  dropLabels?: string[];
72
72
  minify?: boolean;
73
73
  minifyWhitespace?: boolean;
74
74
  minifyIdentifiers?: boolean;
75
75
  minifySyntax?: boolean;
76
76
  lineLimit?: number;
77
- charset?: esbuild.Charset;
77
+ charset?: _$esbuild.Charset;
78
78
  treeShaking?: boolean;
79
79
  ignoreAnnotations?: boolean;
80
80
  jsx?: "transform" | "preserve" | "automatic";
@@ -88,12 +88,12 @@ declare const bundleJSFile: (buildOptions: BuildOptions) => Promise<esbuild.Buil
88
88
  };
89
89
  pure?: string[];
90
90
  keepNames?: boolean;
91
- absPaths?: esbuild.AbsPaths[];
91
+ absPaths?: _$esbuild.AbsPaths[];
92
92
  color?: boolean;
93
- logLevel: esbuild.LogLevel;
93
+ logLevel: _$esbuild.LogLevel;
94
94
  logLimit?: number;
95
- logOverride?: Record<string, esbuild.LogLevel>;
96
- tsconfigRaw?: string | esbuild.TsconfigRaw;
95
+ logOverride?: Record<string, _$esbuild.LogLevel>;
96
+ tsconfigRaw?: string | _$esbuild.TsconfigRaw;
97
97
  }>>;
98
98
  //#endregion
99
99
  export { bundleJSFile };
@@ -1 +1 @@
1
- {"version":3,"file":"bundleJSFile.d.ts","names":[],"sources":["../../../src/loadExternalFile/bundleJSFile.ts"],"mappings":";;;;cAyBa,YAAA,GAAsB,YAAA,EAAc,YAAA,KAAY,OAAA,SAAA,WAAA"}
1
+ {"version":3,"file":"bundleJSFile.d.ts","names":[],"sources":["../../../src/loadExternalFile/bundleJSFile.ts"],"mappings":";;;;cAyBa,YAAA,GAAsB,YAAA,EAAc,YAAA,KAAY,OAAA,WAAA,WAAA"}
@@ -1,4 +1,4 @@
1
- import * as esbuild from "esbuild";
1
+ import * as _$esbuild from "esbuild";
2
2
  import { BuildOptions } from "esbuild";
3
3
 
4
4
  //#region src/loadExternalFile/transpileTSToCJS.d.ts
@@ -10,7 +10,7 @@ type TranspileOptions = BuildOptions & {
10
10
  * When provided, its `buildSync`/`build` methods are used instead of
11
11
  * the ones imported from the `esbuild` package.
12
12
  */
13
- esbuildInstance?: typeof esbuild;
13
+ esbuildInstance?: typeof _$esbuild;
14
14
  };
15
15
  declare const transpileTSToCJSSync: (code: string, filePath: string, options?: TranspileOptions) => string | undefined;
16
16
  declare const transpileTSToCJS: (code: string, filePath: string, options?: TranspileOptions) => Promise<string | undefined>;
@@ -1 +1 @@
1
- {"version":3,"file":"transpileTSToCJS.d.ts","names":[],"sources":["../../../src/loadExternalFile/transpileTSToCJS.ts"],"mappings":";;;;KAOY,gBAAA,GAAmB,YAAA;;;AAA/B;;;;;EAQE,eAAA,UARyC,OAAA;AAAA;AAAA,cA6C9B,oBAAA,GACX,IAAA,UACA,QAAA,UACA,OAAA,GAAU,gBAAA;AAAA,cAwBC,gBAAA,GACX,IAAA,UACA,QAAA,UACA,OAAA,GAAU,gBAAA,KACT,OAAA"}
1
+ {"version":3,"file":"transpileTSToCJS.d.ts","names":[],"sources":["../../../src/loadExternalFile/transpileTSToCJS.ts"],"mappings":";;;;KAOY,gBAAA,GAAmB,YAAA;;;AAA/B;;;;;EAQE,eAAA,UARyC,SAAA;AAAA;AAAA,cA6C9B,oBAAA,GACX,IAAA,UACA,QAAA,UACA,OAAA,GAAU,gBAAA;AAAA,cAwBC,gBAAA,GACX,IAAA,UACA,QAAA,UACA,OAAA,GAAU,gBAAA,KACT,OAAA"}
@@ -1,5 +1,5 @@
1
1
  import { colors_d_exports } from "./colors.js";
2
- import { CustomIntlayerConfig } from "@intlayer/types/config";
2
+ import { CustomIntlayerConfig, IntlayerConfig } from "@intlayer/types/config";
3
3
  import { Locale } from "@intlayer/types/allLocales";
4
4
 
5
5
  //#region src/logger.d.ts
@@ -19,17 +19,11 @@ declare const spinnerFrames: string[];
19
19
  * It allows overriding the default configuration by passing a config object in the details parameter.
20
20
  * The configuration is merged with the default configuration from the intlayer config file.
21
21
  */
22
- declare const getAppLogger: (configuration?: CustomIntlayerConfig, globalDetails?: Details) => (content: any, details?: Details) => void;
23
- declare const colorize: (s: string, color?: ANSIColorsType, reset?: boolean | ANSIColorsType) => string;
22
+ declare const getAppLogger: (configuration?: IntlayerConfig, globalDetails?: Details) => (content: any, details?: Details) => void;
23
+ declare const colorize: (string: string, color?: ANSIColorsType, reset?: boolean | ANSIColorsType) => string;
24
24
  declare const colorizeLocales: (locales: Locale | Locale[], color?: ANSIColorsType, reset?: boolean | ANSIColorsType) => string;
25
25
  declare const colorizeKey: (keyPath: string | string[], color?: ANSIColorsType, reset?: boolean | ANSIColorsType) => string;
26
26
  declare const colorizePath: (path: string | string[], color?: ANSIColorsType, reset?: boolean | ANSIColorsType) => string;
27
- /**
28
- * Colorize numeric value using Intl.NumberFormat and optional ANSI colors.
29
- *
30
- * Examples:
31
- * colorizeNumber(2, [{ pluralRule: 'one' , color: ANSIColors.GREEN}, { pluralRule: 'other' , color: ANSIColors.RED}]) // "'\x1b[31m2\x1b[0m"
32
- */
33
27
  declare const colorizeNumber: (number: number | string, options?: Partial<Record<Intl.LDMLPluralRule, ANSIColorsType>>) => string;
34
28
  declare const removeColor: (text: string) => string;
35
29
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"logger.d.ts","names":[],"sources":["../../src/logger.ts"],"mappings":";;;;;KAIY,cAAA,WAAyB,gBAAA,eAAyB,gBAAA;AAAA,KAElD,OAAA;EACV,SAAA;EACA,KAAA;EACA,MAAA,GAAS,oBAAA;AAAA;AAAA,KAGC,MAAA,IAAU,OAAA,OAAc,OAAA,GAAU,OAAA;AAAA,cAIjC,SAAA,GAAa,MAAA;AAAA,cAIb,SAAA,GAAa,YAAA;AAAA,cAQb,MAAA,EAAQ,MAAA;AAAA,cAoCR,aAAA;;;;;;cAOA,YAAA,GACV,aAAA,GAAgB,oBAAA,EAAsB,aAAA,GAAgB,OAAA,MACtD,OAAA,OAAc,OAAA,GAAU,OAAA;AAAA,cAUd,QAAA,GACX,CAAA,UACA,KAAA,GAAQ,cAAA,EACR,KAAA,aAAkB,cAAA;AAAA,cAMP,eAAA,GACX,OAAA,EAAS,MAAA,GAAS,MAAA,IAClB,KAAA,GAAO,cAAA,EACP,KAAA,aAAiB,cAAA;AAAA,cAON,WAAA,GACX,OAAA,qBACA,KAAA,GAAO,cAAA,EACP,KAAA,aAAiB,cAAA;AAAA,cAON,YAAA,GACX,IAAA,qBACA,KAAA,GAAO,cAAA,EACP,KAAA,aAAiB,cAAA;;;;;;AAnGnB;cAgHa,cAAA,GACX,MAAA,mBACA,OAAA,GAAS,OAAA,CAAQ,MAAA,CAAO,IAAA,CAAK,cAAA,EAAgB,cAAA;AAAA,cAmBlC,WAAA,GAAe,IAAA;;;AAjI5B;;;;cAoKa,KAAA,GACX,IAAA,qBACA,OAAA;EACE,OAAA;EACA,OAAA;EACA,OAAA;EACA,GAAA;EACA,OAAA;AAAA;AAAA,cAyBS,CAAA;AAAA,cACA,CAAA;AAAA,cACA,KAAA"}
1
+ {"version":3,"file":"logger.d.ts","names":[],"sources":["../../src/logger.ts"],"mappings":";;;;;KAQY,cAAA,WACF,gBAAA,eAA8B,gBAAA;AAAA,KAE5B,OAAA;EACV,SAAA;EACA,KAAA;EACA,MAAA,GAAS,oBAAA;AAAA;AAAA,KAGC,MAAA,IAAU,OAAA,OAAc,OAAA,GAAU,OAAA;AAAA,cAIjC,SAAA,GAAa,MAAA;AAAA,cAIb,SAAA,GAAa,YAAA;AAAA,cAQb,MAAA,EAAQ,MAAA;AAAA,cAgBR,aAAA;;;;;;cAOA,YAAA,GACV,aAAA,GAAgB,cAAA,EAAgB,aAAA,GAAgB,OAAA,MAChD,OAAA,OAAc,OAAA,GAAU,OAAA;AAAA,cAUd,QAAA,GACX,MAAA,UACA,KAAA,GAAQ,cAAA,EACR,KAAA,aAAkB,cAAA;AAAA,cAMP,eAAA,GACX,OAAA,EAAS,MAAA,GAAS,MAAA,IAClB,KAAA,GAAO,cAAA,EACP,KAAA,aAAiB,cAAA;AAAA,cAON,WAAA,GACX,OAAA,qBACA,KAAA,GAAO,cAAA,EACP,KAAA,aAAiB,cAAA;AAAA,cAON,YAAA,GACX,IAAA,qBACA,KAAA,GAAO,cAAA,EACP,KAAA,aAAiB,cAAA;AAAA,cAON,cAAA,GACX,MAAA,mBACA,OAAA,GAAS,OAAA,CAAQ,MAAA,CAAO,IAAA,CAAK,cAAA,EAAgB,cAAA;AAAA,cAqBlC,WAAA,GAAe,IAAA;;;;AA7G5B;;;cAsJa,KAAA,GACX,IAAA,qBACA,OAAA;EACE,OAAA;EACA,OAAA;EACA,OAAA;EACA,GAAA;EACA,OAAA;AAAA;AAAA,cAyBS,CAAA;AAAA,cACA,CAAA;AAAA,cACA,KAAA"}
@@ -0,0 +1,14 @@
1
+ import { ProcessedStorageAttributes, RoutingStorageInput } from "@intlayer/types/config";
2
+
3
+ //#region src/utils/getStorageAttributes.d.ts
4
+ /**
5
+ * Extracts and normalizes storage configuration into separate arrays for each storage type.
6
+ * Called at config-build time so the result is pre-computed and stored in the config.
7
+ *
8
+ * @param options - The storage configuration from IntlayerConfig
9
+ * @returns An object containing arrays for cookies, localStorage, sessionStorage and headers
10
+ */
11
+ declare const getStorageAttributes: (options: RoutingStorageInput) => ProcessedStorageAttributes;
12
+ //#endregion
13
+ export { getStorageAttributes };
14
+ //# sourceMappingURL=getStorageAttributes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getStorageAttributes.d.ts","names":[],"sources":["../../../src/utils/getStorageAttributes.ts"],"mappings":";;;;;AA0JA;;;;;cAAa,oBAAA,GACX,OAAA,EAAS,mBAAA,KACR,0BAAA"}
@@ -13,6 +13,7 @@ import { clearModuleCache } from "./clearModuleCache.js";
13
13
  import { compareVersions } from "./compareVersions.js";
14
14
  import { getExtension } from "./getExtension.js";
15
15
  import { getPackageJsonPath } from "./getPackageJsonPath.js";
16
+ import { getStorageAttributes } from "./getStorageAttributes.js";
16
17
  import { parseFilePathPattern, parseStringPattern } from "./parseFilePathPattern.js";
17
18
  import { RetryManagerOptions, retryManager } from "./retryManager.js";
18
- export { CacheKey, GetAliasOptions, RetryManagerOptions, cacheDisk, cacheMemory, camelCaseToKebabCase, camelCaseToSentence, clearAllCache, clearCache, clearDiskCacheMemory, clearModuleCache, compareVersions, computeKeyId, configESMxCJSRequire, extractErrorMessage, getAlias, getCache, getExtension, getPackageJsonPath, getProjectRequire, isESModule, kebabCaseToCamelCase, logStack, normalizePath, parseFilePathPattern, parseStringPattern, retryManager, setCache, stableStringify, toLowerCamelCase };
19
+ export { CacheKey, GetAliasOptions, RetryManagerOptions, cacheDisk, cacheMemory, camelCaseToKebabCase, camelCaseToSentence, clearAllCache, clearCache, clearDiskCacheMemory, clearModuleCache, compareVersions, computeKeyId, configESMxCJSRequire, extractErrorMessage, getAlias, getCache, getExtension, getPackageJsonPath, getProjectRequire, getStorageAttributes, isESModule, kebabCaseToCamelCase, logStack, normalizePath, parseFilePathPattern, parseStringPattern, retryManager, setCache, stableStringify, toLowerCamelCase };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intlayer/config",
3
- "version": "8.5.2",
3
+ "version": "8.6.1",
4
4
  "private": false,
5
5
  "description": "Retrieve Intlayer configurations and manage environment variables for both server-side and client-side environments.",
6
6
  "keywords": [
@@ -144,7 +144,7 @@
144
144
  "typecheck": "tsc --noEmit --project tsconfig.types.json"
145
145
  },
146
146
  "dependencies": {
147
- "@intlayer/types": "8.5.2",
147
+ "@intlayer/types": "8.6.1",
148
148
  "defu": "6.1.4",
149
149
  "dotenv": "17.3.1",
150
150
  "esbuild": "0.27.4",
@@ -157,9 +157,9 @@
157
157
  "@utils/ts-config-types": "1.0.4",
158
158
  "@utils/tsdown-config": "1.0.4",
159
159
  "rimraf": "6.1.3",
160
- "tsdown": "0.21.4",
160
+ "tsdown": "0.21.7",
161
161
  "typescript": "6.0.2",
162
- "vitest": "4.1.1"
162
+ "vitest": "4.1.2"
163
163
  },
164
164
  "peerDependencies": {
165
165
  "react": ">=16.0.0"