@etsoo/appscript 1.1.41 → 1.1.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/AppSettings.d.ts +4 -0
- package/lib/cjs/app/CoreApp.d.ts +11 -4
- package/lib/cjs/app/CoreApp.js +46 -37
- package/lib/cjs/app/ExternalSettings.d.ts +8 -0
- package/lib/cjs/index.d.ts +2 -0
- package/lib/cjs/index.js +5 -0
- package/lib/mjs/app/AppSettings.d.ts +4 -0
- package/lib/mjs/app/CoreApp.d.ts +11 -4
- package/lib/mjs/app/CoreApp.js +46 -37
- package/lib/mjs/app/ExternalSettings.d.ts +8 -0
- package/lib/mjs/index.d.ts +2 -0
- package/lib/mjs/index.js +2 -0
- package/package.json +8 -8
- package/src/app/AppSettings.ts +5 -0
- package/src/app/CoreApp.ts +39 -28
- package/src/app/ExternalSettings.ts +10 -0
- package/src/index.ts +4 -0
package/lib/cjs/app/CoreApp.d.ts
CHANGED
|
@@ -262,8 +262,14 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
|
|
|
262
262
|
get authorized(): boolean;
|
|
263
263
|
private set authorized(value);
|
|
264
264
|
private _isTryingLogin;
|
|
265
|
-
|
|
266
|
-
|
|
265
|
+
/**
|
|
266
|
+
* Last called with token refresh
|
|
267
|
+
*/
|
|
268
|
+
protected lastCalled: boolean;
|
|
269
|
+
/**
|
|
270
|
+
* Token refresh count down seed
|
|
271
|
+
*/
|
|
272
|
+
protected refreshCountdownSeed: number;
|
|
267
273
|
/**
|
|
268
274
|
* Protected constructor
|
|
269
275
|
* @param settings Settings
|
|
@@ -272,6 +278,7 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
|
|
|
272
278
|
* @param name Application name
|
|
273
279
|
*/
|
|
274
280
|
protected constructor(settings: S, api: IApi, notifier: INotifier<N, C>, name: string);
|
|
281
|
+
protected setApi(api: IApi): void;
|
|
275
282
|
/**
|
|
276
283
|
* Alert action result
|
|
277
284
|
* @param result Action result
|
|
@@ -377,8 +384,8 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
|
|
|
377
384
|
* Refresh countdown
|
|
378
385
|
* @param seconds Seconds
|
|
379
386
|
*/
|
|
380
|
-
|
|
381
|
-
|
|
387
|
+
protected refreshCountdown(seconds: number): void;
|
|
388
|
+
protected refreshCountdownClear(): void;
|
|
382
389
|
/**
|
|
383
390
|
* Fresh countdown UI
|
|
384
391
|
* @param callback Callback
|
package/lib/cjs/app/CoreApp.js
CHANGED
|
@@ -24,40 +24,19 @@ class CoreApp {
|
|
|
24
24
|
this.headerTokenField = 'SmartERPRefreshToken';
|
|
25
25
|
this._authorized = false;
|
|
26
26
|
this._isTryingLogin = false;
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
// onComplete, hide loading, rewrite the property to override default action
|
|
36
|
-
api.onComplete = (data) => {
|
|
37
|
-
if (data.showLoading == null || data.showLoading) {
|
|
38
|
-
notifier.hideLoading();
|
|
39
|
-
}
|
|
40
|
-
this._lastCalled = true;
|
|
41
|
-
};
|
|
42
|
-
// Global API error handler
|
|
43
|
-
api.onError = (error) => {
|
|
44
|
-
// Error code
|
|
45
|
-
const status = error.response
|
|
46
|
-
? api.transformResponse(error.response).status
|
|
47
|
-
: undefined;
|
|
48
|
-
if (status === 401) {
|
|
49
|
-
// When status is equal to 401, unauthorized, try login
|
|
50
|
-
this.tryLogin();
|
|
51
|
-
}
|
|
52
|
-
else {
|
|
53
|
-
// Report the error
|
|
54
|
-
notifier.alert(this.formatError(error));
|
|
55
|
-
}
|
|
56
|
-
};
|
|
27
|
+
/**
|
|
28
|
+
* Last called with token refresh
|
|
29
|
+
*/
|
|
30
|
+
this.lastCalled = false;
|
|
31
|
+
/**
|
|
32
|
+
* Token refresh count down seed
|
|
33
|
+
*/
|
|
34
|
+
this.refreshCountdownSeed = 0;
|
|
57
35
|
this.settings = settings;
|
|
58
36
|
this.api = api;
|
|
59
37
|
this.notifier = notifier;
|
|
60
38
|
this.name = name;
|
|
39
|
+
this.setApi(api);
|
|
61
40
|
const { currentCulture, currentRegion } = settings;
|
|
62
41
|
this.changeCulture(currentCulture);
|
|
63
42
|
this.changeRegion(currentRegion);
|
|
@@ -97,6 +76,36 @@ class CoreApp {
|
|
|
97
76
|
set authorized(value) {
|
|
98
77
|
this._authorized = value;
|
|
99
78
|
}
|
|
79
|
+
setApi(api) {
|
|
80
|
+
// onRequest, show loading or not, rewrite the property to override default action
|
|
81
|
+
api.onRequest = (data) => {
|
|
82
|
+
if (data.showLoading == null || data.showLoading) {
|
|
83
|
+
this.notifier.showLoading();
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
// onComplete, hide loading, rewrite the property to override default action
|
|
87
|
+
api.onComplete = (data) => {
|
|
88
|
+
if (data.showLoading == null || data.showLoading) {
|
|
89
|
+
this.notifier.hideLoading();
|
|
90
|
+
}
|
|
91
|
+
this.lastCalled = true;
|
|
92
|
+
};
|
|
93
|
+
// Global API error handler
|
|
94
|
+
api.onError = (error) => {
|
|
95
|
+
// Error code
|
|
96
|
+
const status = error.response
|
|
97
|
+
? api.transformResponse(error.response).status
|
|
98
|
+
: undefined;
|
|
99
|
+
if (status === 401) {
|
|
100
|
+
// When status is equal to 401, unauthorized, try login
|
|
101
|
+
this.tryLogin();
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
// Report the error
|
|
105
|
+
this.notifier.alert(this.formatError(error));
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
}
|
|
100
109
|
/**
|
|
101
110
|
* Alert action result
|
|
102
111
|
* @param result Action result
|
|
@@ -351,23 +360,23 @@ class CoreApp {
|
|
|
351
360
|
// Reset last call flag
|
|
352
361
|
// Any success call will update it to true
|
|
353
362
|
// So first time after login will be always silent
|
|
354
|
-
this.
|
|
355
|
-
this.
|
|
356
|
-
if (this.
|
|
363
|
+
this.lastCalled = false;
|
|
364
|
+
this.refreshCountdownSeed = window.setTimeout(() => {
|
|
365
|
+
if (this.lastCalled) {
|
|
357
366
|
// Call refreshToken to update access token
|
|
358
367
|
this.refreshToken();
|
|
359
368
|
}
|
|
360
369
|
else {
|
|
361
370
|
// Popup countdown for user action
|
|
362
|
-
this.freshCountdownUI(
|
|
371
|
+
this.freshCountdownUI();
|
|
363
372
|
}
|
|
364
373
|
}, 1000 * seconds);
|
|
365
374
|
}
|
|
366
375
|
refreshCountdownClear() {
|
|
367
376
|
// Clear the current timeout seed
|
|
368
|
-
if (this.
|
|
369
|
-
window.clearTimeout(this.
|
|
370
|
-
this.
|
|
377
|
+
if (this.refreshCountdownSeed > 0) {
|
|
378
|
+
window.clearTimeout(this.refreshCountdownSeed);
|
|
379
|
+
this.refreshCountdownSeed = 0;
|
|
371
380
|
}
|
|
372
381
|
}
|
|
373
382
|
/**
|
|
@@ -14,6 +14,14 @@ export interface IExternalSettings {
|
|
|
14
14
|
* Cloud web url
|
|
15
15
|
*/
|
|
16
16
|
readonly webUrl: string;
|
|
17
|
+
/**
|
|
18
|
+
* Core system Url
|
|
19
|
+
*/
|
|
20
|
+
readonly coreUrl?: string;
|
|
21
|
+
/**
|
|
22
|
+
* Core system API
|
|
23
|
+
*/
|
|
24
|
+
readonly coreApi?: string;
|
|
17
25
|
}
|
|
18
26
|
/**
|
|
19
27
|
* External settings host
|
package/lib/cjs/index.d.ts
CHANGED
|
@@ -19,6 +19,8 @@ export * from './dto/UpdateDto';
|
|
|
19
19
|
export * from './i18n/enUS';
|
|
20
20
|
export * from './i18n/zhCN';
|
|
21
21
|
export * from './i18n/zhHK';
|
|
22
|
+
export { ApiAuthorizationScheme, createClient } from '@etsoo/restclient';
|
|
23
|
+
export type { IApi, IApiPayload } from '@etsoo/restclient';
|
|
22
24
|
export * from './result/ActionResult';
|
|
23
25
|
export * from './result/ActionResultError';
|
|
24
26
|
export * from './result/IActionResult';
|
package/lib/cjs/index.js
CHANGED
|
@@ -10,6 +10,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
10
10
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
11
|
};
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.createClient = exports.ApiAuthorizationScheme = void 0;
|
|
13
14
|
// address
|
|
14
15
|
__exportStar(require("./address/AddressContinent"), exports);
|
|
15
16
|
__exportStar(require("./address/AddressRegion"), exports);
|
|
@@ -38,6 +39,10 @@ __exportStar(require("./dto/UpdateDto"), exports);
|
|
|
38
39
|
__exportStar(require("./i18n/enUS"), exports);
|
|
39
40
|
__exportStar(require("./i18n/zhCN"), exports);
|
|
40
41
|
__exportStar(require("./i18n/zhHK"), exports);
|
|
42
|
+
// @etsoo/restclient
|
|
43
|
+
var restclient_1 = require("@etsoo/restclient");
|
|
44
|
+
Object.defineProperty(exports, "ApiAuthorizationScheme", { enumerable: true, get: function () { return restclient_1.ApiAuthorizationScheme; } });
|
|
45
|
+
Object.defineProperty(exports, "createClient", { enumerable: true, get: function () { return restclient_1.createClient; } });
|
|
41
46
|
// result
|
|
42
47
|
__exportStar(require("./result/ActionResult"), exports);
|
|
43
48
|
__exportStar(require("./result/ActionResultError"), exports);
|
package/lib/mjs/app/CoreApp.d.ts
CHANGED
|
@@ -262,8 +262,14 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
|
|
|
262
262
|
get authorized(): boolean;
|
|
263
263
|
private set authorized(value);
|
|
264
264
|
private _isTryingLogin;
|
|
265
|
-
|
|
266
|
-
|
|
265
|
+
/**
|
|
266
|
+
* Last called with token refresh
|
|
267
|
+
*/
|
|
268
|
+
protected lastCalled: boolean;
|
|
269
|
+
/**
|
|
270
|
+
* Token refresh count down seed
|
|
271
|
+
*/
|
|
272
|
+
protected refreshCountdownSeed: number;
|
|
267
273
|
/**
|
|
268
274
|
* Protected constructor
|
|
269
275
|
* @param settings Settings
|
|
@@ -272,6 +278,7 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
|
|
|
272
278
|
* @param name Application name
|
|
273
279
|
*/
|
|
274
280
|
protected constructor(settings: S, api: IApi, notifier: INotifier<N, C>, name: string);
|
|
281
|
+
protected setApi(api: IApi): void;
|
|
275
282
|
/**
|
|
276
283
|
* Alert action result
|
|
277
284
|
* @param result Action result
|
|
@@ -377,8 +384,8 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
|
|
|
377
384
|
* Refresh countdown
|
|
378
385
|
* @param seconds Seconds
|
|
379
386
|
*/
|
|
380
|
-
|
|
381
|
-
|
|
387
|
+
protected refreshCountdown(seconds: number): void;
|
|
388
|
+
protected refreshCountdownClear(): void;
|
|
382
389
|
/**
|
|
383
390
|
* Fresh countdown UI
|
|
384
391
|
* @param callback Callback
|
package/lib/mjs/app/CoreApp.js
CHANGED
|
@@ -21,40 +21,19 @@ export class CoreApp {
|
|
|
21
21
|
this.headerTokenField = 'SmartERPRefreshToken';
|
|
22
22
|
this._authorized = false;
|
|
23
23
|
this._isTryingLogin = false;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
// onComplete, hide loading, rewrite the property to override default action
|
|
33
|
-
api.onComplete = (data) => {
|
|
34
|
-
if (data.showLoading == null || data.showLoading) {
|
|
35
|
-
notifier.hideLoading();
|
|
36
|
-
}
|
|
37
|
-
this._lastCalled = true;
|
|
38
|
-
};
|
|
39
|
-
// Global API error handler
|
|
40
|
-
api.onError = (error) => {
|
|
41
|
-
// Error code
|
|
42
|
-
const status = error.response
|
|
43
|
-
? api.transformResponse(error.response).status
|
|
44
|
-
: undefined;
|
|
45
|
-
if (status === 401) {
|
|
46
|
-
// When status is equal to 401, unauthorized, try login
|
|
47
|
-
this.tryLogin();
|
|
48
|
-
}
|
|
49
|
-
else {
|
|
50
|
-
// Report the error
|
|
51
|
-
notifier.alert(this.formatError(error));
|
|
52
|
-
}
|
|
53
|
-
};
|
|
24
|
+
/**
|
|
25
|
+
* Last called with token refresh
|
|
26
|
+
*/
|
|
27
|
+
this.lastCalled = false;
|
|
28
|
+
/**
|
|
29
|
+
* Token refresh count down seed
|
|
30
|
+
*/
|
|
31
|
+
this.refreshCountdownSeed = 0;
|
|
54
32
|
this.settings = settings;
|
|
55
33
|
this.api = api;
|
|
56
34
|
this.notifier = notifier;
|
|
57
35
|
this.name = name;
|
|
36
|
+
this.setApi(api);
|
|
58
37
|
const { currentCulture, currentRegion } = settings;
|
|
59
38
|
this.changeCulture(currentCulture);
|
|
60
39
|
this.changeRegion(currentRegion);
|
|
@@ -94,6 +73,36 @@ export class CoreApp {
|
|
|
94
73
|
set authorized(value) {
|
|
95
74
|
this._authorized = value;
|
|
96
75
|
}
|
|
76
|
+
setApi(api) {
|
|
77
|
+
// onRequest, show loading or not, rewrite the property to override default action
|
|
78
|
+
api.onRequest = (data) => {
|
|
79
|
+
if (data.showLoading == null || data.showLoading) {
|
|
80
|
+
this.notifier.showLoading();
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
// onComplete, hide loading, rewrite the property to override default action
|
|
84
|
+
api.onComplete = (data) => {
|
|
85
|
+
if (data.showLoading == null || data.showLoading) {
|
|
86
|
+
this.notifier.hideLoading();
|
|
87
|
+
}
|
|
88
|
+
this.lastCalled = true;
|
|
89
|
+
};
|
|
90
|
+
// Global API error handler
|
|
91
|
+
api.onError = (error) => {
|
|
92
|
+
// Error code
|
|
93
|
+
const status = error.response
|
|
94
|
+
? api.transformResponse(error.response).status
|
|
95
|
+
: undefined;
|
|
96
|
+
if (status === 401) {
|
|
97
|
+
// When status is equal to 401, unauthorized, try login
|
|
98
|
+
this.tryLogin();
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
// Report the error
|
|
102
|
+
this.notifier.alert(this.formatError(error));
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
}
|
|
97
106
|
/**
|
|
98
107
|
* Alert action result
|
|
99
108
|
* @param result Action result
|
|
@@ -348,23 +357,23 @@ export class CoreApp {
|
|
|
348
357
|
// Reset last call flag
|
|
349
358
|
// Any success call will update it to true
|
|
350
359
|
// So first time after login will be always silent
|
|
351
|
-
this.
|
|
352
|
-
this.
|
|
353
|
-
if (this.
|
|
360
|
+
this.lastCalled = false;
|
|
361
|
+
this.refreshCountdownSeed = window.setTimeout(() => {
|
|
362
|
+
if (this.lastCalled) {
|
|
354
363
|
// Call refreshToken to update access token
|
|
355
364
|
this.refreshToken();
|
|
356
365
|
}
|
|
357
366
|
else {
|
|
358
367
|
// Popup countdown for user action
|
|
359
|
-
this.freshCountdownUI(
|
|
368
|
+
this.freshCountdownUI();
|
|
360
369
|
}
|
|
361
370
|
}, 1000 * seconds);
|
|
362
371
|
}
|
|
363
372
|
refreshCountdownClear() {
|
|
364
373
|
// Clear the current timeout seed
|
|
365
|
-
if (this.
|
|
366
|
-
window.clearTimeout(this.
|
|
367
|
-
this.
|
|
374
|
+
if (this.refreshCountdownSeed > 0) {
|
|
375
|
+
window.clearTimeout(this.refreshCountdownSeed);
|
|
376
|
+
this.refreshCountdownSeed = 0;
|
|
368
377
|
}
|
|
369
378
|
}
|
|
370
379
|
/**
|
|
@@ -14,6 +14,14 @@ export interface IExternalSettings {
|
|
|
14
14
|
* Cloud web url
|
|
15
15
|
*/
|
|
16
16
|
readonly webUrl: string;
|
|
17
|
+
/**
|
|
18
|
+
* Core system Url
|
|
19
|
+
*/
|
|
20
|
+
readonly coreUrl?: string;
|
|
21
|
+
/**
|
|
22
|
+
* Core system API
|
|
23
|
+
*/
|
|
24
|
+
readonly coreApi?: string;
|
|
17
25
|
}
|
|
18
26
|
/**
|
|
19
27
|
* External settings host
|
package/lib/mjs/index.d.ts
CHANGED
|
@@ -19,6 +19,8 @@ export * from './dto/UpdateDto';
|
|
|
19
19
|
export * from './i18n/enUS';
|
|
20
20
|
export * from './i18n/zhCN';
|
|
21
21
|
export * from './i18n/zhHK';
|
|
22
|
+
export { ApiAuthorizationScheme, createClient } from '@etsoo/restclient';
|
|
23
|
+
export type { IApi, IApiPayload } from '@etsoo/restclient';
|
|
22
24
|
export * from './result/ActionResult';
|
|
23
25
|
export * from './result/ActionResultError';
|
|
24
26
|
export * from './result/IActionResult';
|
package/lib/mjs/index.js
CHANGED
|
@@ -26,6 +26,8 @@ export * from './dto/UpdateDto';
|
|
|
26
26
|
export * from './i18n/enUS';
|
|
27
27
|
export * from './i18n/zhCN';
|
|
28
28
|
export * from './i18n/zhHK';
|
|
29
|
+
// @etsoo/restclient
|
|
30
|
+
export { ApiAuthorizationScheme, createClient } from '@etsoo/restclient';
|
|
29
31
|
// result
|
|
30
32
|
export * from './result/ActionResult';
|
|
31
33
|
export * from './result/ActionResultError';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@etsoo/appscript",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.45",
|
|
4
4
|
"description": "Applications shared TypeScript framework",
|
|
5
5
|
"main": "lib/cjs/index.js",
|
|
6
6
|
"module": "lib/mjs/index.js",
|
|
@@ -59,15 +59,15 @@
|
|
|
59
59
|
"devDependencies": {
|
|
60
60
|
"@babel/cli": "^7.16.0",
|
|
61
61
|
"@babel/core": "^7.16.0",
|
|
62
|
-
"@babel/plugin-transform-runtime": "^7.16.
|
|
63
|
-
"@babel/preset-env": "^7.16.
|
|
64
|
-
"@babel/runtime-corejs3": "^7.16.
|
|
62
|
+
"@babel/plugin-transform-runtime": "^7.16.4",
|
|
63
|
+
"@babel/preset-env": "^7.16.4",
|
|
64
|
+
"@babel/runtime-corejs3": "^7.16.3",
|
|
65
65
|
"@types/jest": "^27.0.2",
|
|
66
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
67
|
-
"@typescript-eslint/parser": "^5.
|
|
66
|
+
"@typescript-eslint/eslint-plugin": "^5.4.0",
|
|
67
|
+
"@typescript-eslint/parser": "^5.4.0",
|
|
68
68
|
"eslint": "^8.2.0",
|
|
69
|
-
"eslint-config-airbnb-base": "^
|
|
70
|
-
"eslint-plugin-import": "^2.25.
|
|
69
|
+
"eslint-config-airbnb-base": "^15.0.0",
|
|
70
|
+
"eslint-plugin-import": "^2.25.3",
|
|
71
71
|
"jest": "^27.3.1",
|
|
72
72
|
"ts-jest": "^27.0.7",
|
|
73
73
|
"typescript": "^4.4.4"
|
package/src/app/AppSettings.ts
CHANGED
package/src/app/CoreApp.ts
CHANGED
|
@@ -362,8 +362,15 @@ export abstract class CoreApp<
|
|
|
362
362
|
|
|
363
363
|
private _isTryingLogin = false;
|
|
364
364
|
|
|
365
|
-
|
|
366
|
-
|
|
365
|
+
/**
|
|
366
|
+
* Last called with token refresh
|
|
367
|
+
*/
|
|
368
|
+
protected lastCalled = false;
|
|
369
|
+
|
|
370
|
+
/**
|
|
371
|
+
* Token refresh count down seed
|
|
372
|
+
*/
|
|
373
|
+
protected refreshCountdownSeed = 0;
|
|
367
374
|
|
|
368
375
|
/**
|
|
369
376
|
* Protected constructor
|
|
@@ -378,19 +385,36 @@ export abstract class CoreApp<
|
|
|
378
385
|
notifier: INotifier<N, C>,
|
|
379
386
|
name: string
|
|
380
387
|
) {
|
|
388
|
+
this.settings = settings;
|
|
389
|
+
this.api = api;
|
|
390
|
+
this.notifier = notifier;
|
|
391
|
+
this.name = name;
|
|
392
|
+
|
|
393
|
+
this.setApi(api);
|
|
394
|
+
|
|
395
|
+
const { currentCulture, currentRegion } = settings;
|
|
396
|
+
this.changeCulture(currentCulture);
|
|
397
|
+
|
|
398
|
+
this.changeRegion(currentRegion);
|
|
399
|
+
|
|
400
|
+
// Setup callback
|
|
401
|
+
this.setup();
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
protected setApi(api: IApi) {
|
|
381
405
|
// onRequest, show loading or not, rewrite the property to override default action
|
|
382
406
|
api.onRequest = (data) => {
|
|
383
407
|
if (data.showLoading == null || data.showLoading) {
|
|
384
|
-
notifier.showLoading();
|
|
408
|
+
this.notifier.showLoading();
|
|
385
409
|
}
|
|
386
410
|
};
|
|
387
411
|
|
|
388
412
|
// onComplete, hide loading, rewrite the property to override default action
|
|
389
413
|
api.onComplete = (data) => {
|
|
390
414
|
if (data.showLoading == null || data.showLoading) {
|
|
391
|
-
notifier.hideLoading();
|
|
415
|
+
this.notifier.hideLoading();
|
|
392
416
|
}
|
|
393
|
-
this.
|
|
417
|
+
this.lastCalled = true;
|
|
394
418
|
};
|
|
395
419
|
|
|
396
420
|
// Global API error handler
|
|
@@ -405,22 +429,9 @@ export abstract class CoreApp<
|
|
|
405
429
|
this.tryLogin();
|
|
406
430
|
} else {
|
|
407
431
|
// Report the error
|
|
408
|
-
notifier.alert(this.formatError(error));
|
|
432
|
+
this.notifier.alert(this.formatError(error));
|
|
409
433
|
}
|
|
410
434
|
};
|
|
411
|
-
|
|
412
|
-
this.settings = settings;
|
|
413
|
-
this.api = api;
|
|
414
|
-
this.notifier = notifier;
|
|
415
|
-
this.name = name;
|
|
416
|
-
|
|
417
|
-
const { currentCulture, currentRegion } = settings;
|
|
418
|
-
this.changeCulture(currentCulture);
|
|
419
|
-
|
|
420
|
-
this.changeRegion(currentRegion);
|
|
421
|
-
|
|
422
|
-
// Setup callback
|
|
423
|
-
this.setup();
|
|
424
435
|
}
|
|
425
436
|
|
|
426
437
|
/**
|
|
@@ -727,7 +738,7 @@ export abstract class CoreApp<
|
|
|
727
738
|
* Refresh countdown
|
|
728
739
|
* @param seconds Seconds
|
|
729
740
|
*/
|
|
730
|
-
|
|
741
|
+
protected refreshCountdown(seconds: number) {
|
|
731
742
|
// Make sure is big than 60 seconds
|
|
732
743
|
// Take action 60 seconds before expiry
|
|
733
744
|
seconds -= 60;
|
|
@@ -739,24 +750,24 @@ export abstract class CoreApp<
|
|
|
739
750
|
// Reset last call flag
|
|
740
751
|
// Any success call will update it to true
|
|
741
752
|
// So first time after login will be always silent
|
|
742
|
-
this.
|
|
753
|
+
this.lastCalled = false;
|
|
743
754
|
|
|
744
|
-
this.
|
|
745
|
-
if (this.
|
|
755
|
+
this.refreshCountdownSeed = window.setTimeout(() => {
|
|
756
|
+
if (this.lastCalled) {
|
|
746
757
|
// Call refreshToken to update access token
|
|
747
758
|
this.refreshToken();
|
|
748
759
|
} else {
|
|
749
760
|
// Popup countdown for user action
|
|
750
|
-
this.freshCountdownUI(
|
|
761
|
+
this.freshCountdownUI();
|
|
751
762
|
}
|
|
752
763
|
}, 1000 * seconds);
|
|
753
764
|
}
|
|
754
765
|
|
|
755
|
-
|
|
766
|
+
protected refreshCountdownClear() {
|
|
756
767
|
// Clear the current timeout seed
|
|
757
|
-
if (this.
|
|
758
|
-
window.clearTimeout(this.
|
|
759
|
-
this.
|
|
768
|
+
if (this.refreshCountdownSeed > 0) {
|
|
769
|
+
window.clearTimeout(this.refreshCountdownSeed);
|
|
770
|
+
this.refreshCountdownSeed = 0;
|
|
760
771
|
}
|
|
761
772
|
}
|
|
762
773
|
|
package/src/index.ts
CHANGED
|
@@ -33,6 +33,10 @@ export * from './i18n/enUS';
|
|
|
33
33
|
export * from './i18n/zhCN';
|
|
34
34
|
export * from './i18n/zhHK';
|
|
35
35
|
|
|
36
|
+
// @etsoo/restclient
|
|
37
|
+
export { ApiAuthorizationScheme, createClient } from '@etsoo/restclient';
|
|
38
|
+
export type { IApi, IApiPayload } from '@etsoo/restclient';
|
|
39
|
+
|
|
36
40
|
// result
|
|
37
41
|
export * from './result/ActionResult';
|
|
38
42
|
export * from './result/ActionResultError';
|