From 8c5f90e124bb0d07e60b11edeff60a6a37c9026d Mon Sep 17 00:00:00 2001 From: Nik Gilmore Date: Wed, 7 Jan 2026 15:52:10 -0800 Subject: [PATCH] Add softDeleteWithServer and softDeleteManyWithServer impl using SDK --- .../src/vault/services/cipher.service.ts | 61 ++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) diff --git a/libs/common/src/vault/services/cipher.service.ts b/libs/common/src/vault/services/cipher.service.ts index b99d2b2e45a..d116a68e357 100644 --- a/libs/common/src/vault/services/cipher.service.ts +++ b/libs/common/src/vault/services/cipher.service.ts @@ -1481,7 +1481,7 @@ export class CipherService implements CipherServiceAbstraction { .delete_many( ids.map((id) => asUuid(id)), null, // TODO: This is required in the SDK - need to remove from SDK or require here - // But how did it work before????? The server also throws a 404. + // But how did it work before????? The server also throws a 404 if not provided.... ); } else { await ref.value @@ -1654,6 +1654,13 @@ export class CipherService implements CipherServiceAbstraction { } async softDeleteWithServer(id: string, userId: UserId, asAdmin = false): Promise { + const useSdk = await this.configService.getFeatureFlag( + FeatureFlag.PM27632_SdkCipherCrudOperations, + ); + if (useSdk) { + return this.softDeleteWithServer_sdk(id, userId, asAdmin); + } + if (asAdmin) { await this.apiService.putDeleteCipherAdmin(id); } else { @@ -1663,7 +1670,31 @@ export class CipherService implements CipherServiceAbstraction { await this.softDelete(id, userId); } + async softDeleteWithServer_sdk(id: string, userId: UserId, asAdmin = false): Promise { + this.sdkService.userClient$(userId).pipe( + map(async (sdk) => { + if (!sdk) { + throw new Error("SDK not available"); + } + using ref = sdk.take(); + if (asAdmin) { + await ref.value.vault().ciphers().admin().soft_delete(asUuid(id)); + } else { + await ref.value.vault().ciphers().soft_delete(asUuid(id)); + } + }), + ); + await this.clearCache(userId); + } + async softDeleteManyWithServer(ids: string[], userId: UserId, asAdmin = false): Promise { + const useSdk = await this.configService.getFeatureFlag( + FeatureFlag.PM27632_SdkCipherCrudOperations, + ); + if (useSdk) { + return this.softDeleteManyWithServer_sdk(ids, userId, asAdmin); + } + const request = new CipherBulkDeleteRequest(ids); if (asAdmin) { await this.apiService.putDeleteManyCiphersAdmin(request); @@ -1674,6 +1705,34 @@ export class CipherService implements CipherServiceAbstraction { await this.softDelete(ids, userId); } + async softDeleteManyWithServer_sdk(ids: string[], userId: UserId, asAdmin = false): Promise { + this.sdkService.userClient$(userId).pipe( + map(async (sdk) => { + if (!sdk) { + throw new Error("SDK not available"); + } + using ref = sdk.take(); + if (asAdmin) { + await ref.value + .vault() + .ciphers() + .admin() + .soft_delete_many( + ids.map((id) => asUuid(id)), + null, // TODO: This is required in the SDK - need to remove from SDK or require here + // But how did it work before????? The server also throws a 404 if not provided.... + ); + } else { + await ref.value + .vault() + .ciphers() + .soft_delete_many(ids.map((id) => asUuid(id))); + } + }), + ); + await this.clearCache(userId); + } + async restore( cipher: { id: string; revisionDate: string } | { id: string; revisionDate: string }[], userId: UserId,