@aws-amplify/geo 3.0.21 → 3.0.22-unstable.1820354.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/dist/cjs/Geo.js +5 -6
- package/dist/cjs/Geo.js.map +1 -1
- package/dist/cjs/providers/location-service/AmazonLocationServiceProvider.js +22 -36
- package/dist/cjs/providers/location-service/AmazonLocationServiceProvider.js.map +1 -1
- package/dist/cjs/util.js +7 -7
- package/dist/cjs/util.js.map +1 -1
- package/dist/esm/Geo.d.ts +4 -4
- package/dist/esm/Geo.mjs +5 -6
- package/dist/esm/Geo.mjs.map +1 -1
- package/dist/esm/providers/location-service/AmazonLocationServiceProvider.d.ts +4 -4
- package/dist/esm/providers/location-service/AmazonLocationServiceProvider.mjs +22 -36
- package/dist/esm/providers/location-service/AmazonLocationServiceProvider.mjs.map +1 -1
- package/dist/esm/types/AmazonLocationServiceProvider.d.ts +1 -1
- package/dist/esm/types/Geo.d.ts +24 -24
- package/dist/esm/types/Provider.d.ts +1 -1
- package/dist/esm/util.d.ts +1 -1
- package/dist/esm/util.mjs +7 -7
- package/dist/esm/util.mjs.map +1 -1
- package/package.json +89 -88
- package/src/Geo.ts +16 -16
- package/src/providers/location-service/AmazonLocationServiceProvider.ts +69 -65
- package/src/types/AmazonLocationServiceProvider.ts +4 -4
- package/src/types/Geo.ts +24 -24
- package/src/types/Provider.ts +6 -6
- package/src/util.ts +10 -9
|
@@ -1,34 +1,33 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
import camelcaseKeys from 'camelcase-keys';
|
|
4
|
-
|
|
5
|
-
import { Amplify, fetchAuthSession, ConsoleLogger } from '@aws-amplify/core';
|
|
4
|
+
import { Amplify, ConsoleLogger, fetchAuthSession } from '@aws-amplify/core';
|
|
6
5
|
import { GeoAction } from '@aws-amplify/core/internals/utils';
|
|
7
6
|
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
SearchPlaceIndexForTextCommandInput,
|
|
12
|
-
SearchPlaceIndexForSuggestionsCommand,
|
|
13
|
-
SearchPlaceIndexForSuggestionsCommandInput,
|
|
14
|
-
SearchPlaceIndexForPositionCommand,
|
|
15
|
-
SearchPlaceIndexForPositionCommandInput,
|
|
7
|
+
BatchDeleteGeofenceCommand,
|
|
8
|
+
BatchDeleteGeofenceCommandInput,
|
|
9
|
+
BatchDeleteGeofenceCommandOutput,
|
|
16
10
|
BatchPutGeofenceCommand,
|
|
17
11
|
BatchPutGeofenceCommandInput,
|
|
18
|
-
BatchPutGeofenceRequestEntry,
|
|
19
12
|
BatchPutGeofenceCommandOutput,
|
|
20
|
-
|
|
21
|
-
GetPlaceCommandInput,
|
|
22
|
-
GetPlaceCommandOutput,
|
|
13
|
+
BatchPutGeofenceRequestEntry,
|
|
23
14
|
GetGeofenceCommand,
|
|
24
15
|
GetGeofenceCommandInput,
|
|
25
16
|
GetGeofenceCommandOutput,
|
|
17
|
+
GetPlaceCommand,
|
|
18
|
+
GetPlaceCommandInput,
|
|
19
|
+
GetPlaceCommandOutput,
|
|
26
20
|
ListGeofencesCommand,
|
|
27
21
|
ListGeofencesCommandInput,
|
|
28
22
|
ListGeofencesCommandOutput,
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
23
|
+
LocationClient,
|
|
24
|
+
Place as PlaceResult,
|
|
25
|
+
SearchPlaceIndexForPositionCommand,
|
|
26
|
+
SearchPlaceIndexForPositionCommandInput,
|
|
27
|
+
SearchPlaceIndexForSuggestionsCommand,
|
|
28
|
+
SearchPlaceIndexForSuggestionsCommandInput,
|
|
29
|
+
SearchPlaceIndexForTextCommand,
|
|
30
|
+
SearchPlaceIndexForTextCommandInput,
|
|
32
31
|
} from '@aws-sdk/client-location';
|
|
33
32
|
|
|
34
33
|
import {
|
|
@@ -37,28 +36,27 @@ import {
|
|
|
37
36
|
validateGeofenceId,
|
|
38
37
|
validateGeofencesInput,
|
|
39
38
|
} from '../../util';
|
|
40
|
-
|
|
41
39
|
import {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
40
|
+
AmazonLocationServiceBatchGeofenceErrorMessages,
|
|
41
|
+
AmazonLocationServiceDeleteGeofencesResults,
|
|
42
|
+
AmazonLocationServiceGeofence,
|
|
43
|
+
AmazonLocationServiceGeofenceOptions,
|
|
44
|
+
AmazonLocationServiceGeofenceStatus,
|
|
45
|
+
AmazonLocationServiceListGeofenceOptions,
|
|
47
46
|
AmazonLocationServiceMapStyle,
|
|
48
47
|
Coordinates,
|
|
49
|
-
|
|
48
|
+
GeoConfig,
|
|
49
|
+
GeoProvider,
|
|
50
50
|
GeofenceId,
|
|
51
51
|
GeofenceInput,
|
|
52
|
-
|
|
53
|
-
AmazonLocationServiceListGeofenceOptions,
|
|
52
|
+
GeofencePolygon,
|
|
54
53
|
ListGeofenceResults,
|
|
55
|
-
|
|
54
|
+
Place,
|
|
56
55
|
SaveGeofencesResults,
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
56
|
+
SearchByCoordinatesOptions,
|
|
57
|
+
SearchByTextOptions,
|
|
58
|
+
SearchForSuggestionsResults,
|
|
60
59
|
searchByPlaceIdOptions,
|
|
61
|
-
AmazonLocationServiceBatchGeofenceErrorMessages,
|
|
62
60
|
} from '../../types';
|
|
63
61
|
|
|
64
62
|
const logger = new ConsoleLogger('AmazonLocationServiceProvider');
|
|
@@ -78,7 +76,7 @@ export class AmazonLocationServiceProvider implements GeoProvider {
|
|
|
78
76
|
* @param {Object} config - Configuration object for Geo
|
|
79
77
|
*/
|
|
80
78
|
constructor(config?: GeoConfig) {
|
|
81
|
-
this._config = config
|
|
79
|
+
this._config = config || {};
|
|
82
80
|
logger.debug('Geo Options', this._config);
|
|
83
81
|
}
|
|
84
82
|
|
|
@@ -107,10 +105,10 @@ export class AmazonLocationServiceProvider implements GeoProvider {
|
|
|
107
105
|
|
|
108
106
|
const mapStyles: AmazonLocationServiceMapStyle[] = [];
|
|
109
107
|
const availableMaps = this._config.maps.items;
|
|
110
|
-
const region = this._config
|
|
108
|
+
const { region } = this._config;
|
|
111
109
|
|
|
112
110
|
for (const mapName in availableMaps) {
|
|
113
|
-
const style = availableMaps[mapName]
|
|
111
|
+
const { style } = availableMaps[mapName];
|
|
114
112
|
mapStyles.push({ mapName, style, region });
|
|
115
113
|
}
|
|
116
114
|
|
|
@@ -125,8 +123,8 @@ export class AmazonLocationServiceProvider implements GeoProvider {
|
|
|
125
123
|
this._verifyMapResources();
|
|
126
124
|
|
|
127
125
|
const mapName = this._config.maps.default;
|
|
128
|
-
const style = this._config.maps.items[mapName]
|
|
129
|
-
const region = this._config
|
|
126
|
+
const { style } = this._config.maps.items[mapName];
|
|
127
|
+
const { region } = this._config;
|
|
130
128
|
|
|
131
129
|
return { mapName, style, region };
|
|
132
130
|
}
|
|
@@ -306,7 +304,6 @@ export class AmazonLocationServiceProvider implements GeoProvider {
|
|
|
306
304
|
if (place) {
|
|
307
305
|
return camelcaseKeys(place, { deep: true }) as unknown as Place;
|
|
308
306
|
}
|
|
309
|
-
return;
|
|
310
307
|
}
|
|
311
308
|
|
|
312
309
|
/**
|
|
@@ -372,7 +369,7 @@ export class AmazonLocationServiceProvider implements GeoProvider {
|
|
|
372
369
|
* Create geofences inside of a geofence collection
|
|
373
370
|
* @param geofences Array of geofence objects to create
|
|
374
371
|
* @param options Optional parameters for creating geofences
|
|
375
|
-
* @returns
|
|
372
|
+
* @returns a promise that resolves to an object that conforms to {@link SaveGeofencesResults}:
|
|
376
373
|
* successes: list of geofences successfully created
|
|
377
374
|
* errors: list of geofences that failed to create
|
|
378
375
|
*/
|
|
@@ -443,14 +440,15 @@ export class AmazonLocationServiceProvider implements GeoProvider {
|
|
|
443
440
|
},
|
|
444
441
|
});
|
|
445
442
|
});
|
|
443
|
+
|
|
446
444
|
return;
|
|
447
445
|
}
|
|
448
446
|
|
|
449
447
|
// Push all successes to results
|
|
450
448
|
response.Successes?.forEach(success => {
|
|
451
|
-
const { GeofenceId, CreateTime, UpdateTime } = success;
|
|
449
|
+
const { GeofenceId: geofenceId, CreateTime, UpdateTime } = success;
|
|
452
450
|
results.successes.push({
|
|
453
|
-
geofenceId:
|
|
451
|
+
geofenceId: geofenceId!,
|
|
454
452
|
createTime: CreateTime,
|
|
455
453
|
updateTime: UpdateTime,
|
|
456
454
|
});
|
|
@@ -458,14 +456,14 @@ export class AmazonLocationServiceProvider implements GeoProvider {
|
|
|
458
456
|
|
|
459
457
|
// Push all errors to results
|
|
460
458
|
response.Errors?.forEach(error => {
|
|
461
|
-
const { Error, GeofenceId } = error;
|
|
459
|
+
const { Error, GeofenceId: geofenceId } = error;
|
|
462
460
|
const { Code, Message } = Error!;
|
|
463
461
|
results.errors.push({
|
|
464
462
|
error: {
|
|
465
463
|
code: Code!,
|
|
466
464
|
message: Message!,
|
|
467
465
|
},
|
|
468
|
-
geofenceId:
|
|
466
|
+
geofenceId: geofenceId!,
|
|
469
467
|
});
|
|
470
468
|
});
|
|
471
469
|
}),
|
|
@@ -524,10 +522,16 @@ export class AmazonLocationServiceProvider implements GeoProvider {
|
|
|
524
522
|
}
|
|
525
523
|
|
|
526
524
|
// Convert response to camelCase for return
|
|
527
|
-
const {
|
|
525
|
+
const {
|
|
526
|
+
GeofenceId: responseGeofenceId,
|
|
527
|
+
CreateTime,
|
|
528
|
+
UpdateTime,
|
|
529
|
+
Status,
|
|
530
|
+
Geometry,
|
|
531
|
+
} = response;
|
|
528
532
|
const geofence: AmazonLocationServiceGeofence = {
|
|
529
533
|
createTime: CreateTime,
|
|
530
|
-
geofenceId:
|
|
534
|
+
geofenceId: responseGeofenceId!,
|
|
531
535
|
geometry: {
|
|
532
536
|
polygon: Geometry!.Polygon as GeofencePolygon,
|
|
533
537
|
},
|
|
@@ -541,7 +545,7 @@ export class AmazonLocationServiceProvider implements GeoProvider {
|
|
|
541
545
|
/**
|
|
542
546
|
* List geofences from a geofence collection
|
|
543
547
|
* @param options ListGeofenceOptions
|
|
544
|
-
* @returns
|
|
548
|
+
* @returns a promise that resolves to an object that conforms to {@link ListGeofenceResults}:
|
|
545
549
|
* entries: list of geofences - 100 geofences are listed per page
|
|
546
550
|
* nextToken: token for next page of geofences
|
|
547
551
|
*/
|
|
@@ -594,9 +598,15 @@ export class AmazonLocationServiceProvider implements GeoProvider {
|
|
|
594
598
|
|
|
595
599
|
const results: ListGeofenceResults = {
|
|
596
600
|
entries: Entries!.map(
|
|
597
|
-
({
|
|
601
|
+
({
|
|
602
|
+
GeofenceId: geofenceId,
|
|
603
|
+
CreateTime,
|
|
604
|
+
UpdateTime,
|
|
605
|
+
Status,
|
|
606
|
+
Geometry,
|
|
607
|
+
}) => {
|
|
598
608
|
return {
|
|
599
|
-
geofenceId:
|
|
609
|
+
geofenceId: geofenceId!,
|
|
600
610
|
createTime: CreateTime,
|
|
601
611
|
updateTime: UpdateTime,
|
|
602
612
|
status: Status,
|
|
@@ -616,7 +626,7 @@ export class AmazonLocationServiceProvider implements GeoProvider {
|
|
|
616
626
|
* Delete geofences from a geofence collection
|
|
617
627
|
* @param geofenceIds string|string[]
|
|
618
628
|
* @param options GeofenceOptions
|
|
619
|
-
* @returns
|
|
629
|
+
* @returns a promise that resolves to an object that conforms to {@link AmazonLocationServiceDeleteGeofencesResults}:
|
|
620
630
|
* successes: list of geofences successfully deleted
|
|
621
631
|
* errors: list of geofences that failed to delete
|
|
622
632
|
*/
|
|
@@ -642,6 +652,8 @@ export class AmazonLocationServiceProvider implements GeoProvider {
|
|
|
642
652
|
} catch (error) {
|
|
643
653
|
return true;
|
|
644
654
|
}
|
|
655
|
+
|
|
656
|
+
return false;
|
|
645
657
|
});
|
|
646
658
|
if (badGeofenceIds.length > 0) {
|
|
647
659
|
throw new Error(`Invalid geofence ids: ${badGeofenceIds.join(', ')}`);
|
|
@@ -681,17 +693,19 @@ export class AmazonLocationServiceProvider implements GeoProvider {
|
|
|
681
693
|
};
|
|
682
694
|
results.errors.push(errorObject);
|
|
683
695
|
});
|
|
696
|
+
|
|
684
697
|
return;
|
|
685
698
|
}
|
|
686
699
|
|
|
687
|
-
const
|
|
700
|
+
const targetBadGeofenceIds = response.Errors.map(
|
|
688
701
|
({ geofenceId }) => geofenceId,
|
|
689
702
|
);
|
|
690
703
|
results.successes.push(
|
|
691
|
-
...batch.filter(Id => !
|
|
704
|
+
...batch.filter(Id => !targetBadGeofenceIds.includes(Id)),
|
|
692
705
|
);
|
|
693
706
|
}),
|
|
694
707
|
);
|
|
708
|
+
|
|
695
709
|
return results;
|
|
696
710
|
}
|
|
697
711
|
|
|
@@ -700,16 +714,18 @@ export class AmazonLocationServiceProvider implements GeoProvider {
|
|
|
700
714
|
*/
|
|
701
715
|
private async _ensureCredentials(): Promise<boolean> {
|
|
702
716
|
try {
|
|
703
|
-
const credentials =
|
|
717
|
+
const { credentials } = await fetchAuthSession();
|
|
704
718
|
if (!credentials) return false;
|
|
705
719
|
logger.debug(
|
|
706
720
|
'Set credentials for storage. Credentials are:',
|
|
707
721
|
credentials,
|
|
708
722
|
);
|
|
709
723
|
this._credentials = credentials;
|
|
724
|
+
|
|
710
725
|
return true;
|
|
711
726
|
} catch (error) {
|
|
712
727
|
logger.debug('Ensure credentials error. Credentials are:', error);
|
|
728
|
+
|
|
713
729
|
return false;
|
|
714
730
|
}
|
|
715
731
|
}
|
|
@@ -785,13 +801,7 @@ export class AmazonLocationServiceProvider implements GeoProvider {
|
|
|
785
801
|
});
|
|
786
802
|
const command = new BatchPutGeofenceCommand(geofenceInput);
|
|
787
803
|
|
|
788
|
-
|
|
789
|
-
try {
|
|
790
|
-
response = await client.send(command);
|
|
791
|
-
} catch (error) {
|
|
792
|
-
throw error;
|
|
793
|
-
}
|
|
794
|
-
return response;
|
|
804
|
+
return client.send(command);
|
|
795
805
|
}
|
|
796
806
|
|
|
797
807
|
private async _AmazonLocationServiceBatchDeleteGeofenceCall(
|
|
@@ -812,12 +822,6 @@ export class AmazonLocationServiceProvider implements GeoProvider {
|
|
|
812
822
|
});
|
|
813
823
|
const command = new BatchDeleteGeofenceCommand(deleteGeofencesInput);
|
|
814
824
|
|
|
815
|
-
|
|
816
|
-
try {
|
|
817
|
-
response = await client.send(command);
|
|
818
|
-
} catch (error) {
|
|
819
|
-
throw error;
|
|
820
|
-
}
|
|
821
|
-
return response;
|
|
825
|
+
return client.send(command);
|
|
822
826
|
}
|
|
823
827
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
import {
|
|
4
|
-
MapStyle,
|
|
5
|
-
GeofenceOptions,
|
|
6
|
-
ListGeofenceOptions,
|
|
7
|
-
Geofence,
|
|
8
4
|
DeleteGeofencesResults,
|
|
5
|
+
Geofence,
|
|
9
6
|
GeofenceError,
|
|
7
|
+
GeofenceOptions,
|
|
8
|
+
ListGeofenceOptions,
|
|
9
|
+
MapStyle,
|
|
10
10
|
} from './Geo';
|
|
11
11
|
|
|
12
12
|
// Maps
|
package/src/types/Geo.ts
CHANGED
|
@@ -53,20 +53,20 @@ export type SearchByTextOptions =
|
|
|
53
53
|
| SearchByTextOptionsWithSearchAreaConstraints;
|
|
54
54
|
|
|
55
55
|
// Options object for searchByCoordinates
|
|
56
|
-
export
|
|
56
|
+
export interface SearchByCoordinatesOptions {
|
|
57
57
|
maxResults?: number;
|
|
58
58
|
searchIndexName?: string;
|
|
59
59
|
providerName?: string;
|
|
60
|
-
}
|
|
60
|
+
}
|
|
61
61
|
|
|
62
|
-
export
|
|
62
|
+
export interface searchByPlaceIdOptions {
|
|
63
63
|
searchIndexName?: string;
|
|
64
|
-
}
|
|
64
|
+
}
|
|
65
65
|
|
|
66
66
|
// Geometry object for Place points
|
|
67
|
-
export
|
|
67
|
+
export interface PlaceGeometry {
|
|
68
68
|
point: Coordinates;
|
|
69
|
-
}
|
|
69
|
+
}
|
|
70
70
|
|
|
71
71
|
// Place object with locality information
|
|
72
72
|
export interface Place {
|
|
@@ -88,38 +88,38 @@ export type LinearRing = Coordinates[];
|
|
|
88
88
|
export type GeofencePolygon = LinearRing[];
|
|
89
89
|
|
|
90
90
|
// Geometry object for Polygon
|
|
91
|
-
export
|
|
91
|
+
export interface PolygonGeometry {
|
|
92
92
|
polygon: GeofencePolygon;
|
|
93
|
-
}
|
|
93
|
+
}
|
|
94
94
|
|
|
95
95
|
export type GeofenceId = string;
|
|
96
96
|
|
|
97
97
|
// Geofence object used as input for saveGeofences
|
|
98
|
-
export
|
|
98
|
+
export interface GeofenceInput {
|
|
99
99
|
geofenceId: GeofenceId;
|
|
100
100
|
geometry: PolygonGeometry;
|
|
101
|
-
}
|
|
101
|
+
}
|
|
102
102
|
|
|
103
103
|
// Options object for saveGeofences
|
|
104
|
-
export
|
|
104
|
+
export interface GeofenceOptions {
|
|
105
105
|
providerName?: string;
|
|
106
|
-
}
|
|
106
|
+
}
|
|
107
107
|
|
|
108
108
|
// Error type for errors related to Geofence API calls
|
|
109
|
-
export
|
|
109
|
+
export interface GeofenceError {
|
|
110
110
|
error: {
|
|
111
111
|
code: string;
|
|
112
112
|
message: string;
|
|
113
113
|
};
|
|
114
114
|
geofenceId: GeofenceId;
|
|
115
|
-
}
|
|
115
|
+
}
|
|
116
116
|
|
|
117
117
|
// Base geofence object
|
|
118
|
-
|
|
118
|
+
interface GeofenceBase {
|
|
119
119
|
geofenceId: GeofenceId;
|
|
120
120
|
createTime?: Date;
|
|
121
121
|
updateTime?: Date;
|
|
122
|
-
}
|
|
122
|
+
}
|
|
123
123
|
|
|
124
124
|
// Results object for getGeofence
|
|
125
125
|
export type Geofence = GeofenceBase & {
|
|
@@ -127,10 +127,10 @@ export type Geofence = GeofenceBase & {
|
|
|
127
127
|
};
|
|
128
128
|
|
|
129
129
|
// Results object for saveGeofences
|
|
130
|
-
export
|
|
130
|
+
export interface SaveGeofencesResults {
|
|
131
131
|
successes: GeofenceBase[];
|
|
132
132
|
errors: GeofenceError[];
|
|
133
|
-
}
|
|
133
|
+
}
|
|
134
134
|
|
|
135
135
|
// Options object for listGeofence
|
|
136
136
|
export type ListGeofenceOptions = GeofenceOptions & {
|
|
@@ -138,21 +138,21 @@ export type ListGeofenceOptions = GeofenceOptions & {
|
|
|
138
138
|
};
|
|
139
139
|
|
|
140
140
|
// Results options for listGeofence
|
|
141
|
-
export
|
|
141
|
+
export interface ListGeofenceResults {
|
|
142
142
|
entries: Geofence[];
|
|
143
143
|
nextToken: string | undefined;
|
|
144
|
-
}
|
|
144
|
+
}
|
|
145
145
|
|
|
146
146
|
// Results object for deleteGeofence
|
|
147
|
-
export
|
|
147
|
+
export interface DeleteGeofencesResults {
|
|
148
148
|
successes: GeofenceId[];
|
|
149
149
|
errors: GeofenceError[];
|
|
150
|
-
}
|
|
150
|
+
}
|
|
151
151
|
|
|
152
152
|
// Return type for searchForSuggestions
|
|
153
153
|
export type SearchForSuggestionsResults = SearchForSuggestionsResult[];
|
|
154
154
|
|
|
155
|
-
export
|
|
155
|
+
export interface SearchForSuggestionsResult {
|
|
156
156
|
text: string;
|
|
157
157
|
placeId?: string;
|
|
158
|
-
}
|
|
158
|
+
}
|
package/src/types/Provider.ts
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
import {
|
|
4
|
-
SearchByTextOptions,
|
|
5
|
-
SearchByCoordinatesOptions,
|
|
6
|
-
SearchForSuggestionsResults,
|
|
7
4
|
Coordinates,
|
|
8
|
-
|
|
9
|
-
MapStyle,
|
|
5
|
+
DeleteGeofencesResults,
|
|
10
6
|
Geofence,
|
|
11
7
|
GeofenceId,
|
|
12
8
|
GeofenceInput,
|
|
13
9
|
GeofenceOptions,
|
|
14
10
|
ListGeofenceOptions,
|
|
15
11
|
ListGeofenceResults,
|
|
12
|
+
MapStyle,
|
|
13
|
+
Place,
|
|
16
14
|
SaveGeofencesResults,
|
|
17
|
-
|
|
15
|
+
SearchByCoordinatesOptions,
|
|
16
|
+
SearchByTextOptions,
|
|
17
|
+
SearchForSuggestionsResults,
|
|
18
18
|
searchByPlaceIdOptions,
|
|
19
19
|
} from './Geo';
|
|
20
20
|
|
package/src/util.ts
CHANGED
|
@@ -10,21 +10,21 @@ import {
|
|
|
10
10
|
import { UserAgent } from '@aws-sdk/types';
|
|
11
11
|
|
|
12
12
|
import {
|
|
13
|
-
Longitude,
|
|
14
|
-
Latitude,
|
|
15
13
|
GeofenceId,
|
|
16
14
|
GeofenceInput,
|
|
17
15
|
GeofencePolygon,
|
|
16
|
+
Latitude,
|
|
18
17
|
LinearRing,
|
|
18
|
+
Longitude,
|
|
19
19
|
} from './types';
|
|
20
20
|
|
|
21
21
|
export function validateCoordinates(lng: Longitude, lat: Latitude): void {
|
|
22
22
|
if (!Number.isFinite(lng) || !Number.isFinite(lat)) {
|
|
23
23
|
throw new Error(`Invalid coordinates: [${lng},${lat}]`);
|
|
24
24
|
}
|
|
25
|
-
if (lat < -90 ||
|
|
25
|
+
if (lat < -90 || lat > 90) {
|
|
26
26
|
throw new Error('Latitude must be between -90 and 90 degrees inclusive.');
|
|
27
|
-
} else if (lng < -180 ||
|
|
27
|
+
} else if (lng < -180 || lng > 180) {
|
|
28
28
|
throw new Error(
|
|
29
29
|
'Longitude must be between -180 and 180 degrees inclusive.',
|
|
30
30
|
);
|
|
@@ -186,17 +186,18 @@ export function mapSearchOptions(options, locationServiceInput) {
|
|
|
186
186
|
locationServiceModifiedInput.IndexName = options.searchIndexName;
|
|
187
187
|
}
|
|
188
188
|
|
|
189
|
-
if (options
|
|
189
|
+
if (options.biasPosition && options.searchAreaConstraints) {
|
|
190
190
|
throw new Error(
|
|
191
191
|
'BiasPosition and SearchAreaConstraints are mutually exclusive, please remove one or the other from the options object',
|
|
192
192
|
);
|
|
193
193
|
}
|
|
194
|
-
if (options
|
|
195
|
-
locationServiceModifiedInput.BiasPosition = options
|
|
194
|
+
if (options.biasPosition) {
|
|
195
|
+
locationServiceModifiedInput.BiasPosition = options.biasPosition;
|
|
196
196
|
}
|
|
197
|
-
if (options
|
|
198
|
-
locationServiceModifiedInput.FilterBBox = options
|
|
197
|
+
if (options.searchAreaConstraints) {
|
|
198
|
+
locationServiceModifiedInput.FilterBBox = options.searchAreaConstraints;
|
|
199
199
|
}
|
|
200
|
+
|
|
200
201
|
return locationServiceModifiedInput;
|
|
201
202
|
}
|
|
202
203
|
|