robbyson-frontend-library 1.0.164 → 1.0.165
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/repositories/base.repository.js +5 -3
- package/dist/utils/cache-control.js +16 -15
- package/dist/utils/chat.utils.js +2 -2
- package/dist/utils/date.utils.js +6 -6
- package/package.json +3 -3
- package/src/repositories/base.repository.ts +4 -4
- package/src/utils/cache-control.ts +16 -16
- package/src/utils/chat.utils.ts +2 -2
- package/src/utils/date.utils.ts +10 -10
|
@@ -35,7 +35,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
35
35
|
}
|
|
36
36
|
};
|
|
37
37
|
import axios from "axios";
|
|
38
|
-
import
|
|
38
|
+
import { isAfter, isEqual } from "date-fns";
|
|
39
39
|
import { CacheControl } from "../utils";
|
|
40
40
|
import sha1 from "crypto-js/sha1";
|
|
41
41
|
import { GlobalStore } from "redux-micro-frontend";
|
|
@@ -74,7 +74,7 @@ var BaseRepository = /** @class */ (function () {
|
|
|
74
74
|
case 0:
|
|
75
75
|
if (config && config.cache) {
|
|
76
76
|
return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
|
|
77
|
-
var key, hasCache, _a, expire, value_1, isExpired, response_1, _b, _c, error_1;
|
|
77
|
+
var key, hasCache, _a, expire, value_1, now, expireDate, isExpired, response_1, _b, _c, error_1;
|
|
78
78
|
var _d, _e;
|
|
79
79
|
return __generator(this, function (_f) {
|
|
80
80
|
switch (_f.label) {
|
|
@@ -88,7 +88,9 @@ var BaseRepository = /** @class */ (function () {
|
|
|
88
88
|
return [4 /*yield*/, CacheControl.getCache(key)];
|
|
89
89
|
case 2:
|
|
90
90
|
_a = (_f.sent()) || {}, expire = _a.expire, value_1 = _a.value;
|
|
91
|
-
|
|
91
|
+
now = new Date();
|
|
92
|
+
expireDate = new Date(expire);
|
|
93
|
+
isExpired = isAfter(now, expireDate) || isEqual(now, expireDate);
|
|
92
94
|
if (value_1 && !isExpired) {
|
|
93
95
|
console.log("RECOVERED FROM CACHE", url);
|
|
94
96
|
return [2 /*return*/, setTimeout(function () { return resolve(value_1); }, (_d = config.delayOnCache) !== null && _d !== void 0 ? _d : 0)];
|
|
@@ -35,7 +35,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
35
35
|
}
|
|
36
36
|
};
|
|
37
37
|
import localforage from 'localforage';
|
|
38
|
-
import
|
|
38
|
+
import { add, isAfter, isEqual } from "date-fns";
|
|
39
39
|
;
|
|
40
40
|
var CacheControl = /** @class */ (function () {
|
|
41
41
|
function CacheControl() {
|
|
@@ -64,22 +64,20 @@ var CacheControl = /** @class */ (function () {
|
|
|
64
64
|
if (type === void 0) { type = ''; }
|
|
65
65
|
return __awaiter(this, void 0, void 0, function () {
|
|
66
66
|
var now, data;
|
|
67
|
-
|
|
68
|
-
|
|
67
|
+
var _a;
|
|
68
|
+
return __generator(this, function (_b) {
|
|
69
|
+
switch (_b.label) {
|
|
69
70
|
case 0:
|
|
70
|
-
now =
|
|
71
|
+
now = new Date();
|
|
71
72
|
data = {
|
|
72
73
|
value: value,
|
|
73
74
|
type: type,
|
|
74
|
-
cratedAt: now.
|
|
75
|
-
expire: now
|
|
76
|
-
.add(maxAge[0], maxAge[1])
|
|
77
|
-
.toDate()
|
|
78
|
-
.toISOString(),
|
|
75
|
+
cratedAt: now.toISOString(),
|
|
76
|
+
expire: add(now, (_a = {}, _a[maxAge[1]] = maxAge[0], _a)).toISOString(),
|
|
79
77
|
};
|
|
80
78
|
return [4 /*yield*/, this.getDbInstance().setItem(key, data)];
|
|
81
79
|
case 1:
|
|
82
|
-
|
|
80
|
+
_b.sent();
|
|
83
81
|
return [2 /*return*/];
|
|
84
82
|
}
|
|
85
83
|
});
|
|
@@ -115,11 +113,14 @@ var CacheControl = /** @class */ (function () {
|
|
|
115
113
|
var _this = this;
|
|
116
114
|
this.getDbInstance()
|
|
117
115
|
.iterate(function (value, key, _) {
|
|
118
|
-
if (value
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
116
|
+
if (value) {
|
|
117
|
+
var expireDate = new Date(value.expire);
|
|
118
|
+
var now = new Date();
|
|
119
|
+
if (isAfter(now, expireDate) || isEqual(now, expireDate)) {
|
|
120
|
+
_this.getDbInstance().removeItem(key, function () {
|
|
121
|
+
return console.log("Key ".concat(key, " is cleared!"));
|
|
122
|
+
});
|
|
123
|
+
}
|
|
123
124
|
}
|
|
124
125
|
})
|
|
125
126
|
.then(function () {
|
package/dist/utils/chat.utils.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ChatConstants } from "../constants";
|
|
2
|
-
import
|
|
2
|
+
import startCase from "lodash/startCase";
|
|
3
3
|
function getCanSendToSuperiors(chat, chatPermissions, quitedGroup, identification, userHierarchy) {
|
|
4
4
|
if (quitedGroup ||
|
|
5
5
|
!chatPermissions.canSendToSuperiors ||
|
|
@@ -66,7 +66,7 @@ export function getChatName(chat) {
|
|
|
66
66
|
if (!(chat === null || chat === void 0 ? void 0 : chat.name))
|
|
67
67
|
return "";
|
|
68
68
|
return (chat === null || chat === void 0 ? void 0 : chat.type) !== ChatConstants.TYPE_CHAT.GROUP
|
|
69
|
-
?
|
|
69
|
+
? startCase((_a = chat.name) === null || _a === void 0 ? void 0 : _a.toLowerCase())
|
|
70
70
|
: chat.name;
|
|
71
71
|
}
|
|
72
72
|
export function getPlaceholderMessage(canSendMessages, isActive) {
|
package/dist/utils/date.utils.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import cloneDeep from "lodash/cloneDeep";
|
|
2
|
+
import { isSameDay, isBefore, differenceInSeconds } from "date-fns";
|
|
3
3
|
import { GlobalStore } from "redux-micro-frontend";
|
|
4
4
|
var DateUtils = /** @class */ (function () {
|
|
5
5
|
function DateUtils() {
|
|
6
6
|
}
|
|
7
7
|
DateUtils.isSameDateAsNow = function (date) {
|
|
8
|
-
return
|
|
8
|
+
return isSameDay(new Date(date), new Date());
|
|
9
9
|
};
|
|
10
10
|
DateUtils.isPastDateAsNow = function (date) {
|
|
11
|
-
return
|
|
11
|
+
return isBefore(new Date(date), new Date());
|
|
12
12
|
};
|
|
13
13
|
DateUtils.getDateBetweenDates = function (start, end) {
|
|
14
|
-
var clonedStart =
|
|
14
|
+
var clonedStart = cloneDeep(start);
|
|
15
15
|
if (!start ||
|
|
16
16
|
!end ||
|
|
17
17
|
!(start instanceof Date) ||
|
|
@@ -78,7 +78,7 @@ var DateUtils = /** @class */ (function () {
|
|
|
78
78
|
if (length === void 0) { length = 2; }
|
|
79
79
|
return time.toString().padStart(length, "0");
|
|
80
80
|
}
|
|
81
|
-
var diff =
|
|
81
|
+
var diff = differenceInSeconds(new Date(compareDate), new Date());
|
|
82
82
|
var days = formatTime(Math.floor(diff / (60 * 60 * 24)), 3);
|
|
83
83
|
var hours = formatTime(Math.floor((diff % (60 * 60 * 24)) / (60 * 60)));
|
|
84
84
|
var minutes = formatTime(Math.floor((diff % (60 * 60)) / 60));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "robbyson-frontend-library",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.165",
|
|
4
4
|
"description": "Robbyson frontend Library",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"license": "MIT",
|
|
@@ -34,12 +34,12 @@
|
|
|
34
34
|
"@types/lovefield": "^2.1.6",
|
|
35
35
|
"axios": "^1.3.5",
|
|
36
36
|
"crypto-js": "^4.1.1",
|
|
37
|
+
"date-fns": "^4.1.0",
|
|
37
38
|
"history": "^5.3.0",
|
|
38
39
|
"js-sha256": "^0.9.0",
|
|
39
40
|
"localforage": "^1.10.0",
|
|
40
|
-
"lodash": "^4.17.
|
|
41
|
+
"lodash": "^4.17.23",
|
|
41
42
|
"lovefield": "^2.1.12",
|
|
42
|
-
"moment": "^2.29.4",
|
|
43
43
|
"query-string": "^8.1.0",
|
|
44
44
|
"react": "^18.2.0",
|
|
45
45
|
"react-inlinesvg": "^3.0.2",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import axios, { AxiosInstance, AxiosRequestConfig } from "axios";
|
|
2
|
-
import
|
|
2
|
+
import { isAfter, isEqual } from "date-fns";
|
|
3
3
|
import { CacheConfig, CacheControl, Cache } from "../utils";
|
|
4
4
|
import sha1 from "crypto-js/sha1";
|
|
5
5
|
import { GlobalStore, IGlobalStore } from "redux-micro-frontend";
|
|
@@ -52,9 +52,9 @@ export class BaseRepository {
|
|
|
52
52
|
const { expire, value }: Cache =
|
|
53
53
|
(await CacheControl.getCache(key)) || {};
|
|
54
54
|
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
);
|
|
55
|
+
const now = new Date();
|
|
56
|
+
const expireDate = new Date(expire);
|
|
57
|
+
const isExpired: boolean = isAfter(now, expireDate) || isEqual(now, expireDate);
|
|
58
58
|
|
|
59
59
|
if (value && !isExpired) {
|
|
60
60
|
console.log("RECOVERED FROM CACHE", url);
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { AxiosRequestConfig } from 'axios';
|
|
2
2
|
import localforage from 'localforage';
|
|
3
|
-
import
|
|
3
|
+
import { add, isAfter, isEqual } from "date-fns";
|
|
4
4
|
|
|
5
|
-
export type
|
|
5
|
+
export type DurationUnit = "seconds" | "minutes" | "hours" | "days" | "weeks" | "months" | "years";
|
|
6
|
+
|
|
7
|
+
export type MaxAge = [number, DurationUnit];
|
|
6
8
|
export interface CacheConfig extends AxiosRequestConfig {
|
|
7
9
|
cache?: boolean;
|
|
8
10
|
maxAge?: MaxAge;
|
|
@@ -12,7 +14,7 @@ export interface CacheConfig extends AxiosRequestConfig {
|
|
|
12
14
|
export type Cache = {
|
|
13
15
|
expire: string;
|
|
14
16
|
value: any
|
|
15
|
-
};
|
|
17
|
+
};
|
|
16
18
|
|
|
17
19
|
export class CacheControl {
|
|
18
20
|
|
|
@@ -41,15 +43,12 @@ export class CacheControl {
|
|
|
41
43
|
}
|
|
42
44
|
|
|
43
45
|
static async setCache(key: string, value: any, maxAge: MaxAge, type = ''): Promise<void> {
|
|
44
|
-
const now =
|
|
46
|
+
const now = new Date();
|
|
45
47
|
const data: any = {
|
|
46
48
|
value,
|
|
47
49
|
type,
|
|
48
|
-
cratedAt: now.
|
|
49
|
-
expire: now
|
|
50
|
-
.add(maxAge[0], maxAge[1])
|
|
51
|
-
.toDate()
|
|
52
|
-
.toISOString(),
|
|
50
|
+
cratedAt: now.toISOString(),
|
|
51
|
+
expire: add(now, { [maxAge[1]]: maxAge[0] }).toISOString(),
|
|
53
52
|
};
|
|
54
53
|
await this.getDbInstance().setItem(key, data);
|
|
55
54
|
}
|
|
@@ -74,13 +73,14 @@ export class CacheControl {
|
|
|
74
73
|
static clearExpiredCache(): void {
|
|
75
74
|
this.getDbInstance()
|
|
76
75
|
.iterate((value: any, key: string, _) => {
|
|
77
|
-
if (
|
|
78
|
-
value
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
76
|
+
if (value) {
|
|
77
|
+
const expireDate = new Date(value.expire);
|
|
78
|
+
const now = new Date();
|
|
79
|
+
if (isAfter(now, expireDate) || isEqual(now, expireDate)) {
|
|
80
|
+
this.getDbInstance().removeItem(key, () =>
|
|
81
|
+
console.log(`Key ${key} is cleared!`),
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
84
|
}
|
|
85
85
|
})
|
|
86
86
|
.then(() =>
|
package/src/utils/chat.utils.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ChatDTO } from "../services";
|
|
2
2
|
import { ChatModel } from "../models";
|
|
3
3
|
import { ChatConstants } from "../constants";
|
|
4
|
-
import
|
|
4
|
+
import startCase from "lodash/startCase";
|
|
5
5
|
|
|
6
6
|
function getCanSendToSuperiors(
|
|
7
7
|
chat: ChatModel,
|
|
@@ -102,7 +102,7 @@ export function getChatName(chat: ChatModel): string {
|
|
|
102
102
|
if (!chat?.name) return "";
|
|
103
103
|
|
|
104
104
|
return chat?.type !== ChatConstants.TYPE_CHAT.GROUP
|
|
105
|
-
?
|
|
105
|
+
? startCase(chat.name?.toLowerCase())
|
|
106
106
|
: chat.name;
|
|
107
107
|
}
|
|
108
108
|
|
package/src/utils/date.utils.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import cloneDeep from "lodash/cloneDeep";
|
|
2
|
+
import { isSameDay, isBefore, differenceInSeconds } from "date-fns";
|
|
3
3
|
import { GlobalStore } from "redux-micro-frontend";
|
|
4
4
|
import { IPlatformState } from "../states";
|
|
5
5
|
|
|
@@ -10,15 +10,15 @@ type RemainingTime = {
|
|
|
10
10
|
|
|
11
11
|
export class DateUtils {
|
|
12
12
|
static isSameDateAsNow(date: Date): boolean {
|
|
13
|
-
return
|
|
13
|
+
return isSameDay(new Date(date), new Date());
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
static isPastDateAsNow(date: Date): boolean {
|
|
17
|
-
return
|
|
17
|
+
return isBefore(new Date(date), new Date());
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
static getDateBetweenDates(start: Date, end: Date): Date[] {
|
|
21
|
-
const clonedStart =
|
|
21
|
+
const clonedStart = cloneDeep(start);
|
|
22
22
|
|
|
23
23
|
if (
|
|
24
24
|
!start ||
|
|
@@ -106,7 +106,7 @@ export class DateUtils {
|
|
|
106
106
|
return time.toString().padStart(length, "0");
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
-
const diff =
|
|
109
|
+
const diff = differenceInSeconds(new Date(compareDate), new Date());
|
|
110
110
|
|
|
111
111
|
const days = formatTime(Math.floor(diff / (60 * 60 * 24)), 3);
|
|
112
112
|
const hours = formatTime(
|
|
@@ -149,14 +149,14 @@ export class DateUtils {
|
|
|
149
149
|
minutes === 0
|
|
150
150
|
? "00"
|
|
151
151
|
: minutes < 10
|
|
152
|
-
|
|
153
|
-
|
|
152
|
+
? "0" + minutes
|
|
153
|
+
: minutes.toString();
|
|
154
154
|
let formattedSeconds =
|
|
155
155
|
seconds === 0
|
|
156
156
|
? "00"
|
|
157
157
|
: seconds < 10
|
|
158
|
-
|
|
159
|
-
|
|
158
|
+
? "0" + seconds
|
|
159
|
+
: seconds.toString();
|
|
160
160
|
|
|
161
161
|
let result = `${formattedHours}:${formattedMinutes}:${formattedSeconds}`;
|
|
162
162
|
|