refactor(web): dependency management (#2386)
This commit is contained in:
@@ -1,24 +1,27 @@
|
||||
import { VaultUserServiceInterface, VaultInviteServiceInterface } from '@standardnotes/services'
|
||||
import {
|
||||
VaultUserServiceInterface,
|
||||
VaultInviteServiceInterface,
|
||||
StorageServiceInterface,
|
||||
SyncServiceInterface,
|
||||
FullyResolvedApplicationOptions,
|
||||
ProtectionsClientInterface,
|
||||
ChangeAndSaveItem,
|
||||
GetHost,
|
||||
SetHost,
|
||||
LegacyApiServiceInterface,
|
||||
StatusServiceInterface,
|
||||
MfaServiceInterface,
|
||||
} from '@standardnotes/services'
|
||||
import { VaultLockServiceInterface } from './../VaultLock/VaultLockServiceInterface'
|
||||
import { HistoryServiceInterface } from './../History/HistoryServiceInterface'
|
||||
import { InternalEventBusInterface } from './../Internal/InternalEventBusInterface'
|
||||
import { PreferenceServiceInterface } from './../Preferences/PreferenceServiceInterface'
|
||||
import { AsymmetricMessageServiceInterface } from './../AsymmetricMessage/AsymmetricMessageServiceInterface'
|
||||
import { SyncOptions } from './../Sync/SyncOptions'
|
||||
import { ImportDataReturnType } from './../Mutator/ImportDataUseCase'
|
||||
import { ChallengeServiceInterface } from './../Challenge/ChallengeServiceInterface'
|
||||
import { VaultServiceInterface } from '../Vault/VaultServiceInterface'
|
||||
import { ApplicationIdentifier } from '@standardnotes/common'
|
||||
import {
|
||||
BackupFile,
|
||||
DecryptedItemInterface,
|
||||
DecryptedItemMutator,
|
||||
ItemStream,
|
||||
PayloadEmitSource,
|
||||
Platform,
|
||||
PrefKey,
|
||||
PrefValue,
|
||||
} from '@standardnotes/models'
|
||||
import { BackupFile, Environment, Platform, PrefKey, PrefValue } from '@standardnotes/models'
|
||||
import { BackupServiceInterface, FilesClientInterface } from '@standardnotes/files'
|
||||
|
||||
import { AlertService } from '../Alert/AlertService'
|
||||
@@ -37,7 +40,6 @@ import { DeinitSource } from './DeinitSource'
|
||||
import { UserServiceInterface } from '../User/UserServiceInterface'
|
||||
import { SessionsClientInterface } from '../Session/SessionsClientInterface'
|
||||
import { HomeServerServiceInterface } from '../HomeServer/HomeServerServiceInterface'
|
||||
import { User } from '@standardnotes/responses'
|
||||
import { EncryptionProviderInterface } from '../Encryption/EncryptionProviderInterface'
|
||||
|
||||
export interface ApplicationInterface {
|
||||
@@ -53,49 +55,24 @@ export interface ApplicationInterface {
|
||||
createDecryptedBackupFile(): Promise<BackupFile | undefined>
|
||||
hasPasscode(): boolean
|
||||
lock(): Promise<void>
|
||||
softLockBiometrics(): void
|
||||
setValue(key: string, value: unknown, mode?: StorageValueModes): void
|
||||
getValue<T>(key: string, mode?: StorageValueModes): T
|
||||
removeValue(key: string, mode?: StorageValueModes): Promise<void>
|
||||
isLocked(): Promise<boolean>
|
||||
getPreference<K extends PrefKey>(key: K): PrefValue[K] | undefined
|
||||
getPreference<K extends PrefKey>(key: K, defaultValue: PrefValue[K]): PrefValue[K]
|
||||
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: string | string[],
|
||||
stream: ItemStream<I>,
|
||||
): () => void
|
||||
|
||||
getUser(): User | undefined
|
||||
hasAccount(): boolean
|
||||
setCustomHost(host: string): Promise<void>
|
||||
isThirdPartyHostUsed(): boolean
|
||||
isUsingHomeServer(): Promise<boolean>
|
||||
getNewSubscriptionToken(): Promise<string | undefined>
|
||||
|
||||
importData(data: BackupFile, awaitSync?: boolean): Promise<ImportDataReturnType>
|
||||
/**
|
||||
* Mutates a pre-existing item, marks it as dirty, and syncs it
|
||||
*/
|
||||
changeAndSaveItem<M extends DecryptedItemMutator = DecryptedItemMutator>(
|
||||
itemToLookupUuidFor: DecryptedItemInterface,
|
||||
mutate: (mutator: M) => void,
|
||||
updateTimestamps?: boolean,
|
||||
emitSource?: PayloadEmitSource,
|
||||
syncOptions?: SyncOptions,
|
||||
): Promise<DecryptedItemInterface | undefined>
|
||||
|
||||
/**
|
||||
* Mutates pre-existing items, marks them as dirty, and syncs
|
||||
*/
|
||||
changeAndSaveItems<M extends DecryptedItemMutator = DecryptedItemMutator>(
|
||||
itemsToLookupUuidsFor: DecryptedItemInterface[],
|
||||
mutate: (mutator: M) => void,
|
||||
updateTimestamps?: boolean,
|
||||
emitSource?: PayloadEmitSource,
|
||||
syncOptions?: SyncOptions,
|
||||
): Promise<void>
|
||||
get changeAndSaveItem(): ChangeAndSaveItem
|
||||
get getHost(): GetHost
|
||||
get setHost(): SetHost
|
||||
|
||||
get alerts(): AlertService
|
||||
get asymmetric(): AsymmetricMessageServiceInterface
|
||||
@@ -109,16 +86,24 @@ export interface ApplicationInterface {
|
||||
get history(): HistoryServiceInterface
|
||||
get homeServer(): HomeServerServiceInterface | undefined
|
||||
get items(): ItemManagerInterface
|
||||
get legacyApi(): LegacyApiServiceInterface
|
||||
get mfa(): MfaServiceInterface
|
||||
get mutator(): MutatorClientInterface
|
||||
get preferences(): PreferenceServiceInterface
|
||||
get protections(): ProtectionsClientInterface
|
||||
get sessions(): SessionsClientInterface
|
||||
get status(): StatusServiceInterface
|
||||
get storage(): StorageServiceInterface
|
||||
get subscriptions(): SubscriptionManagerInterface
|
||||
get sync(): SyncServiceInterface
|
||||
get user(): UserServiceInterface
|
||||
get vaults(): VaultServiceInterface
|
||||
get vaultLocks(): VaultLockServiceInterface
|
||||
get vaultUsers(): VaultUserServiceInterface
|
||||
get vaultInvites(): VaultInviteServiceInterface
|
||||
get vaultLocks(): VaultLockServiceInterface
|
||||
get vaults(): VaultServiceInterface
|
||||
get vaultUsers(): VaultUserServiceInterface
|
||||
|
||||
readonly options: FullyResolvedApplicationOptions
|
||||
readonly environment: Environment
|
||||
readonly identifier: ApplicationIdentifier
|
||||
readonly platform: Platform
|
||||
device: DeviceInterface
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
import { ApplicationOptionsWhichHaveDefaults } from './Defaults'
|
||||
import {
|
||||
ApplicationDisplayOptions,
|
||||
ApplicationOptionalConfiguratioOptions,
|
||||
ApplicationSyncOptions,
|
||||
} from './OptionalOptions'
|
||||
import { RequiredApplicationOptions } from './RequiredOptions'
|
||||
|
||||
export type ApplicationConstructorOptions = RequiredApplicationOptions &
|
||||
Partial<ApplicationSyncOptions & ApplicationDisplayOptions & ApplicationOptionalConfiguratioOptions>
|
||||
|
||||
export type FullyResolvedApplicationOptions = RequiredApplicationOptions &
|
||||
ApplicationSyncOptions &
|
||||
ApplicationDisplayOptions &
|
||||
ApplicationOptionalConfiguratioOptions &
|
||||
ApplicationOptionsWhichHaveDefaults
|
||||
15
packages/services/src/Domain/Application/Options/Defaults.ts
Normal file
15
packages/services/src/Domain/Application/Options/Defaults.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { ApplicationDisplayOptions, ApplicationSyncOptions } from './OptionalOptions'
|
||||
|
||||
export interface ApplicationOptionsWhichHaveDefaults {
|
||||
loadBatchSize: ApplicationSyncOptions['loadBatchSize']
|
||||
sleepBetweenBatches: ApplicationSyncOptions['sleepBetweenBatches']
|
||||
allowNoteSelectionStatePersistence: ApplicationDisplayOptions['allowNoteSelectionStatePersistence']
|
||||
allowMultipleSelection: ApplicationDisplayOptions['allowMultipleSelection']
|
||||
}
|
||||
|
||||
export const ApplicationOptionsDefaults: ApplicationOptionsWhichHaveDefaults = {
|
||||
loadBatchSize: 700,
|
||||
sleepBetweenBatches: 10,
|
||||
allowMultipleSelection: true,
|
||||
allowNoteSelectionStatePersistence: true,
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
export interface ApplicationSyncOptions {
|
||||
/**
|
||||
* The size of the item batch to decrypt and render upon application load.
|
||||
*/
|
||||
loadBatchSize: number
|
||||
|
||||
sleepBetweenBatches: number
|
||||
}
|
||||
|
||||
export interface ApplicationDisplayOptions {
|
||||
allowNoteSelectionStatePersistence: boolean
|
||||
allowMultipleSelection: boolean
|
||||
}
|
||||
|
||||
export interface ApplicationOptionalConfiguratioOptions {
|
||||
/**
|
||||
* URL for WebSocket providing permissions and roles information.
|
||||
*/
|
||||
webSocketUrl?: string
|
||||
|
||||
/**
|
||||
* 3rd party library function for prompting U2F authenticator device registration
|
||||
*
|
||||
* @param registrationOptions - Registration options generated by the server
|
||||
* @returns authenticator device response
|
||||
*/
|
||||
u2fAuthenticatorRegistrationPromptFunction?: (
|
||||
registrationOptions: Record<string, unknown>,
|
||||
) => Promise<Record<string, unknown>>
|
||||
|
||||
/**
|
||||
* 3rd party library function for prompting U2F authenticator device authentication
|
||||
*
|
||||
* @param registrationOptions - Registration options generated by the server
|
||||
* @returns authenticator device response
|
||||
*/
|
||||
u2fAuthenticatorVerificationPromptFunction?: (
|
||||
authenticationOptions: Record<string, unknown>,
|
||||
) => Promise<Record<string, unknown>>
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
import { Environment, Platform } from '@standardnotes/models'
|
||||
import { ApplicationIdentifier } from '@standardnotes/common'
|
||||
import { AlertService, DeviceInterface } from '@standardnotes/services'
|
||||
import { PureCryptoInterface } from '@standardnotes/sncrypto-common'
|
||||
|
||||
export interface RequiredApplicationOptions {
|
||||
/**
|
||||
* The Environment that identifies your application.
|
||||
*/
|
||||
environment: Environment
|
||||
/**
|
||||
* The Platform that identifies your application.
|
||||
*/
|
||||
platform: Platform
|
||||
/**
|
||||
* The device interface that provides platform specific
|
||||
* utilities that are used to read/write raw values from/to the database or value storage.
|
||||
*/
|
||||
deviceInterface: DeviceInterface
|
||||
/**
|
||||
* The platform-dependent implementation of SNPureCrypto to use.
|
||||
* Web uses SNWebCrypto, mobile uses SNReactNativeCrypto.
|
||||
*/
|
||||
crypto: PureCryptoInterface
|
||||
/**
|
||||
* The platform-dependent implementation of alert service.
|
||||
*/
|
||||
alertService: AlertService
|
||||
/**
|
||||
* A unique persistent identifier to namespace storage and other
|
||||
* persistent properties. For an ephemeral runtime identifier, use ephemeralIdentifier.
|
||||
*/
|
||||
identifier: ApplicationIdentifier
|
||||
|
||||
/**
|
||||
* Default host to use in ApiService.
|
||||
*/
|
||||
defaultHost: string
|
||||
/**
|
||||
* Version of client application.
|
||||
*/
|
||||
appVersion: string
|
||||
}
|
||||
Reference in New Issue
Block a user