diff --git a/.yarn/cache/@standardnotes-domain-events-npm-2.113.1-f94d16fda0-de7a64b588.zip b/.yarn/cache/@standardnotes-domain-events-npm-2.120.0-f3a9eaf351-bcd6caf10b.zip similarity index 71% rename from .yarn/cache/@standardnotes-domain-events-npm-2.113.1-f94d16fda0-de7a64b588.zip rename to .yarn/cache/@standardnotes-domain-events-npm-2.120.0-f3a9eaf351-bcd6caf10b.zip index 36e5d32ed..3c9d306f2 100644 Binary files a/.yarn/cache/@standardnotes-domain-events-npm-2.113.1-f94d16fda0-de7a64b588.zip and b/.yarn/cache/@standardnotes-domain-events-npm-2.120.0-f3a9eaf351-bcd6caf10b.zip differ diff --git a/.yarn/cache/@standardnotes-security-npm-1.12.0-b20ed17598-96d42255e7.zip b/.yarn/cache/@standardnotes-security-npm-1.12.0-b20ed17598-96d42255e7.zip new file mode 100644 index 000000000..2c8912e3d Binary files /dev/null and b/.yarn/cache/@standardnotes-security-npm-1.12.0-b20ed17598-96d42255e7.zip differ diff --git a/packages/services/src/Domain/Api/WebSocketsEventData.ts b/packages/services/src/Domain/Api/WebSocketsEventData.ts new file mode 100644 index 000000000..5f8d7cd1c --- /dev/null +++ b/packages/services/src/Domain/Api/WebSocketsEventData.ts @@ -0,0 +1,7 @@ +import { Either } from '@standardnotes/common' +import { UserRolesChangedEventPayload, NotificationAddedForUserEventPayload } from '@standardnotes/domain-events' + +export interface WebSocketsEventData { + type: string + payload: Either +} diff --git a/packages/snjs/lib/Services/Api/WebSocketsServiceEvent.ts b/packages/services/src/Domain/Api/WebSocketsServiceEvent.ts similarity index 62% rename from packages/snjs/lib/Services/Api/WebSocketsServiceEvent.ts rename to packages/services/src/Domain/Api/WebSocketsServiceEvent.ts index eab48edbb..c0e27c147 100644 --- a/packages/snjs/lib/Services/Api/WebSocketsServiceEvent.ts +++ b/packages/services/src/Domain/Api/WebSocketsServiceEvent.ts @@ -1,3 +1,4 @@ export enum WebSocketsServiceEvent { UserRoleMessageReceived = 'WebSocketMessageReceived', + NotificationAddedForUser = 'NotificationAddedForUser', } diff --git a/packages/snjs/lib/Services/Api/WebsocketsService.spec.ts b/packages/services/src/Domain/Api/WebsocketsService.spec.ts similarity index 70% rename from packages/snjs/lib/Services/Api/WebsocketsService.spec.ts rename to packages/services/src/Domain/Api/WebsocketsService.spec.ts index 82cf0458b..9a319f6e3 100644 --- a/packages/snjs/lib/Services/Api/WebsocketsService.spec.ts +++ b/packages/services/src/Domain/Api/WebsocketsService.spec.ts @@ -1,13 +1,14 @@ -import { InternalEventBusInterface } from '@standardnotes/services' import { WebSocketApiServiceInterface } from '@standardnotes/api' -import { StorageKey, DiskStorageService } from '@Lib/index' import { WebSocketsService } from './WebsocketsService' +import { StorageServiceInterface } from '../Storage/StorageServiceInterface' +import { InternalEventBusInterface } from '../Internal/InternalEventBusInterface' +import { StorageKey } from '../Storage/StorageKeys' describe('webSocketsService', () => { const webSocketUrl = '' - let storageService: DiskStorageService + let storageService: StorageServiceInterface let webSocketApiService: WebSocketApiServiceInterface let internalEventBus: InternalEventBusInterface @@ -16,7 +17,7 @@ describe('webSocketsService', () => { } beforeEach(() => { - storageService = {} as jest.Mocked + storageService = {} as jest.Mocked storageService.setValue = jest.fn() internalEventBus = {} as jest.Mocked @@ -27,9 +28,9 @@ describe('webSocketsService', () => { }) describe('setWebSocketUrl()', () => { - it('saves url in local storage', async () => { + it('saves url in local storage', () => { const webSocketUrl = 'wss://test-websocket' - await createService().setWebSocketUrl(webSocketUrl) + createService().setWebSocketUrl(webSocketUrl) expect(storageService.setValue).toHaveBeenCalledWith(StorageKey.WebSocketUrl, webSocketUrl) }) }) diff --git a/packages/snjs/lib/Services/Api/WebsocketsService.ts b/packages/services/src/Domain/Api/WebsocketsService.ts similarity index 69% rename from packages/snjs/lib/Services/Api/WebsocketsService.ts rename to packages/services/src/Domain/Api/WebsocketsService.ts index 625b2909c..32e764bc2 100644 --- a/packages/snjs/lib/Services/Api/WebsocketsService.ts +++ b/packages/services/src/Domain/Api/WebsocketsService.ts @@ -1,15 +1,18 @@ import { isErrorResponse } from '@standardnotes/responses' -import { UserRolesChangedEvent } from '@standardnotes/domain-events' import { - AbstractService, - InternalEventBusInterface, - StorageKey, - StorageServiceInterface, -} from '@standardnotes/services' + DomainEventInterface, + UserRolesChangedEvent, + NotificationAddedForUserEvent, +} from '@standardnotes/domain-events' import { WebSocketApiServiceInterface } from '@standardnotes/api' import { WebSocketsServiceEvent } from './WebSocketsServiceEvent' +import { StorageServiceInterface } from '../Storage/StorageServiceInterface' +import { InternalEventBusInterface } from '../Internal/InternalEventBusInterface' +import { AbstractService } from '../Service/AbstractService' +import { StorageKey } from '../Storage/StorageKeys' +import { WebSocketsEventData } from './WebSocketsEventData' -export class WebSocketsService extends AbstractService { +export class WebSocketsService extends AbstractService { private webSocket?: WebSocket constructor( @@ -61,9 +64,21 @@ export class WebSocketsService extends AbstractService @@ -18,8 +20,13 @@ export class NotificationService } async handleEvent(event: InternalEventInterface): Promise { - if (event.type === SyncEvent.ReceivedNotifications) { - return this.handleReceivedNotifications(event.payload as SyncEventReceivedNotificationsData) + switch (event.type) { + case SyncEvent.ReceivedNotifications: + return this.handleReceivedNotifications(event.payload as SyncEventReceivedNotificationsData) + case WebSocketsServiceEvent.NotificationAddedForUser: + return this.handleReceivedNotifications([(event as NotificationAddedForUserEvent).payload.notification]) + default: + break } } diff --git a/packages/services/src/Domain/index.ts b/packages/services/src/Domain/index.ts index 931d615cf..ad5c76674 100644 --- a/packages/services/src/Domain/index.ts +++ b/packages/services/src/Domain/index.ts @@ -4,6 +4,9 @@ export * from './Api/ApiServiceEventData' export * from './Api/LegacyApiServiceInterface' export * from './Api/MetaReceivedData' export * from './Api/SessionRefreshedData' +export * from './Api/WebSocketsEventData' +export * from './Api/WebsocketsService' +export * from './Api/WebSocketsServiceEvent' export * from './Application/AppGroupManagedApplication' export * from './Application/ApplicationInterface' export * from './Application/ApplicationStage' diff --git a/packages/snjs/lib/Application/Application.ts b/packages/snjs/lib/Application/Application.ts index 17ae2beea..d6062cf2a 100644 --- a/packages/snjs/lib/Application/Application.ts +++ b/packages/snjs/lib/Application/Application.ts @@ -1,6 +1,5 @@ import { MfaService } from './../Services/Mfa/MfaService' import { KeyRecoveryService } from './../Services/KeyRecovery/KeyRecoveryService' -import { WebSocketsService } from './../Services/Api/WebsocketsService' import { MigrationService } from './../Services/Migration/MigrationService' import { LegacyApiService } from './../Services/Api/ApiService' import { FeaturesService } from '@Lib/Services/Features/FeaturesService' @@ -83,6 +82,7 @@ import { CreateEncryptedBackupFile, GetTransitionStatus, StartTransition, + WebSocketsService, } from '@standardnotes/services' import { SNNote, diff --git a/packages/snjs/lib/Application/Dependencies/Dependencies.ts b/packages/snjs/lib/Application/Dependencies/Dependencies.ts index 084f82e73..aa48b40c5 100644 --- a/packages/snjs/lib/Application/Dependencies/Dependencies.ts +++ b/packages/snjs/lib/Application/Dependencies/Dependencies.ts @@ -22,7 +22,6 @@ import { ProtectionService } from '../../Services/Protection/ProtectionService' import { SyncService } from '../../Services/Sync/SyncService' import { HistoryManager } from '../../Services/History/HistoryManager' import { SessionManager } from '../../Services/Session/SessionManager' -import { WebSocketsService } from '../../Services/Api/WebsocketsService' import { LegacyApiService } from '../../Services/Api/ApiService' import { SnjsVersion } from '../../Version' import { DeprecatedHttpService } from '../../Services/Api/DeprecatedHttpService' @@ -143,6 +142,7 @@ import { SyncLocalVaultsWithRemoteSharedVaults, GetTransitionStatus, StartTransition, + WebSocketsService, } from '@standardnotes/services' import { ItemManager } from '../../Services/Items/ItemManager' import { PayloadManager } from '../../Services/Payloads/PayloadManager' diff --git a/packages/snjs/lib/Services/Api/index.ts b/packages/snjs/lib/Services/Api/index.ts index da29683d0..f8b0df329 100644 --- a/packages/snjs/lib/Services/Api/index.ts +++ b/packages/snjs/lib/Services/Api/index.ts @@ -2,4 +2,3 @@ export * from './ApiService' export * from './DeprecatedHttpService' export * from './Paths' export * from '../Session/SessionManager' -export * from './WebsocketsService' diff --git a/packages/snjs/lib/Services/Features/FeaturesService.spec.ts b/packages/snjs/lib/Services/Features/FeaturesService.spec.ts index 26129b745..6e465d754 100644 --- a/packages/snjs/lib/Services/Features/FeaturesService.spec.ts +++ b/packages/snjs/lib/Services/Features/FeaturesService.spec.ts @@ -4,7 +4,6 @@ import { SettingName } from '@standardnotes/settings' import { FeaturesService } from '@Lib/Services/Features' import { RoleName, ContentType, Uuid, Result } from '@standardnotes/domain-core' import { NativeFeatureIdentifier, GetFeatures } from '@standardnotes/features' -import { WebSocketsService } from '../Api/WebsocketsService' import { SettingsService } from '../Settings' import { PureCryptoInterface } from '@standardnotes/sncrypto-common' import { @@ -23,6 +22,7 @@ import { UserServiceInterface, UserService, IsApplicationUsingThirdPartyHost, + WebSocketsService, } from '@standardnotes/services' import { LegacyApiService, SessionManager } from '../Api' import { ItemManager } from '../Items' diff --git a/packages/snjs/lib/Services/Features/FeaturesService.ts b/packages/snjs/lib/Services/Features/FeaturesService.ts index 7ae10aa56..aadba4d29 100644 --- a/packages/snjs/lib/Services/Features/FeaturesService.ts +++ b/packages/snjs/lib/Services/Features/FeaturesService.ts @@ -3,8 +3,6 @@ import { arraysEqual, removeFromArray, lastElement, LoggerInterface } from '@sta import { ClientDisplayableError } from '@standardnotes/responses' import { RoleName, ContentType, Uuid } from '@standardnotes/domain-core' import { PureCryptoInterface } from '@standardnotes/sncrypto-common' -import { WebSocketsService } from '../Api/WebsocketsService' -import { WebSocketsServiceEvent } from '../Api/WebSocketsServiceEvent' import { UserRolesChangedEvent } from '@standardnotes/domain-events' import { ExperimentalFeatures, FindNativeFeature, NativeFeatureIdentifier } from '@standardnotes/features' import { @@ -47,6 +45,8 @@ import { ApplicationEvent, ApplicationStageChangedEventPayload, IsApplicationUsingThirdPartyHost, + WebSocketsServiceEvent, + WebSocketsService, } from '@standardnotes/services' import { DownloadRemoteThirdPartyFeatureUseCase } from './UseCase/DownloadRemoteThirdPartyFeature' diff --git a/packages/snjs/lib/Services/Session/SessionManager.ts b/packages/snjs/lib/Services/Session/SessionManager.ts index 086b6c9ae..74282dad3 100644 --- a/packages/snjs/lib/Services/Session/SessionManager.ts +++ b/packages/snjs/lib/Services/Session/SessionManager.ts @@ -34,6 +34,7 @@ import { ApplicationStage, GetKeyPairs, IsApplicationUsingThirdPartyHost, + WebSocketsService, } from '@standardnotes/services' import { Base64String, PureCryptoInterface } from '@standardnotes/sncrypto-common' import { @@ -59,7 +60,6 @@ import { RawStorageValue } from './Sessions/Types' import { ShareToken } from './ShareToken' import { LegacyApiService } from '../Api/ApiService' import { DiskStorageService } from '../Storage/DiskStorageService' -import { WebSocketsService } from '../Api/WebsocketsService' import { Strings } from '@Lib/Strings' import { UuidString } from '@Lib/Types/UuidString' import { ChallengeResponse, ChallengeService } from '../Challenge' diff --git a/packages/snjs/package.json b/packages/snjs/package.json index 04dd9f24c..14600a998 100644 --- a/packages/snjs/package.json +++ b/packages/snjs/package.json @@ -38,7 +38,7 @@ "@standardnotes/api": "workspace:*", "@standardnotes/common": "^1.50.0", "@standardnotes/domain-core": "^1.25.0", - "@standardnotes/domain-events": "^2.108.1", + "@standardnotes/domain-events": "^2.120.0", "@standardnotes/encryption": "workspace:*", "@standardnotes/features": "workspace:*", "@standardnotes/files": "workspace:*", diff --git a/yarn.lock b/yarn.lock index 9619cad05..3708368fb 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4349,13 +4349,13 @@ __metadata: languageName: node linkType: hard -"@standardnotes/domain-events@npm:^2.108.1": - version: 2.113.1 - resolution: "@standardnotes/domain-events@npm:2.113.1" +"@standardnotes/domain-events@npm:^2.120.0": + version: 2.120.0 + resolution: "@standardnotes/domain-events@npm:2.120.0" dependencies: "@standardnotes/predicates": 1.6.9 - "@standardnotes/security": 1.8.1 - checksum: de7a64b5882c2126fb6c7c7485c330e7065f38cfad83d6bfe3b4025bd42b28e6de6b7fb137086661b8ab16e8ff63b9b9a91e1b52b23ba413f108605d02f8e61a + "@standardnotes/security": 1.12.0 + checksum: bcd6caf10bc050199db4d0fb13605d43773418c1420efea583381ae6cd33a1a365451a61f3d8d6e08d19a52005e5d67ad2b4c8f3b8f951269b1a2a4bc0ac33cf languageName: node linkType: hard @@ -4703,7 +4703,17 @@ __metadata: languageName: node linkType: hard -"@standardnotes/security@npm:1.8.1, @standardnotes/security@npm:^1.2.0": +"@standardnotes/security@npm:1.12.0": + version: 1.12.0 + resolution: "@standardnotes/security@npm:1.12.0" + dependencies: + jsonwebtoken: ^9.0.0 + reflect-metadata: ^0.1.13 + checksum: 96d42255e79fc2cf4c52f3d370c04ae00296673993e1c0cea2356ca4a6c934d22d6100ba95f9ad602ffb72ee686367ef4a263dc6a6c51795d9b61dc835e635cd + languageName: node + linkType: hard + +"@standardnotes/security@npm:^1.2.0": version: 1.8.1 resolution: "@standardnotes/security@npm:1.8.1" dependencies: @@ -4819,7 +4829,7 @@ __metadata: "@standardnotes/api": "workspace:*" "@standardnotes/common": ^1.50.0 "@standardnotes/domain-core": ^1.25.0 - "@standardnotes/domain-events": ^2.108.1 + "@standardnotes/domain-events": ^2.120.0 "@standardnotes/encryption": "workspace:*" "@standardnotes/features": "workspace:*" "@standardnotes/files": "workspace:*"