ag-common 0.0.604 → 0.0.606

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.
@@ -26,4 +26,17 @@ export declare const CSharpToJs: (charpTicks: number) => Date;
26
26
  * @returns
27
27
  */
28
28
  export declare const dateTimeToNearestMinute: (minutes: number, date?: Date) => Date;
29
- export declare const getUtcDateTime: () => Date;
29
+ export declare const dayInMs = 86400000;
30
+ /** strings are padded numbers, eg '02' */
31
+ export interface IUtcDateParams {
32
+ year: number;
33
+ month: number;
34
+ day: number;
35
+ hours: number;
36
+ minutes: number;
37
+ seconds: number;
38
+ }
39
+ export declare const getUtcDateTime: (skipTime?: boolean) => {
40
+ ticks: number;
41
+ };
42
+ export declare const toMs: ({ day, hours, minutes, month, seconds, year, }: IUtcDateParams) => number;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getUtcDateTime = exports.dateTimeToNearestMinute = exports.CSharpToJs = exports.dateDiff = exports.lastDayInMonth = exports.addMinutes = exports.addDays = exports.addHours = exports.getTimeSeconds = void 0;
3
+ exports.toMs = exports.getUtcDateTime = exports.dayInMs = exports.dateTimeToNearestMinute = exports.CSharpToJs = exports.dateDiff = exports.lastDayInMonth = exports.addMinutes = exports.addDays = exports.addHours = exports.getTimeSeconds = void 0;
4
4
  const math_1 = require("./math");
5
5
  const getTimeSeconds = () => Math.ceil(new Date().getTime() / 1000);
6
6
  exports.getTimeSeconds = getTimeSeconds;
@@ -62,15 +62,48 @@ const dateTimeToNearestMinute = (minutes, date) => {
62
62
  return rounded;
63
63
  };
64
64
  exports.dateTimeToNearestMinute = dateTimeToNearestMinute;
