@etsoo/appscript 1.1.3 → 1.1.4

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.
@@ -43,6 +43,10 @@ export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallP
43
43
  * Country or region, like CN
44
44
  */
45
45
  readonly region: string;
46
+ /**
47
+ * Is current authorized
48
+ */
49
+ readonly authorized: boolean;
46
50
  /**
47
51
  * IP data
48
52
  */
@@ -149,6 +153,10 @@ export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallP
149
153
  * @returns Transformed url
150
154
  */
151
155
  transformUrl(url: string): string;
156
+ /**
157
+ * Try login, returning false means is loading
158
+ */
159
+ tryLogin(): boolean;
152
160
  /**
153
161
  * User login
154
162
  * @param user User data
@@ -213,6 +221,13 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
213
221
  * Search input element
214
222
  */
215
223
  searchInput?: HTMLInputElement;
224
+ private _authorized;
225
+ /**
226
+ * Is current authorized
227
+ */
228
+ get authorized(): boolean;
229
+ private set authorized(value);
230
+ private _isTryingLogin;
216
231
  /**
217
232
  * Protected constructor
218
233
  * @param settings Settings
@@ -326,9 +341,9 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
326
341
  */
327
342
  transformUrl(url: string): string;
328
343
  /**
329
- * Try login
344
+ * Try login, returning false means is loading
330
345
  */
331
- abstract tryLogin(): void;
346
+ tryLogin(): boolean;
332
347
  /**
333
348
  * User login
334
349
  * @param user User data
@@ -19,6 +19,8 @@ class CoreApp {
19
19
  * Response token header field name
20
20
  */
21
21
  this.headerTokenField = 'SmartERPRefreshToken';
22
+ this._authorized = false;
23
+ this._isTryingLogin = false;
22
24
  // onRequest, show loading or not, rewrite the property to override default action
