@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
|
@@ -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,
|
|
@@ -25,8 +26,23 @@ import {
|
|
|
25
26
|
SearchPlaceIndexForSuggestionsCommandInput,
|
|
26
27
|
SearchPlaceIndexForPositionCommand,
|
|
27
28
|
SearchPlaceIndexForPositionCommandInput,
|
|
29
|
+
BatchPutGeofenceCommand,
|
|
30
|
+
BatchPutGeofenceCommandInput,
|
|
31
|
+
BatchPutGeofenceRequestEntry,
|
|
32
|
+
BatchPutGeofenceCommandOutput,
|
|
33
|
+
GetGeofenceCommand,
|
|
34
|
+
GetGeofenceCommandInput,
|
|
35
|
+
GetGeofenceCommandOutput,
|
|
36
|
+
ListGeofencesCommand,
|
|
37
|
+
ListGeofencesCommandInput,
|
|
38
|
+
ListGeofencesCommandOutput,
|
|
39
|
+
BatchDeleteGeofenceCommand,
|
|
40
|
+
BatchDeleteGeofenceCommandInput,
|
|
41
|
+
BatchDeleteGeofenceCommandOutput,
|
|
28
42
|
} from '@aws-sdk/client-location';
|
|
29
43
|
|
|
44
|
+
import { validateGeofenceId, validateGeofencesInput } from '../util';
|
|
45
|
+
|
|
30
46
|
import {
|
|
31
47
|
GeoConfig,
|
|
32
48
|
SearchByTextOptions,
|
|
@@ -36,6 +52,15 @@ import {
|
|
|
36
52
|
AmazonLocationServiceMapStyle,
|
|
37
53
|
Coordinates,
|
|
38
54
|
SearchForSuggestionsResults,
|
|
55
|
+
GeofenceInput,
|
|
56
|
+
AmazonLocationServiceGeofenceOptions,
|
|
57
|
+
AmazonLocationServiceListGeofenceOptions,
|
|
58
|
+
ListGeofenceResults,
|
|
59
|
+
AmazonLocationServiceGeofenceStatus,
|
|
60
|
+
SaveGeofencesResults,
|
|
61
|
+
AmazonLocationServiceGeofence,
|
|
62
|
+
GeofencePolygon,
|
|
63
|
+
AmazonLocationServiceDeleteGeofencesResults,
|
|
39
64
|
} from '../types';
|
|
40
65
|
|
|
41
66
|
const logger = new Logger('AmazonLocationServiceProvider');
|
|
@@ -333,6 +358,331 @@ export class AmazonLocationServiceProvider implements GeoProvider {
|
|
|
333
358
|
return results;
|
|
334
359
|
}
|
|
335
360
|
|
|
361
|
+
/**
|
|
362
|
+
* Create geofences inside of a geofence collection
|
|
363
|
+
* @param geofences - Array of geofence objects to create
|
|
364
|
+
* @param options? - Optional parameters for creating geofences
|
|
365
|
+
* @returns {Promise<AmazonLocationServiceSaveGeofencesResults>} - Promise that resolves to an object with:
|
|
366
|
+
* successes: list of geofences successfully created
|
|
367
|
+
* errors: list of geofences that failed to create
|
|
368
|
+
*/
|
|
369
|
+
public async saveGeofences(
|
|
370
|
+
geofences: GeofenceInput[],
|
|
371
|
+
options?: AmazonLocationServiceGeofenceOptions
|
|
372
|
+
): Promise<SaveGeofencesResults> {
|
|
373
|
+
const credentialsOK = await this._ensureCredentials();
|
|
374
|
+
if (!credentialsOK) {
|
|
375
|
+
throw new Error('No credentials');
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
// Verify geofence collection exists in aws-config.js
|
|
379
|
+
try {
|
|
380
|
+
this._verifyGeofenceCollections(options?.collectionName);
|
|
381
|
+
} catch (error) {
|
|
382
|
+
logger.debug(error);
|
|
383
|
+
throw error;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
validateGeofencesInput(geofences);
|
|
387
|
+
|
|
388
|
+
// Convert geofences to PascalCase for Amazon Location Service format
|
|
389
|
+
const PascalGeofences: BatchPutGeofenceRequestEntry[] = geofences.map(
|
|
390
|
+
({ geofenceId, geometry: { polygon } }) => {
|
|
391
|
+
return {
|
|
392
|
+
GeofenceId: geofenceId,
|
|
393
|
+
Geometry: {
|
|
394
|
+
Polygon: polygon,
|
|
395
|
+
},
|
|
396
|
+
};
|
|
397
|
+
}
|
|
398
|
+
);
|
|
399
|
+
const results: SaveGeofencesResults = {
|
|
400
|
+
successes: [],
|
|
401
|
+
errors: [],
|
|
402
|
+
};
|
|
403
|
+
|
|
404
|
+
const batches = [];
|
|
405
|
+
|
|
406
|
+
while (PascalGeofences.length > 0) {
|
|
407
|
+
// Splice off 10 geofences from input clone due to Amazon Location Service API limit
|
|
408
|
+
batches.push(PascalGeofences.splice(0, 10));
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
await Promise.all(
|
|
412
|
+
batches.map(async batch => {
|
|
413
|
+
// for (const batch of batches) {
|
|
414
|
+
// Make API call for the 10 geofences
|
|
415
|
+
let response: BatchPutGeofenceCommandOutput;
|
|
416
|
+
try {
|
|
417
|
+
response = await this._AmazonLocationServiceBatchPutGeofenceCall(
|
|
418
|
+
batch,
|
|
419
|
+
options?.collectionName || this._config.geofenceCollections.default
|
|
420
|
+
);
|
|
421
|
+
} catch (error) {
|
|
422
|
+
// If the API call fails, add the geofences to the errors array and move to next batch
|
|
423
|
+
batch.forEach(geofence => {
|
|
424
|
+
results.errors.push({
|
|
425
|
+
geofenceId: geofence.GeofenceId,
|
|
426
|
+
error: {
|
|
427
|
+
code: 'APIConnectionError',
|
|
428
|
+
message: error.message,
|
|
429
|
+
},
|
|
430
|
+
});
|
|
431
|
+
});
|
|
432
|
+
return;
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
// Push all successes to results
|
|
436
|
+
response.Successes.forEach(success => {
|
|
437
|
+
const { GeofenceId, CreateTime, UpdateTime } = success;
|
|
438
|
+
results.successes.push({
|
|
439
|
+
geofenceId: GeofenceId,
|
|
440
|
+
createTime: CreateTime,
|
|
441
|
+
updateTime: UpdateTime,
|
|
442
|
+
});
|
|
443
|
+
});
|
|
444
|
+
|
|
445
|
+
// Push all errors to results
|
|
446
|
+
response.Errors.forEach(error => {
|
|
447
|
+
const {
|
|
448
|
+
Error: { Code, Message },
|
|
449
|
+
GeofenceId,
|
|
450
|
+
} = error;
|
|
451
|
+
results.errors.push({
|
|
452
|
+
error: {
|
|
453
|
+
code: Code,
|
|
454
|
+
message: Message,
|
|
455
|
+
},
|
|
456
|
+
geofenceId: GeofenceId,
|
|
457
|
+
});
|
|
458
|
+
});
|
|
459
|
+
})
|
|
460
|
+
);
|
|
461
|
+
|
|
462
|
+
return results;
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
/**
|
|
466
|
+
* Get geofence from a geofence collection
|
|
467
|
+
* @param geofenceId:string
|
|
468
|
+
* @param options?: Optional parameters for getGeofence
|
|
469
|
+
* @returns {Promise<AmazonLocationServiceGeofence>} - Promise that resolves to a geofence object
|
|
470
|
+
*/
|
|
471
|
+
public async getGeofence(
|
|
472
|
+
geofenceId: string,
|
|
473
|
+
options?: AmazonLocationServiceGeofenceOptions
|
|
474
|
+
): Promise<AmazonLocationServiceGeofence> {
|
|
475
|
+
const credentialsOK = await this._ensureCredentials();
|
|
476
|
+
if (!credentialsOK) {
|
|
477
|
+
throw new Error('No credentials');
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
// Verify geofence collection exists in aws-config.js
|
|
481
|
+
try {
|
|
482
|
+
this._verifyGeofenceCollections(options?.collectionName);
|
|
483
|
+
} catch (error) {
|
|
484
|
+
logger.debug(error);
|
|
485
|
+
throw error;
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
validateGeofenceId(geofenceId);
|
|
489
|
+
|
|
490
|
+
// Create Amazon Location Service Client
|
|
491
|
+
const client = new LocationClient({
|
|
492
|
+
credentials: this._config.credentials,
|
|
493
|
+
region: this._config.region,
|
|
494
|
+
customUserAgent: getAmplifyUserAgent(),
|
|
495
|
+
});
|
|
496
|
+
|
|
497
|
+
// Create Amazon Location Service command
|
|
498
|
+
const commandInput: GetGeofenceCommandInput = {
|
|
499
|
+
GeofenceId: geofenceId,
|
|
500
|
+
CollectionName:
|
|
501
|
+
options?.collectionName || this._config.geofenceCollections.default,
|
|
502
|
+
};
|
|
503
|
+
const command = new GetGeofenceCommand(commandInput);
|
|
504
|
+
|
|
505
|
+
// Make API call
|
|
506
|
+
let response: GetGeofenceCommandOutput;
|
|
507
|
+
try {
|
|
508
|
+
response = await client.send(command);
|
|
509
|
+
} catch (error) {
|
|
510
|
+
logger.debug(error);
|
|
511
|
+
throw error;
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
// Convert response to camelCase for return
|
|
515
|
+
const { GeofenceId, CreateTime, UpdateTime, Status, Geometry } = response;
|
|
516
|
+
const geofence: AmazonLocationServiceGeofence = {
|
|
517
|
+
createTime: CreateTime,
|
|
518
|
+
geofenceId: GeofenceId,
|
|
519
|
+
geometry: {
|
|
520
|
+
polygon: Geometry.Polygon as GeofencePolygon,
|
|
521
|
+
},
|
|
522
|
+
status: Status as AmazonLocationServiceGeofenceStatus,
|
|
523
|
+
updateTime: UpdateTime,
|
|
524
|
+
};
|
|
525
|
+
|
|
526
|
+
return geofence;
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
/**
|
|
530
|
+
* List geofences from a geofence collection
|
|
531
|
+
* @param options?: ListGeofenceOptions
|
|
532
|
+
* @returns {Promise<ListGeofencesResults>} - Promise that resolves to an object with:
|
|
533
|
+
* entries: list of geofences - 100 geofences are listed per page
|
|
534
|
+
* nextToken: token for next page of geofences
|
|
535
|
+
*/
|
|
536
|
+
public async listGeofences(
|
|
537
|
+
options?: AmazonLocationServiceListGeofenceOptions
|
|
538
|
+
): Promise<ListGeofenceResults> {
|
|
539
|
+
const credentialsOK = await this._ensureCredentials();
|
|
540
|
+
if (!credentialsOK) {
|
|
541
|
+
throw new Error('No credentials');
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
// Verify geofence collection exists in aws-config.js
|
|
545
|
+
try {
|
|
546
|
+
this._verifyGeofenceCollections(options?.collectionName);
|
|
547
|
+
} catch (error) {
|
|
548
|
+
logger.debug(error);
|
|
549
|
+
throw error;
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
// Create Amazon Location Service Client
|
|
553
|
+
const client = new LocationClient({
|
|
554
|
+
credentials: this._config.credentials,
|
|
555
|
+
region: this._config.region,
|
|
556
|
+
customUserAgent: getAmplifyUserAgent(),
|
|
557
|
+
});
|
|
558
|
+
|
|
559
|
+
// Create Amazon Location Service input
|
|
560
|
+
const listGeofencesInput: ListGeofencesCommandInput = {
|
|
561
|
+
NextToken: options?.nextToken,
|
|
562
|
+
CollectionName:
|
|
563
|
+
options?.collectionName || this._config.geofenceCollections.default,
|
|
564
|
+
};
|
|
565
|
+
|
|
566
|
+
// Create Amazon Location Service command
|
|
567
|
+
const command: ListGeofencesCommand = new ListGeofencesCommand(
|
|
568
|
+
listGeofencesInput
|
|
569
|
+
);
|
|
570
|
+
|
|
571
|
+
// Make API call
|
|
572
|
+
let response: ListGeofencesCommandOutput;
|
|
573
|
+
try {
|
|
574
|
+
response = await client.send(command);
|
|
575
|
+
} catch (error) {
|
|
576
|
+
logger.debug(error);
|
|
577
|
+
throw error;
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
// Convert response to camelCase for return
|
|
581
|
+
const { NextToken, Entries } = response;
|
|
582
|
+
|
|
583
|
+
const results: ListGeofenceResults = {
|
|
584
|
+
entries: Entries.map(
|
|
585
|
+
({
|
|
586
|
+
GeofenceId,
|
|
587
|
+
CreateTime,
|
|
588
|
+
UpdateTime,
|
|
589
|
+
Status,
|
|
590
|
+
Geometry: { Polygon },
|
|
591
|
+
}) => {
|
|
592
|
+
return {
|
|
593
|
+
geofenceId: GeofenceId,
|
|
594
|
+
createTime: CreateTime,
|
|
595
|
+
updateTime: UpdateTime,
|
|
596
|
+
status: Status,
|
|
597
|
+
geometry: {
|
|
598
|
+
polygon: Polygon as GeofencePolygon,
|
|
599
|
+
},
|
|
600
|
+
};
|
|
601
|
+
}
|
|
602
|
+
),
|
|
603
|
+
nextToken: NextToken,
|
|
604
|
+
};
|
|
605
|
+
|
|
606
|
+
return results;
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
/**
|
|
610
|
+
* Delete geofences from a geofence collection
|
|
611
|
+
* @param geofenceIds: string|string[]
|
|
612
|
+
* @param options?: GeofenceOptions
|
|
613
|
+
* @returns {Promise<DeleteGeofencesResults>} - Promise that resolves to an object with:
|
|
614
|
+
* successes: list of geofences successfully deleted
|
|
615
|
+
* errors: list of geofences that failed to delete
|
|
616
|
+
*/
|
|
617
|
+
public async deleteGeofences(
|
|
618
|
+
geofenceIds: string[],
|
|
619
|
+
options?: AmazonLocationServiceGeofenceOptions
|
|
620
|
+
): Promise<AmazonLocationServiceDeleteGeofencesResults> {
|
|
621
|
+
const credentialsOK = await this._ensureCredentials();
|
|
622
|
+
if (!credentialsOK) {
|
|
623
|
+
throw new Error('No credentials');
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
this._verifyGeofenceCollections(options?.collectionName);
|
|
627
|
+
|
|
628
|
+
// Validate all geofenceIds are valid
|
|
629
|
+
const badGeofenceIds = geofenceIds.filter(geofenceId => {
|
|
630
|
+
try {
|
|
631
|
+
validateGeofenceId(geofenceId);
|
|
632
|
+
} catch (error) {
|
|
633
|
+
return true;
|
|
634
|
+
}
|
|
635
|
+
});
|
|
636
|
+
if (badGeofenceIds.length > 0) {
|
|
637
|
+
throw new Error(`Invalid geofence ids: ${badGeofenceIds.join(', ')}`);
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
const results: AmazonLocationServiceDeleteGeofencesResults = {
|
|
641
|
+
successes: [],
|
|
642
|
+
errors: [],
|
|
643
|
+
};
|
|
644
|
+
|
|
645
|
+
const batches = [];
|
|
646
|
+
|
|
647
|
+
let count = 0;
|
|
648
|
+
while (count < geofenceIds.length) {
|
|
649
|
+
batches.push(geofenceIds.slice(count, (count += 10)));
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
await Promise.all(
|
|
653
|
+
batches.map(async batch => {
|
|
654
|
+
let response;
|
|
655
|
+
try {
|
|
656
|
+
response = await this._AmazonLocationServiceBatchDeleteGeofenceCall(
|
|
657
|
+
batch,
|
|
658
|
+
options?.collectionName || this._config.geofenceCollections.default
|
|
659
|
+
);
|
|
660
|
+
} catch (error) {
|
|
661
|
+
// If the API call fails, add the geofences to the errors array and move to next batch
|
|
662
|
+
batch.forEach(geofenceId => {
|
|
663
|
+
const errorObject = {
|
|
664
|
+
geofenceId,
|
|
665
|
+
error: {
|
|
666
|
+
code: error.message,
|
|
667
|
+
message: error.message,
|
|
668
|
+
},
|
|
669
|
+
};
|
|
670
|
+
results.errors.push(errorObject);
|
|
671
|
+
});
|
|
672
|
+
return;
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
const badGeofenceIds = response.Errors.map(
|
|
676
|
+
({ geofenceId }) => geofenceId
|
|
677
|
+
);
|
|
678
|
+
results.successes.push(
|
|
679
|
+
...batch.filter(Id => !badGeofenceIds.includes(Id))
|
|
680
|
+
);
|
|
681
|
+
})
|
|
682
|
+
);
|
|
683
|
+
return results;
|
|
684
|
+
}
|
|
685
|
+
|
|
336
686
|
/**
|
|
337
687
|
* @private
|
|
338
688
|
*/
|
|
@@ -345,7 +695,7 @@ export class AmazonLocationServiceProvider implements GeoProvider {
|
|
|
345
695
|
this._config.credentials = cred;
|
|
346
696
|
return true;
|
|
347
697
|
} catch (error) {
|
|
348
|
-
logger.
|
|
698
|
+
logger.debug('Ensure credentials error. Credentials are:', error);
|
|
349
699
|
return false;
|
|
350
700
|
}
|
|
351
701
|
}
|
|
@@ -353,14 +703,14 @@ export class AmazonLocationServiceProvider implements GeoProvider {
|
|
|
353
703
|
private _verifyMapResources() {
|
|
354
704
|
if (!this._config.maps) {
|
|
355
705
|
const errorString =
|
|
356
|
-
"No map resources found in amplify config, run 'amplify add geo' to create
|
|
357
|
-
logger.
|
|
706
|
+
"No map resources found in amplify config, run 'amplify add geo' to create one and run `amplify push` after";
|
|
707
|
+
logger.debug(errorString);
|
|
358
708
|
throw new Error(errorString);
|
|
359
709
|
}
|
|
360
710
|
if (!this._config.maps.default) {
|
|
361
711
|
const errorString =
|
|
362
712
|
"No default map resource found in amplify config, run 'amplify add geo' to create one and run `amplify push` after";
|
|
363
|
-
logger.
|
|
713
|
+
logger.debug(errorString);
|
|
364
714
|
throw new Error(errorString);
|
|
365
715
|
}
|
|
366
716
|
}
|
|
@@ -371,9 +721,76 @@ export class AmazonLocationServiceProvider implements GeoProvider {
|
|
|
371
721
|
!optionalSearchIndex
|
|
372
722
|
) {
|
|
373
723
|
const errorString =
|
|
374
|
-
'No Search Index found, please run `amplify add geo` to
|
|
375
|
-
logger.
|
|
724
|
+
'No Search Index found in amplify config, please run `amplify add geo` to create one and run `amplify push` after.';
|
|
725
|
+
logger.debug(errorString);
|
|
726
|
+
throw new Error(errorString);
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
private _verifyGeofenceCollections(optionalGeofenceCollectionName?: string) {
|
|
731
|
+
if (
|
|
732
|
+
(!this._config.geofenceCollections ||
|
|
733
|
+
!this._config.geofenceCollections.default) &&
|
|
734
|
+
!optionalGeofenceCollectionName
|
|
735
|
+
) {
|
|
736
|
+
const errorString =
|
|
737
|
+
'No Geofence Collections found, please run `amplify add geo` to create one and run `amplify push` after.';
|
|
738
|
+
logger.debug(errorString);
|
|
376
739
|
throw new Error(errorString);
|
|
377
740
|
}
|
|
378
741
|
}
|
|
742
|
+
|
|
743
|
+
private async _AmazonLocationServiceBatchPutGeofenceCall(
|
|
744
|
+
PascalGeofences: BatchPutGeofenceRequestEntry[],
|
|
745
|
+
collectionName?: string
|
|
746
|
+
) {
|
|
747
|
+
// Create the BatchPutGeofence input
|
|
748
|
+
const geofenceInput: BatchPutGeofenceCommandInput = {
|
|
749
|
+
Entries: PascalGeofences,
|
|
750
|
+
CollectionName:
|
|
751
|
+
collectionName || this._config.geofenceCollections.default,
|
|
752
|
+
};
|
|
753
|
+
|
|
754
|
+
const client = new LocationClient({
|
|
755
|
+
credentials: this._config.credentials,
|
|
756
|
+
region: this._config.region,
|
|
757
|
+
customUserAgent: getAmplifyUserAgent(),
|
|
758
|
+
});
|
|
759
|
+
const command = new BatchPutGeofenceCommand(geofenceInput);
|
|
760
|
+
|
|
761
|
+
let response: BatchPutGeofenceCommandOutput;
|
|
762
|
+
try {
|
|
763
|
+
response = await client.send(command);
|
|
764
|
+
} catch (error) {
|
|
765
|
+
throw error;
|
|
766
|
+
}
|
|
767
|
+
return response;
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
private async _AmazonLocationServiceBatchDeleteGeofenceCall(
|
|
771
|
+
geofenceIds: string[],
|
|
772
|
+
collectionName?: string
|
|
773
|
+
): Promise<BatchDeleteGeofenceCommandOutput> {
|
|
774
|
+
// Create the BatchDeleteGeofence input
|
|
775
|
+
const deleteGeofencesInput: BatchDeleteGeofenceCommandInput = {
|
|
776
|
+
GeofenceIds: geofenceIds,
|
|
777
|
+
CollectionName:
|
|
778
|
+
collectionName || this._config.geofenceCollections.default,
|
|
779
|
+
};
|
|
780
|
+
|
|
781
|
+
const client = new LocationClient({
|
|
782
|
+
credentials: this._config.credentials,
|
|
783
|
+
region: this._config.region,
|
|
784
|
+
customUserAgent: getAmplifyUserAgent(),
|
|
785
|
+
});
|
|
786
|
+
const command = new BatchDeleteGeofenceCommand(deleteGeofencesInput);
|
|
787
|
+
|
|
788
|
+
let response: BatchDeleteGeofenceCommandOutput;
|
|
789
|
+
try {
|
|
790
|
+
response = await client.send(command);
|
|
791
|
+
} catch (error) {
|
|
792
|
+
throw error;
|
|
793
|
+
}
|
|
794
|
+
return response;
|
|
795
|
+
}
|
|
379
796
|
}
|
|
@@ -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 searchByCoodinates
|
|
76
81
|
export type SearchByCoordinatesOptions = {
|
|
77
82
|
maxResults?: number;
|
|
78
83
|
searchIndexName?: string;
|
|
@@ -100,3 +105,68 @@ export interface Place {
|
|
|
100
105
|
|
|
101
106
|
// Return type for searchForSuggestions
|
|
102
107
|
export type SearchForSuggestionsResults = string[];
|
|
108
|
+
// Array of 4 or more coordinates, where the first and last coordinate are the same to form a closed boundary
|
|
109
|
+
export type LinearRing = Coordinates[];
|
|
110
|
+
|
|
111
|
+
// An array of one linear ring
|
|
112
|
+
export type GeofencePolygon = LinearRing[];
|
|
113
|
+
|
|
114
|
+
// Geometry object for Polygon
|
|
115
|
+
export type PolygonGeometry = {
|
|
116
|
+
polygon: GeofencePolygon;
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
// Geofence object used as input for saveGeofences
|
|
120
|
+
export type GeofenceInput = {
|
|
121
|
+
geofenceId: string;
|
|
122
|
+
geometry: PolygonGeometry;
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
// Options object for saveGeofences
|
|
126
|
+
export type GeofenceOptions = {
|
|
127
|
+
providerName?: string;
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
// Error type for errors related to Geofence API calls
|
|
131
|
+
export type GeofenceError = {
|
|
132
|
+
error: {
|
|
133
|
+
code: string;
|
|
134
|
+
message: string;
|
|
135
|
+
};
|
|
136
|
+
geofenceId: string;
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
// Base geofence object
|
|
140
|
+
type GeofenceBase = {
|
|
141
|
+
geofenceId: string;
|
|
142
|
+
createTime?: Date;
|
|
143
|
+
updateTime?: Date;
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
// Results object for getGeofence
|
|
147
|
+
export type Geofence = GeofenceBase & {
|
|
148
|
+
geometry: PolygonGeometry;
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
// Results object for saveGeofences
|
|
152
|
+
export type SaveGeofencesResults = {
|
|
153
|
+
successes: GeofenceBase[];
|
|
154
|
+
errors: GeofenceError[];
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
// Options object for listGeofence
|
|
158
|
+
export type ListGeofenceOptions = GeofenceOptions & {
|
|
159
|
+
nextToken?: string;
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
// Results options for listGeofence
|
|
163
|
+
export type ListGeofenceResults = {
|
|
164
|
+
entries: Geofence[];
|
|
165
|
+
nextToken: string;
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
// Results object for deleteGeofence
|
|
169
|
+
export type DeleteGeofencesResults = {
|
|
170
|
+
successes: string[];
|
|
171
|
+
errors: GeofenceError[];
|
|
172
|
+
};
|
package/src/types/Provider.ts
CHANGED
|
@@ -10,7 +10,6 @@
|
|
|
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,
|
|
@@ -18,6 +17,13 @@ import {
|
|
|
18
17
|
Coordinates,
|
|
19
18
|
Place,
|
|
20
19
|
MapStyle,
|
|
20
|
+
Geofence,
|
|
21
|
+
GeofenceInput,
|
|
22
|
+
GeofenceOptions,
|
|
23
|
+
ListGeofenceOptions,
|
|
24
|
+
ListGeofenceResults,
|
|
25
|
+
SaveGeofencesResults,
|
|
26
|
+
DeleteGeofencesResults,
|
|
21
27
|
} from './Geo';
|
|
22
28
|
|
|
23
29
|
export interface GeoProvider {
|
|
@@ -36,15 +42,39 @@ export interface GeoProvider {
|
|
|
36
42
|
// get the map resource listed as default
|
|
37
43
|
getDefaultMap(): MapStyle;
|
|
38
44
|
|
|
45
|
+
// search by a text string and return a list of places
|
|
39
46
|
searchByText(text: string, options?: SearchByTextOptions): Promise<Place[]>;
|
|
40
47
|
|
|
48
|
+
// search by coordinates and return a matching place
|
|
41
49
|
searchByCoordinates(
|
|
42
50
|
coordinates: Coordinates,
|
|
43
51
|
options?: SearchByCoordinatesOptions
|
|
44
52
|
): Promise<Place>;
|
|
45
53
|
|
|
54
|
+
// search for suggestions based on a text string
|
|
46
55
|
searchForSuggestions(
|
|
47
56
|
text: string,
|
|
48
57
|
options?: SearchByTextOptions
|
|
49
58
|
): Promise<SearchForSuggestionsResults>;
|
|
59
|
+
|
|
60
|
+
// create geofences
|
|
61
|
+
saveGeofences(
|
|
62
|
+
geofences: GeofenceInput[],
|
|
63
|
+
options?: GeofenceOptions
|
|
64
|
+
): Promise<SaveGeofencesResults>;
|
|
65
|
+
|
|
66
|
+
// get a single geofence
|
|
67
|
+
getGeofence(
|
|
68
|
+
geofenceId: string,
|
|
69
|
+
options?: ListGeofenceOptions
|
|
70
|
+
): Promise<Geofence>;
|
|
71
|
+
|
|
72
|
+
// list all geofences
|
|
73
|
+
listGeofences(options?: ListGeofenceOptions): Promise<ListGeofenceResults>;
|
|
74
|
+
|
|
75
|
+
// Delete geofences
|
|
76
|
+
deleteGeofences(
|
|
77
|
+
geofenceIds: string[],
|
|
78
|
+
options?: GeofenceOptions
|
|
79
|
+
): Promise<DeleteGeofencesResults>;
|
|
50
80
|
}
|