@etsoo/appscript 1.4.6 → 1.4.8

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.
@@ -163,8 +163,8 @@ test('Tests for encrypt / decrypt', async () => {
163
163
  const passphrase = 'My password';
164
164
 
165
165
  // Act
166
- const encrypted = await app.encrypt(input, passphrase);
167
- const plain = await app.decrypt(encrypted, passphrase);
166
+ const encrypted = app.encrypt(input, passphrase);
167
+ const plain = app.decrypt(encrypted, passphrase);
168
168
  expect(plain).toEqual(input);
169
169
  });
170
170
 
@@ -174,8 +174,8 @@ test('Tests for encryptEnhanced / decryptEnhanced', async () => {
174
174
  const passphrase = 'My password';
175
175
 
176
176
  // Act
177
- const encrypted = await app.encryptEnhanced(input, passphrase);
178
- const plain = await app.decryptEnhanced(encrypted, passphrase);
177
+ const encrypted = app.encryptEnhanced(input, passphrase);
178
+ const plain = app.decryptEnhanced(encrypted, passphrase);
179
179
  expect(plain).toEqual(input);
180
180
  });
181
181
 
@@ -59,6 +59,10 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
59
59
  * Storage
60
60
  */
61
61
  readonly storage: IStorage;
62
+ /**
63
+ * Access token
64
+ */
65
+ accessToken?: string;
62
66
  private _culture;
63
67
  /**
64
68
  * Culture, like zh-CN
@@ -223,7 +223,7 @@ class CoreApp {
223
223
  const passphraseEncrypted = this.storage.getData(this.fields.devicePassphrase);
224
224
  if (passphraseEncrypted) {
225
225
  // this.name to identifier different app's secret
226
- const passphraseDecrypted = await this.decrypt(passphraseEncrypted, this.name);
226
+ const passphraseDecrypted = this.decrypt(passphraseEncrypted, this.name);
227
227
  if (passphraseDecrypted != null) {
228
228
  // Add the device to the list
229
229
  devices.push(d);
@@ -401,7 +401,7 @@ class CoreApp {
401
401
  return false;
402
402
  // Decrypt
403
403
  // Should be done within 120 seconds after returning from the backend
404
- const passphrase = await this.decrypt(data.passphrase, timestamp.toString());
404
+ const passphrase = this.decrypt(data.passphrase, timestamp.toString());
405
405
  if (passphrase == null)
406
406
  return false;
407
407
  // Update device id and cache it
@@ -413,10 +413,10 @@ class CoreApp {
413
413
  this.storage.setPersistedData(this.fields.devices, devices);
414
414
  // Current passphrase
415
415
  this.passphrase = passphrase;
416
- this.storage.setData(this.fields.devicePassphrase, await this.encrypt(passphrase, this.name));
416
+ this.storage.setData(this.fields.devicePassphrase, this.encrypt(passphrase, this.name));
417
417
  // Previous passphrase
418
418
  if (data.previousPassphrase) {
419
- const prev = await this.decrypt(data.previousPassphrase, timestamp.toString());
419
+ const prev = this.decrypt(data.previousPassphrase, timestamp.toString());
420
420
  // Update
421
421
  const fields = this.initCallEncryptedUpdateFields();
422
422
  for (const field of fields) {
@@ -431,10 +431,10 @@ class CoreApp {
431
431
  const enhanced = currentValue.indexOf('!') >= 8;
432
432
  let newValueSource;
433
433
  if (enhanced) {
434
- newValueSource = await this.decryptEnhanced(currentValue, prev, 12);
434
+ newValueSource = this.decryptEnhanced(currentValue, prev, 12);
435
435
  }
436
436
  else {
437
- newValueSource = await this.decrypt(currentValue, prev);
437
+ newValueSource = this.decrypt(currentValue, prev);
438
438
  }
439
439
  if (newValueSource == null || newValueSource === '') {
440
440
  // Reset the field
@@ -442,8 +442,8 @@ class CoreApp {
442
442
  continue;
443
443
  }
444
444
  const newValue = enhanced
445
- ? await this.encryptEnhanced(newValueSource)
446
- : await this.encrypt(newValueSource);
445
+ ? this.encryptEnhanced(newValueSource)
446
+ : this.encrypt(newValueSource);
447
447
  this.storage.setData(field, newValue);
448
448
  }
449
449
  }
@@ -473,6 +473,7 @@ class CoreApp {
473
473
  authorize(token, refreshToken) {
474
474
  var _a;
475
475
  // State, when token is null, means logout
476
+ this.accessToken = token;
476
477
  this.authorized = token != null;
477
478
  // Token
478
479
  this.api.authorize(this.settings.authScheme, token);
@@ -6,6 +6,10 @@ export interface IExternalSettings {
6
6
  * Core system API endpoint
7
7
  */
