@etsoo/appscript 1.1.55 → 1.1.59

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.
@@ -22,14 +22,22 @@ export declare type RefreshTokenResult = boolean | string | ApiDataError | IActi
22
22
  * Refresh token props
23
23
  */
24
24
  export interface RefreshTokenProps<D extends {}> {
25
+ /**
26
+ * Callback
27
+ */
28
+ callback?: (result: RefreshTokenResult) => void;
25
29
  /**
26
30
  * Data to pass
27
31
  */
28
32
  data?: D;
29
33
  /**
30
- * Callback
34
+ * Support relogin or not
31
35
  */
32
- callback?: (result: RefreshTokenResult) => void;
36
+ relogin?: boolean;
37
+ /**
38
+ * Show loading bar or not
39
+ */
40
+ showLoading?: boolean;
33
41
  }
34
42
  /**
35
43
  * Core application interface
@@ -118,6 +126,12 @@ export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallP
118
126
  * @returns string
119
127
  */
120
128
  formatDate(input?: Date | string, options?: DateUtils.FormatOptions, timeZone?: string): string | undefined;
129
+ /**
130
+ * Format error
131
+ * @param error Error
132
+ * @returns Error message
133
+ */
134
+ formatError(error: ApiDataError): string;
121
135
  /**
122
136
  * Format money number
123
137
  * @param input Input money number
@@ -133,6 +147,12 @@ export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallP
133
147
  * @returns Result
134
148
  */
135
149
  formatNumber(input?: number | bigint, options?: Intl.NumberFormatOptions): string | undefined;
150
+ /**
151
+ * Format refresh token result
152
+ * @param result Refresh token result
153
+ * @returns Message
154
+ */
155
+ formatRefreshTokenResult(result: RefreshTokenResult): string | undefined;
136
156
  /**
137
157
  * Format result text
138
158
  * @param result Action result
@@ -215,8 +235,10 @@ export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallP
215
235
  transformUrl(url: string): string;
216
236
  /**
217
237
  * Try login, returning false means is loading
238
+ * UI get involved while refreshToken not intended
239
+ * @param data Additional request data
218
240
  */
219
- tryLogin(): Promise<boolean>;
241
+ tryLogin<D extends {} = {}>(data?: D): Promise<boolean>;
220
242
  /**
221
243
  * User login
222
244
  * @param user User data
@@ -377,6 +399,12 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
377
399
  * @returns Error message
378
400
  */
379
401
  formatError(error: ApiDataError): string;
402
+ /**
403
+ * Format refresh token result
404
+ * @param result Refresh token result
405
+ * @returns Message
406
+ */
407
+ formatRefreshTokenResult(result: RefreshTokenResult): string | undefined;
380
408
  /**
381
409
  * Format result text
382
410
  * @param result Action result
@@ -440,7 +468,7 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
440
468
  abstract freshCountdownUI(callback?: () => PromiseLike<unknown>): void;
441
469
  /**
442
470
  * Refresh token
443
- * @param callback Callback
471
+ * @param props Props
444
472
  */
445
473
  refreshToken<D extends {} = {}>(props?: RefreshTokenProps<D>): Promise<boolean>;
446
474
  /**
@@ -470,8 +498,9 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
470
498
  /**
471
499
  * Try login, returning false means is loading
472
500
  * UI get involved while refreshToken not intended
501
+ * @param data Additional request data
473
502
  */
474
- tryLogin(): Promise<boolean>;
503
+ tryLogin<D extends {} = {}>(_data?: D): Promise<boolean>;
475
504
  /**
476
505
  * User login
477
506
  * @param user User data
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CoreApp = void 0;
4
4
  const notificationbase_1 = require("@etsoo/notificationbase");
5
+ const restclient_1 = require("@etsoo/restclient");
5
6
  const shared_1 = require("@etsoo/shared");
6
7
  const AddressRegion_1 = require("../address/AddressRegion");
7
8
  const AddressUtils_1 = require("../address/AddressUtils");
@@ -266,6 +267,21 @@ class CoreApp {
266
267
  formatError(error) {
267
268
  return error.toString();
268
269
  }
270
+ /**
271
+ * Format refresh token result
272
+ * @param result Refresh token result
273
+ * @returns Message
274
+ */
275
+ formatRefreshTokenResult(result) {
276
+ // Undefined for boolean
277
+ if (typeof result === 'boolean')
278
+ return undefined;
279
+ return result instanceof restclient_1.ApiDataError
280
+ ? this.formatError(result)
281
+ : typeof result !== 'string'
282
+ ? ActionResultError_1.ActionResultError.format(result)
283
+ : result;
284
+ }
269
285
  /**
270
286
  * Format result text
271
287
  * @param result Action result
@@ -399,7 +415,7 @@ class CoreApp {
399
415
  }
400
416
  /**
401
417
  * Refresh token
402
- * @param callback Callback
418
+ * @param props Props
403
419
  */
