@c-rex/utils 0.1.2 → 0.1.4

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 CHANGED
@@ -1,33 +1,83 @@
1
- import { TreeOfContent, DirectoryNodes, SidebarAvailableVersionsInterface } from '@c-rex/interfaces';
1
+ import { TreeOfContent, DirectoryNodes } from '@c-rex/interfaces';
2
2
  import { ClassValue } from 'clsx';
3
3
  import { QueryParams } from '@c-rex/types';
4
4
 
5
+ /**
6
+ * Makes an asynchronous RPC API call to the server.
7
+ * @param method - The RPC method name to call
8
+ * @param params - Optional parameters to pass to the method
9
+ * @returns A Promise resolving to the response data of type T, or null if an error occurs
10
+ */
5
11
  declare const call: <T = unknown>(method: string, params?: any) => Promise<T>;
12
+ /**
13
+ * Retrieves the country code associated with a given language code.
14
+ * @param lang - The language code to look up (e.g., "en-US")
15
+ * @returns The corresponding country code, or the original language code if not found
16
+ */
6
17
  declare const getCountryCodeByLang: (lang: string) => string;
18
+ declare const getFromCookieString: (cookieString: string, key: string) => string;
7
19
 
8
- declare function isBrowser(): boolean;
9
- declare function saveInMemory(value: any, key: string): void;
10
- declare function getFromMemory(key: string): any;
20
+ /**
21
+ * Fetches a cookie value from the server API in client-side code.
22
+ * @param key - The key of the cookie to retrieve
23
+ * @returns A Promise resolving to an object containing the key and value of the cookie
24
+ */
25
+ declare const getCookie: (key: string) => Promise<{
26
+ key: string;
27
+ value: string | null;
28
+ }>;
29
+ /**
30
+ * Sets a cookie value through the server API in client-side code.
31
+ * @param key - The key of the cookie to set
32
+ * @param value - The value to store in the cookie
33
+ * @param maxAge - Optional maximum age of the cookie in seconds. Defaults to DEFAULT_COOKIE_LIMIT if not specified.
34
+ * @returns A Promise that resolves when the cookie has been set
35
+ */
36
+ declare const setCookie: (key: string, value: string, maxAge?: number) => Promise<void>;
11
37
 
38
+ /**
39
+ * Generates breadcrumb items by recursively extracting active items and their active children from a TreeOfContent array.
40
+ * @param treeOfContent - Array of TreeOfContent objects representing the content hierarchy
41
+ * @returns A flattened array of active TreeOfContent items to be used as breadcrumbs
42
+ */
12
43
  declare const generateBreadcrumbItems: (treeOfContent: TreeOfContent[]) => TreeOfContent[];
13
44
 
45
+ /**
46
+ * Merges multiple class values into a single string using clsx and tailwind-merge.
47
+ * Useful for conditionally applying Tailwind CSS classes.
48
+ * @param inputs - Any number of class values (strings, objects, arrays, etc.)
49
+ * @returns A merged string of class names optimized for Tailwind CSS
50
+ */
14
51
  declare function cn(...inputs: ClassValue[]): string;
15
52
 
16
- declare const generateTreeOfContent: (directoryNodes: DirectoryNodes[]) => Promise<TreeOfContent[]>;
53
+ type ReturnType = {
54
+ rootNode: DirectoryNodes | null;
55
+ result: TreeOfContent[];
56
+ };
57
+ /**
58
+ * Generates a hierarchical tree of content from directory nodes.
59
+ * @param directoryNodes - Array of DirectoryNodes to build the tree from
60
+ * @returns A Promise resolving to an object containing the root node and the resulting tree structure
61
+ */
62
+ declare const generateTreeOfContent: (directoryNodes: DirectoryNodes[]) => Promise<ReturnType>;
17
63
 
64
+ /**
65
+ * Creates an array of parameter objects from a list of field values.
66
+ * @param fieldsList - Array of field values to transform into parameter objects
67
+ * @param key - The key to use for each parameter object (defaults to "Fields")
68
+ * @returns An array of objects with key-value pairs
69
+ */
18
70
  declare const createParams: (fieldsList: string[], key?: string) => {
19
71
  key: string;
20
72
  value: string;
21
73
  }[];
74
+ /**
75
+ * Generates a URL query string from an array of parameter objects.
76
+ * @param params - Array of QueryParams objects containing key-value pairs
77
+ * @returns A URL-encoded query string
78
+ */
22
79
  declare const generateQueryParams: (params: QueryParams[]) => string;
23
80
 
24
- declare const loadArticleData: (id: string) => Promise<{
25
- htmlContent: string;
26
- treeOfContent: TreeOfContent[];
27
- breadcrumbItems: TreeOfContent[];
28
- availableVersions: Omit<SidebarAvailableVersionsInterface, "link">[];
29
- documentURL: string;
30
- title: string;
31
- }>;
81
+ declare const manageToken: () => Promise<string | null>;
32
82
 
33
- export { call, cn, createParams, generateBreadcrumbItems, generateQueryParams, generateTreeOfContent, getCountryCodeByLang, getFromMemory, isBrowser, loadArticleData, saveInMemory };
83
+ export { call, cn, createParams, generateBreadcrumbItems, generateQueryParams, generateTreeOfContent, getCookie, getCountryCodeByLang, getFromCookieString, manageToken, setCookie };
package/dist/index.d.ts CHANGED
@@ -1,33 +1,83 @@
1
- import { TreeOfContent, DirectoryNodes, SidebarAvailableVersionsInterface } from '@c-rex/interfaces';
1
+ import { TreeOfContent, DirectoryNodes } from '@c-rex/interfaces';
2
2
  import { ClassValue } from 'clsx';
3
3
  import { QueryParams } from '@c-rex/types';
4
4
 
5
+ /**
6
+ * Makes an asynchronous RPC API call to the server.
7
+ * @param method - The RPC method name to call
8
+ * @param params - Optional parameters to pass to the method
9
+ * @returns A Promise resolving to the response data of type T, or null if an error occurs
10
+ */
5
11
  declare const call: <T = unknown>(method: string, params?: any) => Promise<T>;
12
+ /**
13
+ * Retrieves the country code associated with a given language code.
14
+ * @param lang - The language code to look up (e.g., "en-US")
15
+ * @returns The corresponding country code, or the original language code if not found
16
+ */
6
17
  declare const getCountryCodeByLang: (lang: string) => string;
18
+ declare const getFromCookieString: (cookieString: string, key: string) => string;
7
19
 
8
- declare function isBrowser(): boolean;
9
- declare function saveInMemory(value: any, key: string): void;
10
- declare function getFromMemory(key: string): any;
20
+ /**
21
+ * Fetches a cookie value from the server API in client-side code.
22
+ * @param key - The key of the cookie to retrieve
23
+ * @returns A Promise resolving to an object containing the key and value of the cookie
24
+ */
25
+ declare const getCookie: (key: string) => Promise<{
26
+ key: string;
27
+ value: string | null;
28
+ }>;
29
+ /**
30
+ * Sets a cookie value through the server API in client-side code.
31
+ * @param key - The key of the cookie to set
32
+ * @param value - The value to store in the cookie
33
+ * @param maxAge - Optional maximum age of the cookie in seconds. Defaults to DEFAULT_COOKIE_LIMIT if not specified.
34
+ * @returns A Promise that resolves when the cookie has been set
35
+ */
36
+ declare const setCookie: (key: string, value: string, maxAge?: number) => Promise<void>;
11
37
 
38
+ /**
39
+ * Generates breadcrumb items by recursively extracting active items and their active children from a TreeOfContent array.
40
+ * @param treeOfContent - Array of TreeOfContent objects representing the content hierarchy
41
+ * @returns A flattened array of active TreeOfContent items to be used as breadcrumbs
42
+ */
12
43
  declare const generateBreadcrumbItems: (treeOfContent: TreeOfContent[]) => TreeOfContent[];
13
44
 
45
+ /**
46
+ * Merges multiple class values into a single string using clsx and tailwind-merge.
47
+ * Useful for conditionally applying Tailwind CSS classes.
48
+ * @param inputs - Any number of class values (strings, objects, arrays, etc.)
49
+ * @returns A merged string of class names optimized for Tailwind CSS
50
+ */
14
51
  declare function cn(...inputs: ClassValue[]): string;
15
52
 
16
- declare const generateTreeOfContent: (directoryNodes: DirectoryNodes[]) => Promise<TreeOfContent[]>;
53
+ type ReturnType = {
54
+ rootNode: DirectoryNodes | null;
55
+ result: TreeOfContent[];
56
+ };
57
+ /**
58
+ * Generates a hierarchical tree of content from directory nodes.
59
+ * @param directoryNodes - Array of DirectoryNodes to build the tree from
60
+ * @returns A Promise resolving to an object containing the root node and the resulting tree structure
61
+ */
62
+ declare const generateTreeOfContent: (directoryNodes: DirectoryNodes[]) => Promise<ReturnType>;
17
63
 
64
+ /**
65
+ * Creates an array of parameter objects from a list of field values.
66
+ * @param fieldsList - Array of field values to transform into parameter objects
67
+ * @param key - The key to use for each parameter object (defaults to "Fields")
68
+ * @returns An array of objects with key-value pairs
69
+ */
18
70
  declare const createParams: (fieldsList: string[], key?: string) => {
19
71
  key: string;
20
72
  value: string;
21
73
  }[];
