Skip to content

Commit a353e0d

Browse files
authored
fix: refactor to avoid importing from current index (aws-amplify#12636)
1 parent f2b7a8d commit a353e0d

File tree

8 files changed

+68
-59
lines changed

8 files changed

+68
-59
lines changed

packages/analytics/src/providers/pinpoint/types/inputs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
import { PinpointAnalyticsEvent } from '@aws-amplify/core/internals/providers/pinpoint';
5-
import { IdentifyUserOptions } from '.';
5+
import { IdentifyUserOptions } from './options';
66
import {
77
AnalyticsConfigureAutoTrackInput,
88
AnalyticsIdentifyUserInput,

packages/analytics/src/types/inputs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
import { UserProfile } from '@aws-amplify/core';
5-
import { AnalyticsServiceOptions } from '.';
5+
import { AnalyticsServiceOptions } from './options';
66
import {
77
SessionTrackingOptions,
88
PageViewTrackingOptions,
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
import {
5+
AuthConfig,
6+
AuthTokens,
7+
FetchAuthSessionOptions,
8+
KeyValueStorageInterface,
9+
defaultStorage,
10+
} from '@aws-amplify/core';
11+
import { refreshAuthTokens } from '../utils/refreshAuthTokens';
12+
import { DefaultTokenStore } from './TokenStore';
13+
import { TokenOrchestrator } from './TokenOrchestrator';
14+
import { CognitoUserPoolTokenProviderType } from './types';
15+
16+
export class CognitoUserPoolsTokenProvider
17+
implements CognitoUserPoolTokenProviderType
18+
{
19+
authTokenStore: DefaultTokenStore;
20+
tokenOrchestrator: TokenOrchestrator;
21+
constructor() {
22+
this.authTokenStore = new DefaultTokenStore();
23+
this.authTokenStore.setKeyValueStorage(defaultStorage);
24+
this.tokenOrchestrator = new TokenOrchestrator();
25+
this.tokenOrchestrator.setAuthTokenStore(this.authTokenStore);
26+
this.tokenOrchestrator.setTokenRefresher(refreshAuthTokens);
27+
}
28+
getTokens(
29+
{ forceRefresh }: FetchAuthSessionOptions = { forceRefresh: false }
30+
): Promise<AuthTokens | null> {
31+
return this.tokenOrchestrator.getTokens({ forceRefresh });
32+
}
33+
34+
setKeyValueStorage(keyValueStorage: KeyValueStorageInterface): void {
35+
this.authTokenStore.setKeyValueStorage(keyValueStorage);
36+
}
37+
setWaitForInflightOAuth(waitForInflightOAuth: () => Promise<void>): void {
38+
this.tokenOrchestrator.setWaitForInflightOAuth(waitForInflightOAuth);
39+
}
40+
setAuthConfig(authConfig: AuthConfig) {
41+
this.authTokenStore.setAuthConfig(authConfig);
42+
this.tokenOrchestrator.setAuthConfig(authConfig);
43+
}
44+
}

packages/auth/src/providers/cognito/tokenProvider/cacheTokens.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
33
import { AmplifyError, decodeJWT } from '@aws-amplify/core/internals/utils';
4-
import { tokenOrchestrator } from '.';
4+
import { CognitoAuthSignInDetails } from '../types';
55
import { AuthenticationResultType } from '../utils/clients/CognitoIdentityProvider/types';
6+
import { tokenOrchestrator } from './tokenProvider';
67
import { CognitoAuthTokens, DeviceMetadata } from './types';
7-
import { CognitoAuthSignInDetails } from '../types';
88

99
export async function cacheCognitoTokens(
1010
AuthenticationResult: AuthenticationResultType & {
Lines changed: 7 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,11 @@
11
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
3-
import {
4-
AuthConfig,
5-
AuthTokens,
6-
FetchAuthSessionOptions,
7-
KeyValueStorageInterface,
8-
defaultStorage,
9-
} from '@aws-amplify/core';
10-
import { refreshAuthTokens } from '../utils/refreshAuthTokens';
11-
import { DefaultTokenStore } from './TokenStore';
12-
import { TokenOrchestrator } from './TokenOrchestrator';
13-
import { CognitoUserPoolTokenProviderType } from './types';
14-
15-
class CognitoUserPoolsTokenProviderClass
16-
implements CognitoUserPoolTokenProviderType
17-
{
18-
authTokenStore: DefaultTokenStore;
19-
tokenOrchestrator: TokenOrchestrator;
20-
constructor() {
21-
this.authTokenStore = new DefaultTokenStore();
22-
this.authTokenStore.setKeyValueStorage(defaultStorage);
23-
this.tokenOrchestrator = new TokenOrchestrator();
24-
this.tokenOrchestrator.setAuthTokenStore(this.authTokenStore);
25-
this.tokenOrchestrator.setTokenRefresher(refreshAuthTokens);
26-
}
27-
getTokens(
28-
{ forceRefresh }: FetchAuthSessionOptions = { forceRefresh: false }
29-
): Promise<AuthTokens | null> {
30-
return this.tokenOrchestrator.getTokens({ forceRefresh });
31-
}
32-
33-
setKeyValueStorage(keyValueStorage: KeyValueStorageInterface): void {
34-
this.authTokenStore.setKeyValueStorage(keyValueStorage);
35-
}
36-
setWaitForInflightOAuth(waitForInflightOAuth: () => Promise<void>): void {
37-
this.tokenOrchestrator.setWaitForInflightOAuth(waitForInflightOAuth);
38-
}
39-
setAuthConfig(authConfig: AuthConfig) {
40-
this.authTokenStore.setAuthConfig(authConfig);
41-
this.tokenOrchestrator.setAuthConfig(authConfig);
42-
}
43-
}
44-
45-
export const cognitoUserPoolsTokenProvider =
46-
new CognitoUserPoolsTokenProviderClass();
47-
48-
export const tokenOrchestrator =
49-
cognitoUserPoolsTokenProvider.tokenOrchestrator;
503

4+
export { refreshAuthTokens } from '../utils/refreshAuthTokens';
5+
export { DefaultTokenStore } from './TokenStore';
6+
export { TokenOrchestrator } from './TokenOrchestrator';
7+
export { CognitoUserPoolTokenProviderType } from './types';
518
export {
52-
CognitoUserPoolTokenProviderType,
53-
DefaultTokenStore,
54-
TokenOrchestrator,
55-
refreshAuthTokens,
56-
};
9+
cognitoUserPoolsTokenProvider,
10+
tokenOrchestrator,
11+
} from './tokenProvider';
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
import { CognitoUserPoolsTokenProvider } from './CognitoUserPoolsTokenProvider';
5+
6+
export const cognitoUserPoolsTokenProvider =
7+
new CognitoUserPoolsTokenProvider();
8+
9+
export const tokenOrchestrator =
10+
cognitoUserPoolsTokenProvider.tokenOrchestrator;

packages/notifications/src/inAppMessaging/providers/pinpoint/types/inputs.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
33

4+
import { IdentifyUserOptions } from './options';
45
import {
5-
IdentifyUserOptions,
66
InAppMessageConflictHandler,
77
OnMessageInteractionEventHandler,
8-
} from '.';
8+
} from './types';
99
import {
1010
InAppMessage,
1111
InAppMessageInteractionEvent,

packages/notifications/src/inAppMessaging/types/inputs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
import { UserProfile } from '@aws-amplify/core';
5-
import { InAppMessagingServiceOptions } from '.';
5+
import { InAppMessagingServiceOptions } from './options';
66

77
/**
88
* Input type for `identifyUser`.

0 commit comments

Comments
 (0)