@aws-amplify/geo 2.3.4-user-agent-backup.c6dfb36.0 → 2.3.4

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 (40) hide show
  1. package/lib/Geo.d.ts +41 -3
  2. package/lib/Geo.js +230 -20
  3. package/lib/Geo.js.map +1 -1
  4. package/lib/Providers/AmazonLocationServiceProvider.d.ts +8 -15
  5. package/lib/Providers/AmazonLocationServiceProvider.js +20 -26
  6. package/lib/Providers/AmazonLocationServiceProvider.js.map +1 -1
  7. package/lib/types/Provider.d.ts +8 -9
  8. package/lib-esm/Geo.d.ts +41 -3
  9. package/lib-esm/Geo.js +232 -22
  10. package/lib-esm/Geo.js.map +1 -1
  11. package/lib-esm/Providers/AmazonLocationServiceProvider.d.ts +8 -15
  12. package/lib-esm/Providers/AmazonLocationServiceProvider.js +20 -26
  13. package/lib-esm/Providers/AmazonLocationServiceProvider.js.map +1 -1
  14. package/lib-esm/types/Provider.d.ts +8 -9
  15. package/package.json +5 -6
  16. package/src/Geo.ts +203 -11
  17. package/src/Providers/AmazonLocationServiceProvider.ts +20 -39
  18. package/src/types/Provider.ts +8 -22
  19. package/internals/package.json +0 -8
  20. package/lib/internals/InternalGeo.d.ts +0 -119
  21. package/lib/internals/InternalGeo.js +0 -354
  22. package/lib/internals/InternalGeo.js.map +0 -1
  23. package/lib/internals/index.d.ts +0 -1
  24. package/lib/internals/index.js +0 -7
  25. package/lib/internals/index.js.map +0 -1
  26. package/lib/internals/utils.d.ts +0 -2
  27. package/lib/internals/utils.js +0 -10
  28. package/lib/internals/utils.js.map +0 -1
  29. package/lib-esm/internals/InternalGeo.d.ts +0 -119
  30. package/lib-esm/internals/InternalGeo.js +0 -352
  31. package/lib-esm/internals/InternalGeo.js.map +0 -1
  32. package/lib-esm/internals/index.d.ts +0 -1
  33. package/lib-esm/internals/index.js +0 -4
  34. package/lib-esm/internals/index.js.map +0 -1
  35. package/lib-esm/internals/utils.d.ts +0 -2
  36. package/lib-esm/internals/utils.js +0 -8
  37. package/lib-esm/internals/utils.js.map +0 -1
  38. package/src/internals/InternalGeo.ts +0 -393
  39. package/src/internals/index.ts +0 -3
  40. package/src/internals/utils.ts +0 -15
