chore: fix ContentType usage (#2353)

* chore: fix ContentType usage

* chore: fix specs
This commit is contained in:
Karol Sójko
2023-07-12 13:53:29 +02:00
committed by GitHub
parent d057cdff84
commit 325737bfbd
247 changed files with 1092 additions and 1060 deletions

View File

@@ -3,7 +3,7 @@ import { SyncOptions } from './../Sync/SyncOptions'
import { ImportDataReturnType } from './../Mutator/ImportDataUseCase'
import { ChallengeServiceInterface } from './../Challenge/ChallengeServiceInterface'
import { VaultServiceInterface } from './../Vaults/VaultServiceInterface'
import { ApplicationIdentifier, ContentType } from '@standardnotes/common'
import { ApplicationIdentifier } from '@standardnotes/common'
import {
BackupFile,
DecryptedItemInterface,
@@ -57,7 +57,7 @@ export interface ApplicationInterface {
getPreference<K extends PrefKey>(key: K, defaultValue?: PrefValue[K]): PrefValue[K] | undefined
setPreference<K extends PrefKey>(key: K, value: PrefValue[K]): Promise<void>
streamItems<I extends DecryptedItemInterface = DecryptedItemInterface>(
contentType: ContentType | ContentType[],
contentType: string | string[],
stream: ItemStream<I>,
): () => void

View File

@@ -2,7 +2,7 @@ import { MutatorClientInterface } from './../../Mutator/MutatorClientInterface'
import { HandleTrustedSharedVaultInviteMessage } from './HandleTrustedSharedVaultInviteMessage'
import { SyncServiceInterface } from '../../Sync/SyncServiceInterface'
import { ContactServiceInterface } from '../../Contacts/ContactServiceInterface'
import { ContentType } from '@standardnotes/common'
import { ContentType } from '@standardnotes/domain-core'
import {
AsymmetricMessagePayloadType,
AsymmetricMessageSharedVaultInvite,
@@ -55,11 +55,11 @@ describe('HandleTrustedSharedVaultInviteMessage', () => {
await handleTrustedSharedVaultInviteMessage.execute(testMessage, sharedVaultUuid, senderUuid)
const keySystemRootKeyCallIndex = mutatorMock.createItem.mock.calls.findIndex(
([contentType]) => contentType === ContentType.KeySystemRootKey,
([contentType]) => contentType === ContentType.TYPES.KeySystemRootKey,
)
const vaultListingCallIndex = mutatorMock.createItem.mock.calls.findIndex(
([contentType]) => contentType === ContentType.VaultListing,
([contentType]) => contentType === ContentType.TYPES.VaultListing,
)
expect(keySystemRootKeyCallIndex).toBeLessThan(vaultListingCallIndex)

View File

@@ -9,8 +9,8 @@ import {
VaultListingContentSpecialized,
KeySystemRootKeyStorageMode,
} from '@standardnotes/models'
import { ContentType } from '@standardnotes/common'
import { MutatorClientInterface } from '../../Mutator/MutatorClientInterface'
import { ContentType } from '@standardnotes/domain-core'
export class HandleTrustedSharedVaultInviteMessage {
constructor(
@@ -39,12 +39,12 @@ export class HandleTrustedSharedVaultInviteMessage {
}
await this.mutator.createItem<KeySystemRootKeyInterface>(
ContentType.KeySystemRootKey,
ContentType.TYPES.KeySystemRootKey,
FillItemContent<KeySystemRootKeyContent>(rootKeyContent),
true,
)
await this.mutator.createItem(ContentType.VaultListing, FillItemContentSpecialized(content), true)
await this.mutator.createItem(ContentType.TYPES.VaultListing, FillItemContentSpecialized(content), true)
for (const contact of trustedContacts) {
if (contact.isMe) {

View File

@@ -9,7 +9,7 @@ import {
VaultListingMutator,
} from '@standardnotes/models'
import { ContentType } from '@standardnotes/common'
import { ContentType } from '@standardnotes/domain-core'
import { GetVaultUseCase } from '../../Vaults/UseCase/GetVault'
import { EncryptionProviderInterface } from '@standardnotes/encryption'
@@ -25,7 +25,7 @@ export class HandleTrustedSharedVaultRootKeyChangedMessage {
const rootKeyContent = message.data.rootKey
await this.mutator.createItem<KeySystemRootKeyInterface>(
ContentType.KeySystemRootKey,
ContentType.TYPES.KeySystemRootKey,
FillItemContent<KeySystemRootKeyContent>(rootKeyContent),
true,
)

View File

@@ -1,6 +1,5 @@
import { NoteType } from '@standardnotes/features'
import { ApplicationStage } from './../Application/ApplicationStage'
import { ContentType } from '@standardnotes/common'
import { EncryptionProviderInterface } from '@standardnotes/encryption'
import {
PayloadEmitSource,
@@ -34,6 +33,7 @@ import { StorageKey } from '../Storage/StorageKeys'
import { SessionsClientInterface } from '../Session/SessionsClientInterface'
import { PayloadManagerInterface } from '../Payloads/PayloadManagerInterface'
import { HistoryServiceInterface } from '../History/HistoryServiceInterface'
import { ContentType } from '@standardnotes/domain-core'
const PlaintextBackupsDirectoryName = 'Plaintext Backups'
export const TextBackupsDirectoryName = 'Text Backups'
@@ -65,16 +65,19 @@ export class FilesBackupService extends AbstractService implements BackupService
) {
super(internalEventBus)
this.filesObserverDisposer = items.addObserver<FileItem>(ContentType.File, ({ changed, inserted, source }) => {
const applicableSources = [
PayloadEmitSource.LocalDatabaseLoaded,
PayloadEmitSource.RemoteSaved,
PayloadEmitSource.RemoteRetrieved,
]
if (applicableSources.includes(source)) {
void this.handleChangedFiles([...changed, ...inserted])
}
})
this.filesObserverDisposer = items.addObserver<FileItem>(
ContentType.TYPES.File,
({ changed, inserted, source }) => {
const applicableSources = [
PayloadEmitSource.LocalDatabaseLoaded,
PayloadEmitSource.RemoteSaved,
PayloadEmitSource.RemoteRetrieved,
]
if (applicableSources.includes(source)) {
void this.handleChangedFiles([...changed, ...inserted])
}
},
)
const noteAndTagSources = [
PayloadEmitSource.RemoteSaved,
@@ -82,13 +85,13 @@ export class FilesBackupService extends AbstractService implements BackupService
PayloadEmitSource.OfflineSyncSaved,
]
this.notesObserverDisposer = items.addObserver<SNNote>(ContentType.Note, ({ changed, inserted, source }) => {
this.notesObserverDisposer = items.addObserver<SNNote>(ContentType.TYPES.Note, ({ changed, inserted, source }) => {
if (noteAndTagSources.includes(source)) {
void this.handleChangedNotes([...changed, ...inserted])
}
})
this.tagsObserverDisposer = items.addObserver<SNTag>(ContentType.Tag, ({ changed, inserted, source }) => {
this.tagsObserverDisposer = items.addObserver<SNTag>(ContentType.TYPES.Tag, ({ changed, inserted, source }) => {
if (noteAndTagSources.includes(source)) {
void this.handleChangedTags([...changed, ...inserted])
}
@@ -266,7 +269,7 @@ export class FilesBackupService extends AbstractService implements BackupService
this.storage.setValue(StorageKey.PlaintextBackupsEnabled, true)
this.storage.setValue(StorageKey.PlaintextBackupsLocation, location)
void this.handleChangedNotes(this.items.getItems<SNNote>(ContentType.Note))
void this.handleChangedNotes(this.items.getItems<SNNote>(ContentType.TYPES.Note))
}
disablePlaintextBackups(): void {
@@ -319,7 +322,7 @@ export class FilesBackupService extends AbstractService implements BackupService
}
private backupAllFiles(): void {
const files = this.items.getItems<FileItem>(ContentType.File)
const files = this.items.getItems<FileItem>(ContentType.TYPES.File)
void this.handleChangedFiles(files)
}
@@ -453,7 +456,7 @@ export class FilesBackupService extends AbstractService implements BackupService
}
for (const tag of tags) {
const notes = this.items.referencesForItem<SNNote>(tag, ContentType.Note)
const notes = this.items.referencesForItem<SNNote>(tag, ContentType.TYPES.Note)
await this.handleChangedNotes(notes)
}
}

View File

@@ -15,7 +15,6 @@ import {
TrustedContactMutator,
DecryptedItemInterface,
} from '@standardnotes/models'
import { ContentType } from '@standardnotes/common'
import { AbstractService } from '../Service/AbstractService'
import { SyncServiceInterface } from '../Sync/SyncServiceInterface'
import { ItemManagerInterface } from '../Item/ItemManagerInterface'
@@ -31,6 +30,7 @@ import { FindTrustedContactUseCase } from './UseCase/FindTrustedContact'
import { SelfContactManager } from './Managers/SelfContactManager'
import { CreateOrEditTrustedContactUseCase } from './UseCase/CreateOrEditTrustedContact'
import { UpdateTrustedContactUseCase } from './UseCase/UpdateTrustedContact'
import { ContentType } from '@standardnotes/domain-core'
export class ContactService
extends AbstractService<ContactServiceEvent>
@@ -191,7 +191,7 @@ export class ContactService
})
} else {
contact = await this.mutator.createItem<TrustedContactInterface>(
ContentType.TrustedContact,
ContentType.TYPES.TrustedContact,
FillItemContent<TrustedContactContent>(data),
true,
)
@@ -224,7 +224,7 @@ export class ContactService
}
getAllContacts(): TrustedContactInterface[] {
return this.items.getItems(ContentType.TrustedContact)
return this.items.getItems(ContentType.TYPES.TrustedContact)
}
findTrustedContact(userUuid: string): TrustedContactInterface | undefined {

View File

@@ -15,9 +15,9 @@ import {
TrustedContactContentSpecialized,
TrustedContactInterface,
} from '@standardnotes/models'
import { ContentType } from '@standardnotes/common'
import { CreateOrEditTrustedContactUseCase } from '../UseCase/CreateOrEditTrustedContact'
import { PublicKeySet } from '@standardnotes/encryption'
import { ContentType } from '@standardnotes/domain-core'
export class SelfContactManager {
public selfContact?: TrustedContactInterface
@@ -57,7 +57,7 @@ export class SelfContactManager {
}
this.selfContact = this.singletons.findSingleton<TrustedContactInterface>(
ContentType.TrustedContact,
ContentType.TYPES.TrustedContact,
TrustedContact.singletonPredicate,
)
}
@@ -117,7 +117,7 @@ export class SelfContactManager {
this.selfContact = await this.singletons.findOrCreateSingleton<TrustedContactContent, TrustedContact>(
TrustedContact.singletonPredicate,
ContentType.TrustedContact,
ContentType.TYPES.TrustedContact,
FillItemContent<TrustedContactContent>(content),
)

View File

@@ -10,8 +10,8 @@ import {
} from '@standardnotes/models'
import { FindTrustedContactUseCase } from './FindTrustedContact'
import { UnknownContactName } from '../UnknownContactName'
import { ContentType } from '@standardnotes/common'
import { UpdateTrustedContactUseCase } from './UpdateTrustedContact'
import { ContentType } from '@standardnotes/domain-core'
export class CreateOrEditTrustedContactUseCase {
constructor(
@@ -49,7 +49,7 @@ export class CreateOrEditTrustedContactUseCase {
}
const contact = await this.mutator.createItem<TrustedContactInterface>(
ContentType.TrustedContact,
ContentType.TYPES.TrustedContact,
FillItemContent<TrustedContactContent>(content),
true,
)

View File

@@ -1,7 +1,7 @@
import { Predicate, TrustedContactInterface } from '@standardnotes/models'
import { ItemManagerInterface } from './../../Item/ItemManagerInterface'
import { ContentType } from '@standardnotes/common'
import { FindContactQuery } from './FindContactQuery'
import { ContentType } from '@standardnotes/domain-core'
export class FindTrustedContactUseCase {
constructor(private items: ItemManagerInterface) {}
@@ -9,18 +9,18 @@ export class FindTrustedContactUseCase {
execute(query: FindContactQuery): TrustedContactInterface | undefined {
if ('userUuid' in query && query.userUuid) {
return this.items.itemsMatchingPredicate<TrustedContactInterface>(
ContentType.TrustedContact,
ContentType.TYPES.TrustedContact,
new Predicate<TrustedContactInterface>('contactUuid', '=', query.userUuid),
)[0]
}
if ('signingPublicKey' in query && query.signingPublicKey) {
const allContacts = this.items.getItems<TrustedContactInterface>(ContentType.TrustedContact)
const allContacts = this.items.getItems<TrustedContactInterface>(ContentType.TYPES.TrustedContact)
return allContacts.find((contact) => contact.isSigningKeyTrusted(query.signingPublicKey))
}
if ('publicKey' in query && query.publicKey) {
const allContacts = this.items.getItems<TrustedContactInterface>(ContentType.TrustedContact)
const allContacts = this.items.getItems<TrustedContactInterface>(ContentType.TYPES.TrustedContact)
return allContacts.find((contact) => contact.isPublicKeyTrusted(query.publicKey))
}

View File

@@ -1,4 +1,3 @@
import { ContentType } from '@standardnotes/common'
import { FullyFormedTransferPayload } from '@standardnotes/models'
export type DatabaseKeysLoadChunk = {
@@ -42,7 +41,7 @@ export function isFullEntryLoadChunkResponse(
}
export type DatabaseLoadOptions = {
contentTypePriority: ContentType[]
contentTypePriority: string[]
uuidPriority: string[]
batchSize: number
}

View File

@@ -1,28 +1,28 @@
import { ContentType } from '@standardnotes/common'
import { ContentType } from '@standardnotes/domain-core'
import { FullyFormedPayloadInterface } from '@standardnotes/models'
import { GetSortedPayloadsByPriority } from './DatabaseLoadSorter'
describe('GetSortedPayloadsByPriority', () => {
let payloads: FullyFormedPayloadInterface[] = []
const contentTypePriority = [ContentType.ItemsKey, ContentType.UserPrefs, ContentType.Component, ContentType.Theme]
const contentTypePriority = [ContentType.TYPES.ItemsKey, ContentType.TYPES.UserPrefs, ContentType.TYPES.Component, ContentType.TYPES.Theme]
let launchPriorityUuids: string[] = []
it('should sort payloads based on content type priority', () => {
payloads = [
{
content_type: ContentType.Theme,
content_type: ContentType.TYPES.Theme,
} as FullyFormedPayloadInterface,
{
content_type: ContentType.UserPrefs,
content_type: ContentType.TYPES.UserPrefs,
} as FullyFormedPayloadInterface,
{
content_type: ContentType.Component,
content_type: ContentType.TYPES.Component,
} as FullyFormedPayloadInterface,
{
content_type: ContentType.ItemsKey,
content_type: ContentType.TYPES.ItemsKey,
} as FullyFormedPayloadInterface,
{
content_type: ContentType.Note,
content_type: ContentType.TYPES.Note,
} as FullyFormedPayloadInterface,
]
@@ -33,15 +33,15 @@ describe('GetSortedPayloadsByPriority', () => {
})
expect(itemsKeyPayloads.length).toBe(1)
expect(itemsKeyPayloads[0].content_type).toBe(ContentType.ItemsKey)
expect(itemsKeyPayloads[0].content_type).toBe(ContentType.TYPES.ItemsKey)
expect(contentTypePriorityPayloads.length).toBe(3)
expect(contentTypePriorityPayloads[0].content_type).toBe(ContentType.UserPrefs)
expect(contentTypePriorityPayloads[1].content_type).toBe(ContentType.Component)
expect(contentTypePriorityPayloads[2].content_type).toBe(ContentType.Theme)
expect(contentTypePriorityPayloads[0].content_type).toBe(ContentType.TYPES.UserPrefs)
expect(contentTypePriorityPayloads[1].content_type).toBe(ContentType.TYPES.Component)
expect(contentTypePriorityPayloads[2].content_type).toBe(ContentType.TYPES.Theme)
expect(remainingPayloads.length).toBe(1)
expect(remainingPayloads[0].content_type).toBe(ContentType.Note)
expect(remainingPayloads[0].content_type).toBe(ContentType.TYPES.Note)
})
it('should sort payloads based on launch priority uuids', () => {
@@ -53,31 +53,31 @@ describe('GetSortedPayloadsByPriority', () => {
payloads = [
{
content_type: ContentType.Theme,
content_type: ContentType.TYPES.Theme,
} as FullyFormedPayloadInterface,
{
content_type: ContentType.UserPrefs,
content_type: ContentType.TYPES.UserPrefs,
} as FullyFormedPayloadInterface,
{
content_type: ContentType.Component,
content_type: ContentType.TYPES.Component,
} as FullyFormedPayloadInterface,
{
content_type: ContentType.ItemsKey,
content_type: ContentType.TYPES.ItemsKey,
} as FullyFormedPayloadInterface,
{
content_type: ContentType.Note,
content_type: ContentType.TYPES.Note,
uuid: unprioritizedNoteUuid,
} as FullyFormedPayloadInterface,
{
content_type: ContentType.Tag,
content_type: ContentType.TYPES.Tag,
uuid: unprioritizedTagUuid,
} as FullyFormedPayloadInterface,
{
content_type: ContentType.Note,
content_type: ContentType.TYPES.Note,
uuid: prioritizedNoteUuid,
} as FullyFormedPayloadInterface,
{
content_type: ContentType.Tag,
content_type: ContentType.TYPES.Tag,
uuid: prioritizedTagUuid,
} as FullyFormedPayloadInterface,
]
@@ -91,12 +91,12 @@ describe('GetSortedPayloadsByPriority', () => {
})
expect(itemsKeyPayloads.length).toBe(1)
expect(itemsKeyPayloads[0].content_type).toBe(ContentType.ItemsKey)
expect(itemsKeyPayloads[0].content_type).toBe(ContentType.TYPES.ItemsKey)
expect(contentTypePriorityPayloads.length).toBe(3)
expect(contentTypePriorityPayloads[0].content_type).toBe(ContentType.UserPrefs)
expect(contentTypePriorityPayloads[1].content_type).toBe(ContentType.Component)
expect(contentTypePriorityPayloads[2].content_type).toBe(ContentType.Theme)
expect(contentTypePriorityPayloads[0].content_type).toBe(ContentType.TYPES.UserPrefs)
expect(contentTypePriorityPayloads[1].content_type).toBe(ContentType.TYPES.Component)
expect(contentTypePriorityPayloads[2].content_type).toBe(ContentType.TYPES.Theme)
expect(remainingPayloads.length).toBe(4)
expect(remainingPayloads[0].uuid).toBe(prioritizedNoteUuid)
@@ -114,21 +114,21 @@ describe('GetSortedPayloadsByPriority', () => {
payloads = [
{
content_type: ContentType.Note,
content_type: ContentType.TYPES.Note,
uuid: unprioritizedNoteUuid,
updated_at: new Date(1),
} as FullyFormedPayloadInterface,
{
content_type: ContentType.Tag,
content_type: ContentType.TYPES.Tag,
uuid: unprioritizedTagUuid,
updated_at: new Date(2),
} as FullyFormedPayloadInterface,
{
content_type: ContentType.Note,
content_type: ContentType.TYPES.Note,
uuid: prioritizedNoteUuid,
} as FullyFormedPayloadInterface,
{
content_type: ContentType.Tag,
content_type: ContentType.TYPES.Tag,
uuid: prioritizedTagUuid,
} as FullyFormedPayloadInterface,
]

View File

@@ -1,6 +1,7 @@
import { ContentType } from '@standardnotes/domain-core'
import { DatabaseItemMetadata } from './DatabaseItemMetadata'
import { DatabaseLoadOptions } from './DatabaseLoadOptions'
import { ContentType } from '@standardnotes/common'
/**
* Sorts payloads according by most recently modified first, according to the priority,
@@ -9,7 +10,7 @@ import { ContentType } from '@standardnotes/common'
*/
function SortPayloadsByRecentAndContentPriority<T extends DatabaseItemMetadata = DatabaseItemMetadata>(
payloads: T[],
contentTypePriorityList: ContentType[],
contentTypePriorityList: string[],
): T[] {
return payloads.sort((a, b) => {
const dateResult = new Date(b.updated_at).getTime() - new Date(a.updated_at).getTime()
@@ -97,11 +98,11 @@ export function GetSortedPayloadsByPriority<T extends DatabaseItemMetadata = Dat
for (let index = 0; index < payloads.length; index++) {
const payload = payloads[index]
if (payload.content_type === ContentType.KeySystemRootKey) {
if (payload.content_type === ContentType.TYPES.KeySystemRootKey) {
keySystemRootKeyPayloads.push(payload)
} else if (payload.content_type === ContentType.KeySystemItemsKey) {
} else if (payload.content_type === ContentType.TYPES.KeySystemItemsKey) {
keySystemItemsKeyPayloads.push(payload)
} else if (payload.content_type === ContentType.ItemsKey) {
} else if (payload.content_type === ContentType.TYPES.ItemsKey) {
itemsKeyPayloads.push(payload)
} else if (options.contentTypePriority.includes(payload.content_type)) {
contentTypePriorityPayloads.push(payload)

View File

@@ -1,7 +1,6 @@
import {
AnyKeyParamsContent,
compareVersions,
ContentType,
leftVersionGreaterThanOrEqualToRight,
ProtocolVersion,
} from '@standardnotes/common'
@@ -39,6 +38,7 @@ import {
import { ClientDisplayableError } from '@standardnotes/responses'
import { extendArray } from '@standardnotes/utils'
import { EncryptionService } from './EncryptionService'
import { ContentType } from '@standardnotes/domain-core'
export class DecryptBackupFileUseCase {
constructor(private encryption: EncryptionService) {}
@@ -95,7 +95,7 @@ export class DecryptBackupFileUseCase {
} else {
const hasEncryptedItem = payloads.find(isEncryptedPayload)
const hasDecryptedItemsKey = payloads.find(
(payload) => payload.content_type === ContentType.ItemsKey && isDecryptedPayload(payload),
(payload) => payload.content_type === ContentType.TYPES.ItemsKey && isDecryptedPayload(payload),
)
if (hasEncryptedItem && hasDecryptedItemsKey) {
@@ -149,7 +149,7 @@ export class DecryptBackupFileUseCase {
const encryptedPayloads: EncryptedPayloadInterface[] = []
payloads.forEach((payload) => {
if (payload.content_type === ContentType.ItemsKey && isDecryptedPayload(payload)) {
if (payload.content_type === ContentType.TYPES.ItemsKey && isDecryptedPayload(payload)) {
decryptedItemsKeys.push(payload as DecryptedPayloadInterface<ItemsKeyContent>)
} else if (isEncryptedPayload(payload)) {
encryptedPayloads.push(payload)

View File

@@ -62,7 +62,6 @@ import {
AnyKeyParamsContent,
ApplicationIdentifier,
compareVersions,
ContentType,
isVersionLessThanOrEqualTo,
KeyParamsOrigination,
ProtocolVersion,
@@ -92,6 +91,7 @@ import { RootKeyEncryptPayloadWithKeyLookupUseCase } from './UseCase/RootEncrypt
import { RootKeyEncryptPayloadUseCase } from './UseCase/RootEncryption/EncryptPayload'
import { ValidateAccountPasswordResult } from './RootKey/ValidateAccountPasswordResult'
import { ValidatePasscodeResult } from './RootKey/ValidatePasscodeResult'
import { ContentType } from '@standardnotes/domain-core'
/**
* The encryption service is responsible for the encryption and decryption of payloads, and
@@ -746,7 +746,7 @@ export class EncryptionService
}
public createDecryptedBackupFile(): BackupFile {
const payloads = this.payloads.nonDeletedItems.filter((item) => item.content_type !== ContentType.ItemsKey)
const payloads = this.payloads.nonDeletedItems.filter((item) => item.content_type !== ContentType.TYPES.ItemsKey)
const data: BackupFile = {
version: ProtocolVersionLatest,

View File

@@ -1,4 +1,4 @@
import { ContentType, ProtocolVersion } from '@standardnotes/common'
import { ProtocolVersion } from '@standardnotes/common'
import {
DecryptedParameters,
ErrorDecryptingParameters,
@@ -32,6 +32,7 @@ import { PayloadManagerInterface } from '../Payloads/PayloadManagerInterface'
import { AbstractService } from '../Service/AbstractService'
import { StorageServiceInterface } from '../Storage/StorageServiceInterface'
import { PkcKeyPair } from '@standardnotes/sncrypto-common'
import { ContentType } from '@standardnotes/domain-core'
export class ItemsEncryptionService extends AbstractService {
private removeItemsObserver!: () => void
@@ -47,7 +48,7 @@ export class ItemsEncryptionService extends AbstractService {
) {
super(internalEventBus)
this.removeItemsObserver = this.itemManager.addObserver([ContentType.ItemsKey], ({ changed, inserted }) => {
this.removeItemsObserver = this.itemManager.addObserver([ContentType.TYPES.ItemsKey], ({ changed, inserted }) => {
if (changed.concat(inserted).length > 0) {
void this.decryptErroredItemPayloads()
}
@@ -84,7 +85,9 @@ export class ItemsEncryptionService extends AbstractService {
payload: EncryptedPayloadInterface,
): ItemsKeyInterface | KeySystemItemsKeyInterface | undefined {
const itemsKeys = this.getItemsKeys()
const keySystemItemsKeys = this.itemManager.getItems<KeySystemItemsKeyInterface>(ContentType.KeySystemItemsKey)
const keySystemItemsKeys = this.itemManager.getItems<KeySystemItemsKeyInterface>(
ContentType.TYPES.KeySystemItemsKey,
)
return [...itemsKeys, ...keySystemItemsKeys].find(
(key) => key.uuid === payload.items_key_id || key.duplicateOf === payload.items_key_id,

View File

@@ -1,10 +1,5 @@
import { OperatorManager } from '@standardnotes/encryption'
import {
ContentType,
ProtocolVersionLastNonrootItemsKey,
ProtocolVersionLatest,
compareVersions,
} from '@standardnotes/common'
import { ProtocolVersionLastNonrootItemsKey, ProtocolVersionLatest, compareVersions } from '@standardnotes/common'
import {
CreateDecryptedItemFromPayload,
DecryptedPayload,
@@ -18,6 +13,7 @@ import { UuidGenerator } from '@standardnotes/utils'
import { MutatorClientInterface } from '../../../Mutator/MutatorClientInterface'
import { ItemManagerInterface } from '../../../Item/ItemManagerInterface'
import { RootKeyManager } from '../../RootKey/RootKeyManager'
import { ContentType } from '@standardnotes/domain-core'
/**
* Creates a new random items key to use for item encryption, and adds it to model management.
@@ -41,7 +37,7 @@ export class CreateNewDefaultItemsKeyUseCase {
/** Create root key based items key */
const payload = new DecryptedPayload<ItemsKeyContent>({
uuid: UuidGenerator.GenerateUuid(),
content_type: ContentType.ItemsKey,
content_type: ContentType.TYPES.ItemsKey,
content: FillItemContentSpecialized<ItemsKeyContentSpecialized, ItemsKeyContent>({
itemsKey: rootKey.masterKey,
dataAuthenticationKey: rootKey.dataAuthenticationKey,

View File

@@ -5,7 +5,6 @@ import {
isClientDisplayableError,
isErrorResponse,
} from '@standardnotes/responses'
import { ContentType } from '@standardnotes/common'
import {
FileItem,
FileProtocolV1Constants,
@@ -54,6 +53,7 @@ import {
SharedVaultServerInterface,
HttpServiceInterface,
} from '@standardnotes/api'
import { ContentType } from '@standardnotes/domain-core'
const OneHundredMb = 100 * 1_000_000
@@ -268,7 +268,7 @@ export class FileService extends AbstractService implements FilesClientInterface
}
const file = await this.mutator.createItem<FileItem>(
ContentType.File,
ContentType.TYPES.File,
FillItemContentSpecialized(fileContent),
true,
operation.vault,

View File

@@ -1,4 +1,3 @@
import { ContentType } from '@standardnotes/common'
import {
ItemsKeyInterface,
DecryptedItemInterface,
@@ -54,13 +53,13 @@ export interface ItemManagerInterface extends AbstractService {
getCollection(): ItemCollection
addObserver<I extends DecryptedItemInterface = DecryptedItemInterface>(
contentType: ContentType | ContentType[],
contentType: string | string[],
callback: ItemManagerChangeObserverCallback<I>,
): () => void
get items(): DecryptedItemInterface[]
getItems<T extends DecryptedItemInterface>(contentType: ContentType | ContentType[]): T[]
getItems<T extends DecryptedItemInterface>(contentType: string | string[]): T[]
get invalidItems(): EncryptedItemInterface[]
allTrackedItems(): ItemInterface[]
getDisplayableItemsKeys(): ItemsKeyInterface[]
@@ -69,17 +68,14 @@ export interface ItemManagerInterface extends AbstractService {
C extends ItemContent = ItemContent,
I extends DecryptedItemInterface<C> = DecryptedItemInterface<C>,
>(
contentType: ContentType,
contentType: string,
content?: C,
override?: Partial<DecryptedPayload<C>>,
): I
itemsMatchingPredicate<T extends DecryptedItemInterface>(
contentType: ContentType,
predicate: PredicateInterface<T>,
): T[]
itemsMatchingPredicate<T extends DecryptedItemInterface>(contentType: string, predicate: PredicateInterface<T>): T[]
itemsMatchingPredicates<T extends DecryptedItemInterface>(
contentType: ContentType,
contentType: string,
predicates: PredicateInterface<T>[],
): T[]
subItemsMatchingPredicates<T extends DecryptedItemInterface>(items: T[], predicates: PredicateInterface<T>[]): T[]
@@ -90,11 +86,11 @@ export interface ItemManagerInterface extends AbstractService {
getSortedTagsForItem(item: DecryptedItemInterface<ItemContent>): SNTag[]
itemsReferencingItem<I extends DecryptedItemInterface = DecryptedItemInterface>(
itemToLookupUuidFor: { uuid: string },
contentType?: ContentType,
contentType?: string,
): I[]
referencesForItem<I extends DecryptedItemInterface = DecryptedItemInterface>(
itemToLookupUuidFor: DecryptedItemInterface,
contentType?: ContentType,
contentType?: string,
): I[]
findItem<T extends DecryptedItemInterface = DecryptedItemInterface>(uuid: string): T | undefined
findItems<T extends DecryptedItemInterface>(uuids: string[]): T[]

View File

@@ -1,4 +1,4 @@
import { ContentType } from '@standardnotes/common'
import { ContentType } from '@standardnotes/domain-core'
import { SNNote, SNTag } from '@standardnotes/models'
import { StaticItemCounter } from './StaticItemCounter'
@@ -18,10 +18,10 @@ describe('ItemCounter', () => {
trashed: true,
} as jest.Mocked<SNNote>,
{
content_type: ContentType.Note,
content_type: ContentType.TYPES.Note,
} as jest.Mocked<SNNote>,
{
content_type: ContentType.Tag,
content_type: ContentType.TYPES.Tag,
} as jest.Mocked<SNTag>,
]

View File

@@ -1,4 +1,4 @@
import { ContentType } from '@standardnotes/common'
import { ContentType } from '@standardnotes/domain-core'
import { SNNote, SNTag, ItemCounts } from '@standardnotes/models'
export class StaticItemCounter {
@@ -21,12 +21,12 @@ export class StaticItemCounter {
continue
}
if (item.content_type === ContentType.Note && !item.conflictOf) {
if (item.content_type === ContentType.TYPES.Note && !item.conflictOf) {
counts.notes++
continue
}
if (item.content_type === ContentType.Tag) {
if (item.content_type === ContentType.TYPES.Tag) {
counts.tags++
continue

View File

@@ -16,9 +16,9 @@ import {
VaultListingInterface,
} from '@standardnotes/models'
import { ItemManagerInterface } from './../Item/ItemManagerInterface'
import { ContentType } from '@standardnotes/common'
import { KeySystemKeyManagerInterface } from '@standardnotes/encryption'
import { AbstractService } from '../Service/AbstractService'
import { ContentType } from '@standardnotes/domain-core'
const RootKeyStorageKeyPrefix = 'key-system-root-key-'
@@ -76,7 +76,7 @@ export class KeySystemKeyManager extends AbstractService implements KeySystemKey
}
public getAllSyncedKeySystemRootKeys(): KeySystemRootKeyInterface[] {
return this.items.getItems(ContentType.KeySystemRootKey)
return this.items.getItems(ContentType.TYPES.KeySystemRootKey)
}
public clearMemoryOfKeysRelatedToVault(vault: VaultListingInterface): void {
@@ -88,7 +88,7 @@ export class KeySystemKeyManager extends AbstractService implements KeySystemKey
public getSyncedKeySystemRootKeysForVault(systemIdentifier: KeySystemIdentifier): KeySystemRootKeyInterface[] {
return this.items.itemsMatchingPredicate<KeySystemRootKeyInterface>(
ContentType.KeySystemRootKey,
ContentType.TYPES.KeySystemRootKey,
new Predicate<KeySystemRootKeyInterface>('systemIdentifier', '=', systemIdentifier),
)
}
@@ -131,14 +131,16 @@ export class KeySystemKeyManager extends AbstractService implements KeySystemKey
}
public getAllKeySystemItemsKeys(): (KeySystemItemsKeyInterface | EncryptedItemInterface)[] {
const decryptedItems = this.items.getItems<KeySystemItemsKeyInterface>(ContentType.KeySystemItemsKey)
const encryptedItems = this.items.invalidItems.filter((item) => item.content_type === ContentType.KeySystemItemsKey)
const decryptedItems = this.items.getItems<KeySystemItemsKeyInterface>(ContentType.TYPES.KeySystemItemsKey)
const encryptedItems = this.items.invalidItems.filter(
(item) => item.content_type === ContentType.TYPES.KeySystemItemsKey,
)
return [...decryptedItems, ...encryptedItems]
}
public getKeySystemItemsKeys(systemIdentifier: KeySystemIdentifier): KeySystemItemsKeyInterface[] {
return this.items
.getItems<KeySystemItemsKeyInterface>(ContentType.KeySystemItemsKey)
.getItems<KeySystemItemsKeyInterface>(ContentType.TYPES.KeySystemItemsKey)
.filter((key) => key.key_system_identifier === systemIdentifier)
}

View File

@@ -4,7 +4,7 @@ import { PayloadManagerInterface } from '../Payloads/PayloadManagerInterface'
import { ProtectionsClientInterface } from '../Protection/ProtectionClientInterface'
import { SyncServiceInterface } from '../Sync/SyncServiceInterface'
import { ItemManagerInterface } from '../Item/ItemManagerInterface'
import { ContentType, ProtocolVersion, compareVersions } from '@standardnotes/common'
import { ProtocolVersion, compareVersions } from '@standardnotes/common'
import {
BackupFile,
BackupFileDecryptedContextualPayload,
@@ -20,6 +20,7 @@ import {
import { ClientDisplayableError } from '@standardnotes/responses'
import { EncryptionProviderInterface } from '@standardnotes/encryption'
import { Challenge, ChallengePrompt, ChallengeReason, ChallengeValidation } from '../Challenge'
import { ContentType } from '@standardnotes/domain-core'
const Strings = {
UnsupportedBackupFileVersion:
@@ -115,7 +116,7 @@ export class ImportDataUseCase {
const validPayloads = decryptedPayloadsOrError.filter(isDecryptedPayload).map((payload) => {
/* Don't want to activate any components during import process in
* case of exceptions breaking up the import proccess */
if (payload.content_type === ContentType.Component && (payload.content as ComponentContent).active) {
if (payload.content_type === ContentType.TYPES.Component && (payload.content as ComponentContent).active) {
const typedContent = payload as DecryptedPayloadInterface<ComponentContent>
return CopyPayloadWithContentOverride(typedContent, {
active: false,

View File

@@ -1,4 +1,3 @@
import { ContentType } from '@standardnotes/common'
import {
ComponentMutator,
DecryptedItemInterface,
@@ -37,7 +36,7 @@ export interface MutatorClientInterface {
isUserModified?: boolean,
): Promise<DecryptedItemInterface[]>
createItem<T extends DecryptedItemInterface, C extends ItemContent = ItemContent>(
contentType: ContentType,
contentType: string,
content: C,
needsSync?: boolean,
vault?: VaultListingInterface,

View File

@@ -33,7 +33,6 @@ import {
import { SharedVaultServiceInterface } from './SharedVaultServiceInterface'
import { SharedVaultServiceEvent, SharedVaultServiceEventPayload } from './SharedVaultServiceEvent'
import { EncryptionProviderInterface } from '@standardnotes/encryption'
import { ContentType } from '@standardnotes/common'
import { GetSharedVaultUsersUseCase } from './UseCase/GetSharedVaultUsers'
import { RemoveVaultMemberUseCase } from './UseCase/RemoveSharedVaultMember'
import { AbstractService } from '../Service/AbstractService'
@@ -64,6 +63,7 @@ import { CreateSharedVaultUseCase } from './UseCase/CreateSharedVault'
import { SendSharedVaultMetadataChangedMessageToAll } from './UseCase/SendSharedVaultMetadataChangedMessageToAll'
import { ConvertToSharedVaultUseCase } from './UseCase/ConvertToSharedVault'
import { GetVaultUseCase } from '../Vaults/UseCase/GetVault'
import { ContentType } from '@standardnotes/domain-core'
export class SharedVaultService
extends AbstractService<SharedVaultServiceEvent, SharedVaultServiceEventPayload>
@@ -111,20 +111,23 @@ export class SharedVaultService
)
this.eventDisposers.push(
items.addObserver<TrustedContactInterface>(ContentType.TrustedContact, async ({ changed, inserted, source }) => {
await this.reprocessCachedInvitesTrustStatusAfterTrustedContactsChange()
items.addObserver<TrustedContactInterface>(
ContentType.TYPES.TrustedContact,
async ({ changed, inserted, source }) => {
await this.reprocessCachedInvitesTrustStatusAfterTrustedContactsChange()
if (source === PayloadEmitSource.LocalChanged && inserted.length > 0) {
void this.handleCreationOfNewTrustedContacts(inserted)
}
if (source === PayloadEmitSource.LocalChanged && changed.length > 0) {
void this.handleTrustedContactsChange(changed)
}
}),
if (source === PayloadEmitSource.LocalChanged && inserted.length > 0) {
void this.handleCreationOfNewTrustedContacts(inserted)
}
if (source === PayloadEmitSource.LocalChanged && changed.length > 0) {
void this.handleTrustedContactsChange(changed)
}
},
),
)
this.eventDisposers.push(
items.addObserver<VaultListingInterface>(ContentType.VaultListing, ({ changed, source }) => {
items.addObserver<VaultListingInterface>(ContentType.TYPES.VaultListing, ({ changed, source }) => {
if (source === PayloadEmitSource.LocalChanged && changed.length > 0) {
void this.handleVaultListingsChange(changed)
}

View File

@@ -1,17 +1,13 @@
import { DecryptedItemInterface, ItemContent, Predicate, PredicateInterface } from '@standardnotes/models'
import { ContentType } from '@standardnotes/common'
export interface SingletonManagerInterface {
findSingleton<T extends DecryptedItemInterface>(
contentType: ContentType,
predicate: PredicateInterface<T>,
): T | undefined
findSingleton<T extends DecryptedItemInterface>(contentType: string, predicate: PredicateInterface<T>): T | undefined
findOrCreateContentTypeSingleton<
C extends ItemContent = ItemContent,
T extends DecryptedItemInterface<C> = DecryptedItemInterface<C>,
>(
contentType: ContentType,
contentType: string,
createContent: ItemContent,
): Promise<T>
@@ -20,7 +16,7 @@ export interface SingletonManagerInterface {
T extends DecryptedItemInterface<C> = DecryptedItemInterface<C>,
>(
predicate: Predicate<T>,
contentType: ContentType,
contentType: string,
createContent: ItemContent,
): Promise<T>
}

View File

@@ -10,8 +10,8 @@ import {
FillItemContentSpecialized,
KeySystemRootKeyInterface,
} from '@standardnotes/models'
import { ContentType } from '@standardnotes/common'
import { MutatorClientInterface } from '../../Mutator/MutatorClientInterface'
import { ContentType } from '@standardnotes/domain-core'
export class CreateVaultUseCase {
constructor(
@@ -70,7 +70,7 @@ export class CreateVaultUseCase {
description: dto.vaultDescription,
}
return this.mutator.createItem(ContentType.VaultListing, FillItemContentSpecialized(content), true)
return this.mutator.createItem(ContentType.TYPES.VaultListing, FillItemContentSpecialized(content), true)
}
private async createKeySystemItemsKey(keySystemIdentifier: string, rootKeyToken: string): Promise<void> {

View File

@@ -1,12 +1,12 @@
import { VaultListingInterface } from '@standardnotes/models'
import { ItemManagerInterface } from './../../Item/ItemManagerInterface'
import { ContentType } from '@standardnotes/common'
import { ContentType } from '@standardnotes/domain-core'
export class GetVaultUseCase<T extends VaultListingInterface> {
constructor(private items: ItemManagerInterface) {}
execute(query: { keySystemIdentifier: string } | { sharedVaultUuid: string }): T | undefined {
const vaults = this.items.getItems<VaultListingInterface>(ContentType.VaultListing)
const vaults = this.items.getItems<VaultListingInterface>(ContentType.TYPES.VaultListing)
if ('keySystemIdentifier' in query) {
return vaults.find((listing) => listing.systemIdentifier === query.keySystemIdentifier) as T

View File

@@ -2,7 +2,7 @@ import { MutatorClientInterface, SyncServiceInterface } from '@standardnotes/ser
import { ClientDisplayableError } from '@standardnotes/responses'
import { DecryptedItemInterface, FileItem, VaultListingInterface } from '@standardnotes/models'
import { FilesClientInterface } from '@standardnotes/files'
import { ContentType } from '@standardnotes/common'
import { ContentType } from '@standardnotes/domain-core'
export class MoveItemsToVaultUseCase {
constructor(
@@ -25,7 +25,7 @@ export class MoveItemsToVaultUseCase {
await this.sync.sync()
for (const item of dto.items) {
if (item.content_type !== ContentType.File) {
if (item.content_type !== ContentType.TYPES.File) {
continue
}

View File

@@ -1,7 +1,7 @@
import { MutatorClientInterface, SyncServiceInterface } from '@standardnotes/services'
import { ClientDisplayableError } from '@standardnotes/responses'
import { DecryptedItemInterface, FileItem } from '@standardnotes/models'
import { ContentType } from '@standardnotes/common'
import { ContentType } from '@standardnotes/domain-core'
import { FilesClientInterface } from '@standardnotes/files'
export class RemoveItemFromVault {
@@ -19,7 +19,7 @@ export class RemoveItemFromVault {
await this.sync.sync()
if (dto.item.content_type === ContentType.File) {
if (dto.item.content_type === ContentType.TYPES.File) {
await this.files.moveFileOutOfSharedVault(dto.item as FileItem)
}
}

View File

@@ -24,11 +24,11 @@ import { MoveItemsToVaultUseCase } from './UseCase/MoveItemsToVault'
import { RotateVaultRootKeyUseCase } from './UseCase/RotateVaultRootKey'
import { FilesClientInterface } from '@standardnotes/files'
import { ContentType } from '@standardnotes/common'
import { GetVaultUseCase } from './UseCase/GetVault'
import { ChangeVaultKeyOptionsUseCase } from './UseCase/ChangeVaultKeyOptions'
import { MutatorClientInterface } from '../Mutator/MutatorClientInterface'
import { AlertService } from '../Alert/AlertService'
import { ContentType } from '@standardnotes/domain-core'
export class VaultService
extends AbstractService<VaultServiceEvent, VaultServiceEventPayload[VaultServiceEvent]>
@@ -47,13 +47,16 @@ export class VaultService
) {
super(eventBus)
items.addObserver([ContentType.KeySystemItemsKey, ContentType.KeySystemRootKey, ContentType.VaultListing], () => {
void this.recomputeAllVaultsLockingState()
})
items.addObserver(
[ContentType.TYPES.KeySystemItemsKey, ContentType.TYPES.KeySystemRootKey, ContentType.TYPES.VaultListing],
() => {
void this.recomputeAllVaultsLockingState()
},
)
}
getVaults(): VaultListingInterface[] {
return this.items.getItems<VaultListingInterface>(ContentType.VaultListing).sort((a, b) => {
return this.items.getItems<VaultListingInterface>(ContentType.TYPES.VaultListing).sort((a, b) => {
return a.name.localeCompare(b.name)
})
}