@etsoo/appscript 1.3.33 → 1.3.34

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.
Files changed (94) hide show
  1. package/__tests__/app/CoreApp.ts +27 -4
  2. package/lib/cjs/address/AddressContinent.d.ts +1 -1
  3. package/lib/cjs/address/AddressRegion.d.ts +7 -1
  4. package/lib/cjs/address/AddressRegion.js +21 -20
  5. package/lib/cjs/address/AddressState.d.ts +1 -1
  6. package/lib/cjs/app/CoreApp.js +45 -45
  7. package/lib/cjs/app/IApp.d.ts +2 -2
  8. package/lib/cjs/bridges/FlutterHost.d.ts +2 -1
  9. package/lib/cjs/bridges/FlutterHost.js +1 -0
  10. package/lib/cjs/bridges/IBridgeHost.d.ts +5 -0
  11. package/lib/cjs/business/BusinessTax.js +6 -6
  12. package/lib/cjs/business/Currency.d.ts +1 -1
  13. package/lib/cjs/business/ProductUnit.d.ts +1 -1
  14. package/lib/cjs/def/ListItem.d.ts +1 -1
  15. package/lib/cjs/erp/AddressApi.d.ts +16 -2
  16. package/lib/cjs/erp/AddressApi.js +43 -12
  17. package/lib/cjs/erp/BaseApi.js +6 -6
  18. package/lib/cjs/erp/dto/AuditLineDto.d.ts +3 -3
  19. package/lib/cjs/erp/dto/CurrencyDto.d.ts +1 -1
  20. package/lib/cjs/erp/dto/ExchangeRateDto.d.ts +1 -1
  21. package/lib/cjs/erp/dto/ExchangeRateHistoryDto.d.ts +1 -1
  22. package/lib/cjs/erp/dto/IdLabelDto.d.ts +1 -1
  23. package/lib/cjs/erp/dto/IdLabelPrimaryDto.d.ts +1 -1
  24. package/lib/cjs/erp/dto/InitCallDto.d.ts +1 -1
  25. package/lib/cjs/erp/dto/OrgDto.d.ts +1 -1
  26. package/lib/cjs/erp/dto/OrgQueryDto.d.ts +1 -1
  27. package/lib/cjs/erp/dto/PublicProductDto.d.ts +2 -2
  28. package/lib/cjs/erp/dto/ResultPayload.d.ts +3 -3
  29. package/lib/cjs/erp/rq/MemberListRQ.d.ts +1 -1
  30. package/lib/cjs/erp/rq/OrgListRQ.d.ts +1 -1
  31. package/lib/cjs/erp/rq/OrgQueryRQ.d.ts +1 -1
  32. package/lib/cjs/erp/rq/QueryRQ.d.ts +1 -1
  33. package/lib/cjs/erp/rq/RefreshTokenRQ.d.ts +1 -1
  34. package/lib/cjs/erp/rq/RegionsRQ.d.ts +14 -0
  35. package/lib/cjs/erp/rq/RegionsRQ.js +2 -0
  36. package/lib/cjs/erp/rq/TiplistRQ.d.ts +1 -1
  37. package/lib/cjs/i18n/en-US.json +1 -0
  38. package/lib/cjs/i18n/zh-CN.json +1 -0
  39. package/lib/cjs/i18n/zh-HK.json +1 -0
  40. package/lib/cjs/result/ActionResultError.js +12 -12
  41. package/lib/cjs/result/IActionResult.d.ts +2 -2
  42. package/lib/cjs/result/InitCallResult.d.ts +1 -1
  43. package/lib/cjs/state/User.d.ts +1 -1
  44. package/lib/mjs/address/AddressContinent.d.ts +1 -1
  45. package/lib/mjs/address/AddressRegion.d.ts +7 -1
  46. package/lib/mjs/address/AddressRegion.js +21 -20
  47. package/lib/mjs/address/AddressState.d.ts +1 -1
  48. package/lib/mjs/app/CoreApp.js +45 -45
  49. package/lib/mjs/app/IApp.d.ts +2 -2
  50. package/lib/mjs/bridges/FlutterHost.d.ts +2 -1
  51. package/lib/mjs/bridges/FlutterHost.js +1 -0
  52. package/lib/mjs/bridges/IBridgeHost.d.ts +5 -0
  53. package/lib/mjs/business/BusinessTax.js +6 -6
  54. package/lib/mjs/business/Currency.d.ts +1 -1
  55. package/lib/mjs/business/ProductUnit.d.ts +1 -1
  56. package/lib/mjs/def/ListItem.d.ts +1 -1
  57. package/lib/mjs/erp/AddressApi.d.ts +16 -2
  58. package/lib/mjs/erp/AddressApi.js +43 -12
  59. package/lib/mjs/erp/BaseApi.js +6 -6
  60. package/lib/mjs/erp/dto/AuditLineDto.d.ts +3 -3
  61. package/lib/mjs/erp/dto/CurrencyDto.d.ts +1 -1
  62. package/lib/mjs/erp/dto/ExchangeRateDto.d.ts +1 -1
  63. package/lib/mjs/erp/dto/ExchangeRateHistoryDto.d.ts +1 -1
  64. package/lib/mjs/erp/dto/IdLabelDto.d.ts +1 -1
  65. package/lib/mjs/erp/dto/IdLabelPrimaryDto.d.ts +1 -1
  66. package/lib/mjs/erp/dto/InitCallDto.d.ts +1 -1
  67. package/lib/mjs/erp/dto/OrgDto.d.ts +1 -1
  68. package/lib/mjs/erp/dto/OrgQueryDto.d.ts +1 -1
  69. package/lib/mjs/erp/dto/PublicProductDto.d.ts +2 -2
  70. package/lib/mjs/erp/dto/ResultPayload.d.ts +3 -3
  71. package/lib/mjs/erp/rq/MemberListRQ.d.ts +1 -1
  72. package/lib/mjs/erp/rq/OrgListRQ.d.ts +1 -1
  73. package/lib/mjs/erp/rq/OrgQueryRQ.d.ts +1 -1
  74. package/lib/mjs/erp/rq/QueryRQ.d.ts +1 -1
  75. package/lib/mjs/erp/rq/RefreshTokenRQ.d.ts +1 -1
  76. package/lib/mjs/erp/rq/RegionsRQ.d.ts +14 -0
  77. package/lib/mjs/erp/rq/RegionsRQ.js +1 -0
  78. package/lib/mjs/erp/rq/TiplistRQ.d.ts +1 -1
  79. package/lib/mjs/i18n/en-US.json +1 -0
  80. package/lib/mjs/i18n/zh-CN.json +1 -0
  81. package/lib/mjs/i18n/zh-HK.json +1 -0
  82. package/lib/mjs/result/ActionResultError.js +12 -12
  83. package/lib/mjs/result/IActionResult.d.ts +2 -2
  84. package/lib/mjs/result/InitCallResult.d.ts +1 -1
  85. package/lib/mjs/state/User.d.ts +1 -1
  86. package/package.json +8 -8
  87. package/src/address/AddressRegion.ts +29 -10
  88. package/src/bridges/FlutterHost.ts +2 -0
  89. package/src/bridges/IBridgeHost.ts +6 -0
  90. package/src/erp/AddressApi.ts +72 -25
  91. package/src/erp/rq/RegionsRQ.ts +16 -0
  92. package/src/i18n/en-US.json +1 -0
  93. package/src/i18n/zh-CN.json +1 -0
  94. package/src/i18n/zh-HK.json +1 -0
