@etsoo/appscript 1.1.49 → 1.1.53
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/app/CoreApp.d.ts +41 -0
- package/lib/cjs/app/CoreApp.js +54 -0
- package/lib/cjs/app/UserRole.d.ts +42 -0
- package/lib/cjs/app/UserRole.js +46 -0
- package/lib/cjs/index.d.ts +1 -0
- package/lib/cjs/index.js +1 -0
- package/lib/mjs/app/CoreApp.d.ts +41 -0
- package/lib/mjs/app/CoreApp.js +54 -0
- package/lib/mjs/app/UserRole.d.ts +42 -0
- package/lib/mjs/app/UserRole.js +43 -0
- package/lib/mjs/index.d.ts +1 -0
- package/lib/mjs/index.js +1 -0
- package/package.json +5 -5
- package/src/app/CoreApp.ts +85 -0
- package/src/app/UserRole.ts +50 -0
- package/src/index.ts +1 -0
package/lib/cjs/app/CoreApp.d.ts
CHANGED
|
@@ -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,20 @@ 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
|
+
* Switch organization
|
|
183
|
+
* @param apiOrOrg API URL or organization id
|
|
184
|
+
*/
|
|
185
|
+
switchOrg(apiOrOrg: string | number): Promise<boolean | undefined>;
|
|
186
|
+
/**
|
|
187
|
+
* Go to the login page
|
|
188
|
+
*/
|
|
189
|
+
toLoginPage(): void;
|
|
169
190
|
/**
|
|
170
191
|
* Transform URL
|
|
171
192
|
* @param url URL
|
|
@@ -376,6 +397,12 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
|
|
|
376
397
|
* @returns Time zone
|
|
377
398
|
*/
|
|
378
399
|
getTimeZone(): string | undefined;
|
|
400
|
+
/**
|
|
401
|
+
* Check use has the specific role permission or not
|
|
402
|
+
* @param roles Roles to check
|
|
403
|
+
* @returns Result
|
|
404
|
+
*/
|
|
405
|
+
hasPermission(roles: number | UserRole | number[] | UserRole[]): boolean;
|
|
379
406
|
/**
|
|
380
407
|
* Callback where exit a page
|
|
381
408
|
*/
|
|
@@ -399,6 +426,20 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
|
|
|
399
426
|
* Setup callback
|
|
400
427
|
*/
|
|
401
428
|
setup(): void;
|
|
429
|
+
/**
|
|
430
|
+
* Signout
|
|
431
|
+
* @param apiUrl Signout API URL
|
|
432
|
+
*/
|
|
433
|
+
signout(apiUrl?: string): Promise<void>;
|
|
434
|
+
/**
|
|
435
|
+
* Switch organization
|
|
436
|
+
* @param apiOrOrg API URL or organization id
|
|
437
|
+
*/
|
|
438
|
+
switchOrg(apiOrOrg: string | number): Promise<boolean | undefined>;
|
|
439
|
+
/**
|
|
440
|
+
* Go to the login page
|
|
441
|
+
*/
|
|
442
|
+
toLoginPage(): void;
|
|
402
443
|
/**
|
|
403
444
|
* Transform URL
|
|
404
445
|
* @param url URL
|
package/lib/cjs/app/CoreApp.js
CHANGED
|
@@ -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,42 @@ 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
|
+
* Switch organization
|
|
429
|
+
* @param apiOrOrg API URL or organization id
|
|
430
|
+
*/
|
|
431
|
+
async switchOrg(apiOrOrg) {
|
|
432
|
+
const api = typeof apiOrOrg === 'number'
|
|
433
|
+
? `Organization/Switch/${apiOrOrg}`
|
|
434
|
+
: apiOrOrg;
|
|
435
|
+
const result = await this.api.put(api);
|
|
436
|
+
if (result)
|
|
437
|
+
return await this.refreshToken();
|
|
438
|
+
return result;
|
|
439
|
+
}
|
|
440
|
+
/**
|
|
441
|
+
* Go to the login page
|
|
442
|
+
*/
|
|
443
|
+
toLoginPage() {
|
|
444
|
+
window.location.replace(this.transformUrl('/'));
|
|
445
|
+
}
|
|
392
446
|
/**
|
|
393
447
|
* Transform URL
|
|
394
448
|
* @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 = {}));
|
package/lib/cjs/index.d.ts
CHANGED
|
@@ -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);
|
package/lib/mjs/app/CoreApp.d.ts
CHANGED
|
@@ -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,20 @@ 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
|
+
* Switch organization
|
|
183
|
+
* @param apiOrOrg API URL or organization id
|
|
184
|
+
*/
|
|
185
|
+
switchOrg(apiOrOrg: string | number): Promise<boolean | undefined>;
|
|
186
|
+
/**
|
|
187
|
+
* Go to the login page
|
|
188
|
+
*/
|
|
189
|
+
toLoginPage(): void;
|
|
169
190
|
/**
|
|
170
191
|
* Transform URL
|
|
171
192
|
* @param url URL
|
|
@@ -376,6 +397,12 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
|
|
|
376
397
|
* @returns Time zone
|
|
377
398
|
*/
|
|
378
399
|
getTimeZone(): string | undefined;
|
|
400
|
+
/**
|
|
401
|
+
* Check use has the specific role permission or not
|
|
402
|
+
* @param roles Roles to check
|
|
403
|
+
* @returns Result
|
|
404
|
+
*/
|
|
405
|
+
hasPermission(roles: number | UserRole | number[] | UserRole[]): boolean;
|
|
379
406
|
/**
|
|
380
407
|
* Callback where exit a page
|
|
381
408
|
*/
|
|
@@ -399,6 +426,20 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
|
|
|
399
426
|
* Setup callback
|
|
400
427
|
*/
|
|
401
428
|
setup(): void;
|
|
429
|
+
/**
|
|
430
|
+
* Signout
|
|
431
|
+
* @param apiUrl Signout API URL
|
|
432
|
+
*/
|
|
433
|
+
signout(apiUrl?: string): Promise<void>;
|
|
434
|
+
/**
|
|
435
|
+
* Switch organization
|
|
436
|
+
* @param apiOrOrg API URL or organization id
|
|
437
|
+
*/
|
|
438
|
+
switchOrg(apiOrOrg: string | number): Promise<boolean | undefined>;
|
|
439
|
+
/**
|
|
440
|
+
* Go to the login page
|
|
441
|
+
*/
|
|
442
|
+
toLoginPage(): void;
|
|
402
443
|
/**
|
|
403
444
|
* Transform URL
|
|
404
445
|
* @param url URL
|
package/lib/mjs/app/CoreApp.js
CHANGED
|
@@ -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,42 @@ 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
|
+
* Switch organization
|
|
426
|
+
* @param apiOrOrg API URL or organization id
|
|
427
|
+
*/
|
|
428
|
+
async switchOrg(apiOrOrg) {
|
|
429
|
+
const api = typeof apiOrOrg === 'number'
|
|
430
|
+
? `Organization/Switch/${apiOrOrg}`
|
|
431
|
+
: apiOrOrg;
|
|
432
|
+
const result = await this.api.put(api);
|
|
433
|
+
if (result)
|
|
434
|
+
return await this.refreshToken();
|
|
435
|
+
return result;
|
|
436
|
+
}
|
|
437
|
+
/**
|
|
438
|
+
* Go to the login page
|
|
439
|
+
*/
|
|
440
|
+
toLoginPage() {
|
|
441
|
+
window.location.replace(this.transformUrl('/'));
|
|
442
|
+
}
|
|
389
443
|
/**
|
|
390
444
|
* Transform URL
|
|
391
445
|
* @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 = {}));
|
package/lib/mjs/index.d.ts
CHANGED
|
@@ -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.
|
|
3
|
+
"version": "1.1.53",
|
|
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.
|
|
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.
|
|
67
|
-
"@typescript-eslint/parser": "^5.
|
|
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
|
|
71
|
+
"jest": "^27.4.3",
|
|
72
72
|
"ts-jest": "^27.0.7",
|
|
73
73
|
"typescript": "^4.5.2"
|
|
74
74
|
}
|
package/src/app/CoreApp.ts
CHANGED
|
@@ -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,23 @@ 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
|
+
* Switch organization
|
|
245
|
+
* @param apiOrOrg API URL or organization id
|
|
246
|
+
*/
|
|
247
|
+
switchOrg(apiOrOrg: string | number): Promise<boolean | undefined>;
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* Go to the login page
|
|
251
|
+
*/
|
|
252
|
+
toLoginPage(): void;
|
|
253
|
+
|
|
229
254
|
/**
|
|
230
255
|
* Transform URL
|
|
231
256
|
* @param url URL
|
|
@@ -727,6 +752,25 @@ export abstract class CoreApp<
|
|
|
727
752
|
return this.settings.timeZone ?? this.ipData?.timezone;
|
|
728
753
|
}
|
|
729
754
|
|
|
755
|
+
/**
|
|
756
|
+
* Check use has the specific role permission or not
|
|
757
|
+
* @param roles Roles to check
|
|
758
|
+
* @returns Result
|
|
759
|
+
*/
|
|
760
|
+
hasPermission(roles: number | UserRole | number[] | UserRole[]): boolean {
|
|
761
|
+
const userRole = this.userData?.role;
|
|
762
|
+
if (userRole == null) return false;
|
|
763
|
+
|
|
764
|
+
if (Array.isArray(roles)) {
|
|
765
|
+
return roles.some((role) => (userRole & role) === role);
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
// One role check
|
|
769
|
+
if ((userRole & roles) === roles) return true;
|
|
770
|
+
|
|
771
|
+
return false;
|
|
772
|
+
}
|
|
773
|
+
|
|
730
774
|
/**
|
|
731
775
|
* Callback where exit a page
|
|
732
776
|
*/
|
|
@@ -789,6 +833,47 @@ export abstract class CoreApp<
|
|
|
789
833
|
*/
|
|
790
834
|
setup() {}
|
|
791
835
|
|
|
836
|
+
/**
|
|
837
|
+
* Signout
|
|
838
|
+
* @param apiUrl Signout API URL
|
|
839
|
+
*/
|
|
840
|
+
async signout(apiUrl?: string) {
|
|
841
|
+
await this.api.put<boolean>(apiUrl ?? 'User/Signout', undefined, {
|
|
842
|
+
onError: (error) => {
|
|
843
|
+
console.log(error);
|
|
844
|
+
// Prevent further processing
|
|
845
|
+
return false;
|
|
846
|
+
}
|
|
847
|
+
});
|
|
848
|
+
|
|
849
|
+
// Clear
|
|
850
|
+
this.userLogout();
|
|
851
|
+
|
|
852
|
+
// Go to login page
|
|
853
|
+
this.toLoginPage();
|
|
854
|
+
}
|
|
855
|
+
|
|
856
|
+
/**
|
|
857
|
+
* Switch organization
|
|
858
|
+
* @param apiOrOrg API URL or organization id
|
|
859
|
+
*/
|
|
860
|
+
async switchOrg(apiOrOrg: string | number) {
|
|
861
|
+
const api =
|
|
862
|
+
typeof apiOrOrg === 'number'
|
|
863
|
+
? `Organization/Switch/${apiOrOrg}`
|
|
864
|
+
: apiOrOrg;
|
|
865
|
+
const result = await this.api.put<boolean>(api);
|
|
866
|
+
if (result) return await this.refreshToken();
|
|
867
|
+
return result;
|
|
868
|
+
}
|
|
869
|
+
|
|
870
|
+
/**
|
|
871
|
+
* Go to the login page
|
|
872
|
+
*/
|
|
873
|
+
toLoginPage() {
|
|
874
|
+
window.location.replace(this.transformUrl('/'));
|
|
875
|
+
}
|
|
876
|
+
|
|
792
877
|
/**
|
|
793
878
|
* Transform URL
|
|
794
879
|
* @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
|
+
}
|
package/src/index.ts
CHANGED