@aws-amplify/core 6.0.1-console-preview.5f040a2.0 → 6.0.1-console-preview.a1c533e.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aws-amplify/core",
3
- "version": "6.0.1-console-preview.5f040a2.0+5f040a2",
3
+ "version": "6.0.1-console-preview.a1c533e.0+a1c533e",
4
4
  "description": "Core category of aws-amplify",
5
5
  "main": "./lib/index.js",
6
6
  "module": "./lib-esm/index.js",
@@ -68,7 +68,7 @@
68
68
  "uuid": "^9.0.0"
69
69
  },
70
70
  "devDependencies": {
71
- "@aws-amplify/react-native": "1.0.1-console-preview.5f040a2.0+5f040a2",
71
+ "@aws-amplify/react-native": "1.0.1-console-preview.a1c533e.0+a1c533e",
72
72
  "@types/js-cookie": "^2.2.7",
73
73
  "@types/uuid": "^9.0.0",
74
74
  "find": "^0.2.7",
@@ -86,7 +86,7 @@
86
86
  "name": "Core (I18n)",
87
87
  "path": "./lib-esm/index.js",
88
88
  "import": "{ I18n }",
89
- "limit": "5.48 kB"
89
+ "limit": "5.60 kB"
90
90
  },
91
91
  {
92
92
  "name": "Custom clients (fetch handler)",
@@ -179,5 +179,5 @@
179
179
  "lib-esm"
180
180
  ]
181
181
  },
182
- "gitHead": "5f040a29ecebf29374ae9b58abc661f45143ac4f"
182
+ "gitHead": "a1c533eae82c5386864fb15fc101bb3cb9bd93ae"
183
183
  }
