refactor: break up vault services (#2364)
This commit is contained in:
@@ -1,23 +0,0 @@
|
||||
import { AsymmetricMessageSharedVaultInvite } from '@standardnotes/models'
|
||||
import { SharedVaultInvitesServerInterface } from '@standardnotes/api'
|
||||
import { SharedVaultInviteServerHash } from '@standardnotes/responses'
|
||||
import { ProcessAcceptedVaultInvite } from '../../AsymmetricMessage/UseCase/ProcessAcceptedVaultInvite'
|
||||
|
||||
export class AcceptVaultInvite {
|
||||
constructor(
|
||||
private inviteServer: SharedVaultInvitesServerInterface,
|
||||
private processInvite: ProcessAcceptedVaultInvite,
|
||||
) {}
|
||||
|
||||
async execute(dto: {
|
||||
invite: SharedVaultInviteServerHash
|
||||
message: AsymmetricMessageSharedVaultInvite
|
||||
}): Promise<void> {
|
||||
await this.processInvite.execute(dto.message, dto.invite.shared_vault_uuid, dto.invite.sender_uuid)
|
||||
|
||||
await this.inviteServer.acceptInvite({
|
||||
sharedVaultUuid: dto.invite.shared_vault_uuid,
|
||||
inviteUuid: dto.invite.uuid,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
import { GetVaultUsers } from './GetVaultUsers'
|
||||
import { TrustedContactInterface } from '@standardnotes/models'
|
||||
import { isNotUndefined } from '@standardnotes/utils'
|
||||
import { FindContact } from '../../Contacts/UseCase/FindContact'
|
||||
import { Result, UseCaseInterface } from '@standardnotes/domain-core'
|
||||
|
||||
export class GetVaultContacts implements UseCaseInterface<TrustedContactInterface[]> {
|
||||
constructor(private findContact: FindContact, private getVaultUsers: GetVaultUsers) {}
|
||||
|
||||
async execute(sharedVaultUuid: string): Promise<Result<TrustedContactInterface[]>> {
|
||||
const users = await this.getVaultUsers.execute({ sharedVaultUuid })
|
||||
if (!users) {
|
||||
return Result.fail('Failed to get vault users')
|
||||
}
|
||||
|
||||
const contacts = users
|
||||
.map((user) => this.findContact.execute({ userUuid: user.user_uuid }))
|
||||
.map((result) => (result.isFailed() ? undefined : result.getValue()))
|
||||
.filter(isNotUndefined)
|
||||
|
||||
return Result.ok(contacts)
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
import { SharedVaultUserServerHash, isErrorResponse } from '@standardnotes/responses'
|
||||
import { SharedVaultUsersServerInterface } from '@standardnotes/api'
|
||||
|
||||
export class GetVaultUsers {
|
||||
constructor(private vaultUsersServer: SharedVaultUsersServerInterface) {}
|
||||
|
||||
async execute(params: { sharedVaultUuid: string }): Promise<SharedVaultUserServerHash[] | undefined> {
|
||||
const response = await this.vaultUsersServer.getSharedVaultUsers({ sharedVaultUuid: params.sharedVaultUuid })
|
||||
|
||||
if (isErrorResponse(response)) {
|
||||
return undefined
|
||||
}
|
||||
|
||||
return response.data.users
|
||||
}
|
||||
}
|
||||
@@ -1,135 +0,0 @@
|
||||
import { SharedVaultInviteServerHash, SharedVaultPermission } from '@standardnotes/responses'
|
||||
import {
|
||||
TrustedContactInterface,
|
||||
SharedVaultListingInterface,
|
||||
AsymmetricMessagePayloadType,
|
||||
VaultInviteDelegatedContact,
|
||||
} from '@standardnotes/models'
|
||||
import { SendVaultInvite } from './SendVaultInvite'
|
||||
import { PkcKeyPair } from '@standardnotes/sncrypto-common'
|
||||
import { EncryptMessage } from '../../Encryption/UseCase/Asymmetric/EncryptMessage'
|
||||
import { Result, UseCaseInterface } from '@standardnotes/domain-core'
|
||||
import { ShareContactWithVault } from './ShareContactWithVault'
|
||||
import { KeySystemKeyManagerInterface } from '../../KeySystem/KeySystemKeyManagerInterface'
|
||||
|
||||
export class InviteToVault implements UseCaseInterface<SharedVaultInviteServerHash> {
|
||||
constructor(
|
||||
private keyManager: KeySystemKeyManagerInterface,
|
||||
private encryptMessage: EncryptMessage,
|
||||
private sendInvite: SendVaultInvite,
|
||||
private shareContact: ShareContactWithVault,
|
||||
) {}
|
||||
|
||||
async execute(params: {
|
||||
keys: {
|
||||
encryption: PkcKeyPair
|
||||
signing: PkcKeyPair
|
||||
}
|
||||
senderUuid: string
|
||||
sharedVault: SharedVaultListingInterface
|
||||
sharedVaultContacts: TrustedContactInterface[]
|
||||
recipient: TrustedContactInterface
|
||||
permissions: SharedVaultPermission
|
||||
}): Promise<Result<SharedVaultInviteServerHash>> {
|
||||
const createInviteResult = await this.inviteContact(params)
|
||||
|
||||
if (createInviteResult.isFailed()) {
|
||||
return createInviteResult
|
||||
}
|
||||
|
||||
await this.shareContactWithOtherVaultMembers({
|
||||
contact: params.recipient,
|
||||
senderUuid: params.senderUuid,
|
||||
keys: params.keys,
|
||||
sharedVault: params.sharedVault,
|
||||
})
|
||||
|
||||
return createInviteResult
|
||||
}
|
||||
|
||||
private async shareContactWithOtherVaultMembers(params: {
|
||||
contact: TrustedContactInterface
|
||||
senderUuid: string
|
||||
keys: {
|
||||
encryption: PkcKeyPair
|
||||
signing: PkcKeyPair
|
||||
}
|
||||
sharedVault: SharedVaultListingInterface
|
||||
}): Promise<Result<void>> {
|
||||
const result = await this.shareContact.execute({
|
||||
keys: params.keys,
|
||||
senderUserUuid: params.senderUuid,
|
||||
sharedVault: params.sharedVault,
|
||||
contactToShare: params.contact,
|
||||
})
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
private async inviteContact(params: {
|
||||
keys: {
|
||||
encryption: PkcKeyPair
|
||||
signing: PkcKeyPair
|
||||
}
|
||||
sharedVault: SharedVaultListingInterface
|
||||
sharedVaultContacts: TrustedContactInterface[]
|
||||
recipient: TrustedContactInterface
|
||||
permissions: SharedVaultPermission
|
||||
}): Promise<Result<SharedVaultInviteServerHash>> {
|
||||
const keySystemRootKey = this.keyManager.getPrimaryKeySystemRootKey(params.sharedVault.systemIdentifier)
|
||||
if (!keySystemRootKey) {
|
||||
return Result.fail('Cannot invite contact; key system root key not found')
|
||||
}
|
||||
|
||||
const meContact = params.sharedVaultContacts.find((contact) => contact.isMe)
|
||||
if (!meContact) {
|
||||
return Result.fail('Cannot invite contact; me contact not found')
|
||||
}
|
||||
|
||||
const meContactContent: VaultInviteDelegatedContact = {
|
||||
name: undefined,
|
||||
contactUuid: meContact.contactUuid,
|
||||
publicKeySet: meContact.publicKeySet,
|
||||
}
|
||||
|
||||
const delegatedContacts: VaultInviteDelegatedContact[] = params.sharedVaultContacts
|
||||
.filter((contact) => !contact.isMe && contact.contactUuid !== params.recipient.contactUuid)
|
||||
.map((contact) => {
|
||||
return {
|
||||
name: contact.name,
|
||||
contactUuid: contact.contactUuid,
|
||||
publicKeySet: contact.publicKeySet,
|
||||
}
|
||||
})
|
||||
|
||||
const encryptedMessage = this.encryptMessage.execute({
|
||||
message: {
|
||||
type: AsymmetricMessagePayloadType.SharedVaultInvite,
|
||||
data: {
|
||||
recipientUuid: params.recipient.contactUuid,
|
||||
rootKey: keySystemRootKey.content,
|
||||
trustedContacts: [meContactContent, ...delegatedContacts],
|
||||
metadata: {
|
||||
name: params.sharedVault.name,
|
||||
description: params.sharedVault.description,
|
||||
},
|
||||
},
|
||||
},
|
||||
keys: params.keys,
|
||||
recipientPublicKey: params.recipient.publicKeySet.encryption,
|
||||
})
|
||||
|
||||
if (encryptedMessage.isFailed()) {
|
||||
return Result.fail(encryptedMessage.getError())
|
||||
}
|
||||
|
||||
const createInviteResult = await this.sendInvite.execute({
|
||||
sharedVaultUuid: params.sharedVault.sharing.sharedVaultUuid,
|
||||
recipientUuid: params.recipient.contactUuid,
|
||||
encryptedMessage: encryptedMessage.getValue(),
|
||||
permissions: params.permissions,
|
||||
})
|
||||
|
||||
return createInviteResult
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
import { ClientDisplayableError, isErrorResponse } from '@standardnotes/responses'
|
||||
import { SharedVaultUsersServerInterface } from '@standardnotes/api'
|
||||
import { DeleteThirdPartyVault } from './DeleteExternalSharedVault'
|
||||
import { ItemManagerInterface } from '../../Item/ItemManagerInterface'
|
||||
import { SharedVaultListingInterface } from '@standardnotes/models'
|
||||
|
||||
export class LeaveVault {
|
||||
constructor(
|
||||
private vaultUserServer: SharedVaultUsersServerInterface,
|
||||
private items: ItemManagerInterface,
|
||||
private deleteThirdPartyVault: DeleteThirdPartyVault,
|
||||
) {}
|
||||
|
||||
async execute(params: {
|
||||
sharedVault: SharedVaultListingInterface
|
||||
userUuid: string
|
||||
}): Promise<ClientDisplayableError | void> {
|
||||
const latestVaultListing = this.items.findItem<SharedVaultListingInterface>(params.sharedVault.uuid)
|
||||
if (!latestVaultListing) {
|
||||
throw new Error(`LeaveVaultUseCase: Could not find vault ${params.sharedVault.uuid}`)
|
||||
}
|
||||
|
||||
const response = await this.vaultUserServer.deleteSharedVaultUser({
|
||||
sharedVaultUuid: latestVaultListing.sharing.sharedVaultUuid,
|
||||
userUuid: params.userUuid,
|
||||
})
|
||||
|
||||
if (isErrorResponse(response)) {
|
||||
return ClientDisplayableError.FromString(`Failed to leave vault ${JSON.stringify(response)}`)
|
||||
}
|
||||
|
||||
await this.deleteThirdPartyVault.execute(latestVaultListing)
|
||||
}
|
||||
}
|
||||
@@ -4,8 +4,8 @@ import { SharedVaultInviteServerHash, isErrorResponse } from '@standardnotes/res
|
||||
import { SendVaultKeyChangedMessage } from './SendVaultKeyChangedMessage'
|
||||
import { PkcKeyPair } from '@standardnotes/sncrypto-common'
|
||||
import { Result, UseCaseInterface } from '@standardnotes/domain-core'
|
||||
import { InviteToVault } from './InviteToVault'
|
||||
import { GetVaultContacts } from './GetVaultContacts'
|
||||
import { InviteToVault } from '../../VaultInvite/UseCase/InviteToVault'
|
||||
import { GetVaultContacts } from '../../VaultUser/UseCase/GetVaultContacts'
|
||||
import { DecryptOwnMessage } from '../../Encryption/UseCase/Asymmetric/DecryptOwnMessage'
|
||||
import { FindContact } from '../../Contacts/UseCase/FindContact'
|
||||
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
import { ClientDisplayableError, isErrorResponse } from '@standardnotes/responses'
|
||||
import { SharedVaultUsersServerInterface } from '@standardnotes/api'
|
||||
|
||||
export class RemoveVaultMember {
|
||||
constructor(private vaultUserServer: SharedVaultUsersServerInterface) {}
|
||||
|
||||
async execute(params: { sharedVaultUuid: string; userUuid: string }): Promise<ClientDisplayableError | void> {
|
||||
const response = await this.vaultUserServer.deleteSharedVaultUser({
|
||||
sharedVaultUuid: params.sharedVaultUuid,
|
||||
userUuid: params.userUuid,
|
||||
})
|
||||
|
||||
if (isErrorResponse(response)) {
|
||||
return ClientDisplayableError.FromNetworkError(response)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,86 +0,0 @@
|
||||
import { SharedVaultInviteServerHash, isErrorResponse } from '@standardnotes/responses'
|
||||
import { SharedVaultInvitesServerInterface } from '@standardnotes/api'
|
||||
import { PkcKeyPair } from '@standardnotes/sncrypto-common'
|
||||
import { Result, UseCaseInterface } from '@standardnotes/domain-core'
|
||||
import { ReuploadInvite } from './ReuploadInvite'
|
||||
import { FindContact } from '../../Contacts/UseCase/FindContact'
|
||||
|
||||
type ReuploadAllInvitesDTO = {
|
||||
keys: {
|
||||
encryption: PkcKeyPair
|
||||
signing: PkcKeyPair
|
||||
}
|
||||
previousKeys?: {
|
||||
encryption: PkcKeyPair
|
||||
signing: PkcKeyPair
|
||||
}
|
||||
}
|
||||
|
||||
export class ReuploadAllInvites implements UseCaseInterface<void> {
|
||||
constructor(
|
||||
private reuploadInvite: ReuploadInvite,
|
||||
private findContact: FindContact,
|
||||
private inviteServer: SharedVaultInvitesServerInterface,
|
||||
) {}
|
||||
|
||||
async execute(params: ReuploadAllInvitesDTO): Promise<Result<void>> {
|
||||
const invites = await this.getExistingInvites()
|
||||
if (invites.isFailed()) {
|
||||
return invites
|
||||
}
|
||||
|
||||
const deleteResult = await this.deleteExistingInvites()
|
||||
if (deleteResult.isFailed()) {
|
||||
return deleteResult
|
||||
}
|
||||
|
||||
const errors: string[] = []
|
||||
|
||||
for (const invite of invites.getValue()) {
|
||||
const recipient = this.findContact.execute({ userUuid: invite.user_uuid })
|
||||
if (recipient.isFailed()) {
|
||||
errors.push(`Contact not found for invite ${invite.user_uuid}`)
|
||||
continue
|
||||
}
|
||||
|
||||
const result = await this.reuploadInvite.execute({
|
||||
keys: params.keys,
|
||||
previousKeys: params.previousKeys,
|
||||
recipient: recipient.getValue(),
|
||||
previousInvite: invite,
|
||||
})
|
||||
|
||||
if (result.isFailed()) {
|
||||
errors.push(result.getError())
|
||||
}
|
||||
}
|
||||
|
||||
if (errors.length > 0) {
|
||||
return Result.fail(errors.join(', '))
|
||||
}
|
||||
|
||||
return Result.ok()
|
||||
}
|
||||
|
||||
private async getExistingInvites(): Promise<Result<SharedVaultInviteServerHash[]>> {
|
||||
const response = await this.inviteServer.getOutboundUserInvites()
|
||||
|
||||
if (isErrorResponse(response)) {
|
||||
return Result.fail(`Failed to get outbound user invites ${response}`)
|
||||
}
|
||||
|
||||
const invites = response.data.invites
|
||||
|
||||
return Result.ok(invites)
|
||||
}
|
||||
|
||||
private async deleteExistingInvites(): Promise<Result<void>> {
|
||||
const response = await this.inviteServer.deleteAllOutboundInvites()
|
||||
|
||||
if (isErrorResponse(response)) {
|
||||
return Result.fail(`Failed to delete existing invites ${response}`)
|
||||
}
|
||||
|
||||
return Result.ok()
|
||||
}
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
import { DecryptOwnMessage } from './../../Encryption/UseCase/Asymmetric/DecryptOwnMessage'
|
||||
import { AsymmetricMessageSharedVaultInvite, TrustedContactInterface } from '@standardnotes/models'
|
||||
import { SharedVaultInviteServerHash } from '@standardnotes/responses'
|
||||
import { PkcKeyPair } from '@standardnotes/sncrypto-common'
|
||||
import { Result, UseCaseInterface } from '@standardnotes/domain-core'
|
||||
import { SendVaultInvite } from './SendVaultInvite'
|
||||
import { EncryptMessage } from '../../Encryption/UseCase/Asymmetric/EncryptMessage'
|
||||
|
||||
export class ReuploadInvite implements UseCaseInterface<void> {
|
||||
constructor(
|
||||
private decryptOwnMessage: DecryptOwnMessage<AsymmetricMessageSharedVaultInvite>,
|
||||
private sendInvite: SendVaultInvite,
|
||||
private encryptMessage: EncryptMessage,
|
||||
) {}
|
||||
|
||||
async execute(params: {
|
||||
keys: {
|
||||
encryption: PkcKeyPair
|
||||
signing: PkcKeyPair
|
||||
}
|
||||
previousKeys?: {
|
||||
encryption: PkcKeyPair
|
||||
signing: PkcKeyPair
|
||||
}
|
||||
recipient: TrustedContactInterface
|
||||
previousInvite: SharedVaultInviteServerHash
|
||||
}): Promise<Result<SharedVaultInviteServerHash>> {
|
||||
const decryptedPreviousInvite = this.decryptOwnMessage.execute({
|
||||
message: params.previousInvite.encrypted_message,
|
||||
privateKey: params.previousKeys?.encryption.privateKey ?? params.keys.encryption.privateKey,
|
||||
recipientPublicKey: params.recipient.publicKeySet.encryption,
|
||||
})
|
||||
|
||||
if (decryptedPreviousInvite.isFailed()) {
|
||||
return Result.fail(decryptedPreviousInvite.getError())
|
||||
}
|
||||
|
||||
const encryptedMessage = this.encryptMessage.execute({
|
||||
message: decryptedPreviousInvite.getValue(),
|
||||
keys: params.keys,
|
||||
recipientPublicKey: params.recipient.publicKeySet.encryption,
|
||||
})
|
||||
|
||||
if (encryptedMessage.isFailed()) {
|
||||
return Result.fail(encryptedMessage.getError())
|
||||
}
|
||||
|
||||
const createInviteResult = await this.sendInvite.execute({
|
||||
sharedVaultUuid: params.previousInvite.shared_vault_uuid,
|
||||
recipientUuid: params.recipient.contactUuid,
|
||||
encryptedMessage: encryptedMessage.getValue(),
|
||||
permissions: params.previousInvite.permissions,
|
||||
})
|
||||
|
||||
return createInviteResult
|
||||
}
|
||||
}
|
||||
@@ -1,86 +0,0 @@
|
||||
import { SharedVaultListingInterface } from '@standardnotes/models'
|
||||
import { SharedVaultInviteServerHash, isErrorResponse } from '@standardnotes/responses'
|
||||
import { SharedVaultInvitesServerInterface } from '@standardnotes/api'
|
||||
import { PkcKeyPair } from '@standardnotes/sncrypto-common'
|
||||
import { Result, UseCaseInterface } from '@standardnotes/domain-core'
|
||||
import { ReuploadInvite } from './ReuploadInvite'
|
||||
import { FindContact } from '../../Contacts/UseCase/FindContact'
|
||||
|
||||
type ReuploadVaultInvitesDTO = {
|
||||
sharedVault: SharedVaultListingInterface
|
||||
senderUuid: string
|
||||
keys: {
|
||||
encryption: PkcKeyPair
|
||||
signing: PkcKeyPair
|
||||
}
|
||||
}
|
||||
|
||||
export class ReuploadVaultInvites implements UseCaseInterface<void> {
|
||||
constructor(
|
||||
private reuploadInvite: ReuploadInvite,
|
||||
private findContact: FindContact,
|
||||
private inviteServer: SharedVaultInvitesServerInterface,
|
||||
) {}
|
||||
|
||||
async execute(params: ReuploadVaultInvitesDTO): Promise<Result<void>> {
|
||||
const existingInvites = await this.getExistingInvites(params.sharedVault.sharing.sharedVaultUuid)
|
||||
if (existingInvites.isFailed()) {
|
||||
return existingInvites
|
||||
}
|
||||
|
||||
const deleteResult = await this.deleteExistingInvites(params.sharedVault.sharing.sharedVaultUuid)
|
||||
if (deleteResult.isFailed()) {
|
||||
return deleteResult
|
||||
}
|
||||
|
||||
const errors: string[] = []
|
||||
|
||||
for (const invite of existingInvites.getValue()) {
|
||||
const recipient = this.findContact.execute({ userUuid: invite.user_uuid })
|
||||
if (recipient.isFailed()) {
|
||||
errors.push(`Contact not found for invite ${invite.user_uuid}`)
|
||||
continue
|
||||
}
|
||||
|
||||
const result = await this.reuploadInvite.execute({
|
||||
keys: params.keys,
|
||||
recipient: recipient.getValue(),
|
||||
previousInvite: invite,
|
||||
})
|
||||
|
||||
if (result.isFailed()) {
|
||||
errors.push(result.getError())
|
||||
}
|
||||
}
|
||||
|
||||
if (errors.length > 0) {
|
||||
return Result.fail(errors.join(', '))
|
||||
}
|
||||
|
||||
return Result.ok()
|
||||
}
|
||||
|
||||
private async getExistingInvites(sharedVaultUuid: string): Promise<Result<SharedVaultInviteServerHash[]>> {
|
||||
const response = await this.inviteServer.getOutboundUserInvites()
|
||||
|
||||
if (isErrorResponse(response)) {
|
||||
return Result.fail(`Failed to get outbound user invites ${response}`)
|
||||
}
|
||||
|
||||
const invites = response.data.invites
|
||||
|
||||
return Result.ok(invites.filter((invite) => invite.shared_vault_uuid === sharedVaultUuid))
|
||||
}
|
||||
|
||||
private async deleteExistingInvites(sharedVaultUuid: string): Promise<Result<void>> {
|
||||
const response = await this.inviteServer.deleteAllSharedVaultInvites({
|
||||
sharedVaultUuid: sharedVaultUuid,
|
||||
})
|
||||
|
||||
if (isErrorResponse(response)) {
|
||||
return Result.fail(`Failed to delete existing invites ${response}`)
|
||||
}
|
||||
|
||||
return Result.ok()
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@ import {
|
||||
TrustedContactInterface,
|
||||
} from '@standardnotes/models'
|
||||
import { AsymmetricMessageServerHash } from '@standardnotes/responses'
|
||||
import { GetVaultUsers } from './GetVaultUsers'
|
||||
import { GetVaultUsers } from '../../VaultUser/UseCase/GetVaultUsers'
|
||||
import { PkcKeyPair } from '@standardnotes/sncrypto-common'
|
||||
import { SendMessage } from '../../AsymmetricMessage/UseCase/SendMessage'
|
||||
import { EncryptMessage } from '../../Encryption/UseCase/Asymmetric/EncryptMessage'
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
import {
|
||||
SharedVaultInviteServerHash,
|
||||
isErrorResponse,
|
||||
SharedVaultPermission,
|
||||
getErrorFromErrorResponse,
|
||||
} from '@standardnotes/responses'
|
||||
import { SharedVaultInvitesServerInterface } from '@standardnotes/api'
|
||||
import { Result, UseCaseInterface } from '@standardnotes/domain-core'
|
||||
|
||||
export class SendVaultInvite implements UseCaseInterface<SharedVaultInviteServerHash> {
|
||||
constructor(private vaultInvitesServer: SharedVaultInvitesServerInterface) {}
|
||||
|
||||
async execute(params: {
|
||||
sharedVaultUuid: string
|
||||
recipientUuid: string
|
||||
encryptedMessage: string
|
||||
permissions: SharedVaultPermission
|
||||
}): Promise<Result<SharedVaultInviteServerHash>> {
|
||||
const response = await this.vaultInvitesServer.createInvite({
|
||||
sharedVaultUuid: params.sharedVaultUuid,
|
||||
recipientUuid: params.recipientUuid,
|
||||
encryptedMessage: params.encryptedMessage,
|
||||
permissions: params.permissions,
|
||||
})
|
||||
|
||||
if (isErrorResponse(response)) {
|
||||
return Result.fail(getErrorFromErrorResponse(response).message)
|
||||
}
|
||||
|
||||
return Result.ok(response.data.invite)
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@ import {
|
||||
TrustedContactInterface,
|
||||
} from '@standardnotes/models'
|
||||
import { AsymmetricMessageServerHash } from '@standardnotes/responses'
|
||||
import { GetVaultUsers } from './GetVaultUsers'
|
||||
import { GetVaultUsers } from '../../VaultUser/UseCase/GetVaultUsers'
|
||||
import { PkcKeyPair } from '@standardnotes/sncrypto-common'
|
||||
import { SendMessage } from '../../AsymmetricMessage/UseCase/SendMessage'
|
||||
import { EncryptMessage } from '../../Encryption/UseCase/Asymmetric/EncryptMessage'
|
||||
|
||||
@@ -8,7 +8,7 @@ import { SendMessage } from '../../AsymmetricMessage/UseCase/SendMessage'
|
||||
import { EncryptMessage } from '../../Encryption/UseCase/Asymmetric/EncryptMessage'
|
||||
import { Result, UseCaseInterface } from '@standardnotes/domain-core'
|
||||
import { FindContact } from '../../Contacts/UseCase/FindContact'
|
||||
import { GetVaultUsers } from './GetVaultUsers'
|
||||
import { GetVaultUsers } from '../../VaultUser/UseCase/GetVaultUsers'
|
||||
|
||||
export class ShareContactWithVault implements UseCaseInterface<void> {
|
||||
constructor(
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
import {
|
||||
ClientDisplayableError,
|
||||
SharedVaultInviteServerHash,
|
||||
isErrorResponse,
|
||||
SharedVaultPermission,
|
||||
} from '@standardnotes/responses'
|
||||
import { SharedVaultInvitesServerInterface } from '@standardnotes/api'
|
||||
|
||||
export class UpdateSharedVaultInviteUseCase {
|
||||
constructor(private vaultInvitesServer: SharedVaultInvitesServerInterface) {}
|
||||
|
||||
async execute(params: {
|
||||
sharedVaultUuid: string
|
||||
inviteUuid: string
|
||||
encryptedMessage: string
|
||||
permissions: SharedVaultPermission
|
||||
}): Promise<SharedVaultInviteServerHash | ClientDisplayableError> {
|
||||
const response = await this.vaultInvitesServer.updateInvite({
|
||||
sharedVaultUuid: params.sharedVaultUuid,
|
||||
inviteUuid: params.inviteUuid,
|
||||
encryptedMessage: params.encryptedMessage,
|
||||
permissions: params.permissions,
|
||||
})
|
||||
|
||||
if (isErrorResponse(response)) {
|
||||
return ClientDisplayableError.FromNetworkError(response)
|
||||
}
|
||||
|
||||
return response.data.invite
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user