@etsoo/appscript 1.3.70 → 1.3.71

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 (37) hide show
  1. package/__tests__/app/CoreApp.ts +27 -0
  2. package/lib/cjs/address/AddressAutocomplete.d.ts +22 -0
  3. package/lib/cjs/address/AddressAutocomplete.js +2 -0
  4. package/lib/cjs/address/AddressLocation.d.ts +14 -0
  5. package/lib/cjs/address/AddressLocation.js +2 -0
  6. package/lib/cjs/address/AddressPlace.d.ts +28 -0
  7. package/lib/cjs/address/AddressPlace.js +2 -0
  8. package/lib/cjs/address/AddressPlaceBase.d.ts +37 -0
  9. package/lib/cjs/address/AddressPlaceBase.js +2 -0
  10. package/lib/cjs/erp/AddressApi.d.ts +32 -3
  11. package/lib/cjs/erp/AddressApi.js +49 -17
  12. package/lib/cjs/erp/rq/PlaceQueryRQ.d.ts +45 -0
  13. package/lib/cjs/erp/rq/PlaceQueryRQ.js +12 -0
  14. package/lib/cjs/index.d.ts +5 -0
  15. package/lib/cjs/index.js +5 -0
  16. package/lib/mjs/address/AddressAutocomplete.d.ts +22 -0
  17. package/lib/mjs/address/AddressAutocomplete.js +1 -0
  18. package/lib/mjs/address/AddressLocation.d.ts +14 -0
  19. package/lib/mjs/address/AddressLocation.js +1 -0
  20. package/lib/mjs/address/AddressPlace.d.ts +28 -0
  21. package/lib/mjs/address/AddressPlace.js +1 -0
  22. package/lib/mjs/address/AddressPlaceBase.d.ts +37 -0
  23. package/lib/mjs/address/AddressPlaceBase.js +1 -0
  24. package/lib/mjs/erp/AddressApi.d.ts +32 -3
  25. package/lib/mjs/erp/AddressApi.js +50 -18
  26. package/lib/mjs/erp/rq/PlaceQueryRQ.d.ts +45 -0
  27. package/lib/mjs/erp/rq/PlaceQueryRQ.js +9 -0
  28. package/lib/mjs/index.d.ts +5 -0
  29. package/lib/mjs/index.js +5 -0
  30. package/package.json +4 -4
  31. package/src/address/AddressAutocomplete.ts +25 -0
  32. package/src/address/AddressLocation.ts +15 -0
  33. package/src/address/AddressPlace.ts +32 -0
  34. package/src/address/AddressPlaceBase.ts +43 -0
  35. package/src/erp/AddressApi.ts +68 -16
  36. package/src/erp/rq/PlaceQueryRQ.ts +52 -0
  37. package/src/index.ts +5 -0
