@aws-amplify/geo 3.0.1-api-v6-models.9351bcf.0 → 3.0.1-api-v6-models.891fe0d.0

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