65
- const getUtcDateTime = () => {
65
+ exports.dayInMs = 8.64e7;
66
+ const getUtcDateTime = (
67
+ /** if true will 0 H,M,S */
68
+ skipTime) => {
66
69
  const date = new Date();
67
- const year = date.getUTCFullYear();
68
- const month = ('0' + (date.getUTCMonth() + 1)).slice(-2);
69
- const day = ('0' + date.getUTCDate()).slice(-2);
70
- const hours = ('0' + date.getUTCHours()).slice(-2);
71
- const minutes = ('0' + date.getUTCMinutes()).slice(-2);
72
- const seconds = ('0' + date.getUTCSeconds()).slice(-2);
73
- const datetime = `${year}-${month}-${day} ${hours}:${minutes}:${seconds} UTC`;
74
- return new Date(datetime);
70
+ const p = {
71
+ year: date.getUTCFullYear(),
72
+ month: date.getUTCMonth() + 1,
73
+ day: date.getUTCDate(),
74
+ hours: date.getUTCHours(),
75
+ minutes: date.getUTCMinutes(),
76
+ seconds: date.getUTCSeconds(),
77
+ tz: 'UTC',
78
+ };
79
+ if (skipTime) {
80
+ p.hours = p.minutes = p.seconds = 0;
81
+ }
82
+ const ticks = (0, exports.toMs)(p);
83
+ return { ticks };
75
84
  };
76
85
  exports.getUtcDateTime = getUtcDateTime;
86
+ const toMs = ({ day, hours, minutes, month, seconds, year, }) => {
87
+ // Calculate milliseconds in a year (365 days x 24 hours x 60 minutes x 60 seconds x 1000 milliseconds)
88
+ const millisecondsInYear = 365 * 24 * 60 * 60 * 1000;
89
+ // Calculate milliseconds in a month (based on 30 days)
90
+ const millisecondsInMonth = 30 * 24 * 60 * 60 * 1000;
91
+ // Calculate milliseconds in a day
92
+ const millisecondsInDay = 24 * 60 * 60 * 1000;
93
+ // Calculate milliseconds in an hour
94
+ const millisecondsInHour = 60 * 60 * 1000;
95
+ // Calculate milliseconds in a minute
96
+ const millisecondsInMinute = 60 * 1000;
97
+ // Calculate milliseconds in a second
98
+ const millisecondsInSecond = 1000;
99
+ // Calculate milliseconds since epoch based on given datetime values
100
+ // Note: Math.floor() is used to round down to the nearest integer
101
+ const millisecondsSinceEpoch = (year - 1970) * millisecondsInYear +
102
+ (month - 1) * millisecondsInMonth +
103
+ (day - 1) * millisecondsInDay +
104
+ hours * millisecondsInHour +
105
+ minutes * millisecondsInMinute +
106
+ seconds * millisecondsInSecond;
107
+ return millisecondsSinceEpoch;
108
+ };
109
+ exports.toMs = toMs;
@@ -2,7 +2,8 @@
2
2
  /* eslint-disable no-console */
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.fatal = exports.error = exports.trace = exports.warn = exports.info = exports.debug = exports.SetLogLevel = exports.SetLogShim = exports.GetLogLevel = void 0;
5
- const _1 = require(".");
5
+ const array_1 = require("./array");
6
+ const redact_1 = require("./string/redact");
6
7
  const GetLogLevel = (l) => ['TRACE', 'DEBUG', 'INFO', 'WARN', 'ERROR', 'FATAL'].findIndex((s) => s === l);
7
8
  exports.GetLogLevel = GetLogLevel;
8
9
  let logShim;
@@ -32,7 +33,11 @@ function logprocess(type, args) {
32
33
  }
33
34
  ////////
34
35
  const datetime = new Date().toLocaleTimeString('en-GB');
35
- const log = [`[${datetime}]`, type, ...args.filter(_1.notEmpty)];
36
+ const log = [
37
+ `[${datetime}]`,
38
+ type,
39
+ ...args.filter(array_1.notEmpty).map((s) => (0, redact_1.redactObject)(s)),
40
+ ];
36
41
  if (logShim) {
37
42
  logShim(...log);
38
43
  return;
@@ -4,6 +4,7 @@ export * from './contains';
4
4
  export * from './getExtendedStringSegment';
5
5
  export * from './json';
6
6
  export * from './object';
7
+ export * from './redact';
7
8
  export * from './surround';
8
9
  export * from './trim';
9
10
  export * from './truncate';
@@ -20,6 +20,7 @@ __exportStar(require("./contains"), exports);
20
20
  __exportStar(require("./getExtendedStringSegment"), exports);
21
21
  __exportStar(require("./json"), exports);
22
22
  __exportStar(require("./object"), exports);
23
+ __exportStar(require("./redact"), exports);
23
24
  __exportStar(require("./surround"), exports);
24
25
  __exportStar(require("./trim"), exports);
25
26
  __exportStar(require("./truncate"), exports);
@@ -0,0 +1,2 @@
1
+ export declare function redactString(str: string): string;
2
+ export declare function redactObject<T>(ob: T): T;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.redactObject = exports.redactString = void 0;
4
+ function redactString(str) {
5
+ let ret = str;
6
+ ret = ret !== null && ret !== void 0 ? ret : '';
7
+ const repl = '$1<redacted>$2';
8
+ ret = ret.replace(/(\b)grant_type.+?(\b)/gm, repl);
9
+ ret = ret.replace(/(\b)Bearer .+?(\b)/gm, repl);
10
+ ret = ret.replace(/(\b)eyJ[a-zA-Z0-9]{10}.+?(\b)/gm, repl);
11
+ return ret;
12
+ }
13
+ exports.redactString = redactString;
14
+ function redactObject(ob) {
15
+ if (typeof ob === 'string') {
16
+ return redactString(ob);
17
+ }
18
+ else if (typeof ob === 'object') {
19
+ try {
20
+ return JSON.parse(redactString(JSON.stringify(ob)));
21
+ }
22
+ catch (e) {
23
+ return ob;
24
+ }
25
+ }
26
+ return ob;
27
+ }
28
+ exports.redactObject = redactObject;
@@ -7,6 +7,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.SparkLine = void 0;
8
8
  const styled_1 = __importDefault(require("@emotion/styled"));
9
9
  const react_1 = __importDefault(require("react"));
10
+ const common_1 = require("../../../common");
10
11
  const math_1 = require("../../../common/helpers/math");
11
12
  const Base = styled_1.default.div `
12
13
  width: calc(100% - 1rem - 2px);
@@ -32,7 +33,7 @@ const SparkLine = (p) => {
32
33
  const xMax = Math.max(...raw.map((d) => d.x));
33
34
  const yMin = Math.min(...raw.map((d) => d.y));
34
35
  const yMax = Math.max(...raw.map((d) => d.y));
35
- const data = raw.map((orig) => ({
36
+ const data = (0, common_1.distinctBy)(raw.map((orig) => ({
36
37
  x: (0, math_1.rangePercentage)({
37
38
  value: orig.x,
38
39
  min: xMin,
@@ -44,7 +45,7 @@ const SparkLine = (p) => {
44
45
  max: yMax,
45
46
  }) * 100,
46
47
  orig,
47
- }));
48
+ })), (s) => s.x);
48
49
  return (react_1.default.createElement(Base, { className: p.className, title: p.title },
49
50
  react_1.default.createElement(Points, null, data.map((pt) => {
50
51
  var _a, _b;
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.0.604",
2
+ "version": "0.0.606",
3
3
  "name": "ag-common",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
@@ -13,7 +13,7 @@
13
13
  "lint": "npx eslint --ext .ts,.tsx .",
14
14
  "start": "cross-env BROWSER=none cross-env storybook dev -p 6006",
15
15
  "build-storybook": "storybook build -o docs --quiet",
16
- "test-run": "ts-node -- src/api/helpers/s3.test.ts"
16
+ "test": "globstar -- node --import tsx --test \"src/**/redact.test.ts\""
17
17
  },
18
18
  "dependencies": {
19
19
  "@aws-sdk/client-dynamodb": "^3.390",
@@ -52,17 +52,16 @@
52
52
  "@storybook/react": "7.6.12",
53
53
  "@storybook/react-webpack5": "7.6.12",
54
54
  "@storybook/theming": "7.6.12",
55
- "@types/jest": "29.5.12",
56
55
  "@types/jsonwebtoken": "9.0.5",
57
56
  "@types/node": "20.11.16",
58
57
  "@types/react": "18.2.51",
59
58
  "@types/react-dom": "18.2.18",
60
59
  "cross-env": "7.0.3",
61
60
  "eslint-config-e7npm": "0.0.79",
62
- "jest": "29.7.0",
61
+ "globstar": "^1.0.0",
63
62
  "rimraf": "5.0.5",
64
63
  "storybook": "7.6.12",
65
- "ts-jest": "29.1.2"
64
+ "tsx": "^4.7.0"
66
65
  },
67
66
  "files": [
68
67
  "dist/**/*",