@etsoo/appscript 1.2.65 → 1.2.68

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.
@@ -212,6 +212,13 @@ export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallP
212
212
  * @returns Result
213
213
  */
214
214
  formatNumber(input?: number | bigint, options?: Intl.NumberFormatOptions): string | undefined;
215
+ /**
216
+ * Do refresh token result
217
+ * @param result Result
218
+ * @param initCallCallback InitCall callback
219
+ * @param silent Silent without any popups
220
+ */
221
+ doRefreshTokenResult(result: RefreshTokenResult, initCallCallback?: (result: boolean) => void, silent?: boolean): void;
215
222
  /**
216
223
  * Format refresh token result
217
224
  * @param result Refresh token result
@@ -521,6 +528,12 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
521
528
  * @returns Result
522
529
  */
523
530
  protected apiInitCall(data: InitCallDto): Promise<InitCallResult | undefined>;
531
+ /**
532
+ * Check the action result is about device invalid
533
+ * @param result Action result
534
+ * @returns true means device is invalid
535
+ */
536
+ protected checkDeviceResult(result: IActionResult): boolean;
524
537
  /**
525
538
  * Init call
526
539
  * @param callback Callback
@@ -642,6 +655,17 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
642
655
  * @returns Error message
643
656
  */
644
657
  formatError(error: ApiDataError): string;
658
+ /**
659
+ * Refresh token failed
660
+ */
661
+ protected refreshTokenFailed(): void;
662
+ /**
663
+ * Do refresh token result
664
+ * @param result Result
665
+ * @param initCallCallback InitCall callback
666
+ * @param silent Silent without any popups
667
+ */
668
+ doRefreshTokenResult(result: RefreshTokenResult, initCallCallback?: (result: boolean) => void, silent?: boolean): void;
645
669
  /**
646
670
  * Format refresh token result
647
671
  * @param result Refresh token result
@@ -269,6 +269,16 @@ class CoreApp {
269
269
  async apiInitCall(data) {
270
270
  return await this.api.put(this.initCallApi, data);
271
271
  }
272
+ /**
273
+ * Check the action result is about device invalid
274
+ * @param result Action result
275
+ * @returns true means device is invalid
276
+ */
277
+ checkDeviceResult(result) {
278
+ if (result.type === 'NoValidData' && result.field === 'Device')
279
+ return true;
280
+ return false;
281
+ }
272
282
  /**
273
283
  * Init call
274
284
  * @param callback Callback
@@ -278,8 +288,10 @@ class CoreApp {
278
288
  async initCall(callback, resetKeys) {
279
289
  var _a;
280
290
  // Reset keys
281
- if (resetKeys)
291
+ if (resetKeys) {
292
+ this._deviceId = '';
282
293
  this.resetKeys();
294
+ }
283
295
  // Passphrase exists?
284
296
  if (this.passphrase) {
285
297
  if (callback)
@@ -699,6 +711,38 @@ class CoreApp {
699
711
  formatError(error) {
700
712
  return error.toString();
701
713
  }
714
+ /**
715
+ * Refresh token failed
716
+ */
717
+ refreshTokenFailed() {
718
+ this.userUnauthorized();
719
+ this.toLoginPage();
720
+ }
721
+ /**
722
+ * Do refresh token result
723
+ * @param result Result
724
+ * @param initCallCallback InitCall callback
725
+ * @param silent Silent without any popups
726
+ */
727
+ doRefreshTokenResult(result, initCallCallback, silent = false) {
728
+ if (result === true)
729
+ return;
730
+ if (initCallCallback &&
731
+ typeof result === 'object' &&
732
+ !(result instanceof restclient_1.ApiDataError) &&
733
+ this.checkDeviceResult(result)) {
734
+ this.initCall(initCallCallback, true);
735
+ return;
736
+ }
737
+ const message = this.formatRefreshTokenResult(result);
738
+ if (message == null || silent) {
739
+ this.refreshTokenFailed();
740
+ return;
741
+ }
742
+ this.notifier.alert(message, () => {
743
+ this.refreshTokenFailed();
744
+ });
745
+ }
702
746
  /**
703
747
  * Format refresh token result
704
748
  * @param result Refresh token result
@@ -41,6 +41,7 @@
41
41
  "emailAddresses": "Email addresses",
42
42
  "enabled": "Enabled",
43
43
  "entityStatus": "Status",
44
+ "environmentChanged": "The operating environment has changed, please log in again",
44
45
  "etsoo": "ETSOO",
45
46
  "expiry": "Expiry",
46
47
  "failed": "Operation failed",
@@ -41,6 +41,7 @@
41
41
  "emailAddresses": "电子邮箱",
42
42
  "enabled": "已启用",
43
43
  "entityStatus": "状态",
44
+ "environmentChanged": "运行环境已改变,请重新登录",
44
45
  "etsoo": "亿速思维",
45
46
  "expiry": "到期时间",
46
47
  "failed": "操作失败",
@@ -41,6 +41,7 @@
41
41
  "emailAddresses": "電子郵箱",
42
42
  "enabled": "已啟用",
43
43
  "entityStatus": "狀態",
44
+ "environmentChanged": "運行環境已改變,請重新登錄",
44
45
  "etsoo": "億速思維",
45
46
  "expiry": "到期時間",
46
47
  "failed": "操作失敗",
@@ -212,6 +212,13 @@ export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallP
212
212
  * @returns Result
213
213
  */
