@etsoo/appscript 1.1.62 → 1.1.66

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.
@@ -87,6 +87,10 @@ export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallP
87
87
  * User data
88
88
  */
89
89
  userData?: IUserData;
90
+ /**
91
+ * Passphrase for encryption
92
+ */
93
+ passphrase?: string;
90
94
  /**
91
95
  * Search input element
92
96
  */
@@ -323,6 +327,10 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
323
327
  * User data
324
328
  */
325
329
  userData?: IUserData;
330
+ /**
331
+ * Passphrase for encryption
332
+ */
333
+ passphrase?: string;
326
334
  /**
327
335
  * Response token header field name
328
336
  */
@@ -401,9 +409,10 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
401
409
  /**
402
410
  * Enchance secret passphrase
403
411
  * @param passphrase Secret passphrase
412
+ * @param timestamp Timestamp
404
413
  * @returns Enhanced passphrase
405
414
  */
406
- protected encryptionEnhance(passphrase: string): string;
415
+ protected encryptionEnhance(passphrase: string, timestamp: string): string;
407
416
  /**
408
417
  * Format date to string
409
418
  * @param input Input date
@@ -203,7 +203,10 @@ class CoreApp {
203
203
  * @returns Pure text
204
204
  */
205
205
  decrypt(messageEncrypted, passphrase) {
206
- return crypto_js_1.AES.decrypt(messageEncrypted, this.encryptionEnhance(passphrase)).toString();
206
+ const pos = messageEncrypted.indexOf('+');
207
+ const timestamp = messageEncrypted.substring(0, pos);
208
+ const message = messageEncrypted.substring(pos + 1);
209
+ return crypto_js_1.AES.decrypt(message, this.encryptionEnhance(passphrase, timestamp)).toString();
207
210
  }
208
211
  /**
209
212
  * Detect IP data, call only one time
@@ -245,19 +248,22 @@ class CoreApp {
245
248
  * @returns Result
246
249
  */
247
250
  encrypt(message, passphrase) {
248
- return crypto_js_1.AES.encrypt(message, this.encryptionEnhance(passphrase)).toString();
251
+ const timestamp = shared_1.Utils.numberToChars(new Date().getTime());
252
+ return (timestamp +
253
+ '+' +
254
+ crypto_js_1.AES.encrypt(message, this.encryptionEnhance(passphrase, timestamp)).toString());
249
255
  }
250
256
  /**
251
257
  * Enchance secret passphrase
252
258
  * @param passphrase Secret passphrase
259
+ * @param timestamp Timestamp
253
260
  * @returns Enhanced passphrase
254
261
  */
