@etsoo/appscript 1.1.47 → 1.1.51

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.
@@ -5,6 +5,7 @@ import { AddressRegion } from '../address/AddressRegion';
5
5
  import { IActionResult } from '../result/IActionResult';
6
6
  import { IUserData } from '../state/User';
7
7
  import { IAppSettings } from './AppSettings';
8
+ import { UserRole } from './UserRole';
8
9
  /**
9
10
  * Detect IP callback interface
10
11
  */
@@ -158,6 +159,12 @@ export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallP
158
159
  * @returns Time zone
159
160
  */
160
161
  getTimeZone(): string | undefined;
162
+ /**
163
+ * Check use has the specific role permission or not
164
+ * @param roles Roles to check
165
+ * @returns Result
166
+ */
167
+ hasPermission(roles: number | UserRole | number[] | UserRole[]): boolean;
161
168
  /**
162
169
  * Callback where exit a page
163
170
  */
@@ -182,7 +189,7 @@ export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallP
182
189
  * @param refreshToken Refresh token
183
190
  * @param keep Keep in local storage or not
184
191
  */
185
- userLogin(user: IUserData, refreshToken?: string, keep?: boolean): void;
192
+ userLogin(user: IUserData, refreshToken: string, keep?: boolean): void;
186
193
  /**
187
194
  * User logout
188
195
  * @param clearToken Clear refresh token or not
@@ -376,6 +383,12 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
376
383
  * @returns Time zone
377
384
  */
378
385
  getTimeZone(): string | undefined;
386
+ /**
387
+ * Check use has the specific role permission or not
388
+ * @param roles Roles to check
389
+ * @returns Result
390
+ */
391
+ hasPermission(roles: number | UserRole | number[] | UserRole[]): boolean;
379
392
  /**
380
393
  * Callback where exit a page
381
394
  */
@@ -415,7 +428,7 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
415
428
  * @param refreshToken Refresh token
416
429
  * @param keep Keep in local storage or not
417
430
  */
418
- userLogin(user: IUserData, refreshToken?: string, keep?: boolean): void;
431
+ userLogin(user: IUserData, refreshToken: string, keep?: boolean): void;
419
432
  /**
420
433
  * User logout
421
434
  * @param clearToken Clear refresh token or not
@@ -338,6 +338,24 @@ class CoreApp {
338
338
  // settings.timeZone = Utils.getTimeZone()
339
339
  return (_a = this.settings.timeZone) !== null && _a !== void 0 ? _a : (_b = this.ipData) === null || _b === void 0 ? void 0 : _b.timezone;
340
340
  }
341
+ /**
342
+ * Check use has the specific role permission or not
343
+ * @param roles Roles to check
344
+ * @returns Result
345
+ */
346
+ hasPermission(roles) {
347
+ var _a;
348
+ const userRole = (_a = this.userData) === null || _a === void 0 ? void 0 : _a.role;
349
+ if (userRole == null)
350
+ return false;
351
+ if (Array.isArray(roles)) {
352
+ return roles.some((role) => (userRole & role) === role);
353
+ }
354
+ // One role check
355
+ if ((userRole & roles) === roles)
356
+ return true;
357
+ return false;
358
+ }
341
359
  /**
342
360
  * Callback where exit a page
343
361
  */
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Standard user roles
3
+ * @see com.etsoo.CoreFramework.Authentication.UserRole
4
+ */
5
+ export declare enum UserRole {
6
+ /**
7
+ * Guest
8
+ */
9
+ Guest = 1,
10
+ /**
11
+ * Outsourcing
12
+ */
13
+ Outsourcing = 2,
14
+ /**
15
+ * Operator
16
+ */
17
+ Operator = 4,
18
+ /**
19
+ * User
20
+ */
21
+ User = 8,
22
+ /**
23
+ * Manager
24
+ */
25
+ Manager = 128,
26
+ /**
27
+ * Finance
28
+ */
29
+ Finance = 256,
30
+ /**
31
+ * HR Manager
32
+ */
33
+ HRManager = 512,
34
+ /**
35
+ * Administrator
36
+ */
37
+ Admin = 8192,
38
+ /**
39
+ * Founder, takes all ownership
40
+ */
41
+ Founder = 16384
42
+ }
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UserRole = void 0;
4
+ /**
5
+ * Standard user roles
6
+ * @see com.etsoo.CoreFramework.Authentication.UserRole
7
+ */
8
+ var UserRole;
9
+ (function (UserRole) {
10
+ /**
11
+ * Guest
12
+ */
13
+ UserRole[UserRole["Guest"] = 1] = "Guest";
14
+ /**
15
+ * Outsourcing
16
+ */
17
+ UserRole[UserRole["Outsourcing"] = 2] = "Outsourcing";
18
+ /**
19
+ * Operator
20
+ */
21
+ UserRole[UserRole["Operator"] = 4] = "Operator";
22
+ /**
23
+ * User
24
+ */
25
+ UserRole[UserRole["User"] = 8] = "User";
26
+ /**
27
+ * Manager
28
+ */
29
+ UserRole[UserRole["Manager"] = 128] = "Manager";
30
+ /**
31
+ * Finance
32
+ */
33
+ UserRole[UserRole["Finance"] = 256] = "Finance";
34
+ /**
35
+ * HR Manager
36
+ */
37
+ UserRole[UserRole["HRManager"] = 512] = "HRManager";
38
+ /**
39
+ * Administrator
40
+ */
41
+ UserRole[UserRole["Admin"] = 8192] = "Admin";
42
+ /**
43
+ * Founder, takes all ownership
44
+ */
45
+ UserRole[UserRole["Founder"] = 16384] = "Founder";
46
+ })(UserRole = exports.UserRole || (exports.UserRole = {}));
@@ -31,6 +31,7 @@
31
31
  "name": "Name",
