@etsoo/appscript 1.4.34 → 1.4.36

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.
@@ -179,6 +179,17 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
179
179
  * @param api Api
180
180
  */
181
181
  protected setApi(api: IApi): void;
182
+ /**
183
+ * Setup Api error handler
184
+ * @param api Api
185
+ * @param ignore401 Ignore 401 error try login
186
+ */
187
+ protected setApiErrorHandler(api: IApi, ignore401?: boolean): void;
188
+ /**
189
+ * Setup Api loading
190
+ * @param api Api
191
+ */
192
+ protected setApiLoading(api: IApi): void;
182
193
  /**
183
194
  * Api init call
184
195
  * @param data Data
@@ -290,25 +290,22 @@ class CoreApp {
290
290
  // Base URL of the API
291
291
  api.baseUrl = this.settings.endpoint;
292
292
  // onRequest, show loading or not, rewrite the property to override default action
293
- api.onRequest = (data) => {
294
- if (data.showLoading == null || data.showLoading) {
295
- this.notifier.showLoading();
296
- }
297
- };
298
- // onComplete, hide loading, rewrite the property to override default action
299
- api.onComplete = (data) => {
300
- if (data.showLoading == null || data.showLoading) {
301
- this.notifier.hideLoading();
302
- }
303
- this.lastCalled = true;
304
- };
293
+ this.setApiLoading(api);
305
294
  // Global API error handler
295
+ this.setApiErrorHandler(api);
296
+ }
297
+ /**
298
+ * Setup Api error handler
299
+ * @param api Api
300
+ * @param ignore401 Ignore 401 error try login
301
+ */
302
+ setApiErrorHandler(api, ignore401 = false) {
306
303
  api.onError = (error) => {
307
304
  // Error code
308
305
  const status = error.response
309
306
  ? api.transformResponse(error.response).status
310
307
  : undefined;
311
- if (status === 401) {
308
+ if (status === 401 && !ignore401) {
312
309
  // When status is equal to 401, unauthorized, try login
313
310
  this.tryLogin();
314
311
  }
@@ -318,6 +315,25 @@ class CoreApp {
318
315
  }
319
316
  };
320
317
  }
318
+ /**
319
+ * Setup Api loading
320
+ * @param api Api
321
+ */
322
+ setApiLoading(api) {
323
+ // onRequest, show loading or not, rewrite the property to override default action
324
+ api.onRequest = (data) => {
325
+ if (data.showLoading == null || data.showLoading) {
326
+ this.notifier.showLoading();
327
+ }
328
+ };
329
+ // onComplete, hide loading, rewrite the property to override default action
330
+ api.onComplete = (data) => {
331
+ if (data.showLoading == null || data.showLoading) {
332
+ this.notifier.hideLoading();
333
+ }
334
+ this.lastCalled = true;
335
+ };
336
+ }
321
337
  /**
322
338
  * Api init call
323
339
  * @param data Data
@@ -7,6 +7,7 @@ import { IUser } from '../state/User';
7
7
  import { IAppSettings } from './AppSettings';
8
8
  import { UserRole } from './UserRole';
9
9
  import { EntityStatus } from '../business/EntityStatus';
10
+ import { IAppApi } from './IAppApi';
10
11
  /**
11
12
  * Detect IP callback interface
12
13
  */
@@ -46,6 +47,10 @@ export interface RefreshTokenProps<D extends object> {
46
47
  * Show loading bar or not
47
48
  */
48
49
  showLoading?: boolean;
50
+ /**
51
+ * Service application API
52
+ */
53
+ appApi?: IAppApi;
49
54
  }
50
55
  /**
51
56
  * App fields
@@ -0,0 +1,24 @@
1
+ import { IApi } from '@etsoo/restclient';
2
+ /**
3
+ * Service application API, Implement interface calls between different services
4
+ * 服务程序接口,实现不同服务之间的接口调用
5
+ */
6
+ export interface IAppApi {
7
+ /**
8
+ * API
9
+ */
10
+ readonly api: IApi<any>;
11
+ /**
12
+ * Service id
13
+ */
14
+ readonly serviceId: number;
15
+ /**
16
+ * Authorize the API
17
+ * @param token Access token
18
+ */
19
+ authorize(token: string): void;
20
+ /**
21
+ * Get refresh token data
22
+ */
23
+ getrefreshTokenData(): Object;
24
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -12,6 +12,7 @@ export * from './app/AppSettings';
12
12
  export * from './app/CoreApp';
13
13
  export * from './app/ExternalSettings';
14
14
  export * from './app/IApp';
15
+ export * from './app/IAppApi';
15
16
  export * from './app/UserRole';
16
17
  export * from './bridges/BridgeUtils';
17
18
  export * from './bridges/IBridgeHost';
package/lib/cjs/index.js CHANGED
@@ -31,6 +31,7 @@ __exportStar(require("./app/AppSettings"), exports);
31
31
  __exportStar(require("./app/CoreApp"), exports);
32
32
  __exportStar(require("./app/ExternalSettings"), exports);
33
33
  __exportStar(require("./app/IApp"), exports);
34
+ __exportStar(require("./app/IAppApi"), exports);
34
35
  __exportStar(require("./app/UserRole"), exports);
35
36
  // bridges
36
37
  __exportStar(require("./bridges/BridgeUtils"), exports);
@@ -179,6 +179,17 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
179
179
  * @param api Api
180
180
  */
181
181
  protected setApi(api: IApi): void;
182
+ /**
183
+ * Setup Api error handler
184
+ * @param api Api
185
+ * @param ignore401 Ignore 401 error try login
186
+ */
187
+ protected setApiErrorHandler(api: IApi, ignore401?: boolean): void;
188
+ /**
189
+ * Setup Api loading
190
+ * @param api Api
191
+ */
192
+ protected setApiLoading(api: IApi): void;
182
193
  /**
183
194
  * Api init call
184
195
  * @param data Data
@@ -264,25 +264,22 @@ export class CoreApp {
264
264
  // Base URL of the API
265
265
  api.baseUrl = this.settings.endpoint;
266
266
  // onRequest, show loading or not, rewrite the property to override default action
267
- api.onRequest = (data) => {
268
- if (data.showLoading == null || data.showLoading) {
269
- this.notifier.showLoading();
270
- }
271
- };
272
- // onComplete, hide loading, rewrite the property to override default action
273
- api.onComplete = (data) => {
274
- if (data.showLoading == null || data.showLoading) {
275
- this.notifier.hideLoading();
276
- }
277
- this.lastCalled = true;
278
- };
267
+ this.setApiLoading(api);
279
268
  // Global API error handler
269
+ this.setApiErrorHandler(api);
270
+ }
271
+ /**
272
+ * Setup Api error handler
273
+ * @param api Api
274
+ * @param ignore401 Ignore 401 error try login
275
+ */
276
+ setApiErrorHandler(api, ignore401 = false) {
280
277
  api.onError = (error) => {
281
278
  // Error code
282
279
  const status = error.response
283
280
  ? api.transformResponse(error.response).status
284
281
  : undefined;
285
- if (status === 401) {
282
+ if (status === 401 && !ignore401) {
286
283
  // When status is equal to 401, unauthorized, try login
287
284
  this.tryLogin();
288
285
  }
@@ -292,6 +289,25 @@ export class CoreApp {
292
289
  }
293
290
  };
294
291
  }
292
+ /**
293
+ * Setup Api loading
294
+ * @param api Api
295
+ */
296
+ setApiLoading(api) {
297
+ // onRequest, show loading or not, rewrite the property to override default action
298
+ api.onRequest = (data) => {
299
+ if (data.showLoading == null || data.showLoading) {
300
+ this.notifier.showLoading();
301
+ }
302
+ };
303
+ // onComplete, hide loading, rewrite the property to override default action
304
+ api.onComplete = (data) => {
305
+ if (data.showLoading == null || data.showLoading) {
306
+ this.notifier.hideLoading();
307
+ }
308
+ this.lastCalled = true;
309
+ };
310
+ }
295
311
  /**
296
312
  * Api init call
297
313
  * @param data Data
@@ -7,6 +7,7 @@ import { IUser } from '../state/User';
7
7
  import { IAppSettings } from './AppSettings';
8
8
  import { UserRole } from './UserRole';
9
9
  import { EntityStatus } from '../business/EntityStatus';
10
+ import { IAppApi } from './IAppApi';
10
11
  /**
11
12
  * Detect IP callback interface
12
13
  */
@@ -46,6 +47,10 @@ export interface RefreshTokenProps<D extends object> {
46
47
  * Show loading bar or not
47
48
  */
48
49
  showLoading?: boolean;
50
+ /**
51
+ * Service application API
52
+ */
53
+ appApi?: IAppApi;
49
54
  }
50
55
  /**
51
56
  * App fields
@@ -0,0 +1,24 @@
1
+ import { IApi } from '@etsoo/restclient';
2
+ /**
3
+ * Service application API, Implement interface calls between different services
4
+ * 服务程序接口,实现不同服务之间的接口调用
5
+ */
6
+ export interface IAppApi {
7
+ /**
8
+ * API
9
+ */
10
+ readonly api: IApi<any>;
11
+ /**
12
+ * Service id
13
+ */
14
+ readonly serviceId: number;
15
+ /**
16
+ * Authorize the API
17
+ * @param token Access token
18
+ */
19
+ authorize(token: string): void;
20
+ /**
21
+ * Get refresh token data
22
+ */
23
+ getrefreshTokenData(): Object;
24
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -12,6 +12,7 @@ export * from './app/AppSettings';
12
12
  export * from './app/CoreApp';
13
13
  export * from './app/ExternalSettings';
14
14
  export * from './app/IApp';
15
+ export * from './app/IAppApi';
15
16
  export * from './app/UserRole';
16
17
  export * from './bridges/BridgeUtils';
17
18
  export * from './bridges/IBridgeHost';
package/lib/mjs/index.js CHANGED
@@ -14,6 +14,7 @@ export * from './app/AppSettings';
14
14
  export * from './app/CoreApp';
15
15
  export * from './app/ExternalSettings';
16
16
  export * from './app/IApp';
17
+ export * from './app/IAppApi';
17
18
  export * from './app/UserRole';
18
19
  // bridges
19
20
  export * from './bridges/BridgeUtils';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/appscript",
3
- "version": "1.4.34",
3
+ "version": "1.4.36",
4
4
  "description": "Applications shared TypeScript framework",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/mjs/index.js",
@@ -52,7 +52,7 @@
52
52
  },
53
53
  "homepage": "https://github.com/ETSOO/AppScript#readme",
54
54
  "dependencies": {
55
- "@etsoo/notificationbase": "^1.1.27",
55
+ "@etsoo/notificationbase": "^1.1.28",
56
56
  "@etsoo/restclient": "^1.0.89",
57
57
  "@etsoo/shared": "^1.2.10",
58
58
  "crypto-js": "^4.1.1"
@@ -446,28 +446,25 @@ export abstract class CoreApp<
446
446
  api.baseUrl = this.settings.endpoint;
447
447
 
448
448
  // onRequest, show loading or not, rewrite the property to override default action
449
- api.onRequest = (data) => {
450
- if (data.showLoading == null || data.showLoading) {
451
- this.notifier.showLoading();
452
- }
453
- };
454
-
455
- // onComplete, hide loading, rewrite the property to override default action
456
- api.onComplete = (data) => {
457
- if (data.showLoading == null || data.showLoading) {
458
- this.notifier.hideLoading();
459
- }
460
- this.lastCalled = true;
461
- };
449
+ this.setApiLoading(api);
462
450
 
463
451
  // Global API error handler
452
+ this.setApiErrorHandler(api);
453
+ }
454
+
455
+ /**
456
+ * Setup Api error handler
457
+ * @param api Api
458
+ * @param ignore401 Ignore 401 error try login
459
+ */
460
+ protected setApiErrorHandler(api: IApi, ignore401: boolean = false) {
464
461
  api.onError = (error: ApiDataError) => {
465
462
  // Error code
466
463
  const status = error.response
467
464
  ? api.transformResponse(error.response).status
468
465
  : undefined;
469
466
 
470
- if (status === 401) {
467
+ if (status === 401 && !ignore401) {
471
468
  // When status is equal to 401, unauthorized, try login
472
469
  this.tryLogin();
473
470
  } else {
@@ -477,6 +474,27 @@ export abstract class CoreApp<
477
474
  };
478
475
  }
479
476
 
477
+ /**
478
+ * Setup Api loading
479
+ * @param api Api
480
+ */
481
+ protected setApiLoading(api: IApi) {
482
+ // onRequest, show loading or not, rewrite the property to override default action
483
+ api.onRequest = (data) => {
484
+ if (data.showLoading == null || data.showLoading) {
485
+ this.notifier.showLoading();
486
+ }
487
+ };
488
+
489
+ // onComplete, hide loading, rewrite the property to override default action
490
+ api.onComplete = (data) => {
491
+ if (data.showLoading == null || data.showLoading) {
492
+ this.notifier.hideLoading();
493
+ }
494
+ this.lastCalled = true;
495
+ };
496
+ }
497
+
480
498
  /**
481
499
  * Api init call
482
500
  * @param data Data
package/src/app/IApp.ts CHANGED
@@ -19,6 +19,7 @@ import { IUser } from '../state/User';
19
19
  import { IAppSettings } from './AppSettings';
20
20
  import { UserRole } from './UserRole';
21
21
  import { EntityStatus } from '../business/EntityStatus';
22
+ import { IAppApi } from './IAppApi';
22
23
 
23
24
  /**
24
25
  * Detect IP callback interface
@@ -69,6 +70,11 @@ export interface RefreshTokenProps<D extends object> {
69
70
  * Show loading bar or not
70
71
  */
71
72
  showLoading?: boolean;
73
+
74
+ /**
75
+ * Service application API
76
+ */
77
+ appApi?: IAppApi;
72
78
  }
73
79
 
74
80
  /**
@@ -0,0 +1,28 @@
1
+ import { IApi } from '@etsoo/restclient';
2
+
3
+ /**
4
+ * Service application API, Implement interface calls between different services
5
+ * 服务程序接口,实现不同服务之间的接口调用
6
+ */
7
+ export interface IAppApi {
8
+ /**
9
+ * API
10
+ */
11
+ readonly api: IApi<any>;
12
+
13
+ /**
14
+ * Service id
15
+ */
16
+ readonly serviceId: number;
17
+
18
+ /**
19
+ * Authorize the API
20
+ * @param token Access token
21
+ */
22
+ authorize(token: string): void;
23
+
24
+ /**
25
+ * Get refresh token data
26
+ */
27
+ getrefreshTokenData(): Object;
28
+ }
package/src/index.ts CHANGED
@@ -15,6 +15,7 @@ export * from './app/AppSettings';
15
15
  export * from './app/CoreApp';
16
16
  export * from './app/ExternalSettings';
17
17
  export * from './app/IApp';
18
+ export * from './app/IAppApi';
18
19
  export * from './app/UserRole';
19
20
 
20
21
  // bridges