@etsoo/appscript 1.4.35 → 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.
- package/lib/cjs/app/CoreApp.d.ts +11 -8
- package/lib/cjs/app/CoreApp.js +29 -28
- package/lib/cjs/app/IApp.d.ts +0 -7
- package/lib/mjs/app/CoreApp.d.ts +11 -8
- package/lib/mjs/app/CoreApp.js +29 -28
- package/lib/mjs/app/IApp.d.ts +0 -7
- package/package.json +1 -1
- package/src/app/CoreApp.ts +32 -35
- package/src/app/IApp.ts +0 -12
package/lib/cjs/app/CoreApp.d.ts
CHANGED
|
@@ -10,7 +10,6 @@ import { IUser } from '../state/User';
|
|
|
10
10
|
import { IAppSettings } from './AppSettings';
|
|
11
11
|
import { IApp, IAppFields, IDetectIPCallback, NavigateOptions, RefreshTokenProps, RefreshTokenResult } from './IApp';
|
|
12
12
|
import { UserRole } from './UserRole';
|
|
13
|
-
import { IAppApi } from './IAppApi';
|
|
14
13
|
/**
|
|
15
14
|
* Core application interface
|
|
16
15
|
*/
|
|
@@ -180,6 +179,17 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
|
|
|
180
179
|
* @param api Api
|
|
181
180
|
*/
|
|
182
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;
|
|
183
193
|
/**
|
|
184
194
|
* Api init call
|
|
185
195
|
* @param data Data
|
|
@@ -220,13 +230,6 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
|
|
|
220
230
|
* @param callback Callback
|
|
221
231
|
*/
|
|
222
232
|
alertResult(result: IActionResult | string, callback?: NotificationReturn<void>): void;
|
|
223
|
-
/**
|
|
224
|
-
* Service application API login
|
|
225
|
-
* @param appApi Service application API
|
|
226
|
-
* @param relogin Relogin try
|
|
227
|
-
* @param callback Callback
|
|
228
|
-
*/
|
|
229
|
-
apiLogin(appApi: IAppApi, relogin?: boolean, callback?: (result: RefreshTokenResult, successData?: string) => void): Promise<boolean>;
|
|
230
233
|
/**
|
|
231
234
|
* Authorize
|
|
232
235
|
* @param token New token
|
package/lib/cjs/app/CoreApp.js
CHANGED
|
@@ -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
|
-
|
|
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
|
|
@@ -488,21 +504,6 @@ class CoreApp {
|
|
|
488
504
|
const message = typeof result === 'string' ? result : this.formatResult(result);
|
|
489
505
|
this.notifier.alert(message, callback);
|
|
490
506
|
}
|
|
491
|
-
/**
|
|
492
|
-
* Service application API login
|
|
493
|
-
* @param appApi Service application API
|
|
494
|
-
* @param relogin Relogin try
|
|
495
|
-
* @param callback Callback
|
|
496
|
-
*/
|
|
497
|
-
apiLogin(appApi, relogin = true, callback) {
|
|
498
|
-
return this.refreshToken({
|
|
499
|
-
callback,
|
|
500
|
-
data: appApi.getrefreshTokenData(),
|
|
501
|
-
relogin,
|
|
502
|
-
showLoading: false,
|
|
503
|
-
appApi
|
|
504
|
-
});
|
|
505
|
-
}
|
|
506
507
|
/**
|
|
507
508
|
* Authorize
|
|
508
509
|
* @param token New token
|
package/lib/cjs/app/IApp.d.ts
CHANGED
|
@@ -158,13 +158,6 @@ export interface IApp {
|
|
|
158
158
|
* @param callback Callback
|
|
159
159
|
*/
|
|
160
160
|
alertResult(result: IActionResult | string, callback?: NotificationReturn<void>): void;
|
|
161
|
-
/**
|
|
162
|
-
* Service application API login
|
|
163
|
-
* @param appApi Service application API
|
|
164
|
-
* @param relogin Relogin try
|
|
165
|
-
* @param callback Callback
|
|
166
|
-
*/
|
|
167
|
-
apiLogin(appApi: IAppApi, relogin?: boolean, callback?: (result: RefreshTokenResult, successData?: string) => void): Promise<boolean>;
|
|
168
161
|
/**
|
|
169
162
|
* Authorize
|
|
170
163
|
* @param token New token
|
package/lib/mjs/app/CoreApp.d.ts
CHANGED
|
@@ -10,7 +10,6 @@ import { IUser } from '../state/User';
|
|
|
10
10
|
import { IAppSettings } from './AppSettings';
|
|
11
11
|
import { IApp, IAppFields, IDetectIPCallback, NavigateOptions, RefreshTokenProps, RefreshTokenResult } from './IApp';
|
|
12
12
|
import { UserRole } from './UserRole';
|
|
13
|
-
import { IAppApi } from './IAppApi';
|
|
14
13
|
/**
|
|
15
14
|
* Core application interface
|
|
16
15
|
*/
|
|
@@ -180,6 +179,17 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
|
|
|
180
179
|
* @param api Api
|
|
181
180
|
*/
|
|
182
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;
|
|
183
193
|
/**
|
|
184
194
|
* Api init call
|
|
185
195
|
* @param data Data
|
|
@@ -220,13 +230,6 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
|
|
|
220
230
|
* @param callback Callback
|
|
221
231
|
*/
|
|
222
232
|
alertResult(result: IActionResult | string, callback?: NotificationReturn<void>): void;
|
|
223
|
-
/**
|
|
224
|
-
* Service application API login
|
|
225
|
-
* @param appApi Service application API
|
|
226
|
-
* @param relogin Relogin try
|
|
227
|
-
* @param callback Callback
|
|
228
|
-
*/
|
|
229
|
-
apiLogin(appApi: IAppApi, relogin?: boolean, callback?: (result: RefreshTokenResult, successData?: string) => void): Promise<boolean>;
|
|
230
233
|
/**
|
|
231
234
|
* Authorize
|
|
232
235
|
* @param token New token
|
package/lib/mjs/app/CoreApp.js
CHANGED
|
@@ -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
|
-
|
|
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
|
|
@@ -462,21 +478,6 @@ export class CoreApp {
|
|
|
462
478
|
const message = typeof result === 'string' ? result : this.formatResult(result);
|
|
463
479
|
this.notifier.alert(message, callback);
|
|
464
480
|
}
|
|
465
|
-
/**
|
|
466
|
-
* Service application API login
|
|
467
|
-
* @param appApi Service application API
|
|
468
|
-
* @param relogin Relogin try
|
|
469
|
-
* @param callback Callback
|
|
470
|
-
*/
|
|
471
|
-
apiLogin(appApi, relogin = true, callback) {
|
|
472
|
-
return this.refreshToken({
|
|
473
|
-
callback,
|
|
474
|
-
data: appApi.getrefreshTokenData(),
|
|
475
|
-
relogin,
|
|
476
|
-
showLoading: false,
|
|
477
|
-
appApi
|
|
478
|
-
});
|
|
479
|
-
}
|
|
480
481
|
/**
|
|
481
482
|
* Authorize
|
|
482
483
|
* @param token New token
|
package/lib/mjs/app/IApp.d.ts
CHANGED
|
@@ -158,13 +158,6 @@ export interface IApp {
|
|
|
158
158
|
* @param callback Callback
|
|
159
159
|
*/
|
|
160
160
|
alertResult(result: IActionResult | string, callback?: NotificationReturn<void>): void;
|
|
161
|
-
/**
|
|
162
|
-
* Service application API login
|
|
163
|
-
* @param appApi Service application API
|
|
164
|
-
* @param relogin Relogin try
|
|
165
|
-
* @param callback Callback
|
|
166
|
-
*/
|
|
167
|
-
apiLogin(appApi: IAppApi, relogin?: boolean, callback?: (result: RefreshTokenResult, successData?: string) => void): Promise<boolean>;
|
|
168
161
|
/**
|
|
169
162
|
* Authorize
|
|
170
163
|
* @param token New token
|
package/package.json
CHANGED
package/src/app/CoreApp.ts
CHANGED
|
@@ -39,7 +39,6 @@ import {
|
|
|
39
39
|
} from './IApp';
|
|
40
40
|
import { UserRole } from './UserRole';
|
|
41
41
|
import type CryptoJS from 'crypto-js';
|
|
42
|
-
import { IAppApi } from './IAppApi';
|
|
43
42
|
|
|
44
43
|
type CJType = typeof CryptoJS;
|
|
45
44
|
let CJ: CJType;
|
|
@@ -447,28 +446,25 @@ export abstract class CoreApp<
|
|
|
447
446
|
api.baseUrl = this.settings.endpoint;
|
|
448
447
|
|
|
449
448
|
// onRequest, show loading or not, rewrite the property to override default action
|
|
450
|
-
|
|
451
|
-
if (data.showLoading == null || data.showLoading) {
|
|
452
|
-
this.notifier.showLoading();
|
|
453
|
-
}
|
|
454
|
-
};
|
|
455
|
-
|
|
456
|
-
// onComplete, hide loading, rewrite the property to override default action
|
|
457
|
-
api.onComplete = (data) => {
|
|
458
|
-
if (data.showLoading == null || data.showLoading) {
|
|
459
|
-
this.notifier.hideLoading();
|
|
460
|
-
}
|
|
461
|
-
this.lastCalled = true;
|
|
462
|
-
};
|
|
449
|
+
this.setApiLoading(api);
|
|
463
450
|
|
|
464
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) {
|
|
465
461
|
api.onError = (error: ApiDataError) => {
|
|
466
462
|
// Error code
|
|
467
463
|
const status = error.response
|
|
468
464
|
? api.transformResponse(error.response).status
|
|
469
465
|
: undefined;
|
|
470
466
|
|
|
471
|
-
if (status === 401) {
|
|
467
|
+
if (status === 401 && !ignore401) {
|
|
472
468
|
// When status is equal to 401, unauthorized, try login
|
|
473
469
|
this.tryLogin();
|
|
474
470
|
} else {
|
|
@@ -478,6 +474,27 @@ export abstract class CoreApp<
|
|
|
478
474
|
};
|
|
479
475
|
}
|
|
480
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
|
+
|
|
481
498
|
/**
|
|
482
499
|
* Api init call
|
|
483
500
|
* @param data Data
|
|
@@ -701,26 +718,6 @@ export abstract class CoreApp<
|
|
|
701
718
|
this.notifier.alert(message, callback);
|
|
702
719
|
}
|
|
703
720
|
|
|
704
|
-
/**
|
|
705
|
-
* Service application API login
|
|
706
|
-
* @param appApi Service application API
|
|
707
|
-
* @param relogin Relogin try
|
|
708
|
-
* @param callback Callback
|
|
709
|
-
*/
|
|
710
|
-
apiLogin(
|
|
711
|
-
appApi: IAppApi,
|
|
712
|
-
relogin: boolean = true,
|
|
713
|
-
callback?: (result: RefreshTokenResult, successData?: string) => void
|
|
714
|
-
) {
|
|
715
|
-
return this.refreshToken({
|
|
716
|
-
callback,
|
|
717
|
-
data: appApi.getrefreshTokenData(),
|
|
718
|
-
relogin,
|
|
719
|
-
showLoading: false,
|
|
720
|
-
appApi
|
|
721
|
-
});
|
|
722
|
-
}
|
|
723
|
-
|
|
724
721
|
/**
|
|
725
722
|
* Authorize
|
|
726
723
|
* @param token New token
|
package/src/app/IApp.ts
CHANGED
|
@@ -214,18 +214,6 @@ export interface IApp {
|
|
|
214
214
|
callback?: NotificationReturn<void>
|
|
215
215
|
): void;
|
|
216
216
|
|
|
217
|
-
/**
|
|
218
|
-
* Service application API login
|
|
219
|
-
* @param appApi Service application API
|
|
220
|
-
* @param relogin Relogin try
|
|
221
|
-
* @param callback Callback
|
|
222
|
-
*/
|
|
223
|
-
apiLogin(
|
|
224
|
-
appApi: IAppApi,
|
|
225
|
-
relogin?: boolean,
|
|
226
|
-
callback?: (result: RefreshTokenResult, successData?: string) => void
|
|
227
|
-
): Promise<boolean>;
|
|
228
|
-
|
|
229
217
|
/**
|
|
230
218
|
* Authorize
|
|
231
219
|
* @param token New token
|