Skip to content

Commit

Permalink
chore(auth): enable eslint and remove tslint (#13052)
Browse files Browse the repository at this point in the history
* chore(auth): enable eslint and remove tslint

* chore(auth): run yarn lint:fix

* chore(auth): manual fix of eslint reported errors
  • Loading branch information
HuiSF authored Feb 28, 2024
1 parent 4b67d4d commit f049a9e
Show file tree
Hide file tree
Showing 102 changed files with 834 additions and 718 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ module.exports = {
// 'packages/api',
'packages/api-graphql',
// 'packages/api-rest',
'packages/auth',
// 'packages/auth',
// 'packages/aws-amplify',
// 'packages/core',
'packages/datastore',
Expand Down
3 changes: 2 additions & 1 deletion packages/auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
"clean": "npm run clean:size && rimraf lib-esm lib dist",
"clean:size": "rimraf dual-publish-tmp tmp*",
"format": "echo \"Not implemented\"",
"lint": "tslint '{src}/**/*.ts' && npm run ts-coverage",
"lint": "eslint '**/*.{ts,tsx}' && npm run ts-coverage",
"lint:fix": "eslint '**/*.{ts,tsx}' --fix",
"ts-coverage": "typescript-coverage-report -p ./tsconfig.build.json -t 91.18"
},
"typesVersions": {
Expand Down
3 changes: 2 additions & 1 deletion packages/auth/src/Errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@

// TODO: delete this module when the Auth class is removed.

import { AuthErrorMessages, AuthErrorTypes } from './types/Auth';
import { ConsoleLogger } from '@aws-amplify/core';

import { AuthErrorMessages, AuthErrorTypes } from './types/Auth';
import { AuthErrorStrings } from './common/AuthErrorStrings';

const logger = new ConsoleLogger('AuthError');
Expand Down
1 change: 1 addition & 0 deletions packages/auth/src/common/AuthErrorStrings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

import { AmplifyErrorMap } from '@aws-amplify/core/internals/utils';

import { AuthValidationErrorCode } from '../errors/types/validation';

export const validationErrorMap: AmplifyErrorMap<AuthValidationErrorCode> = {
Expand Down
3 changes: 2 additions & 1 deletion packages/auth/src/errors/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ export const invalidOriginException = new AuthError({
});
export const OAUTH_SIGNOUT_EXCEPTION = 'OAuthSignOutException';
export const TOKEN_REFRESH_EXCEPTION = 'TokenRefreshException';
export const UNEXPECTED_SIGN_IN_INTERRUPTION_EXCEPTION = 'UnexpectedSignInInterruptionException';
export const UNEXPECTED_SIGN_IN_INTERRUPTION_EXCEPTION =
'UnexpectedSignInInterruptionException';
3 changes: 2 additions & 1 deletion packages/auth/src/errors/utils/assertServiceError.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import { AuthError } from '../AuthError';
import {
AmplifyErrorCode,
ServiceError,
} from '@aws-amplify/core/internals/utils';

import { AuthError } from '../AuthError';

export function assertServiceError(
error: unknown,
): asserts error is ServiceError {
Expand Down
2 changes: 2 additions & 0 deletions packages/auth/src/providers/cognito/apis/autoSignIn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ const initialAutoSignIn: AutoSignInCallback =
*
* ```
*/
// TODO(Eslint): can this be refactored not using `let` on exported member?
// eslint-disable-next-line import/no-mutable-exports
export let autoSignIn: AutoSignInCallback = initialAutoSignIn;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@

import { Amplify } from '@aws-amplify/core';
import {
assertTokenProviderConfig,
AuthAction,
assertTokenProviderConfig,
} from '@aws-amplify/core/internals/utils';

import { AuthValidationErrorCode } from '../../../errors/types/validation';
import { assertValidationError } from '../../../errors/utils/assertValidationError';
import { ConfirmResetPasswordInput } from '../types';
Expand Down Expand Up @@ -64,7 +65,7 @@ export async function confirmResetPassword(
Password: newPassword,
ClientMetadata: metadata,
ClientId: authConfig.userPoolClientId,
UserContextData: UserContextData,
UserContextData,
},
);
}
23 changes: 10 additions & 13 deletions packages/auth/src/providers/cognito/apis/confirmSignIn.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import { Amplify } from '@aws-amplify/core';
import { assertTokenProviderConfig } from '@aws-amplify/core/internals/utils';

import {
VerifySoftwareTokenException,
RespondToAuthChallengeException,
AssociateSoftwareTokenException,
RespondToAuthChallengeException,
VerifySoftwareTokenException,
} from '../types/errors';
import { ConfirmSignInInput, ConfirmSignInOutput } from '../types';
import {
Expand All @@ -23,18 +26,12 @@ import { assertServiceError } from '../../../errors/utils/assertServiceError';
import { assertValidationError } from '../../../errors/utils/assertValidationError';
import { AuthValidationErrorCode } from '../../../errors/types/validation';
import { AuthErrorCodes } from '../../../common/AuthErrorStrings';
import { Amplify, Hub } from '@aws-amplify/core';
import {
AMPLIFY_SYMBOL,
assertTokenProviderConfig,
} from '@aws-amplify/core/internals/utils';
import { cacheCognitoTokens } from '../tokenProvider/cacheTokens';
import {
ChallengeName,
ChallengeParameters,
} from '../utils/clients/CognitoIdentityProvider/types';
import { tokenOrchestrator } from '../tokenProvider';
import { getCurrentUser } from './getCurrentUser';
import { dispatchSignedInHubEvent } from '../utils/dispatchSignedInHubEvent';

/**
Expand Down Expand Up @@ -89,9 +86,9 @@ export async function confirmSignIn(
try {
const {
Session,
ChallengeName,
ChallengeName: handledChallengeName,
AuthenticationResult,
ChallengeParameters,
ChallengeParameters: handledChallengeParameters,
} = await handleChallengeName(
username,
challengeName as ChallengeName,
Expand All @@ -107,7 +104,7 @@ export async function confirmSignIn(
setActiveSignInState({
signInSession: Session,
username,
challengeName: ChallengeName as ChallengeName,
challengeName: handledChallengeName as ChallengeName,
signInDetails,
});

Expand All @@ -133,8 +130,8 @@ export async function confirmSignIn(
}

return getSignInResult({
challengeName: ChallengeName as ChallengeName,
challengeParameters: ChallengeParameters as ChallengeParameters,
challengeName: handledChallengeName as ChallengeName,
challengeParameters: handledChallengeParameters as ChallengeParameters,
});
} catch (error) {
assertServiceError(error);
Expand Down
7 changes: 5 additions & 2 deletions packages/auth/src/providers/cognito/apis/confirmSignUp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@

import { Amplify } from '@aws-amplify/core';
import {
assertTokenProviderConfig,
AuthAction,
HubInternal,
assertTokenProviderConfig,
} from '@aws-amplify/core/internals/utils';

import { ConfirmSignUpInput, ConfirmSignUpOutput } from '../types';
import { assertValidationError } from '../../../errors/utils/assertValidationError';
import { AuthValidationErrorCode } from '../../../errors/types/validation';
Expand Down Expand Up @@ -85,7 +86,9 @@ export async function confirmSignUp(
!isAutoSignInStarted() ||
!isAutoSignInUserUsingConfirmSignUp(username)
) {
return resolve(signUpOut);
resolve(signUpOut);

return;
}

const stopListener = HubInternal.listen<AutoSignInEventData>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@

import { Amplify, fetchAuthSession } from '@aws-amplify/core';
import {
assertTokenProviderConfig,
AuthAction,
assertTokenProviderConfig,
} from '@aws-amplify/core/internals/utils';

import { AuthValidationErrorCode } from '../../../errors/types/validation';
import { assertValidationError } from '../../../errors/utils/assertValidationError';
import { verifyUserAttribute } from '../utils/clients/CognitoIdentityProvider';
Expand Down
6 changes: 4 additions & 2 deletions packages/auth/src/providers/cognito/apis/deleteUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@

import { Amplify, fetchAuthSession } from '@aws-amplify/core';
import {
assertTokenProviderConfig,
AuthAction,
assertTokenProviderConfig,
} from '@aws-amplify/core/internals/utils';

import { getRegion } from '../utils/clients/CognitoIdentityProvider/utils';
import { assertAuthTokens } from '../utils/types';
import { deleteUser as serviceDeleteUser } from '../utils/clients/CognitoIdentityProvider';
import { DeleteUserException } from '../types/errors';
import { tokenOrchestrator } from '../tokenProvider';
import { signOut } from './signOut';
import { getAuthUserAgentValue } from '../../../utils';

import { signOut } from './signOut';

/**
* Deletes a user from the user pool while authenticated.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@

import { Amplify, fetchAuthSession } from '@aws-amplify/core';
import {
assertTokenProviderConfig,
AuthAction,
assertTokenProviderConfig,
} from '@aws-amplify/core/internals/utils';

import { deleteUserAttributes as deleteUserAttributesClient } from '../utils/clients/CognitoIdentityProvider';
import { getRegion } from '../utils/clients/CognitoIdentityProvider/utils';
import { assertAuthTokens } from '../utils/types';
Expand Down
6 changes: 5 additions & 1 deletion packages/auth/src/providers/cognito/apis/fetchDevices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@

import { Amplify, fetchAuthSession } from '@aws-amplify/core';
import {
assertTokenProviderConfig,
AuthAction,
assertTokenProviderConfig,
} from '@aws-amplify/core/internals/utils';

import { FetchDevicesOutput } from '../types';
import { listDevices } from '../utils/clients/CognitoIdentityProvider';
import { DeviceType } from '../utils/clients/CognitoIdentityProvider/types';
Expand Down Expand Up @@ -43,6 +44,7 @@ export async function fetchDevices(): Promise<FetchDevicesOutput> {
Limit: MAX_DEVICES,
},
);

return parseDevicesResponse(response.Devices ?? []);
}

Expand All @@ -62,10 +64,12 @@ const parseDevicesResponse = async (
if (Name && Value) {
attrs[Name] = Value;
}

return attrs;
},
{},
);

return {
id,
attributes,
Expand Down
11 changes: 6 additions & 5 deletions packages/auth/src/providers/cognito/apis/fetchMFAPreference.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import { FetchMFAPreferenceOutput } from '../types';
import { getMFAType, getMFATypes } from '../utils/signInHelpers';
import { GetUserException } from '../types/errors';
import { getUser } from '../utils/clients/CognitoIdentityProvider';
import { Amplify, fetchAuthSession } from '@aws-amplify/core';
import {
assertTokenProviderConfig,
AuthAction,
assertTokenProviderConfig,
} from '@aws-amplify/core/internals/utils';

import { FetchMFAPreferenceOutput } from '../types';
import { getMFAType, getMFATypes } from '../utils/signInHelpers';
import { GetUserException } from '../types/errors';
import { getUser } from '../utils/clients/CognitoIdentityProvider';
import { getRegion } from '../utils/clients/CognitoIdentityProvider/utils';
import { assertAuthTokens } from '../utils/types';
import { getAuthUserAgentValue } from '../../../utils';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
// SPDX-License-Identifier: Apache-2.0

import { Amplify } from '@aws-amplify/core';

import { FetchUserAttributesOutput } from '../types';
import { GetUserException } from '../types/errors';

import { fetchUserAttributes as fetchUserAttributesInternal } from './internal/fetchUserAttributes';

/**
Expand Down
7 changes: 4 additions & 3 deletions packages/auth/src/providers/cognito/apis/forgetDevice.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import { forgetDevice as serviceForgetDevice } from '../utils/clients/CognitoIdentityProvider';
import { Amplify, fetchAuthSession } from '@aws-amplify/core';
import { assertAuthTokens, assertDeviceMetadata } from '../utils/types';
import {
assertTokenProviderConfig,
AuthAction,
assertTokenProviderConfig,
} from '@aws-amplify/core/internals/utils';

import { forgetDevice as serviceForgetDevice } from '../utils/clients/CognitoIdentityProvider';
import { assertAuthTokens, assertDeviceMetadata } from '../utils/types';
import { getRegion } from '../utils/clients/CognitoIdentityProvider/utils';
import { tokenOrchestrator } from '../tokenProvider';
import { ForgetDeviceInput } from '../types';
Expand Down
3 changes: 3 additions & 0 deletions packages/auth/src/providers/cognito/apis/getCurrentUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
// SPDX-License-Identifier: Apache-2.0

import { Amplify } from '@aws-amplify/core';

import { GetCurrentUserOutput } from '../types';
import { InitiateAuthException } from '../types/errors';

import { getCurrentUser as getCurrentUserInternal } from './internal/getCurrentUser';

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
assertTokenProviderConfig,
fetchAuthSession,
} from '@aws-amplify/core/internals/utils';

import { getUser } from '../../utils/clients/CognitoIdentityProvider';
import { getRegion } from '../../utils/clients/CognitoIdentityProvider/utils';
import { assertAuthTokens } from '../../utils/types';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@

import { AmplifyClassV6, AuthTokens } from '@aws-amplify/core';
import { assertTokenProviderConfig } from '@aws-amplify/core/internals/utils';

import { assertAuthTokens } from '../../utils/types';
import {
CognitoAuthSignInDetails,
AuthUser,
CognitoAuthSignInDetails,
GetCurrentUserOutput,
} from '../../types';

Expand All @@ -29,6 +30,7 @@ export const getCurrentUser = async (
if (signInDetails) {
authUser.signInDetails = signInDetails;
}

return authUser;
};

Expand Down
7 changes: 4 additions & 3 deletions packages/auth/src/providers/cognito/apis/rememberDevice.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import { updateDeviceStatus } from '../utils/clients/CognitoIdentityProvider';
import { Amplify, fetchAuthSession } from '@aws-amplify/core';
import { assertAuthTokens, assertDeviceMetadata } from '../utils/types';
import {
assertTokenProviderConfig,
AuthAction,
assertTokenProviderConfig,
} from '@aws-amplify/core/internals/utils';

import { updateDeviceStatus } from '../utils/clients/CognitoIdentityProvider';
import { assertAuthTokens, assertDeviceMetadata } from '../utils/types';
import { getRegion } from '../utils/clients/CognitoIdentityProvider/utils';
import { tokenOrchestrator } from '../tokenProvider';
import { UpdateDeviceStatusException } from '../../cognito/types/errors';
Expand Down
Loading

0 comments on commit f049a9e

Please sign in to comment.