@etsoo/appscript 1.1.48 → 1.1.52

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
  */
@@ -166,6 +173,15 @@ export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallP
166
173
  * Refresh token
167
174
  */
168
175
  refreshToken(): Promise<boolean>;
176
+ /**
177
+ * Signout
178
+ * @param apiUrl Signout API URL
179
+ */
180
+ signout(apiUrl?: string): Promise<void>;
181
+ /**
182
+ * Go to the login page
183
+ */
184
+ toLoginPage(): void;
169
185
  /**
170
186
  * Transform URL
171
187
  * @param url URL
@@ -376,6 +392,12 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
376
392
  * @returns Time zone
377
393
  */
378
394
  getTimeZone(): string | undefined;
395
+ /**
396
+ * Check use has the specific role permission or not
397
+ * @param roles Roles to check
398
+ * @returns Result
399
+ */
400
+ hasPermission(roles: number | UserRole | number[] | UserRole[]): boolean;
379
401
  /**
380
402
  * Callback where exit a page
381
403
  */
@@ -399,6 +421,15 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
399
421
  * Setup callback
400
422
  */
401
423
  setup(): void;
424
+ /**
425
+ * Signout
426
+ * @param apiUrl Signout API URL
427
+ */
428
+ signout(apiUrl?: string): Promise<void>;
429
+ /**
430
+ * Go to the login page
431
+ */
432
+ toLoginPage(): void;
402
433
  /**
403
434
  * Transform URL
404
435
  * @param url URL
@@ -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
  */
