@etsoo/appscript 1.5.67 → 1.5.69

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/src/app/IApp.ts CHANGED
@@ -1,44 +1,44 @@
1
1
  import {
2
- INotifier,
3
- NotificationAlign,
4
- NotificationCallProps,
5
- NotificationContent,
6
- NotificationReturn
7
- } from '@etsoo/notificationbase';
8
- import { ApiDataError, IApi, IPData } from '@etsoo/restclient';
2
+ INotifier,
3
+ NotificationAlign,
4
+ NotificationCallProps,
5
+ NotificationContent,
6
+ NotificationReturn
7
+ } from "@etsoo/notificationbase";
8
+ import { ApiDataError, IApi, IPData } from "@etsoo/restclient";
9
9
  import {
10
- DataTypes,
11
- DateUtils,
12
- ErrorData,
13
- ErrorType,
14
- IActionResult,
15
- IStorage,
16
- ListType,
17
- ListType1
18
- } from '@etsoo/shared';
19
- import { AddressRegion } from '../address/AddressRegion';
20
- import { IUser } from '../state/User';
21
- import { IAppSettings } from './AppSettings';
22
- import { UserRole } from './UserRole';
23
- import { EntityStatus } from '../business/EntityStatus';
24
- import { Currency } from '../business/Currency';
25
- import { ExternalEndpoint } from './ExternalSettings';
26
- import { ApiRefreshTokenDto } from '../api/dto/ApiRefreshTokenDto';
27
- import { ApiRefreshTokenRQ } from '../api/rq/ApiRefreshTokenRQ';
10
+ DataTypes,
11
+ DateUtils,
12
+ ErrorData,
13
+ ErrorType,
14
+ IActionResult,
15
+ IStorage,
16
+ ListType,
17
+ ListType1
18
+ } from "@etsoo/shared";
19
+ import { AddressRegion } from "../address/AddressRegion";
20
+ import { IUser } from "../state/User";
21
+ import { IAppSettings } from "./AppSettings";
22
+ import { UserRole } from "./UserRole";
23
+ import { EntityStatus } from "../business/EntityStatus";
24
+ import { Currency } from "../business/Currency";
25
+ import { ExternalEndpoint } from "./ExternalSettings";
26
+ import { ApiRefreshTokenDto } from "../api/dto/ApiRefreshTokenDto";
27
+ import { ApiRefreshTokenRQ } from "../api/rq/ApiRefreshTokenRQ";
28
28
 
29
29
  /**
30
30
  * Detect IP callback interface
31
31
  */
32
32
  export interface IDetectIPCallback {
33
- (): void;
33
+ (): void;
34
34
  }
35
35
 
36
36
  /**
37
37
  * Navigate options
38
38
  */
39
39
  export interface NavigateOptions {
40
- replace?: boolean;
41
- state?: any;
40
+ replace?: boolean;
41
+ state?: any;
42
42
  }
43
43
 
44
44
  /**
@@ -52,95 +52,95 @@ export type RefreshTokenResult<R> = IActionResult | [string | null, R];
52
52
  * Format result custom type
53
53
  */
54
54
  export type FormatResultCustom = {
55
- title?: string;
56
- type?: string;
57
- field?: string;
55
+ title?: string;
56
+ type?: string;
57
+ field?: string;
58
58
  };
59
59
 
60
60
  /**
61
61
  * Format result custom callback type
62
62
  */
63
63
  export type FormatResultCustomCallback =
64
- | ((data: FormatResultCustom) => string | null | undefined)
65
- | boolean;
64
+ | ((data: FormatResultCustom) => string | null | undefined)
65
+ | boolean;
66
66
 
67
67
  /**
68
68
  * Login parameters
69
69
  */
70
70
  export type AppLoginParams = {
71
+ /**
72
+ * Login parameters to pass
73
+ */
74
+ params?: DataTypes.SimpleObject & {
71
75
  /**
72
- * Login parameters to pass
76
+ * Try login with cached refresh token
73
77
  */
74
- params?: DataTypes.SimpleObject & {
75
- /**
76
- * Try login with cached refresh token
77
- */
78
- tryLogin?: boolean;
79
- };
78
+ tryLogin?: boolean;
79
+ };
80
80
 
81
- /**
82
- * Don't cache current URL instead of the default page
83
- */
84
- removeUrl?: boolean;
81
+ /**
82
+ * Don't cache current URL instead of the default page
83
+ */
84
+ removeUrl?: boolean;
85
85
 
86
- /**
87
- * Show loading bar or not
88
- */
89
- showLoading?: boolean;
86
+ /**
87
+ * Show loading bar or not
88
+ */
89
+ showLoading?: boolean;
90
90
  };
91
91
 
92
92
  /**
93
93
  * App try login parameters
94
94
  */
95
95
  export type AppTryLoginParams = AppLoginParams & {
96
- /**
97
- * Callback on failure
98
- */
99
- onFailure?: () => void;
100
-
101
- /**
102
- * Callback on success
103
- */
104
- onSuccess?: () => void;
96
+ /**
97
+ * Callback on failure
98
+ */
99
+ onFailure?: () => void;
100
+
101
+ /**
102
+ * Callback on success
103
+ */
104
+ onSuccess?: () => void;
105
105
  };
106
106
 
107
107
  /**
108
108
  * Refresh token props
109
109
  */
