Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion libs/common/src/platform/abstractions/sdk/sdk.service.ts
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 {
if (Utils.isGuid(uuid)) {
return uuid as T;

Check warning on line 18 in libs/common/src/platform/abstractions/sdk/sdk.service.ts

View check run for this annotation

Codecov / codecov/patch

libs/common/src/platform/abstractions/sdk/sdk.service.ts#L18

Added line #L18 was not covered by tests
}

throw new Error(`Invalid UUID: ${uuid}`);

Check warning on line 21 in libs/common/src/platform/abstractions/sdk/sdk.service.ts

View check run for this annotation

Codecov / codecov/patch

libs/common/src/platform/abstractions/sdk/sdk.service.ts#L21

Added line #L21 was not covered by tests
}

// Converts a UUID to the string representation.
export function uuid_to_string<T extends Uuid>(uuid: T): string {
return uuid as unknown as string;

Check warning on line 26 in libs/common/src/platform/abstractions/sdk/sdk.service.ts

View check run for this annotation

Codecov / codecov/patch

libs/common/src/platform/abstractions/sdk/sdk.service.ts#L26

Added line #L26 was not covered by tests
Copy link
Contributor

Choose a reason for hiding this comment

The 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?

Copy link
Member Author

Choose a reason for hiding this comment

The 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.

Copy link
Contributor

Choose a reason for hiding this comment

The 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.
Expand Down
Loading