214
214
  formatNumber(input?: number | bigint, options?: Intl.NumberFormatOptions): string | undefined;
215
+ /**
216
+ * Do refresh token result
217
+ * @param result Result
218
+ * @param initCallCallback InitCall callback
219
+ * @param silent Silent without any popups
220
+ */
221
+ doRefreshTokenResult(result: RefreshTokenResult, initCallCallback?: (result: boolean) => void, silent?: boolean): void;
215
222
  /**
216
223
  * Format refresh token result
217
224
  * @param result Refresh token result
@@ -521,6 +528,12 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
521
528
  * @returns Result
522
529
  */
523
530
  protected apiInitCall(data: InitCallDto): Promise<InitCallResult | undefined>;
531
+ /**
532
+ * Check the action result is about device invalid
533
+ * @param result Action result
534
+ * @returns true means device is invalid
535
+ */
536
+ protected checkDeviceResult(result: IActionResult): boolean;
524
537
  /**
525
538
  * Init call
526
539
  * @param callback Callback
@@ -642,6 +655,17 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
642
655
  * @returns Error message
643
656
  */
644
657
  formatError(error: ApiDataError): string;
658
+ /**
659
+ * Refresh token failed
660
+ */
661
+ protected refreshTokenFailed(): void;
662
+ /**
663
+ * Do refresh token result
664
+ * @param result Result
665
+ * @param initCallCallback InitCall callback
666
+ * @param silent Silent without any popups
667
+ */
668
+ doRefreshTokenResult(result: RefreshTokenResult, initCallCallback?: (result: boolean) => void, silent?: boolean): void;
645
669
  /**
646
670
  * Format refresh token result
647
671
  * @param result Refresh token result
@@ -266,6 +266,16 @@ export class CoreApp {
266
266
  async apiInitCall(data) {
267
267
  return await this.api.put(this.initCallApi, data);
268
268
  }
269
+ /**
270
+ * Check the action result is about device invalid
271
+ * @param result Action result
272
+ * @returns true means device is invalid
273
+ */
274
+ checkDeviceResult(result) {
275
+ if (result.type === 'NoValidData' && result.field === 'Device')
276
+ return true;
277
+ return false;
278
+ }
269
279
  /**
270
280
  * Init call
271
281
  * @param callback Callback
@@ -275,8 +285,10 @@ export class CoreApp {
275
285
  async initCall(callback, resetKeys) {
276
286
  var _a;
277
287
  // Reset keys
278
- if (resetKeys)
288
+ if (resetKeys) {
289
+ this._deviceId = '';
279
290
  this.resetKeys();
291
+ }
280
292
  // Passphrase exists?
281
293
  if (this.passphrase) {
282
294
  if (callback)
@@ -696,6 +708,38 @@ export class CoreApp {
696
708
  formatError(error) {
697
709
  return error.toString();
698
710
  }
711
+ /**
712
+ * Refresh token failed
713
+ */
714
+ refreshTokenFailed() {
715
+ this.userUnauthorized();
716
+ this.toLoginPage();
717
+ }
718
+ /**
719
+ * Do refresh token result
720
+ * @param result Result
721
+ * @param initCallCallback InitCall callback
722
+ * @param silent Silent without any popups
723
+ */
724
+ doRefreshTokenResult(result, initCallCallback, silent = false) {
725
+ if (result === true)
726
+ return;
727
+ if (initCallCallback &&
728
+ typeof result === 'object' &&
729
+ !(result instanceof ApiDataError) &&
730
+ this.checkDeviceResult(result)) {
731
+ this.initCall(initCallCallback, true);
732
+ return;
733
+ }
734
+ const message = this.formatRefreshTokenResult(result);
735
+ if (message == null || silent) {
736
+ this.refreshTokenFailed();
737
+ return;
738
+ }
739
+ this.notifier.alert(message, () => {
740
+ this.refreshTokenFailed();
741
+ });
742
+ }
699
743
  /**
700
744
  * Format refresh token result
701
745
  * @param result Refresh token result
@@ -41,6 +41,7 @@
41
41
  "emailAddresses": "Email addresses",
42
42
  "enabled": "Enabled",
43
43
  "entityStatus": "Status",
44
+ "environmentChanged": "The operating environment has changed, please log in again",
44
45
  "etsoo": "ETSOO",
45
46
  "expiry": "Expiry",
46
47
  "failed": "Operation failed",
@@ -41,6 +41,7 @@
41
41
  "emailAddresses": "电子邮箱",
42
42
  "enabled": "已启用",
43
43
  "entityStatus": "状态",
44
+ "environmentChanged": "运行环境已改变,请重新登录",
44
45
  "etsoo": "亿速思维",
45
46
  "expiry": "到期时间",
46
47
  "failed": "操作失败",
@@ -41,6 +41,7 @@
41
41
  "emailAddresses": "電子郵箱",
42
42
  "enabled": "已啟用",
43
43
  "entityStatus": "狀態",
44
+ "environmentChanged": "運行環境已改變,請重新登錄",
44
45
  "etsoo": "億速思維",
45
46
  "expiry": "到期時間",
46
47
  "failed": "操作失敗",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/appscript",
3
- "version": "1.2.65",
3
+ "version": "1.2.68",
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
  "crypto-js": "^4.1.1"
60
60
  },
61
61
  "devDependencies": {
62
- "@babel/cli": "^7.18.9",
63
- "@babel/core": "^7.18.9",
64
- "@babel/plugin-transform-runtime": "^7.18.9",
65
- "@babel/preset-env": "^7.18.9",
62
+ "@babel/cli": "^7.18.10",
63
+ "@babel/core": "^7.18.10",
64
+ "@babel/plugin-transform-runtime": "^7.18.10",
65
+ "@babel/preset-env": "^7.18.10",
66
66
  "@babel/runtime-corejs3": "^7.18.9",
67
67
  "@types/jest": "^28.1.6",
68
- "@typescript-eslint/eslint-plugin": "^5.31.0",
69
- "@typescript-eslint/parser": "^5.31.0",
70
- "eslint": "^8.20.0",
68
+ "@typescript-eslint/eslint-plugin": "^5.32.0",
69
+ "@typescript-eslint/parser": "^5.32.0",
70
+ "eslint": "^8.21.0",
71
71
  "eslint-config-airbnb-base": "^15.0.0",
72
72
  "eslint-plugin-import": "^2.26.0",
73
73
  "jest": "^28.1.3",
@@ -315,6 +315,18 @@ export interface ICoreApp<
315
315
  options?: Intl.NumberFormatOptions
316
316
  ): string | undefined;
317
317
 
318
+ /**
319
+ * Do refresh token result
320
+ * @param result Result
321
+ * @param initCallCallback InitCall callback
322
+ * @param silent Silent without any popups
323
+ */
324
+ doRefreshTokenResult(
325
+ result: RefreshTokenResult,
326
+ initCallCallback?: (result: boolean) => void,
327
+ silent?: boolean
328
+ ): void;
329
+
318
330
  /**
319
331
  * Format refresh token result
320
332
  * @param result Refresh token result
@@ -884,6 +896,17 @@ export abstract class CoreApp<
884
896
  return await this.api.put<InitCallResult>(this.initCallApi, data);
885
897
  }
886
898
 
899
+ /**
900
+ * Check the action result is about device invalid
901
+ * @param result Action result
902
+ * @returns true means device is invalid
903
+ */
904
+ protected checkDeviceResult(result: IActionResult): boolean {
905
+ if (result.type === 'NoValidData' && result.field === 'Device')
906
+ return true;
907
+ return false;
908
+ }
909
+
887
910
  /**
888
911
  * Init call
889
912
  * @param callback Callback
@@ -892,7 +915,10 @@ export abstract class CoreApp<
892
915
  */
