1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-06 00:13:28 +00:00

Add UUID helpers to the SDK (#14939)

* Add UUID helpers to the SDK

* Address review feedback
This commit is contained in:
Oscar Hinton
2025-05-26 17:02:28 +02:00
committed by GitHub
parent 43c963032d
commit beb00a206b

View File

@@ -1,9 +1,10 @@
import { Observable } from "rxjs";
import { BitwardenClient } from "@bitwarden/sdk-internal";
import { BitwardenClient, Uuid } from "@bitwarden/sdk-internal";
import { UserId } from "../../../types/guid";
import { Rc } from "../../misc/reference-counting/rc";
import { Utils } from "../../misc/utils";
export class UserNotLoggedInError extends Error {
constructor(userId: UserId) {
@@ -11,6 +12,30 @@ export class UserNotLoggedInError extends Error {
}
}
export class InvalidUuid extends Error {
constructor(uuid: string) {
super(`Invalid UUID: ${uuid}`);
}
}
/**
* Converts a string to UUID. Will throw an error if the UUID is non valid.
*/
export function asUuid<T extends Uuid>(uuid: string): T {
if (Utils.isGuid(uuid)) {
return uuid as T;
}
throw new InvalidUuid(uuid);
}
/**
* Converts a UUID to the string representation.
*/
export function uuidToString<T extends Uuid>(uuid: T): string {
return uuid as unknown as string;
}
export abstract class SdkService {
/**
* Retrieve the version of the SDK.