1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-20 10:13:31 +00:00
Files
browser/libs/common/src/platform/sync/sync.service.ts
SmithThe4th a2945203f4 [PM-12047] Remove usage of ActiveUserState from cipher.service (#12814)
* Cipher service web changes

* Updated browser client to pass user id to cipher service observable changes

* Cli changes

* desktop changes

* Fixed test

* Libs changes

* Fixed merge conflicts

* Fixed merge conflicts

* removed duplicate reference fixed conflict

* Fixed test

* Fixed test

* Fixed test

* Fixed desturcturing issue on failed to decrypt ciphers cipher service

* Updated abstraction to use method syntax

* Fixed conflicts

* Fixed test on add edit v2

Passed active userId to delete function

* Used getUserId utility function

* made vault changes

* made suggestion changes

* made suggestion changes

* made suggestion changes

* Replace getUserId function calls with pipe operator syntax for better consistency

* fixed merge conflicts

* revert mistake made of usinf account activity during merge conflict fix

* fixed conflicts

* fixed tests
2025-02-12 08:53:31 -05:00

71 lines
2.9 KiB
TypeScript

import { Observable } from "rxjs";
import {
SyncCipherNotification,
SyncFolderNotification,
SyncSendNotification,
} from "../../models/response/notification.response";
import { UserId } from "../../types/guid";
/**
* 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.
*
* @deprecated Use {@link lastSync$} to get an observable stream of a given users last sync date instead.
*/
abstract getLastSync(): Promise<Date | null>;
/**
* Retrieves a stream of the given users last sync date. Or null if the user has not synced before.
* @param userId The user id of the user to get the stream for.
*/
abstract lastSync$(userId: UserId): Observable<Date | null>;
/**
* Retrieves a stream of the currently active user's last sync date.
* Or null if there is no current active user or the active user has not synced before.
*/
abstract activeUserLastSync$(): Observable<Date | null>;
/**
* 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,
userId: UserId,
): Promise<boolean>;
abstract syncDeleteFolder(notification: SyncFolderNotification, userId: UserId): Promise<boolean>;
abstract syncUpsertCipher(
notification: SyncCipherNotification,
isEdit: boolean,
userId: UserId,
): Promise<boolean>;
abstract syncDeleteCipher(notification: SyncFolderNotification, userId: UserId): Promise<boolean>;
abstract syncUpsertSend(notification: SyncSendNotification, isEdit: boolean): Promise<boolean>;
abstract syncDeleteSend(notification: SyncSendNotification): Promise<boolean>;
}