@c-rex/utils 0.1.3 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -1,44 +1,33 @@
1
- import { TreeOfContent, DirectoryNodes } from '@c-rex/interfaces';
1
+ import { TreeOfContent, DirectoryNodes, informationUnitsRenditions } from '@c-rex/interfaces';
2
2
  import { ClassValue } from 'clsx';
3
- import { QueryParams } from '@c-rex/types';
3
+ import { QueryParams, FileRenditionType } 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
- */
11
- declare const call: <T = unknown>(method: string, params?: any) => Promise<T>;
5
+ declare const _generateShaKey: (input: string) => Promise<string>;
12
6
  /**
13
7
  * Retrieves the country code associated with a given language code.
14
8
  * @param lang - The language code to look up (e.g., "en-US")
15
9
  * @returns The corresponding country code, or the original language code if not found
16
10
  */
17
11
  declare const getCountryCodeByLang: (lang: string) => string;
12
+ declare const getFromCookieString: (cookieString: string, key: string) => string;
18
13
 
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
14
  /**
34
15
  * Fetches a cookie value from the server API in client-side code.
35
16
  * @param key - The key of the cookie to retrieve
36
17
  * @returns A Promise resolving to an object containing the key and value of the cookie
37
18
  */
38
- declare const getCookieInFront: (key: string) => Promise<{
19
+ declare const getCookie: (key: string) => Promise<{
39
20
  key: string;
40
21
  value: string | null;
41
22
  }>;
23
+ /**
24
+ * Sets a cookie value through the server API in client-side code.
25
+ * @param key - The key of the cookie to set
26
+ * @param value - The value to store in the cookie
27
+ * @param maxAge - Optional maximum age of the cookie in seconds. Defaults to DEFAULT_COOKIE_LIMIT if not specified.
28
+ * @returns A Promise that resolves when the cookie has been set
29
+ */
30
+ declare const setCookie: (key: string, value: string, maxAge?: number) => Promise<void>;
42
31
 
43
32
  /**
44
33
  * Generates breadcrumb items by recursively extracting active items and their active children from a TreeOfContent array.
@@ -59,18 +48,7 @@ type ReturnType = {
59
48
  rootNode: DirectoryNodes | null;
60
49
  result: TreeOfContent[];
61
50
  };
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
51
  declare const generateTreeOfContent: (directoryNodes: DirectoryNodes[]) => Promise<ReturnType>;
68
- /**
69
- * Gets the information unit ID from a directory node ID.
70
- * @param directoryNodeID - The ID of the directory node
71
- * @returns A Promise resolving to the information unit ID, or an empty string if not found
72
- */
73
- declare const getLink: (directoryNodeID: string) => Promise<string>;
74
52
 
75
53
  /**
76
54
  * Creates an array of parameter objects from a list of field values.
@@ -89,35 +67,22 @@ declare const createParams: (fieldsList: string[], key?: string) => {
89
67
  */
90
68
  declare const generateQueryParams: (params: QueryParams[]) => string;
91
69
 
70
+ declare const manageToken: () => Promise<string | null>;
71
+
72
+ type RenditionType = {
73
+ filesToDownload: FileRenditionType[];
74
+ filesToOpen: FileRenditionType[];
75
+ };
76
+ declare const getFileRenditions: ({ renditions }: {
77
+ renditions: informationUnitsRenditions[];
78
+ }) => RenditionType;
79
+
92
80
  /**
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
81
+ * Makes an asynchronous RPC API call to the server.
82
+ * @param method - The RPC method name to call
83
+ * @param params - Optional parameters to pass to the method
84
+ * @returns A Promise resolving to the response data of type T
97
85
  */
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
- }>;
86
+ declare const call: <T = unknown>(method: string, params?: any) => Promise<T>;
122
87
 
123
- export { call, cn, createParams, generateBreadcrumbItems, generateQueryParams, generateTreeOfContent, getCookieInFront, getCountryCodeByLang, getFromMemory, getLink, loadArticleData, saveInMemory };
88
+ export { _generateShaKey, call, cn, createParams, generateBreadcrumbItems, generateQueryParams, generateTreeOfContent, getCookie, getCountryCodeByLang, getFileRenditions, getFromCookieString, manageToken, setCookie };
package/dist/index.d.ts CHANGED
@@ -1,44 +1,33 @@
1
- import { TreeOfContent, DirectoryNodes } from '@c-rex/interfaces';
1
+ import { TreeOfContent, DirectoryNodes, informationUnitsRenditions } from '@c-rex/interfaces';
2
2
  import { ClassValue } from 'clsx';
