Skip to content

Commit

Permalink
chore(aws-amplify): run yarn lint:fix
Browse files Browse the repository at this point in the history
  • Loading branch information
HuiSF committed Feb 13, 2024
1 parent 396c5e2 commit 0a5ae05
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import {
DefaultIdentityIdStore,
} from '@aws-amplify/auth/cognito';
import {
CredentialsAndIdentityIdProvider,
AuthConfig,
CredentialsAndIdentityIdProvider,
KeyValueStorageInterface,
} from '@aws-amplify/core';

Expand All @@ -20,10 +20,11 @@ import {
*/
export const createAWSCredentialsAndIdentityIdProvider = (
authConfig: AuthConfig,
keyValueStorage: KeyValueStorageInterface
keyValueStorage: KeyValueStorageInterface,
): CredentialsAndIdentityIdProvider => {
const credentialsProvider = new CognitoAWSCredentialsAndIdentityIdProvider(
new DefaultIdentityIdStore(keyValueStorage)
new DefaultIdentityIdStore(keyValueStorage),
);

return credentialsProvider;
};
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
*/
export const createUserPoolsTokenProvider = (
authConfig: AuthConfig,
keyValueStorage: KeyValueStorageInterface
keyValueStorage: KeyValueStorageInterface,
): TokenProvider => {
const authTokenStore = new DefaultTokenStore();
authTokenStore.setAuthConfig(authConfig);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
// SPDX-License-Identifier: Apache-2.0

import {
AmplifyServer,
createAmplifyServerContext,
destroyAmplifyServerContext,
AmplifyServer,
} from '@aws-amplify/core/internals/adapter-core';

/**
Expand All @@ -22,7 +22,7 @@ export const runWithAmplifyServerContext: AmplifyServer.RunOperationWithContext
async (amplifyConfig, libraryOptions, operation) => {
const contextSpec = createAmplifyServerContext(
amplifyConfig,
libraryOptions
libraryOptions,
);

// run the operation with injecting the context
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const ONE_YEAR_IN_MS = 365 * 24 * 60 * 60 * 1000;
* @returns An object that implements {@link KeyValueStorageInterface}.
*/
export const createKeyValueStorageFromCookieStorageAdapter = (
cookieStorageAdapter: CookieStorage.Adapter
cookieStorageAdapter: CookieStorage.Adapter,
): KeyValueStorageInterface => {
return {
setItem(key, value) {
Expand All @@ -26,14 +26,17 @@ export const createKeyValueStorageFromCookieStorageAdapter = (
...defaultSetCookieOptions,
expires: new Date(Date.now() + ONE_YEAR_IN_MS),
});

return Promise.resolve();
},
getItem(key) {
const cookie = cookieStorageAdapter.get(key);

return Promise.resolve(cookie?.value ?? null);
},
removeItem(key) {
cookieStorageAdapter.delete(key);

return Promise.resolve();
},
clear() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

/*
This file maps exports from `aws-amplify/in-app-messaging/pinpoint`.
This file maps exports from `aws-amplify/in-app-messaging/pinpoint`.
It provides access to the Pinpoint provider of the InAppMessaging sub-category.
*/
export * from '@aws-amplify/notifications/in-app-messaging/pinpoint';
27 changes: 19 additions & 8 deletions packages/aws-amplify/src/initSingleton.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ import {
LegacyConfig,
parseAWSExports,
} from '@aws-amplify/core/internals/utils';

import {
cognitoUserPoolsTokenProvider,
cognitoCredentialsProvider,
cognitoUserPoolsTokenProvider,
} from './auth/cognito';

export const DefaultAmplify = {
Expand All @@ -31,7 +32,7 @@ export const DefaultAmplify = {
*/
configure(
resourceConfig: ResourcesConfig | LegacyConfig,
libraryOptions?: LibraryOptions
libraryOptions?: LibraryOptions,
): void {
let resolvedResourceConfig: ResourcesConfig;

Expand All @@ -44,13 +45,17 @@ export const DefaultAmplify = {
// If no Auth config is provided, no special handling will be required, configure as is.
// Otherwise, we can assume an Auth config is provided from here on.
if (!resolvedResourceConfig.Auth) {
return Amplify.configure(resolvedResourceConfig, libraryOptions);
Amplify.configure(resolvedResourceConfig, libraryOptions);

return;
}

// If Auth options are provided, always just configure as is.
// Otherwise, we can assume no Auth libraryOptions were provided from here on.
if (libraryOptions?.Auth) {
return Amplify.configure(resolvedResourceConfig, libraryOptions);
Amplify.configure(resolvedResourceConfig, libraryOptions);

return;
}

// If no Auth libraryOptions were previously configured, then always add default providers.
Expand All @@ -60,15 +65,18 @@ export const DefaultAmplify = {
// TODO: allow configure with a public interface
libraryOptions?.ssr
? new CookieStorage({ sameSite: 'lax' })
: defaultStorage
: defaultStorage,
);
return Amplify.configure(resolvedResourceConfig, {

Amplify.configure(resolvedResourceConfig, {
...libraryOptions,
Auth: {
tokenProvider: cognitoUserPoolsTokenProvider,
credentialsProvider: cognitoCredentialsProvider,
},
});

return;
}

// At this point, Auth libraryOptions would have been previously configured and no overriding
Expand All @@ -80,13 +88,16 @@ export const DefaultAmplify = {
// TODO: allow configure with a public interface
libraryOptions.ssr
? new CookieStorage({ sameSite: 'lax' })
: defaultStorage
: defaultStorage,
);
}
return Amplify.configure(resolvedResourceConfig, {

Amplify.configure(resolvedResourceConfig, {
Auth: Amplify.libraryOptions.Auth,
...libraryOptions,
});

return;
}

// Finally, if there were no libraryOptions given at all, we should simply not touch the currently
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

/*
This file maps exports from `aws-amplify/push-notifications/pinpoint`.
This file maps exports from `aws-amplify/push-notifications/pinpoint`.
It provides access to the Pinpoint provider of the PushNotification sub-category.
*/
export * from '@aws-amplify/notifications/push-notifications/pinpoint';

0 comments on commit 0a5ae05

Please sign in to comment.