ag-common 0.0.34 → 0.0.38
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.
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export declare type TLogType = 'TRACE' | 'DEBUG' | 'INFO' | 'WARN' | 'ERROR' | 'FATAL';
|
|
2
2
|
export declare const GetLogLevel: (l: TLogType) => number;
|
|
3
|
+
export declare const SetLogLevel: (l: string) => void;
|
|
3
4
|
export declare const debug: (...args: any[]) => void;
|
|
4
5
|
export declare const info: (...args: any[]) => void;
|
|
5
6
|
export declare const warn: (...args: any[]) => void;
|
|
@@ -1,19 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.fatal = exports.error = exports.trace = exports.warn = exports.info = exports.debug = exports.GetLogLevel = void 0;
|
|
3
|
+
exports.fatal = exports.error = exports.trace = exports.warn = exports.info = exports.debug = exports.SetLogLevel = exports.GetLogLevel = void 0;
|
|
4
|
+
/* eslint-disable no-console */
|
|
4
5
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
5
6
|
const _1 = require(".");
|
|
6
7
|
const GetLogLevel = (l) => ['TRACE', 'DEBUG', 'INFO', 'WARN', 'ERROR', 'FATAL'].findIndex((s) => s === l);
|
|
7
8
|
exports.GetLogLevel = GetLogLevel;
|
|
8
|
-
|
|
9
|
+
let userLogLevel = 'WARN';
|
|
10
|
+
const SetLogLevel = (l) => {
|
|
11
|
+
const lu = l === null || l === void 0 ? void 0 : l.toUpperCase();
|
|
12
|
+
if ((0, exports.GetLogLevel)(lu) === -1) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
userLogLevel = lu;
|
|
16
|
+
};
|
|
17
|
+
exports.SetLogLevel = SetLogLevel;
|
|
18
|
+
(0, exports.SetLogLevel)(process.env.LOG_LEVEL || '');
|
|
9
19
|
function dateF() {
|
|
10
20
|
const d = new Date();
|
|
11
21
|
const str = `${d.getHours()}:${d.getMinutes()}:${d.getSeconds()}`;
|
|
12
22
|
return str;
|
|
13
23
|
}
|
|
14
24
|
function logprocess(type, args) {
|
|
15
|
-
|
|
16
|
-
const min = (0, exports.GetLogLevel)((_a = process.env.LOG_LEVEL) === null || _a === void 0 ? void 0 : _a.toUpperCase()) || 'WARN';
|
|
25
|
+
const min = (0, exports.GetLogLevel)(userLogLevel);
|
|
17
26
|
const typesLogLevel = (0, exports.GetLogLevel)(type);
|
|
18
27
|
// env ignores it
|
|
19
28
|
if (typesLogLevel < min) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.replaceRemove = exports.toTitleCase = exports.niceUrl = exports.truncate = exports.trim = exports.trimSide = exports.csvJSON = void 0;
|
|
3
|
+
exports.containsInsensitive = exports.replaceRemove = exports.toTitleCase = exports.niceUrl = exports.truncate = exports.trim = exports.trimSide = exports.csvJSON = void 0;
|
|
4
4
|
const csvJSON = (csv) => {
|
|
5
5
|
const lines = csv.split('\n');
|
|
6
6
|
const result = [];
|
|
@@ -109,3 +109,11 @@ function replaceRemove(str, ...params) {
|
|
|
109
109
|
return ret;
|
|
110
110
|
}
|
|
111
111
|
exports.replaceRemove = replaceRemove;
|
|
112
|
+
function containsInsensitive(str, ...args) {
|
|
113
|
+
if (!str || !args) {
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
const l = str.toLowerCase();
|
|
117
|
+
return !!args.find((a) => l.includes(a));
|
|
118
|
+
}
|
|
119
|
+
exports.containsInsensitive = containsInsensitive;
|
|
@@ -14,6 +14,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.axiosHelper = void 0;
|
|
16
16
|
const axios_1 = __importDefault(require("axios"));
|
|
17
|
+
const log_1 = require("../../common/helpers/log");
|
|
17
18
|
const object_1 = require("../../common/helpers/object");
|
|
18
19
|
/**
|
|
19
20
|
*
|
|
@@ -72,8 +73,7 @@ const axiosHelper = ({ verb, url, body, headers, timeout = 30000, retryMax = 0,
|
|
|
72
73
|
// jwt expired or bad response
|
|
73
74
|
// 403 returned for old token - will be refreshed
|
|
74
75
|
if (em.code === '401' || em.code === '403') {
|
|
75
|
-
|
|
76
|
-
console.log('auth expired');
|
|
76
|
+
(0, log_1.debug)('auth expired');
|
|
77
77
|
onStaleAuth === null || onStaleAuth === void 0 ? void 0 : onStaleAuth();
|
|
78
78
|
retry = retryMax;
|
|
79
79
|
}
|
|
@@ -9,7 +9,12 @@ const clearLocalStorageItem = (key) => {
|
|
|
9
9
|
if (typeof window === 'undefined') {
|
|
10
10
|
return;
|
|
11
11
|
}
|
|
12
|
-
|
|
12
|
+
try {
|
|
13
|
+
window.localStorage.removeItem(key);
|
|
14
|
+
}
|
|
15
|
+
catch (e) {
|
|
16
|
+
(0, log_1.warn)('error clearing local storage:', e);
|
|
17
|
+
}
|
|
13
18
|
};
|
|
14
19
|
exports.clearLocalStorageItem = clearLocalStorageItem;
|
|
15
20
|
const clearAllLocalStorage = (except) => {
|
|
@@ -43,6 +48,7 @@ const setLocalStorageItem = (key, value, ttl) => {
|
|
|
43
48
|
}
|
|
44
49
|
catch (e) {
|
|
45
50
|
(0, log_1.error)(`set LS error:${key}-${e}`);
|
|
51
|
+
(0, exports.clearLocalStorageItem)(key);
|
|
46
52
|
}
|
|
47
53
|
};
|
|
48
54
|
exports.setLocalStorageItem = setLocalStorageItem;
|
package/package.json
CHANGED
|
@@ -1,51 +1,51 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ag-common",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.38",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"author": "Andrei Gec <@andreigec> (https://gec.dev/)",
|
|
7
7
|
"repository": "github:andreigec/ag-common",
|
|
8
8
|
"license": "ISC",
|
|
9
|
+
"scripts": {
|
|
10
|
+
"build": "rimraf dist && yarn checklint && tsc",
|
|
11
|
+
"fix": "./node_modules/.bin/eslint --fix './src/**/*.ts' './src/**/*.tsx'",
|
|
12
|
+
"checklint": "npx eslint --ext .ts,.tsx ./src",
|
|
13
|
+
"start": "tsc --watch"
|
|
14
|
+
},
|
|
9
15
|
"dependencies": {
|
|
10
|
-
"
|
|
16
|
+
"aws-cdk-lib": "2.4.0",
|
|
17
|
+
"aws-sdk": "2.1052.0",
|
|
11
18
|
"axios": "0.24.0",
|
|
12
|
-
"
|
|
19
|
+
"constructs": "10.0.27",
|
|
20
|
+
"jsonwebtoken": "8.5.1",
|
|
21
|
+
"jwks-rsa": "2.0.5",
|
|
13
22
|
"openapi-request-validator": "10.0.0",
|
|
14
|
-
"aws-sdk": "2.1048.0",
|
|
15
|
-
"aws-cdk-lib": "2.3.0",
|
|
16
|
-
"constructs": "10.0.17",
|
|
17
23
|
"react": "17.0.2",
|
|
18
24
|
"react-dom": "17.0.2",
|
|
19
|
-
"react-hot-toast": "2.
|
|
20
|
-
"
|
|
21
|
-
"
|
|
25
|
+
"react-hot-toast": "2.2.0",
|
|
26
|
+
"styled-components": "5.3.3",
|
|
27
|
+
"typescript": "4.5.4"
|
|
22
28
|
},
|
|
23
29
|
"devDependencies": {
|
|
24
|
-
"@
|
|
25
|
-
"@
|
|
26
|
-
"prettier": "2.5.1",
|
|
27
|
-
"@types/node": "17.0.5",
|
|
30
|
+
"@types/jsonwebtoken": "8.5.6",
|
|
31
|
+
"@types/node": "17.0.8",
|
|
28
32
|
"@types/react": "17.0.38",
|
|
29
33
|
"@types/react-dom": "17.0.11",
|
|
30
34
|
"@types/styled-components": "5.1.19",
|
|
31
|
-
"eslint": "
|
|
35
|
+
"@typescript-eslint/eslint-plugin": "5.9.0",
|
|
36
|
+
"@typescript-eslint/parser": "5.9.0",
|
|
37
|
+
"eslint": "8.6.0",
|
|
32
38
|
"eslint-config-airbnb-typescript": "16.1.0",
|
|
33
39
|
"eslint-config-prettier": "8.3.0",
|
|
34
40
|
"eslint-config-react-app": "7.0.0",
|
|
35
|
-
"eslint-plugin-import": "2.25.
|
|
41
|
+
"eslint-plugin-import": "2.25.4",
|
|
36
42
|
"eslint-plugin-jsx-a11y": "6.5.1",
|
|
37
43
|
"eslint-plugin-prettier": "4.0.0",
|
|
38
44
|
"eslint-plugin-react": "7.28.0",
|
|
39
45
|
"eslint-plugin-react-hooks": "4.3.0",
|
|
46
|
+
"prettier": "2.5.1",
|
|
40
47
|
"rimraf": "3.0.2",
|
|
41
|
-
"typescript-styled-plugin": "0.18.2"
|
|
42
|
-
"@types/jsonwebtoken": "8.5.6"
|
|
43
|
-
},
|
|
44
|
-
"scripts": {
|
|
45
|
-
"build": "rimraf dist && yarn checklint && tsc",
|
|
46
|
-
"fix": "./node_modules/.bin/eslint --fix './src/**/*.ts' './src/**/*.tsx'",
|
|
47
|
-
"checklint": "npx eslint --ext .ts,.tsx ./src",
|
|
48
|
-
"start": "tsc --watch"
|
|
48
|
+
"typescript-styled-plugin": "0.18.2"
|
|
49
49
|
},
|
|
50
50
|
"files": [
|
|
51
51
|
"dist/**/*",
|