@c-rex/utils 0.1.3 → 0.1.5
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 +29 -64
- package/dist/index.d.ts +29 -64
- package/dist/index.js +194 -149
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +188 -144
- package/dist/index.mjs.map +1 -1
- package/dist/next-cookies.d.mts +1 -14
- package/dist/next-cookies.d.ts +1 -14
- package/dist/next-cookies.js +3 -22
- package/dist/next-cookies.js.map +1 -1
- package/dist/next-cookies.mjs +2 -19
- package/dist/next-cookies.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -4,22 +4,16 @@ 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
|
-
var
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const json = await res.json();
|
|
17
|
-
if (!res.ok) throw new Error(json.error || "Unknown error");
|
|
18
|
-
return json.data;
|
|
19
|
-
} catch (error) {
|
|
20
|
-
console.error(error);
|
|
21
|
-
return null;
|
|
22
|
-
}
|
|
10
|
+
var _generateShaKey = async (input) => {
|
|
11
|
+
const encoder = new TextEncoder();
|
|
12
|
+
const data = encoder.encode(input);
|
|
13
|
+
const hashBuffer = await crypto.subtle.digest("SHA-1", data);
|
|
14
|
+
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
|
15
|
+
const base64url = btoa(String.fromCharCode(...hashArray)).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
16
|
+
return base64url.slice(0, 12);
|
|
23
17
|
};
|
|
24
18
|
var getCountryCodeByLang = (lang) => {
|
|
25
19
|
const mappedKeys = Object.keys(FLAGS_BY_LANG);
|
|
@@ -29,32 +23,76 @@ var getCountryCodeByLang = (lang) => {
|
|
|
29
23
|
const country = FLAGS_BY_LANG[lang];
|
|
30
24
|
return country;
|
|
31
25
|
};
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
if (typeof global !== "undefined" && !(key in global)) {
|
|
40
|
-
global[key] = null;
|
|
26
|
+
var getFromCookieString = (cookieString, key) => {
|
|
27
|
+
const cookies = cookieString.split(";");
|
|
28
|
+
for (const cookie of cookies) {
|
|
29
|
+
const [cookieKey, cookieValue] = cookie.trim().split("=");
|
|
30
|
+
if (cookieKey === key) {
|
|
31
|
+
return cookieValue;
|
|
32
|
+
}
|
|
41
33
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
34
|
+
return "";
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
// src/call.ts
|
|
38
|
+
var call = async (method, params) => {
|
|
39
|
+
const shaKey = await _generateShaKey(JSON.stringify({ method, params }));
|
|
40
|
+
const cache = localStorage.getItem(shaKey);
|
|
41
|
+
if (cache !== null) {
|
|
42
|
+
const { data, expireDate } = JSON.parse(cache);
|
|
43
|
+
if (new Date(expireDate) > /* @__PURE__ */ new Date()) {
|
|
44
|
+
return JSON.parse(data);
|
|
45
|
+
} else {
|
|
46
|
+
localStorage.removeItem(shaKey);
|
|
47
|
+
}
|
|
45
48
|
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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"
|
|
49
|
+
const res = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/api/rpc`, {
|
|
50
|
+
method: "POST",
|
|
51
|
+
headers: { "Content-Type": "application/json" },
|
|
52
|
+
body: JSON.stringify({ method, params }),
|
|
53
|
+
credentials: "include"
|
|
54
54
|
});
|
|
55
55
|
const json = await res.json();
|
|
56
|
+
if (!res.ok) throw new Error(json.error || "Unknown error");
|
|
57
|
+
const today = /* @__PURE__ */ new Date();
|
|
58
|
+
const result = {
|
|
59
|
+
data: JSON.stringify(json.data),
|
|
60
|
+
expireDate: new Date(today.getTime() + 1e3 * 60 * 60)
|
|
61
|
+
};
|
|
62
|
+
localStorage.setItem(shaKey, JSON.stringify(result));
|
|
63
|
+
return json.data;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
// src/memory.ts
|
|
67
|
+
var getCookie = async (key) => {
|
|
68
|
+
const res = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/api/cookies?key=${key}`);
|
|
69
|
+
if (!res.ok) {
|
|
70
|
+
return { key, value: null };
|
|
71
|
+
}
|
|
72
|
+
const json = await res.json();
|
|
56
73
|
return json;
|
|
57
74
|
};
|
|
75
|
+
var setCookie = async (key, value, maxAge) => {
|
|
76
|
+
try {
|
|
77
|
+
if (maxAge === void 0) {
|
|
78
|
+
maxAge = DEFAULT_COOKIE_LIMIT;
|
|
79
|
+
}
|
|
80
|
+
await fetch(`${process.env.NEXT_PUBLIC_API_URL}/api/cookies`, {
|
|
81
|
+
method: "POST",
|
|
82
|
+
credentials: "include",
|
|
83
|
+
body: JSON.stringify({
|
|
84
|
+
key,
|
|
85
|
+
value,
|
|
86
|
+
maxAge
|
|
87
|
+
})
|
|
88
|
+
});
|
|
89
|
+
} catch (error) {
|
|
90
|
+
call("CrexLogger.log", {
|
|
91
|
+
level: "error",
|
|
92
|
+
message: `utils.setCookie error: ${error}`
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
};
|
|
58
96
|
|
|
59
97
|
// src/breadcrumbs.ts
|
|
60
98
|
var generateBreadcrumbItems = (treeOfContent) => {
|
|
@@ -76,65 +114,59 @@ function cn(...inputs) {
|
|
|
76
114
|
}
|
|
77
115
|
|
|
78
116
|
// src/treeOfContent.ts
|
|
79
|
-
|
|
117
|
+
var itemCache = /* @__PURE__ */ new Map();
|
|
118
|
+
async function getItemCached(id) {
|
|
119
|
+
if (itemCache.has(id)) return itemCache.get(id);
|
|
120
|
+
const data = await call("DirectoryNodesService.getItem", id);
|
|
121
|
+
itemCache.set(id, data);
|
|
122
|
+
return data;
|
|
123
|
+
}
|
|
80
124
|
var generateTreeOfContent = async (directoryNodes) => {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
let response = await service.getItem(id);
|
|
87
|
-
const childList = await getChildrenInfo(response.childNodes);
|
|
88
|
-
let result = childList;
|
|
89
|
-
while (response.parents != void 0) {
|
|
90
|
-
const hasInfo = response.informationUnits != void 0 && response.informationUnits[0] != void 0;
|
|
91
|
-
const hasLabel = response.labels != void 0 && response.labels[0] != void 0;
|
|
92
|
-
const hasParent = response.parents != void 0 && response.parents[0] != void 0;
|
|
93
|
-
if (!hasInfo || !hasLabel || !hasParent) {
|
|
125
|
+
if (!directoryNodes?.length) return { rootNode: null, result: [] };
|
|
126
|
+
let response = await getItemCached(directoryNodes[0].shortId);
|
|
127
|
+
let result = await getChildrenInfo(response.childNodes);
|
|
128
|
+
while (response.parents?.[0]) {
|
|
129
|
+
if (!response.labels?.[0] || !response.informationUnits?.[0]) {
|
|
94
130
|
return { rootNode: null, result };
|
|
95
131
|
}
|
|
96
132
|
const infoId = response.informationUnits[0].shortId;
|
|
97
|
-
const
|
|
133
|
+
const parentNode = {
|
|
98
134
|
active: true,
|
|
99
135
|
label: response.labels[0].value,
|
|
100
136
|
id: response.shortId,
|
|
101
137
|
link: `/topics/${infoId}`,
|
|
102
|
-
children:
|
|
138
|
+
children: result
|
|
103
139
|
};
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
const tree = await getChildrenInfo(response.childNodes, aux);
|
|
107
|
-
result = [...tree];
|
|
140
|
+
response = await getItemCached(response.parents[0].shortId);
|
|
141
|
+
result = await getChildrenInfo(response.childNodes, parentNode);
|
|
108
142
|
}
|
|
109
143
|
return { rootNode: response, result };
|
|
110
144
|
};
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
145
|
+
async function getChildrenInfo(childNodes, childItem) {
|
|
146
|
+
if (!childNodes?.length) return [];
|
|
147
|
+
const validNodes = childNodes.filter((n) => n.labels?.[0]);
|
|
148
|
+
const responses = await Promise.all(
|
|
149
|
+
validNodes.map(
|
|
150
|
+
(n) => getItemCached(n.shortId).catch((err) => {
|
|
151
|
+
console.error("Erro em", n.shortId, err);
|
|
152
|
+
return void 0;
|
|
153
|
+
})
|
|
154
|
+
)
|
|
155
|
+
);
|
|
156
|
+
return responses.reduce((acc, resp, idx) => {
|
|
157
|
+
if (!resp?.informationUnits?.[0]) return acc;
|
|
158
|
+
const node = validNodes[idx];
|
|
159
|
+
const treeItem = {
|
|
118
160
|
active: false,
|
|
119
|
-
label:
|
|
120
|
-
link: `/topics/${
|
|
121
|
-
id:
|
|
161
|
+
label: node.labels[0].value,
|
|
162
|
+
link: `/topics/${resp.informationUnits[0].shortId}`,
|
|
163
|
+
id: node.shortId,
|
|
122
164
|
children: []
|
|
123
165
|
};
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
}
|
|
129
|
-
return result;
|
|
130
|
-
};
|
|
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
|
-
};
|
|
166
|
+
acc.push(node.shortId === childItem?.id ? childItem : treeItem);
|
|
167
|
+
return acc;
|
|
168
|
+
}, []);
|
|
169
|
+
}
|
|
138
170
|
|
|
139
171
|
// src/params.ts
|
|
140
172
|
var createParams = (fieldsList, key = "Fields") => fieldsList.map((item) => ({
|
|
@@ -148,86 +180,98 @@ var generateQueryParams = (params) => {
|
|
|
148
180
|
return queryParams;
|
|
149
181
|
};
|
|
150
182
|
|
|
151
|
-
// src/
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
})
|
|
166
|
-
|
|
183
|
+
// src/token.ts
|
|
184
|
+
var updateToken = async () => {
|
|
185
|
+
try {
|
|
186
|
+
const response = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/api/token`, {
|
|
187
|
+
method: "POST",
|
|
188
|
+
credentials: "include"
|
|
189
|
+
});
|
|
190
|
+
const cookies = response.headers.get("set-cookie");
|
|
191
|
+
if (cookies === null) return null;
|
|
192
|
+
const aux = cookies.split(`${CREX_TOKEN_HEADER_KEY}=`);
|
|
193
|
+
if (aux.length == 0) return null;
|
|
194
|
+
const token = aux[1].split(";")[0];
|
|
195
|
+
if (token === void 0) throw new Error("Token is undefined");
|
|
196
|
+
return token;
|
|
197
|
+
} catch (error) {
|
|
198
|
+
call("CrexLogger.log", {
|
|
199
|
+
level: "error",
|
|
200
|
+
message: `utils.updateToken error: ${error}`
|
|
201
|
+
});
|
|
202
|
+
return null;
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
var manageToken = async () => {
|
|
206
|
+
try {
|
|
207
|
+
const hasToken = await getCookie(CREX_TOKEN_HEADER_KEY);
|
|
208
|
+
let token = "";
|
|
209
|
+
if (!hasToken || hasToken.value === null) {
|
|
210
|
+
const tokenResult = await updateToken();
|
|
211
|
+
if (tokenResult === null) throw new Error("Token is undefined");
|
|
212
|
+
token = tokenResult;
|
|
213
|
+
} else {
|
|
214
|
+
token = hasToken.value;
|
|
215
|
+
}
|
|
216
|
+
return token;
|
|
217
|
+
} catch (error) {
|
|
218
|
+
call("CrexLogger.log", {
|
|
219
|
+
level: "error",
|
|
220
|
+
message: `utils.manageToken error: ${error}`
|
|
221
|
+
});
|
|
222
|
+
return null;
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
|
|
226
|
+
// src/renditions.ts
|
|
227
|
+
var getFileRenditions = ({ renditions }) => {
|
|
228
|
+
if (renditions == void 0 || renditions.length == 0) {
|
|
167
229
|
return {
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
lang: item.language,
|
|
171
|
-
country: item.language.split("-")[1],
|
|
172
|
-
active: item.language === articleLanguage
|
|
230
|
+
filesToDownload: [],
|
|
231
|
+
filesToOpen: []
|
|
173
232
|
};
|
|
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);
|
|
189
233
|
}
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
htmlContent = await renditionService.getHTMLRendition(childInformationUnit.renditions);
|
|
199
|
-
}
|
|
200
|
-
treeOfContent[0].active = true;
|
|
201
|
-
breadcrumbItems = [{
|
|
202
|
-
link: "/",
|
|
203
|
-
label: title,
|
|
204
|
-
id: "title",
|
|
205
|
-
active: false,
|
|
206
|
-
children: []
|
|
207
|
-
}];
|
|
234
|
+
const filteredRenditions = renditions.filter(
|
|
235
|
+
(item) => item.format != "application/xhtml+xml" && item.format != "application/json" && item.format != "application/llm+xml"
|
|
236
|
+
);
|
|
237
|
+
if (filteredRenditions.length == 0 || filteredRenditions[0] == void 0) {
|
|
238
|
+
return {
|
|
239
|
+
filesToDownload: [],
|
|
240
|
+
filesToOpen: []
|
|
241
|
+
};
|
|
208
242
|
}
|
|
243
|
+
const filesToDownload = filteredRenditions.map((item) => {
|
|
244
|
+
const filteredLinks = item.links.filter((item2) => item2.rel == "download");
|
|
245
|
+
return {
|
|
246
|
+
format: item.format,
|
|
247
|
+
link: filteredLinks[0].href
|
|
248
|
+
};
|
|
249
|
+
});
|
|
250
|
+
const filesToOpen = filteredRenditions.map((item) => {
|
|
251
|
+
const filteredLinks = item.links.filter((item2) => item2.rel == "view");
|
|
252
|
+
return {
|
|
253
|
+
format: item.format,
|
|
254
|
+
link: filteredLinks[0].href
|
|
255
|
+
};
|
|
256
|
+
});
|
|
209
257
|
return {
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
breadcrumbItems,
|
|
213
|
-
availableVersions,
|
|
214
|
-
documents,
|
|
215
|
-
title,
|
|
216
|
-
articleLanguage
|
|
258
|
+
filesToDownload,
|
|
259
|
+
filesToOpen
|
|
217
260
|
};
|
|
218
261
|
};
|
|
219
262
|
export {
|
|
263
|
+
_generateShaKey,
|
|
220
264
|
call,
|
|
221
265
|
cn,
|
|
222
266
|
createParams,
|
|
223
267
|
generateBreadcrumbItems,
|
|
224
268
|
generateQueryParams,
|
|
225
269
|
generateTreeOfContent,
|
|
226
|
-
|
|
270
|
+
getCookie,
|
|
227
271
|
getCountryCodeByLang,
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
272
|
+
getFileRenditions,
|
|
273
|
+
getFromCookieString,
|
|
274
|
+
manageToken,
|
|
275
|
+
setCookie
|
|
232
276
|
};
|
|
233
277
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -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,EACzB,MAAM;AAAA,EACN,MAAM;AACV;AAmBO,IAAM,uBAAuB,IAAI,KAAK,KAAK,KAAK;;;AC1DhD,IAAM,OAAO,OAAmB,QAAgB,WAA6B;AAChF,MAAI;AACA,UAAM,MAAM,MAAM,MAAM,GAAG,QAAQ,IAAI,mBAAmB,YAAY;AAAA,MAClE,QAAQ;AAAA,MACR,SAAS,EAAE,gBAAgB,mBAAmB;AAAA,MAC9C,MAAM,KAAK,UAAU,EAAE,QAAQ,OAAO,CAAC;AAAA,IAC3C,CAAC;AAED,UAAM,OAAO,MAAM,IAAI,KAAK;AAE5B,QAAI,CAAC,IAAI,GAAI,OAAM,IAAI,MAAM,KAAK,SAAS,e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AkB,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/call.ts","../src/memory.ts","../src/breadcrumbs.ts","../src/classMerge.ts","../src/treeOfContent.ts","../src/params.ts","../src/token.ts","../src/renditions.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 BLOG_TYPE_AND_LINK = \"blog\";\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\nexport const _generateShaKey = async (input: string): Promise<string> => {\n const encoder = new TextEncoder();\n const data = encoder.encode(input);\n const hashBuffer = await crypto.subtle.digest('SHA-1', data);\n const hashArray = Array.from(new Uint8Array(hashBuffer));\n const base64url = btoa(String.fromCharCode(...hashArray))\n .replace(/\\+/g, '-')\n .replace(/\\//g, '_')\n .replace(/=+$/, '');\n\n return base64url.slice(0, 12);\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 { _generateShaKey } from \"./utils\"\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\n */\nexport const call = async<T = unknown>(method: string, params?: any): Promise<T> => {\n type result = {\n data: string,\n expireDate: Date,\n }\n\n const shaKey = await _generateShaKey(JSON.stringify({ method, params }))\n const cache = localStorage.getItem(shaKey)\n\n if (cache !== null) {\n const { data, expireDate } = JSON.parse(cache) as result\n\n if (new Date(expireDate) > new Date()) {\n return JSON.parse(data) as T\n } else {\n localStorage.removeItem(shaKey)\n }\n }\n\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 const today = new Date()\n const result: result = {\n data: JSON.stringify(json.data),\n expireDate: new Date(today.getTime() + 1000 * 60 * 60),\n }\n\n localStorage.setItem(shaKey, JSON.stringify(result))\n\n return json.data;\n}","import { DEFAULT_COOKIE_LIMIT } from \"@c-rex/constants\";\nimport { call } from \"./call\";\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 \"./call\";\n\ntype ReturnType = {\n rootNode: DirectoryNodes | null,\n result: TreeOfContent[],\n}\n\nconst itemCache = new Map<string, DirectoryNodes>();\n\nasync function getItemCached(id: string): Promise<DirectoryNodes> {\n if (itemCache.has(id)) return itemCache.get(id)!;\n\n const data = await call<DirectoryNodes>(\"DirectoryNodesService.getItem\", id);\n\n itemCache.set(id, data);\n\n return data;\n}\n\nexport const generateTreeOfContent = async (\n directoryNodes: DirectoryNodes[]\n): Promise<ReturnType> => {\n if (!directoryNodes?.length) return { rootNode: null, result: [] };\n\n let response = await getItemCached(directoryNodes[0].shortId);\n let result = await getChildrenInfo(response.childNodes);\n\n while (response.parents?.[0]) {\n if (!response.labels?.[0] || !response.informationUnits?.[0]) {\n return { rootNode: null, result };\n }\n\n const infoId = response.informationUnits[0].shortId;\n\n const parentNode: TreeOfContent = {\n active: true,\n label: response.labels[0].value,\n id: response.shortId,\n link: `/topics/${infoId}`,\n children: result,\n };\n\n response = await getItemCached(response.parents[0].shortId);\n result = await getChildrenInfo(response.childNodes, parentNode);\n }\n\n return { rootNode: response, result };\n};\n\nasync function getChildrenInfo(\n childNodes: informationUnitsDirectories[] | undefined,\n childItem?: TreeOfContent\n): Promise<TreeOfContent[]> {\n if (!childNodes?.length) return [];\n\n const validNodes = childNodes.filter((n) => n.labels?.[0]);\n\n const responses = await Promise.all(\n validNodes.map((n) =>\n getItemCached(n.shortId).catch((err) => {\n console.error(\"Erro em\", n.shortId, err);\n return undefined;\n })\n )\n );\n\n return responses.reduce<TreeOfContent[]>((acc, resp, idx) => {\n if (!resp?.informationUnits?.[0]) return acc;\n\n const node = validNodes[idx];\n const treeItem: TreeOfContent = {\n active: false,\n label: node.labels![0].value,\n link: `/topics/${resp.informationUnits[0].shortId}`,\n id: node.shortId,\n children: [],\n };\n\n acc.push(node.shortId === childItem?.id ? childItem : treeItem);\n return acc;\n }, []);\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 { call } from \"./call\";\nimport { getCookie } from \"./memory\";\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 const hasToken = await getCookie(CREX_TOKEN_HEADER_KEY);\n\n let token = \"\";\n if (!hasToken || hasToken.value === null) {\n const tokenResult = await updateToken();\n\n if (tokenResult === null) throw new Error(\"Token is undefined\");\n\n token = tokenResult;\n } else {\n token = hasToken.value;\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}","import { FileRenditionType } from \"@c-rex/types\";\nimport { informationUnitsRenditions } from \"@c-rex/interfaces\";\n\ntype RenditionType = {\n filesToDownload: FileRenditionType[],\n filesToOpen: FileRenditionType[]\n}\nexport const getFileRenditions = ({ renditions }: { renditions: informationUnitsRenditions[] }): RenditionType => {\n if (renditions == undefined || renditions.length == 0) {\n return {\n filesToDownload: [],\n filesToOpen: [],\n };\n }\n\n const filteredRenditions = renditions.filter(\n (item) => item.format != \"application/xhtml+xml\" && item.format != \"application/json\" && item.format != \"application/llm+xml\"\n );\n\n if (filteredRenditions.length == 0 || filteredRenditions[0] == undefined) {\n return {\n filesToDownload: [],\n filesToOpen: [],\n };\n }\n\n const filesToDownload = filteredRenditions.map((item) => {\n const filteredLinks = item.links.filter((item) => item.rel == \"download\");\n return {\n format: item.format,\n link: filteredLinks[0].href,\n };\n });\n\n const filesToOpen = filteredRenditions.map((item) => {\n const filteredLinks = item.links.filter((item) => item.rel == \"view\");\n return {\n format: item.format,\n link: filteredLinks[0].href,\n };\n })\n\n return {\n filesToDownload: filesToDownload,\n filesToOpen: filesToOpen,\n }\n}"],"mappings":";AA4CO,IAAM,gBAAgB;AAAA,EACzB,MAAM;AAAA,EACN,MAAM;AACV;AA2BO,IAAM,uBAAuB,IAAI,KAAK,KAAK,KAAK;AAQhD,IAAM,wBAAwB;;;AChF9B,IAAM,kBAAkB,OAAO,UAAmC;AACrE,QAAM,UAAU,IAAI,YAAY;AAChC,QAAM,OAAO,QAAQ,OAAO,KAAK;AACjC,QAAM,aAAa,MAAM,OAAO,OAAO,OAAO,SAAS,IAAI;AAC3D,QAAM,YAAY,MAAM,KAAK,IAAI,WAAW,UAAU,CAAC;AACvD,QAAM,YAAY,KAAK,OAAO,aAAa,GAAG,SAAS,CAAC,EACnD,QAAQ,OAAO,GAAG,EAClB,QAAQ,OAAO,GAAG,EAClB,QAAQ,OAAO,EAAE;AAEtB,SAAO,UAAU,MAAM,GAAG,EAAE;AAChC;AAOO,IAAM,uBAAuB,CAAC,SAAyB;AAC1D,QAAM,aAAa,OAAO,KAAK,aAAa;AAE5C,MAAI,CAAC,WAAW,SAAS,IAAI,GAAG;AAC5B,WAAO;AAAA,EACX;AAGA,QAAM,UAAU,cAAc,IAAe;AAE7C,SAAO;AACX;AAEO,IAAM,sBAAsB,CAAC,cAAsB,QAAwB;AAC9E,QAA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J;AACJ;","names":["item"]}
|
package/dist/next-cookies.d.mts
CHANGED
|
@@ -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
|
|
10
|
+
export { getConfigs };
|
package/dist/next-cookies.d.ts
CHANGED
|
@@ -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
|
|
10
|
+
export { getConfigs };
|
package/dist/next-cookies.js
CHANGED
|
@@ -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 =
|
|
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
|
package/dist/next-cookies.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/next-cookies.ts","../../constants/src/index.ts"],"sourcesContent":["'use server';\n\nimport {
|
|
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 BLOG_TYPE_AND_LINK = \"blog\";\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;AAsCvB,IAAM,uBAAuB,IAAI,KAAK,KAAK,KAAK;;;ADtEvD,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":[]}
|
package/dist/next-cookies.mjs
CHANGED
|
@@ -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 =
|
|
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
|