@c-rex/utils 0.1.1 → 0.1.3
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 +104 -5
- package/dist/index.d.ts +104 -5
- package/dist/index.js +98 -13
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +95 -12
- package/dist/index.mjs.map +1 -1
- package/dist/next-cookies.d.mts +20 -4
- package/dist/next-cookies.d.ts +20 -4
- package/dist/next-cookies.js +18 -8
- package/dist/next-cookies.js.map +1 -1
- package/dist/next-cookies.mjs +17 -7
- package/dist/next-cookies.mjs.map +1 -1
- package/package.json +4 -6
package/dist/index.d.mts
CHANGED
|
@@ -2,23 +2,122 @@ import { TreeOfContent, DirectoryNodes } from '@c-rex/interfaces';
|
|
|
2
2
|
import { ClassValue } from 'clsx';
|
|
3
3
|
import { QueryParams } from '@c-rex/types';
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Makes an asynchronous RPC API call to the server.
|
|
7
|
+
* @param method - The RPC method name to call
|
|
8
|
+
* @param params - Optional parameters to pass to the method
|
|
9
|
+
* @returns A Promise resolving to the response data of type T, or null if an error occurs
|
|
10
|
+
*/
|
|
5
11
|
declare const call: <T = unknown>(method: string, params?: any) => Promise<T>;
|
|
12
|
+
/**
|
|
13
|
+
* Retrieves the country code associated with a given language code.
|
|
14
|
+
* @param lang - The language code to look up (e.g., "en-US")
|
|
15
|
+
* @returns The corresponding country code, or the original language code if not found
|
|
16
|
+
*/
|
|
6
17
|
declare const getCountryCodeByLang: (lang: string) => string;
|
|
7
18
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
+
/**
|
|
34
|
+
* Fetches a cookie value from the server API in client-side code.
|
|
35
|
+
* @param key - The key of the cookie to retrieve
|
|
36
|
+
* @returns A Promise resolving to an object containing the key and value of the cookie
|
|
37
|
+
*/
|
|
38
|
+
declare const getCookieInFront: (key: string) => Promise<{
|
|
39
|
+
key: string;
|
|
40
|
+
value: string | null;
|
|
41
|
+
}>;
|
|
11
42
|
|
|
43
|
+
/**
|
|
44
|
+
* Generates breadcrumb items by recursively extracting active items and their active children from a TreeOfContent array.
|
|
45
|
+
* @param treeOfContent - Array of TreeOfContent objects representing the content hierarchy
|
|
46
|
+
* @returns A flattened array of active TreeOfContent items to be used as breadcrumbs
|
|
47
|
+
*/
|
|
12
48
|
declare const generateBreadcrumbItems: (treeOfContent: TreeOfContent[]) => TreeOfContent[];
|
|
13
49
|
|
|
50
|
+
/**
|
|
51
|
+
* Merges multiple class values into a single string using clsx and tailwind-merge.
|
|
52
|
+
* Useful for conditionally applying Tailwind CSS classes.
|
|
53
|
+
* @param inputs - Any number of class values (strings, objects, arrays, etc.)
|
|
54
|
+
* @returns A merged string of class names optimized for Tailwind CSS
|
|
55
|
+
*/
|
|
14
56
|
declare function cn(...inputs: ClassValue[]): string;
|
|
15
57
|
|
|
16
|
-
|
|
58
|
+
type ReturnType = {
|
|
59
|
+
rootNode: DirectoryNodes | null;
|
|
60
|
+
result: TreeOfContent[];
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Generates a hierarchical tree of content from directory nodes.
|
|
64
|
+
* @param directoryNodes - Array of DirectoryNodes to build the tree from
|
|
65
|
+
* @returns A Promise resolving to an object containing the root node and the resulting tree structure
|
|
66
|
+
*/
|
|
67
|
+
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>;
|
|
17
74
|
|
|
75
|
+
/**
|
|
76
|
+
* Creates an array of parameter objects from a list of field values.
|
|
77
|
+
* @param fieldsList - Array of field values to transform into parameter objects
|
|
78
|
+
* @param key - The key to use for each parameter object (defaults to "Fields")
|
|
79
|
+
* @returns An array of objects with key-value pairs
|
|
80
|
+
*/
|
|
18
81
|
declare const createParams: (fieldsList: string[], key?: string) => {
|
|
19
82
|
key: string;
|
|
20
83
|
value: string;
|
|
21
84
|
}[];
|
|
85
|
+
/**
|
|
86
|
+
* Generates a URL query string from an array of parameter objects.
|
|
87
|
+
* @param params - Array of QueryParams objects containing key-value pairs
|
|
88
|
+
* @returns A URL-encoded query string
|
|
89
|
+
*/
|
|
22
90
|
declare const generateQueryParams: (params: QueryParams[]) => string;
|
|
23
91
|
|
|
24
|
-
|
|
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
|
+
}>;
|
|
122
|
+
|
|
123
|
+
export { call, cn, createParams, generateBreadcrumbItems, generateQueryParams, generateTreeOfContent, getCookieInFront, getCountryCodeByLang, getFromMemory, getLink, loadArticleData, saveInMemory };
|
package/dist/index.d.ts
CHANGED
|
@@ -2,23 +2,122 @@ import { TreeOfContent, DirectoryNodes } from '@c-rex/interfaces';
|
|
|
2
2
|
import { ClassValue } from 'clsx';
|
|
3
3
|
import { QueryParams } from '@c-rex/types';
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Makes an asynchronous RPC API call to the server.
|
|
7
|
+
* @param method - The RPC method name to call
|
|
8
|
+
* @param params - Optional parameters to pass to the method
|
|
9
|
+
* @returns A Promise resolving to the response data of type T, or null if an error occurs
|
|
10
|
+
*/
|
|
5
11
|
declare const call: <T = unknown>(method: string, params?: any) => Promise<T>;
|
|
12
|
+
/**
|
|
13
|
+
* Retrieves the country code associated with a given language code.
|
|
14
|
+
* @param lang - The language code to look up (e.g., "en-US")
|
|
15
|
+
* @returns The corresponding country code, or the original language code if not found
|
|
16
|
+
*/
|
|
6
17
|
declare const getCountryCodeByLang: (lang: string) => string;
|
|
7
18
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
+
/**
|
|
34
|
+
* Fetches a cookie value from the server API in client-side code.
|
|
35
|
+
* @param key - The key of the cookie to retrieve
|
|
36
|
+
* @returns A Promise resolving to an object containing the key and value of the cookie
|
|
37
|
+
*/
|
|
38
|
+
declare const getCookieInFront: (key: string) => Promise<{
|
|
39
|
+
key: string;
|
|
40
|
+
value: string | null;
|
|
41
|
+
}>;
|
|
11
42
|
|
|
43
|
+
/**
|
|
44
|
+
* Generates breadcrumb items by recursively extracting active items and their active children from a TreeOfContent array.
|
|
45
|
+
* @param treeOfContent - Array of TreeOfContent objects representing the content hierarchy
|
|
46
|
+
* @returns A flattened array of active TreeOfContent items to be used as breadcrumbs
|
|
47
|
+
*/
|
|
12
48
|
declare const generateBreadcrumbItems: (treeOfContent: TreeOfContent[]) => TreeOfContent[];
|
|
13
49
|
|
|
50
|
+
/**
|
|
51
|
+
* Merges multiple class values into a single string using clsx and tailwind-merge.
|
|
52
|
+
* Useful for conditionally applying Tailwind CSS classes.
|
|
53
|
+
* @param inputs - Any number of class values (strings, objects, arrays, etc.)
|
|
54
|
+
* @returns A merged string of class names optimized for Tailwind CSS
|
|
55
|
+
*/
|
|
14
56
|
declare function cn(...inputs: ClassValue[]): string;
|
|
15
57
|
|
|
16
|
-
|
|
58
|
+
type ReturnType = {
|
|
59
|
+
rootNode: DirectoryNodes | null;
|
|
60
|
+
result: TreeOfContent[];
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Generates a hierarchical tree of content from directory nodes.
|
|
64
|
+
* @param directoryNodes - Array of DirectoryNodes to build the tree from
|
|
65
|
+
* @returns A Promise resolving to an object containing the root node and the resulting tree structure
|
|
66
|
+
*/
|
|
67
|
+
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>;
|
|
17
74
|
|
|
75
|
+
/**
|
|
76
|
+
* Creates an array of parameter objects from a list of field values.
|
|
77
|
+
* @param fieldsList - Array of field values to transform into parameter objects
|
|
78
|
+
* @param key - The key to use for each parameter object (defaults to "Fields")
|
|
79
|
+
* @returns An array of objects with key-value pairs
|
|
80
|
+
*/
|
|
18
81
|
declare const createParams: (fieldsList: string[], key?: string) => {
|
|
19
82
|
key: string;
|
|
20
83
|
value: string;
|
|
21
84
|
}[];
|
|
85
|
+
/**
|
|
86
|
+
* Generates a URL query string from an array of parameter objects.
|
|
87
|
+
* @param params - Array of QueryParams objects containing key-value pairs
|
|
88
|
+
* @returns A URL-encoded query string
|
|
89
|
+
*/
|
|
22
90
|
declare const generateQueryParams: (params: QueryParams[]) => string;
|
|
23
91
|
|
|
24
|
-
|
|
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
|
+
}>;
|
|
122
|
+
|
|
123
|
+
export { call, cn, createParams, generateBreadcrumbItems, generateQueryParams, generateTreeOfContent, getCookieInFront, getCountryCodeByLang, getFromMemory, getLink, loadArticleData, saveInMemory };
|
package/dist/index.js
CHANGED
|
@@ -26,9 +26,11 @@ __export(index_exports, {
|
|
|
26
26
|
generateBreadcrumbItems: () => generateBreadcrumbItems,
|
|
27
27
|
generateQueryParams: () => generateQueryParams,
|
|
28
28
|
generateTreeOfContent: () => generateTreeOfContent,
|
|
29
|
+
getCookieInFront: () => getCookieInFront,
|
|
29
30
|
getCountryCodeByLang: () => getCountryCodeByLang,
|
|
30
31
|
getFromMemory: () => getFromMemory,
|
|
31
|
-
|
|
32
|
+
getLink: () => getLink,
|
|
33
|
+
loadArticleData: () => loadArticleData,
|
|
32
34
|
saveInMemory: () => saveInMemory
|
|
33
35
|
});
|
|
34
36
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -38,6 +40,7 @@ var FLAGS_BY_LANG = {
|
|
|
38
40
|
"en": "US",
|
|
39
41
|
"de": "DE"
|
|
40
42
|
};
|
|
43
|
+
var DEFAULT_COOKIE_LIMIT = 7 * 24 * 60 * 60 * 1e3;
|
|
41
44
|
|
|
42
45
|
// src/utils.ts
|
|
43
46
|
var call = async (method, params) => {
|
|
@@ -82,6 +85,13 @@ function getFromMemory(key) {
|
|
|
82
85
|
if (isBrowser()) throw new Error("getFromMemory is not supported in browser");
|
|
83
86
|
return global[key];
|
|
84
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
|
+
const json = await res.json();
|
|
93
|
+
return json;
|
|
94
|
+
};
|
|
85
95
|
|
|
86
96
|
// src/breadcrumbs.ts
|
|
87
97
|
var generateBreadcrumbItems = (treeOfContent) => {
|
|
@@ -106,22 +116,26 @@ function cn(...inputs) {
|
|
|
106
116
|
var import_services = require("@c-rex/services");
|
|
107
117
|
var generateTreeOfContent = async (directoryNodes) => {
|
|
108
118
|
const service = new import_services.DirectoryNodesService();
|
|
109
|
-
if (directoryNodes.length == 0
|
|
110
|
-
|
|
119
|
+
if (directoryNodes.length == 0 || directoryNodes[0] == void 0) {
|
|
120
|
+
return { rootNode: null, result: [] };
|
|
121
|
+
}
|
|
111
122
|
let id = directoryNodes[0].shortId;
|
|
112
123
|
let response = await service.getItem(id);
|
|
113
124
|
const childList = await getChildrenInfo(response.childNodes);
|
|
114
125
|
let result = childList;
|
|
115
126
|
while (response.parents != void 0) {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
127
|
+
const hasInfo = response.informationUnits != void 0 && response.informationUnits[0] != void 0;
|
|
128
|
+
const hasLabel = response.labels != void 0 && response.labels[0] != void 0;
|
|
129
|
+
const hasParent = response.parents != void 0 && response.parents[0] != void 0;
|
|
130
|
+
if (!hasInfo || !hasLabel || !hasParent) {
|
|
131
|
+
return { rootNode: null, result };
|
|
132
|
+
}
|
|
119
133
|
const infoId = response.informationUnits[0].shortId;
|
|
120
134
|
const aux = {
|
|
121
135
|
active: true,
|
|
122
136
|
label: response.labels[0].value,
|
|
123
137
|
id: response.shortId,
|
|
124
|
-
link: `/
|
|
138
|
+
link: `/topics/${infoId}`,
|
|
125
139
|
children: [...result]
|
|
126
140
|
};
|
|
127
141
|
id = response.parents[0].shortId;
|
|
@@ -129,18 +143,18 @@ var generateTreeOfContent = async (directoryNodes) => {
|
|
|
129
143
|
const tree = await getChildrenInfo(response.childNodes, aux);
|
|
130
144
|
result = [...tree];
|
|
131
145
|
}
|
|
132
|
-
return result;
|
|
146
|
+
return { rootNode: response, result };
|
|
133
147
|
};
|
|
134
148
|
var getChildrenInfo = async (childNodes, childItem) => {
|
|
135
149
|
const result = [];
|
|
136
150
|
if (childNodes == void 0) return result;
|
|
137
151
|
for (const item of childNodes) {
|
|
138
|
-
if (item.labels[0] == void 0) break;
|
|
152
|
+
if (item.labels == void 0 || item.labels[0] == void 0) break;
|
|
139
153
|
const infoId = await getLink(item.shortId);
|
|
140
154
|
let resultItem = {
|
|
141
155
|
active: false,
|
|
142
156
|
label: item.labels[0].value,
|
|
143
|
-
link: `/
|
|
157
|
+
link: `/topics/${infoId}`,
|
|
144
158
|
id: item.shortId,
|
|
145
159
|
children: []
|
|
146
160
|
};
|
|
@@ -151,9 +165,9 @@ var getChildrenInfo = async (childNodes, childItem) => {
|
|
|
151
165
|
}
|
|
152
166
|
return result;
|
|
153
167
|
};
|
|
154
|
-
var getLink = async (
|
|
168
|
+
var getLink = async (directoryNodeID) => {
|
|
155
169
|
const service = new import_services.DirectoryNodesService();
|
|
156
|
-
const response = await service.getItem(
|
|
170
|
+
const response = await service.getItem(directoryNodeID);
|
|
157
171
|
if (response.informationUnits == void 0) return "";
|
|
158
172
|
if (response.informationUnits[0] == void 0) return "";
|
|
159
173
|
return response.informationUnits[0].shortId;
|
|
@@ -170,6 +184,75 @@ var generateQueryParams = (params) => {
|
|
|
170
184
|
).join("&");
|
|
171
185
|
return queryParams;
|
|
172
186
|
};
|
|
187
|
+
|
|
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);
|
|
226
|
+
}
|
|
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);
|
|
236
|
+
}
|
|
237
|
+
treeOfContent[0].active = true;
|
|
238
|
+
breadcrumbItems = [{
|
|
239
|
+
link: "/",
|
|
240
|
+
label: title,
|
|
241
|
+
id: "title",
|
|
242
|
+
active: false,
|
|
243
|
+
children: []
|
|
244
|
+
}];
|
|
245
|
+
}
|
|
246
|
+
return {
|
|
247
|
+
htmlContent,
|
|
248
|
+
treeOfContent,
|
|
249
|
+
breadcrumbItems,
|
|
250
|
+
availableVersions,
|
|
251
|
+
documents,
|
|
252
|
+
title,
|
|
253
|
+
articleLanguage
|
|
254
|
+
};
|
|
255
|
+
};
|
|
173
256
|
// Annotate the CommonJS export names for ESM import in node:
|
|
174
257
|
0 && (module.exports = {
|
|
175
258
|
call,
|
|
@@ -178,9 +261,11 @@ var generateQueryParams = (params) => {
|
|
|
178
261
|
generateBreadcrumbItems,
|
|
179
262
|
generateQueryParams,
|
|
180
263
|
generateTreeOfContent,
|
|
264
|
+
getCookieInFront,
|
|
181
265
|
getCountryCodeByLang,
|
|
182
266
|
getFromMemory,
|
|
183
|
-
|
|
267
|
+
getLink,
|
|
268
|
+
loadArticleData,
|
|
184
269
|
saveInMemory
|
|
185
270
|
});
|
|
186
271
|
//# 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"],"sourcesContent":["export * from './utils';\nexport * from './memory';\nexport * from './breadcrumbs';\nexport * from './classMerge';\nexport * from './treeOfContent';\nexport * from './params';","export const ALL = \"*\"\n\nexport const LOG_CATEGORIES = [\n \"NoLicense\",\n \"Scenario\",\n \"Favorites\",\n \"Subscription\",\n \"Share\",\n \"Document\",\n \"Search\",\n \"History\",\n \"Notification\",\n \"UserProfile\",\n] as const;\n\nexport const LOG_LEVELS = {\n critical: 2,\n error: 3,\n warning: 4,\n info: 6,\n debug: 7,\n} as const;\n\nexport const API = {\n MAX_RETRY: 3,\n API_TIMEOUT: 10000,\n API_HEADERS: {\n \"content-Type\": \"application/json\",\n },\n};\n\nexport const SDK_CONFIG_KEY = \"crex-sdk-config\";\n\nexport const CONTENT_LANG_KEY = \"CONTENT_LANG_KEY\";\n\nexport const UI_LANG_KEY = \"UI_LANG_KEY\";\n\nexport const FLAGS_BY_LANG = {\n \"en\": \"US\",\n \"de\": \"DE\",\n};\n\nexport const DEFAULT_UI_LANG = \"en\";\nexport const UI_LANG_OPTIONS = [\"en\", \"de\"];","import { FLAGS_BY_LANG } from \"@c-rex/constants\";\n\nexport const call = async<T = unknown>(method: string, params?: any): Promise<T> => {\n try {\n const res = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/api/rpc`, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({ method, params }),\n });\n\n const json = await res.json();\n\n if (!res.ok) throw new Error(json.error || 'Unknown error');\n\n return json.data;\n } catch (error) {\n console.error(error);\n return null as any;\n }\n}\n\nexport const getCountryCodeByLang = (lang: string): string => {\n const mappedKeys = Object.keys(FLAGS_BY_LANG);\n\n if (!mappedKeys.includes(lang)) {\n return lang\n }\n\n type LangKey = keyof typeof FLAGS_BY_LANG;\n const country = FLAGS_BY_LANG[lang as LangKey]\n\n return country\n}","export function isBrowser() {\n return typeof window !== 'undefined' && typeof document !== 'undefined';\n}\n\nexport function saveInMemory(value: any, key: string) {\n if (isBrowser()) throw new Error(\"saveInMemory is not supported in browser\");\n\n if (typeof global !== 'undefined' && !(key in global)) {\n (global as any)[key] = null;\n }\n\n const globalConfig = (global as any)[key] as any;\n\n if (globalConfig === null) {\n (global as any)[key] = value;\n }\n}\n\nexport function getFromMemory(key: string): any {\n if (isBrowser()) throw new Error(\"getFromMemory is not supported in browser\");\n\n return (global as any)[key];\n}\n","import { TreeOfContent } from \"@c-rex/interfaces\";\n\nexport const generateBreadcrumbItems = (\n treeOfContent: TreeOfContent[],\n): TreeOfContent[] => {\n const result: TreeOfContent[] = [];\n\n treeOfContent.forEach((item) => {\n if (item.active) {\n const filteredChildren = generateBreadcrumbItems(item.children);\n result.push(item, ...filteredChildren);\n }\n });\n\n return result;\n};\n","import { clsx, type ClassValue } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nexport function cn(...inputs: ClassValue[]) {\n return twMerge(clsx(inputs));\n}\n","import { DirectoryNodesService } from \"@c-rex/services\";\nimport { DirectoryNodes, informationUnitsDirectories, TreeOfContent } from \"@c-rex/interfaces\";\n\nexport const generateTreeOfContent = async (\n directoryNodes: DirectoryNodes[],\n): Promise<TreeOfContent[]> => {\n\n const service = new DirectoryNodesService();\n\n if (directoryNodes.length == 0) return [];\n if (directoryNodes[0] == undefined) return [];\n\n let id = directoryNodes[0].shortId;\n let response = await service.getItem(id);\n const childList = await getChildrenInfo(response.childNodes);\n let result: TreeOfContent[] = childList;\n\n while (response.parents != undefined) {\n if (response.informationUnits[0] == undefined) return result;\n if (response.labels[0] == undefined) return result;\n if (response.parents[0] == undefined) return result;\n\n const infoId = response.informationUnits[0].shortId;\n const aux = {\n active: true,\n label: response.labels[0].value,\n id: response.shortId,\n link: `/info/${infoId}`,\n children: [...result],\n };\n id = response.parents[0].shortId;\n response = await service.getItem(id);\n\n const tree = await getChildrenInfo(response.childNodes, aux);\n\n result = [...tree];\n }\n\n return result;\n};\n\nconst getChildrenInfo = async (\n childNodes: informationUnitsDirectories[],\n childItem?: TreeOfContent,\n): Promise<TreeOfContent[]> => {\n const result: TreeOfContent[] = [];\n if (childNodes == undefined) return result;\n\n for (const item of childNodes) {\n if (item.labels[0] == undefined) break;\n\n const infoId = await getLink(item.shortId);\n let resultItem: TreeOfContent = {\n active: false,\n label: item.labels[0].value,\n link: `/info/${infoId}`,\n id: item.shortId,\n children: [],\n };\n\n if (childItem?.id == item.shortId) {\n resultItem = childItem;\n }\n result.push(resultItem);\n }\n\n return result;\n};\n\nconst getLink = async (id: string): Promise<string> => {\n const service = new DirectoryNodesService();\n const response = await service.getItem(id);\n\n if (response.informationUnits == undefined) return \"\";\n if (response.informationUnits[0] == undefined) return \"\";\n\n return response.informationUnits[0].shortId;\n};","import { QueryParams } from '@c-rex/types';\n\nexport const createParams = (fieldsList: string[], key: string = \"Fields\") =>\n fieldsList.map((item) => ({\n key: key,\n value: item,\n }));\n\nexport const generateQueryParams = (params: QueryParams[]): string => {\n const queryParams = params\n .map(\n (param) =>\n `${encodeURIComponent(param.key)}=${encodeURIComponent(param.value)}`,\n )\n .join(\"&\");\n return queryParams;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACqCO,IAAM,gBAAgB;AAAA,EACzB,MAAM;AAAA,EACN,MAAM;AACV;;;ACtCO,IAAM,OAAO,OAAmB,QAAgB,WAA6B;AAChF,MAAI;AACA,UAAM,MAAM,MAAM,MAAM,GAAG,QAAQ,IAAI,mBAAmB,YAAY;AAAA,MAClE,QAAQ;AAAA,MACR,SAAS,EAAE,gBAAgB,mBAAmB;AAAA,MAC9C,MAAM,KAAK,UAAU,EAAE,QAAQ,OAAO,CAAC;AAAA,IAC3C,CAAC;AAED,UAAM,OAAO,MAAM,IAAI,KAAK;AAE5B,QAAI,CAAC,IAAI,GAAI,OAAM,IAAI,MAAM,KAAK,SAAS,eAAe;AAE1D,WAAO,KAAK;AAAA,EAChB,SAAS,OAAO;AACZ,YAAQ,MAAM,KAAK;AACnB,WAAO;AAAA,EACX;AACJ;AAEO,IAAM,uBAAuB,CAAC,SAAyB;AAC1D,QAAM,aAAa,OAAO,KAAK,aAAa;AAE5C,MAAI,CAAC,WAAW,SAAS,IAAI,GAAG;AAC5B,WAAO;AAAA,EACX;AAGA,QAAM,UAAU,cAAc,IAAe;AAE7C,SAAO;AACX;;;AChCO,SAAS,YAAY;AACxB,SAAO,OAAO,WAAW,eAAe,OAAO,aAAa;AAChE;AAEO,SAAS,aAAa,OAAY,KAAa;AAClD,MAAI,UAAU,EAAG,OAAM,IA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sBAAsB,CAAC,WAAkC;AAClE,QAAM,cAAc,OACf;AAAA,IACG,CAAC,UACG,GAAG,mBAAmB,MAAM,GAAG,CAAC,IAAI,mBAAmB,MAAM,KAAK,CAAC;AAAA,EAC3E,EACC,KAAK,GAAG;AACb,SAAO;AACX;","names":[]}
|
|
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;;;AC1DhD,IAAM,OAAO,OAAmB,QAAgB,WAA6B;AAChF,MAA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AC,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"]}
|
package/dist/index.mjs
CHANGED
|
@@ -3,6 +3,7 @@ var FLAGS_BY_LANG = {
|
|
|
3
3
|
"en": "US",
|
|
4
4
|
"de": "DE"
|
|
5
5
|
};
|
|
6
|
+
var DEFAULT_COOKIE_LIMIT = 7 * 24 * 60 * 60 * 1e3;
|
|
6
7
|
|
|
7
8
|
// src/utils.ts
|
|
8
9
|
var call = async (method, params) => {
|
|
@@ -47,6 +48,13 @@ function getFromMemory(key) {
|
|
|
47
48
|
if (isBrowser()) throw new Error("getFromMemory is not supported in browser");
|
|
48
49
|
return global[key];
|
|
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"
|
|
54
|
+
});
|
|
55
|
+
const json = await res.json();
|
|
56
|
+
return json;
|
|
57
|
+
};
|
|
50
58
|
|
|
51
59
|
// src/breadcrumbs.ts
|
|
52
60
|
var generateBreadcrumbItems = (treeOfContent) => {
|
|
@@ -71,22 +79,26 @@ function cn(...inputs) {
|
|
|
71
79
|
import { DirectoryNodesService } from "@c-rex/services";
|
|
72
80
|
var generateTreeOfContent = async (directoryNodes) => {
|
|
73
81
|
const service = new DirectoryNodesService();
|
|
74
|
-
if (directoryNodes.length == 0
|
|
75
|
-
|
|
82
|
+
if (directoryNodes.length == 0 || directoryNodes[0] == void 0) {
|
|
83
|
+
return { rootNode: null, result: [] };
|
|
84
|
+
}
|
|
76
85
|
let id = directoryNodes[0].shortId;
|
|
77
86
|
let response = await service.getItem(id);
|
|
78
87
|
const childList = await getChildrenInfo(response.childNodes);
|
|
79
88
|
let result = childList;
|
|
80
89
|
while (response.parents != void 0) {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
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) {
|
|
94
|
+
return { rootNode: null, result };
|
|
95
|
+
}
|
|
84
96
|
const infoId = response.informationUnits[0].shortId;
|
|
85
97
|
const aux = {
|
|
86
98
|
active: true,
|
|
87
99
|
label: response.labels[0].value,
|
|
88
100
|
id: response.shortId,
|
|
89
|
-
link: `/
|
|
101
|
+
link: `/topics/${infoId}`,
|
|
90
102
|
children: [...result]
|
|
91
103
|
};
|
|
92
104
|
id = response.parents[0].shortId;
|
|
@@ -94,18 +106,18 @@ var generateTreeOfContent = async (directoryNodes) => {
|
|
|
94
106
|
const tree = await getChildrenInfo(response.childNodes, aux);
|
|
95
107
|
result = [...tree];
|
|
96
108
|
}
|
|
97
|
-
return result;
|
|
109
|
+
return { rootNode: response, result };
|
|
98
110
|
};
|
|
99
111
|
var getChildrenInfo = async (childNodes, childItem) => {
|
|
100
112
|
const result = [];
|
|
101
113
|
if (childNodes == void 0) return result;
|
|
102
114
|
for (const item of childNodes) {
|
|
103
|
-
if (item.labels[0] == void 0) break;
|
|
115
|
+
if (item.labels == void 0 || item.labels[0] == void 0) break;
|
|
104
116
|
const infoId = await getLink(item.shortId);
|
|
105
117
|
let resultItem = {
|
|
106
118
|
active: false,
|
|
107
119
|
label: item.labels[0].value,
|
|
108
|
-
link: `/
|
|
120
|
+
link: `/topics/${infoId}`,
|
|
109
121
|
id: item.shortId,
|
|
110
122
|
children: []
|
|
111
123
|
};
|
|
@@ -116,9 +128,9 @@ var getChildrenInfo = async (childNodes, childItem) => {
|
|
|
116
128
|
}
|
|
117
129
|
return result;
|
|
118
130
|
};
|
|
119
|
-
var getLink = async (
|
|
131
|
+
var getLink = async (directoryNodeID) => {
|
|
120
132
|
const service = new DirectoryNodesService();
|
|
121
|
-
const response = await service.getItem(
|
|
133
|
+
const response = await service.getItem(directoryNodeID);
|
|
122
134
|
if (response.informationUnits == void 0) return "";
|
|
123
135
|
if (response.informationUnits[0] == void 0) return "";
|
|
124
136
|
return response.informationUnits[0].shortId;
|
|
@@ -135,6 +147,75 @@ var generateQueryParams = (params) => {
|
|
|
135
147
|
).join("&");
|
|
136
148
|
return queryParams;
|
|
137
149
|
};
|
|
150
|
+
|
|
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);
|
|
189
|
+
}
|
|
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);
|
|
199
|
+
}
|
|
200
|
+
treeOfContent[0].active = true;
|
|
201
|
+
breadcrumbItems = [{
|
|
202
|
+
link: "/",
|
|
203
|
+
label: title,
|
|
204
|
+
id: "title",
|
|
205
|
+
active: false,
|
|
206
|
+
children: []
|
|
207
|
+
}];
|
|
208
|
+
}
|
|
209
|
+
return {
|
|
210
|
+
htmlContent,
|
|
211
|
+
treeOfContent,
|
|
212
|
+
breadcrumbItems,
|
|
213
|
+
availableVersions,
|
|
214
|
+
documents,
|
|
215
|
+
title,
|
|
216
|
+
articleLanguage
|
|
217
|
+
};
|
|
218
|
+
};
|
|
138
219
|
export {
|
|
139
220
|
call,
|
|
140
221
|
cn,
|
|
@@ -142,9 +223,11 @@ export {
|
|
|
142
223
|
generateBreadcrumbItems,
|
|
143
224
|
generateQueryParams,
|
|
144
225
|
generateTreeOfContent,
|
|
226
|
+
getCookieInFront,
|
|
145
227
|
getCountryCodeByLang,
|
|
146
228
|
getFromMemory,
|
|
147
|
-
|
|
229
|
+
getLink,
|
|
230
|
+
loadArticleData,
|
|
148
231
|
saveInMemory
|
|
149
232
|
};
|
|
150
233
|
//# 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"],"sourcesContent":["export const ALL = \"*\"\n\nexport const LOG_CATEGORIES = [\n \"NoLicense\",\n \"Scenario\",\n \"Favorites\",\n \"Subscription\",\n \"Share\",\n \"Document\",\n \"Search\",\n \"History\",\n \"Notification\",\n \"UserProfile\",\n] as const;\n\nexport const LOG_LEVELS = {\n critical: 2,\n error: 3,\n warning: 4,\n info: 6,\n debug: 7,\n} as const;\n\nexport const API = {\n MAX_RETRY: 3,\n API_TIMEOUT: 10000,\n API_HEADERS: {\n \"content-Type\": \"application/json\",\n },\n};\n\nexport const SDK_CONFIG_KEY = \"crex-sdk-config\";\n\nexport const CONTENT_LANG_KEY = \"CONTENT_LANG_KEY\";\n\nexport const UI_LANG_KEY = \"UI_LANG_KEY\";\n\nexport const FLAGS_BY_LANG = {\n \"en\": \"US\",\n \"de\": \"DE\",\n};\n\nexport const DEFAULT_UI_LANG = \"en\";\nexport const UI_LANG_OPTIONS = [\"en\", \"de\"];","import { FLAGS_BY_LANG } from \"@c-rex/constants\";\n\nexport const call = async<T = unknown>(method: string, params?: any): Promise<T> => {\n try {\n const res = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/api/rpc`, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({ method, params }),\n });\n\n const json = await res.json();\n\n if (!res.ok) throw new Error(json.error || 'Unknown error');\n\n return json.data;\n } catch (error) {\n console.error(error);\n return null as any;\n }\n}\n\nexport const getCountryCodeByLang = (lang: string): string => {\n const mappedKeys = Object.keys(FLAGS_BY_LANG);\n\n if (!mappedKeys.includes(lang)) {\n return lang\n }\n\n type LangKey = keyof typeof FLAGS_BY_LANG;\n const country = FLAGS_BY_LANG[lang as LangKey]\n\n return country\n}","export function isBrowser() {\n return typeof window !== 'undefined' && typeof document !== 'undefined';\n}\n\nexport function saveInMemory(value: any, key: string) {\n if (isBrowser()) throw new Error(\"saveInMemory is not supported in browser\");\n\n if (typeof global !== 'undefined' && !(key in global)) {\n (global as any)[key] = null;\n }\n\n const globalConfig = (global as any)[key] as any;\n\n if (globalConfig === null) {\n (global as any)[key] = value;\n }\n}\n\nexport function getFromMemory(key: string): any {\n if (isBrowser()) throw new Error(\"getFromMemory is not supported in browser\");\n\n return (global as any)[key];\n}\n","import { TreeOfContent } from \"@c-rex/interfaces\";\n\nexport const generateBreadcrumbItems = (\n treeOfContent: TreeOfContent[],\n): TreeOfContent[] => {\n const result: TreeOfContent[] = [];\n\n treeOfContent.forEach((item) => {\n if (item.active) {\n const filteredChildren = generateBreadcrumbItems(item.children);\n result.push(item, ...filteredChildren);\n }\n });\n\n return result;\n};\n","import { clsx, type ClassValue } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nexport function cn(...inputs: ClassValue[]) {\n return twMerge(clsx(inputs));\n}\n","import { DirectoryNodesService } from \"@c-rex/services\";\nimport { DirectoryNodes, informationUnitsDirectories, TreeOfContent } from \"@c-rex/interfaces\";\n\nexport const generateTreeOfContent = async (\n directoryNodes: DirectoryNodes[],\n): Promise<TreeOfContent[]> => {\n\n const service = new DirectoryNodesService();\n\n if (directoryNodes.length == 0) return [];\n if (directoryNodes[0] == undefined) return [];\n\n let id = directoryNodes[0].shortId;\n let response = await service.getItem(id);\n const childList = await getChildrenInfo(response.childNodes);\n let result: TreeOfContent[] = childList;\n\n while (response.parents != undefined) {\n if (response.informationUnits[0] == undefined) return result;\n if (response.labels[0] == undefined) return result;\n if (response.parents[0] == undefined) return result;\n\n const infoId = response.informationUnits[0].shortId;\n const aux = {\n active: true,\n label: response.labels[0].value,\n id: response.shortId,\n link: `/info/${infoId}`,\n children: [...result],\n };\n id = response.parents[0].shortId;\n response = await service.getItem(id);\n\n const tree = await getChildrenInfo(response.childNodes, aux);\n\n result = [...tree];\n }\n\n return result;\n};\n\nconst getChildrenInfo = async (\n childNodes: informationUnitsDirectories[],\n childItem?: TreeOfContent,\n): Promise<TreeOfContent[]> => {\n const result: TreeOfContent[] = [];\n if (childNodes == undefined) return result;\n\n for (const item of childNodes) {\n if (item.labels[0] == undefined) break;\n\n const infoId = await getLink(item.shortId);\n let resultItem: TreeOfContent = {\n active: false,\n label: item.labels[0].value,\n link: `/info/${infoId}`,\n id: item.shortId,\n children: [],\n };\n\n if (childItem?.id == item.shortId) {\n resultItem = childItem;\n }\n result.push(resultItem);\n }\n\n return result;\n};\n\nconst getLink = async (id: string): Promise<string> => {\n const service = new DirectoryNodesService();\n const response = await service.getItem(id);\n\n if (response.informationUnits == undefined) return \"\";\n if (response.informationUnits[0] == undefined) return \"\";\n\n return response.informationUnits[0].shortId;\n};","import { QueryParams } from '@c-rex/types';\n\nexport const createParams = (fieldsList: string[], key: string = \"Fields\") =>\n fieldsList.map((item) => ({\n key: key,\n value: item,\n }));\n\nexport const generateQueryParams = (params: QueryParams[]): string => {\n const queryParams = params\n .map(\n (param) =>\n `${encodeURIComponent(param.key)}=${encodeURIComponent(param.value)}`,\n )\n .join(\"&\");\n return queryParams;\n};\n"],"mappings":";AAqCO,IAAM,gBAAgB;AAAA,EACzB,MAAM;AAAA,EACN,MAAM;AACV;;;ACtCO,IAAM,OAAO,OAAmB,QAAgB,WAA6B;AAChF,MAAI;AACA,UAAM,MAAM,MAAM,MAAM,GAAG,QAAQ,IAAI,mBAAmB,YAAY;AAAA,MAClE,QAAQ;AAAA,MACR,SAAS,EAAE,gBAAgB,mBAAmB;AAAA,MAC9C,MAAM,KAAK,UAAU,EAAE,QAAQ,OAAO,CAAC;AAAA,IAC3C,CAAC;AAED,UAAM,OAAO,MAAM,IAAI,KAAK;AAE5B,QAAI,CAAC,IAAI,GAAI,OAAM,IAAI,MAAM,KAAK,SAAS,eAAe;AAE1D,WAAO,KAAK;AAAA,EAChB,SAAS,OAAO;AACZ,YAAQ,MAAM,KAAK;AACnB,WAAO;AAAA,EACX;AACJ;AAEO,IAAM,uBAAuB,CAAC,SAAyB;AAC1D,QAAM,aAAa,OAAO,KAAK,aAAa;AAE5C,MAAI,CAAC,WAAW,SAAS,IAAI,GAAG;AAC5B,WAAO;AAAA,EACX;AAGA,QAAM,UAAU,cAAc,IAAe;AAE7C,SAAO;AACX;;;AChCO,SAAS,YAAY;AACxB,SAAO,OAAO,WAAW,eAAe,OAAO,aAAa;AAChE;AAEO,SAAS,aAAa,OAAY,KAAa;AAClD,MAAI,UAAU,EAAG,OAAM,IAAI,MAAM,0CAA0C;AAE3E,MAAI,OAAO,WAAW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AM,cAAc,OACf;AAAA,IACG,CAAC,UACG,GAAG,mBAAmB,MAAM,GAAG,CAAC,IAAI,mBAAmB,MAAM,KAAK,CAAC;AAAA,EAC3E,EACC,KAAK,GAAG;AACb,SAAO;AACX;","names":[]}
|
|
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,I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,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":[]}
|
package/dist/next-cookies.d.mts
CHANGED
|
@@ -1,7 +1,23 @@
|
|
|
1
1
|
import { ConfigInterface } from '@c-rex/interfaces';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
+
/**
|
|
17
|
+
* Retrieves and parses configuration data from a cookie.
|
|
18
|
+
* @returns The parsed configuration object
|
|
19
|
+
* @throws Error if the configuration cookie is not found or cannot be parsed
|
|
20
|
+
*/
|
|
21
|
+
declare const getConfigs: () => ConfigInterface;
|
|
6
22
|
|
|
7
|
-
export { getConfigs,
|
|
23
|
+
export { getConfigs, getCookieFromBack, setCookie };
|
package/dist/next-cookies.d.ts
CHANGED
|
@@ -1,7 +1,23 @@
|
|
|
1
1
|
import { ConfigInterface } from '@c-rex/interfaces';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
+
/**
|
|
17
|
+
* Retrieves and parses configuration data from a cookie.
|
|
18
|
+
* @returns The parsed configuration object
|
|
19
|
+
* @throws Error if the configuration cookie is not found or cannot be parsed
|
|
20
|
+
*/
|
|
21
|
+
declare const getConfigs: () => ConfigInterface;
|
|
6
22
|
|
|
7
|
-
export { getConfigs,
|
|
23
|
+
export { getConfigs, getCookieFromBack, setCookie };
|
package/dist/next-cookies.js
CHANGED
|
@@ -22,24 +22,34 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
22
22
|
var next_cookies_exports = {};
|
|
23
23
|
__export(next_cookies_exports, {
|
|
24
24
|
getConfigs: () => getConfigs,
|
|
25
|
-
|
|
25
|
+
getCookieFromBack: () => getCookieFromBack,
|
|
26
26
|
setCookie: () => setCookie
|
|
27
27
|
});
|
|
28
28
|
module.exports = __toCommonJS(next_cookies_exports);
|
|
29
29
|
|
|
30
30
|
// ../constants/src/index.ts
|
|
31
31
|
var SDK_CONFIG_KEY = "crex-sdk-config";
|
|
32
|
+
var DEFAULT_COOKIE_LIMIT = 7 * 24 * 60 * 60 * 1e3;
|
|
32
33
|
|
|
33
34
|
// src/next-cookies.ts
|
|
34
35
|
var import_headers = require("next/headers");
|
|
35
|
-
var
|
|
36
|
-
|
|
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`);
|
|
37
42
|
};
|
|
38
|
-
var setCookie =
|
|
39
|
-
(
|
|
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
|
+
});
|
|
40
50
|
};
|
|
41
|
-
var getConfigs =
|
|
42
|
-
const jsonConfigs =
|
|
51
|
+
var getConfigs = () => {
|
|
52
|
+
const jsonConfigs = getCookieFromBack(SDK_CONFIG_KEY);
|
|
43
53
|
if (!jsonConfigs) {
|
|
44
54
|
throw new Error("Configs not found");
|
|
45
55
|
}
|
|
@@ -49,7 +59,7 @@ var getConfigs = async () => {
|
|
|
49
59
|
// Annotate the CommonJS export names for ESM import in node:
|
|
50
60
|
0 && (module.exports = {
|
|
51
61
|
getConfigs,
|
|
52
|
-
|
|
62
|
+
getCookieFromBack,
|
|
53
63
|
setCookie
|
|
54
64
|
});
|
|
55
65
|
//# 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 { SDK_CONFIG_KEY } from '@c-rex/constants';\nimport { ConfigInterface } from '@c-rex/interfaces';\nimport { cookies } from 'next/headers';\n\nexport const
|
|
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":[]}
|
package/dist/next-cookies.mjs
CHANGED
|
@@ -2,17 +2,27 @@
|
|
|
2
2
|
|
|
3
3
|
// ../constants/src/index.ts
|
|
4
4
|
var SDK_CONFIG_KEY = "crex-sdk-config";
|
|
5
|
+
var DEFAULT_COOKIE_LIMIT = 7 * 24 * 60 * 60 * 1e3;
|
|
5
6
|
|
|
6
7
|
// src/next-cookies.ts
|
|
7
8
|
import { cookies } from "next/headers";
|
|
8
|
-
var
|
|
9
|
-
|
|
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`);
|
|
10
15
|
};
|
|
11
|
-
var setCookie =
|
|
12
|
-
|
|
16
|
+
var setCookie = (key, value) => {
|
|
17
|
+
cookies().set(key, value, {
|
|
18
|
+
path: "/",
|
|
19
|
+
secure: true,
|
|
20
|
+
httpOnly: true,
|
|
21
|
+
maxAge: DEFAULT_COOKIE_LIMIT
|
|
22
|
+
});
|
|
13
23
|
};
|
|
14
|
-
var getConfigs =
|
|
15
|
-
const jsonConfigs =
|
|
24
|
+
var getConfigs = () => {
|
|
25
|
+
const jsonConfigs = getCookieFromBack(SDK_CONFIG_KEY);
|
|
16
26
|
if (!jsonConfigs) {
|
|
17
27
|
throw new Error("Configs not found");
|
|
18
28
|
}
|
|
@@ -21,7 +31,7 @@ var getConfigs = async () => {
|
|
|
21
31
|
};
|
|
22
32
|
export {
|
|
23
33
|
getConfigs,
|
|
24
|
-
|
|
34
|
+
getCookieFromBack,
|
|
25
35
|
setCookie
|
|
26
36
|
};
|
|
27
37
|
//# 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 API = {\n MAX_RETRY: 3,\n API_TIMEOUT: 10000,\n API_HEADERS: {\n \"content-Type\": \"application/json\",\n },\n};\n\nexport const SDK_CONFIG_KEY = \"crex-sdk-config\";\n\nexport const CONTENT_LANG_KEY = \"CONTENT_LANG_KEY\";\n\nexport const UI_LANG_KEY = \"UI_LANG_KEY\";\n\nexport const FLAGS_BY_LANG = {\n \"en\": \"US\",\n \"de\": \"DE\",\n};\n\nexport const
|
|
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":[]}
|
package/package.json
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@c-rex/utils",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"main": "./dist/index.js",
|
|
5
|
-
"types": "./dist/index.d.ts",
|
|
6
|
-
"module": "./dist/index.mjs",
|
|
3
|
+
"version": "0.1.3",
|
|
7
4
|
"files": [
|
|
8
5
|
"dist"
|
|
9
6
|
],
|
|
@@ -14,7 +11,9 @@
|
|
|
14
11
|
"dev": "tsup --watch",
|
|
15
12
|
"build": "tsup",
|
|
16
13
|
"test:watch": "jest --watch",
|
|
17
|
-
"test": "jest"
|
|
14
|
+
"test": "jest",
|
|
15
|
+
"lint": "eslint .",
|
|
16
|
+
"lint:fix": "eslint . --fix"
|
|
18
17
|
},
|
|
19
18
|
"exports": {
|
|
20
19
|
".": {
|
|
@@ -23,7 +22,6 @@
|
|
|
23
22
|
"require": "./dist/index.js",
|
|
24
23
|
"default": "./dist/index.js"
|
|
25
24
|
},
|
|
26
|
-
"./package.json": "./package.json",
|
|
27
25
|
"./next-cookies": {
|
|
28
26
|
"types": "./dist/next-cookies.d.ts",
|
|
29
27
|
"import": "./dist/next-cookies.mjs",
|