@c-rex/core 0.1.2 → 0.1.4
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 +34 -6
- package/dist/api/cookies.js.map +1 -1
- package/dist/api/cookies.mjs +32 -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 +75 -65
- package/dist/api/rpc.js.map +1 -1
- package/dist/api/rpc.mjs +76 -66
- 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 +44 -2
- package/dist/index.d.ts +44 -2
- package/dist/index.js +224 -86
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +224 -86
- 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 +60 -9
- package/dist/logger.js.map +1 -1
- package/dist/logger.mjs +60 -9
- package/dist/logger.mjs.map +1 -1
- package/package.json +8 -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,47 @@ 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 = await (0, import_headers.cookies)().get(key);
|
|
38
|
+
if (!value) return import_server.NextResponse.json({ error: "Missing value" }, { status: 404 });
|
|
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
|
+
const response = import_server.NextResponse.json({ success: true });
|
|
51
|
+
response.cookies.set({
|
|
52
|
+
name: key,
|
|
53
|
+
value,
|
|
54
|
+
secure: process.env.NODE_ENV === "production",
|
|
55
|
+
sameSite: "lax",
|
|
56
|
+
path: "/",
|
|
57
|
+
maxAge
|
|
58
|
+
});
|
|
59
|
+
return response;
|
|
33
60
|
};
|
|
34
61
|
// Annotate the CommonJS export names for ESM import in node:
|
|
35
62
|
0 && (module.exports = {
|
|
36
|
-
|
|
63
|
+
getMethod,
|
|
64
|
+
postMethod
|
|
37
65
|
});
|
|
38
66
|
//# 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 = await cookies().get(key);\n if (!value) return NextResponse.json({ error: 'Missing value' }, { status: 404 });\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 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 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\";\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;;;ACyEjB,IAAM,uBAAuB,IAAI,KAAK,KAAK,KAAK;;;ADjEhD,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,QAAQ,UAAM,wBAAQ,EAAE,IAAI,GAAG;AACrC,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,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
CHANGED
|
@@ -1,13 +1,40 @@
|
|
|
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 = await cookies().get(key);
|
|
13
|
+
if (!value) return NextResponse.json({ error: "Missing value" }, { status: 404 });
|
|
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
|
+
const response = NextResponse.json({ success: true });
|
|
26
|
+
response.cookies.set({
|
|
27
|
+
name: key,
|
|
28
|
+
value,
|
|
29
|
+
secure: process.env.NODE_ENV === "production",
|
|
30
|
+
sameSite: "lax",
|
|
31
|
+
path: "/",
|
|
32
|
+
maxAge
|
|
33
|
+
});
|
|
34
|
+
return response;
|
|
9
35
|
};
|
|
10
36
|
export {
|
|
11
|
-
|
|
37
|
+
getMethod,
|
|
38
|
+
postMethod
|
|
12
39
|
};
|
|
13
40
|
//# 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 = await cookies().get(key);\n if (!value) return NextResponse.json({ error: 'Missing value' }, { status: 404 });\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 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 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\";\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;;;ACyEjB,IAAM,uBAAuB,IAAI,KAAK,KAAK,KAAK;;;ADjEhD,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,MAAM,QAAQ,EAAE,IAAI,GAAG;AACrC,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,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.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,66 +51,29 @@ 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
|
-
level: configs.logs.
|
|
103
|
-
silent: configs.logs.
|
|
65
|
+
level: configs.logs.matomo.minimumLevel,
|
|
66
|
+
silent: configs.logs.matomo.silent
|
|
104
67
|
});
|
|
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,
|
|
@@ -126,14 +100,25 @@ var GraylogTransport = class extends import_winston_transport2.default {
|
|
|
126
100
|
});
|
|
127
101
|
this.configs = configs;
|
|
128
102
|
this.graylogTransport = new import_winston_graylog2.default({
|
|
129
|
-
name: "
|
|
103
|
+
name: "crex.net.documentation",
|
|
104
|
+
//name: "crex.net.blog",
|
|
130
105
|
silent: false,
|
|
131
106
|
handleExceptions: false,
|
|
132
107
|
graylog: {
|
|
133
|
-
servers: [
|
|
108
|
+
servers: [
|
|
109
|
+
{ host: "localhost", port: 12201 },
|
|
110
|
+
{ host: "https://log.c-rex.net", port: 12202 }
|
|
111
|
+
//TODO: check the URL => https://log.c-rex.net:12202/gelf" GELF??
|
|
112
|
+
]
|
|
134
113
|
}
|
|
135
114
|
});
|
|
136
115
|
}
|
|
116
|
+
/**
|
|
117
|
+
* Logs a message to Graylog if the message category is included in the configured categories.
|
|
118
|
+
*
|
|
119
|
+
* @param info - The log information including level, message, and category
|
|
120
|
+
* @param callback - Callback function to execute after logging
|
|
121
|
+
*/
|
|
137
122
|
log(info, callback) {
|
|
138
123
|
const graylogCategory = this.configs.logs.graylog.categoriesLevel;
|
|
139
124
|
if (graylogCategory.includes(info.category) || graylogCategory.includes(ALL)) {
|
|
@@ -143,22 +128,46 @@ var GraylogTransport = class extends import_winston_transport2.default {
|
|
|
143
128
|
};
|
|
144
129
|
|
|
145
130
|
// src/logger.ts
|
|
146
|
-
var
|
|
131
|
+
var import_next_cookies = require("@c-rex/utils/next-cookies");
|
|
147
132
|
var CrexLogger = class {
|
|
148
133
|
customerConfig;
|
|
149
134
|
logger;
|
|
135
|
+
/**
|
|
136
|
+
* Initializes the logger instance if it hasn't been initialized yet.
|
|
137
|
+
* Loads customer configuration and creates the logger with appropriate transports.
|
|
138
|
+
*
|
|
139
|
+
* @private
|
|
140
|
+
*/
|
|
150
141
|
async initLogger() {
|
|
151
|
-
|
|
152
|
-
this.customerConfig
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
this.logger
|
|
142
|
+
try {
|
|
143
|
+
if (!this.customerConfig) {
|
|
144
|
+
this.customerConfig = await (0, import_next_cookies.getConfigs)();
|
|
145
|
+
}
|
|
146
|
+
if (!this.logger) {
|
|
147
|
+
this.logger = this.createLogger();
|
|
148
|
+
}
|
|
149
|
+
} catch (error) {
|
|
150
|
+
console.error("Error initializing logger:", error);
|
|
156
151
|
}
|
|
157
152
|
}
|
|
153
|
+
/**
|
|
154
|
+
* Logs a message with the specified level and optional category.
|
|
155
|
+
*
|
|
156
|
+
* @param options - Logging options
|
|
157
|
+
* @param options.level - The log level (error, warn, info, etc.)
|
|
158
|
+
* @param options.message - The message to log
|
|
159
|
+
* @param options.category - Optional category for the log message
|
|
160
|
+
*/
|
|
158
161
|
async log({ level, message, category }) {
|
|
159
162
|
await this.initLogger();
|
|
160
163
|
this.logger.log(level, message, category);
|
|
161
164
|
}
|
|
165
|
+
/**
|
|
166
|
+
* Creates a new Winston logger instance with configured transports.
|
|
167
|
+
*
|
|
168
|
+
* @private
|
|
169
|
+
* @returns A configured Winston logger instance
|
|
170
|
+
*/
|
|
162
171
|
createLogger() {
|
|
163
172
|
return import_winston.default.createLogger({
|
|
164
173
|
levels: LOG_LEVELS,
|
|
@@ -179,11 +188,8 @@ var import_services = require("@c-rex/services");
|
|
|
179
188
|
var import_server = require("next/server");
|
|
180
189
|
var serviceRegistry = {
|
|
181
190
|
InformationUnitsService: import_services.InformationUnitsService,
|
|
182
|
-
DocumentTypesService: import_services.DocumentTypesService,
|
|
183
|
-
DirectoryNodesService: import_services.DirectoryNodesService,
|
|
184
|
-
RenditionsService: import_services.RenditionsService,
|
|
185
191
|
CrexLogger,
|
|
186
|
-
|
|
192
|
+
LanguageService: import_services.LanguageService
|
|
187
193
|
};
|
|
188
194
|
var POST = async (req) => {
|
|
189
195
|
try {
|
|
@@ -200,9 +206,13 @@ var POST = async (req) => {
|
|
|
200
206
|
}
|
|
201
207
|
const result = await handler.call(serviceInstance, params);
|
|
202
208
|
return import_server.NextResponse.json({ data: result });
|
|
203
|
-
} catch (
|
|
204
|
-
|
|
205
|
-
|
|
209
|
+
} catch (error) {
|
|
210
|
+
const logger = new CrexLogger();
|
|
211
|
+
logger.log({
|
|
212
|
+
level: "error",
|
|
213
|
+
message: `RPC.POST error: ${error}`
|
|
214
|
+
});
|
|
215
|
+
return import_server.NextResponse.json({ error: String(error) }, { status: 500 });
|
|
206
216
|
}
|
|
207
217
|
};
|
|
208
218
|
// 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;AAA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B,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 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 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\";\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 private configs: ConfigInterface\n\n /**\n * Creates a new instance of GraylogTransport.\n * \n * @param configs - The application configuration containing logging settings\n */\n constructor(configs: ConfigInterface) {\n super({\n level: configs.logs.graylog.minimumLevel,\n silent: configs.logs.graylog.silent,\n });\n\n this.configs = configs;\n this.graylogTransport = new Graylog2Transport({\n name: \"crex.net.documentation\",\n //name: \"crex.net.blog\",\n silent: false,\n handleExceptions: false,\n graylog: {\n servers: [\n { host: \"localhost\", port: 12201 },\n { host: \"https://log.c-rex.net\", port: 12202 }\n\n //TODO: check the URL => https://log.c-rex.net:12202/gelf\" GELF??\n ],\n },\n });\n }\n\n /**\n * Logs a message to Graylog if the message category is included in the configured categories.\n * \n * @param info - The log information including level, message, and category\n * @param callback - Callback function to execute after logging\n */\n log(\n info: { level: LogLevelType, message: string, category: LogCategoriesType },\n callback: () => void,\n ): void {\n const graylogCategory = this.configs.logs.graylog.categoriesLevel\n\n if (graylogCategory.includes(info.category) || graylogCategory.includes(ALL)) {\n this.graylogTransport.log(info, callback);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