diff --git a/x-pack/plugins/endpoint/common/types.ts b/x-pack/plugins/endpoint/common/types.ts index 1a1402671aa013..682b0c2d7615cb 100644 --- a/x-pack/plugins/endpoint/common/types.ts +++ b/x-pack/plugins/endpoint/common/types.ts @@ -4,6 +4,24 @@ * you may not use this file except in compliance with the Elastic License. */ +/** + * A deep readonly type that will make all children of a given object readonly recursively + */ +export type Immutable = T extends undefined | null | boolean | string | number + ? T + : T extends Array + ? ImmutableArray + : T extends Map + ? ImmutableMap + : T extends Set + ? ImmutableSet + : ImmutableObject; + +export type ImmutableArray = ReadonlyArray>; +export type ImmutableMap = ReadonlyMap, Immutable>; +export type ImmutableSet = ReadonlySet>; +export type ImmutableObject = { readonly [K in keyof T]: Immutable }; + export class EndpointAppConstants { static ENDPOINT_INDEX_NAME = 'endpoint-agent*'; } @@ -44,3 +62,37 @@ export interface EndpointMetadata { }; }; } + +export type AlertData = Immutable<{ + value: { + source: { + endgame: { + data: { + file_operation: string; + malware_classification: { + score: number; + }; + }; + metadata: { + key: string; + }; + timestamp_utc: Date; + }; + labels: { + endpoint_id: string; + }; + host: { + hostname: string; + ip: string; + os: { + name: string; + }; + }; + }; + }; +}>; + +/** + * The PageId type is used for the payload when firing userNavigatedToPage actions + */ +export type PageId = 'alertsPage' | 'endpointListPage'; diff --git a/x-pack/plugins/endpoint/endpoint_app_types.ts b/x-pack/plugins/endpoint/endpoint_app_types.ts deleted file mode 100644 index ce4f8349bcf0fc..00000000000000 --- a/x-pack/plugins/endpoint/endpoint_app_types.ts +++ /dev/null @@ -1,54 +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; - * you may not use this file except in compliance with the Elastic License. - */ - -/** - * A deep readonly type that will make all children of a given object readonly recursively - */ -export type Immutable = T extends undefined | null | boolean | string | number - ? T - : T extends Array - ? ImmutableArray - : T extends Map - ? ImmutableMap - : T extends Set - ? ImmutableSet - : ImmutableObject; - -export type ImmutableArray = ReadonlyArray>; -export type ImmutableMap = ReadonlyMap, Immutable>; -export type ImmutableSet = ReadonlySet>; -export type ImmutableObject = { readonly [K in keyof T]: Immutable }; - -export type AlertData = Immutable<{ - value: { - source: { - endgame: { - data: { - file_operation: string; - malware_classification: { - score: number; - }; - }; - metadata: { - key: string; - }; - timestamp_utc: Date; - }; - labels: { - endpoint_id: string; - }; - host: { - hostname: string; - ip: string; - os: { - name: string; - }; - }; - }; - }; -}>; - -export type PageId = 'alertsPage' | 'endpointListPage'; diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/store/alerts/action.ts b/x-pack/plugins/endpoint/public/applications/endpoint/store/alerts/action.ts index 20a123218c751e..51e752d64f7b1f 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/store/alerts/action.ts +++ b/x-pack/plugins/endpoint/public/applications/endpoint/store/alerts/action.ts @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import { AlertData } from '../../../../../endpoint_app_types'; +import { AlertData } from '../../../../../common/types'; interface ServerReturnedAlertsData { readonly type: 'serverReturnedAlertsData'; diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/store/alerts/middleware.ts b/x-pack/plugins/endpoint/public/applications/endpoint/store/alerts/middleware.ts index e681f3641fc9b1..f06e3444aa42fc 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/store/alerts/middleware.ts +++ b/x-pack/plugins/endpoint/public/applications/endpoint/store/alerts/middleware.ts @@ -6,7 +6,7 @@ import { Dispatch, MiddlewareAPI } from 'redux'; import { CoreStart } from 'kibana/public'; -import { AlertData } from '../../../../../endpoint_app_types'; +import { AlertData } from '../../../../../common/types'; import { GlobalState } from '../reducer'; import { AppAction } from '../action'; diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/store/alerts/types.ts b/x-pack/plugins/endpoint/public/applications/endpoint/store/alerts/types.ts index 4a336caab276b0..4c40c00c7d64ea 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/store/alerts/types.ts +++ b/x-pack/plugins/endpoint/public/applications/endpoint/store/alerts/types.ts @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import { AlertData, Immutable } from '../../../../../endpoint_app_types'; +import { Immutable, AlertData } from '../../../../../common/types'; export type AlertListState = Immutable<{ alerts: AlertData[]; diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/store/routing/action.ts b/x-pack/plugins/endpoint/public/applications/endpoint/store/routing/action.ts index 082564af358866..263a3f72d57d5a 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/store/routing/action.ts +++ b/x-pack/plugins/endpoint/public/applications/endpoint/store/routing/action.ts @@ -4,11 +4,10 @@ * you may not use this file except in compliance with the Elastic License. */ -import { PageId } from '../../../../../endpoint_app_types'; +import { PageId } from '../../../../../common/types'; interface UserNavigatedToPage { readonly type: 'userNavigatedToPage'; - readonly payload: PageId; } diff --git a/x-pack/plugins/endpoint/public/applications/endpoint/view/use_page_id.ts b/x-pack/plugins/endpoint/public/applications/endpoint/view/use_page_id.ts index 43c1597bc51610..9e241af4c0445c 100644 --- a/x-pack/plugins/endpoint/public/applications/endpoint/view/use_page_id.ts +++ b/x-pack/plugins/endpoint/public/applications/endpoint/view/use_page_id.ts @@ -6,7 +6,7 @@ import { useEffect } from 'react'; import { useDispatch } from 'react-redux'; -import { PageId } from '../../../../endpoint_app_types'; +import { PageId } from '../../../../common/types'; import { RoutingAction } from '../store/routing'; /**