Skip to content

Commit

Permalink
chore: change enum AuthUpdateAttributeStep to union string
Browse files Browse the repository at this point in the history
  • Loading branch information
israx committed Sep 13, 2023
1 parent f16ab3a commit 35a50b2
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { fetchTransferHandler } from '@aws-amplify/core/internals/aws-client-uti
import { buildMockErrorResponse, mockJsonResponse } from './testUtils/data';
import { UpdateUserAttributesCommandOutput } from '../../../src/providers/cognito/utils/clients/CognitoIdentityProvider/types';
import { toAttributeType } from '../../../src/providers/cognito/utils/apiHelpers';
import { AuthUpdateAttributeStep } from '../../../src/types/enums';
jest.mock('@aws-amplify/core/lib/clients/handlers/fetch');

Amplify.configure({
Expand Down Expand Up @@ -86,22 +85,21 @@ describe('updateUserAttributes API happy path cases', () => {
expect(result.address).toEqual({
isUpdated: true,
nextStep: {
updateAttributeStep: AuthUpdateAttributeStep.DONE,
updateAttributeStep: 'DONE',
},
});

expect(result.name).toEqual({
isUpdated: true,
nextStep: {
updateAttributeStep: AuthUpdateAttributeStep.DONE,
updateAttributeStep: 'DONE',
},
});

expect(result.email).toEqual({
isUpdated: false,
nextStep: {
updateAttributeStep:
AuthUpdateAttributeStep.CONFIRM_ATTRIBUTE_WITH_CODE,
updateAttributeStep: 'CONFIRM_ATTRIBUTE_WITH_CODE',
codeDeliveryDetails: {
attributeName: 'email',
deliveryMedium: 'EMAIL',
Expand All @@ -113,8 +111,7 @@ describe('updateUserAttributes API happy path cases', () => {
expect(result.phone_number).toEqual({
isUpdated: false,
nextStep: {
updateAttributeStep:
AuthUpdateAttributeStep.CONFIRM_ATTRIBUTE_WITH_CODE,
updateAttributeStep: 'CONFIRM_ATTRIBUTE_WITH_CODE',
codeDeliveryDetails: {
attributeName: 'phone_number',
deliveryMedium: 'SMS',
Expand Down Expand Up @@ -157,14 +154,14 @@ describe('updateUserAttributes API happy path cases', () => {
expect(result.address).toEqual({
isUpdated: true,
nextStep: {
updateAttributeStep: AuthUpdateAttributeStep.DONE,
updateAttributeStep: 'DONE',
},
});

expect(result.name).toEqual({
isUpdated: true,
nextStep: {
updateAttributeStep: AuthUpdateAttributeStep.DONE,
updateAttributeStep: 'DONE',
},
});

Expand Down Expand Up @@ -215,8 +212,7 @@ describe('updateUserAttributes API happy path cases', () => {
expect(result.email).toEqual({
isUpdated: false,
nextStep: {
updateAttributeStep:
AuthUpdateAttributeStep.CONFIRM_ATTRIBUTE_WITH_CODE,
updateAttributeStep: 'CONFIRM_ATTRIBUTE_WITH_CODE',
codeDeliveryDetails: {
attributeName: 'email',
deliveryMedium: 'EMAIL',
Expand All @@ -228,8 +224,7 @@ describe('updateUserAttributes API happy path cases', () => {
expect(result.phone_number).toEqual({
isUpdated: false,
nextStep: {
updateAttributeStep:
AuthUpdateAttributeStep.CONFIRM_ATTRIBUTE_WITH_CODE,
updateAttributeStep: 'CONFIRM_ATTRIBUTE_WITH_CODE',
codeDeliveryDetails: {
attributeName: 'phone_number',
deliveryMedium: 'SMS',
Expand Down
2 changes: 1 addition & 1 deletion packages/auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"clean:size": "rimraf dual-publish-tmp tmp*",
"format": "echo \"Not implemented\"",
"lint": "tslint '{src}/**/*.ts' && npm run ts-coverage",
"ts-coverage": "typescript-coverage-report -p ./tsconfig.json -t 91.20"
"ts-coverage": "typescript-coverage-report -p ./tsconfig.json -t 91.19"
},
"typesVersions": {
">=3.8": {
Expand Down
3 changes: 0 additions & 3 deletions packages/auth/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ export {
fetchUserAttributes,
signOut,
} from './providers/cognito';
export {
AuthUpdateAttributeStep
} from './types/enums';

export { AuthError } from './errors/AuthError';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import { assertAuthTokens } from '../utils/types';
import { getRegion } from '../utils/clients/CognitoIdentityProvider/utils';
import { toAttributeType } from '../utils/apiHelpers';
import { CodeDeliveryDetailsType } from '../utils/clients/CognitoIdentityProvider/types';
import { AuthUpdateAttributeStep } from '../../../types/enums';
import { UpdateUserAttributesException } from '../types/errors';

/**
Expand Down Expand Up @@ -68,7 +67,7 @@ function getConfirmedAttributes(
confirmedAttributes[key] = {
isUpdated: true,
nextStep: {
updateAttributeStep: AuthUpdateAttributeStep.DONE,
updateAttributeStep: 'DONE',
},
};
});
Expand All @@ -86,8 +85,7 @@ function getUnConfirmedAttributes(
unConfirmedAttributes[AttributeName] = {
isUpdated: false,
nextStep: {
updateAttributeStep:
AuthUpdateAttributeStep.CONFIRM_ATTRIBUTE_WITH_CODE,
updateAttributeStep: 'CONFIRM_ATTRIBUTE_WITH_CODE',
codeDeliveryDetails: {
attributeName: AttributeName,
deliveryMedium: DeliveryMedium as DeliveryMedium,
Expand Down
18 changes: 0 additions & 18 deletions packages/auth/src/types/enums.ts

This file was deleted.

7 changes: 2 additions & 5 deletions packages/auth/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@
// TODO: Remove "./Auth" export
export * from './Auth';

export {
AuthUpdateAttributeStep,
} from './enums';

export {
AdditionalInfo,
DeliveryMedium,
Expand All @@ -25,7 +21,8 @@ export {
AuthUser,
TOTPSetupDetails,
AuthResetPasswordStep,
AuthSignUpStep
AuthSignUpStep,
AuthUpdateAttributeStep,
} from './models';

export { AuthServiceOptions, AuthSignUpOptions } from './options';
Expand Down
28 changes: 16 additions & 12 deletions packages/auth/src/types/models.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

import { AuthUpdateAttributeStep } from './enums';

/**
* Additional data that may be returned from Auth APIs.
*/
Expand Down Expand Up @@ -246,20 +244,26 @@ export type AuthNextSignUpStep<
codeDeliveryDetails?: AuthCodeDeliveryDetails<UserAttributeKey>;
};

export type ConfirmAttributeWithCodeAttributeStep<
UserAttributeKey extends AuthUserAttributeKey = AuthUserAttributeKey
> = {
updateAttributeStep: AuthUpdateAttributeStep.CONFIRM_ATTRIBUTE_WITH_CODE;
codeDeliveryDetails: AuthCodeDeliveryDetails<UserAttributeKey>;
};
/**
* Denotes the next step in the Update User Attribute process.
*/
export type AuthUpdateAttributeStep =
/**
* Auth update attribute step requires user to confirm an attribute with a code sent to cellphone or email.
*/
| 'CONFIRM_ATTRIBUTE_WITH_CODE'

export type DoneAttributeStep = {
updateAttributeStep: AuthUpdateAttributeStep.DONE;
};
/**
* Auth update attribute step indicates that the attribute is updated.
*/
| 'DONE';

export type AuthNextUpdateAttributeStep<
UserAttributeKey extends AuthUserAttributeKey = AuthUserAttributeKey
> = ConfirmAttributeWithCodeAttributeStep<UserAttributeKey> | DoneAttributeStep;
> = {
updateAttributeStep: AuthUpdateAttributeStep;
codeDeliveryDetails?: AuthCodeDeliveryDetails<UserAttributeKey>;
};

/**
* The AuthUser object contains username and userId from the idToken.
Expand Down

0 comments on commit 35a50b2

Please sign in to comment.