@etsoo/appscript 1.5.42 → 1.5.44

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.
@@ -420,17 +420,6 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
420
420
  * @returns Error message
421
421
  */
422
422
  formatError(error: ApiDataError): string;
423
- /**
424
- * Refresh token failed
425
- */
426
- protected refreshTokenFailed(): void;
427
- /**
428
- * Do refresh token result
429
- * @param result Result
430
- * @param initCallCallback InitCall callback
431
- * @param silent Silent without any popups
432
- */
433
- doRefreshTokenResult(result: RefreshTokenResult<IActionResult<U>>, initCallCallback?: (result: boolean) => void, silent?: boolean): void;
434
423
  /**
435
424
  * Format as full name
436
425
  * @param familyName Family name
@@ -442,7 +431,7 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
442
431
  * @param result Refresh token result
443
432
  * @returns Message
444
433
  */
445
- formatRefreshTokenResult(result: RefreshTokenResult<IActionResult<U>>): string | undefined;
434
+ protected formatRefreshTokenResult(result: RefreshTokenResult<IActionResult<U>>): string | undefined;
446
435
  private getFieldLabel;
447
436
  /**
448
437
  * Format result text
@@ -592,8 +581,9 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
592
581
  /**
593
582
  * Refresh token
594
583
  * @param props Props
584
+ * @param callback Callback
595
585
  */
596
- refreshToken(props?: RefreshTokenProps): Promise<boolean>;
586
+ refreshToken(props?: RefreshTokenProps, callback?: (result?: boolean | string) => boolean | void): Promise<void>;
597
587
  /**
598
588
  * Setup callback
599
589
  */
@@ -643,7 +633,7 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
643
633
  * UI get involved while refreshToken not intended
644
634
  * @param params Login parameters
645
635
  */
646
- tryLogin(params?: AppLoginParams): Promise<boolean>;
636
+ tryLogin(params?: AppLoginParams): Promise<void>;
647
637
  /**
648
638
  * Update embedded status
649
639
  * @param embedded New embedded status
@@ -165,7 +165,11 @@ class CoreApp {
165
165
  const refresh = async (api, token) => {
166
166
  if (this.lastCalled) {
167
167
  // Call refreshToken to update access token
168
- await this.refreshToken();
168
+ // No popups show
169
+ await this.refreshToken({ showLoading: false }, (result) => {
170
+ console.log(`CoreApp.${this.name}.ApiRefreshToken`, result);
171
+ return false;
172
+ });
169
173
  }
170
174
  else {
171
175
  // Popup countdown for user action
@@ -1004,44 +1008,6 @@ class CoreApp {
1004
1008
  formatError(error) {
1005
1009
  return `${error.message} (${error.name})`;
1006
1010
  }
1007
- /**
1008
- * Refresh token failed
1009
- */
1010
- refreshTokenFailed() {
1011
- this.userUnauthorized();
1012
- this.toLoginPage();
1013
- }
1014
- /**
1015
- * Do refresh token result
1016
- * @param result Result
1017
- * @param initCallCallback InitCall callback
1018
- * @param silent Silent without any popups
1019
- */
1020
- doRefreshTokenResult(result, initCallCallback, silent = false) {
1021
- if (Array.isArray(result) &&
1022
- !(result instanceof restclient_1.ApiDataError) &&
1023
- this.checkDeviceResult(result[1])) {
1024
- initCallCallback ?? (initCallCallback = (result) => {
1025
- if (!result)
1026
- return;
1027
- this.notifier.alert(this.get('environmentChanged') ??
1028
- 'Environment changed', () => {
1029
- // Reload the page
1030
- history.go(0);
1031
- });
1032
- });
1033
- this.initCall(initCallCallback, true);
1034
- return;
1035
- }
1036
- const message = this.formatRefreshTokenResult(result);
1037
- if (message == null || silent) {
1038
- this.refreshTokenFailed();
1039
- return;
1040
- }
1041
- this.notifier.alert(message, () => {
1042
- this.refreshTokenFailed();
1043
- });
1044
- }
1045
1011
  /**
1046
1012
  * Format as full name
1047
1013
  * @param familyName Family name
@@ -1414,10 +1380,9 @@ class CoreApp {
1414
1380
  /**
1415
1381
  * Refresh token
1416
1382
  * @param props Props
1383
+ * @param callback Callback
1417
1384
  */
