@aws-amplify/geo 2.3.6-api-v6-models.b3abc9b.0 → 3.0.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.d.ts +3 -9
- package/lib/Geo.js +137 -243
- package/lib/index.js +4 -2
- package/{lib-esm/Providers → lib/providers/location-service}/AmazonLocationServiceProvider.d.ts +3 -7
- package/lib/providers/location-service/AmazonLocationServiceProvider.js +618 -0
- package/lib/tsconfig.tsbuildinfo +1 -0
- package/lib/types/AmazonLocationServiceProvider.d.ts +7 -7
- package/lib/types/AmazonLocationServiceProvider.js +0 -1
- package/lib/types/Geo.d.ts +28 -45
- package/lib/types/Geo.js +0 -1
- package/lib/types/Provider.d.ts +0 -1
- package/lib/types/Provider.js +0 -1
- package/lib/types/index.js +6 -1
- package/lib/util.d.ts +4 -0
- package/lib/util.js +51 -36
- package/lib-esm/Geo.d.ts +3 -9
- package/lib-esm/Geo.js +136 -243
- package/lib-esm/index.js +1 -1
- package/{lib/Providers → lib-esm/providers/location-service}/AmazonLocationServiceProvider.d.ts +3 -7
- package/lib-esm/providers/location-service/AmazonLocationServiceProvider.js +614 -0
- package/lib-esm/tsconfig.tsbuildinfo +1 -0
- package/lib-esm/types/AmazonLocationServiceProvider.d.ts +7 -7
- package/lib-esm/types/AmazonLocationServiceProvider.js +1 -1
- package/lib-esm/types/Geo.d.ts +28 -45
- package/lib-esm/types/Geo.js +1 -1
- package/lib-esm/types/Provider.d.ts +0 -1
- package/lib-esm/types/Provider.js +1 -1
- package/lib-esm/types/index.js +5 -1
- package/lib-esm/util.d.ts +4 -0
- package/lib-esm/util.js +45 -34
- package/package.json +26 -12
- package/src/Geo.ts +12 -36
- package/src/{Providers → providers/location-service}/AmazonLocationServiceProvider.ts +65 -68
- package/src/types/Geo.ts +1 -17
- package/src/types/Provider.ts +0 -3
- package/src/util.ts +24 -3
- package/lib/.tsbuildinfo +0 -3
- package/lib/Geo.js.map +0 -1
- package/lib/Providers/AmazonLocationServiceProvider.js +0 -737
- package/lib/Providers/AmazonLocationServiceProvider.js.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/types/AmazonLocationServiceProvider.js.map +0 -1
- package/lib/types/Geo.js.map +0 -1
- package/lib/types/Provider.js.map +0 -1
- package/lib/types/index.js.map +0 -1
- package/lib/util.js.map +0 -1
- package/lib-esm/.tsbuildinfo +0 -3
- package/lib-esm/Geo.js.map +0 -1
- package/lib-esm/Providers/AmazonLocationServiceProvider.js +0 -735
- package/lib-esm/Providers/AmazonLocationServiceProvider.js.map +0 -1
- package/lib-esm/index.js.map +0 -1
- package/lib-esm/types/AmazonLocationServiceProvider.js.map +0 -1
- package/lib-esm/types/Geo.js.map +0 -1
- package/lib-esm/types/Provider.js.map +0 -1
- package/lib-esm/types/index.js.map +0 -1
- package/lib-esm/util.js.map +0 -1
|
@@ -1,735 +0,0 @@
|
|
|
1
|
-
import { __assign, __awaiter, __generator, __read, __spread } from "tslib";
|
|
2
|
-
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
3
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
4
|
-
import camelcaseKeys from 'camelcase-keys';
|
|
5
|
-
import { ConsoleLogger as Logger, Credentials, getAmplifyUserAgentObject, } from '@aws-amplify/core';
|
|
6
|
-
import { LocationClient, SearchPlaceIndexForTextCommand, SearchPlaceIndexForSuggestionsCommand, SearchPlaceIndexForPositionCommand, BatchPutGeofenceCommand, GetPlaceCommand, GetGeofenceCommand, ListGeofencesCommand, BatchDeleteGeofenceCommand, } from '@aws-sdk/client-location';
|
|
7
|
-
import { mapSearchOptions, validateGeofenceId, validateGeofencesInput, } from '../util';
|
|
8
|
-
var logger = new Logger('AmazonLocationServiceProvider');
|
|
9
|
-
var AmazonLocationServiceProvider = /** @class */ (function () {
|
|
10
|
-
/**
|
|
11
|
-
* Initialize Geo with AWS configurations
|
|
12
|
-
* @param {Object} config - Configuration object for Geo
|
|
13
|
-
*/
|
|
14
|
-
function AmazonLocationServiceProvider(config) {
|
|
15
|
-
this._config = config ? config : {};
|
|
16
|
-
logger.debug('Geo Options', this._config);
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* get the category of the plugin
|
|
20
|
-
* @returns {string} name of the category
|
|
21
|
-
*/
|
|
22
|
-
AmazonLocationServiceProvider.prototype.getCategory = function () {
|
|
23
|
-
return AmazonLocationServiceProvider.CATEGORY;
|
|
24
|
-
};
|
|
25
|
-
/**
|
|
26
|
-
* get provider name of the plugin
|
|
27
|
-
* @returns {string} name of the provider
|
|
28
|
-
*/
|
|
29
|
-
AmazonLocationServiceProvider.prototype.getProviderName = function () {
|
|
30
|
-
return AmazonLocationServiceProvider.PROVIDER_NAME;
|
|
31
|
-
};
|
|
32
|
-
/**
|
|
33
|
-
* Configure Geo part with aws configuration
|
|
34
|
-
* @param {Object} config - Configuration of the Geo
|
|
35
|
-
* @return {Object} - Current configuration
|
|
36
|
-
*/
|
|
37
|
-
AmazonLocationServiceProvider.prototype.configure = function (config) {
|
|
38
|
-
logger.debug('configure Amazon Location Service Provider', config);
|
|
39
|
-
if (!config)
|
|
40
|
-
return this._config;
|
|
41
|
-
this._config = Object.assign({}, this._config, config);
|
|
42
|
-
return this._config;
|
|
43
|
-
};
|
|
44
|
-
/**
|
|
45
|
-
* Get the map resources that are currently available through the provider
|
|
46
|
-
* @returns {AmazonLocationServiceMapStyle[]}- Array of available map resources
|
|
47
|
-
*/
|
|
48
|
-
AmazonLocationServiceProvider.prototype.getAvailableMaps = function () {
|
|
49
|
-
this._verifyMapResources();
|
|
50
|
-
var mapStyles = [];
|
|
51
|
-
var availableMaps = this._config.maps.items;
|
|
52
|
-
var region = this._config.region;
|
|
53
|
-
for (var mapName in availableMaps) {
|
|
54
|
-
var style = availableMaps[mapName].style;
|
|
55
|
-
mapStyles.push({ mapName: mapName, style: style, region: region });
|
|
56
|
-
}
|
|
57
|
-
return mapStyles;
|
|
58
|
-
};
|
|
59
|
-
/**
|
|
60
|
-
* Get the map resource set as default in amplify config
|
|
61
|
-
* @returns {AmazonLocationServiceMapStyle} - Map resource set as the default in amplify config
|
|
62
|
-
*/
|
|
63
|
-
AmazonLocationServiceProvider.prototype.getDefaultMap = function () {
|
|
64
|
-
this._verifyMapResources();
|
|
65
|
-
var mapName = this._config.maps.default;
|
|
66
|
-
var style = this._config.maps.items[mapName].style;
|
|
67
|
-
var region = this._config.region;
|
|
68
|
-
return { mapName: mapName, style: style, region: region };
|
|
69
|
-
};
|
|
70
|
-
/**
|
|
71
|
-
* Search by text input with optional parameters
|
|
72
|
-
* @param {string} text - The text string that is to be searched for
|
|
73
|
-
* @param {SearchByTextOptions} options? - Optional parameters to the search
|
|
74
|
-
* @returns {Promise<Place[]>} - Promise resolves to a list of Places that match search parameters
|
|
75
|
-
*/
|
|
76
|
-
AmazonLocationServiceProvider.prototype.searchByText = function (text, options) {
|
|
77
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
78
|
-
var credentialsOK, locationServiceInput, client, command, response, error_1, PascalResults, results;
|
|
79
|
-
return __generator(this, function (_a) {
|
|
80
|
-
switch (_a.label) {
|
|
81
|
-
case 0: return [4 /*yield*/, this._ensureCredentials()];
|
|
82
|
-
case 1:
|
|
83
|
-
credentialsOK = _a.sent();
|
|
84
|
-
if (!credentialsOK) {
|
|
85
|
-
throw new Error('No credentials');
|
|
86
|
-
}
|
|
87
|
-
this._verifySearchIndex(options === null || options === void 0 ? void 0 : options.searchIndexName);
|
|
88
|
-
locationServiceInput = {
|
|
89
|
-
Text: text,
|
|
90
|
-
IndexName: this._config.search_indices.default,
|
|
91
|
-
};
|
|
92
|
-
/**
|
|
93
|
-
* Map search options to Amazon Location Service input object
|
|
94
|
-
*/
|
|
95
|
-
if (options) {
|
|
96
|
-
locationServiceInput = __assign(__assign({}, locationServiceInput), mapSearchOptions(options, locationServiceInput));
|
|
97
|
-
}
|
|
98
|
-
client = new LocationClient({
|
|
99
|
-
credentials: this._config.credentials,
|
|
100
|
-
region: this._config.region,
|
|
101
|
-
customUserAgent: getAmplifyUserAgentObject(),
|
|
102
|
-
});
|
|
103
|
-
command = new SearchPlaceIndexForTextCommand(locationServiceInput);
|
|
104
|
-
_a.label = 2;
|
|
105
|
-
case 2:
|
|
106
|
-
_a.trys.push([2, 4, , 5]);
|
|
107
|
-
return [4 /*yield*/, client.send(command)];
|
|
108
|
-
case 3:
|
|
109
|
-
response = _a.sent();
|
|
110
|
-
return [3 /*break*/, 5];
|
|
111
|
-
case 4:
|
|
112
|
-
error_1 = _a.sent();
|
|
113
|
-
logger.debug(error_1);
|
|
114
|
-
throw error_1;
|
|
115
|
-
case 5:
|
|
116
|
-
PascalResults = response.Results.map(function (result) { return result.Place; });
|
|
117
|
-
results = camelcaseKeys(PascalResults, {
|
|
118
|
-
deep: true,
|
|
119
|
-
});
|
|
120
|
-
return [2 /*return*/, results];
|
|
121
|
-
}
|
|
122
|
-
});
|
|
123
|
-
});
|
|
124
|
-
};
|
|
125
|
-
/**
|
|
126
|
-
* Search for suggestions based on the input text
|
|
127
|
-
* @param {string} text - The text string that is to be searched for
|
|
128
|
-
* @param {SearchByTextOptions} options? - Optional parameters to the search
|
|
129
|
-
* @returns {Promise<SearchForSuggestionsResults>} - Resolves to an array of search suggestion strings
|
|
130
|
-
*/
|
|
131
|
-
AmazonLocationServiceProvider.prototype.searchForSuggestions = function (text, options) {
|
|
132
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
133
|
-
var credentialsOK, locationServiceInput, client, command, response, error_2, results;
|
|
134
|
-
return __generator(this, function (_a) {
|
|
135
|
-
switch (_a.label) {
|
|
136
|
-
case 0: return [4 /*yield*/, this._ensureCredentials()];
|
|
137
|
-
case 1:
|
|
138
|
-
credentialsOK = _a.sent();
|
|
139
|
-
if (!credentialsOK) {
|
|
140
|
-
throw new Error('No credentials');
|
|
141
|
-
}
|
|
142
|
-
this._verifySearchIndex(options === null || options === void 0 ? void 0 : options.searchIndexName);
|
|
143
|
-
locationServiceInput = {
|
|
144
|
-
Text: text,
|
|
145
|
-
IndexName: this._config.search_indices.default,
|
|
146
|
-
};
|
|
147
|
-
/**
|
|
148
|
-
* Map search options to Amazon Location Service input object
|
|
149
|
-
*/
|
|
150
|
-
if (options) {
|
|
151
|
-
locationServiceInput = __assign(__assign({}, locationServiceInput), mapSearchOptions(options, locationServiceInput));
|
|
152
|
-
}
|
|
153
|
-
client = new LocationClient({
|
|
154
|
-
credentials: this._config.credentials,
|
|
155
|
-
region: this._config.region,
|
|
156
|
-
customUserAgent: getAmplifyUserAgentObject(),
|
|
157
|
-
});
|
|
158
|
-
command = new SearchPlaceIndexForSuggestionsCommand(locationServiceInput);
|
|
159
|
-
_a.label = 2;
|
|
160
|
-
case 2:
|
|
161
|
-
_a.trys.push([2, 4, , 5]);
|
|
162
|
-
return [4 /*yield*/, client.send(command)];
|
|
163
|
-
case 3:
|
|
164
|
-
response = _a.sent();
|
|
165
|
-
return [3 /*break*/, 5];
|
|
166
|
-
case 4:
|
|
167
|
-
error_2 = _a.sent();
|
|
168
|
-
logger.debug(error_2);
|
|
169
|
-
throw error_2;
|
|
170
|
-
case 5:
|
|
171
|
-
results = response.Results.map(function (result) { return ({
|
|
172
|
-
text: result.Text,
|
|
173
|
-
placeId: result.PlaceId,
|
|
174
|
-
}); });
|
|
175
|
-
return [2 /*return*/, results];
|
|
176
|
-
}
|
|
177
|
-
});
|
|
178
|
-
});
|
|
179
|
-
};
|
|
180
|
-
AmazonLocationServiceProvider.prototype._verifyPlaceId = function (placeId) {
|
|
181
|
-
if (placeId.length === 0) {
|
|
182
|
-
var errorString = 'PlaceId cannot be an empty string.';
|
|
183
|
-
logger.debug(errorString);
|
|
184
|
-
throw new Error(errorString);
|
|
185
|
-
}
|
|
186
|
-
};
|
|
187
|
-
AmazonLocationServiceProvider.prototype.searchByPlaceId = function (placeId, options) {
|
|
188
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
189
|
-
var credentialsOK, client, searchByPlaceIdInput, command, response, error_3, place;
|
|
190
|
-
return __generator(this, function (_a) {
|
|
191
|
-
switch (_a.label) {
|
|
192
|
-
case 0: return [4 /*yield*/, this._ensureCredentials()];
|
|
193
|
-
case 1:
|
|
194
|
-
credentialsOK = _a.sent();
|
|
195
|
-
if (!credentialsOK) {
|
|
196
|
-
throw new Error('No credentials');
|
|
197
|
-
}
|
|
198
|
-
this._verifySearchIndex(options === null || options === void 0 ? void 0 : options.searchIndexName);
|
|
199
|
-
this._verifyPlaceId(placeId);
|
|
200
|
-
client = new LocationClient({
|
|
201
|
-
credentials: this._config.credentials,
|
|
202
|
-
region: this._config.region,
|
|
203
|
-
customUserAgent: getAmplifyUserAgentObject(),
|
|
204
|
-
});
|
|
205
|
-
searchByPlaceIdInput = {
|
|
206
|
-
PlaceId: placeId,
|
|
207
|
-
IndexName: (options === null || options === void 0 ? void 0 : options.searchIndexName) || this._config.search_indices.default,
|
|
208
|
-
};
|
|
209
|
-
command = new GetPlaceCommand(searchByPlaceIdInput);
|
|
210
|
-
_a.label = 2;
|
|
211
|
-
case 2:
|
|
212
|
-
_a.trys.push([2, 4, , 5]);
|
|
213
|
-
return [4 /*yield*/, client.send(command)];
|
|
214
|
-
case 3:
|
|
215
|
-
response = _a.sent();
|
|
216
|
-
return [3 /*break*/, 5];
|
|
217
|
-
case 4:
|
|
218
|
-
error_3 = _a.sent();
|
|
219
|
-
logger.debug(error_3);
|
|
220
|
-
throw error_3;
|
|
221
|
-
case 5:
|
|
222
|
-
place = response.Place;
|
|
223
|
-
if (place) {
|
|
224
|
-
return [2 /*return*/, camelcaseKeys(place, { deep: true })];
|
|
225
|
-
}
|
|
226
|
-
return [2 /*return*/];
|
|
227
|
-
}
|
|
228
|
-
});
|
|
229
|
-
});
|
|
230
|
-
};
|
|
231
|
-
/**
|
|
232
|
-
* Reverse geocoding search via a coordinate point on the map
|
|
233
|
-
* @param coordinates - Coordinates array for the search input
|
|
234
|
-
* @param options - Options parameters for the search
|
|
235
|
-
* @returns {Promise<Place>} - Promise that resolves to a place matching search coordinates
|
|
236
|
-
*/
|
|
237
|
-
AmazonLocationServiceProvider.prototype.searchByCoordinates = function (coordinates, options) {
|
|
238
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
239
|
-
var credentialsOK, locationServiceInput, client, command, response, error_4, PascalResults, results;
|
|
240
|
-
return __generator(this, function (_a) {
|
|
241
|
-
switch (_a.label) {
|
|
242
|
-
case 0: return [4 /*yield*/, this._ensureCredentials()];
|
|
243
|
-
case 1:
|
|
244
|
-
credentialsOK = _a.sent();
|
|
245
|
-
if (!credentialsOK) {
|
|
246
|
-
throw new Error('No credentials');
|
|
247
|
-
}
|
|
248
|
-
this._verifySearchIndex(options === null || options === void 0 ? void 0 : options.searchIndexName);
|
|
249
|
-
locationServiceInput = {
|
|
250
|
-
Position: coordinates,
|
|
251
|
-
IndexName: this._config.search_indices.default,
|
|
252
|
-
};
|
|
253
|
-
if (options) {
|
|
254
|
-
if (options.searchIndexName) {
|
|
255
|
-
locationServiceInput.IndexName = options.searchIndexName;
|
|
256
|
-
}
|
|
257
|
-
locationServiceInput.MaxResults = options.maxResults;
|
|
258
|
-
}
|
|
259
|
-
client = new LocationClient({
|
|
260
|
-
credentials: this._config.credentials,
|
|
261
|
-
region: this._config.region,
|
|
262
|
-
customUserAgent: getAmplifyUserAgentObject(),
|
|
263
|
-
});
|
|
264
|
-
command = new SearchPlaceIndexForPositionCommand(locationServiceInput);
|
|
265
|
-
_a.label = 2;
|
|
266
|
-
case 2:
|
|
267
|
-
_a.trys.push([2, 4, , 5]);
|
|
268
|
-
return [4 /*yield*/, client.send(command)];
|
|
269
|
-
case 3:
|
|
270
|
-
response = _a.sent();
|
|
271
|
-
return [3 /*break*/, 5];
|
|
272
|
-
case 4:
|
|
273
|
-
error_4 = _a.sent();
|
|
274
|
-
logger.debug(error_4);
|
|
275
|
-
throw error_4;
|
|
276
|
-
case 5:
|
|
277
|
-
PascalResults = response.Results.map(function (result) { return result.Place; });
|
|
278
|
-
results = camelcaseKeys(PascalResults[0], {
|
|
279
|
-
deep: true,
|
|
280
|
-
});
|
|
281
|
-
return [2 /*return*/, results];
|
|
282
|
-
}
|
|
283
|
-
});
|
|
284
|
-
});
|
|
285
|
-
};
|
|
286
|
-
/**
|
|
287
|
-
* Create geofences inside of a geofence collection
|
|
288
|
-
* @param geofences - Array of geofence objects to create
|
|
289
|
-
* @param options? - Optional parameters for creating geofences
|
|
290
|
-
* @returns {Promise<AmazonLocationServiceSaveGeofencesResults>} - Promise that resolves to an object with:
|
|
291
|
-
* successes: list of geofences successfully created
|
|
292
|
-
* errors: list of geofences that failed to create
|
|
293
|
-
*/
|
|
294
|
-
AmazonLocationServiceProvider.prototype.saveGeofences = function (geofences, options) {
|
|
295
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
296
|
-
var credentialsOK, PascalGeofences, results, geofenceBatches, apiLimit;
|
|
297
|
-
var _this = this;
|
|
298
|
-
return __generator(this, function (_a) {
|
|
299
|
-
switch (_a.label) {
|
|
300
|
-
case 0:
|
|
301
|
-
if (geofences.length < 1) {
|
|
302
|
-
throw new Error('Geofence input array is empty');
|
|
303
|
-
}
|
|
304
|
-
return [4 /*yield*/, this._ensureCredentials()];
|
|
305
|
-
case 1:
|
|
306
|
-
credentialsOK = _a.sent();
|
|
307
|
-
if (!credentialsOK) {
|
|
308
|
-
throw new Error('No credentials');
|
|
309
|
-
}
|
|
310
|
-
// Verify geofence collection exists in aws-config.js
|
|
311
|
-
try {
|
|
312
|
-
this._verifyGeofenceCollections(options === null || options === void 0 ? void 0 : options.collectionName);
|
|
313
|
-
}
|
|
314
|
-
catch (error) {
|
|
315
|
-
logger.debug(error);
|
|
316
|
-
throw error;
|
|
317
|
-
}
|
|
318
|
-
validateGeofencesInput(geofences);
|
|
319
|
-
PascalGeofences = geofences.map(function (_a) {
|
|
320
|
-
var geofenceId = _a.geofenceId, polygon = _a.geometry.polygon;
|
|
321
|
-
return {
|
|
322
|
-
GeofenceId: geofenceId,
|
|
323
|
-
Geometry: {
|
|
324
|
-
Polygon: polygon,
|
|
325
|
-
},
|
|
326
|
-
};
|
|
327
|
-
});
|
|
328
|
-
results = {
|
|
329
|
-
successes: [],
|
|
330
|
-
errors: [],
|
|
331
|
-
};
|
|
332
|
-
geofenceBatches = [];
|
|
333
|
-
while (PascalGeofences.length > 0) {
|
|
334
|
-
apiLimit = 10;
|
|
335
|
-
geofenceBatches.push(PascalGeofences.splice(0, apiLimit));
|
|
336
|
-
}
|
|
337
|
-
return [4 /*yield*/, Promise.all(geofenceBatches.map(function (batch) { return __awaiter(_this, void 0, void 0, function () {
|
|
338
|
-
var response, error_5;
|
|
339
|
-
return __generator(this, function (_a) {
|
|
340
|
-
switch (_a.label) {
|
|
341
|
-
case 0:
|
|
342
|
-
_a.trys.push([0, 2, , 3]);
|
|
343
|
-
return [4 /*yield*/, this._AmazonLocationServiceBatchPutGeofenceCall(batch, (options === null || options === void 0 ? void 0 : options.collectionName) || this._config.geofenceCollections.default)];
|
|
344
|
-
case 1:
|
|
345
|
-
response = _a.sent();
|
|
346
|
-
return [3 /*break*/, 3];
|
|
347
|
-
case 2:
|
|
348
|
-
error_5 = _a.sent();
|
|
349
|
-
// If the API call fails, add the geofences to the errors array and move to next batch
|
|
350
|
-
batch.forEach(function (geofence) {
|
|
351
|
-
results.errors.push({
|
|
352
|
-
geofenceId: geofence.GeofenceId,
|
|
353
|
-
error: {
|
|
354
|
-
code: 'APIConnectionError',
|
|
355
|
-
message: error_5.message,
|
|
356
|
-
},
|
|
357
|
-
});
|
|
358
|
-
});
|
|
359
|
-
return [2 /*return*/];
|
|
360
|
-
case 3:
|
|
361
|
-
// Push all successes to results
|
|
362
|
-
response.Successes.forEach(function (success) {
|
|
363
|
-
var GeofenceId = success.GeofenceId, CreateTime = success.CreateTime, UpdateTime = success.UpdateTime;
|
|
364
|
-
results.successes.push({
|
|
365
|
-
geofenceId: GeofenceId,
|
|
366
|
-
createTime: CreateTime,
|
|
367
|
-
updateTime: UpdateTime,
|
|
368
|
-
});
|
|
369
|
-
});
|
|
370
|
-
// Push all errors to results
|
|
371
|
-
response.Errors.forEach(function (error) {
|
|
372
|
-
var _a = error.Error, Code = _a.Code, Message = _a.Message, GeofenceId = error.GeofenceId;
|
|
373
|
-
results.errors.push({
|
|
374
|
-
error: {
|
|
375
|
-
code: Code,
|
|
376
|
-
message: Message,
|
|
377
|
-
},
|
|
378
|
-
geofenceId: GeofenceId,
|
|
379
|
-
});
|
|
380
|
-
});
|
|
381
|
-
return [2 /*return*/];
|
|
382
|
-
}
|
|
383
|
-
});
|
|
384
|
-
}); }))];
|
|
385
|
-
case 2:
|
|
386
|
-
_a.sent();
|
|
387
|
-
return [2 /*return*/, results];
|
|
388
|
-
}
|
|
389
|
-
});
|
|
390
|
-
});
|
|
391
|
-
};
|
|
392
|
-
/**
|
|
393
|
-
* Get geofence from a geofence collection
|
|
394
|
-
* @param geofenceId:string
|
|
395
|
-
* @param options?: Optional parameters for getGeofence
|
|
396
|
-
* @returns {Promise<AmazonLocationServiceGeofence>} - Promise that resolves to a geofence object
|
|
397
|
-
*/
|
|
398
|
-
AmazonLocationServiceProvider.prototype.getGeofence = function (geofenceId, options) {
|
|
399
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
400
|
-
var credentialsOK, client, commandInput, command, response, error_6, GeofenceId, CreateTime, UpdateTime, Status, Geometry, geofence;
|
|
401
|
-
return __generator(this, function (_a) {
|
|
402
|
-
switch (_a.label) {
|
|
403
|
-
case 0: return [4 /*yield*/, this._ensureCredentials()];
|
|
404
|
-
case 1:
|
|
405
|
-
credentialsOK = _a.sent();
|
|
406
|
-
if (!credentialsOK) {
|
|
407
|
-
throw new Error('No credentials');
|
|
408
|
-
}
|
|
409
|
-
// Verify geofence collection exists in aws-config.js
|
|
410
|
-
try {
|
|
411
|
-
this._verifyGeofenceCollections(options === null || options === void 0 ? void 0 : options.collectionName);
|
|
412
|
-
}
|
|
413
|
-
catch (error) {
|
|
414
|
-
logger.debug(error);
|
|
415
|
-
throw error;
|
|
416
|
-
}
|
|
417
|
-
validateGeofenceId(geofenceId);
|
|
418
|
-
client = new LocationClient({
|
|
419
|
-
credentials: this._config.credentials,
|
|
420
|
-
region: this._config.region,
|
|
421
|
-
customUserAgent: getAmplifyUserAgentObject(),
|
|
422
|
-
});
|
|
423
|
-
commandInput = {
|
|
424
|
-
GeofenceId: geofenceId,
|
|
425
|
-
CollectionName: (options === null || options === void 0 ? void 0 : options.collectionName) || this._config.geofenceCollections.default,
|
|
426
|
-
};
|
|
427
|
-
command = new GetGeofenceCommand(commandInput);
|
|
428
|
-
_a.label = 2;
|
|
429
|
-
case 2:
|
|
430
|
-
_a.trys.push([2, 4, , 5]);
|
|
431
|
-
return [4 /*yield*/, client.send(command)];
|
|
432
|
-
case 3:
|
|
433
|
-
response = _a.sent();
|
|
434
|
-
return [3 /*break*/, 5];
|
|
435
|
-
case 4:
|
|
436
|
-
error_6 = _a.sent();
|
|
437
|
-
logger.debug(error_6);
|
|
438
|
-
throw error_6;
|
|
439
|
-
case 5:
|
|
440
|
-
GeofenceId = response.GeofenceId, CreateTime = response.CreateTime, UpdateTime = response.UpdateTime, Status = response.Status, Geometry = response.Geometry;
|
|
441
|
-
geofence = {
|
|
442
|
-
createTime: CreateTime,
|
|
443
|
-
geofenceId: GeofenceId,
|
|
444
|
-
geometry: {
|
|
445
|
-
polygon: Geometry.Polygon,
|
|
446
|
-
},
|
|
447
|
-
status: Status,
|
|
448
|
-
updateTime: UpdateTime,
|
|
449
|
-
};
|
|
450
|
-
return [2 /*return*/, geofence];
|
|
451
|
-
}
|
|
452
|
-
});
|
|
453
|
-
});
|
|
454
|
-
};
|
|
455
|
-
/**
|
|
456
|
-
* List geofences from a geofence collection
|
|
457
|
-
* @param options?: ListGeofenceOptions
|
|
458
|
-
* @returns {Promise<ListGeofencesResults>} - Promise that resolves to an object with:
|
|
459
|
-
* entries: list of geofences - 100 geofences are listed per page
|
|
460
|
-
* nextToken: token for next page of geofences
|
|
461
|
-
*/
|
|
462
|
-
AmazonLocationServiceProvider.prototype.listGeofences = function (options) {
|
|
463
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
464
|
-
var credentialsOK, client, listGeofencesInput, command, response, error_7, NextToken, Entries, results;
|
|
465
|
-
return __generator(this, function (_a) {
|
|
466
|
-
switch (_a.label) {
|
|
467
|
-
case 0: return [4 /*yield*/, this._ensureCredentials()];
|
|
468
|
-
case 1:
|
|
469
|
-
credentialsOK = _a.sent();
|
|
470
|
-
if (!credentialsOK) {
|
|
471
|
-
throw new Error('No credentials');
|
|
472
|
-
}
|
|
473
|
-
// Verify geofence collection exists in aws-config.js
|
|
474
|
-
try {
|
|
475
|
-
this._verifyGeofenceCollections(options === null || options === void 0 ? void 0 : options.collectionName);
|
|
476
|
-
}
|
|
477
|
-
catch (error) {
|
|
478
|
-
logger.debug(error);
|
|
479
|
-
throw error;
|
|
480
|
-
}
|
|
481
|
-
client = new LocationClient({
|
|
482
|
-
credentials: this._config.credentials,
|
|
483
|
-
region: this._config.region,
|
|
484
|
-
customUserAgent: getAmplifyUserAgentObject(),
|
|
485
|
-
});
|
|
486
|
-
listGeofencesInput = {
|
|
487
|
-
NextToken: options === null || options === void 0 ? void 0 : options.nextToken,
|
|
488
|
-
CollectionName: (options === null || options === void 0 ? void 0 : options.collectionName) || this._config.geofenceCollections.default,
|
|
489
|
-
};
|
|
490
|
-
command = new ListGeofencesCommand(listGeofencesInput);
|
|
491
|
-
_a.label = 2;
|
|
492
|
-
case 2:
|
|
493
|
-
_a.trys.push([2, 4, , 5]);
|
|
494
|
-
return [4 /*yield*/, client.send(command)];
|
|
495
|
-
case 3:
|
|
496
|
-
response = _a.sent();
|
|
497
|
-
return [3 /*break*/, 5];
|
|
498
|
-
case 4:
|
|
499
|
-
error_7 = _a.sent();
|
|
500
|
-
logger.debug(error_7);
|
|
501
|
-
throw error_7;
|
|
502
|
-
case 5:
|
|
503
|
-
NextToken = response.NextToken, Entries = response.Entries;
|
|
504
|
-
results = {
|
|
505
|
-
entries: Entries.map(function (_a) {
|
|
506
|
-
var GeofenceId = _a.GeofenceId, CreateTime = _a.CreateTime, UpdateTime = _a.UpdateTime, Status = _a.Status, Polygon = _a.Geometry.Polygon;
|
|
507
|
-
return {
|
|
508
|
-
geofenceId: GeofenceId,
|
|
509
|
-
createTime: CreateTime,
|
|
510
|
-
updateTime: UpdateTime,
|
|
511
|
-
status: Status,
|
|
512
|
-
geometry: {
|
|
513
|
-
polygon: Polygon,
|
|
514
|
-
},
|
|
515
|
-
};
|
|
516
|
-
}),
|
|
517
|
-
nextToken: NextToken,
|
|
518
|
-
};
|
|
519
|
-
return [2 /*return*/, results];
|
|
520
|
-
}
|
|
521
|
-
});
|
|
522
|
-
});
|
|
523
|
-
};
|
|
524
|
-
/**
|
|
525
|
-
* Delete geofences from a geofence collection
|
|
526
|
-
* @param geofenceIds: string|string[]
|
|
527
|
-
* @param options?: GeofenceOptions
|
|
528
|
-
* @returns {Promise<DeleteGeofencesResults>} - Promise that resolves to an object with:
|
|
529
|
-
* successes: list of geofences successfully deleted
|
|
530
|
-
* errors: list of geofences that failed to delete
|
|
531
|
-
*/
|
|
532
|
-
AmazonLocationServiceProvider.prototype.deleteGeofences = function (geofenceIds, options) {
|
|
533
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
534
|
-
var credentialsOK, badGeofenceIds, results, geofenceIdBatches, count;
|
|
535
|
-
var _this = this;
|
|
536
|
-
return __generator(this, function (_a) {
|
|
537
|
-
switch (_a.label) {
|
|
538
|
-
case 0:
|
|
539
|
-
if (geofenceIds.length < 1) {
|
|
540
|
-
throw new Error('GeofenceId input array is empty');
|
|
541
|
-
}
|
|
542
|
-
return [4 /*yield*/, this._ensureCredentials()];
|
|
543
|
-
case 1:
|
|
544
|
-
credentialsOK = _a.sent();
|
|
545
|
-
if (!credentialsOK) {
|
|
546
|
-
throw new Error('No credentials');
|
|
547
|
-
}
|
|
548
|
-
this._verifyGeofenceCollections(options === null || options === void 0 ? void 0 : options.collectionName);
|
|
549
|
-
badGeofenceIds = geofenceIds.filter(function (geofenceId) {
|
|
550
|
-
try {
|
|
551
|
-
validateGeofenceId(geofenceId);
|
|
552
|
-
}
|
|
553
|
-
catch (error) {
|
|
554
|
-
return true;
|
|
555
|
-
}
|
|
556
|
-
});
|
|
557
|
-
if (badGeofenceIds.length > 0) {
|
|
558
|
-
throw new Error("Invalid geofence ids: " + badGeofenceIds.join(', '));
|
|
559
|
-
}
|
|
560
|
-
results = {
|
|
561
|
-
successes: [],
|
|
562
|
-
errors: [],
|
|
563
|
-
};
|
|
564
|
-
geofenceIdBatches = [];
|
|
565
|
-
count = 0;
|
|
566
|
-
while (count < geofenceIds.length) {
|
|
567
|
-
geofenceIdBatches.push(geofenceIds.slice(count, (count += 10)));
|
|
568
|
-
}
|
|
569
|
-
return [4 /*yield*/, Promise.all(geofenceIdBatches.map(function (batch) { return __awaiter(_this, void 0, void 0, function () {
|
|
570
|
-
var response, error_8, badGeofenceIds;
|
|
571
|
-
var _a;
|
|
572
|
-
return __generator(this, function (_b) {
|
|
573
|
-
switch (_b.label) {
|
|
574
|
-
case 0:
|
|
575
|
-
_b.trys.push([0, 2, , 3]);
|
|
576
|
-
return [4 /*yield*/, this._AmazonLocationServiceBatchDeleteGeofenceCall(batch, (options === null || options === void 0 ? void 0 : options.collectionName) || this._config.geofenceCollections.default)];
|
|
577
|
-
case 1:
|
|
578
|
-
response = _b.sent();
|
|
579
|
-
return [3 /*break*/, 3];
|
|
580
|
-
case 2:
|
|
581
|
-
error_8 = _b.sent();
|
|
582
|
-
// If the API call fails, add the geofences to the errors array and move to next batch
|
|
583
|
-
batch.forEach(function (geofenceId) {
|
|
584
|
-
var errorObject = {
|
|
585
|
-
geofenceId: geofenceId,
|
|
586
|
-
error: {
|
|
587
|
-
code: error_8.message,
|
|
588
|
-
message: error_8.message,
|
|
589
|
-
},
|
|
590
|
-
};
|
|
591
|
-
results.errors.push(errorObject);
|
|
592
|
-
});
|
|
593
|
-
return [2 /*return*/];
|
|
594
|
-
case 3:
|
|
595
|
-
badGeofenceIds = response.Errors.map(function (_a) {
|
|
596
|
-
var geofenceId = _a.geofenceId;
|
|
597
|
-
return geofenceId;
|
|
598
|
-
});
|
|
599
|
-
(_a = results.successes).push.apply(_a, __spread(batch.filter(function (Id) { return !badGeofenceIds.includes(Id); })));
|
|
600
|
-
return [2 /*return*/];
|
|
601
|
-
}
|
|
602
|
-
});
|
|
603
|
-
}); }))];
|
|
604
|
-
case 2:
|
|
605
|
-
_a.sent();
|
|
606
|
-
return [2 /*return*/, results];
|
|
607
|
-
}
|
|
608
|
-
});
|
|
609
|
-
});
|
|
610
|
-
};
|
|
611
|
-
/**
|
|
612
|
-
* @private
|
|
613
|
-
*/
|
|
614
|
-
AmazonLocationServiceProvider.prototype._ensureCredentials = function () {
|
|
615
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
616
|
-
var credentials, cred, error_9;
|
|
617
|
-
return __generator(this, function (_a) {
|
|
618
|
-
switch (_a.label) {
|
|
619
|
-
case 0:
|
|
620
|
-
_a.trys.push([0, 2, , 3]);
|
|
621
|
-
return [4 /*yield*/, Credentials.get()];
|
|
622
|
-
case 1:
|
|
623
|
-
credentials = _a.sent();
|
|
624
|
-
if (!credentials)
|
|
625
|
-
return [2 /*return*/, false];
|
|
626
|
-
cred = Credentials.shear(credentials);
|
|
627
|
-
logger.debug('Set credentials for storage. Credentials are:', cred);
|
|
628
|
-
this._config.credentials = cred;
|
|
629
|
-
return [2 /*return*/, true];
|
|
630
|
-
case 2:
|
|
631
|
-
error_9 = _a.sent();
|
|
632
|
-
logger.debug('Ensure credentials error. Credentials are:', error_9);
|
|
633
|
-
return [2 /*return*/, false];
|
|
634
|
-
case 3: return [2 /*return*/];
|
|
635
|
-
}
|
|
636
|
-
});
|
|
637
|
-
});
|
|
638
|
-
};
|
|
639
|
-
AmazonLocationServiceProvider.prototype._verifyMapResources = function () {
|
|
640
|
-
if (!this._config.maps) {
|
|
641
|
-
var errorString = "No map resources found in amplify config, run 'amplify add geo' to create one and run `amplify push` after";
|
|
642
|
-
logger.debug(errorString);
|
|
643
|
-
throw new Error(errorString);
|
|
644
|
-
}
|
|
645
|
-
if (!this._config.maps.default) {
|
|
646
|
-
var errorString = "No default map resource found in amplify config, run 'amplify add geo' to create one and run `amplify push` after";
|
|
647
|
-
logger.debug(errorString);
|
|
648
|
-
throw new Error(errorString);
|
|
649
|
-
}
|
|
650
|
-
};
|
|
651
|
-
AmazonLocationServiceProvider.prototype._verifySearchIndex = function (optionalSearchIndex) {
|
|
652
|
-
if ((!this._config.search_indices || !this._config.search_indices.default) &&
|
|
653
|
-
!optionalSearchIndex) {
|
|
654
|
-
var errorString = 'No Search Index found in amplify config, please run `amplify add geo` to create one and run `amplify push` after.';
|
|
655
|
-
logger.debug(errorString);
|
|
656
|
-
throw new Error(errorString);
|
|
657
|
-
}
|
|
658
|
-
};
|
|
659
|
-
AmazonLocationServiceProvider.prototype._verifyGeofenceCollections = function (optionalGeofenceCollectionName) {
|
|
660
|
-
if ((!this._config.geofenceCollections ||
|
|
661
|
-
!this._config.geofenceCollections.default) &&
|
|
662
|
-
!optionalGeofenceCollectionName) {
|
|
663
|
-
var errorString = 'No Geofence Collections found, please run `amplify add geo` to create one and run `amplify push` after.';
|
|
664
|
-
logger.debug(errorString);
|
|
665
|
-
throw new Error(errorString);
|
|
666
|
-
}
|
|
667
|
-
};
|
|
668
|
-
AmazonLocationServiceProvider.prototype._AmazonLocationServiceBatchPutGeofenceCall = function (PascalGeofences, collectionName) {
|
|
669
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
670
|
-
var geofenceInput, client, command, response, error_10;
|
|
671
|
-
return __generator(this, function (_a) {
|
|
672
|
-
switch (_a.label) {
|
|
673
|
-
case 0:
|
|
674
|
-
geofenceInput = {
|
|
675
|
-
Entries: PascalGeofences,
|
|
676
|
-
CollectionName: collectionName || this._config.geofenceCollections.default,
|
|
677
|
-
};
|
|
678
|
-
client = new LocationClient({
|
|
679
|
-
credentials: this._config.credentials,
|
|
680
|
-
region: this._config.region,
|
|
681
|
-
customUserAgent: getAmplifyUserAgentObject(),
|
|
682
|
-
});
|
|
683
|
-
command = new BatchPutGeofenceCommand(geofenceInput);
|
|
684
|
-
_a.label = 1;
|
|
685
|
-
case 1:
|
|
686
|
-
_a.trys.push([1, 3, , 4]);
|
|
687
|
-
return [4 /*yield*/, client.send(command)];
|
|
688
|
-
case 2:
|
|
689
|
-
response = _a.sent();
|
|
690
|
-
return [3 /*break*/, 4];
|
|
691
|
-
case 3:
|
|
692
|
-
error_10 = _a.sent();
|
|
693
|
-
throw error_10;
|
|
694
|
-
case 4: return [2 /*return*/, response];
|
|
695
|
-
}
|
|
696
|
-
});
|
|
697
|
-
});
|
|
698
|
-
};
|
|
699
|
-
AmazonLocationServiceProvider.prototype._AmazonLocationServiceBatchDeleteGeofenceCall = function (geofenceIds, collectionName) {
|
|
700
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
701
|
-
var deleteGeofencesInput, client, command, response, error_11;
|
|
702
|
-
return __generator(this, function (_a) {
|
|
703
|
-
switch (_a.label) {
|
|
704
|
-
case 0:
|
|
705
|
-
deleteGeofencesInput = {
|
|
706
|
-
GeofenceIds: geofenceIds,
|
|
707
|
-
CollectionName: collectionName || this._config.geofenceCollections.default,
|
|
708
|
-
};
|
|
709
|
-
client = new LocationClient({
|
|
710
|
-
credentials: this._config.credentials,
|
|
711
|
-
region: this._config.region,
|
|
712
|
-
customUserAgent: getAmplifyUserAgentObject(),
|
|
713
|
-
});
|
|
714
|
-
command = new BatchDeleteGeofenceCommand(deleteGeofencesInput);
|
|
715
|
-
_a.label = 1;
|
|
716
|
-
case 1:
|
|
717
|
-
_a.trys.push([1, 3, , 4]);
|
|
718
|
-
return [4 /*yield*/, client.send(command)];
|
|
719
|
-
case 2:
|
|
720
|
-
response = _a.sent();
|
|
721
|
-
return [3 /*break*/, 4];
|
|
722
|
-
case 3:
|
|
723
|
-
error_11 = _a.sent();
|
|
724
|
-
throw error_11;
|
|
725
|
-
case 4: return [2 /*return*/, response];
|
|
726
|
-
}
|
|
727
|
-
});
|
|
728
|
-
});
|
|
729
|
-
};
|
|
730
|
-
AmazonLocationServiceProvider.CATEGORY = 'Geo';
|
|
731
|
-
AmazonLocationServiceProvider.PROVIDER_NAME = 'AmazonLocationService';
|
|
732
|
-
return AmazonLocationServiceProvider;
|
|
733
|
-
}());
|
|
734
|
-
export { AmazonLocationServiceProvider };
|
|
735
|
-
//# sourceMappingURL=AmazonLocationServiceProvider.js.map
|