@etsoo/appscript 1.2.85 → 1.2.86

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,404 @@
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
+ * Alert action result
119
+ * @param result Action result
120
+ * @param callback Callback
121
+ */
122
+ alertResult(result: IActionResult, callback?: NotificationReturn<void>): void;
123
+ /**
124
+ * Authorize
125
+ * @param token New token
126
+ * @param refreshToken Refresh token
127
+ */
128
+ authorize(token?: string, refreshToken?: string): void;
129
+ /**
130
+ * Change country or region
131
+ * @param region New country or region
132
+ */
133
+ changeRegion(region: string | AddressRegion): void;
134
+ /**
135
+ * Change culture
136
+ * @param culture New culture definition
137
+ */
138
+ changeCulture(culture: DataTypes.CultureDefinition): void;
139
+ /**
140
+ * Check the action result is about device invalid
141
+ * @param result Action result
142
+ * @returns true means device is invalid
143
+ */
144
+ checkDeviceResult(result: IActionResult): boolean;
145
+ /**
146
+ * Clear cache data
147
+ */
148
+ clearCacheData(): void;
149
+ /**
150
+ * Clear cached token
151
+ */
152
+ clearCacheToken(): void;
153
+ /**
154
+ * Decrypt message
155
+ * @param messageEncrypted Encrypted message
156
+ * @param passphrase Secret passphrase
157
+ * @returns Pure text
158
+ */
159
+ decrypt(messageEncrypted: string, passphrase?: string): string | undefined;
160
+ /**
161
+ * Enhanced decrypt message
162
+ * @param messageEncrypted Encrypted message
163
+ * @param passphrase Secret passphrase
164
+ * @param durationSeconds Duration seconds, <= 12 will be considered as month
165
+ * @returns Pure text
166
+ */
167
+ decryptEnhanced(messageEncrypted: string, passphrase?: string, durationSeconds?: number): string | undefined;
168
+ /**
169
+ * Detect IP data, call only one time
170
+ * @param callback Callback will be called when the IP is ready
171
+ */
172
+ detectIP(callback?: IDetectIPCallback): void;
173
+ /**
174
+ * Encrypt message
175
+ * @param message Message
176
+ * @param passphrase Secret passphrase
177
+ * @param iterations Iterations, 1000 times, 1 - 99
178
+ * @returns Result
179
+ */
180
+ encrypt(message: string, passphrase?: string, iterations?: number): string;
181
+ /**
182
+ * Enhanced encrypt message
183
+ * @param message Message
184
+ * @param passphrase Secret passphrase
185
+ * @param iterations Iterations, 1000 times, 1 - 99
186
+ * @returns Result
187
+ */
188
+ encryptEnhanced(message: string, passphrase?: string, iterations?: number): string;
189
+ /**
190
+ * Format date to string
191
+ * @param input Input date
192
+ * @param options Options
193
+ * @param timeZone Time zone
194
+ * @returns string
195
+ */
196
+ formatDate(input?: Date | string, options?: DateUtils.FormatOptions, timeZone?: string): string | undefined;
197
+ /**
198
+ * Format error
199
+ * @param error Error
200
+ * @returns Error message
201
+ */
202
+ formatError(error: ApiDataError): string;
203
+ /**
204
+ * Format money number
205
+ * @param input Input money number
206
+ * @param isInteger Is integer
207
+ * @param options Options
208
+ * @returns Result
209
+ */
210
+ formatMoney(input?: number | bigint, isInteger?: boolean, options?: Intl.NumberFormatOptions): string | undefined;
211
+ /**
212
+ * Format number
213
+ * @param input Input number
214
+ * @param options Options
215
+ * @returns Result
216
+ */
217
+ formatNumber(input?: number | bigint, options?: Intl.NumberFormatOptions): string | undefined;
218
+ /**
219
+ * Do refresh token result
220
+ * @param result Result
221
+ * @param initCallCallback InitCall callback
222
+ * @param silent Silent without any popups
223
+ */
224
+ doRefreshTokenResult(result: RefreshTokenResult, initCallCallback?: (result: boolean) => void, silent?: boolean): void;
225
+ /**
226
+ * Format refresh token result
227
+ * @param result Refresh token result
228
+ * @returns Message
229
+ */
230
+ formatRefreshTokenResult(result: RefreshTokenResult): string | undefined;
231
+ /**
232
+ * Format result text
233
+ * @param result Action result
234
+ * @param forceToLocal Force to local labels
235
+ * @returns Message
236
+ */
237
+ formatResult(result: IActionResult, forceToLocal?: boolean): string;
238
+ /**
239
+ * Fresh countdown UI
240
+ * @param callback Callback
241
+ */
242
+ freshCountdownUI(callback?: () => PromiseLike<unknown>): void;
243
+ /**
244
+ * Get culture resource
245
+ * @param key key
246
+ * @returns Resource
247
+ */
248
+ get<T = string>(key: string): T | undefined;
249
+ /**
250
+ * Get multiple culture labels
251
+ * @param keys Keys
252
+ */
253
+ getLabels<T extends string>(...keys: T[]): {
254
+ [K in T]: string;
255
+ };
256
+ /**
257
+ * Get cached token
258
+ * @returns Cached token
259
+ */
260
+ getCacheToken(): string | undefined;
261
+ /**
262
+ * Get all regions
263
+ * @returns Regions
264
+ */
265
+ getRegions(): AddressRegion[];
266
+ /**
267
+ * Get roles
268
+ * @param role Combination role value
269
+ */
270
+ getRoles(role: number): ListType[];
271
+ /**
272
+ * Get status label
273
+ * @param status Status value
274
+ */
275
+ getStatusLabel(status: number | null | undefined): string;
276
+ /**
277
+ * Get status list
278
+ * @returns list
279
+ */
280
+ getStatusList(): ListType[];
281
+ /**
282
+ * Get refresh token from response headers
283
+ * @param rawResponse Raw response from API call
284
+ * @returns response refresh token
285
+ */
286
+ getResponseToken(rawResponse: any): string | null;
287
+ /**
288
+ * Get time zone
289
+ * @returns Time zone
290
+ */
291
+ getTimeZone(): string | undefined;
292
+ /**
293
+ * Get product unit and repeat option label
294
+ * @param unit Product unit or repeat option
295
+ * @param isJoined Add the join label like 'per Kg' for Kg
296
+ */
297
+ getUnitLabel(unit?: ProductUnit, isJoined?: boolean): string;
298
+ /**
299
+ * Hash message, SHA3 or HmacSHA512, 512 as Base64
300
+ * https://cryptojs.gitbook.io/docs/
301
+ * @param message Message
302
+ * @param passphrase Secret passphrase
303
+ */
304
+ hash(message: string, passphrase?: string): string;
305
+ /**
306
+ * Hash message Hex, SHA3 or HmacSHA512, 512 as Base64
307
+ * https://cryptojs.gitbook.io/docs/
308
+ * @param message Message
309
+ * @param passphrase Secret passphrase
310
+ */
311
+ hashHex(message: string, passphrase?: string): string;
312
+ /**
313
+ * Check use has the specific role permission or not
314
+ * @param roles Roles to check
315
+ * @returns Result
316
+ */
317
+ hasPermission(roles: number | UserRole | number[] | UserRole[]): boolean;
318
+ /**
319
+ * Init call
320
+ * @param callback Callback
321
+ * @param resetKeys Reset all keys first
322
+ * @returns Result
323
+ */
324
+ initCall(callback?: (result: boolean) => void, resetKeys?: boolean): Promise<void>;
325
+ /**
326
+ * Is valid password, override to implement custom check
327
+ * @param password Input password
328
+ */
329
+ isValidPassword(password: string): boolean;
330
+ /**
331
+ * Callback where exit a page
332
+ */
333
+ pageExit(): void;
334
+ /**
335
+ * Refresh token
336
+ * @param props Props
337
+ */
338
+ refreshToken<D extends object = {}>(props?: RefreshTokenProps<D>): Promise<boolean>;
339
+ /**
340
+ * Signout
341
+ */
342
+ signout(): Promise<void>;
343
+ /**
344
+ * Get organization list
345
+ * @param items Max items
346
+ * @param serviceId Service id
347
+ * @returns Result
348
+ */
349
+ orgList(items?: number, serviceId?: number): Promise<ListType[] | undefined>;
350
+ /**
351
+ * Persist settings to source when application exit
352
+ */
353
+ persist(): void;
354
+ /**
355
+ * Redirect to the Url
356
+ * @param url Url
357
+ */
358
+ redirectTo(url: string): void;
359
+ /**
360
+ * Switch organization
361
+ * @param id Organization id
362
+ * @param serviceId Service id
363
+ */
364
+ switchOrg(id: number, serviceId?: number): Promise<boolean | undefined>;
365
+ /**
366
+ * Go to the login page
367
+ * @param tryLogin Try to login again
368
+ */
369
+ toLoginPage(tryLogin?: boolean): void;
370
+ /**
371
+ * Transform URL
372
+ * @param url URL
373
+ * @returns Transformed url
374
+ */
375
+ transformUrl(url: string): string;
376
+ /**
377
+ * Try login, returning false means is loading
378
+ * UI get involved while refreshToken not intended
379
+ * @param data Additional request data
380
+ */
381
+ tryLogin<D extends object = {}>(data?: D): Promise<boolean>;
382
+ /**
383
+ * User login
384
+ * @param user User data
385
+ * @param refreshToken Refresh token
386
+ * @param keep Keep login or not
387
+ */
388
+ userLogin(user: IUser, refreshToken: string, keep?: boolean): void;
389
+ /**
390
+ * User logout
391
+ * @param clearToken Clear refresh token or not
392
+ */
393
+ userLogout(clearToken: boolean): void;
394
+ /**
395
+ * User unauthorized
396
+ */
397
+ userUnauthorized(): void;
398
+ /**
399
+ * Show warning message
400
+ * @param message Message
401
+ * @param align Align, default as TopRight
402
+ */
403
+ warning(message: NotificationContent<unknown>, align?: NotificationAlign): void;
404
+ }
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.appFields = void 0;
4
+ /**
5
+ * App fields
6
+ */
7
+ exports.appFields = [
8
+ 'headerToken',
9
+ 'serversideDeviceId',
10
+ 'deviceId',
11
+ 'devices',
12
+ 'devicePassphrase'
13
+ ];