@aws-amplify/core 6.0.29-unstable.d0fdfa6.0 → 6.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/Platform/version.js +1 -1
- package/dist/cjs/Platform/version.js.map +1 -1
- package/dist/cjs/libraryUtils.js +7 -2
- package/dist/cjs/libraryUtils.js.map +1 -1
- package/dist/cjs/parseAWSExports.js +8 -9
- package/dist/cjs/parseAWSExports.js.map +1 -1
- package/dist/cjs/parseAmplifyOutputs.js +215 -0
- package/dist/cjs/parseAmplifyOutputs.js.map +1 -0
- package/dist/cjs/singleton/Amplify.js +2 -8
- package/dist/cjs/singleton/Amplify.js.map +1 -1
- package/dist/cjs/singleton/AmplifyOutputs/types.js +6 -0
- package/dist/cjs/singleton/AmplifyOutputs/types.js.map +1 -0
- package/dist/cjs/utils/parseAmplifyConfig.js +27 -0
- package/dist/cjs/utils/parseAmplifyConfig.js.map +1 -0
- package/dist/esm/Platform/version.d.ts +1 -1
- package/dist/esm/Platform/version.mjs +1 -1
- package/dist/esm/Platform/version.mjs.map +1 -1
- package/dist/esm/libraryUtils.d.ts +3 -0
- package/dist/esm/libraryUtils.mjs +2 -0
- package/dist/esm/libraryUtils.mjs.map +1 -1
- package/dist/esm/parseAWSExports.mjs +8 -9
- package/dist/esm/parseAWSExports.mjs.map +1 -1
- package/dist/esm/parseAmplifyOutputs.d.ts +5 -0
- package/dist/esm/parseAmplifyOutputs.mjs +210 -0
- package/dist/esm/parseAmplifyOutputs.mjs.map +1 -0
- package/dist/esm/singleton/API/types.d.ts +3 -4
- package/dist/esm/singleton/Amplify.d.ts +2 -2
- package/dist/esm/singleton/Amplify.mjs +15 -9
- package/dist/esm/singleton/Amplify.mjs.map +1 -1
- package/dist/esm/singleton/AmplifyOutputs/types.d.ts +80 -0
- package/dist/esm/singleton/AmplifyOutputs/types.mjs +2 -0
- package/dist/esm/singleton/AmplifyOutputs/types.mjs.map +1 -0
- package/dist/esm/singleton/Auth/types.d.ts +2 -1
- package/dist/esm/singleton/Storage/types.d.ts +10 -0
- package/dist/esm/singleton/types.d.ts +1 -0
- package/dist/esm/utils/parseAmplifyConfig.d.ts +10 -0
- package/dist/esm/utils/parseAmplifyConfig.mjs +25 -0
- package/dist/esm/utils/parseAmplifyConfig.mjs.map +1 -0
- package/package.json +3 -3
- package/src/Platform/version.ts +1 -1
- package/src/libraryUtils.ts +4 -0
- package/src/parseAWSExports.ts +8 -9
- package/src/parseAmplifyOutputs.ts +333 -0
- package/src/singleton/API/types.ts +4 -2
- package/src/singleton/Amplify.ts +4 -9
- package/src/singleton/AmplifyOutputs/types.ts +99 -0
- package/src/singleton/Auth/types.ts +3 -1
- package/src/singleton/Storage/types.ts +10 -0
- package/src/singleton/types.ts +2 -0
- package/src/utils/parseAmplifyConfig.ts +26 -0
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { AtLeastOne } from '../types';
|
|
2
|
+
/** @deprecated This may be removed in the next major version. */
|
|
2
3
|
export type StorageAccessLevel = 'guest' | 'protected' | 'private';
|
|
3
4
|
export interface S3ProviderConfig {
|
|
4
5
|
S3: {
|
|
@@ -13,13 +14,22 @@ export interface S3ProviderConfig {
|
|
|
13
14
|
};
|
|
14
15
|
}
|
|
15
16
|
export type StorageConfig = AtLeastOne<S3ProviderConfig>;
|
|
17
|
+
/** @deprecated This may be removed in the next major version. */
|
|
16
18
|
type StoragePrefixResolver = (params: {
|
|
17
19
|
accessLevel: StorageAccessLevel;
|
|
18
20
|
targetIdentityId?: string;
|
|
19
21
|
}) => Promise<string>;
|
|
20
22
|
export interface LibraryStorageOptions {
|
|
21
23
|
S3: {
|
|
24
|
+
/**
|
|
25
|
+
* @deprecated This may be removed in the next major version.
|
|
26
|
+
* This is currently used for Storage API signature using key as input parameter.
|
|
27
|
+
* */
|
|
22
28
|
prefixResolver?: StoragePrefixResolver;
|
|
29
|
+
/**
|
|
30
|
+
* @deprecated This may be removed in the next major version.
|
|
31
|
+
* This is currently used for Storage API signature using key as input parameter.
|
|
32
|
+
* */
|
|
23
33
|
defaultAccessLevel?: StorageAccessLevel;
|
|
24
34
|
isObjectLockEnabled?: boolean;
|
|
25
35
|
};
|
|
@@ -6,6 +6,7 @@ import { PredictionsConfig } from './Predictions/types';
|
|
|
6
6
|
import { LibraryStorageOptions, StorageAccessLevel, StorageConfig } from './Storage/types';
|
|
7
7
|
import { NotificationsConfig } from './Notifications/types';
|
|
8
8
|
import { InteractionsConfig } from './Interactions/types';
|
|
9
|
+
export { AmplifyOutputs } from './AmplifyOutputs/types';
|
|
9
10
|
/**
|
|
10
11
|
* Compatibility type representing the Amplify Gen 1 configuration file schema. This type should not be used directly.
|
|
11
12
|
*/
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ResourcesConfig } from '../index';
|
|
2
|
+
import { AmplifyOutputs } from '../singleton/AmplifyOutputs/types';
|
|
3
|
+
import { LegacyConfig } from '../singleton/types';
|
|
4
|
+
/**
|
|
5
|
+
* Parses the variety of configuration shapes that Amplify can accept into a ResourcesConfig.
|
|
6
|
+
*
|
|
7
|
+
* @param amplifyConfig An Amplify configuration object conforming to one of the supported schemas.
|
|
8
|
+
* @return A ResourcesConfig for the provided configuration object.
|
|
9
|
+
*/
|
|
10
|
+
export declare const parseAmplifyConfig: (amplifyConfig: ResourcesConfig | LegacyConfig | AmplifyOutputs) => ResourcesConfig;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { parseAWSExports } from '../parseAWSExports.mjs';
|
|
2
|
+
import { isAmplifyOutputs, parseAmplifyOutputs } from '../parseAmplifyOutputs.mjs';
|
|
3
|
+
|
|
4
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
5
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
6
|
+
/**
|
|
7
|
+
* Parses the variety of configuration shapes that Amplify can accept into a ResourcesConfig.
|
|
8
|
+
*
|
|
9
|
+
* @param amplifyConfig An Amplify configuration object conforming to one of the supported schemas.
|
|
10
|
+
* @return A ResourcesConfig for the provided configuration object.
|
|
11
|
+
*/
|
|
12
|
+
const parseAmplifyConfig = (amplifyConfig) => {
|
|
13
|
+
if (Object.keys(amplifyConfig).some(key => key.startsWith('aws_'))) {
|
|
14
|
+
return parseAWSExports(amplifyConfig);
|
|
15
|
+
}
|
|
16
|
+
else if (isAmplifyOutputs(amplifyConfig)) {
|
|
17
|
+
return parseAmplifyOutputs(amplifyConfig);
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
return amplifyConfig;
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export { parseAmplifyConfig };
|
|
25
|
+
//# sourceMappingURL=parseAmplifyConfig.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parseAmplifyConfig.mjs","sources":["../../../src/utils/parseAmplifyConfig.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { parseAWSExports } from '../parseAWSExports';\nimport { isAmplifyOutputs, parseAmplifyOutputs } from '../parseAmplifyOutputs';\n/**\n * Parses the variety of configuration shapes that Amplify can accept into a ResourcesConfig.\n *\n * @param amplifyConfig An Amplify configuration object conforming to one of the supported schemas.\n * @return A ResourcesConfig for the provided configuration object.\n */\nexport const parseAmplifyConfig = (amplifyConfig) => {\n if (Object.keys(amplifyConfig).some(key => key.startsWith('aws_'))) {\n return parseAWSExports(amplifyConfig);\n }\n else if (isAmplifyOutputs(amplifyConfig)) {\n return parseAmplifyOutputs(amplifyConfig);\n }\n else {\n return amplifyConfig;\n }\n};\n"],"names":[],"mappings":";;;AAAA;AACA;AAGA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,kBAAkB,GAAG,CAAC,aAAa,KAAK;AACrD,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,IAAI,CAAC,GAAG,IAAI,GAAG,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,EAAE;AACxE,QAAQ,OAAO,eAAe,CAAC,aAAa,CAAC,CAAC;AAC9C,KAAK;AACL,SAAS,IAAI,gBAAgB,CAAC,aAAa,CAAC,EAAE;AAC9C,QAAQ,OAAO,mBAAmB,CAAC,aAAa,CAAC,CAAC;AAClD,KAAK;AACL,SAAS;AACT,QAAQ,OAAO,aAAa,CAAC;AAC7B,KAAK;AACL;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aws-amplify/core",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.1.0",
|
|
4
4
|
"description": "Core category of aws-amplify",
|
|
5
5
|
"main": "./dist/cjs/index.js",
|
|
6
6
|
"module": "./dist/esm/index.mjs",
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"uuid": "^9.0.0"
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
|
-
"@aws-amplify/react-native": "1.0.
|
|
63
|
+
"@aws-amplify/react-native": "1.0.28",
|
|
64
64
|
"@types/js-cookie": "3.0.2",
|
|
65
65
|
"genversion": "^2.2.0",
|
|
66
66
|
"typescript": "5.0.2"
|
|
@@ -192,5 +192,5 @@
|
|
|
192
192
|
]
|
|
193
193
|
}
|
|
194
194
|
},
|
|
195
|
-
"gitHead": "
|
|
195
|
+
"gitHead": "0cc3ea9027fdb5d35b3c32e183555c51652da62f"
|
|
196
196
|
}
|
package/src/Platform/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// generated by genversion
|
|
2
|
-
export const version = '6.
|
|
2
|
+
export const version = '6.2.0';
|
package/src/libraryUtils.ts
CHANGED
|
@@ -21,11 +21,15 @@ export {
|
|
|
21
21
|
deDupeAsyncFunction,
|
|
22
22
|
} from './utils';
|
|
23
23
|
export { parseAWSExports } from './parseAWSExports';
|
|
24
|
+
export { isAmplifyOutputs, parseAmplifyOutputs } from './parseAmplifyOutputs';
|
|
24
25
|
export { LegacyConfig } from './singleton/types';
|
|
26
|
+
export { AmplifyOutputs } from './singleton/AmplifyOutputs/types';
|
|
25
27
|
export { ADD_OAUTH_LISTENER } from './singleton/constants';
|
|
26
28
|
export { amplifyUuid } from './utils/amplifyUuid';
|
|
27
29
|
export { AmplifyUrl, AmplifyUrlSearchParams } from './utils/amplifyUrl';
|
|
30
|
+
export { parseAmplifyConfig } from './utils/parseAmplifyConfig';
|
|
28
31
|
export { getClientInfo } from './utils';
|
|
32
|
+
|
|
29
33
|
// Auth utilities
|
|
30
34
|
export {
|
|
31
35
|
decodeJWT,
|
package/src/parseAWSExports.ts
CHANGED
|
@@ -249,15 +249,14 @@ export const parseAWSExports = (
|
|
|
249
249
|
// Geo
|
|
250
250
|
if (geo) {
|
|
251
251
|
const { amazon_location_service } = geo;
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
: { ...geo };
|
|
252
|
+
amplifyConfig.Geo = {
|
|
253
|
+
LocationService: {
|
|
254
|
+
maps: amazon_location_service.maps,
|
|
255
|
+
geofenceCollections: amazon_location_service.geofenceCollections,
|
|
256
|
+
searchIndices: amazon_location_service.search_indices,
|
|
257
|
+
region: amazon_location_service.region,
|
|
258
|
+
},
|
|
259
|
+
};
|
|
261
260
|
}
|
|
262
261
|
|
|
263
262
|
// REST API
|
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
/* This is because JSON schema contains keys with snake_case */
|
|
5
|
+
/* eslint-disable camelcase */
|
|
6
|
+
|
|
7
|
+
/* Does not like exahaustive checks */
|
|
8
|
+
/* eslint-disable no-case-declarations */
|
|
9
|
+
|
|
10
|
+
import {
|
|
11
|
+
APIConfig,
|
|
12
|
+
APIGraphQLConfig,
|
|
13
|
+
GraphQLAuthMode,
|
|
14
|
+
ModelIntrospectionSchema,
|
|
15
|
+
} from './singleton/API/types';
|
|
16
|
+
import {
|
|
17
|
+
CognitoUserPoolConfigMfaStatus,
|
|
18
|
+
OAuthProvider,
|
|
19
|
+
} from './singleton/Auth/types';
|
|
20
|
+
import { NotificationsConfig } from './singleton/Notifications/types';
|
|
21
|
+
import {
|
|
22
|
+
AmplifyOutputs,
|
|
23
|
+
AmplifyOutputsAnalyticsProperties,
|
|
24
|
+
AmplifyOutputsAuthProperties,
|
|
25
|
+
AmplifyOutputsDataProperties,
|
|
26
|
+
AmplifyOutputsGeoProperties,
|
|
27
|
+
AmplifyOutputsNotificationsProperties,
|
|
28
|
+
AmplifyOutputsStorageProperties,
|
|
29
|
+
} from './singleton/AmplifyOutputs/types';
|
|
30
|
+
import {
|
|
31
|
+
AnalyticsConfig,
|
|
32
|
+
AuthConfig,
|
|
33
|
+
GeoConfig,
|
|
34
|
+
LegacyConfig,
|
|
35
|
+
ResourcesConfig,
|
|
36
|
+
StorageConfig,
|
|
37
|
+
} from './singleton/types';
|
|
38
|
+
|
|
39
|
+
export function isAmplifyOutputs(
|
|
40
|
+
config: ResourcesConfig | LegacyConfig | AmplifyOutputs,
|
|
41
|
+
): config is AmplifyOutputs {
|
|
42
|
+
// version format initially will be '1' but is expected to be something like x.y where x is major and y minor version
|
|
43
|
+
const { version } = config as AmplifyOutputs;
|
|
44
|
+
|
|
45
|
+
if (!version) {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return version.startsWith('1');
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function parseStorage(
|
|
53
|
+
amplifyOutputsStorageProperties?: AmplifyOutputsStorageProperties,
|
|
54
|
+
): StorageConfig | undefined {
|
|
55
|
+
if (!amplifyOutputsStorageProperties) {
|
|
56
|
+
return undefined;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const { bucket_name, aws_region } = amplifyOutputsStorageProperties;
|
|
60
|
+
|
|
61
|
+
return {
|
|
62
|
+
S3: {
|
|
63
|
+
bucket: bucket_name,
|
|
64
|
+
region: aws_region,
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function parseAuth(
|
|
70
|
+
amplifyOutputsAuthProperties?: AmplifyOutputsAuthProperties,
|
|
71
|
+
): AuthConfig | undefined {
|
|
72
|
+
if (!amplifyOutputsAuthProperties) {
|
|
73
|
+
return undefined;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const {
|
|
77
|
+
user_pool_id,
|
|
78
|
+
user_pool_client_id,
|
|
79
|
+
identity_pool_id,
|
|
80
|
+
password_policy,
|
|
81
|
+
mfa_configuration,
|
|
82
|
+
mfa_methods,
|
|
83
|
+
unauthenticated_identities_enabled,
|
|
84
|
+
oauth,
|
|
85
|
+
username_attributes,
|
|
86
|
+
standard_required_attributes,
|
|
87
|
+
} = amplifyOutputsAuthProperties;
|
|
88
|
+
|
|
89
|
+
const authConfig = {
|
|
90
|
+
Cognito: {
|
|
91
|
+
userPoolId: user_pool_id,
|
|
92
|
+
userPoolClientId: user_pool_client_id,
|
|
93
|
+
},
|
|
94
|
+
} as AuthConfig;
|
|
95
|
+
|
|
96
|
+
if (identity_pool_id) {
|
|
97
|
+
authConfig.Cognito = {
|
|
98
|
+
...authConfig.Cognito,
|
|
99
|
+
identityPoolId: identity_pool_id,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if (password_policy) {
|
|
104
|
+
authConfig.Cognito.passwordFormat = {
|
|
105
|
+
requireLowercase: password_policy.require_lowercase,
|
|
106
|
+
requireNumbers: password_policy.require_numbers,
|
|
107
|
+
requireUppercase: password_policy.require_uppercase,
|
|
108
|
+
requireSpecialCharacters: password_policy.require_symbols,
|
|
109
|
+
minLength: password_policy.min_length ?? 6,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
if (mfa_configuration) {
|
|
114
|
+
authConfig.Cognito.mfa = {
|
|
115
|
+
status: getMfaStatus(mfa_configuration),
|
|
116
|
+
smsEnabled: mfa_methods?.includes('SMS'),
|
|
117
|
+
totpEnabled: mfa_methods?.includes('TOTP'),
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (unauthenticated_identities_enabled) {
|
|
122
|
+
authConfig.Cognito.allowGuestAccess = unauthenticated_identities_enabled;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (oauth) {
|
|
126
|
+
authConfig.Cognito.loginWith = {
|
|
127
|
+
oauth: {
|
|
128
|
+
domain: oauth.domain,
|
|
129
|
+
redirectSignIn: oauth.redirect_sign_in_uri,
|
|
130
|
+
redirectSignOut: oauth.redirect_sign_out_uri,
|
|
131
|
+
responseType: oauth.response_type === 'token' ? 'token' : 'code',
|
|
132
|
+
scopes: oauth.scopes,
|
|
133
|
+
providers: getOAuthProviders(oauth.identity_providers),
|
|
134
|
+
},
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if (username_attributes?.includes('email')) {
|
|
139
|
+
authConfig.Cognito.loginWith = {
|
|
140
|
+
...authConfig.Cognito.loginWith,
|
|
141
|
+
email: true,
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
if (username_attributes?.includes('phone_number')) {
|
|
146
|
+
authConfig.Cognito.loginWith = {
|
|
147
|
+
...authConfig.Cognito.loginWith,
|
|
148
|
+
phone: true,
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
if (standard_required_attributes) {
|
|
153
|
+
authConfig.Cognito.userAttributes = standard_required_attributes.reduce(
|
|
154
|
+
(acc, curr) => ({ ...acc, [curr]: { required: true } }),
|
|
155
|
+
{},
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
return authConfig;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export function parseAnalytics(
|
|
163
|
+
amplifyOutputsAnalyticsProperties?: AmplifyOutputsAnalyticsProperties,
|
|
164
|
+
): AnalyticsConfig | undefined {
|
|
165
|
+
if (!amplifyOutputsAnalyticsProperties?.amazon_pinpoint) {
|
|
166
|
+
return undefined;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
const { amazon_pinpoint } = amplifyOutputsAnalyticsProperties;
|
|
170
|
+
|
|
171
|
+
return {
|
|
172
|
+
Pinpoint: {
|
|
173
|
+
appId: amazon_pinpoint.app_id,
|
|
174
|
+
region: amazon_pinpoint.aws_region,
|
|
175
|
+
},
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function parseGeo(
|
|
180
|
+
amplifyOutputsAnalyticsProperties?: AmplifyOutputsGeoProperties,
|
|
181
|
+
): GeoConfig | undefined {
|
|
182
|
+
if (!amplifyOutputsAnalyticsProperties) {
|
|
183
|
+
return undefined;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
const { aws_region, geofence_collections, maps, search_indices } =
|
|
187
|
+
amplifyOutputsAnalyticsProperties;
|
|
188
|
+
|
|
189
|
+
return {
|
|
190
|
+
LocationService: {
|
|
191
|
+
region: aws_region,
|
|
192
|
+
searchIndices: search_indices,
|
|
193
|
+
geofenceCollections: geofence_collections,
|
|
194
|
+
maps,
|
|
195
|
+
},
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
function parseData(
|
|
200
|
+
amplifyOutputsDataProperties?: AmplifyOutputsDataProperties,
|
|
201
|
+
): APIConfig | undefined {
|
|
202
|
+
if (!amplifyOutputsDataProperties) {
|
|
203
|
+
return undefined;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
const {
|
|
207
|
+
aws_region,
|
|
208
|
+
default_authorization_type,
|
|
209
|
+
url,
|
|
210
|
+
api_key,
|
|
211
|
+
model_introspection,
|
|
212
|
+
} = amplifyOutputsDataProperties;
|
|
213
|
+
|
|
214
|
+
const GraphQL: APIGraphQLConfig = {
|
|
215
|
+
endpoint: url,
|
|
216
|
+
defaultAuthMode: getGraphQLAuthMode(default_authorization_type),
|
|
217
|
+
region: aws_region,
|
|
218
|
+
apiKey: api_key,
|
|
219
|
+
modelIntrospection: model_introspection as ModelIntrospectionSchema,
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
return {
|
|
223
|
+
GraphQL,
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
function parseNotifications(
|
|
228
|
+
amplifyOutputsNotificationsProperties?: AmplifyOutputsNotificationsProperties,
|
|
229
|
+
): NotificationsConfig | undefined {
|
|
230
|
+
if (!amplifyOutputsNotificationsProperties) {
|
|
231
|
+
return undefined;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
const { aws_region, channels, amazon_pinpoint_app_id } =
|
|
235
|
+
amplifyOutputsNotificationsProperties;
|
|
236
|
+
|
|
237
|
+
const hasInAppMessaging = channels.includes('IN_APP_MESSAGING');
|
|
238
|
+
const hasPushNotification =
|
|
239
|
+
channels.includes('APNS') || channels.includes('FCM');
|
|
240
|
+
|
|
241
|
+
if (!(hasInAppMessaging || hasPushNotification)) {
|
|
242
|
+
return undefined;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
// At this point, we know the Amplify outputs contains at least one supported channel
|
|
246
|
+
const notificationsConfig: NotificationsConfig = {} as NotificationsConfig;
|
|
247
|
+
|
|
248
|
+
if (hasInAppMessaging) {
|
|
249
|
+
notificationsConfig.InAppMessaging = {
|
|
250
|
+
Pinpoint: {
|
|
251
|
+
appId: amazon_pinpoint_app_id,
|
|
252
|
+
region: aws_region,
|
|
253
|
+
},
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
if (hasPushNotification) {
|
|
258
|
+
notificationsConfig.PushNotification = {
|
|
259
|
+
Pinpoint: {
|
|
260
|
+
appId: amazon_pinpoint_app_id,
|
|
261
|
+
region: aws_region,
|
|
262
|
+
},
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
return notificationsConfig;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
export function parseAmplifyOutputs(
|
|
270
|
+
amplifyOutputs: AmplifyOutputs,
|
|
271
|
+
): ResourcesConfig {
|
|
272
|
+
const resourcesConfig: ResourcesConfig = {};
|
|
273
|
+
|
|
274
|
+
if (amplifyOutputs.storage) {
|
|
275
|
+
resourcesConfig.Storage = parseStorage(amplifyOutputs.storage);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
if (amplifyOutputs.auth) {
|
|
279
|
+
resourcesConfig.Auth = parseAuth(amplifyOutputs.auth);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
if (amplifyOutputs.analytics) {
|
|
283
|
+
resourcesConfig.Analytics = parseAnalytics(amplifyOutputs.analytics);
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
if (amplifyOutputs.geo) {
|
|
287
|
+
resourcesConfig.Geo = parseGeo(amplifyOutputs.geo);
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
if (amplifyOutputs.data) {
|
|
291
|
+
resourcesConfig.API = parseData(amplifyOutputs.data);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
if (amplifyOutputs.notifications) {
|
|
295
|
+
resourcesConfig.Notifications = parseNotifications(
|
|
296
|
+
amplifyOutputs.notifications,
|
|
297
|
+
);
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
return resourcesConfig;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
const authModeNames: Record<string, GraphQLAuthMode> = {
|
|
304
|
+
AMAZON_COGNITO_USER_POOLS: 'userPool',
|
|
305
|
+
API_KEY: 'apiKey',
|
|
306
|
+
AWS_IAM: 'iam',
|
|
307
|
+
AWS_LAMBDA: 'lambda',
|
|
308
|
+
OPENID_CONNECT: 'oidc',
|
|
309
|
+
};
|
|
310
|
+
|
|
311
|
+
function getGraphQLAuthMode(authType: string): GraphQLAuthMode {
|
|
312
|
+
return authModeNames[authType];
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
const providerNames: Record<string, OAuthProvider> = {
|
|
316
|
+
GOOGLE: 'Google',
|
|
317
|
+
LOGIN_WITH_AMAZON: 'Amazon',
|
|
318
|
+
FACEBOOK: 'Facebook',
|
|
319
|
+
SIGN_IN_WITH_APPLE: 'Apple',
|
|
320
|
+
};
|
|
321
|
+
|
|
322
|
+
function getOAuthProviders(providers: string[] = []): OAuthProvider[] {
|
|
323
|
+
return providers.map(provider => providerNames[provider]);
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
function getMfaStatus(
|
|
327
|
+
mfaConfiguration: string,
|
|
328
|
+
): CognitoUserPoolConfigMfaStatus {
|
|
329
|
+
if (mfaConfiguration === 'OPTIONAL') return 'optional';
|
|
330
|
+
if (mfaConfiguration === 'REQUIRED') return 'on';
|
|
331
|
+
|
|
332
|
+
return 'off';
|
|
333
|
+
}
|
|
@@ -18,7 +18,7 @@ export interface LibraryAPIOptions {
|
|
|
18
18
|
};
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
interface APIGraphQLConfig {
|
|
21
|
+
export interface APIGraphQLConfig {
|
|
22
22
|
/**
|
|
23
23
|
* Required GraphQL endpoint, must be a valid URL string.
|
|
24
24
|
*/
|
|
@@ -47,7 +47,7 @@ interface APIGraphQLConfig {
|
|
|
47
47
|
modelIntrospection?: ModelIntrospectionSchema;
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
-
interface APIRestConfig {
|
|
50
|
+
export interface APIRestConfig {
|
|
51
51
|
/**
|
|
52
52
|
* Required REST endpoint, must be a valid URL string.
|
|
53
53
|
*/
|
|
@@ -81,7 +81,9 @@ export type GraphQLAuthMode =
|
|
|
81
81
|
| 'apiKey'
|
|
82
82
|
| 'oidc'
|
|
83
83
|
| 'userPool'
|
|
84
|
+
// @deprecated; use 'identityPool'
|
|
84
85
|
| 'iam'
|
|
86
|
+
| 'identityPool'
|
|
85
87
|
| 'lambda'
|
|
86
88
|
| 'none';
|
|
87
89
|
|
package/src/singleton/Amplify.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
import { AMPLIFY_SYMBOL, Hub } from '../Hub';
|
|
4
|
-
import { parseAWSExports } from '../parseAWSExports';
|
|
5
4
|
import { deepFreeze } from '../utils';
|
|
5
|
+
import { parseAmplifyConfig } from '../libraryUtils';
|
|
6
6
|
|
|
7
7
|
import {
|
|
8
|
+
AmplifyOutputs,
|
|
8
9
|
AuthConfig,
|
|
9
10
|
LegacyConfig,
|
|
10
11
|
LibraryOptions,
|
|
@@ -48,16 +49,10 @@ export class AmplifyClass {
|
|
|
48
49
|
* @param libraryOptions - Additional options for customizing the behavior of the library.
|
|
49
50
|
*/
|
|
50
51
|
configure(
|
|
51
|
-
resourcesConfig: ResourcesConfig | LegacyConfig,
|
|
52
|
+
resourcesConfig: ResourcesConfig | LegacyConfig | AmplifyOutputs,
|
|
52
53
|
libraryOptions?: LibraryOptions,
|
|
53
54
|
): void {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
if (Object.keys(resourcesConfig).some(key => key.startsWith('aws_'))) {
|
|
57
|
-
resolvedResourceConfig = parseAWSExports(resourcesConfig);
|
|
58
|
-
} else {
|
|
59
|
-
resolvedResourceConfig = resourcesConfig as ResourcesConfig;
|
|
60
|
-
}
|
|
55
|
+
const resolvedResourceConfig = parseAmplifyConfig(resourcesConfig);
|
|
61
56
|
|
|
62
57
|
this.resourcesConfig = resolvedResourceConfig;
|
|
63
58
|
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
export type AmplifyOutputsOAuthIdentityProvider =
|
|
5
|
+
| 'GOOGLE'
|
|
6
|
+
| 'FACEBOOK'
|
|
7
|
+
| 'LOGIN_WITH_AMAZON'
|
|
8
|
+
| 'SIGN_IN_WITH_APPLE';
|
|
9
|
+
|
|
10
|
+
export type AmplifyOutputsAuthMFAConfiguration =
|
|
11
|
+
| 'OPTIONAL'
|
|
12
|
+
| 'REQUIRED'
|
|
13
|
+
| 'NONE';
|
|
14
|
+
|
|
15
|
+
export type AmplifyOutputsAuthMFAMethod = 'SMS' | 'TOTP';
|
|
16
|
+
|
|
17
|
+
export interface AmplifyOutputsAuthProperties {
|
|
18
|
+
aws_region: string;
|
|
19
|
+
authentication_flow_type?: 'USER_SRP_AUTH' | 'CUSTOM_AUTH';
|
|
20
|
+
user_pool_id: string;
|
|
21
|
+
user_pool_client_id: string;
|
|
22
|
+
identity_pool_id?: string;
|
|
23
|
+
password_policy?: {
|
|
24
|
+
min_length: number;
|
|
25
|
+
require_numbers: boolean;
|
|
26
|
+
require_lowercase: boolean;
|
|
27
|
+
require_uppercase: boolean;
|
|
28
|
+
require_symbols: boolean;
|
|
29
|
+
};
|
|
30
|
+
oauth?: {
|
|
31
|
+
identity_providers: string[];
|
|
32
|
+
domain: string;
|
|
33
|
+
scopes: string[];
|
|
34
|
+
redirect_sign_in_uri: string[];
|
|
35
|
+
redirect_sign_out_uri: string[];
|
|
36
|
+
response_type: string;
|
|
37
|
+
};
|
|
38
|
+
standard_required_attributes?: string[];
|
|
39
|
+
username_attributes?: string[];
|
|
40
|
+
user_verification_types?: string[];
|
|
41
|
+
unauthenticated_identities_enabled?: boolean;
|
|
42
|
+
mfa_configuration?: string;
|
|
43
|
+
mfa_methods?: string[];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface AmplifyOutputsStorageProperties {
|
|
47
|
+
aws_region: string;
|
|
48
|
+
bucket_name: string;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface AmplifyOutputsGeoProperties {
|
|
52
|
+
aws_region: string;
|
|
53
|
+
maps?: {
|
|
54
|
+
items: Record<string, unknown>;
|
|
55
|
+
default: string;
|
|
56
|
+
};
|
|
57
|
+
search_indices?: { items: string[]; default: string };
|
|
58
|
+
geofence_collections?: { items: string[]; default: string };
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export interface AmplifyOutputsAnalyticsProperties {
|
|
62
|
+
amazon_pinpoint?: {
|
|
63
|
+
aws_region: string;
|
|
64
|
+
app_id: string;
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export type AuthType =
|
|
69
|
+
| 'AMAZON_COGNITO_USER_POOLS'
|
|
70
|
+
| 'API_KEY'
|
|
71
|
+
| 'AWS_IAM'
|
|
72
|
+
| 'AWS_LAMBDA'
|
|
73
|
+
| 'OPENID_CONNECT';
|
|
74
|
+
|
|
75
|
+
export interface AmplifyOutputsDataProperties {
|
|
76
|
+
aws_region: string;
|
|
77
|
+
url: string;
|
|
78
|
+
default_authorization_type: string;
|
|
79
|
+
authorization_types: string[];
|
|
80
|
+
model_introspection?: object;
|
|
81
|
+
api_key?: string;
|
|
82
|
+
conflict_resolution_mode?: string;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export interface AmplifyOutputsNotificationsProperties {
|
|
86
|
+
aws_region: string;
|
|
87
|
+
amazon_pinpoint_app_id: string;
|
|
88
|
+
channels: string[];
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export interface AmplifyOutputs {
|
|
92
|
+
version?: string;
|
|
93
|
+
storage?: AmplifyOutputsStorageProperties;
|
|
94
|
+
auth?: AmplifyOutputsAuthProperties;
|
|
95
|
+
analytics?: AmplifyOutputsAnalyticsProperties;
|
|
96
|
+
geo?: AmplifyOutputsGeoProperties;
|
|
97
|
+
data?: AmplifyOutputsDataProperties;
|
|
98
|
+
notifications?: AmplifyOutputsNotificationsProperties;
|
|
99
|
+
}
|
|
@@ -145,6 +145,8 @@ export interface AuthUserPoolConfig {
|
|
|
145
145
|
};
|
|
146
146
|
}
|
|
147
147
|
|
|
148
|
+
export type CognitoUserPoolConfigMfaStatus = 'on' | 'off' | 'optional';
|
|
149
|
+
|
|
148
150
|
export interface CognitoUserPoolConfig {
|
|
149
151
|
userPoolClientId: string;
|
|
150
152
|
userPoolId: string;
|
|
@@ -158,7 +160,7 @@ export interface CognitoUserPoolConfig {
|
|
|
158
160
|
};
|
|
159
161
|
userAttributes?: AuthConfigUserAttributes;
|
|
160
162
|
mfa?: {
|
|
161
|
-
status?:
|
|
163
|
+
status?: CognitoUserPoolConfigMfaStatus;
|
|
162
164
|
totpEnabled?: boolean;
|
|
163
165
|
smsEnabled?: boolean;
|
|
164
166
|
};
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
import { AtLeastOne } from '../types';
|
|
5
5
|
|
|
6
|
+
/** @deprecated This may be removed in the next major version. */
|
|
6
7
|
export type StorageAccessLevel = 'guest' | 'protected' | 'private';
|
|
7
8
|
|
|
8
9
|
export interface S3ProviderConfig {
|
|
@@ -20,6 +21,7 @@ export interface S3ProviderConfig {
|
|
|
20
21
|
|
|
21
22
|
export type StorageConfig = AtLeastOne<S3ProviderConfig>;
|
|
22
23
|
|
|
24
|
+
/** @deprecated This may be removed in the next major version. */
|
|
23
25
|
type StoragePrefixResolver = (params: {
|
|
24
26
|
accessLevel: StorageAccessLevel;
|
|
25
27
|
targetIdentityId?: string;
|
|
@@ -27,7 +29,15 @@ type StoragePrefixResolver = (params: {
|
|
|
27
29
|
|
|
28
30
|
export interface LibraryStorageOptions {
|
|
29
31
|
S3: {
|
|
32
|
+
/**
|
|
33
|
+
* @deprecated This may be removed in the next major version.
|
|
34
|
+
* This is currently used for Storage API signature using key as input parameter.
|
|
35
|
+
* */
|
|
30
36
|
prefixResolver?: StoragePrefixResolver;
|
|
37
|
+
/**
|
|
38
|
+
* @deprecated This may be removed in the next major version.
|
|
39
|
+
* This is currently used for Storage API signature using key as input parameter.
|
|
40
|
+
* */
|
|
31
41
|
defaultAccessLevel?: StorageAccessLevel;
|
|
32
42
|
isObjectLockEnabled?: boolean;
|
|
33
43
|
};
|