@etsoo/appscript 1.5.45 → 1.5.47
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 +3 -5
- package/lib/cjs/app/CoreApp.js +76 -21
- package/lib/cjs/app/IApp.d.ts +9 -5
- package/lib/cjs/erp/AuthApi.d.ts +8 -2
- package/lib/cjs/erp/AuthApi.js +19 -12
- package/lib/cjs/erp/OrgApi.d.ts +0 -7
- package/lib/cjs/erp/OrgApi.js +0 -16
- package/lib/cjs/erp/rq/SwitchOrgRQ.d.ts +13 -0
- package/lib/cjs/erp/rq/SwitchOrgRQ.js +2 -0
- package/lib/cjs/index.d.ts +1 -0
- package/lib/cjs/index.js +1 -0
- package/lib/mjs/app/CoreApp.d.ts +3 -5
- package/lib/mjs/app/CoreApp.js +76 -21
- package/lib/mjs/app/IApp.d.ts +9 -5
- package/lib/mjs/erp/AuthApi.d.ts +8 -2
- package/lib/mjs/erp/AuthApi.js +19 -12
- package/lib/mjs/erp/OrgApi.d.ts +0 -7
- package/lib/mjs/erp/OrgApi.js +0 -16
- package/lib/mjs/erp/rq/SwitchOrgRQ.d.ts +13 -0
- package/lib/mjs/erp/rq/SwitchOrgRQ.js +1 -0
- package/lib/mjs/index.d.ts +1 -0
- package/lib/mjs/index.js +1 -0
- package/package.json +1 -1
- package/src/app/CoreApp.ts +86 -22
- package/src/app/IApp.ts +10 -5
- package/src/erp/AuthApi.ts +22 -13
- package/src/erp/OrgApi.ts +0 -24
- package/src/erp/rq/SwitchOrgRQ.ts +14 -0
- package/src/index.ts +1 -0
package/lib/cjs/app/CoreApp.d.ts
CHANGED
|
@@ -152,7 +152,6 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
|
|
|
152
152
|
* Passphrase for encryption
|
|
153
153
|
*/
|
|
154
154
|
protected passphrase: string;
|
|
155
|
-
private cachedRefreshToken?;
|
|
156
155
|
private apis;
|
|
157
156
|
private tasks;
|
|
158
157
|
/**
|
|
@@ -573,7 +572,7 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
|
|
|
573
572
|
*/
|
|
574
573
|
abstract freshCountdownUI(callback?: () => PromiseLike<unknown>): void;
|
|
575
574
|
/**
|
|
576
|
-
* Refresh token
|
|
575
|
+
* Refresh token with result
|
|
577
576
|
* @param props Props
|
|
578
577
|
* @param callback Callback
|
|
579
578
|
*/
|
|
@@ -619,7 +618,7 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
|
|
|
619
618
|
signout(): Promise<void>;
|
|
620
619
|
/**
|
|
621
620
|
* Go to the login page
|
|
622
|
-
* params Login parameters
|
|
621
|
+
* @params Login parameters
|
|
623
622
|
*/
|
|
624
623
|
toLoginPage(params?: AppLoginParams): void;
|
|
625
624
|
/**
|
|
@@ -638,9 +637,8 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
|
|
|
638
637
|
* User login
|
|
639
638
|
* @param user User data
|
|
640
639
|
* @param refreshToken Refresh token
|
|
641
|
-
* @param keep Keep login or not
|
|
642
640
|
*/
|
|
643
|
-
userLogin(user: U, refreshToken: string
|
|
641
|
+
userLogin(user: U, refreshToken: string): void;
|
|
644
642
|
/**
|
|
645
643
|
* User logout
|
|
646
644
|
* @param clearToken Clear refresh token or not
|
package/lib/cjs/app/CoreApp.js
CHANGED
|
@@ -162,13 +162,14 @@ class CoreApp {
|
|
|
162
162
|
throw new Error('No default region defined');
|
|
163
163
|
}
|
|
164
164
|
this.defaultRegion = region;
|
|
165
|
+
// Current system refresh token
|
|
165
166
|
const refresh = async (api, token) => {
|
|
166
167
|
if (this.lastCalled) {
|
|
167
168
|
// Call refreshToken to update access token
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
169
|
+
await this.refreshToken({ token, showLoading: false }, (result) => {
|
|
170
|
+
if (result === true)
|
|
171
|
+
return;
|
|
172
|
+
console.log(`CoreApp.${this.name}.RefreshToken`, result);
|
|
172
173
|
});
|
|
173
174
|
}
|
|
174
175
|
else {
|
|
@@ -666,7 +667,6 @@ class CoreApp {
|
|
|
666
667
|
}
|
|
667
668
|
}
|
|
668
669
|
else {
|
|
669
|
-
this.cachedRefreshToken = undefined;
|
|
670
670
|
this.updateApi(this.api.name, undefined, -1);
|
|
671
671
|
}
|
|
672
672
|
// Host notice
|
|
@@ -773,7 +773,6 @@ class CoreApp {
|
|
|
773
773
|
* Clear cached token
|
|
774
774
|
*/
|
|
775
775
|
clearCacheToken() {
|
|
776
|
-
this.cachedRefreshToken = undefined;
|
|
777
776
|
this.storage.setPersistedData(this.fields.headerToken, undefined);
|
|
778
777
|
}
|
|
779
778
|
/**
|
|
@@ -1108,9 +1107,6 @@ class CoreApp {
|
|
|
1108
1107
|
* @returns Cached token
|
|
1109
1108
|
*/
|
|
1110
1109
|
getCacheToken() {
|
|
1111
|
-
// Temp refresh token
|
|
1112
|
-
if (this.cachedRefreshToken)
|
|
1113
|
-
return this.cachedRefreshToken;
|
|
1114
1110
|
return this.storage.getData(this.fields.headerToken);
|
|
1115
1111
|
}
|
|
1116
1112
|
/**
|
|
@@ -1356,11 +1352,75 @@ class CoreApp {
|
|
|
1356
1352
|
this.notifier.hideLoading(true);
|
|
1357
1353
|
}
|
|
1358
1354
|
/**
|
|
1359
|
-
* Refresh token
|
|
1355
|
+
* Refresh token with result
|
|
1360
1356
|
* @param props Props
|
|
1361
1357
|
* @param callback Callback
|
|
1362
1358
|
*/
|
|
1363
|
-
async refreshToken(props, callback) {
|
|
1359
|
+
async refreshToken(props, callback) {
|
|
1360
|
+
// Check props
|
|
1361
|
+
props ?? (props = {});
|
|
1362
|
+
props.token ?? (props.token = this.getCacheToken());
|
|
1363
|
+
// Call refresh token API
|
|
1364
|
+
let data = await new AuthApi_1.AuthApi(this).refreshToken(props);
|
|
1365
|
+
let r;
|
|
1366
|
+
if (Array.isArray(data)) {
|
|
1367
|
+
const [token, result] = data;
|
|
1368
|
+
if (result.ok) {
|
|
1369
|
+
if (!token) {
|
|
1370
|
+
data = {
|
|
1371
|
+
ok: false,
|
|
1372
|
+
type: 'noData',
|
|
1373
|
+
field: 'token',
|
|
1374
|
+
title: this.get('noData')
|
|
1375
|
+
};
|
|
1376
|
+
}
|
|
1377
|
+
else if (result.data == null) {
|
|
1378
|
+
data = {
|
|
1379
|
+
ok: false,
|
|
1380
|
+
type: 'noData',
|
|
1381
|
+
field: 'user',
|
|
1382
|
+
title: this.get('noData')
|
|
1383
|
+
};
|
|
1384
|
+
}
|
|
1385
|
+
else {
|
|
1386
|
+
// User login
|
|
1387
|
+
this.userLogin(result.data, token);
|
|
1388
|
+
if (callback)
|
|
1389
|
+
callback(true);
|
|
1390
|
+
// Exit
|
|
1391
|
+
return;
|
|
1392
|
+
}
|
|
1393
|
+
}
|
|
1394
|
+
else if (this.checkDeviceResult(result)) {
|
|
1395
|
+
if (callback == null || callback(result) !== true) {
|
|
1396
|
+
this.initCall((ir) => {
|
|
1397
|
+
if (!ir)
|
|
1398
|
+
return;
|
|
1399
|
+
this.notifier.alert(this.get('environmentChanged') ??
|
|
1400
|
+
'Environment changed', () => {
|
|
1401
|
+
// Callback, return true to prevent the default reload action
|
|
1402
|
+
if (callback == null || callback() !== true) {
|
|
1403
|
+
// Reload the page
|
|
1404
|
+
history.go(0);
|
|
1405
|
+
}
|
|
1406
|
+
});
|
|
1407
|
+
}, true);
|
|
1408
|
+
return;
|
|
1409
|
+
}
|
|
1410
|
+
}
|
|
1411
|
+
r = result;
|
|
1412
|
+
}
|
|
1413
|
+
else {
|
|
1414
|
+
r = data;
|
|
1415
|
+
}
|
|
1416
|
+
if (callback == null || callback(r) !== true) {
|
|
1417
|
+
const message = `${r.title} (${r.field})`;
|
|
1418
|
+
this.notifier.alert(message, () => {
|
|
1419
|
+
if (callback)
|
|
1420
|
+
callback(false);
|
|
1421
|
+
});
|
|
1422
|
+
}
|
|
1423
|
+
}
|
|
1364
1424
|
/**
|
|
1365
1425
|
* Setup callback
|
|
1366
1426
|
*/
|
|
@@ -1535,7 +1595,7 @@ class CoreApp {
|
|
|
1535
1595
|
}
|
|
1536
1596
|
/**
|
|
1537
1597
|
* Go to the login page
|
|
1538
|
-
* params Login parameters
|
|
1598
|
+
* @params Login parameters
|
|
1539
1599
|
*/
|
|
1540
1600
|
toLoginPage(params) {
|
|
1541
1601
|
// Destruct
|
|
@@ -1587,21 +1647,16 @@ class CoreApp {
|
|
|
1587
1647
|
* User login
|
|
1588
1648
|
* @param user User data
|
|
1589
1649
|
* @param refreshToken Refresh token
|
|
1590
|
-
* @param keep Keep login or not
|
|
1591
1650
|
*/
|
|
1592
|
-
userLogin(user, refreshToken
|
|
1651
|
+
userLogin(user, refreshToken) {
|
|
1652
|
+
// Hold the user data
|
|
1593
1653
|
this.userData = user;
|
|
1594
1654
|
// Cache the encrypted serverside device id
|
|
1595
1655
|
if (user.deviceId) {
|
|
1596
1656
|
this.storage.setData(this.fields.serversideDeviceId, user.deviceId);
|
|
1597
1657
|
}
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
}
|
|
1601
|
-
else {
|
|
1602
|
-
this.cachedRefreshToken = this.encrypt(refreshToken);
|
|
1603
|
-
this.authorize(user.token, user.tokenScheme, undefined);
|
|
1604
|
-
}
|
|
1658
|
+
// Authorize
|
|
1659
|
+
this.authorize(user.token, user.tokenScheme, refreshToken);
|
|
1605
1660
|
}
|
|
1606
1661
|
/**
|
|
1607
1662
|
* User logout
|
package/lib/cjs/app/IApp.d.ts
CHANGED
|
@@ -27,7 +27,7 @@ export interface NavigateOptions {
|
|
|
27
27
|
* array means success, false means failed but no any message
|
|
28
28
|
* other cases means failed with differnet message
|
|
29
29
|
*/
|
|
30
|
-
export type RefreshTokenResult<R> = IActionResult | [string, R];
|
|
30
|
+
export type RefreshTokenResult<R> = IActionResult | [string | null, R];
|
|
31
31
|
/**
|
|
32
32
|
* Format result custom type
|
|
33
33
|
*/
|
|
@@ -62,7 +62,11 @@ export type AppLoginParams = DataTypes.SimpleObject & {
|
|
|
62
62
|
*/
|
|
63
63
|
export interface RefreshTokenProps {
|
|
64
64
|
/**
|
|
65
|
-
*
|
|
65
|
+
* Refresh token
|
|
66
|
+
*/
|
|
67
|
+
token?: string;
|
|
68
|
+
/**
|
|
69
|
+
* API URL
|
|
66
70
|
*/
|
|
67
71
|
api?: string;
|
|
68
72
|
/**
|
|
@@ -515,9 +519,10 @@ export interface IApp {
|
|
|
515
519
|
*/
|
|
516
520
|
pageExit(): void;
|
|
517
521
|
/**
|
|
518
|
-
* Refresh token
|
|
522
|
+
* Refresh token with result
|
|
519
523
|
* @param props Props
|
|
520
524
|
* @param callback Callback
|
|
525
|
+
* @param api API
|
|
521
526
|
*/
|
|
522
527
|
refreshToken(props?: RefreshTokenProps, callback?: (result?: boolean | IActionResult) => boolean | void): Promise<void>;
|
|
523
528
|
/**
|
|
@@ -572,9 +577,8 @@ export interface IApp {
|
|
|
572
577
|
* User login
|
|
573
578
|
* @param user User data
|
|
574
579
|
* @param refreshToken Refresh token
|
|
575
|
-
* @param keep Keep login or not
|
|
576
580
|
*/
|
|
577
|
-
userLogin(user: IUser, refreshToken: string
|
|
581
|
+
userLogin(user: IUser, refreshToken: string): void;
|
|
578
582
|
/**
|
|
579
583
|
* User logout
|
|
580
584
|
* @param clearToken Clear refresh token or not
|
package/lib/cjs/erp/AuthApi.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ import { GetLogInUrlRQ } from './rq/GetLogInUrlRQ';
|
|
|
10
10
|
import { TokenRQ } from './rq/TokenRQ';
|
|
11
11
|
import { ApiRefreshTokenDto } from './dto/ApiRefreshTokenDto';
|
|
12
12
|
import { RefreshTokenProps, RefreshTokenResult } from '../app/IApp';
|
|
13
|
+
import { SwitchOrgRQ } from './rq/SwitchOrgRQ';
|
|
13
14
|
/**
|
|
14
15
|
* Authentication API
|
|
15
16
|
*/
|
|
@@ -56,11 +57,10 @@ export declare class AuthApi extends BaseApi {
|
|
|
56
57
|
loginId(id: string, payload?: ResultPayload): Promise<IActionResult<{}> | undefined>;
|
|
57
58
|
/**
|
|
58
59
|
* Refresh token
|
|
59
|
-
* @param token Refresh token
|
|
60
60
|
* @param props Props
|
|
61
61
|
* @returns Result
|
|
62
62
|
*/
|
|
63
|
-
refreshToken<R>(
|
|
63
|
+
refreshToken<R>(props: RefreshTokenProps): Promise<RefreshTokenResult<R>>;
|
|
64
64
|
/**
|
|
65
65
|
* Reset password
|
|
66
66
|
* @param rq Request data
|
|
@@ -75,4 +75,10 @@ export declare class AuthApi extends BaseApi {
|
|
|
75
75
|
* @returns Result
|
|
76
76
|
*/
|
|
77
77
|
signout(rq: SignoutRQ, payload?: ResultPayload): Promise<IActionResult<{}> | undefined>;
|
|
78
|
+
/**
|
|
79
|
+
* Switch organization
|
|
80
|
+
* @param rq Request data
|
|
81
|
+
* @param payload Payload
|
|
82
|
+
*/
|
|
83
|
+
switchOrg(rq: SwitchOrgRQ, payload?: ResultPayload): Promise<IActionResult<{}> | undefined>;
|
|
78
84
|
}
|
package/lib/cjs/erp/AuthApi.js
CHANGED
|
@@ -67,13 +67,21 @@ class AuthApi extends BaseApi_1.BaseApi {
|
|
|
67
67
|
}
|
|
68
68
|
/**
|
|
69
69
|
* Refresh token
|
|
70
|
-
* @param token Refresh token
|
|
71
70
|
* @param props Props
|
|
72
71
|
* @returns Result
|
|
73
72
|
*/
|
|
74
|
-
async refreshToken(
|
|
73
|
+
async refreshToken(props) {
|
|
75
74
|
// Destruct
|
|
76
|
-
const { api = 'Auth/RefreshToken', showLoading = false, tokenField = AuthApi.HeaderTokenField } = props ?? {};
|
|
75
|
+
const { api = 'Auth/RefreshToken', showLoading = false, token, tokenField = AuthApi.HeaderTokenField } = props ?? {};
|
|
76
|
+
// Check the token
|
|
77
|
+
if (!token) {
|
|
78
|
+
return {
|
|
79
|
+
ok: false,
|
|
80
|
+
type: 'noData',
|
|
81
|
+
field: 'token',
|
|
82
|
+
title: this.app.get('noData')
|
|
83
|
+
};
|
|
84
|
+
}
|
|
77
85
|
// Reqest data
|
|
78
86
|
const rq = {
|
|
79
87
|
deviceId: this.app.deviceId
|
|
@@ -102,15 +110,6 @@ class AuthApi extends BaseApi_1.BaseApi {
|
|
|
102
110
|
}
|
|
103
111
|
// Token
|
|
104
112
|
const refreshToken = this.app.getResponseToken(payload.response, tokenField);
|
|
105
|
-
if (!refreshToken) {
|
|
106
|
-
// No refresh token
|
|
107
|
-
return {
|
|
108
|
-
ok: false,
|
|
109
|
-
type: 'noData',
|
|
110
|
-
field: 'token',
|
|
111
|
-
title: this.app.get('noData')
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
113
|
// Success
|
|
115
114
|
return [refreshToken, result];
|
|
116
115
|
}
|
|
@@ -132,6 +131,14 @@ class AuthApi extends BaseApi_1.BaseApi {
|
|
|
132
131
|
signout(rq, payload) {
|
|
133
132
|
return this.api.put('Auth/Signout', rq, payload);
|
|
134
133
|
}
|
|
134
|
+
/**
|
|
135
|
+
* Switch organization
|
|
136
|
+
* @param rq Request data
|
|
137
|
+
* @param payload Payload
|
|
138
|
+
*/
|
|
139
|
+
switchOrg(rq, payload) {
|
|
140
|
+
return this.app.api.put('Auth/SwitchOrg', rq, payload);
|
|
141
|
+
}
|
|
135
142
|
}
|
|
136
143
|
exports.AuthApi = AuthApi;
|
|
137
144
|
/**
|
package/lib/cjs/erp/OrgApi.d.ts
CHANGED
|
@@ -57,13 +57,6 @@ export declare class OrgApi extends EntityApi {
|
|
|
57
57
|
* @returns Result
|
|
58
58
|
*/
|
|
59
59
|
sendActionMessage(rq: SendActionMessageRQ, payload?: IApiPayload<void>): Promise<void | undefined>;
|
|
60
|
-
/**
|
|
61
|
-
* Switch organization
|
|
62
|
-
* @param id Organization id
|
|
63
|
-
* @param serviceId Service id
|
|
64
|
-
* @param payload Payload
|
|
65
|
-
*/
|
|
66
|
-
switch(id: number, serviceId?: number, payload?: IApiPayload<boolean>): Promise<false | void>;
|
|
67
60
|
/**
|
|
68
61
|
* Update
|
|
69
62
|
* @param data Modal data
|
package/lib/cjs/erp/OrgApi.js
CHANGED
|
@@ -72,22 +72,6 @@ class OrgApi extends EntityApi_1.EntityApi {
|
|
|
72
72
|
payload ?? (payload = { showLoading: false });
|
|
73
73
|
return this.api.post('System/SendActionMessage', { ...rq, appId }, payload);
|
|
74
74
|
}
|
|
75
|
-
/**
|
|
76
|
-
* Switch organization
|
|
77
|
-
* @param id Organization id
|
|
78
|
-
* @param serviceId Service id
|
|
79
|
-
* @param payload Payload
|
|
80
|
-
*/
|
|
81
|
-
async switch(id, serviceId, payload) {
|
|
82
|
-
const result = await this.app.api.put('Organization/Switch', {
|
|
83
|
-
id,
|
|
84
|
-
serviceId,
|
|
85
|
-
deviceId: this.app.deviceId
|
|
86
|
-
}, payload);
|
|
87
|
-
if (result)
|
|
88
|
-
return await this.app.refreshToken();
|
|
89
|
-
return result;
|
|
90
|
-
}
|
|
91
75
|
/**
|
|
92
76
|
* Update
|
|
93
77
|
* @param data Modal data
|
package/lib/cjs/index.d.ts
CHANGED
|
@@ -61,6 +61,7 @@ export * from './erp/rq/RegionsRQ';
|
|
|
61
61
|
export * from './erp/rq/ResetPasswordRQ';
|
|
62
62
|
export * from './erp/rq/SendActionMessageRQ';
|
|
63
63
|
export * from './erp/rq/SignoutRQ';
|
|
64
|
+
export * from './erp/rq/SwitchOrgRQ';
|
|
64
65
|
export * from './erp/rq/TiplistRQ';
|
|
65
66
|
export * from './erp/rq/TokenRQ';
|
|
66
67
|
export * from './erp/rq/UpdateStatusRQ';
|
package/lib/cjs/index.js
CHANGED
|
@@ -86,6 +86,7 @@ __exportStar(require("./erp/rq/RegionsRQ"), exports);
|
|
|
86
86
|
__exportStar(require("./erp/rq/ResetPasswordRQ"), exports);
|
|
87
87
|
__exportStar(require("./erp/rq/SendActionMessageRQ"), exports);
|
|
88
88
|
__exportStar(require("./erp/rq/SignoutRQ"), exports);
|
|
89
|
+
__exportStar(require("./erp/rq/SwitchOrgRQ"), exports);
|
|
89
90
|
__exportStar(require("./erp/rq/TiplistRQ"), exports);
|
|
90
91
|
__exportStar(require("./erp/rq/TokenRQ"), exports);
|
|
91
92
|
__exportStar(require("./erp/rq/UpdateStatusRQ"), exports);
|
package/lib/mjs/app/CoreApp.d.ts
CHANGED
|
@@ -152,7 +152,6 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
|
|
|
152
152
|
* Passphrase for encryption
|
|
153
153
|
*/
|
|
154
154
|
protected passphrase: string;
|
|
155
|
-
private cachedRefreshToken?;
|
|
156
155
|
private apis;
|
|
157
156
|
private tasks;
|
|
158
157
|
/**
|
|
@@ -573,7 +572,7 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
|
|
|
573
572
|
*/
|
|
574
573
|
abstract freshCountdownUI(callback?: () => PromiseLike<unknown>): void;
|
|
575
574
|
/**
|
|
576
|
-
* Refresh token
|
|
575
|
+
* Refresh token with result
|
|
577
576
|
* @param props Props
|
|
578
577
|
* @param callback Callback
|
|
579
578
|
*/
|
|
@@ -619,7 +618,7 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
|
|
|
619
618
|
signout(): Promise<void>;
|
|
620
619
|
/**
|
|
621
620
|
* Go to the login page
|
|
622
|
-
* params Login parameters
|
|
621
|
+
* @params Login parameters
|
|
623
622
|
*/
|
|
624
623
|
toLoginPage(params?: AppLoginParams): void;
|
|
625
624
|
/**
|
|
@@ -638,9 +637,8 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
|
|
|
638
637
|
* User login
|
|
639
638
|
* @param user User data
|
|
640
639
|
* @param refreshToken Refresh token
|
|
641
|
-
* @param keep Keep login or not
|
|
642
640
|
*/
|
|
643
|
-
userLogin(user: U, refreshToken: string
|
|
641
|
+
userLogin(user: U, refreshToken: string): void;
|
|
644
642
|
/**
|
|
645
643
|
* User logout
|
|
646
644
|
* @param clearToken Clear refresh token or not
|
package/lib/mjs/app/CoreApp.js
CHANGED
|
@@ -159,13 +159,14 @@ export class CoreApp {
|
|
|
159
159
|
throw new Error('No default region defined');
|
|
160
160
|
}
|
|
161
161
|
this.defaultRegion = region;
|
|
162
|
+
// Current system refresh token
|
|
162
163
|
const refresh = async (api, token) => {
|
|
163
164
|
if (this.lastCalled) {
|
|
164
165
|
// Call refreshToken to update access token
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
166
|
+
await this.refreshToken({ token, showLoading: false }, (result) => {
|
|
167
|
+
if (result === true)
|
|
168
|
+
return;
|
|
169
|
+
console.log(`CoreApp.${this.name}.RefreshToken`, result);
|
|
169
170
|
});
|
|
170
171
|
}
|
|
171
172
|
else {
|
|
@@ -663,7 +664,6 @@ export class CoreApp {
|
|
|
663
664
|
}
|
|
664
665
|
}
|
|
665
666
|
else {
|
|
666
|
-
this.cachedRefreshToken = undefined;
|
|
667
667
|
this.updateApi(this.api.name, undefined, -1);
|
|
668
668
|
}
|
|
669
669
|
// Host notice
|
|
@@ -770,7 +770,6 @@ export class CoreApp {
|
|
|
770
770
|
* Clear cached token
|
|
771
771
|
*/
|
|
772
772
|
clearCacheToken() {
|
|
773
|
-
this.cachedRefreshToken = undefined;
|
|
774
773
|
this.storage.setPersistedData(this.fields.headerToken, undefined);
|
|
775
774
|
}
|
|
776
775
|
/**
|
|
@@ -1105,9 +1104,6 @@ export class CoreApp {
|
|
|
1105
1104
|
* @returns Cached token
|
|
1106
1105
|
*/
|
|
1107
1106
|
getCacheToken() {
|
|
1108
|
-
// Temp refresh token
|
|
1109
|
-
if (this.cachedRefreshToken)
|
|
1110
|
-
return this.cachedRefreshToken;
|
|
1111
1107
|
return this.storage.getData(this.fields.headerToken);
|
|
1112
1108
|
}
|
|
1113
1109
|
/**
|
|
@@ -1353,11 +1349,75 @@ export class CoreApp {
|
|
|
1353
1349
|
this.notifier.hideLoading(true);
|
|
1354
1350
|
}
|
|
1355
1351
|
/**
|
|
1356
|
-
* Refresh token
|
|
1352
|
+
* Refresh token with result
|
|
1357
1353
|
* @param props Props
|
|
1358
1354
|
* @param callback Callback
|
|
1359
1355
|
*/
|
|
1360
|
-
async refreshToken(props, callback) {
|
|
1356
|
+
async refreshToken(props, callback) {
|
|
1357
|
+
// Check props
|
|
1358
|
+
props ?? (props = {});
|
|
1359
|
+
props.token ?? (props.token = this.getCacheToken());
|
|
1360
|
+
// Call refresh token API
|
|
1361
|
+
let data = await new AuthApi(this).refreshToken(props);
|
|
1362
|
+
let r;
|
|
1363
|
+
if (Array.isArray(data)) {
|
|
1364
|
+
const [token, result] = data;
|
|
1365
|
+
if (result.ok) {
|
|
1366
|
+
if (!token) {
|
|
1367
|
+
data = {
|
|
1368
|
+
ok: false,
|
|
1369
|
+
type: 'noData',
|
|
1370
|
+
field: 'token',
|
|
1371
|
+
title: this.get('noData')
|
|
1372
|
+
};
|
|
1373
|
+
}
|
|
1374
|
+
else if (result.data == null) {
|
|
1375
|
+
data = {
|
|
1376
|
+
ok: false,
|
|
1377
|
+
type: 'noData',
|
|
1378
|
+
field: 'user',
|
|
1379
|
+
title: this.get('noData')
|
|
1380
|
+
};
|
|
1381
|
+
}
|
|
1382
|
+
else {
|
|
1383
|
+
// User login
|
|
1384
|
+
this.userLogin(result.data, token);
|
|
1385
|
+
if (callback)
|
|
1386
|
+
callback(true);
|
|
1387
|
+
// Exit
|
|
1388
|
+
return;
|
|
1389
|
+
}
|
|
1390
|
+
}
|
|
1391
|
+
else if (this.checkDeviceResult(result)) {
|
|
1392
|
+
if (callback == null || callback(result) !== true) {
|
|
1393
|
+
this.initCall((ir) => {
|
|
1394
|
+
if (!ir)
|
|
1395
|
+
return;
|
|
1396
|
+
this.notifier.alert(this.get('environmentChanged') ??
|
|
1397
|
+
'Environment changed', () => {
|
|
1398
|
+
// Callback, return true to prevent the default reload action
|
|
1399
|
+
if (callback == null || callback() !== true) {
|
|
1400
|
+
// Reload the page
|
|
1401
|
+
history.go(0);
|
|
1402
|
+
}
|
|
1403
|
+
});
|
|
1404
|
+
}, true);
|
|
1405
|
+
return;
|
|
1406
|
+
}
|
|
1407
|
+
}
|
|
1408
|
+
r = result;
|
|
1409
|
+
}
|
|
1410
|
+
else {
|
|
1411
|
+
r = data;
|
|
1412
|
+
}
|
|
1413
|
+
if (callback == null || callback(r) !== true) {
|
|
1414
|
+
const message = `${r.title} (${r.field})`;
|
|
1415
|
+
this.notifier.alert(message, () => {
|
|
1416
|
+
if (callback)
|
|
1417
|
+
callback(false);
|
|
1418
|
+
});
|
|
1419
|
+
}
|
|
1420
|
+
}
|
|
1361
1421
|
/**
|
|
1362
1422
|
* Setup callback
|
|
1363
1423
|
*/
|
|
@@ -1532,7 +1592,7 @@ export class CoreApp {
|
|
|
1532
1592
|
}
|
|
1533
1593
|
/**
|
|
1534
1594
|
* Go to the login page
|
|
1535
|
-
* params Login parameters
|
|
1595
|
+
* @params Login parameters
|
|
1536
1596
|
*/
|
|
1537
1597
|
toLoginPage(params) {
|
|
1538
1598
|
// Destruct
|
|
@@ -1584,21 +1644,16 @@ export class CoreApp {
|
|
|
1584
1644
|
* User login
|
|
1585
1645
|
* @param user User data
|
|
1586
1646
|
* @param refreshToken Refresh token
|
|
1587
|
-
* @param keep Keep login or not
|
|
1588
1647
|
*/
|
|
1589
|
-
userLogin(user, refreshToken
|
|
1648
|
+
userLogin(user, refreshToken) {
|
|
1649
|
+
// Hold the user data
|
|
1590
1650
|
this.userData = user;
|
|
1591
1651
|
// Cache the encrypted serverside device id
|
|
1592
1652
|
if (user.deviceId) {
|
|
1593
1653
|
this.storage.setData(this.fields.serversideDeviceId, user.deviceId);
|
|
1594
1654
|
}
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
}
|
|
1598
|
-
else {
|
|
1599
|
-
this.cachedRefreshToken = this.encrypt(refreshToken);
|
|
1600
|
-
this.authorize(user.token, user.tokenScheme, undefined);
|
|
1601
|
-
}
|
|
1655
|
+
// Authorize
|
|
1656
|
+
this.authorize(user.token, user.tokenScheme, refreshToken);
|
|
1602
1657
|
}
|
|
1603
1658
|
/**
|
|
1604
1659
|
* User logout
|
package/lib/mjs/app/IApp.d.ts
CHANGED
|
@@ -27,7 +27,7 @@ export interface NavigateOptions {
|
|
|
27
27
|
* array means success, false means failed but no any message
|
|
28
28
|
* other cases means failed with differnet message
|
|
29
29
|
*/
|
|
30
|
-
export type RefreshTokenResult<R> = IActionResult | [string, R];
|
|
30
|
+
export type RefreshTokenResult<R> = IActionResult | [string | null, R];
|
|
31
31
|
/**
|
|
32
32
|
* Format result custom type
|
|
33
33
|
*/
|
|
@@ -62,7 +62,11 @@ export type AppLoginParams = DataTypes.SimpleObject & {
|
|
|
62
62
|
*/
|
|
63
63
|
export interface RefreshTokenProps {
|
|
64
64
|
/**
|
|
65
|
-
*
|
|
65
|
+
* Refresh token
|
|
66
|
+
*/
|
|
67
|
+
token?: string;
|
|
68
|
+
/**
|
|
69
|
+
* API URL
|
|
66
70
|
*/
|
|
67
71
|
api?: string;
|
|
68
72
|
/**
|
|
@@ -515,9 +519,10 @@ export interface IApp {
|
|
|
515
519
|
*/
|
|
516
520
|
pageExit(): void;
|
|
517
521
|
/**
|
|
518
|
-
* Refresh token
|
|
522
|
+
* Refresh token with result
|
|
519
523
|
* @param props Props
|
|
520
524
|
* @param callback Callback
|
|
525
|
+
* @param api API
|
|
521
526
|
*/
|
|
522
527
|
refreshToken(props?: RefreshTokenProps, callback?: (result?: boolean | IActionResult) => boolean | void): Promise<void>;
|
|
523
528
|
/**
|
|
@@ -572,9 +577,8 @@ export interface IApp {
|
|
|
572
577
|
* User login
|
|
573
578
|
* @param user User data
|
|
574
579
|
* @param refreshToken Refresh token
|
|
575
|
-
* @param keep Keep login or not
|
|
576
580
|
*/
|
|
577
|
-
userLogin(user: IUser, refreshToken: string
|
|
581
|
+
userLogin(user: IUser, refreshToken: string): void;
|
|
578
582
|
/**
|
|
579
583
|
* User logout
|
|
580
584
|
* @param clearToken Clear refresh token or not
|
package/lib/mjs/erp/AuthApi.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ import { GetLogInUrlRQ } from './rq/GetLogInUrlRQ';
|
|
|
10
10
|
import { TokenRQ } from './rq/TokenRQ';
|
|
11
11
|
import { ApiRefreshTokenDto } from './dto/ApiRefreshTokenDto';
|
|
12
12
|
import { RefreshTokenProps, RefreshTokenResult } from '../app/IApp';
|
|
13
|
+
import { SwitchOrgRQ } from './rq/SwitchOrgRQ';
|
|
13
14
|
/**
|
|
14
15
|
* Authentication API
|
|
15
16
|
*/
|
|
@@ -56,11 +57,10 @@ export declare class AuthApi extends BaseApi {
|
|
|
56
57
|
loginId(id: string, payload?: ResultPayload): Promise<IActionResult<{}> | undefined>;
|
|
57
58
|
/**
|
|
58
59
|
* Refresh token
|
|
59
|
-
* @param token Refresh token
|
|
60
60
|
* @param props Props
|
|
61
61
|
* @returns Result
|
|
62
62
|
*/
|
|
63
|
-
refreshToken<R>(
|
|
63
|
+
refreshToken<R>(props: RefreshTokenProps): Promise<RefreshTokenResult<R>>;
|
|
64
64
|
/**
|
|
65
65
|
* Reset password
|
|
66
66
|
* @param rq Request data
|
|
@@ -75,4 +75,10 @@ export declare class AuthApi extends BaseApi {
|
|
|
75
75
|
* @returns Result
|
|
76
76
|
*/
|
|
77
77
|
signout(rq: SignoutRQ, payload?: ResultPayload): Promise<IActionResult<{}> | undefined>;
|
|
78
|
+
/**
|
|
79
|
+
* Switch organization
|
|
80
|
+
* @param rq Request data
|
|
81
|
+
* @param payload Payload
|
|
82
|
+
*/
|
|
83
|
+
switchOrg(rq: SwitchOrgRQ, payload?: ResultPayload): Promise<IActionResult<{}> | undefined>;
|
|
78
84
|
}
|
package/lib/mjs/erp/AuthApi.js
CHANGED
|
@@ -64,13 +64,21 @@ export class AuthApi extends BaseApi {
|
|
|
64
64
|
}
|
|
65
65
|
/**
|
|
66
66
|
* Refresh token
|
|
67
|
-
* @param token Refresh token
|
|
68
67
|
* @param props Props
|
|
69
68
|
* @returns Result
|
|
70
69
|
*/
|
|
71
|
-
async refreshToken(
|
|
70
|
+
async refreshToken(props) {
|
|
72
71
|
// Destruct
|
|
73
|
-
const { api = 'Auth/RefreshToken', showLoading = false, tokenField = AuthApi.HeaderTokenField } = props ?? {};
|
|
72
|
+
const { api = 'Auth/RefreshToken', showLoading = false, token, tokenField = AuthApi.HeaderTokenField } = props ?? {};
|
|
73
|
+
// Check the token
|
|
74
|
+
if (!token) {
|
|
75
|
+
return {
|
|
76
|
+
ok: false,
|
|
77
|
+
type: 'noData',
|
|
78
|
+
field: 'token',
|
|
79
|
+
title: this.app.get('noData')
|
|
80
|
+
};
|
|
81
|
+
}
|
|
74
82
|
// Reqest data
|
|
75
83
|
const rq = {
|
|
76
84
|
deviceId: this.app.deviceId
|
|
@@ -99,15 +107,6 @@ export class AuthApi extends BaseApi {
|
|
|
99
107
|
}
|
|
100
108
|
// Token
|
|
101
109
|
const refreshToken = this.app.getResponseToken(payload.response, tokenField);
|
|
102
|
-
if (!refreshToken) {
|
|
103
|
-
// No refresh token
|
|
104
|
-
return {
|
|
105
|
-
ok: false,
|
|
106
|
-
type: 'noData',
|
|
107
|
-
field: 'token',
|
|
108
|
-
title: this.app.get('noData')
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
110
|
// Success
|
|
112
111
|
return [refreshToken, result];
|
|
113
112
|
}
|
|
@@ -129,6 +128,14 @@ export class AuthApi extends BaseApi {
|
|
|
129
128
|
signout(rq, payload) {
|
|
130
129
|
return this.api.put('Auth/Signout', rq, payload);
|
|
131
130
|
}
|
|
131
|
+
/**
|
|
132
|
+
* Switch organization
|
|
133
|
+
* @param rq Request data
|
|
134
|
+
* @param payload Payload
|
|
135
|
+
*/
|
|
136
|
+
switchOrg(rq, payload) {
|
|
137
|
+
return this.app.api.put('Auth/SwitchOrg', rq, payload);
|
|
138
|
+
}
|
|
132
139
|
}
|
|
133
140
|
/**
|
|
134
141
|
* Header token field name
|
package/lib/mjs/erp/OrgApi.d.ts
CHANGED
|
@@ -57,13 +57,6 @@ export declare class OrgApi extends EntityApi {
|
|
|
57
57
|
* @returns Result
|
|
58
58
|
*/
|
|
59
59
|
sendActionMessage(rq: SendActionMessageRQ, payload?: IApiPayload<void>): Promise<void | undefined>;
|
|
60
|
-
/**
|
|
61
|
-
* Switch organization
|
|
62
|
-
* @param id Organization id
|
|
63
|
-
* @param serviceId Service id
|
|
64
|
-
* @param payload Payload
|
|
65
|
-
*/
|
|
66
|
-
switch(id: number, serviceId?: number, payload?: IApiPayload<boolean>): Promise<false | void>;
|
|
67
60
|
/**
|
|
68
61
|
* Update
|
|
69
62
|
* @param data Modal data
|
package/lib/mjs/erp/OrgApi.js
CHANGED
|
@@ -69,22 +69,6 @@ export class OrgApi extends EntityApi {
|
|
|
69
69
|
payload ?? (payload = { showLoading: false });
|
|
70
70
|
return this.api.post('System/SendActionMessage', { ...rq, appId }, payload);
|
|
71
71
|
}
|
|
72
|
-
/**
|
|
73
|
-
* Switch organization
|
|
74
|
-
* @param id Organization id
|
|
75
|
-
* @param serviceId Service id
|
|
76
|
-
* @param payload Payload
|
|
77
|
-
*/
|
|
78
|
-
async switch(id, serviceId, payload) {
|
|
79
|
-
const result = await this.app.api.put('Organization/Switch', {
|
|
80
|
-
id,
|
|
81
|
-
serviceId,
|
|
82
|
-
deviceId: this.app.deviceId
|
|
83
|
-
}, payload);
|
|
84
|
-
if (result)
|
|
85
|
-
return await this.app.refreshToken();
|
|
86
|
-
return result;
|
|
87
|
-
}
|
|
88
72
|
/**
|
|
89
73
|
* Update
|
|
90
74
|
* @param data Modal data
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/lib/mjs/index.d.ts
CHANGED
|
@@ -61,6 +61,7 @@ export * from './erp/rq/RegionsRQ';
|
|
|
61
61
|
export * from './erp/rq/ResetPasswordRQ';
|
|
62
62
|
export * from './erp/rq/SendActionMessageRQ';
|
|
63
63
|
export * from './erp/rq/SignoutRQ';
|
|
64
|
+
export * from './erp/rq/SwitchOrgRQ';
|
|
64
65
|
export * from './erp/rq/TiplistRQ';
|
|
65
66
|
export * from './erp/rq/TokenRQ';
|
|
66
67
|
export * from './erp/rq/UpdateStatusRQ';
|
package/lib/mjs/index.js
CHANGED
|
@@ -69,6 +69,7 @@ export * from './erp/rq/RegionsRQ';
|
|
|
69
69
|
export * from './erp/rq/ResetPasswordRQ';
|
|
70
70
|
export * from './erp/rq/SendActionMessageRQ';
|
|
71
71
|
export * from './erp/rq/SignoutRQ';
|
|
72
|
+
export * from './erp/rq/SwitchOrgRQ';
|
|
72
73
|
export * from './erp/rq/TiplistRQ';
|
|
73
74
|
export * from './erp/rq/TokenRQ';
|
|
74
75
|
export * from './erp/rq/UpdateStatusRQ';
|
package/package.json
CHANGED
package/src/app/CoreApp.ts
CHANGED
|
@@ -282,8 +282,6 @@ export abstract class CoreApp<
|
|
|
282
282
|
*/
|
|
283
283
|
protected passphrase: string = '';
|
|
284
284
|
|
|
285
|
-
private cachedRefreshToken?: string;
|
|
286
|
-
|
|
287
285
|
private apis: Record<string, ApiTaskData> = {};
|
|
288
286
|
|
|
289
287
|
private tasks: [() => PromiseLike<void | false>, number, number][] = [];
|
|
@@ -328,14 +326,20 @@ export abstract class CoreApp<
|
|
|
328
326
|
}
|
|
329
327
|
this.defaultRegion = region;
|
|
330
328
|
|
|
329
|
+
// Current system refresh token
|
|
331
330
|
const refresh: ApiRefreshTokenFunction = async (api, token) => {
|
|
332
331
|
if (this.lastCalled) {
|
|
333
332
|
// Call refreshToken to update access token
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
333
|
+
await this.refreshToken(
|
|
334
|
+
{ token, showLoading: false },
|
|
335
|
+
(result) => {
|
|
336
|
+
if (result === true) return;
|
|
337
|
+
console.log(
|
|
338
|
+
`CoreApp.${this.name}.RefreshToken`,
|
|
339
|
+
result
|
|
340
|
+
);
|
|
341
|
+
}
|
|
342
|
+
);
|
|
339
343
|
} else {
|
|
340
344
|
// Popup countdown for user action
|
|
341
345
|
this.freshCountdownUI();
|
|
@@ -1037,7 +1041,6 @@ export abstract class CoreApp<
|
|
|
1037
1041
|
);
|
|
1038
1042
|
}
|
|
1039
1043
|
} else {
|
|
1040
|
-
this.cachedRefreshToken = undefined;
|
|
1041
1044
|
this.updateApi(this.api.name, undefined, -1);
|
|
1042
1045
|
}
|
|
1043
1046
|
|
|
@@ -1169,7 +1172,6 @@ export abstract class CoreApp<
|
|
|
1169
1172
|
* Clear cached token
|
|
1170
1173
|
*/
|
|
1171
1174
|
clearCacheToken() {
|
|
1172
|
-
this.cachedRefreshToken = undefined;
|
|
1173
1175
|
this.storage.setPersistedData(this.fields.headerToken, undefined);
|
|
1174
1176
|
}
|
|
1175
1177
|
|
|
@@ -1596,8 +1598,6 @@ export abstract class CoreApp<
|
|
|
1596
1598
|
* @returns Cached token
|
|
1597
1599
|
*/
|
|
1598
1600
|
getCacheToken(): string | undefined {
|
|
1599
|
-
// Temp refresh token
|
|
1600
|
-
if (this.cachedRefreshToken) return this.cachedRefreshToken;
|
|
1601
1601
|
return this.storage.getData<string>(this.fields.headerToken);
|
|
1602
1602
|
}
|
|
1603
1603
|
|
|
@@ -1883,14 +1883,82 @@ export abstract class CoreApp<
|
|
|
1883
1883
|
abstract freshCountdownUI(callback?: () => PromiseLike<unknown>): void;
|
|
1884
1884
|
|
|
1885
1885
|
/**
|
|
1886
|
-
* Refresh token
|
|
1886
|
+
* Refresh token with result
|
|
1887
1887
|
* @param props Props
|
|
1888
1888
|
* @param callback Callback
|
|
1889
1889
|
*/
|
|
1890
1890
|
async refreshToken(
|
|
1891
1891
|
props?: RefreshTokenProps,
|
|
1892
1892
|
callback?: (result?: boolean | IActionResult) => boolean | void
|
|
1893
|
-
) {
|
|
1893
|
+
) {
|
|
1894
|
+
// Check props
|
|
1895
|
+
props ??= {};
|
|
1896
|
+
props.token ??= this.getCacheToken();
|
|
1897
|
+
|
|
1898
|
+
// Call refresh token API
|
|
1899
|
+
let data = await new AuthApi(this).refreshToken<IActionResult<U>>(
|
|
1900
|
+
props
|
|
1901
|
+
);
|
|
1902
|
+
|
|
1903
|
+
let r: IActionResult;
|
|
1904
|
+
if (Array.isArray(data)) {
|
|
1905
|
+
const [token, result] = data;
|
|
1906
|
+
if (result.ok) {
|
|
1907
|
+
if (!token) {
|
|
1908
|
+
data = {
|
|
1909
|
+
ok: false,
|
|
1910
|
+
type: 'noData',
|
|
1911
|
+
field: 'token',
|
|
1912
|
+
title: this.get('noData')
|
|
1913
|
+
};
|
|
1914
|
+
} else if (result.data == null) {
|
|
1915
|
+
data = {
|
|
1916
|
+
ok: false,
|
|
1917
|
+
type: 'noData',
|
|
1918
|
+
field: 'user',
|
|
1919
|
+
title: this.get('noData')
|
|
1920
|
+
};
|
|
1921
|
+
} else {
|
|
1922
|
+
// User login
|
|
1923
|
+
this.userLogin(result.data, token);
|
|
1924
|
+
|
|
1925
|
+
if (callback) callback(true);
|
|
1926
|
+
|
|
1927
|
+
// Exit
|
|
1928
|
+
return;
|
|
1929
|
+
}
|
|
1930
|
+
} else if (this.checkDeviceResult(result)) {
|
|
1931
|
+
if (callback == null || callback(result) !== true) {
|
|
1932
|
+
this.initCall((ir) => {
|
|
1933
|
+
if (!ir) return;
|
|
1934
|
+
this.notifier.alert(
|
|
1935
|
+
this.get('environmentChanged') ??
|
|
1936
|
+
'Environment changed',
|
|
1937
|
+
() => {
|
|
1938
|
+
// Callback, return true to prevent the default reload action
|
|
1939
|
+
if (callback == null || callback() !== true) {
|
|
1940
|
+
// Reload the page
|
|
1941
|
+
history.go(0);
|
|
1942
|
+
}
|
|
1943
|
+
}
|
|
1944
|
+
);
|
|
1945
|
+
}, true);
|
|
1946
|
+
return;
|
|
1947
|
+
}
|
|
1948
|
+
}
|
|
1949
|
+
|
|
1950
|
+
r = result;
|
|
1951
|
+
} else {
|
|
1952
|
+
r = data;
|
|
1953
|
+
}
|
|
1954
|
+
|
|
1955
|
+
if (callback == null || callback(r) !== true) {
|
|
1956
|
+
const message = `${r.title} (${r.field})`;
|
|
1957
|
+
this.notifier.alert(message, () => {
|
|
1958
|
+
if (callback) callback(false);
|
|
1959
|
+
});
|
|
1960
|
+
}
|
|
1961
|
+
}
|
|
1894
1962
|
|
|
1895
1963
|
/**
|
|
1896
1964
|
* Setup callback
|
|
@@ -2111,7 +2179,7 @@ export abstract class CoreApp<
|
|
|
2111
2179
|
|
|
2112
2180
|
/**
|
|
2113
2181
|
* Go to the login page
|
|
2114
|
-
* params Login parameters
|
|
2182
|
+
* @params Login parameters
|
|
2115
2183
|
*/
|
|
2116
2184
|
toLoginPage(params?: AppLoginParams) {
|
|
2117
2185
|
// Destruct
|
|
@@ -2171,9 +2239,9 @@ export abstract class CoreApp<
|
|
|
2171
2239
|
* User login
|
|
2172
2240
|
* @param user User data
|
|
2173
2241
|
* @param refreshToken Refresh token
|
|
2174
|
-
* @param keep Keep login or not
|
|
2175
2242
|
*/
|
|
2176
|
-
userLogin(user: U, refreshToken: string
|
|
2243
|
+
userLogin(user: U, refreshToken: string) {
|
|
2244
|
+
// Hold the user data
|
|
2177
2245
|
this.userData = user;
|
|
2178
2246
|
|
|
2179
2247
|
// Cache the encrypted serverside device id
|
|
@@ -2181,12 +2249,8 @@ export abstract class CoreApp<
|
|
|
2181
2249
|
this.storage.setData(this.fields.serversideDeviceId, user.deviceId);
|
|
2182
2250
|
}
|
|
2183
2251
|
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
} else {
|
|
2187
|
-
this.cachedRefreshToken = this.encrypt(refreshToken);
|
|
2188
|
-
this.authorize(user.token, user.tokenScheme, undefined);
|
|
2189
|
-
}
|
|
2252
|
+
// Authorize
|
|
2253
|
+
this.authorize(user.token, user.tokenScheme, refreshToken);
|
|
2190
2254
|
}
|
|
2191
2255
|
|
|
2192
2256
|
/**
|
package/src/app/IApp.ts
CHANGED
|
@@ -45,7 +45,7 @@ export interface NavigateOptions {
|
|
|
45
45
|
* array means success, false means failed but no any message
|
|
46
46
|
* other cases means failed with differnet message
|
|
47
47
|
*/
|
|
48
|
-
export type RefreshTokenResult<R> = IActionResult | [string, R];
|
|
48
|
+
export type RefreshTokenResult<R> = IActionResult | [string | null, R];
|
|
49
49
|
|
|
50
50
|
/**
|
|
51
51
|
* Format result custom type
|
|
@@ -88,7 +88,12 @@ export type AppLoginParams = DataTypes.SimpleObject & {
|
|
|
88
88
|
*/
|
|
89
89
|
export interface RefreshTokenProps {
|
|
90
90
|
/**
|
|
91
|
-
*
|
|
91
|
+
* Refresh token
|
|
92
|
+
*/
|
|
93
|
+
token?: string;
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* API URL
|
|
92
97
|
*/
|
|
93
98
|
api?: string;
|
|
94
99
|
|
|
@@ -695,9 +700,10 @@ export interface IApp {
|
|
|
695
700
|
pageExit(): void;
|
|
696
701
|
|
|
697
702
|
/**
|
|
698
|
-
* Refresh token
|
|
703
|
+
* Refresh token with result
|
|
699
704
|
* @param props Props
|
|
700
705
|
* @param callback Callback
|
|
706
|
+
* @param api API
|
|
701
707
|
*/
|
|
702
708
|
refreshToken(
|
|
703
709
|
props?: RefreshTokenProps,
|
|
@@ -771,9 +777,8 @@ export interface IApp {
|
|
|
771
777
|
* User login
|
|
772
778
|
* @param user User data
|
|
773
779
|
* @param refreshToken Refresh token
|
|
774
|
-
* @param keep Keep login or not
|
|
775
780
|
*/
|
|
776
|
-
userLogin(user: IUser, refreshToken: string
|
|
781
|
+
userLogin(user: IUser, refreshToken: string): void;
|
|
777
782
|
|
|
778
783
|
/**
|
|
779
784
|
* User logout
|
package/src/erp/AuthApi.ts
CHANGED
|
@@ -12,6 +12,7 @@ import { TokenRQ } from './rq/TokenRQ';
|
|
|
12
12
|
import { ApiRefreshTokenDto } from './dto/ApiRefreshTokenDto';
|
|
13
13
|
import { RefreshTokenProps, RefreshTokenResult } from '../app/IApp';
|
|
14
14
|
import { RefreshTokenRQ } from './rq/RefreshTokenRQ';
|
|
15
|
+
import { SwitchOrgRQ } from './rq/SwitchOrgRQ';
|
|
15
16
|
|
|
16
17
|
/**
|
|
17
18
|
* Authentication API
|
|
@@ -91,21 +92,30 @@ export class AuthApi extends BaseApi {
|
|
|
91
92
|
|
|
92
93
|
/**
|
|
93
94
|
* Refresh token
|
|
94
|
-
* @param token Refresh token
|
|
95
95
|
* @param props Props
|
|
96
96
|
* @returns Result
|
|
97
97
|
*/
|
|
98
98
|
async refreshToken<R>(
|
|
99
|
-
|
|
100
|
-
props?: RefreshTokenProps
|
|
99
|
+
props: RefreshTokenProps
|
|
101
100
|
): Promise<RefreshTokenResult<R>> {
|
|
102
101
|
// Destruct
|
|
103
102
|
const {
|
|
104
103
|
api = 'Auth/RefreshToken',
|
|
105
104
|
showLoading = false,
|
|
105
|
+
token,
|
|
106
106
|
tokenField = AuthApi.HeaderTokenField
|
|
107
107
|
} = props ?? {};
|
|
108
108
|
|
|
109
|
+
// Check the token
|
|
110
|
+
if (!token) {
|
|
111
|
+
return {
|
|
112
|
+
ok: false,
|
|
113
|
+
type: 'noData',
|
|
114
|
+
field: 'token',
|
|
115
|
+
title: this.app.get('noData')
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
|
|
109
119
|
// Reqest data
|
|
110
120
|
const rq: RefreshTokenRQ = {
|
|
111
121
|
deviceId: this.app.deviceId
|
|
@@ -141,16 +151,6 @@ export class AuthApi extends BaseApi {
|
|
|
141
151
|
tokenField
|
|
142
152
|
);
|
|
143
153
|
|
|
144
|
-
if (!refreshToken) {
|
|
145
|
-
// No refresh token
|
|
146
|
-
return {
|
|
147
|
-
ok: false,
|
|
148
|
-
type: 'noData',
|
|
149
|
-
field: 'token',
|
|
150
|
-
title: this.app.get('noData')
|
|
151
|
-
};
|
|
152
|
-
}
|
|
153
|
-
|
|
154
154
|
// Success
|
|
155
155
|
return [refreshToken, result];
|
|
156
156
|
}
|
|
@@ -174,4 +174,13 @@ export class AuthApi extends BaseApi {
|
|
|
174
174
|
signout(rq: SignoutRQ, payload?: ResultPayload) {
|
|
175
175
|
return this.api.put('Auth/Signout', rq, payload);
|
|
176
176
|
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Switch organization
|
|
180
|
+
* @param rq Request data
|
|
181
|
+
* @param payload Payload
|
|
182
|
+
*/
|
|
183
|
+
switchOrg(rq: SwitchOrgRQ, payload?: ResultPayload) {
|
|
184
|
+
return this.app.api.put('Auth/SwitchOrg', rq, payload);
|
|
185
|
+
}
|
|
177
186
|
}
|
package/src/erp/OrgApi.ts
CHANGED
|
@@ -111,30 +111,6 @@ export class OrgApi extends EntityApi {
|
|
|
111
111
|
);
|
|
112
112
|
}
|
|
113
113
|
|
|
114
|
-
/**
|
|
115
|
-
* Switch organization
|
|
116
|
-
* @param id Organization id
|
|
117
|
-
* @param serviceId Service id
|
|
118
|
-
* @param payload Payload
|
|
119
|
-
*/
|
|
120
|
-
async switch(
|
|
121
|
-
id: number,
|
|
122
|
-
serviceId?: number,
|
|
123
|
-
payload?: IApiPayload<boolean>
|
|
124
|
-
) {
|
|
125
|
-
const result = await this.app.api.put(
|
|
126
|
-
'Organization/Switch',
|
|
127
|
-
{
|
|
128
|
-
id,
|
|
129
|
-
serviceId,
|
|
130
|
-
deviceId: this.app.deviceId
|
|
131
|
-
},
|
|
132
|
-
payload
|
|
133
|
-
);
|
|
134
|
-
if (result) return await this.app.refreshToken();
|
|
135
|
-
return result;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
114
|
/**
|
|
139
115
|
* Update
|
|
140
116
|
* @param data Modal data
|
package/src/index.ts
CHANGED
|
@@ -76,6 +76,7 @@ export * from './erp/rq/RegionsRQ';
|
|
|
76
76
|
export * from './erp/rq/ResetPasswordRQ';
|
|
77
77
|
export * from './erp/rq/SendActionMessageRQ';
|
|
78
78
|
export * from './erp/rq/SignoutRQ';
|
|
79
|
+
export * from './erp/rq/SwitchOrgRQ';
|
|
79
80
|
export * from './erp/rq/TiplistRQ';
|
|
80
81
|
export * from './erp/rq/TokenRQ';
|
|
81
82
|
export * from './erp/rq/UpdateStatusRQ';
|