mirror of
https://github.com/bitwarden/browser
synced 2025-12-06 00:13:28 +00:00
[PM-13374] Update all SDK uuids (#14962)
* fix: broken SDK interface * Fix all compile errors related to uuids * Fix browser desktop * Fix tests --------- Co-authored-by: Andreas Coroiu <andreas.coroiu@gmail.com>
This commit is contained in:
@@ -23,6 +23,7 @@ import { AccountService } from "@bitwarden/common/auth/abstractions/account.serv
|
||||
import { getUserId } from "@bitwarden/common/auth/services/account.service";
|
||||
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
||||
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
|
||||
import { uuidAsString } from "@bitwarden/common/platform/abstractions/sdk/sdk.service";
|
||||
import { CipherId } from "@bitwarden/common/types/guid";
|
||||
import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service";
|
||||
import { CipherType } from "@bitwarden/common/vault/enums";
|
||||
@@ -321,7 +322,7 @@ export class VaultListItemsContainerComponent implements AfterViewInit {
|
||||
}
|
||||
|
||||
const activeUserId = await firstValueFrom(this.accountService.activeAccount$.pipe(getUserId));
|
||||
await this.cipherService.updateLastLaunchedDate(cipher.id!, activeUserId);
|
||||
await this.cipherService.updateLastLaunchedDate(uuidAsString(cipher.id!), activeUserId);
|
||||
|
||||
await BrowserApi.createNewTab(launchURI);
|
||||
|
||||
@@ -338,7 +339,7 @@ export class VaultListItemsContainerComponent implements AfterViewInit {
|
||||
|
||||
// When only the `CipherListView` is available, fetch the full cipher details
|
||||
const activeUserId = await firstValueFrom(this.accountService.activeAccount$.pipe(getUserId));
|
||||
const _cipher = await this.cipherService.get(cipher.id!, activeUserId);
|
||||
const _cipher = await this.cipherService.get(uuidAsString(cipher.id!), activeUserId);
|
||||
const cipherView = await this.cipherService.decrypt(_cipher, activeUserId);
|
||||
|
||||
await this.vaultPopupAutofillService.doAutofill(cipherView);
|
||||
|
||||
@@ -8,6 +8,7 @@ import { OrganizationService } from "@bitwarden/common/admin-console/abstraction
|
||||
import { Organization } from "@bitwarden/common/admin-console/models/domain/organization";
|
||||
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
|
||||
import { ProductTierType } from "@bitwarden/common/billing/enums";
|
||||
import { uuidAsString } from "@bitwarden/common/platform/abstractions/sdk/sdk.service";
|
||||
import { Utils } from "@bitwarden/common/platform/misc/utils";
|
||||
import { SyncService } from "@bitwarden/common/platform/sync";
|
||||
import { ObservableTracker, mockAccountServiceWith } from "@bitwarden/common/spec";
|
||||
@@ -102,7 +103,7 @@ describe("VaultPopupItemsService", () => {
|
||||
|
||||
searchService.searchCiphers.mockImplementation(async (userId, _, __, ciphers) => ciphers);
|
||||
cipherServiceMock.filterCiphersForUrl.mockImplementation(async (ciphers) =>
|
||||
ciphers.filter((c) => ["0", "1"].includes(c.id)),
|
||||
ciphers.filter((c) => ["0", "1"].includes(uuidAsString(c.id))),
|
||||
);
|
||||
vaultSettingsServiceMock.showCardsCurrentTab$ = new BehaviorSubject(false);
|
||||
vaultSettingsServiceMock.showIdentitiesCurrentTab$ = new BehaviorSubject(false);
|
||||
|
||||
@@ -14,6 +14,7 @@ import { AccountService } from "@bitwarden/common/auth/abstractions/account.serv
|
||||
import { ProductTierType } from "@bitwarden/common/billing/enums";
|
||||
import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service";
|
||||
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
||||
import { asUuid } from "@bitwarden/common/platform/abstractions/sdk/sdk.service";
|
||||
import { StateProvider } from "@bitwarden/common/platform/state";
|
||||
import { mockAccountServiceWith } from "@bitwarden/common/spec";
|
||||
import { UserId } from "@bitwarden/common/types/guid";
|
||||
@@ -514,8 +515,17 @@ describe("VaultPopupListFiltersService", () => {
|
||||
describe("filterFunction$", () => {
|
||||
const ciphers = [
|
||||
{ type: CipherType.Login, collectionIds: [], organizationId: null },
|
||||
{ type: CipherType.Card, collectionIds: ["1234"], organizationId: "8978" },
|
||||
{ type: CipherType.Identity, collectionIds: [], folderId: "5432", organizationId: null },
|
||||
{
|
||||
type: CipherType.Card,
|
||||
collectionIds: [asUuid("cbcae898-9f9a-48eb-863e-edf92e3ad7e0")],
|
||||
organizationId: "8978" as any,
|
||||
},
|
||||
{
|
||||
type: CipherType.Identity,
|
||||
collectionIds: [],
|
||||
folderId: "5432" as any,
|
||||
organizationId: null,
|
||||
},
|
||||
{ type: CipherType.SecureNote, collectionIds: [], organizationId: null },
|
||||
] as CipherView[];
|
||||
|
||||
@@ -529,7 +539,7 @@ describe("VaultPopupListFiltersService", () => {
|
||||
});
|
||||
|
||||
it("filters by collection", (done) => {
|
||||
const collection = { id: "1234" } as CollectionView;
|
||||
const collection = { id: "cbcae898-9f9a-48eb-863e-edf92e3ad7e0" } as CollectionView;
|
||||
|
||||
service.filterFunction$.subscribe((filterFunction) => {
|
||||
expect(filterFunction(ciphers)).toEqual([ciphers[1]]);
|
||||
|
||||
@@ -28,6 +28,7 @@ import { ProductTierType } from "@bitwarden/common/billing/enums";
|
||||
import { FeatureFlag } from "@bitwarden/common/enums/feature-flag.enum";
|
||||
import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service";
|
||||
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
||||
import { asUuid } from "@bitwarden/common/platform/abstractions/sdk/sdk.service";
|
||||
import { Utils } from "@bitwarden/common/platform/misc/utils";
|
||||
import {
|
||||
KeyDefinition,
|
||||
@@ -236,7 +237,10 @@ export class VaultPopupListFiltersService {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (filters.collection && !cipher.collectionIds?.includes(filters.collection.id!)) {
|
||||
if (
|
||||
filters.collection &&
|
||||
!cipher.collectionIds?.includes(asUuid(filters.collection.id!))
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import { distinctUntilChanged, debounceTime } from "rxjs";
|
||||
import { JslibModule } from "@bitwarden/angular/jslib.module";
|
||||
import { VaultItemsComponent as BaseVaultItemsComponent } from "@bitwarden/angular/vault/components/vault-items.component";
|
||||
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
|
||||
import { uuidAsString } from "@bitwarden/common/platform/abstractions/sdk/sdk.service";
|
||||
import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service";
|
||||
import { SearchService } from "@bitwarden/common/vault/abstractions/search.service";
|
||||
import { RestrictedItemTypesService } from "@bitwarden/common/vault/services/restricted-item-types.service";
|
||||
@@ -43,6 +44,6 @@ export class VaultItemsV2Component<C extends CipherViewLike> extends BaseVaultIt
|
||||
}
|
||||
|
||||
trackByFn(index: number, c: C): string {
|
||||
return c.id!;
|
||||
return uuidAsString(c.id!);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
import { Component, Input } from "@angular/core";
|
||||
|
||||
import { CollectionView } from "@bitwarden/admin-console/common";
|
||||
import { uuidAsString } from "@bitwarden/common/platform/abstractions/sdk/sdk.service";
|
||||
import { CollectionId } from "@bitwarden/sdk-internal";
|
||||
|
||||
import { SharedModule } from "../../../../shared/shared.module";
|
||||
import { GetCollectionNameFromIdPipe } from "../pipes";
|
||||
@@ -13,11 +15,11 @@ import { GetCollectionNameFromIdPipe } from "../pipes";
|
||||
imports: [SharedModule, GetCollectionNameFromIdPipe],
|
||||
})
|
||||
export class CollectionNameBadgeComponent {
|
||||
@Input() collectionIds: string[];
|
||||
@Input() collectionIds: CollectionId[] | string[];
|
||||
@Input() collections: CollectionView[];
|
||||
|
||||
get shownCollections(): string[] {
|
||||
return this.showXMore ? this.collectionIds.slice(0, 2) : this.collectionIds;
|
||||
return (this.showXMore ? this.collectionIds.slice(0, 2) : this.collectionIds).map(uuidAsString);
|
||||
}
|
||||
|
||||
get showXMore(): boolean {
|
||||
|
||||
@@ -310,7 +310,7 @@ export class VaultItemsComponent<C extends CipherViewLike> {
|
||||
const orgCollections = this.allCollections.filter((c) => c.organizationId === org.id);
|
||||
|
||||
for (const collection of orgCollections) {
|
||||
if (vaultItem.cipher.collectionIds.includes(collection.id) && collection.manage) {
|
||||
if (vaultItem.cipher.collectionIds.includes(collection.id as any) && collection.manage) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -364,7 +364,7 @@ export class VaultItemsComponent<C extends CipherViewLike> {
|
||||
}
|
||||
|
||||
return this.allCollections
|
||||
.filter((c) => cipher.collectionIds.includes(c.id))
|
||||
.filter((c) => cipher.collectionIds.includes(c.id as any))
|
||||
.some((collection) => collection.manage);
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ import { AvatarService } from "@bitwarden/common/auth/abstractions/avatar.servic
|
||||
import { TokenService } from "@bitwarden/common/auth/abstractions/token.service";
|
||||
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
||||
import { Utils } from "@bitwarden/common/platform/misc/utils";
|
||||
import { OrganizationId } from "@bitwarden/sdk-internal";
|
||||
|
||||
@Component({
|
||||
selector: "app-org-badge",
|
||||
@@ -15,7 +16,7 @@ import { Utils } from "@bitwarden/common/platform/misc/utils";
|
||||
standalone: false,
|
||||
})
|
||||
export class OrganizationNameBadgeComponent implements OnChanges {
|
||||
@Input() organizationId?: string;
|
||||
@Input() organizationId?: OrganizationId | string;
|
||||
@Input() organizationName: string;
|
||||
@Input() disabled: boolean;
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { Pipe, PipeTransform } from "@angular/core";
|
||||
|
||||
import { Organization } from "@bitwarden/common/admin-console/models/domain/organization";
|
||||
import { OrganizationId } from "@bitwarden/sdk-internal";
|
||||
|
||||
@Pipe({
|
||||
name: "orgNameFromId",
|
||||
@@ -8,7 +9,7 @@ import { Organization } from "@bitwarden/common/admin-console/models/domain/orga
|
||||
standalone: false,
|
||||
})
|
||||
export class GetOrgNameFromIdPipe implements PipeTransform {
|
||||
transform(value: string, organizations: Organization[]) {
|
||||
transform(value: string | OrganizationId, organizations: Organization[]) {
|
||||
const orgName = organizations?.find((o) => o.id === value)?.name;
|
||||
return orgName;
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ export function createFilterFunction(filter: RoutedVaultFilterModel): FilterFunc
|
||||
filter.collectionId !== undefined &&
|
||||
filter.collectionId !== All &&
|
||||
filter.collectionId !== Unassigned &&
|
||||
(cipher.collectionIds == null || !cipher.collectionIds.includes(filter.collectionId))
|
||||
(cipher.collectionIds == null || !cipher.collectionIds.includes(filter.collectionId as any))
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -56,6 +56,7 @@ import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.servic
|
||||
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
|
||||
import { MessagingService } from "@bitwarden/common/platform/abstractions/messaging.service";
|
||||
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
|
||||
import { uuidAsString } from "@bitwarden/common/platform/abstractions/sdk/sdk.service";
|
||||
import { Utils } from "@bitwarden/common/platform/misc/utils";
|
||||
import { SyncService } from "@bitwarden/common/platform/sync";
|
||||
import { CipherId, CollectionId, OrganizationId, UserId } from "@bitwarden/common/types/guid";
|
||||
@@ -678,7 +679,7 @@ export class VaultComponent<C extends CipherViewLike> implements OnInit, OnDestr
|
||||
return;
|
||||
} else if (cipher.organizationId != null) {
|
||||
const org = await firstValueFrom(
|
||||
this.organizations$.pipe(getOrganizationById(cipher.organizationId)),
|
||||
this.organizations$.pipe(getOrganizationById(uuidAsString(cipher.organizationId))),
|
||||
);
|
||||
if (org != null && (org.maxStorageGb == null || org.maxStorageGb === 0)) {
|
||||
this.messagingService.send("upgradeOrganization", {
|
||||
@@ -775,7 +776,7 @@ export class VaultComponent<C extends CipherViewLike> implements OnInit, OnDestr
|
||||
}
|
||||
|
||||
async editCipher(cipher: CipherView | CipherListView, cloneMode?: boolean) {
|
||||
return this.editCipherId(cipher?.id, cloneMode);
|
||||
return this.editCipherId(uuidAsString(cipher?.id), cloneMode);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1044,7 +1045,7 @@ export class VaultComponent<C extends CipherViewLike> implements OnInit, OnDestr
|
||||
|
||||
try {
|
||||
const activeUserId = await firstValueFrom(this.accountService.activeAccount$.pipe(getUserId));
|
||||
await this.cipherService.restoreWithServer(c.id, activeUserId);
|
||||
await this.cipherService.restoreWithServer(uuidAsString(c.id), activeUserId);
|
||||
this.toastService.showToast({
|
||||
variant: "success",
|
||||
title: null,
|
||||
@@ -1066,7 +1067,7 @@ export class VaultComponent<C extends CipherViewLike> implements OnInit, OnDestr
|
||||
return;
|
||||
}
|
||||
|
||||
const selectedCipherIds = ciphers.map((cipher) => cipher.id);
|
||||
const selectedCipherIds = ciphers.map((cipher) => uuidAsString(cipher.id));
|
||||
if (selectedCipherIds.length === 0) {
|
||||
this.toastService.showToast({
|
||||
variant: "error",
|
||||
@@ -1128,7 +1129,7 @@ export class VaultComponent<C extends CipherViewLike> implements OnInit, OnDestr
|
||||
|
||||
try {
|
||||
const activeUserId = await firstValueFrom(this.accountService.activeAccount$.pipe(getUserId));
|
||||
await this.deleteCipherWithServer(c.id, activeUserId, permanent);
|
||||
await this.deleteCipherWithServer(uuidAsString(c.id), activeUserId, permanent);
|
||||
|
||||
this.toastService.showToast({
|
||||
variant: "success",
|
||||
@@ -1168,7 +1169,7 @@ export class VaultComponent<C extends CipherViewLike> implements OnInit, OnDestr
|
||||
const dialog = openBulkDeleteDialog(this.dialogService, {
|
||||
data: {
|
||||
permanent: this.filter.type === "trash",
|
||||
cipherIds: ciphers.map((c) => c.id),
|
||||
cipherIds: ciphers.map((c) => uuidAsString(c.id)),
|
||||
organizations: organizations,
|
||||
collections: collections,
|
||||
},
|
||||
@@ -1185,7 +1186,7 @@ export class VaultComponent<C extends CipherViewLike> implements OnInit, OnDestr
|
||||
return;
|
||||
}
|
||||
|
||||
const selectedCipherIds = ciphers.map((cipher) => cipher.id);
|
||||
const selectedCipherIds = ciphers.map((cipher) => uuidAsString(cipher.id));
|
||||
if (selectedCipherIds.length === 0) {
|
||||
this.toastService.showToast({
|
||||
variant: "error",
|
||||
@@ -1261,11 +1262,14 @@ export class VaultComponent<C extends CipherViewLike> implements OnInit, OnDestr
|
||||
});
|
||||
|
||||
if (field === "password") {
|
||||
await this.eventCollectionService.collect(EventType.Cipher_ClientCopiedPassword, cipher.id);
|
||||
await this.eventCollectionService.collect(
|
||||
EventType.Cipher_ClientCopiedPassword,
|
||||
uuidAsString(cipher.id),
|
||||
);
|
||||
} else if (field === "totp") {
|
||||
await this.eventCollectionService.collect(
|
||||
EventType.Cipher_ClientCopiedHiddenField,
|
||||
cipher.id,
|
||||
uuidAsString(cipher.id),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1324,7 +1328,7 @@ export class VaultComponent<C extends CipherViewLike> implements OnInit, OnDestr
|
||||
}
|
||||
|
||||
const activeUserId = await firstValueFrom(this.accountService.activeAccount$.pipe(getUserId));
|
||||
const _cipher = await this.cipherService.get(cipher.id, activeUserId);
|
||||
const _cipher = await this.cipherService.get(uuidAsString(cipher.id), activeUserId);
|
||||
const cipherView = await this.cipherService.decrypt(_cipher, activeUserId);
|
||||
return cipherView.login?.password;
|
||||
}
|
||||
|
||||
@@ -118,15 +118,18 @@ describe("VaultFilter", () => {
|
||||
});
|
||||
|
||||
describe("given an organizational cipher (with organization and collections)", () => {
|
||||
const collection1 = "e9652fc0-1fe4-48d5-a3d8-d821e32fbd98";
|
||||
const collection2 = "42a971a5-8c16-48a3-a725-4be27cd99bc9";
|
||||
|
||||
const cipher = createCipher({
|
||||
organizationId: "organizationId",
|
||||
collectionIds: ["collectionId", "anotherId"],
|
||||
collectionIds: [collection1, collection2],
|
||||
});
|
||||
|
||||
it("should return true when filter matches collection id", () => {
|
||||
const filterFunction = createFilterFunction({
|
||||
selectedCollection: true,
|
||||
selectedCollectionId: "collectionId",
|
||||
selectedCollectionId: collection1,
|
||||
});
|
||||
|
||||
const result = filterFunction(cipher);
|
||||
@@ -137,7 +140,7 @@ describe("VaultFilter", () => {
|
||||
it("should return false when filter does not match collection id", () => {
|
||||
const filterFunction = createFilterFunction({
|
||||
selectedCollection: true,
|
||||
selectedCollectionId: "nonMatchingId",
|
||||
selectedCollectionId: "1ea7ad96-3fc1-4567-8fe5-91aa9f697fd1",
|
||||
});
|
||||
|
||||
const result = filterFunction(cipher);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// FIXME: Update this file to be type safe and remove this and next line
|
||||
// @ts-strict-ignore
|
||||
import { asUuid } from "@bitwarden/common/platform/abstractions/sdk/sdk.service";
|
||||
import { CipherType } from "@bitwarden/common/vault/enums";
|
||||
import {
|
||||
CipherViewLike,
|
||||
@@ -65,7 +66,8 @@ export class VaultFilter {
|
||||
}
|
||||
if (this.selectedCollection && this.selectedCollectionId != null && cipherPassesFilter) {
|
||||
cipherPassesFilter =
|
||||
cipher.collectionIds != null && cipher.collectionIds.includes(this.selectedCollectionId);
|
||||
cipher.collectionIds != null &&
|
||||
cipher.collectionIds.includes(asUuid(this.selectedCollectionId));
|
||||
}
|
||||
if (this.selectedOrganizationId != null && cipherPassesFilter) {
|
||||
cipherPassesFilter = cipher.organizationId === this.selectedOrganizationId;
|
||||
|
||||
@@ -32,7 +32,7 @@ export function asUuid<T extends Uuid>(uuid: string): T {
|
||||
/**
|
||||
* Converts a UUID to the string representation.
|
||||
*/
|
||||
export function uuidToString<T extends Uuid>(uuid: T): string {
|
||||
export function uuidAsString<T extends Uuid>(uuid: T): string {
|
||||
return uuid as unknown as string;
|
||||
}
|
||||
|
||||
|
||||
@@ -72,7 +72,7 @@ describe("DefaultSdkService", () => {
|
||||
});
|
||||
|
||||
describe("given the user is logged in", () => {
|
||||
const userId = "user-id" as UserId;
|
||||
const userId = "0da62ebd-98bb-4f42-a846-64e8555087d7" as UserId;
|
||||
beforeEach(() => {
|
||||
environmentService.getEnvironment$
|
||||
.calledWith(userId)
|
||||
|
||||
@@ -35,7 +35,7 @@ import { Environment, EnvironmentService } from "../../abstractions/environment.
|
||||
import { PlatformUtilsService } from "../../abstractions/platform-utils.service";
|
||||
import { SdkClientFactory } from "../../abstractions/sdk/sdk-client-factory";
|
||||
import { SdkLoadService } from "../../abstractions/sdk/sdk-load.service";
|
||||
import { SdkService, UserNotLoggedInError } from "../../abstractions/sdk/sdk.service";
|
||||
import { asUuid, SdkService, UserNotLoggedInError } from "../../abstractions/sdk/sdk.service";
|
||||
import { compareValues } from "../../misc/compare-values";
|
||||
import { Rc } from "../../misc/reference-counting/rc";
|
||||
import { StateProvider } from "../../state";
|
||||
@@ -218,7 +218,7 @@ export class DefaultSdkService implements SdkService {
|
||||
orgKeys: Record<OrganizationId, EncryptedOrganizationKeyData> | null,
|
||||
) {
|
||||
await client.crypto().initialize_user_crypto({
|
||||
userId,
|
||||
userId: asUuid(userId),
|
||||
email: account.email,
|
||||
method: { decryptedKey: { decrypted_user_key: userKey.keyB64 } },
|
||||
kdfParams:
|
||||
@@ -242,7 +242,7 @@ export class DefaultSdkService implements SdkService {
|
||||
organizationKeys: new Map(
|
||||
Object.entries(orgKeys ?? {})
|
||||
.filter(([_, v]) => v.type === "organization")
|
||||
.map(([k, v]) => [k, v.key as UnsignedSharedKey]),
|
||||
.map(([k, v]) => [asUuid(k), v.key as UnsignedSharedKey]),
|
||||
),
|
||||
});
|
||||
|
||||
|
||||
@@ -849,9 +849,9 @@ describe("Cipher DTO", () => {
|
||||
const lastLaunched = new Date("2025-04-15T12:00:00.000Z").getTime();
|
||||
|
||||
const cipherData: CipherData = {
|
||||
id: "id",
|
||||
organizationId: "orgId",
|
||||
folderId: "folderId",
|
||||
id: "2afb03fd-0d8e-4c08-a316-18b2f0efa618",
|
||||
organizationId: "4748ad12-212e-4bc8-82b7-a75f6709d033",
|
||||
folderId: "b4dac811-e44a-495a-9334-9e53b7aaf54c",
|
||||
edit: true,
|
||||
permissions: new CipherPermissionsApi(),
|
||||
viewPassword: true,
|
||||
@@ -920,9 +920,9 @@ describe("Cipher DTO", () => {
|
||||
const sdkCipher = cipher.toSdkCipher();
|
||||
|
||||
expect(sdkCipher).toEqual({
|
||||
id: "id",
|
||||
organizationId: "orgId",
|
||||
folderId: "folderId",
|
||||
id: "2afb03fd-0d8e-4c08-a316-18b2f0efa618",
|
||||
organizationId: "4748ad12-212e-4bc8-82b7-a75f6709d033",
|
||||
folderId: "b4dac811-e44a-495a-9334-9e53b7aaf54c",
|
||||
collectionIds: [],
|
||||
key: "EncryptedString",
|
||||
name: "EncryptedString",
|
||||
@@ -1007,9 +1007,9 @@ describe("Cipher DTO", () => {
|
||||
it("should map from SDK Cipher", () => {
|
||||
jest.restoreAllMocks();
|
||||
const sdkCipher: SdkCipher = {
|
||||
id: "id",
|
||||
organizationId: "orgId",
|
||||
folderId: "folderId",
|
||||
id: "id" as any,
|
||||
organizationId: "orgId" as any,
|
||||
folderId: "folderId" as any,
|
||||
collectionIds: [],
|
||||
key: "EncryptedString" as SdkEncString,
|
||||
name: "EncryptedString" as SdkEncString,
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
// @ts-strict-ignore
|
||||
import { Jsonify } from "type-fest";
|
||||
|
||||
import { uuidToString } from "@bitwarden/common/platform/abstractions/sdk/sdk.service";
|
||||
import { Cipher as SdkCipher } from "@bitwarden/sdk-internal";
|
||||
|
||||
import { EncString } from "../../../key-management/crypto/models/enc-string";
|
||||
import { asUuid, uuidAsString } from "../../../platform/abstractions/sdk/sdk.service";
|
||||
import { Decryptable } from "../../../platform/interfaces/decryptable.interface";
|
||||
import { Utils } from "../../../platform/misc/utils";
|
||||
import Domain from "../../../platform/models/domain/domain-base";
|
||||
@@ -344,10 +344,10 @@ export class Cipher extends Domain implements Decryptable<CipherView> {
|
||||
*/
|
||||
toSdkCipher(): SdkCipher {
|
||||
const sdkCipher: SdkCipher = {
|
||||
id: this.id,
|
||||
organizationId: this.organizationId ?? undefined,
|
||||
folderId: this.folderId ?? undefined,
|
||||
collectionIds: this.collectionIds ?? [],
|
||||
id: asUuid(this.id),
|
||||
organizationId: this.organizationId ? asUuid(this.organizationId) : undefined,
|
||||
folderId: this.folderId ? asUuid(this.folderId) : undefined,
|
||||
collectionIds: this.collectionIds ? this.collectionIds.map(asUuid) : ([] as any),
|
||||
key: this.key?.toSdk(),
|
||||
name: this.name.toSdk(),
|
||||
notes: this.notes?.toSdk(),
|
||||
@@ -412,12 +412,12 @@ export class Cipher extends Domain implements Decryptable<CipherView> {
|
||||
|
||||
const cipher = new Cipher();
|
||||
|
||||
cipher.id = sdkCipher.id ? uuidToString(sdkCipher.id) : undefined;
|
||||
cipher.id = sdkCipher.id ? uuidAsString(sdkCipher.id) : undefined;
|
||||
cipher.organizationId = sdkCipher.organizationId
|
||||
? uuidToString(sdkCipher.organizationId)
|
||||
? uuidAsString(sdkCipher.organizationId)
|
||||
: undefined;
|
||||
cipher.folderId = sdkCipher.folderId ? uuidToString(sdkCipher.folderId) : undefined;
|
||||
cipher.collectionIds = sdkCipher.collectionIds ? sdkCipher.collectionIds.map(uuidToString) : [];
|
||||
cipher.folderId = sdkCipher.folderId ? uuidAsString(sdkCipher.folderId) : undefined;
|
||||
cipher.collectionIds = sdkCipher.collectionIds ? sdkCipher.collectionIds.map(uuidAsString) : [];
|
||||
cipher.key = EncString.fromJSON(sdkCipher.key);
|
||||
cipher.name = EncString.fromJSON(sdkCipher.name);
|
||||
cipher.notes = EncString.fromJSON(sdkCipher.notes);
|
||||
|
||||
@@ -14,6 +14,7 @@ import {
|
||||
} from "@bitwarden/sdk-internal";
|
||||
|
||||
import { mockFromJson, mockFromSdk } from "../../../../spec";
|
||||
import { asUuid } from "../../../platform/abstractions/sdk/sdk.service";
|
||||
import { CipherRepromptType } from "../../enums";
|
||||
import { CipherType } from "../../enums/cipher-type";
|
||||
|
||||
@@ -123,10 +124,10 @@ describe("CipherView", () => {
|
||||
jest.spyOn(FieldView, "fromSdkFieldView").mockImplementation(mockFromSdk);
|
||||
|
||||
sdkCipherView = {
|
||||
id: "id",
|
||||
organizationId: "orgId",
|
||||
folderId: "folderId",
|
||||
collectionIds: ["collectionId"],
|
||||
id: "id" as any,
|
||||
organizationId: "orgId" as any,
|
||||
folderId: "folderId" as any,
|
||||
collectionIds: ["collectionId" as any],
|
||||
key: undefined,
|
||||
name: "name",
|
||||
notes: undefined,
|
||||
@@ -260,11 +261,11 @@ describe("CipherView", () => {
|
||||
const sdkCipherView = cipherView.toSdkCipherView();
|
||||
|
||||
expect(sdkCipherView).toMatchObject({
|
||||
id: "0a54d80c-14aa-4ef8-8c3a-7ea99ce5b602",
|
||||
organizationId: "000f2a6e-da5e-4726-87ed-1c5c77322c3c",
|
||||
folderId: "41b22db4-8e2a-4ed2-b568-f1186c72922f",
|
||||
collectionIds: ["b0473506-3c3c-4260-a734-dfaaf833ab6f"],
|
||||
key: "some-key",
|
||||
id: asUuid("0a54d80c-14aa-4ef8-8c3a-7ea99ce5b602"),
|
||||
organizationId: asUuid("000f2a6e-da5e-4726-87ed-1c5c77322c3c"),
|
||||
folderId: asUuid("41b22db4-8e2a-4ed2-b568-f1186c72922f"),
|
||||
collectionIds: [asUuid("b0473506-3c3c-4260-a734-dfaaf833ab6f")],
|
||||
key: "some-key" as any,
|
||||
name: "name",
|
||||
notes: "notes",
|
||||
type: SdkCipherType.Login,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// FIXME: Update this file to be type safe and remove this and next line
|
||||
// @ts-strict-ignore
|
||||
import { EncString } from "@bitwarden/common/key-management/crypto/models/enc-string";
|
||||
import { uuidToString, asUuid } from "@bitwarden/common/platform/abstractions/sdk/sdk.service";
|
||||
import { asUuid, uuidAsString } from "@bitwarden/common/platform/abstractions/sdk/sdk.service";
|
||||
import { CipherView as SdkCipherView } from "@bitwarden/sdk-internal";
|
||||
|
||||
import { View } from "../../../models/view/view";
|
||||
@@ -256,9 +256,9 @@ export class CipherView implements View, InitializerMetadata {
|
||||
}
|
||||
|
||||
const cipherView = new CipherView();
|
||||
cipherView.id = uuidToString(obj.id) ?? null;
|
||||
cipherView.organizationId = uuidToString(obj.organizationId) ?? null;
|
||||
cipherView.folderId = uuidToString(obj.folderId) ?? null;
|
||||
cipherView.id = uuidAsString(obj.id) ?? null;
|
||||
cipherView.organizationId = uuidAsString(obj.organizationId) ?? null;
|
||||
cipherView.folderId = uuidAsString(obj.folderId) ?? null;
|
||||
cipherView.name = obj.name;
|
||||
cipherView.notes = obj.notes ?? null;
|
||||
cipherView.type = obj.type;
|
||||
@@ -273,7 +273,7 @@ export class CipherView implements View, InitializerMetadata {
|
||||
cipherView.fields = obj.fields?.map((f) => FieldView.fromSdkFieldView(f)) ?? [];
|
||||
cipherView.passwordHistory =
|
||||
obj.passwordHistory?.map((ph) => PasswordHistoryView.fromSdkPasswordHistoryView(ph)) ?? [];
|
||||
cipherView.collectionIds = obj.collectionIds?.map((i) => uuidToString(i)) ?? [];
|
||||
cipherView.collectionIds = obj.collectionIds?.map((i) => uuidAsString(i)) ?? [];
|
||||
cipherView.revisionDate = obj.revisionDate == null ? null : new Date(obj.revisionDate);
|
||||
cipherView.creationDate = obj.creationDate == null ? null : new Date(obj.creationDate);
|
||||
cipherView.deletedDate = obj.deletedDate == null ? null : new Date(obj.deletedDate);
|
||||
@@ -325,7 +325,7 @@ export class CipherView implements View, InitializerMetadata {
|
||||
attachments: this.attachments?.map((a) => a.toSdkAttachmentView()),
|
||||
fields: this.fields?.map((f) => f.toSdkFieldView()),
|
||||
passwordHistory: this.passwordHistory?.map((ph) => ph.toSdkPasswordHistoryView()),
|
||||
collectionIds: this.collectionIds?.map((i) => i) ?? [],
|
||||
collectionIds: this.collectionIds?.map((i) => asUuid(i)) ?? [],
|
||||
// Revision and creation dates are non-nullable in SDKCipherView
|
||||
revisionDate: (this.revisionDate ?? new Date()).toISOString(),
|
||||
creationDate: (this.creationDate ?? new Date()).toISOString(),
|
||||
|
||||
@@ -8,6 +8,7 @@ import { AccountService } from "@bitwarden/common/auth/abstractions/account.serv
|
||||
import { getByIds } from "@bitwarden/common/platform/misc";
|
||||
|
||||
import { getUserId } from "../../auth/services/account.service";
|
||||
import { uuidAsString } from "../../platform/abstractions/sdk/sdk.service";
|
||||
import { CipherLike } from "../types/cipher-like";
|
||||
|
||||
/**
|
||||
@@ -140,7 +141,7 @@ export class DefaultCipherAuthorizationService implements CipherAuthorizationSer
|
||||
}
|
||||
|
||||
return this.collectionService.decryptedCollections$(userId).pipe(
|
||||
getByIds(cipher.collectionIds),
|
||||
getByIds(cipher.collectionIds.map(uuidAsString)),
|
||||
map((allCollections) => allCollections.some((collection) => collection.manage)),
|
||||
);
|
||||
}),
|
||||
|
||||
@@ -31,6 +31,7 @@ import { ListResponse } from "../../models/response/list.response";
|
||||
import { View } from "../../models/view/view";
|
||||
import { ConfigService } from "../../platform/abstractions/config/config.service";
|
||||
import { I18nService } from "../../platform/abstractions/i18n.service";
|
||||
import { uuidAsString } from "../../platform/abstractions/sdk/sdk.service";
|
||||
import { Utils } from "../../platform/misc/utils";
|
||||
import Domain from "../../platform/models/domain/domain-base";
|
||||
import { EncArrayBuffer } from "../../platform/models/domain/enc-array-buffer";
|
||||
@@ -2035,7 +2036,7 @@ export class CipherService implements CipherServiceAbstraction {
|
||||
const activeUserId = await firstValueFrom(
|
||||
this.accountService.activeAccount$.pipe(map((a) => a?.id)),
|
||||
);
|
||||
const cipher = await this.get(c.id!, activeUserId);
|
||||
const cipher = await this.get(uuidAsString(c.id!), activeUserId);
|
||||
return this.decrypt(cipher, activeUserId);
|
||||
}
|
||||
|
||||
|
||||
@@ -124,15 +124,15 @@ describe("DefaultCipherEncryptionService", () => {
|
||||
cipherViewObj = new CipherView(cipherObj);
|
||||
|
||||
jest.spyOn(cipherObj, "toSdkCipher").mockImplementation(() => {
|
||||
return { id: cipherData.id } as SdkCipher;
|
||||
return { id: cipherData.id as any } as SdkCipher;
|
||||
});
|
||||
|
||||
jest.spyOn(cipherViewObj, "toSdkCipherView").mockImplementation(() => {
|
||||
return { id: cipherData.id } as SdkCipherView;
|
||||
return { id: cipherData.id as any } as SdkCipherView;
|
||||
});
|
||||
|
||||
sdkCipherView = {
|
||||
id: cipherId as string,
|
||||
id: cipherId as any,
|
||||
type: SdkCipherType.Login,
|
||||
name: "test-name",
|
||||
login: {
|
||||
@@ -334,7 +334,7 @@ describe("DefaultCipherEncryptionService", () => {
|
||||
.vault()
|
||||
.ciphers()
|
||||
.set_fido2_credentials.mockReturnValue({
|
||||
id: cipherId as string,
|
||||
id: cipherId as any,
|
||||
login: {
|
||||
fido2Credentials: [mockSdkCredentialView],
|
||||
},
|
||||
@@ -519,8 +519,8 @@ describe("DefaultCipherEncryptionService", () => {
|
||||
const ciphers = [new Cipher(cipherData), new Cipher(cipherData)];
|
||||
|
||||
const expectedListViews = [
|
||||
{ id: "list1", name: "List 1" } as CipherListView,
|
||||
{ id: "list2", name: "List 2" } as CipherListView,
|
||||
{ id: "list1" as any, name: "List 1" } as CipherListView,
|
||||
{ id: "list2" as any, name: "List 2" } as CipherListView,
|
||||
];
|
||||
|
||||
mockSdkClient.vault().ciphers().decrypt_list.mockReturnValue(expectedListViews);
|
||||
@@ -554,7 +554,7 @@ describe("DefaultCipherEncryptionService", () => {
|
||||
const encryptedContent = new Uint8Array([1, 2, 3, 4]);
|
||||
const expectedDecryptedContent = new Uint8Array([5, 6, 7, 8]);
|
||||
|
||||
jest.spyOn(cipher, "toSdkCipher").mockReturnValue({ id: "id" } as SdkCipher);
|
||||
jest.spyOn(cipher, "toSdkCipher").mockReturnValue({ id: "id" as any } as SdkCipher);
|
||||
jest
|
||||
.spyOn(attachment, "toSdkAttachmentView")
|
||||
.mockReturnValue({ id: "a1" } as SdkAttachmentView);
|
||||
|
||||
@@ -9,7 +9,7 @@ import {
|
||||
} from "@bitwarden/sdk-internal";
|
||||
|
||||
import { LogService } from "../../platform/abstractions/log.service";
|
||||
import { SdkService, asUuid } from "../../platform/abstractions/sdk/sdk.service";
|
||||
import { SdkService, asUuid, uuidAsString } from "../../platform/abstractions/sdk/sdk.service";
|
||||
import { UserId, OrganizationId } from "../../types/guid";
|
||||
import { CipherEncryptionService } from "../abstractions/cipher-encryption.service";
|
||||
import { CipherType } from "../enums";
|
||||
@@ -39,7 +39,7 @@ export class DefaultCipherEncryptionService implements CipherEncryptionService {
|
||||
|
||||
return {
|
||||
cipher: Cipher.fromSdkCipher(encryptionContext.cipher)!,
|
||||
encryptedFor: asUuid<UserId>(encryptionContext.encryptedFor),
|
||||
encryptedFor: uuidAsString(encryptionContext.encryptedFor) as UserId,
|
||||
};
|
||||
}),
|
||||
catchError((error: unknown) => {
|
||||
@@ -74,7 +74,7 @@ export class DefaultCipherEncryptionService implements CipherEncryptionService {
|
||||
|
||||
return {
|
||||
cipher: Cipher.fromSdkCipher(encryptionContext.cipher)!,
|
||||
encryptedFor: asUuid<UserId>(encryptionContext.encryptedFor),
|
||||
encryptedFor: uuidAsString(encryptionContext.encryptedFor) as UserId,
|
||||
};
|
||||
}),
|
||||
catchError((error: unknown) => {
|
||||
@@ -107,7 +107,7 @@ export class DefaultCipherEncryptionService implements CipherEncryptionService {
|
||||
|
||||
return {
|
||||
cipher: Cipher.fromSdkCipher(encryptionContext.cipher)!,
|
||||
encryptedFor: asUuid<UserId>(encryptionContext.encryptedFor),
|
||||
encryptedFor: uuidAsString(encryptionContext.encryptedFor) as UserId,
|
||||
};
|
||||
}),
|
||||
catchError((error: unknown) => {
|
||||
|
||||
@@ -10,6 +10,7 @@ import { FeatureFlag } from "@bitwarden/common/enums/feature-flag.enum";
|
||||
import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service";
|
||||
import { CipherType } from "@bitwarden/common/vault/enums";
|
||||
|
||||
import { uuidAsString } from "../../platform/abstractions/sdk/sdk.service";
|
||||
import { CipherLike } from "../types/cipher-like";
|
||||
import { CipherViewLikeUtils } from "../utils/cipher-view-like-utils";
|
||||
|
||||
@@ -108,7 +109,7 @@ export class RestrictedItemTypesService {
|
||||
// If cipher belongs to an organization
|
||||
if (cipher.organizationId) {
|
||||
// Check if this organization allows viewing this cipher type
|
||||
return !restriction.allowViewOrgIds.includes(cipher.organizationId);
|
||||
return !restriction.allowViewOrgIds.includes(uuidAsString(cipher.organizationId));
|
||||
}
|
||||
|
||||
// Cipher is restricted by at least one organization, restrict it
|
||||
|
||||
@@ -9,6 +9,7 @@ import { perUserCache$ } from "@bitwarden/common/vault/utils/observable-utilitie
|
||||
import { UriMatchStrategy } from "../../models/domain/domain-service";
|
||||
import { I18nService } from "../../platform/abstractions/i18n.service";
|
||||
import { LogService } from "../../platform/abstractions/log.service";
|
||||
import { uuidAsString } from "../../platform/abstractions/sdk/sdk.service";
|
||||
import {
|
||||
SingleUserState,
|
||||
StateProvider,
|
||||
@@ -261,7 +262,7 @@ export class SearchService implements SearchServiceAbstraction {
|
||||
}
|
||||
|
||||
const ciphersMap = new Map<string, C>();
|
||||
ciphers.forEach((c) => ciphersMap.set(c.id, c));
|
||||
ciphers.forEach((c) => ciphersMap.set(uuidAsString(c.id), c));
|
||||
|
||||
let searchResults: lunr.Index.Result[] = null;
|
||||
const isQueryString = query != null && query.length > 1 && query.indexOf(">") === 0;
|
||||
@@ -304,7 +305,7 @@ export class SearchService implements SearchServiceAbstraction {
|
||||
if (c.name != null && c.name.toLowerCase().indexOf(query) > -1) {
|
||||
return true;
|
||||
}
|
||||
if (query.length >= 8 && c.id.startsWith(query)) {
|
||||
if (query.length >= 8 && uuidAsString(c.id).startsWith(query)) {
|
||||
return true;
|
||||
}
|
||||
const subtitle = CipherViewLikeUtils.subtitle(c);
|
||||
|
||||
@@ -175,13 +175,13 @@ describe("CipherViewLikeUtils", () => {
|
||||
});
|
||||
|
||||
it("returns false when the cipher is assigned to an organization and cannot be edited", () => {
|
||||
cipherListView.organizationId = "org-id";
|
||||
cipherListView.organizationId = "org-id" as any;
|
||||
|
||||
expect(CipherViewLikeUtils.canAssignToCollections(cipherListView)).toBe(false);
|
||||
});
|
||||
|
||||
it("returns true when the cipher is assigned to an organization and can be edited", () => {
|
||||
cipherListView.organizationId = "org-id";
|
||||
cipherListView.organizationId = "org-id" as any;
|
||||
cipherListView.edit = true;
|
||||
cipherListView.viewPassword = true;
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ import { firstValueFrom } from "rxjs";
|
||||
|
||||
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
|
||||
import { getUserId } from "@bitwarden/common/auth/services/account.service";
|
||||
import { uuidAsString } from "@bitwarden/common/platform/abstractions/sdk/sdk.service";
|
||||
import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service";
|
||||
import { CipherView } from "@bitwarden/common/vault/models/view/cipher.view";
|
||||
import {
|
||||
@@ -100,7 +101,10 @@ export class CopyCipherFieldDirective implements OnChanges {
|
||||
const activeAccountId = await firstValueFrom(
|
||||
this.accountService.activeAccount$.pipe(getUserId),
|
||||
);
|
||||
const encryptedCipher = await this.cipherService.get(this.cipher.id!, activeAccountId);
|
||||
const encryptedCipher = await this.cipherService.get(
|
||||
uuidAsString(this.cipher.id!),
|
||||
activeAccountId,
|
||||
);
|
||||
_cipher = await this.cipherService.decrypt(encryptedCipher, activeAccountId);
|
||||
} else {
|
||||
_cipher = this.cipher;
|
||||
|
||||
@@ -7,6 +7,7 @@ import { BillingAccountProfileStateService } from "@bitwarden/common/billing/abs
|
||||
import { EventType } from "@bitwarden/common/enums";
|
||||
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
||||
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
|
||||
import { uuidAsString } from "@bitwarden/common/platform/abstractions/sdk/sdk.service";
|
||||
import { TotpService } from "@bitwarden/common/vault/abstractions/totp.service";
|
||||
import { CipherRepromptType } from "@bitwarden/common/vault/enums";
|
||||
import {
|
||||
@@ -144,9 +145,9 @@ export class CopyCipherFieldService {
|
||||
if (action.event !== undefined) {
|
||||
await this.eventCollectionService.collect(
|
||||
action.event,
|
||||
cipher.id,
|
||||
uuidAsString(cipher.id),
|
||||
false,
|
||||
cipher.organizationId,
|
||||
uuidAsString(cipher.organizationId),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
8
package-lock.json
generated
8
package-lock.json
generated
@@ -23,7 +23,7 @@
|
||||
"@angular/platform-browser": "19.2.14",
|
||||
"@angular/platform-browser-dynamic": "19.2.14",
|
||||
"@angular/router": "19.2.14",
|
||||
"@bitwarden/sdk-internal": "0.2.0-main.242",
|
||||
"@bitwarden/sdk-internal": "0.2.0-main.266",
|
||||
"@electron/fuses": "1.8.0",
|
||||
"@emotion/css": "11.13.5",
|
||||
"@koa/multer": "4.0.0",
|
||||
@@ -4682,9 +4682,9 @@
|
||||
"link": true
|
||||
},
|
||||
"node_modules/@bitwarden/sdk-internal": {
|
||||
"version": "0.2.0-main.242",
|
||||
"resolved": "https://registry.npmjs.org/@bitwarden/sdk-internal/-/sdk-internal-0.2.0-main.242.tgz",
|
||||
"integrity": "sha512-LFPNAAq9ORVGdvcB3PBhlM3GQZUMf3MhIuYbZxmhAG5SVlvem+sbaolgK3Fnf/8ajVx1IDMNEhfgQkA4mU9uAg==",
|
||||
"version": "0.2.0-main.266",
|
||||
"resolved": "https://registry.npmjs.org/@bitwarden/sdk-internal/-/sdk-internal-0.2.0-main.266.tgz",
|
||||
"integrity": "sha512-2Axa1D9AEkax2ssqahZYHVkk2RdguzLV2bJ6j99AZhh4qjGIYtDvmc5gDh7zhuw7Ig7H3mNpKwCZ/eJgadyH6g==",
|
||||
"license": "GPL-3.0",
|
||||
"dependencies": {
|
||||
"type-fest": "^4.41.0"
|
||||
|
||||
@@ -158,7 +158,7 @@
|
||||
"@angular/platform-browser": "19.2.14",
|
||||
"@angular/platform-browser-dynamic": "19.2.14",
|
||||
"@angular/router": "19.2.14",
|
||||
"@bitwarden/sdk-internal": "0.2.0-main.242",
|
||||
"@bitwarden/sdk-internal": "0.2.0-main.266",
|
||||
"@electron/fuses": "1.8.0",
|
||||
"@emotion/css": "11.13.5",
|
||||
"@koa/multer": "4.0.0",
|
||||
|
||||
Reference in New Issue
Block a user