@etsoo/appscript 1.1.57 → 1.1.61
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.
- package/lib/cjs/app/CoreApp.d.ts +56 -0
- package/lib/cjs/app/CoreApp.js +46 -0
- package/lib/cjs/state/User.d.ts +4 -0
- package/lib/mjs/app/CoreApp.d.ts +56 -0
- package/lib/mjs/app/CoreApp.js +46 -0
- package/lib/mjs/state/User.d.ts +4 -0
- package/package.json +4 -2
- package/src/app/CoreApp.ts +89 -0
- package/src/state/User.ts +5 -0
package/lib/cjs/app/CoreApp.d.ts
CHANGED
|
@@ -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
|
|
@@ -348,12 +378,32 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
|
|
|
348
378
|
* @param culture New culture definition
|
|
349
379
|
*/
|
|
350
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;
|
|
351
388
|
/**
|
|
352
389
|
* Detect IP data, call only one time
|
|
353
390
|
* @param callback Callback will be called when the IP is ready
|
|
354
391
|
*/
|
|
355
392
|
detectIP(callback?: IDetectIPCallback): void;
|
|
356
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;
|
|
357
407
|
/**
|
|
358
408
|
* Format date to string
|
|
359
409
|
* @param input Input date
|
|
@@ -383,6 +433,12 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
|
|
|
383
433
|
* @returns Error message
|
|
384
434
|
*/
|
|
385
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;
|
|
386
442
|
/**
|
|
387
443
|
* Format result text
|
|
388
444
|
* @param result Action result
|
package/lib/cjs/app/CoreApp.js
CHANGED
|
@@ -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,27 @@ 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
|
+
var _a, _b;
|
|
256
|
+
passphrase += passphrase.length;
|
|
257
|
+
if (this.authorized)
|
|
258
|
+
return passphrase + ((_b = (_a = this.userData) === null || _a === void 0 ? void 0 : _a.passphrase) !== null && _b !== void 0 ? _b : '');
|
|
259
|
+
return passphrase;
|
|
260
|
+
}
|
|
230
261
|
/**
|
|
231
262
|
* Format date to string
|
|
232
263
|
* @param input Input date
|
|
@@ -266,6 +297,21 @@ class CoreApp {
|
|
|
266
297
|
formatError(error) {
|
|
267
298
|
return error.toString();
|
|
268
299
|
}
|
|
300
|
+
/**
|
|
301
|
+
* Format refresh token result
|
|
302
|
+
* @param result Refresh token result
|
|
303
|
+
* @returns Message
|
|
304
|
+
*/
|
|
305
|
+
formatRefreshTokenResult(result) {
|
|
306
|
+
// Undefined for boolean
|
|
307
|
+
if (typeof result === 'boolean')
|
|
308
|
+
return undefined;
|
|
309
|
+
return result instanceof restclient_1.ApiDataError
|
|
310
|
+
? this.formatError(result)
|
|
311
|
+
: typeof result !== 'string'
|
|
312
|
+
? ActionResultError_1.ActionResultError.format(result)
|
|
313
|
+
: result;
|
|
314
|
+
}
|
|
269
315
|
/**
|
|
270
316
|
* Format result text
|
|
271
317
|
* @param result Action result
|
package/lib/cjs/state/User.d.ts
CHANGED
package/lib/mjs/app/CoreApp.d.ts
CHANGED
|
@@ -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
|
|
@@ -348,12 +378,32 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
|
|
|
348
378
|
* @param culture New culture definition
|
|
349
379
|
*/
|
|
350
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;
|
|
351
388
|
/**
|
|
352
389
|
* Detect IP data, call only one time
|
|
353
390
|
* @param callback Callback will be called when the IP is ready
|
|
354
391
|
*/
|
|
355
392
|
detectIP(callback?: IDetectIPCallback): void;
|
|
356
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;
|
|
357
407
|
/**
|
|
358
408
|
* Format date to string
|
|
359
409
|
* @param input Input date
|
|
@@ -383,6 +433,12 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
|
|
|
383
433
|
* @returns Error message
|
|
384
434
|
*/
|
|
385
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;
|
|
386
442
|
/**
|
|
387
443
|
* Format result text
|
|
388
444
|
* @param result Action result
|
package/lib/mjs/app/CoreApp.js
CHANGED
|
@@ -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,27 @@ 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
|
+
var _a, _b;
|
|
253
|
+
passphrase += passphrase.length;
|
|
254
|
+
if (this.authorized)
|
|
255
|
+
return passphrase + ((_b = (_a = this.userData) === null || _a === void 0 ? void 0 : _a.passphrase) !== null && _b !== void 0 ? _b : '');
|
|
256
|
+
return passphrase;
|
|
257
|
+
}
|
|
227
258
|
/**
|
|
228
259
|
* Format date to string
|
|
229
260
|
* @param input Input date
|
|
@@ -263,6 +294,21 @@ export class CoreApp {
|
|
|
263
294
|
formatError(error) {
|
|
264
295
|
return error.toString();
|
|
265
296
|
}
|
|
297
|
+
/**
|
|
298
|
+
* Format refresh token result
|
|
299
|
+
* @param result Refresh token result
|
|
300
|
+
* @returns Message
|
|
301
|
+
*/
|
|
302
|
+
formatRefreshTokenResult(result) {
|
|
303
|
+
// Undefined for boolean
|
|
304
|
+
if (typeof result === 'boolean')
|
|
305
|
+
return undefined;
|
|
306
|
+
return result instanceof ApiDataError
|
|
307
|
+
? this.formatError(result)
|
|
308
|
+
: typeof result !== 'string'
|
|
309
|
+
? ActionResultError.format(result)
|
|
310
|
+
: result;
|
|
311
|
+
}
|
|
266
312
|
/**
|
|
267
313
|
* Format result text
|
|
268
314
|
* @param result Action result
|
package/lib/mjs/state/User.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@etsoo/appscript",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.61",
|
|
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",
|
package/src/app/CoreApp.ts
CHANGED
|
@@ -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
|
|
@@ -606,6 +641,19 @@ export abstract class CoreApp<
|
|
|
606
641
|
});
|
|
607
642
|
}
|
|
608
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
|
+
|
|
609
657
|
/**
|
|
610
658
|
* Detect IP data, call only one time
|
|
611
659
|
* @param callback Callback will be called when the IP is ready
|
|
@@ -646,6 +694,31 @@ export abstract class CoreApp<
|
|
|
646
694
|
this.ipDetectCallbacks?.forEach((f) => f());
|
|
647
695
|
}
|
|
648
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
|
+
passphrase += passphrase.length;
|
|
717
|
+
if (this.authorized)
|
|
718
|
+
return passphrase + (this.userData?.passphrase ?? '');
|
|
719
|
+
return passphrase;
|
|
720
|
+
}
|
|
721
|
+
|
|
649
722
|
/**
|
|
650
723
|
* Format date to string
|
|
651
724
|
* @param input Input date
|
|
@@ -703,6 +776,22 @@ export abstract class CoreApp<
|
|
|
703
776
|
return error.toString();
|
|
704
777
|
}
|
|
705
778
|
|
|
779
|
+
/**
|
|
780
|
+
* Format refresh token result
|
|
781
|
+
* @param result Refresh token result
|
|
782
|
+
* @returns Message
|
|
783
|
+
*/
|
|
784
|
+
formatRefreshTokenResult(result: RefreshTokenResult) {
|
|
785
|
+
// Undefined for boolean
|
|
786
|
+
if (typeof result === 'boolean') return undefined;
|
|
787
|
+
|
|
788
|
+
return result instanceof ApiDataError
|
|
789
|
+
? this.formatError(result)
|
|
790
|
+
: typeof result !== 'string'
|
|
791
|
+
? ActionResultError.format(result)
|
|
792
|
+
: result;
|
|
793
|
+
}
|
|
794
|
+
|
|
706
795
|
/**
|
|
707
796
|
* Format result text
|
|
708
797
|
* @param result Action result
|