@etsoo/appscript 1.5.45 → 1.5.46
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 +72 -20
- package/lib/cjs/app/IApp.d.ts +9 -5
- package/lib/cjs/erp/AuthApi.d.ts +8 -2
- package/lib/cjs/erp/AuthApi.js +10 -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 +72 -20
- package/lib/mjs/app/IApp.d.ts +9 -5
- package/lib/mjs/erp/AuthApi.d.ts +8 -2
- package/lib/mjs/erp/AuthApi.js +10 -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 +82 -22
- package/src/app/IApp.ts +10 -5
- package/src/erp/AuthApi.ts +12 -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,11 +572,11 @@ 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
|
*/
|
|
580
|
-
refreshToken(props
|
|
579
|
+
refreshToken(props: RefreshTokenProps, callback?: (result?: boolean | IActionResult) => boolean | void): Promise<void>;
|
|
581
580
|
/**
|
|
582
581
|
* Setup callback
|
|
583
582
|
*/
|
|
@@ -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,72 @@ 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
|
+
// Call refresh token API
|
|
1361
|
+
let data = await new AuthApi_1.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
|
+
}
|
|
1364
1421
|
/**
|
|
1365
1422
|
* Setup callback
|
|
1366
1423
|
*/
|
|
@@ -1587,21 +1644,16 @@ class CoreApp {
|
|
|
1587
1644
|
* User login
|
|
1588
1645
|
* @param user User data
|
|
1589
1646
|
* @param refreshToken Refresh token
|
|
1590
|
-
* @param keep Keep login or not
|
|
1591
1647
|
*/
|
|
1592
|
-
userLogin(user, refreshToken
|
|
1648
|
+
userLogin(user, refreshToken) {
|
|
1649
|
+
// Hold the user data
|
|
1593
1650
|
this.userData = user;
|
|
1594
1651
|
// Cache the encrypted serverside device id
|
|
1595
1652
|
if (user.deviceId) {
|
|
1596
1653
|
this.storage.setData(this.fields.serversideDeviceId, user.deviceId);
|
|
1597
1654
|
}
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
}
|
|
1601
|
-
else {
|
|
1602
|
-
this.cachedRefreshToken = this.encrypt(refreshToken);
|
|
1603
|
-
this.authorize(user.token, user.tokenScheme, undefined);
|
|
1604
|
-
}
|
|
1655
|
+
// Authorize
|
|
1656
|
+
this.authorize(user.token, user.tokenScheme, refreshToken);
|
|
1605
1657
|
}
|
|
1606
1658
|
/**
|
|
1607
1659
|
* 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
|
*/
|
|
@@ -61,6 +61,10 @@ export type AppLoginParams = DataTypes.SimpleObject & {
|
|
|
61
61
|
* Refresh token props
|
|
62
62
|
*/
|
|
63
63
|
export interface RefreshTokenProps {
|
|
64
|
+
/**
|
|
65
|
+
* Refresh token
|
|
66
|
+
*/
|
|
67
|
+
token: string;
|
|
64
68
|
/**
|
|
65
69
|
* API name
|
|
66
70
|
*/
|
|
@@ -515,11 +519,12 @@ 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
|
-
refreshToken(props
|
|
527
|
+
refreshToken(props: RefreshTokenProps, callback?: (result?: boolean | IActionResult) => boolean | void): Promise<void>;
|
|
523
528
|
/**
|
|
524
529
|
* Setup Api error handler
|
|
525
530
|
* @param api Api
|
|
@@ -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,12 @@ 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 ?? {};
|
|
77
76
|
// Reqest data
|
|
78
77
|
const rq = {
|
|
79
78
|
deviceId: this.app.deviceId
|
|
@@ -102,15 +101,6 @@ class AuthApi extends BaseApi_1.BaseApi {
|
|
|
102
101
|
}
|
|
103
102
|
// Token
|
|
104
103
|
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
104
|
// Success
|
|
115
105
|
return [refreshToken, result];
|
|
116
106
|
}
|
|
@@ -132,6 +122,14 @@ class AuthApi extends BaseApi_1.BaseApi {
|
|
|
132
122
|
signout(rq, payload) {
|
|
133
123
|
return this.api.put('Auth/Signout', rq, payload);
|
|
134
124
|
}
|
|
125
|
+
/**
|
|
126
|
+
* Switch organization
|
|
127
|
+
* @param rq Request data
|
|
128
|
+
* @param payload Payload
|
|
129
|
+
*/
|
|
130
|
+
switchOrg(rq, payload) {
|
|
131
|
+
return this.app.api.put('Auth/SwitchOrg', rq, payload);
|
|
132
|
+
}
|
|
135
133
|
}
|
|
136
134
|
exports.AuthApi = AuthApi;
|
|
137
135
|
/**
|
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,11 +572,11 @@ 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
|
*/
|
|
580
|
-
refreshToken(props
|
|
579
|
+
refreshToken(props: RefreshTokenProps, callback?: (result?: boolean | IActionResult) => boolean | void): Promise<void>;
|
|
581
580
|
/**
|
|
582
581
|
* Setup callback
|
|
583
582
|
*/
|
|
@@ -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,72 @@ 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
|
+
// Call refresh token API
|
|
1358
|
+
let data = await new AuthApi(this).refreshToken(props);
|
|
1359
|
+
let r;
|
|
1360
|
+
if (Array.isArray(data)) {
|
|
1361
|
+
const [token, result] = data;
|
|
1362
|
+
if (result.ok) {
|
|
1363
|
+
if (!token) {
|
|
1364
|
+
data = {
|
|
1365
|
+
ok: false,
|
|
1366
|
+
type: 'noData',
|
|
1367
|
+
field: 'token',
|
|
1368
|
+
title: this.get('noData')
|
|
1369
|
+
};
|
|
1370
|
+
}
|
|
1371
|
+
else if (result.data == null) {
|
|
1372
|
+
data = {
|
|
1373
|
+
ok: false,
|
|
1374
|
+
type: 'noData',
|
|
1375
|
+
field: 'user',
|
|
1376
|
+
title: this.get('noData')
|
|
1377
|
+
};
|
|
1378
|
+
}
|
|
1379
|
+
else {
|
|
1380
|
+
// User login
|
|
1381
|
+
this.userLogin(result.data, token);
|
|
1382
|
+
if (callback)
|
|
1383
|
+
callback(true);
|
|
1384
|
+
// Exit
|
|
1385
|
+
return;
|
|
1386
|
+
}
|
|
1387
|
+
}
|
|
1388
|
+
else if (this.checkDeviceResult(result)) {
|
|
1389
|
+
if (callback == null || callback(result) !== true) {
|
|
1390
|
+
this.initCall((ir) => {
|
|
1391
|
+
if (!ir)
|
|
1392
|
+
return;
|
|
1393
|
+
this.notifier.alert(this.get('environmentChanged') ??
|
|
1394
|
+
'Environment changed', () => {
|
|
1395
|
+
// Callback, return true to prevent the default reload action
|
|
1396
|
+
if (callback == null || callback() !== true) {
|
|
1397
|
+
// Reload the page
|
|
1398
|
+
history.go(0);
|
|
1399
|
+
}
|
|
1400
|
+
});
|
|
1401
|
+
}, true);
|
|
1402
|
+
return;
|
|
1403
|
+
}
|
|
1404
|
+
}
|
|
1405
|
+
r = result;
|
|
1406
|
+
}
|
|
1407
|
+
else {
|
|
1408
|
+
r = data;
|
|
1409
|
+
}
|
|
1410
|
+
if (callback == null || callback(r) !== true) {
|
|
1411
|
+
const message = `${r.title} (${r.field})`;
|
|
1412
|
+
this.notifier.alert(message, () => {
|
|
1413
|
+
if (callback)
|
|
1414
|
+
callback(false);
|
|
1415
|
+
});
|
|
1416
|
+
}
|
|
1417
|
+
}
|
|
1361
1418
|
/**
|
|
1362
1419
|
* Setup callback
|
|
1363
1420
|
*/
|
|
@@ -1584,21 +1641,16 @@ export class CoreApp {
|
|
|
1584
1641
|
* User login
|
|
1585
1642
|
* @param user User data
|
|
1586
1643
|
* @param refreshToken Refresh token
|
|
1587
|
-
* @param keep Keep login or not
|
|
1588
1644
|
*/
|
|
1589
|
-
userLogin(user, refreshToken
|
|
1645
|
+
userLogin(user, refreshToken) {
|
|
1646
|
+
// Hold the user data
|
|
1590
1647
|
this.userData = user;
|
|
1591
1648
|
// Cache the encrypted serverside device id
|
|
1592
1649
|
if (user.deviceId) {
|
|
1593
1650
|
this.storage.setData(this.fields.serversideDeviceId, user.deviceId);
|
|
1594
1651
|
}
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
}
|
|
1598
|
-
else {
|
|
1599
|
-
this.cachedRefreshToken = this.encrypt(refreshToken);
|
|
1600
|
-
this.authorize(user.token, user.tokenScheme, undefined);
|
|
1601
|
-
}
|
|
1652
|
+
// Authorize
|
|
1653
|
+
this.authorize(user.token, user.tokenScheme, refreshToken);
|
|
1602
1654
|
}
|
|
1603
1655
|
/**
|
|
1604
1656
|
* 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
|
*/
|
|
@@ -61,6 +61,10 @@ export type AppLoginParams = DataTypes.SimpleObject & {
|
|
|
61
61
|
* Refresh token props
|
|
62
62
|
*/
|
|
63
63
|
export interface RefreshTokenProps {
|
|
64
|
+
/**
|
|
65
|
+
* Refresh token
|
|
66
|
+
*/
|
|
67
|
+
token: string;
|
|
64
68
|
/**
|
|
65
69
|
* API name
|
|
66
70
|
*/
|
|
@@ -515,11 +519,12 @@ 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
|
-
refreshToken(props
|
|
527
|
+
refreshToken(props: RefreshTokenProps, callback?: (result?: boolean | IActionResult) => boolean | void): Promise<void>;
|
|
523
528
|
/**
|
|
524
529
|
* Setup Api error handler
|
|
525
530
|
* @param api Api
|
|
@@ -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,12 @@ 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 ?? {};
|
|
74
73
|
// Reqest data
|
|
75
74
|
const rq = {
|
|
76
75
|
deviceId: this.app.deviceId
|
|
@@ -99,15 +98,6 @@ export class AuthApi extends BaseApi {
|
|
|
99
98
|
}
|
|
100
99
|
// Token
|
|
101
100
|
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
101
|
// Success
|
|
112
102
|
return [refreshToken, result];
|
|
113
103
|
}
|
|
@@ -129,6 +119,14 @@ export class AuthApi extends BaseApi {
|
|
|
129
119
|
signout(rq, payload) {
|
|
130
120
|
return this.api.put('Auth/Signout', rq, payload);
|
|
131
121
|
}
|
|
122
|
+
/**
|
|
123
|
+
* Switch organization
|
|
124
|
+
* @param rq Request data
|
|
125
|
+
* @param payload Payload
|
|
126
|
+
*/
|
|
127
|
+
switchOrg(rq, payload) {
|
|
128
|
+
return this.app.api.put('Auth/SwitchOrg', rq, payload);
|
|
129
|
+
}
|
|
132
130
|
}
|
|
133
131
|
/**
|
|
134
132
|
* 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,78 @@ 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
|
-
props
|
|
1891
|
+
props: RefreshTokenProps,
|
|
1892
1892
|
callback?: (result?: boolean | IActionResult) => boolean | void
|
|
1893
|
-
) {
|
|
1893
|
+
) {
|
|
1894
|
+
// Call refresh token API
|
|
1895
|
+
let data = await new AuthApi(this).refreshToken<IActionResult<U>>(
|
|
1896
|
+
props
|
|
1897
|
+
);
|
|
1898
|
+
|
|
1899
|
+
let r: IActionResult;
|
|
1900
|
+
if (Array.isArray(data)) {
|
|
1901
|
+
const [token, result] = data;
|
|
1902
|
+
if (result.ok) {
|
|
1903
|
+
if (!token) {
|
|
1904
|
+
data = {
|
|
1905
|
+
ok: false,
|
|
1906
|
+
type: 'noData',
|
|
1907
|
+
field: 'token',
|
|
1908
|
+
title: this.get('noData')
|
|
1909
|
+
};
|
|
1910
|
+
} else if (result.data == null) {
|
|
1911
|
+
data = {
|
|
1912
|
+
ok: false,
|
|
1913
|
+
type: 'noData',
|
|
1914
|
+
field: 'user',
|
|
1915
|
+
title: this.get('noData')
|
|
1916
|
+
};
|
|
1917
|
+
} else {
|
|
1918
|
+
// User login
|
|
1919
|
+
this.userLogin(result.data, token);
|
|
1920
|
+
|
|
1921
|
+
if (callback) callback(true);
|
|
1922
|
+
|
|
1923
|
+
// Exit
|
|
1924
|
+
return;
|
|
1925
|
+
}
|
|
1926
|
+
} else if (this.checkDeviceResult(result)) {
|
|
1927
|
+
if (callback == null || callback(result) !== true) {
|
|
1928
|
+
this.initCall((ir) => {
|
|
1929
|
+
if (!ir) return;
|
|
1930
|
+
this.notifier.alert(
|
|
1931
|
+
this.get('environmentChanged') ??
|
|
1932
|
+
'Environment changed',
|
|
1933
|
+
() => {
|
|
1934
|
+
// Callback, return true to prevent the default reload action
|
|
1935
|
+
if (callback == null || callback() !== true) {
|
|
1936
|
+
// Reload the page
|
|
1937
|
+
history.go(0);
|
|
1938
|
+
}
|
|
1939
|
+
}
|
|
1940
|
+
);
|
|
1941
|
+
}, true);
|
|
1942
|
+
return;
|
|
1943
|
+
}
|
|
1944
|
+
}
|
|
1945
|
+
|
|
1946
|
+
r = result;
|
|
1947
|
+
} else {
|
|
1948
|
+
r = data;
|
|
1949
|
+
}
|
|
1950
|
+
|
|
1951
|
+
if (callback == null || callback(r) !== true) {
|
|
1952
|
+
const message = `${r.title} (${r.field})`;
|
|
1953
|
+
this.notifier.alert(message, () => {
|
|
1954
|
+
if (callback) callback(false);
|
|
1955
|
+
});
|
|
1956
|
+
}
|
|
1957
|
+
}
|
|
1894
1958
|
|
|
1895
1959
|
/**
|
|
1896
1960
|
* Setup callback
|
|
@@ -2171,9 +2235,9 @@ export abstract class CoreApp<
|
|
|
2171
2235
|
* User login
|
|
2172
2236
|
* @param user User data
|
|
2173
2237
|
* @param refreshToken Refresh token
|
|
2174
|
-
* @param keep Keep login or not
|
|
2175
2238
|
*/
|
|
2176
|
-
userLogin(user: U, refreshToken: string
|
|
2239
|
+
userLogin(user: U, refreshToken: string) {
|
|
2240
|
+
// Hold the user data
|
|
2177
2241
|
this.userData = user;
|
|
2178
2242
|
|
|
2179
2243
|
// Cache the encrypted serverside device id
|
|
@@ -2181,12 +2245,8 @@ export abstract class CoreApp<
|
|
|
2181
2245
|
this.storage.setData(this.fields.serversideDeviceId, user.deviceId);
|
|
2182
2246
|
}
|
|
2183
2247
|
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
} else {
|
|
2187
|
-
this.cachedRefreshToken = this.encrypt(refreshToken);
|
|
2188
|
-
this.authorize(user.token, user.tokenScheme, undefined);
|
|
2189
|
-
}
|
|
2248
|
+
// Authorize
|
|
2249
|
+
this.authorize(user.token, user.tokenScheme, refreshToken);
|
|
2190
2250
|
}
|
|
2191
2251
|
|
|
2192
2252
|
/**
|
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
|
|
@@ -87,6 +87,11 @@ export type AppLoginParams = DataTypes.SimpleObject & {
|
|
|
87
87
|
* Refresh token props
|
|
88
88
|
*/
|
|
89
89
|
export interface RefreshTokenProps {
|
|
90
|
+
/**
|
|
91
|
+
* Refresh token
|
|
92
|
+
*/
|
|
93
|
+
token: string;
|
|
94
|
+
|
|
90
95
|
/**
|
|
91
96
|
* API name
|
|
92
97
|
*/
|
|
@@ -695,12 +700,13 @@ 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
|
-
props
|
|
709
|
+
props: RefreshTokenProps,
|
|
704
710
|
callback?: (result?: boolean | IActionResult) => boolean | void
|
|
705
711
|
): Promise<void>;
|
|
706
712
|
|
|
@@ -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,18 +92,17 @@ 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
|
|
|
@@ -141,16 +141,6 @@ export class AuthApi extends BaseApi {
|
|
|
141
141
|
tokenField
|
|
142
142
|
);
|
|
143
143
|
|
|
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
144
|
// Success
|
|
155
145
|
return [refreshToken, result];
|
|
156
146
|
}
|
|
@@ -174,4 +164,13 @@ export class AuthApi extends BaseApi {
|
|
|
174
164
|
signout(rq: SignoutRQ, payload?: ResultPayload) {
|
|
175
165
|
return this.api.put('Auth/Signout', rq, payload);
|
|
176
166
|
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Switch organization
|
|
170
|
+
* @param rq Request data
|
|
171
|
+
* @param payload Payload
|
|
172
|
+
*/
|
|
173
|
+
switchOrg(rq: SwitchOrgRQ, payload?: ResultPayload) {
|
|
174
|
+
return this.app.api.put('Auth/SwitchOrg', rq, payload);
|
|
175
|
+
}
|
|
177
176
|
}
|
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';
|