@etsoo/appscript 1.5.52 → 1.5.54

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.
@@ -635,15 +635,15 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
635
635
  signout(): Promise<void>;
636
636
  /**
637
637
  * Go to the login page
638
- * @params Login parameters
638
+ * @param data Login parameters
639
639
  */
640
- toLoginPage(params?: AppLoginParams): void;
640
+ toLoginPage(data?: AppLoginParams): void;
641
641
  /**
642
642
  * Try login, returning false means is loading
643
643
  * UI get involved while refreshToken not intended
644
- * @param params Login parameters
644
+ * @param data Login parameters
645
645
  */
646
- tryLogin(params?: AppTryLoginParams): Promise<boolean>;
646
+ tryLogin(data?: AppTryLoginParams): Promise<boolean>;
647
647
  /**
648
648
  * Update embedded status
649
649
  * @param embedded New embedded status
@@ -103,9 +103,15 @@ class CoreApp {
103
103
  return this.storage.getData(this.fields.keepLogin) ?? false;
104
104
  }
105
105
  set keepLogin(value) {
106
+ const field = this.fields.headerToken;
106
107
  if (!value) {
107
108
  // Clear the token
108
109
  this.clearCacheToken();
110
+ // Remove the token field
111
+ this.persistedFields.remove(field);
112
+ }
113
+ else if (!this.persistedFields.includes(field)) {
114
+ this.persistedFields.push(field);
109
115
  }
110
116
  this.storage.setData(this.fields.keepLogin, value);
111
117
  }
@@ -132,7 +138,6 @@ class CoreApp {
132
138
  this.fields.deviceId,
133
139
  this.fields.devicePassphrase,
134
140
  this.fields.serversideDeviceId,
135
- this.fields.headerToken,
136
141
  this.fields.keepLogin
137
142
  ];
138
143
  }
@@ -336,19 +341,13 @@ class CoreApp {
336
341
  // Devices
337
342
  const devices = this.storage.getPersistedData(this.fields.devices);
338
343
  if (devices != null) {
339
- const index = devices.indexOf(this.getDeviceId());
340
- if (index !== -1) {
341
- // Remove current device from the list
342
- devices.splice(index, 1);
344
+ if (devices.remove(this.getDeviceId()).length > 0) {
343
345
  this.storage.setPersistedData(this.fields.devices, devices);
344
346
  }
345
347
  }
346
348
  if (!this.authorized)
347
349
  return;
348
- const fields = this.keepLogin
349
- ? this.persistedFields
350
- : this.persistedFields.filter((f) => f !== this.fields.headerToken);
351
- this.storage.copyTo(fields);
350
+ this.storage.copyTo(this.persistedFields);
352
351
  }
353
352
  /**
354
353
  * Add scheduled task
@@ -1636,27 +1635,27 @@ class CoreApp {
1636
1635
  // Clear, noTrigger = true, avoid state update
1637
1636
  this.userLogout(true, true);
1638
1637
  // Go to login page
1639
- this.toLoginPage({ tryLogin: false, removeUrl: true });
1638
+ this.toLoginPage({ params: { tryLogin: false }, removeUrl: true });
1640
1639
  }
1641
1640
  /**
1642
1641
  * Go to the login page
1643
- * @params Login parameters
1642
+ * @param data Login parameters
1644
1643
  */
