@aws-amplify/geo 1.2.5-unstable.7 → 1.3.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/CHANGELOG.md +16 -0
- package/dist/aws-amplify-geo.js +2097 -73
- 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 +36 -3
- 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 +425 -8
- package/lib/Providers/AmazonLocationServiceProvider.js.map +1 -1
- package/lib/types/AmazonLocationServiceProvider.d.ts +21 -1
- package/lib/types/Geo.d.ts +49 -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 +147 -0
- package/lib/util.js.map +1 -0
- package/lib-esm/Geo.d.ts +36 -3
- 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 +426 -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 +49 -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 +137 -0
- package/lib-esm/util.js.map +1 -0
- package/package.json +6 -4
- package/src/Geo.ts +123 -2
- package/src/Providers/AmazonLocationServiceProvider.ts +432 -6
- package/src/types/AmazonLocationServiceProvider.ts +56 -1
- package/src/types/Geo.ts +74 -2
- package/src/types/Provider.ts +31 -1
- package/src/util.ts +180 -0
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
* and limitations under the License.
|
|
12
12
|
*/
|
|
13
13
|
import camelcaseKeys from 'camelcase-keys';
|
|
14
|
+
|
|
14
15
|
import {
|
|
15
16
|
ConsoleLogger as Logger,
|
|
16
17
|
Credentials,
|
|
@@ -23,8 +24,23 @@ import {
|
|
|
23
24
|
SearchPlaceIndexForTextCommand,
|
|
24
25
|
SearchPlaceIndexForPositionCommand,
|
|
25
26
|
SearchPlaceIndexForPositionCommandInput,
|
|
27
|
+
BatchPutGeofenceCommand,
|
|
28
|
+
BatchPutGeofenceCommandInput,
|
|
29
|
+
BatchPutGeofenceRequestEntry,
|
|
30
|
+
BatchPutGeofenceCommandOutput,
|
|
31
|
+
GetGeofenceCommand,
|
|
32
|
+
GetGeofenceCommandInput,
|
|
33
|
+
GetGeofenceCommandOutput,
|
|
34
|
+
ListGeofencesCommand,
|
|
35
|
+
ListGeofencesCommandInput,
|
|
36
|
+
ListGeofencesCommandOutput,
|
|
37
|
+
BatchDeleteGeofenceCommand,
|
|
38
|
+
BatchDeleteGeofenceCommandInput,
|
|
39
|
+
BatchDeleteGeofenceCommandOutput,
|
|
26
40
|
} from '@aws-sdk/client-location';
|
|
27
41
|
|
|
42
|
+
import { validateGeofenceId, validateGeofencesInput } from '../util';
|
|
43
|
+
|
|
28
44
|
import {
|
|
29
45
|
GeoConfig,
|
|
30
46
|
SearchByTextOptions,
|
|
@@ -33,6 +49,16 @@ import {
|
|
|
33
49
|
Place,
|
|
34
50
|
AmazonLocationServiceMapStyle,
|
|
35
51
|
Coordinates,
|
|
52
|
+
GeofenceId,
|
|
53
|
+
GeofenceInput,
|
|
54
|
+
AmazonLocationServiceGeofenceOptions,
|
|
55
|
+
AmazonLocationServiceListGeofenceOptions,
|
|
56
|
+
ListGeofenceResults,
|
|
57
|
+
AmazonLocationServiceGeofenceStatus,
|
|
58
|
+
SaveGeofencesResults,
|
|
59
|
+
AmazonLocationServiceGeofence,
|
|
60
|
+
GeofencePolygon,
|
|
61
|
+
AmazonLocationServiceDeleteGeofencesResults,
|
|
36
62
|
} from '../types';
|
|
37
63
|
|
|
38
64
|
const logger = new Logger('AmazonLocationServiceProvider');
|
|
@@ -254,6 +280,339 @@ export class AmazonLocationServiceProvider implements GeoProvider {
|
|
|
254
280
|
return results;
|
|
255
281
|
}
|
|
256
282
|
|
|
283
|
+
/**
|
|
284
|
+
* Create geofences inside of a geofence collection
|
|
285
|
+
* @param geofences - Array of geofence objects to create
|
|
286
|
+
* @param options? - Optional parameters for creating geofences
|
|
287
|
+
* @returns {Promise<AmazonLocationServiceSaveGeofencesResults>} - Promise that resolves to an object with:
|
|
288
|
+
* successes: list of geofences successfully created
|
|
289
|
+
* errors: list of geofences that failed to create
|
|
290
|
+
*/
|
|
291
|
+
public async saveGeofences(
|
|
292
|
+
geofences: GeofenceInput[],
|
|
293
|
+
options?: AmazonLocationServiceGeofenceOptions
|
|
294
|
+
): Promise<SaveGeofencesResults> {
|
|
295
|
+
if (geofences.length < 1) {
|
|
296
|
+
throw new Error('Geofence input array is empty');
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
const credentialsOK = await this._ensureCredentials();
|
|
300
|
+
if (!credentialsOK) {
|
|
301
|
+
throw new Error('No credentials');
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
// Verify geofence collection exists in aws-config.js
|
|
305
|
+
try {
|
|
306
|
+
this._verifyGeofenceCollections(options?.collectionName);
|
|
307
|
+
} catch (error) {
|
|
308
|
+
logger.debug(error);
|
|
309
|
+
throw error;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
validateGeofencesInput(geofences);
|
|
313
|
+
|
|
314
|
+
// Convert geofences to PascalCase for Amazon Location Service format
|
|
315
|
+
const PascalGeofences: BatchPutGeofenceRequestEntry[] = geofences.map(
|
|
316
|
+
({ geofenceId, geometry: { polygon } }) => {
|
|
317
|
+
return {
|
|
318
|
+
GeofenceId: geofenceId,
|
|
319
|
+
Geometry: {
|
|
320
|
+
Polygon: polygon,
|
|
321
|
+
},
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
);
|
|
325
|
+
const results: SaveGeofencesResults = {
|
|
326
|
+
successes: [],
|
|
327
|
+
errors: [],
|
|
328
|
+
};
|
|
329
|
+
|
|
330
|
+
const geofenceBatches: BatchPutGeofenceRequestEntry[][] = [];
|
|
331
|
+
|
|
332
|
+
while (PascalGeofences.length > 0) {
|
|
333
|
+
// Splice off 10 geofences from input clone due to Amazon Location Service API limit
|
|
334
|
+
const apiLimit = 10;
|
|
335
|
+
geofenceBatches.push(PascalGeofences.splice(0, apiLimit));
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
await Promise.all(
|
|
339
|
+
geofenceBatches.map(async batch => {
|
|
340
|
+
// Make API call for the 10 geofences
|
|
341
|
+
let response: BatchPutGeofenceCommandOutput;
|
|
342
|
+
try {
|
|
343
|
+
response = await this._AmazonLocationServiceBatchPutGeofenceCall(
|
|
344
|
+
batch,
|
|
345
|
+
options?.collectionName || this._config.geofenceCollections.default
|
|
346
|
+
);
|
|
347
|
+
} catch (error) {
|
|
348
|
+
// If the API call fails, add the geofences to the errors array and move to next batch
|
|
349
|
+
batch.forEach(geofence => {
|
|
350
|
+
results.errors.push({
|
|
351
|
+
geofenceId: geofence.GeofenceId,
|
|
352
|
+
error: {
|
|
353
|
+
code: 'APIConnectionError',
|
|
354
|
+
message: error.message,
|
|
355
|
+
},
|
|
356
|
+
});
|
|
357
|
+
});
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
// Push all successes to results
|
|
362
|
+
response.Successes.forEach(success => {
|
|
363
|
+
const { GeofenceId, CreateTime, UpdateTime } = success;
|
|
364
|
+
results.successes.push({
|
|
365
|
+
geofenceId: GeofenceId,
|
|
366
|
+
createTime: CreateTime,
|
|
367
|
+
updateTime: UpdateTime,
|
|
368
|
+
});
|
|
369
|
+
});
|
|
370
|
+
|
|
371
|
+
// Push all errors to results
|
|
372
|
+
response.Errors.forEach(error => {
|
|
373
|
+
const {
|
|
374
|
+
Error: { Code, Message },
|
|
375
|
+
GeofenceId,
|
|
376
|
+
} = error;
|
|
377
|
+
results.errors.push({
|
|
378
|
+
error: {
|
|
379
|
+
code: Code,
|
|
380
|
+
message: Message,
|
|
381
|
+
},
|
|
382
|
+
geofenceId: GeofenceId,
|
|
383
|
+
});
|
|
384
|
+
});
|
|
385
|
+
})
|
|
386
|
+
);
|
|
387
|
+
|
|
388
|
+
return results;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
/**
|
|
392
|
+
* Get geofence from a geofence collection
|
|
393
|
+
* @param geofenceId:string
|
|
394
|
+
* @param options?: Optional parameters for getGeofence
|
|
395
|
+
* @returns {Promise<AmazonLocationServiceGeofence>} - Promise that resolves to a geofence object
|
|
396
|
+
*/
|
|
397
|
+
public async getGeofence(
|
|
398
|
+
geofenceId: GeofenceId,
|
|
399
|
+
options?: AmazonLocationServiceGeofenceOptions
|
|
400
|
+
): Promise<AmazonLocationServiceGeofence> {
|
|
401
|
+
const credentialsOK = await this._ensureCredentials();
|
|
402
|
+
if (!credentialsOK) {
|
|
403
|
+
throw new Error('No credentials');
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
// Verify geofence collection exists in aws-config.js
|
|
407
|
+
try {
|
|
408
|
+
this._verifyGeofenceCollections(options?.collectionName);
|
|
409
|
+
} catch (error) {
|
|
410
|
+
logger.debug(error);
|
|
411
|
+
throw error;
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
validateGeofenceId(geofenceId);
|
|
415
|
+
|
|
416
|
+
// Create Amazon Location Service Client
|
|
417
|
+
const client = new LocationClient({
|
|
418
|
+
credentials: this._config.credentials,
|
|
419
|
+
region: this._config.region,
|
|
420
|
+
customUserAgent: getAmplifyUserAgent(),
|
|
421
|
+
});
|
|
422
|
+
|
|
423
|
+
// Create Amazon Location Service command
|
|
424
|
+
const commandInput: GetGeofenceCommandInput = {
|
|
425
|
+
GeofenceId: geofenceId,
|
|
426
|
+
CollectionName:
|
|
427
|
+
options?.collectionName || this._config.geofenceCollections.default,
|
|
428
|
+
};
|
|
429
|
+
const command = new GetGeofenceCommand(commandInput);
|
|
430
|
+
|
|
431
|
+
// Make API call
|
|
432
|
+
let response: GetGeofenceCommandOutput;
|
|
433
|
+
try {
|
|
434
|
+
response = await client.send(command);
|
|
435
|
+
} catch (error) {
|
|
436
|
+
logger.debug(error);
|
|
437
|
+
throw error;
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
// Convert response to camelCase for return
|
|
441
|
+
const { GeofenceId, CreateTime, UpdateTime, Status, Geometry } = response;
|
|
442
|
+
const geofence: AmazonLocationServiceGeofence = {
|
|
443
|
+
createTime: CreateTime,
|
|
444
|
+
geofenceId: GeofenceId,
|
|
445
|
+
geometry: {
|
|
446
|
+
polygon: Geometry.Polygon as GeofencePolygon,
|
|
447
|
+
},
|
|
448
|
+
status: Status as AmazonLocationServiceGeofenceStatus,
|
|
449
|
+
updateTime: UpdateTime,
|
|
450
|
+
};
|
|
451
|
+
|
|
452
|
+
return geofence;
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
/**
|
|
456
|
+
* List geofences from a geofence collection
|
|
457
|
+
* @param options?: ListGeofenceOptions
|
|
458
|
+
* @returns {Promise<ListGeofencesResults>} - Promise that resolves to an object with:
|
|
459
|
+
* entries: list of geofences - 100 geofences are listed per page
|
|
460
|
+
* nextToken: token for next page of geofences
|
|
461
|
+
*/
|
|
462
|
+
public async listGeofences(
|
|
463
|
+
options?: AmazonLocationServiceListGeofenceOptions
|
|
464
|
+
): Promise<ListGeofenceResults> {
|
|
465
|
+
const credentialsOK = await this._ensureCredentials();
|
|
466
|
+
if (!credentialsOK) {
|
|
467
|
+
throw new Error('No credentials');
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
// Verify geofence collection exists in aws-config.js
|
|
471
|
+
try {
|
|
472
|
+
this._verifyGeofenceCollections(options?.collectionName);
|
|
473
|
+
} catch (error) {
|
|
474
|
+
logger.debug(error);
|
|
475
|
+
throw error;
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
// Create Amazon Location Service Client
|
|
479
|
+
const client = new LocationClient({
|
|
480
|
+
credentials: this._config.credentials,
|
|
481
|
+
region: this._config.region,
|
|
482
|
+
customUserAgent: getAmplifyUserAgent(),
|
|
483
|
+
});
|
|
484
|
+
|
|
485
|
+
// Create Amazon Location Service input
|
|
486
|
+
const listGeofencesInput: ListGeofencesCommandInput = {
|
|
487
|
+
NextToken: options?.nextToken,
|
|
488
|
+
CollectionName:
|
|
489
|
+
options?.collectionName || this._config.geofenceCollections.default,
|
|
490
|
+
};
|
|
491
|
+
|
|
492
|
+
// Create Amazon Location Service command
|
|
493
|
+
const command: ListGeofencesCommand = new ListGeofencesCommand(
|
|
494
|
+
listGeofencesInput
|
|
495
|
+
);
|
|
496
|
+
|
|
497
|
+
// Make API call
|
|
498
|
+
let response: ListGeofencesCommandOutput;
|
|
499
|
+
try {
|
|
500
|
+
response = await client.send(command);
|
|
501
|
+
} catch (error) {
|
|
502
|
+
logger.debug(error);
|
|
503
|
+
throw error;
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
// Convert response to camelCase for return
|
|
507
|
+
const { NextToken, Entries } = response;
|
|
508
|
+
|
|
509
|
+
const results: ListGeofenceResults = {
|
|
510
|
+
entries: Entries.map(
|
|
511
|
+
({
|
|
512
|
+
GeofenceId,
|
|
513
|
+
CreateTime,
|
|
514
|
+
UpdateTime,
|
|
515
|
+
Status,
|
|
516
|
+
Geometry: { Polygon },
|
|
517
|
+
}) => {
|
|
518
|
+
return {
|
|
519
|
+
geofenceId: GeofenceId,
|
|
520
|
+
createTime: CreateTime,
|
|
521
|
+
updateTime: UpdateTime,
|
|
522
|
+
status: Status,
|
|
523
|
+
geometry: {
|
|
524
|
+
polygon: Polygon as GeofencePolygon,
|
|
525
|
+
},
|
|
526
|
+
};
|
|
527
|
+
}
|
|
528
|
+
),
|
|
529
|
+
nextToken: NextToken,
|
|
530
|
+
};
|
|
531
|
+
|
|
532
|
+
return results;
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
/**
|
|
536
|
+
* Delete geofences from a geofence collection
|
|
537
|
+
* @param geofenceIds: string|string[]
|
|
538
|
+
* @param options?: GeofenceOptions
|
|
539
|
+
* @returns {Promise<DeleteGeofencesResults>} - Promise that resolves to an object with:
|
|
540
|
+
* successes: list of geofences successfully deleted
|
|
541
|
+
* errors: list of geofences that failed to delete
|
|
542
|
+
*/
|
|
543
|
+
public async deleteGeofences(
|
|
544
|
+
geofenceIds: string[],
|
|
545
|
+
options?: AmazonLocationServiceGeofenceOptions
|
|
546
|
+
): Promise<AmazonLocationServiceDeleteGeofencesResults> {
|
|
547
|
+
if (geofenceIds.length < 1) {
|
|
548
|
+
throw new Error('GeofenceId input array is empty');
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
const credentialsOK = await this._ensureCredentials();
|
|
552
|
+
if (!credentialsOK) {
|
|
553
|
+
throw new Error('No credentials');
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
this._verifyGeofenceCollections(options?.collectionName);
|
|
557
|
+
|
|
558
|
+
// Validate all geofenceIds are valid
|
|
559
|
+
const badGeofenceIds = geofenceIds.filter(geofenceId => {
|
|
560
|
+
try {
|
|
561
|
+
validateGeofenceId(geofenceId);
|
|
562
|
+
} catch (error) {
|
|
563
|
+
return true;
|
|
564
|
+
}
|
|
565
|
+
});
|
|
566
|
+
if (badGeofenceIds.length > 0) {
|
|
567
|
+
throw new Error(`Invalid geofence ids: ${badGeofenceIds.join(', ')}`);
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
const results: AmazonLocationServiceDeleteGeofencesResults = {
|
|
571
|
+
successes: [],
|
|
572
|
+
errors: [],
|
|
573
|
+
};
|
|
574
|
+
|
|
575
|
+
const geofenceIdBatches: string[][] = [];
|
|
576
|
+
|
|
577
|
+
let count = 0;
|
|
578
|
+
while (count < geofenceIds.length) {
|
|
579
|
+
geofenceIdBatches.push(geofenceIds.slice(count, (count += 10)));
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
await Promise.all(
|
|
583
|
+
geofenceIdBatches.map(async batch => {
|
|
584
|
+
let response;
|
|
585
|
+
try {
|
|
586
|
+
response = await this._AmazonLocationServiceBatchDeleteGeofenceCall(
|
|
587
|
+
batch,
|
|
588
|
+
options?.collectionName || this._config.geofenceCollections.default
|
|
589
|
+
);
|
|
590
|
+
} catch (error) {
|
|
591
|
+
// If the API call fails, add the geofences to the errors array and move to next batch
|
|
592
|
+
batch.forEach(geofenceId => {
|
|
593
|
+
const errorObject = {
|
|
594
|
+
geofenceId,
|
|
595
|
+
error: {
|
|
596
|
+
code: error.message,
|
|
597
|
+
message: error.message,
|
|
598
|
+
},
|
|
599
|
+
};
|
|
600
|
+
results.errors.push(errorObject);
|
|
601
|
+
});
|
|
602
|
+
return;
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
const badGeofenceIds = response.Errors.map(
|
|
606
|
+
({ geofenceId }) => geofenceId
|
|
607
|
+
);
|
|
608
|
+
results.successes.push(
|
|
609
|
+
...batch.filter(Id => !badGeofenceIds.includes(Id))
|
|
610
|
+
);
|
|
611
|
+
})
|
|
612
|
+
);
|
|
613
|
+
return results;
|
|
614
|
+
}
|
|
615
|
+
|
|
257
616
|
/**
|
|
258
617
|
* @private
|
|
259
618
|
*/
|
|
@@ -266,7 +625,7 @@ export class AmazonLocationServiceProvider implements GeoProvider {
|
|
|
266
625
|
this._config.credentials = cred;
|
|
267
626
|
return true;
|
|
268
627
|
} catch (error) {
|
|
269
|
-
logger.
|
|
628
|
+
logger.debug('Ensure credentials error. Credentials are:', error);
|
|
270
629
|
return false;
|
|
271
630
|
}
|
|
272
631
|
}
|
|
@@ -274,14 +633,14 @@ export class AmazonLocationServiceProvider implements GeoProvider {
|
|
|
274
633
|
private _verifyMapResources() {
|
|
275
634
|
if (!this._config.maps) {
|
|
276
635
|
const errorString =
|
|
277
|
-
"No map resources found in amplify config, run 'amplify add geo' to create
|
|
278
|
-
logger.
|
|
636
|
+
"No map resources found in amplify config, run 'amplify add geo' to create one and run `amplify push` after";
|
|
637
|
+
logger.debug(errorString);
|
|
279
638
|
throw new Error(errorString);
|
|
280
639
|
}
|
|
281
640
|
if (!this._config.maps.default) {
|
|
282
641
|
const errorString =
|
|
283
642
|
"No default map resource found in amplify config, run 'amplify add geo' to create one and run `amplify push` after";
|
|
284
|
-
logger.
|
|
643
|
+
logger.debug(errorString);
|
|
285
644
|
throw new Error(errorString);
|
|
286
645
|
}
|
|
287
646
|
}
|
|
@@ -292,9 +651,76 @@ export class AmazonLocationServiceProvider implements GeoProvider {
|
|
|
292
651
|
!optionalSearchIndex
|
|
293
652
|
) {
|
|
294
653
|
const errorString =
|
|
295
|
-
'No Search Index found, please run `amplify add geo` to
|
|
296
|
-
logger.
|
|
654
|
+
'No Search Index found in amplify config, please run `amplify add geo` to create one and run `amplify push` after.';
|
|
655
|
+
logger.debug(errorString);
|
|
656
|
+
throw new Error(errorString);
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
private _verifyGeofenceCollections(optionalGeofenceCollectionName?: string) {
|
|
661
|
+
if (
|
|
662
|
+
(!this._config.geofenceCollections ||
|
|
663
|
+
!this._config.geofenceCollections.default) &&
|
|
664
|
+
!optionalGeofenceCollectionName
|
|
665
|
+
) {
|
|
666
|
+
const errorString =
|
|
667
|
+
'No Geofence Collections found, please run `amplify add geo` to create one and run `amplify push` after.';
|
|
668
|
+
logger.debug(errorString);
|
|
297
669
|
throw new Error(errorString);
|
|
298
670
|
}
|
|
299
671
|
}
|
|
672
|
+
|
|
673
|
+
private async _AmazonLocationServiceBatchPutGeofenceCall(
|
|
674
|
+
PascalGeofences: BatchPutGeofenceRequestEntry[],
|
|
675
|
+
collectionName?: string
|
|
676
|
+
) {
|
|
677
|
+
// Create the BatchPutGeofence input
|
|
678
|
+
const geofenceInput: BatchPutGeofenceCommandInput = {
|
|
679
|
+
Entries: PascalGeofences,
|
|
680
|
+
CollectionName:
|
|
681
|
+
collectionName || this._config.geofenceCollections.default,
|
|
682
|
+
};
|
|
683
|
+
|
|
684
|
+
const client = new LocationClient({
|
|
685
|
+
credentials: this._config.credentials,
|
|
686
|
+
region: this._config.region,
|
|
687
|
+
customUserAgent: getAmplifyUserAgent(),
|
|
688
|
+
});
|
|
689
|
+
const command = new BatchPutGeofenceCommand(geofenceInput);
|
|
690
|
+
|
|
691
|
+
let response: BatchPutGeofenceCommandOutput;
|
|
692
|
+
try {
|
|
693
|
+
response = await client.send(command);
|
|
694
|
+
} catch (error) {
|
|
695
|
+
throw error;
|
|
696
|
+
}
|
|
697
|
+
return response;
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
private async _AmazonLocationServiceBatchDeleteGeofenceCall(
|
|
701
|
+
geofenceIds: string[],
|
|
702
|
+
collectionName?: string
|
|
703
|
+
): Promise<BatchDeleteGeofenceCommandOutput> {
|
|
704
|
+
// Create the BatchDeleteGeofence input
|
|
705
|
+
const deleteGeofencesInput: BatchDeleteGeofenceCommandInput = {
|
|
706
|
+
GeofenceIds: geofenceIds,
|
|
707
|
+
CollectionName:
|
|
708
|
+
collectionName || this._config.geofenceCollections.default,
|
|
709
|
+
};
|
|
710
|
+
|
|
711
|
+
const client = new LocationClient({
|
|
712
|
+
credentials: this._config.credentials,
|
|
713
|
+
region: this._config.region,
|
|
714
|
+
customUserAgent: getAmplifyUserAgent(),
|
|
715
|
+
});
|
|
716
|
+
const command = new BatchDeleteGeofenceCommand(deleteGeofencesInput);
|
|
717
|
+
|
|
718
|
+
let response: BatchDeleteGeofenceCommandOutput;
|
|
719
|
+
try {
|
|
720
|
+
response = await client.send(command);
|
|
721
|
+
} catch (error) {
|
|
722
|
+
throw error;
|
|
723
|
+
}
|
|
724
|
+
return response;
|
|
725
|
+
}
|
|
300
726
|
}
|
|
@@ -1,5 +1,60 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
MapStyle,
|
|
3
|
+
GeofenceOptions,
|
|
4
|
+
ListGeofenceOptions,
|
|
5
|
+
Geofence,
|
|
6
|
+
DeleteGeofencesResults,
|
|
7
|
+
GeofenceError,
|
|
8
|
+
} from './Geo';
|
|
2
9
|
|
|
10
|
+
// Maps
|
|
3
11
|
export interface AmazonLocationServiceMapStyle extends MapStyle {
|
|
4
12
|
region: string;
|
|
5
13
|
}
|
|
14
|
+
|
|
15
|
+
// Geofences
|
|
16
|
+
export type AmazonLocationServiceGeofenceOptions = GeofenceOptions & {
|
|
17
|
+
collectionName?: string;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
// Status types for Geofences
|
|
21
|
+
export type AmazonLocationServiceGeofenceStatus =
|
|
22
|
+
| 'ACTIVE'
|
|
23
|
+
| 'PENDING'
|
|
24
|
+
| 'FAILED'
|
|
25
|
+
| 'DELETED'
|
|
26
|
+
| 'DELETING';
|
|
27
|
+
|
|
28
|
+
export type AmazonLocationServiceGeofence = Omit<Geofence, 'status'> & {
|
|
29
|
+
status: AmazonLocationServiceGeofenceStatus;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
// List Geofences
|
|
33
|
+
export type AmazonLocationServiceListGeofenceOptions = ListGeofenceOptions & {
|
|
34
|
+
collectionName?: string;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
// Delete Geofences
|
|
38
|
+
export type AmazonLocationServiceBatchGeofenceErrorMessages =
|
|
39
|
+
| 'AccessDeniedException'
|
|
40
|
+
| 'InternalServerException'
|
|
41
|
+
| 'ResourceNotFoundException'
|
|
42
|
+
| 'ThrottlingException'
|
|
43
|
+
| 'ValidationException';
|
|
44
|
+
|
|
45
|
+
export type AmazonLocationServiceBatchGeofenceError = Omit<
|
|
46
|
+
GeofenceError,
|
|
47
|
+
'error'
|
|
48
|
+
> & {
|
|
49
|
+
error: {
|
|
50
|
+
code: string;
|
|
51
|
+
message: AmazonLocationServiceBatchGeofenceErrorMessages;
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export type AmazonLocationServiceDeleteGeofencesResults = Omit<
|
|
56
|
+
DeleteGeofencesResults,
|
|
57
|
+
'errors'
|
|
58
|
+
> & {
|
|
59
|
+
errors: AmazonLocationServiceBatchGeofenceError[];
|
|
60
|
+
};
|
package/src/types/Geo.ts
CHANGED
|
@@ -22,6 +22,10 @@ export interface GeoConfig {
|
|
|
22
22
|
items: string[];
|
|
23
23
|
default: string;
|
|
24
24
|
};
|
|
25
|
+
geofenceCollections?: {
|
|
26
|
+
items: string[];
|
|
27
|
+
default: string;
|
|
28
|
+
};
|
|
25
29
|
};
|
|
26
30
|
}
|
|
27
31
|
|
|
@@ -31,10 +35,10 @@ export interface MapStyle {
|
|
|
31
35
|
style: string;
|
|
32
36
|
}
|
|
33
37
|
|
|
34
|
-
export type Latitude = number;
|
|
35
38
|
export type Longitude = number;
|
|
39
|
+
export type Latitude = number;
|
|
36
40
|
|
|
37
|
-
//
|
|
41
|
+
// Coordinates are a tuple of longitude and latitude
|
|
38
42
|
export type Coordinates = [Longitude, Latitude];
|
|
39
43
|
|
|
40
44
|
// SW Longitude point for bounding box
|
|
@@ -73,6 +77,7 @@ export type SearchByTextOptions =
|
|
|
73
77
|
| SearchByTextOptionsWithBiasPosition
|
|
74
78
|
| SearchByTextOptionsWithSearchAreaConstraints;
|
|
75
79
|
|
|
80
|
+
// Options object for searchByCoordinates
|
|
76
81
|
export type SearchByCoordinatesOptions = {
|
|
77
82
|
maxResults?: number;
|
|
78
83
|
searchIndexName?: string;
|
|
@@ -97,3 +102,70 @@ export interface Place {
|
|
|
97
102
|
street?: string;
|
|
98
103
|
subRegion?: string;
|
|
99
104
|
}
|
|
105
|
+
// Array of 4 or more coordinates, where the first and last coordinate are the same to form a closed boundary
|
|
106
|
+
export type LinearRing = Coordinates[];
|
|
107
|
+
|
|
108
|
+
// An array of one linear ring
|
|
109
|
+
export type GeofencePolygon = LinearRing[];
|
|
110
|
+
|
|
111
|
+
// Geometry object for Polygon
|
|
112
|
+
export type PolygonGeometry = {
|
|
113
|
+
polygon: GeofencePolygon;
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
export type GeofenceId = string;
|
|
117
|
+
|
|
118
|
+
// Geofence object used as input for saveGeofences
|
|
119
|
+
export type GeofenceInput = {
|
|
120
|
+
geofenceId: GeofenceId;
|
|
121
|
+
geometry: PolygonGeometry;
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
// Options object for saveGeofences
|
|
125
|
+
export type GeofenceOptions = {
|
|
126
|
+
providerName?: string;
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
// Error type for errors related to Geofence API calls
|
|
130
|
+
export type GeofenceError = {
|
|
131
|
+
error: {
|
|
132
|
+
code: string;
|
|
133
|
+
message: string;
|
|
134
|
+
};
|
|
135
|
+
geofenceId: GeofenceId;
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
// Base geofence object
|
|
139
|
+
type GeofenceBase = {
|
|
140
|
+
geofenceId: GeofenceId;
|
|
141
|
+
createTime?: Date;
|
|
142
|
+
updateTime?: Date;
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
// Results object for getGeofence
|
|
146
|
+
export type Geofence = GeofenceBase & {
|
|
147
|
+
geometry: PolygonGeometry;
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
// Results object for saveGeofences
|
|
151
|
+
export type SaveGeofencesResults = {
|
|
152
|
+
successes: GeofenceBase[];
|
|
153
|
+
errors: GeofenceError[];
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
// Options object for listGeofence
|
|
157
|
+
export type ListGeofenceOptions = GeofenceOptions & {
|
|
158
|
+
nextToken?: string;
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
// Results options for listGeofence
|
|
162
|
+
export type ListGeofenceResults = {
|
|
163
|
+
entries: Geofence[];
|
|
164
|
+
nextToken: string | undefined;
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
// Results object for deleteGeofence
|
|
168
|
+
export type DeleteGeofencesResults = {
|
|
169
|
+
successes: GeofenceId[];
|
|
170
|
+
errors: GeofenceError[];
|
|
171
|
+
};
|
package/src/types/Provider.ts
CHANGED
|
@@ -10,13 +10,20 @@
|
|
|
10
10
|
* CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
|
|
11
11
|
* and limitations under the License.
|
|
12
12
|
*/
|
|
13
|
-
|
|
14
13
|
import {
|
|
15
14
|
SearchByTextOptions,
|
|
16
15
|
SearchByCoordinatesOptions,
|
|
17
16
|
Coordinates,
|
|
18
17
|
Place,
|
|
19
18
|
MapStyle,
|
|
19
|
+
Geofence,
|
|
20
|
+
GeofenceId,
|
|
21
|
+
GeofenceInput,
|
|
22
|
+
GeofenceOptions,
|
|
23
|
+
ListGeofenceOptions,
|
|
24
|
+
ListGeofenceResults,
|
|
25
|
+
SaveGeofencesResults,
|
|
26
|
+
DeleteGeofencesResults,
|
|
20
27
|
} from './Geo';
|
|
21
28
|
|
|
22
29
|
export interface GeoProvider {
|
|
@@ -35,10 +42,33 @@ export interface GeoProvider {
|
|
|
35
42
|
// get the map resource listed as default
|
|
36
43
|
getDefaultMap(): MapStyle;
|
|
37
44
|
|
|
45
|
+
// search by a text string and return a list of places
|
|
38
46
|
searchByText(text: string, options?: SearchByTextOptions): Promise<Place[]>;
|
|
39
47
|
|
|
48
|
+
// search by coordinates and return a matching place
|
|
40
49
|
searchByCoordinates(
|
|
41
50
|
coordinates: Coordinates,
|
|
42
51
|
options?: SearchByCoordinatesOptions
|
|
43
52
|
): Promise<Place>;
|
|
53
|
+
|
|
54
|
+
// create geofences
|
|
55
|
+
saveGeofences(
|
|
56
|
+
geofences: GeofenceInput[],
|
|
57
|
+
options?: GeofenceOptions
|
|
58
|
+
): Promise<SaveGeofencesResults>;
|
|
59
|
+
|
|
60
|
+
// get a single geofence
|
|
61
|
+
getGeofence(
|
|
62
|
+
geofenceId: GeofenceId,
|
|
63
|
+
options?: ListGeofenceOptions
|
|
64
|
+
): Promise<Geofence>;
|
|
65
|
+
|
|
66
|
+
// list all geofences
|
|
67
|
+
listGeofences(options?: ListGeofenceOptions): Promise<ListGeofenceResults>;
|
|
68
|
+
|
|
69
|
+
// Delete geofences
|
|
70
|
+
deleteGeofences(
|
|
71
|
+
geofenceIds: string[],
|
|
72
|
+
options?: GeofenceOptions
|
|
73
|
+
): Promise<DeleteGeofencesResults>;
|
|
44
74
|
}
|