110
110
  export interface RefreshTokenProps {
111
- /**
112
- * Refresh token
113
- */
114
- token?: string;
115
-
116
- /**
117
- * API URL
118
- */
119
- api?: string;
120
-
121
- /**
122
- * Show loading bar or not
123
- */
124
- showLoading?: boolean;
125
-
126
- /**
127
- * Header token field name
128
- */
129
- tokenField?: string;
111
+ /**
112
+ * Refresh token
113
+ */
114
+ token?: string;
115
+
116
+ /**
117
+ * API URL
118
+ */
119
+ api?: string;
120
+
121
+ /**
122
+ * Show loading bar or not
123
+ */
124
+ showLoading?: boolean;
125
+
126
+ /**
127
+ * Header token field name
128
+ */
129
+ tokenField?: string;
130
130
  }
131
131
 
132
132
  /**
133
133
  * App fields
134
134
  */
135
135
  export const appFields = [
136
- 'headerToken',
137
- 'serversideDeviceId',
138
- 'deviceId',
139
- 'devices',
140
- 'devicePassphrase',
141
- 'cachedUrl',
142
- 'embedded',
143
- 'keepLogin'
136
+ "headerToken",
137
+ "serversideDeviceId",
138
+ "deviceId",
139
+ "devices",
140
+ "devicePassphrase",
141
+ "cachedUrl",
142
+ "embedded",
143
+ "keepLogin"
144
144
  ] as const;
145
145
 
146
146
  /**
@@ -152,686 +152,680 @@ export type IAppFields = { [key in (typeof appFields)[number]]: string };
152
152
  * Application interface, for generic version, see ICoreApp
153
153
  */