package/src/Hub/index.ts CHANGED
@@ -203,3 +203,11 @@ export class HubClass {
203
203
  pseudo Singleton for the main messaging bus, however you can still create
204
204
  your own instance of HubClass() for a separate "private bus" of events.*/
205
205
  export const Hub = new HubClass('__default__');
206
+
207
+ /**
208
+ * @internal
209
+ *
210
+ * Internal hub used for core Amplify functionality. Not intended for use outside of Amplify.
211
+ *
212
+ */
213
+ export const HubInternal = new HubClass('internal-hub');
@@ -0,0 +1,75 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import {
5
+ AdditionalDetails,
6
+ CategoryUserAgentStateMap,
7
+ CustomUserAgentStateMap,
8
+ SetCustomUserAgentInput,
9
+ } from './types';
10
+
11
+ // Maintains custom user-agent state set by external consumers.
12
+ const customUserAgentState: CustomUserAgentStateMap = {};
13
+
14
+ /**
15
+ * Sets custom user agent state which will be appended to applicable requests. Returns a function that can be used to
16
+ * clean up any custom state set with this API.
17
+ *
18
+ * @note
19
+ * This API operates globally. Calling this API multiple times will result in the most recently set values for a
20
+ * particular API being used.
21
+ *
22
+ * @note
23
+ * This utility IS NOT compatible with SSR.
24
+ *
25
+ * @param input - SetCustomUserAgentInput that defines custom state to apply to the specified APIs.
26
+ */
27
+ export const setCustomUserAgent = (
28
+ input: SetCustomUserAgentInput
29
+ ): (() => void) => {
30
+ // Save custom user-agent state & increment reference counter
31
+ // TODO Remove `any` when we upgrade to TypeScript 5.2, see: https://github.com/microsoft/TypeScript/issues/44373
32
+ customUserAgentState[input.category] = (input.apis as any[]).reduce(
33
+ (acc: CategoryUserAgentStateMap, api: string) => ({
34
+ ...acc,
35
+ [api]: {
36
+ refCount: acc[api]?.refCount ? acc[api].refCount + 1 : 1,
37
+ additionalDetails: input.additionalDetails,
38
+ },
39
+ }),
40
+ customUserAgentState[input.category] ?? {}
41
+ );
42
+
43
+ // Callback that cleans up state for APIs recorded by this call
44
+ let cleanUpCallbackCalled = false;
45
+ const cleanUpCallback = () => {
46
+ // Only allow the cleanup callback to be called once
47
+ if (cleanUpCallbackCalled) {
48
+ return;
49
+ }
50
+ cleanUpCallbackCalled = true;
51
+
52
+ input.apis.forEach(api => {
53
+ const apiRefCount = customUserAgentState[input.category][api].refCount;
54
+
55
+ if (apiRefCount > 1) {
56
+ customUserAgentState[input.category][api].refCount = apiRefCount - 1;
57
+ } else {
58
+ delete customUserAgentState[input.category][api];
59
+
60
+ // Clean up category if no more APIs set
61
+ if (!Object.keys(customUserAgentState[input.category]).length) {
62
+ delete customUserAgentState[input.category];
63
+ }
64
+ }
65
+ });
66
+ };
67
+
68
+ return cleanUpCallback;
69
+ };
70
+
71
+ export const getCustomUserAgent = (
72
+ category: string,
73
+ api: string
74
+ ): AdditionalDetails | undefined =>
75
+ customUserAgentState[category]?.[api]?.additionalDetails;
@@ -5,6 +5,7 @@ import { CustomUserAgentDetails, Framework } from './types';
5
5
  import { version } from './version';
6
6
  import { detectFramework, observeFrameworkChanges } from './detectFramework';
7
7
  import { UserAgent as AWSUserAgent } from '@aws-sdk/types';
8
+ import { getCustomUserAgent } from './customUserAgent';
8
9
 
9
10
  const BASE_USER_AGENT = `aws-amplify`;
10
11
 
@@ -39,6 +40,16 @@ export const getAmplifyUserAgentObject = ({
39
40
  }
40
41
  userAgent.push(['framework', detectFramework()]);
41
42
 
43
+ if (category && action) {
44
+ const customState = getCustomUserAgent(category, action);
45
+
46
+ if (customState) {
47
+ customState.forEach(state => {
48
+ userAgent.push(state);
49
+ });
50
+ }
51
+ }
52
+
42
53
  return userAgent;
43
54
  };
44
55
 
@@ -47,7 +58,9 @@ export const getAmplifyUserAgent = (
47
58
  ): string => {
48
59
  const userAgent = getAmplifyUserAgentObject(customUserAgentDetails);
49
60
  const userAgentString = userAgent
50
- .map(([agentKey, agentValue]) => `${agentKey}/${agentValue}`)
61
+ .map(([agentKey, agentValue]) =>
62
+ agentKey && agentValue ? `${agentKey}/${agentValue}` : agentKey
63
+ )
51
64
  .join(' ');
52
65
 
53
66
  return userAgentString;
@@ -110,7 +110,7 @@ export enum StorageAction {
110
110
  Copy = '4',
111
111
  Remove = '5',
112
112
  GetProperties = '6',
113
- GetUrl = '7'
113
+ GetUrl = '7',
114
114
  }
115
115
 
116
116
  type ActionMap = {
@@ -150,3 +150,46 @@ export type CustomUserAgentDetails =
150
150
  | UserAgentDetailsWithCategory<Category.PubSub>
151
151
  | UserAgentDetailsWithCategory<Category.PushNotification>
152
152
  | UserAgentDetailsWithCategory<Category.Storage>;
153
+
154
+ /**
155
+ * `refCount` tracks how many consumers have set state for a particular API to avoid it being cleared before all
156
+ * consumers are done using it.
157
+ *
158
+ * Category -> Action -> Custom State
159
+ */
160
+ export type CategoryUserAgentStateMap = Record<
161
+ string,
162
+ { refCount: number; additionalDetails: AdditionalDetails }
163
+ >;
164
+ export type CustomUserAgentStateMap = Record<string, CategoryUserAgentStateMap>;
165
+
166
+ export type AdditionalDetails = [string, string?][];
167
+
168
+ type StorageUserAgentInput = {
169
+ category: Category.Storage;
170
+ apis: StorageAction[];
171
+ };
172
+
173
+ type AuthUserAgentInput = {
174
+ category: Category.Auth;
175
+ apis: AuthAction[];
176
+ };
177
+
178
+ type InAppMessagingUserAgentInput = {
179
+ category: Category.InAppMessaging;
180
+ apis: InAppMessagingAction[];
181
+ };
182
+
183
+ type GeoUserAgentInput = {
184
+ category: Category.Geo;
185
+ apis: GeoAction[];
186
+ };
187
+
188
+ export type SetCustomUserAgentInput = (
189
+ | StorageUserAgentInput
190
+ | AuthUserAgentInput
191
+ | InAppMessagingUserAgentInput
192
+ | GeoUserAgentInput
193
+ ) & {
194
+ additionalDetails: AdditionalDetails;
195
+ };
@@ -1,2 +1,2 @@
1
1
  // generated by genversion
2
- export const version = '6.0.1-console-preview.5f040a2.0+5f040a2';
2
+ export const version = '6.0.1-console-preview.a1c533e.0+a1c533e';
@@ -20,12 +20,7 @@ export {
20
20
  } from './utils';
21
21
  export { parseAWSExports } from './parseAWSExports';
22
22
  export { LegacyConfig } from './singleton/types';
23
- export {
24
- JWT,
25
- StrictUnion,
26
- CognitoIdentityPoolConfig,
27
- JwtPayload,
28
- } from './singleton/Auth/types';
23
+
29
24
  // Auth utilities
30
25
  export {
31
26
  decodeJWT,
@@ -36,11 +31,19 @@ export {
36
31
  export { isTokenExpired } from './singleton/Auth';
37
32
  export { APIAuthMode, DocumentType } from './singleton/API/types';
38
33
  export { Signer } from './Signer';
34
+ export {
35
+ JWT,
36
+ StrictUnion,
37
+ CognitoIdentityPoolConfig,
38
+ JwtPayload,
39
+ AuthStandardAttributeKey,
40
+ AuthVerifiableAttributeKey,
41
+ } from './singleton/Auth/types';
39
42
 
40
43
  // Logging utilities
41
44
  export { ConsoleLogger, ConsoleLogger as Logger } from './Logger';
42
45
 
43
- // Platform & device utils
46
+ // Platform & user-agent utilities
44
47
  export { ClientDevice } from './ClientDevice';
45
48
  export {
46
49
  Platform,
@@ -62,7 +65,9 @@ export {
62
65
  PubSubAction,
63
66
  PushNotificationAction,
64
67
  StorageAction,
68
+ SetCustomUserAgentInput,
65
69
  } from './Platform/types';
70
+ export { setCustomUserAgent } from './Platform/customUserAgent';
66
71
 
67
72
  // Service worker
68
73
  export { ServiceWorker } from './ServiceWorker';
@@ -93,4 +98,4 @@ export { base64Decoder, base64Encoder } from './utils/convert';
93
98
  export { getCrypto } from './utils/globalHelpers';
94
99
 
95
100
  // Hub
96
- export { HubClass } from './Hub';
101
+ export { HubInternal } from './Hub';
@@ -1,7 +1,7 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
  import { ConsoleLogger as Logger } from './Logger';
4
- import { OAuthConfig } from './singleton/Auth/types';
4
+ import { OAuthConfig, AuthStandardAttributeKey, AuthConfigUserAttributes } from './singleton/Auth/types';
5
5
  import { ResourcesConfig } from './singleton/types';
6
6
 
7
7
  const logger = new Logger('parseAWSExports');
@@ -34,6 +34,12 @@ export const parseAWSExports = (
34
34
  aws_appsync_region,
35
35
  aws_cognito_identity_pool_id,
36
36
  aws_cognito_sign_up_verification_method,
37
+ aws_cognito_mfa_configuration,
38
+ aws_cognito_mfa_types,
39
+ aws_cognito_password_protection_settings,
40
+ aws_cognito_verification_mechanisms,
41
+ aws_cognito_signup_attributes,
42
+ aws_cognito_username_attributes,
37
43
  aws_mandatory_sign_in,
38
44
  aws_mobile_analytics_app_id,
39
45
  aws_mobile_analytics_app_region,
@@ -93,18 +99,55 @@ export const parseAWSExports = (
93
99
  }
94
100
 
95
101
  // Auth
102
+ const mfaConfig = aws_cognito_mfa_configuration ? {
103
+ status: aws_cognito_mfa_configuration && aws_cognito_mfa_configuration.toLowerCase(),
104
+ totpEnabled: aws_cognito_mfa_types?.includes('TOTP') ?? false,
105
+ smsEnabled: aws_cognito_mfa_types?.includes('SMS') ?? false
106
+ } : undefined;
107
+ const passwordFormatConfig = aws_cognito_password_protection_settings ? {
108
+ minLength: aws_cognito_password_protection_settings.passwordPolicyMinLength,
109
+ requireLowercase:
110
+ aws_cognito_password_protection_settings.passwordPolicyCharacters?.includes('REQUIRES_LOWERCASE') ?? false,
111
+ requireUppercase:
112
+ aws_cognito_password_protection_settings.passwordPolicyCharacters?.includes('REQUIRES_UPPERCASE') ?? false,
113
+ requireNumbers:
114
+ aws_cognito_password_protection_settings.passwordPolicyCharacters?.includes('REQUIRES_NUMBERS') ?? false,
115
+ requireSpecialCharacters:
116
+ aws_cognito_password_protection_settings.passwordPolicyCharacters?.includes('REQUIRES_SYMBOLS') ?? false,
117
+ } : undefined;
118
+ const mergedUserAttributes = Array.from(
119
+ new Set([
120
+ ...(aws_cognito_verification_mechanisms ?? []),
121
+ ...(aws_cognito_signup_attributes ?? [])
122
+ ])
123
+ );
124
+ const userAttributesConfig = mergedUserAttributes.map((s: string) => ({
125
+ [s.toLowerCase()]: {
126
+ required: true // All user attributes generated by the CLI will be required
127
+ }
128
+ })) as unknown as AuthConfigUserAttributes;
129
+ const loginWithEmailEnabled = aws_cognito_username_attributes?.includes('EMAIL') ?? false;
130
+ const loginWithPhoneEnabled = aws_cognito_username_attributes?.includes('PHONE_NUMBER') ?? false;
96
131
  if (aws_cognito_identity_pool_id || aws_user_pools_id) {
97
132
  amplifyConfig.Auth = {
98
133
  Cognito: {
99
134
  identityPoolId: aws_cognito_identity_pool_id,
100
135
  allowGuestAccess: aws_mandatory_sign_in !== 'enable',
101
136
  signUpVerificationMethod: aws_cognito_sign_up_verification_method,
137
+ userAttributes: userAttributesConfig,
102
138
  userPoolClientId: aws_user_pools_web_client_id,
103
139
  userPoolId: aws_user_pools_id,
104
- ...(oauth &&
105
- Object.keys(oauth).length > 0 && {
106
- loginWith: getOAuthConfig(oauth),
107
- }),
140
+ mfa: mfaConfig,
141
+ passwordFormat: passwordFormatConfig,
142
+ loginWith: {
143
+ username: (loginWithEmailEnabled || loginWithPhoneEnabled) ? false : true,
144
+ email: loginWithEmailEnabled,
145
+ phone: loginWithPhoneEnabled,
146
+ ...(oauth &&
147
+ Object.keys(oauth).length > 0 && {
148
+ oauth: getOAuthConfig(oauth),
149
+ }),
150
+ },
108
151
  },
109
152
  };
110
153
  }
@@ -168,12 +211,10 @@ const getOAuthConfig = ({
168
211
  redirectSignIn,
169
212
  redirectSignOut,
170
213
  responseType,
171
- }: Record<string, any>): { oauth: OAuthConfig } => ({
172
- oauth: {
173
- domain,
174
- scopes: scope,
175
- redirectSignIn: getRedirectUrl(redirectSignIn),
176
- redirectSignOut: getRedirectUrl(redirectSignOut),
177
- responseType,
178
- },
214
+ }: Record<string, any>): OAuthConfig => ({
215
+ domain,
216
+ scopes: scope,
217
+ redirectSignIn: getRedirectUrl(redirectSignIn),
218
+ redirectSignOut: getRedirectUrl(redirectSignOut),
219
+ responseType,
179
220
  });
@@ -70,6 +70,33 @@ export type AuthTokens = {
70
70
  accessToken: JWT;
71
71
  };
72
72
 
73
+ export type AuthStandardAttributeKey =
74
+ | 'address'
75
+ | 'birthdate'
76
+ | 'email_verified'
77
+ | 'family_name'
78
+ | 'gender'
79
+ | 'given_name'
80
+ | 'locale'
81
+ | 'middle_name'
82
+ | 'name'
83
+ | 'nickname'
84
+ | 'phone_number_verified'
85
+ | 'picture'
86
+ | 'preferred_username'
87
+ | 'profile'
88
+ | 'sub'
89
+ | 'updated_at'
90
+ | 'website'
91
+ | 'zoneinfo'
92
+ | AuthVerifiableAttributeKey;
93
+
94
+ export type AuthVerifiableAttributeKey = 'email' | 'phone_number';
95
+
96
+ export type AuthConfigUserAttributes = Partial<
97
+ Record<AuthStandardAttributeKey, { required: boolean }>
98
+ >;
99
+
73
100
  export type AuthConfig = StrictUnion<
74
101
  | AuthIdentityPoolConfig
75
102
  | AuthUserPoolConfig
@@ -87,6 +114,11 @@ export type AuthIdentityPoolConfig = {
87
114
  userPoolClientId?: never;
88
115
  userPoolId?: never;
89
116
  loginWith?: never;
117
+ signUpVerificationMethod?: never;
118
+ userAttributes?: never;
119
+ mfa?: never;
120
+ passwordFormat?: never;
121
+ endpoint?: never;
90
122
  };
91
123
  };
92
124
 
@@ -108,7 +140,24 @@ export type CognitoUserPoolConfig = {
108
140
  signUpVerificationMethod?: 'code' | 'link';
109
141
  loginWith?: {
110
142
  oauth?: OAuthConfig;
143
+ username?: boolean;
144
+ email?: boolean;
145
+ phone?: boolean;
146
+ };
147
+ userAttributes?: AuthConfigUserAttributes;
148
+ mfa?: {
149
+ status?: 'on' | 'off' | 'optional';
150
+ totpEnabled?: boolean;
151
+ smsEnabled?: boolean;
152
+ };
153
+ passwordFormat?: {
154
+ minLength?: number;
155
+ requireLowercase?: boolean;
156
+ requireUppercase?: boolean;
157
+ requireNumbers?: boolean;
158
+ requireSpecialCharacters?: boolean;
111
159
  };
160
+ endpoint?: string;
112
161
  };
113
162
 
114
163
  export type OAuthConfig = {