Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ResponseOps][Rules] Move Rule Form code into @kbn/response-ops-rule-form #198725

Merged
merged 76 commits into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from 58 commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
b414b7c
Change security solution internal/_find find call to POST
Zacqary Oct 4, 2024
a015a44
Merge remote-tracking branch 'upstream/main'
Zacqary Oct 23, 2024
ee1c71b
Initial rule form package migration
Zacqary Oct 31, 2024
fa4f526
Move use fetch flapping settings back to alerts-ui-shared
Zacqary Nov 1, 2024
34d9942
Remove missing export
Zacqary Nov 1, 2024
d2a953f
Fix API imports
Zacqary Nov 1, 2024
f7a3caf
Restore alerts-ui-shared rule types
Zacqary Nov 1, 2024
9f9b58a
Update tsconfig
Zacqary Nov 1, 2024
d9b7e1a
[CI] Auto-commit changed files from 'node scripts/generate codeowners'
kibanamachine Nov 1, 2024
d6dab95
[CI] Auto-commit changed files from 'node scripts/notice'
kibanamachine Nov 4, 2024
2f9211c
Fix jest rootDir
Zacqary Nov 4, 2024
df7a742
Merge branch '195211-rule-form-package' of https://github.com/Zacqary…
Zacqary Nov 4, 2024
4b193da
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Nov 4, 2024
7f7dbc7
Fix i18n, jest, tsconfig
Zacqary Nov 4, 2024
783b901
Merge branch '195211-rule-form-package' of https://github.com/Zacqary…
Zacqary Nov 4, 2024
e824df5
Merge remote-tracking branch 'upstream/main' into 195211-rule-form-pa…
Zacqary Nov 4, 2024
6c6240e
Fix bad merge of #198036
Zacqary Nov 4, 2024
e85e18e
Revert "Fix bad merge of #198036"
Zacqary Nov 4, 2024
d53c2c5
i18n fix
Zacqary Nov 4, 2024
2c2d16d
Fix typecheck
Zacqary Nov 4, 2024
3e2ced4
Fix imports
Zacqary Nov 4, 2024
7cf86d0
Fix typecheck
Zacqary Nov 5, 2024
2549198
Commit missing files
Zacqary Nov 5, 2024
b41dc1f
Fix types and i18n
Zacqary Nov 5, 2024
2ad2f42
Fix typecheck
Zacqary Nov 5, 2024
a9769a9
Fix even more import errors that the typecheck finally decided to tel…
Zacqary Nov 6, 2024
c6222f7
Fix jest mock imports
Zacqary Nov 6, 2024
b5f1fe1
Merge remote-tracking branch 'upstream/main' into 195211-rule-form-pa…
Zacqary Nov 6, 2024
55c4805
[CI] Auto-commit changed files from 'node scripts/generate codeowners'
kibanamachine Nov 6, 2024
c7a7145
Fix jest config
Zacqary Nov 6, 2024
e41602d
Merge branch '195211-rule-form-package' of https://github.com/Zacqary…
Zacqary Nov 6, 2024
b0ff57b
Merge remote-tracking branch 'upstream/main' into 195211-rule-form-pa…
Zacqary Nov 7, 2024
8ae3ceb
Target imports from alerts-ui-shared
Zacqary Nov 7, 2024
0721c81
Increase bundle limit
Zacqary Nov 8, 2024
68acbc3
Fix imports
Zacqary Nov 8, 2024
3be68cc
Reset bundle limits
Zacqary Nov 11, 2024
2df05ef
Remove unneeded constants
Zacqary Nov 11, 2024
ba85215
Clean up exports
Zacqary Nov 11, 2024
aa63d2c
Fix typecheck import
Zacqary Nov 11, 2024
ed71df9
Force async import EcsFlat
Zacqary Nov 11, 2024
4e09693
[CI] Auto-commit changed files from 'node scripts/notice'
kibanamachine Nov 11, 2024
471109b
Optimize import/exports to bundle rule_form in own chunk
Zacqary Nov 11, 2024
e0a670e
Move action_variables back into alerts-ui-shared
Zacqary Nov 12, 2024
1481123
Fix import
Zacqary Nov 12, 2024
ef28b58
Bump triggersActionsUi limit
Zacqary Nov 12, 2024
a7a4871
Fix imports
Zacqary Nov 12, 2024
98b3085
Fix lint
Zacqary Nov 12, 2024
5038bbf
Merge remote-tracking branch 'upstream/main' into 195211-rule-form-pa…
Zacqary Nov 13, 2024
9340146
Optimize observability import
Zacqary Nov 13, 2024
3049709
Specify type import on stack connectors params
Zacqary Nov 13, 2024
aae334c
Fix lazy loading EcsFlat in useLoadRuleTypeAadTemplateFields
Zacqary Nov 13, 2024
38cdbb1
Merge remote-tracking branch 'upstream/main' into 195211-rule-form-pa…
Zacqary Nov 13, 2024
deb9a09
Add retry.try to autocompletion test
Zacqary Nov 14, 2024
5235957
Prune exports from rule form package
Zacqary Nov 14, 2024
9175558
Skip failing test
Zacqary Nov 14, 2024
97b3c61
Merge remote-tracking branch 'upstream/main' into 195211-rule-form-pa…
Zacqary Nov 18, 2024
a3a4c84
Revert async import of EcsFlat in useLoadRuleTypeAADTemplateFields
Zacqary Nov 19, 2024
f5c6566
[CI] Auto-commit changed files from 'node scripts/notice'
kibanamachine Nov 19, 2024
367adc8
Merge remote-tracking branch 'upstream/main' into 195211-rule-form-pa…
Zacqary Nov 19, 2024
3694ebb
Merge branch '195211-rule-form-package' of https://github.com/Zacqary…
Zacqary Nov 19, 2024
46f4fbe
Merge remote-tracking branch 'upstream/main' into 195211-rule-form-pa…
Zacqary Nov 20, 2024
3ad6293
Remove unnecessary export from triggersActionsUi lib
Zacqary Nov 20, 2024
c622640
Optimize alerts-ui-shared bundle size
Zacqary Nov 20, 2024
ea0fd94
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine Nov 20, 2024
4b81345
Fix imports and i18n
Zacqary Nov 20, 2024
5303bba
Merge branch '195211-rule-form-package' of https://github.com/Zacqary…
Zacqary Nov 20, 2024
df16744
Attempt at fixing test
kdelemme Nov 20, 2024
8493f7c
Unskip autocompletion test
Zacqary Nov 20, 2024
68e8c28
Revert limits change
Zacqary Nov 21, 2024
8c3c9ea
Merge remote-tracking branch 'upstream/main' into 195211-rule-form-pa…
Zacqary Nov 22, 2024
6401b97
Merge remote-tracking branch 'upstream/main' into 195211-rule-form-pa…
Zacqary Nov 25, 2024
49ab7bb
Merge branch 'main' into 195211-rule-form-package
kdelemme Nov 27, 2024
78d1445
Use explicit key names for alerts search bar useQuery hooks
Zacqary Dec 2, 2024
d62658a
Merge remote-tracking branch 'upstream/main' into 195211-rule-form-pa…
Zacqary Dec 2, 2024
9f0939b
Merge branch '195211-rule-form-package' of https://github.com/Zacqary…
Zacqary Dec 2, 2024
c5208b1
Merge remote-tracking branch 'upstream/main' into 195211-rule-form-pa…
Zacqary Dec 3, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,7 @@ packages/react/kibana_context/styled @elastic/appex-sharedux
packages/react/kibana_context/theme @elastic/appex-sharedux
packages/react/kibana_mount @elastic/appex-sharedux
packages/response-ops/feature_flag_service @elastic/response-ops
packages/response-ops/rule_form @elastic/response-ops
packages/response-ops/rule_params @elastic/response-ops
packages/serverless/project_switcher @elastic/appex-sharedux
packages/serverless/settings/common @elastic/appex-sharedux @elastic/kibana-management
Expand Down
5 changes: 3 additions & 2 deletions .i18nrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
"searchTypes": "packages/kbn-search-types",
"securitySolutionPackages": "x-pack/packages/security-solution",
"serverlessPackages": "packages/serverless",
"sse": [ "packages/kbn-sse-utils" ],
"sse": ["packages/kbn-sse-utils"],
"coloring": "packages/kbn-coloring/src",
"languageDocumentation": "packages/kbn-language-documentation/src",
"esql": "src/plugins/esql",
Expand Down Expand Up @@ -154,7 +154,8 @@
"unifiedDataTable": "packages/kbn-unified-data-table",
"unsavedChangesBadge": "packages/kbn-unsaved-changes-badge",
"unsavedChangesPrompt": "packages/kbn-unsaved-changes-prompt",
"managedContentBadge": "packages/kbn-managed-content-badge"
"managedContentBadge": "packages/kbn-managed-content-badge",
"responseOpsRuleForm": "packages/response-ops/rule_form"
},
"translations": []
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,7 @@
"@kbn/resizable-layout-examples-plugin": "link:examples/resizable_layout_examples",
"@kbn/resolver-test-plugin": "link:x-pack/test/plugin_functional/plugins/resolver_test",
"@kbn/response-ops-feature-flag-service": "link:packages/response-ops/feature_flag_service",
"@kbn/response-ops-rule-form": "link:packages/response-ops/rule_form",
"@kbn/response-ops-rule-params": "link:packages/response-ops/rule_params",
"@kbn/response-stream-plugin": "link:examples/response_stream",
"@kbn/rison": "link:packages/kbn-rison",
Expand Down
7 changes: 7 additions & 0 deletions packages/kbn-alerts-ui-shared/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,10 @@ export type { AlertsSearchBarProps } from './src/alerts_search_bar/types';
export * from './src/alert_fields_table';
export * from './src/alert_filter_controls/types';
export * from './src/common/types';
export * from './src/common/i18n';
export * from './src/rule_settings';
export * from './src/common/type_registry';
export * from './src/check_action_type_enabled';
export * from './src/action_variables';

