File tree Expand file tree Collapse file tree 1 file changed +26
-1
lines changed
libs/common/src/platform/abstractions/sdk Expand file tree Collapse file tree 1 file changed +26
-1
lines changed Original file line number Diff line number Diff line change 11import { Observable } from "rxjs" ;
22
3- import { BitwardenClient } from "@bitwarden/sdk-internal" ;
3+ import { BitwardenClient , Uuid } from "@bitwarden/sdk-internal" ;
44
55import { UserId } from "../../../types/guid" ;
66import { Rc } from "../../misc/reference-counting/rc" ;
7+ import { Utils } from "../../misc/utils" ;
78
89export class UserNotLoggedInError extends Error {
910 constructor ( userId : UserId ) {
1011 super ( `User (${ userId } ) is not logged in` ) ;
1112 }
1213}
1314
15+ export class InvalidUuid extends Error {
16+ constructor ( uuid : string ) {
17+ super ( `Invalid UUID: ${ uuid } ` ) ;
18+ }
19+ }
20+
21+ /**
22+ * Converts a string to UUID. Will throw an error if the UUID is non valid.
23+ */
24+ export function asUuid < T extends Uuid > ( uuid : string ) : T {
25+ if ( Utils . isGuid ( uuid ) ) {
26+ return uuid as T ;
27+ }
28+
29+ throw new InvalidUuid ( uuid ) ;
30+ }
31+
32+ /**
33+ * Converts a UUID to the string representation.
34+ */
35+ export function uuidToString < T extends Uuid > ( uuid : T ) : string {
36+ return uuid as unknown as string ;
37+ }
38+
1439export abstract class SdkService {
1540 /**
1641 * Retrieve the version of the SDK.
You can’t perform that action at this time.
0 commit comments