-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Add UUID helpers to the SDK #14939
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add UUID helpers to the SDK #14939
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,16 +1,31 @@ | ||
| 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) { | ||
| super(`User (${userId}) is not logged in`); | ||
| } | ||
| } | ||
|
|
||
| // Converts a string to UUID. Will throw an error if the UUID is non valid. | ||
| export function uuid<T extends Uuid>(uuid: string): T { | ||
Hinton marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if (Utils.isGuid(uuid)) { | ||
| return uuid as T; | ||
| } | ||
|
|
||
| throw new Error(`Invalid UUID: ${uuid}`); | ||
Hinton marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| // Converts a UUID to the string representation. | ||
Hinton marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| export function uuid_to_string<T extends Uuid>(uuid: T): string { | ||
Hinton marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return uuid as unknown as string; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. question: should we do a sanity check here just to double check that the value is a string/defined?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could but they need to use something that is tagged as uuid, feels pretty hard to accidentally insert something unexpected here.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe if it comes across a network or from a deserialization process? |
||
| } | ||
|
|
||
| export abstract class SdkService { | ||
| /** | ||
| * Retrieve the version of the SDK. | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.