@c-rex/core 0.0.1 → 0.0.2
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.d.mts +4 -37
- package/dist/index.d.ts +4 -37
- package/dist/index.js +55 -66
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +51 -64
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -2
package/dist/index.d.mts
CHANGED
|
@@ -1,40 +1,7 @@
|
|
|
1
|
-
import { Method } from 'axios';
|
|
2
1
|
import winston from 'winston';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
declare const LOG_LEVELS: {
|
|
7
|
-
readonly critical: 2;
|
|
8
|
-
readonly error: 3;
|
|
9
|
-
readonly warning: 4;
|
|
10
|
-
readonly info: 6;
|
|
11
|
-
readonly debug: 7;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
type LogLevelType = keyof typeof LOG_LEVELS | typeof ALL;
|
|
15
|
-
type LogCategoriesType = typeof LOG_CATEGORIES[number] | typeof ALL;
|
|
16
|
-
|
|
17
|
-
interface logInfo {
|
|
18
|
-
silent: boolean;
|
|
19
|
-
minimumLevel: LogLevelType;
|
|
20
|
-
categoriesLevel: LogCategoriesType[];
|
|
21
|
-
url: string;
|
|
22
|
-
app: string;
|
|
23
|
-
}
|
|
24
|
-
interface ConfigInterface {
|
|
25
|
-
projectName: string;
|
|
26
|
-
baseUrl: string;
|
|
27
|
-
search: {
|
|
28
|
-
fields: string[];
|
|
29
|
-
tags: string[];
|
|
30
|
-
sparqlWhere?: string;
|
|
31
|
-
};
|
|
32
|
-
logs: {
|
|
33
|
-
console: logInfo;
|
|
34
|
-
graylog: logInfo;
|
|
35
|
-
matomo: logInfo;
|
|
36
|
-
};
|
|
37
|
-
}
|
|
2
|
+
import { ConfigInterface } from '@c-rex/interfaces';
|
|
3
|
+
import { LogLevelType, LogCategoriesType } from '@c-rex/types';
|
|
4
|
+
import { Method } from 'axios';
|
|
38
5
|
|
|
39
6
|
declare class CrexLogger {
|
|
40
7
|
private customerConfig;
|
|
@@ -67,4 +34,4 @@ declare class CrexSDK {
|
|
|
67
34
|
static getInstance(): CrexSDK;
|
|
68
35
|
}
|
|
69
36
|
|
|
70
|
-
export { CrexSDK };
|
|
37
|
+
export { CrexApi, CrexLogger, CrexSDK };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,40 +1,7 @@
|
|
|
1
|
-
import { Method } from 'axios';
|
|
2
1
|
import winston from 'winston';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
declare const LOG_LEVELS: {
|
|
7
|
-
readonly critical: 2;
|
|
8
|
-
readonly error: 3;
|
|
9
|
-
readonly warning: 4;
|
|
10
|
-
readonly info: 6;
|
|
11
|
-
readonly debug: 7;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
type LogLevelType = keyof typeof LOG_LEVELS | typeof ALL;
|
|
15
|
-
type LogCategoriesType = typeof LOG_CATEGORIES[number] | typeof ALL;
|
|
16
|
-
|
|
17
|
-
interface logInfo {
|
|
18
|
-
silent: boolean;
|
|
19
|
-
minimumLevel: LogLevelType;
|
|
20
|
-
categoriesLevel: LogCategoriesType[];
|
|
21
|
-
url: string;
|
|
22
|
-
app: string;
|
|
23
|
-
}
|
|
24
|
-
interface ConfigInterface {
|
|
25
|
-
projectName: string;
|
|
26
|
-
baseUrl: string;
|
|
27
|
-
search: {
|
|
28
|
-
fields: string[];
|
|
29
|
-
tags: string[];
|
|
30
|
-
sparqlWhere?: string;
|
|
31
|
-
};
|
|
32
|
-
logs: {
|
|
33
|
-
console: logInfo;
|
|
34
|
-
graylog: logInfo;
|
|
35
|
-
matomo: logInfo;
|
|
36
|
-
};
|
|
37
|
-
}
|
|
2
|
+
import { ConfigInterface } from '@c-rex/interfaces';
|
|
3
|
+
import { LogLevelType, LogCategoriesType } from '@c-rex/types';
|
|
4
|
+
import { Method } from 'axios';
|
|
38
5
|
|
|
39
6
|
declare class CrexLogger {
|
|
40
7
|
private customerConfig;
|
|
@@ -67,4 +34,4 @@ declare class CrexSDK {
|
|
|
67
34
|
static getInstance(): CrexSDK;
|
|
68
35
|
}
|
|
69
36
|
|
|
70
|
-
export { CrexSDK };
|
|
37
|
+
export { CrexApi, CrexLogger, CrexSDK };
|
package/dist/index.js
CHANGED
|
@@ -2845,77 +2845,19 @@ var require_winston_transport = __commonJS({
|
|
|
2845
2845
|
// src/index.ts
|
|
2846
2846
|
var index_exports = {};
|
|
2847
2847
|
__export(index_exports, {
|
|
2848
|
+
CrexApi: () => CrexApi,
|
|
2849
|
+
CrexLogger: () => CrexLogger,
|
|
2848
2850
|
CrexSDK: () => CrexSDK
|
|
2849
2851
|
});
|
|
2850
2852
|
module.exports = __toCommonJS(index_exports);
|
|
2851
2853
|
|
|
2852
|
-
// src/requests.ts
|
|
2853
|
-
var import_axios = __toESM(require("axios"));
|
|
2854
|
-
|
|
2855
|
-
// src/constants.ts
|
|
2856
|
-
var ALL = "*";
|
|
2857
|
-
var LOG_LEVELS = {
|
|
2858
|
-
critical: 2,
|
|
2859
|
-
error: 3,
|
|
2860
|
-
warning: 4,
|
|
2861
|
-
info: 6,
|
|
2862
|
-
debug: 7
|
|
2863
|
-
};
|
|
2864
|
-
var API = {
|
|
2865
|
-
MAX_RETRY: 3,
|
|
2866
|
-
API_TIMEOUT: 1e4,
|
|
2867
|
-
API_HEADERS: {
|
|
2868
|
-
"content-Type": "application/json"
|
|
2869
|
-
}
|
|
2870
|
-
};
|
|
2871
|
-
|
|
2872
|
-
// src/requests.ts
|
|
2873
|
-
var CrexApi = class {
|
|
2874
|
-
apiClient;
|
|
2875
|
-
logger;
|
|
2876
|
-
constructor(baseUrl, logger) {
|
|
2877
|
-
this.apiClient = import_axios.default.create({
|
|
2878
|
-
baseURL: baseUrl,
|
|
2879
|
-
headers: {
|
|
2880
|
-
"content-Type": "application/json"
|
|
2881
|
-
}
|
|
2882
|
-
});
|
|
2883
|
-
this.logger = logger;
|
|
2884
|
-
}
|
|
2885
|
-
async execute({
|
|
2886
|
-
url,
|
|
2887
|
-
method,
|
|
2888
|
-
params,
|
|
2889
|
-
body,
|
|
2890
|
-
headers
|
|
2891
|
-
}) {
|
|
2892
|
-
let response = void 0;
|
|
2893
|
-
for (let retry = 0; retry < API.MAX_RETRY; retry++) {
|
|
2894
|
-
try {
|
|
2895
|
-
response = await this.apiClient.request({
|
|
2896
|
-
url,
|
|
2897
|
-
method,
|
|
2898
|
-
data: body,
|
|
2899
|
-
params,
|
|
2900
|
-
headers
|
|
2901
|
-
});
|
|
2902
|
-
} catch (error) {
|
|
2903
|
-
this.logger.log("error", `API.execute error when request ${url}. Error: ${error}`);
|
|
2904
|
-
throw error;
|
|
2905
|
-
}
|
|
2906
|
-
}
|
|
2907
|
-
if (response) {
|
|
2908
|
-
return response;
|
|
2909
|
-
}
|
|
2910
|
-
throw new Error("API.execute error: Failed to retrieve a valid response");
|
|
2911
|
-
}
|
|
2912
|
-
};
|
|
2913
|
-
|
|
2914
2854
|
// src/logger.ts
|
|
2915
2855
|
var import_winston = __toESM(require("winston"));
|
|
2856
|
+
var import_constants3 = require("@c-rex/constants");
|
|
2916
2857
|
|
|
2917
2858
|
// src/transports/matomo.ts
|
|
2918
2859
|
var import_winston_transport = __toESM(require_winston_transport());
|
|
2860
|
+
var import_constants = require("@c-rex/constants");
|
|
2919
2861
|
var MatomoTransport = class extends import_winston_transport.default {
|
|
2920
2862
|
matomoTransport;
|
|
2921
2863
|
constructor(opts) {
|
|
@@ -2925,7 +2867,7 @@ var MatomoTransport = class extends import_winston_transport.default {
|
|
|
2925
2867
|
log(info, callback) {
|
|
2926
2868
|
const SDK = CrexSDK.getInstance();
|
|
2927
2869
|
const matomoCategory = SDK.customerConfig.logs.matomo.categoriesLevel;
|
|
2928
|
-
if (matomoCategory.includes(info.category) || matomoCategory.includes(ALL)) {
|
|
2870
|
+
if (matomoCategory.includes(info.category) || matomoCategory.includes(import_constants.ALL)) {
|
|
2929
2871
|
this.matomoTransport.log(info, callback);
|
|
2930
2872
|
}
|
|
2931
2873
|
}
|
|
@@ -2934,6 +2876,7 @@ var MatomoTransport = class extends import_winston_transport.default {
|
|
|
2934
2876
|
// src/transports/graylog.ts
|
|
2935
2877
|
var import_winston_transport2 = __toESM(require_winston_transport());
|
|
2936
2878
|
var import_winston_graylog2 = __toESM(require("winston-graylog2"));
|
|
2879
|
+
var import_constants2 = require("@c-rex/constants");
|
|
2937
2880
|
var GraylogTransport = class extends import_winston_transport2.default {
|
|
2938
2881
|
graylogTransport;
|
|
2939
2882
|
constructor(opts) {
|
|
@@ -2950,7 +2893,7 @@ var GraylogTransport = class extends import_winston_transport2.default {
|
|
|
2950
2893
|
log(info, callback) {
|
|
2951
2894
|
const SDK = CrexSDK.getInstance();
|
|
2952
2895
|
const graylogCategory = SDK.customerConfig.logs.graylog.categoriesLevel;
|
|
2953
|
-
if (graylogCategory.includes(info.category) || graylogCategory.includes(ALL)) {
|
|
2896
|
+
if (graylogCategory.includes(info.category) || graylogCategory.includes(import_constants2.ALL)) {
|
|
2954
2897
|
this.graylogTransport.log(info, callback);
|
|
2955
2898
|
}
|
|
2956
2899
|
}
|
|
@@ -2969,7 +2912,7 @@ var CrexLogger = class {
|
|
|
2969
2912
|
}
|
|
2970
2913
|
createLogger() {
|
|
2971
2914
|
return import_winston.default.createLogger({
|
|
2972
|
-
levels: LOG_LEVELS,
|
|
2915
|
+
levels: import_constants3.LOG_LEVELS,
|
|
2973
2916
|
transports: [
|
|
2974
2917
|
new import_winston.default.transports.Console({
|
|
2975
2918
|
level: this.customerConfig.logs.console.minimumLevel,
|
|
@@ -2988,7 +2931,51 @@ var CrexLogger = class {
|
|
|
2988
2931
|
}
|
|
2989
2932
|
};
|
|
2990
2933
|
|
|
2991
|
-
// src/
|
|
2934
|
+
// src/requests.ts
|
|
2935
|
+
var import_axios = __toESM(require("axios"));
|
|
2936
|
+
var import_constants4 = require("@c-rex/constants");
|
|
2937
|
+
var CrexApi = class {
|
|
2938
|
+
apiClient;
|
|
2939
|
+
logger;
|
|
2940
|
+
constructor(baseUrl, logger) {
|
|
2941
|
+
this.apiClient = import_axios.default.create({
|
|
2942
|
+
baseURL: baseUrl,
|
|
2943
|
+
headers: {
|
|
2944
|
+
"content-Type": "application/json"
|
|
2945
|
+
}
|
|
2946
|
+
});
|
|
2947
|
+
this.logger = logger;
|
|
2948
|
+
}
|
|
2949
|
+
async execute({
|
|
2950
|
+
url,
|
|
2951
|
+
method,
|
|
2952
|
+
params,
|
|
2953
|
+
body,
|
|
2954
|
+
headers
|
|
2955
|
+
}) {
|
|
2956
|
+
let response = void 0;
|
|
2957
|
+
for (let retry = 0; retry < import_constants4.API.MAX_RETRY; retry++) {
|
|
2958
|
+
try {
|
|
2959
|
+
response = await this.apiClient.request({
|
|
2960
|
+
url,
|
|
2961
|
+
method,
|
|
2962
|
+
data: body,
|
|
2963
|
+
params,
|
|
2964
|
+
headers
|
|
2965
|
+
});
|
|
2966
|
+
} catch (error) {
|
|
2967
|
+
this.logger.log("error", `API.execute error when request ${url}. Error: ${error}`);
|
|
2968
|
+
throw error;
|
|
2969
|
+
}
|
|
2970
|
+
}
|
|
2971
|
+
if (response) {
|
|
2972
|
+
return response;
|
|
2973
|
+
}
|
|
2974
|
+
throw new Error("API.execute error: Failed to retrieve a valid response");
|
|
2975
|
+
}
|
|
2976
|
+
};
|
|
2977
|
+
|
|
2978
|
+
// src/sdk.ts
|
|
2992
2979
|
var CrexSDK = class _CrexSDK {
|
|
2993
2980
|
static instance;
|
|
2994
2981
|
customerConfig;
|
|
@@ -3012,6 +2999,8 @@ var CrexSDK = class _CrexSDK {
|
|
|
3012
2999
|
};
|
|
3013
3000
|
// Annotate the CommonJS export names for ESM import in node:
|
|
3014
3001
|
0 && (module.exports = {
|
|
3002
|
+
CrexApi,
|
|
3003
|
+
CrexLogger,
|
|
3015
3004
|
CrexSDK
|
|
3016
3005
|
});
|
|
3017
3006
|
/*! Bundled license information:
|