@c-rex/core 0.1.11 → 0.1.12
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.js.map +1 -1
- package/dist/api/cookies.mjs.map +1 -1
- package/dist/api/rpc.js +11 -3
- package/dist/api/rpc.js.map +1 -1
- package/dist/api/rpc.mjs +11 -3
- package/dist/api/rpc.mjs.map +1 -1
- package/dist/api/token.js +32 -11
- package/dist/api/token.js.map +1 -1
- package/dist/api/token.mjs +32 -11
- package/dist/api/token.mjs.map +1 -1
- package/dist/index.d.mts +15 -4
- package/dist/index.d.ts +15 -4
- package/dist/index.js +83 -75
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +79 -74
- package/dist/index.mjs.map +1 -1
- package/dist/logger.js +11 -3
- package/dist/logger.js.map +1 -1
- package/dist/logger.mjs +11 -3
- package/dist/logger.mjs.map +1 -1
- package/package.json +1 -1
package/dist/api/cookies.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/api/cookies.ts","../../../constants/src/index.ts"],"sourcesContent":["import { NextRequest, NextResponse } from 'next/server';\nimport { cookies } from 'next/headers';\nimport { DEFAULT_COOKIE_LIMIT } from '@c-rex/constants';\n\n/**\n * Retrieves a cookie value by key from the request\n * @param {NextRequest} req - The Next.js request object\n * @returns {Promise<NextResponse>} JSON response containing the cookie key-value pair or error\n */\nexport const getMethod = async (req: NextRequest): Promise<NextResponse> => {\n const key = req.nextUrl.searchParams.get('key');\n if (!key) return NextResponse.json({ error: 'Missing key' }, { status: 400 });\n\n const value = cookies().get(key);\n const response = NextResponse.json({ key, value: value?.value || null });\n\n return response;\n}\n\n/**\n * Sets a cookie with the specified key, value and options\n * @param {NextRequest} req - The Next.js request object\n * @returns {Promise<NextResponse>} JSON response indicating success or error\n * @throws {Error} If key or value are missing in the request body\n */\nexport const postMethod = async (req: NextRequest): Promise<NextResponse> => {\n const { key, value, maxAge: maxAgeAux } = await req.json();\n let maxAge = maxAgeAux;\n\n if (!key || value === undefined) {\n return NextResponse.json({ error: 'Missing key or value' }, { status: 400 });\n }\n\n if (maxAge === undefined) {\n maxAge = DEFAULT_COOKIE_LIMIT\n }\n\n const response = NextResponse.json({ success: true });\n\n response.cookies.set({\n name: key,\n value: value,\n secure: process.env.NODE_ENV === 'production',\n sameSite: 'lax',\n path: '/',\n maxAge: maxAge,\n });\n\n return response\n};","export const ALL = \"*\"\n\nexport const LOG_CATEGORIES = [\n \"NoLicense\",\n \"Scenario\",\n \"Favorites\",\n \"Subscription\",\n \"Share\",\n \"Document\",\n \"Search\",\n \"History\",\n \"Notification\",\n \"UserProfile\",\n] as const;\n\nexport const LOG_LEVELS = {\n critical: 2,\n error: 3,\n warning: 4,\n info: 6,\n debug: 7,\n} as const;\n\nexport const RESULT_VIEW_STYLES = [\n \"cards\",\n \"table\",\n] as const;\n\nexport const API = {\n MAX_RETRY: 3,\n API_TIMEOUT: 10000,\n RETRY_DELAY: 500,\n API_HEADERS: {\n \"content-Type\": \"application/json\",\n },\n};\n\nexport const SDK_CONFIG_KEY = \"crex-sdk-config\";\n\nexport const CONTENT_LANG_KEY = \"CONTENT_LANG_KEY\";\n\nexport const AVAILABLE_CONTENT_LANG_KEY = \"AVAILABLE_CONTENT_LANG_KEY\";\n\nexport const UI_LANG_KEY = \"UI_LANG_KEY\";\n\nexport const FLAGS_BY_LANG = {\n \"en\": \"US\",\n \"de\": \"DE\",\n};\n\nexport const DEFAULT_LANG = \"en-US\";\n\nexport const EN_LANG = \"en\";\n\nexport const UI_LANG_OPTIONS = [\"en-us\", \"de-de\"];\n\nexport const TOPICS_TYPE_AND_LINK = \"topics\";\nexport const BLOG_TYPE_AND_LINK = \"blog\";\nexport const DOCUMENTS_TYPE_AND_LINK = \"documents\";\n\nexport const TOPIC = \"TOPIC\";\nexport const DOCUMENT = \"DOCUMENT\";\nexport const PACKAGE = \"PACKAGE\";\nexport const FRAGMENT = \"FRAGMENT\";\n\nexport const RESULT_TYPES = {\n TOPIC: TOPIC,\n DOCUMENT: DOCUMENT,\n PACKAGE: PACKAGE,\n FRAGMENT: FRAGMENT\n} as const;\n\nexport const FILES_EXTENSIONS = {\n PDF: \"application/pdf\",\n HTML: \"text/html\",\n} as const;\n\nexport const DEFAULT_COOKIE_LIMIT = 30 * 24 * 60 * 60 * 1000; // 30 days in milliseconds\n\nexport const ICONS_BY_FILE_EXTENSION = {\n \"application/pdf\": \"FaFilePdf\",\n} as const;\n\nexport const DEFAULT_ICON = \"file\";\n\nexport const CREX_TOKEN_HEADER_KEY = \"crex-token\";\n\nexport const WILD_CARD_OPTIONS = {\n BOTH: \"BOTH\",\n END: \"END\",\n START: \"START\",\n NONE: \"NONE\",\n} as const;\n\nexport const OPERATOR_OPTIONS = {\n AND: \"AND\",\n OR: \"OR\",\n} as const;\n\nexport const ARTICLE_PAGE_LAYOUT = {\n BLOG: \"BLOG\",\n DOCUMENT: \"DOCUMENT\",\n} as const;\n\nexport const DEVICE_OPTIONS = {\n MOBILE: \"mobile\",\n TABLET: \"tablet\",\n DESKTOP: \"desktop\",\n}\nexport const BREAKPOINTS = {\n sm: 640,\n md: 768,\n lg: 1024,\n xl: 1280,\n \"2xl\": 1536,\n};"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA0C;AAC1C,qBAAwB;;;
|
|
1
|
+
{"version":3,"sources":["../../src/api/cookies.ts","../../../constants/src/index.ts"],"sourcesContent":["import { NextRequest, NextResponse } from 'next/server';\nimport { cookies } from 'next/headers';\nimport { DEFAULT_COOKIE_LIMIT } from '@c-rex/constants';\n\n/**\n * Retrieves a cookie value by key from the request\n * @param {NextRequest} req - The Next.js request object\n * @returns {Promise<NextResponse>} JSON response containing the cookie key-value pair or error\n */\nexport const getMethod = async (req: NextRequest): Promise<NextResponse> => {\n const key = req.nextUrl.searchParams.get('key');\n if (!key) return NextResponse.json({ error: 'Missing key' }, { status: 400 });\n\n const value = cookies().get(key);\n const response = NextResponse.json({ key, value: value?.value || null });\n\n return response;\n}\n\n/**\n * Sets a cookie with the specified key, value and options\n * @param {NextRequest} req - The Next.js request object\n * @returns {Promise<NextResponse>} JSON response indicating success or error\n * @throws {Error} If key or value are missing in the request body\n */\nexport const postMethod = async (req: NextRequest): Promise<NextResponse> => {\n const { key, value, maxAge: maxAgeAux } = await req.json();\n let maxAge = maxAgeAux;\n\n if (!key || value === undefined) {\n return NextResponse.json({ error: 'Missing key or value' }, { status: 400 });\n }\n\n if (maxAge === undefined) {\n maxAge = DEFAULT_COOKIE_LIMIT\n }\n\n const response = NextResponse.json({ success: true });\n\n response.cookies.set({\n name: key,\n value: value,\n secure: process.env.NODE_ENV === 'production',\n sameSite: 'lax',\n path: '/',\n maxAge: maxAge,\n });\n\n return response\n};","export const ALL = \"*\"\n\nexport const LOG_CATEGORIES = [\n \"NoLicense\",\n \"Scenario\",\n \"Favorites\",\n \"Subscription\",\n \"Share\",\n \"Document\",\n \"Search\",\n \"History\",\n \"Notification\",\n \"UserProfile\",\n] as const;\n\nexport const LOG_LEVELS = {\n critical: 2,\n error: 3,\n warning: 4,\n info: 6,\n debug: 7,\n} as const;\n\nexport const RESULT_VIEW_STYLES = [\n \"cards\",\n \"table\",\n \"table-with-images\",\n] as const;\n\nexport const API = {\n MAX_RETRY: 3,\n API_TIMEOUT: 10000,\n RETRY_DELAY: 500,\n API_HEADERS: {\n \"content-Type\": \"application/json\",\n },\n};\n\nexport const SDK_CONFIG_KEY = \"crex-sdk-config\";\n\nexport const CONTENT_LANG_KEY = \"CONTENT_LANG_KEY\";\n\nexport const AVAILABLE_CONTENT_LANG_KEY = \"AVAILABLE_CONTENT_LANG_KEY\";\n\nexport const UI_LANG_KEY = \"UI_LANG_KEY\";\n\nexport const FLAGS_BY_LANG = {\n \"en\": \"US\",\n \"de\": \"DE\",\n};\n\nexport const DEFAULT_LANG = \"en-US\";\n\nexport const EN_LANG = \"en\";\n\nexport const UI_LANG_OPTIONS = [\"en-us\", \"de-de\"];\n\nexport const TOPICS_TYPE_AND_LINK = \"topics\";\nexport const BLOG_TYPE_AND_LINK = \"blog\";\nexport const DOCUMENTS_TYPE_AND_LINK = \"documents\";\n\nexport const TOPIC = \"TOPIC\";\nexport const DOCUMENT = \"DOCUMENT\";\nexport const PACKAGE = \"PACKAGE\";\nexport const FRAGMENT = \"FRAGMENT\";\n\nexport const RESULT_TYPES = {\n TOPIC: TOPIC,\n DOCUMENT: DOCUMENT,\n PACKAGE: PACKAGE,\n FRAGMENT: FRAGMENT\n} as const;\n\nexport const FILES_EXTENSIONS = {\n PDF: \"application/pdf\",\n HTML: \"text/html\",\n} as const;\n\nexport const DEFAULT_COOKIE_LIMIT = 30 * 24 * 60 * 60 * 1000; // 30 days in milliseconds\n\nexport const ICONS_BY_FILE_EXTENSION = {\n \"application/pdf\": \"FaFilePdf\",\n} as const;\n\nexport const DEFAULT_ICON = \"file\";\n\nexport const CREX_TOKEN_HEADER_KEY = \"crex-token\";\n\nexport const WILD_CARD_OPTIONS = {\n BOTH: \"BOTH\",\n END: \"END\",\n START: \"START\",\n NONE: \"NONE\",\n} as const;\n\nexport const OPERATOR_OPTIONS = {\n AND: \"AND\",\n OR: \"OR\",\n} as const;\n\nexport const ARTICLE_PAGE_LAYOUT = {\n BLOG: \"BLOG\",\n DOCUMENT: \"DOCUMENT\",\n} as const;\n\nexport const DEVICE_OPTIONS = {\n MOBILE: \"mobile\",\n TABLET: \"tablet\",\n DESKTOP: \"desktop\",\n}\nexport const BREAKPOINTS = {\n sm: 640,\n md: 768,\n lg: 1024,\n xl: 1280,\n \"2xl\": 1536,\n};"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA0C;AAC1C,qBAAwB;;;AC6EjB,IAAM,uBAAuB,KAAK,KAAK,KAAK,KAAK;;;ADrEjD,IAAM,YAAY,OAAO,QAA4C;AACxE,QAAM,MAAM,IAAI,QAAQ,aAAa,IAAI,KAAK;AAC9C,MAAI,CAAC,IAAK,QAAO,2BAAa,KAAK,EAAE,OAAO,cAAc,GAAG,EAAE,QAAQ,IAAI,CAAC;AAE5E,QAAM,YAAQ,wBAAQ,EAAE,IAAI,GAAG;AAC/B,QAAM,WAAW,2BAAa,KAAK,EAAE,KAAK,OAAO,OAAO,SAAS,KAAK,CAAC;AAEvE,SAAO;AACX;AAQO,IAAM,aAAa,OAAO,QAA4C;AACzE,QAAM,EAAE,KAAK,OAAO,QAAQ,UAAU,IAAI,MAAM,IAAI,KAAK;AACzD,MAAI,SAAS;AAEb,MAAI,CAAC,OAAO,UAAU,QAAW;AAC7B,WAAO,2BAAa,KAAK,EAAE,OAAO,uBAAuB,GAAG,EAAE,QAAQ,IAAI,CAAC;AAAA,EAC/E;AAEA,MAAI,WAAW,QAAW;AACtB,aAAS;AAAA,EACb;AAEA,QAAM,WAAW,2BAAa,KAAK,EAAE,SAAS,KAAK,CAAC;AAEpD,WAAS,QAAQ,IAAI;AAAA,IACjB,MAAM;AAAA,IACN;AAAA,IACA,QAAQ,QAAQ,IAAI,aAAa;AAAA,IACjC,UAAU;AAAA,IACV,MAAM;AAAA,IACN;AAAA,EACJ,CAAC;AAED,SAAO;AACX;","names":[]}
|
package/dist/api/cookies.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/api/cookies.ts","../../../constants/src/index.ts"],"sourcesContent":["import { NextRequest, NextResponse } from 'next/server';\nimport { cookies } from 'next/headers';\nimport { DEFAULT_COOKIE_LIMIT } from '@c-rex/constants';\n\n/**\n * Retrieves a cookie value by key from the request\n * @param {NextRequest} req - The Next.js request object\n * @returns {Promise<NextResponse>} JSON response containing the cookie key-value pair or error\n */\nexport const getMethod = async (req: NextRequest): Promise<NextResponse> => {\n const key = req.nextUrl.searchParams.get('key');\n if (!key) return NextResponse.json({ error: 'Missing key' }, { status: 400 });\n\n const value = cookies().get(key);\n const response = NextResponse.json({ key, value: value?.value || null });\n\n return response;\n}\n\n/**\n * Sets a cookie with the specified key, value and options\n * @param {NextRequest} req - The Next.js request object\n * @returns {Promise<NextResponse>} JSON response indicating success or error\n * @throws {Error} If key or value are missing in the request body\n */\nexport const postMethod = async (req: NextRequest): Promise<NextResponse> => {\n const { key, value, maxAge: maxAgeAux } = await req.json();\n let maxAge = maxAgeAux;\n\n if (!key || value === undefined) {\n return NextResponse.json({ error: 'Missing key or value' }, { status: 400 });\n }\n\n if (maxAge === undefined) {\n maxAge = DEFAULT_COOKIE_LIMIT\n }\n\n const response = NextResponse.json({ success: true });\n\n response.cookies.set({\n name: key,\n value: value,\n secure: process.env.NODE_ENV === 'production',\n sameSite: 'lax',\n path: '/',\n maxAge: maxAge,\n });\n\n return response\n};","export const ALL = \"*\"\n\nexport const LOG_CATEGORIES = [\n \"NoLicense\",\n \"Scenario\",\n \"Favorites\",\n \"Subscription\",\n \"Share\",\n \"Document\",\n \"Search\",\n \"History\",\n \"Notification\",\n \"UserProfile\",\n] as const;\n\nexport const LOG_LEVELS = {\n critical: 2,\n error: 3,\n warning: 4,\n info: 6,\n debug: 7,\n} as const;\n\nexport const RESULT_VIEW_STYLES = [\n \"cards\",\n \"table\",\n] as const;\n\nexport const API = {\n MAX_RETRY: 3,\n API_TIMEOUT: 10000,\n RETRY_DELAY: 500,\n API_HEADERS: {\n \"content-Type\": \"application/json\",\n },\n};\n\nexport const SDK_CONFIG_KEY = \"crex-sdk-config\";\n\nexport const CONTENT_LANG_KEY = \"CONTENT_LANG_KEY\";\n\nexport const AVAILABLE_CONTENT_LANG_KEY = \"AVAILABLE_CONTENT_LANG_KEY\";\n\nexport const UI_LANG_KEY = \"UI_LANG_KEY\";\n\nexport const FLAGS_BY_LANG = {\n \"en\": \"US\",\n \"de\": \"DE\",\n};\n\nexport const DEFAULT_LANG = \"en-US\";\n\nexport const EN_LANG = \"en\";\n\nexport const UI_LANG_OPTIONS = [\"en-us\", \"de-de\"];\n\nexport const TOPICS_TYPE_AND_LINK = \"topics\";\nexport const BLOG_TYPE_AND_LINK = \"blog\";\nexport const DOCUMENTS_TYPE_AND_LINK = \"documents\";\n\nexport const TOPIC = \"TOPIC\";\nexport const DOCUMENT = \"DOCUMENT\";\nexport const PACKAGE = \"PACKAGE\";\nexport const FRAGMENT = \"FRAGMENT\";\n\nexport const RESULT_TYPES = {\n TOPIC: TOPIC,\n DOCUMENT: DOCUMENT,\n PACKAGE: PACKAGE,\n FRAGMENT: FRAGMENT\n} as const;\n\nexport const FILES_EXTENSIONS = {\n PDF: \"application/pdf\",\n HTML: \"text/html\",\n} as const;\n\nexport const DEFAULT_COOKIE_LIMIT = 30 * 24 * 60 * 60 * 1000; // 30 days in milliseconds\n\nexport const ICONS_BY_FILE_EXTENSION = {\n \"application/pdf\": \"FaFilePdf\",\n} as const;\n\nexport const DEFAULT_ICON = \"file\";\n\nexport const CREX_TOKEN_HEADER_KEY = \"crex-token\";\n\nexport const WILD_CARD_OPTIONS = {\n BOTH: \"BOTH\",\n END: \"END\",\n START: \"START\",\n NONE: \"NONE\",\n} as const;\n\nexport const OPERATOR_OPTIONS = {\n AND: \"AND\",\n OR: \"OR\",\n} as const;\n\nexport const ARTICLE_PAGE_LAYOUT = {\n BLOG: \"BLOG\",\n DOCUMENT: \"DOCUMENT\",\n} as const;\n\nexport const DEVICE_OPTIONS = {\n MOBILE: \"mobile\",\n TABLET: \"tablet\",\n DESKTOP: \"desktop\",\n}\nexport const BREAKPOINTS = {\n sm: 640,\n md: 768,\n lg: 1024,\n xl: 1280,\n \"2xl\": 1536,\n};"],"mappings":";AAAA,SAAsB,oBAAoB;AAC1C,SAAS,eAAe;;;
|
|
1
|
+
{"version":3,"sources":["../../src/api/cookies.ts","../../../constants/src/index.ts"],"sourcesContent":["import { NextRequest, NextResponse } from 'next/server';\nimport { cookies } from 'next/headers';\nimport { DEFAULT_COOKIE_LIMIT } from '@c-rex/constants';\n\n/**\n * Retrieves a cookie value by key from the request\n * @param {NextRequest} req - The Next.js request object\n * @returns {Promise<NextResponse>} JSON response containing the cookie key-value pair or error\n */\nexport const getMethod = async (req: NextRequest): Promise<NextResponse> => {\n const key = req.nextUrl.searchParams.get('key');\n if (!key) return NextResponse.json({ error: 'Missing key' }, { status: 400 });\n\n const value = cookies().get(key);\n const response = NextResponse.json({ key, value: value?.value || null });\n\n return response;\n}\n\n/**\n * Sets a cookie with the specified key, value and options\n * @param {NextRequest} req - The Next.js request object\n * @returns {Promise<NextResponse>} JSON response indicating success or error\n * @throws {Error} If key or value are missing in the request body\n */\nexport const postMethod = async (req: NextRequest): Promise<NextResponse> => {\n const { key, value, maxAge: maxAgeAux } = await req.json();\n let maxAge = maxAgeAux;\n\n if (!key || value === undefined) {\n return NextResponse.json({ error: 'Missing key or value' }, { status: 400 });\n }\n\n if (maxAge === undefined) {\n maxAge = DEFAULT_COOKIE_LIMIT\n }\n\n const response = NextResponse.json({ success: true });\n\n response.cookies.set({\n name: key,\n value: value,\n secure: process.env.NODE_ENV === 'production',\n sameSite: 'lax',\n path: '/',\n maxAge: maxAge,\n });\n\n return response\n};","export const ALL = \"*\"\n\nexport const LOG_CATEGORIES = [\n \"NoLicense\",\n \"Scenario\",\n \"Favorites\",\n \"Subscription\",\n \"Share\",\n \"Document\",\n \"Search\",\n \"History\",\n \"Notification\",\n \"UserProfile\",\n] as const;\n\nexport const LOG_LEVELS = {\n critical: 2,\n error: 3,\n warning: 4,\n info: 6,\n debug: 7,\n} as const;\n\nexport const RESULT_VIEW_STYLES = [\n \"cards\",\n \"table\",\n \"table-with-images\",\n] as const;\n\nexport const API = {\n MAX_RETRY: 3,\n API_TIMEOUT: 10000,\n RETRY_DELAY: 500,\n API_HEADERS: {\n \"content-Type\": \"application/json\",\n },\n};\n\nexport const SDK_CONFIG_KEY = \"crex-sdk-config\";\n\nexport const CONTENT_LANG_KEY = \"CONTENT_LANG_KEY\";\n\nexport const AVAILABLE_CONTENT_LANG_KEY = \"AVAILABLE_CONTENT_LANG_KEY\";\n\nexport const UI_LANG_KEY = \"UI_LANG_KEY\";\n\nexport const FLAGS_BY_LANG = {\n \"en\": \"US\",\n \"de\": \"DE\",\n};\n\nexport const DEFAULT_LANG = \"en-US\";\n\nexport const EN_LANG = \"en\";\n\nexport const UI_LANG_OPTIONS = [\"en-us\", \"de-de\"];\n\nexport const TOPICS_TYPE_AND_LINK = \"topics\";\nexport const BLOG_TYPE_AND_LINK = \"blog\";\nexport const DOCUMENTS_TYPE_AND_LINK = \"documents\";\n\nexport const TOPIC = \"TOPIC\";\nexport const DOCUMENT = \"DOCUMENT\";\nexport const PACKAGE = \"PACKAGE\";\nexport const FRAGMENT = \"FRAGMENT\";\n\nexport const RESULT_TYPES = {\n TOPIC: TOPIC,\n DOCUMENT: DOCUMENT,\n PACKAGE: PACKAGE,\n FRAGMENT: FRAGMENT\n} as const;\n\nexport const FILES_EXTENSIONS = {\n PDF: \"application/pdf\",\n HTML: \"text/html\",\n} as const;\n\nexport const DEFAULT_COOKIE_LIMIT = 30 * 24 * 60 * 60 * 1000; // 30 days in milliseconds\n\nexport const ICONS_BY_FILE_EXTENSION = {\n \"application/pdf\": \"FaFilePdf\",\n} as const;\n\nexport const DEFAULT_ICON = \"file\";\n\nexport const CREX_TOKEN_HEADER_KEY = \"crex-token\";\n\nexport const WILD_CARD_OPTIONS = {\n BOTH: \"BOTH\",\n END: \"END\",\n START: \"START\",\n NONE: \"NONE\",\n} as const;\n\nexport const OPERATOR_OPTIONS = {\n AND: \"AND\",\n OR: \"OR\",\n} as const;\n\nexport const ARTICLE_PAGE_LAYOUT = {\n BLOG: \"BLOG\",\n DOCUMENT: \"DOCUMENT\",\n} as const;\n\nexport const DEVICE_OPTIONS = {\n MOBILE: \"mobile\",\n TABLET: \"tablet\",\n DESKTOP: \"desktop\",\n}\nexport const BREAKPOINTS = {\n sm: 640,\n md: 768,\n lg: 1024,\n xl: 1280,\n \"2xl\": 1536,\n};"],"mappings":";AAAA,SAAsB,oBAAoB;AAC1C,SAAS,eAAe;;;AC6EjB,IAAM,uBAAuB,KAAK,KAAK,KAAK,KAAK;;;ADrEjD,IAAM,YAAY,OAAO,QAA4C;AACxE,QAAM,MAAM,IAAI,QAAQ,aAAa,IAAI,KAAK;AAC9C,MAAI,CAAC,IAAK,QAAO,aAAa,KAAK,EAAE,OAAO,cAAc,GAAG,EAAE,QAAQ,IAAI,CAAC;AAE5E,QAAM,QAAQ,QAAQ,EAAE,IAAI,GAAG;AAC/B,QAAM,WAAW,aAAa,KAAK,EAAE,KAAK,OAAO,OAAO,SAAS,KAAK,CAAC;AAEvE,SAAO;AACX;AAQO,IAAM,aAAa,OAAO,QAA4C;AACzE,QAAM,EAAE,KAAK,OAAO,QAAQ,UAAU,IAAI,MAAM,IAAI,KAAK;AACzD,MAAI,SAAS;AAEb,MAAI,CAAC,OAAO,UAAU,QAAW;AAC7B,WAAO,aAAa,KAAK,EAAE,OAAO,uBAAuB,GAAG,EAAE,QAAQ,IAAI,CAAC;AAAA,EAC/E;AAEA,MAAI,WAAW,QAAW;AACtB,aAAS;AAAA,EACb;AAEA,QAAM,WAAW,aAAa,KAAK,EAAE,SAAS,KAAK,CAAC;AAEpD,WAAS,QAAQ,IAAI;AAAA,IACjB,MAAM;AAAA,IACN;AAAA,IACA,QAAQ,QAAQ,IAAI,aAAa;AAAA,IACjC,UAAU;AAAA,IACV,MAAM;AAAA,IACN;AAAA,EACJ,CAAC;AAED,SAAO;AACX;","names":[]}
|
package/dist/api/rpc.js
CHANGED
|
@@ -128,8 +128,16 @@ var GraylogTransport = class extends import_winston_transport2.default {
|
|
|
128
128
|
}
|
|
129
129
|
};
|
|
130
130
|
|
|
131
|
+
// src/config.ts
|
|
132
|
+
var import_headers = require("next/headers");
|
|
133
|
+
function getServerConfig() {
|
|
134
|
+
if (!global.__GLOBAL_CONFIG__) {
|
|
135
|
+
throw new Error("Server config not initialized");
|
|
136
|
+
}
|
|
137
|
+
return global.__GLOBAL_CONFIG__;
|
|
138
|
+
}
|
|
139
|
+
|
|
131
140
|
// src/logger.ts
|
|
132
|
-
var import_next_cookies = require("@c-rex/utils/next-cookies");
|
|
133
141
|
var CrexLogger = class {
|
|
134
142
|
customerConfig;
|
|
135
143
|
logger;
|
|
@@ -142,13 +150,13 @@ var CrexLogger = class {
|
|
|
142
150
|
async initLogger() {
|
|
143
151
|
try {
|
|
144
152
|
if (!this.customerConfig) {
|
|
145
|
-
this.customerConfig =
|
|
153
|
+
this.customerConfig = getServerConfig();
|
|
146
154
|
}
|
|
147
155
|
if (!this.logger) {
|
|
148
156
|
this.logger = this.createLogger();
|
|
149
157
|
}
|
|
150
158
|
} catch (error) {
|
|
151
|
-
console.
|
|
159
|
+
console.log("Error initializing logger:", error);
|
|
152
160
|
}
|
|
153
161
|
}
|
|
154
162
|
/**
|
package/dist/api/rpc.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/api/rpc.ts","../../src/logger.ts","../../src/transports/matomo.ts","../../../constants/src/index.ts","../../src/transports/graylog.ts"],"sourcesContent":["import { CrexLogger } from '../logger';\nimport { InformationUnitsService, LanguageService } from '@c-rex/services';\nimport { NextRequest, NextResponse } from 'next/server';\n\n/**\n * Registry of available services that can be called via RPC.\n */\nconst serviceRegistry = {\n InformationUnitsService,\n CrexLogger,\n LanguageService\n};\n\n/**\n * Interface for RPC payload.\n */\ntype RpcPayload = {\n method: string;\n params: any;\n};\n\n/**\n * Handles POST requests for RPC (Remote Procedure Call) functionality.\n * Allows calling methods on registered services with parameters.\n * \n * @param req - The Next.js request object containing the RPC payload\n * @returns A JSON response with the result of the method call, or an error if the service or method is not found\n */\nexport const POST = async (req: NextRequest) => {\n try {\n const { method, params }: RpcPayload = await req.json();\n const [serviceName, methodName] = method.split('.');\n const ServiceClass = serviceRegistry[serviceName as keyof typeof serviceRegistry];\n\n if (!ServiceClass) {\n return NextResponse.json({ error: `Service '${serviceName}' not found` }, { status: 404 });\n }\n\n const serviceInstance = new ServiceClass();\n const handler = (serviceInstance as any)[methodName as any];\n\n if (typeof handler !== 'function') {\n return NextResponse.json({ error: `Method '${methodName}' not found on '${serviceName}'` }, { status: 404 });\n }\n\n const result = await handler.call(serviceInstance, params);\n return NextResponse.json({ data: result });\n } catch (error) {\n const logger = new CrexLogger()\n logger.log({\n level: \"error\",\n message: `RPC.POST error: ${error}`\n })\n return NextResponse.json({ error: String(error) }, { status: 500 });\n }\n}\n","import winston from \"winston\";\nimport { MatomoTransport } from \"./transports/matomo\";\nimport { GraylogTransport } from \"./transports/graylog\";\nimport { ConfigInterface } from \"@c-rex/interfaces\";\nimport { LogCategoriesType, LogLevelType } from \"@c-rex/types\";\nimport { LOG_LEVELS } from \"@c-rex/constants\";\nimport { getServerConfigs } from \"@c-rex/utils/next-cookies\";\n\n/**\n * Logger class for the CREX application.\n * Provides logging functionality with multiple transports (Console, Matomo, Graylog).\n */\nexport class CrexLogger {\n private customerConfig!: ConfigInterface;\n public logger!: winston.Logger;\n\n /**\n * Initializes the logger instance if it hasn't been initialized yet.\n * Loads customer configuration and creates the logger with appropriate transports.\n * \n * @private\n */\n private async initLogger() {\n try {\n if (!this.customerConfig) {\n this.customerConfig = await getServerConfigs();\n }\n if (!this.logger) {\n this.logger = this.createLogger();\n }\n } catch (error) {\n console.error(\"Error initializing logger:\", error);\n }\n }\n\n /**\n * Logs a message with the specified level and optional category.\n * \n * @param options - Logging options\n * @param options.level - The log level (error, warn, info, etc.)\n * @param options.message - The message to log\n * @param options.category - Optional category for the log message\n */\n public async log({ level, message, category }: {\n level: LogLevelType,\n message: string,\n category?: LogCategoriesType\n }) {\n await this.initLogger();\n this.logger.log(level, message, category);\n }\n\n /**\n * Creates a new Winston logger instance with configured transports.\n * \n * @private\n * @returns A configured Winston logger instance\n */\n private createLogger() {\n return winston.createLogger({\n levels: LOG_LEVELS,\n transports: [\n new winston.transports.Console({\n level: this.customerConfig.logs.console.minimumLevel,\n silent: this.customerConfig.logs.console.silent,\n }),\n new MatomoTransport(this.customerConfig),\n new GraylogTransport(this.customerConfig),\n ],\n });\n }\n}","import Transport from \"winston-transport\";\nimport { LogCategoriesType, LogLevelType } from \"@c-rex/types\";\nimport { ALL } from \"@c-rex/constants\";\nimport { ConfigInterface } from \"@c-rex/interfaces\";\n\n/**\n * Winston transport for sending logs to Matomo analytics.\n * Extends the base Winston transport with Matomo-specific functionality.\n */\nexport class MatomoTransport extends Transport {\n public matomoTransport: any;\n private configs: ConfigInterface;\n\n /**\n * Creates a new instance of MatomoTransport.\n * \n * @param configs - The application configuration containing logging settings\n */\n constructor(configs: ConfigInterface) {\n super({\n level: configs.logs.matomo.minimumLevel,\n silent: configs.logs.matomo.silent,\n });\n\n this.matomoTransport = new Transport();\n this.configs = configs;\n }\n\n /**\n * Logs a message to Matomo if the message category is included in the configured categories.\n * \n * @param info - The log information including level, message, and category\n * @param callback - Callback function to execute after logging\n */\n log(\n info: { level: LogLevelType, message: string, category: LogCategoriesType },\n callback: () => void,\n ): void {\n const matomoCategory = this.configs.logs.matomo.categoriesLevel\n\n if (matomoCategory.includes(info.category) || matomoCategory.includes(ALL)) {\n this.matomoTransport.log(info, callback);\n }\n }\n}\n","export const ALL = \"*\"\n\nexport const LOG_CATEGORIES = [\n \"NoLicense\",\n \"Scenario\",\n \"Favorites\",\n \"Subscription\",\n \"Share\",\n \"Document\",\n \"Search\",\n \"History\",\n \"Notification\",\n \"UserProfile\",\n] as const;\n\nexport const LOG_LEVELS = {\n critical: 2,\n error: 3,\n warning: 4,\n info: 6,\n debug: 7,\n} as const;\n\nexport const RESULT_VIEW_STYLES = [\n \"cards\",\n \"table\",\n] as const;\n\nexport const API = {\n MAX_RETRY: 3,\n API_TIMEOUT: 10000,\n RETRY_DELAY: 500,\n API_HEADERS: {\n \"content-Type\": \"application/json\",\n },\n};\n\nexport const SDK_CONFIG_KEY = \"crex-sdk-config\";\n\nexport const CONTENT_LANG_KEY = \"CONTENT_LANG_KEY\";\n\nexport const AVAILABLE_CONTENT_LANG_KEY = \"AVAILABLE_CONTENT_LANG_KEY\";\n\nexport const UI_LANG_KEY = \"UI_LANG_KEY\";\n\nexport const FLAGS_BY_LANG = {\n \"en\": \"US\",\n \"de\": \"DE\",\n};\n\nexport const DEFAULT_LANG = \"en-US\";\n\nexport const EN_LANG = \"en\";\n\nexport const UI_LANG_OPTIONS = [\"en-us\", \"de-de\"];\n\nexport const TOPICS_TYPE_AND_LINK = \"topics\";\nexport const BLOG_TYPE_AND_LINK = \"blog\";\nexport const DOCUMENTS_TYPE_AND_LINK = \"documents\";\n\nexport const TOPIC = \"TOPIC\";\nexport const DOCUMENT = \"DOCUMENT\";\nexport const PACKAGE = \"PACKAGE\";\nexport const FRAGMENT = \"FRAGMENT\";\n\nexport const RESULT_TYPES = {\n TOPIC: TOPIC,\n DOCUMENT: DOCUMENT,\n PACKAGE: PACKAGE,\n FRAGMENT: FRAGMENT\n} as const;\n\nexport const FILES_EXTENSIONS = {\n PDF: \"application/pdf\",\n HTML: \"text/html\",\n} as const;\n\nexport const DEFAULT_COOKIE_LIMIT = 30 * 24 * 60 * 60 * 1000; // 30 days in milliseconds\n\nexport const ICONS_BY_FILE_EXTENSION = {\n \"application/pdf\": \"FaFilePdf\",\n} as const;\n\nexport const DEFAULT_ICON = \"file\";\n\nexport const CREX_TOKEN_HEADER_KEY = \"crex-token\";\n\nexport const WILD_CARD_OPTIONS = {\n BOTH: \"BOTH\",\n END: \"END\",\n START: \"START\",\n NONE: \"NONE\",\n} as const;\n\nexport const OPERATOR_OPTIONS = {\n AND: \"AND\",\n OR: \"OR\",\n} as const;\n\nexport const ARTICLE_PAGE_LAYOUT = {\n BLOG: \"BLOG\",\n DOCUMENT: \"DOCUMENT\",\n} as const;\n\nexport const DEVICE_OPTIONS = {\n MOBILE: \"mobile\",\n TABLET: \"tablet\",\n DESKTOP: \"desktop\",\n}\nexport const BREAKPOINTS = {\n sm: 640,\n md: 768,\n lg: 1024,\n xl: 1280,\n \"2xl\": 1536,\n};","import Transport from \"winston-transport\";\nimport Graylog2Transport from \"winston-graylog2\";\nimport { LogCategoriesType, LogLevelType } from \"@c-rex/types\";\nimport { ALL } from \"@c-rex/constants\";\nimport { ConfigInterface } from \"@c-rex/interfaces\";\n\n/**\n * Winston transport for sending logs to Graylog.\n * Extends the base Winston transport with Graylog-specific functionality.\n */\nexport class GraylogTransport extends Transport {\n public graylogTransport: any;\n private configs: ConfigInterface\n\n /**\n * Creates a new instance of GraylogTransport.\n * \n * @param configs - The application configuration containing logging settings\n */\n constructor(configs: ConfigInterface) {\n if (!configs.logs.graylog.hostname || configs.logs.graylog.port === undefined) {\n throw new Error(\"Graylog hostname and port must be defined\");\n }\n\n super({\n level: configs.logs.graylog.minimumLevel,\n silent: configs.logs.graylog.silent,\n });\n\n this.configs = configs;\n this.graylogTransport = new Graylog2Transport({\n name: configs.logs.graylog.app,\n silent: configs.logs.graylog.silent,\n handleExceptions: false,\n graylog: {\n servers: [\n { host: \"localhost\", port: 12201 },\n { host: configs.logs.graylog.hostname, port: configs.logs.graylog.port }\n ],\n },\n });\n }\n\n /**\n * Logs a message to Graylog if the message category is included in the configured categories.\n * \n * @param info - The log information including level, message, and category\n * @param callback - Callback function to execute after logging\n */\n log(\n info: { level: LogLevelType, message: string, category: LogCategoriesType },\n callback: () => void,\n ): void {\n const graylogCategory = this.configs.logs.graylog.categoriesLevel\n\n if (graylogCategory.includes(info.category) || graylogCategory.includes(ALL)) {\n this.graylogTransport.log(info, callback);\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,qBAAoB;;;ACApB,+BAAsB;;;ACAf,IAAM,MAAM;AAeZ,IAAM,aAAa;AAAA,EACtB,UAAU;AAAA,EACV,OAAO;AAAA,EACP,SAAS;AAAA,EACT,MAAM;AAAA,EACN,OAAO;AACX;AAwDO,IAAM,uBAAuB,KAAK,KAAK,KAAK,KAAK;;;ADpEjD,IAAM,kBAAN,cAA8B,yBAAAA,QAAU;AAAA,EACpC;AAAA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A,sBAAyD;AACzD,oBAA0C;AAK1C,IAAM,kBAAkB;AAAA,EACpB;AAAA,EACA;AAAA,EACA;AACJ;AAiBO,IAAM,OAAO,OAAO,QAAqB;AAC5C,MAAI;AACA,UAAM,EAAE,QAAQ,OAAO,IAAgB,MAAM,IAAI,KAAK;AACtD,UAAM,CAAC,aAAa,UAAU,IAAI,OAAO,MAAM,GAAG;AAClD,UAAM,eAAe,gBAAgB,WAA2C;AAEhF,QAAI,CAAC,cAAc;AACf,aAAO,2BAAa,KAAK,EAAE,OAAO,YAAY,WAAW,cAAc,GAAG,EAAE,QAAQ,IAAI,CAAC;AAAA,IAC7F;AAEA,UAAM,kBAAkB,IAAI,aAAa;AACzC,UAAM,UAAW,gBAAwB,UAAiB;AAE1D,QAAI,OAAO,YAAY,YAAY;AAC/B,aAAO,2BAAa,KAAK,EAAE,OAAO,WAAW,UAAU,mBAAmB,WAAW,IAAI,GAAG,EAAE,QAAQ,IAAI,CAAC;AAAA,IAC/G;AAEA,UAAM,SAAS,MAAM,QAAQ,KAAK,iBAAiB,MAAM;AACzD,WAAO,2BAAa,KAAK,EAAE,MAAM,OAAO,CAAC;AAAA,EAC7C,SAAS,OAAO;AACZ,UAAM,SAAS,IAAI,WAAW;AAC9B,WAAO,IAAI;AAAA,MACP,OAAO;AAAA,MACP,SAAS,mBAAmB,KAAK;AAAA,IACrC,CAAC;AACD,WAAO,2BAAa,KAAK,EAAE,OAAO,OAAO,KAAK,EAAE,GAAG,EAAE,QAAQ,IAAI,CAAC;AAAA,EACtE;AACJ;","names":["Transport","import_winston_transport","Transport","Graylog2Transport","winston"]}
|
|
1
|
+
{"version":3,"sources":["../../src/api/rpc.ts","../../src/logger.ts","../../src/transports/matomo.ts","../../../constants/src/index.ts","../../src/transports/graylog.ts","../../src/config.ts"],"sourcesContent":["import { CrexLogger } from '../logger';\nimport { InformationUnitsService, LanguageService } from '@c-rex/services';\nimport { NextRequest, NextResponse } from 'next/server';\n\n/**\n * Registry of available services that can be called via RPC.\n */\nconst serviceRegistry = {\n InformationUnitsService,\n CrexLogger,\n LanguageService\n};\n\n/**\n * Interface for RPC payload.\n */\ntype RpcPayload = {\n method: string;\n params: any;\n};\n\n/**\n * Handles POST requests for RPC (Remote Procedure Call) functionality.\n * Allows calling methods on registered services with parameters.\n * \n * @param req - The Next.js request object containing the RPC payload\n * @returns A JSON response with the result of the method call, or an error if the service or method is not found\n */\nexport const POST = async (req: NextRequest) => {\n try {\n const { method, params }: RpcPayload = await req.json();\n const [serviceName, methodName] = method.split('.');\n const ServiceClass = serviceRegistry[serviceName as keyof typeof serviceRegistry];\n\n if (!ServiceClass) {\n return NextResponse.json({ error: `Service '${serviceName}' not found` }, { status: 404 });\n }\n\n const serviceInstance = new ServiceClass();\n const handler = (serviceInstance as any)[methodName as any];\n\n if (typeof handler !== 'function') {\n return NextResponse.json({ error: `Method '${methodName}' not found on '${serviceName}'` }, { status: 404 });\n }\n\n const result = await handler.call(serviceInstance, params);\n return NextResponse.json({ data: result });\n } catch (error) {\n const logger = new CrexLogger()\n logger.log({\n level: \"error\",\n message: `RPC.POST error: ${error}`\n })\n return NextResponse.json({ error: String(error) }, { status: 500 });\n }\n}\n","import winston from \"winston\";\nimport { MatomoTransport } from \"./transports/matomo\";\nimport { GraylogTransport } from \"./transports/graylog\";\nimport { ConfigInterface } from \"@c-rex/interfaces\";\nimport { LogCategoriesType, LogLevelType } from \"@c-rex/types\";\nimport { LOG_LEVELS } from \"@c-rex/constants\";\nimport { getServerConfig } from \"./config\";\n\n\n/**\n * Logger class for the CREX application.\n * Provides logging functionality with multiple transports (Console, Matomo, Graylog).\n */\nexport class CrexLogger {\n private customerConfig!: ConfigInterface;\n public logger!: winston.Logger;\n\n /**\n * Initializes the logger instance if it hasn't been initialized yet.\n * Loads customer configuration and creates the logger with appropriate transports.\n * \n * @private\n */\n private async initLogger() {\n try {\n if (!this.customerConfig) {\n this.customerConfig = getServerConfig();\n }\n if (!this.logger) {\n this.logger = this.createLogger();\n }\n } catch (error) {\n console.log(\"Error initializing logger:\", error);\n }\n }\n\n /**\n * Logs a message with the specified level and optional category.\n * \n * @param options - Logging options\n * @param options.level - The log level (error, warn, info, etc.)\n * @param options.message - The message to log\n * @param options.category - Optional category for the log message\n */\n public async log({ level, message, category }: {\n level: LogLevelType,\n message: string,\n category?: LogCategoriesType\n }) {\n await this.initLogger();\n 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 \"table-with-images\",\n] as const;\n\nexport const API = {\n MAX_RETRY: 3,\n API_TIMEOUT: 10000,\n RETRY_DELAY: 500,\n API_HEADERS: {\n \"content-Type\": \"application/json\",\n },\n};\n\nexport const SDK_CONFIG_KEY = \"crex-sdk-config\";\n\nexport const CONTENT_LANG_KEY = \"CONTENT_LANG_KEY\";\n\nexport const AVAILABLE_CONTENT_LANG_KEY = \"AVAILABLE_CONTENT_LANG_KEY\";\n\nexport const UI_LANG_KEY = \"UI_LANG_KEY\";\n\nexport const FLAGS_BY_LANG = {\n \"en\": \"US\",\n \"de\": \"DE\",\n};\n\nexport const DEFAULT_LANG = \"en-US\";\n\nexport const EN_LANG = \"en\";\n\nexport const UI_LANG_OPTIONS = [\"en-us\", \"de-de\"];\n\nexport const TOPICS_TYPE_AND_LINK = \"topics\";\nexport const BLOG_TYPE_AND_LINK = \"blog\";\nexport const DOCUMENTS_TYPE_AND_LINK = \"documents\";\n\nexport const TOPIC = \"TOPIC\";\nexport const DOCUMENT = \"DOCUMENT\";\nexport const PACKAGE = \"PACKAGE\";\nexport const FRAGMENT = \"FRAGMENT\";\n\nexport const RESULT_TYPES = {\n TOPIC: TOPIC,\n DOCUMENT: DOCUMENT,\n PACKAGE: PACKAGE,\n FRAGMENT: FRAGMENT\n} as const;\n\nexport const FILES_EXTENSIONS = {\n PDF: \"application/pdf\",\n HTML: \"text/html\",\n} as const;\n\nexport const DEFAULT_COOKIE_LIMIT = 30 * 24 * 60 * 60 * 1000; // 30 days in milliseconds\n\nexport const ICONS_BY_FILE_EXTENSION = {\n \"application/pdf\": \"FaFilePdf\",\n} as const;\n\nexport const DEFAULT_ICON = \"file\";\n\nexport const CREX_TOKEN_HEADER_KEY = \"crex-token\";\n\nexport const WILD_CARD_OPTIONS = {\n BOTH: \"BOTH\",\n END: \"END\",\n START: \"START\",\n NONE: \"NONE\",\n} as const;\n\nexport const OPERATOR_OPTIONS = {\n AND: \"AND\",\n OR: \"OR\",\n} as const;\n\nexport const ARTICLE_PAGE_LAYOUT = {\n BLOG: \"BLOG\",\n DOCUMENT: \"DOCUMENT\",\n} as const;\n\nexport const DEVICE_OPTIONS = {\n MOBILE: \"mobile\",\n TABLET: \"tablet\",\n DESKTOP: \"desktop\",\n}\nexport const BREAKPOINTS = {\n sm: 640,\n md: 768,\n lg: 1024,\n xl: 1280,\n \"2xl\": 1536,\n};","import Transport from \"winston-transport\";\nimport Graylog2Transport from \"winston-graylog2\";\nimport { LogCategoriesType, LogLevelType } from \"@c-rex/types\";\nimport { ALL } from \"@c-rex/constants\";\nimport { ConfigInterface } from \"@c-rex/interfaces\";\n\n/**\n * Winston transport for sending logs to Graylog.\n * Extends the base Winston transport with Graylog-specific functionality.\n */\nexport class GraylogTransport extends Transport {\n public graylogTransport: any;\n private configs: ConfigInterface\n\n /**\n * Creates a new instance of GraylogTransport.\n * \n * @param configs - The application configuration containing logging settings\n */\n constructor(configs: ConfigInterface) {\n if (!configs.logs.graylog.hostname || configs.logs.graylog.port === undefined) {\n throw new Error(\"Graylog hostname and port must be defined\");\n }\n\n super({\n level: configs.logs.graylog.minimumLevel,\n silent: configs.logs.graylog.silent,\n });\n\n this.configs = configs;\n this.graylogTransport = new Graylog2Transport({\n name: configs.logs.graylog.app,\n silent: configs.logs.graylog.silent,\n handleExceptions: false,\n graylog: {\n servers: [\n { host: \"localhost\", port: 12201 },\n { host: configs.logs.graylog.hostname, port: configs.logs.graylog.port }\n ],\n },\n });\n }\n\n /**\n * Logs a message to Graylog if the message category is included in the configured categories.\n * \n * @param info - The log information including level, message, and category\n * @param callback - Callback function to execute after logging\n */\n log(\n info: { level: LogLevelType, message: string, category: LogCategoriesType },\n callback: () => void,\n ): void {\n const graylogCategory = this.configs.logs.graylog.categoriesLevel\n\n if (graylogCategory.includes(info.category) || graylogCategory.includes(ALL)) {\n this.graylogTransport.log(info, callback);\n }\n }\n}\n","import { ConfigInterface } from \"@c-rex/interfaces\";\nimport { SDK_CONFIG_KEY } from '@c-rex/constants';\nimport { CookiesConfigs } from '@c-rex/interfaces';\nimport { cookies } from 'next/headers';\n\n/**\n * Retrieves and parses configuration data from a cookie.\n * @returns The parsed configuration object\n * @throws Error if the configuration cookie is not found or cannot be parsed\n */\nexport const getClientConfig = (): CookiesConfigs => {\n const jsonConfigs = cookies().get(SDK_CONFIG_KEY)?.value;\n if (!jsonConfigs) {\n throw new Error('Configs not found');\n }\n\n const configs: CookiesConfigs = JSON.parse(jsonConfigs);\n\n return configs;\n}\n\ndeclare global {\n // eslint-disable-next-line no-var\n var __GLOBAL_CONFIG__: ConfigInterface | null;\n}\n\nexport function initializeConfig(config: ConfigInterface) {\n if (global.__GLOBAL_CONFIG__) return global.__GLOBAL_CONFIG__;\n global.__GLOBAL_CONFIG__ = config;\n return global.__GLOBAL_CONFIG__;\n}\n\nexport function getServerConfig() {\n if (!global.__GLOBAL_CONFIG__) {\n throw new Error('Server config not initialized');\n }\n return global.__GLOBAL_CONFIG__;\n}"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,qBAAoB;;;ACApB,+BAAsB;;;ACAf,IAAM,MAAM;AAeZ,IAAM,aAAa;AAAA,EACtB,UAAU;AAAA,EACV,OAAO;AAAA,EACP,SAAS;AAAA,EACT,MAAM;AAAA,EACN,OAAO;AACX;AAyDO,IAAM,uBAAuB,KAAK,KAAK,KAAK,KAAK;;;ADrEjD,IAAM,kBAAN,cAA8B,yBAAAA,QAAU;AAAA,EACpC;AAAA,EACC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOR,YAAY,SAA0B;AAClC,UAAM;AAAA,MACF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AA,IACJ,CAAC;AAAA,EACL;AACJ;;;ADvEA,sBAAyD;AACzD,oBAA0C;AAK1C,IAAM,kBAAkB;AAAA,EACpB;AAAA,EACA;AAAA,EACA;AACJ;AAiBO,IAAM,OAAO,OAAO,QAAqB;AAC5C,MAAI;AACA,UAAM,EAAE,QAAQ,OAAO,IAAgB,MAAM,IAAI,KAAK;AACtD,UAAM,CAAC,aAAa,UAAU,IAAI,OAAO,MAAM,GAAG;AAClD,UAAM,eAAe,gBAAgB,WAA2C;AAEhF,QAAI,CAAC,cAAc;AACf,aAAO,2BAAa,KAAK,EAAE,OAAO,YAAY,WAAW,cAAc,GAAG,EAAE,QAAQ,IAAI,CAAC;AAAA,IAC7F;AAEA,UAAM,kBAAkB,IAAI,aAAa;AACzC,UAAM,UAAW,gBAAwB,UAAiB;AAE1D,QAAI,OAAO,YAAY,YAAY;AAC/B,aAAO,2BAAa,KAAK,EAAE,OAAO,WAAW,UAAU,mBAAmB,WAAW,IAAI,GAAG,EAAE,QAAQ,IAAI,CAAC;AAAA,IAC/G;AAEA,UAAM,SAAS,MAAM,QAAQ,KAAK,iBAAiB,MAAM;AACzD,WAAO,2BAAa,KAAK,EAAE,MAAM,OAAO,CAAC;AAAA,EAC7C,SAAS,OAAO;AACZ,UAAM,SAAS,IAAI,WAAW;AAC9B,WAAO,IAAI;AAAA,MACP,OAAO;AAAA,MACP,SAAS,mBAAmB,KAAK;AAAA,IACrC,CAAC;AACD,WAAO,2BAAa,KAAK,EAAE,OAAO,OAAO,KAAK,EAAE,GAAG,EAAE,QAAQ,IAAI,CAAC;AAAA,EACtE;AACJ;","names":["Transport","import_winston_transport","Transport","Graylog2Transport","winston"]}
|
package/dist/api/rpc.mjs
CHANGED
|
@@ -92,8 +92,16 @@ var GraylogTransport = class extends Transport2 {
|
|
|
92
92
|
}
|
|
93
93
|
};
|
|
94
94
|
|
|
95
|
+
// src/config.ts
|
|
96
|
+
import { cookies } from "next/headers";
|
|
97
|
+
function getServerConfig() {
|
|
98
|
+
if (!global.__GLOBAL_CONFIG__) {
|
|
99
|
+
throw new Error("Server config not initialized");
|
|
100
|
+
}
|
|
101
|
+
return global.__GLOBAL_CONFIG__;
|
|
102
|
+
}
|
|
103
|
+
|
|
95
104
|
// src/logger.ts
|
|
96
|
-
import { getServerConfigs } from "@c-rex/utils/next-cookies";
|
|
97
105
|
var CrexLogger = class {
|
|
98
106
|
customerConfig;
|
|
99
107
|
logger;
|
|
@@ -106,13 +114,13 @@ var CrexLogger = class {
|
|
|
106
114
|
async initLogger() {
|
|
107
115
|
try {
|
|
108
116
|
if (!this.customerConfig) {
|
|
109
|
-
this.customerConfig =
|
|
117
|
+
this.customerConfig = getServerConfig();
|
|
110
118
|
}
|
|
111
119
|
if (!this.logger) {
|
|
112
120
|
this.logger = this.createLogger();
|
|
113
121
|
}
|
|
114
122
|
} catch (error) {
|
|
115
|
-
console.
|
|
123
|
+
console.log("Error initializing logger:", error);
|
|
116
124
|
}
|
|
117
125
|
}
|
|
118
126
|
/**
|
package/dist/api/rpc.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/logger.ts","../../src/transports/matomo.ts","../../../constants/src/index.ts","../../src/transports/graylog.ts","../../src/api/rpc.ts"],"sourcesContent":["import winston from \"winston\";\nimport { MatomoTransport } from \"./transports/matomo\";\nimport { GraylogTransport } from \"./transports/graylog\";\nimport { ConfigInterface } from \"@c-rex/interfaces\";\nimport { LogCategoriesType, LogLevelType } from \"@c-rex/types\";\nimport { LOG_LEVELS } from \"@c-rex/constants\";\nimport { getServerConfigs } from \"@c-rex/utils/next-cookies\";\n\n/**\n * Logger class for the CREX application.\n * Provides logging functionality with multiple transports (Console, Matomo, Graylog).\n */\nexport class CrexLogger {\n private customerConfig!: ConfigInterface;\n public logger!: winston.Logger;\n\n /**\n * Initializes the logger instance if it hasn't been initialized yet.\n * Loads customer configuration and creates the logger with appropriate transports.\n * \n * @private\n */\n private async initLogger() {\n try {\n if (!this.customerConfig) {\n this.customerConfig = await getServerConfigs();\n }\n if (!this.logger) {\n this.logger = this.createLogger();\n }\n } catch (error) {\n console.error(\"Error initializing logger:\", error);\n }\n }\n\n /**\n * Logs a message with the specified level and optional category.\n * \n * @param options - Logging options\n * @param options.level - The log level (error, warn, info, etc.)\n * @param options.message - The message to log\n * @param options.category - Optional category for the log message\n */\n public async log({ level, message, category }: {\n level: LogLevelType,\n message: string,\n category?: LogCategoriesType\n }) {\n await this.initLogger();\n this.logger.log(level, message, category);\n }\n\n /**\n * Creates a new Winston logger instance with configured transports.\n * \n * @private\n * @returns A configured Winston logger instance\n */\n private createLogger() {\n return winston.createLogger({\n levels: LOG_LEVELS,\n transports: [\n new winston.transports.Console({\n level: this.customerConfig.logs.console.minimumLevel,\n silent: this.customerConfig.logs.console.silent,\n }),\n new MatomoTransport(this.customerConfig),\n new GraylogTransport(this.customerConfig),\n ],\n });\n }\n}","import Transport from \"winston-transport\";\nimport { LogCategoriesType, LogLevelType } from \"@c-rex/types\";\nimport { ALL } from \"@c-rex/constants\";\nimport { ConfigInterface } from \"@c-rex/interfaces\";\n\n/**\n * Winston transport for sending logs to Matomo analytics.\n * Extends the base Winston transport with Matomo-specific functionality.\n */\nexport class MatomoTransport extends Transport {\n public matomoTransport: any;\n private configs: ConfigInterface;\n\n /**\n * Creates a new instance of MatomoTransport.\n * \n * @param configs - The application configuration containing logging settings\n */\n constructor(configs: ConfigInterface) {\n super({\n level: configs.logs.matomo.minimumLevel,\n silent: configs.logs.matomo.silent,\n });\n\n this.matomoTransport = new Transport();\n this.configs = configs;\n }\n\n /**\n * Logs a message to Matomo if the message category is included in the configured categories.\n * \n * @param info - The log information including level, message, and category\n * @param callback - Callback function to execute after logging\n */\n log(\n info: { level: LogLevelType, message: string, category: LogCategoriesType },\n callback: () => void,\n ): void {\n const matomoCategory = this.configs.logs.matomo.categoriesLevel\n\n if (matomoCategory.includes(info.category) || matomoCategory.includes(ALL)) {\n this.matomoTransport.log(info, callback);\n }\n }\n}\n","export const ALL = \"*\"\n\nexport const LOG_CATEGORIES = [\n \"NoLicense\",\n \"Scenario\",\n \"Favorites\",\n \"Subscription\",\n \"Share\",\n \"Document\",\n \"Search\",\n \"History\",\n \"Notification\",\n \"UserProfile\",\n] as const;\n\nexport const LOG_LEVELS = {\n critical: 2,\n error: 3,\n warning: 4,\n info: 6,\n debug: 7,\n} as const;\n\nexport const RESULT_VIEW_STYLES = [\n \"cards\",\n \"table\",\n] as const;\n\nexport const API = {\n MAX_RETRY: 3,\n API_TIMEOUT: 10000,\n RETRY_DELAY: 500,\n API_HEADERS: {\n \"content-Type\": \"application/json\",\n },\n};\n\nexport const SDK_CONFIG_KEY = \"crex-sdk-config\";\n\nexport const CONTENT_LANG_KEY = \"CONTENT_LANG_KEY\";\n\nexport const AVAILABLE_CONTENT_LANG_KEY = \"AVAILABLE_CONTENT_LANG_KEY\";\n\nexport const UI_LANG_KEY = \"UI_LANG_KEY\";\n\nexport const FLAGS_BY_LANG = {\n \"en\": \"US\",\n \"de\": \"DE\",\n};\n\nexport const DEFAULT_LANG = \"en-US\";\n\nexport const EN_LANG = \"en\";\n\nexport const UI_LANG_OPTIONS = [\"en-us\", \"de-de\"];\n\nexport const TOPICS_TYPE_AND_LINK = \"topics\";\nexport const BLOG_TYPE_AND_LINK = \"blog\";\nexport const DOCUMENTS_TYPE_AND_LINK = \"documents\";\n\nexport const TOPIC = \"TOPIC\";\nexport const DOCUMENT = \"DOCUMENT\";\nexport const PACKAGE = \"PACKAGE\";\nexport const FRAGMENT = \"FRAGMENT\";\n\nexport const RESULT_TYPES = {\n TOPIC: TOPIC,\n DOCUMENT: DOCUMENT,\n PACKAGE: PACKAGE,\n FRAGMENT: FRAGMENT\n} as const;\n\nexport const FILES_EXTENSIONS = {\n PDF: \"application/pdf\",\n HTML: \"text/html\",\n} as const;\n\nexport const DEFAULT_COOKIE_LIMIT = 30 * 24 * 60 * 60 * 1000; // 30 days in milliseconds\n\nexport const ICONS_BY_FILE_EXTENSION = {\n \"application/pdf\": \"FaFilePdf\",\n} as const;\n\nexport const DEFAULT_ICON = \"file\";\n\nexport const CREX_TOKEN_HEADER_KEY = \"crex-token\";\n\nexport const WILD_CARD_OPTIONS = {\n BOTH: \"BOTH\",\n END: \"END\",\n START: \"START\",\n NONE: \"NONE\",\n} as const;\n\nexport const OPERATOR_OPTIONS = {\n AND: \"AND\",\n OR: \"OR\",\n} as const;\n\nexport const ARTICLE_PAGE_LAYOUT = {\n BLOG: \"BLOG\",\n DOCUMENT: \"DOCUMENT\",\n} as const;\n\nexport const DEVICE_OPTIONS = {\n MOBILE: \"mobile\",\n TABLET: \"tablet\",\n DESKTOP: \"desktop\",\n}\nexport const BREAKPOINTS = {\n sm: 640,\n md: 768,\n lg: 1024,\n xl: 1280,\n \"2xl\": 1536,\n};","import Transport from \"winston-transport\";\nimport Graylog2Transport from \"winston-graylog2\";\nimport { LogCategoriesType, LogLevelType } from \"@c-rex/types\";\nimport { ALL } from \"@c-rex/constants\";\nimport { ConfigInterface } from \"@c-rex/interfaces\";\n\n/**\n * Winston transport for sending logs to Graylog.\n * Extends the base Winston transport with Graylog-specific functionality.\n */\nexport class GraylogTransport extends Transport {\n public graylogTransport: any;\n private configs: ConfigInterface\n\n /**\n * Creates a new instance of GraylogTransport.\n * \n * @param configs - The application configuration containing logging settings\n */\n constructor(configs: ConfigInterface) {\n if (!configs.logs.graylog.hostname || configs.logs.graylog.port === undefined) {\n throw new Error(\"Graylog hostname and port must be defined\");\n }\n\n super({\n level: configs.logs.graylog.minimumLevel,\n silent: configs.logs.graylog.silent,\n });\n\n this.configs = configs;\n this.graylogTransport = new Graylog2Transport({\n name: configs.logs.graylog.app,\n silent: configs.logs.graylog.silent,\n handleExceptions: false,\n graylog: {\n servers: [\n { host: \"localhost\", port: 12201 },\n { host: configs.logs.graylog.hostname, port: configs.logs.graylog.port }\n ],\n },\n });\n }\n\n /**\n * Logs a message to Graylog if the message category is included in the configured categories.\n * \n * @param info - The log information including level, message, and category\n * @param callback - Callback function to execute after logging\n */\n log(\n info: { level: LogLevelType, message: string, category: LogCategoriesType },\n callback: () => void,\n ): void {\n const graylogCategory = this.configs.logs.graylog.categoriesLevel\n\n if (graylogCategory.includes(info.category) || graylogCategory.includes(ALL)) {\n this.graylogTransport.log(info, callback);\n }\n }\n}\n","import { CrexLogger } from '../logger';\nimport { InformationUnitsService, LanguageService } from '@c-rex/services';\nimport { NextRequest, NextResponse } from 'next/server';\n\n/**\n * Registry of available services that can be called via RPC.\n */\nconst serviceRegistry = {\n InformationUnitsService,\n CrexLogger,\n LanguageService\n};\n\n/**\n * Interface for RPC payload.\n */\ntype RpcPayload = {\n method: string;\n params: any;\n};\n\n/**\n * Handles POST requests for RPC (Remote Procedure Call) functionality.\n * Allows calling methods on registered services with parameters.\n * \n * @param req - The Next.js request object containing the RPC payload\n * @returns A JSON response with the result of the method call, or an error if the service or method is not found\n */\nexport const POST = async (req: NextRequest) => {\n try {\n const { method, params }: RpcPayload = await req.json();\n const [serviceName, methodName] = method.split('.');\n const ServiceClass = serviceRegistry[serviceName as keyof typeof serviceRegistry];\n\n if (!ServiceClass) {\n return NextResponse.json({ error: `Service '${serviceName}' not found` }, { status: 404 });\n }\n\n const serviceInstance = new ServiceClass();\n const handler = (serviceInstance as any)[methodName as any];\n\n if (typeof handler !== 'function') {\n return NextResponse.json({ error: `Method '${methodName}' not found on '${serviceName}'` }, { status: 404 });\n }\n\n const result = await handler.call(serviceInstance, params);\n return NextResponse.json({ data: result });\n } catch (error) {\n const logger = new CrexLogger()\n logger.log({\n level: \"error\",\n message: `RPC.POST error: ${error}`\n })\n return NextResponse.json({ error: String(error) }, { status: 500 });\n }\n}\n"],"mappings":";AAAA,OAAO,aAAa;;;ACApB,OAAO,eAAe;;;ACAf,IAAM,MAAM;AAeZ,IAAM,aAAa;AAAA,EACtB,UAAU;AAAA,EACV,OAAO;AAAA,EACP,SAAS;AAAA,EACT,MAAM;AAAA,EACN,OAAO;AACX;AAwDO,IAAM,u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Ac;AAAA,MAC5C;AAAA,IACJ,CAAC;AAAA,EACL;AACJ;;;AItEA,SAAS,yBAAyB,uBAAuB;AACzD,SAAsB,oBAAoB;AAK1C,IAAM,kBAAkB;AAAA,EACpB;AAAA,EACA;AAAA,EACA;AACJ;AAiBO,IAAM,OAAO,OAAO,QAAqB;AAC5C,MAAI;AACA,UAAM,EAAE,QAAQ,OAAO,IAAgB,MAAM,IAAI,KAAK;AACtD,UAAM,CAAC,aAAa,UAAU,IAAI,OAAO,MAAM,GAAG;AAClD,UAAM,eAAe,gBAAgB,WAA2C;AAEhF,QAAI,CAAC,cAAc;AACf,aAAO,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"]}
|
|
1
|
+
{"version":3,"sources":["../../src/logger.ts","../../src/transports/matomo.ts","../../../constants/src/index.ts","../../src/transports/graylog.ts","../../src/config.ts","../../src/api/rpc.ts"],"sourcesContent":["import winston from \"winston\";\nimport { MatomoTransport } from \"./transports/matomo\";\nimport { GraylogTransport } from \"./transports/graylog\";\nimport { ConfigInterface } from \"@c-rex/interfaces\";\nimport { LogCategoriesType, LogLevelType } from \"@c-rex/types\";\nimport { LOG_LEVELS } from \"@c-rex/constants\";\nimport { getServerConfig } from \"./config\";\n\n\n/**\n * Logger class for the CREX application.\n * Provides logging functionality with multiple transports (Console, Matomo, Graylog).\n */\nexport class CrexLogger {\n private customerConfig!: ConfigInterface;\n public logger!: winston.Logger;\n\n /**\n * Initializes the logger instance if it hasn't been initialized yet.\n * Loads customer configuration and creates the logger with appropriate transports.\n * \n * @private\n */\n private async initLogger() {\n try {\n if (!this.customerConfig) {\n this.customerConfig = getServerConfig();\n }\n if (!this.logger) {\n this.logger = this.createLogger();\n }\n } catch (error) {\n console.log(\"Error initializing logger:\", error);\n }\n }\n\n /**\n * Logs a message with the specified level and optional category.\n * \n * @param options - Logging options\n * @param options.level - The log level (error, warn, info, etc.)\n * @param options.message - The message to log\n * @param options.category - Optional category for the log message\n */\n public async log({ level, message, category }: {\n level: LogLevelType,\n message: string,\n category?: LogCategoriesType\n }) {\n await this.initLogger();\n 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 \"table-with-images\",\n] as const;\n\nexport const API = {\n MAX_RETRY: 3,\n API_TIMEOUT: 10000,\n RETRY_DELAY: 500,\n API_HEADERS: {\n \"content-Type\": \"application/json\",\n },\n};\n\nexport const SDK_CONFIG_KEY = \"crex-sdk-config\";\n\nexport const CONTENT_LANG_KEY = \"CONTENT_LANG_KEY\";\n\nexport const AVAILABLE_CONTENT_LANG_KEY = \"AVAILABLE_CONTENT_LANG_KEY\";\n\nexport const UI_LANG_KEY = \"UI_LANG_KEY\";\n\nexport const FLAGS_BY_LANG = {\n \"en\": \"US\",\n \"de\": \"DE\",\n};\n\nexport const DEFAULT_LANG = \"en-US\";\n\nexport const EN_LANG = \"en\";\n\nexport const UI_LANG_OPTIONS = [\"en-us\", \"de-de\"];\n\nexport const TOPICS_TYPE_AND_LINK = \"topics\";\nexport const BLOG_TYPE_AND_LINK = \"blog\";\nexport const DOCUMENTS_TYPE_AND_LINK = \"documents\";\n\nexport const TOPIC = \"TOPIC\";\nexport const DOCUMENT = \"DOCUMENT\";\nexport const PACKAGE = \"PACKAGE\";\nexport const FRAGMENT = \"FRAGMENT\";\n\nexport const RESULT_TYPES = {\n TOPIC: TOPIC,\n DOCUMENT: DOCUMENT,\n PACKAGE: PACKAGE,\n FRAGMENT: FRAGMENT\n} as const;\n\nexport const FILES_EXTENSIONS = {\n PDF: \"application/pdf\",\n HTML: \"text/html\",\n} as const;\n\nexport const DEFAULT_COOKIE_LIMIT = 30 * 24 * 60 * 60 * 1000; // 30 days in milliseconds\n\nexport const ICONS_BY_FILE_EXTENSION = {\n \"application/pdf\": \"FaFilePdf\",\n} as const;\n\nexport const DEFAULT_ICON = \"file\";\n\nexport const CREX_TOKEN_HEADER_KEY = \"crex-token\";\n\nexport const WILD_CARD_OPTIONS = {\n BOTH: \"BOTH\",\n END: \"END\",\n START: \"START\",\n NONE: \"NONE\",\n} as const;\n\nexport const OPERATOR_OPTIONS = {\n AND: \"AND\",\n OR: \"OR\",\n} as const;\n\nexport const ARTICLE_PAGE_LAYOUT = {\n BLOG: \"BLOG\",\n DOCUMENT: \"DOCUMENT\",\n} as const;\n\nexport const DEVICE_OPTIONS = {\n MOBILE: \"mobile\",\n TABLET: \"tablet\",\n DESKTOP: \"desktop\",\n}\nexport const BREAKPOINTS = {\n sm: 640,\n md: 768,\n lg: 1024,\n xl: 1280,\n \"2xl\": 1536,\n};","import Transport from \"winston-transport\";\nimport Graylog2Transport from \"winston-graylog2\";\nimport { LogCategoriesType, LogLevelType } from \"@c-rex/types\";\nimport { ALL } from \"@c-rex/constants\";\nimport { ConfigInterface } from \"@c-rex/interfaces\";\n\n/**\n * Winston transport for sending logs to Graylog.\n * Extends the base Winston transport with Graylog-specific functionality.\n */\nexport class GraylogTransport extends Transport {\n public graylogTransport: any;\n private configs: ConfigInterface\n\n /**\n * Creates a new instance of GraylogTransport.\n * \n * @param configs - The application configuration containing logging settings\n */\n constructor(configs: ConfigInterface) {\n if (!configs.logs.graylog.hostname || configs.logs.graylog.port === undefined) {\n throw new Error(\"Graylog hostname and port must be defined\");\n }\n\n super({\n level: configs.logs.graylog.minimumLevel,\n silent: configs.logs.graylog.silent,\n });\n\n this.configs = configs;\n this.graylogTransport = new Graylog2Transport({\n name: configs.logs.graylog.app,\n silent: configs.logs.graylog.silent,\n handleExceptions: false,\n graylog: {\n servers: [\n { host: \"localhost\", port: 12201 },\n { host: configs.logs.graylog.hostname, port: configs.logs.graylog.port }\n ],\n },\n });\n }\n\n /**\n * Logs a message to Graylog if the message category is included in the configured categories.\n * \n * @param info - The log information including level, message, and category\n * @param callback - Callback function to execute after logging\n */\n log(\n info: { level: LogLevelType, message: string, category: LogCategoriesType },\n callback: () => void,\n ): void {\n const graylogCategory = this.configs.logs.graylog.categoriesLevel\n\n if (graylogCategory.includes(info.category) || graylogCategory.includes(ALL)) {\n this.graylogTransport.log(info, callback);\n }\n }\n}\n","import { ConfigInterface } from \"@c-rex/interfaces\";\nimport { SDK_CONFIG_KEY } from '@c-rex/constants';\nimport { CookiesConfigs } from '@c-rex/interfaces';\nimport { cookies } from 'next/headers';\n\n/**\n * Retrieves and parses configuration data from a cookie.\n * @returns The parsed configuration object\n * @throws Error if the configuration cookie is not found or cannot be parsed\n */\nexport const getClientConfig = (): CookiesConfigs => {\n const jsonConfigs = cookies().get(SDK_CONFIG_KEY)?.value;\n if (!jsonConfigs) {\n throw new Error('Configs not found');\n }\n\n const configs: CookiesConfigs = JSON.parse(jsonConfigs);\n\n return configs;\n}\n\ndeclare global {\n // eslint-disable-next-line no-var\n var __GLOBAL_CONFIG__: ConfigInterface | null;\n}\n\nexport function initializeConfig(config: ConfigInterface) {\n if (global.__GLOBAL_CONFIG__) return global.__GLOBAL_CONFIG__;\n global.__GLOBAL_CONFIG__ = config;\n return global.__GLOBAL_CONFIG__;\n}\n\nexport function getServerConfig() {\n if (!global.__GLOBAL_CONFIG__) {\n throw new Error('Server config not initialized');\n }\n return global.__GLOBAL_CONFIG__;\n}","import { CrexLogger } from '../logger';\nimport { InformationUnitsService, LanguageService } from '@c-rex/services';\nimport { NextRequest, NextResponse } from 'next/server';\n\n/**\n * Registry of available services that can be called via RPC.\n */\nconst serviceRegistry = {\n InformationUnitsService,\n CrexLogger,\n LanguageService\n};\n\n/**\n * Interface for RPC payload.\n */\ntype RpcPayload = {\n method: string;\n params: any;\n};\n\n/**\n * Handles POST requests for RPC (Remote Procedure Call) functionality.\n * Allows calling methods on registered services with parameters.\n * \n * @param req - The Next.js request object containing the RPC payload\n * @returns A JSON response with the result of the method call, or an error if the service or method is not found\n */\nexport const POST = async (req: NextRequest) => {\n try {\n const { method, params }: RpcPayload = await req.json();\n const [serviceName, methodName] = method.split('.');\n const ServiceClass = serviceRegistry[serviceName as keyof typeof serviceRegistry];\n\n if (!ServiceClass) {\n return NextResponse.json({ error: `Service '${serviceName}' not found` }, { status: 404 });\n }\n\n const serviceInstance = new ServiceClass();\n const handler = (serviceInstance as any)[methodName as any];\n\n if (typeof handler !== 'function') {\n return NextResponse.json({ error: `Method '${methodName}' not found on '${serviceName}'` }, { status: 404 });\n }\n\n const result = await handler.call(serviceInstance, params);\n return NextResponse.json({ data: result });\n } catch (error) {\n const logger = new CrexLogger()\n logger.log({\n level: \"error\",\n message: `RPC.POST error: ${error}`\n })\n return NextResponse.json({ error: String(error) }, { status: 500 });\n }\n}\n"],"mappings":";AAAA,OAAO,aAAa;;;ACApB,OAAO,eAAe;;;ACAf,IAAM,MAAM;AAeZ,IAAM,aAAa;AAAA,EACtB,UAAU;AAAA,EACV,OAAO;AAAA,EACP,SAAS;AAAA,EACT,MAAM;AAAA,EACN,OAAO;AACX;AAyDO,IAAM,uBAAuB,KAAK,KAAK,KAAK,KAAK;;;ADrEjD,IAAM,kBAAN,cAA8B,UAAU;AAAA,EACpC;AAAA,EACC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOR,YAAY,SAA0B;AAClC,UAAM;AAAA,MACF,OAAO,QAAQ,KAA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,yBAAyB,uBAAuB;AACzD,SAAsB,oBAAoB;AAK1C,IAAM,kBAAkB;AAAA,EACpB;AAAA,EACA;AAAA,EACA;AACJ;AAiBO,IAAM,OAAO,OAAO,QAAqB;AAC5C,MAAI;AACA,UAAM,EAAE,QAAQ,OAAO,IAAgB,MAAM,IAAI,KAAK;AACtD,UAAM,CAAC,aAAa,UAAU,IAAI,OAAO,MAAM,GAAG;AAClD,UAAM,eAAe,gBAAgB,WAA2C;AAEhF,QAAI,CAAC,cAAc;AACf,aAAO,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"]}
|
package/dist/api/token.js
CHANGED
|
@@ -24,24 +24,45 @@ __export(token_exports, {
|
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(token_exports);
|
|
26
26
|
var import_server = require("next/server");
|
|
27
|
-
var import_openid_client = require("openid-client");
|
|
28
27
|
|
|
29
28
|
// ../constants/src/index.ts
|
|
30
29
|
var DEFAULT_COOKIE_LIMIT = 30 * 24 * 60 * 60 * 1e3;
|
|
31
30
|
var CREX_TOKEN_HEADER_KEY = "crex-token";
|
|
32
31
|
|
|
32
|
+
// src/token.ts
|
|
33
|
+
var import_openid_client = require("openid-client");
|
|
34
|
+
|
|
35
|
+
// src/config.ts
|
|
36
|
+
var import_headers = require("next/headers");
|
|
37
|
+
function getServerConfig() {
|
|
38
|
+
if (!global.__GLOBAL_CONFIG__) {
|
|
39
|
+
throw new Error("Server config not initialized");
|
|
40
|
+
}
|
|
41
|
+
return global.__GLOBAL_CONFIG__;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// src/token.ts
|
|
45
|
+
var getToken = async () => {
|
|
46
|
+
console.log("veio buscar");
|
|
47
|
+
const config = getServerConfig();
|
|
48
|
+
const issuer = await import_openid_client.Issuer.discover(config.OIDC.client.issuer);
|
|
49
|
+
const client = new issuer.Client({
|
|
50
|
+
client_id: config.OIDC.client.id,
|
|
51
|
+
client_secret: config.OIDC.client.secret
|
|
52
|
+
});
|
|
53
|
+
const tokenSet = await client.grant({ grant_type: "client_credentials" });
|
|
54
|
+
const token = tokenSet.access_token;
|
|
55
|
+
const expiresAt = tokenSet.expires_at;
|
|
56
|
+
if (!token) {
|
|
57
|
+
throw new Error("Failed to get token");
|
|
58
|
+
}
|
|
59
|
+
return { token, expiresAt };
|
|
60
|
+
};
|
|
61
|
+
|
|
33
62
|
// src/api/token.ts
|
|
34
|
-
var import_next_cookies = require("@c-rex/utils/next-cookies");
|
|
35
63
|
var postMethod = async () => {
|
|
36
64
|
try {
|
|
37
|
-
const
|
|
38
|
-
const issuer = await import_openid_client.Issuer.discover(customerConfig.OIDC.client.issuer);
|
|
39
|
-
const client = new issuer.Client({
|
|
40
|
-
client_id: customerConfig.OIDC.client.id,
|
|
41
|
-
client_secret: customerConfig.OIDC.client.secret
|
|
42
|
-
});
|
|
43
|
-
const tokenSet = await client.grant({ grant_type: "client_credentials" });
|
|
44
|
-
const token = tokenSet.access_token;
|
|
65
|
+
const { token, expiresAt } = await getToken();
|
|
45
66
|
if (!token) {
|
|
46
67
|
return import_server.NextResponse.json({ error: "Failed to get token" }, { status: 500 });
|
|
47
68
|
}
|
|
@@ -53,7 +74,7 @@ var postMethod = async () => {
|
|
|
53
74
|
secure: process.env.NODE_ENV === "production",
|
|
54
75
|
sameSite: "lax",
|
|
55
76
|
path: "/",
|
|
56
|
-
expires:
|
|
77
|
+
expires: expiresAt ? new Date(expiresAt * 1e3) : void 0
|
|
57
78
|
});
|
|
58
79
|
return response;
|
|
59
80
|
} catch (error) {
|
package/dist/api/token.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/api/token.ts","../../../constants/src/index.ts"],"sourcesContent":["import { NextResponse } from 'next/server';\nimport {
|
|
1
|
+
{"version":3,"sources":["../../src/api/token.ts","../../../constants/src/index.ts","../../src/token.ts","../../src/config.ts"],"sourcesContent":["import { NextResponse } from 'next/server';\nimport { CREX_TOKEN_HEADER_KEY } from '@c-rex/constants';\nimport { getToken } from '../token';\n\n/**\n * Retrieves an access token using client credentials flow from the configured OIDC provider\n * \n * @returns NextResponse with success status or error message\n * @throws Error if token retrieval fails\n */\nexport const postMethod = async (): Promise<NextResponse> => {\n try {\n const { token, expiresAt } = await getToken();\n\n if (!token) {\n return NextResponse.json({ error: 'Failed to get token' }, { status: 500 });\n }\n\n const response = NextResponse.json({ token: token });\n\n response.cookies.set({\n name: CREX_TOKEN_HEADER_KEY,\n value: token,\n httpOnly: true,\n secure: process.env.NODE_ENV === 'production',\n sameSite: 'lax',\n path: '/',\n expires: expiresAt ? new Date(expiresAt * 1000) : undefined\n });\n\n return response;\n\n } catch (error) {\n return NextResponse.json({ error: String(error) }, { status: 500 });\n }\n}\n","export const ALL = \"*\"\n\nexport const LOG_CATEGORIES = [\n \"NoLicense\",\n \"Scenario\",\n \"Favorites\",\n \"Subscription\",\n \"Share\",\n \"Document\",\n \"Search\",\n \"History\",\n \"Notification\",\n \"UserProfile\",\n] as const;\n\nexport const LOG_LEVELS = {\n critical: 2,\n error: 3,\n warning: 4,\n info: 6,\n debug: 7,\n} as const;\n\nexport const RESULT_VIEW_STYLES = [\n \"cards\",\n \"table\",\n \"table-with-images\",\n] as const;\n\nexport const API = {\n MAX_RETRY: 3,\n API_TIMEOUT: 10000,\n RETRY_DELAY: 500,\n API_HEADERS: {\n \"content-Type\": \"application/json\",\n },\n};\n\nexport const SDK_CONFIG_KEY = \"crex-sdk-config\";\n\nexport const CONTENT_LANG_KEY = \"CONTENT_LANG_KEY\";\n\nexport const AVAILABLE_CONTENT_LANG_KEY = \"AVAILABLE_CONTENT_LANG_KEY\";\n\nexport const UI_LANG_KEY = \"UI_LANG_KEY\";\n\nexport const FLAGS_BY_LANG = {\n \"en\": \"US\",\n \"de\": \"DE\",\n};\n\nexport const DEFAULT_LANG = \"en-US\";\n\nexport const EN_LANG = \"en\";\n\nexport const UI_LANG_OPTIONS = [\"en-us\", \"de-de\"];\n\nexport const TOPICS_TYPE_AND_LINK = \"topics\";\nexport const BLOG_TYPE_AND_LINK = \"blog\";\nexport const DOCUMENTS_TYPE_AND_LINK = \"documents\";\n\nexport const TOPIC = \"TOPIC\";\nexport const DOCUMENT = \"DOCUMENT\";\nexport const PACKAGE = \"PACKAGE\";\nexport const FRAGMENT = \"FRAGMENT\";\n\nexport const RESULT_TYPES = {\n TOPIC: TOPIC,\n DOCUMENT: DOCUMENT,\n PACKAGE: PACKAGE,\n FRAGMENT: FRAGMENT\n} as const;\n\nexport const FILES_EXTENSIONS = {\n PDF: \"application/pdf\",\n HTML: \"text/html\",\n} as const;\n\nexport const DEFAULT_COOKIE_LIMIT = 30 * 24 * 60 * 60 * 1000; // 30 days in milliseconds\n\nexport const ICONS_BY_FILE_EXTENSION = {\n \"application/pdf\": \"FaFilePdf\",\n} as const;\n\nexport const DEFAULT_ICON = \"file\";\n\nexport const CREX_TOKEN_HEADER_KEY = \"crex-token\";\n\nexport const WILD_CARD_OPTIONS = {\n BOTH: \"BOTH\",\n END: \"END\",\n START: \"START\",\n NONE: \"NONE\",\n} as const;\n\nexport const OPERATOR_OPTIONS = {\n AND: \"AND\",\n OR: \"OR\",\n} as const;\n\nexport const ARTICLE_PAGE_LAYOUT = {\n BLOG: \"BLOG\",\n DOCUMENT: \"DOCUMENT\",\n} as const;\n\nexport const DEVICE_OPTIONS = {\n MOBILE: \"mobile\",\n TABLET: \"tablet\",\n DESKTOP: \"desktop\",\n}\nexport const BREAKPOINTS = {\n sm: 640,\n md: 768,\n lg: 1024,\n xl: 1280,\n \"2xl\": 1536,\n};","import { Issuer } from 'openid-client';\nimport { getServerConfig } from './config';\n\n/**\n * Retrieves an access token using client credentials flow from the configured OIDC provider\n * \n * @returns NextResponse with success status or error message\n * @throws Error if token retrieval fails\n */\nexport const getToken = async (): Promise<{ token: string; expiresAt: number }> => {\n\n console.log(\"veio buscar\")\n\n const config = getServerConfig();\n\n const issuer = await Issuer.discover(config.OIDC.client.issuer);\n const client = new issuer.Client({\n client_id: config.OIDC.client.id,\n client_secret: config.OIDC.client.secret,\n });\n const tokenSet = await client.grant({ grant_type: 'client_credentials' });\n\n const token = tokenSet.access_token!;\n const expiresAt = tokenSet.expires_at!;\n\n if (!token) {\n throw new Error('Failed to get token');\n }\n\n return { token, expiresAt };\n}\n","import { ConfigInterface } from \"@c-rex/interfaces\";\nimport { SDK_CONFIG_KEY } from '@c-rex/constants';\nimport { CookiesConfigs } from '@c-rex/interfaces';\nimport { cookies } from 'next/headers';\n\n/**\n * Retrieves and parses configuration data from a cookie.\n * @returns The parsed configuration object\n * @throws Error if the configuration cookie is not found or cannot be parsed\n */\nexport const getClientConfig = (): CookiesConfigs => {\n const jsonConfigs = cookies().get(SDK_CONFIG_KEY)?.value;\n if (!jsonConfigs) {\n throw new Error('Configs not found');\n }\n\n const configs: CookiesConfigs = JSON.parse(jsonConfigs);\n\n return configs;\n}\n\ndeclare global {\n // eslint-disable-next-line no-var\n var __GLOBAL_CONFIG__: ConfigInterface | null;\n}\n\nexport function initializeConfig(config: ConfigInterface) {\n if (global.__GLOBAL_CONFIG__) return global.__GLOBAL_CONFIG__;\n global.__GLOBAL_CONFIG__ = config;\n return global.__GLOBAL_CONFIG__;\n}\n\nexport function getServerConfig() {\n if (!global.__GLOBAL_CONFIG__) {\n throw new Error('Server config not initialized');\n }\n return global.__GLOBAL_CONFIG__;\n}"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA6B;;;AC8EtB,IAAM,uBAAuB,KAAK,KAAK,KAAK,KAAK;AAQjD,IAAM,wBAAwB;;;ACtFrC,2BAAuB;;;ACGvB,qBAAwB;AA6BjB,SAAS,kBAAkB;AAC9B,MAAI,CAAC,OAAO,mBAAmB;AAC3B,UAAM,IAAI,MAAM,+BAA+B;AAAA,EACnD;AACA,SAAO,OAAO;AAClB;;;AD5BO,IAAM,WAAW,YAA2D;AAE/E,UAAQ,IAAI,aAAa;AAEzB,QAAM,SAAS,gBAAgB;AAE/B,QAAM,SAAS,MAAM,4BAAO,SAAS,OAAO,KAAK,OAAO,MAAM;AAC9D,QAAM,SAAS,IAAI,OAAO,OAAO;AAAA,IAC7B,WAAW,OAAO,KAAK,OAAO;AAAA,IAC9B,eAAe,OAAO,KAAK,OAAO;AAAA,EACtC,CAAC;AACD,QAAM,WAAW,MAAM,OAAO,MAAM,EAAE,YAAY,qBAAqB,CAAC;AAExE,QAAM,QAAQ,SAAS;AACvB,QAAM,YAAY,SAAS;AAE3B,MAAI,CAAC,OAAO;AACR,UAAM,IAAI,MAAM,qBAAqB;AAAA,EACzC;AAEA,SAAO,EAAE,OAAO,UAAU;AAC9B;;;AFpBO,IAAM,aAAa,YAAmC;AACzD,MAAI;AACA,UAAM,EAAE,OAAO,UAAU,IAAI,MAAM,SAAS;AAE5C,QAAI,CAAC,OAAO;AACR,aAAO,2BAAa,KAAK,EAAE,OAAO,sBAAsB,GAAG,EAAE,QAAQ,IAAI,CAAC;AAAA,IAC9E;AAEA,UAAM,WAAW,2BAAa,KAAK,EAAE,MAAa,CAAC;AAEnD,aAAS,QAAQ,IAAI;AAAA,MACjB,MAAM;AAAA,MACN,OAAO;AAAA,MACP,UAAU;AAAA,MACV,QAAQ,QAAQ,IAAI,aAAa;AAAA,MACjC,UAAU;AAAA,MACV,MAAM;AAAA,MACN,SAAS,YAAY,IAAI,KAAK,YAAY,GAAI,IAAI;AAAA,IACtD,CAAC;AAED,WAAO;AAAA,EAEX,SAAS,OAAO;AACZ,WAAO,2BAAa,KAAK,EAAE,OAAO,OAAO,KAAK,EAAE,GAAG,EAAE,QAAQ,IAAI,CAAC;AAAA,EACtE;AACJ;","names":[]}
|
package/dist/api/token.mjs
CHANGED
|
@@ -1,23 +1,44 @@
|
|
|
1
1
|
// src/api/token.ts
|
|
2
2
|
import { NextResponse } from "next/server";
|
|
3
|
-
import { Issuer } from "openid-client";
|
|
4
3
|
|
|
5
4
|
// ../constants/src/index.ts
|
|
6
5
|
var DEFAULT_COOKIE_LIMIT = 30 * 24 * 60 * 60 * 1e3;
|
|
7
6
|
var CREX_TOKEN_HEADER_KEY = "crex-token";
|
|
8
7
|
|
|
8
|
+
// src/token.ts
|
|
9
|
+
import { Issuer } from "openid-client";
|
|
10
|
+
|
|
11
|
+
// src/config.ts
|
|
12
|
+
import { cookies } from "next/headers";
|
|
13
|
+
function getServerConfig() {
|
|
14
|
+
if (!global.__GLOBAL_CONFIG__) {
|
|
15
|
+
throw new Error("Server config not initialized");
|
|
16
|
+
}
|
|
17
|
+
return global.__GLOBAL_CONFIG__;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// src/token.ts
|
|
21
|
+
var getToken = async () => {
|
|
22
|
+
console.log("veio buscar");
|
|
23
|
+
const config = getServerConfig();
|
|
24
|
+
const issuer = await Issuer.discover(config.OIDC.client.issuer);
|
|
25
|
+
const client = new issuer.Client({
|
|
26
|
+
client_id: config.OIDC.client.id,
|
|
27
|
+
client_secret: config.OIDC.client.secret
|
|
28
|
+
});
|
|
29
|
+
const tokenSet = await client.grant({ grant_type: "client_credentials" });
|
|
30
|
+
const token = tokenSet.access_token;
|
|
31
|
+
const expiresAt = tokenSet.expires_at;
|
|
32
|
+
if (!token) {
|
|
33
|
+
throw new Error("Failed to get token");
|
|
34
|
+
}
|
|
35
|
+
return { token, expiresAt };
|
|
36
|
+
};
|
|
37
|
+
|
|
9
38
|
// src/api/token.ts
|
|
10
|
-
import { getServerConfigs } from "@c-rex/utils/next-cookies";
|
|
11
39
|
var postMethod = async () => {
|
|
12
40
|
try {
|
|
13
|
-
const
|
|
14
|
-
const issuer = await Issuer.discover(customerConfig.OIDC.client.issuer);
|
|
15
|
-
const client = new issuer.Client({
|
|
16
|
-
client_id: customerConfig.OIDC.client.id,
|
|
17
|
-
client_secret: customerConfig.OIDC.client.secret
|
|
18
|
-
});
|
|
19
|
-
const tokenSet = await client.grant({ grant_type: "client_credentials" });
|
|
20
|
-
const token = tokenSet.access_token;
|
|
41
|
+
const { token, expiresAt } = await getToken();
|
|
21
42
|
if (!token) {
|
|
22
43
|
return NextResponse.json({ error: "Failed to get token" }, { status: 500 });
|
|
23
44
|
}
|
|
@@ -29,7 +50,7 @@ var postMethod = async () => {
|
|
|
29
50
|
secure: process.env.NODE_ENV === "production",
|
|
30
51
|
sameSite: "lax",
|
|
31
52
|
path: "/",
|
|
32
|
-
expires:
|
|
53
|
+
expires: expiresAt ? new Date(expiresAt * 1e3) : void 0
|
|
33
54
|
});
|
|
34
55
|
return response;
|
|
35
56
|
} catch (error) {
|
package/dist/api/token.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/api/token.ts","../../../constants/src/index.ts"],"sourcesContent":["import { NextResponse } from 'next/server';\nimport {
|
|
1
|
+
{"version":3,"sources":["../../src/api/token.ts","../../../constants/src/index.ts","../../src/token.ts","../../src/config.ts"],"sourcesContent":["import { NextResponse } from 'next/server';\nimport { CREX_TOKEN_HEADER_KEY } from '@c-rex/constants';\nimport { getToken } from '../token';\n\n/**\n * Retrieves an access token using client credentials flow from the configured OIDC provider\n * \n * @returns NextResponse with success status or error message\n * @throws Error if token retrieval fails\n */\nexport const postMethod = async (): Promise<NextResponse> => {\n try {\n const { token, expiresAt } = await getToken();\n\n if (!token) {\n return NextResponse.json({ error: 'Failed to get token' }, { status: 500 });\n }\n\n const response = NextResponse.json({ token: token });\n\n response.cookies.set({\n name: CREX_TOKEN_HEADER_KEY,\n value: token,\n httpOnly: true,\n secure: process.env.NODE_ENV === 'production',\n sameSite: 'lax',\n path: '/',\n expires: expiresAt ? new Date(expiresAt * 1000) : undefined\n });\n\n return response;\n\n } catch (error) {\n return NextResponse.json({ error: String(error) }, { status: 500 });\n }\n}\n","export const ALL = \"*\"\n\nexport const LOG_CATEGORIES = [\n \"NoLicense\",\n \"Scenario\",\n \"Favorites\",\n \"Subscription\",\n \"Share\",\n \"Document\",\n \"Search\",\n \"History\",\n \"Notification\",\n \"UserProfile\",\n] as const;\n\nexport const LOG_LEVELS = {\n critical: 2,\n error: 3,\n warning: 4,\n info: 6,\n debug: 7,\n} as const;\n\nexport const RESULT_VIEW_STYLES = [\n \"cards\",\n \"table\",\n \"table-with-images\",\n] as const;\n\nexport const API = {\n MAX_RETRY: 3,\n API_TIMEOUT: 10000,\n RETRY_DELAY: 500,\n API_HEADERS: {\n \"content-Type\": \"application/json\",\n },\n};\n\nexport const SDK_CONFIG_KEY = \"crex-sdk-config\";\n\nexport const CONTENT_LANG_KEY = \"CONTENT_LANG_KEY\";\n\nexport const AVAILABLE_CONTENT_LANG_KEY = \"AVAILABLE_CONTENT_LANG_KEY\";\n\nexport const UI_LANG_KEY = \"UI_LANG_KEY\";\n\nexport const FLAGS_BY_LANG = {\n \"en\": \"US\",\n \"de\": \"DE\",\n};\n\nexport const DEFAULT_LANG = \"en-US\";\n\nexport const EN_LANG = \"en\";\n\nexport const UI_LANG_OPTIONS = [\"en-us\", \"de-de\"];\n\nexport const TOPICS_TYPE_AND_LINK = \"topics\";\nexport const BLOG_TYPE_AND_LINK = \"blog\";\nexport const DOCUMENTS_TYPE_AND_LINK = \"documents\";\n\nexport const TOPIC = \"TOPIC\";\nexport const DOCUMENT = \"DOCUMENT\";\nexport const PACKAGE = \"PACKAGE\";\nexport const FRAGMENT = \"FRAGMENT\";\n\nexport const RESULT_TYPES = {\n TOPIC: TOPIC,\n DOCUMENT: DOCUMENT,\n PACKAGE: PACKAGE,\n FRAGMENT: FRAGMENT\n} as const;\n\nexport const FILES_EXTENSIONS = {\n PDF: \"application/pdf\",\n HTML: \"text/html\",\n} as const;\n\nexport const DEFAULT_COOKIE_LIMIT = 30 * 24 * 60 * 60 * 1000; // 30 days in milliseconds\n\nexport const ICONS_BY_FILE_EXTENSION = {\n \"application/pdf\": \"FaFilePdf\",\n} as const;\n\nexport const DEFAULT_ICON = \"file\";\n\nexport const CREX_TOKEN_HEADER_KEY = \"crex-token\";\n\nexport const WILD_CARD_OPTIONS = {\n BOTH: \"BOTH\",\n END: \"END\",\n START: \"START\",\n NONE: \"NONE\",\n} as const;\n\nexport const OPERATOR_OPTIONS = {\n AND: \"AND\",\n OR: \"OR\",\n} as const;\n\nexport const ARTICLE_PAGE_LAYOUT = {\n BLOG: \"BLOG\",\n DOCUMENT: \"DOCUMENT\",\n} as const;\n\nexport const DEVICE_OPTIONS = {\n MOBILE: \"mobile\",\n TABLET: \"tablet\",\n DESKTOP: \"desktop\",\n}\nexport const BREAKPOINTS = {\n sm: 640,\n md: 768,\n lg: 1024,\n xl: 1280,\n \"2xl\": 1536,\n};","import { Issuer } from 'openid-client';\nimport { getServerConfig } from './config';\n\n/**\n * Retrieves an access token using client credentials flow from the configured OIDC provider\n * \n * @returns NextResponse with success status or error message\n * @throws Error if token retrieval fails\n */\nexport const getToken = async (): Promise<{ token: string; expiresAt: number }> => {\n\n console.log(\"veio buscar\")\n\n const config = getServerConfig();\n\n const issuer = await Issuer.discover(config.OIDC.client.issuer);\n const client = new issuer.Client({\n client_id: config.OIDC.client.id,\n client_secret: config.OIDC.client.secret,\n });\n const tokenSet = await client.grant({ grant_type: 'client_credentials' });\n\n const token = tokenSet.access_token!;\n const expiresAt = tokenSet.expires_at!;\n\n if (!token) {\n throw new Error('Failed to get token');\n }\n\n return { token, expiresAt };\n}\n","import { ConfigInterface } from \"@c-rex/interfaces\";\nimport { SDK_CONFIG_KEY } from '@c-rex/constants';\nimport { CookiesConfigs } from '@c-rex/interfaces';\nimport { cookies } from 'next/headers';\n\n/**\n * Retrieves and parses configuration data from a cookie.\n * @returns The parsed configuration object\n * @throws Error if the configuration cookie is not found or cannot be parsed\n */\nexport const getClientConfig = (): CookiesConfigs => {\n const jsonConfigs = cookies().get(SDK_CONFIG_KEY)?.value;\n if (!jsonConfigs) {\n throw new Error('Configs not found');\n }\n\n const configs: CookiesConfigs = JSON.parse(jsonConfigs);\n\n return configs;\n}\n\ndeclare global {\n // eslint-disable-next-line no-var\n var __GLOBAL_CONFIG__: ConfigInterface | null;\n}\n\nexport function initializeConfig(config: ConfigInterface) {\n if (global.__GLOBAL_CONFIG__) return global.__GLOBAL_CONFIG__;\n global.__GLOBAL_CONFIG__ = config;\n return global.__GLOBAL_CONFIG__;\n}\n\nexport function getServerConfig() {\n if (!global.__GLOBAL_CONFIG__) {\n throw new Error('Server config not initialized');\n }\n return global.__GLOBAL_CONFIG__;\n}"],"mappings":";AAAA,SAAS,oBAAoB;;;AC8EtB,IAAM,uBAAuB,KAAK,KAAK,KAAK,KAAK;AAQjD,IAAM,wBAAwB;;;ACtFrC,SAAS,cAAc;;;ACGvB,SAAS,eAAe;AA6BjB,SAAS,kBAAkB;AAC9B,MAAI,CAAC,OAAO,mBAAmB;AAC3B,UAAM,IAAI,MAAM,+BAA+B;AAAA,EACnD;AACA,SAAO,OAAO;AAClB;;;AD5BO,IAAM,WAAW,YAA2D;AAE/E,UAAQ,IAAI,aAAa;AAEzB,QAAM,SAAS,gBAAgB;AAE/B,QAAM,SAAS,MAAM,OAAO,SAAS,OAAO,KAAK,OAAO,MAAM;AAC9D,QAAM,SAAS,IAAI,OAAO,OAAO;AAAA,IAC7B,WAAW,OAAO,KAAK,OAAO;AAAA,IAC9B,eAAe,OAAO,KAAK,OAAO;AAAA,EACtC,CAAC;AACD,QAAM,WAAW,MAAM,OAAO,MAAM,EAAE,YAAY,qBAAqB,CAAC;AAExE,QAAM,QAAQ,SAAS;AACvB,QAAM,YAAY,SAAS;AAE3B,MAAI,CAAC,OAAO;AACR,UAAM,IAAI,MAAM,qBAAqB;AAAA,EACzC;AAEA,SAAO,EAAE,OAAO,UAAU;AAC9B;;;AFpBO,IAAM,aAAa,YAAmC;AACzD,MAAI;AACA,UAAM,EAAE,OAAO,UAAU,IAAI,MAAM,SAAS;AAE5C,QAAI,CAAC,OAAO;AACR,aAAO,aAAa,KAAK,EAAE,OAAO,sBAAsB,GAAG,EAAE,QAAQ,IAAI,CAAC;AAAA,IAC9E;AAEA,UAAM,WAAW,aAAa,KAAK,EAAE,MAAa,CAAC;AAEnD,aAAS,QAAQ,IAAI;AAAA,MACjB,MAAM;AAAA,MACN,OAAO;AAAA,MACP,UAAU;AAAA,MACV,QAAQ,QAAQ,IAAI,aAAa;AAAA,MACjC,UAAU;AAAA,MACV,MAAM;AAAA,MACN,SAAS,YAAY,IAAI,KAAK,YAAY,GAAI,IAAI;AAAA,IACtD,CAAC;AAED,WAAO;AAAA,EAEX,SAAS,OAAO;AACZ,WAAO,aAAa,KAAK,EAAE,OAAO,OAAO,KAAK,EAAE,GAAG,EAAE,QAAQ,IAAI,CAAC;AAAA,EACtE;AACJ;","names":[]}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Method } from 'axios';
|
|
2
|
-
import { ConfigInterface } from '@c-rex/interfaces';
|
|
2
|
+
import { ConfigInterface, CookiesConfigs } from '@c-rex/interfaces';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Interface for API call parameters.
|
|
@@ -27,7 +27,6 @@ declare class CrexApi {
|
|
|
27
27
|
* @private
|
|
28
28
|
*/
|
|
29
29
|
private initAPI;
|
|
30
|
-
private getToken;
|
|
31
30
|
private manageToken;
|
|
32
31
|
/**
|
|
33
32
|
* Executes an API request with caching, authentication, and retry logic.
|
|
@@ -56,7 +55,7 @@ declare class CrexSDK {
|
|
|
56
55
|
*
|
|
57
56
|
* @private
|
|
58
57
|
*/
|
|
59
|
-
private
|
|
58
|
+
private getServerConfig;
|
|
60
59
|
/**
|
|
61
60
|
* Retrieves the user authentication configuration.
|
|
62
61
|
* If not already loaded, it will load the customer configuration and
|
|
@@ -67,4 +66,16 @@ declare class CrexSDK {
|
|
|
67
66
|
getUserAuthConfig(): Promise<any>;
|
|
68
67
|
}
|
|
69
68
|
|
|
70
|
-
|
|
69
|
+
/**
|
|
70
|
+
* Retrieves and parses configuration data from a cookie.
|
|
71
|
+
* @returns The parsed configuration object
|
|
72
|
+
* @throws Error if the configuration cookie is not found or cannot be parsed
|
|
73
|
+
*/
|
|
74
|
+
declare const getClientConfig: () => CookiesConfigs;
|
|
75
|
+
declare global {
|
|
76
|
+
var __GLOBAL_CONFIG__: ConfigInterface | null;
|
|
77
|
+
}
|
|
78
|
+
declare function initializeConfig(config: ConfigInterface): ConfigInterface;
|
|
79
|
+
declare function getServerConfig(): ConfigInterface;
|
|
80
|
+
|
|
81
|
+
export { CrexApi, CrexSDK, getClientConfig, getServerConfig, initializeConfig };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Method } from 'axios';
|
|
2
|
-
import { ConfigInterface } from '@c-rex/interfaces';
|
|
2
|
+
import { ConfigInterface, CookiesConfigs } from '@c-rex/interfaces';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Interface for API call parameters.
|
|
@@ -27,7 +27,6 @@ declare class CrexApi {
|
|
|
27
27
|
* @private
|
|
28
28
|
*/
|
|
29
29
|
private initAPI;
|
|
30
|
-
private getToken;
|
|
31
30
|
private manageToken;
|
|
32
31
|
/**
|
|
33
32
|
* Executes an API request with caching, authentication, and retry logic.
|
|
@@ -56,7 +55,7 @@ declare class CrexSDK {
|
|
|
56
55
|
*
|
|
57
56
|
* @private
|
|
58
57
|
*/
|
|
59
|
-
private
|
|
58
|
+
private getServerConfig;
|
|
60
59
|
/**
|
|
61
60
|
* Retrieves the user authentication configuration.
|
|
62
61
|
* If not already loaded, it will load the customer configuration and
|
|
@@ -67,4 +66,16 @@ declare class CrexSDK {
|
|
|
67
66
|
getUserAuthConfig(): Promise<any>;
|
|
68
67
|
}
|
|
69
68
|
|
|
70
|
-
|
|
69
|
+
/**
|
|
70
|
+
* Retrieves and parses configuration data from a cookie.
|
|
71
|
+
* @returns The parsed configuration object
|
|
72
|
+
* @throws Error if the configuration cookie is not found or cannot be parsed
|
|
73
|
+
*/
|
|
74
|
+
declare const getClientConfig: () => CookiesConfigs;
|
|
75
|
+
declare global {
|
|
76
|
+
var __GLOBAL_CONFIG__: ConfigInterface | null;
|
|
77
|
+
}
|
|
78
|
+
declare function initializeConfig(config: ConfigInterface): ConfigInterface;
|
|
79
|
+
declare function getServerConfig(): ConfigInterface;
|
|
80
|
+
|
|
81
|
+
export { CrexApi, CrexSDK, getClientConfig, getServerConfig, initializeConfig };
|