@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
@@ -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.zhHans = void 0;
7
- const zh_Hans_json_1 = __importDefault(require("./zh-Hans.json"));
4
+ const shared_1 = require("@etsoo/shared");
5
+ const i18nResources_1 = require("./i18nResources");
8
6
  /**
9
7
  * Get zh-Hans neutral cultrue
10
8
  * @param localResources Local resources
11
9
  * @returns Full culture
12
10
  */
13
- const zhHans = (localResources) => ({
14
- name: 'zh-Hans',
15
- label: '简体中文',
16
- resources: { ...zh_Hans_json_1.default, ...localResources },
17
- compatibleNames: ['zh-CN', 'zh-SG']
18
- });
11
+ const zhHans = (resources) => shared_1.DomUtils.en((0, i18nResources_1.i18nResourceCreator)('./zh-Hans.json', resources));
19
12
  exports.zhHans = zhHans;
@@ -1,7 +1,7 @@
1
- import { DataTypes } from '@etsoo/shared';
1
+ import { i18nResource } from './i18nResources';
2
2
  /**
3
3
  * Get zh-Hant neutral cultrue
4
4
  * @param localResources Local resources
5
5
  * @returns Full culture
6
6
  */
7
- export declare const zhHant: (localResources: object) => DataTypes.CultureDefinition;
7
+ export declare const zhHant: (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.zhHant = void 0;
7
- const zh_Hant_json_1 = __importDefault(require("./zh-Hant.json"));
4
+ const shared_1 = require("@etsoo/shared");
5
+ const i18nResources_1 = require("./i18nResources");
8
6
  /**
9
7
  * Get zh-Hant neutral cultrue
10
8
  * @param localResources Local resources
11
9
  * @returns Full culture
12
10
  */
13
- const zhHant = (localResources) => ({
14
- name: 'zh-Hant',
15
- label: '繁體中文',
16
- resources: { ...zh_Hant_json_1.default, ...localResources },
17
- compatibleNames: ['zh-HK', 'zh-TW', 'zh-MO']
18
- });
11
+ const zhHant = (resources) => shared_1.DomUtils.en((0, i18nResources_1.i18nResourceCreator)('./zh-Hant.json', resources));
19
12
  exports.zhHant = zhHant;
@@ -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,7 +1,6 @@
1
1
  import { NotificationAlign, NotificationMessageType } from '@etsoo/notificationbase';
2
2
  import { ApiDataError } from '@etsoo/restclient';
3
3
  import { DataTypes, DateUtils, DomUtils, NumberUtils, Utils } from '@etsoo/shared';
4
- import { AES, algo, enc, HmacSHA512, lib, mode, pad, PBKDF2, SHA3 } from 'crypto-js';
5
4
  import { AddressRegion } from '../address/AddressRegion';
6
5
  import { BridgeUtils } from '../bridges/BridgeUtils';
7
6
  import { DataPrivacy } from '../business/DataPrivacy';
@@ -130,10 +129,8 @@ export class CoreApp {
130
129
  this.restore();
131
130
  this.setApi(api);
132
131
  const { currentCulture, currentRegion } = settings;
133
- this.changeCulture(currentCulture);
132
+ this.changeCulture(currentCulture, () => this.setup());
134
133
  this.changeRegion(currentRegion);
135
- // Setup callback
136
- this.setup();
137
134
  }
138
135
  getDeviceId() {
139
136
  return this.deviceId.substring(0, 15);
@@ -172,7 +169,7 @@ export class CoreApp {
172
169
  /**
173
170
  * Restore settings from persisted source
174
171
  */
175
- restore() {
172
+ async restore() {
176
173
  // Devices
177
174
  const devices = this.storage.getPersistedData(this.fields.devices, []);
178
175
  if (this.deviceId === '') {
@@ -195,7 +192,7 @@ export class CoreApp {
195
192
  const passphraseEncrypted = this.storage.getData(this.fields.devicePassphrase);
196
193
  if (passphraseEncrypted) {
197
194
  // this.name to identifier different app's secret
198
- const passphraseDecrypted = this.decrypt(passphraseEncrypted, this.name);
195
+ const passphraseDecrypted = await this.decrypt(passphraseEncrypted, this.name);
199
196
  if (passphraseDecrypted != null) {
200
197
  // Add the device to the list
201
198
  devices.push(d);
@@ -355,7 +352,7 @@ export class CoreApp {
355
352
  this.storage.setData(this.fields.deviceId, undefined);
356
353
  return;
357
354
  }
358
- const updateResult = this.initCallUpdate(result.data, data.timestamp);
355
+ const updateResult = await this.initCallUpdate(result.data, data.timestamp);
359
356
  if (!updateResult) {
360
357
  this.notifier.alert(this.get('noData') + '(Update)');
361
358
  }
@@ -367,13 +364,13 @@ export class CoreApp {
367
364
  * @param data Result data
368
365
  * @param timestamp Timestamp
369
366
  */
370
- initCallUpdate(data, timestamp) {
367
+ async initCallUpdate(data, timestamp) {
371
368
  // Data check
372
369
  if (data.deviceId == null || data.passphrase == null)
373
370
  return false;
374
371
  // Decrypt
375
372
  // Should be done within 120 seconds after returning from the backend
376
- const passphrase = this.decrypt(data.passphrase, timestamp.toString());
373
+ const passphrase = await this.decrypt(data.passphrase, timestamp.toString());
377
374
  if (passphrase == null)
378
375
  return false;
379
376
  // Update device id and cache it
@@ -388,7 +385,7 @@ export class CoreApp {
388
385
  this.storage.setData(this.fields.devicePassphrase, this.encrypt(passphrase, this.name));
389
386
  // Previous passphrase
390
387
  if (data.previousPassphrase) {
391
- const prev = this.decrypt(data.previousPassphrase, timestamp.toString());
388
+ const prev = await this.decrypt(data.previousPassphrase, timestamp.toString());
392
389
  // Update
393
390
  const fields = this.initCallEncryptedUpdateFields();
394
391
  for (const field of fields) {
@@ -403,10 +400,10 @@ export class CoreApp {
403
400
  const enhanced = currentValue.indexOf('!') >= 8;
404
401
  let newValueSource;
405
402
  if (enhanced) {
406
- newValueSource = this.decryptEnhanced(currentValue, prev, 12);
403
+ newValueSource = await this.decryptEnhanced(currentValue, prev, 12);
407
404
  }
408
405
  else {
409
- newValueSource = this.decrypt(currentValue, prev);
406
+ newValueSource = await this.decrypt(currentValue, prev);
410
407
  }
411
408
  if (newValueSource == null || newValueSource === '') {
412
409
  // Reset the field
@@ -414,8 +411,8 @@ export class CoreApp {
414
411
  continue;
415
412
  }
416
413
  const newValue = enhanced
417
- ? this.encryptEnhanced(newValueSource)
418
- : this.encrypt(newValueSource);
414
+ ? await this.encryptEnhanced(newValueSource)
415
+ : await this.encrypt(newValueSource);
419
416
  this.storage.setData(field, newValue);
420
417
  }
421
418
  }
@@ -448,10 +445,10 @@ export class CoreApp {
448
445
  this.authorized = token != null;
449
446
  // Token
450
447
  this.api.authorize(this.settings.authScheme, token);
451
- // Cover the current value
448
+ // Overwrite the current value
452
449
  if (refreshToken !== '') {
453
450
  if (refreshToken != null)
454
- refreshToken = this.encrypt(refreshToken);
451
+ this.encrypt(refreshToken).then((result) => this.storage.setData(this.fields.headerToken, result));
455
452
  this.storage.setData(this.fields.headerToken, refreshToken);
456
453
  }
457
454
  // Reset tryLogin state
@@ -500,8 +497,9 @@ export class CoreApp {
500
497
  /**
501
498
  * Change culture
502
499
  * @param culture New culture definition
500
+ * @param onReady On ready callback
503
501
  */
504
- changeCulture(culture) {
502
+ changeCulture(culture, onReady) {
505
503
  // Name
506
504
  const { name } = culture;
507
505
  // Same?
@@ -516,7 +514,19 @@ export class CoreApp {
516
514
  this._culture = name;
517
515
  // Hold the current resources
518
516
  this.settings.currentCulture = culture;
519
- this.updateRegionLabel();
517
+ if (typeof culture.resources !== 'object') {
518
+ culture.resources().then((result) => {
519
+ culture.resources = result;
520
+ this.updateRegionLabel();
521
+ if (onReady)
522
+ onReady();
523
+ });
524
+ }
525
+ else {
526
+ this.updateRegionLabel();
527
+ if (onReady)
528
+ onReady();
529
+ }
520
530
  }
521
531
  /**
522
532
  * Update current region label
@@ -559,11 +569,12 @@ export class CoreApp {
559
569
  * @param passphrase Secret passphrase
560
570
  * @returns Pure text
561
571
  */
562
- decrypt(messageEncrypted, passphrase) {
572
+ async decrypt(messageEncrypted, passphrase) {
563
573
  // Iterations
564
574
  const iterations = parseInt(messageEncrypted.substring(0, 2), 10);
565
575
  if (isNaN(iterations))
566
576
  return undefined;
577
+ const { PBKDF2, algo, enc, AES, pad, mode } = await import('crypto-js');
567
578
  try {
568
579
  const salt = enc.Hex.parse(messageEncrypted.substring(2, 34));
569
580
  const iv = enc.Hex.parse(messageEncrypted.substring(34, 66));
@@ -591,7 +602,7 @@ export class CoreApp {
591
602
  * @param durationSeconds Duration seconds, <= 12 will be considered as month
592
603
  * @returns Pure text
593
604
  */
594
- decryptEnhanced(messageEncrypted, passphrase, durationSeconds) {
605
+ async decryptEnhanced(messageEncrypted, passphrase, durationSeconds) {
595
606
  // Timestamp splitter
596
607
  const pos = messageEncrypted.indexOf('!');
597
608
  // Miliseconds chars are longer than 8
@@ -612,7 +623,7 @@ export class CoreApp {
612
623
  }
613
624
  const message = messageEncrypted.substring(pos + 1);
614
625
  passphrase = this.encryptionEnhance(passphrase !== null && passphrase !== void 0 ? passphrase : this.passphrase, timestamp);
615
- return this.decrypt(message, passphrase);
626
+ return await this.decrypt(message, passphrase);
616
627
  }
617
628
  catch (e) {
618
629
  console.log('decryptEnhanced', e);
@@ -659,9 +670,10 @@ export class CoreApp {
659
670
  * @param iterations Iterations, 1000 times, 1 - 99
660
671
  * @returns Result
661
672
  */
662
- encrypt(message, passphrase, iterations) {
673
+ async encrypt(message, passphrase, iterations) {
663
674
  // Default 1 * 1000
664
675
  iterations !== null && iterations !== void 0 ? iterations : (iterations = 1);
676
+ const { lib, PBKDF2, algo, enc, AES, pad, mode } = await import('crypto-js');
665
677
  const bits = 16; // 128 / 8
666
678
  const salt = lib.WordArray.random(bits);
667
679
  const key = PBKDF2(passphrase !== null && passphrase !== void 0 ? passphrase : this.passphrase, salt, {
@@ -687,11 +699,12 @@ export class CoreApp {
687
699
  * @param iterations Iterations, 1000 times, 1 - 99
688
700
  * @returns Result
689
701
  */
690
- encryptEnhanced(message, passphrase, iterations) {
702
+ async encryptEnhanced(message, passphrase, iterations) {
691
703
  // Timestamp
692
704
  const timestamp = Utils.numberToChars(new Date().getTime());
693
705
  passphrase = this.encryptionEnhance(passphrase !== null && passphrase !== void 0 ? passphrase : this.passphrase, timestamp);
694
- return timestamp + '!' + this.encrypt(message, passphrase, iterations);
706
+ const result = await this.encrypt(message, passphrase, iterations);
707
+ return timestamp + '!' + result;
695
708
  }
696
709
  /**
697
710
  * Enchance secret passphrase
@@ -851,7 +864,9 @@ export class CoreApp {
851
864
  * @returns Resource
852
865
  */
853
866
  get(key) {
854
- const value = this.settings.currentCulture.resources[key];
867
+ // Make sure the resource files are loaded first
868
+ const resources = this.settings.currentCulture.resources;
869
+ const value = typeof resources === 'object' ? resources[key] : undefined;
855
870
  if (value == null)
856
871
  return undefined;
857
872
  // No strict type convertion here
@@ -1028,7 +1043,8 @@ export class CoreApp {
1028
1043
  * @param message Message
1029
1044
  * @param passphrase Secret passphrase
1030
1045
  */
1031
- hash(message, passphrase) {
1046
+ async hash(message, passphrase) {
1047
+ const { SHA3, enc, HmacSHA512 } = await import('crypto-js');
1032
1048
  if (passphrase == null)
1033
1049
  return SHA3(message, { outputLength: 512 }).toString(enc.Base64);
1034
1050
  else
@@ -1040,7 +1056,8 @@ export class CoreApp {
1040
1056
  * @param message Message
1041
1057
  * @param passphrase Secret passphrase
1042
1058
  */
1043
- hashHex(message, passphrase) {
1059
+ async hashHex(message, passphrase) {
1060
+ const { SHA3, enc, HmacSHA512 } = await import('crypto-js');
1044
1061
  if (passphrase == null)
1045
1062
  return SHA3(message, { outputLength: 512 }).toString(enc.Hex);
1046
1063
  else
@@ -1215,7 +1232,7 @@ export class CoreApp {
1215
1232
  this.authorize(user.token, refreshToken);
1216
1233
  }
1217
1234
  else {
1218
- this.cachedRefreshToken = this.encrypt(refreshToken);
1235
+ this.encrypt(refreshToken).then((result) => (this.cachedRefreshToken = result));
1219
1236
  this.authorize(user.token, undefined);
1220
1237
  }
1221
1238
  }
@@ -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;
@@ -23,6 +23,11 @@ var ProductAssetUnit;
23
23
  * 次
24
24
  */
25
25
  ProductAssetUnit[ProductAssetUnit["TIME"] = 99] = "TIME";
26
+ /**
27
+ * Money
28
+ * 储值
29
+ */
30
+ ProductAssetUnit[ProductAssetUnit["MONEY"] = 100] = "MONEY";
26
31
  })(ProductAssetUnit || (ProductAssetUnit = {}));
27
32
  /**
28
33
  * Product weight units
@@ -23,15 +23,15 @@ export class AuthApi extends BaseApi {
23
23
  * @param payload Payload
24
24
  * @returns Result
25
25
  */
26
- loginId(id, payload) {
26
+ async loginId(id, payload) {
27
27
  const { deviceId, region } = this.app;
28
- id = this.app.encrypt(id);
28
+ id = await this.app.encrypt(id);
29
29
  const rq = {
30
30
  id,
31
31
  deviceId,
32
32
  region
33
33
  };
34
- return this.api.get('Auth/LoginId', rq, payload);
34
+ return await this.api.get('Auth/LoginId', rq, payload);
35
35
  }
36
36
  /**
37
37
  * 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,12 +1,8 @@
1
- import enResources from './en.json';
1
+ import { DomUtils } from '@etsoo/shared';
2
+ import { i18nResourceCreator } from './i18nResources';
2
3
  /**
3
4
  * Get en neutral culture
4
5
  * @param localResources Local resources
5
6
  * @returns Full culture
6
7
  */
7
- export const en = (localResources) => ({
8
- name: 'en',
9
- label: 'English',
10
- resources: { ...enResources, ...localResources },
11
- compatibleNames: []
12
- });
8
+ export const en = (resources) => DomUtils.en(i18nResourceCreator('./en.json', resources));
@@ -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,16 @@
1
+ export function i18nResourceCreator(file, resources) {
2
+ return async () => {
3
+ const [r1, r2] = await Promise.all([
4
+ import(file),
5
+ new Promise((resolve) => {
6
+ if (typeof resources === 'object') {
7
+ resolve(resources);
8
+ }
9
+ else {
10
+ resources().then((result) => resolve(result));
11
+ }
12
+ })
13
+ ]);
14
+ return { ...r1, ...r2 };
15
+ };
16
+ }
@@ -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>;
@@ -1,12 +1,8 @@
1
- import zhHansResources from './zh-Hans.json';
1
+ import { DomUtils } from '@etsoo/shared';
2
+ import { i18nResourceCreator } from './i18nResources';
2
3
  /**
3
4
  * Get zh-Hans neutral cultrue
4
5
  * @param localResources Local resources
5
6
  * @returns Full culture
6
7
  */
7
- export const zhHans = (localResources) => ({
8
- name: 'zh-Hans',
9
- label: '简体中文',
10
- resources: { ...zhHansResources, ...localResources },
11
- compatibleNames: ['zh-CN', 'zh-SG']
12
- });
8
+ export const zhHans = (resources) => DomUtils.en(i18nResourceCreator('./zh-Hans.json', resources));
@@ -1,7 +1,7 @@
1
- import { DataTypes } from '@etsoo/shared';
1
+ import { i18nResource } from './i18nResources';
2
2
  /**
3
3
  * Get zh-Hant neutral cultrue
4
4
  * @param localResources Local resources
5
5
  * @returns Full culture
6
6
  */
7
- export declare const zhHant: (localResources: object) => DataTypes.CultureDefinition;
7
+ export declare const zhHant: (resources: i18nResource) => import("@etsoo/shared").DataTypes.CultureDefinition<import("@etsoo/shared").DataTypes.StringRecord>;
@@ -1,12 +1,8 @@
1
- import zhHantResources from './zh-Hant.json';
1
+ import { DomUtils } from '@etsoo/shared';
2
+ import { i18nResourceCreator } from './i18nResources';
2
3
  /**
3
4
  * Get zh-Hant neutral cultrue
4
5
  * @param localResources Local resources
5
6
  * @returns Full culture
6
7
  */
7
- export const zhHant = (localResources) => ({
8
- name: 'zh-Hant',
9
- label: '繁體中文',
10
- resources: { ...zhHantResources, ...localResources },
11
- compatibleNames: ['zh-HK', 'zh-TW', 'zh-MO']
12
- });
8
+ export const zhHant = (resources) => DomUtils.en(i18nResourceCreator('./zh-Hant.json', resources));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/appscript",
3
- "version": "1.3.98",
3
+ "version": "1.4.0",
4
4
  "description": "Applications shared TypeScript framework",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/mjs/index.js",
@@ -54,17 +54,17 @@
54
54
  "dependencies": {
55
55
  "@etsoo/notificationbase": "^1.1.24",
56
56
  "@etsoo/restclient": "^1.0.87",
57
- "@etsoo/shared": "^1.2.1",
58
- "@types/crypto-js": "^4.1.1",
57
+ "@etsoo/shared": "^1.2.5",
59
58
  "crypto-js": "^4.1.1"
60
59
  },
61
60
  "devDependencies": {
62
61
  "@babel/cli": "^7.21.5",
63
- "@babel/core": "^7.21.5",
62
+ "@babel/core": "^7.21.8",
64
63
  "@babel/plugin-transform-runtime": "^7.21.4",
65
64
  "@babel/preset-env": "^7.21.5",
66
65
  "@babel/runtime-corejs3": "^7.21.5",
67
66
  "@types/jest": "^29.5.1",
67
+ "@types/crypto-js": "^4.1.1",
68
68
  "jest": "^29.5.0",
69
69
  "jest-environment-jsdom": "^29.5.0",
70
70
  "ts-jest": "^29.1.0",