32
32
  "no": "No",
33
33
  "noChanges": "No changes yet",
34
+ "noData": "No valid data",
34
35
  "noOptions": "No options",
35
36
  "ok": "OK",
36
37
  "open": "Open",
@@ -31,6 +31,7 @@
31
31
  "name": "姓名",
32
32
  "no": "否",
33
33
  "noChanges": "还没有任何修改",
34
+ "noData": "没有有效数据",
34
35
  "noOptions": "没有选项",
35
36
  "ok": "确定",
36
37
  "open": "打开",
@@ -31,6 +31,7 @@
31
31
  "name": "姓名",
32
32
  "no": "否",
33
33
  "noChanges": "還沒有任何修改",
34
+ "noData": "沒有有效數據",
34
35
  "noOptions": "沒有選項",
35
36
  "ok": "確定",
36
37
  "open": "打開",
@@ -4,6 +4,7 @@ export * from './address/AddressUtils';
4
4
  export * from './app/AppSettings';
5
5
  export * from './app/CoreApp';
6
6
  export * from './app/ExternalSettings';
7
+ export * from './app/UserRole';
7
8
  export * from './bridges/ElectronBridge';
8
9
  export * from './bridges/IAppData';
9
10
  export * from './bridges/IBridge';
package/lib/cjs/index.js CHANGED
@@ -19,6 +19,7 @@ __exportStar(require("./address/AddressUtils"), exports);
19
19
  __exportStar(require("./app/AppSettings"), exports);
20
20
  __exportStar(require("./app/CoreApp"), exports);
21
21
  __exportStar(require("./app/ExternalSettings"), exports);
22
+ __exportStar(require("./app/UserRole"), exports);
22
23
  // bridges
23
24
  __exportStar(require("./bridges/ElectronBridge"), exports);
24
25
  __exportStar(require("./bridges/IAppData"), exports);
@@ -5,6 +5,7 @@ import { AddressRegion } from '../address/AddressRegion';
5
5
  import { IActionResult } from '../result/IActionResult';
6
6
  import { IUserData } from '../state/User';
7
7
  import { IAppSettings } from './AppSettings';
8
+ import { UserRole } from './UserRole';
8
9
  /**
9
10
  * Detect IP callback interface
10
11
  */
@@ -158,6 +159,12 @@ export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallP
158
159
  * @returns Time zone
159
160
  */
160
161
  getTimeZone(): string | undefined;
162
+ /**
163
+ * Check use has the specific role permission or not
164
+ * @param roles Roles to check
165
+ * @returns Result
166
+ */
167
+ hasPermission(roles: number | UserRole | number[] | UserRole[]): boolean;
161
168
  /**
162
169
  * Callback where exit a page
163
170
  */
@@ -182,7 +189,7 @@ export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallP
182
189
  * @param refreshToken Refresh token
183
190
  * @param keep Keep in local storage or not
184
191
  */
