@c-rex/core 0.1.0 → 0.1.1
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/index.js +28 -21
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +28 -21
- package/dist/index.mjs.map +1 -1
- package/dist/logger.js +20 -63
- package/dist/logger.js.map +1 -1
- package/dist/logger.mjs +20 -63
- package/dist/logger.mjs.map +1 -1
- package/package.json +4 -2
package/dist/index.js
CHANGED
|
@@ -54,7 +54,7 @@ var import_openid_client = require("openid-client");
|
|
|
54
54
|
// ../utils/src/utils.ts
|
|
55
55
|
var call = async (method, params) => {
|
|
56
56
|
try {
|
|
57
|
-
const res = await fetch(
|
|
57
|
+
const res = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/api/rpc`, {
|
|
58
58
|
method: "POST",
|
|
59
59
|
headers: { "Content-Type": "application/json" },
|
|
60
60
|
body: JSON.stringify({ method, params })
|
|
@@ -94,6 +94,9 @@ var import_tailwind_merge = require("tailwind-merge");
|
|
|
94
94
|
// ../utils/src/treeOfContent.ts
|
|
95
95
|
var import_services = require("@c-rex/services");
|
|
96
96
|
|
|
97
|
+
// ../utils/src/articles.ts
|
|
98
|
+
var import_services2 = require("@c-rex/services");
|
|
99
|
+
|
|
97
100
|
// src/requests.ts
|
|
98
101
|
var import_next_cookies = require("@c-rex/utils/next-cookies");
|
|
99
102
|
var CREX_TOKEN_HEADER_KEY = "crex-token";
|
|
@@ -130,6 +133,7 @@ var CrexApi = class {
|
|
|
130
133
|
const tokenSet = await client.grant({ grant_type: "client_credentials" });
|
|
131
134
|
token = tokenSet.access_token;
|
|
132
135
|
tokenExpiry = now + tokenSet.expires_at;
|
|
136
|
+
console.log("token", token);
|
|
133
137
|
} catch (error) {
|
|
134
138
|
call("CrexLogger.log", {
|
|
135
139
|
level: "error",
|
|
@@ -215,27 +219,30 @@ var CrexSDK = class {
|
|
|
215
219
|
}
|
|
216
220
|
await this.getConfig();
|
|
217
221
|
const user = this.customerConfig.OIDC.user;
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
222
|
+
if (user.enabled) {
|
|
223
|
+
this.userAuthConfig = {
|
|
224
|
+
providers: [
|
|
225
|
+
{
|
|
226
|
+
id: "crex",
|
|
227
|
+
name: "CREX",
|
|
228
|
+
type: "oauth",
|
|
229
|
+
clientId: user.id,
|
|
230
|
+
wellKnown: user.issuer,
|
|
231
|
+
clientSecret: user.secret,
|
|
232
|
+
authorization: { params: { scope: user.scope } },
|
|
233
|
+
profile(profile) {
|
|
234
|
+
return {
|
|
235
|
+
id: profile.id || "fake Id",
|
|
236
|
+
name: profile.name || "Fake Name",
|
|
237
|
+
email: profile.email || "fake Email",
|
|
238
|
+
image: profile.image || "fake Image"
|
|
239
|
+
};
|
|
240
|
+
}
|
|
235
241
|
}
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
}
|
|
242
|
+
]
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
;
|
|
239
246
|
return this.userAuthConfig;
|
|
240
247
|
}
|
|
241
248
|
};
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/requests.ts","../../constants/src/index.ts","../../utils/src/utils.ts","../../utils/src/memory.ts","../../utils/src/classMerge.ts","../../utils/src/treeOfContent.ts","../src/sdk.ts"],"sourcesContent":["//Do not export logger.ts. Logger must be exported as an another entrypoint on package.json\nexport * from \"./requests\";\nexport * from \"./sdk\";","import axios, { AxiosResponse, Method, AxiosInstance } from \"axios\";\nimport { API, SDK_CONFIG_KEY } from \"@c-rex/constants\";\nimport { Issuer } from \"openid-client\";\nimport { ConfigInterface } from \"@c-rex/interfaces\";\nimport { call, getFromMemory, saveInMemory } from \"@c-rex/utils\";\nimport { getCookie } from \"@c-rex/utils/next-cookies\";\n\nconst CREX_TOKEN_HEADER_KEY = \"crex-token\";\nconst CREX_TOKEN_EXPIRY_HEADER_KEY = \"crex-token-expiry\";\n\ninterface APIGenericResponse<T> extends AxiosResponse {\n data: T;\n statusCode: number;\n}\n\ninterface CallParams {\n url: string;\n method: Method;\n body?: any;\n headers?: any;\n params?: any;\n}\n\nexport class CrexApi {\n private customerConfig!: ConfigInterface;\n private apiClient!: AxiosInstance;\n\n private async manageToken() {\n const headersAux: Record<string, string> = {};\n\n if (this.customerConfig.OIDC.client.enabled) {\n let token = getFromMemory(CREX_TOKEN_HEADER_KEY);\n let tokenExpiry = getFromMemory(CREX_TOKEN_EXPIRY_HEADER_KEY);\n\n const now = Math.floor(Date.now() / 1000);\n\n if (!(token && tokenExpiry > now + 60)) {\n const { token: tokenAux, tokenExpiry: tokenExpiryAux } = await this.getToken();\n\n token = tokenAux;\n\n saveInMemory(token, CREX_TOKEN_HEADER_KEY);\n saveInMemory(tokenExpiryAux, CREX_TOKEN_EXPIRY_HEADER_KEY);\n }\n\n headersAux['Authorization'] = `Bearer ${token}`;\n }\n\n return headersAux;\n }\n\n private async getToken(): Promise<{\n token: string;\n tokenExpiry: number;\n }> {\n let token = \"\";\n let tokenExpiry = 0;\n\n try {\n const now = Math.floor(Date.now() / 1000);\n const issuer = await Issuer.discover(this.customerConfig.OIDC.client.issuer);\n const client = new issuer.Client({\n client_id: this.customerConfig.OIDC.client.id,\n client_secret: this.customerConfig.OIDC.client.secret,\n });\n const tokenSet = await client.grant({ grant_type: 'client_credentials' });\n\n token = tokenSet.access_token!;\n tokenExpiry = now + tokenSet.expires_at!;\n } catch (error) {\n call(\"CrexLogger.log\", {\n level: \"error\",\n message: `API.getToken error when request ${this.customerConfig.OIDC.client.issuer}. Error: ${error}`\n });\n }\n\n return {\n token,\n tokenExpiry\n };\n }\n\n private async initAPI() {\n if (!this.customerConfig) {\n const jsonConfigs = await getCookie(SDK_CONFIG_KEY);\n if (!jsonConfigs) {\n throw new Error(\"SDK not initialized\");\n }\n this.customerConfig = JSON.parse(jsonConfigs) as ConfigInterface;\n }\n if (!this.apiClient) {\n this.apiClient = axios.create({\n baseURL: this.customerConfig.baseUrl,\n })\n }\n }\n\n async execute<T>({\n url,\n method,\n params,\n body,\n headers = {},\n }: CallParams): Promise<T> {\n\n await this.initAPI();\n\n let response: APIGenericResponse<T> | undefined = undefined;\n\n headers = {\n ...headers,\n ...await this.manageToken(),\n };\n\n for (let retry = 0; retry < API.MAX_RETRY; retry++) {\n try {\n response = await this.apiClient.request({\n url,\n method,\n data: body,\n params,\n headers,\n });\n\n break;\n } catch (error) {\n //TODO: add logger\n console.log(\n \"error\",\n `API.execute ${retry + 1}º error when request ${url}. Error: ${error}`\n );\n\n if (retry === API.MAX_RETRY - 1) {\n throw error;\n }\n }\n }\n\n if (response) {\n return response.data;\n }\n\n throw new Error(\"API.execute error: Failed to retrieve a valid response\");\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 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 UI_LANG_KEY = \"UI_LANG_KEY\";\n\nexport const FLAGS_BY_LANG = {\n \"en\": \"US\",\n \"de\": \"DE\",\n};\n\nexport const DEFAULT_UI_LANG = \"en\";\nexport const UI_LANG_OPTIONS = [\"en\", \"de\"];","import { FLAGS_BY_LANG } from \"@c-rex/constants\";\n\nexport const call = async<T = unknown>(method: string, params?: any): Promise<T> => {\n try {\n const res = await fetch(`/api/rpc`, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({ method, params }),\n });\n\n const json = await res.json();\n\n if (!res.ok) throw new Error(json.error || 'Unknown error');\n\n return json.data;\n } catch (error) {\n console.error(error);\n return null as any;\n }\n}\n\nexport const getCountryCodeByLang = (lang: string): string => {\n const mappedKeys = Object.keys(FLAGS_BY_LANG);\n\n if (!mappedKeys.includes(lang)) {\n return lang\n }\n\n type LangKey = keyof typeof FLAGS_BY_LANG;\n const country = FLAGS_BY_LANG[lang as LangKey]\n\n return country\n}","export function isBrowser() {\n return typeof window !== 'undefined' && typeof document !== 'undefined';\n}\n\nexport function saveInMemory(value: any, key: string) {\n if (isBrowser()) throw new Error(\"saveInMemory is not supported in browser\");\n\n if (typeof global !== 'undefined' && !(key in global)) {\n (global as any)[key] = null;\n }\n\n const globalConfig = (global as any)[key] as any;\n\n if (globalConfig === null) {\n (global as any)[key] = value;\n }\n}\n\nexport function getFromMemory(key: string): any {\n if (isBrowser()) throw new Error(\"getFromMemory is not supported in browser\");\n\n return (global as any)[key];\n}\n","import { clsx, type ClassValue } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nexport function cn(...inputs: ClassValue[]) {\n return twMerge(clsx(inputs));\n}\n","import { DirectoryNodesService } from \"@c-rex/services\";\nimport { DirectoryNodes, informationUnitsDirectories, TreeOfContent } from \"@c-rex/interfaces\";\n\nexport const generateTreeOfContent = async (\n directoryNodes: DirectoryNodes[],\n): Promise<TreeOfContent[]> => {\n\n const service = new DirectoryNodesService();\n\n if (directoryNodes.length == 0) return [];\n if (directoryNodes[0] == undefined) return [];\n\n let id = directoryNodes[0].shortId;\n let response = await service.getItem(id);\n const childList = await getChildrenInfo(response.childNodes);\n let result: TreeOfContent[] = childList;\n\n while (response.parents != undefined) {\n if (response.informationUnits[0] == undefined) return result;\n if (response.labels[0] == undefined) return result;\n if (response.parents[0] == undefined) return result;\n\n const infoId = response.informationUnits[0].shortId;\n const aux = {\n active: true,\n label: response.labels[0].value,\n id: response.shortId,\n link: `/info/${infoId}`,\n children: [...result],\n };\n id = response.parents[0].shortId;\n response = await service.getItem(id);\n\n const tree = await getChildrenInfo(response.childNodes, aux);\n\n result = [...tree];\n }\n\n return result;\n};\n\nconst getChildrenInfo = async (\n childNodes: informationUnitsDirectories[],\n childItem?: TreeOfContent,\n): Promise<TreeOfContent[]> => {\n const result: TreeOfContent[] = [];\n if (childNodes == undefined) return result;\n\n for (const item of childNodes) {\n if (item.labels[0] == undefined) break;\n\n const infoId = await getLink(item.shortId);\n let resultItem: TreeOfContent = {\n active: false,\n label: item.labels[0].value,\n link: `/info/${infoId}`,\n id: item.shortId,\n children: [],\n };\n\n if (childItem?.id == item.shortId) {\n resultItem = childItem;\n }\n result.push(resultItem);\n }\n\n return result;\n};\n\nconst getLink = async (id: string): Promise<string> => {\n const service = new DirectoryNodesService();\n const response = await service.getItem(id);\n\n if (response.informationUnits == undefined) return \"\";\n if (response.informationUnits[0] == undefined) return \"\";\n\n return response.informationUnits[0].shortId;\n};","import { SDK_CONFIG_KEY } from \"@c-rex/constants\";\nimport { ConfigInterface } from \"@c-rex/interfaces\";\nimport { getCookie } 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 const jsonConfigs = await getCookie(SDK_CONFIG_KEY);\n if (!jsonConfigs) {\n throw new Error(\"SDK not initialized\");\n }\n this.customerConfig = JSON.parse(jsonConfigs) as ConfigInterface;\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\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 return this.userAuthConfig;\n }\n}"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAA4D;;;ACuBrD,IAAM,MAAM;AAAA,EACf,WAAW;AAAA,EACX,aAAa;AAAA,EACb,aAAa;AAAA,IACT,gBAAgB;AAAA,EACpB;AACJ;AAEO,IAAM,iBAAiB;;;AD7B9B,2BAAuB;;;AEAhB,IAAM,OAAO,OAAmB,QAAgB,WAA6B;AAChF,MAAI;AACA,UAAM,MAAM,MAAM,MAAM,YAAY;AAAA,MAChC,QAAQ;AAAA,MACR,SAAS,EAAE,gBAAgB,mBAAmB;AAAA,MAC9C,MAAM,KAAK,UAAU,EAAE,QAAQ,OAAO,CAAC;AAAA,IAC3C,CAAC;AAED,UAAM,OAAO,MAAM,IAAI,KAAK;AAE5B,QAAI,CAAC,IAAI,GAAI,OAAM,IAAI,MAAM,KAAK,SAAS,eAAe;AAE1D,WAAO,KAAK;AAAA,EAChB,SAAS,OAAO;AACZ,YAAQ,MAAM,KAAK;AACnB,WAAO;AAAA,EACX;AACJ;;;ACnBO,SAAS,YAAY;AACxB,SAAO,OAAO,WAAW,eAAe,OAAO,aAAa;AAChE;AAEO,SAAS,aAAa,OAAY,KAAa;AAClD,MAAI,UAAU,EAAG,OAAM,IAAI,MAAM,0CAA0C;AAE3E,MAAI,OAAO,WAAW,eAAe,EAAE,OAAO,SAAS;AACnD,IAAC,OAAe,GAAG,IAAI;AAAA,EAC3B;AAEA,QAAM,eAAgB,OAAe,GAAG;AAExC,MAAI,iBAAiB,MAAM;AACvB,IAAC,OAAe,GAAG,IAAI;AAAA,EAC3B;AACJ;AAEO,SAAS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;;;AM9IA,IAAAC,uBAA0B;AAEnB,IAAM,UAAN,MAAc;AAAA,EACV;AAAA,EACA;AAAA,EAEP,MAAc,YAAY;AACtB,QAAI,CAAC,KAAK,gBAAgB;AACtB,YAAM,cAAc,UAAM,gCAAU,cAAc;AAClD,UAAI,CAAC,aAAa;AACd,cAAM,IAAI,MAAM,qBAAqB;AAAA,MACzC;AACA,WAAK,iBAAiB,KAAK,MAAM,WAAW;AAAA,IAChD;AAAA,EACJ;AAAA,EAEA,MAAa,oBAAoB;AAC7B,QAAI,KAAK,gBAAgB;AACrB,aAAO,KAAK;AAAA,IAChB;AAEA,UAAM,KAAK,UAAU;AAErB,UAAM,OAAO,KAAK,eAAe,KAAK;AAEtC,SAAK,iBAAiB;AAAA,MAClB,WAAW;AAAA,QACP;AAAA,UACI,IAAI;AAAA,UACJ,MAAM;AAAA,UACN,MAAM;AAAA,UACN,UAAU,KAAK;AAAA,UACf,WAAW,KAAK;AAAA,UAChB,cAAc,KAAK;AAAA,UACnB,eAAe,EAAE,QAAQ,EAAE,OAAO,KAAK,MAAM,EAAE;AAAA,UAC/C,QAAQ,SAAc;AAClB,mBAAO;AAAA,cACH,IAAI,QAAQ,MAAM;AAAA,cAClB,MAAM,QAAQ,QAAQ;AAAA,cACtB,OAAO,QAAQ,SAAS;AAAA,cACxB,OAAO,QAAQ,SAAS;AAAA,YAC5B;AAAA,UACJ;AAAA,QACJ;AAAA,MACJ;AAAA,IACJ;AAEA,WAAO,KAAK;AAAA,EAChB;AACJ;","names":["axios","import_next_cookies"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/requests.ts","../../constants/src/index.ts","../../utils/src/utils.ts","../../utils/src/memory.ts","../../utils/src/classMerge.ts","../../utils/src/treeOfContent.ts","../../utils/src/articles.ts","../src/sdk.ts"],"sourcesContent":["//Do not export logger.ts. Logger must be exported as an another entrypoint on package.json\nexport * from \"./requests\";\nexport * from \"./sdk\";","import axios, { AxiosResponse, Method, AxiosInstance } from \"axios\";\nimport { API, SDK_CONFIG_KEY } from \"@c-rex/constants\";\nimport { Issuer } from \"openid-client\";\nimport { ConfigInterface } from \"@c-rex/interfaces\";\nimport { call, getFromMemory, saveInMemory } from \"@c-rex/utils\";\nimport { getCookie } from \"@c-rex/utils/next-cookies\";\n\nconst CREX_TOKEN_HEADER_KEY = \"crex-token\";\nconst CREX_TOKEN_EXPIRY_HEADER_KEY = \"crex-token-expiry\";\n\ninterface APIGenericResponse<T> extends AxiosResponse {\n data: T;\n statusCode: number;\n}\n\ninterface CallParams {\n url: string;\n method: Method;\n body?: any;\n headers?: any;\n params?: any;\n}\n\nexport class CrexApi {\n private customerConfig!: ConfigInterface;\n private apiClient!: AxiosInstance;\n\n private async manageToken() {\n const headersAux: Record<string, string> = {};\n\n if (this.customerConfig.OIDC.client.enabled) {\n let token = getFromMemory(CREX_TOKEN_HEADER_KEY);\n let tokenExpiry = getFromMemory(CREX_TOKEN_EXPIRY_HEADER_KEY);\n\n const now = Math.floor(Date.now() / 1000);\n\n if (!(token && tokenExpiry > now + 60)) {\n const { token: tokenAux, tokenExpiry: tokenExpiryAux } = await this.getToken();\n\n token = tokenAux;\n\n saveInMemory(token, CREX_TOKEN_HEADER_KEY);\n saveInMemory(tokenExpiryAux, CREX_TOKEN_EXPIRY_HEADER_KEY);\n }\n\n headersAux['Authorization'] = `Bearer ${token}`;\n }\n\n return headersAux;\n }\n\n private async getToken(): Promise<{\n token: string;\n tokenExpiry: number;\n }> {\n let token = \"\";\n let tokenExpiry = 0;\n\n try {\n const now = Math.floor(Date.now() / 1000);\n const issuer = await Issuer.discover(this.customerConfig.OIDC.client.issuer);\n const client = new issuer.Client({\n client_id: this.customerConfig.OIDC.client.id,\n client_secret: this.customerConfig.OIDC.client.secret,\n });\n const tokenSet = await client.grant({ grant_type: 'client_credentials' });\n\n token = tokenSet.access_token!;\n tokenExpiry = now + tokenSet.expires_at!;\n\n console.log('token', token);\n\n } catch (error) {\n call(\"CrexLogger.log\", {\n level: \"error\",\n message: `API.getToken error when request ${this.customerConfig.OIDC.client.issuer}. Error: ${error}`\n });\n }\n\n return {\n token,\n tokenExpiry\n };\n }\n\n private async initAPI() {\n if (!this.customerConfig) {\n const jsonConfigs = await getCookie(SDK_CONFIG_KEY);\n if (!jsonConfigs) {\n throw new Error(\"SDK not initialized\");\n }\n this.customerConfig = JSON.parse(jsonConfigs) as ConfigInterface;\n }\n if (!this.apiClient) {\n this.apiClient = axios.create({\n baseURL: this.customerConfig.baseUrl,\n })\n }\n }\n\n async execute<T>({\n url,\n method,\n params,\n body,\n headers = {},\n }: CallParams): Promise<T> {\n\n await this.initAPI();\n\n let response: APIGenericResponse<T> | undefined = undefined;\n\n headers = {\n ...headers,\n ...await this.manageToken(),\n };\n\n for (let retry = 0; retry < API.MAX_RETRY; retry++) {\n try {\n response = await this.apiClient.request({\n url,\n method,\n data: body,\n params,\n headers,\n });\n\n break;\n } catch (error) {\n //TODO: add logger\n console.log(\n \"error\",\n `API.execute ${retry + 1}º error when request ${url}. Error: ${error}`\n );\n\n if (retry === API.MAX_RETRY - 1) {\n throw error;\n }\n }\n }\n\n if (response) {\n return response.data;\n }\n\n throw new Error(\"API.execute error: Failed to retrieve a valid response\");\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_UI_LANG = \"en\";\n\nexport const UI_LANG_OPTIONS = [\"en\", \"de\"];\n\nexport const RESULT_TYPES = {\n TOPIC: \"TOPIC\",\n DOCUMENT: \"DOCUMENT\",\n PACKAGE: \"PACKAGE\",\n} as const;","import { FLAGS_BY_LANG } from \"@c-rex/constants\";\n\nexport const call = async<T = unknown>(method: string, params?: any): Promise<T> => {\n try {\n const res = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/api/rpc`, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({ method, params }),\n });\n\n const json = await res.json();\n\n if (!res.ok) throw new Error(json.error || 'Unknown error');\n\n return json.data;\n } catch (error) {\n console.error(error);\n return null as any;\n }\n}\n\nexport const getCountryCodeByLang = (lang: string): string => {\n const mappedKeys = Object.keys(FLAGS_BY_LANG);\n\n if (!mappedKeys.includes(lang)) {\n return lang\n }\n\n type LangKey = keyof typeof FLAGS_BY_LANG;\n const country = FLAGS_BY_LANG[lang as LangKey]\n\n return country\n}","export function isBrowser() {\n return typeof window !== 'undefined' && typeof document !== 'undefined';\n}\n\nexport function saveInMemory(value: any, key: string) {\n if (isBrowser()) throw new Error(\"saveInMemory is not supported in browser\");\n\n if (typeof global !== 'undefined' && !(key in global)) {\n (global as any)[key] = null;\n }\n\n const globalConfig = (global as any)[key] as any;\n\n if (globalConfig === null) {\n (global as any)[key] = value;\n }\n}\n\nexport function getFromMemory(key: string): any {\n if (isBrowser()) throw new Error(\"getFromMemory is not supported in browser\");\n\n return (global as any)[key];\n}\n","import { clsx, type ClassValue } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nexport function cn(...inputs: ClassValue[]) {\n return twMerge(clsx(inputs));\n}\n","import { DirectoryNodesService } from \"@c-rex/services\";\nimport { DirectoryNodes, informationUnitsDirectories, TreeOfContent } from \"@c-rex/interfaces\";\n\nexport const generateTreeOfContent = async (\n directoryNodes: DirectoryNodes[],\n): Promise<TreeOfContent[]> => {\n\n const service = new DirectoryNodesService();\n\n if (directoryNodes.length == 0) return [];\n if (directoryNodes[0] == undefined) return [];\n\n let id = directoryNodes[0].shortId;\n let response = await service.getItem(id);\n const childList = await getChildrenInfo(response.childNodes);\n let result: TreeOfContent[] = childList;\n\n while (response.parents != undefined) {\n if (response.informationUnits[0] == undefined) return result;\n if (response.labels[0] == undefined) return result;\n if (response.parents[0] == undefined) return result;\n\n const infoId = response.informationUnits[0].shortId;\n const aux = {\n active: true,\n label: response.labels[0].value,\n id: response.shortId,\n link: `/info/${infoId}`,\n children: [...result],\n };\n id = response.parents[0].shortId;\n response = await service.getItem(id);\n\n const tree = await getChildrenInfo(response.childNodes, aux);\n\n result = [...tree];\n }\n\n return result;\n};\n\nconst getChildrenInfo = async (\n childNodes: informationUnitsDirectories[],\n childItem?: TreeOfContent,\n): Promise<TreeOfContent[]> => {\n const result: TreeOfContent[] = [];\n if (childNodes == undefined) return result;\n\n for (const item of childNodes) {\n if (item.labels[0] == undefined) break;\n\n const infoId = await getLink(item.shortId);\n let resultItem: TreeOfContent = {\n active: false,\n label: item.labels[0].value,\n link: `/info/${infoId}`,\n id: item.shortId,\n children: [],\n };\n\n if (childItem?.id == item.shortId) {\n resultItem = childItem;\n }\n result.push(resultItem);\n }\n\n return result;\n};\n\nconst getLink = async (id: string): Promise<string> => {\n const service = new DirectoryNodesService();\n const response = await service.getItem(id);\n\n if (response.informationUnits == undefined) return \"\";\n if (response.informationUnits[0] == undefined) return \"\";\n\n return response.informationUnits[0].shortId;\n};","import { InformationUnitsService, RenditionsService } from \"@c-rex/services\";\nimport { generateBreadcrumbItems, generateTreeOfContent } from \"@c-rex/utils\";\nimport { SidebarAvailableVersionsInterface, TreeOfContent } from \"@c-rex/interfaces\";\n\nexport const loadArticleData = async (id: string) => {\n const renditionService = new RenditionsService();\n const informationService = new InformationUnitsService();\n const informationUnitsItem = await informationService.getItem({ id });\n\n let title = \"\";\n let versionOf = \"\";\n let documentURL = \"\";\n let htmlContent = \"\";\n let treeOfContent: TreeOfContent[] = [];\n let breadcrumbItems: TreeOfContent[] = [];\n let availableVersions: Omit<SidebarAvailableVersionsInterface, \"link\">[] = [];\n\n if (informationUnitsItem != null) {\n if (informationUnitsItem.versionOf != undefined) {\n versionOf = informationUnitsItem.versionOf.shortId\n }\n if (informationUnitsItem.titles != undefined && informationUnitsItem.titles[0] != undefined) {\n title = informationUnitsItem.titles[0].value\n }\n }\n\n if (versionOf != undefined) {\n const versions = await informationService.getList({\n filters: [`versionOf.shortId=${versionOf}`],\n fields: [\"labels\"],\n })\n\n availableVersions = versions.items.map((item) => {\n return {\n shortId: item.shortId,\n lang: item.labels[0]?.language as string,\n country: item.labels[0]?.language.split(\"-\")[1] as string,\n }\n }).sort((a, b) => {\n if (a.lang < b.lang) {\n return -1;\n }\n if (a.lang > b.lang) {\n return 1;\n }\n return 0;\n })\n }\n\n if (informationUnitsItem?.renditions != undefined) {\n htmlContent = await renditionService.getHTMLRendition(informationUnitsItem.renditions)\n documentURL = await renditionService.getDocumentRendition(informationUnitsItem.renditions, \"pdf\")\n\n if (informationUnitsItem?.directoryNodes != undefined) {\n treeOfContent = await generateTreeOfContent(informationUnitsItem.directoryNodes);\n breadcrumbItems = generateBreadcrumbItems(treeOfContent);\n }\n }\n\n return {\n htmlContent,\n treeOfContent,\n breadcrumbItems,\n availableVersions,\n documentURL,\n title\n }\n};","import { SDK_CONFIG_KEY } from \"@c-rex/constants\";\nimport { ConfigInterface } from \"@c-rex/interfaces\";\nimport { getCookie } 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 const jsonConfigs = await getCookie(SDK_CONFIG_KEY);\n if (!jsonConfigs) {\n throw new Error(\"SDK not initialized\");\n }\n this.customerConfig = JSON.parse(jsonConfigs) as ConfigInterface;\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}"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAA4D;;;AC4BrD,IAAM,MAAM;AAAA,EACf,WAAW;AAAA,EACX,aAAa;AAAA,EACb,aAAa;AAAA,IACT,gBAAgB;AAAA,EACpB;AACJ;AAEO,IAAM,iBAAiB;;;ADlC9B,2BAAuB;;;AEAhB,IAAM,OAAO,OAAmB,QAAgB,WAA6B;AAChF,MAAI;AACA,UAAM,MAAM,MAAM,MAAM,GAAG,QAAQ,IAAI,mBAAmB,YAAY;AAAA,MAClE,QAAQ;AAAA,MACR,SAAS,EAAE,gBAAgB,mBAAmB;AAAA,MAC9C,MAAM,KAAK,UAAU,EAAE,QAAQ,OAAO,CAAC;AAAA,IAC3C,CAAC;AAED,UAAM,OAAO,MAAM,IAAI,KAAK;AAE5B,QAAI,CAAC,IAAI,GAAI,OAAM,IAAI,MAAM,KAAK,SAAS,eAAe;AAE1D,WAAO,KAAK;AAAA,EAChB,SAAS,OAAO;AACZ,YAAQ,MAAM,KAAK;AACnB,WAAO;AAAA,EACX;AACJ;;;ACnBO,SAAS,YAAY;AACxB,SAAO,OAAO,WAAW,eAAe,OAAO,a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cAC5B;AAAA,YACJ;AAAA,UACJ;AAAA,QACJ;AAAA,MACJ;AAAA,IACJ;AAAC;AAED,WAAO,KAAK;AAAA,EAChB;AACJ;","names":["import_services","axios","import_next_cookies"]}
|
package/dist/index.mjs
CHANGED
|
@@ -17,7 +17,7 @@ import { Issuer } from "openid-client";
|
|
|
17
17
|
// ../utils/src/utils.ts
|
|
18
18
|
var call = async (method, params) => {
|
|
19
19
|
try {
|
|
20
|
-
const res = await fetch(
|
|
20
|
+
const res = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/api/rpc`, {
|
|
21
21
|
method: "POST",
|
|
22
22
|
headers: { "Content-Type": "application/json" },
|
|
23
23
|
body: JSON.stringify({ method, params })
|
|
@@ -57,6 +57,9 @@ import { twMerge } from "tailwind-merge";
|
|
|
57
57
|
// ../utils/src/treeOfContent.ts
|
|
58
58
|
import { DirectoryNodesService } from "@c-rex/services";
|
|
59
59
|
|
|
60
|
+
// ../utils/src/articles.ts
|
|
61
|
+
import { InformationUnitsService, RenditionsService } from "@c-rex/services";
|
|
62
|
+
|
|
60
63
|
// src/requests.ts
|
|
61
64
|
import { getCookie } from "@c-rex/utils/next-cookies";
|
|
62
65
|
var CREX_TOKEN_HEADER_KEY = "crex-token";
|
|
@@ -93,6 +96,7 @@ var CrexApi = class {
|
|
|
93
96
|
const tokenSet = await client.grant({ grant_type: "client_credentials" });
|
|
94
97
|
token = tokenSet.access_token;
|
|
95
98
|
tokenExpiry = now + tokenSet.expires_at;
|
|
99
|
+
console.log("token", token);
|
|
96
100
|
} catch (error) {
|
|
97
101
|
call("CrexLogger.log", {
|
|
98
102
|
level: "error",
|
|
@@ -178,27 +182,30 @@ var CrexSDK = class {
|
|
|
178
182
|
}
|
|
179
183
|
await this.getConfig();
|
|
180
184
|
const user = this.customerConfig.OIDC.user;
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
185
|
+
if (user.enabled) {
|
|
186
|
+
this.userAuthConfig = {
|
|
187
|
+
providers: [
|
|
188
|
+
{
|
|
189
|
+
id: "crex",
|
|
190
|
+
name: "CREX",
|
|
191
|
+
type: "oauth",
|
|
192
|
+
clientId: user.id,
|
|
193
|
+
wellKnown: user.issuer,
|
|
194
|
+
clientSecret: user.secret,
|
|
195
|
+
authorization: { params: { scope: user.scope } },
|
|
196
|
+
profile(profile) {
|
|
197
|
+
return {
|
|
198
|
+
id: profile.id || "fake Id",
|
|
199
|
+
name: profile.name || "Fake Name",
|
|
200
|
+
email: profile.email || "fake Email",
|
|
201
|
+
image: profile.image || "fake Image"
|
|
202
|
+
};
|
|
203
|
+
}
|
|
198
204
|
}
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
}
|
|
205
|
+
]
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
;
|
|
202
209
|
return this.userAuthConfig;
|
|
203
210
|
}
|
|
204
211
|
};
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/requests.ts","../../constants/src/index.ts","../../utils/src/utils.ts","../../utils/src/memory.ts","../../utils/src/classMerge.ts","../../utils/src/treeOfContent.ts","../src/sdk.ts"],"sourcesContent":["import axios, { AxiosResponse, Method, AxiosInstance } from \"axios\";\nimport { API, SDK_CONFIG_KEY } from \"@c-rex/constants\";\nimport { Issuer } from \"openid-client\";\nimport { ConfigInterface } from \"@c-rex/interfaces\";\nimport { call, getFromMemory, saveInMemory } from \"@c-rex/utils\";\nimport { getCookie } from \"@c-rex/utils/next-cookies\";\n\nconst CREX_TOKEN_HEADER_KEY = \"crex-token\";\nconst CREX_TOKEN_EXPIRY_HEADER_KEY = \"crex-token-expiry\";\n\ninterface APIGenericResponse<T> extends AxiosResponse {\n data: T;\n statusCode: number;\n}\n\ninterface CallParams {\n url: string;\n method: Method;\n body?: any;\n headers?: any;\n params?: any;\n}\n\nexport class CrexApi {\n private customerConfig!: ConfigInterface;\n private apiClient!: AxiosInstance;\n\n private async manageToken() {\n const headersAux: Record<string, string> = {};\n\n if (this.customerConfig.OIDC.client.enabled) {\n let token = getFromMemory(CREX_TOKEN_HEADER_KEY);\n let tokenExpiry = getFromMemory(CREX_TOKEN_EXPIRY_HEADER_KEY);\n\n const now = Math.floor(Date.now() / 1000);\n\n if (!(token && tokenExpiry > now + 60)) {\n const { token: tokenAux, tokenExpiry: tokenExpiryAux } = await this.getToken();\n\n token = tokenAux;\n\n saveInMemory(token, CREX_TOKEN_HEADER_KEY);\n saveInMemory(tokenExpiryAux, CREX_TOKEN_EXPIRY_HEADER_KEY);\n }\n\n headersAux['Authorization'] = `Bearer ${token}`;\n }\n\n return headersAux;\n }\n\n private async getToken(): Promise<{\n token: string;\n tokenExpiry: number;\n }> {\n let token = \"\";\n let tokenExpiry = 0;\n\n try {\n const now = Math.floor(Date.now() / 1000);\n const issuer = await Issuer.discover(this.customerConfig.OIDC.client.issuer);\n const client = new issuer.Client({\n client_id: this.customerConfig.OIDC.client.id,\n client_secret: this.customerConfig.OIDC.client.secret,\n });\n const tokenSet = await client.grant({ grant_type: 'client_credentials' });\n\n token = tokenSet.access_token!;\n tokenExpiry = now + tokenSet.expires_at!;\n } catch (error) {\n call(\"CrexLogger.log\", {\n level: \"error\",\n message: `API.getToken error when request ${this.customerConfig.OIDC.client.issuer}. Error: ${error}`\n });\n }\n\n return {\n token,\n tokenExpiry\n };\n }\n\n private async initAPI() {\n if (!this.customerConfig) {\n const jsonConfigs = await getCookie(SDK_CONFIG_KEY);\n if (!jsonConfigs) {\n throw new Error(\"SDK not initialized\");\n }\n this.customerConfig = JSON.parse(jsonConfigs) as ConfigInterface;\n }\n if (!this.apiClient) {\n this.apiClient = axios.create({\n baseURL: this.customerConfig.baseUrl,\n })\n }\n }\n\n async execute<T>({\n url,\n method,\n params,\n body,\n headers = {},\n }: CallParams): Promise<T> {\n\n await this.initAPI();\n\n let response: APIGenericResponse<T> | undefined = undefined;\n\n headers = {\n ...headers,\n ...await this.manageToken(),\n };\n\n for (let retry = 0; retry < API.MAX_RETRY; retry++) {\n try {\n response = await this.apiClient.request({\n url,\n method,\n data: body,\n params,\n headers,\n });\n\n break;\n } catch (error) {\n //TODO: add logger\n console.log(\n \"error\",\n `API.execute ${retry + 1}º error when request ${url}. Error: ${error}`\n );\n\n if (retry === API.MAX_RETRY - 1) {\n throw error;\n }\n }\n }\n\n if (response) {\n return response.data;\n }\n\n throw new Error(\"API.execute error: Failed to retrieve a valid response\");\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 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 UI_LANG_KEY = \"UI_LANG_KEY\";\n\nexport const FLAGS_BY_LANG = {\n \"en\": \"US\",\n \"de\": \"DE\",\n};\n\nexport const DEFAULT_UI_LANG = \"en\";\nexport const UI_LANG_OPTIONS = [\"en\", \"de\"];","import { FLAGS_BY_LANG } from \"@c-rex/constants\";\n\nexport const call = async<T = unknown>(method: string, params?: any): Promise<T> => {\n try {\n const res = await fetch(`/api/rpc`, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({ method, params }),\n });\n\n const json = await res.json();\n\n if (!res.ok) throw new Error(json.error || 'Unknown error');\n\n return json.data;\n } catch (error) {\n console.error(error);\n return null as any;\n }\n}\n\nexport const getCountryCodeByLang = (lang: string): string => {\n const mappedKeys = Object.keys(FLAGS_BY_LANG);\n\n if (!mappedKeys.includes(lang)) {\n return lang\n }\n\n type LangKey = keyof typeof FLAGS_BY_LANG;\n const country = FLAGS_BY_LANG[lang as LangKey]\n\n return country\n}","export function isBrowser() {\n return typeof window !== 'undefined' && typeof document !== 'undefined';\n}\n\nexport function saveInMemory(value: any, key: string) {\n if (isBrowser()) throw new Error(\"saveInMemory is not supported in browser\");\n\n if (typeof global !== 'undefined' && !(key in global)) {\n (global as any)[key] = null;\n }\n\n const globalConfig = (global as any)[key] as any;\n\n if (globalConfig === null) {\n (global as any)[key] = value;\n }\n}\n\nexport function getFromMemory(key: string): any {\n if (isBrowser()) throw new Error(\"getFromMemory is not supported in browser\");\n\n return (global as any)[key];\n}\n","import { clsx, type ClassValue } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nexport function cn(...inputs: ClassValue[]) {\n return twMerge(clsx(inputs));\n}\n","import { DirectoryNodesService } from \"@c-rex/services\";\nimport { DirectoryNodes, informationUnitsDirectories, TreeOfContent } from \"@c-rex/interfaces\";\n\nexport const generateTreeOfContent = async (\n directoryNodes: DirectoryNodes[],\n): Promise<TreeOfContent[]> => {\n\n const service = new DirectoryNodesService();\n\n if (directoryNodes.length == 0) return [];\n if (directoryNodes[0] == undefined) return [];\n\n let id = directoryNodes[0].shortId;\n let response = await service.getItem(id);\n const childList = await getChildrenInfo(response.childNodes);\n let result: TreeOfContent[] = childList;\n\n while (response.parents != undefined) {\n if (response.informationUnits[0] == undefined) return result;\n if (response.labels[0] == undefined) return result;\n if (response.parents[0] == undefined) return result;\n\n const infoId = response.informationUnits[0].shortId;\n const aux = {\n active: true,\n label: response.labels[0].value,\n id: response.shortId,\n link: `/info/${infoId}`,\n children: [...result],\n };\n id = response.parents[0].shortId;\n response = await service.getItem(id);\n\n const tree = await getChildrenInfo(response.childNodes, aux);\n\n result = [...tree];\n }\n\n return result;\n};\n\nconst getChildrenInfo = async (\n childNodes: informationUnitsDirectories[],\n childItem?: TreeOfContent,\n): Promise<TreeOfContent[]> => {\n const result: TreeOfContent[] = [];\n if (childNodes == undefined) return result;\n\n for (const item of childNodes) {\n if (item.labels[0] == undefined) break;\n\n const infoId = await getLink(item.shortId);\n let resultItem: TreeOfContent = {\n active: false,\n label: item.labels[0].value,\n link: `/info/${infoId}`,\n id: item.shortId,\n children: [],\n };\n\n if (childItem?.id == item.shortId) {\n resultItem = childItem;\n }\n result.push(resultItem);\n }\n\n return result;\n};\n\nconst getLink = async (id: string): Promise<string> => {\n const service = new DirectoryNodesService();\n const response = await service.getItem(id);\n\n if (response.informationUnits == undefined) return \"\";\n if (response.informationUnits[0] == undefined) return \"\";\n\n return response.informationUnits[0].shortId;\n};","import { SDK_CONFIG_KEY } from \"@c-rex/constants\";\nimport { ConfigInterface } from \"@c-rex/interfaces\";\nimport { getCookie } 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 const jsonConfigs = await getCookie(SDK_CONFIG_KEY);\n if (!jsonConfigs) {\n throw new Error(\"SDK not initialized\");\n }\n this.customerConfig = JSON.parse(jsonConfigs) as ConfigInterface;\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\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 return this.userAuthConfig;\n }\n}"],"mappings":";AAAA,OA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,WAAW;AAAA,IAChD;AAAA,EACJ;AAAA,EAEA,MAAa,oBAAoB;AAC7B,QAAI,KAAK,gBAAgB;AACrB,aAAO,KAAK;AAAA,IAChB;AAEA,UAAM,KAAK,UAAU;AAErB,UAAM,OAAO,KAAK,eAAe,KAAK;AAEtC,SAAK,iBAAiB;AAAA,MAClB,WAAW;AAAA,QACP;AAAA,UACI,IAAI;AAAA,UACJ,MAAM;AAAA,UACN,MAAM;AAAA,UACN,UAAU,KAAK;AAAA,UACf,WAAW,KAAK;AAAA,UAChB,cAAc,KAAK;AAAA,UACnB,eAAe,EAAE,QAAQ,EAAE,OAAO,KAAK,MAAM,EAAE;AAAA,UAC/C,QAAQ,SAAc;AAClB,mBAAO;AAAA,cACH,IAAI,QAAQ,MAAM;AAAA,cAClB,MAAM,QAAQ,QAAQ;AAAA,cACtB,OAAO,QAAQ,SAAS;AAAA,cACxB,OAAO,QAAQ,SAAS;AAAA,YAC5B;AAAA,UACJ;AAAA,QACJ;AAAA,MACJ;AAAA,IACJ;AAEA,WAAO,KAAK;AAAA,EAChB;AACJ;","names":["getCookie"]}
|
|
1
|
+
{"version":3,"sources":["../src/requests.ts","../../constants/src/index.ts","../../utils/src/utils.ts","../../utils/src/memory.ts","../../utils/src/classMerge.ts","../../utils/src/treeOfContent.ts","../../utils/src/articles.ts","../src/sdk.ts"],"sourcesContent":["import axios, { AxiosResponse, Method, AxiosInstance } from \"axios\";\nimport { API, SDK_CONFIG_KEY } from \"@c-rex/constants\";\nimport { Issuer } from \"openid-client\";\nimport { ConfigInterface } from \"@c-rex/interfaces\";\nimport { call, getFromMemory, saveInMemory } from \"@c-rex/utils\";\nimport { getCookie } from \"@c-rex/utils/next-cookies\";\n\nconst CREX_TOKEN_HEADER_KEY = \"crex-token\";\nconst CREX_TOKEN_EXPIRY_HEADER_KEY = \"crex-token-expiry\";\n\ninterface APIGenericResponse<T> extends AxiosResponse {\n data: T;\n statusCode: number;\n}\n\ninterface CallParams {\n url: string;\n method: Method;\n body?: any;\n headers?: any;\n params?: any;\n}\n\nexport class CrexApi {\n private customerConfig!: ConfigInterface;\n private apiClient!: AxiosInstance;\n\n private async manageToken() {\n const headersAux: Record<string, string> = {};\n\n if (this.customerConfig.OIDC.client.enabled) {\n let token = getFromMemory(CREX_TOKEN_HEADER_KEY);\n let tokenExpiry = getFromMemory(CREX_TOKEN_EXPIRY_HEADER_KEY);\n\n const now = Math.floor(Date.now() / 1000);\n\n if (!(token && tokenExpiry > now + 60)) {\n const { token: tokenAux, tokenExpiry: tokenExpiryAux } = await this.getToken();\n\n token = tokenAux;\n\n saveInMemory(token, CREX_TOKEN_HEADER_KEY);\n saveInMemory(tokenExpiryAux, CREX_TOKEN_EXPIRY_HEADER_KEY);\n }\n\n headersAux['Authorization'] = `Bearer ${token}`;\n }\n\n return headersAux;\n }\n\n private async getToken(): Promise<{\n token: string;\n tokenExpiry: number;\n }> {\n let token = \"\";\n let tokenExpiry = 0;\n\n try {\n const now = Math.floor(Date.now() / 1000);\n const issuer = await Issuer.discover(this.customerConfig.OIDC.client.issuer);\n const client = new issuer.Client({\n client_id: this.customerConfig.OIDC.client.id,\n client_secret: this.customerConfig.OIDC.client.secret,\n });\n const tokenSet = await client.grant({ grant_type: 'client_credentials' });\n\n token = tokenSet.access_token!;\n tokenExpiry = now + tokenSet.expires_at!;\n\n console.log('token', token);\n\n } catch (error) {\n call(\"CrexLogger.log\", {\n level: \"error\",\n message: `API.getToken error when request ${this.customerConfig.OIDC.client.issuer}. Error: ${error}`\n });\n }\n\n return {\n token,\n tokenExpiry\n };\n }\n\n private async initAPI() {\n if (!this.customerConfig) {\n const jsonConfigs = await getCookie(SDK_CONFIG_KEY);\n if (!jsonConfigs) {\n throw new Error(\"SDK not initialized\");\n }\n this.customerConfig = JSON.parse(jsonConfigs) as ConfigInterface;\n }\n if (!this.apiClient) {\n this.apiClient = axios.create({\n baseURL: this.customerConfig.baseUrl,\n })\n }\n }\n\n async execute<T>({\n url,\n method,\n params,\n body,\n headers = {},\n }: CallParams): Promise<T> {\n\n await this.initAPI();\n\n let response: APIGenericResponse<T> | undefined = undefined;\n\n headers = {\n ...headers,\n ...await this.manageToken(),\n };\n\n for (let retry = 0; retry < API.MAX_RETRY; retry++) {\n try {\n response = await this.apiClient.request({\n url,\n method,\n data: body,\n params,\n headers,\n });\n\n break;\n } catch (error) {\n //TODO: add logger\n console.log(\n \"error\",\n `API.execute ${retry + 1}º error when request ${url}. Error: ${error}`\n );\n\n if (retry === API.MAX_RETRY - 1) {\n throw error;\n }\n }\n }\n\n if (response) {\n return response.data;\n }\n\n throw new Error(\"API.execute error: Failed to retrieve a valid response\");\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_UI_LANG = \"en\";\n\nexport const UI_LANG_OPTIONS = [\"en\", \"de\"];\n\nexport const RESULT_TYPES = {\n TOPIC: \"TOPIC\",\n DOCUMENT: \"DOCUMENT\",\n PACKAGE: \"PACKAGE\",\n} as const;","import { FLAGS_BY_LANG } from \"@c-rex/constants\";\n\nexport const call = async<T = unknown>(method: string, params?: any): Promise<T> => {\n try {\n const res = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/api/rpc`, {\n method: 'POST',\n headers: { 'Content-Type': 'application/json' },\n body: JSON.stringify({ method, params }),\n });\n\n const json = await res.json();\n\n if (!res.ok) throw new Error(json.error || 'Unknown error');\n\n return json.data;\n } catch (error) {\n console.error(error);\n return null as any;\n }\n}\n\nexport const getCountryCodeByLang = (lang: string): string => {\n const mappedKeys = Object.keys(FLAGS_BY_LANG);\n\n if (!mappedKeys.includes(lang)) {\n return lang\n }\n\n type LangKey = keyof typeof FLAGS_BY_LANG;\n const country = FLAGS_BY_LANG[lang as LangKey]\n\n return country\n}","export function isBrowser() {\n return typeof window !== 'undefined' && typeof document !== 'undefined';\n}\n\nexport function saveInMemory(value: any, key: string) {\n if (isBrowser()) throw new Error(\"saveInMemory is not supported in browser\");\n\n if (typeof global !== 'undefined' && !(key in global)) {\n (global as any)[key] = null;\n }\n\n const globalConfig = (global as any)[key] as any;\n\n if (globalConfig === null) {\n (global as any)[key] = value;\n }\n}\n\nexport function getFromMemory(key: string): any {\n if (isBrowser()) throw new Error(\"getFromMemory is not supported in browser\");\n\n return (global as any)[key];\n}\n","import { clsx, type ClassValue } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nexport function cn(...inputs: ClassValue[]) {\n return twMerge(clsx(inputs));\n}\n","import { DirectoryNodesService } from \"@c-rex/services\";\nimport { DirectoryNodes, informationUnitsDirectories, TreeOfContent } from \"@c-rex/interfaces\";\n\nexport const generateTreeOfContent = async (\n directoryNodes: DirectoryNodes[],\n): Promise<TreeOfContent[]> => {\n\n const service = new DirectoryNodesService();\n\n if (directoryNodes.length == 0) return [];\n if (directoryNodes[0] == undefined) return [];\n\n let id = directoryNodes[0].shortId;\n let response = await service.getItem(id);\n const childList = await getChildrenInfo(response.childNodes);\n let result: TreeOfContent[] = childList;\n\n while (response.parents != undefined) {\n if (response.informationUnits[0] == undefined) return result;\n if (response.labels[0] == undefined) return result;\n if (response.parents[0] == undefined) return result;\n\n const infoId = response.informationUnits[0].shortId;\n const aux = {\n active: true,\n label: response.labels[0].value,\n id: response.shortId,\n link: `/info/${infoId}`,\n children: [...result],\n };\n id = response.parents[0].shortId;\n response = await service.getItem(id);\n\n const tree = await getChildrenInfo(response.childNodes, aux);\n\n result = [...tree];\n }\n\n return result;\n};\n\nconst getChildrenInfo = async (\n childNodes: informationUnitsDirectories[],\n childItem?: TreeOfContent,\n): Promise<TreeOfContent[]> => {\n const result: TreeOfContent[] = [];\n if (childNodes == undefined) return result;\n\n for (const item of childNodes) {\n if (item.labels[0] == undefined) break;\n\n const infoId = await getLink(item.shortId);\n let resultItem: TreeOfContent = {\n active: false,\n label: item.labels[0].value,\n link: `/info/${infoId}`,\n id: item.shortId,\n children: [],\n };\n\n if (childItem?.id == item.shortId) {\n resultItem = childItem;\n }\n result.push(resultItem);\n }\n\n return result;\n};\n\nconst getLink = async (id: string): Promise<string> => {\n const service = new DirectoryNodesService();\n const response = await service.getItem(id);\n\n if (response.informationUnits == undefined) return \"\";\n if (response.informationUnits[0] == undefined) return \"\";\n\n return response.informationUnits[0].shortId;\n};","import { InformationUnitsService, RenditionsService } from \"@c-rex/services\";\nimport { generateBreadcrumbItems, generateTreeOfContent } from \"@c-rex/utils\";\nimport { SidebarAvailableVersionsInterface, TreeOfContent } from \"@c-rex/interfaces\";\n\nexport const loadArticleData = async (id: string) => {\n const renditionService = new RenditionsService();\n const informationService = new InformationUnitsService();\n const informationUnitsItem = await informationService.getItem({ id });\n\n let title = \"\";\n let versionOf = \"\";\n let documentURL = \"\";\n let htmlContent = \"\";\n let treeOfContent: TreeOfContent[] = [];\n let breadcrumbItems: TreeOfContent[] = [];\n let availableVersions: Omit<SidebarAvailableVersionsInterface, \"link\">[] = [];\n\n if (informationUnitsItem != null) {\n if (informationUnitsItem.versionOf != undefined) {\n versionOf = informationUnitsItem.versionOf.shortId\n }\n if (informationUnitsItem.titles != undefined && informationUnitsItem.titles[0] != undefined) {\n title = informationUnitsItem.titles[0].value\n }\n }\n\n if (versionOf != undefined) {\n const versions = await informationService.getList({\n filters: [`versionOf.shortId=${versionOf}`],\n fields: [\"labels\"],\n })\n\n availableVersions = versions.items.map((item) => {\n return {\n shortId: item.shortId,\n lang: item.labels[0]?.language as string,\n country: item.labels[0]?.language.split(\"-\")[1] as string,\n }\n }).sort((a, b) => {\n if (a.lang < b.lang) {\n return -1;\n }\n if (a.lang > b.lang) {\n return 1;\n }\n return 0;\n })\n }\n\n if (informationUnitsItem?.renditions != undefined) {\n htmlContent = await renditionService.getHTMLRendition(informationUnitsItem.renditions)\n documentURL = await renditionService.getDocumentRendition(informationUnitsItem.renditions, \"pdf\")\n\n if (informationUnitsItem?.directoryNodes != undefined) {\n treeOfContent = await generateTreeOfContent(informationUnitsItem.directoryNodes);\n breadcrumbItems = generateBreadcrumbItems(treeOfContent);\n }\n }\n\n return {\n htmlContent,\n treeOfContent,\n breadcrumbItems,\n availableVersions,\n documentURL,\n title\n }\n};","import { SDK_CONFIG_KEY } from \"@c-rex/constants\";\nimport { ConfigInterface } from \"@c-rex/interfaces\";\nimport { getCookie } 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 const jsonConfigs = await getCookie(SDK_CONFIG_KEY);\n if (!jsonConfigs) {\n throw new Error(\"SDK not initialized\");\n }\n this.customerConfig = JSON.parse(jsonConfigs) as ConfigInterface;\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}"],"mappings":";AAAA,OAAO,WAAqD;;;AC4BrD,IAAM,MAAM;AAAA,EACf,WAAW;AAAA,EACX,aAAa;AAAA,EACb,aAAa;AAAA,IACT,gBAAgB;AAAA,EACpB;AACJ;AAEO,IAAM,iBAAiB;;;ADlC9B,SAAS,cAAc;;;AEAhB,IAAM,OAAO,OAAmB,QAAgB,WAA6B;AAChF,MAAI;AACA,UAAM,MAAM,MAAM,MAAM,GAAG,QAAQ,IAAI,mBAAmB,YAAY;AAAA,MAClE,QAAQ;AAAA,MACR,SAAS,EAAE,gBAAgB,mBAAmB;AAAA,MAC9C,MAAM,KAAK,UAAU,EAAE,QAAQ,OAAO,CAAC;AAAA,IAC3C,CAAC;AAED,UAAM,OAAO,MAAM,IAAI,KAAK;AAE5B,QAAI,CAAC,IAAI,GAAI,OAAM,IAAI,MAAM,KAAK,SAAS,eAAe;AAE1D,WAAO,KAAK;AAAA,EAChB,SAAS,OAAO;AACZ,YAAQ,MAAM,KAAK;AACnB,WAAO;AAAA,EACX;AACJ;;;ACnBO,SAAS,YAAY;AACxB,SAAO,OAAO,WAAW,eAAe,OAAO,aAAa;AAChE;AAEO,SAAS,aAAa,OAAY,KAAa;AAClD,MAAI,UAAU,EAAG,OAAM,IAAI,MAAM,0CAA0C;AAE3E,MAAI,OAAO,WAAW,eAAe,EAAE,OAAO,SAAS;AACnD,IAAC,OAAe,GAAG,IAAI;AAAA,EAC3B;AAEA,QAAM,eAAgB,OAAe,GAAG;AAExC,MAAI,iBAAiB,MAAM;AACvB,IAAC,OAAe,GAAG,IAAI;AAAA,EAC3B;AACJ;AAEO,SAAS,cAAc,KAAkB;AAC5C,MAAI,UAAU,EAAG,OAAM,IAAI,MAAM,2CAA2C;AAE5E,SAAQ,OAAe,GAAG;AAC9B;;;ACtBA,SAAS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B,IAAM,UAAN,MAAc;AAAA,EACV;AAAA,EACA;AAAA,EAEP,MAAc,YAAY;AACtB,QAAI,CAAC,KAAK,gBAAgB;AACtB,YAAM,cAAc,MAAMA,WAAU,cAAc;AAClD,UAAI,CAAC,aAAa;AACd,cAAM,IAAI,MAAM,qBAAqB;AAAA,MACzC;AACA,WAAK,iBAAiB,KAAK,MAAM,WAAW;AAAA,IAChD;AAAA,EACJ;AAAA,EAEA,MAAa,oBAAoB;AAC7B,QAAI,KAAK,gBAAgB;AACrB,aAAO,KAAK;AAAA,IAChB;AAEA,UAAM,KAAK,UAAU;AAErB,UAAM,OAAO,KAAK,eAAe,KAAK;AACtC,QAAI,KAAK,SAAS;AACd,WAAK,iBAAiB;AAAA,QAClB,WAAW;AAAA,UACP;AAAA,YACI,IAAI;AAAA,YACJ,MAAM;AAAA,YACN,MAAM;AAAA,YACN,UAAU,KAAK;AAAA,YACf,WAAW,KAAK;AAAA,YAChB,cAAc,KAAK;AAAA,YACnB,eAAe,EAAE,QAAQ,EAAE,OAAO,KAAK,MAAM,EAAE;AAAA,YAC/C,QAAQ,SAAc;AAClB,qBAAO;AAAA,gBACH,IAAI,QAAQ,MAAM;AAAA,gBAClB,MAAM,QAAQ,QAAQ;AAAA,gBACtB,OAAO,QAAQ,SAAS;AAAA,gBACxB,OAAO,QAAQ,SAAS;AAAA,cAC5B;AAAA,YACJ;AAAA,UACJ;AAAA,QACJ;AAAA,MACJ;AAAA,IACJ;AAAC;AAED,WAAO,KAAK;AAAA,EAChB;AACJ;","names":["getCookie"]}
|
package/dist/logger.js
CHANGED
|
@@ -49,61 +49,20 @@ var LOG_LEVELS = {
|
|
|
49
49
|
};
|
|
50
50
|
var SDK_CONFIG_KEY = "crex-sdk-config";
|
|
51
51
|
|
|
52
|
-
// src/sdk.ts
|
|
53
|
-
var import_next_cookies = require("@c-rex/utils/next-cookies");
|
|
54
|
-
var CrexSDK = class {
|
|
55
|
-
userAuthConfig;
|
|
56
|
-
customerConfig;
|
|
57
|
-
async getConfig() {
|
|
58
|
-
if (!this.customerConfig) {
|
|
59
|
-
const jsonConfigs = await (0, import_next_cookies.getCookie)(SDK_CONFIG_KEY);
|
|
60
|
-
if (!jsonConfigs) {
|
|
61
|
-
throw new Error("SDK not initialized");
|
|
62
|
-
}
|
|
63
|
-
this.customerConfig = JSON.parse(jsonConfigs);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
async getUserAuthConfig() {
|
|
67
|
-
if (this.userAuthConfig) {
|
|
68
|
-
return this.userAuthConfig;
|
|
69
|
-
}
|
|
70
|
-
await this.getConfig();
|
|
71
|
-
const user = this.customerConfig.OIDC.user;
|
|
72
|
-
this.userAuthConfig = {
|
|
73
|
-
providers: [
|
|
74
|
-
{
|
|
75
|
-
id: "crex",
|
|
76
|
-
name: "CREX",
|
|
77
|
-
type: "oauth",
|
|
78
|
-
clientId: user.id,
|
|
79
|
-
wellKnown: user.issuer,
|
|
80
|
-
clientSecret: user.secret,
|
|
81
|
-
authorization: { params: { scope: user.scope } },
|
|
82
|
-
profile(profile) {
|
|
83
|
-
return {
|
|
84
|
-
id: profile.id || "fake Id",
|
|
85
|
-
name: profile.name || "Fake Name",
|
|
86
|
-
email: profile.email || "fake Email",
|
|
87
|
-
image: profile.image || "fake Image"
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
]
|
|
92
|
-
};
|
|
93
|
-
return this.userAuthConfig;
|
|
94
|
-
}
|
|
95
|
-
};
|
|
96
|
-
|
|
97
52
|
// src/transports/matomo.ts
|
|
98
53
|
var MatomoTransport = class extends import_winston_transport.default {
|
|
99
54
|
matomoTransport;
|
|
100
|
-
|
|
101
|
-
|
|
55
|
+
configs;
|
|
56
|
+
constructor(configs) {
|
|
57
|
+
super({
|
|
58
|
+
level: configs.logs.console.minimumLevel,
|
|
59
|
+
silent: configs.logs.console.silent
|
|
60
|
+
});
|
|
102
61
|
this.matomoTransport = new import_winston_transport.default();
|
|
62
|
+
this.configs = configs;
|
|
103
63
|
}
|
|
104
64
|
log(info, callback) {
|
|
105
|
-
const
|
|
106
|
-
const matomoCategory = SDK.customerConfig.logs.matomo.categoriesLevel;
|
|
65
|
+
const matomoCategory = this.configs.logs.matomo.categoriesLevel;
|
|
107
66
|
if (matomoCategory.includes(info.category) || matomoCategory.includes(ALL)) {
|
|
108
67
|
this.matomoTransport.log(info, callback);
|
|
109
68
|
}
|
|
@@ -115,8 +74,13 @@ var import_winston_transport2 = __toESM(require("winston-transport"));
|
|
|
115
74
|
var import_winston_graylog2 = __toESM(require("winston-graylog2"));
|
|
116
75
|
var GraylogTransport = class extends import_winston_transport2.default {
|
|
117
76
|
graylogTransport;
|
|
118
|
-
|
|
119
|
-
|
|
77
|
+
configs;
|
|
78
|
+
constructor(configs) {
|
|
79
|
+
super({
|
|
80
|
+
level: configs.logs.graylog.minimumLevel,
|
|
81
|
+
silent: configs.logs.graylog.silent
|
|
82
|
+
});
|
|
83
|
+
this.configs = configs;
|
|
120
84
|
this.graylogTransport = new import_winston_graylog2.default({
|
|
121
85
|
name: "Periotto-TEST",
|
|
122
86
|
silent: false,
|
|
@@ -127,8 +91,7 @@ var GraylogTransport = class extends import_winston_transport2.default {
|
|
|
127
91
|
});
|
|
128
92
|
}
|
|
129
93
|
log(info, callback) {
|
|
130
|
-
const
|
|
131
|
-
const graylogCategory = SDK.customerConfig.logs.graylog.categoriesLevel;
|
|
94
|
+
const graylogCategory = this.configs.logs.graylog.categoriesLevel;
|
|
132
95
|
if (graylogCategory.includes(info.category) || graylogCategory.includes(ALL)) {
|
|
133
96
|
this.graylogTransport.log(info, callback);
|
|
134
97
|
}
|
|
@@ -136,13 +99,13 @@ var GraylogTransport = class extends import_winston_transport2.default {
|
|
|
136
99
|
};
|
|
137
100
|
|
|
138
101
|
// src/logger.ts
|
|
139
|
-
var
|
|
102
|
+
var import_next_cookies = require("@c-rex/utils/next-cookies");
|
|
140
103
|
var CrexLogger = class {
|
|
141
104
|
customerConfig;
|
|
142
105
|
logger;
|
|
143
106
|
async initLogger() {
|
|
144
107
|
if (!this.customerConfig) {
|
|
145
|
-
const jsonConfigs = await (0,
|
|
108
|
+
const jsonConfigs = await (0, import_next_cookies.getCookie)(SDK_CONFIG_KEY);
|
|
146
109
|
if (!jsonConfigs) {
|
|
147
110
|
throw new Error("SDK not initialized");
|
|
148
111
|
}
|
|
@@ -164,14 +127,8 @@ var CrexLogger = class {
|
|
|
164
127
|
level: this.customerConfig.logs.console.minimumLevel,
|
|
165
128
|
silent: this.customerConfig.logs.console.silent
|
|
166
129
|
}),
|
|
167
|
-
new MatomoTransport(
|
|
168
|
-
|
|
169
|
-
silent: this.customerConfig.logs.console.silent
|
|
170
|
-
}),
|
|
171
|
-
new GraylogTransport({
|
|
172
|
-
level: this.customerConfig.logs.graylog.minimumLevel,
|
|
173
|
-
silent: this.customerConfig.logs.graylog.silent
|
|
174
|
-
})
|
|
130
|
+
new MatomoTransport(this.customerConfig),
|
|
131
|
+
new GraylogTransport(this.customerConfig)
|
|
175
132
|
]
|
|
176
133
|
});
|
|
177
134
|
}
|
package/dist/logger.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/logger.ts","../src/transports/matomo.ts","../../constants/src/index.ts","../src/
|
|
1
|
+
{"version":3,"sources":["../src/logger.ts","../src/transports/matomo.ts","../../constants/src/index.ts","../src/transports/graylog.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, SDK_CONFIG_KEY } from \"@c-rex/constants\";\nimport { getCookie } 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 const jsonConfigs = await getCookie(SDK_CONFIG_KEY);\n if (!jsonConfigs) {\n throw new Error(\"SDK not initialized\");\n }\n this.customerConfig = JSON.parse(jsonConfigs) as ConfigInterface;\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","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_UI_LANG = \"en\";\n\nexport const UI_LANG_OPTIONS = [\"en\", \"de\"];\n\nexport const RESULT_TYPES = {\n TOPIC: \"TOPIC\",\n DOCUMENT: \"DOCUMENT\",\n PACKAGE: \"PACKAGE\",\n} as const;","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;AAAA,qBAAoB;;;ACApB,+BAAsB;;;ACAf,IAAM,MAAM;AAeZ,IAAM,aAAa;AAAA,EACtB,UAAU;AAAA,EACV,OAAO;AAAA,EACP,SAAS;AAAA,EACT,MAAM;A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EnB,IAAM,aAAN,MAAiB;AAAA,EACZ;AAAA,EACD;AAAA,EAEP,MAAc,aAAa;AACvB,QAAI,CAAC,KAAK,gBAAgB;AACtB,YAAM,cAAc,UAAM,+BAAU,cAAc;AAClD,UAAI,CAAC,aAAa;AACd,cAAM,IAAI,MAAM,qBAAqB;AAAA,MACzC;AACA,WAAK,iBAAiB,KAAK,MAAM,WAAW;AAAA,IAChD;AAEA,QAAI,CAAC,KAAK,QAAQ;AACd,WAAK,SAAS,KAAK,aAAa;AAAA,IACpC;AAAA,EACJ;AAAA,EAEA,MAAa,IAAI,EAAE,OAAO,SAAS,SAAS,GAIzC;AACC,UAAM,KAAK,WAAW;AACtB,SAAK,OAAO,IAAI,OAAO,SAAS,QAAQ;AAAA,EAC5C;AAAA,EAEQ,eAAe;AACnB,WAAO,eAAAC,QAAQ,aAAa;AAAA,MACxB,QAAQ;AAAA,MACR,YAAY;AAAA,QACR,IAAI,eAAAA,QAAQ,WAAW,QAAQ;AAAA,UAC3B,OAAO,KAAK,eAAe,KAAK,QAAQ;AAAA,UACxC,QAAQ,KAAK,eAAe,KAAK,QAAQ;AAAA,QAC7C,CAAC;AAAA,QACD,IAAI,gBAAgB,KAAK,cAAc;AAAA,QACvC,IAAI,iBAAiB,KAAK,cAAc;AAAA,MAC5C;AAAA,IACJ,CAAC;AAAA,EACL;AACJ;","names":["Transport","import_winston_transport","Transport","Graylog2Transport","winston"]}
|
package/dist/logger.mjs
CHANGED
|
@@ -15,61 +15,20 @@ var LOG_LEVELS = {
|
|
|
15
15
|
};
|
|
16
16
|
var SDK_CONFIG_KEY = "crex-sdk-config";
|
|
17
17
|
|
|
18
|
-
// src/sdk.ts
|
|
19
|
-
import { getCookie } from "@c-rex/utils/next-cookies";
|
|
20
|
-
var CrexSDK = class {
|
|
21
|
-
userAuthConfig;
|
|
22
|
-
customerConfig;
|
|
23
|
-
async getConfig() {
|
|
24
|
-
if (!this.customerConfig) {
|
|
25
|
-
const jsonConfigs = await getCookie(SDK_CONFIG_KEY);
|
|
26
|
-
if (!jsonConfigs) {
|
|
27
|
-
throw new Error("SDK not initialized");
|
|
28
|
-
}
|
|
29
|
-
this.customerConfig = JSON.parse(jsonConfigs);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
async getUserAuthConfig() {
|
|
33
|
-
if (this.userAuthConfig) {
|
|
34
|
-
return this.userAuthConfig;
|
|
35
|
-
}
|
|
36
|
-
await this.getConfig();
|
|
37
|
-
const user = this.customerConfig.OIDC.user;
|
|
38
|
-
this.userAuthConfig = {
|
|
39
|
-
providers: [
|
|
40
|
-
{
|
|
41
|
-
id: "crex",
|
|
42
|
-
name: "CREX",
|
|
43
|
-
type: "oauth",
|
|
44
|
-
clientId: user.id,
|
|
45
|
-
wellKnown: user.issuer,
|
|
46
|
-
clientSecret: user.secret,
|
|
47
|
-
authorization: { params: { scope: user.scope } },
|
|
48
|
-
profile(profile) {
|
|
49
|
-
return {
|
|
50
|
-
id: profile.id || "fake Id",
|
|
51
|
-
name: profile.name || "Fake Name",
|
|
52
|
-
email: profile.email || "fake Email",
|
|
53
|
-
image: profile.image || "fake Image"
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
]
|
|
58
|
-
};
|
|
59
|
-
return this.userAuthConfig;
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
|
|
63
18
|
// src/transports/matomo.ts
|
|
64
19
|
var MatomoTransport = class extends Transport {
|
|
65
20
|
matomoTransport;
|
|
66
|
-
|
|
67
|
-
|
|
21
|
+
configs;
|
|
22
|
+
constructor(configs) {
|
|
23
|
+
super({
|
|
24
|
+
level: configs.logs.console.minimumLevel,
|
|
25
|
+
silent: configs.logs.console.silent
|
|
26
|
+
});
|
|
68
27
|
this.matomoTransport = new Transport();
|
|
28
|
+
this.configs = configs;
|
|
69
29
|
}
|
|
70
30
|
log(info, callback) {
|
|
71
|
-
const
|
|
72
|
-
const matomoCategory = SDK.customerConfig.logs.matomo.categoriesLevel;
|
|
31
|
+
const matomoCategory = this.configs.logs.matomo.categoriesLevel;
|
|
73
32
|
if (matomoCategory.includes(info.category) || matomoCategory.includes(ALL)) {
|
|
74
33
|
this.matomoTransport.log(info, callback);
|
|
75
34
|
}
|
|
@@ -81,8 +40,13 @@ import Transport2 from "winston-transport";
|
|
|
81
40
|
import Graylog2Transport from "winston-graylog2";
|
|
82
41
|
var GraylogTransport = class extends Transport2 {
|
|
83
42
|
graylogTransport;
|
|
84
|
-
|
|
85
|
-
|
|
43
|
+
configs;
|
|
44
|
+
constructor(configs) {
|
|
45
|
+
super({
|
|
46
|
+
level: configs.logs.graylog.minimumLevel,
|
|
47
|
+
silent: configs.logs.graylog.silent
|
|
48
|
+
});
|
|
49
|
+
this.configs = configs;
|
|
86
50
|
this.graylogTransport = new Graylog2Transport({
|
|
87
51
|
name: "Periotto-TEST",
|
|
88
52
|
silent: false,
|
|
@@ -93,8 +57,7 @@ var GraylogTransport = class extends Transport2 {
|
|
|
93
57
|
});
|
|
94
58
|
}
|
|
95
59
|
log(info, callback) {
|
|
96
|
-
const
|
|
97
|
-
const graylogCategory = SDK.customerConfig.logs.graylog.categoriesLevel;
|
|
60
|
+
const graylogCategory = this.configs.logs.graylog.categoriesLevel;
|
|
98
61
|
if (graylogCategory.includes(info.category) || graylogCategory.includes(ALL)) {
|
|
99
62
|
this.graylogTransport.log(info, callback);
|
|
100
63
|
}
|
|
@@ -102,13 +65,13 @@ var GraylogTransport = class extends Transport2 {
|
|
|
102
65
|
};
|
|
103
66
|
|
|
104
67
|
// src/logger.ts
|
|
105
|
-
import { getCookie
|
|
68
|
+
import { getCookie } from "@c-rex/utils/next-cookies";
|
|
106
69
|
var CrexLogger = class {
|
|
107
70
|
customerConfig;
|
|
108
71
|
logger;
|
|
109
72
|
async initLogger() {
|
|
110
73
|
if (!this.customerConfig) {
|
|
111
|
-
const jsonConfigs = await
|
|
74
|
+
const jsonConfigs = await getCookie(SDK_CONFIG_KEY);
|
|
112
75
|
if (!jsonConfigs) {
|
|
113
76
|
throw new Error("SDK not initialized");
|
|
114
77
|
}
|
|
@@ -130,14 +93,8 @@ var CrexLogger = class {
|
|
|
130
93
|
level: this.customerConfig.logs.console.minimumLevel,
|
|
131
94
|
silent: this.customerConfig.logs.console.silent
|
|
132
95
|
}),
|
|
133
|
-
new MatomoTransport(
|
|
134
|
-
|
|
135
|
-
silent: this.customerConfig.logs.console.silent
|
|
136
|
-
}),
|
|
137
|
-
new GraylogTransport({
|
|
138
|
-
level: this.customerConfig.logs.graylog.minimumLevel,
|
|
139
|
-
silent: this.customerConfig.logs.graylog.silent
|
|
140
|
-
})
|
|
96
|
+
new MatomoTransport(this.customerConfig),
|
|
97
|
+
new GraylogTransport(this.customerConfig)
|
|
141
98
|
]
|
|
142
99
|
});
|
|
143
100
|
}
|
package/dist/logger.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/logger.ts","../src/transports/matomo.ts","../../constants/src/index.ts","../src/
|
|
1
|
+
{"version":3,"sources":["../src/logger.ts","../src/transports/matomo.ts","../../constants/src/index.ts","../src/transports/graylog.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, SDK_CONFIG_KEY } from \"@c-rex/constants\";\nimport { getCookie } 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 const jsonConfigs = await getCookie(SDK_CONFIG_KEY);\n if (!jsonConfigs) {\n throw new Error(\"SDK not initialized\");\n }\n this.customerConfig = JSON.parse(jsonConfigs) as ConfigInterface;\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","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_UI_LANG = \"en\";\n\nexport const UI_LANG_OPTIONS = [\"en\", \"de\"];\n\nexport const RESULT_TYPES = {\n TOPIC: \"TOPIC\",\n DOCUMENT: \"DOCUMENT\",\n PACKAGE: \"PACKAGE\",\n} as const;","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,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;AAeO,IAAM,iBAAiB;;;AD/BvB,IAAM,kBAAN,cAA8B,UAAU;AAAA,EACpC;AAAA,EACC;AAAA,EAER,YAAY,SAA0B;AAClC,UAAM;AAAA,MACF,OAAO,QAAQ,KAAK,QAAQ;AAAA,MAC5B,QAAQ,QAAQ,KAAK,QAAQ;AAAA,IAC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AAAA,IAChD;AAEA,QAAI,CAAC,KAAK,QAAQ;AACd,WAAK,SAAS,KAAK,aAAa;AAAA,IACpC;AAAA,EACJ;AAAA,EAEA,MAAa,IAAI,EAAE,OAAO,SAAS,SAAS,GAIzC;AACC,UAAM,KAAK,WAAW;AACtB,SAAK,OAAO,IAAI,OAAO,SAAS,QAAQ;AAAA,EAC5C;AAAA,EAEQ,eAAe;AACnB,WAAO,QAAQ,aAAa;AAAA,MACxB,QAAQ;AAAA,MACR,YAAY;AAAA,QACR,IAAI,QAAQ,WAAW,QAAQ;AAAA,UAC3B,OAAO,KAAK,eAAe,KAAK,QAAQ;AAAA,UACxC,QAAQ,KAAK,eAAe,KAAK,QAAQ;AAAA,QAC7C,CAAC;AAAA,QACD,IAAI,gBAAgB,KAAK,cAAc;AAAA,QACvC,IAAI,iBAAiB,KAAK,cAAc;AAAA,MAC5C;AAAA,IACJ,CAAC;AAAA,EACL;AACJ;","names":["Transport","Transport"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@c-rex/core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"module": "dist/index.mjs",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -30,7 +30,9 @@
|
|
|
30
30
|
"dev": "tsup --watch",
|
|
31
31
|
"build": "tsup",
|
|
32
32
|
"test:watch": "jest --watch",
|
|
33
|
-
"test": "jest"
|
|
33
|
+
"test": "jest",
|
|
34
|
+
"lint": "eslint .",
|
|
35
|
+
"lint:fix": "eslint . --fix"
|
|
34
36
|
},
|
|
35
37
|
"devDependencies": {
|
|
36
38
|
"@c-rex/eslint-config": "*",
|