@etsoo/appscript 1.5.43 → 1.5.45
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 -8
- package/lib/cjs/app/CoreApp.js +7 -24
- package/lib/cjs/app/IApp.d.ts +3 -7
- package/lib/cjs/erp/AuthApi.d.ts +4 -0
- package/lib/cjs/erp/AuthApi.js +23 -2
- package/lib/cjs/index.d.ts +1 -1
- package/lib/cjs/index.js +2 -1
- package/lib/mjs/app/CoreApp.d.ts +3 -8
- package/lib/mjs/app/CoreApp.js +8 -25
- package/lib/mjs/app/IApp.d.ts +3 -7
- package/lib/mjs/erp/AuthApi.d.ts +4 -0
- package/lib/mjs/erp/AuthApi.js +23 -2
- package/lib/mjs/index.d.ts +1 -1
- package/lib/mjs/index.js +1 -1
- package/package.json +1 -1
- package/src/app/CoreApp.ts +11 -30
- package/src/app/IApp.ts +6 -8
- package/src/erp/AuthApi.ts +25 -3
- package/src/index.ts +1 -0
package/lib/cjs/app/CoreApp.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ import { InitCallDto } from '../erp/dto/InitCallDto';
|
|
|
7
7
|
import { InitCallResult, InitCallResultData } from '../result/InitCallResult';
|
|
8
8
|
import { IUser } from '../state/User';
|
|
9
9
|
import { IAppSettings } from './AppSettings';
|
|
10
|
-
import { AppLoginParams, FormatResultCustomCallback, IApp, IAppFields, IDetectIPCallback, NavigateOptions, RefreshTokenProps
|
|
10
|
+
import { AppLoginParams, FormatResultCustomCallback, IApp, IAppFields, IDetectIPCallback, NavigateOptions, RefreshTokenProps } from './IApp';
|
|
11
11
|
import { UserRole } from './UserRole';
|
|
12
12
|
import { ExternalEndpoint } from './ExternalSettings';
|
|
13
13
|
import { ApiRefreshTokenDto } from '../erp/dto/ApiRefreshTokenDto';
|
|
@@ -426,12 +426,6 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
|
|
|
426
426
|
* @param givenName Given name
|
|
427
427
|
*/
|
|
428
428
|
formatFullName(familyName: string | undefined | null, givenName: string | undefined | null): string;
|
|
429
|
-
/**
|
|
430
|
-
* Format refresh token result
|
|
431
|
-
* @param result Refresh token result
|
|
432
|
-
* @returns Message
|
|
433
|
-
*/
|
|
434
|
-
protected formatRefreshTokenResult(result: RefreshTokenResult<IActionResult<U>>): string | undefined;
|
|
435
429
|
private getFieldLabel;
|
|
436
430
|
/**
|
|
437
431
|
* Format result text
|
|
@@ -581,8 +575,9 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
|
|
|
581
575
|
/**
|
|
582
576
|
* Refresh token
|
|
583
577
|
* @param props Props
|
|
578
|
+
* @param callback Callback
|
|
584
579
|
*/
|
|
585
|
-
refreshToken(props?: RefreshTokenProps): Promise<void>;
|
|
580
|
+
refreshToken(props?: RefreshTokenProps, callback?: (result?: boolean | IActionResult) => boolean | void): Promise<void>;
|
|
586
581
|
/**
|
|
587
582
|
* Setup callback
|
|
588
583
|
*/
|
package/lib/cjs/app/CoreApp.js
CHANGED
|
@@ -165,7 +165,11 @@ class CoreApp {
|
|
|
165
165
|
const refresh = async (api, token) => {
|
|
166
166
|
if (this.lastCalled) {
|
|
167
167
|
// Call refreshToken to update access token
|
|
168
|
-
|
|
168
|
+
// No popups show
|
|
169
|
+
await this.refreshToken({ showLoading: false }, (result) => {
|
|
170
|
+
console.log(`CoreApp.${this.name}.ApiRefreshToken`, result);
|
|
171
|
+
return false;
|
|
172
|
+
});
|
|
169
173
|
}
|
|
170
174
|
else {
|
|
171
175
|
// Popup countdown for user action
|
|
@@ -1020,28 +1024,6 @@ class CoreApp {
|
|
|
1020
1024
|
}
|
|
1021
1025
|
return wf;
|
|
1022
1026
|
}
|
|
1023
|
-
/**
|
|
1024
|
-
* Format refresh token result
|
|
1025
|
-
* @param result Refresh token result
|
|
1026
|
-
* @returns Message
|
|
1027
|
-
*/
|
|
1028
|
-
formatRefreshTokenResult(result) {
|
|
1029
|
-
// Error message
|
|
1030
|
-
if (typeof result === 'string')
|
|
1031
|
-
return result;
|
|
1032
|
-
// API error
|
|
1033
|
-
if (result instanceof restclient_1.ApiDataError)
|
|
1034
|
-
return this.formatError(result);
|
|
1035
|
-
// Action result
|
|
1036
|
-
const [token, r] = result;
|
|
1037
|
-
// Success
|
|
1038
|
-
if (r.ok)
|
|
1039
|
-
return undefined;
|
|
1040
|
-
// No token data
|
|
1041
|
-
if (token == null)
|
|
1042
|
-
return `${this.get('noData')} (token)`;
|
|
1043
|
-
return ActionResultError_1.ActionResultError.format(r);
|
|
1044
|
-
}
|
|
1045
1027
|
getFieldLabel(field) {
|
|
1046
1028
|
return this.get(field.formatInitial(false)) ?? field;
|
|
1047
1029
|
}
|
|
@@ -1376,8 +1358,9 @@ class CoreApp {
|
|
|
1376
1358
|
/**
|
|
1377
1359
|
* Refresh token
|
|
1378
1360
|
* @param props Props
|
|
1361
|
+
* @param callback Callback
|
|
1379
1362
|
*/
|
|
1380
|
-
async refreshToken(props) { }
|
|
1363
|
+
async refreshToken(props, callback) { }
|
|
1381
1364
|
/**
|
|
1382
1365
|
* Setup callback
|
|
1383
1366
|
*/
|
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> =
|
|
30
|
+
export type RefreshTokenResult<R> = IActionResult | [string, R];
|
|
31
31
|
/**
|
|
32
32
|
* Format result custom type
|
|
33
33
|
*/
|
|
@@ -65,11 +65,6 @@ export interface RefreshTokenProps {
|
|
|
65
65
|
* API name
|
|
66
66
|
*/
|
|
67
67
|
api?: string;
|
|
68
|
-
/**
|
|
69
|
-
* Callback
|
|
70
|
-
* @param result Result
|
|
71
|
-
*/
|
|
72
|
-
callback?: (result: boolean) => void;
|
|
73
68
|
/**
|
|
74
69
|
* Show loading bar or not
|
|
75
70
|
*/
|
|
@@ -522,8 +517,9 @@ export interface IApp {
|
|
|
522
517
|
/**
|
|
523
518
|
* Refresh token
|
|
524
519
|
* @param props Props
|
|
520
|
+
* @param callback Callback
|
|
525
521
|
*/
|
|
526
|
-
refreshToken(props?: RefreshTokenProps): Promise<void>;
|
|
522
|
+
refreshToken(props?: RefreshTokenProps, callback?: (result?: boolean | IActionResult) => boolean | void): Promise<void>;
|
|
527
523
|
/**
|
|
528
524
|
* Setup Api error handler
|
|
529
525
|
* @param api Api
|
package/lib/cjs/erp/AuthApi.d.ts
CHANGED
|
@@ -14,6 +14,10 @@ import { RefreshTokenProps, RefreshTokenResult } from '../app/IApp';
|
|
|
14
14
|
* Authentication API
|
|
15
15
|
*/
|
|
16
16
|
export declare class AuthApi extends BaseApi {
|
|
17
|
+
/**
|
|
18
|
+
* Header token field name
|
|
19
|
+
*/
|
|
20
|
+
static HeaderTokenField: string;
|
|
17
21
|
/**
|
|
18
22
|
* API refresh token
|
|
19
23
|
* @param rq Request data
|
package/lib/cjs/erp/AuthApi.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AuthApi = void 0;
|
|
4
4
|
const BaseApi_1 = require("./BaseApi");
|
|
5
|
+
const shared_1 = require("@etsoo/shared");
|
|
5
6
|
/**
|
|
6
7
|
* Authentication API
|
|
7
8
|
*/
|
|
@@ -72,7 +73,7 @@ class AuthApi extends BaseApi_1.BaseApi {
|
|
|
72
73
|
*/
|
|
73
74
|
async refreshToken(token, props) {
|
|
74
75
|
// Destruct
|
|
75
|
-
const { api = 'Auth/RefreshToken', showLoading = false, tokenField =
|
|
76
|
+
const { api = 'Auth/RefreshToken', showLoading = false, tokenField = AuthApi.HeaderTokenField } = props ?? {};
|
|
76
77
|
// Reqest data
|
|
77
78
|
const rq = {
|
|
78
79
|
deviceId: this.app.deviceId
|
|
@@ -90,10 +91,26 @@ class AuthApi extends BaseApi_1.BaseApi {
|
|
|
90
91
|
// Call API
|
|
91
92
|
const result = await this.api.put(api, rq, payload);
|
|
92
93
|
if (result == null) {
|
|
93
|
-
return this.api.lastError
|
|
94
|
+
return this.api.lastError
|
|
95
|
+
? shared_1.ActionResult.create(this.api.lastError)
|
|
96
|
+
: {
|
|
97
|
+
ok: false,
|
|
98
|
+
type: 'unknownError',
|
|
99
|
+
field: 'result',
|
|
100
|
+
title: this.app.get('unknownError')
|
|
101
|
+
};
|
|
94
102
|
}
|
|
95
103
|
// Token
|
|
96
104
|
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
|
+
}
|
|
97
114
|
// Success
|
|
98
115
|
return [refreshToken, result];
|
|
99
116
|
}
|
|
@@ -117,3 +134,7 @@ class AuthApi extends BaseApi_1.BaseApi {
|
|
|
117
134
|
}
|
|
118
135
|
}
|
|
119
136
|
exports.AuthApi = AuthApi;
|
|
137
|
+
/**
|
|
138
|
+
* Header token field name
|
|
139
|
+
*/
|
|
140
|
+
AuthApi.HeaderTokenField = 'Etsoo-Refresh-Token';
|
package/lib/cjs/index.d.ts
CHANGED
|
@@ -75,7 +75,7 @@ export * from './i18n/CultureUtils';
|
|
|
75
75
|
export * from './i18n/en';
|
|
76
76
|
export * from './i18n/zhHans';
|
|
77
77
|
export * from './i18n/zhHant';
|
|
78
|
-
export { ApiAuthorizationScheme, ApiMethod, ApiResponseType, createClient, createClientAsync } from '@etsoo/restclient';
|
|
78
|
+
export { ApiAuthorizationScheme, ApiDataError, ApiMethod, ApiResponseType, createClient, createClientAsync } from '@etsoo/restclient';
|
|
79
79
|
export type { IApi, IApiPayload } from '@etsoo/restclient';
|
|
80
80
|
export * from './result/ActionResult';
|
|
81
81
|
export * from './result/ActionResultError';
|
package/lib/cjs/index.js
CHANGED
|
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.createClientAsync = exports.createClient = exports.ApiResponseType = exports.ApiMethod = exports.ApiAuthorizationScheme = void 0;
|
|
17
|
+
exports.createClientAsync = exports.createClient = exports.ApiResponseType = exports.ApiMethod = exports.ApiDataError = exports.ApiAuthorizationScheme = void 0;
|
|
18
18
|
// address
|
|
19
19
|
__exportStar(require("./address/AddressAutocomplete"), exports);
|
|
20
20
|
__exportStar(require("./address/AddressCity"), exports);
|
|
@@ -105,6 +105,7 @@ __exportStar(require("./i18n/zhHant"), exports);
|
|
|
105
105
|
// @etsoo/restclient
|
|
106
106
|
var restclient_1 = require("@etsoo/restclient");
|
|
107
107
|
Object.defineProperty(exports, "ApiAuthorizationScheme", { enumerable: true, get: function () { return restclient_1.ApiAuthorizationScheme; } });
|
|
108
|
+
Object.defineProperty(exports, "ApiDataError", { enumerable: true, get: function () { return restclient_1.ApiDataError; } });
|
|
108
109
|
Object.defineProperty(exports, "ApiMethod", { enumerable: true, get: function () { return restclient_1.ApiMethod; } });
|
|
109
110
|
Object.defineProperty(exports, "ApiResponseType", { enumerable: true, get: function () { return restclient_1.ApiResponseType; } });
|
|
110
111
|
Object.defineProperty(exports, "createClient", { enumerable: true, get: function () { return restclient_1.createClient; } });
|
package/lib/mjs/app/CoreApp.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ import { InitCallDto } from '../erp/dto/InitCallDto';
|
|
|
7
7
|
import { InitCallResult, InitCallResultData } from '../result/InitCallResult';
|
|
8
8
|
import { IUser } from '../state/User';
|
|
9
9
|
import { IAppSettings } from './AppSettings';
|
|
10
|
-
import { AppLoginParams, FormatResultCustomCallback, IApp, IAppFields, IDetectIPCallback, NavigateOptions, RefreshTokenProps
|
|
10
|
+
import { AppLoginParams, FormatResultCustomCallback, IApp, IAppFields, IDetectIPCallback, NavigateOptions, RefreshTokenProps } from './IApp';
|
|
11
11
|
import { UserRole } from './UserRole';
|
|
12
12
|
import { ExternalEndpoint } from './ExternalSettings';
|
|
13
13
|
import { ApiRefreshTokenDto } from '../erp/dto/ApiRefreshTokenDto';
|
|
@@ -426,12 +426,6 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
|
|
|
426
426
|
* @param givenName Given name
|
|
427
427
|
*/
|
|
428
428
|
formatFullName(familyName: string | undefined | null, givenName: string | undefined | null): string;
|
|
429
|
-
/**
|
|
430
|
-
* Format refresh token result
|
|
431
|
-
* @param result Refresh token result
|
|
432
|
-
* @returns Message
|
|
433
|
-
*/
|
|
434
|
-
protected formatRefreshTokenResult(result: RefreshTokenResult<IActionResult<U>>): string | undefined;
|
|
435
429
|
private getFieldLabel;
|
|
436
430
|
/**
|
|
437
431
|
* Format result text
|
|
@@ -581,8 +575,9 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
|
|
|
581
575
|
/**
|
|
582
576
|
* Refresh token
|
|
583
577
|
* @param props Props
|
|
578
|
+
* @param callback Callback
|
|
584
579
|
*/
|
|
585
|
-
refreshToken(props?: RefreshTokenProps): Promise<void>;
|
|
580
|
+
refreshToken(props?: RefreshTokenProps, callback?: (result?: boolean | IActionResult) => boolean | void): Promise<void>;
|
|
586
581
|
/**
|
|
587
582
|
* Setup callback
|
|
588
583
|
*/
|
package/lib/mjs/app/CoreApp.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { NotificationAlign, NotificationMessageType } from '@etsoo/notificationbase';
|
|
2
|
-
import {
|
|
2
|
+
import { createClient } from '@etsoo/restclient';
|
|
3
3
|
import { DataTypes, DateUtils, DomUtils, ExtendUtils, NumberUtils, Utils } from '@etsoo/shared';
|
|
4
4
|
import { AddressRegion } from '../address/AddressRegion';
|
|
5
5
|
import { BridgeUtils } from '../bridges/BridgeUtils';
|
|
@@ -162,7 +162,11 @@ export class CoreApp {
|
|
|
162
162
|
const refresh = async (api, token) => {
|
|
163
163
|
if (this.lastCalled) {
|
|
164
164
|
// Call refreshToken to update access token
|
|
165
|
-
|
|
165
|
+
// No popups show
|
|
166
|
+
await this.refreshToken({ showLoading: false }, (result) => {
|
|
167
|
+
console.log(`CoreApp.${this.name}.ApiRefreshToken`, result);
|
|
168
|
+
return false;
|
|
169
|
+
});
|
|
166
170
|
}
|
|
167
171
|
else {
|
|
168
172
|
// Popup countdown for user action
|
|
@@ -1017,28 +1021,6 @@ export class CoreApp {
|
|
|
1017
1021
|
}
|
|
1018
1022
|
return wf;
|
|
1019
1023
|
}
|
|
1020
|
-
/**
|
|
1021
|
-
* Format refresh token result
|
|
1022
|
-
* @param result Refresh token result
|
|
1023
|
-
* @returns Message
|
|
1024
|
-
*/
|
|
1025
|
-
formatRefreshTokenResult(result) {
|
|
1026
|
-
// Error message
|
|
1027
|
-
if (typeof result === 'string')
|
|
1028
|
-
return result;
|
|
1029
|
-
// API error
|
|
1030
|
-
if (result instanceof ApiDataError)
|
|
1031
|
-
return this.formatError(result);
|
|
1032
|
-
// Action result
|
|
1033
|
-
const [token, r] = result;
|
|
1034
|
-
// Success
|
|
1035
|
-
if (r.ok)
|
|
1036
|
-
return undefined;
|
|
1037
|
-
// No token data
|
|
1038
|
-
if (token == null)
|
|
1039
|
-
return `${this.get('noData')} (token)`;
|
|
1040
|
-
return ActionResultError.format(r);
|
|
1041
|
-
}
|
|
1042
1024
|
getFieldLabel(field) {
|
|
1043
1025
|
return this.get(field.formatInitial(false)) ?? field;
|
|
1044
1026
|
}
|
|
@@ -1373,8 +1355,9 @@ export class CoreApp {
|
|
|
1373
1355
|
/**
|
|
1374
1356
|
* Refresh token
|
|
1375
1357
|
* @param props Props
|
|
1358
|
+
* @param callback Callback
|
|
1376
1359
|
*/
|
|
1377
|
-
async refreshToken(props) { }
|
|
1360
|
+
async refreshToken(props, callback) { }
|
|
1378
1361
|
/**
|
|
1379
1362
|
* Setup callback
|
|
1380
1363
|
*/
|
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> =
|
|
30
|
+
export type RefreshTokenResult<R> = IActionResult | [string, R];
|
|
31
31
|
/**
|
|
32
32
|
* Format result custom type
|
|
33
33
|
*/
|
|
@@ -65,11 +65,6 @@ export interface RefreshTokenProps {
|
|
|
65
65
|
* API name
|
|
66
66
|
*/
|
|
67
67
|
api?: string;
|
|
68
|
-
/**
|
|
69
|
-
* Callback
|
|
70
|
-
* @param result Result
|
|
71
|
-
*/
|
|
72
|
-
callback?: (result: boolean) => void;
|
|
73
68
|
/**
|
|
74
69
|
* Show loading bar or not
|
|
75
70
|
*/
|
|
@@ -522,8 +517,9 @@ export interface IApp {
|
|
|
522
517
|
/**
|
|
523
518
|
* Refresh token
|
|
524
519
|
* @param props Props
|
|
520
|
+
* @param callback Callback
|
|
525
521
|
*/
|
|
526
|
-
refreshToken(props?: RefreshTokenProps): Promise<void>;
|
|
522
|
+
refreshToken(props?: RefreshTokenProps, callback?: (result?: boolean | IActionResult) => boolean | void): Promise<void>;
|
|
527
523
|
/**
|
|
528
524
|
* Setup Api error handler
|
|
529
525
|
* @param api Api
|
package/lib/mjs/erp/AuthApi.d.ts
CHANGED
|
@@ -14,6 +14,10 @@ import { RefreshTokenProps, RefreshTokenResult } from '../app/IApp';
|
|
|
14
14
|
* Authentication API
|
|
15
15
|
*/
|
|
16
16
|
export declare class AuthApi extends BaseApi {
|
|
17
|
+
/**
|
|
18
|
+
* Header token field name
|
|
19
|
+
*/
|
|
20
|
+
static HeaderTokenField: string;
|
|
17
21
|
/**
|
|
18
22
|
* API refresh token
|
|
19
23
|
* @param rq Request data
|
package/lib/mjs/erp/AuthApi.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { BaseApi } from './BaseApi';
|
|
2
|
+
import { ActionResult } from '@etsoo/shared';
|
|
2
3
|
/**
|
|
3
4
|
* Authentication API
|
|
4
5
|
*/
|
|
@@ -69,7 +70,7 @@ export class AuthApi extends BaseApi {
|
|
|
69
70
|
*/
|
|
70
71
|
async refreshToken(token, props) {
|
|
71
72
|
// Destruct
|
|
72
|
-
const { api = 'Auth/RefreshToken', showLoading = false, tokenField =
|
|
73
|
+
const { api = 'Auth/RefreshToken', showLoading = false, tokenField = AuthApi.HeaderTokenField } = props ?? {};
|
|
73
74
|
// Reqest data
|
|
74
75
|
const rq = {
|
|
75
76
|
deviceId: this.app.deviceId
|
|
@@ -87,10 +88,26 @@ export class AuthApi extends BaseApi {
|
|
|
87
88
|
// Call API
|
|
88
89
|
const result = await this.api.put(api, rq, payload);
|
|
89
90
|
if (result == null) {
|
|
90
|
-
return this.api.lastError
|
|
91
|
+
return this.api.lastError
|
|
92
|
+
? ActionResult.create(this.api.lastError)
|
|
93
|
+
: {
|
|
94
|
+
ok: false,
|
|
95
|
+
type: 'unknownError',
|
|
96
|
+
field: 'result',
|
|
97
|
+
title: this.app.get('unknownError')
|
|
98
|
+
};
|
|
91
99
|
}
|
|
92
100
|
// Token
|
|
93
101
|
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
|
+
}
|
|
94
111
|
// Success
|
|
95
112
|
return [refreshToken, result];
|
|
96
113
|
}
|
|
@@ -113,3 +130,7 @@ export class AuthApi extends BaseApi {
|
|
|
113
130
|
return this.api.put('Auth/Signout', rq, payload);
|
|
114
131
|
}
|
|
115
132
|
}
|
|
133
|
+
/**
|
|
134
|
+
* Header token field name
|
|
135
|
+
*/
|
|
136
|
+
AuthApi.HeaderTokenField = 'Etsoo-Refresh-Token';
|
package/lib/mjs/index.d.ts
CHANGED
|
@@ -75,7 +75,7 @@ export * from './i18n/CultureUtils';
|
|
|
75
75
|
export * from './i18n/en';
|
|
76
76
|
export * from './i18n/zhHans';
|
|
77
77
|
export * from './i18n/zhHant';
|
|
78
|
-
export { ApiAuthorizationScheme, ApiMethod, ApiResponseType, createClient, createClientAsync } from '@etsoo/restclient';
|
|
78
|
+
export { ApiAuthorizationScheme, ApiDataError, ApiMethod, ApiResponseType, createClient, createClientAsync } from '@etsoo/restclient';
|
|
79
79
|
export type { IApi, IApiPayload } from '@etsoo/restclient';
|
|
80
80
|
export * from './result/ActionResult';
|
|
81
81
|
export * from './result/ActionResultError';
|
package/lib/mjs/index.js
CHANGED
|
@@ -86,7 +86,7 @@ export * from './i18n/en';
|
|
|
86
86
|
export * from './i18n/zhHans';
|
|
87
87
|
export * from './i18n/zhHant';
|
|
88
88
|
// @etsoo/restclient
|
|
89
|
-
export { ApiAuthorizationScheme, ApiMethod, ApiResponseType, createClient, createClientAsync } from '@etsoo/restclient';
|
|
89
|
+
export { ApiAuthorizationScheme, ApiDataError, ApiMethod, ApiResponseType, createClient, createClientAsync } from '@etsoo/restclient';
|
|
90
90
|
// result
|
|
91
91
|
export * from './result/ActionResult';
|
|
92
92
|
export * from './result/ActionResultError';
|
package/package.json
CHANGED
package/src/app/CoreApp.ts
CHANGED
|
@@ -39,8 +39,7 @@ import {
|
|
|
39
39
|
IAppFields,
|
|
40
40
|
IDetectIPCallback,
|
|
41
41
|
NavigateOptions,
|
|
42
|
-
RefreshTokenProps
|
|
43
|
-
RefreshTokenResult
|
|
42
|
+
RefreshTokenProps
|
|
44
43
|
} from './IApp';
|
|
45
44
|
import { UserRole } from './UserRole';
|
|
46
45
|
import type CryptoJS from 'crypto-js';
|
|
@@ -332,7 +331,11 @@ export abstract class CoreApp<
|
|
|
332
331
|
const refresh: ApiRefreshTokenFunction = async (api, token) => {
|
|
333
332
|
if (this.lastCalled) {
|
|
334
333
|
// Call refreshToken to update access token
|
|
335
|
-
|
|
334
|
+
// No popups show
|
|
335
|
+
await this.refreshToken({ showLoading: false }, (result) => {
|
|
336
|
+
console.log(`CoreApp.${this.name}.ApiRefreshToken`, result);
|
|
337
|
+
return false;
|
|
338
|
+
});
|
|
336
339
|
} else {
|
|
337
340
|
// Popup countdown for user action
|
|
338
341
|
this.freshCountdownUI();
|
|
@@ -1494,32 +1497,6 @@ export abstract class CoreApp<
|
|
|
1494
1497
|
return wf;
|
|
1495
1498
|
}
|
|
1496
1499
|
|
|
1497
|
-
/**
|
|
1498
|
-
* Format refresh token result
|
|
1499
|
-
* @param result Refresh token result
|
|
1500
|
-
* @returns Message
|
|
1501
|
-
*/
|
|
1502
|
-
protected formatRefreshTokenResult(
|
|
1503
|
-
result: RefreshTokenResult<IActionResult<U>>
|
|
1504
|
-
): string | undefined {
|
|
1505
|
-
// Error message
|
|
1506
|
-
if (typeof result === 'string') return result;
|
|
1507
|
-
|
|
1508
|
-
// API error
|
|
1509
|
-
if (result instanceof ApiDataError) return this.formatError(result);
|
|
1510
|
-
|
|
1511
|
-
// Action result
|
|
1512
|
-
const [token, r] = result;
|
|
1513
|
-
|
|
1514
|
-
// Success
|
|
1515
|
-
if (r.ok) return undefined;
|
|
1516
|
-
|
|
1517
|
-
// No token data
|
|
1518
|
-
if (token == null) return `${this.get('noData')} (token)`;
|
|
1519
|
-
|
|
1520
|
-
return ActionResultError.format(r);
|
|
1521
|
-
}
|
|
1522
|
-
|
|
1523
1500
|
private getFieldLabel(field: string) {
|
|
1524
1501
|
return this.get(field.formatInitial(false)) ?? field;
|
|
1525
1502
|
}
|
|
@@ -1908,8 +1885,12 @@ export abstract class CoreApp<
|
|
|
1908
1885
|
/**
|
|
1909
1886
|
* Refresh token
|
|
1910
1887
|
* @param props Props
|
|
1888
|
+
* @param callback Callback
|
|
1911
1889
|
*/
|
|
1912
|
-
async refreshToken(
|
|
1890
|
+
async refreshToken(
|
|
1891
|
+
props?: RefreshTokenProps,
|
|
1892
|
+
callback?: (result?: boolean | IActionResult) => boolean | void
|
|
1893
|
+
) {}
|
|
1913
1894
|
|
|
1914
1895
|
/**
|
|
1915
1896
|
* Setup callback
|
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> =
|
|
48
|
+
export type RefreshTokenResult<R> = IActionResult | [string, R];
|
|
49
49
|
|
|
50
50
|
/**
|
|
51
51
|
* Format result custom type
|
|
@@ -92,12 +92,6 @@ export interface RefreshTokenProps {
|
|
|
92
92
|
*/
|
|
93
93
|
api?: string;
|
|
94
94
|
|
|
95
|
-
/**
|
|
96
|
-
* Callback
|
|
97
|
-
* @param result Result
|
|
98
|
-
*/
|
|
99
|
-
callback?: (result: boolean) => void;
|
|
100
|
-
|
|
101
95
|
/**
|
|
102
96
|
* Show loading bar or not
|
|
103
97
|
*/
|
|
@@ -703,8 +697,12 @@ export interface IApp {
|
|
|
703
697
|
/**
|
|
704
698
|
* Refresh token
|
|
705
699
|
* @param props Props
|
|
700
|
+
* @param callback Callback
|
|
706
701
|
*/
|
|
707
|
-
refreshToken(
|
|
702
|
+
refreshToken(
|
|
703
|
+
props?: RefreshTokenProps,
|
|
704
|
+
callback?: (result?: boolean | IActionResult) => boolean | void
|
|
705
|
+
): Promise<void>;
|
|
708
706
|
|
|
709
707
|
/**
|
|
710
708
|
* Setup Api error handler
|
package/src/erp/AuthApi.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { ResultPayload } from './dto/ResultPayload';
|
|
|
5
5
|
import { LoginIdRQ } from './rq/LoginIdRQ';
|
|
6
6
|
import { LoginRQ } from './rq/LoginRQ';
|
|
7
7
|
import { ResetPasswordRQ } from './rq/ResetPasswordRQ';
|
|
8
|
-
import { IActionResult } from '@etsoo/shared';
|
|
8
|
+
import { ActionResult, IActionResult } from '@etsoo/shared';
|
|
9
9
|
import { SignoutRQ } from './rq/SignoutRQ';
|
|
10
10
|
import { GetLogInUrlRQ } from './rq/GetLogInUrlRQ';
|
|
11
11
|
import { TokenRQ } from './rq/TokenRQ';
|
|
@@ -17,6 +17,11 @@ import { RefreshTokenRQ } from './rq/RefreshTokenRQ';
|
|
|
17
17
|
* Authentication API
|
|
18
18
|
*/
|
|
19
19
|
export class AuthApi extends BaseApi {
|
|
20
|
+
/**
|
|
21
|
+
* Header token field name
|
|
22
|
+
*/
|
|
23
|
+
static HeaderTokenField = 'Etsoo-Refresh-Token';
|
|
24
|
+
|
|
20
25
|
/**
|
|
21
26
|
* API refresh token
|
|
22
27
|
* @param rq Request data
|
|
@@ -98,7 +103,7 @@ export class AuthApi extends BaseApi {
|
|
|
98
103
|
const {
|
|
99
104
|
api = 'Auth/RefreshToken',
|
|
100
105
|
showLoading = false,
|
|
101
|
-
tokenField =
|
|
106
|
+
tokenField = AuthApi.HeaderTokenField
|
|
102
107
|
} = props ?? {};
|
|
103
108
|
|
|
104
109
|
// Reqest data
|
|
@@ -120,7 +125,14 @@ export class AuthApi extends BaseApi {
|
|
|
120
125
|
// Call API
|
|
121
126
|
const result = await this.api.put(api, rq, payload);
|
|
122
127
|
if (result == null) {
|
|
123
|
-
return this.api.lastError
|
|
128
|
+
return this.api.lastError
|
|
129
|
+
? ActionResult.create(this.api.lastError)
|
|
130
|
+
: {
|
|
131
|
+
ok: false,
|
|
132
|
+
type: 'unknownError',
|
|
133
|
+
field: 'result',
|
|
134
|
+
title: this.app.get('unknownError')
|
|
135
|
+
};
|
|
124
136
|
}
|
|
125
137
|
|
|
126
138
|
// Token
|
|
@@ -129,6 +141,16 @@ export class AuthApi extends BaseApi {
|
|
|
129
141
|
tokenField
|
|
130
142
|
);
|
|
131
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
|
+
|
|
132
154
|
// Success
|
|
133
155
|
return [refreshToken, result];
|
|
134
156
|
}
|