@etsoo/appscript 1.5.47 → 1.5.49

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.
@@ -7,7 +7,7 @@ import { InitCallDto } from '../erp/dto/InitCallDto';
7
7
  import { InitCallResult, InitCallResultData } from '../result/InitCallResult';
8
8
  import { IUser } from '../state/User';
9
9
  import { IAppSettings } from './AppSettings';
10
- import { AppLoginParams, FormatResultCustomCallback, IApp, IAppFields, IDetectIPCallback, NavigateOptions, RefreshTokenProps } from './IApp';
10
+ import { AppLoginParams, AppTryLoginParams, FormatResultCustomCallback, IApp, IAppFields, IDetectIPCallback, NavigateOptions, RefreshTokenProps } from './IApp';
11
11
  import { UserRole } from './UserRole';
12
12
  import { ExternalEndpoint } from './ExternalSettings';
13
13
  import { ApiRefreshTokenDto } from '../erp/dto/ApiRefreshTokenDto';
@@ -600,6 +600,13 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
600
600
  * @param coreName Core system's name, default is 'core'
601
601
  */
602
602
  exchangeTokenAll(coreData: ApiRefreshTokenDto, coreName?: string): void;
603
+ /**
604
+ * API refresh token data
605
+ * @param api Current API
606
+ * @param token Refresh token
607
+ * @returns Result
608
+ */
609
+ protected apiRefreshTokenData(api: IApi, token: string): Promise<ApiRefreshTokenDto | undefined>;
603
610
  /**
604
611
  * API refresh token
605
612
  * @param api Current API
@@ -626,7 +633,7 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
626
633
  * UI get involved while refreshToken not intended
627
634
  * @param params Login parameters
628
635
  */
629
- tryLogin(params?: AppLoginParams): Promise<void>;
636
+ tryLogin(params?: AppTryLoginParams): Promise<boolean>;
630
637
  /**
631
638
  * Update embedded status
632
639
  * @param embedded New embedded status
@@ -1488,14 +1488,14 @@ class CoreApp {
1488
1488
  }
1489
1489
  }
1490
1490
  /**
1491
- * API refresh token
1491
+ * API refresh token data
1492
1492
  * @param api Current API
1493
1493
  * @param token Refresh token
1494
1494
  * @returns Result
1495
1495
  */
