@aws-amplify/geo 1.1.13 → 1.1.14-beta.8
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/dist/aws-amplify-geo.js +1759 -484
- package/dist/aws-amplify-geo.js.map +1 -1
- package/dist/aws-amplify-geo.min.js +6 -6
- package/dist/aws-amplify-geo.min.js.map +1 -1
- package/lib/Geo.d.ts +8 -1
- package/lib/Geo.js +32 -4
- package/lib/Geo.js.map +1 -1
- package/lib/Providers/AmazonLocationServiceProvider.d.ts +8 -1
- package/lib/Providers/AmazonLocationServiceProvider.js +72 -7
- package/lib/Providers/AmazonLocationServiceProvider.js.map +1 -1
- package/lib/types/Geo.d.ts +1 -0
- package/lib/types/Provider.d.ts +2 -1
- package/lib-esm/Geo.d.ts +8 -1
- package/lib-esm/Geo.js +32 -4
- package/lib-esm/Geo.js.map +1 -1
- package/lib-esm/Providers/AmazonLocationServiceProvider.d.ts +8 -1
- package/lib-esm/Providers/AmazonLocationServiceProvider.js +73 -8
- package/lib-esm/Providers/AmazonLocationServiceProvider.js.map +1 -1
- package/lib-esm/types/Geo.d.ts +1 -0
- package/lib-esm/types/Provider.d.ts +2 -1
- package/package.json +4 -4
- package/src/Geo.ts +22 -0
- package/src/Providers/AmazonLocationServiceProvider.ts +84 -5
- package/src/types/Geo.ts +3 -0
- package/src/types/Provider.ts +6 -0
|
@@ -18,9 +18,11 @@ import {
|
|
|
18
18
|
} from '@aws-amplify/core';
|
|
19
19
|
import {
|
|
20
20
|
Place as PlaceResult,
|
|
21
|
-
SearchPlaceIndexForTextCommandInput,
|
|
22
21
|
LocationClient,
|
|
23
22
|
SearchPlaceIndexForTextCommand,
|
|
23
|
+
SearchPlaceIndexForTextCommandInput,
|
|
24
|
+
SearchPlaceIndexForSuggestionsCommand,
|
|
25
|
+
SearchPlaceIndexForSuggestionsCommandInput,
|
|
24
26
|
SearchPlaceIndexForPositionCommand,
|
|
25
27
|
SearchPlaceIndexForPositionCommandInput,
|
|
26
28
|
} from '@aws-sdk/client-location';
|
|
@@ -33,6 +35,7 @@ import {
|
|
|
33
35
|
Place,
|
|
34
36
|
AmazonLocationServiceMapStyle,
|
|
35
37
|
Coordinates,
|
|
38
|
+
SearchForSuggestionsResults,
|
|
36
39
|
} from '../types';
|
|
37
40
|
|
|
38
41
|
const logger = new Logger('AmazonLocationServiceProvider');
|
|
@@ -188,9 +191,85 @@ export class AmazonLocationServiceProvider implements GeoProvider {
|
|
|
188
191
|
const PascalResults: PlaceResult[] = response.Results.map(
|
|
189
192
|
result => result.Place
|
|
190
193
|
);
|
|
191
|
-
const results: Place[] =
|
|
194
|
+
const results: Place[] = camelcaseKeys(PascalResults, {
|
|
192
195
|
deep: true,
|
|
193
|
-
}) as undefined
|
|
196
|
+
}) as undefined as Place[];
|
|
197
|
+
|
|
198
|
+
return results;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Search for suggestions based on the input text
|
|
203
|
+
* @param {string} text - The text string that is to be searched for
|
|
204
|
+
* @param {SearchByTextOptions} options? - Optional parameters to the search
|
|
205
|
+
* @returns {Promise<SearchForSuggestionsResults>} - Resolves to an array of search suggestion strings
|
|
206
|
+
*/
|
|
207
|
+
|
|
208
|
+
public async searchForSuggestions(
|
|
209
|
+
text: string,
|
|
210
|
+
options?: SearchByTextOptions
|
|
211
|
+
): Promise<SearchForSuggestionsResults> {
|
|
212
|
+
const credentialsOK = await this._ensureCredentials();
|
|
213
|
+
if (!credentialsOK) {
|
|
214
|
+
throw new Error('No credentials');
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
this._verifySearchIndex(options?.searchIndexName);
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Setup the searchInput
|
|
221
|
+
*/
|
|
222
|
+
const locationServiceInput: SearchPlaceIndexForSuggestionsCommandInput = {
|
|
223
|
+
Text: text,
|
|
224
|
+
IndexName: this._config.search_indices.default,
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Map search options to Amazon Location Service input object
|
|
229
|
+
*/
|
|
230
|
+
if (options) {
|
|
231
|
+
locationServiceInput.FilterCountries = options.countries;
|
|
232
|
+
locationServiceInput.MaxResults = options.maxResults;
|
|
233
|
+
|
|
234
|
+
if (options.searchIndexName) {
|
|
235
|
+
locationServiceInput.IndexName = options.searchIndexName;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
if (options['biasPosition'] && options['searchAreaConstraints']) {
|
|
239
|
+
throw new Error(
|
|
240
|
+
'BiasPosition and SearchAreaConstraints are mutually exclusive, please remove one or the other from the options object'
|
|
241
|
+
);
|
|
242
|
+
}
|
|
243
|
+
if (options['biasPosition']) {
|
|
244
|
+
locationServiceInput.BiasPosition = options['biasPosition'];
|
|
245
|
+
}
|
|
246
|
+
if (options['searchAreaConstraints']) {
|
|
247
|
+
locationServiceInput.FilterBBox = options['searchAreaConstraints'];
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
const client = new LocationClient({
|
|
252
|
+
credentials: this._config.credentials,
|
|
253
|
+
region: this._config.region,
|
|
254
|
+
customUserAgent: getAmplifyUserAgent(),
|
|
255
|
+
});
|
|
256
|
+
const command = new SearchPlaceIndexForSuggestionsCommand(
|
|
257
|
+
locationServiceInput
|
|
258
|
+
);
|
|
259
|
+
|
|
260
|
+
let response;
|
|
261
|
+
try {
|
|
262
|
+
response = await client.send(command);
|
|
263
|
+
} catch (error) {
|
|
264
|
+
logger.debug(error);
|
|
265
|
+
throw error;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* The response from Amazon Location Service is a "Results" array of objects with a single `Text` item.
|
|
270
|
+
* Here we want to flatten that to an array of just the strings from those `Text` items.
|
|
271
|
+
*/
|
|
272
|
+
const results = response.Results.map(result => result.Text);
|
|
194
273
|
|
|
195
274
|
return results;
|
|
196
275
|
}
|
|
@@ -247,9 +326,9 @@ export class AmazonLocationServiceProvider implements GeoProvider {
|
|
|
247
326
|
* Here we want to flatten that to an array of results and change them to camelCase
|
|
248
327
|
*/
|
|
249
328
|
const PascalResults = response.Results.map(result => result.Place);
|
|
250
|
-
const results: Place =
|
|
329
|
+
const results: Place = camelcaseKeys(PascalResults[0], {
|
|
251
330
|
deep: true,
|
|
252
|
-
}) as any
|
|
331
|
+
}) as any as Place;
|
|
253
332
|
|
|
254
333
|
return results;
|
|
255
334
|
}
|
package/src/types/Geo.ts
CHANGED
package/src/types/Provider.ts
CHANGED
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
import {
|
|
15
15
|
SearchByTextOptions,
|
|
16
16
|
SearchByCoordinatesOptions,
|
|
17
|
+
SearchForSuggestionsResults,
|
|
17
18
|
Coordinates,
|
|
18
19
|
Place,
|
|
19
20
|
MapStyle,
|
|
@@ -41,4 +42,9 @@ export interface GeoProvider {
|
|
|
41
42
|
coordinates: Coordinates,
|
|
42
43
|
options?: SearchByCoordinatesOptions
|
|
43
44
|
): Promise<Place>;
|
|
45
|
+
|
|
46
|
+
searchForSuggestions(
|
|
47
|
+
text: string,
|
|
48
|
+
options?: SearchByTextOptions
|
|
49
|
+
): Promise<SearchForSuggestionsResults>;
|
|
44
50
|
}
|