@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.
@@ -8,401 +8,24 @@ import { IActionResult } from '../result/IActionResult';
8
8
  import { InitCallResult, InitCallResultData } from '../result/InitCallResult';
9
9
  import { IUser } from '../state/User';
10
10
  import { IAppSettings } from './AppSettings';
11
+ import { IApp, IAppFields, IDetectIPCallback, RefreshTokenProps, RefreshTokenResult } from './IApp';
11
12
  import { UserRole } from './UserRole';
12
- /**
13
- * Detect IP callback interface
14
- */
15
- export interface IDetectIPCallback {
16
- (): void;
17
- }
18
- /**
19
- * Refresh token result type
20
- * true means success, false means failed but no any message
21
- * other cases means failed with differnet message
22
- */
23
- export declare type RefreshTokenResult = boolean | string | ApiDataError | IActionResult;
24
- /**
25
- * Refresh token props
26
- */
27
- export interface RefreshTokenProps<D extends object> {
28
- /**
29
- * Callback
30
- */
31
- callback?: (result: RefreshTokenResult, successData?: string) => void;
32
- /**
33
- * Data to pass
34
- */
35
- data?: D;
36
- /**
37
- * Support relogin or not
38
- */
39
- relogin?: boolean;
40
- /**
41
- * Show loading bar or not
42
- */
43
- showLoading?: boolean;
44
- }
45
- /**
46
- * App fields
47
- */
48
- declare const appFields: readonly ["headerToken", "serversideDeviceId", "deviceId", "devices", "devicePassphrase"];
49
- /**
50
- * Basic type template
51
- */
52
- export declare type IAppFields = {
53
- [key in typeof appFields[number]]: string;
54
- };
55
13
  /**
56
14
  * Core application interface
57
15
  */
