@aws-amplify/geo 3.0.1-api-v6-models.9351bcf.0 → 3.0.1-api-v6-models.891fe0d.0
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.
- package/lib/Geo.js +135 -229
- package/lib/index.js +1 -1
- package/lib/providers/location-service/AmazonLocationServiceProvider.js +494 -617
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/types/index.js +1 -1
- package/lib/util.js +37 -37
- package/lib-esm/Geo.js +133 -227
- package/lib-esm/providers/location-service/AmazonLocationServiceProvider.js +488 -612
- package/lib-esm/tsconfig.tsbuildinfo +1 -1
- package/lib-esm/util.js +34 -35
- package/package.json +5 -8
package/lib/Geo.js
CHANGED
|
@@ -1,22 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Geo = exports.GeoClass = void 0;
|
|
4
|
-
var tslib_1 = require("tslib");
|
|
5
4
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
6
5
|
// SPDX-License-Identifier: Apache-2.0
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
var _a;
|
|
6
|
+
const core_1 = require("@aws-amplify/core");
|
|
7
|
+
const AmazonLocationServiceProvider_1 = require("./providers/location-service/AmazonLocationServiceProvider");
|
|
8
|
+
const util_1 = require("./util");
|
|
9
|
+
const logger = new core_1.ConsoleLogger('Geo');
|
|
10
|
+
const DEFAULT_PROVIDER = 'AmazonLocationService';
|
|
11
|
+
class GeoClass {
|
|
12
|
+
constructor() {
|
|
15
13
|
this._config = {};
|
|
16
14
|
this._pluggables = [];
|
|
17
|
-
|
|
15
|
+
const amplifyConfig = core_1.Amplify.getConfig() ?? {};
|
|
18
16
|
this._config = Object.assign({}, this._config, amplifyConfig.Geo);
|
|
19
|
-
|
|
17
|
+
const locationProvider = new AmazonLocationServiceProvider_1.AmazonLocationServiceProvider(amplifyConfig.Geo);
|
|
20
18
|
this._pluggables.push(locationProvider);
|
|
21
19
|
logger.debug('Geo Options', this._config);
|
|
22
20
|
}
|
|
@@ -24,176 +22,127 @@ var GeoClass = exports.GeoClass = /** @class */ (function () {
|
|
|
24
22
|
* get the name of the module category
|
|
25
23
|
* @returns {string} name of the module category
|
|
26
24
|
*/
|
|
27
|
-
|
|
25
|
+
getModuleName() {
|
|
28
26
|
return GeoClass.MODULE;
|
|
29
|
-
}
|
|
27
|
+
}
|
|
30
28
|
/**
|
|
31
29
|
* add plugin into Geo category
|
|
32
30
|
* @param {Object} pluggable - an instance of the plugin
|
|
33
31
|
*/
|
|
34
|
-
|
|
32
|
+
addPluggable(pluggable) {
|
|
35
33
|
if (pluggable && pluggable.getCategory() === 'Geo') {
|
|
36
34
|
this._pluggables.push(pluggable);
|
|
37
35
|
}
|
|
38
|
-
}
|
|
36
|
+
}
|
|
39
37
|
/**
|
|
40
38
|
* Get the plugin object
|
|
41
39
|
* @param providerName - the name of the plugin
|
|
42
40
|
*/
|
|
43
|
-
|
|
44
|
-
|
|
41
|
+
getPluggable(providerName) {
|
|
42
|
+
const pluggable = this._pluggables.find(pluggable => pluggable.getProviderName() === providerName);
|
|
45
43
|
if (pluggable === undefined) {
|
|
46
44
|
logger.debug('No plugin found with providerName', providerName);
|
|
47
45
|
throw new Error('No plugin found in Geo for the provider');
|
|
48
46
|
}
|
|
49
47
|
else
|
|
50
48
|
return pluggable;
|
|
51
|
-
}
|
|
49
|
+
}
|
|
52
50
|
/**
|
|
53
51
|
* Remove the plugin object
|
|
54
52
|
* @param providerName - the name of the plugin
|
|
55
53
|
*/
|
|
56
|
-
|
|
57
|
-
this._pluggables = this._pluggables.filter(
|
|
54
|
+
removePluggable(providerName) {
|
|
55
|
+
this._pluggables = this._pluggables.filter(pluggable => pluggable.getProviderName() !== providerName);
|
|
58
56
|
return;
|
|
59
|
-
}
|
|
57
|
+
}
|
|
60
58
|
/**
|
|
61
59
|
* Get the map resources that are currently available through the provider
|
|
62
60
|
* @param {string} provider
|
|
63
61
|
* @returns - Array of available map resources
|
|
64
62
|
*/
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
var prov = this.getPluggable(provider);
|
|
63
|
+
getAvailableMaps(provider = DEFAULT_PROVIDER) {
|
|
64
|
+
const prov = this.getPluggable(provider);
|
|
68
65
|
return prov.getAvailableMaps();
|
|
69
|
-
}
|
|
66
|
+
}
|
|
70
67
|
/**
|
|
71
68
|
* Get the map resource set as default in amplify config
|
|
72
69
|
* @param {string} provider
|
|
73
70
|
* @returns - Map resource set as the default in amplify config
|
|
74
71
|
*/
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
var prov = this.getPluggable(provider);
|
|
72
|
+
getDefaultMap(provider = DEFAULT_PROVIDER) {
|
|
73
|
+
const prov = this.getPluggable(provider);
|
|
78
74
|
return prov.getDefaultMap();
|
|
79
|
-
}
|
|
75
|
+
}
|
|
80
76
|
/**
|
|
81
77
|
* Search by text input with optional parameters
|
|
82
78
|
* @param {string} text - The text string that is to be searched for
|
|
83
79
|
* @param {SearchByTextOptions} options? - Optional parameters to the search
|
|
84
80
|
* @returns {Promise<Place[]>} - Promise resolves to a list of Places that match search parameters
|
|
85
81
|
*/
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
return
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
_b.trys.push([1, 3, , 4]);
|
|
98
|
-
return [4 /*yield*/, prov.searchByText(text, options)];
|
|
99
|
-
case 2: return [2 /*return*/, _b.sent()];
|
|
100
|
-
case 3:
|
|
101
|
-
error_1 = _b.sent();
|
|
102
|
-
logger.debug(error_1);
|
|
103
|
-
throw error_1;
|
|
104
|
-
case 4: return [2 /*return*/];
|
|
105
|
-
}
|
|
106
|
-
});
|
|
107
|
-
});
|
|
108
|
-
};
|
|
82
|
+
async searchByText(text, options) {
|
|
83
|
+
const { providerName = DEFAULT_PROVIDER } = options || {};
|
|
84
|
+
const prov = this.getPluggable(providerName);
|
|
85
|
+
try {
|
|
86
|
+
return await prov.searchByText(text, options);
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
89
|
+
logger.debug(error);
|
|
90
|
+
throw error;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
109
93
|
/**
|
|
110
94
|
* Search for search term suggestions based on input text
|
|
111
95
|
* @param {string} text - The text string that is to be search for
|
|
112
96
|
* @param {SearchByTextOptions} options? - Optional parameters to the search
|
|
113
97
|
* @returns {Promise<SearchForSuggestionsResults>} - Resolves to an array of search suggestion strings
|
|
114
98
|
*/
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
return
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
_b.trys.push([1, 3, , 4]);
|
|
127
|
-
return [4 /*yield*/, prov.searchForSuggestions(text, options)];
|
|
128
|
-
case 2: return [2 /*return*/, _b.sent()];
|
|
129
|
-
case 3:
|
|
130
|
-
error_2 = _b.sent();
|
|
131
|
-
logger.debug(error_2);
|
|
132
|
-
throw error_2;
|
|
133
|
-
case 4: return [2 /*return*/];
|
|
134
|
-
}
|
|
135
|
-
});
|
|
136
|
-
});
|
|
137
|
-
};
|
|
99
|
+
async searchForSuggestions(text, options) {
|
|
100
|
+
const { providerName = DEFAULT_PROVIDER } = options || {};
|
|
101
|
+
const prov = this.getPluggable(providerName);
|
|
102
|
+
try {
|
|
103
|
+
return await prov.searchForSuggestions(text, options);
|
|
104
|
+
}
|
|
105
|
+
catch (error) {
|
|
106
|
+
logger.debug(error);
|
|
107
|
+
throw error;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
138
110
|
/**
|
|
139
111
|
* Search for location by unique ID
|
|
140
112
|
* @param {string} placeId - Unique ID of the location that is to be searched for
|
|
141
113
|
* @param {searchByPlaceIdOptions} options? - Optional parameters to the search
|
|
142
114
|
* @returns {Promise<Place>} - Resolves to a place with the given placeId
|
|
143
115
|
*/
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
return [4 /*yield*/, prov.searchByPlaceId(placeId, options)];
|
|
156
|
-
case 2: return [2 /*return*/, _a.sent()];
|
|
157
|
-
case 3:
|
|
158
|
-
error_3 = _a.sent();
|
|
159
|
-
logger.debug(error_3);
|
|
160
|
-
throw error_3;
|
|
161
|
-
case 4: return [2 /*return*/];
|
|
162
|
-
}
|
|
163
|
-
});
|
|
164
|
-
});
|
|
165
|
-
};
|
|
116
|
+
async searchByPlaceId(placeId, options) {
|
|
117
|
+
const providerName = DEFAULT_PROVIDER;
|
|
118
|
+
const prov = this.getPluggable(providerName);
|
|
119
|
+
try {
|
|
120
|
+
return await prov.searchByPlaceId(placeId, options);
|
|
121
|
+
}
|
|
122
|
+
catch (error) {
|
|
123
|
+
logger.debug(error);
|
|
124
|
+
throw error;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
166
127
|
/**
|
|
167
128
|
* Reverse geocoding search via a coordinate point on the map
|
|
168
129
|
* @param coordinates - Coordinates array for the search input
|
|
169
130
|
* @param options - Options parameters for the search
|
|
170
131
|
* @returns {Promise<Place>} - Promise that resolves to a place matching search coordinates
|
|
171
132
|
*/
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
(0, util_1.validateCoordinates)(lng, lat);
|
|
186
|
-
return [4 /*yield*/, prov.searchByCoordinates(coordinates, options)];
|
|
187
|
-
case 2: return [2 /*return*/, _c.sent()];
|
|
188
|
-
case 3:
|
|
189
|
-
error_4 = _c.sent();
|
|
190
|
-
logger.debug(error_4);
|
|
191
|
-
throw error_4;
|
|
192
|
-
case 4: return [2 /*return*/];
|
|
193
|
-
}
|
|
194
|
-
});
|
|
195
|
-
});
|
|
196
|
-
};
|
|
133
|
+
async searchByCoordinates(coordinates, options) {
|
|
134
|
+
const { providerName = DEFAULT_PROVIDER } = options || {};
|
|
135
|
+
const prov = this.getPluggable(providerName);
|
|
136
|
+
const [lng, lat] = coordinates;
|
|
137
|
+
try {
|
|
138
|
+
(0, util_1.validateCoordinates)(lng, lat);
|
|
139
|
+
return await prov.searchByCoordinates(coordinates, options);
|
|
140
|
+
}
|
|
141
|
+
catch (error) {
|
|
142
|
+
logger.debug(error);
|
|
143
|
+
throw error;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
197
146
|
/**
|
|
198
147
|
* Create geofences
|
|
199
148
|
* @param geofences - Single or array of geofence objects to create
|
|
@@ -202,64 +151,42 @@ var GeoClass = exports.GeoClass = /** @class */ (function () {
|
|
|
202
151
|
* successes: list of geofences successfully created
|
|
203
152
|
* errors: list of geofences that failed to create
|
|
204
153
|
*/
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
case 2: return [2 /*return*/, _b.sent()];
|
|
225
|
-
case 3:
|
|
226
|
-
error_5 = _b.sent();
|
|
227
|
-
logger.debug(error_5);
|
|
228
|
-
throw error_5;
|
|
229
|
-
case 4: return [2 /*return*/];
|
|
230
|
-
}
|
|
231
|
-
});
|
|
232
|
-
});
|
|
233
|
-
};
|
|
154
|
+
async saveGeofences(geofences, options) {
|
|
155
|
+
const { providerName = DEFAULT_PROVIDER } = options || {};
|
|
156
|
+
const prov = this.getPluggable(providerName);
|
|
157
|
+
// If single geofence input, make it an array for batch call
|
|
158
|
+
let geofenceInputArray;
|
|
159
|
+
if (!Array.isArray(geofences)) {
|
|
160
|
+
geofenceInputArray = [geofences];
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
geofenceInputArray = geofences;
|
|
164
|
+
}
|
|
165
|
+
try {
|
|
166
|
+
return await prov.saveGeofences(geofenceInputArray, options);
|
|
167
|
+
}
|
|
168
|
+
catch (error) {
|
|
169
|
+
logger.debug(error);
|
|
170
|
+
throw error;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
234
173
|
/**
|
|
235
174
|
* Get a single geofence by geofenceId
|
|
236
175
|
* @param geofenceId: GeofenceId - The string id of the geofence to get
|
|
237
176
|
* @param options?: GeofenceOptions - Optional parameters for getting a geofence
|
|
238
177
|
* @returns Promise<Geofence> - Promise that resolves to a geofence object
|
|
239
178
|
*/
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
return
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
_b.trys.push([1, 3, , 4]);
|
|
252
|
-
return [4 /*yield*/, prov.getGeofence(geofenceId, options)];
|
|
253
|
-
case 2: return [2 /*return*/, _b.sent()];
|
|
254
|
-
case 3:
|
|
255
|
-
error_6 = _b.sent();
|
|
256
|
-
logger.debug(error_6);
|
|
257
|
-
throw error_6;
|
|
258
|
-
case 4: return [2 /*return*/];
|
|
259
|
-
}
|
|
260
|
-
});
|
|
261
|
-
});
|
|
262
|
-
};
|
|
179
|
+
async getGeofence(geofenceId, options) {
|
|
180
|
+
const { providerName = DEFAULT_PROVIDER } = options || {};
|
|
181
|
+
const prov = this.getPluggable(providerName);
|
|
182
|
+
try {
|
|
183
|
+
return await prov.getGeofence(geofenceId, options);
|
|
184
|
+
}
|
|
185
|
+
catch (error) {
|
|
186
|
+
logger.debug(error);
|
|
187
|
+
throw error;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
263
190
|
/**
|
|
264
191
|
* List geofences
|
|
265
192
|
* @param options?: ListGeofenceOptions
|
|
@@ -267,29 +194,17 @@ var GeoClass = exports.GeoClass = /** @class */ (function () {
|
|
|
267
194
|
* entries: list of geofences - 100 geofences are listed per page
|
|
268
195
|
* nextToken: token for next page of geofences
|
|
269
196
|
*/
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
return
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
_b.trys.push([1, 3, , 4]);
|
|
282
|
-
return [4 /*yield*/, prov.listGeofences(options)];
|
|
283
|
-
case 2: return [2 /*return*/, _b.sent()];
|
|
284
|
-
case 3:
|
|
285
|
-
error_7 = _b.sent();
|
|
286
|
-
logger.debug(error_7);
|
|
287
|
-
throw error_7;
|
|
288
|
-
case 4: return [2 /*return*/];
|
|
289
|
-
}
|
|
290
|
-
});
|
|
291
|
-
});
|
|
292
|
-
};
|
|
197
|
+
async listGeofences(options) {
|
|
198
|
+
const { providerName = DEFAULT_PROVIDER } = options || {};
|
|
199
|
+
const prov = this.getPluggable(providerName);
|
|
200
|
+
try {
|
|
201
|
+
return await prov.listGeofences(options);
|
|
202
|
+
}
|
|
203
|
+
catch (error) {
|
|
204
|
+
logger.debug(error);
|
|
205
|
+
throw error;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
293
208
|
/**
|
|
294
209
|
* Delete geofences
|
|
295
210
|
* @param geofenceIds: string|string[]
|
|
@@ -298,36 +213,27 @@ var GeoClass = exports.GeoClass = /** @class */ (function () {
|
|
|
298
213
|
* successes: list of geofences successfully deleted
|
|
299
214
|
* errors: list of geofences that failed to delete
|
|
300
215
|
*/
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
throw error_8;
|
|
325
|
-
case 4: return [2 /*return*/];
|
|
326
|
-
}
|
|
327
|
-
});
|
|
328
|
-
});
|
|
329
|
-
};
|
|
330
|
-
GeoClass.MODULE = 'Geo';
|
|
331
|
-
return GeoClass;
|
|
332
|
-
}());
|
|
216
|
+
async deleteGeofences(geofenceIds, options) {
|
|
217
|
+
const { providerName = DEFAULT_PROVIDER } = options || {};
|
|
218
|
+
const prov = this.getPluggable(providerName);
|
|
219
|
+
// If single geofence input, make it an array for batch call
|
|
220
|
+
let geofenceIdsInputArray;
|
|
221
|
+
if (!Array.isArray(geofenceIds)) {
|
|
222
|
+
geofenceIdsInputArray = [geofenceIds];
|
|
223
|
+
}
|
|
224
|
+
else {
|
|
225
|
+
geofenceIdsInputArray = geofenceIds;
|
|
226
|
+
}
|
|
227
|
+
// Delete geofences
|
|
228
|
+
try {
|
|
229
|
+
return await prov.deleteGeofences(geofenceIdsInputArray, options);
|
|
230
|
+
}
|
|
231
|
+
catch (error) {
|
|
232
|
+
logger.debug(error);
|
|
233
|
+
throw error;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
GeoClass.MODULE = 'Geo';
|
|
238
|
+
exports.GeoClass = GeoClass;
|
|
333
239
|
exports.Geo = new GeoClass();
|
package/lib/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.Geo = void 0;
|
|
4
|
-
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
5
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
6
6
|
// SPDX-License-Identifier: Apache-2.0
|
|
7
7
|
var Geo_1 = require("./Geo");
|