8
8
  readonly endpoint: string;
9
+ /**
10
+ * Message hub endpoint
11
+ */
12
+ readonly messageHub?: string;
9
13
  /**
10
14
  * Core system app root url
11
15
  */
@@ -113,6 +113,10 @@ export interface IApp {
113
113
  * Application name
114
114
  */
115
115
  readonly name: string;
116
+ /**
117
+ * Access token
118
+ */
119
+ accessToken?: string;
116
120
  /**
117
121
  * IP data
118
122
  */
@@ -26,15 +26,15 @@ class AuthApi extends BaseApi_1.BaseApi {
26
26
  * @param payload Payload
27
27
  * @returns Result
28
28
  */
29
- async loginId(id, payload) {
29
+ loginId(id, payload) {
30
30
  const { deviceId, region } = this.app;
31
- id = await this.app.encrypt(id);
31
+ id = this.app.encrypt(id);
32
32
  const rq = {
33
33
  id,
34
34
  deviceId,
35
35
  region
36
36
  };
37
- return await this.api.get('Auth/LoginId', rq, payload);
37
+ return this.api.get('Auth/LoginId', rq, payload);
38
38
  }
39
39
  /**
40
40
  * Reset password
@@ -30,7 +30,7 @@ const shared_1 = require("@etsoo/shared");
30
30
  * @param localResources Local resources
31
31
  * @returns Full culture
32
32
  */
33
- const zhHans = (resources) => shared_1.DomUtils.en(async () => {
33
+ const zhHans = (resources) => shared_1.DomUtils.zhHans(async () => {
34
34
  const [r1, r2] = await Promise.all([
35
35
  Promise.resolve().then(() => __importStar(require('./zh-Hans.json'))),
36
36
  new Promise((resolve) => {
@@ -30,7 +30,7 @@ const shared_1 = require("@etsoo/shared");
30
30
  * @param localResources Local resources
31
31
  * @returns Full culture
32
32
  */
33
- const zhHant = (resources) => shared_1.DomUtils.en(async () => {
33
+ const zhHant = (resources) => shared_1.DomUtils.zhHant(async () => {
34
34
  const [r1, r2] = await Promise.all([
35
35
  Promise.resolve().then(() => __importStar(require('./zh-Hant.json'))),
36
36
  new Promise((resolve) => {
@@ -59,6 +59,10 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
59
59
  * Storage
60
60
  */
61
61
  readonly storage: IStorage;
62
+ /**
63
+ * Access token
64
+ */
65
+ accessToken?: string;
62
66
  private _culture;
63
67
  /**
64
68
  * Culture, like zh-CN
@@ -197,7 +197,7 @@ export class CoreApp {
197
197
  const passphraseEncrypted = this.storage.getData(this.fields.devicePassphrase);
198
198
  if (passphraseEncrypted) {
199
199
  // this.name to identifier different app's secret
200
- const passphraseDecrypted = await this.decrypt(passphraseEncrypted, this.name);
200
+ const passphraseDecrypted = this.decrypt(passphraseEncrypted, this.name);
201
201
  if (passphraseDecrypted != null) {
202
202
  // Add the device to the list
203
203
  devices.push(d);
@@ -375,7 +375,7 @@ export class CoreApp {
375
375
  return false;
376
376
  // Decrypt
377
377
  // Should be done within 120 seconds after returning from the backend
378
- const passphrase = await this.decrypt(data.passphrase, timestamp.toString());
378
+ const passphrase = this.decrypt(data.passphrase, timestamp.toString());
379
379
  if (passphrase == null)
380
380
  return false;
381
381
  // Update device id and cache it
@@ -387,10 +387,10 @@ export class CoreApp {
387
387
  this.storage.setPersistedData(this.fields.devices, devices);
388
388
  // Current passphrase
389
389
  this.passphrase = passphrase;
390
- this.storage.setData(this.fields.devicePassphrase, await this.encrypt(passphrase, this.name));
390
+ this.storage.setData(this.fields.devicePassphrase, this.encrypt(passphrase, this.name));
391
391
  // Previous passphrase
392
392
  if (data.previousPassphrase) {
393
- const prev = await this.decrypt(data.previousPassphrase, timestamp.toString());
393
+ const prev = this.decrypt(data.previousPassphrase, timestamp.toString());
394
394
  // Update
395
395
  const fields = this.initCallEncryptedUpdateFields();
396
396
  for (const field of fields) {
@@ -405,10 +405,10 @@ export class CoreApp {
405
405
  const enhanced = currentValue.indexOf('!') >= 8;
406
406
  let newValueSource;
407
407
  if (enhanced) {
408
- newValueSource = await this.decryptEnhanced(currentValue, prev, 12);
408
+ newValueSource = this.decryptEnhanced(currentValue, prev, 12);
409
409
  }
410
410
  else {
411
- newValueSource = await this.decrypt(currentValue, prev);
411
+ newValueSource = this.decrypt(currentValue, prev);
412
412
  }
413
413
  if (newValueSource == null || newValueSource === '') {
414
414
  // Reset the field
@@ -416,8 +416,8 @@ export class CoreApp {
416
416
  continue;
417
417
  }
418
418
  const newValue = enhanced
419
- ? await this.encryptEnhanced(newValueSource)
420
- : await this.encrypt(newValueSource);
419
+ ? this.encryptEnhanced(newValueSource)
420
+ : this.encrypt(newValueSource);
421
421
  this.storage.setData(field, newValue);
422
422
  }
423
423
  }
@@ -447,6 +447,7 @@ export class CoreApp {
447
447
  authorize(token, refreshToken) {
448
448
  var _a;
449
449
  // State, when token is null, means logout
450
+ this.accessToken = token;
450
451
  this.authorized = token != null;
451
452
  // Token
452
453
  this.api.authorize(this.settings.authScheme, token);
@@ -6,6 +6,10 @@ export interface IExternalSettings {
6
6
  * Core system API endpoint
7
7
  */
8
8
  readonly endpoint: string;
9
+ /**
10
+ * Message hub endpoint
11
+ */
12
+ readonly messageHub?: string;
9
13
  /**
10
14
  * Core system app root url
11
15
  */
@@ -113,6 +113,10 @@ export interface IApp {
113
113
  * Application name
114
114
  */
115
115
  readonly name: string;
116
+ /**
117
+ * Access token
118
+ */
119
+ accessToken?: string;
116
120
  /**
117
121
  * IP data
118
122
  */
@@ -23,15 +23,15 @@ export class AuthApi extends BaseApi {
23
23
  * @param payload Payload
24
24
  * @returns Result
25
25
  */
26
- async loginId(id, payload) {
26
+ loginId(id, payload) {
27
27
  const { deviceId, region } = this.app;
28
- id = await this.app.encrypt(id);
28
+ id = this.app.encrypt(id);
29
29
  const rq = {
30
30
  id,
31
31
  deviceId,
32
32
  region
33
33
  };
34
- return await this.api.get('Auth/LoginId', rq, payload);
34
+ return this.api.get('Auth/LoginId', rq, payload);
35
35
  }
36
36
  /**
37
37
  * Reset password
@@ -4,7 +4,7 @@ import { DomUtils } from '@etsoo/shared';
4
4
  * @param localResources Local resources
5
5
  * @returns Full culture
6
6
  */
7
- export const zhHans = (resources) => DomUtils.en(async () => {
7
+ export const zhHans = (resources) => DomUtils.zhHans(async () => {
8
8
  const [r1, r2] = await Promise.all([
9
9
  import('./zh-Hans.json'),
10
10
  new Promise((resolve) => {
@@ -4,7 +4,7 @@ import { DomUtils } from '@etsoo/shared';
4
4
  * @param localResources Local resources
5
5
  * @returns Full culture
6
6
  */
7
- export const zhHant = (resources) => DomUtils.en(async () => {
7
+ export const zhHant = (resources) => DomUtils.zhHant(async () => {
8
8
  const [r1, r2] = await Promise.all([
9
9
  import('./zh-Hant.json'),
10
10
  new Promise((resolve) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/appscript",
3
- "version": "1.4.6",
3
+ "version": "1.4.8",
4
4
  "description": "Applications shared TypeScript framework",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/mjs/index.js",
@@ -113,6 +113,11 @@ export abstract class CoreApp<
113
113
  */
114
114
  readonly storage: IStorage;
115
115
 
116
+ /**
117
+ * Access token
118
+ */
119
+ accessToken?: string;
120
+
116
121
  private _culture!: string;
117
122
  /**
118
123
  * Culture, like zh-CN
@@ -362,7 +367,7 @@ export abstract class CoreApp<
362
367
  );
363
368
  if (passphraseEncrypted) {
364
369
  // this.name to identifier different app's secret
365
- const passphraseDecrypted = await this.decrypt(
370
+ const passphraseDecrypted = this.decrypt(
366
371
  passphraseEncrypted,
367
372
  this.name
368
373
  );
@@ -578,10 +583,7 @@ export abstract class CoreApp<
578
583
 
579
584
  // Decrypt
580
585
  // Should be done within 120 seconds after returning from the backend
581
- const passphrase = await this.decrypt(
582
- data.passphrase,
583
- timestamp.toString()
584
- );
586
+ const passphrase = this.decrypt(data.passphrase, timestamp.toString());
585
587
  if (passphrase == null) return false;
586
588
 
587
589
  // Update device id and cache it
@@ -600,12 +602,12 @@ export abstract class CoreApp<
600
602
  this.passphrase = passphrase;
601
603
  this.storage.setData(
602
604
  this.fields.devicePassphrase,
603
- await this.encrypt(passphrase, this.name)
605
+ this.encrypt(passphrase, this.name)
604
606
  );
605
607
 
606
608
  // Previous passphrase
607
609
  if (data.previousPassphrase) {
608
- const prev = await this.decrypt(
610
+ const prev = this.decrypt(
609
611
  data.previousPassphrase,
610
612
  timestamp.toString()
611
613
  );
@@ -626,13 +628,13 @@ export abstract class CoreApp<
626
628
  let newValueSource: string | undefined;
627
629
 
628
630
  if (enhanced) {
629
- newValueSource = await this.decryptEnhanced(
631
+ newValueSource = this.decryptEnhanced(
630
632
  currentValue,
631
633
  prev,
632
634
  12
633
635
  );
634
636
  } else {
635
- newValueSource = await this.decrypt(currentValue, prev);
637
+ newValueSource = this.decrypt(currentValue, prev);
636
638
  }
637
639
 
638
640
  if (newValueSource == null || newValueSource === '') {
@@ -642,8 +644,8 @@ export abstract class CoreApp<
642
644
  }
643
645
 
644
646
  const newValue = enhanced
645
- ? await this.encryptEnhanced(newValueSource)
646
- : await this.encrypt(newValueSource);
647
+ ? this.encryptEnhanced(newValueSource)
648
+ : this.encrypt(newValueSource);
647
649
 
648
650
  this.storage.setData(field, newValue);
649
651
  }
@@ -681,6 +683,7 @@ export abstract class CoreApp<
681
683
  */
682
684
  authorize(token?: string, refreshToken?: string) {
683
685
  // State, when token is null, means logout
686
+ this.accessToken = token;
684
687
  this.authorized = token != null;
685
688
 
686
689
  // Token
@@ -7,6 +7,11 @@ export interface IExternalSettings {
7
7
  */
8
8
  readonly endpoint: string;
9
9
 
10
+ /**
11
+ * Message hub endpoint
12
+ */
13
+ readonly messageHub?: string;
14
+
10
15
  /**
11
16
  * Core system app root url
12
17
  */
package/src/app/IApp.ts CHANGED
@@ -156,6 +156,11 @@ export interface IApp {
156
156
  */
157
157
  readonly name: string;
158
158
 
159
+ /**
160
+ * Access token
161
+ */
162
+ accessToken?: string;
163
+
159
164
  /**
160
165
  * IP data
161
166
  */
@@ -35,15 +35,15 @@ export class AuthApi extends BaseApi {
35
35
  * @param payload Payload
36
36
  * @returns Result
37
37
  */
38
- async loginId(id: string, payload?: ResultPayload) {
38
+ loginId(id: string, payload?: ResultPayload) {
39
39
  const { deviceId, region } = this.app;
40
- id = await this.app.encrypt(id);
40
+ id = this.app.encrypt(id);
41
41
  const rq: LoginIdRQ = {
42
42
  id,
43
43
  deviceId,
44
44
  region
45
45
  };
46
- return await this.api.get('Auth/LoginId', rq, payload);
46
+ return this.api.get('Auth/LoginId', rq, payload);
47
47
  }
48
48
 
49
49
  /**
@@ -6,7 +6,7 @@ import { DataTypes, DomUtils } from '@etsoo/shared';
6
6
  * @returns Full culture
7
7
  */
8
8
  export const zhHans = (resources: object | (() => Promise<object>)) =>
9
- DomUtils.en(async () => {
9
+ DomUtils.zhHans(async () => {
10
10
  const [r1, r2] = await Promise.all([
11
11
  import('./zh-Hans.json'),
12
12
  new Promise<object>((resolve) => {
@@ -6,7 +6,7 @@ import { DataTypes, DomUtils } from '@etsoo/shared';
6
6
  * @returns Full culture
7
7
  */
8
8
  export const zhHant = (resources: object | (() => Promise<object>)) =>
9
- DomUtils.en(async () => {
9
+ DomUtils.zhHant(async () => {
10
10
  const [r1, r2] = await Promise.all([
11
11
  import('./zh-Hant.json'),
12
12
  new Promise<object>((resolve) => {