58
- export interface ICoreApp<U extends IUser, S extends IAppSettings, N, C extends NotificationCallProps> {
16
+ export interface ICoreApp<U extends IUser, S extends IAppSettings, N, C extends NotificationCallProps> extends IApp {
59
17
  /**
60
18
  * Settings
61
19
  */
62
20
  readonly settings: S;
63
- /**
64
- * Fields
65
- */
66
- readonly fields: IAppFields;
67
- /**
68
- * API
69
- */
70
- readonly api: IApi;
71
21
  /**
72
22
  * Notifier
73
23
  */
74
24
  readonly notifier: INotifier<N, C>;
75
- /**
76
- * Label delegate
77
- */
78
- readonly labelDelegate: <T = string>(key: string) => T | undefined;
79
- /**
80
- * Culture, like zh-CN
81
- */
82
- readonly culture: string;
83
- /**
84
- * Currency, like USD for US dollar
85
- */
86
- readonly currency: string;
87
- /**
88
- * Device id
89
- */
90
- readonly deviceId: string;
91
- /**
92
- * Country or region, like CN
93
- */
94
- readonly region: string;
95
- /**
96
- * Storage
97
- */
98
- readonly storage: IStorage;
99
- /**
100
- * Is current authorized
101
- */
102
- readonly authorized: boolean;
103
- /**
104
- * Application name
105
- */
106
- readonly name: string;
107
- /**
108
- * IP data
109
- */
110
- ipData?: IPData;
111
25
  /**
112
26
  * User data
113
27
  */
114
28
  userData?: U;
115
- /**
116
- * Search input element
117
- */
118
- searchInput?: HTMLInputElement;
119
- /**
120
- * Alert action result
121
- * @param result Action result
122
- * @param callback Callback
123
- */
124
- alertResult(result: IActionResult, callback?: NotificationReturn<void>): void;
125
- /**
126
- * Authorize
127
- * @param token New token
128
- * @param refreshToken Refresh token
129
- */
130
- authorize(token?: string, refreshToken?: string): void;
131
- /**
132
- * Change country or region
133
- * @param region New country or region
134
- */
135
- changeRegion(region: string | AddressRegion): void;
136
- /**
137
- * Change culture
138
- * @param culture New culture definition
139
- */
140
- changeCulture(culture: DataTypes.CultureDefinition): void;
141
- /**
142
- * Check the action result is about device invalid
143
- * @param result Action result
144
- * @returns true means device is invalid
145
- */
146
- checkDeviceResult(result: IActionResult): boolean;
147
- /**
148
- * Clear cache data
149
- */
150
- clearCacheData(): void;
151
- /**
152
- * Clear cached token
153
- */
154
- clearCacheToken(): void;
155
- /**
156
- * Decrypt message
157
- * @param messageEncrypted Encrypted message
158
- * @param passphrase Secret passphrase
159
- * @returns Pure text
160
- */
161
- decrypt(messageEncrypted: string, passphrase?: string): string | undefined;
162
- /**
163
- * Enhanced decrypt message
164
- * @param messageEncrypted Encrypted message
165
- * @param passphrase Secret passphrase
166
- * @param durationSeconds Duration seconds, <= 12 will be considered as month
167
- * @returns Pure text
168
- */
169
- decryptEnhanced(messageEncrypted: string, passphrase?: string, durationSeconds?: number): string | undefined;
170
- /**
171
- * Detect IP data, call only one time
172
- * @param callback Callback will be called when the IP is ready
173
- */
174
- detectIP(callback?: IDetectIPCallback): void;
175
- /**
176
- * Encrypt message
177
- * @param message Message
178
- * @param passphrase Secret passphrase
179
- * @param iterations Iterations, 1000 times, 1 - 99
180
- * @returns Result
181
- */
182
- encrypt(message: string, passphrase?: string, iterations?: number): string;
183
- /**
184
- * Enhanced encrypt message
185
- * @param message Message
186
- * @param passphrase Secret passphrase
187
- * @param iterations Iterations, 1000 times, 1 - 99
188
- * @returns Result
189
- */
190
- encryptEnhanced(message: string, passphrase?: string, iterations?: number): string;
191
- /**
192
- * Format date to string
193
- * @param input Input date
194
- * @param options Options
195
- * @param timeZone Time zone
196
- * @returns string
197
- */
198
- formatDate(input?: Date | string, options?: DateUtils.FormatOptions, timeZone?: string): string | undefined;
199
- /**
200
- * Format error
201
- * @param error Error
202
- * @returns Error message
203
- */
204
- formatError(error: ApiDataError): string;
205
- /**
206
- * Format money number
207
- * @param input Input money number
208
- * @param isInteger Is integer
209
- * @param options Options
210
- * @returns Result
211
- */
212
- formatMoney(input?: number | bigint, isInteger?: boolean, options?: Intl.NumberFormatOptions): string | undefined;
213
- /**
214
- * Format number
215
- * @param input Input number
216
- * @param options Options
217
- * @returns Result
218
- */
219
- formatNumber(input?: number | bigint, options?: Intl.NumberFormatOptions): string | undefined;
220
- /**
221
- * Do refresh token result
222
- * @param result Result
223
- * @param initCallCallback InitCall callback
224
- * @param silent Silent without any popups
225
- */
226
- doRefreshTokenResult(result: RefreshTokenResult, initCallCallback?: (result: boolean) => void, silent?: boolean): void;
227
- /**
228
- * Format refresh token result
229
- * @param result Refresh token result
230
- * @returns Message
231
- */
232
- formatRefreshTokenResult(result: RefreshTokenResult): string | undefined;
233
- /**
234
- * Format result text
235
- * @param result Action result
236
- * @param forceToLocal Force to local labels
237
- * @returns Message
238
- */
239
- formatResult(result: IActionResult, forceToLocal?: boolean): string;
240
- /**
241
- * Fresh countdown UI
242
- * @param callback Callback
243
- */
244
- freshCountdownUI(callback?: () => PromiseLike<unknown>): void;
245
- /**
246
- * Get culture resource
247
- * @param key key
248
- * @returns Resource
249
- */
250
- get<T = string>(key: string): T | undefined;
251
- /**
252
- * Get multiple culture labels
253
- * @param keys Keys
254
- */
255
- getLabels<T extends string>(...keys: T[]): {
256
- [K in T]: string;
257
- };
258
- /**
259
- * Get cached token
260
- * @returns Cached token
261
- */
262
- getCacheToken(): string | undefined;
263
- /**
264
- * Get all regions
265
- * @returns Regions
266
- */
267
- getRegions(): AddressRegion[];
268
- /**
269
- * Get roles
270
- * @param role Combination role value
271
- */
272
- getRoles(role: number): ListType[];
273
- /**
274
- * Get status label
275
- * @param status Status value
276
- */
277
- getStatusLabel(status: number | null | undefined): string;
278
- /**
279
- * Get status list
280
- * @returns list
281
- */
282
- getStatusList(): ListType[];
283
- /**
284
- * Get refresh token from response headers
285
- * @param rawResponse Raw response from API call
286
- * @returns response refresh token
287
- */
288
- getResponseToken(rawResponse: any): string | null;
289
- /**
290
- * Get time zone
291
- * @returns Time zone
292
- */
293
- getTimeZone(): string | undefined;
294
- /**
295
- * Get product unit and repeat option label
296
- * @param unit Product unit or repeat option
297
- * @param isJoined Add the join label like 'per Kg' for Kg
298
- */
299
- getUnitLabel(unit?: ProductUnit, isJoined?: boolean): string;
300
- /**
301
- * Hash message, SHA3 or HmacSHA512, 512 as Base64
302
- * https://cryptojs.gitbook.io/docs/
303
- * @param message Message
304
- * @param passphrase Secret passphrase
305
- */
306
- hash(message: string, passphrase?: string): string;
307
- /**
308
- * Hash message Hex, SHA3 or HmacSHA512, 512 as Base64
309
- * https://cryptojs.gitbook.io/docs/
310
- * @param message Message
311
- * @param passphrase Secret passphrase
312
- */
313
- hashHex(message: string, passphrase?: string): string;
314
- /**
315
- * Check use has the specific role permission or not
316
- * @param roles Roles to check
317
- * @returns Result
318
- */
319
- hasPermission(roles: number | UserRole | number[] | UserRole[]): boolean;
320
- /**
321
- * Init call
322
- * @param callback Callback
323
- * @param resetKeys Reset all keys first
324
- * @returns Result
325
- */
326
- initCall(callback?: (result: boolean) => void, resetKeys?: boolean): Promise<void>;
327
- /**
328
- * Is valid password, override to implement custom check
329
- * @param password Input password
330
- */
331
- isValidPassword(password: string): boolean;
332
- /**
333
- * Callback where exit a page
334
- */
335
- pageExit(): void;
336
- /**
337
- * Refresh token
338
- * @param props Props
339
- */
340
- refreshToken<D extends object = {}>(props?: RefreshTokenProps<D>): Promise<boolean>;
341
- /**
342
- * Signout
343
- */
344
- signout(): Promise<void>;
345
- /**
346
- * Get organization list
347
- * @param items Max items
348
- * @param serviceId Service id
349
- * @returns Result
350
- */
351
- orgList(items?: number, serviceId?: number): Promise<ListType[] | undefined>;
352
- /**
353
- * Persist settings to source when application exit
354
- */
355
- persist(): void;
356
- /**
357
- * Redirect to the Url
358
- * @param url Url
359
- */
360
- redirectTo(url: string): void;
361
- /**
362
- * Switch organization
363
- * @param id Organization id
364
- * @param serviceId Service id
365
- */
366
- switchOrg(id: number, serviceId?: number): Promise<boolean | undefined>;
367
- /**
368
- * Go to the login page
369
- * @param tryLogin Try to login again
370
- */
371
- toLoginPage(tryLogin?: boolean): void;
372
- /**
373
- * Transform URL
374
- * @param url URL
375
- * @returns Transformed url
376
- */
377
- transformUrl(url: string): string;
378
- /**
379
- * Try login, returning false means is loading
380
- * UI get involved while refreshToken not intended
381
- * @param data Additional request data
382
- */
383
- tryLogin<D extends object = {}>(data?: D): Promise<boolean>;
384
- /**
385
- * User login
386
- * @param user User data
387
- * @param refreshToken Refresh token
388
- * @param keep Keep login or not
389
- */
390
- userLogin(user: U, refreshToken: string, keep?: boolean): void;
391
- /**
392
- * User logout
393
- * @param clearToken Clear refresh token or not
394
- */
395
- userLogout(clearToken: boolean): void;
396
- /**
397
- * User unauthorized
398
- */
399
- userUnauthorized(): void;
400
- /**
401
- * Show warning message
402
- * @param message Message
403
- * @param align Align, default as TopRight
404
- */
405
- warning(message: NotificationContent<N>, align?: NotificationAlign): void;
406
29
  }
407
30
  /**
408
31
  * Core application
@@ -872,4 +495,3 @@ export declare abstract class CoreApp<U extends IUser, S extends IAppSettings, N
872
495
  */
873
496
  warning(message: NotificationContent<N>, align?: NotificationAlign): void;
874
497
  }
