@aws-amplify/geo 2.3.6-api-v6-models.b3abc9b.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/Geo.d.ts +3 -9
- package/lib/Geo.js +137 -243
- package/lib/index.js +4 -2
- package/{lib-esm/Providers → lib/providers/location-service}/AmazonLocationServiceProvider.d.ts +3 -7
- package/lib/providers/location-service/AmazonLocationServiceProvider.js +618 -0
- package/lib/tsconfig.tsbuildinfo +1 -0
- package/lib/types/AmazonLocationServiceProvider.d.ts +7 -7
- package/lib/types/AmazonLocationServiceProvider.js +0 -1
- package/lib/types/Geo.d.ts +28 -45
- package/lib/types/Geo.js +0 -1
- package/lib/types/Provider.d.ts +0 -1
- package/lib/types/Provider.js +0 -1
- package/lib/types/index.js +6 -1
- package/lib/util.d.ts +4 -0
- package/lib/util.js +51 -36
- package/lib-esm/Geo.d.ts +3 -9
- package/lib-esm/Geo.js +136 -243
- package/lib-esm/index.js +1 -1
- package/{lib/Providers → lib-esm/providers/location-service}/AmazonLocationServiceProvider.d.ts +3 -7
- package/lib-esm/providers/location-service/AmazonLocationServiceProvider.js +614 -0
- package/lib-esm/tsconfig.tsbuildinfo +1 -0
- package/lib-esm/types/AmazonLocationServiceProvider.d.ts +7 -7
- package/lib-esm/types/AmazonLocationServiceProvider.js +1 -1
- package/lib-esm/types/Geo.d.ts +28 -45
- package/lib-esm/types/Geo.js +1 -1
- package/lib-esm/types/Provider.d.ts +0 -1
- package/lib-esm/types/Provider.js +1 -1
- package/lib-esm/types/index.js +5 -1
- package/lib-esm/util.d.ts +4 -0
- package/lib-esm/util.js +45 -34
- package/package.json +26 -12
- package/src/Geo.ts +12 -36
- package/src/{Providers → providers/location-service}/AmazonLocationServiceProvider.ts +65 -68
- package/src/types/Geo.ts +1 -17
- package/src/types/Provider.ts +0 -3
- package/src/util.ts +24 -3
- package/lib/.tsbuildinfo +0 -3
- package/lib/Geo.js.map +0 -1
- package/lib/Providers/AmazonLocationServiceProvider.js +0 -737
- package/lib/Providers/AmazonLocationServiceProvider.js.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/types/AmazonLocationServiceProvider.js.map +0 -1
- package/lib/types/Geo.js.map +0 -1
- package/lib/types/Provider.js.map +0 -1
- package/lib/types/index.js.map +0 -1
- package/lib/util.js.map +0 -1
- package/lib-esm/.tsbuildinfo +0 -3
- package/lib-esm/Geo.js.map +0 -1
- package/lib-esm/Providers/AmazonLocationServiceProvider.js +0 -735
- package/lib-esm/Providers/AmazonLocationServiceProvider.js.map +0 -1
- package/lib-esm/index.js.map +0 -1
- package/lib-esm/types/AmazonLocationServiceProvider.js.map +0 -1
- package/lib-esm/types/Geo.js.map +0 -1
- package/lib-esm/types/Provider.js.map +0 -1
- package/lib-esm/types/index.js.map +0 -1
- package/lib-esm/util.js.map +0 -1
package/lib/util.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
3
|
+
exports.getGeoUserAgentString = exports.getGeoUserAgent = exports.mapSearchOptions = exports.validateGeofencesInput = exports.validatePolygon = exports.validateLinearRing = exports.validateGeofenceId = exports.validateCoordinates = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
4
5
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
5
6
|
// SPDX-License-Identifier: Apache-2.0
|
|
6
|
-
|
|
7
|
+
const boolean_clockwise_1 = tslib_1.__importDefault(require("@turf/boolean-clockwise"));
|
|
8
|
+
const utils_1 = require("@aws-amplify/core/internals/utils");
|
|
7
9
|
function validateCoordinates(lng, lat) {
|
|
8
10
|
if (!Number.isFinite(lng) || !Number.isFinite(lat)) {
|
|
9
|
-
throw new Error(
|
|
11
|
+
throw new Error(`Invalid coordinates: [${lng},${lat}]`);
|
|
10
12
|
}
|
|
11
13
|
if (lat < -90 || 90 < lat) {
|
|
12
14
|
throw new Error('Latitude must be between -90 and 90 degrees inclusive.');
|
|
@@ -17,107 +19,107 @@ function validateCoordinates(lng, lat) {
|
|
|
17
19
|
}
|
|
18
20
|
exports.validateCoordinates = validateCoordinates;
|
|
19
21
|
function validateGeofenceId(geofenceId) {
|
|
20
|
-
|
|
22
|
+
const geofenceIdRegex = /^[-._\p{L}\p{N}]+$/iu;
|
|
21
23
|
// Check if geofenceId is valid
|
|
22
24
|
if (!geofenceIdRegex.test(geofenceId)) {
|
|
23
|
-
throw new Error(
|
|
25
|
+
throw new Error(`Invalid geofenceId: '${geofenceId}' - IDs can only contain alphanumeric characters, hyphens, underscores and periods.`);
|
|
24
26
|
}
|
|
25
27
|
}
|
|
26
28
|
exports.validateGeofenceId = validateGeofenceId;
|
|
27
29
|
function validateLinearRing(linearRing, geofenceId) {
|
|
28
|
-
|
|
30
|
+
const errorPrefix = geofenceId ? `${geofenceId}: ` : '';
|
|
29
31
|
// Validate LinearRing size, must be at least 4 points
|
|
30
32
|
if (linearRing.length < 4) {
|
|
31
|
-
throw new Error(errorPrefix
|
|
33
|
+
throw new Error(`${errorPrefix}LinearRing must contain 4 or more coordinates.`);
|
|
32
34
|
}
|
|
33
35
|
// Validate all coordinates are valid, error with which ones are bad
|
|
34
|
-
|
|
35
|
-
linearRing.forEach(
|
|
36
|
+
const badCoordinates = [];
|
|
37
|
+
linearRing.forEach(coordinates => {
|
|
36
38
|
try {
|
|
37
39
|
validateCoordinates(coordinates[0], coordinates[1]);
|
|
38
40
|
}
|
|
39
41
|
catch (error) {
|
|
40
|
-
badCoordinates.push({ coordinates
|
|
42
|
+
badCoordinates.push({ coordinates, error: error.message });
|
|
41
43
|
}
|
|
42
44
|
});
|
|
43
45
|
if (badCoordinates.length > 0) {
|
|
44
|
-
throw new Error(errorPrefix
|
|
46
|
+
throw new Error(`${errorPrefix}One or more of the coordinates in the Polygon LinearRing are not valid: ${JSON.stringify(badCoordinates)}`);
|
|
45
47
|
}
|
|
46
48
|
// Validate first and last coordinates are the same
|
|
47
|
-
|
|
48
|
-
|
|
49
|
+
const [lngA, latA] = linearRing[0];
|
|
50
|
+
const [lngB, latB] = linearRing[linearRing.length - 1];
|
|
49
51
|
if (lngA !== lngB || latA !== latB) {
|
|
50
|
-
throw new Error(errorPrefix
|
|
52
|
+
throw new Error(`${errorPrefix}LinearRing's first and last coordinates are not the same`);
|
|
51
53
|
}
|
|
52
|
-
if (boolean_clockwise_1.default(linearRing)) {
|
|
53
|
-
throw new Error(errorPrefix
|
|
54
|
+
if ((0, boolean_clockwise_1.default)(linearRing)) {
|
|
55
|
+
throw new Error(`${errorPrefix}LinearRing coordinates must be wound counterclockwise`);
|
|
54
56
|
}
|
|
55
57
|
}
|
|
56
58
|
exports.validateLinearRing = validateLinearRing;
|
|
57
59
|
function validatePolygon(polygon, geofenceId) {
|
|
58
|
-
|
|
60
|
+
const errorPrefix = geofenceId ? `${geofenceId}: ` : '';
|
|
59
61
|
if (!Array.isArray(polygon)) {
|
|
60
|
-
throw new Error(errorPrefix
|
|
62
|
+
throw new Error(`${errorPrefix}Polygon is of incorrect structure. It should be an array of LinearRings`);
|
|
61
63
|
}
|
|
62
64
|
if (polygon.length < 1) {
|
|
63
|
-
throw new Error(errorPrefix
|
|
65
|
+
throw new Error(`${errorPrefix}Polygon must have a single LinearRing array.`);
|
|
64
66
|
}
|
|
65
67
|
if (polygon.length > 1) {
|
|
66
|
-
throw new Error(errorPrefix
|
|
68
|
+
throw new Error(`${errorPrefix}Polygon must have a single LinearRing array. Note: We do not currently support polygons with holes, multipolygons, polygons that are wound clockwise, or that cross the antimeridian.`);
|
|
67
69
|
}
|
|
68
|
-
|
|
70
|
+
const verticesCount = polygon.reduce((prev, linearRing) => prev + linearRing.length, 0);
|
|
69
71
|
if (verticesCount > 1000) {
|
|
70
|
-
throw new Error(errorPrefix
|
|
72
|
+
throw new Error(`${errorPrefix}Polygon has more than the maximum 1000 vertices.`);
|
|
71
73
|
}
|
|
72
|
-
polygon.forEach(
|
|
74
|
+
polygon.forEach(linearRing => {
|
|
73
75
|
validateLinearRing(linearRing, geofenceId);
|
|
74
76
|
});
|
|
75
77
|
}
|
|
76
78
|
exports.validatePolygon = validatePolygon;
|
|
77
79
|
function validateGeofencesInput(geofences) {
|
|
78
|
-
|
|
79
|
-
geofences.forEach(
|
|
80
|
+
const geofenceIds = {};
|
|
81
|
+
geofences.forEach((geofence) => {
|
|
80
82
|
// verify all required properties are present
|
|
81
83
|
// Validate geofenceId exists
|
|
82
84
|
if (!geofence.geofenceId) {
|
|
83
|
-
throw new Error(
|
|
85
|
+
throw new Error(`Geofence '${geofence}' is missing geofenceId`);
|
|
84
86
|
}
|
|
85
|
-
|
|
87
|
+
const { geofenceId } = geofence;
|
|
86
88
|
validateGeofenceId(geofenceId);
|
|
87
89
|
// Validate geofenceId is unique
|
|
88
90
|
if (geofenceIds[geofenceId]) {
|
|
89
|
-
throw new Error(
|
|
91
|
+
throw new Error(`Duplicate geofenceId: ${geofenceId}`);
|
|
90
92
|
}
|
|
91
93
|
else {
|
|
92
94
|
geofenceIds[geofenceId] = true;
|
|
93
95
|
}
|
|
94
96
|
// Validate geometry exists
|
|
95
97
|
if (!geofence.geometry) {
|
|
96
|
-
throw new Error(
|
|
98
|
+
throw new Error(`Geofence '${geofenceId}' is missing geometry`);
|
|
97
99
|
}
|
|
98
|
-
|
|
100
|
+
const { geometry } = geofence;
|
|
99
101
|
// Validate polygon exists
|
|
100
102
|
if (!geometry.polygon) {
|
|
101
|
-
throw new Error(
|
|
103
|
+
throw new Error(`Geofence '${geofenceId}' is missing geometry.polygon`);
|
|
102
104
|
}
|
|
103
|
-
|
|
105
|
+
const { polygon } = geometry;
|
|
104
106
|
// Validate polygon length and structure
|
|
105
107
|
try {
|
|
106
108
|
validatePolygon(polygon, geofenceId);
|
|
107
109
|
}
|
|
108
110
|
catch (error) {
|
|
109
111
|
if (error.message.includes('Polygon has more than the maximum 1000 vertices.')) {
|
|
110
|
-
throw new Error(
|
|
112
|
+
throw new Error(`Geofence '${geofenceId}' has more than the maximum of 1000 vertices`);
|
|
111
113
|
}
|
|
112
114
|
}
|
|
113
115
|
// Validate LinearRing length, structure, and coordinates
|
|
114
|
-
|
|
116
|
+
const [linearRing] = polygon;
|
|
115
117
|
validateLinearRing(linearRing, geofenceId);
|
|
116
118
|
});
|
|
117
119
|
}
|
|
118
120
|
exports.validateGeofencesInput = validateGeofencesInput;
|
|
119
121
|
function mapSearchOptions(options, locationServiceInput) {
|
|
120
|
-
|
|
122
|
+
const locationServiceModifiedInput = { ...locationServiceInput };
|
|
121
123
|
locationServiceModifiedInput.FilterCountries = options.countries;
|
|
122
124
|
locationServiceModifiedInput.MaxResults = options.maxResults;
|
|
123
125
|
if (options.searchIndexName) {
|
|
@@ -135,4 +137,17 @@ function mapSearchOptions(options, locationServiceInput) {
|
|
|
135
137
|
return locationServiceModifiedInput;
|
|
136
138
|
}
|
|
137
139
|
exports.mapSearchOptions = mapSearchOptions;
|
|
138
|
-
|
|
140
|
+
function getGeoUserAgent(action) {
|
|
141
|
+
return (0, utils_1.getAmplifyUserAgentObject)({
|
|
142
|
+
category: utils_1.Category.Geo,
|
|
143
|
+
action,
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
exports.getGeoUserAgent = getGeoUserAgent;
|
|
147
|
+
function getGeoUserAgentString(action) {
|
|
148
|
+
return (0, utils_1.getAmplifyUserAgent)({
|
|
149
|
+
category: utils_1.Category.Geo,
|
|
150
|
+
action,
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
exports.getGeoUserAgentString = getGeoUserAgentString;
|
package/lib-esm/Geo.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Place,
|
|
1
|
+
import { Place, Coordinates, SearchByTextOptions, SearchByCoordinatesOptions, GeoProvider, MapStyle, GeofenceId, GeofenceInput, GeofenceOptions, SaveGeofencesResults, Geofence, ListGeofenceOptions, ListGeofenceResults, DeleteGeofencesResults, searchByPlaceIdOptions } from './types';
|
|
2
2
|
export declare class GeoClass {
|
|
3
3
|
static MODULE: string;
|
|
4
4
|
/**
|
|
@@ -16,7 +16,7 @@ export declare class GeoClass {
|
|
|
16
16
|
* add plugin into Geo category
|
|
17
17
|
* @param {Object} pluggable - an instance of the plugin
|
|
18
18
|
*/
|
|
19
|
-
addPluggable(pluggable: GeoProvider):
|
|
19
|
+
addPluggable(pluggable: GeoProvider): void;
|
|
20
20
|
/**
|
|
21
21
|
* Get the plugin object
|
|
22
22
|
* @param providerName - the name of the plugin
|
|
@@ -27,12 +27,6 @@ export declare class GeoClass {
|
|
|
27
27
|
* @param providerName - the name of the plugin
|
|
28
28
|
*/
|
|
29
29
|
removePluggable(providerName: string): void;
|
|
30
|
-
/**
|
|
31
|
-
* Configure Geo
|
|
32
|
-
* @param {Object} config - Configuration object for Geo
|
|
33
|
-
* @return {Object} - Current configuration
|
|
34
|
-
*/
|
|
35
|
-
configure(config?: any): GeoConfig;
|
|
36
30
|
/**
|
|
37
31
|
* Get the map resources that are currently available through the provider
|
|
38
32
|
* @param {string} provider
|
|
@@ -65,7 +59,7 @@ export declare class GeoClass {
|
|
|
65
59
|
* @param {searchByPlaceIdOptions} options? - Optional parameters to the search
|
|
66
60
|
* @returns {Promise<Place>} - Resolves to a place with the given placeId
|
|
67
61
|
*/
|
|
68
|
-
searchByPlaceId(placeId: string, options?: searchByPlaceIdOptions): Promise<Place>;
|
|
62
|
+
searchByPlaceId(placeId: string, options?: searchByPlaceIdOptions): Promise<Place | undefined>;
|
|
69
63
|
/**
|
|
70
64
|
* Reverse geocoding search via a coordinate point on the map
|
|
71
65
|
* @param coordinates - Coordinates array for the search input
|