1 | import { AmplifyConfig } from './types';
|
2 | import { ConsoleLogger as Logger } from './Logger';
|
3 |
|
4 | const logger = new Logger('Parser');
|
5 |
|
6 | export const parseMobileHubConfig = (config): AmplifyConfig => {
|
7 | const amplifyConfig: AmplifyConfig = {};
|
8 |
|
9 | if (config['aws_mobile_analytics_app_id']) {
|
10 | const Analytics = {
|
11 | AWSPinpoint: {
|
12 | appId: config['aws_mobile_analytics_app_id'],
|
13 | region: config['aws_mobile_analytics_app_region'],
|
14 | },
|
15 | };
|
16 | amplifyConfig.Analytics = Analytics;
|
17 | }
|
18 |
|
19 |
|
20 | if (config['aws_cognito_identity_pool_id'] || config['aws_user_pools_id']) {
|
21 | amplifyConfig.Auth = {
|
22 | userPoolId: config['aws_user_pools_id'],
|
23 | userPoolWebClientId: config['aws_user_pools_web_client_id'],
|
24 | region: config['aws_cognito_region'],
|
25 | identityPoolId: config['aws_cognito_identity_pool_id'],
|
26 | identityPoolRegion: config['aws_cognito_region'],
|
27 | mandatorySignIn: config['aws_mandatory_sign_in'] === 'enable',
|
28 | signUpVerificationMethod:
|
29 | config['aws_cognito_sign_up_verification_method'] || 'code',
|
30 | };
|
31 | }
|
32 |
|
33 |
|
34 | let storageConfig;
|
35 | if (config['aws_user_files_s3_bucket']) {
|
36 | storageConfig = {
|
37 | AWSS3: {
|
38 | bucket: config['aws_user_files_s3_bucket'],
|
39 | region: config['aws_user_files_s3_bucket_region'],
|
40 | dangerouslyConnectToHttpEndpointForTesting:
|
41 | config[
|
42 | 'aws_user_files_s3_dangerously_connect_to_http_endpoint_for_testing'
|
43 | ],
|
44 | },
|
45 | };
|
46 | } else {
|
47 | storageConfig = config ? config.Storage || config : {};
|
48 | }
|
49 |
|
50 |
|
51 | if (config['Logging']) {
|
52 | amplifyConfig.Logging = {
|
53 | ...config['Logging'],
|
54 | region: config['aws_project_region'],
|
55 | };
|
56 | }
|
57 |
|
58 |
|
59 | if (config['geo']) {
|
60 | amplifyConfig.Geo = Object.assign({}, config.geo);
|
61 | if (config.geo['amazon_location_service']) {
|
62 | amplifyConfig.Geo = {
|
63 | AmazonLocationService: config.geo['amazon_location_service'],
|
64 | };
|
65 | }
|
66 | }
|
67 |
|
68 | amplifyConfig.Analytics = Object.assign(
|
69 | {},
|
70 | amplifyConfig.Analytics,
|
71 | config.Analytics
|
72 | );
|
73 | amplifyConfig.Auth = Object.assign({}, amplifyConfig.Auth, config.Auth);
|
74 | amplifyConfig.Storage = Object.assign({}, storageConfig);
|
75 | amplifyConfig.Logging = Object.assign(
|
76 | {},
|
77 | amplifyConfig.Logging,
|
78 | config.Logging
|
79 | );
|
80 | logger.debug('parse config', config, 'to amplifyconfig', amplifyConfig);
|
81 | return amplifyConfig;
|
82 | };
|
83 |
|
84 |
|
85 |
|
86 |
|
87 | export class Parser {
|
88 | static parseMobilehubConfig = parseMobileHubConfig;
|
89 | }
|
90 |
|
91 |
|
92 |
|
93 |
|
94 | export default Parser;
|