@aws-amplify/geo 1.2.4 → 1.2.5-geo.7
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 +2145 -136
- 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 +37 -4
- package/lib/Geo.js +153 -5
- package/lib/Geo.js.map +1 -1
- package/lib/Providers/AmazonLocationServiceProvider.d.ts +37 -1
- package/lib/Providers/AmazonLocationServiceProvider.js +417 -8
- package/lib/Providers/AmazonLocationServiceProvider.js.map +1 -1
- package/lib/types/AmazonLocationServiceProvider.d.ts +21 -1
- package/lib/types/Geo.d.ts +48 -1
- package/lib/types/Provider.d.ts +5 -1
- package/lib/types/Provider.js +0 -12
- package/lib/types/Provider.js.map +1 -1
- package/lib/util.d.ts +6 -0
- package/lib/util.js +142 -0
- package/lib/util.js.map +1 -0
- package/lib-esm/Geo.d.ts +37 -4
- package/lib-esm/Geo.js +153 -5
- package/lib-esm/Geo.js.map +1 -1
- package/lib-esm/Providers/AmazonLocationServiceProvider.d.ts +37 -1
- package/lib-esm/Providers/AmazonLocationServiceProvider.js +418 -9
- package/lib-esm/Providers/AmazonLocationServiceProvider.js.map +1 -1
- package/lib-esm/types/AmazonLocationServiceProvider.d.ts +21 -1
- package/lib-esm/types/Geo.d.ts +48 -1
- package/lib-esm/types/Provider.d.ts +5 -1
- package/lib-esm/types/Provider.js +0 -12
- package/lib-esm/types/Provider.js.map +1 -1
- package/lib-esm/util.d.ts +6 -0
- package/lib-esm/util.js +132 -0
- package/lib-esm/util.js.map +1 -0
- package/package.json +6 -4
- package/src/Geo.ts +122 -3
- package/src/Providers/AmazonLocationServiceProvider.ts +423 -6
- package/src/types/AmazonLocationServiceProvider.ts +56 -1
- package/src/types/Geo.ts +72 -2
- package/src/types/Provider.ts +31 -1
- package/src/util.ts +171 -0
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Longitude, Latitude, GeofenceInput, GeofencePolygon, LinearRing } from './types';
|
|
2
|
+
export declare function validateCoordinates(lng: Longitude, lat: Latitude): void;
|
|
3
|
+
export declare function validateGeofenceId(geofenceId: string): void;
|
|
4
|
+
export declare function validateLinearRing(linearRing: LinearRing, geofenceId?: string): void;
|
|
5
|
+
export declare function validatePolygon(polygon: GeofencePolygon, geofenceId?: string): void;
|
|
6
|
+
export declare function validateGeofencesInput(geofences: GeofenceInput[]): void;
|
package/lib-esm/util.js
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
2
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
3
|
+
if (!m) return o;
|
|
4
|
+
var i = m.call(o), r, ar = [], e;
|
|
5
|
+
try {
|
|
6
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
7
|
+
}
|
|
8
|
+
catch (error) { e = { error: error }; }
|
|
9
|
+
finally {
|
|
10
|
+
try {
|
|
11
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
12
|
+
}
|
|
13
|
+
finally { if (e) throw e.error; }
|
|
14
|
+
}
|
|
15
|
+
return ar;
|
|
16
|
+
};
|
|
17
|
+
/*
|
|
18
|
+
* Copyright 2017-2021 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
19
|
+
*
|
|
20
|
+
* Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
|
|
21
|
+
* the License. A copy of the License is located at
|
|
22
|
+
*
|
|
23
|
+
* http://aws.amazon.com/apache2.0/
|
|
24
|
+
*
|
|
25
|
+
* or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
|
26
|
+
* CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
|
|
27
|
+
* and limitations under the License.
|
|
28
|
+
*/
|
|
29
|
+
import booleanClockwise from '@turf/boolean-clockwise';
|
|
30
|
+
export function validateCoordinates(lng, lat) {
|
|
31
|
+
if (!Number.isFinite(lng) || !Number.isFinite(lat)) {
|
|
32
|
+
throw new Error("Invalid coordinates: [" + lng + "," + lat + "]");
|
|
33
|
+
}
|
|
34
|
+
if (lat < -90 || lat > 90) {
|
|
35
|
+
throw new Error('Latitude must be between -90 and 90 degrees inclusive.');
|
|
36
|
+
}
|
|
37
|
+
else if (lng < -180 || lng > 180) {
|
|
38
|
+
throw new Error('Longitude must be between -180 and 180 degrees inclusive.');
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
export function validateGeofenceId(geofenceId) {
|
|
42
|
+
var geofenceIdRegex = /^[-._\p{L}\p{N}]+$/iu;
|
|
43
|
+
// Check if geofenceId is valid
|
|
44
|
+
if (!geofenceIdRegex.test(geofenceId)) {
|
|
45
|
+
throw new Error("Invalid geofenceId: '" + geofenceId + "' - IDs can only contain alphanumeric characters, hyphens, underscores and periods.");
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
export function validateLinearRing(linearRing, geofenceId) {
|
|
49
|
+
// Validate LinearRing size, must be at least 4 points
|
|
50
|
+
if (linearRing.length < 4) {
|
|
51
|
+
throw new Error(geofenceId + ": LinearRing must contain 4 or more coordinates.");
|
|
52
|
+
}
|
|
53
|
+
// Validate all coordinates are valid, error with which ones are bad
|
|
54
|
+
var badCoordinates = [];
|
|
55
|
+
linearRing.forEach(function (coordinates) {
|
|
56
|
+
try {
|
|
57
|
+
validateCoordinates(coordinates[0], coordinates[1]);
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
badCoordinates.push({ coordinates: coordinates, error: error.message });
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
if (badCoordinates.length > 0) {
|
|
64
|
+
throw new Error(geofenceId + ": One or more of the coordinates in the Polygon LinearRing are not valid: " + JSON.stringify(badCoordinates));
|
|
65
|
+
}
|
|
66
|
+
// Validate first and last coordinates are the same
|
|
67
|
+
var _a = __read(linearRing[0], 2), lngA = _a[0], latA = _a[1];
|
|
68
|
+
var _b = __read(linearRing[linearRing.length - 1], 2), lngB = _b[0], latB = _b[1];
|
|
69
|
+
if (lngA !== lngB || latA !== latB) {
|
|
70
|
+
throw new Error(geofenceId + ": LinearRing's first and last coordinates are not the same");
|
|
71
|
+
}
|
|
72
|
+
if (booleanClockwise(linearRing)) {
|
|
73
|
+
throw new Error(geofenceId + ": LinearRing coordinates must be wound counterclockwise");
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
export function validatePolygon(polygon, geofenceId) {
|
|
77
|
+
if (!Array.isArray(polygon)) {
|
|
78
|
+
throw new Error(geofenceId + ": Polygon is of incorrect structure. It should be an array of LinearRings");
|
|
79
|
+
}
|
|
80
|
+
if (polygon.length < 1) {
|
|
81
|
+
throw new Error(geofenceId + ": Polygon must have a single LinearRing array.");
|
|
82
|
+
}
|
|
83
|
+
if (polygon.length > 1) {
|
|
84
|
+
throw new Error(geofenceId + ": 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.");
|
|
85
|
+
}
|
|
86
|
+
var verticesCount = polygon.reduce(function (prev, linearRing) { return prev + linearRing.length; }, 0);
|
|
87
|
+
if (verticesCount > 1000) {
|
|
88
|
+
throw new Error(geofenceId + ": Polygon has more than the maximum 1000 vertices.");
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
export function validateGeofencesInput(geofences) {
|
|
92
|
+
var geofenceIds = {};
|
|
93
|
+
geofences.forEach(function (geofence) {
|
|
94
|
+
// verify all required properties are present
|
|
95
|
+
// Validate geofenceId exists
|
|
96
|
+
if (!geofence.geofenceId) {
|
|
97
|
+
throw new Error("Geofence '" + geofence + "' is missing geofenceId");
|
|
98
|
+
}
|
|
99
|
+
var geofenceId = geofence.geofenceId;
|
|
100
|
+
validateGeofenceId(geofenceId);
|
|
101
|
+
// Validate geofenceId is unique
|
|
102
|
+
if (geofenceIds[geofenceId]) {
|
|
103
|
+
throw new Error("Duplicate geofenceId: " + geofenceId);
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
geofenceIds[geofenceId] = true;
|
|
107
|
+
}
|
|
108
|
+
// Validate geometry exists
|
|
109
|
+
if (!geofence.geometry) {
|
|
110
|
+
throw new Error("Geofence '" + geofenceId + "' is missing geometry");
|
|
111
|
+
}
|
|
112
|
+
var geometry = geofence.geometry;
|
|
113
|
+
// Validate polygon exists
|
|
114
|
+
if (!geometry.polygon) {
|
|
115
|
+
throw new Error("Geofence '" + geofenceId + "' is missing geometry.polygon");
|
|
116
|
+
}
|
|
117
|
+
var polygon = geometry.polygon;
|
|
118
|
+
// Validate polygon length and structure
|
|
119
|
+
try {
|
|
120
|
+
validatePolygon(polygon, geofenceId);
|
|
121
|
+
}
|
|
122
|
+
catch (error) {
|
|
123
|
+
if (error.message === "Polygon has more than the maximum 1000 vertices.") {
|
|
124
|
+
throw new Error("Geofence '" + geofenceId + "' has more than the maximum of 1000 vertices");
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
// Validate LinearRing length, structure, and coordinates
|
|
128
|
+
var _a = __read(polygon, 1), linearRing = _a[0];
|
|
129
|
+
validateLinearRing(linearRing, geofenceId);
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
//# sourceMappingURL=util.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"util.js","sourceRoot":"","sources":["../src/util.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;GAWG;AACH,OAAO,gBAAgB,MAAM,yBAAyB,CAAC;AAUvD,MAAM,UAAU,mBAAmB,CAAC,GAAc,EAAE,GAAa;IAChE,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;QACnD,MAAM,IAAI,KAAK,CAAC,2BAAyB,GAAG,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E;QACO,IAAA,gCAAU,CAAc;QAChC,kBAAkB,CAAC,UAAU,CAAC,CAAC;QAE/B,gCAAgC;QAChC,IAAI,WAAW,CAAC,UAAU,CAAC,EAAE;YAC5B,MAAM,IAAI,KAAK,CAAC,2BAAyB,UAAY,CAAC,CAAC;SACvD;aAAM;YACN,WAAW,CAAC,UAAU,CAAC,GAAG,IAAI,CAAC;SAC/B;QAED,2BAA2B;QAC3B,IAAI,CAAC,QAAQ,CAAC,QAAQ,EAAE;YACvB,MAAM,IAAI,KAAK,CAAC,eAAa,UAAU,0BAAuB,CAAC,CAAC;SAChE;QACO,IAAA,4BAAQ,CAAc;QAE9B,0BAA0B;QAC1B,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE;YACtB,MAAM,IAAI,KAAK,CAAC,eAAa,UAAU,kCAA+B,CAAC,CAAC;SACxE;QACO,IAAA,0BAAO,CAAc;QAE7B,wCAAwC;QACxC,IAAI;YACH,eAAe,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;SACrC;QAAC,OAAO,KAAK,EAAE;YACf,IACC,KAAK,CAAC,OAAO,KAAK,kDAAkD,EACnE;gBACD,MAAM,IAAI,KAAK,CACd,eAAa,UAAU,iDAA8C,CACrE,CAAC;aACF;SACD;QAED,yDAAyD;QACnD,IAAA,uBAAsB,EAArB,kBAAqB,CAAC;QAC7B,kBAAkB,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;IAC5C,CAAC,CAAC,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aws-amplify/geo",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.5-geo.7+94f320b8c",
|
|
4
4
|
"description": "Geo category for aws-amplify",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"module": "./lib-esm/index.js",
|
|
@@ -41,8 +41,9 @@
|
|
|
41
41
|
},
|
|
42
42
|
"homepage": "https://aws-amplify.github.io/",
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@aws-amplify/core": "4.5.
|
|
44
|
+
"@aws-amplify/core": "4.5.1-geo.7+94f320b8c",
|
|
45
45
|
"@aws-sdk/client-location": "3.48.0",
|
|
46
|
+
"@turf/boolean-clockwise": "6.5.0",
|
|
46
47
|
"camelcase-keys": "6.2.2"
|
|
47
48
|
},
|
|
48
49
|
"jest": {
|
|
@@ -71,7 +72,8 @@
|
|
|
71
72
|
"__tests__/model.ts",
|
|
72
73
|
"__tests__/schema.ts",
|
|
73
74
|
"__tests__/helpers.ts",
|
|
74
|
-
"__tests__/
|
|
75
|
+
"__tests__/testData.ts",
|
|
76
|
+
"__tests__/testUtils.ts"
|
|
75
77
|
],
|
|
76
78
|
"moduleFileExtensions": [
|
|
77
79
|
"ts",
|
|
@@ -97,5 +99,5 @@
|
|
|
97
99
|
"lib-esm"
|
|
98
100
|
]
|
|
99
101
|
},
|
|
100
|
-
"gitHead": "
|
|
102
|
+
"gitHead": "94f320b8ca8ca2261c12166569ef0555b6dc35c7"
|
|
101
103
|
}
|
package/src/Geo.ts
CHANGED
|
@@ -17,14 +17,23 @@ import {
|
|
|
17
17
|
} from '@aws-amplify/core';
|
|
18
18
|
import { AmazonLocationServiceProvider } from './Providers/AmazonLocationServiceProvider';
|
|
19
19
|
|
|
20
|
+
import { validateCoordinates } from './util';
|
|
21
|
+
|
|
20
22
|
import {
|
|
23
|
+
Place,
|
|
21
24
|
GeoConfig,
|
|
22
25
|
Coordinates,
|
|
23
26
|
SearchByTextOptions,
|
|
24
|
-
SearchForSuggestionsResults,
|
|
25
27
|
SearchByCoordinatesOptions,
|
|
26
28
|
GeoProvider,
|
|
27
29
|
MapStyle,
|
|
30
|
+
GeofenceInput,
|
|
31
|
+
GeofenceOptions,
|
|
32
|
+
SaveGeofencesResults,
|
|
33
|
+
Geofence,
|
|
34
|
+
ListGeofenceOptions,
|
|
35
|
+
ListGeofenceResults,
|
|
36
|
+
DeleteGeofencesResults,
|
|
28
37
|
} from './types';
|
|
29
38
|
|
|
30
39
|
const logger = new Logger('Geo');
|
|
@@ -143,7 +152,10 @@ export class GeoClass {
|
|
|
143
152
|
* @param {SearchByTextOptions} options? - Optional parameters to the search
|
|
144
153
|
* @returns {Promise<Place[]>} - Promise resolves to a list of Places that match search parameters
|
|
145
154
|
*/
|
|
146
|
-
public async searchByText(
|
|
155
|
+
public async searchByText(
|
|
156
|
+
text: string,
|
|
157
|
+
options?: SearchByTextOptions
|
|
158
|
+
): Promise<Place[]> {
|
|
147
159
|
const { providerName = DEFAULT_PROVIDER } = options || {};
|
|
148
160
|
const prov = this.getPluggable(providerName);
|
|
149
161
|
|
|
@@ -185,17 +197,124 @@ export class GeoClass {
|
|
|
185
197
|
public async searchByCoordinates(
|
|
186
198
|
coordinates: Coordinates,
|
|
187
199
|
options?: SearchByCoordinatesOptions
|
|
188
|
-
) {
|
|
200
|
+
): Promise<Place> {
|
|
189
201
|
const { providerName = DEFAULT_PROVIDER } = options || {};
|
|
190
202
|
const prov = this.getPluggable(providerName);
|
|
191
203
|
|
|
204
|
+
const [lng, lat] = coordinates;
|
|
192
205
|
try {
|
|
206
|
+
validateCoordinates(lng, lat);
|
|
193
207
|
return await prov.searchByCoordinates(coordinates, options);
|
|
194
208
|
} catch (error) {
|
|
195
209
|
logger.debug(error);
|
|
196
210
|
throw error;
|
|
197
211
|
}
|
|
198
212
|
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Create geofences
|
|
216
|
+
* @param geofences - Single or array of geofence objects to create
|
|
217
|
+
* @param options? - Optional parameters for creating geofences
|
|
218
|
+
* @returns {Promise<SaveGeofencesResults>} - Promise that resolves to an object with:
|
|
219
|
+
* successes: list of geofences successfully created
|
|
220
|
+
* errors: list of geofences that failed to create
|
|
221
|
+
*/
|
|
222
|
+
public async saveGeofences(
|
|
223
|
+
geofences: GeofenceInput | GeofenceInput[],
|
|
224
|
+
options?: GeofenceOptions
|
|
225
|
+
): Promise<SaveGeofencesResults> {
|
|
226
|
+
const { providerName = DEFAULT_PROVIDER } = options || {};
|
|
227
|
+
const prov = this.getPluggable(providerName);
|
|
228
|
+
|
|
229
|
+
// If single geofence input, make it an array for batch call
|
|
230
|
+
let geofenceInputArray;
|
|
231
|
+
if (!Array.isArray(geofences)) {
|
|
232
|
+
geofenceInputArray = [geofences];
|
|
233
|
+
} else {
|
|
234
|
+
geofenceInputArray = geofences;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
try {
|
|
238
|
+
return await prov.saveGeofences(geofenceInputArray, options);
|
|
239
|
+
} catch (error) {
|
|
240
|
+
logger.debug(error);
|
|
241
|
+
throw error;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* Get a single geofence by geofenceId
|
|
247
|
+
* @param geofenceId: string
|
|
248
|
+
* @param options?: GeofenceOptions
|
|
249
|
+
* @returns Promise<Geofence> - Promise that resolves to a geofence object
|
|
250
|
+
*/
|
|
251
|
+
public async getGeofence(
|
|
252
|
+
geofenceId: string,
|
|
253
|
+
options?: GeofenceOptions
|
|
254
|
+
): Promise<Geofence> {
|
|
255
|
+
const { providerName = DEFAULT_PROVIDER } = options || {};
|
|
256
|
+
const prov = this.getPluggable(providerName);
|
|
257
|
+
|
|
258
|
+
try {
|
|
259
|
+
return await prov.getGeofence(geofenceId, options);
|
|
260
|
+
} catch (error) {
|
|
261
|
+
logger.debug(error);
|
|
262
|
+
throw error;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* List geofences
|
|
268
|
+
* @param options?: ListGeofenceOptions
|
|
269
|
+
* @returns {Promise<ListGeofencesResults>} - Promise that resolves to an object with:
|
|
270
|
+
* entries: list of geofences - 100 geofences are listed per page
|
|
271
|
+
* nextToken: token for next page of geofences
|
|
272
|
+
*/
|
|
273
|
+
public async listGeofences(
|
|
274
|
+
options?: ListGeofenceOptions
|
|
275
|
+
): Promise<ListGeofenceResults> {
|
|
276
|
+
const { providerName = DEFAULT_PROVIDER } = options || {};
|
|
277
|
+
const prov = this.getPluggable(providerName);
|
|
278
|
+
|
|
279
|
+
try {
|
|
280
|
+
return await prov.listGeofences(options);
|
|
281
|
+
} catch (error) {
|
|
282
|
+
logger.debug(error);
|
|
283
|
+
throw error;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* Delete geofences
|
|
289
|
+
* @param geofenceIds: string|string[]
|
|
290
|
+
* @param options?: GeofenceOptions
|
|
291
|
+
* @returns {Promise<DeleteGeofencesResults>} - Promise that resolves to an object with:
|
|
292
|
+
* successes: list of geofences successfully deleted
|
|
293
|
+
* errors: list of geofences that failed to delete
|
|
294
|
+
*/
|
|
295
|
+
public async deleteGeofences(
|
|
296
|
+
geofenceIds: string | string[],
|
|
297
|
+
options?: GeofenceOptions
|
|
298
|
+
): Promise<DeleteGeofencesResults> {
|
|
299
|
+
const { providerName = DEFAULT_PROVIDER } = options || {};
|
|
300
|
+
const prov = this.getPluggable(providerName);
|
|
301
|
+
|
|
302
|
+
// If single geofence input, make it an array for batch call
|
|
303
|
+
let geofenceIdsInputArray;
|
|
304
|
+
if (!Array.isArray(geofenceIds)) {
|
|
305
|
+
geofenceIdsInputArray = [geofenceIds];
|
|
306
|
+
} else {
|
|
307
|
+
geofenceIdsInputArray = geofenceIds;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
// Delete geofences
|
|
311
|
+
try {
|
|
312
|
+
return await prov.deleteGeofences(geofenceIdsInputArray, options);
|
|
313
|
+
} catch (error) {
|
|
314
|
+
logger.debug(error);
|
|
315
|
+
throw error;
|
|
316
|
+
}
|
|
317
|
+
}
|
|
199
318
|
}
|
|
200
319
|
|
|
201
320
|
export const Geo = new GeoClass();
|