@c-rex/core 0.0.4 → 0.0.7
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 -12
- package/dist/index.d.ts +4 -12
- package/dist/index.js +113 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +114 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -5
- package/dist/chunk-QOOUMY2T.js +0 -128
- package/dist/chunk-QOOUMY2T.js.map +0 -1
- package/dist/chunk-T7GRZ5WF.mjs +0 -128
- package/dist/chunk-T7GRZ5WF.mjs.map +0 -1
- package/dist/server-BUDEHO2T.js +0 -2905
- package/dist/server-BUDEHO2T.js.map +0 -1
- package/dist/server-IY4UU5DM.mjs +0 -2905
- package/dist/server-IY4UU5DM.mjs.map +0 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,12 +1,5 @@
|
|
|
1
1
|
import { Method } from 'axios';
|
|
2
2
|
import { ConfigInterface } from '@c-rex/interfaces';
|
|
3
|
-
import { LogLevelType, LogCategoriesType } from '@c-rex/types';
|
|
4
|
-
|
|
5
|
-
declare class CrexLogger {
|
|
6
|
-
private customerConfig;
|
|
7
|
-
constructor(config: ConfigInterface);
|
|
8
|
-
log(level: LogLevelType, message: string, category?: LogCategoriesType): Promise<void>;
|
|
9
|
-
}
|
|
10
3
|
|
|
11
4
|
interface CallParams {
|
|
12
5
|
url: string;
|
|
@@ -18,17 +11,16 @@ interface CallParams {
|
|
|
18
11
|
declare class CrexApi {
|
|
19
12
|
private apiClient;
|
|
20
13
|
private logger;
|
|
21
|
-
constructor(baseUrl: string, logger:
|
|
14
|
+
constructor(baseUrl: string, logger: any);
|
|
22
15
|
execute<T>({ url, method, params, body, headers, }: CallParams): Promise<any>;
|
|
23
16
|
}
|
|
24
17
|
|
|
25
18
|
declare class CrexSDK {
|
|
26
|
-
private static instance;
|
|
27
19
|
customerConfig: ConfigInterface;
|
|
28
|
-
logger:
|
|
20
|
+
logger: any;
|
|
29
21
|
api: CrexApi;
|
|
30
|
-
constructor(
|
|
31
|
-
static
|
|
22
|
+
constructor();
|
|
23
|
+
static setConfig(config: ConfigInterface): void;
|
|
32
24
|
}
|
|
33
25
|
|
|
34
26
|
export { CrexApi, CrexSDK };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,5 @@
|
|
|
1
1
|
import { Method } from 'axios';
|
|
2
2
|
import { ConfigInterface } from '@c-rex/interfaces';
|
|
3
|
-
import { LogLevelType, LogCategoriesType } from '@c-rex/types';
|
|
4
|
-
|
|
5
|
-
declare class CrexLogger {
|
|
6
|
-
private customerConfig;
|
|
7
|
-
constructor(config: ConfigInterface);
|
|
8
|
-
log(level: LogLevelType, message: string, category?: LogCategoriesType): Promise<void>;
|
|
9
|
-
}
|
|
10
3
|
|
|
11
4
|
interface CallParams {
|
|
12
5
|
url: string;
|
|
@@ -18,17 +11,16 @@ interface CallParams {
|
|
|
18
11
|
declare class CrexApi {
|
|
19
12
|
private apiClient;
|
|
20
13
|
private logger;
|
|
21
|
-
constructor(baseUrl: string, logger:
|
|
14
|
+
constructor(baseUrl: string, logger: any);
|
|
22
15
|
execute<T>({ url, method, params, body, headers, }: CallParams): Promise<any>;
|
|
23
16
|
}
|
|
24
17
|
|
|
25
18
|
declare class CrexSDK {
|
|
26
|
-
private static instance;
|
|
27
19
|
customerConfig: ConfigInterface;
|
|
28
|
-
logger:
|
|
20
|
+
logger: any;
|
|
29
21
|
api: CrexApi;
|
|
30
|
-
constructor(
|
|
31
|
-
static
|
|
22
|
+
constructor();
|
|
23
|
+
static setConfig(config: ConfigInterface): void;
|
|
32
24
|
}
|
|
33
25
|
|
|
34
26
|
export { CrexApi, CrexSDK };
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,119 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }// src/requests.ts
|
|
2
|
+
var _axios = require('axios'); var _axios2 = _interopRequireDefault(_axios);
|
|
3
|
+
var _constants = require('@c-rex/constants');
|
|
4
|
+
var CrexApi = class {
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
constructor(baseUrl, logger) {
|
|
8
|
+
this.apiClient = _axios2.default.create({
|
|
9
|
+
baseURL: baseUrl,
|
|
10
|
+
headers: {
|
|
11
|
+
"content-Type": "application/json"
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
this.logger = logger;
|
|
15
|
+
}
|
|
16
|
+
async execute({
|
|
17
|
+
url,
|
|
18
|
+
method,
|
|
19
|
+
params,
|
|
20
|
+
body,
|
|
21
|
+
headers
|
|
22
|
+
}) {
|
|
23
|
+
let response = void 0;
|
|
24
|
+
for (let retry = 0; retry < _constants.API.MAX_RETRY; retry++) {
|
|
25
|
+
try {
|
|
26
|
+
response = await this.apiClient.request({
|
|
27
|
+
url,
|
|
28
|
+
method,
|
|
29
|
+
data: body,
|
|
30
|
+
params,
|
|
31
|
+
headers
|
|
32
|
+
});
|
|
33
|
+
} catch (error) {
|
|
34
|
+
this.logger.log("error", `API.execute error when request ${url}. Error: ${error}`);
|
|
35
|
+
throw error;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
if (response) {
|
|
39
|
+
return response.data;
|
|
40
|
+
}
|
|
41
|
+
throw new Error("API.execute error: Failed to retrieve a valid response");
|
|
42
|
+
}
|
|
43
|
+
};
|
|
2
44
|
|
|
45
|
+
// src/cookies.ts
|
|
46
|
+
var GLOBAL_KEY = "__CREX_INITIAL_CONFIG__";
|
|
47
|
+
var CONFIG_COOKIE_KEY = "crex_config";
|
|
48
|
+
function isBrowser() {
|
|
49
|
+
return typeof window !== "undefined" && typeof document !== "undefined";
|
|
50
|
+
}
|
|
51
|
+
function parseCookies() {
|
|
52
|
+
const cookies = {};
|
|
53
|
+
if (typeof document === "undefined") {
|
|
54
|
+
return cookies;
|
|
55
|
+
}
|
|
56
|
+
document.cookie.split(";").forEach((cookie) => {
|
|
57
|
+
const [key, value] = cookie.split("=");
|
|
58
|
+
if (key && value) {
|
|
59
|
+
cookies[key.trim()] = decodeURIComponent(value.trim());
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
return cookies;
|
|
63
|
+
}
|
|
64
|
+
function setCookie(name, value, days = 30) {
|
|
65
|
+
if (typeof document === "undefined") return;
|
|
66
|
+
const expires = new Date(Date.now() + days * 86400 * 1e3).toUTCString();
|
|
67
|
+
document.cookie = `${name}=${encodeURIComponent(value)}; path=/; expires=${expires}; SameSite=Lax`;
|
|
68
|
+
}
|
|
69
|
+
function setConfig(config) {
|
|
70
|
+
if (isBrowser()) {
|
|
71
|
+
setCookie(CONFIG_COOKIE_KEY, JSON.stringify(config));
|
|
72
|
+
} else {
|
|
73
|
+
if (typeof global !== "undefined" && !(GLOBAL_KEY in global)) {
|
|
74
|
+
global[GLOBAL_KEY] = null;
|
|
75
|
+
}
|
|
76
|
+
const globalConfig = global[GLOBAL_KEY];
|
|
77
|
+
if (globalConfig === null) {
|
|
78
|
+
global[GLOBAL_KEY] = config;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
function getConfig() {
|
|
83
|
+
let returnValue;
|
|
84
|
+
if (isBrowser()) {
|
|
85
|
+
const cookies = parseCookies();
|
|
86
|
+
const configStr = cookies[CONFIG_COOKIE_KEY];
|
|
87
|
+
if (configStr) {
|
|
88
|
+
try {
|
|
89
|
+
return JSON.parse(configStr);
|
|
90
|
+
} catch (e) {
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return null;
|
|
95
|
+
} else {
|
|
96
|
+
returnValue = global[GLOBAL_KEY];
|
|
97
|
+
}
|
|
98
|
+
return returnValue;
|
|
99
|
+
}
|
|
3
100
|
|
|
4
|
-
|
|
101
|
+
// src/sdk.ts
|
|
102
|
+
var CrexSDK = class {
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
constructor() {
|
|
107
|
+
const config = getConfig();
|
|
108
|
+
this.customerConfig = config;
|
|
109
|
+
this.api = new CrexApi(this.customerConfig.baseUrl, null);
|
|
110
|
+
}
|
|
111
|
+
static setConfig(config) {
|
|
112
|
+
setConfig(config);
|
|
113
|
+
}
|
|
114
|
+
};
|
|
5
115
|
|
|
6
116
|
|
|
7
117
|
|
|
8
|
-
exports.CrexApi =
|
|
118
|
+
exports.CrexApi = CrexApi; exports.CrexSDK = CrexSDK;
|
|
9
119
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/periotto/Desktop/workspace/c-rex.net-web-client-foundation/packages/core/dist/index.js"],"names":[],"mappings":"AAAA;
|
|
1
|
+
{"version":3,"sources":["/Users/periotto/Desktop/workspace/c-rex.net-web-client-foundation/packages/core/dist/index.js","../src/requests.ts","../src/cookies.ts","../src/sdk.ts"],"names":[],"mappings":"AAAA;ACAA,4EAA4D;AAC5D,6CAAoB;AAeb,IAAM,QAAA,EAAN,MAAc;AAAA,EACT;AAAA,EACA;AAAA,EAED,WAAA,CAAY,OAAA,EAAiB,MAAA,EAAa;AAC7C,IAAA,IAAA,CAAK,UAAA,EAAY,eAAA,CAAM,MAAA,CAAO;AAAA,MAC1B,OAAA,EAAS,OAAA;AAAA,MACT,OAAA,EAAS;AAAA,QACL,cAAA,EAAgB;AAAA,MACpB;AAAA,IACJ,CAAC,CAAA;AACD,IAAA,IAAA,CAAK,OAAA,EAAS,MAAA;AAAA,EAClB;AAAA,EAEA,MAAM,OAAA,CAAW;AAAA,IACb,GAAA;AAAA,IACA,MAAA;AAAA,IACA,MAAA;AAAA,IACA,IAAA;AAAA,IACA;AAAA,EACJ,CAAA,EAA6B;AACzB,IAAA,IAAI,SAAA,EAA8C,KAAA,CAAA;AAElD,IAAA,IAAA,CAAA,IAAS,MAAA,EAAQ,CAAA,EAAG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AA;AAEiD,EAAA;AAC7B,IAAA;AACpB,EAAA;AACJ;AH+FwF;AACA;AACA;AACA","file":"/Users/periotto/Desktop/workspace/c-rex.net-web-client-foundation/packages/core/dist/index.js","sourcesContent":[null,"import axios, { AxiosResponse, Method, AxiosInstance } from \"axios\";\nimport { API } from \"@c-rex/constants\";\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: AxiosInstance;\n private logger: any;\n\n public constructor(baseUrl: string, logger: any) {\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","const GLOBAL_KEY = '__CREX_INITIAL_CONFIG__';\nconst CONFIG_COOKIE_KEY = 'crex_config';\n\nfunction isBrowser() {\n return typeof window !== 'undefined' && typeof document !== 'undefined';\n}\n\nfunction parseCookies(): Record<string, string> {\n const cookies: Record<string, string> = {};\n\n if (typeof document === 'undefined') {\n return cookies;\n }\n\n document.cookie.split(';').forEach(cookie => {\n const [key, value] = cookie.split('=');\n if (key && value) {\n cookies[key.trim()] = decodeURIComponent(value.trim());\n }\n });\n\n return cookies;\n}\n\nfunction setCookie(name: string, value: string, days = 30) {\n if (typeof document === 'undefined') return;\n\n const expires = new Date(Date.now() + days * 86400 * 1000).toUTCString();\n document.cookie = `${name}=${encodeURIComponent(value)}; path=/; expires=${expires}; SameSite=Lax`;\n}\n\nexport function setConfig(config: Record<string, any>) {\n\n if (isBrowser()) {\n setCookie(CONFIG_COOKIE_KEY, JSON.stringify(config));\n } else {\n if (typeof global !== 'undefined' && !(GLOBAL_KEY in global)) {\n (global as any)[GLOBAL_KEY] = null;\n }\n\n const globalConfig = (global as any)[GLOBAL_KEY] as any;\n\n if (globalConfig === null) {\n (global as any)[GLOBAL_KEY] = config;\n }\n }\n}\n\nexport function getConfig(): Record<string, any> | null {\n let returnValue\n\n if (isBrowser()) {\n const cookies = parseCookies();\n const configStr = cookies[CONFIG_COOKIE_KEY];\n if (configStr) {\n try {\n return JSON.parse(configStr);\n } catch {\n return null;\n }\n }\n return null;\n\n } else {\n returnValue = (global as any)[GLOBAL_KEY];\n }\n\n return returnValue\n}\n","import { CrexApi } from \"./requests\";\nimport { ConfigInterface } from \"@c-rex/interfaces\";\nimport { getConfig, setConfig } from \"./cookies\";\n\nexport class CrexSDK {\n public customerConfig!: ConfigInterface;\n public logger!: any;\n public api!: CrexApi;\n\n public constructor() {\n const config = getConfig();\n\n this.customerConfig = config as ConfigInterface;\n this.api = new CrexApi(this.customerConfig.baseUrl, null);\n }\n\n public static setConfig(config: ConfigInterface) {\n setConfig(config);\n }\n}"]}
|
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,117 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
// src/requests.ts
|
|
2
|
+
import axios from "axios";
|
|
3
|
+
import { API } from "@c-rex/constants";
|
|
4
|
+
var CrexApi = class {
|
|
5
|
+
apiClient;
|
|
6
|
+
logger;
|
|
7
|
+
constructor(baseUrl, logger) {
|
|
8
|
+
this.apiClient = axios.create({
|
|
9
|
+
baseURL: baseUrl,
|
|
10
|
+
headers: {
|
|
11
|
+
"content-Type": "application/json"
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
this.logger = logger;
|
|
15
|
+
}
|
|
16
|
+
async execute({
|
|
17
|
+
url,
|
|
18
|
+
method,
|
|
19
|
+
params,
|
|
20
|
+
body,
|
|
21
|
+
headers
|
|
22
|
+
}) {
|
|
23
|
+
let response = void 0;
|
|
24
|
+
for (let retry = 0; retry < API.MAX_RETRY; retry++) {
|
|
25
|
+
try {
|
|
26
|
+
response = await this.apiClient.request({
|
|
27
|
+
url,
|
|
28
|
+
method,
|
|
29
|
+
data: body,
|
|
30
|
+
params,
|
|
31
|
+
headers
|
|
32
|
+
});
|
|
33
|
+
} catch (error) {
|
|
34
|
+
this.logger.log("error", `API.execute error when request ${url}. Error: ${error}`);
|
|
35
|
+
throw error;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
if (response) {
|
|
39
|
+
return response.data;
|
|
40
|
+
}
|
|
41
|
+
throw new Error("API.execute error: Failed to retrieve a valid response");
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
// src/cookies.ts
|
|
46
|
+
var GLOBAL_KEY = "__CREX_INITIAL_CONFIG__";
|
|
47
|
+
var CONFIG_COOKIE_KEY = "crex_config";
|
|
48
|
+
function isBrowser() {
|
|
49
|
+
return typeof window !== "undefined" && typeof document !== "undefined";
|
|
50
|
+
}
|
|
51
|
+
function parseCookies() {
|
|
52
|
+
const cookies = {};
|
|
53
|
+
if (typeof document === "undefined") {
|
|
54
|
+
return cookies;
|
|
55
|
+
}
|
|
56
|
+
document.cookie.split(";").forEach((cookie) => {
|
|
57
|
+
const [key, value] = cookie.split("=");
|
|
58
|
+
if (key && value) {
|
|
59
|
+
cookies[key.trim()] = decodeURIComponent(value.trim());
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
return cookies;
|
|
63
|
+
}
|
|
64
|
+
function setCookie(name, value, days = 30) {
|
|
65
|
+
if (typeof document === "undefined") return;
|
|
66
|
+
const expires = new Date(Date.now() + days * 86400 * 1e3).toUTCString();
|
|
67
|
+
document.cookie = `${name}=${encodeURIComponent(value)}; path=/; expires=${expires}; SameSite=Lax`;
|
|
68
|
+
}
|
|
69
|
+
function setConfig(config) {
|
|
70
|
+
if (isBrowser()) {
|
|
71
|
+
setCookie(CONFIG_COOKIE_KEY, JSON.stringify(config));
|
|
72
|
+
} else {
|
|
73
|
+
if (typeof global !== "undefined" && !(GLOBAL_KEY in global)) {
|
|
74
|
+
global[GLOBAL_KEY] = null;
|
|
75
|
+
}
|
|
76
|
+
const globalConfig = global[GLOBAL_KEY];
|
|
77
|
+
if (globalConfig === null) {
|
|
78
|
+
global[GLOBAL_KEY] = config;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
function getConfig() {
|
|
83
|
+
let returnValue;
|
|
84
|
+
if (isBrowser()) {
|
|
85
|
+
const cookies = parseCookies();
|
|
86
|
+
const configStr = cookies[CONFIG_COOKIE_KEY];
|
|
87
|
+
if (configStr) {
|
|
88
|
+
try {
|
|
89
|
+
return JSON.parse(configStr);
|
|
90
|
+
} catch {
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return null;
|
|
95
|
+
} else {
|
|
96
|
+
returnValue = global[GLOBAL_KEY];
|
|
97
|
+
}
|
|
98
|
+
return returnValue;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// src/sdk.ts
|
|
102
|
+
var CrexSDK = class {
|
|
103
|
+
customerConfig;
|
|
104
|
+
logger;
|
|
105
|
+
api;
|
|
106
|
+
constructor() {
|
|
107
|
+
const config = getConfig();
|
|
108
|
+
this.customerConfig = config;
|
|
109
|
+
this.api = new CrexApi(this.customerConfig.baseUrl, null);
|
|
110
|
+
}
|
|
111
|
+
static setConfig(config) {
|
|
112
|
+
setConfig(config);
|
|
113
|
+
}
|
|
114
|
+
};
|
|
5
115
|
export {
|
|
6
116
|
CrexApi,
|
|
7
117
|
CrexSDK
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/requests.ts","../src/cookies.ts","../src/sdk.ts"],"sourcesContent":["import axios, { AxiosResponse, Method, AxiosInstance } from \"axios\";\nimport { API } from \"@c-rex/constants\";\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: AxiosInstance;\n private logger: any;\n\n public constructor(baseUrl: string, logger: any) {\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","const GLOBAL_KEY = '__CREX_INITIAL_CONFIG__';\nconst CONFIG_COOKIE_KEY = 'crex_config';\n\nfunction isBrowser() {\n return typeof window !== 'undefined' && typeof document !== 'undefined';\n}\n\nfunction parseCookies(): Record<string, string> {\n const cookies: Record<string, string> = {};\n\n if (typeof document === 'undefined') {\n return cookies;\n }\n\n document.cookie.split(';').forEach(cookie => {\n const [key, value] = cookie.split('=');\n if (key && value) {\n cookies[key.trim()] = decodeURIComponent(value.trim());\n }\n });\n\n return cookies;\n}\n\nfunction setCookie(name: string, value: string, days = 30) {\n if (typeof document === 'undefined') return;\n\n const expires = new Date(Date.now() + days * 86400 * 1000).toUTCString();\n document.cookie = `${name}=${encodeURIComponent(value)}; path=/; expires=${expires}; SameSite=Lax`;\n}\n\nexport function setConfig(config: Record<string, any>) {\n\n if (isBrowser()) {\n setCookie(CONFIG_COOKIE_KEY, JSON.stringify(config));\n } else {\n if (typeof global !== 'undefined' && !(GLOBAL_KEY in global)) {\n (global as any)[GLOBAL_KEY] = null;\n }\n\n const globalConfig = (global as any)[GLOBAL_KEY] as any;\n\n if (globalConfig === null) {\n (global as any)[GLOBAL_KEY] = config;\n }\n }\n}\n\nexport function getConfig(): Record<string, any> | null {\n let returnValue\n\n if (isBrowser()) {\n const cookies = parseCookies();\n const configStr = cookies[CONFIG_COOKIE_KEY];\n if (configStr) {\n try {\n return JSON.parse(configStr);\n } catch {\n return null;\n }\n }\n return null;\n\n } else {\n returnValue = (global as any)[GLOBAL_KEY];\n }\n\n return returnValue\n}\n","import { CrexApi } from \"./requests\";\nimport { ConfigInterface } from \"@c-rex/interfaces\";\nimport { getConfig, setConfig } from \"./cookies\";\n\nexport class CrexSDK {\n public customerConfig!: ConfigInterface;\n public logger!: any;\n public api!: CrexApi;\n\n public constructor() {\n const config = getConfig();\n\n this.customerConfig = config as ConfigInterface;\n this.api = new CrexApi(this.customerConfig.baseUrl, null);\n }\n\n public static setConfig(config: ConfigInterface) {\n setConfig(config);\n }\n}"],"mappings":";AAAA,OAAO,WAAqD;AAC5D,SAAS,WAAW;AAeb,IAAM,UAAN,MAAc;AAAA,EACT;AAAA,EACA;AAAA,EAED,YAAY,SAAiB,QAAa;AAC7C,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;AA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IAAI;AAAA,IAClC;AAAA,EACJ;AACJ;AAEO,SAAS,YAAwC;AACpD,MAAI;AAEJ,MAAI,UAAU,GAAG;AACb,UAAM,UAAU,aAAa;AAC7B,UAAM,YAAY,QAAQ,iBAAiB;AAC3C,QAAI,WAAW;AACX,UAAI;AACA,eAAO,KAAK,MAAM,SAAS;AAAA,MAC/B,QAAQ;AACJ,eAAO;AAAA,MACX;AAAA,IACJ;AACA,WAAO;AAAA,EAEX,OAAO;AACH,kBAAe,OAAe,UAAU;AAAA,EAC5C;AAEA,SAAO;AACX;;;AChEO,IAAM,UAAN,MAAc;AAAA,EACV;AAAA,EACA;AAAA,EACA;AAAA,EAEA,cAAc;AACjB,UAAM,SAAS,UAAU;AAEzB,SAAK,iBAAiB;AACtB,SAAK,MAAM,IAAI,QAAQ,KAAK,eAAe,SAAS,IAAI;AAAA,EAC5D;AAAA,EAEA,OAAc,UAAU,QAAyB;AAC7C,cAAU,MAAM;AAAA,EACpB;AACJ;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@c-rex/core",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"module": "dist/index.mjs",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -21,10 +21,6 @@
|
|
|
21
21
|
"./logger.server": {
|
|
22
22
|
"import": "./dist/logger.server.mjs",
|
|
23
23
|
"require": "./dist/logger.server.cjs"
|
|
24
|
-
},
|
|
25
|
-
"./logger.client": {
|
|
26
|
-
"import": "./dist/logger.client.mjs",
|
|
27
|
-
"require": "./dist/logger.client.cjs"
|
|
28
24
|
}
|
|
29
25
|
},
|
|
30
26
|
"sideEffects": false,
|
package/dist/chunk-QOOUMY2T.js
DELETED
|
@@ -1,128 +0,0 @@
|
|
|
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-BUDEHO2T.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-QOOUMY2T.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["/Users/periotto/Desktop/workspace/c-r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ACR,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-QOOUMY2T.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/chunk-T7GRZ5WF.mjs
DELETED
|
@@ -1,128 +0,0 @@
|
|
|
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-IY4UU5DM.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-T7GRZ5WF.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
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,aAA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