185
- userLogin(user: IUserData, refreshToken?: string, keep?: boolean): void;
192
+ userLogin(user: IUserData, refreshToken: string, keep?: boolean): void;
186
193
  /**
187
194
  * User logout
188
195
  * @param clearToken Clear refresh token or not
@@ -376,6 +383,12 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
376
383
  * @returns Time zone
377
384
  */
378
385
  getTimeZone(): string | undefined;
386
+ /**
387
+ * Check use has the specific role permission or not
388
+ * @param roles Roles to check
389
+ * @returns Result
390
+ */
391
+ hasPermission(roles: number | UserRole | number[] | UserRole[]): boolean;
379
392
  /**
380
393
  * Callback where exit a page
381
394
  */
@@ -415,7 +428,7 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
415
428
  * @param refreshToken Refresh token
416
429
  * @param keep Keep in local storage or not
417
430
  */
418
- userLogin(user: IUserData, refreshToken?: string, keep?: boolean): void;
431
+ userLogin(user: IUserData, refreshToken: string, keep?: boolean): void;
419
432
  /**
420
433
  * User logout
421
434
  * @param clearToken Clear refresh token or not
@@ -335,6 +335,24 @@ export class CoreApp {
335
335
  // settings.timeZone = Utils.getTimeZone()
336
336
  return (_a = this.settings.timeZone) !== null && _a !== void 0 ? _a : (_b = this.ipData) === null || _b === void 0 ? void 0 : _b.timezone;
337
337
  }
338
+ /**
339
+ * Check use has the specific role permission or not
340
+ * @param roles Roles to check
341
+ * @returns Result
342
+ */
343
+ hasPermission(roles) {
344
+ var _a;
345
+ const userRole = (_a = this.userData) === null || _a === void 0 ? void 0 : _a.role;
346
+ if (userRole == null)
347
+ return false;
348
+ if (Array.isArray(roles)) {
349
+ return roles.some((role) => (userRole & role) === role);
350
+ }
351
+ // One role check
352
+ if ((userRole & roles) === roles)
353
+ return true;
354
+ return false;
355
+ }
338
356
  /**
339
357
  * Callback where exit a page
340
358
  */
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Standard user roles
3
+ * @see com.etsoo.CoreFramework.Authentication.UserRole
4
+ */
5
+ export declare enum UserRole {
6
+ /**
7
+ * Guest
8
+ */
9
+ Guest = 1,
10
+ /**
11
+ * Outsourcing
12
+ */
13
+ Outsourcing = 2,
14
+ /**
15
+ * Operator
16
+ */
17
+ Operator = 4,
18
+ /**
19
+ * User
20
+ */
21
+ User = 8,
22
+ /**
23
+ * Manager
24
+ */
25
+ Manager = 128,
26
+ /**
27
+ * Finance
28
+ */
29
+ Finance = 256,
30
+ /**
31
+ * HR Manager
32
+ */
33
+ HRManager = 512,
34
+ /**
35
+ * Administrator
36
+ */
37
+ Admin = 8192,
38
+ /**
39
+ * Founder, takes all ownership
40
+ */
41
+ Founder = 16384
42
+ }
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Standard user roles
3
+ * @see com.etsoo.CoreFramework.Authentication.UserRole
4
+ */
5
+ export var UserRole;
6
+ (function (UserRole) {
7
+ /**
8
+ * Guest
9
+ */
10
+ UserRole[UserRole["Guest"] = 1] = "Guest";
11
+ /**
12
+ * Outsourcing
13
+ */
14
+ UserRole[UserRole["Outsourcing"] = 2] = "Outsourcing";
15
+ /**
16
+ * Operator
17
+ */
18
+ UserRole[UserRole["Operator"] = 4] = "Operator";
19
+ /**
20
+ * User
21
+ */
22
+ UserRole[UserRole["User"] = 8] = "User";
23
+ /**
24
+ * Manager
25
+ */
26
+ UserRole[UserRole["Manager"] = 128] = "Manager";
27
+ /**
28
+ * Finance
29
+ */
30
+ UserRole[UserRole["Finance"] = 256] = "Finance";
31
+ /**
32
+ * HR Manager
33
+ */
34
+ UserRole[UserRole["HRManager"] = 512] = "HRManager";
35
+ /**
36
+ * Administrator
37
+ */
38
+ UserRole[UserRole["Admin"] = 8192] = "Admin";
39
+ /**
40
+ * Founder, takes all ownership
41
+ */
42
+ UserRole[UserRole["Founder"] = 16384] = "Founder";
43
+ })(UserRole || (UserRole = {}));
@@ -31,6 +31,7 @@
31
31
  "name": "Name",
