@etsoo/appscript 1.2.47 → 1.2.51

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.
@@ -43,6 +43,16 @@ export interface RefreshTokenProps<D extends {}> {
43
43
  */
44
44
  showLoading?: boolean;
45
45
  }
46
+ /**
47
+ * App fields
48
+ */
49
+ declare const appFields: readonly ["headerToken", "serversideDeviceId", "deviceId", "devices", "devicePassphrase"];
50
+ /**
51
+ * Basic type template
52
+ */
53
+ export declare type IAppFields = {
54
+ [key in typeof appFields[number]]: string;
55
+ };
46
56
  /**
47
57
  * Core application interface
48
58
  */
@@ -51,6 +61,10 @@ export interface ICoreApp<S extends IAppSettings, N, C extends NotificationCallP
51
61
  * Settings
52
62
  */
53
63
  readonly settings: S;
64
+ /**
65
+ * Fields
66
+ */
67
+ readonly fields: IAppFields;
54
68
  /**
55
69
  * API
56
70
  */
@@ -371,6 +385,10 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
371
385
  * Settings
372
386
  */
373
387
  readonly settings: S;
388
+ /**
389
+ * Fields
390
+ */
391
+ readonly fields: IAppFields;
374
392
  /**
375
393
  * API
376
394
  */
@@ -467,6 +485,12 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
467
485
  protected constructor(settings: S, api: IApi, notifier: INotifier<N, C>, storage: IStorage, name: string);
468
486
  private getDeviceId;
469
487
  private resetKeys;
488
+ /**
489
+ * Add app name as identifier
490
+ * @param field Field
491
+ * @returns Result
492
+ */
493
+ protected addIdentifier(field: string): string;
470
494
  /**
471
495
  * Restore settings from persisted source
472
496
  */
@@ -475,12 +499,6 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
475
499
  * Persist settings to source when application exit
476
500
  */
477
501
  persist(): void;
478
- /**
479
- * Add app name as identifier
480
- * @param field Field
481
- * @returns Result
482
- */
483
- protected addIdentifier(field: string): string;
484
502
  /**
485
503
  * Setup Api
486
504
  * @param api Api
@@ -753,8 +771,9 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
753
771
  * Try login, returning false means is loading
754
772
  * UI get involved while refreshToken not intended
755
773
  * @param data Additional request data
774
+ * @param showLoading Show loading bar or not during call
756
775
  */
757
- tryLogin<D extends {} = {}>(_data?: D): Promise<boolean>;
776
+ tryLogin<D extends {} = {}>(_data?: D, _showLoading?: boolean): Promise<boolean>;
758
777
  /**
759
778
  * User login
760
779
  * @param user User data
@@ -779,25 +798,4 @@ export declare abstract class CoreApp<S extends IAppSettings, N, C extends Notif
779
798
  */
780
799
  warning(message: NotificationContent<N>, align?: NotificationAlign): void;
781
800
  }
782
- export declare namespace CoreApp {
783
- /**
784
- * Response token header field name
785
- */
786
- const headerTokenField = "SmartERPRefreshToken";
787
- /**
788
- * Serverside device id encrypted field name
789
- */
790
- const serversideDeviceIdField = "SmartERPServersideDeviceId";
791
- /**
792
- * Device id field name
793
- */
794
- const deviceIdField = "SmartERPDeviceId";
795
- /**
796
- * Devices field name
797
- */
798
- const devicesField = "SmartERPDevices";
799
- /**
800
- * Device passphrase field name
801
- */
802
- const devicePassphraseField = "SmartERPDevicePassphrase";
803
- }
801
+ export {};
@@ -6,6 +6,16 @@ import { AddressRegion } from '../address/AddressRegion';
6
6
  import { AddressUtils } from '../address/AddressUtils';
7
7
  import { BusinessUtils } from '../business/BusinessUtils';
8
8
  import { ActionResultError } from '../result/ActionResultError';
9
+ /**
10
+ * App fields
11
+ */
12
+ const appFields = [
13
+ 'headerToken',
14
+ 'serversideDeviceId',
15
+ 'deviceId',
16
+ 'devices',
17
+ 'devicePassphrase'
18
+ ];
9
19
  /**
10
20
  * Core application
11
21
  */