@@ -204,13 +204,36 @@ test('Tests for isValidPassword', () => {
204
204
  expect(app.isValidPassword('1234abcd')).toBeTruthy();
205
205
  });
206
206
 
207
- test('Tests for addressApi', async () => {
208
- const continents = await app.addressApi.continents();
209
- expect(continents.length).toBe(7);
210
-
207
+ test('Tests for addressApi', () => {
211
208
  const regions = app.addressApi.regions();
212
209
  const cn = regions.find((r) => r.id === 'CN');
213
210
  expect(cn?.label).toBe('中国大陆');
211
+
212
+ const favoredRegions = app.addressApi.regions(['US', 'CA']);
213
+ expect(favoredRegions.length).toBe(2);
214
+ expect(favoredRegions.find((region) => region.id === 'US')?.label).toBe(
215
+ '美国'
216
+ );
217
+ });
218
+
219
+ /*
220
+ test('Tests for addressApi Async', async () => {
221
+ const regions = await app.addressApi.getRegions({
222
+ items: 3,
223
+ favoredIds: ['US', 'AU', 'CA', 'NZ']
224
+ });
225
+ expect(regions?.length).toBe(3);
226
+ expect(regions![2].id).toBe('CA');
227
+ });
228
+ */
229
+
230
+ test('Tests for addressApi.continents', () => {
231
+ const continents1 = app.addressApi.continents();
232
+ const continents2 = app.addressApi.continents(true, true);
233
+ expect(continents1.length).toBe(6);
234
+ expect(continents1.some((item) => item.id === 'AN')).toBeFalsy();
235
+ expect(continents2.length).toBe(7);
236
+ expect(continents2[0].id).toBe(1);
214
237
  });
215
238
 
216
239
  test('Tests for publicApi', async () => {
@@ -13,4 +13,4 @@ export declare enum AddressContinent {
13
13
  /**
14
14
  * Address continent ids
15
15
  */
16
- export declare type AddressContinentId = keyof typeof AddressContinent;
16
+ export type AddressContinentId = keyof typeof AddressContinent;
@@ -30,6 +30,11 @@ export interface AddressRegionDb {
30
30
  * 国际拨号的电话退出代码
31
31
  */
32
32
  readonly exitCode: string;
33
+ /**
34
+ * National (truck) prefix
35
+ * 国内呼叫的拨号
36
+ */
37
+ readonly nationalPrefix?: string;
33
38
  /**
34
39
  * Area code for international dial, like 86 for China
35
40
  * 国际电话区号
@@ -71,6 +76,7 @@ export declare class AddressRegion implements IAddressRegion {
71
76
  continent: AddressContinent;
72
77
  exitCode: string;
73
78
  idd: string;
79
+ nationalPrefix: string | undefined;
74
80
  currency: Currency;
75
81
  languages: string[];
76
82
  label: string;
@@ -147,5 +153,5 @@ export declare class AddressRegion implements IAddressRegion {
147
153
  * 洲编号
148
154
  */
149
155
  readonly continentId: AddressContinentId;
150
- constructor(id: string, id3: string, nid: string, continent: AddressContinent, exitCode: string, idd: string, currency: Currency, languages: string[], label?: string);
156
+ constructor(id: string, id3: string, nid: string, continent: AddressContinent, exitCode: string, idd: string, nationalPrefix: string | undefined, currency: Currency, languages: string[], label?: string);
151
157
  }
@@ -6,87 +6,88 @@ const AddressContinent_1 = require("./AddressContinent");
6
6
  * Address or region
7
7
  */
8
8
  class AddressRegion {
9
+ /**
10
+ * Get country or region by id
11
+ * @param id Country id
12
+ */
13
+ static getById(id) {
14
+ return AddressRegion.all.find((c) => c.id === id);
15
+ }
9
16
  // Typescript constructor shorthand
10
- constructor(id, id3, nid, continent, exitCode, idd, currency, languages, label = id) {
17
+ constructor(id, id3, nid, continent, exitCode, idd, nationalPrefix, currency, languages, label = id) {
11
18
  this.id = id;
12
19
  this.id3 = id3;
13
20
  this.nid = nid;
14
21
  this.continent = continent;
15
22
  this.exitCode = exitCode;
16
23
  this.idd = idd;
24
+ this.nationalPrefix = nationalPrefix;
17
25
  this.currency = currency;
18
26
  this.languages = languages;
19
27
  this.label = label;
20
28
  this.continentId = AddressContinent_1.AddressContinent[continent];
21
29
  }
22
- /**
23
- * Get country or region by id
24
- * @param id Country id
25
- */
26
- static getById(id) {
27
- return AddressRegion.all.find((c) => c.id === id);
28
- }
29
30
  }
30
31
  exports.AddressRegion = AddressRegion;
31
32
  /**
32
33
  * CN - China
33
34
  */
34
- AddressRegion.CN = new AddressRegion('CN', 'CHN', '156', AddressContinent_1.AddressContinent.AS, '00', '86', 'CNY', ['zh-CN']);
35
+ AddressRegion.CN = new AddressRegion('CN', 'CHN', '156', AddressContinent_1.AddressContinent.AS, '00', '+86', '0', 'CNY', ['zh-CN']);
35
36
  /**
36
37
  * HK - HK, China
37
38
  * 中国香港
38
39
  */
39
- AddressRegion.HK = new AddressRegion('HK', 'HKG', '344', AddressContinent_1.AddressContinent.AS, '001', '852', 'HKD', ['zh-HK', 'en-HK']);
40
+ AddressRegion.HK = new AddressRegion('HK', 'HKG', '344', AddressContinent_1.AddressContinent.AS, '001', '+852', undefined, 'HKD', ['zh-HK', 'en-HK']);
40
41
  /**
41
42
  * SG - Singapore
42
43
  * 新加坡
43
44
  */
44
- AddressRegion.SG = new AddressRegion('SG', 'SGP', '702', AddressContinent_1.AddressContinent.AS, '000', '65', 'SGD', ['zh-SG', 'en-SG']);
45
+ AddressRegion.SG = new AddressRegion('SG', 'SGP', '702', AddressContinent_1.AddressContinent.AS, '000', '+65', undefined, 'SGD', ['zh-SG', 'en-SG']);
45
46
  /**
46
47
  * JP - Japan
47
48
  * 日本
48
49
  */
49
- AddressRegion.JP = new AddressRegion('JP', 'JPN', '392', AddressContinent_1.AddressContinent.AS, '010', '81', 'JPY', ['ja-JP']);
50
+ AddressRegion.JP = new AddressRegion('JP', 'JPN', '392', AddressContinent_1.AddressContinent.AS, '010', '+81', '0', 'JPY', ['ja-JP']);
50
51
  /**
51
52
  * US - United States
52
53
  * 美国
53
54
  */
54
- AddressRegion.US = new AddressRegion('US', 'USA', '840', AddressContinent_1.AddressContinent.NA, '011', '1', 'USD', ['en-US']);
55
+ AddressRegion.US = new AddressRegion('US', 'USA', '840', AddressContinent_1.AddressContinent.NA, '011', '+1', '1', 'USD', ['en-US']);
55
56
  /**
56
57
  * CA - Canada
57
58
  * 加拿大
58
59
  */
59
- AddressRegion.CA = new AddressRegion('CA', 'CAN', '124', AddressContinent_1.AddressContinent.NA, '011', '1', 'CAD', ['en-CA', 'fr-CA']);
60
+ AddressRegion.CA = new AddressRegion('CA', 'CAN', '124', AddressContinent_1.AddressContinent.NA, '011', '+1', '1', 'CAD', ['en-CA', 'fr-CA']);
60
61
  /**
61
62
  * AU - Australia
62
63
  * 澳大利亚
63
64
  */
64
- AddressRegion.AU = new AddressRegion('AU', 'AUS', '036', AddressContinent_1.AddressContinent.OC, '0011', '61', 'AUD', ['en-AU']);
65
+ AddressRegion.AU = new AddressRegion('AU', 'AUS', '036', AddressContinent_1.AddressContinent.OC, '0011', '+61', '0', 'AUD', ['en-AU']);
65
66
  /**
66
67
  * NZ - New Zealand
67
68
  * 新西兰
68
69
  */
69
- AddressRegion.NZ = new AddressRegion('NZ', 'NZL', '554', AddressContinent_1.AddressContinent.OC, '00', '64', 'NZD', ['en-NZ', 'mi-NZ']);
70
+ AddressRegion.NZ = new AddressRegion('NZ', 'NZL', '554', AddressContinent_1.AddressContinent.OC, '00', '+64', '0', 'NZD', ['en-NZ', 'mi-NZ']);
70
71
  /**
71
72
  * GB - Great Britain
72
73
  * 英国
73
74
  */
74
- AddressRegion.GB = new AddressRegion('GB', 'GBR', '826', AddressContinent_1.AddressContinent.EU, '00', '44', 'GBP', ['en-GB']);
75
+ AddressRegion.GB = new AddressRegion('GB', 'GBR', '826', AddressContinent_1.AddressContinent.EU, '00', '+44', '0', 'GBP', ['en-GB']);
75
76
  /**
76
77
  * IE - Ireland
77
78
  * 爱尔兰
78
79
  */
79
- AddressRegion.IE = new AddressRegion('IE', 'IRL', '372', AddressContinent_1.AddressContinent.EU, '00', '353', 'EUR', ['en-IE']);
80
+ AddressRegion.IE = new AddressRegion('IE', 'IRL', '372', AddressContinent_1.AddressContinent.EU, '00', '+353', '0', 'EUR', ['en-IE']);
80
81
  /**
81
82
  * DE - Germany
82
83
  * 德国
83
84
  */
84
- AddressRegion.DE = new AddressRegion('DE', 'DEU', '276', AddressContinent_1.AddressContinent.EU, '00', '49', 'EUR', ['de-DE']);
85
+ AddressRegion.DE = new AddressRegion('DE', 'DEU', '276', AddressContinent_1.AddressContinent.EU, '00', '+49', '0', 'EUR', ['de-DE']);
85
86
  /**
86
87
  * FR - France
87
88
  * 法国
88
89
  */
89
- AddressRegion.FR = new AddressRegion('FR', 'FRA', '250', AddressContinent_1.AddressContinent.EU, '00', '33', 'EUR', ['fr-FR']);
90
+ AddressRegion.FR = new AddressRegion('FR', 'FRA', '250', AddressContinent_1.AddressContinent.EU, '00', '+33', '0', 'EUR', ['fr-FR']);
90
91
  /**
91
92
  * All countries and regions
92
93
  */
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Address state
3
3
  */
4
- export declare type AddressState = {
4
+ export type AddressState = {
5
5
  /**
6
6
  * Id
7
7
  */
@@ -15,51 +15,6 @@ const UserRole_1 = require("./UserRole");
15
15
  * Core application
16
16
  */
17
17
  class CoreApp {
18
- /**
19
- * Protected constructor
20
- * @param settings Settings
21
- * @param api API
22
- * @param notifier Notifier
23
- * @param storage Storage
24
- * @param name Application name
25
- */
26
- constructor(settings, api, notifier, storage, name) {
27
- this._authorized = false;
28
- this._isTryingLogin = false;
29
- /**
30
- * Last called with token refresh
31
- */
32
- this.lastCalled = false;
33
- /**
34
- * Token refresh count down seed
35
- */
36
- this.refreshCountdownSeed = 0;
37
- /**
38
- * Init call Api URL
39
- */
40
- this.initCallApi = 'Auth/WebInitCall';
41
- /**
42
- * Passphrase for encryption
43
- */
44
- this.passphrase = '';
45
- this.settings = settings;
46
- this.api = api;
47
- this.notifier = notifier;
48
- this.storage = storage;
49
- this.name = name;
50
- // Fields, attach with the name identifier
51
- this.fields = IApp_1.appFields.reduce((a, v) => ({ ...a, [v]: 'smarterp-' + v + '-' + name }), {});
52
- // Device id
53
- this._deviceId = storage.getData(this.fields.deviceId, '');
54
- // Restore
55
- this.restore();
56
- this.setApi(api);
57
- const { currentCulture, currentRegion } = settings;
58
- this.changeCulture(currentCulture);
59
- this.changeRegion(currentRegion);
60
- // Setup callback
61
- this.setup();
62
- }
63
18
  /**
64
19
  * Culture, like zh-CN
65
20
  */
@@ -128,6 +83,51 @@ class CoreApp {
128
83
  this.fields.headerToken
129
84
  ];
130
85
  }
86
+ /**
87
+ * Protected constructor
88
+ * @param settings Settings
89
+ * @param api API
90
+ * @param notifier Notifier
91
+ * @param storage Storage
92
+ * @param name Application name
93
+ */
94
+ constructor(settings, api, notifier, storage, name) {
95
+ this._authorized = false;
96
+ this._isTryingLogin = false;
97
+ /**
98
+ * Last called with token refresh
99
+ */
100
+ this.lastCalled = false;
101
+ /**
102
+ * Token refresh count down seed
103
+ */
104
+ this.refreshCountdownSeed = 0;
105
+ /**
106
+ * Init call Api URL
107
+ */
108
+ this.initCallApi = 'Auth/WebInitCall';
109
+ /**
110
+ * Passphrase for encryption
111
+ */
112
+ this.passphrase = '';
113
+ this.settings = settings;
114
+ this.api = api;
115
+ this.notifier = notifier;
116
+ this.storage = storage;
117
+ this.name = name;
118
+ // Fields, attach with the name identifier
119
+ this.fields = IApp_1.appFields.reduce((a, v) => ({ ...a, [v]: 'smarterp-' + v + '-' + name }), {});
120
+ // Device id
121
+ this._deviceId = storage.getData(this.fields.deviceId, '');
122
+ // Restore
123
+ this.restore();
124
+ this.setApi(api);
125
+ const { currentCulture, currentRegion } = settings;
126
+ this.changeCulture(currentCulture);
127
+ this.changeRegion(currentRegion);
128
+ // Setup callback
129
+ this.setup();
130
+ }
131
131
  getDeviceId() {
132
132
  return this.deviceId.substring(0, 15);
133
133
  }
@@ -24,7 +24,7 @@ export interface NavigateOptions {
24
24
  * true means success, false means failed but no any message
25
25
  * other cases means failed with differnet message
26
26
  */
27
- export declare type RefreshTokenResult = boolean | string | ApiDataError | IActionResult;
27
+ export type RefreshTokenResult = boolean | string | ApiDataError | IActionResult;
28
28
  /**
29
29
  * Refresh token props
30
30
  */
@@ -53,7 +53,7 @@ export declare const appFields: readonly ["headerToken", "serversideDeviceId", "
53
53
  /**
54
54
  * Basic type template
55
55
  */
56
- export declare type IAppFields = {
56
+ export type IAppFields = {
57
57
  [key in typeof appFields[number]]: string;
58
58
  };
59
59
  /**
@@ -1,6 +1,6 @@
1
1
  import { DataTypes } from '@etsoo/shared';
2
2
  import { IBridgeHost } from './IBridgeHost';
3
- declare type CallHandlerType = (name: string, ...args: unknown[]) => PromiseLike<DataTypes.StringRecord | void>;
3
+ type CallHandlerType = (name: string, ...args: unknown[]) => PromiseLike<DataTypes.StringRecord | void>;
4
4
  /**
5
5
  * Flutter JavaScript Host
6
6
  * https://inappwebview.dev/docs/javascript/communication/
@@ -31,5 +31,6 @@ export declare class FlutterHost implements IBridgeHost {
31
31
  loadApp(name: string, startUrl?: string): void;
32
32
  userAuthorization(authorized: boolean): void;
33
33
  onUpdate(func: (app: string, version: string) => void): void;
34
+ setTitle(title: string): void;
34
35
  }
35
36
  export {};
@@ -87,5 +87,6 @@ class FlutterHost {
87
87
  this.cacheCommand('userAuthorization', authorized);
88
88
  }
89
89
  onUpdate(func) { }
90
+ setTitle(title) { }
90
91
  }
91
92
  exports.FlutterHost = FlutterHost;
@@ -42,4 +42,9 @@ export interface IBridgeHost {
42
42
  * @param func Callback function
43
43
  */
44
44
  onUpdate(func: (app: string, version: string) => void): void;
45
+ /**
46
+ * Set window title
47
+ * @param title Title
48
+ */
49
+ setTitle(title: string): void;
45
50
  }
@@ -6,12 +6,6 @@ exports.BusinessTax = void 0;
6
6
  * https://imask.js.org/
7
7
  */
8
8
  class BusinessTax {
9
- // Typescript constructor shorthand
10
- constructor(id, name, mask) {
11
- this.id = id;
12
- this.name = name;
13
- this.mask = mask;
14
- }
15
9
  /**
16
10
  * Get country or region by id
17
11
  * @param id Country id
@@ -19,6 +13,12 @@ class BusinessTax {
19
13
  static getById(id) {
20
14
  return BusinessTax.all.find((c) => c.id === id);
21
15
  }
16
+ // Typescript constructor shorthand
17
+ constructor(id, name, mask) {
18
+ this.id = id;
19
+ this.name = name;
20
+ this.mask = mask;
21
+ }
22
22
  /**
23
23
  * Get label key
24
24
  */
@@ -5,4 +5,4 @@ export declare const Currencies: readonly ["AUD", "CAD", "CNY", "EUR", "GBP", "H
5
5
  /**
6
6
  * Currency type
7
7
  */
8
- export declare type Currency = typeof Currencies[number];
8
+ export type Currency = typeof Currencies[number];
@@ -65,4 +65,4 @@ export declare const ProductUnit: {
65
65
  PC: ProductBaseUnit.PC;
66
66
  SET: ProductBaseUnit.SET;
67
67
  };
68
- export declare type ProductUnit = ProductBaseUnit | RepeatOption | ProductWeightUnit;
68
+ export type ProductUnit = ProductBaseUnit | RepeatOption | ProductWeightUnit;
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * List item definition
3
3
  */
4
- export declare type ListItem<T> = {
4
+ export type ListItem<T> = {
5
5
  /**
6
6
  * Label, '-' for divider
7
7
  */
@@ -4,6 +4,7 @@ import { AddressState } from '../address/AddressState';
4
4
  import { IdLabelConditional } from './dto/IdLabelDto';
5
5
  import { BaseApi } from './BaseApi';
6
6
  import { IApiPayload } from '@etsoo/restclient';
7
+ import { RegionsRQ } from './rq/RegionsRQ';
7
8
  /**
8
9
  * Address Api
9
10
  */
@@ -11,17 +12,30 @@ export declare class AddressApi extends BaseApi {
11
12
  /**
12
13
  * Get all continents
13
14
  * @param isNumberKey Is number key or key as id
15
+ * @param includeAntarctica Include Antarctica or not
14
16
  * @returns Continents
15
17
  */
16
- continents<T extends boolean>(isNumberKey?: T): Promise<IdLabelConditional<T>>;
18
+ continents<T extends boolean>(isNumberKey?: T, includeAntarctica?: boolean): IdLabelConditional<T>;
17
19
  /**
18
20
  * Get continent label
19
21
  * @param id Region id
20
22
  * @returns Label
21
23
  */
22
24
  getContinentLabel(id: AddressContinent | string): string;
23
- regions(isRemote: true): Promise<AddressRegionDb[] | undefined>;
25
+ /**
26
+ * Get all regions
27
+ * @param rq Rquest data
28
+ */
29
+ getRegions(rq?: RegionsRQ): Promise<AddressRegionDb[] | undefined>;
30
+ /**
31
+ * Get all local regions
32
+ */
24
33
  regions(): AddressRegion[];
34
+ /**
35
+ * Get all local regions limited to favored ids
36
+ * @param favoredIds Favored ids
37
+ */
38
+ regions(favoredIds: string[]): AddressRegion[];
25
39
  /**
26
40
  * Get state list
27
41
  * @param regionId Region id
@@ -5,6 +5,7 @@ const shared_1 = require("@etsoo/shared");
5
5
  const AddressContinent_1 = require("../address/AddressContinent");
6
6
  const AddressRegion_1 = require("../address/AddressRegion");
7
7
  const BaseApi_1 = require("./BaseApi");
8
+ const cachedRegions = {};
8
9
  /**
9
10
  * Address Api
10
11
  */
@@ -12,10 +13,13 @@ class AddressApi extends BaseApi_1.BaseApi {
12
13
  /**
13
14
  * Get all continents
14
15
  * @param isNumberKey Is number key or key as id
16
+ * @param includeAntarctica Include Antarctica or not
15
17
  * @returns Continents
16
18
  */
17
- async continents(isNumberKey = false) {
18
- return shared_1.DataTypes.getEnumKeys(AddressContinent_1.AddressContinent).map((key) => ({
19
+ continents(isNumberKey = false, includeAntarctica = false) {
20
+ return shared_1.DataTypes.getEnumKeys(AddressContinent_1.AddressContinent)
21
+ .filter((item) => includeAntarctica || item !== 'AN')
22
+ .map((key) => ({
19
23
  id: isNumberKey
20
24
  ? shared_1.DataTypes.getEnumByKey(AddressContinent_1.AddressContinent, key)
21
25
  : key.toString(),
@@ -32,20 +36,47 @@ class AddressApi extends BaseApi_1.BaseApi {
32
36
  return (_a = this.app.get('continent' + id)) !== null && _a !== void 0 ? _a : id;
33
37
  }
34
38
  /**
35
- * Get region list
36
- * @param isRemote Is Remote version
37
- * @returns Result
39
+ * Get all regions
40
+ * @param rq Rquest data
38
41
  */
39
- regions(isRemote) {
40
- if (isRemote) {
41
- return this.api.get(`Address/RegionList?language=${this.app.culture}`, undefined, { defaultValue: [], showLoading: false });
42
+ async getRegions(rq) {
43
+ const culture = this.app.culture;
44
+ let regions = cachedRegions[culture];
45
+ if (regions == null) {
46
+ regions = await this.api.get(`Address/RegionList?language=${culture}`, undefined, { defaultValue: [], showLoading: false });
47
+ if (regions == null)
48
+ return undefined;
49
+ cachedRegions[culture] = regions;
42
50
  }
43
- else {
44
- return AddressRegion_1.AddressRegion.all.map((region) => {
45
- region.label = this.app.getRegionLabel(region.id);
46
- return { ...region };
51
+ const { favoredIds = [], items = 8, keyword } = rq !== null && rq !== void 0 ? rq : {};
52
+ // Keyword filter
53
+ if (keyword)
54
+ regions = regions.filter((region) => region.label.includes(keyword) || region.id === keyword);
55
+ // Order by favoredIds
56
+ if (favoredIds.length > 0) {
57
+ regions = [...regions].sort((r1, r2) => {
58
+ const n1 = favoredIds.indexOf(r1.id);
59
+ const n2 = favoredIds.indexOf(r2.id);
60
+ if (n1 === n2)
61
+ return 0;
62
+ if (n1 === -1)
63
+ return 1;
64
+ if (n2 === -1)
65
+ return -1;
66
+ return n1 - n2;
47
67
  });
48
68
  }
69
+ // Return the top items
70
+ return regions.slice(0, items);
71
+ }
72
+ regions(p) {
73
+ const items = p == null || p.length === 0
74
+ ? AddressRegion_1.AddressRegion.all
75
+ : AddressRegion_1.AddressRegion.all.filter((ad) => p.includes(ad.id));
76
+ return items.map((region) => ({
77
+ ...region,
78
+ label: this.app.getRegionLabel(region.id)
79
+ }));
49
80
  }
50
81
  /**
51
82
  * Get state list
@@ -5,6 +5,12 @@ exports.BaseApi = void 0;
5
5
  * SmartERP base API
6
6
  */
7
7
  class BaseApi {
8
+ /**
9
+ * API Last error
10
+ */
11
+ get lastError() {
12
+ return this.api.lastError;
13
+ }
8
14
  /**
9
15
  * Constructor
10
16
  * @param app Application
@@ -14,11 +20,5 @@ class BaseApi {
14
20
  this.app = app;
15
21
  this.api = api;
16
22
  }
17
- /**
18
- * API Last error
19
- */
20
- get lastError() {
21
- return this.api.lastError;
22
- }
23
23
  }
24
24
  exports.BaseApi = BaseApi;
@@ -2,7 +2,7 @@ import { IApiPayload } from '@etsoo/restclient';
2
2
  /**
3
3
  * Audit line data
4
4
  */
5
- export declare type AuditLineDto = {
5
+ export type AuditLineDto = {
6
6
  id: number;
7
7
  creation: Date;
8
8
  user: string;
@@ -14,11 +14,11 @@ export declare type AuditLineDto = {
14
14
  /**
15
15
  * Audit line changes data
16
16
  */
17
- export declare type AuditLineChangesDto = {
17
+ export type AuditLineChangesDto = {
18
18
  oldData: Record<string, unknown>;
19
19
  newData: Record<string, unknown>;
20
20
  };
21
21
  /**
22
22
  * Audit line API payload
23
23
  */
24
- export declare type AuditLinePayload = IApiPayload<AuditLineDto[]>;
24
+ export type AuditLinePayload = IApiPayload<AuditLineDto[]>;
@@ -3,4 +3,4 @@ import { ExchangeRateDto } from './ExchangeRateDto';
3
3
  /**
4
4
  * Currency data
5
5
  */
6
- export declare type CurrencyDto = ListType1 & ExchangeRateDto;
6
+ export type CurrencyDto = ListType1 & ExchangeRateDto;
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Exchange rate data
3
3
  */
4
- export declare type ExchangeRateDto = {
4
+ export type ExchangeRateDto = {
5
5
  /**
6
6
  * Exchange rate
7
7
  */
@@ -3,6 +3,6 @@ import { ExchangeRateDto } from './ExchangeRateDto';
3
3
  /**
4
4
  * Exchange rate history data
5
5
  */
6
- export declare type ExchangeRateHistoryDto = ExchangeRateDto & {
6
+ export type ExchangeRateHistoryDto = ExchangeRateDto & {
7
7
  id: Currency;
8
8
  };
@@ -2,4 +2,4 @@ import { ListType, ListType1 } from '@etsoo/shared';
2
2
  /**
3
3
  * Conditional IdLabel type
4
4
  */
5
- export declare type IdLabelConditional<T extends boolean> = T extends true ? ListType[] : ListType1[];
5
+ export type IdLabelConditional<T extends boolean> = T extends true ? ListType[] : ListType1[];
@@ -2,7 +2,7 @@ import { DataTypes } from '@etsoo/shared';
2
2
  /**
3
3
  * Dto with id, label and primary field
4
4
  */
5
- export declare type IdLabelPrimaryDto<T extends DataTypes.IdType = number> = DataTypes.IdLabelItem<T> & {
5
+ export type IdLabelPrimaryDto<T extends DataTypes.IdType = number> = DataTypes.IdLabelItem<T> & {
6
6
  /**
7
7
  * Is primary
8
8
  */
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Init call dto
3
3
  */
4
- export declare type InitCallDto = {
4
+ export type InitCallDto = {
5
5
  /**
6
6
  * Device id
7
7
  */
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Organization data
3
3
  */
4
- export declare type OrgDto = {
4
+ export type OrgDto = {
5
5
  /**
6
6
  * Id
7
7
  */
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Organization query data
3
3
  */
4
- export declare type OrgQueryDto = {
4
+ export type OrgQueryDto = {
5
5
  /**
6
6
  * Id
7
7
  */