@etsoo/appscript 1.1.58 → 1.1.62
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 +52 -0
- package/lib/cjs/app/CoreApp.js +47 -0
- package/lib/cjs/state/User.d.ts +4 -0
- package/lib/mjs/app/CoreApp.d.ts +52 -0
- package/lib/mjs/app/CoreApp.js +47 -0
- package/lib/mjs/state/User.d.ts +4 -0
- package/package.json +4 -2
- package/src/app/CoreApp.ts +85 -0
- package/src/state/User.ts +5 -0
package/lib/cjs/app/CoreApp.d.ts
CHANGED
|
@@ -113,11 +113,25 @@ export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallP
|
|
|
113
113
|
* @param culture New culture definition
|
|
114
114
|
*/
|
|
115
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;
|
|
116
123
|
/**
|
|
117
124
|
* Detect IP data, call only one time
|
|
118
125
|
* @param callback Callback will be called when the IP is ready
|
|
119
126
|
*/
|
|
120
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;
|
|
121
135
|
/**
|
|
122
136
|
* Format date to string
|
|
123
137
|
* @param input Input date
|
|
@@ -126,6 +140,12 @@ export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallP
|
|
|
126
140
|
* @returns string
|
|
127
141
|
*/
|
|
128
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;
|
|
129
149
|
/**
|
|
130
150
|
* Format money number
|
|
131
151
|
* @param input Input money number
|
|
@@ -141,6 +161,12 @@ export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallP
|
|
|
141
161
|
* @returns Result
|
|
142
162
|
*/
|
|
143
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;
|
|
144
170
|
/**
|
|
145
171
|
* Format result text
|
|
146
172
|
* @param result Action result
|
|
@@ -352,12 +378,32 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
|
|
|
352
378
|
* @param culture New culture definition
|
|
353
379
|
*/
|
|
354
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;
|
|
355
388
|
/**
|
|
356
389
|
* Detect IP data, call only one time
|
|
357
390
|
* @param callback Callback will be called when the IP is ready
|
|
358
391
|
*/
|
|
359
392
|
detectIP(callback?: IDetectIPCallback): void;
|
|
360
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;
|
|
361
407
|
/**
|
|
362
408
|
* Format date to string
|
|
363
409
|
* @param input Input date
|
|
@@ -387,6 +433,12 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
|
|
|
387
433
|
* @returns Error message
|
|
388
434
|
*/
|
|
389
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;
|
|
390
442
|
/**
|
|
391
443
|
* Format result text
|
|
392
444
|
* @param result Action result
|
package/lib/cjs/app/CoreApp.js
CHANGED
|
@@ -2,7 +2,9 @@
|
|
|
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");
|
|
7
|
+
const crypto_js_1 = require("crypto-js");
|
|
6
8
|
const AddressRegion_1 = require("../address/AddressRegion");
|
|
7
9
|
const AddressUtils_1 = require("../address/AddressUtils");
|
|
8
10
|
const ActionResultError_1 = require("../result/ActionResultError");
|
|
@@ -194,6 +196,15 @@ class CoreApp {
|
|
|
194
196
|
region.name = AddressUtils_1.AddressUtils.getRegionLabel(id, this.labelDelegate);
|
|
195
197
|
});
|
|
196
198
|
}
|
|
199
|
+
/**
|
|
200
|
+
* Decrypt message
|
|
201
|
+
* @param messageEncrypted Encrypted message
|
|
202
|
+
* @param passphrase Secret passphrase
|
|
203
|
+
* @returns Pure text
|
|
204
|
+
*/
|
|
205
|
+
decrypt(messageEncrypted, passphrase) {
|
|
206
|
+
return crypto_js_1.AES.decrypt(messageEncrypted, this.encryptionEnhance(passphrase)).toString();
|
|
207
|
+
}
|
|
197
208
|
/**
|
|
198
209
|
* Detect IP data, call only one time
|
|
199
210
|
* @param callback Callback will be called when the IP is ready
|
|
@@ -227,6 +238,27 @@ class CoreApp {
|
|
|
227
238
|
var _a;
|
|
228
239
|
(_a = this.ipDetectCallbacks) === null || _a === void 0 ? void 0 : _a.forEach((f) => f());
|
|
229
240
|
}
|
|
241
|
+
/**
|
|
242
|
+
* Encrypt message
|
|
243
|
+
* @param message Message
|
|
244
|
+
* @param passphrase Secret passphrase
|
|
245
|
+
* @returns Result
|
|
246
|
+
*/
|
|
247
|
+
encrypt(message, passphrase) {
|
|
248
|
+
return crypto_js_1.AES.encrypt(message, this.encryptionEnhance(passphrase)).toString();
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Enchance secret passphrase
|
|
252
|
+
* @param passphrase Secret passphrase
|
|
253
|
+
* @returns Enhanced passphrase
|
|
254
|
+
*/
|
|
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;
|
|
261
|
+
}
|
|
230
262
|
/**
|
|
231
263
|
* Format date to string
|
|
232
264
|
* @param input Input date
|
|
@@ -266,6 +298,21 @@ class CoreApp {
|
|
|
266
298
|
formatError(error) {
|
|
267
299
|
return error.toString();
|
|
268
300
|
}
|
|
301
|
+
/**
|
|
302
|
+
* Format refresh token result
|
|
303
|
+
* @param result Refresh token result
|
|
304
|
+
* @returns Message
|
|
305
|
+
*/
|
|
306
|
+
formatRefreshTokenResult(result) {
|
|
307
|
+
// Undefined for boolean
|
|
308
|
+
if (typeof result === 'boolean')
|
|
309
|
+
return undefined;
|
|
310
|
+
return result instanceof restclient_1.ApiDataError
|
|
311
|
+
? this.formatError(result)
|
|
312
|
+
: typeof result !== 'string'
|
|
313
|
+
? ActionResultError_1.ActionResultError.format(result)
|
|
314
|
+
: result;
|
|
315
|
+
}
|
|
269
316
|
/**
|
|
270
317
|
* Format result text
|
|
271
318
|
* @param result Action result
|
package/lib/cjs/state/User.d.ts
CHANGED
package/lib/mjs/app/CoreApp.d.ts
CHANGED
|
@@ -113,11 +113,25 @@ export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallP
|
|
|
113
113
|
* @param culture New culture definition
|
|
114
114
|
*/
|
|
115
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;
|
|
116
123
|
/**
|
|
117
124
|
* Detect IP data, call only one time
|
|
118
125
|
* @param callback Callback will be called when the IP is ready
|
|
119
126
|
*/
|
|
120
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;
|
|
121
135
|
/**
|
|
122
136
|
* Format date to string
|
|
123
137
|
* @param input Input date
|
|
@@ -126,6 +140,12 @@ export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallP
|
|
|
126
140
|
* @returns string
|
|
127
141
|
*/
|
|
128
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;
|
|
129
149
|
/**
|
|
130
150
|
* Format money number
|
|
131
151
|
* @param input Input money number
|
|
@@ -141,6 +161,12 @@ export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallP
|
|
|
141
161
|
* @returns Result
|
|
142
162
|
*/
|
|
143
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;
|
|
144
170
|
/**
|
|
145
171
|
* Format result text
|
|
146
172
|
* @param result Action result
|
|
@@ -352,12 +378,32 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
|
|
|
352
378
|
* @param culture New culture definition
|
|
353
379
|
*/
|
|
354
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;
|
|
355
388
|
/**
|
|
356
389
|
* Detect IP data, call only one time
|
|
357
390
|
* @param callback Callback will be called when the IP is ready
|
|
358
391
|
*/
|
|
359
392
|
detectIP(callback?: IDetectIPCallback): void;
|
|
360
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;
|
|
361
407
|
/**
|
|
362
408
|
* Format date to string
|
|
363
409
|
* @param input Input date
|
|
@@ -387,6 +433,12 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
|
|
|
387
433
|
* @returns Error message
|
|
388
434
|
*/
|
|
389
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;
|
|
390
442
|
/**
|
|
391
443
|
* Format result text
|
|
392
444
|
* @param result Action result
|
package/lib/mjs/app/CoreApp.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { NotificationAlign, NotificationMessageType } from '@etsoo/notificationbase';
|
|
2
|
+
import { ApiDataError } from '@etsoo/restclient';
|
|
2
3
|
import { DateUtils, DomUtils, NumberUtils, StorageUtils } from '@etsoo/shared';
|
|
4
|
+
import { AES } from 'crypto-js';
|
|
3
5
|
import { AddressRegion } from '../address/AddressRegion';
|
|
4
6
|
import { AddressUtils } from '../address/AddressUtils';
|
|
5
7
|
import { ActionResultError } from '../result/ActionResultError';
|
|
@@ -191,6 +193,15 @@ export class CoreApp {
|
|
|
191
193
|
region.name = AddressUtils.getRegionLabel(id, this.labelDelegate);
|
|
192
194
|
});
|
|
193
195
|
}
|
|
196
|
+
/**
|
|
197
|
+
* Decrypt message
|
|
198
|
+
* @param messageEncrypted Encrypted message
|
|
199
|
+
* @param passphrase Secret passphrase
|
|
200
|
+
* @returns Pure text
|
|
201
|
+
*/
|
|
202
|
+
decrypt(messageEncrypted, passphrase) {
|
|
203
|
+
return AES.decrypt(messageEncrypted, this.encryptionEnhance(passphrase)).toString();
|
|
204
|
+
}
|
|
194
205
|
/**
|
|
195
206
|
* Detect IP data, call only one time
|
|
196
207
|
* @param callback Callback will be called when the IP is ready
|
|
@@ -224,6 +235,27 @@ export class CoreApp {
|
|
|
224
235
|
var _a;
|
|
225
236
|
(_a = this.ipDetectCallbacks) === null || _a === void 0 ? void 0 : _a.forEach((f) => f());
|
|
226
237
|
}
|
|
238
|
+
/**
|
|
239
|
+
* Encrypt message
|
|
240
|
+
* @param message Message
|
|
241
|
+
* @param passphrase Secret passphrase
|
|
242
|
+
* @returns Result
|
|
243
|
+
*/
|
|
244
|
+
encrypt(message, passphrase) {
|
|
245
|
+
return AES.encrypt(message, this.encryptionEnhance(passphrase)).toString();
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Enchance secret passphrase
|
|
249
|
+
* @param passphrase Secret passphrase
|
|
250
|
+
* @returns Enhanced passphrase
|
|
251
|
+
*/
|
|
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;
|
|
258
|
+
}
|
|
227
259
|
/**
|
|
228
260
|
* Format date to string
|
|
229
261
|
* @param input Input date
|
|
@@ -263,6 +295,21 @@ export class CoreApp {
|
|
|
263
295
|
formatError(error) {
|
|
264
296
|
return error.toString();
|
|
265
297
|
}
|
|
298
|
+
/**
|
|
299
|
+
* Format refresh token result
|
|
300
|
+
* @param result Refresh token result
|
|
301
|
+
* @returns Message
|
|
302
|
+
*/
|
|
303
|
+
formatRefreshTokenResult(result) {
|
|
304
|
+
// Undefined for boolean
|
|
305
|
+
if (typeof result === 'boolean')
|
|
306
|
+
return undefined;
|
|
307
|
+
return result instanceof ApiDataError
|
|
308
|
+
? this.formatError(result)
|
|
309
|
+
: typeof result !== 'string'
|
|
310
|
+
? ActionResultError.format(result)
|
|
311
|
+
: result;
|
|
312
|
+
}
|
|
266
313
|
/**
|
|
267
314
|
* Format result text
|
|
268
315
|
* @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.62",
|
|
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
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
NumberUtils,
|
|
15
15
|
StorageUtils
|
|
16
16
|
} from '@etsoo/shared';
|
|
17
|
+
import { AES } from 'crypto-js';
|
|
17
18
|
import { AddressRegion } from '../address/AddressRegion';
|
|
18
19
|
import { AddressUtils } from '../address/AddressUtils';
|
|
19
20
|
import { ActionResultError } from '../result/ActionResultError';
|
|
@@ -159,12 +160,28 @@ export interface ICoreApp<
|
|
|
159
160
|
*/
|
|
160
161
|
changeCulture(culture: DataTypes.CultureDefinition): void;
|
|
161
162
|
|
|
163
|
+
/**
|
|
164
|
+
* Decrypt message
|
|
165
|
+
* @param messageEncrypted Encrypted message
|
|
166
|
+
* @param passphrase Secret passphrase
|
|
167
|
+
* @returns Pure text
|
|
168
|
+
*/
|
|
169
|
+
decrypt(messageEncrypted: string, passphrase: string): string;
|
|
170
|
+
|
|
162
171
|
/**
|
|
163
172
|
* Detect IP data, call only one time
|
|
164
173
|
* @param callback Callback will be called when the IP is ready
|
|
165
174
|
*/
|
|
166
175
|
detectIP(callback?: IDetectIPCallback): void;
|
|
167
176
|
|
|
177
|
+
/**
|
|
178
|
+
* Encrypt message
|
|
179
|
+
* @param message Message
|
|
180
|
+
* @param passphrase Secret passphrase
|
|
181
|
+
* @returns Result
|
|
182
|
+
*/
|
|
183
|
+
encrypt(message: string, passphrase: string): string;
|
|
184
|
+
|
|
168
185
|
/**
|
|
169
186
|
* Format date to string
|
|
170
187
|
* @param input Input date
|
|
@@ -178,6 +195,13 @@ export interface ICoreApp<
|
|
|
178
195
|
timeZone?: string
|
|
179
196
|
): string | undefined;
|
|
180
197
|
|
|
198
|
+
/**
|
|
199
|
+
* Format error
|
|
200
|
+
* @param error Error
|
|
201
|
+
* @returns Error message
|
|
202
|
+
*/
|
|
203
|
+
formatError(error: ApiDataError): string;
|
|
204
|
+
|
|
181
205
|
/**
|
|
182
206
|
* Format money number
|
|
183
207
|
* @param input Input money number
|
|
@@ -202,6 +226,13 @@ export interface ICoreApp<
|
|
|
202
226
|
options?: Intl.NumberFormatOptions
|
|
203
227
|
): string | undefined;
|
|
204
228
|
|
|
229
|
+
/**
|
|
230
|
+
* Format refresh token result
|
|
231
|
+
* @param result Refresh token result
|
|
232
|
+
* @returns Message
|
|
233
|
+
*/
|
|
234
|
+
formatRefreshTokenResult(result: RefreshTokenResult): string | undefined;
|
|
235
|
+
|
|
205
236
|
/**
|
|
206
237
|
* Format result text
|
|
207
238
|
* @param result Action result
|
|
@@ -611,6 +642,19 @@ export abstract class CoreApp<
|
|
|
611
642
|
});
|
|
612
643
|
}
|
|
613
644
|
|
|
645
|
+
/**
|
|
646
|
+
* Decrypt message
|
|
647
|
+
* @param messageEncrypted Encrypted message
|
|
648
|
+
* @param passphrase Secret passphrase
|
|
649
|
+
* @returns Pure text
|
|
650
|
+
*/
|
|
651
|
+
decrypt(messageEncrypted: string, passphrase: string) {
|
|
652
|
+
return AES.decrypt(
|
|
653
|
+
messageEncrypted,
|
|
654
|
+
this.encryptionEnhance(passphrase)
|
|
655
|
+
).toString();
|
|
656
|
+
}
|
|
657
|
+
|
|
614
658
|
/**
|
|
615
659
|
* Detect IP data, call only one time
|
|
616
660
|
* @param callback Callback will be called when the IP is ready
|
|
@@ -651,6 +695,31 @@ export abstract class CoreApp<
|
|
|
651
695
|
this.ipDetectCallbacks?.forEach((f) => f());
|
|
652
696
|
}
|
|
653
697
|
|
|
698
|
+
/**
|
|
699
|
+
* Encrypt message
|
|
700
|
+
* @param message Message
|
|
701
|
+
* @param passphrase Secret passphrase
|
|
702
|
+
* @returns Result
|
|
703
|
+
*/
|
|
704
|
+
encrypt(message: string, passphrase: string) {
|
|
705
|
+
return AES.encrypt(
|
|
706
|
+
message,
|
|
707
|
+
this.encryptionEnhance(passphrase)
|
|
708
|
+
).toString();
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
/**
|
|
712
|
+
* Enchance secret passphrase
|
|
713
|
+
* @param passphrase Secret passphrase
|
|
714
|
+
* @returns Enhanced passphrase
|
|
715
|
+
*/
|
|
716
|
+
protected encryptionEnhance(passphrase: string) {
|
|
717
|
+
passphrase += passphrase.length;
|
|
718
|
+
if (this.authorized)
|
|
719
|
+
return passphrase + (this.userData?.passphrase ?? '');
|
|
720
|
+
return passphrase;
|
|
721
|
+
}
|
|
722
|
+
|
|
654
723
|
/**
|
|
655
724
|
* Format date to string
|
|
656
725
|
* @param input Input date
|
|
@@ -708,6 +777,22 @@ export abstract class CoreApp<
|
|
|
708
777
|
return error.toString();
|
|
709
778
|
}
|
|
710
779
|
|
|
780
|
+
/**
|
|
781
|
+
* Format refresh token result
|
|
782
|
+
* @param result Refresh token result
|
|
783
|
+
* @returns Message
|
|
784
|
+
*/
|
|
785
|
+
formatRefreshTokenResult(result: RefreshTokenResult) {
|
|
786
|
+
// Undefined for boolean
|
|
787
|
+
if (typeof result === 'boolean') return undefined;
|
|
788
|
+
|
|
789
|
+
return result instanceof ApiDataError
|
|
790
|
+
? this.formatError(result)
|
|
791
|
+
: typeof result !== 'string'
|
|
792
|
+
? ActionResultError.format(result)
|
|
793
|
+
: result;
|
|
794
|
+
}
|
|
795
|
+
|
|
711
796
|
/**
|
|
712
797
|
* Format result text
|
|
713
798
|
* @param result Action result
|