@etsoo/appscript 1.3.32 → 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 (98) 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.d.ts +13 -2
  7. package/lib/cjs/app/CoreApp.js +45 -49
  8. package/lib/cjs/app/IApp.d.ts +2 -17
  9. package/lib/cjs/bridges/FlutterHost.d.ts +2 -1
  10. package/lib/cjs/bridges/FlutterHost.js +1 -0
  11. package/lib/cjs/bridges/IBridgeHost.d.ts +5 -0
  12. package/lib/cjs/business/BusinessTax.js +6 -6
  13. package/lib/cjs/business/Currency.d.ts +1 -1
  14. package/lib/cjs/business/ProductUnit.d.ts +1 -1
  15. package/lib/cjs/def/ListItem.d.ts +1 -1
  16. package/lib/cjs/erp/AddressApi.d.ts +16 -2
  17. package/lib/cjs/erp/AddressApi.js +43 -12
  18. package/lib/cjs/erp/BaseApi.js +6 -6
  19. package/lib/cjs/erp/dto/AuditLineDto.d.ts +3 -3
  20. package/lib/cjs/erp/dto/CurrencyDto.d.ts +1 -1
  21. package/lib/cjs/erp/dto/ExchangeRateDto.d.ts +1 -1
  22. package/lib/cjs/erp/dto/ExchangeRateHistoryDto.d.ts +1 -1
  23. package/lib/cjs/erp/dto/IdLabelDto.d.ts +1 -1
  24. package/lib/cjs/erp/dto/IdLabelPrimaryDto.d.ts +1 -1
  25. package/lib/cjs/erp/dto/InitCallDto.d.ts +1 -1
  26. package/lib/cjs/erp/dto/OrgDto.d.ts +1 -1
  27. package/lib/cjs/erp/dto/OrgQueryDto.d.ts +1 -1
  28. package/lib/cjs/erp/dto/PublicProductDto.d.ts +2 -2
  29. package/lib/cjs/erp/dto/ResultPayload.d.ts +3 -3
  30. package/lib/cjs/erp/rq/MemberListRQ.d.ts +1 -1
  31. package/lib/cjs/erp/rq/OrgListRQ.d.ts +1 -1
  32. package/lib/cjs/erp/rq/OrgQueryRQ.d.ts +1 -1
  33. package/lib/cjs/erp/rq/QueryRQ.d.ts +1 -1
  34. package/lib/cjs/erp/rq/RefreshTokenRQ.d.ts +1 -1
  35. package/lib/cjs/erp/rq/RegionsRQ.d.ts +14 -0
  36. package/lib/cjs/erp/rq/RegionsRQ.js +2 -0
  37. package/lib/cjs/erp/rq/TiplistRQ.d.ts +1 -1
  38. package/lib/cjs/i18n/en-US.json +1 -0
  39. package/lib/cjs/i18n/zh-CN.json +1 -0
  40. package/lib/cjs/i18n/zh-HK.json +1 -0
  41. package/lib/cjs/result/ActionResultError.js +12 -12
  42. package/lib/cjs/result/IActionResult.d.ts +2 -2
  43. package/lib/cjs/result/InitCallResult.d.ts +1 -1
  44. package/lib/cjs/state/User.d.ts +1 -1
  45. package/lib/mjs/address/AddressContinent.d.ts +1 -1
  46. package/lib/mjs/address/AddressRegion.d.ts +7 -1
  47. package/lib/mjs/address/AddressRegion.js +21 -20
  48. package/lib/mjs/address/AddressState.d.ts +1 -1
  49. package/lib/mjs/app/CoreApp.d.ts +13 -2
  50. package/lib/mjs/app/CoreApp.js +45 -49
  51. package/lib/mjs/app/IApp.d.ts +2 -17
  52. package/lib/mjs/bridges/FlutterHost.d.ts +2 -1
  53. package/lib/mjs/bridges/FlutterHost.js +1 -0
  54. package/lib/mjs/bridges/IBridgeHost.d.ts +5 -0
  55. package/lib/mjs/business/BusinessTax.js +6 -6
  56. package/lib/mjs/business/Currency.d.ts +1 -1
  57. package/lib/mjs/business/ProductUnit.d.ts +1 -1
  58. package/lib/mjs/def/ListItem.d.ts +1 -1
  59. package/lib/mjs/erp/AddressApi.d.ts +16 -2
  60. package/lib/mjs/erp/AddressApi.js +43 -12
  61. package/lib/mjs/erp/BaseApi.js +6 -6
  62. package/lib/mjs/erp/dto/AuditLineDto.d.ts +3 -3
  63. package/lib/mjs/erp/dto/CurrencyDto.d.ts +1 -1
  64. package/lib/mjs/erp/dto/ExchangeRateDto.d.ts +1 -1
  65. package/lib/mjs/erp/dto/ExchangeRateHistoryDto.d.ts +1 -1
  66. package/lib/mjs/erp/dto/IdLabelDto.d.ts +1 -1
  67. package/lib/mjs/erp/dto/IdLabelPrimaryDto.d.ts +1 -1
  68. package/lib/mjs/erp/dto/InitCallDto.d.ts +1 -1
  69. package/lib/mjs/erp/dto/OrgDto.d.ts +1 -1
  70. package/lib/mjs/erp/dto/OrgQueryDto.d.ts +1 -1
  71. package/lib/mjs/erp/dto/PublicProductDto.d.ts +2 -2
  72. package/lib/mjs/erp/dto/ResultPayload.d.ts +3 -3
  73. package/lib/mjs/erp/rq/MemberListRQ.d.ts +1 -1
  74. package/lib/mjs/erp/rq/OrgListRQ.d.ts +1 -1
  75. package/lib/mjs/erp/rq/OrgQueryRQ.d.ts +1 -1
  76. package/lib/mjs/erp/rq/QueryRQ.d.ts +1 -1
  77. package/lib/mjs/erp/rq/RefreshTokenRQ.d.ts +1 -1
  78. package/lib/mjs/erp/rq/RegionsRQ.d.ts +14 -0
  79. package/lib/mjs/erp/rq/RegionsRQ.js +1 -0
  80. package/lib/mjs/erp/rq/TiplistRQ.d.ts +1 -1
  81. package/lib/mjs/i18n/en-US.json +1 -0
  82. package/lib/mjs/i18n/zh-CN.json +1 -0
  83. package/lib/mjs/i18n/zh-HK.json +1 -0
  84. package/lib/mjs/result/ActionResultError.js +12 -12
  85. package/lib/mjs/result/IActionResult.d.ts +2 -2
  86. package/lib/mjs/result/InitCallResult.d.ts +1 -1
  87. package/lib/mjs/state/User.d.ts +1 -1
  88. package/package.json +8 -8
  89. package/src/address/AddressRegion.ts +29 -10
  90. package/src/app/CoreApp.ts +2 -26
  91. package/src/app/IApp.ts +0 -25
  92. package/src/bridges/FlutterHost.ts +2 -0
  93. package/src/bridges/IBridgeHost.ts +6 -0
  94. package/src/erp/AddressApi.ts +72 -25
  95. package/src/erp/rq/RegionsRQ.ts +16 -0
  96. package/src/i18n/en-US.json +1 -0
  97. package/src/i18n/zh-CN.json +1 -0
  98. package/src/i18n/zh-HK.json +1 -0
