@c-rex/utils 0.1.3 → 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
@@ -15,30 +15,25 @@ declare const call: <T = unknown>(method: string, params?: any) => Promise<T>;
15
15
  * @returns The corresponding country code, or the original language code if not found
16
16
  */
17
17
  declare const getCountryCodeByLang: (lang: string) => string;
18
+ declare const getFromCookieString: (cookieString: string, key: string) => string;
18
19
 
19
- /**
20
- * Saves a value in memory on the server side.
21
- * @param value - The string value to save
22
- * @param key - The key under which to store the value
23
- * @throws Error if called in a browser environment
24
- */
25
- declare function saveInMemory(value: string, key: string): void;
26
- /**
27
- * Retrieves a value from memory on the server side.
28
- * @param key - The key of the value to retrieve
29
- * @returns The stored string value
30
- * @throws Error if called in a browser environment
31
- */
32
- declare function getFromMemory(key: string): string;
33
20
  /**
34
21
  * Fetches a cookie value from the server API in client-side code.
35
22
  * @param key - The key of the cookie to retrieve
36
23
  * @returns A Promise resolving to an object containing the key and value of the cookie
37
24
  */
38
- declare const getCookieInFront: (key: string) => Promise<{
25
+ declare const getCookie: (key: string) => Promise<{
39
26
  key: string;
40
27
  value: string | null;
41
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>;
42
37
 
43
38
  /**
44
39
  * Generates breadcrumb items by recursively extracting active items and their active children from a TreeOfContent array.
@@ -65,12 +60,6 @@ type ReturnType = {
65
60
  * @returns A Promise resolving to an object containing the root node and the resulting tree structure
66
61
  */
67
62
  declare const generateTreeOfContent: (directoryNodes: DirectoryNodes[]) => Promise<ReturnType>;
68
- /**
69
- * Gets the information unit ID from a directory node ID.
70
- * @param directoryNodeID - The ID of the directory node
71
- * @returns A Promise resolving to the information unit ID, or an empty string if not found
72
- */
73
- declare const getLink: (directoryNodeID: string) => Promise<string>;
74
63
 
75
64
  /**
76
65
  * Creates an array of parameter objects from a list of field values.
@@ -89,35 +78,6 @@ declare const createParams: (fieldsList: string[], key?: string) => {
89
78
  */
90
79
  declare const generateQueryParams: (params: QueryParams[]) => string;
91
80
 
92
- /**
93
- * Loads article data including content, tree structure, breadcrumbs, and available versions.
94
- * @param id - The ID of the article to load
95
- * @param type - The type of article ("documents" or "topics", defaults to "documents")
96
- * @returns A Promise resolving to an object containing the article data
97
- */
98
- declare const loadArticleData: (id: string, type?: string) => Promise<{
99
- htmlContent: string;
100
- treeOfContent: TreeOfContent[];
101
- breadcrumbItems: TreeOfContent[];
102
- availableVersions: {
103
- shortId: string;
104
- link: string;
105
- lang: string;
106
- country: string;
107
- active: boolean;
108
- }[];
109
- documents: {
110
- filesToDownload: {
111
- format: string;
112
- link: string;
113
- }[];
114
- filesToOpen: {
115
- format: string;
116
- link: string;
117
- }[];
118
- };
119
- title: string;
120
- articleLanguage: string;
121
- }>;
81
+ declare const manageToken: () => Promise<string | null>;
122
82
 
123
- export { call, cn, createParams, generateBreadcrumbItems, generateQueryParams, generateTreeOfContent, getCookieInFront, getCountryCodeByLang, getFromMemory, getLink, loadArticleData, saveInMemory };
83
+ export { call, cn, createParams, generateBreadcrumbItems, generateQueryParams, generateTreeOfContent, getCookie, getCountryCodeByLang, getFromCookieString, manageToken, setCookie };
package/dist/index.d.ts CHANGED
@@ -15,30 +15,25 @@ declare const call: <T = unknown>(method: string, params?: any) => Promise<T>;
15
15
  * @returns The corresponding country code, or the original language code if not found
16
16
  */
17
17
  declare const getCountryCodeByLang: (lang: string) => string;
18
+ declare const getFromCookieString: (cookieString: string, key: string) => string;
18
19
 
19
- /**
20
- * Saves a value in memory on the server side.
21
- * @param value - The string value to save
22
- * @param key - The key under which to store the value
23
- * @throws Error if called in a browser environment
24
- */
25
- declare function saveInMemory(value: string, key: string): void;
26
- /**
27
- * Retrieves a value from memory on the server side.
28
- * @param key - The key of the value to retrieve
29
- * @returns The stored string value
30
- * @throws Error if called in a browser environment
31
- */
32
- declare function getFromMemory(key: string): string;
33
20
  /**
34
21
  * Fetches a cookie value from the server API in client-side code.
35
22
  * @param key - The key of the cookie to retrieve
36
23
  * @returns A Promise resolving to an object containing the key and value of the cookie
37
24
  */
38
- declare const getCookieInFront: (key: string) => Promise<{
25
+ declare const getCookie: (key: string) => Promise<{
39
26
  key: string;
40
27
  value: string | null;
41
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>;
42
37
 
43
38
  /**
44
39
  * Generates breadcrumb items by recursively extracting active items and their active children from a TreeOfContent array.
@@ -65,12 +60,6 @@ type ReturnType = {
65
60
  * @returns A Promise resolving to an object containing the root node and the resulting tree structure
66
61
  */
67
62
  declare const generateTreeOfContent: (directoryNodes: DirectoryNodes[]) => Promise<ReturnType>;
68
- /**
69
- * Gets the information unit ID from a directory node ID.
70
- * @param directoryNodeID - The ID of the directory node
71
- * @returns A Promise resolving to the information unit ID, or an empty string if not found
72
- */
73
- declare const getLink: (directoryNodeID: string) => Promise<string>;
74
63
 
75
64
  /**
76
65
  * Creates an array of parameter objects from a list of field values.
@@ -89,35 +78,6 @@ declare const createParams: (fieldsList: string[], key?: string) => {
89
78
  */
90
79
  declare const generateQueryParams: (params: QueryParams[]) => string;
91
80
 
92
- /**
93
- * Loads article data including content, tree structure, breadcrumbs, and available versions.
94
- * @param id - The ID of the article to load
95
- * @param type - The type of article ("documents" or "topics", defaults to "documents")
96
- * @returns A Promise resolving to an object containing the article data
97
- */
98
- declare const loadArticleData: (id: string, type?: string) => Promise<{
99
- htmlContent: string;
100
- treeOfContent: TreeOfContent[];
101
- breadcrumbItems: TreeOfContent[];
102
- availableVersions: {
103
- shortId: string;
104
- link: string;
105
- lang: string;
106
- country: string;
107
- active: boolean;
108
- }[];
109
- documents: {
110
- filesToDownload: {
111
- format: string;
112
- link: string;
113
- }[];
114
- filesToOpen: {
115
- format: string;
116
- link: string;
117
- }[];
118
- };
119
- title: string;
120
- articleLanguage: string;
121
- }>;
81
+ declare const manageToken: () => Promise<string | null>;
122
82
 
123
- export { call, cn, createParams, generateBreadcrumbItems, generateQueryParams, generateTreeOfContent, getCookieInFront, getCountryCodeByLang, getFromMemory, getLink, loadArticleData, saveInMemory };
83
+ export { call, cn, createParams, generateBreadcrumbItems, generateQueryParams, generateTreeOfContent, getCookie, getCountryCodeByLang, getFromCookieString, manageToken, setCookie };
package/dist/index.js CHANGED
@@ -26,12 +26,11 @@ __export(index_exports, {
26
26
  generateBreadcrumbItems: () => generateBreadcrumbItems,
27
27
  generateQueryParams: () => generateQueryParams,
28
28
  generateTreeOfContent: () => generateTreeOfContent,
29
- getCookieInFront: () => getCookieInFront,
29
+ getCookie: () => getCookie,
30
30
  getCountryCodeByLang: () => getCountryCodeByLang,
31
- getFromMemory: () => getFromMemory,
32
- getLink: () => getLink,
33
- loadArticleData: () => loadArticleData,
34
- saveInMemory: () => saveInMemory
31
+ getFromCookieString: () => getFromCookieString,
32
+ manageToken: () => manageToken,
33
+ setCookie: () => setCookie
35
34
  });
36
35
  module.exports = __toCommonJS(index_exports);
37
36
 
@@ -41,6 +40,7 @@ var FLAGS_BY_LANG = {
41
40
  "de": "DE"
42
41
  };
43
42
  var DEFAULT_COOKIE_LIMIT = 7 * 24 * 60 * 60 * 1e3;
43
+ var CREX_TOKEN_HEADER_KEY = "crex-token";
44
44
 
45
45
  // src/utils.ts
46
46
  var call = async (method, params) => {
@@ -48,7 +48,8 @@ var call = async (method, params) => {
48
48
  const res = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/api/rpc`, {
49
49
  method: "POST",
50
50
  headers: { "Content-Type": "application/json" },
51
- body: JSON.stringify({ method, params })
51
+ body: JSON.stringify({ method, params }),
52
+ credentials: "include"
52
53
  });
53
54
  const json = await res.json();
54
55
  if (!res.ok) throw new Error(json.error || "Unknown error");
@@ -66,32 +67,47 @@ var getCountryCodeByLang = (lang) => {
66
67
  const country = FLAGS_BY_LANG[lang];
67
68
  return country;
68
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
+ };
69
80
 
70
81
  // src/memory.ts
71
- function isBrowser() {
72
- return typeof window !== "undefined" && typeof document !== "undefined";
73
- }
74
- function saveInMemory(value, key) {
75
- if (isBrowser()) throw new Error("saveInMemory is not supported in browser");
76
- if (typeof global !== "undefined" && !(key in global)) {
77
- global[key] = null;
78
- }
79
- const globalConfig = global[key];
80
- if (globalConfig === null) {
81
- global[key] = value;
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 };
82
86
  }
83
- }
84
- function getFromMemory(key) {
85
- if (isBrowser()) throw new Error("getFromMemory is not supported in browser");
86
- return global[key];
87
- }
88
- var getCookieInFront = async (key) => {
89
- const res = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/api/cookies?key=${key}`, {
90
- cache: "no-store"
91
- });
92
87
  const json = await res.json();
93
88
  return json;
94
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
+ });
109
+ }
110
+ };
95
111
 
96
112
  // src/breadcrumbs.ts
97
113
  var generateBreadcrumbItems = (treeOfContent) => {
@@ -113,14 +129,12 @@ function cn(...inputs) {
113
129
  }
114
130
 
115
131
  // src/treeOfContent.ts
116
- var import_services = require("@c-rex/services");
117
132
  var generateTreeOfContent = async (directoryNodes) => {
118
- const service = new import_services.DirectoryNodesService();
119
133
  if (directoryNodes.length == 0 || directoryNodes[0] == void 0) {
120
134
  return { rootNode: null, result: [] };
121
135
  }
122
136
  let id = directoryNodes[0].shortId;
123
- let response = await service.getItem(id);
137
+ let response = await call("DirectoryNodesService.getItem", id);
124
138
  const childList = await getChildrenInfo(response.childNodes);
125
139
  let result = childList;
126
140
  while (response.parents != void 0) {
@@ -139,7 +153,7 @@ var generateTreeOfContent = async (directoryNodes) => {
139
153
  children: [...result]
140
154
  };
141
155
  id = response.parents[0].shortId;
142
- response = await service.getItem(id);
156
+ response = await call("DirectoryNodesService.getItem", id);
143
157
  const tree = await getChildrenInfo(response.childNodes, aux);
144
158
  result = [...tree];
145
159
  }
@@ -150,7 +164,10 @@ var getChildrenInfo = async (childNodes, childItem) => {
150
164
  if (childNodes == void 0) return result;
151
165
  for (const item of childNodes) {
152
166
  if (item.labels == void 0 || item.labels[0] == void 0) break;
153
- const infoId = await getLink(item.shortId);
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;
154
171
  let resultItem = {
155
172
  active: false,
156
173
  label: item.labels[0].value,
@@ -165,13 +182,6 @@ var getChildrenInfo = async (childNodes, childItem) => {
165
182
  }
166
183
  return result;
167
184
  };
168
- var getLink = async (directoryNodeID) => {
169
- const service = new import_services.DirectoryNodesService();
170
- const response = await service.getItem(directoryNodeID);
171
- if (response.informationUnits == void 0) return "";
172
- if (response.informationUnits[0] == void 0) return "";
173
- return response.informationUnits[0].shortId;
174
- };
175
185
 
176
186
  // src/params.ts
177
187
  var createParams = (fieldsList, key = "Fields") => fieldsList.map((item) => ({
@@ -185,73 +195,45 @@ var generateQueryParams = (params) => {
185
195
  return queryParams;
186
196
  };
187
197
 
188
- // src/articles.ts
189
- var import_services2 = require("@c-rex/services");
190
- var DOCUMENT = "documents";
191
- var TOPIC = "topics";
192
- var loadArticleData = async (id, type = DOCUMENT) => {
193
- const renditionService = new import_services2.RenditionsService();
194
- const informationService = new import_services2.InformationUnitsService();
195
- const informationUnitsItem = await informationService.getItem({ id });
196
- const { rootNode, result: treeOfContent } = await generateTreeOfContent(informationUnitsItem.directoryNodes);
197
- const articleLanguage = informationUnitsItem.languages[0];
198
- const versionOf = informationUnitsItem.versionOf.shortId;
199
- const versions = await informationService.getList({
200
- filters: [`versionOf.shortId=${versionOf}`],
201
- fields: ["renditions", "class", "languages", "labels"]
202
- });
203
- const availableVersions = versions.items.map((item) => {
204
- return {
205
- shortId: item.shortId,
206
- link: `/${type}/${item.shortId}`,
207
- lang: item.language,
208
- country: item.language.split("-")[1],
209
- active: item.language === articleLanguage
210
- };
211
- }).sort((a, b) => {
212
- if (a.lang < b.lang) return -1;
213
- if (a.lang > b.lang) return 1;
214
- return 0;
215
- });
216
- let title = informationUnitsItem.labels[0].value;
217
- let documents = renditionService.getFileRenditions(informationUnitsItem.renditions);
218
- let htmlContent = "";
219
- let rootNodeInfoID = "";
220
- let breadcrumbItems;
221
- if (rootNode != null) {
222
- title = rootNode.informationUnits[0].labels[0].value;
223
- rootNodeInfoID = rootNode.informationUnits[0].shortId;
224
- const childInformationUnit = await informationService.getItem({ id: rootNodeInfoID });
225
- documents = renditionService.getFileRenditions(childInformationUnit.renditions);
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"
204
+ });
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}`
216
+ });
217
+ return null;
226
218
  }
227
- if (type == TOPIC) {
228
- htmlContent = await renditionService.getHTMLRendition(informationUnitsItem.renditions);
229
- breadcrumbItems = generateBreadcrumbItems(treeOfContent);
230
- } else {
231
- if (rootNode != null) {
232
- const directoryId = rootNode.childNodes[0].shortId;
233
- const infoId = await getLink(directoryId);
234
- const childInformationUnit = await informationService.getItem({ id: infoId });
235
- htmlContent = await renditionService.getHTMLRendition(childInformationUnit.renditions);
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;
236
228
  }
237
- treeOfContent[0].active = true;
238
- breadcrumbItems = [{
239
- link: "/",
240
- label: title,
241
- id: "title",
242
- active: false,
243
- children: []
244
- }];
229
+ return token;
230
+ } catch (error) {
231
+ call("CrexLogger.log", {
232
+ level: "error",
233
+ message: `utils.manageToken error: ${error}`
234
+ });
235
+ return null;
245
236
  }
246
- return {
247
- htmlContent,
248
- treeOfContent,
249
- breadcrumbItems,
250
- availableVersions,
251
- documents,
252
- title,
253
- articleLanguage
254
- };
255
237
  };
256
238
  // Annotate the CommonJS export names for ESM import in node:
257
239
  0 && (module.exports = {
@@ -261,11 +243,10 @@ var loadArticleData = async (id, type = DOCUMENT) => {
261
243
  generateBreadcrumbItems,
262
244
  generateQueryParams,
263
245
  generateTreeOfContent,
264
- getCookieInFront,
246
+ getCookie,
265
247
  getCountryCodeByLang,
266
- getFromMemory,
267
- getLink,
268
- loadArticleData,
269
- saveInMemory
248
+ getFromCookieString,
249
+ manageToken,
250
+ setCookie
270
251
  });
271
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_LANG = \"en-US\";\n\nexport const EN_LANG = \"en\";\n\nexport const UI_LANG_OPTIONS = [\"en-us\", \"de-de\"];\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\";","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 });\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 * Checks if the current environment is a browser.\n * @returns True if running in a browser environment, false otherwise\n */\nfunction isBrowser() {\n return typeof window !== 'undefined' && typeof document !== 'undefined';\n}\n\n/**\n * Saves a value in memory on the server side.\n * @param value - The string value to save\n * @param key - The key under which to store the value\n * @throws Error if called in a browser environment\n */\nexport function saveInMemory(value: string, 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\n/**\n * Retrieves a value from memory on the server side.\n * @param key - The key of the value to retrieve\n * @returns The stored string value\n * @throws Error if called in a browser environment\n */\nexport function getFromMemory(key: string): string {\n if (isBrowser()) throw new Error(\"getFromMemory is not supported in browser\");\n\n return (global as any)[key];\n}\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 getCookieInFront = 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 cache: 'no-store',\n });\n const json = await res.json();\n\n return json;\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 { DirectoryNodesService } from \"@c-rex/services\";\nimport { DirectoryNodes, informationUnitsDirectories, TreeOfContent } from \"@c-rex/interfaces\";\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 const service = new DirectoryNodesService();\n\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 service.getItem(id);\n const childList = await getChildrenInfo(response.childNodes);\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 service.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 infoId = await getLink(item.shortId);\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\n/**\n * Gets the information unit ID from a directory node ID.\n * @param directoryNodeID - The ID of the directory node\n * @returns A Promise resolving to the information unit ID, or an empty string if not found\n */\nexport const getLink = async (directoryNodeID: string): Promise<string> => {\n const service = new DirectoryNodesService();\n const response = await service.getItem(directoryNodeID);\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\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 { InformationUnitsService, RenditionsService } from \"@c-rex/services\";\nimport { generateBreadcrumbItems, generateTreeOfContent, getLink } from \"./\";\nimport { TreeOfContent } from \"@c-rex/interfaces\";\n\nconst DOCUMENT = \"documents\";\nconst TOPIC = \"topics\";\n\n/**\n * Loads article data including content, tree structure, breadcrumbs, and available versions.\n * @param id - The ID of the article to load\n * @param type - The type of article (\"documents\" or \"topics\", defaults to \"documents\")\n * @returns A Promise resolving to an object containing the article data\n */\nexport const loadArticleData = async (id: string, type: string = DOCUMENT) => {\n const renditionService = new RenditionsService();\n const informationService = new InformationUnitsService();\n const informationUnitsItem = await informationService.getItem({ id });\n\n const { rootNode, result: treeOfContent } = await generateTreeOfContent(informationUnitsItem.directoryNodes);\n\n const articleLanguage = informationUnitsItem.languages[0]\n const versionOf = informationUnitsItem.versionOf.shortId\n\n const versions = await informationService.getList({\n filters: [`versionOf.shortId=${versionOf}`],\n fields: [\"renditions\", \"class\", \"languages\", \"labels\"],\n })\n const availableVersions = versions.items.map((item) => {\n return {\n shortId: item.shortId,\n link: `/${type}/${item.shortId}`,\n lang: item.language,\n country: item.language.split(\"-\")[1],\n active: item.language === articleLanguage,\n }\n }).sort((a, b) => {\n if (a.lang < b.lang) return -1;\n if (a.lang > b.lang) return 1;\n return 0;\n });\n\n let title = informationUnitsItem.labels[0].value\n let documents = renditionService.getFileRenditions(informationUnitsItem.renditions);\n let htmlContent = \"\"\n let rootNodeInfoID = \"\";\n let breadcrumbItems: TreeOfContent[]\n\n if (rootNode != null) {\n title = rootNode.informationUnits[0].labels[0].value;\n rootNodeInfoID = rootNode.informationUnits[0].shortId;\n\n const childInformationUnit = await informationService.getItem({ id: rootNodeInfoID });\n documents = renditionService.getFileRenditions(childInformationUnit.renditions);\n }\n\n if (type == TOPIC) {\n htmlContent = await renditionService.getHTMLRendition(informationUnitsItem.renditions);\n breadcrumbItems = generateBreadcrumbItems(treeOfContent);\n } else {\n\n if (rootNode != null) {\n const directoryId = rootNode.childNodes[0].shortId;\n const infoId = await getLink(directoryId);\n const childInformationUnit = await informationService.getItem({ id: infoId });\n htmlContent = await renditionService.getHTMLRendition(childInformationUnit.renditions);\n }\n\n treeOfContent[0].active = true;\n\n breadcrumbItems = [{\n link: \"/\",\n label: title,\n id: \"title\",\n active: false,\n children: [],\n }]\n }\n\n return {\n htmlContent,\n treeOfContent,\n breadcrumbItems,\n availableVersions,\n documents,\n title,\n articleLanguage\n }\n};"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;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;AAmBO,IAAM,uBAAuB,IAAI,KAAK,KAAK,KAAK;;;A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,MAAI,YAAY,MAAM;AAClB,YAAQ,SAAS,iBAAiB,CAAC,EAAE,OAAO,CAAC,EAAE;AAC/C,qBAAiB,SAAS,iBAAiB,CAAC,EAAE;AAE9C,UAAM,uBAAuB,MAAM,mBAAmB,QAAQ,EAAE,IAAI,eAAe,CAAC;AACpF,gBAAY,iBAAiB,kBAAkB,qBAAqB,UAAU;AAAA,EAClF;AAEA,MAAI,QAAQ,OAAO;AACf,kBAAc,MAAM,iBAAiB,iBAAiB,qBAAqB,UAAU;AACrF,sBAAkB,wBAAwB,aAAa;AAAA,EAC3D,OAAO;AAEH,QAAI,YAAY,MAAM;AAClB,YAAM,cAAc,SAAS,WAAW,CAAC,EAAE;AAC3C,YAAM,SAAS,MAAM,QAAQ,WAAW;AACxC,YAAM,uBAAuB,MAAM,mBAAmB,QAAQ,EAAE,IAAI,OAAO,CAAC;AAC5E,oBAAc,MAAM,iBAAiB,iBAAiB,qBAAqB,UAAU;AAAA,IACzF;AAEA,kBAAc,CAAC,EAAE,SAAS;AAE1B,sBAAkB,CAAC;AAAA,MACf,MAAM;AAAA,MACN,OAAO;AAAA,MACP,IAAI;AAAA,MACJ,QAAQ;AAAA,MACR,UAAU,CAAC;AAAA,IACf,CAAC;AAAA,EACL;AAEA,SAAO;AAAA,IACH;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACJ;AACJ;","names":["import_services"]}
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/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;;;AC4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,kBAAkB;AAAA,MACnB,OAAO;AAAA,MACP,SAAS,4BAA4B,KAAK;AAAA,IAC9C,CAAC;AAED,WAAO;AAAA,EACX;AACJ;","names":[]}
package/dist/index.mjs CHANGED
@@ -4,6 +4,7 @@ var FLAGS_BY_LANG = {
4
4
  "de": "DE"
5
5
  };
6
6
  var DEFAULT_COOKIE_LIMIT = 7 * 24 * 60 * 60 * 1e3;
7
+ var CREX_TOKEN_HEADER_KEY = "crex-token";
7
8
 
8
9
  // src/utils.ts
9
10
  var call = async (method, params) => {
@@ -11,7 +12,8 @@ var call = async (method, params) => {
11
12
  const res = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/api/rpc`, {
12
13
  method: "POST",
13
14
  headers: { "Content-Type": "application/json" },
14
- body: JSON.stringify({ method, params })
15
+ body: JSON.stringify({ method, params }),
16
+ credentials: "include"
15
17
  });
16
18
  const json = await res.json();
17
19
  if (!res.ok) throw new Error(json.error || "Unknown error");
@@ -29,32 +31,47 @@ var getCountryCodeByLang = (lang) => {
29
31
  const country = FLAGS_BY_LANG[lang];
30
32
  return country;
31
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
+ };
32
44
 
33
45
  // src/memory.ts
34
- function isBrowser() {
35
- return typeof window !== "undefined" && typeof document !== "undefined";
36
- }
37
- function saveInMemory(value, key) {
38
- if (isBrowser()) throw new Error("saveInMemory is not supported in browser");
39
- if (typeof global !== "undefined" && !(key in global)) {
40
- global[key] = null;
41
- }
42
- const globalConfig = global[key];
43
- if (globalConfig === null) {
44
- global[key] = value;
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 };
45
50
  }
46
- }
47
- function getFromMemory(key) {
48
- if (isBrowser()) throw new Error("getFromMemory is not supported in browser");
49
- return global[key];
50
- }
51
- var getCookieInFront = async (key) => {
52
- const res = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/api/cookies?key=${key}`, {
53
- cache: "no-store"
54
- });
55
51
  const json = await res.json();
56
52
  return json;
57
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
+ });
73
+ }
74
+ };
58
75
 
59
76
  // src/breadcrumbs.ts
60
77
  var generateBreadcrumbItems = (treeOfContent) => {
@@ -76,14 +93,12 @@ function cn(...inputs) {
76
93
  }
77
94
 
78
95
  // src/treeOfContent.ts
79
- import { DirectoryNodesService } from "@c-rex/services";
80
96
  var generateTreeOfContent = async (directoryNodes) => {
81
- const service = new DirectoryNodesService();
82
97
  if (directoryNodes.length == 0 || directoryNodes[0] == void 0) {
83
98
  return { rootNode: null, result: [] };
84
99
  }
85
100
  let id = directoryNodes[0].shortId;
86
- let response = await service.getItem(id);
101
+ let response = await call("DirectoryNodesService.getItem", id);
87
102
  const childList = await getChildrenInfo(response.childNodes);
88
103
  let result = childList;
89
104
  while (response.parents != void 0) {
@@ -102,7 +117,7 @@ var generateTreeOfContent = async (directoryNodes) => {
102
117
  children: [...result]
103
118
  };
104
119
  id = response.parents[0].shortId;
105
- response = await service.getItem(id);
120
+ response = await call("DirectoryNodesService.getItem", id);
106
121
  const tree = await getChildrenInfo(response.childNodes, aux);
107
122
  result = [...tree];
108
123
  }
@@ -113,7 +128,10 @@ var getChildrenInfo = async (childNodes, childItem) => {
113
128
  if (childNodes == void 0) return result;
114
129
  for (const item of childNodes) {
115
130
  if (item.labels == void 0 || item.labels[0] == void 0) break;
116
- const infoId = await getLink(item.shortId);
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;
117
135
  let resultItem = {
118
136
  active: false,
119
137
  label: item.labels[0].value,
@@ -128,13 +146,6 @@ var getChildrenInfo = async (childNodes, childItem) => {
128
146
  }
129
147
  return result;
130
148
  };
131
- var getLink = async (directoryNodeID) => {
132
- const service = new DirectoryNodesService();
133
- const response = await service.getItem(directoryNodeID);
134
- if (response.informationUnits == void 0) return "";
135
- if (response.informationUnits[0] == void 0) return "";
136
- return response.informationUnits[0].shortId;
137
- };
138
149
 
139
150
  // src/params.ts
140
151
  var createParams = (fieldsList, key = "Fields") => fieldsList.map((item) => ({
@@ -148,73 +159,45 @@ var generateQueryParams = (params) => {
148
159
  return queryParams;
149
160
  };
150
161
 
151
- // src/articles.ts
152
- import { InformationUnitsService, RenditionsService } from "@c-rex/services";
153
- var DOCUMENT = "documents";
154
- var TOPIC = "topics";
155
- var loadArticleData = async (id, type = DOCUMENT) => {
156
- const renditionService = new RenditionsService();
157
- const informationService = new InformationUnitsService();
158
- const informationUnitsItem = await informationService.getItem({ id });
159
- const { rootNode, result: treeOfContent } = await generateTreeOfContent(informationUnitsItem.directoryNodes);
160
- const articleLanguage = informationUnitsItem.languages[0];
161
- const versionOf = informationUnitsItem.versionOf.shortId;
162
- const versions = await informationService.getList({
163
- filters: [`versionOf.shortId=${versionOf}`],
164
- fields: ["renditions", "class", "languages", "labels"]
165
- });
166
- const availableVersions = versions.items.map((item) => {
167
- return {
168
- shortId: item.shortId,
169
- link: `/${type}/${item.shortId}`,
170
- lang: item.language,
171
- country: item.language.split("-")[1],
172
- active: item.language === articleLanguage
173
- };
174
- }).sort((a, b) => {
175
- if (a.lang < b.lang) return -1;
176
- if (a.lang > b.lang) return 1;
177
- return 0;
178
- });
179
- let title = informationUnitsItem.labels[0].value;
180
- let documents = renditionService.getFileRenditions(informationUnitsItem.renditions);
181
- let htmlContent = "";
182
- let rootNodeInfoID = "";
183
- let breadcrumbItems;
184
- if (rootNode != null) {
185
- title = rootNode.informationUnits[0].labels[0].value;
186
- rootNodeInfoID = rootNode.informationUnits[0].shortId;
187
- const childInformationUnit = await informationService.getItem({ id: rootNodeInfoID });
188
- documents = renditionService.getFileRenditions(childInformationUnit.renditions);
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"
168
+ });
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}`
180
+ });
181
+ return null;
189
182
  }
190
- if (type == TOPIC) {
191
- htmlContent = await renditionService.getHTMLRendition(informationUnitsItem.renditions);
192
- breadcrumbItems = generateBreadcrumbItems(treeOfContent);
193
- } else {
194
- if (rootNode != null) {
195
- const directoryId = rootNode.childNodes[0].shortId;
196
- const infoId = await getLink(directoryId);
197
- const childInformationUnit = await informationService.getItem({ id: infoId });
198
- htmlContent = await renditionService.getHTMLRendition(childInformationUnit.renditions);
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;
199
192
  }
200
- treeOfContent[0].active = true;
201
- breadcrumbItems = [{
202
- link: "/",
203
- label: title,
204
- id: "title",
205
- active: false,
206
- children: []
207
- }];
193
+ return token;
194
+ } catch (error) {
195
+ call("CrexLogger.log", {
196
+ level: "error",
197
+ message: `utils.manageToken error: ${error}`
198
+ });
199
+ return null;
208
200
  }
209
- return {
210
- htmlContent,
211
- treeOfContent,
212
- breadcrumbItems,
213
- availableVersions,
214
- documents,
215
- title,
216
- articleLanguage
217
- };
218
201
  };
219
202
  export {
220
203
  call,
@@ -223,11 +206,10 @@ export {
223
206
  generateBreadcrumbItems,
224
207
  generateQueryParams,
225
208
  generateTreeOfContent,
226
- getCookieInFront,
209
+ getCookie,
227
210
  getCountryCodeByLang,
228
- getFromMemory,
229
- getLink,
230
- loadArticleData,
231
- saveInMemory
211
+ getFromCookieString,
212
+ manageToken,
213
+ setCookie
232
214
  };
233
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_LANG = \"en-US\";\n\nexport const EN_LANG = \"en\";\n\nexport const UI_LANG_OPTIONS = [\"en-us\", \"de-de\"];\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\";","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 });\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 * Checks if the current environment is a browser.\n * @returns True if running in a browser environment, false otherwise\n */\nfunction isBrowser() {\n return typeof window !== 'undefined' && typeof document !== 'undefined';\n}\n\n/**\n * Saves a value in memory on the server side.\n * @param value - The string value to save\n * @param key - The key under which to store the value\n * @throws Error if called in a browser environment\n */\nexport function saveInMemory(value: string, 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\n/**\n * Retrieves a value from memory on the server side.\n * @param key - The key of the value to retrieve\n * @returns The stored string value\n * @throws Error if called in a browser environment\n */\nexport function getFromMemory(key: string): string {\n if (isBrowser()) throw new Error(\"getFromMemory is not supported in browser\");\n\n return (global as any)[key];\n}\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 getCookieInFront = 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 cache: 'no-store',\n });\n const json = await res.json();\n\n return json;\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 { DirectoryNodesService } from \"@c-rex/services\";\nimport { DirectoryNodes, informationUnitsDirectories, TreeOfContent } from \"@c-rex/interfaces\";\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 const service = new DirectoryNodesService();\n\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 service.getItem(id);\n const childList = await getChildrenInfo(response.childNodes);\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 service.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 infoId = await getLink(item.shortId);\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\n/**\n * Gets the information unit ID from a directory node ID.\n * @param directoryNodeID - The ID of the directory node\n * @returns A Promise resolving to the information unit ID, or an empty string if not found\n */\nexport const getLink = async (directoryNodeID: string): Promise<string> => {\n const service = new DirectoryNodesService();\n const response = await service.getItem(directoryNodeID);\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\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 { InformationUnitsService, RenditionsService } from \"@c-rex/services\";\nimport { generateBreadcrumbItems, generateTreeOfContent, getLink } from \"./\";\nimport { TreeOfContent } from \"@c-rex/interfaces\";\n\nconst DOCUMENT = \"documents\";\nconst TOPIC = \"topics\";\n\n/**\n * Loads article data including content, tree structure, breadcrumbs, and available versions.\n * @param id - The ID of the article to load\n * @param type - The type of article (\"documents\" or \"topics\", defaults to \"documents\")\n * @returns A Promise resolving to an object containing the article data\n */\nexport const loadArticleData = async (id: string, type: string = DOCUMENT) => {\n const renditionService = new RenditionsService();\n const informationService = new InformationUnitsService();\n const informationUnitsItem = await informationService.getItem({ id });\n\n const { rootNode, result: treeOfContent } = await generateTreeOfContent(informationUnitsItem.directoryNodes);\n\n const articleLanguage = informationUnitsItem.languages[0]\n const versionOf = informationUnitsItem.versionOf.shortId\n\n const versions = await informationService.getList({\n filters: [`versionOf.shortId=${versionOf}`],\n fields: [\"renditions\", \"class\", \"languages\", \"labels\"],\n })\n const availableVersions = versions.items.map((item) => {\n return {\n shortId: item.shortId,\n link: `/${type}/${item.shortId}`,\n lang: item.language,\n country: item.language.split(\"-\")[1],\n active: item.language === articleLanguage,\n }\n }).sort((a, b) => {\n if (a.lang < b.lang) return -1;\n if (a.lang > b.lang) return 1;\n return 0;\n });\n\n let title = informationUnitsItem.labels[0].value\n let documents = renditionService.getFileRenditions(informationUnitsItem.renditions);\n let htmlContent = \"\"\n let rootNodeInfoID = \"\";\n let breadcrumbItems: TreeOfContent[]\n\n if (rootNode != null) {\n title = rootNode.informationUnits[0].labels[0].value;\n rootNodeInfoID = rootNode.informationUnits[0].shortId;\n\n const childInformationUnit = await informationService.getItem({ id: rootNodeInfoID });\n documents = renditionService.getFileRenditions(childInformationUnit.renditions);\n }\n\n if (type == TOPIC) {\n htmlContent = await renditionService.getHTMLRendition(informationUnitsItem.renditions);\n breadcrumbItems = generateBreadcrumbItems(treeOfContent);\n } else {\n\n if (rootNode != null) {\n const directoryId = rootNode.childNodes[0].shortId;\n const infoId = await getLink(directoryId);\n const childInformationUnit = await informationService.getItem({ id: infoId });\n htmlContent = await renditionService.getHTMLRendition(childInformationUnit.renditions);\n }\n\n treeOfContent[0].active = true;\n\n breadcrumbItems = [{\n link: \"/\",\n label: title,\n id: \"title\",\n active: false,\n children: [],\n }]\n }\n\n return {\n htmlContent,\n treeOfContent,\n breadcrumbItems,\n availableVersions,\n documents,\n title,\n articleLanguage\n }\n};"],"mappings":";AA4CO,IAAM,gBAAgB;AAAA,EACz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MAAI,YAAY,iBAAiB,kBAAkB,qBAAqB,UAAU;AAClF,MAAI,cAAc;AAClB,MAAI,iBAAiB;AACrB,MAAI;AAEJ,MAAI,YAAY,MAAM;AAClB,YAAQ,SAAS,iBAAiB,CAAC,EAAE,OAAO,CAAC,EAAE;AAC/C,qBAAiB,SAAS,iBAAiB,CAAC,EAAE;AAE9C,UAAM,uBAAuB,MAAM,mBAAmB,QAAQ,EAAE,IAAI,eAAe,CAAC;AACpF,gBAAY,iBAAiB,kBAAkB,qBAAqB,UAAU;AAAA,EAClF;AAEA,MAAI,QAAQ,OAAO;AACf,kBAAc,MAAM,iBAAiB,iBAAiB,qBAAqB,UAAU;AACrF,sBAAkB,wBAAwB,aAAa;AAAA,EAC3D,OAAO;AAEH,QAAI,YAAY,MAAM;AAClB,YAAM,cAAc,SAAS,WAAW,CAAC,EAAE;AAC3C,YAAM,SAAS,MAAM,QAAQ,WAAW;AACxC,YAAM,uBAAuB,MAAM,mBAAmB,QAAQ,EAAE,IAAI,OAAO,CAAC;AAC5E,oBAAc,MAAM,iBAAiB,iBAAiB,qBAAqB,UAAU;AAAA,IACzF;AAEA,kBAAc,CAAC,EAAE,SAAS;AAE1B,sBAAkB,CAAC;AAAA,MACf,MAAM;AAAA,MACN,OAAO;AAAA,MACP,IAAI;AAAA,MACJ,QAAQ;AAAA,MACR,UAAU,CAAC;AAAA,IACf,CAAC;AAAA,EACL;AAEA,SAAO;AAAA,IACH;AAAA,IACA;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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-1,18 +1,5 @@
1
1
  import { ConfigInterface } from '@c-rex/interfaces';
2
2
 
3
- /**
4
- * Gets a cookie value from the server-side cookies store.
5
- * @param key - The key of the cookie to retrieve
6
- * @returns The value of the cookie
7
- * @throws Error if the cookie is not found
8
- */
9
- declare const getCookieFromBack: (key: string) => string;
10
- /**
11
- * Sets a cookie with secure and HttpOnly flags.
12
- * @param key - The key of the cookie to set
13
- * @param value - The value to store in the cookie
14
- */
15
- declare const setCookie: (key: string, value: string) => void;
16
3
  /**
17
4
  * Retrieves and parses configuration data from a cookie.
18
5
  * @returns The parsed configuration object
@@ -20,4 +7,4 @@ declare const setCookie: (key: string, value: string) => void;
20
7
  */
21
8
  declare const getConfigs: () => ConfigInterface;
22
9
 
23
- export { getConfigs, getCookieFromBack, setCookie };
10
+ export { getConfigs };
@@ -1,18 +1,5 @@
1
1
  import { ConfigInterface } from '@c-rex/interfaces';
2
2
 
3
- /**
4
- * Gets a cookie value from the server-side cookies store.
5
- * @param key - The key of the cookie to retrieve
6
- * @returns The value of the cookie
7
- * @throws Error if the cookie is not found
8
- */
9
- declare const getCookieFromBack: (key: string) => string;
10
- /**
11
- * Sets a cookie with secure and HttpOnly flags.
12
- * @param key - The key of the cookie to set
13
- * @param value - The value to store in the cookie
14
- */
15
- declare const setCookie: (key: string, value: string) => void;
16
3
  /**
17
4
  * Retrieves and parses configuration data from a cookie.
18
5
  * @returns The parsed configuration object
@@ -20,4 +7,4 @@ declare const setCookie: (key: string, value: string) => void;
20
7
  */
21
8
  declare const getConfigs: () => ConfigInterface;
22
9
 
23
- export { getConfigs, getCookieFromBack, setCookie };
10
+ export { getConfigs };
@@ -21,9 +21,7 @@ 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
- getCookieFromBack: () => getCookieFromBack,
26
- setCookie: () => setCookie
24
+ getConfigs: () => getConfigs
27
25
  });
