@c-rex/utils 0.0.7 → 0.1.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/index.d.mts +16 -8
- package/dist/index.d.ts +16 -8
- package/dist/index.js +127 -18
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +121 -17
- package/dist/index.mjs.map +1 -1
- package/dist/next-cookies.d.mts +7 -0
- package/dist/next-cookies.d.ts +7 -0
- package/dist/next-cookies.js +55 -0
- package/dist/next-cookies.js.map +1 -0
- package/dist/next-cookies.mjs +27 -0
- package/dist/next-cookies.mjs.map +1 -0
- package/package.json +21 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,16 +1,24 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { TreeOfContent } from '@c-rex/interfaces';
|
|
1
|
+
import { TreeOfContent, DirectoryNodes } from '@c-rex/interfaces';
|
|
3
2
|
import { ClassValue } from 'clsx';
|
|
3
|
+
import { QueryParams } from '@c-rex/types';
|
|
4
|
+
|
|
5
|
+
declare const call: <T = unknown>(method: string, params?: any) => Promise<T>;
|
|
6
|
+
declare const getCountryCodeByLang: (lang: string) => string;
|
|
7
|
+
|
|
8
|
+
declare function isBrowser(): boolean;
|
|
9
|
+
declare function saveInMemory(value: any, key: string): void;
|
|
10
|
+
declare function getFromMemory(key: string): any;
|
|
11
|
+
|
|
12
|
+
declare const generateBreadcrumbItems: (treeOfContent: TreeOfContent[]) => TreeOfContent[];
|
|
13
|
+
|
|
14
|
+
declare function cn(...inputs: ClassValue[]): string;
|
|
15
|
+
|
|
16
|
+
declare const generateTreeOfContent: (directoryNodes: DirectoryNodes[]) => Promise<TreeOfContent[]>;
|
|
4
17
|
|
|
5
18
|
declare const createParams: (fieldsList: string[], key?: string) => {
|
|
6
19
|
key: string;
|
|
7
20
|
value: string;
|
|
8
21
|
}[];
|
|
9
|
-
declare const updateUrlWithParams: (router: any, params: QueryParams[]) => void;
|
|
10
22
|
declare const generateQueryParams: (params: QueryParams[]) => string;
|
|
11
23
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
declare function cn(...inputs: ClassValue[]): string;
|
|
15
|
-
|
|
16
|
-
export { cn, createParams, generateBreadcrumbItems, generateQueryParams, updateUrlWithParams };
|
|
24
|
+
export { call, cn, createParams, generateBreadcrumbItems, generateQueryParams, generateTreeOfContent, getCountryCodeByLang, getFromMemory, isBrowser, saveInMemory };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,16 +1,24 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { TreeOfContent } from '@c-rex/interfaces';
|
|
1
|
+
import { TreeOfContent, DirectoryNodes } from '@c-rex/interfaces';
|
|
3
2
|
import { ClassValue } from 'clsx';
|
|
3
|
+
import { QueryParams } from '@c-rex/types';
|
|
4
|
+
|
|
5
|
+
declare const call: <T = unknown>(method: string, params?: any) => Promise<T>;
|
|
6
|
+
declare const getCountryCodeByLang: (lang: string) => string;
|
|
7
|
+
|
|
8
|
+
declare function isBrowser(): boolean;
|
|
9
|
+
declare function saveInMemory(value: any, key: string): void;
|
|
10
|
+
declare function getFromMemory(key: string): any;
|
|
11
|
+
|
|
12
|
+
declare const generateBreadcrumbItems: (treeOfContent: TreeOfContent[]) => TreeOfContent[];
|
|
13
|
+
|
|
14
|
+
declare function cn(...inputs: ClassValue[]): string;
|
|
15
|
+
|
|
16
|
+
declare const generateTreeOfContent: (directoryNodes: DirectoryNodes[]) => Promise<TreeOfContent[]>;
|
|
4
17
|
|
|
5
18
|
declare const createParams: (fieldsList: string[], key?: string) => {
|
|
6
19
|
key: string;
|
|
7
20
|
value: string;
|
|
8
21
|
}[];
|
|
9
|
-
declare const updateUrlWithParams: (router: any, params: QueryParams[]) => void;
|
|
10
22
|
declare const generateQueryParams: (params: QueryParams[]) => string;
|
|
11
23
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
declare function cn(...inputs: ClassValue[]): string;
|
|
15
|
-
|
|
16
|
-
export { cn, createParams, generateBreadcrumbItems, generateQueryParams, updateUrlWithParams };
|
|
24
|
+
export { call, cn, createParams, generateBreadcrumbItems, generateQueryParams, generateTreeOfContent, getCountryCodeByLang, getFromMemory, isBrowser, saveInMemory };
|
package/dist/index.js
CHANGED
|
@@ -20,34 +20,69 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/index.ts
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
|
+
call: () => call,
|
|
23
24
|
cn: () => cn,
|
|
24
25
|
createParams: () => createParams,
|
|
25
26
|
generateBreadcrumbItems: () => generateBreadcrumbItems,
|
|
26
27
|
generateQueryParams: () => generateQueryParams,
|
|
27
|
-
|
|
28
|
+
generateTreeOfContent: () => generateTreeOfContent,
|
|
29
|
+
getCountryCodeByLang: () => getCountryCodeByLang,
|
|
30
|
+
getFromMemory: () => getFromMemory,
|
|
31
|
+
isBrowser: () => isBrowser,
|
|
32
|
+
saveInMemory: () => saveInMemory
|
|
28
33
|
});
|
|
29
34
|
module.exports = __toCommonJS(index_exports);
|
|
30
35
|
|
|
36
|
+
// ../constants/src/index.ts
|
|
37
|
+
var FLAGS_BY_LANG = {
|
|
38
|
+
"en": "US",
|
|
39
|
+
"de": "DE"
|
|
40
|
+
};
|
|
41
|
+
|
|
31
42
|
// src/utils.ts
|
|
32
|
-
var
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
+
var call = async (method, params) => {
|
|
44
|
+
try {
|
|
45
|
+
const res = await fetch(`/api/rpc`, {
|
|
46
|
+
method: "POST",
|
|
47
|
+
headers: { "Content-Type": "application/json" },
|
|
48
|
+
body: JSON.stringify({ method, params })
|
|
49
|
+
});
|
|
50
|
+
const json = await res.json();
|
|
51
|
+
if (!res.ok) throw new Error(json.error || "Unknown error");
|
|
52
|
+
return json.data;
|
|
53
|
+
} catch (error) {
|
|
54
|
+
console.error(error);
|
|
55
|
+
return null;
|
|
56
|
+
}
|
|
43
57
|
};
|
|
44
|
-
var
|
|
45
|
-
const
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
58
|
+
var getCountryCodeByLang = (lang) => {
|
|
59
|
+
const mappedKeys = Object.keys(FLAGS_BY_LANG);
|
|
60
|
+
if (!mappedKeys.includes(lang)) {
|
|
61
|
+
return lang;
|
|
62
|
+
}
|
|
63
|
+
const country = FLAGS_BY_LANG[lang];
|
|
64
|
+
return country;
|
|
49
65
|
};
|
|
50
66
|
|
|
67
|
+
// src/memory.ts
|
|
68
|
+
function isBrowser() {
|
|
69
|
+
return typeof window !== "undefined" && typeof document !== "undefined";
|
|
70
|
+
}
|
|
71
|
+
function saveInMemory(value, key) {
|
|
72
|
+
if (isBrowser()) throw new Error("saveInMemory is not supported in browser");
|
|
73
|
+
if (typeof global !== "undefined" && !(key in global)) {
|
|
74
|
+
global[key] = null;
|
|
75
|
+
}
|
|
76
|
+
const globalConfig = global[key];
|
|
77
|
+
if (globalConfig === null) {
|
|
78
|
+
global[key] = value;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
function getFromMemory(key) {
|
|
82
|
+
if (isBrowser()) throw new Error("getFromMemory is not supported in browser");
|
|
83
|
+
return global[key];
|
|
84
|
+
}
|
|
85
|
+
|
|
51
86
|
// src/breadcrumbs.ts
|
|
52
87
|
var generateBreadcrumbItems = (treeOfContent) => {
|
|
53
88
|
const result = [];
|
|
@@ -66,12 +101,86 @@ var import_tailwind_merge = require("tailwind-merge");
|
|
|
66
101
|
function cn(...inputs) {
|
|
67
102
|
return (0, import_tailwind_merge.twMerge)((0, import_clsx.clsx)(inputs));
|
|
68
103
|
}
|
|
104
|
+
|
|
105
|
+
// src/treeOfContent.ts
|
|
106
|
+
var import_services = require("@c-rex/services");
|
|
107
|
+
var generateTreeOfContent = async (directoryNodes) => {
|
|
108
|
+
const service = new import_services.DirectoryNodesService();
|
|
109
|
+
if (directoryNodes.length == 0) return [];
|
|
110
|
+
if (directoryNodes[0] == void 0) return [];
|
|
111
|
+
let id = directoryNodes[0].shortId;
|
|
112
|
+
let response = await service.getItem(id);
|
|
113
|
+
const childList = await getChildrenInfo(response.childNodes);
|
|
114
|
+
let result = childList;
|
|
115
|
+
while (response.parents != void 0) {
|
|
116
|
+
if (response.informationUnits[0] == void 0) return result;
|
|
117
|
+
if (response.labels[0] == void 0) return result;
|
|
118
|
+
if (response.parents[0] == void 0) return result;
|
|
119
|
+
const infoId = response.informationUnits[0].shortId;
|
|
120
|
+
const aux = {
|
|
121
|
+
active: true,
|
|
122
|
+
label: response.labels[0].value,
|
|
123
|
+
id: response.shortId,
|
|
124
|
+
link: `/info/${infoId}`,
|
|
125
|
+
children: [...result]
|
|
126
|
+
};
|
|
127
|
+
id = response.parents[0].shortId;
|
|
128
|
+
response = await service.getItem(id);
|
|
129
|
+
const tree = await getChildrenInfo(response.childNodes, aux);
|
|
130
|
+
result = [...tree];
|
|
131
|
+
}
|
|
132
|
+
return result;
|
|
133
|
+
};
|
|
134
|
+
var getChildrenInfo = async (childNodes, childItem) => {
|
|
135
|
+
const result = [];
|
|
136
|
+
if (childNodes == void 0) return result;
|
|
137
|
+
for (const item of childNodes) {
|
|
138
|
+
if (item.labels[0] == void 0) break;
|
|
139
|
+
const infoId = await getLink(item.shortId);
|
|
140
|
+
let resultItem = {
|
|
141
|
+
active: false,
|
|
142
|
+
label: item.labels[0].value,
|
|
143
|
+
link: `/info/${infoId}`,
|
|
144
|
+
id: item.shortId,
|
|
145
|
+
children: []
|
|
146
|
+
};
|
|
147
|
+
if (childItem?.id == item.shortId) {
|
|
148
|
+
resultItem = childItem;
|
|
149
|
+
}
|
|
150
|
+
result.push(resultItem);
|
|
151
|
+
}
|
|
152
|
+
return result;
|
|
153
|
+
};
|
|
154
|
+
var getLink = async (id) => {
|
|
155
|
+
const service = new import_services.DirectoryNodesService();
|
|
156
|
+
const response = await service.getItem(id);
|
|
157
|
+
if (response.informationUnits == void 0) return "";
|
|
158
|
+
if (response.informationUnits[0] == void 0) return "";
|
|
159
|
+
return response.informationUnits[0].shortId;
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
// src/params.ts
|
|
163
|
+
var createParams = (fieldsList, key = "Fields") => fieldsList.map((item) => ({
|
|
164
|
+
key,
|
|
165
|
+
value: item
|
|
166
|
+
}));
|
|
167
|
+
var generateQueryParams = (params) => {
|
|
168
|
+
const queryParams = params.map(
|
|
169
|
+
(param) => `${encodeURIComponent(param.key)}=${encodeURIComponent(param.value)}`
|
|
170
|
+
).join("&");
|
|
171
|
+
return queryParams;
|
|
172
|
+
};
|
|
69
173
|
// Annotate the CommonJS export names for ESM import in node:
|
|
70
174
|
0 && (module.exports = {
|
|
175
|
+
call,
|
|
71
176
|
cn,
|
|
72
177
|
createParams,
|
|
73
178
|
generateBreadcrumbItems,
|
|
74
179
|
generateQueryParams,
|
|
75
|
-
|
|
180
|
+
generateTreeOfContent,
|
|
181
|
+
getCountryCodeByLang,
|
|
182
|
+
getFromMemory,
|
|
183
|
+
isBrowser,
|
|
184
|
+
saveInMemory
|
|
76
185
|
});
|
|
77
186
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/utils.ts","../src/breadcrumbs.ts","../src/classMerge.ts"],"sourcesContent":["export * from './utils';\
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../../constants/src/index.ts","../src/utils.ts","../src/memory.ts","../src/breadcrumbs.ts","../src/classMerge.ts","../src/treeOfContent.ts","../src/params.ts"],"sourcesContent":["export * from './utils';\nexport * from './memory';\nexport * from './breadcrumbs';\nexport * from './classMerge';\nexport * from './treeOfContent';\nexport * from './params';","export const ALL = \"*\"\n\nexport const LOG_CATEGORIES = [\n \"NoLicense\",\n \"Scenario\",\n \"Favorites\",\n \"Subscription\",\n \"Share\",\n \"Document\",\n \"Search\",\n \"History\",\n \"Notification\",\n \"UserProfile\",\n] as const;\n\nexport const LOG_LEVELS = {\n critical: 2,\n error: 3,\n warning: 4,\n info: 6,\n debug: 7,\n} as const;\n\nexport const API = {\n MAX_RETRY: 3,\n API_TIMEOUT: 10000,\n API_HEADERS: {\n \"content-Type\": \"application/json\",\n },\n};\n\nexport const SDK_CONFIG_KEY = \"crex-sdk-config\";\n\nexport const CONTENT_LANG_KEY = \"CONTENT_LANG_KEY\";\n\nexport const UI_LANG_KEY = \"UI_LANG_KEY\";\n\nexport const FLAGS_BY_LANG = {\n \"en\": \"US\",\n \"de\": \"DE\",\n};\n\nexport const DEFAULT_UI_LANG = \"en\";\nexport const UI_LANG_OPTIONS = [\"en\", \"de\"];","import { FLAGS_BY_LANG } from \"@c-rex/constants\";\n\nexport const call = async<T = unknown>(method: string, params?: any): Promise<T> => {\n try {\n const res = await fetch(`/api/rpc`, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({ method, params }),\n });\n\n const json = await res.json();\n\n if (!res.ok) throw new Error(json.error || 'Unknown error');\n\n return json.data;\n } catch (error) {\n console.error(error);\n return null as any;\n }\n}\n\nexport const getCountryCodeByLang = (lang: string): string => {\n const mappedKeys = Object.keys(FLAGS_BY_LANG);\n\n if (!mappedKeys.includes(lang)) {\n return lang\n }\n\n type LangKey = keyof typeof FLAGS_BY_LANG;\n const country = FLAGS_BY_LANG[lang as LangKey]\n\n return country\n}","export function isBrowser() {\n return typeof window !== 'undefined' && typeof document !== 'undefined';\n}\n\nexport function saveInMemory(value: any, key: string) {\n if (isBrowser()) throw new Error(\"saveInMemory is not supported in browser\");\n\n if (typeof global !== 'undefined' && !(key in global)) {\n (global as any)[key] = null;\n }\n\n const globalConfig = (global as any)[key] as any;\n\n if (globalConfig === null) {\n (global as any)[key] = value;\n }\n}\n\nexport function getFromMemory(key: string): any {\n if (isBrowser()) throw new Error(\"getFromMemory is not supported in browser\");\n\n return (global as any)[key];\n}\n","import { TreeOfContent } from \"@c-rex/interfaces\";\n\nexport const generateBreadcrumbItems = (\n treeOfContent: TreeOfContent[],\n): TreeOfContent[] => {\n const result: TreeOfContent[] = [];\n\n treeOfContent.forEach((item) => {\n if (item.active) {\n const filteredChildren = generateBreadcrumbItems(item.children);\n result.push(item, ...filteredChildren);\n }\n });\n\n return result;\n};\n","import { clsx, type ClassValue } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nexport function cn(...inputs: ClassValue[]) {\n return twMerge(clsx(inputs));\n}\n","import { DirectoryNodesService } from \"@c-rex/services\";\nimport { DirectoryNodes, informationUnitsDirectories, TreeOfContent } from \"@c-rex/interfaces\";\n\nexport const generateTreeOfContent = async (\n directoryNodes: DirectoryNodes[],\n): Promise<TreeOfContent[]> => {\n\n const service = new DirectoryNodesService();\n\n if (directoryNodes.length == 0) return [];\n if (directoryNodes[0] == undefined) return [];\n\n let id = directoryNodes[0].shortId;\n let response = await service.getItem(id);\n const childList = await getChildrenInfo(response.childNodes);\n let result: TreeOfContent[] = childList;\n\n while (response.parents != undefined) {\n if (response.informationUnits[0] == undefined) return result;\n if (response.labels[0] == undefined) return result;\n if (response.parents[0] == undefined) return result;\n\n const infoId = response.informationUnits[0].shortId;\n const aux = {\n active: true,\n label: response.labels[0].value,\n id: response.shortId,\n link: `/info/${infoId}`,\n children: [...result],\n };\n id = response.parents[0].shortId;\n response = await service.getItem(id);\n\n const tree = await getChildrenInfo(response.childNodes, aux);\n\n result = [...tree];\n }\n\n return result;\n};\n\nconst getChildrenInfo = async (\n childNodes: informationUnitsDirectories[],\n childItem?: TreeOfContent,\n): Promise<TreeOfContent[]> => {\n const result: TreeOfContent[] = [];\n if (childNodes == undefined) return result;\n\n for (const item of childNodes) {\n if (item.labels[0] == undefined) break;\n\n const infoId = await getLink(item.shortId);\n let resultItem: TreeOfContent = {\n active: false,\n label: item.labels[0].value,\n link: `/info/${infoId}`,\n id: item.shortId,\n children: [],\n };\n\n if (childItem?.id == item.shortId) {\n resultItem = childItem;\n }\n result.push(resultItem);\n }\n\n return result;\n};\n\nconst getLink = async (id: string): Promise<string> => {\n const service = new DirectoryNodesService();\n const response = await service.getItem(id);\n\n if (response.informationUnits == undefined) return \"\";\n if (response.informationUnits[0] == undefined) return \"\";\n\n return response.informationUnits[0].shortId;\n};","import { QueryParams } from '@c-rex/types';\n\nexport const createParams = (fieldsList: string[], key: string = \"Fields\") =>\n fieldsList.map((item) => ({\n key: key,\n value: item,\n }));\n\nexport const generateQueryParams = (params: QueryParams[]): string => {\n const queryParams = params\n .map(\n (param) =>\n `${encodeURIComponent(param.key)}=${encodeURIComponent(param.value)}`,\n )\n .join(\"&\");\n return queryParams;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACqCO,IAAM,gBAAgB;AAAA,EACzB,MAAM;AAAA,EACN,MAAM;AACV;;;ACtCO,IAAM,OAAO,OAAmB,QAAgB,WAA6B;AAChF,MAAI;AACA,UAAM,MAAM,MAAM,MAAM,YAAY;AAAA,MAChC,QAAQ;AAAA,MACR,SAAS,EAAE,gBAAgB,mBAAmB;AAAA,MAC9C,MAAM,KAAK,UAAU,EAAE,QAAQ,OAAO,CAAC;AAAA,IAC3C,CAAC;AAED,UAAM,OAAO,MAAM,IAAI,KAAK;AAE5B,QAAI,CAAC,IAAI,GAAI,OAAM,IAAI,MAAM,KAAK,SAAS,eAAe;AAE1D,WAAO,KAAK;AAAA,EAChB,SAAS,OAAO;AACZ,YAAQ,MAAM,KAAK;AACnB,WAAO;AAAA,EACX;AACJ;AAEO,IAAM,uBAAuB,CAAC,SAAyB;AAC1D,QAAM,aAAa,OAAO,KAAK,aAAa;AAE5C,MAAI,CAAC,WAAW,SAAS,IAAI,GAAG;AAC5B,WAAO;AAAA,EACX;AAGA,QAAM,UAAU,cAAc,IAAe;AAE7C,SAAO;AACX;;;A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xC;;;AC3EO,IAAM,eAAe,CAAC,YAAsB,MAAc,aAC7D,WAAW,IAAI,CAAC,UAAU;AAAA,EACtB;AAAA,EACA,OAAO;AACX,EAAE;AAEC,IAAM,sBAAsB,CAAC,WAAkC;AAClE,QAAM,cAAc,OACf;AAAA,IACG,CAAC,UACG,GAAG,mBAAmB,MAAM,GAAG,CAAC,IAAI,mBAAmB,MAAM,KAAK,CAAC;AAAA,EAC3E,EACC,KAAK,GAAG;AACb,SAAO;AACX;","names":[]}
|
package/dist/index.mjs
CHANGED
|
@@ -1,23 +1,53 @@
|
|
|
1
|
+
// ../constants/src/index.ts
|
|
2
|
+
var FLAGS_BY_LANG = {
|
|
3
|
+
"en": "US",
|
|
4
|
+
"de": "DE"
|
|
5
|
+
};
|
|
6
|
+
|
|
1
7
|
// src/utils.ts
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
var call = async (method, params) => {
|
|
9
|
+
try {
|
|
10
|
+
const res = await fetch(`/api/rpc`, {
|
|
11
|
+
method: "POST",
|
|
12
|
+
headers: { "Content-Type": "application/json" },
|
|
13
|
+
body: JSON.stringify({ method, params })
|
|
14
|
+
});
|
|
15
|
+
const json = await res.json();
|
|
16
|
+
if (!res.ok) throw new Error(json.error || "Unknown error");
|
|
17
|
+
return json.data;
|
|
18
|
+
} catch (error) {
|
|
19
|
+
console.error(error);
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
13
22
|
};
|
|
14
|
-
var
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
23
|
+
var getCountryCodeByLang = (lang) => {
|
|
24
|
+
const mappedKeys = Object.keys(FLAGS_BY_LANG);
|
|
25
|
+
if (!mappedKeys.includes(lang)) {
|
|
26
|
+
return lang;
|
|
27
|
+
}
|
|
28
|
+
const country = FLAGS_BY_LANG[lang];
|
|
29
|
+
return country;
|
|
19
30
|
};
|
|
20
31
|
|
|
32
|
+
// src/memory.ts
|
|
33
|
+
function isBrowser() {
|
|
34
|
+
return typeof window !== "undefined" && typeof document !== "undefined";
|
|
35
|
+
}
|
|
36
|
+
function saveInMemory(value, key) {
|
|
37
|
+
if (isBrowser()) throw new Error("saveInMemory is not supported in browser");
|
|
38
|
+
if (typeof global !== "undefined" && !(key in global)) {
|
|
39
|
+
global[key] = null;
|
|
40
|
+
}
|
|
41
|
+
const globalConfig = global[key];
|
|
42
|
+
if (globalConfig === null) {
|
|
43
|
+
global[key] = value;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
function getFromMemory(key) {
|
|
47
|
+
if (isBrowser()) throw new Error("getFromMemory is not supported in browser");
|
|
48
|
+
return global[key];
|
|
49
|
+
}
|
|
50
|
+
|
|
21
51
|
// src/breadcrumbs.ts
|
|
22
52
|
var generateBreadcrumbItems = (treeOfContent) => {
|
|
23
53
|
const result = [];
|
|
@@ -36,11 +66,85 @@ import { twMerge } from "tailwind-merge";
|
|
|
36
66
|
function cn(...inputs) {
|
|
37
67
|
return twMerge(clsx(inputs));
|
|
38
68
|
}
|
|
69
|
+
|
|
70
|
+
// src/treeOfContent.ts
|
|
71
|
+
import { DirectoryNodesService } from "@c-rex/services";
|
|
72
|
+
var generateTreeOfContent = async (directoryNodes) => {
|
|
73
|
+
const service = new DirectoryNodesService();
|
|
74
|
+
if (directoryNodes.length == 0) return [];
|
|
75
|
+
if (directoryNodes[0] == void 0) return [];
|
|
76
|
+
let id = directoryNodes[0].shortId;
|
|
77
|
+
let response = await service.getItem(id);
|
|
78
|
+
const childList = await getChildrenInfo(response.childNodes);
|
|
79
|
+
let result = childList;
|
|
80
|
+
while (response.parents != void 0) {
|
|
81
|
+
if (response.informationUnits[0] == void 0) return result;
|
|
82
|
+
if (response.labels[0] == void 0) return result;
|
|
83
|
+
if (response.parents[0] == void 0) return result;
|
|
84
|
+
const infoId = response.informationUnits[0].shortId;
|
|
85
|
+
const aux = {
|
|
86
|
+
active: true,
|
|
87
|
+
label: response.labels[0].value,
|
|
88
|
+
id: response.shortId,
|
|
89
|
+
link: `/info/${infoId}`,
|
|
90
|
+
children: [...result]
|
|
91
|
+
};
|
|
92
|
+
id = response.parents[0].shortId;
|
|
93
|
+
response = await service.getItem(id);
|
|
94
|
+
const tree = await getChildrenInfo(response.childNodes, aux);
|
|
95
|
+
result = [...tree];
|
|
96
|
+
}
|
|
97
|
+
return result;
|
|
98
|
+
};
|
|
99
|
+
var getChildrenInfo = async (childNodes, childItem) => {
|
|
100
|
+
const result = [];
|
|
101
|
+
if (childNodes == void 0) return result;
|
|
102
|
+
for (const item of childNodes) {
|
|
103
|
+
if (item.labels[0] == void 0) break;
|
|
104
|
+
const infoId = await getLink(item.shortId);
|
|
105
|
+
let resultItem = {
|
|
106
|
+
active: false,
|
|
107
|
+
label: item.labels[0].value,
|
|
108
|
+
link: `/info/${infoId}`,
|
|
109
|
+
id: item.shortId,
|
|
110
|
+
children: []
|
|
111
|
+
};
|
|
112
|
+
if (childItem?.id == item.shortId) {
|
|
113
|
+
resultItem = childItem;
|
|
114
|
+
}
|
|
115
|
+
result.push(resultItem);
|
|
116
|
+
}
|
|
117
|
+
return result;
|
|
118
|
+
};
|
|
119
|
+
var getLink = async (id) => {
|
|
120
|
+
const service = new DirectoryNodesService();
|
|
121
|
+
const response = await service.getItem(id);
|
|
122
|
+
if (response.informationUnits == void 0) return "";
|
|
123
|
+
if (response.informationUnits[0] == void 0) return "";
|
|
124
|
+
return response.informationUnits[0].shortId;
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
// src/params.ts
|
|
128
|
+
var createParams = (fieldsList, key = "Fields") => fieldsList.map((item) => ({
|
|
129
|
+
key,
|
|
130
|
+
value: item
|
|
131
|
+
}));
|
|
132
|
+
var generateQueryParams = (params) => {
|
|
133
|
+
const queryParams = params.map(
|
|
134
|
+
(param) => `${encodeURIComponent(param.key)}=${encodeURIComponent(param.value)}`
|
|
135
|
+
).join("&");
|
|
136
|
+
return queryParams;
|
|
137
|
+
};
|
|
39
138
|
export {
|
|
139
|
+
call,
|
|
40
140
|
cn,
|
|
41
141
|
createParams,
|
|
42
142
|
generateBreadcrumbItems,
|
|
43
143
|
generateQueryParams,
|
|
44
|
-
|
|
144
|
+
generateTreeOfContent,
|
|
145
|
+
getCountryCodeByLang,
|
|
146
|
+
getFromMemory,
|
|
147
|
+
isBrowser,
|
|
148
|
+
saveInMemory
|
|
45
149
|
};
|
|
46
150
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/utils.ts","../src/breadcrumbs.ts","../src/classMerge.ts"],"sourcesContent":["\
|
|
1
|
+
{"version":3,"sources":["../../constants/src/index.ts","../src/utils.ts","../src/memory.ts","../src/breadcrumbs.ts","../src/classMerge.ts","../src/treeOfContent.ts","../src/params.ts"],"sourcesContent":["export const ALL = \"*\"\n\nexport const LOG_CATEGORIES = [\n \"NoLicense\",\n \"Scenario\",\n \"Favorites\",\n \"Subscription\",\n \"Share\",\n \"Document\",\n \"Search\",\n \"History\",\n \"Notification\",\n \"UserProfile\",\n] as const;\n\nexport const LOG_LEVELS = {\n critical: 2,\n error: 3,\n warning: 4,\n info: 6,\n debug: 7,\n} as const;\n\nexport const API = {\n MAX_RETRY: 3,\n API_TIMEOUT: 10000,\n API_HEADERS: {\n \"content-Type\": \"application/json\",\n },\n};\n\nexport const SDK_CONFIG_KEY = \"crex-sdk-config\";\n\nexport const CONTENT_LANG_KEY = \"CONTENT_LANG_KEY\";\n\nexport const UI_LANG_KEY = \"UI_LANG_KEY\";\n\nexport const FLAGS_BY_LANG = {\n \"en\": \"US\",\n \"de\": \"DE\",\n};\n\nexport const DEFAULT_UI_LANG = \"en\";\nexport const UI_LANG_OPTIONS = [\"en\", \"de\"];","import { FLAGS_BY_LANG } from \"@c-rex/constants\";\n\nexport const call = async<T = unknown>(method: string, params?: any): Promise<T> => {\n try {\n const res = await fetch(`/api/rpc`, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({ method, params }),\n });\n\n const json = await res.json();\n\n if (!res.ok) throw new Error(json.error || 'Unknown error');\n\n return json.data;\n } catch (error) {\n console.error(error);\n return null as any;\n }\n}\n\nexport const getCountryCodeByLang = (lang: string): string => {\n const mappedKeys = Object.keys(FLAGS_BY_LANG);\n\n if (!mappedKeys.includes(lang)) {\n return lang\n }\n\n type LangKey = keyof typeof FLAGS_BY_LANG;\n const country = FLAGS_BY_LANG[lang as LangKey]\n\n return country\n}","export function isBrowser() {\n return typeof window !== 'undefined' && typeof document !== 'undefined';\n}\n\nexport function saveInMemory(value: any, key: string) {\n if (isBrowser()) throw new Error(\"saveInMemory is not supported in browser\");\n\n if (typeof global !== 'undefined' && !(key in global)) {\n (global as any)[key] = null;\n }\n\n const globalConfig = (global as any)[key] as any;\n\n if (globalConfig === null) {\n (global as any)[key] = value;\n }\n}\n\nexport function getFromMemory(key: string): any {\n if (isBrowser()) throw new Error(\"getFromMemory is not supported in browser\");\n\n return (global as any)[key];\n}\n","import { TreeOfContent } from \"@c-rex/interfaces\";\n\nexport const generateBreadcrumbItems = (\n treeOfContent: TreeOfContent[],\n): TreeOfContent[] => {\n const result: TreeOfContent[] = [];\n\n treeOfContent.forEach((item) => {\n if (item.active) {\n const filteredChildren = generateBreadcrumbItems(item.children);\n result.push(item, ...filteredChildren);\n }\n });\n\n return result;\n};\n","import { clsx, type ClassValue } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nexport function cn(...inputs: ClassValue[]) {\n return twMerge(clsx(inputs));\n}\n","import { DirectoryNodesService } from \"@c-rex/services\";\nimport { DirectoryNodes, informationUnitsDirectories, TreeOfContent } from \"@c-rex/interfaces\";\n\nexport const generateTreeOfContent = async (\n directoryNodes: DirectoryNodes[],\n): Promise<TreeOfContent[]> => {\n\n const service = new DirectoryNodesService();\n\n if (directoryNodes.length == 0) return [];\n if (directoryNodes[0] == undefined) return [];\n\n let id = directoryNodes[0].shortId;\n let response = await service.getItem(id);\n const childList = await getChildrenInfo(response.childNodes);\n let result: TreeOfContent[] = childList;\n\n while (response.parents != undefined) {\n if (response.informationUnits[0] == undefined) return result;\n if (response.labels[0] == undefined) return result;\n if (response.parents[0] == undefined) return result;\n\n const infoId = response.informationUnits[0].shortId;\n const aux = {\n active: true,\n label: response.labels[0].value,\n id: response.shortId,\n link: `/info/${infoId}`,\n children: [...result],\n };\n id = response.parents[0].shortId;\n response = await service.getItem(id);\n\n const tree = await getChildrenInfo(response.childNodes, aux);\n\n result = [...tree];\n }\n\n return result;\n};\n\nconst getChildrenInfo = async (\n childNodes: informationUnitsDirectories[],\n childItem?: TreeOfContent,\n): Promise<TreeOfContent[]> => {\n const result: TreeOfContent[] = [];\n if (childNodes == undefined) return result;\n\n for (const item of childNodes) {\n if (item.labels[0] == undefined) break;\n\n const infoId = await getLink(item.shortId);\n let resultItem: TreeOfContent = {\n active: false,\n label: item.labels[0].value,\n link: `/info/${infoId}`,\n id: item.shortId,\n children: [],\n };\n\n if (childItem?.id == item.shortId) {\n resultItem = childItem;\n }\n result.push(resultItem);\n }\n\n return result;\n};\n\nconst getLink = async (id: string): Promise<string> => {\n const service = new DirectoryNodesService();\n const response = await service.getItem(id);\n\n if (response.informationUnits == undefined) return \"\";\n if (response.informationUnits[0] == undefined) return \"\";\n\n return response.informationUnits[0].shortId;\n};","import { QueryParams } from '@c-rex/types';\n\nexport const createParams = (fieldsList: string[], key: string = \"Fields\") =>\n fieldsList.map((item) => ({\n key: key,\n value: item,\n }));\n\nexport const generateQueryParams = (params: QueryParams[]): string => {\n const queryParams = params\n .map(\n (param) =>\n `${encodeURIComponent(param.key)}=${encodeURIComponent(param.value)}`,\n )\n .join(\"&\");\n return queryParams;\n};\n"],"mappings":";AAqCO,IAAM,gBAAgB;AAAA,EACzB,MAAM;AAAA,EACN,MAAM;AACV;;;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Q,YAAY;AAC3B,QAAI,KAAK,OAAO,CAAC,KAAK,OAAW;AAEjC,UAAM,SAAS,MAAM,QAAQ,KAAK,OAAO;AACzC,QAAI,aAA4B;AAAA,MAC5B,QAAQ;AAAA,MACR,OAAO,KAAK,OAAO,CAAC,EAAE;AAAA,MACtB,MAAM,SAAS,MAAM;AAAA,MACrB,IAAI,KAAK;AAAA,MACT,UAAU,CAAC;AAAA,IACf;AAEA,QAAI,WAAW,MAAM,KAAK,SAAS;AAC/B,mBAAa;AAAA,IACjB;AACA,WAAO,KAAK,UAAU;AAAA,EAC1B;AAEA,SAAO;AACX;AAEA,IAAM,UAAU,OAAO,OAAgC;AACnD,QAAM,UAAU,IAAI,sBAAsB;AAC1C,QAAM,WAAW,MAAM,QAAQ,QAAQ,EAAE;AAEzC,MAAI,SAAS,oBAAoB,OAAW,QAAO;AACnD,MAAI,SAAS,iBAAiB,CAAC,KAAK,OAAW,QAAO;AAEtD,SAAO,SAAS,iBAAiB,CAAC,EAAE;AACxC;;;AC3EO,IAAM,eAAe,CAAC,YAAsB,MAAc,aAC7D,WAAW,IAAI,CAAC,UAAU;AAAA,EACtB;AAAA,EACA,OAAO;AACX,EAAE;AAEC,IAAM,sBAAsB,CAAC,WAAkC;AAClE,QAAM,cAAc,OACf;AAAA,IACG,CAAC,UACG,GAAG,mBAAmB,MAAM,GAAG,CAAC,IAAI,mBAAmB,MAAM,KAAK,CAAC;AAAA,EAC3E,EACC,KAAK,GAAG;AACb,SAAO;AACX;","names":[]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ConfigInterface } from '@c-rex/interfaces';
|
|
2
|
+
|
|
3
|
+
declare const getCookie: (key: string) => Promise<string | undefined>;
|
|
4
|
+
declare const setCookie: (key: string, value: string) => Promise<void>;
|
|
5
|
+
declare const getConfigs: () => Promise<ConfigInterface>;
|
|
6
|
+
|
|
7
|
+
export { getConfigs, getCookie, setCookie };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ConfigInterface } from '@c-rex/interfaces';
|
|
2
|
+
|
|
3
|
+
declare const getCookie: (key: string) => Promise<string | undefined>;
|
|
4
|
+
declare const setCookie: (key: string, value: string) => Promise<void>;
|
|
5
|
+
declare const getConfigs: () => Promise<ConfigInterface>;
|
|
6
|
+
|
|
7
|
+
export { getConfigs, getCookie, setCookie };
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use server";
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
|
|
21
|
+
// src/next-cookies.ts
|
|
22
|
+
var next_cookies_exports = {};
|
|
23
|
+
__export(next_cookies_exports, {
|
|
24
|
+
getConfigs: () => getConfigs,
|
|
25
|
+
getCookie: () => getCookie,
|
|
26
|
+
setCookie: () => setCookie
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(next_cookies_exports);
|
|
29
|
+
|
|
30
|
+
// ../constants/src/index.ts
|
|
31
|
+
var SDK_CONFIG_KEY = "crex-sdk-config";
|
|
32
|
+
|
|
33
|
+
// src/next-cookies.ts
|
|
34
|
+
var import_headers = require("next/headers");
|
|
35
|
+
var getCookie = async (key) => {
|
|
36
|
+
return (await (0, import_headers.cookies)()).get(key)?.value;
|
|
37
|
+
};
|
|
38
|
+
var setCookie = async (key, value) => {
|
|
39
|
+
(await (0, import_headers.cookies)()).set(key, value);
|
|
40
|
+
};
|
|
41
|
+
var getConfigs = async () => {
|
|
42
|
+
const jsonConfigs = await getCookie(SDK_CONFIG_KEY);
|
|
43
|
+
if (!jsonConfigs) {
|
|
44
|
+
throw new Error("Configs not found");
|
|
45
|
+
}
|
|
46
|
+
const configs = JSON.parse(jsonConfigs);
|
|
47
|
+
return configs;
|
|
48
|
+
};
|
|
49
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
50
|
+
0 && (module.exports = {
|
|
51
|
+
getConfigs,
|
|
52
|
+
getCookie,
|
|
53
|
+
setCookie
|
|
54
|
+
});
|
|
55
|
+
//# sourceMappingURL=next-cookies.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/next-cookies.ts","../../constants/src/index.ts"],"sourcesContent":["'use server';\n\nimport { SDK_CONFIG_KEY } from '@c-rex/constants';\nimport { ConfigInterface } from '@c-rex/interfaces';\nimport { cookies } from 'next/headers';\n\nexport const getCookie = async (key: string): Promise<string | undefined> => {\n return (await cookies()).get(key)?.value;\n}\n\nexport const setCookie = async (key: string, value: string) => {\n (await cookies()).set(key, value);\n}\n\n\nexport const getConfigs = async (): Promise<ConfigInterface> => {\n const jsonConfigs = await getCookie(SDK_CONFIG_KEY);\n if (!jsonConfigs) {\n throw new Error('Configs not found');\n }\n\n const configs: ConfigInterface = JSON.parse(jsonConfigs);\n\n return configs;\n}","export const ALL = \"*\"\n\nexport const LOG_CATEGORIES = [\n \"NoLicense\",\n \"Scenario\",\n \"Favorites\",\n \"Subscription\",\n \"Share\",\n \"Document\",\n \"Search\",\n \"History\",\n \"Notification\",\n \"UserProfile\",\n] as const;\n\nexport const LOG_LEVELS = {\n critical: 2,\n error: 3,\n warning: 4,\n info: 6,\n debug: 7,\n} as const;\n\nexport const API = {\n MAX_RETRY: 3,\n API_TIMEOUT: 10000,\n API_HEADERS: {\n \"content-Type\": \"application/json\",\n },\n};\n\nexport const SDK_CONFIG_KEY = \"crex-sdk-config\";\n\nexport const CONTENT_LANG_KEY = \"CONTENT_LANG_KEY\";\n\nexport const UI_LANG_KEY = \"UI_LANG_KEY\";\n\nexport const FLAGS_BY_LANG = {\n \"en\": \"US\",\n \"de\": \"DE\",\n};\n\nexport const DEFAULT_UI_LANG = \"en\";\nexport const UI_LANG_OPTIONS = [\"en\", \"de\"];"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;AC+BO,IAAM,iBAAiB;;;AD3B9B,qBAAwB;AAEjB,IAAM,YAAY,OAAO,QAA6C;AACzE,UAAQ,UAAM,wBAAQ,GAAG,IAAI,GAAG,GAAG;AACvC;AAEO,IAAM,YAAY,OAAO,KAAa,UAAkB;AAC3D,GAAC,UAAM,wBAAQ,GAAG,IAAI,KAAK,KAAK;AACpC;AAGO,IAAM,aAAa,YAAsC;AAC5D,QAAM,cAAc,MAAM,UAAU,cAAc;AAClD,MAAI,CAAC,aAAa;AACd,UAAM,IAAI,MAAM,mBAAmB;AAAA,EACvC;AAEA,QAAM,UAA2B,KAAK,MAAM,WAAW;AAEvD,SAAO;AACX;","names":[]}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use server";
|
|
2
|
+
|
|
3
|
+
// ../constants/src/index.ts
|
|
4
|
+
var SDK_CONFIG_KEY = "crex-sdk-config";
|
|
5
|
+
|
|
6
|
+
// src/next-cookies.ts
|
|
7
|
+
import { cookies } from "next/headers";
|
|
8
|
+
var getCookie = async (key) => {
|
|
9
|
+
return (await cookies()).get(key)?.value;
|
|
10
|
+
};
|
|
11
|
+
var setCookie = async (key, value) => {
|
|
12
|
+
(await cookies()).set(key, value);
|
|
13
|
+
};
|
|
14
|
+
var getConfigs = async () => {
|
|
15
|
+
const jsonConfigs = await getCookie(SDK_CONFIG_KEY);
|
|
16
|
+
if (!jsonConfigs) {
|
|
17
|
+
throw new Error("Configs not found");
|
|
18
|
+
}
|
|
19
|
+
const configs = JSON.parse(jsonConfigs);
|
|
20
|
+
return configs;
|
|
21
|
+
};
|
|
22
|
+
export {
|
|
23
|
+
getConfigs,
|
|
24
|
+
getCookie,
|
|
25
|
+
setCookie
|
|
26
|
+
};
|
|
27
|
+
//# sourceMappingURL=next-cookies.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../constants/src/index.ts","../src/next-cookies.ts"],"sourcesContent":["export const ALL = \"*\"\n\nexport const LOG_CATEGORIES = [\n \"NoLicense\",\n \"Scenario\",\n \"Favorites\",\n \"Subscription\",\n \"Share\",\n \"Document\",\n \"Search\",\n \"History\",\n \"Notification\",\n \"UserProfile\",\n] as const;\n\nexport const LOG_LEVELS = {\n critical: 2,\n error: 3,\n warning: 4,\n info: 6,\n debug: 7,\n} as const;\n\nexport const API = {\n MAX_RETRY: 3,\n API_TIMEOUT: 10000,\n API_HEADERS: {\n \"content-Type\": \"application/json\",\n },\n};\n\nexport const SDK_CONFIG_KEY = \"crex-sdk-config\";\n\nexport const CONTENT_LANG_KEY = \"CONTENT_LANG_KEY\";\n\nexport const UI_LANG_KEY = \"UI_LANG_KEY\";\n\nexport const FLAGS_BY_LANG = {\n \"en\": \"US\",\n \"de\": \"DE\",\n};\n\nexport const DEFAULT_UI_LANG = \"en\";\nexport const UI_LANG_OPTIONS = [\"en\", \"de\"];","'use server';\n\nimport { SDK_CONFIG_KEY } from '@c-rex/constants';\nimport { ConfigInterface } from '@c-rex/interfaces';\nimport { cookies } from 'next/headers';\n\nexport const getCookie = async (key: string): Promise<string | undefined> => {\n return (await cookies()).get(key)?.value;\n}\n\nexport const setCookie = async (key: string, value: string) => {\n (await cookies()).set(key, value);\n}\n\n\nexport const getConfigs = async (): Promise<ConfigInterface> => {\n const jsonConfigs = await getCookie(SDK_CONFIG_KEY);\n if (!jsonConfigs) {\n throw new Error('Configs not found');\n }\n\n const configs: ConfigInterface = JSON.parse(jsonConfigs);\n\n return configs;\n}"],"mappings":";;;AA+BO,IAAM,iBAAiB;;;AC3B9B,SAAS,eAAe;AAEjB,IAAM,YAAY,OAAO,QAA6C;AACzE,UAAQ,MAAM,QAAQ,GAAG,IAAI,GAAG,GAAG;AACvC;AAEO,IAAM,YAAY,OAAO,KAAa,UAAkB;AAC3D,GAAC,MAAM,QAAQ,GAAG,IAAI,KAAK,KAAK;AACpC;AAGO,IAAM,aAAa,YAAsC;AAC5D,QAAM,cAAc,MAAM,UAAU,cAAc;AAClD,MAAI,CAAC,aAAa;AACd,UAAM,IAAI,MAAM,mBAAmB;AAAA,EACvC;AAEA,QAAM,UAA2B,KAAK,MAAM,WAAW;AAEvD,SAAO;AACX;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@c-rex/utils",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.1.0",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -16,6 +16,21 @@
|
|
|
16
16
|
"test:watch": "jest --watch",
|
|
17
17
|
"test": "jest"
|
|
18
18
|
},
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"import": "./dist/index.mjs",
|
|
23
|
+
"require": "./dist/index.js",
|
|
24
|
+
"default": "./dist/index.js"
|
|
25
|
+
},
|
|
26
|
+
"./package.json": "./package.json",
|
|
27
|
+
"./next-cookies": {
|
|
28
|
+
"types": "./dist/next-cookies.d.ts",
|
|
29
|
+
"import": "./dist/next-cookies.mjs",
|
|
30
|
+
"require": "./dist/next-cookies.js",
|
|
31
|
+
"default": "./dist/next-cookies.js"
|
|
32
|
+
}
|
|
33
|
+
},
|
|
19
34
|
"devDependencies": {
|
|
20
35
|
"@c-rex/eslint-config": "*",
|
|
21
36
|
"@c-rex/typescript-config": "*",
|
|
@@ -29,8 +44,13 @@
|
|
|
29
44
|
"typescript": "^5.8.3"
|
|
30
45
|
},
|
|
31
46
|
"dependencies": {
|
|
47
|
+
"@c-rex/constants": "*",
|
|
32
48
|
"@c-rex/interfaces": "*",
|
|
49
|
+
"@c-rex/types": "*",
|
|
33
50
|
"clsx": "^2.1.1",
|
|
51
|
+
"country-flag-icons": "^1.5.19",
|
|
52
|
+
"next": "^14.2.28",
|
|
53
|
+
"nuqs": "^2.4.3",
|
|
34
54
|
"tailwind-merge": "^3.2.0"
|
|
35
55
|
}
|
|
36
56
|
}
|