@c-rex/core 0.1.11 → 0.1.13
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/api/{token.d.mts → OIDC.d.mts} +3 -2
- package/dist/api/{token.d.ts → OIDC.d.ts} +3 -2
- package/dist/api/OIDC.js +623 -0
- package/dist/api/OIDC.js.map +1 -0
- package/dist/api/OIDC.mjs +587 -0
- package/dist/api/OIDC.mjs.map +1 -0
- package/dist/api/cookies.js.map +1 -1
- package/dist/api/cookies.mjs.map +1 -1
- package/dist/api/rpc.js +14 -5
- package/dist/api/rpc.js.map +1 -1
- package/dist/api/rpc.mjs +14 -5
- package/dist/api/rpc.mjs.map +1 -1
- package/dist/index.d.mts +11 -23
- package/dist/index.d.ts +11 -23
- package/dist/index.js +99 -159
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +95 -158
- package/dist/index.mjs.map +1 -1
- package/dist/logger.js +14 -5
- package/dist/logger.js.map +1 -1
- package/dist/logger.mjs +14 -5
- package/dist/logger.mjs.map +1 -1
- package/dist/sdk.d.mts +25 -0
- package/dist/sdk.d.ts +25 -0
- package/dist/sdk.js +387 -0
- package/dist/sdk.js.map +1 -0
- package/dist/sdk.mjs +360 -0
- package/dist/sdk.mjs.map +1 -0
- package/package.json +12 -6
- package/dist/api/token.js +0 -67
- package/dist/api/token.js.map +0 -1
- package/dist/api/token.mjs +0 -42
- package/dist/api/token.mjs.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/api/OIDC.ts","../../../constants/src/index.ts","../../src/OIDC.ts","../../src/config.ts","../../src/logger.ts","../../src/transports/matomo.ts","../../src/transports/graylog.ts","../../src/utils.ts","../../src/sdk.ts"],"sourcesContent":["import { NextResponse } from 'next/server';\nimport { CREX_TOKEN_HEADER_KEY } from '@c-rex/constants';\nimport { getIssuerMetadata, getToken } from '../OIDC';\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 getTokenMethod = async (): Promise<NextResponse> => {\n try {\n const { token, expiresAt, error } = await getToken();\n\n if (error) {\n return NextResponse.json({ error }, { status: 500 });\n }\n\n const response = NextResponse.json({ token: token });\n\n response.cookies.set({\n name: CREX_TOKEN_HEADER_KEY,\n value: token,\n httpOnly: true,\n secure: process.env.NODE_ENV === 'production',\n sameSite: 'lax',\n path: '/',\n expires: expiresAt ? new Date(expiresAt * 1000) : undefined\n });\n\n return response;\n\n } catch (error) {\n return NextResponse.json({ error: String(error) }, { status: 500 });\n }\n}\n\nexport const discoverIssuerMethod = async (): Promise<NextResponse> => {\n try {\n const metadata = await getIssuerMetadata();\n const sdk = new CrexSDK();\n const config = sdk.getServerConfig();\n sdk.updateConfigProp('OIDC', {\n ...config.OIDC,\n issuerMetadata: metadata\n });\n\n const response = NextResponse.json({ issuerMetadata: metadata });\n\n return response;\n\n } catch (error) {\n return NextResponse.json({ error: String(error) }, { status: 500 });\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 { 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","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 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 { WarningVars } from \"@c-rex/types\";\nimport { logInfo, OIDCInterface } from \"@c-rex/interfaces\";\nimport { LogLevelType } from \"@c-rex/types\";\nimport { LogCategoriesType } from \"@c-rex/types\";\n\nconst formatIssuer = (issuer: string): string => {\n let newIssuer = issuer\n const lastChar = newIssuer.charAt(newIssuer.length - 1)\n if (lastChar !== \"/\") {\n newIssuer += \"/\"\n }\n newIssuer += \".well-known/openid-configuration\"\n\n return newIssuer;\n}\n\nexport const mergeConfigs = <T>(defaultConfig: Partial<T>, envVars: Partial<T>): T => {\n const definedEnvVars: T = {} as T;\n\n for (const key in envVars) {\n if (envVars[key] !== undefined) {\n definedEnvVars[key] = envVars[key];\n }\n }\n\n return {\n ...defaultConfig,\n ...definedEnvVars,\n };\n}\n\nexport const generateWarnings = (vars: WarningVars[]): string[] => {\n\n const warnings: string[] = []\n\n vars.forEach((variable) => {\n const value = process.env[variable.key];\n if (value === undefined) {\n warnings.push(`Missing environment variable ${variable.key}, using default value: ${variable.default}`)\n }\n })\n\n return warnings;\n}\n\nexport const createUserOIDCConfig = (): { user: OIDCInterface, warnings: string[] } => {\n const warnings: string[] = []\n const userDefaults: Partial<OIDCInterface> = {\n secret: \"dummy\",\n scope: \"openid profile crex.ids.api crex.ids.api.public\",\n enabled: true,\n }\n const userEnvs: Partial<OIDCInterface> = {\n id: process.env.CREX_IDS_ID,\n secret: process.env.CREX_IDS_SECRET,\n scope: process.env.CREX_IDS_USER_SCOPES,\n issuer: process.env.CREX_IDS_ISSUER == undefined ? undefined : formatIssuer(process.env.CREX_IDS_ISSUER),\n enabled: process.env.CREX_IDS_USER_LOGIN_ENABLE == undefined ? undefined : process.env.CREX_IDS_USER_LOGIN_ENABLE == \"true\",\n }\n const user: OIDCInterface = mergeConfigs<OIDCInterface>(userDefaults, userEnvs);\n\n if (user.enabled) {\n const disableOIDCVars = [\n { key: \"CREX_IDS_ID\", value: process.env.CREX_IDS_ID },\n { key: \"CREX_IDS_ISSUER\", value: process.env.CREX_IDS_ISSUER },\n ]\n disableOIDCVars.forEach((variable) => {\n if (variable.value === undefined) {\n user.enabled = false\n\n warnings.push(`Missing environment variable ${variable.key}, disabling client and login`)\n }\n })\n\n }\n\n if (user.enabled) {\n const userWarningVars = [\n { key: \"CREX_IDS_USER_SCOPES\", default: user.scope },\n { key: \"CREX_IDS_SECRET\", default: user.secret },\n { key: \"CREX_IDS_USER_LOGIN_ENABLE\", default: user.enabled }\n ]\n const aux = generateWarnings(userWarningVars)\n warnings.push(...aux);\n }\n\n return { user, warnings }\n}\n\nexport const createClientOIDCConfig = (): { client: OIDCInterface, warnings: string[] } => {\n const warnings: string[] = []\n const clientDefault: Partial<OIDCInterface> = {\n secret: \"dummy\",\n enabled: true,\n }\n const clientEnvs: Partial<OIDCInterface> = {\n id: process.env.CREX_IDS_ID,\n issuer: process.env.CREX_IDS_ISSUER == undefined ? undefined : formatIssuer(process.env.CREX_IDS_ISSUER),\n secret: process.env.CREX_IDS_SECRET,\n enabled: process.env.CREX_IDS_CLIENT_LOGIN_ENABLE == undefined ? undefined : process.env.CREX_IDS_CLIENT_LOGIN_ENABLE == \"true\",\n }\n const client: OIDCInterface = mergeConfigs<OIDCInterface>(clientDefault, clientEnvs);\n\n if (client.enabled) {\n const disableOIDCVars = [\n { key: \"CREX_IDS_ID\", value: process.env.CREX_IDS_ID },\n { key: \"CREX_IDS_ISSUER\", value: process.env.CREX_IDS_ISSUER },\n ]\n disableOIDCVars.forEach((variable) => {\n if (variable.value === undefined) {\n client.enabled = false\n warnings.push(`Missing environment variable ${variable.key}, disabling client and login`)\n }\n })\n }\n\n if (client.enabled) {\n const clientWarningVars = [\n { key: \"CREX_IDS_SECRET\", default: client.secret },\n { key: \"CREX_IDS_CLIENT_LOGIN_ENABLE\", default: client.enabled }\n ]\n\n const aux = generateWarnings(clientWarningVars)\n warnings.push(...aux);\n }\n\n return { client, warnings }\n}\n\nexport const createConsoleLoggerConfig = (): { consoleLogger: Omit<logInfo, \"hostname\" | \"app\" | \"categoriesLevel\">, warnings: string[]; } => {\n const warnings: string[] = []\n\n const consoleLoggerDefaults: Partial<logInfo> = {\n minimumLevel: \"info\" as LogLevelType,\n silent: false,\n }\n const consoleLoggerEnvs: Partial<logInfo> = {\n minimumLevel: process.env.LOG_CONSOLE_LEVEL as LogLevelType,\n silent: process.env.LOG_CONSOLE_SILENT == undefined ? undefined : process.env.LOG_CONSOLE_SILENT == \"true\",\n }\n const consoleLogger: logInfo = mergeConfigs<logInfo>(consoleLoggerDefaults, consoleLoggerEnvs);\n\n if (consoleLogger.silent == false) {\n const consoleWarningsVars = [\n { key: \"LOG_CONSOLE_SILENT\", default: consoleLogger.silent },\n { key: \"LOG_CONSOLE_LEVEL\", default: consoleLogger.minimumLevel }\n ]\n const aux = generateWarnings(consoleWarningsVars)\n warnings.push(...aux);\n }\n\n return {\n consoleLogger,\n warnings\n }\n}\n\nexport const createGraylogLoggerConfig = (): { graylog: logInfo, warnings: string[] } => {\n const warnings: string[] = []\n\n const graylogDefaults: Partial<logInfo> = {\n app: \"app name not set\",\n minimumLevel: \"info\" as LogLevelType,\n silent: false,\n hostname: \"https://log.c-rex.net\",\n port: 12202,\n categoriesLevel: [\"NoLicense\", \"Scenario\", \"Document\", \"Search\", \"Notification\", \"History\", \"UserProfile\"],\n }\n const graylogEnvs: Partial<logInfo> = {\n app: process.env.LOG_GRAYLOG_APP_NAME,\n silent: process.env.LOG_GRAYLOG_SILENT == undefined ? undefined : process.env.LOG_GRAYLOG_SILENT == \"true\",\n hostname: process.env.LOG_GRAYLOG_HOSTNAME,\n port: process.env.LOG_GRAYLOG_PORT == undefined ? undefined : Number(process.env.LOG_GRAYLOG_PORT),\n minimumLevel: process.env.LOG_GRAYLOG_LEVEL as any,\n categoriesLevel: process.env.LOG_GRAYLOG_CATEGORIES == undefined ? undefined : process.env.LOG_GRAYLOG_CATEGORIES.split(\",\") as LogCategoriesType[],\n }\n const graylog: logInfo = mergeConfigs<logInfo>(graylogDefaults, graylogEnvs);\n\n if (graylog.silent == false) {\n const graylogWarningVars = [\n { key: \"LOG_GRAYLOG_APP_NAME\", default: graylog.app },\n { key: \"LOG_GRAYLOG_HOSTNAME\", default: graylog.hostname },\n { key: \"LOG_GRAYLOG_LEVEL\", default: graylog.minimumLevel },\n { key: \"LOG_GRAYLOG_SILENT\", default: graylog.silent },\n { key: \"LOG_GRAYLOG_CATEGORIES\", default: graylog.categoriesLevel },\n { key: \"LOG_GRAYLOG_PORT\", default: graylog.port }\n ]\n const aux = generateWarnings(graylogWarningVars)\n warnings.push(...aux);\n }\n\n return {\n graylog,\n warnings\n }\n}\n\nexport const createMatomoLoggerConfig = (): { matomo: logInfo, warnings: string[] } => {\n const warnings: string[] = []\n\n const matomoDefaults: Partial<logInfo> = {\n app: \"NextJsProjectName\",\n minimumLevel: \"info\" as LogLevelType,\n silent: true,\n hostname: \"\",\n port: 0,\n categoriesLevel: [\"NoLicense\", \"Scenario\", \"Document\", \"Search\", \"Notification\", \"History\", \"UserProfile\"],\n }\n const matomoEnvs: Partial<logInfo> = {\n app: process.env.LOG_MATOMO_APP_NAME,\n silent: process.env.LOG_MATOMO_SILENT == undefined ? undefined : process.env.LOG_MATOMO_SILENT == \"true\",\n hostname: process.env.LOG_MATOMO_HOSTNAME,\n port: process.env.LOG_MATOMO_PORT == undefined ? undefined : Number(process.env.LOG_MATOMO_PORT),\n minimumLevel: process.env.LOG_MATOMO_LEVEL as any,\n categoriesLevel: process.env.LOG_MATOMO_CATEGORIES == undefined ? undefined : process.env.LOG_MATOMO_CATEGORIES.split(\",\") as LogCategoriesType[],\n }\n const matomo: logInfo = mergeConfigs<logInfo>(matomoDefaults, matomoEnvs);\n\n\n const matomoSilentVars = [\n { key: \"LOG_MATOMO_SILENT\", value: process.env.LOG_MATOMO_SILENT },\n { key: \"LOG_MATOMO_HOSTNAME\", value: process.env.LOG_MATOMO_HOSTNAME },\n { key: \"LOG_MATOMO_PORT\", value: process.env.LOG_MATOMO_PORT }\n ]\n matomoSilentVars.forEach((variable) => {\n if (variable.value === undefined) {\n matomo.silent = true\n warnings.push(`Missing environment variable ${variable.key}, setting matomo logger to silent`)\n }\n })\n\n if (matomo.silent == false) {\n const matomoWarningVars = [\n { key: \"LOG_MATOMO_APP_NAME\", default: matomo.app },\n { key: \"LOG_MATOMO_LEVEL\", default: matomo.minimumLevel },\n { key: \"LOG_MATOMO_CATEGORIES\", default: matomo.categoriesLevel }\n ]\n const aux = generateWarnings(matomoWarningVars)\n warnings.push(...aux);\n }\n\n return {\n matomo,\n warnings\n }\n}\n\n","import { ConfigInterface, CookiesConfigs, CustomerConfig } from \"@c-rex/interfaces\";\nimport {\n createClientOIDCConfig,\n createConsoleLoggerConfig,\n createGraylogLoggerConfig,\n createMatomoLoggerConfig,\n createUserOIDCConfig\n} from \"./utils\";\nimport { cookies } from \"next/headers\";\nimport { SDK_CONFIG_KEY } from \"@c-rex/constants\";\n\ndeclare global {\n // eslint-disable-next-line no-var\n var __GLOBAL_CONFIG__: ConfigInterface | null;\n}\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 public cookiesConfig!: CookiesConfigs;\n\n public async getUserAuthConfig() {\n if (this.userAuthConfig) {\n return this.userAuthConfig;\n }\n\n if (!this.customerConfig) {\n this.customerConfig = this.getServerConfig()\n }\n\n const user = this.customerConfig.OIDC.user;\n const userInfoEndPoint = this.customerConfig.OIDC.issuerMetadata?.userinfo_endpoint;\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: {\n scope: user.scope,\n prompt: \"login\"\n }\n },\n idToken: true,\n checks: [\"pkce\", \"state\"],\n async profile(_: any, tokens: any) {\n const res = await fetch(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 callbacks: {\n async jwt({ token, account }: any) {\n if (account) {\n token.id_token = account.id_token;\n }\n return token;\n },\n async session({ session, token }: any) {\n session.id_token = token.id_token;\n return session;\n },\n },\n },\n ]\n }\n };\n\n return this.userAuthConfig;\n }\n\n public createCustomerConfig(CUSTOMER_CONFIG: CustomerConfig, shouldLog: boolean): { cookiesConfig: CookiesConfigs, config: ConfigInterface } {\n\n const requiredEnvVars = [\"CREX_API_URL\", \"NEXT_PUBLIC_API_URL\"]\n\n const errors = requiredEnvVars.map(key => {\n const value = process.env[key];\n if (value === undefined) {\n return `Missing required environment variable: ${key}`;\n }\n\n return \"\"\n }).filter(item => item.length > 0)\n\n const { user, warnings: userWarnings } = createUserOIDCConfig()\n const { client, warnings: clientWarnings } = createClientOIDCConfig()\n const { matomo, warnings: matomoWarnings } = createMatomoLoggerConfig()\n const { graylog, warnings: graylogWarnings } = createGraylogLoggerConfig()\n const { consoleLogger, warnings: consoleWarnings } = createConsoleLoggerConfig()\n\n const warnings = [\n ...clientWarnings,\n ...consoleWarnings,\n ...userWarnings,\n ...graylogWarnings,\n ...matomoWarnings\n ]\n\n if (shouldLog) {\n if (errors.length > 0) throw new Error(errors.join('\\n'));\n if (warnings.length > 0) console.warn(warnings.join('\\n'));\n }\n\n const cookiesConfig: CookiesConfigs = {\n publicNextApiUrl: process.env.NEXT_PUBLIC_API_URL!,\n ...CUSTOMER_CONFIG,\n OIDC: {\n clientEnabled: client.enabled,\n userEnabled: user.enabled,\n },\n }\n\n let baseUrl = process.env.CREX_API_URL!\n const lastChar = baseUrl.charAt(baseUrl.length - 1)\n if (lastChar !== \"/\") {\n baseUrl += \"/\"\n }\n baseUrl += \"iirds/v1/\"\n\n const config: ConfigInterface = {\n baseUrl,\n OIDC: { client, user },\n logs: { console: consoleLogger, graylog, matomo, },\n ...CUSTOMER_CONFIG,\n }\n\n return { cookiesConfig, config };\n }\n\n public 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\n public getServerConfig() {\n if (!global.__GLOBAL_CONFIG__) {\n throw new Error('Server config not initialized');\n }\n return global.__GLOBAL_CONFIG__;\n }\n\n public initializeConfig(config: ConfigInterface) {\n if (global.__GLOBAL_CONFIG__) return global.__GLOBAL_CONFIG__;\n global.__GLOBAL_CONFIG__ = config;\n return global.__GLOBAL_CONFIG__;\n }\n\n public 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 }\n}"],"mappings":";AAAA,SAAS,oBAAoB;;;ACAtB,IAAM,MAAM;AAeZ,IAAM,aAAa;AAAA,EACtB,UAAU;AAAA,EACV,OAAO;AAAA,EACP,SAAS;AAAA,EACT,MAAM;AAAA,EACN,OAAO;AACX;A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MAAI;AACA,UAAM,WAAW,MAAM,kBAAkB;AACzC,UAAM,MAAM,IAAI,QAAQ;AACxB,UAAM,SAAS,IAAI,gBAAgB;AACnC,QAAI,iBAAiB,QAAQ;AAAA,MACzB,GAAG,OAAO;AAAA,MACV,gBAAgB;AAAA,IACpB,CAAC;AAED,UAAM,WAAW,aAAa,KAAK,EAAE,gBAAgB,SAAS,CAAC;AAE/D,WAAO;AAAA,EAEX,SAAS,OAAO;AACZ,WAAO,aAAa,KAAK,EAAE,OAAO,OAAO,KAAK,EAAE,GAAG,EAAE,QAAQ,IAAI,CAAC;AAAA,EACtE;AACJ;","names":["Transport","Transport","cookies","cookies"]}
|
package/dist/api/cookies.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/api/cookies.ts","../../../constants/src/index.ts"],"sourcesContent":["import { NextRequest, NextResponse } from 'next/server';\nimport { cookies } from 'next/headers';\nimport { DEFAULT_COOKIE_LIMIT } from '@c-rex/constants';\n\n/**\n * Retrieves a cookie value by key from the request\n * @param {NextRequest} req - The Next.js request object\n * @returns {Promise<NextResponse>} JSON response containing the cookie key-value pair or error\n */\nexport const getMethod = async (req: NextRequest): Promise<NextResponse> => {\n const key = req.nextUrl.searchParams.get('key');\n if (!key) return NextResponse.json({ error: 'Missing key' }, { status: 400 });\n\n const value = cookies().get(key);\n const response = NextResponse.json({ key, value: value?.value || null });\n\n return response;\n}\n\n/**\n * Sets a cookie with the specified key, value and options\n * @param {NextRequest} req - The Next.js request object\n * @returns {Promise<NextResponse>} JSON response indicating success or error\n * @throws {Error} If key or value are missing in the request body\n */\nexport const postMethod = async (req: NextRequest): Promise<NextResponse> => {\n const { key, value, maxAge: maxAgeAux } = await req.json();\n let maxAge = maxAgeAux;\n\n if (!key || value === undefined) {\n return NextResponse.json({ error: 'Missing key or value' }, { status: 400 });\n }\n\n if (maxAge === undefined) {\n maxAge = DEFAULT_COOKIE_LIMIT\n }\n\n const response = NextResponse.json({ success: true });\n\n response.cookies.set({\n name: key,\n value: value,\n secure: process.env.NODE_ENV === 'production',\n sameSite: 'lax',\n path: '/',\n maxAge: maxAge,\n });\n\n return response\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 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};"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA0C;AAC1C,qBAAwB;;;
|
|
1
|
+
{"version":3,"sources":["../../src/api/cookies.ts","../../../constants/src/index.ts"],"sourcesContent":["import { NextRequest, NextResponse } from 'next/server';\nimport { cookies } from 'next/headers';\nimport { DEFAULT_COOKIE_LIMIT } from '@c-rex/constants';\n\n/**\n * Retrieves a cookie value by key from the request\n * @param {NextRequest} req - The Next.js request object\n * @returns {Promise<NextResponse>} JSON response containing the cookie key-value pair or error\n */\nexport const getMethod = async (req: NextRequest): Promise<NextResponse> => {\n const key = req.nextUrl.searchParams.get('key');\n if (!key) return NextResponse.json({ error: 'Missing key' }, { status: 400 });\n\n const value = cookies().get(key);\n const response = NextResponse.json({ key, value: value?.value || null });\n\n return response;\n}\n\n/**\n * Sets a cookie with the specified key, value and options\n * @param {NextRequest} req - The Next.js request object\n * @returns {Promise<NextResponse>} JSON response indicating success or error\n * @throws {Error} If key or value are missing in the request body\n */\nexport const postMethod = async (req: NextRequest): Promise<NextResponse> => {\n const { key, value, maxAge: maxAgeAux } = await req.json();\n let maxAge = maxAgeAux;\n\n if (!key || value === undefined) {\n return NextResponse.json({ error: 'Missing key or value' }, { status: 400 });\n }\n\n if (maxAge === undefined) {\n maxAge = DEFAULT_COOKIE_LIMIT\n }\n\n const response = NextResponse.json({ success: true });\n\n response.cookies.set({\n name: key,\n value: value,\n secure: process.env.NODE_ENV === 'production',\n sameSite: 'lax',\n path: '/',\n maxAge: maxAge,\n });\n\n return response\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];"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA0C;AAC1C,qBAAwB;;;AC6EjB,IAAM,uBAAuB,KAAK,KAAK,KAAK,KAAK;;;ADrEjD,IAAM,YAAY,OAAO,QAA4C;AACxE,QAAM,MAAM,IAAI,QAAQ,aAAa,IAAI,KAAK;AAC9C,MAAI,CAAC,IAAK,QAAO,2BAAa,KAAK,EAAE,OAAO,cAAc,GAAG,EAAE,QAAQ,IAAI,CAAC;AAE5E,QAAM,YAAQ,wBAAQ,EAAE,IAAI,GAAG;AAC/B,QAAM,WAAW,2BAAa,KAAK,EAAE,KAAK,OAAO,OAAO,SAAS,KAAK,CAAC;AAEvE,SAAO;AACX;AAQO,IAAM,aAAa,OAAO,QAA4C;AACzE,QAAM,EAAE,KAAK,OAAO,QAAQ,UAAU,IAAI,MAAM,IAAI,KAAK;AACzD,MAAI,SAAS;AAEb,MAAI,CAAC,OAAO,UAAU,QAAW;AAC7B,WAAO,2BAAa,KAAK,EAAE,OAAO,uBAAuB,GAAG,EAAE,QAAQ,IAAI,CAAC;AAAA,EAC/E;AAEA,MAAI,WAAW,QAAW;AACtB,aAAS;AAAA,EACb;AAEA,QAAM,WAAW,2BAAa,KAAK,EAAE,SAAS,KAAK,CAAC;AAEpD,WAAS,QAAQ,IAAI;AAAA,IACjB,MAAM;AAAA,IACN;AAAA,IACA,QAAQ,QAAQ,IAAI,aAAa;AAAA,IACjC,UAAU;AAAA,IACV,MAAM;AAAA,IACN;AAAA,EACJ,CAAC;AAED,SAAO;AACX;","names":[]}
|
package/dist/api/cookies.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/api/cookies.ts","../../../constants/src/index.ts"],"sourcesContent":["import { NextRequest, NextResponse } from 'next/server';\nimport { cookies } from 'next/headers';\nimport { DEFAULT_COOKIE_LIMIT } from '@c-rex/constants';\n\n/**\n * Retrieves a cookie value by key from the request\n * @param {NextRequest} req - The Next.js request object\n * @returns {Promise<NextResponse>} JSON response containing the cookie key-value pair or error\n */\nexport const getMethod = async (req: NextRequest): Promise<NextResponse> => {\n const key = req.nextUrl.searchParams.get('key');\n if (!key) return NextResponse.json({ error: 'Missing key' }, { status: 400 });\n\n const value = cookies().get(key);\n const response = NextResponse.json({ key, value: value?.value || null });\n\n return response;\n}\n\n/**\n * Sets a cookie with the specified key, value and options\n * @param {NextRequest} req - The Next.js request object\n * @returns {Promise<NextResponse>} JSON response indicating success or error\n * @throws {Error} If key or value are missing in the request body\n */\nexport const postMethod = async (req: NextRequest): Promise<NextResponse> => {\n const { key, value, maxAge: maxAgeAux } = await req.json();\n let maxAge = maxAgeAux;\n\n if (!key || value === undefined) {\n return NextResponse.json({ error: 'Missing key or value' }, { status: 400 });\n }\n\n if (maxAge === undefined) {\n maxAge = DEFAULT_COOKIE_LIMIT\n }\n\n const response = NextResponse.json({ success: true });\n\n response.cookies.set({\n name: key,\n value: value,\n secure: process.env.NODE_ENV === 'production',\n sameSite: 'lax',\n path: '/',\n maxAge: maxAge,\n });\n\n return response\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 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};"],"mappings":";AAAA,SAAsB,oBAAoB;AAC1C,SAAS,eAAe;;;
|
|
1
|
+
{"version":3,"sources":["../../src/api/cookies.ts","../../../constants/src/index.ts"],"sourcesContent":["import { NextRequest, NextResponse } from 'next/server';\nimport { cookies } from 'next/headers';\nimport { DEFAULT_COOKIE_LIMIT } from '@c-rex/constants';\n\n/**\n * Retrieves a cookie value by key from the request\n * @param {NextRequest} req - The Next.js request object\n * @returns {Promise<NextResponse>} JSON response containing the cookie key-value pair or error\n */\nexport const getMethod = async (req: NextRequest): Promise<NextResponse> => {\n const key = req.nextUrl.searchParams.get('key');\n if (!key) return NextResponse.json({ error: 'Missing key' }, { status: 400 });\n\n const value = cookies().get(key);\n const response = NextResponse.json({ key, value: value?.value || null });\n\n return response;\n}\n\n/**\n * Sets a cookie with the specified key, value and options\n * @param {NextRequest} req - The Next.js request object\n * @returns {Promise<NextResponse>} JSON response indicating success or error\n * @throws {Error} If key or value are missing in the request body\n */\nexport const postMethod = async (req: NextRequest): Promise<NextResponse> => {\n const { key, value, maxAge: maxAgeAux } = await req.json();\n let maxAge = maxAgeAux;\n\n if (!key || value === undefined) {\n return NextResponse.json({ error: 'Missing key or value' }, { status: 400 });\n }\n\n if (maxAge === undefined) {\n maxAge = DEFAULT_COOKIE_LIMIT\n }\n\n const response = NextResponse.json({ success: true });\n\n response.cookies.set({\n name: key,\n value: value,\n secure: process.env.NODE_ENV === 'production',\n sameSite: 'lax',\n path: '/',\n maxAge: maxAge,\n });\n\n return response\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];"],"mappings":";AAAA,SAAsB,oBAAoB;AAC1C,SAAS,eAAe;;;AC6EjB,IAAM,uBAAuB,KAAK,KAAK,KAAK,KAAK;;;ADrEjD,IAAM,YAAY,OAAO,QAA4C;AACxE,QAAM,MAAM,IAAI,QAAQ,aAAa,IAAI,KAAK;AAC9C,MAAI,CAAC,IAAK,QAAO,aAAa,KAAK,EAAE,OAAO,cAAc,GAAG,EAAE,QAAQ,IAAI,CAAC;AAE5E,QAAM,QAAQ,QAAQ,EAAE,IAAI,GAAG;AAC/B,QAAM,WAAW,aAAa,KAAK,EAAE,KAAK,OAAO,OAAO,SAAS,KAAK,CAAC;AAEvE,SAAO;AACX;AAQO,IAAM,aAAa,OAAO,QAA4C;AACzE,QAAM,EAAE,KAAK,OAAO,QAAQ,UAAU,IAAI,MAAM,IAAI,KAAK;AACzD,MAAI,SAAS;AAEb,MAAI,CAAC,OAAO,UAAU,QAAW;AAC7B,WAAO,aAAa,KAAK,EAAE,OAAO,uBAAuB,GAAG,EAAE,QAAQ,IAAI,CAAC;AAAA,EAC/E;AAEA,MAAI,WAAW,QAAW;AACtB,aAAS;AAAA,EACb;AAEA,QAAM,WAAW,aAAa,KAAK,EAAE,SAAS,KAAK,CAAC;AAEpD,WAAS,QAAQ,IAAI;AAAA,IACjB,MAAM;AAAA,IACN;AAAA,IACA,QAAQ,QAAQ,IAAI,aAAa;AAAA,IACjC,UAAU;AAAA,IACV,MAAM;AAAA,IACN;AAAA,EACJ,CAAC;AAED,SAAO;AACX;","names":[]}
|
package/dist/api/rpc.js
CHANGED
|
@@ -108,7 +108,6 @@ var GraylogTransport = class extends import_winston_transport2.default {
|
|
|
108
108
|
handleExceptions: false,
|
|
109
109
|
graylog: {
|
|
110
110
|
servers: [
|
|
111
|
-
{ host: "localhost", port: 12201 },
|
|
112
111
|
{ host: configs.logs.graylog.hostname, port: configs.logs.graylog.port }
|
|
113
112
|
]
|
|
114
113
|
}
|
|
@@ -128,8 +127,16 @@ var GraylogTransport = class extends import_winston_transport2.default {
|
|
|
128
127
|
}
|
|
129
128
|
};
|
|
130
129
|
|
|
130
|
+
// src/config.ts
|
|
131
|
+
var import_headers = require("next/headers");
|
|
132
|
+
function getServerConfig() {
|
|
133
|
+
if (!global.__GLOBAL_CONFIG__) {
|
|
134
|
+
throw new Error("Server config not initialized");
|
|
135
|
+
}
|
|
136
|
+
return global.__GLOBAL_CONFIG__;
|
|
137
|
+
}
|
|
138
|
+
|
|
131
139
|
// src/logger.ts
|
|
132
|
-
var import_next_cookies = require("@c-rex/utils/next-cookies");
|
|
133
140
|
var CrexLogger = class {
|
|
134
141
|
customerConfig;
|
|
135
142
|
logger;
|
|
@@ -142,13 +149,13 @@ var CrexLogger = class {
|
|
|
142
149
|
async initLogger() {
|
|
143
150
|
try {
|
|
144
151
|
if (!this.customerConfig) {
|
|
145
|
-
this.customerConfig =
|
|
152
|
+
this.customerConfig = getServerConfig();
|
|
146
153
|
}
|
|
147
154
|
if (!this.logger) {
|
|
148
155
|
this.logger = this.createLogger();
|
|
149
156
|
}
|
|
150
157
|
} catch (error) {
|
|
151
|
-
console.
|
|
158
|
+
console.log("Error initializing logger:", error);
|
|
152
159
|
}
|
|
153
160
|
}
|
|
154
161
|
/**
|
|
@@ -161,7 +168,9 @@ var CrexLogger = class {
|
|
|
161
168
|
*/
|
|
162
169
|
async log({ level, message, category }) {
|
|
163
170
|
await this.initLogger();
|
|
164
|
-
|
|
171
|
+
const timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
172
|
+
const newMessage = `[${timestamp}] ${message}`;
|
|
173
|
+
this.logger.log(level, newMessage, category);
|
|
165
174
|
}
|
|
166
175
|
/**
|
|
167
176
|
* Creates a new Winston logger instance with configured transports.
|
package/dist/api/rpc.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/api/rpc.ts","../../src/logger.ts","../../src/transports/matomo.ts","../../../constants/src/index.ts","../../src/transports/graylog.ts"],"sourcesContent":["import { CrexLogger } from '../logger';\nimport { InformationUnitsService, LanguageService } from '@c-rex/services';\nimport { NextRequest, NextResponse } from 'next/server';\n\n/**\n * Registry of available services that can be called via RPC.\n */\nconst serviceRegistry = {\n InformationUnitsService,\n CrexLogger,\n LanguageService\n};\n\n/**\n * Interface for RPC payload.\n */\ntype RpcPayload = {\n method: string;\n params: any;\n};\n\n/**\n * Handles POST requests for RPC (Remote Procedure Call) functionality.\n * Allows calling methods on registered services with parameters.\n * \n * @param req - The Next.js request object containing the RPC payload\n * @returns A JSON response with the result of the method call, or an error if the service or method is not found\n */\nexport const POST = async (req: NextRequest) => {\n try {\n const { method, params }: RpcPayload = await req.json();\n const [serviceName, methodName] = method.split('.');\n const ServiceClass = serviceRegistry[serviceName as keyof typeof serviceRegistry];\n\n if (!ServiceClass) {\n return NextResponse.json({ error: `Service '${serviceName}' not found` }, { status: 404 });\n }\n\n const serviceInstance = new ServiceClass();\n const handler = (serviceInstance as any)[methodName as any];\n\n if (typeof handler !== 'function') {\n return NextResponse.json({ error: `Method '${methodName}' not found on '${serviceName}'` }, { status: 404 });\n }\n\n const result = await handler.call(serviceInstance, params);\n return NextResponse.json({ data: result });\n } catch (error) {\n const logger = new CrexLogger()\n logger.log({\n level: \"error\",\n message: `RPC.POST error: ${error}`\n })\n return NextResponse.json({ error: String(error) }, { status: 500 });\n }\n}\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 { getServerConfigs } 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 getServerConfigs();\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","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 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};","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: \"localhost\", port: 12201 },\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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,qBAAoB;;;ACApB,+BAAsB;;;ACAf,IAAM,MAAM;AAeZ,IAAM,aAAa;AAAA,EACtB,UAAU;AAAA,EACV,OAAO;AAAA,EACP,SAAS;AAAA,EACT,MAAM;AAAA,EACN,OAAO;AACX;AAwDO,IAAM,uBAAuB,KAAK,KAAK,KAAK,KAAK;;;ADpEjD,IAAM,kBAAN,cAA8B,yBAAAA,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,QAAU;AACrC,SAAK,UAAU;AAAA,EACnB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,IACI,MACA,UACI;AACJ,UAAM,iBAAiB,KAAK,QAAQ,KAAK,OAAO;AAEhD,QAAI,eAAe,SAAS,KAAK,QAAQ,KAAK,eAAe,SAAS,GAAG,GAAG;AACxE,WAAK,gBAAgB,IAAI,MAAM,QA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,gBAAwB,UAAiB;AAE1D,QAAI,OAAO,YAAY,YAAY;AAC/B,aAAO,2BAAa,KAAK,EAAE,OAAO,WAAW,UAAU,mBAAmB,WAAW,IAAI,GAAG,EAAE,QAAQ,IAAI,CAAC;AAAA,IAC/G;AAEA,UAAM,SAAS,MAAM,QAAQ,KAAK,iBAAiB,MAAM;AACzD,WAAO,2BAAa,KAAK,EAAE,MAAM,OAAO,CAAC;AAAA,EAC7C,SAAS,OAAO;AACZ,UAAM,SAAS,IAAI,WAAW;AAC9B,WAAO,IAAI;AAAA,MACP,OAAO;AAAA,MACP,SAAS,mBAAmB,KAAK;AAAA,IACrC,CAAC;AACD,WAAO,2BAAa,KAAK,EAAE,OAAO,OAAO,KAAK,EAAE,GAAG,EAAE,QAAQ,IAAI,CAAC;AAAA,EACtE;AACJ;","names":["Transport","import_winston_transport","Transport","Graylog2Transport","winston"]}
|
|
1
|
+
{"version":3,"sources":["../../src/api/rpc.ts","../../src/logger.ts","../../src/transports/matomo.ts","../../../constants/src/index.ts","../../src/transports/graylog.ts","../../src/config.ts"],"sourcesContent":["import { CrexLogger } from '../logger';\nimport { InformationUnitsService, LanguageService } from '@c-rex/services';\nimport { NextRequest, NextResponse } from 'next/server';\n\n/**\n * Registry of available services that can be called via RPC.\n */\nconst serviceRegistry = {\n InformationUnitsService,\n CrexLogger,\n LanguageService\n};\n\n/**\n * Interface for RPC payload.\n */\ntype RpcPayload = {\n method: string;\n params: any;\n};\n\n/**\n * Handles POST requests for RPC (Remote Procedure Call) functionality.\n * Allows calling methods on registered services with parameters.\n * \n * @param req - The Next.js request object containing the RPC payload\n * @returns A JSON response with the result of the method call, or an error if the service or method is not found\n */\nexport const POST = async (req: NextRequest) => {\n try {\n const { method, params }: RpcPayload = await req.json();\n const [serviceName, methodName] = method.split('.');\n const ServiceClass = serviceRegistry[serviceName as keyof typeof serviceRegistry];\n\n if (!ServiceClass) {\n return NextResponse.json({ error: `Service '${serviceName}' not found` }, { status: 404 });\n }\n\n const serviceInstance = new ServiceClass();\n const handler = (serviceInstance as any)[methodName as any];\n\n if (typeof handler !== 'function') {\n return NextResponse.json({ error: `Method '${methodName}' not found on '${serviceName}'` }, { status: 404 });\n }\n\n const result = await handler.call(serviceInstance, params);\n return NextResponse.json({ data: result });\n } catch (error) {\n const logger = new CrexLogger()\n logger.log({\n level: \"error\",\n message: `RPC.POST error: ${error}`\n })\n return NextResponse.json({ error: String(error) }, { status: 500 });\n }\n}\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","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 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}"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,qBAAoB;;;ACApB,+BAAsB;;;ACAf,IAAM,MAAM;AAeZ,IAAM,aAAa;AAAA,EACtB,UAAU;AAAA,EACV,OAAO;AAAA,EACP,SAAS;AAAA,EACT,MAAM;AAAA,EACN,OAAO;AACX;AAyDO,IAAM,uBAAuB,KAAK,KAAK,KAAK,KAAK;;;ADrEjD,IAAM,kBAAN,cAA8B,yBAAAA,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;AA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sBAAyD;AACzD,oBAA0C;AAK1C,IAAM,kBAAkB;AAAA,EACpB;AAAA,EACA;AAAA,EACA;AACJ;AAiBO,IAAM,OAAO,OAAO,QAAqB;AAC5C,MAAI;AACA,UAAM,EAAE,QAAQ,OAAO,IAAgB,MAAM,IAAI,KAAK;AACtD,UAAM,CAAC,aAAa,UAAU,IAAI,OAAO,MAAM,GAAG;AAClD,UAAM,eAAe,gBAAgB,WAA2C;AAEhF,QAAI,CAAC,cAAc;AACf,aAAO,2BAAa,KAAK,EAAE,OAAO,YAAY,WAAW,cAAc,GAAG,EAAE,QAAQ,IAAI,CAAC;AAAA,IAC7F;AAEA,UAAM,kBAAkB,IAAI,aAAa;AACzC,UAAM,UAAW,gBAAwB,UAAiB;AAE1D,QAAI,OAAO,YAAY,YAAY;AAC/B,aAAO,2BAAa,KAAK,EAAE,OAAO,WAAW,UAAU,mBAAmB,WAAW,IAAI,GAAG,EAAE,QAAQ,IAAI,CAAC;AAAA,IAC/G;AAEA,UAAM,SAAS,MAAM,QAAQ,KAAK,iBAAiB,MAAM;AACzD,WAAO,2BAAa,KAAK,EAAE,MAAM,OAAO,CAAC;AAAA,EAC7C,SAAS,OAAO;AACZ,UAAM,SAAS,IAAI,WAAW;AAC9B,WAAO,IAAI;AAAA,MACP,OAAO;AAAA,MACP,SAAS,mBAAmB,KAAK;AAAA,IACrC,CAAC;AACD,WAAO,2BAAa,KAAK,EAAE,OAAO,OAAO,KAAK,EAAE,GAAG,EAAE,QAAQ,IAAI,CAAC;AAAA,EACtE;AACJ;","names":["Transport","import_winston_transport","Transport","Graylog2Transport","winston"]}
|
package/dist/api/rpc.mjs
CHANGED
|
@@ -72,7 +72,6 @@ var GraylogTransport = class extends Transport2 {
|
|
|
72
72
|
handleExceptions: false,
|
|
73
73
|
graylog: {
|
|
74
74
|
servers: [
|
|
75
|
-
{ host: "localhost", port: 12201 },
|
|
76
75
|
{ host: configs.logs.graylog.hostname, port: configs.logs.graylog.port }
|
|
77
76
|
]
|
|
78
77
|
}
|
|
@@ -92,8 +91,16 @@ var GraylogTransport = class extends Transport2 {
|
|
|
92
91
|
}
|
|
93
92
|
};
|
|
94
93
|
|
|
94
|
+
// src/config.ts
|
|
95
|
+
import { cookies } from "next/headers";
|
|
96
|
+
function getServerConfig() {
|
|
97
|
+
if (!global.__GLOBAL_CONFIG__) {
|
|
98
|
+
throw new Error("Server config not initialized");
|
|
99
|
+
}
|
|
100
|
+
return global.__GLOBAL_CONFIG__;
|
|
101
|
+
}
|
|
102
|
+
|
|
95
103
|
// src/logger.ts
|
|
96
|
-
import { getServerConfigs } from "@c-rex/utils/next-cookies";
|
|
97
104
|
var CrexLogger = class {
|
|
98
105
|
customerConfig;
|
|
99
106
|
logger;
|
|
@@ -106,13 +113,13 @@ var CrexLogger = class {
|
|
|
106
113
|
async initLogger() {
|
|
107
114
|
try {
|
|
108
115
|
if (!this.customerConfig) {
|
|
109
|
-
this.customerConfig =
|
|
116
|
+
this.customerConfig = getServerConfig();
|
|
110
117
|
}
|
|
111
118
|
if (!this.logger) {
|
|
112
119
|
this.logger = this.createLogger();
|
|
113
120
|
}
|
|
114
121
|
} catch (error) {
|
|
115
|
-
console.
|
|
122
|
+
console.log("Error initializing logger:", error);
|
|
116
123
|
}
|
|
117
124
|
}
|
|
118
125
|
/**
|
|
@@ -125,7 +132,9 @@ var CrexLogger = class {
|
|
|
125
132
|
*/
|
|
126
133
|
async log({ level, message, category }) {
|
|
127
134
|
await this.initLogger();
|
|
128
|
-
|
|
135
|
+
const timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
136
|
+
const newMessage = `[${timestamp}] ${message}`;
|
|
137
|
+
this.logger.log(level, newMessage, category);
|
|
129
138
|
}
|
|
130
139
|
/**
|
|
131
140
|
* Creates a new Winston logger instance with configured transports.
|
package/dist/api/rpc.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/logger.ts","../../src/transports/matomo.ts","../../../constants/src/index.ts","../../src/transports/graylog.ts","../../src/api/rpc.ts"],"sourcesContent":["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 { getServerConfigs } 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 getServerConfigs();\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","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 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};","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: \"localhost\", port: 12201 },\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 { CrexLogger } from '../logger';\nimport { InformationUnitsService, LanguageService } from '@c-rex/services';\nimport { NextRequest, NextResponse } from 'next/server';\n\n/**\n * Registry of available services that can be called via RPC.\n */\nconst serviceRegistry = {\n InformationUnitsService,\n CrexLogger,\n LanguageService\n};\n\n/**\n * Interface for RPC payload.\n */\ntype RpcPayload = {\n method: string;\n params: any;\n};\n\n/**\n * Handles POST requests for RPC (Remote Procedure Call) functionality.\n * Allows calling methods on registered services with parameters.\n * \n * @param req - The Next.js request object containing the RPC payload\n * @returns A JSON response with the result of the method call, or an error if the service or method is not found\n */\nexport const POST = async (req: NextRequest) => {\n try {\n const { method, params }: RpcPayload = await req.json();\n const [serviceName, methodName] = method.split('.');\n const ServiceClass = serviceRegistry[serviceName as keyof typeof serviceRegistry];\n\n if (!ServiceClass) {\n return NextResponse.json({ error: `Service '${serviceName}' not found` }, { status: 404 });\n }\n\n const serviceInstance = new ServiceClass();\n const handler = (serviceInstance as any)[methodName as any];\n\n if (typeof handler !== 'function') {\n return NextResponse.json({ error: `Method '${methodName}' not found on '${serviceName}'` }, { status: 404 });\n }\n\n const result = await handler.call(serviceInstance, params);\n return NextResponse.json({ data: result });\n } catch (error) {\n const logger = new CrexLogger()\n logger.log({\n level: \"error\",\n message: `RPC.POST error: ${error}`\n })\n return NextResponse.json({ error: String(error) }, { status: 500 });\n }\n}\n"],"mappings":";AAAA,OAAO,aAAa;;;ACApB,OAAO,eAAe;;;ACAf,IAAM,MAAM;AAeZ,IAAM,aAAa;AAAA,EACtB,UAAU;AAAA,EACV,OAAO;AAAA,EACP,SAAS;AAAA,EACT,MAAM;AAAA,EACN,OAAO;AACX;AAwDO,IAAM,uBAAuB,KAAK,KAAK,KAAK,KAAK;;;ADpEjD,IAAM,kBAAN,cAA8B,UAAU;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,UAAU;AACrC,SAAK,UAAU;AAAA,EACnB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,IACI,MACA,UACI;AACJ,UAAM,iBAAiB,KAAK,QAAQ,KAAK,OAAO;AAEhD,QAAI,eAAe,SAAS,KAAK,QAAQ,KAAK,eAAe,SAAS,GAAG,GAAG;AACxE,WAAK,gBAAgB,IAAI,MAAM,QAAQ;AAAA,IAC3C;AAAA,EACJ;AACJ;;;AE5CA,OAAOA,gBAAe;AACtB,OAAO,uBAAuB;AASvB,IAAM,mBAAN,cAA+BC,WAAU;AAAA,EACrC;AAAA,EACC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOR,YAAY,SAA0B;AAClC,QAAI,CAAC,QAAQ,KAAK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AAO,aAAa,KAAK,EAAE,MAAM,OAAO,CAAC;AAAA,EAC7C,SAAS,OAAO;AACZ,UAAM,SAAS,IAAI,WAAW;AAC9B,WAAO,IAAI;AAAA,MACP,OAAO;AAAA,MACP,SAAS,mBAAmB,KAAK;AAAA,IACrC,CAAC;AACD,WAAO,aAAa,KAAK,EAAE,OAAO,OAAO,KAAK,EAAE,GAAG,EAAE,QAAQ,IAAI,CAAC;AAAA,EACtE;AACJ;","names":["Transport","Transport"]}
|
|
1
|
+
{"version":3,"sources":["../../src/logger.ts","../../src/transports/matomo.ts","../../../constants/src/index.ts","../../src/transports/graylog.ts","../../src/config.ts","../../src/api/rpc.ts"],"sourcesContent":["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","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 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 { CrexLogger } from '../logger';\nimport { InformationUnitsService, LanguageService } from '@c-rex/services';\nimport { NextRequest, NextResponse } from 'next/server';\n\n/**\n * Registry of available services that can be called via RPC.\n */\nconst serviceRegistry = {\n InformationUnitsService,\n CrexLogger,\n LanguageService\n};\n\n/**\n * Interface for RPC payload.\n */\ntype RpcPayload = {\n method: string;\n params: any;\n};\n\n/**\n * Handles POST requests for RPC (Remote Procedure Call) functionality.\n * Allows calling methods on registered services with parameters.\n * \n * @param req - The Next.js request object containing the RPC payload\n * @returns A JSON response with the result of the method call, or an error if the service or method is not found\n */\nexport const POST = async (req: NextRequest) => {\n try {\n const { method, params }: RpcPayload = await req.json();\n const [serviceName, methodName] = method.split('.');\n const ServiceClass = serviceRegistry[serviceName as keyof typeof serviceRegistry];\n\n if (!ServiceClass) {\n return NextResponse.json({ error: `Service '${serviceName}' not found` }, { status: 404 });\n }\n\n const serviceInstance = new ServiceClass();\n const handler = (serviceInstance as any)[methodName as any];\n\n if (typeof handler !== 'function') {\n return NextResponse.json({ error: `Method '${methodName}' not found on '${serviceName}'` }, { status: 404 });\n }\n\n const result = await handler.call(serviceInstance, params);\n return NextResponse.json({ data: result });\n } catch (error) {\n const logger = new CrexLogger()\n logger.log({\n level: \"error\",\n message: `RPC.POST error: ${error}`\n })\n return NextResponse.json({ error: String(error) }, { status: 500 });\n }\n}\n"],"mappings":";AAAA,OAAO,aAAa;;;ACApB,OAAO,eAAe;;;ACAf,IAAM,MAAM;AAeZ,IAAM,aAAa;AAAA,EACtB,UAAU;AAAA,EACV,OAAO;AAAA,EACP,SAAS;AAAA,EACT,MAAM;AAAA,EACN,OAAO;AACX;AAyDO,IAAM,uBAAuB,KAAK,KAAK,KAAK,KAAK;;;ADrEjD,IAAM,kBAAN,cAA8B,UAAU;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,UAAU;AACrC,SAAK,UAAU;AAAA,EACnB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,IACI,MACA,UACI;AACJ,UAAM,iBAAiB,KAAK,QAAQ,KAAK,OAAO;AAEhD,QAAI,eAAe,SAAS,KAAK,QAAQ,KAAK,eAAe,SAAS,GAAG,GAAG;AACxE,WAAK,gBAAgB,IAAI,MAAM,QAAQ;AAAA,IAC3C;AAAA,EACJ;AACJ;;;AE5CA,O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E,OAAO,YAAY,WAAW,cAAc,GAAG,EAAE,QAAQ,IAAI,CAAC;AAAA,IAC7F;AAEA,UAAM,kBAAkB,IAAI,aAAa;AACzC,UAAM,UAAW,gBAAwB,UAAiB;AAE1D,QAAI,OAAO,YAAY,YAAY;AAC/B,aAAO,aAAa,KAAK,EAAE,OAAO,WAAW,UAAU,mBAAmB,WAAW,IAAI,GAAG,EAAE,QAAQ,IAAI,CAAC;AAAA,IAC/G;AAEA,UAAM,SAAS,MAAM,QAAQ,KAAK,iBAAiB,MAAM;AACzD,WAAO,aAAa,KAAK,EAAE,MAAM,OAAO,CAAC;AAAA,EAC7C,SAAS,OAAO;AACZ,UAAM,SAAS,IAAI,WAAW;AAC9B,WAAO,IAAI;AAAA,MACP,OAAO;AAAA,MACP,SAAS,mBAAmB,KAAK;AAAA,IACrC,CAAC;AACD,WAAO,aAAa,KAAK,EAAE,OAAO,OAAO,KAAK,EAAE,GAAG,EAAE,QAAQ,IAAI,CAAC;AAAA,EACtE;AACJ;","names":["Transport","Transport"]}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Method } from 'axios';
|
|
2
|
-
import { ConfigInterface } from '@c-rex/interfaces';
|
|
2
|
+
import { ConfigInterface, CookiesConfigs } from '@c-rex/interfaces';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Interface for API call parameters.
|
|
@@ -19,7 +19,6 @@ declare class CrexApi {
|
|
|
19
19
|
private customerConfig;
|
|
20
20
|
private apiClient;
|
|
21
21
|
private logger;
|
|
22
|
-
private publicNextApiUrl;
|
|
23
22
|
/**
|
|
24
23
|
* Initializes the API client if it hasn't been initialized yet.
|
|
25
24
|
* Loads customer configuration, creates the axios instance, and initializes the logger.
|
|
@@ -27,7 +26,6 @@ declare class CrexApi {
|
|
|
27
26
|
* @private
|
|
28
27
|
*/
|
|
29
28
|
private initAPI;
|
|
30
|
-
private getToken;
|
|
31
29
|
private manageToken;
|
|
32
30
|
/**
|
|
33
31
|
* Executes an API request with caching, authentication, and retry logic.
|
|
@@ -45,26 +43,16 @@ declare class CrexApi {
|
|
|
45
43
|
}
|
|
46
44
|
|
|
47
45
|
/**
|
|
48
|
-
*
|
|
49
|
-
*
|
|
46
|
+
* Retrieves and parses configuration data from a cookie.
|
|
47
|
+
* @returns The parsed configuration object
|
|
48
|
+
* @throws Error if the configuration cookie is not found or cannot be parsed
|
|
50
49
|
*/
|
|
51
|
-
declare
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Retrieves the customer configuration if it hasn't been loaded yet.
|
|
56
|
-
*
|
|
57
|
-
* @private
|
|
58
|
-
*/
|
|
59
|
-
private getConfig;
|
|
60
|
-
/**
|
|
61
|
-
* Retrieves the user authentication configuration.
|
|
62
|
-
* If not already loaded, it will load the customer configuration and
|
|
63
|
-
* create the auth config based on OIDC settings.
|
|
64
|
-
*
|
|
65
|
-
* @returns The user authentication configuration object
|
|
66
|
-
*/
|
|
67
|
-
getUserAuthConfig(): Promise<any>;
|
|
50
|
+
declare const getClientConfig: () => CookiesConfigs;
|
|
51
|
+
declare global {
|
|
52
|
+
var __GLOBAL_CONFIG__: ConfigInterface | null;
|
|
68
53
|
}
|
|
54
|
+
declare function initializeConfig(config: ConfigInterface): ConfigInterface;
|
|
55
|
+
declare function getServerConfig(): ConfigInterface;
|
|
56
|
+
declare function updateConfigProp(key: keyof ConfigInterface, value: any): ConfigInterface;
|
|
69
57
|
|
|
70
|
-
export { CrexApi,
|
|
58
|
+
export { CrexApi, getClientConfig, getServerConfig, initializeConfig, updateConfigProp };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Method } from 'axios';
|
|
2
|
-
import { ConfigInterface } from '@c-rex/interfaces';
|
|
2
|
+
import { ConfigInterface, CookiesConfigs } from '@c-rex/interfaces';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Interface for API call parameters.
|
|
@@ -19,7 +19,6 @@ declare class CrexApi {
|
|
|
19
19
|
private customerConfig;
|
|
20
20
|
private apiClient;
|
|
21
21
|
private logger;
|
|
22
|
-
private publicNextApiUrl;
|
|
23
22
|
/**
|
|
24
23
|
* Initializes the API client if it hasn't been initialized yet.
|
|
25
24
|
* Loads customer configuration, creates the axios instance, and initializes the logger.
|
|
@@ -27,7 +26,6 @@ declare class CrexApi {
|
|
|
27
26
|
* @private
|
|
28
27
|
*/
|
|
29
28
|
private initAPI;
|
|
30
|
-
private getToken;
|
|
31
29
|
private manageToken;
|
|
32
30
|
/**
|
|
33
31
|
* Executes an API request with caching, authentication, and retry logic.
|
|
@@ -45,26 +43,16 @@ declare class CrexApi {
|
|
|
45
43
|
}
|
|
46
44
|
|
|
47
45
|
/**
|
|
48
|
-
*
|
|
49
|
-
*
|
|
46
|
+
* Retrieves and parses configuration data from a cookie.
|
|
47
|
+
* @returns The parsed configuration object
|
|
48
|
+
* @throws Error if the configuration cookie is not found or cannot be parsed
|
|
50
49
|
*/
|
|
51
|
-
declare
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Retrieves the customer configuration if it hasn't been loaded yet.
|
|
56
|
-
*
|
|
57
|
-
* @private
|
|
58
|
-
*/
|
|
59
|
-
private getConfig;
|
|
60
|
-
/**
|
|
61
|
-
* Retrieves the user authentication configuration.
|
|
62
|
-
* If not already loaded, it will load the customer configuration and
|
|
63
|
-
* create the auth config based on OIDC settings.
|
|
64
|
-
*
|
|
65
|
-
* @returns The user authentication configuration object
|
|
66
|
-
*/
|
|
67
|
-
getUserAuthConfig(): Promise<any>;
|
|
50
|
+
declare const getClientConfig: () => CookiesConfigs;
|
|
51
|
+
declare global {
|
|
52
|
+
var __GLOBAL_CONFIG__: ConfigInterface | null;
|
|
68
53
|
}
|
|
54
|
+
declare function initializeConfig(config: ConfigInterface): ConfigInterface;
|
|
55
|
+
declare function getServerConfig(): ConfigInterface;
|
|
56
|
+
declare function updateConfigProp(key: keyof ConfigInterface, value: any): ConfigInterface;
|
|
69
57
|
|
|
70
|
-
export { CrexApi,
|
|
58
|
+
export { CrexApi, getClientConfig, getServerConfig, initializeConfig, updateConfigProp };
|