refactor: import/export use cases (#2397)
This commit is contained in:
@@ -20,8 +20,8 @@ import {
|
||||
ApplicationStageChangedEventPayload,
|
||||
StorageValueModes,
|
||||
ChallengeObserver,
|
||||
ImportDataReturnType,
|
||||
ImportDataUseCase,
|
||||
ImportDataResult,
|
||||
ImportData,
|
||||
StoragePersistencePolicies,
|
||||
HomeServerServiceInterface,
|
||||
DeviceInterface,
|
||||
@@ -79,6 +79,8 @@ import {
|
||||
SetHost,
|
||||
MfaServiceInterface,
|
||||
GenerateUuid,
|
||||
CreateDecryptedBackupFile,
|
||||
CreateEncryptedBackupFile,
|
||||
} from '@standardnotes/services'
|
||||
import {
|
||||
SNNote,
|
||||
@@ -133,6 +135,7 @@ import { GetAuthenticatorAuthenticationOptions } from '@Lib/Domain/UseCase/GetAu
|
||||
import { Dependencies } from './Dependencies/Dependencies'
|
||||
import { TYPES } from './Dependencies/Types'
|
||||
import { RegisterApplicationServicesEvents } from './Dependencies/DependencyEvents'
|
||||
import { Result } from '@standardnotes/domain-core'
|
||||
|
||||
/** How often to automatically sync, in milliseconds */
|
||||
const DEFAULT_AUTO_SYNC_INTERVAL = 30_000
|
||||
@@ -672,26 +675,6 @@ export class SNApplication implements ApplicationInterface, AppGroupManagedAppli
|
||||
return this.protections.authorizeAutolockIntervalChange()
|
||||
}
|
||||
|
||||
public async createEncryptedBackupFileForAutomatedDesktopBackups(): Promise<BackupFile | undefined> {
|
||||
return this.encryption.createEncryptedBackupFile()
|
||||
}
|
||||
|
||||
public async createEncryptedBackupFile(): Promise<BackupFile | undefined> {
|
||||
if (!(await this.protections.authorizeBackupCreation())) {
|
||||
return
|
||||
}
|
||||
|
||||
return this.encryption.createEncryptedBackupFile()
|
||||
}
|
||||
|
||||
public async createDecryptedBackupFile(): Promise<BackupFile | undefined> {
|
||||
if (!(await this.protections.authorizeBackupCreation())) {
|
||||
return
|
||||
}
|
||||
|
||||
return this.encryption.createDecryptedBackupFile()
|
||||
}
|
||||
|
||||
public isEphemeralSession(): boolean {
|
||||
return this.storage.isEphemeralSession()
|
||||
}
|
||||
@@ -842,8 +825,8 @@ export class SNApplication implements ApplicationInterface, AppGroupManagedAppli
|
||||
})
|
||||
}
|
||||
|
||||
public async importData(data: BackupFile, awaitSync = false): Promise<ImportDataReturnType> {
|
||||
const usecase = this.dependencies.get<ImportDataUseCase>(TYPES.ImportDataUseCase)
|
||||
public async importData(data: BackupFile, awaitSync = false): Promise<Result<ImportDataResult>> {
|
||||
const usecase = this.dependencies.get<ImportData>(TYPES.ImportData)
|
||||
return usecase.execute(data, awaitSync)
|
||||
}
|
||||
|
||||
@@ -1164,6 +1147,14 @@ export class SNApplication implements ApplicationInterface, AppGroupManagedAppli
|
||||
return this.dependencies.get<GenerateUuid>(TYPES.GenerateUuid)
|
||||
}
|
||||
|
||||
public get createDecryptedBackupFile(): CreateDecryptedBackupFile {
|
||||
return this.dependencies.get<CreateDecryptedBackupFile>(TYPES.CreateDecryptedBackupFile)
|
||||
}
|
||||
|
||||
public get createEncryptedBackupFile(): CreateEncryptedBackupFile {
|
||||
return this.dependencies.get<CreateEncryptedBackupFile>(TYPES.CreateEncryptedBackupFile)
|
||||
}
|
||||
|
||||
private get migrations(): MigrationService {
|
||||
return this.dependencies.get<MigrationService>(TYPES.MigrationService)
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ import {
|
||||
GetAllContacts,
|
||||
GetVault,
|
||||
HomeServerService,
|
||||
ImportDataUseCase,
|
||||
ImportData,
|
||||
InMemoryStore,
|
||||
IntegrityService,
|
||||
InternalEventBus,
|
||||
@@ -133,7 +133,13 @@ import {
|
||||
GenerateUuid,
|
||||
GetVaultItems,
|
||||
ValidateVaultPassword,
|
||||
DecryptBackupPayloads,
|
||||
DetermineKeyToUse,
|
||||
GetBackupFileType,
|
||||
GetFilePassword,
|
||||
IsApplicationUsingThirdPartyHost,
|
||||
CreateDecryptedBackupFile,
|
||||
CreateEncryptedBackupFile,
|
||||
} from '@standardnotes/services'
|
||||
import { ItemManager } from '../../Services/Items/ItemManager'
|
||||
import { PayloadManager } from '../../Services/Payloads/PayloadManager'
|
||||
@@ -160,7 +166,7 @@ import {
|
||||
WebSocketServer,
|
||||
} from '@standardnotes/api'
|
||||
import { TYPES } from './Types'
|
||||
import { Logger, isNotUndefined, isDeinitable } from '@standardnotes/utils'
|
||||
import { Logger, isNotUndefined, isDeinitable, LoggerInterface } from '@standardnotes/utils'
|
||||
import { EncryptionOperators } from '@standardnotes/encryption'
|
||||
import { AsymmetricMessagePayload, AsymmetricMessageSharedVaultInvite } from '@standardnotes/models'
|
||||
import { PureCryptoInterface } from '@standardnotes/sncrypto-common'
|
||||
@@ -219,6 +225,29 @@ export class Dependencies {
|
||||
}
|
||||
|
||||
private registerUseCaseMakers() {
|
||||
this.factory.set(TYPES.DecryptBackupPayloads, () => {
|
||||
return new DecryptBackupPayloads(
|
||||
this.get<EncryptionService>(TYPES.EncryptionService),
|
||||
this.get<DetermineKeyToUse>(TYPES.DetermineKeyToUse),
|
||||
this.get<LoggerInterface>(TYPES.Logger),
|
||||
)
|
||||
})
|
||||
|
||||
this.factory.set(TYPES.DetermineKeyToUse, () => {
|
||||
return new DetermineKeyToUse(
|
||||
this.get<EncryptionService>(TYPES.EncryptionService),
|
||||
this.get<KeySystemKeyManager>(TYPES.KeySystemKeyManager),
|
||||
)
|
||||
})
|
||||
|
||||
this.factory.set(TYPES.GetBackupFileType, () => {
|
||||
return new GetBackupFileType()
|
||||
})
|
||||
|
||||
this.factory.set(TYPES.GetFilePassword, () => {
|
||||
return new GetFilePassword(this.get<ChallengeService>(TYPES.ChallengeService))
|
||||
})
|
||||
|
||||
this.factory.set(TYPES.ValidateVaultPassword, () => {
|
||||
return new ValidateVaultPassword(
|
||||
this.get<EncryptionService>(TYPES.EncryptionService),
|
||||
@@ -273,16 +302,31 @@ export class Dependencies {
|
||||
)
|
||||
})
|
||||
|
||||
this.factory.set(TYPES.ImportDataUseCase, () => {
|
||||
return new ImportDataUseCase(
|
||||
this.factory.set(TYPES.CreateDecryptedBackupFile, () => {
|
||||
return new CreateDecryptedBackupFile(
|
||||
this.get<PayloadManager>(TYPES.PayloadManager),
|
||||
this.get<ProtectionService>(TYPES.ProtectionService),
|
||||
)
|
||||
})
|
||||
|
||||
this.factory.set(TYPES.CreateEncryptedBackupFile, () => {
|
||||
return new CreateEncryptedBackupFile(
|
||||
this.get<ItemManager>(TYPES.ItemManager),
|
||||
this.get<ProtectionService>(TYPES.ProtectionService),
|
||||
this.get<EncryptionService>(TYPES.EncryptionService),
|
||||
)
|
||||
})
|
||||
|
||||
this.factory.set(TYPES.ImportData, () => {
|
||||
return new ImportData(
|
||||
this.get<ItemManager>(TYPES.ItemManager),
|
||||
this.get<SyncService>(TYPES.SyncService),
|
||||
this.get<ProtectionService>(TYPES.ProtectionService),
|
||||
this.get<EncryptionService>(TYPES.EncryptionService),
|
||||
this.get<PayloadManager>(TYPES.PayloadManager),
|
||||
this.get<ChallengeService>(TYPES.ChallengeService),
|
||||
this.get<HistoryManager>(TYPES.HistoryManager),
|
||||
this.get<DecryptBackupFile>(TYPES.DecryptBackupFile),
|
||||
this.get<GetFilePassword>(TYPES.GetFilePassword),
|
||||
)
|
||||
})
|
||||
|
||||
@@ -291,7 +335,12 @@ export class Dependencies {
|
||||
})
|
||||
|
||||
this.factory.set(TYPES.DecryptBackupFile, () => {
|
||||
return new DecryptBackupFile(this.get<EncryptionService>(TYPES.EncryptionService), this.get<Logger>(TYPES.Logger))
|
||||
return new DecryptBackupFile(
|
||||
this.get<EncryptionService>(TYPES.EncryptionService),
|
||||
this.get<KeySystemKeyManager>(TYPES.KeySystemKeyManager),
|
||||
this.get<GetBackupFileType>(TYPES.GetBackupFileType),
|
||||
this.get<DecryptBackupPayloads>(TYPES.DecryptBackupPayloads),
|
||||
)
|
||||
})
|
||||
|
||||
this.factory.set(TYPES.DiscardItemsLocally, () => {
|
||||
|
||||
@@ -89,7 +89,7 @@ export const TYPES = {
|
||||
ListRevisions: Symbol.for('ListRevisions'),
|
||||
GetRevision: Symbol.for('GetRevision'),
|
||||
DeleteRevision: Symbol.for('DeleteRevision'),
|
||||
ImportDataUseCase: Symbol.for('ImportDataUseCase'),
|
||||
ImportData: Symbol.for('ImportData'),
|
||||
DiscardItemsLocally: Symbol.for('DiscardItemsLocally'),
|
||||
FindContact: Symbol.for('FindContact'),
|
||||
GetAllContacts: Symbol.for('GetAllContacts'),
|
||||
@@ -163,7 +163,13 @@ export const TYPES = {
|
||||
GenerateUuid: Symbol.for('GenerateUuid'),
|
||||
GetVaultItems: Symbol.for('GetVaultItems'),
|
||||
ValidateVaultPassword: Symbol.for('ValidateVaultPassword'),
|
||||
DecryptBackupPayloads: Symbol.for('DecryptBackupPayloads'),
|
||||
DetermineKeyToUse: Symbol.for('DetermineKeyToUse'),
|
||||
GetBackupFileType: Symbol.for('GetBackupFileType'),
|
||||
GetFilePassword: Symbol.for('GetFilePassword'),
|
||||
AuthorizeVaultDeletion: Symbol.for('AuthorizeVaultDeletion'),
|
||||
CreateDecryptedBackupFile: Symbol.for('CreateDecryptedBackupFile'),
|
||||
CreateEncryptedBackupFile: Symbol.for('CreateEncryptedBackupFile'),
|
||||
|
||||
// Mappers
|
||||
SessionStorageMapper: Symbol.for('SessionStorageMapper'),
|
||||
|
||||
Reference in New Issue
Block a user