ag-common 0.0.34 → 0.0.35

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
- /* eslint-disable no-console */
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
- var _a;
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) {
@@ -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
- // eslint-disable-next-line no-console
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
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ag-common",
3
- "version": "0.0.34",
3
+ "version": "0.0.35",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "author": "Andrei Gec <@andreigec> (https://gec.dev/)",