255
- encryptionEnhance(passphrase) {
256
- var _a, _b;
257
- passphrase += passphrase.length;
258
- if (this.authorized)
259
- return passphrase + ((_b = (_a = this.userData) === null || _a === void 0 ? void 0 : _a.passphrase) !== null && _b !== void 0 ? _b : '');
260
- return passphrase;
262
+ encryptionEnhance(passphrase, timestamp) {
263
+ var _a;
264
+ passphrase += timestamp;
265
+ passphrase += passphrase.length.toString();
266
+ return passphrase + ((_a = this.passphrase) !== null && _a !== void 0 ? _a : '');
261
267
  }
262
268
  /**
263
269
  * Format date to string
@@ -534,6 +540,7 @@ class CoreApp {
534
540
  */
535
541
  userLogin(user, refreshToken, keep = false) {
536
542
  this.userData = user;
543
+ this.passphrase = user.passphrase;
537
544
  this.authorize(user.token, refreshToken, keep);
538
545
  }
539
546
  /**
@@ -59,6 +59,7 @@
59
59
  "status": "Status",
60
60
  "submit": "Submit",
61
61
  "success": "Success",
62
+ "timeDifferenceInvalid": "The time difference between the device and the server is {0}, which exceeds the limit of {1} seconds. Please adjust the device time. If it is abnormal, please inform the administrator",
62
63
  "tokenExpiry": "Your session is about to expire. Click the Cancel button to continue",
63
64
  "yes": "Yes",
64
65
  "unknownError": "Unknown Error",
@@ -59,6 +59,7 @@
59
59
  "status": "状态",
60
60
  "submit": "提交",
61
61
  "success": "成功",
62
+ "timeDifferenceInvalid": "设备时间和服务器时间差为{0},超过{1}秒的限制,请调整设备时间,如果异常请告知管理员",
62
63
  "tokenExpiry": "您的会话即将过期。点击 取消 按钮继续使用",
63
64
  "yes": "是",
64
65
  "unknownError": "未知错误",
@@ -59,6 +59,7 @@
59
59
  "status": "狀態",
60
60
  "submit": "提交",
61
61
  "success": "成功",
62
+ "timeDifferenceInvalid": "設備時間和服務器時間差為{0},超過{1}秒的限制,請調整設備時間,如果異常請告知管理員",
62
63
  "tokenExpiry": "您的會話即將過期。點擊 取消 按鈕繼續使用",
63
64
  "yes": "是",
64
65
  "unknownError": "未知錯誤",
@@ -25,6 +25,7 @@ export type { IApi, IApiPayload } from '@etsoo/restclient';
25
25
  export * from './result/ActionResult';
26
26
  export * from './result/ActionResultError';
27
27
  export * from './result/IActionResult';
28
+ export * from './result/InitCallResult';
28
29
  export * from './state/Culture';
29
30
  export * from './state/State';
30
31
  export * from './state/User';
package/lib/cjs/index.js CHANGED
@@ -48,6 +48,7 @@ Object.defineProperty(exports, "createClient", { enumerable: true, get: function
48
48
  __exportStar(require("./result/ActionResult"), exports);
49
49
  __exportStar(require("./result/ActionResultError"), exports);
50
50
  __exportStar(require("./result/IActionResult"), exports);
51
+ __exportStar(require("./result/InitCallResult"), exports);
51
52
  // state
52
53
  __exportStar(require("./state/Culture"), exports);
53
54
  __exportStar(require("./state/State"), exports);
@@ -0,0 +1,22 @@
1
+ import { IActionResult, IResultData } from './IActionResult';
2
+ /**
3
+ * Result data with id, follow this style to extend for specific model
4
+ */
5
+ export interface InitCallResultData extends IResultData {
6
+ /**
7
+ * Secret passphrase
8
+ */
9
+ passphrase: string;
10
+ /**
11
+ * Actual seconds gap
12
+ */
13
+ seconds: number;
14
+ /**
15
+ * Valid seconds gap
16
+ */
17
+ validSeconds: number;
18
+ }
19
+ /**
20
+ * Init call result
21
+ */
22
+ export declare type InitCallResult = IActionResult<InitCallResultData>;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -28,7 +28,7 @@ export interface IUserData {
28
28
  */
29
29
  readonly token: string;
30
30
  /**
31
- * Passphrase for encryption
31
+ * Secret passphrase
32
32
  */
33
33
  readonly passphrase: string;
34
34
  }
@@ -87,6 +87,10 @@ export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallP
87
87
  * User data
88
88
  */
89
89
  userData?: IUserData;
90
+ /**
91
+ * Passphrase for encryption
92
+ */
93
+ passphrase?: string;
90
94
  /**
91
95
  * Search input element
92
96
  */
@@ -323,6 +327,10 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
323
327
  * User data
324
328
  */
325
329
  userData?: IUserData;
330
+ /**
331
+ * Passphrase for encryption
332
+ */
333
+ passphrase?: string;
326
334
  /**
327
335
  * Response token header field name
328
336
  */
@@ -401,9 +409,10 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
401
409
  /**
402
410
  * Enchance secret passphrase
403
411
  * @param passphrase Secret passphrase
412
+ * @param timestamp Timestamp
404
413
  * @returns Enhanced passphrase
405
414
  */
406
- protected encryptionEnhance(passphrase: string): string;
415
+ protected encryptionEnhance(passphrase: string, timestamp: string): string;
407
416
  /**
408
417
  * Format date to string
409
418
  * @param input Input date
@@ -1,6 +1,6 @@
1
1
  import { NotificationAlign, NotificationMessageType } from '@etsoo/notificationbase';
2
2
  import { ApiDataError } from '@etsoo/restclient';
3
- import { DateUtils, DomUtils, NumberUtils, StorageUtils } from '@etsoo/shared';
3
+ import { DateUtils, DomUtils, NumberUtils, StorageUtils, Utils } from '@etsoo/shared';
4
4
  import { AES } from 'crypto-js';
5
5
  import { AddressRegion } from '../address/AddressRegion';
6
6
  import { AddressUtils } from '../address/AddressUtils';
@@ -200,7 +200,10 @@ export class CoreApp {
200
200
  * @returns Pure text
201
201
  */
202
202
  decrypt(messageEncrypted, passphrase) {
203
- return AES.decrypt(messageEncrypted, this.encryptionEnhance(passphrase)).toString();
203
+ const pos = messageEncrypted.indexOf('+');
204
+ const timestamp = messageEncrypted.substring(0, pos);
205
+ const message = messageEncrypted.substring(pos + 1);
206
+ return AES.decrypt(message, this.encryptionEnhance(passphrase, timestamp)).toString();
204
207
  }
205
208
  /**
206
209
  * Detect IP data, call only one time
@@ -242,19 +245,22 @@ export class CoreApp {
242
245
  * @returns Result
243
246
  */
244
247
  encrypt(message, passphrase) {
245
- return AES.encrypt(message, this.encryptionEnhance(passphrase)).toString();
248
+ const timestamp = Utils.numberToChars(new Date().getTime());
249
+ return (timestamp +
250
+ '+' +
251
+ AES.encrypt(message, this.encryptionEnhance(passphrase, timestamp)).toString());
246
252
  }
247
253
  /**
248
254
  * Enchance secret passphrase
249
255
  * @param passphrase Secret passphrase
256
+ * @param timestamp Timestamp
250
257
  * @returns Enhanced passphrase
251
258
  */
252
- encryptionEnhance(passphrase) {
253
- var _a, _b;
254
- passphrase += passphrase.length;
255
- if (this.authorized)
256
- return passphrase + ((_b = (_a = this.userData) === null || _a === void 0 ? void 0 : _a.passphrase) !== null && _b !== void 0 ? _b : '');
257
- return passphrase;
259
+ encryptionEnhance(passphrase, timestamp) {
260
+ var _a;
261
+ passphrase += timestamp;
262
+ passphrase += passphrase.length.toString();
263
+ return passphrase + ((_a = this.passphrase) !== null && _a !== void 0 ? _a : '');
258
264
  }
259
265
  /**
260
266
  * Format date to string
@@ -531,6 +537,7 @@ export class CoreApp {
531
537
  */
532
538
  userLogin(user, refreshToken, keep = false) {
533
539
  this.userData = user;
540
+ this.passphrase = user.passphrase;
534
541
  this.authorize(user.token, refreshToken, keep);
535
542
  }
536
543
  /**
@@ -59,6 +59,7 @@
59
59
  "status": "Status",
60
60
  "submit": "Submit",
61
61
  "success": "Success",
62
+ "timeDifferenceInvalid": "The time difference between the device and the server is {0}, which exceeds the limit of {1} seconds. Please adjust the device time. If it is abnormal, please inform the administrator",
62
63
  "tokenExpiry": "Your session is about to expire. Click the Cancel button to continue",
63
64
  "yes": "Yes",
64
65
  "unknownError": "Unknown Error",
@@ -59,6 +59,7 @@
59
59
  "status": "状态",
60
60
  "submit": "提交",
61
61
  "success": "成功",
62
+ "timeDifferenceInvalid": "设备时间和服务器时间差为{0},超过{1}秒的限制,请调整设备时间,如果异常请告知管理员",
62
63
  "tokenExpiry": "您的会话即将过期。点击 取消 按钮继续使用",
63
64
  "yes": "是",
64
65
  "unknownError": "未知错误",
@@ -59,6 +59,7 @@
59
59
  "status": "狀態",
60
60
  "submit": "提交",
61
61
  "success": "成功",
62
+ "timeDifferenceInvalid": "設備時間和服務器時間差為{0},超過{1}秒的限制,請調整設備時間,如果異常請告知管理員",
62
63
  "tokenExpiry": "您的會話即將過期。點擊 取消 按鈕繼續使用",
63
64
  "yes": "是",
64
65
  "unknownError": "未知錯誤",
@@ -25,6 +25,7 @@ export type { IApi, IApiPayload } from '@etsoo/restclient';
25
25
  export * from './result/ActionResult';
26
26
  export * from './result/ActionResultError';
27
27
  export * from './result/IActionResult';
28
+ export * from './result/InitCallResult';
28
29
  export * from './state/Culture';
29
30
  export * from './state/State';
30
31
  export * from './state/User';
package/lib/mjs/index.js CHANGED
@@ -33,6 +33,7 @@ export { ApiAuthorizationScheme, createClient } from '@etsoo/restclient';
33
33
  export * from './result/ActionResult';
34
34
  export * from './result/ActionResultError';
35
35
  export * from './result/IActionResult';
36
+ export * from './result/InitCallResult';
36
37
  // state
37
38
  export * from './state/Culture';
38
39
  export * from './state/State';
@@ -0,0 +1,22 @@
1
+ import { IActionResult, IResultData } from './IActionResult';
2
+ /**
3
+ * Result data with id, follow this style to extend for specific model
4
+ */
5
+ export interface InitCallResultData extends IResultData {
6
+ /**
7
+ * Secret passphrase
8
+ */
9
+ passphrase: string;
10
+ /**
11
+ * Actual seconds gap
12
+ */
13
+ seconds: number;
14
+ /**
15
+ * Valid seconds gap
16
+ */
17
+ validSeconds: number;
18
+ }
19
+ /**
20
+ * Init call result
21
+ */
22
+ export declare type InitCallResult = IActionResult<InitCallResultData>;
@@ -0,0 +1 @@
1
+ export {};
@@ -28,7 +28,7 @@ export interface IUserData {
28
28
  */
29
29
  readonly token: string;
30
30
  /**
31
- * Passphrase for encryption
31
+ * Secret passphrase
32
32
  */
33
33
  readonly passphrase: string;
34
34
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/appscript",
3
- "version": "1.1.62",
3
+ "version": "1.1.66",
4
4
  "description": "Applications shared TypeScript framework",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/mjs/index.js",
@@ -54,7 +54,7 @@
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.76",
58
58
  "@types/crypto-js": "^4.0.2",
59
59
  "crypto-js": "^4.1.1"
60
60
  },
@@ -71,7 +71,7 @@
71
71
  "eslint-config-airbnb-base": "^15.0.0",
72
72
  "eslint-plugin-import": "^2.25.3",
73
73
  "jest": "^27.4.3",
74
- "ts-jest": "^27.0.7",
74
+ "ts-jest": "^27.1.0",
75
75
  "typescript": "^4.5.2"
76
76
  }
77
77
  }