154
154
  export interface IApp {
155
- /**
156
- * Settings
157
- */
158
- readonly settings: IAppSettings;
159
-
160
- /**
161
- * Default region
162
- */
163
- readonly defaultRegion: AddressRegion;
164
-
165
- /**
166
- * Fields
167
- */
168
- readonly fields: IAppFields;
169
-
170
- /**
171
- * API, not recommend to use it directly in code, wrap to separate methods
172
- */
173
- readonly api: IApi;
174
-
175
- /**
176
- * Notifier
177
- */
178
- readonly notifier: INotifier<unknown, NotificationCallProps>;
179
-
180
- /**
181
- * Label delegate
182
- */
183
- readonly labelDelegate: <T = string>(key: string) => T | undefined;
184
-
185
- /**
186
- * Culture, like zh-CN
187
- */
188
- readonly culture: string;
189
-
190
- /**
191
- * Currency, like USD for US dollar
192
- */
193
- readonly currency: Currency;
194
-
195
- /**
196
- * Device id
197
- */
198
- readonly deviceId: string;
199
-
200
- /**
201
- * Country or region, like CN
202
- */
203
- readonly region: string;
204
-
205
- /**
206
- * Storage
207
- */
208
- readonly storage: IStorage;
209
-
210
- /**
211
- * Is current authorized
212
- */
213
- readonly authorized: boolean;
214
-
215
- /**
216
- * Is the app ready
217
- */
218
- readonly isReady: boolean;
219
-
220
- /**
221
- * Is trying to login
222
- */
223
- readonly isTryingLogin: boolean;
224
-
225
- /**
226
- * Application name
227
- */
228
- readonly name: string;
229
-
230
- /**
231
- * Pending actions
232
- */
233
- readonly pendings: (() => any)[];
234
-
235
- /**
236
- * Is debug mode
237
- */
238
- readonly debug: boolean;
239
-
240
- /**
241
- * Is embedded mode
242
- */
243
- readonly embedded: boolean;
244
-
245
- /**
246
- * Cached URL
247
- */
248
- cachedUrl: string | undefined | null;
249
-
250
- /**
251
- * Keep login or not
252
- */
253
- keepLogin: boolean;
254
-
255
- /**
256
- * IP data
257
- */
258
- ipData?: IPData;
259
-
260
- /**
261
- * User data
262
- */
263
- userData?: IUser;
264
-
265
- /**
266
- * Search input element
267
- */
268
- searchInput?: HTMLInputElement;
269
-
270
- /**
271
- * Is screen size down 'sm'
272
- */
273
- smDown?: boolean;
274
-
275
- /**
276
- * Is screen size up 'md'
277
- */
278
- mdUp?: boolean;
279
-
280
- /**
281
- * Add root (homepage) to the URL
282
- * @param url URL to add
283
- * @returns Result
284
- */
285
- addRootUrl(url: string): string;
286
-
287
- /**
288
- * Add scheduled task
289
- * @param task Task, return false to stop
290
- * @param interval Interval in milliseconds
291
- */
292
- addTask(task: () => PromiseLike<void | false>, interval: number): void;
293
-
294
- /**
295
- * Alert result
296
- * @param result Result message
297
- * @param callback Callback
298
- */
299
- alertResult(result: string, callback?: NotificationReturn<void>): void;
300
-
301
- /**
302
- * Alert action result
303
- * @param result Action result
304
- * @param callback Callback
305
- * @param forceToLocal Force to local labels
306
- */
307
- alertResult(
308
- result: IActionResult,
309
- callback?: NotificationReturn<void>,
310
- forceToLocal?: FormatResultCustomCallback
311
- ): void;
312
-
313
- /**
314
- * Authorize
315
- * @param token New access token
316
- * @param schema Access token schema
317
- * @param refreshToken Refresh token
318
- */
319
- authorize(token?: string, schema?: string, refreshToken?: string): void;
320
-
321
- /**
322
- * Change country or region
323
- * @param region New country or region
324
- */
325
- changeRegion(region: string | AddressRegion): void;
326
-
327
- /**
328
- * Change culture
329
- * @param culture New culture definition
330
- */
331
- changeCulture(
332
- culture: DataTypes.CultureDefinition
333
- ): Promise<DataTypes.StringRecord>;
334
-
335
- /**
336
- * Check the action result is about device invalid
337
- * @param result Action result
338
- * @returns true means device is invalid
339
- */
340
- checkDeviceResult(result: IActionResult): boolean;
341
-
342
- /**
343
- * Check language is supported or not
344
- * @param language Language
345
- * @returns Result
346
- */
347
- checkLanguage(language?: string): string;
348
-
349
- /**
350
- * Clear cache data
351
- */
352
- clearCacheData(): void;
353
-
354
- /**
355
- * Clear cached token
356
- */
357
- clearCacheToken(): void;
358
-
359
- /**
360
- * Clear device id
361
- */
362
- clearDeviceId(): void;
363
-
364
- /**
365
- * Create API client, override to implement custom client creation by name
366
- * @param name Client name
367
- * @param item External endpoint item
368
- * @returns Result
369
- */
370
- createApi(
371
- name: string,
372
- item: ExternalEndpoint,
373
- refresh?: (
374
- api: IApi,
375
- rq: ApiRefreshTokenRQ
376
- ) => Promise<[string, number] | undefined>
377
- ): IApi;
378
-
379
- /**
380
- * Decrypt message
381
- * @param messageEncrypted Encrypted message
382
- * @param passphrase Secret passphrase
383
- * @returns Pure text
384
- */
385
- decrypt(messageEncrypted: string, passphrase?: string): string | undefined;
386
-
387
- /**
388
- * Enhanced decrypt message
389
- * @param messageEncrypted Encrypted message
390
- * @param passphrase Secret passphrase
391
- * @param durationSeconds Duration seconds, <= 12 will be considered as month
392
- * @returns Pure text
393
- */
394
- decryptEnhanced(
395
- messageEncrypted: string,
396
- passphrase?: string,
397
- durationSeconds?: number
398
- ): string | undefined;
399
-
400
- /**
401
- * Detect IP data, call only one time
402
- * @param callback Callback will be called when the IP is ready
403
- */
404
- detectIP(callback?: IDetectIPCallback): void;
405
-
406
- /**
407
- * Dispose the application
408
- */
409
- dispose(): void;
410
-
411
- /**
412
- * Download file
413
- * @param stream File stream
414
- * @param filename File name
415
- * @param callback callback
416
- */
417
- download(
418
- stream: ReadableStream,
419
- filename?: string,
420
- callback?: (success: boolean | undefined) => void
421
- ): Promise<void>;
422
-
423
- /**
424
- * Encrypt message
425
- * @param message Message
426
- * @param passphrase Secret passphrase
427
- * @param iterations Iterations, 1000 times, 1 - 99
428
- * @returns Result
429
- */
430
- encrypt(message: string, passphrase?: string, iterations?: number): string;
431
-
432
- /**
433
- * Enhanced encrypt message
434
- * @param message Message
435
- * @param passphrase Secret passphrase
436
- * @param iterations Iterations, 1000 times, 1 - 99
437
- * @returns Result
438
- */
439
- encryptEnhanced(
440
- message: string,
441
- passphrase?: string,
442
- iterations?: number
443
- ): string;
444
-
445
- /**
446
- * Exchange token data
447
- * @param api API
448
- * @param token Core system's refresh token to exchange
449
- * @returns Result
450
- */
451
- exchangeToken(api: IApi, token: string): Promise<void>;
452
-
453
- /**
454
- * Exchange intergration tokens for all APIs
455
- * @param coreData Core system's token data to exchange
456
- * @param coreName Core system's name, default is 'core'
457
- */
458
- exchangeTokenAll(coreData: ApiRefreshTokenDto, coreName?: string): void;
459
-
460
- /**
461
- * Format date to string
462
- * @param input Input date
463
- * @param options Options
464
- * @param timeZone Time zone
465
- * @returns string
466
- */
467
- formatDate(
468
- input?: Date | string,
469
- options?: DateUtils.FormatOptions,
470
- timeZone?: string
471
- ): string | undefined;
472
-
473
- /**
474
- * Format action
475
- * @param action Action
476
- * @param target Target name or title
477
- * @param items More items
478
- * @returns Result
479
- */
480
- formatAction(action: string, target: string, ...items: string[]): string;
481
-
482
- /**
483
- * Format error
484
- * @param error Error
485
- * @returns Error message
486
- */
487
- formatError(error: ApiDataError): string;
488
-
489
- /**
490
- * Format money number
491
- * @param input Input money number
492
- * @param isInteger Is integer
493
- * @param options Options
494
- * @returns Result
495
- */
496
- formatMoney(
497
- input: number | bigint,
498
- isInteger?: boolean,
499
- options?: Intl.NumberFormatOptions
500
- ): string;
501
-
502
- /**
503
- * Format number
504
- * @param input Input number
505
- * @param options Options
506
- * @returns Result
507
- */
508
- formatNumber(
509
- input: number | bigint,
510
- options?: Intl.NumberFormatOptions
511
- ): string;
512
-
513
- /**
514
- * Format as full name
515
- * @param familyName Family name
516
- * @param givenName Given name
517
- */
518
- formatFullName(
519
- familyName: string | undefined | null,
520
- givenName: string | undefined | null
521
- ): string;
522
-
523
- /**
524
- * Format result text
525
- * @param result Action result
526
- * @param forceToLocal Force to local labels
527
- * @returns Message
528
- */
529
- formatResult(
530
- result: IActionResult,
531
- forceToLocal?: FormatResultCustomCallback
532
- ): string;
533
-
534
- /**
535
- * Fresh countdown UI
536
- * @param callback Callback
537
- */
538
- freshCountdownUI(callback?: () => PromiseLike<unknown>): void;
539
-
540
- /**
541
- * Get culture resource
542
- * @param key key
543
- * @returns Resource
544
- */
545
- get<T = string>(key: string): T | undefined;
546
-
547
- /**
548
- * Get multiple culture labels
549
- * @param keys Keys
550
- */
551
- getLabels<T extends string>(...keys: T[]): { [K in T]: string };
552
-
553
- /**
554
- * Get bool items
555
- * @returns Bool items
556
- */
557
- getBools(): ListType1[];
558
-
559
- /**
560
- * Get cached token
561
- * @returns Cached token
562
- */
563
- getCacheToken(): string | undefined;
564
-
565
- /**
566
- * Get data privacies
567
- * @returns Result
568
- */
569
- getDataPrivacies(): ListType[];
570
-
571
- /**
572
- * Get enum item number id list
573
- * @param em Enum
574
- * @param prefix Label prefix or callback
575
- * @param filter Filter
576
- * @returns List
577
- */
578
- getEnumList<E extends DataTypes.EnumBase = DataTypes.EnumBase>(
579
- em: E,
580
- prefix: string | ((key: string) => string),
581
- filter?: (
582
- id: E[keyof E],
583
- key: keyof E & string
584
- ) => E[keyof E] | undefined
585
- ): ListType[];
586
-
587
- /**
588
- * Get enum item string id list
589
- * @param em Enum
590
- * @param prefix Label prefix or callback
591
- * @param filter Filter
592
- * @returns List
593
- */
594
- getEnumStrList<E extends DataTypes.EnumBase = DataTypes.EnumBase>(
595
- em: E,
596
- prefix: string | ((key: string) => string),
597
- filter?:
598
- | ((
599
- id: E[keyof E],
600
- key: keyof E & string
601
- ) => E[keyof E] | undefined)
602
- | E[keyof E][]
603
- ): ListType1[];
604
-
605
- /**
606
- * Get region label
607
- * @param id Region id
608
- * @returns Label
609
- */
610
- getRegionLabel(id: string): string;
611
-
612
- /**
613
- * Get all regions
614
- * @returns Regions
615
- */
616
- getRegions(): AddressRegion[];
617
-
618
- /**
619
- * Get roles
620
- * @param role Combination role value
621
- */
622
- getRoles(role: number): ListType[];
623
-
624
- /**
625
- * Get status label
626
- * @param status Status value
627
- */
628
- getStatusLabel(status: number | null | undefined): string;
629
-
630
- /**
631
- * Get status list
632
- * @param ids Limited ids
633
- * @returns list
634
- */
635
- getStatusList(ids?: EntityStatus[]): ListType[];
636
-
637
- /**
638
- * Get refresh token from response headers
639
- * @param rawResponse Raw response from API call
640
- * @param tokenKey Refresh token key
641
- * @returns response refresh token
642
- */
643
- getResponseToken(rawResponse: any, tokenKey: string): string | null;
644
-
645
- /**
646
- * Get time zone
647
- * @returns Time zone
648
- */
649
- getTimeZone(): string | undefined;
650
-
651
- /**
652
- * Hash message, SHA3 or HmacSHA512, 512 as Base64
653
- * https://cryptojs.gitbook.io/docs/
654
- * @param message Message
655
- * @param passphrase Secret passphrase
656
- */
657
- hash(message: string, passphrase?: string): string;
658
-
659
- /**
660
- * Hash message Hex, SHA3 or HmacSHA512, 512 as Base64
661
- * https://cryptojs.gitbook.io/docs/
662
- * @param message Message
663
- * @param passphrase Secret passphrase
664
- */
665
- hashHex(message: string, passphrase?: string): string;
666
-
667
- /**
668
- * Check use has the specific role permission or not
669
- * @param roles Roles to check
670
- * @returns Result
671
- */
672
- hasPermission(roles: number | UserRole | number[] | UserRole[]): boolean;
673
-
674
- /**
675
- * Init call
676
- * @param callback Callback
677
- * @param resetKeys Reset all keys first
678
- * @returns Result
679
- */
680
- initCall(
681
- callback?: (result: boolean) => void,
682
- resetKeys?: boolean
683
- ): Promise<void>;
684
-
685
- /**
686
- * Is admin user
687
- * @returns Result
688
- */
689
- isAdminUser(): boolean;
690
-
691
- /**
692
- * Is Finance user
693
- * @returns Result
694
- */
695
- isFinanceUser(): boolean;
696
-
697
- /**
698
- * Is HR user
699
- * @returns Result
700
- */
701
- isHRUser(): boolean;
702
-
703
- /**
704
- * Is valid password, override to implement custom check
705
- * @param password Input password
706
- */
707
- isValidPassword(password: string): boolean;
708
-
709
- /**
710
- * Navigate to Url or delta
711
- * @param url Url or delta
712
- * @param options Options
713
- */
714
- navigate<T extends number | string | URL>(
715
- to: T,
716
- options?: T extends number ? never : NavigateOptions
717
- ): void;
718
-
719
- /**
720
- * Notify user with success message
721
- * @param message Success message
722
- * @param callback Popup close callback
723
- */
724
- ok(
725
- callback?: NotificationReturn<void>,
726
- message?: NotificationContent<unknown>
727
- ): void;
728
-
729
- /**
730
- * Callback where exit a page
731
- */
732
- pageExit(): void;
733
-
734
- /**
735
- * Refresh token with result
736
- * @param props Props
737
- * @param callback Callback
738
- * @param api API
739
- */
740
- refreshToken(
741
- props?: RefreshTokenProps,
742
- callback?: (result?: boolean | IActionResult) => boolean | void
743
- ): Promise<void>;
744
-
745
- /**
746
- * Setup Api error handler
747
- * @param api Api
748
- * @param handlerFor401 Handler for 401 error
749
- */
750
- setApiErrorHandler(
751
- api: IApi,
752
- handlerFor401?: boolean | (() => Promise<void>)
753
- ): void;
754
-
755
- /**
756
- * Setup Api loading
757
- * @param api Api
758
- */
759
- setApiLoading(api: IApi): void;
760
-
761
- /**
762
- * Setup frontend logging
763
- * @param action Custom action
764
- * @param preventDefault Is prevent default action
765
- */
766
- setupLogging(
767
- action?: (data: ErrorData) => void | Promise<void>,
768
- preventDefault?: ((type: ErrorType) => boolean) | boolean
769
- ): void;
770
-
771
- /**
772
- * Signout, with userLogout and toLoginPage
773
- * @param action Callback
774
- */
775
- signout(action?: () => void | boolean): Promise<void>;
776
-
777
- /**
778
- * Persist settings to source when application exit
779
- */
780
- persist(): void;
781
-
782
- /**
783
- * Go to the login page
784
- * @param data Login parameters
785
- */
786
- toLoginPage(data?: AppLoginParams): void;
787
-
788
- /**
789
- * Try login, returning false means is loading
790
- * UI get involved while refreshToken not intended
791
- * @param data Login parameters
792
- */
793
- tryLogin(data?: AppLoginParams): Promise<boolean>;
794
-
795
- /**
796
- * Update API token and expires
797
- * @param name Api name
798
- * @param token Refresh token
799
- * @param seconds Access token expires in seconds
800
- */
801
- updateApi(name: string, token: string | undefined, seconds: number): void;
802
-
803
- /**
804
- * Update embedded status
805
- * @param embedded New embedded status
806
- */
807
- updateEmbedded(embedded?: boolean): void;
808
-
809
- /**
810
- * User login
811
- * @param user User data
812
- * @param refreshToken Refresh token
813
- */
814
- userLogin(user: IUser, refreshToken: string): void;
815
-
816
- /**
817
- * User logout
818
- * @param clearToken Clear refresh token or not
819
- * @param noTrigger No trigger for state change
820
- */
821
- userLogout(clearToken: boolean, noTrigger?: boolean): void;
822
-
823
- /**
824
- * User unauthorized
825
- */
826
- userUnauthorized(): void;
827
-
828
- /**
829
- * Show warning message
830
- * @param message Message
831
- * @param align Align, default as TopRight
832
- */
833
- warning(
834
- message: NotificationContent<unknown>,
835
- align?: NotificationAlign
836
- ): void;
155
+ /**
156
+ * Settings
157
+ */
158
+ readonly settings: IAppSettings;
159
+
160
+ /**
161
+ * Default region
162
+ */
163
+ readonly defaultRegion: AddressRegion;
164
+
165
+ /**
166
+ * Fields
167
+ */
168
+ readonly fields: IAppFields;
169
+
170
+ /**
171
+ * API, not recommend to use it directly in code, wrap to separate methods
172
+ */
173
+ readonly api: IApi;
174
+
175
+ /**
176
+ * Notifier
177
+ */
178
+ readonly notifier: INotifier<unknown, NotificationCallProps>;
179
+
180
+ /**
181
+ * Label delegate
182
+ */
183
+ readonly labelDelegate: <T = string>(key: string) => T | undefined;
184
+
185
+ /**
186
+ * Culture, like zh-CN
187
+ */
188
+ readonly culture: string;
189
+
190
+ /**
191
+ * Currency, like USD for US dollar
192
+ */
193
+ readonly currency: Currency;
194
+
195
+ /**
196
+ * Device id
197
+ */
198
+ readonly deviceId: string;
199
+
200
+ /**
201
+ * Country or region, like CN
202
+ */
203
+ readonly region: string;
204
+
205
+ /**
206
+ * Storage
207
+ */
208
+ readonly storage: IStorage;
209
+
210
+ /**
211
+ * Is current authorized
212
+ */
213
+ readonly authorized: boolean;
214
+
215
+ /**
216
+ * Is the app ready
217
+ */
218
+ readonly isReady: boolean;
219
+
220
+ /**
221
+ * Is trying to login
222
+ */
223
+ readonly isTryingLogin: boolean;
224
+
225
+ /**
226
+ * Application name
227
+ */
228
+ readonly name: string;
229
+
230
+ /**
231
+ * Pending actions
232
+ */
233
+ readonly pendings: (() => any)[];
234
+
235
+ /**
236
+ * Is debug mode
237
+ */
238
+ readonly debug: boolean;
239
+
240
+ /**
241
+ * Is embedded mode
242
+ */
243
+ readonly embedded: boolean;
244
+
245
+ /**
246
+ * Cached URL
247
+ */
248
+ cachedUrl: string | undefined | null;
249
+
250
+ /**
251
+ * Keep login or not
252
+ */
253
+ keepLogin: boolean;
254
+
255
+ /**
256
+ * IP data
257
+ */
258
+ ipData?: IPData;
259
+
260
+ /**
261
+ * User data
262
+ */
263
+ userData?: IUser;
264
+
265
+ /**
266
+ * Search input element
267
+ */
268
+ searchInput?: HTMLInputElement;
269
+
270
+ /**
271
+ * Is screen size down 'sm'
272
+ */
273
+ smDown?: boolean;
274
+
275
+ /**
276
+ * Is screen size up 'md'
277
+ */
278
+ mdUp?: boolean;
279
+
280
+ /**
281
+ * Add root (homepage) to the URL
282
+ * @param url URL to add
283
+ * @returns Result
284
+ */
285
+ addRootUrl(url: string): string;
286
+
287
+ /**
288
+ * Add scheduled task
289
+ * @param task Task, return false to stop
290
+ * @param interval Interval in milliseconds
291
+ */
292
+ addTask(task: () => PromiseLike<void | false>, interval: number): void;
293
+
294
+ /**
295
+ * Alert result
296
+ * @param result Result message
297
+ * @param callback Callback
298
+ */
299
+ alertResult(result: string, callback?: NotificationReturn<void>): void;
300
+
301
+ /**
302
+ * Alert action result
303
+ * @param result Action result
304
+ * @param callback Callback
305
+ * @param forceToLocal Force to local labels
306
+ */
307
+ alertResult(
308
+ result: IActionResult,
309
+ callback?: NotificationReturn<void>,
310
+ forceToLocal?: FormatResultCustomCallback
311
+ ): void;
312
+
313
+ /**
314
+ * Authorize
315
+ * @param token New access token
316
+ * @param schema Access token schema
317
+ * @param refreshToken Refresh token
318
+ */
319
+ authorize(token?: string, schema?: string, refreshToken?: string): void;
320
+
321
+ /**
322
+ * Change country or region
323
+ * @param region New country or region
324
+ */
325
+ changeRegion(region: string | AddressRegion): void;
326
+
327
+ /**
328
+ * Change culture
329
+ * @param culture New culture definition
330
+ */
331
+ changeCulture(
332
+ culture: DataTypes.CultureDefinition
333
+ ): Promise<DataTypes.StringRecord>;
334
+
335
+ /**
336
+ * Check the action result is about device invalid
337
+ * @param result Action result
338
+ * @returns true means device is invalid
339
+ */
340
+ checkDeviceResult(result: IActionResult): boolean;
341
+
342
+ /**
343
+ * Check language is supported or not
344
+ * @param language Language
345
+ * @returns Result
346
+ */
347
+ checkLanguage(language?: string): string;
348
+
349
+ /**
350
+ * Clear cache data
351
+ */
352
+ clearCacheData(): void;
353
+
354
+ /**
355
+ * Clear cached token
356
+ */
357
+ clearCacheToken(): void;
358
+
359
+ /**
360
+ * Clear device id
361
+ */
362
+ clearDeviceId(): void;
363
+
364
+ /**
365
+ * Create API client, override to implement custom client creation by name
366
+ * @param name Client name
367
+ * @param item External endpoint item
368
+ * @returns Result
369
+ */
370
+ createApi(
371
+ name: string,
372
+ item: ExternalEndpoint,
373
+ refresh?: (
374
+ api: IApi,
375
+ rq: ApiRefreshTokenRQ
376
+ ) => Promise<[string, number] | undefined>
377
+ ): IApi;
378
+
379
+ /**
380
+ * Decrypt message
381
+ * @param messageEncrypted Encrypted message
382
+ * @param passphrase Secret passphrase
383
+ * @returns Pure text
384
+ */
385
+ decrypt(messageEncrypted: string, passphrase?: string): string | undefined;
386
+
387
+ /**
388
+ * Enhanced decrypt message
389
+ * @param messageEncrypted Encrypted message
390
+ * @param passphrase Secret passphrase
391
+ * @param durationSeconds Duration seconds, <= 12 will be considered as month
392
+ * @returns Pure text
393
+ */
394
+ decryptEnhanced(
395
+ messageEncrypted: string,
396
+ passphrase?: string,
397
+ durationSeconds?: number
398
+ ): string | undefined;
399
+
400
+ /**
401
+ * Detect IP data, call only one time
402
+ * @param callback Callback will be called when the IP is ready
403
+ */
404
+ detectIP(callback?: IDetectIPCallback): void;
405
+
406
+ /**
407
+ * Dispose the application
408
+ */
409
+ dispose(): void;
410
+
411
+ /**
412
+ * Download file
413
+ * @param stream File stream
414
+ * @param filename File name
415
+ * @param callback callback
416
+ */
417
+ download(
418
+ stream: ReadableStream,
419
+ filename?: string,
420
+ callback?: (success: boolean | undefined) => void
421
+ ): Promise<void>;
422
+
423
+ /**
424
+ * Encrypt message
425
+ * @param message Message
426
+ * @param passphrase Secret passphrase
427
+ * @param iterations Iterations, 1000 times, 1 - 99
428
+ * @returns Result
429
+ */
430
+ encrypt(message: string, passphrase?: string, iterations?: number): string;
431
+
432
+ /**
433
+ * Enhanced encrypt message
434
+ * @param message Message
435
+ * @param passphrase Secret passphrase
436
+ * @param iterations Iterations, 1000 times, 1 - 99
437
+ * @returns Result
438
+ */
439
+ encryptEnhanced(
440
+ message: string,
441
+ passphrase?: string,
442
+ iterations?: number
443
+ ): string;
444
+
445
+ /**
446
+ * Exchange token data
447
+ * @param api API
448
+ * @param token Core system's refresh token to exchange
449
+ * @returns Result
450
+ */
451
+ exchangeToken(api: IApi, token: string): Promise<void>;
452
+
453
+ /**
454
+ * Exchange intergration tokens for all APIs
455
+ * @param coreData Core system's token data to exchange
456
+ * @param coreName Core system's name, default is 'core'
457
+ */
458
+ exchangeTokenAll(coreData: ApiRefreshTokenDto, coreName?: string): void;
459
+
460
+ /**
461
+ * Format date to string
462
+ * @param input Input date
463
+ * @param options Options
464
+ * @param timeZone Time zone
465
+ * @returns string
466
+ */
467
+ formatDate(
468
+ input?: Date | string,
469
+ options?: DateUtils.FormatOptions,
470
+ timeZone?: string
471
+ ): string | undefined;
472
+
473
+ /**
474
+ * Format action
475
+ * @param action Action
476
+ * @param target Target name or title
477
+ * @param items More items
478
+ * @returns Result
479
+ */
480
+ formatAction(action: string, target: string, ...items: string[]): string;
481
+
482
+ /**
483
+ * Format error
484
+ * @param error Error
485
+ * @returns Error message
486
+ */
487
+ formatError(error: ApiDataError): string;
488
+
489
+ /**
490
+ * Format money number
491
+ * @param input Input money number
492
+ * @param isInteger Is integer
493
+ * @param options Options
494
+ * @returns Result
495
+ */
496
+ formatMoney(
497
+ input: number | bigint,
498
+ isInteger?: boolean,
499
+ options?: Intl.NumberFormatOptions
500
+ ): string;
501
+
502
+ /**
503
+ * Format number
504
+ * @param input Input number
505
+ * @param options Options
506
+ * @returns Result
507
+ */
508
+ formatNumber(
509
+ input: number | bigint,
510
+ options?: Intl.NumberFormatOptions
511
+ ): string;
512
+
513
+ /**
514
+ * Format as full name
515
+ * @param familyName Family name
516
+ * @param givenName Given name
517
+ */
518
+ formatFullName(
519
+ familyName: string | undefined | null,
520
+ givenName: string | undefined | null
521
+ ): string;
522
+
523
+ /**
524
+ * Format result text
525
+ * @param result Action result
526
+ * @param forceToLocal Force to local labels
527
+ * @returns Message
528
+ */
529
+ formatResult(
530
+ result: IActionResult,
531
+ forceToLocal?: FormatResultCustomCallback
532
+ ): string;
533
+
534
+ /**
535
+ * Fresh countdown UI
536
+ * @param callback Callback
537
+ */
538
+ freshCountdownUI(callback?: () => PromiseLike<unknown>): void;
539
+
540
+ /**
541
+ * Get culture resource
542
+ * @param key key
543
+ * @returns Resource
544
+ */
545
+ get<T = string>(key: string): T | undefined;
546
+
547
+ /**
548
+ * Get multiple culture labels
549
+ * @param keys Keys
550
+ */
551
+ getLabels<T extends string>(...keys: T[]): { [K in T]: string };
552
+
553
+ /**
554
+ * Get bool items
555
+ * @returns Bool items
556
+ */
557
+ getBools(): ListType1[];
558
+
559
+ /**
560
+ * Get cached token
561
+ * @returns Cached token
562
+ */
563
+ getCacheToken(): string | undefined;
564
+
565
+ /**
566
+ * Get data privacies
567
+ * @returns Result
568
+ */
569
+ getDataPrivacies(): ListType[];
570
+
571
+ /**
572
+ * Get enum item number id list
573
+ * @param em Enum
574
+ * @param prefix Label prefix or callback
575
+ * @param filter Filter
576
+ * @returns List
577
+ */
578
+ getEnumList<E extends DataTypes.EnumBase = DataTypes.EnumBase>(
579
+ em: E,
580
+ prefix: string | ((key: string) => string),
581
+ filter?: (id: E[keyof E], key: keyof E & string) => E[keyof E] | undefined
582
+ ): ListType[];
583
+
584
+ /**
585
+ * Get enum item string id list
586
+ * @param em Enum
587
+ * @param prefix Label prefix or callback
588
+ * @param filter Filter
589
+ * @returns List
590
+ */
591
+ getEnumStrList<E extends DataTypes.EnumBase = DataTypes.EnumBase>(
592
+ em: E,
593
+ prefix: string | ((key: string) => string),
594
+ filter?:
595
+ | ((id: E[keyof E], key: keyof E & string) => E[keyof E] | undefined)
596
+ | E[keyof E][]
597
+ ): ListType1[];
598
+
599
+ /**
600
+ * Get region label
601
+ * @param id Region id
602
+ * @returns Label
603
+ */
604
+ getRegionLabel(id: string): string;
605
+
606
+ /**
607
+ * Get all regions
608
+ * @returns Regions
609
+ */
610
+ getRegions(): AddressRegion[];
611
+
612
+ /**
613
+ * Get roles
614
+ * @param role Combination role value
615
+ */
616
+ getRoles(role: number): ListType[];
617
+
618
+ /**
619
+ * Get status label
620
+ * @param status Status value
621
+ */
622
+ getStatusLabel(status: number | null | undefined): string;
623
+
624
+ /**
625
+ * Get status list
626
+ * @param ids Limited ids
627
+ * @returns list
628
+ */
629
+ getStatusList(ids?: EntityStatus[]): ListType[];
630
+
631
+ /**
632
+ * Get refresh token from response headers
633
+ * @param rawResponse Raw response from API call
634
+ * @param tokenKey Refresh token key
635
+ * @returns response refresh token
636
+ */
637
+ getResponseToken(rawResponse: any, tokenKey: string): string | null;
638
+
639
+ /**
640
+ * Get time zone
641
+ * @returns Time zone
642
+ */
643
+ getTimeZone(): string | undefined;
644
+
645
+ /**
646
+ * Hash message, SHA3 or HmacSHA512, 512 as Base64
647
+ * https://cryptojs.gitbook.io/docs/
648
+ * @param message Message
649
+ * @param passphrase Secret passphrase
650
+ */
651
+ hash(message: string, passphrase?: string): string;
652
+
653
+ /**
654
+ * Hash message Hex, SHA3 or HmacSHA512, 512 as Base64
655
+ * https://cryptojs.gitbook.io/docs/
656
+ * @param message Message
657
+ * @param passphrase Secret passphrase
658
+ */
659
+ hashHex(message: string, passphrase?: string): string;
660
+
661
+ /**
662
+ * Check use has the specific role permission or not
663
+ * @param roles Roles to check
664
+ * @returns Result
665
+ */
666
+ hasPermission(roles: number | UserRole | number[] | UserRole[]): boolean;
667
+
668
+ /**
669
+ * Init call
670
+ * @param callback Callback
671
+ * @param resetKeys Reset all keys first
672
+ * @returns Result
673
+ */
674
+ initCall(
675
+ callback?: (result: boolean) => void,
676
+ resetKeys?: boolean
677
+ ): Promise<void>;
678
+
679
+ /**
680
+ * Is admin user
681
+ * @returns Result
682
+ */
683
+ isAdminUser(): boolean;
684
+
685
+ /**
686
+ * Is Finance user
687
+ * @returns Result
688
+ */
689
+ isFinanceUser(): boolean;
690
+
691
+ /**
692
+ * Is HR user
693
+ * @returns Result
694
+ */
695
+ isHRUser(): boolean;
696
+
697
+ /**
698
+ * Is valid password, override to implement custom check
699
+ * @param password Input password
700
+ */
701
+ isValidPassword(password: string): boolean;
702
+
703
+ /**
704
+ * Navigate to Url or delta
705
+ * @param url Url or delta
706
+ * @param options Options
707
+ */
708
+ navigate<T extends number | string | URL>(
709
+ to: T,
710
+ options?: T extends number ? never : NavigateOptions
711
+ ): void;
712
+
713
+ /**
714
+ * Notify user with success message
715
+ * @param message Success message
716
+ * @param callback Popup close callback
717
+ */
718
+ ok(
719
+ callback?: NotificationReturn<void>,
720
+ message?: NotificationContent<unknown>
721
+ ): void;
722
+
723
+ /**
724
+ * Callback where exit a page
725
+ */
726
+ pageExit(): void;
727
+
728
+ /**
729
+ * Refresh token with result
730
+ * @param props Props
731
+ * @param callback Callback
732
+ * @param api API
733
+ */
734
+ refreshToken(
735
+ props?: RefreshTokenProps,
736
+ callback?: (result?: boolean | IActionResult) => boolean | void
737
+ ): Promise<void>;
738
+
739
+ /**
740
+ * Setup Api error handler
741
+ * @param api Api
742
+ * @param handlerFor401 Handler for 401 error
743
+ */
744
+ setApiErrorHandler(
745
+ api: IApi,
746
+ handlerFor401?: boolean | (() => Promise<void>)
747
+ ): void;
748
+
749
+ /**
750
+ * Setup Api loading
751
+ * @param api Api
752
+ */
753
+ setApiLoading(api: IApi): void;
754
+
755
+ /**
756
+ * Setup frontend logging
757
+ * @param action Custom action
758
+ * @param preventDefault Is prevent default action
759
+ */
760
+ setupLogging(
761
+ action?: (data: ErrorData) => void | Promise<void>,
762
+ preventDefault?: ((type: ErrorType) => boolean) | boolean
763
+ ): void;
764
+
765
+ /**
766
+ * Signout, with userLogout and toLoginPage
767
+ * @param action Callback
768
+ */
769
+ signout(action?: () => void | boolean): Promise<void>;
770
+
771
+ /**
772
+ * Persist settings to source when application exit
773
+ */
774
+ persist(): void;
775
+
776
+ /**
777
+ * Go to the login page
778
+ * @param data Login parameters
779
+ */
780
+ toLoginPage(data?: AppLoginParams): void;
781
+
782
+ /**
783
+ * Try login, returning false means is loading
784
+ * UI get involved while refreshToken not intended
785
+ * @param data Login parameters
786
+ */
787
+ tryLogin(data?: AppLoginParams): Promise<boolean>;
788
+
789
+ /**
790
+ * Update API token and expires
791
+ * @param name Api name
792
+ * @param token Refresh token
793
+ * @param seconds Access token expires in seconds
794
+ */
795
+ updateApi(name: string, token: string | undefined, seconds: number): void;
796
+
797
+ /**
798
+ * Update embedded status
799
+ * @param embedded New embedded status
800
+ */
801
+ updateEmbedded(embedded?: boolean): void;
802
+
803
+ /**
804
+ * User login
805
+ * @param user User data
806
+ * @param refreshToken Refresh token
807
+ */
808
+ userLogin(user: IUser, refreshToken: string): void;
809
+
810
+ /**
811
+ * User logout
812
+ * @param clearToken Clear refresh token or not
813
+ * @param noTrigger No trigger for state change
814
+ */
815
+ userLogout(clearToken: boolean, noTrigger?: boolean): void;
816
+
817
+ /**
818
+ * User unauthorized
819
+ */
820
+ userUnauthorized(): void;
821
+
822
+ /**
823
+ * Show warning message
824
+ * @param message Message
825
+ * @param align Align, default as TopRight
826
+ */
827
+ warning(
828
+ message: NotificationContent<unknown>,
829
+ align?: NotificationAlign
830
+ ): void;
837
831
  }