@c-rex/core 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/chunk-5IZ7T5HI.mjs +128 -0
- package/dist/chunk-5IZ7T5HI.mjs.map +1 -0
- package/dist/chunk-TH2O62UQ.js +128 -0
- package/dist/chunk-TH2O62UQ.js.map +1 -0
- package/dist/index.d.mts +3 -6
- package/dist/index.d.ts +3 -6
- package/dist/index.js +3 -3005
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +4 -2996
- package/dist/index.mjs.map +1 -1
- package/dist/server-HTFBG5OL.js +2905 -0
- package/dist/server-HTFBG5OL.js.map +1 -0
- package/dist/server-QPUQ2EWO.mjs +2905 -0
- package/dist/server-QPUQ2EWO.mjs.map +1 -0
- package/package.json +13 -4
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
8
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
9
|
+
}) : x)(function(x) {
|
|
10
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
11
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
12
|
+
});
|
|
13
|
+
var __commonJS = (cb, mod) => function __require2() {
|
|
14
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
15
|
+
};
|
|
16
|
+
var __copyProps = (to, from, except, desc) => {
|
|
17
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
18
|
+
for (let key of __getOwnPropNames(from))
|
|
19
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
20
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
21
|
+
}
|
|
22
|
+
return to;
|
|
23
|
+
};
|
|
24
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
25
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
26
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
27
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
28
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
29
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
30
|
+
mod
|
|
31
|
+
));
|
|
32
|
+
|
|
33
|
+
// src/requests.ts
|
|
34
|
+
import axios from "axios";
|
|
35
|
+
import { API } from "@c-rex/constants";
|
|
36
|
+
var CrexApi = class {
|
|
37
|
+
apiClient;
|
|
38
|
+
logger;
|
|
39
|
+
constructor(baseUrl, logger) {
|
|
40
|
+
this.apiClient = axios.create({
|
|
41
|
+
baseURL: baseUrl,
|
|
42
|
+
headers: {
|
|
43
|
+
"content-Type": "application/json"
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
this.logger = logger;
|
|
47
|
+
}
|
|
48
|
+
async execute({
|
|
49
|
+
url,
|
|
50
|
+
method,
|
|
51
|
+
params,
|
|
52
|
+
body,
|
|
53
|
+
headers
|
|
54
|
+
}) {
|
|
55
|
+
let response = void 0;
|
|
56
|
+
for (let retry = 0; retry < API.MAX_RETRY; retry++) {
|
|
57
|
+
try {
|
|
58
|
+
response = await this.apiClient.request({
|
|
59
|
+
url,
|
|
60
|
+
method,
|
|
61
|
+
data: body,
|
|
62
|
+
params,
|
|
63
|
+
headers
|
|
64
|
+
});
|
|
65
|
+
} catch (error) {
|
|
66
|
+
this.logger.log("error", `API.execute error when request ${url}. Error: ${error}`);
|
|
67
|
+
throw error;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
if (response) {
|
|
71
|
+
return response.data;
|
|
72
|
+
}
|
|
73
|
+
throw new Error("API.execute error: Failed to retrieve a valid response");
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
// src/logger.ts
|
|
78
|
+
var CrexLogger = class {
|
|
79
|
+
customerConfig;
|
|
80
|
+
constructor(config) {
|
|
81
|
+
this.customerConfig = config;
|
|
82
|
+
}
|
|
83
|
+
async log(level, message, category) {
|
|
84
|
+
if (typeof window === "undefined") {
|
|
85
|
+
const { LoggerServer } = await import("./server-QPUQ2EWO.mjs");
|
|
86
|
+
const serverLog = new LoggerServer(this.customerConfig);
|
|
87
|
+
serverLog.log(level, message, category);
|
|
88
|
+
} else {
|
|
89
|
+
fetch("/api/log", {
|
|
90
|
+
method: "POST",
|
|
91
|
+
headers: { "Content-Type": "application/json" },
|
|
92
|
+
body: JSON.stringify({ level, message, category })
|
|
93
|
+
}).catch((err) => console.error("Erro ao enviar log", err));
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
// src/sdk.ts
|
|
99
|
+
var CrexSDK = class _CrexSDK {
|
|
100
|
+
static instance;
|
|
101
|
+
customerConfig;
|
|
102
|
+
logger;
|
|
103
|
+
api;
|
|
104
|
+
constructor(config) {
|
|
105
|
+
if (_CrexSDK.instance) {
|
|
106
|
+
return _CrexSDK.instance;
|
|
107
|
+
}
|
|
108
|
+
this.customerConfig = config;
|
|
109
|
+
this.logger = new CrexLogger(this.customerConfig);
|
|
110
|
+
this.api = new CrexApi(this.customerConfig.baseUrl, this.logger);
|
|
111
|
+
_CrexSDK.instance = this;
|
|
112
|
+
}
|
|
113
|
+
static getInstance() {
|
|
114
|
+
if (!_CrexSDK.instance) {
|
|
115
|
+
throw new Error("SDK not initialized");
|
|
116
|
+
}
|
|
117
|
+
return _CrexSDK.instance;
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
export {
|
|
122
|
+
__require,
|
|
123
|
+
__commonJS,
|
|
124
|
+
__toESM,
|
|
125
|
+
CrexApi,
|
|
126
|
+
CrexSDK
|
|
127
|
+
};
|
|
128
|
+
//# sourceMappingURL=chunk-5IZ7T5HI.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/requests.ts","../src/logger.ts","../src/sdk.ts"],"sourcesContent":["import axios, { AxiosResponse, Method } from \"axios\";\nimport { API } from \"@c-rex/constants\";\nimport { CrexLogger } from \"./logger\";\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 apiClient: axios.AxiosInstance;\n private logger: CrexLogger;\n\n public constructor(baseUrl: string, logger: CrexLogger) {\n this.apiClient = axios.create({\n baseURL: baseUrl,\n headers: {\n \"content-Type\": \"application/json\",\n },\n });\n this.logger = logger;\n }\n\n async execute<T>({\n url,\n method,\n params,\n body,\n headers,\n }: CallParams): Promise<any> {\n let response: APIGenericResponse<T> | undefined = undefined;\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 } catch (error) {\n this.logger.log(\"error\", `API.execute error when request ${url}. Error: ${error}`);\n throw error;\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}\n","import { ConfigInterface } from \"@c-rex/interfaces\";\nimport { LogCategoriesType, LogLevelType } from \"@c-rex/types\";\n\nexport class CrexLogger {\n private customerConfig: ConfigInterface;\n\n constructor(config: ConfigInterface) {\n this.customerConfig = config;\n }\n\n async log(level: LogLevelType, message: string, category?: LogCategoriesType) {\n if (typeof window === \"undefined\") {\n const { LoggerServer } = await import(\"./logs/server.js\");\n const serverLog = new LoggerServer(this.customerConfig);\n serverLog.log(level, message, category);\n } else {\n fetch(\"/api/log\", {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify({ level, message, category }),\n }).catch((err) => console.error(\"Erro ao enviar log\", err));\n }\n }\n}","import { CrexApi } from \"./requests\";\nimport { CrexLogger } from \"./logger\";\nimport { ConfigInterface } from \"@c-rex/interfaces\";\n\nexport class CrexSDK {\n private static instance: CrexSDK;\n public customerConfig!: ConfigInterface;\n public logger!: CrexLogger;\n public api!: CrexApi;\n\n public constructor(config: ConfigInterface) {\n if (CrexSDK.instance) {\n return CrexSDK.instance;\n }\n\n this.customerConfig = config;\n this.logger = new CrexLogger(this.customerConfig);\n this.api = new CrexApi(this.customerConfig.baseUrl, this.logger);\n\n CrexSDK.instance = this;\n }\n\n public static getInstance(): CrexSDK {\n if (!CrexSDK.instance) {\n throw new Error(\"SDK not initialized\");\n }\n return CrexSDK.instance;\n }\n}"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,WAAsC;AAC7C,SAAS,WAAW;AAgBb,IAAM,UAAN,MAAc;AAAA,EACT;AAAA,EACA;AAAA,EAED,YAAY,SAAiB,QAAoB;AACpD,SAAK,YAAY,MAAM,OAAO;AAAA,MAC1B,SAAS;AAAA,MACT,SAAS;AAAA,QACL,gBAAgB;AAAA,MACpB;AAAA,IACJ,CAAC;AACD,SAAK,SAAS;AAAA,EAClB;AAAA,EAEA,MAAM,QAAW;AAAA,IACb;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACJ,GAA6B;AACzB,QAAI,WAA8C;AAElD,aAAS,QAAQ,GAAG,QAAQ,IAAI,WAAW,SAAS;AAChD,UAAI;AACA,mBAAW,MAAM,KAAK,UAAU,QAAQ;AAAA,UACpC;AAAA,UACA;AAAA,UACA,MAAM;AAAA,UACN;AAAA,UACA;AAAA,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WAAO,SAAQ;AAAA,EACnB;AACJ;","names":[]}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
8
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
9
|
+
}) : x)(function(x) {
|
|
10
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
11
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
12
|
+
});
|
|
13
|
+
var __commonJS = (cb, mod) => function __require2() {
|
|
14
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
15
|
+
};
|
|
16
|
+
var __copyProps = (to, from, except, desc) => {
|
|
17
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
18
|
+
for (let key of __getOwnPropNames(from))
|
|
19
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
20
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
21
|
+
}
|
|
22
|
+
return to;
|
|
23
|
+
};
|
|
24
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
25
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
26
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
27
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
28
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
29
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
30
|
+
mod
|
|
31
|
+
));
|
|
32
|
+
|
|
33
|
+
// src/requests.ts
|
|
34
|
+
var _axios = require('axios'); var _axios2 = _interopRequireDefault(_axios);
|
|
35
|
+
var _constants = require('@c-rex/constants');
|
|
36
|
+
var CrexApi = class {
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
constructor(baseUrl, logger) {
|
|
40
|
+
this.apiClient = _axios2.default.create({
|
|
41
|
+
baseURL: baseUrl,
|
|
42
|
+
headers: {
|
|
43
|
+
"content-Type": "application/json"
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
this.logger = logger;
|
|
47
|
+
}
|
|
48
|
+
async execute({
|
|
49
|
+
url,
|
|
50
|
+
method,
|
|
51
|
+
params,
|
|
52
|
+
body,
|
|
53
|
+
headers
|
|
54
|
+
}) {
|
|
55
|
+
let response = void 0;
|
|
56
|
+
for (let retry = 0; retry < _constants.API.MAX_RETRY; retry++) {
|
|
57
|
+
try {
|
|
58
|
+
response = await this.apiClient.request({
|
|
59
|
+
url,
|
|
60
|
+
method,
|
|
61
|
+
data: body,
|
|
62
|
+
params,
|
|
63
|
+
headers
|
|
64
|
+
});
|
|
65
|
+
} catch (error) {
|
|
66
|
+
this.logger.log("error", `API.execute error when request ${url}. Error: ${error}`);
|
|
67
|
+
throw error;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
if (response) {
|
|
71
|
+
return response.data;
|
|
72
|
+
}
|
|
73
|
+
throw new Error("API.execute error: Failed to retrieve a valid response");
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
// src/logger.ts
|
|
78
|
+
var CrexLogger = class {
|
|
79
|
+
|
|
80
|
+
constructor(config) {
|
|
81
|
+
this.customerConfig = config;
|
|
82
|
+
}
|
|
83
|
+
async log(level, message, category) {
|
|
84
|
+
if (typeof window === "undefined") {
|
|
85
|
+
const { LoggerServer } = await Promise.resolve().then(() => _interopRequireWildcard(require("./server-HTFBG5OL.js")));
|
|
86
|
+
const serverLog = new LoggerServer(this.customerConfig);
|
|
87
|
+
serverLog.log(level, message, category);
|
|
88
|
+
} else {
|
|
89
|
+
fetch("/api/log", {
|
|
90
|
+
method: "POST",
|
|
91
|
+
headers: { "Content-Type": "application/json" },
|
|
92
|
+
body: JSON.stringify({ level, message, category })
|
|
93
|
+
}).catch((err) => console.error("Erro ao enviar log", err));
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
// src/sdk.ts
|
|
99
|
+
var CrexSDK = class _CrexSDK {
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
constructor(config) {
|
|
105
|
+
if (_CrexSDK.instance) {
|
|
106
|
+
return _CrexSDK.instance;
|
|
107
|
+
}
|
|
108
|
+
this.customerConfig = config;
|
|
109
|
+
this.logger = new CrexLogger(this.customerConfig);
|
|
110
|
+
this.api = new CrexApi(this.customerConfig.baseUrl, this.logger);
|
|
111
|
+
_CrexSDK.instance = this;
|
|
112
|
+
}
|
|
113
|
+
static getInstance() {
|
|
114
|
+
if (!_CrexSDK.instance) {
|
|
115
|
+
throw new Error("SDK not initialized");
|
|
116
|
+
}
|
|
117
|
+
return _CrexSDK.instance;
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
exports.__require = __require; exports.__commonJS = __commonJS; exports.__toESM = __toESM; exports.CrexApi = CrexApi; exports.CrexSDK = CrexSDK;
|
|
128
|
+
//# sourceMappingURL=chunk-TH2O62UQ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/Users/periotto/Desktop/workspace/c-rex.net-web-client-foundation/packages/core/dist/chunk-TH2O62UQ.js","../src/requests.ts","../src/logger.ts","../src/sdk.ts"],"names":[],"mappings":"AAAA,+bAAI,SAAS,EAAE,MAAM,CAAC,MAAM;AAC5B,IAAI,UAAU,EAAE,MAAM,CAAC,cAAc;AACrC,IAAI,iBAAiB,EAAE,MAAM,CAAC,wBAAwB;AACtD,IAAI,kBAAkB,EAAE,MAAM,CAAC,mBAAmB;AAClD,IAAI,aAAa,EAAE,MAAM,CAAC,cAAc;AACxC,IAAI,aAAa,EAAE,MAAM,CAAC,SAAS,CAAC,cAAc;AAClD,IAAI,UAAU,kBAAkB,CAAC,CAAC,CAAC,EAAE,GAAG,OAAO,QAAQ,IAAI,YAAY,EAAE,QAAQ,EAAE,OAAO,MAAM,IAAI,YAAY,EAAE,IAAI,KAAK,CAAC,CAAC,EAAE;AAC/H,EAAE,GAAG,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,CAAC,OAAO,QAAQ,IAAI,YAAY,EAAE,QAAQ,EAAE,CAAC,CAAC,CAAC,CAAC;AACjE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE;AACpB,EAAE,GAAG,CAAC,OAAO,QAAQ,IAAI,WAAW,EAAE,OAAO,OAAO,CAAC,KAAK,CAAC,IAAI,EAAE,SAAS,CAAC;AAC3E,EAAE,MAAM,KAAK,CAAC,uBAAuB,EAAE,EAAE,EAAE,oBAAoB,CAAC;AAChE,CAAC,CAAC;AACF,IAAI,WAAW,EAAE,CAAC,EAAE,EAAE,GAAG,EAAE,GAAG,SAAS,UAAU,CAAC,EAAE;AACpD,EAAE,OAAO,IAAI,GAAG,CAAC,CAAC,EAAE,EAAE,CAAC,iBAAiB,CAAC,EAAE,CA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A;AACnC,IAAA;AACe,MAAA;AACN,QAAA;AACsC,QAAA;AACG,QAAA;AACK,MAAA;AAC9D,IAAA;AACJ,EAAA;AACJ;AFyEwF;AACA;AG7FnE;AACF,EAAA;AACR,EAAA;AACA,EAAA;AACA,EAAA;AAEqC,EAAA;AAClB,IAAA;AACH,MAAA;AACnB,IAAA;AAEsB,IAAA;AAC0B,IAAA;AACe,IAAA;AAE5C,IAAA;AACvB,EAAA;AAEqC,EAAA;AACV,IAAA;AACkB,MAAA;AACzC,IAAA;AACe,IAAA;AACnB,EAAA;AACJ;AH2FwF;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/Users/periotto/Desktop/workspace/c-rex.net-web-client-foundation/packages/core/dist/chunk-TH2O62UQ.js","sourcesContent":[null,"import axios, { AxiosResponse, Method } from \"axios\";\nimport { API } from \"@c-rex/constants\";\nimport { CrexLogger } from \"./logger\";\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 apiClient: axios.AxiosInstance;\n private logger: CrexLogger;\n\n public constructor(baseUrl: string, logger: CrexLogger) {\n this.apiClient = axios.create({\n baseURL: baseUrl,\n headers: {\n \"content-Type\": \"application/json\",\n },\n });\n this.logger = logger;\n }\n\n async execute<T>({\n url,\n method,\n params,\n body,\n headers,\n }: CallParams): Promise<any> {\n let response: APIGenericResponse<T> | undefined = undefined;\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 } catch (error) {\n this.logger.log(\"error\", `API.execute error when request ${url}. Error: ${error}`);\n throw error;\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}\n","import { ConfigInterface } from \"@c-rex/interfaces\";\nimport { LogCategoriesType, LogLevelType } from \"@c-rex/types\";\n\nexport class CrexLogger {\n private customerConfig: ConfigInterface;\n\n constructor(config: ConfigInterface) {\n this.customerConfig = config;\n }\n\n async log(level: LogLevelType, message: string, category?: LogCategoriesType) {\n if (typeof window === \"undefined\") {\n const { LoggerServer } = await import(\"./logs/server.js\");\n const serverLog = new LoggerServer(this.customerConfig);\n serverLog.log(level, message, category);\n } else {\n fetch(\"/api/log\", {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify({ level, message, category }),\n }).catch((err) => console.error(\"Erro ao enviar log\", err));\n }\n }\n}","import { CrexApi } from \"./requests\";\nimport { CrexLogger } from \"./logger\";\nimport { ConfigInterface } from \"@c-rex/interfaces\";\n\nexport class CrexSDK {\n private static instance: CrexSDK;\n public customerConfig!: ConfigInterface;\n public logger!: CrexLogger;\n public api!: CrexApi;\n\n public constructor(config: ConfigInterface) {\n if (CrexSDK.instance) {\n return CrexSDK.instance;\n }\n\n this.customerConfig = config;\n this.logger = new CrexLogger(this.customerConfig);\n this.api = new CrexApi(this.customerConfig.baseUrl, this.logger);\n\n CrexSDK.instance = this;\n }\n\n public static getInstance(): CrexSDK {\n if (!CrexSDK.instance) {\n throw new Error(\"SDK not initialized\");\n }\n return CrexSDK.instance;\n }\n}"]}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Method } from 'axios';
|
|
2
2
|
import { ConfigInterface } from '@c-rex/interfaces';
|
|
3
3
|
import { LogLevelType, LogCategoriesType } from '@c-rex/types';
|
|
4
|
-
import { Method } from 'axios';
|
|
5
4
|
|
|
6
5
|
declare class CrexLogger {
|
|
7
6
|
private customerConfig;
|
|
8
|
-
logger: winston.Logger;
|
|
9
7
|
constructor(config: ConfigInterface);
|
|
10
|
-
log(level: LogLevelType, message: string, category?: LogCategoriesType): void
|
|
11
|
-
private createLogger;
|
|
8
|
+
log(level: LogLevelType, message: string, category?: LogCategoriesType): Promise<void>;
|
|
12
9
|
}
|
|
13
10
|
|
|
14
11
|
interface CallParams {
|
|
@@ -34,4 +31,4 @@ declare class CrexSDK {
|
|
|
34
31
|
static getInstance(): CrexSDK;
|
|
35
32
|
}
|
|
36
33
|
|
|
37
|
-
export { CrexApi,
|
|
34
|
+
export { CrexApi, CrexSDK };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Method } from 'axios';
|
|
2
2
|
import { ConfigInterface } from '@c-rex/interfaces';
|
|
3
3
|
import { LogLevelType, LogCategoriesType } from '@c-rex/types';
|
|
4
|
-
import { Method } from 'axios';
|
|
5
4
|
|
|
6
5
|
declare class CrexLogger {
|
|
7
6
|
private customerConfig;
|
|
8
|
-
logger: winston.Logger;
|
|
9
7
|
constructor(config: ConfigInterface);
|
|
10
|
-
log(level: LogLevelType, message: string, category?: LogCategoriesType): void
|
|
11
|
-
private createLogger;
|
|
8
|
+
log(level: LogLevelType, message: string, category?: LogCategoriesType): Promise<void>;
|
|
12
9
|
}
|
|
13
10
|
|
|
14
11
|
interface CallParams {
|
|
@@ -34,4 +31,4 @@ declare class CrexSDK {
|
|
|
34
31
|
static getInstance(): CrexSDK;
|
|
35
32
|
}
|
|
36
33
|
|
|
37
|
-
export { CrexApi,
|
|
34
|
+
export { CrexApi, CrexSDK };
|