@etsoo/appscript 1.2.85 → 1.2.88
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 +2 -380
- package/lib/cjs/app/CoreApp.js +2 -11
- package/lib/cjs/app/IApp.d.ts +412 -0
- package/lib/cjs/app/IApp.js +13 -0
- package/lib/cjs/index.d.ts +1 -0
- package/lib/cjs/index.js +1 -0
- package/lib/mjs/app/CoreApp.d.ts +2 -380
- package/lib/mjs/app/CoreApp.js +1 -10
- package/lib/mjs/app/IApp.d.ts +412 -0
- package/lib/mjs/app/IApp.js +10 -0
- package/lib/mjs/index.d.ts +1 -0
- package/lib/mjs/index.js +1 -0
- package/package.json +1 -1
- package/src/app/CoreApp.ts +9 -488
- package/src/app/IApp.ts +535 -0
- package/src/index.ts +1 -0
package/src/app/CoreApp.ts
CHANGED
|
@@ -41,67 +41,16 @@ import { IActionResult } from '../result/IActionResult';
|
|
|
41
41
|
import { InitCallResult, InitCallResultData } from '../result/InitCallResult';
|
|
42
42
|
import { IUser } from '../state/User';
|
|
43
43
|
import { IAppSettings } from './AppSettings';
|
|
44
|
+
import {
|
|
45
|
+
appFields,
|
|
46
|
+
IApp,
|
|
47
|
+
IAppFields,
|
|
48
|
+
IDetectIPCallback,
|
|
49
|
+
RefreshTokenProps,
|
|
50
|
+
RefreshTokenResult
|
|
51
|
+
} from './IApp';
|
|
44
52
|
import { UserRole } from './UserRole';
|
|
45
53
|
|
|
46
|
-
/**
|
|
47
|
-
* Detect IP callback interface
|
|
48
|
-
*/
|
|
49
|
-
export interface IDetectIPCallback {
|
|
50
|
-
(): void;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Refresh token result type
|
|
55
|
-
* true means success, false means failed but no any message
|
|
56
|
-
* other cases means failed with differnet message
|
|
57
|
-
*/
|
|
58
|
-
export type RefreshTokenResult =
|
|
59
|
-
| boolean
|
|
60
|
-
| string
|
|
61
|
-
| ApiDataError
|
|
62
|
-
| IActionResult;
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Refresh token props
|
|
66
|
-
*/
|
|
67
|
-
export interface RefreshTokenProps<D extends object> {
|
|
68
|
-
/**
|
|
69
|
-
* Callback
|
|
70
|
-
*/
|
|
71
|
-
callback?: (result: RefreshTokenResult, successData?: string) => void;
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Data to pass
|
|
75
|
-
*/
|
|
76
|
-
data?: D;
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Support relogin or not
|
|
80
|
-
*/
|
|
81
|
-
relogin?: boolean;
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Show loading bar or not
|
|
85
|
-
*/
|
|
86
|
-
showLoading?: boolean;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* App fields
|
|
91
|
-
*/
|
|
92
|
-
const appFields = [
|
|
93
|
-
'headerToken',
|
|
94
|
-
'serversideDeviceId',
|
|
95
|
-
'deviceId',
|
|
96
|
-
'devices',
|
|
97
|
-
'devicePassphrase'
|
|
98
|
-
] as const;
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* Basic type template
|
|
102
|
-
*/
|
|
103
|
-
export type IAppFields = { [key in typeof appFields[number]]: string };
|
|
104
|
-
|
|
105
54
|
/**
|
|
106
55
|
* Core application interface
|
|
107
56
|
*/
|
|
@@ -110,449 +59,21 @@ export interface ICoreApp<
|
|
|
110
59
|
S extends IAppSettings,
|
|
111
60
|
N,
|
|
112
61
|
C extends NotificationCallProps
|
|
113
|
-
> {
|
|
62
|
+
> extends IApp {
|
|
114
63
|
/**
|
|
115
64
|
* Settings
|
|
116
65
|
*/
|
|
117
66
|
readonly settings: S;
|
|
118
67
|
|
|
119
|
-
/**
|
|
120
|
-
* Fields
|
|
121
|
-
*/
|
|
122
|
-
readonly fields: IAppFields;
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* API
|
|
126
|
-
*/
|
|
127
|
-
readonly api: IApi;
|
|
128
|
-
|
|
129
68
|
/**
|
|
130
69
|
* Notifier
|
|
131
70
|
*/
|
|
132
71
|
readonly notifier: INotifier<N, C>;
|
|
133
72
|
|
|
134
|
-
/**
|
|
135
|
-
* Label delegate
|
|
136
|
-
*/
|
|
137
|
-
readonly labelDelegate: <T = string>(key: string) => T | undefined;
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* Culture, like zh-CN
|
|
141
|
-
*/
|
|
142
|
-
readonly culture: string;
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* Currency, like USD for US dollar
|
|
146
|
-
*/
|
|
147
|
-
readonly currency: string;
|
|
148
|
-
|
|
149
|
-
/**
|
|
150
|
-
* Device id
|
|
151
|
-
*/
|
|
152
|
-
readonly deviceId: string;
|
|
153
|
-
|
|
154
|
-
/**
|
|
155
|
-
* Country or region, like CN
|
|
156
|
-
*/
|
|
157
|
-
readonly region: string;
|
|
158
|
-
|
|
159
|
-
/**
|
|
160
|
-
* Storage
|
|
161
|
-
*/
|
|
162
|
-
readonly storage: IStorage;
|
|
163
|
-
|
|
164
|
-
/**
|
|
165
|
-
* Is current authorized
|
|
166
|
-
*/
|
|
167
|
-
readonly authorized: boolean;
|
|
168
|
-
|
|
169
|
-
/**
|
|
170
|
-
* Application name
|
|
171
|
-
*/
|
|
172
|
-
readonly name: string;
|
|
173
|
-
|
|
174
|
-
/**
|
|
175
|
-
* IP data
|
|
176
|
-
*/
|
|
177
|
-
ipData?: IPData;
|
|
178
|
-
|
|
179
73
|
/**
|
|
180
74
|
* User data
|
|
181
75
|
*/
|
|
182
76
|
userData?: U;
|
|
183
|
-
|
|
184
|
-
/**
|
|
185
|
-
* Search input element
|
|
186
|
-
*/
|
|
187
|
-
searchInput?: HTMLInputElement;
|
|
188
|
-
|
|
189
|
-
/**
|
|
190
|
-
* Alert action result
|
|
191
|
-
* @param result Action result
|
|
192
|
-
* @param callback Callback
|
|
193
|
-
*/
|
|
194
|
-
alertResult(
|
|
195
|
-
result: IActionResult,
|
|
196
|
-
callback?: NotificationReturn<void>
|
|
197
|
-
): void;
|
|
198
|
-
|
|
199
|
-
/**
|
|
200
|
-
* Authorize
|
|
201
|
-
* @param token New token
|
|
202
|
-
* @param refreshToken Refresh token
|
|
203
|
-
*/
|
|
204
|
-
authorize(token?: string, refreshToken?: string): void;
|
|
205
|
-
|
|
206
|
-
/**
|
|
207
|
-
* Change country or region
|
|
208
|
-
* @param region New country or region
|
|
209
|
-
*/
|
|
210
|
-
changeRegion(region: string | AddressRegion): void;
|
|
211
|
-
|
|
212
|
-
/**
|
|
213
|
-
* Change culture
|
|
214
|
-
* @param culture New culture definition
|
|
215
|
-
*/
|
|
216
|
-
changeCulture(culture: DataTypes.CultureDefinition): void;
|
|
217
|
-
|
|
218
|
-
/**
|
|
219
|
-
* Check the action result is about device invalid
|
|
220
|
-
* @param result Action result
|
|
221
|
-
* @returns true means device is invalid
|
|
222
|
-
*/
|
|
223
|
-
checkDeviceResult(result: IActionResult): boolean;
|
|
224
|
-
|
|
225
|
-
/**
|
|
226
|
-
* Clear cache data
|
|
227
|
-
*/
|
|
228
|
-
clearCacheData(): void;
|
|
229
|
-
|
|
230
|
-
/**
|
|
231
|
-
* Clear cached token
|
|
232
|
-
*/
|
|
233
|
-
clearCacheToken(): void;
|
|
234
|
-
|
|
235
|
-
/**
|
|
236
|
-
* Decrypt message
|
|
237
|
-
* @param messageEncrypted Encrypted message
|
|
238
|
-
* @param passphrase Secret passphrase
|
|
239
|
-
* @returns Pure text
|
|
240
|
-
*/
|
|
241
|
-
decrypt(messageEncrypted: string, passphrase?: string): string | undefined;
|
|
242
|
-
|
|
243
|
-
/**
|
|
244
|
-
* Enhanced decrypt message
|
|
245
|
-
* @param messageEncrypted Encrypted message
|
|
246
|
-
* @param passphrase Secret passphrase
|
|
247
|
-
* @param durationSeconds Duration seconds, <= 12 will be considered as month
|
|
248
|
-
* @returns Pure text
|
|
249
|
-
*/
|
|
250
|
-
decryptEnhanced(
|
|
251
|
-
messageEncrypted: string,
|
|
252
|
-
passphrase?: string,
|
|
253
|
-
durationSeconds?: number
|
|
254
|
-
): string | undefined;
|
|
255
|
-
|
|
256
|
-
/**
|
|
257
|
-
* Detect IP data, call only one time
|
|
258
|
-
* @param callback Callback will be called when the IP is ready
|
|
259
|
-
*/
|
|
260
|
-
detectIP(callback?: IDetectIPCallback): void;
|
|
261
|
-
|
|
262
|
-
/**
|
|
263
|
-
* Encrypt message
|
|
264
|
-
* @param message Message
|
|
265
|
-
* @param passphrase Secret passphrase
|
|
266
|
-
* @param iterations Iterations, 1000 times, 1 - 99
|
|
267
|
-
* @returns Result
|
|
268
|
-
*/
|
|
269
|
-
encrypt(message: string, passphrase?: string, iterations?: number): string;
|
|
270
|
-
|
|
271
|
-
/**
|
|
272
|
-
* Enhanced encrypt message
|
|
273
|
-
* @param message Message
|
|
274
|
-
* @param passphrase Secret passphrase
|
|
275
|
-
* @param iterations Iterations, 1000 times, 1 - 99
|
|
276
|
-
* @returns Result
|
|
277
|
-
*/
|
|
278
|
-
encryptEnhanced(
|
|
279
|
-
message: string,
|
|
280
|
-
passphrase?: string,
|
|
281
|
-
iterations?: number
|
|
282
|
-
): string;
|
|
283
|
-
|
|
284
|
-
/**
|
|
285
|
-
* Format date to string
|
|
286
|
-
* @param input Input date
|
|
287
|
-
* @param options Options
|
|
288
|
-
* @param timeZone Time zone
|
|
289
|
-
* @returns string
|
|
290
|
-
*/
|
|
291
|
-
formatDate(
|
|
292
|
-
input?: Date | string,
|
|
293
|
-
options?: DateUtils.FormatOptions,
|
|
294
|
-
timeZone?: string
|
|
295
|
-
): string | undefined;
|
|
296
|
-
|
|
297
|
-
/**
|
|
298
|
-
* Format error
|
|
299
|
-
* @param error Error
|
|
300
|
-
* @returns Error message
|
|
301
|
-
*/
|
|
302
|
-
formatError(error: ApiDataError): string;
|
|
303
|
-
|
|
304
|
-
/**
|
|
305
|
-
* Format money number
|
|
306
|
-
* @param input Input money number
|
|
307
|
-
* @param isInteger Is integer
|
|
308
|
-
* @param options Options
|
|
309
|
-
* @returns Result
|
|
310
|
-
*/
|
|
311
|
-
formatMoney(
|
|
312
|
-
input?: number | bigint,
|
|
313
|
-
isInteger?: boolean,
|
|
314
|
-
options?: Intl.NumberFormatOptions
|
|
315
|
-
): string | undefined;
|
|
316
|
-
|
|
317
|
-
/**
|
|
318
|
-
* Format number
|
|
319
|
-
* @param input Input number
|
|
320
|
-
* @param options Options
|
|
321
|
-
* @returns Result
|
|
322
|
-
*/
|
|
323
|
-
formatNumber(
|
|
324
|
-
input?: number | bigint,
|
|
325
|
-
options?: Intl.NumberFormatOptions
|
|
326
|
-
): string | undefined;
|
|
327
|
-
|
|
328
|
-
/**
|
|
329
|
-
* Do refresh token result
|
|
330
|
-
* @param result Result
|
|
331
|
-
* @param initCallCallback InitCall callback
|
|
332
|
-
* @param silent Silent without any popups
|
|
333
|
-
*/
|
|
334
|
-
doRefreshTokenResult(
|
|
335
|
-
result: RefreshTokenResult,
|
|
336
|
-
initCallCallback?: (result: boolean) => void,
|
|
337
|
-
silent?: boolean
|
|
338
|
-
): void;
|
|
339
|
-
|
|
340
|
-
/**
|
|
341
|
-
* Format refresh token result
|
|
342
|
-
* @param result Refresh token result
|
|
343
|
-
* @returns Message
|
|
344
|
-
*/
|
|
345
|
-
formatRefreshTokenResult(result: RefreshTokenResult): string | undefined;
|
|
346
|
-
|
|
347
|
-
/**
|
|
348
|
-
* Format result text
|
|
349
|
-
* @param result Action result
|
|
350
|
-
* @param forceToLocal Force to local labels
|
|
351
|
-
* @returns Message
|
|
352
|
-
*/
|
|
353
|
-
formatResult(result: IActionResult, forceToLocal?: boolean): string;
|
|
354
|
-
|
|
355
|
-
/**
|
|
356
|
-
* Fresh countdown UI
|
|
357
|
-
* @param callback Callback
|
|
358
|
-
*/
|
|
359
|
-
freshCountdownUI(callback?: () => PromiseLike<unknown>): void;
|
|
360
|
-
|
|
361
|
-
/**
|
|
362
|
-
* Get culture resource
|
|
363
|
-
* @param key key
|
|
364
|
-
* @returns Resource
|
|
365
|
-
*/
|
|
366
|
-
get<T = string>(key: string): T | undefined;
|
|
367
|
-
|
|
368
|
-
/**
|
|
369
|
-
* Get multiple culture labels
|
|
370
|
-
* @param keys Keys
|
|
371
|
-
*/
|
|
372
|
-
getLabels<T extends string>(...keys: T[]): { [K in T]: string };
|
|
373
|
-
|
|
374
|
-
/**
|
|
375
|
-
* Get cached token
|
|
376
|
-
* @returns Cached token
|
|
377
|
-
*/
|
|
378
|
-
getCacheToken(): string | undefined;
|
|
379
|
-
|
|
380
|
-
/**
|
|
381
|
-
* Get all regions
|
|
382
|
-
* @returns Regions
|
|
383
|
-
*/
|
|
384
|
-
getRegions(): AddressRegion[];
|
|
385
|
-
|
|
386
|
-
/**
|
|
387
|
-
* Get roles
|
|
388
|
-
* @param role Combination role value
|
|
389
|
-
*/
|
|
390
|
-
getRoles(role: number): ListType[];
|
|
391
|
-
|
|
392
|
-
/**
|
|
393
|
-
* Get status label
|
|
394
|
-
* @param status Status value
|
|
395
|
-
*/
|
|
396
|
-
getStatusLabel(status: number | null | undefined): string;
|
|
397
|
-
|
|
398
|
-
/**
|
|
399
|
-
* Get status list
|
|
400
|
-
* @returns list
|
|
401
|
-
*/
|
|
402
|
-
getStatusList(): ListType[];
|
|
403
|
-
|
|
404
|
-
/**
|
|
405
|
-
* Get refresh token from response headers
|
|
406
|
-
* @param rawResponse Raw response from API call
|
|
407
|
-
* @returns response refresh token
|
|
408
|
-
*/
|
|
409
|
-
getResponseToken(rawResponse: any): string | null;
|
|
410
|
-
|
|
411
|
-
/**
|
|
412
|
-
* Get time zone
|
|
413
|
-
* @returns Time zone
|
|
414
|
-
*/
|
|
415
|
-
getTimeZone(): string | undefined;
|
|
416
|
-
|
|
417
|
-
/**
|
|
418
|
-
* Get product unit and repeat option label
|
|
419
|
-
* @param unit Product unit or repeat option
|
|
420
|
-
* @param isJoined Add the join label like 'per Kg' for Kg
|
|
421
|
-
*/
|
|
422
|
-
getUnitLabel(unit?: ProductUnit, isJoined?: boolean): string;
|
|
423
|
-
|
|
424
|
-
/**
|
|
425
|
-
* Hash message, SHA3 or HmacSHA512, 512 as Base64
|
|
426
|
-
* https://cryptojs.gitbook.io/docs/
|
|
427
|
-
* @param message Message
|
|
428
|
-
* @param passphrase Secret passphrase
|
|
429
|
-
*/
|
|
430
|
-
hash(message: string, passphrase?: string): string;
|
|
431
|
-
|
|
432
|
-
/**
|
|
433
|
-
* Hash message Hex, SHA3 or HmacSHA512, 512 as Base64
|
|
434
|
-
* https://cryptojs.gitbook.io/docs/
|
|
435
|
-
* @param message Message
|
|
436
|
-
* @param passphrase Secret passphrase
|
|
437
|
-
*/
|
|
438
|
-
hashHex(message: string, passphrase?: string): string;
|
|
439
|
-
|
|
440
|
-
/**
|
|
441
|
-
* Check use has the specific role permission or not
|
|
442
|
-
* @param roles Roles to check
|
|
443
|
-
* @returns Result
|
|
444
|
-
*/
|
|
445
|
-
hasPermission(roles: number | UserRole | number[] | UserRole[]): boolean;
|
|
446
|
-
|
|
447
|
-
/**
|
|
448
|
-
* Init call
|
|
449
|
-
* @param callback Callback
|
|
450
|
-
* @param resetKeys Reset all keys first
|
|
451
|
-
* @returns Result
|
|
452
|
-
*/
|
|
453
|
-
initCall(
|
|
454
|
-
callback?: (result: boolean) => void,
|
|
455
|
-
resetKeys?: boolean
|
|
456
|
-
): Promise<void>;
|
|
457
|
-
|
|
458
|
-
/**
|
|
459
|
-
* Is valid password, override to implement custom check
|
|
460
|
-
* @param password Input password
|
|
461
|
-
*/
|
|
462
|
-
isValidPassword(password: string): boolean;
|
|
463
|
-
|
|
464
|
-
/**
|
|
465
|
-
* Callback where exit a page
|
|
466
|
-
*/
|
|
467
|
-
pageExit(): void;
|
|
468
|
-
|
|
469
|
-
/**
|
|
470
|
-
* Refresh token
|
|
471
|
-
* @param props Props
|
|
472
|
-
*/
|
|
473
|
-
refreshToken<D extends object = {}>(
|
|
474
|
-
props?: RefreshTokenProps<D>
|
|
475
|
-
): Promise<boolean>;
|
|
476
|
-
|
|
477
|
-
/**
|
|
478
|
-
* Signout
|
|
479
|
-
*/
|
|
480
|
-
signout(): Promise<void>;
|
|
481
|
-
|
|
482
|
-
/**
|
|
483
|
-
* Get organization list
|
|
484
|
-
* @param items Max items
|
|
485
|
-
* @param serviceId Service id
|
|
486
|
-
* @returns Result
|
|
487
|
-
*/
|
|
488
|
-
orgList(
|
|
489
|
-
items?: number,
|
|
490
|
-
serviceId?: number
|
|
491
|
-
): Promise<ListType[] | undefined>;
|
|
492
|
-
|
|
493
|
-
/**
|
|
494
|
-
* Persist settings to source when application exit
|
|
495
|
-
*/
|
|
496
|
-
persist(): void;
|
|
497
|
-
|
|
498
|
-
/**
|
|
499
|
-
* Redirect to the Url
|
|
500
|
-
* @param url Url
|
|
501
|
-
*/
|
|
502
|
-
redirectTo(url: string): void;
|
|
503
|
-
|
|
504
|
-
/**
|
|
505
|
-
* Switch organization
|
|
506
|
-
* @param id Organization id
|
|
507
|
-
* @param serviceId Service id
|
|
508
|
-
*/
|
|
509
|
-
switchOrg(id: number, serviceId?: number): Promise<boolean | undefined>;
|
|
510
|
-
|
|
511
|
-
/**
|
|
512
|
-
* Go to the login page
|
|
513
|
-
* @param tryLogin Try to login again
|
|
514
|
-
*/
|
|
515
|
-
toLoginPage(tryLogin?: boolean): void;
|
|
516
|
-
|
|
517
|
-
/**
|
|
518
|
-
* Transform URL
|
|
519
|
-
* @param url URL
|
|
520
|
-
* @returns Transformed url
|
|
521
|
-
*/
|
|
522
|
-
transformUrl(url: string): string;
|
|
523
|
-
|
|
524
|
-
/**
|
|
525
|
-
* Try login, returning false means is loading
|
|
526
|
-
* UI get involved while refreshToken not intended
|
|
527
|
-
* @param data Additional request data
|
|
528
|
-
*/
|
|
529
|
-
tryLogin<D extends object = {}>(data?: D): Promise<boolean>;
|
|
530
|
-
|
|
531
|
-
/**
|
|
532
|
-
* User login
|
|
533
|
-
* @param user User data
|
|
534
|
-
* @param refreshToken Refresh token
|
|
535
|
-
* @param keep Keep login or not
|
|
536
|
-
*/
|
|
537
|
-
userLogin(user: U, refreshToken: string, keep?: boolean): void;
|
|
538
|
-
|
|
539
|
-
/**
|
|
540
|
-
* User logout
|
|
541
|
-
* @param clearToken Clear refresh token or not
|
|
542
|
-
*/
|
|
543
|
-
userLogout(clearToken: boolean): void;
|
|
544
|
-
|
|
545
|
-
/**
|
|
546
|
-
* User unauthorized
|
|
547
|
-
*/
|
|
548
|
-
userUnauthorized(): void;
|
|
549
|
-
|
|
550
|
-
/**
|
|
551
|
-
* Show warning message
|
|
552
|
-
* @param message Message
|
|
553
|
-
* @param align Align, default as TopRight
|
|
554
|
-
*/
|
|
555
|
-
warning(message: NotificationContent<N>, align?: NotificationAlign): void;
|
|
556
77
|
}
|
|
557
78
|
|
|
558
79
|
/**
|