From 24312782301d879c8c619b7bb665eb1b88778d73 Mon Sep 17 00:00:00 2001 From: Hui Zhao Date: Wed, 8 Nov 2023 15:17:48 -0800 Subject: [PATCH] chore(auth|aws-amplify): fix instance naming (use camel-case) --- .../__tests__/providers/cognito/autoSignIn.test.ts | 4 ++-- .../cognito/confirmSignInHappyCases.test.ts | 4 ++-- .../providers/cognito/fetchAuthSession.test.ts | 8 ++++---- .../providers/cognito/signInErrorCases.test.ts | 4 ++-- .../providers/cognito/signInStateManagement.test.ts | 4 ++-- .../providers/cognito/signInWithCustomAuth.test.ts | 4 ++-- .../cognito/signInWithCustomSRPAuth.test.ts | 4 ++-- .../providers/cognito/signInWithSRP.test.ts | 4 ++-- .../providers/cognito/signInWithUserPassword.test.ts | 4 ++-- .../src/providers/cognito/apis/signInWithRedirect.ts | 4 ++-- packages/auth/src/providers/cognito/index.ts | 2 +- .../src/providers/cognito/tokenProvider/index.ts | 4 ++-- packages/aws-amplify/__tests__/exports.test.ts | 2 +- packages/aws-amplify/__tests__/initSingleton.test.ts | 12 ++++++------ packages/aws-amplify/src/initSingleton.ts | 8 ++++---- 15 files changed, 36 insertions(+), 36 deletions(-) diff --git a/packages/auth/__tests__/providers/cognito/autoSignIn.test.ts b/packages/auth/__tests__/providers/cognito/autoSignIn.test.ts index 4155a788c28..8765a94aa72 100644 --- a/packages/auth/__tests__/providers/cognito/autoSignIn.test.ts +++ b/packages/auth/__tests__/providers/cognito/autoSignIn.test.ts @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 import { - CognitoUserPoolsTokenProvider, + cognitoUserPoolsTokenProvider, signUp, } from '../../../src/providers/cognito'; import { autoSignIn } from '../../../src/providers/cognito/apis/autoSignIn'; @@ -20,7 +20,7 @@ const authConfig = { userPoolId: 'us-west-2_zzzzz', }, }; -CognitoUserPoolsTokenProvider.setAuthConfig(authConfig); +cognitoUserPoolsTokenProvider.setAuthConfig(authConfig); Amplify.configure({ Auth: authConfig, }); diff --git a/packages/auth/__tests__/providers/cognito/confirmSignInHappyCases.test.ts b/packages/auth/__tests__/providers/cognito/confirmSignInHappyCases.test.ts index 48c876584d0..ce6cc7457af 100644 --- a/packages/auth/__tests__/providers/cognito/confirmSignInHappyCases.test.ts +++ b/packages/auth/__tests__/providers/cognito/confirmSignInHappyCases.test.ts @@ -11,7 +11,7 @@ import { import * as signInHelpers from '../../../src/providers/cognito/utils/signInHelpers'; import { RespondToAuthChallengeCommandOutput } from '../../../src/providers/cognito/utils/clients/CognitoIdentityProvider/types'; import { - CognitoUserPoolsTokenProvider, + cognitoUserPoolsTokenProvider, tokenOrchestrator, } from '../../../src/providers/cognito/tokenProvider'; import * as clients from '../../../src/providers/cognito/utils/clients/CognitoIdentityProvider'; @@ -34,7 +34,7 @@ describe('confirmSignIn API happy path cases', () => { const password = authAPITestParams.user1.password; beforeEach(async () => { - CognitoUserPoolsTokenProvider.setAuthConfig(authConfig); + cognitoUserPoolsTokenProvider.setAuthConfig(authConfig); handleChallengeNameSpy = jest .spyOn(signInHelpers, 'handleChallengeName') diff --git a/packages/auth/__tests__/providers/cognito/fetchAuthSession.test.ts b/packages/auth/__tests__/providers/cognito/fetchAuthSession.test.ts index 660f075da57..fd32724b43f 100644 --- a/packages/auth/__tests__/providers/cognito/fetchAuthSession.test.ts +++ b/packages/auth/__tests__/providers/cognito/fetchAuthSession.test.ts @@ -2,7 +2,7 @@ import { Amplify } from '@aws-amplify/core'; import { fetchAuthSession } from '@aws-amplify/core'; import { CognitoAWSCredentialsAndIdentityIdProvider, - CognitoUserPoolsTokenProvider, + cognitoUserPoolsTokenProvider, cognitoCredentialsProvider, } from '../../../src/providers/cognito'; import { decodeJWT } from '@aws-amplify/core/internals/utils'; @@ -43,7 +43,7 @@ describe('fetchAuthSession behavior for IdentityPools only', () => { { Auth: { credentialsProvider: cognitoCredentialsProvider, - tokenProvider: CognitoUserPoolsTokenProvider, + tokenProvider: cognitoUserPoolsTokenProvider, }, } ); @@ -78,7 +78,7 @@ describe.only('fetchAuthSession behavior for UserPools only', () => { let tokenProviderSpy; beforeEach(() => { tokenProviderSpy = jest - .spyOn(CognitoUserPoolsTokenProvider, 'getTokens') + .spyOn(cognitoUserPoolsTokenProvider, 'getTokens') .mockImplementation(async () => { return { accessToken: decodeJWT( @@ -104,7 +104,7 @@ describe.only('fetchAuthSession behavior for UserPools only', () => { { Auth: { credentialsProvider: cognitoCredentialsProvider, - tokenProvider: CognitoUserPoolsTokenProvider, + tokenProvider: cognitoUserPoolsTokenProvider, }, } ); diff --git a/packages/auth/__tests__/providers/cognito/signInErrorCases.test.ts b/packages/auth/__tests__/providers/cognito/signInErrorCases.test.ts index fa948beb54c..e050dfab6a1 100644 --- a/packages/auth/__tests__/providers/cognito/signInErrorCases.test.ts +++ b/packages/auth/__tests__/providers/cognito/signInErrorCases.test.ts @@ -7,7 +7,7 @@ import { authAPITestParams } from './testUtils/authApiTestParams'; import { signIn, getCurrentUser, - CognitoUserPoolsTokenProvider, + cognitoUserPoolsTokenProvider, } from '../../../src/providers/cognito'; import { InitiateAuthException } from '../../../src/providers/cognito/types/errors'; import { Amplify } from 'aws-amplify'; @@ -27,7 +27,7 @@ const authConfig = { Amplify.configure({ Auth: authConfig, }); -CognitoUserPoolsTokenProvider.setAuthConfig(authConfig); +cognitoUserPoolsTokenProvider.setAuthConfig(authConfig); describe('signIn API error path cases:', () => { test('signIn API should throw a validation AuthError when a user is already signed-in', async () => { diff --git a/packages/auth/__tests__/providers/cognito/signInStateManagement.test.ts b/packages/auth/__tests__/providers/cognito/signInStateManagement.test.ts index 48647dacb82..9cb49b83b29 100644 --- a/packages/auth/__tests__/providers/cognito/signInStateManagement.test.ts +++ b/packages/auth/__tests__/providers/cognito/signInStateManagement.test.ts @@ -7,7 +7,7 @@ import * as signInHelpers from '../../../src/providers/cognito/utils/signInHelpe import { signInStore } from '../../../src/providers/cognito/utils/signInStore'; import { Amplify } from '@aws-amplify/core'; import { RespondToAuthChallengeCommandOutput } from '../../../src/providers/cognito/utils/clients/CognitoIdentityProvider/types'; -import { CognitoUserPoolsTokenProvider } from '../../../src/providers/cognito/tokenProvider'; +import { cognitoUserPoolsTokenProvider } from '../../../src/providers/cognito/tokenProvider'; jest.mock('../../../src/providers/cognito/apis/getCurrentUser'); // getCurrentUser is mocked so Hub is able to dispatch a mocked AuthUser @@ -26,7 +26,7 @@ describe('local sign-in state management tests', () => { }; beforeEach(() => { - CognitoUserPoolsTokenProvider.setAuthConfig(authConfig); + cognitoUserPoolsTokenProvider.setAuthConfig(authConfig); }); test('local state management should return state after signIn returns a ChallengeName', async () => { diff --git a/packages/auth/__tests__/providers/cognito/signInWithCustomAuth.test.ts b/packages/auth/__tests__/providers/cognito/signInWithCustomAuth.test.ts index b12dd7db71b..567a706b82f 100644 --- a/packages/auth/__tests__/providers/cognito/signInWithCustomAuth.test.ts +++ b/packages/auth/__tests__/providers/cognito/signInWithCustomAuth.test.ts @@ -8,7 +8,7 @@ import { signInWithCustomAuth } from '../../../src/providers/cognito/apis/signIn import * as initiateAuthHelpers from '../../../src/providers/cognito/utils/signInHelpers'; import { InitiateAuthCommandOutput } from '../../../src/providers/cognito/utils/clients/CognitoIdentityProvider/types'; import { - CognitoUserPoolsTokenProvider, + cognitoUserPoolsTokenProvider, tokenOrchestrator, } from '../../../src/providers/cognito/tokenProvider'; import * as clients from '../../../src/providers/cognito/utils/clients/CognitoIdentityProvider'; @@ -23,7 +23,7 @@ const authConfig = { Amplify.configure({ Auth: authConfig, }); -CognitoUserPoolsTokenProvider.setAuthConfig(authConfig); +cognitoUserPoolsTokenProvider.setAuthConfig(authConfig); describe('signIn API happy path cases', () => { let handleCustomAuthFlowWithoutSRPSpy; diff --git a/packages/auth/__tests__/providers/cognito/signInWithCustomSRPAuth.test.ts b/packages/auth/__tests__/providers/cognito/signInWithCustomSRPAuth.test.ts index e91dce6ddf0..c49983466f9 100644 --- a/packages/auth/__tests__/providers/cognito/signInWithCustomSRPAuth.test.ts +++ b/packages/auth/__tests__/providers/cognito/signInWithCustomSRPAuth.test.ts @@ -8,7 +8,7 @@ import { signInWithCustomSRPAuth } from '../../../src/providers/cognito/apis/sig import { RespondToAuthChallengeCommandOutput } from '../../../src/providers/cognito/utils/clients/CognitoIdentityProvider/types'; import { Amplify } from 'aws-amplify'; import { - CognitoUserPoolsTokenProvider, + cognitoUserPoolsTokenProvider, tokenOrchestrator, } from '../../../src/providers/cognito/tokenProvider'; import * as clients from '../../../src/providers/cognito/utils/clients/CognitoIdentityProvider'; @@ -19,7 +19,7 @@ const authConfig = { userPoolId: 'us-west-2_zzzzz', }, }; -CognitoUserPoolsTokenProvider.setAuthConfig(authConfig); +cognitoUserPoolsTokenProvider.setAuthConfig(authConfig); Amplify.configure({ Auth: authConfig, }); diff --git a/packages/auth/__tests__/providers/cognito/signInWithSRP.test.ts b/packages/auth/__tests__/providers/cognito/signInWithSRP.test.ts index f200e53b157..200f1659164 100644 --- a/packages/auth/__tests__/providers/cognito/signInWithSRP.test.ts +++ b/packages/auth/__tests__/providers/cognito/signInWithSRP.test.ts @@ -8,7 +8,7 @@ import * as initiateAuthHelpers from '../../../src/providers/cognito/utils/signI import { RespondToAuthChallengeCommandOutput } from '../../../src/providers/cognito/utils/clients/CognitoIdentityProvider/types'; import { Amplify } from 'aws-amplify'; import { - CognitoUserPoolsTokenProvider, + cognitoUserPoolsTokenProvider, tokenOrchestrator, } from '../../../src/providers/cognito/tokenProvider'; import { AuthError } from '../../../src'; @@ -22,7 +22,7 @@ const authConfig = { }, }; -CognitoUserPoolsTokenProvider.setAuthConfig(authConfig); +cognitoUserPoolsTokenProvider.setAuthConfig(authConfig); Amplify.configure({ Auth: authConfig, }); diff --git a/packages/auth/__tests__/providers/cognito/signInWithUserPassword.test.ts b/packages/auth/__tests__/providers/cognito/signInWithUserPassword.test.ts index 0a437425c4a..2fd5e0b6fd1 100644 --- a/packages/auth/__tests__/providers/cognito/signInWithUserPassword.test.ts +++ b/packages/auth/__tests__/providers/cognito/signInWithUserPassword.test.ts @@ -8,7 +8,7 @@ import { signInWithUserPassword } from '../../../src/providers/cognito/apis/sign import { RespondToAuthChallengeCommandOutput } from '../../../src/providers/cognito/utils/clients/CognitoIdentityProvider/types'; import { Amplify } from 'aws-amplify'; import { - CognitoUserPoolsTokenProvider, + cognitoUserPoolsTokenProvider, tokenOrchestrator, } from '../../../src/providers/cognito/tokenProvider'; import * as clients from '../../../src/providers/cognito/utils/clients/CognitoIdentityProvider'; @@ -20,7 +20,7 @@ const authConfig = { }, }; -CognitoUserPoolsTokenProvider.setAuthConfig(authConfig); +cognitoUserPoolsTokenProvider.setAuthConfig(authConfig); Amplify.configure({ Auth: authConfig, }); diff --git a/packages/auth/src/providers/cognito/apis/signInWithRedirect.ts b/packages/auth/src/providers/cognito/apis/signInWithRedirect.ts index a5004e499bc..76f99752cf1 100644 --- a/packages/auth/src/providers/cognito/apis/signInWithRedirect.ts +++ b/packages/auth/src/providers/cognito/apis/signInWithRedirect.ts @@ -15,7 +15,7 @@ import { AmplifyUrl, } from '@aws-amplify/core/internals/utils'; import { cacheCognitoTokens } from '../tokenProvider/cacheTokens'; -import { CognitoUserPoolsTokenProvider } from '../tokenProvider'; +import { cognitoUserPoolsTokenProvider } from '../tokenProvider'; import { cognitoHostedUIIdentityProviderMap } from '../types/models'; import { DefaultOAuthStore } from '../utils/signInWithRedirectStore'; import { AuthError } from '../../../errors/AuthError'; @@ -472,7 +472,7 @@ const invokeAndClearPromise = () => { }; isBrowser() && - CognitoUserPoolsTokenProvider.setWaitForInflightOAuth( + cognitoUserPoolsTokenProvider.setWaitForInflightOAuth( () => new Promise(async (res, _rej) => { if (!(await store.loadOAuthInFlight())) { diff --git a/packages/auth/src/providers/cognito/index.ts b/packages/auth/src/providers/cognito/index.ts index 1043a5ae7ae..9229b376083 100644 --- a/packages/auth/src/providers/cognito/index.ts +++ b/packages/auth/src/providers/cognito/index.ts @@ -75,7 +75,7 @@ export { DefaultIdentityIdStore, } from './credentialsProvider'; export { - CognitoUserPoolsTokenProvider, + cognitoUserPoolsTokenProvider, CognitoUserPoolTokenProviderType, TokenOrchestrator, DefaultTokenStore, diff --git a/packages/auth/src/providers/cognito/tokenProvider/index.ts b/packages/auth/src/providers/cognito/tokenProvider/index.ts index 3054ca51596..bc2ac570b53 100644 --- a/packages/auth/src/providers/cognito/tokenProvider/index.ts +++ b/packages/auth/src/providers/cognito/tokenProvider/index.ts @@ -42,11 +42,11 @@ class CognitoUserPoolsTokenProviderClass } } -export const CognitoUserPoolsTokenProvider = +export const cognitoUserPoolsTokenProvider = new CognitoUserPoolsTokenProviderClass(); export const tokenOrchestrator = - CognitoUserPoolsTokenProvider.tokenOrchestrator; + cognitoUserPoolsTokenProvider.tokenOrchestrator; export { CognitoUserPoolTokenProviderType, diff --git a/packages/aws-amplify/__tests__/exports.test.ts b/packages/aws-amplify/__tests__/exports.test.ts index d35f392da1d..2732f332d47 100644 --- a/packages/aws-amplify/__tests__/exports.test.ts +++ b/packages/aws-amplify/__tests__/exports.test.ts @@ -210,7 +210,7 @@ describe('aws-amplify Exports', () => { 'fetchDevices', 'autoSignIn', 'cognitoCredentialsProvider', - 'CognitoUserPoolsTokenProvider', + 'cognitoUserPoolsTokenProvider', 'CognitoAWSCredentialsAndIdentityIdProvider', 'DefaultIdentityIdStore', 'TokenOrchestrator', diff --git a/packages/aws-amplify/__tests__/initSingleton.test.ts b/packages/aws-amplify/__tests__/initSingleton.test.ts index 3bdad8a9d86..56b1261314e 100644 --- a/packages/aws-amplify/__tests__/initSingleton.test.ts +++ b/packages/aws-amplify/__tests__/initSingleton.test.ts @@ -9,7 +9,7 @@ import { defaultStorage, } from '@aws-amplify/core'; import { - CognitoUserPoolsTokenProvider, + cognitoUserPoolsTokenProvider, cognitoCredentialsProvider, } from '../src/auth/cognito'; @@ -17,7 +17,7 @@ import { Amplify } from '../src'; jest.mock('@aws-amplify/core'); jest.mock('../src/auth/cognito', () => ({ - CognitoUserPoolsTokenProvider: { + cognitoUserPoolsTokenProvider: { setAuthConfig: jest.fn(), setKeyValueStorage: jest.fn(), }, @@ -25,9 +25,9 @@ jest.mock('../src/auth/cognito', () => ({ })); const mockCognitoUserPoolsTokenProviderSetAuthConfig = - CognitoUserPoolsTokenProvider.setAuthConfig as jest.Mock; + cognitoUserPoolsTokenProvider.setAuthConfig as jest.Mock; const mockCognitoUserPoolsTokenProviderSetKeyValueStorage = - CognitoUserPoolsTokenProvider.setKeyValueStorage as jest.Mock; + cognitoUserPoolsTokenProvider.setKeyValueStorage as jest.Mock; const mockAmplifySingletonConfigure = AmplifySingleton.configure as jest.Mock; const mockAmplifySingletonGetConfig = AmplifySingleton.getConfig as jest.Mock; const MockCookieStorage = CookieStorage as jest.Mock; @@ -137,7 +137,7 @@ describe('initSingleton (DefaultAmplify)', () => { mockResourceConfig, { Auth: { - tokenProvider: CognitoUserPoolsTokenProvider, + tokenProvider: cognitoUserPoolsTokenProvider, credentialsProvider: cognitoCredentialsProvider, }, } @@ -200,7 +200,7 @@ describe('initSingleton (DefaultAmplify)', () => { mockResourceConfig, { Auth: { - tokenProvider: CognitoUserPoolsTokenProvider, + tokenProvider: cognitoUserPoolsTokenProvider, credentialsProvider: cognitoCredentialsProvider, }, ...libraryOptionsWithStorage, diff --git a/packages/aws-amplify/src/initSingleton.ts b/packages/aws-amplify/src/initSingleton.ts index 2ec413012c9..58e92dd053b 100644 --- a/packages/aws-amplify/src/initSingleton.ts +++ b/packages/aws-amplify/src/initSingleton.ts @@ -12,7 +12,7 @@ import { parseAWSExports, } from '@aws-amplify/core/internals/utils'; import { - CognitoUserPoolsTokenProvider, + cognitoUserPoolsTokenProvider, cognitoCredentialsProvider, } from './auth/cognito'; @@ -36,17 +36,17 @@ export const DefaultAmplify = { !libraryOptions?.Auth && !Amplify.libraryOptions.Auth ) { - CognitoUserPoolsTokenProvider.setAuthConfig(resolvedResourceConfig.Auth); + cognitoUserPoolsTokenProvider.setAuthConfig(resolvedResourceConfig.Auth); const libraryOptionsWithDefaultAuthProviders: LibraryOptions = { ...libraryOptions, Auth: { - tokenProvider: CognitoUserPoolsTokenProvider, + tokenProvider: cognitoUserPoolsTokenProvider, credentialsProvider: cognitoCredentialsProvider, }, }; - CognitoUserPoolsTokenProvider.setKeyValueStorage( + cognitoUserPoolsTokenProvider.setKeyValueStorage( libraryOptions?.ssr ? // TODO: allow configure with a public interface new CookieStorage({