@etsoo/appscript 1.5.50 → 1.5.52
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/Culture.ts +20 -1
- package/lib/cjs/app/CoreApp.d.ts +11 -2
- package/lib/cjs/app/CoreApp.js +36 -9
- package/lib/cjs/app/IApp.d.ts +10 -3
- package/lib/cjs/app/IApp.js +2 -1
- package/lib/cjs/i18n/CultureUtils.d.ts +3 -2
- package/lib/cjs/i18n/CultureUtils.js +3 -3
- package/lib/cjs/i18n/en.js +2 -1
- package/lib/cjs/i18n/zhHans.js +2 -1
- package/lib/cjs/i18n/zhHant.js +2 -1
- package/lib/mjs/app/CoreApp.d.ts +11 -2
- package/lib/mjs/app/CoreApp.js +36 -9
- package/lib/mjs/app/IApp.d.ts +10 -3
- package/lib/mjs/app/IApp.js +2 -1
- package/lib/mjs/i18n/CultureUtils.d.ts +3 -2
- package/lib/mjs/i18n/CultureUtils.js +3 -3
- package/lib/mjs/i18n/en.js +2 -1
- package/lib/mjs/i18n/zhHans.js +2 -1
- package/lib/mjs/i18n/zhHant.js +2 -1
- package/package.json +4 -4
- package/src/app/CoreApp.ts +44 -10
- package/src/app/IApp.ts +13 -3
- package/src/i18n/CultureUtils.ts +6 -2
- package/src/i18n/en.ts +2 -1
- package/src/i18n/zhHans.ts +2 -1
- package/src/i18n/zhHant.ts +2 -1
package/__tests__/app/Culture.ts
CHANGED
|
@@ -1,10 +1,29 @@
|
|
|
1
|
-
import { zhHans } from '../../src';
|
|
1
|
+
import { en, zhHans } from '../../src';
|
|
2
|
+
|
|
3
|
+
test('Tests for en', async () => {
|
|
4
|
+
const e = en(
|
|
5
|
+
{ nameB: 'Name for Business' },
|
|
6
|
+
new Promise((resolve) => resolve({ no: 'No override' }))
|
|
7
|
+
);
|
|
8
|
+
|
|
9
|
+
expect(e.name).toBe('en');
|
|
10
|
+
|
|
11
|
+
const resources =
|
|
12
|
+
typeof e.resources === 'object' ? e.resources : await e.resources();
|
|
13
|
+
|
|
14
|
+
expect(resources.name).toBe('Name');
|
|
15
|
+
expect(resources.nameB).toBe('Name for Business');
|
|
16
|
+
expect(resources.no).toBe('No override');
|
|
17
|
+
});
|
|
2
18
|
|
|
3
19
|
test('Tests for zhHans', async () => {
|
|
4
20
|
const zh = zhHans(
|
|
5
21
|
{ nameB: '名称覆盖' },
|
|
6
22
|
new Promise((resolve) => resolve({ no: 'No override' }))
|
|
7
23
|
);
|
|
24
|
+
|
|
25
|
+
expect(zh.name).toBe('zh-Hans');
|
|
26
|
+
|
|
8
27
|
const resources =
|
|
9
28
|
typeof zh.resources === 'object' ? zh.resources : await zh.resources();
|
|
10
29
|
|
package/lib/cjs/app/CoreApp.d.ts
CHANGED
|
@@ -129,6 +129,11 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
|
|
|
129
129
|
*/
|
|
130
130
|
get cachedUrl(): string | undefined | null;
|
|
131
131
|
set cachedUrl(value: string | undefined | null);
|
|
132
|
+
/**
|
|
133
|
+
* Keep login or not
|
|
134
|
+
*/
|
|
135
|
+
get keepLogin(): boolean;
|
|
136
|
+
set keepLogin(value: boolean);
|
|
132
137
|
private _embedded;
|
|
133
138
|
/**
|
|
134
139
|
* Is embedded
|
|
@@ -154,6 +159,7 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
|
|
|
154
159
|
protected passphrase: string;
|
|
155
160
|
private apis;
|
|
156
161
|
private tasks;
|
|
162
|
+
private clearInterval?;
|
|
157
163
|
/**
|
|
158
164
|
* Get persisted fields
|
|
159
165
|
*/
|
|
@@ -186,6 +192,10 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
|
|
|
186
192
|
* Restore settings from persisted source
|
|
187
193
|
*/
|
|
188
194
|
protected restore(): Promise<boolean>;
|
|
195
|
+
/**
|
|
196
|
+
* Dispose the application
|
|
197
|
+
*/
|
|
198
|
+
dispose(): void;
|
|
189
199
|
/**
|
|
190
200
|
* Is valid password, override to implement custom check
|
|
191
201
|
* @param password Input password
|
|
@@ -193,9 +203,8 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
|
|
|
193
203
|
isValidPassword(password: string): boolean;
|
|
194
204
|
/**
|
|
195
205
|
* Persist settings to source when application exit
|
|
196
|
-
* @param keepLogin Keep login or not
|
|
197
206
|
*/
|
|
198
|
-
persist(
|
|
207
|
+
persist(): void;
|
|
199
208
|
/**
|
|
200
209
|
* Add scheduled task
|
|
201
210
|
* @param task Task, return false to stop
|
package/lib/cjs/app/CoreApp.js
CHANGED
|
@@ -96,6 +96,19 @@ class CoreApp {
|
|
|
96
96
|
set cachedUrl(value) {
|
|
97
97
|
this.storage.setData(this.fields.cachedUrl, value);
|
|
98
98
|
}
|
|
99
|
+
/**
|
|
100
|
+
* Keep login or not
|
|
101
|
+
*/
|
|
102
|
+
get keepLogin() {
|
|
103
|
+
return this.storage.getData(this.fields.keepLogin) ?? false;
|
|
104
|
+
}
|
|
105
|
+
set keepLogin(value) {
|
|
106
|
+
if (!value) {
|
|
107
|
+
// Clear the token
|
|
108
|
+
this.clearCacheToken();
|
|
109
|
+
}
|
|
110
|
+
this.storage.setData(this.fields.keepLogin, value);
|
|
111
|
+
}
|
|
99
112
|
/**
|
|
100
113
|
* Is embedded
|
|
101
114
|
*/
|
|
@@ -119,7 +132,8 @@ class CoreApp {
|
|
|
119
132
|
this.fields.deviceId,
|
|
120
133
|
this.fields.devicePassphrase,
|
|
121
134
|
this.fields.serversideDeviceId,
|
|
122
|
-
this.fields.headerToken
|
|
135
|
+
this.fields.headerToken,
|
|
136
|
+
this.fields.keepLogin
|
|
123
137
|
];
|
|
124
138
|
}
|
|
125
139
|
/**
|
|
@@ -287,6 +301,20 @@ class CoreApp {
|
|
|
287
301
|
}
|
|
288
302
|
return false;
|
|
289
303
|
}
|
|
304
|
+
/**
|
|
305
|
+
* Dispose the application
|
|
306
|
+
*/
|
|
307
|
+
dispose() {
|
|
308
|
+
// Avoid duplicated call
|
|
309
|
+
if (!this._isReady)
|
|
310
|
+
return;
|
|
311
|
+
// Persist storage defined fields
|
|
312
|
+
this.persist();
|
|
313
|
+
// Clear the interval
|
|
314
|
+
this.clearInterval?.();
|
|
315
|
+
// Reset the status to false
|
|
316
|
+
this.isReady = false;
|
|
317
|
+
}
|
|
290
318
|
/**
|
|
291
319
|
* Is valid password, override to implement custom check
|
|
292
320
|
* @param password Input password
|
|
@@ -303,13 +331,8 @@ class CoreApp {
|
|
|
303
331
|
}
|
|
304
332
|
/**
|
|
305
333
|
* Persist settings to source when application exit
|
|
306
|
-
* @param keepLogin Keep login or not
|
|
307
334
|
*/
|
|
308
|
-
persist(
|
|
309
|
-
if (!keepLogin) {
|
|
310
|
-
// Unconditional clear the cache for security
|
|
311
|
-
this.clearCacheToken();
|
|
312
|
-
}
|
|
335
|
+
persist() {
|
|
313
336
|
// Devices
|
|
314
337
|
const devices = this.storage.getPersistedData(this.fields.devices);
|
|
315
338
|
if (devices != null) {
|
|
@@ -322,7 +345,7 @@ class CoreApp {
|
|
|
322
345
|
}
|
|
323
346
|
if (!this.authorized)
|
|
324
347
|
return;
|
|
325
|
-
const fields = keepLogin
|
|
348
|
+
const fields = this.keepLogin
|
|
326
349
|
? this.persistedFields
|
|
327
350
|
: this.persistedFields.filter((f) => f !== this.fields.headerToken);
|
|
328
351
|
this.storage.copyTo(fields);
|
|
@@ -683,6 +706,8 @@ class CoreApp {
|
|
|
683
706
|
this.onAuthorized(authorized);
|
|
684
707
|
// Everything is ready, update the state
|
|
685
708
|
this.authorized = authorized;
|
|
709
|
+
// Persist
|
|
710
|
+
this.persist();
|
|
686
711
|
}
|
|
687
712
|
/**
|
|
688
713
|
* On authorized or not callback
|
|
@@ -1532,7 +1557,7 @@ class CoreApp {
|
|
|
1532
1557
|
* Setup tasks
|
|
1533
1558
|
*/
|
|
1534
1559
|
setupTasks() {
|
|
1535
|
-
shared_1.ExtendUtils.intervalFor(() => {
|
|
1560
|
+
this.clearInterval = shared_1.ExtendUtils.intervalFor(() => {
|
|
1536
1561
|
// Exit when not authorized
|
|
1537
1562
|
if (!this.authorized)
|
|
1538
1563
|
return;
|
|
@@ -1590,6 +1615,8 @@ class CoreApp {
|
|
|
1590
1615
|
* @param apiUrl Signout API URL
|
|
1591
1616
|
*/
|
|
1592
1617
|
async signout() {
|
|
1618
|
+
// Clear the keep login status
|
|
1619
|
+
this.keepLogin = false;
|
|
1593
1620
|
const token = this.getCacheToken();
|
|
1594
1621
|
if (token) {
|
|
1595
1622
|
const result = await new AuthApi_1.AuthApi(this).signout({
|
package/lib/cjs/app/IApp.d.ts
CHANGED
|
@@ -94,7 +94,7 @@ export interface RefreshTokenProps {
|
|
|
94
94
|
/**
|
|
95
95
|
* App fields
|
|
96
96
|
*/
|
|
97
|
-
export declare const appFields: readonly ["headerToken", "serversideDeviceId", "deviceId", "devices", "devicePassphrase", "cachedUrl", "embedded"];
|
|
97
|
+
export declare const appFields: readonly ["headerToken", "serversideDeviceId", "deviceId", "devices", "devicePassphrase", "cachedUrl", "embedded", "keepLogin"];
|
|
98
98
|
/**
|
|
99
99
|
* Basic type template
|
|
100
100
|
*/
|
|
@@ -181,6 +181,10 @@ export interface IApp {
|
|
|
181
181
|
* Cached URL
|
|
182
182
|
*/
|
|
183
183
|
cachedUrl: string | undefined | null;
|
|
184
|
+
/**
|
|
185
|
+
* Keep login or not
|
|
186
|
+
*/
|
|
187
|
+
keepLogin: boolean;
|
|
184
188
|
/**
|
|
185
189
|
* IP data
|
|
186
190
|
*/
|
|
@@ -294,6 +298,10 @@ export interface IApp {
|
|
|
294
298
|
* @param callback Callback will be called when the IP is ready
|
|
295
299
|
*/
|
|
296
300
|
detectIP(callback?: IDetectIPCallback): void;
|
|
301
|
+
/**
|
|
302
|
+
* Dispose the application
|
|
303
|
+
*/
|
|
304
|
+
dispose(): void;
|
|
297
305
|
/**
|
|
298
306
|
* Download file
|
|
299
307
|
* @param stream File stream
|
|
@@ -561,9 +569,8 @@ export interface IApp {
|
|
|
561
569
|
signout(): Promise<void>;
|
|
562
570
|
/**
|
|
563
571
|
* Persist settings to source when application exit
|
|
564
|
-
* @param keepLogin Keep login or not
|
|
565
572
|
*/
|
|
566
|
-
persist(
|
|
573
|
+
persist(): void;
|
|
567
574
|
/**
|
|
568
575
|
* Go to the login page
|
|
569
576
|
* @param params Login parameters
|
package/lib/cjs/app/IApp.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import { DataTypes } from '@etsoo/shared';
|
|
1
|
+
import { DataTypes, DomUtils } from '@etsoo/shared';
|
|
2
2
|
/**
|
|
3
3
|
* Culture utilities
|
|
4
4
|
*/
|
|
5
5
|
export declare namespace CultureUtils {
|
|
6
6
|
/**
|
|
7
7
|
* Make culture
|
|
8
|
+
* @param cultureMaker Culture maker
|
|
8
9
|
* @param resources Resources
|
|
9
10
|
* @returns Culture
|
|
10
11
|
*/
|
|
11
|
-
function make(...resources: (object | (() => Promise<object>))[]): DataTypes.CultureDefinition<DataTypes.StringRecord>;
|
|
12
|
+
function make(cultureMaker: typeof DomUtils.zhHans, ...resources: (object | (() => Promise<object>))[]): DataTypes.CultureDefinition<DataTypes.StringRecord>;
|
|
12
13
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CultureUtils = void 0;
|
|
4
|
-
const shared_1 = require("@etsoo/shared");
|
|
5
4
|
/**
|
|
6
5
|
* Culture utilities
|
|
7
6
|
*/
|
|
@@ -9,11 +8,12 @@ var CultureUtils;
|
|
|
9
8
|
(function (CultureUtils) {
|
|
10
9
|
/**
|
|
11
10
|
* Make culture
|
|
11
|
+
* @param cultureMaker Culture maker
|
|
12
12
|
* @param resources Resources
|
|
13
13
|
* @returns Culture
|
|
14
14
|
*/
|
|
15
|
-
function make(...resources) {
|
|
16
|
-
return
|
|
15
|
+
function make(cultureMaker, ...resources) {
|
|
16
|
+
return cultureMaker(async () => {
|
|
17
17
|
const rs = await Promise.all(resources.map((resource) => new Promise((resolve) => {
|
|
18
18
|
if (typeof resource === 'object') {
|
|
19
19
|
resolve(resource);
|
package/lib/cjs/i18n/en.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.en = void 0;
|
|
4
|
+
const shared_1 = require("@etsoo/shared");
|
|
4
5
|
const CultureUtils_1 = require("./CultureUtils");
|
|
5
6
|
/**
|
|
6
7
|
* Get en neutral culture
|
|
7
8
|
* @param localResources Local resources
|
|
8
9
|
* @returns Full culture
|
|
9
10
|
*/
|
|
10
|
-
const en = (...resources) => CultureUtils_1.CultureUtils.make(import('./en.json'), ...resources);
|
|
11
|
+
const en = (...resources) => CultureUtils_1.CultureUtils.make(shared_1.DomUtils.en, import('./en.json'), ...resources);
|
|
11
12
|
exports.en = en;
|
package/lib/cjs/i18n/zhHans.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.zhHans = void 0;
|
|
4
|
+
const shared_1 = require("@etsoo/shared");
|
|
4
5
|
const CultureUtils_1 = require("./CultureUtils");
|
|
5
6
|
/**
|
|
6
7
|
* Get zh-Hans neutral cultrue
|
|
7
8
|
* @param localResources Local resources
|
|
8
9
|
* @returns Full culture
|
|
9
10
|
*/
|
|
10
|
-
const zhHans = (...resources) => CultureUtils_1.CultureUtils.make(import('./zh-Hans.json'), ...resources);
|
|
11
|
+
const zhHans = (...resources) => CultureUtils_1.CultureUtils.make(shared_1.DomUtils.zhHans, import('./zh-Hans.json'), ...resources);
|
|
11
12
|
exports.zhHans = zhHans;
|
package/lib/cjs/i18n/zhHant.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.zhHant = void 0;
|
|
4
|
+
const shared_1 = require("@etsoo/shared");
|
|
4
5
|
const CultureUtils_1 = require("./CultureUtils");
|
|
5
6
|
/**
|
|
6
7
|
* Get zh-Hant neutral cultrue
|
|
7
8
|
* @param localResources Local resources
|
|
8
9
|
* @returns Full culture
|
|
9
10
|
*/
|
|
10
|
-
const zhHant = (...resources) => CultureUtils_1.CultureUtils.make(import('./zh-Hant.json'), ...resources);
|
|
11
|
+
const zhHant = (...resources) => CultureUtils_1.CultureUtils.make(shared_1.DomUtils.zhHant, import('./zh-Hant.json'), ...resources);
|
|
11
12
|
exports.zhHant = zhHant;
|
package/lib/mjs/app/CoreApp.d.ts
CHANGED
|
@@ -129,6 +129,11 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
|
|
|
129
129
|
*/
|
|
130
130
|
get cachedUrl(): string | undefined | null;
|
|
131
131
|
set cachedUrl(value: string | undefined | null);
|
|
132
|
+
/**
|
|
133
|
+
* Keep login or not
|
|
134
|
+
*/
|
|
135
|
+
get keepLogin(): boolean;
|
|
136
|
+
set keepLogin(value: boolean);
|
|
132
137
|
private _embedded;
|
|
133
138
|
/**
|
|
134
139
|
* Is embedded
|
|
@@ -154,6 +159,7 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
|
|
|
154
159
|
protected passphrase: string;
|
|
155
160
|
private apis;
|
|
156
161
|
private tasks;
|
|
162
|
+
private clearInterval?;
|
|
157
163
|
/**
|
|
158
164
|
* Get persisted fields
|
|
159
165
|
*/
|
|
@@ -186,6 +192,10 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
|
|
|
186
192
|
* Restore settings from persisted source
|
|
187
193
|
*/
|
|
188
194
|
protected restore(): Promise<boolean>;
|
|
195
|
+
/**
|
|
196
|
+
* Dispose the application
|
|
197
|
+
*/
|
|
198
|
+
dispose(): void;
|
|
189
199
|
/**
|
|
190
200
|
* Is valid password, override to implement custom check
|
|
191
201
|
* @param password Input password
|
|
@@ -193,9 +203,8 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
|
|
|
193
203
|
isValidPassword(password: string): boolean;
|
|
194
204
|
/**
|
|
195
205
|
* Persist settings to source when application exit
|
|
196
|
-
* @param keepLogin Keep login or not
|
|
197
206
|
*/
|
|
198
|
-
persist(
|
|
207
|
+
persist(): void;
|
|
199
208
|
/**
|
|
200
209
|
* Add scheduled task
|
|
201
210
|
* @param task Task, return false to stop
|
package/lib/mjs/app/CoreApp.js
CHANGED
|
@@ -93,6 +93,19 @@ export class CoreApp {
|
|
|
93
93
|
set cachedUrl(value) {
|
|
94
94
|
this.storage.setData(this.fields.cachedUrl, value);
|
|
95
95
|
}
|
|
96
|
+
/**
|
|
97
|
+
* Keep login or not
|
|
98
|
+
*/
|
|
99
|
+
get keepLogin() {
|
|
100
|
+
return this.storage.getData(this.fields.keepLogin) ?? false;
|
|
101
|
+
}
|
|
102
|
+
set keepLogin(value) {
|
|
103
|
+
if (!value) {
|
|
104
|
+
// Clear the token
|
|
105
|
+
this.clearCacheToken();
|
|
106
|
+
}
|
|
107
|
+
this.storage.setData(this.fields.keepLogin, value);
|
|
108
|
+
}
|
|
96
109
|
/**
|
|
97
110
|
* Is embedded
|
|
98
111
|
*/
|
|
@@ -116,7 +129,8 @@ export class CoreApp {
|
|
|
116
129
|
this.fields.deviceId,
|
|
117
130
|
this.fields.devicePassphrase,
|
|
118
131
|
this.fields.serversideDeviceId,
|
|
119
|
-
this.fields.headerToken
|
|
132
|
+
this.fields.headerToken,
|
|
133
|
+
this.fields.keepLogin
|
|
120
134
|
];
|
|
121
135
|
}
|
|
122
136
|
/**
|
|
@@ -284,6 +298,20 @@ export class CoreApp {
|
|
|
284
298
|
}
|
|
285
299
|
return false;
|
|
286
300
|
}
|
|
301
|
+
/**
|
|
302
|
+
* Dispose the application
|
|
303
|
+
*/
|
|
304
|
+
dispose() {
|
|
305
|
+
// Avoid duplicated call
|
|
306
|
+
if (!this._isReady)
|
|
307
|
+
return;
|
|
308
|
+
// Persist storage defined fields
|
|
309
|
+
this.persist();
|
|
310
|
+
// Clear the interval
|
|
311
|
+
this.clearInterval?.();
|
|
312
|
+
// Reset the status to false
|
|
313
|
+
this.isReady = false;
|
|
314
|
+
}
|
|
287
315
|
/**
|
|
288
316
|
* Is valid password, override to implement custom check
|
|
289
317
|
* @param password Input password
|
|
@@ -300,13 +328,8 @@ export class CoreApp {
|
|
|
300
328
|
}
|
|
301
329
|
/**
|
|
302
330
|
* Persist settings to source when application exit
|
|
303
|
-
* @param keepLogin Keep login or not
|
|
304
331
|
*/
|
|
305
|
-
persist(
|
|
306
|
-
if (!keepLogin) {
|
|
307
|
-
// Unconditional clear the cache for security
|
|
308
|
-
this.clearCacheToken();
|
|
309
|
-
}
|
|
332
|
+
persist() {
|
|
310
333
|
// Devices
|
|
311
334
|
const devices = this.storage.getPersistedData(this.fields.devices);
|
|
312
335
|
if (devices != null) {
|
|
@@ -319,7 +342,7 @@ export class CoreApp {
|
|
|
319
342
|
}
|
|
320
343
|
if (!this.authorized)
|
|
321
344
|
return;
|
|
322
|
-
const fields = keepLogin
|
|
345
|
+
const fields = this.keepLogin
|
|
323
346
|
? this.persistedFields
|
|
324
347
|
: this.persistedFields.filter((f) => f !== this.fields.headerToken);
|
|
325
348
|
this.storage.copyTo(fields);
|
|
@@ -680,6 +703,8 @@ export class CoreApp {
|
|
|
680
703
|
this.onAuthorized(authorized);
|
|
681
704
|
// Everything is ready, update the state
|
|
682
705
|
this.authorized = authorized;
|
|
706
|
+
// Persist
|
|
707
|
+
this.persist();
|
|
683
708
|
}
|
|
684
709
|
/**
|
|
685
710
|
* On authorized or not callback
|
|
@@ -1529,7 +1554,7 @@ export class CoreApp {
|
|
|
1529
1554
|
* Setup tasks
|
|
1530
1555
|
*/
|
|
1531
1556
|
setupTasks() {
|
|
1532
|
-
ExtendUtils.intervalFor(() => {
|
|
1557
|
+
this.clearInterval = ExtendUtils.intervalFor(() => {
|
|
1533
1558
|
// Exit when not authorized
|
|
1534
1559
|
if (!this.authorized)
|
|
1535
1560
|
return;
|
|
@@ -1587,6 +1612,8 @@ export class CoreApp {
|
|
|
1587
1612
|
* @param apiUrl Signout API URL
|
|
1588
1613
|
*/
|
|
1589
1614
|
async signout() {
|
|
1615
|
+
// Clear the keep login status
|
|
1616
|
+
this.keepLogin = false;
|
|
1590
1617
|
const token = this.getCacheToken();
|
|
1591
1618
|
if (token) {
|
|
1592
1619
|
const result = await new AuthApi(this).signout({
|
package/lib/mjs/app/IApp.d.ts
CHANGED
|
@@ -94,7 +94,7 @@ export interface RefreshTokenProps {
|
|
|
94
94
|
/**
|
|
95
95
|
* App fields
|
|
96
96
|
*/
|
|
97
|
-
export declare const appFields: readonly ["headerToken", "serversideDeviceId", "deviceId", "devices", "devicePassphrase", "cachedUrl", "embedded"];
|
|
97
|
+
export declare const appFields: readonly ["headerToken", "serversideDeviceId", "deviceId", "devices", "devicePassphrase", "cachedUrl", "embedded", "keepLogin"];
|
|
98
98
|
/**
|
|
99
99
|
* Basic type template
|
|
100
100
|
*/
|
|
@@ -181,6 +181,10 @@ export interface IApp {
|
|
|
181
181
|
* Cached URL
|
|
182
182
|
*/
|
|
183
183
|
cachedUrl: string | undefined | null;
|
|
184
|
+
/**
|
|
185
|
+
* Keep login or not
|
|
186
|
+
*/
|
|
187
|
+
keepLogin: boolean;
|
|
184
188
|
/**
|
|
185
189
|
* IP data
|
|
186
190
|
*/
|
|
@@ -294,6 +298,10 @@ export interface IApp {
|
|
|
294
298
|
* @param callback Callback will be called when the IP is ready
|
|
295
299
|
*/
|
|
296
300
|
detectIP(callback?: IDetectIPCallback): void;
|
|
301
|
+
/**
|
|
302
|
+
* Dispose the application
|
|
303
|
+
*/
|
|
304
|
+
dispose(): void;
|
|
297
305
|
/**
|
|
298
306
|
* Download file
|
|
299
307
|
* @param stream File stream
|
|
@@ -561,9 +569,8 @@ export interface IApp {
|
|
|
561
569
|
signout(): Promise<void>;
|
|
562
570
|
/**
|
|
563
571
|
* Persist settings to source when application exit
|
|
564
|
-
* @param keepLogin Keep login or not
|
|
565
572
|
*/
|
|
566
|
-
persist(
|
|
573
|
+
persist(): void;
|
|
567
574
|
/**
|
|
568
575
|
* Go to the login page
|
|
569
576
|
* @param params Login parameters
|
package/lib/mjs/app/IApp.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import { DataTypes } from '@etsoo/shared';
|
|
1
|
+
import { DataTypes, DomUtils } from '@etsoo/shared';
|
|
2
2
|
/**
|
|
3
3
|
* Culture utilities
|
|
4
4
|
*/
|
|
5
5
|
export declare namespace CultureUtils {
|
|
6
6
|
/**
|
|
7
7
|
* Make culture
|
|
8
|
+
* @param cultureMaker Culture maker
|
|
8
9
|
* @param resources Resources
|
|
9
10
|
* @returns Culture
|
|
10
11
|
*/
|
|
11
|
-
function make(...resources: (object | (() => Promise<object>))[]): DataTypes.CultureDefinition<DataTypes.StringRecord>;
|
|
12
|
+
function make(cultureMaker: typeof DomUtils.zhHans, ...resources: (object | (() => Promise<object>))[]): DataTypes.CultureDefinition<DataTypes.StringRecord>;
|
|
12
13
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { DomUtils } from '@etsoo/shared';
|
|
2
1
|
/**
|
|
3
2
|
* Culture utilities
|
|
4
3
|
*/
|
|
@@ -6,11 +5,12 @@ export var CultureUtils;
|
|
|
6
5
|
(function (CultureUtils) {
|
|
7
6
|
/**
|
|
8
7
|
* Make culture
|
|
8
|
+
* @param cultureMaker Culture maker
|
|
9
9
|
* @param resources Resources
|
|
10
10
|
* @returns Culture
|
|
11
11
|
*/
|
|
12
|
-
function make(...resources) {
|
|
13
|
-
return
|
|
12
|
+
function make(cultureMaker, ...resources) {
|
|
13
|
+
return cultureMaker(async () => {
|
|
14
14
|
const rs = await Promise.all(resources.map((resource) => new Promise((resolve) => {
|
|
15
15
|
if (typeof resource === 'object') {
|
|
16
16
|
resolve(resource);
|
package/lib/mjs/i18n/en.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { DomUtils } from '@etsoo/shared';
|
|
1
2
|
import { CultureUtils } from './CultureUtils';
|
|
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 = (...resources) => CultureUtils.make(import('./en.json'), ...resources);
|
|
8
|
+
export const en = (...resources) => CultureUtils.make(DomUtils.en, import('./en.json'), ...resources);
|
package/lib/mjs/i18n/zhHans.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { DomUtils } from '@etsoo/shared';
|
|
1
2
|
import { CultureUtils } from './CultureUtils';
|
|
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 = (...resources) => CultureUtils.make(import('./zh-Hans.json'), ...resources);
|
|
8
|
+
export const zhHans = (...resources) => CultureUtils.make(DomUtils.zhHans, import('./zh-Hans.json'), ...resources);
|
package/lib/mjs/i18n/zhHant.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { DomUtils } from '@etsoo/shared';
|
|
1
2
|
import { CultureUtils } from './CultureUtils';
|
|
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 = (...resources) => CultureUtils.make(import('./zh-Hant.json'), ...resources);
|
|
8
|
+
export const zhHant = (...resources) => CultureUtils.make(DomUtils.zhHant, import('./zh-Hant.json'), ...resources);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@etsoo/appscript",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.52",
|
|
4
4
|
"description": "Applications shared TypeScript framework",
|
|
5
5
|
"main": "lib/cjs/index.js",
|
|
6
6
|
"module": "lib/mjs/index.js",
|
|
@@ -52,9 +52,9 @@
|
|
|
52
52
|
},
|
|
53
53
|
"homepage": "https://github.com/ETSOO/AppScript#readme",
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@etsoo/notificationbase": "^1.1.
|
|
56
|
-
"@etsoo/restclient": "^1.1.
|
|
57
|
-
"@etsoo/shared": "^1.2.
|
|
55
|
+
"@etsoo/notificationbase": "^1.1.50",
|
|
56
|
+
"@etsoo/restclient": "^1.1.12",
|
|
57
|
+
"@etsoo/shared": "^1.2.49",
|
|
58
58
|
"crypto-js": "^4.2.0"
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
package/src/app/CoreApp.ts
CHANGED
|
@@ -249,6 +249,20 @@ export abstract class CoreApp<
|
|
|
249
249
|
this.storage.setData(this.fields.cachedUrl, value);
|
|
250
250
|
}
|
|
251
251
|
|
|
252
|
+
/**
|
|
253
|
+
* Keep login or not
|
|
254
|
+
*/
|
|
255
|
+
get keepLogin() {
|
|
256
|
+
return this.storage.getData<boolean>(this.fields.keepLogin) ?? false;
|
|
257
|
+
}
|
|
258
|
+
set keepLogin(value: boolean) {
|
|
259
|
+
if (!value) {
|
|
260
|
+
// Clear the token
|
|
261
|
+
this.clearCacheToken();
|
|
262
|
+
}
|
|
263
|
+
this.storage.setData(this.fields.keepLogin, value);
|
|
264
|
+
}
|
|
265
|
+
|
|
252
266
|
private _embedded: boolean;
|
|
253
267
|
/**
|
|
254
268
|
* Is embedded
|
|
@@ -287,6 +301,8 @@ export abstract class CoreApp<
|
|
|
287
301
|
|
|
288
302
|
private tasks: [() => PromiseLike<void | false>, number, number][] = [];
|
|
289
303
|
|
|
304
|
+
private clearInterval?: () => void;
|
|
305
|
+
|
|
290
306
|
/**
|
|
291
307
|
* Get persisted fields
|
|
292
308
|
*/
|
|
@@ -295,7 +311,8 @@ export abstract class CoreApp<
|
|
|
295
311
|
this.fields.deviceId,
|
|
296
312
|
this.fields.devicePassphrase,
|
|
297
313
|
this.fields.serversideDeviceId,
|
|
298
|
-
this.fields.headerToken
|
|
314
|
+
this.fields.headerToken,
|
|
315
|
+
this.fields.keepLogin
|
|
299
316
|
];
|
|
300
317
|
}
|
|
301
318
|
|
|
@@ -507,6 +524,23 @@ export abstract class CoreApp<
|
|
|
507
524
|
return false;
|
|
508
525
|
}
|
|
509
526
|
|
|
527
|
+
/**
|
|
528
|
+
* Dispose the application
|
|
529
|
+
*/
|
|
530
|
+
dispose() {
|
|
531
|
+
// Avoid duplicated call
|
|
532
|
+
if (!this._isReady) return;
|
|
533
|
+
|
|
534
|
+
// Persist storage defined fields
|
|
535
|
+
this.persist();
|
|
536
|
+
|
|
537
|
+
// Clear the interval
|
|
538
|
+
this.clearInterval?.();
|
|
539
|
+
|
|
540
|
+
// Reset the status to false
|
|
541
|
+
this.isReady = false;
|
|
542
|
+
}
|
|
543
|
+
|
|
510
544
|
/**
|
|
511
545
|
* Is valid password, override to implement custom check
|
|
512
546
|
* @param password Input password
|
|
@@ -525,14 +559,8 @@ export abstract class CoreApp<
|
|
|
525
559
|
|
|
526
560
|
/**
|
|
527
561
|
* Persist settings to source when application exit
|
|
528
|
-
* @param keepLogin Keep login or not
|
|
529
562
|
*/
|
|
530
|
-
persist(
|
|
531
|
-
if (!keepLogin) {
|
|
532
|
-
// Unconditional clear the cache for security
|
|
533
|
-
this.clearCacheToken();
|
|
534
|
-
}
|
|
535
|
-
|
|
563
|
+
persist() {
|
|
536
564
|
// Devices
|
|
537
565
|
const devices = this.storage.getPersistedData<string[]>(
|
|
538
566
|
this.fields.devices
|
|
@@ -548,7 +576,7 @@ export abstract class CoreApp<
|
|
|
548
576
|
|
|
549
577
|
if (!this.authorized) return;
|
|
550
578
|
|
|
551
|
-
const fields = keepLogin
|
|
579
|
+
const fields = this.keepLogin
|
|
552
580
|
? this.persistedFields
|
|
553
581
|
: this.persistedFields.filter((f) => f !== this.fields.headerToken);
|
|
554
582
|
|
|
@@ -1064,6 +1092,9 @@ export abstract class CoreApp<
|
|
|
1064
1092
|
|
|
1065
1093
|
// Everything is ready, update the state
|
|
1066
1094
|
this.authorized = authorized;
|
|
1095
|
+
|
|
1096
|
+
// Persist
|
|
1097
|
+
this.persist();
|
|
1067
1098
|
}
|
|
1068
1099
|
|
|
1069
1100
|
/**
|
|
@@ -2106,7 +2137,7 @@ export abstract class CoreApp<
|
|
|
2106
2137
|
* Setup tasks
|
|
2107
2138
|
*/
|
|
2108
2139
|
protected setupTasks() {
|
|
2109
|
-
ExtendUtils.intervalFor(() => {
|
|
2140
|
+
this.clearInterval = ExtendUtils.intervalFor(() => {
|
|
2110
2141
|
// Exit when not authorized
|
|
2111
2142
|
if (!this.authorized) return;
|
|
2112
2143
|
|
|
@@ -2169,6 +2200,9 @@ export abstract class CoreApp<
|
|
|
2169
2200
|
* @param apiUrl Signout API URL
|
|
2170
2201
|
*/
|
|
2171
2202
|
async signout() {
|
|
2203
|
+
// Clear the keep login status
|
|
2204
|
+
this.keepLogin = false;
|
|
2205
|
+
|
|
2172
2206
|
const token = this.getCacheToken();
|
|
2173
2207
|
if (token) {
|
|
2174
2208
|
const result = await new AuthApi(this).signout(
|
package/src/app/IApp.ts
CHANGED
|
@@ -133,7 +133,8 @@ export const appFields = [
|
|
|
133
133
|
'devices',
|
|
134
134
|
'devicePassphrase',
|
|
135
135
|
'cachedUrl',
|
|
136
|
-
'embedded'
|
|
136
|
+
'embedded',
|
|
137
|
+
'keepLogin'
|
|
137
138
|
] as const;
|
|
138
139
|
|
|
139
140
|
/**
|
|
@@ -240,6 +241,11 @@ export interface IApp {
|
|
|
240
241
|
*/
|
|
241
242
|
cachedUrl: string | undefined | null;
|
|
242
243
|
|
|
244
|
+
/**
|
|
245
|
+
* Keep login or not
|
|
246
|
+
*/
|
|
247
|
+
keepLogin: boolean;
|
|
248
|
+
|
|
243
249
|
/**
|
|
244
250
|
* IP data
|
|
245
251
|
*/
|
|
@@ -391,6 +397,11 @@ export interface IApp {
|
|
|
391
397
|
*/
|
|
392
398
|
detectIP(callback?: IDetectIPCallback): void;
|
|
393
399
|
|
|
400
|
+
/**
|
|
401
|
+
* Dispose the application
|
|
402
|
+
*/
|
|
403
|
+
dispose(): void;
|
|
404
|
+
|
|
394
405
|
/**
|
|
395
406
|
* Download file
|
|
396
407
|
* @param stream File stream
|
|
@@ -758,9 +769,8 @@ export interface IApp {
|
|
|
758
769
|
|
|
759
770
|
/**
|
|
760
771
|
* Persist settings to source when application exit
|
|
761
|
-
* @param keepLogin Keep login or not
|
|
762
772
|
*/
|
|
763
|
-
persist(
|
|
773
|
+
persist(): void;
|
|
764
774
|
|
|
765
775
|
/**
|
|
766
776
|
* Go to the login page
|
package/src/i18n/CultureUtils.ts
CHANGED
|
@@ -6,11 +6,15 @@ import { DataTypes, DomUtils } from '@etsoo/shared';
|
|
|
6
6
|
export namespace CultureUtils {
|
|
7
7
|
/**
|
|
8
8
|
* Make culture
|
|
9
|
+
* @param cultureMaker Culture maker
|
|
9
10
|
* @param resources Resources
|
|
10
11
|
* @returns Culture
|
|
11
12
|
*/
|
|
12
|
-
export function make(
|
|
13
|
-
|
|
13
|
+
export function make(
|
|
14
|
+
cultureMaker: typeof DomUtils.zhHans,
|
|
15
|
+
...resources: (object | (() => Promise<object>))[]
|
|
16
|
+
) {
|
|
17
|
+
return cultureMaker(async () => {
|
|
14
18
|
const rs = await Promise.all(
|
|
15
19
|
resources.map(
|
|
16
20
|
(resource) =>
|
package/src/i18n/en.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { DomUtils } from '@etsoo/shared';
|
|
1
2
|
import { CultureUtils } from './CultureUtils';
|
|
2
3
|
|
|
3
4
|
/**
|
|
@@ -6,4 +7,4 @@ import { CultureUtils } from './CultureUtils';
|
|
|
6
7
|
* @returns Full culture
|
|
7
8
|
*/
|
|
8
9
|
export const en = (...resources: (object | (() => Promise<object>))[]) =>
|
|
9
|
-
CultureUtils.make(import('./en.json'), ...resources);
|
|
10
|
+
CultureUtils.make(DomUtils.en, import('./en.json'), ...resources);
|
package/src/i18n/zhHans.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { DomUtils } from '@etsoo/shared';
|
|
1
2
|
import { CultureUtils } from './CultureUtils';
|
|
2
3
|
|
|
3
4
|
/**
|
|
@@ -6,4 +7,4 @@ import { CultureUtils } from './CultureUtils';
|
|
|
6
7
|
* @returns Full culture
|
|
7
8
|
*/
|
|
8
9
|
export const zhHans = (...resources: (object | (() => Promise<object>))[]) =>
|
|
9
|
-
CultureUtils.make(import('./zh-Hans.json'), ...resources);
|
|
10
|
+
CultureUtils.make(DomUtils.zhHans, import('./zh-Hans.json'), ...resources);
|
package/src/i18n/zhHant.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { DomUtils } from '@etsoo/shared';
|
|
1
2
|
import { CultureUtils } from './CultureUtils';
|
|
2
3
|
|
|
3
4
|
/**
|
|
@@ -6,4 +7,4 @@ import { CultureUtils } from './CultureUtils';
|
|
|
6
7
|
* @returns Full culture
|
|
7
8
|
*/
|
|
8
9
|
export const zhHant = (...resources: (object | (() => Promise<object>))[]) =>
|
|
9
|
-
CultureUtils.make(import('./zh-Hant.json'), ...resources);
|
|
10
|
+
CultureUtils.make(DomUtils.zhHant, import('./zh-Hant.json'), ...resources);
|