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