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