1496
- async apiRefreshToken(api, token) {
1496
+ async apiRefreshTokenData(api, token) {
1497
1497
  // Call the API quietly, no loading bar and no error popup
1498
- const data = await new AuthApi_1.AuthApi(this).apiRefreshToken({ token }, {
1498
+ return new AuthApi_1.AuthApi(this).apiRefreshToken({ token }, {
1499
1499
  showLoading: false,
1500
1500
  onError: (error) => {
1501
1501
  console.error(`CoreApp.${api.name}.apiRefreshToken error`, error);
@@ -1503,6 +1503,16 @@ class CoreApp {
1503
1503
  return false;
1504
1504
  }
1505
1505
  });
1506
+ }
1507
+ /**
1508
+ * API refresh token
1509
+ * @param api Current API
1510
+ * @param token Refresh token
1511
+ * @returns Result
1512
+ */
1513
+ async apiRefreshToken(api, token) {
1514
+ // Call the API quietly, no loading bar and no error popup
1515
+ const data = await this.apiRefreshTokenData(api, token);
1506
1516
  if (data == null)
1507
1517
  return undefined;
1508
1518
  // Update the access token
@@ -1614,9 +1624,9 @@ class CoreApp {
1614
1624
  async tryLogin(params) {
1615
1625
  // Check status
1616
1626
  if (this._isTryingLogin)
1617
- return;
1627
+ return false;
1618
1628
  this._isTryingLogin = true;
1619
- this.toLoginPage(params);
1629
+ return true;
1620
1630
  }
1621
1631
  /**
1622
1632
  * Update embedded status
@@ -57,6 +57,19 @@ export type AppLoginParams = DataTypes.SimpleObject & {
57
57
  */
58
58
  showLoading?: boolean;
59
59
  };
60
+ /**
61
+ * App try login parameters
62
+ */
63
+ export type AppTryLoginParams = AppLoginParams & {
64
+ /**
65
+ * Callback on failure
66
+ */
67
+ onFailure?: () => void;
68
+ /**
69
+ * Callback on success
70
+ */
71
+ onSuccess?: () => void;
72
+ };
60
73
  /**
61
74
  * Refresh token props
62
75
  */
@@ -560,7 +573,7 @@ export interface IApp {
560
573
  * UI get involved while refreshToken not intended
561
574
  * @param params Login parameters
562
575
  */
563
- tryLogin(params?: AppLoginParams): Promise<void>;
576
+ tryLogin(params?: AppLoginParams): Promise<boolean>;
564
577
  /**
565
578
  * Update API token and expires
566
579
  * @param name Api name
@@ -7,7 +7,7 @@ import { InitCallDto } from '../erp/dto/InitCallDto';
7
7
  import { InitCallResult, InitCallResultData } from '../result/InitCallResult';
8
8
  import { IUser } from '../state/User';
9
9
  import { IAppSettings } from './AppSettings';
10
- import { AppLoginParams, FormatResultCustomCallback, IApp, IAppFields, IDetectIPCallback, NavigateOptions, RefreshTokenProps } from './IApp';
10
+ import { AppLoginParams, AppTryLoginParams, FormatResultCustomCallback, IApp, IAppFields, IDetectIPCallback, NavigateOptions, RefreshTokenProps } from './IApp';
11
11
  import { UserRole } from './UserRole';
12
12
  import { ExternalEndpoint } from './ExternalSettings';
13
13
  import { ApiRefreshTokenDto } from '../erp/dto/ApiRefreshTokenDto';
@@ -600,6 +600,13 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
600
600
  * @param coreName Core system's name, default is 'core'
601
601
  */
602
602
  exchangeTokenAll(coreData: ApiRefreshTokenDto, coreName?: string): void;
603
+ /**
604
+ * API refresh token data
605
+ * @param api Current API
606
+ * @param token Refresh token
607
+ * @returns Result
608
+ */
609
+ protected apiRefreshTokenData(api: IApi, token: string): Promise<ApiRefreshTokenDto | undefined>;
603
610
  /**
604
611
  * API refresh token
605
612
  * @param api Current API
@@ -626,7 +633,7 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
626
633
  * UI get involved while refreshToken not intended
627
634
  * @param params Login parameters
628
635
  */
629
- tryLogin(params?: AppLoginParams): Promise<void>;
636
+ tryLogin(params?: AppTryLoginParams): Promise<boolean>;
630
637
  /**
631
638
  * Update embedded status
632
639
  * @param embedded New embedded status
@@ -1485,14 +1485,14 @@ export class CoreApp {
1485
1485
  }
1486
1486
  }
1487
1487
  /**
1488
- * API refresh token
1488
+ * API refresh token data
1489
1489
  * @param api Current API
1490
1490
  * @param token Refresh token
1491
1491
  * @returns Result
1492
1492
  */
1493
- async apiRefreshToken(api, token) {
1493
+ async apiRefreshTokenData(api, token) {
1494
1494
  // Call the API quietly, no loading bar and no error popup
1495
- const data = await new AuthApi(this).apiRefreshToken({ token }, {
1495
+ return new AuthApi(this).apiRefreshToken({ token }, {
1496
1496
  showLoading: false,
1497
1497
  onError: (error) => {
1498
1498
  console.error(`CoreApp.${api.name}.apiRefreshToken error`, error);
@@ -1500,6 +1500,16 @@ export class CoreApp {
1500
1500
  return false;
1501
1501
  }
1502
1502
  });
1503
+ }
1504
+ /**
1505
+ * API refresh token
1506
+ * @param api Current API
1507
+ * @param token Refresh token
1508
+ * @returns Result
1509
+ */
1510
+ async apiRefreshToken(api, token) {
1511
+ // Call the API quietly, no loading bar and no error popup
1512
+ const data = await this.apiRefreshTokenData(api, token);
1503
1513
  if (data == null)
1504
1514
  return undefined;
1505
1515
  // Update the access token
@@ -1611,9 +1621,9 @@ export class CoreApp {
1611
1621
  async tryLogin(params) {
1612
1622
  // Check status
1613
1623
  if (this._isTryingLogin)
1614
- return;
1624
+ return false;
1615
1625
  this._isTryingLogin = true;
1616
- this.toLoginPage(params);
1626
+ return true;
1617
1627
  }
1618
1628
  /**
1619
1629
  * Update embedded status
@@ -57,6 +57,19 @@ export type AppLoginParams = DataTypes.SimpleObject & {
57
57
  */
58
58
  showLoading?: boolean;
59
59
  };
60
+ /**
61
+ * App try login parameters
62
+ */
63
+ export type AppTryLoginParams = AppLoginParams & {
64
+ /**
65
+ * Callback on failure
66
+ */
67
+ onFailure?: () => void;
68
+ /**
69
+ * Callback on success
70
+ */
71
+ onSuccess?: () => void;
72
+ };
60
73
  /**
61
74
  * Refresh token props
62
75
  */
@@ -560,7 +573,7 @@ export interface IApp {
560
573
  * UI get involved while refreshToken not intended
561
574
  * @param params Login parameters
562
575
  */
563
- tryLogin(params?: AppLoginParams): Promise<void>;
576
+ tryLogin(params?: AppLoginParams): Promise<boolean>;
564
577
  /**
565
578
  * Update API token and expires
566
579
  * @param name Api name
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/appscript",
3
- "version": "1.5.47",
3
+ "version": "1.5.49",
4
4
  "description": "Applications shared TypeScript framework",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/mjs/index.js",
@@ -34,6 +34,7 @@ import { IAppSettings } from './AppSettings';
34
34
  import {
35
35
  appFields,
36
36
  AppLoginParams,
37
+ AppTryLoginParams,
37
38
  FormatResultCustomCallback,
38
39
  IApp,
39
40
  IAppFields,
@@ -2045,17 +2046,17 @@ export abstract class CoreApp<
2045
2046
  }
2046
2047
 
2047
2048
  /**
2048
- * API refresh token
2049
+ * API refresh token data
2049
2050
  * @param api Current API
2050
2051
  * @param token Refresh token
2051
2052
  * @returns Result
2052
2053
  */
2053
- protected async apiRefreshToken(
2054
+ protected async apiRefreshTokenData(
2054
2055
  api: IApi,
2055
2056
  token: string
2056
- ): Promise<[string, number] | undefined> {
2057
+ ): Promise<ApiRefreshTokenDto | undefined> {
2057
2058
  // Call the API quietly, no loading bar and no error popup
2058
- const data = await new AuthApi(this).apiRefreshToken(
2059
+ return new AuthApi(this).apiRefreshToken(
2059
2060
  { token },
2060
2061
  {
2061
2062
  showLoading: false,
@@ -2070,6 +2071,20 @@ export abstract class CoreApp<
2070
2071
  }
2071
2072
  }
2072
2073
  );
2074
+ }
2075
+
2076
+ /**
2077
+ * API refresh token
2078
+ * @param api Current API
2079
+ * @param token Refresh token
2080
+ * @returns Result
2081
+ */
2082
+ protected async apiRefreshToken(
2083
+ api: IApi,
2084
+ token: string
2085
+ ): Promise<[string, number] | undefined> {
2086
+ // Call the API quietly, no loading bar and no error popup
2087
+ const data = await this.apiRefreshTokenData(api, token);
2073
2088
  if (data == null) return undefined;
2074
2089
 
2075
2090
  // Update the access token
@@ -2199,12 +2214,12 @@ export abstract class CoreApp<
2199
2214
  * UI get involved while refreshToken not intended
2200
2215
  * @param params Login parameters
2201
2216
  */
2202
- async tryLogin(params?: AppLoginParams) {
2217
+ async tryLogin(params?: AppTryLoginParams) {
2203
2218
  // Check status
2204
- if (this._isTryingLogin) return;
2219
+ if (this._isTryingLogin) return false;
2205
2220
  this._isTryingLogin = true;
2206
2221
 
2207
- this.toLoginPage(params);
2222
+ return true;
2208
2223
  }
2209
2224
 
2210
2225
  /**
package/src/app/IApp.ts CHANGED
@@ -83,6 +83,21 @@ export type AppLoginParams = DataTypes.SimpleObject & {
83
83
  showLoading?: boolean;
84
84
  };
85
85
 
86
+ /**
87
+ * App try login parameters
88
+ */
89
+ export type AppTryLoginParams = AppLoginParams & {
90
+ /**
91
+ * Callback on failure
92
+ */
93
+ onFailure?: () => void;
94
+
95
+ /**
96
+ * Callback on success
97
+ */
98
+ onSuccess?: () => void;
99
+ };
100
+
86
101
  /**
87
102
  * Refresh token props
88
103
  */
@@ -757,7 +772,7 @@ export interface IApp {
757
772
  * UI get involved while refreshToken not intended
758
773
  * @param params Login parameters
759
774
  */
760
- tryLogin(params?: AppLoginParams): Promise<void>;
775
+ tryLogin(params?: AppLoginParams): Promise<boolean>;
761
776
 
762
777
  /**
763
778
  * Update API token and expires