@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/cookies.d.mts
CHANGED
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
import { NextRequest, NextResponse } from 'next/server';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Retrieves a cookie value by key from the request
|
|
5
|
+
* @param {NextRequest} req - The Next.js request object
|
|
6
|
+
* @returns {Promise<NextResponse>} JSON response containing the cookie key-value pair or error
|
|
7
|
+
*/
|
|
8
|
+
declare const getMethod: (req: NextRequest) => Promise<NextResponse>;
|
|
9
|
+
/**
|
|
10
|
+
* Sets a cookie with the specified key, value and options
|
|
11
|
+
* @param {NextRequest} req - The Next.js request object
|
|
12
|
+
* @returns {Promise<NextResponse>} JSON response indicating success or error
|
|
13
|
+
* @throws {Error} If key or value are missing in the request body
|
|
14
|
+
*/
|
|
15
|
+
declare const postMethod: (req: NextRequest) => Promise<NextResponse>;
|
|
9
16
|
|
|
10
|
-
export {
|
|
17
|
+
export { getMethod, postMethod };
|
package/dist/api/cookies.d.ts
CHANGED
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
import { NextRequest, NextResponse } from 'next/server';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Retrieves a cookie value by key from the request
|
|
5
|
+
* @param {NextRequest} req - The Next.js request object
|
|
6
|
+
* @returns {Promise<NextResponse>} JSON response containing the cookie key-value pair or error
|
|
7
|
+
*/
|
|
8
|
+
declare const getMethod: (req: NextRequest) => Promise<NextResponse>;
|
|
9
|
+
/**
|
|
10
|
+
* Sets a cookie with the specified key, value and options
|
|
11
|
+
* @param {NextRequest} req - The Next.js request object
|
|
12
|
+
* @returns {Promise<NextResponse>} JSON response indicating success or error
|
|
13
|
+
* @throws {Error} If key or value are missing in the request body
|
|
14
|
+
*/
|
|
15
|
+
declare const postMethod: (req: NextRequest) => Promise<NextResponse>;
|
|
9
16
|
|
|
10
|
-
export {
|
|
17
|
+
export { getMethod, postMethod };
|
package/dist/api/cookies.js
CHANGED
|
@@ -20,19 +20,46 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/api/cookies.ts
|
|
21
21
|
var cookies_exports = {};
|
|
22
22
|
__export(cookies_exports, {
|
|
23
|
-
|
|
23
|
+
getMethod: () => getMethod,
|
|
24
|
+
postMethod: () => postMethod
|
|
24
25
|
});
|
|
25
26
|
module.exports = __toCommonJS(cookies_exports);
|
|
26
27
|
var import_server = require("next/server");
|
|
27
|
-
var
|
|
28
|
-
|
|
28
|
+
var import_headers = require("next/headers");
|
|
29
|
+
|
|
30
|
+
// ../constants/src/index.ts
|
|
31
|
+
var DEFAULT_COOKIE_LIMIT = 7 * 24 * 60 * 60 * 1e3;
|
|
32
|
+
|
|
33
|
+
// src/api/cookies.ts
|
|
34
|
+
var getMethod = async (req) => {
|
|
29
35
|
const key = req.nextUrl.searchParams.get("key");
|
|
30
36
|
if (!key) return import_server.NextResponse.json({ error: "Missing key" }, { status: 400 });
|
|
31
|
-
const value = (0,
|
|
32
|
-
return import_server.NextResponse.json({
|
|
37
|
+
const value = (0, import_headers.cookies)().get(key);
|
|
38
|
+
if (!value) return import_server.NextResponse.json({ error: "Missing value" }, { status: 400 });
|
|
39
|
+
return import_server.NextResponse.json({ key, value: value.value });
|
|
40
|
+
};
|
|
41
|
+
var postMethod = async (req) => {
|
|
42
|
+
const { key, value, maxAge: maxAgeAux } = await req.json();
|
|
43
|
+
let maxAge = maxAgeAux;
|
|
44
|
+
if (!key || value === void 0) {
|
|
45
|
+
return import_server.NextResponse.json({ error: "Missing key or value" }, { status: 400 });
|
|
46
|
+
}
|
|
47
|
+
if (maxAge === void 0) {
|
|
48
|
+
maxAge = DEFAULT_COOKIE_LIMIT;
|
|
49
|
+
}
|
|
50
|
+
(0, import_headers.cookies)().set({
|
|
51
|
+
name: key,
|
|
52
|
+
value,
|
|
53
|
+
secure: process.env.NODE_ENV === "production",
|
|
54
|
+
sameSite: "lax",
|
|
55
|
+
path: "/",
|
|
56
|
+
maxAge
|
|
57
|
+
});
|
|
58
|
+
return import_server.NextResponse.json({ success: true });
|
|
33
59
|
};
|
|
34
60
|
// Annotate the CommonJS export names for ESM import in node:
|
|
35
61
|
0 && (module.exports = {
|
|
36
|
-
|
|
62
|
+
getMethod,
|
|
63
|
+
postMethod
|
|
37
64
|
});
|
|
38
65
|
//# sourceMappingURL=cookies.js.map
|
package/dist/api/cookies.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/api/cookies.ts"],"sourcesContent":["import { NextRequest, NextResponse } from 'next/server';\nimport {
|
|
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 if (!value) return NextResponse.json({ error: 'Missing value' }, { status: 400 });\n\n return NextResponse.json({ key, value: value.value });\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 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 NextResponse.json({ success: true });\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;AAAA,oBAA0C;AAC1C,qBAAwB;;;ACwEjB,IAAM,uBAAuB,IAAI,KAAK,KAAK,KAAK;;;ADhEhD,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,MAAI,CAAC,MAAO,QAAO,2BAAa,KAAK,EAAE,OAAO,gBAAgB,GAAG,EAAE,QAAQ,IAAI,CAAC;AAEhF,SAAO,2BAAa,KAAK,EAAE,KAAK,OAAO,MAAM,MAAM,CAAC;AACxD;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,8BAAQ,EAAE,IAAI;AAAA,IACV,MAAM;AAAA,IACN;AAAA,IACA,QAAQ,QAAQ,IAAI,aAAa;AAAA,IACjC,UAAU;AAAA,IACV,MAAM;AAAA,IACN;AAAA,EACJ,CAAC;AAED,SAAO,2BAAa,KAAK,EAAE,SAAS,KAAK,CAAC;AAC9C;","names":[]}
|
package/dist/api/cookies.mjs
CHANGED
|
@@ -1,13 +1,39 @@
|
|
|
1
1
|
// src/api/cookies.ts
|
|
2
2
|
import { NextResponse } from "next/server";
|
|
3
|
-
import {
|
|
4
|
-
|
|
3
|
+
import { cookies } from "next/headers";
|
|
4
|
+
|
|
5
|
+
// ../constants/src/index.ts
|
|
6
|
+
var DEFAULT_COOKIE_LIMIT = 7 * 24 * 60 * 60 * 1e3;
|
|
7
|
+
|
|
8
|
+
// src/api/cookies.ts
|
|
9
|
+
var getMethod = async (req) => {
|
|
5
10
|
const key = req.nextUrl.searchParams.get("key");
|
|
6
11
|
if (!key) return NextResponse.json({ error: "Missing key" }, { status: 400 });
|
|
7
|
-
const value =
|
|
8
|
-
return NextResponse.json({
|
|
12
|
+
const value = cookies().get(key);
|
|
13
|
+
if (!value) return NextResponse.json({ error: "Missing value" }, { status: 400 });
|
|
14
|
+
return NextResponse.json({ key, value: value.value });
|
|
15
|
+
};
|
|
16
|
+
var postMethod = async (req) => {
|
|
17
|
+
const { key, value, maxAge: maxAgeAux } = await req.json();
|
|
18
|
+
let maxAge = maxAgeAux;
|
|
19
|
+
if (!key || value === void 0) {
|
|
20
|
+
return NextResponse.json({ error: "Missing key or value" }, { status: 400 });
|
|
21
|
+
}
|
|
22
|
+
if (maxAge === void 0) {
|
|
23
|
+
maxAge = DEFAULT_COOKIE_LIMIT;
|
|
24
|
+
}
|
|
25
|
+
cookies().set({
|
|
26
|
+
name: key,
|
|
27
|
+
value,
|
|
28
|
+
secure: process.env.NODE_ENV === "production",
|
|
29
|
+
sameSite: "lax",
|
|
30
|
+
path: "/",
|
|
31
|
+
maxAge
|
|
32
|
+
});
|
|
33
|
+
return NextResponse.json({ success: true });
|
|
9
34
|
};
|
|
10
35
|
export {
|
|
11
|
-
|
|
36
|
+
getMethod,
|
|
37
|
+
postMethod
|
|
12
38
|
};
|
|
13
39
|
//# sourceMappingURL=cookies.mjs.map
|
package/dist/api/cookies.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/api/cookies.ts"],"sourcesContent":["import { NextRequest, NextResponse } from 'next/server';\nimport {
|
|
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 if (!value) return NextResponse.json({ error: 'Missing value' }, { status: 400 });\n\n return NextResponse.json({ key, value: value.value });\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 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 NextResponse.json({ success: true });\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,SAAsB,oBAAoB;AAC1C,SAAS,eAAe;;;ACwEjB,IAAM,uBAAuB,IAAI,KAAK,KAAK,KAAK;;;ADhEhD,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,MAAI,CAAC,MAAO,QAAO,aAAa,KAAK,EAAE,OAAO,gBAAgB,GAAG,EAAE,QAAQ,IAAI,CAAC;AAEhF,SAAO,aAAa,KAAK,EAAE,KAAK,OAAO,MAAM,MAAM,CAAC;AACxD;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,UAAQ,EAAE,IAAI;AAAA,IACV,MAAM;AAAA,IACN;AAAA,IACA,QAAQ,QAAQ,IAAI,aAAa;AAAA,IACjC,UAAU;AAAA,IACV,MAAM;AAAA,IACN;AAAA,EACJ,CAAC;AAED,SAAO,aAAa,KAAK,EAAE,SAAS,KAAK,CAAC;AAC9C;","names":[]}
|
package/dist/api/rpc.d.mts
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import { NextRequest, NextResponse } from 'next/server';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Handles POST requests for RPC (Remote Procedure Call) functionality.
|
|
5
|
+
* Allows calling methods on registered services with parameters.
|
|
6
|
+
*
|
|
7
|
+
* @param req - The Next.js request object containing the RPC payload
|
|
8
|
+
* @returns A JSON response with the result of the method call, or an error if the service or method is not found
|
|
9
|
+
*/
|
|
3
10
|
declare const POST: (req: NextRequest) => Promise<NextResponse<{
|
|
4
11
|
error: string;
|
|
5
12
|
}> | NextResponse<{
|
package/dist/api/rpc.d.ts
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import { NextRequest, NextResponse } from 'next/server';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Handles POST requests for RPC (Remote Procedure Call) functionality.
|
|
5
|
+
* Allows calling methods on registered services with parameters.
|
|
6
|
+
*
|
|
7
|
+
* @param req - The Next.js request object containing the RPC payload
|
|
8
|
+
* @returns A JSON response with the result of the method call, or an error if the service or method is not found
|
|
9
|
+
*/
|
|
3
10
|
declare const POST: (req: NextRequest) => Promise<NextResponse<{
|
|
4
11
|
error: string;
|
|
5
12
|
}> | NextResponse<{
|
package/dist/api/rpc.js
CHANGED
|
@@ -34,6 +34,12 @@ __export(rpc_exports, {
|
|
|
34
34
|
});
|
|
35
35
|
module.exports = __toCommonJS(rpc_exports);
|
|
36
36
|
|
|
37
|
+
// src/logger.ts
|
|
38
|
+
var import_winston = __toESM(require("winston"));
|
|
39
|
+
|
|
40
|
+
// src/transports/matomo.ts
|
|
41
|
+
var import_winston_transport = __toESM(require("winston-transport"));
|
|
42
|
+
|
|
37
43
|
// ../constants/src/index.ts
|
|
38
44
|
var ALL = "*";
|
|
39
45
|
var LOG_LEVELS = {
|
|
@@ -45,58 +51,15 @@ var LOG_LEVELS = {
|
|
|
45
51
|
};
|
|
46
52
|
var DEFAULT_COOKIE_LIMIT = 7 * 24 * 60 * 60 * 1e3;
|
|
47
53
|
|
|
48
|
-
// src/sdk.ts
|
|
49
|
-
var import_next_cookies = require("@c-rex/utils/next-cookies");
|
|
50
|
-
var CrexSDK = class {
|
|
51
|
-
userAuthConfig;
|
|
52
|
-
customerConfig;
|
|
53
|
-
async getConfig() {
|
|
54
|
-
if (!this.customerConfig) {
|
|
55
|
-
this.customerConfig = await (0, import_next_cookies.getConfigs)();
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
async getUserAuthConfig() {
|
|
59
|
-
if (this.userAuthConfig) {
|
|
60
|
-
return this.userAuthConfig;
|
|
61
|
-
}
|
|
62
|
-
await this.getConfig();
|
|
63
|
-
const user = this.customerConfig.OIDC.user;
|
|
64
|
-
if (user.enabled) {
|
|
65
|
-
this.userAuthConfig = {
|
|
66
|
-
providers: [
|
|
67
|
-
{
|
|
68
|
-
id: "crex",
|
|
69
|
-
name: "CREX",
|
|
70
|
-
type: "oauth",
|
|
71
|
-
clientId: user.id,
|
|
72
|
-
wellKnown: user.issuer,
|
|
73
|
-
clientSecret: user.secret,
|
|
74
|
-
authorization: { params: { scope: user.scope } },
|
|
75
|
-
profile(profile) {
|
|
76
|
-
return {
|
|
77
|
-
id: profile.id || "fake Id",
|
|
78
|
-
name: profile.name || "Fake Name",
|
|
79
|
-
email: profile.email || "fake Email",
|
|
80
|
-
image: profile.image || "fake Image"
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
]
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
;
|
|
88
|
-
return this.userAuthConfig;
|
|
89
|
-
}
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
// src/logger.ts
|
|
93
|
-
var import_winston = __toESM(require("winston"));
|
|
94
|
-
|
|
95
54
|
// src/transports/matomo.ts
|
|
96
|
-
var import_winston_transport = __toESM(require("winston-transport"));
|
|
97
55
|
var MatomoTransport = class extends import_winston_transport.default {
|
|
98
56
|
matomoTransport;
|
|
99
57
|
configs;
|
|
58
|
+
/**
|
|
59
|
+
* Creates a new instance of MatomoTransport.
|
|
60
|
+
*
|
|
61
|
+
* @param configs - The application configuration containing logging settings
|
|
62
|
+
*/
|
|
100
63
|
constructor(configs) {
|
|
101
64
|
super({
|
|
102
65
|
level: configs.logs.console.minimumLevel,
|
|
@@ -105,6 +68,12 @@ var MatomoTransport = class extends import_winston_transport.default {
|
|
|
105
68
|
this.matomoTransport = new import_winston_transport.default();
|
|
106
69
|
this.configs = configs;
|
|
107
70
|
}
|
|
71
|
+
/**
|
|
72
|
+
* Logs a message to Matomo if the message category is included in the configured categories.
|
|
73
|
+
*
|
|
74
|
+
* @param info - The log information including level, message, and category
|
|
75
|
+
* @param callback - Callback function to execute after logging
|
|
76
|
+
*/
|
|
108
77
|
log(info, callback) {
|
|
109
78
|
const matomoCategory = this.configs.logs.matomo.categoriesLevel;
|
|
110
79
|
if (matomoCategory.includes(info.category) || matomoCategory.includes(ALL)) {
|
|
@@ -119,6 +88,11 @@ var import_winston_graylog2 = __toESM(require("winston-graylog2"));
|
|
|
119
88
|
var GraylogTransport = class extends import_winston_transport2.default {
|
|
120
89
|
graylogTransport;
|
|
121
90
|
configs;
|
|
91
|
+
/**
|
|
92
|
+
* Creates a new instance of GraylogTransport.
|
|
93
|
+
*
|
|
94
|
+
* @param configs - The application configuration containing logging settings
|
|
95
|
+
*/
|
|
122
96
|
constructor(configs) {
|
|
123
97
|
super({
|
|
124
98
|
level: configs.logs.graylog.minimumLevel,
|
|
@@ -134,6 +108,12 @@ var GraylogTransport = class extends import_winston_transport2.default {
|
|
|
134
108
|
}
|
|
135
109
|
});
|
|
136
110
|
}
|
|
111
|
+
/**
|
|
112
|
+
* Logs a message to Graylog if the message category is included in the configured categories.
|
|
113
|
+
*
|
|
114
|
+
* @param info - The log information including level, message, and category
|
|
115
|
+
* @param callback - Callback function to execute after logging
|
|
116
|
+
*/
|
|
137
117
|
log(info, callback) {
|
|
138
118
|
const graylogCategory = this.configs.logs.graylog.categoriesLevel;
|
|
139
119
|
if (graylogCategory.includes(info.category) || graylogCategory.includes(ALL)) {
|
|
@@ -143,22 +123,46 @@ var GraylogTransport = class extends import_winston_transport2.default {
|
|
|
143
123
|
};
|
|
144
124
|
|
|
145
125
|
// src/logger.ts
|
|
146
|
-
var
|
|
126
|
+
var import_next_cookies = require("@c-rex/utils/next-cookies");
|
|
147
127
|
var CrexLogger = class {
|
|
148
128
|
customerConfig;
|
|
149
129
|
logger;
|
|
130
|
+
/**
|
|
131
|
+
* Initializes the logger instance if it hasn't been initialized yet.
|
|
132
|
+
* Loads customer configuration and creates the logger with appropriate transports.
|
|
133
|
+
*
|
|
134
|
+
* @private
|
|
135
|
+
*/
|
|
150
136
|
async initLogger() {
|
|
151
|
-
|
|
152
|
-
this.customerConfig
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
this.logger
|
|
137
|
+
try {
|
|
138
|
+
if (!this.customerConfig) {
|
|
139
|
+
this.customerConfig = await (0, import_next_cookies.getConfigs)();
|
|
140
|
+
}
|
|
141
|
+
if (!this.logger) {
|
|
142
|
+
this.logger = this.createLogger();
|
|
143
|
+
}
|
|
144
|
+
} catch (error) {
|
|
145
|
+
console.error("Error initializing logger:", error);
|
|
156
146
|
}
|
|
157
147
|
}
|
|
148
|
+
/**
|
|
149
|
+
* Logs a message with the specified level and optional category.
|
|
150
|
+
*
|
|
151
|
+
* @param options - Logging options
|
|
152
|
+
* @param options.level - The log level (error, warn, info, etc.)
|
|
153
|
+
* @param options.message - The message to log
|
|
154
|
+
* @param options.category - Optional category for the log message
|
|
155
|
+
*/
|
|
158
156
|
async log({ level, message, category }) {
|
|
159
157
|
await this.initLogger();
|
|
160
158
|
this.logger.log(level, message, category);
|
|
161
159
|
}
|
|
160
|
+
/**
|
|
161
|
+
* Creates a new Winston logger instance with configured transports.
|
|
162
|
+
*
|
|
163
|
+
* @private
|
|
164
|
+
* @returns A configured Winston logger instance
|
|
165
|
+
*/
|
|
162
166
|
createLogger() {
|
|
163
167
|
return import_winston.default.createLogger({
|
|
164
168
|
levels: LOG_LEVELS,
|
|
@@ -179,11 +183,8 @@ var import_services = require("@c-rex/services");
|
|
|
179
183
|
var import_server = require("next/server");
|
|
180
184
|
var serviceRegistry = {
|
|
181
185
|
InformationUnitsService: import_services.InformationUnitsService,
|
|
182
|
-
DocumentTypesService: import_services.DocumentTypesService,
|
|
183
|
-
DirectoryNodesService: import_services.DirectoryNodesService,
|
|
184
|
-
RenditionsService: import_services.RenditionsService,
|
|
185
186
|
CrexLogger,
|
|
186
|
-
|
|
187
|
+
LanguageService: import_services.LanguageService
|
|
187
188
|
};
|
|
188
189
|
var POST = async (req) => {
|
|
189
190
|
try {
|
|
@@ -200,9 +201,13 @@ var POST = async (req) => {
|
|
|
200
201
|
}
|
|
201
202
|
const result = await handler.call(serviceInstance, params);
|
|
202
203
|
return import_server.NextResponse.json({ data: result });
|
|
203
|
-
} catch (
|
|
204
|
-
|
|
205
|
-
|
|
204
|
+
} catch (error) {
|
|
205
|
+
const logger = new CrexLogger();
|
|
206
|
+
logger.log({
|
|
207
|
+
level: "error",
|
|
208
|
+
message: `RPC.POST error: ${error}`
|
|
209
|
+
});
|
|
210
|
+
return import_server.NextResponse.json({ error: String(error) }, { status: 500 });
|
|
206
211
|
}
|
|
207
212
|
};
|
|
208
213
|
// Annotate the CommonJS export names for ESM import in node:
|
package/dist/api/rpc.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/api/rpc.ts","../../../constants/src/index.ts","../../src/sdk.ts","../../src/logger.ts","../../src/transports/matomo.ts","../../src/transports/graylog.ts"],"sourcesContent":["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","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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAO,IAAM,MAAM;AAeZ,IAAM,aAAa;AAAA,EACtB,UAAU;AAAA,EACV,OAAO;AAAA,EACP,SAAS;AAAA,EACT,MAAM;AAAA,EACN,OAAO;AACX;AA6CO,IAAM,uBAAuB,IAAI,KAAK,KAAK,KAAK;;;ACjEvD,0BAA2B;AAEpB,IAAM,UAAN,MAAc;AAAA,EACV;AAAA,EACA;AAAA,EAEP,MAAc,YAAY;AACtB,QAAI,CAAC,KAAK,gBAAgB;AACtB,WAAK,iBAAiB,UAAM,gCAAW;AAAA,IAC3C;AAAA,EACJ;AAAA,EAEA,MAAa,oBAAoB;AAC7B,QAAI,KAAK,gBAAgB;AACrB,aAAO,KAAK;AAAA,IAChB;AAEA,UAAM,KAAK,UAAU;AAErB,UAAM,OAAO,KAAK,eAAe,KAAK;AACtC,QAAI,KAAK,SAAS;AACd,WAAK,iBAAiB;AAAA,QAClB,WAAW;AAAA,UACP;AAAA,YACI,IAAI;AAAA,YACJ,MAAM;AAAA,YACN,MAAM;AAAA,YACN,UAAU,KAAK;AAAA,YACf,WAAW,KAAK;AAAA,YAChB,cAAc,KAAK;AAAA,YACnB,eAAe,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,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,KAAK;AACV,YAAQ,MAAM,GAAG;AACjB,WAAO,2BAAa,KAAK,EAAE,OAAO,OAAO,GAAG,EAAE,GAAG,EAAE,QAAQ,IAAI,CAAC;AAAA,EACpE;AACJ;","names":["Transport","import_winston_transport","Transport","Graylog2Transport","import_next_cookies","winston"]}
|
|
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 { 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"],"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;AAoDO,IAAM,uBAAuB,IAAI,KAAK,KAAK,KAAK;;;ADhEhD,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,QAAQ;AAAA,MAC5B,QAAQ,QAAQ,KAAK,QAAQ;AAAA,IACjC,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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