From 740e2dc2065573441b4577bb80b42df2abc1aca5 Mon Sep 17 00:00:00 2001 From: awsluja <110861985+awsluja@users.noreply.github.com> Date: Tue, 26 Sep 2023 14:30:28 -0400 Subject: [PATCH] fix: make types more user friendly (#288) * fix: make types more user friendly * chore: update pkg lock * chore: add changeset --- .changeset/tidy-seals-fetch.md | 5 +++ packages/auth-construct/API.md | 12 +++--- packages/auth-construct/src/construct.test.ts | 42 +++++++++---------- packages/auth-construct/src/construct.ts | 6 +-- packages/auth-construct/src/types.ts | 24 ++++++++--- 5 files changed, 53 insertions(+), 36 deletions(-) create mode 100644 .changeset/tidy-seals-fetch.md diff --git a/.changeset/tidy-seals-fetch.md b/.changeset/tidy-seals-fetch.md new file mode 100644 index 0000000000..e2be92450d --- /dev/null +++ b/.changeset/tidy-seals-fetch.md @@ -0,0 +1,5 @@ +--- +'@aws-amplify/auth-construct-alpha': patch +--- + +Update types for verification settings. diff --git a/packages/auth-construct/API.md b/packages/auth-construct/API.md index 7bd3c5915b..3f52cbfa1d 100644 --- a/packages/auth-construct/API.md +++ b/packages/auth-construct/API.md @@ -94,13 +94,13 @@ export type BasicLoginOptions = { // @public export type EmailLogin = true | { - emailBody?: `${string}{####}${string}`; - emailStyle?: aws_cognito.VerificationEmailStyle.CODE; - emailSubject?: string; + verificationEmailStyle?: aws_cognito.VerificationEmailStyle.CODE; + verificationEmailBody?: `${string}{####}${string}`; + verificationEmailSubject?: string; } | { - emailBody?: `${string}{##Verify Email##}${string}`; - emailStyle?: aws_cognito.VerificationEmailStyle.LINK; - emailSubject?: string; + verificationEmailStyle?: aws_cognito.VerificationEmailStyle.LINK; + verificationEmailBody?: `${string}{##Verify Email##}${string}`; + verificationEmailSubject?: string; }; // @public diff --git a/packages/auth-construct/src/construct.test.ts b/packages/auth-construct/src/construct.test.ts index 7c308e6b43..c46a38f408 100644 --- a/packages/auth-construct/src/construct.test.ts +++ b/packages/auth-construct/src/construct.test.ts @@ -148,9 +148,9 @@ void describe('Auth construct', () => { new AmplifyAuth(stack, 'test', { loginWith: { email: { - emailBody: customEmailVerificationMessage, - emailStyle: VerificationEmailStyle.CODE, - emailSubject: customEmailVerificationSubject, + verificationEmailBody: customEmailVerificationMessage, + verificationEmailStyle: VerificationEmailStyle.CODE, + verificationEmailSubject: customEmailVerificationSubject, }, }, }); @@ -177,9 +177,9 @@ void describe('Auth construct', () => { new AmplifyAuth(stack, 'test', { loginWith: { email: { - emailBody: customEmailVerificationMessage, - emailStyle: VerificationEmailStyle.CODE, - emailSubject: customEmailVerificationSubject, + verificationEmailBody: customEmailVerificationMessage, + verificationEmailStyle: VerificationEmailStyle.CODE, + verificationEmailSubject: customEmailVerificationSubject, }, phoneNumber: { verificationMessage: smsVerificationMessage, @@ -217,9 +217,9 @@ void describe('Auth construct', () => { loginWith: { email: { // @ts-expect-error We know this is a compile error, but must have runtime validation as well. - emailBody: customEmailVerificationMessage, - emailStyle: VerificationEmailStyle.CODE, - emailSubject: customEmailVerificationSubject, + verificationEmailBody: customEmailVerificationMessage, + verificationEmailStyle: VerificationEmailStyle.CODE, + verificationEmailSubject: customEmailVerificationSubject, }, }, }; @@ -228,9 +228,9 @@ void describe('Auth construct', () => { props = { loginWith: { email: { - emailBody: validMessage, - emailStyle: VerificationEmailStyle.CODE, - emailSubject: customEmailVerificationSubject, + verificationEmailBody: validMessage, + verificationEmailStyle: VerificationEmailStyle.CODE, + verificationEmailSubject: customEmailVerificationSubject, }, }, }; @@ -246,9 +246,9 @@ void describe('Auth construct', () => { loginWith: { email: { // @ts-expect-error We expect this to be a compile error - emailBody: customEmailVerificationMessage, - emailStyle: VerificationEmailStyle.LINK, - emailSubject: customEmailVerificationSubject, + verificationEmailBody: customEmailVerificationMessage, + verificationEmailStyle: VerificationEmailStyle.LINK, + verificationEmailSubject: customEmailVerificationSubject, }, }, }; @@ -257,9 +257,9 @@ void describe('Auth construct', () => { props = { loginWith: { email: { - emailBody: validMessage, - emailStyle: VerificationEmailStyle.LINK, - emailSubject: customEmailVerificationSubject, + verificationEmailBody: validMessage, + verificationEmailStyle: VerificationEmailStyle.LINK, + verificationEmailSubject: customEmailVerificationSubject, }, }, }; @@ -278,9 +278,9 @@ void describe('Auth construct', () => { new AmplifyAuth(stack, 'test', { loginWith: { email: { - emailBody: customEmailVerificationMessage, - emailStyle: VerificationEmailStyle.LINK, - emailSubject: customEmailVerificationSubject, + verificationEmailBody: customEmailVerificationMessage, + verificationEmailStyle: VerificationEmailStyle.LINK, + verificationEmailSubject: customEmailVerificationSubject, }, }, }) diff --git a/packages/auth-construct/src/construct.ts b/packages/auth-construct/src/construct.ts index 7121193d7d..d002522163 100644 --- a/packages/auth-construct/src/construct.ts +++ b/packages/auth-construct/src/construct.ts @@ -219,9 +219,9 @@ export class AmplifyAuth if (emailEnabled && typeof props.loginWith.email === 'object') { const emailSettings = props.loginWith.email; userVerificationSettings = { - emailBody: emailSettings.emailBody, - emailStyle: emailSettings.emailStyle, - emailSubject: emailSettings.emailSubject, + emailBody: emailSettings.verificationEmailBody, + emailStyle: emailSettings.verificationEmailStyle, + emailSubject: emailSettings.verificationEmailSubject, }; } if (phoneEnabled && typeof props.loginWith.phoneNumber === 'object') { diff --git a/packages/auth-construct/src/types.ts b/packages/auth-construct/src/types.ts index 347b766458..9d74fdba2d 100644 --- a/packages/auth-construct/src/types.ts +++ b/packages/auth-construct/src/types.ts @@ -13,14 +13,26 @@ import { AuthOutput } from '@aws-amplify/backend-output-schemas/auth'; export type EmailLogin = | true | { - emailBody?: `${string}{####}${string}`; - emailStyle?: cognito.VerificationEmailStyle.CODE; - emailSubject?: string; + /** + * The type of verification. Must be one of aws_cognito.VerificationEmailStyle. + */ + verificationEmailStyle?: cognito.VerificationEmailStyle.CODE; + /** + * When verificationEmailStyle is set to VerificationEmailStyle.CODE, the emailBody must contain the template {####} where the code will be inserted. + */ + verificationEmailBody?: `${string}{####}${string}`; + /** + * The verification email subject. + */ + verificationEmailSubject?: string; } | { - emailBody?: `${string}{##Verify Email##}${string}`; - emailStyle?: cognito.VerificationEmailStyle.LINK; - emailSubject?: string; + verificationEmailStyle?: cognito.VerificationEmailStyle.LINK; + /** + * When verificationEmailStyle is set to VerificationEmailStyle.LINK, the emailBody must contain the template {##Verify Email##} where the link will be inserted. + */ + verificationEmailBody?: `${string}{##Verify Email##}${string}`; + verificationEmailSubject?: string; }; /** * Phone number login options.