@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
@@ -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": "授權人",