export { useFetchFlappingSettings } from './src/common/hooks/use_fetch_flapping_settings';
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import { ActionVariables, RuleType } from '@kbn/triggers-actions-ui-types';
import { transformActionVariables } from './transforms';
import { ALERTING_FEATURE_ID } from '../rule_form';
import { ALERTING_FEATURE_ID } from '../common/constants';

beforeEach(() => jest.resetAllMocks());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
*/

import { ActionType } from '@kbn/actions-types';
import { PreConfiguredActionConnector } from '../common/types';
import {
checkActionTypeEnabled,
checkActionFormActionTypeEnabled,
checkActionTypeEnabled,
} from './check_action_type_enabled';
import { PreConfiguredActionConnector } from '../../common';

describe('checkActionTypeEnabled', () => {
test(`returns isEnabled:true when action type isn't provided`, async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
*/

import { ActionType } from '@kbn/actions-types';
import { configurationCheckResult, getLicenseCheckResult } from './get_license_check_result';
import { ActionConnector } from '../../common';
import { ActionConnector } from '../common/types';
import './check_action_type_enabled.scss';
import { configurationCheckResult, getLicenseCheckResult } from './get_license_check_result';

export interface IsEnabledResult {
isEnabled: true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { i18n } from '@kbn/i18n';
import { EuiCard, EuiLink } from '@elastic/eui';
import { ActionType } from '@kbn/actions-types';
import { FormattedMessage } from '@kbn/i18n-react';
import { VIEW_LICENSE_OPTIONS_LINK } from '../../common/constants';
import { VIEW_LICENSE_OPTIONS_LINK } from '../common/constants';

export const getLicenseCheckResult = (actionType: ActionType) => {
return {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* 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", the "GNU Affero General Public License v3.0 only", 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", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

export * from './check_action_type_enabled';
7 changes: 2 additions & 5 deletions packages/kbn-alerts-ui-shared/src/common/apis/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,10 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

export * from './create_rule';
export * from './fetch_alerting_framework_health';
export * from './fetch_alerts_fields';
export * from './fetch_connector_types';
export * from './fetch_alerts_index_names';
export * from './fetch_connectors';
export * from './fetch_connector_types';
export * from './fetch_rule_type_aad_template_fields';
export * from './fetch_ui_config';
export * from './fetch_ui_health_status';
export * from './resolve_rule';
export * from './update_rule';
2 changes: 2 additions & 0 deletions packages/kbn-alerts-ui-shared/src/common/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ export * from './i18n_weekdays';
export * from './routes';

export const VIEW_LICENSE_OPTIONS_LINK = 'https://www.elastic.co/subscriptions';

export const ALERTING_FEATURE_ID = 'alerts';
8 changes: 0 additions & 8 deletions packages/kbn-alerts-ui-shared/src/common/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,9 @@
*/

export * from './use_alerts_data_view';
export * from './use_create_rule';
export * from './use_update_rule';
export * from './use_resolve_rule';
export * from './use_load_connectors';
export * from './use_load_connector_types';
export * from './use_get_alerts_group_aggregations_query';
export * from './use_health_check';
export * from './use_load_alerting_framework_health';
export * from './use_load_rule_types_query';
export * from './use_load_ui_config';
export * from './use_load_ui_health';
export * from './use_resolve_rule';
export * from './use_rule_aad_fields';
export * from './use_update_rule';
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/

import { useQuery } from '@tanstack/react-query';
import { HttpStart } from '@kbn/core-http-browser';
import type { HttpStart } from '@kbn/core-http-browser';
import { RulesSettingsFlapping } from '@kbn/alerting-types/rule_settings';
import { fetchFlappingSettings } from '../apis/fetch_flapping_settings';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,19 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import { keyBy } from 'lodash';
import { i18n } from '@kbn/i18n';
import { useMemo } from 'react';
import { useQuery } from '@tanstack/react-query';
import type { HttpStart } from '@kbn/core-http-browser';
import type { ToastsStart } from '@kbn/core-notifications-browser';
import { i18n } from '@kbn/i18n';
import type { RuleType } from '@kbn/triggers-actions-ui-types';
import { ALERTS_FEATURE_ID } from '../constants';
import {
RuleTypeIndexWithDescriptions,
RuleTypeWithDescription,
} from '@kbn/triggers-actions-ui-types';
import { useQuery } from '@tanstack/react-query';
import { keyBy } from 'lodash';
import { useMemo } from 'react';
import { fetchRuleTypes } from '../apis/fetch_rule_types';
import { RuleTypeIndexWithDescriptions, RuleTypeWithDescription } from '../types';
import { ALERTS_FEATURE_ID } from '../constants';

export interface UseRuleTypesProps {
http: HttpStart;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,3 @@
*/

export * from './transform_action';
export * from './transform_rule';
14 changes: 14 additions & 0 deletions packages/kbn-alerts-ui-shared/src/rule_settings/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* 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", the "GNU Affero General Public License v3.0 only", 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", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

export * from './rule_settings_flapping_form';
export * from './rule_settings_flapping_inputs';
export * from './rule_settings_flapping_message';
export * from './rule_settings_flapping_title_tooltip';
export * from './rule_settings_range_input';
22 changes: 3 additions & 19 deletions packages/kbn-alerts-ui-shared/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,10 @@
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"outDir": "target/types",
"types": [
"jest",
"node",
"react"
]
"types": ["jest", "node", "react"]
},
"include": [
"**/*.ts",
"**/*.tsx"
],
"exclude": [
"target/**/*"
],
"include": ["**/*.ts", "**/*.tsx"],
"exclude": ["target/**/*"],
"kbn_references": [
"@kbn/i18n",
"@kbn/rule-data-utils",
Expand All @@ -40,16 +31,9 @@
"@kbn/search-types",
"@kbn/utility-types",
"@kbn/safer-lodash-set",
"@kbn/core-application-browser",
"@kbn/react-kibana-mount",
"@kbn/core-i18n-browser",
"@kbn/core-theme-browser",
"@kbn/alerts-as-data-utils",
"@kbn/test-jest-helpers",
"@kbn/core-ui-settings-browser",
"@kbn/core-http-browser-mocks",
"@kbn/core-notifications-browser-mocks",
"@kbn/kibana-react-plugin",
"@kbn/shared-ux-table-persist"
]
}
2 changes: 1 addition & 1 deletion packages/kbn-optimizer/limits.yml
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ pageLoadAssetSize:
threatIntelligence: 44299
timelines: 327300
transform: 41007
triggersActionsUi: 135613
triggersActionsUi: 150000
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you please explain what happened here? why 150000?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Increased this beyond 139.3kb to give it a bit of breathing room. Haven't been able to figure out why we're getting a 10kb increase in triggersActionsUi, that's the best I was able to get it.

Plugin size is still reasonable so unless it's something obvious that someone else can spot quickly, I'd prefer not to devote more resources and to try and get this PR through

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have now somehow managed to decrease the bundle size by 1.5kb from main so I guess we're good here

uiActions: 35121
uiActionsEnhanced: 38494
unifiedDocViewer: 25099
Expand Down
4 changes: 4 additions & 0 deletions packages/kbn-triggers-actions-ui-types/rule_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,7 @@ export interface RuleType<
}

export type RuleTypeIndex = Map<string, RuleType>;

export type RuleTypeWithDescription = RuleType<string, string> & { description?: string };

export type RuleTypeIndexWithDescriptions = Map<string, RuleTypeWithDescription>;
3 changes: 3 additions & 0 deletions packages/response-ops/rule_form/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# @kbn/response-ops-rule-form

This package contains all components necessary to render the forms for creating and editing rules.
32 changes: 32 additions & 0 deletions packages/response-ops/rule_form/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* 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", the "GNU Affero General Public License v3.0 only", 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", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

export * from './src/types';
export * from './src/rule_type_modal';

export { RuleForm } from './src/rule_form';

export {
fetchUiConfig,
createRule,
updateRule,
type CreateRuleBody,
UPDATE_FIELDS_WITH_ACTIONS,
transformCreateRuleBody,
transformUpdateRuleBody,
resolveRule,
} from './src/common/apis';

export { CREATE_RULE_ROUTE, EDIT_RULE_ROUTE } from './src/constants';

export {
RuleActionsNotifyWhen,
RuleActionsAlertsFilter,
RuleActionsAlertsFilterTimeframe,
} from './src/rule_actions';
15 changes: 15 additions & 0 deletions packages/response-ops/rule_form/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* 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", the "GNU Affero General Public License v3.0 only", 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", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

module.exports = {
preset: '@kbn/test',
rootDir: '../../..',
roots: ['<rootDir>/packages/response-ops/rule_form'],
setupFilesAfterEnv: ['<rootDir>/packages/response-ops/rule_form/setup_tests.ts'],
};
5 changes: 5 additions & 0 deletions packages/response-ops/rule_form/kibana.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "shared-browser",
"id": "@kbn/response-ops-rule-form",
"owner": "@elastic/response-ops"
}
6 changes: 6 additions & 0 deletions packages/response-ops/rule_form/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "@kbn/response-ops-rule-form",
"private": true,
"version": "1.0.0",
"license": "Elastic License 2.0 OR AGPL-3.0-only OR SSPL-1.0"
}
11 changes: 11 additions & 0 deletions packages/response-ops/rule_form/setup_tests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* 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", the "GNU Affero General Public License v3.0 only", 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", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

// eslint-disable-next-line import/no-extraneous-dependencies
import '@testing-library/jest-dom';
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import type { HttpSetup } from '@kbn/core/public';
import type { AsApiContract } from '@kbn/actions-types';
import type { Rule } from '../../types';
import { CreateRuleBody, transformCreateRuleBody } from '.';
import { BASE_ALERTING_API_PATH } from '../../constants';
import { BASE_ALERTING_API_PATH } from '../../../constants';
import { transformRule } from '../../transformations';

export async function createRule({
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* 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", the "GNU Affero General Public License v3.0 only", 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", the "GNU Affero General Public
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import { HttpSetup } from '@kbn/core/public';
import type { AsApiContract, RewriteRequestCase } from '@kbn/actions-types';
import type { RuleType } from '@kbn/triggers-actions-ui-types';
import { BASE_ALERTING_API_PATH } from '../../constants';

const rewriteResponseRes = (results: Array<AsApiContract<RuleType>>): RuleType[] => {
return results.map((item) => rewriteBodyReq(item));
};

const rewriteBodyReq: RewriteRequestCase<RuleType> = ({
enabled_in_license: enabledInLicense,
recovery_action_group: recoveryActionGroup,
action_groups: actionGroups,
default_action_group_id: defaultActionGroupId,
minimum_license_required: minimumLicenseRequired,
action_variables: actionVariables,
authorized_consumers: authorizedConsumers,
rule_task_timeout: ruleTaskTimeout,
does_set_recovery_context: doesSetRecoveryContext,
default_schedule_interval: defaultScheduleInterval,
has_alerts_mappings: hasAlertsMappings,
has_fields_for_a_a_d: hasFieldsForAAD,
...rest
}: AsApiContract<RuleType>) => ({
enabledInLicense,
recoveryActionGroup,
actionGroups,
defaultActionGroupId,
minimumLicenseRequired,
actionVariables,
authorizedConsumers,
ruleTaskTimeout,
doesSetRecoveryContext,
defaultScheduleInterval,
hasAlertsMappings,
hasFieldsForAAD,
...rest,
});

export async function fetchRuleTypes({ http }: { http: HttpSetup }): Promise<RuleType[]> {
const res = await http.get<Array<AsApiContract<RuleType<string, string>>>>(
`${BASE_ALERTING_API_PATH}/rule_types`
);
return rewriteResponseRes(res);
}
Loading