@etsoo/appscript 1.5.44 → 1.5.45

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, RefreshTokenResult } from './IApp';
10
+ import { AppLoginParams, 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';
@@ -426,12 +426,6 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
426
426
  * @param givenName Given name
427
427
  */
428
428
  formatFullName(familyName: string | undefined | null, givenName: string | undefined | null): string;
429
- /**
430
- * Format refresh token result
431
- * @param result Refresh token result
432
- * @returns Message
433
- */
434
- protected formatRefreshTokenResult(result: RefreshTokenResult<IActionResult<U>>): string | undefined;
435
429
  private getFieldLabel;
436
430
  /**
437
431
  * Format result text
@@ -583,7 +577,7 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
583
577
  * @param props Props
584
578
  * @param callback Callback
585
579
  */
586
- refreshToken(props?: RefreshTokenProps, callback?: (result?: boolean | string) => boolean | void): Promise<void>;
580
+ refreshToken(props?: RefreshTokenProps, callback?: (result?: boolean | IActionResult) => boolean | void): Promise<void>;
587
581
  /**
588
582
  * Setup callback
589
583
  */
@@ -1024,28 +1024,6 @@ class CoreApp {
1024
1024
  }
1025
1025
  return wf;
1026
1026
  }
1027
- /**
1028
- * Format refresh token result
1029
- * @param result Refresh token result
1030
- * @returns Message
1031
- */
1032
- formatRefreshTokenResult(result) {
1033
- // Error message
1034
- if (typeof result === 'string')
1035
- return result;
1036
- // API error
1037
- if (result instanceof restclient_1.ApiDataError)
1038
- return this.formatError(result);
1039
- // Action result
1040
- const [token, r] = result;
1041
- // Success
1042
- if (r.ok)
1043
- return undefined;
1044
- // No token data
1045
- if (token == null)
1046
- return `${this.get('noData')} (token)`;
1047
- return ActionResultError_1.ActionResultError.format(r);
1048
- }
1049
1027
  getFieldLabel(field) {
1050
1028
  return this.get(field.formatInitial(false)) ?? field;
1051
1029
  }
