@aws-amplify/geo 1.2.1 → 1.2.2-geo.3

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 (39) hide show
  1. package/dist/aws-amplify-geo.js +1062 -51
  2. package/dist/aws-amplify-geo.js.map +1 -1
  3. package/dist/aws-amplify-geo.min.js +6 -6
  4. package/dist/aws-amplify-geo.min.js.map +1 -1
  5. package/lib/Geo.d.ts +36 -3
  6. package/lib/Geo.js +170 -5
  7. package/lib/Geo.js.map +1 -1
  8. package/lib/Providers/AmazonLocationServiceProvider.d.ts +37 -1
  9. package/lib/Providers/AmazonLocationServiceProvider.js +409 -8
  10. package/lib/Providers/AmazonLocationServiceProvider.js.map +1 -1
  11. package/lib/types/AmazonLocationServiceProvider.d.ts +21 -1
  12. package/lib/types/Geo.d.ts +48 -1
  13. package/lib/types/Provider.d.ts +5 -1
  14. package/lib/types/Provider.js +0 -12
  15. package/lib/types/Provider.js.map +1 -1
  16. package/lib/util.d.ts +6 -0
  17. package/lib/util.js +163 -0
  18. package/lib/util.js.map +1 -0
  19. package/lib-esm/Geo.d.ts +36 -3
  20. package/lib-esm/Geo.js +170 -5
  21. package/lib-esm/Geo.js.map +1 -1
  22. package/lib-esm/Providers/AmazonLocationServiceProvider.d.ts +37 -1
  23. package/lib-esm/Providers/AmazonLocationServiceProvider.js +410 -9
  24. package/lib-esm/Providers/AmazonLocationServiceProvider.js.map +1 -1
  25. package/lib-esm/types/AmazonLocationServiceProvider.d.ts +21 -1
  26. package/lib-esm/types/Geo.d.ts +48 -1
  27. package/lib-esm/types/Provider.d.ts +5 -1
  28. package/lib-esm/types/Provider.js +0 -12
  29. package/lib-esm/types/Provider.js.map +1 -1
  30. package/lib-esm/util.d.ts +6 -0
  31. package/lib-esm/util.js +156 -0
  32. package/lib-esm/util.js.map +1 -0
  33. package/package.json +5 -4
  34. package/src/Geo.ts +144 -2
  35. package/src/Providers/AmazonLocationServiceProvider.ts +409 -6
  36. package/src/types/AmazonLocationServiceProvider.ts +56 -1
  37. package/src/types/Geo.ts +72 -2
  38. package/src/types/Provider.ts +31 -1
  39. package/src/util.ts +182 -0
@@ -27556,6 +27556,7 @@ __webpack_require__.r(__webpack_exports__);
27556
27556
  /* harmony import */ var _aws_amplify_core__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @aws-amplify/core */ "@aws-amplify/core");
27557
27557
  /* harmony import */ var _aws_amplify_core__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_aws_amplify_core__WEBPACK_IMPORTED_MODULE_0__);
27558
27558
  /* harmony import */ var _Providers_AmazonLocationServiceProvider__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./Providers/AmazonLocationServiceProvider */ "./lib-esm/Providers/AmazonLocationServiceProvider.js");
