@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.
- package/__tests__/app/CoreApp.ts +4 -4
- package/lib/cjs/app/CoreApp.d.ts +4 -0
- package/lib/cjs/app/CoreApp.js +9 -8
- package/lib/cjs/app/ExternalSettings.d.ts +4 -0
- package/lib/cjs/app/IApp.d.ts +4 -0
- package/lib/cjs/erp/AuthApi.js +3 -3
- package/lib/cjs/i18n/zhHans.js +1 -1
- package/lib/cjs/i18n/zhHant.js +1 -1
- package/lib/mjs/app/CoreApp.d.ts +4 -0
- package/lib/mjs/app/CoreApp.js +9 -8
- package/lib/mjs/app/ExternalSettings.d.ts +4 -0
- package/lib/mjs/app/IApp.d.ts +4 -0
- package/lib/mjs/erp/AuthApi.js +3 -3
- package/lib/mjs/i18n/zhHans.js +1 -1
- package/lib/mjs/i18n/zhHant.js +1 -1
- package/package.json +1 -1
- package/src/app/CoreApp.ts +14 -11
- package/src/app/ExternalSettings.ts +5 -0
- package/src/app/IApp.ts +5 -0
- package/src/erp/AuthApi.ts +3 -3
- package/src/i18n/zhHans.ts +1 -1
- package/src/i18n/zhHant.ts +1 -1
package/__tests__/app/CoreApp.ts
CHANGED
|
@@ -163,8 +163,8 @@ test('Tests for encrypt / decrypt', async () => {
|
|
|
163
163
|
const passphrase = 'My password';
|
|
164
164
|
|
|
165
165
|
// Act
|
|
166
|
-
const encrypted =
|
|
167
|
-
const plain =
|
|
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 =
|
|
178
|
-
const plain =
|
|
177
|
+
const encrypted = app.encryptEnhanced(input, passphrase);
|
|
178
|
+
const plain = app.decryptEnhanced(encrypted, passphrase);
|
|
179
179
|
expect(plain).toEqual(input);
|
|
180
180
|
});
|
|
181
181
|
|
package/lib/cjs/app/CoreApp.d.ts
CHANGED
package/lib/cjs/app/CoreApp.js
CHANGED
|
@@ -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 =
|
|
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 =
|
|
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,
|
|
416
|
+
this.storage.setData(this.fields.devicePassphrase, this.encrypt(passphrase, this.name));
|
|
417
417
|
// Previous passphrase
|
|
418
418
|
if (data.previousPassphrase) {
|
|
419
|
-
const prev =
|
|
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 =
|
|
434
|
+
newValueSource = this.decryptEnhanced(currentValue, prev, 12);
|
|
435
435
|
}
|
|
436
436
|
else {
|
|
437
|
-
newValueSource =
|
|
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
|
-
?
|
|
446
|
-
:
|
|
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);
|
package/lib/cjs/app/IApp.d.ts
CHANGED
package/lib/cjs/erp/AuthApi.js
CHANGED
|
@@ -26,15 +26,15 @@ class AuthApi extends BaseApi_1.BaseApi {
|
|
|
26
26
|
* @param payload Payload
|
|
27
27
|
* @returns Result
|
|
28
28
|
*/
|
|
29
|
-
|
|
29
|
+
loginId(id, payload) {
|
|
30
30
|
const { deviceId, region } = this.app;
|
|
31
|
-
id =
|
|
31
|
+
id = this.app.encrypt(id);
|
|
32
32
|
const rq = {
|
|
33
33
|
id,
|
|
34
34
|
deviceId,
|
|
35
35
|
region
|
|
36
36
|
};
|
|
37
|
-
return
|
|
37
|
+
return this.api.get('Auth/LoginId', rq, payload);
|
|
38
38
|
}
|
|
39
39
|
/**
|
|
40
40
|
* Reset password
|
package/lib/cjs/i18n/zhHans.js
CHANGED
|
@@ -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.
|
|
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) => {
|
package/lib/cjs/i18n/zhHant.js
CHANGED
|
@@ -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.
|
|
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) => {
|
package/lib/mjs/app/CoreApp.d.ts
CHANGED
package/lib/mjs/app/CoreApp.js
CHANGED
|
@@ -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 =
|
|
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 =
|
|
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,
|
|
390
|
+
this.storage.setData(this.fields.devicePassphrase, this.encrypt(passphrase, this.name));
|
|
391
391
|
// Previous passphrase
|
|
392
392
|
if (data.previousPassphrase) {
|
|
393
|
-
const prev =
|
|
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 =
|
|
408
|
+
newValueSource = this.decryptEnhanced(currentValue, prev, 12);
|
|
409
409
|
}
|
|
410
410
|
else {
|
|
411
|
-
newValueSource =
|
|
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
|
-
?
|
|
420
|
-
:
|
|
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);
|
package/lib/mjs/app/IApp.d.ts
CHANGED
package/lib/mjs/erp/AuthApi.js
CHANGED
|
@@ -23,15 +23,15 @@ export class AuthApi extends BaseApi {
|
|
|
23
23
|
* @param payload Payload
|
|
24
24
|
* @returns Result
|
|
25
25
|
*/
|
|
26
|
-
|
|
26
|
+
loginId(id, payload) {
|
|
27
27
|
const { deviceId, region } = this.app;
|
|
28
|
-
id =
|
|
28
|
+
id = this.app.encrypt(id);
|
|
29
29
|
const rq = {
|
|
30
30
|
id,
|
|
31
31
|
deviceId,
|
|
32
32
|
region
|
|
33
33
|
};
|
|
34
|
-
return
|
|
34
|
+
return this.api.get('Auth/LoginId', rq, payload);
|
|
35
35
|
}
|
|
36
36
|
/**
|
|
37
37
|
* Reset password
|
package/lib/mjs/i18n/zhHans.js
CHANGED
|
@@ -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.
|
|
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) => {
|
package/lib/mjs/i18n/zhHant.js
CHANGED
|
@@ -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.
|
|
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
package/src/app/CoreApp.ts
CHANGED
|
@@ -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 =
|
|
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 =
|
|
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
|
-
|
|
605
|
+
this.encrypt(passphrase, this.name)
|
|
604
606
|
);
|
|
605
607
|
|
|
606
608
|
// Previous passphrase
|
|
607
609
|
if (data.previousPassphrase) {
|
|
608
|
-
const prev =
|
|
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 =
|
|
631
|
+
newValueSource = this.decryptEnhanced(
|
|
630
632
|
currentValue,
|
|
631
633
|
prev,
|
|
632
634
|
12
|
|
633
635
|
);
|
|
634
636
|
} else {
|
|
635
|
-
newValueSource =
|
|
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
|
-
?
|
|
646
|
-
:
|
|
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
|
package/src/app/IApp.ts
CHANGED
package/src/erp/AuthApi.ts
CHANGED
|
@@ -35,15 +35,15 @@ export class AuthApi extends BaseApi {
|
|
|
35
35
|
* @param payload Payload
|
|
36
36
|
* @returns Result
|
|
37
37
|
*/
|
|
38
|
-
|
|
38
|
+
loginId(id: string, payload?: ResultPayload) {
|
|
39
39
|
const { deviceId, region } = this.app;
|
|
40
|
-
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
|
|
46
|
+
return this.api.get('Auth/LoginId', rq, payload);
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
/**
|
package/src/i18n/zhHans.ts
CHANGED
|
@@ -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.
|
|
9
|
+
DomUtils.zhHans(async () => {
|
|
10
10
|
const [r1, r2] = await Promise.all([
|
|
11
11
|
import('./zh-Hans.json'),
|
|
12
12
|
new Promise<object>((resolve) => {
|
package/src/i18n/zhHant.ts
CHANGED
|
@@ -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.
|
|
9
|
+
DomUtils.zhHant(async () => {
|
|
10
10
|
const [r1, r2] = await Promise.all([
|
|
11
11
|
import('./zh-Hant.json'),
|
|
12
12
|
new Promise<object>((resolve) => {
|