893
916
  async initCall(callback?: (result: boolean) => void, resetKeys?: boolean) {
894
917
  // Reset keys
895
- if (resetKeys) this.resetKeys();
918
+ if (resetKeys) {
919
+ this._deviceId = '';
920
+ this.resetKeys();
921
+ }
896
922
 
897
923
  // Passphrase exists?
898
924
  if (this.passphrase) {
@@ -1422,6 +1448,48 @@ export abstract class CoreApp<
1422
1448
  return error.toString();
1423
1449
  }
1424
1450
 
1451
+ /**
1452
+ * Refresh token failed
1453
+ */
1454
+ protected refreshTokenFailed() {
1455
+ this.userUnauthorized();
1456
+ this.toLoginPage();
1457
+ }
1458
+
1459
+ /**
1460
+ * Do refresh token result
1461
+ * @param result Result
1462
+ * @param initCallCallback InitCall callback
1463
+ * @param silent Silent without any popups
1464
+ */
1465
+ doRefreshTokenResult(
1466
+ result: RefreshTokenResult,
1467
+ initCallCallback?: (result: boolean) => void,
1468
+ silent: boolean = false
1469
+ ) {
1470
+ if (result === true) return;
1471
+
1472
+ if (
1473
+ initCallCallback &&
1474
+ typeof result === 'object' &&
1475
+ !(result instanceof ApiDataError) &&
1476
+ this.checkDeviceResult(result)
1477
+ ) {
1478
+ this.initCall(initCallCallback, true);
1479
+ return;
1480
+ }
1481
+
1482
+ const message = this.formatRefreshTokenResult(result);
1483
+ if (message == null || silent) {
1484
+ this.refreshTokenFailed();
1485
+ return;
1486
+ }
1487
+
1488
+ this.notifier.alert(message, () => {
1489
+ this.refreshTokenFailed();
1490
+ });
1491
+ }
1492
+
1425
1493
  /**
1426
1494
  * Format refresh token result
1427
1495
  * @param result Refresh token result
@@ -41,6 +41,7 @@
41
41
  "emailAddresses": "Email addresses",
42
42
  "enabled": "Enabled",
43
43
  "entityStatus": "Status",
44
+ "environmentChanged": "The operating environment has changed, please log in again",
44
45
  "etsoo": "ETSOO",
45
46
  "expiry": "Expiry",
46
47
  "failed": "Operation failed",
@@ -41,6 +41,7 @@
41
41
  "emailAddresses": "电子邮箱",
42
42
  "enabled": "已启用",
43
43
  "entityStatus": "状态",
44
+ "environmentChanged": "运行环境已改变,请重新登录",
44
45
  "etsoo": "亿速思维",
45
46
  "expiry": "到期时间",
46
47
  "failed": "操作失败",
@@ -41,6 +41,7 @@
41
41
  "emailAddresses": "電子郵箱",
42
42
  "enabled": "已啟用",
43
43
  "entityStatus": "狀態",
44
+ "environmentChanged": "運行環境已改變,請重新登錄",
44
45
  "etsoo": "億速思維",
45
46
  "expiry": "到期時間",
46
47
  "failed": "操作失敗",