1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-13 23:03:32 +00:00

[PM-7837] Move SyncService to Platform Ownership (#9055)

* Move

* Update  References In Unowned Files

* Update  References In Vault Files

* Update Web AppComponent

* Add Import
This commit is contained in:
Justin Baur
2024-06-05 10:48:12 -04:00
committed by GitHub
parent cb0927ac5d
commit 1aaa88a64d
29 changed files with 152 additions and 143 deletions

View File

@@ -103,6 +103,7 @@ import { EventResponse } from "../models/response/event.response";
import { ListResponse } from "../models/response/list.response";
import { ProfileResponse } from "../models/response/profile.response";
import { UserKeyResponse } from "../models/response/user-key.response";
import { SyncResponse } from "../platform/sync";
import { UserId } from "../types/guid";
import { AttachmentRequest } from "../vault/models/request/attachment.request";
import { CipherBulkDeleteRequest } from "../vault/models/request/cipher-bulk-delete.request";
@@ -124,7 +125,6 @@ import {
CollectionResponse,
} from "../vault/models/response/collection.response";
import { OptionalCipherResponse } from "../vault/models/response/optional-cipher.response";
import { SyncResponse } from "../vault/models/response/sync.response";
/**
* @deprecated The `ApiService` class is deprecated and calls should be extracted into individual

View File

@@ -1,50 +1,53 @@
import { firstValueFrom } from "rxjs";
import { LogoutReason, UserDecryptionOptionsServiceAbstraction } from "@bitwarden/auth/common";
import { UserDecryptionOptionsServiceAbstraction } from "../../../../auth/src/common/abstractions";
import { LogoutReason } from "../../../../auth/src/common/types";
import { ApiService } from "../../abstractions/api.service";
import { InternalOrganizationServiceAbstraction } from "../../admin-console/abstractions/organization/organization.service.abstraction";
import { InternalPolicyService } from "../../admin-console/abstractions/policy/policy.service.abstraction";
import { ProviderService } from "../../admin-console/abstractions/provider.service";
import { OrganizationUserType } from "../../admin-console/enums";
import { OrganizationData } from "../../admin-console/models/data/organization.data";
import { PolicyData } from "../../admin-console/models/data/policy.data";
import { ProviderData } from "../../admin-console/models/data/provider.data";
import { PolicyResponse } from "../../admin-console/models/response/policy.response";
import { AccountService } from "../../auth/abstractions/account.service";
import { AuthService } from "../../auth/abstractions/auth.service";
import { AvatarService } from "../../auth/abstractions/avatar.service";
import { KeyConnectorService } from "../../auth/abstractions/key-connector.service";
import { InternalMasterPasswordServiceAbstraction } from "../../auth/abstractions/master-password.service.abstraction";
import { TokenService } from "../../auth/abstractions/token.service";
import { ForceSetPasswordReason } from "../../auth/models/domain/force-set-password-reason";
import { DomainSettingsService } from "../../autofill/services/domain-settings.service";
import { BillingAccountProfileStateService } from "../../billing/abstractions";
import { DomainsResponse } from "../../models/response/domains.response";
import { ProfileResponse } from "../../models/response/profile.response";
import { SendData } from "../../tools/send/models/data/send.data";
import { SendResponse } from "../../tools/send/models/response/send.response";
import { SendApiService } from "../../tools/send/services/send-api.service.abstraction";
import { InternalSendService } from "../../tools/send/services/send.service.abstraction";
import { UserId } from "../../types/guid";
import { CipherService } from "../../vault/abstractions/cipher.service";
import { CollectionService } from "../../vault/abstractions/collection.service";
import { FolderApiServiceAbstraction } from "../../vault/abstractions/folder/folder-api.service.abstraction";
import { InternalFolderService } from "../../vault/abstractions/folder/folder.service.abstraction";
import { CipherData } from "../../vault/models/data/cipher.data";
import { CollectionData } from "../../vault/models/data/collection.data";
import { FolderData } from "../../vault/models/data/folder.data";
import { CipherResponse } from "../../vault/models/response/cipher.response";
import { CollectionDetailsResponse } from "../../vault/models/response/collection.response";
import { FolderResponse } from "../../vault/models/response/folder.response";
import { CryptoService } from "../abstractions/crypto.service";
import { LogService } from "../abstractions/log.service";
import { StateService } from "../abstractions/state.service";
import { MessageSender } from "../messaging";
import { sequentialize } from "../misc/sequentialize";
import { ApiService } from "../../../abstractions/api.service";
import { InternalOrganizationServiceAbstraction } from "../../../admin-console/abstractions/organization/organization.service.abstraction";
import { InternalPolicyService } from "../../../admin-console/abstractions/policy/policy.service.abstraction";
import { ProviderService } from "../../../admin-console/abstractions/provider.service";
import { OrganizationUserType } from "../../../admin-console/enums";
import { OrganizationData } from "../../../admin-console/models/data/organization.data";
import { PolicyData } from "../../../admin-console/models/data/policy.data";
import { ProviderData } from "../../../admin-console/models/data/provider.data";
import { PolicyResponse } from "../../../admin-console/models/response/policy.response";
import { AccountService } from "../../../auth/abstractions/account.service";
import { AuthService } from "../../../auth/abstractions/auth.service";
import { AvatarService } from "../../../auth/abstractions/avatar.service";
import { KeyConnectorService } from "../../../auth/abstractions/key-connector.service";
import { InternalMasterPasswordServiceAbstraction } from "../../../auth/abstractions/master-password.service.abstraction";
import { TokenService } from "../../../auth/abstractions/token.service";
import { ForceSetPasswordReason } from "../../../auth/models/domain/force-set-password-reason";
import { DomainSettingsService } from "../../../autofill/services/domain-settings.service";
import { BillingAccountProfileStateService } from "../../../billing/abstractions/account/billing-account-profile-state.service";
import { DomainsResponse } from "../../../models/response/domains.response";
import { ProfileResponse } from "../../../models/response/profile.response";
import { CryptoService } from "../../../platform/abstractions/crypto.service";
import { LogService } from "../../../platform/abstractions/log.service";
import { StateService } from "../../../platform/abstractions/state.service";
import { MessageSender } from "../../../platform/messaging";
import { sequentialize } from "../../../platform/misc/sequentialize";
import { CoreSyncService } from "../../../platform/sync/core-sync.service";
import { SendData } from "../../../tools/send/models/data/send.data";
import { SendResponse } from "../../../tools/send/models/response/send.response";
import { SendApiService } from "../../../tools/send/services/send-api.service.abstraction";
import { InternalSendService } from "../../../tools/send/services/send.service.abstraction";
import { UserId } from "../../../types/guid";
import { CipherService } from "../../../vault/abstractions/cipher.service";
import { FolderApiServiceAbstraction } from "../../../vault/abstractions/folder/folder-api.service.abstraction";
import { InternalFolderService } from "../../../vault/abstractions/folder/folder.service.abstraction";
import { CipherData } from "../../../vault/models/data/cipher.data";
import { FolderData } from "../../../vault/models/data/folder.data";
import { CipherResponse } from "../../../vault/models/response/cipher.response";
import { FolderResponse } from "../../../vault/models/response/folder.response";
import { CollectionService } from "../../abstractions/collection.service";
import { CollectionData } from "../../models/data/collection.data";
import { CollectionDetailsResponse } from "../../models/response/collection.response";
import { CoreSyncService } from "./core-sync.service";
export class DefaultSyncService extends CoreSyncService {
syncInProgress = false;
export class SyncService extends CoreSyncService {
constructor(
private masterPasswordService: InternalMasterPasswordServiceAbstraction,
accountService: AccountService,

View File

@@ -0,0 +1,2 @@
export { SyncService } from "./sync.service";
export { SyncResponse } from "./sync.response";

View File

@@ -1 +1,2 @@
export { DefaultSyncService } from "./default-sync.service";
export { CoreSyncService } from "./core-sync.service";

View File

@@ -1,4 +1,4 @@
import { SyncResponse } from "../models/response/sync.response";
import { SyncResponse } from "./sync.response";
type SyncStatus = "Started" | "Completed";

View File

@@ -1,12 +1,11 @@
import { PolicyResponse } from "../../../admin-console/models/response/policy.response";
import { BaseResponse } from "../../../models/response/base.response";
import { DomainsResponse } from "../../../models/response/domains.response";
import { ProfileResponse } from "../../../models/response/profile.response";
import { SendResponse } from "../../../tools/send/models/response/send.response";
import { CipherResponse } from "./cipher.response";
import { CollectionDetailsResponse } from "./collection.response";
import { FolderResponse } from "./folder.response";
import { PolicyResponse } from "../../admin-console/models/response/policy.response";
import { BaseResponse } from "../../models/response/base.response";
import { DomainsResponse } from "../../models/response/domains.response";
import { ProfileResponse } from "../../models/response/profile.response";
import { SendResponse } from "../../tools/send/models/response/send.response";
import { CipherResponse } from "../../vault/models/response/cipher.response";
import { CollectionDetailsResponse } from "../../vault/models/response/collection.response";
import { FolderResponse } from "../../vault/models/response/folder.response";
export class SyncResponse extends BaseResponse {
profile?: ProfileResponse;

View File

@@ -0,0 +1,58 @@
import {
SyncCipherNotification,
SyncFolderNotification,
SyncSendNotification,
} from "../../models/response/notification.response";
/**
* A class encapsulating sync operations and data.
*/
export abstract class SyncService {
/**
* A boolean indicating if a sync is currently in progress via this instance and this instance only.
*
* @deprecated Trusting this property is not safe as it only tells if the current instance is currently
* doing a sync operation but does not tell if another instance of SyncService is doing a sync operation.
*/
abstract syncInProgress: boolean;
/**
* Gets the date of the last sync for the currently active user.
*
* @returns The date of the last sync or null if there is no active user or the active user has not synced before.
*/
abstract getLastSync(): Promise<Date>;
/**
* Updates a users last sync date.
* @param date The date to be set as the users last sync date.
* @param userId The userId of the user to update the last sync date for.
*/
abstract setLastSync(date: Date, userId?: string): Promise<void>;
/**
* Optionally does a full sync operation including going to the server to gather the source
* of truth and set that data to state.
* @param forceSync A boolean dictating if a sync should be forced. If `true` a sync will happen
* as long as the current user is authenticated. If `false` it will only sync if either a sync
* has not happened before or the last sync date for the active user is before their account
* revision date. Try to always use `false` if possible.
*
* @param allowThrowOnError A boolean dictating whether or not caught errors should be rethrown.
* `true` if they can be rethrown, `false` if they should not be rethrown.
*/
abstract fullSync(forceSync: boolean, allowThrowOnError?: boolean): Promise<boolean>;
abstract syncUpsertFolder(
notification: SyncFolderNotification,
isEdit: boolean,
): Promise<boolean>;
abstract syncDeleteFolder(notification: SyncFolderNotification): Promise<boolean>;
abstract syncUpsertCipher(
notification: SyncCipherNotification,
isEdit: boolean,
): Promise<boolean>;
abstract syncDeleteCipher(notification: SyncFolderNotification): Promise<boolean>;
abstract syncUpsertSend(notification: SyncSendNotification, isEdit: boolean): Promise<boolean>;
abstract syncDeleteSend(notification: SyncSendNotification): Promise<boolean>;
}

View File

@@ -121,6 +121,7 @@ import { EnvironmentService } from "../platform/abstractions/environment.service
import { LogService } from "../platform/abstractions/log.service";
import { PlatformUtilsService } from "../platform/abstractions/platform-utils.service";
import { Utils } from "../platform/misc/utils";
import { SyncResponse } from "../platform/sync";
import { UserId } from "../types/guid";
import { AttachmentRequest } from "../vault/models/request/attachment.request";
import { CipherBulkDeleteRequest } from "../vault/models/request/cipher-bulk-delete.request";
@@ -142,7 +143,6 @@ import {
CollectionResponse,
} from "../vault/models/response/collection.response";
import { OptionalCipherResponse } from "../vault/models/response/optional-cipher.response";
import { SyncResponse } from "../vault/models/response/sync.response";
/**
* @deprecated The `ApiService` class is deprecated and calls should be extracted into individual

View File

@@ -21,8 +21,8 @@ import { EnvironmentService } from "../platform/abstractions/environment.service
import { LogService } from "../platform/abstractions/log.service";
import { MessagingService } from "../platform/abstractions/messaging.service";
import { StateService } from "../platform/abstractions/state.service";
import { SyncService } from "../platform/sync/sync.service";
import { UserId } from "../types/guid";
import { SyncService } from "../vault/abstractions/sync/sync.service.abstraction";
export class NotificationsService implements NotificationsServiceAbstraction {
private signalrConnection: signalR.HubConnection;

View File

@@ -1,8 +0,0 @@
import { Observable } from "rxjs";
import { SyncEventArgs } from "../../types/sync-event-args";
export abstract class SyncNotifierService {
sync$: Observable<SyncEventArgs>;
next: (event: SyncEventArgs) => void;
}

View File

@@ -1,19 +1,2 @@
import {
SyncCipherNotification,
SyncFolderNotification,
SyncSendNotification,
} from "../../../models/response/notification.response";
export abstract class SyncService {
syncInProgress: boolean;
getLastSync: () => Promise<Date>;
setLastSync: (date: Date, userId?: string) => Promise<any>;
fullSync: (forceSync: boolean, allowThrowOnError?: boolean) => Promise<boolean>;
syncUpsertFolder: (notification: SyncFolderNotification, isEdit: boolean) => Promise<boolean>;
syncDeleteFolder: (notification: SyncFolderNotification) => Promise<boolean>;
syncUpsertCipher: (notification: SyncCipherNotification, isEdit: boolean) => Promise<boolean>;
syncDeleteCipher: (notification: SyncFolderNotification) => Promise<boolean>;
syncUpsertSend: (notification: SyncSendNotification, isEdit: boolean) => Promise<boolean>;
syncDeleteSend: (notification: SyncSendNotification) => Promise<boolean>;
}
// TEMP: Re-export of original SyncService location to allow for team specific PR's
export { SyncService } from "../../../platform/sync";

View File

@@ -1,18 +0,0 @@
import { Subject } from "rxjs";
import { SyncNotifierService as SyncNotifierServiceAbstraction } from "../../abstractions/sync/sync-notifier.service.abstraction";
import { SyncEventArgs } from "../../types/sync-event-args";
/**
* This class should most likely have 0 dependencies because it will hopefully
* be rolled into SyncService once upon a time.
*/
export class SyncNotifierService implements SyncNotifierServiceAbstraction {
private _sync = new Subject<SyncEventArgs>();
sync$ = this._sync.asObservable();
next(event: SyncEventArgs): void {
this._sync.next(event);
}
}