3
- import { QueryParams } from '@c-rex/types';
3
+ import { QueryParams, FileRenditionType } 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
- */
11
- declare const call: <T = unknown>(method: string, params?: any) => Promise<T>;
5
+ declare const _generateShaKey: (input: string) => Promise<string>;
12
6
  /**
13
7
  * Retrieves the country code associated with a given language code.
14
8
  * @param lang - The language code to look up (e.g., "en-US")
15
9
  * @returns The corresponding country code, or the original language code if not found
16
10
  */
17
11
  declare const getCountryCodeByLang: (lang: string) => string;
12
+ declare const getFromCookieString: (cookieString: string, key: string) => string;
18
13
 
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
14
  /**
34
15
  * Fetches a cookie value from the server API in client-side code.
35
16
  * @param key - The key of the cookie to retrieve
36
17
  * @returns A Promise resolving to an object containing the key and value of the cookie
37
18
  */
38
- declare const getCookieInFront: (key: string) => Promise<{
19
+ declare const getCookie: (key: string) => Promise<{
39
20
  key: string;
40
21
  value: string | null;
41
22
  }>;
23
+ /**
24
+ * Sets a cookie value through the server API in client-side code.
25
+ * @param key - The key of the cookie to set
26
+ * @param value - The value to store in the cookie
27
+ * @param maxAge - Optional maximum age of the cookie in seconds. Defaults to DEFAULT_COOKIE_LIMIT if not specified.
28
+ * @returns A Promise that resolves when the cookie has been set
29
+ */
30
+ declare const setCookie: (key: string, value: string, maxAge?: number) => Promise<void>;
42
31
 
43
32
  /**
44
33
  * Generates breadcrumb items by recursively extracting active items and their active children from a TreeOfContent array.
@@ -59,18 +48,7 @@ type ReturnType = {
59
48
  rootNode: DirectoryNodes | null;
60
49
  result: TreeOfContent[];
61
50
  };
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
51
  declare const generateTreeOfContent: (directoryNodes: DirectoryNodes[]) => Promise<ReturnType>;
68
- /**
69
- * Gets the information unit ID from a directory node ID.
70
- * @param directoryNodeID - The ID of the directory node
71
- * @returns A Promise resolving to the information unit ID, or an empty string if not found
72
- */
73
- declare const getLink: (directoryNodeID: string) => Promise<string>;
74
52
 
75
53
  /**
76
54
  * Creates an array of parameter objects from a list of field values.
@@ -89,35 +67,22 @@ declare const createParams: (fieldsList: string[], key?: string) => {
89
67
  */
90
68
  declare const generateQueryParams: (params: QueryParams[]) => string;
91
69
 
70
+ declare const manageToken: () => Promise<string | null>;
71
+
72
+ type RenditionType = {
73
+ filesToDownload: FileRenditionType[];
74
+ filesToOpen: FileRenditionType[];
75
+ };
76
+ declare const getFileRenditions: ({ renditions }: {
77
+ renditions: informationUnitsRenditions[];
78
+ }) => RenditionType;
79
+
92
80
  /**
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
81
+ * Makes an asynchronous RPC API call to the server.
82
+ * @param method - The RPC method name to call
83
+ * @param params - Optional parameters to pass to the method
84
+ * @returns A Promise resolving to the response data of type T
97
85
  */
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
- }>;
86
+ declare const call: <T = unknown>(method: string, params?: any) => Promise<T>;
122
87
 
123
- export { call, cn, createParams, generateBreadcrumbItems, generateQueryParams, generateTreeOfContent, getCookieInFront, getCountryCodeByLang, getFromMemory, getLink, loadArticleData, saveInMemory };
88
+ export { _generateShaKey, call, cn, createParams, generateBreadcrumbItems, generateQueryParams, generateTreeOfContent, getCookie, getCountryCodeByLang, getFileRenditions, getFromCookieString, manageToken, setCookie };