@intlayer/core 7.0.0-canary.3 → 7.0.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 (62) hide show
  1. package/dist/cjs/getStorageAttributes.cjs +24 -5
  2. package/dist/cjs/getStorageAttributes.cjs.map +1 -1
  3. package/dist/cjs/localization/getMultilingualUrls.cjs +3 -1
  4. package/dist/cjs/localization/getMultilingualUrls.cjs.map +1 -1
  5. package/dist/cjs/transpiler/file/file.cjs +2 -2
  6. package/dist/cjs/utils/localeStorage.cjs +18 -5
  7. package/dist/cjs/utils/localeStorage.cjs.map +1 -1
  8. package/dist/esm/getStorageAttributes.mjs +24 -5
  9. package/dist/esm/getStorageAttributes.mjs.map +1 -1
  10. package/dist/esm/localization/getMultilingualUrls.mjs +2 -1
  11. package/dist/esm/localization/getMultilingualUrls.mjs.map +1 -1
  12. package/dist/esm/transpiler/file/file.mjs +1 -1
  13. package/dist/esm/utils/localeStorage.mjs +18 -5
  14. package/dist/esm/utils/localeStorage.mjs.map +1 -1
  15. package/dist/types/deepTransformPlugins/getFilterMissingTranslationsContent.d.ts +4 -4
  16. package/dist/types/deepTransformPlugins/getFilterTranslationsOnlyContent.d.ts +4 -4
  17. package/dist/types/deepTransformPlugins/getFilteredLocalesContent.d.ts +4 -4
  18. package/dist/types/deepTransformPlugins/index.d.ts.map +1 -0
  19. package/dist/types/dictionaryManipulator/getUnmergedDictionaryByKeyPath.d.ts +2 -2
  20. package/dist/types/dictionaryManipulator/index.d.ts.map +1 -0
  21. package/dist/types/dictionaryManipulator/orderDictionaries.d.ts +2 -2
  22. package/dist/types/formatters/index.d.ts.map +1 -0
  23. package/dist/types/getStorageAttributes.d.ts +7 -3
  24. package/dist/types/getStorageAttributes.d.ts.map +1 -1
  25. package/dist/types/index.d.ts +2 -2
  26. package/dist/types/index.d.ts.map +1 -0
  27. package/dist/types/interpreter/getContent/index.d.ts.map +1 -0
  28. package/dist/types/interpreter/getContent/plugins.d.ts.map +1 -1
  29. package/dist/types/interpreter/getIntlayerAsync.d.ts +13 -0
  30. package/dist/types/interpreter/getIntlayerAsync.d.ts.map +1 -0
  31. package/dist/types/interpreter/index.d.ts.map +1 -0
  32. package/dist/types/localization/getMultilingualUrls.d.ts.map +1 -1
  33. package/dist/types/localization/index.d.ts.map +1 -0
  34. package/dist/types/localization/localeList.d.ts +3 -0
  35. package/dist/types/localization/localeList.d.ts.map +1 -0
  36. package/dist/types/transpiler/condition/index.d.ts.map +1 -0
  37. package/dist/types/transpiler/enumeration/enumeration.d.ts.map +1 -1
  38. package/dist/types/transpiler/enumeration/index.d.ts.map +1 -0
  39. package/dist/types/transpiler/file/index.d.ts.map +1 -0
  40. package/dist/types/transpiler/gender/index.d.ts.map +1 -0
  41. package/dist/types/transpiler/index.d.ts.map +1 -0
  42. package/dist/types/transpiler/insertion/index.d.ts.map +1 -0
  43. package/dist/types/transpiler/markdown/index.d.ts.map +1 -0
  44. package/dist/types/transpiler/nesting/index.d.ts.map +1 -0
  45. package/dist/types/transpiler/translation/index.d.ts.map +1 -0
  46. package/dist/types/transpiler/translation/translation.d.ts +1 -1
  47. package/dist/types/transpiler/translation/translation.d.ts.map +1 -1
  48. package/dist/types/types/dictionary.d.ts +307 -0
  49. package/dist/types/types/dictionary.d.ts.map +1 -0
  50. package/dist/types/types/index.d.ts +5 -0
  51. package/dist/types/types/index.d.ts.map +1 -0
  52. package/dist/types/types/intlayer.d.ts +5 -0
  53. package/dist/types/types/intlayer.d.ts.map +1 -0
  54. package/dist/types/types/keyPath.d.ts +47 -0
  55. package/dist/types/types/keyPath.d.ts.map +1 -0
  56. package/dist/types/types/nodeType.d.ts +30 -0
  57. package/dist/types/types/nodeType.d.ts.map +1 -0
  58. package/dist/types/types/translation.d.ts +25 -0
  59. package/dist/types/types/translation.d.ts.map +1 -0
  60. package/dist/types/utils/localeStorage.d.ts +8 -6
  61. package/dist/types/utils/localeStorage.d.ts.map +1 -1
  62. package/package.json +14 -14
@@ -28,6 +28,13 @@ const createWebStorageEntry = (options) => {
28
28
  return { name: name ?? __intlayer_config_client.DefaultValues.Routing.LOCALE_STORAGE_NAME };
29
29
  };
30
30
  /**
31
+ * Creates a header entry with default name
32
+ */
33
+ const createHeaderEntry = (options) => {
34
+ const { name } = options ?? {};
35
+ return { name: name ?? __intlayer_config_client.DefaultValues.Routing.HEADER_NAME };
36
+ };
37
+ /**
31
38
  * Determines if a storage entry is a cookie based on its properties
32
39
  */