32
32
  "no": "No",
33
33
  "noChanges": "No changes yet",
34
+ "noData": "No valid data",
34
35
  "noOptions": "No options",
35
36
  "ok": "OK",
36
37
  "open": "Open",
@@ -31,6 +31,7 @@
31
31
  "name": "姓名",
32
32
  "no": "否",
33
33
  "noChanges": "还没有任何修改",
34
+ "noData": "没有有效数据",
34
35
  "noOptions": "没有选项",
35
36
  "ok": "确定",
36
37
  "open": "打开",
@@ -31,6 +31,7 @@
31
31
  "name": "姓名",
32
32
  "no": "否",
33
33
  "noChanges": "還沒有任何修改",
34
+ "noData": "沒有有效數據",
34
35
  "noOptions": "沒有選項",
35
36
  "ok": "確定",
36
37
  "open": "打開",
@@ -4,6 +4,7 @@ export * from './address/AddressUtils';
4
4
  export * from './app/AppSettings';
5
5
  export * from './app/CoreApp';
6
6
  export * from './app/ExternalSettings';
7
+ export * from './app/UserRole';
7
8
  export * from './bridges/ElectronBridge';
8
9
  export * from './bridges/IAppData';
9
10
  export * from './bridges/IBridge';
package/lib/mjs/index.js CHANGED
@@ -6,6 +6,7 @@ export * from './address/AddressUtils';
6
6
  export * from './app/AppSettings';
7
7
  export * from './app/CoreApp';
8
8
  export * from './app/ExternalSettings';
9
+ export * from './app/UserRole';
9
10
  // bridges
10
11
  export * from './bridges/ElectronBridge';
11
12
  export * from './bridges/IAppData';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/appscript",
3
- "version": "1.1.47",
3
+ "version": "1.1.51",
4
4
  "description": "Applications shared TypeScript framework",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/mjs/index.js",
@@ -52,9 +52,9 @@
52
52
  },
53
53
  "homepage": "https://github.com/ETSOO/AppScript#readme",
54
54
  "dependencies": {
55
- "@etsoo/notificationbase": "^1.0.93",
55
+ "@etsoo/notificationbase": "^1.0.94",
56
56
  "@etsoo/restclient": "^1.0.62",
57
- "@etsoo/shared": "^1.0.74"
57
+ "@etsoo/shared": "^1.0.75"
58
58
  },
59
59
  "devDependencies": {
60
60
  "@babel/cli": "^7.16.0",
@@ -62,13 +62,13 @@
62
62
  "@babel/plugin-transform-runtime": "^7.16.4",
63
63
  "@babel/preset-env": "^7.16.4",
64
64
  "@babel/runtime-corejs3": "^7.16.3",
65
- "@types/jest": "^27.0.2",
66
- "@typescript-eslint/eslint-plugin": "^5.4.0",
67
- "@typescript-eslint/parser": "^5.4.0",
68
- "eslint": "^8.2.0",
65
+ "@types/jest": "^27.0.3",
66
+ "@typescript-eslint/eslint-plugin": "^5.5.0",
67
+ "@typescript-eslint/parser": "^5.5.0",
68
+ "eslint": "^8.3.0",
69
69
  "eslint-config-airbnb-base": "^15.0.0",
70
70
  "eslint-plugin-import": "^2.25.3",
71
- "jest": "^27.3.1",
71
+ "jest": "^27.4.3",
72
72
  "ts-jest": "^27.0.7",
73
73
  "typescript": "^4.5.2"
74
74
  }
@@ -20,6 +20,7 @@ import { ActionResultError } from '../result/ActionResultError';
20
20
  import { IActionResult } from '../result/IActionResult';
21
21
  import { IUserData } from '../state/User';
22
22
  import { IAppSettings } from './AppSettings';
23
+ import { UserRole } from './UserRole';
23
24
 
24
25
  /**
25
26
  * Detect IP callback interface
@@ -216,6 +217,13 @@ export interface ICoreApp<
216
217
  */
217
218
  getTimeZone(): string | undefined;
218
219
 
