@c-rex/core 0.1.8 → 0.1.9
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 +3 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +3 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -230,7 +230,7 @@ var CrexApi = class {
|
|
|
230
230
|
}
|
|
231
231
|
async getToken() {
|
|
232
232
|
try {
|
|
233
|
-
const response = await fetch(`${
|
|
233
|
+
const response = await fetch(`${this.customerConfig.publicNextApiUrl}/api/token`, {
|
|
234
234
|
method: "POST",
|
|
235
235
|
credentials: "include"
|
|
236
236
|
});
|
|
@@ -259,7 +259,7 @@ var CrexApi = class {
|
|
|
259
259
|
} catch (error) {
|
|
260
260
|
this.logger.log({
|
|
261
261
|
level: "error",
|
|
262
|
-
message: `
|
|
262
|
+
message: `CrexAPI.manageToken error: ${error}`
|
|
263
263
|
});
|
|
264
264
|
throw error;
|
|
265
265
|
}
|
|
@@ -365,7 +365,7 @@ var CrexSDK = class {
|
|
|
365
365
|
idToken: true,
|
|
366
366
|
checks: ["pkce", "state"],
|
|
367
367
|
async profile(_, tokens) {
|
|
368
|
-
const res = await fetch(
|
|
368
|
+
const res = await fetch(user.userInfoEndPoint, {
|
|
369
369
|
headers: {
|
|
370
370
|
Authorization: `Bearer ${tokens.access_token}`
|
|
371
371
|
}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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/sdk.ts"],"sourcesContent":["//Do not export logger.ts. Logger must be exported as an another entrypoint on package.json\nexport * from \"./requests\";\nexport * from \"./sdk\";","import axios, { AxiosResponse, Method, AxiosInstance } from \"axios\";\nimport { API, CREX_TOKEN_HEADER_KEY, SDK_CONFIG_KEY } from \"@c-rex/constants\";\nimport { ConfigInterface } from \"@c-rex/interfaces\";\nimport { cookies } from \"next/headers\";\nimport { CrexLogger } from \"./logger\";\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 const aux = cookies().get(SDK_CONFIG_KEY);\n if (aux != undefined) {\n this.customerConfig = JSON.parse(aux.value);\n } else {\n this.logger.log({\n level: \"error\",\n message: `utils.initAPI error: Config cookie not available`\n });\n\n throw new Error(\"Config cookie not available\");\n }\n }\n\n if (!this.apiClient) {\n this.apiClient = axios.create({\n baseURL: this.customerConfig.baseUrl,\n })\n }\n }\n\n private async getToken() {\n try {\n const response = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/api/token`, {\n method: 'POST',\n credentials: 'include',\n });\n\n const { token } = await response.json();\n\n return token;\n } catch (error) {\n this.logger.log({\n level: \"error\",\n message: `utils.getToken error: ${error}`\n });\n\n throw error\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 tokenResult = await this.getToken();\n\n if (tokenResult === null) 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: `utils.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 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 for (let retry = 0; retry < API.MAX_RETRY; retry++) {\n try {\n response = await this.apiClient.request({\n url,\n method,\n data: body,\n params,\n headers,\n });\n\n break;\n } catch (error) {\n this.logger.log({\n level: \"error\",\n message: `API.execute ${retry + 1}º error when request ${url}. Error: ${error}`\n });\n\n if (retry === API.MAX_RETRY - 1) {\n throw error;\n }\n }\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 }\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] as const;\n\nexport const API = {\n MAX_RETRY: 3,\n API_TIMEOUT: 10000,\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 = 7 * 24 * 60 * 60 * 1000; // 7 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};","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 { getConfigs } from \"@c-rex/utils/next-cookies\";\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 = await getConfigs();\n }\n if (!this.logger) {\n this.logger = this.createLogger();\n }\n } catch (error) {\n console.error(\"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 this.logger.log(level, message, 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 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: \"crex.net.documentation\",\n //name: \"crex.net.blog\",\n silent: false,\n handleExceptions: false,\n graylog: {\n servers: [\n { host: \"localhost\", port: 12201 },\n { host: \"https://log.c-rex.net\", port: 12202 }\n\n //TODO: check the URL => https://log.c-rex.net:12202/gelf\" GELF??\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 { getConfigs } from \"@c-rex/utils/next-cookies\";\nimport { ConfigInterface } from \"@c-rex/interfaces\";\n\n/**\n * SDK class for the CREX application.\n * Provides configuration and authentication functionality.\n */\nexport class CrexSDK {\n public userAuthConfig!: any;\n public customerConfig!: ConfigInterface;\n\n /**\n * Retrieves the customer configuration if it hasn't been loaded yet.\n * \n * @private\n */\n private async getConfig() {\n if (!this.customerConfig) {\n this.customerConfig = await getConfigs()\n }\n }\n\n /**\n * Retrieves the user authentication configuration.\n * If not already loaded, it will load the customer configuration and\n * create the auth config based on OIDC settings.\n * \n * @returns The user authentication configuration object\n */\n public async getUserAuthConfig() {\n if (this.userAuthConfig) {\n return this.userAuthConfig;\n }\n\n await this.getConfig();\n\n const user = this.customerConfig.OIDC.user;\n if (user.enabled) {\n this.userAuthConfig = {\n providers: [\n {\n id: \"crex\",\n name: \"CREX\",\n type: \"oauth\",\n version: \"2.0\",\n clientId: user.id,\n wellKnown: user.issuer,\n clientSecret: user.secret,\n authorization: {\n params: { scope: user.scope }\n },\n idToken: true,\n checks: [\"pkce\", \"state\"],\n async profile(_: any, tokens: any) {\n\n const res = await fetch(\"https://data2type.c-rex.net/oidc/connect/userinfo\", {\n headers: {\n Authorization: `Bearer ${tokens.access_token}`,\n },\n });\n\n const userinfo = await res.json();\n\n return {\n id: userinfo.sub,\n name: userinfo.name,\n email: userinfo.email,\n };\n },\n },\n ]\n }\n };\n\n return this.userAuthConfig;\n }\n}"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;AAOO,IAAM,MAAM;AAAA,EACf,WAAW;AAAA,EACX,aAAa;AAAA,EACb,aAAa;A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ACV;AAAA,EACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOP,MAAc,YAAY;AACtB,QAAI,CAAC,KAAK,gBAAgB;AACtB,WAAK,iBAAiB,UAAM,iCAAW;AAAA,IAC3C;AAAA,EACJ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,MAAa,oBAAoB;AAC7B,QAAI,KAAK,gBAAgB;AACrB,aAAO,KAAK;AAAA,IAChB;AAEA,UAAM,KAAK,UAAU;AAErB,UAAM,OAAO,KAAK,eAAe,KAAK;AACtC,QAAI,KAAK,SAAS;AACd,WAAK,iBAAiB;AAAA,QAClB,WAAW;AAAA,UACP;AAAA,YACI,IAAI;AAAA,YACJ,MAAM;AAAA,YACN,MAAM;AAAA,YACN,SAAS;AAAA,YACT,UAAU,KAAK;AAAA,YACf,WAAW,KAAK;AAAA,YAChB,cAAc,KAAK;AAAA,YACnB,eAAe;AAAA,cACX,QAAQ,EAAE,OAAO,KAAK,MAAM;AAAA,YAChC;AAAA,YACA,SAAS;AAAA,YACT,QAAQ,CAAC,QAAQ,OAAO;AAAA,YACxB,MAAM,QAAQ,GAAQ,QAAa;AAE/B,oBAAM,MAAM,MAAM,MAAM,qDAAqD;AAAA,gBACzE,SAAS;AAAA,kBACL,eAAe,UAAU,OAAO,YAAY;AAAA,gBAChD;AAAA,cACJ,CAAC;AAED,oBAAM,WAAW,MAAM,IAAI,KAAK;AAEhC,qBAAO;AAAA,gBACH,IAAI,SAAS;AAAA,gBACb,MAAM,SAAS;AAAA,gBACf,OAAO,SAAS;AAAA,cACpB;AAAA,YACJ;AAAA,UACJ;AAAA,QACJ;AAAA,MACJ;AAAA,IACJ;AAAC;AAED,WAAO,KAAK;AAAA,EAChB;AACJ;","names":["Transport","import_winston_transport","Transport","Graylog2Transport","winston","axios","import_next_cookies"]}
|
|
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/sdk.ts"],"sourcesContent":["//Do not export logger.ts. Logger must be exported as an another entrypoint on package.json\nexport * from \"./requests\";\nexport * from \"./sdk\";","import axios, { AxiosResponse, Method, AxiosInstance } from \"axios\";\nimport { API, CREX_TOKEN_HEADER_KEY, SDK_CONFIG_KEY } from \"@c-rex/constants\";\nimport { ConfigInterface } from \"@c-rex/interfaces\";\nimport { cookies } from \"next/headers\";\nimport { CrexLogger } from \"./logger\";\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 const aux = cookies().get(SDK_CONFIG_KEY);\n if (aux != undefined) {\n this.customerConfig = JSON.parse(aux.value);\n } else {\n this.logger.log({\n level: \"error\",\n message: `utils.initAPI error: Config cookie not available`\n });\n\n throw new Error(\"Config cookie not available\");\n }\n }\n\n if (!this.apiClient) {\n this.apiClient = axios.create({\n baseURL: this.customerConfig.baseUrl,\n })\n }\n }\n\n private async getToken() {\n try {\n const response = await fetch(`${this.customerConfig.publicNextApiUrl}/api/token`, {\n method: 'POST',\n credentials: 'include',\n });\n\n const { token } = await response.json();\n\n return token;\n } catch (error) {\n this.logger.log({\n level: \"error\",\n message: `utils.getToken error: ${error}`\n });\n\n throw error\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 tokenResult = await this.getToken();\n\n if (tokenResult === null) 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 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 for (let retry = 0; retry < API.MAX_RETRY; retry++) {\n try {\n response = await this.apiClient.request({\n url,\n method,\n data: body,\n params,\n headers,\n });\n\n break;\n } catch (error) {\n this.logger.log({\n level: \"error\",\n message: `API.execute ${retry + 1}º error when request ${url}. Error: ${error}`\n });\n\n if (retry === API.MAX_RETRY - 1) {\n throw error;\n }\n }\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 }\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] as const;\n\nexport const API = {\n MAX_RETRY: 3,\n API_TIMEOUT: 10000,\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 = 7 * 24 * 60 * 60 * 1000; // 7 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};","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 { getConfigs } from \"@c-rex/utils/next-cookies\";\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 = await getConfigs();\n }\n if (!this.logger) {\n this.logger = this.createLogger();\n }\n } catch (error) {\n console.error(\"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 this.logger.log(level, message, 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 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: \"crex.net.documentation\",\n //name: \"crex.net.blog\",\n silent: false,\n handleExceptions: false,\n graylog: {\n servers: [\n { host: \"localhost\", port: 12201 },\n { host: \"https://log.c-rex.net\", port: 12202 }\n\n //TODO: check the URL => https://log.c-rex.net:12202/gelf\" GELF??\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 { getConfigs } from \"@c-rex/utils/next-cookies\";\nimport { ConfigInterface } from \"@c-rex/interfaces\";\n\n/**\n * SDK class for the CREX application.\n * Provides configuration and authentication functionality.\n */\nexport class CrexSDK {\n public userAuthConfig!: any;\n public customerConfig!: ConfigInterface;\n\n /**\n * Retrieves the customer configuration if it hasn't been loaded yet.\n * \n * @private\n */\n private async getConfig() {\n if (!this.customerConfig) {\n this.customerConfig = await getConfigs()\n }\n }\n\n /**\n * Retrieves the user authentication configuration.\n * If not already loaded, it will load the customer configuration and\n * create the auth config based on OIDC settings.\n * \n * @returns The user authentication configuration object\n */\n public async getUserAuthConfig() {\n if (this.userAuthConfig) {\n return this.userAuthConfig;\n }\n\n await this.getConfig();\n\n const user = this.customerConfig.OIDC.user;\n if (user.enabled) {\n this.userAuthConfig = {\n providers: [\n {\n id: \"crex\",\n name: \"CREX\",\n type: \"oauth\",\n version: \"2.0\",\n clientId: user.id,\n wellKnown: user.issuer,\n clientSecret: user.secret,\n authorization: {\n params: { scope: user.scope }\n },\n idToken: true,\n checks: [\"pkce\", \"state\"],\n async profile(_: any, tokens: any) {\n const res = await fetch(user.userInfoEndPoint!, {\n headers: {\n Authorization: `Bearer ${tokens.access_token}`,\n },\n });\n\n const userinfo = await res.json();\n\n return {\n id: userinfo.sub,\n name: userinfo.name,\n email: userinfo.email,\n };\n },\n },\n ]\n }\n };\n\n return this.userAuthConfig;\n }\n}"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAA4D;;;ACArD,IAAM,MAAM;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C;AAED,WAAO,KAAK;AAAA,EAChB;AACJ;","names":["Transport","import_winston_transport","Transport","Graylog2Transport","winston","axios","import_next_cookies"]}
|
package/dist/index.mjs
CHANGED
|
@@ -193,7 +193,7 @@ var CrexApi = class {
|
|
|
193
193
|
}
|
|
194
194
|
async getToken() {
|
|
195
195
|
try {
|
|
196
|
-
const response = await fetch(`${
|
|
196
|
+
const response = await fetch(`${this.customerConfig.publicNextApiUrl}/api/token`, {
|
|
197
197
|
method: "POST",
|
|
198
198
|
credentials: "include"
|
|
199
199
|
});
|
|
@@ -222,7 +222,7 @@ var CrexApi = class {
|
|
|
222
222
|
} catch (error) {
|
|
223
223
|
this.logger.log({
|
|
224
224
|
level: "error",
|
|
225
|
-
message: `
|
|
225
|
+
message: `CrexAPI.manageToken error: ${error}`
|
|
226
226
|
});
|
|
227
227
|
throw error;
|
|
228
228
|
}
|
|
@@ -328,7 +328,7 @@ var CrexSDK = class {
|
|
|
328
328
|
idToken: true,
|
|
329
329
|
checks: ["pkce", "state"],
|
|
330
330
|
async profile(_, tokens) {
|
|
331
|
-
const res = await fetch(
|
|
331
|
+
const res = await fetch(user.userInfoEndPoint, {
|
|
332
332
|
headers: {
|
|
333
333
|
Authorization: `Bearer ${tokens.access_token}`
|
|
334
334
|
}
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/requests.ts","../../constants/src/index.ts","../src/logger.ts","../src/transports/matomo.ts","../src/transports/graylog.ts","../src/sdk.ts"],"sourcesContent":["import axios, { AxiosResponse, Method, AxiosInstance } from \"axios\";\nimport { API, CREX_TOKEN_HEADER_KEY, SDK_CONFIG_KEY } from \"@c-rex/constants\";\nimport { ConfigInterface } from \"@c-rex/interfaces\";\nimport { cookies } from \"next/headers\";\nimport { CrexLogger } from \"./logger\";\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 const aux = cookies().get(SDK_CONFIG_KEY);\n if (aux != undefined) {\n this.customerConfig = JSON.parse(aux.value);\n } else {\n this.logger.log({\n level: \"error\",\n message: `utils.initAPI error: Config cookie not available`\n });\n\n throw new Error(\"Config cookie not available\");\n }\n }\n\n if (!this.apiClient) {\n this.apiClient = axios.create({\n baseURL: this.customerConfig.baseUrl,\n })\n }\n }\n\n private async getToken() {\n try {\n const response = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/api/token`, {\n method: 'POST',\n credentials: 'include',\n });\n\n const { token } = await response.json();\n\n return token;\n } catch (error) {\n this.logger.log({\n level: \"error\",\n message: `utils.getToken error: ${error}`\n });\n\n throw error\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 tokenResult = await this.getToken();\n\n if (tokenResult === null) 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: `utils.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 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 for (let retry = 0; retry < API.MAX_RETRY; retry++) {\n try {\n response = await this.apiClient.request({\n url,\n method,\n data: body,\n params,\n headers,\n });\n\n break;\n } catch (error) {\n this.logger.log({\n level: \"error\",\n message: `API.execute ${retry + 1}º error when request ${url}. Error: ${error}`\n });\n\n if (retry === API.MAX_RETRY - 1) {\n throw error;\n }\n }\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 }\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] as const;\n\nexport const API = {\n MAX_RETRY: 3,\n API_TIMEOUT: 10000,\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 = 7 * 24 * 60 * 60 * 1000; // 7 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};","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 { getConfigs } from \"@c-rex/utils/next-cookies\";\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 = await getConfigs();\n }\n if (!this.logger) {\n this.logger = this.createLogger();\n }\n } catch (error) {\n console.error(\"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 this.logger.log(level, message, 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 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: \"crex.net.documentation\",\n //name: \"crex.net.blog\",\n silent: false,\n handleExceptions: false,\n graylog: {\n servers: [\n { host: \"localhost\", port: 12201 },\n { host: \"https://log.c-rex.net\", port: 12202 }\n\n //TODO: check the URL => https://log.c-rex.net:12202/gelf\" GELF??\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 { getConfigs } from \"@c-rex/utils/next-cookies\";\nimport { ConfigInterface } from \"@c-rex/interfaces\";\n\n/**\n * SDK class for the CREX application.\n * Provides configuration and authentication functionality.\n */\nexport class CrexSDK {\n public userAuthConfig!: any;\n public customerConfig!: ConfigInterface;\n\n /**\n * Retrieves the customer configuration if it hasn't been loaded yet.\n * \n * @private\n */\n private async getConfig() {\n if (!this.customerConfig) {\n this.customerConfig = await getConfigs()\n }\n }\n\n /**\n * Retrieves the user authentication configuration.\n * If not already loaded, it will load the customer configuration and\n * create the auth config based on OIDC settings.\n * \n * @returns The user authentication configuration object\n */\n public async getUserAuthConfig() {\n if (this.userAuthConfig) {\n return this.userAuthConfig;\n }\n\n await this.getConfig();\n\n const user = this.customerConfig.OIDC.user;\n if (user.enabled) {\n this.userAuthConfig = {\n providers: [\n {\n id: \"crex\",\n name: \"CREX\",\n type: \"oauth\",\n version: \"2.0\",\n clientId: user.id,\n wellKnown: user.issuer,\n clientSecret: user.secret,\n authorization: {\n params: { scope: user.scope }\n },\n idToken: true,\n checks: [\"pkce\", \"state\"],\n async profile(_: any, tokens: any) {\n\n const res = await fetch(\"https://data2type.c-rex.net/oidc/connect/userinfo\", {\n headers: {\n Authorization: `Bearer ${tokens.access_token}`,\n },\n });\n\n const userinfo = await res.json();\n\n return {\n id: userinfo.sub,\n name: userinfo.name,\n email: userinfo.email,\n };\n },\n },\n ]\n }\n };\n\n return this.userAuthConfig;\n }\n}"],"mappings":";AAAA,OAAO,WAAqD;;;ACArD,IAAM,MAAM;AAeZ,IAAM,aAAa;AAAA,EACtB,UAAU;AAAA,EACV,OAAO;AAAA,EACP,SAAS;AAAA,EACT,MAAM;AAAA,EACN,OAAO;AACX;AAOO,IAAM,MAAM;AAAA,EACf,WAAW;AAAA,EACX,aAAa;AAAA,EACb,aAAa;AAAA,IACT,gBAAgB;AAAA,EACpB;AACJ;AAEO,IAAM,iBAAiB;AAwCvB,IAAM,uBAAuB,IAAI,KAAK,KAAK,KAAK;AAQhD,IAAM,wBAAwB;;;ADjFrC,SAAS,eAAe;;;AEHxB,OAAO,aAAa;;;ACApB,OAAO,eAAe;AASf,IAAM,kBAAN,cAA8B,UAAU;AAAA,EACpC;AAAA,EACC;AAAA;AAA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B;AAEA,UAAM,KAAK,UAAU;AAErB,UAAM,OAAO,KAAK,eAAe,KAAK;AACtC,QAAI,KAAK,SAAS;AACd,WAAK,iBAAiB;AAAA,QAClB,WAAW;AAAA,UACP;AAAA,YACI,IAAI;AAAA,YACJ,MAAM;AAAA,YACN,MAAM;AAAA,YACN,SAAS;AAAA,YACT,UAAU,KAAK;AAAA,YACf,WAAW,KAAK;AAAA,YAChB,cAAc,KAAK;AAAA,YACnB,eAAe;AAAA,cACX,QAAQ,EAAE,OAAO,KAAK,MAAM;AAAA,YAChC;AAAA,YACA,SAAS;AAAA,YACT,QAAQ,CAAC,QAAQ,OAAO;AAAA,YACxB,MAAM,QAAQ,GAAQ,QAAa;AAE/B,oBAAM,MAAM,MAAM,MAAM,qDAAqD;AAAA,gBACzE,SAAS;AAAA,kBACL,eAAe,UAAU,OAAO,YAAY;AAAA,gBAChD;AAAA,cACJ,CAAC;AAED,oBAAM,WAAW,MAAM,IAAI,KAAK;AAEhC,qBAAO;AAAA,gBACH,IAAI,SAAS;AAAA,gBACb,MAAM,SAAS;AAAA,gBACf,OAAO,SAAS;AAAA,cACpB;AAAA,YACJ;AAAA,UACJ;AAAA,QACJ;AAAA,MACJ;AAAA,IACJ;AAAC;AAED,WAAO,KAAK;AAAA,EAChB;AACJ;","names":["Transport","Transport","getConfigs"]}
|
|
1
|
+
{"version":3,"sources":["../src/requests.ts","../../constants/src/index.ts","../src/logger.ts","../src/transports/matomo.ts","../src/transports/graylog.ts","../src/sdk.ts"],"sourcesContent":["import axios, { AxiosResponse, Method, AxiosInstance } from \"axios\";\nimport { API, CREX_TOKEN_HEADER_KEY, SDK_CONFIG_KEY } from \"@c-rex/constants\";\nimport { ConfigInterface } from \"@c-rex/interfaces\";\nimport { cookies } from \"next/headers\";\nimport { CrexLogger } from \"./logger\";\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 const aux = cookies().get(SDK_CONFIG_KEY);\n if (aux != undefined) {\n this.customerConfig = JSON.parse(aux.value);\n } else {\n this.logger.log({\n level: \"error\",\n message: `utils.initAPI error: Config cookie not available`\n });\n\n throw new Error(\"Config cookie not available\");\n }\n }\n\n if (!this.apiClient) {\n this.apiClient = axios.create({\n baseURL: this.customerConfig.baseUrl,\n })\n }\n }\n\n private async getToken() {\n try {\n const response = await fetch(`${this.customerConfig.publicNextApiUrl}/api/token`, {\n method: 'POST',\n credentials: 'include',\n });\n\n const { token } = await response.json();\n\n return token;\n } catch (error) {\n this.logger.log({\n level: \"error\",\n message: `utils.getToken error: ${error}`\n });\n\n throw error\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 tokenResult = await this.getToken();\n\n if (tokenResult === null) 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 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 for (let retry = 0; retry < API.MAX_RETRY; retry++) {\n try {\n response = await this.apiClient.request({\n url,\n method,\n data: body,\n params,\n headers,\n });\n\n break;\n } catch (error) {\n this.logger.log({\n level: \"error\",\n message: `API.execute ${retry + 1}º error when request ${url}. Error: ${error}`\n });\n\n if (retry === API.MAX_RETRY - 1) {\n throw error;\n }\n }\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 }\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] as const;\n\nexport const API = {\n MAX_RETRY: 3,\n API_TIMEOUT: 10000,\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 = 7 * 24 * 60 * 60 * 1000; // 7 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};","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 { getConfigs } from \"@c-rex/utils/next-cookies\";\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 = await getConfigs();\n }\n if (!this.logger) {\n this.logger = this.createLogger();\n }\n } catch (error) {\n console.error(\"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 this.logger.log(level, message, 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 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: \"crex.net.documentation\",\n //name: \"crex.net.blog\",\n silent: false,\n handleExceptions: false,\n graylog: {\n servers: [\n { host: \"localhost\", port: 12201 },\n { host: \"https://log.c-rex.net\", port: 12202 }\n\n //TODO: check the URL => https://log.c-rex.net:12202/gelf\" GELF??\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 { getConfigs } from \"@c-rex/utils/next-cookies\";\nimport { ConfigInterface } from \"@c-rex/interfaces\";\n\n/**\n * SDK class for the CREX application.\n * Provides configuration and authentication functionality.\n */\nexport class CrexSDK {\n public userAuthConfig!: any;\n public customerConfig!: ConfigInterface;\n\n /**\n * Retrieves the customer configuration if it hasn't been loaded yet.\n * \n * @private\n */\n private async getConfig() {\n if (!this.customerConfig) {\n this.customerConfig = await getConfigs()\n }\n }\n\n /**\n * Retrieves the user authentication configuration.\n * If not already loaded, it will load the customer configuration and\n * create the auth config based on OIDC settings.\n * \n * @returns The user authentication configuration object\n */\n public async getUserAuthConfig() {\n if (this.userAuthConfig) {\n return this.userAuthConfig;\n }\n\n await this.getConfig();\n\n const user = this.customerConfig.OIDC.user;\n if (user.enabled) {\n this.userAuthConfig = {\n providers: [\n {\n id: \"crex\",\n name: \"CREX\",\n type: \"oauth\",\n version: \"2.0\",\n clientId: user.id,\n wellKnown: user.issuer,\n clientSecret: user.secret,\n authorization: {\n params: { scope: user.scope }\n },\n idToken: true,\n checks: [\"pkce\", \"state\"],\n async profile(_: any, tokens: any) {\n const res = await fetch(user.userInfoEndPoint!, {\n headers: {\n Authorization: `Bearer ${tokens.access_token}`,\n },\n });\n\n const userinfo = await res.json();\n\n return {\n id: userinfo.sub,\n name: userinfo.name,\n email: userinfo.email,\n };\n },\n },\n ]\n }\n };\n\n return this.userAuthConfig;\n }\n}"],"mappings":";AAAA,OAAO,WAAqD;;;ACArD,IAAM,MAAM;AAeZ,IAAM,aAAa;AAAA,EACtB,UAAU;AAAA,EACV,OAAO;AAAA,EACP,SAAS;AAAA,EACT,MAAM;AAAA,EACN,OAAO;AACX;AAOO,IAAM,MAAM;AAAA,EACf,WAAW;AAAA,EACX,aAAa;AAAA,EACb,aAAa;AAAA,IACT,gBAAgB;AAAA,EACpB;AACJ;AAEO,IAAM,iBAAiB;AAwCvB,IAAM,uBAAuB,IAAI,KAAK,KAAK,KAAK;AAQhD,IAAM,wBAAwB;;;ADjFrC,SAAS,eAAe;;;AEHxB,OAAO,aAAa;;;ACApB,OAAO,eAAe;AASf,IAAM,kBAAN,cAA8B,UAAU;AAAA,EACpC;AAAA,EACC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,E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