@@ -42,8 +52,10 @@ export class CoreApp {
42
52
  this.notifier = notifier;
43
53
  this.storage = storage;
44
54
  this.name = name;
55
+ // Fields, attach with the name identifier
56
+ this.fields = appFields.reduce((a, v) => ({ ...a, [v]: 'smarterp-' + v + '-' + name }), {});
45
57
  // Device id
46
- this._deviceId = storage.getData(this.addIdentifier(CoreApp.deviceIdField), '');
58
+ this._deviceId = storage.getData(this.fields.deviceId, '');
47
59
  // Restore
48
60
  this.restore();
49
61
  this.setApi(api);
@@ -115,10 +127,10 @@ export class CoreApp {
115
127
  */
116
128
  get persistedFields() {
117
129
  return [
118
- this.addIdentifier(CoreApp.deviceIdField),
119
- this.addIdentifier(CoreApp.devicePassphraseField),
120
- this.addIdentifier(CoreApp.serversideDeviceIdField),
121
- this.addIdentifier(CoreApp.headerTokenField)
130
+ this.fields.deviceId,
131
+ this.fields.devicePassphrase,
132
+ this.fields.serversideDeviceId,
133
+ this.fields.headerToken
122
134
  ];
123
135
  }
124
136
  getDeviceId() {
@@ -126,23 +138,31 @@ export class CoreApp {
126
138
  }
127
139
  resetKeys() {
128
140
  this.storage.clear([
129
- this.addIdentifier(CoreApp.devicePassphraseField),
130
- this.addIdentifier(CoreApp.headerTokenField),
131
- this.addIdentifier(CoreApp.serversideDeviceIdField)
141
+ this.fields.devicePassphrase,
142
+ this.fields.headerToken,
143
+ this.fields.serversideDeviceId
132
144
  ], false);
133
145
  this.passphrase = '';
134
146
  }
147
+ /**
148
+ * Add app name as identifier
149
+ * @param field Field
150
+ * @returns Result
151
+ */
152
+ addIdentifier(field) {
153
+ return field + '-' + this.name;
154
+ }
135
155
  /**
136
156
  * Restore settings from persisted source
137
157
  */
138
158
  restore() {
139
159
  // Devices
140
- const devices = this.storage.getPersistedData(CoreApp.devicesField, []);
160
+ const devices = this.storage.getPersistedData(this.fields.devices, []);
141
161
  if (this.deviceId === '') {
142
162
  // First vist, restore and keep the source
143
163
  this.storage.copyFrom(this.persistedFields, false);
144
164
  // Reset device id
145
- this._deviceId = this.storage.getData(this.addIdentifier(CoreApp.deviceIdField), '');
165
+ this._deviceId = this.storage.getData(this.fields.deviceId, '');
146
166
  // Totally new, no data restored
147
167
  if (this._deviceId === '')
148
168
  return false;
@@ -156,13 +176,13 @@ export class CoreApp {
156
176
  return false;
157
177
  }
158
178
  // this.name to identifier different app's secret
159
- const passphraseEncrypted = this.storage.getData(this.addIdentifier(CoreApp.devicePassphraseField));
179
+ const passphraseEncrypted = this.storage.getData(this.fields.devicePassphrase);
160
180
  if (passphraseEncrypted) {
161
181
  const passphraseDecrypted = this.decrypt(passphraseEncrypted, this.name);
162
182
  if (passphraseDecrypted != null) {
163
183
  // Add the device to the list
164
184
  devices.push(d);
165
- this.storage.setPersistedData(CoreApp.devicesField, devices);
185
+ this.storage.setPersistedData(this.fields.devices, devices);
166
186
  this.passphrase = passphraseDecrypted;
167
187
  return true;
168
188
  }
@@ -176,27 +196,19 @@ export class CoreApp {
176
196
  */
177
197
  persist() {
178
198
  // Devices
179
- const devices = this.storage.getPersistedData(CoreApp.devicesField);
199
+ const devices = this.storage.getPersistedData(this.fields.devices);
180
200
  if (devices != null) {
181
201
  const index = devices.indexOf(this.getDeviceId());
182
202
  if (index !== -1) {
183
203
  // Remove current device from the list
184
204
  devices.splice(index, 1);
185
- this.storage.setPersistedData(CoreApp.devicesField, devices);
205
+ this.storage.setPersistedData(this.fields.devices, devices);
186
206
  }
187
207
  }
188
208
  if (!this.authorized)
189
209
  return;
190
210
  this.storage.copyTo(this.persistedFields);
191
211
  }
192
- /**
193
- * Add app name as identifier
194
- * @param field Field
195
- * @returns Result
196
- */
197
- addIdentifier(field) {
198
- return field + '-' + this.name;
199
- }
200
212
  /**
201
213
  * Setup Api
202
214
  * @param api Api
@@ -253,7 +265,7 @@ export class CoreApp {
253
265
  return;
254
266
  }
255
267
  // Serverside encrypted device id
256
- const identifier = this.storage.getData(this.addIdentifier(CoreApp.serversideDeviceIdField));
268
+ const identifier = this.storage.getData(this.fields.serversideDeviceId);
257
269
  // Timestamp
258
270
  const timestamp = new Date().getTime();
259
271
  // Request data
@@ -289,7 +301,7 @@ export class CoreApp {
289
301
  if (callback)
290
302
  callback(false);
291
303
  // Clear device id
292
- this.storage.setData(this.addIdentifier(CoreApp.deviceIdField), undefined);
304
+ this.storage.setData(this.fields.deviceId, undefined);
293
305
  return;
294
306
  }
295
307
  this.initCallUpdate(result.data, data.timestamp);
@@ -312,14 +324,14 @@ export class CoreApp {
312
324
  return;
313
325
  // Update device id and cache it
314
326
  this._deviceId = data.deviceId;
315
- this.storage.setData(this.addIdentifier(CoreApp.deviceIdField), this._deviceId);
327
+ this.storage.setData(this.fields.deviceId, this._deviceId);
316
328
  // Devices
317
- const devices = this.storage.getPersistedData(CoreApp.devicesField, []);
329
+ const devices = this.storage.getPersistedData(this.fields.devices, []);
318
330
  devices.push(this.getDeviceId());
319
- this.storage.setPersistedData(CoreApp.devicesField, devices);
331
+ this.storage.setPersistedData(this.fields.devices, devices);
320
332
  // Current passphrase
321
333
  this.passphrase = passphrase;
322
- this.storage.setData(this.addIdentifier(CoreApp.devicePassphraseField), this.encrypt(passphrase, this.name));
334
+ this.storage.setData(this.fields.devicePassphrase, this.encrypt(passphrase, this.name));
323
335
  // Previous passphrase
324
336
  if (data.previousPassphrase) {
325
337
  const prev = this.decrypt(data.previousPassphrase, timestamp.toString());
@@ -351,7 +363,7 @@ export class CoreApp {
351
363
  * @returns Fields
352
364
  */
353
365
  initCallEncryptedUpdateFields() {
354
- return [this.addIdentifier(CoreApp.headerTokenField)];
366
+ return [this.fields.headerToken];
355
367
  }
356
368
  /**
357
369
  * Alert action result
@@ -376,7 +388,7 @@ export class CoreApp {
376
388
  if (refreshToken !== '') {
377
389
  if (refreshToken != null)
378
390
  refreshToken = this.encrypt(refreshToken);
379
- this.storage.setData(this.addIdentifier(CoreApp.headerTokenField), refreshToken);
391
+ this.storage.setData(this.fields.headerToken, refreshToken);
380
392
  }
381
393
  // Reset tryLogin state
382
394
  this._isTryingLogin = false;
@@ -449,14 +461,14 @@ export class CoreApp {
449
461
  */
450
462
  clearCacheData() {
451
463
  this.clearCacheToken();
452
- this.storage.setData(this.addIdentifier(CoreApp.devicePassphraseField), undefined);
464
+ this.storage.setData(this.fields.devicePassphrase, undefined);
453
465
  }
454
466
  /**
455
467
  * Clear cached token
456
468
  */
457
469
  clearCacheToken() {
458
470
  this.cachedRefreshToken = undefined;
459
- this.storage.setPersistedData(this.addIdentifier(CoreApp.headerTokenField), undefined);
471
+ this.storage.setPersistedData(this.fields.headerToken, undefined);
460
472
  }
461
473
  /**
462
474
  * Decrypt message
@@ -711,7 +723,7 @@ export class CoreApp {
711
723
  // Temp refresh token
712
724
  if (this.cachedRefreshToken)
713
725
  return this.cachedRefreshToken;
714
- return this.storage.getData(this.addIdentifier(CoreApp.headerTokenField));
726
+ return this.storage.getData(this.fields.headerToken);
715
727
  }
716
728
  /**
717
729
  * Get all regions
@@ -738,7 +750,7 @@ export class CoreApp {
738
750
  */
739
751
  getResponseToken(rawResponse) {
740
752
  const response = this.api.transformResponse(rawResponse);
741
- return this.api.getHeaderValue(response.headers, CoreApp.headerTokenField);
753
+ return this.api.getHeaderValue(response.headers, 'SmartERPRefreshToken');
742
754
  }
743
755
  /**
744
756
  * Get time zone
@@ -941,8 +953,9 @@ export class CoreApp {
941
953
  * Try login, returning false means is loading
942
954
  * UI get involved while refreshToken not intended
943
955
  * @param data Additional request data
956
+ * @param showLoading Show loading bar or not during call
944
957
  */
945
- async tryLogin(_data) {
958
+ async tryLogin(_data, _showLoading) {
946
959
  if (this._isTryingLogin)
947
960
  return false;
948
961
  this._isTryingLogin = true;
@@ -957,7 +970,7 @@ export class CoreApp {
957
970
  userLogin(user, refreshToken, keep) {
958
971
  this.userData = user;
959
972
  // Cache the encrypted serverside device id
960
- this.storage.setData(this.addIdentifier(CoreApp.serversideDeviceIdField), user.deviceId);
973
+ this.storage.setData(this.fields.serversideDeviceId, user.deviceId);
961
974
  if (keep) {
962
975
  this.authorize(user.token, refreshToken);
963
976
  }
@@ -994,25 +1007,3 @@ export class CoreApp {
994
1007
  });
995
1008
  }
996
1009
  }
997
- (function (CoreApp) {
998
- /**
999
- * Response token header field name
1000
- */
1001
- CoreApp.headerTokenField = 'SmartERPRefreshToken';
1002
- /**
1003
- * Serverside device id encrypted field name
1004
- */
1005
- CoreApp.serversideDeviceIdField = 'SmartERPServersideDeviceId';
1006
- /**
1007
- * Device id field name
1008
- */
1009
- CoreApp.deviceIdField = 'SmartERPDeviceId';
1010
- /**
1011
- * Devices field name
1012
- */
1013
- CoreApp.devicesField = 'SmartERPDevices';
1014
- /**
1015
- * Device passphrase field name
1016
- */
1017
- CoreApp.devicePassphraseField = 'SmartERPDevicePassphrase';
1018
- })(CoreApp || (CoreApp = {}));
@@ -3,11 +3,6 @@ import { IBridgeHost } from './IBridgeHost';
3
3
  * Bridge utils
4
4
  */
5
5
  export declare namespace BridgeUtils {
6
- /**
7
- * Is electron client
8
- * @returns Result
9
- */
10
- function isElectronClient(): boolean;
11
6
  /**
12
7
  * Bridge host
13
8
  */
@@ -1,38 +1,17 @@
1
+ import { FlutterHost } from './FlutterHost';
1
2
  /**
2
3
  * Bridge utils
3
4
  */
4
5
  export var BridgeUtils;
5
6
  (function (BridgeUtils) {
6
- /**
7
- * Is electron client
8
- * @returns Result
9
- */
10
- function isElectronClient() {
11
- // Renderer process
12
- if (typeof window !== 'undefined' &&
13
- typeof window.process === 'object' &&
14
- window.process.type === 'renderer') {
15
- return true;
16
- }
17
- // Main process
18
- if (typeof process !== 'undefined' &&
19
- typeof process.versions === 'object' &&
20
- !!process.versions.electron) {
21
- return true;
22
- }
23
- // Detect the user agent when the `nodeIntegration` option is set to true
24
- if (typeof navigator === 'object' &&
25
- typeof navigator.userAgent === 'string' &&
26
- navigator.userAgent.indexOf('Electron') >= 0) {
27
- return true;
28
- }
29
- return false;
30
- }
31
- BridgeUtils.isElectronClient = isElectronClient;
7
+ var _a;
8
+ const g = globalThis;
32
9
  /**
33
10
  * Bridge host
34
11
  */
35
- BridgeUtils.host = isElectronClient()
36
- ? globalThis.electron
37
- : undefined;
12
+ BridgeUtils.host = typeof ((_a = g.flutter_inappwebview) === null || _a === void 0 ? void 0 : _a.callHandler) === 'function'
13
+ ? new FlutterHost(g.flutter_inappwebview.callHandler)
14
+ : typeof g.electron === 'object'
15
+ ? g.electron
16
+ : undefined;
38
17
  })(BridgeUtils || (BridgeUtils = {}));
@@ -0,0 +1,21 @@
1
+ import { IBridgeHost } from './IBridgeHost';
2
+ /**
3
+ * Flutter JavaScript Host
4
+ * https://inappwebview.dev/docs/javascript/communication/
5
+ */
6
+ export declare class FlutterHost implements IBridgeHost {
7
+ callHandler: (name: string, ...args: unknown[]) => PromiseLike<{} | void>;
8
+ /**
9
+ * Start Url
10
+ */
11
+ private startUrl;
12
+ /**
13
+ * Constructor
14
+ * @param callHandler Call handler
15
+ */
16
+ constructor(callHandler: (name: string, ...args: unknown[]) => PromiseLike<{} | void>);
17
+ changeCulture(locale: string): void;
18
+ exit(): void;
19
+ getStartUrl(): string | null | undefined;
20
+ loadApp(name: string, startUrl?: string): void;
21
+ }
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Flutter JavaScript Host
3
+ * https://inappwebview.dev/docs/javascript/communication/
4
+ */
5
+ export class FlutterHost {
6
+ /**
7
+ * Constructor
8
+ * @param callHandler Call handler
9
+ */
10
+ constructor(callHandler) {
11
+ this.callHandler = callHandler;
12
+ }
13
+ changeCulture(locale) {
14
+ this.callHandler('changeCulture', locale);
15
+ }
16
+ exit() {
17
+ this.callHandler('exit');
18
+ }
19
+ getStartUrl() {
20
+ return this.startUrl;
21
+ }
22
+ loadApp(name, startUrl) {
23
+ this.startUrl = startUrl;
24
+ this.callHandler('loadApp', name, startUrl);
25
+ }
26
+ }
@@ -11,10 +11,14 @@ export interface IBridgeHost {
11
11
  * Exit the application
12
12
  */
13
13
  exit(): void;
14
+ /**
15
+ * Get app start Url / router Url
16
+ */
17
+ getStartUrl(): string | undefined | null;
14
18
  /**
15
19
  * Load application
16
20
  * @param name App name
17
- * @param startUrl Start Url
21
+ * @param startUrl Start Url / router Url
18
22
  */
19
23
  loadApp(name: string, startUrl?: string): void;
20
24
  }
@@ -1,3 +1,4 @@
1
+ import { DataTypes } from '@etsoo/shared';
1
2
  import { IdLabelDto } from '../dto/IdLabelDto';
2
3
  import { ICultureGet } from '../state/Culture';
3
4
  import { EntityStatus } from './EntityStatus';
@@ -31,6 +32,13 @@ export declare namespace BusinessUtils {
31
32
  id: EntityStatus;
32
33
  label: string;
33
34
  }[];
35
+ /**
36
+ * Get 12-month items
37
+ * @param monthLabels Month labels
38
+ * @param startMonth Start month, 0 as Jan.
39
+ * @returns 12 months
40
+ */
41
+ function getMonths(monthLabels: string[], startMonth?: number): DataTypes.IdLabelItem[];
34
42
  /**
35
43
  * Get product unit's label
36
44
  * Please define the label in culture with key 'unitPC' for ProductUnit.PC like that
@@ -52,6 +52,23 @@ export var BusinessUtils;
52
52
  });
53
53
  }
54
54
  BusinessUtils.getEntityStatus = getEntityStatus;
55
+ /**
56
+ * Get 12-month items
57
+ * @param monthLabels Month labels
58
+ * @param startMonth Start month, 0 as Jan.
59
+ * @returns 12 months
60
+ */
61
+ function getMonths(monthLabels, startMonth = 0) {
62
+ const months = [];
63
+ for (let i = 0; i < 12; i++) {
64
+ if (startMonth >= 12)
65
+ startMonth = 0;
66
+ months.push({ id: startMonth, label: monthLabels[startMonth] });
67
+ startMonth++;
68
+ }
69
+ return months;
70
+ }
71
+ BusinessUtils.getMonths = getMonths;
55
72
  /**
56
73
  * Get product unit's label
57
74
  * Please define the label in culture with key 'unitPC' for ProductUnit.PC like that
@@ -50,6 +50,20 @@
50
50
  "message": "Message",
51
51
  "mobile": "Mobile number",
52
52
  "mobilePhones": "Mobile numbers",
53
+ "months": [
54
+ "Jan.",
55
+ "Feb.",
56
+ "Mar.",
57
+ "Apr.",
58
+ "May.",
59
+ "Jun.",
60
+ "Jul.",
61
+ "Aug.",
62
+ "Sep.",
63
+ "Oct.",
64
+ "Nov.",
65
+ "Dec."
66
+ ],
53
67
  "more": "More",
54
68
  "moreTag": "{0} more",
55
69
  "name": "Name",
@@ -67,6 +81,7 @@
67
81
  "pageNotFound": "Page Not Found",
68
82
  "prompt": "Input",
69
83
  "pullToRefresh": "Pull down to refresh",
84
+ "quarters": ["Q1", "Q2", "Q3", "Q4"],
70
85
  "record": "Record",
71
86
  "refresh": "Refresh",
72
87
  "refreshing": "Refreshing",
@@ -50,6 +50,20 @@
50
50
  "message": "留言",
51
51
  "mobile": "手机号码",
52
52
  "mobilePhones": "手机号码",
53
+ "months": [
54
+ "1月",
55
+ "2月",
56
+ "3月",
57
+ "4月",
58
+ "5月",
59
+ "6月",
60
+ "7月",
61
+ "8月",
62
+ "9月",
63
+ "10月",
64
+ "11月",
65
+ "12月"
66
+ ],
53
67
  "more": "更多",
54
68
  "moreTag": "({0}+)",
55
69
  "name": "姓名",
@@ -67,6 +81,7 @@
67
81
  "pageNotFound": "找不到页面",
68
82
  "prompt": "输入",
69
83
  "pullToRefresh": "下拉刷新",
84
+ "quarters": ["一季度", "二季度", "三季度", "四季度"],
70
85
  "record": "记录",
71
86
  "refresh": "刷新",
72
87
  "refreshing": "正在刷新",
@@ -50,6 +50,20 @@
50
50
  "message": "留言",
51
51
  "mobilePhone": "手機號碼",
52
52
  "mobilePhones": "手機號碼",
53
+ "months": [
54
+ "1月",
55
+ "2月",
56
+ "3月",
57
+ "4月",
58
+ "5月",
59
+ "6月",
60
+ "7月",
61
+ "8月",
62
+ "9月",
63
+ "10月",
64
+ "11月",
65
+ "12月"
66
+ ],
53
67
  "more": "更多",
54
68
  "moreTag": "({0}+)",
55
69
  "name": "姓名",
@@ -67,6 +81,7 @@
67
81
  "pageNotFound": "找不到頁面",
68
82
  "prompt": "輸入",
69
83
  "pullToRefresh": "下拉刷新",
84
+ "quarters": ["一季度", "二季度", "三季度", "四季度"],
70
85
  "record": "記錄",
71
86
  "refresh": "刷新",
72
87
  "refreshing": "正在刷新",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/appscript",
3
- "version": "1.2.47",
3
+ "version": "1.2.51",
4
4
  "description": "Applications shared TypeScript framework",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/mjs/index.js",