ag-common 0.0.31 → 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.
@@ -58,7 +58,7 @@ let batchWriteRaw = (req, debugMsg) => __awaiter(void 0, void 0, void 0, functio
58
58
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
59
59
  let es = e.toString();
60
60
  if (es.indexOf('429') !== -1 ||
61
- es.indexOf(' ProvisionedThroughputExceeded') !== -1) {
61
+ es.indexOf('ProvisionedThroughputExceeded') !== -1) {
62
62
  count += 1;
63
63
  }
64
64
  if (count >= max) {
@@ -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) {
@@ -15,3 +15,4 @@ export interface IArrayType<T> {
15
15
  export declare function objectToArray<T>(obj: {
16
16
  [a: string]: T;
17
17
  }): IArrayType<T>[];
18
+ export declare const objectAlphaSort: (object: any, depthLeft?: number) => object;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.objectToArray = exports.getObjectKeysAsNumber = exports.objectKeysToLowerCase = exports.isJson = exports.tryJsonParse = void 0;
3
+ exports.objectAlphaSort = exports.objectToArray = exports.getObjectKeysAsNumber = exports.objectKeysToLowerCase = exports.isJson = exports.tryJsonParse = void 0;
4
4
  const tryJsonParse = (str, defaultValue) => {
5
5
  if (!str) {
6
6
  return null;
@@ -52,3 +52,25 @@ function objectToArray(obj) {
52
52
  return ret;
53
53
  }
54
54
  exports.objectToArray = objectToArray;
55
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
56
+ const objectAlphaSort = (object, depthLeft = -1) => {
57
+ if (depthLeft === 0) {
58
+ return object;
59
+ }
60
+ if (object !== null && typeof object === 'object') {
61
+ return (Object.keys(object)
62
+ .sort((a, b) => (a.toLowerCase() < b.toLowerCase() ? -1 : 1))
63
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
64
+ .reduce((result, key) => {
65
+ result[key] = (0, exports.objectAlphaSort)(object[key], depthLeft - 1);
66
+ return result;
67
+ }, {}));
68
+ }
69
+ else if (Array.isArray(object)) {
70
+ return object.map((obj) => (0, exports.objectAlphaSort)(obj, depthLeft - 1));
71
+ }
72
+ else {
73
+ return object;
74
+ }
75
+ };
76
+ exports.objectAlphaSort = objectAlphaSort;
@@ -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
  }
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.UseLocalStorage = exports.getLocalStorageItem = exports.setLocalStorageItem = exports.clearAllLocalStorage = exports.clearLocalStorageItem = void 0;
4
+ const react_1 = require("react");
4
5
  const log_1 = require("../../common/helpers/log");
5
6
  const object_1 = require("../../common/helpers/object");
6
7
  const getTimeSeconds = () => Math.ceil(new Date().getTime() / 1000);
@@ -66,6 +67,8 @@ exports.getLocalStorageItem = getLocalStorageItem;
66
67
  // Hook
67
68
  function UseLocalStorage(key, initialValue, ttl) {
68
69
  const storedValue = (0, exports.getLocalStorageItem)(key, initialValue, ttl);
70
+ //bump use of stored value
71
+ const [, setT] = (0, react_1.useState)(0);
69
72
  // Return a wrapped version of useState's setter function that ...
70
73
  // ... persists the new value to localStorage.
71
74
  const setValue = (value) => {
@@ -74,6 +77,7 @@ function UseLocalStorage(key, initialValue, ttl) {
74
77
  }
75
78
  const valueToStore = (value instanceof Function ? value(storedValue) : value);
76
79
  (0, exports.setLocalStorageItem)(key, valueToStore, ttl);
80
+ setT(new Date().getTime());
77
81
  };
78
82
  return [storedValue, setValue];
79
83
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ag-common",
3
- "version": "0.0.31",
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/)",