mirror of
https://github.com/bitwarden/browser
synced 2026-02-07 04:03:29 +00:00
PM-20532 - Clean up types and model middle sendId + email submission scenario
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user