@@ -1,393 +0,0 @@
1
- // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
- // SPDX-License-Identifier: Apache-2.0
3
- import {
4
- Amplify,
5
- CustomUserAgentDetails,
6
- GeoAction,
7
- ConsoleLogger as Logger,
8
- parseAWSExports,
9
- } from '@aws-amplify/core';
10
- import { AmazonLocationServiceProvider } from '../Providers/AmazonLocationServiceProvider';
11
-
12
- import { validateCoordinates } from '../util';
13
-
14
- import {
15
- Place,
16
- GeoConfig,
17
- Coordinates,
18
- SearchByTextOptions,
19
- SearchByCoordinatesOptions,
20
- GeoProvider,
21
- MapStyle,
22
- GeofenceId,
23
- GeofenceInput,
24
- GeofenceOptions,
25
- SaveGeofencesResults,
26
- Geofence,
27
- ListGeofenceOptions,
28
- ListGeofenceResults,
29
- DeleteGeofencesResults,
30
- searchByPlaceIdOptions,
31
- } from '../types';
32
- import { getGeoUserAgentDetails } from './utils';
33
-
34
- const logger = new Logger('Geo');
35
-
36
- const DEFAULT_PROVIDER = 'AmazonLocationService';
37
- export class InternalGeoClass {
38
- static MODULE = 'InternalGeo';
39
- /**
40
- * @private
41
- */
42
- private _config: GeoConfig;
43
- private _pluggables: GeoProvider[];
44
-
45
- constructor() {
46
- this._config = {};
47
- this._pluggables = [];
48
- logger.debug('Geo Options', this._config);
49
- }
50
-
51
- /**
52
- * get the name of the module category
53
- * @returns {string} name of the module category
54
- */
55
- public getModuleName() {
56
- return InternalGeoClass.MODULE;
57
- }
58
-
59
- /**
60
- * add plugin into Geo category
61
- * @param {Object} pluggable - an instance of the plugin
62
- */
63
- public addPluggable(pluggable: GeoProvider) {
64
- if (pluggable && pluggable.getCategory() === 'Geo') {
65
- this._pluggables.push(pluggable);
66
- const config = pluggable.configure(
67
- this._config[pluggable.getProviderName()]
68
- );
69
-
70
- return config;
71
- }
72
- }
73
-
74
- /**
75
- * Get the plugin object
76
- * @param providerName - the name of the plugin
77
- */
78
- public getPluggable(providerName: string) {
79
- const pluggable = this._pluggables.find(
80
- pluggable => pluggable.getProviderName() === providerName
81
- );
82
- if (pluggable === undefined) {
83
- logger.debug('No plugin found with providerName', providerName);
84
- throw new Error('No plugin found in Geo for the provider');
85
- } else return pluggable;
86
- }
87
-
88
- /**
89
- * Remove the plugin object
90
- * @param providerName - the name of the plugin
91
- */
92
- public removePluggable(providerName: string) {
93
- this._pluggables = this._pluggables.filter(
94
- pluggable => pluggable.getProviderName() !== providerName
95
- );
96
- return;
97
- }
98
-
99
- /**
100
- * Configure Geo
101
- * @param {Object} config - Configuration object for Geo
102
- * @return {Object} - Current configuration
103
- */
104
- configure(config?) {
105
- logger.debug('configure Geo');
106
-
107
- if (!config) return this._config;
108
-
109
- const amplifyConfig = parseAWSExports(config);
110
- this._config = Object.assign({}, this._config, amplifyConfig.Geo, config);
111
-
112
- this._pluggables.forEach(pluggable => {
113
- pluggable.configure(this._config[pluggable.getProviderName()]);
114
- });
115
-
116
- if (this._pluggables.length === 0) {
117
- this.addPluggable(new AmazonLocationServiceProvider());
118
- }
119
- return this._config;
120
- }
121
-
122
- /**
123
- * Get the map resources that are currently available through the provider
124
- * @param {string} provider
125
- * @returns - Array of available map resources
126
- */
127
- public getAvailableMaps(provider = DEFAULT_PROVIDER): MapStyle[] {
128
- const prov = this.getPluggable(provider);
129
-
130
- return prov.getAvailableMaps();
131
- }
132
-
133
- /**
134
- * Get the map resource set as default in amplify config
135
- * @param {string} provider
136
- * @returns - Map resource set as the default in amplify config
137
- */
138
- public getDefaultMap(provider = DEFAULT_PROVIDER): MapStyle {
139
- const prov = this.getPluggable(provider);
140
-
141
- return prov.getDefaultMap();
142
- }
143
-
144
- /**
145
- * Search by text input with optional parameters
146
- * @param {string} text - The text string that is to be searched for
147
- * @param {SearchByTextOptions} options? - Optional parameters to the search
148
- * @param {CustomUserAgentDetails} customUserAgentDetails - Optional parameter to send user agent details
149
- * @returns {Promise<Place[]>} - Promise resolves to a list of Places that match search parameters
150
- */
151
- public async searchByText(
152
- text: string,
153
- options?: SearchByTextOptions,
154
- customUserAgentDetails?: CustomUserAgentDetails
155
- ): Promise<Place[]> {
156
- const { providerName = DEFAULT_PROVIDER } = options || {};
157
- const prov = this.getPluggable(providerName);
158
-
159
- try {
160
- return await prov.searchByText(
161
- text,
162
- options,
163
- getGeoUserAgentDetails(GeoAction.SearchByText, customUserAgentDetails)
164
- );
165
- } catch (error) {
166
- logger.debug(error);
167
- throw error;
168
- }
169
- }
170
-
171
- /**
172
- * Search for search term suggestions based on input text
173
- * @param {string} text - The text string that is to be search for
174
- * @param {SearchByTextOptions} options? - Optional parameters to the search
175
- * @param {CustomUserAgentDetails} customUserAgentDetails - Optional parameter to send user agent details
176
- * @returns {Promise<SearchForSuggestionsResults>} - Resolves to an array of search suggestion strings
177
- */
178
- public async searchForSuggestions(
179
- text: string,
180
- options?: SearchByTextOptions,
181
- customUserAgentDetails?: CustomUserAgentDetails
182
- ) {
183
- const { providerName = DEFAULT_PROVIDER } = options || {};
184
- const prov = this.getPluggable(providerName);
185
-
186
- try {
187
- return await prov.searchForSuggestions(
188
- text,
189
- options,
190
- getGeoUserAgentDetails(
191
- GeoAction.SearchForSuggestions,
192
- customUserAgentDetails
193
- )
194
- );
195
- } catch (error) {
196
- logger.debug(error);
197
- throw error;
198
- }
199
- }
200
-
201
- /**
202
- * Search for location by unique ID
203
- * @param {string} placeId - Unique ID of the location that is to be searched for
204
- * @param {searchByPlaceIdOptions} options? - Optional parameters to the search
205
- * @param {CustomUserAgentDetails} customUserAgentDetails - Optional parameter to send user agent details
206
- * @returns {Promise<Place>} - Resolves to a place with the given placeId
207
- */
208
- public async searchByPlaceId(
209
- placeId: string,
210
- options?: searchByPlaceIdOptions,
211
- customUserAgentDetails?: CustomUserAgentDetails
212
- ) {
213
- const providerName = DEFAULT_PROVIDER;
214
- const prov = this.getPluggable(providerName);
215
-
216
- try {
217
- return await prov.searchByPlaceId(
218
- placeId,
219
- options,
220
- getGeoUserAgentDetails(
221
- GeoAction.SearchByPlaceId,
222
- customUserAgentDetails
223
- )
224
- );
225
- } catch (error) {
226
- logger.debug(error);
227
- throw error;
228
- }
229
- }
230
-
231
- /**
232
- * Reverse geocoding search via a coordinate point on the map
233
- * @param coordinates - Coordinates array for the search input
234
- * @param options - Options parameters for the search
235
- * @param {CustomUserAgentDetails} customUserAgentDetails - Optional parameter to send user agent details
236
- * @returns {Promise<Place>} - Promise that resolves to a place matching search coordinates
237
- */
238
- public async searchByCoordinates(
239
- coordinates: Coordinates,
240
- options?: SearchByCoordinatesOptions,
241
- customUserAgentDetails?: CustomUserAgentDetails
242
- ): Promise<Place> {
243
- const { providerName = DEFAULT_PROVIDER } = options || {};
244
- const prov = this.getPluggable(providerName);
245
-
246
- const [lng, lat] = coordinates;
247
- try {
248
- validateCoordinates(lng, lat);
249
- return await prov.searchByCoordinates(
250
- coordinates,
251
- options,
252
- getGeoUserAgentDetails(GeoAction.SearchByCoordinates)
253
- );
254
- } catch (error) {
255
- logger.debug(error);
256
- throw error;
257
- }
258
- }
259
-
260
- /**
261
- * Create geofences
262
- * @param geofences - Single or array of geofence objects to create
263
- * @param options? - Optional parameters for creating geofences
264
- * @param {CustomUserAgentDetails} customUserAgentDetails - Optional parameter to send user agent details
265
- * @returns {Promise<SaveGeofencesResults>} - Promise that resolves to an object with:
266
- * successes: list of geofences successfully created
267
- * errors: list of geofences that failed to create
268
- */
269
- public async saveGeofences(
270
- geofences: GeofenceInput | GeofenceInput[],
271
- options?: GeofenceOptions,
272
- customUserAgentDetails?: CustomUserAgentDetails
273
- ): Promise<SaveGeofencesResults> {
274
- const { providerName = DEFAULT_PROVIDER } = options || {};
275
- const prov = this.getPluggable(providerName);
276
-
277
- // If single geofence input, make it an array for batch call
278
- let geofenceInputArray;
279
- if (!Array.isArray(geofences)) {
280
- geofenceInputArray = [geofences];
281
- } else {
282
- geofenceInputArray = geofences;
283
- }
284
-
285
- try {
286
- return await prov.saveGeofences(
287
- geofenceInputArray,
288
- options,
289
- getGeoUserAgentDetails(GeoAction.SaveGeofences, customUserAgentDetails)
290
- );
291
- } catch (error) {
292
- logger.debug(error);
293
- throw error;
294
- }
295
- }
296
-
297
- /**
298
- * Get a single geofence by geofenceId
299
- * @param geofenceId: GeofenceId - The string id of the geofence to get
300
- * @param options?: GeofenceOptions - Optional parameters for getting a geofence
301
- * @param {CustomUserAgentDetails} customUserAgentDetails - Optional parameter to send user agent details
302
- * @returns Promise<Geofence> - Promise that resolves to a geofence object
303
- */
304
- public async getGeofence(
305
- geofenceId: GeofenceId,
306
- options?: GeofenceOptions,
307
- customUserAgentDetails?: CustomUserAgentDetails
308
- ): Promise<Geofence> {
309
- const { providerName = DEFAULT_PROVIDER } = options || {};
310
- const prov = this.getPluggable(providerName);
311
-
312
- try {
313
- return await prov.getGeofence(
314
- geofenceId,
315
- options,
316
- getGeoUserAgentDetails(GeoAction.GetGeofence, customUserAgentDetails)
317
- );
318
- } catch (error) {
319
- logger.debug(error);
320
- throw error;
321
- }
322
- }
323
-
324
- /**
325
- * List geofences
326
- * @param options?: ListGeofenceOptions
327
- * @param {CustomUserAgentDetails} customUserAgentDetails - Optional parameter to send user agent details
328
- * @returns {Promise<ListGeofencesResults>} - Promise that resolves to an object with:
329
- * entries: list of geofences - 100 geofences are listed per page
330
- * nextToken: token for next page of geofences
331
- */
332
- public async listGeofences(
333
- options?: ListGeofenceOptions,
334
- customUserAgentDetails?: CustomUserAgentDetails
335
- ): Promise<ListGeofenceResults> {
336
- const { providerName = DEFAULT_PROVIDER } = options || {};
337
- const prov = this.getPluggable(providerName);
338
-
339
- try {
340
- return await prov.listGeofences(
341
- options,
342
- getGeoUserAgentDetails(GeoAction.ListGeofences, customUserAgentDetails)
343
- );
344
- } catch (error) {
345
- logger.debug(error);
346
- throw error;
347
- }
348
- }
349
-
350
- /**
351
- * Delete geofences
352
- * @param geofenceIds: string|string[]
353
- * @param options?: GeofenceOptions
354
- * @param {CustomUserAgentDetails} customUserAgentDetails - Optional parameter to send user agent details
355
- * @returns {Promise<DeleteGeofencesResults>} - Promise that resolves to an object with:
356
- * successes: list of geofences successfully deleted
357
- * errors: list of geofences that failed to delete
358
- */
359
- public async deleteGeofences(
360
- geofenceIds: string | string[],
361
- options?: GeofenceOptions,
362
- customUserAgentDetails?: CustomUserAgentDetails
363
- ): Promise<DeleteGeofencesResults> {
364
- const { providerName = DEFAULT_PROVIDER } = options || {};
365
- const prov = this.getPluggable(providerName);
366
-
367
- // If single geofence input, make it an array for batch call
368
- let geofenceIdsInputArray;
369
- if (!Array.isArray(geofenceIds)) {
370
- geofenceIdsInputArray = [geofenceIds];
371
- } else {
372
- geofenceIdsInputArray = geofenceIds;
373
- }
374
-
375
- // Delete geofences
376
- try {
377
- return await prov.deleteGeofences(
378
- geofenceIdsInputArray,
379
- options,
380
- getGeoUserAgentDetails(
381
- GeoAction.DeleteGeofences,
382
- customUserAgentDetails
383
- )
384
- );
385
- } catch (error) {
386
- logger.debug(error);
387
- throw error;
388
- }
389
- }
390
- }
391
-
392
- export const InternalGeo = new InternalGeoClass();
393
- Amplify.register(InternalGeo);
@@ -1,3 +0,0 @@
1
- // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
- // SPDX-License-Identifier: Apache-2.0
3
- export { InternalGeo } from './InternalGeo';
@@ -1,15 +0,0 @@
1
- // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
- // SPDX-License-Identifier: Apache-2.0
3
-
4
- import { Category, CustomUserAgentDetails, GeoAction } from '@aws-amplify/core';
5
-
6
- export const getGeoUserAgentDetails = (
7
- action: GeoAction,
8
- customUserAgentDetails?: CustomUserAgentDetails
9
- ): CustomUserAgentDetails => {
10
- return {
11
- category: Category.Geo,
12
- action,
13
- ...customUserAgentDetails,
14
- };
15
- };