28
26
  module.exports = __toCommonJS(next_cookies_exports);
29
27
 
@@ -33,23 +31,8 @@ var DEFAULT_COOKIE_LIMIT = 7 * 24 * 60 * 60 * 1e3;
33
31
 
34
32
  // src/next-cookies.ts
35
33
  var import_headers = require("next/headers");
36
- var getCookieFromBack = (key) => {
37
- const value = (0, import_headers.cookies)().get(key);
38
- if (value) {
39
- return value.value;
40
- }
41
- throw new Error(`Cookie ${key} not found`);
42
- };
43
- var setCookie = (key, value) => {
44
- (0, import_headers.cookies)().set(key, value, {
45
- path: "/",
46
- secure: true,
47
- httpOnly: true,
48
- maxAge: DEFAULT_COOKIE_LIMIT
49
- });
50
- };
51
34
  var getConfigs = () => {
52
- const jsonConfigs = getCookieFromBack(SDK_CONFIG_KEY);
35
+ const jsonConfigs = (0, import_headers.cookies)().get(SDK_CONFIG_KEY)?.value;
53
36
  if (!jsonConfigs) {
54
37
  throw new Error("Configs not found");
55
38
  }
@@ -58,8 +41,6 @@ var getConfigs = () => {
58
41
  };
59
42
  // Annotate the CommonJS export names for ESM import in node:
60
43
  0 && (module.exports = {
61
- getConfigs,
62
- getCookieFromBack,
63
- setCookie
44
+ getConfigs
64
45
  });
65
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 { DEFAULT_COOKIE_LIMIT, SDK_CONFIG_KEY } from '@c-rex/constants';\nimport { ConfigInterface } from '@c-rex/interfaces';\nimport { cookies } from 'next/headers';\n\n/*\n* Use this function to get a cookie value by key.\n* @param key - The key of the cookie.\n* @returns The value of the cookie.\n*/\n/**\n * Gets a cookie value from the server-side cookies store.\n * @param key - The key of the cookie to retrieve\n * @returns The value of the cookie\n * @throws Error if the cookie is not found\n */\nexport const getCookieFromBack = (key: string): string => {\n const value = cookies().get(key);\n if (value) {\n return value.value;\n }\n\n throw new Error(`Cookie ${key} not found`);\n}\n\n/**\n * Sets a cookie with secure and HttpOnly flags.\n * @param key - The key of the cookie to set\n * @param value - The value to store in the cookie\n */\nexport const setCookie = (key: string, value: string): void => {\n cookies().set(key, value, {\n path: '/',\n secure: true,\n httpOnly: true,\n maxAge: DEFAULT_COOKIE_LIMIT\n });\n}\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 = getCookieFromBack(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_LANG = \"en-US\";\n\nexport const EN_LANG = \"en\";\n\nexport const UI_LANG_OPTIONS = [\"en-us\", \"de-de\"];\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\";"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACoCO,IAAM,iBAAiB;AA8BvB,IAAM,uBAAuB,IAAI,KAAK,KAAK,KAAK;;;AD9DvD,qBAAwB;AAajB,IAAM,oBAAoB,CAAC,QAAwB;AACtD,QAAM,YAAQ,wBAAQ,EAAE,IAAI,GAAG;AAC/B,MAAI,OAAO;AACP,WAAO,MAAM;AAAA,EACjB;AAEA,QAAM,IAAI,MAAM,UAAU,GAAG,YAAY;AAC7C;AAOO,IAAM,YAAY,CAAC,KAAa,UAAwB;AAC3D,8BAAQ,EAAE,IAAI,KAAK,OAAO;AAAA,IACtB,MAAM;AAAA,IACN,QAAQ;AAAA,IACR,UAAU;AAAA,IACV,QAAQ;AAAA,EACZ,CAAC;AACL;AAOO,IAAM,aAAa,MAAuB;AAC7C,QAAM,cAAc,kBAAkB,cAAc;AACpD,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":[]}
@@ -6,23 +6,8 @@ var DEFAULT_COOKIE_LIMIT = 7 * 24 * 60 * 60 * 1e3;
6
6
 
7
7
  // src/next-cookies.ts
8
8
  import { cookies } from "next/headers";
9
- var getCookieFromBack = (key) => {
10
- const value = cookies().get(key);
11
- if (value) {
12
- return value.value;
13
- }
14
- throw new Error(`Cookie ${key} not found`);
15
- };
16
- var setCookie = (key, value) => {
17
- cookies().set(key, value, {
18
- path: "/",
19
- secure: true,
20
- httpOnly: true,
21
- maxAge: DEFAULT_COOKIE_LIMIT
22
- });
23
- };
24
9
  var getConfigs = () => {
25
- const jsonConfigs = getCookieFromBack(SDK_CONFIG_KEY);
10
+ const jsonConfigs = cookies().get(SDK_CONFIG_KEY)?.value;
26
11
  if (!jsonConfigs) {
27
12
  throw new Error("Configs not found");
28
13
  }
@@ -30,8 +15,6 @@ var getConfigs = () => {
30
15
  return configs;
31
16
  };
32
17
  export {
33
- getConfigs,
34
- getCookieFromBack,
35
- setCookie
18
+ getConfigs
36
19
  };
37
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_LANG = \"en-US\";\n\nexport const EN_LANG = \"en\";\n\nexport const UI_LANG_OPTIONS = [\"en-us\", \"de-de\"];\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\";","'use server';\n\nimport { DEFAULT_COOKIE_LIMIT, SDK_CONFIG_KEY } from '@c-rex/constants';\nimport { ConfigInterface } from '@c-rex/interfaces';\nimport { cookies } from 'next/headers';\n\n/*\n* Use this function to get a cookie value by key.\n* @param key - The key of the cookie.\n* @returns The value of the cookie.\n*/\n/**\n * Gets a cookie value from the server-side cookies store.\n * @param key - The key of the cookie to retrieve\n * @returns The value of the cookie\n * @throws Error if the cookie is not found\n */\nexport const getCookieFromBack = (key: string): string => {\n const value = cookies().get(key);\n if (value) {\n return value.value;\n }\n\n throw new Error(`Cookie ${key} not found`);\n}\n\n/**\n * Sets a cookie with secure and HttpOnly flags.\n * @param key - The key of the cookie to set\n * @param value - The value to store in the cookie\n */\nexport const setCookie = (key: string, value: string): void => {\n cookies().set(key, value, {\n path: '/',\n secure: true,\n httpOnly: true,\n maxAge: DEFAULT_COOKIE_LIMIT\n });\n}\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 = getCookieFromBack(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;AA8BvB,IAAM,uBAAuB,IAAI,KAAK,KAAK,KAAK;;;AC9DvD,SAAS,eAAe;AAajB,IAAM,oBAAoB,CAAC,QAAwB;AACtD,QAAM,QAAQ,QAAQ,EAAE,IAAI,GAAG;AAC/B,MAAI,OAAO;AACP,WAAO,MAAM;AAAA,EACjB;AAEA,QAAM,IAAI,MAAM,UAAU,GAAG,YAAY;AAC7C;AAOO,IAAM,YAAY,CAAC,KAAa,UAAwB;AAC3D,UAAQ,EAAE,IAAI,KAAK,OAAO;AAAA,IACtB,MAAM;AAAA,IACN,QAAQ;AAAA,IACR,UAAU;AAAA,IACV,QAAQ;AAAA,EACZ,CAAC;AACL;AAOO,IAAM,aAAa,MAAuB;AAC7C,QAAM,cAAc,kBAAkB,cAAc;AACpD,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,6 +1,6 @@
1
1
  {
2
2
  "name": "@c-rex/utils",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "files": [
5
5
  "dist"
6
6
  ],