1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-16 00:03:56 +00:00

[PS-1906] Extract uploadEvents from EventService into new service (#4108)

* Move event.service to it's own folder

Move abstractions/event.service to abstractions/event/event.service
Move services/event.service to services/event/event.service
Fix all the imports

* Extract event-upload from event.service

Move `uploadEvents` from `EventService` to `EventUploadService`
Create event-upload-service-factory
Fix wiring up all the dependencies

* Remove clearEvents from EventService

clearEvents is only related to uploading events and can be moved into EventUploadService

Change the logout-method to only call EventUploadService.uploadEvents as that also calls clearEvents internally

* Rename EventService to EventCollectionService

Rename libs\common\abstraction\event\event.service.ts to libs\common\abstractions\event\event-collection.service.ts

Rename libs\common\services\event\event.service.ts to libs\common\services\event\event-collection.service.ts

Fix all the imports

Fix up service regristration/instantiation

Reanme \browser\src\background\service_factories\event-service.factory.ts to \browser\src\background\service_factories\event-collection-service.factory.ts

* Move interval to upload events to EventUploadSvc

Move the `init()` from event-collection.service to event-upload.service
Change call-site in web, desktop, browser
This commit is contained in:
Daniel James Smith
2022-12-06 14:47:42 +01:00
committed by GitHub
parent 1dca425dc4
commit 200dd0a1fb
44 changed files with 400 additions and 293 deletions

View File

@@ -12,7 +12,7 @@ import { BroadcasterService } from "@bitwarden/common/abstractions/broadcaster.s
import { CipherService } from "@bitwarden/common/abstractions/cipher.service";
import { CollectionService } from "@bitwarden/common/abstractions/collection.service";
import { CryptoService } from "@bitwarden/common/abstractions/crypto.service";
import { EventService } from "@bitwarden/common/abstractions/event.service";
import { EventUploadService } from "@bitwarden/common/abstractions/event/event-upload.service";
import { InternalFolderService } from "@bitwarden/common/abstractions/folder/folder.service.abstraction";
import { I18nService } from "@bitwarden/common/abstractions/i18n.service";
import { KeyConnectorService } from "@bitwarden/common/abstractions/keyConnector.service";
@@ -74,7 +74,7 @@ export class AppComponent implements OnDestroy, OnInit {
private notificationsService: NotificationsService,
private routerService: RouterService,
private stateService: StateService,
private eventService: EventService,
private eventUploadService: EventUploadService,
private policyService: InternalPolicyService,
protected policyListService: PolicyListService,
private keyConnectorService: KeyConnectorService
@@ -221,10 +221,9 @@ export class AppComponent implements OnDestroy, OnInit {
}
private async logOut(expired: boolean) {
await this.eventService.uploadEvents();
await this.eventUploadService.uploadEvents();
const userId = await this.stateService.getUserId();
await Promise.all([
this.eventService.clearEvents(),
this.syncService.setLastSync(new Date(0)),
this.cryptoService.clearKeys(),
this.settingsService.clear(userId),

View File

@@ -8,14 +8,14 @@ import {
EnvironmentService as EnvironmentServiceAbstraction,
Urls,
} from "@bitwarden/common/abstractions/environment.service";
import { EventService as EventLoggingServiceAbstraction } from "@bitwarden/common/abstractions/event.service";
import { EventUploadService as EventUploadServiceAbstraction } from "@bitwarden/common/abstractions/event/event-upload.service";
import { I18nService as I18nServiceAbstraction } from "@bitwarden/common/abstractions/i18n.service";
import { NotificationsService as NotificationsServiceAbstraction } from "@bitwarden/common/abstractions/notifications.service";
import { StateService as StateServiceAbstraction } from "@bitwarden/common/abstractions/state.service";
import { TwoFactorService as TwoFactorServiceAbstraction } from "@bitwarden/common/abstractions/twoFactor.service";
import { VaultTimeoutService as VaultTimeoutServiceAbstraction } from "@bitwarden/common/abstractions/vaultTimeout/vaultTimeout.service";
import { ContainerService } from "@bitwarden/common/services/container.service";
import { EventService as EventLoggingService } from "@bitwarden/common/services/event.service";
import { EventUploadService } from "@bitwarden/common/services/event/event-upload.service";
import { VaultTimeoutService as VaultTimeoutService } from "@bitwarden/common/services/vaultTimeout/vaultTimeout.service";
import { I18nService } from "./i18n.service";
@@ -28,7 +28,7 @@ export class InitService {
private notificationsService: NotificationsServiceAbstraction,
private vaultTimeoutService: VaultTimeoutServiceAbstraction,
private i18nService: I18nServiceAbstraction,
private eventLoggingService: EventLoggingServiceAbstraction,
private eventUploadService: EventUploadServiceAbstraction,
private twoFactorService: TwoFactorServiceAbstraction,
private stateService: StateServiceAbstraction,
private cryptoService: CryptoServiceAbstraction,
@@ -48,7 +48,7 @@ export class InitService {
(this.vaultTimeoutService as VaultTimeoutService).init(true);
const locale = await this.stateService.getLocale();
await (this.i18nService as I18nService).init(locale);
(this.eventLoggingService as EventLoggingService).init(true);
(this.eventUploadService as EventUploadService).init(true);
this.twoFactorService.init();
const htmlEl = this.win.document.documentElement;
htmlEl.classList.add("locale_" + this.i18nService.translationLocale);

View File

@@ -4,7 +4,7 @@ import { ActivatedRoute } from "@angular/router";
import { ModalService } from "@bitwarden/angular/services/modal.service";
import { CryptoService } from "@bitwarden/common/abstractions/crypto.service";
import { EventService } from "@bitwarden/common/abstractions/event.service";
import { EventCollectionService } from "@bitwarden/common/abstractions/event/event-collection.service";
import { ExportService } from "@bitwarden/common/abstractions/export.service";
import { FileDownloadService } from "@bitwarden/common/abstractions/fileDownload/fileDownload.service";
import { I18nService } from "@bitwarden/common/abstractions/i18n.service";
@@ -27,7 +27,7 @@ export class OrganizationExportComponent extends ExportComponent {
i18nService: I18nService,
platformUtilsService: PlatformUtilsService,
exportService: ExportService,
eventService: EventService,
eventCollectionService: EventCollectionService,
private route: ActivatedRoute,
policyService: PolicyService,
logService: LogService,
@@ -41,7 +41,7 @@ export class OrganizationExportComponent extends ExportComponent {
i18nService,
platformUtilsService,
exportService,
eventService,
eventCollectionService,
policyService,
logService,
userVerificationService,
@@ -76,7 +76,7 @@ export class OrganizationExportComponent extends ExportComponent {
}
async collectEvent(): Promise<void> {
await this.eventService.collect(
await this.eventCollectionService.collect(
EventType.Organization_ClientExportedVault,
null,
null,

View File

@@ -4,7 +4,7 @@ import { ApiService } from "@bitwarden/common/abstractions/api.service";
import { AuditService } from "@bitwarden/common/abstractions/audit.service";
import { CipherService } from "@bitwarden/common/abstractions/cipher.service";
import { CollectionService } from "@bitwarden/common/abstractions/collection.service";
import { EventService } from "@bitwarden/common/abstractions/event.service";
import { EventCollectionService } from "@bitwarden/common/abstractions/event/event-collection.service";
import { FolderService } from "@bitwarden/common/abstractions/folder/folder.service.abstraction";
import { I18nService } from "@bitwarden/common/abstractions/i18n.service";
import { LogService } from "@bitwarden/common/abstractions/log.service";
@@ -42,7 +42,7 @@ export class AddEditComponent extends BaseAddEditComponent {
passwordGenerationService: PasswordGenerationService,
private apiService: ApiService,
messagingService: MessagingService,
eventService: EventService,
eventCollectionService: EventCollectionService,
policyService: PolicyService,
logService: LogService,
passwordRepromptService: PasswordRepromptService,
@@ -59,7 +59,7 @@ export class AddEditComponent extends BaseAddEditComponent {
totpService,
passwordGenerationService,
messagingService,
eventService,
eventCollectionService,
policyService,
organizationService,
logService,

View File

@@ -2,7 +2,7 @@ import { Component, EventEmitter, Output } from "@angular/core";
import { ApiService } from "@bitwarden/common/abstractions/api.service";
import { CipherService } from "@bitwarden/common/abstractions/cipher.service";
import { EventService } from "@bitwarden/common/abstractions/event.service";
import { EventCollectionService } from "@bitwarden/common/abstractions/event/event-collection.service";
import { I18nService } from "@bitwarden/common/abstractions/i18n.service";
import { LogService } from "@bitwarden/common/abstractions/log.service";
import { OrganizationService } from "@bitwarden/common/abstractions/organization/organization.service.abstraction";
@@ -30,7 +30,7 @@ export class VaultItemsComponent extends BaseVaultItemsComponent {
i18nService: I18nService,
platformUtilsService: PlatformUtilsService,
cipherService: CipherService,
eventService: EventService,
eventCollectionService: EventCollectionService,
totpService: TotpService,
passwordRepromptService: PasswordRepromptService,
logService: LogService,
@@ -44,7 +44,7 @@ export class VaultItemsComponent extends BaseVaultItemsComponent {
i18nService,
platformUtilsService,
cipherService,
eventService,
eventCollectionService,
totpService,
stateService,
passwordRepromptService,

View File

@@ -3,7 +3,7 @@ import { Component } from "@angular/core";
import { AuditService } from "@bitwarden/common/abstractions/audit.service";
import { CipherService } from "@bitwarden/common/abstractions/cipher.service";
import { CollectionService } from "@bitwarden/common/abstractions/collection.service";
import { EventService } from "@bitwarden/common/abstractions/event.service";
import { EventCollectionService } from "@bitwarden/common/abstractions/event/event-collection.service";
import { FolderService } from "@bitwarden/common/abstractions/folder/folder.service.abstraction";
import { I18nService } from "@bitwarden/common/abstractions/i18n.service";
import { LogService } from "@bitwarden/common/abstractions/log.service";
@@ -38,7 +38,7 @@ export class EmergencyAddEditComponent extends BaseAddEditComponent {
totpService: TotpService,
passwordGenerationService: PasswordGenerationService,
messagingService: MessagingService,
eventService: EventService,
eventCollectionService: EventCollectionService,
policyService: PolicyService,
passwordRepromptService: PasswordRepromptService,
organizationService: OrganizationService,
@@ -55,7 +55,7 @@ export class EmergencyAddEditComponent extends BaseAddEditComponent {
totpService,
passwordGenerationService,
messagingService,
eventService,
eventCollectionService,
policyService,
organizationService,
logService,

View File

@@ -4,7 +4,7 @@ import { UntypedFormBuilder } from "@angular/forms";
import { ExportComponent as BaseExportComponent } from "@bitwarden/angular/components/export.component";
import { ModalService } from "@bitwarden/angular/services/modal.service";
import { CryptoService } from "@bitwarden/common/abstractions/crypto.service";
import { EventService } from "@bitwarden/common/abstractions/event.service";
import { EventCollectionService } from "@bitwarden/common/abstractions/event/event-collection.service";
import { ExportService } from "@bitwarden/common/abstractions/export.service";
import { FileDownloadService } from "@bitwarden/common/abstractions/fileDownload/fileDownload.service";
import { I18nService } from "@bitwarden/common/abstractions/i18n.service";
@@ -29,7 +29,7 @@ export class ExportComponent extends BaseExportComponent {
i18nService: I18nService,
platformUtilsService: PlatformUtilsService,
exportService: ExportService,
eventService: EventService,
eventCollectionService: EventCollectionService,
policyService: PolicyService,
logService: LogService,
userVerificationService: UserVerificationService,
@@ -42,7 +42,7 @@ export class ExportComponent extends BaseExportComponent {
i18nService,
platformUtilsService,
exportService,
eventService,
eventCollectionService,
policyService,
window,
logService,

View File

@@ -1,7 +1,7 @@
import { Component, Input } from "@angular/core";
import { AddEditCustomFieldsComponent as BaseAddEditCustomFieldsComponent } from "@bitwarden/angular/components/add-edit-custom-fields.component";
import { EventService } from "@bitwarden/common/abstractions/event.service";
import { EventCollectionService } from "@bitwarden/common/abstractions/event/event-collection.service";
import { I18nService } from "@bitwarden/common/abstractions/i18n.service";
@Component({
@@ -12,7 +12,7 @@ export class AddEditCustomFieldsComponent extends BaseAddEditCustomFieldsCompone
@Input() viewOnly: boolean;
@Input() copy: (value: string, typeI18nKey: string, aType: string) => void;
constructor(i18nService: I18nService, eventService: EventService) {
super(i18nService, eventService);
constructor(i18nService: I18nService, eventCollectionService: EventCollectionService) {
super(i18nService, eventCollectionService);
}
}

View File

@@ -4,7 +4,7 @@ import { AddEditComponent as BaseAddEditComponent } from "@bitwarden/angular/com
import { AuditService } from "@bitwarden/common/abstractions/audit.service";
import { CipherService } from "@bitwarden/common/abstractions/cipher.service";
import { CollectionService } from "@bitwarden/common/abstractions/collection.service";
import { EventService } from "@bitwarden/common/abstractions/event.service";
import { EventCollectionService } from "@bitwarden/common/abstractions/event/event-collection.service";
import { FolderService } from "@bitwarden/common/abstractions/folder/folder.service.abstraction";
import { I18nService } from "@bitwarden/common/abstractions/i18n.service";
import { LogService } from "@bitwarden/common/abstractions/log.service";
@@ -49,7 +49,7 @@ export class AddEditComponent extends BaseAddEditComponent implements OnInit, On
protected totpService: TotpService,
protected passwordGenerationService: PasswordGenerationService,
protected messagingService: MessagingService,
eventService: EventService,
eventCollectionService: EventCollectionService,
protected policyService: PolicyService,
organizationService: OrganizationService,
logService: LogService,
@@ -64,7 +64,7 @@ export class AddEditComponent extends BaseAddEditComponent implements OnInit, On
stateService,
collectionService,
messagingService,
eventService,
eventCollectionService,
policyService,
logService,
passwordRepromptService,
@@ -125,11 +125,17 @@ export class AddEditComponent extends BaseAddEditComponent implements OnInit, On
if (this.editMode) {
if (typeI18nKey === "password") {
this.eventService.collect(EventType.Cipher_ClientToggledHiddenFieldVisible, this.cipherId);
this.eventCollectionService.collect(
EventType.Cipher_ClientToggledHiddenFieldVisible,
this.cipherId
);
} else if (typeI18nKey === "securityCode") {
this.eventService.collect(EventType.Cipher_ClientCopiedCardCode, this.cipherId);
this.eventCollectionService.collect(EventType.Cipher_ClientCopiedCardCode, this.cipherId);
} else if (aType === "H_Field") {
this.eventService.collect(EventType.Cipher_ClientCopiedHiddenField, this.cipherId);
this.eventCollectionService.collect(
EventType.Cipher_ClientCopiedHiddenField,
this.cipherId
);
}
}
}

View File

@@ -2,7 +2,7 @@ import { Component, EventEmitter, Input, OnDestroy, Output } from "@angular/core
import { VaultItemsComponent as BaseVaultItemsComponent } from "@bitwarden/angular/components/vault-items.component";
import { CipherService } from "@bitwarden/common/abstractions/cipher.service";
import { EventService } from "@bitwarden/common/abstractions/event.service";
import { EventCollectionService } from "@bitwarden/common/abstractions/event/event-collection.service";
import { I18nService } from "@bitwarden/common/abstractions/i18n.service";
import { LogService } from "@bitwarden/common/abstractions/log.service";
import { OrganizationService } from "@bitwarden/common/abstractions/organization/organization.service.abstraction";
@@ -51,7 +51,7 @@ export class VaultItemsComponent extends BaseVaultItemsComponent implements OnDe
protected i18nService: I18nService,
protected platformUtilsService: PlatformUtilsService,
protected cipherService: CipherService,
protected eventService: EventService,
protected eventCollectionService: EventCollectionService,
protected totpService: TotpService,
protected stateService: StateService,
protected passwordRepromptService: PasswordRepromptService,
@@ -241,9 +241,12 @@ export class VaultItemsComponent extends BaseVaultItemsComponent implements OnDe
);
if (typeI18nKey === "password" || typeI18nKey === "verificationCodeTotp") {
this.eventService.collect(EventType.Cipher_ClientToggledHiddenFieldVisible, cipher.id);
this.eventCollectionService.collect(
EventType.Cipher_ClientToggledHiddenFieldVisible,
cipher.id
);
} else if (typeI18nKey === "securityCode") {
this.eventService.collect(EventType.Cipher_ClientCopiedCardCode, cipher.id);
this.eventCollectionService.collect(EventType.Cipher_ClientCopiedCardCode, cipher.id);
}
}