74
+ /**
75
+ * Generates a URL query string from an array of parameter objects.
76
+ * @param params - Array of QueryParams objects containing key-value pairs
77
+ * @returns A URL-encoded query string
78
+ */
22
79
  declare const generateQueryParams: (params: QueryParams[]) => string;
23
80
 
24
- declare const loadArticleData: (id: string) => Promise<{
25
- htmlContent: string;
26
- treeOfContent: TreeOfContent[];
27
- breadcrumbItems: TreeOfContent[];
28
- availableVersions: Omit<SidebarAvailableVersionsInterface, "link">[];
29
- documentURL: string;
30
- title: string;
31
- }>;
81
+ declare const manageToken: () => Promise<string | null>;
32
82
 
33
- export { call, cn, createParams, generateBreadcrumbItems, generateQueryParams, generateTreeOfContent, getCountryCodeByLang, getFromMemory, isBrowser, loadArticleData, saveInMemory };
83
+ export { call, cn, createParams, generateBreadcrumbItems, generateQueryParams, generateTreeOfContent, getCookie, getCountryCodeByLang, getFromCookieString, manageToken, setCookie };
package/dist/index.js CHANGED
@@ -26,11 +26,11 @@ __export(index_exports, {
26
26
  generateBreadcrumbItems: () => generateBreadcrumbItems,
27
27
  generateQueryParams: () => generateQueryParams,
28
28
  generateTreeOfContent: () => generateTreeOfContent,
29
+ getCookie: () => getCookie,
29
30
  getCountryCodeByLang: () => getCountryCodeByLang,
30
- getFromMemory: () => getFromMemory,
31
- isBrowser: () => isBrowser,
32
- loadArticleData: () => loadArticleData,
33
- saveInMemory: () => saveInMemory
31
+ getFromCookieString: () => getFromCookieString,
32
+ manageToken: () => manageToken,
33
+ setCookie: () => setCookie
34
34
  });
35
35
  module.exports = __toCommonJS(index_exports);
36
36
 
@@ -39,6 +39,8 @@ var FLAGS_BY_LANG = {
39
39
  "en": "US",
40
40
  "de": "DE"
41
41
  };
42
+ var DEFAULT_COOKIE_LIMIT = 7 * 24 * 60 * 60 * 1e3;
43
+ var CREX_TOKEN_HEADER_KEY = "crex-token";
42
44
 
43
45
  // src/utils.ts
44
46
  var call = async (method, params) => {
@@ -46,7 +48,8 @@ var call = async (method, params) => {
46
48
  const res = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/api/rpc`, {
47
49
  method: "POST",
48
50
  headers: { "Content-Type": "application/json" },
49
- body: JSON.stringify({ method, params })
51
+ body: JSON.stringify({ method, params }),
52
+ credentials: "include"
50
53
  });
51
54
  const json = await res.json();
52
55
  if (!res.ok) throw new Error(json.error || "Unknown error");
@@ -64,25 +67,47 @@ var getCountryCodeByLang = (lang) => {
64
67
  const country = FLAGS_BY_LANG[lang];
65
68
  return country;
66
69
  };
70
+ var getFromCookieString = (cookieString, key) => {
71
+ const cookies = cookieString.split(";");
72
+ for (const cookie of cookies) {
73
+ const [cookieKey, cookieValue] = cookie.trim().split("=");
74
+ if (cookieKey === key) {
75
+ return cookieValue;
76
+ }
77
+ }
78
+ return "";
79
+ };
67
80
 
68
81
  // src/memory.ts
69
- function isBrowser() {
70
- return typeof window !== "undefined" && typeof document !== "undefined";
71
- }
72
- function saveInMemory(value, key) {
73
- if (isBrowser()) throw new Error("saveInMemory is not supported in browser");
74
- if (typeof global !== "undefined" && !(key in global)) {
75
- global[key] = null;
82
+ var getCookie = async (key) => {
83
+ const res = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/api/cookies?key=${key}`);
84
+ if (!res.ok) {
85
+ return { key, value: null };
76
86
  }
77
- const globalConfig = global[key];
78
- if (globalConfig === null) {
79
- global[key] = value;
87
+ const json = await res.json();
88
+ return json;
89
+ };
90
+ var setCookie = async (key, value, maxAge) => {
91
+ try {
92
+ if (maxAge === void 0) {
93
+ maxAge = DEFAULT_COOKIE_LIMIT;
94
+ }
95
+ await fetch(`${process.env.NEXT_PUBLIC_API_URL}/api/cookies`, {
96
+ method: "POST",
97
+ credentials: "include",
98
+ body: JSON.stringify({
99
+ key,
100
+ value,
101
+ maxAge
102
+ })
103
+ });
104
+ } catch (error) {
105
+ call("CrexLogger.log", {
106
+ level: "error",
107
+ message: `utils.setCookie error: ${error}`
108
+ });
80
109
  }
81
- }
82
- function getFromMemory(key) {
83
- if (isBrowser()) throw new Error("getFromMemory is not supported in browser");
84
- return global[key];
85
- }
110
+ };
86
111
 
87
112
  // src/breadcrumbs.ts