@@ -27,7 +27,7 @@ export interface NavigateOptions {
27
27
  * array means success, false means failed but no any message
28
28
  * other cases means failed with differnet message
29
29
  */
30
- export type RefreshTokenResult<R> = string | ApiDataError | [string | null, R];
30
+ export type RefreshTokenResult<R> = IActionResult | [string, R];
31
31
  /**
32
32
  * Format result custom type
33
33
  */
@@ -519,7 +519,7 @@ export interface IApp {
519
519
  * @param props Props
520
520
  * @param callback Callback
521
521
  */
522
- refreshToken(props?: RefreshTokenProps, callback?: (result?: boolean | string) => boolean | void): Promise<void>;
522
+ refreshToken(props?: RefreshTokenProps, callback?: (result?: boolean | IActionResult) => boolean | void): Promise<void>;
523
523
  /**
524
524
  * Setup Api error handler
525
525
  * @param api Api
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AuthApi = void 0;
4
4
  const BaseApi_1 = require("./BaseApi");
5
+ const shared_1 = require("@etsoo/shared");
5
6
  /**
6
7
  * Authentication API
7
8
  */
@@ -90,10 +91,26 @@ class AuthApi extends BaseApi_1.BaseApi {
90
91
  // Call API
91
92
  const result = await this.api.put(api, rq, payload);
92
93
  if (result == null) {
93
- return this.api.lastError ?? this.app.get('unknownError');
94
+ return this.api.lastError
95
+ ? shared_1.ActionResult.create(this.api.lastError)
96
+ : {
97
+ ok: false,
98
+ type: 'unknownError',
99
+ field: 'result',
100
+ title: this.app.get('unknownError')
101
+ };
94
102
  }
95
103
  // Token
96
104
  const refreshToken = this.app.getResponseToken(payload.response, tokenField);
105
+ if (!refreshToken) {
106
+ // No refresh token
107
+ return {
108
+ ok: false,
109
+ type: 'noData',
110
+ field: 'token',
111
+ title: this.app.get('noData')
112
+ };
113
+ }
97
114
  // Success
98
115
  return [refreshToken, result];
99
116
  }
@@ -75,7 +75,7 @@ export * from './i18n/CultureUtils';
75
75
  export * from './i18n/en';
76
76
  export * from './i18n/zhHans';
77
77
  export * from './i18n/zhHant';
78
- export { ApiAuthorizationScheme, ApiMethod, ApiResponseType, createClient, createClientAsync } from '@etsoo/restclient';
78
+ export { ApiAuthorizationScheme, ApiDataError, ApiMethod, ApiResponseType, createClient, createClientAsync } from '@etsoo/restclient';
79
79
  export type { IApi, IApiPayload } from '@etsoo/restclient';
80
80
  export * from './result/ActionResult';
81
81
  export * from './result/ActionResultError';
package/lib/cjs/index.js CHANGED
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.createClientAsync = exports.createClient = exports.ApiResponseType = exports.ApiMethod = exports.ApiAuthorizationScheme = void 0;
17
+ exports.createClientAsync = exports.createClient = exports.ApiResponseType = exports.ApiMethod = exports.ApiDataError = exports.ApiAuthorizationScheme = void 0;
18
18
  // address
19
19
  __exportStar(require("./address/AddressAutocomplete"), exports);
20
20
  __exportStar(require("./address/AddressCity"), exports);
@@ -105,6 +105,7 @@ __exportStar(require("./i18n/zhHant"), exports);
105
105
  // @etsoo/restclient
106
106
  var restclient_1 = require("@etsoo/restclient");
107
107
  Object.defineProperty(exports, "ApiAuthorizationScheme", { enumerable: true, get: function () { return restclient_1.ApiAuthorizationScheme; } });
108
+ Object.defineProperty(exports, "ApiDataError", { enumerable: true, get: function () { return restclient_1.ApiDataError; } });
108
109
  Object.defineProperty(exports, "ApiMethod", { enumerable: true, get: function () { return restclient_1.ApiMethod; } });
109
110
  Object.defineProperty(exports, "ApiResponseType", { enumerable: true, get: function () { return restclient_1.ApiResponseType; } });
110
111
  Object.defineProperty(exports, "createClient", { enumerable: true, get: function () { return restclient_1.createClient; } });
@@ -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, RefreshTokenResult } from './IApp';
10
+ import { AppLoginParams, 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';
@@ -426,12 +426,6 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
426
426
  * @param givenName Given name
427
427
  */
428
428
  formatFullName(familyName: string | undefined | null, givenName: string | undefined | null): string;
429
- /**
430
- * Format refresh token result
431
- * @param result Refresh token result
432
- * @returns Message
433
- */
434
- protected formatRefreshTokenResult(result: RefreshTokenResult<IActionResult<U>>): string | undefined;
435
429
  private getFieldLabel;
436
430
  /**
437
431
  * Format result text
@@ -583,7 +577,7 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
583
577
  * @param props Props
584
578
  * @param callback Callback
585
579
  */
586
- refreshToken(props?: RefreshTokenProps, callback?: (result?: boolean | string) => boolean | void): Promise<void>;
580
+ refreshToken(props?: RefreshTokenProps, callback?: (result?: boolean | IActionResult) => boolean | void): Promise<void>;
587
581
  /**
588
582
  * Setup callback
589
583
  */
@@ -1,5 +1,5 @@
1
1
  import { NotificationAlign, NotificationMessageType } from '@etsoo/notificationbase';
2
- import { ApiDataError, createClient } from '@etsoo/restclient';
2
+ import { createClient } from '@etsoo/restclient';
3
3
  import { DataTypes, DateUtils, DomUtils, ExtendUtils, NumberUtils, Utils } from '@etsoo/shared';
4
4
  import { AddressRegion } from '../address/AddressRegion';
5
5
  import { BridgeUtils } from '../bridges/BridgeUtils';
@@ -1021,28 +1021,6 @@ export class CoreApp {
1021
1021
  }
1022
1022
  return wf;
1023
1023
  }
1024
- /**
1025
- * Format refresh token result
1026
- * @param result Refresh token result
1027
- * @returns Message
1028
- */
1029
- formatRefreshTokenResult(result) {
1030
- // Error message
1031
- if (typeof result === 'string')
1032
- return result;
1033
- // API error
1034
- if (result instanceof ApiDataError)
1035
- return this.formatError(result);
1036
- // Action result
1037
- const [token, r] = result;
1038
- // Success
1039
- if (r.ok)
1040
- return undefined;
1041
- // No token data
1042
- if (token == null)
1043
- return `${this.get('noData')} (token)`;
1044
- return ActionResultError.format(r);
1045
- }
1046
1024
  getFieldLabel(field) {
1047
1025
  return this.get(field.formatInitial(false)) ?? field;
1048
1026
  }
@@ -27,7 +27,7 @@ export interface NavigateOptions {
27
27
  * array means success, false means failed but no any message
28
28
  * other cases means failed with differnet message
29
29
  */
30
- export type RefreshTokenResult<R> = string | ApiDataError | [string | null, R];
30
+ export type RefreshTokenResult<R> = IActionResult | [string, R];
31
31
  /**
32
32
  * Format result custom type
33
33
  */
@@ -519,7 +519,7 @@ export interface IApp {
519
519
  * @param props Props
520
520
  * @param callback Callback
521
521
  */
522
- refreshToken(props?: RefreshTokenProps, callback?: (result?: boolean | string) => boolean | void): Promise<void>;
522
+ refreshToken(props?: RefreshTokenProps, callback?: (result?: boolean | IActionResult) => boolean | void): Promise<void>;
523
523
  /**
524
524
  * Setup Api error handler
525
525
  * @param api Api
@@ -1,4 +1,5 @@
1
1
  import { BaseApi } from './BaseApi';
2
+ import { ActionResult } from '@etsoo/shared';
2
3
  /**
3
4
  * Authentication API
4
5
  */
@@ -87,10 +88,26 @@ export class AuthApi extends BaseApi {
87
88
  // Call API
88
89
  const result = await this.api.put(api, rq, payload);
89
90
  if (result == null) {
90
- return this.api.lastError ?? this.app.get('unknownError');
91
+ return this.api.lastError
92
+ ? ActionResult.create(this.api.lastError)
93
+ : {
94
+ ok: false,
95
+ type: 'unknownError',
96
+ field: 'result',
97
+ title: this.app.get('unknownError')
98
+ };
91
99
  }
92
100
  // Token
93
101
  const refreshToken = this.app.getResponseToken(payload.response, tokenField);
102
+ if (!refreshToken) {
103
+ // No refresh token
104
+ return {
105
+ ok: false,
106
+ type: 'noData',
107
+ field: 'token',
108
+ title: this.app.get('noData')
109
+ };
110
+ }
94
111
  // Success
95
112
  return [refreshToken, result];
96
113
  }
@@ -75,7 +75,7 @@ export * from './i18n/CultureUtils';
75
75
  export * from './i18n/en';
76
76
  export * from './i18n/zhHans';
77
77
  export * from './i18n/zhHant';
78
- export { ApiAuthorizationScheme, ApiMethod, ApiResponseType, createClient, createClientAsync } from '@etsoo/restclient';
78
+ export { ApiAuthorizationScheme, ApiDataError, ApiMethod, ApiResponseType, createClient, createClientAsync } from '@etsoo/restclient';
79
79
  export type { IApi, IApiPayload } from '@etsoo/restclient';
80
80
  export * from './result/ActionResult';
81
81
  export * from './result/ActionResultError';
package/lib/mjs/index.js CHANGED
@@ -86,7 +86,7 @@ export * from './i18n/en';
86
86
  export * from './i18n/zhHans';
87
87
  export * from './i18n/zhHant';
88
88
  // @etsoo/restclient
89
- export { ApiAuthorizationScheme, ApiMethod, ApiResponseType, createClient, createClientAsync } from '@etsoo/restclient';
89
+ export { ApiAuthorizationScheme, ApiDataError, ApiMethod, ApiResponseType, createClient, createClientAsync } from '@etsoo/restclient';
90
90
  // result
91
91
  export * from './result/ActionResult';
92
92
  export * from './result/ActionResultError';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/appscript",
3
- "version": "1.5.44",
3
+ "version": "1.5.45",
4
4
  "description": "Applications shared TypeScript framework",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/mjs/index.js",
@@ -39,8 +39,7 @@ import {
39
39
  IAppFields,
40
40
  IDetectIPCallback,
41
41
  NavigateOptions,
42
- RefreshTokenProps,
43
- RefreshTokenResult
42
+ RefreshTokenProps
44
43
  } from './IApp';
45
44
  import { UserRole } from './UserRole';
46
45
  import type CryptoJS from 'crypto-js';
@@ -1498,32 +1497,6 @@ export abstract class CoreApp<
1498
1497
  return wf;
1499
1498
  }
1500
1499
 
1501
- /**
1502
- * Format refresh token result
1503
- * @param result Refresh token result
1504
- * @returns Message
1505
- */
1506
- protected formatRefreshTokenResult(
1507
- result: RefreshTokenResult<IActionResult<U>>
1508
- ): string | undefined {
1509
- // Error message
1510
- if (typeof result === 'string') return result;
1511
-
1512
- // API error
1513
- if (result instanceof ApiDataError) return this.formatError(result);
1514
-
1515
- // Action result
1516
- const [token, r] = result;
1517
-
1518
- // Success
1519
- if (r.ok) return undefined;
1520
-
1521
- // No token data
1522
- if (token == null) return `${this.get('noData')} (token)`;
1523
-
1524
- return ActionResultError.format(r);
1525
- }
1526
-
1527
1500
  private getFieldLabel(field: string) {
1528
1501
  return this.get(field.formatInitial(false)) ?? field;
1529
1502
  }
@@ -1916,7 +1889,7 @@ export abstract class CoreApp<
1916
1889
  */
1917
1890
  async refreshToken(
1918
1891
  props?: RefreshTokenProps,
1919
- callback?: (result?: boolean | string) => boolean | void
1892
+ callback?: (result?: boolean | IActionResult) => boolean | void
1920
1893
  ) {}
1921
1894
 
1922
1895
  /**
package/src/app/IApp.ts CHANGED
@@ -45,7 +45,7 @@ export interface NavigateOptions {
45
45
  * array means success, false means failed but no any message
46
46
  * other cases means failed with differnet message
47
47
  */
48
- export type RefreshTokenResult<R> = string | ApiDataError | [string | null, R];
48
+ export type RefreshTokenResult<R> = IActionResult | [string, R];
49
49
 
50
50
  /**
51
51
  * Format result custom type
@@ -701,7 +701,7 @@ export interface IApp {
701
701
  */
702
702
  refreshToken(
703
703
  props?: RefreshTokenProps,
704
- callback?: (result?: boolean | string) => boolean | void
704
+ callback?: (result?: boolean | IActionResult) => boolean | void
705
705
  ): Promise<void>;
706
706
 
707
707
  /**
@@ -5,7 +5,7 @@ import { ResultPayload } from './dto/ResultPayload';
5
5
  import { LoginIdRQ } from './rq/LoginIdRQ';
6
6
  import { LoginRQ } from './rq/LoginRQ';
7
7
  import { ResetPasswordRQ } from './rq/ResetPasswordRQ';
8
- import { IActionResult } from '@etsoo/shared';
8
+ import { ActionResult, IActionResult } from '@etsoo/shared';
9
9
  import { SignoutRQ } from './rq/SignoutRQ';
10
10
  import { GetLogInUrlRQ } from './rq/GetLogInUrlRQ';
11
11
  import { TokenRQ } from './rq/TokenRQ';
@@ -125,7 +125,14 @@ export class AuthApi extends BaseApi {
125
125
  // Call API
126
126
  const result = await this.api.put(api, rq, payload);
127
127
  if (result == null) {
128
- return this.api.lastError ?? this.app.get('unknownError')!;
128
+ return this.api.lastError
129
+ ? ActionResult.create(this.api.lastError)
130
+ : {
131
+ ok: false,
132
+ type: 'unknownError',
133
+ field: 'result',
134
+ title: this.app.get('unknownError')
135
+ };
129
136
  }
130
137
 
131
138
  // Token
@@ -134,6 +141,16 @@ export class AuthApi extends BaseApi {
134
141
  tokenField
135
142
  );
136
143
 
144
+ if (!refreshToken) {
145
+ // No refresh token
146
+ return {
147
+ ok: false,
148
+ type: 'noData',
149
+ field: 'token',
150
+ title: this.app.get('noData')
151
+ };
152
+ }
153
+
137
154
  // Success
138
155
  return [refreshToken, result];
139
156
  }
package/src/index.ts CHANGED
@@ -98,6 +98,7 @@ export * from './i18n/zhHant';
98
98
  // @etsoo/restclient
99
99
  export {
100
100
  ApiAuthorizationScheme,
101
+ ApiDataError,
101
102
  ApiMethod,
102
103
  ApiResponseType,
103
104
  createClient,