diff --git a/.buildkite/scripts/steps/code_generation/security_solution_codegen.sh b/.buildkite/scripts/steps/code_generation/security_solution_codegen.sh index b36a9e52001e4..5a37c8a08d99a 100755 --- a/.buildkite/scripts/steps/code_generation/security_solution_codegen.sh +++ b/.buildkite/scripts/steps/code_generation/security_solution_codegen.sh @@ -6,5 +6,17 @@ source .buildkite/scripts/common/util.sh echo --- Security Solution OpenAPI Code Generation +echo OpenAPI Common Package + +(cd packages/kbn-openapi-common && yarn openapi:generate) +check_for_changed_files "yarn openapi:generate" true + +echo Lists API Common Package + +(cd packages/kbn-securitysolution-lists-common && yarn openapi:generate) +check_for_changed_files "yarn openapi:generate" true + +echo Security Solution Plugin + (cd x-pack/plugins/security_solution && yarn openapi:generate) check_for_changed_files "yarn openapi:generate" true \ No newline at end of file diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index a5fc58216acbf..b506f2488d310 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -621,6 +621,7 @@ x-pack/plugins/observability_solution/observability_shared @elastic/observabilit x-pack/test/security_api_integration/plugins/oidc_provider @elastic/kibana-security test/common/plugins/otel_metrics @elastic/obs-ux-infra_services-team packages/kbn-openapi-bundler @elastic/security-detection-rule-management +packages/kbn-openapi-common @elastic/security-detection-rule-management packages/kbn-openapi-generator @elastic/security-detection-rule-management packages/kbn-optimizer @elastic/kibana-operations packages/kbn-optimizer-webpack-helpers @elastic/kibana-operations @@ -751,6 +752,7 @@ packages/kbn-securitysolution-list-api @elastic/security-detection-engine packages/kbn-securitysolution-list-constants @elastic/security-detection-engine packages/kbn-securitysolution-list-hooks @elastic/security-detection-engine packages/kbn-securitysolution-list-utils @elastic/security-detection-engine +packages/kbn-securitysolution-lists-common @elastic/security-detection-engine packages/kbn-securitysolution-rules @elastic/security-detection-engine packages/kbn-securitysolution-t-grid @elastic/security-detection-engine packages/kbn-securitysolution-utils @elastic/security-detection-engine diff --git a/package.json b/package.json index 0c50f51a82f2e..3c127da92ed19 100644 --- a/package.json +++ b/package.json @@ -646,6 +646,7 @@ "@kbn/observability-shared-plugin": "link:x-pack/plugins/observability_solution/observability_shared", "@kbn/oidc-provider-plugin": "link:x-pack/test/security_api_integration/plugins/oidc_provider", "@kbn/open-telemetry-instrumented-plugin": "link:test/common/plugins/otel_metrics", + "@kbn/openapi-common": "link:packages/kbn-openapi-common", "@kbn/osquery-io-ts-types": "link:packages/kbn-osquery-io-ts-types", "@kbn/osquery-plugin": "link:x-pack/plugins/osquery", "@kbn/paertial-results-example-plugin": "link:examples/partial_results_example", @@ -761,6 +762,7 @@ "@kbn/securitysolution-list-constants": "link:packages/kbn-securitysolution-list-constants", "@kbn/securitysolution-list-hooks": "link:packages/kbn-securitysolution-list-hooks", "@kbn/securitysolution-list-utils": "link:packages/kbn-securitysolution-list-utils", + "@kbn/securitysolution-lists-common": "link:packages/kbn-securitysolution-lists-common", "@kbn/securitysolution-rules": "link:packages/kbn-securitysolution-rules", "@kbn/securitysolution-t-grid": "link:packages/kbn-securitysolution-t-grid", "@kbn/securitysolution-utils": "link:packages/kbn-securitysolution-utils", diff --git a/packages/kbn-openapi-common/README.md b/packages/kbn-openapi-common/README.md new file mode 100644 index 0000000000000..7199904b486be --- /dev/null +++ b/packages/kbn-openapi-common/README.md @@ -0,0 +1,3 @@ +# OpenAPI Common Schemas + +This package contains common reusable schemas like `NonEmptyString` to be reused by any OpenAPI specification defined inside Kibana. diff --git a/packages/kbn-openapi-common/kibana.jsonc b/packages/kbn-openapi-common/kibana.jsonc new file mode 100644 index 0000000000000..4254feb1b8a73 --- /dev/null +++ b/packages/kbn-openapi-common/kibana.jsonc @@ -0,0 +1,5 @@ +{ + "type": "shared-common", + "id": "@kbn/openapi-common", + "owner": "@elastic/security-detection-rule-management" +} diff --git a/packages/kbn-openapi-common/package.json b/packages/kbn-openapi-common/package.json new file mode 100644 index 0000000000000..c90099eacadf0 --- /dev/null +++ b/packages/kbn-openapi-common/package.json @@ -0,0 +1,11 @@ +{ + "description": "OpenAPI common schemas for Kibana", + "license": "SSPL-1.0 OR Elastic License 2.0", + "name": "@kbn/openapi-common", + "private": true, + "version": "1.0.0", + "scripts": { + "openapi:generate": "node scripts/openapi_generate" + } +} + diff --git a/packages/kbn-openapi-common/schemas/error_responses.gen.ts b/packages/kbn-openapi-common/schemas/error_responses.gen.ts new file mode 100644 index 0000000000000..1555dcbb612e1 --- /dev/null +++ b/packages/kbn-openapi-common/schemas/error_responses.gen.ts @@ -0,0 +1,31 @@ +/* + * 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. + */ + +/* + * NOTICE: Do not edit this file manually. + * This file is automatically generated by the OpenAPI Generator, @kbn/openapi-generator. + * + * info: + * title: Error response schemas + * version: not applicable + */ + +import { z } from 'zod'; + +export type PlatformErrorResponse = z.infer; +export const PlatformErrorResponse = z.object({ + statusCode: z.number().int(), + error: z.string(), + message: z.string(), +}); + +export type SiemErrorResponse = z.infer; +export const SiemErrorResponse = z.object({ + status_code: z.number().int(), + message: z.string(), +}); diff --git a/packages/kbn-openapi-common/schemas/error_responses.schema.yaml b/packages/kbn-openapi-common/schemas/error_responses.schema.yaml new file mode 100644 index 0000000000000..9574103b9411e --- /dev/null +++ b/packages/kbn-openapi-common/schemas/error_responses.schema.yaml @@ -0,0 +1,32 @@ +openapi: 3.0.0 +info: + title: Error response schemas + version: 'not applicable' +paths: {} +components: + x-codegen-enabled: true + schemas: + PlatformErrorResponse: + type: object + properties: + statusCode: + type: integer + error: + type: string + message: + type: string + required: + - statusCode + - error + - message + + SiemErrorResponse: + type: object + properties: + status_code: + type: integer + message: + type: string + required: + - status_code + - message diff --git a/packages/kbn-openapi-common/schemas/primitives.gen.ts b/packages/kbn-openapi-common/schemas/primitives.gen.ts new file mode 100644 index 0000000000000..a9027448d7e77 --- /dev/null +++ b/packages/kbn-openapi-common/schemas/primitives.gen.ts @@ -0,0 +1,33 @@ +/* + * 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. + */ + +/* + * NOTICE: Do not edit this file manually. + * This file is automatically generated by the OpenAPI Generator, @kbn/openapi-generator. + * + * info: + * title: Shared Primitives Schema + * version: not applicable + */ + +import { z } from 'zod'; + +/** + * A string that is not empty and does not contain only whitespace + */ +export type NonEmptyString = z.infer; +export const NonEmptyString = z + .string() + .min(1) + .regex(/^(?! *$).+$/); + +/** + * A universally unique identifier + */ +export type UUID = z.infer; +export const UUID = z.string().uuid(); diff --git a/packages/kbn-openapi-common/schemas/primitives.schema.yaml b/packages/kbn-openapi-common/schemas/primitives.schema.yaml new file mode 100644 index 0000000000000..177ad2ed30ecc --- /dev/null +++ b/packages/kbn-openapi-common/schemas/primitives.schema.yaml @@ -0,0 +1,18 @@ +openapi: 3.0.0 +info: + title: Shared Primitives Schema + version: 'not applicable' +paths: {} +components: + x-codegen-enabled: true + schemas: + NonEmptyString: + type: string + pattern: ^(?! *$).+$ + minLength: 1 + description: A string that is not empty and does not contain only whitespace + + UUID: + type: string + format: uuid + description: A universally unique identifier diff --git a/packages/kbn-openapi-common/scripts/openapi_generate.js b/packages/kbn-openapi-common/scripts/openapi_generate.js new file mode 100644 index 0000000000000..e8e7ffca22ede --- /dev/null +++ b/packages/kbn-openapi-common/scripts/openapi_generate.js @@ -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. + */ + +require('../../../src/setup_node_env'); +const { resolve } = require('path'); +const { generate } = require('@kbn/openapi-generator'); + +const ROOT = resolve(__dirname, '..'); + +(async () => { + await generate({ + title: 'OpenAPI Common Schemas (kbn-openapi-common)', + rootDir: ROOT, + sourceGlob: './schemas/**/*.schema.yaml', + templateName: 'zod_operation_schema', + }); +})(); diff --git a/packages/kbn-openapi-common/tsconfig.json b/packages/kbn-openapi-common/tsconfig.json new file mode 100644 index 0000000000000..168274f98f058 --- /dev/null +++ b/packages/kbn-openapi-common/tsconfig.json @@ -0,0 +1,10 @@ +{ + "compilerOptions": { + "outDir": "target/types", + "types": ["jest", "node"] + }, + "exclude": ["target/**/*"], + "extends": "../../tsconfig.base.json", + "include": ["**/*.ts"], + "kbn_references": [] +} diff --git a/packages/kbn-securitysolution-lists-common/README.md b/packages/kbn-securitysolution-lists-common/README.md new file mode 100644 index 0000000000000..4b7fbddc3ea06 --- /dev/null +++ b/packages/kbn-securitysolution-lists-common/README.md @@ -0,0 +1,20 @@ +# Security Solution Lists common package + +The package contains common files for the Lists feature. + +`common` in the name highlights that this package is intended to combine any common entities related to Lists in this package. E.g. the other `kbn-securitysolution-list-*` packages +content should be moved here while `kbn-securitysolution-io-ts-list-types` package should be +gone eventually. + +## API folder + +`api` folder contains OpenAPI schemas for Security Solution Lists feature. There are automatically generated Zod schemas and TS types for each schemas located in corresponding +`*.gen.ts` files. + +**Please add any Lists feature related schemas to this package.** + +TS types and/or Zod schemas can be imported in a plugin or another package like + +```ts +import { CreateListRequestBody } from '@kbn/securitysolution-lists-common/api'; +``` diff --git a/packages/kbn-securitysolution-lists-common/api/create_list/create_list.gen.ts b/packages/kbn-securitysolution-lists-common/api/create_list/create_list.gen.ts new file mode 100644 index 0000000000000..22c4a1c47bb8a --- /dev/null +++ b/packages/kbn-securitysolution-lists-common/api/create_list/create_list.gen.ts @@ -0,0 +1,43 @@ +/* + * 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. + */ + +/* + * NOTICE: Do not edit this file manually. + * This file is automatically generated by the OpenAPI Generator, @kbn/openapi-generator. + * + * info: + * title: Create list API endpoint + * version: 2023-10-31 + */ + +import { z } from 'zod'; + +import { + ListId, + ListName, + ListDescription, + ListType, + ListMetadata, +} from '../model/list_common.gen'; +import { List } from '../model/list_schemas.gen'; + +export type CreateListRequestBody = z.infer; +export const CreateListRequestBody = z.object({ + id: ListId.optional(), + name: ListName, + description: ListDescription, + type: ListType, + serializer: z.string().optional(), + deserializer: z.string().optional(), + meta: ListMetadata.optional(), + version: z.number().int().min(1).optional().default(1), +}); +export type CreateListRequestBodyInput = z.input; + +export type CreateListResponse = z.infer; +export const CreateListResponse = List; diff --git a/packages/kbn-securitysolution-lists-common/api/create_list/create_list.schema.yaml b/packages/kbn-securitysolution-lists-common/api/create_list/create_list.schema.yaml new file mode 100644 index 0000000000000..0cd635c46ff7f --- /dev/null +++ b/packages/kbn-securitysolution-lists-common/api/create_list/create_list.schema.yaml @@ -0,0 +1,82 @@ +openapi: 3.0.0 +info: + title: Create list API endpoint + version: '2023-10-31' +paths: + /api/lists: + post: + x-labels: [serverless, ess] + operationId: CreateList + x-codegen-enabled: true + summary: Creates a list + tags: + - List API + requestBody: + description: List's properties + required: true + content: + application/json: + schema: + type: object + properties: + id: + $ref: '../model/list_common.schema.yaml#/components/schemas/ListId' + name: + $ref: '../model/list_common.schema.yaml#/components/schemas/ListName' + description: + $ref: '../model/list_common.schema.yaml#/components/schemas/ListDescription' + type: + $ref: '../model/list_common.schema.yaml#/components/schemas/ListType' + serializer: + type: string + deserializer: + type: string + meta: + $ref: '../model/list_common.schema.yaml#/components/schemas/ListMetadata' + version: + type: integer + minimum: 1 + default: 1 + required: + - name + - description + - type + responses: + 200: + description: Successful response + content: + application/json: + schema: + $ref: '../model/list_schemas.schema.yaml#/components/schemas/List' + 400: + description: Invalid input data response + content: + application/json: + schema: + oneOf: + - $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + - $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' + 401: + description: Unsuccessful authentication response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + 403: + description: Not enough privileges response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + 409: + description: List already exists response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' + 500: + description: Internal server error response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' diff --git a/packages/kbn-securitysolution-lists-common/api/create_list_index/create_list_index.gen.ts b/packages/kbn-securitysolution-lists-common/api/create_list_index/create_list_index.gen.ts new file mode 100644 index 0000000000000..b2217f2016422 --- /dev/null +++ b/packages/kbn-securitysolution-lists-common/api/create_list_index/create_list_index.gen.ts @@ -0,0 +1,23 @@ +/* + * 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. + */ + +/* + * NOTICE: Do not edit this file manually. + * This file is automatically generated by the OpenAPI Generator, @kbn/openapi-generator. + * + * info: + * title: Create list DS API endpoint + * version: 2023-10-31 + */ + +import { z } from 'zod'; + +export type CreateListIndexResponse = z.infer; +export const CreateListIndexResponse = z.object({ + acknowledged: z.boolean(), +}); diff --git a/packages/kbn-securitysolution-lists-common/api/create_list_index/create_list_index.schema.yaml b/packages/kbn-securitysolution-lists-common/api/create_list_index/create_list_index.schema.yaml new file mode 100644 index 0000000000000..f42937a8885d2 --- /dev/null +++ b/packages/kbn-securitysolution-lists-common/api/create_list_index/create_list_index.schema.yaml @@ -0,0 +1,56 @@ +openapi: 3.0.0 +info: + title: Create list DS API endpoint + version: '2023-10-31' +paths: + /api/lists/index: + post: + x-labels: [serverless, ess] + operationId: CreateListIndex + x-codegen-enabled: true + summary: Creates necessary list data streams + tags: + - List API + responses: + 200: + description: Successful response + content: + application/json: + schema: + type: object + properties: + acknowledged: + type: boolean + required: [acknowledged] + 400: + description: Invalid input data response + content: + application/json: + schema: + oneOf: + - $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + - $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' + 401: + description: Unsuccessful authentication response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + 403: + description: Not enough privileges response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + 409: + description: List data stream exists response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' + 500: + description: Internal server error response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' diff --git a/packages/kbn-securitysolution-lists-common/api/create_list_item/create_list_item.gen.ts b/packages/kbn-securitysolution-lists-common/api/create_list_item/create_list_item.gen.ts new file mode 100644 index 0000000000000..94e1be2171921 --- /dev/null +++ b/packages/kbn-securitysolution-lists-common/api/create_list_item/create_list_item.gen.ts @@ -0,0 +1,37 @@ +/* + * 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. + */ + +/* + * NOTICE: Do not edit this file manually. + * This file is automatically generated by the OpenAPI Generator, @kbn/openapi-generator. + * + * info: + * title: Create list item API endpoint + * version: 2023-10-31 + */ + +import { z } from 'zod'; + +import { ListItemId, ListId, ListItemValue, ListItemMetadata } from '../model/list_common.gen'; +import { ListItem } from '../model/list_schemas.gen'; + +export type CreateListItemRequestBody = z.infer; +export const CreateListItemRequestBody = z.object({ + id: ListItemId.optional(), + list_id: ListId, + value: ListItemValue, + meta: ListItemMetadata.optional(), + /** + * Determines when changes made by the request are made visible to search + */ + refresh: z.enum(['true', 'false', 'wait_for']).optional(), +}); +export type CreateListItemRequestBodyInput = z.input; + +export type CreateListItemResponse = z.infer; +export const CreateListItemResponse = ListItem; diff --git a/packages/kbn-securitysolution-lists-common/api/create_list_item/create_list_item.schema.yaml b/packages/kbn-securitysolution-lists-common/api/create_list_item/create_list_item.schema.yaml new file mode 100644 index 0000000000000..ca75b8555b9c4 --- /dev/null +++ b/packages/kbn-securitysolution-lists-common/api/create_list_item/create_list_item.schema.yaml @@ -0,0 +1,78 @@ +openapi: 3.0.0 +info: + title: Create list item API endpoint + version: '2023-10-31' +paths: + /api/lists/items: + post: + x-labels: [serverless, ess] + operationId: CreateListItem + x-codegen-enabled: true + summary: Creates a list item + tags: + - List item API + requestBody: + description: List item's properties + required: true + content: + application/json: + schema: + type: object + properties: + id: + $ref: '../model/list_common.schema.yaml#/components/schemas/ListItemId' + list_id: + $ref: '../model/list_common.schema.yaml#/components/schemas/ListId' + value: + $ref: '../model/list_common.schema.yaml#/components/schemas/ListItemValue' + meta: + $ref: '../model/list_common.schema.yaml#/components/schemas/ListItemMetadata' + refresh: + type: string + enum: + - 'true' + - 'false' + - wait_for + description: Determines when changes made by the request are made visible to search + required: + - list_id + - value + responses: + 200: + description: Successful response + content: + application/json: + schema: + $ref: '../model/list_schemas.schema.yaml#/components/schemas/ListItem' + 400: + description: Invalid input data response + content: + application/json: + schema: + oneOf: + - $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + - $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' + 401: + description: Unsuccessful authentication response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + 403: + description: Not enough privileges response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + 409: + description: List item already exists response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' + 500: + description: Internal server error response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' diff --git a/packages/kbn-securitysolution-lists-common/api/delete_list/delete_list.gen.ts b/packages/kbn-securitysolution-lists-common/api/delete_list/delete_list.gen.ts new file mode 100644 index 0000000000000..fe058928eca0b --- /dev/null +++ b/packages/kbn-securitysolution-lists-common/api/delete_list/delete_list.gen.ts @@ -0,0 +1,36 @@ +/* + * 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. + */ + +/* + * NOTICE: Do not edit this file manually. + * This file is automatically generated by the OpenAPI Generator, @kbn/openapi-generator. + * + * info: + * title: Delete list API endpoint + * version: 2023-10-31 + */ + +import { z } from 'zod'; +import { BooleanFromString } from '@kbn/zod-helpers'; + +import { ListId } from '../model/list_common.gen'; +import { List } from '../model/list_schemas.gen'; + +export type DeleteListRequestQuery = z.infer; +export const DeleteListRequestQuery = z.object({ + /** + * List's `id` value + */ + id: ListId, + deleteReferences: BooleanFromString.optional().default(false), + ignoreReferences: BooleanFromString.optional().default(false), +}); +export type DeleteListRequestQueryInput = z.input; + +export type DeleteListResponse = z.infer; +export const DeleteListResponse = List; diff --git a/packages/kbn-securitysolution-lists-common/api/delete_list/delete_list.schema.yaml b/packages/kbn-securitysolution-lists-common/api/delete_list/delete_list.schema.yaml new file mode 100644 index 0000000000000..c116d43edd93a --- /dev/null +++ b/packages/kbn-securitysolution-lists-common/api/delete_list/delete_list.schema.yaml @@ -0,0 +1,71 @@ +openapi: 3.0.0 +info: + title: Delete list API endpoint + version: '2023-10-31' +paths: + /api/lists: + delete: + x-labels: [serverless, ess] + operationId: DeleteList + x-codegen-enabled: true + summary: Deletes a list + tags: + - List API + parameters: + - name: id + in: query + required: true + description: List's `id` value + schema: + $ref: '../model/list_common.schema.yaml#/components/schemas/ListId' + - name: deleteReferences + in: query + required: false + schema: + type: boolean + default: false + - name: ignoreReferences + in: query + required: false + schema: + type: boolean + default: false + responses: + 200: + description: Successful response + content: + application/json: + schema: + $ref: '../model/list_schemas.schema.yaml#/components/schemas/List' + 400: + description: Invalid input data response + content: + application/json: + schema: + oneOf: + - $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + - $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' + 401: + description: Unsuccessful authentication response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + 403: + description: Not enough privileges response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + 404: + description: List not found response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' + 500: + description: Internal server error response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' diff --git a/packages/kbn-securitysolution-lists-common/api/delete_list_index/delete_list_index.gen.ts b/packages/kbn-securitysolution-lists-common/api/delete_list_index/delete_list_index.gen.ts new file mode 100644 index 0000000000000..3be609d0b8a92 --- /dev/null +++ b/packages/kbn-securitysolution-lists-common/api/delete_list_index/delete_list_index.gen.ts @@ -0,0 +1,23 @@ +/* + * 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. + */ + +/* + * NOTICE: Do not edit this file manually. + * This file is automatically generated by the OpenAPI Generator, @kbn/openapi-generator. + * + * info: + * title: Delete list DS API endpoint + * version: 2023-10-31 + */ + +import { z } from 'zod'; + +export type DeleteListIndexResponse = z.infer; +export const DeleteListIndexResponse = z.object({ + acknowledged: z.boolean(), +}); diff --git a/packages/kbn-securitysolution-lists-common/api/delete_list_index/delete_list_index.schema.yaml b/packages/kbn-securitysolution-lists-common/api/delete_list_index/delete_list_index.schema.yaml new file mode 100644 index 0000000000000..c3b4969aa3283 --- /dev/null +++ b/packages/kbn-securitysolution-lists-common/api/delete_list_index/delete_list_index.schema.yaml @@ -0,0 +1,56 @@ +openapi: 3.0.0 +info: + title: Delete list DS API endpoint + version: '2023-10-31' +paths: + /api/lists/index: + delete: + x-labels: [serverless, ess] + operationId: DeleteListIndex + x-codegen-enabled: true + summary: Deletes list data streams + tags: + - List API + responses: + 200: + description: Successful response + content: + application/json: + schema: + type: object + properties: + acknowledged: + type: boolean + required: [acknowledged] + 400: + description: Invalid input data response + content: + application/json: + schema: + oneOf: + - $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + - $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' + 401: + description: Unsuccessful authentication response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + 403: + description: Not enough privileges response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + 404: + description: List data stream not found response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' + 500: + description: Internal server error response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' diff --git a/packages/kbn-securitysolution-lists-common/api/delete_list_item/delete_list_item.gen.ts b/packages/kbn-securitysolution-lists-common/api/delete_list_item/delete_list_item.gen.ts new file mode 100644 index 0000000000000..d94b2f18d6158 --- /dev/null +++ b/packages/kbn-securitysolution-lists-common/api/delete_list_item/delete_list_item.gen.ts @@ -0,0 +1,45 @@ +/* + * 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. + */ + +/* + * NOTICE: Do not edit this file manually. + * This file is automatically generated by the OpenAPI Generator, @kbn/openapi-generator. + * + * info: + * title: Delete list item API endpoint + * version: 2023-10-31 + */ + +import { z } from 'zod'; + +import { ListId } from '../model/list_common.gen'; +import { ListItem } from '../model/list_schemas.gen'; + +export type DeleteListItemRequestQuery = z.infer; +export const DeleteListItemRequestQuery = z.object({ + /** + * Required if `list_id` and `value` are not specified + */ + id: ListId.optional(), + /** + * Required if `id` is not specified + */ + list_id: ListId.optional(), + /** + * Required if `id` is not specified + */ + value: z.string().optional(), + /** + * Determines when changes made by the request are made visible to search + */ + refresh: z.enum(['true', 'false', 'wait_for']).optional().default('false'), +}); +export type DeleteListItemRequestQueryInput = z.input; + +export type DeleteListItemResponse = z.infer; +export const DeleteListItemResponse = z.union([ListItem, z.array(ListItem)]); diff --git a/packages/kbn-securitysolution-lists-common/api/delete_list_item/delete_list_item.schema.yaml b/packages/kbn-securitysolution-lists-common/api/delete_list_item/delete_list_item.schema.yaml new file mode 100644 index 0000000000000..63938d313aea2 --- /dev/null +++ b/packages/kbn-securitysolution-lists-common/api/delete_list_item/delete_list_item.schema.yaml @@ -0,0 +1,83 @@ +openapi: 3.0.0 +info: + title: Delete list item API endpoint + version: '2023-10-31' +paths: + /api/lists/items: + delete: + x-labels: [serverless, ess] + operationId: DeleteListItem + x-codegen-enabled: true + summary: Deletes a list item + tags: + - List item API + parameters: + - name: id + in: query + required: false + description: Required if `list_id` and `value` are not specified + schema: + $ref: '../model/list_common.schema.yaml#/components/schemas/ListId' + - name: list_id + in: query + required: false + description: Required if `id` is not specified + schema: + $ref: '../model/list_common.schema.yaml#/components/schemas/ListId' + - name: value + in: query + required: false + description: Required if `id` is not specified + schema: + type: string + - name: refresh + in: query + required: false + description: Determines when changes made by the request are made visible to search + schema: + type: string + enum: ['true', 'false', 'wait_for'] + default: 'false' + responses: + 200: + description: Successful response + content: + application/json: + schema: + oneOf: + - $ref: '../model/list_schemas.schema.yaml#/components/schemas/ListItem' + - type: array + items: + $ref: '../model/list_schemas.schema.yaml#/components/schemas/ListItem' + 400: + description: Invalid input data response + content: + application/json: + schema: + oneOf: + - $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + - $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' + 401: + description: Unsuccessful authentication response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + 403: + description: Not enough privileges response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + 404: + description: List item not found response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' + 500: + description: Internal server error response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' diff --git a/packages/kbn-securitysolution-lists-common/api/export_list_item/export_list_item.gen.ts b/packages/kbn-securitysolution-lists-common/api/export_list_item/export_list_item.gen.ts new file mode 100644 index 0000000000000..0e831e0887bd0 --- /dev/null +++ b/packages/kbn-securitysolution-lists-common/api/export_list_item/export_list_item.gen.ts @@ -0,0 +1,29 @@ +/* + * 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. + */ + +/* + * NOTICE: Do not edit this file manually. + * This file is automatically generated by the OpenAPI Generator, @kbn/openapi-generator. + * + * info: + * title: Export list items API endpoint + * version: 2023-10-31 + */ + +import { z } from 'zod'; + +import { ListId } from '../model/list_common.gen'; + +export type ExportListItemsRequestQuery = z.infer; +export const ExportListItemsRequestQuery = z.object({ + /** + * List's id to export + */ + list_id: ListId, +}); +export type ExportListItemsRequestQueryInput = z.input; diff --git a/packages/kbn-securitysolution-lists-common/api/export_list_item/export_list_item.schema.yaml b/packages/kbn-securitysolution-lists-common/api/export_list_item/export_list_item.schema.yaml new file mode 100644 index 0000000000000..26708a18a899a --- /dev/null +++ b/packages/kbn-securitysolution-lists-common/api/export_list_item/export_list_item.schema.yaml @@ -0,0 +1,61 @@ +openapi: 3.0.0 +info: + title: Export list items API endpoint + version: '2023-10-31' +paths: + /api/lists/items/_export: + post: + operationId: ExportListItems + x-codegen-enabled: true + summary: Exports list items + description: Exports list item values from the specified list + tags: + - List items Import/Export API + parameters: + - name: list_id + in: query + required: true + description: List's id to export + schema: + $ref: '../model/list_common.schema.yaml#/components/schemas/ListId' + responses: + 200: + description: Successful response + content: + application/ndjson: + schema: + type: string + format: binary + description: A `.txt` file containing list items from the specified list + 400: + description: Invalid input data response + content: + application/json: + schema: + oneOf: + - $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + - $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' + 401: + description: Unsuccessful authentication response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + 403: + description: Not enough privileges response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + 404: + description: List not found response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' + 500: + description: Internal server error response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' diff --git a/packages/kbn-securitysolution-lists-common/api/find_list/find_list.gen.ts b/packages/kbn-securitysolution-lists-common/api/find_list/find_list.gen.ts new file mode 100644 index 0000000000000..22bd50fcf0f35 --- /dev/null +++ b/packages/kbn-securitysolution-lists-common/api/find_list/find_list.gen.ts @@ -0,0 +1,70 @@ +/* + * 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. + */ + +/* + * NOTICE: Do not edit this file manually. + * This file is automatically generated by the OpenAPI Generator, @kbn/openapi-generator. + * + * info: + * title: Find lists API endpoint + * version: 2023-10-31 + */ + +import { z } from 'zod'; + +import { NonEmptyString } from '@kbn/openapi-common/schemas/primitives.gen'; +import { List } from '../model/list_schemas.gen'; + +export type FindListsCursor = z.infer; +export const FindListsCursor = NonEmptyString; + +export type FindListsFilter = z.infer; +export const FindListsFilter = NonEmptyString; + +export type FindListsRequestQuery = z.infer; +export const FindListsRequestQuery = z.object({ + /** + * The page number to return + */ + page: z.coerce.number().int().optional(), + /** + * The number of lists to return per page + */ + per_page: z.coerce.number().int().optional(), + /** + * Determines which field is used to sort the results + */ + sort_field: NonEmptyString.optional(), + /** + * Determines the sort order, which can be `desc` or `asc` + */ + sort_order: z.enum(['desc', 'asc']).optional(), + /** + * Returns the list that come after the last list returned in the previous call +(use the cursor value returned in the previous call). This parameter uses +the `tie_breaker_id` field to ensure all lists are sorted and returned correctly. + + */ + cursor: FindListsCursor.optional(), + /** + * Filters the returned results according to the value of the specified field, +using the : syntax. + + */ + filter: FindListsFilter.optional(), +}); +export type FindListsRequestQueryInput = z.input; + +export type FindListsResponse = z.infer; +export const FindListsResponse = z.object({ + data: z.array(List), + page: z.number().int().min(0), + per_page: z.number().int().min(0), + total: z.number().int().min(0), + cursor: FindListsCursor, +}); diff --git a/packages/kbn-securitysolution-lists-common/api/find_list/find_list.schema.yaml b/packages/kbn-securitysolution-lists-common/api/find_list/find_list.schema.yaml new file mode 100644 index 0000000000000..7fa5f1ac581ac --- /dev/null +++ b/packages/kbn-securitysolution-lists-common/api/find_list/find_list.schema.yaml @@ -0,0 +1,119 @@ +openapi: 3.0.0 +info: + title: Find lists API endpoint + version: '2023-10-31' +paths: + /api/lists/_find: + get: + x-labels: [serverless, ess] + operationId: FindLists + x-codegen-enabled: true + summary: Finds lists + tags: + - List API + parameters: + - name: page + in: query + required: false + description: The page number to return + schema: + type: integer + - name: per_page + in: query + required: false + description: The number of lists to return per page + schema: + type: integer + - name: sort_field + in: query + required: false + description: Determines which field is used to sort the results + schema: + $ref: '../../../kbn-openapi-common/schemas/primitives.schema.yaml#/components/schemas/NonEmptyString' + - name: sort_order + in: query + required: false + description: Determines the sort order, which can be `desc` or `asc` + schema: + type: string + enum: [desc, asc] + - name: cursor + in: query + required: false + description: | + Returns the list that come after the last list returned in the previous call + (use the cursor value returned in the previous call). This parameter uses + the `tie_breaker_id` field to ensure all lists are sorted and returned correctly. + schema: + $ref: '#/components/schemas/FindListsCursor' + - name: filter + in: query + required: false + description: | + Filters the returned results according to the value of the specified field, + using the : syntax. + schema: + $ref: '#/components/schemas/FindListsFilter' + responses: + 200: + description: Successful response + content: + application/json: + schema: + type: object + properties: + data: + type: array + items: + $ref: '../model/list_schemas.schema.yaml#/components/schemas/List' + page: + type: integer + minimum: 0 + per_page: + type: integer + minimum: 0 + total: + type: integer + minimum: 0 + cursor: + $ref: '#/components/schemas/FindListsCursor' + required: + - data + - page + - per_page + - total + - cursor + 400: + description: Invalid input data response + content: + application/json: + schema: + oneOf: + - $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + - $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' + 401: + description: Unsuccessful authentication response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + 403: + description: Not enough privileges response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + 500: + description: Internal server error response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' + +components: + schemas: + FindListsCursor: + $ref: '../../../kbn-openapi-common/schemas/primitives.schema.yaml#/components/schemas/NonEmptyString' + + FindListsFilter: + $ref: '../../../kbn-openapi-common/schemas/primitives.schema.yaml#/components/schemas/NonEmptyString' diff --git a/packages/kbn-securitysolution-lists-common/api/find_list_item/find_list_item.gen.ts b/packages/kbn-securitysolution-lists-common/api/find_list_item/find_list_item.gen.ts new file mode 100644 index 0000000000000..ef23adf7a7dcd --- /dev/null +++ b/packages/kbn-securitysolution-lists-common/api/find_list_item/find_list_item.gen.ts @@ -0,0 +1,75 @@ +/* + * 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. + */ + +/* + * NOTICE: Do not edit this file manually. + * This file is automatically generated by the OpenAPI Generator, @kbn/openapi-generator. + * + * info: + * title: Find list items API endpoint + * version: 2023-10-31 + */ + +import { z } from 'zod'; + +import { NonEmptyString } from '@kbn/openapi-common/schemas/primitives.gen'; +import { ListId } from '../model/list_common.gen'; +import { ListItem } from '../model/list_schemas.gen'; + +export type FindListItemsCursor = z.infer; +export const FindListItemsCursor = NonEmptyString; + +export type FindListItemsFilter = z.infer; +export const FindListItemsFilter = NonEmptyString; + +export type FindListItemsRequestQuery = z.infer; +export const FindListItemsRequestQuery = z.object({ + /** + * List's ide + */ + list_id: ListId, + /** + * The page number to return + */ + page: z.coerce.number().int().optional(), + /** + * The number of list items to return per page + */ + per_page: z.coerce.number().int().optional(), + /** + * Determines which field is used to sort the results + */ + sort_field: NonEmptyString.optional(), + /** + * Determines the sort order, which can be `desc` or `asc` + */ + sort_order: z.enum(['desc', 'asc']).optional(), + /** + * Returns the list that come after the last list returned in the previous call +(use the cursor value returned in the previous call). This parameter uses +the `tie_breaker_id` field to ensure all lists are sorted and returned correctly. + + */ + cursor: FindListItemsCursor.optional(), + /** + * Filters the returned results according to the value of the specified field, +using the : syntax. + + */ + filter: FindListItemsFilter.optional(), +}); +export type FindListItemsRequestQueryInput = z.input; + +export type FindListItemsResponse = z.infer; +export const FindListItemsResponse = z.object({ + data: z.array(ListItem), + page: z.number().int().min(0), + per_page: z.number().int().min(0), + total: z.number().int().min(0), + cursor: FindListItemsCursor, +}); diff --git a/packages/kbn-securitysolution-lists-common/api/find_list_item/find_list_item.schema.yaml b/packages/kbn-securitysolution-lists-common/api/find_list_item/find_list_item.schema.yaml new file mode 100644 index 0000000000000..92dbc361b7ad2 --- /dev/null +++ b/packages/kbn-securitysolution-lists-common/api/find_list_item/find_list_item.schema.yaml @@ -0,0 +1,125 @@ +openapi: 3.0.0 +info: + title: Find list items API endpoint + version: '2023-10-31' +paths: + /api/lists/_find: + get: + x-labels: [serverless, ess] + operationId: FindListItems + x-codegen-enabled: true + summary: Finds list items + tags: + - List API + parameters: + - name: list_id + in: query + required: true + description: List's ide + schema: + $ref: '../model/list_common.schema.yaml#/components/schemas/ListId' + - name: page + in: query + required: false + description: The page number to return + schema: + type: integer + - name: per_page + in: query + required: false + description: The number of list items to return per page + schema: + type: integer + - name: sort_field + in: query + required: false + description: Determines which field is used to sort the results + schema: + $ref: '../../../kbn-openapi-common/schemas/primitives.schema.yaml#/components/schemas/NonEmptyString' + - name: sort_order + in: query + required: false + description: Determines the sort order, which can be `desc` or `asc` + schema: + type: string + enum: [desc, asc] + - name: cursor + in: query + required: false + description: | + Returns the list that come after the last list returned in the previous call + (use the cursor value returned in the previous call). This parameter uses + the `tie_breaker_id` field to ensure all lists are sorted and returned correctly. + schema: + $ref: '#/components/schemas/FindListItemsCursor' + - name: filter + in: query + required: false + description: | + Filters the returned results according to the value of the specified field, + using the : syntax. + schema: + $ref: '#/components/schemas/FindListItemsFilter' + responses: + 200: + description: Successful response + content: + application/json: + schema: + type: object + properties: + data: + type: array + items: + $ref: '../model/list_schemas.schema.yaml#/components/schemas/ListItem' + page: + type: integer + minimum: 0 + per_page: + type: integer + minimum: 0 + total: + type: integer + minimum: 0 + cursor: + $ref: '#/components/schemas/FindListItemsCursor' + required: + - data + - page + - per_page + - total + - cursor + 400: + description: Invalid input data response + content: + application/json: + schema: + oneOf: + - $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + - $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' + 401: + description: Unsuccessful authentication response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + 403: + description: Not enough privileges response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + 500: + description: Internal server error response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' + +components: + schemas: + FindListItemsCursor: + $ref: '../../../kbn-openapi-common/schemas/primitives.schema.yaml#/components/schemas/NonEmptyString' + + FindListItemsFilter: + $ref: '../../../kbn-openapi-common/schemas/primitives.schema.yaml#/components/schemas/NonEmptyString' diff --git a/packages/kbn-securitysolution-lists-common/api/get_list_privileges/get_list_privileges.gen.ts b/packages/kbn-securitysolution-lists-common/api/get_list_privileges/get_list_privileges.gen.ts new file mode 100644 index 0000000000000..3fe6348242822 --- /dev/null +++ b/packages/kbn-securitysolution-lists-common/api/get_list_privileges/get_list_privileges.gen.ts @@ -0,0 +1,43 @@ +/* + * 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. + */ + +/* + * NOTICE: Do not edit this file manually. + * This file is automatically generated by the OpenAPI Generator, @kbn/openapi-generator. + * + * info: + * title: Get list privileges API endpoint + * version: 2023-10-31 + */ + +import { z } from 'zod'; + +export type ListPrivileges = z.infer; +export const ListPrivileges = z.object({ + username: z.string(), + has_all_requested: z.boolean(), + cluster: z.object({}).catchall(z.boolean()), + index: z.object({}).catchall(z.object({}).catchall(z.boolean())), + application: z.object({}).catchall(z.boolean()), +}); + +export type ListItemPrivileges = z.infer; +export const ListItemPrivileges = z.object({ + username: z.string(), + has_all_requested: z.boolean(), + cluster: z.object({}).catchall(z.boolean()), + index: z.object({}).catchall(z.object({}).catchall(z.boolean())), + application: z.object({}).catchall(z.boolean()), +}); + +export type GetListPrivilegesResponse = z.infer; +export const GetListPrivilegesResponse = z.object({ + lists: ListPrivileges, + listItems: ListItemPrivileges, + is_authenticated: z.boolean(), +}); diff --git a/packages/kbn-securitysolution-lists-common/api/get_list_privileges/get_list_privileges.schema.yaml b/packages/kbn-securitysolution-lists-common/api/get_list_privileges/get_list_privileges.schema.yaml new file mode 100644 index 0000000000000..729da9b8f62a8 --- /dev/null +++ b/packages/kbn-securitysolution-lists-common/api/get_list_privileges/get_list_privileges.schema.yaml @@ -0,0 +1,115 @@ +openapi: 3.0.0 +info: + title: Get list privileges API endpoint + version: '2023-10-31' +paths: + /api/lists/privileges: + get: + x-labels: [serverless, ess] + operationId: GetListPrivileges + x-codegen-enabled: true + summary: Gets list privileges + tags: + - List API + responses: + 200: + description: Successful response + content: + application/json: + schema: + type: object + properties: + lists: + $ref: '#/components/schemas/ListPrivileges' + listItems: + $ref: '#/components/schemas/ListItemPrivileges' + is_authenticated: + type: boolean + required: + - lists + - listItems + - is_authenticated + 400: + description: Invalid input data response + content: + application/json: + schema: + oneOf: + - $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + - $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' + 401: + description: Unsuccessful authentication response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + 403: + description: Not enough privileges response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + 500: + description: Internal server error response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' + +components: + schemas: + ListPrivileges: + type: object + properties: + username: + type: string + has_all_requested: + type: boolean + cluster: + type: object + additionalProperties: + type: boolean + index: + type: object + additionalProperties: + type: object + additionalProperties: + type: boolean + application: + type: object + additionalProperties: + type: boolean + required: + - username + - has_all_requested + - cluster + - index + - application + + ListItemPrivileges: + type: object + properties: + username: + type: string + has_all_requested: + type: boolean + cluster: + type: object + additionalProperties: + type: boolean + index: + type: object + additionalProperties: + type: object + additionalProperties: + type: boolean + application: + type: object + additionalProperties: + type: boolean + required: + - username + - has_all_requested + - cluster + - index + - application diff --git a/packages/kbn-securitysolution-lists-common/api/import_list_item/import_list_item.gen.ts b/packages/kbn-securitysolution-lists-common/api/import_list_item/import_list_item.gen.ts new file mode 100644 index 0000000000000..5748e6a78e2c0 --- /dev/null +++ b/packages/kbn-securitysolution-lists-common/api/import_list_item/import_list_item.gen.ts @@ -0,0 +1,49 @@ +/* + * 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. + */ + +/* + * NOTICE: Do not edit this file manually. + * This file is automatically generated by the OpenAPI Generator, @kbn/openapi-generator. + * + * info: + * title: Import list items API endpoint + * version: 2023-10-31 + */ + +import { z } from 'zod'; + +import { ListId, ListType } from '../model/list_common.gen'; +import { List } from '../model/list_schemas.gen'; + +export type ImportListItemsRequestQuery = z.infer; +export const ImportListItemsRequestQuery = z.object({ + /** + * List's id. + +Required when importing to an existing list. + + */ + list_id: ListId.optional(), + /** + * Type of the importing list. + +Required when importing a new list that is `list_id` is not specified. + + */ + type: ListType.optional(), + serializer: z.string().optional(), + deserializer: z.string().optional(), + /** + * Determines when changes made by the request are made visible to search + */ + refresh: z.enum(['true', 'false', 'wait_for']).optional(), +}); +export type ImportListItemsRequestQueryInput = z.input; + +export type ImportListItemsResponse = z.infer; +export const ImportListItemsResponse = List; diff --git a/packages/kbn-securitysolution-lists-common/api/import_list_item/import_list_item.schema.yaml b/packages/kbn-securitysolution-lists-common/api/import_list_item/import_list_item.schema.yaml new file mode 100644 index 0000000000000..561d52587aad2 --- /dev/null +++ b/packages/kbn-securitysolution-lists-common/api/import_list_item/import_list_item.schema.yaml @@ -0,0 +1,102 @@ +openapi: 3.0.0 +info: + title: Import list items API endpoint + version: '2023-10-31' +paths: + /api/lists/items/_import: + post: + operationId: ImportListItems + x-codegen-enabled: true + summary: Imports list items + description: | + Imports a list of items from a `.txt` or `.csv` file. The maximum file size is 9 million bytes. + + You can import items to a new or existing list. + tags: + - List items Import/Export API + requestBody: + required: true + content: + multipart/form-data: + schema: + type: object + properties: + file: + type: string + format: binary + description: A `.txt` or `.csv` file containing newline separated list items + parameters: + - name: list_id + in: query + required: false + description: | + List's id. + + Required when importing to an existing list. + schema: + $ref: '../model/list_common.schema.yaml#/components/schemas/ListId' + - name: type + in: query + required: false + description: | + Type of the importing list. + + Required when importing a new list that is `list_id` is not specified. + schema: + $ref: '../model/list_common.schema.yaml#/components/schemas/ListType' + - name: serializer + in: query + required: false + schema: + type: string + - name: deserializer + in: query + required: false + schema: + type: string + - name: refresh + in: query + required: false + description: Determines when changes made by the request are made visible to search + schema: + type: string + enum: ['true', 'false', 'wait_for'] + responses: + 200: + description: Successful response + content: + application/json: + schema: + $ref: '../model/list_schemas.schema.yaml#/components/schemas/List' + 400: + description: Invalid input data response + content: + application/json: + schema: + oneOf: + - $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + - $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' + 401: + description: Unsuccessful authentication response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + 403: + description: Not enough privileges response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + 409: + description: List with specified list_id does not exist response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' + 500: + description: Internal server error response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' diff --git a/packages/kbn-securitysolution-lists-common/api/index.ts b/packages/kbn-securitysolution-lists-common/api/index.ts new file mode 100644 index 0000000000000..7b1fb1508653d --- /dev/null +++ b/packages/kbn-securitysolution-lists-common/api/index.ts @@ -0,0 +1,26 @@ +/* + * 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. + */ +export * from './model/list_common.gen'; +export * from './model/list_schemas.gen'; +export * from './create_list_index/create_list_index.gen'; +export * from './create_list_item/create_list_item.gen'; +export * from './create_list/create_list.gen'; +export * from './delete_list_index/delete_list_index.gen'; +export * from './delete_list_item/delete_list_item.gen'; +export * from './delete_list/delete_list.gen'; +export * from './find_list_item/find_list_item.gen'; +export * from './find_list/find_list.gen'; +export * from './export_list_item/export_list_item.gen'; +export * from './import_list_item/import_list_item.gen'; +export * from './patch_list_item/patch_list_item.gen'; +export * from './patch_list/patch_list.gen'; +export * from './read_list_index/read_list_index.gen'; +export * from './read_list_item/read_list_item.gen'; +export * from './read_list/read_list.gen'; +export * from './update_list_item/update_list_item.gen'; +export * from './update_list/update_list.gen'; diff --git a/packages/kbn-securitysolution-lists-common/api/model/list_common.gen.ts b/packages/kbn-securitysolution-lists-common/api/model/list_common.gen.ts new file mode 100644 index 0000000000000..f4a6a007fed9b --- /dev/null +++ b/packages/kbn-securitysolution-lists-common/api/model/list_common.gen.ts @@ -0,0 +1,73 @@ +/* + * 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. + */ + +/* + * NOTICE: Do not edit this file manually. + * This file is automatically generated by the OpenAPI Generator, @kbn/openapi-generator. + * + * info: + * title: Common List Attributes + * version: not applicable + */ + +import { z } from 'zod'; + +import { NonEmptyString } from '@kbn/openapi-common/schemas/primitives.gen'; + +export type ListId = z.infer; +export const ListId = NonEmptyString; + +export type ListType = z.infer; +export const ListType = z.enum([ + 'binary', + 'boolean', + 'byte', + 'date', + 'date_nanos', + 'date_range', + 'double', + 'double_range', + 'float', + 'float_range', + 'geo_point', + 'geo_shape', + 'half_float', + 'integer', + 'integer_range', + 'ip', + 'ip_range', + 'keyword', + 'long', + 'long_range', + 'shape', + 'short', + 'text', +]); +export type ListTypeEnum = typeof ListType.enum; +export const ListTypeEnum = ListType.enum; + +export type ListName = z.infer; +export const ListName = NonEmptyString; + +export type ListDescription = z.infer; +export const ListDescription = NonEmptyString; + +export type ListMetadata = z.infer; +export const ListMetadata = z.object({}).catchall(z.unknown()); + +export type ListItemId = z.infer; +export const ListItemId = NonEmptyString; + +export type ListItemValue = z.infer; +export const ListItemValue = NonEmptyString; + +export type ListItemDescription = z.infer; +export const ListItemDescription = NonEmptyString; + +export type ListItemMetadata = z.infer; +export const ListItemMetadata = z.object({}).catchall(z.unknown()); diff --git a/packages/kbn-securitysolution-lists-common/api/model/list_common.schema.yaml b/packages/kbn-securitysolution-lists-common/api/model/list_common.schema.yaml new file mode 100644 index 0000000000000..6fb160105bb5a --- /dev/null +++ b/packages/kbn-securitysolution-lists-common/api/model/list_common.schema.yaml @@ -0,0 +1,59 @@ +openapi: 3.0.0 +info: + title: Common List Attributes + version: 'not applicable' +paths: {} +components: + schemas: + ListId: + $ref: '../../../kbn-openapi-common/schemas/primitives.schema.yaml#/components/schemas/NonEmptyString' + + ListType: + type: string + enum: + - binary + - boolean + - byte + - date + - date_nanos + - date_range + - double + - double_range + - float + - float_range + - geo_point + - geo_shape + - half_float + - integer + - integer_range + - ip + - ip_range + - keyword + - long + - long_range + - shape + - short + - text + + ListName: + $ref: '../../../kbn-openapi-common/schemas/primitives.schema.yaml#/components/schemas/NonEmptyString' + + ListDescription: + $ref: '../../../kbn-openapi-common/schemas/primitives.schema.yaml#/components/schemas/NonEmptyString' + + ListMetadata: + type: object + additionalProperties: true + + ListItemId: + $ref: '../../../kbn-openapi-common/schemas/primitives.schema.yaml#/components/schemas/NonEmptyString' + + ListItemValue: + $ref: '../../../kbn-openapi-common/schemas/primitives.schema.yaml#/components/schemas/NonEmptyString' + + ListItemDescription: + $ref: '../../../kbn-openapi-common/schemas/primitives.schema.yaml#/components/schemas/NonEmptyString' + + ListItemMetadata: + type: object + additionalProperties: true diff --git a/packages/kbn-securitysolution-lists-common/api/model/list_schemas.gen.ts b/packages/kbn-securitysolution-lists-common/api/model/list_schemas.gen.ts new file mode 100644 index 0000000000000..c70278df938ce --- /dev/null +++ b/packages/kbn-securitysolution-lists-common/api/model/list_schemas.gen.ts @@ -0,0 +1,67 @@ +/* + * 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. + */ + +/* + * NOTICE: Do not edit this file manually. + * This file is automatically generated by the OpenAPI Generator, @kbn/openapi-generator. + * + * info: + * title: List Schemas + * version: not applicable + */ + +import { z } from 'zod'; + +import { + ListId, + ListType, + ListName, + ListDescription, + ListMetadata, + ListItemId, + ListItemValue, + ListItemMetadata, +} from './list_common.gen'; + +export type List = z.infer; +export const List = z.object({ + id: ListId, + type: ListType, + name: ListName, + description: ListDescription, + serializer: z.string().optional(), + deserializer: z.string().optional(), + immutable: z.boolean(), + meta: ListMetadata.optional(), + '@timestamp': z.string().datetime().optional(), + version: z.number().int().min(1), + _version: z.string().optional(), + tie_breaker_id: z.string(), + created_at: z.string().datetime(), + created_by: z.string(), + updated_at: z.string().datetime(), + updated_by: z.string(), +}); + +export type ListItem = z.infer; +export const ListItem = z.object({ + id: ListItemId, + type: ListType, + list_id: ListId, + value: ListItemValue, + serializer: z.string().optional(), + deserializer: z.string().optional(), + meta: ListItemMetadata.optional(), + '@timestamp': z.string().datetime().optional(), + _version: z.string().optional(), + tie_breaker_id: z.string(), + created_at: z.string().datetime(), + created_by: z.string(), + updated_at: z.string().datetime(), + updated_by: z.string(), +}); diff --git a/packages/kbn-securitysolution-lists-common/api/model/list_schemas.schema.yaml b/packages/kbn-securitysolution-lists-common/api/model/list_schemas.schema.yaml new file mode 100644 index 0000000000000..838dc5e4edea0 --- /dev/null +++ b/packages/kbn-securitysolution-lists-common/api/model/list_schemas.schema.yaml @@ -0,0 +1,103 @@ +openapi: 3.0.0 +info: + title: List Schemas + version: 'not applicable' +paths: {} +components: + schemas: + List: + type: object + properties: + id: + $ref: './list_common.schema.yaml#/components/schemas/ListId' + type: + $ref: './list_common.schema.yaml#/components/schemas/ListType' + name: + $ref: './list_common.schema.yaml#/components/schemas/ListName' + description: + $ref: './list_common.schema.yaml#/components/schemas/ListDescription' + serializer: + type: string + deserializer: + type: string + immutable: + type: boolean + meta: + $ref: './list_common.schema.yaml#/components/schemas/ListMetadata' + '@timestamp': + type: string + format: date-time + version: + type: integer + minimum: 1 + _version: + type: string + tie_breaker_id: + type: string + created_at: + type: string + format: date-time + created_by: + type: string + updated_at: + type: string + format: date-time + updated_by: + type: string + required: + - id + - type + - name + - description + - immutable + - version + - tie_breaker_id + - created_at + - created_by + - updated_at + - updated_by + + ListItem: + type: object + properties: + id: + $ref: './list_common.schema.yaml#/components/schemas/ListItemId' + type: + $ref: './list_common.schema.yaml#/components/schemas/ListType' + list_id: + $ref: './list_common.schema.yaml#/components/schemas/ListId' + value: + $ref: './list_common.schema.yaml#/components/schemas/ListItemValue' + serializer: + type: string + deserializer: + type: string + meta: + $ref: './list_common.schema.yaml#/components/schemas/ListItemMetadata' + '@timestamp': + type: string + format: date-time + _version: + type: string + tie_breaker_id: + type: string + created_at: + type: string + format: date-time + created_by: + type: string + updated_at: + type: string + format: date-time + updated_by: + type: string + required: + - id + - type + - list_id + - value + - tie_breaker_id + - created_at + - created_by + - updated_at + - updated_by diff --git a/packages/kbn-securitysolution-lists-common/api/patch_list/patch_list.gen.ts b/packages/kbn-securitysolution-lists-common/api/patch_list/patch_list.gen.ts new file mode 100644 index 0000000000000..47eeb87d0f5d4 --- /dev/null +++ b/packages/kbn-securitysolution-lists-common/api/patch_list/patch_list.gen.ts @@ -0,0 +1,35 @@ +/* + * 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. + */ + +/* + * NOTICE: Do not edit this file manually. + * This file is automatically generated by the OpenAPI Generator, @kbn/openapi-generator. + * + * info: + * title: Patch list API endpoint + * version: 2023-10-31 + */ + +import { z } from 'zod'; + +import { ListId, ListName, ListDescription, ListMetadata } from '../model/list_common.gen'; +import { List } from '../model/list_schemas.gen'; + +export type PatchListRequestBody = z.infer; +export const PatchListRequestBody = z.object({ + id: ListId, + name: ListName.optional(), + description: ListDescription.optional(), + meta: ListMetadata.optional(), + version: z.number().int().min(1).optional(), + _version: z.string().optional(), +}); +export type PatchListRequestBodyInput = z.input; + +export type PatchListResponse = z.infer; +export const PatchListResponse = List; diff --git a/packages/kbn-securitysolution-lists-common/api/patch_list/patch_list.schema.yaml b/packages/kbn-securitysolution-lists-common/api/patch_list/patch_list.schema.yaml new file mode 100644 index 0000000000000..cae09887db312 --- /dev/null +++ b/packages/kbn-securitysolution-lists-common/api/patch_list/patch_list.schema.yaml @@ -0,0 +1,75 @@ +openapi: 3.0.0 +info: + title: Patch list API endpoint + version: '2023-10-31' +paths: + /api/lists: + patch: + x-labels: [serverless, ess] + operationId: PatchList + x-codegen-enabled: true + summary: Patches a list + tags: + - List API + requestBody: + description: List's properties + required: true + content: + application/json: + schema: + type: object + properties: + id: + $ref: '../model/list_common.schema.yaml#/components/schemas/ListId' + name: + $ref: '../model/list_common.schema.yaml#/components/schemas/ListName' + description: + $ref: '../model/list_common.schema.yaml#/components/schemas/ListDescription' + meta: + $ref: '../model/list_common.schema.yaml#/components/schemas/ListMetadata' + version: + type: integer + minimum: 1 + _version: + type: string + required: + - id + responses: + 200: + description: Successful response + content: + application/json: + schema: + $ref: '../model/list_schemas.schema.yaml#/components/schemas/List' + 400: + description: Invalid input data response + content: + application/json: + schema: + oneOf: + - $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + - $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' + 401: + description: Unsuccessful authentication response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + 403: + description: Not enough privileges response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + 404: + description: List not found response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' + 500: + description: Internal server error response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' diff --git a/packages/kbn-securitysolution-lists-common/api/patch_list_item/patch_list_item.gen.ts b/packages/kbn-securitysolution-lists-common/api/patch_list_item/patch_list_item.gen.ts new file mode 100644 index 0000000000000..ce29d68bed7a7 --- /dev/null +++ b/packages/kbn-securitysolution-lists-common/api/patch_list_item/patch_list_item.gen.ts @@ -0,0 +1,37 @@ +/* + * 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. + */ + +/* + * NOTICE: Do not edit this file manually. + * This file is automatically generated by the OpenAPI Generator, @kbn/openapi-generator. + * + * info: + * title: Patch list item API endpoint + * version: 2023-10-31 + */ + +import { z } from 'zod'; + +import { ListItemId, ListItemValue, ListItemMetadata } from '../model/list_common.gen'; +import { ListItem } from '../model/list_schemas.gen'; + +export type PatchListItemRequestBody = z.infer; +export const PatchListItemRequestBody = z.object({ + id: ListItemId, + value: ListItemValue.optional(), + meta: ListItemMetadata.optional(), + _version: z.string().optional(), + /** + * Determines when changes made by the request are made visible to search + */ + refresh: z.enum(['true', 'false', 'wait_for']).optional(), +}); +export type PatchListItemRequestBodyInput = z.input; + +export type PatchListItemResponse = z.infer; +export const PatchListItemResponse = ListItem; diff --git a/packages/kbn-securitysolution-lists-common/api/patch_list_item/patch_list_item.schema.yaml b/packages/kbn-securitysolution-lists-common/api/patch_list_item/patch_list_item.schema.yaml new file mode 100644 index 0000000000000..36ca55c7ae065 --- /dev/null +++ b/packages/kbn-securitysolution-lists-common/api/patch_list_item/patch_list_item.schema.yaml @@ -0,0 +1,77 @@ +openapi: 3.0.0 +info: + title: Patch list item API endpoint + version: '2023-10-31' +paths: + /api/lists/items: + patch: + x-labels: [serverless, ess] + operationId: PatchListItem + x-codegen-enabled: true + summary: Patches a list item + tags: + - List item API + requestBody: + description: List item's properties + required: true + content: + application/json: + schema: + type: object + properties: + id: + $ref: '../model/list_common.schema.yaml#/components/schemas/ListItemId' + value: + $ref: '../model/list_common.schema.yaml#/components/schemas/ListItemValue' + meta: + $ref: '../model/list_common.schema.yaml#/components/schemas/ListItemMetadata' + _version: + type: string + refresh: + type: string + enum: + - 'true' + - 'false' + - wait_for + description: Determines when changes made by the request are made visible to search + required: + - id + responses: + 200: + description: Successful response + content: + application/json: + schema: + $ref: '../model/list_schemas.schema.yaml#/components/schemas/ListItem' + 400: + description: Invalid input data response + content: + application/json: + schema: + oneOf: + - $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + - $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' + 401: + description: Unsuccessful authentication response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + 403: + description: Not enough privileges response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + 404: + description: List item not found response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' + 500: + description: Internal server error response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' diff --git a/packages/kbn-securitysolution-lists-common/api/read_list/read_list.gen.ts b/packages/kbn-securitysolution-lists-common/api/read_list/read_list.gen.ts new file mode 100644 index 0000000000000..2ae0eb6f6c91b --- /dev/null +++ b/packages/kbn-securitysolution-lists-common/api/read_list/read_list.gen.ts @@ -0,0 +1,33 @@ +/* + * 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. + */ + +/* + * NOTICE: Do not edit this file manually. + * This file is automatically generated by the OpenAPI Generator, @kbn/openapi-generator. + * + * info: + * title: Get list API endpoint + * version: 2023-10-31 + */ + +import { z } from 'zod'; + +import { ListId } from '../model/list_common.gen'; +import { List } from '../model/list_schemas.gen'; + +export type GetListRequestQuery = z.infer; +export const GetListRequestQuery = z.object({ + /** + * List's `id` value + */ + id: ListId, +}); +export type GetListRequestQueryInput = z.input; + +export type GetListResponse = z.infer; +export const GetListResponse = List; diff --git a/packages/kbn-securitysolution-lists-common/api/read_list/read_list.schema.yaml b/packages/kbn-securitysolution-lists-common/api/read_list/read_list.schema.yaml new file mode 100644 index 0000000000000..4a2ae5d2cd42c --- /dev/null +++ b/packages/kbn-securitysolution-lists-common/api/read_list/read_list.schema.yaml @@ -0,0 +1,59 @@ +openapi: 3.0.0 +info: + title: Get list API endpoint + version: '2023-10-31' +paths: + /api/lists: + get: + x-labels: [serverless, ess] + operationId: GetList + x-codegen-enabled: true + summary: Retrieves a list using its id field + tags: + - List API + parameters: + - name: id + in: query + required: true + description: List's `id` value + schema: + $ref: '../model/list_common.schema.yaml#/components/schemas/ListId' + responses: + 200: + description: Successful response + content: + application/json: + schema: + $ref: '../model/list_schemas.schema.yaml#/components/schemas/List' + 400: + description: Invalid input data response + content: + application/json: + schema: + oneOf: + - $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + - $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' + 401: + description: Unsuccessful authentication response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + 403: + description: Not enough privileges response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + 404: + description: List not found response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' + 500: + description: Internal server error response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' diff --git a/packages/kbn-securitysolution-lists-common/api/read_list_index/read_list_index.gen.ts b/packages/kbn-securitysolution-lists-common/api/read_list_index/read_list_index.gen.ts new file mode 100644 index 0000000000000..c25105f038636 --- /dev/null +++ b/packages/kbn-securitysolution-lists-common/api/read_list_index/read_list_index.gen.ts @@ -0,0 +1,24 @@ +/* + * 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. + */ + +/* + * NOTICE: Do not edit this file manually. + * This file is automatically generated by the OpenAPI Generator, @kbn/openapi-generator. + * + * info: + * title: Get list DS existence status API endpoint + * version: 2023-10-31 + */ + +import { z } from 'zod'; + +export type GetListIndexResponse = z.infer; +export const GetListIndexResponse = z.object({ + list_index: z.boolean(), + list_item_index: z.boolean(), +}); diff --git a/packages/kbn-securitysolution-lists-common/api/read_list_index/read_list_index.schema.yaml b/packages/kbn-securitysolution-lists-common/api/read_list_index/read_list_index.schema.yaml new file mode 100644 index 0000000000000..accef8b58411e --- /dev/null +++ b/packages/kbn-securitysolution-lists-common/api/read_list_index/read_list_index.schema.yaml @@ -0,0 +1,58 @@ +openapi: 3.0.0 +info: + title: Get list DS existence status API endpoint + version: '2023-10-31' +paths: + /api/lists/index: + get: + x-labels: [serverless, ess] + operationId: GetListIndex + x-codegen-enabled: true + summary: Get list data stream existence status + tags: + - List API + responses: + 200: + description: Successful response + content: + application/json: + schema: + type: object + properties: + list_index: + type: boolean + list_item_index: + type: boolean + required: [list_index, list_item_index] + 400: + description: Invalid input data response + content: + application/json: + schema: + oneOf: + - $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + - $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' + 401: + description: Unsuccessful authentication response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + 403: + description: Not enough privileges response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + 404: + description: List data stream(s) not found response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' + 500: + description: Internal server error response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' diff --git a/packages/kbn-securitysolution-lists-common/api/read_list_item/read_list_item.gen.ts b/packages/kbn-securitysolution-lists-common/api/read_list_item/read_list_item.gen.ts new file mode 100644 index 0000000000000..e9f5b9eef9cf8 --- /dev/null +++ b/packages/kbn-securitysolution-lists-common/api/read_list_item/read_list_item.gen.ts @@ -0,0 +1,41 @@ +/* + * 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. + */ + +/* + * NOTICE: Do not edit this file manually. + * This file is automatically generated by the OpenAPI Generator, @kbn/openapi-generator. + * + * info: + * title: Get list item API endpoint + * version: 2023-10-31 + */ + +import { z } from 'zod'; + +import { ListId } from '../model/list_common.gen'; +import { ListItem } from '../model/list_schemas.gen'; + +export type GetListItemRequestQuery = z.infer; +export const GetListItemRequestQuery = z.object({ + /** + * Required if `list_id` and `value` are not specified + */ + id: ListId.optional(), + /** + * Required if `id` is not specified + */ + list_id: ListId.optional(), + /** + * Required if `id` is not specified + */ + value: z.string().optional(), +}); +export type GetListItemRequestQueryInput = z.input; + +export type GetListItemResponse = z.infer; +export const GetListItemResponse = z.union([ListItem, z.array(ListItem)]); diff --git a/packages/kbn-securitysolution-lists-common/api/read_list_item/read_list_item.schema.yaml b/packages/kbn-securitysolution-lists-common/api/read_list_item/read_list_item.schema.yaml new file mode 100644 index 0000000000000..3a651617163aa --- /dev/null +++ b/packages/kbn-securitysolution-lists-common/api/read_list_item/read_list_item.schema.yaml @@ -0,0 +1,75 @@ +openapi: 3.0.0 +info: + title: Get list item API endpoint + version: '2023-10-31' +paths: + /api/lists/items: + get: + x-labels: [serverless, ess] + operationId: GetListItem + x-codegen-enabled: true + summary: Gets a list item + tags: + - List item API + parameters: + - name: id + in: query + required: false + description: Required if `list_id` and `value` are not specified + schema: + $ref: '../model/list_common.schema.yaml#/components/schemas/ListId' + - name: list_id + in: query + required: false + description: Required if `id` is not specified + schema: + $ref: '../model/list_common.schema.yaml#/components/schemas/ListId' + - name: value + in: query + required: false + description: Required if `id` is not specified + schema: + type: string + responses: + 200: + description: Successful response + content: + application/json: + schema: + oneOf: + - $ref: '../model/list_schemas.schema.yaml#/components/schemas/ListItem' + - type: array + items: + $ref: '../model/list_schemas.schema.yaml#/components/schemas/ListItem' + 400: + description: Invalid input data response + content: + application/json: + schema: + oneOf: + - $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + - $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' + 401: + description: Unsuccessful authentication response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + 403: + description: Not enough privileges response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + 404: + description: List item not found response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' + 500: + description: Internal server error response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' diff --git a/packages/kbn-securitysolution-lists-common/api/update_list/update_list.gen.ts b/packages/kbn-securitysolution-lists-common/api/update_list/update_list.gen.ts new file mode 100644 index 0000000000000..833239a7eb82b --- /dev/null +++ b/packages/kbn-securitysolution-lists-common/api/update_list/update_list.gen.ts @@ -0,0 +1,35 @@ +/* + * 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. + */ + +/* + * NOTICE: Do not edit this file manually. + * This file is automatically generated by the OpenAPI Generator, @kbn/openapi-generator. + * + * info: + * title: Update list API endpoint + * version: 2023-10-31 + */ + +import { z } from 'zod'; + +import { ListId, ListName, ListDescription, ListMetadata } from '../model/list_common.gen'; +import { List } from '../model/list_schemas.gen'; + +export type UpdateListRequestBody = z.infer; +export const UpdateListRequestBody = z.object({ + id: ListId, + name: ListName, + description: ListDescription, + meta: ListMetadata.optional(), + version: z.number().int().min(1).optional(), + _version: z.string().optional(), +}); +export type UpdateListRequestBodyInput = z.input; + +export type UpdateListResponse = z.infer; +export const UpdateListResponse = List; diff --git a/packages/kbn-securitysolution-lists-common/api/update_list/update_list.schema.yaml b/packages/kbn-securitysolution-lists-common/api/update_list/update_list.schema.yaml new file mode 100644 index 0000000000000..d25b21157c725 --- /dev/null +++ b/packages/kbn-securitysolution-lists-common/api/update_list/update_list.schema.yaml @@ -0,0 +1,77 @@ +openapi: 3.0.0 +info: + title: Update list API endpoint + version: '2023-10-31' +paths: + /api/lists: + put: + x-labels: [serverless, ess] + operationId: UpdateList + x-codegen-enabled: true + summary: Updates a list + tags: + - List API + requestBody: + description: List's properties + required: true + content: + application/json: + schema: + type: object + properties: + id: + $ref: '../model/list_common.schema.yaml#/components/schemas/ListId' + name: + $ref: '../model/list_common.schema.yaml#/components/schemas/ListName' + description: + $ref: '../model/list_common.schema.yaml#/components/schemas/ListDescription' + meta: + $ref: '../model/list_common.schema.yaml#/components/schemas/ListMetadata' + version: + type: integer + minimum: 1 + _version: + type: string + required: + - id + - name + - description + responses: + 200: + description: Successful response + content: + application/json: + schema: + $ref: '../model/list_schemas.schema.yaml#/components/schemas/List' + 400: + description: Invalid input data response + content: + application/json: + schema: + oneOf: + - $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + - $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' + 401: + description: Unsuccessful authentication response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + 403: + description: Not enough privileges response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + 404: + description: List not found response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' + 500: + description: Internal server error response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' diff --git a/packages/kbn-securitysolution-lists-common/api/update_list_item/update_list_item.gen.ts b/packages/kbn-securitysolution-lists-common/api/update_list_item/update_list_item.gen.ts new file mode 100644 index 0000000000000..069c101beaaf4 --- /dev/null +++ b/packages/kbn-securitysolution-lists-common/api/update_list_item/update_list_item.gen.ts @@ -0,0 +1,33 @@ +/* + * 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. + */ + +/* + * NOTICE: Do not edit this file manually. + * This file is automatically generated by the OpenAPI Generator, @kbn/openapi-generator. + * + * info: + * title: Update list item API endpoint + * version: 2023-10-31 + */ + +import { z } from 'zod'; + +import { ListItemId, ListItemValue, ListItemMetadata } from '../model/list_common.gen'; +import { ListItem } from '../model/list_schemas.gen'; + +export type UpdateListItemRequestBody = z.infer; +export const UpdateListItemRequestBody = z.object({ + id: ListItemId, + value: ListItemValue, + meta: ListItemMetadata.optional(), + _version: z.string().optional(), +}); +export type UpdateListItemRequestBodyInput = z.input; + +export type UpdateListItemResponse = z.infer; +export const UpdateListItemResponse = ListItem; diff --git a/packages/kbn-securitysolution-lists-common/api/update_list_item/update_list_item.schema.yaml b/packages/kbn-securitysolution-lists-common/api/update_list_item/update_list_item.schema.yaml new file mode 100644 index 0000000000000..21df82f4ba40a --- /dev/null +++ b/packages/kbn-securitysolution-lists-common/api/update_list_item/update_list_item.schema.yaml @@ -0,0 +1,71 @@ +openapi: 3.0.0 +info: + title: Update list item API endpoint + version: '2023-10-31' +paths: + /api/lists/items: + put: + x-labels: [serverless, ess] + operationId: UpdateListItem + x-codegen-enabled: true + summary: Updates a list item + tags: + - List item API + requestBody: + description: List item's properties + required: true + content: + application/json: + schema: + type: object + properties: + id: + $ref: '../model/list_common.schema.yaml#/components/schemas/ListItemId' + value: + $ref: '../model/list_common.schema.yaml#/components/schemas/ListItemValue' + meta: + $ref: '../model/list_common.schema.yaml#/components/schemas/ListItemMetadata' + _version: + type: string + required: + - id + - value + responses: + 200: + description: Successful response + content: + application/json: + schema: + $ref: '../model/list_schemas.schema.yaml#/components/schemas/ListItem' + 400: + description: Invalid input data response + content: + application/json: + schema: + oneOf: + - $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + - $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' + 401: + description: Unsuccessful authentication response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + 403: + description: Not enough privileges response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/PlatformErrorResponse' + 404: + description: List item not found response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' + 500: + description: Internal server error response + content: + application/json: + schema: + $ref: '../../../kbn-openapi-common/schemas/error_responses.schema.yaml#/components/schemas/SiemErrorResponse' diff --git a/packages/kbn-securitysolution-lists-common/kibana.jsonc b/packages/kbn-securitysolution-lists-common/kibana.jsonc new file mode 100644 index 0000000000000..614314f10e8b4 --- /dev/null +++ b/packages/kbn-securitysolution-lists-common/kibana.jsonc @@ -0,0 +1,5 @@ +{ + "type": "shared-common", + "id": "@kbn/securitysolution-lists-common", + "owner": "@elastic/security-detection-engine" +} diff --git a/packages/kbn-securitysolution-lists-common/package.json b/packages/kbn-securitysolution-lists-common/package.json new file mode 100644 index 0000000000000..298f0e47bb10f --- /dev/null +++ b/packages/kbn-securitysolution-lists-common/package.json @@ -0,0 +1,10 @@ +{ + "description": "Security Solution Lists common package", + "license": "SSPL-1.0 OR Elastic License 2.0", + "name": "@kbn/securitysolution-lists-common", + "private": true, + "version": "1.0.0", + "scripts": { + "openapi:generate": "node scripts/openapi_generate" + } +} diff --git a/packages/kbn-securitysolution-lists-common/scripts/openapi_generate.js b/packages/kbn-securitysolution-lists-common/scripts/openapi_generate.js new file mode 100644 index 0000000000000..8580994b16859 --- /dev/null +++ b/packages/kbn-securitysolution-lists-common/scripts/openapi_generate.js @@ -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. + */ + +require('../../../src/setup_node_env'); +const { resolve } = require('path'); +const { generate } = require('@kbn/openapi-generator'); + +const ROOT = resolve(__dirname, '..'); + +(async () => { + await generate({ + title: 'OpenAPI Lists API Schemas', + rootDir: ROOT, + sourceGlob: './**/*.schema.yaml', + templateName: 'zod_operation_schema', + }); +})(); diff --git a/packages/kbn-securitysolution-lists-common/tsconfig.json b/packages/kbn-securitysolution-lists-common/tsconfig.json new file mode 100644 index 0000000000000..b6a14b40363c7 --- /dev/null +++ b/packages/kbn-securitysolution-lists-common/tsconfig.json @@ -0,0 +1,10 @@ +{ + "compilerOptions": { + "outDir": "target/types", + "types": ["jest", "node"] + }, + "exclude": ["target/**/*"], + "extends": "../../tsconfig.base.json", + "include": ["**/*.ts"], + "kbn_references": ["@kbn/zod-helpers", "@kbn/openapi-common"] +} diff --git a/packages/kbn-zod-helpers/index.ts b/packages/kbn-zod-helpers/index.ts index d8a62f58686b2..e3b0f4e35a19d 100644 --- a/packages/kbn-zod-helpers/index.ts +++ b/packages/kbn-zod-helpers/index.ts @@ -14,3 +14,4 @@ export * from './src/is_valid_date_math'; export * from './src/required_optional'; export * from './src/safe_parse_result'; export * from './src/stringify_zod_error'; +export * from './src/build_route_validation_with_zod'; diff --git a/packages/kbn-zod-helpers/src/build_route_validation_with_zod.ts b/packages/kbn-zod-helpers/src/build_route_validation_with_zod.ts new file mode 100644 index 0000000000000..a72eb96d3b968 --- /dev/null +++ b/packages/kbn-zod-helpers/src/build_route_validation_with_zod.ts @@ -0,0 +1,48 @@ +/* + * 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 type { TypeOf, ZodType } from 'zod'; +import type { RouteValidationFunction, RouteValidationResultFactory } from '@kbn/core/server'; +import { stringifyZodError } from './stringify_zod_error'; + +/** + * Zod validation factory for Kibana route's request validation. + * It allows to pass a Zod schema for parameters, query and/or body validation. + * + * Example: + * + * ```ts + * router.versioned + * .post({ + * access: 'public', + * path: MY_URL, + * }) + * .addVersion( + * { + * version: 'my-version', + * validate: { + * request: { + * params: buildRouteValidationWithZod(MyRequestParamsZodSchema), + * query: buildRouteValidationWithZod(MyRequestQueryZodSchema), + * body: buildRouteValidationWithZod(MyRequestBodyZodSchema), + * }, + * }, + * }, + * ``` + */ +export function buildRouteValidationWithZod>( + schema: ZodSchema +): RouteValidationFunction { + return (inputValue: unknown, validationResult: RouteValidationResultFactory) => { + const decoded = schema.safeParse(inputValue); + + return decoded.success + ? validationResult.ok(decoded.data) + : validationResult.badRequest(stringifyZodError(decoded.error)); + }; +} diff --git a/packages/kbn-zod-helpers/tsconfig.json b/packages/kbn-zod-helpers/tsconfig.json index 0b3850da21158..fbe3b91a89493 100644 --- a/packages/kbn-zod-helpers/tsconfig.json +++ b/packages/kbn-zod-helpers/tsconfig.json @@ -6,7 +6,5 @@ "exclude": ["target/**/*"], "extends": "../../tsconfig.base.json", "include": ["**/*.ts"], - "kbn_references": [ - "@kbn/datemath", - ] + "kbn_references": ["@kbn/datemath", "@kbn/core"] } diff --git a/tsconfig.base.json b/tsconfig.base.json index 9c7e088b966d3..ee2dd40f72e0f 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -1236,6 +1236,8 @@ "@kbn/open-telemetry-instrumented-plugin/*": ["test/common/plugins/otel_metrics/*"], "@kbn/openapi-bundler": ["packages/kbn-openapi-bundler"], "@kbn/openapi-bundler/*": ["packages/kbn-openapi-bundler/*"], + "@kbn/openapi-common": ["packages/kbn-openapi-common"], + "@kbn/openapi-common/*": ["packages/kbn-openapi-common/*"], "@kbn/openapi-generator": ["packages/kbn-openapi-generator"], "@kbn/openapi-generator/*": ["packages/kbn-openapi-generator/*"], "@kbn/optimizer": ["packages/kbn-optimizer"], @@ -1496,6 +1498,8 @@ "@kbn/securitysolution-list-hooks/*": ["packages/kbn-securitysolution-list-hooks/*"], "@kbn/securitysolution-list-utils": ["packages/kbn-securitysolution-list-utils"], "@kbn/securitysolution-list-utils/*": ["packages/kbn-securitysolution-list-utils/*"], + "@kbn/securitysolution-lists-common": ["packages/kbn-securitysolution-lists-common"], + "@kbn/securitysolution-lists-common/*": ["packages/kbn-securitysolution-lists-common/*"], "@kbn/securitysolution-rules": ["packages/kbn-securitysolution-rules"], "@kbn/securitysolution-rules/*": ["packages/kbn-securitysolution-rules/*"], "@kbn/securitysolution-t-grid": ["packages/kbn-securitysolution-t-grid"], diff --git a/x-pack/plugins/lists/common/api/index.ts b/x-pack/plugins/lists/common/api/index.ts index 1d76a041d2824..1cbbeba219078 100644 --- a/x-pack/plugins/lists/common/api/index.ts +++ b/x-pack/plugins/lists/common/api/index.ts @@ -27,20 +27,4 @@ export * from './exceptions/summary_exception_list/summary_exception_list_route' export * from './exceptions/update_endpoint_list_item/update_endpoint_list_item_route'; export * from './exceptions/update_exception_list_item/update_exception_list_item_route'; export * from './exceptions/update_exception_list/update_exception_list_route'; -export * from './values/create_list_index/create_list_index_route'; -export * from './values/create_list_item/create_list_item_route'; -export * from './values/create_list/create_list_route'; -export * from './values/delete_list_index/delete_list_index_route'; -export * from './values/delete_list_item/delete_list_item_route'; -export * from './values/delete_list/delete_list_route'; -export * from './values/find_list_item/find_list_item_route'; -export * from './values/find_list/find_list_route'; export * from './values/find_lists_by_size/find_lists_by_size_route'; -export * from './values/import_list_item/import_list_item_route'; -export * from './values/patch_list_item/patch_list_item_route'; -export * from './values/patch_list/patch_list_route'; -export * from './values/read_list_index/read_list_index_route'; -export * from './values/read_list_item/read_list_item_route'; -export * from './values/read_list/read_list_route'; -export * from './values/update_list_item/update_list_item_route'; -export * from './values/update_list/update_list_route'; diff --git a/x-pack/plugins/lists/common/api/values/create_list/create_list_route.ts b/x-pack/plugins/lists/common/api/values/create_list/create_list_route.ts deleted file mode 100644 index 71dc2eecde8ea..0000000000000 --- a/x-pack/plugins/lists/common/api/values/create_list/create_list_route.ts +++ /dev/null @@ -1,15 +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 { - CreateListSchemaDecoded, - createListSchema, - listSchema, -} from '@kbn/securitysolution-io-ts-list-types'; - -export { createListSchema as createListRequest, listSchema as createListResponse }; -export type { CreateListSchemaDecoded as CreateListRequestDecoded }; diff --git a/x-pack/plugins/lists/common/api/values/create_list_index/create_list_index_route.ts b/x-pack/plugins/lists/common/api/values/create_list_index/create_list_index_route.ts deleted file mode 100644 index 85e094b273e13..0000000000000 --- a/x-pack/plugins/lists/common/api/values/create_list_index/create_list_index_route.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. - */ - -import { acknowledgeSchema } from '@kbn/securitysolution-io-ts-list-types'; - -export { acknowledgeSchema as createListIndexResponse }; diff --git a/x-pack/plugins/lists/common/api/values/create_list_item/create_list_item_route.ts b/x-pack/plugins/lists/common/api/values/create_list_item/create_list_item_route.ts deleted file mode 100644 index 70cef948d6cf1..0000000000000 --- a/x-pack/plugins/lists/common/api/values/create_list_item/create_list_item_route.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. - */ - -import { createListItemSchema, listItemSchema } from '@kbn/securitysolution-io-ts-list-types'; - -export { createListItemSchema as createListItemRequest, listItemSchema as createListItemResponse }; diff --git a/x-pack/plugins/lists/common/api/values/delete_list/delete_list_route.ts b/x-pack/plugins/lists/common/api/values/delete_list/delete_list_route.ts deleted file mode 100644 index b360d3e5c6880..0000000000000 --- a/x-pack/plugins/lists/common/api/values/delete_list/delete_list_route.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. - */ - -import { deleteListSchema, listSchema } from '@kbn/securitysolution-io-ts-list-types'; - -export { deleteListSchema as deleteListRequestQuery, listSchema as deleteListResponse }; diff --git a/x-pack/plugins/lists/common/api/values/delete_list_index/delete_list_index_route.ts b/x-pack/plugins/lists/common/api/values/delete_list_index/delete_list_index_route.ts deleted file mode 100644 index 2423ebd6bea60..0000000000000 --- a/x-pack/plugins/lists/common/api/values/delete_list_index/delete_list_index_route.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. - */ - -import { acknowledgeSchema } from '@kbn/securitysolution-io-ts-list-types'; - -export { acknowledgeSchema as deleteListIndexResponse }; diff --git a/x-pack/plugins/lists/common/api/values/delete_list_item/delete_list_item_route.ts b/x-pack/plugins/lists/common/api/values/delete_list_item/delete_list_item_route.ts deleted file mode 100644 index 418401d2b6c17..0000000000000 --- a/x-pack/plugins/lists/common/api/values/delete_list_item/delete_list_item_route.ts +++ /dev/null @@ -1,18 +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 { - deleteListItemSchema, - listItemArraySchema, - listItemSchema, -} from '@kbn/securitysolution-io-ts-list-types'; - -export { - deleteListItemSchema as deleteListItemRequestQuery, - listItemSchema as deleteListItemResponse, - listItemArraySchema as deleteListItemArrayResponse, -}; diff --git a/x-pack/plugins/lists/common/api/values/find_list/find_list_route.ts b/x-pack/plugins/lists/common/api/values/find_list/find_list_route.ts deleted file mode 100644 index 8c3301daed3c9..0000000000000 --- a/x-pack/plugins/lists/common/api/values/find_list/find_list_route.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. - */ - -import { findListSchema, foundListSchema } from '@kbn/securitysolution-io-ts-list-types'; - -export { findListSchema as findListRequestQuery, foundListSchema as findListResponse }; diff --git a/x-pack/plugins/lists/common/api/values/find_list_item/find_list_item_route.ts b/x-pack/plugins/lists/common/api/values/find_list_item/find_list_item_route.ts deleted file mode 100644 index b9d4d93ccb340..0000000000000 --- a/x-pack/plugins/lists/common/api/values/find_list_item/find_list_item_route.ts +++ /dev/null @@ -1,18 +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 { - FindListItemSchemaDecoded, - findListItemSchema, - foundListItemSchema, -} from '@kbn/securitysolution-io-ts-list-types'; - -export { - findListItemSchema as findListItemRequestQuery, - foundListItemSchema as findListItemResponse, -}; -export type { FindListItemSchemaDecoded as FindListItemRequestQueryDecoded }; diff --git a/x-pack/plugins/lists/common/api/values/import_list_item/import_list_item_route.ts b/x-pack/plugins/lists/common/api/values/import_list_item/import_list_item_route.ts deleted file mode 100644 index 3ea57eda532fc..0000000000000 --- a/x-pack/plugins/lists/common/api/values/import_list_item/import_list_item_route.ts +++ /dev/null @@ -1,13 +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 { importListItemQuerySchema, listSchema } from '@kbn/securitysolution-io-ts-list-types'; - -export { - importListItemQuerySchema as importListItemRequestQuery, - listSchema as importListItemResponse, -}; diff --git a/x-pack/plugins/lists/common/api/values/patch_list/patch_list_route.ts b/x-pack/plugins/lists/common/api/values/patch_list/patch_list_route.ts deleted file mode 100644 index 8821658c5b23a..0000000000000 --- a/x-pack/plugins/lists/common/api/values/patch_list/patch_list_route.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. - */ - -import { listSchema, patchListSchema } from '@kbn/securitysolution-io-ts-list-types'; - -export { patchListSchema as patchListRequest, listSchema as patchListResponse }; diff --git a/x-pack/plugins/lists/common/api/values/patch_list_item/patch_list_item_route.ts b/x-pack/plugins/lists/common/api/values/patch_list_item/patch_list_item_route.ts deleted file mode 100644 index 12b4bd36e968e..0000000000000 --- a/x-pack/plugins/lists/common/api/values/patch_list_item/patch_list_item_route.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. - */ - -import { listItemSchema, patchListItemSchema } from '@kbn/securitysolution-io-ts-list-types'; - -export { patchListItemSchema as patchListItemRequest, listItemSchema as patchListItemResponse }; diff --git a/x-pack/plugins/lists/common/api/values/read_list/read_list_route.ts b/x-pack/plugins/lists/common/api/values/read_list/read_list_route.ts deleted file mode 100644 index be13d604f57c5..0000000000000 --- a/x-pack/plugins/lists/common/api/values/read_list/read_list_route.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. - */ - -import { listSchema, readListSchema } from '@kbn/securitysolution-io-ts-list-types'; - -export { readListSchema as readListRequestQuery, listSchema as readListResponse }; diff --git a/x-pack/plugins/lists/common/api/values/read_list_index/read_list_index_route.ts b/x-pack/plugins/lists/common/api/values/read_list_index/read_list_index_route.ts deleted file mode 100644 index 772d042b7e11c..0000000000000 --- a/x-pack/plugins/lists/common/api/values/read_list_index/read_list_index_route.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. - */ - -import { listItemIndexExistSchema } from '@kbn/securitysolution-io-ts-list-types'; - -export { listItemIndexExistSchema as readListIndexResponse }; diff --git a/x-pack/plugins/lists/common/api/values/read_list_item/read_list_item_route.ts b/x-pack/plugins/lists/common/api/values/read_list_item/read_list_item_route.ts deleted file mode 100644 index 0b67159ceaf03..0000000000000 --- a/x-pack/plugins/lists/common/api/values/read_list_item/read_list_item_route.ts +++ /dev/null @@ -1,18 +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 { - listItemArraySchema, - listItemSchema, - readListItemSchema, -} from '@kbn/securitysolution-io-ts-list-types'; - -export { - readListItemSchema as readListItemRequestQuery, - listItemSchema as readListItemResponse, - listItemArraySchema as readListItemArrayResponse, -}; diff --git a/x-pack/plugins/lists/common/api/values/update_list/update_list_route.ts b/x-pack/plugins/lists/common/api/values/update_list/update_list_route.ts deleted file mode 100644 index 801e9784ac80d..0000000000000 --- a/x-pack/plugins/lists/common/api/values/update_list/update_list_route.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. - */ - -import { listSchema, updateListSchema } from '@kbn/securitysolution-io-ts-list-types'; - -export { updateListSchema as updateListRequest, listSchema as updateListResponse }; diff --git a/x-pack/plugins/lists/common/api/values/update_list_item/update_list_item_route.ts b/x-pack/plugins/lists/common/api/values/update_list_item/update_list_item_route.ts deleted file mode 100644 index 9b512e61f464e..0000000000000 --- a/x-pack/plugins/lists/common/api/values/update_list_item/update_list_item_route.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. - */ - -import { listItemSchema, updateListItemSchema } from '@kbn/securitysolution-io-ts-list-types'; - -export { updateListItemSchema as updateListItemRequest, listItemSchema as updateListItemResponse }; diff --git a/x-pack/plugins/lists/common/schemas/request/create_list_schema.mock.ts b/x-pack/plugins/lists/common/schemas/request/create_list_schema.mock.ts index 117659423103d..57dae64930dc5 100644 --- a/x-pack/plugins/lists/common/schemas/request/create_list_schema.mock.ts +++ b/x-pack/plugins/lists/common/schemas/request/create_list_schema.mock.ts @@ -5,11 +5,11 @@ * 2.0. */ -import type { CreateListSchema } from '@kbn/securitysolution-io-ts-list-types'; +import type { CreateListRequestBodyInput } from '@kbn/securitysolution-lists-common/api'; import { DESCRIPTION, LIST_ID, META, NAME, TYPE, VERSION } from '../../constants.mock'; -export const getCreateListSchemaMock = (): CreateListSchema => ({ +export const getCreateListSchemaMock = (): CreateListRequestBodyInput => ({ description: DESCRIPTION, deserializer: undefined, id: LIST_ID, @@ -23,7 +23,7 @@ export const getCreateListSchemaMock = (): CreateListSchema => ({ /** * Useful for end to end tests and other mechanisms which want to fill in the values */ -export const getCreateMinimalListSchemaMock = (): CreateListSchema => ({ +export const getCreateMinimalListSchemaMock = (): CreateListRequestBodyInput => ({ description: DESCRIPTION, id: LIST_ID, name: NAME, @@ -33,7 +33,7 @@ export const getCreateMinimalListSchemaMock = (): CreateListSchema => ({ /** * Useful for end to end tests and other mechanisms which want to fill in the values */ -export const getCreateMinimalListSchemaMockWithoutId = (): CreateListSchema => ({ +export const getCreateMinimalListSchemaMockWithoutId = (): CreateListRequestBodyInput => ({ description: DESCRIPTION, name: NAME, type: TYPE, diff --git a/x-pack/plugins/lists/common/schemas/request/update_list_schema.mock.ts b/x-pack/plugins/lists/common/schemas/request/update_list_schema.mock.ts index d38744a35a6cb..564c79e67a2bb 100644 --- a/x-pack/plugins/lists/common/schemas/request/update_list_schema.mock.ts +++ b/x-pack/plugins/lists/common/schemas/request/update_list_schema.mock.ts @@ -5,11 +5,11 @@ * 2.0. */ -import type { UpdateListSchema } from '@kbn/securitysolution-io-ts-list-types'; +import type { UpdateListRequestBody } from '@kbn/securitysolution-lists-common/api'; import { DESCRIPTION, LIST_ID, META, NAME, _VERSION } from '../../constants.mock'; -export const getUpdateListSchemaMock = (): UpdateListSchema => ({ +export const getUpdateListSchemaMock = (): UpdateListRequestBody => ({ _version: _VERSION, description: DESCRIPTION, id: LIST_ID, @@ -21,7 +21,7 @@ export const getUpdateListSchemaMock = (): UpdateListSchema => ({ * Useful for end to end tests and other mechanisms which want to fill in the values * after doing a get of the structure. */ -export const getUpdateMinimalListSchemaMock = (): UpdateListSchema => ({ +export const getUpdateMinimalListSchemaMock = (): UpdateListRequestBody => ({ description: DESCRIPTION, id: LIST_ID, name: NAME, diff --git a/x-pack/plugins/lists/server/routes/list/create_list_route.ts b/x-pack/plugins/lists/server/routes/list/create_list_route.ts index 063056461c20c..3b0e80aa7ee7e 100644 --- a/x-pack/plugins/lists/server/routes/list/create_list_route.ts +++ b/x-pack/plugins/lists/server/routes/list/create_list_route.ts @@ -5,17 +5,13 @@ * 2.0. */ -import { validate } from '@kbn/securitysolution-io-ts-utils'; import { transformError } from '@kbn/securitysolution-es-utils'; import { LIST_URL } from '@kbn/securitysolution-list-constants'; +import { buildRouteValidationWithZod } from '@kbn/zod-helpers'; +import { CreateListRequestBody, CreateListResponse } from '@kbn/securitysolution-lists-common/api'; import type { ListsPluginRouter } from '../../types'; -import { - CreateListRequestDecoded, - createListRequest, - createListResponse, -} from '../../../common/api'; -import { buildRouteValidation, buildSiemResponse } from '../utils'; +import { buildSiemResponse } from '../utils'; import { getListClient } from '..'; export const createListRoute = (router: ListsPluginRouter): void => { @@ -31,9 +27,7 @@ export const createListRoute = (router: ListsPluginRouter): void => { { validate: { request: { - body: buildRouteValidation( - createListRequest - ), + body: buildRouteValidationWithZod(CreateListRequestBody), }, }, version: '2023-10-31', @@ -77,12 +71,8 @@ export const createListRoute = (router: ListsPluginRouter): void => { type, version, }); - const [validated, errors] = validate(list, createListResponse); - if (errors != null) { - return siemResponse.error({ body: errors, statusCode: 500 }); - } else { - return response.ok({ body: validated ?? {} }); - } + + return response.ok({ body: CreateListResponse.parse(list) }); } } catch (err) { const error = transformError(err); diff --git a/x-pack/plugins/lists/server/routes/list/delete_list_route.ts b/x-pack/plugins/lists/server/routes/list/delete_list_route.ts index f2571cd44acf9..d28b777a2ba8e 100644 --- a/x-pack/plugins/lists/server/routes/list/delete_list_route.ts +++ b/x-pack/plugins/lists/server/routes/list/delete_list_route.ts @@ -17,12 +17,13 @@ import { } from '@kbn/securitysolution-io-ts-list-types'; import { getSavedObjectType } from '@kbn/securitysolution-list-utils'; import { LIST_URL } from '@kbn/securitysolution-list-constants'; +import { buildRouteValidationWithZod } from '@kbn/zod-helpers'; +import { DeleteListRequestQuery, DeleteListResponse } from '@kbn/securitysolution-lists-common/api'; import type { ListsPluginRouter } from '../../types'; import type { ExceptionListClient } from '../../services/exception_lists/exception_list_client'; import { escapeQuotes } from '../../services/utils/escape_query'; -import { deleteListRequestQuery, deleteListResponse } from '../../../common/api'; -import { buildRouteValidation, buildSiemResponse } from '../utils'; +import { buildSiemResponse } from '../utils'; import { getExceptionListClient, getListClient } from '..'; export const deleteListRoute = (router: ListsPluginRouter): void => { @@ -38,7 +39,7 @@ export const deleteListRoute = (router: ListsPluginRouter): void => { { validate: { request: { - query: buildRouteValidation(deleteListRequestQuery), + query: buildRouteValidationWithZod(DeleteListRequestQuery), }, }, version: '2023-10-31', @@ -49,7 +50,6 @@ export const deleteListRoute = (router: ListsPluginRouter): void => { const lists = await getListClient(context); const exceptionLists = await getExceptionListClient(context); const { id, deleteReferences, ignoreReferences } = request.query; - let deleteExceptionItemResponses; // ignoreReferences=true maintains pre-7.11 behavior of deleting value list without performing any additional checks if (!ignoreReferences) { @@ -75,7 +75,7 @@ export const deleteListRoute = (router: ListsPluginRouter): void => { if (deleteReferences) { // Delete referenced exception list items // TODO: Create deleteListItems to delete in batch - deleteExceptionItemResponses = await Promise.all( + await Promise.all( referencedExceptionListItems.map(async (listItem) => { // Ensure only the single entry is deleted as there could be a separate value list referenced that is okay to keep // TODO: Add API to delete single entry const remainingEntries = listItem.entries.filter( @@ -122,16 +122,9 @@ export const deleteListRoute = (router: ListsPluginRouter): void => { statusCode: 404, }); } else { - const [validated, errors] = validate(deleted, deleteListResponse); - if (errors != null) { - return siemResponse.error({ body: errors, statusCode: 500 }); - } else { - return response.ok({ - body: validated ?? { - deleteItemResponses: deleteExceptionItemResponses, - }, - }); - } + return response.ok({ + body: DeleteListResponse.parse(deleted), + }); } } catch (err) { const error = transformError(err); diff --git a/x-pack/plugins/lists/server/routes/list/import_list_item_route.ts b/x-pack/plugins/lists/server/routes/list/import_list_item_route.ts index d9d1bc5af1e6e..f3f52828f7872 100644 --- a/x-pack/plugins/lists/server/routes/list/import_list_item_route.ts +++ b/x-pack/plugins/lists/server/routes/list/import_list_item_route.ts @@ -8,14 +8,17 @@ import { extname } from 'path'; import { schema } from '@kbn/config-schema'; -import { validate } from '@kbn/securitysolution-io-ts-utils'; import { transformError } from '@kbn/securitysolution-es-utils'; import { LIST_ITEM_URL } from '@kbn/securitysolution-list-constants'; +import { buildRouteValidationWithZod } from '@kbn/zod-helpers'; +import { + ImportListItemsRequestQuery, + ImportListItemsResponse, +} from '@kbn/securitysolution-lists-common/api'; import type { ListsPluginRouter } from '../../types'; import { ConfigType } from '../../config'; -import { importListItemRequestQuery, importListItemResponse } from '../../../common/api'; -import { buildRouteValidation, buildSiemResponse } from '../utils'; +import { buildSiemResponse } from '../utils'; import { createStreamFromBuffer } from '../utils/create_stream_from_buffer'; import { getListClient } from '..'; @@ -43,7 +46,7 @@ export const importListItemRoute = (router: ListsPluginRouter, config: ConfigTyp validate: { request: { body: schema.buffer(), - query: buildRouteValidation(importListItemRequestQuery), + query: buildRouteValidationWithZod(ImportListItemsRequestQuery), }, }, version: '2023-10-31', @@ -119,12 +122,7 @@ export const importListItemRoute = (router: ListsPluginRouter, config: ConfigTyp version: 1, }); - const [validated, errors] = validate(list, importListItemResponse); - if (errors != null) { - return siemResponse.error({ body: errors, statusCode: 500 }); - } else { - return response.ok({ body: validated ?? {} }); - } + return response.ok({ body: ImportListItemsResponse.parse(list) }); } else if (type != null) { const importedList = await lists.importListItemsToStream({ deserializer, @@ -142,12 +140,8 @@ export const importListItemRoute = (router: ListsPluginRouter, config: ConfigTyp statusCode: 400, }); } - const [validated, errors] = validate(importedList, importListItemResponse); - if (errors != null) { - return siemResponse.error({ body: errors, statusCode: 500 }); - } else { - return response.ok({ body: validated ?? {} }); - } + + return response.ok({ body: ImportListItemsResponse.parse(importedList) }); } else { return siemResponse.error({ body: 'Either type or list_id need to be defined in the query', diff --git a/x-pack/plugins/lists/server/routes/list/patch_list_route.ts b/x-pack/plugins/lists/server/routes/list/patch_list_route.ts index 336239854f70b..fb14166d74f9c 100644 --- a/x-pack/plugins/lists/server/routes/list/patch_list_route.ts +++ b/x-pack/plugins/lists/server/routes/list/patch_list_route.ts @@ -5,13 +5,13 @@ * 2.0. */ -import { validate } from '@kbn/securitysolution-io-ts-utils'; import { transformError } from '@kbn/securitysolution-es-utils'; import { LIST_URL } from '@kbn/securitysolution-list-constants'; +import { buildRouteValidationWithZod } from '@kbn/zod-helpers'; +import { PatchListRequestBody, PatchListResponse } from '@kbn/securitysolution-lists-common/api'; import type { ListsPluginRouter } from '../../types'; -import { patchListRequest, patchListResponse } from '../../../common/api'; -import { buildRouteValidation, buildSiemResponse } from '../utils'; +import { buildSiemResponse } from '../utils'; import { getListClient } from '..'; export const patchListRoute = (router: ListsPluginRouter): void => { @@ -27,7 +27,7 @@ export const patchListRoute = (router: ListsPluginRouter): void => { { validate: { request: { - body: buildRouteValidation(patchListRequest), + body: buildRouteValidationWithZod(PatchListRequestBody), }, }, version: '2023-10-31', @@ -54,12 +54,7 @@ export const patchListRoute = (router: ListsPluginRouter): void => { statusCode: 404, }); } else { - const [validated, errors] = validate(list, patchListResponse); - if (errors != null) { - return siemResponse.error({ body: errors, statusCode: 500 }); - } else { - return response.ok({ body: validated ?? {} }); - } + return response.ok({ body: PatchListResponse.parse(list) }); } } catch (err) { const error = transformError(err); diff --git a/x-pack/plugins/lists/server/routes/list/read_list_route.ts b/x-pack/plugins/lists/server/routes/list/read_list_route.ts index ab403e933e53f..e9af8cfc8f4eb 100644 --- a/x-pack/plugins/lists/server/routes/list/read_list_route.ts +++ b/x-pack/plugins/lists/server/routes/list/read_list_route.ts @@ -5,13 +5,13 @@ * 2.0. */ -import { validate } from '@kbn/securitysolution-io-ts-utils'; import { transformError } from '@kbn/securitysolution-es-utils'; import { LIST_URL } from '@kbn/securitysolution-list-constants'; +import { buildRouteValidationWithZod } from '@kbn/zod-helpers'; +import { GetListRequestQuery, GetListResponse } from '@kbn/securitysolution-lists-common/api'; import type { ListsPluginRouter } from '../../types'; -import { readListRequestQuery, readListResponse } from '../../../common/api'; -import { buildRouteValidation, buildSiemResponse } from '../utils'; +import { buildSiemResponse } from '../utils'; import { getListClient } from '..'; export const readListRoute = (router: ListsPluginRouter): void => { @@ -27,7 +27,7 @@ export const readListRoute = (router: ListsPluginRouter): void => { { validate: { request: { - query: buildRouteValidation(readListRequestQuery), + query: buildRouteValidationWithZod(GetListRequestQuery), }, }, version: '2023-10-31', @@ -44,12 +44,7 @@ export const readListRoute = (router: ListsPluginRouter): void => { statusCode: 404, }); } else { - const [validated, errors] = validate(list, readListResponse); - if (errors != null) { - return siemResponse.error({ body: errors, statusCode: 500 }); - } else { - return response.ok({ body: validated ?? {} }); - } + return response.ok({ body: GetListResponse.parse(list) }); } } catch (err) { const error = transformError(err); diff --git a/x-pack/plugins/lists/server/routes/list/update_list_route.ts b/x-pack/plugins/lists/server/routes/list/update_list_route.ts index 46b2d8e058857..c20714b75e090 100644 --- a/x-pack/plugins/lists/server/routes/list/update_list_route.ts +++ b/x-pack/plugins/lists/server/routes/list/update_list_route.ts @@ -5,13 +5,13 @@ * 2.0. */ -import { validate } from '@kbn/securitysolution-io-ts-utils'; import { transformError } from '@kbn/securitysolution-es-utils'; import { LIST_URL } from '@kbn/securitysolution-list-constants'; +import { buildRouteValidationWithZod } from '@kbn/zod-helpers'; +import { UpdateListRequestBody, UpdateListResponse } from '@kbn/securitysolution-lists-common/api'; import type { ListsPluginRouter } from '../../types'; -import { updateListRequest, updateListResponse } from '../../../common/api'; -import { buildRouteValidation, buildSiemResponse } from '../utils'; +import { buildSiemResponse } from '../utils'; import { getListClient } from '..'; export const updateListRoute = (router: ListsPluginRouter): void => { @@ -27,7 +27,7 @@ export const updateListRoute = (router: ListsPluginRouter): void => { { validate: { request: { - body: buildRouteValidation(updateListRequest), + body: buildRouteValidationWithZod(UpdateListRequestBody), }, }, version: '2023-10-31', @@ -54,12 +54,7 @@ export const updateListRoute = (router: ListsPluginRouter): void => { statusCode: 404, }); } else { - const [validated, errors] = validate(list, updateListResponse); - if (errors != null) { - return siemResponse.error({ body: errors, statusCode: 500 }); - } else { - return response.ok({ body: validated ?? {} }); - } + return response.ok({ body: UpdateListResponse.parse(list) }); } } catch (err) { const error = transformError(err); diff --git a/x-pack/plugins/lists/server/routes/list_index/create_list_index_route.ts b/x-pack/plugins/lists/server/routes/list_index/create_list_index_route.ts index e3cab179c2f40..2f74871f23fc2 100644 --- a/x-pack/plugins/lists/server/routes/list_index/create_list_index_route.ts +++ b/x-pack/plugins/lists/server/routes/list_index/create_list_index_route.ts @@ -5,11 +5,10 @@ * 2.0. */ -import { validate } from '@kbn/securitysolution-io-ts-utils'; import { transformError } from '@kbn/securitysolution-es-utils'; import { LIST_INDEX } from '@kbn/securitysolution-list-constants'; +import { CreateListIndexResponse } from '@kbn/securitysolution-lists-common/api'; -import { createListIndexResponse } from '../../../common/api'; import type { ListsPluginRouter } from '../../types'; import { buildSiemResponse } from '../utils'; import { getListClient } from '..'; @@ -64,12 +63,7 @@ export const createListIndexRoute = (router: ListsPluginRouter): void => { : lists.createListItemDataStream()); } - const [validated, errors] = validate({ acknowledged: true }, createListIndexResponse); - if (errors != null) { - return siemResponse.error({ body: errors, statusCode: 500 }); - } else { - return response.ok({ body: validated ?? {} }); - } + return response.ok({ body: CreateListIndexResponse.parse({ acknowledged: true }) }); } catch (err) { const error = transformError(err); return siemResponse.error({ diff --git a/x-pack/plugins/lists/server/routes/list_index/delete_list_index_route.ts b/x-pack/plugins/lists/server/routes/list_index/delete_list_index_route.ts index a9683f4636151..0814739ab11e7 100644 --- a/x-pack/plugins/lists/server/routes/list_index/delete_list_index_route.ts +++ b/x-pack/plugins/lists/server/routes/list_index/delete_list_index_route.ts @@ -5,13 +5,12 @@ * 2.0. */ -import { validate } from '@kbn/securitysolution-io-ts-utils'; import { transformError } from '@kbn/securitysolution-es-utils'; import { LIST_INDEX } from '@kbn/securitysolution-list-constants'; +import { DeleteListIndexResponse } from '@kbn/securitysolution-lists-common/api'; import { ListClient } from '../../services/lists/list_client'; import type { ListsPluginRouter } from '../../types'; -import { deleteListIndexResponse } from '../../../common/api'; import { buildSiemResponse } from '../utils'; import { getListClient } from '..'; @@ -83,12 +82,7 @@ export const deleteListIndexRoute = (router: ListsPluginRouter): void => { await deleteIndexTemplates(lists); - const [validated, errors] = validate({ acknowledged: true }, deleteListIndexResponse); - if (errors != null) { - return siemResponse.error({ body: errors, statusCode: 500 }); - } else { - return response.ok({ body: validated ?? {} }); - } + return response.ok({ body: DeleteListIndexResponse.parse({ acknowledged: true }) }); } catch (err) { const error = transformError(err); return siemResponse.error({ diff --git a/x-pack/plugins/lists/server/routes/list_index/export_list_item_route.ts b/x-pack/plugins/lists/server/routes/list_index/export_list_item_route.ts index 1d43d4fd8c181..af9c40117f9c6 100644 --- a/x-pack/plugins/lists/server/routes/list_index/export_list_item_route.ts +++ b/x-pack/plugins/lists/server/routes/list_index/export_list_item_route.ts @@ -9,10 +9,11 @@ import { Stream } from 'stream'; import { transformError } from '@kbn/securitysolution-es-utils'; import { LIST_ITEM_URL } from '@kbn/securitysolution-list-constants'; +import { buildRouteValidationWithZod } from '@kbn/zod-helpers'; +import { ExportListItemsRequestQuery } from '@kbn/securitysolution-lists-common/api'; import type { ListsPluginRouter } from '../../types'; -import { exportListItemRequestQuery } from '../../../common/api'; -import { buildRouteValidation, buildSiemResponse } from '../utils'; +import { buildSiemResponse } from '../utils'; import { getListClient } from '..'; export const exportListItemRoute = (router: ListsPluginRouter): void => { @@ -28,7 +29,7 @@ export const exportListItemRoute = (router: ListsPluginRouter): void => { { validate: { request: { - query: buildRouteValidation(exportListItemRequestQuery), + query: buildRouteValidationWithZod(ExportListItemsRequestQuery), }, }, version: '2023-10-31', diff --git a/x-pack/plugins/lists/server/routes/list_index/find_list_route.ts b/x-pack/plugins/lists/server/routes/list_index/find_list_route.ts index 9b492006e0605..157b11e3832eb 100644 --- a/x-pack/plugins/lists/server/routes/list_index/find_list_route.ts +++ b/x-pack/plugins/lists/server/routes/list_index/find_list_route.ts @@ -5,14 +5,14 @@ * 2.0. */ -import { validate } from '@kbn/securitysolution-io-ts-utils'; import { transformError } from '@kbn/securitysolution-es-utils'; import { LIST_URL } from '@kbn/securitysolution-list-constants'; +import { buildRouteValidationWithZod } from '@kbn/zod-helpers'; +import { FindListsRequestQuery, FindListsResponse } from '@kbn/securitysolution-lists-common/api'; import type { ListsPluginRouter } from '../../types'; import { decodeCursor } from '../../services/utils'; -import { findListRequestQuery, findListResponse } from '../../../common/api'; -import { buildRouteValidation, buildSiemResponse, getListClient } from '../utils'; +import { buildSiemResponse, getListClient } from '../utils'; export const findListRoute = (router: ListsPluginRouter): void => { router.versioned @@ -27,7 +27,7 @@ export const findListRoute = (router: ListsPluginRouter): void => { { validate: { request: { - query: buildRouteValidation(findListRequestQuery), + query: buildRouteValidationWithZod(FindListsRequestQuery), }, }, version: '2023-10-31', @@ -74,12 +74,8 @@ export const findListRoute = (router: ListsPluginRouter): void => { sortField, sortOrder, }); - const [validated, errors] = validate(exceptionList, findListResponse); - if (errors != null) { - return siemResponse.error({ body: errors, statusCode: 500 }); - } else { - return response.ok({ body: validated ?? {} }); - } + + return response.ok({ body: FindListsResponse.parse(exceptionList) }); } } catch (err) { const error = transformError(err); diff --git a/x-pack/plugins/lists/server/routes/list_index/read_list_index_route.ts b/x-pack/plugins/lists/server/routes/list_index/read_list_index_route.ts index 6e9fdb29e55b8..80637788e00db 100644 --- a/x-pack/plugins/lists/server/routes/list_index/read_list_index_route.ts +++ b/x-pack/plugins/lists/server/routes/list_index/read_list_index_route.ts @@ -5,12 +5,11 @@ * 2.0. */ -import { validate } from '@kbn/securitysolution-io-ts-utils'; import { transformError } from '@kbn/securitysolution-es-utils'; import { LIST_INDEX } from '@kbn/securitysolution-list-constants'; +import { GetListIndexResponse } from '@kbn/securitysolution-lists-common/api'; import type { ListsPluginRouter } from '../../types'; -import { readListIndexResponse } from '../../../common/api'; import { buildSiemResponse } from '../utils'; import { getListClient } from '..'; @@ -37,15 +36,12 @@ export const readListIndexRoute = (router: ListsPluginRouter): void => { const listItemDataStreamExists = await lists.getListItemDataStreamExists(); if (listDataStreamExists && listItemDataStreamExists) { - const [validated, errors] = validate( - { list_index: listDataStreamExists, list_item_index: listItemDataStreamExists }, - readListIndexResponse - ); - if (errors != null) { - return siemResponse.error({ body: errors, statusCode: 500 }); - } else { - return response.ok({ body: validated ?? {} }); - } + return response.ok({ + body: GetListIndexResponse.parse({ + list_index: listDataStreamExists, + list_item_index: listItemDataStreamExists, + }), + }); } else if (!listDataStreamExists && listItemDataStreamExists) { return siemResponse.error({ body: `data stream ${lists.getListName()} does not exist`, diff --git a/x-pack/plugins/lists/server/routes/list_item/create_list_item_route.ts b/x-pack/plugins/lists/server/routes/list_item/create_list_item_route.ts index b3ab6f4e09eb7..2f8bd2738ae0f 100644 --- a/x-pack/plugins/lists/server/routes/list_item/create_list_item_route.ts +++ b/x-pack/plugins/lists/server/routes/list_item/create_list_item_route.ts @@ -5,13 +5,16 @@ * 2.0. */ -import { validate } from '@kbn/securitysolution-io-ts-utils'; import { transformError } from '@kbn/securitysolution-es-utils'; import { LIST_ITEM_URL } from '@kbn/securitysolution-list-constants'; +import { buildRouteValidationWithZod } from '@kbn/zod-helpers'; +import { + CreateListItemRequestBody, + CreateListItemResponse, +} from '@kbn/securitysolution-lists-common/api'; -import { createListItemRequest, createListItemResponse } from '../../../common/api'; import type { ListsPluginRouter } from '../../types'; -import { buildRouteValidation, buildSiemResponse } from '../utils'; +import { buildSiemResponse } from '../utils'; import { getListClient } from '..'; export const createListItemRoute = (router: ListsPluginRouter): void => { @@ -27,7 +30,7 @@ export const createListItemRoute = (router: ListsPluginRouter): void => { { validate: { request: { - body: buildRouteValidation(createListItemRequest), + body: buildRouteValidationWithZod(CreateListItemRequestBody), }, }, version: '2023-10-31', @@ -63,13 +66,9 @@ export const createListItemRoute = (router: ListsPluginRouter): void => { type: list.type, value, }); + if (createdListItem != null) { - const [validated, errors] = validate(createdListItem, createListItemResponse); - if (errors != null) { - return siemResponse.error({ body: errors, statusCode: 500 }); - } else { - return response.ok({ body: validated ?? {} }); - } + return response.ok({ body: CreateListItemResponse.parse(createdListItem) }); } else { return siemResponse.error({ body: 'list item invalid', diff --git a/x-pack/plugins/lists/server/routes/list_item/delete_list_item_route.ts b/x-pack/plugins/lists/server/routes/list_item/delete_list_item_route.ts index 644c8235bae06..2cf30a61988b0 100644 --- a/x-pack/plugins/lists/server/routes/list_item/delete_list_item_route.ts +++ b/x-pack/plugins/lists/server/routes/list_item/delete_list_item_route.ts @@ -5,17 +5,16 @@ * 2.0. */ -import { validate } from '@kbn/securitysolution-io-ts-utils'; import { transformError } from '@kbn/securitysolution-es-utils'; import { LIST_ITEM_URL } from '@kbn/securitysolution-list-constants'; +import { buildRouteValidationWithZod } from '@kbn/zod-helpers'; +import { + DeleteListItemRequestQuery, + DeleteListItemResponse, +} from '@kbn/securitysolution-lists-common/api'; import type { ListsPluginRouter } from '../../types'; -import { - deleteListItemArrayResponse, - deleteListItemRequestQuery, - deleteListItemResponse, -} from '../../../common/api'; -import { buildRouteValidation, buildSiemResponse } from '../utils'; +import { buildSiemResponse } from '../utils'; import { getListClient } from '..'; export const deleteListItemRoute = (router: ListsPluginRouter): void => { @@ -31,7 +30,7 @@ export const deleteListItemRoute = (router: ListsPluginRouter): void => { { validate: { request: { - query: buildRouteValidation(deleteListItemRequestQuery), + query: buildRouteValidationWithZod(DeleteListItemRequestQuery), }, }, version: '2023-10-31', @@ -50,12 +49,7 @@ export const deleteListItemRoute = (router: ListsPluginRouter): void => { statusCode: 404, }); } else { - const [validated, errors] = validate(deleted, deleteListItemResponse); - if (errors != null) { - return siemResponse.error({ body: errors, statusCode: 500 }); - } else { - return response.ok({ body: validated ?? {} }); - } + return response.ok({ body: DeleteListItemResponse.parse(deleted) }); } } else if (listId != null && value != null) { const list = await lists.getList({ id: listId }); @@ -77,12 +71,7 @@ export const deleteListItemRoute = (router: ListsPluginRouter): void => { statusCode: 404, }); } else { - const [validated, errors] = validate(deleted, deleteListItemArrayResponse); - if (errors != null) { - return siemResponse.error({ body: errors, statusCode: 500 }); - } else { - return response.ok({ body: validated ?? {} }); - } + return response.ok({ body: DeleteListItemResponse.parse(deleted) }); } } } else { diff --git a/x-pack/plugins/lists/server/routes/list_item/find_list_item_route.ts b/x-pack/plugins/lists/server/routes/list_item/find_list_item_route.ts index 0fd4300ea51dc..f65b678e36242 100644 --- a/x-pack/plugins/lists/server/routes/list_item/find_list_item_route.ts +++ b/x-pack/plugins/lists/server/routes/list_item/find_list_item_route.ts @@ -5,18 +5,17 @@ * 2.0. */ -import { validate } from '@kbn/securitysolution-io-ts-utils'; import { transformError } from '@kbn/securitysolution-es-utils'; import { LIST_ITEM_URL } from '@kbn/securitysolution-list-constants'; +import { buildRouteValidationWithZod } from '@kbn/zod-helpers'; +import { + FindListItemsRequestQuery, + FindListItemsResponse, +} from '@kbn/securitysolution-lists-common/api'; import type { ListsPluginRouter } from '../../types'; import { decodeCursor } from '../../services/utils'; -import { - FindListItemRequestQueryDecoded, - findListItemRequestQuery, - findListItemResponse, -} from '../../../common/api'; -import { buildRouteValidation, buildSiemResponse, getListClient } from '../utils'; +import { buildSiemResponse, getListClient } from '../utils'; export const findListItemRoute = (router: ListsPluginRouter): void => { router.versioned @@ -31,10 +30,7 @@ export const findListItemRoute = (router: ListsPluginRouter): void => { { validate: { request: { - query: buildRouteValidation< - typeof findListItemRequestQuery, - FindListItemRequestQueryDecoded - >(findListItemRequestQuery), + query: buildRouteValidationWithZod(FindListItemsRequestQuery), }, }, version: '2023-10-31', @@ -90,12 +86,7 @@ export const findListItemRoute = (router: ListsPluginRouter): void => { statusCode: 404, }); } else { - const [validated, errors] = validate(exceptionList, findListItemResponse); - if (errors != null) { - return siemResponse.error({ body: errors, statusCode: 500 }); - } else { - return response.ok({ body: validated ?? {} }); - } + return response.ok({ body: FindListItemsResponse.parse(exceptionList) }); } } } catch (err) { diff --git a/x-pack/plugins/lists/server/routes/list_item/patch_list_item_route.ts b/x-pack/plugins/lists/server/routes/list_item/patch_list_item_route.ts index ff369aa9403e8..68c82e93fcc38 100644 --- a/x-pack/plugins/lists/server/routes/list_item/patch_list_item_route.ts +++ b/x-pack/plugins/lists/server/routes/list_item/patch_list_item_route.ts @@ -5,13 +5,16 @@ * 2.0. */ -import { validate } from '@kbn/securitysolution-io-ts-utils'; import { transformError } from '@kbn/securitysolution-es-utils'; import { LIST_ITEM_URL } from '@kbn/securitysolution-list-constants'; +import { buildRouteValidationWithZod } from '@kbn/zod-helpers'; +import { + PatchListItemRequestBody, + PatchListItemResponse, +} from '@kbn/securitysolution-lists-common/api'; import type { ListsPluginRouter } from '../../types'; -import { patchListItemRequest, patchListItemResponse } from '../../../common/api'; -import { buildRouteValidation, buildSiemResponse } from '../utils'; +import { buildSiemResponse } from '../utils'; import { getListClient } from '..'; export const patchListItemRoute = (router: ListsPluginRouter): void => { @@ -27,7 +30,7 @@ export const patchListItemRoute = (router: ListsPluginRouter): void => { { validate: { request: { - body: buildRouteValidation(patchListItemRequest), + body: buildRouteValidationWithZod(PatchListItemRequestBody), }, }, version: '2023-10-31', @@ -61,12 +64,7 @@ export const patchListItemRoute = (router: ListsPluginRouter): void => { statusCode: 404, }); } else { - const [validated, errors] = validate(listItem, patchListItemResponse); - if (errors != null) { - return siemResponse.error({ body: errors, statusCode: 500 }); - } else { - return response.ok({ body: validated ?? {} }); - } + return response.ok({ body: PatchListItemResponse.parse(listItem) }); } } catch (err) { const error = transformError(err); diff --git a/x-pack/plugins/lists/server/routes/list_item/read_list_item_route.ts b/x-pack/plugins/lists/server/routes/list_item/read_list_item_route.ts index 67c4793736483..0e6a9dbe50155 100644 --- a/x-pack/plugins/lists/server/routes/list_item/read_list_item_route.ts +++ b/x-pack/plugins/lists/server/routes/list_item/read_list_item_route.ts @@ -5,17 +5,16 @@ * 2.0. */ -import { validate } from '@kbn/securitysolution-io-ts-utils'; import { transformError } from '@kbn/securitysolution-es-utils'; import { LIST_ITEM_URL } from '@kbn/securitysolution-list-constants'; +import { buildRouteValidationWithZod } from '@kbn/zod-helpers'; +import { + GetListItemRequestQuery, + GetListItemResponse, +} from '@kbn/securitysolution-lists-common/api'; import type { ListsPluginRouter } from '../../types'; -import { - readListItemArrayResponse, - readListItemRequestQuery, - readListItemResponse, -} from '../../../common/api'; -import { buildRouteValidation, buildSiemResponse } from '../utils'; +import { buildSiemResponse } from '../utils'; import { getListClient } from '..'; export const readListItemRoute = (router: ListsPluginRouter): void => { @@ -31,7 +30,7 @@ export const readListItemRoute = (router: ListsPluginRouter): void => { { validate: { request: { - query: buildRouteValidation(readListItemRequestQuery), + query: buildRouteValidationWithZod(GetListItemRequestQuery), }, }, version: '2023-10-31', @@ -49,12 +48,7 @@ export const readListItemRoute = (router: ListsPluginRouter): void => { statusCode: 404, }); } else { - const [validated, errors] = validate(listItem, readListItemResponse); - if (errors != null) { - return siemResponse.error({ body: errors, statusCode: 500 }); - } else { - return response.ok({ body: validated ?? {} }); - } + return response.ok({ body: GetListItemResponse.parse(listItem) }); } } else if (listId != null && value != null) { const list = await lists.getList({ id: listId }); @@ -75,12 +69,7 @@ export const readListItemRoute = (router: ListsPluginRouter): void => { statusCode: 404, }); } else { - const [validated, errors] = validate(listItem, readListItemArrayResponse); - if (errors != null) { - return siemResponse.error({ body: errors, statusCode: 500 }); - } else { - return response.ok({ body: validated ?? {} }); - } + return response.ok({ body: GetListItemResponse.parse(listItem) }); } } } else { diff --git a/x-pack/plugins/lists/server/routes/list_item/update_list_item_route.ts b/x-pack/plugins/lists/server/routes/list_item/update_list_item_route.ts index c627f9e9e95ea..8b2c4f65e54eb 100644 --- a/x-pack/plugins/lists/server/routes/list_item/update_list_item_route.ts +++ b/x-pack/plugins/lists/server/routes/list_item/update_list_item_route.ts @@ -5,13 +5,16 @@ * 2.0. */ -import { validate } from '@kbn/securitysolution-io-ts-utils'; import { transformError } from '@kbn/securitysolution-es-utils'; import { LIST_ITEM_URL } from '@kbn/securitysolution-list-constants'; +import { buildRouteValidationWithZod } from '@kbn/zod-helpers'; +import { + UpdateListItemRequestBody, + UpdateListItemResponse, +} from '@kbn/securitysolution-lists-common/api'; import type { ListsPluginRouter } from '../../types'; -import { updateListItemRequest, updateListItemResponse } from '../../../common/api'; -import { buildRouteValidation, buildSiemResponse } from '../utils'; +import { buildSiemResponse } from '../utils'; import { getListClient } from '..'; export const updateListItemRoute = (router: ListsPluginRouter): void => { @@ -27,7 +30,7 @@ export const updateListItemRoute = (router: ListsPluginRouter): void => { { validate: { request: { - body: buildRouteValidation(updateListItemRequest), + body: buildRouteValidationWithZod(UpdateListItemRequestBody), }, }, version: '2023-10-31', @@ -59,12 +62,7 @@ export const updateListItemRoute = (router: ListsPluginRouter): void => { statusCode: 404, }); } else { - const [validated, errors] = validate(listItem, updateListItemResponse); - if (errors != null) { - return siemResponse.error({ body: errors, statusCode: 500 }); - } else { - return response.ok({ body: validated ?? {} }); - } + return response.ok({ body: UpdateListItemResponse.parse(listItem) }); } } catch (err) { const error = transformError(err); diff --git a/x-pack/plugins/lists/tsconfig.json b/x-pack/plugins/lists/tsconfig.json index b18887c254336..47dc15c00ec8b 100644 --- a/x-pack/plugins/lists/tsconfig.json +++ b/x-pack/plugins/lists/tsconfig.json @@ -1,15 +1,14 @@ - { "extends": "../../../tsconfig.base.json", "compilerOptions": { - "outDir": "target/types", + "outDir": "target/types" }, "include": [ "common/**/*", "public/**/*", "server/**/*", // have to declare *.json explicitly due to https://github.com/microsoft/TypeScript/issues/25636 - "server/**/*.json", + "server/**/*.json" ], "kbn_references": [ "@kbn/core", @@ -20,6 +19,7 @@ "@kbn/securitysolution-list-constants", "@kbn/securitysolution-list-hooks", "@kbn/securitysolution-list-api", + "@kbn/securitysolution-lists-common", "@kbn/kibana-react-plugin", "@kbn/i18n", "@kbn/data-plugin", @@ -39,8 +39,7 @@ "@kbn/utility-types", "@kbn/core-elasticsearch-client-server-mocks", "@kbn/core-saved-objects-server", + "@kbn/zod-helpers" ], - "exclude": [ - "target/**/*", - ] + "exclude": ["target/**/*"] } 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 51e1843e9b8e8..b6e7ae696b755 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 @@ -6,11 +6,11 @@ */ import { transformError, BadRequestError, getIndexAliases } from '@kbn/securitysolution-es-utils'; +import { buildRouteValidationWithZod } from '@kbn/zod-helpers'; import { CreateAlertsMigrationRequestBody } from '../../../../../common/api/detection_engine/signals_migration'; import type { SecuritySolutionPluginRouter } from '../../../../types'; import type { SetupPlugins } from '../../../../plugin'; import { DETECTION_ENGINE_SIGNALS_MIGRATION_URL } from '../../../../../common/constants'; -import { buildRouteValidationWithZod } from '../../../../utils/build_validation/route_validation'; import { buildSiemResponse } from '../utils'; import { getTemplateVersion } from '../index/check_template_version'; 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 c2e364e58ca5b..f4452c73eaf78 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 @@ -6,11 +6,11 @@ */ import { transformError } from '@kbn/securitysolution-es-utils'; +import { buildRouteValidationWithZod } from '@kbn/zod-helpers'; import { AlertsMigrationCleanupRequestBody } from '../../../../../common/api/detection_engine/signals_migration'; import type { SecuritySolutionPluginRouter } from '../../../../types'; import type { SetupPlugins } from '../../../../plugin'; import { DETECTION_ENGINE_SIGNALS_MIGRATION_URL } from '../../../../../common/constants'; -import { buildRouteValidationWithZod } from '../../../../utils/build_validation/route_validation'; import { buildSiemResponse } from '../utils'; import { signalsMigrationService } from '../../migrations/migration_service'; 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 bfec0f82867a6..468baae7fdcad 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 @@ -7,11 +7,11 @@ import { transformError, BadRequestError } from '@kbn/securitysolution-es-utils'; import type { RuleDataPluginService } from '@kbn/rule-registry-plugin/server'; +import { buildRouteValidationWithZod } from '@kbn/zod-helpers'; import { FinalizeAlertsMigrationRequestBody } from '../../../../../common/api/detection_engine/signals_migration'; import type { SecuritySolutionPluginRouter } from '../../../../types'; import type { SetupPlugins } from '../../../../plugin'; import { DETECTION_ENGINE_SIGNALS_FINALIZE_MIGRATION_URL } from '../../../../../common/constants'; -import { buildRouteValidationWithZod } from '../../../../utils/build_validation/route_validation'; import { isMigrationFailed, isMigrationPending } from '../../migrations/helpers'; import { signalsMigrationService } from '../../migrations/migration_service'; import { buildSiemResponse } from '../utils'; 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 185e0c6ed6175..418db17b566c5 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 @@ -6,10 +6,10 @@ */ import { transformError, getIndexAliases } from '@kbn/securitysolution-es-utils'; +import { buildRouteValidationWithZod } from '@kbn/zod-helpers'; import { GetAlertsMigrationStatusRequestQuery } from '../../../../../common/api/detection_engine/signals_migration'; import type { SecuritySolutionPluginRouter } from '../../../../types'; import { DETECTION_ENGINE_SIGNALS_MIGRATION_STATUS_URL } from '../../../../../common/constants'; -import { buildRouteValidationWithZod } from '../../../../utils/build_validation/route_validation'; 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'; 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 3030e5fe799b6..5db7cc16b05ec 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 @@ -14,7 +14,7 @@ import { } from '@kbn/rule-data-utils'; import type { ElasticsearchClient, Logger, StartServicesAccessor } from '@kbn/core/server'; import type { AuthenticatedUser } from '@kbn/security-plugin/common'; -import { buildRouteValidationWithZod } from '../../../../utils/build_validation/route_validation'; +import { buildRouteValidationWithZod } from '@kbn/zod-helpers'; import { SetAlertsStatusRequestBody } from '../../../../../common/api/detection_engine/signals'; import type { SecuritySolutionPluginRouter } from '../../../../types'; import { 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 e868c2b979018..60e0bde69c590 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 @@ -9,8 +9,8 @@ import type { MappingRuntimeFields, Sort } from '@elastic/elasticsearch/lib/api/ import { transformError } from '@kbn/securitysolution-es-utils'; import type { IRuleDataClient } from '@kbn/rule-registry-plugin/server'; import type { AggregationsAggregationContainer } from '@elastic/elasticsearch/lib/api/types'; +import { buildRouteValidationWithZod } from '@kbn/zod-helpers'; import { SearchAlertsRequestBody } from '../../../../../common/api/detection_engine/signals'; -import { buildRouteValidationWithZod } from '../../../../utils/build_validation/route_validation'; import type { SecuritySolutionPluginRouter } from '../../../../types'; import { DETECTION_ENGINE_QUERY_SIGNALS_URL } from '../../../../../common/constants'; import { buildSiemResponse } from '../utils'; diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/signals/set_alert_assignees_route.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/signals/set_alert_assignees_route.ts index f15342a36f46c..1ce791143705b 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/signals/set_alert_assignees_route.ts +++ b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/signals/set_alert_assignees_route.ts @@ -7,6 +7,7 @@ import { transformError } from '@kbn/securitysolution-es-utils'; import { uniq } from 'lodash/fp'; +import { buildRouteValidationWithZod } from '@kbn/zod-helpers'; import { SetAlertAssigneesRequestBody } from '../../../../../common/api/detection_engine/alert_assignees'; import type { SecuritySolutionPluginRouter } from '../../../../types'; import { @@ -14,7 +15,6 @@ import { DETECTION_ENGINE_ALERT_ASSIGNEES_URL, } from '../../../../../common/constants'; import { buildSiemResponse } from '../utils'; -import { buildRouteValidationWithZod } from '../../../../utils/build_validation/route_validation'; import { validateAlertAssigneesArrays } from './helpers'; export const setAlertAssigneesRoute = (router: SecuritySolutionPluginRouter) => { diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/signals/set_alert_tags_route.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/signals/set_alert_tags_route.ts index 95d722ac0a381..c6997cc9a9bed 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/signals/set_alert_tags_route.ts +++ b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/signals/set_alert_tags_route.ts @@ -7,6 +7,7 @@ import { transformError } from '@kbn/securitysolution-es-utils'; import { uniq } from 'lodash/fp'; +import { buildRouteValidationWithZod } from '@kbn/zod-helpers'; import { ManageAlertTagsRequestBody } from '../../../../../common/api/detection_engine/alert_tags'; import type { SecuritySolutionPluginRouter } from '../../../../types'; import { @@ -14,7 +15,6 @@ import { DETECTION_ENGINE_ALERT_TAGS_URL, } from '../../../../../common/constants'; import { buildSiemResponse } from '../utils'; -import { buildRouteValidationWithZod } from '../../../../utils/build_validation/route_validation'; import { validateAlertTagsArrays } from './helpers'; export const setAlertTagsRoute = (router: SecuritySolutionPluginRouter) => { diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/users/suggest_user_profiles_route.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/users/suggest_user_profiles_route.ts index 76787a82b7799..1b1aeada05660 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/routes/users/suggest_user_profiles_route.ts +++ b/x-pack/plugins/security_solution/server/lib/detection_engine/routes/users/suggest_user_profiles_route.ts @@ -8,11 +8,11 @@ import type { IKibanaResponse, StartServicesAccessor } from '@kbn/core/server'; import { transformError } from '@kbn/securitysolution-es-utils'; import type { UserProfileWithAvatar } from '@kbn/user-profile-components'; +import { buildRouteValidationWithZod } from '@kbn/zod-helpers'; import type { SecuritySolutionPluginRouter } from '../../../../types'; import { DETECTION_ENGINE_ALERT_SUGGEST_USERS_URL } from '../../../../../common/constants'; import { buildSiemResponse } from '../utils'; import type { StartPlugins } from '../../../../plugin'; -import { buildRouteValidationWithZod } from '../../../../utils/build_validation/route_validation'; import { SuggestUserProfilesRequestQuery } from '../../../../../common/api/detection_engine/users'; export const suggestUserProfilesRoute = ( diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/rule_management/api/rules/bulk_actions/route.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/rule_management/api/rules/bulk_actions/route.ts index ff608a6344057..1177d4363fe29 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/rule_management/api/rules/bulk_actions/route.ts +++ b/x-pack/plugins/security_solution/server/lib/detection_engine/rule_management/api/rules/bulk_actions/route.ts @@ -8,6 +8,7 @@ import type { IKibanaResponse, Logger } from '@kbn/core/server'; import { AbortError } from '@kbn/kibana-utils-plugin/common'; import { transformError } from '@kbn/securitysolution-es-utils'; +import { buildRouteValidationWithZod } from '@kbn/zod-helpers'; import type { ConfigType } from '../../../../../../config'; import type { PerformBulkActionResponse } from '../../../../../../../common/api/detection_engine/rule_management'; import { @@ -22,7 +23,6 @@ import { } from '../../../../../../../common/constants'; import type { SetupPlugins } from '../../../../../../plugin'; import type { SecuritySolutionPluginRouter } from '../../../../../../types'; -import { buildRouteValidationWithZod } from '../../../../../../utils/build_validation/route_validation'; import { initPromisePool } from '../../../../../../utils/promise_pool'; import { routeLimitedConcurrencyTag } from '../../../../../../utils/route_limited_concurrency_tag'; import { buildMlAuthz } from '../../../../../machine_learning/authz'; diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/rule_management/api/rules/bulk_create_rules/route.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/rule_management/api/rules/bulk_create_rules/route.ts index ba6eebce2207c..98910ea337630 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/rule_management/api/rules/bulk_create_rules/route.ts +++ b/x-pack/plugins/security_solution/server/lib/detection_engine/rule_management/api/rules/bulk_create_rules/route.ts @@ -8,6 +8,7 @@ import type { IKibanaResponse, Logger } from '@kbn/core/server'; import { transformError } from '@kbn/securitysolution-es-utils'; +import { buildRouteValidationWithZod } from '@kbn/zod-helpers'; import { DETECTION_ENGINE_RULES_BULK_CREATE } from '../../../../../../../common/constants'; import { BulkCreateRulesRequestBody, @@ -18,7 +19,6 @@ import { import type { SecuritySolutionPluginRouter } from '../../../../../../types'; import { readRules } from '../../../logic/detection_rules_client/read_rules'; import { getDuplicates } from './get_duplicates'; -import { buildRouteValidationWithZod } from '../../../../../../utils/build_validation/route_validation'; import { validateRuleDefaultExceptionList } from '../../../logic/exceptions/validate_rule_default_exception_list'; import { validateRulesWithDuplicatedDefaultExceptionsList } from '../../../logic/exceptions/validate_rules_with_duplicated_default_exceptions_list'; import { RULE_MANAGEMENT_BULK_ACTION_SOCKET_TIMEOUT_MS } from '../../timeouts'; diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/rule_management/api/rules/bulk_delete_rules/route.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/rule_management/api/rules/bulk_delete_rules/route.ts index 234439eb49052..2f1ef59d0971b 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/rule_management/api/rules/bulk_delete_rules/route.ts +++ b/x-pack/plugins/security_solution/server/lib/detection_engine/rule_management/api/rules/bulk_delete_rules/route.ts @@ -8,6 +8,7 @@ import type { VersionedRouteConfig } from '@kbn/core-http-server'; import type { IKibanaResponse, Logger, RequestHandler } from '@kbn/core/server'; import { transformError } from '@kbn/securitysolution-es-utils'; +import { buildRouteValidationWithZod } from '@kbn/zod-helpers'; import { BulkCrudRulesResponse, BulkDeleteRulesRequestBody, @@ -18,7 +19,6 @@ import type { SecuritySolutionPluginRouter, SecuritySolutionRequestHandlerContext, } from '../../../../../../types'; -import { buildRouteValidationWithZod } from '../../../../../../utils/build_validation/route_validation'; import { buildSiemResponse, createBulkErrorObject, diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/rule_management/api/rules/bulk_patch_rules/route.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/rule_management/api/rules/bulk_patch_rules/route.ts index a3752d421380b..aa06c04db0619 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/rule_management/api/rules/bulk_patch_rules/route.ts +++ b/x-pack/plugins/security_solution/server/lib/detection_engine/rule_management/api/rules/bulk_patch_rules/route.ts @@ -8,13 +8,12 @@ import type { IKibanaResponse, Logger } from '@kbn/core/server'; import { transformError } from '@kbn/securitysolution-es-utils'; +import { buildRouteValidationWithZod } from '@kbn/zod-helpers'; import { DETECTION_ENGINE_RULES_BULK_UPDATE } from '../../../../../../../common/constants'; import { BulkPatchRulesRequestBody, BulkCrudRulesResponse, } from '../../../../../../../common/api/detection_engine/rule_management'; - -import { buildRouteValidationWithZod } from '../../../../../../utils/build_validation/route_validation'; import type { SecuritySolutionPluginRouter } from '../../../../../../types'; import { transformBulkError, buildSiemResponse } from '../../../../routes/utils'; import { getIdBulkError } from '../../../utils/utils'; diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/rule_management/api/rules/bulk_update_rules/route.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/rule_management/api/rules/bulk_update_rules/route.ts index e08d781cd74d8..bae89a74ab0b1 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/rule_management/api/rules/bulk_update_rules/route.ts +++ b/x-pack/plugins/security_solution/server/lib/detection_engine/rule_management/api/rules/bulk_update_rules/route.ts @@ -6,15 +6,13 @@ */ import type { IKibanaResponse, Logger } from '@kbn/core/server'; - +import { buildRouteValidationWithZod } from '@kbn/zod-helpers'; import { transformError } from '@kbn/securitysolution-es-utils'; import { BulkUpdateRulesRequestBody, validateUpdateRuleProps, BulkCrudRulesResponse, } from '../../../../../../../common/api/detection_engine/rule_management'; - -import { buildRouteValidationWithZod } from '../../../../../../utils/build_validation/route_validation'; import type { SecuritySolutionPluginRouter } from '../../../../../../types'; import { DETECTION_ENGINE_RULES_BULK_UPDATE } from '../../../../../../../common/constants'; import { getIdBulkError } from '../../../utils/utils'; diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/rule_management/api/rules/create_rule/route.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/rule_management/api/rules/create_rule/route.ts index 3819154c1b8a3..aa6425b2e673c 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/rule_management/api/rules/create_rule/route.ts +++ b/x-pack/plugins/security_solution/server/lib/detection_engine/rule_management/api/rules/create_rule/route.ts @@ -7,6 +7,7 @@ import type { IKibanaResponse } from '@kbn/core/server'; import { transformError } from '@kbn/securitysolution-es-utils'; +import { buildRouteValidationWithZod } from '@kbn/zod-helpers'; import type { CreateRuleResponse } from '../../../../../../../common/api/detection_engine/rule_management'; import { CreateRuleRequestBody, @@ -14,7 +15,6 @@ import { } from '../../../../../../../common/api/detection_engine/rule_management'; import { DETECTION_ENGINE_RULES_URL } from '../../../../../../../common/constants'; import type { SecuritySolutionPluginRouter } from '../../../../../../types'; -import { buildRouteValidationWithZod } from '../../../../../../utils/build_validation/route_validation'; import { buildSiemResponse } from '../../../../routes/utils'; import { readRules } from '../../../logic/detection_rules_client/read_rules'; import { checkDefaultRuleExceptionListReferences } from '../../../logic/exceptions/check_for_default_rule_exception_list'; diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/rule_management/api/rules/delete_rule/route.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/rule_management/api/rules/delete_rule/route.ts index 3cf9aa6a2fb55..42a6a1c47544f 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/rule_management/api/rules/delete_rule/route.ts +++ b/x-pack/plugins/security_solution/server/lib/detection_engine/rule_management/api/rules/delete_rule/route.ts @@ -7,6 +7,7 @@ import type { IKibanaResponse } from '@kbn/core/server'; import { transformError } from '@kbn/securitysolution-es-utils'; +import { buildRouteValidationWithZod } from '@kbn/zod-helpers'; import type { DeleteRuleResponse } from '../../../../../../../common/api/detection_engine/rule_management'; import { DeleteRuleRequestQuery, @@ -14,7 +15,6 @@ import { } from '../../../../../../../common/api/detection_engine/rule_management'; import { DETECTION_ENGINE_RULES_URL } from '../../../../../../../common/constants'; import type { SecuritySolutionPluginRouter } from '../../../../../../types'; -import { buildRouteValidationWithZod } from '../../../../../../utils/build_validation/route_validation'; import { buildSiemResponse } from '../../../../routes/utils'; import { readRules } from '../../../logic/detection_rules_client/read_rules'; import { getIdError, transform } from '../../../utils/utils'; diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/rule_management/api/rules/export_rules/route.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/rule_management/api/rules/export_rules/route.ts index 301bb62452f28..478a0ce02cc96 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/rule_management/api/rules/export_rules/route.ts +++ b/x-pack/plugins/security_solution/server/lib/detection_engine/rule_management/api/rules/export_rules/route.ts @@ -7,14 +7,12 @@ import { transformError } from '@kbn/securitysolution-es-utils'; import type { Logger } from '@kbn/core/server'; - +import { buildRouteValidationWithZod } from '@kbn/zod-helpers'; import { DETECTION_ENGINE_RULES_URL } from '../../../../../../../common/constants'; import { ExportRulesRequestBody, ExportRulesRequestQuery, } from '../../../../../../../common/api/detection_engine/rule_management'; - -import { buildRouteValidationWithZod } from '../../../../../../utils/build_validation/route_validation'; import type { SecuritySolutionPluginRouter } from '../../../../../../types'; import type { ConfigType } from '../../../../../../config'; import { getNonPackagedRulesCount } from '../../../logic/search/get_existing_prepackaged_rules'; diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/rule_management/api/rules/find_rules/route.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/rule_management/api/rules/find_rules/route.ts index 3cbd164586a9d..02ff637ab6f10 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/rule_management/api/rules/find_rules/route.ts +++ b/x-pack/plugins/security_solution/server/lib/detection_engine/rule_management/api/rules/find_rules/route.ts @@ -7,7 +7,7 @@ import type { IKibanaResponse, Logger } from '@kbn/core/server'; import { transformError } from '@kbn/securitysolution-es-utils'; - +import { buildRouteValidationWithZod } from '@kbn/zod-helpers'; import { DETECTION_ENGINE_RULES_URL_FIND } from '../../../../../../../common/constants'; import type { FindRulesResponse } from '../../../../../../../common/api/detection_engine/rule_management'; import { @@ -18,7 +18,6 @@ import { import type { SecuritySolutionPluginRouter } from '../../../../../../types'; import { findRules } from '../../../logic/search/find_rules'; import { buildSiemResponse } from '../../../../routes/utils'; -import { buildRouteValidationWithZod } from '../../../../../../utils/build_validation/route_validation'; import { transformFindAlerts } from '../../../utils/utils'; export const findRulesRoute = (router: SecuritySolutionPluginRouter, logger: Logger) => { diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/rule_management/api/rules/import_rules/route.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/rule_management/api/rules/import_rules/route.ts index 45379d3d17555..297a4cb587352 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/rule_management/api/rules/import_rules/route.ts +++ b/x-pack/plugins/security_solution/server/lib/detection_engine/rule_management/api/rules/import_rules/route.ts @@ -11,6 +11,7 @@ import { transformError } from '@kbn/securitysolution-es-utils'; import { createPromiseFromStreams } from '@kbn/utils'; import { chunk } from 'lodash/fp'; import { extname } from 'path'; +import { buildRouteValidationWithZod } from '@kbn/zod-helpers'; import { ImportRulesRequestQuery, ImportRulesResponse, @@ -18,7 +19,6 @@ import { import { DETECTION_ENGINE_RULES_URL } from '../../../../../../../common/constants'; import type { ConfigType } from '../../../../../../config'; import type { HapiReadableStream, SecuritySolutionPluginRouter } from '../../../../../../types'; -import { buildRouteValidationWithZod } from '../../../../../../utils/build_validation/route_validation'; import type { BulkError, ImportRuleResponse } from '../../../../routes/utils'; import { buildSiemResponse, isBulkError, isImportRegular } from '../../../../routes/utils'; import { importRuleActionConnectors } from '../../../logic/import/action_connectors/import_rule_action_connectors'; diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/rule_management/api/rules/patch_rule/route.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/rule_management/api/rules/patch_rule/route.ts index 38b283b2c5fb6..506b36d4441dc 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/rule_management/api/rules/patch_rule/route.ts +++ b/x-pack/plugins/security_solution/server/lib/detection_engine/rule_management/api/rules/patch_rule/route.ts @@ -7,6 +7,7 @@ import type { IKibanaResponse } from '@kbn/core/server'; import { transformError } from '@kbn/securitysolution-es-utils'; +import { buildRouteValidationWithZod } from '@kbn/zod-helpers'; import type { PatchRuleResponse } from '../../../../../../../common/api/detection_engine/rule_management'; import { PatchRuleRequestBody, @@ -14,7 +15,6 @@ import { } from '../../../../../../../common/api/detection_engine/rule_management'; import { DETECTION_ENGINE_RULES_URL } from '../../../../../../../common/constants'; import type { SecuritySolutionPluginRouter } from '../../../../../../types'; -import { buildRouteValidationWithZod } from '../../../../../../utils/build_validation/route_validation'; import { buildSiemResponse } from '../../../../routes/utils'; import { readRules } from '../../../logic/detection_rules_client/read_rules'; import { checkDefaultRuleExceptionListReferences } from '../../../logic/exceptions/check_for_default_rule_exception_list'; diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/rule_management/api/rules/read_rule/route.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/rule_management/api/rules/read_rule/route.ts index 95992618b0625..a119d1afae912 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/rule_management/api/rules/read_rule/route.ts +++ b/x-pack/plugins/security_solution/server/lib/detection_engine/rule_management/api/rules/read_rule/route.ts @@ -7,6 +7,7 @@ import type { IKibanaResponse, Logger } from '@kbn/core/server'; import { transformError } from '@kbn/securitysolution-es-utils'; +import { buildRouteValidationWithZod } from '@kbn/zod-helpers'; import type { ReadRuleResponse } from '../../../../../../../common/api/detection_engine/rule_management'; import { ReadRuleRequestQuery, @@ -14,7 +15,6 @@ import { } from '../../../../../../../common/api/detection_engine/rule_management'; import { DETECTION_ENGINE_RULES_URL } from '../../../../../../../common/constants'; import type { SecuritySolutionPluginRouter } from '../../../../../../types'; -import { buildRouteValidationWithZod } from '../../../../../../utils/build_validation/route_validation'; import { buildSiemResponse } from '../../../../routes/utils'; import { readRules } from '../../../logic/detection_rules_client/read_rules'; import { getIdError, transform } from '../../../utils/utils'; diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/rule_management/api/rules/update_rule/route.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/rule_management/api/rules/update_rule/route.ts index 5ac2df600908c..5e77fa64e1fb9 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/rule_management/api/rules/update_rule/route.ts +++ b/x-pack/plugins/security_solution/server/lib/detection_engine/rule_management/api/rules/update_rule/route.ts @@ -7,6 +7,7 @@ import type { IKibanaResponse } from '@kbn/core/server'; import { transformError } from '@kbn/securitysolution-es-utils'; +import { buildRouteValidationWithZod } from '@kbn/zod-helpers'; import type { UpdateRuleResponse } from '../../../../../../../common/api/detection_engine/rule_management'; import { UpdateRuleRequestBody, @@ -14,7 +15,6 @@ import { } from '../../../../../../../common/api/detection_engine/rule_management'; import { DETECTION_ENGINE_RULES_URL } from '../../../../../../../common/constants'; import type { SecuritySolutionPluginRouter } from '../../../../../../types'; -import { buildRouteValidationWithZod } from '../../../../../../utils/build_validation/route_validation'; import { buildSiemResponse } from '../../../../routes/utils'; import { readRules } from '../../../logic/detection_rules_client/read_rules'; import { checkDefaultRuleExceptionListReferences } from '../../../logic/exceptions/check_for_default_rule_exception_list'; diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/rule_monitoring/api/rule_execution_logs/get_rule_execution_events/get_rule_execution_events_route.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/rule_monitoring/api/rule_execution_logs/get_rule_execution_events/get_rule_execution_events_route.ts index 4a01a6550cabc..4e8001193b5c5 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/rule_monitoring/api/rule_execution_logs/get_rule_execution_events/get_rule_execution_events_route.ts +++ b/x-pack/plugins/security_solution/server/lib/detection_engine/rule_monitoring/api/rule_execution_logs/get_rule_execution_events/get_rule_execution_events_route.ts @@ -7,7 +7,7 @@ import { transformError } from '@kbn/securitysolution-es-utils'; import type { IKibanaResponse } from '@kbn/core/server'; -import { buildRouteValidationWithZod } from '../../../../../../utils/build_validation/route_validation'; +import { buildRouteValidationWithZod } from '@kbn/zod-helpers'; import { buildSiemResponse } from '../../../../routes/utils'; import type { SecuritySolutionPluginRouter } from '../../../../../../types'; diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/rule_monitoring/api/rule_execution_logs/get_rule_execution_results/get_rule_execution_results_route.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/rule_monitoring/api/rule_execution_logs/get_rule_execution_results/get_rule_execution_results_route.ts index 6c71652d27e34..bf3a9864260ac 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/rule_monitoring/api/rule_execution_logs/get_rule_execution_results/get_rule_execution_results_route.ts +++ b/x-pack/plugins/security_solution/server/lib/detection_engine/rule_monitoring/api/rule_execution_logs/get_rule_execution_results/get_rule_execution_results_route.ts @@ -7,8 +7,8 @@ import type { IKibanaResponse } from '@kbn/core/server'; import { transformError } from '@kbn/securitysolution-es-utils'; +import { buildRouteValidationWithZod } from '@kbn/zod-helpers'; import type { SecuritySolutionPluginRouter } from '../../../../../../types'; -import { buildRouteValidationWithZod } from '../../../../../../utils/build_validation/route_validation'; import { buildSiemResponse } from '../../../../routes/utils'; import type { GetRuleExecutionResultsResponse } from '../../../../../../../common/api/detection_engine/rule_monitoring'; diff --git a/x-pack/plugins/security_solution/server/lib/detection_engine/rule_preview/api/preview_rules/route.ts b/x-pack/plugins/security_solution/server/lib/detection_engine/rule_preview/api/preview_rules/route.ts index 8c4137bf3d386..c2faa464b75da 100644 --- a/x-pack/plugins/security_solution/server/lib/detection_engine/rule_preview/api/preview_rules/route.ts +++ b/x-pack/plugins/security_solution/server/lib/detection_engine/rule_preview/api/preview_rules/route.ts @@ -19,7 +19,7 @@ import type { import { parseDuration, DISABLE_FLAPPING_SETTINGS } from '@kbn/alerting-plugin/common'; import type { ExecutorType } from '@kbn/alerting-plugin/server/types'; import type { Alert } from '@kbn/alerting-plugin/server'; - +import { buildRouteValidationWithZod } from '@kbn/zod-helpers'; import { DEFAULT_PREVIEW_INDEX, DETECTION_ENGINE_RULES_PREVIEW, @@ -40,7 +40,6 @@ import { createPreviewRuleExecutionLogger } from './preview_rule_execution_logge import { parseInterval } from '../../../rule_types/utils/utils'; import { buildMlAuthz } from '../../../../machine_learning/authz'; import { throwAuthzError } from '../../../../machine_learning/validation'; -import { buildRouteValidationWithZod } from '../../../../../utils/build_validation/route_validation'; import { routeLimitedConcurrencyTag } from '../../../../../utils/route_limited_concurrency_tag'; import type { SecuritySolutionPluginRouter } from '../../../../../types'; diff --git a/x-pack/plugins/security_solution/server/lib/entity_analytics/asset_criticality/routes/delete.ts b/x-pack/plugins/security_solution/server/lib/entity_analytics/asset_criticality/routes/delete.ts index e2737c6ebe045..c7a0f07400cc8 100644 --- a/x-pack/plugins/security_solution/server/lib/entity_analytics/asset_criticality/routes/delete.ts +++ b/x-pack/plugins/security_solution/server/lib/entity_analytics/asset_criticality/routes/delete.ts @@ -7,6 +7,7 @@ import type { IKibanaResponse, KibanaResponseFactory, Logger } from '@kbn/core/server'; import { buildSiemResponse } from '@kbn/lists-plugin/server/routes/utils'; import { transformError } from '@kbn/securitysolution-es-utils'; +import { buildRouteValidationWithZod } from '@kbn/zod-helpers'; import type { SecuritySolutionRequestHandlerContext } from '../../../../types'; import { ASSET_CRITICALITY_PUBLIC_URL, @@ -16,7 +17,6 @@ import { API_VERSIONS, } from '../../../../../common/constants'; import { DeleteAssetCriticalityRecord } from '../../../../../common/api/entity_analytics/asset_criticality'; -import { buildRouteValidationWithZod } from '../../../../utils/build_validation/route_validation'; import { checkAndInitAssetCriticalityResources } from '../check_and_init_asset_criticality_resources'; import { assertAdvancedSettingsEnabled } from '../../utils/assert_advanced_setting_enabled'; import type { EntityAnalyticsRoutesDeps } from '../../types'; diff --git a/x-pack/plugins/security_solution/server/lib/entity_analytics/asset_criticality/routes/get.ts b/x-pack/plugins/security_solution/server/lib/entity_analytics/asset_criticality/routes/get.ts index 57e52724b94ce..07d0cb3098dbc 100644 --- a/x-pack/plugins/security_solution/server/lib/entity_analytics/asset_criticality/routes/get.ts +++ b/x-pack/plugins/security_solution/server/lib/entity_analytics/asset_criticality/routes/get.ts @@ -7,6 +7,7 @@ import type { IKibanaResponse, KibanaResponseFactory, Logger } from '@kbn/core/server'; import { buildSiemResponse } from '@kbn/lists-plugin/server/routes/utils'; import { transformError } from '@kbn/securitysolution-es-utils'; +import { buildRouteValidationWithZod } from '@kbn/zod-helpers'; import type { SecuritySolutionRequestHandlerContext } from '../../../../types'; import { ASSET_CRITICALITY_INTERNAL_URL, @@ -16,7 +17,6 @@ import { API_VERSIONS, } from '../../../../../common/constants'; import { checkAndInitAssetCriticalityResources } from '../check_and_init_asset_criticality_resources'; -import { buildRouteValidationWithZod } from '../../../../utils/build_validation/route_validation'; import { AssetCriticalityRecordIdParts } from '../../../../../common/api/entity_analytics/asset_criticality'; import { assertAdvancedSettingsEnabled } from '../../utils/assert_advanced_setting_enabled'; import type { EntityAnalyticsRoutesDeps } from '../../types'; diff --git a/x-pack/plugins/security_solution/server/lib/entity_analytics/asset_criticality/routes/upsert.ts b/x-pack/plugins/security_solution/server/lib/entity_analytics/asset_criticality/routes/upsert.ts index d367a1f8bd4d3..78fbe29786298 100644 --- a/x-pack/plugins/security_solution/server/lib/entity_analytics/asset_criticality/routes/upsert.ts +++ b/x-pack/plugins/security_solution/server/lib/entity_analytics/asset_criticality/routes/upsert.ts @@ -7,6 +7,7 @@ import type { IKibanaResponse, KibanaResponseFactory, Logger } from '@kbn/core/server'; import { buildSiemResponse } from '@kbn/lists-plugin/server/routes/utils'; import { transformError } from '@kbn/securitysolution-es-utils'; +import { buildRouteValidationWithZod } from '@kbn/zod-helpers'; import type { SecuritySolutionRequestHandlerContext } from '../../../../types'; import { ASSET_CRITICALITY_PUBLIC_URL, @@ -16,7 +17,6 @@ import { API_VERSIONS, } from '../../../../../common/constants'; import { checkAndInitAssetCriticalityResources } from '../check_and_init_asset_criticality_resources'; -import { buildRouteValidationWithZod } from '../../../../utils/build_validation/route_validation'; import { CreateAssetCriticalityRecord } from '../../../../../common/api/entity_analytics'; import type { EntityAnalyticsRoutesDeps } from '../../types'; import { AssetCriticalityAuditActions } from '../audit'; diff --git a/x-pack/plugins/security_solution/server/lib/entity_analytics/risk_score/routes/calculation.ts b/x-pack/plugins/security_solution/server/lib/entity_analytics/risk_score/routes/calculation.ts index be4875d7dee04..1602e724db227 100644 --- a/x-pack/plugins/security_solution/server/lib/entity_analytics/risk_score/routes/calculation.ts +++ b/x-pack/plugins/security_solution/server/lib/entity_analytics/risk_score/routes/calculation.ts @@ -8,13 +8,13 @@ import type { Logger } from '@kbn/core/server'; import { buildSiemResponse } from '@kbn/lists-plugin/server/routes/utils'; import { transformError } from '@kbn/securitysolution-es-utils'; +import { buildRouteValidationWithZod } from '@kbn/zod-helpers'; import { RiskScoresCalculationRequest } from '../../../../../common/api/entity_analytics/risk_engine/calculation_route.gen'; import { APP_ID, DEFAULT_RISK_SCORE_PAGE_SIZE, RISK_SCORE_CALCULATION_URL, } from '../../../../../common/constants'; -import { buildRouteValidationWithZod } from '../../../../utils/build_validation/route_validation'; import { getRiskInputsIndex } from '../get_risk_inputs_index'; import type { EntityAnalyticsRoutesDeps } from '../../types'; import { RiskScoreAuditActions } from '../audit'; diff --git a/x-pack/plugins/security_solution/server/lib/entity_analytics/risk_score/routes/entity_calculation.ts b/x-pack/plugins/security_solution/server/lib/entity_analytics/risk_score/routes/entity_calculation.ts index fe6e404e9e96d..eeb773b41a180 100644 --- a/x-pack/plugins/security_solution/server/lib/entity_analytics/risk_score/routes/entity_calculation.ts +++ b/x-pack/plugins/security_solution/server/lib/entity_analytics/risk_score/routes/entity_calculation.ts @@ -5,16 +5,15 @@ * 2.0. */ +import { isEmpty } from 'lodash/fp'; import type { Logger } from '@kbn/core/server'; import { buildSiemResponse } from '@kbn/lists-plugin/server/routes/utils'; import { transformError } from '@kbn/securitysolution-es-utils'; - -import { isEmpty } from 'lodash/fp'; +import { buildRouteValidationWithZod } from '@kbn/zod-helpers'; import type { RiskScoresCalculationResponse } from '../../../../../common/api/entity_analytics/risk_engine/calculation_route.gen'; import type { AfterKeys } from '../../../../../common/api/entity_analytics/common'; import { RiskScoresEntityCalculationRequest } from '../../../../../common/api/entity_analytics/risk_engine/entity_calculation_route.gen'; import { APP_ID, RISK_SCORE_ENTITY_CALCULATION_URL } from '../../../../../common/constants'; -import { buildRouteValidationWithZod } from '../../../../utils/build_validation/route_validation'; import { getRiskInputsIndex } from '../get_risk_inputs_index'; import type { EntityAnalyticsRoutesDeps } from '../../types'; import { RiskScoreAuditActions } from '../audit'; diff --git a/x-pack/plugins/security_solution/server/lib/entity_analytics/risk_score/routes/preview.ts b/x-pack/plugins/security_solution/server/lib/entity_analytics/risk_score/routes/preview.ts index 0979b5900737a..d17dc8c99e19e 100644 --- a/x-pack/plugins/security_solution/server/lib/entity_analytics/risk_score/routes/preview.ts +++ b/x-pack/plugins/security_solution/server/lib/entity_analytics/risk_score/routes/preview.ts @@ -8,14 +8,13 @@ import type { Logger } from '@kbn/core/server'; import { buildSiemResponse } from '@kbn/lists-plugin/server/routes/utils'; import { transformError } from '@kbn/securitysolution-es-utils'; - +import { buildRouteValidationWithZod } from '@kbn/zod-helpers'; import { RiskScoresPreviewRequest } from '../../../../../common/api/entity_analytics/risk_engine/preview_route.gen'; import { APP_ID, DEFAULT_RISK_SCORE_PAGE_SIZE, RISK_SCORE_PREVIEW_URL, } from '../../../../../common/constants'; -import { buildRouteValidationWithZod } from '../../../../utils/build_validation/route_validation'; import { getRiskInputsIndex } from '../get_risk_inputs_index'; import type { EntityAnalyticsRoutesDeps } from '../../types'; import { RiskScoreAuditActions } from '../audit'; 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 7775186cde97f..57692b515a230 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 @@ -14,8 +14,6 @@ import type { RouteValidationResultFactory, RouteValidationError, } from '@kbn/core/server'; -import type { TypeOf, ZodType } from 'zod'; -import { stringifyZodError } from '@kbn/zod-helpers'; import type { GenericIntersectionC } from '../runtime_types'; import { excess } from '../runtime_types'; @@ -67,14 +65,3 @@ export const buildRouteValidationWithExcess = (validatedInput: A) => validationResult.ok(validatedInput) ) ); - -export const buildRouteValidationWithZod = - >(schema: T): RouteValidationFunction => - (inputValue: unknown, validationResult: RouteValidationResultFactory) => { - const decoded = schema.safeParse(inputValue); - if (decoded.success) { - return validationResult.ok(decoded.data); - } else { - return validationResult.badRequest(stringifyZodError(decoded.error)); - } - }; diff --git a/x-pack/test/security_solution_api_integration/test_suites/lists_and_exception_lists/lists_items/trial_license_complete_tier/items/find_list_items.ts b/x-pack/test/security_solution_api_integration/test_suites/lists_and_exception_lists/lists_items/trial_license_complete_tier/items/find_list_items.ts index 0c8aa8aa50fa8..aed7d61acf7b2 100644 --- a/x-pack/test/security_solution_api_integration/test_suites/lists_and_exception_lists/lists_items/trial_license_complete_tier/items/find_list_items.ts +++ b/x-pack/test/security_solution_api_integration/test_suites/lists_and_exception_lists/lists_items/trial_license_complete_tier/items/find_list_items.ts @@ -5,27 +5,20 @@ * 2.0. */ -import expect from '@kbn/expect'; +import expect from 'expect'; import { LIST_URL, LIST_ITEM_URL } from '@kbn/securitysolution-list-constants'; import { LIST_ITEM_ID, LIST_ID } from '@kbn/lists-plugin/common/constants.mock'; -import { getListItemResponseMockWithoutAutoGeneratedValues } from '@kbn/lists-plugin/common/schemas/response/list_item_schema.mock'; import { getCreateMinimalListItemSchemaMock } from '@kbn/lists-plugin/common/schemas/request/create_list_item_schema.mock'; import { getCreateMinimalListSchemaMock } from '@kbn/lists-plugin/common/schemas/request/create_list_schema.mock'; -import { - createListsIndex, - deleteListsIndex, - removeListItemServerGeneratedProperties, -} from '../../../utils'; +import { createListsIndex, deleteListsIndex } from '../../../utils'; import { FtrProviderContext } from '../../../../../ftr_provider_context'; export default ({ getService }: FtrProviderContext): void => { const supertest = getService('supertest'); const log = getService('log'); - const config = getService('config'); - const ELASTICSEARCH_USERNAME = config.get('servers.kibana.username'); describe('@ess @serverless find_list_items', () => { describe('find list items', () => { @@ -44,9 +37,9 @@ export default ({ getService }: FtrProviderContext): void => { .send() .expect(400); - expect(body).to.eql({ + expect(body).toEqual({ error: 'Bad Request', - message: '[request query]: Invalid value "undefined" supplied to "list_id"', + message: '[request query]: list_id: Required', statusCode: 400, }); }); @@ -58,8 +51,8 @@ export default ({ getService }: FtrProviderContext): void => { .send() .expect(404); - expect(body).to.eql({ - message: 'list id: "some-list-item-id" does not exist', + expect(body).toEqual({ + message: expect.any(String), status_code: 404, }); }); @@ -77,7 +70,7 @@ export default ({ getService }: FtrProviderContext): void => { .send() .expect(200); - expect(body).to.eql({ + expect(body).toEqual({ cursor: 'WzBd', data: [], page: 1, @@ -87,17 +80,12 @@ export default ({ getService }: FtrProviderContext): void => { }); it('should return a single list item when a single list item is loaded from a find with defaults added', async () => { - await supertest - .post(LIST_URL) - .set('kbn-xsrf', 'true') - .send(getCreateMinimalListSchemaMock()) - .expect(200); + const listMock = getCreateMinimalListSchemaMock(); + const listItemMock = getCreateMinimalListItemSchemaMock(); - await supertest - .post(LIST_ITEM_URL) - .set('kbn-xsrf', 'true') - .send(getCreateMinimalListItemSchemaMock()) - .expect(200); + await supertest.post(LIST_URL).set('kbn-xsrf', 'true').send(listMock).expect(200); + + await supertest.post(LIST_ITEM_URL).set('kbn-xsrf', 'true').send(listItemMock).expect(200); const { body } = await supertest .get(`${LIST_ITEM_URL}/_find?list_id=${LIST_ID}`) @@ -105,11 +93,14 @@ export default ({ getService }: FtrProviderContext): void => { .send() .expect(200); - body.data = [removeListItemServerGeneratedProperties(body.data[0])]; - // cursor is a constant changing value so we have to delete it as well. - delete body.cursor; - expect(body).to.eql({ - data: [getListItemResponseMockWithoutAutoGeneratedValues(ELASTICSEARCH_USERNAME)], + expect(body).toMatchObject({ + data: [ + expect.objectContaining({ + list_id: listItemMock.list_id, + value: listItemMock.value, + type: listMock.type, + }), + ], page: 1, per_page: 20, total: 1, diff --git a/yarn.lock b/yarn.lock index 07416bc65a2e4..a886aef857d57 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5625,6 +5625,10 @@ version "0.0.0" uid "" +"@kbn/openapi-common@link:packages/kbn-openapi-common": + version "0.0.0" + uid "" + "@kbn/openapi-generator@link:packages/kbn-openapi-generator": version "0.0.0" uid "" @@ -6145,6 +6149,10 @@ version "0.0.0" uid "" +"@kbn/securitysolution-lists-common@link:packages/kbn-securitysolution-lists-common": + version "0.0.0" + uid "" + "@kbn/securitysolution-rules@link:packages/kbn-securitysolution-rules": version "0.0.0" uid ""