88
113
  var generateBreadcrumbItems = (treeOfContent) => {
@@ -104,44 +129,49 @@ function cn(...inputs) {
104
129
  }
105
130
 
106
131
  // src/treeOfContent.ts
107
- var import_services = require("@c-rex/services");
108
132
  var generateTreeOfContent = async (directoryNodes) => {
109
- const service = new import_services.DirectoryNodesService();
110
- if (directoryNodes.length == 0) return [];
111
- if (directoryNodes[0] == void 0) return [];
133
+ if (directoryNodes.length == 0 || directoryNodes[0] == void 0) {
134
+ return { rootNode: null, result: [] };
135
+ }
112
136
  let id = directoryNodes[0].shortId;
113
- let response = await service.getItem(id);
137
+ let response = await call("DirectoryNodesService.getItem", id);
114
138
  const childList = await getChildrenInfo(response.childNodes);
115
139
  let result = childList;
116
140
  while (response.parents != void 0) {
117
- if (response.informationUnits[0] == void 0) return result;
118
- if (response.labels[0] == void 0) return result;
119
- if (response.parents[0] == void 0) return result;
141
+ const hasInfo = response.informationUnits != void 0 && response.informationUnits[0] != void 0;
142
+ const hasLabel = response.labels != void 0 && response.labels[0] != void 0;
143
+ const hasParent = response.parents != void 0 && response.parents[0] != void 0;
144
+ if (!hasInfo || !hasLabel || !hasParent) {
145
+ return { rootNode: null, result };
146
+ }
120
147
  const infoId = response.informationUnits[0].shortId;
121
148
  const aux = {
122
149
  active: true,
123
150
  label: response.labels[0].value,
124
151
  id: response.shortId,
125
- link: `/info/${infoId}`,
152
+ link: `/topics/${infoId}`,
126
153
  children: [...result]
127
154
  };
128
155
  id = response.parents[0].shortId;
129
- response = await service.getItem(id);
156
+ response = await call("DirectoryNodesService.getItem", id);
130
157
  const tree = await getChildrenInfo(response.childNodes, aux);
131
158
  result = [...tree];
132
159
  }
133
- return result;
160
+ return { rootNode: response, result };
134
161
  };
135
162
  var getChildrenInfo = async (childNodes, childItem) => {
136
163
  const result = [];
137
164
  if (childNodes == void 0) return result;
138
165
  for (const item of childNodes) {
139
- if (item.labels[0] == void 0) break;
140
- const infoId = await getLink(item.shortId);
166
+ if (item.labels == void 0 || item.labels[0] == void 0) break;
167
+ const response = await call("DirectoryNodesService.getItem", item.shortId);
168
+ if (response.informationUnits == void 0) break;
169
+ if (response.informationUnits[0] == void 0) break;
170
+ const infoId = response.informationUnits[0].shortId;
141
171
  let resultItem = {
142
172
  active: false,
143
173
  label: item.labels[0].value,
144
- link: `/info/${infoId}`,
174
+ link: `/topics/${infoId}`,
145
175
  id: item.shortId,
146
176
  children: []
147
177
  };
@@ -152,13 +182,6 @@ var getChildrenInfo = async (childNodes, childItem) => {
152
182
  }
153
183
  return result;
154
184
  };
155
- var getLink = async (id) => {
156
- const service = new import_services.DirectoryNodesService();
157
- const response = await service.getItem(id);
158
- if (response.informationUnits == void 0) return "";
159
- if (response.informationUnits[0] == void 0) return "";
160
- return response.informationUnits[0].shortId;
161
- };
162
185
 
163
186
  // src/params.ts
164
187
  var createParams = (fieldsList, key = "Fields") => fieldsList.map((item) => ({
@@ -172,64 +195,45 @@ var generateQueryParams = (params) => {
172
195
  return queryParams;
173
196
  };
174
197
 
175
- // src/articles.ts
176
- var import_services2 = require("@c-rex/services");
177
- var loadArticleData = async (id) => {
178
- const renditionService = new import_services2.RenditionsService();
179
- const informationService = new import_services2.InformationUnitsService();
180
- const informationUnitsItem = await informationService.getItem({ id });
181
- let title = "";
182
- let versionOf = "";
183
- let documentURL = "";
184
- let htmlContent = "";
185
- let treeOfContent = [];
186
- let breadcrumbItems = [];
187
- let availableVersions = [];
188
- if (informationUnitsItem != null) {
189
- if (informationUnitsItem.versionOf != void 0) {
190
- versionOf = informationUnitsItem.versionOf.shortId;
191
- }
192
- if (informationUnitsItem.titles != void 0 && informationUnitsItem.titles[0] != void 0) {
193
- title = informationUnitsItem.titles[0].value;
194
- }
195
- }
196
- if (versionOf != void 0) {
197
- const versions = await informationService.getList({
198
- filters: [`versionOf.shortId=${versionOf}`],
199
- fields: ["labels"]
198
+ // src/token.ts
199
+ var updateToken = async () => {
200
+ try {
201
+ const response = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/api/token`, {
202
+ method: "POST",
203
+ credentials: "include"
200
204
  });
201
- availableVersions = versions.items.map((item) => {
202
- return {
203
- shortId: item.shortId,
204
- lang: item.labels[0]?.language,
205
- country: item.labels[0]?.language.split("-")[1]
206
- };
207
- }).sort((a, b) => {
208
- if (a.lang < b.lang) {
209
- return -1;
210
- }
211
- if (a.lang > b.lang) {
212
- return 1;
213
- }
214
- return 0;
205
+ const cookies = response.headers.get("set-cookie");
206
+ if (cookies === null) return null;
207
+ const aux = cookies.split(`${CREX_TOKEN_HEADER_KEY}=`);
208
+ if (aux.length == 0) return null;
209
+ const token = aux[1].split(";")[0];
210
+ if (token === void 0) throw new Error("Token is undefined");
211
+ return token;
212
+ } catch (error) {
213
+ call("CrexLogger.log", {
214
+ level: "error",
215
+ message: `utils.updateToken error: ${error}`
215
216
  });
217
+ return null;
216
218
  }
217
- if (informationUnitsItem?.renditions != void 0) {
218
- htmlContent = await renditionService.getHTMLRendition(informationUnitsItem.renditions);
219
- documentURL = await renditionService.getDocumentRendition(informationUnitsItem.renditions, "pdf");
220
- if (informationUnitsItem?.directoryNodes != void 0) {
221
- treeOfContent = await generateTreeOfContent(informationUnitsItem.directoryNodes);
222
- breadcrumbItems = generateBreadcrumbItems(treeOfContent);
219
+ };
220
+ var manageToken = async () => {
221
+ try {
222
+ const hasToken = await getCookie(CREX_TOKEN_HEADER_KEY);
223
+ let token = hasToken.value;
224
+ if (hasToken.value === null) {
225
+ const tokenResult = await updateToken();
226
+ if (tokenResult === null) throw new Error("Token is undefined");
227
+ token = tokenResult;
223
228
  }
229
+ return token;
230
+ } catch (error) {
231
+ call("CrexLogger.log", {
232
+ level: "error",
233
+ message: `utils.manageToken error: ${error}`
234
+ });
235
+ return null;
224
236
  }
225
- return {
226
- htmlContent,
227
- treeOfContent,
228
- breadcrumbItems,
229
- availableVersions,
230
- documentURL,
231
- title
232
- };
233
237
  };
234
238
  // Annotate the CommonJS export names for ESM import in node:
235
239
  0 && (module.exports = {
@@ -239,10 +243,10 @@ var loadArticleData = async (id) => {
239
243
  generateBreadcrumbItems,
240
244
  generateQueryParams,
241
245
  generateTreeOfContent,
246
+ getCookie,
242
247
  getCountryCodeByLang,
243
- getFromMemory,
244
- isBrowser,
245
- loadArticleData,
246
- saveInMemory
248
+ getFromCookieString,
249
+ manageToken,
250
+ setCookie
247
251
  });
248
252
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
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","../src/articles.ts"],"sourcesContent":["export * from './utils';\nexport * from './memory';\nexport * from './breadcrumbs';\nexport * from './classMerge';\nexport * from './treeOfContent';\nexport * from './params';\nexport * from './articles';","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 RESULT_VIEW_STYLES = [\n \"cards\",\n \"table\",\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 AVAILABLE_CONTENT_LANG_KEY = \"AVAILABLE_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\";\n\nexport const UI_LANG_OPTIONS = [\"en\", \"de\"];\n\nexport const RESULT_TYPES = {\n TOPIC: \"TOPIC\",\n DOCUMENT: \"DOCUMENT\",\n PACKAGE: \"PACKAGE\",\n} as const;","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(`${process.env.NEXT_PUBLIC_API_URL}/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","import { InformationUnitsService, RenditionsService } from \"@c-rex/services\";\nimport { generateBreadcrumbItems, generateTreeOfContent } from \"@c-rex/utils\";\nimport { SidebarAvailableVersionsInterface, TreeOfContent } from \"@c-rex/interfaces\";\n\nexport const loadArticleData = async (id: string) => {\n const renditionService = new RenditionsService();\n const informationService = new InformationUnitsService();\n const informationUnitsItem = await informationService.getItem({ id });\n\n let title = \"\";\n let versionOf = \"\";\n let documentURL = \"\";\n let htmlContent = \"\";\n let treeOfContent: TreeOfContent[] = [];\n let breadcrumbItems: TreeOfContent[] = [];\n let availableVersions: Omit<SidebarAvailableVersionsInterface, \"link\">[] = [];\n\n if (informationUnitsItem != null) {\n if (informationUnitsItem.versionOf != undefined) {\n versionOf = informationUnitsItem.versionOf.shortId\n }\n if (informationUnitsItem.titles != undefined && informationUnitsItem.titles[0] != undefined) {\n title = informationUnitsItem.titles[0].value\n }\n }\n\n if (versionOf != undefined) {\n const versions = await informationService.getList({\n filters: [`versionOf.shortId=${versionOf}`],\n fields: [\"labels\"],\n })\n\n availableVersions = versions.items.map((item) => {\n return {\n shortId: item.shortId,\n lang: item.labels[0]?.language as string,\n country: item.labels[0]?.language.split(\"-\")[1] as string,\n }\n }).sort((a, b) => {\n if (a.lang < b.lang) {\n return -1;\n }\n if (a.lang > b.lang) {\n return 1;\n }\n return 0;\n })\n }\n\n if (informationUnitsItem?.renditions != undefined) {\n htmlContent = await renditionService.getHTMLRendition(informationUnitsItem.renditions)\n documentURL = await renditionService.getDocumentRendition(informationUnitsItem.renditions, \"pdf\")\n\n if (informationUnitsItem?.directoryNodes != undefined) {\n treeOfContent = await generateTreeOfContent(informationUnitsItem.directoryNodes);\n breadcrumbItems = generateBreadcrumbItems(treeOfContent);\n }\n }\n\n return {\n htmlContent,\n treeOfContent,\n breadcrumbItems,\n availableVersions,\n documentURL,\n title\n }\n};"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;AC4CO,IAAM,gBAAgB;AAAA,EACzB,MAAM;AAAA,EACN,MAAM;AACV;;;AC7CO,IAAM,OAAO,OAAmB,QAAgB,WAA6B;AAChF,MAAI;AACA,UAAM,MAAM,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","../src/breadcrumbs.ts","../src/classMerge.ts","../src/treeOfContent.ts","../src/params.ts","../src/token.ts"],"sourcesContent":["export * from './utils';\nexport * from './memory';\nexport * from './breadcrumbs';\nexport * from './classMerge';\nexport * from './treeOfContent';\nexport * from './params';\nexport * from './token';","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 RESULT_VIEW_STYLES = [\n \"cards\",\n \"table\",\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 AVAILABLE_CONTENT_LANG_KEY = \"AVAILABLE_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_LANG = \"en-US\";\n\nexport const EN_LANG = \"en\";\n\nexport const UI_LANG_OPTIONS = [\"en-us\", \"de-de\"];\n\nexport const TOPICS_TYPE_AND_LINK = \"topics\";\nexport const DOCUMENTS_TYPE_AND_LINK = \"documents\";\n\nexport const TOPIC = \"TOPIC\";\nexport const DOCUMENT = \"DOCUMENT\";\nexport const PACKAGE = \"PACKAGE\";\n\nexport const RESULT_TYPES = {\n TOPIC: TOPIC,\n DOCUMENT: DOCUMENT,\n PACKAGE: PACKAGE,\n} as const;\n\nexport const FILES_EXTENSIONS = {\n PDF: \"application/pdf\",\n HTML: \"text/html\",\n} as const;\n\nexport const DEFAULT_COOKIE_LIMIT = 7 * 24 * 60 * 60 * 1000; // 7 days in milliseconds\n\nexport const ICONS_BY_FILE_EXTENSION = {\n \"application/pdf\": \"FaFilePdf\",\n} as const;\n\nexport const DEFAULT_ICON = \"file\";\n\nexport const CREX_TOKEN_HEADER_KEY = \"crex-token\";","import { FLAGS_BY_LANG } from \"@c-rex/constants\";\n\n/**\n * Makes an asynchronous RPC API call to the server.\n * @param method - The RPC method name to call\n * @param params - Optional parameters to pass to the method\n * @returns A Promise resolving to the response data of type T, or null if an error occurs\n */\nexport const call = async<T = unknown>(method: string, params?: any): Promise<T> => {\n try {\n const res = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/api/rpc`, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({ method, params }),\n credentials: 'include',\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 //TODO: add logger\n console.error(error);\n return null as T;\n }\n}\n\n/**\n * Retrieves the country code associated with a given language code.\n * @param lang - The language code to look up (e.g., \"en-US\")\n * @returns The corresponding country code, or the original language code if not found\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}\n\nexport const getFromCookieString = (cookieString: string, key: string): string => {\n const cookies = cookieString.split(';')\n\n for (const cookie of cookies) {\n const [cookieKey, cookieValue] = cookie.trim().split('=')\n\n if (cookieKey === key) {\n return cookieValue as string;\n }\n }\n\n return ''\n}\n","import { DEFAULT_COOKIE_LIMIT } from \"@c-rex/constants\";\nimport { call } from \"./utils\";\n\n/**\n * Fetches a cookie value from the server API in client-side code.\n * @param key - The key of the cookie to retrieve\n * @returns A Promise resolving to an object containing the key and value of the cookie\n */\nexport const getCookie = async (key: string): Promise<{ key: string, value: string | null }> => {\n const res = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/api/cookies?key=${key}`);\n\n if (!res.ok) {\n return { key: key, value: null };\n }\n const json = await res.json();\n\n return json;\n}\n\n/**\n * Sets a cookie value through the server API in client-side code.\n * @param key - The key of the cookie to set\n * @param value - The value to store in the cookie\n * @param maxAge - Optional maximum age of the cookie in seconds. Defaults to DEFAULT_COOKIE_LIMIT if not specified.\n * @returns A Promise that resolves when the cookie has been set\n */\nexport const setCookie = async (key: string, value: string, maxAge?: number): Promise<void> => {\n try {\n\n if (maxAge === undefined) {\n maxAge = DEFAULT_COOKIE_LIMIT;\n }\n\n await fetch(`${process.env.NEXT_PUBLIC_API_URL}/api/cookies`, {\n method: 'POST',\n credentials: 'include',\n body: JSON.stringify({\n key: key,\n value: value,\n maxAge: maxAge,\n }),\n });\n } catch (error) {\n call(\"CrexLogger.log\", {\n level: \"error\",\n message: `utils.setCookie error: ${error}`\n });\n }\n}\n\n","import { TreeOfContent } from \"@c-rex/interfaces\";\n\n/**\n * Generates breadcrumb items by recursively extracting active items and their active children from a TreeOfContent array.\n * @param treeOfContent - Array of TreeOfContent objects representing the content hierarchy\n * @returns A flattened array of active TreeOfContent items to be used as breadcrumbs\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\n/**\n * Merges multiple class values into a single string using clsx and tailwind-merge.\n * Useful for conditionally applying Tailwind CSS classes.\n * @param inputs - Any number of class values (strings, objects, arrays, etc.)\n * @returns A merged string of class names optimized for Tailwind CSS\n */\nexport function cn(...inputs: ClassValue[]) {\n return twMerge(clsx(inputs));\n}\n","import { DirectoryNodes, informationUnitsDirectories, TreeOfContent } from \"@c-rex/interfaces\";\nimport { call } from \"./utils\";\n\ntype ReturnType = {\n rootNode: DirectoryNodes | null,\n result: TreeOfContent[],\n}\n\n/**\n * Generates a hierarchical tree of content from directory nodes.\n * @param directoryNodes - Array of DirectoryNodes to build the tree from\n * @returns A Promise resolving to an object containing the root node and the resulting tree structure\n */\nexport const generateTreeOfContent = async (directoryNodes: DirectoryNodes[]): Promise<ReturnType> => {\n if (directoryNodes.length == 0 || directoryNodes[0] == undefined) {\n return { rootNode: null, result: [] };\n }\n\n let id = directoryNodes[0].shortId;\n let response = await call<DirectoryNodes>(\"DirectoryNodesService.getItem\", id);\n\n const childList = await getChildrenInfo(response.childNodes);\n\n let result: TreeOfContent[] = childList;\n\n while (response.parents != undefined) {\n\n const hasInfo = (response.informationUnits != undefined) && (response.informationUnits[0] != undefined);\n const hasLabel = (response.labels != undefined) && (response.labels[0] != undefined);\n const hasParent = (response.parents != undefined) && (response.parents[0] != undefined);\n if (!hasInfo || !hasLabel || !hasParent) {\n return { rootNode: null, result: result };\n }\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: `/topics/${infoId}`,\n children: [...result],\n };\n id = response.parents[0].shortId;\n response = await call<DirectoryNodes>(\"DirectoryNodesService.getItem\", id);\n\n const tree = await getChildrenInfo(response.childNodes, aux);\n\n result = [...tree];\n }\n\n return { rootNode: response, result: result };\n};\n\n/**\n * Processes child directory nodes and returns an array of TreeOfContent objects.\n * @param childNodes - Array of information units directories to process\n * @param childItem - Optional TreeOfContent item to include in the result if it matches a child node\n * @returns A Promise resolving to an array of TreeOfContent objects\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 == undefined || item.labels[0] == undefined) break;\n\n const response = await call<DirectoryNodes>(\"DirectoryNodesService.getItem\", item.shortId);\n\n if (response.informationUnits == undefined) break;\n if (response.informationUnits[0] == undefined) break;\n\n const infoId = response.informationUnits[0].shortId;\n\n let resultItem: TreeOfContent = {\n active: false,\n label: item.labels[0].value,\n link: `/topics/${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 return result;\n};\n","import { QueryParams } from '@c-rex/types';\n\n/**\n * Creates an array of parameter objects from a list of field values.\n * @param fieldsList - Array of field values to transform into parameter objects\n * @param key - The key to use for each parameter object (defaults to \"Fields\")\n * @returns An array of objects with key-value pairs\n */\nexport const createParams = (fieldsList: string[], key: string = \"Fields\") =>\n fieldsList.map((item) => ({\n key: key,\n value: item,\n }));\n\n/**\n * Generates a URL query string from an array of parameter objects.\n * @param params - Array of QueryParams objects containing key-value pairs\n * @returns A URL-encoded query string\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","import { CREX_TOKEN_HEADER_KEY } from \"@c-rex/constants\";\nimport { getCookie } from \"./memory\";\nimport { call } from \"./utils\";\n\nconst updateToken = async (): Promise<string | null> => {\n try {\n const response = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/api/token`, {\n method: 'POST',\n credentials: 'include',\n });\n\n const cookies = response.headers.get(\"set-cookie\");\n if (cookies === null) return null\n\n const aux = cookies.split(`${CREX_TOKEN_HEADER_KEY}=`);\n if (aux.length == 0) return null\n\n const token = aux[1].split(\";\")[0];\n if (token === undefined) throw new Error(\"Token is undefined\");\n\n return token;\n } catch (error) {\n call(\"CrexLogger.log\", {\n level: \"error\",\n message: `utils.updateToken error: ${error}`\n });\n return null\n }\n}\n\nexport const manageToken = async (): Promise<string | null> => {\n try {\n\n const hasToken = await getCookie(CREX_TOKEN_HEADER_KEY);\n let token = hasToken.value!;\n\n if (hasToken.value === null) {\n const tokenResult = await updateToken();\n\n if (tokenResult === null) throw new Error(\"Token is undefined\");\n\n token = tokenResult;\n }\n\n return token;\n } catch (error) {\n call(\"CrexLogger.log\", {\n level: \"error\",\n message: `utils.manageToken error: ${error}`\n });\n\n return null\n }\n}"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;AC4CO,IAAM,gBAAgB;AAAA,EACzB,MAAM;AAAA,EACN,MAAM;AACV;AA0BO,IAAM,uBAAuB,IAAI,KAAK,KAAK,KAAK;AAQhD,IAAM,wBAAwB;;;ACzE9B,IAAM,OAAO,OAAmB,QAAgB,WAA6B;AAChF,MAAI;AACA,UAAM,MAAM,MAAM,MAAM,GAAG,QAAQ,IAAI,mBAAmB,YAAY;AAAA,MAClE,QAAQ;AAAA,MACR,SAAS,EAAE,gBAAgB,mBAAmB;AAAA,MAC9C,MAAM,KAAK,UAAU,EAAE,QAAQ,OAAO,CAAC;AAAA,MACvC,aAAa;AAAA,IACjB,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;AAEZ,YAAQ,MAAM,KAAK;AACnB,WAAO;AAAA,EACX;AACJ;AAOO,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;AAEO,IAAM,sBAAsB,CAAC,cAAsB,QAAwB;AAC9E,QAAM,UAAU,aAAa,MAAM,GAAG;AAEtC,aAAW,UAAU,SAAS;AAC1B,UAAM,CAAC,WAAW,WAAW,IAAI,OAAO,KAAK,EAAE,MAAM,GAAG;AA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AAc,YAAoC;AAC3D,MAAI;AAEA,UAAM,WAAW,MAAM,UAAU,qBAAqB;AACtD,QAAI,QAAQ,SAAS;AAErB,QAAI,SAAS,UAAU,MAAM;AACzB,YAAM,cAAc,MAAM,YAAY;AAEtC,UAAI,gBAAgB,KAAM,OAAM,IAAI,MAAM,oBAAoB;AAE9D,cAAQ;AAAA,IACZ;AAEA,WAAO;AAAA,EACX,SAAS,OAAO;AACZ,SAAK,kBAAkB;AAAA,MACnB,OAAO;AAAA,MACP,SAAS,4BAA4B,KAAK;AAAA,IAC9C,CAAC;AAED,WAAO;AAAA,EACX;AACJ;","names":[]}
package/dist/index.mjs CHANGED
@@ -3,6 +3,8 @@ var FLAGS_BY_LANG = {
3
3
  "en": "US",
4
4
  "de": "DE"
5
5
  };
6
+ var DEFAULT_COOKIE_LIMIT = 7 * 24 * 60 * 60 * 1e3;
7
+ var CREX_TOKEN_HEADER_KEY = "crex-token";
6
8
 
7
9
  // src/utils.ts
8
10
  var call = async (method, params) => {
@@ -10,7 +12,8 @@ var call = async (method, params) => {
10
12
  const res = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/api/rpc`, {
11
13
  method: "POST",
12
14
  headers: { "Content-Type": "application/json" },
13
- body: JSON.stringify({ method, params })
15
+ body: JSON.stringify({ method, params }),
16
+ credentials: "include"
14
17
  });
15
18
  const json = await res.json();
16
19
  if (!res.ok) throw new Error(json.error || "Unknown error");
@@ -28,25 +31,47 @@ var getCountryCodeByLang = (lang) => {
28
31
  const country = FLAGS_BY_LANG[lang];
29
32
  return country;
30
33
  };
34
+ var getFromCookieString = (cookieString, key) => {
35
+ const cookies = cookieString.split(";");
36
+ for (const cookie of cookies) {
37
+ const [cookieKey, cookieValue] = cookie.trim().split("=");
38
+ if (cookieKey === key) {
39
+ return cookieValue;
40
+ }
41
+ }
42
+ return "";
43
+ };
31
44
 
32
45
  // 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;
46
+ var getCookie = async (key) => {
47
+ const res = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/api/cookies?key=${key}`);
48
+ if (!res.ok) {
49
+ return { key, value: null };
40
50
  }
41
- const globalConfig = global[key];
42
- if (globalConfig === null) {
43
- global[key] = value;
51
+ const json = await res.json();
52
+ return json;
53
+ };
54
+ var setCookie = async (key, value, maxAge) => {
55
+ try {
56
+ if (maxAge === void 0) {
57
+ maxAge = DEFAULT_COOKIE_LIMIT;
58
+ }
59
+ await fetch(`${process.env.NEXT_PUBLIC_API_URL}/api/cookies`, {
60
+ method: "POST",
61
+ credentials: "include",
62
+ body: JSON.stringify({
63
+ key,
64
+ value,
65
+ maxAge
66
+ })
67
+ });
68
+ } catch (error) {
69
+ call("CrexLogger.log", {
70
+ level: "error",
71
+ message: `utils.setCookie error: ${error}`
72
+ });
44
73
  }
45
- }
46
- function getFromMemory(key) {
47
- if (isBrowser()) throw new Error("getFromMemory is not supported in browser");
48
- return global[key];
49
- }
74
+ };
50
75
 
51
76
  // src/breadcrumbs.ts
52
77
  var generateBreadcrumbItems = (treeOfContent) => {
@@ -68,44 +93,49 @@ function cn(...inputs) {
68
93
  }
69
94
 
70
95
  // src/treeOfContent.ts
71
- import { DirectoryNodesService } from "@c-rex/services";
72
96
  var generateTreeOfContent = async (directoryNodes) => {
73
- const service = new DirectoryNodesService();
74
- if (directoryNodes.length == 0) return [];
75
- if (directoryNodes[0] == void 0) return [];
97
+ if (directoryNodes.length == 0 || directoryNodes[0] == void 0) {
98
+ return { rootNode: null, result: [] };
99
+ }
76
100
  let id = directoryNodes[0].shortId;
77
- let response = await service.getItem(id);
101
+ let response = await call("DirectoryNodesService.getItem", id);
78
102
  const childList = await getChildrenInfo(response.childNodes);
79
103
  let result = childList;
80
104
  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;
105
+ const hasInfo = response.informationUnits != void 0 && response.informationUnits[0] != void 0;
106
+ const hasLabel = response.labels != void 0 && response.labels[0] != void 0;
107
+ const hasParent = response.parents != void 0 && response.parents[0] != void 0;
108
+ if (!hasInfo || !hasLabel || !hasParent) {
109
+ return { rootNode: null, result };
110
+ }
84
111
  const infoId = response.informationUnits[0].shortId;
85
112
  const aux = {
86
113
  active: true,
87
114
  label: response.labels[0].value,
88
115
  id: response.shortId,
89
- link: `/info/${infoId}`,
116
+ link: `/topics/${infoId}`,
90
117
  children: [...result]
91
118
  };
92
119
  id = response.parents[0].shortId;
93
- response = await service.getItem(id);
120
+ response = await call("DirectoryNodesService.getItem", id);
94
121
  const tree = await getChildrenInfo(response.childNodes, aux);
95
122
  result = [...tree];
96
123
  }
97
- return result;
124
+ return { rootNode: response, result };
98
125
  };
99
126
  var getChildrenInfo = async (childNodes, childItem) => {
100
127
  const result = [];
101
128
  if (childNodes == void 0) return result;
102
129
  for (const item of childNodes) {
103
- if (item.labels[0] == void 0) break;
104
- const infoId = await getLink(item.shortId);
130
+ if (item.labels == void 0 || item.labels[0] == void 0) break;
131
+ const response = await call("DirectoryNodesService.getItem", item.shortId);
132
+ if (response.informationUnits == void 0) break;
133
+ if (response.informationUnits[0] == void 0) break;
134
+ const infoId = response.informationUnits[0].shortId;
105
135
  let resultItem = {
106
136
  active: false,
107
137
  label: item.labels[0].value,
108
- link: `/info/${infoId}`,
138
+ link: `/topics/${infoId}`,
109
139
  id: item.shortId,
110
140
  children: []
111
141
  };
@@ -116,13 +146,6 @@ var getChildrenInfo = async (childNodes, childItem) => {
116
146
  }
117
147
  return result;
118
148
  };
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
149
 
127
150
  // src/params.ts
128
151
  var createParams = (fieldsList, key = "Fields") => fieldsList.map((item) => ({
@@ -136,64 +159,45 @@ var generateQueryParams = (params) => {
136
159
  return queryParams;
137
160
  };
138
161
 
139
- // src/articles.ts
140
- import { InformationUnitsService, RenditionsService } from "@c-rex/services";
141
- var loadArticleData = async (id) => {
142
- const renditionService = new RenditionsService();
143
- const informationService = new InformationUnitsService();
144
- const informationUnitsItem = await informationService.getItem({ id });
145
- let title = "";
146
- let versionOf = "";
147
- let documentURL = "";
148
- let htmlContent = "";
149
- let treeOfContent = [];
150
- let breadcrumbItems = [];
151
- let availableVersions = [];
152
- if (informationUnitsItem != null) {
153
- if (informationUnitsItem.versionOf != void 0) {
154
- versionOf = informationUnitsItem.versionOf.shortId;
155
- }
156
- if (informationUnitsItem.titles != void 0 && informationUnitsItem.titles[0] != void 0) {
157
- title = informationUnitsItem.titles[0].value;
158
- }
159
- }
160
- if (versionOf != void 0) {
161
- const versions = await informationService.getList({
162
- filters: [`versionOf.shortId=${versionOf}`],
163
- fields: ["labels"]
162
+ // src/token.ts
163
+ var updateToken = async () => {
164
+ try {
165
+ const response = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/api/token`, {
166
+ method: "POST",
167
+ credentials: "include"
164
168
  });
165
- availableVersions = versions.items.map((item) => {
166
- return {
167
- shortId: item.shortId,
168
- lang: item.labels[0]?.language,
169
- country: item.labels[0]?.language.split("-")[1]
170
- };
171
- }).sort((a, b) => {
172
- if (a.lang < b.lang) {
173
- return -1;
174
- }
175
- if (a.lang > b.lang) {
176
- return 1;
177
- }
178
- return 0;
169
+ const cookies = response.headers.get("set-cookie");
170
+ if (cookies === null) return null;
171
+ const aux = cookies.split(`${CREX_TOKEN_HEADER_KEY}=`);
172
+ if (aux.length == 0) return null;
173
+ const token = aux[1].split(";")[0];
174
+ if (token === void 0) throw new Error("Token is undefined");
175
+ return token;
176
+ } catch (error) {
177
+ call("CrexLogger.log", {
178
+ level: "error",
179
+ message: `utils.updateToken error: ${error}`
179
180
  });
181
+ return null;
180
182
  }
181
- if (informationUnitsItem?.renditions != void 0) {
182
- htmlContent = await renditionService.getHTMLRendition(informationUnitsItem.renditions);
183
- documentURL = await renditionService.getDocumentRendition(informationUnitsItem.renditions, "pdf");
184
- if (informationUnitsItem?.directoryNodes != void 0) {
185
- treeOfContent = await generateTreeOfContent(informationUnitsItem.directoryNodes);
186
- breadcrumbItems = generateBreadcrumbItems(treeOfContent);
183
+ };
184
+ var manageToken = async () => {
185
+ try {
186
+ const hasToken = await getCookie(CREX_TOKEN_HEADER_KEY);
187
+ let token = hasToken.value;
188
+ if (hasToken.value === null) {
189
+ const tokenResult = await updateToken();
190
+ if (tokenResult === null) throw new Error("Token is undefined");
191
+ token = tokenResult;
187
192
  }
193
+ return token;
194
+ } catch (error) {
195
+ call("CrexLogger.log", {
196
+ level: "error",
197
+ message: `utils.manageToken error: ${error}`
198
+ });
199
+ return null;
188
200
  }
189
- return {
190
- htmlContent,
191
- treeOfContent,
192
- breadcrumbItems,
193
- availableVersions,
194
- documentURL,
195
- title
196
- };
197
201
  };
198
202
  export {
199
203
  call,
@@ -202,10 +206,10 @@ export {
202
206
  generateBreadcrumbItems,
203
207
  generateQueryParams,
204
208
  generateTreeOfContent,
209
+ getCookie,
205
210
  getCountryCodeByLang,
206
- getFromMemory,
207
- isBrowser,
208
- loadArticleData,
209
- saveInMemory
211
+ getFromCookieString,
212
+ manageToken,
213
+ setCookie
210
214
  };
211
215
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
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","../src/articles.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 RESULT_VIEW_STYLES = [\n \"cards\",\n \"table\",\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 AVAILABLE_CONTENT_LANG_KEY = \"AVAILABLE_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\";\n\nexport const UI_LANG_OPTIONS = [\"en\", \"de\"];\n\nexport const RESULT_TYPES = {\n TOPIC: \"TOPIC\",\n DOCUMENT: \"DOCUMENT\",\n PACKAGE: \"PACKAGE\",\n} as const;","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(`${process.env.NEXT_PUBLIC_API_URL}/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","import { InformationUnitsService, RenditionsService } from \"@c-rex/services\";\nimport { generateBreadcrumbItems, generateTreeOfContent } from \"@c-rex/utils\";\nimport { SidebarAvailableVersionsInterface, TreeOfContent } from \"@c-rex/interfaces\";\n\nexport const loadArticleData = async (id: string) => {\n const renditionService = new RenditionsService();\n const informationService = new InformationUnitsService();\n const informationUnitsItem = await informationService.getItem({ id });\n\n let title = \"\";\n let versionOf = \"\";\n let documentURL = \"\";\n let htmlContent = \"\";\n let treeOfContent: TreeOfContent[] = [];\n let breadcrumbItems: TreeOfContent[] = [];\n let availableVersions: Omit<SidebarAvailableVersionsInterface, \"link\">[] = [];\n\n if (informationUnitsItem != null) {\n if (informationUnitsItem.versionOf != undefined) {\n versionOf = informationUnitsItem.versionOf.shortId\n }\n if (informationUnitsItem.titles != undefined && informationUnitsItem.titles[0] != undefined) {\n title = informationUnitsItem.titles[0].value\n }\n }\n\n if (versionOf != undefined) {\n const versions = await informationService.getList({\n filters: [`versionOf.shortId=${versionOf}`],\n fields: [\"labels\"],\n })\n\n availableVersions = versions.items.map((item) => {\n return {\n shortId: item.shortId,\n lang: item.labels[0]?.language as string,\n country: item.labels[0]?.language.split(\"-\")[1] as string,\n }\n }).sort((a, b) => {\n if (a.lang < b.lang) {\n return -1;\n }\n if (a.lang > b.lang) {\n return 1;\n }\n return 0;\n })\n }\n\n if (informationUnitsItem?.renditions != undefined) {\n htmlContent = await renditionService.getHTMLRendition(informationUnitsItem.renditions)\n documentURL = await renditionService.getDocumentRendition(informationUnitsItem.renditions, \"pdf\")\n\n if (informationUnitsItem?.directoryNodes != undefined) {\n treeOfContent = await generateTreeOfContent(informationUnitsItem.directoryNodes);\n breadcrumbItems = generateBreadcrumbItems(treeOfContent);\n }\n }\n\n return {\n htmlContent,\n treeOfContent,\n breadcrumbItems,\n availableVersions,\n documentURL,\n title\n }\n};"],"mappings":";AA4CO,IAAM,gBAAgB;AAAA,EACzB,MAAM;AAAA,EACN,MAAM;AACV;;;AC7CO,IAAM,OAAO,OAAmB,QAAgB,WAA6B;AAChF,MAAI;AACA,UAAM,MAAM,MAAM,MAAM,GAAG,QAAQ,IAAI,mBAAmB,YAAY;AAAA,MAClE,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,SA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G,SAAS,MAAM,GAAG,EAAE,CAAC;AAAA,MAClD;AAAA,IACJ,CAAC,EAAE,KAAK,CAAC,GAAG,MAAM;AACd,UAAI,EAAE,OAAO,EAAE,MAAM;AACjB,eAAO;AAAA,MACX;AACA,UAAI,EAAE,OAAO,EAAE,MAAM;AACjB,eAAO;AAAA,MACX;AACA,aAAO;AAAA,IACX,CAAC;AAAA,EACL;AAEA,MAAI,sBAAsB,cAAc,QAAW;AAC/C,kBAAc,MAAM,iBAAiB,iBAAiB,qBAAqB,UAAU;AACrF,kBAAc,MAAM,iBAAiB,qBAAqB,qBAAqB,YAAY,KAAK;AAEhG,QAAI,sBAAsB,kBAAkB,QAAW;AACnD,sBAAgB,MAAM,sBAAsB,qBAAqB,cAAc;AAC/E,wBAAkB,wBAAwB,aAAa;AAAA,IAC3D;AAAA,EACJ;AAEA,SAAO;AAAA,IACH;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACJ;AACJ;","names":[]}
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","../src/token.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 RESULT_VIEW_STYLES = [\n \"cards\",\n \"table\",\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 AVAILABLE_CONTENT_LANG_KEY = \"AVAILABLE_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_LANG = \"en-US\";\n\nexport const EN_LANG = \"en\";\n\nexport const UI_LANG_OPTIONS = [\"en-us\", \"de-de\"];\n\nexport const TOPICS_TYPE_AND_LINK = \"topics\";\nexport const DOCUMENTS_TYPE_AND_LINK = \"documents\";\n\nexport const TOPIC = \"TOPIC\";\nexport const DOCUMENT = \"DOCUMENT\";\nexport const PACKAGE = \"PACKAGE\";\n\nexport const RESULT_TYPES = {\n TOPIC: TOPIC,\n DOCUMENT: DOCUMENT,\n PACKAGE: PACKAGE,\n} as const;\n\nexport const FILES_EXTENSIONS = {\n PDF: \"application/pdf\",\n HTML: \"text/html\",\n} as const;\n\nexport const DEFAULT_COOKIE_LIMIT = 7 * 24 * 60 * 60 * 1000; // 7 days in milliseconds\n\nexport const ICONS_BY_FILE_EXTENSION = {\n \"application/pdf\": \"FaFilePdf\",\n} as const;\n\nexport const DEFAULT_ICON = \"file\";\n\nexport const CREX_TOKEN_HEADER_KEY = \"crex-token\";","import { FLAGS_BY_LANG } from \"@c-rex/constants\";\n\n/**\n * Makes an asynchronous RPC API call to the server.\n * @param method - The RPC method name to call\n * @param params - Optional parameters to pass to the method\n * @returns A Promise resolving to the response data of type T, or null if an error occurs\n */\nexport const call = async<T = unknown>(method: string, params?: any): Promise<T> => {\n try {\n const res = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/api/rpc`, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({ method, params }),\n credentials: 'include',\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 //TODO: add logger\n console.error(error);\n return null as T;\n }\n}\n\n/**\n * Retrieves the country code associated with a given language code.\n * @param lang - The language code to look up (e.g., \"en-US\")\n * @returns The corresponding country code, or the original language code if not found\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}\n\nexport const getFromCookieString = (cookieString: string, key: string): string => {\n const cookies = cookieString.split(';')\n\n for (const cookie of cookies) {\n const [cookieKey, cookieValue] = cookie.trim().split('=')\n\n if (cookieKey === key) {\n return cookieValue as string;\n }\n }\n\n return ''\n}\n","import { DEFAULT_COOKIE_LIMIT } from \"@c-rex/constants\";\nimport { call } from \"./utils\";\n\n/**\n * Fetches a cookie value from the server API in client-side code.\n * @param key - The key of the cookie to retrieve\n * @returns A Promise resolving to an object containing the key and value of the cookie\n */\nexport const getCookie = async (key: string): Promise<{ key: string, value: string | null }> => {\n const res = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/api/cookies?key=${key}`);\n\n if (!res.ok) {\n return { key: key, value: null };\n }\n const json = await res.json();\n\n return json;\n}\n\n/**\n * Sets a cookie value through the server API in client-side code.\n * @param key - The key of the cookie to set\n * @param value - The value to store in the cookie\n * @param maxAge - Optional maximum age of the cookie in seconds. Defaults to DEFAULT_COOKIE_LIMIT if not specified.\n * @returns A Promise that resolves when the cookie has been set\n */\nexport const setCookie = async (key: string, value: string, maxAge?: number): Promise<void> => {\n try {\n\n if (maxAge === undefined) {\n maxAge = DEFAULT_COOKIE_LIMIT;\n }\n\n await fetch(`${process.env.NEXT_PUBLIC_API_URL}/api/cookies`, {\n method: 'POST',\n credentials: 'include',\n body: JSON.stringify({\n key: key,\n value: value,\n maxAge: maxAge,\n }),\n });\n } catch (error) {\n call(\"CrexLogger.log\", {\n level: \"error\",\n message: `utils.setCookie error: ${error}`\n });\n }\n}\n\n","import { TreeOfContent } from \"@c-rex/interfaces\";\n\n/**\n * Generates breadcrumb items by recursively extracting active items and their active children from a TreeOfContent array.\n * @param treeOfContent - Array of TreeOfContent objects representing the content hierarchy\n * @returns A flattened array of active TreeOfContent items to be used as breadcrumbs\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\n/**\n * Merges multiple class values into a single string using clsx and tailwind-merge.\n * Useful for conditionally applying Tailwind CSS classes.\n * @param inputs - Any number of class values (strings, objects, arrays, etc.)\n * @returns A merged string of class names optimized for Tailwind CSS\n */\nexport function cn(...inputs: ClassValue[]) {\n return twMerge(clsx(inputs));\n}\n","import { DirectoryNodes, informationUnitsDirectories, TreeOfContent } from \"@c-rex/interfaces\";\nimport { call } from \"./utils\";\n\ntype ReturnType = {\n rootNode: DirectoryNodes | null,\n result: TreeOfContent[],\n}\n\n/**\n * Generates a hierarchical tree of content from directory nodes.\n * @param directoryNodes - Array of DirectoryNodes to build the tree from\n * @returns A Promise resolving to an object containing the root node and the resulting tree structure\n */\nexport const generateTreeOfContent = async (directoryNodes: DirectoryNodes[]): Promise<ReturnType> => {\n if (directoryNodes.length == 0 || directoryNodes[0] == undefined) {\n return { rootNode: null, result: [] };\n }\n\n let id = directoryNodes[0].shortId;\n let response = await call<DirectoryNodes>(\"DirectoryNodesService.getItem\", id);\n\n const childList = await getChildrenInfo(response.childNodes);\n\n let result: TreeOfContent[] = childList;\n\n while (response.parents != undefined) {\n\n const hasInfo = (response.informationUnits != undefined) && (response.informationUnits[0] != undefined);\n const hasLabel = (response.labels != undefined) && (response.labels[0] != undefined);\n const hasParent = (response.parents != undefined) && (response.parents[0] != undefined);\n if (!hasInfo || !hasLabel || !hasParent) {\n return { rootNode: null, result: result };\n }\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: `/topics/${infoId}`,\n children: [...result],\n };\n id = response.parents[0].shortId;\n response = await call<DirectoryNodes>(\"DirectoryNodesService.getItem\", id);\n\n const tree = await getChildrenInfo(response.childNodes, aux);\n\n result = [...tree];\n }\n\n return { rootNode: response, result: result };\n};\n\n/**\n * Processes child directory nodes and returns an array of TreeOfContent objects.\n * @param childNodes - Array of information units directories to process\n * @param childItem - Optional TreeOfContent item to include in the result if it matches a child node\n * @returns A Promise resolving to an array of TreeOfContent objects\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 == undefined || item.labels[0] == undefined) break;\n\n const response = await call<DirectoryNodes>(\"DirectoryNodesService.getItem\", item.shortId);\n\n if (response.informationUnits == undefined) break;\n if (response.informationUnits[0] == undefined) break;\n\n const infoId = response.informationUnits[0].shortId;\n\n let resultItem: TreeOfContent = {\n active: false,\n label: item.labels[0].value,\n link: `/topics/${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 return result;\n};\n","import { QueryParams } from '@c-rex/types';\n\n/**\n * Creates an array of parameter objects from a list of field values.\n * @param fieldsList - Array of field values to transform into parameter objects\n * @param key - The key to use for each parameter object (defaults to \"Fields\")\n * @returns An array of objects with key-value pairs\n */\nexport const createParams = (fieldsList: string[], key: string = \"Fields\") =>\n fieldsList.map((item) => ({\n key: key,\n value: item,\n }));\n\n/**\n * Generates a URL query string from an array of parameter objects.\n * @param params - Array of QueryParams objects containing key-value pairs\n * @returns A URL-encoded query string\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","import { CREX_TOKEN_HEADER_KEY } from \"@c-rex/constants\";\nimport { getCookie } from \"./memory\";\nimport { call } from \"./utils\";\n\nconst updateToken = async (): Promise<string | null> => {\n try {\n const response = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/api/token`, {\n method: 'POST',\n credentials: 'include',\n });\n\n const cookies = response.headers.get(\"set-cookie\");\n if (cookies === null) return null\n\n const aux = cookies.split(`${CREX_TOKEN_HEADER_KEY}=`);\n if (aux.length == 0) return null\n\n const token = aux[1].split(\";\")[0];\n if (token === undefined) throw new Error(\"Token is undefined\");\n\n return token;\n } catch (error) {\n call(\"CrexLogger.log\", {\n level: \"error\",\n message: `utils.updateToken error: ${error}`\n });\n return null\n }\n}\n\nexport const manageToken = async (): Promise<string | null> => {\n try {\n\n const hasToken = await getCookie(CREX_TOKEN_HEADER_KEY);\n let token = hasToken.value!;\n\n if (hasToken.value === null) {\n const tokenResult = await updateToken();\n\n if (tokenResult === null) throw new Error(\"Token is undefined\");\n\n token = tokenResult;\n }\n\n return token;\n } catch (error) {\n call(\"CrexLogger.log\", {\n level: \"error\",\n message: `utils.manageToken error: ${error}`\n });\n\n return null\n }\n}"],"mappings":";AA4CO,IAAM,gBAAgB;AAAA,EACzB,MAAM;AAAA,EACN,MAAM;AACV;AA0BO,IAAM,uBAAuB,IAAI,KAAK,KAAK,KAAK;AAQhD,IAAM,wBAAwB;;;ACzE9B,IAAM,OAAO,OAAmB,QAAgB,WAA6B;AAChF,MAAI;AACA,UAAM,MAAM,MAAM,MAAM,GAAG,QAAQ,IAAI,mBAAmB,YAAY;AAAA,MAClE,QAAQ;AAAA,MACR,SAAS,EAAE,gBAAgB,mBAAmB;AAAA,MAC9C,MAAM,KAAK,UAAU,EAAE,QAAQ,OAAO,CAAC;AAAA,MACvC,aAAa;AAAA,IACjB,CAAC;AAED,UAAM,OAAO,MAAM,IAAI,KAAK;AAE5B,QAAI,CAAC,IAAI,GAAI,OAAM,IAAI,MAAM,KAAK,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;AAAA,MACR,aAAa;AAAA,IACjB,CAAC;AAED,UAAM,UAAU,SAAS,QAAQ,IAAI,YAAY;AACjD,QAAI,YAAY,KAAM,QAAO;AAE7B,UAAM,MAAM,QAAQ,MAAM,GAAG,qBAAqB,GAAG;AACrD,QAAI,IAAI,UAAU,EAAG,QAAO;AAE5B,UAAM,QAAQ,IAAI,CAAC,EAAE,MAAM,GAAG,EAAE,CAAC;AACjC,QAAI,UAAU,OAAW,OAAM,IAAI,MAAM,oBAAoB;AAE7D,WAAO;AAAA,EACX,SAAS,OAAO;AACZ,SAAK,kBAAkB;AAAA,MACnB,OAAO;AAAA,MACP,SAAS,4BAA4B,KAAK;AAAA,IAC9C,CAAC;AACD,WAAO;AAAA,EACX;AACJ;AAEO,IAAM,cAAc,YAAoC;AAC3D,MAAI;AAEA,UAAM,WAAW,MAAM,UAAU,qBAAqB;AACtD,QAAI,QAAQ,SAAS;AAErB,QAAI,SAAS,UAAU,MAAM;AACzB,YAAM,cAAc,MAAM,YAAY;AAEtC,UAAI,gBAAgB,KAAM,OAAM,IAAI,MAAM,oBAAoB;AAE9D,cAAQ;AAAA,IACZ;AAEA,WAAO;AAAA,EACX,SAAS,OAAO;AACZ,SAAK,kBAAkB;AAAA,MACnB,OAAO;AAAA,MACP,SAAS,4BAA4B,KAAK;AAAA,IAC9C,CAAC;AAED,WAAO;AAAA,EACX;AACJ;","names":[]}
@@ -1,7 +1,10 @@
1
1
  import { ConfigInterface } from '@c-rex/interfaces';
2
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>;
3
+ /**
4
+ * Retrieves and parses configuration data from a cookie.
5
+ * @returns The parsed configuration object
6
+ * @throws Error if the configuration cookie is not found or cannot be parsed
7
+ */
8
+ declare const getConfigs: () => ConfigInterface;
6
9
 
7
- export { getConfigs, getCookie, setCookie };
10
+ export { getConfigs };
@@ -1,7 +1,10 @@
1
1
  import { ConfigInterface } from '@c-rex/interfaces';
2
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>;
3
+ /**
4
+ * Retrieves and parses configuration data from a cookie.
5
+ * @returns The parsed configuration object
6
+ * @throws Error if the configuration cookie is not found or cannot be parsed
7
+ */
8
+ declare const getConfigs: () => ConfigInterface;
6
9
 
7
- export { getConfigs, getCookie, setCookie };
10
+ export { getConfigs };
@@ -21,25 +21,18 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  // src/next-cookies.ts
22
22
  var next_cookies_exports = {};
23
23
  __export(next_cookies_exports, {
24
- getConfigs: () => getConfigs,
25
- getCookie: () => getCookie,
26
- setCookie: () => setCookie
24
+ getConfigs: () => getConfigs
27
25
  });
28
26
  module.exports = __toCommonJS(next_cookies_exports);
29
27
 
30
28
  // ../constants/src/index.ts
31
29
  var SDK_CONFIG_KEY = "crex-sdk-config";
30
+ var DEFAULT_COOKIE_LIMIT = 7 * 24 * 60 * 60 * 1e3;
32
31
 
33
32
  // src/next-cookies.ts
34
33
  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);
34
+ var getConfigs = () => {
35
+ const jsonConfigs = (0, import_headers.cookies)().get(SDK_CONFIG_KEY)?.value;
43
36
  if (!jsonConfigs) {
44
37
  throw new Error("Configs not found");
45
38
  }
@@ -48,8 +41,6 @@ var getConfigs = async () => {
48
41
  };
49
42
  // Annotate the CommonJS export names for ESM import in node:
50
43
  0 && (module.exports = {
51
- getConfigs,
52
- getCookie,
53
- setCookie
44
+ getConfigs
54
45
  });
55
46
  //# sourceMappingURL=next-cookies.js.map
@@ -1 +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 RESULT_VIEW_STYLES = [\n \"cards\",\n \"table\",\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 AVAILABLE_CONTENT_LANG_KEY = \"AVAILABLE_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\";\n\nexport const UI_LANG_OPTIONS = [\"en\", \"de\"];\n\nexport const RESULT_TYPES = {\n TOPIC: \"TOPIC\",\n DOCUMENT: \"DOCUMENT\",\n PACKAGE: \"PACKAGE\",\n} as const;"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACoCO,IAAM,iBAAiB;;;ADhC9B,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":[]}
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\n/**\n * Retrieves and parses configuration data from a cookie.\n * @returns The parsed configuration object\n * @throws Error if the configuration cookie is not found or cannot be parsed\n */\nexport const getConfigs = (): ConfigInterface => {\n const jsonConfigs = cookies().get(SDK_CONFIG_KEY)?.value;\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 RESULT_VIEW_STYLES = [\n \"cards\",\n \"table\",\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 AVAILABLE_CONTENT_LANG_KEY = \"AVAILABLE_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_LANG = \"en-US\";\n\nexport const EN_LANG = \"en\";\n\nexport const UI_LANG_OPTIONS = [\"en-us\", \"de-de\"];\n\nexport const TOPICS_TYPE_AND_LINK = \"topics\";\nexport const DOCUMENTS_TYPE_AND_LINK = \"documents\";\n\nexport const TOPIC = \"TOPIC\";\nexport const DOCUMENT = \"DOCUMENT\";\nexport const PACKAGE = \"PACKAGE\";\n\nexport const RESULT_TYPES = {\n TOPIC: TOPIC,\n DOCUMENT: DOCUMENT,\n PACKAGE: PACKAGE,\n} as const;\n\nexport const FILES_EXTENSIONS = {\n PDF: \"application/pdf\",\n HTML: \"text/html\",\n} as const;\n\nexport const DEFAULT_COOKIE_LIMIT = 7 * 24 * 60 * 60 * 1000; // 7 days in milliseconds\n\nexport const ICONS_BY_FILE_EXTENSION = {\n \"application/pdf\": \"FaFilePdf\",\n} as const;\n\nexport const DEFAULT_ICON = \"file\";\n\nexport const CREX_TOKEN_HEADER_KEY = \"crex-token\";"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACoCO,IAAM,iBAAiB;AAqCvB,IAAM,uBAAuB,IAAI,KAAK,KAAK,KAAK;;;ADrEvD,qBAAwB;AAOjB,IAAM,aAAa,MAAuB;AAC7C,QAAM,kBAAc,wBAAQ,EAAE,IAAI,cAAc,GAAG;AACnD,MAAI,CAAC,aAAa;AACd,UAAM,IAAI,MAAM,mBAAmB;AAAA,EACvC;AAEA,QAAM,UAA2B,KAAK,MAAM,WAAW;AAEvD,SAAO;AACX;","names":[]}
@@ -2,17 +2,12 @@
2
2
 
3
3
  // ../constants/src/index.ts
4
4
  var SDK_CONFIG_KEY = "crex-sdk-config";
5
+ var DEFAULT_COOKIE_LIMIT = 7 * 24 * 60 * 60 * 1e3;
5
6
 
6
7
  // src/next-cookies.ts
7
8
  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);
9
+ var getConfigs = () => {
10
+ const jsonConfigs = cookies().get(SDK_CONFIG_KEY)?.value;
16
11
  if (!jsonConfigs) {
17
12
  throw new Error("Configs not found");
18
13
  }
@@ -20,8 +15,6 @@ var getConfigs = async () => {
20
15
  return configs;
21
16
  };
22
17
  export {
23
- getConfigs,
24
- getCookie,
25
- setCookie
18
+ getConfigs
26
19
  };
27
20
  //# sourceMappingURL=next-cookies.mjs.map
@@ -1 +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 RESULT_VIEW_STYLES = [\n \"cards\",\n \"table\",\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 AVAILABLE_CONTENT_LANG_KEY = \"AVAILABLE_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\";\n\nexport const UI_LANG_OPTIONS = [\"en\", \"de\"];\n\nexport const RESULT_TYPES = {\n TOPIC: \"TOPIC\",\n DOCUMENT: \"DOCUMENT\",\n PACKAGE: \"PACKAGE\",\n} as const;","'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":";;;AAoCO,IAAM,iBAAiB;;;AChC9B,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":[]}
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 RESULT_VIEW_STYLES = [\n \"cards\",\n \"table\",\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 AVAILABLE_CONTENT_LANG_KEY = \"AVAILABLE_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_LANG = \"en-US\";\n\nexport const EN_LANG = \"en\";\n\nexport const UI_LANG_OPTIONS = [\"en-us\", \"de-de\"];\n\nexport const TOPICS_TYPE_AND_LINK = \"topics\";\nexport const DOCUMENTS_TYPE_AND_LINK = \"documents\";\n\nexport const TOPIC = \"TOPIC\";\nexport const DOCUMENT = \"DOCUMENT\";\nexport const PACKAGE = \"PACKAGE\";\n\nexport const RESULT_TYPES = {\n TOPIC: TOPIC,\n DOCUMENT: DOCUMENT,\n PACKAGE: PACKAGE,\n} as const;\n\nexport const FILES_EXTENSIONS = {\n PDF: \"application/pdf\",\n HTML: \"text/html\",\n} as const;\n\nexport const DEFAULT_COOKIE_LIMIT = 7 * 24 * 60 * 60 * 1000; // 7 days in milliseconds\n\nexport const ICONS_BY_FILE_EXTENSION = {\n \"application/pdf\": \"FaFilePdf\",\n} as const;\n\nexport const DEFAULT_ICON = \"file\";\n\nexport const CREX_TOKEN_HEADER_KEY = \"crex-token\";","'use server';\n\nimport { SDK_CONFIG_KEY } from '@c-rex/constants';\nimport { ConfigInterface } from '@c-rex/interfaces';\nimport { cookies } from 'next/headers';\n\n/**\n * Retrieves and parses configuration data from a cookie.\n * @returns The parsed configuration object\n * @throws Error if the configuration cookie is not found or cannot be parsed\n */\nexport const getConfigs = (): ConfigInterface => {\n const jsonConfigs = cookies().get(SDK_CONFIG_KEY)?.value;\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":";;;AAoCO,IAAM,iBAAiB;AAqCvB,IAAM,uBAAuB,IAAI,KAAK,KAAK,KAAK;;;ACrEvD,SAAS,eAAe;AAOjB,IAAM,aAAa,MAAuB;AAC7C,QAAM,cAAc,QAAQ,EAAE,IAAI,cAAc,GAAG;AACnD,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,9 +1,6 @@
1
1
  {
2
2
  "name": "@c-rex/utils",
3
- "version": "0.1.2",
4
- "main": "./dist/index.js",
5
- "types": "./dist/index.d.ts",
6
- "module": "./dist/index.mjs",
3
+ "version": "0.1.4",
7
4
  "files": [
8
5
  "dist"
9
6
  ],
@@ -25,7 +22,6 @@
25
22
  "require": "./dist/index.js",
26
23
  "default": "./dist/index.js"
27
24
  },
28
- "./package.json": "./package.json",
29
25
  "./next-cookies": {
30
26
  "types": "./dist/next-cookies.d.ts",
31
27
  "import": "./dist/next-cookies.mjs",