feat(web): extract ui-services package

This commit is contained in:
Karol Sójko
2022-08-04 15:13:30 +02:00
parent c72a407095
commit 7e251262d7
161 changed files with 1105 additions and 824 deletions

View File

@@ -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,
)