Skip to content

Commit

Permalink
cover geo in client config (aws-amplify#995)
Browse files Browse the repository at this point in the history
* cover geo in client config

* cover geo in client config
  • Loading branch information
sobolk authored Feb 6, 2024
1 parent bded277 commit b1c3e0d
Show file tree
Hide file tree
Showing 9 changed files with 163 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/angry-zebras-tease.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@aws-amplify/client-config': minor
---

Add typings for geo category in client config
1 change: 1 addition & 0 deletions .eslint_dictionary.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"frontend",
"frontends",
"func",
"geofence",
"gitignore",
"gitignored",
"globals",
Expand Down
25 changes: 24 additions & 1 deletion packages/client-config/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export type AuthClientConfig = {
};

// @public
export type ClientConfig = Partial<AuthClientConfig & GraphqlClientConfig & StorageClientConfig & PlatformClientConfig & CustomClientConfig>;
export type ClientConfig = Partial<AuthClientConfig & GeoClientConfig & GraphqlClientConfig & StorageClientConfig & PlatformClientConfig & CustomClientConfig>;

// @public (undocumented)
export enum ClientConfigFormat {
Expand All @@ -63,6 +63,29 @@ export const generateClientConfig: (credentialProvider: AwsCredentialIdentityPro
// @public
export const generateClientConfigToFile: (credentialProvider: AwsCredentialIdentityProvider, backendIdentifier: DeployedBackendIdentifier, outDir?: string, format?: ClientConfigFormat, log?: ((message: string) => void) | undefined) => Promise<void>;

// @public (undocumented)
export type GeoClientConfig = {
geo?: {
amazon_location_service: {
region: string;
maps?: {
items: Record<string, {
style: string;
}>;
default: string;
};
search_indices?: {
items: Array<string>;
default: string;
};
geofenceCollections?: {
items: Array<string>;
default: string;
};
};
};
};

// @public
export const getClientConfigPath: (outDir?: string, format?: ClientConfigFormat) => Promise<string>;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ import { GraphqlClientConfig } from './graphql_client_config.js';
import { PlatformClientConfig } from './platform_client_config.js';
import { StorageClientConfig } from './storage_client_config.js';
import { CustomClientConfig } from './custom_client_config.js';
import { GeoClientConfig } from './geo_client_config.js';

/**
* Merged type of all category client config types
*/
export type ClientConfig = Partial<
AuthClientConfig &
GeoClientConfig &
GraphqlClientConfig &
StorageClientConfig &
PlatformClientConfig &
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
export type GeoClientConfig = {
geo?: {
amazon_location_service: {
region: string;
maps?: {
items: Record<
string,
{
style: string;
}
>;
default: string;
};
search_indices?: {
items: Array<string>;
default: string;
};
geofenceCollections?: {
items: Array<string>;
default: string;
};
};
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export type ClientConfigMobile = {
Version: '1.0';
api?: ClientConfigMobileApi;
auth?: ClientConfigMobileAuth;
geo?: ClientConfigMobileGeo;
};

export type ClientConfigMobileApi = {
Expand Down Expand Up @@ -68,3 +69,25 @@ export type ClientConfigMobileAuth = {
};
};
};

export type ClientConfigMobileGeo = {
plugins: {
awsLocationGeoPlugin: {
region: string;
maps?: {
items: Record<
string,
{
style: string;
}
>;

default: string;
};
searchIndices?: {
items: Array<string>;
default: string;
};
};
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -219,4 +219,64 @@ void describe('client config converter', () => {

assert.deepStrictEqual(expectedMobileConfig, actualMobileConfig);
});

void it('converts geo config', () => {
const clientConfig: ClientConfig = {
geo: {
amazon_location_service: {
region: 'us-west-2',
maps: {
items: {
map1: {
style: 'style1',
},
map2: {
style: 'style2',
},
},
default: 'map1',
},
search_indices: {
items: ['index1', 'index2'],
default: 'index1',
},
// these are not in mobile schema, making sure this doesn't derail converter
geofenceCollections: {
items: ['geoFence1', 'geoFence2'],
default: 'geoFence1',
},
},
},
};

const expectedMobileConfig: ClientConfigMobile = {
UserAgent: 'test_package_name/test_package_version;',
Version: '1.0',
geo: {
plugins: {
awsLocationGeoPlugin: {
maps: {
default: 'map1',
items: {
map1: {
style: 'style1',
},
map2: {
style: 'style2',
},
},
},
region: 'us-west-2',
searchIndices: {
default: 'index1',
items: ['index1', 'index2'],
},
},
},
},
};
const actualMobileConfig = converter.convertToMobileConfig(clientConfig);

assert.deepStrictEqual(expectedMobileConfig, actualMobileConfig);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
ClientConfigMobile,
ClientConfigMobileApi,
ClientConfigMobileAuth,
ClientConfigMobileGeo,
} from '../client-config-types/mobile/client_config_mobile_types.js';

/**
Expand Down Expand Up @@ -121,6 +122,28 @@ export class ClientConfigConverter {
}
}
}

if (clientConfig.geo) {
const geoConfig: ClientConfigMobileGeo = {
plugins: {
awsLocationGeoPlugin: {
region: clientConfig.geo.amazon_location_service.region,
},
},
};

const maps = clientConfig.geo.amazon_location_service.maps;
if (maps) {
geoConfig.plugins.awsLocationGeoPlugin.maps = maps;
}
const searchIndices =
clientConfig.geo.amazon_location_service.search_indices;
if (searchIndices) {
geoConfig.plugins.awsLocationGeoPlugin.searchIndices = searchIndices;
}

mobileConfig.geo = geoConfig;
}
return mobileConfig;
};
}
1 change: 1 addition & 0 deletions packages/client-config/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export * from './generate_client_config.js';
export * from './generate_client_config_to_file.js';
export * from './client-config-types/client_config.js';
export * from './client-config-types/auth_client_config.js';
export * from './client-config-types/geo_client_config.js';
export * from './client-config-types/custom_client_config.js';
export * from './client-config-types/graphql_client_config.js';
export * from './client-config-types/storage_client_config.js';
Expand Down

0 comments on commit b1c3e0d

Please sign in to comment.