@etsoo/appscript 1.2.64 → 1.2.67

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.
@@ -160,6 +160,12 @@ test('Tests for getUnitLabel', () => {
160
160
  expect(app.getUnitLabel(12, true)).toBe('每年');
161
161
  });
162
162
 
163
+ test('Tests for isValidPassword', () => {
164
+ expect(app.isValidPassword('12345678')).toBeFalsy();
165
+ expect(app.isValidPassword('abcd3')).toBeFalsy();
166
+ expect(app.isValidPassword('1234abcd')).toBeTruthy();
167
+ });
168
+
163
169
  test('Tests for getRepeatOptions', () => {
164
170
  const options = BusinessUtils.getRepeatOptions(app.labelDelegate, [
165
171
  'MONTH',
@@ -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
@@ -303,6 +310,11 @@ export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallP
303
310
  * @returns Result
304
311
  */
305
312
  initCall(callback?: (result: boolean) => void, resetKeys?: boolean): Promise<void>;
313
+ /**
314
+ * Is valid password, override to implement custom check
315
+ * @param password Input password
316
+ */
317
+ isValidPassword(password: string): boolean;
306
318
  /**
307
319
  * Callback where exit a page
308
320
  */
@@ -496,6 +508,11 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
496
508
  * Restore settings from persisted source
497
509
  */
498
510
  protected restore(): boolean;
511
+ /**
512
+ * Is valid password, override to implement custom check
513
+ * @param password Input password
514
+ */
515
+ isValidPassword(password: string): boolean;
499
516
  /**
500
517
  * Persist settings to source when application exit
501
518
  */
@@ -511,6 +528,12 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
511
528
  * @returns Result
512
529
  */
513
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;
514
537
  /**
515
538
  * Init call
516
539
  * @param callback Callback
@@ -632,6 +655,17 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
632
655
  * @returns Error message
633
656
  */
634
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;
635
669
  /**
636
670
  * Format refresh token result
637
671
  * @param result Refresh token result
@@ -195,6 +195,20 @@ class CoreApp {
195
195
  }
196
196
  return false;
197
197
  }
198
+ /**
199
+ * Is valid password, override to implement custom check
200
+ * @param password Input password
201
+ */
202
+ isValidPassword(password) {
203
+ // Length check
204
+ if (password.length < 6)
205
+ return false;
206
+ // One letter and number required
207
+ if (/\d+/gi.test(password) && /[a-z]+/gi.test(password)) {
208
+ return true;
209
+ }
210
+ return false;
211
+ }
198
212
  /**
199
213
  * Persist settings to source when application exit
200
214
  */
@@ -255,6 +269,16 @@ class CoreApp {
255
269
  async apiInitCall(data) {
256
270
  return await this.api.put(this.initCallApi, data);
257
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
+ }
258
282
  /**
259
283
  * Init call
260
284
  * @param callback Callback
@@ -264,8 +288,10 @@ class CoreApp {
264
288
  async initCall(callback, resetKeys) {
265
289
  var _a;
266
290
  // Reset keys
267
- if (resetKeys)
291
+ if (resetKeys) {
292
+ this._deviceId = '';
268
293
  this.resetKeys();
294
+ }
269
295
  // Passphrase exists?
270
296
  if (this.passphrase) {
271
297
  if (callback)
@@ -685,6 +711,38 @@ class CoreApp {
685
711
  formatError(error) {
686
712
  return error.toString();
687
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
+ }
688
746
  /**
689
747
  * Format refresh token result
690
748
  * @param result Refresh token result
@@ -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
@@ -303,6 +310,11 @@ export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallP
303
310
  * @returns Result
304
311
  */
305
312
  initCall(callback?: (result: boolean) => void, resetKeys?: boolean): Promise<void>;
313
+ /**
314
+ * Is valid password, override to implement custom check
315
+ * @param password Input password
316
+ */
317
+ isValidPassword(password: string): boolean;
306
318
  /**
307
319
  * Callback where exit a page
308
320
  */
@@ -496,6 +508,11 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
496
508
  * Restore settings from persisted source
497
509
  */
498
510
  protected restore(): boolean;
511
+ /**
512
+ * Is valid password, override to implement custom check
513
+ * @param password Input password
514
+ */
515
+ isValidPassword(password: string): boolean;
499
516
  /**
500
517
  * Persist settings to source when application exit
501
518
  */
@@ -511,6 +528,12 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
511
528
  * @returns Result
512
529
  */
513
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;
514
537
  /**
515
538
  * Init call
516
539
  * @param callback Callback
@@ -632,6 +655,17 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
632
655
  * @returns Error message
633
656
  */
634
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;
635
669
  /**
636
670
  * Format refresh token result
637
671
  * @param result Refresh token result
@@ -192,6 +192,20 @@ export class CoreApp {
192
192
  }
193
193
  return false;
194
194
  }
195
+ /**
196
+ * Is valid password, override to implement custom check
197
+ * @param password Input password
198
+ */
199
+ isValidPassword(password) {
200
+ // Length check
201
+ if (password.length < 6)
202
+ return false;
203
+ // One letter and number required
204
+ if (/\d+/gi.test(password) && /[a-z]+/gi.test(password)) {
205
+ return true;
206
+ }
207
+ return false;
208
+ }
195
209
  /**
196
210
  * Persist settings to source when application exit
197
211
  */
@@ -252,6 +266,16 @@ export class CoreApp {
252
266
  async apiInitCall(data) {
253
267
  return await this.api.put(this.initCallApi, data);
254
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
+ }
255
279
  /**
256
280
  * Init call
257
281
  * @param callback Callback
@@ -261,8 +285,10 @@ export class CoreApp {
261
285
  async initCall(callback, resetKeys) {
262
286
  var _a;
263
287
  // Reset keys
264
- if (resetKeys)
288
+ if (resetKeys) {
289
+ this._deviceId = '';
265
290
  this.resetKeys();
291
+ }
266
292
  // Passphrase exists?
267
293
  if (this.passphrase) {
268
294
  if (callback)
@@ -682,6 +708,38 @@ export class CoreApp {
682
708
  formatError(error) {
683
709
  return error.toString();
684
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
+ }
685
743
  /**
686
744
  * Format refresh token result
687
745
  * @param result Refresh token result
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/appscript",
3
- "version": "1.2.64",
3
+ "version": "1.2.67",
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
@@ -420,6 +432,12 @@ export interface ICoreApp<
420
432
  resetKeys?: boolean
421
433
  ): Promise<void>;
422
434
 
435
+ /**
436
+ * Is valid password, override to implement custom check
437
+ * @param password Input password
438
+ */
439
+ isValidPassword(password: string): boolean;
440
+
423
441
  /**
424
442
  * Callback where exit a page
425
443
  */
@@ -795,6 +813,22 @@ export abstract class CoreApp<
795
813
  return false;
796
814
  }
797
815
 
816
+ /**
817
+ * Is valid password, override to implement custom check
818
+ * @param password Input password
819
+ */
820
+ isValidPassword(password: string) {
821
+ // Length check
822
+ if (password.length < 6) return false;
823
+
824
+ // One letter and number required
825
+ if (/\d+/gi.test(password) && /[a-z]+/gi.test(password)) {
826
+ return true;
827
+ }
828
+
829
+ return false;
830
+ }
831
+
798
832
  /**
799
833
  * Persist settings to source when application exit
800
834
  */
@@ -862,6 +896,17 @@ export abstract class CoreApp<
862
896
  return await this.api.put<InitCallResult>(this.initCallApi, data);
863
897
  }
864
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
+
865
910
  /**
866
911
  * Init call
867
912
  * @param callback Callback
@@ -870,7 +915,10 @@ export abstract class CoreApp<
870
915
  */
871
916
  async initCall(callback?: (result: boolean) => void, resetKeys?: boolean) {
872
917
  // Reset keys
873
- if (resetKeys) this.resetKeys();
918
+ if (resetKeys) {
919
+ this._deviceId = '';
920
+ this.resetKeys();
921
+ }
874
922
 
875
923
  // Passphrase exists?
876
924
  if (this.passphrase) {
@@ -1400,6 +1448,48 @@ export abstract class CoreApp<
1400
1448
  return error.toString();
1401
1449
  }
1402
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
+
1403
1493
  /**
1404
1494
  * Format refresh token result
1405
1495
  * @param result Refresh token result