Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: custom user agent Geo changes for UI handoff #11632

Merged
merged 19 commits into from
Jul 27, 2023
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
ca34154
chore: copy Geo code into InternalGeo
erinleigh90 Jul 17, 2023
04659fe
feat: add geo actions
erinleigh90 Jul 17, 2023
db70cdb
feat: add customUserAgentDetails to geo provider
erinleigh90 Jul 17, 2023
f590271
feat: add customUserAgentDetails to public api's and send to service …
erinleigh90 Jul 17, 2023
2144f2e
feat: make Geo extend InternalGeo and override public API's
erinleigh90 Jul 17, 2023
cccf459
build: export InternalGeo from scoped geo/internals path
erinleigh90 Jul 17, 2023
b9f7284
Merge branch 'main' into feat/custom-user-agent-ui/geo
erinleigh90 Jul 18, 2023
7578ab1
chore: increase bundle size limits
erinleigh90 Jul 18, 2023
b33bf8c
chore: increase bundle size limits
erinleigh90 Jul 18, 2023
38af6b8
feat: add user agent param to action that was missed
erinleigh90 Jul 19, 2023
e70f689
chore: update doc-strings with new param
erinleigh90 Jul 19, 2023
b4986a0
chore: publish feature branch for testing
erinleigh90 Jul 19, 2023
3468be5
Feat/custom user agent UI/inappmessaging (#11656)
erinleigh90 Jul 19, 2023
f1cfed2
Merge branch 'feat/custom-user-agent-ui/main' into feat/custom-user-a…
erinleigh90 Jul 19, 2023
8c23228
Merge branch 'main' into feat/custom-user-agent-ui/geo
erinleigh90 Jul 26, 2023
70b51b5
Revert "Merge branch 'feat/custom-user-agent-ui/main' into feat/custo…
erinleigh90 Jul 26, 2023
7affbbb
chore: update jsdocs in AmazonLocationServiceProvider
erinleigh90 Jul 26, 2023
230d85f
Merge branch 'main' into feat/custom-user-agent-ui/geo
erinleigh90 Jul 26, 2023
4a02d4e
chore: increase bundle size limits:
erinleigh90 Jul 26, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1632,6 +1632,7 @@ releasable_branches: &releasable_branches
- release
- main
- next
- feat/custom-user-agent-ui/main

# List of test browsers that are always used in every E2E test. Tests that aren't expected to interact with browser APIs
# should use `minimal_browser_list` to keep test execution time low.
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"publish:next": "lerna publish --canary --force-publish \"*\" --yes --dist-tag=next --preid=next${PREID_HASH_SUFFIX} --exact --no-verify-access",
"publish:release": "lerna publish --conventional-commits --yes --message 'chore(release): Publish [ci skip]' --no-verify-access",
"publish:verdaccio": "lerna publish --no-push --canary minor --dist-tag=unstable --preid=unstable --exact --force-publish --yes --no-verify-access",
"publish:feat/custom-user-agent-ui/main": "lerna publish --canary --force-publish \"*\" --yes --dist-tag=v5-user-agent-for-ui --preid=v5-user-agent-for-ui${PREID_HASH_SUFFIX} --exact --no-verify-access",
"ts-coverage": "lerna run ts-coverage"
},
"husky": {
Expand Down
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-rest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"name": "API (rest client)",
"path": "./lib-esm/index.js",
"import": "{ Amplify, RestAPI }",
"limit": "30.94 kB"
"limit": "31.5 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.39 kB"
},
{
"name": "Core (Signer)",
Expand Down
11 changes: 10 additions & 1 deletion packages/core/src/Platform/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,19 @@ 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',
SyncMessages = '1',
IdentifyUser = '2',
}
export enum InteractionsAction {
None = '0',
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.6.0",
Expand All @@ -57,7 +58,7 @@
"name": "Geo (top-level class)",
"path": "./lib-esm/index.js",
"import": "{ Amplify, Geo }",
"limit": "51.72 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