Skip to content

Commit

Permalink
Merge branch 'main' into feat/custom-user-agent-ui/storage
Browse files Browse the repository at this point in the history
  • Loading branch information
erinleigh90 committed Jul 27, 2023
2 parents 6c64eea + 01bfa8f commit f034b54
Show file tree
Hide file tree
Showing 17 changed files with 513 additions and 245 deletions.
4 changes: 2 additions & 2 deletions packages/analytics/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@
"name": "Analytics (Pinpoint)",
"path": "./lib-esm/index.js",
"import": "{ Amplify, Analytics, AWSPinpointProvider }",
"limit": "31.1 kB"
"limit": "31.5 kB"
},
{
"name": "Analytics (Kinesis)",
"path": "./lib-esm/index.js",
"import": "{ Amplify, Analytics, AWSKinesisProvider }",
"limit": "60.4 kB"
"limit": "60.5 kB"
}
],
"jest": {
Expand Down
2 changes: 1 addition & 1 deletion packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"name": "API (top-level class)",
"path": "./lib-esm/index.js",
"import": "{ Amplify, API }",
"limit": "89 kB"
"limit": "89.07 kB"
}
],
"jest": {
Expand Down
2 changes: 1 addition & 1 deletion packages/auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"name": "Auth (top-level class)",
"path": "./lib-esm/index.js",
"import": "{ Amplify, Auth }",
"limit": "55.1 kB"
"limit": "55.15 kB"
}
],
"jest": {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
"name": "Core (Credentials)",
"path": "./lib-esm/index.js",
"import": "{ Credentials }",
"limit": "13.33 kB"
"limit": "13.45 kB"
},
{
"name": "Core (Signer)",
Expand Down
9 changes: 8 additions & 1 deletion packages/core/src/Platform/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,14 @@ export enum DataStoreAction {
GraphQl = '2',
}
export enum GeoAction {
None = '0',
SearchByText = '1',
SearchForSuggestions = '2',
SearchByPlaceId = '3',
SearchByCoordinates = '4',
SaveGeofences = '5',
GetGeofence = '6',
ListGeofences = '7',
DeleteGeofences = '8',
}
export enum InAppMessagingAction {
None = '0',
Expand Down
2 changes: 1 addition & 1 deletion packages/datastore/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"name": "DataStore (top-level class)",
"path": "./lib-esm/index.js",
"import": "{ Amplify, DataStore }",
"limit": "137 kB"
"limit": "137.1 kB"
}
],
"jest": {
Expand Down
8 changes: 8 additions & 0 deletions packages/geo/internals/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "@aws-amplify/geo/internals",
"types": "../lib-esm/internals/index.d.ts",
"main": "../lib/internals/index.js",
"module": "../lib-esm/internals/index.js",
"react-native": "../lib-esm/internals/index.js",
"sideEffects": false
}
5 changes: 3 additions & 2 deletions packages/geo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
"files": [
"lib",
"lib-esm",
"src"
"src",
"internals"
],
"dependencies": {
"@aws-amplify/core": "5.7.0",
Expand All @@ -57,7 +58,7 @@
"name": "Geo (top-level class)",
"path": "./lib-esm/index.js",
"import": "{ Amplify, Geo }",
"limit": "51.75 kB"
"limit": "52.1 kB"
}
],
"jest": {
Expand Down
214 changes: 11 additions & 203 deletions packages/geo/src/Geo.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,11 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import {
Amplify,
ConsoleLogger as Logger,
parseAWSExports,
} from '@aws-amplify/core';
import { AmazonLocationServiceProvider } from './Providers/AmazonLocationServiceProvider';

import { validateCoordinates } from './util';

import { Amplify, ConsoleLogger as Logger } from '@aws-amplify/core';
import {
Place,
GeoConfig,
Coordinates,
SearchByTextOptions,
SearchByCoordinatesOptions,
GeoProvider,
MapStyle,
GeofenceId,
GeofenceInput,
GeofenceOptions,
Expand All @@ -27,23 +16,10 @@ import {
DeleteGeofencesResults,
searchByPlaceIdOptions,
} from './types';
import { InternalGeoClass } from './internals/InternalGeo';

const logger = new Logger('Geo');

const DEFAULT_PROVIDER = 'AmazonLocationService';
export class GeoClass {
export class GeoClass extends InternalGeoClass {
static MODULE = 'Geo';
/**
* @private
*/
private _config: GeoConfig;
private _pluggables: GeoProvider[];

constructor() {
this._config = {};
this._pluggables = [];
logger.debug('Geo Options', this._config);
}

/**
* get the name of the module category
Expand All @@ -53,91 +29,6 @@ export class GeoClass {
return GeoClass.MODULE;
}

/**
* add plugin into Geo category
* @param {Object} pluggable - an instance of the plugin
*/
public addPluggable(pluggable: GeoProvider) {
if (pluggable && pluggable.getCategory() === 'Geo') {
this._pluggables.push(pluggable);
const config = pluggable.configure(
this._config[pluggable.getProviderName()]
);

return config;
}
}

/**
* Get the plugin object
* @param providerName - the name of the plugin
*/
public getPluggable(providerName: string) {
const pluggable = this._pluggables.find(
pluggable => pluggable.getProviderName() === providerName
);
if (pluggable === undefined) {
logger.debug('No plugin found with providerName', providerName);
throw new Error('No plugin found in Geo for the provider');
} else return pluggable;
}

/**
* Remove the plugin object
* @param providerName - the name of the plugin
*/
public removePluggable(providerName: string) {
this._pluggables = this._pluggables.filter(
pluggable => pluggable.getProviderName() !== providerName
);
return;
}

/**
* Configure Geo
* @param {Object} config - Configuration object for Geo
* @return {Object} - Current configuration
*/
configure(config?) {
logger.debug('configure Geo');

if (!config) return this._config;

const amplifyConfig = parseAWSExports(config);
this._config = Object.assign({}, this._config, amplifyConfig.Geo, config);

this._pluggables.forEach(pluggable => {
pluggable.configure(this._config[pluggable.getProviderName()]);
});

if (this._pluggables.length === 0) {
this.addPluggable(new AmazonLocationServiceProvider());
}
return this._config;
}

/**
* Get the map resources that are currently available through the provider
* @param {string} provider
* @returns - Array of available map resources
*/
public getAvailableMaps(provider = DEFAULT_PROVIDER): MapStyle[] {
const prov = this.getPluggable(provider);

return prov.getAvailableMaps();
}

/**
* Get the map resource set as default in amplify config
* @param {string} provider
* @returns - Map resource set as the default in amplify config
*/
public getDefaultMap(provider = DEFAULT_PROVIDER): MapStyle {
const prov = this.getPluggable(provider);

return prov.getDefaultMap();
}

/**
* Search by text input with optional parameters
* @param {string} text - The text string that is to be searched for
Expand All @@ -148,15 +39,7 @@ export class GeoClass {
text: string,
options?: SearchByTextOptions
): Promise<Place[]> {
const { providerName = DEFAULT_PROVIDER } = options || {};
const prov = this.getPluggable(providerName);

try {
return await prov.searchByText(text, options);
} catch (error) {
logger.debug(error);
throw error;
}
return super.searchByText(text, options);
}

/**
Expand All @@ -169,15 +52,7 @@ export class GeoClass {
text: string,
options?: SearchByTextOptions
) {
const { providerName = DEFAULT_PROVIDER } = options || {};
const prov = this.getPluggable(providerName);

try {
return await prov.searchForSuggestions(text, options);
} catch (error) {
logger.debug(error);
throw error;
}
return super.searchForSuggestions(text, options);
}

/**
Expand All @@ -190,15 +65,7 @@ export class GeoClass {
placeId: string,
options?: searchByPlaceIdOptions
) {
const providerName = DEFAULT_PROVIDER;
const prov = this.getPluggable(providerName);

try {
return await prov.searchByPlaceId(placeId, options);
} catch (error) {
logger.debug(error);
throw error;
}
return super.searchByPlaceId(placeId, options);
}

/**
Expand All @@ -211,17 +78,7 @@ export class GeoClass {
coordinates: Coordinates,
options?: SearchByCoordinatesOptions
): Promise<Place> {
const { providerName = DEFAULT_PROVIDER } = options || {};
const prov = this.getPluggable(providerName);

const [lng, lat] = coordinates;
try {
validateCoordinates(lng, lat);
return await prov.searchByCoordinates(coordinates, options);
} catch (error) {
logger.debug(error);
throw error;
}
return super.searchByCoordinates(coordinates, options);
}

/**
Expand All @@ -236,23 +93,7 @@ export class GeoClass {
geofences: GeofenceInput | GeofenceInput[],
options?: GeofenceOptions
): Promise<SaveGeofencesResults> {
const { providerName = DEFAULT_PROVIDER } = options || {};
const prov = this.getPluggable(providerName);

// If single geofence input, make it an array for batch call
let geofenceInputArray;
if (!Array.isArray(geofences)) {
geofenceInputArray = [geofences];
} else {
geofenceInputArray = geofences;
}

try {
return await prov.saveGeofences(geofenceInputArray, options);
} catch (error) {
logger.debug(error);
throw error;
}
return super.saveGeofences(geofences, options);
}

/**
Expand All @@ -265,15 +106,7 @@ export class GeoClass {
geofenceId: GeofenceId,
options?: GeofenceOptions
): Promise<Geofence> {
const { providerName = DEFAULT_PROVIDER } = options || {};
const prov = this.getPluggable(providerName);

try {
return await prov.getGeofence(geofenceId, options);
} catch (error) {
logger.debug(error);
throw error;
}
return super.getGeofence(geofenceId, options);
}

/**
Expand All @@ -286,15 +119,7 @@ export class GeoClass {
public async listGeofences(
options?: ListGeofenceOptions
): Promise<ListGeofenceResults> {
const { providerName = DEFAULT_PROVIDER } = options || {};
const prov = this.getPluggable(providerName);

try {
return await prov.listGeofences(options);
} catch (error) {
logger.debug(error);
throw error;
}
return super.listGeofences(options);
}

/**
Expand All @@ -309,24 +134,7 @@ export class GeoClass {
geofenceIds: string | string[],
options?: GeofenceOptions
): Promise<DeleteGeofencesResults> {
const { providerName = DEFAULT_PROVIDER } = options || {};
const prov = this.getPluggable(providerName);

// If single geofence input, make it an array for batch call
let geofenceIdsInputArray;
if (!Array.isArray(geofenceIds)) {
geofenceIdsInputArray = [geofenceIds];
} else {
geofenceIdsInputArray = geofenceIds;
}

// Delete geofences
try {
return await prov.deleteGeofences(geofenceIdsInputArray, options);
} catch (error) {
logger.debug(error);
throw error;
}
return super.deleteGeofences(geofenceIds, options);
}
}

Expand Down
Loading

0 comments on commit f034b54

Please sign in to comment.