diff --git a/x-pack/plugins/ingest_manager/common/constants/epm.ts b/x-pack/plugins/ingest_manager/common/constants/epm.ts index 571580e81258f..a2ce7703de039 100644 --- a/x-pack/plugins/ingest_manager/common/constants/epm.ts +++ b/x-pack/plugins/ingest_manager/common/constants/epm.ts @@ -8,3 +8,8 @@ export const PACKAGES_SAVED_OBJECT_TYPE = 'epm-packages'; export const INDEX_PATTERN_SAVED_OBJECT_TYPE = 'index-pattern'; export const INDEX_PATTERN_PLACEHOLDER_SUFFIX = '-index_pattern_placeholder'; export const MAX_TIME_COMPLETE_INSTALL = 60000; + +export const requiredPackages = { + System: 'system', + Endpoint: 'endpoint', +} as const; diff --git a/x-pack/plugins/ingest_manager/common/types/index.ts b/x-pack/plugins/ingest_manager/common/types/index.ts index e9271c24456b5..ba76194b1d9b9 100644 --- a/x-pack/plugins/ingest_manager/common/types/index.ts +++ b/x-pack/plugins/ingest_manager/common/types/index.ts @@ -34,3 +34,8 @@ export interface IngestManagerConfigType { // and https://github.com/Microsoft/TypeScript/pull/12253#issuecomment-263132208 // and https://github.com/Microsoft/TypeScript/issues/21826#issuecomment-479851685 export const entries = Object.entries as (o: T) => Array<[keyof T, T[keyof T]]>; + +/** + * Creates a Union Type for all the values of an object + */ +export type ValueOf = T[keyof T]; diff --git a/x-pack/plugins/ingest_manager/common/types/models/epm.ts b/x-pack/plugins/ingest_manager/common/types/models/epm.ts index 2ec9d7be6c882..cd6b9059fa091 100644 --- a/x-pack/plugins/ingest_manager/common/types/models/epm.ts +++ b/x-pack/plugins/ingest_manager/common/types/models/epm.ts @@ -7,6 +7,7 @@ // Follow pattern from https://github.com/elastic/kibana/pull/52447 // TODO: Update when https://github.com/elastic/kibana/issues/53021 is closed import { SavedObject, SavedObjectAttributes, SavedObjectReference } from 'src/core/public'; +import { requiredPackages } from '../../constants'; export enum InstallationStatus { installed = 'installed', @@ -277,6 +278,8 @@ export type EsAssetReference = Pick & { type: ElasticsearchAssetType; }; +export type RequiredPackage = typeof requiredPackages; + export enum DefaultPackages { system = 'system', endpoint = 'endpoint', diff --git a/x-pack/plugins/ingest_manager/server/services/epm/packages/index.ts b/x-pack/plugins/ingest_manager/server/services/epm/packages/index.ts index 92070f3c2fafc..15c45e7449fec 100644 --- a/x-pack/plugins/ingest_manager/server/services/epm/packages/index.ts +++ b/x-pack/plugins/ingest_manager/server/services/epm/packages/index.ts @@ -5,6 +5,7 @@ */ import { SavedObject } from 'src/core/server'; +import { RequiredPackage, requiredPackages, ValueOf } from '../../../../common'; import { AssetType, Installable, @@ -35,14 +36,8 @@ export { } from './install'; export { removeInstallation } from './remove'; -type RequiredPackage = 'system' | 'endpoint'; -const requiredPackages: Record = { - system: true, - endpoint: true, -}; - -export function isRequiredPackage(value: string): value is RequiredPackage { - return value in requiredPackages; +export function isRequiredPackage(value: string): value is ValueOf { + return Object.values(requiredPackages).some((required) => value === required); } export class PackageNotInstalledError extends Error {