From 2471b20b628a0f423bc50c3a9e72ca76201ac3ba Mon Sep 17 00:00:00 2001 From: Jared Snider Date: Thu, 5 Jun 2025 12:03:57 -0400 Subject: [PATCH] PM-20532 - Clean up types and model middle sendId + email submission scenario --- .../identity-token/send-access-token.request.ts | 4 ++++ .../abstractions/send-token.service.ts | 16 +++++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/libs/common/src/auth/models/request/identity-token/send-access-token.request.ts b/libs/common/src/auth/models/request/identity-token/send-access-token.request.ts index b6f89fcd614..5c6cec20a2c 100644 --- a/libs/common/src/auth/models/request/identity-token/send-access-token.request.ts +++ b/libs/common/src/auth/models/request/identity-token/send-access-token.request.ts @@ -4,6 +4,7 @@ import { Scope } from "../../../enums/scopes.enum"; import { SendAccessCredentials } from "../../../send-access/abstractions/send-token.service"; export type SendAccessTokenPasswordPayload = { password_hash: string }; +export type SendAccessTokenEmailPayload = { email: string }; export type SendAccessTokenEmailOtpPayload = { email: string; otp: string }; export type SendAccessTokenAnonymousPayload = object; // empty object @@ -19,6 +20,7 @@ export interface SendAccessTokenPayloadBase { export type SendAccessTokenPayload = SendAccessTokenPayloadBase & ( | SendAccessTokenPasswordPayload + | SendAccessTokenEmailPayload | SendAccessTokenEmailOtpPayload | SendAccessTokenAnonymousPayload ); @@ -46,6 +48,8 @@ export class SendAccessTokenRequest { if (this.sendAccessCredentials && this.sendAccessCredentials.type === "password") { return { ...base, password_hash: this.sendAccessCredentials.passwordHash }; + } else if (this.sendAccessCredentials && this.sendAccessCredentials.type === "email") { + return { ...base, email: this.sendAccessCredentials.email }; } else if (this.sendAccessCredentials && this.sendAccessCredentials.type === "email-otp") { return { ...base, diff --git a/libs/common/src/auth/send-access/abstractions/send-token.service.ts b/libs/common/src/auth/send-access/abstractions/send-token.service.ts index c7b634dab27..2f70c750931 100644 --- a/libs/common/src/auth/send-access/abstractions/send-token.service.ts +++ b/libs/common/src/auth/send-access/abstractions/send-token.service.ts @@ -5,18 +5,28 @@ import { TryGetSendAccessTokenError, } from "../services/send-token.service"; -export type SendAccessCredentialsType = "password" | "email-otp"; - export type SendPasswordCredentials = { type: "password"; passwordHash: SendHashedPassword; }; + +// Credentials for sending an OTP to the user's email address. +// This is used when the send requires email verification with an OTP. +export type SendEmailCredentials = { + type: "email"; + email: string; +}; + +// Credentials for getting a send access token using an email and OTP. export type SendEmailOtpCredentials = { type: "email-otp"; email: string; otp: string; }; -export type SendAccessCredentials = SendPasswordCredentials | SendEmailOtpCredentials; +export type SendAccessCredentials = + | SendPasswordCredentials + | SendEmailCredentials + | SendEmailOtpCredentials; export abstract class SendTokenService { // TODO: consider converting to observable.