1645
- toLoginPage(params) {
1644
+ toLoginPage(data) {
1646
1645
  // Destruct
1647
- const { removeUrl, showLoading, ...rest } = params ?? {};
1646
+ const { params = {}, removeUrl } = data ?? {};
1648
1647
  // Save the current URL
1649
1648
  this.cachedUrl = removeUrl ? undefined : globalThis.location.href;
1650
1649
  // URL with parameters
1651
- const url = '/'.addUrlParams(rest);
1650
+ const url = '/'.addUrlParams(params);
1652
1651
  this.navigate(url);
1653
1652
  }
1654
1653
  /**
1655
1654
  * Try login, returning false means is loading
1656
1655
  * UI get involved while refreshToken not intended
1657
- * @param params Login parameters
1656
+ * @param data Login parameters
1658
1657
  */
1659
- async tryLogin(params) {
1658
+ async tryLogin(data) {
1660
1659
  // Check status
1661
1660
  if (this._isTryingLogin)
1662
1661
  return false;
@@ -43,11 +43,16 @@ export type FormatResultCustomCallback = ((data: FormatResultCustom) => string |
43
43
  /**
44
44
  * Login parameters
45
45
  */
46
- export type AppLoginParams = DataTypes.SimpleObject & {
46
+ export type AppLoginParams = {
47
47
  /**
48
- * Try login with cached refresh token
48
+ * Login parameters to pass
49
49
  */
50
- tryLogin?: boolean;
50
+ params: DataTypes.SimpleObject & {
51
+ /**
52
+ * Try login with cached refresh token
53
+ */
54
+ tryLogin?: boolean;
55
+ };
51
56
  /**
52
57
  * Don't cache current URL instead of the default page
53
58
  */
@@ -573,15 +578,15 @@ export interface IApp {
573
578
  persist(): void;
574
579
  /**
575
580
  * Go to the login page
576
- * @param params Login parameters
581
+ * @param data Login parameters
577
582
  */
578
- toLoginPage(params?: AppLoginParams): void;
583
+ toLoginPage(data?: AppLoginParams): void;
579
584
  /**
580
585
  * Try login, returning false means is loading
581
586
  * UI get involved while refreshToken not intended
582
- * @param params Login parameters
587
+ * @param data Login parameters
583
588
  */
584
- tryLogin(params?: AppLoginParams): Promise<boolean>;
589
+ tryLogin(data?: AppLoginParams): Promise<boolean>;
585
590
  /**
586
591
  * Update API token and expires
587
592
  * @param name Api name
@@ -52,9 +52,7 @@ var BusinessUtils;
52
52
  }
53
53
  });
54
54
  // Remove the default culture
55
- const index = allCultures.findIndex((a) => a.id === cultures[0].id);
56
- if (index !== -1)
57
- allCultures.splice(index, 1);
55
+ allCultures.remove((a) => a.id === cultures[0].id);
58
56
  // Sort
59
57
  allCultures.sortByProperty('id', cultures.map((c) => c.id));
60
58
  // Set back
@@ -247,12 +247,7 @@ class ShoppingCart {
247
247
  }
248
248
  else {
249
249
  ShoppingCart.clear(this.identifier, this.storage);
250
- const keys = this.keys;
251
- const index = keys.indexOf(this.identifier);
252
- if (index !== -1) {
253
- keys.splice(index, 1);
254
- this.keys = keys;
255
- }
250
+ this.keys.remove(this.identifier);
256
251
  }
257
252
  this.doChange('clear', []);
258
253
  }
@@ -635,15 +635,15 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
635
635
  signout(): Promise<void>;
636
636
  /**
637
637
  * Go to the login page
638
- * @params Login parameters
638
+ * @param data Login parameters
639
639
  */
640
- toLoginPage(params?: AppLoginParams): void;
640
+ toLoginPage(data?: AppLoginParams): void;
641
641
  /**
642
642
  * Try login, returning false means is loading
643
643
  * UI get involved while refreshToken not intended
644
- * @param params Login parameters
644
+ * @param data Login parameters
645
645
  */
646
- tryLogin(params?: AppTryLoginParams): Promise<boolean>;
646
+ tryLogin(data?: AppTryLoginParams): Promise<boolean>;
647
647
  /**
648
648
  * Update embedded status
649
649
  * @param embedded New embedded status
@@ -100,9 +100,15 @@ export class CoreApp {
100
100
  return this.storage.getData(this.fields.keepLogin) ?? false;
101
101
  }
102
102
  set keepLogin(value) {
103
+ const field = this.fields.headerToken;
103
104
  if (!value) {
104
105
  // Clear the token
105
106
  this.clearCacheToken();
107
+ // Remove the token field
108
+ this.persistedFields.remove(field);
109
+ }
110
+ else if (!this.persistedFields.includes(field)) {
111
+ this.persistedFields.push(field);
106
112
  }
107
113
  this.storage.setData(this.fields.keepLogin, value);
108
114
  }
@@ -129,7 +135,6 @@ export class CoreApp {
129
135
  this.fields.deviceId,
130
136
  this.fields.devicePassphrase,
131
137
  this.fields.serversideDeviceId,
132
- this.fields.headerToken,
133
138
  this.fields.keepLogin
134
139
  ];
135
140
  }
@@ -333,19 +338,13 @@ export class CoreApp {
333
338
  // Devices
334
339
  const devices = this.storage.getPersistedData(this.fields.devices);
335
340
  if (devices != null) {
336
- const index = devices.indexOf(this.getDeviceId());
337
- if (index !== -1) {
338
- // Remove current device from the list
339
- devices.splice(index, 1);
341
+ if (devices.remove(this.getDeviceId()).length > 0) {
340
342
  this.storage.setPersistedData(this.fields.devices, devices);
341
343
  }
342
344
  }
343
345
  if (!this.authorized)
344
346
  return;
345
- const fields = this.keepLogin
346
- ? this.persistedFields
347
- : this.persistedFields.filter((f) => f !== this.fields.headerToken);
348
- this.storage.copyTo(fields);
347
+ this.storage.copyTo(this.persistedFields);
349
348
  }
350
349
  /**
351
350
  * Add scheduled task
@@ -1633,27 +1632,27 @@ export class CoreApp {
1633
1632
  // Clear, noTrigger = true, avoid state update
1634
1633
  this.userLogout(true, true);
1635
1634
  // Go to login page
1636
- this.toLoginPage({ tryLogin: false, removeUrl: true });
1635
+ this.toLoginPage({ params: { tryLogin: false }, removeUrl: true });
1637
1636
  }
1638
1637
  /**
1639
1638
  * Go to the login page
1640
- * @params Login parameters
1639
+ * @param data Login parameters
1641
1640
  */
1642
- toLoginPage(params) {
1641
+ toLoginPage(data) {
1643
1642
  // Destruct
1644
- const { removeUrl, showLoading, ...rest } = params ?? {};
1643
+ const { params = {}, removeUrl } = data ?? {};
1645
1644
  // Save the current URL
1646
1645
  this.cachedUrl = removeUrl ? undefined : globalThis.location.href;
1647
1646
  // URL with parameters
1648
- const url = '/'.addUrlParams(rest);
1647
+ const url = '/'.addUrlParams(params);
1649
1648
  this.navigate(url);
1650
1649
  }
1651
1650
  /**
1652
1651
  * Try login, returning false means is loading
1653
1652
  * UI get involved while refreshToken not intended
1654
- * @param params Login parameters
1653
+ * @param data Login parameters
1655
1654
  */
1656
- async tryLogin(params) {
1655
+ async tryLogin(data) {
1657
1656
  // Check status
1658
1657
  if (this._isTryingLogin)
1659
1658
  return false;
@@ -43,11 +43,16 @@ export type FormatResultCustomCallback = ((data: FormatResultCustom) => string |
43
43
  /**
44
44
  * Login parameters
45
45
  */
46
- export type AppLoginParams = DataTypes.SimpleObject & {
46
+ export type AppLoginParams = {
47
47
  /**
48
- * Try login with cached refresh token
48
+ * Login parameters to pass
49
49
  */
50
- tryLogin?: boolean;
50
+ params: DataTypes.SimpleObject & {
51
+ /**
52
+ * Try login with cached refresh token
53
+ */
54
+ tryLogin?: boolean;
55
+ };
51
56
  /**
52
57
  * Don't cache current URL instead of the default page
53
58
  */
@@ -573,15 +578,15 @@ export interface IApp {
573
578
  persist(): void;
574
579
  /**
575
580
  * Go to the login page
576
- * @param params Login parameters
581
+ * @param data Login parameters
577
582
  */
578
- toLoginPage(params?: AppLoginParams): void;
583
+ toLoginPage(data?: AppLoginParams): void;
579
584
  /**
580
585
  * Try login, returning false means is loading
581
586
  * UI get involved while refreshToken not intended
582
- * @param params Login parameters
587
+ * @param data Login parameters
583
588
  */
584
- tryLogin(params?: AppLoginParams): Promise<boolean>;
589
+ tryLogin(data?: AppLoginParams): Promise<boolean>;
585
590
  /**
586
591
  * Update API token and expires
587
592
  * @param name Api name
@@ -49,9 +49,7 @@ export var BusinessUtils;
49
49
  }
50
50
  });
51
51
  // Remove the default culture
52
- const index = allCultures.findIndex((a) => a.id === cultures[0].id);
53
- if (index !== -1)
54
- allCultures.splice(index, 1);
52
+ allCultures.remove((a) => a.id === cultures[0].id);
55
53
  // Sort
56
54
  allCultures.sortByProperty('id', cultures.map((c) => c.id));
57
55
  // Set back
@@ -244,12 +244,7 @@ export class ShoppingCart {
244
244
  }
245
245
  else {
246
246
  ShoppingCart.clear(this.identifier, this.storage);
247
- const keys = this.keys;
248
- const index = keys.indexOf(this.identifier);
249
- if (index !== -1) {
250
- keys.splice(index, 1);
251
- this.keys = keys;
252
- }
247
+ this.keys.remove(this.identifier);
253
248
  }
254
249
  this.doChange('clear', []);
255
250
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/appscript",
3
- "version": "1.5.52",
3
+ "version": "1.5.54",
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.50",
56
- "@etsoo/restclient": "^1.1.12",
57
- "@etsoo/shared": "^1.2.49",
55
+ "@etsoo/notificationbase": "^1.1.52",
56
+ "@etsoo/restclient": "^1.1.14",
57
+ "@etsoo/shared": "^1.2.51",
58
58
  "crypto-js": "^4.2.0"
59
59
  },
60
60
  "devDependencies": {
@@ -256,9 +256,15 @@ export abstract class CoreApp<
256
256
  return this.storage.getData<boolean>(this.fields.keepLogin) ?? false;
257
257
  }
258
258
  set keepLogin(value: boolean) {
259
+ const field = this.fields.headerToken;
259
260
  if (!value) {
260
261
  // Clear the token
261
262
  this.clearCacheToken();
263
+
264
+ // Remove the token field
265
+ this.persistedFields.remove(field);
266
+ } else if (!this.persistedFields.includes(field)) {
267
+ this.persistedFields.push(field);
262
268
  }
263
269
  this.storage.setData(this.fields.keepLogin, value);
264
270
  }
@@ -311,7 +317,6 @@ export abstract class CoreApp<
311
317
  this.fields.deviceId,
312
318
  this.fields.devicePassphrase,
313
319
  this.fields.serversideDeviceId,
314
- this.fields.headerToken,
315
320
  this.fields.keepLogin
316
321
  ];
317
322
  }
@@ -566,21 +571,14 @@ export abstract class CoreApp<
566
571
  this.fields.devices
567
572
  );
568
573
  if (devices != null) {
569
- const index = devices.indexOf(this.getDeviceId());
570
- if (index !== -1) {
571
- // Remove current device from the list
572
- devices.splice(index, 1);
574
+ if (devices.remove(this.getDeviceId()).length > 0) {
573
575
  this.storage.setPersistedData(this.fields.devices, devices);
574
576
  }
575
577
  }
576
578
 
577
579
  if (!this.authorized) return;
578
580
 
579
- const fields = this.keepLogin
580
- ? this.persistedFields
581
- : this.persistedFields.filter((f) => f !== this.fields.headerToken);
582
-
583
- this.storage.copyTo(fields);
581
+ this.storage.copyTo(this.persistedFields);
584
582
  }
585
583
 
586
584
  /**
@@ -2231,22 +2229,22 @@ export abstract class CoreApp<
2231
2229
  this.userLogout(true, true);
2232
2230
 
2233
2231
  // Go to login page
2234
- this.toLoginPage({ tryLogin: false, removeUrl: true });
2232
+ this.toLoginPage({ params: { tryLogin: false }, removeUrl: true });
2235
2233
  }
2236
2234
 
2237
2235
  /**
2238
2236
  * Go to the login page
2239
- * @params Login parameters
2237
+ * @param data Login parameters
2240
2238
  */
2241
- toLoginPage(params?: AppLoginParams) {
2239
+ toLoginPage(data?: AppLoginParams) {
2242
2240
  // Destruct
2243
- const { removeUrl, showLoading, ...rest } = params ?? {};
2241
+ const { params = {}, removeUrl } = data ?? {};
2244
2242
 
2245
2243
  // Save the current URL
2246
2244
  this.cachedUrl = removeUrl ? undefined : globalThis.location.href;
2247
2245
 
2248
2246
  // URL with parameters
2249
- const url = '/'.addUrlParams(rest);
2247
+ const url = '/'.addUrlParams(params);
2250
2248
 
2251
2249
  this.navigate(url);
2252
2250
  }
@@ -2254,9 +2252,9 @@ export abstract class CoreApp<
2254
2252
  /**
2255
2253
  * Try login, returning false means is loading
2256
2254
  * UI get involved while refreshToken not intended
2257
- * @param params Login parameters
2255
+ * @param data Login parameters
2258
2256
  */
2259
- async tryLogin(params?: AppTryLoginParams) {
2257
+ async tryLogin(data?: AppTryLoginParams) {
2260
2258
  // Check status
2261
2259
  if (this._isTryingLogin) return false;
2262
2260
  this._isTryingLogin = true;
package/src/app/IApp.ts CHANGED
@@ -66,11 +66,16 @@ export type FormatResultCustomCallback =
66
66
  /**
67
67
  * Login parameters
68
68
  */
69
- export type AppLoginParams = DataTypes.SimpleObject & {
69
+ export type AppLoginParams = {
70
70
  /**
71
- * Try login with cached refresh token
71
+ * Login parameters to pass
72
72
  */
73
- tryLogin?: boolean;
73
+ params: DataTypes.SimpleObject & {
74
+ /**
75
+ * Try login with cached refresh token
76
+ */
77
+ tryLogin?: boolean;
78
+ };
74
79
 
75
80
  /**
76
81
  * Don't cache current URL instead of the default page
@@ -774,16 +779,16 @@ export interface IApp {
774
779
 
775
780
  /**
776
781
  * Go to the login page
777
- * @param params Login parameters
782
+ * @param data Login parameters
778
783
  */
779
- toLoginPage(params?: AppLoginParams): void;
784
+ toLoginPage(data?: AppLoginParams): void;
780
785
 
781
786
  /**
782
787
  * Try login, returning false means is loading
783
788
  * UI get involved while refreshToken not intended
784
- * @param params Login parameters
789
+ * @param data Login parameters
785
790
  */
786
- tryLogin(params?: AppLoginParams): Promise<boolean>;
791
+ tryLogin(data?: AppLoginParams): Promise<boolean>;
787
792
 
788
793
  /**
789
794
  * Update API token and expires
@@ -62,9 +62,7 @@ export namespace BusinessUtils {
62
62
  });
63
63
 
64
64
  // Remove the default culture
65
- const index = allCultures.findIndex((a) => a.id === cultures[0].id);
66
- if (index !== -1) allCultures.splice(index, 1);
67
-
65
+ allCultures.remove((a) => a.id === cultures[0].id);
68
66
  // Sort
69
67
  allCultures.sortByProperty(
70
68
  'id',
@@ -475,13 +475,7 @@ export class ShoppingCart<T extends ShoppingCartItem> {
475
475
  this.save();
476
476
  } else {
477
477
  ShoppingCart.clear(this.identifier, this.storage);
478
-
479
- const keys = this.keys;
480
- const index = keys.indexOf(this.identifier);
481
- if (index !== -1) {
482
- keys.splice(index, 1);
483
- this.keys = keys;
484
- }
478
+ this.keys.remove(this.identifier);
485
479
  }
486
480
 
487
481
  this.doChange('clear', []);