@@ -228,6 +228,33 @@ test('Tests for addressApi', async () => {
228
228
  expect(regionFailed).toBeUndefined();
229
229
 
230
230
  /*
231
+ const results1 = await app.addressApi.autocomplete({
232
+ query: '青岛市玫瑰庭院',
233
+ region: 'CN',
234
+ language: 'zh-CN'
235
+ });
236
+
237
+ const results2 = await app.addressApi.autocomplete({
238
+ query: '青岛市玫瑰庭院',
239
+ language: 'zh-CN'
240
+ });
241
+
242
+ const results1 = await app.addressApi.searchPlace({
243
+ query: '青岛市玫瑰庭院',
244
+ region: 'CN',
245
+ language: 'zh-CN'
246
+ });
247
+
248
+ const result = await app.addressApi.GetPlaceDetails(
249
+ 'ChIJczySyo1qljUR1Jnq4Uqak2I',
250
+ 'zh-CN'
251
+ );
252
+
253
+ const results2 = await app.addressApi.searchPlace({
254
+ query: '青岛市玫瑰庭院',
255
+ language: 'zh-CN'
256
+ });
257
+
231
258
  const cities = await app.addressApi.cities('CNHN');
232
259
  console.log(cities);
233
260
 
@@ -0,0 +1,22 @@
1
+ import { AddressPlaceBase } from './AddressPlaceBase';
2
+ /**
3
+ * Address autocomplete
4
+ * 地点自动填充
5
+ */
6
+ export type AddressAutocomplete = {
7
+ /**
8
+ * Place id
9
+ * 地点编号
10
+ */
11
+ placeId: string;
12
+ /**
13
+ * Name
14
+ * 名称
15
+ */
16
+ name: string;
17
+ /**
18
+ * Place data
19
+ * 地点数据
20
+ */
21
+ place?: AddressPlaceBase;
22
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Address location
3
+ * 地理位置
4
+ */
5
+ export type AddressLocation = {
6
+ /**
7
+ * Latitude, 纬度
8
+ */
9
+ lat: number;
10
+ /**
11
+ * Longitude, 经度
12
+ */
13
+ lng: number;
14
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,28 @@
1
+ import { AddressLocation } from './AddressLocation';
2
+ import { AddressPlaceBase } from './AddressPlaceBase';
3
+ /**
4
+ * Address place
5
+ * 地点
6
+ */
7
+ export type AddressPlace = Omit<AddressPlaceBase, 'location'> & {
8
+ /**
9
+ * Place id
10
+ * 地点编号
11
+ */
12
+ placeId: string;
13
+ /**
14
+ * Name
15
+ * 名称
16
+ */
17
+ name: string;
18
+ /**
19
+ * Location
20
+ * 位置
21
+ */
22
+ location: AddressLocation;
23
+ /**
24
+ * Formatted address
25
+ * 格式化地址
26
+ */
27
+ formattedAddress: string;
28
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,37 @@
1
+ import { AddressLocation } from './AddressLocation';
2
+ /**
3
+ * Address place base
4
+ * 基础地点
5
+ */
6
+ export type AddressPlaceBase = {
7
+ /**
8
+ * Location
9
+ * 位置
10
+ */
11
+ location?: AddressLocation;
12
+ /**
13
+ * Region or country, like CN = China
14
+ * 地区或国家,比如 CN 表示中国
15
+ */
16
+ region?: string;
17
+ /**
18
+ * State or province
19
+ * 州 / 省
20
+ */
21
+ state?: string;
22
+ /**
23
+ * City
24
+ * 城市
25
+ */
26
+ city?: string;
27
+ /**
28
+ * District
29
+ * 区县
30
+ */
31
+ district?: string;
32
+ /**
33
+ * Postcode
34
+ * 邮编
35
+ */
36
+ postcode?: string;
37
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -7,10 +7,20 @@ import { IApiPayload } from '@etsoo/restclient';
7
7
  import { RegionsRQ } from './rq/RegionsRQ';
8
8
  import { AddressCity } from '../address/AddressCity';
9
9
  import { AddressDistrict } from '../address/AddressDistrict';
10
+ import { PlaceQueryRQ } from './rq/PlaceQueryRQ';
11
+ import { AddressAutocomplete } from '../address/AddressAutocomplete';
12
+ import { AddressPlace } from '../address/AddressPlace';
10
13
  /**
11
14
  * Address Api
12
15
  */
13
16
  export declare class AddressApi extends BaseApi {
17
+ /**
18
+ * Place autocomplete
19
+ * @param rq Request data
20
+ * @param payload Payload
21
+ * @returns Result
22
+ */
23
+ autocomplete(rq: PlaceQueryRQ, payload?: IApiPayload<AddressAutocomplete[]>): Promise<AddressAutocomplete[] | undefined>;
14
24
  /**
15
25
  * Get all continents
16
26
  * @param isNumberKey Is number key or key as id
@@ -65,25 +75,44 @@ export declare class AddressApi extends BaseApi {
65
75
  /**
66
76
  * Get state list
67
77
  * @param regionId Region id
78
+ * @param favoredIds Favored ids
68
79
  * @param payload Payload
69
80
  * @param culture Culture
70
81
  * @returns Result
71
82
  */
72
- states(regionId: string, payload?: IApiPayload<AddressState[]>, culture?: string): Promise<AddressState[] | undefined>;
83
+ states(regionId: string, favoredIds?: string[], payload?: IApiPayload<AddressState[]>, culture?: string): Promise<AddressState[] | undefined>;
73
84
  /**
74
85
  * Get city list
75
86
  * @param stateId State id
87
+ * @param favoredIds Favored ids
76
88
  * @param payload Payload
77
89
  * @param culture Culture
90
+ *
78
91
  * @returns Result
79
92
  */
80
- cities(stateId: string, payload?: IApiPayload<AddressCity[]>, culture?: string): Promise<AddressCity[] | undefined>;
93
+ cities(stateId: string, favoredIds?: number[], payload?: IApiPayload<AddressCity[]>, culture?: string): Promise<AddressCity[] | undefined>;
81
94
  /**
82
95
  * Get district list
83
96
  * @param cityId City id
97
+ * @param favoredIds Favored ids
84
98
  * @param payload Payload
85
99
  * @param culture Culture
86
100
  * @returns Result
87
101
  */
88
- districts(cityId: number, payload?: IApiPayload<AddressDistrict[]>, culture?: string): Promise<AddressDistrict[] | undefined>;
102
+ districts(cityId: number, favoredIds?: number[], payload?: IApiPayload<AddressDistrict[]>, culture?: string): Promise<AddressDistrict[] | undefined>;
103
+ /**
104
+ * Get place details
105
+ * @param placeId Place id
106
+ * @param language Language
107
+ * @param payload Payload
108
+ * @returns Result
109
+ */
110
+ GetPlaceDetails(placeId: string, language?: string, payload?: IApiPayload<AddressPlace>): Promise<AddressPlace | undefined>;
111
+ /**
112
+ * Place autocomplete
113
+ * @param rq Request data
114
+ * @param payload Payload
115
+ * @returns Result
116
+ */
117
+ searchPlace(rq: PlaceQueryRQ, payload?: IApiPayload<AddressPlace[]>): Promise<AddressPlace[] | undefined>;
89
118
  }
@@ -10,6 +10,15 @@ const cachedRegions = {};
10
10
  * Address Api
11
11
  */
12
12
  class AddressApi extends BaseApi_1.BaseApi {
13
+ /**
14
+ * Place autocomplete
15
+ * @param rq Request data
16
+ * @param payload Payload
17
+ * @returns Result
18
+ */
19
+ autocomplete(rq, payload) {
20
+ return this.api.post('Address/Autocomplete', rq, payload);
21
+ }
13
22
  /**
14
23
  * Get all continents
15
24
  * @param isNumberKey Is number key or key as id
@@ -94,17 +103,7 @@ class AddressApi extends BaseApi_1.BaseApi {
94
103
  });
95
104
  // Order by favoredIds
96
105
  if (favoredIds.length > 0) {
97
- regions = [...regions].sort((r1, r2) => {
98
- const n1 = favoredIds.indexOf(r1.id);
99
- const n2 = favoredIds.indexOf(r2.id);
100
- if (n1 === n2)
101
- return 0;
102
- if (n1 === -1)
103
- return 1;
104
- if (n2 === -1)
105
- return -1;
106
- return n1 - n2;
107
- });
106
+ regions = shared_1.Utils.sortByFieldFavor([...regions], 'id', favoredIds);
108
107
  }
109
108
  // Return the top items
110
109
  return regions.slice(0, items);
@@ -143,38 +142,71 @@ class AddressApi extends BaseApi_1.BaseApi {
143
142
  /**
144
143
  * Get state list
145
144
  * @param regionId Region id
145
+ * @param favoredIds Favored ids
146
146
  * @param payload Payload
147
147
  * @param culture Culture
148
148
  * @returns Result
149
149
  */
150
- states(regionId, payload, culture) {
150
+ async states(regionId, favoredIds = [], payload, culture) {
151
151
  payload !== null && payload !== void 0 ? payload : (payload = { defaultValue: [], showLoading: false });
152
152
  culture !== null && culture !== void 0 ? culture : (culture = this.app.culture);
153
- return this.api.get(`Address/StateList?regionId=${regionId}&language=${culture}`, undefined, payload);
153
+ var items = await this.api.get(`Address/StateList?regionId=${regionId}&language=${culture}`, undefined, payload);
154
+ if (items == null || favoredIds.length === 0)
155
+ return items;
156
+ return shared_1.Utils.sortByFieldFavor(items, 'id', favoredIds);
154
157
  }
155
158
  /**
156
159
  * Get city list
157
160
  * @param stateId State id
161
+ * @param favoredIds Favored ids
158
162
  * @param payload Payload
159
163
  * @param culture Culture
164
+ *
160
165
  * @returns Result
161
166
  */
162
- cities(stateId, payload, culture) {
167
+ async cities(stateId, favoredIds = [], payload, culture) {
163
168
  payload !== null && payload !== void 0 ? payload : (payload = { defaultValue: [], showLoading: false });
164
169
  culture !== null && culture !== void 0 ? culture : (culture = this.app.culture);
165
- return this.api.get(`Address/CityList?stateId=${stateId}&language=${culture}`, undefined, payload);
170
+ const items = await this.api.get(`Address/CityList?stateId=${stateId}&language=${culture}`, undefined, payload);
171
+ if (items == null || favoredIds.length === 0)
172
+ return items;
173
+ return shared_1.Utils.sortByFieldFavor(items, 'id', favoredIds);
166
174
  }
167
175
  /**
168
176
  * Get district list
169
177
  * @param cityId City id
178
+ * @param favoredIds Favored ids
170
179
  * @param payload Payload
171
180
  * @param culture Culture
172
181
  * @returns Result
173
182
  */
174
- districts(cityId, payload, culture) {
183
+ async districts(cityId, favoredIds = [], payload, culture) {
175
184
  payload !== null && payload !== void 0 ? payload : (payload = { defaultValue: [], showLoading: false });
176
185
  culture !== null && culture !== void 0 ? culture : (culture = this.app.culture);
177
- return this.api.get(`Address/DistrictList?cityId=${cityId}&language=${culture}`, undefined, payload);
186
+ const items = await this.api.get(`Address/DistrictList?cityId=${cityId}&language=${culture}`, undefined, payload);
187
+ if (items == null || favoredIds.length === 0)
188
+ return items;
189
+ return shared_1.Utils.sortByFieldFavor(items, 'id', favoredIds);
190
+ }
191
+ /**
192
+ * Get place details
193
+ * @param placeId Place id
194
+ * @param language Language
195
+ * @param payload Payload
196
+ * @returns Result
197
+ */
198
+ GetPlaceDetails(placeId, language, payload) {
199
+ const url = `Address/GetPlaceDetails/${placeId}/${language == null ? '' : language}`;
200
+ return this.api.get(url, undefined, payload);
201
+ }
202
+ /**
203
+ * Place autocomplete
204
+ * @param rq Request data
205
+ * @param payload Payload
206
+ * @returns Result
207
+ */
208
+ searchPlace(rq, payload) {
209
+ return this.api.post('Address/SearchPlace', rq, payload);
178
210
  }
179
211
  }
180
212
  exports.AddressApi = AddressApi;
@@ -0,0 +1,45 @@
1
+ import { AddressLocation } from '../../address/AddressLocation';
2
+ /**
3
+ * Place query output type
4
+ * 地址查询输出类型
5
+ */
6
+ export declare enum PlaceQueryOutput {
7
+ JSON = 0,
8
+ XML = 1
9
+ }
10
+ /**
11
+ * Place query request data
12
+ * 地址查询请求数据
13
+ */
14
+ export type PlaceQueryRQ = {
15
+ /**
16
+ * Query address
17
+ * 查询地址
18
+ */
19
+ query: string;
20
+ /**
21
+ * Output type
22
+ * 输出类型
23
+ */
24
+ output?: PlaceQueryOutput;
25
+ /**
26
+ * Language
27
+ * 语言
28
+ */
29
+ language?: string;
30
+ /**
31
+ * Limited region / country id, like CN
32
+ * 限定的地区获国家编号
33
+ */
34
+ region?: string;
35
+ /**
36
+ * Center location
37
+ * 中心位置
38
+ */
39
+ location?: AddressLocation;
40
+ /**
41
+ * Circle radius
42
+ * 方圆半径
43
+ */
44
+ radius?: number;
45
+ };
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PlaceQueryOutput = void 0;
4
+ /**
5
+ * Place query output type
6
+ * 地址查询输出类型
7
+ */
8
+ var PlaceQueryOutput;
9
+ (function (PlaceQueryOutput) {
10
+ PlaceQueryOutput[PlaceQueryOutput["JSON"] = 0] = "JSON";
11
+ PlaceQueryOutput[PlaceQueryOutput["XML"] = 1] = "XML";
12
+ })(PlaceQueryOutput = exports.PlaceQueryOutput || (exports.PlaceQueryOutput = {}));
@@ -1,6 +1,10 @@
1
+ export * from './address/AddressAutocomplete';
1
2
  export * from './address/AddressCity';
2
3
  export * from './address/AddressContinent';
3
4
  export * from './address/AddressDistrict';
5
+ export * from './address/AddressLocation';
6
+ export * from './address/AddressPlace';
7
+ export * from './address/AddressPlaceBase';
4
8
  export * from './address/AddressRegion';
5
9
  export * from './address/AddressState';
6
10
  export * from './address/AddressUtils';
@@ -36,6 +40,7 @@ export * from './erp/rq/LoginRQ';
36
40
  export * from './erp/rq/MemberListRQ';
37
41
  export * from './erp/rq/OrgListRQ';
38
42
  export * from './erp/rq/OrgQueryRQ';
43
+ export * from './erp/rq/PlaceQueryRQ';
39
44
  export * from './erp/rq/QueryRQ';
40
45
  export * from './erp/rq/RefreshTokenRQ';
41
46
  export * from './erp/rq/RegionsRQ';
package/lib/cjs/index.js CHANGED
@@ -16,9 +16,13 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  exports.createClient = exports.ApiResponseType = exports.ApiMethod = exports.ApiAuthorizationScheme = void 0;
18
18
  // address
19
+ __exportStar(require("./address/AddressAutocomplete"), exports);
19
20
  __exportStar(require("./address/AddressCity"), exports);
20
21
  __exportStar(require("./address/AddressContinent"), exports);
21
22
  __exportStar(require("./address/AddressDistrict"), exports);
23
+ __exportStar(require("./address/AddressLocation"), exports);
24
+ __exportStar(require("./address/AddressPlace"), exports);
25
+ __exportStar(require("./address/AddressPlaceBase"), exports);
22
26
  __exportStar(require("./address/AddressRegion"), exports);
23
27
  __exportStar(require("./address/AddressState"), exports);
24
28
  __exportStar(require("./address/AddressUtils"), exports);
@@ -60,6 +64,7 @@ __exportStar(require("./erp/rq/LoginRQ"), exports);
60
64
  __exportStar(require("./erp/rq/MemberListRQ"), exports);
61
65
  __exportStar(require("./erp/rq/OrgListRQ"), exports);
62
66
  __exportStar(require("./erp/rq/OrgQueryRQ"), exports);
67
+ __exportStar(require("./erp/rq/PlaceQueryRQ"), exports);
63
68
  __exportStar(require("./erp/rq/QueryRQ"), exports);
64
69
  __exportStar(require("./erp/rq/RefreshTokenRQ"), exports);
65
70
  __exportStar(require("./erp/rq/RegionsRQ"), exports);
@@ -0,0 +1,22 @@
1
+ import { AddressPlaceBase } from './AddressPlaceBase';
2
+ /**
3
+ * Address autocomplete
4
+ * 地点自动填充
5
+ */
6
+ export type AddressAutocomplete = {
7
+ /**
8
+ * Place id
9
+ * 地点编号
10
+ */
11
+ placeId: string;
12
+ /**
13
+ * Name
14
+ * 名称
15
+ */
16
+ name: string;
17
+ /**
18
+ * Place data
19
+ * 地点数据
20
+ */
21
+ place?: AddressPlaceBase;
22
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Address location
3
+ * 地理位置
4
+ */
5
+ export type AddressLocation = {
6
+ /**
7
+ * Latitude, 纬度
8
+ */
9
+ lat: number;
10
+ /**
11
+ * Longitude, 经度
12
+ */
13
+ lng: number;
14
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,28 @@
1
+ import { AddressLocation } from './AddressLocation';
2
+ import { AddressPlaceBase } from './AddressPlaceBase';
3
+ /**
4
+ * Address place
5
+ * 地点
6
+ */
7
+ export type AddressPlace = Omit<AddressPlaceBase, 'location'> & {
8
+ /**
9
+ * Place id
10
+ * 地点编号
11
+ */
12
+ placeId: string;
13
+ /**
14
+ * Name
15
+ * 名称
16
+ */
17
+ name: string;
18
+ /**
19
+ * Location
20
+ * 位置
21
+ */
22
+ location: AddressLocation;
23
+ /**
24
+ * Formatted address
25
+ * 格式化地址
26
+ */
27
+ formattedAddress: string;
28
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,37 @@
1
+ import { AddressLocation } from './AddressLocation';
2
+ /**
3
+ * Address place base
4
+ * 基础地点
5
+ */
6
+ export type AddressPlaceBase = {
7
+ /**
8
+ * Location
9
+ * 位置
10
+ */
11
+ location?: AddressLocation;
12
+ /**
13
+ * Region or country, like CN = China
14
+ * 地区或国家,比如 CN 表示中国
15
+ */
16
+ region?: string;
17
+ /**
18
+ * State or province
19
+ * 州 / 省
20
+ */
21
+ state?: string;
22
+ /**
23
+ * City
24
+ * 城市
25
+ */
26
+ city?: string;
27
+ /**
28
+ * District
29
+ * 区县
30
+ */
31
+ district?: string;
32
+ /**
33
+ * Postcode
34
+ * 邮编
35
+ */
36
+ postcode?: string;
37
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -7,10 +7,20 @@ import { IApiPayload } from '@etsoo/restclient';
7
7
  import { RegionsRQ } from './rq/RegionsRQ';
8
8
  import { AddressCity } from '../address/AddressCity';
9
9
  import { AddressDistrict } from '../address/AddressDistrict';
10
+ import { PlaceQueryRQ } from './rq/PlaceQueryRQ';
11
+ import { AddressAutocomplete } from '../address/AddressAutocomplete';
12
+ import { AddressPlace } from '../address/AddressPlace';
10
13
  /**
11
14
  * Address Api
12
15
  */
13
16
  export declare class AddressApi extends BaseApi {
17
+ /**
18
+ * Place autocomplete
19
+ * @param rq Request data
20
+ * @param payload Payload
21
+ * @returns Result
22
+ */
23
+ autocomplete(rq: PlaceQueryRQ, payload?: IApiPayload<AddressAutocomplete[]>): Promise<AddressAutocomplete[] | undefined>;
14
24
  /**
15
25
  * Get all continents
16
26
  * @param isNumberKey Is number key or key as id
@@ -65,25 +75,44 @@ export declare class AddressApi extends BaseApi {
65
75
  /**
66
76
  * Get state list
67
77
  * @param regionId Region id
78
+ * @param favoredIds Favored ids
68
79
  * @param payload Payload
69
80
  * @param culture Culture
70
81
  * @returns Result
71
82
  */
72
- states(regionId: string, payload?: IApiPayload<AddressState[]>, culture?: string): Promise<AddressState[] | undefined>;
83
+ states(regionId: string, favoredIds?: string[], payload?: IApiPayload<AddressState[]>, culture?: string): Promise<AddressState[] | undefined>;
73
84
  /**
74
85
  * Get city list
75
86
  * @param stateId State id
87
+ * @param favoredIds Favored ids
76
88
  * @param payload Payload
77
89
  * @param culture Culture
90
+ *
78
91
  * @returns Result
79
92
  */
80
- cities(stateId: string, payload?: IApiPayload<AddressCity[]>, culture?: string): Promise<AddressCity[] | undefined>;
93
+ cities(stateId: string, favoredIds?: number[], payload?: IApiPayload<AddressCity[]>, culture?: string): Promise<AddressCity[] | undefined>;
81
94
  /**
82
95
  * Get district list
83
96
  * @param cityId City id
97
+ * @param favoredIds Favored ids
84
98
  * @param payload Payload
85
99
  * @param culture Culture
86
100
  * @returns Result
87
101
  */
88
- districts(cityId: number, payload?: IApiPayload<AddressDistrict[]>, culture?: string): Promise<AddressDistrict[] | undefined>;
102
+ districts(cityId: number, favoredIds?: number[], payload?: IApiPayload<AddressDistrict[]>, culture?: string): Promise<AddressDistrict[] | undefined>;
103
+ /**
104
+ * Get place details
105
+ * @param placeId Place id
106
+ * @param language Language
107
+ * @param payload Payload
108
+ * @returns Result
109
+ */
110
+ GetPlaceDetails(placeId: string, language?: string, payload?: IApiPayload<AddressPlace>): Promise<AddressPlace | undefined>;
111
+ /**
112
+ * Place autocomplete
113
+ * @param rq Request data
114
+ * @param payload Payload
115
+ * @returns Result
116
+ */
117
+ searchPlace(rq: PlaceQueryRQ, payload?: IApiPayload<AddressPlace[]>): Promise<AddressPlace[] | undefined>;
89
118
  }
@@ -1,4 +1,4 @@
1
- import { DataTypes } from '@etsoo/shared';
1
+ import { DataTypes, Utils } from '@etsoo/shared';
2
2
  import { AddressContinent } from '../address/AddressContinent';
3
3
  import { AddressRegion } from '../address/AddressRegion';
4
4
  import { BaseApi } from './BaseApi';
@@ -7,6 +7,15 @@ const cachedRegions = {};
7
7
  * Address Api
8
8
  */
9
9
  export class AddressApi extends BaseApi {
10
+ /**
11
+ * Place autocomplete
12
+ * @param rq Request data
13
+ * @param payload Payload
14
+ * @returns Result
15
+ */
16
+ autocomplete(rq, payload) {
17
+ return this.api.post('Address/Autocomplete', rq, payload);
18
+ }
10
19
  /**
11
20
  * Get all continents
12
21
  * @param isNumberKey Is number key or key as id
@@ -91,17 +100,7 @@ export class AddressApi extends BaseApi {
91
100
  });
92
101
  // Order by favoredIds
93
102
  if (favoredIds.length > 0) {
94
- regions = [...regions].sort((r1, r2) => {
95
- const n1 = favoredIds.indexOf(r1.id);
96
- const n2 = favoredIds.indexOf(r2.id);
97
- if (n1 === n2)
98
- return 0;
99
- if (n1 === -1)
100
- return 1;
101
- if (n2 === -1)
102
- return -1;
103
- return n1 - n2;
104
- });
103
+ regions = Utils.sortByFieldFavor([...regions], 'id', favoredIds);
105
104
  }
106
105
  // Return the top items
107
106
  return regions.slice(0, items);
@@ -140,37 +139,70 @@ export class AddressApi extends BaseApi {
140
139
  /**
141
140
  * Get state list
142
141
  * @param regionId Region id
142
+ * @param favoredIds Favored ids
143
143
  * @param payload Payload
144
144
  * @param culture Culture
145
145
  * @returns Result
146
146
  */
147
- states(regionId, payload, culture) {
147
+ async states(regionId, favoredIds = [], payload, culture) {
148
148
  payload !== null && payload !== void 0 ? payload : (payload = { defaultValue: [], showLoading: false });
149
149
  culture !== null && culture !== void 0 ? culture : (culture = this.app.culture);
150
- return this.api.get(`Address/StateList?regionId=${regionId}&language=${culture}`, undefined, payload);
150
+ var items = await this.api.get(`Address/StateList?regionId=${regionId}&language=${culture}`, undefined, payload);
151
+ if (items == null || favoredIds.length === 0)
152
+ return items;
153
+ return Utils.sortByFieldFavor(items, 'id', favoredIds);
151
154
  }
152
155
  /**
153
156
  * Get city list
154
157
  * @param stateId State id
158
+ * @param favoredIds Favored ids
155
159
  * @param payload Payload
156
160
  * @param culture Culture
161
+ *
157
162
  * @returns Result
158
163
  */
159
- cities(stateId, payload, culture) {
164
+ async cities(stateId, favoredIds = [], payload, culture) {
160
165
  payload !== null && payload !== void 0 ? payload : (payload = { defaultValue: [], showLoading: false });
161
166
  culture !== null && culture !== void 0 ? culture : (culture = this.app.culture);
162
- return this.api.get(`Address/CityList?stateId=${stateId}&language=${culture}`, undefined, payload);
167
+ const items = await this.api.get(`Address/CityList?stateId=${stateId}&language=${culture}`, undefined, payload);
168
+ if (items == null || favoredIds.length === 0)
169
+ return items;
170
+ return Utils.sortByFieldFavor(items, 'id', favoredIds);
163
171
  }
164
172
  /**
165
173
  * Get district list
166
174
  * @param cityId City id
175
+ * @param favoredIds Favored ids
167
176
  * @param payload Payload
168
177
  * @param culture Culture
169
178
  * @returns Result
170
179
  */
171
- districts(cityId, payload, culture) {
180
+ async districts(cityId, favoredIds = [], payload, culture) {
172
181
  payload !== null && payload !== void 0 ? payload : (payload = { defaultValue: [], showLoading: false });
173
182
  culture !== null && culture !== void 0 ? culture : (culture = this.app.culture);
174
- return this.api.get(`Address/DistrictList?cityId=${cityId}&language=${culture}`, undefined, payload);
183
+ const items = await this.api.get(`Address/DistrictList?cityId=${cityId}&language=${culture}`, undefined, payload);
184
+ if (items == null || favoredIds.length === 0)
185
+ return items;
186
+ return Utils.sortByFieldFavor(items, 'id', favoredIds);
187
+ }
188
+ /**
189
+ * Get place details
190
+ * @param placeId Place id
191
+ * @param language Language
192
+ * @param payload Payload
193
+ * @returns Result
194
+ */
195
+ GetPlaceDetails(placeId, language, payload) {
196
+ const url = `Address/GetPlaceDetails/${placeId}/${language == null ? '' : language}`;
197
+ return this.api.get(url, undefined, payload);
198
+ }
199
+ /**
200
+ * Place autocomplete
201
+ * @param rq Request data
202
+ * @param payload Payload
203
+ * @returns Result
204
+ */
205
+ searchPlace(rq, payload) {
206
+ return this.api.post('Address/SearchPlace', rq, payload);
175
207
  }
176
208
  }
@@ -0,0 +1,45 @@
1
+ import { AddressLocation } from '../../address/AddressLocation';
2
+ /**
3
+ * Place query output type
4
+ * 地址查询输出类型
5
+ */
6
+ export declare enum PlaceQueryOutput {
7
+ JSON = 0,
8
+ XML = 1
9
+ }
10
+ /**
11
+ * Place query request data
12
+ * 地址查询请求数据
13
+ */
14
+ export type PlaceQueryRQ = {
15
+ /**
16
+ * Query address
17
+ * 查询地址
18
+ */
19
+ query: string;
20
+ /**
21
+ * Output type
22
+ * 输出类型
23
+ */
24
+ output?: PlaceQueryOutput;
25
+ /**
26
+ * Language
27
+ * 语言
28
+ */
29
+ language?: string;
30
+ /**
31
+ * Limited region / country id, like CN
32
+ * 限定的地区获国家编号
33
+ */
34
+ region?: string;
35
+ /**
36
+ * Center location
37
+ * 中心位置
38
+ */
39
+ location?: AddressLocation;
40
+ /**
41
+ * Circle radius
42
+ * 方圆半径
43
+ */
44
+ radius?: number;
45
+ };
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Place query output type
3
+ * 地址查询输出类型
4
+ */
5
+ export var PlaceQueryOutput;
6
+ (function (PlaceQueryOutput) {
7
+ PlaceQueryOutput[PlaceQueryOutput["JSON"] = 0] = "JSON";
8
+ PlaceQueryOutput[PlaceQueryOutput["XML"] = 1] = "XML";
9
+ })(PlaceQueryOutput || (PlaceQueryOutput = {}));
@@ -1,6 +1,10 @@
1
+ export * from './address/AddressAutocomplete';
1
2
  export * from './address/AddressCity';
2
3
  export * from './address/AddressContinent';
3
4
  export * from './address/AddressDistrict';
5
+ export * from './address/AddressLocation';
6
+ export * from './address/AddressPlace';
7
+ export * from './address/AddressPlaceBase';
4
8
  export * from './address/AddressRegion';
5
9
  export * from './address/AddressState';
6
10
  export * from './address/AddressUtils';
@@ -36,6 +40,7 @@ export * from './erp/rq/LoginRQ';
36
40
  export * from './erp/rq/MemberListRQ';
37
41
  export * from './erp/rq/OrgListRQ';
38
42
  export * from './erp/rq/OrgQueryRQ';
43
+ export * from './erp/rq/PlaceQueryRQ';
39
44
  export * from './erp/rq/QueryRQ';
40
45
  export * from './erp/rq/RefreshTokenRQ';
41
46
  export * from './erp/rq/RegionsRQ';
package/lib/mjs/index.js CHANGED
@@ -1,7 +1,11 @@
1
1
  // address
2
+ export * from './address/AddressAutocomplete';
2
3
  export * from './address/AddressCity';
3
4
  export * from './address/AddressContinent';
4
5
  export * from './address/AddressDistrict';
6
+ export * from './address/AddressLocation';
7
+ export * from './address/AddressPlace';
8
+ export * from './address/AddressPlaceBase';
5
9
  export * from './address/AddressRegion';
6
10
  export * from './address/AddressState';
7
11
  export * from './address/AddressUtils';
@@ -43,6 +47,7 @@ export * from './erp/rq/LoginRQ';
43
47
  export * from './erp/rq/MemberListRQ';
44
48
  export * from './erp/rq/OrgListRQ';
45
49
  export * from './erp/rq/OrgQueryRQ';
50
+ export * from './erp/rq/PlaceQueryRQ';
46
51
  export * from './erp/rq/QueryRQ';
47
52
  export * from './erp/rq/RefreshTokenRQ';
48
53
  export * from './erp/rq/RegionsRQ';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/appscript",
3
- "version": "1.3.70",
3
+ "version": "1.3.71",
4
4
  "description": "Applications shared TypeScript framework",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/mjs/index.js",
@@ -54,7 +54,7 @@
54
54
  "dependencies": {
55
55
  "@etsoo/notificationbase": "^1.1.24",
56
56
  "@etsoo/restclient": "^1.0.87",
57
- "@etsoo/shared": "^1.1.89",
57
+ "@etsoo/shared": "^1.1.90",
58
58
  "@types/crypto-js": "^4.1.1",
59
59
  "crypto-js": "^4.1.1"
60
60
  },
@@ -65,8 +65,8 @@
65
65
  "@babel/preset-env": "^7.20.2",
66
66
  "@babel/runtime-corejs3": "^7.21.0",
67
67
  "@types/jest": "^29.4.0",
68
- "jest": "^29.4.3",
69
- "jest-environment-jsdom": "^29.4.3",
68
+ "jest": "^29.5.0",
69
+ "jest-environment-jsdom": "^29.5.0",
70
70
  "ts-jest": "^29.0.5",
71
71
  "typescript": "^4.9.5"
72
72
  }
@@ -0,0 +1,25 @@
1
+ import { AddressPlaceBase } from './AddressPlaceBase';
2
+
3
+ /**
4
+ * Address autocomplete
5
+ * 地点自动填充
6
+ */
7
+ export type AddressAutocomplete = {
8
+ /**
9
+ * Place id
10
+ * 地点编号
11
+ */
12
+ placeId: string;
13
+
14
+ /**
15
+ * Name
16
+ * 名称
17
+ */
18
+ name: string;
19
+
20
+ /**
21
+ * Place data
22
+ * 地点数据
23
+ */
24
+ place?: AddressPlaceBase;
25
+ };
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Address location
3
+ * 地理位置
4
+ */
5
+ export type AddressLocation = {
6
+ /**
7
+ * Latitude, 纬度
8
+ */
9
+ lat: number;
10
+
11
+ /**
12
+ * Longitude, 经度
13
+ */
14
+ lng: number;
15
+ };
@@ -0,0 +1,32 @@
1
+ import { AddressLocation } from './AddressLocation';
2
+ import { AddressPlaceBase } from './AddressPlaceBase';
3
+
4
+ /**
5
+ * Address place
6
+ * 地点
7
+ */
8
+ export type AddressPlace = Omit<AddressPlaceBase, 'location'> & {
9
+ /**
10
+ * Place id
11
+ * 地点编号
12
+ */
13
+ placeId: string;
14
+
15
+ /**
16
+ * Name
17
+ * 名称
18
+ */
19
+ name: string;
20
+
21
+ /**
22
+ * Location
23
+ * 位置
24
+ */
25
+ location: AddressLocation;
26
+
27
+ /**
28
+ * Formatted address
29
+ * 格式化地址
30
+ */
31
+ formattedAddress: string;
32
+ };
@@ -0,0 +1,43 @@
1
+ import { AddressLocation } from './AddressLocation';
2
+
3
+ /**
4
+ * Address place base
5
+ * 基础地点
6
+ */
7
+ export type AddressPlaceBase = {
8
+ /**
9
+ * Location
10
+ * 位置
11
+ */
12
+ location?: AddressLocation;
13
+
14
+ /**
15
+ * Region or country, like CN = China
16
+ * 地区或国家,比如 CN 表示中国
17
+ */
18
+ region?: string;
19
+
20
+ /**
21
+ * State or province
22
+ * 州 / 省
23
+ */
24
+ state?: string;
25
+
26
+ /**
27
+ * City
28
+ * 城市
29
+ */
30
+ city?: string;
31
+
32
+ /**
33
+ * District
34
+ * 区县
35
+ */
36
+ district?: string;
37
+
38
+ /**
39
+ * Postcode
40
+ * 邮编
41
+ */
42
+ postcode?: string;
43
+ };
@@ -1,4 +1,4 @@
1
- import { DataTypes } from '@etsoo/shared';
1
+ import { DataTypes, Utils } from '@etsoo/shared';
2
2
  import { AddressContinent } from '../address/AddressContinent';
3
3
  import { AddressRegion, AddressRegionDb } from '../address/AddressRegion';
4
4
  import { AddressState } from '../address/AddressState';
@@ -8,6 +8,9 @@ import { IApiPayload } from '@etsoo/restclient';
8
8
  import { RegionsRQ } from './rq/RegionsRQ';
9
9
  import { AddressCity } from '../address/AddressCity';
10
10
  import { AddressDistrict } from '../address/AddressDistrict';
11
+ import { PlaceQueryRQ } from './rq/PlaceQueryRQ';
12
+ import { AddressAutocomplete } from '../address/AddressAutocomplete';
13
+ import { AddressPlace } from '../address/AddressPlace';
11
14
 
12
15
  const cachedRegions: { [P: string]: AddressRegionDb[] | undefined | null } = {};
13
16
 
@@ -15,6 +18,19 @@ const cachedRegions: { [P: string]: AddressRegionDb[] | undefined | null } = {};
15
18
  * Address Api
16
19
  */
17
20
  export class AddressApi extends BaseApi {
21
+ /**
22
+ * Place autocomplete
23
+ * @param rq Request data
24
+ * @param payload Payload
25
+ * @returns Result
26
+ */
27
+ autocomplete(
28
+ rq: PlaceQueryRQ,
29
+ payload?: IApiPayload<AddressAutocomplete[]>
30
+ ) {
31
+ return this.api.post('Address/Autocomplete', rq, payload);
32
+ }
33
+
18
34
  /**
19
35
  * Get all continents
20
36
  * @param isNumberKey Is number key or key as id
@@ -108,15 +124,7 @@ export class AddressApi extends BaseApi {
108
124
 
109
125
  // Order by favoredIds
110
126
  if (favoredIds.length > 0) {
111
- regions = [...regions].sort((r1, r2) => {
112
- const n1 = favoredIds.indexOf(r1.id);
113
- const n2 = favoredIds.indexOf(r2.id);
114
-
115
- if (n1 === n2) return 0;
116
- if (n1 === -1) return 1;
117
- if (n2 === -1) return -1;
118
- return n1 - n2;
119
- });
127
+ regions = Utils.sortByFieldFavor([...regions], 'id', favoredIds);
120
128
  }
121
129
 
122
130
  // Return the top items
@@ -171,66 +179,110 @@ export class AddressApi extends BaseApi {
171
179
  /**
172
180
  * Get state list
173
181
  * @param regionId Region id
182
+ * @param favoredIds Favored ids
174
183
  * @param payload Payload
175
184
  * @param culture Culture
176
185
  * @returns Result
177
186
  */
178
- states(
187
+ async states(
179
188
  regionId: string,
189
+ favoredIds: string[] = [],
180
190
  payload?: IApiPayload<AddressState[]>,
181
191
  culture?: string
182
192
  ) {
183
193
  payload ??= { defaultValue: [], showLoading: false };
184
194
  culture ??= this.app.culture;
185
195
 
186
- return this.api.get(
196
+ var items = await this.api.get(
187
197
  `Address/StateList?regionId=${regionId}&language=${culture}`,
188
198
  undefined,
189
199
  payload
190
200
  );
201
+
202
+ if (items == null || favoredIds.length === 0) return items;
203
+ return Utils.sortByFieldFavor(items, 'id', favoredIds);
191
204
  }
192
205
 
193
206
  /**
194
207
  * Get city list
195
208
  * @param stateId State id
209
+ * @param favoredIds Favored ids
196
210
  * @param payload Payload
197
211
  * @param culture Culture
212
+ *
198
213
  * @returns Result
199
214
  */
200
- cities(
215
+ async cities(
201
216
  stateId: string,
217
+ favoredIds: number[] = [],
202
218
  payload?: IApiPayload<AddressCity[]>,
203
219
  culture?: string
204
220
  ) {
205
221
  payload ??= { defaultValue: [], showLoading: false };
206
222
  culture ??= this.app.culture;
207
223
 
208
- return this.api.get(
224
+ const items = await this.api.get(
209
225
  `Address/CityList?stateId=${stateId}&language=${culture}`,
210
226
  undefined,
211
227
  payload
212
228
  );
229
+
230
+ if (items == null || favoredIds.length === 0) return items;
231
+ return Utils.sortByFieldFavor(items, 'id', favoredIds);
213
232
  }
214
233
 
215
234
  /**
216
235
  * Get district list
217
236
  * @param cityId City id
237
+ * @param favoredIds Favored ids
218
238
  * @param payload Payload
219
239
  * @param culture Culture
220
240
  * @returns Result
221
241
  */
222
- districts(
242
+ async districts(
223
243
  cityId: number,
244
+ favoredIds: number[] = [],
224
245
  payload?: IApiPayload<AddressDistrict[]>,
225
246
  culture?: string
226
247
  ) {
227
248
  payload ??= { defaultValue: [], showLoading: false };
228
249
  culture ??= this.app.culture;
229
250
 
230
- return this.api.get(
251
+ const items = await this.api.get(
231
252
  `Address/DistrictList?cityId=${cityId}&language=${culture}`,
232
253
  undefined,
233
254
  payload
234
255
  );
256
+
257
+ if (items == null || favoredIds.length === 0) return items;
258
+ return Utils.sortByFieldFavor(items, 'id', favoredIds);
259
+ }
260
+
261
+ /**
262
+ * Get place details
263
+ * @param placeId Place id
264
+ * @param language Language
265
+ * @param payload Payload
266
+ * @returns Result
267
+ */
268
+ GetPlaceDetails(
269
+ placeId: string,
270
+ language?: string,
271
+ payload?: IApiPayload<AddressPlace>
272
+ ) {
273
+ const url = `Address/GetPlaceDetails/${placeId}/${
274
+ language == null ? '' : language
275
+ }`;
276
+ return this.api.get(url, undefined, payload);
277
+ }
278
+
279
+ /**
280
+ * Place autocomplete
281
+ * @param rq Request data
282
+ * @param payload Payload
283
+ * @returns Result
284
+ */
285
+ searchPlace(rq: PlaceQueryRQ, payload?: IApiPayload<AddressPlace[]>) {
286
+ return this.api.post('Address/SearchPlace', rq, payload);
235
287
  }
236
288
  }
@@ -0,0 +1,52 @@
1
+ import { AddressLocation } from '../../address/AddressLocation';
2
+
3
+ /**
4
+ * Place query output type
5
+ * 地址查询输出类型
6
+ */
7
+ export enum PlaceQueryOutput {
8
+ JSON,
9
+ XML
10
+ }
11
+
12
+ /**
13
+ * Place query request data
14
+ * 地址查询请求数据
15
+ */
16
+ export type PlaceQueryRQ = {
17
+ /**
18
+ * Query address
19
+ * 查询地址
20
+ */
21
+ query: string;
22
+
23
+ /**
24
+ * Output type
25
+ * 输出类型
26
+ */
27
+ output?: PlaceQueryOutput;
28
+
29
+ /**
30
+ * Language
31
+ * 语言
32
+ */
33
+ language?: string;
34
+
35
+ /**
36
+ * Limited region / country id, like CN
37
+ * 限定的地区获国家编号
38
+ */
39
+ region?: string;
40
+
41
+ /**
42
+ * Center location
43
+ * 中心位置
44
+ */
45
+ location?: AddressLocation;
46
+
47
+ /**
48
+ * Circle radius
49
+ * 方圆半径
50
+ */
51
+ radius?: number;
52
+ };
package/src/index.ts CHANGED
@@ -1,7 +1,11 @@
1
1
  // address
2
+ export * from './address/AddressAutocomplete';
2
3
  export * from './address/AddressCity';
3
4
  export * from './address/AddressContinent';
4
5
  export * from './address/AddressDistrict';
6
+ export * from './address/AddressLocation';
7
+ export * from './address/AddressPlace';
8
+ export * from './address/AddressPlaceBase';
5
9
  export * from './address/AddressRegion';
6
10
  export * from './address/AddressState';
7
11
  export * from './address/AddressUtils';
@@ -49,6 +53,7 @@ export * from './erp/rq/LoginRQ';
49
53
  export * from './erp/rq/MemberListRQ';
50
54
  export * from './erp/rq/OrgListRQ';
51
55
  export * from './erp/rq/OrgQueryRQ';
56
+ export * from './erp/rq/PlaceQueryRQ';
52
57
  export * from './erp/rq/QueryRQ';
53
58
  export * from './erp/rq/RefreshTokenRQ';
54
59
  export * from './erp/rq/RegionsRQ';