mirror of
https://github.com/bitwarden/browser
synced 2025-12-19 17:53:39 +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:
@@ -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(),
|
||||
|
||||
Reference in New Issue
Block a user