@@ -12,7 +12,8 @@ import {
12
12
  DateUtils,
13
13
  DomUtils,
14
14
  NumberUtils,
15
- StorageUtils
15
+ StorageUtils,
16
+ Utils
16
17
  } from '@etsoo/shared';
17
18
  import { AES } from 'crypto-js';
18
19
  import { AddressRegion } from '../address/AddressRegion';
@@ -129,6 +130,11 @@ export interface ICoreApp<
129
130
  */
130
131
  userData?: IUserData;
131
132
 
133
+ /**
134
+ * Passphrase for encryption
135
+ */
136
+ passphrase?: string;
137
+
132
138
  /**
133
139
  * Search input element
134
140
  */
@@ -432,6 +438,11 @@ export abstract class CoreApp<
432
438
  */
433
439
  userData?: IUserData;
434
440
 
441
+ /**
442
+ * Passphrase for encryption
443
+ */
444
+ passphrase?: string;
445
+
435
446
  /**
436
447
  * Response token header field name
437
448
  */
@@ -649,9 +660,12 @@ export abstract class CoreApp<
649
660
  * @returns Pure text
650
661
  */
651
662
  decrypt(messageEncrypted: string, passphrase: string) {
663
+ const pos = messageEncrypted.indexOf('+');
664
+ const timestamp = messageEncrypted.substring(0, pos);
665
+ const message = messageEncrypted.substring(pos + 1);
652
666
  return AES.decrypt(
653
- messageEncrypted,
654
- this.encryptionEnhance(passphrase)
667
+ message,
668
+ this.encryptionEnhance(passphrase, timestamp)
655
669
  ).toString();
656
670
  }
