@c-rex/core 0.1.13 → 0.1.14

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.js DELETED
@@ -1,350 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
-
30
- // src/index.ts
31
- var index_exports = {};
32
- __export(index_exports, {
33
- CrexApi: () => CrexApi,
34
- getClientConfig: () => getClientConfig,
35
- getServerConfig: () => getServerConfig,
36
- initializeConfig: () => initializeConfig,
37
- updateConfigProp: () => updateConfigProp
38
- });
39
- module.exports = __toCommonJS(index_exports);
40
-
41
- // src/requests.ts
42
- var import_axios = __toESM(require("axios"));
43
-
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
- };
53
- var SDK_CONFIG_KEY = "crex-sdk-config";
54
- var DEFAULT_COOKIE_LIMIT = 30 * 24 * 60 * 60 * 1e3;
55
- var CREX_TOKEN_HEADER_KEY = "crex-token";
56
-
57
- // src/requests.ts
58
- var import_headers2 = require("next/headers");
59
-
60
- // src/logger.ts
61
- var import_winston = __toESM(require("winston"));
62
-
63
- // src/transports/matomo.ts
64
- var import_winston_transport = __toESM(require("winston-transport"));
65
- var MatomoTransport = class extends import_winston_transport.default {
66
- matomoTransport;
67
- configs;
68
- /**
69
- * Creates a new instance of MatomoTransport.
70
- *
71
- * @param configs - The application configuration containing logging settings
72
- */
73
- constructor(configs) {
74
- super({
75
- level: configs.logs.matomo.minimumLevel,
76
- silent: configs.logs.matomo.silent
77
- });
78
- this.matomoTransport = new import_winston_transport.default();
79
- this.configs = configs;
80
- }
81
- /**
82
- * Logs a message to Matomo if the message category is included in the configured categories.
83
- *
84
- * @param info - The log information including level, message, and category
85
- * @param callback - Callback function to execute after logging
86
- */
87
- log(info, callback) {
88
- const matomoCategory = this.configs.logs.matomo.categoriesLevel;
89
- if (matomoCategory.includes(info.category) || matomoCategory.includes(ALL)) {
90
- this.matomoTransport.log(info, callback);
91
- }
92
- }
93
- };
94
-
95
- // src/transports/graylog.ts
96
- var import_winston_transport2 = __toESM(require("winston-transport"));
97
- var import_winston_graylog2 = __toESM(require("winston-graylog2"));
98
- var GraylogTransport = class extends import_winston_transport2.default {
99
- graylogTransport;
100
- configs;
101
- /**
102
- * Creates a new instance of GraylogTransport.
103
- *
104
- * @param configs - The application configuration containing logging settings
105
- */
106
- constructor(configs) {
107
- if (!configs.logs.graylog.hostname || configs.logs.graylog.port === void 0) {
108
- throw new Error("Graylog hostname and port must be defined");
109
- }
110
- super({
111
- level: configs.logs.graylog.minimumLevel,
112
- silent: configs.logs.graylog.silent
113
- });
114
- this.configs = configs;
115
- this.graylogTransport = new import_winston_graylog2.default({
116
- name: configs.logs.graylog.app,
117
- silent: configs.logs.graylog.silent,
118
- handleExceptions: false,
119
- graylog: {
120
- servers: [
121
- { host: configs.logs.graylog.hostname, port: configs.logs.graylog.port }
122
- ]
123
- }
124
- });
125
- }
126
- /**
127
- * Logs a message to Graylog if the message category is included in the configured categories.
128
- *
129
- * @param info - The log information including level, message, and category
130
- * @param callback - Callback function to execute after logging
131
- */
132
- log(info, callback) {
133
- const graylogCategory = this.configs.logs.graylog.categoriesLevel;
134
- if (graylogCategory.includes(info.category) || graylogCategory.includes(ALL)) {
135
- this.graylogTransport.log(info, callback);
136
- }
137
- }
138
- };
139
-
140
- // src/config.ts
141
- var import_headers = require("next/headers");
142
- var getClientConfig = () => {
143
- const jsonConfigs = (0, import_headers.cookies)().get(SDK_CONFIG_KEY)?.value;
144
- if (!jsonConfigs) {
145
- throw new Error("Configs not found");
146
- }
147
- const configs = JSON.parse(jsonConfigs);
148
- return configs;
149
- };
150
- function initializeConfig(config) {
151
- if (global.__GLOBAL_CONFIG__) return global.__GLOBAL_CONFIG__;
152
- global.__GLOBAL_CONFIG__ = config;
153
- return global.__GLOBAL_CONFIG__;
154
- }
155
- function getServerConfig() {
156
- if (!global.__GLOBAL_CONFIG__) {
157
- throw new Error("Server config not initialized");
158
- }
159
- return global.__GLOBAL_CONFIG__;
160
- }
161
- function updateConfigProp(key, value) {
162
- if (!global.__GLOBAL_CONFIG__) {
163
- throw new Error("Server config not initialized");
164
- }
165
- global.__GLOBAL_CONFIG__[key] = value;
166
- return global.__GLOBAL_CONFIG__;
167
- }
168
-
169
- // src/logger.ts
170
- var CrexLogger = class {
171
- customerConfig;
172
- logger;
173
- /**
174
- * Initializes the logger instance if it hasn't been initialized yet.
175
- * Loads customer configuration and creates the logger with appropriate transports.
176
- *
177
- * @private
178
- */
179
- async initLogger() {
180
- try {
181
- if (!this.customerConfig) {
182
- this.customerConfig = getServerConfig();
183
- }
184
- if (!this.logger) {
185
- this.logger = this.createLogger();
186
- }
187
- } catch (error) {
188
- console.log("Error initializing logger:", error);
189
- }
190
- }
191
- /**
192
- * Logs a message with the specified level and optional category.
193
- *
194
- * @param options - Logging options
195
- * @param options.level - The log level (error, warn, info, etc.)
196
- * @param options.message - The message to log
197
- * @param options.category - Optional category for the log message
198
- */
199
- async log({ level, message, category }) {
200
- await this.initLogger();
201
- const timestamp = (/* @__PURE__ */ new Date()).toISOString();
202
- const newMessage = `[${timestamp}] ${message}`;
203
- this.logger.log(level, newMessage, 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
- });
223
- }
224
- };
225
-
226
- // src/OIDC.ts
227
- var import_openid_client = require("openid-client");
228
- var getToken = async () => {
229
- try {
230
- const config = getServerConfig();
231
- const issuer = await import_openid_client.Issuer.discover(config.OIDC.client.issuer);
232
- const client = new issuer.Client({
233
- client_id: config.OIDC.client.id,
234
- client_secret: config.OIDC.client.secret
235
- });
236
- const tokenSet = await client.grant({ grant_type: "client_credentials" });
237
- const token = tokenSet.access_token;
238
- const expiresAt = tokenSet.expires_at;
239
- return { token, expiresAt };
240
- } catch (error) {
241
- const logger = new CrexLogger();
242
- logger.log({
243
- level: "error",
244
- message: `getToken error: ${error}`
245
- });
246
- return { token: "", expiresAt: 0, error: JSON.stringify(error) };
247
- }
248
- };
249
-
250
- // src/requests.ts
251
- var CrexApi = class {
252
- customerConfig;
253
- apiClient;
254
- logger;
255
- /**
256
- * Initializes the API client if it hasn't been initialized yet.
257
- * Loads customer configuration, creates the axios instance, and initializes the logger.
258
- *
259
- * @private
260
- */
261
- async initAPI() {
262
- this.logger = new CrexLogger();
263
- if (!this.customerConfig) {
264
- this.customerConfig = getServerConfig();
265
- }
266
- if (!this.apiClient) {
267
- this.apiClient = import_axios.default.create({
268
- baseURL: this.customerConfig.baseUrl
269
- });
270
- }
271
- }
272
- async manageToken() {
273
- try {
274
- let token = "";
275
- const hasToken = (0, import_headers2.cookies)().get(CREX_TOKEN_HEADER_KEY);
276
- if (hasToken == void 0 || hasToken.value === null) {
277
- const { token: tokenResult } = await getToken();
278
- if (tokenResult.length === 0) throw new Error("Token is undefined");
279
- token = tokenResult;
280
- } else {
281
- token = hasToken.value;
282
- }
283
- return token;
284
- } catch (error) {
285
- this.logger.log({
286
- level: "error",
287
- message: `CrexAPI.manageToken error: ${error}`
288
- });
289
- throw error;
290
- }
291
- }
292
- /**
293
- * Executes an API request with caching, authentication, and retry logic.
294
- *
295
- * @param options - Request options
296
- * @param options.url - The URL to request
297
- * @param options.method - The HTTP method to use
298
- * @param options.params - Optional query parameters
299
- * @param options.body - Optional request body
300
- * @param options.headers - Optional request headers
301
- * @returns The response data
302
- * @throws Error if the request fails after maximum retries
303
- */
304
- async execute({
305
- url,
306
- method,
307
- params,
308
- body,
309
- headers = {}
310
- }) {
311
- try {
312
- await this.initAPI();
313
- let response = void 0;
314
- if (this.customerConfig.OIDC.client.enabled) {
315
- const token = await this.manageToken();
316
- headers = {
317
- ...headers,
318
- Authorization: `Bearer ${token}`
319
- };
320
- this.apiClient.defaults.headers.common["Authorization"] = `Bearer ${token}`;
321
- }
322
- response = await this.apiClient.request({
323
- url,
324
- method,
325
- data: body,
326
- params,
327
- headers
328
- });
329
- if (response) {
330
- return response.data;
331
- }
332
- throw new Error("API.execute error: Failed to retrieve a valid response");
333
- } catch (error) {
334
- this.logger.log({
335
- level: "error",
336
- message: `CrexAPI.execute error: ${error}`
337
- });
338
- throw error;
339
- }
340
- }
341
- };
342
- // Annotate the CommonJS export names for ESM import in node:
343
- 0 && (module.exports = {
344
- CrexApi,
345
- getClientConfig,
346
- getServerConfig,
347
- initializeConfig,
348
- updateConfigProp
349
- });
350
- //# sourceMappingURL=index.js.map
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/index.ts","../src/requests.ts","../../constants/src/index.ts","../src/logger.ts","../src/transports/matomo.ts","../src/transports/graylog.ts","../src/config.ts","../src/OIDC.ts"],"sourcesContent":["//Do not export logger.ts. Logger must be exported as an another entrypoint on package.json\nexport * from \"./requests\";\nexport * from \"./config\";","import axios, { AxiosResponse, Method, AxiosInstance } from \"axios\";\nimport { CREX_TOKEN_HEADER_KEY } from \"@c-rex/constants\";\nimport { ConfigInterface } from \"@c-rex/interfaces\";\nimport { cookies } from \"next/headers\";\nimport { CrexLogger } from \"./logger\";\nimport { getServerConfig } from \"./config\";\nimport { getToken } from \"./OIDC\";\n\n/**\n * Interface for API response with generic data type.\n */\ninterface APIGenericResponse<T> extends AxiosResponse {\n data: T;\n statusCode: number;\n}\n\n/**\n * Interface for API call parameters.\n */\ninterface CallParams {\n url: string;\n method: Method;\n body?: any;\n headers?: any;\n params?: any;\n}\n\n/**\n * API client class for the CREX application.\n * Handles API requests with caching, authentication, and retry logic.\n */\nexport class CrexApi {\n private customerConfig!: ConfigInterface;\n private apiClient!: AxiosInstance;\n private logger!: CrexLogger;\n\n /**\n * Initializes the API client if it hasn't been initialized yet.\n * Loads customer configuration, creates the axios instance, and initializes the logger.\n * \n * @private\n */\n private async initAPI() {\n this.logger = new CrexLogger();\n\n if (!this.customerConfig) {\n this.customerConfig = getServerConfig();\n }\n\n\n if (!this.apiClient) {\n this.apiClient = axios.create({\n baseURL: this.customerConfig.baseUrl,\n })\n }\n }\n\n private async manageToken() {\n try {\n let token = \"\";\n const hasToken = cookies().get(CREX_TOKEN_HEADER_KEY);\n\n if (hasToken == undefined || hasToken.value === null) {\n const { token: tokenResult } = await getToken();\n\n if (tokenResult.length === 0) throw new Error(\"Token is undefined\");\n\n token = tokenResult;\n } else {\n token = hasToken.value;\n }\n\n return token;\n } catch (error) {\n this.logger.log({\n level: \"error\",\n message: `CrexAPI.manageToken error: ${error}`\n });\n\n throw error\n }\n }\n\n /**\n * Executes an API request with caching, authentication, and retry logic.\n * \n * @param options - Request options\n * @param options.url - The URL to request\n * @param options.method - The HTTP method to use\n * @param options.params - Optional query parameters\n * @param options.body - Optional request body\n * @param options.headers - Optional request headers\n * @returns The response data\n * @throws Error if the request fails after maximum retries\n */\n async execute<T>({\n url,\n method,\n params,\n body,\n headers = {},\n }: CallParams): Promise<T> {\n try {\n await this.initAPI();\n\n let response: APIGenericResponse<T> | undefined = undefined;\n\n if (this.customerConfig.OIDC.client.enabled) {\n const token = await this.manageToken();\n\n headers = {\n ...headers,\n Authorization: `Bearer ${token}`,\n };\n\n this.apiClient.defaults.headers.common['Authorization'] = `Bearer ${token}`;\n }\n\n response = await this.apiClient.request({\n url,\n method,\n data: body,\n params,\n headers,\n });\n\n if (response) {\n return response.data;\n }\n\n throw new Error(\"API.execute error: Failed to retrieve a valid response\");\n } catch (error) {\n this.logger.log({\n level: \"error\",\n message: `CrexAPI.execute error: ${error}`\n });\n throw error;\n }\n }\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];","import winston from \"winston\";\nimport { MatomoTransport } from \"./transports/matomo\";\nimport { GraylogTransport } from \"./transports/graylog\";\nimport { ConfigInterface } from \"@c-rex/interfaces\";\nimport { LogCategoriesType, LogLevelType } from \"@c-rex/types\";\nimport { LOG_LEVELS } from \"@c-rex/constants\";\nimport { getServerConfig } from \"./config\";\n\n\n/**\n * Logger class for the CREX application.\n * Provides logging functionality with multiple transports (Console, Matomo, Graylog).\n */\nexport class CrexLogger {\n private customerConfig!: ConfigInterface;\n public logger!: winston.Logger;\n\n /**\n * Initializes the logger instance if it hasn't been initialized yet.\n * Loads customer configuration and creates the logger with appropriate transports.\n * \n * @private\n */\n private async initLogger() {\n try {\n if (!this.customerConfig) {\n this.customerConfig = getServerConfig();\n }\n if (!this.logger) {\n this.logger = this.createLogger();\n }\n } catch (error) {\n console.log(\"Error initializing logger:\", error);\n }\n }\n\n /**\n * Logs a message with the specified level and optional category.\n * \n * @param options - Logging options\n * @param options.level - The log level (error, warn, info, etc.)\n * @param options.message - The message to log\n * @param options.category - Optional category for the log message\n */\n public async log({ level, message, category }: {\n level: LogLevelType,\n message: string,\n category?: LogCategoriesType\n }) {\n await this.initLogger();\n const timestamp = new Date().toISOString();\n const newMessage = `[${timestamp}] ${message}`;\n this.logger.log(level, newMessage, category);\n }\n\n /**\n * Creates a new Winston logger instance with configured transports.\n * \n * @private\n * @returns A configured Winston logger instance\n */\n private createLogger() {\n return winston.createLogger({\n levels: LOG_LEVELS,\n transports: [\n new winston.transports.Console({\n level: this.customerConfig.logs.console.minimumLevel,\n silent: this.customerConfig.logs.console.silent,\n }),\n new MatomoTransport(this.customerConfig),\n new GraylogTransport(this.customerConfig),\n ],\n });\n }\n}","import Transport from \"winston-transport\";\nimport { LogCategoriesType, LogLevelType } from \"@c-rex/types\";\nimport { ALL } from \"@c-rex/constants\";\nimport { ConfigInterface } from \"@c-rex/interfaces\";\n\n/**\n * Winston transport for sending logs to Matomo analytics.\n * Extends the base Winston transport with Matomo-specific functionality.\n */\nexport class MatomoTransport extends Transport {\n public matomoTransport: any;\n private configs: ConfigInterface;\n\n /**\n * Creates a new instance of MatomoTransport.\n * \n * @param configs - The application configuration containing logging settings\n */\n constructor(configs: ConfigInterface) {\n super({\n level: configs.logs.matomo.minimumLevel,\n silent: configs.logs.matomo.silent,\n });\n\n this.matomoTransport = new Transport();\n this.configs = configs;\n }\n\n /**\n * Logs a message to Matomo if the message category is included in the configured categories.\n * \n * @param info - The log information including level, message, and category\n * @param callback - Callback function to execute after logging\n */\n log(\n info: { level: LogLevelType, message: string, category: LogCategoriesType },\n callback: () => void,\n ): void {\n const matomoCategory = this.configs.logs.matomo.categoriesLevel\n\n if (matomoCategory.includes(info.category) || matomoCategory.includes(ALL)) {\n this.matomoTransport.log(info, callback);\n }\n }\n}\n","import Transport from \"winston-transport\";\nimport Graylog2Transport from \"winston-graylog2\";\nimport { LogCategoriesType, LogLevelType } from \"@c-rex/types\";\nimport { ALL } from \"@c-rex/constants\";\nimport { ConfigInterface } from \"@c-rex/interfaces\";\n\n/**\n * Winston transport for sending logs to Graylog.\n * Extends the base Winston transport with Graylog-specific functionality.\n */\nexport class GraylogTransport extends Transport {\n public graylogTransport: any;\n private configs: ConfigInterface\n\n /**\n * Creates a new instance of GraylogTransport.\n * \n * @param configs - The application configuration containing logging settings\n */\n constructor(configs: ConfigInterface) {\n if (!configs.logs.graylog.hostname || configs.logs.graylog.port === undefined) {\n throw new Error(\"Graylog hostname and port must be defined\");\n }\n\n super({\n level: configs.logs.graylog.minimumLevel,\n silent: configs.logs.graylog.silent,\n });\n\n this.configs = configs;\n this.graylogTransport = new Graylog2Transport({\n name: configs.logs.graylog.app,\n silent: configs.logs.graylog.silent,\n handleExceptions: false,\n graylog: {\n servers: [\n { host: configs.logs.graylog.hostname, port: configs.logs.graylog.port }\n ],\n },\n });\n }\n\n /**\n * Logs a message to Graylog if the message category is included in the configured categories.\n * \n * @param info - The log information including level, message, and category\n * @param callback - Callback function to execute after logging\n */\n log(\n info: { level: LogLevelType, message: string, category: LogCategoriesType },\n callback: () => void,\n ): void {\n const graylogCategory = this.configs.logs.graylog.categoriesLevel\n\n if (graylogCategory.includes(info.category) || graylogCategory.includes(ALL)) {\n this.graylogTransport.log(info, callback);\n }\n }\n}\n","import { ConfigInterface, CookiesConfigs } from \"@c-rex/interfaces\";\nimport { SDK_CONFIG_KEY } from '@c-rex/constants';\nimport { cookies } from 'next/headers';\n\n/**\n * Retrieves and parses configuration data from a cookie.\n * @returns The parsed configuration object\n * @throws Error if the configuration cookie is not found or cannot be parsed\n */\nexport const getClientConfig = (): CookiesConfigs => {\n const jsonConfigs = cookies().get(SDK_CONFIG_KEY)?.value;\n if (!jsonConfigs) {\n throw new Error('Configs not found');\n }\n\n const configs: CookiesConfigs = JSON.parse(jsonConfigs);\n\n return configs;\n}\n\ndeclare global {\n // eslint-disable-next-line no-var\n var __GLOBAL_CONFIG__: ConfigInterface | null;\n}\n\nexport function initializeConfig(config: ConfigInterface) {\n if (global.__GLOBAL_CONFIG__) return global.__GLOBAL_CONFIG__;\n global.__GLOBAL_CONFIG__ = config;\n return global.__GLOBAL_CONFIG__;\n}\n\nexport function getServerConfig() {\n if (!global.__GLOBAL_CONFIG__) {\n throw new Error('Server config not initialized');\n }\n return global.__GLOBAL_CONFIG__;\n}\n\nexport function updateConfigProp(key: keyof ConfigInterface, value: any) {\n if (!global.__GLOBAL_CONFIG__) {\n throw new Error('Server config not initialized');\n }\n global.__GLOBAL_CONFIG__[key] = value;\n return global.__GLOBAL_CONFIG__;\n}","import { Issuer } from 'openid-client';\nimport { getServerConfig } from './config';\nimport { CrexLogger } from './logger';\nimport { CrexSDK } from './sdk';\n\n/**\n * Retrieves an access token using client credentials flow from the configured OIDC provider\n * \n * @returns NextResponse with success status or error message\n * @throws Error if token retrieval fails\n */\nexport const getToken = async (): Promise<{ token: string; expiresAt: number; error?: string }> => {\n try {\n const config = getServerConfig();\n const issuer = await Issuer.discover(config.OIDC.client.issuer);\n const client = new issuer.Client({\n client_id: config.OIDC.client.id,\n client_secret: config.OIDC.client.secret,\n });\n const tokenSet = await client.grant({ grant_type: 'client_credentials' });\n\n const token = tokenSet.access_token!;\n const expiresAt = tokenSet.expires_at!;\n\n return { token, expiresAt };\n\n } catch (error) {\n const logger = new CrexLogger()\n logger.log({\n level: \"error\",\n message: `getToken error: ${error}`\n })\n return { token: '', expiresAt: 0, error: JSON.stringify(error) };\n\n }\n}\n\nexport const getIssuerMetadata = async (): Promise<any> => {\n const sdk = new CrexSDK();\n const config = sdk.getServerConfig();\n const issuer = await Issuer.discover(config.OIDC.client.issuer);\n return issuer.metadata;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAA4D;;;ACArD,IAAM,MAAM;AAeZ,IAAM,aAAa;AAAA,EACtB,UAAU;AAAA,EACV,OAAO;AAAA,EACP,SAAS;AAAA,EACT,MAAM;AAAA,EACN,OAAO;AACX;AAiBO,IAAM,iBAAiB;AAwCvB,IAAM,uBAAuB,KAAK,KAAK,KAAK,KAAK;AAQjD,IAAM,wBAAwB;;;ADnFrC,IAAAA,kBAAwB;;;AEHxB,qBAAoB;;;ACApB,+BAAsB;AASf,IAAM,kBAAN,cAA8B,yBAAAC,QAAU;AAAA,EACpC;AAAA,EACC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOR,YAAY,SAA0B;AAClC,UAAM;AAAA,MACF,OAAO,QAAQ,KAAK,OAAO;AAAA,MAC3B,QAAQ,QAAQ,KAAK,OAAO;AAAA,IAChC,CAAC;AAED,SAAK,kBAAkB,IAAI,yBAAAA,Q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M;AAAA,QACN;AAAA,QACA;AAAA,MACJ,CAAC;AAED,UAAI,UAAU;AACV,eAAO,SAAS;AAAA,MACpB;AAEA,YAAM,IAAI,MAAM,wDAAwD;AAAA,IAC5E,SAAS,OAAO;AACZ,WAAK,OAAO,IAAI;AAAA,QACZ,OAAO;AAAA,QACP,SAAS,0BAA0B,KAAK;AAAA,MAC5C,CAAC;AACD,YAAM;AAAA,IACV;AAAA,EACJ;AACJ;","names":["import_headers","Transport","import_winston_transport","Transport","Graylog2Transport","winston","axios"]}