asv-hlps 1.4.5 → 1.4.6
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/lib/cjs/auth/auth.d.ts +2 -1
- package/lib/cjs/auth/auth.js +18 -23
- package/lib/cjs/utils.d.ts +1 -0
- package/lib/cjs/utils.js +5 -0
- package/lib/esm/auth/auth.d.ts +2 -1
- package/lib/esm/auth/auth.js +18 -23
- package/lib/esm/utils.d.ts +1 -0
- package/lib/esm/utils.js +4 -0
- package/package.json +1 -1
package/lib/cjs/auth/auth.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Ste, SteGrp, UserGrp, UserRole } from "../users/models";
|
|
2
|
+
import AuthTag from "./models/AuthTag";
|
|
2
3
|
interface AuthParam {
|
|
3
4
|
tag?: string;
|
|
4
5
|
roles?: string[];
|
|
@@ -17,7 +18,7 @@ interface AuthParam {
|
|
|
17
18
|
url?: string;
|
|
18
19
|
}
|
|
19
20
|
type TData = {
|
|
20
|
-
tags?: string[];
|
|
21
|
+
tags?: AuthTag[] | string[];
|
|
21
22
|
ste: Ste;
|
|
22
23
|
role: UserRole;
|
|
23
24
|
roles: string[];
|
package/lib/cjs/auth/auth.js
CHANGED
|
@@ -2,33 +2,28 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getAuth = void 0;
|
|
4
4
|
const user_1 = require("../users/user");
|
|
5
|
+
const utils_1 = require("../utils");
|
|
5
6
|
const arraySome = (arr1, arr2) => {
|
|
6
7
|
return arr1.some((x) => arr2.includes(x));
|
|
7
8
|
};
|
|
8
9
|
const getAuth = (authUser, authSte, param) => {
|
|
9
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
10
|
-
/* if (param?.tag && authUser?.tags?.length) {
|
|
11
|
-
const tags: string[] = [];
|
|
12
|
-
for (const tag of authUser.tags) {
|
|
13
|
-
tags.push(tag?.code?.toLowerCase());
|
|
14
|
-
}
|
|
15
|
-
const authIn = tags?.includes(param?.tag?.toLowerCase());
|
|
16
|
-
if (authIn) {
|
|
17
|
-
return true;
|
|
18
|
-
}
|
|
19
|
-
} */
|
|
10
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
20
11
|
if ((param === null || param === void 0 ? void 0 : param.tag) && ((_a = authUser === null || authUser === void 0 ? void 0 : authUser.tags) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
|
|
12
|
+
let tags = [];
|
|
13
|
+
if ((0, utils_1.checkIsStringOfArray)(authUser.tags)) {
|
|
14
|
+
tags = authUser === null || authUser === void 0 ? void 0 : authUser.tags;
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
for (const tag of authUser.tags) {
|
|
18
|
+
tags.push((_b = tag === null || tag === void 0 ? void 0 : tag.code) === null || _b === void 0 ? void 0 : _b.toLowerCase());
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
const authIn = tags === null || tags === void 0 ? void 0 : tags.includes((_c = param === null || param === void 0 ? void 0 : param.tag) === null || _c === void 0 ? void 0 : _c.toLowerCase());
|
|
27
22
|
if (authIn) {
|
|
28
23
|
return true;
|
|
29
24
|
}
|
|
30
25
|
}
|
|
31
|
-
if (((
|
|
26
|
+
if (((_d = param === null || param === void 0 ? void 0 : param.roles) === null || _d === void 0 ? void 0 : _d.length) > 0) {
|
|
32
27
|
/* if (isStaffSte(authSte, authUser.ste.name) && ["sadm", ...param.roles].includes(authUser.role.code.toLowerCase())) {
|
|
33
28
|
return true;
|
|
34
29
|
} */
|
|
@@ -38,7 +33,7 @@ const getAuth = (authUser, authSte, param) => {
|
|
|
38
33
|
}
|
|
39
34
|
// ------ staff ------
|
|
40
35
|
if (param === null || param === void 0 ? void 0 : param.staff) {
|
|
41
|
-
if (((
|
|
36
|
+
if (((_e = param === null || param === void 0 ? void 0 : param.staff.roles) === null || _e === void 0 ? void 0 : _e.length) > 0 &&
|
|
42
37
|
(0, user_1.isStaffSte)(authSte, authUser.ste.name) &&
|
|
43
38
|
["sadm", ...param.roles].includes(authUser.role.code.toLowerCase())) {
|
|
44
39
|
return true;
|
|
@@ -59,7 +54,7 @@ const getAuth = (authUser, authSte, param) => {
|
|
|
59
54
|
param.client.steGrps.includes(authUser.ste.grp.code.toLowerCase())) {
|
|
60
55
|
return true;
|
|
61
56
|
}
|
|
62
|
-
if (((
|
|
57
|
+
if (((_f = param === null || param === void 0 ? void 0 : param.client.roles) === null || _f === void 0 ? void 0 : _f.length) &&
|
|
63
58
|
(param === null || param === void 0 ? void 0 : param.client.steGrps.length) &&
|
|
64
59
|
["ceo", ...param === null || param === void 0 ? void 0 : param.client.roles].includes(authUser.role.code.toLowerCase()) &&
|
|
65
60
|
(param === null || param === void 0 ? void 0 : param.client.steGrps).includes(authUser.ste.grp.code.toLowerCase())) {
|
|
@@ -68,13 +63,13 @@ const getAuth = (authUser, authSte, param) => {
|
|
|
68
63
|
}
|
|
69
64
|
}
|
|
70
65
|
// ------ ste grps ------
|
|
71
|
-
if (((
|
|
66
|
+
if (((_g = param === null || param === void 0 ? void 0 : param.steGrps) === null || _g === void 0 ? void 0 : _g.length) > 0 && param.steGrps.includes(authUser.ste.grp.code.toLowerCase())) {
|
|
72
67
|
return true;
|
|
73
68
|
}
|
|
74
|
-
if (((
|
|
69
|
+
if (((_h = param === null || param === void 0 ? void 0 : param.grps) === null || _h === void 0 ? void 0 : _h.length) && param.grps.includes(authUser.grp.code.toLowerCase())) {
|
|
75
70
|
return true;
|
|
76
71
|
}
|
|
77
|
-
if (((
|
|
72
|
+
if (((_j = param === null || param === void 0 ? void 0 : param.steNames) === null || _j === void 0 ? void 0 : _j.length) > 0 && param.steNames.includes(authUser.ste.name.toLowerCase())) {
|
|
78
73
|
return true;
|
|
79
74
|
}
|
|
80
75
|
return false;
|
package/lib/cjs/utils.d.ts
CHANGED
|
@@ -108,3 +108,4 @@ export declare const toggleProp: (tob: any, propToToggle: string) => any;
|
|
|
108
108
|
export declare const winMaxHeight: (step?: 0.2 | 0.3 | 0.4 | 0.5 | 0.6 | 0.7 | 0.8 | 0.9) => number;
|
|
109
109
|
export declare const arraySome: (arr1: any[], arr2: any[]) => boolean;
|
|
110
110
|
export declare const checkObjInArray: (objs: any[], checkProp: string | number, prop?: string) => boolean;
|
|
111
|
+
export declare function checkIsStringOfArray(array: unknown[]): array is string[];
|
package/lib/cjs/utils.js
CHANGED
|
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.unCheckedAll = exports.inputChecked = exports.arrayMultiChecked = exports.getPeriodDateColor = exports.getColorAccordingToDate = exports.genRandomColour = exports.formatNgbDate = exports.getNbOfDaysBetweenTwoDates = exports.displayDateRangeFr = exports.reformatDates = exports.firstDayOfDate = exports.dateToString = exports.dateDiff = exports.dateFormatter = exports.replaceSpacesWith = exports.replaceAllIn = exports.toPlural = exports.sesStorageGet = exports.sesStorageSet = exports.genSequenceRef = exports.refGenerator = exports.removeBackSlashOccurences = exports.stringifyFormatter = exports.removeString = exports.diffArraysByProp = exports.diffArraysByFunc = exports.deepClone = exports.findFirstSequenceMissing = exports.fillNumWithZero = exports.findSequencesMissing = exports.sequencesToNumbers = exports.notInSequence = exports.currencyFormatterCfa = exports.formatToStringCfa = exports.currencyFormatter = exports.formatToString = exports.checkAuth = exports.wakeUp = exports.sleep = exports.limitTo = exports.titleCase = exports.toObjectDate = exports.duplicateObjects = exports.removeDuplicateObjects = exports.getRandomColor = exports.calPercent = exports.percentOf = exports.genDateMinutesStep = exports.formatDateFirstDayFr = exports.isEmpty = void 0;
|
|
7
7
|
exports.checkObjInArray = exports.arraySome = exports.winMaxHeight = exports.toggleProp = exports.roundLastNDigits = exports.removeParamKeyName = exports.countryIsoToFlag = exports.monthStringName = exports.returnBool = exports.formatAmountToString = exports.reduceTimes = exports.reduceSum = exports.sumAmount = exports.fillEndWithZero = exports.fillStartWithZero = exports.absFromSequence = exports.returnDates = exports.displayFrDatePeriode = exports.getArrayOfRandomColor = exports.randomHslColor = exports.randomHexColor = exports.randomRgbColor = exports.randomInteger = exports.insertAtInArray = exports.isBirthday = exports.padEndWithZero = exports.padStartWithZero = exports.formatMonthYearToLocaleString = exports.calculPercent = exports.validEmail = exports.convertToCfa = exports.packAndUnit = void 0;
|
|
8
|
+
exports.checkIsStringOfArray = checkIsStringOfArray;
|
|
8
9
|
const dayjs_1 = __importDefault(require("dayjs"));
|
|
9
10
|
const relativeTime_1 = __importDefault(require("dayjs/plugin/relativeTime"));
|
|
10
11
|
const lodash_1 = __importDefault(require("lodash"));
|
|
@@ -774,3 +775,7 @@ const checkObjInArray = (objs, checkProp, prop = "id") => {
|
|
|
774
775
|
});
|
|
775
776
|
};
|
|
776
777
|
exports.checkObjInArray = checkObjInArray;
|
|
778
|
+
function checkIsStringOfArray(array) {
|
|
779
|
+
// return array.every((element) => typeof element === "string");
|
|
780
|
+
return array.some((element) => typeof element === "string");
|
|
781
|
+
}
|
package/lib/esm/auth/auth.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Ste, SteGrp, UserGrp, UserRole } from "../users/models";
|
|
2
|
+
import AuthTag from "./models/AuthTag";
|
|
2
3
|
interface AuthParam {
|
|
3
4
|
tag?: string;
|
|
4
5
|
roles?: string[];
|
|
@@ -17,7 +18,7 @@ interface AuthParam {
|
|
|
17
18
|
url?: string;
|
|
18
19
|
}
|
|
19
20
|
type TData = {
|
|
20
|
-
tags?: string[];
|
|
21
|
+
tags?: AuthTag[] | string[];
|
|
21
22
|
ste: Ste;
|
|
22
23
|
role: UserRole;
|
|
23
24
|
roles: string[];
|
package/lib/esm/auth/auth.js
CHANGED
|
@@ -1,31 +1,26 @@
|
|
|
1
1
|
import { isStaffSte } from "../users/user";
|
|
2
|
+
import { checkIsStringOfArray } from "../utils";
|
|
2
3
|
const arraySome = (arr1, arr2) => {
|
|
3
4
|
return arr1.some((x) => arr2.includes(x));
|
|
4
5
|
};
|
|
5
6
|
const getAuth = (authUser, authSte, param) => {
|
|
6
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
7
|
-
/* if (param?.tag && authUser?.tags?.length) {
|
|
8
|
-
const tags: string[] = [];
|
|
9
|
-
for (const tag of authUser.tags) {
|
|
10
|
-
tags.push(tag?.code?.toLowerCase());
|
|
11
|
-
}
|
|
12
|
-
const authIn = tags?.includes(param?.tag?.toLowerCase());
|
|
13
|
-
if (authIn) {
|
|
14
|
-
return true;
|
|
15
|
-
}
|
|
16
|
-
} */
|
|
7
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
17
8
|
if ((param === null || param === void 0 ? void 0 : param.tag) && ((_a = authUser === null || authUser === void 0 ? void 0 : authUser.tags) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
|
|
9
|
+
let tags = [];
|
|
10
|
+
if (checkIsStringOfArray(authUser.tags)) {
|
|
11
|
+
tags = authUser === null || authUser === void 0 ? void 0 : authUser.tags;
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
for (const tag of authUser.tags) {
|
|
15
|
+
tags.push((_b = tag === null || tag === void 0 ? void 0 : tag.code) === null || _b === void 0 ? void 0 : _b.toLowerCase());
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
const authIn = tags === null || tags === void 0 ? void 0 : tags.includes((_c = param === null || param === void 0 ? void 0 : param.tag) === null || _c === void 0 ? void 0 : _c.toLowerCase());
|
|
24
19
|
if (authIn) {
|
|
25
20
|
return true;
|
|
26
21
|
}
|
|
27
22
|
}
|
|
28
|
-
if (((
|
|
23
|
+
if (((_d = param === null || param === void 0 ? void 0 : param.roles) === null || _d === void 0 ? void 0 : _d.length) > 0) {
|
|
29
24
|
/* if (isStaffSte(authSte, authUser.ste.name) && ["sadm", ...param.roles].includes(authUser.role.code.toLowerCase())) {
|
|
30
25
|
return true;
|
|
31
26
|
} */
|
|
@@ -35,7 +30,7 @@ const getAuth = (authUser, authSte, param) => {
|
|
|
35
30
|
}
|
|
36
31
|
// ------ staff ------
|
|
37
32
|
if (param === null || param === void 0 ? void 0 : param.staff) {
|
|
38
|
-
if (((
|
|
33
|
+
if (((_e = param === null || param === void 0 ? void 0 : param.staff.roles) === null || _e === void 0 ? void 0 : _e.length) > 0 &&
|
|
39
34
|
isStaffSte(authSte, authUser.ste.name) &&
|
|
40
35
|
["sadm", ...param.roles].includes(authUser.role.code.toLowerCase())) {
|
|
41
36
|
return true;
|
|
@@ -56,7 +51,7 @@ const getAuth = (authUser, authSte, param) => {
|
|
|
56
51
|
param.client.steGrps.includes(authUser.ste.grp.code.toLowerCase())) {
|
|
57
52
|
return true;
|
|
58
53
|
}
|
|
59
|
-
if (((
|
|
54
|
+
if (((_f = param === null || param === void 0 ? void 0 : param.client.roles) === null || _f === void 0 ? void 0 : _f.length) &&
|
|
60
55
|
(param === null || param === void 0 ? void 0 : param.client.steGrps.length) &&
|
|
61
56
|
["ceo", ...param === null || param === void 0 ? void 0 : param.client.roles].includes(authUser.role.code.toLowerCase()) &&
|
|
62
57
|
(param === null || param === void 0 ? void 0 : param.client.steGrps).includes(authUser.ste.grp.code.toLowerCase())) {
|
|
@@ -65,13 +60,13 @@ const getAuth = (authUser, authSte, param) => {
|
|
|
65
60
|
}
|
|
66
61
|
}
|
|
67
62
|
// ------ ste grps ------
|
|
68
|
-
if (((
|
|
63
|
+
if (((_g = param === null || param === void 0 ? void 0 : param.steGrps) === null || _g === void 0 ? void 0 : _g.length) > 0 && param.steGrps.includes(authUser.ste.grp.code.toLowerCase())) {
|
|
69
64
|
return true;
|
|
70
65
|
}
|
|
71
|
-
if (((
|
|
66
|
+
if (((_h = param === null || param === void 0 ? void 0 : param.grps) === null || _h === void 0 ? void 0 : _h.length) && param.grps.includes(authUser.grp.code.toLowerCase())) {
|
|
72
67
|
return true;
|
|
73
68
|
}
|
|
74
|
-
if (((
|
|
69
|
+
if (((_j = param === null || param === void 0 ? void 0 : param.steNames) === null || _j === void 0 ? void 0 : _j.length) > 0 && param.steNames.includes(authUser.ste.name.toLowerCase())) {
|
|
75
70
|
return true;
|
|
76
71
|
}
|
|
77
72
|
return false;
|
package/lib/esm/utils.d.ts
CHANGED
|
@@ -108,3 +108,4 @@ export declare const toggleProp: (tob: any, propToToggle: string) => any;
|
|
|
108
108
|
export declare const winMaxHeight: (step?: 0.2 | 0.3 | 0.4 | 0.5 | 0.6 | 0.7 | 0.8 | 0.9) => number;
|
|
109
109
|
export declare const arraySome: (arr1: any[], arr2: any[]) => boolean;
|
|
110
110
|
export declare const checkObjInArray: (objs: any[], checkProp: string | number, prop?: string) => boolean;
|
|
111
|
+
export declare function checkIsStringOfArray(array: unknown[]): array is string[];
|
package/lib/esm/utils.js
CHANGED
|
@@ -685,3 +685,7 @@ export const checkObjInArray = (objs, checkProp, prop = "id") => {
|
|
|
685
685
|
return x[prop] === checkProp;
|
|
686
686
|
});
|
|
687
687
|
};
|
|
688
|
+
export function checkIsStringOfArray(array) {
|
|
689
|
+
// return array.every((element) => typeof element === "string");
|
|
690
|
+
return array.some((element) => typeof element === "string");
|
|
691
|
+
}
|