@@ -30,7 +30,6 @@ import {
30
30
  SHA3
31
31
  } from 'crypto-js';
32
32
  import { AddressRegion } from '../address/AddressRegion';
33
- import { AddressUtils } from '../address/AddressUtils';
34
33
  import { BridgeUtils } from '../bridges/BridgeUtils';
35
34
  import { EntityStatus } from '../business/EntityStatus';
36
35
  import { InitCallDto } from '../erp/dto/InitCallDto';
@@ -996,16 +995,6 @@ export abstract class CoreApp<
996
995
  return DateUtils.format(input, currentCulture.name, options, timeZone);
997
996
  }
998
997
 
999
- formatMoney(
1000
- input: null | undefined,
1001
- isInteger?: boolean,
1002
- options?: Intl.NumberFormatOptions
1003
- ): undefined;
1004
- formatMoney(
1005
- input: number | bigint,
1006
- isInteger?: boolean,
1007
- options?: Intl.NumberFormatOptions
1008
- ): string;
1009
998
  /**
1010
999
  * Format money number
1011
1000
  * @param input Input money number
@@ -1014,11 +1003,10 @@ export abstract class CoreApp<
1014
1003
  * @returns Result
1015
1004
  */
1016
1005
  formatMoney(
1017
- input: number | bigint | null | undefined,
1006
+ input: number | bigint,
1018
1007
  isInteger: boolean = false,
1019
1008
  options?: Intl.NumberFormatOptions
1020
1009
  ) {
1021
- if (input == null) return undefined;
1022
1010
  return NumberUtils.formatMoney(
1023
1011
  input,
1024
1012
  this.currency,
@@ -1028,25 +1016,13 @@ export abstract class CoreApp<
1028
1016
  );
1029
1017
  }
1030
1018
 
