@etsoo/appscript 1.5.51 → 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.
@@ -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(keepLogin?: boolean): void;
207
+ persist(): void;
199
208
  /**
200
209
  * Add scheduled task
201
210
  * @param task Task, return false to stop
@@ -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(keepLogin) {
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({
@@ -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(keepLogin?: boolean): void;
573
+ persist(): void;
567
574
  /**
568
575
  * Go to the login page
569
576
  * @param params Login parameters
@@ -11,5 +11,6 @@ exports.appFields = [
11
11
  'devices',
12
12
  'devicePassphrase',
13
13
  'cachedUrl',
14
- 'embedded'
14
+ 'embedded',
15
+ 'keepLogin'
15
16
  ];
@@ -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(keepLogin?: boolean): void;
207
+ persist(): void;
199
208
  /**
200
209
  * Add scheduled task
201
210
  * @param task Task, return false to stop
@@ -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(keepLogin) {
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({
@@ -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(keepLogin?: boolean): void;
573
+ persist(): void;
567
574
  /**
568
575
  * Go to the login page
569
576
  * @param params Login parameters
@@ -8,5 +8,6 @@ export const appFields = [
8
8
  'devices',
9
9
  'devicePassphrase',
10
10
  'cachedUrl',
11
- 'embedded'
11
+ 'embedded',
12
+ 'keepLogin'
12
13
  ];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/appscript",
3
- "version": "1.5.51",
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",
@@ -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(keepLogin?: boolean) {
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(keepLogin?: boolean): void;
773
+ persist(): void;
764
774
 
765
775
  /**
766
776
  * Go to the login page