@intlayer/core 8.5.2 → 8.6.0
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.
- package/dist/cjs/formatters/compact.cjs +1 -1
- package/dist/cjs/formatters/compact.cjs.map +1 -1
- package/dist/cjs/formatters/currency.cjs +1 -1
- package/dist/cjs/formatters/currency.cjs.map +1 -1
- package/dist/cjs/formatters/date.cjs +1 -1
- package/dist/cjs/formatters/date.cjs.map +1 -1
- package/dist/cjs/formatters/index.cjs +1 -1
- package/dist/cjs/formatters/list.cjs +1 -1
- package/dist/cjs/formatters/list.cjs.map +1 -1
- package/dist/cjs/formatters/number.cjs +1 -1
- package/dist/cjs/formatters/number.cjs.map +1 -1
- package/dist/cjs/formatters/percentage.cjs +2 -2
- package/dist/cjs/formatters/percentage.cjs.map +1 -1
- package/dist/cjs/formatters/relativeTime.cjs +1 -1
- package/dist/cjs/formatters/relativeTime.cjs.map +1 -1
- package/dist/cjs/formatters/units.cjs +1 -1
- package/dist/cjs/formatters/units.cjs.map +1 -1
- package/dist/cjs/index.cjs +16 -9
- package/dist/cjs/interpreter/getContent/getContent.cjs +8 -8
- package/dist/cjs/interpreter/getContent/getContent.cjs.map +1 -1
- package/dist/cjs/interpreter/splitAndJoinInsertion.cjs +10 -35
- package/dist/cjs/interpreter/splitAndJoinInsertion.cjs.map +1 -1
- package/dist/cjs/localization/generateSitemap.cjs +111 -0
- package/dist/cjs/localization/generateSitemap.cjs.map +1 -0
- package/dist/cjs/localization/getBrowserLocale.cjs +1 -1
- package/dist/cjs/localization/getBrowserLocale.cjs.map +1 -1
- package/dist/cjs/localization/getLocale.cjs +2 -2
- package/dist/cjs/localization/getLocale.cjs.map +1 -1
- package/dist/cjs/localization/getLocalizedUrl.cjs +1 -1
- package/dist/cjs/localization/getPrefix.cjs +1 -1
- package/dist/cjs/localization/index.cjs +8 -7
- package/dist/cjs/localization/localeMapper.cjs +1 -1
- package/dist/cjs/transpiler/html/getHTMLCustomComponents.cjs +2 -3
- package/dist/cjs/transpiler/html/getHTMLCustomComponents.cjs.map +1 -1
- package/dist/cjs/utils/index.cjs +9 -3
- package/dist/cjs/utils/intl.cjs +88 -72
- package/dist/cjs/utils/intl.cjs.map +1 -1
- package/dist/cjs/utils/localeStorage.cjs +191 -64
- package/dist/cjs/utils/localeStorage.cjs.map +1 -1
- package/dist/esm/formatters/compact.mjs +2 -2
- package/dist/esm/formatters/compact.mjs.map +1 -1
- package/dist/esm/formatters/currency.mjs +2 -2
- package/dist/esm/formatters/currency.mjs.map +1 -1
- package/dist/esm/formatters/date.mjs +2 -2
- package/dist/esm/formatters/date.mjs.map +1 -1
- package/dist/esm/formatters/index.mjs +2 -2
- package/dist/esm/formatters/list.mjs +2 -2
- package/dist/esm/formatters/list.mjs.map +1 -1
- package/dist/esm/formatters/number.mjs +2 -2
- package/dist/esm/formatters/number.mjs.map +1 -1
- package/dist/esm/formatters/percentage.mjs +3 -3
- package/dist/esm/formatters/percentage.mjs.map +1 -1
- package/dist/esm/formatters/relativeTime.mjs +2 -2
- package/dist/esm/formatters/relativeTime.mjs.map +1 -1
- package/dist/esm/formatters/units.mjs +2 -2
- package/dist/esm/formatters/units.mjs.map +1 -1
- package/dist/esm/index.mjs +10 -10
- package/dist/esm/interpreter/getContent/getContent.mjs +8 -8
- package/dist/esm/interpreter/getContent/getContent.mjs.map +1 -1
- package/dist/esm/interpreter/splitAndJoinInsertion.mjs +10 -35
- package/dist/esm/interpreter/splitAndJoinInsertion.mjs.map +1 -1
- package/dist/esm/localization/generateSitemap.mjs +109 -0
- package/dist/esm/localization/generateSitemap.mjs.map +1 -0
- package/dist/esm/localization/getBrowserLocale.mjs +2 -2
- package/dist/esm/localization/getBrowserLocale.mjs.map +1 -1
- package/dist/esm/localization/getLocale.mjs +3 -3
- package/dist/esm/localization/getLocale.mjs.map +1 -1
- package/dist/esm/localization/getLocalizedUrl.mjs +1 -1
- package/dist/esm/localization/getPrefix.mjs +1 -1
- package/dist/esm/localization/index.mjs +7 -7
- package/dist/esm/localization/localeMapper.mjs +1 -1
- package/dist/esm/transpiler/html/getHTMLCustomComponents.mjs +2 -4
- package/dist/esm/transpiler/html/getHTMLCustomComponents.mjs.map +1 -1
- package/dist/esm/utils/index.mjs +4 -4
- package/dist/esm/utils/intl.mjs +87 -72
- package/dist/esm/utils/intl.mjs.map +1 -1
- package/dist/esm/utils/localeStorage.mjs +186 -65
- package/dist/esm/utils/localeStorage.mjs.map +1 -1
- package/dist/types/deepTransformPlugins/getFilterMissingTranslationsContent.d.ts +10 -10
- package/dist/types/deepTransformPlugins/getFilterMissingTranslationsContent.d.ts.map +1 -1
- package/dist/types/deepTransformPlugins/getFilterTranslationsOnlyContent.d.ts +10 -10
- package/dist/types/deepTransformPlugins/getFilterTranslationsOnlyContent.d.ts.map +1 -1
- package/dist/types/deepTransformPlugins/getFilteredLocalesContent.d.ts +10 -10
- package/dist/types/deepTransformPlugins/getFilteredLocalesContent.d.ts.map +1 -1
- package/dist/types/dictionaryManipulator/orderDictionaries.d.ts +2 -2
- package/dist/types/dictionaryManipulator/orderDictionaries.d.ts.map +1 -1
- package/dist/types/formatters/index.d.ts +2 -2
- package/dist/types/formatters/number.d.ts +4 -1
- package/dist/types/formatters/number.d.ts.map +1 -1
- package/dist/types/formatters/percentage.d.ts +4 -1
- package/dist/types/formatters/percentage.d.ts.map +1 -1
- package/dist/types/index.d.ts +4 -4
- package/dist/types/interpreter/getContent/getContent.d.ts.map +1 -1
- package/dist/types/interpreter/splitAndJoinInsertion.d.ts +0 -17
- package/dist/types/interpreter/splitAndJoinInsertion.d.ts.map +1 -1
- package/dist/types/localization/generateSitemap.d.ts +93 -0
- package/dist/types/localization/generateSitemap.d.ts.map +1 -0
- package/dist/types/localization/getBrowserLocale.d.ts +2 -2
- package/dist/types/localization/getBrowserLocale.d.ts.map +1 -1
- package/dist/types/localization/index.d.ts +2 -2
- package/dist/types/transpiler/html/getHTMLCustomComponents.d.ts.map +1 -1
- package/dist/types/utils/index.d.ts +3 -3
- package/dist/types/utils/intl.d.ts +15 -11
- package/dist/types/utils/intl.d.ts.map +1 -1
- package/dist/types/utils/localeStorage.d.ts +85 -68
- package/dist/types/utils/localeStorage.d.ts.map +1 -1
- package/package.json +8 -8
- package/dist/cjs/getStorageAttributes.cjs +0 -135
- package/dist/cjs/getStorageAttributes.cjs.map +0 -1
- package/dist/esm/getStorageAttributes.mjs +0 -133
- package/dist/esm/getStorageAttributes.mjs.map +0 -1
- package/dist/types/getStorageAttributes.d.ts +0 -29
- package/dist/types/getStorageAttributes.d.ts.map +0 -1
|
@@ -3,62 +3,14 @@ import { Locale } from "@intlayer/types/allLocales";
|
|
|
3
3
|
|
|
4
4
|
//#region src/utils/localeStorage.d.ts
|
|
5
5
|
type CookieBuildAttributes = {
|
|
6
|
-
/**
|
|
7
|
-
* Cookie domain to store the locale information
|
|
8
|
-
*
|
|
9
|
-
* Default: undefined
|
|
10
|
-
*
|
|
11
|
-
* Define the domain where the cookie is available. Defaults to
|
|
12
|
-
* the domain of the page where the cookie was created.
|
|
13
|
-
*/
|
|
14
6
|
domain?: string;
|
|
15
|
-
/**
|
|
16
|
-
* Cookie path to store the locale information
|
|
17
|
-
*
|
|
18
|
-
* Default: undefined
|
|
19
|
-
*
|
|
20
|
-
* Define the path where the cookie is available. Defaults to '/'
|
|
21
|
-
*/
|
|
22
7
|
path?: string;
|
|
23
|
-
/**
|
|
24
|
-
* Cookie secure to store the locale information
|
|
25
|
-
*
|
|
26
|
-
* Default: undefined
|
|
27
|
-
*
|
|
28
|
-
* A Boolean indicating if the cookie transmission requires a
|
|
29
|
-
* secure protocol (https). Defaults to false.
|
|
30
|
-
*/
|
|
31
8
|
secure?: boolean;
|
|
32
|
-
/**
|
|
33
|
-
* Cookie httpOnly to store the locale information
|
|
34
|
-
*
|
|
35
|
-
* Default: undefined
|
|
36
|
-
*
|
|
37
|
-
* The cookie httpOnly where the locale information is stored.
|
|
38
|
-
*/
|
|
39
9
|
httpOnly?: boolean;
|
|
40
|
-
/**
|
|
41
|
-
* Cookie sameSite to store the locale information
|
|
42
|
-
*
|
|
43
|
-
* Default: undefined
|
|
44
|
-
*
|
|
45
|
-
* Asserts that a cookie must not be sent with cross-origin requests,
|
|
46
|
-
* providing some protection against cross-site request forgery
|
|
47
|
-
* attacks (CSRF)
|
|
48
|
-
*/
|
|
49
|
-
sameSite?: 'strict' | 'lax' | 'none';
|
|
50
|
-
/**
|
|
51
|
-
* Cookie expires to store the locale information
|
|
52
|
-
*
|
|
53
|
-
* Default: undefined
|
|
54
|
-
*
|
|
55
|
-
* Define when the cookie will be removed. Value can be a Number
|
|
56
|
-
* which will be interpreted as days from time of creation or a
|
|
57
|
-
* Date instance. If omitted, the cookie becomes a session cookie.
|
|
58
|
-
*/
|
|
10
|
+
sameSite?: 'strict' | 'lax' | 'none'; /** Expiry as milliseconds since epoch (Date.getTime()) or number of days */
|
|
59
11
|
expires?: number | undefined;
|
|
60
12
|
};
|
|
61
|
-
type
|
|
13
|
+
type LocaleStorageClientOptions = {
|
|
62
14
|
overwrite?: boolean;
|
|
63
15
|
isCookieEnabled?: boolean;
|
|
64
16
|
setCookieStore?: (name: string, value: string, cookie: CookieBuildAttributes) => void;
|
|
@@ -68,41 +20,106 @@ type LocaleStorageOptions = {
|
|
|
68
20
|
getSessionStorage?: (name: string) => string | undefined | null;
|
|
69
21
|
setLocaleStorage?: (name: string, value: string) => void;
|
|
70
22
|
getLocaleStorage?: (name: string) => string | undefined | null;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Retrieves the locale from browser storage mechanisms
|
|
26
|
+
* (cookies, localStorage, sessionStorage).
|
|
27
|
+
* Does not read from headers — use `getLocaleFromStorageServer` for that.
|
|
28
|
+
*/
|
|
29
|
+
declare const getLocaleFromStorageClient: (options: LocaleStorageClientOptions) => Locale | undefined;
|
|
30
|
+
/**
|
|
31
|
+
* Stores the locale in browser storage mechanisms
|
|
32
|
+
* (cookies, localStorage, sessionStorage).
|
|
33
|
+
* Does not write to headers — use `setLocaleInStorageServer` for that.
|
|
34
|
+
*/
|
|
35
|
+
declare const setLocaleInStorageClient: (locale: LocalesValues, options?: LocaleStorageClientOptions) => void;
|
|
36
|
+
/**
|
|
37
|
+
* Client-side locale storage utility.
|
|
38
|
+
* Handles cookies (browser), localStorage and sessionStorage.
|
|
39
|
+
* Does not access headers.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```ts
|
|
43
|
+
* const storage = LocaleStorageClient(localeStorageOptions);
|
|
44
|
+
* const locale = storage.getLocale();
|
|
45
|
+
* storage.setLocale('fr');
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
declare const LocaleStorageClient: (options: LocaleStorageClientOptions) => {
|
|
49
|
+
getLocale: () => Locale;
|
|
50
|
+
setLocale: (locale: LocalesValues) => void;
|
|
51
|
+
};
|
|
52
|
+
type LocaleStorageServerOptions = {
|
|
53
|
+
overwrite?: boolean;
|
|
54
|
+
isCookieEnabled?: boolean;
|
|
55
|
+
setCookieStore?: (name: string, value: string, cookie: CookieBuildAttributes) => void;
|
|
56
|
+
setCookieString?: (name: string, cookie: string) => void;
|
|
57
|
+
getCookie?: (name: string) => string | undefined | null;
|
|
71
58
|
getHeader?: (name: string) => string | undefined | null;
|
|
72
59
|
setHeader?: (name: string, value: string) => void;
|
|
73
60
|
};
|
|
74
61
|
/**
|
|
75
|
-
* Retrieves the locale from
|
|
76
|
-
*
|
|
62
|
+
* Retrieves the locale from server-side storage mechanisms (cookies, headers).
|
|
63
|
+
* Does not access localStorage or sessionStorage.
|
|
64
|
+
* No browser cookie fallback — the caller must provide `getCookie`.
|
|
65
|
+
*/
|
|
66
|
+
declare const getLocaleFromStorageServer: (options: LocaleStorageServerOptions) => Locale | undefined;
|
|
67
|
+
/**
|
|
68
|
+
* Stores the locale in server-side storage mechanisms (cookies, headers).
|
|
69
|
+
* Does not write to localStorage or sessionStorage.
|
|
70
|
+
*/
|
|
71
|
+
declare const setLocaleInStorageServer: (locale: LocalesValues, options?: LocaleStorageServerOptions) => void;
|
|
72
|
+
/**
|
|
73
|
+
* Server-side locale storage utility.
|
|
74
|
+
* Handles cookies (via injected getter/setter) and headers.
|
|
75
|
+
* Does not access localStorage or sessionStorage.
|
|
77
76
|
*
|
|
78
|
-
* @
|
|
77
|
+
* @example
|
|
78
|
+
* ```ts
|
|
79
|
+
* const storage = LocaleStorageServer({
|
|
80
|
+
* getCookie: (name) => req.cookies[name],
|
|
81
|
+
* setCookieStore: (name, value, attrs) => res.cookie(name, value, attrs),
|
|
82
|
+
* getHeader: (name) => req.headers[name],
|
|
83
|
+
* setHeader: (name, value) => res.setHeader(name, value),
|
|
84
|
+
* });
|
|
85
|
+
* const locale = storage.getLocale();
|
|
86
|
+
* storage.setLocale('fr');
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
declare const LocaleStorageServer: (options: LocaleStorageServerOptions) => {
|
|
90
|
+
getLocale: () => Locale;
|
|
91
|
+
setLocale: (locale: LocalesValues) => void;
|
|
92
|
+
};
|
|
93
|
+
/**
|
|
94
|
+
* @deprecated Use {@link LocaleStorageClientOptions} or {@link LocaleStorageServerOptions} instead.
|
|
95
|
+
*/
|
|
96
|
+
type LocaleStorageOptions = LocaleStorageClientOptions & LocaleStorageServerOptions;
|
|
97
|
+
/**
|
|
98
|
+
* Retrieves the locale from all storage mechanisms
|
|
99
|
+
* (cookies, localStorage, sessionStorage, headers).
|
|
100
|
+
*
|
|
101
|
+
* @deprecated Use {@link getLocaleFromStorageClient} (browser) or
|
|
102
|
+
* {@link getLocaleFromStorageServer} (server) instead.
|
|
79
103
|
*/
|
|
80
104
|
declare const getLocaleFromStorage: (options: Pick<LocaleStorageOptions, "getCookie" | "getSessionStorage" | "getLocaleStorage" | "getHeader" | "isCookieEnabled">) => Locale | undefined;
|
|
81
105
|
/**
|
|
82
|
-
* Stores the locale in
|
|
83
|
-
*
|
|
84
|
-
* Respects overwrite flags for localStorage and sessionStorage.
|
|
106
|
+
* Stores the locale in all configured storage mechanisms
|
|
107
|
+
* (cookies, localStorage, sessionStorage, headers).
|
|
85
108
|
*
|
|
86
|
-
* @
|
|
109
|
+
* @deprecated Use {@link setLocaleInStorageClient} (browser) or
|
|
110
|
+
* {@link setLocaleInStorageServer} (server) instead.
|
|
87
111
|
*/
|
|
88
112
|
declare const setLocaleInStorage: (locale: LocalesValues, options?: LocaleStorageOptions) => void;
|
|
89
113
|
/**
|
|
90
|
-
* Utility object to get and set the locale in
|
|
91
|
-
*
|
|
92
|
-
* @property getLocale - Retrieves the locale from various storage mechanisms (cookies, localStorage, sessionStorage, headers).
|
|
93
|
-
* Retrieves the locale from various storage mechanisms (cookies, localStorage, sessionStorage, headers).
|
|
94
|
-
* The function checks storage locations in order of priority as defined in the configuration.
|
|
95
|
-
*
|
|
96
|
-
* @property setLocale - Stores the locale in various storage mechanisms (cookies, localStorage, sessionStorage, headers).
|
|
97
|
-
* The function writes to all configured storage locations according to their attributes.
|
|
98
|
-
* Respects overwrite flags for localStorage and sessionStorage.
|
|
114
|
+
* Utility object to get and set the locale in storage based on configuration.
|
|
99
115
|
*
|
|
100
|
-
* @
|
|
116
|
+
* @deprecated Use {@link LocaleStorageClient} (browser) or
|
|
117
|
+
* {@link LocaleStorageServer} (server) instead.
|
|
101
118
|
*/
|
|
102
119
|
declare const LocaleStorage: (options: LocaleStorageOptions) => {
|
|
103
120
|
getLocale: () => Locale;
|
|
104
121
|
setLocale: (locale: LocalesValues) => void;
|
|
105
122
|
};
|
|
106
123
|
//#endregion
|
|
107
|
-
export { LocaleStorage, LocaleStorageOptions, getLocaleFromStorage, setLocaleInStorage };
|
|
124
|
+
export { CookieBuildAttributes, LocaleStorage, LocaleStorageClient, LocaleStorageClientOptions, LocaleStorageOptions, LocaleStorageServer, LocaleStorageServerOptions, getLocaleFromStorage, getLocaleFromStorageClient, getLocaleFromStorageServer, setLocaleInStorage, setLocaleInStorageClient, setLocaleInStorageServer };
|
|
108
125
|
//# sourceMappingURL=localeStorage.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"localeStorage.d.ts","names":[],"sources":["../../../src/utils/localeStorage.ts"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"localeStorage.d.ts","names":[],"sources":["../../../src/utils/localeStorage.ts"],"mappings":";;;;KAUY,qBAAA;EACV,MAAA;EACA,IAAA;EACA,MAAA;EACA,QAAA;EACA,QAAA,8BAJA;EAMA,OAAA;AAAA;AAAA,KA6BU,0BAAA;EACV,SAAA;EACA,eAAA;EACA,cAAA,IACE,IAAA,UACA,KAAA,UACA,MAAA,EAAQ,qBAAA;EAEV,eAAA,IAAmB,IAAA,UAAc,MAAA;EACjC,SAAA,IAAa,IAAA;EACb,iBAAA,IAAqB,IAAA,UAAc,KAAA;EACnC,iBAAA,IAAqB,IAAA;EACrB,gBAAA,IAAoB,IAAA,UAAc,KAAA;EAClC,gBAAA,IAAoB,IAAA;AAAA;;;;;;cAQT,0BAAA,GACX,OAAA,EAAS,0BAAA,KACR,MAAA;;;;;;cAyCU,wBAAA,GACX,MAAA,EAAQ,aAAA,EACR,OAAA,GAAU,0BAAA;;;;;;;;;;;AA7CZ;;cAiHa,mBAAA,GAAuB,OAAA,EAAS,0BAAA;;sBAEvB,aAAA;AAAA;AAAA,KASV,0BAAA;EACV,SAAA;EACA,eAAA;EACA,cAAA,IACE,IAAA,UACA,KAAA,UACA,MAAA,EAAQ,qBAAA;EAEV,eAAA,IAAmB,IAAA,UAAc,MAAA;EACjC,SAAA,IAAa,IAAA;EACb,SAAA,IAAa,IAAA;EACb,SAAA,IAAa,IAAA,UAAc,KAAA;AAAA;;;;;AAtB7B;cA8Ba,0BAAA,GACX,OAAA,EAAS,0BAAA,KACR,MAAA;;;;;cA6BU,wBAAA,GACX,MAAA,EAAQ,aAAA,EACR,OAAA,GAAU,0BAAA;;;;;;;;;;;AApDZ;;;;;;;cA6Ga,mBAAA,GAAuB,OAAA,EAAS,0BAAA;;sBAEvB,aAAA;AAAA;;;;KAYV,oBAAA,GAAuB,0BAAA,GACjC,0BAAA;;;;;;;;cASW,oBAAA,GACX,OAAA,EAAS,IAAA,CACP,oBAAA,gGAOD,MAAA;AA3HH;;;;;;;AAAA,cAoLa,kBAAA,GACX,MAAA,EAAQ,aAAA,EACR,OAAA,GAAU,oBAAA;;AAvJZ;;;;;cA6Na,aAAA,GAAiB,OAAA,EAAS,oBAAA;;sBAEjB,aAAA;AAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intlayer/core",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.6.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Includes core Intlayer functions like translation, dictionary, and utility functions shared across multiple packages.",
|
|
6
6
|
"keywords": [
|
|
@@ -168,11 +168,11 @@
|
|
|
168
168
|
"typecheck": "tsc --noEmit --project tsconfig.types.json"
|
|
169
169
|
},
|
|
170
170
|
"dependencies": {
|
|
171
|
-
"@intlayer/api": "8.
|
|
172
|
-
"@intlayer/config": "8.
|
|
173
|
-
"@intlayer/dictionaries-entry": "8.
|
|
174
|
-
"@intlayer/types": "8.
|
|
175
|
-
"@intlayer/unmerged-dictionaries-entry": "8.
|
|
171
|
+
"@intlayer/api": "8.6.0",
|
|
172
|
+
"@intlayer/config": "8.6.0",
|
|
173
|
+
"@intlayer/dictionaries-entry": "8.6.0",
|
|
174
|
+
"@intlayer/types": "8.6.0",
|
|
175
|
+
"@intlayer/unmerged-dictionaries-entry": "8.6.0",
|
|
176
176
|
"defu": "6.1.4"
|
|
177
177
|
},
|
|
178
178
|
"devDependencies": {
|
|
@@ -181,9 +181,9 @@
|
|
|
181
181
|
"@utils/ts-config-types": "1.0.4",
|
|
182
182
|
"@utils/tsdown-config": "1.0.4",
|
|
183
183
|
"rimraf": "6.1.3",
|
|
184
|
-
"tsdown": "0.21.
|
|
184
|
+
"tsdown": "0.21.7",
|
|
185
185
|
"typescript": "6.0.2",
|
|
186
|
-
"vitest": "4.1.
|
|
186
|
+
"vitest": "4.1.2"
|
|
187
187
|
},
|
|
188
188
|
"engines": {
|
|
189
189
|
"node": ">=14.18"
|
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
|
|
3
|
-
let _intlayer_config_defaultValues = require("@intlayer/config/defaultValues");
|
|
4
|
-
|
|
5
|
-
//#region src/getStorageAttributes.ts
|
|
6
|
-
/**
|
|
7
|
-
* Creates a cookie entry with default values for missing attributes
|
|
8
|
-
*/
|
|
9
|
-
const createCookieEntry = (options) => {
|
|
10
|
-
const { name, path, expires, domain, secure, sameSite, httpOnly } = options ?? {};
|
|
11
|
-
return {
|
|
12
|
-
name: name ?? _intlayer_config_defaultValues.COOKIE_NAME,
|
|
13
|
-
attributes: {
|
|
14
|
-
path,
|
|
15
|
-
expires,
|
|
16
|
-
domain,
|
|
17
|
-
secure,
|
|
18
|
-
sameSite,
|
|
19
|
-
httpOnly
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
|
-
};
|
|
23
|
-
/**
|
|
24
|
-
* Creates a web storage entry (localStorage or sessionStorage) with default name
|
|
25
|
-
*/
|
|
26
|
-
const createWebStorageEntry = (options) => {
|
|
27
|
-
const { name } = options ?? {};
|
|
28
|
-
return { name: name ?? _intlayer_config_defaultValues.LOCALE_STORAGE_NAME };
|
|
29
|
-
};
|
|
30
|
-
/**
|
|
31
|
-
* Creates a header entry with default name
|
|
32
|
-
*/
|
|
33
|
-
const createHeaderEntry = (options) => {
|
|
34
|
-
const { name } = options ?? {};
|
|
35
|
-
return { name: name ?? _intlayer_config_defaultValues.HEADER_NAME };
|
|
36
|
-
};
|
|
37
|
-
/**
|
|
38
|
-
* Determines if a storage entry is a cookie based on its properties
|
|
39
|
-
*/
|
|
40
|
-
const isCookieEntry = (entry) => {
|
|
41
|
-
return entry.type === "cookie" || "sameSite" in entry || "httpOnly" in entry || "secure" in entry;
|
|
42
|
-
};
|
|
43
|
-
/**
|
|
44
|
-
* Determines the storage type from a string literal
|
|
45
|
-
*/
|
|
46
|
-
const isStorageType = (value) => {
|
|
47
|
-
return value === "cookie" || value === "localStorage" || value === "sessionStorage" || value === "header";
|
|
48
|
-
};
|
|
49
|
-
/**
|
|
50
|
-
* Processes a single storage entry and returns the appropriate storage attributes
|
|
51
|
-
*/
|
|
52
|
-
const processStorageEntry = (entry) => {
|
|
53
|
-
if (typeof entry === "string") {
|
|
54
|
-
if (!isStorageType(entry)) return {
|
|
55
|
-
cookies: [],
|
|
56
|
-
localStorage: [],
|
|
57
|
-
sessionStorage: [],
|
|
58
|
-
headers: []
|
|
59
|
-
};
|
|
60
|
-
if (entry === "cookie") return { cookies: [createCookieEntry()] };
|
|
61
|
-
if (entry === "localStorage") return { localStorage: [createWebStorageEntry()] };
|
|
62
|
-
if (entry === "sessionStorage") return { sessionStorage: [createWebStorageEntry()] };
|
|
63
|
-
if (entry === "header") return { headers: [createHeaderEntry()] };
|
|
64
|
-
}
|
|
65
|
-
if (typeof entry === "object" && entry !== null) {
|
|
66
|
-
const typedEntry = entry;
|
|
67
|
-
if (isCookieEntry(typedEntry)) return { cookies: [createCookieEntry(typedEntry)] };
|
|
68
|
-
if ("type" in typedEntry && typedEntry.type === "localStorage") {
|
|
69
|
-
const { name, ...rest } = typedEntry;
|
|
70
|
-
return { localStorage: [createWebStorageEntry({
|
|
71
|
-
name,
|
|
72
|
-
...rest
|
|
73
|
-
})] };
|
|
74
|
-
}
|
|
75
|
-
if ("type" in typedEntry && typedEntry.type === "sessionStorage") {
|
|
76
|
-
const { name, ...rest } = typedEntry;
|
|
77
|
-
return { sessionStorage: [createWebStorageEntry({
|
|
78
|
-
name,
|
|
79
|
-
...rest
|
|
80
|
-
})] };
|
|
81
|
-
}
|
|
82
|
-
if ("type" in typedEntry && typedEntry.type === "header") {
|
|
83
|
-
const { name, ...rest } = typedEntry;
|
|
84
|
-
return { headers: [createHeaderEntry({
|
|
85
|
-
name,
|
|
86
|
-
...rest
|
|
87
|
-
})] };
|
|
88
|
-
}
|
|
89
|
-
const { name, ...rest } = typedEntry;
|
|
90
|
-
return { localStorage: [createWebStorageEntry({
|
|
91
|
-
name,
|
|
92
|
-
...rest
|
|
93
|
-
})] };
|
|
94
|
-
}
|
|
95
|
-
return {
|
|
96
|
-
cookies: [],
|
|
97
|
-
localStorage: [],
|
|
98
|
-
sessionStorage: [],
|
|
99
|
-
headers: []
|
|
100
|
-
};
|
|
101
|
-
};
|
|
102
|
-
/**
|
|
103
|
-
* Merges multiple partial storage attributes into a single result
|
|
104
|
-
*/
|
|
105
|
-
const mergeStorageAttributes = (accumulated, partial) => {
|
|
106
|
-
return {
|
|
107
|
-
cookies: [...accumulated.cookies, ...partial.cookies ?? []],
|
|
108
|
-
localStorage: [...accumulated.localStorage, ...partial.localStorage ?? []],
|
|
109
|
-
sessionStorage: [...accumulated.sessionStorage, ...partial.sessionStorage ?? []],
|
|
110
|
-
headers: [...accumulated.headers, ...partial.headers ?? []]
|
|
111
|
-
};
|
|
112
|
-
};
|
|
113
|
-
/**
|
|
114
|
-
* Extracts and normalizes storage configuration into separate arrays for each storage type
|
|
115
|
-
*
|
|
116
|
-
* @param options - The storage configuration from IntlayerConfig
|
|
117
|
-
* @returns An object containing arrays for cookies, localStorage, and sessionStorage
|
|
118
|
-
*/
|
|
119
|
-
const getStorageAttributes = (options) => {
|
|
120
|
-
const emptyResult = {
|
|
121
|
-
cookies: [],
|
|
122
|
-
localStorage: [],
|
|
123
|
-
sessionStorage: [],
|
|
124
|
-
headers: []
|
|
125
|
-
};
|
|
126
|
-
if (options === false || options === void 0) return emptyResult;
|
|
127
|
-
if (Array.isArray(options)) return options.reduce((acc, entry) => {
|
|
128
|
-
return mergeStorageAttributes(acc, processStorageEntry(entry));
|
|
129
|
-
}, emptyResult);
|
|
130
|
-
return mergeStorageAttributes(emptyResult, processStorageEntry(options));
|
|
131
|
-
};
|
|
132
|
-
|
|
133
|
-
//#endregion
|
|
134
|
-
exports.getStorageAttributes = getStorageAttributes;
|
|
135
|
-
//# sourceMappingURL=getStorageAttributes.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getStorageAttributes.cjs","names":["COOKIE_NAME","LOCALE_STORAGE_NAME","HEADER_NAME"],"sources":["../../src/getStorageAttributes.ts"],"sourcesContent":["import {\n COOKIE_NAME,\n HEADER_NAME,\n LOCALE_STORAGE_NAME,\n} from '@intlayer/config/defaultValues';\nimport type {\n CookiesAttributes,\n IntlayerConfig,\n StorageAttributes,\n} from '@intlayer/types/config';\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 ?? 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 ?? 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 ?? 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":";;;;;;;;AAkDA,MAAM,qBACJ,YACgB;CAChB,MAAM,EAAE,MAAM,MAAM,SAAS,QAAQ,QAAQ,UAAU,aACrD,WAAW,EAAE;AAEf,QAAO;EACL,MAAM,QAAQA;EACd,YAAY;GACV;GACA;GACA;GACA;GACA;G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NAME, LOCALE_STORAGE_NAME } from "@intlayer/config/defaultValues";
|
|
2
|
-
|
|
3
|
-
//#region src/getStorageAttributes.ts
|
|
4
|
-
/**
|
|
5
|
-
* Creates a cookie entry with default values for missing attributes
|
|
6
|
-
*/
|
|
7
|
-
const createCookieEntry = (options) => {
|
|
8
|
-
const { name, path, expires, domain, secure, sameSite, httpOnly } = options ?? {};
|
|
9
|
-
return {
|
|
10
|
-
name: name ?? COOKIE_NAME,
|
|
11
|
-
attributes: {
|
|
12
|
-
path,
|
|
13
|
-
expires,
|
|
14
|
-
domain,
|
|
15
|
-
secure,
|
|
16
|
-
sameSite,
|
|
17
|
-
httpOnly
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
};
|
|
21
|
-
/**
|
|
22
|
-
* Creates a web storage entry (localStorage or sessionStorage) with default name
|
|
23
|
-
*/
|
|
24
|
-
const createWebStorageEntry = (options) => {
|
|
25
|
-
const { name } = options ?? {};
|
|
26
|
-
return { name: name ?? LOCALE_STORAGE_NAME };
|
|
27
|
-
};
|
|
28
|
-
/**
|
|
29
|
-
* Creates a header entry with default name
|
|
30
|
-
*/
|
|
31
|
-
const createHeaderEntry = (options) => {
|
|
32
|
-
const { name } = options ?? {};
|
|
33
|
-
return { name: name ?? HEADER_NAME };
|
|
34
|
-
};
|
|
35
|
-
/**
|
|
36
|
-
* Determines if a storage entry is a cookie based on its properties
|
|
37
|
-
*/
|
|
38
|
-
const isCookieEntry = (entry) => {
|
|
39
|
-
return entry.type === "cookie" || "sameSite" in entry || "httpOnly" in entry || "secure" in entry;
|
|
40
|
-
};
|
|
41
|
-
/**
|
|
42
|
-
* Determines the storage type from a string literal
|
|
43
|
-
*/
|
|
44
|
-
const isStorageType = (value) => {
|
|
45
|
-
return value === "cookie" || value === "localStorage" || value === "sessionStorage" || value === "header";
|
|
46
|
-
};
|
|
47
|
-
/**
|
|
48
|
-
* Processes a single storage entry and returns the appropriate storage attributes
|
|
49
|
-
*/
|
|
50
|
-
const processStorageEntry = (entry) => {
|
|
51
|
-
if (typeof entry === "string") {
|
|
52
|
-
if (!isStorageType(entry)) return {
|
|
53
|
-
cookies: [],
|
|
54
|
-
localStorage: [],
|
|
55
|
-
sessionStorage: [],
|
|
56
|
-
headers: []
|
|
57
|
-
};
|
|
58
|
-
if (entry === "cookie") return { cookies: [createCookieEntry()] };
|
|
59
|
-
if (entry === "localStorage") return { localStorage: [createWebStorageEntry()] };
|
|
60
|
-
if (entry === "sessionStorage") return { sessionStorage: [createWebStorageEntry()] };
|
|
61
|
-
if (entry === "header") return { headers: [createHeaderEntry()] };
|
|
62
|
-
}
|
|
63
|
-
if (typeof entry === "object" && entry !== null) {
|
|
64
|
-
const typedEntry = entry;
|
|
65
|
-
if (isCookieEntry(typedEntry)) return { cookies: [createCookieEntry(typedEntry)] };
|
|
66
|
-
if ("type" in typedEntry && typedEntry.type === "localStorage") {
|
|
67
|
-
const { name, ...rest } = typedEntry;
|
|
68
|
-
return { localStorage: [createWebStorageEntry({
|
|
69
|
-
name,
|
|
70
|
-
...rest
|
|
71
|
-
})] };
|
|
72
|
-
}
|
|
73
|
-
if ("type" in typedEntry && typedEntry.type === "sessionStorage") {
|
|
74
|
-
const { name, ...rest } = typedEntry;
|
|
75
|
-
return { sessionStorage: [createWebStorageEntry({
|
|
76
|
-
name,
|
|
77
|
-
...rest
|
|
78
|
-
})] };
|
|
79
|
-
}
|
|
80
|
-
if ("type" in typedEntry && typedEntry.type === "header") {
|
|
81
|
-
const { name, ...rest } = typedEntry;
|
|
82
|
-
return { headers: [createHeaderEntry({
|
|
83
|
-
name,
|
|
84
|
-
...rest
|
|
85
|
-
})] };
|
|
86
|
-
}
|
|
87
|
-
const { name, ...rest } = typedEntry;
|
|
88
|
-
return { localStorage: [createWebStorageEntry({
|
|
89
|
-
name,
|
|
90
|
-
...rest
|
|
91
|
-
})] };
|
|
92
|
-
}
|
|
93
|
-
return {
|
|
94
|
-
cookies: [],
|
|
95
|
-
localStorage: [],
|
|
96
|
-
sessionStorage: [],
|
|
97
|
-
headers: []
|
|
98
|
-
};
|
|
99
|
-
};
|
|
100
|
-
/**
|
|
101
|
-
* Merges multiple partial storage attributes into a single result
|
|
102
|
-
*/
|
|
103
|
-
const mergeStorageAttributes = (accumulated, partial) => {
|
|
104
|
-
return {
|
|
105
|
-
cookies: [...accumulated.cookies, ...partial.cookies ?? []],
|
|
106
|
-
localStorage: [...accumulated.localStorage, ...partial.localStorage ?? []],
|
|
107
|
-
sessionStorage: [...accumulated.sessionStorage, ...partial.sessionStorage ?? []],
|
|
108
|
-
headers: [...accumulated.headers, ...partial.headers ?? []]
|
|
109
|
-
};
|
|
110
|
-
};
|
|
111
|
-
/**
|
|
112
|
-
* Extracts and normalizes storage configuration into separate arrays for each storage type
|
|
113
|
-
*
|
|
114
|
-
* @param options - The storage configuration from IntlayerConfig
|
|
115
|
-
* @returns An object containing arrays for cookies, localStorage, and sessionStorage
|
|
116
|
-
*/
|
|
117
|
-
const getStorageAttributes = (options) => {
|
|
118
|
-
const emptyResult = {
|
|
119
|
-
cookies: [],
|
|
120
|
-
localStorage: [],
|
|
121
|
-
sessionStorage: [],
|
|
122
|
-
headers: []
|
|
123
|
-
};
|
|
124
|
-
if (options === false || options === void 0) return emptyResult;
|
|
125
|
-
if (Array.isArray(options)) return options.reduce((acc, entry) => {
|
|
126
|
-
return mergeStorageAttributes(acc, processStorageEntry(entry));
|
|
127
|
-
}, emptyResult);
|
|
128
|
-
return mergeStorageAttributes(emptyResult, processStorageEntry(options));
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
//#endregion
|
|
132
|
-
export { getStorageAttributes };
|
|
133
|
-
//# sourceMappingURL=getStorageAttributes.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getStorageAttributes.mjs","names":[],"sources":["../../src/getStorageAttributes.ts"],"sourcesContent":["import {\n COOKIE_NAME,\n HEADER_NAME,\n LOCALE_STORAGE_NAME,\n} from '@intlayer/config/defaultValues';\nimport type {\n CookiesAttributes,\n IntlayerConfig,\n StorageAttributes,\n} from '@intlayer/types/config';\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 ?? 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 ?? 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 ?? 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":";;;;;;AAkDA,MAAM,qBACJ,YACgB;CAChB,MAAM,EAAE,MAAM,MAAM,SAAS,QAAQ,QAAQ,UAAU,aACrD,WAAW,EAAE;AAEf,QAAO;EACL,MAAM,QAAQ;EACd,YAAY;GACV;GACA;GACA;GACA;GACA;GACA;GACD;EACF;;;;;AAMH,MAAM,yBACJ,YACoB;CACpB,MAAM,EAAE,SAAS,WAAW,EAAE;AAE9B,QAAO,EACL,MAAM,QAAQ,qBACf;;;;;AAMH,MAAM,qBACJ,YACgB;CAChB,MAAM,EAAE,SAAS,WAAW,EAAE;AAE9B,QAAO,EACL,MAAM,QAAQ,aACf;;;;;AAMH,MAAM,iBAAiB,UAAwB;AAC7C,QACE,MAAM,SAAS,YACf,cAAc,SACd,cAAc,SACd,YAAY;;;;;AAOhB,MAAM,iBACJ,UACqE;AACrE,QACE,UAAU,YACV,UAAU,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AM,CAAC,CAAC,EAAE;;AAGrE,QAAO;EAAE,SAAS,EAAE;EAAE,cAAc,EAAE;EAAE,gBAAgB,EAAE;EAAE,SAAS,EAAE;EAAE;;;;;AAM3E,MAAM,0BACJ,aACA,YAC+B;AAC/B,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;EACD,SAAS,CAAC,GAAG,YAAY,SAAS,GAAI,QAAQ,WAAW,EAAE,CAAE;EAC9D;;;;;;;;AASH,MAAa,wBACX,YAC+B;CAC/B,MAAM,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,29 +0,0 @@
|
|
|
1
|
-
import { CookiesAttributes, IntlayerConfig } from "@intlayer/types/config";
|
|
2
|
-
|
|
3
|
-
//#region src/getStorageAttributes.d.ts
|
|
4
|
-
type CookieEntry = {
|
|
5
|
-
name: string;
|
|
6
|
-
attributes: Omit<CookiesAttributes, 'type' | 'name'>;
|
|
7
|
-
};
|
|
8
|
-
type WebStorageEntry = {
|
|
9
|
-
name: string;
|
|
10
|
-
};
|
|
11
|
-
type HeaderEntry = {
|
|
12
|
-
name: string;
|
|
13
|
-
};
|
|
14
|
-
type ProcessedStorageAttributes = {
|
|
15
|
-
cookies: CookieEntry[];
|
|
16
|
-
localStorage: WebStorageEntry[];
|
|
17
|
-
sessionStorage: WebStorageEntry[];
|
|
18
|
-
headers: HeaderEntry[];
|
|
19
|
-
};
|
|
20
|
-
/**
|
|
21
|
-
* Extracts and normalizes storage configuration into separate arrays for each storage type
|
|
22
|
-
*
|
|
23
|
-
* @param options - The storage configuration from IntlayerConfig
|
|
24
|
-
* @returns An object containing arrays for cookies, localStorage, and sessionStorage
|
|
25
|
-
*/
|
|
26
|
-
declare const getStorageAttributes: (options: IntlayerConfig["routing"]["storage"]) => ProcessedStorageAttributes;
|
|
27
|
-
//#endregion
|
|
28
|
-
export { ProcessedStorageAttributes, getStorageAttributes };
|
|
29
|
-
//# sourceMappingURL=getStorageAttributes.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getStorageAttributes.d.ts","names":[],"sources":["../../src/getStorageAttributes.ts"],"mappings":";;;KAeK,WAAA;EACH,IAAA;EACA,UAAA,EAAY,IAAA,CAAK,iBAAA;AAAA;AAAA,KAGd,eAAA;EACH,IAAA;AAAA;AAAA,KAGG,WAAA;EACH,IAAA;AAAA;AAAA,KAGU,0BAAA;EACV,OAAA,EAAS,WAAA;EACT,YAAA,EAAc,eAAA;EACd,cAAA,EAAgB,eAAA;EAChB,OAAA,EAAS,WAAA;AAAA;;AAXL;;;;;cAkMO,oBAAA,GACX,OAAA,EAAS,cAAA,2BACR,0BAAA"}
|