@c-rex/core 0.1.2 → 0.1.3
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/cookies.d.mts +14 -7
- package/dist/api/cookies.d.ts +14 -7
- package/dist/api/cookies.js +33 -6
- package/dist/api/cookies.js.map +1 -1
- package/dist/api/cookies.mjs +31 -5
- package/dist/api/cookies.mjs.map +1 -1
- package/dist/api/rpc.d.mts +7 -0
- package/dist/api/rpc.d.ts +7 -0
- package/dist/api/rpc.js +66 -61
- package/dist/api/rpc.js.map +1 -1
- package/dist/api/rpc.mjs +67 -62
- package/dist/api/rpc.mjs.map +1 -1
- package/dist/api/token.d.mts +13 -0
- package/dist/api/token.d.ts +13 -0
- package/dist/api/token.js +61 -0
- package/dist/api/token.js.map +1 -0
- package/dist/api/token.mjs +36 -0
- package/dist/api/token.mjs.map +1 -0
- package/dist/index.d.mts +42 -2
- package/dist/index.d.ts +42 -2
- package/dist/index.js +176 -67
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +176 -67
- package/dist/index.mjs.map +1 -1
- package/dist/logger.d.mts +24 -0
- package/dist/logger.d.ts +24 -0
- package/dist/logger.js +51 -5
- package/dist/logger.js.map +1 -1
- package/dist/logger.mjs +51 -5
- package/dist/logger.mjs.map +1 -1
- package/package.json +7 -1
package/dist/api/rpc.mjs
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
// src/logger.ts
|
|
2
|
+
import winston from "winston";
|
|
3
|
+
|
|
4
|
+
// src/transports/matomo.ts
|
|
5
|
+
import Transport from "winston-transport";
|
|
6
|
+
|
|
1
7
|
// ../constants/src/index.ts
|
|
2
8
|
var ALL = "*";
|
|
3
9
|
var LOG_LEVELS = {
|
|
@@ -9,58 +15,15 @@ var LOG_LEVELS = {
|
|
|
9
15
|
};
|
|
10
16
|
var DEFAULT_COOKIE_LIMIT = 7 * 24 * 60 * 60 * 1e3;
|
|
11
17
|
|
|
12
|
-
// src/sdk.ts
|
|
13
|
-
import { getConfigs } from "@c-rex/utils/next-cookies";
|
|
14
|
-
var CrexSDK = class {
|
|
15
|
-
userAuthConfig;
|
|
16
|
-
customerConfig;
|
|
17
|
-
async getConfig() {
|
|
18
|
-
if (!this.customerConfig) {
|
|
19
|
-
this.customerConfig = await getConfigs();
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
async getUserAuthConfig() {
|
|
23
|
-
if (this.userAuthConfig) {
|
|
24
|
-
return this.userAuthConfig;
|
|
25
|
-
}
|
|
26
|
-
await this.getConfig();
|
|
27
|
-
const user = this.customerConfig.OIDC.user;
|
|
28
|
-
if (user.enabled) {
|
|
29
|
-
this.userAuthConfig = {
|
|
30
|
-
providers: [
|
|
31
|
-
{
|
|
32
|
-
id: "crex",
|
|
33
|
-
name: "CREX",
|
|
34
|
-
type: "oauth",
|
|
35
|
-
clientId: user.id,
|
|
36
|
-
wellKnown: user.issuer,
|
|
37
|
-
clientSecret: user.secret,
|
|
38
|
-
authorization: { params: { scope: user.scope } },
|
|
39
|
-
profile(profile) {
|
|
40
|
-
return {
|
|
41
|
-
id: profile.id || "fake Id",
|
|
42
|
-
name: profile.name || "Fake Name",
|
|
43
|
-
email: profile.email || "fake Email",
|
|
44
|
-
image: profile.image || "fake Image"
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
]
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
;
|
|
52
|
-
return this.userAuthConfig;
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
// src/logger.ts
|
|
57
|
-
import winston from "winston";
|
|
58
|
-
|
|
59
18
|
// src/transports/matomo.ts
|
|
60
|
-
import Transport from "winston-transport";
|
|
61
19
|
var MatomoTransport = class extends Transport {
|
|
62
20
|
matomoTransport;
|
|
63
21
|
configs;
|
|
22
|
+
/**
|
|
23
|
+
* Creates a new instance of MatomoTransport.
|
|
24
|
+
*
|
|
25
|
+
* @param configs - The application configuration containing logging settings
|
|
26
|
+
*/
|
|
64
27
|
constructor(configs) {
|
|
65
28
|
super({
|
|
66
29
|
level: configs.logs.console.minimumLevel,
|
|
@@ -69,6 +32,12 @@ var MatomoTransport = class extends Transport {
|
|
|
69
32
|
this.matomoTransport = new Transport();
|
|
70
33
|
this.configs = configs;
|
|
71
34
|
}
|
|
35
|
+
/**
|
|
36
|
+
* Logs a message to Matomo if the message category is included in the configured categories.
|
|
37
|
+
*
|
|
38
|
+
* @param info - The log information including level, message, and category
|
|
39
|
+
* @param callback - Callback function to execute after logging
|
|
40
|
+
*/
|
|
72
41
|
log(info, callback) {
|
|
73
42
|
const matomoCategory = this.configs.logs.matomo.categoriesLevel;
|
|
74
43
|
if (matomoCategory.includes(info.category) || matomoCategory.includes(ALL)) {
|
|
@@ -83,6 +52,11 @@ import Graylog2Transport from "winston-graylog2";
|
|
|
83
52
|
var GraylogTransport = class extends Transport2 {
|
|
84
53
|
graylogTransport;
|
|
85
54
|
configs;
|
|
55
|
+
/**
|
|
56
|
+
* Creates a new instance of GraylogTransport.
|
|
57
|
+
*
|
|
58
|
+
* @param configs - The application configuration containing logging settings
|
|
59
|
+
*/
|
|
86
60
|
constructor(configs) {
|
|
87
61
|
super({
|
|
88
62
|
level: configs.logs.graylog.minimumLevel,
|
|
@@ -98,6 +72,12 @@ var GraylogTransport = class extends Transport2 {
|
|
|
98
72
|
}
|
|
99
73
|
});
|
|
100
74
|
}
|
|
75
|
+
/**
|
|
76
|
+
* Logs a message to Graylog if the message category is included in the configured categories.
|
|
77
|
+
*
|
|
78
|
+
* @param info - The log information including level, message, and category
|
|
79
|
+
* @param callback - Callback function to execute after logging
|
|
80
|
+
*/
|
|
101
81
|
log(info, callback) {
|
|
102
82
|
const graylogCategory = this.configs.logs.graylog.categoriesLevel;
|
|
103
83
|
if (graylogCategory.includes(info.category) || graylogCategory.includes(ALL)) {
|
|
@@ -107,22 +87,46 @@ var GraylogTransport = class extends Transport2 {
|
|
|
107
87
|
};
|
|
108
88
|
|
|
109
89
|
// src/logger.ts
|
|
110
|
-
import { getConfigs
|
|
90
|
+
import { getConfigs } from "@c-rex/utils/next-cookies";
|
|
111
91
|
var CrexLogger = class {
|
|
112
92
|
customerConfig;
|
|
113
93
|
logger;
|
|
94
|
+
/**
|
|
95
|
+
* Initializes the logger instance if it hasn't been initialized yet.
|
|
96
|
+
* Loads customer configuration and creates the logger with appropriate transports.
|
|
97
|
+
*
|
|
98
|
+
* @private
|
|
99
|
+
*/
|
|
114
100
|
async initLogger() {
|
|
115
|
-
|
|
116
|
-
this.customerConfig
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
this.logger
|
|
101
|
+
try {
|
|
102
|
+
if (!this.customerConfig) {
|
|
103
|
+
this.customerConfig = await getConfigs();
|
|
104
|
+
}
|
|
105
|
+
if (!this.logger) {
|
|
106
|
+
this.logger = this.createLogger();
|
|
107
|
+
}
|
|
108
|
+
} catch (error) {
|
|
109
|
+
console.error("Error initializing logger:", error);
|
|
120
110
|
}
|
|
121
111
|
}
|
|
112
|
+
/**
|
|
113
|
+
* Logs a message with the specified level and optional category.
|
|
114
|
+
*
|
|
115
|
+
* @param options - Logging options
|
|
116
|
+
* @param options.level - The log level (error, warn, info, etc.)
|
|
117
|
+
* @param options.message - The message to log
|
|
118
|
+
* @param options.category - Optional category for the log message
|
|
119
|
+
*/
|
|
122
120
|
async log({ level, message, category }) {
|
|
123
121
|
await this.initLogger();
|
|
124
122
|
this.logger.log(level, message, category);
|
|
125
123
|
}
|
|
124
|
+
/**
|
|
125
|
+
* Creates a new Winston logger instance with configured transports.
|
|
126
|
+
*
|
|
127
|
+
* @private
|
|
128
|
+
* @returns A configured Winston logger instance
|
|
129
|
+
*/
|
|
126
130
|
createLogger() {
|
|
127
131
|
return winston.createLogger({
|
|
128
132
|
levels: LOG_LEVELS,
|
|
@@ -139,15 +143,12 @@ var CrexLogger = class {
|
|
|
139
143
|
};
|
|
140
144
|
|
|
141
145
|
// src/api/rpc.ts
|
|
142
|
-
import {
|
|
146
|
+
import { InformationUnitsService, LanguageService } from "@c-rex/services";
|
|
143
147
|
import { NextResponse } from "next/server";
|
|
144
148
|
var serviceRegistry = {
|
|
145
149
|
InformationUnitsService,
|
|
146
|
-
DocumentTypesService,
|
|
147
|
-
DirectoryNodesService,
|
|
148
|
-
RenditionsService,
|
|
149
150
|
CrexLogger,
|
|
150
|
-
|
|
151
|
+
LanguageService
|
|
151
152
|
};
|
|
152
153
|
var POST = async (req) => {
|
|
153
154
|
try {
|
|
@@ -164,9 +165,13 @@ var POST = async (req) => {
|
|
|
164
165
|
}
|
|
165
166
|
const result = await handler.call(serviceInstance, params);
|
|
166
167
|
return NextResponse.json({ data: result });
|
|
167
|
-
} catch (
|
|
168
|
-
|
|
169
|
-
|
|
168
|
+
} catch (error) {
|
|
169
|
+
const logger = new CrexLogger();
|
|
170
|
+
logger.log({
|
|
171
|
+
level: "error",
|
|
172
|
+
message: `RPC.POST error: ${error}`
|
|
173
|
+
});
|
|
174
|
+
return NextResponse.json({ error: String(error) }, { status: 500 });
|
|
170
175
|
}
|
|
171
176
|
};
|
|
172
177
|
export {
|
package/dist/api/rpc.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../constants/src/index.ts","../../src/sdk.ts","../../src/logger.ts","../../src/transports/matomo.ts","../../src/transports/graylog.ts","../../src/api/rpc.ts"],"sourcesContent":["export const ALL = \"*\"\n\nexport const LOG_CATEGORIES = [\n \"NoLicense\",\n \"Scenario\",\n \"Favorites\",\n \"Subscription\",\n \"Share\",\n \"Document\",\n \"Search\",\n \"History\",\n \"Notification\",\n \"UserProfile\",\n] as const;\n\nexport const LOG_LEVELS = {\n critical: 2,\n error: 3,\n warning: 4,\n info: 6,\n debug: 7,\n} as const;\n\nexport const RESULT_VIEW_STYLES = [\n \"cards\",\n \"table\",\n] as const;\n\nexport const API = {\n MAX_RETRY: 3,\n API_TIMEOUT: 10000,\n API_HEADERS: {\n \"content-Type\": \"application/json\",\n },\n};\n\nexport const SDK_CONFIG_KEY = \"crex-sdk-config\";\n\nexport const CONTENT_LANG_KEY = \"CONTENT_LANG_KEY\";\n\nexport const AVAILABLE_CONTENT_LANG_KEY = \"AVAILABLE_CONTENT_LANG_KEY\";\n\nexport const UI_LANG_KEY = \"UI_LANG_KEY\";\n\nexport const FLAGS_BY_LANG = {\n \"en\": \"US\",\n \"de\": \"DE\",\n};\n\nexport const DEFAULT_LANG = \"en-US\";\n\nexport const EN_LANG = \"en\";\n\nexport const UI_LANG_OPTIONS = [\"en-us\", \"de-de\"];\n\nexport const RESULT_TYPES = {\n TOPIC: \"TOPIC\",\n DOCUMENT: \"DOCUMENT\",\n PACKAGE: \"PACKAGE\",\n} as const;\n\nexport const FILES_EXTENSIONS = {\n PDF: \"application/pdf\",\n HTML: \"text/html\",\n} as const;\n\nexport const DEFAULT_COOKIE_LIMIT = 7 * 24 * 60 * 60 * 1000; // 7 days in milliseconds\n\nexport const ICONS_BY_FILE_EXTENSION = {\n \"application/pdf\": \"FaFilePdf\",\n} as const;\n\nexport const DEFAULT_ICON = \"file\";","import { ConfigInterface } from \"@c-rex/interfaces\";\nimport { getConfigs } from \"@c-rex/utils/next-cookies\";\n\nexport class CrexSDK {\n public userAuthConfig!: any;\n public customerConfig!: ConfigInterface;\n\n private async getConfig() {\n if (!this.customerConfig) {\n this.customerConfig = await getConfigs()\n }\n }\n\n public async getUserAuthConfig() {\n if (this.userAuthConfig) {\n return this.userAuthConfig;\n }\n\n await this.getConfig();\n\n const user = this.customerConfig.OIDC.user;\n if (user.enabled) {\n this.userAuthConfig = {\n providers: [\n {\n id: \"crex\",\n name: \"CREX\",\n type: \"oauth\",\n clientId: user.id,\n wellKnown: user.issuer,\n clientSecret: user.secret,\n authorization: { params: { scope: user.scope } },\n profile(profile: any) {\n return {\n id: profile.id || \"fake Id\",\n name: profile.name || \"Fake Name\",\n email: profile.email || \"fake Email\",\n image: profile.image || \"fake Image\",\n }\n },\n },\n ]\n }\n };\n\n return this.userAuthConfig;\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 { getConfigs } from \"@c-rex/utils/next-cookies\";\n\nexport class CrexLogger {\n private customerConfig!: ConfigInterface;\n public logger!: winston.Logger;\n\n private async initLogger() {\n if (!this.customerConfig) {\n this.customerConfig = await getConfigs();\n }\n\n if (!this.logger) {\n this.logger = this.createLogger();\n }\n }\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 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\nexport class MatomoTransport extends Transport {\n public matomoTransport: any;\n private configs: ConfigInterface;\n\n constructor(configs: ConfigInterface) {\n super({\n level: configs.logs.console.minimumLevel,\n silent: configs.logs.console.silent,\n });\n\n this.matomoTransport = new Transport();\n this.configs = configs;\n }\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\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\nexport class GraylogTransport extends Transport {\n public graylogTransport: any;\n public configs: ConfigInterface\n\n constructor(configs: ConfigInterface) {\n super({\n level: configs.logs.graylog.minimumLevel,\n silent: configs.logs.graylog.silent,\n });\n\n this.configs = configs;\n this.graylogTransport = new Graylog2Transport({\n name: \"Periotto-TEST\",\n silent: false,\n handleExceptions: false,\n graylog: {\n servers: [{ host: \"localhost\", port: 12201 }],\n },\n });\n }\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 { CrexSDK } from '../';\nimport { CrexLogger } from '../logger';\nimport { DirectoryNodesService, DocumentTypesService, InformationUnitsService, RenditionsService } from '@c-rex/services';\nimport { NextRequest, NextResponse } from 'next/server';\n\nconst serviceRegistry = {\n InformationUnitsService,\n DocumentTypesService,\n DirectoryNodesService,\n RenditionsService,\n CrexLogger,\n CrexSDK,\n};\n\ntype RpcPayload = {\n method: string;\n params: any;\n};\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 (err) {\n console.error(err);\n return NextResponse.json({ error: String(err) }, { status: 500 });\n }\n}\n"],"mappings":";AAAO,IAAM,MAAM;AAeZ,IAAM,aAAa;AA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AAK,EAAE,MAAM,OAAO,CAAC;AAAA,EAC7C,SAAS,KAAK;AACV,YAAQ,MAAM,GAAG;AACjB,WAAO,aAAa,KAAK,EAAE,OAAO,OAAO,GAAG,EAAE,GAAG,EAAE,QAAQ,IAAI,CAAC;AAAA,EACpE;AACJ;","names":["Transport","Transport","getConfigs"]}
|
|
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 { getConfigs } from \"@c-rex/utils/next-cookies\";\n\n/**\n * Logger class for the CREX application.\n * Provides logging functionality with multiple transports (Console, Matomo, Graylog).\n */\nexport class CrexLogger {\n private customerConfig!: ConfigInterface;\n public logger!: winston.Logger;\n\n /**\n * Initializes the logger instance if it hasn't been initialized yet.\n * Loads customer configuration and creates the logger with appropriate transports.\n * \n * @private\n */\n private async initLogger() {\n try {\n if (!this.customerConfig) {\n this.customerConfig = await getConfigs();\n }\n\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.console.minimumLevel,\n silent: configs.logs.console.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 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 DOCUMENTS_TYPE_AND_LINK = \"documents\";\n\nexport const TOPIC = \"TOPIC\";\nexport const DOCUMENT = \"DOCUMENT\";\nexport const PACKAGE = \"PACKAGE\";\n\nexport const RESULT_TYPES = {\n TOPIC: TOPIC,\n DOCUMENT: DOCUMENT,\n PACKAGE: PACKAGE,\n} as const;\n\nexport const FILES_EXTENSIONS = {\n PDF: \"application/pdf\",\n HTML: \"text/html\",\n} as const;\n\nexport const DEFAULT_COOKIE_LIMIT = 7 * 24 * 60 * 60 * 1000; // 7 days in milliseconds\n\nexport const ICONS_BY_FILE_EXTENSION = {\n \"application/pdf\": \"FaFilePdf\",\n} as const;\n\nexport const DEFAULT_ICON = \"file\";\n\nexport const CREX_TOKEN_HEADER_KEY = \"crex-token\";","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 public configs: ConfigInterface\n\n /**\n * Creates a new instance of GraylogTransport.\n * \n * @param configs - The application configuration containing logging settings\n */\n constructor(configs: ConfigInterface) {\n super({\n level: configs.logs.graylog.minimumLevel,\n silent: configs.logs.graylog.silent,\n });\n\n this.configs = configs;\n this.graylogTransport = new Graylog2Transport({\n name: \"Periotto-TEST\",\n silent: false,\n handleExceptions: false,\n graylog: {\n servers: [{ host: \"localhost\", port: 12201 }],\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;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;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,aAAa,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,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"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { NextResponse } from 'next/server';
|
|
2
|
+
import { ConfigInterface } from '@c-rex/interfaces';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Retrieves an access token using client credentials flow from the configured OIDC provider
|
|
6
|
+
*
|
|
7
|
+
* @param CUSTOMER_CONFIG - Configuration object containing OIDC client settings
|
|
8
|
+
* @returns NextResponse with success status or error message
|
|
9
|
+
* @throws Error if token retrieval fails
|
|
10
|
+
*/
|
|
11
|
+
declare const postMethod: (CUSTOMER_CONFIG: ConfigInterface) => Promise<NextResponse>;
|
|
12
|
+
|
|
13
|
+
export { postMethod };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { NextResponse } from 'next/server';
|
|
2
|
+
import { ConfigInterface } from '@c-rex/interfaces';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Retrieves an access token using client credentials flow from the configured OIDC provider
|
|
6
|
+
*
|
|
7
|
+
* @param CUSTOMER_CONFIG - Configuration object containing OIDC client settings
|
|
8
|
+
* @returns NextResponse with success status or error message
|
|
9
|
+
* @throws Error if token retrieval fails
|
|
10
|
+
*/
|
|
11
|
+
declare const postMethod: (CUSTOMER_CONFIG: ConfigInterface) => Promise<NextResponse>;
|
|
12
|
+
|
|
13
|
+
export { postMethod };
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/api/token.ts
|
|
21
|
+
var token_exports = {};
|
|
22
|
+
__export(token_exports, {
|
|
23
|
+
postMethod: () => postMethod
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(token_exports);
|
|
26
|
+
var import_server = require("next/server");
|
|
27
|
+
var import_headers = require("next/headers");
|
|
28
|
+
var import_openid_client = require("openid-client");
|
|
29
|
+
|
|
30
|
+
// ../constants/src/index.ts
|
|
31
|
+
var DEFAULT_COOKIE_LIMIT = 7 * 24 * 60 * 60 * 1e3;
|
|
32
|
+
var CREX_TOKEN_HEADER_KEY = "crex-token";
|
|
33
|
+
|
|
34
|
+
// src/api/token.ts
|
|
35
|
+
var postMethod = async (CUSTOMER_CONFIG) => {
|
|
36
|
+
const issuer = await import_openid_client.Issuer.discover(CUSTOMER_CONFIG.OIDC.client.issuer);
|
|
37
|
+
const client = new issuer.Client({
|
|
38
|
+
client_id: CUSTOMER_CONFIG.OIDC.client.id,
|
|
39
|
+
client_secret: CUSTOMER_CONFIG.OIDC.client.secret
|
|
40
|
+
});
|
|
41
|
+
const tokenSet = await client.grant({ grant_type: "client_credentials" });
|
|
42
|
+
const token = tokenSet.access_token;
|
|
43
|
+
if (!token) {
|
|
44
|
+
return import_server.NextResponse.json({ error: "Failed to get token" }, { status: 500 });
|
|
45
|
+
}
|
|
46
|
+
(0, import_headers.cookies)().set({
|
|
47
|
+
name: CREX_TOKEN_HEADER_KEY,
|
|
48
|
+
value: token,
|
|
49
|
+
httpOnly: true,
|
|
50
|
+
secure: process.env.NODE_ENV === "production",
|
|
51
|
+
sameSite: "lax",
|
|
52
|
+
path: "/",
|
|
53
|
+
maxAge: 8 * 60
|
|
54
|
+
});
|
|
55
|
+
return import_server.NextResponse.json({ success: true });
|
|
56
|
+
};
|
|
57
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
58
|
+
0 && (module.exports = {
|
|
59
|
+
postMethod
|
|
60
|
+
});
|
|
61
|
+
//# sourceMappingURL=token.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/api/token.ts","../../../constants/src/index.ts"],"sourcesContent":["import { NextResponse } from 'next/server';\nimport { cookies } from 'next/headers';\nimport { Issuer } from 'openid-client';\nimport { CREX_TOKEN_HEADER_KEY } from '@c-rex/constants';\nimport { ConfigInterface } from '@c-rex/interfaces';\n\n/**\n * Retrieves an access token using client credentials flow from the configured OIDC provider\n * \n * @param CUSTOMER_CONFIG - Configuration object containing OIDC client settings\n * @returns NextResponse with success status or error message\n * @throws Error if token retrieval fails\n */\nexport const postMethod = async (CUSTOMER_CONFIG: ConfigInterface): Promise<NextResponse> => {\n const issuer = await Issuer.discover(CUSTOMER_CONFIG.OIDC.client.issuer);\n const client = new issuer.Client({\n client_id: CUSTOMER_CONFIG.OIDC.client.id,\n client_secret: CUSTOMER_CONFIG.OIDC.client.secret,\n });\n const tokenSet = await client.grant({ grant_type: 'client_credentials' });\n\n const token = tokenSet.access_token!;\n\n if (!token) {\n return NextResponse.json({ error: 'Failed to get token' }, { status: 500 });\n }\n\n 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 maxAge: 8 * 60\n });\n\n return NextResponse.json({ success: true });\n}\n","export const ALL = \"*\"\n\nexport const LOG_CATEGORIES = [\n \"NoLicense\",\n \"Scenario\",\n \"Favorites\",\n \"Subscription\",\n \"Share\",\n \"Document\",\n \"Search\",\n \"History\",\n \"Notification\",\n \"UserProfile\",\n] as const;\n\nexport const LOG_LEVELS = {\n critical: 2,\n error: 3,\n warning: 4,\n info: 6,\n debug: 7,\n} as const;\n\nexport const RESULT_VIEW_STYLES = [\n \"cards\",\n \"table\",\n] as const;\n\nexport const API = {\n MAX_RETRY: 3,\n API_TIMEOUT: 10000,\n API_HEADERS: {\n \"content-Type\": \"application/json\",\n },\n};\n\nexport const SDK_CONFIG_KEY = \"crex-sdk-config\";\n\nexport const CONTENT_LANG_KEY = \"CONTENT_LANG_KEY\";\n\nexport const AVAILABLE_CONTENT_LANG_KEY = \"AVAILABLE_CONTENT_LANG_KEY\";\n\nexport const UI_LANG_KEY = \"UI_LANG_KEY\";\n\nexport const FLAGS_BY_LANG = {\n \"en\": \"US\",\n \"de\": \"DE\",\n};\n\nexport const DEFAULT_LANG = \"en-US\";\n\nexport const EN_LANG = \"en\";\n\nexport const UI_LANG_OPTIONS = [\"en-us\", \"de-de\"];\n\nexport const TOPICS_TYPE_AND_LINK = \"topics\";\nexport const DOCUMENTS_TYPE_AND_LINK = \"documents\";\n\nexport const TOPIC = \"TOPIC\";\nexport const DOCUMENT = \"DOCUMENT\";\nexport const PACKAGE = \"PACKAGE\";\n\nexport const RESULT_TYPES = {\n TOPIC: TOPIC,\n DOCUMENT: DOCUMENT,\n PACKAGE: PACKAGE,\n} as const;\n\nexport const FILES_EXTENSIONS = {\n PDF: \"application/pdf\",\n HTML: \"text/html\",\n} as const;\n\nexport const DEFAULT_COOKIE_LIMIT = 7 * 24 * 60 * 60 * 1000; // 7 days in milliseconds\n\nexport const ICONS_BY_FILE_EXTENSION = {\n \"application/pdf\": \"FaFilePdf\",\n} as const;\n\nexport const DEFAULT_ICON = \"file\";\n\nexport const CREX_TOKEN_HEADER_KEY = \"crex-token\";"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA6B;AAC7B,qBAAwB;AACxB,2BAAuB;;;ACuEhB,IAAM,uBAAuB,IAAI,KAAK,KAAK,KAAK;AAQhD,IAAM,wBAAwB;;;ADpE9B,IAAM,aAAa,OAAO,oBAA4D;AACzF,QAAM,SAAS,MAAM,4BAAO,SAAS,gBAAgB,KAAK,OAAO,MAAM;AACvE,QAAM,SAAS,IAAI,OAAO,OAAO;AAAA,IAC7B,WAAW,gBAAgB,KAAK,OAAO;AAAA,IACvC,eAAe,gBAAgB,KAAK,OAAO;AAAA,EAC/C,CAAC;AACD,QAAM,WAAW,MAAM,OAAO,MAAM,EAAE,YAAY,qBAAqB,CAAC;AAExE,QAAM,QAAQ,SAAS;AAEvB,MAAI,CAAC,OAAO;AACR,WAAO,2BAAa,KAAK,EAAE,OAAO,sBAAsB,GAAG,EAAE,QAAQ,IAAI,CAAC;AAAA,EAC9E;AAEA,8BAAQ,EAAE,IAAI;AAAA,IACV,MAAM;AAAA,IACN,OAAO;AAAA,IACP,UAAU;AAAA,IACV,QAAQ,QAAQ,IAAI,aAAa;AAAA,IACjC,UAAU;AAAA,IACV,MAAM;AAAA,IACN,QAAQ,IAAI;AAAA,EAChB,CAAC;AAED,SAAO,2BAAa,KAAK,EAAE,SAAS,KAAK,CAAC;AAC9C;","names":[]}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// src/api/token.ts
|
|
2
|
+
import { NextResponse } from "next/server";
|
|
3
|
+
import { cookies } from "next/headers";
|
|
4
|
+
import { Issuer } from "openid-client";
|
|
5
|
+
|
|
6
|
+
// ../constants/src/index.ts
|
|
7
|
+
var DEFAULT_COOKIE_LIMIT = 7 * 24 * 60 * 60 * 1e3;
|
|
8
|
+
var CREX_TOKEN_HEADER_KEY = "crex-token";
|
|
9
|
+
|
|
10
|
+
// src/api/token.ts
|
|
11
|
+
var postMethod = async (CUSTOMER_CONFIG) => {
|
|
12
|
+
const issuer = await Issuer.discover(CUSTOMER_CONFIG.OIDC.client.issuer);
|
|
13
|
+
const client = new issuer.Client({
|
|
14
|
+
client_id: CUSTOMER_CONFIG.OIDC.client.id,
|
|
15
|
+
client_secret: CUSTOMER_CONFIG.OIDC.client.secret
|
|
16
|
+
});
|
|
17
|
+
const tokenSet = await client.grant({ grant_type: "client_credentials" });
|
|
18
|
+
const token = tokenSet.access_token;
|
|
19
|
+
if (!token) {
|
|
20
|
+
return NextResponse.json({ error: "Failed to get token" }, { status: 500 });
|
|
21
|
+
}
|
|
22
|
+
cookies().set({
|
|
23
|
+
name: CREX_TOKEN_HEADER_KEY,
|
|
24
|
+
value: token,
|
|
25
|
+
httpOnly: true,
|
|
26
|
+
secure: process.env.NODE_ENV === "production",
|
|
27
|
+
sameSite: "lax",
|
|
28
|
+
path: "/",
|
|
29
|
+
maxAge: 8 * 60
|
|
30
|
+
});
|
|
31
|
+
return NextResponse.json({ success: true });
|
|
32
|
+
};
|
|
33
|
+
export {
|
|
34
|
+
postMethod
|
|
35
|
+
};
|
|
36
|
+
//# sourceMappingURL=token.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/api/token.ts","../../../constants/src/index.ts"],"sourcesContent":["import { NextResponse } from 'next/server';\nimport { cookies } from 'next/headers';\nimport { Issuer } from 'openid-client';\nimport { CREX_TOKEN_HEADER_KEY } from '@c-rex/constants';\nimport { ConfigInterface } from '@c-rex/interfaces';\n\n/**\n * Retrieves an access token using client credentials flow from the configured OIDC provider\n * \n * @param CUSTOMER_CONFIG - Configuration object containing OIDC client settings\n * @returns NextResponse with success status or error message\n * @throws Error if token retrieval fails\n */\nexport const postMethod = async (CUSTOMER_CONFIG: ConfigInterface): Promise<NextResponse> => {\n const issuer = await Issuer.discover(CUSTOMER_CONFIG.OIDC.client.issuer);\n const client = new issuer.Client({\n client_id: CUSTOMER_CONFIG.OIDC.client.id,\n client_secret: CUSTOMER_CONFIG.OIDC.client.secret,\n });\n const tokenSet = await client.grant({ grant_type: 'client_credentials' });\n\n const token = tokenSet.access_token!;\n\n if (!token) {\n return NextResponse.json({ error: 'Failed to get token' }, { status: 500 });\n }\n\n 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 maxAge: 8 * 60\n });\n\n return NextResponse.json({ success: true });\n}\n","export const ALL = \"*\"\n\nexport const LOG_CATEGORIES = [\n \"NoLicense\",\n \"Scenario\",\n \"Favorites\",\n \"Subscription\",\n \"Share\",\n \"Document\",\n \"Search\",\n \"History\",\n \"Notification\",\n \"UserProfile\",\n] as const;\n\nexport const LOG_LEVELS = {\n critical: 2,\n error: 3,\n warning: 4,\n info: 6,\n debug: 7,\n} as const;\n\nexport const RESULT_VIEW_STYLES = [\n \"cards\",\n \"table\",\n] as const;\n\nexport const API = {\n MAX_RETRY: 3,\n API_TIMEOUT: 10000,\n API_HEADERS: {\n \"content-Type\": \"application/json\",\n },\n};\n\nexport const SDK_CONFIG_KEY = \"crex-sdk-config\";\n\nexport const CONTENT_LANG_KEY = \"CONTENT_LANG_KEY\";\n\nexport const AVAILABLE_CONTENT_LANG_KEY = \"AVAILABLE_CONTENT_LANG_KEY\";\n\nexport const UI_LANG_KEY = \"UI_LANG_KEY\";\n\nexport const FLAGS_BY_LANG = {\n \"en\": \"US\",\n \"de\": \"DE\",\n};\n\nexport const DEFAULT_LANG = \"en-US\";\n\nexport const EN_LANG = \"en\";\n\nexport const UI_LANG_OPTIONS = [\"en-us\", \"de-de\"];\n\nexport const TOPICS_TYPE_AND_LINK = \"topics\";\nexport const DOCUMENTS_TYPE_AND_LINK = \"documents\";\n\nexport const TOPIC = \"TOPIC\";\nexport const DOCUMENT = \"DOCUMENT\";\nexport const PACKAGE = \"PACKAGE\";\n\nexport const RESULT_TYPES = {\n TOPIC: TOPIC,\n DOCUMENT: DOCUMENT,\n PACKAGE: PACKAGE,\n} as const;\n\nexport const FILES_EXTENSIONS = {\n PDF: \"application/pdf\",\n HTML: \"text/html\",\n} as const;\n\nexport const DEFAULT_COOKIE_LIMIT = 7 * 24 * 60 * 60 * 1000; // 7 days in milliseconds\n\nexport const ICONS_BY_FILE_EXTENSION = {\n \"application/pdf\": \"FaFilePdf\",\n} as const;\n\nexport const DEFAULT_ICON = \"file\";\n\nexport const CREX_TOKEN_HEADER_KEY = \"crex-token\";"],"mappings":";AAAA,SAAS,oBAAoB;AAC7B,SAAS,eAAe;AACxB,SAAS,cAAc;;;ACuEhB,IAAM,uBAAuB,IAAI,KAAK,KAAK,KAAK;AAQhD,IAAM,wBAAwB;;;ADpE9B,IAAM,aAAa,OAAO,oBAA4D;AACzF,QAAM,SAAS,MAAM,OAAO,SAAS,gBAAgB,KAAK,OAAO,MAAM;AACvE,QAAM,SAAS,IAAI,OAAO,OAAO;AAAA,IAC7B,WAAW,gBAAgB,KAAK,OAAO;AAAA,IACvC,eAAe,gBAAgB,KAAK,OAAO;AAAA,EAC/C,CAAC;AACD,QAAM,WAAW,MAAM,OAAO,MAAM,EAAE,YAAY,qBAAqB,CAAC;AAExE,QAAM,QAAQ,SAAS;AAEvB,MAAI,CAAC,OAAO;AACR,WAAO,aAAa,KAAK,EAAE,OAAO,sBAAsB,GAAG,EAAE,QAAQ,IAAI,CAAC;AAAA,EAC9E;AAEA,UAAQ,EAAE,IAAI;AAAA,IACV,MAAM;AAAA,IACN,OAAO;AAAA,IACP,UAAU;AAAA,IACV,QAAQ,QAAQ,IAAI,aAAa;AAAA,IACjC,UAAU;AAAA,IACV,MAAM;AAAA,IACN,QAAQ,IAAI;AAAA,EAChB,CAAC;AAED,SAAO,aAAa,KAAK,EAAE,SAAS,KAAK,CAAC;AAC9C;","names":[]}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { Method } from 'axios';
|
|
2
2
|
import { ConfigInterface } from '@c-rex/interfaces';
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Interface for API call parameters.
|
|
6
|
+
*/
|
|
4
7
|
interface CallParams {
|
|
5
8
|
url: string;
|
|
6
9
|
method: Method;
|
|
@@ -8,19 +11,56 @@ interface CallParams {
|
|
|
8
11
|
headers?: any;
|
|
9
12
|
params?: any;
|
|
10
13
|
}
|
|
14
|
+
/**
|
|
15
|
+
* API client class for the CREX application.
|
|
16
|
+
* Handles API requests with caching, authentication, and retry logic.
|
|
17
|
+
*/
|
|
11
18
|
declare class CrexApi {
|
|
12
19
|
private customerConfig;
|
|
13
20
|
private apiClient;
|
|
14
|
-
private
|
|
15
|
-
|
|
21
|
+
private cache;
|
|
22
|
+
/**
|
|
23
|
+
* Initializes the API client if it hasn't been initialized yet.
|
|
24
|
+
* Loads customer configuration, creates the axios instance, and initializes the cache.
|
|
25
|
+
*
|
|
26
|
+
* @private
|
|
27
|
+
*/
|
|
16
28
|
private initAPI;
|
|
29
|
+
/**
|
|
30
|
+
* Executes an API request with caching, authentication, and retry logic.
|
|
31
|
+
*
|
|
32
|
+
* @param options - Request options
|
|
33
|
+
* @param options.url - The URL to request
|
|
34
|
+
* @param options.method - The HTTP method to use
|
|
35
|
+
* @param options.params - Optional query parameters
|
|
36
|
+
* @param options.body - Optional request body
|
|
37
|
+
* @param options.headers - Optional request headers
|
|
38
|
+
* @returns The response data
|
|
39
|
+
* @throws Error if the request fails after maximum retries
|
|
40
|
+
*/
|
|
17
41
|
execute<T>({ url, method, params, body, headers, }: CallParams): Promise<T>;
|
|
18
42
|
}
|
|
19
43
|
|
|
44
|
+
/**
|
|
45
|
+
* SDK class for the CREX application.
|
|
46
|
+
* Provides configuration and authentication functionality.
|
|
47
|
+
*/
|
|
20
48
|
declare class CrexSDK {
|
|
21
49
|
userAuthConfig: any;
|
|
22
50
|
customerConfig: ConfigInterface;
|
|
51
|
+
/**
|
|
52
|
+
* Retrieves the customer configuration if it hasn't been loaded yet.
|
|
53
|
+
*
|
|
54
|
+
* @private
|
|
55
|
+
*/
|
|
23
56
|
private getConfig;
|
|
57
|
+
/**
|
|
58
|
+
* Retrieves the user authentication configuration.
|
|
59
|
+
* If not already loaded, it will load the customer configuration and
|
|
60
|
+
* create the auth config based on OIDC settings.
|
|
61
|
+
*
|
|
62
|
+
* @returns The user authentication configuration object
|
|
63
|
+
*/
|
|
24
64
|
getUserAuthConfig(): Promise<any>;
|
|
25
65
|
}
|
|
26
66
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { Method } from 'axios';
|
|
2
2
|
import { ConfigInterface } from '@c-rex/interfaces';
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Interface for API call parameters.
|
|
6
|
+
*/
|
|
4
7
|
interface CallParams {
|
|
5
8
|
url: string;
|
|
6
9
|
method: Method;
|
|
@@ -8,19 +11,56 @@ interface CallParams {
|
|
|
8
11
|
headers?: any;
|
|
9
12
|
params?: any;
|
|
10
13
|
}
|
|
14
|
+
/**
|
|
15
|
+
* API client class for the CREX application.
|
|
16
|
+
* Handles API requests with caching, authentication, and retry logic.
|
|
17
|
+
*/
|
|
11
18
|
declare class CrexApi {
|
|
12
19
|
private customerConfig;
|
|
13
20
|
private apiClient;
|
|
14
|
-
private
|
|
15
|
-
|
|
21
|
+
private cache;
|
|
22
|
+
/**
|
|
23
|
+
* Initializes the API client if it hasn't been initialized yet.
|
|
24
|
+
* Loads customer configuration, creates the axios instance, and initializes the cache.
|
|
25
|
+
*
|
|
26
|
+
* @private
|
|
27
|
+
*/
|
|
16
28
|
private initAPI;
|
|
29
|
+
/**
|
|
30
|
+
* Executes an API request with caching, authentication, and retry logic.
|
|
31
|
+
*
|
|
32
|
+
* @param options - Request options
|
|
33
|
+
* @param options.url - The URL to request
|
|
34
|
+
* @param options.method - The HTTP method to use
|
|
35
|
+
* @param options.params - Optional query parameters
|
|
36
|
+
* @param options.body - Optional request body
|
|
37
|
+
* @param options.headers - Optional request headers
|
|
38
|
+
* @returns The response data
|
|
39
|
+
* @throws Error if the request fails after maximum retries
|
|
40
|
+
*/
|
|
17
41
|
execute<T>({ url, method, params, body, headers, }: CallParams): Promise<T>;
|
|
18
42
|
}
|
|
19
43
|
|
|
44
|
+
/**
|
|
45
|
+
* SDK class for the CREX application.
|
|
46
|
+
* Provides configuration and authentication functionality.
|
|
47
|
+
*/
|
|
20
48
|
declare class CrexSDK {
|
|
21
49
|
userAuthConfig: any;
|
|
22
50
|
customerConfig: ConfigInterface;
|
|
51
|
+
/**
|
|
52
|
+
* Retrieves the customer configuration if it hasn't been loaded yet.
|
|
53
|
+
*
|
|
54
|
+
* @private
|
|
55
|
+
*/
|
|
23
56
|
private getConfig;
|
|
57
|
+
/**
|
|
58
|
+
* Retrieves the user authentication configuration.
|
|
59
|
+
* If not already loaded, it will load the customer configuration and
|
|
60
|
+
* create the auth config based on OIDC settings.
|
|
61
|
+
*
|
|
62
|
+
* @returns The user authentication configuration object
|
|
63
|
+
*/
|
|
24
64
|
getUserAuthConfig(): Promise<any>;
|
|
25
65
|
}
|
|
26
66
|
|