Skip to content

Commit b1c3e0d

Browse files
author
Kamil Sobol
authored
cover geo in client config (#995)
* cover geo in client config * cover geo in client config
1 parent bded277 commit b1c3e0d

File tree

9 files changed

+163
-1
lines changed

9 files changed

+163
-1
lines changed

.changeset/angry-zebras-tease.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@aws-amplify/client-config': minor
3+
---
4+
5+
Add typings for geo category in client config

.eslint_dictionary.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"frontend",
4444
"frontends",
4545
"func",
46+
"geofence",
4647
"gitignore",
4748
"gitignored",
4849
"globals",

packages/client-config/API.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export type AuthClientConfig = {
3636
};
3737

3838
// @public
39-
export type ClientConfig = Partial<AuthClientConfig & GraphqlClientConfig & StorageClientConfig & PlatformClientConfig & CustomClientConfig>;
39+
export type ClientConfig = Partial<AuthClientConfig & GeoClientConfig & GraphqlClientConfig & StorageClientConfig & PlatformClientConfig & CustomClientConfig>;
4040

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

66+
// @public (undocumented)
67+
export type GeoClientConfig = {
68+
geo?: {
69+
amazon_location_service: {
70+
region: string;
71+
maps?: {
72+
items: Record<string, {
73+
style: string;
74+
}>;
75+
default: string;
76+
};
77+
search_indices?: {
78+
items: Array<string>;
79+
default: string;
80+
};
81+
geofenceCollections?: {
82+
items: Array<string>;
83+
default: string;
84+
};
85+
};
86+
};
87+
};
88+
6689
// @public
6790
export const getClientConfigPath: (outDir?: string, format?: ClientConfigFormat) => Promise<string>;
6891

packages/client-config/src/client-config-types/client_config.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ import { GraphqlClientConfig } from './graphql_client_config.js';
33
import { PlatformClientConfig } from './platform_client_config.js';
44
import { StorageClientConfig } from './storage_client_config.js';
55
import { CustomClientConfig } from './custom_client_config.js';
6+
import { GeoClientConfig } from './geo_client_config.js';
67

78
/**
89
* Merged type of all category client config types
910
*/
1011
export type ClientConfig = Partial<
1112
AuthClientConfig &
13+
GeoClientConfig &
1214
GraphqlClientConfig &
1315
StorageClientConfig &
1416
PlatformClientConfig &
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
export type GeoClientConfig = {
2+
geo?: {
3+
amazon_location_service: {
4+
region: string;
5+
maps?: {
6+
items: Record<
7+
string,
8+
{
9+
style: string;
10+
}
11+
>;
12+
default: string;
13+
};
14+
search_indices?: {
15+
items: Array<string>;
16+
default: string;
17+
};
18+
geofenceCollections?: {
19+
items: Array<string>;
20+
default: string;
21+
};
22+
};
23+
};
24+
};

packages/client-config/src/client-config-types/mobile/client_config_mobile_types.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export type ClientConfigMobile = {
33
Version: '1.0';
44
api?: ClientConfigMobileApi;
55
auth?: ClientConfigMobileAuth;
6+
geo?: ClientConfigMobileGeo;
67
};
78

89
export type ClientConfigMobileApi = {
@@ -68,3 +69,25 @@ export type ClientConfigMobileAuth = {
6869
};
6970
};
7071
};
72+
73+
export type ClientConfigMobileGeo = {
74+
plugins: {
75+
awsLocationGeoPlugin: {
76+
region: string;
77+
maps?: {
78+
items: Record<
79+
string,
80+
{
81+
style: string;
82+
}
83+
>;
84+
85+
default: string;
86+
};
87+
searchIndices?: {
88+
items: Array<string>;
89+
default: string;
90+
};
91+
};
92+
};
93+
};

packages/client-config/src/client-config-writer/client_config_converter.test.ts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,4 +219,64 @@ void describe('client config converter', () => {
219219

220220
assert.deepStrictEqual(expectedMobileConfig, actualMobileConfig);
221221
});
222+
223+
void it('converts geo config', () => {
224+
const clientConfig: ClientConfig = {
225+
geo: {
226+
amazon_location_service: {
227+
region: 'us-west-2',
228+
maps: {
229+
items: {
230+
map1: {
231+
style: 'style1',
232+
},
233+
map2: {
234+
style: 'style2',
235+
},
236+
},
237+
default: 'map1',
238+
},
239+
search_indices: {
240+
items: ['index1', 'index2'],
241+
default: 'index1',
242+
},
243+
// these are not in mobile schema, making sure this doesn't derail converter
244+
geofenceCollections: {
245+
items: ['geoFence1', 'geoFence2'],
246+
default: 'geoFence1',
247+
},
248+
},
249+
},
250+
};
251+
252+
const expectedMobileConfig: ClientConfigMobile = {
253+
UserAgent: 'test_package_name/test_package_version;',
254+
Version: '1.0',
255+
geo: {
256+
plugins: {
257+
awsLocationGeoPlugin: {
258+
maps: {
259+
default: 'map1',
260+
items: {
261+
map1: {
262+
style: 'style1',
263+
},
264+
map2: {
265+
style: 'style2',
266+
},
267+
},
268+
},
269+
region: 'us-west-2',
270+
searchIndices: {
271+
default: 'index1',
272+
items: ['index1', 'index2'],
273+
},
274+
},
275+
},
276+
},
277+
};
278+
const actualMobileConfig = converter.convertToMobileConfig(clientConfig);
279+
280+
assert.deepStrictEqual(expectedMobileConfig, actualMobileConfig);
281+
});
222282
});

packages/client-config/src/client-config-writer/client_config_converter.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
ClientConfigMobile,
44
ClientConfigMobileApi,
55
ClientConfigMobileAuth,
6+
ClientConfigMobileGeo,
67
} from '../client-config-types/mobile/client_config_mobile_types.js';
78

89
/**
@@ -121,6 +122,28 @@ export class ClientConfigConverter {
121122
}
122123
}
123124
}
125+
126+
if (clientConfig.geo) {
127+
const geoConfig: ClientConfigMobileGeo = {
128+
plugins: {
129+
awsLocationGeoPlugin: {
130+
region: clientConfig.geo.amazon_location_service.region,
131+
},
132+
},
133+
};
134+
135+
const maps = clientConfig.geo.amazon_location_service.maps;
136+
if (maps) {
137+
geoConfig.plugins.awsLocationGeoPlugin.maps = maps;
138+
}
139+
const searchIndices =
140+
clientConfig.geo.amazon_location_service.search_indices;
141+
if (searchIndices) {
142+
geoConfig.plugins.awsLocationGeoPlugin.searchIndices = searchIndices;
143+
}
144+
145+
mobileConfig.geo = geoConfig;
146+
}
124147
return mobileConfig;
125148
};
126149
}

packages/client-config/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ export * from './generate_client_config.js';
22
export * from './generate_client_config_to_file.js';
33
export * from './client-config-types/client_config.js';
44
export * from './client-config-types/auth_client_config.js';
5+
export * from './client-config-types/geo_client_config.js';
56
export * from './client-config-types/custom_client_config.js';
67
export * from './client-config-types/graphql_client_config.js';
78
export * from './client-config-types/storage_client_config.js';

0 commit comments

Comments
 (0)