asv-hlps 1.2.1 → 1.2.4

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.
@@ -0,0 +1,14 @@
1
+ import { User } from "./models/entities/users/User";
2
+ export interface AuthParam {
3
+ tag?: string;
4
+ roles?: string[];
5
+ grps?: string[];
6
+ client?: {
7
+ roles?: string[];
8
+ steGrps?: string[];
9
+ };
10
+ steGrps?: string[];
11
+ steNames?: string[];
12
+ url?: string;
13
+ }
14
+ export declare const getAuth: (authUser: User, param?: AuthParam) => boolean;
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getAuth = void 0;
4
+ const user_1 = require("./user");
5
+ const getAuth = (authUser, param) => {
6
+ var _a, _b, _c, _d, _e, _f;
7
+ // let auth: boolean = false;
8
+ if ((param === null || param === void 0 ? void 0 : param.tag) && (authUser === null || authUser === void 0 ? void 0 : authUser.tags)) {
9
+ const tags = [];
10
+ for (const tag of authUser.tags) {
11
+ tags.push(tag.code.toLowerCase());
12
+ }
13
+ const authIn = tags.includes(param.tag.toLowerCase());
14
+ if (authIn) {
15
+ return true;
16
+ }
17
+ }
18
+ if ((_a = param === null || param === void 0 ? void 0 : param.roles) === null || _a === void 0 ? void 0 : _a.length) {
19
+ if ((0, user_1.isStaffSte)(["cpa"], authUser)) {
20
+ return ((_b = param === null || param === void 0 ? void 0 : param.roles) === null || _b === void 0 ? void 0 : _b.length) ? ["sadm", ...param.roles].includes(authUser.role.code.toLowerCase()) : false;
21
+ // ------ multi roles ------
22
+ // return param?.roles?.length ? this.checkRoles(["sadm", ...param.roles]) : false;
23
+ }
24
+ }
25
+ if ((_c = param === null || param === void 0 ? void 0 : param.steGrps) === null || _c === void 0 ? void 0 : _c.length) {
26
+ return param.steGrps.includes(authUser.ste.grp.code.toLowerCase());
27
+ }
28
+ if ((_d = param === null || param === void 0 ? void 0 : param.grps) === null || _d === void 0 ? void 0 : _d.length) {
29
+ return param.grps.includes(authUser.grp.code.toLowerCase());
30
+ }
31
+ if (param === null || param === void 0 ? void 0 : param.client) {
32
+ if (!(0, user_1.isStaffSte)(["cpa"], authUser)) {
33
+ if (param.client.roles && !param.client.steGrps) {
34
+ return param.client.roles.length ? ["ceo", ...param === null || param === void 0 ? void 0 : param.client.roles].includes(authUser.role.code.toLowerCase()) : false;
35
+ }
36
+ if (!param.client.roles && param.client.steGrps) {
37
+ return param.client.steGrps.length ? param.client.steGrps.includes(authUser.ste.grp.code.toLowerCase()) : false;
38
+ }
39
+ return ((_e = param === null || param === void 0 ? void 0 : param.client.roles) === null || _e === void 0 ? void 0 : _e.length) && (param === null || param === void 0 ? void 0 : param.client.steGrps.length)
40
+ ? ["ceo", ...param === null || param === void 0 ? void 0 : param.client.roles].includes(authUser.role.code.toLowerCase()) &&
41
+ (param === null || param === void 0 ? void 0 : param.client.steGrps).includes(authUser.ste.grp.code.toLowerCase())
42
+ : false;
43
+ }
44
+ /* const authIn = (param.steGrps).includes(this.authUser.ste.grp.code.toLowerCase());
45
+ if(authIn) { return true} */
46
+ }
47
+ if ((_f = param === null || param === void 0 ? void 0 : param.steNames) === null || _f === void 0 ? void 0 : _f.length) {
48
+ return param.steNames.includes(authUser.ste.name.toLowerCase());
49
+ /* const authIn = (param.steGrps).includes(this.authUser.ste.grp.code.toLowerCase());
50
+ if(authIn) { return true} */
51
+ }
52
+ /* if (param?.url) {
53
+ return this.router.url === param.url;
54
+ } */
55
+ // return false;
56
+ // return auth;
57
+ /* if(param?.steGrps?.length) {
58
+ auth = (param.steGrps).includes(this.authUser.ste.grp.code.toLowerCase());
59
+ } */
60
+ };
61
+ exports.getAuth = getAuth;
@@ -15,6 +15,7 @@ import "./sale";
15
15
  import "./typeorm";
