diff --git a/packages/analytics/src/providers/pinpoint/types/inputs.ts b/packages/analytics/src/providers/pinpoint/types/inputs.ts index 5dbd0880d50..acb28b68c4a 100644 --- a/packages/analytics/src/providers/pinpoint/types/inputs.ts +++ b/packages/analytics/src/providers/pinpoint/types/inputs.ts @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 import { PinpointAnalyticsEvent } from '@aws-amplify/core/internals/providers/pinpoint'; -import { IdentifyUserOptions } from '.'; +import { IdentifyUserOptions } from './options'; import { AnalyticsConfigureAutoTrackInput, AnalyticsIdentifyUserInput, diff --git a/packages/analytics/src/types/inputs.ts b/packages/analytics/src/types/inputs.ts index 2d7f2a8fcde..6f3911ad52b 100644 --- a/packages/analytics/src/types/inputs.ts +++ b/packages/analytics/src/types/inputs.ts @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 import { UserProfile } from '@aws-amplify/core'; -import { AnalyticsServiceOptions } from '.'; +import { AnalyticsServiceOptions } from './options'; import { SessionTrackingOptions, PageViewTrackingOptions, diff --git a/packages/auth/src/providers/cognito/tokenProvider/CognitoUserPoolsTokenProvider.ts b/packages/auth/src/providers/cognito/tokenProvider/CognitoUserPoolsTokenProvider.ts new file mode 100644 index 00000000000..cae8a50fa36 --- /dev/null +++ b/packages/auth/src/providers/cognito/tokenProvider/CognitoUserPoolsTokenProvider.ts @@ -0,0 +1,44 @@ +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +// SPDX-License-Identifier: Apache-2.0 + +import { + AuthConfig, + AuthTokens, + FetchAuthSessionOptions, + KeyValueStorageInterface, + defaultStorage, +} from '@aws-amplify/core'; +import { refreshAuthTokens } from '../utils/refreshAuthTokens'; +import { DefaultTokenStore } from './TokenStore'; +import { TokenOrchestrator } from './TokenOrchestrator'; +import { CognitoUserPoolTokenProviderType } from './types'; + +export class CognitoUserPoolsTokenProvider + implements CognitoUserPoolTokenProviderType +{ + authTokenStore: DefaultTokenStore; + tokenOrchestrator: TokenOrchestrator; + constructor() { + this.authTokenStore = new DefaultTokenStore(); + this.authTokenStore.setKeyValueStorage(defaultStorage); + this.tokenOrchestrator = new TokenOrchestrator(); + this.tokenOrchestrator.setAuthTokenStore(this.authTokenStore); + this.tokenOrchestrator.setTokenRefresher(refreshAuthTokens); + } + getTokens( + { forceRefresh }: FetchAuthSessionOptions = { forceRefresh: false } + ): Promise { + return this.tokenOrchestrator.getTokens({ forceRefresh }); + } + + setKeyValueStorage(keyValueStorage: KeyValueStorageInterface): void { + this.authTokenStore.setKeyValueStorage(keyValueStorage); + } + setWaitForInflightOAuth(waitForInflightOAuth: () => Promise): void { + this.tokenOrchestrator.setWaitForInflightOAuth(waitForInflightOAuth); + } + setAuthConfig(authConfig: AuthConfig) { + this.authTokenStore.setAuthConfig(authConfig); + this.tokenOrchestrator.setAuthConfig(authConfig); + } +} diff --git a/packages/auth/src/providers/cognito/tokenProvider/cacheTokens.ts b/packages/auth/src/providers/cognito/tokenProvider/cacheTokens.ts index 6aa385dd9a4..acd5ee07f47 100644 --- a/packages/auth/src/providers/cognito/tokenProvider/cacheTokens.ts +++ b/packages/auth/src/providers/cognito/tokenProvider/cacheTokens.ts @@ -1,10 +1,10 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 import { AmplifyError, decodeJWT } from '@aws-amplify/core/internals/utils'; -import { tokenOrchestrator } from '.'; +import { CognitoAuthSignInDetails } from '../types'; import { AuthenticationResultType } from '../utils/clients/CognitoIdentityProvider/types'; +import { tokenOrchestrator } from './tokenProvider'; import { CognitoAuthTokens, DeviceMetadata } from './types'; -import { CognitoAuthSignInDetails } from '../types'; export async function cacheCognitoTokens( AuthenticationResult: AuthenticationResultType & { diff --git a/packages/auth/src/providers/cognito/tokenProvider/index.ts b/packages/auth/src/providers/cognito/tokenProvider/index.ts index bc2ac570b53..c44dc5e8325 100644 --- a/packages/auth/src/providers/cognito/tokenProvider/index.ts +++ b/packages/auth/src/providers/cognito/tokenProvider/index.ts @@ -1,56 +1,11 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { - AuthConfig, - AuthTokens, - FetchAuthSessionOptions, - KeyValueStorageInterface, - defaultStorage, -} from '@aws-amplify/core'; -import { refreshAuthTokens } from '../utils/refreshAuthTokens'; -import { DefaultTokenStore } from './TokenStore'; -import { TokenOrchestrator } from './TokenOrchestrator'; -import { CognitoUserPoolTokenProviderType } from './types'; - -class CognitoUserPoolsTokenProviderClass - implements CognitoUserPoolTokenProviderType -{ - authTokenStore: DefaultTokenStore; - tokenOrchestrator: TokenOrchestrator; - constructor() { - this.authTokenStore = new DefaultTokenStore(); - this.authTokenStore.setKeyValueStorage(defaultStorage); - this.tokenOrchestrator = new TokenOrchestrator(); - this.tokenOrchestrator.setAuthTokenStore(this.authTokenStore); - this.tokenOrchestrator.setTokenRefresher(refreshAuthTokens); - } - getTokens( - { forceRefresh }: FetchAuthSessionOptions = { forceRefresh: false } - ): Promise { - return this.tokenOrchestrator.getTokens({ forceRefresh }); - } - - setKeyValueStorage(keyValueStorage: KeyValueStorageInterface): void { - this.authTokenStore.setKeyValueStorage(keyValueStorage); - } - setWaitForInflightOAuth(waitForInflightOAuth: () => Promise): void { - this.tokenOrchestrator.setWaitForInflightOAuth(waitForInflightOAuth); - } - setAuthConfig(authConfig: AuthConfig) { - this.authTokenStore.setAuthConfig(authConfig); - this.tokenOrchestrator.setAuthConfig(authConfig); - } -} - -export const cognitoUserPoolsTokenProvider = - new CognitoUserPoolsTokenProviderClass(); - -export const tokenOrchestrator = - cognitoUserPoolsTokenProvider.tokenOrchestrator; +export { refreshAuthTokens } from '../utils/refreshAuthTokens'; +export { DefaultTokenStore } from './TokenStore'; +export { TokenOrchestrator } from './TokenOrchestrator'; +export { CognitoUserPoolTokenProviderType } from './types'; export { - CognitoUserPoolTokenProviderType, - DefaultTokenStore, - TokenOrchestrator, - refreshAuthTokens, -}; + cognitoUserPoolsTokenProvider, + tokenOrchestrator, +} from './tokenProvider'; diff --git a/packages/auth/src/providers/cognito/tokenProvider/tokenProvider.ts b/packages/auth/src/providers/cognito/tokenProvider/tokenProvider.ts new file mode 100644 index 00000000000..7e5135395f4 --- /dev/null +++ b/packages/auth/src/providers/cognito/tokenProvider/tokenProvider.ts @@ -0,0 +1,10 @@ +// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +// SPDX-License-Identifier: Apache-2.0 + +import { CognitoUserPoolsTokenProvider } from './CognitoUserPoolsTokenProvider'; + +export const cognitoUserPoolsTokenProvider = + new CognitoUserPoolsTokenProvider(); + +export const tokenOrchestrator = + cognitoUserPoolsTokenProvider.tokenOrchestrator; diff --git a/packages/notifications/src/inAppMessaging/providers/pinpoint/types/inputs.ts b/packages/notifications/src/inAppMessaging/providers/pinpoint/types/inputs.ts index d98ac12d22b..092bdd88b91 100644 --- a/packages/notifications/src/inAppMessaging/providers/pinpoint/types/inputs.ts +++ b/packages/notifications/src/inAppMessaging/providers/pinpoint/types/inputs.ts @@ -1,11 +1,11 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 +import { IdentifyUserOptions } from './options'; import { - IdentifyUserOptions, InAppMessageConflictHandler, OnMessageInteractionEventHandler, -} from '.'; +} from './types'; import { InAppMessage, InAppMessageInteractionEvent, diff --git a/packages/notifications/src/inAppMessaging/types/inputs.ts b/packages/notifications/src/inAppMessaging/types/inputs.ts index 75e653cdb9f..0df082ea000 100644 --- a/packages/notifications/src/inAppMessaging/types/inputs.ts +++ b/packages/notifications/src/inAppMessaging/types/inputs.ts @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 import { UserProfile } from '@aws-amplify/core'; -import { InAppMessagingServiceOptions } from '.'; +import { InAppMessagingServiceOptions } from './options'; /** * Input type for `identifyUser`.