@@ -389,6 +407,29 @@ class CoreApp {
389
407
  * Setup callback
390
408
  */
391
409
  setup() { }
410
+ /**
411
+ * Signout
412
+ * @param apiUrl Signout API URL
413
+ */
414
+ async signout(apiUrl) {
415
+ await this.api.put(apiUrl !== null && apiUrl !== void 0 ? apiUrl : 'User/Signout', undefined, {
416
+ onError: (error) => {
417
+ console.log(error);
418
+ // Prevent further processing
419
+ return false;
420
+ }
421
+ });
422
+ // Clear
423
+ this.userLogout();
424
+ // Go to login page
425
+ this.toLoginPage();
426
+ }
427
+ /**
428
+ * Go to the login page
429
+ */
430
+ toLoginPage() {
431
+ window.location.replace(this.transformUrl('/'));
432
+ }
392
433
  /**
393
434
  * Transform URL
394
435
  * @param url URL
@@ -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
  */
@@ -166,6 +173,15 @@ export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallP
166
173
  * Refresh token
167
174
  */
168
175
  refreshToken(): Promise<boolean>;
176
+ /**
177
+ * Signout
178
+ * @param apiUrl Signout API URL
179
+ */
180
+ signout(apiUrl?: string): Promise<void>;
181
+ /**
182
+ * Go to the login page
183
+ */
184
+ toLoginPage(): void;
169
185
  /**
170
186
  * Transform URL
171
187
  * @param url URL
@@ -376,6 +392,12 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
376
392
  * @returns Time zone
377
393
  */
378
394
  getTimeZone(): string | undefined;
395
+ /**
396
+ * Check use has the specific role permission or not
397
+ * @param roles Roles to check
398
+ * @returns Result
399
+ */
400
+ hasPermission(roles: number | UserRole | number[] | UserRole[]): boolean;
379
401
  /**
380
402
  * Callback where exit a page
381
403
  */
@@ -399,6 +421,15 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
399
421
  * Setup callback
400
422
  */
401
423
  setup(): void;
424
+ /**
425
+ * Signout
426
+ * @param apiUrl Signout API URL
427
+ */
428
+ signout(apiUrl?: string): Promise<void>;
429
+ /**
430
+ * Go to the login page
431
+ */
432
+ toLoginPage(): void;
402
433
  /**
403
434
  * Transform URL
404
435
  * @param url URL
@@ -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
  */
@@ -386,6 +404,29 @@ export class CoreApp {
386
404
  * Setup callback
387
405
  */
388
406
  setup() { }
407
+ /**
408
+ * Signout
409
+ * @param apiUrl Signout API URL
410
+ */
411
+ async signout(apiUrl) {
412
+ await this.api.put(apiUrl !== null && apiUrl !== void 0 ? apiUrl : 'User/Signout', undefined, {
413
+ onError: (error) => {
414
+ console.log(error);
415
+ // Prevent further processing
416
+ return false;
417
+ }
418
+ });
419
+ // Clear
420
+ this.userLogout();
421
+ // Go to login page
422
+ this.toLoginPage();
423
+ }
424
+ /**
425
+ * Go to the login page
426
+ */
427
+ toLoginPage() {
428
+ window.location.replace(this.transformUrl('/'));
429
+ }
389
430
  /**
390
431
  * Transform URL
391
432
  * @param url URL
@@ -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.48",
3
+ "version": "1.1.52",
4
4
  "description": "Applications shared TypeScript framework",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/mjs/index.js",
@@ -52,7 +52,7 @@
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
57
  "@etsoo/shared": "^1.0.75"
58
58
  },
@@ -63,12 +63,12 @@
63
63
  "@babel/preset-env": "^7.16.4",
64
64
  "@babel/runtime-corejs3": "^7.16.3",
65
65
  "@types/jest": "^27.0.3",
66
- "@typescript-eslint/eslint-plugin": "^5.4.0",
67
- "@typescript-eslint/parser": "^5.4.0",
66
+ "@typescript-eslint/eslint-plugin": "^5.5.0",
67
+ "@typescript-eslint/parser": "^5.5.0",
68
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
  */
@@ -226,6 +234,17 @@ export interface ICoreApp<
226
234
  */
227
235
  refreshToken(): Promise<boolean>;
228
236
 
237
+ /**
238
+ * Signout
239
+ * @param apiUrl Signout API URL
240
+ */
241
+ signout(apiUrl?: string): Promise<void>;
242
+
243
+ /**
244
+ * Go to the login page
245
+ */
246
+ toLoginPage(): void;
247
+
229
248
  /**
230
249
  * Transform URL
231
250
  * @param url URL
@@ -727,6 +746,25 @@ export abstract class CoreApp<
727
746
  return this.settings.timeZone ?? this.ipData?.timezone;
728
747
  }
729
748
 
749
+ /**
750
+ * Check use has the specific role permission or not
751
+ * @param roles Roles to check
752
+ * @returns Result
753
+ */
754
+ hasPermission(roles: number | UserRole | number[] | UserRole[]): boolean {
755
+ const userRole = this.userData?.role;
756
+ if (userRole == null) return false;
757
+
758
+ if (Array.isArray(roles)) {
759
+ return roles.some((role) => (userRole & role) === role);
760
+ }
761
+
762
+ // One role check
763
+ if ((userRole & roles) === roles) return true;
764
+
765
+ return false;
766
+ }
767
+
730
768
  /**
731
769
  * Callback where exit a page
732
770
  */
@@ -789,6 +827,33 @@ export abstract class CoreApp<
789
827
  */
790
828
  setup() {}
791
829
 
830
+ /**
831
+ * Signout
832
+ * @param apiUrl Signout API URL
833
+ */
834
+ async signout(apiUrl?: string) {
835
+ await this.api.put<boolean>(apiUrl ?? 'User/Signout', undefined, {
836
+ onError: (error) => {
837
+ console.log(error);
838
+ // Prevent further processing
839
+ return false;
840
+ }
841
+ });
842
+
843
+ // Clear
844
+ this.userLogout();
845
+
846
+ // Go to login page
847
+ this.toLoginPage();
848
+ }
849
+
850
+ /**
851
+ * Go to the login page
852
+ */
853
+ toLoginPage() {
854
+ window.location.replace(this.transformUrl('/'));
855
+ }
856
+
792
857
  /**
793
858
  * Transform URL
794
859
  * @param url URL
@@ -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';