657
671
 
@@ -702,22 +716,27 @@ export abstract class CoreApp<
702
716
  * @returns Result
703
717
  */
704
718
  encrypt(message: string, passphrase: string) {
705
- return AES.encrypt(
706
- message,
707
- this.encryptionEnhance(passphrase)
708
- ).toString();
719
+ const timestamp = Utils.numberToChars(new Date().getTime());
720
+ return (
721
+ timestamp +
722
+ '+' +
723
+ AES.encrypt(
724
+ message,
725
+ this.encryptionEnhance(passphrase, timestamp)
726
+ ).toString()
727
+ );
709
728
  }
710
729
 
711
730
  /**
712
731
  * Enchance secret passphrase
713
732
  * @param passphrase Secret passphrase
733
+ * @param timestamp Timestamp
714
734
  * @returns Enhanced passphrase
715
735
  */
716
- protected encryptionEnhance(passphrase: string) {
717
- passphrase += passphrase.length;
718
- if (this.authorized)
719
- return passphrase + (this.userData?.passphrase ?? '');
720
- return passphrase;
736
+ protected encryptionEnhance(passphrase: string, timestamp: string) {
737
+ passphrase += timestamp;
738
+ passphrase += passphrase.length.toString();
739
+ return passphrase + (this.passphrase ?? '');
721
740
  }
722
741
 
723
742
  /**
@@ -1046,6 +1065,7 @@ export abstract class CoreApp<
1046
1065
  */
1047
1066
  userLogin(user: IUserData, refreshToken: string, keep: boolean = false) {
1048
1067
  this.userData = user;
1068
+ this.passphrase = user.passphrase;
1049
1069
  this.authorize(user.token, refreshToken, keep);
1050
1070
  }
1051
1071
 
@@ -59,6 +59,7 @@
59
59
  "status": "Status",
60
60
  "submit": "Submit",
61
61
  "success": "Success",
62
+ "timeDifferenceInvalid": "The time difference between the device and the server is {0}, which exceeds the limit of {1} seconds. Please adjust the device time. If it is abnormal, please inform the administrator",
62
63
  "tokenExpiry": "Your session is about to expire. Click the Cancel button to continue",
63
64
  "yes": "Yes",
64
65
  "unknownError": "Unknown Error",
@@ -59,6 +59,7 @@
59
59
  "status": "状态",
60
60
  "submit": "提交",
61
61
  "success": "成功",
62
+ "timeDifferenceInvalid": "设备时间和服务器时间差为{0},超过{1}秒的限制,请调整设备时间,如果异常请告知管理员",
62
63
  "tokenExpiry": "您的会话即将过期。点击 取消 按钮继续使用",
63
64
  "yes": "是",
64
65
  "unknownError": "未知错误",
@@ -59,6 +59,7 @@
59
59
  "status": "狀態",
60
60
  "submit": "提交",
61
61
  "success": "成功",
62
+ "timeDifferenceInvalid": "設備時間和服務器時間差為{0},超過{1}秒的限制,請調整設備時間,如果異常請告知管理員",
62
63
  "tokenExpiry": "您的會話即將過期。點擊 取消 按鈕繼續使用",
63
64
  "yes": "是",
64
65
  "unknownError": "未知錯誤",
package/src/index.ts CHANGED
@@ -42,6 +42,7 @@ export type { IApi, IApiPayload } from '@etsoo/restclient';
42
42
  export * from './result/ActionResult';
43
43
  export * from './result/ActionResultError';
44
44
  export * from './result/IActionResult';
45
+ export * from './result/InitCallResult';
45
46
 
46
47
  // state
47
48
  export * from './state/Culture';
@@ -0,0 +1,26 @@
1
+ import { IActionResult, IResultData } from './IActionResult';
2
+
3
+ /**
4
+ * Result data with id, follow this style to extend for specific model
5
+ */
6
+ export interface InitCallResultData extends IResultData {
7
+ /**
8
+ * Secret passphrase
9
+ */
10
+ passphrase: string;
11
+
12
+ /**
13
+ * Actual seconds gap
14
+ */
15
+ seconds: number;
16
+
17
+ /**
18
+ * Valid seconds gap
19
+ */
20
+ validSeconds: number;
21
+ }
22
+
23
+ /**
24
+ * Init call result
25
+ */
26
+ export type InitCallResult = IActionResult<InitCallResultData>;
package/src/state/User.ts CHANGED
@@ -35,7 +35,7 @@ export interface IUserData {
35
35
  readonly token: string;
36
36
 
37
37
  /**
38
- * Passphrase for encryption
38
+ * Secret passphrase
39
39
  */
40
40
  readonly passphrase: string;
41
41
  }