From adc1a4cd8eb3f1943c96b4619e65e1c0424be4de Mon Sep 17 00:00:00 2001 From: "opensearch-trigger-bot[bot]" <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com> Date: Tue, 17 Jan 2023 23:24:24 +0530 Subject: [PATCH] consolidated most shared types at top level (#347) (#362) Signed-off-by: Amardeepsingh Siglani Signed-off-by: Amardeepsingh Siglani (cherry picked from commit dae16fa49ef379de30c8a066b26f9fdb79ca408e) Co-authored-by: Amardeepsingh Siglani Signed-off-by: AWSHurneyt --- .../containers/Categories/Categories.tsx | 22 --- .../Categories/containers/Categories/index.ts | 8 -- public/pages/Categories/index.ts | 8 -- public/pages/Detectors/models/interfaces.ts | 15 -- public/pages/Findings/models/interfaces.ts | 5 - public/pages/Overview/models/types.ts | 4 +- public/pages/Rules/models/types.ts | 3 - public/services/DetectorService.ts | 3 +- public/services/OpenSearchService.ts | 23 --- types/Alert.ts | 94 ++++++++++++ types/Detector.ts | 135 ++++++++++++++++++ types/FieldMapping.ts | 68 +++++++++ types/Finding.ts | 49 +++++++ types/Indices.ts | 26 ++++ types/Notification.ts | 41 ++++++ types/Overview.ts | 70 +++++++++ types/Rule.ts | 93 ++++++++++++ types/index.ts | 14 ++ types/services/IAlertService.ts | 15 ++ types/services/IBrowserServices.ts | 24 ++++ types/services/IDetectorService.ts | 25 ++++ types/services/IFieldMappingService.ts | 25 ++++ types/services/IFindingService.ts | 11 ++ types/services/IIndexService.ts | 22 +++ types/services/INotificationService.ts | 12 ++ types/services/IOpensearchService.ts | 12 ++ types/services/IRuleService.ts | 24 ++++ types/services/ServerResponse.ts | 7 + types/services/index.ts | 15 ++ 29 files changed, 785 insertions(+), 88 deletions(-) delete mode 100644 public/pages/Categories/containers/Categories/Categories.tsx delete mode 100644 public/pages/Categories/containers/Categories/index.ts delete mode 100644 public/pages/Categories/index.ts create mode 100644 types/Alert.ts create mode 100644 types/Detector.ts create mode 100644 types/FieldMapping.ts create mode 100644 types/Finding.ts create mode 100644 types/Indices.ts create mode 100644 types/Notification.ts create mode 100644 types/Overview.ts create mode 100644 types/Rule.ts create mode 100644 types/index.ts create mode 100644 types/services/IAlertService.ts create mode 100644 types/services/IBrowserServices.ts create mode 100644 types/services/IDetectorService.ts create mode 100644 types/services/IFieldMappingService.ts create mode 100644 types/services/IFindingService.ts create mode 100644 types/services/IIndexService.ts create mode 100644 types/services/INotificationService.ts create mode 100644 types/services/IOpensearchService.ts create mode 100644 types/services/IRuleService.ts create mode 100644 types/services/ServerResponse.ts create mode 100644 types/services/index.ts diff --git a/public/pages/Categories/containers/Categories/Categories.tsx b/public/pages/Categories/containers/Categories/Categories.tsx deleted file mode 100644 index 0ddd39e64..000000000 --- a/public/pages/Categories/containers/Categories/Categories.tsx +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright OpenSearch Contributors - * SPDX-License-Identifier: Apache-2.0 - */ - -import React, { Component } from 'react'; -import { RouteComponentProps } from 'react-router-dom'; -import { ContentPanel } from '../../../../components/ContentPanel'; - -interface CategoriesProps extends RouteComponentProps {} - -interface CategoriesState {} - -export default class Categories extends Component { - constructor(props: CategoriesProps) { - super(props); - } - - render() { - return ; - } -} diff --git a/public/pages/Categories/containers/Categories/index.ts b/public/pages/Categories/containers/Categories/index.ts deleted file mode 100644 index 4406c2064..000000000 --- a/public/pages/Categories/containers/Categories/index.ts +++ /dev/null @@ -1,8 +0,0 @@ -/* - * Copyright OpenSearch Contributors - * SPDX-License-Identifier: Apache-2.0 - */ - -import Categories from './Categories'; - -export default Categories; diff --git a/public/pages/Categories/index.ts b/public/pages/Categories/index.ts deleted file mode 100644 index 569298bf6..000000000 --- a/public/pages/Categories/index.ts +++ /dev/null @@ -1,8 +0,0 @@ -/* - * Copyright OpenSearch Contributors - * SPDX-License-Identifier: Apache-2.0 - */ - -import Categories from './containers/Categories'; - -export default Categories; diff --git a/public/pages/Detectors/models/interfaces.ts b/public/pages/Detectors/models/interfaces.ts index b1f54134e..cc7961374 100644 --- a/public/pages/Detectors/models/interfaces.ts +++ b/public/pages/Detectors/models/interfaces.ts @@ -3,21 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ -import { Direction } from '@elastic/eui'; - -export interface DetectorItem { - id: string; - name: string; -} - -export interface DetectorsQueryParams { - from: number; - size: number; - search: string; - sortField: keyof DetectorItem; - sortDirection: Direction; -} - export interface IndexOption { label: string; } diff --git a/public/pages/Findings/models/interfaces.ts b/public/pages/Findings/models/interfaces.ts index 5c3ac0f7a..f1345a2d2 100644 --- a/public/pages/Findings/models/interfaces.ts +++ b/public/pages/Findings/models/interfaces.ts @@ -3,11 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ -export interface FilterOption { - id: string; - label: string; -} - export interface Finding { id: string; detectorId: string; diff --git a/public/pages/Overview/models/types.ts b/public/pages/Overview/models/types.ts index e50bb05b3..d5d6b7786 100644 --- a/public/pages/Overview/models/types.ts +++ b/public/pages/Overview/models/types.ts @@ -1,9 +1,7 @@ /* * Copyright OpenSearch Contributors * SPDX-License-Identifier: Apache-2.0 - */ { - loading; -} + */ import { EuiBasicTableColumn } from '@elastic/eui'; import { AlertItem, DetectorItem, FindingItem } from './interfaces'; diff --git a/public/pages/Rules/models/types.ts b/public/pages/Rules/models/types.ts index 4e99c0524..77d21381b 100644 --- a/public/pages/Rules/models/types.ts +++ b/public/pages/Rules/models/types.ts @@ -3,9 +3,6 @@ * SPDX-License-Identifier: Apache-2.0 */ -import { Rule } from '../../../../models/interfaces'; import { RuleInfo } from '../../../../server/models/interfaces'; export type RuleItemInfoBase = RuleInfo & { prePackaged: boolean }; - -export type RulePayload = Omit; diff --git a/public/services/DetectorService.ts b/public/services/DetectorService.ts index 2fef5b4e7..9a6517247 100644 --- a/public/services/DetectorService.ts +++ b/public/services/DetectorService.ts @@ -13,8 +13,9 @@ import { } from '../../server/models/interfaces'; import { API } from '../../server/utils/constants'; import { Detector } from '../../models/interfaces'; +import { IDetectorService } from '../../types'; -export default class DetectorsService { +export default class DetectorsService implements IDetectorService { constructor(private httpClient: HttpSetup) {} createDetector = async (detector: Detector): Promise> => { diff --git a/public/services/OpenSearchService.ts b/public/services/OpenSearchService.ts index f1b1c6632..10e4790b1 100644 --- a/public/services/OpenSearchService.ts +++ b/public/services/OpenSearchService.ts @@ -9,7 +9,6 @@ import { SimpleSavedObject, } from 'opensearch-dashboards/public'; import { ServerResponse } from '../../server/models/types'; -import { SearchResponse, Plugin } from '../../server/models/interfaces'; import { API } from '../../server/utils/constants'; export default class OpenSearchService { @@ -18,28 +17,6 @@ export default class OpenSearchService { private savedObjectsClient: SavedObjectsClientContract ) {} - documentIdsQuery = async ( - index: string, - documentIds: string[] - ): Promise>> => { - if (!index || !documentIds) return; - return (await this.httpClient.get(`..${API.DOCUMENT_IDS_QUERY}`, { - query: { index, documentIds }, - })) as ServerResponse>; - }; - - timeRangeQuery = async ( - index: string, - timeField = 'timestamp', - startTime = 'now-15m', - endTime = 'now' - ): Promise>> => { - if (!index) return; - return (await this.httpClient.get(`..${API.TIME_RANGE_QUERY}`, { - query: { index, timeField, startTime, endTime }, - })) as ServerResponse>; - }; - getPlugins = async (): Promise> => { let url = `..${API.PLUGINS}`; return await this.httpClient.get(url); diff --git a/types/Alert.ts b/types/Alert.ts new file mode 100644 index 000000000..f085fa067 --- /dev/null +++ b/types/Alert.ts @@ -0,0 +1,94 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +export interface AlertCondition { + // Trigger fields + name: string; + id?: string; + + // Detector types + types: string[]; + + // Trigger fields based on Rules + sev_levels: string[]; + tags: string[]; + ids: string[]; + + // Alert related fields + actions: TriggerAction[]; + severity: string; +} + +export interface TriggerAction { + id: string; + // Id of notification channel + destination_id: string; + subject_template: { + source: string; + lang: string; + }; + name: string; + throttle_enabled: boolean; + message_template: { + source: string; + lang: string; + }; + throttle: { + unit: string; + value: number; + }; +} + +/** + * API interfaces + */ + +export type GetAlertsParams = + | { + detector_id: string; + detectorType?: string; + } + | { + detectorType: string; + detector_id?: string; + }; + +export interface GetAlertsResponse { + alerts: AlertResponse[]; +} + +export interface AlertItem { + id: string; + start_time: string; + trigger_name: string; + detector_id: string; + state: string; + severity: string; + finding_ids: string[]; + last_notification_time: string; + acknowledged_time: string | null; +} + +export interface AlertResponse extends AlertItem { + version: number; + schema_version: number; + trigger_id: string; + related_doc_ids: string[]; + error_message: string | null; + alert_history: string[]; + action_execution_results: { + action_id: string; + last_execution_time: number; + throttled_count: number; + }[]; + end_time: string | null; +} + +export interface AcknowledgeAlertsParams { + body: { alerts: string[] }; + detector_id: string; +} + +export interface AcknowledgeAlertsResponse {} diff --git a/types/Detector.ts b/types/Detector.ts new file mode 100644 index 000000000..3632dcde8 --- /dev/null +++ b/types/Detector.ts @@ -0,0 +1,135 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +import { AlertCondition } from './Alert'; +import { DetectorRuleInfo } from './Rule'; + +export interface DetectorInput { + detector_input: { + description: string; + indices: string[]; + pre_packaged_rules: DetectorRuleInfo[]; + custom_rules: DetectorRuleInfo[]; + }; +} + +export interface DetectorSchedule { + period: { + interval: number; + unit: string; + }; +} + +export interface Detector { + id?: string; + type: 'detector'; + detector_type: string; + name: string; + enabled: boolean; + createdBy: string; + schedule: DetectorSchedule; + inputs: DetectorInput[]; + triggers: AlertCondition[]; +} + +export interface AlertConditionRuleOption { + name: string; + id: string; + severity: string; + tags: string[]; +} + +export interface RulesSharedState { + page: RulesPage; + rulesOptions: AlertConditionRuleOption[]; +} + +export interface RulesPage { + index: number; +} + +export interface SourceIndexOption { + label: string; +} + +export interface DetectorTypeOption { + id: string; + label: string; +} + +export enum DetectorCreationStep { + DEFINE_DETECTOR = 1, + CONFIGURE_FIELD_MAPPING = 2, + CONFIGURE_ALERTS = 3, + REVIEW_CREATE = 4, +} + +export interface DetectorHit { + _index: string; + _source: DetectorResponse; + _id: string; +} + +/** + * API Interfaces + */ + +export type DetectorResponse = Detector & { + last_update_time: number; + enabled_time: number; +}; + +export interface CreateDetectorParams { + body: Detector; +} + +export interface CreateDetectorResponse { + _id: string; + _version: number; + detector: DetectorResponse; +} + +export interface GetDetectorParams { + detectorId: string; +} + +export interface GetDetectorResponse {} + +export interface SearchDetectorsParams { + body: { + size: number; + query: object; + }; +} + +export interface SearchDetectorsResponse { + hits: { + total: { value: number }; + hits: DetectorHit[]; + }; +} + +export interface UpdateDetectorParams { + detectorId: string; + body: Detector; +} + +export interface UpdateDetectorResponse { + _id: string; + _version: number; + detector: { + detector: Detector & { + last_update_time: number; + monitor_id: string; + rule_topic_index: string; + }; + }; +} + +export interface DeleteDetectorParams { + detectorId: string; +} + +export interface DeleteDetectorResponse {} diff --git a/types/FieldMapping.ts b/types/FieldMapping.ts new file mode 100644 index 000000000..be2c40a61 --- /dev/null +++ b/types/FieldMapping.ts @@ -0,0 +1,68 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +export interface FieldMapping { + indexFieldName: string; + ruleFieldName: string; +} + +export interface FieldMappingsTableItem { + ruleFieldName: string; + logFieldName?: string; +} + +/** + * API interfaces + */ +export interface GetFieldMapingsViewParams { + indexName: string; + ruleTopic?: string; +} + +export interface GetFieldMappingViewResponse extends FieldMappingPropertyMap { + unmapped_index_fields?: string[]; + unmapped_field_aliases?: string[]; +} + +export interface CreateMappingsParams { + body: CreateMappingBody; +} + +export interface CreateMappingBody { + index_name: string; + rule_topic: string; + partial: boolean; + alias_mappings: { + properties: { + [aliasName: string]: { + type: string; + path: string; + }; + }; + }; +} + +export interface CreateMappingsResponse { + acknowledged: boolean; +} + +export interface GetMappingsParams { + indexName: string; +} + +export interface GetMappingsResponse { + [indexName: string]: { + mappings: FieldMappingPropertyMap; + }; +} + +export interface IndexFieldInfo { + type: 'alias'; + path: string; +} + +export interface FieldMappingPropertyMap { + properties: { [aliasName: string]: IndexFieldInfo }; +} diff --git a/types/Finding.ts b/types/Finding.ts new file mode 100644 index 000000000..3ca6815cf --- /dev/null +++ b/types/Finding.ts @@ -0,0 +1,49 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +export interface Finding { + id: string; + detectorId: string; + document_list: FindingDocument[]; + index: string; + queries: Query[]; + related_doc_ids: string[]; + timestamp: number; +} + +export interface Query { + id: string; + name: string; + query: string; + tags: string[]; + category: string; + severity: string; + description: string; +} + +export interface FindingDocument { + id: string; + index: string; + found: boolean; + document: string; +} + +/** + * API interfaces + */ +export type GetFindingsParams = + | { + detectorId: string; + detectorType?: string; + } + | { + detectorType: string; + detectorId?: string; + }; + +export interface GetFindingsResponse { + total_findings: number; + findings: Finding[]; +} diff --git a/types/Indices.ts b/types/Indices.ts new file mode 100644 index 000000000..aef399a28 --- /dev/null +++ b/types/Indices.ts @@ -0,0 +1,26 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +// Default _cat index response +export interface CatIndex { + 'docs.count': string; + 'docs.deleted': string; + health: string; + index: string; + pri: string; + 'pri.store.size': string; + rep: string; + status: string; + 'store.size': string; + uuid: string; + data_stream: string | null; +} + +/** + * API Interfaces + */ +export interface GetIndicesResponse { + indices: CatIndex[]; +} diff --git a/types/Notification.ts b/types/Notification.ts new file mode 100644 index 000000000..dd694accf --- /dev/null +++ b/types/Notification.ts @@ -0,0 +1,41 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +export interface NotificationConfig { + config_id: string; + last_updated_time_ms: number; + created_time_ms: number; + config: { + name: string; + description: string; + config_type: string; + is_enabled: boolean; + }; +} + +export interface FeatureChannelList { + config_id: string; + name: string; + description: string; + config_type: string; + is_enabled: boolean; +} + +/** + * API interfaces + */ +export interface GetChannelsResponse { + start_index: number; + total_hits: number; + total_hit_relation: string; + channel_list: FeatureChannelList[]; +} + +export interface GetNotificationConfigsResponse { + start_index: number; + total_hits: number; + total_hit_relation: string; + config_list: NotificationConfig[]; +} diff --git a/types/Overview.ts b/types/Overview.ts new file mode 100644 index 000000000..e8a559ce1 --- /dev/null +++ b/types/Overview.ts @@ -0,0 +1,70 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +import { EuiBasicTableColumn } from '@elastic/eui'; +import { NotificationsStart } from 'opensearch-dashboards/public'; +import { RouteComponentProps } from 'react-router-dom'; +import { DetectorHit } from './Detector'; + +export interface DateTimeFilter { + startTime: string; + endTime: string; +} + +export interface OverviewViewModel { + detectors: DetectorHit[]; + findings: OverviewFindingItem[]; + alerts: OverviewAlertItem[]; +} + +export type OverviewViewModelRefreshHandler = (overviewState: OverviewViewModel) => void; + +export interface OverviewProps extends RouteComponentProps { + getStartedDismissedOnce: boolean; + onGetStartedDismissed: () => void; + notifications?: NotificationsStart; + setDateTimeFilter?: Function; + dateTimeFilter?: DateTimeFilter; +} + +export interface OverviewState { + groupBy: string; + overviewViewModel: OverviewViewModel; +} + +export interface OverviewFindingItem { + id: string; + time: number; + findingName: string; + detector: string; + logType: string; + ruleId: string; + ruleName: string; + ruleSeverity: string; +} + +export interface OverviewAlertItem { + id: string; + time: string; + triggerName: string; + severity: string; + logType: string; + acknowledged: boolean; +} + +export interface OverviewDetectorItem { + id: string; + detectorName: string; + status: string; + logTypes: string; +} + +export type TableWidgetItem = OverviewFindingItem | OverviewAlertItem | OverviewDetectorItem; + +export type TableWidgetProps = { + columns: EuiBasicTableColumn[]; + items: T[]; + loading?: boolean; +}; diff --git a/types/Rule.ts b/types/Rule.ts new file mode 100644 index 000000000..d0f500140 --- /dev/null +++ b/types/Rule.ts @@ -0,0 +1,93 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +export interface Rule { + id: string; + category: string; + log_source: string; + title: string; + description: string; + tags: { value: string }[]; + false_positives: { value: string }[]; + level: string; + status: string; + references: { value: string }[]; + author: string; + detection: string; +} + +export type RuleSource = Rule & { + rule: string; + last_update_time: string; + queries: { value: string }[]; +}; + +export interface RuleInfo { + _id: string; + _index: string; + _primary_term: number; + _source: RuleSource; + _version: number; +} + +export interface DetectorRuleInfo { + id: string; +} + +export type RuleItemInfoBase = RuleInfo & { prePackaged: boolean }; + +/** + * API Interfaces + */ +export interface CreateRuleParams { + body: string; + category: string; +} + +export interface CreateRuleResponse { + _id: string; + _version: number; + rule: Omit & { + last_update_time: number; + monitor_id: string; + }; +} + +export interface UpdateRuleParams { + body: string; + category: string; + ruleId: string; +} + +export interface UpdateRuleResponse { + _id: string; + _version: number; + rule: Omit & { + last_update_time: number; + monitor_id: string; + }; +} + +export interface GetRulesParams { + prePackaged: boolean; + body: any; +} + +export interface GetRulesResponse { + hits: { + hits: RuleInfo[]; + total: { + value: number; + relation: string; + }; + timed_out: boolean; + }; +} + +export interface DeleteRuleParams { + ruleId: string; +} + +export interface DeleteRuleResponse {} diff --git a/types/index.ts b/types/index.ts new file mode 100644 index 000000000..2e50faaf9 --- /dev/null +++ b/types/index.ts @@ -0,0 +1,14 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +export * from './Alert'; +export * from './Detector'; +export * from './FieldMapping'; +export * from './Finding'; +export * from './Indices'; +export * from './Notification'; +export * from './Overview'; +export * from './Rule'; +export * from './services'; diff --git a/types/services/IAlertService.ts b/types/services/IAlertService.ts new file mode 100644 index 000000000..440178279 --- /dev/null +++ b/types/services/IAlertService.ts @@ -0,0 +1,15 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +import { AcknowledgeAlertsResponse, GetAlertsParams, GetAlertsResponse } from '../Alert'; +import { ServerResponse } from './ServerResponse'; + +export interface IAlertService { + getAlerts(detectorParams: GetAlertsParams): Promise>; + acknowledgeAlerts( + alertIds: string[], + detector_id: string + ): Promise>; +} diff --git a/types/services/IBrowserServices.ts b/types/services/IBrowserServices.ts new file mode 100644 index 000000000..3f9d8cade --- /dev/null +++ b/types/services/IBrowserServices.ts @@ -0,0 +1,24 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +import { IDetectorService } from './IDetectorService'; +import { IFieldMappingService } from './IFieldMappingService'; +import { IFindingService } from './IFindingService'; +import { IIndexService } from './IIndexService'; +import { IOpenSearchService } from './IOpensearchService'; +import { IAlertService } from './IAlertService'; +import { IRuleService } from './IRuleService'; +import { INotificationService } from './INotificationService'; + +export interface IBrowserServices { + detectorsService: IDetectorService; + findingsService: IFindingService; + indexService: IIndexService; + opensearchService: IOpenSearchService; + fieldMappingService: IFieldMappingService; + alertService: IAlertService; + ruleService: IRuleService; + notificationsService: INotificationService; +} diff --git a/types/services/IDetectorService.ts b/types/services/IDetectorService.ts new file mode 100644 index 000000000..8c67db306 --- /dev/null +++ b/types/services/IDetectorService.ts @@ -0,0 +1,25 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +import { + CreateDetectorResponse, + DeleteDetectorResponse, + Detector, + SearchDetectorsResponse, + UpdateDetectorResponse, +} from '../Detector'; +import { ServerResponse } from './ServerResponse'; + +export type MatchAllQuery = { match_all: {} }; + +export interface IDetectorService { + createDetector(detector: Detector): Promise>; + deleteDetector(detectorId: string): Promise>; + getDetectors(): Promise>; + updateDetector( + detectorId: string, + detector: Detector + ): Promise>; +} diff --git a/types/services/IFieldMappingService.ts b/types/services/IFieldMappingService.ts new file mode 100644 index 000000000..9d9961521 --- /dev/null +++ b/types/services/IFieldMappingService.ts @@ -0,0 +1,25 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +import { ServerResponse } from './ServerResponse'; +import { + CreateMappingsResponse, + FieldMapping, + GetFieldMappingViewResponse, + GetMappingsResponse, +} from '../FieldMapping'; + +export interface IFieldMappingService { + getMappingsView( + indexName: string, + ruleTopic?: string + ): Promise>; + createMappings( + index_name: string, + rule_topic: string, + fieldMappings: FieldMapping[] + ): Promise>; + getMappings(indexName: string): Promise>; +} diff --git a/types/services/IFindingService.ts b/types/services/IFindingService.ts new file mode 100644 index 000000000..6920aba4f --- /dev/null +++ b/types/services/IFindingService.ts @@ -0,0 +1,11 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +import { GetFindingsParams, GetFindingsResponse } from '../Finding'; +import { ServerResponse } from './ServerResponse'; + +export interface IFindingService { + getFindings(detectorParams: GetFindingsParams): Promise>; +} diff --git a/types/services/IIndexService.ts b/types/services/IIndexService.ts new file mode 100644 index 000000000..62f61ee32 --- /dev/null +++ b/types/services/IIndexService.ts @@ -0,0 +1,22 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +import { + OpenSearchDashboardsRequest, + OpenSearchDashboardsResponseFactory, + IOpenSearchDashboardsResponse, + ResponseError, + RequestHandlerContext, +} from 'opensearch-dashboards/server'; +import { ServerResponse } from './ServerResponse'; +import { GetIndicesResponse } from '../Indices'; + +export interface IIndexService { + getIndices( + _context: RequestHandlerContext, + request: OpenSearchDashboardsRequest, + response: OpenSearchDashboardsResponseFactory + ): Promise | ResponseError>>; +} diff --git a/types/services/INotificationService.ts b/types/services/INotificationService.ts new file mode 100644 index 000000000..0141aba7a --- /dev/null +++ b/types/services/INotificationService.ts @@ -0,0 +1,12 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +import { GetChannelsResponse, GetNotificationConfigsResponse } from '../Notification'; +import { ServerResponse } from './ServerResponse'; + +export interface INotificationService { + getChannel(channelId: string): Promise>; + getChannels(): Promise>; +} diff --git a/types/services/IOpensearchService.ts b/types/services/IOpensearchService.ts new file mode 100644 index 000000000..0942ed8b6 --- /dev/null +++ b/types/services/IOpensearchService.ts @@ -0,0 +1,12 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +import { ServerResponse } from './ServerResponse'; +import { SimpleSavedObject } from 'opensearch-dashboards/public'; + +export interface IOpenSearchService { + getPlugins(): Promise>; + getIndexPatterns(): Promise[]>; +} diff --git a/types/services/IRuleService.ts b/types/services/IRuleService.ts new file mode 100644 index 000000000..e49f89ed6 --- /dev/null +++ b/types/services/IRuleService.ts @@ -0,0 +1,24 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +import { ServerResponse } from './ServerResponse'; +import { + CreateRuleResponse, + DeleteRuleResponse, + GetRulesResponse, + Rule, + UpdateRuleResponse, +} from '../Rule'; + +export interface IRuleService { + getRules(prePackaged: boolean, body: any): Promise>; + createRule(rule: Rule): Promise>; + updateRule( + ruleId: string, + category: string, + rule: Rule + ): Promise>; + deleteRule(ruleId: string): Promise>; +} diff --git a/types/services/ServerResponse.ts b/types/services/ServerResponse.ts new file mode 100644 index 000000000..875faa1a3 --- /dev/null +++ b/types/services/ServerResponse.ts @@ -0,0 +1,7 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +export type ServerResponse = FailedServerResponse | { ok: true; response: T }; +export type FailedServerResponse = { ok: false; error: string }; diff --git a/types/services/index.ts b/types/services/index.ts new file mode 100644 index 000000000..20404cd89 --- /dev/null +++ b/types/services/index.ts @@ -0,0 +1,15 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +export * from './IAlertService'; +export * from './IBrowserServices'; +export * from './IDetectorService'; +export * from './IFieldMappingService'; +export * from './IFindingService'; +export * from './IIndexService'; +export * from './INotificationService'; +export * from './IOpensearchService'; +export * from './IRuleService'; +export * from './ServerResponse';