From ea89b501ba8a2a61ec9dbcb8853aa4f7d53776e3 Mon Sep 17 00:00:00 2001 From: Nicolas Chaulet Date: Thu, 31 Oct 2024 11:43:47 -0400 Subject: [PATCH] fix types --- .../fleet/server/services/epm/packages/remove.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/x-pack/plugins/fleet/server/services/epm/packages/remove.ts b/x-pack/plugins/fleet/server/services/epm/packages/remove.ts index ac3f5def5d09c..396ba430ceacb 100644 --- a/x-pack/plugins/fleet/server/services/epm/packages/remove.ts +++ b/x-pack/plugins/fleet/server/services/epm/packages/remove.ts @@ -57,14 +57,18 @@ const MAX_ASSETS_TO_DELETE = 1000; export async function removeInstallation(options: { savedObjectsClient: SavedObjectsClientContract; pkgName: string; - pkgVersion: string; + pkgVersion?: string; esClient: ElasticsearchClient; force?: boolean; }): Promise { const { savedObjectsClient, pkgName, pkgVersion, esClient } = options; const installation = await getInstallation({ savedObjectsClient, pkgName }); - if (!installation) throw new PackageRemovalError(`${pkgName} is not installed`); - + if (!installation) { + throw new PackageRemovalError(`${pkgName} is not installed`); + } + if (pkgVersion && installation.version !== pkgVersion) { + throw new PackageRemovalError(`${pkgName} ${pkgVersion} is not installed`); + } const { total, items } = await packagePolicyService.list( appContextService.getInternalUserSOClientWithoutSpaceExtension(), { @@ -115,7 +119,7 @@ export async function removeInstallation(options: { // a fresh copy from the registry deletePackageCache({ name: pkgName, - version: pkgVersion, + version: installation.version, }); await removeArchiveEntries({ savedObjectsClient, refs: installation.package_assets });