220
+ /**
221
+ * Check use has the specific role permission or not
222
+ * @param roles Roles to check
223
+ * @returns Result
224
+ */
225
+ hasPermission(roles: number | UserRole | number[] | UserRole[]): boolean;
226
+
219
227
  /**
220
228
  * Callback where exit a page
221
229
  */
@@ -244,7 +252,7 @@ export interface ICoreApp<
244
252
  * @param refreshToken Refresh token
245
253
  * @param keep Keep in local storage or not
246
254
  */
247
- userLogin(user: IUserData, refreshToken?: string, keep?: boolean): void;
255
+ userLogin(user: IUserData, refreshToken: string, keep?: boolean): void;
248
256
 
249
257
  /**
250
258
  * User logout
@@ -727,6 +735,25 @@ export abstract class CoreApp<
727
735
  return this.settings.timeZone ?? this.ipData?.timezone;
728
736
  }
729
737
 
738
+ /**
739
+ * Check use has the specific role permission or not
740
+ * @param roles Roles to check
741
+ * @returns Result
742
+ */
743
+ hasPermission(roles: number | UserRole | number[] | UserRole[]): boolean {
744
+ const userRole = this.userData?.role;
745
+ if (userRole == null) return false;
746
+
747
+ if (Array.isArray(roles)) {
748
+ return roles.some((role) => (userRole & role) === role);
749
+ }
750
+
751
+ // One role check
752
+ if ((userRole & roles) === roles) return true;
753
+
754
+ return false;
755
+ }
756
+
730
757
  /**
731
758
  * Callback where exit a page
732
759
  */
@@ -829,7 +856,7 @@ export abstract class CoreApp<
829
856
  * @param refreshToken Refresh token
830
857
  * @param keep Keep in local storage or not
831
858
  */
832
- userLogin(user: IUserData, refreshToken?: string, keep: boolean = false) {
859
+ userLogin(user: IUserData, refreshToken: string, keep: boolean = false) {
833
860
  this.userData = user;
834
861
  this.authorize(user.token, refreshToken, keep);
835
862
  }
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Standard user roles
3
+ * @see com.etsoo.CoreFramework.Authentication.UserRole
4
+ */
5
+ export enum UserRole {
6
+ /**
7
+ * Guest
8
+ */
9
+ Guest = 1,
10
+
11
+ /**
12
+ * Outsourcing
13
+ */
14
+ Outsourcing = 2,
15
+
16
+ /**
17
+ * Operator
18
+ */
19
+ Operator = 4,
20
+
21
+ /**
22
+ * User
23
+ */
24
+ User = 8,
25
+
26
+ /**
27
+ * Manager
28
+ */
29
+ Manager = 128,
30
+
31
+ /**
32
+ * Finance
33
+ */
34
+ Finance = 256,
35
+
36
+ /**
37
+ * HR Manager
38
+ */
39
+ HRManager = 512,
40
+
41
+ /**
42
+ * Administrator
43
+ */
44
+ Admin = 8192,
45
+
46
+ /**
47
+ * Founder, takes all ownership
48
+ */
49
+ Founder = 16384
50
+ }
@@ -31,6 +31,7 @@
31
31
  "name": "Name",
32
32
  "no": "No",
33
33
  "noChanges": "No changes yet",
34
+ "noData": "No valid data",
34
35
  "noOptions": "No options",
35
36
  "ok": "OK",
36
37
  "open": "Open",
@@ -31,6 +31,7 @@
31
31
  "name": "姓名",
32
32
  "no": "否",
33
33
  "noChanges": "还没有任何修改",
34
+ "noData": "没有有效数据",
34
35
  "noOptions": "没有选项",
35
36
  "ok": "确定",
36
37
  "open": "打开",
@@ -31,6 +31,7 @@
31
31
  "name": "姓名",
32
32
  "no": "否",
33
33
  "noChanges": "還沒有任何修改",
34
+ "noData": "沒有有效數據",
34
35
  "noOptions": "沒有選項",
35
36
  "ok": "確定",
36
37
  "open": "打開",
package/src/index.ts CHANGED
@@ -7,6 +7,7 @@ export * from './address/AddressUtils';
7
7
  export * from './app/AppSettings';
8
8
  export * from './app/CoreApp';
9
9
  export * from './app/ExternalSettings';
10
+ export * from './app/UserRole';
10
11
 
11
12
  // bridges
12
13
  export * from './bridges/ElectronBridge';