33
40
  const isCookieEntry = (entry) => {
@@ -37,7 +44,7 @@ const isCookieEntry = (entry) => {
37
44
  * Determines the storage type from a string literal
38
45
  */
39
46
  const isStorageType = (value) => {
40
- return value === "cookie" || value === "localStorage" || value === "sessionStorage";
47
+ return value === "cookie" || value === "localStorage" || value === "sessionStorage" || value === "header";
41
48
  };
42
49
  /**
43
50
  * Processes a single storage entry and returns the appropriate storage attributes
@@ -47,11 +54,13 @@ const processStorageEntry = (entry) => {
47
54
  if (!isStorageType(entry)) return {
48
55
  cookies: [],
49
56
  localStorage: [],
50
- sessionStorage: []
57
+ sessionStorage: [],
58
+ headers: []
51
59
  };
52
60
  if (entry === "cookie") return { cookies: [createCookieEntry()] };
53
61
  if (entry === "localStorage") return { localStorage: [createWebStorageEntry()] };
54
62
  if (entry === "sessionStorage") return { sessionStorage: [createWebStorageEntry()] };
63
+ if (entry === "header") return { headers: [createHeaderEntry()] };
55
64
  }
56
65
  if (typeof entry === "object" && entry !== null) {
57
66
  const typedEntry = entry;
@@ -70,6 +79,13 @@ const processStorageEntry = (entry) => {
70
79
  ...rest$1
71
80
  })] };
72
81
  }
82
+ if ("type" in typedEntry && typedEntry.type === "header") {
83
+ const { name: name$1,...rest$1 } = typedEntry;
84
+ return { headers: [createHeaderEntry({
85
+ name: name$1,
86
+ ...rest$1
87
+ })] };
88
+ }
73
89
  const { name,...rest } = typedEntry;
74
90
  return { localStorage: [createWebStorageEntry({
75
91
  name,
@@ -79,7 +95,8 @@ const processStorageEntry = (entry) => {
79
95
  return {
80
96
  cookies: [],
81
97
  localStorage: [],
82
- sessionStorage: []
98
+ sessionStorage: [],
99
+ headers: []
83
100
  };
84
101
  };
85
102
  /**
@@ -89,7 +106,8 @@ const mergeStorageAttributes = (accumulated, partial) => {
89
106
  return {
90
107
  cookies: [...accumulated.cookies, ...partial.cookies ?? []],
91
108
  localStorage: [...accumulated.localStorage, ...partial.localStorage ?? []],
92
- sessionStorage: [...accumulated.sessionStorage, ...partial.sessionStorage ?? []]
109
+ sessionStorage: [...accumulated.sessionStorage, ...partial.sessionStorage ?? []],
110
+ headers: [...accumulated.headers, ...partial.headers ?? []]
93
111
  };
94
112
  };
95
113
  /**
@@ -102,7 +120,8 @@ const getStorageAttributes = (options) => {
102
120
  const emptyResult = {
103
121
  cookies: [],
104
122
  localStorage: [],
105
- sessionStorage: []
123
+ sessionStorage: [],
124
+ headers: []
106
125
  };
107
126
  if (options === false || options === void 0) return emptyResult;
108
127
  if (Array.isArray(options)) return options.reduce((acc, entry) => {
@@ -1 +1 @@
1
- {"version":3,"file":"getStorageAttributes.cjs","names":["DefaultValues","rest","emptyResult: StorageAttributes"],"sources":["../../src/getStorageAttributes.ts"],"sourcesContent":["import { DefaultValues } from '@intlayer/config/client';\nimport type {\n CookiesAttributes,\n IntlayerConfig,\n LocaleStorageAttributes,\n} from '@intlayer/types';\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\nexport type StorageAttributes = {\n cookies: CookieEntry[];\n localStorage: WebStorageEntry[];\n sessionStorage: WebStorageEntry[];\n};\n\ntype StorageEntry =\n | 'cookie'\n | 'localStorage'\n | 'sessionStorage'\n | CookiesAttributes\n | LocaleStorageAttributes;\n\n// ============================================================================\n// Helper Functions\n// ============================================================================\n\n/**\n * Creates a cookie entry with default values for missing attributes\n */\nconst createCookieEntry = (\n options?: Partial<CookiesAttributes>\n): CookieEntry => {\n const { name, path, expires, domain, secure, sameSite, httpOnly } =\n options ?? {};\n\n return {\n name: name ?? DefaultValues.Routing.COOKIE_NAME,\n attributes: {\n path,\n expires,\n domain,\n secure,\n sameSite,\n httpOnly,\n },\n };\n};\n\n/**\n * Creates a web storage entry (localStorage or sessionStorage) with default name\n */\nconst createWebStorageEntry = (\n options?: Partial<LocaleStorageAttributes>\n): WebStorageEntry => {\n const { name } = options ?? {};\n\n return {\n name: name ?? DefaultValues.Routing.LOCALE_STORAGE_NAME,\n };\n};\n\n/**\n * Determines if a storage entry is a cookie based on its properties\n */\nconst isCookieEntry = (entry: any): boolean => {\n return (\n entry.type === 'cookie' ||\n 'sameSite' in entry ||\n 'httpOnly' in entry ||\n 'secure' in entry\n );\n};\n\n/**\n * Determines the storage type from a string literal\n */\nconst isStorageType = (\n value: string\n): value is 'cookie' | 'localStorage' | 'sessionStorage' => {\n return (\n value === 'cookie' || value === 'localStorage' || value === 'sessionStorage'\n );\n};\n\n// ============================================================================\n// Main Function\n// ============================================================================\n\n/**\n * Processes a single storage entry and returns the appropriate storage attributes\n */\nconst processStorageEntry = (\n entry: StorageEntry\n): Partial<StorageAttributes> => {\n // Handle string literals\n if (typeof entry === 'string') {\n if (!isStorageType(entry)) {\n return { cookies: [], localStorage: [], sessionStorage: [] };\n }\n\n if (entry === 'cookie') {\n return { cookies: [createCookieEntry()] };\n }\n\n if (entry === 'localStorage') {\n return { localStorage: [createWebStorageEntry()] };\n }\n\n if (entry === 'sessionStorage') {\n return { sessionStorage: [createWebStorageEntry()] };\n }\n }\n\n // Handle object entries\n if (typeof entry === 'object' && entry !== null) {\n const typedEntry = entry as CookiesAttributes | LocaleStorageAttributes;\n\n if (isCookieEntry(typedEntry)) {\n return { cookies: [createCookieEntry(typedEntry as CookiesAttributes)] };\n }\n\n // Handle localStorage\n if ('type' in typedEntry && typedEntry.type === 'localStorage') {\n const { name, ...rest } = typedEntry as LocaleStorageAttributes;\n return { localStorage: [createWebStorageEntry({ name, ...rest })] };\n }\n\n // Handle sessionStorage\n if ('type' in typedEntry && typedEntry.type === 'sessionStorage') {\n const { name, ...rest } = typedEntry as LocaleStorageAttributes;\n return { sessionStorage: [createWebStorageEntry({ name, ...rest })] };\n }\n\n // Default to localStorage for ambiguous objects\n const { name, ...rest } = typedEntry as Omit<\n LocaleStorageAttributes,\n 'type'\n >;\n return { localStorage: [createWebStorageEntry({ name, ...rest })] };\n }\n\n return { cookies: [], localStorage: [], sessionStorage: [] };\n};\n\n/**\n * Merges multiple partial storage attributes into a single result\n */\nconst mergeStorageAttributes = (\n accumulated: StorageAttributes,\n partial: Partial<StorageAttributes>\n): StorageAttributes => {\n return {\n cookies: [...accumulated.cookies, ...(partial.cookies ?? [])],\n localStorage: [\n ...accumulated.localStorage,\n ...(partial.localStorage ?? []),\n ],\n sessionStorage: [\n ...accumulated.sessionStorage,\n ...(partial.sessionStorage ?? []),\n ],\n };\n};\n\n/**\n * Extracts and normalizes storage configuration into separate arrays for each storage type\n *\n * @param options - The storage configuration from IntlayerConfig\n * @returns An object containing arrays for cookies, localStorage, and sessionStorage\n */\nexport const getStorageAttributes = (\n options: IntlayerConfig['routing']['storage']\n): StorageAttributes => {\n const emptyResult: StorageAttributes = {\n cookies: [],\n localStorage: [],\n sessionStorage: [],\n };\n\n // Storage is disabled\n if (options === false || options === undefined) {\n return emptyResult;\n }\n\n // Handle array of storage entries\n if (Array.isArray(options)) {\n return options.reduce((acc, entry) => {\n const partial = processStorageEntry(entry);\n return mergeStorageAttributes(acc, partial);\n }, emptyResult);\n }\n\n // Handle single storage entry\n const partial = processStorageEntry(options);\n\n return mergeStorageAttributes(emptyResult, partial);\n};\n"],"mappings":";;;;;;;;AAwCA,MAAM,qBACJ,YACgB;CAChB,MAAM,EAAE,MAAM,MAAM,SAAS,QAAQ,QAAQ,UAAU,aACrD,WAAW,EAAE;AAEf,QAAO;EACL,MAAM,QAAQA,uCAAc,QAAQ;EACpC,YAAY;GACV;GACA;GACA;GACA;GACA;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AAC,sBAAsB;GAAE;GAAM,GAAG;GAAM,CAAC,CAAC,EAAE;;AAGrE,QAAO;EAAE,SAAS,EAAE;EAAE,cAAc,EAAE;EAAE,gBAAgB,EAAE;EAAE;;;;;AAM9D,MAAM,0BACJ,aACA,YACsB;AACtB,QAAO;EACL,SAAS,CAAC,GAAG,YAAY,SAAS,GAAI,QAAQ,WAAW,EAAE,CAAE;EAC7D,cAAc,CACZ,GAAG,YAAY,cACf,GAAI,QAAQ,gBAAgB,EAAE,CAC/B;EACD,gBAAgB,CACd,GAAG,YAAY,gBACf,GAAI,QAAQ,kBAAkB,EAAE,CACjC;EACF;;;;;;;;AASH,MAAa,wBACX,YACsB;CACtB,MAAMC,cAAiC;EACrC,SAAS,EAAE;EACX,cAAc,EAAE;EAChB,gBAAgB,EAAE;EACnB;AAGD,KAAI,YAAY,SAAS,YAAY,OACnC,QAAO;AAIT,KAAI,MAAM,QAAQ,QAAQ,CACxB,QAAO,QAAQ,QAAQ,KAAK,UAAU;AAEpC,SAAO,uBAAuB,KADd,oBAAoB,MAAM,CACC;IAC1C,YAAY;AAMjB,QAAO,uBAAuB,aAFd,oBAAoB,QAAQ,CAEO"}
1
+ {"version":3,"file":"getStorageAttributes.cjs","names":["DefaultValues","rest","emptyResult: ProcessedStorageAttributes"],"sources":["../../src/getStorageAttributes.ts"],"sourcesContent":["import { DefaultValues } from '@intlayer/config/client';\nimport type {\n CookiesAttributes,\n IntlayerConfig,\n StorageAttributes,\n} from '@intlayer/types';\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\nexport type ProcessedStorageAttributes = {\n cookies: CookieEntry[];\n localStorage: WebStorageEntry[];\n sessionStorage: WebStorageEntry[];\n headers: HeaderEntry[];\n};\n\ntype StorageEntry =\n | 'cookie'\n | 'localStorage'\n | 'sessionStorage'\n | 'header'\n | CookiesAttributes\n | StorageAttributes;\n\n// ============================================================================\n// Helper Functions\n// ============================================================================\n\n/**\n * Creates a cookie entry with default values for missing attributes\n */\nconst createCookieEntry = (\n options?: Partial<CookiesAttributes>\n): CookieEntry => {\n const { name, path, expires, domain, secure, sameSite, httpOnly } =\n options ?? {};\n\n return {\n name: name ?? DefaultValues.Routing.COOKIE_NAME,\n attributes: {\n path,\n expires,\n domain,\n secure,\n sameSite,\n httpOnly,\n },\n };\n};\n\n/**\n * Creates a web storage entry (localStorage or sessionStorage) with default name\n */\nconst createWebStorageEntry = (\n options?: Partial<StorageAttributes>\n): WebStorageEntry => {\n const { name } = options ?? {};\n\n return {\n name: name ?? DefaultValues.Routing.LOCALE_STORAGE_NAME,\n };\n};\n\n/**\n * Creates a header entry with default name\n */\nconst createHeaderEntry = (\n options?: Partial<StorageAttributes>\n): HeaderEntry => {\n const { name } = options ?? {};\n\n return {\n name: name ?? DefaultValues.Routing.HEADER_NAME,\n };\n};\n\n/**\n * Determines if a storage entry is a cookie based on its properties\n */\nconst isCookieEntry = (entry: any): boolean => {\n return (\n entry.type === 'cookie' ||\n 'sameSite' in entry ||\n 'httpOnly' in entry ||\n 'secure' in entry\n );\n};\n\n/**\n * Determines the storage type from a string literal\n */\nconst isStorageType = (\n value: string\n): value is 'cookie' | 'localStorage' | 'sessionStorage' | 'header' => {\n return (\n value === 'cookie' ||\n value === 'localStorage' ||\n value === 'sessionStorage' ||\n value === 'header'\n );\n};\n\n// ============================================================================\n// Main Function\n// ============================================================================\n\n/**\n * Processes a single storage entry and returns the appropriate storage attributes\n */\nconst processStorageEntry = (\n entry: StorageEntry\n): Partial<ProcessedStorageAttributes> => {\n // Handle string literals\n if (typeof entry === 'string') {\n if (!isStorageType(entry)) {\n return { cookies: [], localStorage: [], sessionStorage: [], headers: [] };\n }\n\n if (entry === 'cookie') {\n return { cookies: [createCookieEntry()] };\n }\n\n if (entry === 'localStorage') {\n return { localStorage: [createWebStorageEntry()] };\n }\n\n if (entry === 'sessionStorage') {\n return { sessionStorage: [createWebStorageEntry()] };\n }\n\n if (entry === 'header') {\n return { headers: [createHeaderEntry()] };\n }\n }\n\n // Handle object entries\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\n // Handle localStorage\n if ('type' in typedEntry && typedEntry.type === 'localStorage') {\n const { name, ...rest } = typedEntry as StorageAttributes;\n return { localStorage: [createWebStorageEntry({ name, ...rest })] };\n }\n\n // Handle sessionStorage\n if ('type' in typedEntry && typedEntry.type === 'sessionStorage') {\n const { name, ...rest } = typedEntry as StorageAttributes;\n return { sessionStorage: [createWebStorageEntry({ name, ...rest })] };\n }\n\n // Handle header\n if ('type' in typedEntry && typedEntry.type === 'header') {\n const { name, ...rest } = typedEntry as StorageAttributes;\n return { headers: [createHeaderEntry({ name, ...rest })] };\n }\n\n // Default to localStorage for ambiguous objects\n const { name, ...rest } = typedEntry as Omit<StorageAttributes, 'type'>;\n return { localStorage: [createWebStorageEntry({ name, ...rest })] };\n }\n\n return { cookies: [], localStorage: [], sessionStorage: [], headers: [] };\n};\n\n/**\n * Merges multiple partial storage attributes into a single result\n */\nconst mergeStorageAttributes = (\n accumulated: ProcessedStorageAttributes,\n partial: Partial<ProcessedStorageAttributes>\n): ProcessedStorageAttributes => {\n return {\n cookies: [...accumulated.cookies, ...(partial.cookies ?? [])],\n localStorage: [\n ...accumulated.localStorage,\n ...(partial.localStorage ?? []),\n ],\n sessionStorage: [\n ...accumulated.sessionStorage,\n ...(partial.sessionStorage ?? []),\n ],\n headers: [...accumulated.headers, ...(partial.headers ?? [])],\n };\n};\n\n/**\n * Extracts and normalizes storage configuration into separate arrays for each storage type\n *\n * @param options - The storage configuration from IntlayerConfig\n * @returns An object containing arrays for cookies, localStorage, and sessionStorage\n */\nexport const getStorageAttributes = (\n options: IntlayerConfig['routing']['storage']\n): ProcessedStorageAttributes => {\n const emptyResult: ProcessedStorageAttributes = {\n cookies: [],\n localStorage: [],\n sessionStorage: [],\n headers: [],\n };\n\n // Storage is disabled\n if (options === false || options === undefined) {\n return emptyResult;\n }\n\n // Handle array of storage entries\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 // Handle single storage entry\n const partial = processStorageEntry(options);\n\n return mergeStorageAttributes(emptyResult, partial);\n};\n"],"mappings":";;;;;;;;AA8CA,MAAM,qBACJ,YACgB;CAChB,MAAM,EAAE,MAAM,MAAM,SAAS,QAAQ,QAAQ,UAAU,aACrD,WAAW,EAAE;AAEf,QAAO;EACL,MAAM,QAAQA,uCAAc,QAAQ;EACpC,YAAY;GACV;GACA;GACA;GACA;GACA;GACA;GACD;EACF;;;;;AAMH,MAAM,yBACJ,YACoB;CACpB,MAAM,EAAE,SAAS,WAAW,EAAE;AAE9B,QAAO,EACL,MAAM,QAAQA,uCAAc,QAAQ,qBACrC;;;;;AAMH,MAAM,qBACJ,YACgB;CAChB,MAAM,EAAE,SAAS,WAAW,EAAE;AAE9B,QAAO,EACL,MAAM,QAAQA,uCAAc,QAAQ,aACrC;;;;;AAMH,MAAM,iBAAiB,UAAwB;AAC7C,QACE,MAAM,SAAS,YACf,cAAc,SACd,cAAc,SACd,YAAY;;;;;AAOhB,MAAM,iBACJ,UACqE;AACrE,QACE,UAAU,YACV,UAAU,kBACV,UAAU,oBACV,UAAU;;;;;AAWd,MAAM,uBACJ,UACwC;AAExC,KAAI,OAAO,UAAU,UAAU;AAC7B,MAAI,CAAC,cAAc,MAAM,CACvB,QAAO;GAAE,SAAS,EAAE;GAAE,cAAc,EAAE;GAAE,gBAAgB,EAAE;GAAE,SAAS,EAAE;GAAE;AAG3E,MAAI,UAAU,SACZ,QAAO,EAAE,SAAS,CAAC,mBAAmB,CAAC,EAAE;A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AI,QAAQ,gBAAgB,EAAE,CAC/B;EACD,gBAAgB,CACd,GAAG,YAAY,gBACf,GAAI,QAAQ,kBAAkB,EAAE,CACjC;EACD,SAAS,CAAC,GAAG,YAAY,SAAS,GAAI,QAAQ,WAAW,EAAE,CAAE;EAC9D;;;;;;;;AASH,MAAa,wBACX,YAC+B;CAC/B,MAAMC,cAA0C;EAC9C,SAAS,EAAE;EACX,cAAc,EAAE;EAChB,gBAAgB,EAAE;EAClB,SAAS,EAAE;EACZ;AAGD,KAAI,YAAY,SAAS,YAAY,OACnC,QAAO;AAIT,KAAI,MAAM,QAAQ,QAAQ,CACxB,QAAO,QAAQ,QAAoC,KAAK,UAAU;AAEhE,SAAO,uBAAuB,KADd,oBAAoB,MAAM,CACC;IAC1C,YAAY;AAMjB,QAAO,uBAAuB,aAFd,oBAAoB,QAAQ,CAEO"}
@@ -3,6 +3,8 @@ const require_utils_checkIsURLAbsolute = require('../utils/checkIsURLAbsolute.cj
3
3
  const require_localization_getPathWithoutLocale = require('./getPathWithoutLocale.cjs');
4
4
  let __intlayer_config_built = require("@intlayer/config/built");
5
5
  __intlayer_config_built = require_rolldown_runtime.__toESM(__intlayer_config_built);
6
+ let __intlayer_config = require("@intlayer/config");
7
+ __intlayer_config = require_rolldown_runtime.__toESM(__intlayer_config);
6
8
 
7
9
  //#region src/localization/getMultilingualUrls.ts
8
10
  /**
@@ -45,7 +47,7 @@ const getMultilingualUrls = (url, locales = __intlayer_config_built.default?.int
45
47
  let pathname = parsedUrl.pathname;
46
48
  if (!pathname.startsWith("/")) pathname = `/${pathname}`;
47
49
  const baseUrl = isAbsoluteUrl ? `${parsedUrl.protocol}//${parsedUrl.host}` : "";
48
- const routingMode = mode ?? "prefix-no-default";
50
+ const routingMode = mode ?? __intlayer_config.DefaultValues.Routing.ROUTING_MODE;
49
51
  return (locales ?? []).reduce((acc, locale) => {
50
52
  const isDefaultLocale = locale?.toString() === defaultLocale?.toString();
51
53
  let localizedUrl;
@@ -1 +1 @@
1
- {"version":3,"file":"getMultilingualUrls.cjs","names":["configuration","getPathWithoutLocale","checkIsURLAbsolute","localizedUrl: string"],"sources":["../../../src/localization/getMultilingualUrls.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { LocalesValues, StrictModeLocaleMap } from '@intlayer/types';\nimport { checkIsURLAbsolute } from '../utils/checkIsURLAbsolute';\nimport { getPathWithoutLocale } from './getPathWithoutLocale';\n\n/**\n * Generates multilingual URLs by prefixing the given URL with each supported locale\n * or adding search parameters based on the routing mode.\n * Handles both absolute and relative URLs appropriately.\n *\n * This function gets the locales, default locale, and routing mode from the configuration if not provided.\n *\n * Example:\n *\n * ```ts\n * // prefix-no-default mode\n * getMultilingualUrls('/dashboard', ['en', 'fr'], 'en', 'prefix-no-default')\n * // Returns { en: '/dashboard', fr: '/fr/dashboard' }\n *\n * // prefix-all mode\n * getMultilingualUrls('/dashboard', ['en', 'fr'], 'en', 'prefix-all')\n * // Returns { en: '/en/dashboard', fr: '/fr/dashboard' }\n *\n * // search-params mode\n * getMultilingualUrls('/dashboard', ['en', 'fr'], 'en', 'search-params')\n * // Returns { en: '/dashboard?locale=en', fr: '/dashboard?locale=fr' }\n *\n * // no-prefix mode\n * getMultilingualUrls('/dashboard', ['en', 'fr'], 'en', 'no-prefix')\n * // Returns { en: '/dashboard', fr: '/dashboard' }\n * ```\n *\n * @param url - The original URL string to be processed.\n * @param locales - Optional array of supported locales. Defaults to configured locales.\n * @param defaultLocale - The default locale. Defaults to configured default locale.\n * @param mode - URL routing mode for locale handling. Defaults to configured mode.\n * @returns An object mapping each locale to its corresponding multilingual URL.\n */\nexport const getMultilingualUrls = (\n url: string,\n locales: LocalesValues[] | undefined = configuration?.internationalization\n ?.locales,\n defaultLocale: LocalesValues | undefined = configuration?.internationalization\n ?.defaultLocale,\n mode:\n | 'prefix-no-default'\n | 'prefix-all'\n | 'no-prefix'\n | 'search-params'\n | undefined = configuration?.routing?.mode\n): StrictModeLocaleMap<string> => {\n // Remove any existing locale segment from the URL\n const urlWithoutLocale = getPathWithoutLocale(url, locales);\n\n // Determine if the original URL is absolute (includes protocol)\n const isAbsoluteUrl = checkIsURLAbsolute(urlWithoutLocale);\n\n // Initialize a URL object if the URL is absolute\n // For relative URLs, use a dummy base to leverage the URL API\n const parsedUrl = isAbsoluteUrl\n ? new URL(urlWithoutLocale)\n : new URL(urlWithoutLocale, 'http://example.com');\n\n // Extract the pathname from the parsed URL\n let pathname = parsedUrl.pathname;\n\n // Ensure the pathname starts with a '/'\n if (!pathname.startsWith('/')) {\n pathname = `/${pathname}`;\n }\n\n // Prepare the base URL (protocol + host) if it's absolute\n const baseUrl = isAbsoluteUrl\n ? `${parsedUrl.protocol}//${parsedUrl.host}`\n : '';\n\n // Default mode to 'prefix-no-default' if not provided\n const routingMode = mode ?? 'prefix-no-default';\n\n // Generate multilingual URLs by iterating over each locale\n const multilingualUrls = (locales ?? []).reduce<StrictModeLocaleMap<string>>(\n (acc, locale) => {\n // Determine if the current locale is the default locale\n const isDefaultLocale = locale?.toString() === defaultLocale?.toString();\n\n let localizedUrl: string;\n\n if (routingMode === 'search-params') {\n // Use search parameters for locale handling\n const searchParams = new URLSearchParams(parsedUrl.search);\n searchParams.set('locale', locale.toString());\n\n const queryString = searchParams.toString();\n const pathWithQuery = queryString\n ? `${pathname}?${queryString}`\n : pathname;\n\n localizedUrl = isAbsoluteUrl\n ? `${baseUrl}${pathWithQuery}${parsedUrl.hash}`\n : `${pathWithQuery}${parsedUrl.hash}`;\n } else if (routingMode === 'no-prefix') {\n // No locale prefixing\n localizedUrl = isAbsoluteUrl\n ? `${baseUrl}${pathname}${parsedUrl.search}${parsedUrl.hash}`\n : `${pathname}${parsedUrl.search}${parsedUrl.hash}`;\n } else {\n // Handle prefix-based modes (prefix-all or prefix-no-default)\n const shouldPrefix =\n routingMode === 'prefix-all' ||\n (routingMode === 'prefix-no-default' && !isDefaultLocale);\n\n // Construct the new pathname with or without the locale prefix\n let localizedPath = shouldPrefix ? `/${locale}${pathname}` : pathname;\n\n if (localizedPath.length > 1 && localizedPath.endsWith('/')) {\n localizedPath = localizedPath.slice(0, -1);\n }\n\n // Combine with the base URL if the original URL was absolute\n localizedUrl = isAbsoluteUrl\n ? `${baseUrl}${localizedPath}${parsedUrl.search}${parsedUrl.hash}`\n : `${localizedPath}${parsedUrl.search}${parsedUrl.hash}`;\n }\n\n // Assign the constructed URL to the corresponding locale key\n acc[locale as unknown as keyof typeof acc] = localizedUrl;\n\n return acc;\n },\n {} as StrictModeLocaleMap<string>\n );\n\n return multilingualUrls;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCA,MAAa,uBACX,KACA,UAAuCA,iCAAe,sBAClD,SACJ,gBAA2CA,iCAAe,sBACtD,eACJ,OAKgBA,iCAAe,SAAS,SACR;CAEhC,MAAM,mBAAmBC,+DAAqB,KAAK,QAAQ;CAG3D,MAAM,gBAAgBC,oDAAmB,iBAAiB;CAI1D,MAAM,YAAY,gBACd,IAAI,IAAI,iBAAiB,GACzB,IAAI,IAAI,kBAAkB,qBAAqB;CAGnD,IAAI,WAAW,UAAU;AAGzB,KAAI,CAAC,SAAS,WAAW,IAAI,CAC3B,YAAW,IAAI;CAIjB,MAAM,UAAU,gBACZ,GAAG,UAAU,SAAS,IAAI,UAAU,SACpC;CAGJ,MAAM,cAAc,QAAQ;AAuD5B,SApD0B,WAAW,EAAE,EAAE,QACtC,KAAK,WAAW;EAEf,MAAM,kBAAkB,QAAQ,UAAU,KAAK,eAAe,UAAU;EAExE,IAAIC;AAEJ,MAAI,gBAAgB,iBAAiB;GAEnC,MAAM,eAAe,IAAI,gBAAgB,UAAU,OAAO;AAC1D,gBAAa,IAAI,UAAU,OAAO,UAAU,CAAC;GAE7C,MAAM,cAAc,aAAa,UAAU;GAC3C,MAAM,gBAAgB,cAClB,GAAG,SAAS,GAAG,gBACf;AAEJ,kBAAe,gBACX,GAAG,UAAU,gBAAgB,UAAU,SACvC,GAAG,gBAAgB,UAAU;aACxB,gBAAgB,YAEzB,gBAAe,gBACX,GAAG,UAAU,WAAW,UAAU,SAAS,UAAU,SACrD,GAAG,WAAW,UAAU,SAAS,UAAU;OAC1C;GAOL,IAAI,gBAJF,gBAAgB,gBACf,gBAAgB,uBAAuB,CAAC,kBAGR,IAAI,SAAS,aAAa;AAE7D,OAAI,cAAc,SAAS,KAAK,cAAc,SAAS,IAAI,CACzD,iBAAgB,cAAc,MAAM,GAAG,GAAG;AAI5C,kBAAe,gBACX,GAAG,UAAU,gBAAgB,UAAU,SAAS,UAAU,SAC1D,GAAG,gBAAgB,UAAU,SAAS,UAAU;;AAItD,MAAI,UAAyC;AAE7C,SAAO;IAET,EAAE,CACH"}
1
+ {"version":3,"file":"getMultilingualUrls.cjs","names":["configuration","getPathWithoutLocale","checkIsURLAbsolute","DefaultValues","localizedUrl: string"],"sources":["../../../src/localization/getMultilingualUrls.ts"],"sourcesContent":["import { DefaultValues } from '@intlayer/config';\nimport configuration from '@intlayer/config/built';\nimport type { LocalesValues, StrictModeLocaleMap } from '@intlayer/types';\nimport { checkIsURLAbsolute } from '../utils/checkIsURLAbsolute';\nimport { getPathWithoutLocale } from './getPathWithoutLocale';\n\n/**\n * Generates multilingual URLs by prefixing the given URL with each supported locale\n * or adding search parameters based on the routing mode.\n * Handles both absolute and relative URLs appropriately.\n *\n * This function gets the locales, default locale, and routing mode from the configuration if not provided.\n *\n * Example:\n *\n * ```ts\n * // prefix-no-default mode\n * getMultilingualUrls('/dashboard', ['en', 'fr'], 'en', 'prefix-no-default')\n * // Returns { en: '/dashboard', fr: '/fr/dashboard' }\n *\n * // prefix-all mode\n * getMultilingualUrls('/dashboard', ['en', 'fr'], 'en', 'prefix-all')\n * // Returns { en: '/en/dashboard', fr: '/fr/dashboard' }\n *\n * // search-params mode\n * getMultilingualUrls('/dashboard', ['en', 'fr'], 'en', 'search-params')\n * // Returns { en: '/dashboard?locale=en', fr: '/dashboard?locale=fr' }\n *\n * // no-prefix mode\n * getMultilingualUrls('/dashboard', ['en', 'fr'], 'en', 'no-prefix')\n * // Returns { en: '/dashboard', fr: '/dashboard' }\n * ```\n *\n * @param url - The original URL string to be processed.\n * @param locales - Optional array of supported locales. Defaults to configured locales.\n * @param defaultLocale - The default locale. Defaults to configured default locale.\n * @param mode - URL routing mode for locale handling. Defaults to configured mode.\n * @returns An object mapping each locale to its corresponding multilingual URL.\n */\nexport const getMultilingualUrls = (\n url: string,\n locales: LocalesValues[] | undefined = configuration?.internationalization\n ?.locales,\n defaultLocale: LocalesValues | undefined = configuration?.internationalization\n ?.defaultLocale,\n mode:\n | 'prefix-no-default'\n | 'prefix-all'\n | 'no-prefix'\n | 'search-params'\n | undefined = configuration?.routing?.mode\n): StrictModeLocaleMap<string> => {\n // Remove any existing locale segment from the URL\n const urlWithoutLocale = getPathWithoutLocale(url, locales);\n\n // Determine if the original URL is absolute (includes protocol)\n const isAbsoluteUrl = checkIsURLAbsolute(urlWithoutLocale);\n\n // Initialize a URL object if the URL is absolute\n // For relative URLs, use a dummy base to leverage the URL API\n const parsedUrl = isAbsoluteUrl\n ? new URL(urlWithoutLocale)\n : new URL(urlWithoutLocale, 'http://example.com');\n\n // Extract the pathname from the parsed URL\n let pathname = parsedUrl.pathname;\n\n // Ensure the pathname starts with a '/'\n if (!pathname.startsWith('/')) {\n pathname = `/${pathname}`;\n }\n\n // Prepare the base URL (protocol + host) if it's absolute\n const baseUrl = isAbsoluteUrl\n ? `${parsedUrl.protocol}//${parsedUrl.host}`\n : '';\n\n // Default mode to 'prefix-no-default' if not provided\n const routingMode = mode ?? DefaultValues.Routing.ROUTING_MODE;\n\n // Generate multilingual URLs by iterating over each locale\n const multilingualUrls = (locales ?? []).reduce<StrictModeLocaleMap<string>>(\n (acc, locale) => {\n // Determine if the current locale is the default locale\n const isDefaultLocale = locale?.toString() === defaultLocale?.toString();\n\n let localizedUrl: string;\n\n if (routingMode === 'search-params') {\n // Use search parameters for locale handling\n const searchParams = new URLSearchParams(parsedUrl.search);\n searchParams.set('locale', locale.toString());\n\n const queryString = searchParams.toString();\n const pathWithQuery = queryString\n ? `${pathname}?${queryString}`\n : pathname;\n\n localizedUrl = isAbsoluteUrl\n ? `${baseUrl}${pathWithQuery}${parsedUrl.hash}`\n : `${pathWithQuery}${parsedUrl.hash}`;\n } else if (routingMode === 'no-prefix') {\n // No locale prefixing\n localizedUrl = isAbsoluteUrl\n ? `${baseUrl}${pathname}${parsedUrl.search}${parsedUrl.hash}`\n : `${pathname}${parsedUrl.search}${parsedUrl.hash}`;\n } else {\n // Handle prefix-based modes (prefix-all or prefix-no-default)\n const shouldPrefix =\n routingMode === 'prefix-all' ||\n (routingMode === 'prefix-no-default' && !isDefaultLocale);\n\n // Construct the new pathname with or without the locale prefix\n let localizedPath = shouldPrefix ? `/${locale}${pathname}` : pathname;\n\n if (localizedPath.length > 1 && localizedPath.endsWith('/')) {\n localizedPath = localizedPath.slice(0, -1);\n }\n\n // Combine with the base URL if the original URL was absolute\n localizedUrl = isAbsoluteUrl\n ? `${baseUrl}${localizedPath}${parsedUrl.search}${parsedUrl.hash}`\n : `${localizedPath}${parsedUrl.search}${parsedUrl.hash}`;\n }\n\n // Assign the constructed URL to the corresponding locale key\n acc[locale as unknown as keyof typeof acc] = localizedUrl;\n\n return acc;\n },\n {} as StrictModeLocaleMap<string>\n );\n\n return multilingualUrls;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuCA,MAAa,uBACX,KACA,UAAuCA,iCAAe,sBAClD,SACJ,gBAA2CA,iCAAe,sBACtD,eACJ,OAKgBA,iCAAe,SAAS,SACR;CAEhC,MAAM,mBAAmBC,+DAAqB,KAAK,QAAQ;CAG3D,MAAM,gBAAgBC,oDAAmB,iBAAiB;CAI1D,MAAM,YAAY,gBACd,IAAI,IAAI,iBAAiB,GACzB,IAAI,IAAI,kBAAkB,qBAAqB;CAGnD,IAAI,WAAW,UAAU;AAGzB,KAAI,CAAC,SAAS,WAAW,IAAI,CAC3B,YAAW,IAAI;CAIjB,MAAM,UAAU,gBACZ,GAAG,UAAU,SAAS,IAAI,UAAU,SACpC;CAGJ,MAAM,cAAc,QAAQC,gCAAc,QAAQ;AAuDlD,SApD0B,WAAW,EAAE,EAAE,QACtC,KAAK,WAAW;EAEf,MAAM,kBAAkB,QAAQ,UAAU,KAAK,eAAe,UAAU;EAExE,IAAIC;AAEJ,MAAI,gBAAgB,iBAAiB;GAEnC,MAAM,eAAe,IAAI,gBAAgB,UAAU,OAAO;AAC1D,gBAAa,IAAI,UAAU,OAAO,UAAU,CAAC;GAE7C,MAAM,cAAc,aAAa,UAAU;GAC3C,MAAM,gBAAgB,cAClB,GAAG,SAAS,GAAG,gBACf;AAEJ,kBAAe,gBACX,GAAG,UAAU,gBAAgB,UAAU,SACvC,GAAG,gBAAgB,UAAU;aACxB,gBAAgB,YAEzB,gBAAe,gBACX,GAAG,UAAU,WAAW,UAAU,SAAS,UAAU,SACrD,GAAG,WAAW,UAAU,SAAS,UAAU;OAC1C;GAOL,IAAI,gBAJF,gBAAgB,gBACf,gBAAgB,uBAAuB,CAAC,kBAGR,IAAI,SAAS,aAAa;AAE7D,OAAI,cAAc,SAAS,KAAK,cAAc,SAAS,IAAI,CACzD,iBAAgB,cAAc,MAAM,GAAG,GAAG;AAI5C,kBAAe,gBACX,GAAG,UAAU,gBAAgB,UAAU,SAAS,UAAU,SAC1D,GAAG,gBAAgB,UAAU,SAAS,UAAU;;AAItD,MAAI,UAAyC;AAE7C,SAAO;IAET,EAAE,CACH"}
@@ -1,12 +1,12 @@
1
1
  const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
2
2
  let __intlayer_types = require("@intlayer/types");
3
3
  __intlayer_types = require_rolldown_runtime.__toESM(__intlayer_types);
4
+ let __intlayer_config = require("@intlayer/config");
5
+ __intlayer_config = require_rolldown_runtime.__toESM(__intlayer_config);
4
6
  let node_fs = require("node:fs");
5
7
  node_fs = require_rolldown_runtime.__toESM(node_fs);
6
8
  let node_path = require("node:path");
7
9
  node_path = require_rolldown_runtime.__toESM(node_path);
8
- let __intlayer_config = require("@intlayer/config");
9
- __intlayer_config = require_rolldown_runtime.__toESM(__intlayer_config);
10
10
 
11
11
  //#region src/transpiler/file/file.ts
12
12
  const fileContent = (path, callerDir, baseDir) => {
@@ -14,7 +14,7 @@ const buildCookieString = (name, value, attributes) => {
14
14
  return parts.join("; ");
15
15
  };
16
16
  /**
17
- * Retrieves the locale from various storage mechanisms (cookies, localStorage, sessionStorage).
17
+ * Retrieves the locale from various storage mechanisms (cookies, localStorage, sessionStorage, headers).
18
18
  * The function checks storage locations in order of priority as defined in the configuration.
19
19
  *
20
20
  * @returns The locale if found in any storage, or undefined if not found
@@ -72,9 +72,16 @@ const getLocaleFromStorage = (options) => {
72
72
  if (isValidLocale(value)) return value;
73
73
  } catch {}
74
74
  }
75
+ for (let i = 0; i < storageAttributes.headers.length; i++) {
76
+ const { name } = storageAttributes.headers[i];
77
+ try {
78
+ const value = options?.getHeader?.(name);
79
+ if (isValidLocale(value)) return value;
80
+ } catch {}
81
+ }
75
82
  };
76
83
  /**
77
- * Stores the locale in various storage mechanisms (cookies, localStorage, sessionStorage).
84
+ * Stores the locale in various storage mechanisms (cookies, localStorage, sessionStorage, headers).
78
85
  * The function writes to all configured storage locations according to their attributes.
79
86
  * Respects overwrite flags for localStorage and sessionStorage.
80
87
  *
@@ -117,15 +124,21 @@ const setLocaleInStorage = (locale, options) => {
117
124
  options?.setSessionStorage?.(name, locale);
118
125
  } catch {}
119
126
  }
127
+ if (options?.setHeader) for (let i = 0; i < storageAttributes.headers.length; i++) {
128
+ const { name } = storageAttributes.headers[i];
129
+ try {
130
+ options?.setHeader?.(name, locale);
131
+ } catch {}
132
+ }
120
133
  };
121
134
  /**
122
135
  * Utility object to get and set the locale in the storage by considering the configuration
123
136
  *
124
- * @property getLocale - Retrieves the locale from various storage mechanisms (cookies, localStorage, sessionStorage).
125
- * Retrieves the locale from various storage mechanisms (cookies, localStorage, sessionStorage).
137
+ * @property getLocale - Retrieves the locale from various storage mechanisms (cookies, localStorage, sessionStorage, headers).
138
+ * Retrieves the locale from various storage mechanisms (cookies, localStorage, sessionStorage, headers).
126
139
  * The function checks storage locations in order of priority as defined in the configuration.
127
140
  *
128
- * @property setLocale - Stores the locale in various storage mechanisms (cookies, localStorage, sessionStorage).
141
+ * @property setLocale - Stores the locale in various storage mechanisms (cookies, localStorage, sessionStorage, headers).
129
142
  * The function writes to all configured storage locations according to their attributes.
130
143
  * Respects overwrite flags for localStorage and sessionStorage.
131
144
  *
@@ -1 +1 @@
1
- {"version":3,"file":"localeStorage.cjs","names":["parts: string[]","configuration","getStorageAttributes"],"sources":["../../../src/utils/localeStorage.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { CookiesAttributes, Locale, LocalesValues } from '@intlayer/types';\nimport { getStorageAttributes } from '../getStorageAttributes';\n\ntype CookieBuildAttributes = {\n /**\n * Cookie domain to store the locale information\n *\n * Default: undefined\n *\n * Define the domain where the cookie is available. Defaults to\n * the domain of the page where the cookie was created.\n */\n domain?: string;\n /**\n * Cookie path to store the locale information\n *\n * Default: undefined\n *\n * Define the path where the cookie is available. Defaults to '/'\n */\n path?: string;\n /**\n * Cookie secure to store the locale information\n *\n * Default: undefined\n *\n * A Boolean indicating if the cookie transmission requires a\n * secure protocol (https). Defaults to false.\n */\n secure?: boolean;\n /**\n * Cookie httpOnly to store the locale information\n *\n * Default: undefined\n *\n * The cookie httpOnly where the locale information is stored.\n */\n httpOnly?: boolean;\n /**\n * Cookie sameSite to store the locale information\n *\n * Default: undefined\n *\n * Asserts that a cookie must not be sent with cross-origin requests,\n * providing some protection against cross-site request forgery\n * attacks (CSRF)\n */\n sameSite?: 'strict' | 'lax' | 'none';\n\n /**\n * Cookie expires to store the locale information\n *\n * Default: undefined\n *\n * Define when the cookie will be removed. Value can be a Number\n * which will be interpreted as days from time of creation or a\n * Date instance. If omitted, the cookie becomes a session cookie.\n */\n expires?: number | undefined;\n};\n\nconst buildCookieString = (\n name: string,\n value: string,\n attributes: Omit<CookiesAttributes, 'name' | 'type'>\n): string => {\n const encodedValue = encodeURIComponent(value);\n const parts: string[] = [`${name}=${encodedValue}`];\n\n if (attributes.path) parts.push(`Path=${attributes.path}`);\n if (attributes.domain) parts.push(`Domain=${attributes.domain}`);\n if (attributes.expires instanceof Date)\n parts.push(`Expires=${attributes.expires.toUTCString()}`);\n\n if (attributes.secure) parts.push('Secure');\n if (attributes.sameSite) parts.push(`SameSite=${attributes.sameSite}`);\n return parts.join('; ');\n};\n\nexport type LocaleStorageOptions = {\n overwrite?: boolean;\n isCookieEnabled?: boolean;\n setCookieStore?: (\n name: string,\n value: string,\n cookie: CookieBuildAttributes\n ) => void;\n setCookieString?: (name: string, cookie: string) => void;\n getCookie?: (name: string) => string | undefined | null;\n setSessionStorage?: (name: string, value: string) => void;\n getSessionStorage?: (name: string) => string | undefined | null;\n setLocaleStorage?: (name: string, value: string) => void;\n getLocaleStorage?: (name: string) => string | undefined | null;\n};\n\n/**\n * Retrieves the locale from various storage mechanisms (cookies, localStorage, sessionStorage).\n * The function checks storage locations in order of priority as defined in the configuration.\n *\n * @returns The locale if found in any storage, or undefined if not found\n */\nexport const getLocaleFromStorage = (\n options: Pick<\n LocaleStorageOptions,\n 'getCookie' | 'getSessionStorage' | 'getLocaleStorage' | 'isCookieEnabled'\n >\n): Locale | undefined => {\n const { routing, internationalization } = configuration;\n const { locales } = internationalization;\n const { storage } = routing;\n\n // If storage is disabled, return undefined\n if (storage === false || options?.isCookieEnabled === false) return undefined;\n\n const storageAttributes = getStorageAttributes(storage);\n\n const isValidLocale = (value: string | null | undefined): value is Locale => {\n if (!value) return false;\n\n return locales.includes(value as Locale);\n };\n\n const readCookie = (name: string): string | undefined => {\n // Prefer provided getter (server or custom environment)\n try {\n const fromOption = options?.getCookie?.(name);\n\n if (fromOption !== null) return fromOption;\n } catch {}\n\n // Fallback to browser cookie parsing\n try {\n const cookieString = document.cookie ?? '';\n\n if (!cookieString) return;\n\n const pairs = cookieString.split(';');\n\n for (let i = 0; i < pairs.length; i++) {\n const part = pairs[i].trim();\n\n if (!part) continue;\n\n const equalIndex = part.indexOf('=');\n const key = equalIndex >= 0 ? part.substring(0, equalIndex) : part;\n\n if (key === name) {\n const rawValue =\n equalIndex >= 0 ? part.substring(equalIndex + 1) : '';\n\n try {\n return decodeURIComponent(rawValue);\n } catch {\n return rawValue;\n }\n }\n }\n } catch {}\n };\n\n // 1) Check cookies first\n for (let i = 0; i < storageAttributes.cookies.length; i++) {\n const { name } = storageAttributes.cookies[i];\n\n const value = readCookie(name);\n\n if (isValidLocale(value)) return value;\n }\n\n // 2) Then check localStorage candidates (browser only)\n for (let i = 0; i < storageAttributes.localStorage.length; i++) {\n const { name } = storageAttributes.localStorage[i];\n\n try {\n const value = options?.getLocaleStorage?.(name);\n\n if (isValidLocale(value)) return value;\n } catch {}\n }\n\n // 3) Finally check sessionStorage candidates (browser only)\n for (let i = 0; i < storageAttributes.sessionStorage.length; i++) {\n const { name } = storageAttributes.sessionStorage[i];\n\n try {\n const value = options?.getSessionStorage?.(name);\n\n if (isValidLocale(value)) return value;\n } catch {}\n }\n};\n\n/**\n * Stores the locale in various storage mechanisms (cookies, localStorage, sessionStorage).\n * The function writes to all configured storage locations according to their attributes.\n * Respects overwrite flags for localStorage and sessionStorage.\n *\n * @param locale - The locale to store\n */\nexport const setLocaleInStorage = (\n locale: LocalesValues,\n options?: LocaleStorageOptions\n): void => {\n // If storage is disabled, do nothing\n if (\n configuration.routing.storage === false ||\n options?.isCookieEnabled === false\n )\n return;\n\n const storageAttributes = getStorageAttributes(configuration.routing.storage);\n\n // Write to cookies (server via setCookie, client via cookieStore/document)\n for (let i = 0; i < storageAttributes.cookies.length; i++) {\n const { name, attributes } = storageAttributes.cookies[i];\n\n try {\n if (options?.setCookieStore) {\n options?.setCookieStore?.(name, locale, {\n ...attributes,\n expires:\n attributes.expires instanceof Date\n ? attributes.expires.getTime()\n : attributes.expires,\n });\n }\n } catch {\n try {\n if (options?.setCookieString) {\n const cookieString = buildCookieString(name, locale, attributes);\n\n options?.setCookieString?.(name, cookieString);\n }\n } catch {}\n }\n }\n\n // Write to localStorage (browser only)\n if (options?.setLocaleStorage) {\n for (let i = 0; i < storageAttributes.localStorage.length; i++) {\n const { name } = storageAttributes.localStorage[i];\n\n try {\n const shouldOverwrite = options?.overwrite ?? true;\n\n if (!shouldOverwrite && options?.getLocaleStorage) {\n const existing = options?.getLocaleStorage?.(name);\n if (existing) continue;\n }\n options?.setLocaleStorage?.(name, locale);\n } catch {}\n }\n }\n\n // Write to sessionStorage (browser only)\n if (options?.setSessionStorage) {\n for (let i = 0; i < storageAttributes.sessionStorage.length; i++) {\n const { name } = storageAttributes.sessionStorage[i];\n\n try {\n const shouldOverwrite = options?.overwrite ?? true;\n\n if (!shouldOverwrite && options?.getSessionStorage) {\n const existing = options?.getSessionStorage?.(name);\n if (existing) continue;\n }\n\n options?.setSessionStorage?.(name, locale);\n } catch {}\n }\n }\n};\n\n/**\n * Utility object to get and set the locale in the storage by considering the configuration\n *\n * @property getLocale - Retrieves the locale from various storage mechanisms (cookies, localStorage, sessionStorage).\n * Retrieves the locale from various storage mechanisms (cookies, localStorage, sessionStorage).\n * The function checks storage locations in order of priority as defined in the configuration.\n *\n * @property setLocale - Stores the locale in various storage mechanisms (cookies, localStorage, sessionStorage).\n * The function writes to all configured storage locations according to their attributes.\n * Respects overwrite flags for localStorage and sessionStorage.\n *\n * @returns The locale if found in any storage, or undefined if not found\n */\nexport const LocaleStorage = (options: LocaleStorageOptions) => ({\n getLocale: () => getLocaleFromStorage(options),\n setLocale: (locale: LocalesValues) => setLocaleInStorage(locale, options),\n});\n"],"mappings":";;;;;;AA8DA,MAAM,qBACJ,MACA,OACA,eACW;CAEX,MAAMA,QAAkB,CAAC,GAAG,KAAK,GADZ,mBAAmB,MAAM,GACK;AAEnD,KAAI,WAAW,KAAM,OAAM,KAAK,QAA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AS,mBAAmB,KAAK,CACpC;;AAEhB,YAAS,mBAAmB,MAAM,OAAO;UACnC;;AAKZ,KAAI,SAAS,kBACX,MAAK,IAAI,IAAI,GAAG,IAAI,kBAAkB,eAAe,QAAQ,KAAK;EAChE,MAAM,EAAE,SAAS,kBAAkB,eAAe;AAElD,MAAI;AAGF,OAAI,EAFoB,SAAS,aAAa,SAEtB,SAAS,mBAE/B;QADiB,SAAS,oBAAoB,KAAK,CACrC;;AAGhB,YAAS,oBAAoB,MAAM,OAAO;UACpC;;;;;;;;;;;;;;;;AAkBd,MAAa,iBAAiB,aAAmC;CAC/D,iBAAiB,qBAAqB,QAAQ;CAC9C,YAAY,WAA0B,mBAAmB,QAAQ,QAAQ;CAC1E"}
1
+ {"version":3,"file":"localeStorage.cjs","names":["parts: string[]","configuration","getStorageAttributes"],"sources":["../../../src/utils/localeStorage.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { CookiesAttributes, Locale, LocalesValues } from '@intlayer/types';\nimport { getStorageAttributes } from '../getStorageAttributes';\n\ntype CookieBuildAttributes = {\n /**\n * Cookie domain to store the locale information\n *\n * Default: undefined\n *\n * Define the domain where the cookie is available. Defaults to\n * the domain of the page where the cookie was created.\n */\n domain?: string;\n /**\n * Cookie path to store the locale information\n *\n * Default: undefined\n *\n * Define the path where the cookie is available. Defaults to '/'\n */\n path?: string;\n /**\n * Cookie secure to store the locale information\n *\n * Default: undefined\n *\n * A Boolean indicating if the cookie transmission requires a\n * secure protocol (https). Defaults to false.\n */\n secure?: boolean;\n /**\n * Cookie httpOnly to store the locale information\n *\n * Default: undefined\n *\n * The cookie httpOnly where the locale information is stored.\n */\n httpOnly?: boolean;\n /**\n * Cookie sameSite to store the locale information\n *\n * Default: undefined\n *\n * Asserts that a cookie must not be sent with cross-origin requests,\n * providing some protection against cross-site request forgery\n * attacks (CSRF)\n */\n sameSite?: 'strict' | 'lax' | 'none';\n\n /**\n * Cookie expires to store the locale information\n *\n * Default: undefined\n *\n * Define when the cookie will be removed. Value can be a Number\n * which will be interpreted as days from time of creation or a\n * Date instance. If omitted, the cookie becomes a session cookie.\n */\n expires?: number | undefined;\n};\n\nconst buildCookieString = (\n name: string,\n value: string,\n attributes: Omit<CookiesAttributes, 'name' | 'type'>\n): string => {\n const encodedValue = encodeURIComponent(value);\n const parts: string[] = [`${name}=${encodedValue}`];\n\n if (attributes.path) parts.push(`Path=${attributes.path}`);\n if (attributes.domain) parts.push(`Domain=${attributes.domain}`);\n if (attributes.expires instanceof Date)\n parts.push(`Expires=${attributes.expires.toUTCString()}`);\n\n if (attributes.secure) parts.push('Secure');\n if (attributes.sameSite) parts.push(`SameSite=${attributes.sameSite}`);\n return parts.join('; ');\n};\n\nexport type LocaleStorageOptions = {\n overwrite?: boolean;\n isCookieEnabled?: boolean;\n setCookieStore?: (\n name: string,\n value: string,\n cookie: CookieBuildAttributes\n ) => void;\n setCookieString?: (name: string, cookie: string) => void;\n getCookie?: (name: string) => string | undefined | null;\n setSessionStorage?: (name: string, value: string) => void;\n getSessionStorage?: (name: string) => string | undefined | null;\n setLocaleStorage?: (name: string, value: string) => void;\n getLocaleStorage?: (name: string) => string | undefined | null;\n getHeader?: (name: string) => string | undefined | null;\n setHeader?: (name: string, value: string) => void;\n};\n\n/**\n * Retrieves the locale from various storage mechanisms (cookies, localStorage, sessionStorage, headers).\n * The function checks storage locations in order of priority as defined in the configuration.\n *\n * @returns The locale if found in any storage, or undefined if not found\n */\nexport const getLocaleFromStorage = (\n options: Pick<\n LocaleStorageOptions,\n | 'getCookie'\n | 'getSessionStorage'\n | 'getLocaleStorage'\n | 'getHeader'\n | 'isCookieEnabled'\n >\n): Locale | undefined => {\n const { routing, internationalization } = configuration;\n const { locales } = internationalization;\n const { storage } = routing;\n\n // If storage is disabled, return undefined\n if (storage === false || options?.isCookieEnabled === false) return undefined;\n\n const storageAttributes = getStorageAttributes(storage);\n\n const isValidLocale = (value: string | null | undefined): value is Locale => {\n if (!value) return false;\n\n return locales.includes(value as Locale);\n };\n\n const readCookie = (name: string): string | undefined => {\n // Prefer provided getter (server or custom environment)\n try {\n const fromOption = options?.getCookie?.(name);\n\n if (fromOption !== null) return fromOption;\n } catch {}\n\n // Fallback to browser cookie parsing\n try {\n const cookieString = document.cookie ?? '';\n\n if (!cookieString) return;\n\n const pairs = cookieString.split(';');\n\n for (let i = 0; i < pairs.length; i++) {\n const part = pairs[i].trim();\n\n if (!part) continue;\n\n const equalIndex = part.indexOf('=');\n const key = equalIndex >= 0 ? part.substring(0, equalIndex) : part;\n\n if (key === name) {\n const rawValue =\n equalIndex >= 0 ? part.substring(equalIndex + 1) : '';\n\n try {\n return decodeURIComponent(rawValue);\n } catch {\n return rawValue;\n }\n }\n }\n } catch {}\n };\n\n // 1) Check cookies first\n for (let i = 0; i < storageAttributes.cookies.length; i++) {\n const { name } = storageAttributes.cookies[i];\n\n const value = readCookie(name);\n\n if (isValidLocale(value)) return value;\n }\n\n // 2) Then check localStorage candidates (browser only)\n for (let i = 0; i < storageAttributes.localStorage.length; i++) {\n const { name } = storageAttributes.localStorage[i];\n\n try {\n const value = options?.getLocaleStorage?.(name);\n\n if (isValidLocale(value)) return value;\n } catch {}\n }\n\n // 3) Check sessionStorage candidates (browser only)\n for (let i = 0; i < storageAttributes.sessionStorage.length; i++) {\n const { name } = storageAttributes.sessionStorage[i];\n\n try {\n const value = options?.getSessionStorage?.(name);\n\n if (isValidLocale(value)) return value;\n } catch {}\n }\n\n // 4) Finally check header candidates (server only)\n for (let i = 0; i < storageAttributes.headers.length; i++) {\n const { name } = storageAttributes.headers[i];\n\n try {\n const value = options?.getHeader?.(name);\n\n if (isValidLocale(value)) return value;\n } catch {}\n }\n};\n\n/**\n * Stores the locale in various storage mechanisms (cookies, localStorage, sessionStorage, headers).\n * The function writes to all configured storage locations according to their attributes.\n * Respects overwrite flags for localStorage and sessionStorage.\n *\n * @param locale - The locale to store\n */\nexport const setLocaleInStorage = (\n locale: LocalesValues,\n options?: LocaleStorageOptions\n): void => {\n // If storage is disabled, do nothing\n if (\n configuration.routing.storage === false ||\n options?.isCookieEnabled === false\n )\n return;\n\n const storageAttributes = getStorageAttributes(configuration.routing.storage);\n\n // Write to cookies (server via setCookie, client via cookieStore/document)\n for (let i = 0; i < storageAttributes.cookies.length; i++) {\n const { name, attributes } = storageAttributes.cookies[i];\n\n try {\n if (options?.setCookieStore) {\n options?.setCookieStore?.(name, locale, {\n ...attributes,\n expires:\n attributes.expires instanceof Date\n ? attributes.expires.getTime()\n : attributes.expires,\n });\n }\n } catch {\n try {\n if (options?.setCookieString) {\n const cookieString = buildCookieString(name, locale, attributes);\n\n options?.setCookieString?.(name, cookieString);\n }\n } catch {}\n }\n }\n\n // Write to localStorage (browser only)\n if (options?.setLocaleStorage) {\n for (let i = 0; i < storageAttributes.localStorage.length; i++) {\n const { name } = storageAttributes.localStorage[i];\n\n try {\n const shouldOverwrite = options?.overwrite ?? true;\n\n if (!shouldOverwrite && options?.getLocaleStorage) {\n const existing = options?.getLocaleStorage?.(name);\n if (existing) continue;\n }\n options?.setLocaleStorage?.(name, locale);\n } catch {}\n }\n }\n\n // Write to sessionStorage (browser only)\n if (options?.setSessionStorage) {\n for (let i = 0; i < storageAttributes.sessionStorage.length; i++) {\n const { name } = storageAttributes.sessionStorage[i];\n\n try {\n const shouldOverwrite = options?.overwrite ?? true;\n\n if (!shouldOverwrite && options?.getSessionStorage) {\n const existing = options?.getSessionStorage?.(name);\n if (existing) continue;\n }\n\n options?.setSessionStorage?.(name, locale);\n } catch {}\n }\n }\n\n // Write to headers (server only)\n if (options?.setHeader) {\n for (let i = 0; i < storageAttributes.headers.length; i++) {\n const { name } = storageAttributes.headers[i];\n\n try {\n options?.setHeader?.(name, locale);\n } catch {}\n }\n }\n};\n\n/**\n * Utility object to get and set the locale in the storage by considering the configuration\n *\n * @property getLocale - Retrieves the locale from various storage mechanisms (cookies, localStorage, sessionStorage, headers).\n * Retrieves the locale from various storage mechanisms (cookies, localStorage, sessionStorage, headers).\n * The function checks storage locations in order of priority as defined in the configuration.\n *\n * @property setLocale - Stores the locale in various storage mechanisms (cookies, localStorage, sessionStorage, headers).\n * The function writes to all configured storage locations according to their attributes.\n * Respects overwrite flags for localStorage and sessionStorage.\n *\n * @returns The locale if found in any storage, or undefined if not found\n */\nexport const LocaleStorage = (options: LocaleStorageOptions) => ({\n getLocale: () => getLocaleFromStorage(options),\n setLocale: (locale: LocalesValues) => setLocaleInStorage(locale, options),\n});\n"],"mappings":";;;;;;AA8DA,MAAM,qBACJ,MACA,OACA,eACW;CAEX,MAAMA,QAAkB,CAAC,GAAG,KAAK,GADZ,mBAAmB,MAAM,GACK;AAEnD,KAAI,WAAW,KAAM,OAAM,KAAK,QAAQ,WAAW,OAAO;AAC1D,KAAI,WAAW,OAAQ,OAAM,KAAK,UAAU,WAAW,SAAS;AAChE,KAAI,WAAW,mBAAmB,KAChC,OAAM,KAAK,WAAW,WAAW,QAAQ,aAAa,GAAG;AAE3D,KAAI,WAAW,OAAQ,OAAM,KAAK,SAAS;AAC3C,KAAI,WAAW,SAAU,OAAM,KAAK,YAAY,WAAW,WAAW;AACtE,QAAO,MAAM,KAAK,KAAK;;;;;;;;AA2BzB,MAAa,wBACX,YAQuB;CACvB,MAAM,EAAE,SAAS,yBAAyBC;CAC1C,MAAM,EAAE,YAAY;CACpB,MAAM,EAAE,YAAY;AAGpB,KAAI,YAAY,SAAS,SAAS,oBAAoB,MAAO,QAAO;CAEpE,MAAM,oBAAoBC,kDAAqB,QAAQ;CAEvD,MAAM,iBAAiB,UAAsD;AAC3E,MAAI,CAAC,MAAO,QAAO;AAEnB,SAAO,QAAQ,SAAS,MAAgB;;CAG1C,MAAM,cAAc,SAAqC;AAEvD,MAAI;GACF,MAAM,aAAa,SAAS,YAAY,KAAK;AAE7C,OAAI,eAAe,KAAM,QAAO;UAC1B;AAGR,MAAI;GACF,MAAM,eAAe,SAAS,UAAU;AAExC,OAAI,CAAC,aAAc;GAEnB,MAAM,QAAQ,aAAa,MAAM,IA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,mBAAmB,QAAQ,QAAQ;CAC1E"}
@@ -26,6 +26,13 @@ const createWebStorageEntry = (options) => {
26
26
  return { name: name ?? DefaultValues.Routing.LOCALE_STORAGE_NAME };
27
27
  };
28
28
  /**
29
+ * Creates a header entry with default name
30
+ */
31
+ const createHeaderEntry = (options) => {
32
+ const { name } = options ?? {};
33
+ return { name: name ?? DefaultValues.Routing.HEADER_NAME };
34
+ };
35
+ /**
29
36
  * Determines if a storage entry is a cookie based on its properties
30
37
  */
31
38
  const isCookieEntry = (entry) => {
@@ -35,7 +42,7 @@ const isCookieEntry = (entry) => {
35
42
  * Determines the storage type from a string literal
36
43
  */
37
44
  const isStorageType = (value) => {
38
- return value === "cookie" || value === "localStorage" || value === "sessionStorage";
45
+ return value === "cookie" || value === "localStorage" || value === "sessionStorage" || value === "header";
39
46
  };
40
47
  /**
41
48
  * Processes a single storage entry and returns the appropriate storage attributes
@@ -45,11 +52,13 @@ const processStorageEntry = (entry) => {
45
52
  if (!isStorageType(entry)) return {
46
53
  cookies: [],
47
54
  localStorage: [],
48
- sessionStorage: []
55
+ sessionStorage: [],
56
+ headers: []
49
57
  };
50
58
  if (entry === "cookie") return { cookies: [createCookieEntry()] };
51
59
  if (entry === "localStorage") return { localStorage: [createWebStorageEntry()] };
52
60
  if (entry === "sessionStorage") return { sessionStorage: [createWebStorageEntry()] };
61
+ if (entry === "header") return { headers: [createHeaderEntry()] };
53
62
  }
54
63
  if (typeof entry === "object" && entry !== null) {
55
64
  const typedEntry = entry;
@@ -68,6 +77,13 @@ const processStorageEntry = (entry) => {
68
77
  ...rest$1
69
78
  })] };
70
79
  }
80
+ if ("type" in typedEntry && typedEntry.type === "header") {
81
+ const { name: name$1,...rest$1 } = typedEntry;
82
+ return { headers: [createHeaderEntry({
83
+ name: name$1,
84
+ ...rest$1
85
+ })] };
86
+ }
71
87
  const { name,...rest } = typedEntry;
72
88
  return { localStorage: [createWebStorageEntry({
73
89
  name,
@@ -77,7 +93,8 @@ const processStorageEntry = (entry) => {
77
93
  return {
78
94
  cookies: [],
79
95
  localStorage: [],
80
- sessionStorage: []
96
+ sessionStorage: [],
97
+ headers: []
81
98
  };
82
99
  };
83
100
  /**
@@ -87,7 +104,8 @@ const mergeStorageAttributes = (accumulated, partial) => {
87
104
  return {
88
105
  cookies: [...accumulated.cookies, ...partial.cookies ?? []],
89
106
  localStorage: [...accumulated.localStorage, ...partial.localStorage ?? []],
90
- sessionStorage: [...accumulated.sessionStorage, ...partial.sessionStorage ?? []]
107
+ sessionStorage: [...accumulated.sessionStorage, ...partial.sessionStorage ?? []],
108
+ headers: [...accumulated.headers, ...partial.headers ?? []]
91
109
  };
92
110
  };
93
111
  /**
@@ -100,7 +118,8 @@ const getStorageAttributes = (options) => {
100
118
  const emptyResult = {
101
119
  cookies: [],
102
120
  localStorage: [],
103
- sessionStorage: []
121
+ sessionStorage: [],
122
+ headers: []
104
123
  };
105
124
  if (options === false || options === void 0) return emptyResult;
106
125
  if (Array.isArray(options)) return options.reduce((acc, entry) => {
@@ -1 +1 @@
1
- {"version":3,"file":"getStorageAttributes.mjs","names":["rest","emptyResult: StorageAttributes"],"sources":["../../src/getStorageAttributes.ts"],"sourcesContent":["import { DefaultValues } from '@intlayer/config/client';\nimport type {\n CookiesAttributes,\n IntlayerConfig,\n LocaleStorageAttributes,\n} from '@intlayer/types';\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\nexport type StorageAttributes = {\n cookies: CookieEntry[];\n localStorage: WebStorageEntry[];\n sessionStorage: WebStorageEntry[];\n};\n\ntype StorageEntry =\n | 'cookie'\n | 'localStorage'\n | 'sessionStorage'\n | CookiesAttributes\n | LocaleStorageAttributes;\n\n// ============================================================================\n// Helper Functions\n// ============================================================================\n\n/**\n * Creates a cookie entry with default values for missing attributes\n */\nconst createCookieEntry = (\n options?: Partial<CookiesAttributes>\n): CookieEntry => {\n const { name, path, expires, domain, secure, sameSite, httpOnly } =\n options ?? {};\n\n return {\n name: name ?? DefaultValues.Routing.COOKIE_NAME,\n attributes: {\n path,\n expires,\n domain,\n secure,\n sameSite,\n httpOnly,\n },\n };\n};\n\n/**\n * Creates a web storage entry (localStorage or sessionStorage) with default name\n */\nconst createWebStorageEntry = (\n options?: Partial<LocaleStorageAttributes>\n): WebStorageEntry => {\n const { name } = options ?? {};\n\n return {\n name: name ?? DefaultValues.Routing.LOCALE_STORAGE_NAME,\n };\n};\n\n/**\n * Determines if a storage entry is a cookie based on its properties\n */\nconst isCookieEntry = (entry: any): boolean => {\n return (\n entry.type === 'cookie' ||\n 'sameSite' in entry ||\n 'httpOnly' in entry ||\n 'secure' in entry\n );\n};\n\n/**\n * Determines the storage type from a string literal\n */\nconst isStorageType = (\n value: string\n): value is 'cookie' | 'localStorage' | 'sessionStorage' => {\n return (\n value === 'cookie' || value === 'localStorage' || value === 'sessionStorage'\n );\n};\n\n// ============================================================================\n// Main Function\n// ============================================================================\n\n/**\n * Processes a single storage entry and returns the appropriate storage attributes\n */\nconst processStorageEntry = (\n entry: StorageEntry\n): Partial<StorageAttributes> => {\n // Handle string literals\n if (typeof entry === 'string') {\n if (!isStorageType(entry)) {\n return { cookies: [], localStorage: [], sessionStorage: [] };\n }\n\n if (entry === 'cookie') {\n return { cookies: [createCookieEntry()] };\n }\n\n if (entry === 'localStorage') {\n return { localStorage: [createWebStorageEntry()] };\n }\n\n if (entry === 'sessionStorage') {\n return { sessionStorage: [createWebStorageEntry()] };\n }\n }\n\n // Handle object entries\n if (typeof entry === 'object' && entry !== null) {\n const typedEntry = entry as CookiesAttributes | LocaleStorageAttributes;\n\n if (isCookieEntry(typedEntry)) {\n return { cookies: [createCookieEntry(typedEntry as CookiesAttributes)] };\n }\n\n // Handle localStorage\n if ('type' in typedEntry && typedEntry.type === 'localStorage') {\n const { name, ...rest } = typedEntry as LocaleStorageAttributes;\n return { localStorage: [createWebStorageEntry({ name, ...rest })] };\n }\n\n // Handle sessionStorage\n if ('type' in typedEntry && typedEntry.type === 'sessionStorage') {\n const { name, ...rest } = typedEntry as LocaleStorageAttributes;\n return { sessionStorage: [createWebStorageEntry({ name, ...rest })] };\n }\n\n // Default to localStorage for ambiguous objects\n const { name, ...rest } = typedEntry as Omit<\n LocaleStorageAttributes,\n 'type'\n >;\n return { localStorage: [createWebStorageEntry({ name, ...rest })] };\n }\n\n return { cookies: [], localStorage: [], sessionStorage: [] };\n};\n\n/**\n * Merges multiple partial storage attributes into a single result\n */\nconst mergeStorageAttributes = (\n accumulated: StorageAttributes,\n partial: Partial<StorageAttributes>\n): StorageAttributes => {\n return {\n cookies: [...accumulated.cookies, ...(partial.cookies ?? [])],\n localStorage: [\n ...accumulated.localStorage,\n ...(partial.localStorage ?? []),\n ],\n sessionStorage: [\n ...accumulated.sessionStorage,\n ...(partial.sessionStorage ?? []),\n ],\n };\n};\n\n/**\n * Extracts and normalizes storage configuration into separate arrays for each storage type\n *\n * @param options - The storage configuration from IntlayerConfig\n * @returns An object containing arrays for cookies, localStorage, and sessionStorage\n */\nexport const getStorageAttributes = (\n options: IntlayerConfig['routing']['storage']\n): StorageAttributes => {\n const emptyResult: StorageAttributes = {\n cookies: [],\n localStorage: [],\n sessionStorage: [],\n };\n\n // Storage is disabled\n if (options === false || options === undefined) {\n return emptyResult;\n }\n\n // Handle array of storage entries\n if (Array.isArray(options)) {\n return options.reduce((acc, entry) => {\n const partial = processStorageEntry(entry);\n return mergeStorageAttributes(acc, partial);\n }, emptyResult);\n }\n\n // Handle single storage entry\n const partial = processStorageEntry(options);\n\n return mergeStorageAttributes(emptyResult, partial);\n};\n"],"mappings":";;;;;;AAwCA,MAAM,qBACJ,YACgB;CAChB,MAAM,EAAE,MAAM,MAAM,SAAS,QAAQ,QAAQ,UAAU,aACrD,WAAW,EAAE;AAEf,QAAO;EACL,MAAM,QAAQ,cAAc,QAAQ;EACpC,YAAY;GACV;GACA;GACA;GACA;GACA;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AC,sBAAsB;GAAE;GAAM,GAAG;GAAM,CAAC,CAAC,EAAE;;AAGrE,QAAO;EAAE,SAAS,EAAE;EAAE,cAAc,EAAE;EAAE,gBAAgB,EAAE;EAAE;;;;;AAM9D,MAAM,0BACJ,aACA,YACsB;AACtB,QAAO;EACL,SAAS,CAAC,GAAG,YAAY,SAAS,GAAI,QAAQ,WAAW,EAAE,CAAE;EAC7D,cAAc,CACZ,GAAG,YAAY,cACf,GAAI,QAAQ,gBAAgB,EAAE,CAC/B;EACD,gBAAgB,CACd,GAAG,YAAY,gBACf,GAAI,QAAQ,kBAAkB,EAAE,CACjC;EACF;;;;;;;;AASH,MAAa,wBACX,YACsB;CACtB,MAAMC,cAAiC;EACrC,SAAS,EAAE;EACX,cAAc,EAAE;EAChB,gBAAgB,EAAE;EACnB;AAGD,KAAI,YAAY,SAAS,YAAY,OACnC,QAAO;AAIT,KAAI,MAAM,QAAQ,QAAQ,CACxB,QAAO,QAAQ,QAAQ,KAAK,UAAU;AAEpC,SAAO,uBAAuB,KADd,oBAAoB,MAAM,CACC;IAC1C,YAAY;AAMjB,QAAO,uBAAuB,aAFd,oBAAoB,QAAQ,CAEO"}
1
+ {"version":3,"file":"getStorageAttributes.mjs","names":["rest","emptyResult: ProcessedStorageAttributes"],"sources":["../../src/getStorageAttributes.ts"],"sourcesContent":["import { DefaultValues } from '@intlayer/config/client';\nimport type {\n CookiesAttributes,\n IntlayerConfig,\n StorageAttributes,\n} from '@intlayer/types';\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\nexport type ProcessedStorageAttributes = {\n cookies: CookieEntry[];\n localStorage: WebStorageEntry[];\n sessionStorage: WebStorageEntry[];\n headers: HeaderEntry[];\n};\n\ntype StorageEntry =\n | 'cookie'\n | 'localStorage'\n | 'sessionStorage'\n | 'header'\n | CookiesAttributes\n | StorageAttributes;\n\n// ============================================================================\n// Helper Functions\n// ============================================================================\n\n/**\n * Creates a cookie entry with default values for missing attributes\n */\nconst createCookieEntry = (\n options?: Partial<CookiesAttributes>\n): CookieEntry => {\n const { name, path, expires, domain, secure, sameSite, httpOnly } =\n options ?? {};\n\n return {\n name: name ?? DefaultValues.Routing.COOKIE_NAME,\n attributes: {\n path,\n expires,\n domain,\n secure,\n sameSite,\n httpOnly,\n },\n };\n};\n\n/**\n * Creates a web storage entry (localStorage or sessionStorage) with default name\n */\nconst createWebStorageEntry = (\n options?: Partial<StorageAttributes>\n): WebStorageEntry => {\n const { name } = options ?? {};\n\n return {\n name: name ?? DefaultValues.Routing.LOCALE_STORAGE_NAME,\n };\n};\n\n/**\n * Creates a header entry with default name\n */\nconst createHeaderEntry = (\n options?: Partial<StorageAttributes>\n): HeaderEntry => {\n const { name } = options ?? {};\n\n return {\n name: name ?? DefaultValues.Routing.HEADER_NAME,\n };\n};\n\n/**\n * Determines if a storage entry is a cookie based on its properties\n */\nconst isCookieEntry = (entry: any): boolean => {\n return (\n entry.type === 'cookie' ||\n 'sameSite' in entry ||\n 'httpOnly' in entry ||\n 'secure' in entry\n );\n};\n\n/**\n * Determines the storage type from a string literal\n */\nconst isStorageType = (\n value: string\n): value is 'cookie' | 'localStorage' | 'sessionStorage' | 'header' => {\n return (\n value === 'cookie' ||\n value === 'localStorage' ||\n value === 'sessionStorage' ||\n value === 'header'\n );\n};\n\n// ============================================================================\n// Main Function\n// ============================================================================\n\n/**\n * Processes a single storage entry and returns the appropriate storage attributes\n */\nconst processStorageEntry = (\n entry: StorageEntry\n): Partial<ProcessedStorageAttributes> => {\n // Handle string literals\n if (typeof entry === 'string') {\n if (!isStorageType(entry)) {\n return { cookies: [], localStorage: [], sessionStorage: [], headers: [] };\n }\n\n if (entry === 'cookie') {\n return { cookies: [createCookieEntry()] };\n }\n\n if (entry === 'localStorage') {\n return { localStorage: [createWebStorageEntry()] };\n }\n\n if (entry === 'sessionStorage') {\n return { sessionStorage: [createWebStorageEntry()] };\n }\n\n if (entry === 'header') {\n return { headers: [createHeaderEntry()] };\n }\n }\n\n // Handle object entries\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\n // Handle localStorage\n if ('type' in typedEntry && typedEntry.type === 'localStorage') {\n const { name, ...rest } = typedEntry as StorageAttributes;\n return { localStorage: [createWebStorageEntry({ name, ...rest })] };\n }\n\n // Handle sessionStorage\n if ('type' in typedEntry && typedEntry.type === 'sessionStorage') {\n const { name, ...rest } = typedEntry as StorageAttributes;\n return { sessionStorage: [createWebStorageEntry({ name, ...rest })] };\n }\n\n // Handle header\n if ('type' in typedEntry && typedEntry.type === 'header') {\n const { name, ...rest } = typedEntry as StorageAttributes;\n return { headers: [createHeaderEntry({ name, ...rest })] };\n }\n\n // Default to localStorage for ambiguous objects\n const { name, ...rest } = typedEntry as Omit<StorageAttributes, 'type'>;\n return { localStorage: [createWebStorageEntry({ name, ...rest })] };\n }\n\n return { cookies: [], localStorage: [], sessionStorage: [], headers: [] };\n};\n\n/**\n * Merges multiple partial storage attributes into a single result\n */\nconst mergeStorageAttributes = (\n accumulated: ProcessedStorageAttributes,\n partial: Partial<ProcessedStorageAttributes>\n): ProcessedStorageAttributes => {\n return {\n cookies: [...accumulated.cookies, ...(partial.cookies ?? [])],\n localStorage: [\n ...accumulated.localStorage,\n ...(partial.localStorage ?? []),\n ],\n sessionStorage: [\n ...accumulated.sessionStorage,\n ...(partial.sessionStorage ?? []),\n ],\n headers: [...accumulated.headers, ...(partial.headers ?? [])],\n };\n};\n\n/**\n * Extracts and normalizes storage configuration into separate arrays for each storage type\n *\n * @param options - The storage configuration from IntlayerConfig\n * @returns An object containing arrays for cookies, localStorage, and sessionStorage\n */\nexport const getStorageAttributes = (\n options: IntlayerConfig['routing']['storage']\n): ProcessedStorageAttributes => {\n const emptyResult: ProcessedStorageAttributes = {\n cookies: [],\n localStorage: [],\n sessionStorage: [],\n headers: [],\n };\n\n // Storage is disabled\n if (options === false || options === undefined) {\n return emptyResult;\n }\n\n // Handle array of storage entries\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 // Handle single storage entry\n const partial = processStorageEntry(options);\n\n return mergeStorageAttributes(emptyResult, partial);\n};\n"],"mappings":";;;;;;AA8CA,MAAM,qBACJ,YACgB;CAChB,MAAM,EAAE,MAAM,MAAM,SAAS,QAAQ,QAAQ,UAAU,aACrD,WAAW,EAAE;AAEf,QAAO;EACL,MAAM,QAAQ,cAAc,QAAQ;EACpC,YAAY;GACV;GACA;GACA;GACA;GACA;GACA;GACD;EACF;;;;;AAMH,MAAM,yBACJ,YACoB;CACpB,MAAM,EAAE,SAAS,WAAW,EAAE;AAE9B,QAAO,EACL,MAAM,QAAQ,cAAc,QAAQ,qBACrC;;;;;AAMH,MAAM,qBACJ,YACgB;CAChB,MAAM,EAAE,SAAS,WAAW,EAAE;AAE9B,QAAO,EACL,MAAM,QAAQ,cAAc,QAAQ,aACrC;;;;;AAMH,MAAM,iBAAiB,UAAwB;AAC7C,QACE,MAAM,SAAS,YACf,cAAc,SACd,cAAc,SACd,YAAY;;;;;AAOhB,MAAM,iBACJ,UACqE;AACrE,QACE,UAAU,YACV,UAAU,kBACV,UAAU,oBACV,UAAU;;;;;AAWd,MAAM,uBACJ,UACwC;AAExC,KAAI,OAAO,UAAU,UAAU;AAC7B,MAAI,CAAC,cAAc,MAAM,CACvB,QAAO;GAAE,SAAS,EAAE;GAAE,cAAc,EAAE;GAAE,gBAAgB,EAAE;GAAE,SAAS,EAAE;GAAE;AAG3E,MAAI,UAAU,SACZ,QAAO,EAAE,SAAS,CAAC,mBAAmB,CAAC,EAAE;AAG3C,MAAI,UAA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gB,EAAE,CAC/B;EACD,gBAAgB,CACd,GAAG,YAAY,gBACf,GAAI,QAAQ,kBAAkB,EAAE,CACjC;EACD,SAAS,CAAC,GAAG,YAAY,SAAS,GAAI,QAAQ,WAAW,EAAE,CAAE;EAC9D;;;;;;;;AASH,MAAa,wBACX,YAC+B;CAC/B,MAAMC,cAA0C;EAC9C,SAAS,EAAE;EACX,cAAc,EAAE;EAChB,gBAAgB,EAAE;EAClB,SAAS,EAAE;EACZ;AAGD,KAAI,YAAY,SAAS,YAAY,OACnC,QAAO;AAIT,KAAI,MAAM,QAAQ,QAAQ,CACxB,QAAO,QAAQ,QAAoC,KAAK,UAAU;AAEhE,SAAO,uBAAuB,KADd,oBAAoB,MAAM,CACC;IAC1C,YAAY;AAMjB,QAAO,uBAAuB,aAFd,oBAAoB,QAAQ,CAEO"}
@@ -1,6 +1,7 @@
1
1
  import { checkIsURLAbsolute } from "../utils/checkIsURLAbsolute.mjs";
2
2
  import { getPathWithoutLocale } from "./getPathWithoutLocale.mjs";
3
3
  import configuration from "@intlayer/config/built";
4
+ import { DefaultValues } from "@intlayer/config";
4
5
 
5
6
  //#region src/localization/getMultilingualUrls.ts
6
7
  /**
@@ -43,7 +44,7 @@ const getMultilingualUrls = (url, locales = configuration?.internationalization?
43
44
  let pathname = parsedUrl.pathname;
44
45
  if (!pathname.startsWith("/")) pathname = `/${pathname}`;
45
46
  const baseUrl = isAbsoluteUrl ? `${parsedUrl.protocol}//${parsedUrl.host}` : "";
46
- const routingMode = mode ?? "prefix-no-default";
47
+ const routingMode = mode ?? DefaultValues.Routing.ROUTING_MODE;
47
48
  return (locales ?? []).reduce((acc, locale) => {
48
49
  const isDefaultLocale = locale?.toString() === defaultLocale?.toString();
49
50
  let localizedUrl;
@@ -1 +1 @@
1
- {"version":3,"file":"getMultilingualUrls.mjs","names":["localizedUrl: string"],"sources":["../../../src/localization/getMultilingualUrls.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { LocalesValues, StrictModeLocaleMap } from '@intlayer/types';\nimport { checkIsURLAbsolute } from '../utils/checkIsURLAbsolute';\nimport { getPathWithoutLocale } from './getPathWithoutLocale';\n\n/**\n * Generates multilingual URLs by prefixing the given URL with each supported locale\n * or adding search parameters based on the routing mode.\n * Handles both absolute and relative URLs appropriately.\n *\n * This function gets the locales, default locale, and routing mode from the configuration if not provided.\n *\n * Example:\n *\n * ```ts\n * // prefix-no-default mode\n * getMultilingualUrls('/dashboard', ['en', 'fr'], 'en', 'prefix-no-default')\n * // Returns { en: '/dashboard', fr: '/fr/dashboard' }\n *\n * // prefix-all mode\n * getMultilingualUrls('/dashboard', ['en', 'fr'], 'en', 'prefix-all')\n * // Returns { en: '/en/dashboard', fr: '/fr/dashboard' }\n *\n * // search-params mode\n * getMultilingualUrls('/dashboard', ['en', 'fr'], 'en', 'search-params')\n * // Returns { en: '/dashboard?locale=en', fr: '/dashboard?locale=fr' }\n *\n * // no-prefix mode\n * getMultilingualUrls('/dashboard', ['en', 'fr'], 'en', 'no-prefix')\n * // Returns { en: '/dashboard', fr: '/dashboard' }\n * ```\n *\n * @param url - The original URL string to be processed.\n * @param locales - Optional array of supported locales. Defaults to configured locales.\n * @param defaultLocale - The default locale. Defaults to configured default locale.\n * @param mode - URL routing mode for locale handling. Defaults to configured mode.\n * @returns An object mapping each locale to its corresponding multilingual URL.\n */\nexport const getMultilingualUrls = (\n url: string,\n locales: LocalesValues[] | undefined = configuration?.internationalization\n ?.locales,\n defaultLocale: LocalesValues | undefined = configuration?.internationalization\n ?.defaultLocale,\n mode:\n | 'prefix-no-default'\n | 'prefix-all'\n | 'no-prefix'\n | 'search-params'\n | undefined = configuration?.routing?.mode\n): StrictModeLocaleMap<string> => {\n // Remove any existing locale segment from the URL\n const urlWithoutLocale = getPathWithoutLocale(url, locales);\n\n // Determine if the original URL is absolute (includes protocol)\n const isAbsoluteUrl = checkIsURLAbsolute(urlWithoutLocale);\n\n // Initialize a URL object if the URL is absolute\n // For relative URLs, use a dummy base to leverage the URL API\n const parsedUrl = isAbsoluteUrl\n ? new URL(urlWithoutLocale)\n : new URL(urlWithoutLocale, 'http://example.com');\n\n // Extract the pathname from the parsed URL\n let pathname = parsedUrl.pathname;\n\n // Ensure the pathname starts with a '/'\n if (!pathname.startsWith('/')) {\n pathname = `/${pathname}`;\n }\n\n // Prepare the base URL (protocol + host) if it's absolute\n const baseUrl = isAbsoluteUrl\n ? `${parsedUrl.protocol}//${parsedUrl.host}`\n : '';\n\n // Default mode to 'prefix-no-default' if not provided\n const routingMode = mode ?? 'prefix-no-default';\n\n // Generate multilingual URLs by iterating over each locale\n const multilingualUrls = (locales ?? []).reduce<StrictModeLocaleMap<string>>(\n (acc, locale) => {\n // Determine if the current locale is the default locale\n const isDefaultLocale = locale?.toString() === defaultLocale?.toString();\n\n let localizedUrl: string;\n\n if (routingMode === 'search-params') {\n // Use search parameters for locale handling\n const searchParams = new URLSearchParams(parsedUrl.search);\n searchParams.set('locale', locale.toString());\n\n const queryString = searchParams.toString();\n const pathWithQuery = queryString\n ? `${pathname}?${queryString}`\n : pathname;\n\n localizedUrl = isAbsoluteUrl\n ? `${baseUrl}${pathWithQuery}${parsedUrl.hash}`\n : `${pathWithQuery}${parsedUrl.hash}`;\n } else if (routingMode === 'no-prefix') {\n // No locale prefixing\n localizedUrl = isAbsoluteUrl\n ? `${baseUrl}${pathname}${parsedUrl.search}${parsedUrl.hash}`\n : `${pathname}${parsedUrl.search}${parsedUrl.hash}`;\n } else {\n // Handle prefix-based modes (prefix-all or prefix-no-default)\n const shouldPrefix =\n routingMode === 'prefix-all' ||\n (routingMode === 'prefix-no-default' && !isDefaultLocale);\n\n // Construct the new pathname with or without the locale prefix\n let localizedPath = shouldPrefix ? `/${locale}${pathname}` : pathname;\n\n if (localizedPath.length > 1 && localizedPath.endsWith('/')) {\n localizedPath = localizedPath.slice(0, -1);\n }\n\n // Combine with the base URL if the original URL was absolute\n localizedUrl = isAbsoluteUrl\n ? `${baseUrl}${localizedPath}${parsedUrl.search}${parsedUrl.hash}`\n : `${localizedPath}${parsedUrl.search}${parsedUrl.hash}`;\n }\n\n // Assign the constructed URL to the corresponding locale key\n acc[locale as unknown as keyof typeof acc] = localizedUrl;\n\n return acc;\n },\n {} as StrictModeLocaleMap<string>\n );\n\n return multilingualUrls;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCA,MAAa,uBACX,KACA,UAAuC,eAAe,sBAClD,SACJ,gBAA2C,eAAe,sBACtD,eACJ,OAKgB,eAAe,SAAS,SACR;CAEhC,MAAM,mBAAmB,qBAAqB,KAAK,QAAQ;CAG3D,MAAM,gBAAgB,mBAAmB,iBAAiB;CAI1D,MAAM,YAAY,gBACd,IAAI,IAAI,iBAAiB,GACzB,IAAI,IAAI,kBAAkB,qBAAqB;CAGnD,IAAI,WAAW,UAAU;AAGzB,KAAI,CAAC,SAAS,WAAW,IAAI,CAC3B,YAAW,IAAI;CAIjB,MAAM,UAAU,gBACZ,GAAG,UAAU,SAAS,IAAI,UAAU,SACpC;CAGJ,MAAM,cAAc,QAAQ;AAuD5B,SApD0B,WAAW,EAAE,EAAE,QACtC,KAAK,WAAW;EAEf,MAAM,kBAAkB,QAAQ,UAAU,KAAK,eAAe,UAAU;EAExE,IAAIA;AAEJ,MAAI,gBAAgB,iBAAiB;GAEnC,MAAM,eAAe,IAAI,gBAAgB,UAAU,OAAO;AAC1D,gBAAa,IAAI,UAAU,OAAO,UAAU,CAAC;GAE7C,MAAM,cAAc,aAAa,UAAU;GAC3C,MAAM,gBAAgB,cAClB,GAAG,SAAS,GAAG,gBACf;AAEJ,kBAAe,gBACX,GAAG,UAAU,gBAAgB,UAAU,SACvC,GAAG,gBAAgB,UAAU;aACxB,gBAAgB,YAEzB,gBAAe,gBACX,GAAG,UAAU,WAAW,UAAU,SAAS,UAAU,SACrD,GAAG,WAAW,UAAU,SAAS,UAAU;OAC1C;GAOL,IAAI,gBAJF,gBAAgB,gBACf,gBAAgB,uBAAuB,CAAC,kBAGR,IAAI,SAAS,aAAa;AAE7D,OAAI,cAAc,SAAS,KAAK,cAAc,SAAS,IAAI,CACzD,iBAAgB,cAAc,MAAM,GAAG,GAAG;AAI5C,kBAAe,gBACX,GAAG,UAAU,gBAAgB,UAAU,SAAS,UAAU,SAC1D,GAAG,gBAAgB,UAAU,SAAS,UAAU;;AAItD,MAAI,UAAyC;AAE7C,SAAO;IAET,EAAE,CACH"}
1
+ {"version":3,"file":"getMultilingualUrls.mjs","names":["localizedUrl: string"],"sources":["../../../src/localization/getMultilingualUrls.ts"],"sourcesContent":["import { DefaultValues } from '@intlayer/config';\nimport configuration from '@intlayer/config/built';\nimport type { LocalesValues, StrictModeLocaleMap } from '@intlayer/types';\nimport { checkIsURLAbsolute } from '../utils/checkIsURLAbsolute';\nimport { getPathWithoutLocale } from './getPathWithoutLocale';\n\n/**\n * Generates multilingual URLs by prefixing the given URL with each supported locale\n * or adding search parameters based on the routing mode.\n * Handles both absolute and relative URLs appropriately.\n *\n * This function gets the locales, default locale, and routing mode from the configuration if not provided.\n *\n * Example:\n *\n * ```ts\n * // prefix-no-default mode\n * getMultilingualUrls('/dashboard', ['en', 'fr'], 'en', 'prefix-no-default')\n * // Returns { en: '/dashboard', fr: '/fr/dashboard' }\n *\n * // prefix-all mode\n * getMultilingualUrls('/dashboard', ['en', 'fr'], 'en', 'prefix-all')\n * // Returns { en: '/en/dashboard', fr: '/fr/dashboard' }\n *\n * // search-params mode\n * getMultilingualUrls('/dashboard', ['en', 'fr'], 'en', 'search-params')\n * // Returns { en: '/dashboard?locale=en', fr: '/dashboard?locale=fr' }\n *\n * // no-prefix mode\n * getMultilingualUrls('/dashboard', ['en', 'fr'], 'en', 'no-prefix')\n * // Returns { en: '/dashboard', fr: '/dashboard' }\n * ```\n *\n * @param url - The original URL string to be processed.\n * @param locales - Optional array of supported locales. Defaults to configured locales.\n * @param defaultLocale - The default locale. Defaults to configured default locale.\n * @param mode - URL routing mode for locale handling. Defaults to configured mode.\n * @returns An object mapping each locale to its corresponding multilingual URL.\n */\nexport const getMultilingualUrls = (\n url: string,\n locales: LocalesValues[] | undefined = configuration?.internationalization\n ?.locales,\n defaultLocale: LocalesValues | undefined = configuration?.internationalization\n ?.defaultLocale,\n mode:\n | 'prefix-no-default'\n | 'prefix-all'\n | 'no-prefix'\n | 'search-params'\n | undefined = configuration?.routing?.mode\n): StrictModeLocaleMap<string> => {\n // Remove any existing locale segment from the URL\n const urlWithoutLocale = getPathWithoutLocale(url, locales);\n\n // Determine if the original URL is absolute (includes protocol)\n const isAbsoluteUrl = checkIsURLAbsolute(urlWithoutLocale);\n\n // Initialize a URL object if the URL is absolute\n // For relative URLs, use a dummy base to leverage the URL API\n const parsedUrl = isAbsoluteUrl\n ? new URL(urlWithoutLocale)\n : new URL(urlWithoutLocale, 'http://example.com');\n\n // Extract the pathname from the parsed URL\n let pathname = parsedUrl.pathname;\n\n // Ensure the pathname starts with a '/'\n if (!pathname.startsWith('/')) {\n pathname = `/${pathname}`;\n }\n\n // Prepare the base URL (protocol + host) if it's absolute\n const baseUrl = isAbsoluteUrl\n ? `${parsedUrl.protocol}//${parsedUrl.host}`\n : '';\n\n // Default mode to 'prefix-no-default' if not provided\n const routingMode = mode ?? DefaultValues.Routing.ROUTING_MODE;\n\n // Generate multilingual URLs by iterating over each locale\n const multilingualUrls = (locales ?? []).reduce<StrictModeLocaleMap<string>>(\n (acc, locale) => {\n // Determine if the current locale is the default locale\n const isDefaultLocale = locale?.toString() === defaultLocale?.toString();\n\n let localizedUrl: string;\n\n if (routingMode === 'search-params') {\n // Use search parameters for locale handling\n const searchParams = new URLSearchParams(parsedUrl.search);\n searchParams.set('locale', locale.toString());\n\n const queryString = searchParams.toString();\n const pathWithQuery = queryString\n ? `${pathname}?${queryString}`\n : pathname;\n\n localizedUrl = isAbsoluteUrl\n ? `${baseUrl}${pathWithQuery}${parsedUrl.hash}`\n : `${pathWithQuery}${parsedUrl.hash}`;\n } else if (routingMode === 'no-prefix') {\n // No locale prefixing\n localizedUrl = isAbsoluteUrl\n ? `${baseUrl}${pathname}${parsedUrl.search}${parsedUrl.hash}`\n : `${pathname}${parsedUrl.search}${parsedUrl.hash}`;\n } else {\n // Handle prefix-based modes (prefix-all or prefix-no-default)\n const shouldPrefix =\n routingMode === 'prefix-all' ||\n (routingMode === 'prefix-no-default' && !isDefaultLocale);\n\n // Construct the new pathname with or without the locale prefix\n let localizedPath = shouldPrefix ? `/${locale}${pathname}` : pathname;\n\n if (localizedPath.length > 1 && localizedPath.endsWith('/')) {\n localizedPath = localizedPath.slice(0, -1);\n }\n\n // Combine with the base URL if the original URL was absolute\n localizedUrl = isAbsoluteUrl\n ? `${baseUrl}${localizedPath}${parsedUrl.search}${parsedUrl.hash}`\n : `${localizedPath}${parsedUrl.search}${parsedUrl.hash}`;\n }\n\n // Assign the constructed URL to the corresponding locale key\n acc[locale as unknown as keyof typeof acc] = localizedUrl;\n\n return acc;\n },\n {} as StrictModeLocaleMap<string>\n );\n\n return multilingualUrls;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuCA,MAAa,uBACX,KACA,UAAuC,eAAe,sBAClD,SACJ,gBAA2C,eAAe,sBACtD,eACJ,OAKgB,eAAe,SAAS,SACR;CAEhC,MAAM,mBAAmB,qBAAqB,KAAK,QAAQ;CAG3D,MAAM,gBAAgB,mBAAmB,iBAAiB;CAI1D,MAAM,YAAY,gBACd,IAAI,IAAI,iBAAiB,GACzB,IAAI,IAAI,kBAAkB,qBAAqB;CAGnD,IAAI,WAAW,UAAU;AAGzB,KAAI,CAAC,SAAS,WAAW,IAAI,CAC3B,YAAW,IAAI;CAIjB,MAAM,UAAU,gBACZ,GAAG,UAAU,SAAS,IAAI,UAAU,SACpC;CAGJ,MAAM,cAAc,QAAQ,cAAc,QAAQ;AAuDlD,SApD0B,WAAW,EAAE,EAAE,QACtC,KAAK,WAAW;EAEf,MAAM,kBAAkB,QAAQ,UAAU,KAAK,eAAe,UAAU;EAExE,IAAIA;AAEJ,MAAI,gBAAgB,iBAAiB;GAEnC,MAAM,eAAe,IAAI,gBAAgB,UAAU,OAAO;AAC1D,gBAAa,IAAI,UAAU,OAAO,UAAU,CAAC;GAE7C,MAAM,cAAc,aAAa,UAAU;GAC3C,MAAM,gBAAgB,cAClB,GAAG,SAAS,GAAG,gBACf;AAEJ,kBAAe,gBACX,GAAG,UAAU,gBAAgB,UAAU,SACvC,GAAG,gBAAgB,UAAU;aACxB,gBAAgB,YAEzB,gBAAe,gBACX,GAAG,UAAU,WAAW,UAAU,SAAS,UAAU,SACrD,GAAG,WAAW,UAAU,SAAS,UAAU;OAC1C;GAOL,IAAI,gBAJF,gBAAgB,gBACf,gBAAgB,uBAAuB,CAAC,kBAGR,IAAI,SAAS,aAAa;AAE7D,OAAI,cAAc,SAAS,KAAK,cAAc,SAAS,IAAI,CACzD,iBAAgB,cAAc,MAAM,GAAG,GAAG;AAI5C,kBAAe,gBACX,GAAG,UAAU,gBAAgB,UAAU,SAAS,UAAU,SAC1D,GAAG,gBAAgB,UAAU,SAAS,UAAU;;AAItD,MAAI,UAAyC;AAE7C,SAAO;IAET,EAAE,CACH"}
@@ -1,7 +1,7 @@
1
1
  import { NodeType, formatNodeType } from "@intlayer/types";
2
+ import { colorizePath, getAppLogger } from "@intlayer/config";
2
3
  import { existsSync, readFileSync, statSync } from "node:fs";
3
4
  import { dirname, isAbsolute, relative, resolve } from "node:path";
4
- import { colorizePath, getAppLogger } from "@intlayer/config";
5
5
 
6
6
  //#region src/transpiler/file/file.ts
7
7
  const fileContent = (path, callerDir, baseDir) => {
@@ -12,7 +12,7 @@ const buildCookieString = (name, value, attributes) => {
12
12
  return parts.join("; ");
13
13
  };
14
14
  /**
15
- * Retrieves the locale from various storage mechanisms (cookies, localStorage, sessionStorage).
15
+ * Retrieves the locale from various storage mechanisms (cookies, localStorage, sessionStorage, headers).
16
16
  * The function checks storage locations in order of priority as defined in the configuration.
17
17
  *
18
18
  * @returns The locale if found in any storage, or undefined if not found
@@ -70,9 +70,16 @@ const getLocaleFromStorage = (options) => {
70
70
  if (isValidLocale(value)) return value;
71
71
  } catch {}
72
72
  }
73
+ for (let i = 0; i < storageAttributes.headers.length; i++) {
74
+ const { name } = storageAttributes.headers[i];
75
+ try {
76
+ const value = options?.getHeader?.(name);
77
+ if (isValidLocale(value)) return value;
78
+ } catch {}
79
+ }
73
80
  };
74
81
  /**
75
- * Stores the locale in various storage mechanisms (cookies, localStorage, sessionStorage).
82
+ * Stores the locale in various storage mechanisms (cookies, localStorage, sessionStorage, headers).
76
83
  * The function writes to all configured storage locations according to their attributes.
77
84
  * Respects overwrite flags for localStorage and sessionStorage.
78
85
  *
@@ -115,15 +122,21 @@ const setLocaleInStorage = (locale, options) => {
115
122
  options?.setSessionStorage?.(name, locale);
116
123
  } catch {}
117
124
  }
125
+ if (options?.setHeader) for (let i = 0; i < storageAttributes.headers.length; i++) {
126
+ const { name } = storageAttributes.headers[i];
127
+ try {
128
+ options?.setHeader?.(name, locale);
129
+ } catch {}
130
+ }
118
131
  };
119
132
  /**
120
133
  * Utility object to get and set the locale in the storage by considering the configuration
121
134
  *
122
- * @property getLocale - Retrieves the locale from various storage mechanisms (cookies, localStorage, sessionStorage).
123
- * Retrieves the locale from various storage mechanisms (cookies, localStorage, sessionStorage).
135
+ * @property getLocale - Retrieves the locale from various storage mechanisms (cookies, localStorage, sessionStorage, headers).
136
+ * Retrieves the locale from various storage mechanisms (cookies, localStorage, sessionStorage, headers).
124
137
  * The function checks storage locations in order of priority as defined in the configuration.
125
138
  *
126
- * @property setLocale - Stores the locale in various storage mechanisms (cookies, localStorage, sessionStorage).
139
+ * @property setLocale - Stores the locale in various storage mechanisms (cookies, localStorage, sessionStorage, headers).
127
140
  * The function writes to all configured storage locations according to their attributes.
128
141
  * Respects overwrite flags for localStorage and sessionStorage.
129
142
  *