diff --git a/x-pack/plugins/osquery/server/routes/saved_query/read_saved_query_route.ts b/x-pack/plugins/osquery/server/routes/saved_query/read_saved_query_route.ts index 684b9c12cee1a..d1627d220682a 100644 --- a/x-pack/plugins/osquery/server/routes/saved_query/read_saved_query_route.ts +++ b/x-pack/plugins/osquery/server/routes/saved_query/read_saved_query_route.ts @@ -33,8 +33,6 @@ export const readSavedQueryRoute = (router: IRouter, osqueryContext: OsqueryAppC prebuilt: boolean; }>(savedQuerySavedObjectType, request.params.id); - const isPrebuilt: boolean = await isSavedQueryPrebuilt(osqueryContext, savedQuery.id); - if (savedQuery.attributes.ecs_mapping) { // @ts-expect-error update types savedQuery.attributes.ecs_mapping = convertECSMappingToObject( @@ -42,7 +40,7 @@ export const readSavedQueryRoute = (router: IRouter, osqueryContext: OsqueryAppC ); } - savedQuery.attributes.prebuilt = isPrebuilt; + savedQuery.attributes.prebuilt = await isSavedQueryPrebuilt(osqueryContext, savedQuery.id); return response.ok({ body: savedQuery, diff --git a/x-pack/plugins/osquery/server/routes/saved_query/utils.ts b/x-pack/plugins/osquery/server/routes/saved_query/utils.ts index dcbabaa70257b..d99d5b70f0dab 100644 --- a/x-pack/plugins/osquery/server/routes/saved_query/utils.ts +++ b/x-pack/plugins/osquery/server/routes/saved_query/utils.ts @@ -5,7 +5,9 @@ * 2.0. */ -import { find, mapKeys } from 'lodash'; +import { find, reduce } from 'lodash'; +import { KibanaAssetReference } from '@kbn/fleet-plugin/common'; + import { OSQUERY_INTEGRATION_NAME } from '../../../common'; import { savedQuerySavedObjectType } from '../../../common/types'; import { OsqueryAppContext } from '../../lib/osquery_app_context_services'; @@ -18,11 +20,16 @@ const getInstallation = async (osqueryContext: OsqueryAppContext) => export const getInstalledSavedQueriesMap = async (osqueryContext: OsqueryAppContext) => { const installation = await getInstallation(osqueryContext); if (installation) { - return mapKeys(installation.installed_kibana, (value) => { - if (value.type === savedQuerySavedObjectType) { - return value.id; - } - }); + return reduce( + installation.installed_kibana, + // @ts-expect-error not sure why it shouts, but still it's properly typed + (acc: Record, item: KibanaAssetReference) => { + if (item.type === savedQuerySavedObjectType) { + return { ...acc, [item.id]: item }; + } + }, + {} + ); } return {};