@aws-amplify/geo 3.0.22 → 3.0.23

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.
@@ -25,17 +25,17 @@ export interface SearchByTextOptionsWithSearchAreaConstraints extends SearchByTe
25
25
  searchAreaConstraints?: BoundingBox;
26
26
  }
27
27
  export type SearchByTextOptions = SearchByTextOptionsWithBiasPosition | SearchByTextOptionsWithSearchAreaConstraints;
28
- export type SearchByCoordinatesOptions = {
28
+ export interface SearchByCoordinatesOptions {
29
29
  maxResults?: number;
30
30
  searchIndexName?: string;
31
31
  providerName?: string;
32
- };
33
- export type searchByPlaceIdOptions = {
32
+ }
33
+ export interface searchByPlaceIdOptions {
34
34
  searchIndexName?: string;
35
- };
36
- export type PlaceGeometry = {
35
+ }
36
+ export interface PlaceGeometry {
37
37
  point: Coordinates;
38
- };
38
+ }
39
39
  export interface Place {
40
40
  addressNumber?: string;
41
41
  country?: string;
@@ -50,49 +50,49 @@ export interface Place {
50
50
  }
51
51
  export type LinearRing = Coordinates[];
52
52
  export type GeofencePolygon = LinearRing[];
53
- export type PolygonGeometry = {
53
+ export interface PolygonGeometry {
54
54
  polygon: GeofencePolygon;
55
- };
55
+ }
56
56
  export type GeofenceId = string;
57
- export type GeofenceInput = {
57
+ export interface GeofenceInput {
58
58
  geofenceId: GeofenceId;
59
59
  geometry: PolygonGeometry;
60
- };
61
- export type GeofenceOptions = {
60
+ }
61
+ export interface GeofenceOptions {
62
62
  providerName?: string;
63
- };
64
- export type GeofenceError = {
63
+ }
64
+ export interface GeofenceError {
65
65
  error: {
66
66
  code: string;
67
67
  message: string;
68
68
  };
69
69
  geofenceId: GeofenceId;
70
- };
71
- type GeofenceBase = {
70
+ }
71
+ interface GeofenceBase {
72
72
  geofenceId: GeofenceId;
73
73
  createTime?: Date;
74
74
  updateTime?: Date;
75
- };
75
+ }
76
76
  export type Geofence = GeofenceBase & {
77
77
  geometry: PolygonGeometry;
78
78
  };
79
- export type SaveGeofencesResults = {
79
+ export interface SaveGeofencesResults {
80
80
  successes: GeofenceBase[];
81
81
  errors: GeofenceError[];
82
- };
82
+ }
83
83
  export type ListGeofenceOptions = GeofenceOptions & {
84
84
  nextToken?: string;
85
85
  };
86
- export type ListGeofenceResults = {
86
+ export interface ListGeofenceResults {
87
87
  entries: Geofence[];
88
88
  nextToken: string | undefined;
89
- };
90
- export type DeleteGeofencesResults = {
89
+ }
90
+ export interface DeleteGeofencesResults {
91
91
  successes: GeofenceId[];
92
92
  errors: GeofenceError[];
93
- };
93
+ }
94
94
  export type SearchForSuggestionsResults = SearchForSuggestionsResult[];
95
- export type SearchForSuggestionsResult = {
95
+ export interface SearchForSuggestionsResult {
96
96
  text: string;
97
97
  placeId?: string;
98
- };
98
+ }
@@ -1,4 +1,4 @@
1
- import { SearchByTextOptions, SearchByCoordinatesOptions, SearchForSuggestionsResults, Coordinates, Place, MapStyle, Geofence, GeofenceId, GeofenceInput, GeofenceOptions, ListGeofenceOptions, ListGeofenceResults, SaveGeofencesResults, DeleteGeofencesResults, searchByPlaceIdOptions } from './Geo';
1
+ import { Coordinates, DeleteGeofencesResults, Geofence, GeofenceId, GeofenceInput, GeofenceOptions, ListGeofenceOptions, ListGeofenceResults, MapStyle, Place, SaveGeofencesResults, SearchByCoordinatesOptions, SearchByTextOptions, SearchForSuggestionsResults, searchByPlaceIdOptions } from './Geo';
2
2
  export interface GeoProvider {
3
3
  getCategory(): string;
4
4
  getProviderName(): string;
@@ -1,6 +1,6 @@
1
1
  import { GeoAction } from '@aws-amplify/core/internals/utils';
2
2
  import { UserAgent } from '@aws-sdk/types';
3
- import { Longitude, Latitude, GeofenceId, GeofenceInput, GeofencePolygon, LinearRing } from './types';
3
+ import { GeofenceId, GeofenceInput, GeofencePolygon, Latitude, LinearRing, Longitude } from './types';
4
4
  export declare function validateCoordinates(lng: Longitude, lat: Latitude): void;
5
5
  export declare function validateGeofenceId(geofenceId: GeofenceId): void;
6
6
  export declare function validateLinearRing(linearRing: LinearRing, geofenceId?: GeofenceId): void;
package/dist/esm/util.mjs CHANGED
@@ -7,10 +7,10 @@ function validateCoordinates(lng, lat) {
7
7
  if (!Number.isFinite(lng) || !Number.isFinite(lat)) {
8
8
  throw new Error(`Invalid coordinates: [${lng},${lat}]`);
9
9
  }
10
- if (lat < -90 || 90 < lat) {
10
+ if (lat < -90 || lat > 90) {
11
11
  throw new Error('Latitude must be between -90 and 90 degrees inclusive.');
12
12
  }
13
- else if (lng < -180 || 180 < lng) {
13
+ else if (lng < -180 || lng > 180) {
14
14
  throw new Error('Longitude must be between -180 and 180 degrees inclusive.');
15
15
  }
16
16
  }
@@ -118,14 +118,14 @@ function mapSearchOptions(options, locationServiceInput) {
118
118
  if (options.searchIndexName) {
119
119
  locationServiceModifiedInput.IndexName = options.searchIndexName;
120
120
  }
121
- if (options['biasPosition'] && options['searchAreaConstraints']) {
121
+ if (options.biasPosition && options.searchAreaConstraints) {
122
122
  throw new Error('BiasPosition and SearchAreaConstraints are mutually exclusive, please remove one or the other from the options object');
123
123
  }
124
- if (options['biasPosition']) {
125
- locationServiceModifiedInput.BiasPosition = options['biasPosition'];
124
+ if (options.biasPosition) {
125
+ locationServiceModifiedInput.BiasPosition = options.biasPosition;
126
126
  }
127
- if (options['searchAreaConstraints']) {
128
- locationServiceModifiedInput.FilterBBox = options['searchAreaConstraints'];
127
+ if (options.searchAreaConstraints) {
128
+ locationServiceModifiedInput.FilterBBox = options.searchAreaConstraints;
129
129
  }
130
130
  return locationServiceModifiedInput;
131
131
  }
@@ -1 +1 @@
1
- {"version":3,"file":"util.mjs","sources":["../../src/util.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport booleanClockwise from '@turf/boolean-clockwise';\nimport { Category, getAmplifyUserAgent, getAmplifyUserAgentObject, } from '@aws-amplify/core/internals/utils';\nexport function validateCoordinates(lng, lat) {\n if (!Number.isFinite(lng) || !Number.isFinite(lat)) {\n throw new Error(`Invalid coordinates: [${lng},${lat}]`);\n }\n if (lat < -90 || 90 < lat) {\n throw new Error('Latitude must be between -90 and 90 degrees inclusive.');\n }\n else if (lng < -180 || 180 < lng) {\n throw new Error('Longitude must be between -180 and 180 degrees inclusive.');\n }\n}\nexport function validateGeofenceId(geofenceId) {\n const geofenceIdRegex = /^[-._\\p{L}\\p{N}]+$/iu;\n // Check if geofenceId is valid\n if (!geofenceIdRegex.test(geofenceId)) {\n throw new Error(`Invalid geofenceId: '${geofenceId}' - IDs can only contain alphanumeric characters, hyphens, underscores and periods.`);\n }\n}\nexport function validateLinearRing(linearRing, geofenceId) {\n const errorPrefix = geofenceId ? `${geofenceId}: ` : '';\n // Validate LinearRing size, must be at least 4 points\n if (linearRing.length < 4) {\n throw new Error(`${errorPrefix}LinearRing must contain 4 or more coordinates.`);\n }\n // Validate all coordinates are valid, error with which ones are bad\n const badCoordinates = [];\n linearRing.forEach(coordinates => {\n try {\n validateCoordinates(coordinates[0], coordinates[1]);\n }\n catch (error) {\n badCoordinates.push({ coordinates, error: error.message });\n }\n });\n if (badCoordinates.length > 0) {\n throw new Error(`${errorPrefix}One or more of the coordinates in the Polygon LinearRing are not valid: ${JSON.stringify(badCoordinates)}`);\n }\n // Validate first and last coordinates are the same\n const [lngA, latA] = linearRing[0];\n const [lngB, latB] = linearRing[linearRing.length - 1];\n if (lngA !== lngB || latA !== latB) {\n throw new Error(`${errorPrefix}LinearRing's first and last coordinates are not the same`);\n }\n if (booleanClockwise(linearRing)) {\n throw new Error(`${errorPrefix}LinearRing coordinates must be wound counterclockwise`);\n }\n}\nexport function validatePolygon(polygon, geofenceId) {\n const errorPrefix = geofenceId ? `${geofenceId}: ` : '';\n if (!Array.isArray(polygon)) {\n throw new Error(`${errorPrefix}Polygon is of incorrect structure. It should be an array of LinearRings`);\n }\n if (polygon.length < 1) {\n throw new Error(`${errorPrefix}Polygon must have a single LinearRing array.`);\n }\n if (polygon.length > 1) {\n throw new Error(`${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.`);\n }\n const verticesCount = polygon.reduce((prev, linearRing) => prev + linearRing.length, 0);\n if (verticesCount > 1000) {\n throw new Error(`${errorPrefix}Polygon has more than the maximum 1000 vertices.`);\n }\n polygon.forEach(linearRing => {\n validateLinearRing(linearRing, geofenceId);\n });\n}\nexport function validateGeofencesInput(geofences) {\n const geofenceIds = {};\n geofences.forEach((geofence) => {\n // verify all required properties are present\n // Validate geofenceId exists\n if (!geofence.geofenceId) {\n throw new Error(`Geofence '${geofence}' is missing geofenceId`);\n }\n const { geofenceId } = geofence;\n validateGeofenceId(geofenceId);\n // Validate geofenceId is unique\n if (geofenceIds[geofenceId]) {\n throw new Error(`Duplicate geofenceId: ${geofenceId}`);\n }\n else {\n geofenceIds[geofenceId] = true;\n }\n // Validate geometry exists\n if (!geofence.geometry) {\n throw new Error(`Geofence '${geofenceId}' is missing geometry`);\n }\n const { geometry } = geofence;\n // Validate polygon exists\n if (!geometry.polygon) {\n throw new Error(`Geofence '${geofenceId}' is missing geometry.polygon`);\n }\n const { polygon } = geometry;\n // Validate polygon length and structure\n try {\n validatePolygon(polygon, geofenceId);\n }\n catch (error) {\n if (error.message.includes('Polygon has more than the maximum 1000 vertices.')) {\n throw new Error(`Geofence '${geofenceId}' has more than the maximum of 1000 vertices`);\n }\n }\n // Validate LinearRing length, structure, and coordinates\n const [linearRing] = polygon;\n validateLinearRing(linearRing, geofenceId);\n });\n}\nexport function mapSearchOptions(options, locationServiceInput) {\n const locationServiceModifiedInput = { ...locationServiceInput };\n locationServiceModifiedInput.FilterCountries = options.countries;\n locationServiceModifiedInput.MaxResults = options.maxResults;\n locationServiceModifiedInput.Language = options.language;\n if (options.searchIndexName) {\n locationServiceModifiedInput.IndexName = options.searchIndexName;\n }\n if (options['biasPosition'] && options['searchAreaConstraints']) {\n throw new Error('BiasPosition and SearchAreaConstraints are mutually exclusive, please remove one or the other from the options object');\n }\n if (options['biasPosition']) {\n locationServiceModifiedInput.BiasPosition = options['biasPosition'];\n }\n if (options['searchAreaConstraints']) {\n locationServiceModifiedInput.FilterBBox = options['searchAreaConstraints'];\n }\n return locationServiceModifiedInput;\n}\nexport function getGeoUserAgent(action) {\n return getAmplifyUserAgentObject({\n category: Category.Geo,\n action,\n });\n}\nexport function getGeoUserAgentString(action) {\n return getAmplifyUserAgent({\n category: Category.Geo,\n action,\n });\n}\n"],"names":[],"mappings":";;;AAAA;AACA;AAGO,SAAS,mBAAmB,CAAC,GAAG,EAAE,GAAG,EAAE;AAC9C,IAAI,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;AACxD,QAAQ,MAAM,IAAI,KAAK,CAAC,CAAC,sBAAsB,EAAE,GAAG,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;AAChE,KAAK;AACL,IAAI,IAAI,GAAG,GAAG,CAAC,EAAE,IAAI,EAAE,GAAG,GAAG,EAAE;AAC/B,QAAQ,MAAM,IAAI,KAAK,CAAC,wDAAwD,CAAC,CAAC;AAClF,KAAK;AACL,SAAS,IAAI,GAAG,GAAG,CAAC,GAAG,IAAI,GAAG,GAAG,GAAG,EAAE;AACtC,QAAQ,MAAM,IAAI,KAAK,CAAC,2DAA2D,CAAC,CAAC;AACrF,KAAK;AACL,CAAC;AACM,SAAS,kBAAkB,CAAC,UAAU,EAAE;AAC/C,IAAI,MAAM,eAAe,GAAG,sBAAsB,CAAC;AACnD;AACA,IAAI,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE;AAC3C,QAAQ,MAAM,IAAI,KAAK,CAAC,CAAC,qBAAqB,EAAE,UAAU,CAAC,mFAAmF,CAAC,CAAC,CAAC;AACjJ,KAAK;AACL,CAAC;AACM,SAAS,kBAAkB,CAAC,UAAU,EAAE,UAAU,E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AE,QAAQ,CAAC,GAAG;AAC9B,QAAQ,MAAM;AACd,KAAK,CAAC,CAAC;AACP,CAAC;AACM,SAAS,qBAAqB,CAAC,MAAM,EAAE;AAC9C,IAAI,OAAO,mBAAmB,CAAC;AAC/B,QAAQ,QAAQ,EAAE,QAAQ,CAAC,GAAG;AAC9B,QAAQ,MAAM;AACd,KAAK,CAAC,CAAC;AACP;;;;"}
1
+ {"version":3,"file":"util.mjs","sources":["../../src/util.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport booleanClockwise from '@turf/boolean-clockwise';\nimport { Category, getAmplifyUserAgent, getAmplifyUserAgentObject, } from '@aws-amplify/core/internals/utils';\nexport function validateCoordinates(lng, lat) {\n if (!Number.isFinite(lng) || !Number.isFinite(lat)) {\n throw new Error(`Invalid coordinates: [${lng},${lat}]`);\n }\n if (lat < -90 || lat > 90) {\n throw new Error('Latitude must be between -90 and 90 degrees inclusive.');\n }\n else if (lng < -180 || lng > 180) {\n throw new Error('Longitude must be between -180 and 180 degrees inclusive.');\n }\n}\nexport function validateGeofenceId(geofenceId) {\n const geofenceIdRegex = /^[-._\\p{L}\\p{N}]+$/iu;\n // Check if geofenceId is valid\n if (!geofenceIdRegex.test(geofenceId)) {\n throw new Error(`Invalid geofenceId: '${geofenceId}' - IDs can only contain alphanumeric characters, hyphens, underscores and periods.`);\n }\n}\nexport function validateLinearRing(linearRing, geofenceId) {\n const errorPrefix = geofenceId ? `${geofenceId}: ` : '';\n // Validate LinearRing size, must be at least 4 points\n if (linearRing.length < 4) {\n throw new Error(`${errorPrefix}LinearRing must contain 4 or more coordinates.`);\n }\n // Validate all coordinates are valid, error with which ones are bad\n const badCoordinates = [];\n linearRing.forEach(coordinates => {\n try {\n validateCoordinates(coordinates[0], coordinates[1]);\n }\n catch (error) {\n badCoordinates.push({ coordinates, error: error.message });\n }\n });\n if (badCoordinates.length > 0) {\n throw new Error(`${errorPrefix}One or more of the coordinates in the Polygon LinearRing are not valid: ${JSON.stringify(badCoordinates)}`);\n }\n // Validate first and last coordinates are the same\n const [lngA, latA] = linearRing[0];\n const [lngB, latB] = linearRing[linearRing.length - 1];\n if (lngA !== lngB || latA !== latB) {\n throw new Error(`${errorPrefix}LinearRing's first and last coordinates are not the same`);\n }\n if (booleanClockwise(linearRing)) {\n throw new Error(`${errorPrefix}LinearRing coordinates must be wound counterclockwise`);\n }\n}\nexport function validatePolygon(polygon, geofenceId) {\n const errorPrefix = geofenceId ? `${geofenceId}: ` : '';\n if (!Array.isArray(polygon)) {\n throw new Error(`${errorPrefix}Polygon is of incorrect structure. It should be an array of LinearRings`);\n }\n if (polygon.length < 1) {\n throw new Error(`${errorPrefix}Polygon must have a single LinearRing array.`);\n }\n if (polygon.length > 1) {\n throw new Error(`${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.`);\n }\n const verticesCount = polygon.reduce((prev, linearRing) => prev + linearRing.length, 0);\n if (verticesCount > 1000) {\n throw new Error(`${errorPrefix}Polygon has more than the maximum 1000 vertices.`);\n }\n polygon.forEach(linearRing => {\n validateLinearRing(linearRing, geofenceId);\n });\n}\nexport function validateGeofencesInput(geofences) {\n const geofenceIds = {};\n geofences.forEach((geofence) => {\n // verify all required properties are present\n // Validate geofenceId exists\n if (!geofence.geofenceId) {\n throw new Error(`Geofence '${geofence}' is missing geofenceId`);\n }\n const { geofenceId } = geofence;\n validateGeofenceId(geofenceId);\n // Validate geofenceId is unique\n if (geofenceIds[geofenceId]) {\n throw new Error(`Duplicate geofenceId: ${geofenceId}`);\n }\n else {\n geofenceIds[geofenceId] = true;\n }\n // Validate geometry exists\n if (!geofence.geometry) {\n throw new Error(`Geofence '${geofenceId}' is missing geometry`);\n }\n const { geometry } = geofence;\n // Validate polygon exists\n if (!geometry.polygon) {\n throw new Error(`Geofence '${geofenceId}' is missing geometry.polygon`);\n }\n const { polygon } = geometry;\n // Validate polygon length and structure\n try {\n validatePolygon(polygon, geofenceId);\n }\n catch (error) {\n if (error.message.includes('Polygon has more than the maximum 1000 vertices.')) {\n throw new Error(`Geofence '${geofenceId}' has more than the maximum of 1000 vertices`);\n }\n }\n // Validate LinearRing length, structure, and coordinates\n const [linearRing] = polygon;\n validateLinearRing(linearRing, geofenceId);\n });\n}\nexport function mapSearchOptions(options, locationServiceInput) {\n const locationServiceModifiedInput = { ...locationServiceInput };\n locationServiceModifiedInput.FilterCountries = options.countries;\n locationServiceModifiedInput.MaxResults = options.maxResults;\n locationServiceModifiedInput.Language = options.language;\n if (options.searchIndexName) {\n locationServiceModifiedInput.IndexName = options.searchIndexName;\n }\n if (options.biasPosition && options.searchAreaConstraints) {\n throw new Error('BiasPosition and SearchAreaConstraints are mutually exclusive, please remove one or the other from the options object');\n }\n if (options.biasPosition) {\n locationServiceModifiedInput.BiasPosition = options.biasPosition;\n }\n if (options.searchAreaConstraints) {\n locationServiceModifiedInput.FilterBBox = options.searchAreaConstraints;\n }\n return locationServiceModifiedInput;\n}\nexport function getGeoUserAgent(action) {\n return getAmplifyUserAgentObject({\n category: Category.Geo,\n action,\n });\n}\nexport function getGeoUserAgentString(action) {\n return getAmplifyUserAgent({\n category: Category.Geo,\n action,\n });\n}\n"],"names":[],"mappings":";;;AAAA;AACA;AAGO,SAAS,mBAAmB,CAAC,GAAG,EAAE,GAAG,EAAE;AAC9C,IAAI,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;AACxD,QAAQ,MAAM,IAAI,KAAK,CAAC,CAAC,sBAAsB,EAAE,GAAG,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;AAChE,KAAK;AACL,IAAI,IAAI,GAAG,GAAG,CAAC,EAAE,IAAI,GAAG,GAAG,EAAE,EAAE;AAC/B,QAAQ,MAAM,IAAI,KAAK,CAA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AAO,CAAC,qBAAqB,EAAE;AAC/D,QAAQ,MAAM,IAAI,KAAK,CAAC,uHAAuH,CAAC,CAAC;AACjJ,KAAK;AACL,IAAI,IAAI,OAAO,CAAC,YAAY,EAAE;AAC9B,QAAQ,4BAA4B,CAAC,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC;AACzE,KAAK;AACL,IAAI,IAAI,OAAO,CAAC,qBAAqB,EAAE;AACvC,QAAQ,4BAA4B,CAAC,UAAU,GAAG,OAAO,CAAC,qBAAqB,CAAC;AAChF,KAAK;AACL,IAAI,OAAO,4BAA4B,CAAC;AACxC,CAAC;AACM,SAAS,eAAe,CAAC,MAAM,EAAE;AACxC,IAAI,OAAO,yBAAyB,CAAC;AACrC,QAAQ,QAAQ,EAAE,QAAQ,CAAC,GAAG;AAC9B,QAAQ,MAAM;AACd,KAAK,CAAC,CAAC;AACP,CAAC;AACM,SAAS,qBAAqB,CAAC,MAAM,EAAE;AAC9C,IAAI,OAAO,mBAAmB,CAAC;AAC/B,QAAQ,QAAQ,EAAE,QAAQ,CAAC,GAAG;AAC9B,QAAQ,MAAM;AACd,KAAK,CAAC,CAAC;AACP;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aws-amplify/geo",
3
- "version": "3.0.22",
3
+ "version": "3.0.23",
4
4
  "description": "Geo category for aws-amplify",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "module": "./dist/esm/index.mjs",
@@ -24,7 +24,8 @@
24
24
  "clean": "npm run clean:size && rimraf dist lib lib-esm",
25
25
  "clean:size": "rimraf dual-publish-tmp tmp*",
26
26
  "format": "echo \"Not implemented\"",
27
- "lint": "tslint '{__tests__,src}/**/*.ts' && npm run ts-coverage",
27
+ "lint": "eslint '**/*.{ts,tsx}' && npm run ts-coverage",
28
+ "lint:fix": "eslint '**/*.{ts,tsx}' --fix",
28
29
  "ts-coverage": "typescript-coverage-report -p ./tsconfig.build.json -t 84.00"
29
30
  },
30
31
  "exports": {
@@ -75,7 +76,7 @@
75
76
  "@aws-amplify/core": "^6.0.0"
76
77
  },
77
78
  "devDependencies": {
78
- "@aws-amplify/core": "6.0.22",
79
+ "@aws-amplify/core": "6.0.23",
79
80
  "typescript": "5.0.2"
80
81
  },
81
82
  "size-limit": [
@@ -86,5 +87,5 @@
86
87
  "limit": "43.9 kB"
87
88
  }
88
89
  ],
89
- "gitHead": "080f8c11e9eb89cdcd29d78a2b4fe07c8c5b5404"
90
+ "gitHead": "6c46368559f4c3229024d10c18aabb34c58efe68"
90
91
  }
package/src/Geo.ts CHANGED
@@ -1,26 +1,26 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
  import { Amplify, ConsoleLogger } from '@aws-amplify/core';
4
- import { AmazonLocationServiceProvider } from './providers/location-service/AmazonLocationServiceProvider';
5
4
 
5
+ import { AmazonLocationServiceProvider } from './providers/location-service/AmazonLocationServiceProvider';
6
6
  import { validateCoordinates } from './util';
7
-
8
7
  import {
9
- Place,
10
- GeoConfig,
11
8
  Coordinates,
12
- SearchByTextOptions,
13
- SearchByCoordinatesOptions,
9
+ DeleteGeofencesResults,
10
+ GeoConfig,
14
11
  GeoProvider,
15
- MapStyle,
12
+ Geofence,
16
13
  GeofenceId,
17
14
  GeofenceInput,
18
15
  GeofenceOptions,
19
- SaveGeofencesResults,
20
- Geofence,
21
16
  ListGeofenceOptions,
22
17
  ListGeofenceResults,
23
- DeleteGeofencesResults,
18
+ MapStyle,
19
+ Place,
20
+ SaveGeofencesResults,
21
+ SearchByCoordinatesOptions,
22
+ SearchByTextOptions,
23
+ SearchForSuggestionsResults,
24
24
  searchByPlaceIdOptions,
25
25
  } from './types';
26
26
 
@@ -73,13 +73,13 @@ export class GeoClass {
73
73
  * @param providerName the name of the plugin
74
74
  */
75
75
  public getPluggable(providerName: string) {
76
- const pluggable = this._pluggables.find(
76
+ const targetPluggable = this._pluggables.find(
77
77
  pluggable => pluggable.getProviderName() === providerName,
78
78
  );
79
- if (pluggable === undefined) {
79
+ if (targetPluggable === undefined) {
80
80
  logger.debug('No plugin found with providerName', providerName);
81
81
  throw new Error('No plugin found in Geo for the provider');
82
- } else return pluggable;
82
+ } else return targetPluggable;
83
83
  }
84
84
 
85
85
  /**
@@ -90,7 +90,6 @@ export class GeoClass {
90
90
  this._pluggables = this._pluggables.filter(
91
91
  pluggable => pluggable.getProviderName() !== providerName,
92
92
  );
93
- return;
94
93
  }
95
94
 
96
95
  /**
@@ -140,7 +139,7 @@ export class GeoClass {
140
139
  * Search for search term suggestions based on input text
141
140
  * @param {string} text The text string that is to be search for
142
141
  * @param {SearchByTextOptions} options Optional parameters to the search
143
- * @returns {Promise<SearchForSuggestionsResults>} - Resolves to an array of search suggestion strings
142
+ * @returns a `Promise` of {@link SearchForSuggestionsResults} that resolves to an array of search suggestion strings
144
143
  */
145
144
  public async searchForSuggestions(
146
145
  text: string,
@@ -194,6 +193,7 @@ export class GeoClass {
194
193
  const [lng, lat] = coordinates;
195
194
  try {
196
195
  validateCoordinates(lng, lat);
196
+
197
197
  return await prov.searchByCoordinates(coordinates, options);
198
198
  } catch (error) {
199
199
  logger.debug(error);
@@ -256,7 +256,7 @@ export class GeoClass {
256
256
  /**
257
257
  * List geofences
258
258
  * @param options ListGeofenceOptions
259
- * @returns {Promise<ListGeofencesResults>} - Promise that resolves to an object with:
259
+ * @returns a promise that resolves to an object that conforms to {@link ListGeofenceResults}:
260
260
  * entries: list of geofences - 100 geofences are listed per page
261
261
  * nextToken: token for next page of geofences
262
262
  */
@@ -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
- Place as PlaceResult,
9
- LocationClient,
10
- SearchPlaceIndexForTextCommand,
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
- GetPlaceCommand,
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
- BatchDeleteGeofenceCommand,
30
- BatchDeleteGeofenceCommandInput,
31
- BatchDeleteGeofenceCommandOutput,
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
- GeoConfig,
43
- SearchByTextOptions,
44
- SearchByCoordinatesOptions,
45
- GeoProvider,
46
- Place,
40
+ AmazonLocationServiceBatchGeofenceErrorMessages,
41
+ AmazonLocationServiceDeleteGeofencesResults,
42
+ AmazonLocationServiceGeofence,
43
+ AmazonLocationServiceGeofenceOptions,
44
+ AmazonLocationServiceGeofenceStatus,
45
+ AmazonLocationServiceListGeofenceOptions,
47
46
  AmazonLocationServiceMapStyle,
48
47
  Coordinates,
49
- SearchForSuggestionsResults,
48
+ GeoConfig,
49
+ GeoProvider,
50
50
  GeofenceId,
51
51
  GeofenceInput,
52
- AmazonLocationServiceGeofenceOptions,
53
- AmazonLocationServiceListGeofenceOptions,
52
+ GeofencePolygon,
54
53
  ListGeofenceResults,
55
- AmazonLocationServiceGeofenceStatus,
54
+ Place,
56
55
  SaveGeofencesResults,
57
- AmazonLocationServiceGeofence,
58
- GeofencePolygon,
59
- AmazonLocationServiceDeleteGeofencesResults,
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 ? 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.region;
108
+ const { region } = this._config;
111
109
 
112
110
  for (const mapName in availableMaps) {
113
- const style = availableMaps[mapName].style;
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].style;
129
- const region = this._config.region;
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 {Promise<AmazonLocationServiceSaveGeofencesResults>} - Promise that resolves to an object with:
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: 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: 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 { GeofenceId, CreateTime, UpdateTime, Status, Geometry } = response;
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: 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 {Promise<ListGeofencesResults>} - Promise that resolves to an object with:
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
- ({ GeofenceId, CreateTime, UpdateTime, Status, Geometry }) => {
601
+ ({
602
+ GeofenceId: geofenceId,
603
+ CreateTime,
604
+ UpdateTime,
605
+ Status,
606
+ Geometry,
607
+ }) => {
598
608
  return {
599
- geofenceId: 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 {Promise<DeleteGeofencesResults>} - Promise that resolves to an object with:
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 badGeofenceIds = response.Errors.map(
700
+ const targetBadGeofenceIds = response.Errors.map(
688
701
  ({ geofenceId }) => geofenceId,
689
702
  );
690
703
  results.successes.push(
691
- ...batch.filter(Id => !badGeofenceIds.includes(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 = (await fetchAuthSession()).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
- let response: BatchPutGeofenceCommandOutput;
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
- let response: BatchDeleteGeofenceCommandOutput;
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