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