@etsoo/appscript 1.5.46 → 1.5.48

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';
@@ -576,7 +576,7 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
576
576
  * @param props Props
577
577
  * @param callback Callback
578
578
  */
579
- refreshToken(props: RefreshTokenProps, callback?: (result?: boolean | IActionResult) => boolean | void): Promise<void>;
579
+ refreshToken(props?: RefreshTokenProps, callback?: (result?: boolean | IActionResult) => boolean | void): Promise<void>;
580
580
  /**
581
581
  * Setup callback
582
582
  */
@@ -618,7 +618,7 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
618
618
  signout(): Promise<void>;
619
619
  /**
620
620
  * Go to the login page
621
- * params Login parameters
621
+ * @params Login parameters
622
622
  */
623
623
  toLoginPage(params?: AppLoginParams): void;
624
624
  /**
@@ -626,7 +626,7 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
626
626
  * UI get involved while refreshToken not intended
627
627
  * @param params Login parameters
628
628
  */
629
- tryLogin(params?: AppLoginParams): Promise<void>;
629
+ tryLogin(params?: AppTryLoginParams): Promise<boolean>;
630
630
  /**
631
631
  * Update embedded status
632
632
  * @param embedded New embedded status
@@ -1357,6 +1357,9 @@ class CoreApp {
1357
1357
  * @param callback Callback
1358
1358
  */
