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

[PM-17408] Create new method on sdk service to allow explicit addition of a new client instance (#13309)

* feat: allow the user client to be overriden by an external provider

* feat: add ability to unset client

* feat: add `setClient` to interface (and add some docs)

* fix: re-add undefined

* fix: strict typing issues
This commit is contained in:
Andreas Coroiu
2025-02-24 11:29:47 +01:00
committed by GitHub
parent 5f390e6151
commit a9862d2a19
4 changed files with 265 additions and 74 deletions

View File

@@ -5,6 +5,12 @@ import { BitwardenClient } from "@bitwarden/sdk-internal";
import { UserId } from "../../../types/guid";
import { Rc } from "../../misc/reference-counting/rc";
export class UserNotLoggedInError extends Error {
constructor(userId: UserId) {
super(`User (${userId}) is not logged in`);
}
}
export abstract class SdkService {
/**
* Retrieve the version of the SDK.
@@ -26,7 +32,20 @@ export abstract class SdkService {
* The client will be destroyed when the observable is no longer subscribed to.
* Please let platform know if you need a client that is not destroyed when the observable is no longer subscribed to.
*
* @param userId
* @param userId The user id for which to retrieve the client
*
* @throws {UserNotLoggedInError} If the user is not logged in
*/
abstract userClient$(userId: UserId): Observable<Rc<BitwardenClient> | undefined>;
/**
* This method is used during/after an authentication procedure to set a new client for a specific user.
* It can also be used to unset the client when a user logs out, this will result in:
* - The client being disposed of
* - All subscriptions to the client being completed
* - Any new subscribers receiving an error
* @param userId The user id for which to set the client
* @param client The client to set for the user. If undefined, the client will be unset.
*/
abstract setClient(userId: UserId, client: BitwardenClient | undefined): void;
}