@c-rex/utils 0.1.14 → 0.1.15
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/cookies.d.mts +13 -0
- package/dist/cookies.d.ts +13 -0
- package/dist/cookies.js +49 -0
- package/dist/cookies.js.map +1 -0
- package/dist/cookies.mjs +23 -0
- package/dist/cookies.mjs.map +1 -0
- package/dist/index.d.mts +1 -35
- package/dist/index.d.ts +1 -35
- package/dist/index.js +2 -17
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -14
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -1
- package/dist/next-cookies.d.mts +0 -2
- package/dist/next-cookies.d.ts +0 -2
- package/dist/next-cookies.js +0 -3
- package/dist/next-cookies.js.map +0 -1
- package/dist/next-cookies.mjs +0 -2
- package/dist/next-cookies.mjs.map +0 -1
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sets a client-side cookie with the specified name, value, and expiration.
|
|
3
|
+
* This function manipulates cookies that are NOT httpOnly, meaning they are accessible via JavaScript.
|
|
4
|
+
* Cannot be used with httpOnly cookies as those are only accessible server-side.
|
|
5
|
+
*
|
|
6
|
+
* @param name - The name of the cookie to set
|
|
7
|
+
* @param value - The value to store in the cookie (will be URL encoded)
|
|
8
|
+
* @param days - Number of days until the cookie expires (default: 30 days)
|
|
9
|
+
* @throws {Error} When document is not defined (e.g., in server-side environment)
|
|
10
|
+
*/
|
|
11
|
+
declare const setCookie: (name: string, value: string, options?: any) => void;
|
|
12
|
+
|
|
13
|
+
export { setCookie };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sets a client-side cookie with the specified name, value, and expiration.
|
|
3
|
+
* This function manipulates cookies that are NOT httpOnly, meaning they are accessible via JavaScript.
|
|
4
|
+
* Cannot be used with httpOnly cookies as those are only accessible server-side.
|
|
5
|
+
*
|
|
6
|
+
* @param name - The name of the cookie to set
|
|
7
|
+
* @param value - The value to store in the cookie (will be URL encoded)
|
|
8
|
+
* @param days - Number of days until the cookie expires (default: 30 days)
|
|
9
|
+
* @throws {Error} When document is not defined (e.g., in server-side environment)
|
|
10
|
+
*/
|
|
11
|
+
declare const setCookie: (name: string, value: string, options?: any) => void;
|
|
12
|
+
|
|
13
|
+
export { setCookie };
|
package/dist/cookies.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use server";
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
|
|
21
|
+
// src/cookies.ts
|
|
22
|
+
var cookies_exports = {};
|
|
23
|
+
__export(cookies_exports, {
|
|
24
|
+
setCookie: () => setCookie
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(cookies_exports);
|
|
27
|
+
|
|
28
|
+
// ../constants/src/index.ts
|
|
29
|
+
var DEFAULT_COOKIE_LIMIT = 30 * 24 * 60 * 60 * 1e3;
|
|
30
|
+
|
|
31
|
+
// src/cookies.ts
|
|
32
|
+
var import_headers = require("next/headers");
|
|
33
|
+
var setCookie = (name, value, options = {}) => {
|
|
34
|
+
const store = (0, import_headers.cookies)();
|
|
35
|
+
const newOptions = {
|
|
36
|
+
...options,
|
|
37
|
+
path: "/",
|
|
38
|
+
maxAge: options.maxAge || DEFAULT_COOKIE_LIMIT * 86400,
|
|
39
|
+
httpOnly: true,
|
|
40
|
+
secure: process.env.NODE_ENV === "production",
|
|
41
|
+
sameSite: "lax"
|
|
42
|
+
};
|
|
43
|
+
store.set(name, value, newOptions);
|
|
44
|
+
};
|
|
45
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
46
|
+
0 && (module.exports = {
|
|
47
|
+
setCookie
|
|
48
|
+
});
|
|
49
|
+
//# sourceMappingURL=cookies.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/cookies.ts","../../constants/src/index.ts"],"sourcesContent":["\"use server\"\n\nimport { DEFAULT_COOKIE_LIMIT } from \"@c-rex/constants\";\nimport { cookies } from \"next/headers\";\n\n/**\n * Sets a client-side cookie with the specified name, value, and expiration.\n * This function manipulates cookies that are NOT httpOnly, meaning they are accessible via JavaScript.\n * Cannot be used with httpOnly cookies as those are only accessible server-side.\n * \n * @param name - The name of the cookie to set\n * @param value - The value to store in the cookie (will be URL encoded)\n * @param days - Number of days until the cookie expires (default: 30 days)\n * @throws {Error} When document is not defined (e.g., in server-side environment)\n */\nexport const setCookie = (name: string, value: string, options: any = {}) => {\n const store = cookies();\n\n const newOptions = {\n ...options,\n path: '/',\n maxAge: options.maxAge || DEFAULT_COOKIE_LIMIT * 86400,\n httpOnly: true,\n secure: process.env.NODE_ENV === 'production',\n sameSite: 'lax',\n };\n\n store.set(name, value, newOptions);\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 \"table-with-images\",\n] as const;\n\nexport const API = {\n MAX_RETRY: 3,\n API_TIMEOUT: 10000,\n RETRY_DELAY: 500,\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\";\nexport const FRAGMENT = \"FRAGMENT\";\n\nexport const RESULT_TYPES = {\n TOPIC: TOPIC,\n DOCUMENT: DOCUMENT,\n PACKAGE: PACKAGE,\n FRAGMENT: FRAGMENT\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 = 30 * 24 * 60 * 60 * 1000; // 30 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\";\n\nexport const WILD_CARD_OPTIONS = {\n BOTH: \"BOTH\",\n END: \"END\",\n START: \"START\",\n NONE: \"NONE\",\n} as const;\n\nexport const OPERATOR_OPTIONS = {\n AND: \"AND\",\n OR: \"OR\",\n} as const;\n\nexport const ARTICLE_PAGE_LAYOUT = {\n BLOG: \"BLOG\",\n DOCUMENT: \"DOCUMENT\",\n} as const;\n\nexport const DEVICE_OPTIONS = {\n MOBILE: \"mobile\",\n TABLET: \"tablet\",\n DESKTOP: \"desktop\",\n}\nexport const BREAKPOINTS = {\n sm: 640,\n md: 768,\n lg: 1024,\n xl: 1280,\n \"2xl\": 1536,\n};\n\nexport const MARKER_COLORS = [\n \"red-500\",\n \"orange-500\",\n \"yellow-400\",\n \"green-500\",\n \"teal-500\",\n \"blue-500\",\n \"sky-500\",\n \"purple-500\",\n \"pink-500\",\n \"gray-500\",\n \"neutral-800\",\n \"cyan-500\",\n \"lime-500\",\n \"amber-500\",\n \"indigo-500\",\n];"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;AC8EO,IAAM,uBAAuB,KAAK,KAAK,KAAK,KAAK;;;AD3ExD,qBAAwB;AAYjB,IAAM,YAAY,CAAC,MAAc,OAAe,UAAe,CAAC,MAAM;AACzE,QAAM,YAAQ,wBAAQ;AAEtB,QAAM,aAAa;AAAA,IACf,GAAG;AAAA,IACH,MAAM;AAAA,IACN,QAAQ,QAAQ,UAAU,uBAAuB;AAAA,IACjD,UAAU;AAAA,IACV,QAAQ,QAAQ,IAAI,aAAa;AAAA,IACjC,UAAU;AAAA,EACd;AAEA,QAAM,IAAI,MAAM,OAAO,UAAU;AACrC;","names":[]}
|
package/dist/cookies.mjs
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use server";
|
|
2
|
+
|
|
3
|
+
// ../constants/src/index.ts
|
|
4
|
+
var DEFAULT_COOKIE_LIMIT = 30 * 24 * 60 * 60 * 1e3;
|
|
5
|
+
|
|
6
|
+
// src/cookies.ts
|
|
7
|
+
import { cookies } from "next/headers";
|
|
8
|
+
var setCookie = (name, value, options = {}) => {
|
|
9
|
+
const store = cookies();
|
|
10
|
+
const newOptions = {
|
|
11
|
+
...options,
|
|
12
|
+
path: "/",
|
|
13
|
+
maxAge: options.maxAge || DEFAULT_COOKIE_LIMIT * 86400,
|
|
14
|
+
httpOnly: true,
|
|
15
|
+
secure: process.env.NODE_ENV === "production",
|
|
16
|
+
sameSite: "lax"
|
|
17
|
+
};
|
|
18
|
+
store.set(name, value, newOptions);
|
|
19
|
+
};
|
|
20
|
+
export {
|
|
21
|
+
setCookie
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=cookies.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../constants/src/index.ts","../src/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 \"table-with-images\",\n] as const;\n\nexport const API = {\n MAX_RETRY: 3,\n API_TIMEOUT: 10000,\n RETRY_DELAY: 500,\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\";\nexport const FRAGMENT = \"FRAGMENT\";\n\nexport const RESULT_TYPES = {\n TOPIC: TOPIC,\n DOCUMENT: DOCUMENT,\n PACKAGE: PACKAGE,\n FRAGMENT: FRAGMENT\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 = 30 * 24 * 60 * 60 * 1000; // 30 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\";\n\nexport const WILD_CARD_OPTIONS = {\n BOTH: \"BOTH\",\n END: \"END\",\n START: \"START\",\n NONE: \"NONE\",\n} as const;\n\nexport const OPERATOR_OPTIONS = {\n AND: \"AND\",\n OR: \"OR\",\n} as const;\n\nexport const ARTICLE_PAGE_LAYOUT = {\n BLOG: \"BLOG\",\n DOCUMENT: \"DOCUMENT\",\n} as const;\n\nexport const DEVICE_OPTIONS = {\n MOBILE: \"mobile\",\n TABLET: \"tablet\",\n DESKTOP: \"desktop\",\n}\nexport const BREAKPOINTS = {\n sm: 640,\n md: 768,\n lg: 1024,\n xl: 1280,\n \"2xl\": 1536,\n};\n\nexport const MARKER_COLORS = [\n \"red-500\",\n \"orange-500\",\n \"yellow-400\",\n \"green-500\",\n \"teal-500\",\n \"blue-500\",\n \"sky-500\",\n \"purple-500\",\n \"pink-500\",\n \"gray-500\",\n \"neutral-800\",\n \"cyan-500\",\n \"lime-500\",\n \"amber-500\",\n \"indigo-500\",\n];","\"use server\"\n\nimport { DEFAULT_COOKIE_LIMIT } from \"@c-rex/constants\";\nimport { cookies } from \"next/headers\";\n\n/**\n * Sets a client-side cookie with the specified name, value, and expiration.\n * This function manipulates cookies that are NOT httpOnly, meaning they are accessible via JavaScript.\n * Cannot be used with httpOnly cookies as those are only accessible server-side.\n * \n * @param name - The name of the cookie to set\n * @param value - The value to store in the cookie (will be URL encoded)\n * @param days - Number of days until the cookie expires (default: 30 days)\n * @throws {Error} When document is not defined (e.g., in server-side environment)\n */\nexport const setCookie = (name: string, value: string, options: any = {}) => {\n const store = cookies();\n\n const newOptions = {\n ...options,\n path: '/',\n maxAge: options.maxAge || DEFAULT_COOKIE_LIMIT * 86400,\n httpOnly: true,\n secure: process.env.NODE_ENV === 'production',\n sameSite: 'lax',\n };\n\n store.set(name, value, newOptions);\n}"],"mappings":";;;AA8EO,IAAM,uBAAuB,KAAK,KAAK,KAAK,KAAK;;;AC3ExD,SAAS,eAAe;AAYjB,IAAM,YAAY,CAAC,MAAc,OAAe,UAAe,CAAC,MAAM;AACzE,QAAM,QAAQ,QAAQ;AAEtB,QAAM,aAAa;AAAA,IACf,GAAG;AAAA,IACH,MAAM;AAAA,IACN,QAAQ,QAAQ,UAAU,uBAAuB;AAAA,IACjD,UAAU;AAAA,IACV,QAAQ,QAAQ,IAAI,aAAa;AAAA,IACjC,UAAU;AAAA,EACd;AAEA,QAAM,IAAI,MAAM,OAAO,UAAU;AACrC;","names":[]}
|
package/dist/index.d.mts
CHANGED
|
@@ -57,38 +57,4 @@ declare const getFileRenditions: ({ renditions }: {
|
|
|
57
57
|
*/
|
|
58
58
|
declare const call: <T = unknown>(method: string, params?: any) => Promise<T>;
|
|
59
59
|
|
|
60
|
-
|
|
61
|
-
* Sets a client-side cookie with the specified name, value, and expiration.
|
|
62
|
-
* This function manipulates cookies that are NOT httpOnly, meaning they are accessible via JavaScript.
|
|
63
|
-
* Cannot be used with httpOnly cookies as those are only accessible server-side.
|
|
64
|
-
*
|
|
65
|
-
* @param name - The name of the cookie to set
|
|
66
|
-
* @param value - The value to store in the cookie (will be URL encoded)
|
|
67
|
-
* @param days - Number of days until the cookie expires (default: 365)
|
|
68
|
-
* @throws {Error} When document is not defined (e.g., in server-side environment)
|
|
69
|
-
*
|
|
70
|
-
* @example
|
|
71
|
-
* ```typescript
|
|
72
|
-
* setCookie('userToken', 'abc123', 30); // Expires in 30 days
|
|
73
|
-
* setCookie('theme', 'dark'); // Expires in 365 days (default)
|
|
74
|
-
* ```
|
|
75
|
-
*/
|
|
76
|
-
declare const setCookie: (name: string, value: string, days?: number) => void;
|
|
77
|
-
/**
|
|
78
|
-
* Retrieves the value of a client-side cookie by its name.
|
|
79
|
-
* This function reads cookies that are NOT httpOnly, meaning they are accessible via JavaScript.
|
|
80
|
-
* Cannot be used with httpOnly cookies as those are only accessible server-side.
|
|
81
|
-
*
|
|
82
|
-
* @param name - The name of the cookie to retrieve
|
|
83
|
-
* @returns The decoded cookie value, or an empty string if the cookie doesn't exist
|
|
84
|
-
* @throws {Error} When document is not defined (e.g., in server-side environment)
|
|
85
|
-
*
|
|
86
|
-
* @example
|
|
87
|
-
* ```typescript
|
|
88
|
-
* const token = getCookieFromDocument('userToken'); // Returns cookie value or ''
|
|
89
|
-
* const theme = getCookieFromDocument('theme'); // Returns cookie value or ''
|
|
90
|
-
* ```
|
|
91
|
-
*/
|
|
92
|
-
declare const getCookieFromDocument: (name: string) => string;
|
|
93
|
-
|
|
94
|
-
export { call, cn, createAvailableVersionList, createParams, formatDateToLocale, generateBreadcrumbItems, generateQueryParams, generateTreeOfContent, getCookieFromDocument, getCountryCodeByLang, getFileRenditions, setCookie };
|
|
60
|
+
export { call, cn, createAvailableVersionList, createParams, formatDateToLocale, generateBreadcrumbItems, generateQueryParams, generateTreeOfContent, getCountryCodeByLang, getFileRenditions };
|
package/dist/index.d.ts
CHANGED
|
@@ -57,38 +57,4 @@ declare const getFileRenditions: ({ renditions }: {
|
|
|
57
57
|
*/
|
|
58
58
|
declare const call: <T = unknown>(method: string, params?: any) => Promise<T>;
|
|
59
59
|
|
|
60
|
-
|
|
61
|
-
* Sets a client-side cookie with the specified name, value, and expiration.
|
|
62
|
-
* This function manipulates cookies that are NOT httpOnly, meaning they are accessible via JavaScript.
|
|
63
|
-
* Cannot be used with httpOnly cookies as those are only accessible server-side.
|
|
64
|
-
*
|
|
65
|
-
* @param name - The name of the cookie to set
|
|
66
|
-
* @param value - The value to store in the cookie (will be URL encoded)
|
|
67
|
-
* @param days - Number of days until the cookie expires (default: 365)
|
|
68
|
-
* @throws {Error} When document is not defined (e.g., in server-side environment)
|
|
69
|
-
*
|
|
70
|
-
* @example
|
|
71
|
-
* ```typescript
|
|
72
|
-
* setCookie('userToken', 'abc123', 30); // Expires in 30 days
|
|
73
|
-
* setCookie('theme', 'dark'); // Expires in 365 days (default)
|
|
74
|
-
* ```
|
|
75
|
-
*/
|
|
76
|
-
declare const setCookie: (name: string, value: string, days?: number) => void;
|
|
77
|
-
/**
|
|
78
|
-
* Retrieves the value of a client-side cookie by its name.
|
|
79
|
-
* This function reads cookies that are NOT httpOnly, meaning they are accessible via JavaScript.
|
|
80
|
-
* Cannot be used with httpOnly cookies as those are only accessible server-side.
|
|
81
|
-
*
|
|
82
|
-
* @param name - The name of the cookie to retrieve
|
|
83
|
-
* @returns The decoded cookie value, or an empty string if the cookie doesn't exist
|
|
84
|
-
* @throws {Error} When document is not defined (e.g., in server-side environment)
|
|
85
|
-
*
|
|
86
|
-
* @example
|
|
87
|
-
* ```typescript
|
|
88
|
-
* const token = getCookieFromDocument('userToken'); // Returns cookie value or ''
|
|
89
|
-
* const theme = getCookieFromDocument('theme'); // Returns cookie value or ''
|
|
90
|
-
* ```
|
|
91
|
-
*/
|
|
92
|
-
declare const getCookieFromDocument: (name: string) => string;
|
|
93
|
-
|
|
94
|
-
export { call, cn, createAvailableVersionList, createParams, formatDateToLocale, generateBreadcrumbItems, generateQueryParams, generateTreeOfContent, getCookieFromDocument, getCountryCodeByLang, getFileRenditions, setCookie };
|
|
60
|
+
export { call, cn, createAvailableVersionList, createParams, formatDateToLocale, generateBreadcrumbItems, generateQueryParams, generateTreeOfContent, getCountryCodeByLang, getFileRenditions };
|
package/dist/index.js
CHANGED
|
@@ -28,10 +28,8 @@ __export(index_exports, {
|
|
|
28
28
|
generateBreadcrumbItems: () => generateBreadcrumbItems,
|
|
29
29
|
generateQueryParams: () => generateQueryParams,
|
|
30
30
|
generateTreeOfContent: () => generateTreeOfContent,
|
|
31
|
-
getCookieFromDocument: () => getCookieFromDocument,
|
|
32
31
|
getCountryCodeByLang: () => getCountryCodeByLang,
|
|
33
|
-
getFileRenditions: () => getFileRenditions
|
|
34
|
-
setCookie: () => setCookie
|
|
32
|
+
getFileRenditions: () => getFileRenditions
|
|
35
33
|
});
|
|
36
34
|
module.exports = __toCommonJS(index_exports);
|
|
37
35
|
|
|
@@ -206,17 +204,6 @@ var getFileRenditions = ({ renditions }) => {
|
|
|
206
204
|
});
|
|
207
205
|
return result;
|
|
208
206
|
};
|
|
209
|
-
|
|
210
|
-
// src/cookies.ts
|
|
211
|
-
var setCookie = (name, value, days = 365) => {
|
|
212
|
-
if (!document) throw new Error("Document is not defined");
|
|
213
|
-
const expires = new Date(Date.now() + days * 864e5).toUTCString();
|
|
214
|
-
document.cookie = `${name}=${encodeURIComponent(value)}; expires=${expires}; path=/`;
|
|
215
|
-
};
|
|
216
|
-
var getCookieFromDocument = (name) => {
|
|
217
|
-
if (!document) throw new Error("Document is not defined");
|
|
218
|
-
return document.cookie.split("; ").find((row) => row.startsWith(name + "="))?.split("=")[1] || "";
|
|
219
|
-
};
|
|
220
207
|
// Annotate the CommonJS export names for ESM import in node:
|
|
221
208
|
0 && (module.exports = {
|
|
222
209
|
call,
|
|
@@ -227,9 +214,7 @@ var getCookieFromDocument = (name) => {
|
|
|
227
214
|
generateBreadcrumbItems,
|
|
228
215
|
generateQueryParams,
|
|
229
216
|
generateTreeOfContent,
|
|
230
|
-
getCookieFromDocument,
|
|
231
217
|
getCountryCodeByLang,
|
|
232
|
-
getFileRenditions
|
|
233
|
-
setCookie
|
|
218
|
+
getFileRenditions
|
|
234
219
|
});
|
|
235
220
|
//# 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/breadcrumbs.ts","../src/classMerge.ts","../src/call.ts","../src/treeOfContent.ts","../src/params.ts","../src/renditions.ts","../src/cookies.ts"],"sourcesContent":["export * from './utils';\nexport * from './breadcrumbs';\nexport * from './classMerge';\nexport * from './treeOfContent';\nexport * from './params';\nexport * from './renditions';\nexport * from './call';\nexport * from './cookies';","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 \"table-with-images\",\n] as const;\n\nexport const API = {\n MAX_RETRY: 3,\n API_TIMEOUT: 10000,\n RETRY_DELAY: 500,\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\";\nexport const FRAGMENT = \"FRAGMENT\";\n\nexport const RESULT_TYPES = {\n TOPIC: TOPIC,\n DOCUMENT: DOCUMENT,\n PACKAGE: PACKAGE,\n FRAGMENT: FRAGMENT\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 = 30 * 24 * 60 * 60 * 1000; // 30 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\";\n\nexport const WILD_CARD_OPTIONS = {\n BOTH: \"BOTH\",\n END: \"END\",\n START: \"START\",\n NONE: \"NONE\",\n} as const;\n\nexport const OPERATOR_OPTIONS = {\n AND: \"AND\",\n OR: \"OR\",\n} as const;\n\nexport const ARTICLE_PAGE_LAYOUT = {\n BLOG: \"BLOG\",\n DOCUMENT: \"DOCUMENT\",\n} as const;\n\nexport const DEVICE_OPTIONS = {\n MOBILE: \"mobile\",\n TABLET: \"tablet\",\n DESKTOP: \"desktop\",\n}\nexport const BREAKPOINTS = {\n sm: 640,\n md: 768,\n lg: 1024,\n xl: 1280,\n \"2xl\": 1536,\n};\n\nexport const MARKER_COLORS = [\n \"red-500\",\n \"orange-500\",\n \"yellow-400\",\n \"green-500\",\n \"teal-500\",\n \"blue-500\",\n \"sky-500\",\n \"purple-500\",\n \"pink-500\",\n \"gray-500\",\n \"neutral-800\",\n \"cyan-500\",\n \"lime-500\",\n \"amber-500\",\n \"indigo-500\",\n];","import { FLAGS_BY_LANG } from \"@c-rex/constants\";\nimport { AvailableVersionsInterface, informationUnitsResponseItem } from \"@c-rex/interfaces\";\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 formatDateToLocale = (date: string, locale: string): string => {\n if (typeof date !== 'string' || !date) {\n return date;\n }\n\n const dateAux = new Date(date);\n return new Intl.DateTimeFormat(locale, {\n day: '2-digit',\n month: 'long',\n year: 'numeric'\n }).format(dateAux);\n}\n\nexport const createAvailableVersionList = (\n versions: informationUnitsResponseItem[],\n articleLang: string,\n type: string\n): AvailableVersionsInterface[] => {\n\n const availableVersions = versions.map(item => {\n return {\n shortId: item.shortId,\n active: item.language === articleLang,\n lang: item.language,\n country: item.language.split(\"-\")[1],\n link: `/${type}/${item.shortId}`,\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 }) as AvailableVersionsInterface[];\n\n return availableVersions;\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","/**\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 const res = await fetch(`/api/rpc`, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({ method, params }),\n credentials: 'include',\n });\n\n const json = await res.json();\n\n if (!res.ok) throw new Error(json.error || 'Unknown error');\n\n return json.data;\n}","import { DirectoryNodes, DefaultCrexDirectories, TreeOfContent } from \"@c-rex/interfaces\";\nimport { call } from \"./call\";\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<TreeOfContent[]> => {\n if (!directoryNodes?.length) return [];\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 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 result;\n};\n\nasync function getChildrenInfo(\n childNodes: DefaultCrexDirectories[] | 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 if (!fieldsList || fieldsList.length === 0) {\n return [];\n }\n\n return fieldsList.map((item) => ({\n key: key,\n value: item,\n }));\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((param) => `${encodeURIComponent(param.key)}=${encodeURIComponent(param.value)}`)\n .join(\"&\");\n return queryParams;\n};\n","import { informationUnitsRenditions } from \"@c-rex/interfaces\";\nimport { DocumentsType } from \"@c-rex/types\";\n\n\nexport const getFileRenditions = ({ renditions }: { renditions: informationUnitsRenditions[] }): DocumentsType => {\n if (renditions == undefined || renditions.length == 0) {\n return {};\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 }\n\n const result: {\n [key: string]: {\n view: string;\n download: string;\n }\n } = {}\n\n filteredRenditions.forEach((item) => {\n const key = item.format\n\n if (result[key] == undefined) {\n result[key] = {\n view: \"\",\n download: \"\"\n }\n }\n\n result[key].download = item.links.filter((link) => link.rel == \"download\")[0]?.href\n result[key].view = item.links.filter((link) => link.rel == \"view\")[0]?.href\n })\n\n return result\n}","/**\n * Sets a client-side cookie with the specified name, value, and expiration.\n * This function manipulates cookies that are NOT httpOnly, meaning they are accessible via JavaScript.\n * Cannot be used with httpOnly cookies as those are only accessible server-side.\n * \n * @param name - The name of the cookie to set\n * @param value - The value to store in the cookie (will be URL encoded)\n * @param days - Number of days until the cookie expires (default: 365)\n * @throws {Error} When document is not defined (e.g., in server-side environment)\n * \n * @example\n * ```typescript\n * setCookie('userToken', 'abc123', 30); // Expires in 30 days\n * setCookie('theme', 'dark'); // Expires in 365 days (default)\n * ```\n */\nexport const setCookie = (name: string, value: string, days = 365) => {\n if (!document) throw new Error(\"Document is not defined\");\n\n const expires = new Date(Date.now() + days * 864e5).toUTCString();\n document.cookie = `${name}=${encodeURIComponent(value)}; expires=${expires}; path=/`;\n}\n\n/**\n * Retrieves the value of a client-side cookie by its name.\n * This function reads cookies that are NOT httpOnly, meaning they are accessible via JavaScript.\n * Cannot be used with httpOnly cookies as those are only accessible server-side.\n * \n * @param name - The name of the cookie to retrieve\n * @returns The decoded cookie value, or an empty string if the cookie doesn't exist\n * @throws {Error} When document is not defined (e.g., in server-side environment)\n * \n * @example\n * ```typescript\n * const token = getCookieFromDocument('userToken'); // Returns cookie value or ''\n * const theme = getCookieFromDocument('theme'); // Returns cookie value or ''\n * ```\n */\nexport const getCookieFromDocument = (name: string): string => {\n if (!document) throw new Error(\"Document is not defined\");\n\n return document.cookie\n .split('; ')\n .find(row => row.startsWith(name + '='))\n ?.split('=')[1] || '';\n}"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;AC8CO,IAAM,gBAAgB;AAAA,EACzB,MAAM;AAAA,EACN,MAAM;AACV;AA6BO,IAAM,uBAAuB,KAAK,KAAK,KAAK,KAAK;;;ACtEjD,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,"sources":["../src/index.ts","../../constants/src/index.ts","../src/utils.ts","../src/breadcrumbs.ts","../src/classMerge.ts","../src/call.ts","../src/treeOfContent.ts","../src/params.ts","../src/renditions.ts"],"sourcesContent":["export * from './utils';\nexport * from './breadcrumbs';\nexport * from './classMerge';\nexport * from './treeOfContent';\nexport * from './params';\nexport * from './renditions';\nexport * from './call';","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 \"table-with-images\",\n] as const;\n\nexport const API = {\n MAX_RETRY: 3,\n API_TIMEOUT: 10000,\n RETRY_DELAY: 500,\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\";\nexport const FRAGMENT = \"FRAGMENT\";\n\nexport const RESULT_TYPES = {\n TOPIC: TOPIC,\n DOCUMENT: DOCUMENT,\n PACKAGE: PACKAGE,\n FRAGMENT: FRAGMENT\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 = 30 * 24 * 60 * 60 * 1000; // 30 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\";\n\nexport const WILD_CARD_OPTIONS = {\n BOTH: \"BOTH\",\n END: \"END\",\n START: \"START\",\n NONE: \"NONE\",\n} as const;\n\nexport const OPERATOR_OPTIONS = {\n AND: \"AND\",\n OR: \"OR\",\n} as const;\n\nexport const ARTICLE_PAGE_LAYOUT = {\n BLOG: \"BLOG\",\n DOCUMENT: \"DOCUMENT\",\n} as const;\n\nexport const DEVICE_OPTIONS = {\n MOBILE: \"mobile\",\n TABLET: \"tablet\",\n DESKTOP: \"desktop\",\n}\nexport const BREAKPOINTS = {\n sm: 640,\n md: 768,\n lg: 1024,\n xl: 1280,\n \"2xl\": 1536,\n};\n\nexport const MARKER_COLORS = [\n \"red-500\",\n \"orange-500\",\n \"yellow-400\",\n \"green-500\",\n \"teal-500\",\n \"blue-500\",\n \"sky-500\",\n \"purple-500\",\n \"pink-500\",\n \"gray-500\",\n \"neutral-800\",\n \"cyan-500\",\n \"lime-500\",\n \"amber-500\",\n \"indigo-500\",\n];","import { FLAGS_BY_LANG } from \"@c-rex/constants\";\nimport { AvailableVersionsInterface, informationUnitsResponseItem } from \"@c-rex/interfaces\";\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 formatDateToLocale = (date: string, locale: string): string => {\n if (typeof date !== 'string' || !date) {\n return date;\n }\n\n const dateAux = new Date(date);\n return new Intl.DateTimeFormat(locale, {\n day: '2-digit',\n month: 'long',\n year: 'numeric'\n }).format(dateAux);\n}\n\nexport const createAvailableVersionList = (\n versions: informationUnitsResponseItem[],\n articleLang: string,\n type: string\n): AvailableVersionsInterface[] => {\n\n const availableVersions = versions.map(item => {\n return {\n shortId: item.shortId,\n active: item.language === articleLang,\n lang: item.language,\n country: item.language.split(\"-\")[1],\n link: `/${type}/${item.shortId}`,\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 }) as AvailableVersionsInterface[];\n\n return availableVersions;\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","/**\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 const res = await fetch(`/api/rpc`, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({ method, params }),\n credentials: 'include',\n });\n\n const json = await res.json();\n\n if (!res.ok) throw new Error(json.error || 'Unknown error');\n\n return json.data;\n}","import { DirectoryNodes, DefaultCrexDirectories, TreeOfContent } from \"@c-rex/interfaces\";\nimport { call } from \"./call\";\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<TreeOfContent[]> => {\n if (!directoryNodes?.length) return [];\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 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 result;\n};\n\nasync function getChildrenInfo(\n childNodes: DefaultCrexDirectories[] | 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 if (!fieldsList || fieldsList.length === 0) {\n return [];\n }\n\n return fieldsList.map((item) => ({\n key: key,\n value: item,\n }));\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((param) => `${encodeURIComponent(param.key)}=${encodeURIComponent(param.value)}`)\n .join(\"&\");\n return queryParams;\n};\n","import { informationUnitsRenditions } from \"@c-rex/interfaces\";\nimport { DocumentsType } from \"@c-rex/types\";\n\n\nexport const getFileRenditions = ({ renditions }: { renditions: informationUnitsRenditions[] }): DocumentsType => {\n if (renditions == undefined || renditions.length == 0) {\n return {};\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 }\n\n const result: {\n [key: string]: {\n view: string;\n download: string;\n }\n } = {}\n\n filteredRenditions.forEach((item) => {\n const key = item.format\n\n if (result[key] == undefined) {\n result[key] = {\n view: \"\",\n download: \"\"\n }\n }\n\n result[key].download = item.links.filter((link) => link.rel == \"download\")[0]?.href\n result[key].view = item.links.filter((link) => link.rel == \"view\")[0]?.href\n })\n\n return result\n}"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA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,CAAC,UAAU,GAAG,mBAAmB,MAAM,GAAG,CAAC,IAAI,mBAAmB,MAAM,KAAK,CAAC,EAAE,EACpF,KAAK,GAAG;AACb,SAAO;AACX;;;ACzBO,IAAM,oBAAoB,CAAC,EAAE,WAAW,MAAmE;AAC9G,MAAI,cAAc,UAAa,WAAW,UAAU,GAAG;AACnD,WAAO,CAAC;AAAA,EACZ;AAEA,QAAM,qBAAqB,WAAW;AAAA,IAClC,CAAC,SAAS,KAAK,UAAU,2BAA2B,KAAK,UAAU,sBAAsB,KAAK,UAAU;AAAA,EAC5G;AAEA,MAAI,mBAAmB,UAAU,KAAK,mBAAmB,CAAC,KAAK,QAAW;AACtE,WAAO,CAAC;AAAA,EACZ;AAEA,QAAM,SAKF,CAAC;AAEL,qBAAmB,QAAQ,CAAC,SAAS;AACjC,UAAM,MAAM,KAAK;AAEjB,QAAI,OAAO,GAAG,KAAK,QAAW;AAC1B,aAAO,GAAG,IAAI;AAAA,QACV,MAAM;AAAA,QACN,UAAU;AAAA,MACd;AAAA,IACJ;AAEA,WAAO,GAAG,EAAE,WAAW,KAAK,MAAM,OAAO,CAAC,SAAS,KAAK,OAAO,UAAU,EAAE,CAAC,GAAG;AAC/E,WAAO,GAAG,EAAE,OAAO,KAAK,MAAM,OAAO,CAAC,SAAS,KAAK,OAAO,MAAM,EAAE,CAAC,GAAG;AAAA,EAC3E,CAAC;AAED,SAAO;AACX;","names":[]}
|
package/dist/index.mjs
CHANGED
|
@@ -169,17 +169,6 @@ var getFileRenditions = ({ renditions }) => {
|
|
|
169
169
|
});
|
|
170
170
|
return result;
|
|
171
171
|
};
|
|
172
|
-
|
|
173
|
-
// src/cookies.ts
|
|
174
|
-
var setCookie = (name, value, days = 365) => {
|
|
175
|
-
if (!document) throw new Error("Document is not defined");
|
|
176
|
-
const expires = new Date(Date.now() + days * 864e5).toUTCString();
|
|
177
|
-
document.cookie = `${name}=${encodeURIComponent(value)}; expires=${expires}; path=/`;
|
|
178
|
-
};
|
|
179
|
-
var getCookieFromDocument = (name) => {
|
|
180
|
-
if (!document) throw new Error("Document is not defined");
|
|
181
|
-
return document.cookie.split("; ").find((row) => row.startsWith(name + "="))?.split("=")[1] || "";
|
|
182
|
-
};
|
|
183
172
|
export {
|
|
184
173
|
call,
|
|
185
174
|
cn,
|
|
@@ -189,9 +178,7 @@ export {
|
|
|
189
178
|
generateBreadcrumbItems,
|
|
190
179
|
generateQueryParams,
|
|
191
180
|
generateTreeOfContent,
|
|
192
|
-
getCookieFromDocument,
|
|
193
181
|
getCountryCodeByLang,
|
|
194
|
-
getFileRenditions
|
|
195
|
-
setCookie
|
|
182
|
+
getFileRenditions
|
|
196
183
|
};
|
|
197
184
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../constants/src/index.ts","../src/utils.ts","../src/breadcrumbs.ts","../src/classMerge.ts","../src/call.ts","../src/treeOfContent.ts","../src/params.ts","../src/renditions.ts","../src/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 \"table-with-images\",\n] as const;\n\nexport const API = {\n MAX_RETRY: 3,\n API_TIMEOUT: 10000,\n RETRY_DELAY: 500,\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\";\nexport const FRAGMENT = \"FRAGMENT\";\n\nexport const RESULT_TYPES = {\n TOPIC: TOPIC,\n DOCUMENT: DOCUMENT,\n PACKAGE: PACKAGE,\n FRAGMENT: FRAGMENT\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 = 30 * 24 * 60 * 60 * 1000; // 30 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\";\n\nexport const WILD_CARD_OPTIONS = {\n BOTH: \"BOTH\",\n END: \"END\",\n START: \"START\",\n NONE: \"NONE\",\n} as const;\n\nexport const OPERATOR_OPTIONS = {\n AND: \"AND\",\n OR: \"OR\",\n} as const;\n\nexport const ARTICLE_PAGE_LAYOUT = {\n BLOG: \"BLOG\",\n DOCUMENT: \"DOCUMENT\",\n} as const;\n\nexport const DEVICE_OPTIONS = {\n MOBILE: \"mobile\",\n TABLET: \"tablet\",\n DESKTOP: \"desktop\",\n}\nexport const BREAKPOINTS = {\n sm: 640,\n md: 768,\n lg: 1024,\n xl: 1280,\n \"2xl\": 1536,\n};\n\nexport const MARKER_COLORS = [\n \"red-500\",\n \"orange-500\",\n \"yellow-400\",\n \"green-500\",\n \"teal-500\",\n \"blue-500\",\n \"sky-500\",\n \"purple-500\",\n \"pink-500\",\n \"gray-500\",\n \"neutral-800\",\n \"cyan-500\",\n \"lime-500\",\n \"amber-500\",\n \"indigo-500\",\n];","import { FLAGS_BY_LANG } from \"@c-rex/constants\";\nimport { AvailableVersionsInterface, informationUnitsResponseItem } from \"@c-rex/interfaces\";\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 formatDateToLocale = (date: string, locale: string): string => {\n if (typeof date !== 'string' || !date) {\n return date;\n }\n\n const dateAux = new Date(date);\n return new Intl.DateTimeFormat(locale, {\n day: '2-digit',\n month: 'long',\n year: 'numeric'\n }).format(dateAux);\n}\n\nexport const createAvailableVersionList = (\n versions: informationUnitsResponseItem[],\n articleLang: string,\n type: string\n): AvailableVersionsInterface[] => {\n\n const availableVersions = versions.map(item => {\n return {\n shortId: item.shortId,\n active: item.language === articleLang,\n lang: item.language,\n country: item.language.split(\"-\")[1],\n link: `/${type}/${item.shortId}`,\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 }) as AvailableVersionsInterface[];\n\n return availableVersions;\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","/**\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 const res = await fetch(`/api/rpc`, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({ method, params }),\n credentials: 'include',\n });\n\n const json = await res.json();\n\n if (!res.ok) throw new Error(json.error || 'Unknown error');\n\n return json.data;\n}","import { DirectoryNodes, DefaultCrexDirectories, TreeOfContent } from \"@c-rex/interfaces\";\nimport { call } from \"./call\";\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<TreeOfContent[]> => {\n if (!directoryNodes?.length) return [];\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 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 result;\n};\n\nasync function getChildrenInfo(\n childNodes: DefaultCrexDirectories[] | 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 if (!fieldsList || fieldsList.length === 0) {\n return [];\n }\n\n return fieldsList.map((item) => ({\n key: key,\n value: item,\n }));\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((param) => `${encodeURIComponent(param.key)}=${encodeURIComponent(param.value)}`)\n .join(\"&\");\n return queryParams;\n};\n","import { informationUnitsRenditions } from \"@c-rex/interfaces\";\nimport { DocumentsType } from \"@c-rex/types\";\n\n\nexport const getFileRenditions = ({ renditions }: { renditions: informationUnitsRenditions[] }): DocumentsType => {\n if (renditions == undefined || renditions.length == 0) {\n return {};\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 }\n\n const result: {\n [key: string]: {\n view: string;\n download: string;\n }\n } = {}\n\n filteredRenditions.forEach((item) => {\n const key = item.format\n\n if (result[key] == undefined) {\n result[key] = {\n view: \"\",\n download: \"\"\n }\n }\n\n result[key].download = item.links.filter((link) => link.rel == \"download\")[0]?.href\n result[key].view = item.links.filter((link) => link.rel == \"view\")[0]?.href\n })\n\n return result\n}","/**\n * Sets a client-side cookie with the specified name, value, and expiration.\n * This function manipulates cookies that are NOT httpOnly, meaning they are accessible via JavaScript.\n * Cannot be used with httpOnly cookies as those are only accessible server-side.\n * \n * @param name - The name of the cookie to set\n * @param value - The value to store in the cookie (will be URL encoded)\n * @param days - Number of days until the cookie expires (default: 365)\n * @throws {Error} When document is not defined (e.g., in server-side environment)\n * \n * @example\n * ```typescript\n * setCookie('userToken', 'abc123', 30); // Expires in 30 days\n * setCookie('theme', 'dark'); // Expires in 365 days (default)\n * ```\n */\nexport const setCookie = (name: string, value: string, days = 365) => {\n if (!document) throw new Error(\"Document is not defined\");\n\n const expires = new Date(Date.now() + days * 864e5).toUTCString();\n document.cookie = `${name}=${encodeURIComponent(value)}; expires=${expires}; path=/`;\n}\n\n/**\n * Retrieves the value of a client-side cookie by its name.\n * This function reads cookies that are NOT httpOnly, meaning they are accessible via JavaScript.\n * Cannot be used with httpOnly cookies as those are only accessible server-side.\n * \n * @param name - The name of the cookie to retrieve\n * @returns The decoded cookie value, or an empty string if the cookie doesn't exist\n * @throws {Error} When document is not defined (e.g., in server-side environment)\n * \n * @example\n * ```typescript\n * const token = getCookieFromDocument('userToken'); // Returns cookie value or ''\n * const theme = getCookieFromDocument('theme'); // Returns cookie value or ''\n * ```\n */\nexport const getCookieFromDocument = (name: string): string => {\n if (!document) throw new Error(\"Document is not defined\");\n\n return document.cookie\n .split('; ')\n .find(row => row.startsWith(name + '='))\n ?.split('=')[1] ||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SAAS,OACX,MAAM,IAAI,EACV,KAAK,SAAO,IAAI,WAAW,OAAO,GAAG,CAAC,GACrC,MAAM,GAAG,EAAE,CAAC,KAAK;AAC3B;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../constants/src/index.ts","../src/utils.ts","../src/breadcrumbs.ts","../src/classMerge.ts","../src/call.ts","../src/treeOfContent.ts","../src/params.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 \"table-with-images\",\n] as const;\n\nexport const API = {\n MAX_RETRY: 3,\n API_TIMEOUT: 10000,\n RETRY_DELAY: 500,\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\";\nexport const FRAGMENT = \"FRAGMENT\";\n\nexport const RESULT_TYPES = {\n TOPIC: TOPIC,\n DOCUMENT: DOCUMENT,\n PACKAGE: PACKAGE,\n FRAGMENT: FRAGMENT\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 = 30 * 24 * 60 * 60 * 1000; // 30 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\";\n\nexport const WILD_CARD_OPTIONS = {\n BOTH: \"BOTH\",\n END: \"END\",\n START: \"START\",\n NONE: \"NONE\",\n} as const;\n\nexport const OPERATOR_OPTIONS = {\n AND: \"AND\",\n OR: \"OR\",\n} as const;\n\nexport const ARTICLE_PAGE_LAYOUT = {\n BLOG: \"BLOG\",\n DOCUMENT: \"DOCUMENT\",\n} as const;\n\nexport const DEVICE_OPTIONS = {\n MOBILE: \"mobile\",\n TABLET: \"tablet\",\n DESKTOP: \"desktop\",\n}\nexport const BREAKPOINTS = {\n sm: 640,\n md: 768,\n lg: 1024,\n xl: 1280,\n \"2xl\": 1536,\n};\n\nexport const MARKER_COLORS = [\n \"red-500\",\n \"orange-500\",\n \"yellow-400\",\n \"green-500\",\n \"teal-500\",\n \"blue-500\",\n \"sky-500\",\n \"purple-500\",\n \"pink-500\",\n \"gray-500\",\n \"neutral-800\",\n \"cyan-500\",\n \"lime-500\",\n \"amber-500\",\n \"indigo-500\",\n];","import { FLAGS_BY_LANG } from \"@c-rex/constants\";\nimport { AvailableVersionsInterface, informationUnitsResponseItem } from \"@c-rex/interfaces\";\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 formatDateToLocale = (date: string, locale: string): string => {\n if (typeof date !== 'string' || !date) {\n return date;\n }\n\n const dateAux = new Date(date);\n return new Intl.DateTimeFormat(locale, {\n day: '2-digit',\n month: 'long',\n year: 'numeric'\n }).format(dateAux);\n}\n\nexport const createAvailableVersionList = (\n versions: informationUnitsResponseItem[],\n articleLang: string,\n type: string\n): AvailableVersionsInterface[] => {\n\n const availableVersions = versions.map(item => {\n return {\n shortId: item.shortId,\n active: item.language === articleLang,\n lang: item.language,\n country: item.language.split(\"-\")[1],\n link: `/${type}/${item.shortId}`,\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 }) as AvailableVersionsInterface[];\n\n return availableVersions;\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","/**\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 const res = await fetch(`/api/rpc`, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({ method, params }),\n credentials: 'include',\n });\n\n const json = await res.json();\n\n if (!res.ok) throw new Error(json.error || 'Unknown error');\n\n return json.data;\n}","import { DirectoryNodes, DefaultCrexDirectories, TreeOfContent } from \"@c-rex/interfaces\";\nimport { call } from \"./call\";\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<TreeOfContent[]> => {\n if (!directoryNodes?.length) return [];\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 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 result;\n};\n\nasync function getChildrenInfo(\n childNodes: DefaultCrexDirectories[] | 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 if (!fieldsList || fieldsList.length === 0) {\n return [];\n }\n\n return fieldsList.map((item) => ({\n key: key,\n value: item,\n }));\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((param) => `${encodeURIComponent(param.key)}=${encodeURIComponent(param.value)}`)\n .join(\"&\");\n return queryParams;\n};\n","import { informationUnitsRenditions } from \"@c-rex/interfaces\";\nimport { DocumentsType } from \"@c-rex/types\";\n\n\nexport const getFileRenditions = ({ renditions }: { renditions: informationUnitsRenditions[] }): DocumentsType => {\n if (renditions == undefined || renditions.length == 0) {\n return {};\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 }\n\n const result: {\n [key: string]: {\n view: string;\n download: string;\n }\n } = {}\n\n filteredRenditions.forEach((item) => {\n const key = item.format\n\n if (result[key] == undefined) {\n result[key] = {\n view: \"\",\n download: \"\"\n }\n }\n\n result[key].download = item.links.filter((link) => link.rel == \"download\")[0]?.href\n result[key].view = item.links.filter((link) => link.rel == \"view\")[0]?.href\n })\n\n return result\n}"],"mappings":";AA8CO,IAAM,gBAAgB;AAAA,EACzB,MAAM;AAAA,EACN,MAAM;A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AAK,CAAC,EAAE,EACpF,KAAK,GAAG;AACb,SAAO;AACX;;;ACzBO,IAAM,oBAAoB,CAAC,EAAE,WAAW,MAAmE;AAC9G,MAAI,cAAc,UAAa,WAAW,UAAU,GAAG;AACnD,WAAO,CAAC;AAAA,EACZ;AAEA,QAAM,qBAAqB,WAAW;AAAA,IAClC,CAAC,SAAS,KAAK,UAAU,2BAA2B,KAAK,UAAU,sBAAsB,KAAK,UAAU;AAAA,EAC5G;AAEA,MAAI,mBAAmB,UAAU,KAAK,mBAAmB,CAAC,KAAK,QAAW;AACtE,WAAO,CAAC;AAAA,EACZ;AAEA,QAAM,SAKF,CAAC;AAEL,qBAAmB,QAAQ,CAAC,SAAS;AACjC,UAAM,MAAM,KAAK;AAEjB,QAAI,OAAO,GAAG,KAAK,QAAW;AAC1B,aAAO,GAAG,IAAI;AAAA,QACV,MAAM;AAAA,QACN,UAAU;AAAA,MACd;AAAA,IACJ;AAEA,WAAO,GAAG,EAAE,WAAW,KAAK,MAAM,OAAO,CAAC,SAAS,KAAK,OAAO,UAAU,EAAE,CAAC,GAAG;AAC/E,WAAO,GAAG,EAAE,OAAO,KAAK,MAAM,OAAO,CAAC,SAAS,KAAK,OAAO,MAAM,EAAE,CAAC,GAAG;AAAA,EAC3E,CAAC;AAED,SAAO;AACX;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@c-rex/utils",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.15",
|
|
4
4
|
"files": [
|
|
5
5
|
"dist"
|
|
6
6
|
],
|
|
@@ -21,6 +21,12 @@
|
|
|
21
21
|
"import": "./dist/index.mjs",
|
|
22
22
|
"require": "./dist/index.js",
|
|
23
23
|
"default": "./dist/index.js"
|
|
24
|
+
},
|
|
25
|
+
"./cookies": {
|
|
26
|
+
"types": "./dist/cookies.d.ts",
|
|
27
|
+
"import": "./dist/cookies.mjs",
|
|
28
|
+
"require": "./dist/cookies.js",
|
|
29
|
+
"default": "./dist/cookies.js"
|
|
24
30
|
}
|
|
25
31
|
},
|
|
26
32
|
"devDependencies": {
|
package/dist/next-cookies.d.mts
DELETED
package/dist/next-cookies.d.ts
DELETED
package/dist/next-cookies.js
DELETED
package/dist/next-cookies.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/dist/next-cookies.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|