feat(web): extract ui-services package
This commit is contained in:
@@ -19,9 +19,12 @@ import * as Settings from '@standardnotes/settings'
|
||||
import * as Files from '@standardnotes/files'
|
||||
import { Subscription } from '@standardnotes/security'
|
||||
import { UuidString, ApplicationEventPayload } from '../Types'
|
||||
import { ApplicationEvent, applicationEventForSyncEvent } from '@Lib/Application/Event'
|
||||
import { applicationEventForSyncEvent } from '@Lib/Application/Event'
|
||||
import {
|
||||
ApplicationEvent,
|
||||
ApplicationEventCallback,
|
||||
ChallengeValidation,
|
||||
ComponentManagerInterface,
|
||||
DiagnosticInfo,
|
||||
Environment,
|
||||
isDesktopDevice,
|
||||
@@ -36,7 +39,7 @@ import {
|
||||
} from '@standardnotes/services'
|
||||
import { SNLog } from '../Log'
|
||||
import { useBoolean } from '@standardnotes/utils'
|
||||
import { DecryptedItemInterface, EncryptedItemInterface } from '@standardnotes/models'
|
||||
import { BackupFile, DecryptedItemInterface, EncryptedItemInterface, ItemStream } from '@standardnotes/models'
|
||||
import { ClientDisplayableError } from '@standardnotes/responses'
|
||||
import { Challenge, ChallengeResponse } from '../Services'
|
||||
import { ApplicationConstructorOptions, FullyResolvedApplicationOptions } from './Options/ApplicationOptions'
|
||||
@@ -49,20 +52,11 @@ type LaunchCallback = {
|
||||
receiveChallenge: (challenge: Challenge) => void
|
||||
}
|
||||
|
||||
type ApplicationEventCallback = (event: ApplicationEvent, data?: unknown) => Promise<void>
|
||||
|
||||
type ApplicationObserver = {
|
||||
singleEvent?: ApplicationEvent
|
||||
callback: ApplicationEventCallback
|
||||
}
|
||||
|
||||
type ItemStream<I extends DecryptedItemInterface> = (data: {
|
||||
changed: I[]
|
||||
inserted: I[]
|
||||
removed: (Models.DeletedItemInterface | Models.EncryptedItemInterface)[]
|
||||
source: Models.PayloadEmitSource
|
||||
}) => void
|
||||
|
||||
type ObserverRemover = () => void
|
||||
|
||||
export class SNApplication
|
||||
@@ -97,7 +91,7 @@ export class SNApplication
|
||||
private syncService!: InternalServices.SNSyncService
|
||||
private challengeService!: InternalServices.ChallengeService
|
||||
public singletonManager!: InternalServices.SNSingletonManager
|
||||
public componentManager!: InternalServices.SNComponentManager
|
||||
public componentManagerService!: InternalServices.SNComponentManager
|
||||
public protectionService!: InternalServices.SNProtectionService
|
||||
public actionsManager!: InternalServices.SNActionsService
|
||||
public historyManager!: InternalServices.SNHistoryManager
|
||||
@@ -192,11 +186,11 @@ export class SNApplication
|
||||
return this.fileService
|
||||
}
|
||||
|
||||
public get features(): InternalServices.FeaturesClientInterface {
|
||||
public get features(): ExternalServices.FeaturesClientInterface {
|
||||
return this.featuresService
|
||||
}
|
||||
|
||||
public get items(): InternalServices.ItemsClientInterface {
|
||||
public get items(): ExternalServices.ItemsClientInterface {
|
||||
return this.itemManager
|
||||
}
|
||||
|
||||
@@ -216,7 +210,7 @@ export class SNApplication
|
||||
return this.settingsService
|
||||
}
|
||||
|
||||
public get mutator(): InternalServices.MutatorClientInterface {
|
||||
public get mutator(): ExternalServices.MutatorClientInterface {
|
||||
return this.mutatorService
|
||||
}
|
||||
|
||||
@@ -232,6 +226,10 @@ export class SNApplication
|
||||
return this.filesBackupService
|
||||
}
|
||||
|
||||
public get componentManager(): ComponentManagerInterface {
|
||||
return this.componentManagerService
|
||||
}
|
||||
|
||||
public computePrivateWorkspaceIdentifier(userphrase: string, name: string): Promise<string | undefined> {
|
||||
return Encryption.ComputePrivateWorkspaceIdentifier(this.options.crypto, userphrase, name)
|
||||
}
|
||||
@@ -659,11 +657,11 @@ export class SNApplication
|
||||
return this.listedService.getListedAccountInfo(account, inContextOfItem)
|
||||
}
|
||||
|
||||
public async createEncryptedBackupFileForAutomatedDesktopBackups(): Promise<Encryption.BackupFile | undefined> {
|
||||
public async createEncryptedBackupFileForAutomatedDesktopBackups(): Promise<BackupFile | undefined> {
|
||||
return this.protocolService.createEncryptedBackupFile()
|
||||
}
|
||||
|
||||
public async createEncryptedBackupFile(): Promise<Encryption.BackupFile | undefined> {
|
||||
public async createEncryptedBackupFile(): Promise<BackupFile | undefined> {
|
||||
if (!(await this.protectionService.authorizeBackupCreation())) {
|
||||
return
|
||||
}
|
||||
@@ -671,7 +669,7 @@ export class SNApplication
|
||||
return this.protocolService.createEncryptedBackupFile()
|
||||
}
|
||||
|
||||
public async createDecryptedBackupFile(): Promise<Encryption.BackupFile | undefined> {
|
||||
public async createDecryptedBackupFile(): Promise<BackupFile | undefined> {
|
||||
if (!(await this.protectionService.authorizeBackupCreation())) {
|
||||
return
|
||||
}
|
||||
@@ -1070,7 +1068,7 @@ export class SNApplication
|
||||
;(this.syncService as unknown) = undefined
|
||||
;(this.challengeService as unknown) = undefined
|
||||
;(this.singletonManager as unknown) = undefined
|
||||
;(this.componentManager as unknown) = undefined
|
||||
;(this.componentManagerService as unknown) = undefined
|
||||
;(this.protectionService as unknown) = undefined
|
||||
;(this.actionsManager as unknown) = undefined
|
||||
;(this.historyManager as unknown) = undefined
|
||||
@@ -1161,11 +1159,11 @@ export class SNApplication
|
||||
this.serviceObservers.push(
|
||||
this.featuresService.addEventObserver((event) => {
|
||||
switch (event) {
|
||||
case InternalServices.FeaturesEvent.UserRolesChanged: {
|
||||
case ExternalServices.FeaturesEvent.UserRolesChanged: {
|
||||
void this.notifyEvent(ApplicationEvent.UserRolesChanged)
|
||||
break
|
||||
}
|
||||
case InternalServices.FeaturesEvent.FeaturesUpdated: {
|
||||
case ExternalServices.FeaturesEvent.FeaturesUpdated: {
|
||||
void this.notifyEvent(ApplicationEvent.FeaturesUpdated)
|
||||
break
|
||||
}
|
||||
@@ -1268,7 +1266,7 @@ export class SNApplication
|
||||
const MaybeSwappedComponentManager = this.getClass<typeof InternalServices.SNComponentManager>(
|
||||
InternalServices.SNComponentManager,
|
||||
)
|
||||
this.componentManager = new MaybeSwappedComponentManager(
|
||||
this.componentManagerService = new MaybeSwappedComponentManager(
|
||||
this.itemManager,
|
||||
this.syncService,
|
||||
this.featuresService,
|
||||
@@ -1278,7 +1276,7 @@ export class SNApplication
|
||||
this.platform,
|
||||
this.internalEventBus,
|
||||
)
|
||||
this.services.push(this.componentManager)
|
||||
this.services.push(this.componentManagerService)
|
||||
}
|
||||
|
||||
private createHttpManager() {
|
||||
@@ -1533,7 +1531,7 @@ export class SNApplication
|
||||
this.protocolService,
|
||||
this.payloadManager,
|
||||
this.challengeService,
|
||||
this.componentManager,
|
||||
this.componentManagerService,
|
||||
this.historyManager,
|
||||
this.internalEventBus,
|
||||
)
|
||||
|
||||
@@ -1,72 +1,6 @@
|
||||
import { SyncEvent } from '@standardnotes/services'
|
||||
import { ApplicationEvent, SyncEvent } from '@standardnotes/services'
|
||||
export { SyncEvent }
|
||||
|
||||
export enum ApplicationEvent {
|
||||
SignedIn = 2,
|
||||
SignedOut = 3,
|
||||
|
||||
/** When a full, potentially multi-page sync completes */
|
||||
CompletedFullSync = 5,
|
||||
|
||||
FailedSync = 6,
|
||||
HighLatencySync = 7,
|
||||
EnteredOutOfSync = 8,
|
||||
ExitedOutOfSync = 9,
|
||||
|
||||
/**
|
||||
* The application has finished it `prepareForLaunch` state and is now ready for unlock
|
||||
* Called when the application has initialized and is ready for launch, but before
|
||||
* the application has been unlocked, if applicable. Use this to do pre-launch
|
||||
* configuration, but do not attempt to access user data like notes or tags.
|
||||
*/
|
||||
Started = 10,
|
||||
|
||||
/**
|
||||
* The applicaiton is fully unlocked and ready for i/o
|
||||
* Called when the application has been fully decrypted and unlocked. Use this to
|
||||
* to begin streaming data like notes and tags.
|
||||
*/
|
||||
Launched = 11,
|
||||
LocalDataLoaded = 12,
|
||||
|
||||
/**
|
||||
* When the root key or root key wrapper changes. Includes events like account state
|
||||
* changes (registering, signing in, changing pw, logging out) and passcode state
|
||||
* changes (adding, removing, changing).
|
||||
*/
|
||||
KeyStatusChanged = 13,
|
||||
|
||||
MajorDataChange = 14,
|
||||
CompletedRestart = 15,
|
||||
LocalDataIncrementalLoad = 16,
|
||||
SyncStatusChanged = 17,
|
||||
WillSync = 18,
|
||||
InvalidSyncSession = 19,
|
||||
LocalDatabaseReadError = 20,
|
||||
LocalDatabaseWriteError = 21,
|
||||
|
||||
/** When a single roundtrip completes with sync, in a potentially multi-page sync request.
|
||||
* If just a single roundtrip, this event will be triggered, along with CompletedFullSync */
|
||||
CompletedIncrementalSync = 22,
|
||||
|
||||
/**
|
||||
* The application has loaded all pending migrations (but not run any, except for the base one),
|
||||
* and consumers may now call `hasPendingMigrations`
|
||||
*/
|
||||
MigrationsLoaded = 23,
|
||||
|
||||
/** When StorageService is ready to start servicing read/write requests */
|
||||
StorageReady = 24,
|
||||
|
||||
PreferencesChanged = 25,
|
||||
UnprotectedSessionBegan = 26,
|
||||
UserRolesChanged = 27,
|
||||
FeaturesUpdated = 28,
|
||||
UnprotectedSessionExpired = 29,
|
||||
/** Called when the app first launches and after first sync request made after sign in */
|
||||
CompletedInitialSync = 30,
|
||||
}
|
||||
|
||||
export function applicationEventForSyncEvent(syncEvent: SyncEvent) {
|
||||
return (
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user