@etsoo/appscript 1.3.98 → 1.4.0

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.
Files changed (47) hide show
  1. package/__tests__/app/CoreApp.ts +6 -6
  2. package/lib/cjs/app/CoreApp.d.ts +10 -9
  3. package/lib/cjs/app/CoreApp.js +89 -49
  4. package/lib/cjs/app/IApp.d.ts +9 -8
  5. package/lib/cjs/business/ProductUnit.d.ts +8 -1
  6. package/lib/cjs/business/ProductUnit.js +5 -0
  7. package/lib/cjs/erp/AuthApi.js +3 -3
  8. package/lib/cjs/i18n/en.d.ts +2 -2
  9. package/lib/cjs/i18n/en.js +3 -10
  10. package/lib/cjs/i18n/i18nResources.d.ts +3 -0
  11. package/lib/cjs/i18n/i18nResources.js +43 -0
  12. package/lib/cjs/i18n/zhHans.d.ts +2 -2
  13. package/lib/cjs/i18n/zhHans.js +3 -10
  14. package/lib/cjs/i18n/zhHant.d.ts +2 -2
  15. package/lib/cjs/i18n/zhHant.js +3 -10
  16. package/lib/mjs/app/CoreApp.d.ts +10 -9
  17. package/lib/mjs/app/CoreApp.js +45 -28
  18. package/lib/mjs/app/IApp.d.ts +9 -8
  19. package/lib/mjs/business/ProductUnit.d.ts +8 -1
  20. package/lib/mjs/business/ProductUnit.js +5 -0
  21. package/lib/mjs/erp/AuthApi.js +3 -3
  22. package/lib/mjs/i18n/en.d.ts +2 -2
  23. package/lib/mjs/i18n/en.js +3 -7
  24. package/lib/mjs/i18n/i18nResources.d.ts +3 -0
  25. package/lib/mjs/i18n/i18nResources.js +16 -0
  26. package/lib/mjs/i18n/zhHans.d.ts +2 -2
  27. package/lib/mjs/i18n/zhHans.js +3 -7
  28. package/lib/mjs/i18n/zhHant.d.ts +2 -2
  29. package/lib/mjs/i18n/zhHant.js +3 -7
  30. package/package.json +4 -4
  31. package/src/app/CoreApp.ts +64 -40
  32. package/src/app/IApp.ts +19 -8
  33. package/src/business/ProductUnit.ts +7 -1
  34. package/src/erp/AuthApi.ts +3 -3
  35. package/src/i18n/en.json +1 -0
  36. package/src/i18n/en.ts +4 -8
  37. package/src/i18n/i18nResources.ts +19 -0
  38. package/src/i18n/zh-Hans.json +1 -0
  39. package/src/i18n/zh-Hant.json +1 -0
  40. package/src/i18n/zhHans.ts +4 -8
  41. package/src/i18n/zhHant.ts +4 -10
  42. package/lib/cjs/i18n/en.json +0 -226
  43. package/lib/cjs/i18n/zh-Hans.json +0 -226
  44. package/lib/cjs/i18n/zh-Hant.json +0 -225
  45. package/lib/mjs/i18n/en.json +0 -226
  46. package/lib/mjs/i18n/zh-Hans.json +0 -226
  47. package/lib/mjs/i18n/zh-Hant.json +0 -225
@@ -157,25 +157,25 @@ test('Tests for addRootUrl', () => {
157
157
  expect(app.addRootUrl('home')).toBe('/cms/home');
158
158
  });
159
159
 
