diff --git a/x-pack/plugins/security_solution/common/api/timeline/model/api.ts b/x-pack/plugins/security_solution/common/api/timeline/model/api.ts index 9780f872e3b48..fcf21c0de0639 100644 --- a/x-pack/plugins/security_solution/common/api/timeline/model/api.ts +++ b/x-pack/plugins/security_solution/common/api/timeline/model/api.ts @@ -5,19 +5,21 @@ * 2.0. */ -import type { Maybe } from '../../../search_strategy'; import type { DataProviderType } from './components.gen'; import { BareNote, BarePinnedEvent, + ColumnHeaderResult, DataProviderTypeEnum, + DataProviderResult, FavoriteTimelineResponse, - type FavoriteTimelineResult, + FilterTimelineResult, ImportTimelineResult, ImportTimelines, type Note, PinnedEvent, PersistTimelineResponse, + QueryMatchResult, ResolvedTimeline, RowRendererId, RowRendererIdEnum, @@ -41,14 +43,18 @@ import { export { BareNote, BarePinnedEvent, + ColumnHeaderResult, + DataProviderResult, DataProviderType, DataProviderTypeEnum, FavoriteTimelineResponse, + FilterTimelineResult, ImportTimelineResult, ImportTimelines, Note, PinnedEvent, PersistTimelineResponse, + QueryMatchResult, ResolvedTimeline, RowRendererId, RowRendererIdEnum, @@ -92,11 +98,6 @@ export interface ExportedNotes { globalNotes: ExportedGlobalNotes; } -export type ExportedTimelines = SavedTimeline & - ExportedNotes & { - pinnedEventIds: string[]; - }; - export interface ExportTimelineNotFoundError { statusCode: number; message: string; @@ -107,134 +108,6 @@ export interface PageInfoTimeline { pageSize: number; } -export interface ColumnHeaderResult { - aggregatable?: Maybe; - category?: Maybe; - columnHeaderType?: Maybe; - description?: Maybe; - example?: Maybe; - indexes?: Maybe; - id?: Maybe; - name?: Maybe; - placeholder?: Maybe; - searchable?: Maybe; - type?: Maybe; -} - -export interface DataProviderResult { - id?: Maybe; - name?: Maybe; - enabled?: Maybe; - excluded?: Maybe; - kqlQuery?: Maybe; - queryMatch?: Maybe; - type?: Maybe; - and?: Maybe; -} - -export interface QueryMatchResult { - field?: Maybe; - displayField?: Maybe; - value?: Maybe; - displayValue?: Maybe; - operator?: Maybe; -} - -export interface DateRangePickerResult { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - start?: Maybe; - // eslint-disable-next-line @typescript-eslint/no-explicit-any - end?: Maybe; -} - -export interface EqlOptionsResult { - eventCategoryField?: Maybe; - tiebreakerField?: Maybe; - timestampField?: Maybe; - query?: Maybe; - // eslint-disable-next-line @typescript-eslint/no-explicit-any - size?: Maybe; -} - -export interface FilterTimelineResult { - exists?: Maybe; - meta?: Maybe; - match_all?: Maybe; - missing?: Maybe; - query?: Maybe; - range?: Maybe; - script?: Maybe; -} - -export interface FilterMetaTimelineResult { - alias?: Maybe; - controlledBy?: Maybe; - disabled?: Maybe; - field?: Maybe; - formattedValue?: Maybe; - index?: Maybe; - key?: Maybe; - negate?: Maybe; - params?: Maybe; - type?: Maybe; - value?: Maybe; -} - -export interface SerializedFilterQueryResult { - filterQuery?: Maybe; -} - -export interface KueryFilterQueryResult { - kind?: Maybe; - expression?: Maybe; -} - -export interface SerializedKueryQueryResult { - kuery?: Maybe; - serializedQuery?: Maybe; -} - -export interface TimelineResult { - columns?: Maybe; - created?: Maybe; - createdBy?: Maybe; - dataProviders?: Maybe; - dataViewId?: Maybe; - dateRange?: Maybe; - description?: Maybe; - eqlOptions?: Maybe; - eventIdToNoteIds?: Maybe; - eventType?: Maybe; - excludedRowRendererIds?: Maybe; - favorite?: Maybe; - filters?: Maybe; - kqlMode?: Maybe; - kqlQuery?: Maybe; - indexNames?: Maybe; - notes?: Maybe; - noteIds?: Maybe; - pinnedEventIds?: Maybe; - pinnedEventsSaveObject?: Maybe; - savedQueryId?: Maybe; - savedObjectId: string; - sort?: Maybe; - status?: Maybe; - title?: Maybe; - templateTimelineId?: Maybe; - templateTimelineVersion?: Maybe; - timelineType?: Maybe; - updated?: Maybe; - updatedBy?: Maybe; - version: string; - savedSearchId?: Maybe; -} - -export interface ResponseTimeline { - code?: Maybe; - message?: Maybe; - timeline: TimelineResult; -} - export interface SortTimeline { sortField: SortFieldTimeline; sortOrder: SortDirection; diff --git a/x-pack/plugins/security_solution/common/api/timeline/model/components.gen.ts b/x-pack/plugins/security_solution/common/api/timeline/model/components.gen.ts index c8d966aad9934..93d627f53263b 100644 --- a/x-pack/plugins/security_solution/common/api/timeline/model/components.gen.ts +++ b/x-pack/plugins/security_solution/common/api/timeline/model/components.gen.ts @@ -413,12 +413,3 @@ export const TimelineErrorResponse = z.union([ statusCode: z.number(), }), ]); - -export type ExportedTimelines = z.infer; -export const ExportedTimelines = SavedTimeline.merge( - z.object({ - globalNotes: z.array(Note).optional(), - eventNotes: z.array(Note).optional(), - pinnedEventIds: z.array(z.string()).optional(), - }) -); diff --git a/x-pack/plugins/security_solution/common/api/timeline/model/components.schema.yaml b/x-pack/plugins/security_solution/common/api/timeline/model/components.schema.yaml index 1335062586e06..568eec1975769 100644 --- a/x-pack/plugins/security_solution/common/api/timeline/model/components.schema.yaml +++ b/x-pack/plugins/security_solution/common/api/timeline/model/components.schema.yaml @@ -732,21 +732,3 @@ components: type: string statusCode: type: number - - ExportedTimelines: - allOf: - - $ref: '#/components/schemas/SavedTimeline' - - type: object - properties: - globalNotes: - type: array - items: - $ref: '#/components/schemas/Note' - eventNotes: - type: array - items: - $ref: '#/components/schemas/Note' - pinnedEventIds: - type: array - items: - type: string diff --git a/x-pack/plugins/security_solution/public/common/mock/timeline_results.ts b/x-pack/plugins/security_solution/public/common/mock/timeline_results.ts index a97be122e8a6a..d32891333c7f0 100644 --- a/x-pack/plugins/security_solution/public/common/mock/timeline_results.ts +++ b/x-pack/plugins/security_solution/public/common/mock/timeline_results.ts @@ -9,8 +9,8 @@ import { FilterStateStore } from '@kbn/es-query'; import type { DataTableModel } from '@kbn/securitysolution-data-table'; import { VIEW_SELECTION } from '../../../common/constants'; -import type { TimelineResult } from '../../../common/api/timeline'; import { TimelineId, TimelineTabs } from '../../../common/types/timeline'; +import type { TimelineResponse } from '../../../common/api/timeline'; import { type ColumnHeaderResult, RowRendererIdEnum, @@ -1987,7 +1987,7 @@ export const mockDataTableModel: DataTableModel = { }, }; -export const mockGetOneTimelineResult: TimelineResult = { +export const mockGetOneTimelineResult: TimelineResponse = { savedObjectId: 'ef579e40-jibber-jabber', columns: timelineDefaults.columns.filter( (column) => column.id !== 'event.action' diff --git a/x-pack/plugins/security_solution/public/detections/components/alerts_table/actions.tsx b/x-pack/plugins/security_solution/public/detections/components/alerts_table/actions.tsx index c83fa2bf22211..a2dfef2c43e9f 100644 --- a/x-pack/plugins/security_solution/public/detections/components/alerts_table/actions.tsx +++ b/x-pack/plugins/security_solution/public/detections/components/alerts_table/actions.tsx @@ -50,8 +50,8 @@ import { isNewTermsRule, isThresholdRule, } from '../../../../common/detection_engine/utils'; -import type { TimelineResult } from '../../../../common/api/timeline'; import { TimelineId } from '../../../../common/types/timeline'; +import type { TimelineResponse } from '../../../../common/api/timeline'; import { TimelineStatusEnum, TimelineTypeEnum } from '../../../../common/api/timeline'; import type { SendAlertToTimelineActionProps, @@ -69,7 +69,7 @@ import { TimelineEventsQueries } from '../../../../common/search_strategy/timeli import { timelineDefaults } from '../../../timelines/store/defaults'; import { omitTypenameInTimeline, - formatTimelineResultToModel, + formatTimelineResponseToModel, } from '../../../timelines/components/open_timeline/helpers'; import { convertKueryToElasticSearchQuery } from '../../../common/lib/kuery'; import { getField, getFieldKey } from '../../../helpers'; @@ -983,11 +983,15 @@ export const sendAlertToTimelineAction = async ({ ), ]); - const resultingTimeline: TimelineResult = getOr({}, 'data.getOneTimeline', responseTimeline); + const resultingTimeline: TimelineResponse = getOr( + {}, + 'data.getOneTimeline', + responseTimeline + ); const eventData: TimelineEventsDetailsItem[] = eventDataResp.data ?? []; if (!isEmpty(resultingTimeline)) { - const timelineTemplate: TimelineResult = omitTypenameInTimeline(resultingTimeline); - const { timeline, notes } = formatTimelineResultToModel( + const timelineTemplate = omitTypenameInTimeline(resultingTimeline); + const { timeline, notes } = formatTimelineResponseToModel( timelineTemplate, true, timelineTemplate.timelineType ?? TimelineTypeEnum.default diff --git a/x-pack/plugins/security_solution/public/timelines/components/open_timeline/helpers.test.ts b/x-pack/plugins/security_solution/public/timelines/components/open_timeline/helpers.test.ts index 9238568b7cc96..a3428ae6f2e1d 100644 --- a/x-pack/plugins/security_solution/public/timelines/components/open_timeline/helpers.test.ts +++ b/x-pack/plugins/security_solution/public/timelines/components/open_timeline/helpers.test.ts @@ -20,7 +20,7 @@ import { isUntitled, omitTypenameInTimeline, useQueryTimelineById, - formatTimelineResultToModel, + formatTimelineResponseToModel, } from './helpers'; import type { OpenTimelineResult } from './types'; import { TimelineId } from '../../../../common/types/timeline'; @@ -695,7 +695,7 @@ describe('helpers', () => { }); test('Do not override daterange if TimelineStatus is active', () => { - const { timeline } = formatTimelineResultToModel( + const { timeline } = formatTimelineResponseToModel( omitTypenameInTimeline(getOr({}, 'data.timeline', selectedTimeline)), args.duplicate, args.timelineType @@ -748,7 +748,7 @@ describe('helpers', () => { }); test('should not override daterange if TimelineStatus is active', () => { - const { timeline } = formatTimelineResultToModel( + const { timeline } = formatTimelineResponseToModel( omitTypenameInTimeline(getOr({}, 'data.timeline', selectedTimeline)), args.duplicate, args.timelineType @@ -822,7 +822,7 @@ describe('helpers', () => { }); test('override daterange if TimelineStatus is immutable', () => { - const { timeline } = formatTimelineResultToModel( + const { timeline } = formatTimelineResponseToModel( omitTypenameInTimeline(getOr({}, 'data.timeline', template)), args.duplicate, args.timelineType diff --git a/x-pack/plugins/security_solution/public/timelines/components/open_timeline/helpers.ts b/x-pack/plugins/security_solution/public/timelines/components/open_timeline/helpers.ts index e977d05f07689..000a7b226561e 100644 --- a/x-pack/plugins/security_solution/public/timelines/components/open_timeline/helpers.ts +++ b/x-pack/plugins/security_solution/public/timelines/components/open_timeline/helpers.ts @@ -14,7 +14,7 @@ import { useCallback } from 'react'; import { useDiscoverInTimelineContext } from '../../../common/components/discover_in_timeline/use_discover_in_timeline_context'; import type { ColumnHeaderOptions } from '../../../../common/types/timeline'; import type { - TimelineResult, + TimelineResponse, ResolvedTimeline, ColumnHeaderResult, FilterTimelineResult, @@ -80,7 +80,7 @@ export const isUntitled = ({ title }: OpenTimelineResult): boolean => const omitTypename = (key: string, value: keyof TimelineModel) => key === '__typename' ? undefined : value; -export const omitTypenameInTimeline = (timeline: TimelineResult): TimelineResult => +export const omitTypenameInTimeline = (timeline: TimelineResponse): TimelineResponse => JSON.parse(JSON.stringify(timeline), omitTypename); const parseString = (params: string) => { @@ -164,7 +164,7 @@ const setPinnedEventIds = (duplicate: boolean, pinnedEventIds: string[] | null | : {}; const getTemplateTimelineId = ( - timeline: TimelineResult, + timeline: TimelineResponse, duplicate: boolean, targetTimelineType?: TimelineType ) => { @@ -200,7 +200,7 @@ const convertToDefaultField = ({ and, ...dataProvider }: DataProviderResult) => const getDataProviders = ( duplicate: boolean, - dataProviders: TimelineResult['dataProviders'], + dataProviders: TimelineResponse['dataProviders'], timelineType?: TimelineType ) => { if (duplicate && dataProviders && timelineType === TimelineTypeEnum.default) { @@ -214,7 +214,7 @@ const getDataProviders = ( }; export const getTimelineTitle = ( - timeline: TimelineResult, + timeline: TimelineResponse, duplicate: boolean, timelineType?: TimelineType ) => { @@ -225,7 +225,7 @@ export const getTimelineTitle = ( }; export const getTimelineStatus = ( - timeline: TimelineResult, + timeline: TimelineResponse, duplicate: boolean, timelineType?: TimelineType ) => { @@ -236,7 +236,7 @@ export const getTimelineStatus = ( }; export const defaultTimelineToTimelineModel = ( - timeline: TimelineResult, + timeline: TimelineResponse, duplicate: boolean, timelineType?: TimelineType, unifiedComponentsInTimelineDisabled?: boolean @@ -291,8 +291,8 @@ export const defaultTimelineToTimelineModel = ( ); }; -export const formatTimelineResultToModel = ( - timelineToOpen: TimelineResult, +export const formatTimelineResponseToModel = ( + timelineToOpen: TimelineResponse, duplicate: boolean = false, timelineType?: TimelineType, unifiedComponentsInTimelineDisabled?: boolean @@ -381,7 +381,7 @@ export const useQueryTimelineById = () => { const timelineToOpen = omitTypenameInTimeline(data.timeline); - const { timeline, notes } = formatTimelineResultToModel( + const { timeline, notes } = formatTimelineResponseToModel( timelineToOpen, duplicate, timelineType, diff --git a/x-pack/plugins/security_solution/public/timelines/containers/all/index.tsx b/x-pack/plugins/security_solution/public/timelines/containers/all/index.tsx index 48d4aa698a324..9db2a0b8924d9 100644 --- a/x-pack/plugins/security_solution/public/timelines/containers/all/index.tsx +++ b/x-pack/plugins/security_solution/public/timelines/containers/all/index.tsx @@ -21,7 +21,7 @@ import type { TimelineType, TimelineStatus, PageInfoTimeline, - TimelineResult, + TimelineResponse, SortTimeline, GetTimelinesRequestQuery, } from '../../../../common/api/timeline'; @@ -59,7 +59,7 @@ export interface AllTimelinesVariables { export const ALL_TIMELINE_QUERY_ID = 'FETCH_ALL_TIMELINES'; export const getAllTimeline = memoizeOne( - (_variables: string, timelines: TimelineResult[]): OpenTimelineResult[] => + (_variables: string, timelines: TimelineResponse[]): OpenTimelineResult[] => timelines.map((timeline) => ({ created: timeline.created, description: timeline.description, @@ -165,7 +165,7 @@ export const useGetAllTimeline = (): AllTimelinesArgs => { setAllTimelines({ loading: false, totalCount, - timelines: getAllTimeline(JSON.stringify(variables), timelines as TimelineResult[]), + timelines: getAllTimeline(JSON.stringify(variables), timelines as TimelineResponse[]), customTemplateTimelineCount, defaultTimelineCount, elasticTemplateTimelineCount, diff --git a/x-pack/plugins/security_solution/public/timelines/containers/helpers.ts b/x-pack/plugins/security_solution/public/timelines/containers/helpers.ts index 17d0050488f5b..fef5fa22f0bfb 100644 --- a/x-pack/plugins/security_solution/public/timelines/containers/helpers.ts +++ b/x-pack/plugins/security_solution/public/timelines/containers/helpers.ts @@ -6,10 +6,10 @@ */ import { TableId } from '@kbn/securitysolution-data-table'; -import type { TimelineResult } from '../../../common/api/timeline'; +import type { TimelineResponse } from '../../../common/api/timeline'; import { DEFAULT_ALERTS_INDEX } from '../../../common/constants'; -export const getTimelineQueryTypes = (timeline: TimelineResult) => ({ +export const getTimelineQueryTypes = (timeline: TimelineResponse) => ({ hasQuery: (timeline.kqlQuery != null && timeline.kqlQuery.filterQuery != null && diff --git a/x-pack/plugins/security_solution/server/lib/timeline/routes/timelines/create_timelines/helpers.ts b/x-pack/plugins/security_solution/server/lib/timeline/routes/timelines/create_timelines/helpers.ts index 3736386ac3f03..ac05fe3f880e9 100644 --- a/x-pack/plugins/security_solution/server/lib/timeline/routes/timelines/create_timelines/helpers.ts +++ b/x-pack/plugins/security_solution/server/lib/timeline/routes/timelines/create_timelines/helpers.ts @@ -10,8 +10,9 @@ import { isEmpty } from 'lodash/fp'; import moment from 'moment'; import { timeline as timelineLib, pinnedEvent as pinnedEventLib } from '../../../saved_object'; import type { FrameworkRequest } from '../../../../framework'; -import type { ResponseTimeline, SavedTimeline, Note } from '../../../../../../common/api/timeline'; +import type { SavedTimeline, Note } from '../../../../../../common/api/timeline'; import { persistNotes } from '../../../saved_object/notes/persist_notes'; +import type { InternalTimelineResponse } from '../../../saved_object/timelines'; interface CreateTimelineProps { frameworkRequest: FrameworkRequest; @@ -40,7 +41,7 @@ export const createTimelines = async ({ existingNoteIds = [], isImmutable, overrideNotesOwner = true, -}: CreateTimelineProps): Promise => { +}: CreateTimelineProps): Promise => { const timerangeStart = isImmutable ? moment().subtract(24, 'hours').toISOString() : timeline.dateRange?.start; diff --git a/x-pack/plugins/security_solution/server/lib/timeline/routes/timelines/export_timelines/helpers.ts b/x-pack/plugins/security_solution/server/lib/timeline/routes/timelines/export_timelines/helpers.ts index 4974e6bd0edda..6e4f3d84da1ff 100644 --- a/x-pack/plugins/security_solution/server/lib/timeline/routes/timelines/export_timelines/helpers.ts +++ b/x-pack/plugins/security_solution/server/lib/timeline/routes/timelines/export_timelines/helpers.ts @@ -9,11 +9,11 @@ import { omit } from 'lodash/fp'; import { transformDataToNdjson } from '@kbn/securitysolution-utils'; import type { - ExportedTimelines, ExportedNotes, ExportTimelineNotFoundError, Note, PinnedEvent, + TimelineResponse, } from '../../../../../../common/api/timeline'; import type { FrameworkRequest } from '../../../../framework'; @@ -45,7 +45,7 @@ const getPinnedEventsIdsByTimelineId = (currentPinnedEvents: PinnedEvent[]): str const getTimelinesFromObjects = async ( request: FrameworkRequest, ids?: string[] | null -): Promise> => { +): Promise> => { const { timelines, errors } = await getSelectedTimelines(request, ids); const exportedIds = timelines.map((t) => t.savedObjectId); @@ -65,7 +65,7 @@ const getTimelinesFromObjects = async ( [] ); - const myResponse = exportedIds.reduce((acc, timelineId) => { + const myResponse = exportedIds.reduce((acc, timelineId) => { const myTimeline = timelines.find((t) => t.savedObjectId === timelineId); if (myTimeline != null) { const timelineNotes = myNotes.filter((n) => n.timelineId === timelineId); diff --git a/x-pack/plugins/security_solution/server/lib/timeline/saved_object/timelines/index.ts b/x-pack/plugins/security_solution/server/lib/timeline/saved_object/timelines/index.ts index cbde4fb2aaacf..c3016164d4e7e 100644 --- a/x-pack/plugins/security_solution/server/lib/timeline/saved_object/timelines/index.ts +++ b/x-pack/plugins/security_solution/server/lib/timeline/saved_object/timelines/index.ts @@ -377,7 +377,7 @@ export const persistFavorite = async ( } }; -interface InternalTimelineResponse { +export interface InternalTimelineResponse { code: number; message: string; timeline: TimelineResponse;