875
- export {};
@@ -11,17 +11,8 @@ const BridgeUtils_1 = require("../bridges/BridgeUtils");
11
11
  const BusinessUtils_1 = require("../business/BusinessUtils");
12
12
  const EntityStatus_1 = require("../business/EntityStatus");
13
13
  const ActionResultError_1 = require("../result/ActionResultError");
14
+ const IApp_1 = require("./IApp");
14
15
  const UserRole_1 = require("./UserRole");
15
- /**
16
- * App fields
17
- */
18
- const appFields = [
19
- 'headerToken',
20
- 'serversideDeviceId',
21
- 'deviceId',
22
- 'devices',
23
- 'devicePassphrase'
24
- ];
25
16
  /**
26
17
  * Core application
27
18
  */
@@ -59,7 +50,7 @@ class CoreApp {
59
50
  this.storage = storage;
60
51
  this.name = name;
61
52
  // Fields, attach with the name identifier
62
- this.fields = appFields.reduce((a, v) => ({ ...a, [v]: 'smarterp-' + v + '-' + name }), {});
53
+ this.fields = IApp_1.appFields.reduce((a, v) => ({ ...a, [v]: 'smarterp-' + v + '-' + name }), {});
63
54
  // Device id
64
55
  this._deviceId = storage.getData(this.fields.deviceId, '');
65
56
  // Restore