@aws-amplify/geo 2.3.6-api-v6-models.b3abc9b.0 → 3.0.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.
Files changed (56) hide show
  1. package/lib/Geo.d.ts +3 -9
  2. package/lib/Geo.js +137 -243
  3. package/lib/index.js +4 -2
  4. package/{lib-esm/Providers → lib/providers/location-service}/AmazonLocationServiceProvider.d.ts +3 -7
  5. package/lib/providers/location-service/AmazonLocationServiceProvider.js +618 -0
  6. package/lib/tsconfig.tsbuildinfo +1 -0
  7. package/lib/types/AmazonLocationServiceProvider.d.ts +7 -7
  8. package/lib/types/AmazonLocationServiceProvider.js +0 -1
  9. package/lib/types/Geo.d.ts +28 -45
  10. package/lib/types/Geo.js +0 -1
  11. package/lib/types/Provider.d.ts +0 -1
  12. package/lib/types/Provider.js +0 -1
  13. package/lib/types/index.js +6 -1
  14. package/lib/util.d.ts +4 -0
  15. package/lib/util.js +51 -36
  16. package/lib-esm/Geo.d.ts +3 -9
  17. package/lib-esm/Geo.js +136 -243
  18. package/lib-esm/index.js +1 -1
  19. package/{lib/Providers → lib-esm/providers/location-service}/AmazonLocationServiceProvider.d.ts +3 -7
  20. package/lib-esm/providers/location-service/AmazonLocationServiceProvider.js +614 -0
  21. package/lib-esm/tsconfig.tsbuildinfo +1 -0
  22. package/lib-esm/types/AmazonLocationServiceProvider.d.ts +7 -7
  23. package/lib-esm/types/AmazonLocationServiceProvider.js +1 -1
  24. package/lib-esm/types/Geo.d.ts +28 -45
  25. package/lib-esm/types/Geo.js +1 -1
  26. package/lib-esm/types/Provider.d.ts +0 -1
  27. package/lib-esm/types/Provider.js +1 -1
  28. package/lib-esm/types/index.js +5 -1
  29. package/lib-esm/util.d.ts +4 -0
  30. package/lib-esm/util.js +45 -34
  31. package/package.json +26 -12
  32. package/src/Geo.ts +12 -36
  33. package/src/{Providers → providers/location-service}/AmazonLocationServiceProvider.ts +65 -68
  34. package/src/types/Geo.ts +1 -17
  35. package/src/types/Provider.ts +0 -3
  36. package/src/util.ts +24 -3
  37. package/lib/.tsbuildinfo +0 -3
  38. package/lib/Geo.js.map +0 -1
  39. package/lib/Providers/AmazonLocationServiceProvider.js +0 -737
  40. package/lib/Providers/AmazonLocationServiceProvider.js.map +0 -1
  41. package/lib/index.js.map +0 -1
  42. package/lib/types/AmazonLocationServiceProvider.js.map +0 -1
  43. package/lib/types/Geo.js.map +0 -1
  44. package/lib/types/Provider.js.map +0 -1
  45. package/lib/types/index.js.map +0 -1
  46. package/lib/util.js.map +0 -1
  47. package/lib-esm/.tsbuildinfo +0 -3
  48. package/lib-esm/Geo.js.map +0 -1
  49. package/lib-esm/Providers/AmazonLocationServiceProvider.js +0 -735
  50. package/lib-esm/Providers/AmazonLocationServiceProvider.js.map +0 -1
  51. package/lib-esm/index.js.map +0 -1
  52. package/lib-esm/types/AmazonLocationServiceProvider.js.map +0 -1
  53. package/lib-esm/types/Geo.js.map +0 -1
  54. package/lib-esm/types/Provider.js.map +0 -1
  55. package/lib-esm/types/index.js.map +0 -1
  56. package/lib-esm/util.js.map +0 -1
package/lib-esm/util.js CHANGED
@@ -1,10 +1,10 @@
1
- import { __assign, __read } from "tslib";
2
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
2
  // SPDX-License-Identifier: Apache-2.0
4
3
  import booleanClockwise from '@turf/boolean-clockwise';
