@aws-amplify/geo 3.0.17-unstable.5c56101.0 → 3.0.17
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/package.json +88 -88
- package/src/Geo.ts +11 -11
- package/src/providers/location-service/AmazonLocationServiceProvider.ts +23 -23
- package/src/types/Provider.ts +6 -6
- package/src/util.ts +17 -17
package/package.json
CHANGED
|
@@ -1,90 +1,90 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
2
|
+
"name": "@aws-amplify/geo",
|
|
3
|
+
"version": "3.0.17",
|
|
4
|
+
"description": "Geo category for aws-amplify",
|
|
5
|
+
"main": "./dist/cjs/index.js",
|
|
6
|
+
"module": "./dist/esm/index.mjs",
|
|
7
|
+
"typings": "./dist/esm/index.d.ts",
|
|
8
|
+
"react-native": "./src/index.ts",
|
|
9
|
+
"publishConfig": {
|
|
10
|
+
"access": "public"
|
|
11
|
+
},
|
|
12
|
+
"sideEffects": [
|
|
13
|
+
"./dist/cjs/geo/geo.js",
|
|
14
|
+
"./dist/esm/geo/geo.mjs"
|
|
15
|
+
],
|
|
16
|
+
"scripts": {
|
|
17
|
+
"test": "yarn run lint && jest -w 1 --coverage --logHeapUsage",
|
|
18
|
+
"test:size": "size-limit",
|
|
19
|
+
"build-with-test": "npm test && npm run build",
|
|
20
|
+
"build:umd": "webpack && webpack --config ./webpack.config.dev.js",
|
|
21
|
+
"build:esm-cjs": "rollup -c rollup.config.mjs",
|
|
22
|
+
"build:watch": "npm run build:esm-cjs -- --watch",
|
|
23
|
+
"build": "npm run clean && npm run build:esm-cjs && npm run build:umd",
|
|
24
|
+
"clean": "npm run clean:size && rimraf dist lib lib-esm",
|
|
25
|
+
"clean:size": "rimraf dual-publish-tmp tmp*",
|
|
26
|
+
"format": "echo \"Not implemented\"",
|
|
27
|
+
"lint": "tslint '{__tests__,src}/**/*.ts' && npm run ts-coverage",
|
|
28
|
+
"ts-coverage": "typescript-coverage-report -p ./tsconfig.build.json -t 84.00"
|
|
29
|
+
},
|
|
30
|
+
"exports": {
|
|
31
|
+
".": {
|
|
32
|
+
"types": "./dist/esm/index.d.ts",
|
|
33
|
+
"import": "./dist/esm/index.mjs",
|
|
34
|
+
"require": "./dist/cjs/index.js",
|
|
35
|
+
"react-native": "./src/index.ts"
|
|
36
|
+
},
|
|
37
|
+
"./location-service": {
|
|
38
|
+
"types": "./dist/esm/providers/location-service/AmazonLocationServiceProvider.d.ts",
|
|
39
|
+
"import": "./dist/esm/providers/location-service/AmazonLocationServiceProvider.mjs",
|
|
40
|
+
"require": "./dist/cjs/providers/location-service/AmazonLocationServiceProvider.js",
|
|
41
|
+
"react-native": "./src/providers/location-service/AmazonLocationServiceProvider.ts"
|
|
42
|
+
},
|
|
43
|
+
"./package.json": "./package.json"
|
|
44
|
+
},
|
|
45
|
+
"typesVersions": {
|
|
46
|
+
">=4.2": {
|
|
47
|
+
"location-service": [
|
|
48
|
+
"./dist/esm/providers/location-service/AmazonLocationServiceProvider.d.ts"
|
|
49
|
+
]
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
"repository": {
|
|
53
|
+
"type": "git",
|
|
54
|
+
"url": "https://github.com/aws-amplify/amplify-js.git"
|
|
55
|
+
},
|
|
56
|
+
"author": "Amazon Web Services",
|
|
57
|
+
"license": "Apache-2.0",
|
|
58
|
+
"bugs": {
|
|
59
|
+
"url": "https://github.com/aws/aws-amplify/issues"
|
|
60
|
+
},
|
|
61
|
+
"homepage": "https://aws-amplify.github.io/",
|
|
62
|
+
"files": [
|
|
63
|
+
"dist/cjs",
|
|
64
|
+
"dist/esm",
|
|
65
|
+
"location-service",
|
|
66
|
+
"src"
|
|
67
|
+
],
|
|
68
|
+
"dependencies": {
|
|
69
|
+
"@aws-sdk/client-location": "3.398.0",
|
|
70
|
+
"@turf/boolean-clockwise": "6.5.0",
|
|
71
|
+
"camelcase-keys": "6.2.2",
|
|
72
|
+
"tslib": "^2.5.0"
|
|
73
|
+
},
|
|
74
|
+
"peerDependencies": {
|
|
75
|
+
"@aws-amplify/core": "^6.0.0"
|
|
76
|
+
},
|
|
77
|
+
"devDependencies": {
|
|
78
|
+
"@aws-amplify/core": "6.0.17",
|
|
79
|
+
"typescript": "5.0.2"
|
|
80
|
+
},
|
|
81
|
+
"size-limit": [
|
|
82
|
+
{
|
|
83
|
+
"name": "Geo (top-level class)",
|
|
84
|
+
"path": "./dist/esm/index.mjs",
|
|
85
|
+
"import": "{ Amplify, Geo }",
|
|
86
|
+
"limit": "43.9 kB"
|
|
87
|
+
}
|
|
88
|
+
],
|
|
89
|
+
"gitHead": "c54a19c8a654a47d559cb0fd41c74bd2c3eb79ca"
|
|
90
90
|
}
|
package/src/Geo.ts
CHANGED
|
@@ -43,7 +43,7 @@ export class GeoClass {
|
|
|
43
43
|
this._config = Object.assign({}, this._config, amplifyConfig.Geo);
|
|
44
44
|
|
|
45
45
|
const locationProvider = new AmazonLocationServiceProvider(
|
|
46
|
-
amplifyConfig.Geo
|
|
46
|
+
amplifyConfig.Geo,
|
|
47
47
|
);
|
|
48
48
|
this._pluggables.push(locationProvider);
|
|
49
49
|
|
|
@@ -74,7 +74,7 @@ export class GeoClass {
|
|
|
74
74
|
*/
|
|
75
75
|
public getPluggable(providerName: string) {
|
|
76
76
|
const pluggable = this._pluggables.find(
|
|
77
|
-
pluggable => pluggable.getProviderName() === providerName
|
|
77
|
+
pluggable => pluggable.getProviderName() === providerName,
|
|
78
78
|
);
|
|
79
79
|
if (pluggable === undefined) {
|
|
80
80
|
logger.debug('No plugin found with providerName', providerName);
|
|
@@ -88,7 +88,7 @@ export class GeoClass {
|
|
|
88
88
|
*/
|
|
89
89
|
public removePluggable(providerName: string) {
|
|
90
90
|
this._pluggables = this._pluggables.filter(
|
|
91
|
-
pluggable => pluggable.getProviderName() !== providerName
|
|
91
|
+
pluggable => pluggable.getProviderName() !== providerName,
|
|
92
92
|
);
|
|
93
93
|
return;
|
|
94
94
|
}
|
|
@@ -123,7 +123,7 @@ export class GeoClass {
|
|
|
123
123
|
*/
|
|
124
124
|
public async searchByText(
|
|
125
125
|
text: string,
|
|
126
|
-
options?: SearchByTextOptions
|
|
126
|
+
options?: SearchByTextOptions,
|
|
127
127
|
): Promise<Place[]> {
|
|
128
128
|
const { providerName = DEFAULT_PROVIDER } = options || {};
|
|
129
129
|
const prov = this.getPluggable(providerName);
|
|
@@ -144,7 +144,7 @@ export class GeoClass {
|
|
|
144
144
|
*/
|
|
145
145
|
public async searchForSuggestions(
|
|
146
146
|
text: string,
|
|
147
|
-
options?: SearchByTextOptions
|
|
147
|
+
options?: SearchByTextOptions,
|
|
148
148
|
) {
|
|
149
149
|
const { providerName = DEFAULT_PROVIDER } = options || {};
|
|
150
150
|
const prov = this.getPluggable(providerName);
|
|
@@ -165,7 +165,7 @@ export class GeoClass {
|
|
|
165
165
|
*/
|
|
166
166
|
public async searchByPlaceId(
|
|
167
167
|
placeId: string,
|
|
168
|
-
options?: searchByPlaceIdOptions
|
|
168
|
+
options?: searchByPlaceIdOptions,
|
|
169
169
|
) {
|
|
170
170
|
const providerName = DEFAULT_PROVIDER;
|
|
171
171
|
const prov = this.getPluggable(providerName);
|
|
@@ -186,7 +186,7 @@ export class GeoClass {
|
|
|
186
186
|
*/
|
|
187
187
|
public async searchByCoordinates(
|
|
188
188
|
coordinates: Coordinates,
|
|
189
|
-
options?: SearchByCoordinatesOptions
|
|
189
|
+
options?: SearchByCoordinatesOptions,
|
|
190
190
|
): Promise<Place> {
|
|
191
191
|
const { providerName = DEFAULT_PROVIDER } = options || {};
|
|
192
192
|
const prov = this.getPluggable(providerName);
|
|
@@ -211,7 +211,7 @@ export class GeoClass {
|
|
|
211
211
|
*/
|
|
212
212
|
public async saveGeofences(
|
|
213
213
|
geofences: GeofenceInput | GeofenceInput[],
|
|
214
|
-
options?: GeofenceOptions
|
|
214
|
+
options?: GeofenceOptions,
|
|
215
215
|
): Promise<SaveGeofencesResults> {
|
|
216
216
|
const { providerName = DEFAULT_PROVIDER } = options || {};
|
|
217
217
|
const prov = this.getPluggable(providerName);
|
|
@@ -240,7 +240,7 @@ export class GeoClass {
|
|
|
240
240
|
*/
|
|
241
241
|
public async getGeofence(
|
|
242
242
|
geofenceId: GeofenceId,
|
|
243
|
-
options?: GeofenceOptions
|
|
243
|
+
options?: GeofenceOptions,
|
|
244
244
|
): Promise<Geofence> {
|
|
245
245
|
const { providerName = DEFAULT_PROVIDER } = options || {};
|
|
246
246
|
const prov = this.getPluggable(providerName);
|
|
@@ -261,7 +261,7 @@ export class GeoClass {
|
|
|
261
261
|
* nextToken: token for next page of geofences
|
|
262
262
|
*/
|
|
263
263
|
public async listGeofences(
|
|
264
|
-
options?: ListGeofenceOptions
|
|
264
|
+
options?: ListGeofenceOptions,
|
|
265
265
|
): Promise<ListGeofenceResults> {
|
|
266
266
|
const { providerName = DEFAULT_PROVIDER } = options || {};
|
|
267
267
|
const prov = this.getPluggable(providerName);
|
|
@@ -284,7 +284,7 @@ export class GeoClass {
|
|
|
284
284
|
*/
|
|
285
285
|
public async deleteGeofences(
|
|
286
286
|
geofenceIds: string | string[],
|
|
287
|
-
options?: GeofenceOptions
|
|
287
|
+
options?: GeofenceOptions,
|
|
288
288
|
): Promise<DeleteGeofencesResults> {
|
|
289
289
|
const { providerName = DEFAULT_PROVIDER } = options || {};
|
|
290
290
|
const prov = this.getPluggable(providerName);
|
|
@@ -139,7 +139,7 @@ export class AmazonLocationServiceProvider implements GeoProvider {
|
|
|
139
139
|
*/
|
|
140
140
|
public async searchByText(
|
|
141
141
|
text: string,
|
|
142
|
-
options?: SearchByTextOptions
|
|
142
|
+
options?: SearchByTextOptions,
|
|
143
143
|
): Promise<Place[]> {
|
|
144
144
|
const credentialsOK = await this._ensureCredentials();
|
|
145
145
|
if (!credentialsOK) {
|
|
@@ -187,7 +187,7 @@ export class AmazonLocationServiceProvider implements GeoProvider {
|
|
|
187
187
|
* Here we want to flatten that to an array of results and change them to camelCase
|
|
188
188
|
*/
|
|
189
189
|
const PascalResults: PlaceResult[] = response.Results.map(
|
|
190
|
-
result => result.Place
|
|
190
|
+
result => result.Place,
|
|
191
191
|
);
|
|
192
192
|
const results: Place[] = camelcaseKeys(PascalResults, {
|
|
193
193
|
deep: true,
|
|
@@ -205,7 +205,7 @@ export class AmazonLocationServiceProvider implements GeoProvider {
|
|
|
205
205
|
|
|
206
206
|
public async searchForSuggestions(
|
|
207
207
|
text: string,
|
|
208
|
-
options?: SearchByTextOptions
|
|
208
|
+
options?: SearchByTextOptions,
|
|
209
209
|
): Promise<SearchForSuggestionsResults> {
|
|
210
210
|
const credentialsOK = await this._ensureCredentials();
|
|
211
211
|
if (!credentialsOK) {
|
|
@@ -238,7 +238,7 @@ export class AmazonLocationServiceProvider implements GeoProvider {
|
|
|
238
238
|
customUserAgent: getGeoUserAgent(GeoAction.SearchForSuggestions),
|
|
239
239
|
});
|
|
240
240
|
const command = new SearchPlaceIndexForSuggestionsCommand(
|
|
241
|
-
locationServiceInput
|
|
241
|
+
locationServiceInput,
|
|
242
242
|
);
|
|
243
243
|
|
|
244
244
|
let response;
|
|
@@ -270,7 +270,7 @@ export class AmazonLocationServiceProvider implements GeoProvider {
|
|
|
270
270
|
|
|
271
271
|
public async searchByPlaceId(
|
|
272
272
|
placeId: string,
|
|
273
|
-
options?: searchByPlaceIdOptions
|
|
273
|
+
options?: searchByPlaceIdOptions,
|
|
274
274
|
): Promise<Place | undefined> {
|
|
275
275
|
const credentialsOK = await this._ensureCredentials();
|
|
276
276
|
if (!credentialsOK) {
|
|
@@ -317,7 +317,7 @@ export class AmazonLocationServiceProvider implements GeoProvider {
|
|
|
317
317
|
*/
|
|
318
318
|
public async searchByCoordinates(
|
|
319
319
|
coordinates: Coordinates,
|
|
320
|
-
options?: SearchByCoordinatesOptions
|
|
320
|
+
options?: SearchByCoordinatesOptions,
|
|
321
321
|
): Promise<Place> {
|
|
322
322
|
const credentialsOK = await this._ensureCredentials();
|
|
323
323
|
if (!credentialsOK) {
|
|
@@ -344,7 +344,7 @@ export class AmazonLocationServiceProvider implements GeoProvider {
|
|
|
344
344
|
customUserAgent: getGeoUserAgent(GeoAction.SearchByCoordinates),
|
|
345
345
|
});
|
|
346
346
|
const command = new SearchPlaceIndexForPositionCommand(
|
|
347
|
-
locationServiceInput
|
|
347
|
+
locationServiceInput,
|
|
348
348
|
);
|
|
349
349
|
|
|
350
350
|
let response;
|
|
@@ -378,7 +378,7 @@ export class AmazonLocationServiceProvider implements GeoProvider {
|
|
|
378
378
|
*/
|
|
379
379
|
public async saveGeofences(
|
|
380
380
|
geofences: GeofenceInput[],
|
|
381
|
-
options?: AmazonLocationServiceGeofenceOptions
|
|
381
|
+
options?: AmazonLocationServiceGeofenceOptions,
|
|
382
382
|
): Promise<SaveGeofencesResults> {
|
|
383
383
|
if (geofences.length < 1) {
|
|
384
384
|
throw new Error('Geofence input array is empty');
|
|
@@ -408,7 +408,7 @@ export class AmazonLocationServiceProvider implements GeoProvider {
|
|
|
408
408
|
Polygon: polygon,
|
|
409
409
|
},
|
|
410
410
|
};
|
|
411
|
-
}
|
|
411
|
+
},
|
|
412
412
|
);
|
|
413
413
|
const results: SaveGeofencesResults = {
|
|
414
414
|
successes: [],
|
|
@@ -430,7 +430,7 @@ export class AmazonLocationServiceProvider implements GeoProvider {
|
|
|
430
430
|
try {
|
|
431
431
|
response = await this._AmazonLocationServiceBatchPutGeofenceCall(
|
|
432
432
|
batch,
|
|
433
|
-
options?.collectionName || this._config.geofenceCollections.default
|
|
433
|
+
options?.collectionName || this._config.geofenceCollections.default,
|
|
434
434
|
);
|
|
435
435
|
} catch (error) {
|
|
436
436
|
// If the API call fails, add the geofences to the errors array and move to next batch
|
|
@@ -468,7 +468,7 @@ export class AmazonLocationServiceProvider implements GeoProvider {
|
|
|
468
468
|
geofenceId: GeofenceId!,
|
|
469
469
|
});
|
|
470
470
|
});
|
|
471
|
-
})
|
|
471
|
+
}),
|
|
472
472
|
);
|
|
473
473
|
|
|
474
474
|
return results;
|
|
@@ -482,7 +482,7 @@ export class AmazonLocationServiceProvider implements GeoProvider {
|
|
|
482
482
|
*/
|
|
483
483
|
public async getGeofence(
|
|
484
484
|
geofenceId: GeofenceId,
|
|
485
|
-
options?: AmazonLocationServiceGeofenceOptions
|
|
485
|
+
options?: AmazonLocationServiceGeofenceOptions,
|
|
486
486
|
): Promise<AmazonLocationServiceGeofence> {
|
|
487
487
|
const credentialsOK = await this._ensureCredentials();
|
|
488
488
|
if (!credentialsOK) {
|
|
@@ -546,7 +546,7 @@ export class AmazonLocationServiceProvider implements GeoProvider {
|
|
|
546
546
|
* nextToken: token for next page of geofences
|
|
547
547
|
*/
|
|
548
548
|
public async listGeofences(
|
|
549
|
-
options?: AmazonLocationServiceListGeofenceOptions
|
|
549
|
+
options?: AmazonLocationServiceListGeofenceOptions,
|
|
550
550
|
): Promise<ListGeofenceResults> {
|
|
551
551
|
const credentialsOK = await this._ensureCredentials();
|
|
552
552
|
if (!credentialsOK) {
|
|
@@ -577,7 +577,7 @@ export class AmazonLocationServiceProvider implements GeoProvider {
|
|
|
577
577
|
|
|
578
578
|
// Create Amazon Location Service command
|
|
579
579
|
const command: ListGeofencesCommand = new ListGeofencesCommand(
|
|
580
|
-
listGeofencesInput
|
|
580
|
+
listGeofencesInput,
|
|
581
581
|
);
|
|
582
582
|
|
|
583
583
|
// Make API call
|
|
@@ -604,7 +604,7 @@ export class AmazonLocationServiceProvider implements GeoProvider {
|
|
|
604
604
|
polygon: Geometry!.Polygon as GeofencePolygon,
|
|
605
605
|
},
|
|
606
606
|
};
|
|
607
|
-
}
|
|
607
|
+
},
|
|
608
608
|
),
|
|
609
609
|
nextToken: NextToken,
|
|
610
610
|
};
|
|
@@ -622,7 +622,7 @@ export class AmazonLocationServiceProvider implements GeoProvider {
|
|
|
622
622
|
*/
|
|
623
623
|
public async deleteGeofences(
|
|
624
624
|
geofenceIds: string[],
|
|
625
|
-
options?: AmazonLocationServiceGeofenceOptions
|
|
625
|
+
options?: AmazonLocationServiceGeofenceOptions,
|
|
626
626
|
): Promise<AmazonLocationServiceDeleteGeofencesResults> {
|
|
627
627
|
if (geofenceIds.length < 1) {
|
|
628
628
|
throw new Error('GeofenceId input array is empty');
|
|
@@ -665,7 +665,7 @@ export class AmazonLocationServiceProvider implements GeoProvider {
|
|
|
665
665
|
try {
|
|
666
666
|
response = await this._AmazonLocationServiceBatchDeleteGeofenceCall(
|
|
667
667
|
batch,
|
|
668
|
-
options?.collectionName || this._config.geofenceCollections.default
|
|
668
|
+
options?.collectionName || this._config.geofenceCollections.default,
|
|
669
669
|
);
|
|
670
670
|
} catch (error) {
|
|
671
671
|
// If the API call fails, add the geofences to the errors array and move to next batch
|
|
@@ -685,12 +685,12 @@ export class AmazonLocationServiceProvider implements GeoProvider {
|
|
|
685
685
|
}
|
|
686
686
|
|
|
687
687
|
const badGeofenceIds = response.Errors.map(
|
|
688
|
-
({ geofenceId }) => geofenceId
|
|
688
|
+
({ geofenceId }) => geofenceId,
|
|
689
689
|
);
|
|
690
690
|
results.successes.push(
|
|
691
|
-
...batch.filter(Id => !badGeofenceIds.includes(Id))
|
|
691
|
+
...batch.filter(Id => !badGeofenceIds.includes(Id)),
|
|
692
692
|
);
|
|
693
|
-
})
|
|
693
|
+
}),
|
|
694
694
|
);
|
|
695
695
|
return results;
|
|
696
696
|
}
|
|
@@ -704,7 +704,7 @@ export class AmazonLocationServiceProvider implements GeoProvider {
|
|
|
704
704
|
if (!credentials) return false;
|
|
705
705
|
logger.debug(
|
|
706
706
|
'Set credentials for storage. Credentials are:',
|
|
707
|
-
credentials
|
|
707
|
+
credentials,
|
|
708
708
|
);
|
|
709
709
|
this._credentials = credentials;
|
|
710
710
|
return true;
|
|
@@ -769,7 +769,7 @@ export class AmazonLocationServiceProvider implements GeoProvider {
|
|
|
769
769
|
|
|
770
770
|
private async _AmazonLocationServiceBatchPutGeofenceCall(
|
|
771
771
|
PascalGeofences: BatchPutGeofenceRequestEntry[],
|
|
772
|
-
collectionName?: string
|
|
772
|
+
collectionName?: string,
|
|
773
773
|
) {
|
|
774
774
|
// Create the BatchPutGeofence input
|
|
775
775
|
const geofenceInput: BatchPutGeofenceCommandInput = {
|
|
@@ -796,7 +796,7 @@ export class AmazonLocationServiceProvider implements GeoProvider {
|
|
|
796
796
|
|
|
797
797
|
private async _AmazonLocationServiceBatchDeleteGeofenceCall(
|
|
798
798
|
geofenceIds: string[],
|
|
799
|
-
collectionName?: string
|
|
799
|
+
collectionName?: string,
|
|
800
800
|
): Promise<BatchDeleteGeofenceCommandOutput> {
|
|
801
801
|
// Create the BatchDeleteGeofence input
|
|
802
802
|
const deleteGeofencesInput: BatchDeleteGeofenceCommandInput = {
|
package/src/types/Provider.ts
CHANGED
|
@@ -37,29 +37,29 @@ export interface GeoProvider {
|
|
|
37
37
|
// search by coordinates and return a matching place
|
|
38
38
|
searchByCoordinates(
|
|
39
39
|
coordinates: Coordinates,
|
|
40
|
-
options?: SearchByCoordinatesOptions
|
|
40
|
+
options?: SearchByCoordinatesOptions,
|
|
41
41
|
): Promise<Place>;
|
|
42
42
|
|
|
43
43
|
searchForSuggestions(
|
|
44
44
|
text: string,
|
|
45
|
-
options?: SearchByTextOptions
|
|
45
|
+
options?: SearchByTextOptions,
|
|
46
46
|
): Promise<SearchForSuggestionsResults>;
|
|
47
47
|
|
|
48
48
|
searchByPlaceId(
|
|
49
49
|
placeId: string,
|
|
50
|
-
options?: searchByPlaceIdOptions
|
|
50
|
+
options?: searchByPlaceIdOptions,
|
|
51
51
|
): Promise<Place | undefined>;
|
|
52
52
|
|
|
53
53
|
// create geofences
|
|
54
54
|
saveGeofences(
|
|
55
55
|
geofences: GeofenceInput[],
|
|
56
|
-
options?: GeofenceOptions
|
|
56
|
+
options?: GeofenceOptions,
|
|
57
57
|
): Promise<SaveGeofencesResults>;
|
|
58
58
|
|
|
59
59
|
// get a single geofence
|
|
60
60
|
getGeofence(
|
|
61
61
|
geofenceId: GeofenceId,
|
|
62
|
-
options?: ListGeofenceOptions
|
|
62
|
+
options?: ListGeofenceOptions,
|
|
63
63
|
): Promise<Geofence>;
|
|
64
64
|
|
|
65
65
|
// list all geofences
|
|
@@ -68,6 +68,6 @@ export interface GeoProvider {
|
|
|
68
68
|
// Delete geofences
|
|
69
69
|
deleteGeofences(
|
|
70
70
|
geofenceIds: string[],
|
|
71
|
-
options?: GeofenceOptions
|
|
71
|
+
options?: GeofenceOptions,
|
|
72
72
|
): Promise<DeleteGeofencesResults>;
|
|
73
73
|
}
|
package/src/util.ts
CHANGED
|
@@ -26,7 +26,7 @@ export function validateCoordinates(lng: Longitude, lat: Latitude): void {
|
|
|
26
26
|
throw new Error('Latitude must be between -90 and 90 degrees inclusive.');
|
|
27
27
|
} else if (lng < -180 || 180 < lng) {
|
|
28
28
|
throw new Error(
|
|
29
|
-
'Longitude must be between -180 and 180 degrees inclusive.'
|
|
29
|
+
'Longitude must be between -180 and 180 degrees inclusive.',
|
|
30
30
|
);
|
|
31
31
|
}
|
|
32
32
|
}
|
|
@@ -37,20 +37,20 @@ export function validateGeofenceId(geofenceId: GeofenceId): void {
|
|
|
37
37
|
// Check if geofenceId is valid
|
|
38
38
|
if (!geofenceIdRegex.test(geofenceId)) {
|
|
39
39
|
throw new Error(
|
|
40
|
-
`Invalid geofenceId: '${geofenceId}' - IDs can only contain alphanumeric characters, hyphens, underscores and periods
|
|
40
|
+
`Invalid geofenceId: '${geofenceId}' - IDs can only contain alphanumeric characters, hyphens, underscores and periods.`,
|
|
41
41
|
);
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
export function validateLinearRing(
|
|
46
46
|
linearRing: LinearRing,
|
|
47
|
-
geofenceId?: GeofenceId
|
|
47
|
+
geofenceId?: GeofenceId,
|
|
48
48
|
): void {
|
|
49
49
|
const errorPrefix = geofenceId ? `${geofenceId}: ` : '';
|
|
50
50
|
// Validate LinearRing size, must be at least 4 points
|
|
51
51
|
if (linearRing.length < 4) {
|
|
52
52
|
throw new Error(
|
|
53
|
-
`${errorPrefix}LinearRing must contain 4 or more coordinates
|
|
53
|
+
`${errorPrefix}LinearRing must contain 4 or more coordinates.`,
|
|
54
54
|
);
|
|
55
55
|
}
|
|
56
56
|
|
|
@@ -66,8 +66,8 @@ export function validateLinearRing(
|
|
|
66
66
|
if (badCoordinates.length > 0) {
|
|
67
67
|
throw new Error(
|
|
68
68
|
`${errorPrefix}One or more of the coordinates in the Polygon LinearRing are not valid: ${JSON.stringify(
|
|
69
|
-
badCoordinates
|
|
70
|
-
)}
|
|
69
|
+
badCoordinates,
|
|
70
|
+
)}`,
|
|
71
71
|
);
|
|
72
72
|
}
|
|
73
73
|
|
|
@@ -77,45 +77,45 @@ export function validateLinearRing(
|
|
|
77
77
|
|
|
78
78
|
if (lngA !== lngB || latA !== latB) {
|
|
79
79
|
throw new Error(
|
|
80
|
-
`${errorPrefix}LinearRing's first and last coordinates are not the same
|
|
80
|
+
`${errorPrefix}LinearRing's first and last coordinates are not the same`,
|
|
81
81
|
);
|
|
82
82
|
}
|
|
83
83
|
|
|
84
84
|
if (booleanClockwise(linearRing)) {
|
|
85
85
|
throw new Error(
|
|
86
|
-
`${errorPrefix}LinearRing coordinates must be wound counterclockwise
|
|
86
|
+
`${errorPrefix}LinearRing coordinates must be wound counterclockwise`,
|
|
87
87
|
);
|
|
88
88
|
}
|
|
89
89
|
}
|
|
90
90
|
|
|
91
91
|
export function validatePolygon(
|
|
92
92
|
polygon: GeofencePolygon,
|
|
93
|
-
geofenceId?: GeofenceId
|
|
93
|
+
geofenceId?: GeofenceId,
|
|
94
94
|
): void {
|
|
95
95
|
const errorPrefix = geofenceId ? `${geofenceId}: ` : '';
|
|
96
96
|
if (!Array.isArray(polygon)) {
|
|
97
97
|
throw new Error(
|
|
98
|
-
`${errorPrefix}Polygon is of incorrect structure. It should be an array of LinearRings
|
|
98
|
+
`${errorPrefix}Polygon is of incorrect structure. It should be an array of LinearRings`,
|
|
99
99
|
);
|
|
100
100
|
}
|
|
101
101
|
if (polygon.length < 1) {
|
|
102
102
|
throw new Error(
|
|
103
|
-
`${errorPrefix}Polygon must have a single LinearRing array
|
|
103
|
+
`${errorPrefix}Polygon must have a single LinearRing array.`,
|
|
104
104
|
);
|
|
105
105
|
}
|
|
106
106
|
|
|
107
107
|
if (polygon.length > 1) {
|
|
108
108
|
throw new Error(
|
|
109
|
-
`${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
|
|
109
|
+
`${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.`,
|
|
110
110
|
);
|
|
111
111
|
}
|
|
112
112
|
const verticesCount = polygon.reduce(
|
|
113
113
|
(prev, linearRing) => prev + linearRing.length,
|
|
114
|
-
0
|
|
114
|
+
0,
|
|
115
115
|
);
|
|
116
116
|
if (verticesCount > 1000) {
|
|
117
117
|
throw new Error(
|
|
118
|
-
`${errorPrefix}Polygon has more than the maximum 1000 vertices
|
|
118
|
+
`${errorPrefix}Polygon has more than the maximum 1000 vertices.`,
|
|
119
119
|
);
|
|
120
120
|
}
|
|
121
121
|
polygon.forEach(linearRing => {
|
|
@@ -161,11 +161,11 @@ export function validateGeofencesInput(geofences: GeofenceInput[]) {
|
|
|
161
161
|
} catch (error) {
|
|
162
162
|
if (
|
|
163
163
|
(error as Error).message.includes(
|
|
164
|
-
'Polygon has more than the maximum 1000 vertices.'
|
|
164
|
+
'Polygon has more than the maximum 1000 vertices.',
|
|
165
165
|
)
|
|
166
166
|
) {
|
|
167
167
|
throw new Error(
|
|
168
|
-
`Geofence '${geofenceId}' has more than the maximum of 1000 vertices
|
|
168
|
+
`Geofence '${geofenceId}' has more than the maximum of 1000 vertices`,
|
|
169
169
|
);
|
|
170
170
|
}
|
|
171
171
|
}
|
|
@@ -188,7 +188,7 @@ export function mapSearchOptions(options, locationServiceInput) {
|
|
|
188
188
|
|
|
189
189
|
if (options['biasPosition'] && options['searchAreaConstraints']) {
|
|
190
190
|
throw new Error(
|
|
191
|
-
'BiasPosition and SearchAreaConstraints are mutually exclusive, please remove one or the other from the options object'
|
|
191
|
+
'BiasPosition and SearchAreaConstraints are mutually exclusive, please remove one or the other from the options object',
|
|
192
192
|
);
|
|
193
193
|
}
|
|
194
194
|
if (options['biasPosition']) {
|