1359
1359
  async refreshToken(props, callback) {
1360
+ // Check props
1361
+ props ?? (props = {});
1362
+ props.token ?? (props.token = this.getCacheToken());
1360
1363
  // Call refresh token API
1361
1364
  let data = await new AuthApi_1.AuthApi(this).refreshToken(props);
1362
1365
  let r;
@@ -1592,7 +1595,7 @@ class CoreApp {
1592
1595
  }
1593
1596
  /**
1594
1597
  * Go to the login page
1595
- * params Login parameters
1598
+ * @params Login parameters
1596
1599
  */
1597
1600
  toLoginPage(params) {
1598
1601
  // Destruct
@@ -1611,9 +1614,9 @@ class CoreApp {
1611
1614
  async tryLogin(params) {
1612
1615
  // Check status
1613
1616
  if (this._isTryingLogin)
1614
- return;
1617
+ return false;
1615
1618
  this._isTryingLogin = true;
1616
- this.toLoginPage(params);
1619
+ return true;
1617
1620
  }
1618
1621
  /**
1619
1622
  * 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
  */
@@ -64,9 +77,9 @@ export interface RefreshTokenProps {
64
77
  /**
65
78
  * Refresh token
66
79
  */
67
- token: string;
80
+ token?: string;
68
81
  /**
69
- * API name
82
+ * API URL
70
83
  */
71
84
  api?: string;
72
85
  /**
@@ -524,7 +537,7 @@ export interface IApp {
524
537
  * @param callback Callback
525
538
  * @param api API
526
539
  */
527
- refreshToken(props: RefreshTokenProps, callback?: (result?: boolean | IActionResult) => boolean | void): Promise<void>;
540
+ refreshToken(props?: RefreshTokenProps, callback?: (result?: boolean | IActionResult) => boolean | void): Promise<void>;
528
541
  /**
529
542
  * Setup Api error handler
530
543
  * @param api Api
@@ -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
@@ -73,6 +73,15 @@ class AuthApi extends BaseApi_1.BaseApi {
73
73
  async refreshToken(props) {
74
74
  // Destruct
75
75
  const { api = 'Auth/RefreshToken', showLoading = false, token, tokenField = AuthApi.HeaderTokenField } = props ?? {};
76
+ // Check the token
77
+ if (!token) {
78
+ return {
79
+ ok: false,
80
+ type: 'noData',
81
+ field: 'token',
82
+ title: this.app.get('noData')
83
+ };
84
+ }
76
85
  // Reqest data
77
86
  const rq = {
78
87
  deviceId: this.app.deviceId
@@ -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';
@@ -576,7 +576,7 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
576
576
  * @param props Props
577
577
  * @param callback Callback
578
578
  */
579
- refreshToken(props: RefreshTokenProps, callback?: (result?: boolean | IActionResult) => boolean | void): Promise<void>;
579
+ refreshToken(props?: RefreshTokenProps, callback?: (result?: boolean | IActionResult) => boolean | void): Promise<void>;
580
580
  /**
581
581
  * Setup callback
582
582
  */
@@ -618,7 +618,7 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
618
618
  signout(): Promise<void>;
619
619
  /**
620
620
  * Go to the login page
621
- * params Login parameters
621
+ * @params Login parameters
622
622
  */
623
623
  toLoginPage(params?: AppLoginParams): void;
624
624
  /**
@@ -626,7 +626,7 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
626
626
  * UI get involved while refreshToken not intended
627
627
  * @param params Login parameters
628
628
  */
629
- tryLogin(params?: AppLoginParams): Promise<void>;
629
+ tryLogin(params?: AppTryLoginParams): Promise<boolean>;
630
630
  /**
631
631
  * Update embedded status
632
632
  * @param embedded New embedded status
@@ -1354,6 +1354,9 @@ export class CoreApp {
1354
1354
  * @param callback Callback
1355
1355
  */
1356
1356
  async refreshToken(props, callback) {
1357
+ // Check props
1358
+ props ?? (props = {});
1359
+ props.token ?? (props.token = this.getCacheToken());
1357
1360
  // Call refresh token API
1358
1361
  let data = await new AuthApi(this).refreshToken(props);
1359
1362
  let r;
@@ -1589,7 +1592,7 @@ export class CoreApp {
1589
1592
  }
1590
1593
  /**
1591
1594
  * Go to the login page
1592
- * params Login parameters
1595
+ * @params Login parameters
1593
1596
  */
1594
1597
  toLoginPage(params) {
1595
1598
  // Destruct
@@ -1608,9 +1611,9 @@ export class CoreApp {
1608
1611
  async tryLogin(params) {
1609
1612
  // Check status
1610
1613
  if (this._isTryingLogin)
1611
- return;
1614
+ return false;
1612
1615
  this._isTryingLogin = true;
1613
- this.toLoginPage(params);
1616
+ return true;
1614
1617
  }
1615
1618
  /**
1616
1619
  * 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
  */
@@ -64,9 +77,9 @@ export interface RefreshTokenProps {
64
77
  /**
65
78
  * Refresh token
66
79
  */
67
- token: string;
80
+ token?: string;
68
81
  /**
69
- * API name
82
+ * API URL
70
83
  */
71
84
  api?: string;
72
85
  /**
@@ -524,7 +537,7 @@ export interface IApp {
524
537
  * @param callback Callback
525
538
  * @param api API
526
539
  */
527
- refreshToken(props: RefreshTokenProps, callback?: (result?: boolean | IActionResult) => boolean | void): Promise<void>;
540
+ refreshToken(props?: RefreshTokenProps, callback?: (result?: boolean | IActionResult) => boolean | void): Promise<void>;
528
541
  /**
529
542
  * Setup Api error handler
530
543
  * @param api Api
@@ -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
@@ -70,6 +70,15 @@ export class AuthApi extends BaseApi {
70
70
  async refreshToken(props) {
71
71
  // Destruct
72
72
  const { api = 'Auth/RefreshToken', showLoading = false, token, tokenField = AuthApi.HeaderTokenField } = props ?? {};
73
+ // Check the token
74
+ if (!token) {
75
+ return {
76
+ ok: false,
77
+ type: 'noData',
78
+ field: 'token',
79
+ title: this.app.get('noData')
80
+ };
81
+ }
73
82
  // Reqest data
74
83
  const rq = {
75
84
  deviceId: this.app.deviceId
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/appscript",
3
- "version": "1.5.46",
3
+ "version": "1.5.48",
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,
@@ -1888,9 +1889,13 @@ export abstract class CoreApp<
1888
1889
  * @param callback Callback
1889
1890
  */
1890
1891
  async refreshToken(
1891
- props: RefreshTokenProps,
1892
+ props?: RefreshTokenProps,
1892
1893
  callback?: (result?: boolean | IActionResult) => boolean | void
1893
1894
  ) {
1895
+ // Check props
1896
+ props ??= {};
1897
+ props.token ??= this.getCacheToken();
1898
+
1894
1899
  // Call refresh token API
1895
1900
  let data = await new AuthApi(this).refreshToken<IActionResult<U>>(
1896
1901
  props
@@ -2175,7 +2180,7 @@ export abstract class CoreApp<
2175
2180
 
2176
2181
  /**
2177
2182
  * Go to the login page
2178
- * params Login parameters
2183
+ * @params Login parameters
2179
2184
  */
2180
2185
  toLoginPage(params?: AppLoginParams) {
2181
2186
  // Destruct
@@ -2195,12 +2200,12 @@ export abstract class CoreApp<
2195
2200
  * UI get involved while refreshToken not intended
2196
2201
  * @param params Login parameters
2197
2202
  */
2198
- async tryLogin(params?: AppLoginParams) {
2203
+ async tryLogin(params?: AppTryLoginParams) {
2199
2204
  // Check status
2200
- if (this._isTryingLogin) return;
2205
+ if (this._isTryingLogin) return false;
2201
2206
  this._isTryingLogin = true;
2202
2207
 
2203
- this.toLoginPage(params);
2208
+ return true;
2204
2209
  }
2205
2210
 
2206
2211
  /**
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
  */
@@ -90,10 +105,10 @@ export interface RefreshTokenProps {
90
105
  /**
91
106
  * Refresh token
92
107
  */
93
- token: string;
108
+ token?: string;
94
109
 
95
110
  /**
96
- * API name
111
+ * API URL
97
112
  */
98
113
  api?: string;
99
114
 
@@ -706,7 +721,7 @@ export interface IApp {
706
721
  * @param api API
707
722
  */
708
723
  refreshToken(
709
- props: RefreshTokenProps,
724
+ props?: RefreshTokenProps,
710
725
  callback?: (result?: boolean | IActionResult) => boolean | void
711
726
  ): Promise<void>;
712
727
 
@@ -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
@@ -106,6 +106,16 @@ export class AuthApi extends BaseApi {
106
106
  tokenField = AuthApi.HeaderTokenField
107
107
  } = props ?? {};
108
108
 
109
+ // Check the token
110
+ if (!token) {
111
+ return {
112
+ ok: false,
113
+ type: 'noData',
114
+ field: 'token',
115
+ title: this.app.get('noData')
116
+ };
117
+ }
118
+
109
119
  // Reqest data
110
120
  const rq: RefreshTokenRQ = {
111
121
  deviceId: this.app.deviceId