1031
- formatNumber(
1032
- input: null | undefined,
1033
- options?: Intl.NumberFormatOptions
1034
- ): undefined;
1035
- formatNumber(
1036
- input: number | bigint,
1037
- options?: Intl.NumberFormatOptions
1038
- ): string;
1039
1019
  /**
1040
1020
  * Format number
1041
1021
  * @param input Input number
1042
1022
  * @param options Options
1043
1023
  * @returns Result
1044
1024
  */
1045
- formatNumber(
1046
- input: number | bigint | null | undefined,
1047
- options?: Intl.NumberFormatOptions
1048
- ) {
1049
- if (input == null) return undefined;
1025
+ formatNumber(input: number | bigint, options?: Intl.NumberFormatOptions) {
1050
1026
  return NumberUtils.format(input, this.culture, options);
1051
1027
  }
1052
1028
 
package/src/app/IApp.ts CHANGED
@@ -8,7 +8,6 @@ import {
8
8
  import { ApiDataError, IApi, IPData } from '@etsoo/restclient';
9
9
  import { DataTypes, DateUtils, IStorage, ListType } from '@etsoo/shared';
10
10
  import { AddressRegion } from '../address/AddressRegion';
11
- import { ProductUnit } from '../business/ProductUnit';
12
11
  import { IActionResult } from '../result/IActionResult';
13
12
  import { IUser } from '../state/User';
14
13
  import { IAppSettings } from './AppSettings';
@@ -299,19 +298,6 @@ export interface IApp {
299
298
  */
300
299
  formatError(error: ApiDataError): string;
301
300
 
302
- /**
303
- * Format money number
304
- * @param input Input money number
305
- * @param isInteger Is integer
306
- * @param options Options
307
- * @returns Result
308
- */
309
- formatMoney(
310
- input: null | undefined,
311
- isInteger?: boolean,
312
- options?: Intl.NumberFormatOptions
313
- ): undefined;
314
-
315
301
  /**
316
302
  * Format money number
317
303
  * @param input Input money number
@@ -325,17 +311,6 @@ export interface IApp {
325
311
  options?: Intl.NumberFormatOptions
326
312
  ): string;
327
313
 
328
- /**
329
- * Format number
330
- * @param input Input number
331
- * @param options Options
332
- * @returns Result
333
- */
334
- formatNumber(
335
- input: null | undefined,
336
- options?: Intl.NumberFormatOptions
337
- ): undefined;
338
-
339
314
  /**
340
315
  * Format number
341
316
  * @param input Input number
@@ -108,4 +108,6 @@ export class FlutterHost implements IBridgeHost {
108
108
  }
109
109
 
110
110
  onUpdate(func: (app: string, version: string) => void) {}
111
+
112
+ setTitle(title: string) {}
111
113
  }
@@ -49,4 +49,10 @@ export interface IBridgeHost {
49
49
  * @param func Callback function
50
50
  */
51
51
  onUpdate(func: (app: string, version: string) => void): void;
52
+
53
+ /**
54
+ * Set window title
55
+ * @param title Title
56
+ */
57
+ setTitle(title: string): void;
52
58
  }
@@ -5,6 +5,9 @@ import { AddressState } from '../address/AddressState';
5
5
  import { IdLabelConditional } from './dto/IdLabelDto';
6
6
  import { BaseApi } from './BaseApi';
7
7
  import { IApiPayload } from '@etsoo/restclient';
8
+ import { RegionsRQ } from './rq/RegionsRQ';
9
+
10
+ const cachedRegions: { [P: string]: AddressRegionDb[] | undefined | null } = {};
8
11
 
9
12
  /**
10
13
  * Address Api
@@ -13,19 +16,21 @@ export class AddressApi extends BaseApi {
13
16
  /**
14
17
  * Get all continents
15
18
  * @param isNumberKey Is number key or key as id
19
+ * @param includeAntarctica Include Antarctica or not
16
20
  * @returns Continents
17
21
  */
18
- async continents<T extends boolean>(
19
- isNumberKey = <T>false
20
- ): Promise<IdLabelConditional<T>> {
21
- return <IdLabelConditional<T>>DataTypes.getEnumKeys(
22
- AddressContinent
23
- ).map((key) => ({
24
- id: isNumberKey
25
- ? <number>DataTypes.getEnumByKey(AddressContinent, key)!
26
- : key.toString(),
27
- label: this.getContinentLabel(key)
28
- }));
22
+ continents<T extends boolean>(
23
+ isNumberKey = <T>false,
24
+ includeAntarctica: boolean = false
25
+ ): IdLabelConditional<T> {
26
+ return <IdLabelConditional<T>>DataTypes.getEnumKeys(AddressContinent)
27
+ .filter((item) => includeAntarctica || item !== 'AN')
28
+ .map((key) => ({
29
+ id: isNumberKey
30
+ ? <number>DataTypes.getEnumByKey(AddressContinent, key)!
31
+ : key.toString(),
32
+ label: this.getContinentLabel(key)
33
+ }));
29
34
  }
30
35
 
31
36
  /**
@@ -37,27 +42,69 @@ export class AddressApi extends BaseApi {
37
42
  return this.app.get('continent' + id) ?? (id as string);
38
43
  }
39
44
 
40
- regions(isRemote: true): Promise<AddressRegionDb[] | undefined>;
41
- regions(): AddressRegion[];
42
-
43
45
  /**
44
- * Get region list
45
- * @param isRemote Is Remote version
46
- * @returns Result
46
+ * Get all regions
47
+ * @param rq Rquest data
47
48
  */
48
- regions(isRemote?: boolean) {
49
- if (isRemote) {
50
- return this.api.get<AddressRegionDb[]>(
51
- `Address/RegionList?language=${this.app.culture}`,
49
+ async getRegions(rq?: RegionsRQ): Promise<AddressRegionDb[] | undefined> {
50
+ const culture = this.app.culture;
51
+ let regions = cachedRegions[culture];
52
+ if (regions == null) {
53
+ regions = await this.api.get<AddressRegionDb[]>(
54
+ `Address/RegionList?language=${culture}`,
52
55
  undefined,
53
56
  { defaultValue: [], showLoading: false }
54
57
  );
55
- } else {
56
- return AddressRegion.all.map((region) => {
57
- region.label = this.app.getRegionLabel(region.id);
58
- return { ...region };
58
+ if (regions == null) return undefined;
59
+ cachedRegions[culture] = regions;
60
+ }
61
+
62
+ const { favoredIds = [], items = 8, keyword } = rq ?? {};
63
+
64
+ // Keyword filter
65
+ if (keyword)
66
+ regions = regions.filter(
67
+ (region) =>
68
+ region.label.includes(keyword) || region.id === keyword
69
+ );
70
+
71
+ // Order by favoredIds
72
+ if (favoredIds.length > 0) {
73
+ regions = [...regions].sort((r1, r2) => {
74
+ const n1 = favoredIds.indexOf(r1.id);
75
+ const n2 = favoredIds.indexOf(r2.id);
76
+
77
+ if (n1 === n2) return 0;
78
+ if (n1 === -1) return 1;
79
+ if (n2 === -1) return -1;
80
+ return n1 - n2;
59
81
  });
60
82
  }
83
+
84
+ // Return the top items
85
+ return regions.slice(0, items);
86
+ }
87
+
88
+ /**
89
+ * Get all local regions
90
+ */
91
+ regions(): AddressRegion[];
92
+
93
+ /**
94
+ * Get all local regions limited to favored ids
95
+ * @param favoredIds Favored ids
96
+ */
97
+ regions(favoredIds: string[]): AddressRegion[];
98
+
99
+ regions(p?: string[]) {
100
+ const items =
101
+ p == null || p.length === 0
102
+ ? AddressRegion.all
103
+ : AddressRegion.all.filter((ad) => p.includes(ad.id));
104
+ return items.map((region) => ({
105
+ ...region,
106
+ label: this.app.getRegionLabel(region.id)
107
+ }));
61
108
  }
62
109
 
63
110
  /**
@@ -0,0 +1,16 @@
1
+ export type RegionsRQ = {
2
+ /**
3
+ * Favored country ids from top to bottom
4
+ */
5
+ favoredIds?: string[];
6
+
7
+ /**
8
+ * Items count to query
9
+ */
10
+ items?: number;
11
+
12
+ /**
13
+ * Filter keyword
14
+ */
15
+ keyword?: string;
16
+ };
@@ -2,6 +2,7 @@
2
2
  "accountant": "Accountant",
3
3
  "actions": "Actions",
4
4
  "add": "Add",
5
+ "assignedId": "Assigned ID",
5
6
  "audits": "Audits",
6
7
  "author": "Author",
7
8
  "authorizer": "Authorizer",
@@ -2,6 +2,7 @@
2
2
  "accountant": "会计",
3
3
  "actions": "操作",
4
4
  "add": "添加",
5
+ "assignedId": "分配的编号",
5
6
  "audits": "操作历史",
6
7
  "author": "作者",
7
8
  "authorizer": "授权人",
@@ -2,6 +2,7 @@
2
2
  "accountant": "會計",
3
3
  "actions": "操作",
4
4
  "add": "添加",
5
+ "assignedId": "分配的編號",
5
6
  "audits": "操作歷史",
6
7
  "author": "作者",
7
8
  "authorizer": "授權人",