@etsoo/appscript 1.1.56 → 1.1.60

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.
@@ -30,6 +30,10 @@ export interface RefreshTokenProps<D extends {}> {
30
30
  * Data to pass
31
31
  */
32
32
  data?: D;
33
+ /**
34
+ * Support relogin or not
35
+ */
36
+ relogin?: boolean;
33
37
  /**
34
38
  * Show loading bar or not
35
39
  */
@@ -109,11 +113,25 @@ export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallP
109
113
  * @param culture New culture definition
110
114
  */
111
115
  changeCulture(culture: DataTypes.CultureDefinition): void;
116
+ /**
117
+ * Decrypt message
118
+ * @param messageEncrypted Encrypted message
119
+ * @param passphrase Secret passphrase
120
+ * @returns Pure text
121
+ */
122
+ decrypt(messageEncrypted: string, passphrase: string): string;
112
123
  /**
113
124
  * Detect IP data, call only one time
114
125
  * @param callback Callback will be called when the IP is ready
115
126
  */
116
127
  detectIP(callback?: IDetectIPCallback): void;
128
+ /**
129
+ * Encrypt message
130
+ * @param message Message
131
+ * @param passphrase Secret passphrase
132
+ * @returns Result
133
+ */
134
+ encrypt(message: string, passphrase: string): string;
117
135
  /**
118
136
  * Format date to string
119
137
  * @param input Input date
@@ -122,6 +140,12 @@ export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallP
122
140
  * @returns string
123
141
  */
124
142
  formatDate(input?: Date | string, options?: DateUtils.FormatOptions, timeZone?: string): string | undefined;
143
+ /**
144
+ * Format error
145
+ * @param error Error
146
+ * @returns Error message
147
+ */
148
+ formatError(error: ApiDataError): string;
125
149
  /**
126
150
  * Format money number
127
151
  * @param input Input money number
@@ -137,6 +161,12 @@ export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallP
137
161
  * @returns Result
138
162
  */
139
163
  formatNumber(input?: number | bigint, options?: Intl.NumberFormatOptions): string | undefined;
164
+ /**
165
+ * Format refresh token result
166
+ * @param result Refresh token result
167
+ * @returns Message
168
+ */
169
+ formatRefreshTokenResult(result: RefreshTokenResult): string | undefined;
140
170
  /**
141
171
  * Format result text
142
172
  * @param result Action result
@@ -219,8 +249,10 @@ export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallP
219
249
  transformUrl(url: string): string;
220
250
  /**
221
251
  * Try login, returning false means is loading
252
+ * UI get involved while refreshToken not intended
253
+ * @param data Additional request data
222
254
  */
223
- tryLogin(): Promise<boolean>;
255
+ tryLogin<D extends {} = {}>(data?: D): Promise<boolean>;
224
256
  /**
225
257
  * User login
226
258
  * @param user User data
@@ -346,12 +378,32 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
346
378
  * @param culture New culture definition
347
379
  */
348
380
  changeCulture(culture: DataTypes.CultureDefinition): void;
381
+ /**
382
+ * Decrypt message
383
+ * @param messageEncrypted Encrypted message
384
+ * @param passphrase Secret passphrase
385
+ * @returns Pure text
386
+ */
387
+ decrypt(messageEncrypted: string, passphrase: string): string;
349
388
  /**
350
389
  * Detect IP data, call only one time
351
390
  * @param callback Callback will be called when the IP is ready
352
391
  */
353
392
  detectIP(callback?: IDetectIPCallback): void;
354
393
  private detectIPCallbacks;
394
+ /**
395
+ * Encrypt message
396
+ * @param message Message
397
+ * @param passphrase Secret passphrase
398
+ * @returns Result
399
+ */
400
+ encrypt(message: string, passphrase: string): string;
401
+ /**
402
+ * Enchance secret passphrase
403
+ * @param passphrase Secret passphrase
404
+ * @returns Enhanced passphrase
405
+ */
406
+ protected encryptionEnhance(passphrase: string): string;
355
407
  /**
356
408
  * Format date to string
357
409
  * @param input Input date
@@ -381,6 +433,12 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
381
433
  * @returns Error message
382
434
  */
383
435
  formatError(error: ApiDataError): string;
436
+ /**
437
+ * Format refresh token result
438
+ * @param result Refresh token result
439
+ * @returns Message
440
+ */
441
+ formatRefreshTokenResult(result: RefreshTokenResult): string | undefined;
384
442
  /**
385
443
  * Format result text
386
444
  * @param result Action result
@@ -444,7 +502,7 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
444
502
  abstract freshCountdownUI(callback?: () => PromiseLike<unknown>): void;
445
503
  /**
446
504
  * Refresh token
447
- * @param callback Callback
505
+ * @param props Props
448
506
  */
449
507
  refreshToken<D extends {} = {}>(props?: RefreshTokenProps<D>): Promise<boolean>;
450
508
  /**
@@ -474,8 +532,9 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
474
532
  /**
475
533
  * Try login, returning false means is loading
476
534
  * UI get involved while refreshToken not intended
535
+ * @param data Additional request data
477
536
  */
478
- tryLogin(): Promise<boolean>;
537
+ tryLogin<D extends {} = {}>(_data?: D): Promise<boolean>;
479
538
  /**
480
539
  * User login
481
540
  * @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");
@@ -194,6 +195,15 @@ class CoreApp {
194
195
  region.name = AddressUtils_1.AddressUtils.getRegionLabel(id, this.labelDelegate);
195
196
  });
196
197
  }
198
+ /**
199
+ * Decrypt message
200
+ * @param messageEncrypted Encrypted message
201
+ * @param passphrase Secret passphrase
202
+ * @returns Pure text
203
+ */
204
+ decrypt(messageEncrypted, passphrase) {
205
+ return CryptoJS.AES.decrypt(messageEncrypted, this.encryptionEnhance(passphrase)).toString();
206
+ }
197
207
  /**
198
208
  * Detect IP data, call only one time
199
209
  * @param callback Callback will be called when the IP is ready
@@ -227,6 +237,23 @@ class CoreApp {
227
237
  var _a;
228
238
  (_a = this.ipDetectCallbacks) === null || _a === void 0 ? void 0 : _a.forEach((f) => f());
229
239
  }
240
+ /**
241
+ * Encrypt message
242
+ * @param message Message
243
+ * @param passphrase Secret passphrase
244
+ * @returns Result
245
+ */
246
+ encrypt(message, passphrase) {
247
+ return CryptoJS.AES.encrypt(message, this.encryptionEnhance(passphrase)).toString();
248
+ }
249
+ /**
250
+ * Enchance secret passphrase
251
+ * @param passphrase Secret passphrase
252
+ * @returns Enhanced passphrase
253
+ */
254
+ encryptionEnhance(passphrase) {
255
+ return passphrase;
256
+ }
230
257
  /**
231
258
  * Format date to string
232
259
  * @param input Input date
@@ -266,6 +293,21 @@ class CoreApp {
266
293
  formatError(error) {
267
294
  return error.toString();
268
295
  }
296
+ /**
297
+ * Format refresh token result
298
+ * @param result Refresh token result
299
+ * @returns Message
300
+ */
301
+ formatRefreshTokenResult(result) {
302
+ // Undefined for boolean
303
+ if (typeof result === 'boolean')
304
+ return undefined;
305
+ return result instanceof restclient_1.ApiDataError
306
+ ? this.formatError(result)
307
+ : typeof result !== 'string'
308
+ ? ActionResultError_1.ActionResultError.format(result)
309
+ : result;
310
+ }
269
311
  /**
270
312
  * Format result text
271
313
  * @param result Action result
@@ -399,7 +441,7 @@ class CoreApp {
399
441
  }
400
442
  /**
401
443
  * Refresh token
402
- * @param callback Callback
444
+ * @param props Props
403
445
  */
404
446
  async refreshToken(props) {
405
447
  if (props && props.callback)
@@ -471,8 +513,9 @@ class CoreApp {
471
513
  /**
472
514
  * Try login, returning false means is loading
473
515
  * UI get involved while refreshToken not intended
516
+ * @param data Additional request data
474
517
  */
475
- async tryLogin() {
518
+ async tryLogin(_data) {
476
519
  if (this._isTryingLogin)
477
520
  return false;
478
521
  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": "重新發送",
@@ -30,6 +30,10 @@ export interface RefreshTokenProps<D extends {}> {
30
30
  * Data to pass
31
31
  */
32
32
  data?: D;
33
+ /**
34
+ * Support relogin or not
35
+ */
36
+ relogin?: boolean;
33
37
  /**
34
38
  * Show loading bar or not
35
39
  */
@@ -109,11 +113,25 @@ export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallP
109
113
  * @param culture New culture definition
110
114
  */
111
115
  changeCulture(culture: DataTypes.CultureDefinition): void;
116
+ /**
117
+ * Decrypt message
118
+ * @param messageEncrypted Encrypted message
119
+ * @param passphrase Secret passphrase
120
+ * @returns Pure text
121
+ */
122
+ decrypt(messageEncrypted: string, passphrase: string): string;
112
123
  /**
113
124
  * Detect IP data, call only one time
114
125
  * @param callback Callback will be called when the IP is ready
115
126
  */
116
127
  detectIP(callback?: IDetectIPCallback): void;
128
+ /**
129
+ * Encrypt message
130
+ * @param message Message
131
+ * @param passphrase Secret passphrase
132
+ * @returns Result
133
+ */
134
+ encrypt(message: string, passphrase: string): string;
117
135
  /**
118
136
  * Format date to string
119
137
  * @param input Input date
@@ -122,6 +140,12 @@ export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallP
122
140
  * @returns string
123
141
  */
124
142
  formatDate(input?: Date | string, options?: DateUtils.FormatOptions, timeZone?: string): string | undefined;
143
+ /**
144
+ * Format error
145
+ * @param error Error
146
+ * @returns Error message
147
+ */
148
+ formatError(error: ApiDataError): string;
125
149
  /**
126
150
  * Format money number
127
151
  * @param input Input money number
@@ -137,6 +161,12 @@ export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallP
137
161
  * @returns Result
138
162
  */
139
163
  formatNumber(input?: number | bigint, options?: Intl.NumberFormatOptions): string | undefined;
164
+ /**
165
+ * Format refresh token result
166
+ * @param result Refresh token result
167
+ * @returns Message
168
+ */
169
+ formatRefreshTokenResult(result: RefreshTokenResult): string | undefined;
140
170
  /**
141
171
  * Format result text
142
172
  * @param result Action result
@@ -219,8 +249,10 @@ export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallP
219
249
  transformUrl(url: string): string;
220
250
  /**
221
251
  * Try login, returning false means is loading
252
+ * UI get involved while refreshToken not intended
253
+ * @param data Additional request data
222
254
  */
223
- tryLogin(): Promise<boolean>;
255
+ tryLogin<D extends {} = {}>(data?: D): Promise<boolean>;
224
256
  /**
225
257
  * User login
226
258
  * @param user User data
@@ -346,12 +378,32 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
346
378
  * @param culture New culture definition
347
379
  */
348
380
  changeCulture(culture: DataTypes.CultureDefinition): void;
381
+ /**
382
+ * Decrypt message
383
+ * @param messageEncrypted Encrypted message
384
+ * @param passphrase Secret passphrase
385
+ * @returns Pure text
386
+ */
387
+ decrypt(messageEncrypted: string, passphrase: string): string;
349
388
  /**
350
389
  * Detect IP data, call only one time
351
390
  * @param callback Callback will be called when the IP is ready
352
391
  */
353
392
  detectIP(callback?: IDetectIPCallback): void;
354
393
  private detectIPCallbacks;
394
+ /**
395
+ * Encrypt message
396
+ * @param message Message
397
+ * @param passphrase Secret passphrase
398
+ * @returns Result
399
+ */
400
+ encrypt(message: string, passphrase: string): string;
401
+ /**
402
+ * Enchance secret passphrase
403
+ * @param passphrase Secret passphrase
404
+ * @returns Enhanced passphrase
405
+ */
406
+ protected encryptionEnhance(passphrase: string): string;
355
407
  /**
356
408
  * Format date to string
357
409
  * @param input Input date
@@ -381,6 +433,12 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
381
433
  * @returns Error message
382
434
  */
383
435
  formatError(error: ApiDataError): string;
436
+ /**
437
+ * Format refresh token result
438
+ * @param result Refresh token result
439
+ * @returns Message
440
+ */
441
+ formatRefreshTokenResult(result: RefreshTokenResult): string | undefined;
384
442
  /**
385
443
  * Format result text
386
444
  * @param result Action result
@@ -444,7 +502,7 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
444
502
  abstract freshCountdownUI(callback?: () => PromiseLike<unknown>): void;
445
503
  /**
446
504
  * Refresh token
447
- * @param callback Callback
505
+ * @param props Props
448
506
  */
449
507
  refreshToken<D extends {} = {}>(props?: RefreshTokenProps<D>): Promise<boolean>;
450
508
  /**
@@ -474,8 +532,9 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
474
532
  /**
475
533
  * Try login, returning false means is loading
476
534
  * UI get involved while refreshToken not intended
535
+ * @param data Additional request data
477
536
  */
478
- tryLogin(): Promise<boolean>;
537
+ tryLogin<D extends {} = {}>(_data?: D): Promise<boolean>;
479
538
  /**
480
539
  * User login
481
540
  * @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';
@@ -191,6 +192,15 @@ export class CoreApp {
191
192
  region.name = AddressUtils.getRegionLabel(id, this.labelDelegate);
192
193
  });
193
194
  }
195
+ /**
196
+ * Decrypt message
197
+ * @param messageEncrypted Encrypted message
198
+ * @param passphrase Secret passphrase
199
+ * @returns Pure text
200
+ */
201
+ decrypt(messageEncrypted, passphrase) {
202
+ return CryptoJS.AES.decrypt(messageEncrypted, this.encryptionEnhance(passphrase)).toString();
203
+ }
194
204
  /**
195
205
  * Detect IP data, call only one time
196
206
  * @param callback Callback will be called when the IP is ready
@@ -224,6 +234,23 @@ export class CoreApp {
224
234
  var _a;
225
235
  (_a = this.ipDetectCallbacks) === null || _a === void 0 ? void 0 : _a.forEach((f) => f());
226
236
  }
237
+ /**
238
+ * Encrypt message
239
+ * @param message Message
240
+ * @param passphrase Secret passphrase
241
+ * @returns Result
242
+ */
243
+ encrypt(message, passphrase) {
244
+ return CryptoJS.AES.encrypt(message, this.encryptionEnhance(passphrase)).toString();
245
+ }
246
+ /**
247
+ * Enchance secret passphrase
248
+ * @param passphrase Secret passphrase
249
+ * @returns Enhanced passphrase
250
+ */
251
+ encryptionEnhance(passphrase) {
252
+ return passphrase;
253
+ }
227
254
  /**
228
255
  * Format date to string
229
256
  * @param input Input date
@@ -263,6 +290,21 @@ export class CoreApp {
263
290
  formatError(error) {
264
291
  return error.toString();
265
292
  }
293
+ /**
294
+ * Format refresh token result
295
+ * @param result Refresh token result
296
+ * @returns Message
297
+ */
298
+ formatRefreshTokenResult(result) {
299
+ // Undefined for boolean
300
+ if (typeof result === 'boolean')
301
+ return undefined;
302
+ return result instanceof ApiDataError
303
+ ? this.formatError(result)
304
+ : typeof result !== 'string'
305
+ ? ActionResultError.format(result)
306
+ : result;
307
+ }
266
308
  /**
267
309
  * Format result text
268
310
  * @param result Action result
@@ -396,7 +438,7 @@ export class CoreApp {
396
438
  }
397
439
  /**
398
440
  * Refresh token
399
- * @param callback Callback
441
+ * @param props Props
400
442
  */
401
443
  async refreshToken(props) {
402
444
  if (props && props.callback)
@@ -468,8 +510,9 @@ export class CoreApp {
468
510
  /**
469
511
  * Try login, returning false means is loading
470
512
  * UI get involved while refreshToken not intended
513
+ * @param data Additional request data
471
514
  */
472
- async tryLogin() {
515
+ async tryLogin(_data) {
473
516
  if (this._isTryingLogin)
474
517
  return false;
475
518
  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.56",
3
+ "version": "1.1.60",
4
4
  "description": "Applications shared TypeScript framework",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/mjs/index.js",
@@ -54,7 +54,9 @@
54
54
  "dependencies": {
55
55
  "@etsoo/notificationbase": "^1.0.94",
56
56
  "@etsoo/restclient": "^1.0.62",
57
- "@etsoo/shared": "^1.0.75"
57
+ "@etsoo/shared": "^1.0.75",
58
+ "@types/crypto-js": "^4.0.2",
59
+ "crypto-js": "^4.1.1"
58
60
  },
59
61
  "devDependencies": {
60
62
  "@babel/cli": "^7.16.0",
@@ -54,6 +54,11 @@ export interface RefreshTokenProps<D extends {}> {
54
54
  */
55
55
  data?: D;
56
56
 
57
+ /**
58
+ * Support relogin or not
59
+ */
60
+ relogin?: boolean;
61
+
57
62
  /**
58
63
  * Show loading bar or not
59
64
  */
@@ -154,12 +159,28 @@ export interface ICoreApp<
154
159
  */
155
160
  changeCulture(culture: DataTypes.CultureDefinition): void;
156
161
 
162
+ /**
163
+ * Decrypt message
164
+ * @param messageEncrypted Encrypted message
165
+ * @param passphrase Secret passphrase
166
+ * @returns Pure text
167
+ */
168
+ decrypt(messageEncrypted: string, passphrase: string): string;
169
+
157
170
  /**
158
171
  * Detect IP data, call only one time
159
172
  * @param callback Callback will be called when the IP is ready
160
173
  */
161
174
  detectIP(callback?: IDetectIPCallback): void;
162
175
 
176
+ /**
177
+ * Encrypt message
178
+ * @param message Message
179
+ * @param passphrase Secret passphrase
180
+ * @returns Result
181
+ */
182
+ encrypt(message: string, passphrase: string): string;
183
+
163
184
  /**
164
185
  * Format date to string
165
186
  * @param input Input date
@@ -173,6 +194,13 @@ export interface ICoreApp<
173
194
  timeZone?: string
174
195
  ): string | undefined;
175
196
 
197
+ /**
198
+ * Format error
199
+ * @param error Error
200
+ * @returns Error message
201
+ */
202
+ formatError(error: ApiDataError): string;
203
+
176
204
  /**
177
205
  * Format money number
178
206
  * @param input Input money number
@@ -197,6 +225,13 @@ export interface ICoreApp<
197
225
  options?: Intl.NumberFormatOptions
198
226
  ): string | undefined;
199
227
 
228
+ /**
229
+ * Format refresh token result
230
+ * @param result Refresh token result
231
+ * @returns Message
232
+ */
233
+ formatRefreshTokenResult(result: RefreshTokenResult): string | undefined;
234
+
200
235
  /**
201
236
  * Format result text
202
237
  * @param result Action result
@@ -294,8 +329,10 @@ export interface ICoreApp<
294
329
 
295
330
  /**
296
331
  * Try login, returning false means is loading
332
+ * UI get involved while refreshToken not intended
333
+ * @param data Additional request data
297
334
  */
298
- tryLogin(): Promise<boolean>;
335
+ tryLogin<D extends {} = {}>(data?: D): Promise<boolean>;
299
336
 
300
337
  /**
301
338
  * User login
@@ -604,6 +641,19 @@ export abstract class CoreApp<
604
641
  });
605
642
  }
606
643
 
644
+ /**
645
+ * Decrypt message
646
+ * @param messageEncrypted Encrypted message
647
+ * @param passphrase Secret passphrase
648
+ * @returns Pure text
649
+ */
650
+ decrypt(messageEncrypted: string, passphrase: string) {
651
+ return CryptoJS.AES.decrypt(
652
+ messageEncrypted,
653
+ this.encryptionEnhance(passphrase)
654
+ ).toString();
655
+ }
656
+
607
657
  /**
608
658
  * Detect IP data, call only one time
609
659
  * @param callback Callback will be called when the IP is ready
@@ -644,6 +694,28 @@ export abstract class CoreApp<
644
694
  this.ipDetectCallbacks?.forEach((f) => f());
645
695
  }
646
696
 
697
+ /**
698
+ * Encrypt message
699
+ * @param message Message
700
+ * @param passphrase Secret passphrase
701
+ * @returns Result
702
+ */
703
+ encrypt(message: string, passphrase: string) {
704
+ return CryptoJS.AES.encrypt(
705
+ message,
706
+ this.encryptionEnhance(passphrase)
707
+ ).toString();
708
+ }
709
+
710
+ /**
711
+ * Enchance secret passphrase
712
+ * @param passphrase Secret passphrase
713
+ * @returns Enhanced passphrase
714
+ */
715
+ protected encryptionEnhance(passphrase: string) {
716
+ return passphrase;
717
+ }
718
+
647
719
  /**
648
720
  * Format date to string
649
721
  * @param input Input date
@@ -701,6 +773,22 @@ export abstract class CoreApp<
701
773
  return error.toString();
702
774
  }
703
775
 
776
+ /**
777
+ * Format refresh token result
778
+ * @param result Refresh token result
779
+ * @returns Message
780
+ */
781
+ formatRefreshTokenResult(result: RefreshTokenResult) {
782
+ // Undefined for boolean
783
+ if (typeof result === 'boolean') return undefined;
784
+
785
+ return result instanceof ApiDataError
786
+ ? this.formatError(result)
787
+ : typeof result !== 'string'
788
+ ? ActionResultError.format(result)
789
+ : result;
790
+ }
791
+
704
792
  /**
705
793
  * Format result text
706
794
  * @param result Action result
@@ -857,7 +945,7 @@ export abstract class CoreApp<
857
945
 
858
946
  /**
859
947
  * Refresh token
860
- * @param callback Callback
948
+ * @param props Props
861
949
  */
862
950
  async refreshToken<D extends {} = {}>(props?: RefreshTokenProps<D>) {
863
951
  if (props && props.callback) props.callback(true);
@@ -938,8 +1026,9 @@ export abstract class CoreApp<
938
1026
  /**
939
1027
  * Try login, returning false means is loading
940
1028
  * UI get involved while refreshToken not intended
1029
+ * @param data Additional request data
941
1030
  */
942
- async tryLogin() {
1031
+ async tryLogin<D extends {} = {}>(_data?: D) {
943
1032
  if (this._isTryingLogin) return false;
944
1033
  this._isTryingLogin = true;
945
1034
  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": "重新發送",