27559
+ /* harmony import */ var _util__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./util */ "./lib-esm/util.js");
27559
27560
  var __awaiter = undefined && undefined.__awaiter || function (thisArg, _arguments, P, generator) {
27560
27561
  function adopt(value) {
27561
27562
  return value instanceof P ? value : new P(function (resolve) {
@@ -27698,6 +27699,33 @@ var __generator = undefined && undefined.__generator || function (thisArg, body)
27698
27699
  };
27699
27700
  }
27700
27701
  };
27702
+
27703
+ var __read = undefined && undefined.__read || function (o, n) {
27704
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
27705
+ if (!m) return o;
27706
+ var i = m.call(o),
27707
+ r,
27708
+ ar = [],
27709
+ e;
27710
+
27711
+ try {
27712
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) {
27713
+ ar.push(r.value);
27714
+ }
27715
+ } catch (error) {
27716
+ e = {
27717
+ error: error
27718
+ };
27719
+ } finally {
27720
+ try {
27721
+ if (r && !r.done && (m = i["return"])) m.call(i);
27722
+ } finally {
27723
+ if (e) throw e.error;
27724
+ }
27725
+ }
27726
+
27727
+ return ar;
27728
+ };
27701
27729
  /*
27702
27730
  * Copyright 2017-2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
27703
27731
  *
@@ -27714,6 +27742,7 @@ var __generator = undefined && undefined.__generator || function (thisArg, body)
27714
27742
 
27715
27743
 
27716
27744
 
27745
+
27717
27746
  var logger = new _aws_amplify_core__WEBPACK_IMPORTED_MODULE_0__["ConsoleLogger"]('Geo');
27718
27747
  var DEFAULT_PROVIDER = 'AmazonLocationService';
27719
27748
 
@@ -27929,7 +27958,155 @@ function () {
27929
27958
 
27930
27959
  GeoClass.prototype.searchByCoordinates = function (coordinates, options) {
27931
27960
  return __awaiter(this, void 0, void 0, function () {
27932
- var _a, providerName, prov, error_3;
27961
+ var _a, providerName, prov, _b, lng, lat, error_3;
27962
+
27963
+ return __generator(this, function (_c) {
27964
+ switch (_c.label) {
27965
+ case 0:
27966
+ _a = (options || {}).providerName, providerName = _a === void 0 ? DEFAULT_PROVIDER : _a;
27967
+ prov = this.getPluggable(providerName);
27968
+ _b = __read(coordinates, 2), lng = _b[0], lat = _b[1];
27969
+ _c.label = 1;
27970
+
27971
+ case 1:
27972
+ _c.trys.push([1, 3,, 4]);
27973
+
27974
+ Object(_util__WEBPACK_IMPORTED_MODULE_2__["validateCoordinates"])(lng, lat);
27975
+ return [4
27976
+ /*yield*/
27977
+ , prov.searchByCoordinates(coordinates, options)];
27978
+
27979
+ case 2:
27980
+ return [2
27981
+ /*return*/
27982
+ , _c.sent()];
27983
+
27984
+ case 3:
27985
+ error_3 = _c.sent();
27986
+ logger.debug(error_3);
27987
+ throw error_3;
27988
+
27989
+ case 4:
27990
+ return [2
27991
+ /*return*/
27992
+ ];
27993
+ }
27994
+ });
27995
+ });
27996
+ };
27997
+ /**
27998
+ * Create geofences
27999
+ * @param geofences - Single or array of geofence objects to create
28000
+ * @param options? - Optional parameters for creating geofences
28001
+ * @returns {Promise<SaveGeofencesResults>} - Promise that resolves to an object with:
28002
+ * successes: list of geofences successfully created
28003
+ * errors: list of geofences that failed to create
28004
+ */
28005
+
28006
+
28007
+ GeoClass.prototype.saveGeofences = function (geofences, options) {
28008
+ return __awaiter(this, void 0, void 0, function () {
28009
+ var _a, providerName, prov, geofenceInputArray, error_4;
28010
+
28011
+ return __generator(this, function (_b) {
28012
+ switch (_b.label) {
28013
+ case 0:
28014
+ _a = (options || {}).providerName, providerName = _a === void 0 ? DEFAULT_PROVIDER : _a;
28015
+ prov = this.getPluggable(providerName);
28016
+
28017
+ if (!Array.isArray(geofences)) {
28018
+ geofenceInputArray = [geofences];
28019
+ } else {
28020
+ geofenceInputArray = geofences;
28021
+ }
28022
+
28023
+ _b.label = 1;
28024
+
28025
+ case 1:
28026
+ _b.trys.push([1, 3,, 4]); // Validate all geofences are unique and valid before calling Provider
28027
+
28028
+
28029
+ Object(_util__WEBPACK_IMPORTED_MODULE_2__["validateGeofences"])(geofenceInputArray);
28030
+ return [4
28031
+ /*yield*/
28032
+ , prov.saveGeofences(geofenceInputArray, options)];
28033
+
28034
+ case 2:
28035
+ return [2
28036
+ /*return*/
28037
+ , _b.sent()];
28038
+
28039
+ case 3:
28040
+ error_4 = _b.sent();
28041
+ logger.debug(error_4);
28042
+ throw error_4;
28043
+
28044
+ case 4:
28045
+ return [2
28046
+ /*return*/
28047
+ ];
28048
+ }
28049
+ });
28050
+ });
28051
+ };
28052
+ /**
28053
+ * Get a single geofence by geofenceId
28054
+ * @param geofenceId: string
28055
+ * @param options?: GeofenceOptions
28056
+ * @returns Promise<Geofence> - Promise that resolves to a geofence object
28057
+ */
28058
+
28059
+
28060
+ GeoClass.prototype.getGeofence = function (geofenceId, options) {
28061
+ return __awaiter(this, void 0, void 0, function () {
28062
+ var _a, providerName, prov, error_5;
28063
+
28064
+ return __generator(this, function (_b) {
28065
+ switch (_b.label) {
28066
+ case 0:
28067
+ _a = (options || {}).providerName, providerName = _a === void 0 ? DEFAULT_PROVIDER : _a;
28068
+ prov = this.getPluggable(providerName);
28069
+ _b.label = 1;
28070
+
28071
+ case 1:
28072
+ _b.trys.push([1, 3,, 4]); // Validate geofenceId is valid before calling Provider
28073
+
28074
+
28075
+ Object(_util__WEBPACK_IMPORTED_MODULE_2__["validateGeofenceId"])(geofenceId);
28076
+ return [4
28077
+ /*yield*/
28078
+ , prov.getGeofence(geofenceId, options)];
28079
+
28080
+ case 2:
28081
+ return [2
28082
+ /*return*/
28083
+ , _b.sent()];
28084
+
28085
+ case 3:
28086
+ error_5 = _b.sent();
28087
+ logger.debug(error_5);
28088
+ throw error_5;
28089
+
28090
+ case 4:
28091
+ return [2
28092
+ /*return*/
28093
+ ];
28094
+ }
28095
+ });
28096
+ });
28097
+ };
28098
+ /**
28099
+ * List geofences
28100
+ * @param options?: ListGeofenceOptions
28101
+ * @returns {Promise<ListGeofencesResults>} - Promise that resolves to an object with:
28102
+ * entries: list of geofences - 100 geofences are listed per page
28103
+ * nextToken: token for next page of geofences
28104
+ */
28105
+
28106
+
28107
+ GeoClass.prototype.listGeofences = function (options) {
28108
+ return __awaiter(this, void 0, void 0, function () {
28109
+ var _a, providerName, prov, error_6;
27933
28110
 
27934
28111
  return __generator(this, function (_b) {
27935
28112
  switch (_b.label) {
@@ -27943,7 +28120,7 @@ function () {
27943
28120
 
27944
28121
  return [4
27945
28122
  /*yield*/
27946
- , prov.searchByCoordinates(coordinates, options)];
28123
+ , prov.listGeofences(options)];
27947
28124
 
27948
28125
  case 2:
27949
28126
  return [2
@@ -27951,9 +28128,76 @@ function () {
27951
28128
  , _b.sent()];
27952
28129
 
27953
28130
  case 3:
27954
- error_3 = _b.sent();
27955
- logger.debug(error_3);
27956
- throw error_3;
28131
+ error_6 = _b.sent();
28132
+ logger.debug(error_6);
28133
+ throw error_6;
28134
+
28135
+ case 4:
28136
+ return [2
28137
+ /*return*/
28138
+ ];
28139
+ }
28140
+ });
28141
+ });
28142
+ };
28143
+ /**
28144
+ * Delete geofences
28145
+ * @param geofenceIds: string|string[]
28146
+ * @param options?: GeofenceOptions
28147
+ * @returns {Promise<DeleteGeofencesResults>} - Promise that resolves to an object with:
28148
+ * successes: list of geofences successfully deleted
28149
+ * errors: list of geofences that failed to delete
28150
+ */
28151
+
28152
+
28153
+ GeoClass.prototype.deleteGeofences = function (geofenceIds, options) {
28154
+ return __awaiter(this, void 0, void 0, function () {
28155
+ var _a, providerName, prov, geofenceIdsInputArray, badGeofenceIds, errorString, error_7;
28156
+
28157
+ return __generator(this, function (_b) {
28158
+ switch (_b.label) {
28159
+ case 0:
28160
+ _a = (options || {}).providerName, providerName = _a === void 0 ? DEFAULT_PROVIDER : _a;
28161
+ prov = this.getPluggable(providerName);
28162
+
28163
+ if (!Array.isArray(geofenceIds)) {
28164
+ geofenceIdsInputArray = [geofenceIds];
28165
+ } else {
28166
+ geofenceIdsInputArray = geofenceIds;
28167
+ }
28168
+
28169
+ badGeofenceIds = geofenceIdsInputArray.filter(function (geofenceId) {
28170
+ try {
28171
+ Object(_util__WEBPACK_IMPORTED_MODULE_2__["validateGeofenceId"])(geofenceId);
28172
+ } catch (error) {
28173
+ return false;
28174
+ }
28175
+ });
28176
+
28177
+ if (badGeofenceIds.length > 0) {
28178
+ errorString = "Invalid geofence ids: " + badGeofenceIds;
28179
+ logger.debug(errorString);
28180
+ throw new Error(errorString);
28181
+ }
28182
+
28183
+ _b.label = 1;
28184
+
28185
+ case 1:
28186
+ _b.trys.push([1, 3,, 4]);
28187
+
28188
+ return [4
28189
+ /*yield*/
28190
+ , prov.deleteGeofences(geofenceIdsInputArray, options)];
28191
+
28192
+ case 2:
28193
+ return [2
28194
+ /*return*/
28195
+ , _b.sent()];
28196
+
28197
+ case 3:
28198
+ error_7 = _b.sent();
28199
+ logger.debug(error_7);
28200
+ throw error_7;
27957
28201
 
27958
28202
  case 4:
27959
28203
  return [2
@@ -28131,6 +28375,41 @@ var __generator = undefined && undefined.__generator || function (thisArg, body)
28131
28375
  };
28132
28376
  }
28133
28377
  };
28378
+
28379
+ var __read = undefined && undefined.__read || function (o, n) {
28380
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
28381
+ if (!m) return o;
28382
+ var i = m.call(o),
28383
+ r,
28384
+ ar = [],
28385
+ e;
28386
+
28387
+ try {
28388
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) {
28389
+ ar.push(r.value);
28390
+ }
28391
+ } catch (error) {
28392
+ e = {
28393
+ error: error
28394
+ };
28395
+ } finally {
28396
+ try {
28397
+ if (r && !r.done && (m = i["return"])) m.call(i);
28398
+ } finally {
28399
+ if (e) throw e.error;
28400
+ }
28401
+ }
28402
+
28403
+ return ar;
28404
+ };
28405
+
28406
+ var __spread = undefined && undefined.__spread || function () {
28407
+ for (var ar = [], i = 0; i < arguments.length; i++) {
28408
+ ar = ar.concat(__read(arguments[i]));
28409
+ }
28410
+
28411
+ return ar;
28412
+ };
28134
28413
  /*
28135
28414
  * Copyright 2017-2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
28136
28415
  *
@@ -28504,76 +28783,600 @@ function () {
28504
28783
  });
28505
28784
  };
28506
28785
  /**
28507
- * @private
28786
+ * Create geofences inside of a geofence collection
28787
+ * @param geofences - Array of geofence objects to create
28788
+ * @param options? - Optional parameters for creating geofences
28789
+ * @returns {Promise<AmazonLocationServiceSaveGeofencesResults>} - Promise that resolves to an object with:
28790
+ * successes: list of geofences successfully created
28791
+ * errors: list of geofences that failed to create
28508
28792
  */
28509
28793
 
28510
28794
 
28511
- AmazonLocationServiceProvider.prototype._ensureCredentials = function () {
28795
+ AmazonLocationServiceProvider.prototype.saveGeofences = function (geofences, options) {
28512
28796
  return __awaiter(this, void 0, void 0, function () {
28513
- var credentials, cred, error_4;
28797
+ var credentialsOK, PascalGeofences, results, batches;
28798
+
28799
+ var _this = this;
28800
+
28514
28801
  return __generator(this, function (_a) {
28515
28802
  switch (_a.label) {
28516
28803
  case 0:
28517
- _a.trys.push([0, 2,, 3]);
28518
-
28519
28804
  return [4
28520
28805
  /*yield*/
28521
- , _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["Credentials"].get()];
28806
+ , this._ensureCredentials()];
28522
28807
 
28523
28808
  case 1:
28524
- credentials = _a.sent();
28525
- if (!credentials) return [2
28526
- /*return*/
28527
- , false];
28528
- cred = _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["Credentials"].shear(credentials);
28529
- logger.debug('Set credentials for storage. Credentials are:', cred);
28530
- this._config.credentials = cred;
28531
- return [2
28532
- /*return*/
28533
- , true];
28809
+ credentialsOK = _a.sent();
28810
+
28811
+ if (!credentialsOK) {
28812
+ throw new Error('No credentials');
28813
+ }
28814
+
28815
+ try {
28816
+ this._verifyGeofenceCollections(options === null || options === void 0 ? void 0 : options.collectionName);
28817
+ } catch (error) {
28818
+ logger.debug(error);
28819
+ throw error;
28820
+ }
28821
+
28822
+ PascalGeofences = geofences.map(function (_a) {
28823
+ var geofenceId = _a.geofenceId,
28824
+ polygon = _a.geometry.polygon;
28825
+ return {
28826
+ GeofenceId: geofenceId,
28827
+ Geometry: {
28828
+ Polygon: polygon
28829
+ }
28830
+ };
28831
+ });
28832
+ results = {
28833
+ successes: [],
28834
+ errors: []
28835
+ };
28836
+ batches = [];
28837
+
28838
+ while (PascalGeofences.length > 0) {
28839
+ // Splice off 10 geofences from input clone due to Amazon Location Service API limit
28840
+ batches.push(PascalGeofences.splice(0, 10));
28841
+ }
28842
+
28843
+ return [4
28844
+ /*yield*/
28845
+ , Promise.all(batches.map(function (batch) {
28846
+ return __awaiter(_this, void 0, void 0, function () {
28847
+ var response, error_4;
28848
+ return __generator(this, function (_a) {
28849
+ switch (_a.label) {
28850
+ case 0:
28851
+ _a.trys.push([0, 2,, 3]);
28852
+
28853
+ return [4
28854
+ /*yield*/
28855
+ , this._AmazonLocationServiceBatchPutGeofenceCall(batch, (options === null || options === void 0 ? void 0 : options.collectionName) || this._config.geofenceCollections["default"])];
28856
+
28857
+ case 1:
28858
+ response = _a.sent();
28859
+ return [3
28860
+ /*break*/
28861
+ , 3];
28862
+
28863
+ case 2:
28864
+ error_4 = _a.sent(); // If the API call fails, add the geofences to the errors array and move to next batch
28865
+
28866
+ batch.forEach(function (geofence) {
28867
+ results.errors.push({
28868
+ geofenceId: geofence.GeofenceId,
28869
+ error: {
28870
+ code: 'APIConnectionError',
28871
+ message: error_4.message
28872
+ }
28873
+ });
28874
+ });
28875
+ return [2
28876
+ /*return*/
28877
+ ];
28878
+
28879
+ case 3:
28880
+ // Push all successes to results
28881
+ response.Successes.forEach(function (success) {
28882
+ var GeofenceId = success.GeofenceId,
28883
+ CreateTime = success.CreateTime,
28884
+ UpdateTime = success.UpdateTime;
28885
+ results.successes.push({
28886
+ geofenceId: GeofenceId,
28887
+ createTime: CreateTime,
28888
+ updateTime: UpdateTime
28889
+ });
28890
+ }); // Push all errors to results
28891
+
28892
+ response.Errors.forEach(function (error) {
28893
+ var _a = error.Error,
28894
+ Code = _a.Code,
28895
+ Message = _a.Message,
28896
+ GeofenceId = error.GeofenceId;
28897
+ results.errors.push({
28898
+ error: {
28899
+ code: Code,
28900
+ message: Message
28901
+ },
28902
+ geofenceId: GeofenceId
28903
+ });
28904
+ });
28905
+ return [2
28906
+ /*return*/
28907
+ ];
28908
+ }
28909
+ });
28910
+ });
28911
+ }))];
28534
28912
 
28535
28913
  case 2:
28536
- error_4 = _a.sent();
28537
- logger.warn('Ensure credentials error. Credentials are:', error_4);
28538
- return [2
28539
- /*return*/
28540
- , false];
28914
+ _a.sent();
28541
28915
 
28542
- case 3:
28543
28916
  return [2
28544
28917
  /*return*/
28545
- ];
28918
+ , results];
28546
28919
  }
28547
28920
  });
28548
28921
  });
28549
28922
  };
28923
+ /**
28924
+ * Get geofence from a geofence collection
28925
+ * @param geofenceId:string
28926
+ * @param options?: Optional parameters for getGeofence
28927
+ * @returns {Promise<AmazonLocationServiceGeofence>} - Promise that resolves to a geofence object
28928
+ */
28550
28929
 
28551
- AmazonLocationServiceProvider.prototype._verifyMapResources = function () {
28552
- if (!this._config.maps) {
28553
- var errorString = "No map resources found in amplify config, run 'amplify add geo' to create them and run `amplify push` after";
28554
- logger.warn(errorString);
28555
- throw new Error(errorString);
28556
- }
28557
28930
 
28558
- if (!this._config.maps["default"]) {
28559
- var errorString = "No default map resource found in amplify config, run 'amplify add geo' to create one and run `amplify push` after";
28560
- logger.warn(errorString);
28561
- throw new Error(errorString);
28562
- }
28563
- };
28931
+ AmazonLocationServiceProvider.prototype.getGeofence = function (geofenceId, options) {
28932
+ return __awaiter(this, void 0, void 0, function () {
28933
+ var credentialsOK, client, commandInput, command, response, error_5, GeofenceId, CreateTime, UpdateTime, Status, Geometry, geofence;
28934
+ return __generator(this, function (_a) {
28935
+ switch (_a.label) {
28936
+ case 0:
28937
+ return [4
28938
+ /*yield*/
28939
+ , this._ensureCredentials()];
28564
28940
 
28565
- AmazonLocationServiceProvider.prototype._verifySearchIndex = function (optionalSearchIndex) {
28566
- if ((!this._config.search_indices || !this._config.search_indices["default"]) && !optionalSearchIndex) {
28567
- var errorString = 'No Search Index found, please run `amplify add geo` to add one and run `amplify push` after.';
28568
- logger.warn(errorString);
28569
- throw new Error(errorString);
28570
- }
28571
- };
28941
+ case 1:
28942
+ credentialsOK = _a.sent();
28572
28943
 
28573
- AmazonLocationServiceProvider.CATEGORY = 'Geo';
28574
- AmazonLocationServiceProvider.PROVIDER_NAME = 'AmazonLocationService';
28575
- return AmazonLocationServiceProvider;
28576
- }();
28944
+ if (!credentialsOK) {
28945
+ throw new Error('No credentials');
28946
+ } // Verify geofence collection exists in aws-config.js
28947
+
28948
+
28949
+ try {
28950
+ this._verifyGeofenceCollections(options === null || options === void 0 ? void 0 : options.collectionName);
28951
+ } catch (error) {
28952
+ logger.debug(error);
28953
+ throw error;
28954
+ }
28955
+
28956
+ client = new _aws_sdk_client_location__WEBPACK_IMPORTED_MODULE_2__["LocationClient"]({
28957
+ credentials: this._config.credentials,
28958
+ region: this._config.region,
28959
+ customUserAgent: Object(_aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["getAmplifyUserAgent"])()
28960
+ });
28961
+ commandInput = {
28962
+ GeofenceId: geofenceId,
28963
+ CollectionName: (options === null || options === void 0 ? void 0 : options.collectionName) || this._config.geofenceCollections["default"]
28964
+ };
28965
+ command = new _aws_sdk_client_location__WEBPACK_IMPORTED_MODULE_2__["GetGeofenceCommand"](commandInput);
28966
+ _a.label = 2;
28967
+
28968
+ case 2:
28969
+ _a.trys.push([2, 4,, 5]);
28970
+
28971
+ return [4
28972
+ /*yield*/
28973
+ , client.send(command)];
28974
+
28975
+ case 3:
28976
+ response = _a.sent();
28977
+ return [3
28978
+ /*break*/
28979
+ , 5];
28980
+
28981
+ case 4:
28982
+ error_5 = _a.sent();
28983
+ logger.debug(error_5);
28984
+ throw error_5;
28985
+
28986
+ case 5:
28987
+ GeofenceId = response.GeofenceId, CreateTime = response.CreateTime, UpdateTime = response.UpdateTime, Status = response.Status, Geometry = response.Geometry;
28988
+ geofence = {
28989
+ createTime: CreateTime,
28990
+ geofenceId: GeofenceId,
28991
+ geometry: {
28992
+ polygon: Geometry.Polygon
28993
+ },
28994
+ status: Status,
28995
+ updateTime: UpdateTime
28996
+ };
28997
+ return [2
28998
+ /*return*/
28999
+ , geofence];
29000
+ }
29001
+ });
29002
+ });
29003
+ };
29004
+ /**
29005
+ * List geofences from a geofence collection
29006
+ * @param options?: ListGeofenceOptions
29007
+ * @returns {Promise<ListGeofencesResults>} - Promise that resolves to an object with:
29008
+ * entries: list of geofences - 100 geofences are listed per page
29009
+ * nextToken: token for next page of geofences
29010
+ */
29011
+
29012
+
29013
+ AmazonLocationServiceProvider.prototype.listGeofences = function (options) {
29014
+ return __awaiter(this, void 0, void 0, function () {
29015
+ var credentialsOK, client, listGeofencesInput, command, response, error_6, NextToken, Entries, results;
29016
+ return __generator(this, function (_a) {
29017
+ switch (_a.label) {
29018
+ case 0:
29019
+ return [4
29020
+ /*yield*/
29021
+ , this._ensureCredentials()];
29022
+
29023
+ case 1:
29024
+ credentialsOK = _a.sent();
29025
+
29026
+ if (!credentialsOK) {
29027
+ throw new Error('No credentials');
29028
+ } // Verify geofence collection exists in aws-config.js
29029
+
29030
+
29031
+ try {
29032
+ this._verifyGeofenceCollections(options === null || options === void 0 ? void 0 : options.collectionName);
29033
+ } catch (error) {
29034
+ logger.debug(error);
29035
+ throw error;
29036
+ }
29037
+
29038
+ client = new _aws_sdk_client_location__WEBPACK_IMPORTED_MODULE_2__["LocationClient"]({
29039
+ credentials: this._config.credentials,
29040
+ region: this._config.region,
29041
+ customUserAgent: Object(_aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["getAmplifyUserAgent"])()
29042
+ });
29043
+ listGeofencesInput = {
29044
+ NextToken: options === null || options === void 0 ? void 0 : options.nextToken,
29045
+ CollectionName: (options === null || options === void 0 ? void 0 : options.collectionName) || this._config.geofenceCollections["default"]
29046
+ };
29047
+ command = new _aws_sdk_client_location__WEBPACK_IMPORTED_MODULE_2__["ListGeofencesCommand"](listGeofencesInput);
29048
+ _a.label = 2;
29049
+
29050
+ case 2:
29051
+ _a.trys.push([2, 4,, 5]);
29052
+
29053
+ return [4
29054
+ /*yield*/
29055
+ , client.send(command)];
29056
+
29057
+ case 3:
29058
+ response = _a.sent();
29059
+ return [3
29060
+ /*break*/
29061
+ , 5];
29062
+
29063
+ case 4:
29064
+ error_6 = _a.sent();
29065
+ logger.debug(error_6);
29066
+ throw error_6;
29067
+
29068
+ case 5:
29069
+ NextToken = response.NextToken, Entries = response.Entries;
29070
+ results = {
29071
+ entries: Entries.map(function (_a) {
29072
+ var GeofenceId = _a.GeofenceId,
29073
+ CreateTime = _a.CreateTime,
29074
+ UpdateTime = _a.UpdateTime,
29075
+ Status = _a.Status,
29076
+ Polygon = _a.Geometry.Polygon;
29077
+ return {
29078
+ geofenceId: GeofenceId,
29079
+ createTime: CreateTime,
29080
+ updateTime: UpdateTime,
29081
+ status: Status,
29082
+ geometry: {
29083
+ polygon: Polygon
29084
+ }
29085
+ };
29086
+ }),
29087
+ nextToken: NextToken
29088
+ };
29089
+ return [2
29090
+ /*return*/
29091
+ , results];
29092
+ }
29093
+ });
29094
+ });
29095
+ };
29096
+ /**
29097
+ * Delete geofences from a geofence collection
29098
+ * @param geofenceIds: string|string[]
29099
+ * @param options?: GeofenceOptions
29100
+ * @returns {Promise<DeleteGeofencesResults>} - Promise that resolves to an object with:
29101
+ * successes: list of geofences successfully deleted
29102
+ * errors: list of geofences that failed to delete
29103
+ */
29104
+
29105
+
29106
+ AmazonLocationServiceProvider.prototype.deleteGeofences = function (geofenceIds, options) {
29107
+ return __awaiter(this, void 0, void 0, function () {
29108
+ var credentialsOK, results, batches, count;
29109
+
29110
+ var _this = this;
29111
+
29112
+ return __generator(this, function (_a) {
29113
+ switch (_a.label) {
29114
+ case 0:
29115
+ return [4
29116
+ /*yield*/
29117
+ , this._ensureCredentials()];
29118
+
29119
+ case 1:
29120
+ credentialsOK = _a.sent();
29121
+
29122
+ if (!credentialsOK) {
29123
+ throw new Error('No credentials');
29124
+ } // Verify geofence collection exists in aws-config.js
29125
+
29126
+
29127
+ try {
29128
+ this._verifyGeofenceCollections(options === null || options === void 0 ? void 0 : options.collectionName);
29129
+ } catch (error) {
29130
+ logger.debug(error);
29131
+ throw error;
29132
+ }
29133
+
29134
+ results = {
29135
+ successes: [],
29136
+ errors: []
29137
+ };
29138
+ batches = [];
29139
+ count = 0;
29140
+
29141
+ while (count < geofenceIds.length) {
29142
+ batches.push(geofenceIds.slice(count, count += 10));
29143
+ }
29144
+
29145
+ return [4
29146
+ /*yield*/
29147
+ , Promise.all(batches.map(function (batch) {
29148
+ return __awaiter(_this, void 0, void 0, function () {
29149
+ var response, error_7, badGeofenceIds;
29150
+
29151
+ var _a;
29152
+
29153
+ return __generator(this, function (_b) {
29154
+ switch (_b.label) {
29155
+ case 0:
29156
+ _b.trys.push([0, 2,, 3]);
29157
+
29158
+ return [4
29159
+ /*yield*/
29160
+ , this._AmazonLocationServiceBatchDeleteGeofenceCall(batch, (options === null || options === void 0 ? void 0 : options.collectionName) || this._config.geofenceCollections["default"])];
29161
+
29162
+ case 1:
29163
+ response = _b.sent();
29164
+ return [3
29165
+ /*break*/
29166
+ , 3];
29167
+
29168
+ case 2:
29169
+ error_7 = _b.sent(); // If the API call fails, add the geofences to the errors array and move to next batch
29170
+
29171
+ batch.forEach(function (geofenceId) {
29172
+ var errorObject = {
29173
+ geofenceId: geofenceId,
29174
+ error: {
29175
+ code: error_7.message,
29176
+ message: error_7.message
29177
+ }
29178
+ };
29179
+ results.errors.push(errorObject);
29180
+ });
29181
+ return [2
29182
+ /*return*/
29183
+ ];
29184
+
29185
+ case 3:
29186
+ badGeofenceIds = response.Errors.map(function (_a) {
29187
+ var geofenceId = _a.geofenceId;
29188
+ return geofenceId;
29189
+ });
29190
+
29191
+ (_a = results.successes).push.apply(_a, __spread(batch.filter(function (Id) {
29192
+ return !badGeofenceIds.includes(Id);
29193
+ })));
29194
+
29195
+ return [2
29196
+ /*return*/
29197
+ ];
29198
+ }
29199
+ });
29200
+ });
29201
+ }))];
29202
+
29203
+ case 2:
29204
+ _a.sent();
29205
+
29206
+ return [2
29207
+ /*return*/
29208
+ , results];
29209
+ }
29210
+ });
29211
+ });
29212
+ };
29213
+ /**
29214
+ * @private
29215
+ */
29216
+
29217
+
29218
+ AmazonLocationServiceProvider.prototype._ensureCredentials = function () {
29219
+ return __awaiter(this, void 0, void 0, function () {
29220
+ var credentials, cred, error_8;
29221
+ return __generator(this, function (_a) {
29222
+ switch (_a.label) {
29223
+ case 0:
29224
+ _a.trys.push([0, 2,, 3]);
29225
+
29226
+ return [4
29227
+ /*yield*/
29228
+ , _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["Credentials"].get()];
29229
+
29230
+ case 1:
29231
+ credentials = _a.sent();
29232
+ if (!credentials) return [2
29233
+ /*return*/
29234
+ , false];
29235
+ cred = _aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["Credentials"].shear(credentials);
29236
+ logger.debug('Set credentials for storage. Credentials are:', cred);
29237
+ this._config.credentials = cred;
29238
+ return [2
29239
+ /*return*/
29240
+ , true];
29241
+
29242
+ case 2:
29243
+ error_8 = _a.sent();
29244
+ logger.debug('Ensure credentials error. Credentials are:', error_8);
29245
+ return [2
29246
+ /*return*/
29247
+ , false];
29248
+
29249
+ case 3:
29250
+ return [2
29251
+ /*return*/
29252
+ ];
29253
+ }
29254
+ });
29255
+ });
29256
+ };
29257
+
29258
+ AmazonLocationServiceProvider.prototype._verifyMapResources = function () {
29259
+ if (!this._config.maps) {
29260
+ var errorString = "No map resources found in amplify config, run 'amplify add geo' to create one and run `amplify push` after";
29261
+ logger.debug(errorString);
29262
+ throw new Error(errorString);
29263
+ }
29264
+
29265
+ if (!this._config.maps["default"]) {
29266
+ var errorString = "No default map resource found in amplify config, run 'amplify add geo' to create one and run `amplify push` after";
29267
+ logger.debug(errorString);
29268
+ throw new Error(errorString);
29269
+ }
29270
+ };
29271
+
29272
+ AmazonLocationServiceProvider.prototype._verifySearchIndex = function (optionalSearchIndex) {
29273
+ if ((!this._config.search_indices || !this._config.search_indices["default"]) && !optionalSearchIndex) {
29274
+ var errorString = 'No Search Index found in amplify config, please run `amplify add geo` to create one and run `amplify push` after.';
29275
+ logger.debug(errorString);
29276
+ throw new Error(errorString);
29277
+ }
29278
+ };
29279
+
29280
+ AmazonLocationServiceProvider.prototype._verifyGeofenceCollections = function (optionalGeofenceCollectionName) {
29281
+ if ((!this._config.geofenceCollections || !this._config.geofenceCollections["default"]) && !optionalGeofenceCollectionName) {
29282
+ var errorString = 'No Geofence Collections found, please run `amplify add geo` to create one and run `amplify push` after.';
29283
+ logger.debug(errorString);
29284
+ throw new Error(errorString);
29285
+ }
29286
+ };
29287
+
29288
+ AmazonLocationServiceProvider.prototype._AmazonLocationServiceBatchPutGeofenceCall = function (PascalGeofences, collectionName) {
29289
+ return __awaiter(this, void 0, void 0, function () {
29290
+ var geofenceInput, client, command, response, error_9;
29291
+ return __generator(this, function (_a) {
29292
+ switch (_a.label) {
29293
+ case 0:
29294
+ geofenceInput = {
29295
+ Entries: PascalGeofences,
29296
+ CollectionName: collectionName || this._config.geofenceCollections["default"]
29297
+ };
29298
+ client = new _aws_sdk_client_location__WEBPACK_IMPORTED_MODULE_2__["LocationClient"]({
29299
+ credentials: this._config.credentials,
29300
+ region: this._config.region,
29301
+ customUserAgent: Object(_aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["getAmplifyUserAgent"])()
29302
+ });
29303
+ command = new _aws_sdk_client_location__WEBPACK_IMPORTED_MODULE_2__["BatchPutGeofenceCommand"](geofenceInput);
29304
+ _a.label = 1;
29305
+
29306
+ case 1:
29307
+ _a.trys.push([1, 3,, 4]);
29308
+
29309
+ return [4
29310
+ /*yield*/
29311
+ , client.send(command)];
29312
+
29313
+ case 2:
29314
+ response = _a.sent();
29315
+ return [3
29316
+ /*break*/
29317
+ , 4];
29318
+
29319
+ case 3:
29320
+ error_9 = _a.sent();
29321
+ throw error_9;
29322
+
29323
+ case 4:
29324
+ return [2
29325
+ /*return*/
29326
+ , response];
29327
+ }
29328
+ });
29329
+ });
29330
+ };
29331
+
29332
+ AmazonLocationServiceProvider.prototype._AmazonLocationServiceBatchDeleteGeofenceCall = function (geofenceIds, collectionName) {
29333
+ return __awaiter(this, void 0, void 0, function () {
29334
+ var deleteGeofencesInput, client, command, response, error_10;
29335
+ return __generator(this, function (_a) {
29336
+ switch (_a.label) {
29337
+ case 0:
29338
+ deleteGeofencesInput = {
29339
+ GeofenceIds: geofenceIds,
29340
+ CollectionName: collectionName || this._config.geofenceCollections["default"]
29341
+ };
29342
+ client = new _aws_sdk_client_location__WEBPACK_IMPORTED_MODULE_2__["LocationClient"]({
29343
+ credentials: this._config.credentials,
29344
+ region: this._config.region,
29345
+ customUserAgent: Object(_aws_amplify_core__WEBPACK_IMPORTED_MODULE_1__["getAmplifyUserAgent"])()
29346
+ });
29347
+ command = new _aws_sdk_client_location__WEBPACK_IMPORTED_MODULE_2__["BatchDeleteGeofenceCommand"](deleteGeofencesInput);
29348
+ _a.label = 1;
29349
+
29350
+ case 1:
29351
+ _a.trys.push([1, 3,, 4]);
29352
+
29353
+ return [4
29354
+ /*yield*/
29355
+ , client.send(command)];
29356
+
29357
+ case 2:
29358
+ response = _a.sent();
29359
+ return [3
29360
+ /*break*/
29361
+ , 4];
29362
+
29363
+ case 3:
29364
+ error_10 = _a.sent();
29365
+ throw error_10;
29366
+
29367
+ case 4:
29368
+ return [2
29369
+ /*return*/
29370
+ , response];
29371
+ }
29372
+ });
29373
+ });
29374
+ };
29375
+
29376
+ AmazonLocationServiceProvider.CATEGORY = 'Geo';
29377
+ AmazonLocationServiceProvider.PROVIDER_NAME = 'AmazonLocationService';
29378
+ return AmazonLocationServiceProvider;
29379
+ }();
28577
29380
 
28578
29381
 
28579
29382
 
@@ -28593,6 +29396,214 @@ __webpack_require__.r(__webpack_exports__);
28593
29396
 
28594
29397
 
28595
29398
 
29399
+ /***/ }),
29400
+
29401
+ /***/ "./lib-esm/util.js":
29402
+ /*!*************************!*\
29403
+ !*** ./lib-esm/util.js ***!
29404
+ \*************************/
29405
+ /*! exports provided: validateCoordinates, validateGeofenceId, validateLinearRing, validatePolygon, validateGeofences */
29406
+ /***/ (function(module, __webpack_exports__, __webpack_require__) {
29407
+
29408
+ "use strict";
29409
+ __webpack_require__.r(__webpack_exports__);
29410
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "validateCoordinates", function() { return validateCoordinates; });
29411
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "validateGeofenceId", function() { return validateGeofenceId; });
29412
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "validateLinearRing", function() { return validateLinearRing; });
29413
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "validatePolygon", function() { return validatePolygon; });
29414
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "validateGeofences", function() { return validateGeofences; });
29415
+ /* harmony import */ var _aws_amplify_core__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @aws-amplify/core */ "@aws-amplify/core");
29416
+ /* harmony import */ var _aws_amplify_core__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_aws_amplify_core__WEBPACK_IMPORTED_MODULE_0__);
29417
+ var __read = undefined && undefined.__read || function (o, n) {
29418
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
29419
+ if (!m) return o;
29420
+ var i = m.call(o),
29421
+ r,
29422
+ ar = [],
29423
+ e;
29424
+
29425
+ try {
29426
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) {
29427
+ ar.push(r.value);
29428
+ }
29429
+ } catch (error) {
29430
+ e = {
29431
+ error: error
29432
+ };
29433
+ } finally {
29434
+ try {
29435
+ if (r && !r.done && (m = i["return"])) m.call(i);
29436
+ } finally {
29437
+ if (e) throw e.error;
29438
+ }
29439
+ }
29440
+
29441
+ return ar;
29442
+ };
29443
+ /*
29444
+ * Copyright 2017-2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
29445
+ *
29446
+ * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
29447
+ * the License. A copy of the License is located at
29448
+ *
29449
+ * http://aws.amazon.com/apache2.0/
29450
+ *
29451
+ * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
29452
+ * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
29453
+ * and limitations under the License.
29454
+ */
29455
+
29456
+
29457
+
29458
+ var logger = new _aws_amplify_core__WEBPACK_IMPORTED_MODULE_0__["ConsoleLogger"]('Geo');
29459
+ function validateCoordinates(lng, lat) {
29460
+ if (!Number.isFinite(lng) || !Number.isFinite(lat)) {
29461
+ throw new Error("Invalid coordinates: [" + lng + "," + lat + "]");
29462
+ }
29463
+
29464
+ if (lat < -90 || lat > 90) {
29465
+ var errorString = 'Latitude must be between -90 and 90 degrees inclusive.';
29466
+ logger.debug(errorString);
29467
+ throw new Error(errorString);
29468
+ } else if (lng < -180 || lng > 180) {
29469
+ var errorString = 'Longitude must be between -180 and 180 degrees inclusive.';
29470
+ logger.debug(errorString);
29471
+ throw new Error(errorString);
29472
+ }
29473
+ }
29474
+ function validateGeofenceId(geofenceId) {
29475
+ var geofenceIdRegex = /^(?:[\x2D\.0-9A-Z_a-z\xAA\xB2\xB3\xB5\xB9\xBA\xBC-\xBE\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u048A-\u052F\u0531-\u0556\u0559\u0560-\u0588\u05D0-\u05EA\u05EF-\u05F2\u0620-\u064A\u0660-\u0669\u066E\u066F\u0671-\u06D3\u06D5\u06E5\u06E6\u06EE-\u06FC\u06FF\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07C0-\u07EA\u07F4\u07F5\u07FA\u0800-\u0815\u081A\u0824\u0828\u0840-\u0858\u0860-\u086A\u0870-\u0887\u0889-\u088E\u08A0-\u08C9\u0904-\u0939\u093D\u0950\u0958-\u0961\u0966-\u096F\u0971-\u0980\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BD\u09CE\u09DC\u09DD\u09DF-\u09E1\u09E6-\u09F1\u09F4-\u09F9\u09FC\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A59-\u0A5C\u0A5E\u0A66-\u0A6F\u0A72-\u0A74\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABD\u0AD0\u0AE0\u0AE1\u0AE6-\u0AEF\u0AF9\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3D\u0B5C\u0B5D\u0B5F-\u0B61\u0B66-\u0B6F\u0B71-\u0B77\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BD0\u0BE6-\u0BF2\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D\u0C58-\u0C5A\u0C5D\u0C60\u0C61\u0C66-\u0C6F\u0C78-\u0C7E\u0C80\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBD\u0CDD\u0CDE\u0CE0\u0CE1\u0CE6-\u0CEF\u0CF1\u0CF2\u0D04-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D\u0D4E\u0D54-\u0D56\u0D58-\u0D61\u0D66-\u0D78\u0D7A-\u0D7F\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0DE6-\u0DEF\u0E01-\u0E30\u0E32\u0E33\u0E40-\u0E46\u0E50-\u0E59\u0E81\u0E82\u0E84\u0E86-\u0E8A\u0E8C-\u0EA3\u0EA5\u0EA7-\u0EB0\u0EB2\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6\u0ED0-\u0ED9\u0EDC-\u0EDF\u0F00\u0F20-\u0F33\u0F40-\u0F47\u0F49-\u0F6C\u0F88-\u0F8C\u1000-\u102A\u103F-\u1049\u1050-\u1055\u105A-\u105D\u1061\u1065\u1066\u106E-\u1070\u1075-\u1081\u108E\u1090-\u1099\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u1369-\u137C\u1380-\u138F\u13A0-\u13F5\u13F8-\u13FD\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16EE-\u16F8\u1700-\u1711\u171F-\u1731\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17D7\u17DC\u17E0-\u17E9\u17F0-\u17F9\u1810-\u1819\u1820-\u1878\u1880-\u1884\u1887-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191E\u1946-\u196D\u1970-\u1974\u1980-\u19AB\u19B0-\u19C9\u19D0-\u19DA\u1A00-\u1A16\u1A20-\u1A54\u1A80-\u1A89\u1A90-\u1A99\u1AA7\u1B05-\u1B33\u1B45-\u1B4C\u1B50-\u1B59\u1B83-\u1BA0\u1BAE-\u1BE5\u1C00-\u1C23\u1C40-\u1C49\u1C4D-\u1C7D\u1C80-\u1C88\u1C90-\u1CBA\u1CBD-\u1CBF\u1CE9-\u1CEC\u1CEE-\u1CF3\u1CF5\u1CF6\u1CFA\u1D00-\u1DBF\u1E00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2070\u2071\u2074-\u2079\u207F-\u2089\u2090-\u209C\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2150-\u2189\u2460-\u249B\u24EA-\u24FF\u2776-\u2793\u2C00-\u2CE4\u2CEB-\u2CEE\u2CF2\u2CF3\u2CFD\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D80-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2E2F\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303C\u3041-\u3096\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312F\u3131-\u318E\u3192-\u3195\u31A0-\u31BF\u31F0-\u31FF\u3220-\u3229\u3248-\u324F\u3251-\u325F\u3280-\u3289\u32B1-\u32BF\u3400-\u4DBF\u4E00-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA62B\uA640-\uA66E\uA67F-\uA69D\uA6A0-\uA6EF\uA717-\uA71F\uA722-\uA788\uA78B-\uA7CA\uA7D0\uA7D1\uA7D3\uA7D5-\uA7D9\uA7F2-\uA801\uA803-\uA805\uA807-\uA80A\uA80C-\uA822\uA830-\uA835\uA840-\uA873\uA882-\uA8B3\uA8D0-\uA8D9\uA8F2-\uA8F7\uA8FB\uA8FD\uA8FE\uA900-\uA925\uA930-\uA946\uA960-\uA97C\uA984-\uA9B2\uA9CF-\uA9D9\uA9E0-\uA9E4\uA9E6-\uA9FE\uAA00-\uAA28\uAA40-\uAA42\uAA44-\uAA4B\uAA50-\uAA59\uAA60-\uAA76\uAA7A\uAA7E-\uAAAF\uAAB1\uAAB5\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAADD\uAAE0-\uAAEA\uAAF2-\uAAF4\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB69\uAB70-\uABE2\uABF0-\uABF9\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE70-\uFE74\uFE76-\uFEFC\uFF10-\uFF19\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]|\uD800[\uDC00-\uDC0B\uDC0D-\uDC26\uDC28-\uDC3A\uDC3C\uDC3D\uDC3F-\uDC4D\uDC50-\uDC5D\uDC80-\uDCFA\uDD07-\uDD33\uDD40-\uDD78\uDD8A\uDD8B\uDE80-\uDE9C\uDEA0-\uDED0\uDEE1-\uDEFB\uDF00-\uDF23\uDF2D-\uDF4A\uDF50-\uDF75\uDF80-\uDF9D\uDFA0-\uDFC3\uDFC8-\uDFCF\uDFD1-\uDFD5]|\uD801[\uDC00-\uDC9D\uDCA0-\uDCA9\uDCB0-\uDCD3\uDCD8-\uDCFB\uDD00-\uDD27\uDD30-\uDD63\uDD70-\uDD7A\uDD7C-\uDD8A\uDD8C-\uDD92\uDD94\uDD95\uDD97-\uDDA1\uDDA3-\uDDB1\uDDB3-\uDDB9\uDDBB\uDDBC\uDE00-\uDF36\uDF40-\uDF55\uDF60-\uDF67\uDF80-\uDF85\uDF87-\uDFB0\uDFB2-\uDFBA]|\uD802[\uDC00-\uDC05\uDC08\uDC0A-\uDC35\uDC37\uDC38\uDC3C\uDC3F-\uDC55\uDC58-\uDC76\uDC79-\uDC9E\uDCA7-\uDCAF\uDCE0-\uDCF2\uDCF4\uDCF5\uDCFB-\uDD1B\uDD20-\uDD39\uDD80-\uDDB7\uDDBC-\uDDCF\uDDD2-\uDE00\uDE10-\uDE13\uDE15-\uDE17\uDE19-\uDE35\uDE40-\uDE48\uDE60-\uDE7E\uDE80-\uDE9F\uDEC0-\uDEC7\uDEC9-\uDEE4\uDEEB-\uDEEF\uDF00-\uDF35\uDF40-\uDF55\uDF58-\uDF72\uDF78-\uDF91\uDFA9-\uDFAF]|\uD803[\uDC00-\uDC48\uDC80-\uDCB2\uDCC0-\uDCF2\uDCFA-\uDD23\uDD30-\uDD39\uDE60-\uDE7E\uDE80-\uDEA9\uDEB0\uDEB1\uDF00-\uDF27\uDF30-\uDF45\uDF51-\uDF54\uDF70-\uDF81\uDFB0-\uDFCB\uDFE0-\uDFF6]|\uD804[\uDC03-\uDC37\uDC52-\uDC6F\uDC71\uDC72\uDC75\uDC83-\uDCAF\uDCD0-\uDCE8\uDCF0-\uDCF9\uDD03-\uDD26\uDD36-\uDD3F\uDD44\uDD47\uDD50-\uDD72\uDD76\uDD83-\uDDB2\uDDC1-\uDDC4\uDDD0-\uDDDA\uDDDC\uDDE1-\uDDF4\uDE00-\uDE11\uDE13-\uDE2B\uDE80-\uDE86\uDE88\uDE8A-\uDE8D\uDE8F-\uDE9D\uDE9F-\uDEA8\uDEB0-\uDEDE\uDEF0-\uDEF9\uDF05-\uDF0C\uDF0F\uDF10\uDF13-\uDF28\uDF2A-\uDF30\uDF32\uDF33\uDF35-\uDF39\uDF3D\uDF50\uDF5D-\uDF61]|\uD805[\uDC00-\uDC34\uDC47-\uDC4A\uDC50-\uDC59\uDC5F-\uDC61\uDC80-\uDCAF\uDCC4\uDCC5\uDCC7\uDCD0-\uDCD9\uDD80-\uDDAE\uDDD8-\uDDDB\uDE00-\uDE2F\uDE44\uDE50-\uDE59\uDE80-\uDEAA\uDEB8\uDEC0-\uDEC9\uDF00-\uDF1A\uDF30-\uDF3B\uDF40-\uDF46]|\uD806[\uDC00-\uDC2B\uDCA0-\uDCF2\uDCFF-\uDD06\uDD09\uDD0C-\uDD13\uDD15\uDD16\uDD18-\uDD2F\uDD3F\uDD41\uDD50-\uDD59\uDDA0-\uDDA7\uDDAA-\uDDD0\uDDE1\uDDE3\uDE00\uDE0B-\uDE32\uDE3A\uDE50\uDE5C-\uDE89\uDE9D\uDEB0-\uDEF8]|\uD807[\uDC00-\uDC08\uDC0A-\uDC2E\uDC40\uDC50-\uDC6C\uDC72-\uDC8F\uDD00-\uDD06\uDD08\uDD09\uDD0B-\uDD30\uDD46\uDD50-\uDD59\uDD60-\uDD65\uDD67\uDD68\uDD6A-\uDD89\uDD98\uDDA0-\uDDA9\uDEE0-\uDEF2\uDFB0\uDFC0-\uDFD4]|\uD808[\uDC00-\uDF99]|\uD809[\uDC00-\uDC6E\uDC80-\uDD43]|\uD80B[\uDF90-\uDFF0]|[\uD80C\uD81C-\uD820\uD822\uD840-\uD868\uD86A-\uD86C\uD86F-\uD872\uD874-\uD879\uD880-\uD883][\uDC00-\uDFFF]|\uD80D[\uDC00-\uDC2E]|\uD811[\uDC00-\uDE46]|\uD81A[\uDC00-\uDE38\uDE40-\uDE5E\uDE60-\uDE69\uDE70-\uDEBE\uDEC0-\uDEC9\uDED0-\uDEED\uDF00-\uDF2F\uDF40-\uDF43\uDF50-\uDF59\uDF5B-\uDF61\uDF63-\uDF77\uDF7D-\uDF8F]|\uD81B[\uDE40-\uDE96\uDF00-\uDF4A\uDF50\uDF93-\uDF9F\uDFE0\uDFE1\uDFE3]|\uD821[\uDC00-\uDFF7]|\uD823[\uDC00-\uDCD5\uDD00-\uDD08]|\uD82B[\uDFF0-\uDFF3\uDFF5-\uDFFB\uDFFD\uDFFE]|\uD82C[\uDC00-\uDD22\uDD50-\uDD52\uDD64-\uDD67\uDD70-\uDEFB]|\uD82F[\uDC00-\uDC6A\uDC70-\uDC7C\uDC80-\uDC88\uDC90-\uDC99]|\uD834[\uDEE0-\uDEF3\uDF60-\uDF78]|\uD835[\uDC00-\uDC54\uDC56-\uDC9C\uDC9E\uDC9F\uDCA2\uDCA5\uDCA6\uDCA9-\uDCAC\uDCAE-\uDCB9\uDCBB\uDCBD-\uDCC3\uDCC5-\uDD05\uDD07-\uDD0A\uDD0D-\uDD14\uDD16-\uDD1C\uDD1E-\uDD39\uDD3B-\uDD3E\uDD40-\uDD44\uDD46\uDD4A-\uDD50\uDD52-\uDEA5\uDEA8-\uDEC0\uDEC2-\uDEDA\uDEDC-\uDEFA\uDEFC-\uDF14\uDF16-\uDF34\uDF36-\uDF4E\uDF50-\uDF6E\uDF70-\uDF88\uDF8A-\uDFA8\uDFAA-\uDFC2\uDFC4-\uDFCB\uDFCE-\uDFFF]|\uD837[\uDF00-\uDF1E]|\uD838[\uDD00-\uDD2C\uDD37-\uDD3D\uDD40-\uDD49\uDD4E\uDE90-\uDEAD\uDEC0-\uDEEB\uDEF0-\uDEF9]|\uD839[\uDFE0-\uDFE6\uDFE8-\uDFEB\uDFED\uDFEE\uDFF0-\uDFFE]|\uD83A[\uDC00-\uDCC4\uDCC7-\uDCCF\uDD00-\uDD43\uDD4B\uDD50-\uDD59]|\uD83B[\uDC71-\uDCAB\uDCAD-\uDCAF\uDCB1-\uDCB4\uDD01-\uDD2D\uDD2F-\uDD3D\uDE00-\uDE03\uDE05-\uDE1F\uDE21\uDE22\uDE24\uDE27\uDE29-\uDE32\uDE34-\uDE37\uDE39\uDE3B\uDE42\uDE47\uDE49\uDE4B\uDE4D-\uDE4F\uDE51\uDE52\uDE54\uDE57\uDE59\uDE5B\uDE5D\uDE5F\uDE61\uDE62\uDE64\uDE67-\uDE6A\uDE6C-\uDE72\uDE74-\uDE77\uDE79-\uDE7C\uDE7E\uDE80-\uDE89\uDE8B-\uDE9B\uDEA1-\uDEA3\uDEA5-\uDEA9\uDEAB-\uDEBB]|\uD83C[\uDD00-\uDD0C]|\uD83E[\uDFF0-\uDFF9]|\uD869[\uDC00-\uDEDF\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF38\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D\uDC20-\uDFFF]|\uD873[\uDC00-\uDEA1\uDEB0-\uDFFF]|\uD87A[\uDC00-\uDFE0]|\uD87E[\uDC00-\uDE1D]|\uD884[\uDC00-\uDF4A])+$/i; // Check if geofenceId is valid
29476
+
29477
+ if (!geofenceIdRegex.test(geofenceId)) {
29478
+ var errorString = "Invalid geofenceId: " + geofenceId + " Ids can only contain alphanumeric characters, hyphens, underscores and periods.";
29479
+ logger.debug(errorString);
29480
+ throw new Error(errorString);
29481
+ }
29482
+ }
29483
+ function validateLinearRing(linearRing) {
29484
+ // Validate LinearRing size, must be at least 4 points
29485
+ if (linearRing.length < 4) {
29486
+ var errorString = 'LinearRing must contain 4 or more coordinates.';
29487
+ logger.debug(errorString);
29488
+ throw new Error(errorString);
29489
+ } // Validate all coordinates are valid, error with which ones are bad
29490
+
29491
+
29492
+ var badCoordinates = [];
29493
+ linearRing.forEach(function (coordinates) {
29494
+ try {
29495
+ validateCoordinates(coordinates[0], coordinates[1]);
29496
+ } catch (error) {
29497
+ badCoordinates.push({
29498
+ coordinates: coordinates,
29499
+ error: error.message
29500
+ });
29501
+ }
29502
+ });
29503
+
29504
+ if (badCoordinates.length > 0) {
29505
+ var errorString = "One or more of the coordinates are not valid: " + JSON.stringify(badCoordinates);
29506
+ logger.debug(errorString);
29507
+ throw new Error(errorString);
29508
+ } // Validate first and last coordinates are the same
29509
+
29510
+
29511
+ var _a = __read(linearRing[0], 2),
29512
+ lngA = _a[0],
29513
+ latA = _a[1];
29514
+
29515
+ var _b = __read(linearRing[linearRing.length - 1], 2),
29516
+ lngB = _b[0],
29517
+ latB = _b[1];
29518
+
29519
+ if (lngA !== lngB || latA !== latB) {
29520
+ var errorString = "LinearRing's first and last coordinates are not the same";
29521
+ logger.debug(errorString);
29522
+ throw new Error(errorString);
29523
+ }
29524
+ }
29525
+ function validatePolygon(polygon) {
29526
+ if (!Array.isArray(polygon)) {
29527
+ var errorString = "Polygon " + JSON.stringify(polygon) + " is of incorrect structure. It should be an array of 'LinearRing'";
29528
+ logger.debug(errorString);
29529
+ throw new Error(errorString);
29530
+ }
29531
+
29532
+ if (!(polygon.length === 1)) {
29533
+ var errorString = "Polygon " + JSON.stringify(polygon) + " geometry.polygon must have a single LinearRing array";
29534
+ logger.debug(errorString);
29535
+ throw new Error(errorString);
29536
+ }
29537
+
29538
+ var verticesCount = polygon.reduce(function (prev, linearRing) {
29539
+ return prev + linearRing.length;
29540
+ }, 0);
29541
+
29542
+ if (verticesCount > 1000) {
29543
+ var errorString = "Polygon has more than the maximum 1000 vertices.";
29544
+ logger.debug(errorString);
29545
+ throw new Error(errorString);
29546
+ }
29547
+ }
29548
+ function validateGeofences(geofences) {
29549
+ var geofenceIds = {};
29550
+ geofences.forEach(function (geofence) {
29551
+ // verify all required properties are present
29552
+ if (!geofence.geofenceId) {
29553
+ var errorString = "Geofence " + JSON.stringify(geofence) + " is missing geofenceId";
29554
+ logger.debug(errorString);
29555
+ throw new Error(errorString);
29556
+ }
29557
+
29558
+ if (!geofence.geometry) {
29559
+ var errorString = "Geofence " + JSON.stringify(geofence) + " is missing geometry";
29560
+ logger.debug(errorString);
29561
+ throw new Error(errorString);
29562
+ }
29563
+
29564
+ if (!geofence.geometry.polygon) {
29565
+ var errorString = "Geofence " + JSON.stringify(geofence) + " is missing geometry.polygon";
29566
+ logger.debug(errorString);
29567
+ throw new Error(errorString);
29568
+ }
29569
+
29570
+ var geofenceId = geofence.geofenceId,
29571
+ polygon = geofence.geometry.polygon; // Validate geofenceId is valid
29572
+
29573
+ try {
29574
+ validateGeofenceId(geofenceId);
29575
+ } catch (error) {
29576
+ throw error;
29577
+ } // Validate geofenceId is unique
29578
+
29579
+
29580
+ if (geofenceIds[geofenceId]) {
29581
+ var errorString = "Duplicate geofenceId: " + geofenceId;
29582
+ logger.debug(errorString);
29583
+ throw new Error(errorString);
29584
+ } else {
29585
+ geofenceIds[geofenceId] = true;
29586
+ } // Validate polygon length and structure
29587
+
29588
+
29589
+ try {
29590
+ validatePolygon(polygon);
29591
+ } catch (error) {
29592
+ if (error.message === "Polygon has more than the maximum 1000 vertices.") {
29593
+ var errorString = "Geofence " + geofenceId + " has more than the maximum of 1000 vertices";
29594
+ logger.debug(errorString);
29595
+ throw new Error(errorString);
29596
+ }
29597
+ } // Validate LinearRing length, structure, and coordinates
29598
+
29599
+
29600
+ var _a = __read(polygon, 1),
29601
+ linearRing = _a[0];
29602
+
29603
+ validateLinearRing(linearRing);
29604
+ });
29605
+ }
29606
+
28596
29607
  /***/ }),
28597
29608
 
28598
29609
  /***/ "@aws-amplify/core":