160
- test('Tests for encrypt / decrypt', () => {
160
+ test('Tests for encrypt / decrypt', async () => {
161
161
  // Arrange
162
162
  const input = 'Hello, world!';
163
163
  const passphrase = 'My password';
164
164
 
165
165
  // Act
166
- const encrypted = app.encrypt(input, passphrase);
167
- const plain = app.decrypt(encrypted, passphrase);
166
+ const encrypted = await app.encrypt(input, passphrase);
167
+ const plain = await app.decrypt(encrypted, passphrase);
168
168
  expect(plain).toEqual(input);
169
169
  });
170
170
 
171
- test('Tests for encryptEnhanced / decryptEnhanced', () => {
171
+ test('Tests for encryptEnhanced / decryptEnhanced', async () => {
172
172
  // Arrange
173
173
  const input = 'Hello, world!';
174
174
  const passphrase = 'My password';
175
175
 
176
176
  // Act
177
- const encrypted = app.encryptEnhanced(input, passphrase);
178
- const plain = app.decryptEnhanced(encrypted, passphrase);
177
+ const encrypted = await app.encryptEnhanced(input, passphrase);
178
+ const plain = await app.decryptEnhanced(encrypted, passphrase);
179
179
  expect(plain).toEqual(input);
180
180
  });
181
181
 
@@ -154,7 +154,7 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
154
154
  /**
155
155
  * Restore settings from persisted source
156
156
  */
157
- protected restore(): boolean;
157
+ protected restore(): Promise<boolean>;
158
158
  /**
159
159
  * Is valid password, override to implement custom check
160
160
  * @param password Input password
@@ -193,7 +193,7 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
193
193
  * @param data Result data
194
194
  * @param timestamp Timestamp
195
195
  */
196
- protected initCallUpdate(data: InitCallResultData, timestamp: number): boolean;
196
+ protected initCallUpdate(data: InitCallResultData, timestamp: number): Promise<boolean>;
197
197
  /**
198
198
  * Init call encrypted fields update
199
199
  * @returns Fields
@@ -219,8 +219,9 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
219
219
  /**
220
220
  * Change culture
221
221
  * @param culture New culture definition
222
+ * @param onReady On ready callback
222
223
  */
223
- changeCulture(culture: DataTypes.CultureDefinition): void;
224
+ changeCulture(culture: DataTypes.CultureDefinition, onReady?: () => void): void;
224
225
  /**
225
226
  * Update current region label
226
227
  */
@@ -245,7 +246,7 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
245
246
  * @param passphrase Secret passphrase
246
247
  * @returns Pure text
247
248
  */
248
- decrypt(messageEncrypted: string, passphrase?: string): string | undefined;
249
+ decrypt(messageEncrypted: string, passphrase?: string): Promise<string | undefined>;
249
250
  /**
250
251
  * Enhanced decrypt message
251
252
  * @param messageEncrypted Encrypted message
@@ -253,7 +254,7 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
253
254
  * @param durationSeconds Duration seconds, <= 12 will be considered as month
254
255
  * @returns Pure text
255
256
  */
256
- decryptEnhanced(messageEncrypted: string, passphrase?: string, durationSeconds?: number): string | undefined;
257
+ decryptEnhanced(messageEncrypted: string, passphrase?: string, durationSeconds?: number): Promise<string | undefined>;
257
258
  /**
258
259
  * Detect IP data, call only one time
259
260
  * @param callback Callback will be called when the IP is ready
@@ -267,7 +268,7 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
267
268
  * @param iterations Iterations, 1000 times, 1 - 99
268
269
  * @returns Result
269
270
  */
270
- encrypt(message: string, passphrase?: string, iterations?: number): string;
271
+ encrypt(message: string, passphrase?: string, iterations?: number): Promise<string>;
271
272
  /**
272
273
  * Enhanced encrypt message
273
274
  * @param message Message
@@ -275,7 +276,7 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
275
276
  * @param iterations Iterations, 1000 times, 1 - 99
276
277
  * @returns Result
277
278
  */
278
- encryptEnhanced(message: string, passphrase?: string, iterations?: number): string;
279
+ encryptEnhanced(message: string, passphrase?: string, iterations?: number): Promise<string>;
279
280
  /**
280
281
  * Enchance secret passphrase
281
282
  * @param passphrase Secret passphrase
@@ -429,14 +430,14 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
429
430
  * @param message Message
430
431
  * @param passphrase Secret passphrase
431
432
  */
432
- hash(message: string, passphrase?: string): string;
433
+ hash(message: string, passphrase?: string): Promise<string>;
433
434
  /**
434
435
  * Hash message Hex, SHA3 or HmacSHA512, 512 as Base64
435
436
  * https://cryptojs.gitbook.io/docs/
436
437
  * @param message Message
437
438
  * @param passphrase Secret passphrase
438
439
  */
439
- hashHex(message: string, passphrase?: string): string;
440
+ hashHex(message: string, passphrase?: string): Promise<string>;
440
441
  /**
441
442
  * Check use has the specific role permission or not
442
443
  * @param roles Roles to check
@@ -1,10 +1,32 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  Object.defineProperty(exports, "__esModule", { value: true });
3
26
  exports.CoreApp = void 0;
4
27
  const notificationbase_1 = require("@etsoo/notificationbase");
5
28
  const restclient_1 = require("@etsoo/restclient");
6
29
  const shared_1 = require("@etsoo/shared");
7
- const crypto_js_1 = require("crypto-js");
8
30
  const AddressRegion_1 = require("../address/AddressRegion");
9
31
  const BridgeUtils_1 = require("../bridges/BridgeUtils");
10
32
  const DataPrivacy_1 = require("../business/DataPrivacy");
@@ -133,10 +155,8 @@ class CoreApp {
133
155
  this.restore();
134
156
  this.setApi(api);
135
157
  const { currentCulture, currentRegion } = settings;
136
- this.changeCulture(currentCulture);
158
+ this.changeCulture(currentCulture, () => this.setup());
137
159
  this.changeRegion(currentRegion);
138
- // Setup callback
139
- this.setup();
140
160
  }
141
161
  getDeviceId() {
142
162
  return this.deviceId.substring(0, 15);
@@ -175,7 +195,7 @@ class CoreApp {
175
195
  /**
176
196
  * Restore settings from persisted source
177
197
  */
178
- restore() {
198
+ async restore() {
179
199
  // Devices
180
200
  const devices = this.storage.getPersistedData(this.fields.devices, []);
181
201
  if (this.deviceId === '') {
@@ -198,7 +218,7 @@ class CoreApp {
198
218
  const passphraseEncrypted = this.storage.getData(this.fields.devicePassphrase);
199
219
  if (passphraseEncrypted) {
200
220
  // this.name to identifier different app's secret
201
- const passphraseDecrypted = this.decrypt(passphraseEncrypted, this.name);
221
+ const passphraseDecrypted = await this.decrypt(passphraseEncrypted, this.name);
202
222
  if (passphraseDecrypted != null) {
203
223
  // Add the device to the list
204
224
  devices.push(d);
@@ -358,7 +378,7 @@ class CoreApp {
358
378
  this.storage.setData(this.fields.deviceId, undefined);
359
379
  return;
360
380
  }
361
- const updateResult = this.initCallUpdate(result.data, data.timestamp);
381
+ const updateResult = await this.initCallUpdate(result.data, data.timestamp);
362
382
  if (!updateResult) {
363
383
  this.notifier.alert(this.get('noData') + '(Update)');
364
384
  }
@@ -370,13 +390,13 @@ class CoreApp {
370
390
  * @param data Result data
371
391
  * @param timestamp Timestamp
372
392
  */
373
- initCallUpdate(data, timestamp) {
393
+ async initCallUpdate(data, timestamp) {
374
394
  // Data check
375
395
  if (data.deviceId == null || data.passphrase == null)
376
396
  return false;
377
397
  // Decrypt
378
398
  // Should be done within 120 seconds after returning from the backend
379
- const passphrase = this.decrypt(data.passphrase, timestamp.toString());
399
+ const passphrase = await this.decrypt(data.passphrase, timestamp.toString());
380
400
  if (passphrase == null)
381
401
  return false;
382
402
  // Update device id and cache it
@@ -391,7 +411,7 @@ class CoreApp {
391
411
  this.storage.setData(this.fields.devicePassphrase, this.encrypt(passphrase, this.name));
392
412
  // Previous passphrase
393
413
  if (data.previousPassphrase) {
394
- const prev = this.decrypt(data.previousPassphrase, timestamp.toString());
414
+ const prev = await this.decrypt(data.previousPassphrase, timestamp.toString());
395
415
  // Update
396
416
  const fields = this.initCallEncryptedUpdateFields();
397
417
  for (const field of fields) {
@@ -406,10 +426,10 @@ class CoreApp {
406
426
  const enhanced = currentValue.indexOf('!') >= 8;
407
427
  let newValueSource;
408
428
  if (enhanced) {
409
- newValueSource = this.decryptEnhanced(currentValue, prev, 12);
429
+ newValueSource = await this.decryptEnhanced(currentValue, prev, 12);
410
430
  }
411
431
  else {
412
- newValueSource = this.decrypt(currentValue, prev);
432
+ newValueSource = await this.decrypt(currentValue, prev);
413
433
  }
414
434
  if (newValueSource == null || newValueSource === '') {
415
435
  // Reset the field
@@ -417,8 +437,8 @@ class CoreApp {
417
437
  continue;
418
438
  }
419
439
  const newValue = enhanced
420
- ? this.encryptEnhanced(newValueSource)
421
- : this.encrypt(newValueSource);
440
+ ? await this.encryptEnhanced(newValueSource)
441
+ : await this.encrypt(newValueSource);
422
442
  this.storage.setData(field, newValue);
423
443
  }
424
444
  }
@@ -451,10 +471,10 @@ class CoreApp {
451
471
  this.authorized = token != null;
452
472
  // Token
453
473
  this.api.authorize(this.settings.authScheme, token);
454
- // Cover the current value
474
+ // Overwrite the current value
455
475
  if (refreshToken !== '') {
456
476
  if (refreshToken != null)
457
- refreshToken = this.encrypt(refreshToken);
477
+ this.encrypt(refreshToken).then((result) => this.storage.setData(this.fields.headerToken, result));
458
478
  this.storage.setData(this.fields.headerToken, refreshToken);
459
479
  }
460
480
  // Reset tryLogin state
@@ -503,8 +523,9 @@ class CoreApp {
503
523
  /**
504
524
  * Change culture
505
525
  * @param culture New culture definition
526
+ * @param onReady On ready callback
506
527
  */
507
- changeCulture(culture) {
528
+ changeCulture(culture, onReady) {
508
529
  // Name
509
530
  const { name } = culture;
510
531
  // Same?
@@ -519,7 +540,19 @@ class CoreApp {
519
540
  this._culture = name;
520
541
  // Hold the current resources
521
542
  this.settings.currentCulture = culture;
522
- this.updateRegionLabel();
543
+ if (typeof culture.resources !== 'object') {
544
+ culture.resources().then((result) => {
545
+ culture.resources = result;
546
+ this.updateRegionLabel();
547
+ if (onReady)
548
+ onReady();
549
+ });
550
+ }
551
+ else {
552
+ this.updateRegionLabel();
553
+ if (onReady)
554
+ onReady();
555
+ }
523
556
  }
524
557
  /**
525
558
  * Update current region label
@@ -562,25 +595,26 @@ class CoreApp {
562
595
  * @param passphrase Secret passphrase
563
596
  * @returns Pure text
564
597
  */
565
- decrypt(messageEncrypted, passphrase) {
598
+ async decrypt(messageEncrypted, passphrase) {
566
599
  // Iterations
567
600
  const iterations = parseInt(messageEncrypted.substring(0, 2), 10);
568
601
  if (isNaN(iterations))
569
602
  return undefined;
603
+ const { PBKDF2, algo, enc, AES, pad, mode } = await Promise.resolve().then(() => __importStar(require('crypto-js')));
570
604
  try {
571
- const salt = crypto_js_1.enc.Hex.parse(messageEncrypted.substring(2, 34));
572
- const iv = crypto_js_1.enc.Hex.parse(messageEncrypted.substring(34, 66));
605
+ const salt = enc.Hex.parse(messageEncrypted.substring(2, 34));
606
+ const iv = enc.Hex.parse(messageEncrypted.substring(34, 66));
573
607
  const encrypted = messageEncrypted.substring(66);
574
- const key = (0, crypto_js_1.PBKDF2)(passphrase !== null && passphrase !== void 0 ? passphrase : this.passphrase, salt, {
608
+ const key = PBKDF2(passphrase !== null && passphrase !== void 0 ? passphrase : this.passphrase, salt, {
575
609
  keySize: 8,
576
- hasher: crypto_js_1.algo.SHA256,
610
+ hasher: algo.SHA256,
577
611
  iterations: 1000 * iterations
578
612
  });
579
- return crypto_js_1.AES.decrypt(encrypted, key, {
613
+ return AES.decrypt(encrypted, key, {
580
614
  iv,
581
- padding: crypto_js_1.pad.Pkcs7,
582
- mode: crypto_js_1.mode.CBC
583
- }).toString(crypto_js_1.enc.Utf8);
615
+ padding: pad.Pkcs7,
616
+ mode: mode.CBC
617
+ }).toString(enc.Utf8);
584
618
  }
585
619
  catch (e) {
586
620
  console.log('decrypt', e);
@@ -594,7 +628,7 @@ class CoreApp {
594
628
  * @param durationSeconds Duration seconds, <= 12 will be considered as month
595
629
  * @returns Pure text
596
630
  */
597
- decryptEnhanced(messageEncrypted, passphrase, durationSeconds) {
631
+ async decryptEnhanced(messageEncrypted, passphrase, durationSeconds) {
598
632
  // Timestamp splitter
599
633
  const pos = messageEncrypted.indexOf('!');
600
634
  // Miliseconds chars are longer than 8
@@ -615,7 +649,7 @@ class CoreApp {
615
649
  }
616
650
  const message = messageEncrypted.substring(pos + 1);
617
651
  passphrase = this.encryptionEnhance(passphrase !== null && passphrase !== void 0 ? passphrase : this.passphrase, timestamp);
618
- return this.decrypt(message, passphrase);
652
+ return await this.decrypt(message, passphrase);
619
653
  }
620
654
  catch (e) {
621
655
  console.log('decryptEnhanced', e);
@@ -662,24 +696,25 @@ class CoreApp {
662
696
  * @param iterations Iterations, 1000 times, 1 - 99
663
697
  * @returns Result
664
698
  */
665
- encrypt(message, passphrase, iterations) {
699
+ async encrypt(message, passphrase, iterations) {
666
700
  // Default 1 * 1000
667
701
  iterations !== null && iterations !== void 0 ? iterations : (iterations = 1);
702
+ const { lib, PBKDF2, algo, enc, AES, pad, mode } = await Promise.resolve().then(() => __importStar(require('crypto-js')));
668
703
  const bits = 16; // 128 / 8
669
- const salt = crypto_js_1.lib.WordArray.random(bits);
670
- const key = (0, crypto_js_1.PBKDF2)(passphrase !== null && passphrase !== void 0 ? passphrase : this.passphrase, salt, {
704
+ const salt = lib.WordArray.random(bits);
705
+ const key = PBKDF2(passphrase !== null && passphrase !== void 0 ? passphrase : this.passphrase, salt, {
671
706
  keySize: 8,
672
- hasher: crypto_js_1.algo.SHA256,
707
+ hasher: algo.SHA256,
673
708
  iterations: 1000 * iterations
674
709
  });
675
- const iv = crypto_js_1.lib.WordArray.random(bits);
710
+ const iv = lib.WordArray.random(bits);
676
711
  return (iterations.toString().padStart(2, '0') +
677
- salt.toString(crypto_js_1.enc.Hex) +
678
- iv.toString(crypto_js_1.enc.Hex) +
679
- crypto_js_1.AES.encrypt(message, key, {
712
+ salt.toString(enc.Hex) +
713
+ iv.toString(enc.Hex) +
714
+ AES.encrypt(message, key, {
680
715
  iv,
681
- padding: crypto_js_1.pad.Pkcs7,
682
- mode: crypto_js_1.mode.CBC
716
+ padding: pad.Pkcs7,
717
+ mode: mode.CBC
683
718
  }).toString() // enc.Base64
684
719
  );
685
720
  }
@@ -690,11 +725,12 @@ class CoreApp {
690
725
  * @param iterations Iterations, 1000 times, 1 - 99
691
726
  * @returns Result
692
727
  */
693
- encryptEnhanced(message, passphrase, iterations) {
728
+ async encryptEnhanced(message, passphrase, iterations) {
694
729
  // Timestamp
695
730
  const timestamp = shared_1.Utils.numberToChars(new Date().getTime());
696
731
  passphrase = this.encryptionEnhance(passphrase !== null && passphrase !== void 0 ? passphrase : this.passphrase, timestamp);
697
- return timestamp + '!' + this.encrypt(message, passphrase, iterations);
732
+ const result = await this.encrypt(message, passphrase, iterations);
733
+ return timestamp + '!' + result;
698
734
  }
699
735
  /**
700
736
  * Enchance secret passphrase
@@ -854,7 +890,9 @@ class CoreApp {
854
890
  * @returns Resource
855
891
  */
856
892
  get(key) {
857
- const value = this.settings.currentCulture.resources[key];
893
+ // Make sure the resource files are loaded first
894
+ const resources = this.settings.currentCulture.resources;
895
+ const value = typeof resources === 'object' ? resources[key] : undefined;
858
896
  if (value == null)
859
897
  return undefined;
860
898
  // No strict type convertion here
@@ -1031,11 +1069,12 @@ class CoreApp {
1031
1069
  * @param message Message
1032
1070
  * @param passphrase Secret passphrase
1033
1071
  */
1034
- hash(message, passphrase) {
1072
+ async hash(message, passphrase) {
1073
+ const { SHA3, enc, HmacSHA512 } = await Promise.resolve().then(() => __importStar(require('crypto-js')));
1035
1074
  if (passphrase == null)
1036
- return (0, crypto_js_1.SHA3)(message, { outputLength: 512 }).toString(crypto_js_1.enc.Base64);
1075
+ return SHA3(message, { outputLength: 512 }).toString(enc.Base64);
1037
1076
  else
1038
- return (0, crypto_js_1.HmacSHA512)(message, passphrase).toString(crypto_js_1.enc.Base64);
1077
+ return HmacSHA512(message, passphrase).toString(enc.Base64);
1039
1078
  }
1040
1079
  /**
1041
1080
  * Hash message Hex, SHA3 or HmacSHA512, 512 as Base64
@@ -1043,11 +1082,12 @@ class CoreApp {
1043
1082
  * @param message Message
1044
1083
  * @param passphrase Secret passphrase
1045
1084
  */
1046
- hashHex(message, passphrase) {
1085
+ async hashHex(message, passphrase) {
1086
+ const { SHA3, enc, HmacSHA512 } = await Promise.resolve().then(() => __importStar(require('crypto-js')));
1047
1087
  if (passphrase == null)
1048
- return (0, crypto_js_1.SHA3)(message, { outputLength: 512 }).toString(crypto_js_1.enc.Hex);
1088
+ return SHA3(message, { outputLength: 512 }).toString(enc.Hex);
1049
1089
  else
1050
- return (0, crypto_js_1.HmacSHA512)(message, passphrase).toString(crypto_js_1.enc.Hex);
1090
+ return HmacSHA512(message, passphrase).toString(enc.Hex);
1051
1091
  }
1052
1092
  /**
1053
1093
  * Check use has the specific role permission or not
@@ -1218,7 +1258,7 @@ class CoreApp {
1218
1258
  this.authorize(user.token, refreshToken);
1219
1259
  }
1220
1260
  else {
1221
- this.cachedRefreshToken = this.encrypt(refreshToken);
1261
+ this.encrypt(refreshToken).then((result) => (this.cachedRefreshToken = result));
1222
1262
  this.authorize(user.token, undefined);
1223
1263
  }
1224
1264
  }
@@ -55,7 +55,7 @@ export declare const appFields: readonly ["headerToken", "serversideDeviceId", "
55
55
  * Basic type template
56
56
  */
57
57
  export type IAppFields = {
58
- [key in typeof appFields[number]]: string;
58
+ [key in (typeof appFields)[number]]: string;
59
59
  };
60
60
  /**
61
61
  * Application interface, for generic version, see ICoreApp
@@ -159,8 +159,9 @@ export interface IApp {
159
159
  /**
160
160
  * Change culture
161
161
  * @param culture New culture definition
162
+ * @param onReady On ready callback
162
163
  */
163
- changeCulture(culture: DataTypes.CultureDefinition): void;
164
+ changeCulture(culture: DataTypes.CultureDefinition, onReady?: () => void): void;
164
165
  /**
165
166
  * Check the action result is about device invalid
166
167
  * @param result Action result
@@ -187,7 +188,7 @@ export interface IApp {
187
188
  * @param passphrase Secret passphrase
188
189
  * @returns Pure text
189
190
  */
190
- decrypt(messageEncrypted: string, passphrase?: string): string | undefined;
191
+ decrypt(messageEncrypted: string, passphrase?: string): Promise<string | undefined>;
191
192
  /**
192
193
  * Enhanced decrypt message
193
194
  * @param messageEncrypted Encrypted message
@@ -195,7 +196,7 @@ export interface IApp {
195
196
  * @param durationSeconds Duration seconds, <= 12 will be considered as month
196
197
  * @returns Pure text
197
198
  */
198
- decryptEnhanced(messageEncrypted: string, passphrase?: string, durationSeconds?: number): string | undefined;
199
+ decryptEnhanced(messageEncrypted: string, passphrase?: string, durationSeconds?: number): Promise<string | undefined>;
199
200
  /**
200
201
  * Detect IP data, call only one time
201
202
  * @param callback Callback will be called when the IP is ready
@@ -208,7 +209,7 @@ export interface IApp {
208
209
  * @param iterations Iterations, 1000 times, 1 - 99
209
210
  * @returns Result
210
211
  */
211
- encrypt(message: string, passphrase?: string, iterations?: number): string;
212
+ encrypt(message: string, passphrase?: string, iterations?: number): Promise<string>;
212
213
  /**
213
214
  * Enhanced encrypt message
214
215
  * @param message Message
@@ -216,7 +217,7 @@ export interface IApp {
216
217
  * @param iterations Iterations, 1000 times, 1 - 99
217
218
  * @returns Result
218
219
  */
219
- encryptEnhanced(message: string, passphrase?: string, iterations?: number): string;
220
+ encryptEnhanced(message: string, passphrase?: string, iterations?: number): Promise<string>;
220
221
  /**
221
222
  * Format date to string
222
223
  * @param input Input date
@@ -365,14 +366,14 @@ export interface IApp {
365
366
  * @param message Message
366
367
  * @param passphrase Secret passphrase
367
368
  */
368
- hash(message: string, passphrase?: string): string;
369
+ hash(message: string, passphrase?: string): Promise<string>;
369
370
  /**
370
371
  * Hash message Hex, SHA3 or HmacSHA512, 512 as Base64
371
372
  * https://cryptojs.gitbook.io/docs/
372
373
  * @param message Message
373
374
  * @param passphrase Secret passphrase
374
375
  */
375
- hashHex(message: string, passphrase?: string): string;
376
+ hashHex(message: string, passphrase?: string): Promise<string>;
376
377
  /**
377
378
  * Check use has the specific role permission or not
378
379
  * @param roles Roles to check
@@ -20,7 +20,12 @@ declare enum ProductAssetUnit {
20
20
  * Time
21
21
  * 次
22
22
  */
23
- TIME = 99
23
+ TIME = 99,
24
+ /**
25
+ * Money
26
+ * 储值
27
+ */
28
+ MONEY = 100
24
29
  }
25
30
  /**
26
31
  * Product weight units
@@ -60,6 +65,7 @@ export declare const ProductUnit: {
60
65
  KILOGRAM: ProductWeightUnit.KILOGRAM;
61
66
  TON: ProductWeightUnit.TON;
62
67
  TIME: ProductAssetUnit.TIME;
68
+ MONEY: ProductAssetUnit.MONEY;
63
69
  HOUR: RepeatOption.HOUR;
64
70
  DAY: RepeatOption.DAY;
65
71
  YEAR: RepeatOption.YEAR;
@@ -80,6 +86,7 @@ export type ProductUnit = ProductBaseUnit | RepeatOption | ProductAssetUnit | Pr
80
86
  export declare const AssetUnits: {
81
87
  [x: number]: string;
82
88
  TIME: ProductAssetUnit.TIME;
89
+ MONEY: ProductAssetUnit.MONEY;
83
90
  HOUR: RepeatOption.HOUR;
84
91
  DAY: RepeatOption.DAY;
85
92
  YEAR: RepeatOption.YEAR;
@@ -26,6 +26,11 @@ var ProductAssetUnit;
26
26
  * 次
27
27
  */
28
28
  ProductAssetUnit[ProductAssetUnit["TIME"] = 99] = "TIME";
29
+ /**
30
+ * Money
31
+ * 储值
32
+ */
33
+ ProductAssetUnit[ProductAssetUnit["MONEY"] = 100] = "MONEY";
29
34
  })(ProductAssetUnit || (ProductAssetUnit = {}));
30
35
  /**
31
36
  * Product weight units
@@ -26,15 +26,15 @@ class AuthApi extends BaseApi_1.BaseApi {
26
26
  * @param payload Payload
27
27
  * @returns Result
28
28
  */
29
- loginId(id, payload) {
29
+ async loginId(id, payload) {
30
30
  const { deviceId, region } = this.app;
31
- id = this.app.encrypt(id);
31
+ id = await this.app.encrypt(id);
32
32
  const rq = {
33
33
  id,
34
34
  deviceId,
35
35
  region
36
36
  };
37
- return this.api.get('Auth/LoginId', rq, payload);
37
+ return await this.api.get('Auth/LoginId', rq, payload);
38
38
  }
39
39
  /**
40
40
  * Reset password
@@ -1,7 +1,7 @@
1
- import { DataTypes } from '@etsoo/shared';
1
+ import { i18nResource } from './i18nResources';
2
2
  /**
3
3
  * Get en neutral culture
4
4
  * @param localResources Local resources
5
5
  * @returns Full culture
6
6
  */
7
- export declare const en: (localResources: object) => DataTypes.CultureDefinition;
7
+ export declare const en: (resources: i18nResource) => import("@etsoo/shared").DataTypes.CultureDefinition<import("@etsoo/shared").DataTypes.StringRecord>;
@@ -1,19 +1,12 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.en = void 0;
7
- const en_json_1 = __importDefault(require("./en.json"));
4
+ const shared_1 = require("@etsoo/shared");
5
+ const i18nResources_1 = require("./i18nResources");
8
6
  /**
9
7
  * Get en neutral culture
10
8
  * @param localResources Local resources
11
9
  * @returns Full culture
12
10
  */
13
- const en = (localResources) => ({
14
- name: 'en',
15
- label: 'English',
16
- resources: { ...en_json_1.default, ...localResources },
17
- compatibleNames: []
18
- });
11
+ const en = (resources) => shared_1.DomUtils.en((0, i18nResources_1.i18nResourceCreator)('./en.json', resources));
19
12
  exports.en = en;
@@ -0,0 +1,3 @@
1
+ import { DataTypes } from '@etsoo/shared';
2
+ export type i18nResource = object | (() => Promise<object>);
3
+ export declare function i18nResourceCreator(file: string, resources: i18nResource): () => Promise<DataTypes.StringRecord>;
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.i18nResourceCreator = void 0;
27
+ function i18nResourceCreator(file, resources) {
28
+ return async () => {
29
+ const [r1, r2] = await Promise.all([
30
+ Promise.resolve(`${file}`).then(s => __importStar(require(s))),
31
+ new Promise((resolve) => {
32
+ if (typeof resources === 'object') {
33
+ resolve(resources);
34
+ }
35
+ else {
36
+ resources().then((result) => resolve(result));
37
+ }
38
+ })
39
+ ]);
40
+ return { ...r1, ...r2 };
41
+ };
42
+ }
43
+ exports.i18nResourceCreator = i18nResourceCreator;
@@ -1,7 +1,7 @@
1
- import { DataTypes } from '@etsoo/shared';
1
+ import { i18nResource } from './i18nResources';
2
2
  /**
3
3
  * Get zh-Hans neutral cultrue
4
4
  * @param localResources Local resources
5
5
  * @returns Full culture
6
6
  */
7
- export declare const zhHans: (localResources: {}) => DataTypes.CultureDefinition;
7
+ export declare const zhHans: (resources: i18nResource) => import("@etsoo/shared").DataTypes.CultureDefinition<import("@etsoo/shared").DataTypes.StringRecord>;