@c-rex/services 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 +13 -18
- package/dist/index.d.ts +13 -18
- package/dist/index.js +332 -238
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +332 -238
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
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"
|
|
@@ -64,188 +73,153 @@ var RESULT_TYPES = {
|
|
|
64
73
|
};
|
|
65
74
|
var DEFAULT_COOKIE_LIMIT = 7 * 24 * 60 * 60 * 1e3;
|
|
66
75
|
var CREX_TOKEN_HEADER_KEY = "crex-token";
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
method: "POST",
|
|
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
|
-
}
|
|
76
|
+
var WILD_CARD_OPTIONS = {
|
|
77
|
+
BOTH: "BOTH",
|
|
78
|
+
END: "END",
|
|
79
|
+
START: "START",
|
|
80
|
+
NONE: "NONE"
|
|
84
81
|
};
|
|
85
|
-
var
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
return lang;
|
|
89
|
-
}
|
|
90
|
-
const country = FLAGS_BY_LANG[lang];
|
|
91
|
-
return country;
|
|
82
|
+
var OPERATOR_OPTIONS = {
|
|
83
|
+
AND: "AND",
|
|
84
|
+
OR: "OR"
|
|
92
85
|
};
|
|
93
86
|
|
|
94
|
-
// ../
|
|
95
|
-
var
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
87
|
+
// ../core/src/requests.ts
|
|
88
|
+
var import_headers = require("next/headers");
|
|
89
|
+
|
|
90
|
+
// ../core/src/logger.ts
|
|
91
|
+
var import_winston = __toESM(require("winston"));
|
|
92
|
+
|
|
93
|
+
// ../core/src/transports/matomo.ts
|
|
94
|
+
var import_winston_transport = __toESM(require("winston-transport"));
|
|
95
|
+
var MatomoTransport = class extends import_winston_transport.default {
|
|
96
|
+
matomoTransport;
|
|
97
|
+
configs;
|
|
98
|
+
/**
|
|
99
|
+
* Creates a new instance of MatomoTransport.
|
|
100
|
+
*
|
|
101
|
+
* @param configs - The application configuration containing logging settings
|
|
102
|
+
*/
|
|
103
|
+
constructor(configs) {
|
|
104
|
+
super({
|
|
105
|
+
level: configs.logs.matomo.minimumLevel,
|
|
106
|
+
silent: configs.logs.matomo.silent
|
|
107
|
+
});
|
|
108
|
+
this.matomoTransport = new import_winston_transport.default();
|
|
109
|
+
this.configs = configs;
|
|
99
110
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
111
|
+
/**
|
|
112
|
+
* Logs a message to Matomo if the message category is included in the configured categories.
|
|
113
|
+
*
|
|
114
|
+
* @param info - The log information including level, message, and category
|
|
115
|
+
* @param callback - Callback function to execute after logging
|
|
116
|
+
*/
|
|
117
|
+
log(info, callback) {
|
|
118
|
+
const matomoCategory = this.configs.logs.matomo.categoriesLevel;
|
|
119
|
+
if (matomoCategory.includes(info.category) || matomoCategory.includes(ALL)) {
|
|
120
|
+
this.matomoTransport.log(info, callback);
|
|
107
121
|
}
|
|
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
122
|
}
|
|
123
123
|
};
|
|
124
124
|
|
|
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"
|
|
125
|
+
// ../core/src/transports/graylog.ts
|
|
126
|
+
var import_winston_transport2 = __toESM(require("winston-transport"));
|
|
127
|
+
var import_winston_graylog2 = __toESM(require("winston-graylog2"));
|
|
128
|
+
var GraylogTransport = class extends import_winston_transport2.default {
|
|
129
|
+
graylogTransport;
|
|
130
|
+
configs;
|
|
131
|
+
/**
|
|
132
|
+
* Creates a new instance of GraylogTransport.
|
|
133
|
+
*
|
|
134
|
+
* @param configs - The application configuration containing logging settings
|
|
135
|
+
*/
|
|
136
|
+
constructor(configs) {
|
|
137
|
+
super({
|
|
138
|
+
level: configs.logs.graylog.minimumLevel,
|
|
139
|
+
silent: configs.logs.graylog.silent
|
|
147
140
|
});
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
141
|
+
this.configs = configs;
|
|
142
|
+
this.graylogTransport = new import_winston_graylog2.default({
|
|
143
|
+
name: "crex.net.documentation",
|
|
144
|
+
//name: "crex.net.blog",
|
|
145
|
+
silent: false,
|
|
146
|
+
handleExceptions: false,
|
|
147
|
+
graylog: {
|
|
148
|
+
servers: [
|
|
149
|
+
{ host: "localhost", port: 12201 },
|
|
150
|
+
{ host: "https://log.c-rex.net", port: 12202 }
|
|
151
|
+
//TODO: check the URL => https://log.c-rex.net:12202/gelf" GELF??
|
|
152
|
+
]
|
|
153
|
+
}
|
|
159
154
|
});
|
|
160
|
-
return null;
|
|
161
155
|
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
156
|
+
/**
|
|
157
|
+
* Logs a message to Graylog if the message category is included in the configured categories.
|
|
158
|
+
*
|
|
159
|
+
* @param info - The log information including level, message, and category
|
|
160
|
+
* @param callback - Callback function to execute after logging
|
|
161
|
+
*/
|
|
162
|
+
log(info, callback) {
|
|
163
|
+
const graylogCategory = this.configs.logs.graylog.categoriesLevel;
|
|
164
|
+
if (graylogCategory.includes(info.category) || graylogCategory.includes(ALL)) {
|
|
165
|
+
this.graylogTransport.log(info, callback);
|
|
171
166
|
}
|
|
172
|
-
return token;
|
|
173
|
-
} catch (error) {
|
|
174
|
-
call("CrexLogger.log", {
|
|
175
|
-
level: "error",
|
|
176
|
-
message: `utils.manageToken error: ${error}`
|
|
177
|
-
});
|
|
178
|
-
return null;
|
|
179
167
|
}
|
|
180
168
|
};
|
|
181
169
|
|
|
182
|
-
// ../core/src/
|
|
170
|
+
// ../core/src/logger.ts
|
|
183
171
|
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
|
-
}
|
|
172
|
+
var CrexLogger = class {
|
|
173
|
+
customerConfig;
|
|
174
|
+
logger;
|
|
197
175
|
/**
|
|
198
|
-
*
|
|
199
|
-
*
|
|
176
|
+
* Initializes the logger instance if it hasn't been initialized yet.
|
|
177
|
+
* Loads customer configuration and creates the logger with appropriate transports.
|
|
200
178
|
*
|
|
201
|
-
* @
|
|
202
|
-
* @param value - The value to store
|
|
179
|
+
* @private
|
|
203
180
|
*/
|
|
204
|
-
async
|
|
181
|
+
async initLogger() {
|
|
205
182
|
try {
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
183
|
+
if (!this.customerConfig) {
|
|
184
|
+
this.customerConfig = await (0, import_next_cookies.getConfigs)();
|
|
185
|
+
}
|
|
186
|
+
if (!this.logger) {
|
|
187
|
+
this.logger = this.createLogger();
|
|
211
188
|
}
|
|
212
189
|
} catch (error) {
|
|
213
|
-
|
|
214
|
-
level: "error",
|
|
215
|
-
message: `CrexCache.set error: ${error}`
|
|
216
|
-
});
|
|
190
|
+
console.error("Error initializing logger:", error);
|
|
217
191
|
}
|
|
218
192
|
}
|
|
219
193
|
/**
|
|
220
|
-
*
|
|
221
|
-
* Combines URL, method, and optionally params, body, and headers into a single string key.
|
|
194
|
+
* Logs a message with the specified level and optional category.
|
|
222
195
|
*
|
|
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
|
|
196
|
+
* @param options - Logging options
|
|
197
|
+
* @param options.level - The log level (error, warn, info, etc.)
|
|
198
|
+
* @param options.message - The message to log
|
|
199
|
+
* @param options.category - Optional category for the log message
|
|
230
200
|
*/
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
201
|
+
async log({ level, message, category }) {
|
|
202
|
+
await this.initLogger();
|
|
203
|
+
this.logger.log(level, message, category);
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Creates a new Winston logger instance with configured transports.
|
|
207
|
+
*
|
|
208
|
+
* @private
|
|
209
|
+
* @returns A configured Winston logger instance
|
|
210
|
+
*/
|
|
211
|
+
createLogger() {
|
|
212
|
+
return import_winston.default.createLogger({
|
|
213
|
+
levels: LOG_LEVELS,
|
|
214
|
+
transports: [
|
|
215
|
+
new import_winston.default.transports.Console({
|
|
216
|
+
level: this.customerConfig.logs.console.minimumLevel,
|
|
217
|
+
silent: this.customerConfig.logs.console.silent
|
|
218
|
+
}),
|
|
219
|
+
new MatomoTransport(this.customerConfig),
|
|
220
|
+
new GraylogTransport(this.customerConfig)
|
|
221
|
+
]
|
|
222
|
+
});
|
|
249
223
|
}
|
|
250
224
|
};
|
|
251
225
|
|
|
@@ -253,24 +227,67 @@ var CrexCache = class {
|
|
|
253
227
|
var CrexApi = class {
|
|
254
228
|
customerConfig;
|
|
255
229
|
apiClient;
|
|
256
|
-
|
|
230
|
+
logger;
|
|
257
231
|
/**
|
|
258
232
|
* Initializes the API client if it hasn't been initialized yet.
|
|
259
|
-
* Loads customer configuration, creates the axios instance, and initializes the
|
|
233
|
+
* Loads customer configuration, creates the axios instance, and initializes the logger.
|
|
260
234
|
*
|
|
261
235
|
* @private
|
|
262
236
|
*/
|
|
263
237
|
async initAPI() {
|
|
238
|
+
this.logger = new CrexLogger();
|
|
264
239
|
if (!this.customerConfig) {
|
|
265
|
-
|
|
240
|
+
const aux = await (0, import_headers.cookies)().get(SDK_CONFIG_KEY);
|
|
241
|
+
if (aux != void 0) {
|
|
242
|
+
this.customerConfig = JSON.parse(aux.value);
|
|
243
|
+
} else {
|
|
244
|
+
this.logger.log({
|
|
245
|
+
level: "error",
|
|
246
|
+
message: `utils.initAPI error: Config cookie not available`
|
|
247
|
+
});
|
|
248
|
+
throw new Error("Config cookie not available");
|
|
249
|
+
}
|
|
266
250
|
}
|
|
267
251
|
if (!this.apiClient) {
|
|
268
252
|
this.apiClient = import_axios.default.create({
|
|
269
253
|
baseURL: this.customerConfig.baseUrl
|
|
270
254
|
});
|
|
271
255
|
}
|
|
272
|
-
|
|
273
|
-
|
|
256
|
+
}
|
|
257
|
+
async getToken() {
|
|
258
|
+
try {
|
|
259
|
+
const response = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/api/token`, {
|
|
260
|
+
method: "POST",
|
|
261
|
+
credentials: "include"
|
|
262
|
+
});
|
|
263
|
+
const { token } = await response.json();
|
|
264
|
+
return token;
|
|
265
|
+
} catch (error) {
|
|
266
|
+
this.logger.log({
|
|
267
|
+
level: "error",
|
|
268
|
+
message: `utils.getToken error: ${error}`
|
|
269
|
+
});
|
|
270
|
+
throw error;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
async manageToken() {
|
|
274
|
+
try {
|
|
275
|
+
let token = "";
|
|
276
|
+
const hasToken = (0, import_headers.cookies)().get(CREX_TOKEN_HEADER_KEY);
|
|
277
|
+
if (hasToken == void 0 || hasToken.value === null) {
|
|
278
|
+
const tokenResult = await this.getToken();
|
|
279
|
+
if (tokenResult === null) throw new Error("Token is undefined");
|
|
280
|
+
token = tokenResult;
|
|
281
|
+
} else {
|
|
282
|
+
token = hasToken.value;
|
|
283
|
+
}
|
|
284
|
+
return token;
|
|
285
|
+
} catch (error) {
|
|
286
|
+
this.logger.log({
|
|
287
|
+
level: "error",
|
|
288
|
+
message: `utils.manageToken error: ${error}`
|
|
289
|
+
});
|
|
290
|
+
throw error;
|
|
274
291
|
}
|
|
275
292
|
}
|
|
276
293
|
/**
|
|
@@ -295,7 +312,7 @@ var CrexApi = class {
|
|
|
295
312
|
await this.initAPI();
|
|
296
313
|
let response = void 0;
|
|
297
314
|
if (this.customerConfig.OIDC.client.enabled) {
|
|
298
|
-
const token = await manageToken();
|
|
315
|
+
const token = await this.manageToken();
|
|
299
316
|
headers = {
|
|
300
317
|
...headers,
|
|
301
318
|
Authorization: `Bearer ${token}`
|
|
@@ -313,7 +330,7 @@ var CrexApi = class {
|
|
|
313
330
|
});
|
|
314
331
|
break;
|
|
315
332
|
} catch (error) {
|
|
316
|
-
|
|
333
|
+
this.logger.log({
|
|
317
334
|
level: "error",
|
|
318
335
|
message: `API.execute ${retry + 1}\xBA error when request ${url}. Error: ${error}`
|
|
319
336
|
});
|
|
@@ -329,6 +346,106 @@ var CrexApi = class {
|
|
|
329
346
|
}
|
|
330
347
|
};
|
|
331
348
|
|
|
349
|
+
// ../utils/src/utils.ts
|
|
350
|
+
var _generateShaKey = async (input) => {
|
|
351
|
+
const encoder = new TextEncoder();
|
|
352
|
+
const data = encoder.encode(input);
|
|
353
|
+
const hashBuffer = await crypto.subtle.digest("SHA-1", data);
|
|
354
|
+
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
|
355
|
+
const base64url = btoa(String.fromCharCode(...hashArray)).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
356
|
+
return base64url.slice(0, 12);
|
|
357
|
+
};
|
|
358
|
+
var getCountryCodeByLang = (lang) => {
|
|
359
|
+
const mappedKeys = Object.keys(FLAGS_BY_LANG);
|
|
360
|
+
if (!mappedKeys.includes(lang)) {
|
|
361
|
+
return lang;
|
|
362
|
+
}
|
|
363
|
+
const country = FLAGS_BY_LANG[lang];
|
|
364
|
+
return country;
|
|
365
|
+
};
|
|
366
|
+
|
|
367
|
+
// ../utils/src/call.ts
|
|
368
|
+
var call = async (method, params) => {
|
|
369
|
+
const shaKey = await _generateShaKey(JSON.stringify({ method, params }));
|
|
370
|
+
const cache = localStorage.getItem(shaKey);
|
|
371
|
+
if (cache !== null) {
|
|
372
|
+
const { data, expireDate } = JSON.parse(cache);
|
|
373
|
+
if (new Date(expireDate) > /* @__PURE__ */ new Date()) {
|
|
374
|
+
return JSON.parse(data);
|
|
375
|
+
} else {
|
|
376
|
+
localStorage.removeItem(shaKey);
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
const res = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/api/rpc`, {
|
|
380
|
+
method: "POST",
|
|
381
|
+
headers: { "Content-Type": "application/json" },
|
|
382
|
+
body: JSON.stringify({ method, params }),
|
|
383
|
+
credentials: "include"
|
|
384
|
+
});
|
|
385
|
+
const json = await res.json();
|
|
386
|
+
if (!res.ok) throw new Error(json.error || "Unknown error");
|
|
387
|
+
const today = /* @__PURE__ */ new Date();
|
|
388
|
+
const result = {
|
|
389
|
+
data: JSON.stringify(json.data),
|
|
390
|
+
expireDate: new Date(today.getTime() + 1e3 * 60 * 60)
|
|
391
|
+
};
|
|
392
|
+
localStorage.setItem(shaKey, JSON.stringify(result));
|
|
393
|
+
return json.data;
|
|
394
|
+
};
|
|
395
|
+
|
|
396
|
+
// ../utils/src/classMerge.ts
|
|
397
|
+
var import_clsx = require("clsx");
|
|
398
|
+
var import_tailwind_merge = require("tailwind-merge");
|
|
399
|
+
|
|
400
|
+
// ../utils/src/params.ts
|
|
401
|
+
var createParams = (fieldsList, key = "Fields") => fieldsList.map((item) => ({
|
|
402
|
+
key,
|
|
403
|
+
value: item
|
|
404
|
+
}));
|
|
405
|
+
var generateQueryParams = (params) => {
|
|
406
|
+
const queryParams = params.map(
|
|
407
|
+
(param) => `${encodeURIComponent(param.key)}=${encodeURIComponent(param.value)}`
|
|
408
|
+
).join("&");
|
|
409
|
+
return queryParams;
|
|
410
|
+
};
|
|
411
|
+
|
|
412
|
+
// ../utils/src/renditions.ts
|
|
413
|
+
var getFileRenditions = ({ renditions }) => {
|
|
414
|
+
if (renditions == void 0 || renditions.length == 0) {
|
|
415
|
+
return {
|
|
416
|
+
filesToDownload: [],
|
|
417
|
+
filesToOpen: []
|
|
418
|
+
};
|
|
419
|
+
}
|
|
420
|
+
const filteredRenditions = renditions.filter(
|
|
421
|
+
(item) => item.format != "application/xhtml+xml" && item.format != "application/json" && item.format != "application/llm+xml"
|
|
422
|
+
);
|
|
423
|
+
if (filteredRenditions.length == 0 || filteredRenditions[0] == void 0) {
|
|
424
|
+
return {
|
|
425
|
+
filesToDownload: [],
|
|
426
|
+
filesToOpen: []
|
|
427
|
+
};
|
|
428
|
+
}
|
|
429
|
+
const filesToDownload = filteredRenditions.map((item) => {
|
|
430
|
+
const filteredLinks = item.links.filter((item2) => item2.rel == "download");
|
|
431
|
+
return {
|
|
432
|
+
format: item.format,
|
|
433
|
+
link: filteredLinks[0].href
|
|
434
|
+
};
|
|
435
|
+
});
|
|
436
|
+
const filesToOpen = filteredRenditions.map((item) => {
|
|
437
|
+
const filteredLinks = item.links.filter((item2) => item2.rel == "view");
|
|
438
|
+
return {
|
|
439
|
+
format: item.format,
|
|
440
|
+
link: filteredLinks[0].href
|
|
441
|
+
};
|
|
442
|
+
});
|
|
443
|
+
return {
|
|
444
|
+
filesToDownload,
|
|
445
|
+
filesToOpen
|
|
446
|
+
};
|
|
447
|
+
};
|
|
448
|
+
|
|
332
449
|
// src/baseService.ts
|
|
333
450
|
var BaseService = class {
|
|
334
451
|
api;
|
|
@@ -413,48 +530,6 @@ var RenditionsService = class extends BaseService {
|
|
|
413
530
|
});
|
|
414
531
|
return response;
|
|
415
532
|
}
|
|
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
533
|
};
|
|
459
534
|
|
|
460
535
|
// src/directoryNodes.ts
|
|
@@ -536,21 +611,38 @@ var DocumentTypesService = class extends BaseService {
|
|
|
536
611
|
|
|
537
612
|
// src/transforms/information.ts
|
|
538
613
|
var import_next_cookies2 = require("@c-rex/utils/next-cookies");
|
|
614
|
+
var import_logger2 = require("@c-rex/core/logger");
|
|
539
615
|
var transformInformationUnits = async (data) => {
|
|
540
|
-
const config = (0, import_next_cookies2.getConfigs)();
|
|
616
|
+
const config = await (0, import_next_cookies2.getConfigs)();
|
|
617
|
+
const logger = new import_logger2.CrexLogger();
|
|
541
618
|
const items = await Promise.all(data.items.map(async (item) => {
|
|
542
619
|
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 });
|
|
620
|
+
const { filesToOpen, filesToDownload } = getFileRenditions({ renditions: item?.renditions });
|
|
545
621
|
let link = `/topics/${item.shortId}`;
|
|
546
622
|
if (config.results.articlePageLayout == "BLOG") {
|
|
547
623
|
link = `/blog/${item.shortId}`;
|
|
548
624
|
} else if (type == RESULT_TYPES.DOCUMENT) {
|
|
549
625
|
link = `/documents/${item.shortId}`;
|
|
550
626
|
}
|
|
627
|
+
let title = "NO TITLE";
|
|
628
|
+
let language = "NO LANGUAGE";
|
|
629
|
+
try {
|
|
630
|
+
if (item.titles) {
|
|
631
|
+
title = item.titles[0].value;
|
|
632
|
+
language = item.titles[0].language;
|
|
633
|
+
} else {
|
|
634
|
+
title = item.labels[0].value;
|
|
635
|
+
language = item.labels[0].language;
|
|
636
|
+
}
|
|
637
|
+
} catch {
|
|
638
|
+
logger.log({
|
|
639
|
+
level: "error",
|
|
640
|
+
message: `No label or title on item ${item.shortId}`
|
|
641
|
+
});
|
|
642
|
+
}
|
|
551
643
|
return {
|
|
552
|
-
language
|
|
553
|
-
title
|
|
644
|
+
language,
|
|
645
|
+
title,
|
|
554
646
|
type,
|
|
555
647
|
localeType: "",
|
|
556
648
|
shortId: item.shortId,
|
|
@@ -560,11 +652,24 @@ var transformInformationUnits = async (data) => {
|
|
|
560
652
|
filesToDownload
|
|
561
653
|
};
|
|
562
654
|
}));
|
|
655
|
+
const filteredList = items.filter((item) => item != null);
|
|
563
656
|
return {
|
|
564
|
-
items,
|
|
657
|
+
items: filteredList,
|
|
565
658
|
pageInfo: data.pageInfo
|
|
566
659
|
};
|
|
567
660
|
};
|
|
661
|
+
var transformSuggestions = (data, query) => {
|
|
662
|
+
const suggestions = [];
|
|
663
|
+
const comparableList = [];
|
|
664
|
+
data.suggestions.forEach((item) => {
|
|
665
|
+
suggestions.push(item.value);
|
|
666
|
+
comparableList.push(item.value.toLowerCase());
|
|
667
|
+
});
|
|
668
|
+
if (!comparableList.includes(query.toLowerCase())) {
|
|
669
|
+
return [query, ...suggestions];
|
|
670
|
+
}
|
|
671
|
+
return suggestions;
|
|
672
|
+
};
|
|
568
673
|
|
|
569
674
|
// src/informationUnits.ts
|
|
570
675
|
var InformationUnitsService = class extends BaseService {
|
|
@@ -588,20 +693,29 @@ var InformationUnitsService = class extends BaseService {
|
|
|
588
693
|
page = 1,
|
|
589
694
|
fields = [],
|
|
590
695
|
filters = [],
|
|
591
|
-
|
|
696
|
+
restrict = [],
|
|
697
|
+
languages = [],
|
|
698
|
+
wildcard = WILD_CARD_OPTIONS.BOTH,
|
|
699
|
+
operator = OPERATOR_OPTIONS.AND,
|
|
700
|
+
like = false
|
|
592
701
|
}) {
|
|
593
702
|
const remainFields = createParams(fields, "Fields");
|
|
594
703
|
const remainFilters = createParams(filters, "Filter");
|
|
704
|
+
const restrictions = createParams(restrict, "Restrict");
|
|
595
705
|
const languageParams = createParams(
|
|
596
|
-
languages.map((item) =>
|
|
597
|
-
"
|
|
706
|
+
languages.map((item) => `?s iirds:language '${item}'`),
|
|
707
|
+
"sparqlWhere"
|
|
598
708
|
);
|
|
599
709
|
const params = [
|
|
600
710
|
{ key: "pageSize", value: "12" },
|
|
711
|
+
{ key: "wildcard", value: wildcard.toLowerCase() },
|
|
601
712
|
{ key: "PageNumber", value: page.toString() },
|
|
713
|
+
{ key: "Operator", value: operator },
|
|
714
|
+
{ key: "Like", value: like.toString() },
|
|
602
715
|
...remainFields,
|
|
603
716
|
...languageParams,
|
|
604
|
-
...remainFilters
|
|
717
|
+
...remainFilters,
|
|
718
|
+
...restrictions
|
|
605
719
|
];
|
|
606
720
|
if (queries.length > 0) {
|
|
607
721
|
params.push(
|
|
@@ -629,7 +743,8 @@ var InformationUnitsService = class extends BaseService {
|
|
|
629
743
|
{ key: "Fields", value: "versionOf" },
|
|
630
744
|
{ key: "Fields", value: "titles" },
|
|
631
745
|
{ key: "Fields", value: "languages" },
|
|
632
|
-
{ key: "Fields", value: "labels" }
|
|
746
|
+
{ key: "Fields", value: "labels" },
|
|
747
|
+
{ key: "Fields", value: "packages" }
|
|
633
748
|
];
|
|
634
749
|
return await this.request({
|
|
635
750
|
path: id,
|
|
@@ -647,23 +762,12 @@ var InformationUnitsService = class extends BaseService {
|
|
|
647
762
|
*/
|
|
648
763
|
async getSuggestions({ query, language }) {
|
|
649
764
|
return await this.request({
|
|
650
|
-
path:
|
|
765
|
+
path: "Suggestions",
|
|
651
766
|
params: [
|
|
652
767
|
{ key: "prefix", value: query },
|
|
653
768
|
{ key: "lang", value: language }
|
|
654
769
|
],
|
|
655
|
-
transformer: (data) =>
|
|
656
|
-
const suggestions = [];
|
|
657
|
-
const comparableList = [];
|
|
658
|
-
data.suggestions.forEach((item) => {
|
|
659
|
-
suggestions.push(item.value);
|
|
660
|
-
comparableList.push(item.value.toLowerCase());
|
|
661
|
-
});
|
|
662
|
-
if (!comparableList.includes(query.toLowerCase())) {
|
|
663
|
-
return [query, ...suggestions];
|
|
664
|
-
}
|
|
665
|
-
return suggestions;
|
|
666
|
-
}
|
|
770
|
+
transformer: (data) => transformSuggestions(data, query)
|
|
667
771
|
});
|
|
668
772
|
}
|
|
669
773
|
};
|
|
@@ -675,16 +779,6 @@ var LanguageService = class extends BaseService {
|
|
|
675
779
|
const configs = (0, import_next_cookies3.getConfigs)();
|
|
676
780
|
super(configs.languageSwitcher.endpoint);
|
|
677
781
|
}
|
|
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
782
|
/**
|
|
689
783
|
* Retrieves a list of available languages and their associated countries.
|
|
690
784
|
* Transforms the API response to include language code, country code, and original value.
|