404
420
  async refreshToken(props) {
405
421
  if (props && props.callback)
@@ -471,8 +487,9 @@ class CoreApp {
471
487
  /**
472
488
  * Try login, returning false means is loading
473
489
  * UI get involved while refreshToken not intended
490
+ * @param data Additional request data
474
491
  */
475
- async tryLogin() {
492
+ async tryLogin(_data) {
476
493
  if (this._isTryingLogin)
477
494
  return false;
478
495
  this._isTryingLogin = true;
@@ -22,6 +22,7 @@
22
22
  "failed": "Operation failed",
23
23
  "id": "Number#",
24
24
  "loading": "Loading...",
25
+ "login": "Login",
25
26
  "menuHome": "Home",
26
27
  "message": "Message",
27
28
  "mobile": "Mobile number",
@@ -42,6 +43,7 @@
42
43
  "refresh": "Refresh",
43
44
  "refreshing": "Refreshing",
44
45
  "releaseToRefresh": "Release to refresh",
46
+ "reloginTip": "Please enter your password, resubmit the data after successful login",
45
47
  "remove": "Remove",
46
48
  "renew": "Renew",
47
49
  "resending": "Resending",
@@ -22,6 +22,7 @@
22
22
  "failed": "操作失败",
23
23
  "id": "编号",
24
24
  "loading": "正在加载...",
25
+ "login": "登录",
25
26
  "menuHome": "首页",
26
27
  "message": "留言",
27
28
  "mobile": "手机号码",
@@ -42,6 +43,7 @@
42
43
  "refresh": "刷新",
43
44
  "refreshing": "正在刷新",
44
45
  "releaseToRefresh": "释放刷新",
46
+ "reloginTip": "请输入您的登录密码,登录成功后请重新提交数据",
45
47
  "remove": "移除",
46
48
  "renew": "续费",
47
49
  "resending": "重新发送",
@@ -22,6 +22,7 @@
22
22
  "failed": "操作失敗",
23
23
  "id": "編號",
24
24
  "loading": "正在加載...",
25
+ "login": "登錄",
25
26
  "menuHome": "首頁",
26
27
  "message": "留言",
27
28
  "mobilePhone": "手機號碼",
@@ -42,6 +43,7 @@
42
43
  "refresh": "刷新",
43
44
  "refreshing": "正在刷新",
44
45
  "releaseToRefresh": "釋放刷新",
46
+ "reloginTip": "請輸入您的登錄密碼,登錄成功後請重新提交數據",
45
47
  "remove": "移除",
46
48
  "renew": "續費",
47
49
  "resending": "重新發送",
@@ -22,14 +22,22 @@ export declare type RefreshTokenResult = boolean | string | ApiDataError | IActi
22
22
  * Refresh token props
23
23
  */
24
24
  export interface RefreshTokenProps<D extends {}> {
25
+ /**
26
+ * Callback
27
+ */
28
+ callback?: (result: RefreshTokenResult) => void;
25
29
  /**
26
30
  * Data to pass
27
31
  */
28
32
  data?: D;
29
33
  /**
30
- * Callback
34
+ * Support relogin or not
31
35
  */
32
- callback?: (result: RefreshTokenResult) => void;
36
+ relogin?: boolean;
37
+ /**
38
+ * Show loading bar or not
39
+ */
40
+ showLoading?: boolean;
33
41
  }
34
42
  /**
35
43
  * Core application interface
@@ -118,6 +126,12 @@ export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallP
118
126
  * @returns string
119
127
  */
120
128
  formatDate(input?: Date | string, options?: DateUtils.FormatOptions, timeZone?: string): string | undefined;
129
+ /**
130
+ * Format error
131
+ * @param error Error
132
+ * @returns Error message
133
+ */
134
+ formatError(error: ApiDataError): string;
121
135
  /**
122
136
  * Format money number
123
137
  * @param input Input money number
@@ -133,6 +147,12 @@ export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallP
133
147
  * @returns Result
134
148
  */
135
149
  formatNumber(input?: number | bigint, options?: Intl.NumberFormatOptions): string | undefined;
150
+ /**
151
+ * Format refresh token result
152
+ * @param result Refresh token result
153
+ * @returns Message
154
+ */
155
+ formatRefreshTokenResult(result: RefreshTokenResult): string | undefined;
136
156
  /**
137
157
  * Format result text
138
158
  * @param result Action result
@@ -215,8 +235,10 @@ export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallP
215
235
  transformUrl(url: string): string;
216
236
  /**
217
237
  * Try login, returning false means is loading
238
+ * UI get involved while refreshToken not intended
239
+ * @param data Additional request data
218
240
  */
219
- tryLogin(): Promise<boolean>;
241
+ tryLogin<D extends {} = {}>(data?: D): Promise<boolean>;
220
242
  /**
221
243
  * User login
222
244
  * @param user User data
@@ -377,6 +399,12 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
377
399
  * @returns Error message
378
400
  */
379
401
  formatError(error: ApiDataError): string;
402
+ /**
403
+ * Format refresh token result
404
+ * @param result Refresh token result
405
+ * @returns Message
406
+ */
407
+ formatRefreshTokenResult(result: RefreshTokenResult): string | undefined;
380
408
  /**
381
409
  * Format result text
382
410
  * @param result Action result
@@ -440,7 +468,7 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
440
468
  abstract freshCountdownUI(callback?: () => PromiseLike<unknown>): void;
441
469
  /**
442
470
  * Refresh token
443
- * @param callback Callback
471
+ * @param props Props
444
472
  */
445
473
  refreshToken<D extends {} = {}>(props?: RefreshTokenProps<D>): Promise<boolean>;
446
474
  /**
@@ -470,8 +498,9 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
470
498
  /**
471
499
  * Try login, returning false means is loading
472
500
  * UI get involved while refreshToken not intended
501
+ * @param data Additional request data
473
502
  */
474
- tryLogin(): Promise<boolean>;
503
+ tryLogin<D extends {} = {}>(_data?: D): Promise<boolean>;
475
504
  /**
476
505
  * User login
477
506
  * @param user User data
@@ -1,4 +1,5 @@
1
1
  import { NotificationAlign, NotificationMessageType } from '@etsoo/notificationbase';
2
+ import { ApiDataError } from '@etsoo/restclient';
2
3
  import { DateUtils, DomUtils, NumberUtils, StorageUtils } from '@etsoo/shared';
3
4
  import { AddressRegion } from '../address/AddressRegion';
4
5
  import { AddressUtils } from '../address/AddressUtils';
@@ -263,6 +264,21 @@ export class CoreApp {
263
264
  formatError(error) {
264
265
  return error.toString();
265
266
  }
267
+ /**
268
+ * Format refresh token result
269
+ * @param result Refresh token result
270
+ * @returns Message
271
+ */
272
+ formatRefreshTokenResult(result) {
273
+ // Undefined for boolean
274
+ if (typeof result === 'boolean')
275
+ return undefined;
276
+ return result instanceof ApiDataError
277
+ ? this.formatError(result)
278
+ : typeof result !== 'string'
279
+ ? ActionResultError.format(result)
280
+ : result;
281
+ }
266
282
  /**
267
283
  * Format result text
268
284
  * @param result Action result
@@ -396,7 +412,7 @@ export class CoreApp {
396
412
  }
397
413
  /**
398
414
  * Refresh token
399
- * @param callback Callback
415
+ * @param props Props
400
416
  */
401
417
  async refreshToken(props) {
402
418
  if (props && props.callback)
@@ -468,8 +484,9 @@ export class CoreApp {
468
484
  /**
469
485
  * Try login, returning false means is loading
470
486
  * UI get involved while refreshToken not intended
487
+ * @param data Additional request data
471
488
  */
472
- async tryLogin() {
489
+ async tryLogin(_data) {
473
490
  if (this._isTryingLogin)
474
491
  return false;
475
492
  this._isTryingLogin = true;
@@ -22,6 +22,7 @@
22
22
  "failed": "Operation failed",
23
23
  "id": "Number#",
24
24
  "loading": "Loading...",
25
+ "login": "Login",
25
26
  "menuHome": "Home",
26
27
  "message": "Message",
27
28
  "mobile": "Mobile number",
@@ -42,6 +43,7 @@
42
43
  "refresh": "Refresh",
43
44
  "refreshing": "Refreshing",
44
45
  "releaseToRefresh": "Release to refresh",
46
+ "reloginTip": "Please enter your password, resubmit the data after successful login",
45
47
  "remove": "Remove",
46
48
  "renew": "Renew",
47
49
  "resending": "Resending",
@@ -22,6 +22,7 @@
22
22
  "failed": "操作失败",
23
23
  "id": "编号",
24
24
  "loading": "正在加载...",
25
+ "login": "登录",
25
26
  "menuHome": "首页",
26
27
  "message": "留言",
27
28
  "mobile": "手机号码",
@@ -42,6 +43,7 @@
42
43
  "refresh": "刷新",
43
44
  "refreshing": "正在刷新",
44
45
  "releaseToRefresh": "释放刷新",
46
+ "reloginTip": "请输入您的登录密码,登录成功后请重新提交数据",
45
47
  "remove": "移除",
46
48
  "renew": "续费",
47
49
  "resending": "重新发送",
@@ -22,6 +22,7 @@
22
22
  "failed": "操作失敗",
23
23
  "id": "編號",
24
24
  "loading": "正在加載...",
25
+ "login": "登錄",
25
26
  "menuHome": "首頁",
26
27
  "message": "留言",
27
28
  "mobilePhone": "手機號碼",
@@ -42,6 +43,7 @@
42
43
  "refresh": "刷新",
43
44
  "refreshing": "正在刷新",
44
45
  "releaseToRefresh": "釋放刷新",
46
+ "reloginTip": "請輸入您的登錄密碼,登錄成功後請重新提交數據",
45
47
  "remove": "移除",
46
48
  "renew": "續費",
47
49
  "resending": "重新發送",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/appscript",
3
- "version": "1.1.55",
3
+ "version": "1.1.59",
4
4
  "description": "Applications shared TypeScript framework",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/mjs/index.js",
@@ -44,15 +44,25 @@ export type RefreshTokenResult =
44
44
  * Refresh token props
45
45
  */
46
46
  export interface RefreshTokenProps<D extends {}> {
47
+ /**
48
+ * Callback
49
+ */
50
+ callback?: (result: RefreshTokenResult) => void;
51
+
47
52
  /**
48
53
  * Data to pass
49
54
  */
50
55
  data?: D;
51
56
 
52
57
  /**
53
- * Callback
58
+ * Support relogin or not
54
59
  */
55
- callback?: (result: RefreshTokenResult) => void;
60
+ relogin?: boolean;
61
+
62
+ /**
63
+ * Show loading bar or not
64
+ */
65
+ showLoading?: boolean;
56
66
  }
57
67
 
58
68
  /**
@@ -168,6 +178,13 @@ export interface ICoreApp<
168
178
  timeZone?: string
169
179
  ): string | undefined;
170
180
 
181
+ /**
182
+ * Format error
183
+ * @param error Error
184
+ * @returns Error message
185
+ */
186
+ formatError(error: ApiDataError): string;
187
+
171
188
  /**
172
189
  * Format money number
173
190
  * @param input Input money number
@@ -192,6 +209,13 @@ export interface ICoreApp<
192
209
  options?: Intl.NumberFormatOptions
193
210
  ): string | undefined;
194
211
 
212
+ /**
213
+ * Format refresh token result
214
+ * @param result Refresh token result
215
+ * @returns Message
216
+ */
217
+ formatRefreshTokenResult(result: RefreshTokenResult): string | undefined;
218
+
195
219
  /**
196
220
  * Format result text
197
221
  * @param result Action result
@@ -289,8 +313,10 @@ export interface ICoreApp<
289
313
 
290
314
  /**
291
315
  * Try login, returning false means is loading
316
+ * UI get involved while refreshToken not intended
317
+ * @param data Additional request data
292
318
  */
293
- tryLogin(): Promise<boolean>;
319
+ tryLogin<D extends {} = {}>(data?: D): Promise<boolean>;
294
320
 
295
321
  /**
296
322
  * User login
@@ -696,6 +722,22 @@ export abstract class CoreApp<
696
722
  return error.toString();
697
723
  }
698
724
 
725
+ /**
726
+ * Format refresh token result
727
+ * @param result Refresh token result
728
+ * @returns Message
729
+ */
730
+ formatRefreshTokenResult(result: RefreshTokenResult) {
731
+ // Undefined for boolean
732
+ if (typeof result === 'boolean') return undefined;
733
+
734
+ return result instanceof ApiDataError
735
+ ? this.formatError(result)
736
+ : typeof result !== 'string'
737
+ ? ActionResultError.format(result)
738
+ : result;
739
+ }
740
+
699
741
  /**
700
742
  * Format result text
701
743
  * @param result Action result
@@ -852,7 +894,7 @@ export abstract class CoreApp<
852
894
 
853
895
  /**
854
896
  * Refresh token
855
- * @param callback Callback
897
+ * @param props Props
856
898
  */
857
899
  async refreshToken<D extends {} = {}>(props?: RefreshTokenProps<D>) {
858
900
  if (props && props.callback) props.callback(true);
@@ -933,8 +975,9 @@ export abstract class CoreApp<
933
975
  /**
934
976
  * Try login, returning false means is loading
935
977
  * UI get involved while refreshToken not intended
978
+ * @param data Additional request data
936
979
  */
937
- async tryLogin() {
980
+ async tryLogin<D extends {} = {}>(_data?: D) {
938
981
  if (this._isTryingLogin) return false;
939
982
  this._isTryingLogin = true;
940
983
  return true;
@@ -22,6 +22,7 @@
22
22
  "failed": "Operation failed",
23
23
  "id": "Number#",
24
24
  "loading": "Loading...",
25
+ "login": "Login",
25
26
  "menuHome": "Home",
26
27
  "message": "Message",
27
28
  "mobile": "Mobile number",
@@ -42,6 +43,7 @@
42
43
  "refresh": "Refresh",
43
44
  "refreshing": "Refreshing",
44
45
  "releaseToRefresh": "Release to refresh",
46
+ "reloginTip": "Please enter your password, resubmit the data after successful login",
45
47
  "remove": "Remove",
46
48
  "renew": "Renew",
47
49
  "resending": "Resending",
@@ -22,6 +22,7 @@
22
22
  "failed": "操作失败",
23
23
  "id": "编号",
24
24
  "loading": "正在加载...",
25
+ "login": "登录",
25
26
  "menuHome": "首页",
26
27
  "message": "留言",
27
28
  "mobile": "手机号码",
@@ -42,6 +43,7 @@
42
43
  "refresh": "刷新",
43
44
  "refreshing": "正在刷新",
44
45
  "releaseToRefresh": "释放刷新",
46
+ "reloginTip": "请输入您的登录密码,登录成功后请重新提交数据",
45
47
  "remove": "移除",
46
48
  "renew": "续费",
47
49
  "resending": "重新发送",
@@ -22,6 +22,7 @@
22
22
  "failed": "操作失敗",
23
23
  "id": "編號",
24
24
  "loading": "正在加載...",
25
+ "login": "登錄",
25
26
  "menuHome": "首頁",
26
27
  "message": "留言",
27
28
  "mobilePhone": "手機號碼",
@@ -42,6 +43,7 @@
42
43
  "refresh": "刷新",
43
44
  "refreshing": "正在刷新",
44
45
  "releaseToRefresh": "釋放刷新",
46
+ "reloginTip": "請輸入您的登錄密碼,登錄成功後請重新提交數據",
45
47
  "remove": "移除",
46
48
  "renew": "續費",
47
49
  "resending": "重新發送",