diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/index/get_index_aliases.ts b/packages/kbn-securitysolution-es-utils/src/get_index_aliases/index.ts similarity index 80% rename from x-pack/plugins/security_solution/server/lib/detection_engine/index/get_index_aliases.ts rename to packages/kbn-securitysolution-es-utils/src/get_index_aliases/index.ts index d9e90cccc20a..885103c1fb58 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/index/get_index_aliases.ts +++ b/packages/kbn-securitysolution-es-utils/src/get_index_aliases/index.ts @@ -1,11 +1,12 @@ /* * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. */ -import { ElasticsearchClient } from 'src/core/server'; +import { ElasticsearchClient } from '../elasticsearch_client'; interface AliasesResponse { [indexName: string]: { diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/index/get_index_count.ts b/packages/kbn-securitysolution-es-utils/src/get_index_count/index.ts similarity index 71% rename from x-pack/plugins/security_solution/server/lib/detection_engine/index/get_index_count.ts rename to packages/kbn-securitysolution-es-utils/src/get_index_count/index.ts index f45ef0a9ff59..523b41303a56 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/index/get_index_count.ts +++ b/packages/kbn-securitysolution-es-utils/src/get_index_count/index.ts @@ -1,11 +1,12 @@ /* * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. */ -import { ElasticsearchClient } from 'src/core/server'; +import { ElasticsearchClient } from '../elasticsearch_client'; /** * Retrieves the count of documents in a given index diff --git a/packages/kbn-securitysolution-es-utils/src/index.ts b/packages/kbn-securitysolution-es-utils/src/index.ts index 657a63eef15c..cfa6820e9aac 100644 --- a/packages/kbn-securitysolution-es-utils/src/index.ts +++ b/packages/kbn-securitysolution-es-utils/src/index.ts @@ -12,9 +12,12 @@ export * from './delete_all_index'; export * from './delete_policy'; export * from './delete_template'; export * from './elasticsearch_client'; +export * from './get_index_aliases'; +export * from './get_index_count'; export * from './get_index_exists'; export * from './get_policy_exists'; export * from './get_template_exists'; +export * from './read_index'; export * from './read_privileges'; export * from './set_policy'; export * from './set_template'; diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/index/read_index.ts b/packages/kbn-securitysolution-es-utils/src/read_index/index.ts similarity index 55% rename from x-pack/plugins/security_solution/server/lib/detection_engine/index/read_index.ts rename to packages/kbn-securitysolution-es-utils/src/read_index/index.ts index 7674ca3b4830..cc16645120b7 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/index/read_index.ts +++ b/packages/kbn-securitysolution-es-utils/src/read_index/index.ts @@ -1,11 +1,12 @@ /* * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. */ -import { ElasticsearchClient } from 'kibana/server'; +import { ElasticsearchClient } from '../elasticsearch_client'; export const readIndex = async (esClient: ElasticsearchClient, index: string): Promise => { return esClient.indices.get({ diff --git a/packages/kbn-securitysolution-io-ts-alerting-types/src/from/index.ts b/packages/kbn-securitysolution-io-ts-alerting-types/src/from/index.ts index 3bf4592a581f..37ed4b2daa51 100644 --- a/packages/kbn-securitysolution-io-ts-alerting-types/src/from/index.ts +++ b/packages/kbn-securitysolution-io-ts-alerting-types/src/from/index.ts @@ -24,3 +24,6 @@ export const from = new t.Type( t.identity ); export type From = t.TypeOf; + +export const fromOrUndefined = t.union([from, t.undefined]); +export type FromOrUndefined = t.TypeOf; diff --git a/packages/kbn-securitysolution-io-ts-alerting-types/src/index.ts b/packages/kbn-securitysolution-io-ts-alerting-types/src/index.ts index 639140be049f..c6f29862206e 100644 --- a/packages/kbn-securitysolution-io-ts-alerting-types/src/index.ts +++ b/packages/kbn-securitysolution-io-ts-alerting-types/src/index.ts @@ -24,6 +24,7 @@ export * from './default_to_string'; export * from './default_uuid'; export * from './from'; export * from './language'; +export * from './machine_learning_job_id'; export * from './max_signals'; export * from './normalized_ml_job_id'; export * from './references_default_array'; @@ -38,3 +39,4 @@ export * from './threat_subtechnique'; export * from './threat_tactic'; export * from './threat_technique'; export * from './throttle'; +export * from './type'; diff --git a/packages/kbn-securitysolution-io-ts-alerting-types/src/language/index.ts b/packages/kbn-securitysolution-io-ts-alerting-types/src/language/index.ts index fc3f70f1f2d8..0632f09e6a39 100644 --- a/packages/kbn-securitysolution-io-ts-alerting-types/src/language/index.ts +++ b/packages/kbn-securitysolution-io-ts-alerting-types/src/language/index.ts @@ -10,3 +10,6 @@ import * as t from 'io-ts'; export const language = t.keyof({ eql: null, kuery: null, lucene: null }); export type Language = t.TypeOf; + +export const languageOrUndefined = t.union([language, t.undefined]); +export type LanguageOrUndefined = t.TypeOf; diff --git a/packages/kbn-securitysolution-io-ts-alerting-types/src/machine_learning_job_id/index.ts b/packages/kbn-securitysolution-io-ts-alerting-types/src/machine_learning_job_id/index.ts new file mode 100644 index 000000000000..9e9c25c62b93 --- /dev/null +++ b/packages/kbn-securitysolution-io-ts-alerting-types/src/machine_learning_job_id/index.ts @@ -0,0 +1,19 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +/* eslint-disable @typescript-eslint/naming-convention */ + +import * as t from 'io-ts'; + +import { machine_learning_job_id_normalized } from '../normalized_ml_job_id'; + +export const machine_learning_job_id = t.union([t.string, machine_learning_job_id_normalized]); +export type MachineLearningJobId = t.TypeOf; + +export const machineLearningJobIdOrUndefined = t.union([machine_learning_job_id, t.undefined]); +export type MachineLearningJobIdOrUndefined = t.TypeOf; diff --git a/packages/kbn-securitysolution-io-ts-alerting-types/src/max_signals/index.ts b/packages/kbn-securitysolution-io-ts-alerting-types/src/max_signals/index.ts index 83360234c65a..ef7a225d9373 100644 --- a/packages/kbn-securitysolution-io-ts-alerting-types/src/max_signals/index.ts +++ b/packages/kbn-securitysolution-io-ts-alerting-types/src/max_signals/index.ts @@ -13,3 +13,6 @@ import { PositiveIntegerGreaterThanZero } from '@kbn/securitysolution-io-ts-type export const max_signals = PositiveIntegerGreaterThanZero; export type MaxSignals = t.TypeOf; + +export const maxSignalsOrUndefined = t.union([max_signals, t.undefined]); +export type MaxSignalsOrUndefined = t.TypeOf; diff --git a/packages/kbn-securitysolution-io-ts-alerting-types/src/risk_score/index.ts b/packages/kbn-securitysolution-io-ts-alerting-types/src/risk_score/index.ts index 0aca7dd70ba1..98b9c33e7e3e 100644 --- a/packages/kbn-securitysolution-io-ts-alerting-types/src/risk_score/index.ts +++ b/packages/kbn-securitysolution-io-ts-alerting-types/src/risk_score/index.ts @@ -6,6 +6,8 @@ * Side Public License, v 1. */ +/* eslint-disable @typescript-eslint/naming-convention */ + import * as t from 'io-ts'; import { Either } from 'fp-ts/lib/Either'; @@ -26,3 +28,9 @@ export const RiskScore = new t.Type( ); export type RiskScoreC = typeof RiskScore; + +export const risk_score = RiskScore; +export type RiskScore = t.TypeOf; + +export const riskScoreOrUndefined = t.union([risk_score, t.undefined]); +export type RiskScoreOrUndefined = t.TypeOf; diff --git a/packages/kbn-securitysolution-io-ts-alerting-types/src/risk_score_mapping/index.ts b/packages/kbn-securitysolution-io-ts-alerting-types/src/risk_score_mapping/index.ts index b35b502811ec..be07bab64f46 100644 --- a/packages/kbn-securitysolution-io-ts-alerting-types/src/risk_score_mapping/index.ts +++ b/packages/kbn-securitysolution-io-ts-alerting-types/src/risk_score_mapping/index.ts @@ -10,10 +10,7 @@ import * as t from 'io-ts'; import { operator } from '@kbn/securitysolution-io-ts-types'; -import { RiskScore } from '../risk_score'; - -export const riskScoreOrUndefined = t.union([RiskScore, t.undefined]); -export type RiskScoreOrUndefined = t.TypeOf; +import { riskScoreOrUndefined } from '../risk_score'; export const risk_score_mapping_field = t.string; export const risk_score_mapping_value = t.string; @@ -28,3 +25,6 @@ export const risk_score_mapping_item = t.exact( export const risk_score_mapping = t.array(risk_score_mapping_item); export type RiskScoreMapping = t.TypeOf; + +export const riskScoreMappingOrUndefined = t.union([risk_score_mapping, t.undefined]); +export type RiskScoreMappingOrUndefined = t.TypeOf; diff --git a/packages/kbn-securitysolution-io-ts-alerting-types/src/threat/index.ts b/packages/kbn-securitysolution-io-ts-alerting-types/src/threat/index.ts index 0e4022e3ec26..08ff6cca60a4 100644 --- a/packages/kbn-securitysolution-io-ts-alerting-types/src/threat/index.ts +++ b/packages/kbn-securitysolution-io-ts-alerting-types/src/threat/index.ts @@ -32,3 +32,6 @@ export type Threat = t.TypeOf; export const threats = t.array(threat); export type Threats = t.TypeOf; + +export const threatsOrUndefined = t.union([threats, t.undefined]); +export type ThreatsOrUndefined = t.TypeOf; diff --git a/packages/kbn-securitysolution-io-ts-alerting-types/src/threat_subtechnique/index.ts b/packages/kbn-securitysolution-io-ts-alerting-types/src/threat_subtechnique/index.ts index 8d64f53cb162..4909b82d8ec5 100644 --- a/packages/kbn-securitysolution-io-ts-alerting-types/src/threat_subtechnique/index.ts +++ b/packages/kbn-securitysolution-io-ts-alerting-types/src/threat_subtechnique/index.ts @@ -21,3 +21,5 @@ export const threat_subtechnique = t.type({ }); export const threat_subtechniques = t.array(threat_subtechnique); + +export type ThreatSubtechnique = t.TypeOf; diff --git a/packages/kbn-securitysolution-io-ts-alerting-types/src/threat_technique/index.ts b/packages/kbn-securitysolution-io-ts-alerting-types/src/threat_technique/index.ts index ed2e771e1e11..2d56e842287d 100644 --- a/packages/kbn-securitysolution-io-ts-alerting-types/src/threat_technique/index.ts +++ b/packages/kbn-securitysolution-io-ts-alerting-types/src/threat_technique/index.ts @@ -30,3 +30,5 @@ export const threat_technique = t.intersection([ ), ]); export const threat_techniques = t.array(threat_technique); + +export type ThreatTechnique = t.TypeOf; diff --git a/packages/kbn-securitysolution-io-ts-alerting-types/src/type/index.ts b/packages/kbn-securitysolution-io-ts-alerting-types/src/type/index.ts new file mode 100644 index 000000000000..0e7403787899 --- /dev/null +++ b/packages/kbn-securitysolution-io-ts-alerting-types/src/type/index.ts @@ -0,0 +1,22 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0 and the Server Side Public License, v 1; you may not use this file except + * in compliance with, at your election, the Elastic License 2.0 or the Server + * Side Public License, v 1. + */ + +import * as t from 'io-ts'; + +export const type = t.keyof({ + eql: null, + machine_learning: null, + query: null, + saved_query: null, + threshold: null, + threat_match: null, +}); +export type Type = t.TypeOf; + +export const typeOrUndefined = t.union([type, t.undefined]); +export type TypeOrUndefined = t.TypeOf; diff --git a/packages/kbn-securitysolution-io-ts-list-types/src/index.ts b/packages/kbn-securitysolution-io-ts-list-types/src/index.ts index 1a1c1c331482..3c60df315e43 100644 --- a/packages/kbn-securitysolution-io-ts-list-types/src/index.ts +++ b/packages/kbn-securitysolution-io-ts-list-types/src/index.ts @@ -16,7 +16,6 @@ export * from './default_create_comments_array'; export * from './default_namespace'; export * from './default_namespace_array'; export * from './default_update_comments_array'; -export * from './default_version_number'; export * from './description'; export * from './endpoint'; export * from './entries'; @@ -43,4 +42,3 @@ export * from './type'; export * from './update_comment'; export * from './updated_at'; export * from './updated_by'; -export * from './version'; diff --git a/packages/kbn-securitysolution-io-ts-list-types/src/type/index.ts b/packages/kbn-securitysolution-io-ts-list-types/src/type/index.ts index 90a8c36eb8b3..50cacb8e0259 100644 --- a/packages/kbn-securitysolution-io-ts-list-types/src/type/index.ts +++ b/packages/kbn-securitysolution-io-ts-list-types/src/type/index.ts @@ -40,3 +40,4 @@ export const type = t.keyof({ export const typeOrUndefined = t.union([type, t.undefined]); export type Type = t.TypeOf; +export type TypeOrUndefined = t.TypeOf; diff --git a/packages/kbn-securitysolution-io-ts-list-types/src/default_version_number/index.test.ts b/packages/kbn-securitysolution-io-ts-types/src/default_version_number/index.test.ts similarity index 100% rename from packages/kbn-securitysolution-io-ts-list-types/src/default_version_number/index.test.ts rename to packages/kbn-securitysolution-io-ts-types/src/default_version_number/index.test.ts diff --git a/packages/kbn-securitysolution-io-ts-list-types/src/default_version_number/index.ts b/packages/kbn-securitysolution-io-ts-types/src/default_version_number/index.ts similarity index 100% rename from packages/kbn-securitysolution-io-ts-list-types/src/default_version_number/index.ts rename to packages/kbn-securitysolution-io-ts-types/src/default_version_number/index.ts diff --git a/packages/kbn-securitysolution-io-ts-types/src/index.ts b/packages/kbn-securitysolution-io-ts-types/src/index.ts index 8b5a4d9e4de9..fc0f017016e9 100644 --- a/packages/kbn-securitysolution-io-ts-types/src/index.ts +++ b/packages/kbn-securitysolution-io-ts-types/src/index.ts @@ -13,6 +13,7 @@ export * from './default_empty_string'; export * from './default_string_array'; export * from './default_string_boolean_false'; export * from './default_uuid'; +export * from './default_version_number'; export * from './empty_string_array'; export * from './iso_date_string'; export * from './non_empty_array'; @@ -26,3 +27,4 @@ export * from './positive_integer'; export * from './positive_integer_greater_than_zero'; export * from './string_to_positive_number'; export * from './uuid'; +export * from './version'; diff --git a/packages/kbn-securitysolution-io-ts-list-types/src/version/index.ts b/packages/kbn-securitysolution-io-ts-types/src/version/index.ts similarity index 78% rename from packages/kbn-securitysolution-io-ts-list-types/src/version/index.ts rename to packages/kbn-securitysolution-io-ts-types/src/version/index.ts index 97a81b546c84..245b64781a7f 100644 --- a/packages/kbn-securitysolution-io-ts-list-types/src/version/index.ts +++ b/packages/kbn-securitysolution-io-ts-types/src/version/index.ts @@ -7,7 +7,7 @@ */ import * as t from 'io-ts'; -import { PositiveIntegerGreaterThanZero } from '@kbn/securitysolution-io-ts-types'; +import { PositiveIntegerGreaterThanZero } from '../positive_integer_greater_than_zero'; /** * Note this is just a positive number, but we use it as a type here which is still ok. @@ -16,3 +16,6 @@ import { PositiveIntegerGreaterThanZero } from '@kbn/securitysolution-io-ts-type */ export const version = PositiveIntegerGreaterThanZero; export type Version = t.TypeOf; + +export const versionOrUndefined = t.union([version, t.undefined]); +export type VersionOrUndefined = t.TypeOf; diff --git a/x-pack/plugins/lists/common/exceptions/build_exceptions_filter.ts b/x-pack/plugins/lists/common/exceptions/build_exceptions_filter.ts index eda81f91cd98..6e76076bc63e 100644 --- a/x-pack/plugins/lists/common/exceptions/build_exceptions_filter.ts +++ b/x-pack/plugins/lists/common/exceptions/build_exceptions_filter.ts @@ -17,10 +17,10 @@ import { entriesNested, } from '@kbn/securitysolution-io-ts-list-types'; -import { Filter } from '../../../../../src/plugins/data/common'; -import { CreateExceptionListItemSchema, ExceptionListItemSchema } from '../schemas'; +import type { Filter } from '../../../../../src/plugins/data/common'; +import type { CreateExceptionListItemSchema, ExceptionListItemSchema } from '../schemas'; -import { BooleanFilter, NestedFilter } from './types'; +import type { BooleanFilter, NestedFilter } from './types'; import { hasLargeValueList } from './utils'; type NonListEntry = EntryMatch | EntryMatchAny | EntryNested | EntryExists; diff --git a/x-pack/plugins/lists/common/exceptions/utils.ts b/x-pack/plugins/lists/common/exceptions/utils.ts index f5881c1d3cbf..350cb581153b 100644 --- a/x-pack/plugins/lists/common/exceptions/utils.ts +++ b/x-pack/plugins/lists/common/exceptions/utils.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { EntriesArray } from '@kbn/securitysolution-io-ts-list-types'; +import type { EntriesArray } from '@kbn/securitysolution-io-ts-list-types'; export const hasLargeValueList = (entries: EntriesArray): boolean => { const found = entries.filter(({ type }) => type === 'list'); diff --git a/x-pack/plugins/lists/common/schemas/common/schemas.ts b/x-pack/plugins/lists/common/schemas/common/schemas.ts index 612b7ea559e4..83ec27d60b76 100644 --- a/x-pack/plugins/lists/common/schemas/common/schemas.ts +++ b/x-pack/plugins/lists/common/schemas/common/schemas.ts @@ -11,18 +11,6 @@ import * as t from 'io-ts'; import { NonEmptyString } from '@kbn/securitysolution-io-ts-types'; import { DefaultNamespace } from '@kbn/securitysolution-io-ts-list-types'; -/** - * @deprecated Directly use the type from the package and not from here - */ -export { - DefaultNamespace, - Type, - OsType, - OsTypeArray, - listOperator as operator, - NonEmptyEntriesArray, -} from '@kbn/securitysolution-io-ts-list-types'; - export const list_id = NonEmptyString; export type ListId = t.TypeOf; export const list_idOrUndefined = t.union([list_id, t.undefined]); @@ -91,12 +79,6 @@ export const _version = t.string; export const _versionOrUndefined = t.union([_version, t.undefined]); export type _VersionOrUndefined = t.TypeOf; -export const version = t.number; -export type Version = t.TypeOf; - -export const versionOrUndefined = t.union([version, t.undefined]); -export type VersionOrUndefined = t.TypeOf; - export const immutable = t.boolean; export type Immutable = t.TypeOf; diff --git a/x-pack/plugins/lists/common/schemas/request/create_exception_list_schema.ts b/x-pack/plugins/lists/common/schemas/request/create_exception_list_schema.ts index 91b3a98bdd5a..30e4ff908ee8 100644 --- a/x-pack/plugins/lists/common/schemas/request/create_exception_list_schema.ts +++ b/x-pack/plugins/lists/common/schemas/request/create_exception_list_schema.ts @@ -7,8 +7,6 @@ import * as t from 'io-ts'; import { - DefaultVersionNumber, - DefaultVersionNumberDecoded, NamespaceType, OsTypeArray, Tags, @@ -19,7 +17,11 @@ import { osTypeArrayOrUndefined, tags, } from '@kbn/securitysolution-io-ts-list-types'; -import { DefaultUuid } from '@kbn/securitysolution-io-ts-types'; +import { + DefaultUuid, + DefaultVersionNumber, + DefaultVersionNumberDecoded, +} from '@kbn/securitysolution-io-ts-types'; import { ListId, namespace_type } from '../common/schemas'; import { RequiredKeepUndefined } from '../../types'; diff --git a/x-pack/plugins/lists/common/schemas/request/create_list_schema.ts b/x-pack/plugins/lists/common/schemas/request/create_list_schema.ts index 5fa9da0cdc59..1c197a37c0cb 100644 --- a/x-pack/plugins/lists/common/schemas/request/create_list_schema.ts +++ b/x-pack/plugins/lists/common/schemas/request/create_list_schema.ts @@ -9,12 +9,8 @@ import * as t from 'io-ts'; import { DefaultVersionNumber, DefaultVersionNumberDecoded, - description, - id, - meta, - name, - type, -} from '@kbn/securitysolution-io-ts-list-types'; +} from '@kbn/securitysolution-io-ts-types'; +import { description, id, meta, name, type } from '@kbn/securitysolution-io-ts-list-types'; import { deserializer, serializer } from '../common/schemas'; import { RequiredKeepUndefined } from '../../types'; diff --git a/x-pack/plugins/lists/common/schemas/request/patch_list_schema.ts b/x-pack/plugins/lists/common/schemas/request/patch_list_schema.ts index eea4ba9fc87d..2cd41584ef9f 100644 --- a/x-pack/plugins/lists/common/schemas/request/patch_list_schema.ts +++ b/x-pack/plugins/lists/common/schemas/request/patch_list_schema.ts @@ -7,8 +7,9 @@ import * as t from 'io-ts'; import { description, id, meta, name } from '@kbn/securitysolution-io-ts-list-types'; +import { version } from '@kbn/securitysolution-io-ts-types'; -import { _version, version } from '../common/schemas'; +import { _version } from '../common/schemas'; import { RequiredKeepUndefined } from '../../types'; export const patchListSchema = t.intersection([ diff --git a/x-pack/plugins/lists/common/schemas/request/update_exception_list_schema.ts b/x-pack/plugins/lists/common/schemas/request/update_exception_list_schema.ts index c58c1c253a8c..08f15f52977f 100644 --- a/x-pack/plugins/lists/common/schemas/request/update_exception_list_schema.ts +++ b/x-pack/plugins/lists/common/schemas/request/update_exception_list_schema.ts @@ -18,8 +18,9 @@ import { osTypeArrayOrUndefined, tags, } from '@kbn/securitysolution-io-ts-list-types'; +import { version } from '@kbn/securitysolution-io-ts-types'; -import { _version, list_id, namespace_type, version } from '../common/schemas'; +import { _version, list_id, namespace_type } from '../common/schemas'; import { RequiredKeepUndefined } from '../../types'; export const updateExceptionListSchema = t.intersection([ diff --git a/x-pack/plugins/lists/common/schemas/request/update_list_schema.ts b/x-pack/plugins/lists/common/schemas/request/update_list_schema.ts index 230853e69fae..253c4cec566f 100644 --- a/x-pack/plugins/lists/common/schemas/request/update_list_schema.ts +++ b/x-pack/plugins/lists/common/schemas/request/update_list_schema.ts @@ -6,7 +6,8 @@ */ import * as t from 'io-ts'; -import { description, id, meta, name, version } from '@kbn/securitysolution-io-ts-list-types'; +import { description, id, meta, name } from '@kbn/securitysolution-io-ts-list-types'; +import { version } from '@kbn/securitysolution-io-ts-types'; import { _version } from '../common/schemas'; import { RequiredKeepUndefined } from '../../types'; diff --git a/x-pack/plugins/lists/common/schemas/response/exception_list_schema.ts b/x-pack/plugins/lists/common/schemas/response/exception_list_schema.ts index 7bfc2af9863e..f96496343fb7 100644 --- a/x-pack/plugins/lists/common/schemas/response/exception_list_schema.ts +++ b/x-pack/plugins/lists/common/schemas/response/exception_list_schema.ts @@ -19,6 +19,7 @@ import { updated_at, updated_by, } from '@kbn/securitysolution-io-ts-list-types'; +import { version } from '@kbn/securitysolution-io-ts-types'; import { _versionOrUndefined, @@ -26,7 +27,6 @@ import { list_id, namespace_type, tie_breaker_id, - version, } from '../common/schemas'; export const exceptionListSchema = t.exact( diff --git a/x-pack/plugins/lists/common/schemas/response/list_schema.ts b/x-pack/plugins/lists/common/schemas/response/list_schema.ts index 21504d64fdea..5b478cd25daa 100644 --- a/x-pack/plugins/lists/common/schemas/response/list_schema.ts +++ b/x-pack/plugins/lists/common/schemas/response/list_schema.ts @@ -17,6 +17,7 @@ import { updated_at, updated_by, } from '@kbn/securitysolution-io-ts-list-types'; +import { version } from '@kbn/securitysolution-io-ts-types'; import { _versionOrUndefined, @@ -24,7 +25,6 @@ import { immutable, serializerOrUndefined, tie_breaker_id, - version, } from '../common/schemas'; export const listSchema = t.exact( diff --git a/x-pack/plugins/lists/common/shared_exports.ts b/x-pack/plugins/lists/common/shared_exports.ts index f00afb7ac810..3f1dc01644e2 100644 --- a/x-pack/plugins/lists/common/shared_exports.ts +++ b/x-pack/plugins/lists/common/shared_exports.ts @@ -5,16 +5,13 @@ * 2.0. */ -export { +export type { ListSchema, ExceptionListSchema, ExceptionListItemSchema, CreateExceptionListSchema, CreateExceptionListItemSchema, UpdateExceptionListItemSchema, - exceptionListItemSchema, - createExceptionListItemSchema, - listSchema, } from './schemas'; export { buildExceptionFilter } from './exceptions'; diff --git a/x-pack/plugins/lists/public/exceptions/components/builder/exception_items_renderer.tsx b/x-pack/plugins/lists/public/exceptions/components/builder/exception_items_renderer.tsx index f771969a9202..6058d4f7b725 100644 --- a/x-pack/plugins/lists/public/exceptions/components/builder/exception_items_renderer.tsx +++ b/x-pack/plugins/lists/public/exceptions/components/builder/exception_items_renderer.tsx @@ -23,7 +23,7 @@ import { CreateExceptionListItemSchema, ExceptionListItemSchema, exceptionListItemSchema, -} from '../../../../common'; +} from '../../../../common/schemas'; import { AutocompleteStart, IIndexPattern } from '../../../../../../../src/plugins/data/public'; import { AndOrBadge } from '../and_or_badge'; diff --git a/x-pack/plugins/lists/public/exceptions/components/builder/helpers.ts b/x-pack/plugins/lists/public/exceptions/components/builder/helpers.ts index 6cd9dec0dc7a..c4052acda604 100644 --- a/x-pack/plugins/lists/public/exceptions/components/builder/helpers.ts +++ b/x-pack/plugins/lists/public/exceptions/components/builder/helpers.ts @@ -29,7 +29,7 @@ import { ListSchema, createExceptionListItemSchema, exceptionListItemSchema, -} from '../../../../common'; +} from '../../../../common/schemas'; import { IFieldType, IIndexPattern } from '../../../../../../../src/plugins/data/public'; import { EXCEPTION_OPERATORS, diff --git a/x-pack/plugins/lists/public/index.ts b/x-pack/plugins/lists/public/index.ts index f940bbe02b8f..0b67ab05f5bd 100644 --- a/x-pack/plugins/lists/public/index.ts +++ b/x-pack/plugins/lists/public/index.ts @@ -7,11 +7,11 @@ export * from './shared_exports'; -import { PluginInitializerContext } from '../../../../src/core/public'; +import type { PluginInitializerContext } from '../../../../src/core/public'; import { Plugin } from './plugin'; -import { PluginSetup, PluginStart } from './types'; +import type { PluginSetup, PluginStart } from './types'; export const plugin = (context: PluginInitializerContext): Plugin => new Plugin(context); -export { Plugin, PluginSetup, PluginStart }; +export type { Plugin, PluginSetup, PluginStart }; diff --git a/x-pack/plugins/lists/server/schemas/elastic_query/index_es_list_schema.ts b/x-pack/plugins/lists/server/schemas/elastic_query/index_es_list_schema.ts index 4383e9334629..607535b68c1e 100644 --- a/x-pack/plugins/lists/server/schemas/elastic_query/index_es_list_schema.ts +++ b/x-pack/plugins/lists/server/schemas/elastic_query/index_es_list_schema.ts @@ -16,13 +16,13 @@ import { updated_at, updated_by, } from '@kbn/securitysolution-io-ts-list-types'; +import { version } from '@kbn/securitysolution-io-ts-types'; import { deserializerOrUndefined, immutable, serializerOrUndefined, tie_breaker_id, - version, } from '../../../common/schemas'; export const indexEsListSchema = t.exact( diff --git a/x-pack/plugins/lists/server/schemas/elastic_response/search_es_list_schema.ts b/x-pack/plugins/lists/server/schemas/elastic_response/search_es_list_schema.ts index 536269b9c0ae..f6d6ae4effe7 100644 --- a/x-pack/plugins/lists/server/schemas/elastic_response/search_es_list_schema.ts +++ b/x-pack/plugins/lists/server/schemas/elastic_response/search_es_list_schema.ts @@ -16,13 +16,13 @@ import { updated_at, updated_by, } from '@kbn/securitysolution-io-ts-list-types'; +import { version } from '@kbn/securitysolution-io-ts-types'; import { deserializerOrUndefined, immutable, serializerOrUndefined, tie_breaker_id, - version, } from '../../../common/schemas'; export const searchEsListSchema = t.exact( diff --git a/x-pack/plugins/lists/server/schemas/saved_objects/exceptions_list_so_schema.ts b/x-pack/plugins/lists/server/schemas/saved_objects/exceptions_list_so_schema.ts index c1f480e50c8f..d815dbaae043 100644 --- a/x-pack/plugins/lists/server/schemas/saved_objects/exceptions_list_so_schema.ts +++ b/x-pack/plugins/lists/server/schemas/saved_objects/exceptions_list_so_schema.ts @@ -20,6 +20,7 @@ import { tags, updated_by, } from '@kbn/securitysolution-io-ts-list-types'; +import { versionOrUndefined } from '@kbn/securitysolution-io-ts-types'; import { immutableOrUndefined, @@ -27,7 +28,6 @@ import { list_id, list_type, tie_breaker_id, - versionOrUndefined, } from '../../../common/schemas'; /** diff --git a/x-pack/plugins/lists/server/services/exception_lists/create_endoint_event_filters_list.ts b/x-pack/plugins/lists/server/services/exception_lists/create_endoint_event_filters_list.ts index dba729437b81..9bcf6c63d065 100644 --- a/x-pack/plugins/lists/server/services/exception_lists/create_endoint_event_filters_list.ts +++ b/x-pack/plugins/lists/server/services/exception_lists/create_endoint_event_filters_list.ts @@ -7,13 +7,14 @@ import { SavedObjectsClientContract } from 'kibana/server'; import uuid from 'uuid'; +import { Version } from '@kbn/securitysolution-io-ts-types'; import { ENDPOINT_EVENT_FILTERS_LIST_DESCRIPTION, ENDPOINT_EVENT_FILTERS_LIST_ID, ENDPOINT_EVENT_FILTERS_LIST_NAME, } from '../../../common/constants'; -import { ExceptionListSchema, Version } from '../../../common/schemas'; +import { ExceptionListSchema } from '../../../common/schemas'; import { ExceptionListSoSchema } from '../../schemas/saved_objects'; import { getSavedObjectType, transformSavedObjectToExceptionList } from './utils'; diff --git a/x-pack/plugins/lists/server/services/exception_lists/create_endpoint_list.ts b/x-pack/plugins/lists/server/services/exception_lists/create_endpoint_list.ts index de2be0cb7273..86891e5f8395 100644 --- a/x-pack/plugins/lists/server/services/exception_lists/create_endpoint_list.ts +++ b/x-pack/plugins/lists/server/services/exception_lists/create_endpoint_list.ts @@ -7,13 +7,14 @@ import { SavedObjectsClientContract } from 'kibana/server'; import uuid from 'uuid'; +import { Version } from '@kbn/securitysolution-io-ts-types'; import { ENDPOINT_LIST_DESCRIPTION, ENDPOINT_LIST_ID, ENDPOINT_LIST_NAME, } from '../../../common/constants'; -import { ExceptionListSchema, Version } from '../../../common/schemas'; +import { ExceptionListSchema } from '../../../common/schemas'; import { ExceptionListSoSchema } from '../../schemas/saved_objects'; import { getSavedObjectType, transformSavedObjectToExceptionList } from './utils'; diff --git a/x-pack/plugins/lists/server/services/exception_lists/create_endpoint_trusted_apps_list.ts b/x-pack/plugins/lists/server/services/exception_lists/create_endpoint_trusted_apps_list.ts index 6f6ad7c357f1..ada043403f24 100644 --- a/x-pack/plugins/lists/server/services/exception_lists/create_endpoint_trusted_apps_list.ts +++ b/x-pack/plugins/lists/server/services/exception_lists/create_endpoint_trusted_apps_list.ts @@ -7,13 +7,14 @@ import { SavedObjectsClientContract } from 'kibana/server'; import uuid from 'uuid'; +import { Version } from '@kbn/securitysolution-io-ts-types'; import { ENDPOINT_TRUSTED_APPS_LIST_DESCRIPTION, ENDPOINT_TRUSTED_APPS_LIST_ID, ENDPOINT_TRUSTED_APPS_LIST_NAME, } from '../../../common/constants'; -import { ExceptionListSchema, Version } from '../../../common/schemas'; +import { ExceptionListSchema } from '../../../common/schemas'; import { ExceptionListSoSchema } from '../../schemas/saved_objects'; import { getSavedObjectType, transformSavedObjectToExceptionList } from './utils'; diff --git a/x-pack/plugins/lists/server/services/exception_lists/create_exception_list.ts b/x-pack/plugins/lists/server/services/exception_lists/create_exception_list.ts index 5f2587fc1e98..c6110dc4f470 100644 --- a/x-pack/plugins/lists/server/services/exception_lists/create_exception_list.ts +++ b/x-pack/plugins/lists/server/services/exception_lists/create_exception_list.ts @@ -15,8 +15,9 @@ import { NamespaceType, Tags, } from '@kbn/securitysolution-io-ts-list-types'; +import { Version } from '@kbn/securitysolution-io-ts-types'; -import { ExceptionListSchema, Immutable, ListId, Version } from '../../../common/schemas'; +import { ExceptionListSchema, Immutable, ListId } from '../../../common/schemas'; import { ExceptionListSoSchema } from '../../schemas/saved_objects'; import { getSavedObjectType, transformSavedObjectToExceptionList } from './utils'; diff --git a/x-pack/plugins/lists/server/services/exception_lists/exception_list_client_types.ts b/x-pack/plugins/lists/server/services/exception_lists/exception_list_client_types.ts index 576b0c4d25aa..c6f5e3a3bc16 100644 --- a/x-pack/plugins/lists/server/services/exception_lists/exception_list_client_types.ts +++ b/x-pack/plugins/lists/server/services/exception_lists/exception_list_client_types.ts @@ -30,6 +30,8 @@ import { import { EmptyStringArrayDecoded, NonEmptyStringArrayDecoded, + Version, + VersionOrUndefined, } from '@kbn/securitysolution-io-ts-types'; import { @@ -43,8 +45,6 @@ import { PerPageOrUndefined, SortFieldOrUndefined, SortOrderOrUndefined, - Version, - VersionOrUndefined, _VersionOrUndefined, } from '../../../common/schemas'; diff --git a/x-pack/plugins/lists/server/services/exception_lists/update_exception_list.ts b/x-pack/plugins/lists/server/services/exception_lists/update_exception_list.ts index 3daa2e9157b5..43c319cca000 100644 --- a/x-pack/plugins/lists/server/services/exception_lists/update_exception_list.ts +++ b/x-pack/plugins/lists/server/services/exception_lists/update_exception_list.ts @@ -16,11 +16,11 @@ import { OsTypeArray, TagsOrUndefined, } from '@kbn/securitysolution-io-ts-list-types'; +import { VersionOrUndefined } from '@kbn/securitysolution-io-ts-types'; import { ExceptionListSchema, ListIdOrUndefined, - VersionOrUndefined, _VersionOrUndefined, } from '../../../common/schemas'; import { ExceptionListSoSchema } from '../../schemas/saved_objects'; diff --git a/x-pack/plugins/lists/server/services/items/write_lines_to_bulk_list_items.ts b/x-pack/plugins/lists/server/services/items/write_lines_to_bulk_list_items.ts index b3ce823f9ac2..392c44cf72b0 100644 --- a/x-pack/plugins/lists/server/services/items/write_lines_to_bulk_list_items.ts +++ b/x-pack/plugins/lists/server/services/items/write_lines_to_bulk_list_items.ts @@ -9,6 +9,7 @@ import { Readable } from 'stream'; import { ElasticsearchClient } from 'kibana/server'; import { MetaOrUndefined, Type } from '@kbn/securitysolution-io-ts-list-types'; +import { Version } from '@kbn/securitysolution-io-ts-types'; import { createListIfItDoesNotExist } from '../lists/create_list_if_it_does_not_exist'; import { @@ -16,7 +17,6 @@ import { ListIdOrUndefined, ListSchema, SerializerOrUndefined, - Version, } from '../../../common/schemas'; import { ConfigType } from '../../config'; diff --git a/x-pack/plugins/lists/server/services/lists/create_list.ts b/x-pack/plugins/lists/server/services/lists/create_list.ts index d139ef3ea4bb..bd5b3c901fdc 100644 --- a/x-pack/plugins/lists/server/services/lists/create_list.ts +++ b/x-pack/plugins/lists/server/services/lists/create_list.ts @@ -14,6 +14,7 @@ import { Name, Type, } from '@kbn/securitysolution-io-ts-list-types'; +import { Version } from '@kbn/securitysolution-io-ts-types'; import { encodeHitVersion } from '../utils/encode_hit_version'; import { @@ -21,7 +22,6 @@ import { Immutable, ListSchema, SerializerOrUndefined, - Version, } from '../../../common/schemas'; import { IndexEsListSchema } from '../../schemas/elastic_query'; diff --git a/x-pack/plugins/lists/server/services/lists/create_list_if_it_does_not_exist.ts b/x-pack/plugins/lists/server/services/lists/create_list_if_it_does_not_exist.ts index 71094a5ab49d..4d4e634a465a 100644 --- a/x-pack/plugins/lists/server/services/lists/create_list_if_it_does_not_exist.ts +++ b/x-pack/plugins/lists/server/services/lists/create_list_if_it_does_not_exist.ts @@ -13,13 +13,13 @@ import { Name, Type, } from '@kbn/securitysolution-io-ts-list-types'; +import { Version } from '@kbn/securitysolution-io-ts-types'; import { DeserializerOrUndefined, Immutable, ListSchema, SerializerOrUndefined, - Version, } from '../../../common/schemas'; import { getList } from './get_list'; diff --git a/x-pack/plugins/lists/server/services/lists/list_client_types.ts b/x-pack/plugins/lists/server/services/lists/list_client_types.ts index b4fe52019ec7..28732090342c 100644 --- a/x-pack/plugins/lists/server/services/lists/list_client_types.ts +++ b/x-pack/plugins/lists/server/services/lists/list_client_types.ts @@ -18,6 +18,7 @@ import { NameOrUndefined, Type, } from '@kbn/securitysolution-io-ts-list-types'; +import { Version, VersionOrUndefined } from '@kbn/securitysolution-io-ts-types'; import { DeserializerOrUndefined, @@ -30,8 +31,6 @@ import { SerializerOrUndefined, SortFieldOrUndefined, SortOrderOrUndefined, - Version, - VersionOrUndefined, _VersionOrUndefined, } from '../../../common/schemas'; import { ConfigType } from '../../config'; diff --git a/x-pack/plugins/lists/server/services/lists/update_list.ts b/x-pack/plugins/lists/server/services/lists/update_list.ts index 374c3cd0e2de..2e1cc4382681 100644 --- a/x-pack/plugins/lists/server/services/lists/update_list.ts +++ b/x-pack/plugins/lists/server/services/lists/update_list.ts @@ -12,10 +12,11 @@ import { MetaOrUndefined, NameOrUndefined, } from '@kbn/securitysolution-io-ts-list-types'; +import { VersionOrUndefined } from '@kbn/securitysolution-io-ts-types'; import { decodeVersion } from '../utils/decode_version'; import { encodeHitVersion } from '../utils/encode_hit_version'; -import { ListSchema, VersionOrUndefined, _VersionOrUndefined } from '../../../common/schemas'; +import { ListSchema, _VersionOrUndefined } from '../../../common/schemas'; import { UpdateEsListSchema } from '../../schemas/elastic_query'; import { getList } from '.'; diff --git a/x-pack/plugins/security_solution/common/add_remove_id_to_item.test.ts b/x-pack/plugins/security_solution/common/add_remove_id_to_item.test.ts deleted file mode 100644 index 0bd88adda726..000000000000 --- a/x-pack/plugins/security_solution/common/add_remove_id_to_item.test.ts +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { addIdToItem, removeIdFromItem } from './add_remove_id_to_item'; - -jest.mock('uuid', () => ({ - v4: jest.fn().mockReturnValue('123'), -})); - -describe('add_remove_id_to_item', () => { - afterEach(() => { - jest.clearAllMocks(); - }); - - describe('addIdToItem', () => { - test('it adds an id to an empty item', () => { - expect(addIdToItem({})).toEqual({ id: '123' }); - }); - - test('it adds a complex object', () => { - expect( - addIdToItem({ - field: '', - type: 'mapping', - value: '', - }) - ).toEqual({ - id: '123', - field: '', - type: 'mapping', - value: '', - }); - }); - - test('it adds an id to an existing item', () => { - expect(addIdToItem({ test: '456' })).toEqual({ id: '123', test: '456' }); - }); - - test('it does not change the id if it already exists', () => { - expect(addIdToItem({ id: '456' })).toEqual({ id: '456' }); - }); - - test('it returns the same reference if it has an id already', () => { - const obj = { id: '456' }; - expect(addIdToItem(obj)).toBe(obj); - }); - - test('it returns a new reference if it adds an id to an item', () => { - const obj = { test: '456' }; - expect(addIdToItem(obj)).not.toBe(obj); - }); - }); - - describe('removeIdFromItem', () => { - test('it removes an id from an item', () => { - expect(removeIdFromItem({ id: '456' })).toEqual({}); - }); - - test('it returns a new reference if it removes an id from an item', () => { - const obj = { id: '123', test: '456' }; - expect(removeIdFromItem(obj)).not.toBe(obj); - }); - - test('it does not effect an item without an id', () => { - expect(removeIdFromItem({ test: '456' })).toEqual({ test: '456' }); - }); - - test('it returns the same reference if it does not have an id already', () => { - const obj = { test: '456' }; - expect(removeIdFromItem(obj)).toBe(obj); - }); - }); -}); diff --git a/x-pack/plugins/security_solution/common/add_remove_id_to_item.ts b/x-pack/plugins/security_solution/common/add_remove_id_to_item.ts deleted file mode 100644 index 1f35574038fd..000000000000 --- a/x-pack/plugins/security_solution/common/add_remove_id_to_item.ts +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import uuid from 'uuid'; - -/** - * This is useful for when you have arrays without an ID and need to add one for - * ReactJS keys. I break the types slightly by introducing an id to an arbitrary item - * but then cast it back to the regular type T. - * Usage of this could be considered tech debt as I am adding an ID when the backend - * could be doing the same thing but it depends on how you want to model your data and - * if you view modeling your data with id's to please ReactJS a good or bad thing. - * @param item The item to add an id to. - */ -type NotArray = T extends unknown[] ? never : T; -export const addIdToItem = (item: NotArray): T => { - const maybeId: typeof item & { id?: string } = item; - if (maybeId.id != null) { - return item; - } else { - return { ...item, id: uuid.v4() }; - } -}; - -/** - * This is to reverse the id you added to your arrays for ReactJS keys. - * @param item The item to remove the id from. - */ -export const removeIdFromItem = ( - item: NotArray -): - | T - | Pick< - T & { - id?: string | undefined; - }, - Exclude - > => { - const maybeId: typeof item & { id?: string } = item; - if (maybeId.id != null) { - const { id, ...noId } = maybeId; - return noId; - } else { - return item; - } -}; diff --git a/x-pack/plugins/security_solution/common/detection_engine/get_query_filter.ts b/x-pack/plugins/security_solution/common/detection_engine/get_query_filter.ts index e562d186bc42..7d24c1e157e4 100644 --- a/x-pack/plugins/security_solution/common/detection_engine/get_query_filter.ts +++ b/x-pack/plugins/security_solution/common/detection_engine/get_query_filter.ts @@ -5,6 +5,7 @@ * 2.0. */ +import { Language } from '@kbn/securitysolution-io-ts-alerting-types'; import { Filter, IIndexPattern, @@ -17,7 +18,7 @@ import { } from '../../../lists/common/schemas'; import { ESBoolQuery } from '../typed_json'; import { buildExceptionFilter } from '../shared_imports'; -import { Query, Language, Index, TimestampOverrideOrUndefined } from './schemas/common/schemas'; +import { Query, Index, TimestampOverrideOrUndefined } from './schemas/common/schemas'; export const getQueryFilter = ( query: Query, diff --git a/x-pack/plugins/security_solution/common/detection_engine/schemas/common/schemas.ts b/x-pack/plugins/security_solution/common/detection_engine/schemas/common/schemas.ts index e085d500bee0..7b49b68ab79a 100644 --- a/x-pack/plugins/security_solution/common/detection_engine/schemas/common/schemas.ts +++ b/x-pack/plugins/security_solution/common/detection_engine/schemas/common/schemas.ts @@ -8,21 +8,14 @@ /* eslint-disable @typescript-eslint/naming-convention */ import * as t from 'io-ts'; -import { Either } from 'fp-ts/lib/Either'; import { - SavedObjectAttributes, - SavedObjectAttribute, - SavedObjectAttributeSingle, -} from 'src/core/types'; -import { RiskScore } from '../types/risk_score'; -import { UUID } from '../types/uuid'; -import { IsoDateString } from '../types/iso_date_string'; -import { PositiveIntegerGreaterThanZero } from '../types/positive_integer_greater_than_zero'; -import { PositiveInteger } from '../types/positive_integer'; -import { NonEmptyString } from '../types/non_empty_string'; -import { parseScheduleDates } from '../../parse_schedule_dates'; -import { machine_learning_job_id_normalized } from '../types/normalized_ml_job_id'; + UUID, + NonEmptyString, + IsoDateString, + PositiveIntegerGreaterThanZero, + PositiveInteger, +} from '@kbn/securitysolution-io-ts-types'; export const author = t.array(t.string); export type Author = t.TypeOf; @@ -76,79 +69,6 @@ export type Filters = t.TypeOf; // Filters are not easily type-a export const filtersOrUndefined = t.union([filters, t.undefined]); export type FiltersOrUndefined = t.TypeOf; -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export const saved_object_attribute_single: t.Type = t.recursion( - 'saved_object_attribute_single', - () => t.union([t.string, t.number, t.boolean, t.null, t.undefined, saved_object_attributes]) -); - -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export const saved_object_attribute: t.Type = t.recursion( - 'saved_object_attribute', - () => t.union([saved_object_attribute_single, t.array(saved_object_attribute_single)]) -); - -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export const saved_object_attributes: t.Type = t.recursion( - 'saved_object_attributes', - () => t.record(t.string, saved_object_attribute) -); - -/** - * Params is an "object", since it is a type of AlertActionParams which is action templates. - * @see x-pack/plugins/alerting/common/alert.ts - */ -export const action_group = t.string; -export const action_id = t.string; -export const action_action_type_id = t.string; -export const action_params = saved_object_attributes; -export const action = t.exact( - t.type({ - group: action_group, - id: action_id, - action_type_id: action_action_type_id, - params: action_params, - }) -); - -export const actions = t.array(action); -export type Actions = t.TypeOf; - -export const actionsCamel = t.array( - t.exact( - t.type({ - group: action_group, - id: action_id, - actionTypeId: action_action_type_id, - params: action_params, - }) - ) -); -export type ActionsCamel = t.TypeOf; - -const stringValidator = (input: unknown): input is string => typeof input === 'string'; -export const from = new t.Type( - 'From', - t.string.is, - (input, context): Either => { - if (stringValidator(input) && parseScheduleDates(input) == null) { - return t.failure(input, context, 'Failed to parse "from" on rule param'); - } - return t.string.validate(input, context); - }, - t.identity -); -export type From = t.TypeOf; - -export const fromOrUndefined = t.union([from, t.undefined]); -export type FromOrUndefined = t.TypeOf; - export const immutable = t.boolean; export type Immutable = t.TypeOf; @@ -183,26 +103,6 @@ export type Query = t.TypeOf; export const queryOrUndefined = t.union([query, t.undefined]); export type QueryOrUndefined = t.TypeOf; -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export const language = t.keyof({ eql: null, kuery: null, lucene: null }); - -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export type Language = t.TypeOf; - -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export const languageOrUndefined = t.union([language, t.undefined]); - -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export type LanguageOrUndefined = t.TypeOf; - export const license = t.string; export type License = t.TypeOf; @@ -241,27 +141,12 @@ export type TimestampOverride = t.TypeOf; export const timestampOverrideOrUndefined = t.union([timestamp_override, t.undefined]); export type TimestampOverrideOrUndefined = t.TypeOf; -export const throttle = t.string; -export type Throttle = t.TypeOf; - -export const throttleOrNull = t.union([throttle, t.null]); -export type ThrottleOrNull = t.TypeOf; - -export const throttleOrNullOrUndefined = t.union([throttle, t.null, t.undefined]); -export type ThrottleOrUndefinedOrNull = t.TypeOf; - export const anomaly_threshold = PositiveInteger; export type AnomalyThreshold = t.TypeOf; export const anomalyThresholdOrUndefined = t.union([anomaly_threshold, t.undefined]); export type AnomalyThresholdOrUndefined = t.TypeOf; -export const machine_learning_job_id = t.union([t.string, machine_learning_job_id_normalized]); -export type MachineLearningJobId = t.TypeOf; - -export const machineLearningJobIdOrUndefined = t.union([machine_learning_job_id, t.undefined]); -export type MachineLearningJobIdOrUndefined = t.TypeOf; - /** * Note that this is a non-exact io-ts type as we allow extra meta information * to be added to the meta object @@ -271,158 +156,18 @@ export type Meta = t.TypeOf; export const metaOrUndefined = t.union([meta, t.undefined]); export type MetaOrUndefined = t.TypeOf; -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export const max_signals = PositiveIntegerGreaterThanZero; - -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export type MaxSignals = t.TypeOf; - -export const maxSignalsOrUndefined = t.union([max_signals, t.undefined]); -export type MaxSignalsOrUndefined = t.TypeOf; - export const name = NonEmptyString; export type Name = t.TypeOf; export const nameOrUndefined = t.union([name, t.undefined]); export type NameOrUndefined = t.TypeOf; -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export const operator = t.keyof({ - equals: null, -}); - -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export type Operator = t.TypeOf; - -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export enum OperatorEnum { - EQUALS = 'equals', -} - -export const risk_score = RiskScore; -export type RiskScore = t.TypeOf; - -export const riskScoreOrUndefined = t.union([risk_score, t.undefined]); -export type RiskScoreOrUndefined = t.TypeOf; - -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export const risk_score_mapping_field = t.string; - -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export const risk_score_mapping_value = t.string; - -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export const risk_score_mapping_item = t.exact( - t.type({ - field: risk_score_mapping_field, - value: risk_score_mapping_value, - operator, - risk_score: riskScoreOrUndefined, - }) -); - -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export const risk_score_mapping = t.array(risk_score_mapping_item); - -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export type RiskScoreMapping = t.TypeOf; - -export const riskScoreMappingOrUndefined = t.union([risk_score_mapping, t.undefined]); -export type RiskScoreMappingOrUndefined = t.TypeOf; - export const rule_name_override = t.string; export type RuleNameOverride = t.TypeOf; export const ruleNameOverrideOrUndefined = t.union([rule_name_override, t.undefined]); export type RuleNameOverrideOrUndefined = t.TypeOf; -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export const severity = t.keyof({ low: null, medium: null, high: null, critical: null }); - -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export type Severity = t.TypeOf; - -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export const severityOrUndefined = t.union([severity, t.undefined]); - -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export type SeverityOrUndefined = t.TypeOf; - -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export const severity_mapping_field = t.string; - -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export const severity_mapping_value = t.string; - -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export const severity_mapping_item = t.exact( - t.type({ - field: severity_mapping_field, - operator, - value: severity_mapping_value, - severity, - }) -); - -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export type SeverityMappingItem = t.TypeOf; - -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export const severity_mapping = t.array(severity_mapping_item); - -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export type SeverityMapping = t.TypeOf; - -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export const severityMappingOrUndefined = t.union([severity_mapping, t.undefined]); - -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export type SeverityMappingOrUndefined = t.TypeOf; - export const status = t.keyof({ open: null, closed: null, 'in-progress': null }); export type Status = t.TypeOf; @@ -445,19 +190,6 @@ export type To = t.TypeOf; export const toOrUndefined = t.union([to, t.undefined]); export type ToOrUndefined = t.TypeOf; -export const type = t.keyof({ - eql: null, - machine_learning: null, - query: null, - saved_query: null, - threshold: null, - threat_match: null, -}); -export type Type = t.TypeOf; - -export const typeOrUndefined = t.union([type, t.undefined]); -export type TypeOrUndefined = t.TypeOf; - export const queryFilter = t.string; export type QueryFilter = t.TypeOf; @@ -511,152 +243,6 @@ export type Fields = t.TypeOf; export const fieldsOrUndefined = t.union([fields, t.undefined]); export type FieldsOrUndefined = t.TypeOf; -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export const threat_framework = t.string; - -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export const threat_tactic_id = t.string; - -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export const threat_tactic_name = t.string; - -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export const threat_tactic_reference = t.string; - -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export const threat_tactic = t.type({ - id: threat_tactic_id, - name: threat_tactic_name, - reference: threat_tactic_reference, -}); - -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export type ThreatTactic = t.TypeOf; - -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export const threat_subtechnique_id = t.string; - -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export const threat_subtechnique_name = t.string; - -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export const threat_subtechnique_reference = t.string; - -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export const threat_subtechnique = t.type({ - id: threat_subtechnique_id, - name: threat_subtechnique_name, - reference: threat_subtechnique_reference, -}); - -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export type ThreatSubtechnique = t.TypeOf; - -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export const threat_subtechniques = t.array(threat_subtechnique); - -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export const threat_technique_id = t.string; - -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export const threat_technique_name = t.string; - -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export const threat_technique_reference = t.string; - -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export const threat_technique = t.intersection([ - t.exact( - t.type({ - id: threat_technique_id, - name: threat_technique_name, - reference: threat_technique_reference, - }) - ), - t.exact( - t.partial({ - subtechnique: threat_subtechniques, - }) - ), -]); - -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export type ThreatTechnique = t.TypeOf; - -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export const threat_techniques = t.array(threat_technique); - -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export const threat = t.intersection([ - t.exact( - t.type({ - framework: threat_framework, - tactic: threat_tactic, - }) - ), - t.exact( - t.partial({ - technique: threat_techniques, - }) - ), -]); - -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export type Threat = t.TypeOf; - -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export const threats = t.array(threat); - -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export type Threats = t.TypeOf; - -export const threatsOrUndefined = t.union([threats, t.undefined]); -export type ThreatsOrUndefined = t.TypeOf; - export const thresholdField = t.exact( t.type({ field: t.union([t.string, t.array(t.string)]), // Covers pre- and post-7.12 @@ -707,43 +293,19 @@ export type ThresholdNormalized = t.TypeOf; export const thresholdNormalizedOrUndefined = t.union([thresholdNormalized, t.undefined]); export type ThresholdNormalizedOrUndefined = t.TypeOf; -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ export const created_at = IsoDateString; -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ export const updated_at = IsoDateString; -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ export const updated_by = t.string; -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ export const created_by = t.string; + export const updatedByOrNull = t.union([updated_by, t.null]); export type UpdatedByOrNull = t.TypeOf; export const createdByOrNull = t.union([created_by, t.null]); export type CreatedByOrNull = t.TypeOf; -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export const version = PositiveIntegerGreaterThanZero; - -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export type Version = t.TypeOf; - -export const versionOrUndefined = t.union([version, t.undefined]); -export type VersionOrUndefined = t.TypeOf; - export const last_success_at = IsoDateString; export type LastSuccessAt = t.TypeOf; diff --git a/x-pack/plugins/security_solution/common/detection_engine/schemas/request/add_prepackaged_rules_schema.ts b/x-pack/plugins/security_solution/common/detection_engine/schemas/request/add_prepackaged_rules_schema.ts index 981a5422a059..eed20951190b 100644 --- a/x-pack/plugins/security_solution/common/detection_engine/schemas/request/add_prepackaged_rules_schema.ts +++ b/x-pack/plugins/security_solution/common/detection_engine/schemas/request/add_prepackaged_rules_schema.ts @@ -8,46 +8,20 @@ import * as t from 'io-ts'; import { - description, - anomaly_threshold, - filters, - index, - saved_id, - timeline_id, - timeline_title, - meta, + Actions, + DefaultActionsArray, + DefaultFromString, + DefaultIntervalString, + DefaultMaxSignalsNumber, + DefaultRiskScoreMappingArray, + DefaultSeverityMappingArray, + DefaultThreatArray, + DefaultThrottleNull, + DefaultToString, + From, + RiskScoreMapping, machine_learning_job_id, risk_score, - MaxSignals, - name, - severity, - Tags, - To, - type, - Threats, - threshold, - ThrottleOrNull, - note, - References, - Actions, - Enabled, - FalsePositives, - From, - Interval, - language, - query, - rule_id, - version, - building_block_type, - license, - rule_name_override, - timestamp_override, - Author, - RiskScoreMapping, - SeverityMapping, - event_category_override, -} from '../common/schemas'; -import { threat_index, concurrent_searches, items_per_search, @@ -56,23 +30,48 @@ import { threat_mapping, threat_language, threat_indicator_path, -} from '../types/threat_mapping'; - + Threats, + type, + language, + severity, + SeverityMapping, + ThrottleOrNull, + MaxSignals, +} from '@kbn/securitysolution-io-ts-alerting-types'; import { + version, DefaultStringArray, - DefaultActionsArray, DefaultBooleanFalse, - DefaultFromString, - DefaultIntervalString, - DefaultMaxSignalsNumber, - DefaultToString, - DefaultThreatArray, - DefaultThrottleNull, - DefaultListArray, - ListArray, - DefaultRiskScoreMappingArray, - DefaultSeverityMappingArray, -} from '../types'; +} from '@kbn/securitysolution-io-ts-types'; + +import { DefaultListArray, ListArray } from '@kbn/securitysolution-io-ts-list-types'; +import { + description, + anomaly_threshold, + filters, + index, + saved_id, + timeline_id, + timeline_title, + meta, + name, + Tags, + To, + threshold, + note, + References, + Enabled, + FalsePositives, + Interval, + query, + rule_id, + building_block_type, + license, + rule_name_override, + timestamp_override, + Author, + event_category_override, +} from '../common/schemas'; /** * Big differences between this schema and the createRulesSchema diff --git a/x-pack/plugins/security_solution/common/detection_engine/schemas/request/add_prepackged_rules_schema.test.ts b/x-pack/plugins/security_solution/common/detection_engine/schemas/request/add_prepackged_rules_schema.test.ts index f3bef5ad7445..03c0947aaf50 100644 --- a/x-pack/plugins/security_solution/common/detection_engine/schemas/request/add_prepackged_rules_schema.test.ts +++ b/x-pack/plugins/security_solution/common/detection_engine/schemas/request/add_prepackged_rules_schema.test.ts @@ -11,9 +11,8 @@ import { AddPrepackagedRulesSchema, } from './add_prepackaged_rules_schema'; -import { exactCheck } from '../../../exact_check'; +import { exactCheck, foldLeftRight, getPaths } from '@kbn/securitysolution-io-ts-utils'; import { pipe } from 'fp-ts/lib/pipeable'; -import { foldLeftRight, getPaths } from '../../../test_utils'; import { left } from 'fp-ts/lib/Either'; import { getAddPrepackagedRulesSchemaMock, diff --git a/x-pack/plugins/security_solution/common/detection_engine/schemas/request/create_rules_bulk_schema.test.ts b/x-pack/plugins/security_solution/common/detection_engine/schemas/request/create_rules_bulk_schema.test.ts index 9fe602bca8de..e606e1f77fc2 100644 --- a/x-pack/plugins/security_solution/common/detection_engine/schemas/request/create_rules_bulk_schema.test.ts +++ b/x-pack/plugins/security_solution/common/detection_engine/schemas/request/create_rules_bulk_schema.test.ts @@ -6,9 +6,7 @@ */ import { createRulesBulkSchema, CreateRulesBulkSchema } from './create_rules_bulk_schema'; -import { exactCheck } from '../../../exact_check'; -import { foldLeftRight } from '../../../test_utils'; -import { formatErrors } from '../../../format_errors'; +import { exactCheck, foldLeftRight, formatErrors } from '@kbn/securitysolution-io-ts-utils'; import { getCreateRulesSchemaMock } from './rule_schemas.mock'; // only the basics of testing are here. diff --git a/x-pack/plugins/security_solution/common/detection_engine/schemas/request/create_signals_migration_schema.ts b/x-pack/plugins/security_solution/common/detection_engine/schemas/request/create_signals_migration_schema.ts index f52244810240..55267c27ee37 100644 --- a/x-pack/plugins/security_solution/common/detection_engine/schemas/request/create_signals_migration_schema.ts +++ b/x-pack/plugins/security_solution/common/detection_engine/schemas/request/create_signals_migration_schema.ts @@ -7,8 +7,8 @@ import * as t from 'io-ts'; +import { PositiveInteger, PositiveIntegerGreaterThanZero } from '@kbn/securitysolution-io-ts-types'; import { index } from '../common/schemas'; -import { PositiveInteger, PositiveIntegerGreaterThanZero } from '../types'; export const signalsReindexOptions = t.partial({ requests_per_second: t.number, diff --git a/x-pack/plugins/security_solution/common/detection_engine/schemas/request/export_rules_schema.test.ts b/x-pack/plugins/security_solution/common/detection_engine/schemas/request/export_rules_schema.test.ts index f9c2d38ea4da..186f170ad700 100644 --- a/x-pack/plugins/security_solution/common/detection_engine/schemas/request/export_rules_schema.test.ts +++ b/x-pack/plugins/security_solution/common/detection_engine/schemas/request/export_rules_schema.test.ts @@ -12,9 +12,8 @@ import { ExportRulesQuerySchema, ExportRulesQuerySchemaDecoded, } from './export_rules_schema'; -import { exactCheck } from '../../../exact_check'; +import { exactCheck, foldLeftRight, getPaths } from '@kbn/securitysolution-io-ts-utils'; import { pipe } from 'fp-ts/lib/pipeable'; -import { foldLeftRight, getPaths } from '../../../test_utils'; import { left } from 'fp-ts/lib/Either'; describe('create rules schema', () => { diff --git a/x-pack/plugins/security_solution/common/detection_engine/schemas/request/export_rules_schema.ts b/x-pack/plugins/security_solution/common/detection_engine/schemas/request/export_rules_schema.ts index 4dcb7351aebd..a83e1c2c0f46 100644 --- a/x-pack/plugins/security_solution/common/detection_engine/schemas/request/export_rules_schema.ts +++ b/x-pack/plugins/security_solution/common/detection_engine/schemas/request/export_rules_schema.ts @@ -7,11 +7,10 @@ import * as t from 'io-ts'; +import { DefaultExportFileName } from '@kbn/securitysolution-io-ts-alerting-types'; +import { DefaultStringBooleanFalse } from '@kbn/securitysolution-io-ts-types'; import { rule_id, FileName, ExcludeExportDetails } from '../common/schemas'; -import { DefaultExportFileName } from '../types/default_export_file_name'; -import { DefaultStringBooleanFalse } from '../types/default_string_boolean_false'; - const objects = t.array(t.exact(t.type({ rule_id }))); export const exportRulesSchema = t.union([t.exact(t.type({ objects })), t.null]); export type ExportRulesSchema = t.TypeOf; diff --git a/x-pack/plugins/security_solution/common/detection_engine/schemas/request/find_rules_schema.test.ts b/x-pack/plugins/security_solution/common/detection_engine/schemas/request/find_rules_schema.test.ts index 923d54e1d6fa..cd221c9f0a4b 100644 --- a/x-pack/plugins/security_solution/common/detection_engine/schemas/request/find_rules_schema.test.ts +++ b/x-pack/plugins/security_solution/common/detection_engine/schemas/request/find_rules_schema.test.ts @@ -5,9 +5,8 @@ * 2.0. */ -import { exactCheck } from '../../../exact_check'; +import { exactCheck, foldLeftRight, getPaths } from '@kbn/securitysolution-io-ts-utils'; import { pipe } from 'fp-ts/lib/pipeable'; -import { foldLeftRight, getPaths } from '../../../test_utils'; import { left } from 'fp-ts/lib/Either'; import { FindRulesSchema, findRulesSchema } from './find_rules_schema'; diff --git a/x-pack/plugins/security_solution/common/detection_engine/schemas/request/find_rules_schema.ts b/x-pack/plugins/security_solution/common/detection_engine/schemas/request/find_rules_schema.ts index 25c880290454..b04afd14375c 100644 --- a/x-pack/plugins/security_solution/common/detection_engine/schemas/request/find_rules_schema.ts +++ b/x-pack/plugins/security_solution/common/detection_engine/schemas/request/find_rules_schema.ts @@ -7,9 +7,8 @@ import * as t from 'io-ts'; +import { DefaultPerPage, DefaultPage } from '@kbn/securitysolution-io-ts-alerting-types'; import { queryFilter, fields, sort_field, sort_order, PerPage, Page } from '../common/schemas'; -import { DefaultPerPage } from '../types/default_per_page'; -import { DefaultPage } from '../types/default_page'; export const findRulesSchema = t.exact( t.partial({ diff --git a/x-pack/plugins/security_solution/common/detection_engine/schemas/request/get_signals_migration_status_schema.ts b/x-pack/plugins/security_solution/common/detection_engine/schemas/request/get_signals_migration_status_schema.ts index 9441cabf73ba..c0969768d8be 100644 --- a/x-pack/plugins/security_solution/common/detection_engine/schemas/request/get_signals_migration_status_schema.ts +++ b/x-pack/plugins/security_solution/common/detection_engine/schemas/request/get_signals_migration_status_schema.ts @@ -7,7 +7,7 @@ import * as t from 'io-ts'; -import { from } from '../common/schemas'; +import { from } from '@kbn/securitysolution-io-ts-alerting-types'; export const getSignalsMigrationStatusSchema = t.exact( t.type({ diff --git a/x-pack/plugins/security_solution/common/detection_engine/schemas/request/import_rules_schema.test.ts b/x-pack/plugins/security_solution/common/detection_engine/schemas/request/import_rules_schema.test.ts index 2caedd2e0119..1a937473c4b1 100644 --- a/x-pack/plugins/security_solution/common/detection_engine/schemas/request/import_rules_schema.test.ts +++ b/x-pack/plugins/security_solution/common/detection_engine/schemas/request/import_rules_schema.test.ts @@ -5,9 +5,8 @@ * 2.0. */ -import { exactCheck } from '../../../exact_check'; +import { exactCheck, foldLeftRight, getPaths } from '@kbn/securitysolution-io-ts-utils'; import { pipe } from 'fp-ts/lib/pipeable'; -import { foldLeftRight, getPaths } from '../../../test_utils'; import { left } from 'fp-ts/lib/Either'; import { ImportRulesSchema, diff --git a/x-pack/plugins/security_solution/common/detection_engine/schemas/request/import_rules_schema.ts b/x-pack/plugins/security_solution/common/detection_engine/schemas/request/import_rules_schema.ts index 8fa5809abe68..70a7b8245f17 100644 --- a/x-pack/plugins/security_solution/common/detection_engine/schemas/request/import_rules_schema.ts +++ b/x-pack/plugins/security_solution/common/detection_engine/schemas/request/import_rules_schema.ts @@ -7,6 +7,47 @@ import * as t from 'io-ts'; +import { + Actions, + DefaultActionsArray, + DefaultFromString, + DefaultIntervalString, + DefaultMaxSignalsNumber, + DefaultRiskScoreMappingArray, + DefaultSeverityMappingArray, + DefaultThreatArray, + DefaultThrottleNull, + DefaultToString, + From, + machine_learning_job_id, + risk_score, + RiskScoreMapping, + threat_index, + items_per_search, + concurrent_searches, + threat_query, + threat_filters, + threat_mapping, + threat_language, + threat_indicator_path, + Threats, + type, + language, + severity, + SeverityMapping, + ThrottleOrNull, + MaxSignals, +} from '@kbn/securitysolution-io-ts-alerting-types'; + +import { + DefaultVersionNumber, + Version, + DefaultStringArray, + DefaultBooleanTrue, + OnlyFalseAllowed, + DefaultStringBooleanFalse, +} from '@kbn/securitysolution-io-ts-types'; +import { DefaultListArray, ListArray } from '@kbn/securitysolution-io-ts-list-types'; import { description, anomaly_threshold, @@ -18,26 +59,15 @@ import { timeline_id, timeline_title, meta, - machine_learning_job_id, - risk_score, - MaxSignals, name, - severity, Tags, To, - type, - Threats, threshold, - ThrottleOrNull, note, - Version, References, - Actions, Enabled, FalsePositives, - From, Interval, - language, query, rule_id, id, @@ -50,39 +80,8 @@ import { rule_name_override, timestamp_override, Author, - RiskScoreMapping, - SeverityMapping, event_category_override, } from '../common/schemas'; -import { - threat_index, - items_per_search, - concurrent_searches, - threat_query, - threat_filters, - threat_mapping, - threat_language, - threat_indicator_path, -} from '../types/threat_mapping'; - -import { - DefaultStringArray, - DefaultActionsArray, - DefaultBooleanTrue, - DefaultFromString, - DefaultIntervalString, - DefaultMaxSignalsNumber, - DefaultToString, - DefaultThreatArray, - DefaultThrottleNull, - DefaultVersionNumber, - OnlyFalseAllowed, - DefaultStringBooleanFalse, - DefaultListArray, - ListArray, - DefaultRiskScoreMappingArray, - DefaultSeverityMappingArray, -} from '../types'; /** * Differences from this and the createRulesSchema are diff --git a/x-pack/plugins/security_solution/common/detection_engine/schemas/request/patch_rules_bulk_schema.test.ts b/x-pack/plugins/security_solution/common/detection_engine/schemas/request/patch_rules_bulk_schema.test.ts index caa57525ab34..290f190562fe 100644 --- a/x-pack/plugins/security_solution/common/detection_engine/schemas/request/patch_rules_bulk_schema.test.ts +++ b/x-pack/plugins/security_solution/common/detection_engine/schemas/request/patch_rules_bulk_schema.test.ts @@ -6,9 +6,7 @@ */ import { patchRulesBulkSchema, PatchRulesBulkSchema } from './patch_rules_bulk_schema'; -import { exactCheck } from '../../../exact_check'; -import { foldLeftRight } from '../../../test_utils'; -import { formatErrors } from '../../../format_errors'; +import { exactCheck, formatErrors, foldLeftRight } from '@kbn/securitysolution-io-ts-utils'; import { PatchRulesSchema } from './patch_rules_schema'; // only the basics of testing are here. diff --git a/x-pack/plugins/security_solution/common/detection_engine/schemas/request/patch_rules_schema.test.ts b/x-pack/plugins/security_solution/common/detection_engine/schemas/request/patch_rules_schema.test.ts index 3dfa12acc29d..5ac49deb32e0 100644 --- a/x-pack/plugins/security_solution/common/detection_engine/schemas/request/patch_rules_schema.test.ts +++ b/x-pack/plugins/security_solution/common/detection_engine/schemas/request/patch_rules_schema.test.ts @@ -7,9 +7,8 @@ import { patchRulesSchema, PatchRulesSchema, PatchRulesSchemaDecoded } from './patch_rules_schema'; import { getPatchRulesSchemaMock, getPatchRulesSchemaDecodedMock } from './patch_rules_schema.mock'; -import { exactCheck } from '../../../exact_check'; +import { exactCheck, foldLeftRight, getPaths } from '@kbn/securitysolution-io-ts-utils'; import { pipe } from 'fp-ts/lib/pipeable'; -import { foldLeftRight, getPaths } from '../../../test_utils'; import { left } from 'fp-ts/lib/Either'; import { getListArrayMock } from '../types/lists.mock'; diff --git a/x-pack/plugins/security_solution/common/detection_engine/schemas/request/patch_rules_schema.ts b/x-pack/plugins/security_solution/common/detection_engine/schemas/request/patch_rules_schema.ts index 920fbaf4915c..8c801e75af08 100644 --- a/x-pack/plugins/security_solution/common/detection_engine/schemas/request/patch_rules_schema.ts +++ b/x-pack/plugins/security_solution/common/detection_engine/schemas/request/patch_rules_schema.ts @@ -7,6 +7,32 @@ import * as t from 'io-ts'; +import { + actions, + from, + machine_learning_job_id, + risk_score, + risk_score_mapping, + threat_index, + concurrent_searches, + items_per_search, + threat_query, + threat_filters, + threat_mapping, + threat_language, + threat_indicator_path, + threats, + type, + language, + severity, + severity_mapping, + max_signals, + throttle, +} from '@kbn/securitysolution-io-ts-alerting-types'; + +import { version } from '@kbn/securitysolution-io-ts-types'; + +import { listArrayOrUndefined } from '@kbn/securitysolution-io-ts-list-types'; import { description, anomaly_threshold, @@ -17,27 +43,16 @@ import { timeline_id, timeline_title, meta, - machine_learning_job_id, - risk_score, rule_id, name, - severity, - type, note, - version, - actions, false_positives, interval, - max_signals, - from, enabled, tags, - threats, threshold, - throttle, references, to, - language, query, id, building_block_type, @@ -45,21 +60,8 @@ import { license, rule_name_override, timestamp_override, - risk_score_mapping, - severity_mapping, event_category_override, } from '../common/schemas'; -import { - threat_index, - concurrent_searches, - items_per_search, - threat_query, - threat_filters, - threat_mapping, - threat_language, - threat_indicator_path, -} from '../types/threat_mapping'; -import { listArrayOrUndefined } from '../types/lists'; /** * All of the patch elements should default to undefined if not set diff --git a/x-pack/plugins/security_solution/common/detection_engine/schemas/request/query_rules_bulk_schema.test.ts b/x-pack/plugins/security_solution/common/detection_engine/schemas/request/query_rules_bulk_schema.test.ts index 5c1ded9a6ec5..fa167090b2f3 100644 --- a/x-pack/plugins/security_solution/common/detection_engine/schemas/request/query_rules_bulk_schema.test.ts +++ b/x-pack/plugins/security_solution/common/detection_engine/schemas/request/query_rules_bulk_schema.test.ts @@ -6,9 +6,7 @@ */ import { queryRulesBulkSchema, QueryRulesBulkSchema } from './query_rules_bulk_schema'; -import { exactCheck } from '../../../exact_check'; -import { foldLeftRight } from '../../../test_utils'; -import { formatErrors } from '../../../format_errors'; +import { exactCheck, formatErrors, foldLeftRight } from '@kbn/securitysolution-io-ts-utils'; // only the basics of testing are here. // see: query_rules_schema.test.ts for the bulk of the validation tests diff --git a/x-pack/plugins/security_solution/common/detection_engine/schemas/request/query_rules_schema.test.ts b/x-pack/plugins/security_solution/common/detection_engine/schemas/request/query_rules_schema.test.ts index 95c045b90f80..566d752a8623 100644 --- a/x-pack/plugins/security_solution/common/detection_engine/schemas/request/query_rules_schema.test.ts +++ b/x-pack/plugins/security_solution/common/detection_engine/schemas/request/query_rules_schema.test.ts @@ -6,9 +6,8 @@ */ import { queryRulesSchema, QueryRulesSchema } from './query_rules_schema'; -import { exactCheck } from '../../../exact_check'; +import { exactCheck, foldLeftRight, getPaths } from '@kbn/securitysolution-io-ts-utils'; import { pipe } from 'fp-ts/lib/pipeable'; -import { foldLeftRight, getPaths } from '../../../test_utils'; import { left } from 'fp-ts/lib/Either'; describe('query_rules_schema', () => { diff --git a/x-pack/plugins/security_solution/common/detection_engine/schemas/request/query_signals_index_schema.test.ts b/x-pack/plugins/security_solution/common/detection_engine/schemas/request/query_signals_index_schema.test.ts index ef7dfb9496ec..65107079c580 100644 --- a/x-pack/plugins/security_solution/common/detection_engine/schemas/request/query_signals_index_schema.test.ts +++ b/x-pack/plugins/security_solution/common/detection_engine/schemas/request/query_signals_index_schema.test.ts @@ -6,9 +6,8 @@ */ import { QuerySignalsSchema, querySignalsSchema } from './query_signals_index_schema'; -import { exactCheck } from '../../../exact_check'; +import { exactCheck, foldLeftRight, getPaths } from '@kbn/securitysolution-io-ts-utils'; import { pipe } from 'fp-ts/lib/pipeable'; -import { foldLeftRight, getPaths } from '../../../test_utils'; import { left } from 'fp-ts/lib/Either'; describe('query, aggs, size, _source and track_total_hits on signals index', () => { diff --git a/x-pack/plugins/security_solution/common/detection_engine/schemas/request/query_signals_index_schema.ts b/x-pack/plugins/security_solution/common/detection_engine/schemas/request/query_signals_index_schema.ts index d7f17fd842b9..81761dd085df 100644 --- a/x-pack/plugins/security_solution/common/detection_engine/schemas/request/query_signals_index_schema.ts +++ b/x-pack/plugins/security_solution/common/detection_engine/schemas/request/query_signals_index_schema.ts @@ -6,7 +6,7 @@ */ import * as t from 'io-ts'; -import { PositiveIntegerGreaterThanZero } from '../types/positive_integer_greater_than_zero'; +import { PositiveIntegerGreaterThanZero } from '@kbn/securitysolution-io-ts-types'; export const querySignalsSchema = t.exact( t.partial({ diff --git a/x-pack/plugins/security_solution/common/detection_engine/schemas/request/rule_schemas.test.ts b/x-pack/plugins/security_solution/common/detection_engine/schemas/request/rule_schemas.test.ts index 70ff921d3b33..2e4a53766448 100644 --- a/x-pack/plugins/security_solution/common/detection_engine/schemas/request/rule_schemas.test.ts +++ b/x-pack/plugins/security_solution/common/detection_engine/schemas/request/rule_schemas.test.ts @@ -6,9 +6,8 @@ */ import { createRulesSchema, CreateRulesSchema, SavedQueryCreateSchema } from './rule_schemas'; -import { exactCheck } from '../../../exact_check'; +import { exactCheck, foldLeftRight, getPaths } from '@kbn/securitysolution-io-ts-utils'; import { pipe } from 'fp-ts/lib/pipeable'; -import { foldLeftRight, getPaths } from '../../../test_utils'; import { left } from 'fp-ts/lib/Either'; import { getCreateSavedQueryRulesSchemaMock, diff --git a/x-pack/plugins/security_solution/common/detection_engine/schemas/request/rule_schemas.ts b/x-pack/plugins/security_solution/common/detection_engine/schemas/request/rule_schemas.ts index c7b33372e595..dbc40763a0c6 100644 --- a/x-pack/plugins/security_solution/common/detection_engine/schemas/request/rule_schemas.ts +++ b/x-pack/plugins/security_solution/common/detection_engine/schemas/request/rule_schemas.ts @@ -7,8 +7,12 @@ import * as t from 'io-ts'; -import { listArray } from '../types/lists'; import { + actions, + from, + risk_score, + machine_learning_job_id, + risk_score_mapping, threat_filters, threat_query, threat_mapping, @@ -16,14 +20,20 @@ import { threat_indicator_path, concurrent_searches, items_per_search, -} from '../types/threat_mapping'; + threats, + severity_mapping, + severity, + max_signals, + throttle, +} from '@kbn/securitysolution-io-ts-alerting-types'; +import { listArray } from '@kbn/securitysolution-io-ts-list-types'; +import { version } from '@kbn/securitysolution-io-ts-types'; + import { id, index, filters, event_category_override, - risk_score_mapping, - severity_mapping, building_block_type, note, license, @@ -35,25 +45,17 @@ import { author, description, false_positives, - from, rule_id, immutable, output_index, query, - machine_learning_job_id, - max_signals, - risk_score, - severity, - threats, to, references, - version, saved_id, threshold, anomaly_threshold, name, tags, - actions, interval, enabled, updated_at, @@ -66,7 +68,6 @@ import { last_success_message, last_failure_at, last_failure_message, - throttle, } from '../common/schemas'; const createSchema = < diff --git a/x-pack/plugins/security_solution/common/detection_engine/schemas/request/set_signal_status_schema.test.ts b/x-pack/plugins/security_solution/common/detection_engine/schemas/request/set_signal_status_schema.test.ts index c189821090f5..994691ecfa57 100644 --- a/x-pack/plugins/security_solution/common/detection_engine/schemas/request/set_signal_status_schema.test.ts +++ b/x-pack/plugins/security_solution/common/detection_engine/schemas/request/set_signal_status_schema.test.ts @@ -6,9 +6,8 @@ */ import { setSignalsStatusSchema, SetSignalsStatusSchema } from './set_signal_status_schema'; -import { exactCheck } from '../../../exact_check'; +import { exactCheck, foldLeftRight, getPaths } from '@kbn/securitysolution-io-ts-utils'; import { pipe } from 'fp-ts/lib/pipeable'; -import { foldLeftRight, getPaths } from '../../../test_utils'; import { left } from 'fp-ts/lib/Either'; describe('set signal status schema', () => { diff --git a/x-pack/plugins/security_solution/common/detection_engine/schemas/request/update_rules_bulk_schema.test.ts b/x-pack/plugins/security_solution/common/detection_engine/schemas/request/update_rules_bulk_schema.test.ts index 3d0c579e3c46..63217186affe 100644 --- a/x-pack/plugins/security_solution/common/detection_engine/schemas/request/update_rules_bulk_schema.test.ts +++ b/x-pack/plugins/security_solution/common/detection_engine/schemas/request/update_rules_bulk_schema.test.ts @@ -6,9 +6,7 @@ */ import { updateRulesBulkSchema, UpdateRulesBulkSchema } from './update_rules_bulk_schema'; -import { exactCheck } from '../../../exact_check'; -import { foldLeftRight } from '../../../test_utils'; -import { formatErrors } from '../../../format_errors'; +import { exactCheck, formatErrors, foldLeftRight } from '@kbn/securitysolution-io-ts-utils'; import { getUpdateRulesSchemaMock } from './rule_schemas.mock'; import { UpdateRulesSchema } from './rule_schemas'; diff --git a/x-pack/plugins/security_solution/common/detection_engine/schemas/response/error_schema.test.ts b/x-pack/plugins/security_solution/common/detection_engine/schemas/response/error_schema.test.ts index a584c9254b17..5ef7f80a09a2 100644 --- a/x-pack/plugins/security_solution/common/detection_engine/schemas/response/error_schema.test.ts +++ b/x-pack/plugins/security_solution/common/detection_engine/schemas/response/error_schema.test.ts @@ -9,8 +9,7 @@ import { left } from 'fp-ts/lib/Either'; import { pipe } from 'fp-ts/lib/pipeable'; import { errorSchema, ErrorSchema } from './error_schema'; -import { exactCheck } from '../../../exact_check'; -import { foldLeftRight, getPaths } from '../../../test_utils'; +import { exactCheck, foldLeftRight, getPaths } from '@kbn/securitysolution-io-ts-utils'; import { getErrorSchemaMock } from './error_schema.mocks'; describe('error_schema', () => { diff --git a/x-pack/plugins/security_solution/common/detection_engine/schemas/response/import_rules_schema.test.ts b/x-pack/plugins/security_solution/common/detection_engine/schemas/response/import_rules_schema.test.ts index cb9876b0a165..4c8cdbdd427a 100644 --- a/x-pack/plugins/security_solution/common/detection_engine/schemas/response/import_rules_schema.test.ts +++ b/x-pack/plugins/security_solution/common/detection_engine/schemas/response/import_rules_schema.test.ts @@ -10,8 +10,7 @@ import { left, Either } from 'fp-ts/lib/Either'; import { ImportRulesSchema, importRulesSchema } from './import_rules_schema'; import { ErrorSchema } from './error_schema'; import { Errors } from 'io-ts'; -import { exactCheck } from '../../../exact_check'; -import { foldLeftRight, getPaths } from '../../../test_utils'; +import { exactCheck, foldLeftRight, getPaths } from '@kbn/securitysolution-io-ts-utils'; describe('import_rules_schema', () => { test('it should validate an empty import response with no errors', () => { diff --git a/x-pack/plugins/security_solution/common/detection_engine/schemas/response/prepackaged_rules_schema.test.ts b/x-pack/plugins/security_solution/common/detection_engine/schemas/response/prepackaged_rules_schema.test.ts index 67f3da845941..fbbc754f597a 100644 --- a/x-pack/plugins/security_solution/common/detection_engine/schemas/response/prepackaged_rules_schema.test.ts +++ b/x-pack/plugins/security_solution/common/detection_engine/schemas/response/prepackaged_rules_schema.test.ts @@ -11,8 +11,7 @@ import { PrePackagedRulesAndTimelinesSchema, prePackagedRulesAndTimelinesSchema, } from './prepackaged_rules_schema'; -import { exactCheck } from '../../../exact_check'; -import { foldLeftRight, getPaths } from '../../../test_utils'; +import { exactCheck, foldLeftRight, getPaths } from '@kbn/securitysolution-io-ts-utils'; describe('prepackaged_rules_schema', () => { test('it should validate an empty prepackaged response with defaults', () => { diff --git a/x-pack/plugins/security_solution/common/detection_engine/schemas/response/prepackaged_rules_status_schema.test.ts b/x-pack/plugins/security_solution/common/detection_engine/schemas/response/prepackaged_rules_status_schema.test.ts index 5a7b1dd14c34..de44c7e5e37a 100644 --- a/x-pack/plugins/security_solution/common/detection_engine/schemas/response/prepackaged_rules_status_schema.test.ts +++ b/x-pack/plugins/security_solution/common/detection_engine/schemas/response/prepackaged_rules_status_schema.test.ts @@ -11,8 +11,7 @@ import { PrePackagedRulesAndTimelinesStatusSchema, prePackagedRulesAndTimelinesStatusSchema, } from './prepackaged_rules_status_schema'; -import { exactCheck } from '../../../exact_check'; -import { foldLeftRight, getPaths } from '../../../test_utils'; +import { exactCheck, foldLeftRight, getPaths } from '@kbn/securitysolution-io-ts-utils'; describe('prepackaged_rules_schema', () => { test('it should validate an empty prepackaged response with defaults', () => { diff --git a/x-pack/plugins/security_solution/common/detection_engine/schemas/response/rules_bulk_schema.test.ts b/x-pack/plugins/security_solution/common/detection_engine/schemas/response/rules_bulk_schema.test.ts index 3501ecfc0c1b..55d5444bccf7 100644 --- a/x-pack/plugins/security_solution/common/detection_engine/schemas/response/rules_bulk_schema.test.ts +++ b/x-pack/plugins/security_solution/common/detection_engine/schemas/response/rules_bulk_schema.test.ts @@ -11,8 +11,7 @@ import { pipe } from 'fp-ts/lib/pipeable'; import { RulesBulkSchema, rulesBulkSchema } from './rules_bulk_schema'; import { RulesSchema } from './rules_schema'; import { ErrorSchema } from './error_schema'; -import { exactCheck } from '../../../exact_check'; -import { foldLeftRight, getPaths } from '../../../test_utils'; +import { exactCheck, foldLeftRight, getPaths } from '@kbn/securitysolution-io-ts-utils'; import { getRulesSchemaMock } from './rules_schema.mocks'; import { getErrorSchemaMock } from './error_schema.mocks'; diff --git a/x-pack/plugins/security_solution/common/detection_engine/schemas/response/rules_schema.test.ts b/x-pack/plugins/security_solution/common/detection_engine/schemas/response/rules_schema.test.ts index 4865c0ee77d5..a8521c013f45 100644 --- a/x-pack/plugins/security_solution/common/detection_engine/schemas/response/rules_schema.test.ts +++ b/x-pack/plugins/security_solution/common/detection_engine/schemas/response/rules_schema.test.ts @@ -21,8 +21,7 @@ import { addThreatMatchFields, addEqlFields, } from './rules_schema'; -import { exactCheck } from '../../../exact_check'; -import { foldLeftRight, getPaths } from '../../../test_utils'; +import { exactCheck, foldLeftRight, getPaths } from '@kbn/securitysolution-io-ts-utils'; import { TypeAndTimelineOnly } from './type_timeline_only_schema'; import { getRulesSchemaMock, @@ -30,7 +29,7 @@ import { getThreatMatchingSchemaMock, getRulesEqlSchemaMock, } from './rules_schema.mocks'; -import { ListArray } from '../types/lists'; +import { ListArray } from '@kbn/securitysolution-io-ts-list-types'; export const ANCHOR_DATE = '2020-02-20T03:57:54.037Z'; diff --git a/x-pack/plugins/security_solution/common/detection_engine/schemas/response/rules_schema.ts b/x-pack/plugins/security_solution/common/detection_engine/schemas/response/rules_schema.ts index 6bd54973e064..0924588600d3 100644 --- a/x-pack/plugins/security_solution/common/detection_engine/schemas/response/rules_schema.ts +++ b/x-pack/plugins/security_solution/common/detection_engine/schemas/response/rules_schema.ts @@ -10,59 +10,13 @@ import { isObject } from 'lodash/fp'; import { Either, left, fold } from 'fp-ts/lib/Either'; import { pipe } from 'fp-ts/lib/pipeable'; -import { isMlRule } from '../../../machine_learning/helpers'; -import { isThresholdRule } from '../../utils'; import { actions, - anomaly_threshold, - description, - enabled, - event_category_override, - false_positives, from, - id, - immutable, - index, - interval, - rule_id, - language, - name, - output_index, - max_signals, machine_learning_job_id, - query, - references, - severity, - updated_by, - tags, - to, risk_score, - created_at, - created_by, - updated_at, - saved_id, - timeline_id, - timeline_title, - type, - threats, - threshold, - throttle, - job_status, - status_date, - last_success_at, - last_success_message, - last_failure_at, - last_failure_message, - version, - filters, - meta, - note, - building_block_type, - license, - rule_name_override, - timestamp_override, -} from '../common/schemas'; -import { + DefaultRiskScoreMappingArray, + DefaultSeverityMappingArray, threat_index, concurrent_searches, items_per_search, @@ -71,14 +25,58 @@ import { threat_mapping, threat_language, threat_indicator_path, -} from '../types/threat_mapping'; + threats, + type, + language, + severity, + throttle, + max_signals, +} from '@kbn/securitysolution-io-ts-alerting-types'; +import { DefaultStringArray, version } from '@kbn/securitysolution-io-ts-types'; -import { DefaultListArray } from '../types/lists_default_array'; +import { DefaultListArray } from '@kbn/securitysolution-io-ts-list-types'; +import { isMlRule } from '../../../machine_learning/helpers'; +import { isThresholdRule } from '../../utils'; import { - DefaultStringArray, - DefaultRiskScoreMappingArray, - DefaultSeverityMappingArray, -} from '../types'; + anomaly_threshold, + description, + enabled, + event_category_override, + false_positives, + id, + immutable, + index, + interval, + rule_id, + name, + output_index, + query, + references, + updated_by, + tags, + to, + created_at, + created_by, + updated_at, + saved_id, + timeline_id, + timeline_title, + threshold, + job_status, + status_date, + last_success_at, + last_success_message, + last_failure_at, + last_failure_message, + filters, + meta, + note, + building_block_type, + license, + rule_name_override, + timestamp_override, +} from '../common/schemas'; + import { typeAndTimelineOnlySchema, TypeAndTimelineOnly } from './type_timeline_only_schema'; /** diff --git a/x-pack/plugins/security_solution/common/detection_engine/schemas/response/type_timeline_only_schema.test.ts b/x-pack/plugins/security_solution/common/detection_engine/schemas/response/type_timeline_only_schema.test.ts index 7099b03de58b..58612376760b 100644 --- a/x-pack/plugins/security_solution/common/detection_engine/schemas/response/type_timeline_only_schema.test.ts +++ b/x-pack/plugins/security_solution/common/detection_engine/schemas/response/type_timeline_only_schema.test.ts @@ -9,8 +9,7 @@ import { left } from 'fp-ts/lib/Either'; import { pipe } from 'fp-ts/lib/pipeable'; import { TypeAndTimelineOnly, typeAndTimelineOnlySchema } from './type_timeline_only_schema'; -import { exactCheck } from '../../../exact_check'; -import { foldLeftRight, getPaths } from '../../../test_utils'; +import { exactCheck, foldLeftRight, getPaths } from '@kbn/securitysolution-io-ts-utils'; describe('prepackaged_rule_schema', () => { test('it should validate a a type and timeline_id together', () => { diff --git a/x-pack/plugins/security_solution/common/detection_engine/schemas/response/type_timeline_only_schema.ts b/x-pack/plugins/security_solution/common/detection_engine/schemas/response/type_timeline_only_schema.ts index 3aff1b62dfb9..b164ab9b44e4 100644 --- a/x-pack/plugins/security_solution/common/detection_engine/schemas/response/type_timeline_only_schema.ts +++ b/x-pack/plugins/security_solution/common/detection_engine/schemas/response/type_timeline_only_schema.ts @@ -7,7 +7,8 @@ import * as t from 'io-ts'; -import { timeline_id, type } from '../common/schemas'; +import { type } from '@kbn/securitysolution-io-ts-alerting-types'; +import { timeline_id } from '../common/schemas'; /** * Special schema type that is only the type and the timeline_id. diff --git a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/deafult_boolean_true.test.ts b/x-pack/plugins/security_solution/common/detection_engine/schemas/types/deafult_boolean_true.test.ts deleted file mode 100644 index 14b4f034358c..000000000000 --- a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/deafult_boolean_true.test.ts +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { DefaultBooleanTrue } from './default_boolean_true'; -import { pipe } from 'fp-ts/lib/pipeable'; -import { left } from 'fp-ts/lib/Either'; -import { foldLeftRight, getPaths } from '../../../test_utils'; - -describe('default_boolean_true', () => { - test('it should validate a boolean false', () => { - const payload = false; - const decoded = DefaultBooleanTrue.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([]); - expect(message.schema).toEqual(payload); - }); - - test('it should validate a boolean true', () => { - const payload = true; - const decoded = DefaultBooleanTrue.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([]); - expect(message.schema).toEqual(payload); - }); - - test('it should not validate a number', () => { - const payload = 5; - const decoded = DefaultBooleanTrue.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([ - 'Invalid value "5" supplied to "DefaultBooleanTrue"', - ]); - expect(message.schema).toEqual({}); - }); - - test('it should return a default true', () => { - const payload = null; - const decoded = DefaultBooleanTrue.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([]); - expect(message.schema).toEqual(true); - }); -}); diff --git a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/deafult_from_string.test.ts b/x-pack/plugins/security_solution/common/detection_engine/schemas/types/deafult_from_string.test.ts deleted file mode 100644 index ca3ecb2bfb90..000000000000 --- a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/deafult_from_string.test.ts +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { DefaultFromString } from './default_from_string'; -import { pipe } from 'fp-ts/lib/pipeable'; -import { left } from 'fp-ts/lib/Either'; -import { foldLeftRight, getPaths } from '../../../test_utils'; - -describe('default_from_string', () => { - test('it should validate a from string', () => { - const payload = 'now-20m'; - const decoded = DefaultFromString.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([]); - expect(message.schema).toEqual(payload); - }); - - test('it should not validate a number', () => { - const payload = 5; - const decoded = DefaultFromString.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([ - 'Invalid value "5" supplied to "DefaultFromString"', - ]); - expect(message.schema).toEqual({}); - }); - - test('it should return a default of "now-6m"', () => { - const payload = null; - const decoded = DefaultFromString.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([]); - expect(message.schema).toEqual('now-6m'); - }); -}); diff --git a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_actions_array.test.ts b/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_actions_array.test.ts deleted file mode 100644 index 993e96f5d319..000000000000 --- a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_actions_array.test.ts +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { DefaultActionsArray } from './default_actions_array'; -import { pipe } from 'fp-ts/lib/pipeable'; -import { left } from 'fp-ts/lib/Either'; -import { foldLeftRight, getPaths } from '../../../test_utils'; -import { Actions } from '../common/schemas'; - -describe('default_actions_array', () => { - test('it should validate an empty array', () => { - const payload: string[] = []; - const decoded = DefaultActionsArray.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([]); - expect(message.schema).toEqual(payload); - }); - - test('it should validate an array of actions', () => { - const payload: Actions = [ - { id: '123', group: 'group', action_type_id: 'action_type_id', params: {} }, - ]; - const decoded = DefaultActionsArray.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([]); - expect(message.schema).toEqual(payload); - }); - - test('it should not validate an array with a number', () => { - const payload = [ - { id: '123', group: 'group', action_type_id: 'action_type_id', params: {} }, - 5, - ]; - const decoded = DefaultActionsArray.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([ - 'Invalid value "5" supplied to "DefaultActionsArray"', - ]); - expect(message.schema).toEqual({}); - }); - - test('it should return a default array entry', () => { - const payload = null; - const decoded = DefaultActionsArray.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([]); - expect(message.schema).toEqual([]); - }); -}); diff --git a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_actions_array.ts b/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_actions_array.ts deleted file mode 100644 index 49302102ddee..000000000000 --- a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_actions_array.ts +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import * as t from 'io-ts'; -import { Either } from 'fp-ts/lib/Either'; -import { actions, Actions } from '../common/schemas'; - -/** - * Types the DefaultStringArray as: - * - If undefined, then a default action array will be set - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export const DefaultActionsArray = new t.Type( - 'DefaultActionsArray', - actions.is, - (input, context): Either => - input == null ? t.success([]) : actions.validate(input, context), - t.identity -); diff --git a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_array.test.ts b/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_array.test.ts deleted file mode 100644 index 92c2669071f1..000000000000 --- a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_array.test.ts +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import * as t from 'io-ts'; - -import { DefaultArray } from './default_array'; -import { pipe } from 'fp-ts/lib/pipeable'; -import { left } from 'fp-ts/lib/Either'; -import { foldLeftRight, getPaths } from '../../../test_utils'; - -const testSchema = t.keyof({ - valid: true, - also_valid: true, -}); -type TestSchema = t.TypeOf; - -const defaultArraySchema = DefaultArray(testSchema); - -describe('default_array', () => { - test('it should validate an empty array', () => { - const payload: string[] = []; - const decoded = defaultArraySchema.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([]); - expect(message.schema).toEqual(payload); - }); - - test('it should validate an array of testSchema', () => { - const payload: TestSchema[] = ['valid']; - const decoded = defaultArraySchema.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([]); - expect(message.schema).toEqual(payload); - }); - - test('it should validate an array of valid testSchema strings', () => { - const payload = ['valid', 'also_valid']; - const decoded = defaultArraySchema.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([]); - expect(message.schema).toEqual(payload); - }); - - test('it should not validate an array with a number', () => { - const payload = ['valid', 123]; - const decoded = defaultArraySchema.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([ - 'Invalid value "123" supplied to "DefaultArray"', - ]); - expect(message.schema).toEqual({}); - }); - - test('it should not validate an array with an invalid string', () => { - const payload = ['valid', 'invalid']; - const decoded = defaultArraySchema.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([ - 'Invalid value "invalid" supplied to "DefaultArray"', - ]); - expect(message.schema).toEqual({}); - }); - - test('it should return a default array entry', () => { - const payload = null; - const decoded = defaultArraySchema.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([]); - expect(message.schema).toEqual([]); - }); -}); diff --git a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_array.ts b/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_array.ts deleted file mode 100644 index a6397754b23d..000000000000 --- a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_array.ts +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import * as t from 'io-ts'; -import { Either } from 'fp-ts/lib/Either'; - -/** - * Types the DefaultArray as: - * - If undefined, then a default array will be set - * - If an array is sent in, then the array will be validated to ensure all elements are type C - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export const DefaultArray = (codec: C) => { - const arrType = t.array(codec); - type ArrType = t.TypeOf; - return new t.Type( - 'DefaultArray', - arrType.is, - (input, context): Either => - input == null ? t.success([]) : arrType.validate(input, context), - t.identity - ); -}; diff --git a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_boolean_false.test.ts b/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_boolean_false.test.ts deleted file mode 100644 index c01efa6e55d4..000000000000 --- a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_boolean_false.test.ts +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { DefaultBooleanFalse } from './default_boolean_false'; -import { pipe } from 'fp-ts/lib/pipeable'; -import { left } from 'fp-ts/lib/Either'; -import { foldLeftRight, getPaths } from '../../../test_utils'; - -describe('default_boolean_false', () => { - test('it should validate a boolean false', () => { - const payload = false; - const decoded = DefaultBooleanFalse.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([]); - expect(message.schema).toEqual(payload); - }); - - test('it should validate a boolean true', () => { - const payload = true; - const decoded = DefaultBooleanFalse.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([]); - expect(message.schema).toEqual(payload); - }); - - test('it should not validate a number', () => { - const payload = 5; - const decoded = DefaultBooleanFalse.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([ - 'Invalid value "5" supplied to "DefaultBooleanFalse"', - ]); - expect(message.schema).toEqual({}); - }); - - test('it should return a default false', () => { - const payload = null; - const decoded = DefaultBooleanFalse.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([]); - expect(message.schema).toEqual(false); - }); -}); diff --git a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_boolean_false.ts b/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_boolean_false.ts deleted file mode 100644 index 46e7bde55638..000000000000 --- a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_boolean_false.ts +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import * as t from 'io-ts'; -import { Either } from 'fp-ts/lib/Either'; - -/** - * Types the DefaultBooleanFalse as: - * - If null or undefined, then a default false will be set - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export const DefaultBooleanFalse = new t.Type( - 'DefaultBooleanFalse', - t.boolean.is, - (input, context): Either => - input == null ? t.success(false) : t.boolean.validate(input, context), - t.identity -); diff --git a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_boolean_true.ts b/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_boolean_true.ts deleted file mode 100644 index 3845150841c2..000000000000 --- a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_boolean_true.ts +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import * as t from 'io-ts'; -import { Either } from 'fp-ts/lib/Either'; - -/** - * Types the DefaultBooleanTrue as: - * - If null or undefined, then a default true will be set - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export const DefaultBooleanTrue = new t.Type( - 'DefaultBooleanTrue', - t.boolean.is, - (input, context): Either => - input == null ? t.success(true) : t.boolean.validate(input, context), - t.identity -); diff --git a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_empty_string.test.ts b/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_empty_string.test.ts deleted file mode 100644 index 08a5354dc74b..000000000000 --- a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_empty_string.test.ts +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { DefaultEmptyString } from './default_empty_string'; -import { pipe } from 'fp-ts/lib/pipeable'; -import { left } from 'fp-ts/lib/Either'; -import { foldLeftRight, getPaths } from '../../../test_utils'; - -describe('default_empty_string', () => { - test('it should validate a regular string', () => { - const payload = 'some string'; - const decoded = DefaultEmptyString.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([]); - expect(message.schema).toEqual(payload); - }); - - test('it should not validate a number', () => { - const payload = 5; - const decoded = DefaultEmptyString.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([ - 'Invalid value "5" supplied to "DefaultEmptyString"', - ]); - expect(message.schema).toEqual({}); - }); - - test('it should return a default of ""', () => { - const payload = null; - const decoded = DefaultEmptyString.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([]); - expect(message.schema).toEqual(''); - }); -}); diff --git a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_empty_string.ts b/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_empty_string.ts deleted file mode 100644 index 77a06a928a2e..000000000000 --- a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_empty_string.ts +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import * as t from 'io-ts'; -import { Either } from 'fp-ts/lib/Either'; - -/** - * Types the DefaultEmptyString as: - * - If null or undefined, then a default of an empty string "" will be used - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export const DefaultEmptyString = new t.Type( - 'DefaultEmptyString', - t.string.is, - (input, context): Either => - input == null ? t.success('') : t.string.validate(input, context), - t.identity -); diff --git a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_export_file_name.test.ts b/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_export_file_name.test.ts deleted file mode 100644 index f53c6d801dc5..000000000000 --- a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_export_file_name.test.ts +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { DefaultExportFileName } from './default_export_file_name'; -import { pipe } from 'fp-ts/lib/pipeable'; -import { left } from 'fp-ts/lib/Either'; -import { foldLeftRight, getPaths } from '../../../test_utils'; - -describe('default_export_file_name', () => { - test('it should validate a regular string', () => { - const payload = 'some string'; - const decoded = DefaultExportFileName.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([]); - expect(message.schema).toEqual(payload); - }); - - test('it should not validate a number', () => { - const payload = 5; - const decoded = DefaultExportFileName.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([ - 'Invalid value "5" supplied to "DefaultExportFileName"', - ]); - expect(message.schema).toEqual({}); - }); - - test('it should return a default of "export.ndjson"', () => { - const payload = null; - const decoded = DefaultExportFileName.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([]); - expect(message.schema).toEqual('export.ndjson'); - }); -}); diff --git a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_export_file_name.ts b/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_export_file_name.ts deleted file mode 100644 index a2b2fb6eaad3..000000000000 --- a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_export_file_name.ts +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import * as t from 'io-ts'; -import { Either } from 'fp-ts/lib/Either'; - -/** - * Types the DefaultExportFileName as: - * - If null or undefined, then a default of "export.ndjson" will be used - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export const DefaultExportFileName = new t.Type( - 'DefaultExportFileName', - t.string.is, - (input, context): Either => - input == null ? t.success('export.ndjson') : t.string.validate(input, context), - t.identity -); diff --git a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_from_string.ts b/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_from_string.ts deleted file mode 100644 index a2eb2a2b9f46..000000000000 --- a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_from_string.ts +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import * as t from 'io-ts'; -import { Either } from 'fp-ts/lib/Either'; -import { from } from '../common/schemas'; -/** - * Types the DefaultFromString as: - * - If null or undefined, then a default of the string "now-6m" will be used - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export const DefaultFromString = new t.Type( - 'DefaultFromString', - t.string.is, - (input, context): Either => { - if (input == null) { - return t.success('now-6m'); - } - return from.validate(input, context); - }, - t.identity -); diff --git a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_interval_string.test.ts b/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_interval_string.test.ts deleted file mode 100644 index 99e15403ef3a..000000000000 --- a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_interval_string.test.ts +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { DefaultIntervalString } from './default_interval_string'; -import { pipe } from 'fp-ts/lib/pipeable'; -import { left } from 'fp-ts/lib/Either'; -import { foldLeftRight, getPaths } from '../../../test_utils'; - -describe('default_interval_string', () => { - test('it should validate a interval string', () => { - const payload = '20m'; - const decoded = DefaultIntervalString.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([]); - expect(message.schema).toEqual(payload); - }); - - test('it should not validate a number', () => { - const payload = 5; - const decoded = DefaultIntervalString.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([ - 'Invalid value "5" supplied to "DefaultIntervalString"', - ]); - expect(message.schema).toEqual({}); - }); - - test('it should return a default of "5m"', () => { - const payload = null; - const decoded = DefaultIntervalString.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([]); - expect(message.schema).toEqual('5m'); - }); -}); diff --git a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_interval_string.ts b/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_interval_string.ts deleted file mode 100644 index fb3a5931199a..000000000000 --- a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_interval_string.ts +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import * as t from 'io-ts'; -import { Either } from 'fp-ts/lib/Either'; - -/** - * Types the DefaultIntervalString as: - * - If null or undefined, then a default of the string "5m" will be used - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export const DefaultIntervalString = new t.Type( - 'DefaultIntervalString', - t.string.is, - (input, context): Either => - input == null ? t.success('5m') : t.string.validate(input, context), - t.identity -); diff --git a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_language_string.test.ts b/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_language_string.test.ts deleted file mode 100644 index 615f27e08b19..000000000000 --- a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_language_string.test.ts +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { DefaultLanguageString } from './default_language_string'; -import { pipe } from 'fp-ts/lib/pipeable'; -import { left } from 'fp-ts/lib/Either'; -import { foldLeftRight, getPaths } from '../../../test_utils'; -import { Language } from '../common/schemas'; - -describe('default_language_string', () => { - test('it should validate a string', () => { - const payload: Language = 'lucene'; - const decoded = DefaultLanguageString.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([]); - expect(message.schema).toEqual(payload); - }); - - test('it should not validate a number', () => { - const payload = 5; - const decoded = DefaultLanguageString.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([ - 'Invalid value "5" supplied to "DefaultLanguageString"', - ]); - expect(message.schema).toEqual({}); - }); - - test('it should return a default of "kuery"', () => { - const payload = null; - const decoded = DefaultLanguageString.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([]); - expect(message.schema).toEqual('kuery'); - }); -}); diff --git a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_language_string.ts b/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_language_string.ts deleted file mode 100644 index a40b0d8eeaca..000000000000 --- a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_language_string.ts +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import * as t from 'io-ts'; -import { Either } from 'fp-ts/lib/Either'; -import { language } from '../common/schemas'; - -/** - * Types the DefaultLanguageString as: - * - If null or undefined, then a default of the string "kuery" will be used - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export const DefaultLanguageString = new t.Type( - 'DefaultLanguageString', - t.string.is, - (input, context): Either => - input == null ? t.success('kuery') : language.validate(input, context), - t.identity -); diff --git a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_max_signals_number.test.ts b/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_max_signals_number.test.ts deleted file mode 100644 index bdfdc15150b9..000000000000 --- a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_max_signals_number.test.ts +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { DefaultMaxSignalsNumber } from './default_max_signals_number'; -import { pipe } from 'fp-ts/lib/pipeable'; -import { left } from 'fp-ts/lib/Either'; -import { foldLeftRight, getPaths } from '../../../test_utils'; -import { DEFAULT_MAX_SIGNALS } from '../../../constants'; - -describe('default_from_string', () => { - test('it should validate a max signal number', () => { - const payload = 5; - const decoded = DefaultMaxSignalsNumber.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([]); - expect(message.schema).toEqual(payload); - }); - - test('it should not validate a string', () => { - const payload = '5'; - const decoded = DefaultMaxSignalsNumber.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([ - 'Invalid value "5" supplied to "DefaultMaxSignals"', - ]); - expect(message.schema).toEqual({}); - }); - - test('it should not validate a zero', () => { - const payload = 0; - const decoded = DefaultMaxSignalsNumber.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([ - 'Invalid value "0" supplied to "DefaultMaxSignals"', - ]); - expect(message.schema).toEqual({}); - }); - - test('it should not validate a negative number', () => { - const payload = -1; - const decoded = DefaultMaxSignalsNumber.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([ - 'Invalid value "-1" supplied to "DefaultMaxSignals"', - ]); - expect(message.schema).toEqual({}); - }); - - test('it should return a default of DEFAULT_MAX_SIGNALS', () => { - const payload = null; - const decoded = DefaultMaxSignalsNumber.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([]); - expect(message.schema).toEqual(DEFAULT_MAX_SIGNALS); - }); -}); diff --git a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_max_signals_number.ts b/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_max_signals_number.ts deleted file mode 100644 index d9209cdba4d0..000000000000 --- a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_max_signals_number.ts +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import * as t from 'io-ts'; -import { Either } from 'fp-ts/lib/Either'; -import { max_signals } from '../common/schemas'; -import { DEFAULT_MAX_SIGNALS } from '../../../constants'; - -/** - * Types the default max signal: - * - Natural Number (positive integer and not a float), - * - greater than 1 - * - If undefined then it will use DEFAULT_MAX_SIGNALS (100) as the default - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export const DefaultMaxSignalsNumber = new t.Type( - 'DefaultMaxSignals', - t.number.is, - (input, context): Either => { - return input == null ? t.success(DEFAULT_MAX_SIGNALS) : max_signals.validate(input, context); - }, - t.identity -); diff --git a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_page.test.ts b/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_page.test.ts deleted file mode 100644 index 939245412758..000000000000 --- a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_page.test.ts +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { DefaultPage } from './default_page'; -import { pipe } from 'fp-ts/lib/pipeable'; -import { left } from 'fp-ts/lib/Either'; -import { foldLeftRight, getPaths } from '../../../test_utils'; - -describe('default_page', () => { - test('it should validate a regular number greater than zero', () => { - const payload = 5; - const decoded = DefaultPage.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([]); - expect(message.schema).toEqual(payload); - }); - - test('it should validate a string of a number', () => { - const payload = '5'; - const decoded = DefaultPage.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([]); - expect(message.schema).toEqual(5); - }); - - test('it should not validate a junk string', () => { - const payload = 'invalid-string'; - const decoded = DefaultPage.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([ - 'Invalid value "NaN" supplied to "DefaultPerPage"', - ]); - expect(message.schema).toEqual({}); - }); - - test('it should not validate an empty string', () => { - const payload = ''; - const decoded = DefaultPage.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([ - 'Invalid value "NaN" supplied to "DefaultPerPage"', - ]); - expect(message.schema).toEqual({}); - }); - - test('it should not validate a zero', () => { - const payload = 0; - const decoded = DefaultPage.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([ - 'Invalid value "0" supplied to "DefaultPerPage"', - ]); - expect(message.schema).toEqual({}); - }); - - test('it should not validate a negative number', () => { - const payload = -1; - const decoded = DefaultPage.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([ - 'Invalid value "-1" supplied to "DefaultPerPage"', - ]); - expect(message.schema).toEqual({}); - }); - - test('it should return a default of 20', () => { - const payload = null; - const decoded = DefaultPage.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([]); - expect(message.schema).toEqual(1); - }); -}); diff --git a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_page.ts b/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_page.ts deleted file mode 100644 index 2f2cdaf3b6cd..000000000000 --- a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_page.ts +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import * as t from 'io-ts'; -import { Either } from 'fp-ts/lib/Either'; -import { PositiveIntegerGreaterThanZero } from './positive_integer_greater_than_zero'; - -/** - * Types the DefaultPerPage as: - * - If a string this will convert the string to a number - * - If null or undefined, then a default of 1 will be used - * - If the number is 0 or less this will not validate as it has to be a positive number greater than zero - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export const DefaultPage = new t.Type( - 'DefaultPerPage', - t.number.is, - (input, context): Either => { - if (input == null) { - return t.success(1); - } else if (typeof input === 'string') { - return PositiveIntegerGreaterThanZero.validate(parseInt(input, 10), context); - } else { - return PositiveIntegerGreaterThanZero.validate(input, context); - } - }, - t.identity -); diff --git a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_per_page.test.ts b/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_per_page.test.ts deleted file mode 100644 index 5a550dca120e..000000000000 --- a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_per_page.test.ts +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { DefaultPerPage } from './default_per_page'; -import { pipe } from 'fp-ts/lib/pipeable'; -import { left } from 'fp-ts/lib/Either'; -import { foldLeftRight, getPaths } from '../../../test_utils'; - -describe('default_per_page', () => { - test('it should validate a regular number greater than zero', () => { - const payload = 5; - const decoded = DefaultPerPage.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([]); - expect(message.schema).toEqual(payload); - }); - - test('it should validate a string of a number', () => { - const payload = '5'; - const decoded = DefaultPerPage.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([]); - expect(message.schema).toEqual(5); - }); - - test('it should not validate a junk string', () => { - const payload = 'invalid-string'; - const decoded = DefaultPerPage.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([ - 'Invalid value "NaN" supplied to "DefaultPerPage"', - ]); - expect(message.schema).toEqual({}); - }); - - test('it should not validate an empty string', () => { - const payload = ''; - const decoded = DefaultPerPage.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([ - 'Invalid value "NaN" supplied to "DefaultPerPage"', - ]); - expect(message.schema).toEqual({}); - }); - - test('it should not validate a zero', () => { - const payload = 0; - const decoded = DefaultPerPage.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([ - 'Invalid value "0" supplied to "DefaultPerPage"', - ]); - expect(message.schema).toEqual({}); - }); - - test('it should not validate a negative number', () => { - const payload = -1; - const decoded = DefaultPerPage.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([ - 'Invalid value "-1" supplied to "DefaultPerPage"', - ]); - expect(message.schema).toEqual({}); - }); - - test('it should return a default of 20', () => { - const payload = null; - const decoded = DefaultPerPage.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([]); - expect(message.schema).toEqual(20); - }); -}); diff --git a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_per_page.ts b/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_per_page.ts deleted file mode 100644 index 124fdf25917f..000000000000 --- a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_per_page.ts +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import * as t from 'io-ts'; -import { Either } from 'fp-ts/lib/Either'; -import { PositiveIntegerGreaterThanZero } from './positive_integer_greater_than_zero'; - -/** - * Types the DefaultPerPage as: - * - If a string this will convert the string to a number - * - If null or undefined, then a default of 20 will be used - * - If the number is 0 or less this will not validate as it has to be a positive number greater than zero - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export const DefaultPerPage = new t.Type( - 'DefaultPerPage', - t.number.is, - (input, context): Either => { - if (input == null) { - return t.success(20); - } else if (typeof input === 'string') { - return PositiveIntegerGreaterThanZero.validate(parseInt(input, 10), context); - } else { - return PositiveIntegerGreaterThanZero.validate(input, context); - } - }, - t.identity -); diff --git a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_risk_score_mapping_array.ts b/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_risk_score_mapping_array.ts deleted file mode 100644 index 219b9d30b52e..000000000000 --- a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_risk_score_mapping_array.ts +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import * as t from 'io-ts'; -import { Either } from 'fp-ts/lib/Either'; -import { risk_score_mapping, RiskScoreMapping } from '../common/schemas'; - -/** - * Types the DefaultStringArray as: - * - If null or undefined, then a default risk_score_mapping array will be set - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export const DefaultRiskScoreMappingArray = new t.Type< - RiskScoreMapping, - RiskScoreMapping | undefined, - unknown ->( - 'DefaultRiskScoreMappingArray', - risk_score_mapping.is, - (input, context): Either => - input == null ? t.success([]) : risk_score_mapping.validate(input, context), - t.identity -); diff --git a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_severity_mapping_array.ts b/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_severity_mapping_array.ts deleted file mode 100644 index fe6557438329..000000000000 --- a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_severity_mapping_array.ts +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import * as t from 'io-ts'; -import { Either } from 'fp-ts/lib/Either'; -import { severity_mapping, SeverityMapping } from '../common/schemas'; - -/** - * Types the DefaultStringArray as: - * - If null or undefined, then a default severity_mapping array will be set - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export const DefaultSeverityMappingArray = new t.Type< - SeverityMapping, - SeverityMapping | undefined, - unknown ->( - 'DefaultSeverityMappingArray', - severity_mapping.is, - (input, context): Either => - input == null ? t.success([]) : severity_mapping.validate(input, context), - t.identity -); diff --git a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_string_array.test.ts b/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_string_array.test.ts deleted file mode 100644 index c8995f6a7cef..000000000000 --- a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_string_array.test.ts +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { DefaultStringArray } from './default_string_array'; -import { pipe } from 'fp-ts/lib/pipeable'; -import { left } from 'fp-ts/lib/Either'; -import { foldLeftRight, getPaths } from '../../../test_utils'; - -describe('default_string_array', () => { - test('it should validate an empty array', () => { - const payload: string[] = []; - const decoded = DefaultStringArray.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([]); - expect(message.schema).toEqual(payload); - }); - - test('it should validate an array of strings', () => { - const payload = ['value 1', 'value 2']; - const decoded = DefaultStringArray.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([]); - expect(message.schema).toEqual(payload); - }); - - test('it should not validate an array with a number', () => { - const payload = ['value 1', 5]; - const decoded = DefaultStringArray.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([ - 'Invalid value "5" supplied to "DefaultStringArray"', - ]); - expect(message.schema).toEqual({}); - }); - - test('it should return a default array entry', () => { - const payload = null; - const decoded = DefaultStringArray.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([]); - expect(message.schema).toEqual([]); - }); -}); diff --git a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_string_array.ts b/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_string_array.ts deleted file mode 100644 index be4b5563ddb1..000000000000 --- a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_string_array.ts +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import * as t from 'io-ts'; -import { Either } from 'fp-ts/lib/Either'; - -/** - * Types the DefaultStringArray as: - * - If undefined, then a default array will be set - * - If an array is sent in, then the array will be validated to ensure all elements are a string - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export const DefaultStringArray = new t.Type( - 'DefaultStringArray', - t.array(t.string).is, - (input, context): Either => - input == null ? t.success([]) : t.array(t.string).validate(input, context), - t.identity -); diff --git a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_string_boolean_false.test.ts b/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_string_boolean_false.test.ts deleted file mode 100644 index 2ee3e87e37e0..000000000000 --- a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_string_boolean_false.test.ts +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { pipe } from 'fp-ts/lib/pipeable'; -import { left } from 'fp-ts/lib/Either'; -import { foldLeftRight, getPaths } from '../../../test_utils'; -import { DefaultStringBooleanFalse } from './default_string_boolean_false'; - -describe('default_string_boolean_false', () => { - test('it should validate a boolean false', () => { - const payload = false; - const decoded = DefaultStringBooleanFalse.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([]); - expect(message.schema).toEqual(payload); - }); - - test('it should validate a boolean true', () => { - const payload = true; - const decoded = DefaultStringBooleanFalse.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([]); - expect(message.schema).toEqual(payload); - }); - - test('it should not validate a number', () => { - const payload = 5; - const decoded = DefaultStringBooleanFalse.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([ - 'Invalid value "5" supplied to "DefaultStringBooleanFalse"', - ]); - expect(message.schema).toEqual({}); - }); - - test('it should return a default false', () => { - const payload = null; - const decoded = DefaultStringBooleanFalse.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([]); - expect(message.schema).toEqual(false); - }); - - test('it should return a default false when given a string of "false"', () => { - const payload = 'false'; - const decoded = DefaultStringBooleanFalse.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([]); - expect(message.schema).toEqual(false); - }); - - test('it should return a default true when given a string of "true"', () => { - const payload = 'true'; - const decoded = DefaultStringBooleanFalse.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([]); - expect(message.schema).toEqual(true); - }); - - test('it should return a default true when given a string of "TruE"', () => { - const payload = 'TruE'; - const decoded = DefaultStringBooleanFalse.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([]); - expect(message.schema).toEqual(true); - }); - - test('it should not work with a string of junk "junk"', () => { - const payload = 'junk'; - const decoded = DefaultStringBooleanFalse.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([ - 'Invalid value "junk" supplied to "DefaultStringBooleanFalse"', - ]); - expect(message.schema).toEqual({}); - }); - - test('it should not work with an empty string', () => { - const payload = ''; - const decoded = DefaultStringBooleanFalse.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([ - 'Invalid value "" supplied to "DefaultStringBooleanFalse"', - ]); - expect(message.schema).toEqual({}); - }); -}); diff --git a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_string_boolean_false.ts b/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_string_boolean_false.ts deleted file mode 100644 index 69bd4564fd3b..000000000000 --- a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_string_boolean_false.ts +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import * as t from 'io-ts'; -import { Either } from 'fp-ts/lib/Either'; - -/** - * Types the DefaultStringBooleanFalse as: - * - If a string this will convert the string to a boolean - * - If null or undefined, then a default false will be set - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export const DefaultStringBooleanFalse = new t.Type( - 'DefaultStringBooleanFalse', - t.boolean.is, - (input, context): Either => { - if (input == null) { - return t.success(false); - } else if (typeof input === 'string' && input.toLowerCase() === 'true') { - return t.success(true); - } else if (typeof input === 'string' && input.toLowerCase() === 'false') { - return t.success(false); - } else { - return t.boolean.validate(input, context); - } - }, - t.identity -); - -export type DefaultStringBooleanFalseC = typeof DefaultStringBooleanFalse; diff --git a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_threat_array.test.ts b/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_threat_array.test.ts deleted file mode 100644 index d04338586371..000000000000 --- a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_threat_array.test.ts +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { DefaultThreatArray } from './default_threat_array'; -import { pipe } from 'fp-ts/lib/pipeable'; -import { left } from 'fp-ts/lib/Either'; -import { foldLeftRight, getPaths } from '../../../test_utils'; -import { Threats } from '../common/schemas'; - -describe('default_threat_null', () => { - test('it should validate an empty array', () => { - const payload: Threats = []; - const decoded = DefaultThreatArray.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([]); - expect(message.schema).toEqual(payload); - }); - - test('it should validate an array of threats', () => { - const payload: Threats = [ - { - framework: 'MITRE ATTACK', - technique: [{ reference: 'https://test.com', name: 'Audio Capture', id: 'T1123' }], - tactic: { reference: 'https://test.com', name: 'Collection', id: 'TA000999' }, - }, - ]; - const decoded = DefaultThreatArray.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([]); - expect(message.schema).toEqual(payload); - }); - - test('it should not validate an array with a number', () => { - const payload = [ - { - framework: 'MITRE ATTACK', - technique: [{ reference: 'https://test.com', name: 'Audio Capture', id: 'T1123' }], - tactic: { reference: 'https://test.com', name: 'Collection', id: 'TA000999' }, - }, - 5, - ]; - const decoded = DefaultThreatArray.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([ - 'Invalid value "5" supplied to "DefaultThreatArray"', - ]); - expect(message.schema).toEqual({}); - }); - - test('it should return a default empty array if not provided a value', () => { - const payload = null; - const decoded = DefaultThreatArray.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([]); - expect(message.schema).toEqual([]); - }); -}); diff --git a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_threat_array.ts b/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_threat_array.ts deleted file mode 100644 index 86c7ab245d6f..000000000000 --- a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_threat_array.ts +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import * as t from 'io-ts'; -import { Either } from 'fp-ts/lib/Either'; -import { Threats, threats } from '../common/schemas'; - -/** - * Types the DefaultThreatArray as: - * - If null or undefined, then an empty array will be set - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export const DefaultThreatArray = new t.Type( - 'DefaultThreatArray', - threats.is, - (input, context): Either => - input == null ? t.success([]) : threats.validate(input, context), - t.identity -); diff --git a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_throttle_null.test.ts b/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_throttle_null.test.ts deleted file mode 100644 index 1f29718533c1..000000000000 --- a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_throttle_null.test.ts +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { DefaultThrottleNull } from './default_throttle_null'; -import { pipe } from 'fp-ts/lib/pipeable'; -import { left } from 'fp-ts/lib/Either'; -import { foldLeftRight, getPaths } from '../../../test_utils'; -import { Throttle } from '../common/schemas'; - -describe('default_throttle_null', () => { - test('it should validate a throttle string', () => { - const payload: Throttle = 'some string'; - const decoded = DefaultThrottleNull.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([]); - expect(message.schema).toEqual(payload); - }); - - test('it should not validate an array with a number', () => { - const payload = 5; - const decoded = DefaultThrottleNull.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([ - 'Invalid value "5" supplied to "DefaultThreatNull"', - ]); - expect(message.schema).toEqual({}); - }); - - test('it should return a default "null" if not provided a value', () => { - const payload = undefined; - const decoded = DefaultThrottleNull.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([]); - expect(message.schema).toEqual(null); - }); -}); diff --git a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_throttle_null.ts b/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_throttle_null.ts deleted file mode 100644 index db6eb5eab32a..000000000000 --- a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_throttle_null.ts +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import * as t from 'io-ts'; -import { Either } from 'fp-ts/lib/Either'; -import { ThrottleOrNull, throttle } from '../common/schemas'; - -/** - * Types the DefaultThrottleNull as: - * - If null or undefined, then a null will be set - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export const DefaultThrottleNull = new t.Type( - 'DefaultThreatNull', - throttle.is, - (input, context): Either => - input == null ? t.success(null) : throttle.validate(input, context), - t.identity -); diff --git a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_to_string.test.ts b/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_to_string.test.ts deleted file mode 100644 index defb348b7e00..000000000000 --- a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_to_string.test.ts +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { DefaultToString } from './default_to_string'; -import { pipe } from 'fp-ts/lib/pipeable'; -import { left } from 'fp-ts/lib/Either'; -import { foldLeftRight, getPaths } from '../../../test_utils'; - -describe('default_to_string', () => { - test('it should validate a to string', () => { - const payload = 'now-5m'; - const decoded = DefaultToString.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([]); - expect(message.schema).toEqual(payload); - }); - - test('it should not validate a number', () => { - const payload = 5; - const decoded = DefaultToString.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([ - 'Invalid value "5" supplied to "DefaultToString"', - ]); - expect(message.schema).toEqual({}); - }); - - test('it should return a default of "now"', () => { - const payload = null; - const decoded = DefaultToString.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([]); - expect(message.schema).toEqual('now'); - }); -}); diff --git a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_to_string.ts b/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_to_string.ts deleted file mode 100644 index 05c93951bfe1..000000000000 --- a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_to_string.ts +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import * as t from 'io-ts'; -import { Either } from 'fp-ts/lib/Either'; - -/** - * Types the DefaultToString as: - * - If null or undefined, then a default of the string "now" will be used - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export const DefaultToString = new t.Type( - 'DefaultToString', - t.string.is, - (input, context): Either => - input == null ? t.success('now') : t.string.validate(input, context), - t.identity -); diff --git a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_uuid.test.ts b/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_uuid.test.ts deleted file mode 100644 index e2b2ac501596..000000000000 --- a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_uuid.test.ts +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { DefaultUuid } from './default_uuid'; -import { pipe } from 'fp-ts/lib/pipeable'; -import { left } from 'fp-ts/lib/Either'; -import { foldLeftRight, getPaths } from '../../../test_utils'; - -describe('default_uuid', () => { - test('it should validate a regular string', () => { - const payload = '1'; - const decoded = DefaultUuid.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([]); - expect(message.schema).toEqual(payload); - }); - - test('it should not validate a number', () => { - const payload = 5; - const decoded = DefaultUuid.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual(['Invalid value "5" supplied to "DefaultUuid"']); - expect(message.schema).toEqual({}); - }); - - test('it should return a default of a uuid', () => { - const payload = null; - const decoded = DefaultUuid.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([]); - expect(message.schema).toMatch( - /^[0-9a-f]{8}-[0-9a-f]{4}-[0-5][0-9a-f]{3}-[089ab][0-9a-f]{3}-[0-9a-f]{12}$/i - ); - }); -}); diff --git a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_uuid.ts b/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_uuid.ts deleted file mode 100644 index ecb8cd00ff30..000000000000 --- a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_uuid.ts +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import * as t from 'io-ts'; -import { Either } from 'fp-ts/lib/Either'; -import uuid from 'uuid'; - -import { NonEmptyString } from './non_empty_string'; - -/** - * Types the DefaultUuid as: - * - If null or undefined, then a default string uuid.v4() will be - * created otherwise it will be checked just against an empty string - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export const DefaultUuid = new t.Type( - 'DefaultUuid', - t.string.is, - (input, context): Either => - input == null ? t.success(uuid.v4()) : NonEmptyString.validate(input, context), - t.identity -); diff --git a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_version_number.test.ts b/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_version_number.test.ts deleted file mode 100644 index a50a9ed7815b..000000000000 --- a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_version_number.test.ts +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { DefaultVersionNumber } from './default_version_number'; -import { pipe } from 'fp-ts/lib/pipeable'; -import { left } from 'fp-ts/lib/Either'; -import { foldLeftRight, getPaths } from '../../../test_utils'; - -describe('default_version_number', () => { - test('it should validate a version number', () => { - const payload = 5; - const decoded = DefaultVersionNumber.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([]); - expect(message.schema).toEqual(payload); - }); - - test('it should not validate a 0', () => { - const payload = 0; - const decoded = DefaultVersionNumber.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([ - 'Invalid value "0" supplied to "DefaultVersionNumber"', - ]); - expect(message.schema).toEqual({}); - }); - - test('it should not validate a -1', () => { - const payload = -1; - const decoded = DefaultVersionNumber.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([ - 'Invalid value "-1" supplied to "DefaultVersionNumber"', - ]); - expect(message.schema).toEqual({}); - }); - - test('it should not validate a string', () => { - const payload = '5'; - const decoded = DefaultVersionNumber.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([ - 'Invalid value "5" supplied to "DefaultVersionNumber"', - ]); - expect(message.schema).toEqual({}); - }); - - test('it should return a default of 1', () => { - const payload = null; - const decoded = DefaultVersionNumber.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([]); - expect(message.schema).toEqual(1); - }); -}); diff --git a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_version_number.ts b/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_version_number.ts deleted file mode 100644 index 625973694a24..000000000000 --- a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/default_version_number.ts +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import * as t from 'io-ts'; -import { Either } from 'fp-ts/lib/Either'; -import { version, Version } from '../common/schemas'; - -/** - * Types the DefaultVersionNumber as: - * - If null or undefined, then a default of the number 1 will be used - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export const DefaultVersionNumber = new t.Type( - 'DefaultVersionNumber', - version.is, - (input, context): Either => - input == null ? t.success(1) : version.validate(input, context), - t.identity -); - -export type DefaultVersionNumberDecoded = t.TypeOf; diff --git a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/index.ts b/x-pack/plugins/security_solution/common/detection_engine/schemas/types/index.ts deleted file mode 100644 index ff69075580ad..000000000000 --- a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/index.ts +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -export * from './default_actions_array'; -export * from './default_array'; -export * from './default_boolean_false'; -export * from './default_boolean_true'; -export * from './default_empty_string'; -export * from './default_export_file_name'; -export * from './default_from_string'; -export * from './default_interval_string'; -export * from './default_language_string'; -export * from './default_max_signals_number'; -export * from './default_page'; -export * from './default_per_page'; -export * from './default_risk_score_mapping_array'; -export * from './default_severity_mapping_array'; -export * from './default_string_array'; -export * from './default_string_boolean_false'; -export * from './default_threat_array'; -export * from './default_throttle_null'; -export * from './default_to_string'; -export * from './default_uuid'; -export * from './default_version_number'; -export * from './iso_date_string'; -export * from './lists'; -export * from './lists_default_array'; -export * from './non_empty_array'; -export * from './non_empty_string'; -export * from './only_false_allowed'; -export * from './positive_integer'; -export * from './positive_integer_greater_than_zero'; -export * from './references_default_array'; -export * from './risk_score'; -export * from './threat_mapping'; -export * from './uuid'; diff --git a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/iso_date_string.test.ts b/x-pack/plugins/security_solution/common/detection_engine/schemas/types/iso_date_string.test.ts deleted file mode 100644 index ff45aef21f83..000000000000 --- a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/iso_date_string.test.ts +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { IsoDateString } from './iso_date_string'; -import { pipe } from 'fp-ts/lib/pipeable'; -import { left } from 'fp-ts/lib/Either'; -import { foldLeftRight, getPaths } from '../../../test_utils'; - -describe('ios_date_string', () => { - test('it should validate a iso string', () => { - const payload = '2020-02-26T00:32:34.541Z'; - const decoded = IsoDateString.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([]); - expect(message.schema).toEqual(payload); - }); - - test('it should not validate an epoch number', () => { - const payload = '1582677283067'; - const decoded = IsoDateString.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([ - 'Invalid value "1582677283067" supplied to "IsoDateString"', - ]); - expect(message.schema).toEqual({}); - }); - - test('it should not validate a number such as 2000', () => { - const payload = '2000'; - const decoded = IsoDateString.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([ - 'Invalid value "2000" supplied to "IsoDateString"', - ]); - expect(message.schema).toEqual({}); - }); - - test('it should not validate a UTC', () => { - const payload = 'Wed, 26 Feb 2020 00:36:20 GMT'; - const decoded = IsoDateString.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([ - 'Invalid value "Wed, 26 Feb 2020 00:36:20 GMT" supplied to "IsoDateString"', - ]); - expect(message.schema).toEqual({}); - }); -}); diff --git a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/iso_date_string.ts b/x-pack/plugins/security_solution/common/detection_engine/schemas/types/iso_date_string.ts deleted file mode 100644 index 9c8f490d2d59..000000000000 --- a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/iso_date_string.ts +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import * as t from 'io-ts'; -import { Either } from 'fp-ts/lib/Either'; - -/** - * Types the IsoDateString as: - * - A string that is an ISOString - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export const IsoDateString = new t.Type( - 'IsoDateString', - t.string.is, - (input, context): Either => { - if (typeof input === 'string') { - try { - const parsed = new Date(input); - if (parsed.toISOString() === input) { - return t.success(input); - } else { - return t.failure(input, context); - } - } catch (err) { - return t.failure(input, context); - } - } else { - return t.failure(input, context); - } - }, - t.identity -); - -export type IsoDateStringC = typeof IsoDateString; diff --git a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/lists.mock.ts b/x-pack/plugins/security_solution/common/detection_engine/schemas/types/lists.mock.ts index 62a3c51b31bd..70f41539e846 100644 --- a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/lists.mock.ts +++ b/x-pack/plugins/security_solution/common/detection_engine/schemas/types/lists.mock.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { List, ListArray } from './lists'; +import { List, ListArray } from '@kbn/securitysolution-io-ts-list-types'; import { ENDPOINT_LIST_ID } from '../../../shared_imports'; export const getListMock = (): List => ({ diff --git a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/lists.test.ts b/x-pack/plugins/security_solution/common/detection_engine/schemas/types/lists.test.ts deleted file mode 100644 index 28b70f51742a..000000000000 --- a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/lists.test.ts +++ /dev/null @@ -1,134 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { pipe } from 'fp-ts/lib/pipeable'; -import { left } from 'fp-ts/lib/Either'; - -import { foldLeftRight, getPaths } from '../../../test_utils'; - -import { getEndpointListMock, getListMock, getListArrayMock } from './lists.mock'; -import { - List, - ListArray, - ListArrayOrUndefined, - list, - listArray, - listArrayOrUndefined, -} from './lists'; - -describe('Lists', () => { - describe('list', () => { - test('it should validate a list', () => { - const payload = getListMock(); - const decoded = list.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([]); - expect(message.schema).toEqual(payload); - }); - - test('it should validate a list with "namespace_type" of "agnostic"', () => { - const payload = getEndpointListMock(); - const decoded = list.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([]); - expect(message.schema).toEqual(payload); - }); - - test('it should NOT validate a list without an "id"', () => { - const payload = getListMock(); - // @ts-expect-error - delete payload.id; - const decoded = list.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([ - 'Invalid value "undefined" supplied to "id"', - ]); - expect(message.schema).toEqual({}); - }); - - test('it should NOT validate a list without "namespace_type"', () => { - const payload = getListMock(); - // @ts-expect-error - delete payload.namespace_type; - const decoded = list.decode(payload); - const message = pipe(decoded, foldLeftRight); - expect(getPaths(left(message.errors))).toEqual([ - 'Invalid value "undefined" supplied to "namespace_type"', - ]); - expect(message.schema).toEqual({}); - }); - - test('it should strip out extra keys', () => { - const payload: List & { - extraKey?: string; - } = getListMock(); - payload.extraKey = 'some value'; - const decoded = list.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([]); - expect(message.schema).toEqual(getListMock()); - }); - }); - - describe('listArray', () => { - test('it should validate an array of lists', () => { - const payload = getListArrayMock(); - const decoded = listArray.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([]); - expect(message.schema).toEqual(payload); - }); - - test('it should not validate when unexpected type found in array', () => { - const payload = ([1] as unknown) as ListArray; - const decoded = listArray.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([ - 'Invalid value "1" supplied to "Array<{| id: NonEmptyString, list_id: NonEmptyString, type: "detection" | "endpoint" | "endpoint_events", namespace_type: "agnostic" | "single" |}>"', - ]); - expect(message.schema).toEqual({}); - }); - }); - - describe('listArrayOrUndefined', () => { - test('it should validate an array of lists', () => { - const payload = getListArrayMock(); - const decoded = listArrayOrUndefined.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([]); - expect(message.schema).toEqual(payload); - }); - - test('it should validate when undefined', () => { - const payload = undefined; - const decoded = listArrayOrUndefined.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([]); - expect(message.schema).toEqual(payload); - }); - - test('it should not allow an item that is not of type "list" in array', () => { - const payload = ([1] as unknown) as ListArrayOrUndefined; - const decoded = listArrayOrUndefined.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([ - 'Invalid value "1" supplied to "(Array<{| id: NonEmptyString, list_id: NonEmptyString, type: "detection" | "endpoint" | "endpoint_events", namespace_type: "agnostic" | "single" |}> | undefined)"', - 'Invalid value "[1]" supplied to "(Array<{| id: NonEmptyString, list_id: NonEmptyString, type: "detection" | "endpoint" | "endpoint_events", namespace_type: "agnostic" | "single" |}> | undefined)"', - ]); - expect(message.schema).toEqual({}); - }); - }); -}); diff --git a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/lists.ts b/x-pack/plugins/security_solution/common/detection_engine/schemas/types/lists.ts deleted file mode 100644 index e2c3ee88f6a6..000000000000 --- a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/lists.ts +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import * as t from 'io-ts'; - -import { exceptionListType, namespaceType } from '@kbn/securitysolution-io-ts-list-types'; - -import { NonEmptyString } from './non_empty_string'; - -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export const list = t.exact( - t.type({ - id: NonEmptyString, - list_id: NonEmptyString, - type: exceptionListType, - namespace_type: namespaceType, - }) -); - -export type List = t.TypeOf; -export const listArray = t.array(list); -export type ListArray = t.TypeOf; -export const listArrayOrUndefined = t.union([listArray, t.undefined]); -export type ListArrayOrUndefined = t.TypeOf; diff --git a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/lists_default_array.test.ts b/x-pack/plugins/security_solution/common/detection_engine/schemas/types/lists_default_array.test.ts deleted file mode 100644 index 0d989b4de0b2..000000000000 --- a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/lists_default_array.test.ts +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { pipe } from 'fp-ts/lib/pipeable'; -import { left } from 'fp-ts/lib/Either'; - -import { foldLeftRight, getPaths } from '../../../test_utils'; - -import { DefaultListArray } from './lists_default_array'; -import { getListArrayMock } from './lists.mock'; - -describe('lists_default_array', () => { - test('it should return a default array when null', () => { - const payload = null; - const decoded = DefaultListArray.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([]); - expect(message.schema).toEqual([]); - }); - - test('it should return a default array when undefined', () => { - const payload = undefined; - const decoded = DefaultListArray.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([]); - expect(message.schema).toEqual([]); - }); - - test('it should validate an empty array', () => { - const payload: string[] = []; - const decoded = DefaultListArray.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([]); - expect(message.schema).toEqual(payload); - }); - - test('it should validate an array of lists', () => { - const payload = getListArrayMock(); - const decoded = DefaultListArray.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([]); - expect(message.schema).toEqual(payload); - }); - - test('it should not validate an array of non accepted types', () => { - // Terrible casting for purpose of tests - const payload = [1] as unknown; - const decoded = DefaultListArray.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([ - 'Invalid value "1" supplied to "DefaultListArray"', - ]); - expect(message.schema).toEqual({}); - }); -}); diff --git a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/lists_default_array.ts b/x-pack/plugins/security_solution/common/detection_engine/schemas/types/lists_default_array.ts deleted file mode 100644 index eba48c0419ec..000000000000 --- a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/lists_default_array.ts +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import * as t from 'io-ts'; -import { Either } from 'fp-ts/lib/Either'; - -import { ListArray, list } from './lists'; - -/** - * Types the DefaultListArray as: - * - If null or undefined, then a default array of type list will be set - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export const DefaultListArray = new t.Type( - 'DefaultListArray', - t.array(list).is, - (input, context): Either => - input == null ? t.success([]) : t.array(list).validate(input, context), - t.identity -); diff --git a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/non_empty_array.test.ts b/x-pack/plugins/security_solution/common/detection_engine/schemas/types/non_empty_array.test.ts deleted file mode 100644 index c08cb70f544e..000000000000 --- a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/non_empty_array.test.ts +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import * as t from 'io-ts'; - -import { NonEmptyArray } from './non_empty_array'; -import { pipe } from 'fp-ts/lib/pipeable'; -import { left } from 'fp-ts/lib/Either'; -import { foldLeftRight, getPaths } from '../../../test_utils'; - -const testSchema = t.keyof({ - valid: true, - also_valid: true, -}); -type TestSchema = t.TypeOf; - -const nonEmptyArraySchema = NonEmptyArray(testSchema, 'TestSchemaArray'); - -describe('non empty array', () => { - test('it should generate the correct name for non empty array', () => { - const newTestSchema = NonEmptyArray(testSchema); - expect(newTestSchema.name).toEqual('NonEmptyArray<"valid" | "also_valid">'); - }); - - test('it should use a supplied name override', () => { - const newTestSchema = NonEmptyArray(testSchema, 'someName'); - expect(newTestSchema.name).toEqual('someName'); - }); - - test('it should NOT validate an empty array', () => { - const payload: string[] = []; - const decoded = nonEmptyArraySchema.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([ - 'Invalid value "[]" supplied to "TestSchemaArray"', - ]); - expect(message.schema).toEqual({}); - }); - - test('it should validate an array of testSchema', () => { - const payload: TestSchema[] = ['valid']; - const decoded = nonEmptyArraySchema.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([]); - expect(message.schema).toEqual(payload); - }); - - test('it should validate an array of valid testSchema strings', () => { - const payload: TestSchema[] = ['valid', 'also_valid']; - const decoded = nonEmptyArraySchema.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([]); - expect(message.schema).toEqual(payload); - }); - - test('it should not validate an array with a number', () => { - const payload = ['valid', 123]; - const decoded = nonEmptyArraySchema.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([ - 'Invalid value "123" supplied to "TestSchemaArray"', - ]); - expect(message.schema).toEqual({}); - }); - - test('it should not validate an array with an invalid string', () => { - const payload = ['valid', 'invalid']; - const decoded = nonEmptyArraySchema.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([ - 'Invalid value "invalid" supplied to "TestSchemaArray"', - ]); - expect(message.schema).toEqual({}); - }); - - test('it should not validate a null value', () => { - const payload = null; - const decoded = nonEmptyArraySchema.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([ - 'Invalid value "null" supplied to "TestSchemaArray"', - ]); - expect(message.schema).toEqual({}); - }); -}); diff --git a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/non_empty_array.ts b/x-pack/plugins/security_solution/common/detection_engine/schemas/types/non_empty_array.ts deleted file mode 100644 index 1b5261931230..000000000000 --- a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/non_empty_array.ts +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import * as t from 'io-ts'; -import { Either } from 'fp-ts/lib/Either'; - -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export const NonEmptyArray = ( - codec: C, - name: string = `NonEmptyArray<${codec.name}>` -) => { - const arrType = t.array(codec); - type ArrType = t.TypeOf; - return new t.Type( - name, - arrType.is, - (input, context): Either => { - if (Array.isArray(input) && input.length === 0) { - return t.failure(input, context); - } else { - return arrType.validate(input, context); - } - }, - t.identity - ); -}; diff --git a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/non_empty_string.test.ts b/x-pack/plugins/security_solution/common/detection_engine/schemas/types/non_empty_string.test.ts deleted file mode 100644 index 470f8bc81c5d..000000000000 --- a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/non_empty_string.test.ts +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { NonEmptyString } from './non_empty_string'; -import { pipe } from 'fp-ts/lib/pipeable'; -import { left } from 'fp-ts/lib/Either'; -import { foldLeftRight, getPaths } from '../../../test_utils'; - -describe('non_empty_string', () => { - test('it should validate a regular string', () => { - const payload = '1'; - const decoded = NonEmptyString.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([]); - expect(message.schema).toEqual(payload); - }); - - test('it should not validate a number', () => { - const payload = 5; - const decoded = NonEmptyString.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([ - 'Invalid value "5" supplied to "NonEmptyString"', - ]); - expect(message.schema).toEqual({}); - }); - - test('it should not validate an empty string', () => { - const payload = ''; - const decoded = NonEmptyString.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([ - 'Invalid value "" supplied to "NonEmptyString"', - ]); - expect(message.schema).toEqual({}); - }); - - test('it should not validate empty spaces', () => { - const payload = ' '; - const decoded = NonEmptyString.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([ - 'Invalid value " " supplied to "NonEmptyString"', - ]); - expect(message.schema).toEqual({}); - }); -}); diff --git a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/non_empty_string.ts b/x-pack/plugins/security_solution/common/detection_engine/schemas/types/non_empty_string.ts deleted file mode 100644 index e01eabd4c434..000000000000 --- a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/non_empty_string.ts +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import * as t from 'io-ts'; -import { Either } from 'fp-ts/lib/Either'; - -/** - * Types the NonEmptyString as: - * - A string that is not empty - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export const NonEmptyString = new t.Type( - 'NonEmptyString', - t.string.is, - (input, context): Either => { - if (typeof input === 'string' && input.trim() !== '') { - return t.success(input); - } else { - return t.failure(input, context); - } - }, - t.identity -); - -export type NonEmptyStringC = typeof NonEmptyString; diff --git a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/normalized_ml_job_id.ts b/x-pack/plugins/security_solution/common/detection_engine/schemas/types/normalized_ml_job_id.ts deleted file mode 100644 index 7001cb8254d2..000000000000 --- a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/normalized_ml_job_id.ts +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ -/* eslint-disable @typescript-eslint/naming-convention */ - -import * as t from 'io-ts'; - -import { NonEmptyArray } from './non_empty_array'; - -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export const machine_learning_job_id_normalized = NonEmptyArray(t.string); - -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export type MachineLearningJobIdNormalized = t.TypeOf; - -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export const machineLearningJobIdNormalizedOrUndefined = t.union([ - machine_learning_job_id_normalized, - t.undefined, -]); - -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export type MachineLearningJobIdNormalizedOrUndefined = t.TypeOf< - typeof machineLearningJobIdNormalizedOrUndefined ->; diff --git a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/only_false_allowed.test.ts b/x-pack/plugins/security_solution/common/detection_engine/schemas/types/only_false_allowed.test.ts deleted file mode 100644 index a22266fb04f6..000000000000 --- a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/only_false_allowed.test.ts +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { pipe } from 'fp-ts/lib/pipeable'; -import { left } from 'fp-ts/lib/Either'; -import { foldLeftRight, getPaths } from '../../../test_utils'; -import { OnlyFalseAllowed } from './only_false_allowed'; - -describe('only_false_allowed', () => { - test('it should validate a boolean false as false', () => { - const payload = false; - const decoded = OnlyFalseAllowed.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([]); - expect(message.schema).toEqual(payload); - }); - - test('it should not validate a boolean true', () => { - const payload = true; - const decoded = OnlyFalseAllowed.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([ - 'Invalid value "true" supplied to "DefaultBooleanTrue"', - ]); - expect(message.schema).toEqual({}); - }); - - test('it should not validate a number', () => { - const payload = 5; - const decoded = OnlyFalseAllowed.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([ - 'Invalid value "5" supplied to "DefaultBooleanTrue"', - ]); - expect(message.schema).toEqual({}); - }); - - test('it should return a default false', () => { - const payload = null; - const decoded = OnlyFalseAllowed.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([]); - expect(message.schema).toEqual(false); - }); -}); diff --git a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/only_false_allowed.ts b/x-pack/plugins/security_solution/common/detection_engine/schemas/types/only_false_allowed.ts deleted file mode 100644 index 8150979cf294..000000000000 --- a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/only_false_allowed.ts +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import * as t from 'io-ts'; -import { Either } from 'fp-ts/lib/Either'; - -/** - * Types the OnlyFalseAllowed as: - * - If null or undefined, then a default false will be set - * - If true is sent in then this will return an error - * - If false is sent in then this will allow it only false - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export const OnlyFalseAllowed = new t.Type( - 'DefaultBooleanTrue', - t.boolean.is, - (input, context): Either => { - if (input == null) { - return t.success(false); - } else { - if (typeof input === 'boolean' && input === false) { - return t.success(false); - } else { - return t.failure(input, context); - } - } - }, - t.identity -); diff --git a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/positive_integer.ts b/x-pack/plugins/security_solution/common/detection_engine/schemas/types/positive_integer.ts deleted file mode 100644 index 1771d0515fa2..000000000000 --- a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/positive_integer.ts +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import * as t from 'io-ts'; -import { Either } from 'fp-ts/lib/Either'; - -/** - * Types the positive integer are: - * - Natural Number (positive integer and not a float), - * - zero or greater - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export const PositiveInteger = new t.Type( - 'PositiveInteger', - t.number.is, - (input, context): Either => { - return typeof input === 'number' && Number.isSafeInteger(input) && input >= 0 - ? t.success(input) - : t.failure(input, context); - }, - t.identity -); diff --git a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/positive_integer_greater_than_zero.test.ts b/x-pack/plugins/security_solution/common/detection_engine/schemas/types/positive_integer_greater_than_zero.test.ts deleted file mode 100644 index dfb8b90633c8..000000000000 --- a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/positive_integer_greater_than_zero.test.ts +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { PositiveIntegerGreaterThanZero } from './positive_integer_greater_than_zero'; -import { pipe } from 'fp-ts/lib/pipeable'; -import { left } from 'fp-ts/lib/Either'; -import { foldLeftRight, getPaths } from '../../../test_utils'; - -describe('positive_integer_greater_than_zero', () => { - test('it should validate a positive number', () => { - const payload = 1; - const decoded = PositiveIntegerGreaterThanZero.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([]); - expect(message.schema).toEqual(payload); - }); - - test('it should NOT validate a zero', () => { - const payload = 0; - const decoded = PositiveIntegerGreaterThanZero.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([ - 'Invalid value "0" supplied to "PositiveIntegerGreaterThanZero"', - ]); - expect(message.schema).toEqual({}); - }); - - test('it should NOT validate a negative number', () => { - const payload = -1; - const decoded = PositiveIntegerGreaterThanZero.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([ - 'Invalid value "-1" supplied to "PositiveIntegerGreaterThanZero"', - ]); - expect(message.schema).toEqual({}); - }); - - test('it should NOT validate a string', () => { - const payload = 'some string'; - const decoded = PositiveIntegerGreaterThanZero.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([ - 'Invalid value "some string" supplied to "PositiveIntegerGreaterThanZero"', - ]); - expect(message.schema).toEqual({}); - }); -}); diff --git a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/positive_integer_greater_than_zero.ts b/x-pack/plugins/security_solution/common/detection_engine/schemas/types/positive_integer_greater_than_zero.ts deleted file mode 100644 index ddfb82b748ee..000000000000 --- a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/positive_integer_greater_than_zero.ts +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import * as t from 'io-ts'; -import { Either } from 'fp-ts/lib/Either'; - -/** - * Types the positive integer greater than zero is: - * - Natural Number (positive integer and not a float), - * - 1 or greater - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export const PositiveIntegerGreaterThanZero = new t.Type( - 'PositiveIntegerGreaterThanZero', - t.number.is, - (input, context): Either => { - return typeof input === 'number' && Number.isSafeInteger(input) && input >= 1 - ? t.success(input) - : t.failure(input, context); - }, - t.identity -); diff --git a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/postive_integer.test.ts b/x-pack/plugins/security_solution/common/detection_engine/schemas/types/postive_integer.test.ts deleted file mode 100644 index b0c64e70787a..000000000000 --- a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/postive_integer.test.ts +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { PositiveInteger } from './positive_integer'; -import { pipe } from 'fp-ts/lib/pipeable'; -import { left } from 'fp-ts/lib/Either'; -import { foldLeftRight, getPaths } from '../../../test_utils'; - -describe('positive_integer_greater_than_zero', () => { - test('it should validate a positive number', () => { - const payload = 1; - const decoded = PositiveInteger.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([]); - expect(message.schema).toEqual(payload); - }); - - test('it should validate a zero', () => { - const payload = 0; - const decoded = PositiveInteger.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([]); - expect(message.schema).toEqual(payload); - }); - - test('it should NOT validate a negative number', () => { - const payload = -1; - const decoded = PositiveInteger.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([ - 'Invalid value "-1" supplied to "PositiveInteger"', - ]); - expect(message.schema).toEqual({}); - }); - - test('it should NOT validate a string', () => { - const payload = 'some string'; - const decoded = PositiveInteger.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([ - 'Invalid value "some string" supplied to "PositiveInteger"', - ]); - expect(message.schema).toEqual({}); - }); -}); diff --git a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/references_default_array.test.ts b/x-pack/plugins/security_solution/common/detection_engine/schemas/types/references_default_array.test.ts deleted file mode 100644 index c8995f6a7cef..000000000000 --- a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/references_default_array.test.ts +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { DefaultStringArray } from './default_string_array'; -import { pipe } from 'fp-ts/lib/pipeable'; -import { left } from 'fp-ts/lib/Either'; -import { foldLeftRight, getPaths } from '../../../test_utils'; - -describe('default_string_array', () => { - test('it should validate an empty array', () => { - const payload: string[] = []; - const decoded = DefaultStringArray.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([]); - expect(message.schema).toEqual(payload); - }); - - test('it should validate an array of strings', () => { - const payload = ['value 1', 'value 2']; - const decoded = DefaultStringArray.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([]); - expect(message.schema).toEqual(payload); - }); - - test('it should not validate an array with a number', () => { - const payload = ['value 1', 5]; - const decoded = DefaultStringArray.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([ - 'Invalid value "5" supplied to "DefaultStringArray"', - ]); - expect(message.schema).toEqual({}); - }); - - test('it should return a default array entry', () => { - const payload = null; - const decoded = DefaultStringArray.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([]); - expect(message.schema).toEqual([]); - }); -}); diff --git a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/references_default_array.ts b/x-pack/plugins/security_solution/common/detection_engine/schemas/types/references_default_array.ts deleted file mode 100644 index a76606911f4a..000000000000 --- a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/references_default_array.ts +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import * as t from 'io-ts'; -import { Either } from 'fp-ts/lib/Either'; - -/** - * Types the ReferencesDefaultArray as: - * - If null or undefined, then a default array will be set - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export const ReferencesDefaultArray = new t.Type( - 'referencesWithDefaultArray', - t.array(t.string).is, - (input, context): Either => - input == null ? t.success([]) : t.array(t.string).validate(input, context), - t.identity -); diff --git a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/risk_score.test.ts b/x-pack/plugins/security_solution/common/detection_engine/schemas/types/risk_score.test.ts deleted file mode 100644 index 67e8c801391c..000000000000 --- a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/risk_score.test.ts +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { RiskScore } from './risk_score'; -import { pipe } from 'fp-ts/lib/pipeable'; -import { left } from 'fp-ts/lib/Either'; -import { foldLeftRight, getPaths } from '../../../test_utils'; - -describe('risk_score', () => { - test('it should validate a positive number', () => { - const payload = 1; - const decoded = RiskScore.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([]); - expect(message.schema).toEqual(payload); - }); - - test('it should validate a zero', () => { - const payload = 0; - const decoded = RiskScore.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([]); - expect(message.schema).toEqual(payload); - }); - - test('it should NOT validate a negative number', () => { - const payload = -1; - const decoded = RiskScore.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual(['Invalid value "-1" supplied to "RiskScore"']); - expect(message.schema).toEqual({}); - }); - - test('it should NOT validate a string', () => { - const payload = 'some string'; - const decoded = RiskScore.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([ - 'Invalid value "some string" supplied to "RiskScore"', - ]); - expect(message.schema).toEqual({}); - }); - - test('it should NOT validate a risk score greater than 100', () => { - const payload = 101; - const decoded = RiskScore.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual(['Invalid value "101" supplied to "RiskScore"']); - expect(message.schema).toEqual({}); - }); -}); diff --git a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/risk_score.ts b/x-pack/plugins/security_solution/common/detection_engine/schemas/types/risk_score.ts deleted file mode 100644 index e518bf13fd18..000000000000 --- a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/risk_score.ts +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import * as t from 'io-ts'; -import { Either } from 'fp-ts/lib/Either'; - -/** - * Types the risk score as: - * - Natural Number (positive integer and not a float), - * - Between the values [0 and 100] inclusive. - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export const RiskScore = new t.Type( - 'RiskScore', - t.number.is, - (input, context): Either => { - return typeof input === 'number' && Number.isSafeInteger(input) && input >= 0 && input <= 100 - ? t.success(input) - : t.failure(input, context); - }, - t.identity -); - -export type RiskScoreC = typeof RiskScore; diff --git a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/threat.mock.ts b/x-pack/plugins/security_solution/common/detection_engine/schemas/types/threat.mock.ts index e8a62822bfe5..fb063a130e83 100644 --- a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/threat.mock.ts +++ b/x-pack/plugins/security_solution/common/detection_engine/schemas/types/threat.mock.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { Threats } from '../common/schemas'; +import { Threats } from '@kbn/securitysolution-io-ts-alerting-types'; export const getThreatMock = (): Threats => [ { diff --git a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/threat_mapping.test.ts b/x-pack/plugins/security_solution/common/detection_engine/schemas/types/threat_mapping.test.ts deleted file mode 100644 index c89c1059eedf..000000000000 --- a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/threat_mapping.test.ts +++ /dev/null @@ -1,236 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { - concurrent_searches, - items_per_search, - ThreatMapping, - threatMappingEntries, - ThreatMappingEntries, - threat_mapping, -} from './threat_mapping'; -import { pipe } from 'fp-ts/lib/pipeable'; -import { left } from 'fp-ts/lib/Either'; -import { foldLeftRight, getPaths } from '../../../test_utils'; -import { exactCheck } from '../../../exact_check'; - -describe('threat_mapping', () => { - describe('threatMappingEntries', () => { - test('it should validate an entry', () => { - const payload: ThreatMappingEntries = [ - { - field: 'field.one', - type: 'mapping', - value: 'field.one', - }, - ]; - const decoded = threatMappingEntries.decode(payload); - const checked = exactCheck(payload, decoded); - const message = pipe(checked, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([]); - expect(message.schema).toEqual(payload); - }); - - test('it should fail validation with an extra entry item', () => { - const payload: ThreatMappingEntries & Array<{ extra: string }> = [ - { - field: 'field.one', - type: 'mapping', - value: 'field.one', - extra: 'blah', - }, - ]; - const decoded = threatMappingEntries.decode(payload); - const checked = exactCheck(payload, decoded); - const message = pipe(checked, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual(['invalid keys "extra"']); - expect(message.schema).toEqual({}); - }); - - test('it should fail validation with a non string', () => { - const payload = ([ - { - field: 5, - type: 'mapping', - value: 'field.one', - }, - ] as unknown) as ThreatMappingEntries[]; - const decoded = threatMappingEntries.decode(payload); - const checked = exactCheck(payload, decoded); - const message = pipe(checked, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual(['Invalid value "5" supplied to "field"']); - expect(message.schema).toEqual({}); - }); - - test('it should fail validation with a wrong type', () => { - const payload = ([ - { - field: 'field.one', - type: 'invalid', - value: 'field.one', - }, - ] as unknown) as ThreatMappingEntries[]; - const decoded = threatMappingEntries.decode(payload); - const checked = exactCheck(payload, decoded); - const message = pipe(checked, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([ - 'Invalid value "invalid" supplied to "type"', - ]); - expect(message.schema).toEqual({}); - }); - }); - - describe('threat_mapping', () => { - test('it should validate a threat mapping', () => { - const payload: ThreatMapping = [ - { - entries: [ - { - field: 'field.one', - type: 'mapping', - value: 'field.one', - }, - ], - }, - ]; - const decoded = threat_mapping.decode(payload); - const checked = exactCheck(payload, decoded); - const message = pipe(checked, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([]); - expect(message.schema).toEqual(payload); - }); - }); - - test('it should fail validate with an extra key', () => { - const payload: ThreatMapping & Array<{ extra: string }> = [ - { - entries: [ - { - field: 'field.one', - type: 'mapping', - value: 'field.one', - }, - ], - extra: 'invalid', - }, - ]; - - const decoded = threat_mapping.decode(payload); - const checked = exactCheck(payload, decoded); - const message = pipe(checked, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual(['invalid keys "extra"']); - expect(message.schema).toEqual({}); - }); - - test('it should fail validate with an extra inner entry', () => { - const payload: ThreatMapping & Array<{ entries: Array<{ extra: string }> }> = [ - { - entries: [ - { - field: 'field.one', - type: 'mapping', - value: 'field.one', - extra: 'blah', - }, - ], - }, - ]; - - const decoded = threat_mapping.decode(payload); - const checked = exactCheck(payload, decoded); - const message = pipe(checked, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual(['invalid keys "extra"']); - expect(message.schema).toEqual({}); - }); - - test('it should fail validate with an extra inner entry with the wrong data type', () => { - const payload = ([ - { - entries: [ - { - field: 5, - type: 'mapping', - value: 'field.one', - }, - ], - }, - ] as unknown) as ThreatMapping; - - const decoded = threat_mapping.decode(payload); - const checked = exactCheck(payload, decoded); - const message = pipe(checked, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([ - 'Invalid value "5" supplied to "entries,field"', - ]); - expect(message.schema).toEqual({}); - }); - - test('it should fail validate with empty array', () => { - const payload: string[] = []; - - const decoded = threat_mapping.decode(payload); - const checked = exactCheck(payload, decoded); - const message = pipe(checked, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([ - 'Invalid value "[]" supplied to "NonEmptyArray"', - ]); - expect(message.schema).toEqual({}); - }); - - test('it should fail validation when concurrent_searches is < 0', () => { - const payload = -1; - const decoded = concurrent_searches.decode(payload); - const checked = exactCheck(payload, decoded); - const message = pipe(checked, foldLeftRight); - expect(getPaths(left(message.errors))).toEqual([ - 'Invalid value "-1" supplied to "PositiveIntegerGreaterThanZero"', - ]); - expect(message.schema).toEqual({}); - }); - - test('it should fail validation when concurrent_searches is 0', () => { - const payload = 0; - const decoded = concurrent_searches.decode(payload); - const checked = exactCheck(payload, decoded); - const message = pipe(checked, foldLeftRight); - expect(getPaths(left(message.errors))).toEqual([ - 'Invalid value "0" supplied to "PositiveIntegerGreaterThanZero"', - ]); - expect(message.schema).toEqual({}); - }); - - test('it should fail validation when items_per_search is 0', () => { - const payload = 0; - const decoded = items_per_search.decode(payload); - const checked = exactCheck(payload, decoded); - const message = pipe(checked, foldLeftRight); - expect(getPaths(left(message.errors))).toEqual([ - 'Invalid value "0" supplied to "PositiveIntegerGreaterThanZero"', - ]); - expect(message.schema).toEqual({}); - }); - - test('it should fail validation when items_per_search is < 0', () => { - const payload = -1; - const decoded = items_per_search.decode(payload); - const checked = exactCheck(payload, decoded); - const message = pipe(checked, foldLeftRight); - expect(getPaths(left(message.errors))).toEqual([ - 'Invalid value "-1" supplied to "PositiveIntegerGreaterThanZero"', - ]); - expect(message.schema).toEqual({}); - }); -}); diff --git a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/threat_mapping.ts b/x-pack/plugins/security_solution/common/detection_engine/schemas/types/threat_mapping.ts deleted file mode 100644 index 707b51e6b896..000000000000 --- a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/threat_mapping.ts +++ /dev/null @@ -1,214 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -/* eslint-disable @typescript-eslint/naming-convention */ - -import * as t from 'io-ts'; -import { language } from '../common/schemas'; -import { NonEmptyArray } from './non_empty_array'; -import { NonEmptyString } from './non_empty_string'; -import { PositiveIntegerGreaterThanZero } from './positive_integer_greater_than_zero'; - -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export const threat_query = t.string; - -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export type ThreatQuery = t.TypeOf; - -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export const threatQueryOrUndefined = t.union([threat_query, t.undefined]); - -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export type ThreatQueryOrUndefined = t.TypeOf; - -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export const threat_indicator_path = t.string; - -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export type ThreatIndicatorPath = t.TypeOf; - -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export const threatIndicatorPathOrUndefined = t.union([threat_indicator_path, t.undefined]); - -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export type ThreatIndicatorPathOrUndefined = t.TypeOf; - -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export const threat_filters = t.array(t.unknown); // Filters are not easily type-able yet - -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export type ThreatFilters = t.TypeOf; - -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export const threatFiltersOrUndefined = t.union([threat_filters, t.undefined]); - -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export type ThreatFiltersOrUndefined = t.TypeOf; - -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export const threatMapEntry = t.exact( - t.type({ - field: NonEmptyString, - type: t.keyof({ mapping: null }), - value: NonEmptyString, - }) -); - -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export type ThreatMapEntry = t.TypeOf; - -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export const threatMappingEntries = t.array(threatMapEntry); - -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export type ThreatMappingEntries = t.TypeOf; - -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export const threatMap = t.exact( - t.type({ - entries: threatMappingEntries, - }) -); - -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export type ThreatMap = t.TypeOf; - -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export const threat_mapping = NonEmptyArray(threatMap, 'NonEmptyArray'); - -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export type ThreatMapping = t.TypeOf; - -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export const threatMappingOrUndefined = t.union([threat_mapping, t.undefined]); - -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export type ThreatMappingOrUndefined = t.TypeOf; - -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export const threat_index = t.array(t.string); - -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export type ThreatIndex = t.TypeOf; - -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export const threatIndexOrUndefined = t.union([threat_index, t.undefined]); - -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export type ThreatIndexOrUndefined = t.TypeOf; - -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export const threat_language = t.union([language, t.undefined]); - -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export type ThreatLanguage = t.TypeOf; - -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export const threatLanguageOrUndefined = t.union([threat_language, t.undefined]); - -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export type ThreatLanguageOrUndefined = t.TypeOf; - -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export const concurrent_searches = PositiveIntegerGreaterThanZero; - -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export type ConcurrentSearches = t.TypeOf; - -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export const concurrentSearchesOrUndefined = t.union([concurrent_searches, t.undefined]); - -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export type ConcurrentSearchesOrUndefined = t.TypeOf; - -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export const items_per_search = PositiveIntegerGreaterThanZero; - -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export type ItemsPerSearch = t.TypeOf; - -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export const itemsPerSearchOrUndefined = t.union([items_per_search, t.undefined]); - -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export type ItemsPerSearchOrUndefined = t.TypeOf; diff --git a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/uuid.test.ts b/x-pack/plugins/security_solution/common/detection_engine/schemas/types/uuid.test.ts deleted file mode 100644 index 2a98fd16c710..000000000000 --- a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/uuid.test.ts +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { UUID } from './uuid'; -import { pipe } from 'fp-ts/lib/pipeable'; -import { left } from 'fp-ts/lib/Either'; -import { foldLeftRight, getPaths } from '../../../test_utils'; - -describe('uuid', () => { - test('it should validate a uuid', () => { - const payload = '4656dc92-5832-11ea-8e2d-0242ac130003'; - const decoded = UUID.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([]); - expect(message.schema).toEqual(payload); - }); - - test('it should not validate a non uuid', () => { - const payload = '4656dc92-5832-11ea-8e2d'; - const decoded = UUID.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual([ - 'Invalid value "4656dc92-5832-11ea-8e2d" supplied to "UUID"', - ]); - expect(message.schema).toEqual({}); - }); - - test('it should not validate an empty string', () => { - const payload = ''; - const decoded = UUID.decode(payload); - const message = pipe(decoded, foldLeftRight); - - expect(getPaths(left(message.errors))).toEqual(['Invalid value "" supplied to "UUID"']); - expect(message.schema).toEqual({}); - }); -}); diff --git a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/uuid.ts b/x-pack/plugins/security_solution/common/detection_engine/schemas/types/uuid.ts deleted file mode 100644 index 79a130b26a6f..000000000000 --- a/x-pack/plugins/security_solution/common/detection_engine/schemas/types/uuid.ts +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import * as t from 'io-ts'; -import { Either } from 'fp-ts/lib/Either'; - -const regex = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i; - -/** - * Types the risk score as: - * - Natural Number (positive integer and not a float), - * - Between the values [0 and 100] inclusive. - * @deprecated Use packages/kbn-securitysolution-io-ts-utils - */ -export const UUID = new t.Type( - 'UUID', - t.string.is, - (input, context): Either => { - return typeof input === 'string' && regex.test(input) - ? t.success(input) - : t.failure(input, context); - }, - t.identity -); - -export type UUIDC = typeof UUID; diff --git a/x-pack/plugins/security_solution/common/detection_engine/utils.ts b/x-pack/plugins/security_solution/common/detection_engine/utils.ts index 611d23fd1ce2..6aa672881ff7 100644 --- a/x-pack/plugins/security_solution/common/detection_engine/utils.ts +++ b/x-pack/plugins/security_solution/common/detection_engine/utils.ts @@ -9,9 +9,10 @@ import { isEmpty } from 'lodash'; import type { EntriesArray } from '@kbn/securitysolution-io-ts-list-types'; +import { Type } from '@kbn/securitysolution-io-ts-alerting-types'; import { CreateExceptionListItemSchema, ExceptionListItemSchema } from '../shared_imports'; -import { Type, JobStatus, Threshold, ThresholdNormalized } from './schemas/common/schemas'; +import { JobStatus, Threshold, ThresholdNormalized } from './schemas/common/schemas'; export const hasLargeValueItem = ( exceptionItems: Array diff --git a/x-pack/plugins/security_solution/common/exact_check.test.ts b/x-pack/plugins/security_solution/common/exact_check.test.ts deleted file mode 100644 index d4a4ad4ce76c..000000000000 --- a/x-pack/plugins/security_solution/common/exact_check.test.ts +++ /dev/null @@ -1,177 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import * as t from 'io-ts'; -import { left, right, Either } from 'fp-ts/lib/Either'; -import { pipe } from 'fp-ts/lib/pipeable'; - -import { exactCheck, findDifferencesRecursive } from './exact_check'; -import { foldLeftRight, getPaths } from './test_utils'; - -describe('exact_check', () => { - test('it returns an error if given extra object properties', () => { - const someType = t.exact( - t.type({ - a: t.string, - }) - ); - const payload = { a: 'test', b: 'test' }; - const decoded = someType.decode(payload); - const checked = exactCheck(payload, decoded); - const message = pipe(checked, foldLeftRight); - expect(getPaths(left(message.errors))).toEqual(['invalid keys "b"']); - expect(message.schema).toEqual({}); - }); - - test('it returns an error if the data type is not as expected', () => { - type UnsafeCastForTest = Either< - t.Errors, - { - a: number; - } - >; - - const someType = t.exact( - t.type({ - a: t.string, - }) - ); - - const payload = { a: 1 }; - const decoded = someType.decode(payload); - const checked = exactCheck(payload, decoded as UnsafeCastForTest); - const message = pipe(checked, foldLeftRight); - expect(getPaths(left(message.errors))).toEqual(['Invalid value "1" supplied to "a"']); - expect(message.schema).toEqual({}); - }); - - test('it does NOT return an error if given normal object properties', () => { - const someType = t.exact( - t.type({ - a: t.string, - }) - ); - const payload = { a: 'test' }; - const decoded = someType.decode(payload); - const checked = exactCheck(payload, decoded); - const message = pipe(checked, foldLeftRight); - expect(getPaths(left(message.errors))).toEqual([]); - expect(message.schema).toEqual(payload); - }); - - test('it will return an existing error and not validate', () => { - const payload = { a: 'test' }; - const validationError: t.ValidationError = { - value: 'Some existing error', - context: [], - message: 'some error', - }; - const error: t.Errors = [validationError]; - const leftValue = left(error); - const checked = exactCheck(payload, leftValue); - const message = pipe(checked, foldLeftRight); - expect(getPaths(left(message.errors))).toEqual(['some error']); - expect(message.schema).toEqual({}); - }); - - test('it will work with a regular "right" payload without any decoding', () => { - const payload = { a: 'test' }; - const rightValue = right(payload); - const checked = exactCheck(payload, rightValue); - const message = pipe(checked, foldLeftRight); - expect(getPaths(left(message.errors))).toEqual([]); - expect(message.schema).toEqual({ a: 'test' }); - }); - - test('it will work with decoding a null payload when the schema expects a null', () => { - const someType = t.union([ - t.exact( - t.type({ - a: t.string, - }) - ), - t.null, - ]); - const payload = null; - const decoded = someType.decode(payload); - const checked = exactCheck(payload, decoded); - const message = pipe(checked, foldLeftRight); - expect(getPaths(left(message.errors))).toEqual([]); - expect(message.schema).toEqual(null); - }); - - test('it should find no differences recursively with two empty objects', () => { - const difference = findDifferencesRecursive({}, {}); - expect(difference).toEqual([]); - }); - - test('it should find a single difference with two objects with different keys', () => { - const difference = findDifferencesRecursive({ a: 1 }, { b: 1 }); - expect(difference).toEqual(['a']); - }); - - test('it should find a two differences with two objects with multiple different keys', () => { - const difference = findDifferencesRecursive({ a: 1, c: 1 }, { b: 1 }); - expect(difference).toEqual(['a', 'c']); - }); - - test('it should find no differences with two objects with the same keys', () => { - const difference = findDifferencesRecursive({ a: 1, b: 1 }, { a: 1, b: 1 }); - expect(difference).toEqual([]); - }); - - test('it should find a difference with two deep objects with different same keys', () => { - const difference = findDifferencesRecursive({ a: 1, b: { c: 1 } }, { a: 1, b: { d: 1 } }); - expect(difference).toEqual(['c']); - }); - - test('it should find a difference within an array', () => { - const difference = findDifferencesRecursive({ a: 1, b: [{ c: 1 }] }, { a: 1, b: [{ a: 1 }] }); - expect(difference).toEqual(['c']); - }); - - test('it should find a no difference when using arrays that are identical', () => { - const difference = findDifferencesRecursive({ a: 1, b: [{ c: 1 }] }, { a: 1, b: [{ c: 1 }] }); - expect(difference).toEqual([]); - }); - - test('it should find differences when one has an array and the other does not', () => { - const difference = findDifferencesRecursive({ a: 1, b: [{ c: 1 }] }, { a: 1 }); - expect(difference).toEqual(['b', '[{"c":1}]']); - }); - - test('it should find differences when one has an deep object and the other does not', () => { - const difference = findDifferencesRecursive({ a: 1, b: { c: 1 } }, { a: 1 }); - expect(difference).toEqual(['b', '{"c":1}']); - }); - - test('it should find differences when one has a deep object with multiple levels and the other does not', () => { - const difference = findDifferencesRecursive({ a: 1, b: { c: { d: 1 } } }, { a: 1 }); - expect(difference).toEqual(['b', '{"c":{"d":1}}']); - }); - - test('it tests two deep objects as the same with no key differences', () => { - const difference = findDifferencesRecursive( - { a: 1, b: { c: { d: 1 } } }, - { a: 1, b: { c: { d: 1 } } } - ); - expect(difference).toEqual([]); - }); - - test('it tests two deep objects with just one deep key difference', () => { - const difference = findDifferencesRecursive( - { a: 1, b: { c: { d: 1 } } }, - { a: 1, b: { c: { e: 1 } } } - ); - expect(difference).toEqual(['d']); - }); - - test('it should not find any differences when the original and decoded are both null', () => { - const difference = findDifferencesRecursive(null, null); - expect(difference).toEqual([]); - }); -}); diff --git a/x-pack/plugins/security_solution/common/exact_check.ts b/x-pack/plugins/security_solution/common/exact_check.ts deleted file mode 100644 index 5334989ea085..000000000000 --- a/x-pack/plugins/security_solution/common/exact_check.ts +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import * as t from 'io-ts'; -import { left, Either, fold, right } from 'fp-ts/lib/Either'; -import { pipe } from 'fp-ts/lib/pipeable'; -import { isObject, get } from 'lodash/fp'; - -/** - * Given an original object and a decoded object this will return an error - * if and only if the original object has additional keys that the decoded - * object does not have. If the original decoded already has an error, then - * this will return the error as is and not continue. - * - * NOTE: You MUST use t.exact(...) for this to operate correctly as your schema - * needs to remove additional keys before the compare - * - * You might not need this in the future if the below issue is solved: - * https://github.com/gcanti/io-ts/issues/322 - * - * @param original The original to check if it has additional keys - * @param decoded The decoded either which has either an existing error or the - * decoded object which could have additional keys stripped from it. - * @deprecated Use packages/kbn-securitysolution-io-ts-utils/src/exact_check/index.ts - */ -export const exactCheck = ( - original: unknown, - decoded: Either -): Either => { - const onLeft = (errors: t.Errors): Either => left(errors); - const onRight = (decodedValue: T): Either => { - const differences = findDifferencesRecursive(original, decodedValue); - if (differences.length !== 0) { - const validationError: t.ValidationError = { - value: differences, - context: [], - message: `invalid keys "${differences.join(',')}"`, - }; - const error: t.Errors = [validationError]; - return left(error); - } else { - return right(decodedValue); - } - }; - return pipe(decoded, fold(onLeft, onRight)); -}; - -export const findDifferencesRecursive = (original: unknown, decodedValue: T): string[] => { - if (decodedValue === null && original === null) { - // both the decodedValue and the original are null which indicates that they are equal - // so do not report differences - return []; - } else if (decodedValue == null) { - try { - // It is null and painful when the original contains an object or an array - // the the decoded value does not have. - return [JSON.stringify(original)]; - } catch (err) { - return ['circular reference']; - } - } else if (typeof original !== 'object' || original == null) { - // We are not an object or null so do not report differences - return []; - } else { - const decodedKeys = Object.keys(decodedValue); - const differences = Object.keys(original).flatMap((originalKey) => { - const foundKey = decodedKeys.some((key) => key === originalKey); - const topLevelKey = foundKey ? [] : [originalKey]; - // I use lodash to cheat and get an any (not going to lie ;-)) - const valueObjectOrArrayOriginal = get(originalKey, original); - const valueObjectOrArrayDecoded = get(originalKey, decodedValue); - if (isObject(valueObjectOrArrayOriginal)) { - return [ - ...topLevelKey, - ...findDifferencesRecursive(valueObjectOrArrayOriginal, valueObjectOrArrayDecoded), - ]; - } else if (Array.isArray(valueObjectOrArrayOriginal)) { - return [ - ...topLevelKey, - ...valueObjectOrArrayOriginal.flatMap((arrayElement, index) => - findDifferencesRecursive(arrayElement, get(index, valueObjectOrArrayDecoded)) - ), - ]; - } else { - return topLevelKey; - } - }); - return differences; - } -}; diff --git a/x-pack/plugins/security_solution/common/format_errors.test.ts b/x-pack/plugins/security_solution/common/format_errors.test.ts deleted file mode 100644 index 149bae85fec8..000000000000 --- a/x-pack/plugins/security_solution/common/format_errors.test.ts +++ /dev/null @@ -1,188 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import * as t from 'io-ts'; -import { formatErrors } from './format_errors'; - -describe('utils', () => { - test('returns an empty error message string if there are no errors', () => { - const errors: t.Errors = []; - const output = formatErrors(errors); - expect(output).toEqual([]); - }); - - test('returns a single error message if given one', () => { - const validationError: t.ValidationError = { - value: 'Some existing error', - context: [], - message: 'some error', - }; - const errors: t.Errors = [validationError]; - const output = formatErrors(errors); - expect(output).toEqual(['some error']); - }); - - test('returns a two error messages if given two', () => { - const validationError1: t.ValidationError = { - value: 'Some existing error 1', - context: [], - message: 'some error 1', - }; - const validationError2: t.ValidationError = { - value: 'Some existing error 2', - context: [], - message: 'some error 2', - }; - const errors: t.Errors = [validationError1, validationError2]; - const output = formatErrors(errors); - expect(output).toEqual(['some error 1', 'some error 2']); - }); - - test('it filters out duplicate error messages', () => { - const validationError1: t.ValidationError = { - value: 'Some existing error 1', - context: [], - message: 'some error 1', - }; - const validationError2: t.ValidationError = { - value: 'Some existing error 1', - context: [], - message: 'some error 1', - }; - const errors: t.Errors = [validationError1, validationError2]; - const output = formatErrors(errors); - expect(output).toEqual(['some error 1']); - }); - - test('will use message before context if it is set', () => { - const context: t.Context = ([{ key: 'some string key' }] as unknown) as t.Context; - const validationError1: t.ValidationError = { - value: 'Some existing error 1', - context, - message: 'I should be used first', - }; - const errors: t.Errors = [validationError1]; - const output = formatErrors(errors); - expect(output).toEqual(['I should be used first']); - }); - - test('will use context entry of a single string', () => { - const context: t.Context = ([{ key: 'some string key' }] as unknown) as t.Context; - const validationError1: t.ValidationError = { - value: 'Some existing error 1', - context, - }; - const errors: t.Errors = [validationError1]; - const output = formatErrors(errors); - expect(output).toEqual(['Invalid value "Some existing error 1" supplied to "some string key"']); - }); - - test('will use two context entries of two strings', () => { - const context: t.Context = ([ - { key: 'some string key 1' }, - { key: 'some string key 2' }, - ] as unknown) as t.Context; - const validationError1: t.ValidationError = { - value: 'Some existing error 1', - context, - }; - const errors: t.Errors = [validationError1]; - const output = formatErrors(errors); - expect(output).toEqual([ - 'Invalid value "Some existing error 1" supplied to "some string key 1,some string key 2"', - ]); - }); - - test('will filter out and not use any strings of numbers', () => { - const context: t.Context = ([ - { key: '5' }, - { key: 'some string key 2' }, - ] as unknown) as t.Context; - const validationError1: t.ValidationError = { - value: 'Some existing error 1', - context, - }; - const errors: t.Errors = [validationError1]; - const output = formatErrors(errors); - expect(output).toEqual([ - 'Invalid value "Some existing error 1" supplied to "some string key 2"', - ]); - }); - - test('will filter out and not use null', () => { - const context: t.Context = ([ - { key: null }, - { key: 'some string key 2' }, - ] as unknown) as t.Context; - const validationError1: t.ValidationError = { - value: 'Some existing error 1', - context, - }; - const errors: t.Errors = [validationError1]; - const output = formatErrors(errors); - expect(output).toEqual([ - 'Invalid value "Some existing error 1" supplied to "some string key 2"', - ]); - }); - - test('will filter out and not use empty strings', () => { - const context: t.Context = ([ - { key: '' }, - { key: 'some string key 2' }, - ] as unknown) as t.Context; - const validationError1: t.ValidationError = { - value: 'Some existing error 1', - context, - }; - const errors: t.Errors = [validationError1]; - const output = formatErrors(errors); - expect(output).toEqual([ - 'Invalid value "Some existing error 1" supplied to "some string key 2"', - ]); - }); - - test('will use a name context if it cannot find a keyContext', () => { - const context: t.Context = ([ - { key: '' }, - { key: '', type: { name: 'someName' } }, - ] as unknown) as t.Context; - const validationError1: t.ValidationError = { - value: 'Some existing error 1', - context, - }; - const errors: t.Errors = [validationError1]; - const output = formatErrors(errors); - expect(output).toEqual(['Invalid value "Some existing error 1" supplied to "someName"']); - }); - - test('will return an empty string if name does not exist but type does', () => { - const context: t.Context = ([{ key: '' }, { key: '', type: {} }] as unknown) as t.Context; - const validationError1: t.ValidationError = { - value: 'Some existing error 1', - context, - }; - const errors: t.Errors = [validationError1]; - const output = formatErrors(errors); - expect(output).toEqual(['Invalid value "Some existing error 1" supplied to ""']); - }); - - test('will stringify an error value', () => { - const context: t.Context = ([ - { key: '' }, - { key: 'some string key 2' }, - ] as unknown) as t.Context; - const validationError1: t.ValidationError = { - value: { foo: 'some error' }, - context, - }; - const errors: t.Errors = [validationError1]; - const output = formatErrors(errors); - expect(output).toEqual([ - 'Invalid value "{"foo":"some error"}" supplied to "some string key 2"', - ]); - }); -}); diff --git a/x-pack/plugins/security_solution/common/format_errors.ts b/x-pack/plugins/security_solution/common/format_errors.ts deleted file mode 100644 index 16925699b0fc..000000000000 --- a/x-pack/plugins/security_solution/common/format_errors.ts +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import * as t from 'io-ts'; -import { isObject } from 'lodash/fp'; - -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils/src/format_errors/index.ts - */ -export const formatErrors = (errors: t.Errors): string[] => { - const err = errors.map((error) => { - if (error.message != null) { - return error.message; - } else { - const keyContext = error.context - .filter( - (entry) => entry.key != null && !Number.isInteger(+entry.key) && entry.key.trim() !== '' - ) - .map((entry) => entry.key) - .join(','); - - const nameContext = error.context.find((entry) => entry.type?.name?.length > 0); - const suppliedValue = - keyContext !== '' ? keyContext : nameContext != null ? nameContext.type.name : ''; - const value = isObject(error.value) ? JSON.stringify(error.value) : error.value; - return `Invalid value "${value}" supplied to "${suppliedValue}"`; - } - }); - - return [...new Set(err)]; -}; diff --git a/x-pack/plugins/security_solution/common/index.ts b/x-pack/plugins/security_solution/common/index.ts index 9f4af059632c..1fec1c76430e 100644 --- a/x-pack/plugins/security_solution/common/index.ts +++ b/x-pack/plugins/security_solution/common/index.ts @@ -4,5 +4,3 @@ * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ - -export * from './shared_exports'; diff --git a/x-pack/plugins/security_solution/common/machine_learning/helpers.ts b/x-pack/plugins/security_solution/common/machine_learning/helpers.ts index 60477d3685db..819337d8b715 100644 --- a/x-pack/plugins/security_solution/common/machine_learning/helpers.ts +++ b/x-pack/plugins/security_solution/common/machine_learning/helpers.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { Type } from '../detection_engine/schemas/common/schemas'; +import { Type } from '@kbn/securitysolution-io-ts-alerting-types'; // Based on ML Job/Datafeed States from x-pack/legacy/plugins/ml/common/constants/states.js const enabledStates = ['started', 'opened']; diff --git a/x-pack/plugins/security_solution/common/shared_exports.ts b/x-pack/plugins/security_solution/common/shared_exports.ts deleted file mode 100644 index bf740ddce9fd..000000000000 --- a/x-pack/plugins/security_solution/common/shared_exports.ts +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -export { NonEmptyString } from './detection_engine/schemas/types/non_empty_string'; -export { DefaultArray } from './detection_engine/schemas/types/default_array'; -export { DefaultUuid } from './detection_engine/schemas/types/default_uuid'; -export { DefaultStringArray } from './detection_engine/schemas/types/default_string_array'; -export { - DefaultVersionNumber, - DefaultVersionNumberDecoded, -} from './detection_engine/schemas/types/default_version_number'; -export { exactCheck } from './exact_check'; -export { getPaths, foldLeftRight, removeExternalLinkText } from './test_utils'; -export { validate, validateEither } from './validate'; -export { formatErrors } from './format_errors'; -export { addIdToItem, removeIdFromItem } from './add_remove_id_to_item'; diff --git a/x-pack/plugins/security_solution/common/shared_imports.ts b/x-pack/plugins/security_solution/common/shared_imports.ts index a6bad0347e64..8f858e724394 100644 --- a/x-pack/plugins/security_solution/common/shared_imports.ts +++ b/x-pack/plugins/security_solution/common/shared_imports.ts @@ -12,9 +12,6 @@ export { CreateExceptionListSchema, CreateExceptionListItemSchema, UpdateExceptionListItemSchema, - exceptionListItemSchema, - createExceptionListItemSchema, - listSchema, ENDPOINT_LIST_ID, ENDPOINT_TRUSTED_APPS_LIST_ID, EXCEPTION_LIST_URL, diff --git a/x-pack/plugins/security_solution/common/test_utils.ts b/x-pack/plugins/security_solution/common/test_utils.ts deleted file mode 100644 index df9e9e12fc1d..000000000000 --- a/x-pack/plugins/security_solution/common/test_utils.ts +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import * as t from 'io-ts'; -import { fold } from 'fp-ts/lib/Either'; -import { pipe } from 'fp-ts/lib/pipeable'; -import { formatErrors } from './format_errors'; - -interface Message { - errors: t.Errors; - schema: T | {}; -} - -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils/src/test_utils/index.ts - */ -const onLeft = (errors: t.Errors): Message => { - return { schema: {}, errors }; -}; - -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils/src/test_utils/index.ts - */ -const onRight = (schema: T): Message => { - return { - schema, - errors: [], - }; -}; - -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils/src/test_utils/index.ts - */ -export const foldLeftRight = fold(onLeft, onRight); - -/** - * Convenience utility to keep the error message handling within tests to be - * very concise. - * @deprecated Use packages/kbn-securitysolution-io-ts-utils/src/test_utils/index.ts - * @param validation The validation to get the errors from - */ -export const getPaths = (validation: t.Validation): string[] => { - return pipe( - validation, - fold( - (errors) => formatErrors(errors), - () => ['no errors'] - ) - ); -}; - -/** - * Convenience utility to remove text appended to links by EUI - * @deprecated Use packages/kbn-securitysolution-io-ts-utils/src/test_utils/index.ts - */ -export const removeExternalLinkText = (str: string) => - str.replace(/\(opens in a new tab or window\)/g, ''); diff --git a/x-pack/plugins/security_solution/common/types/timeline/index.ts b/x-pack/plugins/security_solution/common/types/timeline/index.ts index 5b6c9c532ba7..7ae52a3990ff 100644 --- a/x-pack/plugins/security_solution/common/types/timeline/index.ts +++ b/x-pack/plugins/security_solution/common/types/timeline/index.ts @@ -7,6 +7,7 @@ import * as runtimeTypes from 'io-ts'; +import { PositiveInteger } from '@kbn/securitysolution-io-ts-types'; import { stringEnum, unionWithNullType } from '../../utility_types'; import { NoteResult, NoteSavedObject, NoteSavedObjectToReturnRuntimeType } from './note'; import { @@ -19,7 +20,6 @@ import { success_count as successCount, } from '../../detection_engine/schemas/common/schemas'; import { FlowTarget } from '../../search_strategy/security_solution/network'; -import { PositiveInteger } from '../../detection_engine/schemas/types'; import { errorSchema } from '../../detection_engine/schemas/response/error_schema'; import { Direction, Maybe } from '../../search_strategy'; diff --git a/x-pack/plugins/security_solution/common/validate.test.ts b/x-pack/plugins/security_solution/common/validate.test.ts deleted file mode 100644 index e3fe5c55288a..000000000000 --- a/x-pack/plugins/security_solution/common/validate.test.ts +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { left, right } from 'fp-ts/lib/Either'; -import * as t from 'io-ts'; - -import { validate, validateEither } from './validate'; - -describe('validate', () => { - test('it should do a validation correctly', () => { - const schema = t.exact(t.type({ a: t.number })); - const payload = { a: 1 }; - const [validated, errors] = validate(payload, schema); - - expect(validated).toEqual(payload); - expect(errors).toEqual(null); - }); - - test('it should do an in-validation correctly', () => { - const schema = t.exact(t.type({ a: t.number })); - const payload = { a: 'some other value' }; - const [validated, errors] = validate(payload, schema); - - expect(validated).toEqual(null); - expect(errors).toEqual('Invalid value "some other value" supplied to "a"'); - }); -}); - -describe('validateEither', () => { - it('returns the ORIGINAL payload as right if valid', () => { - const schema = t.exact(t.type({ a: t.number })); - const payload = { a: 1 }; - const result = validateEither(schema, payload); - - expect(result).toEqual(right(payload)); - }); - - it('returns an error string if invalid', () => { - const schema = t.exact(t.type({ a: t.number })); - const payload = { a: 'some other value' }; - const result = validateEither(schema, payload); - - expect(result).toEqual(left(new Error('Invalid value "some other value" supplied to "a"'))); - }); -}); diff --git a/x-pack/plugins/security_solution/common/validate.ts b/x-pack/plugins/security_solution/common/validate.ts deleted file mode 100644 index 1ac41ecbfb88..000000000000 --- a/x-pack/plugins/security_solution/common/validate.ts +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { fold, Either, mapLeft } from 'fp-ts/lib/Either'; -import { pipe } from 'fp-ts/lib/pipeable'; -import { fromEither, TaskEither } from 'fp-ts/lib/TaskEither'; -import * as t from 'io-ts'; -import { exactCheck } from './exact_check'; -import { formatErrors } from './format_errors'; - -export const validate = ( - obj: object, - schema: T -): [t.TypeOf | null, string | null] => { - const decoded = schema.decode(obj); - const checked = exactCheck(obj, decoded); - const left = (errors: t.Errors): [T | null, string | null] => [ - null, - formatErrors(errors).join(','), - ]; - const right = (output: T): [T | null, string | null] => [output, null]; - return pipe(checked, fold(left, right)); -}; - -export const validateNonExact = ( - obj: unknown, - schema: T -): [t.TypeOf | null, string | null] => { - const decoded = schema.decode(obj); - const left = (errors: t.Errors): [T | null, string | null] => [ - null, - formatErrors(errors).join(','), - ]; - const right = (output: T): [T | null, string | null] => [output, null]; - return pipe(decoded, fold(left, right)); -}; - -export const validateEither = ( - schema: T, - obj: A -): Either => - pipe( - obj, - (a) => schema.validate(a, t.getDefaultContext(schema.asDecoder())), - mapLeft((errors) => new Error(formatErrors(errors).join(','))) - ); - -export const validateTaskEither = ( - schema: T, - obj: A -): TaskEither => fromEither(validateEither(schema, obj)); diff --git a/x-pack/plugins/security_solution/public/common/components/autocomplete/field_value_lists.test.tsx b/x-pack/plugins/security_solution/public/common/components/autocomplete/field_value_lists.test.tsx index c605a71c50e3..45d4137f8c5b 100644 --- a/x-pack/plugins/security_solution/public/common/components/autocomplete/field_value_lists.test.tsx +++ b/x-pack/plugins/security_solution/public/common/components/autocomplete/field_value_lists.test.tsx @@ -11,7 +11,7 @@ import { EuiComboBox, EuiComboBoxOptionOption } from '@elastic/eui'; import { waitFor } from '@testing-library/react'; import { getField } from '../../../../../../../src/plugins/data/common/index_patterns/fields/fields.mocks'; -import { ListSchema } from '../../../lists_plugin_deps'; +import { ListSchema } from '../../../shared_imports'; import { getFoundListSchemaMock } from '../../../../../lists/common/schemas/response/found_list_schema.mock'; import { getListResponseMock } from '../../../../../lists/common/schemas/response/list_schema.mock'; import { DATE_NOW, VERSION, IMMUTABLE } from '../../../../../lists/common/constants.mock'; @@ -28,8 +28,8 @@ const mockKeywordList: ListSchema = { }; const mockResult = { ...getFoundListSchemaMock() }; mockResult.data = [...mockResult.data, mockKeywordList]; -jest.mock('../../../lists_plugin_deps', () => { - const originalModule = jest.requireActual('../../../lists_plugin_deps'); +jest.mock('../../../shared_imports', () => { + const originalModule = jest.requireActual('../../../shared_imports'); return { ...originalModule, diff --git a/x-pack/plugins/security_solution/public/common/components/autocomplete/field_value_lists.tsx b/x-pack/plugins/security_solution/public/common/components/autocomplete/field_value_lists.tsx index 3efa8c4c2d60..37e5961c8cd7 100644 --- a/x-pack/plugins/security_solution/public/common/components/autocomplete/field_value_lists.tsx +++ b/x-pack/plugins/security_solution/public/common/components/autocomplete/field_value_lists.tsx @@ -9,7 +9,7 @@ import React, { useState, useEffect, useCallback, useMemo } from 'react'; import { EuiFormRow, EuiComboBoxOptionOption, EuiComboBox } from '@elastic/eui'; import { IFieldType } from '../../../../../../../src/plugins/data/common'; -import { useFindLists, ListSchema } from '../../../lists_plugin_deps'; +import { useFindLists, ListSchema } from '../../../shared_imports'; import { useKibana } from '../../../common/lib/kibana'; import { filterFieldToList, getGenericComboBoxProps } from './helpers'; import * as i18n from './translations'; diff --git a/x-pack/plugins/security_solution/public/common/components/autocomplete/helpers.ts b/x-pack/plugins/security_solution/public/common/components/autocomplete/helpers.ts index bd79bb0fcc8e..13f4e5e6fd6f 100644 --- a/x-pack/plugins/security_solution/public/common/components/autocomplete/helpers.ts +++ b/x-pack/plugins/security_solution/public/common/components/autocomplete/helpers.ts @@ -9,7 +9,7 @@ import dateMath from '@elastic/datemath'; import { EuiComboBoxOptionOption } from '@elastic/eui'; import type { Type } from '@kbn/securitysolution-io-ts-list-types'; -import type { ListSchema } from '../../../lists_plugin_deps'; +import type { ListSchema } from '../../../shared_imports'; import { IFieldType } from '../../../../../../../src/plugins/data/common'; import { diff --git a/x-pack/plugins/security_solution/public/common/components/exceptions/add_exception_modal/index.tsx b/x-pack/plugins/security_solution/public/common/components/exceptions/add_exception_modal/index.tsx index 6efbbcf64406..3216a020c3b0 100644 --- a/x-pack/plugins/security_solution/public/common/components/exceptions/add_exception_modal/index.tsx +++ b/x-pack/plugins/security_solution/public/common/components/exceptions/add_exception_modal/index.tsx @@ -25,7 +25,11 @@ import { EuiComboBox, EuiComboBoxOptionOption, } from '@elastic/eui'; -import type { ExceptionListType } from '@kbn/securitysolution-io-ts-list-types'; +import type { + ExceptionListType, + OsTypeArray, + OsType, +} from '@kbn/securitysolution-io-ts-list-types'; import { hasEqlSequenceQuery, isEqlRule, @@ -63,7 +67,6 @@ import { ErrorInfo, ErrorCallout } from '../error_callout'; import { AlertData, ExceptionsBuilderExceptionItem } from '../types'; import { useFetchIndex } from '../../../containers/source'; import { useGetInstalledJob } from '../../ml/hooks/use_get_jobs'; -import { OsTypeArray, OsType } from '../../../../../../lists/common/schemas'; export interface AddExceptionModalProps { ruleName: string; diff --git a/x-pack/plugins/security_solution/public/common/components/exceptions/edit_exception_modal/index.tsx b/x-pack/plugins/security_solution/public/common/components/exceptions/edit_exception_modal/index.tsx index 6c68dcf934b7..ed050574c399 100644 --- a/x-pack/plugins/security_solution/public/common/components/exceptions/edit_exception_modal/index.tsx +++ b/x-pack/plugins/security_solution/public/common/components/exceptions/edit_exception_modal/index.tsx @@ -22,7 +22,11 @@ import { EuiCallOut, } from '@elastic/eui'; -import type { ExceptionListType } from '@kbn/securitysolution-io-ts-list-types'; +import type { + ExceptionListType, + OsTypeArray, + OsType, +} from '@kbn/securitysolution-io-ts-list-types'; import { hasEqlSequenceQuery, isEqlRule, @@ -54,7 +58,6 @@ import { import { Loader } from '../../loader'; import { ErrorInfo, ErrorCallout } from '../error_callout'; import { useGetInstalledJob } from '../../ml/hooks/use_get_jobs'; -import { OsTypeArray, OsType } from '../../../../../../lists/common/schemas'; interface EditExceptionModalProps { ruleName: string; diff --git a/x-pack/plugins/security_solution/public/common/components/exceptions/error_callout.tsx b/x-pack/plugins/security_solution/public/common/components/exceptions/error_callout.tsx index 2317ec353a3b..ba8b5b522f0a 100644 --- a/x-pack/plugins/security_solution/public/common/components/exceptions/error_callout.tsx +++ b/x-pack/plugins/security_solution/public/common/components/exceptions/error_callout.tsx @@ -16,8 +16,8 @@ import { EuiSpacer, } from '@elastic/eui'; +import { List } from '@kbn/securitysolution-io-ts-list-types'; import { HttpSetup } from '../../../../../../../src/core/public'; -import { List } from '../../../../common/detection_engine/schemas/types/lists'; import { Rule } from '../../../detections/containers/detection_engine/rules/types'; import * as i18n from './translations'; import { useDissasociateExceptionList } from '../../../detections/containers/detection_engine/rules/use_dissasociate_exception_list'; diff --git a/x-pack/plugins/security_solution/public/common/components/exceptions/types.ts b/x-pack/plugins/security_solution/public/common/components/exceptions/types.ts index 49cdd7103c48..bbf83a58e367 100644 --- a/x-pack/plugins/security_solution/public/common/components/exceptions/types.ts +++ b/x-pack/plugins/security_solution/public/common/components/exceptions/types.ts @@ -17,11 +17,14 @@ import type { ListOperatorTypeEnum as OperatorTypeEnum, ListOperatorEnum as OperatorEnum, } from '@kbn/securitysolution-io-ts-list-types'; -import { Ecs } from '../../../../common/ecs'; -import { CodeSignature } from '../../../../common/ecs/file'; -import { IFieldType } from '../../../../../../../src/plugins/data/common'; -import { OperatorOption } from '../autocomplete/types'; -import { ExceptionListItemSchema, CreateExceptionListItemSchema } from '../../../lists_plugin_deps'; +import type { Ecs } from '../../../../common/ecs'; +import type { CodeSignature } from '../../../../common/ecs/file'; +import type { IFieldType } from '../../../../../../../src/plugins/data/common'; +import type { OperatorOption } from '../autocomplete/types'; +import type { + ExceptionListItemSchema, + CreateExceptionListItemSchema, +} from '../../../shared_imports'; export interface FormattedEntry { fieldName: string; diff --git a/x-pack/plugins/security_solution/public/common/components/exceptions/use_add_exception.test.tsx b/x-pack/plugins/security_solution/public/common/components/exceptions/use_add_exception.test.tsx index f609acf9c6c6..c8a624b009c4 100644 --- a/x-pack/plugins/security_solution/public/common/components/exceptions/use_add_exception.test.tsx +++ b/x-pack/plugins/security_solution/public/common/components/exceptions/use_add_exception.test.tsx @@ -16,11 +16,11 @@ import * as buildFilterHelpers from '../../../detections/components/alerts_table import { getExceptionListItemSchemaMock } from '../../../../../lists/common/schemas/response/exception_list_item_schema.mock'; import { getCreateExceptionListItemSchemaMock } from '../../../../../lists/common/schemas/request/create_exception_list_item_schema.mock'; import { getUpdateExceptionListItemSchemaMock } from '../../../../../lists/common/schemas/request/update_exception_list_item_schema.mock'; -import { +import type { ExceptionListItemSchema, CreateExceptionListItemSchema, UpdateExceptionListItemSchema, -} from '../../../lists_plugin_deps'; +} from '../../../shared_imports'; import { useAddOrUpdateException, UseAddOrUpdateExceptionProps, diff --git a/x-pack/plugins/security_solution/public/common/components/exceptions/use_add_exception.tsx b/x-pack/plugins/security_solution/public/common/components/exceptions/use_add_exception.tsx index 614f5301c82e..6aa68373d5eb 100644 --- a/x-pack/plugins/security_solution/public/common/components/exceptions/use_add_exception.tsx +++ b/x-pack/plugins/security_solution/public/common/components/exceptions/use_add_exception.tsx @@ -13,7 +13,7 @@ import { ExceptionListItemSchema, CreateExceptionListItemSchema, useApi, -} from '../../../lists_plugin_deps'; +} from '../../../shared_imports'; import { updateAlertStatus } from '../../../detections/containers/detection_engine/alerts/api'; import { getUpdateAlertsQuery } from '../../../detections/components/alerts_table/actions'; import { diff --git a/x-pack/plugins/security_solution/public/common/components/exceptions/use_fetch_or_create_rule_exception_list.test.tsx b/x-pack/plugins/security_solution/public/common/components/exceptions/use_fetch_or_create_rule_exception_list.test.tsx index 17237f4f94c6..d38d920eee18 100644 --- a/x-pack/plugins/security_solution/public/common/components/exceptions/use_fetch_or_create_rule_exception_list.test.tsx +++ b/x-pack/plugins/security_solution/public/common/components/exceptions/use_fetch_or_create_rule_exception_list.test.tsx @@ -12,8 +12,7 @@ import * as rulesApi from '../../../detections/containers/detection_engine/rules import * as listsApi from '../../../../../lists/public/exceptions/api'; import { getExceptionListSchemaMock } from '../../../../../lists/common/schemas/response/exception_list_schema.mock'; import { savedRuleMock } from '../../../detections/containers/detection_engine/rules/mock'; -import type { ExceptionListType } from '@kbn/securitysolution-io-ts-list-types'; -import { ListArray } from '../../../../common/detection_engine/schemas/types'; +import type { ExceptionListType, ListArray } from '@kbn/securitysolution-io-ts-list-types'; import { getListArrayMock } from '../../../../common/detection_engine/schemas/types/lists.mock'; import { useFetchOrCreateRuleExceptionList, diff --git a/x-pack/plugins/security_solution/public/common/components/exceptions/use_fetch_or_create_rule_exception_list.tsx b/x-pack/plugins/security_solution/public/common/components/exceptions/use_fetch_or_create_rule_exception_list.tsx index 9b970e2caab1..98c207f47a45 100644 --- a/x-pack/plugins/security_solution/public/common/components/exceptions/use_fetch_or_create_rule_exception_list.tsx +++ b/x-pack/plugins/security_solution/public/common/components/exceptions/use_fetch_or_create_rule_exception_list.tsx @@ -6,10 +6,10 @@ */ import { useEffect, useState } from 'react'; +import { List, ListArray } from '@kbn/securitysolution-io-ts-list-types'; import { HttpStart } from '../../../../../../../src/core/public'; import { Rule } from '../../../detections/containers/detection_engine/rules/types'; -import { List, ListArray } from '../../../../common/detection_engine/schemas/types'; import { fetchRuleById, patchRule, @@ -18,7 +18,7 @@ import { fetchExceptionListById, addExceptionList, addEndpointExceptionList, -} from '../../../lists_plugin_deps'; +} from '../../../shared_imports'; import { ExceptionListSchema, CreateExceptionListSchema, diff --git a/x-pack/plugins/security_solution/public/common/components/exceptions/viewer/exception_item/exception_details.tsx b/x-pack/plugins/security_solution/public/common/components/exceptions/viewer/exception_item/exception_details.tsx index 86eca688ef08..ff242506927f 100644 --- a/x-pack/plugins/security_solution/public/common/components/exceptions/viewer/exception_item/exception_details.tsx +++ b/x-pack/plugins/security_solution/public/common/components/exceptions/viewer/exception_item/exception_details.tsx @@ -16,10 +16,10 @@ import { import React, { useMemo, Fragment } from 'react'; import styled, { css } from 'styled-components'; -import { DescriptionListItem } from '../../types'; +import type { DescriptionListItem } from '../../types'; import { getDescriptionListContent } from '../helpers'; import * as i18n from '../../translations'; -import { ExceptionListItemSchema } from '../../../../../../public/lists_plugin_deps'; +import type { ExceptionListItemSchema } from '../../../../../../public/shared_imports'; const MyExceptionDetails = styled(EuiFlexItem)` ${({ theme }) => css` diff --git a/x-pack/plugins/security_solution/public/common/components/exceptions/viewer/exception_item/index.tsx b/x-pack/plugins/security_solution/public/common/components/exceptions/viewer/exception_item/index.tsx index caff2be29ab2..7909366e7a32 100644 --- a/x-pack/plugins/security_solution/public/common/components/exceptions/viewer/exception_item/index.tsx +++ b/x-pack/plugins/security_solution/public/common/components/exceptions/viewer/exception_item/index.tsx @@ -20,8 +20,8 @@ import { ExceptionDetails } from './exception_details'; import { ExceptionEntries } from './exception_entries'; import { getFormattedComments } from '../../helpers'; import { getFormattedEntries } from '../helpers'; -import { FormattedEntry, ExceptionListItemIdentifiers } from '../../types'; -import { ExceptionListItemSchema } from '../../../../../../public/lists_plugin_deps'; +import type { FormattedEntry, ExceptionListItemIdentifiers } from '../../types'; +import type { ExceptionListItemSchema } from '../../../../../../public/shared_imports'; const MyFlexItem = styled(EuiFlexItem)` &.comments--show { diff --git a/x-pack/plugins/security_solution/public/common/components/exceptions/viewer/exceptions_viewer_items.tsx b/x-pack/plugins/security_solution/public/common/components/exceptions/viewer/exceptions_viewer_items.tsx index 825bbf5f6f05..1e4cd306c466 100644 --- a/x-pack/plugins/security_solution/public/common/components/exceptions/viewer/exceptions_viewer_items.tsx +++ b/x-pack/plugins/security_solution/public/common/components/exceptions/viewer/exceptions_viewer_items.tsx @@ -12,8 +12,8 @@ import styled from 'styled-components'; import * as i18n from '../translations'; import { ExceptionItem } from './exception_item'; import { AndOrBadge } from '../../and_or_badge'; -import { ExceptionListItemSchema } from '../../../../../public/lists_plugin_deps'; -import { ExceptionListItemIdentifiers } from '../types'; +import type { ExceptionListItemSchema } from '../../../../../public/shared_imports'; +import type { ExceptionListItemIdentifiers } from '../types'; const MyFlexItem = styled(EuiFlexItem)` margin: ${({ theme }) => `${theme.eui.euiSize} 0`}; diff --git a/x-pack/plugins/security_solution/public/common/components/exceptions/viewer/helpers.tsx b/x-pack/plugins/security_solution/public/common/components/exceptions/viewer/helpers.tsx index abd45cf2945c..936423d0c362 100644 --- a/x-pack/plugins/security_solution/public/common/components/exceptions/viewer/helpers.tsx +++ b/x-pack/plugins/security_solution/public/common/components/exceptions/viewer/helpers.tsx @@ -12,10 +12,10 @@ import { ExceptionListItemSchema, getEntryValue, getExceptionOperatorSelect, -} from '../../../../lists_plugin_deps'; +} from '../../../../shared_imports'; import { formatOperatingSystems } from '../helpers'; -import { FormattedEntry, BuilderEntry, DescriptionListItem } from '../types'; +import type { FormattedEntry, BuilderEntry, DescriptionListItem } from '../types'; import * as i18n from '../translations'; /** diff --git a/x-pack/plugins/security_solution/public/common/components/exceptions/viewer/index.test.tsx b/x-pack/plugins/security_solution/public/common/components/exceptions/viewer/index.test.tsx index 971b3fda4719..45db39d6a03a 100644 --- a/x-pack/plugins/security_solution/public/common/components/exceptions/viewer/index.test.tsx +++ b/x-pack/plugins/security_solution/public/common/components/exceptions/viewer/index.test.tsx @@ -11,7 +11,7 @@ import { ThemeProvider } from 'styled-components'; import { ExceptionsViewer } from './'; import { useKibana } from '../../../../common/lib/kibana'; -import { useExceptionListItems, useApi } from '../../../../../public/lists_plugin_deps'; +import { useExceptionListItems, useApi } from '../../../../../public/shared_imports'; import { ExceptionListTypeEnum } from '@kbn/securitysolution-io-ts-list-types'; import { getExceptionListSchemaMock } from '../../../../../../lists/common/schemas/response/exception_list_schema.mock'; @@ -31,7 +31,7 @@ const mockTheme = getMockTheme({ }); jest.mock('../../../../common/lib/kibana'); -jest.mock('../../../../../public/lists_plugin_deps'); +jest.mock('../../../../../public/shared_imports'); describe('ExceptionsViewer', () => { const ruleName = 'test rule'; diff --git a/x-pack/plugins/security_solution/public/common/components/exceptions/viewer/index.tsx b/x-pack/plugins/security_solution/public/common/components/exceptions/viewer/index.tsx index da7607f40ab7..8055e771a164 100644 --- a/x-pack/plugins/security_solution/public/common/components/exceptions/viewer/index.tsx +++ b/x-pack/plugins/security_solution/public/common/components/exceptions/viewer/index.tsx @@ -24,7 +24,7 @@ import { ExceptionListItemSchema, UseExceptionListItemsSuccess, useApi, -} from '../../../../../public/lists_plugin_deps'; +} from '../../../../../public/shared_imports'; import { ExceptionsViewerPagination } from './exceptions_pagination'; import { ExceptionsViewerUtility } from './exceptions_utility'; diff --git a/x-pack/plugins/security_solution/public/common/components/exceptions/viewer/reducer.ts b/x-pack/plugins/security_solution/public/common/components/exceptions/viewer/reducer.ts index bf8e454e9971..4908a88b7252 100644 --- a/x-pack/plugins/security_solution/public/common/components/exceptions/viewer/reducer.ts +++ b/x-pack/plugins/security_solution/public/common/components/exceptions/viewer/reducer.ts @@ -6,17 +6,17 @@ */ import type { ExceptionListType } from '@kbn/securitysolution-io-ts-list-types'; -import { +import type { FilterOptions, ExceptionsPagination, ExceptionListItemIdentifiers, Filter, } from '../types'; -import { +import type { ExceptionListItemSchema, ExceptionListIdentifiers, Pagination, -} from '../../../../../public/lists_plugin_deps'; +} from '../../../../../public/shared_imports'; export type ViewerModalName = 'addModal' | 'editModal' | null; diff --git a/x-pack/plugins/security_solution/public/common/components/links/index.test.tsx b/x-pack/plugins/security_solution/public/common/components/links/index.test.tsx index cd19eb5a27d7..965167f2c945 100644 --- a/x-pack/plugins/security_solution/public/common/components/links/index.test.tsx +++ b/x-pack/plugins/security_solution/public/common/components/links/index.test.tsx @@ -7,7 +7,7 @@ import { mount, shallow, ReactWrapper, ShallowWrapper } from 'enzyme'; import React from 'react'; -import { removeExternalLinkText } from '../../../../common/test_utils'; +import { removeExternalLinkText } from '@kbn/securitysolution-io-ts-utils'; import { mountWithIntl } from '@kbn/test/jest'; import { encodeIpv6 } from '../../lib/helpers'; diff --git a/x-pack/plugins/security_solution/public/common/components/markdown_editor/renderer.test.tsx b/x-pack/plugins/security_solution/public/common/components/markdown_editor/renderer.test.tsx index 490392c237e1..da3785648de6 100644 --- a/x-pack/plugins/security_solution/public/common/components/markdown_editor/renderer.test.tsx +++ b/x-pack/plugins/security_solution/public/common/components/markdown_editor/renderer.test.tsx @@ -8,7 +8,7 @@ import React from 'react'; import { mount } from 'enzyme'; -import { removeExternalLinkText } from '../../../../common/test_utils'; +import { removeExternalLinkText } from '@kbn/securitysolution-io-ts-utils'; import { MarkdownRenderer } from './renderer'; describe('Markdown', () => { diff --git a/x-pack/plugins/security_solution/public/common/components/threat_match/entry_delete_button.test.tsx b/x-pack/plugins/security_solution/public/common/components/threat_match/entry_delete_button.test.tsx index 9c3056469931..0e8edbf04752 100644 --- a/x-pack/plugins/security_solution/public/common/components/threat_match/entry_delete_button.test.tsx +++ b/x-pack/plugins/security_solution/public/common/components/threat_match/entry_delete_button.test.tsx @@ -7,7 +7,7 @@ import { mount } from 'enzyme'; import React from 'react'; -import { ThreatMappingEntries } from '../../../../common/detection_engine/schemas/types'; +import { ThreatMappingEntries } from '@kbn/securitysolution-io-ts-alerting-types'; import { EntryDeleteButtonComponent } from './entry_delete_button'; diff --git a/x-pack/plugins/security_solution/public/common/components/threat_match/helpers.test.tsx b/x-pack/plugins/security_solution/public/common/components/threat_match/helpers.test.tsx index 1d576dc6da32..cf9407a6bf46 100644 --- a/x-pack/plugins/security_solution/public/common/components/threat_match/helpers.test.tsx +++ b/x-pack/plugins/security_solution/public/common/components/threat_match/helpers.test.tsx @@ -20,7 +20,7 @@ import { getFormattedEntry, getUpdatedEntriesOnDelete, } from './helpers'; -import { ThreatMapEntry } from '../../../../common/detection_engine/schemas/types'; +import { ThreatMapEntry } from '@kbn/securitysolution-io-ts-alerting-types'; jest.mock('uuid', () => ({ v4: jest.fn().mockReturnValue('123'), diff --git a/x-pack/plugins/security_solution/public/common/components/threat_match/helpers.tsx b/x-pack/plugins/security_solution/public/common/components/threat_match/helpers.tsx index ef3e9280e6e6..232fac4ad843 100644 --- a/x-pack/plugins/security_solution/public/common/components/threat_match/helpers.tsx +++ b/x-pack/plugins/security_solution/public/common/components/threat_match/helpers.tsx @@ -6,15 +6,11 @@ */ import uuid from 'uuid'; -import { - ThreatMap, - threatMap, - ThreatMapping, -} from '../../../../common/detection_engine/schemas/types'; +import { addIdToItem } from '@kbn/securitysolution-utils'; +import { ThreatMap, threatMap, ThreatMapping } from '@kbn/securitysolution-io-ts-alerting-types'; import { IndexPattern, IFieldType } from '../../../../../../../src/plugins/data/common'; import { Entry, FormattedEntry, ThreatMapEntries, EmptyEntry } from './types'; -import { addIdToItem } from '../../../../common/add_remove_id_to_item'; /** * Formats the entry into one that is easily usable for the UI. diff --git a/x-pack/plugins/security_solution/public/common/components/threat_match/index.tsx b/x-pack/plugins/security_solution/public/common/components/threat_match/index.tsx index 8bdbe7b1a3db..3e4f0283145e 100644 --- a/x-pack/plugins/security_solution/public/common/components/threat_match/index.tsx +++ b/x-pack/plugins/security_solution/public/common/components/threat_match/index.tsx @@ -9,7 +9,7 @@ import React, { useCallback, useEffect, useReducer } from 'react'; import { EuiFlexGroup, EuiFlexItem } from '@elastic/eui'; import styled from 'styled-components'; -import { ThreatMapping } from '../../../../common/detection_engine/schemas/types'; +import { ThreatMapping } from '@kbn/securitysolution-io-ts-alerting-types'; import { ListItemComponent } from './list_item'; import { IndexPattern } from '../../../../../../../src/plugins/data/common'; import { AndOrBadge } from '../and_or_badge'; diff --git a/x-pack/plugins/security_solution/public/common/components/threat_match/reducer.test.ts b/x-pack/plugins/security_solution/public/common/components/threat_match/reducer.test.ts index 8d1ae27ec6f7..7c19b61efff0 100644 --- a/x-pack/plugins/security_solution/public/common/components/threat_match/reducer.test.ts +++ b/x-pack/plugins/security_solution/public/common/components/threat_match/reducer.test.ts @@ -8,7 +8,7 @@ import { ThreatMapEntries } from './types'; import { State, reducer } from './reducer'; import { getDefaultEmptyEntry } from './helpers'; -import { ThreatMapEntry } from '../../../../common/detection_engine/schemas/types'; +import { ThreatMapEntry } from '@kbn/securitysolution-io-ts-alerting-types'; jest.mock('uuid', () => ({ v4: jest.fn().mockReturnValue('123'), diff --git a/x-pack/plugins/security_solution/public/common/components/threat_match/types.ts b/x-pack/plugins/security_solution/public/common/components/threat_match/types.ts index 0ea7727f2282..3d4fa19ac579 100644 --- a/x-pack/plugins/security_solution/public/common/components/threat_match/types.ts +++ b/x-pack/plugins/security_solution/public/common/components/threat_match/types.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { ThreatMap, ThreatMapEntry } from '../../../../common/detection_engine/schemas/types'; +import { ThreatMap, ThreatMapEntry } from '@kbn/securitysolution-io-ts-alerting-types'; import { IFieldType } from '../../../../../../../src/plugins/data/common'; export interface FormattedEntry { diff --git a/x-pack/plugins/security_solution/public/detections/components/rules/description_step/helpers.tsx b/x-pack/plugins/security_solution/public/detections/components/rules/description_step/helpers.tsx index 7b9c3f35ef57..17162a2206fc 100644 --- a/x-pack/plugins/security_solution/public/detections/components/rules/description_step/helpers.tsx +++ b/x-pack/plugins/security_solution/public/detections/components/rules/description_step/helpers.tsx @@ -22,12 +22,12 @@ import { isEmpty } from 'lodash/fp'; import React from 'react'; import styled from 'styled-components'; +import { ThreatMapping, Type } from '@kbn/securitysolution-io-ts-alerting-types'; import { MATCHES, AND, OR } from '../../../../common/components/threat_match/translations'; -import { ThreatMapping } from '../../../../../common/detection_engine/schemas/types'; import { assertUnreachable } from '../../../../../common/utility_types'; import * as i18nSeverity from '../severity_mapping/translations'; import * as i18nRiskScore from '../risk_score_mapping/translations'; -import { Threshold, Type } from '../../../../../common/detection_engine/schemas/common/schemas'; +import { Threshold } from '../../../../../common/detection_engine/schemas/common/schemas'; import { esFilters } from '../../../../../../../../src/plugins/data/public'; import { diff --git a/x-pack/plugins/security_solution/public/detections/components/rules/description_step/index.tsx b/x-pack/plugins/security_solution/public/detections/components/rules/description_step/index.tsx index 9c4085379474..ab84f1a65cc4 100644 --- a/x-pack/plugins/security_solution/public/detections/components/rules/description_step/index.tsx +++ b/x-pack/plugins/security_solution/public/detections/components/rules/description_step/index.tsx @@ -10,7 +10,7 @@ import { isEmpty, chunk, get, pick, isNumber } from 'lodash/fp'; import React, { memo, useState } from 'react'; import styled from 'styled-components'; -import { ThreatMapping } from '../../../../../common/detection_engine/schemas/types'; +import { ThreatMapping, Threats, Type } from '@kbn/securitysolution-io-ts-alerting-types'; import { IIndexPattern, Filter, @@ -39,7 +39,6 @@ import { import { buildMlJobsDescription } from './ml_job_description'; import { buildActionsDescription } from './actions_description'; import { buildThrottleDescription } from './throttle_description'; -import { Threats, Type } from '../../../../../common/detection_engine/schemas/common/schemas'; import { THREAT_QUERY_LABEL } from './translations'; import { filterEmptyThreats } from '../../../pages/detection_engine/rules/create/helpers'; diff --git a/x-pack/plugins/security_solution/public/detections/components/rules/description_step/types.ts b/x-pack/plugins/security_solution/public/detections/components/rules/description_step/types.ts index 0e685da07822..dc5e7fea8e77 100644 --- a/x-pack/plugins/security_solution/public/detections/components/rules/description_step/types.ts +++ b/x-pack/plugins/security_solution/public/detections/components/rules/description_step/types.ts @@ -6,7 +6,7 @@ */ import { ReactNode } from 'react'; -import { Threats } from '../../../../../common/detection_engine/schemas/common/schemas'; +import { Threats } from '@kbn/securitysolution-io-ts-alerting-types'; import { IIndexPattern, diff --git a/x-pack/plugins/security_solution/public/detections/components/rules/mitre/helpers.ts b/x-pack/plugins/security_solution/public/detections/components/rules/mitre/helpers.ts index b867d3d76cc7..6f5cb37d9f91 100644 --- a/x-pack/plugins/security_solution/public/detections/components/rules/mitre/helpers.ts +++ b/x-pack/plugins/security_solution/public/detections/components/rules/mitre/helpers.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { ThreatTechnique } from '../../../../../common/detection_engine/schemas/common/schemas'; +import { ThreatTechnique } from '@kbn/securitysolution-io-ts-alerting-types'; import { subtechniquesOptions } from '../../../mitre/mitre_tactics_techniques'; /** diff --git a/x-pack/plugins/security_solution/public/detections/components/rules/mitre/index.tsx b/x-pack/plugins/security_solution/public/detections/components/rules/mitre/index.tsx index c39efa1409bc..25eb7a65e0d1 100644 --- a/x-pack/plugins/security_solution/public/detections/components/rules/mitre/index.tsx +++ b/x-pack/plugins/security_solution/public/detections/components/rules/mitre/index.tsx @@ -11,7 +11,7 @@ import React, { memo, useCallback, useMemo } from 'react'; import styled from 'styled-components'; import { isEqual } from 'lodash'; -import { Threat, Threats } from '../../../../../common/detection_engine/schemas/common/schemas'; +import { Threat, Threats } from '@kbn/securitysolution-io-ts-alerting-types'; import { tacticsOptions } from '../../../mitre/mitre_tactics_techniques'; import * as Rulei18n from '../../../pages/detection_engine/rules/translations'; import { FieldHook } from '../../../../shared_imports'; diff --git a/x-pack/plugins/security_solution/public/detections/components/rules/mitre/subtechnique_fields.tsx b/x-pack/plugins/security_solution/public/detections/components/rules/mitre/subtechnique_fields.tsx index d283c19bd13d..7504a5d706f1 100644 --- a/x-pack/plugins/security_solution/public/detections/components/rules/mitre/subtechnique_fields.tsx +++ b/x-pack/plugins/security_solution/public/detections/components/rules/mitre/subtechnique_fields.tsx @@ -17,10 +17,7 @@ import { camelCase } from 'lodash/fp'; import React, { useCallback, useMemo } from 'react'; import styled from 'styled-components'; -import { - Threats, - ThreatSubtechnique, -} from '../../../../../common/detection_engine/schemas/common/schemas'; +import { Threats, ThreatSubtechnique } from '@kbn/securitysolution-io-ts-alerting-types'; import { subtechniquesOptions } from '../../../mitre/mitre_tactics_techniques'; import * as Rulei18n from '../../../pages/detection_engine/rules/translations'; import { FieldHook } from '../../../../shared_imports'; diff --git a/x-pack/plugins/security_solution/public/detections/components/rules/mitre/technique_fields.tsx b/x-pack/plugins/security_solution/public/detections/components/rules/mitre/technique_fields.tsx index 7f698740f5d3..5a0fde1a739a 100644 --- a/x-pack/plugins/security_solution/public/detections/components/rules/mitre/technique_fields.tsx +++ b/x-pack/plugins/security_solution/public/detections/components/rules/mitre/technique_fields.tsx @@ -17,10 +17,7 @@ import { kebabCase, camelCase } from 'lodash/fp'; import React, { useCallback } from 'react'; import styled, { css } from 'styled-components'; -import { - Threats, - ThreatTechnique, -} from '../../../../../common/detection_engine/schemas/common/schemas'; +import { Threats, ThreatTechnique } from '@kbn/securitysolution-io-ts-alerting-types'; import { techniquesOptions } from '../../../mitre/mitre_tactics_techniques'; import * as Rulei18n from '../../../pages/detection_engine/rules/translations'; import { FieldHook } from '../../../../shared_imports'; diff --git a/x-pack/plugins/security_solution/public/detections/components/rules/query_preview/helpers.ts b/x-pack/plugins/security_solution/public/detections/components/rules/query_preview/helpers.ts index bc4888acc90f..1d3135b8cb34 100644 --- a/x-pack/plugins/security_solution/public/detections/components/rules/query_preview/helpers.ts +++ b/x-pack/plugins/security_solution/public/detections/components/rules/query_preview/helpers.ts @@ -9,10 +9,10 @@ import { Position, ScaleType } from '@elastic/charts'; import { EuiSelectOption } from '@elastic/eui'; import { Unit } from '@elastic/datemath'; +import { Type, Language } from '@kbn/securitysolution-io-ts-alerting-types'; import * as i18n from './translations'; import { histogramDateTimeFormatter } from '../../../../common/components/utils'; import { ChartSeriesConfigs } from '../../../../common/components/charts/common'; -import { Type, Language } from '../../../../../common/detection_engine/schemas/common/schemas'; import { getQueryFilter } from '../../../../../common/detection_engine/get_query_filter'; import { FieldValueQueryBar } from '../query_bar'; import { ESQuery } from '../../../../../common/typed_json'; diff --git a/x-pack/plugins/security_solution/public/detections/components/rules/query_preview/index.tsx b/x-pack/plugins/security_solution/public/detections/components/rules/query_preview/index.tsx index 70d292660388..6342d468f596 100644 --- a/x-pack/plugins/security_solution/public/detections/components/rules/query_preview/index.tsx +++ b/x-pack/plugins/security_solution/public/detections/components/rules/query_preview/index.tsx @@ -20,11 +20,11 @@ import { } from '@elastic/eui'; import { debounce } from 'lodash/fp'; +import { Type } from '@kbn/securitysolution-io-ts-alerting-types'; import * as i18n from './translations'; import { useMatrixHistogram } from '../../../../common/containers/matrix_histogram'; import { MatrixHistogramType } from '../../../../../common/search_strategy/security_solution/matrix_histogram'; import { FieldValueQueryBar } from '../query_bar'; -import { Type } from '../../../../../common/detection_engine/schemas/common/schemas'; import { PreviewEqlQueryHistogram } from './eql_histogram'; import { useEqlPreview } from '../../../../common/hooks/eql/'; import { PreviewThresholdQueryHistogram } from './threshold_histogram'; diff --git a/x-pack/plugins/security_solution/public/detections/components/rules/query_preview/reducer.ts b/x-pack/plugins/security_solution/public/detections/components/rules/query_preview/reducer.ts index 2dff858d61c7..afddca63afcc 100644 --- a/x-pack/plugins/security_solution/public/detections/components/rules/query_preview/reducer.ts +++ b/x-pack/plugins/security_solution/public/detections/components/rules/query_preview/reducer.ts @@ -8,10 +8,10 @@ import { Unit } from '@elastic/datemath'; import { EuiSelectOption } from '@elastic/eui'; +import { Type, Language } from '@kbn/securitysolution-io-ts-alerting-types'; import * as i18n from './translations'; import { Filter } from '../../../../../../../../src/plugins/data/common/es_query'; import { ESQuery } from '../../../../../common/typed_json'; -import { Language, Type } from '../../../../../common/detection_engine/schemas/common/schemas'; import { FieldValueQueryBar } from '../query_bar'; import { formatDate } from '../../../../common/components/super_date_picker'; import { getInfoFromQueryBar, getTimeframeOptions } from './helpers'; diff --git a/x-pack/plugins/security_solution/public/detections/components/rules/risk_score_mapping/index.tsx b/x-pack/plugins/security_solution/public/detections/components/rules/risk_score_mapping/index.tsx index 79c54a1cc022..c02f7992a9b9 100644 --- a/x-pack/plugins/security_solution/public/detections/components/rules/risk_score_mapping/index.tsx +++ b/x-pack/plugins/security_solution/public/detections/components/rules/risk_score_mapping/index.tsx @@ -19,13 +19,13 @@ import { import React, { useCallback, useMemo } from 'react'; import styled from 'styled-components'; import { noop } from 'lodash/fp'; +import { RiskScoreMapping } from '@kbn/securitysolution-io-ts-alerting-types'; import * as i18n from './translations'; import { FieldHook } from '../../../../../../../../src/plugins/es_ui_shared/static/forms/hook_form_lib'; import { AboutStepRiskScore } from '../../../pages/detection_engine/rules/types'; import { FieldComponent } from '../../../../common/components/autocomplete/field'; import { IFieldType } from '../../../../../../../../src/plugins/data/common/index_patterns/fields'; import { IIndexPattern } from '../../../../../../../../src/plugins/data/common/index_patterns'; -import { RiskScoreMapping } from '../../../../../common/detection_engine/schemas/common/schemas'; const NestedContent = styled.div` margin-left: 24px; diff --git a/x-pack/plugins/security_solution/public/detections/components/rules/select_rule_type/index.tsx b/x-pack/plugins/security_solution/public/detections/components/rules/select_rule_type/index.tsx index 5650c2c55488..712166df2b53 100644 --- a/x-pack/plugins/security_solution/public/detections/components/rules/select_rule_type/index.tsx +++ b/x-pack/plugins/security_solution/public/detections/components/rules/select_rule_type/index.tsx @@ -8,7 +8,7 @@ import React, { useCallback, useMemo } from 'react'; import { EuiCard, EuiFlexGrid, EuiFlexItem, EuiFormRow, EuiIcon } from '@elastic/eui'; -import { Type } from '../../../../../common/detection_engine/schemas/common/schemas'; +import { Type } from '@kbn/securitysolution-io-ts-alerting-types'; import { isMlRule } from '../../../../../common/machine_learning/helpers'; import { isThresholdRule, diff --git a/x-pack/plugins/security_solution/public/detections/components/rules/severity_mapping/index.tsx b/x-pack/plugins/security_solution/public/detections/components/rules/severity_mapping/index.tsx index d83ad8f4f4d2..8b8c9441e7ea 100644 --- a/x-pack/plugins/security_solution/public/detections/components/rules/severity_mapping/index.tsx +++ b/x-pack/plugins/security_solution/public/detections/components/rules/severity_mapping/index.tsx @@ -19,6 +19,11 @@ import { import { noop } from 'lodash/fp'; import React, { useCallback, useMemo } from 'react'; import styled from 'styled-components'; +import { + Severity, + SeverityMapping, + SeverityMappingItem, +} from '@kbn/securitysolution-io-ts-alerting-types'; import * as i18n from './translations'; import { FieldHook } from '../../../../../../../../src/plugins/es_ui_shared/static/forms/hook_form_lib'; import { SeverityOptionItem } from '../step_about_rule/data'; @@ -29,11 +34,6 @@ import { } from '../../../../../../../../src/plugins/data/common/index_patterns'; import { FieldComponent } from '../../../../common/components/autocomplete/field'; import { AutocompleteFieldMatchComponent } from '../../../../common/components/autocomplete/field_value_match'; -import { - Severity, - SeverityMapping, - SeverityMappingItem, -} from '../../../../../common/detection_engine/schemas/common/schemas'; const NestedContent = styled.div` margin-left: 24px; diff --git a/x-pack/plugins/security_solution/public/detections/components/rules/step_about_rule/data.tsx b/x-pack/plugins/security_solution/public/detections/components/rules/step_about_rule/data.tsx index 8a01d5b072fb..264e499d9cf8 100644 --- a/x-pack/plugins/security_solution/public/detections/components/rules/step_about_rule/data.tsx +++ b/x-pack/plugins/security_solution/public/detections/components/rules/step_about_rule/data.tsx @@ -10,7 +10,7 @@ import { EuiHealth } from '@elastic/eui'; import euiLightVars from '@elastic/eui/dist/eui_theme_light.json'; import React from 'react'; -import { Severity } from '../../../../../common/detection_engine/schemas/common/schemas'; +import { Severity } from '@kbn/securitysolution-io-ts-alerting-types'; import * as I18n from './translations'; export interface SeverityOptionItem { diff --git a/x-pack/plugins/security_solution/public/detections/containers/detection_engine/rules/transforms.ts b/x-pack/plugins/security_solution/public/detections/containers/detection_engine/rules/transforms.ts index 7eb91e259a72..891e7f47c1b7 100644 --- a/x-pack/plugins/security_solution/public/detections/containers/detection_engine/rules/transforms.ts +++ b/x-pack/plugins/security_solution/public/detections/containers/detection_engine/rules/transforms.ts @@ -6,7 +6,7 @@ */ import { flow } from 'fp-ts/lib/function'; -import { addIdToItem, removeIdFromItem } from '../../../../../common/add_remove_id_to_item'; +import { addIdToItem, removeIdFromItem } from '@kbn/securitysolution-utils'; import { CreateRulesSchema, UpdateRulesSchema, diff --git a/x-pack/plugins/security_solution/public/detections/containers/detection_engine/rules/types.ts b/x-pack/plugins/security_solution/public/detections/containers/detection_engine/rules/types.ts index 2c3d6484aebd..338124ad5ce6 100644 --- a/x-pack/plugins/security_solution/public/detections/containers/detection_engine/rules/types.ts +++ b/x-pack/plugins/security_solution/public/detections/containers/detection_engine/rules/types.ts @@ -7,28 +7,28 @@ import * as t from 'io-ts'; +import { listArray } from '@kbn/securitysolution-io-ts-list-types'; import { - SortOrder, - author, - building_block_type, - license, risk_score_mapping, - rule_name_override, - severity_mapping, - timestamp_override, - threshold, - type, - threats, -} from '../../../../../common/detection_engine/schemas/common/schemas'; -import { - listArray, threat_query, threat_index, threat_indicator_path, threat_mapping, threat_language, threat_filters, -} from '../../../../../common/detection_engine/schemas/types'; + threats, + type, + severity_mapping, +} from '@kbn/securitysolution-io-ts-alerting-types'; +import { + SortOrder, + author, + building_block_type, + license, + rule_name_override, + timestamp_override, + threshold, +} from '../../../../../common/detection_engine/schemas/common/schemas'; import { CreateRulesSchema, PatchRulesSchema, @@ -38,6 +38,7 @@ import { /** * Params is an "record", since it is a type of AlertActionParams which is action templates. * @see x-pack/plugins/alerting/common/alert.ts + * @deprecated Use the one from @kbn/security-io-ts-alerting-types */ export const action = t.exact( t.type({ diff --git a/x-pack/plugins/security_solution/public/detections/containers/detection_engine/rules/use_dissasociate_exception_list.tsx b/x-pack/plugins/security_solution/public/detections/containers/detection_engine/rules/use_dissasociate_exception_list.tsx index 1fc6ff607c47..8807f02774e0 100644 --- a/x-pack/plugins/security_solution/public/detections/containers/detection_engine/rules/use_dissasociate_exception_list.tsx +++ b/x-pack/plugins/security_solution/public/detections/containers/detection_engine/rules/use_dissasociate_exception_list.tsx @@ -7,8 +7,8 @@ import { useEffect, useState, useRef } from 'react'; +import { List } from '@kbn/securitysolution-io-ts-list-types'; import { HttpStart } from '../../../../../../../../src/core/public'; -import { List } from '../../../../../common/detection_engine/schemas/types/lists'; import { patchRule } from './api'; type Func = (lists: List[]) => void; diff --git a/x-pack/plugins/security_solution/public/detections/mitre/valid_threat_mock.ts b/x-pack/plugins/security_solution/public/detections/mitre/valid_threat_mock.ts index 70c340096f46..a7de7494e111 100644 --- a/x-pack/plugins/security_solution/public/detections/mitre/valid_threat_mock.ts +++ b/x-pack/plugins/security_solution/public/detections/mitre/valid_threat_mock.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { Threats } from '../../../common/detection_engine/schemas/common/schemas'; +import { Threats } from '@kbn/securitysolution-io-ts-alerting-types'; import { mockThreatData } from './mitre_tactics_techniques'; const { tactic, technique, subtechnique } = mockThreatData; diff --git a/x-pack/plugins/security_solution/public/detections/pages/detection_engine/rules/create/helpers.test.ts b/x-pack/plugins/security_solution/public/detections/pages/detection_engine/rules/create/helpers.test.ts index 98d3dadc7bbc..f018bc148d62 100644 --- a/x-pack/plugins/security_solution/public/detections/pages/detection_engine/rules/create/helpers.test.ts +++ b/x-pack/plugins/security_solution/public/detections/pages/detection_engine/rules/create/helpers.test.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { List } from '../../../../../../common/detection_engine/schemas/types'; +import { List } from '@kbn/securitysolution-io-ts-list-types'; import { CreateRulesSchema } from '../../../../../../common/detection_engine/schemas/request'; import { Rule } from '../../../../containers/detection_engine/rules'; import { @@ -40,7 +40,7 @@ import { mockActionsStepRule, } from '../all/__mocks__/mock'; import { getThreatMock } from '../../../../../../common/detection_engine/schemas/types/threat.mock'; -import { Threat, Threats } from '../../../../../../common/detection_engine/schemas/common/schemas'; +import { Threat, Threats } from '@kbn/securitysolution-io-ts-alerting-types'; describe('helpers', () => { describe('getTimeTypeValue', () => { diff --git a/x-pack/plugins/security_solution/public/detections/pages/detection_engine/rules/create/helpers.ts b/x-pack/plugins/security_solution/public/detections/pages/detection_engine/rules/create/helpers.ts index 29b63721513d..5259b95a09ae 100644 --- a/x-pack/plugins/security_solution/public/detections/pages/detection_engine/rules/create/helpers.ts +++ b/x-pack/plugins/security_solution/public/detections/pages/detection_engine/rules/create/helpers.ts @@ -9,20 +9,22 @@ import { has, isEmpty } from 'lodash/fp'; import moment from 'moment'; import deepmerge from 'deepmerge'; -import type { ExceptionListType, NamespaceType } from '@kbn/securitysolution-io-ts-list-types'; -import { NOTIFICATION_THROTTLE_NO_ACTIONS } from '../../../../../../common/constants'; -import { assertUnreachable } from '../../../../../../common/utility_types'; -import { transformAlertToRuleAction } from '../../../../../../common/detection_engine/transform_actions'; -import { List } from '../../../../../../common/detection_engine/schemas/types'; -import { ENDPOINT_LIST_ID } from '../../../../../shared_imports'; -import { Rule } from '../../../../containers/detection_engine/rules'; +import type { + ExceptionListType, + NamespaceType, + List, +} from '@kbn/securitysolution-io-ts-list-types'; import { Threats, ThreatSubtechnique, ThreatTechnique, Type, -} from '../../../../../../common/detection_engine/schemas/common/schemas'; - +} from '@kbn/securitysolution-io-ts-alerting-types'; +import { NOTIFICATION_THROTTLE_NO_ACTIONS } from '../../../../../../common/constants'; +import { assertUnreachable } from '../../../../../../common/utility_types'; +import { transformAlertToRuleAction } from '../../../../../../common/detection_engine/transform_actions'; +import { ENDPOINT_LIST_ID } from '../../../../../shared_imports'; +import { Rule } from '../../../../containers/detection_engine/rules'; import { AboutStepRule, DefineStepRule, diff --git a/x-pack/plugins/security_solution/public/detections/pages/detection_engine/rules/helpers.tsx b/x-pack/plugins/security_solution/public/detections/pages/detection_engine/rules/helpers.tsx index 03688264bcf4..25785f6bbcb2 100644 --- a/x-pack/plugins/security_solution/public/detections/pages/detection_engine/rules/helpers.tsx +++ b/x-pack/plugins/security_solution/public/detections/pages/detection_engine/rules/helpers.tsx @@ -12,6 +12,12 @@ import { useLocation } from 'react-router-dom'; import styled from 'styled-components'; import { EuiFlexItem } from '@elastic/eui'; +import { + Threats, + Type, + SeverityMapping, + Severity, +} from '@kbn/securitysolution-io-ts-alerting-types'; import { ActionVariables } from '../../../../../../triggers_actions_ui/public'; import { normalizeThresholdField } from '../../../../../common/detection_engine/utils'; import { RuleAlertAction } from '../../../../../common/detection_engine/types'; @@ -27,12 +33,6 @@ import { ScheduleStepRule, ActionsStepRule, } from './types'; -import { - SeverityMapping, - Type, - Severity, - Threats, -} from '../../../../../common/detection_engine/schemas/common/schemas'; import { severityOptions } from '../../../components/rules/step_about_rule/data'; export interface GetStepsData { diff --git a/x-pack/plugins/security_solution/public/detections/pages/detection_engine/rules/types.ts b/x-pack/plugins/security_solution/public/detections/pages/detection_engine/rules/types.ts index 58994c5a5f55..cf82e7cb7944 100644 --- a/x-pack/plugins/security_solution/public/detections/pages/detection_engine/rules/types.ts +++ b/x-pack/plugins/security_solution/public/detections/pages/detection_engine/rules/types.ts @@ -5,6 +5,16 @@ * 2.0. */ +import { List } from '@kbn/securitysolution-io-ts-list-types'; +import { + RiskScoreMapping, + ThreatIndex, + ThreatMapping, + Threats, + Type, + SeverityMapping, + Severity, +} from '@kbn/securitysolution-io-ts-alerting-types'; import { RuleAlertAction } from '../../../../../common/detection_engine/types'; import { AlertAction } from '../../../../../../alerting/common'; import { Filter } from '../../../../../../../../src/plugins/data/common'; @@ -15,20 +25,10 @@ import { Author, BuildingBlockType, License, - RiskScoreMapping, RuleNameOverride, - SeverityMapping, SortOrder, TimestampOverride, - Type, - Severity, - Threats, } from '../../../../../common/detection_engine/schemas/common/schemas'; -import { - List, - ThreatIndex, - ThreatMapping, -} from '../../../../../common/detection_engine/schemas/types'; export interface EuiBasicTableSortTypes { field: string; diff --git a/x-pack/plugins/security_solution/public/lists_plugin_deps.ts b/x-pack/plugins/security_solution/public/lists_plugin_deps.ts deleted file mode 100644 index 498995b53842..000000000000 --- a/x-pack/plugins/security_solution/public/lists_plugin_deps.ts +++ /dev/null @@ -1,10 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -// DEPRECATED: Do not add exports to this file; please import from shared_imports instead - -export * from './shared_imports'; diff --git a/x-pack/plugins/security_solution/public/network/components/port/index.test.tsx b/x-pack/plugins/security_solution/public/network/components/port/index.test.tsx index 9c7a0833b24b..ef1039bfc92e 100644 --- a/x-pack/plugins/security_solution/public/network/components/port/index.test.tsx +++ b/x-pack/plugins/security_solution/public/network/components/port/index.test.tsx @@ -8,7 +8,7 @@ import { shallow } from 'enzyme'; import React from 'react'; -import { removeExternalLinkText } from '../../../../common/test_utils'; +import { removeExternalLinkText } from '@kbn/securitysolution-io-ts-utils'; import '../../../common/mock/match_media'; import { TestProviders } from '../../../common/mock/test_providers'; import { useMountAppended } from '../../../common/utils/use_mount_appended'; diff --git a/x-pack/plugins/security_solution/public/network/components/source_destination/index.test.tsx b/x-pack/plugins/security_solution/public/network/components/source_destination/index.test.tsx index 6be0382e54cd..01065ad5bf15 100644 --- a/x-pack/plugins/security_solution/public/network/components/source_destination/index.test.tsx +++ b/x-pack/plugins/security_solution/public/network/components/source_destination/index.test.tsx @@ -10,7 +10,7 @@ import { shallow } from 'enzyme'; import { get } from 'lodash/fp'; import React from 'react'; -import { removeExternalLinkText } from '../../../../common/test_utils'; +import { removeExternalLinkText } from '@kbn/securitysolution-io-ts-utils'; import { asArrayIfExists } from '../../../common/lib/helpers'; import { getMockNetflowData } from '../../../common/mock'; import '../../../common/mock/match_media'; diff --git a/x-pack/plugins/security_solution/public/network/components/source_destination/source_destination_ip.test.tsx b/x-pack/plugins/security_solution/public/network/components/source_destination/source_destination_ip.test.tsx index a13621cfe3a9..f767e793c8f2 100644 --- a/x-pack/plugins/security_solution/public/network/components/source_destination/source_destination_ip.test.tsx +++ b/x-pack/plugins/security_solution/public/network/components/source_destination/source_destination_ip.test.tsx @@ -8,7 +8,7 @@ import { get } from 'lodash/fp'; import React from 'react'; -import { removeExternalLinkText } from '../../../../common/test_utils'; +import { removeExternalLinkText } from '@kbn/securitysolution-io-ts-utils'; import { asArrayIfExists } from '../../../common/lib/helpers'; import { getMockNetflowData } from '../../../common/mock'; import '../../../common/mock/match_media'; diff --git a/x-pack/plugins/security_solution/public/timelines/components/certificate_fingerprint/index.test.tsx b/x-pack/plugins/security_solution/public/timelines/components/certificate_fingerprint/index.test.tsx index 63e27bd8fa9c..7a38c873450c 100644 --- a/x-pack/plugins/security_solution/public/timelines/components/certificate_fingerprint/index.test.tsx +++ b/x-pack/plugins/security_solution/public/timelines/components/certificate_fingerprint/index.test.tsx @@ -7,7 +7,7 @@ import React from 'react'; -import { removeExternalLinkText } from '../../../../common/test_utils'; +import { removeExternalLinkText } from '@kbn/securitysolution-io-ts-utils'; import { TestProviders } from '../../../common/mock'; import '../../../common/mock/match_media'; import { useMountAppended } from '../../../common/utils/use_mount_appended'; diff --git a/x-pack/plugins/security_solution/public/timelines/components/ja3_fingerprint/index.test.tsx b/x-pack/plugins/security_solution/public/timelines/components/ja3_fingerprint/index.test.tsx index bb2061f74428..802dd74c1892 100644 --- a/x-pack/plugins/security_solution/public/timelines/components/ja3_fingerprint/index.test.tsx +++ b/x-pack/plugins/security_solution/public/timelines/components/ja3_fingerprint/index.test.tsx @@ -7,7 +7,7 @@ import React from 'react'; -import { removeExternalLinkText } from '../../../../common/test_utils'; +import { removeExternalLinkText } from '@kbn/securitysolution-io-ts-utils'; import { TestProviders } from '../../../common/mock'; import '../../../common/mock/match_media'; import { useMountAppended } from '../../../common/utils/use_mount_appended'; diff --git a/x-pack/plugins/security_solution/public/timelines/components/netflow/index.test.tsx b/x-pack/plugins/security_solution/public/timelines/components/netflow/index.test.tsx index 5e6d804b01fd..e2c8b8854504 100644 --- a/x-pack/plugins/security_solution/public/timelines/components/netflow/index.test.tsx +++ b/x-pack/plugins/security_solution/public/timelines/components/netflow/index.test.tsx @@ -9,7 +9,7 @@ import { get } from 'lodash/fp'; import React from 'react'; import { shallow } from 'enzyme'; -import { removeExternalLinkText } from '../../../../common/test_utils'; +import { removeExternalLinkText } from '@kbn/securitysolution-io-ts-utils'; import { asArrayIfExists } from '../../../common/lib/helpers'; import { getMockNetflowData } from '../../../common/mock'; import '../../../common/mock/match_media'; diff --git a/x-pack/plugins/security_solution/public/timelines/components/timeline/body/renderers/get_row_renderer.test.tsx b/x-pack/plugins/security_solution/public/timelines/components/timeline/body/renderers/get_row_renderer.test.tsx index b92a4381d837..56dbc99d47c6 100644 --- a/x-pack/plugins/security_solution/public/timelines/components/timeline/body/renderers/get_row_renderer.test.tsx +++ b/x-pack/plugins/security_solution/public/timelines/components/timeline/body/renderers/get_row_renderer.test.tsx @@ -9,7 +9,7 @@ import { shallow } from 'enzyme'; import { cloneDeep } from 'lodash'; import React from 'react'; -import { removeExternalLinkText } from '../../../../../../common/test_utils'; +import { removeExternalLinkText } from '@kbn/securitysolution-io-ts-utils'; import '../../../../../common/mock/match_media'; import { mockBrowserFields } from '../../../../../common/containers/source/mock'; import { Ecs } from '../../../../../../common/ecs'; diff --git a/x-pack/plugins/security_solution/public/timelines/components/timeline/body/renderers/suricata/suricata_details.test.tsx b/x-pack/plugins/security_solution/public/timelines/components/timeline/body/renderers/suricata/suricata_details.test.tsx index bd8c2d10ccfa..5960f43174b9 100644 --- a/x-pack/plugins/security_solution/public/timelines/components/timeline/body/renderers/suricata/suricata_details.test.tsx +++ b/x-pack/plugins/security_solution/public/timelines/components/timeline/body/renderers/suricata/suricata_details.test.tsx @@ -8,7 +8,7 @@ import { shallow } from 'enzyme'; import React from 'react'; -import { removeExternalLinkText } from '../../../../../../../common/test_utils'; +import { removeExternalLinkText } from '@kbn/securitysolution-io-ts-utils'; import { mockBrowserFields } from '../../../../../../common/containers/source/mock'; import { mockTimelineData } from '../../../../../../common/mock'; import '../../../../../../common/mock/match_media'; diff --git a/x-pack/plugins/security_solution/public/timelines/components/timeline/body/renderers/suricata/suricata_row_renderer.test.tsx b/x-pack/plugins/security_solution/public/timelines/components/timeline/body/renderers/suricata/suricata_row_renderer.test.tsx index 469c8f6c3ec4..098d6775cfaa 100644 --- a/x-pack/plugins/security_solution/public/timelines/components/timeline/body/renderers/suricata/suricata_row_renderer.test.tsx +++ b/x-pack/plugins/security_solution/public/timelines/components/timeline/body/renderers/suricata/suricata_row_renderer.test.tsx @@ -9,7 +9,7 @@ import { shallow } from 'enzyme'; import { cloneDeep } from 'lodash/fp'; import React from 'react'; -import { removeExternalLinkText } from '../../../../../../../common/test_utils'; +import { removeExternalLinkText } from '@kbn/securitysolution-io-ts-utils'; import { mockBrowserFields } from '../../../../../../common/containers/source/mock'; import { Ecs } from '../../../../../../../common/ecs'; import { mockTimelineData } from '../../../../../../common/mock'; diff --git a/x-pack/plugins/security_solution/public/timelines/components/timeline/body/renderers/system/generic_row_renderer.test.tsx b/x-pack/plugins/security_solution/public/timelines/components/timeline/body/renderers/system/generic_row_renderer.test.tsx index b7857e6bf458..8e8ce9cb2f98 100644 --- a/x-pack/plugins/security_solution/public/timelines/components/timeline/body/renderers/system/generic_row_renderer.test.tsx +++ b/x-pack/plugins/security_solution/public/timelines/components/timeline/body/renderers/system/generic_row_renderer.test.tsx @@ -9,7 +9,7 @@ import { shallow } from 'enzyme'; import { cloneDeep } from 'lodash/fp'; import React from 'react'; -import { removeExternalLinkText } from '../../../../../../../common/test_utils'; +import { removeExternalLinkText } from '@kbn/securitysolution-io-ts-utils'; import { BrowserFields } from '../../../../../../common/containers/source'; import { mockBrowserFields } from '../../../../../../common/containers/source/mock'; import { Ecs } from '../../../../../../../common/ecs'; diff --git a/x-pack/plugins/security_solution/public/timelines/components/timeline/body/renderers/zeek/zeek_details.test.tsx b/x-pack/plugins/security_solution/public/timelines/components/timeline/body/renderers/zeek/zeek_details.test.tsx index 0f27dccd1aff..04150163fb4d 100644 --- a/x-pack/plugins/security_solution/public/timelines/components/timeline/body/renderers/zeek/zeek_details.test.tsx +++ b/x-pack/plugins/security_solution/public/timelines/components/timeline/body/renderers/zeek/zeek_details.test.tsx @@ -7,7 +7,7 @@ import React from 'react'; -import { removeExternalLinkText } from '../../../../../../../common/test_utils'; +import { removeExternalLinkText } from '@kbn/securitysolution-io-ts-utils'; import '../../../../../../common/mock/match_media'; import { mockBrowserFields } from '../../../../../../common/containers/source/mock'; import { mockTimelineData, TestProviders } from '../../../../../../common/mock'; diff --git a/x-pack/plugins/security_solution/public/timelines/components/timeline/body/renderers/zeek/zeek_row_renderer.test.tsx b/x-pack/plugins/security_solution/public/timelines/components/timeline/body/renderers/zeek/zeek_row_renderer.test.tsx index 2d20da0c5e6d..749e450b36ae 100644 --- a/x-pack/plugins/security_solution/public/timelines/components/timeline/body/renderers/zeek/zeek_row_renderer.test.tsx +++ b/x-pack/plugins/security_solution/public/timelines/components/timeline/body/renderers/zeek/zeek_row_renderer.test.tsx @@ -9,7 +9,7 @@ import { shallow } from 'enzyme'; import { cloneDeep } from 'lodash/fp'; import React from 'react'; -import { removeExternalLinkText } from '../../../../../../../common/test_utils'; +import { removeExternalLinkText } from '@kbn/securitysolution-io-ts-utils'; import { mockBrowserFields } from '../../../../../../common/containers/source/mock'; import { Ecs } from '../../../../../../../common/ecs'; import { mockTimelineData, TestProviders } from '../../../../../../common/mock'; diff --git a/x-pack/plugins/security_solution/public/timelines/components/timeline/body/renderers/zeek/zeek_signature.test.tsx b/x-pack/plugins/security_solution/public/timelines/components/timeline/body/renderers/zeek/zeek_signature.test.tsx index 4fc2f90c87da..61155331b1a4 100644 --- a/x-pack/plugins/security_solution/public/timelines/components/timeline/body/renderers/zeek/zeek_signature.test.tsx +++ b/x-pack/plugins/security_solution/public/timelines/components/timeline/body/renderers/zeek/zeek_signature.test.tsx @@ -9,7 +9,7 @@ import { shallow } from 'enzyme'; import { cloneDeep } from 'lodash/fp'; import React from 'react'; -import { removeExternalLinkText } from '../../../../../../../common/test_utils'; +import { removeExternalLinkText } from '@kbn/securitysolution-io-ts-utils'; import '../../../../../../common/mock/match_media'; import { Ecs } from '../../../../../../../common/ecs'; import { mockTimelineData, TestProviders } from '../../../../../../common/mock'; diff --git a/x-pack/plugins/security_solution/server/endpoint/lib/artifacts/lists.ts b/x-pack/plugins/security_solution/server/endpoint/lib/artifacts/lists.ts index f3bc195b5a89..e73e3eb5c56f 100644 --- a/x-pack/plugins/security_solution/server/endpoint/lib/artifacts/lists.ts +++ b/x-pack/plugins/security_solution/server/endpoint/lib/artifacts/lists.ts @@ -8,8 +8,8 @@ import { createHash } from 'crypto'; import { deflate } from 'zlib'; import { Entry, EntryNested } from '@kbn/securitysolution-io-ts-list-types'; +import { validate } from '@kbn/securitysolution-io-ts-utils'; import { ExceptionListItemSchema } from '../../../../../lists/common/schemas'; -import { validate } from '../../../../common/validate'; import { ExceptionListClient } from '../../../../../lists/server'; import { ENDPOINT_LIST_ID, ENDPOINT_TRUSTED_APPS_LIST_ID } from '../../../../common/shared_imports'; diff --git a/x-pack/plugins/security_solution/server/endpoint/lib/artifacts/manifest.ts b/x-pack/plugins/security_solution/server/endpoint/lib/artifacts/manifest.ts index 7e1accac37cf..43d4fc49161b 100644 --- a/x-pack/plugins/security_solution/server/endpoint/lib/artifacts/manifest.ts +++ b/x-pack/plugins/security_solution/server/endpoint/lib/artifacts/manifest.ts @@ -7,7 +7,7 @@ import { flatMap, isEqual } from 'lodash'; import semver from 'semver'; -import { validate } from '../../../../common'; +import { validate } from '@kbn/securitysolution-io-ts-utils'; import { InternalArtifactSchema, InternalManifestSchema, diff --git a/x-pack/plugins/security_solution/server/endpoint/routes/trusted_apps/mapping.ts b/x-pack/plugins/security_solution/server/endpoint/routes/trusted_apps/mapping.ts index e4704523a16c..897ffe4ee48c 100644 --- a/x-pack/plugins/security_solution/server/endpoint/routes/trusted_apps/mapping.ts +++ b/x-pack/plugins/security_solution/server/endpoint/routes/trusted_apps/mapping.ts @@ -13,11 +13,11 @@ import type { EntryMatchWildcard, EntryNested, NestedEntriesArray, + OsType, } from '@kbn/securitysolution-io-ts-list-types'; import type { ExceptionListItemSchema } from '../../../../../lists/common'; -import type { OsType } from '../../../../../lists/common/schemas'; import { ENDPOINT_TRUSTED_APPS_LIST_ID } from '../../../../../lists/common/constants'; import type { CreateExceptionListItemOptions, diff --git a/x-pack/plugins/security_solution/server/endpoint/schemas/artifacts/lists.ts b/x-pack/plugins/security_solution/server/endpoint/schemas/artifacts/lists.ts index 1b1370472f63..3a37bfbe9320 100644 --- a/x-pack/plugins/security_solution/server/endpoint/schemas/artifacts/lists.ts +++ b/x-pack/plugins/security_solution/server/endpoint/schemas/artifacts/lists.ts @@ -6,7 +6,7 @@ */ import * as t from 'io-ts'; -import { operator } from '../../../../../lists/common/schemas'; +import { listOperator as operator } from '@kbn/securitysolution-io-ts-list-types'; export const translatedEntryMatchAnyMatcher = t.keyof({ exact_cased_any: null, diff --git a/x-pack/plugins/security_solution/server/endpoint/services/artifacts/manifest_client.ts b/x-pack/plugins/security_solution/server/endpoint/services/artifacts/manifest_client.ts index e2f6118f4f0a..d7b05ffa5592 100644 --- a/x-pack/plugins/security_solution/server/endpoint/services/artifacts/manifest_client.ts +++ b/x-pack/plugins/security_solution/server/endpoint/services/artifacts/manifest_client.ts @@ -10,11 +10,11 @@ import { SavedObjectsClientContract, SavedObjectsUpdateResponse, } from 'src/core/server'; +import { validate } from '@kbn/securitysolution-io-ts-utils'; import { manifestSchemaVersion, ManifestSchemaVersion, } from '../../../../common/endpoint/schema/common'; -import { validate } from '../../../../common/validate'; import { ManifestConstants } from '../../lib/artifacts'; import { InternalManifestSchema, InternalManifestCreateSchema } from '../../schemas/artifacts'; diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/errors/bad_request_error.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/errors/bad_request_error.ts deleted file mode 100644 index c68e7845953f..000000000000 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/errors/bad_request_error.ts +++ /dev/null @@ -1,8 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -export class BadRequestError extends Error {} diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/index/create_bootstrap_index.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/index/create_bootstrap_index.ts deleted file mode 100644 index 02f8f3f7b36a..000000000000 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/index/create_bootstrap_index.ts +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { ElasticsearchClient } from 'kibana/server'; - -// See the reference(s) below on explanations about why -000001 was chosen and -// why the is_write_index is true as well as the bootstrapping step which is needed. -// Ref: https://www.elastic.co/guide/en/elasticsearch/reference/current/applying-policy-to-template.html - -/** - * @deprecated Use the one from kbn-securitysolution-es-utils - */ -export const createBootstrapIndex = async ( - esClient: ElasticsearchClient, - index: string -): Promise => { - return ( - await esClient.transport.request({ - path: `/${index}-000001`, - method: 'PUT', - body: { - aliases: { - [index]: { - is_write_index: true, - }, - }, - }, - }) - ).body; -}; diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/index/delete_all_index.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/index/delete_all_index.ts deleted file mode 100644 index d76290921fac..000000000000 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/index/delete_all_index.ts +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { ElasticsearchClient } from 'kibana/server'; - -/** - * @deprecated Use the one from kbn-securitysolution-es-utils - */ -export const deleteAllIndex = async ( - esClient: ElasticsearchClient, - pattern: string, - maxAttempts = 5 -): Promise => { - for (let attempt = 1; ; attempt++) { - if (attempt > maxAttempts) { - throw new Error( - `Failed to delete indexes with pattern [${pattern}] after ${maxAttempts} attempts` - ); - } - - // resolve pattern to concrete index names - const { body: resp } = await esClient.indices.getAlias( - { - index: pattern, - }, - { ignore: [404] } - ); - - // @ts-expect-error status doesn't exist on response - if (resp.status === 404) { - return true; - } - - const indices = Object.keys(resp) as string[]; - - // if no indexes exits then we're done with this pattern - if (!indices.length) { - return true; - } - - // delete the concrete indexes we found and try again until this pattern resolves to no indexes - await esClient.indices.delete({ - index: indices, - ignore_unavailable: true, - }); - } -}; diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/index/delete_policy.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/index/delete_policy.ts deleted file mode 100644 index 924970d304c8..000000000000 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/index/delete_policy.ts +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { ElasticsearchClient } from 'kibana/server'; - -/** - * @deprecated Use the one from kbn-securitysolution-es-utils - */ -export const deletePolicy = async ( - esClient: ElasticsearchClient, - policy: string -): Promise => { - return ( - await esClient.transport.request({ - path: `/_ilm/policy/${policy}`, - method: 'DELETE', - }) - ).body; -}; diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/index/delete_template.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/index/delete_template.ts deleted file mode 100644 index 5466fd03f534..000000000000 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/index/delete_template.ts +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ -import { ElasticsearchClient } from 'kibana/server'; - -/** - * @deprecated Use the one from kbn-securitysolution-es-utils - */ -export const deleteTemplate = async ( - esClient: ElasticsearchClient, - name: string -): Promise => { - return ( - await esClient.indices.deleteTemplate({ - name, - }) - ).body; -}; diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/index/get_index_exists.test.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/index/get_index_exists.test.ts deleted file mode 100644 index abe587ec825c..000000000000 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/index/get_index_exists.test.ts +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -// eslint-disable-next-line @kbn/eslint/no-restricted-paths -import { elasticsearchClientMock } from 'src/core/server/elasticsearch/client/mocks'; -import { getIndexExists } from './get_index_exists'; - -class StatusCode extends Error { - status: number = -1; - constructor(status: number, message: string) { - super(message); - this.status = status; - } -} - -describe('get_index_exists', () => { - test('it should return a true if you have _shards', async () => { - const esClient = elasticsearchClientMock.createScopedClusterClient().asCurrentUser; - esClient.search.mockReturnValue( - // @ts-expect-error not full interface - elasticsearchClientMock.createSuccessTransportRequestPromise({ _shards: { total: 1 } }) - ); - const indexExists = await getIndexExists(esClient, 'some-index'); - expect(indexExists).toEqual(true); - }); - - test('it should return a false if you do NOT have _shards', async () => { - const esClient = elasticsearchClientMock.createScopedClusterClient().asCurrentUser; - esClient.search.mockReturnValue( - // @ts-expect-error not full interface - elasticsearchClientMock.createSuccessTransportRequestPromise({ _shards: { total: 0 } }) - ); - const indexExists = await getIndexExists(esClient, 'some-index'); - expect(indexExists).toEqual(false); - }); - - test('it should return a false if it encounters a 404', async () => { - const esClient = elasticsearchClientMock.createScopedClusterClient().asCurrentUser; - esClient.search.mockReturnValue( - elasticsearchClientMock.createErrorTransportRequestPromise({ - body: new StatusCode(404, 'I am a 404 error'), - }) - ); - const indexExists = await getIndexExists(esClient, 'some-index'); - expect(indexExists).toEqual(false); - }); - - test('it should reject if it encounters a non 404', async () => { - const esClient = elasticsearchClientMock.createScopedClusterClient().asCurrentUser; - esClient.search.mockReturnValue( - elasticsearchClientMock.createErrorTransportRequestPromise( - new StatusCode(500, 'I am a 500 error') - ) - ); - await expect(getIndexExists(esClient, 'some-index')).rejects.toThrow('I am a 500 error'); - }); -}); diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/index/get_index_exists.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/index/get_index_exists.ts deleted file mode 100644 index 7ca7f9818ba0..000000000000 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/index/get_index_exists.ts +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { ElasticsearchClient } from 'kibana/server'; - -/** - * @deprecated Use the one from kbn-securitysolution-es-utils - */ -export const getIndexExists = async ( - esClient: ElasticsearchClient, - index: string -): Promise => { - try { - const { body: response } = await esClient.search({ - index, - size: 0, - allow_no_indices: true, - body: { - terminate_after: 1, - }, - }); - return response._shards.total > 0; - } catch (err) { - if (err.body?.status === 404) { - return false; - } else { - throw err.body ? err.body : err; - } - } -}; diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/index/get_policy_exists.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/index/get_policy_exists.ts deleted file mode 100644 index 6ebdac0d244c..000000000000 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/index/get_policy_exists.ts +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { ElasticsearchClient } from 'kibana/server'; - -/** - * @deprecated Use the one from kbn-securitysolution-es-utils - */ -export const getPolicyExists = async ( - esClient: ElasticsearchClient, - policy: string -): Promise => { - try { - await esClient.transport.request({ - path: `/_ilm/policy/${policy}`, - method: 'GET', - }); - // Return true that there exists a policy which is not 404 or some error - // Since there is not a policy exists API, this is how we create one by calling - // into the API to get it if it exists or rely on it to throw a 404 - return true; - } catch (err) { - if (err.statusCode === 404) { - return false; - } else { - throw err; - } - } -}; diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/index/get_template_exists.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/index/get_template_exists.ts deleted file mode 100644 index af5f874a0568..000000000000 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/index/get_template_exists.ts +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { ElasticsearchClient } from 'kibana/server'; - -/** - * @deprecated Use the one from kbn-securitysolution-es-utils - */ -export const getTemplateExists = async ( - esClient: ElasticsearchClient, - template: string -): Promise => { - return ( - await esClient.indices.existsTemplate({ - name: template, - }) - ).body; -}; diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/index/set_policy.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/index/set_policy.ts deleted file mode 100644 index 113b9d368e0d..000000000000 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/index/set_policy.ts +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { ElasticsearchClient } from 'kibana/server'; - -/** - * @deprecated Use the one from kbn-securitysolution-es-utils - */ -export const setPolicy = async ( - esClient: ElasticsearchClient, - policy: string, - body: Record -): Promise => { - return ( - await esClient.transport.request({ - path: `/_ilm/policy/${policy}`, - method: 'PUT', - body, - }) - ).body; -}; diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/index/set_template.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/index/set_template.ts deleted file mode 100644 index 288377c30632..000000000000 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/index/set_template.ts +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { ElasticsearchClient } from 'kibana/server'; - -/** - * @deprecated Use the one from kbn-securitysolution-es-utils - */ -export const setTemplate = async ( - esClient: ElasticsearchClient, - name: string, - body: Record -): Promise => { - return ( - await esClient.indices.putTemplate({ - name, - body, - }) - ).body; -}; diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/migrations/create_migration_saved_object.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/migrations/create_migration_saved_object.ts index 9c1154f19e8d..3aee9db31bf1 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/migrations/create_migration_saved_object.ts +++ b/x-pack/plugins/security_solution/server/lib/detection_engine/migrations/create_migration_saved_object.ts @@ -9,7 +9,7 @@ import { chain, tryCatch } from 'fp-ts/lib/TaskEither'; import { pipe } from 'fp-ts/lib/pipeable'; import { SavedObjectsClientContract } from 'src/core/server'; -import { validateTaskEither } from '../../../../common/validate'; +import { validateTaskEither } from '@kbn/securitysolution-io-ts-utils'; import { toError, toPromise } from '../../../../common/fp_utils'; import { signalsMigrationSOClient } from './saved_objects_client'; import { diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/migrations/finalize_migration.test.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/migrations/finalize_migration.test.ts index bdc22f2ff20c..46de2eb133ba 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/migrations/finalize_migration.test.ts +++ b/x-pack/plugins/security_solution/server/lib/detection_engine/migrations/finalize_migration.test.ts @@ -6,13 +6,13 @@ */ import { elasticsearchServiceMock, savedObjectsClientMock } from 'src/core/server/mocks'; -import { getIndexCount } from '../index/get_index_count'; +import { getIndexCount } from '@kbn/securitysolution-es-utils'; import { updateMigrationSavedObject } from './update_migration_saved_object'; import { getSignalsMigrationSavedObjectMock } from './saved_objects_schema.mock'; import { finalizeMigration } from './finalize_migration'; jest.mock('./update_migration_saved_object'); -jest.mock('../index/get_index_count'); +jest.mock('@kbn/securitysolution-es-utils'); describe('finalizeMigration', () => { let esClient: ReturnType; diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/migrations/finalize_migration.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/migrations/finalize_migration.ts index 7a52470e5805..ca8ae01ee2d1 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/migrations/finalize_migration.ts +++ b/x-pack/plugins/security_solution/server/lib/detection_engine/migrations/finalize_migration.ts @@ -6,7 +6,7 @@ */ import { ElasticsearchClient, SavedObjectsClientContract } from 'src/core/server'; -import { getIndexCount } from '../index/get_index_count'; +import { getIndexCount } from '@kbn/securitysolution-es-utils'; import { isMigrationPending } from './helpers'; import { applyMigrationCleanupPolicy } from './migration_cleanup'; import { replaceSignalsIndexAlias } from './replace_signals_index_alias'; diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/migrations/find_migration_saved_objects.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/migrations/find_migration_saved_objects.ts index 2a3e25ee57aa..2cc73c36500f 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/migrations/find_migration_saved_objects.ts +++ b/x-pack/plugins/security_solution/server/lib/detection_engine/migrations/find_migration_saved_objects.ts @@ -9,9 +9,9 @@ import { fold } from 'fp-ts/lib/Either'; import { pipe } from 'fp-ts/lib/pipeable'; import { SavedObjectsClientContract, SavedObjectsFindOptions } from 'src/core/server'; +import { validateEither } from '@kbn/securitysolution-io-ts-utils'; import { signalsMigrationSOClient } from './saved_objects_client'; import { SignalsMigrationSO, signalsMigrationSOs } from './saved_objects_schema'; -import { validateEither } from '../../../../common/validate'; export const findMigrationSavedObjects = async ({ options, diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/migrations/get_migration_saved_objects_by_id.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/migrations/get_migration_saved_objects_by_id.ts index 7d66dca2ef19..66bbc01ef0d6 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/migrations/get_migration_saved_objects_by_id.ts +++ b/x-pack/plugins/security_solution/server/lib/detection_engine/migrations/get_migration_saved_objects_by_id.ts @@ -9,7 +9,7 @@ import { fold } from 'fp-ts/lib/Either'; import { pipe } from 'fp-ts/lib/pipeable'; import { SavedObjectsClientContract } from 'src/core/server'; -import { validateEither } from '../../../../common/validate'; +import { validateEither } from '@kbn/securitysolution-io-ts-utils'; import { signalsMigrationSOClient } from './saved_objects_client'; import { SignalsMigrationSO, signalsMigrationSOs } from './saved_objects_schema'; diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/migrations/saved_objects_schema.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/migrations/saved_objects_schema.ts index 3ce798ec5a5c..e81583b825e3 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/migrations/saved_objects_schema.ts +++ b/x-pack/plugins/security_solution/server/lib/detection_engine/migrations/saved_objects_schema.ts @@ -7,7 +7,7 @@ import * as t from 'io-ts'; -import { IsoDateString, PositiveInteger } from '../../../../common/detection_engine/schemas/types'; +import { IsoDateString, PositiveInteger } from '@kbn/securitysolution-io-ts-types'; import { unionWithNullType } from '../../../../common/utility_types'; const status = t.keyof({ success: null, failure: null, pending: null }); diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/migrations/update_migration_saved_object.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/migrations/update_migration_saved_object.ts index 05d7d3e50dca..5bd8b47c3b74 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/migrations/update_migration_saved_object.ts +++ b/x-pack/plugins/security_solution/server/lib/detection_engine/migrations/update_migration_saved_object.ts @@ -9,7 +9,7 @@ import { chain, tryCatch } from 'fp-ts/lib/TaskEither'; import { pipe } from 'fp-ts/lib/pipeable'; import { SavedObjectsClientContract, SavedObjectsUpdateResponse } from 'src/core/server'; -import { validateTaskEither } from '../../../../common/validate'; +import { validateTaskEither } from '@kbn/securitysolution-io-ts-utils'; import { toError, toPromise } from '../../../../common/fp_utils'; import { signalsMigrationSOClient } from './saved_objects_client'; import { diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/index/create_index_route.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/index/create_index_route.ts index cd1b77862af0..d98cd7cea0f2 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/index/create_index_route.ts +++ b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/index/create_index_route.ts @@ -5,19 +5,22 @@ * 2.0. */ +import { + transformError, + getIndexExists, + getPolicyExists, + setPolicy, + setTemplate, + createBootstrapIndex, +} from '@kbn/securitysolution-es-utils'; import type { AppClient, SecuritySolutionPluginRouter, SecuritySolutionRequestHandlerContext, } from '../../../../types'; import { DETECTION_ENGINE_INDEX_URL } from '../../../../../common/constants'; -import { transformError, buildSiemResponse } from '../utils'; -import { getIndexExists } from '../../index/get_index_exists'; -import { getPolicyExists } from '../../index/get_policy_exists'; -import { setPolicy } from '../../index/set_policy'; -import { setTemplate } from '../../index/set_template'; +import { buildSiemResponse } from '../utils'; import { getSignalsTemplate, SIGNALS_TEMPLATE_VERSION } from './get_signals_template'; -import { createBootstrapIndex } from '../../index/create_bootstrap_index'; import { ensureMigrationCleanupPolicy } from '../../migrations/migration_cleanup'; import signalsPolicy from './signals_policy.json'; import { templateNeedsUpdate } from './check_template_version'; diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/index/delete_index_route.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/index/delete_index_route.ts index 1a4f00a57042..5260c9487de8 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/index/delete_index_route.ts +++ b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/index/delete_index_route.ts @@ -5,15 +5,18 @@ * 2.0. */ +import { + transformError, + getIndexExists, + getPolicyExists, + deletePolicy, + getTemplateExists, + deleteAllIndex, + deleteTemplate, +} from '@kbn/securitysolution-es-utils'; import type { SecuritySolutionPluginRouter } from '../../../../types'; import { DETECTION_ENGINE_INDEX_URL } from '../../../../../common/constants'; -import { transformError, buildSiemResponse } from '../utils'; -import { getIndexExists } from '../../index/get_index_exists'; -import { getPolicyExists } from '../../index/get_policy_exists'; -import { deletePolicy } from '../../index/delete_policy'; -import { getTemplateExists } from '../../index/get_template_exists'; -import { deleteAllIndex } from '../../index/delete_all_index'; -import { deleteTemplate } from '../../index/delete_template'; +import { buildSiemResponse } from '../utils'; /** * Deletes all of the indexes, template, ilm policies, and aliases. You can check diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/index/get_index_version.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/index/get_index_version.ts index b333ef999a6a..b6f711fc319f 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/index/get_index_version.ts +++ b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/index/get_index_version.ts @@ -6,8 +6,8 @@ */ import { get } from 'lodash'; +import { readIndex } from '@kbn/securitysolution-es-utils'; import { ElasticsearchClient } from '../../../../../../../../src/core/server'; -import { readIndex } from '../../index/read_index'; export const getIndexVersion = async ( esClient: ElasticsearchClient, diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/index/read_index_route.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/index/read_index_route.ts index 01d07f68aa48..6af4397a4193 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/index/read_index_route.ts +++ b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/index/read_index_route.ts @@ -5,10 +5,11 @@ * 2.0. */ +import { transformError, getIndexExists } from '@kbn/securitysolution-es-utils'; import type { SecuritySolutionPluginRouter } from '../../../../types'; import { DETECTION_ENGINE_INDEX_URL } from '../../../../../common/constants'; -import { transformError, buildSiemResponse } from '../utils'; -import { getIndexExists } from '../../index/get_index_exists'; + +import { buildSiemResponse } from '../utils'; import { SIGNALS_TEMPLATE_VERSION } from './get_signals_template'; import { getIndexVersion } from './get_index_version'; import { isOutdated } from '../../migrations/helpers'; diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/privileges/read_privileges_route.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/privileges/read_privileges_route.ts index f006d9250d36..04fd2aeaebb2 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/privileges/read_privileges_route.ts +++ b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/privileges/read_privileges_route.ts @@ -7,9 +7,11 @@ import { merge } from 'lodash/fp'; +import { transformError } from '@kbn/securitysolution-es-utils'; import type { SecuritySolutionPluginRouter } from '../../../../types'; import { DETECTION_ENGINE_PRIVILEGES_URL } from '../../../../../common/constants'; -import { buildSiemResponse, transformError } from '../utils'; +import { buildSiemResponse } from '../utils'; + import { readPrivileges } from '../../privileges/read_privileges'; export const readPrivilegesRoute = ( diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/add_prepackaged_rules_route.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/add_prepackaged_rules_route.ts index 4f9bd7d0cfd6..03d357ab10bb 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/add_prepackaged_rules_route.ts +++ b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/add_prepackaged_rules_route.ts @@ -6,13 +6,14 @@ */ import moment from 'moment'; +import { transformError, getIndexExists } from '@kbn/securitysolution-es-utils'; +import { validate } from '@kbn/securitysolution-io-ts-utils'; import type { AppClient, SecuritySolutionPluginRouter, SecuritySolutionRequestHandlerContext, } from '../../../../types'; -import { validate } from '../../../../../common/validate'; import { PrePackagedRulesAndTimelinesSchema, prePackagedRulesAndTimelinesSchema, @@ -24,7 +25,6 @@ import { ConfigType } from '../../../../config'; import { SetupPlugins } from '../../../../plugin'; import { buildFrameworkRequest } from '../../../timeline/utils/common'; -import { getIndexExists } from '../../index/get_index_exists'; import { getLatestPrepackagedRules } from '../../rules/get_prepackaged_rules'; import { installPrepackagedRules } from '../../rules/install_prepacked_rules'; import { updatePrepackagedRules } from '../../rules/update_prepacked_rules'; @@ -33,7 +33,7 @@ import { getRulesToUpdate } from '../../rules/get_rules_to_update'; import { getExistingPrepackagedRules } from '../../rules/get_existing_prepackaged_rules'; import { ruleAssetSavedObjectsClientFactory } from '../../rules/rule_asset_saved_objects_client'; -import { transformError, buildSiemResponse } from '../utils'; +import { buildSiemResponse } from '../utils'; import { AlertsClient } from '../../../../../../alerting/server'; import { FrameworkRequest } from '../../../framework'; diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/create_rules_bulk_route.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/create_rules_bulk_route.ts index cd0e1883e78f..500c74e47ea7 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/create_rules_bulk_route.ts +++ b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/create_rules_bulk_route.ts @@ -5,7 +5,8 @@ * 2.0. */ -import { validate } from '../../../../../common/validate'; +import { validate } from '@kbn/securitysolution-io-ts-utils'; +import { getIndexExists } from '@kbn/securitysolution-es-utils'; import { createRuleValidateTypeDependents } from '../../../../../common/detection_engine/schemas/request/create_rules_type_dependents'; import { createRulesBulkSchema } from '../../../../../common/detection_engine/schemas/request/create_rules_bulk_schema'; import { rulesBulkSchema } from '../../../../../common/detection_engine/schemas/response/rules_bulk_schema'; @@ -17,7 +18,6 @@ import { throwHttpError } from '../../../machine_learning/validation'; import { readRules } from '../../rules/read_rules'; import { getDuplicates } from './utils'; import { transformValidateBulkError } from './validate'; -import { getIndexExists } from '../../index/get_index_exists'; import { buildRouteValidation } from '../../../../utils/build_validation/route_validation'; import { transformBulkError, createBulkErrorObject, buildSiemResponse } from '../utils'; diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/create_rules_route.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/create_rules_route.ts index 1e34bbbbe474..9b7e7bb42f42 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/create_rules_route.ts +++ b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/create_rules_route.ts @@ -5,6 +5,7 @@ * 2.0. */ +import { transformError, getIndexExists } from '@kbn/securitysolution-es-utils'; import { buildRouteValidation } from '../../../../utils/build_validation/route_validation'; import { DETECTION_ENGINE_RULES_URL } from '../../../../../common/constants'; import { SetupPlugins } from '../../../../plugin'; @@ -12,8 +13,8 @@ import type { SecuritySolutionPluginRouter } from '../../../../types'; import { buildMlAuthz } from '../../../machine_learning/authz'; import { throwHttpError } from '../../../machine_learning/validation'; import { readRules } from '../../rules/read_rules'; -import { getIndexExists } from '../../index/get_index_exists'; -import { transformError, buildSiemResponse } from '../utils'; +import { buildSiemResponse } from '../utils'; + import { updateRulesNotifications } from '../../rules/update_rules_notifications'; import { ruleStatusSavedObjectsClientFactory } from '../../signals/rule_status_saved_objects_client'; import { createRulesSchema } from '../../../../../common/detection_engine/schemas/request'; diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/delete_rules_bulk_route.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/delete_rules_bulk_route.ts index 9739eb7ba9e0..1e7ba976d691 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/delete_rules_bulk_route.ts +++ b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/delete_rules_bulk_route.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { validate } from '../../../../../common/validate'; +import { validate } from '@kbn/securitysolution-io-ts-utils'; import { queryRuleValidateTypeDependents } from '../../../../../common/detection_engine/schemas/request/query_rules_type_dependents'; import { buildRouteValidation } from '../../../../utils/build_validation/route_validation'; import { diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/delete_rules_route.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/delete_rules_route.ts index 3bd7c7f8730b..76fb9ac0c77e 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/delete_rules_route.ts +++ b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/delete_rules_route.ts @@ -5,6 +5,7 @@ * 2.0. */ +import { transformError } from '@kbn/securitysolution-es-utils'; import { queryRuleValidateTypeDependents } from '../../../../../common/detection_engine/schemas/request/query_rules_type_dependents'; import { queryRulesSchema, @@ -15,7 +16,8 @@ import type { SecuritySolutionPluginRouter } from '../../../../types'; import { DETECTION_ENGINE_RULES_URL } from '../../../../../common/constants'; import { deleteRules } from '../../rules/delete_rules'; import { getIdError, transform } from './utils'; -import { transformError, buildSiemResponse } from '../utils'; +import { buildSiemResponse } from '../utils'; + import { deleteNotifications } from '../../notifications/delete_notifications'; import { deleteRuleActionsSavedObject } from '../../rule_actions/delete_rule_actions_saved_object'; import { ruleStatusSavedObjectsClientFactory } from '../../signals/rule_status_saved_objects_client'; diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/export_rules_route.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/export_rules_route.ts index 8fe20e4db612..cb1c1feba529 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/export_rules_route.ts +++ b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/export_rules_route.ts @@ -5,6 +5,7 @@ * 2.0. */ +import { transformError } from '@kbn/securitysolution-es-utils'; import { exportRulesQuerySchema, ExportRulesQuerySchemaDecoded, @@ -18,7 +19,7 @@ import { ConfigType } from '../../../../config'; import { getNonPackagedRulesCount } from '../../rules/get_existing_prepackaged_rules'; import { getExportByObjectIds } from '../../rules/get_export_by_object_ids'; import { getExportAll } from '../../rules/get_export_all'; -import { transformError, buildSiemResponse } from '../utils'; +import { buildSiemResponse } from '../utils'; export const exportRulesRoute = (router: SecuritySolutionPluginRouter, config: ConfigType) => { router.post( diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/find_rules_route.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/find_rules_route.ts index 005266f5c178..ccf0a59e87c7 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/find_rules_route.ts +++ b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/find_rules_route.ts @@ -5,6 +5,7 @@ * 2.0. */ +import { transformError } from '@kbn/securitysolution-es-utils'; import { findRuleValidateTypeDependents } from '../../../../../common/detection_engine/schemas/request/find_rules_type_dependents'; import { findRulesSchema, @@ -13,7 +14,8 @@ import { import type { SecuritySolutionPluginRouter } from '../../../../types'; import { DETECTION_ENGINE_RULES_URL } from '../../../../../common/constants'; import { findRules } from '../../rules/find_rules'; -import { transformError, buildSiemResponse } from '../utils'; +import { buildSiemResponse } from '../utils'; + import { getRuleActionsSavedObject } from '../../rule_actions/get_rule_actions_saved_object'; import { ruleStatusSavedObjectsClientFactory } from '../../signals/rule_status_saved_objects_client'; import { buildRouteValidation } from '../../../../utils/build_validation/route_validation'; diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/find_rules_status_route.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/find_rules_status_route.ts index cb436b89af01..bd6e8fc9e7aa 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/find_rules_status_route.ts +++ b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/find_rules_status_route.ts @@ -5,11 +5,13 @@ * 2.0. */ +import { transformError } from '@kbn/securitysolution-es-utils'; import { buildRouteValidation } from '../../../../utils/build_validation/route_validation'; import type { SecuritySolutionPluginRouter } from '../../../../types'; import { DETECTION_ENGINE_RULES_URL } from '../../../../../common/constants'; import { RuleStatusResponse } from '../../rules/types'; -import { transformError, buildSiemResponse, mergeStatuses, getFailingRules } from '../utils'; +import { buildSiemResponse, mergeStatuses, getFailingRules } from '../utils'; + import { ruleStatusSavedObjectsClientFactory } from '../../signals/rule_status_saved_objects_client'; import { findRulesStatusesSchema, diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/get_prepackaged_rules_status_route.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/get_prepackaged_rules_status_route.ts index 33f9746fe924..cd02cc72ba40 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/get_prepackaged_rules_status_route.ts +++ b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/get_prepackaged_rules_status_route.ts @@ -5,14 +5,16 @@ * 2.0. */ -import { validate } from '../../../../../common/validate'; +import { transformError } from '@kbn/securitysolution-es-utils'; +import { validate } from '@kbn/securitysolution-io-ts-utils'; import { PrePackagedRulesAndTimelinesStatusSchema, prePackagedRulesAndTimelinesStatusSchema, } from '../../../../../common/detection_engine/schemas/response/prepackaged_rules_status_schema'; import type { SecuritySolutionPluginRouter } from '../../../../types'; import { DETECTION_ENGINE_PREPACKAGED_URL } from '../../../../../common/constants'; -import { transformError, buildSiemResponse } from '../utils'; +import { buildSiemResponse } from '../utils'; + import { getRulesToInstall } from '../../rules/get_rules_to_install'; import { getRulesToUpdate } from '../../rules/get_rules_to_update'; import { findRules } from '../../rules/find_rules'; diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/import_rules_route.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/import_rules_route.ts index b37cc41f1439..8e322405280d 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/import_rules_route.ts +++ b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/import_rules_route.ts @@ -10,7 +10,8 @@ import { extname } from 'path'; import { schema } from '@kbn/config-schema'; import { createPromiseFromStreams } from '@kbn/utils'; -import { validate } from '../../../../../common/validate'; +import { transformError, getIndexExists } from '@kbn/securitysolution-es-utils'; +import { validate } from '@kbn/securitysolution-io-ts-utils'; import { importRulesQuerySchema, ImportRulesQuerySchemaDecoded, @@ -29,16 +30,15 @@ import { buildMlAuthz } from '../../../machine_learning/authz'; import { throwHttpError } from '../../../machine_learning/validation'; import { createRules } from '../../rules/create_rules'; import { readRules } from '../../rules/read_rules'; -import { getIndexExists } from '../../index/get_index_exists'; import { createBulkErrorObject, ImportRuleResponse, BulkError, isBulkError, isImportRegular, - transformError, buildSiemResponse, } from '../utils'; + import { patchRules } from '../../rules/patch_rules'; import { getTupleDuplicateErrorsAndUniqueRules } from './utils'; import { createRulesStreamFromNdJson } from '../../rules/create_rules_stream_from_ndjson'; diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/patch_rules_bulk_route.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/patch_rules_bulk_route.ts index 7d7124259af0..7eb01e8b0d40 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/patch_rules_bulk_route.ts +++ b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/patch_rules_bulk_route.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { validate } from '../../../../../common/validate'; +import { validate } from '@kbn/securitysolution-io-ts-utils'; import { RuleAlertAction } from '../../../../../common/detection_engine/types'; import { patchRulesBulkSchema, diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/patch_rules_route.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/patch_rules_route.ts index fd5c33f126fe..780c248183ab 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/patch_rules_route.ts +++ b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/patch_rules_route.ts @@ -5,6 +5,7 @@ * 2.0. */ +import { transformError } from '@kbn/securitysolution-es-utils'; import { RuleAlertAction } from '../../../../../common/detection_engine/types'; import { patchRuleValidateTypeDependents } from '../../../../../common/detection_engine/schemas/request/patch_rules_type_dependents'; import { buildRouteValidation } from '../../../../utils/build_validation/route_validation'; @@ -18,7 +19,8 @@ import { SetupPlugins } from '../../../../plugin'; import { buildMlAuthz } from '../../../machine_learning/authz'; import { throwHttpError } from '../../../machine_learning/validation'; import { patchRules } from '../../rules/patch_rules'; -import { transformError, buildSiemResponse } from '../utils'; +import { buildSiemResponse } from '../utils'; + import { getIdError } from './utils'; import { transformValidate } from './validate'; import { updateRulesNotifications } from '../../rules/update_rules_notifications'; diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/read_rules_route.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/read_rules_route.ts index b2dd9ea8fb79..ac45e5d2ed3b 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/read_rules_route.ts +++ b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/read_rules_route.ts @@ -5,6 +5,7 @@ * 2.0. */ +import { transformError } from '@kbn/securitysolution-es-utils'; import { queryRuleValidateTypeDependents } from '../../../../../common/detection_engine/schemas/request/query_rules_type_dependents'; import { queryRulesSchema, @@ -14,7 +15,8 @@ import { buildRouteValidation } from '../../../../utils/build_validation/route_v import type { SecuritySolutionPluginRouter } from '../../../../types'; import { DETECTION_ENGINE_RULES_URL } from '../../../../../common/constants'; import { getIdError, transform } from './utils'; -import { transformError, buildSiemResponse } from '../utils'; +import { buildSiemResponse } from '../utils'; + import { readRules } from '../../rules/read_rules'; import { getRuleActionsSavedObject } from '../../rule_actions/get_rule_actions_saved_object'; import { ruleStatusSavedObjectsClientFactory } from '../../signals/rule_status_saved_objects_client'; diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/update_rules_bulk_route.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/update_rules_bulk_route.ts index d088795a118b..4c59ae2ba442 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/update_rules_bulk_route.ts +++ b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/update_rules_bulk_route.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { validate } from '../../../../../common/validate'; +import { validate } from '@kbn/securitysolution-io-ts-utils'; import { updateRuleValidateTypeDependents } from '../../../../../common/detection_engine/schemas/request/update_rules_type_dependents'; import { buildRouteValidation } from '../../../../utils/build_validation/route_validation'; import { updateRulesBulkSchema } from '../../../../../common/detection_engine/schemas/request/update_rules_bulk_schema'; diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/update_rules_route.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/update_rules_route.ts index b883b7b3462e..aad0068758f7 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/update_rules_route.ts +++ b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/update_rules_route.ts @@ -5,6 +5,7 @@ * 2.0. */ +import { transformError } from '@kbn/securitysolution-es-utils'; import { updateRulesSchema } from '../../../../../common/detection_engine/schemas/request'; import { updateRuleValidateTypeDependents } from '../../../../../common/detection_engine/schemas/request/update_rules_type_dependents'; import type { SecuritySolutionPluginRouter } from '../../../../types'; @@ -12,7 +13,8 @@ import { DETECTION_ENGINE_RULES_URL } from '../../../../../common/constants'; import { SetupPlugins } from '../../../../plugin'; import { buildMlAuthz } from '../../../machine_learning/authz'; import { throwHttpError } from '../../../machine_learning/validation'; -import { transformError, buildSiemResponse } from '../utils'; +import { buildSiemResponse } from '../utils'; + import { getIdError } from './utils'; import { transformValidate } from './validate'; import { updateRules } from '../../rules/update_rules'; diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/utils.test.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/utils.test.ts index b841507bc7a6..f2788ab1bd4c 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/utils.test.ts +++ b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/utils.test.ts @@ -32,7 +32,7 @@ import { createRulesStreamFromNdJson } from '../../rules/create_rules_stream_fro import { RuleAlertType } from '../../rules/types'; import { ImportRulesSchemaDecoded } from '../../../../../common/detection_engine/schemas/request/import_rules_schema'; import { getCreateRulesSchemaMock } from '../../../../../common/detection_engine/schemas/request/rule_schemas.mock'; -import { ThreatMapping } from '../../../../../common/detection_engine/schemas/types/threat_mapping'; +import { ThreatMapping } from '@kbn/securitysolution-io-ts-alerting-types'; import { CreateRulesBulkSchema } from '../../../../../common/detection_engine/schemas/request'; import { getMlRuleParams, diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/validate.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/validate.ts index ac9ac960d6f0..d27208de487d 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/validate.ts +++ b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/validate.ts @@ -7,11 +7,11 @@ import { SavedObject, SavedObjectsFindResponse } from 'kibana/server'; +import { validateNonExact } from '@kbn/securitysolution-io-ts-utils'; import { FullResponseSchema, fullResponseSchema, } from '../../../../../common/detection_engine/schemas/request'; -import { validateNonExact } from '../../../../../common/validate'; import { RulesSchema, rulesSchema, diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/signals/create_signals_migration_route.test.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/signals/create_signals_migration_route.test.ts index aed15b66b9bb..f10907f7c0c0 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/signals/create_signals_migration_route.test.ts +++ b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/signals/create_signals_migration_route.test.ts @@ -13,13 +13,19 @@ import { getCreateSignalsMigrationSchemaMock } from '../../../../../common/detec import { getIndexVersionsByIndex } from '../../migrations/get_index_versions_by_index'; import { getSignalVersionsByIndex } from '../../migrations/get_signal_versions_by_index'; import { createMigration } from '../../migrations/create_migration'; -import { getIndexAliases } from '../../index/get_index_aliases'; +import { getIndexAliases } from '@kbn/securitysolution-es-utils'; import { getTemplateVersion } from '../index/check_template_version'; import { createSignalsMigrationRoute } from './create_signals_migration_route'; import { SIGNALS_TEMPLATE_VERSION } from '../index/get_signals_template'; jest.mock('../index/check_template_version'); -jest.mock('../../index/get_index_aliases'); +jest.mock('@kbn/securitysolution-es-utils', () => { + const original = jest.requireActual('@kbn/securitysolution-es-utils'); + return { + ...original, + getIndexAliases: jest.fn(), + }; +}); jest.mock('../../migrations/create_migration'); jest.mock('../../migrations/get_index_versions_by_index'); jest.mock('../../migrations/get_signal_versions_by_index'); diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/signals/create_signals_migration_route.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/signals/create_signals_migration_route.ts index 99732930234a..6dd2534870dc 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/signals/create_signals_migration_route.ts +++ b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/signals/create_signals_migration_route.ts @@ -5,16 +5,16 @@ * 2.0. */ +import { transformError, BadRequestError, getIndexAliases } from '@kbn/securitysolution-es-utils'; import type { SecuritySolutionPluginRouter } from '../../../../types'; import { SetupPlugins } from '../../../../plugin'; import { DETECTION_ENGINE_SIGNALS_MIGRATION_URL } from '../../../../../common/constants'; import { createSignalsMigrationSchema } from '../../../../../common/detection_engine/schemas/request/create_signals_migration_schema'; import { buildRouteValidation } from '../../../../utils/build_validation/route_validation'; -import { buildSiemResponse, transformError } from '../utils'; +import { buildSiemResponse } from '../utils'; + import { getTemplateVersion } from '../index/check_template_version'; import { isOutdated, signalsAreOutdated } from '../../migrations/helpers'; -import { getIndexAliases } from '../../index/get_index_aliases'; -import { BadRequestError } from '../../errors/bad_request_error'; import { signalsMigrationService } from '../../migrations/migration_service'; import { getIndexVersionsByIndex } from '../../migrations/get_index_versions_by_index'; import { getSignalVersionsByIndex } from '../../migrations/get_signal_versions_by_index'; diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/signals/delete_signals_migration_route.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/signals/delete_signals_migration_route.ts index 2f0749388522..65ed42a0a166 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/signals/delete_signals_migration_route.ts +++ b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/signals/delete_signals_migration_route.ts @@ -5,12 +5,14 @@ * 2.0. */ +import { transformError } from '@kbn/securitysolution-es-utils'; import type { SecuritySolutionPluginRouter } from '../../../../types'; import { SetupPlugins } from '../../../../plugin'; import { DETECTION_ENGINE_SIGNALS_MIGRATION_URL } from '../../../../../common/constants'; import { deleteSignalsMigrationSchema } from '../../../../../common/detection_engine/schemas/request/delete_signals_migration_schema'; import { buildRouteValidation } from '../../../../utils/build_validation/route_validation'; -import { buildSiemResponse, transformError } from '../utils'; +import { buildSiemResponse } from '../utils'; + import { signalsMigrationService } from '../../migrations/migration_service'; import { getMigrationSavedObjectsById } from '../../migrations/get_migration_saved_objects_by_id'; diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/signals/finalize_signals_migration_route.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/signals/finalize_signals_migration_route.ts index 93567f77d17d..20931a8ba723 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/signals/finalize_signals_migration_route.ts +++ b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/signals/finalize_signals_migration_route.ts @@ -5,15 +5,16 @@ * 2.0. */ +import { transformError, BadRequestError } from '@kbn/securitysolution-es-utils'; import type { SecuritySolutionPluginRouter } from '../../../../types'; import { SetupPlugins } from '../../../../plugin'; import { DETECTION_ENGINE_SIGNALS_FINALIZE_MIGRATION_URL } from '../../../../../common/constants'; import { finalizeSignalsMigrationSchema } from '../../../../../common/detection_engine/schemas/request/finalize_signals_migration_schema'; import { buildRouteValidation } from '../../../../utils/build_validation/route_validation'; -import { BadRequestError } from '../../errors/bad_request_error'; import { isMigrationFailed, isMigrationPending } from '../../migrations/helpers'; import { signalsMigrationService } from '../../migrations/migration_service'; -import { buildSiemResponse, transformError } from '../utils'; +import { buildSiemResponse } from '../utils'; + import { getMigrationSavedObjectsById } from '../../migrations/get_migration_saved_objects_by_id'; export const finalizeSignalsMigrationRoute = ( diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/signals/get_signals_migration_status_route.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/signals/get_signals_migration_status_route.ts index cd7cd017b8c2..d800cead20cd 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/signals/get_signals_migration_status_route.ts +++ b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/signals/get_signals_migration_status_route.ts @@ -5,18 +5,18 @@ * 2.0. */ +import { transformError, getIndexAliases } from '@kbn/securitysolution-es-utils'; import type { SecuritySolutionPluginRouter } from '../../../../types'; import { DETECTION_ENGINE_SIGNALS_MIGRATION_STATUS_URL } from '../../../../../common/constants'; import { getSignalsMigrationStatusSchema } from '../../../../../common/detection_engine/schemas/request/get_signals_migration_status_schema'; import { buildRouteValidation } from '../../../../utils/build_validation/route_validation'; -import { getIndexAliases } from '../../index/get_index_aliases'; import { getIndexVersionsByIndex } from '../../migrations/get_index_versions_by_index'; import { getMigrationSavedObjectsByIndex } from '../../migrations/get_migration_saved_objects_by_index'; import { getSignalsIndicesInRange } from '../../migrations/get_signals_indices_in_range'; import { getSignalVersionsByIndex } from '../../migrations/get_signal_versions_by_index'; import { isOutdated, signalsAreOutdated } from '../../migrations/helpers'; import { getTemplateVersion } from '../index/check_template_version'; -import { buildSiemResponse, transformError } from '../utils'; +import { buildSiemResponse } from '../utils'; export const getSignalsMigrationStatusRoute = (router: SecuritySolutionPluginRouter) => { router.get( diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/signals/open_close_signals_route.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/signals/open_close_signals_route.ts index d92d39f91baa..fd001595fb9c 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/signals/open_close_signals_route.ts +++ b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/signals/open_close_signals_route.ts @@ -5,6 +5,7 @@ * 2.0. */ +import { transformError } from '@kbn/securitysolution-es-utils'; import { setSignalStatusValidateTypeDependents } from '../../../../../common/detection_engine/schemas/request/set_signal_status_type_dependents'; import { SetSignalsStatusSchemaDecoded, @@ -12,7 +13,8 @@ import { } from '../../../../../common/detection_engine/schemas/request/set_signal_status_schema'; import type { SecuritySolutionPluginRouter } from '../../../../types'; import { DETECTION_ENGINE_SIGNALS_STATUS_URL } from '../../../../../common/constants'; -import { transformError, buildSiemResponse } from '../utils'; +import { buildSiemResponse } from '../utils'; + import { buildRouteValidation } from '../../../../utils/build_validation/route_validation'; export const setSignalsStatusRoute = (router: SecuritySolutionPluginRouter) => { diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/signals/query_signals_route.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/signals/query_signals_route.ts index 9e542f6974ff..91172a277bf5 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/signals/query_signals_route.ts +++ b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/signals/query_signals_route.ts @@ -5,9 +5,10 @@ * 2.0. */ +import { transformError } from '@kbn/securitysolution-es-utils'; import type { SecuritySolutionPluginRouter } from '../../../../types'; import { DETECTION_ENGINE_QUERY_SIGNALS_URL } from '../../../../../common/constants'; -import { transformError, buildSiemResponse } from '../utils'; +import { buildSiemResponse } from '../utils'; import { buildRouteValidation } from '../../../../utils/build_validation/route_validation'; import { diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/tags/read_tags_route.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/tags/read_tags_route.ts index 31ee4f5f42a5..817e4b95aabc 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/tags/read_tags_route.ts +++ b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/tags/read_tags_route.ts @@ -5,9 +5,11 @@ * 2.0. */ +import { transformError } from '@kbn/securitysolution-es-utils'; import type { SecuritySolutionPluginRouter } from '../../../../types'; import { DETECTION_ENGINE_TAGS_URL } from '../../../../../common/constants'; -import { transformError, buildSiemResponse } from '../utils'; +import { buildSiemResponse } from '../utils'; + import { readTags } from '../../tags/read_tags'; export const readTagsRoute = (router: SecuritySolutionPluginRouter) => { diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/utils.test.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/utils.test.ts index cca7e871f5b8..3c3eda5b19e4 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/utils.test.ts +++ b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/utils.test.ts @@ -6,15 +6,13 @@ */ import Boom from '@hapi/boom'; -import { errors } from '@elastic/elasticsearch'; import { SavedObjectsFindResponse } from 'kibana/server'; import { alertsClientMock } from '../../../../../alerting/server/mocks'; import { IRuleSavedAttributesSavedObjectAttributes, IRuleStatusSOAttributes } from '../rules/types'; -import { BadRequestError } from '../errors/bad_request_error'; +import { BadRequestError } from '@kbn/securitysolution-es-utils'; import { - transformError, transformBulkError, BulkError, createSuccessObject, @@ -35,95 +33,6 @@ import { getQueryRuleParams } from '../schemas/rule_schemas.mock'; let alertsClient: ReturnType; describe('utils', () => { - describe('transformError', () => { - test('returns transformed output error from boom object with a 500 and payload of internal server error', () => { - const boom = new Boom.Boom('some boom message'); - const transformed = transformError(boom); - expect(transformed).toEqual({ - message: 'An internal server error occurred', - statusCode: 500, - }); - }); - - test('returns transformed output if it is some non boom object that has a statusCode', () => { - const error: Error & { statusCode?: number } = { - statusCode: 403, - name: 'some name', - message: 'some message', - }; - const transformed = transformError(error); - expect(transformed).toEqual({ - message: 'some message', - statusCode: 403, - }); - }); - - test('returns a transformed message with the message set and statusCode', () => { - const error: Error & { statusCode?: number } = { - statusCode: 403, - name: 'some name', - message: 'some message', - }; - const transformed = transformError(error); - expect(transformed).toEqual({ - message: 'some message', - statusCode: 403, - }); - }); - - test('transforms best it can if it is some non boom object but it does not have a status Code.', () => { - const error: Error = { - name: 'some name', - message: 'some message', - }; - const transformed = transformError(error); - expect(transformed).toEqual({ - message: 'some message', - statusCode: 500, - }); - }); - - test('it detects a BadRequestError and returns a status code of 400 from that particular error type', () => { - const error: BadRequestError = new BadRequestError('I have a type error'); - const transformed = transformError(error); - expect(transformed).toEqual({ - message: 'I have a type error', - statusCode: 400, - }); - }); - - test('it detects a BadRequestError and returns a Boom status of 400', () => { - const error: BadRequestError = new BadRequestError('I have a type error'); - const transformed = transformError(error); - expect(transformed).toEqual({ - message: 'I have a type error', - statusCode: 400, - }); - }); - - it('transforms a ResponseError returned by the elasticsearch client', () => { - const error: errors.ResponseError = { - name: 'ResponseError', - message: 'illegal_argument_exception', - headers: {}, - body: { - error: { - type: 'illegal_argument_exception', - reason: 'detailed explanation', - }, - }, - meta: ({} as unknown) as errors.ResponseError['meta'], - statusCode: 400, - }; - const transformed = transformError(error); - - expect(transformed).toEqual({ - message: 'illegal_argument_exception: detailed explanation', - statusCode: 400, - }); - }); - }); - describe('transformBulkError', () => { test('returns transformed object if it is a boom object', () => { const boom = new Boom.Boom('some boom message', { statusCode: 400 }); diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/utils.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/utils.ts index c2acbf9c5cc0..130084da2159 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/utils.ts +++ b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/utils.ts @@ -6,8 +6,8 @@ */ import Boom from '@hapi/boom'; -import { errors } from '@elastic/elasticsearch'; import { has, snakeCase } from 'lodash/fp'; +import { BadRequestError } from '@kbn/securitysolution-es-utils'; import { SanitizedAlert } from '../../../../../alerting/common'; import { @@ -17,53 +17,12 @@ import { SavedObjectsFindResult, } from '../../../../../../../src/core/server'; import { AlertsClient } from '../../../../../alerting/server'; -import { BadRequestError } from '../errors/bad_request_error'; import { RuleStatusResponse, IRuleStatusSOAttributes } from '../rules/types'; export interface OutputError { message: string; statusCode: number; } - -/** - * @deprecated Use kbn-securitysolution-es-utils version - */ -export const transformError = (err: Error & Partial): OutputError => { - if (Boom.isBoom(err)) { - return { - message: err.output.payload.message, - statusCode: err.output.statusCode, - }; - } else { - if (err.statusCode != null) { - if (err.body?.error != null) { - return { - statusCode: err.statusCode, - message: `${err.body.error.type}: ${err.body.error.reason}`, - }; - } else { - return { - statusCode: err.statusCode, - message: err.message, - }; - } - } else if (err instanceof BadRequestError) { - // allows us to throw request validation errors in the absence of Boom - return { - message: err.message, - statusCode: 400, - }; - } else { - // natively return the err and allow the regular framework - // to deal with the error when it is a non Boom - return { - message: err.message ?? '(unknown error message)', - statusCode: 500, - }; - } - } -}; - export interface BulkError { id?: string; rule_id?: string; diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/rules/create_rules_stream_from_ndjson.test.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/rules/create_rules_stream_from_ndjson.test.ts index 248afda7ff5c..c5b3e98c4c44 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/rules/create_rules_stream_from_ndjson.test.ts +++ b/x-pack/plugins/security_solution/server/lib/detection_engine/rules/create_rules_stream_from_ndjson.test.ts @@ -8,7 +8,7 @@ import { Readable } from 'stream'; import { createPromiseFromStreams } from '@kbn/utils'; import { createRulesStreamFromNdJson } from './create_rules_stream_from_ndjson'; -import { BadRequestError } from '../errors/bad_request_error'; +import { BadRequestError } from '@kbn/securitysolution-es-utils'; import { ImportRulesSchemaDecoded } from '../../../../common/detection_engine/schemas/request/import_rules_schema'; type PromiseFromStreams = ImportRulesSchemaDecoded | Error; diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/rules/create_rules_stream_from_ndjson.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/rules/create_rules_stream_from_ndjson.ts index 5e3c3c8b1cb9..0c2d81c18646 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/rules/create_rules_stream_from_ndjson.ts +++ b/x-pack/plugins/security_solution/server/lib/detection_engine/rules/create_rules_stream_from_ndjson.ts @@ -11,15 +11,14 @@ import { pipe } from 'fp-ts/lib/pipeable'; import { fold } from 'fp-ts/lib/Either'; import { createSplitStream, createMapStream, createConcatStream } from '@kbn/utils'; -import { formatErrors } from '../../../../common/format_errors'; +import { exactCheck, formatErrors } from '@kbn/securitysolution-io-ts-utils'; +import { BadRequestError } from '@kbn/securitysolution-es-utils'; import { importRuleValidateTypeDependents } from '../../../../common/detection_engine/schemas/request/import_rules_type_dependents'; -import { exactCheck } from '../../../../common/exact_check'; import { importRulesSchema, ImportRulesSchema, ImportRulesSchemaDecoded, } from '../../../../common/detection_engine/schemas/request/import_rules_schema'; -import { BadRequestError } from '../errors/bad_request_error'; import { parseNdjsonStrings, filterExportedCounts, diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/rules/get_prepackaged_rules.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/rules/get_prepackaged_rules.ts index b91557c6d7b1..f2d28d13fa92 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/rules/get_prepackaged_rules.ts +++ b/x-pack/plugins/security_solution/server/lib/detection_engine/rules/get_prepackaged_rules.ts @@ -8,14 +8,13 @@ import * as t from 'io-ts'; import { fold } from 'fp-ts/lib/Either'; import { pipe } from 'fp-ts/lib/pipeable'; -import { formatErrors } from '../../../../common/format_errors'; -import { exactCheck } from '../../../../common/exact_check'; +import { exactCheck, formatErrors } from '@kbn/securitysolution-io-ts-utils'; +import { BadRequestError } from '@kbn/securitysolution-es-utils'; import { addPrepackagedRulesSchema, AddPrepackagedRulesSchema, AddPrepackagedRulesSchemaDecoded, } from '../../../../common/detection_engine/schemas/request/add_prepackaged_rules_schema'; -import { BadRequestError } from '../errors/bad_request_error'; // TODO: convert rules files to TS and add explicit type definitions import { rawRules } from './prepackaged_rules'; diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/rules/patch_rules.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/rules/patch_rules.ts index bccd1f2fb73c..b9a88bc36a81 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/rules/patch_rules.ts +++ b/x-pack/plugins/security_solution/server/lib/detection_engine/rules/patch_rules.ts @@ -6,7 +6,7 @@ */ import { defaults } from 'lodash/fp'; -import { validate } from '../../../../common/validate'; +import { validate } from '@kbn/securitysolution-io-ts-utils'; import { PartialAlert } from '../../../../../alerting/server'; import { transformRuleToAlertAction } from '../../../../common/detection_engine/transform_actions'; import { PatchRulesOptions } from './types'; diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/rules/types.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/rules/types.ts index 2990a0f72802..e670535c26ae 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/rules/types.ts +++ b/x-pack/plugins/security_solution/server/lib/detection_engine/rules/types.ts @@ -14,55 +14,70 @@ import { SavedObjectsFindResponse, SavedObjectsClientContract, } from 'kibana/server'; +import { + MachineLearningJobIdOrUndefined, + From, + FromOrUndefined, + RiskScore, + RiskScoreMapping, + RiskScoreMappingOrUndefined, + RiskScoreOrUndefined, + ThreatIndexOrUndefined, + ThreatQueryOrUndefined, + ThreatMappingOrUndefined, + ThreatFiltersOrUndefined, + ThreatLanguageOrUndefined, + ConcurrentSearchesOrUndefined, + ItemsPerSearchOrUndefined, + ThreatIndicatorPathOrUndefined, + Threats, + ThreatsOrUndefined, + TypeOrUndefined, + Type, + LanguageOrUndefined, + SeverityMapping, + SeverityMappingOrUndefined, + SeverityOrUndefined, + Severity, + MaxSignalsOrUndefined, + MaxSignals, +} from '@kbn/securitysolution-io-ts-alerting-types'; +import { VersionOrUndefined, Version } from '@kbn/securitysolution-io-ts-types'; + +import { ListArrayOrUndefined, ListArray } from '@kbn/securitysolution-io-ts-list-types'; import { UpdateRulesSchema } from '../../../../common/detection_engine/schemas/request'; import { RuleAlertAction } from '../../../../common/detection_engine/types'; import { FalsePositives, - From, RuleId, Immutable, DescriptionOrUndefined, Interval, - MaxSignals, - RiskScore, OutputIndex, Name, - Severity, Tags, - Threats, To, - Type, References, - Version, AnomalyThresholdOrUndefined, QueryOrUndefined, - LanguageOrUndefined, SavedIdOrUndefined, TimelineIdOrUndefined, TimelineTitleOrUndefined, - MachineLearningJobIdOrUndefined, IndexOrUndefined, NoteOrUndefined, MetaOrUndefined, Description, Enabled, - VersionOrUndefined, IdOrUndefined, RuleIdOrUndefined, EnabledOrUndefined, FalsePositivesOrUndefined, - FromOrUndefined, OutputIndexOrUndefined, IntervalOrUndefined, - MaxSignalsOrUndefined, - RiskScoreOrUndefined, NameOrUndefined, - SeverityOrUndefined, TagsOrUndefined, ToOrUndefined, - ThreatsOrUndefined, ThresholdOrUndefined, - TypeOrUndefined, ReferencesOrUndefined, PerPageOrUndefined, PageOrUndefined, @@ -79,31 +94,16 @@ import { Author, AuthorOrUndefined, LicenseOrUndefined, - RiskScoreMapping, - RiskScoreMappingOrUndefined, - SeverityMapping, - SeverityMappingOrUndefined, TimestampOverrideOrUndefined, BuildingBlockTypeOrUndefined, RuleNameOverrideOrUndefined, EventCategoryOverrideOrUndefined, } from '../../../../common/detection_engine/schemas/common/schemas'; -import { - ThreatIndexOrUndefined, - ThreatQueryOrUndefined, - ThreatMappingOrUndefined, - ThreatFiltersOrUndefined, - ThreatLanguageOrUndefined, - ConcurrentSearchesOrUndefined, - ItemsPerSearchOrUndefined, - ThreatIndicatorPathOrUndefined, -} from '../../../../common/detection_engine/schemas/types/threat_mapping'; import { AlertsClient, PartialAlert } from '../../../../../alerting/server'; import { Alert, SanitizedAlert } from '../../../../../alerting/common'; import { SIGNALS_ID } from '../../../../common/constants'; import { PartialFilter } from '../types'; -import { ListArrayOrUndefined, ListArray } from '../../../../common/detection_engine/schemas/types'; import { RuleParams } from '../schemas/rule_schemas'; export type RuleAlertType = Alert; diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/rules/utils.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/rules/utils.ts index 5c8450201d09..a31f9bec2cd5 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/rules/utils.ts +++ b/x-pack/plugins/security_solution/server/lib/detection_engine/rules/utils.ts @@ -7,52 +7,52 @@ import { pickBy, isEmpty } from 'lodash/fp'; import { - DescriptionOrUndefined, - AnomalyThresholdOrUndefined, - QueryOrUndefined, - LanguageOrUndefined, - SavedIdOrUndefined, - TimelineIdOrUndefined, - TimelineTitleOrUndefined, - MachineLearningJobIdOrUndefined, - IndexOrUndefined, - NoteOrUndefined, - MetaOrUndefined, - VersionOrUndefined, - FalsePositivesOrUndefined, FromOrUndefined, - OutputIndexOrUndefined, - IntervalOrUndefined, - MaxSignalsOrUndefined, - RiskScoreOrUndefined, - NameOrUndefined, - SeverityOrUndefined, - TagsOrUndefined, - ToOrUndefined, - ThreatsOrUndefined, - ThresholdOrUndefined, - TypeOrUndefined, - ReferencesOrUndefined, - AuthorOrUndefined, - BuildingBlockTypeOrUndefined, - LicenseOrUndefined, + MachineLearningJobIdOrUndefined, RiskScoreMappingOrUndefined, - RuleNameOverrideOrUndefined, - SeverityMappingOrUndefined, - TimestampOverrideOrUndefined, - EventCategoryOverrideOrUndefined, -} from '../../../../common/detection_engine/schemas/common/schemas'; -import { PartialFilter } from '../types'; -import { + RiskScoreOrUndefined, ConcurrentSearchesOrUndefined, ItemsPerSearchOrUndefined, - ListArrayOrUndefined, ThreatFiltersOrUndefined, ThreatIndexOrUndefined, ThreatLanguageOrUndefined, ThreatMappingOrUndefined, ThreatQueryOrUndefined, -} from '../../../../common/detection_engine/schemas/types'; + ThreatsOrUndefined, + TypeOrUndefined, + LanguageOrUndefined, + SeverityOrUndefined, + SeverityMappingOrUndefined, + MaxSignalsOrUndefined, +} from '@kbn/securitysolution-io-ts-alerting-types'; +import { ListArrayOrUndefined } from '@kbn/securitysolution-io-ts-list-types'; +import { VersionOrUndefined } from '@kbn/securitysolution-io-ts-types'; +import { + DescriptionOrUndefined, + AnomalyThresholdOrUndefined, + QueryOrUndefined, + SavedIdOrUndefined, + TimelineIdOrUndefined, + TimelineTitleOrUndefined, + IndexOrUndefined, + NoteOrUndefined, + MetaOrUndefined, + FalsePositivesOrUndefined, + OutputIndexOrUndefined, + IntervalOrUndefined, + NameOrUndefined, + TagsOrUndefined, + ToOrUndefined, + ThresholdOrUndefined, + ReferencesOrUndefined, + AuthorOrUndefined, + BuildingBlockTypeOrUndefined, + LicenseOrUndefined, + RuleNameOverrideOrUndefined, + TimestampOverrideOrUndefined, + EventCategoryOverrideOrUndefined, +} from '../../../../common/detection_engine/schemas/common/schemas'; +import { PartialFilter } from '../types'; export const calculateInterval = ( interval: string | undefined, diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/schemas/rule_schemas.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/schemas/rule_schemas.ts index 79b862d6419c..2af481b195a0 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/schemas/rule_schemas.ts +++ b/x-pack/plugins/security_solution/server/lib/detection_engine/schemas/rule_schemas.ts @@ -7,15 +7,26 @@ import * as t from 'io-ts'; -import { listArray } from '../../../../common/detection_engine/schemas/types/lists'; import { + actionsCamel, + from, + machine_learning_job_id_normalized, + risk_score, + risk_score_mapping, threat_mapping, threat_index, threat_query, concurrentSearchesOrUndefined, itemsPerSearchOrUndefined, threatIndicatorPathOrUndefined, -} from '../../../../common/detection_engine/schemas/types/threat_mapping'; + threats, + severity, + severity_mapping, + throttleOrNull, + max_signals, +} from '@kbn/securitysolution-io-ts-alerting-types'; +import { listArray } from '@kbn/securitysolution-io-ts-list-types'; +import { version } from '@kbn/securitysolution-io-ts-types'; import { author, buildingBlockTypeOrUndefined, @@ -23,7 +34,6 @@ import { enabled, noteOrUndefined, false_positives, - from, rule_id, immutable, indexOrUndefined, @@ -36,32 +46,23 @@ import { query, queryOrUndefined, filtersOrUndefined, - max_signals, - risk_score, - risk_score_mapping, ruleNameOverrideOrUndefined, - severity, - severity_mapping, tags, timestampOverrideOrUndefined, - threats, to, references, - version, eventCategoryOverrideOrUndefined, savedIdOrUndefined, saved_id, thresholdNormalized, anomaly_threshold, - actionsCamel, - throttleOrNull, createdByOrNull, updatedByOrNull, created_at, updated_at, } from '../../../../common/detection_engine/schemas/common/schemas'; + import { SIGNALS_ID, SERVER_APP_ID } from '../../../../common/constants'; -import { machine_learning_job_id_normalized } from '../../../../common/detection_engine/schemas/types/normalized_ml_job_id'; const nonEqlLanguages = t.keyof({ kuery: null, lucene: null }); export const baseRuleParams = t.exact( diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/signals/filters/types.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/signals/filters/types.ts index e1618d217d0d..f653fde816c6 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/signals/filters/types.ts +++ b/x-pack/plugins/security_solution/server/lib/detection_engine/signals/filters/types.ts @@ -7,9 +7,10 @@ import type { estypes } from '@elastic/elasticsearch'; import { Logger } from 'src/core/server'; +import { Type } from '@kbn/securitysolution-io-ts-list-types'; import { ListClient } from '../../../../../../lists/server'; import { BuildRuleMessage } from '../rule_messages'; -import { ExceptionListItemSchema, Type } from '../../../../../../lists/common/schemas'; +import { ExceptionListItemSchema } from '../../../../../../lists/common/schemas'; export interface FilterEventsAgainstListOptions { listClient: ListClient; diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/signals/get_filter.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/signals/get_filter.ts index 86940e9b7708..3d6a1f8da7f4 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/signals/get_filter.ts +++ b/x-pack/plugins/security_solution/server/lib/detection_engine/signals/get_filter.ts @@ -5,15 +5,14 @@ * 2.0. */ +import { BadRequestError } from '@kbn/securitysolution-es-utils'; +import { Type, LanguageOrUndefined, Language } from '@kbn/securitysolution-io-ts-alerting-types'; import { assertUnreachable } from '../../../../common/utility_types'; import { getQueryFilter } from '../../../../common/detection_engine/get_query_filter'; import { - LanguageOrUndefined, QueryOrUndefined, - Type, SavedIdOrUndefined, IndexOrUndefined, - Language, } from '../../../../common/detection_engine/schemas/common/schemas'; import { ExceptionListItemSchema } from '../../../../../lists/common/schemas'; import { @@ -22,7 +21,6 @@ import { AlertServices, } from '../../../../../alerting/server'; import { PartialFilter } from '../types'; -import { BadRequestError } from '../errors/bad_request_error'; import { QueryFilter } from './types'; interface GetFilterArgs { diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/signals/mappings/build_risk_score_from_mapping.test.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/signals/mappings/build_risk_score_from_mapping.test.ts index 88ce9de15cff..82f3ff46b347 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/signals/mappings/build_risk_score_from_mapping.test.ts +++ b/x-pack/plugins/security_solution/server/lib/detection_engine/signals/mappings/build_risk_score_from_mapping.test.ts @@ -5,10 +5,7 @@ * 2.0. */ -import { - RiskScore, - RiskScoreMappingOrUndefined, -} from '../../../../../common/detection_engine/schemas/common/schemas'; +import { RiskScore, RiskScoreMappingOrUndefined } from '@kbn/securitysolution-io-ts-alerting-types'; import { sampleDocRiskScore } from '../__mocks__/es_results'; import { buildRiskScoreFromMapping, diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/signals/mappings/build_risk_score_from_mapping.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/signals/mappings/build_risk_score_from_mapping.ts index 84d45f22b7f4..7253b24e6608 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/signals/mappings/build_risk_score_from_mapping.ts +++ b/x-pack/plugins/security_solution/server/lib/detection_engine/signals/mappings/build_risk_score_from_mapping.ts @@ -5,12 +5,9 @@ * 2.0. */ +import { RiskScore, RiskScoreMappingOrUndefined } from '@kbn/securitysolution-io-ts-alerting-types'; import { get } from 'lodash/fp'; -import { - Meta, - RiskScore, - RiskScoreMappingOrUndefined, -} from '../../../../../common/detection_engine/schemas/common/schemas'; +import { Meta } from '../../../../../common/detection_engine/schemas/common/schemas'; import { SignalSource } from '../types'; export interface BuildRiskScoreFromMappingProps { diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/signals/mappings/build_severity_from_mapping.test.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/signals/mappings/build_severity_from_mapping.test.ts index cfd4b81ae3bc..4ccf24a307cc 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/signals/mappings/build_severity_from_mapping.test.ts +++ b/x-pack/plugins/security_solution/server/lib/detection_engine/signals/mappings/build_severity_from_mapping.test.ts @@ -5,10 +5,8 @@ * 2.0. */ -import { - Severity, - SeverityMappingOrUndefined, -} from '../../../../../common/detection_engine/schemas/common/schemas'; +import { Severity, SeverityMappingOrUndefined } from '@kbn/securitysolution-io-ts-alerting-types'; + import { sampleDocSeverity } from '../__mocks__/es_results'; import { buildSeverityFromMapping, diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/signals/mappings/build_severity_from_mapping.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/signals/mappings/build_severity_from_mapping.ts index 44e41fbd0c9c..652b6b222190 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/signals/mappings/build_severity_from_mapping.ts +++ b/x-pack/plugins/security_solution/server/lib/detection_engine/signals/mappings/build_severity_from_mapping.ts @@ -6,13 +6,14 @@ */ import { get } from 'lodash/fp'; + import { - Meta, Severity, SeverityMappingItem, severity as SeverityIOTS, SeverityMappingOrUndefined, -} from '../../../../../common/detection_engine/schemas/common/schemas'; +} from '@kbn/securitysolution-io-ts-alerting-types'; +import { Meta } from '../../../../../common/detection_engine/schemas/common/schemas'; import { SearchTypes } from '../../../../../common/detection_engine/types'; import { SignalSource } from '../types'; diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/signals/signal_rule_alert_type.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/signals/signal_rule_alert_type.ts index 6e24e96c6e36..d00bcc2a9f11 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/signals/signal_rule_alert_type.ts +++ b/x-pack/plugins/security_solution/server/lib/detection_engine/signals/signal_rule_alert_type.ts @@ -12,7 +12,7 @@ import { chain, tryCatch } from 'fp-ts/lib/TaskEither'; import { flow } from 'fp-ts/lib/function'; import * as t from 'io-ts'; -import { validateNonExact } from '../../../../common/validate'; +import { validateNonExact } from '@kbn/securitysolution-io-ts-utils'; import { toError, toPromise } from '../../../../common/fp_utils'; import { diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/signals/threat_mapping/build_threat_mapping_filter.mock.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/signals/threat_mapping/build_threat_mapping_filter.mock.ts index e39b78b4f4a4..f49e3dec9360 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/signals/threat_mapping/build_threat_mapping_filter.mock.ts +++ b/x-pack/plugins/security_solution/server/lib/detection_engine/signals/threat_mapping/build_threat_mapping_filter.mock.ts @@ -5,7 +5,7 @@ * 2.0. */ import type { estypes } from '@elastic/elasticsearch'; -import { ThreatMapping } from '../../../../../common/detection_engine/schemas/types/threat_mapping'; +import { ThreatMapping } from '@kbn/securitysolution-io-ts-alerting-types'; import { Filter } from 'src/plugins/data/common'; import { ThreatListDoc, ThreatListItem } from './types'; diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/signals/threat_mapping/build_threat_mapping_filter.test.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/signals/threat_mapping/build_threat_mapping_filter.test.ts index 1c0300ee0cc7..a96eb50af3c5 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/signals/threat_mapping/build_threat_mapping_filter.test.ts +++ b/x-pack/plugins/security_solution/server/lib/detection_engine/signals/threat_mapping/build_threat_mapping_filter.test.ts @@ -5,10 +5,7 @@ * 2.0. */ -import { - ThreatMapping, - ThreatMappingEntries, -} from '../../../../../common/detection_engine/schemas/types/threat_mapping'; +import { ThreatMapping, ThreatMappingEntries } from '@kbn/securitysolution-io-ts-alerting-types'; import { filterThreatMapping, diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/signals/threat_mapping/build_threat_mapping_filter.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/signals/threat_mapping/build_threat_mapping_filter.ts index 18204bb678a4..22e21ef40cb3 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/signals/threat_mapping/build_threat_mapping_filter.ts +++ b/x-pack/plugins/security_solution/server/lib/detection_engine/signals/threat_mapping/build_threat_mapping_filter.ts @@ -7,7 +7,7 @@ import get from 'lodash/fp/get'; import { Filter } from 'src/plugins/data/common'; -import { ThreatMapping } from '../../../../../common/detection_engine/schemas/types/threat_mapping'; +import { ThreatMapping } from '@kbn/securitysolution-io-ts-alerting-types'; import { BooleanFilter, BuildEntriesMappingFilterOptions, diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/signals/threat_mapping/types.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/signals/threat_mapping/types.ts index 360fb118faa8..82fc0dd3abd0 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/signals/threat_mapping/types.ts +++ b/x-pack/plugins/security_solution/server/lib/detection_engine/signals/threat_mapping/types.ts @@ -5,11 +5,6 @@ * 2.0. */ import type { estypes } from '@elastic/elasticsearch'; -import { ListClient } from '../../../../../../lists/server'; -import { - Type, - LanguageOrUndefined, -} from '../../../../../common/detection_engine/schemas/common/schemas'; import { ThreatQuery, ThreatMapping, @@ -19,7 +14,10 @@ import { ConcurrentSearches, ItemsPerSearch, ThreatIndicatorPathOrUndefined, -} from '../../../../../common/detection_engine/schemas/types/threat_mapping'; + LanguageOrUndefined, + Type, +} from '@kbn/securitysolution-io-ts-alerting-types'; +import { ListClient } from '../../../../../../lists/server'; import { AlertInstanceContext, AlertInstanceState, diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/signals/utils.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/signals/utils.ts index bd37cf62c74b..c2e3fe83b889 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/signals/utils.ts +++ b/x-pack/plugins/security_solution/server/lib/detection_engine/signals/utils.ts @@ -14,6 +14,7 @@ import { isEmpty, partition } from 'lodash'; import { ApiResponse, Context } from '@elastic/elasticsearch/lib/Transport'; import { SortResults } from '@elastic/elasticsearch/api/types'; +import { ListArray } from '@kbn/securitysolution-io-ts-list-types'; import { TimestampOverrideOrUndefined, Privilege, @@ -27,7 +28,6 @@ import { } from '../../../../../alerting/server'; import { ExceptionListClient, ListClient, ListPluginSetup } from '../../../../../lists/server'; import { ExceptionListItemSchema } from '../../../../../lists/common/schemas'; -import { ListArray } from '../../../../common/detection_engine/schemas/types/lists'; import { BulkResponseErrorAggregation, SignalHit, diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/types.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/types.ts index 85c8483a0b98..03ec7928115b 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/types.ts +++ b/x-pack/plugins/security_solution/server/lib/detection_engine/types.ts @@ -6,41 +6,10 @@ */ import { - AnomalyThresholdOrUndefined, - Description, - NoteOrUndefined, - ThreatsOrUndefined, - ThresholdOrUndefined, - FalsePositives, From, - Immutable, - IndexOrUndefined, - LanguageOrUndefined, - MaxSignals, MachineLearningJobIdOrUndefined, RiskScore, - OutputIndex, - QueryOrUndefined, - References, - SavedIdOrUndefined, - Severity, - To, - TimelineIdOrUndefined, - TimelineTitleOrUndefined, - Version, - MetaOrUndefined, - RuleId, - AuthorOrUndefined, - BuildingBlockTypeOrUndefined, - LicenseOrUndefined, RiskScoreMappingOrUndefined, - RuleNameOverrideOrUndefined, - SeverityMappingOrUndefined, - TimestampOverrideOrUndefined, - Type, - EventCategoryOverrideOrUndefined, -} from '../../../common/detection_engine/schemas/common/schemas'; -import { ThreatIndexOrUndefined, ThreatQueryOrUndefined, ThreatMappingOrUndefined, @@ -48,11 +17,43 @@ import { ConcurrentSearchesOrUndefined, ItemsPerSearchOrUndefined, ThreatIndicatorPathOrUndefined, -} from '../../../common/detection_engine/schemas/types/threat_mapping'; + ThreatsOrUndefined, + Type, + LanguageOrUndefined, + Severity, + SeverityMappingOrUndefined, + MaxSignals, +} from '@kbn/securitysolution-io-ts-alerting-types'; +import { Version } from '@kbn/securitysolution-io-ts-types'; + +import { ListArrayOrUndefined } from '@kbn/securitysolution-io-ts-list-types'; +import { + AnomalyThresholdOrUndefined, + Description, + NoteOrUndefined, + ThresholdOrUndefined, + FalsePositives, + Immutable, + IndexOrUndefined, + OutputIndex, + QueryOrUndefined, + References, + SavedIdOrUndefined, + To, + TimelineIdOrUndefined, + TimelineTitleOrUndefined, + MetaOrUndefined, + RuleId, + AuthorOrUndefined, + BuildingBlockTypeOrUndefined, + LicenseOrUndefined, + RuleNameOverrideOrUndefined, + TimestampOverrideOrUndefined, + EventCategoryOverrideOrUndefined, +} from '../../../common/detection_engine/schemas/common/schemas'; import { LegacyCallAPIOptions } from '../../../../../../src/core/server'; import { Filter } from '../../../../../../src/plugins/data/server'; -import { ListArrayOrUndefined } from '../../../common/detection_engine/schemas/types'; import { AlertTypeParams } from '../../../../alerting/common'; export type PartialFilter = Partial; diff --git a/x-pack/plugins/security_solution/server/lib/machine_learning/authz.ts b/x-pack/plugins/security_solution/server/lib/machine_learning/authz.ts index 85c1eea7a957..d5e8e951397c 100644 --- a/x-pack/plugins/security_solution/server/lib/machine_learning/authz.ts +++ b/x-pack/plugins/security_solution/server/lib/machine_learning/authz.ts @@ -7,6 +7,7 @@ import { i18n } from '@kbn/i18n'; +import { Type } from '@kbn/securitysolution-io-ts-alerting-types'; import { KibanaRequest, SavedObjectsClientContract } from '../../../../../../src/core/server/'; import { ILicense } from '../../../../licensing/server'; import { MlPluginSetup } from '../../../../ml/server'; @@ -16,8 +17,6 @@ import { hasMlAdminPermissions } from '../../../common/machine_learning/has_ml_a import { isMlRule } from '../../../common/machine_learning/helpers'; import { Validation } from './validation'; import { cache } from './cache'; -import { Type } from '../../../common/detection_engine/schemas/common/schemas'; - export interface MlAuthz { validateRuleType: (type: Type) => Promise; } diff --git a/x-pack/plugins/security_solution/server/lib/timeline/routes/draft_timelines/clean_draft_timelines/index.ts b/x-pack/plugins/security_solution/server/lib/timeline/routes/draft_timelines/clean_draft_timelines/index.ts index 113860f369f7..62770408af2f 100644 --- a/x-pack/plugins/security_solution/server/lib/timeline/routes/draft_timelines/clean_draft_timelines/index.ts +++ b/x-pack/plugins/security_solution/server/lib/timeline/routes/draft_timelines/clean_draft_timelines/index.ts @@ -6,9 +6,11 @@ */ import uuid from 'uuid'; +import { transformError } from '@kbn/securitysolution-es-utils'; import type { SecuritySolutionPluginRouter } from '../../../../../types'; import { ConfigType } from '../../../../..'; -import { transformError, buildSiemResponse } from '../../../../detection_engine/routes/utils'; +import { buildSiemResponse } from '../../../../detection_engine/routes/utils'; + import { TIMELINE_DRAFT_URL } from '../../../../../../common/constants'; import { buildFrameworkRequest } from '../../../utils/common'; import { SetupPlugins } from '../../../../../plugin'; diff --git a/x-pack/plugins/security_solution/server/lib/timeline/routes/draft_timelines/get_draft_timelines/index.ts b/x-pack/plugins/security_solution/server/lib/timeline/routes/draft_timelines/get_draft_timelines/index.ts index f3f813ace411..cd7770dcd5b4 100644 --- a/x-pack/plugins/security_solution/server/lib/timeline/routes/draft_timelines/get_draft_timelines/index.ts +++ b/x-pack/plugins/security_solution/server/lib/timeline/routes/draft_timelines/get_draft_timelines/index.ts @@ -5,9 +5,11 @@ * 2.0. */ +import { transformError } from '@kbn/securitysolution-es-utils'; import type { SecuritySolutionPluginRouter } from '../../../../../types'; import { ConfigType } from '../../../../..'; -import { transformError, buildSiemResponse } from '../../../../detection_engine/routes/utils'; +import { buildSiemResponse } from '../../../../detection_engine/routes/utils'; + import { TIMELINE_DRAFT_URL } from '../../../../../../common/constants'; import { buildFrameworkRequest } from '../../../utils/common'; import { SetupPlugins } from '../../../../../plugin'; diff --git a/x-pack/plugins/security_solution/server/lib/timeline/routes/notes/persist_note.ts b/x-pack/plugins/security_solution/server/lib/timeline/routes/notes/persist_note.ts index cb7d984ade40..32fd87f39620 100644 --- a/x-pack/plugins/security_solution/server/lib/timeline/routes/notes/persist_note.ts +++ b/x-pack/plugins/security_solution/server/lib/timeline/routes/notes/persist_note.ts @@ -5,6 +5,7 @@ * 2.0. */ +import { transformError } from '@kbn/securitysolution-es-utils'; import type { SecuritySolutionPluginRouter } from '../../../../types'; import { NOTE_URL } from '../../../../../common/constants'; @@ -13,7 +14,7 @@ import { SetupPlugins } from '../../../../plugin'; import { buildRouteValidationWithExcess } from '../../../../utils/build_validation/route_validation'; import { ConfigType } from '../../../..'; -import { transformError, buildSiemResponse } from '../../../detection_engine/routes/utils'; +import { buildSiemResponse } from '../../../detection_engine/routes/utils'; import { buildFrameworkRequest } from '../../utils/common'; import { persistNoteSchema } from '../../schemas/notes'; diff --git a/x-pack/plugins/security_solution/server/lib/timeline/routes/pinned_events/persist_pinned_event.ts b/x-pack/plugins/security_solution/server/lib/timeline/routes/pinned_events/persist_pinned_event.ts index 53ac002721c6..ee407468f0c3 100644 --- a/x-pack/plugins/security_solution/server/lib/timeline/routes/pinned_events/persist_pinned_event.ts +++ b/x-pack/plugins/security_solution/server/lib/timeline/routes/pinned_events/persist_pinned_event.ts @@ -5,6 +5,7 @@ * 2.0. */ +import { transformError } from '@kbn/securitysolution-es-utils'; import type { SecuritySolutionPluginRouter } from '../../../../types'; import { PINNED_EVENT_URL } from '../../../../../common/constants'; @@ -13,7 +14,7 @@ import { SetupPlugins } from '../../../../plugin'; import { buildRouteValidationWithExcess } from '../../../../utils/build_validation/route_validation'; import { ConfigType } from '../../../..'; -import { transformError, buildSiemResponse } from '../../../detection_engine/routes/utils'; +import { buildSiemResponse } from '../../../detection_engine/routes/utils'; import { buildFrameworkRequest } from '../../utils/common'; import { persistPinnedEventSchema } from '../../schemas/pinned_events'; diff --git a/x-pack/plugins/security_solution/server/lib/timeline/routes/prepackaged_timelines/install_prepackaged_timelines/index.ts b/x-pack/plugins/security_solution/server/lib/timeline/routes/prepackaged_timelines/install_prepackaged_timelines/index.ts index bb447948df24..438ce71edd08 100644 --- a/x-pack/plugins/security_solution/server/lib/timeline/routes/prepackaged_timelines/install_prepackaged_timelines/index.ts +++ b/x-pack/plugins/security_solution/server/lib/timeline/routes/prepackaged_timelines/install_prepackaged_timelines/index.ts @@ -5,15 +5,16 @@ * 2.0. */ +import { transformError } from '@kbn/securitysolution-es-utils'; +import { validate } from '@kbn/securitysolution-io-ts-utils'; import type { SecuritySolutionPluginRouter } from '../../../../../types'; import { TIMELINE_PREPACKAGED_URL } from '../../../../../../common/constants'; import { SetupPlugins } from '../../../../../plugin'; import { ConfigType } from '../../../../../config'; -import { validate } from '../../../../../../common/validate'; -import { buildSiemResponse, transformError } from '../../../../detection_engine/routes/utils'; +import { buildSiemResponse } from '../../../../detection_engine/routes/utils'; import { installPrepackagedTimelines } from './helpers'; diff --git a/x-pack/plugins/security_solution/server/lib/timeline/routes/timelines/create_timelines/index.ts b/x-pack/plugins/security_solution/server/lib/timeline/routes/timelines/create_timelines/index.ts index f35ddf1a76c7..432a441e61e0 100644 --- a/x-pack/plugins/security_solution/server/lib/timeline/routes/timelines/create_timelines/index.ts +++ b/x-pack/plugins/security_solution/server/lib/timeline/routes/timelines/create_timelines/index.ts @@ -5,6 +5,7 @@ * 2.0. */ +import { transformError } from '@kbn/securitysolution-es-utils'; import type { SecuritySolutionPluginRouter } from '../../../../../types'; import { TIMELINE_URL } from '../../../../../../common/constants'; @@ -13,7 +14,7 @@ import { ConfigType } from '../../../../..'; import { SetupPlugins } from '../../../../../plugin'; import { buildRouteValidationWithExcess } from '../../../../../utils/build_validation/route_validation'; -import { transformError, buildSiemResponse } from '../../../../detection_engine/routes/utils'; +import { buildSiemResponse } from '../../../../detection_engine/routes/utils'; import { createTimelineSchema } from '../../../schemas/timelines'; import { diff --git a/x-pack/plugins/security_solution/server/lib/timeline/routes/timelines/delete_timelines/index.ts b/x-pack/plugins/security_solution/server/lib/timeline/routes/timelines/delete_timelines/index.ts index 7617881b90b7..13fbc22aba5d 100644 --- a/x-pack/plugins/security_solution/server/lib/timeline/routes/timelines/delete_timelines/index.ts +++ b/x-pack/plugins/security_solution/server/lib/timeline/routes/timelines/delete_timelines/index.ts @@ -5,13 +5,15 @@ * 2.0. */ +import { transformError } from '@kbn/securitysolution-es-utils'; import { buildRouteValidationWithExcess } from '../../../../../utils/build_validation/route_validation'; import { ConfigType } from '../../../../..'; import { deleteTimelinesSchema } from '../../../schemas/timelines/delete_timelines_schema'; import { SecuritySolutionPluginRouter } from '../../../../../types'; import { SetupPlugins } from '../../../../../plugin'; import { TIMELINE_URL } from '../../../../../../common/constants'; -import { transformError, buildSiemResponse } from '../../../../detection_engine/routes/utils'; +import { buildSiemResponse } from '../../../../detection_engine/routes/utils'; + import { buildFrameworkRequest } from '../../../utils/common'; import { deleteTimeline } from '../../../saved_object/timelines'; diff --git a/x-pack/plugins/security_solution/server/lib/timeline/routes/timelines/export_timelines/index.ts b/x-pack/plugins/security_solution/server/lib/timeline/routes/timelines/export_timelines/index.ts index 9e1eabc4450b..0d60129b1fcd 100644 --- a/x-pack/plugins/security_solution/server/lib/timeline/routes/timelines/export_timelines/index.ts +++ b/x-pack/plugins/security_solution/server/lib/timeline/routes/timelines/export_timelines/index.ts @@ -5,10 +5,11 @@ * 2.0. */ +import { transformError } from '@kbn/securitysolution-es-utils'; import { TIMELINE_EXPORT_URL } from '../../../../../../common/constants'; import type { SecuritySolutionPluginRouter } from '../../../../../types'; import { ConfigType } from '../../../../../config'; -import { transformError, buildSiemResponse } from '../../../../detection_engine/routes/utils'; +import { buildSiemResponse } from '../../../../detection_engine/routes/utils'; import { exportTimelinesQuerySchema, diff --git a/x-pack/plugins/security_solution/server/lib/timeline/routes/timelines/get_timeline/index.ts b/x-pack/plugins/security_solution/server/lib/timeline/routes/timelines/get_timeline/index.ts index 8d94cd2ef2cc..921ae2352a56 100644 --- a/x-pack/plugins/security_solution/server/lib/timeline/routes/timelines/get_timeline/index.ts +++ b/x-pack/plugins/security_solution/server/lib/timeline/routes/timelines/get_timeline/index.ts @@ -5,6 +5,7 @@ * 2.0. */ +import { transformError } from '@kbn/securitysolution-es-utils'; import type { SecuritySolutionPluginRouter } from '../../../../../types'; import { TIMELINE_URL } from '../../../../../../common/constants'; @@ -13,7 +14,7 @@ import { ConfigType } from '../../../../..'; import { SetupPlugins } from '../../../../../plugin'; import { buildRouteValidationWithExcess } from '../../../../../utils/build_validation/route_validation'; -import { buildSiemResponse, transformError } from '../../../../detection_engine/routes/utils'; +import { buildSiemResponse } from '../../../../detection_engine/routes/utils'; import { buildFrameworkRequest } from '../../../utils/common'; import { getTimelineQuerySchema } from '../../../schemas/timelines'; diff --git a/x-pack/plugins/security_solution/server/lib/timeline/routes/timelines/get_timelines/index.ts b/x-pack/plugins/security_solution/server/lib/timeline/routes/timelines/get_timelines/index.ts index 51a02db681b0..459991609261 100644 --- a/x-pack/plugins/security_solution/server/lib/timeline/routes/timelines/get_timelines/index.ts +++ b/x-pack/plugins/security_solution/server/lib/timeline/routes/timelines/get_timelines/index.ts @@ -10,13 +10,14 @@ import { pipe } from 'fp-ts/lib/pipeable'; import { fold } from 'fp-ts/lib/Either'; import { identity } from 'fp-ts/lib/function'; +import { transformError } from '@kbn/securitysolution-es-utils'; import type { SecuritySolutionPluginRouter } from '../../../../../types'; import { TIMELINES_URL } from '../../../../../../common/constants'; import { ConfigType } from '../../../../..'; import { SetupPlugins } from '../../../../../plugin'; -import { buildSiemResponse, transformError } from '../../../../detection_engine/routes/utils'; +import { buildSiemResponse } from '../../../../detection_engine/routes/utils'; import { buildFrameworkRequest, escapeHatch, throwErrors } from '../../../utils/common'; import { getAllTimeline } from '../../../saved_object/timelines'; diff --git a/x-pack/plugins/security_solution/server/lib/timeline/routes/timelines/import_timelines/create_timelines_stream_from_ndjson.ts b/x-pack/plugins/security_solution/server/lib/timeline/routes/timelines/import_timelines/create_timelines_stream_from_ndjson.ts index aeb7463377b1..d016fe8a24ff 100644 --- a/x-pack/plugins/security_solution/server/lib/timeline/routes/timelines/import_timelines/create_timelines_stream_from_ndjson.ts +++ b/x-pack/plugins/security_solution/server/lib/timeline/routes/timelines/import_timelines/create_timelines_stream_from_ndjson.ts @@ -11,6 +11,7 @@ import { pipe } from 'fp-ts/lib/pipeable'; import { fold } from 'fp-ts/lib/Either'; import { identity } from 'fp-ts/lib/function'; import { createConcatStream, createSplitStream, createMapStream } from '@kbn/utils'; +import { BadRequestError } from '@kbn/securitysolution-es-utils'; import { parseNdjsonStrings, filterExportedCounts, @@ -19,7 +20,6 @@ import { import { ImportTimelineResponse } from './types'; import { ImportTimelinesSchemaRt } from '../../../schemas/timelines/import_timelines_schema'; -import { BadRequestError } from '../../../../detection_engine/errors/bad_request_error'; import { throwErrors } from '../../../utils/common'; type ErrorFactory = (message: string) => Error; diff --git a/x-pack/plugins/security_solution/server/lib/timeline/routes/timelines/import_timelines/helpers.ts b/x-pack/plugins/security_solution/server/lib/timeline/routes/timelines/import_timelines/helpers.ts index a19276652e78..70d93d7552b1 100644 --- a/x-pack/plugins/security_solution/server/lib/timeline/routes/timelines/import_timelines/helpers.ts +++ b/x-pack/plugins/security_solution/server/lib/timeline/routes/timelines/import_timelines/helpers.ts @@ -10,12 +10,12 @@ import { Readable } from 'stream'; import uuid from 'uuid'; import { createPromiseFromStreams } from '@kbn/utils'; +import { validate } from '@kbn/securitysolution-io-ts-utils'; import { ImportTimelineResultSchema, importTimelineResultSchema, TimelineStatus, } from '../../../../../../common/types/timeline'; -import { validate } from '../../../../../../common/validate'; import { createBulkErrorObject, BulkError } from '../../../../detection_engine/routes/utils'; diff --git a/x-pack/plugins/security_solution/server/lib/timeline/routes/timelines/import_timelines/index.ts b/x-pack/plugins/security_solution/server/lib/timeline/routes/timelines/import_timelines/index.ts index 603aad16dd9c..65ffd10c5168 100644 --- a/x-pack/plugins/security_solution/server/lib/timeline/routes/timelines/import_timelines/index.ts +++ b/x-pack/plugins/security_solution/server/lib/timeline/routes/timelines/import_timelines/index.ts @@ -8,6 +8,7 @@ import { extname } from 'path'; import { Readable } from 'stream'; +import { transformError } from '@kbn/securitysolution-es-utils'; import type { SecuritySolutionPluginRouter } from '../../../../../types'; import { TIMELINE_IMPORT_URL } from '../../../../../../common/constants'; @@ -15,7 +16,7 @@ import { TIMELINE_IMPORT_URL } from '../../../../../../common/constants'; import { SetupPlugins } from '../../../../../plugin'; import { ConfigType } from '../../../../../config'; import { buildRouteValidationWithExcess } from '../../../../../utils/build_validation/route_validation'; -import { buildSiemResponse, transformError } from '../../../../detection_engine/routes/utils'; +import { buildSiemResponse } from '../../../../detection_engine/routes/utils'; import { importTimelines } from './helpers'; import { ImportTimelinesPayloadSchemaRt } from '../../../schemas/timelines/import_timelines_schema'; diff --git a/x-pack/plugins/security_solution/server/lib/timeline/routes/timelines/patch_timelines/index.ts b/x-pack/plugins/security_solution/server/lib/timeline/routes/timelines/patch_timelines/index.ts index b0142625f5e0..e3ad9bc7cb04 100644 --- a/x-pack/plugins/security_solution/server/lib/timeline/routes/timelines/patch_timelines/index.ts +++ b/x-pack/plugins/security_solution/server/lib/timeline/routes/timelines/patch_timelines/index.ts @@ -5,6 +5,7 @@ * 2.0. */ +import { transformError } from '@kbn/securitysolution-es-utils'; import type { SecuritySolutionPluginRouter } from '../../../../../types'; import { TIMELINE_URL } from '../../../../../../common/constants'; @@ -13,7 +14,7 @@ import { SetupPlugins } from '../../../../../plugin'; import { buildRouteValidationWithExcess } from '../../../../../utils/build_validation/route_validation'; import { ConfigType } from '../../../../..'; -import { transformError, buildSiemResponse } from '../../../../detection_engine/routes/utils'; +import { buildSiemResponse } from '../../../../detection_engine/routes/utils'; import { patchTimelineSchema } from '../../../schemas/timelines/patch_timelines_schema'; import { buildFrameworkRequest, TimelineStatusActions } from '../../../utils/common'; diff --git a/x-pack/plugins/security_solution/server/lib/timeline/routes/timelines/persist_favorite/index.ts b/x-pack/plugins/security_solution/server/lib/timeline/routes/timelines/persist_favorite/index.ts index 2cc388869624..0de64171e0fb 100644 --- a/x-pack/plugins/security_solution/server/lib/timeline/routes/timelines/persist_favorite/index.ts +++ b/x-pack/plugins/security_solution/server/lib/timeline/routes/timelines/persist_favorite/index.ts @@ -5,6 +5,7 @@ * 2.0. */ +import { transformError } from '@kbn/securitysolution-es-utils'; import type { SecuritySolutionPluginRouter } from '../../../../../types'; import { TIMELINE_FAVORITE_URL } from '../../../../../../common/constants'; @@ -13,7 +14,7 @@ import { SetupPlugins } from '../../../../../plugin'; import { buildRouteValidationWithExcess } from '../../../../../utils/build_validation/route_validation'; import { ConfigType } from '../../../../..'; -import { transformError, buildSiemResponse } from '../../../../detection_engine/routes/utils'; +import { buildSiemResponse } from '../../../../detection_engine/routes/utils'; import { buildFrameworkRequest } from '../../../utils/common'; import { persistFavorite } from '../../../saved_object/timelines'; diff --git a/x-pack/plugins/security_solution/server/lib/timeline/utils/common.ts b/x-pack/plugins/security_solution/server/lib/timeline/utils/common.ts index c4ddefd925b3..be086732ddcd 100644 --- a/x-pack/plugins/security_solution/server/lib/timeline/utils/common.ts +++ b/x-pack/plugins/security_solution/server/lib/timeline/utils/common.ts @@ -11,9 +11,9 @@ import fs from 'fs'; import { Readable } from 'stream'; import { createListStream } from '@kbn/utils'; import { schema } from '@kbn/config-schema'; -import { isObject } from 'lodash/fp'; import { KibanaRequest } from 'src/core/server'; +import { formatErrors } from '@kbn/securitysolution-io-ts-utils'; import { SetupPlugins, StartPlugins } from '../../../plugin'; import type { SecuritySolutionRequestHandlerContext } from '../../../types'; @@ -40,32 +40,6 @@ export const buildFrameworkRequest = async ( export const escapeHatch = schema.object({}, { unknowns: 'allow' }); -/** - * @deprecated Use packages/kbn-securitysolution-io-ts-utils/src/format_errors/index.ts - */ -export const formatErrors = (errors: rt.Errors): string[] => { - const err = errors.map((error) => { - if (error.message != null) { - return error.message; - } else { - const keyContext = error.context - .filter( - (entry) => entry.key != null && !Number.isInteger(+entry.key) && entry.key.trim() !== '' - ) - .map((entry) => entry.key) - .join(','); - - const nameContext = error.context.find((entry) => entry.type?.name?.length > 0); - const suppliedValue = - keyContext !== '' ? keyContext : nameContext != null ? nameContext.type.name : ''; - const value = isObject(error.value) ? JSON.stringify(error.value) : error.value; - return `Invalid value "${value}" supplied to "${suppliedValue}"`; - } - }); - - return [...new Set(err)]; -}; - type ErrorFactory = (message: string) => Error; export const throwErrors = (createError: ErrorFactory) => (errors: rt.Errors) => { diff --git a/x-pack/plugins/security_solution/server/utils/build_validation/route_validation.ts b/x-pack/plugins/security_solution/server/utils/build_validation/route_validation.ts index caba0eb9f015..5dfa74c14bf7 100644 --- a/x-pack/plugins/security_solution/server/utils/build_validation/route_validation.ts +++ b/x-pack/plugins/security_solution/server/utils/build_validation/route_validation.ts @@ -8,8 +8,7 @@ import { fold } from 'fp-ts/lib/Either'; import { pipe } from 'fp-ts/lib/pipeable'; import * as rt from 'io-ts'; -import { formatErrors } from '../../../common/format_errors'; -import { exactCheck } from '../../../common/exact_check'; +import { exactCheck, formatErrors } from '@kbn/securitysolution-io-ts-utils'; import { RouteValidationFunction, RouteValidationResultFactory, diff --git a/x-pack/plugins/security_solution/server/utils/read_stream/create_stream_from_ndjson.ts b/x-pack/plugins/security_solution/server/utils/read_stream/create_stream_from_ndjson.ts index 02749cf09369..b0b70aeb3ea3 100644 --- a/x-pack/plugins/security_solution/server/utils/read_stream/create_stream_from_ndjson.ts +++ b/x-pack/plugins/security_solution/server/utils/read_stream/create_stream_from_ndjson.ts @@ -12,15 +12,14 @@ import { fold } from 'fp-ts/lib/Either'; import * as t from 'io-ts'; import { createMapStream, createFilterStream } from '@kbn/utils'; -import { formatErrors } from '../../../common/format_errors'; +import { exactCheck, formatErrors } from '@kbn/securitysolution-io-ts-utils'; +import { BadRequestError } from '@kbn/securitysolution-es-utils'; import { importRuleValidateTypeDependents } from '../../../common/detection_engine/schemas/request/import_rules_type_dependents'; import { ImportRulesSchemaDecoded, importRulesSchema, ImportRulesSchema, } from '../../../common/detection_engine/schemas/request/import_rules_schema'; -import { exactCheck } from '../../../common/exact_check'; -import { BadRequestError } from '../../lib/detection_engine/errors/bad_request_error'; export interface RulesObjectsExportResultDetails { /** number of successfully exported objects */ diff --git a/x-pack/test/detection_engine_api_integration/utils.ts b/x-pack/test/detection_engine_api_integration/utils.ts index 0f57728f99d6..d8466f013a11 100644 --- a/x-pack/test/detection_engine_api_integration/utils.ts +++ b/x-pack/test/detection_engine_api_integration/utils.ts @@ -12,8 +12,8 @@ import { SuperTest } from 'supertest'; import supertestAsPromised from 'supertest-as-promised'; import { Context } from '@elastic/elasticsearch/lib/Transport'; import { SearchResponse } from 'elasticsearch'; +import { NonEmptyEntriesArray } from '@kbn/securitysolution-io-ts-list-types'; import { PrePackagedRulesAndTimelinesStatusSchema } from '../../plugins/security_solution/common/detection_engine/schemas/response'; -import { NonEmptyEntriesArray } from '../../plugins/lists/common/schemas'; import { getCreateExceptionListDetectionSchemaMock } from '../../plugins/lists/common/schemas/request/create_exception_list_schema.mock'; import { CreateRulesSchema, diff --git a/x-pack/test/lists_api_integration/utils.ts b/x-pack/test/lists_api_integration/utils.ts index 0512cede0a84..29846a79d6b0 100644 --- a/x-pack/test/lists_api_integration/utils.ts +++ b/x-pack/test/lists_api_integration/utils.ts @@ -9,12 +9,12 @@ import { SuperTest } from 'supertest'; import supertestAsPromised from 'supertest-as-promised'; import type { KibanaClient } from '@elastic/elasticsearch/api/kibana'; +import { Type } from '@kbn/securitysolution-io-ts-list-types'; import { getImportListItemAsBuffer } from '../../plugins/lists/common/schemas/request/import_list_item_schema.mock'; import { ListItemSchema, ExceptionListSchema, ExceptionListItemSchema, - Type, } from '../../plugins/lists/common/schemas'; import { ListSchema } from '../../plugins/lists/common'; import { LIST_INDEX, LIST_ITEM_URL } from '../../plugins/lists/common/constants';