@c-rex/services 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +0 -17
- package/dist/index.d.ts +0 -17
- package/dist/index.js +272 -218
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +272 -218
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -6,10 +6,6 @@ type QueryParams = {
|
|
|
6
6
|
key: string;
|
|
7
7
|
value: string;
|
|
8
8
|
};
|
|
9
|
-
type FileRenditionType = {
|
|
10
|
-
format: string;
|
|
11
|
-
link: string;
|
|
12
|
-
};
|
|
13
9
|
|
|
14
10
|
/**
|
|
15
11
|
* Base service class that provides common functionality for API interactions.
|
|
@@ -61,19 +57,6 @@ declare class RenditionsService extends BaseService {
|
|
|
61
57
|
getHTMLRendition({ renditions }: {
|
|
62
58
|
renditions: informationUnitsRenditions[];
|
|
63
59
|
}): Promise<string>;
|
|
64
|
-
/**
|
|
65
|
-
* Processes a list of renditions and categorizes them into files to download and files to open.
|
|
66
|
-
* Excludes renditions with formats 'application/xhtml+xml', 'application/json', and 'application/llm+xml'.
|
|
67
|
-
*
|
|
68
|
-
* @param renditions - Array of rendition objects to process
|
|
69
|
-
* @returns An object containing arrays of file renditions categorized as 'filesToDownload' and 'filesToOpen'
|
|
70
|
-
*/
|
|
71
|
-
getFileRenditions: ({ renditions }: {
|
|
72
|
-
renditions: informationUnitsRenditions[];
|
|
73
|
-
}) => {
|
|
74
|
-
filesToDownload: FileRenditionType[];
|
|
75
|
-
filesToOpen: FileRenditionType[];
|
|
76
|
-
};
|
|
77
60
|
}
|
|
78
61
|
|
|
79
62
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -6,10 +6,6 @@ type QueryParams = {
|
|
|
6
6
|
key: string;
|
|
7
7
|
value: string;
|
|
8
8
|
};
|
|
9
|
-
type FileRenditionType = {
|
|
10
|
-
format: string;
|
|
11
|
-
link: string;
|
|
12
|
-
};
|
|
13
9
|
|
|
14
10
|
/**
|
|
15
11
|
* Base service class that provides common functionality for API interactions.
|
|
@@ -61,19 +57,6 @@ declare class RenditionsService extends BaseService {
|
|
|
61
57
|
getHTMLRendition({ renditions }: {
|
|
62
58
|
renditions: informationUnitsRenditions[];
|
|
63
59
|
}): Promise<string>;
|
|
64
|
-
/**
|
|
65
|
-
* Processes a list of renditions and categorizes them into files to download and files to open.
|
|
66
|
-
* Excludes renditions with formats 'application/xhtml+xml', 'application/json', and 'application/llm+xml'.
|
|
67
|
-
*
|
|
68
|
-
* @param renditions - Array of rendition objects to process
|
|
69
|
-
* @returns An object containing arrays of file renditions categorized as 'filesToDownload' and 'filesToOpen'
|
|
70
|
-
*/
|
|
71
|
-
getFileRenditions: ({ renditions }: {
|
|
72
|
-
renditions: informationUnitsRenditions[];
|
|
73
|
-
}) => {
|
|
74
|
-
filesToDownload: FileRenditionType[];
|
|
75
|
-
filesToOpen: FileRenditionType[];
|
|
76
|
-
};
|
|
77
60
|
}
|
|
78
61
|
|
|
79
62
|
/**
|
package/dist/index.js
CHANGED
|
@@ -42,6 +42,14 @@ module.exports = __toCommonJS(index_exports);
|
|
|
42
42
|
var import_axios = __toESM(require("axios"));
|
|
43
43
|
|
|
44
44
|
// ../constants/src/index.ts
|
|
45
|
+
var ALL = "*";
|
|
46
|
+
var LOG_LEVELS = {
|
|
47
|
+
critical: 2,
|
|
48
|
+
error: 3,
|
|
49
|
+
warning: 4,
|
|
50
|
+
info: 6,
|
|
51
|
+
debug: 7
|
|
52
|
+
};
|
|
45
53
|
var API = {
|
|
46
54
|
MAX_RETRY: 3,
|
|
47
55
|
API_TIMEOUT: 1e4,
|
|
@@ -49,6 +57,7 @@ var API = {
|
|
|
49
57
|
"content-Type": "application/json"
|
|
50
58
|
}
|
|
51
59
|
};
|
|
60
|
+
var SDK_CONFIG_KEY = "crex-sdk-config";
|
|
52
61
|
var FLAGS_BY_LANG = {
|
|
53
62
|
"en": "US",
|
|
54
63
|
"de": "DE"
|
|
@@ -65,187 +74,142 @@ var RESULT_TYPES = {
|
|
|
65
74
|
var DEFAULT_COOKIE_LIMIT = 7 * 24 * 60 * 60 * 1e3;
|
|
66
75
|
var CREX_TOKEN_HEADER_KEY = "crex-token";
|
|
67
76
|
|
|
68
|
-
// ../
|
|
69
|
-
var
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
headers: { "Content-Type": "application/json" },
|
|
74
|
-
body: JSON.stringify({ method, params }),
|
|
75
|
-
credentials: "include"
|
|
76
|
-
});
|
|
77
|
-
const json = await res.json();
|
|
78
|
-
if (!res.ok) throw new Error(json.error || "Unknown error");
|
|
79
|
-
return json.data;
|
|
80
|
-
} catch (error) {
|
|
81
|
-
console.error(error);
|
|
82
|
-
return null;
|
|
83
|
-
}
|
|
84
|
-
};
|
|
85
|
-
var getCountryCodeByLang = (lang) => {
|
|
86
|
-
const mappedKeys = Object.keys(FLAGS_BY_LANG);
|
|
87
|
-
if (!mappedKeys.includes(lang)) {
|
|
88
|
-
return lang;
|
|
89
|
-
}
|
|
90
|
-
const country = FLAGS_BY_LANG[lang];
|
|
91
|
-
return country;
|
|
92
|
-
};
|
|
77
|
+
// ../core/src/requests.ts
|
|
78
|
+
var import_headers = require("next/headers");
|
|
79
|
+
|
|
80
|
+
// ../core/src/logger.ts
|
|
81
|
+
var import_winston = __toESM(require("winston"));
|
|
93
82
|
|
|
94
|
-
// ../
|
|
95
|
-
var
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
83
|
+
// ../core/src/transports/matomo.ts
|
|
84
|
+
var import_winston_transport = __toESM(require("winston-transport"));
|
|
85
|
+
var MatomoTransport = class extends import_winston_transport.default {
|
|
86
|
+
matomoTransport;
|
|
87
|
+
configs;
|
|
88
|
+
/**
|
|
89
|
+
* Creates a new instance of MatomoTransport.
|
|
90
|
+
*
|
|
91
|
+
* @param configs - The application configuration containing logging settings
|
|
92
|
+
*/
|
|
93
|
+
constructor(configs) {
|
|
94
|
+
super({
|
|
95
|
+
level: configs.logs.matomo.minimumLevel,
|
|
96
|
+
silent: configs.logs.matomo.silent
|
|
97
|
+
});
|
|
98
|
+
this.matomoTransport = new import_winston_transport.default();
|
|
99
|
+
this.configs = configs;
|
|
99
100
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
101
|
+
/**
|
|
102
|
+
* Logs a message to Matomo if the message category is included in the configured categories.
|
|
103
|
+
*
|
|
104
|
+
* @param info - The log information including level, message, and category
|
|
105
|
+
* @param callback - Callback function to execute after logging
|
|
106
|
+
*/
|
|
107
|
+
log(info, callback) {
|
|
108
|
+
const matomoCategory = this.configs.logs.matomo.categoriesLevel;
|
|
109
|
+
if (matomoCategory.includes(info.category) || matomoCategory.includes(ALL)) {
|
|
110
|
+
this.matomoTransport.log(info, callback);
|
|
107
111
|
}
|
|
108
|
-
await fetch(`${process.env.NEXT_PUBLIC_API_URL}/api/cookies`, {
|
|
109
|
-
method: "POST",
|
|
110
|
-
credentials: "include",
|
|
111
|
-
body: JSON.stringify({
|
|
112
|
-
key,
|
|
113
|
-
value,
|
|
114
|
-
maxAge
|
|
115
|
-
})
|
|
116
|
-
});
|
|
117
|
-
} catch (error) {
|
|
118
|
-
call("CrexLogger.log", {
|
|
119
|
-
level: "error",
|
|
120
|
-
message: `utils.setCookie error: ${error}`
|
|
121
|
-
});
|
|
122
112
|
}
|
|
123
113
|
};
|
|
124
114
|
|
|
125
|
-
// ../
|
|
126
|
-
var
|
|
127
|
-
var
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
// ../utils/src/token.ts
|
|
142
|
-
var updateToken = async () => {
|
|
143
|
-
try {
|
|
144
|
-
const response = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/api/token`, {
|
|
145
|
-
method: "POST",
|
|
146
|
-
credentials: "include"
|
|
115
|
+
// ../core/src/transports/graylog.ts
|
|
116
|
+
var import_winston_transport2 = __toESM(require("winston-transport"));
|
|
117
|
+
var import_winston_graylog2 = __toESM(require("winston-graylog2"));
|
|
118
|
+
var GraylogTransport = class extends import_winston_transport2.default {
|
|
119
|
+
graylogTransport;
|
|
120
|
+
configs;
|
|
121
|
+
/**
|
|
122
|
+
* Creates a new instance of GraylogTransport.
|
|
123
|
+
*
|
|
124
|
+
* @param configs - The application configuration containing logging settings
|
|
125
|
+
*/
|
|
126
|
+
constructor(configs) {
|
|
127
|
+
super({
|
|
128
|
+
level: configs.logs.graylog.minimumLevel,
|
|
129
|
+
silent: configs.logs.graylog.silent
|
|
147
130
|
});
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
131
|
+
this.configs = configs;
|
|
132
|
+
this.graylogTransport = new import_winston_graylog2.default({
|
|
133
|
+
name: "crex.net.documentation",
|
|
134
|
+
//name: "crex.net.blog",
|
|
135
|
+
silent: false,
|
|
136
|
+
handleExceptions: false,
|
|
137
|
+
graylog: {
|
|
138
|
+
servers: [
|
|
139
|
+
{ host: "localhost", port: 12201 },
|
|
140
|
+
{ host: "https://log.c-rex.net", port: 12202 }
|
|
141
|
+
//TODO: check the URL => https://log.c-rex.net:12202/gelf" GELF??
|
|
142
|
+
]
|
|
143
|
+
}
|
|
159
144
|
});
|
|
160
|
-
return null;
|
|
161
145
|
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
146
|
+
/**
|
|
147
|
+
* Logs a message to Graylog if the message category is included in the configured categories.
|
|
148
|
+
*
|
|
149
|
+
* @param info - The log information including level, message, and category
|
|
150
|
+
* @param callback - Callback function to execute after logging
|
|
151
|
+
*/
|
|
152
|
+
log(info, callback) {
|
|
153
|
+
const graylogCategory = this.configs.logs.graylog.categoriesLevel;
|
|
154
|
+
if (graylogCategory.includes(info.category) || graylogCategory.includes(ALL)) {
|
|
155
|
+
this.graylogTransport.log(info, callback);
|
|
171
156
|
}
|
|
172
|
-
return token;
|
|
173
|
-
} catch (error) {
|
|
174
|
-
call("CrexLogger.log", {
|
|
175
|
-
level: "error",
|
|
176
|
-
message: `utils.manageToken error: ${error}`
|
|
177
|
-
});
|
|
178
|
-
return null;
|
|
179
157
|
}
|
|
180
158
|
};
|
|
181
159
|
|
|
182
|
-
// ../core/src/
|
|
160
|
+
// ../core/src/logger.ts
|
|
183
161
|
var import_next_cookies = require("@c-rex/utils/next-cookies");
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
/**
|
|
188
|
-
* Retrieves a value from the cache by key.
|
|
189
|
-
*
|
|
190
|
-
* @param key - The cache key to retrieve
|
|
191
|
-
* @returns The cached value as a string, or null if not found
|
|
192
|
-
*/
|
|
193
|
-
async get(key) {
|
|
194
|
-
const cookie = await getCookie(key);
|
|
195
|
-
return cookie.value;
|
|
196
|
-
}
|
|
162
|
+
var CrexLogger = class {
|
|
163
|
+
customerConfig;
|
|
164
|
+
logger;
|
|
197
165
|
/**
|
|
198
|
-
*
|
|
199
|
-
*
|
|
166
|
+
* Initializes the logger instance if it hasn't been initialized yet.
|
|
167
|
+
* Loads customer configuration and creates the logger with appropriate transports.
|
|
200
168
|
*
|
|
201
|
-
* @
|
|
202
|
-
* @param value - The value to store
|
|
169
|
+
* @private
|
|
203
170
|
*/
|
|
204
|
-
async
|
|
171
|
+
async initLogger() {
|
|
205
172
|
try {
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
173
|
+
if (!this.customerConfig) {
|
|
174
|
+
this.customerConfig = await (0, import_next_cookies.getConfigs)();
|
|
175
|
+
}
|
|
176
|
+
if (!this.logger) {
|
|
177
|
+
this.logger = this.createLogger();
|
|
211
178
|
}
|
|
212
179
|
} catch (error) {
|
|
213
|
-
|
|
214
|
-
level: "error",
|
|
215
|
-
message: `CrexCache.set error: ${error}`
|
|
216
|
-
});
|
|
180
|
+
console.error("Error initializing logger:", error);
|
|
217
181
|
}
|
|
218
182
|
}
|
|
219
183
|
/**
|
|
220
|
-
*
|
|
221
|
-
* Combines URL, method, and optionally params, body, and headers into a single string key.
|
|
184
|
+
* Logs a message with the specified level and optional category.
|
|
222
185
|
*
|
|
223
|
-
* @param options -
|
|
224
|
-
* @param options.
|
|
225
|
-
* @param options.
|
|
226
|
-
* @param options.
|
|
227
|
-
* @param options.params - Optional query parameters
|
|
228
|
-
* @param options.headers - Optional request headers
|
|
229
|
-
* @returns A string cache key
|
|
186
|
+
* @param options - Logging options
|
|
187
|
+
* @param options.level - The log level (error, warn, info, etc.)
|
|
188
|
+
* @param options.message - The message to log
|
|
189
|
+
* @param options.category - Optional category for the log message
|
|
230
190
|
*/
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
191
|
+
async log({ level, message, category }) {
|
|
192
|
+
await this.initLogger();
|
|
193
|
+
this.logger.log(level, message, category);
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Creates a new Winston logger instance with configured transports.
|
|
197
|
+
*
|
|
198
|
+
* @private
|
|
199
|
+
* @returns A configured Winston logger instance
|
|
200
|
+
*/
|
|
201
|
+
createLogger() {
|
|
202
|
+
return import_winston.default.createLogger({
|
|
203
|
+
levels: LOG_LEVELS,
|
|
204
|
+
transports: [
|
|
205
|
+
new import_winston.default.transports.Console({
|
|
206
|
+
level: this.customerConfig.logs.console.minimumLevel,
|
|
207
|
+
silent: this.customerConfig.logs.console.silent
|
|
208
|
+
}),
|
|
209
|
+
new MatomoTransport(this.customerConfig),
|
|
210
|
+
new GraylogTransport(this.customerConfig)
|
|
211
|
+
]
|
|
212
|
+
});
|
|
249
213
|
}
|
|
250
214
|
};
|
|
251
215
|
|
|
@@ -253,24 +217,67 @@ var CrexCache = class {
|
|
|
253
217
|
var CrexApi = class {
|
|
254
218
|
customerConfig;
|
|
255
219
|
apiClient;
|
|
256
|
-
|
|
220
|
+
logger;
|
|
257
221
|
/**
|
|
258
222
|
* Initializes the API client if it hasn't been initialized yet.
|
|
259
|
-
* Loads customer configuration, creates the axios instance, and initializes the
|
|
223
|
+
* Loads customer configuration, creates the axios instance, and initializes the logger.
|
|
260
224
|
*
|
|
261
225
|
* @private
|
|
262
226
|
*/
|
|
263
227
|
async initAPI() {
|
|
228
|
+
this.logger = new CrexLogger();
|
|
264
229
|
if (!this.customerConfig) {
|
|
265
|
-
|
|
230
|
+
const aux = (0, import_headers.cookies)().get(SDK_CONFIG_KEY);
|
|
231
|
+
if (aux != void 0) {
|
|
232
|
+
this.customerConfig = JSON.parse(aux.value);
|
|
233
|
+
} else {
|
|
234
|
+
this.logger.log({
|
|
235
|
+
level: "error",
|
|
236
|
+
message: `utils.initAPI error: Config cookie not available`
|
|
237
|
+
});
|
|
238
|
+
throw new Error("Config cookie not available");
|
|
239
|
+
}
|
|
266
240
|
}
|
|
267
241
|
if (!this.apiClient) {
|
|
268
242
|
this.apiClient = import_axios.default.create({
|
|
269
243
|
baseURL: this.customerConfig.baseUrl
|
|
270
244
|
});
|
|
271
245
|
}
|
|
272
|
-
|
|
273
|
-
|
|
246
|
+
}
|
|
247
|
+
async getToken() {
|
|
248
|
+
try {
|
|
249
|
+
const response = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/api/token`, {
|
|
250
|
+
method: "POST",
|
|
251
|
+
credentials: "include"
|
|
252
|
+
});
|
|
253
|
+
const { token } = await response.json();
|
|
254
|
+
return token;
|
|
255
|
+
} catch (error) {
|
|
256
|
+
this.logger.log({
|
|
257
|
+
level: "error",
|
|
258
|
+
message: `utils.getToken error: ${error}`
|
|
259
|
+
});
|
|
260
|
+
throw error;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
async manageToken() {
|
|
264
|
+
try {
|
|
265
|
+
let token = "";
|
|
266
|
+
const hasToken = (0, import_headers.cookies)().get(CREX_TOKEN_HEADER_KEY);
|
|
267
|
+
if (hasToken == void 0 || hasToken.value === null) {
|
|
268
|
+
const tokenResult = await this.getToken();
|
|
269
|
+
if (tokenResult === null) throw new Error("Token is undefined");
|
|
270
|
+
token = tokenResult;
|
|
271
|
+
} else {
|
|
272
|
+
token = hasToken.value;
|
|
273
|
+
}
|
|
274
|
+
return token;
|
|
275
|
+
} catch (error) {
|
|
276
|
+
this.logger.log({
|
|
277
|
+
level: "error",
|
|
278
|
+
message: `utils.manageToken error: ${error}`
|
|
279
|
+
});
|
|
280
|
+
throw error;
|
|
274
281
|
}
|
|
275
282
|
}
|
|
276
283
|
/**
|
|
@@ -295,7 +302,7 @@ var CrexApi = class {
|
|
|
295
302
|
await this.initAPI();
|
|
296
303
|
let response = void 0;
|
|
297
304
|
if (this.customerConfig.OIDC.client.enabled) {
|
|
298
|
-
const token = await manageToken();
|
|
305
|
+
const token = await this.manageToken();
|
|
299
306
|
headers = {
|
|
300
307
|
...headers,
|
|
301
308
|
Authorization: `Bearer ${token}`
|
|
@@ -313,7 +320,7 @@ var CrexApi = class {
|
|
|
313
320
|
});
|
|
314
321
|
break;
|
|
315
322
|
} catch (error) {
|
|
316
|
-
|
|
323
|
+
this.logger.log({
|
|
317
324
|
level: "error",
|
|
318
325
|
message: `API.execute ${retry + 1}\xBA error when request ${url}. Error: ${error}`
|
|
319
326
|
});
|
|
@@ -329,6 +336,106 @@ var CrexApi = class {
|
|
|
329
336
|
}
|
|
330
337
|
};
|
|
331
338
|
|
|
339
|
+
// ../utils/src/utils.ts
|
|
340
|
+
var _generateShaKey = async (input) => {
|
|
341
|
+
const encoder = new TextEncoder();
|
|
342
|
+
const data = encoder.encode(input);
|
|
343
|
+
const hashBuffer = await crypto.subtle.digest("SHA-1", data);
|
|
344
|
+
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
|
345
|
+
const base64url = btoa(String.fromCharCode(...hashArray)).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
346
|
+
return base64url.slice(0, 12);
|
|
347
|
+
};
|
|
348
|
+
var getCountryCodeByLang = (lang) => {
|
|
349
|
+
const mappedKeys = Object.keys(FLAGS_BY_LANG);
|
|
350
|
+
if (!mappedKeys.includes(lang)) {
|
|
351
|
+
return lang;
|
|
352
|
+
}
|
|
353
|
+
const country = FLAGS_BY_LANG[lang];
|
|
354
|
+
return country;
|
|
355
|
+
};
|
|
356
|
+
|
|
357
|
+
// ../utils/src/call.ts
|
|
358
|
+
var call = async (method, params) => {
|
|
359
|
+
const shaKey = await _generateShaKey(JSON.stringify({ method, params }));
|
|
360
|
+
const cache = localStorage.getItem(shaKey);
|
|
361
|
+
if (cache !== null) {
|
|
362
|
+
const { data, expireDate } = JSON.parse(cache);
|
|
363
|
+
if (new Date(expireDate) > /* @__PURE__ */ new Date()) {
|
|
364
|
+
return JSON.parse(data);
|
|
365
|
+
} else {
|
|
366
|
+
localStorage.removeItem(shaKey);
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
const res = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/api/rpc`, {
|
|
370
|
+
method: "POST",
|
|
371
|
+
headers: { "Content-Type": "application/json" },
|
|
372
|
+
body: JSON.stringify({ method, params }),
|
|
373
|
+
credentials: "include"
|
|
374
|
+
});
|
|
375
|
+
const json = await res.json();
|
|
376
|
+
if (!res.ok) throw new Error(json.error || "Unknown error");
|
|
377
|
+
const today = /* @__PURE__ */ new Date();
|
|
378
|
+
const result = {
|
|
379
|
+
data: JSON.stringify(json.data),
|
|
380
|
+
expireDate: new Date(today.getTime() + 1e3 * 60 * 60)
|
|
381
|
+
};
|
|
382
|
+
localStorage.setItem(shaKey, JSON.stringify(result));
|
|
383
|
+
return json.data;
|
|
384
|
+
};
|
|
385
|
+
|
|
386
|
+
// ../utils/src/classMerge.ts
|
|
387
|
+
var import_clsx = require("clsx");
|
|
388
|
+
var import_tailwind_merge = require("tailwind-merge");
|
|
389
|
+
|
|
390
|
+
// ../utils/src/params.ts
|
|
391
|
+
var createParams = (fieldsList, key = "Fields") => fieldsList.map((item) => ({
|
|
392
|
+
key,
|
|
393
|
+
value: item
|
|
394
|
+
}));
|
|
395
|
+
var generateQueryParams = (params) => {
|
|
396
|
+
const queryParams = params.map(
|
|
397
|
+
(param) => `${encodeURIComponent(param.key)}=${encodeURIComponent(param.value)}`
|
|
398
|
+
).join("&");
|
|
399
|
+
return queryParams;
|
|
400
|
+
};
|
|
401
|
+
|
|
402
|
+
// ../utils/src/renditions.ts
|
|
403
|
+
var getFileRenditions = ({ renditions }) => {
|
|
404
|
+
if (renditions == void 0 || renditions.length == 0) {
|
|
405
|
+
return {
|
|
406
|
+
filesToDownload: [],
|
|
407
|
+
filesToOpen: []
|
|
408
|
+
};
|
|
409
|
+
}
|
|
410
|
+
const filteredRenditions = renditions.filter(
|
|
411
|
+
(item) => item.format != "application/xhtml+xml" && item.format != "application/json" && item.format != "application/llm+xml"
|
|
412
|
+
);
|
|
413
|
+
if (filteredRenditions.length == 0 || filteredRenditions[0] == void 0) {
|
|
414
|
+
return {
|
|
415
|
+
filesToDownload: [],
|
|
416
|
+
filesToOpen: []
|
|
417
|
+
};
|
|
418
|
+
}
|
|
419
|
+
const filesToDownload = filteredRenditions.map((item) => {
|
|
420
|
+
const filteredLinks = item.links.filter((item2) => item2.rel == "download");
|
|
421
|
+
return {
|
|
422
|
+
format: item.format,
|
|
423
|
+
link: filteredLinks[0].href
|
|
424
|
+
};
|
|
425
|
+
});
|
|
426
|
+
const filesToOpen = filteredRenditions.map((item) => {
|
|
427
|
+
const filteredLinks = item.links.filter((item2) => item2.rel == "view");
|
|
428
|
+
return {
|
|
429
|
+
format: item.format,
|
|
430
|
+
link: filteredLinks[0].href
|
|
431
|
+
};
|
|
432
|
+
});
|
|
433
|
+
return {
|
|
434
|
+
filesToDownload,
|
|
435
|
+
filesToOpen
|
|
436
|
+
};
|
|
437
|
+
};
|
|
438
|
+
|
|
332
439
|
// src/baseService.ts
|
|
333
440
|
var BaseService = class {
|
|
334
441
|
api;
|
|
@@ -413,48 +520,6 @@ var RenditionsService = class extends BaseService {
|
|
|
413
520
|
});
|
|
414
521
|
return response;
|
|
415
522
|
}
|
|
416
|
-
/**
|
|
417
|
-
* Processes a list of renditions and categorizes them into files to download and files to open.
|
|
418
|
-
* Excludes renditions with formats 'application/xhtml+xml', 'application/json', and 'application/llm+xml'.
|
|
419
|
-
*
|
|
420
|
-
* @param renditions - Array of rendition objects to process
|
|
421
|
-
* @returns An object containing arrays of file renditions categorized as 'filesToDownload' and 'filesToOpen'
|
|
422
|
-
*/
|
|
423
|
-
getFileRenditions = ({ renditions }) => {
|
|
424
|
-
if (renditions == void 0 || renditions.length == 0) {
|
|
425
|
-
return {
|
|
426
|
-
filesToDownload: [],
|
|
427
|
-
filesToOpen: []
|
|
428
|
-
};
|
|
429
|
-
}
|
|
430
|
-
const filteredRenditions = renditions.filter(
|
|
431
|
-
(item) => item.format != "application/xhtml+xml" && item.format != "application/json" && item.format != "application/llm+xml"
|
|
432
|
-
);
|
|
433
|
-
if (filteredRenditions.length == 0 || filteredRenditions[0] == void 0) {
|
|
434
|
-
return {
|
|
435
|
-
filesToDownload: [],
|
|
436
|
-
filesToOpen: []
|
|
437
|
-
};
|
|
438
|
-
}
|
|
439
|
-
const filesToDownload = filteredRenditions.map((item) => {
|
|
440
|
-
const filteredLinks = item.links.filter((item2) => item2.rel == "download");
|
|
441
|
-
return {
|
|
442
|
-
format: item.format,
|
|
443
|
-
link: filteredLinks[0].href
|
|
444
|
-
};
|
|
445
|
-
});
|
|
446
|
-
const filesToOpen = filteredRenditions.map((item) => {
|
|
447
|
-
const filteredLinks = item.links.filter((item2) => item2.rel == "view");
|
|
448
|
-
return {
|
|
449
|
-
format: item.format,
|
|
450
|
-
link: filteredLinks[0].href
|
|
451
|
-
};
|
|
452
|
-
});
|
|
453
|
-
return {
|
|
454
|
-
filesToDownload,
|
|
455
|
-
filesToOpen
|
|
456
|
-
};
|
|
457
|
-
};
|
|
458
523
|
};
|
|
459
524
|
|
|
460
525
|
// src/directoryNodes.ts
|
|
@@ -537,11 +602,10 @@ var DocumentTypesService = class extends BaseService {
|
|
|
537
602
|
// src/transforms/information.ts
|
|
538
603
|
var import_next_cookies2 = require("@c-rex/utils/next-cookies");
|
|
539
604
|
var transformInformationUnits = async (data) => {
|
|
540
|
-
const config = (0, import_next_cookies2.getConfigs)();
|
|
605
|
+
const config = await (0, import_next_cookies2.getConfigs)();
|
|
541
606
|
const items = await Promise.all(data.items.map(async (item) => {
|
|
542
607
|
const type = item.class.labels.filter((item2) => item2.language === EN_LANG)[0].value.toUpperCase();
|
|
543
|
-
const
|
|
544
|
-
const { filesToOpen, filesToDownload } = service.getFileRenditions({ renditions: item?.renditions });
|
|
608
|
+
const { filesToOpen, filesToDownload } = getFileRenditions({ renditions: item?.renditions });
|
|
545
609
|
let link = `/topics/${item.shortId}`;
|
|
546
610
|
if (config.results.articlePageLayout == "BLOG") {
|
|
547
611
|
link = `/blog/${item.shortId}`;
|
|
@@ -675,16 +739,6 @@ var LanguageService = class extends BaseService {
|
|
|
675
739
|
const configs = (0, import_next_cookies3.getConfigs)();
|
|
676
740
|
super(configs.languageSwitcher.endpoint);
|
|
677
741
|
}
|
|
678
|
-
/*
|
|
679
|
-
public static async getInstance(): Promise<LanguageService> {
|
|
680
|
-
const customerConfig = await getConfigs()
|
|
681
|
-
|
|
682
|
-
if (!LanguageService.instance) {
|
|
683
|
-
LanguageService.instance = new LanguageService(customerConfig.languageSwitcher.endpoint);
|
|
684
|
-
}
|
|
685
|
-
return LanguageService.instance;
|
|
686
|
-
}
|
|
687
|
-
*/
|
|
688
742
|
/**
|
|
689
743
|
* Retrieves a list of available languages and their associated countries.
|
|
690
744
|
* Transforms the API response to include language code, country code, and original value.
|