diff --git a/jest.config.js b/jest.config.js index 99100f706a5..1512d30d8a7 100644 --- a/jest.config.js +++ b/jest.config.js @@ -15,6 +15,9 @@ module.exports = { noImplicitAny: false, types: ['jest', 'jsdom'], }, + diagnostics: { + warnOnly: false, + }, }, ], }, diff --git a/packages/core/__tests__/singleton/Singleton.test.ts b/packages/core/__tests__/singleton/Singleton.test.ts index 03c0185359d..b46ae694c3e 100644 --- a/packages/core/__tests__/singleton/Singleton.test.ts +++ b/packages/core/__tests__/singleton/Singleton.test.ts @@ -6,6 +6,9 @@ import { AuthClass as Auth } from '../../src/singleton/Auth'; import { decodeJWT } from '../../src/singleton/Auth/utils'; import { CredentialsAndIdentityId } from '../../src/singleton/Auth/types'; import { ResourcesConfig, fetchAuthSession } from '../../src'; +import { AmplifyOutputs } from '../../src/libraryUtils'; + +import mockAmplifyOutputs from './utils/amplify_outputs.json'; Object.assign(global, { TextDecoder, TextEncoder }); @@ -164,6 +167,22 @@ describe('Amplify.configure() and Amplify.getConfig()', () => { expect(result).toEqual(expectedResourceConfig); }); + it(`should successfully configure from a 'amplify_outputs.json' file`, () => { + type DeepRequired = T extends object + ? { [K in keyof T]-?: DeepRequired> } + : T; + + const recreateObject = (obj: T): DeepRequired => + obj as DeepRequired; + + // Ensures that all optional properties in mockAmplifyOutputs are defined + const _amplifyOutputs: DeepRequired = + recreateObject(mockAmplifyOutputs); + + // Configures Amplify with mockAmplifyOutputs, relying on its inferred type + Amplify.configure(mockAmplifyOutputs); + }); + it('dispatches hub event with parsed ResourceConfig from the legacy config', () => { Amplify.configure(mockLegacyConfig); diff --git a/packages/core/__tests__/singleton/utils/amplify_outputs.json b/packages/core/__tests__/singleton/utils/amplify_outputs.json new file mode 100644 index 00000000000..5b1c0697157 --- /dev/null +++ b/packages/core/__tests__/singleton/utils/amplify_outputs.json @@ -0,0 +1,198 @@ +{ + "version": "1", + "auth": { + "aws_region": "us-west-2", + "user_pool_id": "mock-cup-id", + "user_pool_client_id": "mock-cup-client-id", + "identity_pool_id": "mock-idp-id", + "authentication_flow_type": "CUSTOM_AUTH", + "oauth": { + "identity_providers": [ + "FACEBOOK", + "SIGN_IN_WITH_APPLE", + "GOOGLE", + "Auth0" + ], + "domain": "mock-oauth-domain", + "scopes": ["phone"], + "redirect_sign_in_uri": ["mock-sign-in-uri"], + "redirect_sign_out_uri": ["mock-sign-out-uri"], + "response_type": "token" + }, + "standard_required_attributes": ["address", "locale", "email"], + "username_attributes": ["phone_number", "email"], + "user_verification_types": ["email"], + "unauthenticated_identities_enabled": true, + "mfa_configuration": "OPTIONAL", + "mfa_methods": ["TOTP", "SMS"], + "password_policy": { + "require_lowercase": true, + "require_numbers": true, + "require_uppercase": true, + "require_symbols": true, + "min_length": 6 + }, + "groups": [ + { "ADMIN": { "precedence": 0 } }, + { "USER": { "precedence": 1 } }, + { "TEST": { "precedence": 2 } } + ] + }, + "data": { + "aws_region": "us-west-2", + "url": "mock-data-url", + "api_key": "mock-data-api-key", + "default_authorization_type": "API_KEY", + "authorization_types": [], + "conflict_resolution_mode": "AUTOMERGE", + "model_introspection": { + "version": 1, + "models": { + "Todo": { + "name": "Todo", + "fields": { + "id": { + "name": "id", + "isArray": false, + "type": "ID", + "isRequired": true, + "attributes": [] + }, + "content": { + "name": "content", + "isArray": false, + "type": "String", + "isRequired": false, + "attributes": [] + }, + "createdAt": { + "name": "createdAt", + "isArray": false, + "type": "AWSDateTime", + "isRequired": false, + "attributes": [], + "isReadOnly": true + }, + "updatedAt": { + "name": "updatedAt", + "isArray": false, + "type": "AWSDateTime", + "isRequired": false, + "attributes": [], + "isReadOnly": true + } + }, + "syncable": true, + "pluralName": "Todos", + "attributes": [ + { + "type": "model", + "properties": {} + }, + { + "type": "auth", + "properties": { + "rules": [ + { + "provider": "userPools", + "ownerField": "owner", + "allow": "owner", + "identityClaim": "cognito:username", + "operations": ["create", "update", "delete", "read"] + }, + { + "allow": "private", + "provider": "iam", + "operations": ["create", "update", "delete", "read"] + } + ] + } + } + ], + "primaryKeyInfo": { + "isCustomPrimaryKey": false, + "primaryKeyFieldName": "id", + "sortKeyFieldNames": [] + } + } + }, + "enums": {}, + "nonModels": {} + } + }, + "geo": { + "aws_region": "us-west-2", + "search_indices": { + "items": ["mock-geo-search-item", "mock-geo-search-item-alt"], + "default": "mock-geo-search-item" + }, + "geofence_collections": { + "items": ["mock-geo-fence-item", "mock-geo-fence-item-alt"], + "default": "mock-geo-fence-item" + }, + + "maps": { + "items": { + "map51addb38-dev": { + "style": "VectorEsriStreets" + }, + "map30grxcw31-prod": { + "style": "VectorEsriStreets" + } + }, + "default": "map51addb38-dev" + } + }, + "custom": { + "custom-prop": -51806024, + "custom-prop-alt": 87599986, + "events": { + "url": "mock-events-url", + "aws_region": "us-west-2", + "default_authorization_type": "API_KEY", + "api_key": "mock-events-api-key" + } + }, + "notifications": { + "aws_region": "us-west-2", + "amazon_pinpoint_app_id": "mock-pinpoint-app-id", + "channels": ["IN_APP_MESSAGING", "APNS"] + }, + "analytics": { + "amazon_pinpoint": { + "app_id": "mock-pinpoint-app-id", + "aws_region": "us-west-2" + } + }, + "storage": { + "aws_region": "us-west-2", + "bucket_name": "mock-bucket-1", + "buckets": [ + { + "name": "mock-bucket-1", + "bucket_name": "bucket1", + "aws_region": "us-west-2", + "paths": { + "sub/*": { + "authenticated": ["get", "list"] + }, + "public/*": { + "guest": ["get", "list", "write", "delete"], + "authenticated": ["write", "get", "list", "delete"] + } + } + }, + { + "name": "mock-bucket-2", + "bucket_name": "bucket2", + "aws_region": "us-west-2", + "paths": { + "public/*": { + "guest": ["get", "list", "write", "delete"], + "authenticated": ["write", "get", "list", "delete"] + } + } + } + ] + } +} diff --git a/packages/core/src/singleton/AmplifyOutputs/types.ts b/packages/core/src/singleton/AmplifyOutputs/types.ts index 4ff761a2f08..22768694c62 100644 --- a/packages/core/src/singleton/AmplifyOutputs/types.ts +++ b/packages/core/src/singleton/AmplifyOutputs/types.ts @@ -17,7 +17,7 @@ type UserGroupName = string; type UserGroupPrecedence = Record; export interface AmplifyOutputsAuthProperties { aws_region: string; - authentication_flow_type?: 'USER_SRP_AUTH' | 'CUSTOM_AUTH'; + authentication_flow_type?: string; user_pool_id: string; user_pool_client_id: string; identity_pool_id?: string;