23
25
  api.onRequest = (data) => {
24
26
  if (data.showLoading == null || data.showLoading) {
@@ -79,6 +81,15 @@ class CoreApp {
79
81
  get labelDelegate() {
80
82
  return this.get.bind(this);
81
83
  }
84
+ /**
85
+ * Is current authorized
86
+ */
87
+ get authorized() {
88
+ return this._authorized;
89
+ }
90
+ set authorized(value) {
91
+ this._authorized = value;
92
+ }
82
93
  /**
83
94
  * Alert action result
84
95
  * @param result Action result
@@ -93,10 +104,15 @@ class CoreApp {
93
104
  * @param keep Keep in local storage or not
94
105
  */
95
106
  authorize(token, refreshToken, keep = false) {
107
+ // State, when token is null, means logout
108
+ this.authorized = token != null;
109
+ // Token
96
110
  this.api.authorize(this.settings.authScheme, token);
97
111
  // Cover the current value
98
112
  shared_1.StorageUtils.setLocalData(this.headerTokenField, keep ? refreshToken : undefined);
99
113
  shared_1.StorageUtils.setSessionData(this.headerTokenField, keep ? undefined : refreshToken);
114
+ // Reset tryLogin state
115
+ this._isTryingLogin = false;
100
116
  }
101
117
  /**
102
118
  * Change country or region
@@ -312,6 +328,15 @@ class CoreApp {
312
328
  // To /a/b/../ => /a
313
329
  return pathname.endsWith('/') ? pathname + url : pathname + '/' + url;
314
330
  }
331
+ /**
332
+ * Try login, returning false means is loading
333
+ */
334
+ tryLogin() {
335
+ if (this._isTryingLogin)
336
+ return false;
337
+ this._isTryingLogin = true;
338
+ return true;
339
+ }
315
340
  /**
316
341
  * User login
317
342
  * @param user User data
@@ -43,6 +43,10 @@ export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallP
43
43
  * Country or region, like CN
44
44
  */
45
45
  readonly region: string;
46
+ /**
47
+ * Is current authorized
48
+ */
49
+ readonly authorized: boolean;
46
50
  /**
47
51
  * IP data
48
52
  */
@@ -149,6 +153,10 @@ export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallP
149
153
  * @returns Transformed url
150
154
  */
151
155
  transformUrl(url: string): string;
156
+ /**
157
+ * Try login, returning false means is loading
158
+ */
159
+ tryLogin(): boolean;
152
160
  /**
153
161
  * User login
154
162
  * @param user User data
@@ -213,6 +221,13 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
213
221
  * Search input element
214
222
  */
215
223
  searchInput?: HTMLInputElement;
224
+ private _authorized;
225
+ /**
226
+ * Is current authorized
227
+ */
228
+ get authorized(): boolean;
229
+ private set authorized(value);
230
+ private _isTryingLogin;
216
231
  /**
217
232
  * Protected constructor
218
233
  * @param settings Settings
@@ -326,9 +341,9 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
326
341
  */
327
342
  transformUrl(url: string): string;
328
343
  /**
329
- * Try login
344
+ * Try login, returning false means is loading
330
345
  */
331
- abstract tryLogin(): void;
346
+ tryLogin(): boolean;
332
347
  /**
333
348
  * User login
334
349
  * @param user User data
@@ -16,6 +16,8 @@ export class CoreApp {
16
16
  * Response token header field name
17
17
  */
18
18
  this.headerTokenField = 'SmartERPRefreshToken';
19
+ this._authorized = false;
20
+ this._isTryingLogin = false;
19
21
  // onRequest, show loading or not, rewrite the property to override default action
20
22
  api.onRequest = (data) => {
21
23
  if (data.showLoading == null || data.showLoading) {
@@ -76,6 +78,15 @@ export class CoreApp {
76
78
  get labelDelegate() {
77
79
  return this.get.bind(this);
78
80
  }
81
+ /**
82
+ * Is current authorized
83
+ */
84
+ get authorized() {
85
+ return this._authorized;
86
+ }
87
+ set authorized(value) {
88
+ this._authorized = value;
89
+ }
79
90
  /**
80
91
  * Alert action result
81
92
  * @param result Action result
@@ -90,10 +101,15 @@ export class CoreApp {
90
101
  * @param keep Keep in local storage or not
91
102
  */
92
103
  authorize(token, refreshToken, keep = false) {
104
+ // State, when token is null, means logout
105
+ this.authorized = token != null;
106
+ // Token
93
107
  this.api.authorize(this.settings.authScheme, token);
94
108
  // Cover the current value
95
109
  StorageUtils.setLocalData(this.headerTokenField, keep ? refreshToken : undefined);
96
110
  StorageUtils.setSessionData(this.headerTokenField, keep ? undefined : refreshToken);
111
+ // Reset tryLogin state
112
+ this._isTryingLogin = false;
97
113
  }
98
114
  /**
99
115
  * Change country or region
@@ -309,6 +325,15 @@ export class CoreApp {
309
325
  // To /a/b/../ => /a
310
326
  return pathname.endsWith('/') ? pathname + url : pathname + '/' + url;
311
327
  }
328
+ /**
329
+ * Try login, returning false means is loading
330
+ */
331
+ tryLogin() {
332
+ if (this._isTryingLogin)
333
+ return false;
334
+ this._isTryingLogin = true;
335
+ return true;
336
+ }
312
337
  /**
313
338
  * User login
314
339
  * @param user User data
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/appscript",
3
- "version": "1.1.3",
3
+ "version": "1.1.4",
4
4
  "description": "Applications shared TypeScript framework",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/mjs/index.js",
@@ -65,6 +65,11 @@ export interface ICoreApp<
65
65
  */
66
66
  readonly region: string;
67
67
 
68
+ /**
69
+ * Is current authorized
70
+ */
71
+ readonly authorized: boolean;
72
+
68
73
  /**
69
74
  * IP data
70
75
  */
@@ -199,6 +204,11 @@ export interface ICoreApp<
199
204
  */
200
205
  transformUrl(url: string): string;
201
206
 
207
+ /**
208
+ * Try login, returning false means is loading
209
+ */
210
+ tryLogin(): boolean;
211
+
202
212
  /**
203
213
  * User login
204
214
  * @param user User data
@@ -291,6 +301,20 @@ export abstract class CoreApp<
291
301
  */
292
302
  searchInput?: HTMLInputElement;
293
303
 
304
+ private _authorized: boolean = false;
305
+ /**
306
+ * Is current authorized
307
+ */
308
+ get authorized() {
309
+ return this._authorized;
310
+ }
311
+
312
+ private set authorized(value: boolean) {
313
+ this._authorized = value;
314
+ }
315
+
316
+ private _isTryingLogin = false;
317
+
294
318
  /**
295
319
  * Protected constructor
296
320
  * @param settings Settings
@@ -355,6 +379,10 @@ export abstract class CoreApp<
355
379
  * @param keep Keep in local storage or not
356
380
  */
357
381
  authorize(token?: string, refreshToken?: string, keep: boolean = false) {
382
+ // State, when token is null, means logout
383
+ this.authorized = token != null;
384
+
385
+ // Token
358
386
  this.api.authorize(this.settings.authScheme, token);
359
387
 
360
388
  // Cover the current value
@@ -366,6 +394,9 @@ export abstract class CoreApp<
366
394
  this.headerTokenField,
367
395
  keep ? undefined : refreshToken
368
396
  );
397
+
398
+ // Reset tryLogin state
399
+ this._isTryingLogin = false;
369
400
  }
370
401
 
371
402
  /**
@@ -632,9 +663,13 @@ export abstract class CoreApp<
632
663
  }
633
664
 
634
665
  /**
635
- * Try login
666
+ * Try login, returning false means is loading
636
667
  */
637
- abstract tryLogin(): void;
668
+ tryLogin() {
669
+ if (this._isTryingLogin) return false;
670
+ this._isTryingLogin = true;
671
+ return true;
672
+ }
638
673
 
639
674
  /**
640
675
  * User login