1418
- async refreshToken(props) {
1419
- return true;
1420
- }
1385
+ async refreshToken(props, callback) { }
1421
1386
  /**
1422
1387
  * Setup callback
1423
1388
  */
@@ -1611,10 +1576,9 @@ class CoreApp {
1611
1576
  async tryLogin(params) {
1612
1577
  // Check status
1613
1578
  if (this._isTryingLogin)
1614
- return false;
1579
+ return;
1615
1580
  this._isTryingLogin = true;
1616
1581
  this.toLoginPage(params);
1617
- return true;
1618
1582
  }
1619
1583
  /**
1620
1584
  * Update embedded status
@@ -350,25 +350,12 @@ export interface IApp {
350
350
  * @returns Result
351
351
  */
352
352
  formatNumber(input: number | bigint, options?: Intl.NumberFormatOptions): string;
353
- /**
354
- * Do refresh token result
355
- * @param result Result
356
- * @param initCallCallback InitCall callback
357
- * @param silent Silent without any popups
358
- */
359
- doRefreshTokenResult(result: RefreshTokenResult<IActionResult<IUser>>, initCallCallback?: (result: boolean) => void, silent?: boolean): void;
360
353
  /**
361
354
  * Format as full name
362
355
  * @param familyName Family name
363
356
  * @param givenName Given name
364
357
  */
365
358
  formatFullName(familyName: string | undefined | null, givenName: string | undefined | null): string;
366
- /**
367
- * Format refresh token result
368
- * @param result Refresh token result
369
- * @returns Message
370
- */
371
- formatRefreshTokenResult(result: RefreshTokenResult<IActionResult<IUser>>): string | undefined;
372
359
  /**
373
360
  * Format result text
374
361
  * @param result Action result
@@ -530,8 +517,9 @@ export interface IApp {
530
517
  /**
531
518
  * Refresh token
532
519
  * @param props Props
520
+ * @param callback Callback
533
521
  */
534
- refreshToken(props?: RefreshTokenProps): Promise<boolean>;
522
+ refreshToken(props?: RefreshTokenProps, callback?: (result?: boolean | string) => boolean | void): Promise<void>;
535
523
  /**
536
524
  * Setup Api error handler
537
525
  * @param api Api
@@ -567,7 +555,7 @@ export interface IApp {
567
555
  * UI get involved while refreshToken not intended
568
556
  * @param params Login parameters
569
557
  */
570
- tryLogin(params?: AppLoginParams): Promise<boolean>;
558
+ tryLogin(params?: AppLoginParams): Promise<void>;
571
559
  /**
572
560
  * Update API token and expires
573
561
  * @param name Api name
@@ -14,6 +14,10 @@ import { RefreshTokenProps, RefreshTokenResult } from '../app/IApp';
14
14
  * Authentication API
15
15
  */
16
16
  export declare class AuthApi extends BaseApi {
17
+ /**
18
+ * Header token field name
19
+ */
20
+ static HeaderTokenField: string;
17
21
  /**
18
22
  * API refresh token
19
23
  * @param rq Request data
@@ -72,7 +72,7 @@ class AuthApi extends BaseApi_1.BaseApi {
72
72
  */
73
73
  async refreshToken(token, props) {
74
74
  // Destruct
75
- const { api = 'Auth/RefreshToken', showLoading = false, tokenField = 'Etsoo-Refresh-Token' } = props ?? {};
75
+ const { api = 'Auth/RefreshToken', showLoading = false, tokenField = AuthApi.HeaderTokenField } = props ?? {};
76
76
  // Reqest data
77
77
  const rq = {
78
78
  deviceId: this.app.deviceId
@@ -117,3 +117,7 @@ class AuthApi extends BaseApi_1.BaseApi {
117
117
  }
118
118
  }
119
119
  exports.AuthApi = AuthApi;
120
+ /**
121
+ * Header token field name
122
+ */
123
+ AuthApi.HeaderTokenField = 'Etsoo-Refresh-Token';
@@ -63,7 +63,7 @@ export declare class OrgApi extends EntityApi {
63
63
  * @param serviceId Service id
64
64
  * @param payload Payload
65
65
  */
66
- switch(id: number, serviceId?: number, payload?: IApiPayload<boolean>): Promise<boolean | undefined>;
66
+ switch(id: number, serviceId?: number, payload?: IApiPayload<boolean>): Promise<false | void>;
67
67
  /**
68
68
  * Update
69
69
  * @param data Modal data
@@ -420,17 +420,6 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
420
420
  * @returns Error message
421
421
  */
422
422
  formatError(error: ApiDataError): string;
423
- /**
424
- * Refresh token failed
425
- */
426
- protected refreshTokenFailed(): void;
427
- /**
428
- * Do refresh token result
429
- * @param result Result
430
- * @param initCallCallback InitCall callback
431
- * @param silent Silent without any popups
432
- */
433
- doRefreshTokenResult(result: RefreshTokenResult<IActionResult<U>>, initCallCallback?: (result: boolean) => void, silent?: boolean): void;
434
423
  /**
435
424
  * Format as full name
436
425
  * @param familyName Family name
@@ -442,7 +431,7 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
442
431
  * @param result Refresh token result
443
432
  * @returns Message
444
433
  */
445
- formatRefreshTokenResult(result: RefreshTokenResult<IActionResult<U>>): string | undefined;
434
+ protected formatRefreshTokenResult(result: RefreshTokenResult<IActionResult<U>>): string | undefined;
446
435
  private getFieldLabel;
447
436
  /**
448
437
  * Format result text
@@ -592,8 +581,9 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
592
581
  /**
593
582
  * Refresh token
594
583
  * @param props Props
584
+ * @param callback Callback
595
585
  */
596
- refreshToken(props?: RefreshTokenProps): Promise<boolean>;
586
+ refreshToken(props?: RefreshTokenProps, callback?: (result?: boolean | string) => boolean | void): Promise<void>;
597
587
  /**
598
588
  * Setup callback
599
589
  */
@@ -643,7 +633,7 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
643
633
  * UI get involved while refreshToken not intended
644
634
  * @param params Login parameters
645
635
  */
646
- tryLogin(params?: AppLoginParams): Promise<boolean>;
636
+ tryLogin(params?: AppLoginParams): Promise<void>;
647
637
  /**
648
638
  * Update embedded status
649
639
  * @param embedded New embedded status
@@ -162,7 +162,11 @@ export class CoreApp {
162
162
  const refresh = async (api, token) => {
163
163
  if (this.lastCalled) {
164
164
  // Call refreshToken to update access token
165
- await this.refreshToken();
165
+ // No popups show
166
+ await this.refreshToken({ showLoading: false }, (result) => {
167
+ console.log(`CoreApp.${this.name}.ApiRefreshToken`, result);
168
+ return false;
169
+ });
166
170
  }
167
171
  else {
168
172
  // Popup countdown for user action
@@ -1001,44 +1005,6 @@ export class CoreApp {
1001
1005
  formatError(error) {
1002
1006
  return `${error.message} (${error.name})`;
1003
1007
  }
1004
- /**
1005
- * Refresh token failed
1006
- */
1007
- refreshTokenFailed() {
1008
- this.userUnauthorized();
1009
- this.toLoginPage();
1010
- }
1011
- /**
1012
- * Do refresh token result
1013
- * @param result Result
1014
- * @param initCallCallback InitCall callback
1015
- * @param silent Silent without any popups
1016
- */
1017
- doRefreshTokenResult(result, initCallCallback, silent = false) {
1018
- if (Array.isArray(result) &&
1019
- !(result instanceof ApiDataError) &&
1020
- this.checkDeviceResult(result[1])) {
1021
- initCallCallback ?? (initCallCallback = (result) => {
1022
- if (!result)
1023
- return;
1024
- this.notifier.alert(this.get('environmentChanged') ??
1025
- 'Environment changed', () => {
1026
- // Reload the page
1027
- history.go(0);
1028
- });
1029
- });
1030
- this.initCall(initCallCallback, true);
1031
- return;
1032
- }
1033
- const message = this.formatRefreshTokenResult(result);
1034
- if (message == null || silent) {
1035
- this.refreshTokenFailed();
1036
- return;
1037
- }
1038
- this.notifier.alert(message, () => {
1039
- this.refreshTokenFailed();
1040
- });
1041
- }
1042
1008
  /**
1043
1009
  * Format as full name
1044
1010
  * @param familyName Family name
@@ -1411,10 +1377,9 @@ export class CoreApp {
1411
1377
  /**
1412
1378
  * Refresh token
1413
1379
  * @param props Props
1380
+ * @param callback Callback
1414
1381
  */
1415
- async refreshToken(props) {
1416
- return true;
1417
- }
1382
+ async refreshToken(props, callback) { }
1418
1383
  /**
1419
1384
  * Setup callback
1420
1385
  */
@@ -1608,10 +1573,9 @@ export class CoreApp {
1608
1573
  async tryLogin(params) {
1609
1574
  // Check status
1610
1575
  if (this._isTryingLogin)
1611
- return false;
1576
+ return;
1612
1577
  this._isTryingLogin = true;
1613
1578
  this.toLoginPage(params);
1614
- return true;
1615
1579
  }
1616
1580
  /**
1617
1581
  * Update embedded status
@@ -350,25 +350,12 @@ export interface IApp {
350
350
  * @returns Result
351
351
  */
352
352
  formatNumber(input: number | bigint, options?: Intl.NumberFormatOptions): string;
353
- /**
354
- * Do refresh token result
355
- * @param result Result
356
- * @param initCallCallback InitCall callback
357
- * @param silent Silent without any popups
358
- */
359
- doRefreshTokenResult(result: RefreshTokenResult<IActionResult<IUser>>, initCallCallback?: (result: boolean) => void, silent?: boolean): void;
360
353
  /**
361
354
  * Format as full name
362
355
  * @param familyName Family name
363
356
  * @param givenName Given name
364
357
  */
365
358
  formatFullName(familyName: string | undefined | null, givenName: string | undefined | null): string;
366
- /**
367
- * Format refresh token result
368
- * @param result Refresh token result
369
- * @returns Message
370
- */
371
- formatRefreshTokenResult(result: RefreshTokenResult<IActionResult<IUser>>): string | undefined;
372
359
  /**
373
360
  * Format result text
374
361
  * @param result Action result
@@ -530,8 +517,9 @@ export interface IApp {
530
517
  /**
531
518
  * Refresh token
532
519
  * @param props Props
520
+ * @param callback Callback
533
521
  */
534
- refreshToken(props?: RefreshTokenProps): Promise<boolean>;
522
+ refreshToken(props?: RefreshTokenProps, callback?: (result?: boolean | string) => boolean | void): Promise<void>;
535
523
  /**
536
524
  * Setup Api error handler
537
525
  * @param api Api
@@ -567,7 +555,7 @@ export interface IApp {
567
555
  * UI get involved while refreshToken not intended
568
556
  * @param params Login parameters
569
557
  */
570
- tryLogin(params?: AppLoginParams): Promise<boolean>;
558
+ tryLogin(params?: AppLoginParams): Promise<void>;
571
559
  /**
572
560
  * Update API token and expires
573
561
  * @param name Api name
@@ -14,6 +14,10 @@ import { RefreshTokenProps, RefreshTokenResult } from '../app/IApp';
14
14
  * Authentication API
15
15
  */
16
16
  export declare class AuthApi extends BaseApi {
17
+ /**
18
+ * Header token field name
19
+ */
20
+ static HeaderTokenField: string;
17
21
  /**
18
22
  * API refresh token
19
23
  * @param rq Request data
@@ -69,7 +69,7 @@ export class AuthApi extends BaseApi {
69
69
  */
70
70
  async refreshToken(token, props) {
71
71
  // Destruct
72
- const { api = 'Auth/RefreshToken', showLoading = false, tokenField = 'Etsoo-Refresh-Token' } = props ?? {};
72
+ const { api = 'Auth/RefreshToken', showLoading = false, tokenField = AuthApi.HeaderTokenField } = props ?? {};
73
73
  // Reqest data
74
74
  const rq = {
75
75
  deviceId: this.app.deviceId
@@ -113,3 +113,7 @@ export class AuthApi extends BaseApi {
113
113
  return this.api.put('Auth/Signout', rq, payload);
114
114
  }
115
115
  }
116
+ /**
117
+ * Header token field name
118
+ */
119
+ AuthApi.HeaderTokenField = 'Etsoo-Refresh-Token';
@@ -63,7 +63,7 @@ export declare class OrgApi extends EntityApi {
63
63
  * @param serviceId Service id
64
64
  * @param payload Payload
65
65
  */
66
- switch(id: number, serviceId?: number, payload?: IApiPayload<boolean>): Promise<boolean | undefined>;
66
+ switch(id: number, serviceId?: number, payload?: IApiPayload<boolean>): Promise<false | void>;
67
67
  /**
68
68
  * Update
69
69
  * @param data Modal data
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/appscript",
3
- "version": "1.5.42",
3
+ "version": "1.5.44",
4
4
  "description": "Applications shared TypeScript framework",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/mjs/index.js",
@@ -332,7 +332,11 @@ export abstract class CoreApp<
332
332
  const refresh: ApiRefreshTokenFunction = async (api, token) => {
333
333
  if (this.lastCalled) {
334
334
  // Call refreshToken to update access token
335
- await this.refreshToken();
335
+ // No popups show
336
+ await this.refreshToken({ showLoading: false }, (result) => {
337
+ console.log(`CoreApp.${this.name}.ApiRefreshToken`, result);
338
+ return false;
339
+ });
336
340
  } else {
337
341
  // Popup countdown for user action
338
342
  this.freshCountdownUI();
@@ -1476,57 +1480,6 @@ export abstract class CoreApp<
1476
1480
  return `${error.message} (${error.name})`;
1477
1481
  }
1478
1482
 
1479
- /**
1480
- * Refresh token failed
1481
- */
1482
- protected refreshTokenFailed() {
1483
- this.userUnauthorized();
1484
- this.toLoginPage();
1485
- }
1486
-
1487
- /**
1488
- * Do refresh token result
1489
- * @param result Result
1490
- * @param initCallCallback InitCall callback
1491
- * @param silent Silent without any popups
1492
- */
1493
- doRefreshTokenResult(
1494
- result: RefreshTokenResult<IActionResult<U>>,
1495
- initCallCallback?: (result: boolean) => void,
1496
- silent: boolean = false
1497
- ) {
1498
- if (
1499
- Array.isArray(result) &&
1500
- !(result instanceof ApiDataError) &&
1501
- this.checkDeviceResult(result[1])
1502
- ) {
1503
- initCallCallback ??= (result) => {
1504
- if (!result) return;
1505
- this.notifier.alert(
1506
- this.get<string>('environmentChanged') ??
1507
- 'Environment changed',
1508
- () => {
1509
- // Reload the page
1510
- history.go(0);
1511
- }
1512
- );
1513
- };
1514
-
1515
- this.initCall(initCallCallback, true);
1516
- return;
1517
- }
1518
-
1519
- const message = this.formatRefreshTokenResult(result);
1520
- if (message == null || silent) {
1521
- this.refreshTokenFailed();
1522
- return;
1523
- }
1524
-
1525
- this.notifier.alert(message, () => {
1526
- this.refreshTokenFailed();
1527
- });
1528
- }
1529
-
1530
1483
  /**
1531
1484
  * Format as full name
1532
1485
  * @param familyName Family name
@@ -1550,7 +1503,9 @@ export abstract class CoreApp<
1550
1503
  * @param result Refresh token result
1551
1504
  * @returns Message
1552
1505
  */
1553
- formatRefreshTokenResult(result: RefreshTokenResult<IActionResult<U>>) {
1506
+ protected formatRefreshTokenResult(
1507
+ result: RefreshTokenResult<IActionResult<U>>
1508
+ ): string | undefined {
1554
1509
  // Error message
1555
1510
  if (typeof result === 'string') return result;
1556
1511
 
@@ -1957,10 +1912,12 @@ export abstract class CoreApp<
1957
1912
  /**
1958
1913
  * Refresh token
1959
1914
  * @param props Props
1915
+ * @param callback Callback
1960
1916
  */
1961
- async refreshToken(props?: RefreshTokenProps) {
1962
- return true;
1963
- }
1917
+ async refreshToken(
1918
+ props?: RefreshTokenProps,
1919
+ callback?: (result?: boolean | string) => boolean | void
1920
+ ) {}
1964
1921
 
1965
1922
  /**
1966
1923
  * Setup callback
@@ -2203,12 +2160,10 @@ export abstract class CoreApp<
2203
2160
  */
2204
2161
  async tryLogin(params?: AppLoginParams) {
2205
2162
  // Check status
2206
- if (this._isTryingLogin) return false;
2163
+ if (this._isTryingLogin) return;
2207
2164
  this._isTryingLogin = true;
2208
2165
 
2209
2166
  this.toLoginPage(params);
2210
-
2211
- return true;
2212
2167
  }
2213
2168
 
2214
2169
  /**
package/src/app/IApp.ts CHANGED
@@ -473,18 +473,6 @@ export interface IApp {
473
473
  options?: Intl.NumberFormatOptions
474
474
  ): string;
475
475
 
476
- /**
477
- * Do refresh token result
478
- * @param result Result
479
- * @param initCallCallback InitCall callback
480
- * @param silent Silent without any popups
481
- */
482
- doRefreshTokenResult(
483
- result: RefreshTokenResult<IActionResult<IUser>>,
484
- initCallCallback?: (result: boolean) => void,
485
- silent?: boolean
486
- ): void;
487
-
488
476
  /**
489
477
  * Format as full name
490
478
  * @param familyName Family name
@@ -495,15 +483,6 @@ export interface IApp {
495
483
  givenName: string | undefined | null
496
484
  ): string;
497
485
 
498
- /**
499
- * Format refresh token result
500
- * @param result Refresh token result
501
- * @returns Message
502
- */
503
- formatRefreshTokenResult(
504
- result: RefreshTokenResult<IActionResult<IUser>>
505
- ): string | undefined;
506
-
507
486
  /**
508
487
  * Format result text
509
488
  * @param result Action result
@@ -718,8 +697,12 @@ export interface IApp {
718
697
  /**
719
698
  * Refresh token
720
699
  * @param props Props
700
+ * @param callback Callback
721
701
  */
722
- refreshToken(props?: RefreshTokenProps): Promise<boolean>;
702
+ refreshToken(
703
+ props?: RefreshTokenProps,
704
+ callback?: (result?: boolean | string) => boolean | void
705
+ ): Promise<void>;
723
706
 
724
707
  /**
725
708
  * Setup Api error handler
@@ -768,7 +751,7 @@ export interface IApp {
768
751
  * UI get involved while refreshToken not intended
769
752
  * @param params Login parameters
770
753
  */
771
- tryLogin(params?: AppLoginParams): Promise<boolean>;
754
+ tryLogin(params?: AppLoginParams): Promise<void>;
772
755
 
773
756
  /**
774
757
  * Update API token and expires
@@ -17,6 +17,11 @@ import { RefreshTokenRQ } from './rq/RefreshTokenRQ';
17
17
  * Authentication API
18
18
  */
19
19
  export class AuthApi extends BaseApi {
20
+ /**
21
+ * Header token field name
22
+ */
23
+ static HeaderTokenField = 'Etsoo-Refresh-Token';
24
+
20
25
  /**
21
26
  * API refresh token
22
27
  * @param rq Request data
@@ -98,7 +103,7 @@ export class AuthApi extends BaseApi {
98
103
  const {
99
104
  api = 'Auth/RefreshToken',
100
105
  showLoading = false,
101
- tokenField = 'Etsoo-Refresh-Token'
106
+ tokenField = AuthApi.HeaderTokenField
102
107
  } = props ?? {};
103
108
 
104
109
  // Reqest data