16
16
  import "./user";
17
17
  import "./utils";
18
+ import "./auth";
18
19
  export * from "./bill";
19
20
  export * from "./models/index";
20
21
  export * from "./pdfs/invoices/amountInvoice";
@@ -27,4 +28,5 @@ export * from "./user";
27
28
  export * from "./utils";
28
29
  export * from "./react-utils";
29
30
  export * from "./bootstrap";
31
+ export * from "./auth";
30
32
  export { HlpProduct, HlpEntry, StockPipe, AmountOnListBillPipe, AmountOnBillPipe };
package/lib/cjs/index.js CHANGED
@@ -40,6 +40,7 @@ require("./sale");
40
40
  require("./typeorm");
41
41
  require("./user");
42
42
  require("./utils");
43
+ require("./auth");
43
44
  __exportStar(require("./bill"), exports);
44
45
  __exportStar(require("./models/index"), exports);
45
46
  __exportStar(require("./pdfs/invoices/amountInvoice"), exports);
@@ -52,3 +53,4 @@ __exportStar(require("./user"), exports);
52
53
  __exportStar(require("./utils"), exports);
53
54
  __exportStar(require("./react-utils"), exports);
54
55
  __exportStar(require("./bootstrap"), exports);
56
+ __exportStar(require("./auth"), exports);
@@ -1,3 +1,4 @@
1
+ import { AuthParam } from "../../auth";
1
2
  export interface IPath {
2
3
  id: number;
3
4
  title: any;
@@ -5,7 +6,7 @@ export interface IPath {
5
6
  default?: boolean;
6
7
  icon?: string;
7
8
  param?: any;
8
- auth?: any;
9
+ authParam?: AuthParam;
9
10
  ms?: boolean;
10
11
  }
11
12
  export declare type HeaderTableColumnType = {
@@ -13,7 +14,7 @@ export declare type HeaderTableColumnType = {
13
14
  accessor?: string;
14
15
  content?: any;
15
16
  style?: any;
16
- auth?: boolean;
17
+ authParam?: AuthParam;
17
18
  tooltipH?: any;
18
19
  tooltipB?: any;
19
20
  };
@@ -0,0 +1,14 @@
1
+ import { User } from "./models/entities/users/User";
2
+ export interface AuthParam {
3
+ tag?: string;
4
+ roles?: string[];
5
+ grps?: string[];
6
+ client?: {
7
+ roles?: string[];
8
+ steGrps?: string[];
9
+ };
10
+ steGrps?: string[];
11
+ steNames?: string[];
12
+ url?: string;
13
+ }
14
+ export declare const getAuth: (authUser: User, param?: AuthParam) => boolean;
@@ -0,0 +1,57 @@
1
+ import { isStaffSte } from "./user";
2
+ export const getAuth = (authUser, param) => {
3
+ var _a, _b, _c, _d, _e, _f;
4
+ // let auth: boolean = false;
5
+ if ((param === null || param === void 0 ? void 0 : param.tag) && (authUser === null || authUser === void 0 ? void 0 : authUser.tags)) {
6
+ const tags = [];
7
+ for (const tag of authUser.tags) {
8
+ tags.push(tag.code.toLowerCase());
9
+ }
10
+ const authIn = tags.includes(param.tag.toLowerCase());
11
+ if (authIn) {
12
+ return true;
13
+ }
14
+ }
15
+ if ((_a = param === null || param === void 0 ? void 0 : param.roles) === null || _a === void 0 ? void 0 : _a.length) {
16
+ if (isStaffSte(["cpa"], authUser)) {
17
+ return ((_b = param === null || param === void 0 ? void 0 : param.roles) === null || _b === void 0 ? void 0 : _b.length) ? ["sadm", ...param.roles].includes(authUser.role.code.toLowerCase()) : false;
18
+ // ------ multi roles ------
19
+ // return param?.roles?.length ? this.checkRoles(["sadm", ...param.roles]) : false;
20
+ }
21
+ }
22
+ if ((_c = param === null || param === void 0 ? void 0 : param.steGrps) === null || _c === void 0 ? void 0 : _c.length) {
23
+ return param.steGrps.includes(authUser.ste.grp.code.toLowerCase());
24
+ }
25
+ if ((_d = param === null || param === void 0 ? void 0 : param.grps) === null || _d === void 0 ? void 0 : _d.length) {
26
+ return param.grps.includes(authUser.grp.code.toLowerCase());
27
+ }
28
+ if (param === null || param === void 0 ? void 0 : param.client) {
29
+ if (!isStaffSte(["cpa"], authUser)) {
30
+ if (param.client.roles && !param.client.steGrps) {
31
+ return param.client.roles.length ? ["ceo", ...param === null || param === void 0 ? void 0 : param.client.roles].includes(authUser.role.code.toLowerCase()) : false;
32
+ }
33
+ if (!param.client.roles && param.client.steGrps) {
34
+ return param.client.steGrps.length ? param.client.steGrps.includes(authUser.ste.grp.code.toLowerCase()) : false;
35
+ }
36
+ return ((_e = param === null || param === void 0 ? void 0 : param.client.roles) === null || _e === void 0 ? void 0 : _e.length) && (param === null || param === void 0 ? void 0 : param.client.steGrps.length)
37
+ ? ["ceo", ...param === null || param === void 0 ? void 0 : param.client.roles].includes(authUser.role.code.toLowerCase()) &&
38
+ (param === null || param === void 0 ? void 0 : param.client.steGrps).includes(authUser.ste.grp.code.toLowerCase())
39
+ : false;
40
+ }
41
+ /* const authIn = (param.steGrps).includes(this.authUser.ste.grp.code.toLowerCase());
42
+ if(authIn) { return true} */
43
+ }
44
+ if ((_f = param === null || param === void 0 ? void 0 : param.steNames) === null || _f === void 0 ? void 0 : _f.length) {
45
+ return param.steNames.includes(authUser.ste.name.toLowerCase());
46
+ /* const authIn = (param.steGrps).includes(this.authUser.ste.grp.code.toLowerCase());
47
+ if(authIn) { return true} */
48
+ }
49
+ /* if (param?.url) {
50
+ return this.router.url === param.url;
51
+ } */
52
+ // return false;
53
+ // return auth;
54
+ /* if(param?.steGrps?.length) {
55
+ auth = (param.steGrps).includes(this.authUser.ste.grp.code.toLowerCase());
56
+ } */
57
+ };
@@ -15,6 +15,7 @@ import "./sale";
15
15
  import "./typeorm";
16
16
  import "./user";
17
17
  import "./utils";
18
+ import "./auth";
18
19
  export * from "./bill";
19
20
  export * from "./models/index";
20
21
  export * from "./pdfs/invoices/amountInvoice";
@@ -27,4 +28,5 @@ export * from "./user";
27
28
  export * from "./utils";
28
29
  export * from "./react-utils";
29
30
  export * from "./bootstrap";
31
+ export * from "./auth";
30
32
  export { HlpProduct, HlpEntry, StockPipe, AmountOnListBillPipe, AmountOnBillPipe };
package/lib/esm/index.js CHANGED
@@ -15,6 +15,7 @@ import "./sale";
15
15
  import "./typeorm";
16
16
  import "./user";
17
17
  import "./utils";
18
+ import "./auth";
18
19
  export * from "./bill";
19
20
  export * from "./models/index";
20
21
  export * from "./pdfs/invoices/amountInvoice";
@@ -27,5 +28,6 @@ export * from "./user";
27
28
  export * from "./utils";
28
29
  export * from "./react-utils";
29
30
  export * from "./bootstrap";
31
+ export * from "./auth";
30
32
  // export * from "./helpers/hlpProduct";
31
33
  export { HlpProduct, HlpEntry, StockPipe, AmountOnListBillPipe, AmountOnBillPipe };
@@ -1,3 +1,4 @@
1
+ import { AuthParam } from "../../auth";
1
2
  export interface IPath {
2
3
  id: number;
3
4
  title: any;
@@ -5,7 +6,7 @@ export interface IPath {
5
6
  default?: boolean;
6
7
  icon?: string;
7
8
  param?: any;
8
- auth?: any;
9
+ authParam?: AuthParam;
9
10
  ms?: boolean;
10
11
  }
11
12
  export declare type HeaderTableColumnType = {
@@ -13,7 +14,7 @@ export declare type HeaderTableColumnType = {
13
14
  accessor?: string;
14
15
  content?: any;
15
16
  style?: any;
16
- auth?: boolean;
17
+ authParam?: AuthParam;
17
18
  tooltipH?: any;
18
19
  tooltipB?: any;
19
20
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "asv-hlps",
3
- "version": "1.2.1",
3
+ "version": "1.2.4",
4
4
  "description": "",
5
5
  "main": "./lib/cjs/index.js",
6
6
  "module": "./lib/esm/index.js",