4
+ import { Category, getAmplifyUserAgent, getAmplifyUserAgentObject, } from '@aws-amplify/core/internals/utils';
5
5
  export function validateCoordinates(lng, lat) {
6
6
  if (!Number.isFinite(lng) || !Number.isFinite(lat)) {
7
- throw new Error("Invalid coordinates: [" + lng + "," + lat + "]");
7
+ throw new Error(`Invalid coordinates: [${lng},${lat}]`);
8
8
  }
9
9
  if (lat < -90 || 90 < lat) {
10
10
  throw new Error('Latitude must be between -90 and 90 degrees inclusive.');
@@ -14,103 +14,103 @@ export function validateCoordinates(lng, lat) {
14
14
  }
15
15
  }
16
16
  export function validateGeofenceId(geofenceId) {
17
- var geofenceIdRegex = /^[-._\p{L}\p{N}]+$/iu;
17
+ const geofenceIdRegex = /^[-._\p{L}\p{N}]+$/iu;
18
18
  // Check if geofenceId is valid
19
19
  if (!geofenceIdRegex.test(geofenceId)) {
20
- throw new Error("Invalid geofenceId: '" + geofenceId + "' - IDs can only contain alphanumeric characters, hyphens, underscores and periods.");
20
+ throw new Error(`Invalid geofenceId: '${geofenceId}' - IDs can only contain alphanumeric characters, hyphens, underscores and periods.`);
21
21
  }
22
22
  }
23
23
  export function validateLinearRing(linearRing, geofenceId) {
24
- var errorPrefix = geofenceId ? geofenceId + ": " : '';
24
+ const errorPrefix = geofenceId ? `${geofenceId}: ` : '';
25
25
  // Validate LinearRing size, must be at least 4 points
26
26
  if (linearRing.length < 4) {
27
- throw new Error(errorPrefix + "LinearRing must contain 4 or more coordinates.");
27
+ throw new Error(`${errorPrefix}LinearRing must contain 4 or more coordinates.`);
28
28
  }
29
29
  // Validate all coordinates are valid, error with which ones are bad
30
- var badCoordinates = [];
31
- linearRing.forEach(function (coordinates) {
30
+ const badCoordinates = [];
31
+ linearRing.forEach(coordinates => {
32
32
  try {
33
33
  validateCoordinates(coordinates[0], coordinates[1]);
34
34
  }
35
35
  catch (error) {
36
- badCoordinates.push({ coordinates: coordinates, error: error.message });
36
+ badCoordinates.push({ coordinates, error: error.message });
37
37
  }
38
38
  });
39
39
  if (badCoordinates.length > 0) {
40
- throw new Error(errorPrefix + "One or more of the coordinates in the Polygon LinearRing are not valid: " + JSON.stringify(badCoordinates));
40
+ throw new Error(`${errorPrefix}One or more of the coordinates in the Polygon LinearRing are not valid: ${JSON.stringify(badCoordinates)}`);
41
41
  }
42
42
  // Validate first and last coordinates are the same
43
- var _a = __read(linearRing[0], 2), lngA = _a[0], latA = _a[1];
44
- var _b = __read(linearRing[linearRing.length - 1], 2), lngB = _b[0], latB = _b[1];
43
+ const [lngA, latA] = linearRing[0];
44
+ const [lngB, latB] = linearRing[linearRing.length - 1];
45
45
  if (lngA !== lngB || latA !== latB) {
46
- throw new Error(errorPrefix + "LinearRing's first and last coordinates are not the same");
46
+ throw new Error(`${errorPrefix}LinearRing's first and last coordinates are not the same`);
47
47
  }
48
48
  if (booleanClockwise(linearRing)) {
49
- throw new Error(errorPrefix + "LinearRing coordinates must be wound counterclockwise");
49
+ throw new Error(`${errorPrefix}LinearRing coordinates must be wound counterclockwise`);
50
50
  }
51
51
  }
52
52
  export function validatePolygon(polygon, geofenceId) {
53
- var errorPrefix = geofenceId ? geofenceId + ": " : '';
53
+ const errorPrefix = geofenceId ? `${geofenceId}: ` : '';
54
54
  if (!Array.isArray(polygon)) {
55
- throw new Error(errorPrefix + "Polygon is of incorrect structure. It should be an array of LinearRings");
55
+ throw new Error(`${errorPrefix}Polygon is of incorrect structure. It should be an array of LinearRings`);
56
56
  }
57
57
  if (polygon.length < 1) {
58
- throw new Error(errorPrefix + "Polygon must have a single LinearRing array.");
58
+ throw new Error(`${errorPrefix}Polygon must have a single LinearRing array.`);
59
59
  }
60
60
  if (polygon.length > 1) {
61
- 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.");
61
+ 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.`);
62
62
  }
63
- var verticesCount = polygon.reduce(function (prev, linearRing) { return prev + linearRing.length; }, 0);
63
+ const verticesCount = polygon.reduce((prev, linearRing) => prev + linearRing.length, 0);
64
64
  if (verticesCount > 1000) {
65
- throw new Error(errorPrefix + "Polygon has more than the maximum 1000 vertices.");
65
+ throw new Error(`${errorPrefix}Polygon has more than the maximum 1000 vertices.`);
66
66
  }
67
- polygon.forEach(function (linearRing) {
67
+ polygon.forEach(linearRing => {
68
68
  validateLinearRing(linearRing, geofenceId);
69
69
  });
70
70
  }
71
71
  export function validateGeofencesInput(geofences) {
72
- var geofenceIds = {};
73
- geofences.forEach(function (geofence) {
72
+ const geofenceIds = {};
73
+ geofences.forEach((geofence) => {
74
74
  // verify all required properties are present
75
75
  // Validate geofenceId exists
76
76
  if (!geofence.geofenceId) {
77
- throw new Error("Geofence '" + geofence + "' is missing geofenceId");
77
+ throw new Error(`Geofence '${geofence}' is missing geofenceId`);
78
78
  }
79
- var geofenceId = geofence.geofenceId;
79
+ const { geofenceId } = geofence;
80
80
  validateGeofenceId(geofenceId);
81
81
  // Validate geofenceId is unique
82
82
  if (geofenceIds[geofenceId]) {
83
- throw new Error("Duplicate geofenceId: " + geofenceId);
83
+ throw new Error(`Duplicate geofenceId: ${geofenceId}`);
84
84
  }
85
85
  else {
86
86
  geofenceIds[geofenceId] = true;
87
87
  }
88
88
  // Validate geometry exists
89
89
  if (!geofence.geometry) {
90
- throw new Error("Geofence '" + geofenceId + "' is missing geometry");
90
+ throw new Error(`Geofence '${geofenceId}' is missing geometry`);
91
91
  }
92
- var geometry = geofence.geometry;
92
+ const { geometry } = geofence;
93
93
  // Validate polygon exists
94
94
  if (!geometry.polygon) {
95
- throw new Error("Geofence '" + geofenceId + "' is missing geometry.polygon");
95
+ throw new Error(`Geofence '${geofenceId}' is missing geometry.polygon`);
96
96
  }
97
- var polygon = geometry.polygon;
97
+ const { polygon } = geometry;
98
98
  // Validate polygon length and structure
99
99
  try {
100
100
  validatePolygon(polygon, geofenceId);
101
101
  }
102
102
  catch (error) {
103
103
  if (error.message.includes('Polygon has more than the maximum 1000 vertices.')) {
104
- throw new Error("Geofence '" + geofenceId + "' has more than the maximum of 1000 vertices");
104
+ throw new Error(`Geofence '${geofenceId}' has more than the maximum of 1000 vertices`);
105
105
  }
106
106
  }
107
107
  // Validate LinearRing length, structure, and coordinates
108
- var _a = __read(polygon, 1), linearRing = _a[0];
108
+ const [linearRing] = polygon;
109
109
  validateLinearRing(linearRing, geofenceId);
110
110
  });
111
111
  }
112
112
  export function mapSearchOptions(options, locationServiceInput) {
113
- var locationServiceModifiedInput = __assign({}, locationServiceInput);
113
+ const locationServiceModifiedInput = { ...locationServiceInput };
114
114
  locationServiceModifiedInput.FilterCountries = options.countries;
115
115
  locationServiceModifiedInput.MaxResults = options.maxResults;
116
116
  if (options.searchIndexName) {
@@ -127,4 +127,15 @@ export function mapSearchOptions(options, locationServiceInput) {
127
127
  }
128
128
  return locationServiceModifiedInput;
129
129
  }
130
- //# sourceMappingURL=util.js.map
130
+ export function getGeoUserAgent(action) {
131
+ return getAmplifyUserAgentObject({
132
+ category: Category.Geo,
133
+ action,
134
+ });
135
+ }
136
+ export function getGeoUserAgentString(action) {
137
+ return getAmplifyUserAgent({
138
+ category: Category.Geo,
139
+ action,
140
+ });
141
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aws-amplify/geo",
3
- "version": "2.3.6-api-v6-models.b3abc9b.0+b3abc9b",
3
+ "version": "3.0.0",
4
4
  "description": "Geo category for aws-amplify",
5
5
  "main": "./lib/index.js",
6
6
  "module": "./lib-esm/index.js",
@@ -19,16 +19,23 @@
19
19
  "test": "yarn run lint && jest -w 1 --coverage",
20
20
  "test:size": "size-limit",
21
21
  "build-with-test": "yarn test && yarn run build",
22
- "build:cjs": "node ./build es5 && webpack && webpack --config ./webpack.config.dev.js",
23
- "build:esm": "node ./build es6",
24
- "build:cjs:watch": "node ./build es5 --watch",
25
- "build:esm:watch": "rimraf lib-esm && node ./build es6 --watch",
22
+ "build:cjs": "rimraf lib && tsc -m commonjs --outDir lib && webpack && webpack --config ./webpack.config.dev.js",
23
+ "build:esm": "rimraf lib-esm && tsc -m esnext --outDir lib-esm",
24
+ "build:cjs:watch": "rimraf lib && tsc -m commonjs --outDir lib --watch",
25
+ "build:esm:watch": "rimraf lib-esm && tsc -m esnext --outDir lib-esm --watch",
26
26
  "build": "yarn clean && yarn build:esm && yarn run build:cjs",
27
27
  "clean": "npm run clean:size && rimraf lib-esm lib dist",
28
28
  "clean:size": "rimraf dual-publish-tmp tmp*",
29
29
  "format": "echo \"Not implemented\"",
30
30
  "lint": "tslint '{__tests__,src}/**/*.ts' && npm run ts-coverage",
31
- "ts-coverage": "typescript-coverage-report -p ./tsconfig.build.json -t 86.56"
31
+ "ts-coverage": "typescript-coverage-report -p ./tsconfig.json -t 84.00"
32
+ },
33
+ "typesVersions": {
34
+ ">=4.2": {
35
+ "pinpoint": [
36
+ "./lib-esm/providers/pinpoint/AmazonLocationServiceProvider.d.ts"
37
+ ]
38
+ }
32
39
  },
33
40
  "repository": {
34
41
  "type": "git",
@@ -46,18 +53,24 @@
46
53
  "src"
47
54
  ],
48
55
  "dependencies": {
49
- "@aws-amplify/core": "5.8.6-api-v6-models.b3abc9b.0+b3abc9b",
50
- "@aws-sdk/client-location": "3.186.3",
56
+ "@aws-sdk/client-location": "3.398.0",
51
57
  "@turf/boolean-clockwise": "6.5.0",
52
58
  "camelcase-keys": "6.2.2",
53
- "tslib": "^1.8.0"
59
+ "tslib": "^2.5.0"
60
+ },
61
+ "peerDependencies": {
62
+ "@aws-amplify/core": "^6.0.0"
63
+ },
64
+ "devDependencies": {
65
+ "@aws-amplify/core": "6.0.0",
66
+ "typescript": "5.0.2"
54
67
  },
55
68
  "size-limit": [
56
69
  {
57
70
  "name": "Geo (top-level class)",
58
71
  "path": "./lib-esm/index.js",
59
72
  "import": "{ Amplify, Geo }",
60
- "limit": "52.12 kB"
73
+ "limit": "43.9 kB"
61
74
  }
62
75
  ],
63
76
  "jest": {
@@ -73,6 +86,7 @@
73
86
  "es2019.object"
74
87
  ],
75
88
  "allowJs": true,
89
+ "noEmitOnError": false,
76
90
  "esModuleInterop": true,
77
91
  "downlevelIteration": true
78
92
  }
@@ -107,11 +121,11 @@
107
121
  }
108
122
  },
109
123
  "coveragePathIgnorePatterns": [
110
- "/node_modules/",
124
+ "node_modules",
111
125
  "dist",
112
126
  "lib",
113
127
  "lib-esm"
114
128
  ]
115
129
  },
116
- "gitHead": "b3abc9b75f6f1353f4c2fbc10cd3369be498e9fc"
130
+ "gitHead": "d505105326d7f6214f6bd1e06eb20be3a3651377"
117
131
  }
package/src/Geo.ts CHANGED
@@ -1,11 +1,7 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
- import {
4
- Amplify,
5
- ConsoleLogger as Logger,
6
- parseAWSExports,
7
- } from '@aws-amplify/core';
8
- import { AmazonLocationServiceProvider } from './Providers/AmazonLocationServiceProvider';
3
+ import { Amplify, ConsoleLogger } from '@aws-amplify/core';
4
+ import { AmazonLocationServiceProvider } from './providers/location-service/AmazonLocationServiceProvider';
9
5
 
10
6
  import { validateCoordinates } from './util';
11
7
 
@@ -28,7 +24,7 @@ import {
28
24
  searchByPlaceIdOptions,
29
25
  } from './types';
30
26
 
31
- const logger = new Logger('Geo');
27
+ const logger = new ConsoleLogger('Geo');
32
28
 
33
29
  const DEFAULT_PROVIDER = 'AmazonLocationService';
34
30
  export class GeoClass {
@@ -42,6 +38,15 @@ export class GeoClass {
42
38
  constructor() {
43
39
  this._config = {};
44
40
  this._pluggables = [];
41
+
42
+ const amplifyConfig = Amplify.getConfig() ?? {};
43
+ this._config = Object.assign({}, this._config, amplifyConfig.Geo);
44
+
45
+ const locationProvider = new AmazonLocationServiceProvider(
46
+ amplifyConfig.Geo
47
+ );
48
+ this._pluggables.push(locationProvider);
49
+
45
50
  logger.debug('Geo Options', this._config);
46
51
  }
47
52
 
@@ -60,11 +65,6 @@ export class GeoClass {
60
65
  public addPluggable(pluggable: GeoProvider) {
61
66
  if (pluggable && pluggable.getCategory() === 'Geo') {
62
67
  this._pluggables.push(pluggable);
63
- const config = pluggable.configure(
64
- this._config[pluggable.getProviderName()]
65
- );
66
-
67
- return config;
68
68
  }
69
69
  }
70
70
 
@@ -93,29 +93,6 @@ export class GeoClass {
93
93
  return;
94
94
  }
95
95
 
96
- /**
97
- * Configure Geo
98
- * @param {Object} config - Configuration object for Geo
99
- * @return {Object} - Current configuration
100
- */
101
- configure(config?) {
102
- logger.debug('configure Geo');
103
-
104
- if (!config) return this._config;
105
-
106
- const amplifyConfig = parseAWSExports(config);
107
- this._config = Object.assign({}, this._config, amplifyConfig.Geo, config);
108
-
109
- this._pluggables.forEach(pluggable => {
110
- pluggable.configure(this._config[pluggable.getProviderName()]);
111
- });
112
-
113
- if (this._pluggables.length === 0) {
114
- this.addPluggable(new AmazonLocationServiceProvider());
115
- }
116
- return this._config;
117
- }
118
-
119
96
  /**
120
97
  * Get the map resources that are currently available through the provider
121
98
  * @param {string} provider
@@ -331,4 +308,3 @@ export class GeoClass {
331
308
  }
332
309
 
333
310
  export const Geo = new GeoClass();
334
- Amplify.register(Geo);
@@ -2,11 +2,8 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
  import camelcaseKeys from 'camelcase-keys';
4
4
 
5
- import {
6
- ConsoleLogger as Logger,
7
- Credentials,
8
- getAmplifyUserAgentObject,
9
- } from '@aws-amplify/core';
5
+ import { Amplify, fetchAuthSession, ConsoleLogger } from '@aws-amplify/core';
6
+ import { GeoAction } from '@aws-amplify/core/internals/utils';
10
7
  import {
11
8
  Place as PlaceResult,
12
9
  LocationClient,
@@ -35,10 +32,11 @@ import {
35
32
  } from '@aws-sdk/client-location';
36
33
 
37
34
  import {
35
+ getGeoUserAgent,
38
36
  mapSearchOptions,
39
37
  validateGeofenceId,
40
38
  validateGeofencesInput,
41
- } from '../util';
39
+ } from '../../util';
42
40
 
43
41
  import {
44
42
  GeoConfig,
@@ -60,9 +58,10 @@ import {
60
58
  GeofencePolygon,
61
59
  AmazonLocationServiceDeleteGeofencesResults,
62
60
  searchByPlaceIdOptions,
63
- } from '../types';
61
+ AmazonLocationServiceBatchGeofenceErrorMessages,
62
+ } from '../../types';
64
63
 
65
- const logger = new Logger('AmazonLocationServiceProvider');
64
+ const logger = new ConsoleLogger('AmazonLocationServiceProvider');
66
65
 
67
66
  export class AmazonLocationServiceProvider implements GeoProvider {
68
67
  static CATEGORY = 'Geo';
@@ -72,6 +71,7 @@ export class AmazonLocationServiceProvider implements GeoProvider {
72
71
  * @private
73
72
  */
74
73
  private _config;
74
+ private _credentials;
75
75
 
76
76
  /**
77
77
  * Initialize Geo with AWS configurations
@@ -98,18 +98,6 @@ export class AmazonLocationServiceProvider implements GeoProvider {
98
98
  return AmazonLocationServiceProvider.PROVIDER_NAME;
99
99
  }
100
100
 
101
- /**
102
- * Configure Geo part with aws configuration
103
- * @param {Object} config - Configuration of the Geo
104
- * @return {Object} - Current configuration
105
- */
106
- public configure(config?): object {
107
- logger.debug('configure Amazon Location Service Provider', config);
108
- if (!config) return this._config;
109
- this._config = Object.assign({}, this._config, config);
110
- return this._config;
111
- }
112
-
113
101
  /**
114
102
  * Get the map resources that are currently available through the provider
115
103
  * @returns {AmazonLocationServiceMapStyle[]}- Array of available map resources
@@ -179,9 +167,9 @@ export class AmazonLocationServiceProvider implements GeoProvider {
179
167
  }
180
168
 
181
169
  const client = new LocationClient({
182
- credentials: this._config.credentials,
170
+ credentials: this._credentials,
183
171
  region: this._config.region,
184
- customUserAgent: getAmplifyUserAgentObject(),
172
+ customUserAgent: getGeoUserAgent(GeoAction.SearchByText),
185
173
  });
186
174
  const command = new SearchPlaceIndexForTextCommand(locationServiceInput);
187
175
 
@@ -203,7 +191,7 @@ export class AmazonLocationServiceProvider implements GeoProvider {
203
191
  );
204
192
  const results: Place[] = camelcaseKeys(PascalResults, {
205
193
  deep: true,
206
- }) as undefined as Place[];
194
+ }) as unknown as Place[];
207
195
 
208
196
  return results;
209
197
  }
@@ -245,9 +233,9 @@ export class AmazonLocationServiceProvider implements GeoProvider {
245
233
  }
246
234
 
247
235
  const client = new LocationClient({
248
- credentials: this._config.credentials,
236
+ credentials: this._credentials,
249
237
  region: this._config.region,
250
- customUserAgent: getAmplifyUserAgentObject(),
238
+ customUserAgent: getGeoUserAgent(GeoAction.SearchForSuggestions),
251
239
  });
252
240
  const command = new SearchPlaceIndexForSuggestionsCommand(
253
241
  locationServiceInput
@@ -293,9 +281,9 @@ export class AmazonLocationServiceProvider implements GeoProvider {
293
281
  this._verifyPlaceId(placeId);
294
282
 
295
283
  const client = new LocationClient({
296
- credentials: this._config.credentials,
284
+ credentials: this._credentials,
297
285
  region: this._config.region,
298
- customUserAgent: getAmplifyUserAgentObject(),
286
+ customUserAgent: getGeoUserAgent(GeoAction.SearchByPlaceId),
299
287
  });
300
288
 
301
289
  const searchByPlaceIdInput: GetPlaceCommandInput = {
@@ -351,9 +339,9 @@ export class AmazonLocationServiceProvider implements GeoProvider {
351
339
  }
352
340
 
353
341
  const client = new LocationClient({
354
- credentials: this._config.credentials,
342
+ credentials: this._credentials,
355
343
  region: this._config.region,
356
- customUserAgent: getAmplifyUserAgentObject(),
344
+ customUserAgent: getGeoUserAgent(GeoAction.SearchByCoordinates),
357
345
  });
358
346
  const command = new SearchPlaceIndexForPositionCommand(
359
347
  locationServiceInput
@@ -448,10 +436,10 @@ export class AmazonLocationServiceProvider implements GeoProvider {
448
436
  // If the API call fails, add the geofences to the errors array and move to next batch
449
437
  batch.forEach(geofence => {
450
438
  results.errors.push({
451
- geofenceId: geofence.GeofenceId,
439
+ geofenceId: geofence.GeofenceId!,
452
440
  error: {
453
441
  code: 'APIConnectionError',
454
- message: error.message,
442
+ message: (error as Error).message,
455
443
  },
456
444
  });
457
445
  });
@@ -459,27 +447,25 @@ export class AmazonLocationServiceProvider implements GeoProvider {
459
447
  }
460
448
 
461
449
  // Push all successes to results
462
- response.Successes.forEach(success => {
450
+ response.Successes?.forEach(success => {
463
451
  const { GeofenceId, CreateTime, UpdateTime } = success;
464
452
  results.successes.push({
465
- geofenceId: GeofenceId,
453
+ geofenceId: GeofenceId!,
466
454
  createTime: CreateTime,
467
455
  updateTime: UpdateTime,
468
456
  });
469
457
  });
470
458
 
471
459
  // Push all errors to results
472
- response.Errors.forEach(error => {
473
- const {
474
- Error: { Code, Message },
475
- GeofenceId,
476
- } = error;
460
+ response.Errors?.forEach(error => {
461
+ const { Error, GeofenceId } = error;
462
+ const { Code, Message } = Error!;
477
463
  results.errors.push({
478
464
  error: {
479
- code: Code,
480
- message: Message,
465
+ code: Code!,
466
+ message: Message!,
481
467
  },
482
- geofenceId: GeofenceId,
468
+ geofenceId: GeofenceId!,
483
469
  });
484
470
  });
485
471
  })
@@ -515,9 +501,9 @@ export class AmazonLocationServiceProvider implements GeoProvider {
515
501
 
516
502
  // Create Amazon Location Service Client
517
503
  const client = new LocationClient({
518
- credentials: this._config.credentials,
504
+ credentials: this._credentials,
519
505
  region: this._config.region,
520
- customUserAgent: getAmplifyUserAgentObject(),
506
+ customUserAgent: getGeoUserAgent(GeoAction.GetGeofence),
521
507
  });
522
508
 
523
509
  // Create Amazon Location Service command
@@ -541,9 +527,9 @@ export class AmazonLocationServiceProvider implements GeoProvider {
541
527
  const { GeofenceId, CreateTime, UpdateTime, Status, Geometry } = response;
542
528
  const geofence: AmazonLocationServiceGeofence = {
543
529
  createTime: CreateTime,
544
- geofenceId: GeofenceId,
530
+ geofenceId: GeofenceId!,
545
531
  geometry: {
546
- polygon: Geometry.Polygon as GeofencePolygon,
532
+ polygon: Geometry!.Polygon as GeofencePolygon,
547
533
  },
548
534
  status: Status as AmazonLocationServiceGeofenceStatus,
549
535
  updateTime: UpdateTime,
@@ -577,9 +563,9 @@ export class AmazonLocationServiceProvider implements GeoProvider {
577
563
 
578
564
  // Create Amazon Location Service Client
579
565
  const client = new LocationClient({
580
- credentials: this._config.credentials,
566
+ credentials: this._credentials,
581
567
  region: this._config.region,
582
- customUserAgent: getAmplifyUserAgentObject(),
568
+ customUserAgent: getGeoUserAgent(GeoAction.ListGeofences),
583
569
  });
584
570
 
585
571
  // Create Amazon Location Service input
@@ -607,21 +593,15 @@ export class AmazonLocationServiceProvider implements GeoProvider {
607
593
  const { NextToken, Entries } = response;
608
594
 
609
595
  const results: ListGeofenceResults = {
610
- entries: Entries.map(
611
- ({
612
- GeofenceId,
613
- CreateTime,
614
- UpdateTime,
615
- Status,
616
- Geometry: { Polygon },
617
- }) => {
596
+ entries: Entries!.map(
597
+ ({ GeofenceId, CreateTime, UpdateTime, Status, Geometry }) => {
618
598
  return {
619
- geofenceId: GeofenceId,
599
+ geofenceId: GeofenceId!,
620
600
  createTime: CreateTime,
621
601
  updateTime: UpdateTime,
622
602
  status: Status,
623
603
  geometry: {
624
- polygon: Polygon as GeofencePolygon,
604
+ polygon: Geometry!.Polygon as GeofencePolygon,
625
605
  },
626
606
  };
627
607
  }
@@ -693,8 +673,10 @@ export class AmazonLocationServiceProvider implements GeoProvider {
693
673
  const errorObject = {
694
674
  geofenceId,
695
675
  error: {
696
- code: error.message,
697
- message: error.message,
676
+ code: (error as Error)
677
+ .message as AmazonLocationServiceBatchGeofenceErrorMessages,
678
+ message: (error as Error)
679
+ .message as AmazonLocationServiceBatchGeofenceErrorMessages,
698
680
  },
699
681
  };
700
682
  results.errors.push(errorObject);
@@ -718,11 +700,13 @@ export class AmazonLocationServiceProvider implements GeoProvider {
718
700
  */
719
701
  private async _ensureCredentials(): Promise<boolean> {
720
702
  try {
721
- const credentials = await Credentials.get();
703
+ const credentials = (await fetchAuthSession()).credentials;
722
704
  if (!credentials) return false;
723
- const cred = Credentials.shear(credentials);
724
- logger.debug('Set credentials for storage. Credentials are:', cred);
725
- this._config.credentials = cred;
705
+ logger.debug(
706
+ 'Set credentials for storage. Credentials are:',
707
+ credentials
708
+ );
709
+ this._credentials = credentials;
726
710
  return true;
727
711
  } catch (error) {
728
712
  logger.debug('Ensure credentials error. Credentials are:', error);
@@ -730,7 +714,18 @@ export class AmazonLocationServiceProvider implements GeoProvider {
730
714
  }
731
715
  }
732
716
 
717
+ private _refreshConfig() {
718
+ this._config = Amplify.getConfig().Geo?.LocationService;
719
+ if (!this._config) {
720
+ const errorString =
721
+ "No Geo configuration found in amplify config, run 'amplify add geo' to create one and run `amplify push` after";
722
+ logger.debug(errorString);
723
+ throw new Error(errorString);
724
+ }
725
+ }
726
+
733
727
  private _verifyMapResources() {
728
+ this._refreshConfig();
734
729
  if (!this._config.maps) {
735
730
  const errorString =
736
731
  "No map resources found in amplify config, run 'amplify add geo' to create one and run `amplify push` after";
@@ -746,8 +741,9 @@ export class AmazonLocationServiceProvider implements GeoProvider {
746
741
  }
747
742
 
748
743
  private _verifySearchIndex(optionalSearchIndex?: string) {
744
+ this._refreshConfig();
749
745
  if (
750
- (!this._config.search_indices || !this._config.search_indices.default) &&
746
+ (!this._config.searchIndices || !this._config.searchIndices.default) &&
751
747
  !optionalSearchIndex
752
748
  ) {
753
749
  const errorString =
@@ -758,6 +754,7 @@ export class AmazonLocationServiceProvider implements GeoProvider {
758
754
  }
759
755
 
760
756
  private _verifyGeofenceCollections(optionalGeofenceCollectionName?: string) {
757
+ this._refreshConfig();
761
758
  if (
762
759
  (!this._config.geofenceCollections ||
763
760
  !this._config.geofenceCollections.default) &&
@@ -782,9 +779,9 @@ export class AmazonLocationServiceProvider implements GeoProvider {
782
779
  };
783
780
 
784
781
  const client = new LocationClient({
785
- credentials: this._config.credentials,
782
+ credentials: this._credentials,
786
783
  region: this._config.region,
787
- customUserAgent: getAmplifyUserAgentObject(),
784
+ customUserAgent: getGeoUserAgent(GeoAction.SaveGeofences),
788
785
  });
789
786
  const command = new BatchPutGeofenceCommand(geofenceInput);
790
787
 
@@ -809,9 +806,9 @@ export class AmazonLocationServiceProvider implements GeoProvider {
809
806
  };
810
807
 
811
808
  const client = new LocationClient({
812
- credentials: this._config.credentials,
809
+ credentials: this._credentials,
813
810
  region: this._config.region,
814
- customUserAgent: getAmplifyUserAgentObject(),
811
+ customUserAgent: getGeoUserAgent(GeoAction.DeleteGeofences),
815
812
  });
816
813
  const command = new BatchDeleteGeofenceCommand(deleteGeofencesInput);
817
814