diff --git a/packages/kbn-cases-components/src/status/types.ts b/packages/kbn-cases-components/src/status/types.ts index 228867340d3c64..226b70f3d8aed8 100644 --- a/packages/kbn-cases-components/src/status/types.ts +++ b/packages/kbn-cases-components/src/status/types.ts @@ -6,6 +6,14 @@ * Side Public License, v 1. */ +/** + * This is being used by Cases in + * x-pack/plugins/cases/common/types/domain/case/v1.ts. + * Introducing a breaking change in this enum will + * force cases to create a version of the domain object + * which in turn will force cases to create a new version + * to most of the Cases APIs. + */ export enum CaseStatuses { open = 'open', 'in-progress' = 'in-progress', diff --git a/x-pack/plugins/cases/common/api/cases/assignee.test.ts b/x-pack/plugins/cases/common/api/cases/assignee.test.ts deleted file mode 100644 index 0b75e5b57bbddf..00000000000000 --- a/x-pack/plugins/cases/common/api/cases/assignee.test.ts +++ /dev/null @@ -1,41 +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 { CaseAssigneesRt } from './assignee'; - -describe('Assignee', () => { - describe('CaseAssigneesRt', () => { - const defaultRequest = [{ uid: '1' }, { uid: '2' }]; - - it('has expected attributes in request', () => { - const query = CaseAssigneesRt.decode(defaultRequest); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: defaultRequest, - }); - }); - - it('removes foo:bar attributes from request', () => { - const query = CaseAssigneesRt.decode([{ ...defaultRequest[0], foo: 'bar' }]); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: [defaultRequest[0]], - }); - }); - - it('removes foo:bar attributes from assignees', () => { - const query = CaseAssigneesRt.decode([{ uid: '1', foo: 'bar' }, { uid: '2' }]); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: [{ uid: '1' }, { uid: '2' }], - }); - }); - }); -}); diff --git a/x-pack/plugins/cases/common/api/cases/case.test.ts b/x-pack/plugins/cases/common/api/cases/case.test.ts deleted file mode 100644 index 893ee107087f80..00000000000000 --- a/x-pack/plugins/cases/common/api/cases/case.test.ts +++ /dev/null @@ -1,765 +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 { PathReporter } from 'io-ts/lib/PathReporter'; -import { ConnectorTypes } from '../../types/domain/connector/v1'; -import { - RelatedCaseInfoRt, - SettingsRt, - CaseSeverity, - CaseFullExternalServiceRt, - CasesFindRequestRt, - CasesByAlertIDRequestRt, - CasePatchRequestRt, - CasesPatchRequestRt, - CasePushRequestParamsRt, - ExternalServiceResponseRt, - AllReportersFindRequestRt, - CasesBulkGetRequestRt, - CasesBulkGetResponseRt, - CasePostRequestRt, - CaseAttributesRt, - CasesRt, - CasesFindResponseRt, - CaseResolveResponseRt, - CasesFindRequestSearchFieldsRt, - CasesFindRequestSortFieldsRt, -} from './case'; -import { CommentType } from './comment'; -import { CaseStatuses } from './status'; - -const basicCase = { - owner: 'cases', - closed_at: null, - closed_by: null, - id: 'basic-case-id', - comments: [ - { - comment: 'Solve this fast!', - type: CommentType.user, - id: 'basic-comment-id', - created_at: '2020-02-19T23:06:33.798Z', - created_by: { - full_name: 'Leslie Knope', - username: 'lknope', - email: 'leslie.knope@elastic.co', - }, - owner: 'cases', - pushed_at: null, - pushed_by: null, - updated_at: null, - updated_by: null, - version: 'WzQ3LDFc', - }, - ], - created_at: '2020-02-19T23:06:33.798Z', - created_by: { - full_name: 'Leslie Knope', - username: 'lknope', - email: 'leslie.knope@elastic.co', - }, - connector: { - id: 'none', - name: 'My Connector', - type: ConnectorTypes.none, - fields: null, - }, - description: 'Security banana Issue', - severity: CaseSeverity.LOW, - duration: null, - external_service: null, - status: CaseStatuses.open, - tags: ['coke', 'pepsi'], - title: 'Another horrible breach!!', - totalComment: 1, - totalAlerts: 0, - updated_at: '2020-02-20T15:02:57.995Z', - updated_by: { - full_name: 'Leslie Knope', - username: 'lknope', - email: 'leslie.knope@elastic.co', - }, - version: 'WzQ3LDFd', - settings: { - syncAlerts: true, - }, - // damaged_raccoon uid - assignees: [{ uid: 'u_J41Oh6L9ki-Vo2tOogS8WRTENzhHurGtRc87NgEAlkc_0' }], - category: null, -}; - -describe('Case', () => { - describe('RelatedCaseInfoRt', () => { - const defaultRequest = { - id: 'basic-case-id', - title: 'basic-case-title', - description: 'this is a simple description', - status: CaseStatuses.open, - createdAt: '2023-01-17T09:46:29.813Z', - totals: { - alerts: 5, - userComments: 2, - }, - }; - it('has expected attributes in request', () => { - const query = RelatedCaseInfoRt.decode(defaultRequest); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: defaultRequest, - }); - }); - - it('removes foo:bar attributes from request', () => { - const query = RelatedCaseInfoRt.decode({ ...defaultRequest, foo: 'bar' }); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: defaultRequest, - }); - }); - - it('removes foo:bar attributes from totals', () => { - const query = RelatedCaseInfoRt.decode({ - ...defaultRequest, - totals: { ...defaultRequest.totals, foo: 'bar' }, - }); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: defaultRequest, - }); - }); - }); - - describe('SettingsRt', () => { - it('has expected attributes in request', () => { - const query = SettingsRt.decode({ syncAlerts: true }); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: { syncAlerts: true }, - }); - }); - - it('removes foo:bar attributes from request', () => { - const query = SettingsRt.decode({ syncAlerts: false, foo: 'bar' }); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: { syncAlerts: false }, - }); - }); - }); - - describe('CaseFullExternalServiceRt', () => { - const defaultRequest = { - connector_id: 'servicenow-1', - connector_name: 'My SN connector', - external_id: 'external_id', - external_title: 'external title', - external_url: 'basicPush.com', - pushed_at: '2023-01-17T09:46:29.813Z', - pushed_by: { - full_name: 'Leslie Knope', - username: 'lknope', - email: 'leslie.knope@elastic.co', - }, - }; - it('has expected attributes in request', () => { - const query = CaseFullExternalServiceRt.decode(defaultRequest); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: defaultRequest, - }); - }); - - it('removes foo:bar attributes from request', () => { - const query = CaseFullExternalServiceRt.decode({ ...defaultRequest, foo: 'bar' }); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: defaultRequest, - }); - }); - - it('removes foo:bar attributes from pushed_by', () => { - const query = CaseFullExternalServiceRt.decode({ - ...defaultRequest, - pushed_by: { ...defaultRequest.pushed_by, foo: 'bar' }, - }); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: defaultRequest, - }); - }); - }); - - describe('CaseAttributesRt', () => { - const defaultRequest = { - description: 'A description', - status: CaseStatuses.open, - tags: ['new', 'case'], - title: 'My new case', - connector: { - id: '123', - name: 'My connector', - type: ConnectorTypes.jira, - fields: { issueType: 'Task', priority: 'High', parent: null }, - }, - settings: { - syncAlerts: true, - }, - owner: 'cases', - severity: CaseSeverity.LOW, - assignees: [{ uid: 'u_J41Oh6L9ki-Vo2tOogS8WRTENzhHurGtRc87NgEAlkc_0' }], - duration: null, - closed_at: null, - closed_by: null, - created_at: '2020-02-19T23:06:33.798Z', - created_by: { - full_name: 'Leslie Knope', - username: 'lknope', - email: 'leslie.knope@elastic.co', - }, - external_service: null, - updated_at: '2020-02-20T15:02:57.995Z', - updated_by: null, - category: null, - }; - - it('has expected attributes in request', () => { - const query = CaseAttributesRt.decode(defaultRequest); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: defaultRequest, - }); - }); - - it('removes foo:bar attributes from request', () => { - const query = CaseAttributesRt.decode({ ...defaultRequest, foo: 'bar' }); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: defaultRequest, - }); - }); - - it('removes foo:bar attributes from connector', () => { - const query = CaseAttributesRt.decode({ - ...defaultRequest, - connector: { ...defaultRequest.connector, foo: 'bar' }, - }); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: defaultRequest, - }); - }); - - it('removes foo:bar attributes from created_by', () => { - const query = CaseAttributesRt.decode({ - ...defaultRequest, - created_by: { ...defaultRequest.created_by, foo: 'bar' }, - }); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: defaultRequest, - }); - }); - }); - - describe('CasePostRequestRt', () => { - const defaultRequest = { - description: 'A description', - tags: ['new', 'case'], - title: 'My new case', - connector: { - id: '123', - name: 'My connector', - type: ConnectorTypes.jira, - fields: { issueType: 'Task', priority: 'High', parent: null }, - }, - settings: { - syncAlerts: true, - }, - owner: 'cases', - severity: CaseSeverity.LOW, - assignees: [{ uid: 'u_J41Oh6L9ki-Vo2tOogS8WRTENzhHurGtRc87NgEAlkc_0' }], - }; - - it('has expected attributes in request', () => { - const query = CasePostRequestRt.decode(defaultRequest); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: defaultRequest, - }); - }); - - it('removes foo:bar attributes from request', () => { - const query = CasePostRequestRt.decode({ ...defaultRequest, foo: 'bar' }); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: defaultRequest, - }); - }); - - it('removes foo:bar attributes from connector', () => { - const query = CasePostRequestRt.decode({ - ...defaultRequest, - connector: { ...defaultRequest.connector, foo: 'bar' }, - }); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: defaultRequest, - }); - }); - }); - - describe('CasesFindRequestRt', () => { - const defaultRequest = { - tags: ['new', 'case'], - status: CaseStatuses.open, - severity: CaseSeverity.LOW, - assignees: ['damaged_racoon'], - reporters: ['damaged_racoon'], - defaultSearchOperator: 'AND', - from: 'now', - page: '1', - perPage: '10', - search: 'search text', - searchFields: ['title', 'description'], - to: '1w', - sortOrder: 'desc', - sortField: 'createdAt', - owner: 'cases', - }; - - it('has expected attributes in request', () => { - const query = CasesFindRequestRt.decode(defaultRequest); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: { ...defaultRequest, page: 1, perPage: 10 }, - }); - }); - - it('removes foo:bar attributes from request', () => { - const query = CasesFindRequestRt.decode({ ...defaultRequest, foo: 'bar' }); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: { ...defaultRequest, page: 1, perPage: 10 }, - }); - }); - - const searchFields = Object.keys(CasesFindRequestSearchFieldsRt.keys); - - it.each(searchFields)('succeeds with %s as searchFields', (field) => { - const query = CasesFindRequestRt.decode({ ...defaultRequest, searchFields: field }); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: { ...defaultRequest, searchFields: field, page: 1, perPage: 10 }, - }); - }); - - const sortFields = Object.keys(CasesFindRequestSortFieldsRt.keys); - - it.each(sortFields)('succeeds with %s as sortField', (sortField) => { - const query = CasesFindRequestRt.decode({ ...defaultRequest, sortField }); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: { ...defaultRequest, sortField, page: 1, perPage: 10 }, - }); - }); - - it('removes rootSearchField when passed', () => { - expect( - PathReporter.report( - CasesFindRequestRt.decode({ ...defaultRequest, rootSearchField: ['foobar'] }) - ) - ).toContain('No errors!'); - }); - - describe('errors', () => { - it('throws error when invalid searchField passed', () => { - expect( - PathReporter.report( - CasesFindRequestRt.decode({ ...defaultRequest, searchFields: 'foobar' }) - ) - ).not.toContain('No errors!'); - }); - - it('throws error when invalid sortField passed', () => { - expect( - PathReporter.report(CasesFindRequestRt.decode({ ...defaultRequest, sortField: 'foobar' })) - ).not.toContain('No errors!'); - }); - - it('succeeds when valid parameters passed', () => { - expect(PathReporter.report(CasesFindRequestRt.decode(defaultRequest))).toContain( - 'No errors!' - ); - }); - }); - }); - - describe('CasesByAlertIDRequestRt', () => { - it('has expected attributes in request', () => { - const query = CasesByAlertIDRequestRt.decode({ owner: 'cases' }); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: { owner: 'cases' }, - }); - }); - - it('removes foo:bar attributes from request', () => { - const query = CasesByAlertIDRequestRt.decode({ owner: ['cases'], foo: 'bar' }); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: { owner: ['cases'] }, - }); - }); - }); - - describe('CaseResolveResponseRt', () => { - const defaultRequest = { - case: { ...basicCase }, - outcome: 'exactMatch', - alias_target_id: 'sample-target-id', - alias_purpose: 'savedObjectConversion', - }; - - it('has expected attributes in request', () => { - const query = CaseResolveResponseRt.decode(defaultRequest); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: defaultRequest, - }); - }); - - it('removes foo:bar attributes from request', () => { - const query = CaseResolveResponseRt.decode({ ...defaultRequest, foo: 'bar' }); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: defaultRequest, - }); - }); - }); - - describe('CasesFindResponseRt', () => { - const defaultRequest = { - cases: [{ ...basicCase }], - page: 1, - per_page: 10, - total: 20, - count_open_cases: 10, - count_in_progress_cases: 5, - count_closed_cases: 5, - }; - - it('has expected attributes in request', () => { - const query = CasesFindResponseRt.decode(defaultRequest); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: defaultRequest, - }); - }); - - it('removes foo:bar attributes from request', () => { - const query = CasesFindResponseRt.decode({ ...defaultRequest, foo: 'bar' }); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: defaultRequest, - }); - }); - - it('removes foo:bar attributes from cases', () => { - const query = CasesFindResponseRt.decode({ - ...defaultRequest, - cases: [{ ...basicCase, foo: 'bar' }], - }); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: defaultRequest, - }); - }); - }); - - describe('CasePatchRequestRt', () => { - const defaultRequest = { - id: 'basic-case-id', - version: 'WzQ3LDFd', - description: 'Updated description', - }; - - it('has expected attributes in request', () => { - const query = CasePatchRequestRt.decode(defaultRequest); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: defaultRequest, - }); - }); - - it('removes foo:bar attributes from request', () => { - const query = CasePatchRequestRt.decode({ ...defaultRequest, foo: 'bar' }); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: defaultRequest, - }); - }); - }); - - describe('CasesPatchRequestRt', () => { - const defaultRequest = { - cases: [ - { - id: 'basic-case-id', - version: 'WzQ3LDFd', - description: 'Updated description', - }, - ], - }; - - it('has expected attributes in request', () => { - const query = CasesPatchRequestRt.decode(defaultRequest); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: defaultRequest, - }); - }); - - it('removes foo:bar attributes from request', () => { - const query = CasesPatchRequestRt.decode({ ...defaultRequest, foo: 'bar' }); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: defaultRequest, - }); - }); - }); - - describe('CasesRt', () => { - const defaultRequest = [ - { - ...basicCase, - }, - ]; - - it('has expected attributes in request', () => { - const query = CasesRt.decode(defaultRequest); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: defaultRequest, - }); - }); - - it('removes foo:bar attributes from request', () => { - const query = CasesRt.decode([{ ...defaultRequest[0], foo: 'bar' }]); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: defaultRequest, - }); - }); - }); - - describe('CasePushRequestParamsRt', () => { - const defaultRequest = { - case_id: 'basic-case-id', - connector_id: 'basic-connector-id', - }; - - it('has expected attributes in request', () => { - const query = CasePushRequestParamsRt.decode(defaultRequest); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: defaultRequest, - }); - }); - - it('removes foo:bar attributes from request', () => { - const query = CasePushRequestParamsRt.decode({ ...defaultRequest, foo: 'bar' }); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: defaultRequest, - }); - }); - }); - - describe('ExternalServiceResponseRt', () => { - const defaultRequest = { - title: 'case_title', - id: 'basic-case-id', - pushedDate: '2020-02-19T23:06:33.798Z', - url: 'https://atlassian.com', - comments: [ - { - commentId: 'basic-comment-id', - pushedDate: '2020-02-19T23:06:33.798Z', - externalCommentId: 'external-comment-id', - }, - ], - }; - - it('has expected attributes in request', () => { - const query = ExternalServiceResponseRt.decode(defaultRequest); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: defaultRequest, - }); - }); - - it('removes foo:bar attributes from request', () => { - const query = ExternalServiceResponseRt.decode({ ...defaultRequest, foo: 'bar' }); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: defaultRequest, - }); - }); - - it('removes foo:bar attributes from comments', () => { - const query = ExternalServiceResponseRt.decode({ - ...defaultRequest, - comments: [{ ...defaultRequest.comments[0], foo: 'bar' }], - }); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: defaultRequest, - }); - }); - }); - - describe('AllReportersFindRequestRt', () => { - const defaultRequest = { - owner: ['cases', 'security-solution'], - }; - - it('has expected attributes in request', () => { - const query = AllReportersFindRequestRt.decode(defaultRequest); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: defaultRequest, - }); - }); - - it('removes foo:bar attributes from request', () => { - const query = AllReportersFindRequestRt.decode({ ...defaultRequest, foo: 'bar' }); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: defaultRequest, - }); - }); - }); - - describe('CasesBulkGetRequestRt', () => { - const defaultRequest = { - ids: ['case-1', 'case-2'], - }; - - it('has expected attributes in request', () => { - const query = CasesBulkGetRequestRt.decode(defaultRequest); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: defaultRequest, - }); - }); - - it('removes foo:bar attributes from request', () => { - const query = CasesBulkGetRequestRt.decode({ ...defaultRequest, foo: 'bar' }); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: defaultRequest, - }); - }); - }); - - describe('CasesBulkGetResponseRt', () => { - const defaultRequest = { - cases: [basicCase], - errors: [ - { - error: 'error', - message: 'error-message', - status: 403, - caseId: 'basic-case-id', - }, - ], - }; - - it('has expected attributes in request', () => { - const query = CasesBulkGetResponseRt.decode(defaultRequest); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: defaultRequest, - }); - }); - - it('removes foo:bar attributes from request', () => { - const query = CasesBulkGetResponseRt.decode({ ...defaultRequest, foo: 'bar' }); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: defaultRequest, - }); - }); - - it('removes foo:bar attributes from cases', () => { - const query = CasesBulkGetResponseRt.decode({ - ...defaultRequest, - cases: [{ ...defaultRequest.cases[0], foo: 'bar' }], - }); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: { ...defaultRequest, cases: defaultRequest.cases }, - }); - }); - - it('removes foo:bar attributes from errors', () => { - const query = CasesBulkGetResponseRt.decode({ - ...defaultRequest, - errors: [{ ...defaultRequest.errors[0], foo: 'bar' }], - }); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: defaultRequest, - }); - }); - }); -}); diff --git a/x-pack/plugins/cases/common/api/cases/comment/files.test.ts b/x-pack/plugins/cases/common/api/cases/comment/files.test.ts deleted file mode 100644 index e30496cf5cb429..00000000000000 --- a/x-pack/plugins/cases/common/api/cases/comment/files.test.ts +++ /dev/null @@ -1,98 +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 { - SingleFileAttachmentMetadataRt, - FileAttachmentMetadataRt, - BulkDeleteFileAttachmentsRequestRt, -} from './files'; - -describe('Files', () => { - describe('SingleFileAttachmentMetadataRt', () => { - const defaultRequest = { - created: '2020-02-19T23:06:33.798Z', - extension: 'png', - mimeType: 'image/png', - name: 'my-super-cool-screenshot', - }; - - it('has expected attributes in request', () => { - const query = SingleFileAttachmentMetadataRt.decode(defaultRequest); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: defaultRequest, - }); - }); - - it('removes foo:bar attributes from request', () => { - const query = SingleFileAttachmentMetadataRt.decode({ ...defaultRequest, foo: 'bar' }); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: defaultRequest, - }); - }); - }); - describe('FileAttachmentMetadataRt', () => { - const defaultRequest = { - created: '2020-02-19T23:06:33.798Z', - extension: 'png', - mimeType: 'image/png', - name: 'my-super-cool-screenshot', - }; - - it('has expected attributes in request', () => { - const query = FileAttachmentMetadataRt.decode({ files: [defaultRequest] }); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: { - files: [ - { - ...defaultRequest, - }, - ], - }, - }); - }); - - it('removes foo:bar attributes from request', () => { - const query = FileAttachmentMetadataRt.decode({ files: [{ ...defaultRequest, foo: 'bar' }] }); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: { - files: [ - { - ...defaultRequest, - }, - ], - }, - }); - }); - }); - describe('BulkDeleteFileAttachmentsRequestRt', () => { - it('has expected attributes in request', () => { - const query = BulkDeleteFileAttachmentsRequestRt.decode({ ids: ['abc', 'xyz'] }); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: { ids: ['abc', 'xyz'] }, - }); - }); - - it('removes foo:bar attributes from request', () => { - const query = BulkDeleteFileAttachmentsRequestRt.decode({ ids: ['abc', 'xyz'], foo: 'bar' }); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: { ids: ['abc', 'xyz'] }, - }); - }); - }); -}); diff --git a/x-pack/plugins/cases/common/api/cases/comment/files.ts b/x-pack/plugins/cases/common/api/cases/comment/files.ts deleted file mode 100644 index 38d70cdc455553..00000000000000 --- a/x-pack/plugins/cases/common/api/cases/comment/files.ts +++ /dev/null @@ -1,36 +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 * as rt from 'io-ts'; -import { MAX_DELETE_FILES } from '../../../constants'; -import { limitedArraySchema, NonEmptyString } from '../../../schema'; - -export const SingleFileAttachmentMetadataRt = rt.strict({ - name: rt.string, - extension: rt.string, - mimeType: rt.string, - created: rt.string, -}); - -export const FileAttachmentMetadataRt = rt.strict({ - files: rt.array(SingleFileAttachmentMetadataRt), -}); - -export type FileAttachmentMetadata = rt.TypeOf; - -const MIN_DELETE_IDS = 1; - -export const BulkDeleteFileAttachmentsRequestRt = rt.strict({ - ids: limitedArraySchema({ - codec: NonEmptyString, - min: MIN_DELETE_IDS, - max: MAX_DELETE_FILES, - fieldName: 'ids', - }), -}); - -export type BulkDeleteFileAttachmentsRequest = rt.TypeOf; diff --git a/x-pack/plugins/cases/common/api/cases/comment/index.test.ts b/x-pack/plugins/cases/common/api/cases/comment/index.test.ts deleted file mode 100644 index 23ea839c5d5401..00000000000000 --- a/x-pack/plugins/cases/common/api/cases/comment/index.test.ts +++ /dev/null @@ -1,962 +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 { PathReporter } from 'io-ts/lib/PathReporter'; - -import { - CommentAttributesBasicRt, - CommentType, - ContextTypeUserRt, - AlertCommentRequestRt, - ActionsCommentRequestRt, - ExternalReferenceStorageType, - ExternalReferenceRt, - PersistableStateAttachmentRt, - CommentRequestRt, - CommentRt, - CommentResponseTypeUserRt, - CommentResponseTypeAlertsRt, - CommentResponseTypeActionsRt, - CommentResponseTypeExternalReferenceRt, - CommentResponseTypePersistableStateRt, - CommentPatchRequestRt, - CommentPatchAttributesRt, - CommentsFindResponseRt, - FindCommentsQueryParamsRt, - BulkCreateCommentRequestRt, - BulkGetAttachmentsRequestRt, - BulkGetAttachmentsResponseRt, -} from '.'; -import { MAX_COMMENT_LENGTH, MAX_BULK_CREATE_ATTACHMENTS } from '../../../constants'; - -describe('Comments', () => { - describe('CommentAttributesBasicRt', () => { - const defaultRequest = { - created_at: '2019-11-25T22:32:30.608Z', - created_by: { - full_name: 'elastic', - email: 'testemail@elastic.co', - username: 'elastic', - }, - owner: 'cases', - updated_at: null, - updated_by: null, - pushed_at: null, - pushed_by: null, - }; - - it('has expected attributes in request', () => { - const query = CommentAttributesBasicRt.decode(defaultRequest); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: defaultRequest, - }); - }); - - it('removes foo:bar attributes from request', () => { - const query = CommentAttributesBasicRt.decode({ ...defaultRequest, foo: 'bar' }); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: defaultRequest, - }); - }); - }); - - describe('ContextTypeUserRt', () => { - const defaultRequest = { - comment: 'This is a sample comment', - type: CommentType.user, - owner: 'cases', - }; - - it('has expected attributes in request', () => { - const query = ContextTypeUserRt.decode(defaultRequest); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: defaultRequest, - }); - }); - - it('removes foo:bar attributes from request', () => { - const query = ContextTypeUserRt.decode({ ...defaultRequest, foo: 'bar' }); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: defaultRequest, - }); - }); - }); - - describe('AlertCommentRequestRt', () => { - const defaultRequest = { - alertId: 'alert-id-1', - index: 'alert-index-1', - type: CommentType.alert, - owner: 'cases', - rule: { - id: 'rule-id-1', - name: 'Awesome rule', - }, - }; - - it('has expected attributes in request', () => { - const query = AlertCommentRequestRt.decode(defaultRequest); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: defaultRequest, - }); - }); - - it('removes foo:bar attributes from request', () => { - const query = AlertCommentRequestRt.decode({ ...defaultRequest, foo: 'bar' }); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: defaultRequest, - }); - }); - - it('removes foo:bar attributes from rule', () => { - const query = AlertCommentRequestRt.decode({ - ...defaultRequest, - rule: { id: 'rule-id-1', name: 'Awesome rule', foo: 'bar' }, - }); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: defaultRequest, - }); - }); - }); - - describe('ActionsCommentRequestRt', () => { - const defaultRequest = { - type: CommentType.actions, - comment: 'I just isolated the host!', - actions: { - targets: [ - { - hostname: 'host1', - endpointId: '001', - }, - ], - type: 'isolate', - }, - owner: 'cases', - }; - - it('has expected attributes in request', () => { - const query = ActionsCommentRequestRt.decode(defaultRequest); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: defaultRequest, - }); - }); - - it('removes foo:bar attributes from request', () => { - const query = ActionsCommentRequestRt.decode({ ...defaultRequest, foo: 'bar' }); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: defaultRequest, - }); - }); - - it('removes foo:bar attributes from actions', () => { - const query = ActionsCommentRequestRt.decode({ - ...defaultRequest, - actions: { - targets: [ - { - hostname: 'host1', - endpointId: '001', - }, - ], - type: 'isolate', - foo: 'bar', - }, - }); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: defaultRequest, - }); - }); - - it('removes foo:bar attributes from targets', () => { - const query = ActionsCommentRequestRt.decode({ - ...defaultRequest, - actions: { - targets: [ - { - hostname: 'host1', - endpointId: '001', - foo: 'bar', - }, - ], - type: 'isolate', - }, - }); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: defaultRequest, - }); - }); - }); - - describe('ExternalReferenceRt', () => { - const defaultRequest = { - type: CommentType.externalReference, - externalReferenceId: 'my-id', - externalReferenceStorage: { type: ExternalReferenceStorageType.elasticSearchDoc }, - externalReferenceAttachmentTypeId: '.test', - externalReferenceMetadata: { test_foo: 'foo' }, - owner: 'cases', - }; - it('has expected attributes in request', () => { - const query = ExternalReferenceRt.decode(defaultRequest); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: defaultRequest, - }); - }); - - it('removes foo:bar attributes from request', () => { - const query = ExternalReferenceRt.decode({ ...defaultRequest, foo: 'bar' }); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: defaultRequest, - }); - }); - - it('removes foo:bar attributes from externalReferenceStorage', () => { - const query = ExternalReferenceRt.decode({ - ...defaultRequest, - externalReferenceStorage: { - type: ExternalReferenceStorageType.elasticSearchDoc, - foo: 'bar', - }, - }); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: defaultRequest, - }); - }); - - it('removes foo:bar attributes from externalReferenceStorage with soType', () => { - const query = ExternalReferenceRt.decode({ - ...defaultRequest, - externalReferenceStorage: { - type: ExternalReferenceStorageType.savedObject, - soType: 'awesome', - foo: 'bar', - }, - }); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: { - ...defaultRequest, - externalReferenceStorage: { - type: ExternalReferenceStorageType.savedObject, - soType: 'awesome', - }, - }, - }); - }); - }); - - describe('PersistableStateAttachmentRt', () => { - const defaultRequest = { - type: CommentType.persistableState, - persistableStateAttachmentState: { test_foo: 'foo' }, - persistableStateAttachmentTypeId: '.test', - owner: 'cases', - }; - it('has expected attributes in request', () => { - const query = PersistableStateAttachmentRt.decode(defaultRequest); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: defaultRequest, - }); - }); - - it('removes foo:bar attributes from request', () => { - const query = PersistableStateAttachmentRt.decode({ ...defaultRequest, foo: 'bar' }); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: defaultRequest, - }); - }); - - it('removes foo:bar attributes from persistableStateAttachmentState', () => { - const query = PersistableStateAttachmentRt.decode({ - ...defaultRequest, - persistableStateAttachmentState: { test_foo: 'foo', foo: 'bar' }, - }); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: { - ...defaultRequest, - persistableStateAttachmentState: { test_foo: 'foo', foo: 'bar' }, - }, - }); - }); - }); - - describe('CommentRequestRt', () => { - const defaultRequest = { - comment: 'Solve this fast!', - type: CommentType.user, - owner: 'cases', - }; - - it('has expected attributes in request', () => { - const query = CommentRequestRt.decode(defaultRequest); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: defaultRequest, - }); - }); - - it('removes foo:bar attributes from request', () => { - const query = CommentRequestRt.decode({ ...defaultRequest, foo: 'bar' }); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: defaultRequest, - }); - }); - - describe('errors', () => { - describe('commentType: user', () => { - it('throws error when comment is too long', () => { - const longComment = 'x'.repeat(MAX_COMMENT_LENGTH + 1); - - expect( - PathReporter.report( - CommentRequestRt.decode({ ...defaultRequest, comment: longComment }) - ) - ).toContain('The length of the comment is too long. The maximum length is 30000.'); - }); - - it('throws error when comment is empty', () => { - expect( - PathReporter.report(CommentRequestRt.decode({ ...defaultRequest, comment: '' })) - ).toContain('The comment field cannot be an empty string.'); - }); - - it('throws error when comment string of empty characters', () => { - expect( - PathReporter.report(CommentRequestRt.decode({ ...defaultRequest, comment: ' ' })) - ).toContain('The comment field cannot be an empty string.'); - }); - }); - - describe('commentType: action', () => { - const request = { - type: CommentType.actions, - actions: { - targets: [ - { - hostname: 'host1', - endpointId: '001', - }, - ], - type: 'isolate', - }, - owner: 'cases', - }; - - it('throws error when comment is too long', () => { - const longComment = 'x'.repeat(MAX_COMMENT_LENGTH + 1); - - expect( - PathReporter.report(CommentRequestRt.decode({ ...request, comment: longComment })) - ).toContain('The length of the comment is too long. The maximum length is 30000.'); - }); - - it('throws error when comment is empty', () => { - expect( - PathReporter.report(CommentRequestRt.decode({ ...request, comment: '' })) - ).toContain('The comment field cannot be an empty string.'); - }); - - it('throws error when comment string of empty characters', () => { - expect( - PathReporter.report(CommentRequestRt.decode({ ...request, comment: ' ' })) - ).toContain('The comment field cannot be an empty string.'); - }); - }); - }); - }); - - describe('CommentRt', () => { - const defaultRequest = { - comment: 'Solve this fast!', - type: CommentType.user, - owner: 'cases', - id: 'basic-comment-id', - version: 'WzQ3LDFc', - created_at: '2020-02-19T23:06:33.798Z', - created_by: { - full_name: 'Leslie Knope', - username: 'lknope', - email: 'leslie.knope@elastic.co', - }, - pushed_at: null, - pushed_by: null, - updated_at: null, - updated_by: null, - }; - it('has expected attributes in request', () => { - const query = CommentRt.decode(defaultRequest); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: defaultRequest, - }); - }); - - it('removes foo:bar attributes from request', () => { - const query = CommentRt.decode({ ...defaultRequest, foo: 'bar' }); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: defaultRequest, - }); - }); - }); - - describe('CommentResponseTypeUserRt', () => { - const defaultRequest = { - comment: 'Solve this fast!', - type: CommentType.user, - owner: 'cases', - id: 'basic-comment-id', - version: 'WzQ3LDFc', - created_at: '2020-02-19T23:06:33.798Z', - created_by: { - full_name: 'Leslie Knope', - username: 'lknope', - email: 'leslie.knope@elastic.co', - }, - pushed_at: null, - pushed_by: null, - updated_at: null, - updated_by: null, - }; - it('has expected attributes in request', () => { - const query = CommentResponseTypeUserRt.decode(defaultRequest); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: defaultRequest, - }); - }); - - it('removes foo:bar attributes from request', () => { - const query = CommentResponseTypeUserRt.decode({ ...defaultRequest, foo: 'bar' }); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: defaultRequest, - }); - }); - }); - - describe('CommentResponseTypeAlertsRt', () => { - const defaultRequest = { - alertId: 'alert-id-1', - index: 'alert-index-1', - type: CommentType.alert, - id: 'alert-comment-id', - owner: 'cases', - rule: { - id: 'rule-id-1', - name: 'Awesome rule', - }, - version: 'WzQ3LDFc', - created_at: '2020-02-19T23:06:33.798Z', - created_by: { - full_name: 'Leslie Knope', - username: 'lknope', - email: 'leslie.knope@elastic.co', - }, - pushed_at: null, - pushed_by: null, - updated_at: null, - updated_by: null, - }; - it('has expected attributes in request', () => { - const query = CommentResponseTypeAlertsRt.decode(defaultRequest); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: defaultRequest, - }); - }); - - it('removes foo:bar attributes from request', () => { - const query = CommentResponseTypeAlertsRt.decode({ ...defaultRequest, foo: 'bar' }); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: defaultRequest, - }); - }); - - it('removes foo:bar attributes from created_by', () => { - const query = CommentResponseTypeAlertsRt.decode({ - ...defaultRequest, - created_by: { - full_name: 'Leslie Knope', - username: 'lknope', - email: 'leslie.knope@elastic.co', - foo: 'bar', - }, - }); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: defaultRequest, - }); - }); - }); - - describe('CommentResponseTypeActionsRt', () => { - const defaultRequest = { - type: CommentType.actions, - comment: 'I just isolated the host!', - actions: { - targets: [ - { - hostname: 'host1', - endpointId: '001', - }, - ], - type: 'isolate', - }, - owner: 'cases', - id: 'basic-comment-id', - version: 'WzQ3LDFc', - created_at: '2020-02-19T23:06:33.798Z', - created_by: { - full_name: 'Leslie Knope', - username: 'lknope', - email: 'leslie.knope@elastic.co', - }, - pushed_at: null, - pushed_by: null, - updated_at: null, - updated_by: null, - }; - it('has expected attributes in request', () => { - const query = CommentResponseTypeActionsRt.decode(defaultRequest); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: defaultRequest, - }); - }); - - it('removes foo:bar attributes from request', () => { - const query = CommentResponseTypeActionsRt.decode({ ...defaultRequest, foo: 'bar' }); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: defaultRequest, - }); - }); - }); - - describe('CommentResponseTypeExternalReferenceRt', () => { - const defaultRequest = { - type: CommentType.externalReference, - externalReferenceId: 'my-id', - externalReferenceStorage: { type: ExternalReferenceStorageType.elasticSearchDoc }, - externalReferenceAttachmentTypeId: '.test', - externalReferenceMetadata: { test_foo: 'foo' }, - owner: 'cases', - id: 'basic-comment-id', - version: 'WzQ3LDFc', - created_at: '2020-02-19T23:06:33.798Z', - created_by: { - full_name: 'Leslie Knope', - username: 'lknope', - email: 'leslie.knope@elastic.co', - }, - pushed_at: null, - pushed_by: null, - updated_at: null, - updated_by: null, - }; - it('has expected attributes in request', () => { - const query = CommentResponseTypeExternalReferenceRt.decode(defaultRequest); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: defaultRequest, - }); - }); - - it('removes foo:bar attributes from request', () => { - const query = CommentResponseTypeExternalReferenceRt.decode({ - ...defaultRequest, - foo: 'bar', - }); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: defaultRequest, - }); - }); - }); - - describe('CommentResponseTypePersistableStateRt', () => { - const defaultRequest = { - type: CommentType.persistableState, - persistableStateAttachmentState: { test_foo: 'foo' }, - persistableStateAttachmentTypeId: '.test', - owner: 'cases', - id: 'basic-comment-id', - version: 'WzQ3LDFc', - created_at: '2020-02-19T23:06:33.798Z', - created_by: { - full_name: 'Leslie Knope', - username: 'lknope', - email: 'leslie.knope@elastic.co', - }, - pushed_at: null, - pushed_by: null, - updated_at: null, - updated_by: null, - }; - it('has expected attributes in request', () => { - const query = CommentResponseTypePersistableStateRt.decode(defaultRequest); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: defaultRequest, - }); - }); - - it('removes foo:bar attributes from request', () => { - const query = CommentResponseTypePersistableStateRt.decode({ ...defaultRequest, foo: 'bar' }); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: defaultRequest, - }); - }); - }); - - describe('CommentPatchRequestRt', () => { - const defaultRequest = { - alertId: 'alert-id-1', - index: 'alert-index-1', - type: CommentType.alert, - id: 'alert-comment-id', - owner: 'cases', - rule: { - id: 'rule-id-1', - name: 'Awesome rule', - }, - version: 'WzQ3LDFc', - }; - it('has expected attributes in request', () => { - const query = CommentPatchRequestRt.decode(defaultRequest); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: defaultRequest, - }); - }); - - it('removes foo:bar attributes from request', () => { - const query = CommentPatchRequestRt.decode({ ...defaultRequest, foo: 'bar' }); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: defaultRequest, - }); - }); - }); - - describe('CommentPatchAttributesRt', () => { - const defaultRequest = { - type: CommentType.actions, - actions: { - targets: [ - { - hostname: 'host1', - endpointId: '001', - }, - ], - type: 'isolate', - }, - owner: 'cases', - }; - it('has expected attributes in request', () => { - const query = CommentPatchAttributesRt.decode(defaultRequest); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: defaultRequest, - }); - }); - - it('removes foo:bar attributes from request', () => { - const query = CommentPatchAttributesRt.decode({ ...defaultRequest, foo: 'bar' }); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: defaultRequest, - }); - }); - }); - - describe('CommentsFindResponseRt', () => { - const defaultRequest = { - comments: [ - { - comment: 'Solve this fast!', - type: CommentType.user, - owner: 'cases', - created_at: '2020-02-19T23:06:33.798Z', - created_by: { - full_name: 'Leslie Knope', - username: 'lknope', - email: 'leslie.knope@elastic.co', - }, - pushed_at: null, - pushed_by: null, - updated_at: null, - updated_by: null, - id: 'basic-comment-id', - version: 'WzQ3LDFc', - }, - ], - page: 1, - per_page: 10, - total: 1, - }; - it('has expected attributes in request', () => { - const query = CommentsFindResponseRt.decode(defaultRequest); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: defaultRequest, - }); - }); - - it('removes foo:bar attributes from request', () => { - const query = CommentsFindResponseRt.decode({ ...defaultRequest, foo: 'bar' }); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: defaultRequest, - }); - }); - - it('removes foo:bar attributes from comments', () => { - const query = CommentsFindResponseRt.decode({ - ...defaultRequest, - comments: [{ ...defaultRequest.comments[0], foo: 'bar' }], - }); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: defaultRequest, - }); - }); - }); - - describe('FindCommentsQueryParamsRt', () => { - const defaultRequest = { - page: 1, - perPage: 10, - sortOrder: 'asc', - }; - - it('has expected attributes in request', () => { - const query = FindCommentsQueryParamsRt.decode(defaultRequest); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: defaultRequest, - }); - }); - - it('removes foo:bar attributes from request', () => { - const query = FindCommentsQueryParamsRt.decode({ ...defaultRequest, foo: 'bar' }); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: defaultRequest, - }); - }); - }); - - describe('BulkCreateCommentRequestRt', () => { - const defaultRequest = [ - { - comment: 'Solve this fast!', - type: CommentType.user, - owner: 'cases', - }, - ]; - - it('has expected attributes in request', () => { - const query = BulkCreateCommentRequestRt.decode(defaultRequest); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: defaultRequest, - }); - }); - - it('removes foo:bar attributes from request', () => { - const query = BulkCreateCommentRequestRt.decode([ - { comment: 'Solve this fast!', type: CommentType.user, owner: 'cases', foo: 'bar' }, - ]); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: defaultRequest, - }); - }); - - describe('errors', () => { - it(`throws error when attachments are more than ${MAX_BULK_CREATE_ATTACHMENTS}`, () => { - const comment = { - comment: 'Solve this fast!', - type: CommentType.user, - owner: 'cases', - }; - const attachments = Array(MAX_BULK_CREATE_ATTACHMENTS + 1).fill(comment); - - expect(PathReporter.report(BulkCreateCommentRequestRt.decode(attachments))).toContain( - `The length of the field attachments is too long. Array must be of length <= ${MAX_BULK_CREATE_ATTACHMENTS}.` - ); - }); - - it(`no errors when empty array of attachments`, () => { - expect(PathReporter.report(BulkCreateCommentRequestRt.decode([]))).toStrictEqual([ - 'No errors!', - ]); - }); - }); - }); - - describe('BulkGetAttachmentsRequestRt', () => { - it('has expected attributes in request', () => { - const query = BulkGetAttachmentsRequestRt.decode({ ids: ['abc', 'xyz'] }); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: { ids: ['abc', 'xyz'] }, - }); - }); - - it('removes foo:bar attributes from request', () => { - const query = BulkGetAttachmentsRequestRt.decode({ ids: ['abc', 'xyz'], foo: 'bar' }); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: { ids: ['abc', 'xyz'] }, - }); - }); - }); - - describe('BulkGetAttachmentsResponseRt', () => { - const defaultRequest = { - attachments: [ - { - comment: 'Solve this fast!', - type: CommentType.user, - owner: 'cases', - id: 'basic-comment-id', - version: 'WzQ3LDFc', - created_at: '2020-02-19T23:06:33.798Z', - created_by: { - full_name: 'Leslie Knope', - username: 'lknope', - email: 'leslie.knope@elastic.co', - }, - pushed_at: null, - pushed_by: null, - updated_at: null, - updated_by: null, - }, - ], - errors: [ - { - error: 'error', - message: 'not found', - status: 404, - attachmentId: 'abc', - }, - ], - }; - - it('has expected attributes in request', () => { - const query = BulkGetAttachmentsResponseRt.decode(defaultRequest); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: defaultRequest, - }); - }); - - it('removes foo:bar attributes from request', () => { - const query = BulkGetAttachmentsResponseRt.decode({ ...defaultRequest, foo: 'bar' }); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: defaultRequest, - }); - }); - - it('removes foo:bar attributes from attachments', () => { - const query = BulkGetAttachmentsResponseRt.decode({ - ...defaultRequest, - attachments: [{ ...defaultRequest.attachments[0], foo: 'bar' }], - }); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: defaultRequest, - }); - }); - - it('removes foo:bar attributes from errors', () => { - const query = BulkGetAttachmentsResponseRt.decode({ - ...defaultRequest, - errors: [{ ...defaultRequest.errors[0], foo: 'bar' }], - }); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: defaultRequest, - }); - }); - }); -}); diff --git a/x-pack/plugins/cases/common/api/cases/comment/index.ts b/x-pack/plugins/cases/common/api/cases/comment/index.ts deleted file mode 100644 index f23d0f82377be9..00000000000000 --- a/x-pack/plugins/cases/common/api/cases/comment/index.ts +++ /dev/null @@ -1,400 +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 * as rt from 'io-ts'; -import { - MAX_BULK_GET_ATTACHMENTS, - MAX_COMMENTS_PER_PAGE, - MAX_COMMENT_LENGTH, - MAX_BULK_CREATE_ATTACHMENTS, -} from '../../../constants'; -import { limitedArraySchema, paginationSchema, limitedStringSchema } from '../../../schema'; -import { jsonValueRt } from '../../runtime_types'; - -import { UserRt } from '../../user'; - -export * from './files'; - -export const CommentAttributesBasicRt = rt.strict({ - created_at: rt.string, - created_by: UserRt, - owner: rt.string, - pushed_at: rt.union([rt.string, rt.null]), - pushed_by: rt.union([UserRt, rt.null]), - updated_at: rt.union([rt.string, rt.null]), - updated_by: rt.union([UserRt, rt.null]), -}); - -export enum CommentType { - user = 'user', - alert = 'alert', - actions = 'actions', - externalReference = 'externalReference', - persistableState = 'persistableState', -} - -export enum IsolateHostActionType { - isolate = 'isolate', - unisolate = 'unisolate', -} - -export const ContextTypeUserRt = rt.strict({ - comment: rt.string, - type: rt.literal(CommentType.user), - owner: rt.string, -}); - -/** - * This defines the structure of how alerts (generated or user attached) are stored in saved objects documents. It also - * represents of an alert after it has been transformed. A generated alert will be transformed by the connector so that - * it matches this structure. User attached alerts do not need to be transformed. - */ -export const AlertCommentRequestRt = rt.strict({ - type: rt.literal(CommentType.alert), - alertId: rt.union([rt.array(rt.string), rt.string]), - index: rt.union([rt.array(rt.string), rt.string]), - rule: rt.strict({ - id: rt.union([rt.string, rt.null]), - name: rt.union([rt.string, rt.null]), - }), - owner: rt.string, -}); - -export const ActionsCommentRequestRt = rt.strict({ - type: rt.literal(CommentType.actions), - comment: rt.string, - actions: rt.strict({ - targets: rt.array( - rt.strict({ - hostname: rt.string, - endpointId: rt.string, - }) - ), - type: rt.string, - }), - owner: rt.string, -}); - -export enum ExternalReferenceStorageType { - savedObject = 'savedObject', - elasticSearchDoc = 'elasticSearchDoc', -} - -const ExternalReferenceStorageNoSORt = rt.strict({ - type: rt.literal(ExternalReferenceStorageType.elasticSearchDoc), -}); - -const ExternalReferenceStorageSORt = rt.strict({ - type: rt.literal(ExternalReferenceStorageType.savedObject), - soType: rt.string, -}); - -export const ExternalReferenceBaseRt = rt.strict({ - externalReferenceAttachmentTypeId: rt.string, - externalReferenceMetadata: rt.union([rt.null, rt.record(rt.string, jsonValueRt)]), - type: rt.literal(CommentType.externalReference), - owner: rt.string, -}); - -export const ExternalReferenceNoSORt = rt.strict({ - ...ExternalReferenceBaseRt.type.props, - externalReferenceId: rt.string, - externalReferenceStorage: ExternalReferenceStorageNoSORt, -}); - -export const ExternalReferenceSORt = rt.strict({ - ...ExternalReferenceBaseRt.type.props, - externalReferenceId: rt.string, - externalReferenceStorage: ExternalReferenceStorageSORt, -}); - -// externalReferenceId is missing. -export const ExternalReferenceSOWithoutRefsRt = rt.strict({ - ...ExternalReferenceBaseRt.type.props, - externalReferenceStorage: ExternalReferenceStorageSORt, -}); - -export const ExternalReferenceRt = rt.union([ExternalReferenceNoSORt, ExternalReferenceSORt]); -export const ExternalReferenceWithoutRefsRt = rt.union([ - ExternalReferenceNoSORt, - ExternalReferenceSOWithoutRefsRt, -]); - -export const PersistableStateAttachmentRt = rt.strict({ - type: rt.literal(CommentType.persistableState), - owner: rt.string, - persistableStateAttachmentTypeId: rt.string, - persistableStateAttachmentState: rt.record(rt.string, jsonValueRt), -}); - -const AttributesTypeUserRt = rt.intersection([ContextTypeUserRt, CommentAttributesBasicRt]); -export const AttributesTypeAlertsRt = rt.intersection([ - AlertCommentRequestRt, - CommentAttributesBasicRt, -]); -const AttributesTypeActionsRt = rt.intersection([ - ActionsCommentRequestRt, - CommentAttributesBasicRt, -]); - -const AttributesTypeExternalReferenceRt = rt.intersection([ - ExternalReferenceRt, - CommentAttributesBasicRt, -]); - -const AttributesTypeExternalReferenceWithoutRefsRt = rt.intersection([ - ExternalReferenceWithoutRefsRt, - CommentAttributesBasicRt, -]); - -const AttributesTypeExternalReferenceNoSORt = rt.intersection([ - ExternalReferenceNoSORt, - CommentAttributesBasicRt, -]); - -const AttributesTypeExternalReferenceSORt = rt.intersection([ - ExternalReferenceSORt, - CommentAttributesBasicRt, -]); - -const AttributesTypePersistableStateRt = rt.intersection([ - PersistableStateAttachmentRt, - CommentAttributesBasicRt, -]); - -export const CommentAttributesRt = rt.union([ - AttributesTypeUserRt, - AttributesTypeAlertsRt, - AttributesTypeActionsRt, - AttributesTypeExternalReferenceRt, - AttributesTypePersistableStateRt, -]); - -const CommentAttributesNoSORt = rt.union([ - AttributesTypeUserRt, - AttributesTypeAlertsRt, - AttributesTypeActionsRt, - AttributesTypeExternalReferenceNoSORt, - AttributesTypePersistableStateRt, -]); - -const CommentAttributesWithoutRefsRt = rt.union([ - AttributesTypeUserRt, - AttributesTypeAlertsRt, - AttributesTypeActionsRt, - AttributesTypeExternalReferenceWithoutRefsRt, - AttributesTypePersistableStateRt, -]); - -const BasicCommentRequestRt = rt.union([ - ContextTypeUserRt, - AlertCommentRequestRt, - ActionsCommentRequestRt, - ExternalReferenceNoSORt, - PersistableStateAttachmentRt, -]); - -export const CommentRequestRt = rt.union([ - rt.strict({ - comment: limitedStringSchema({ fieldName: 'comment', min: 1, max: MAX_COMMENT_LENGTH }), - type: rt.literal(CommentType.user), - owner: rt.string, - }), - AlertCommentRequestRt, - rt.strict({ - type: rt.literal(CommentType.actions), - comment: limitedStringSchema({ fieldName: 'comment', min: 1, max: MAX_COMMENT_LENGTH }), - actions: rt.strict({ - targets: rt.array( - rt.strict({ - hostname: rt.string, - endpointId: rt.string, - }) - ), - type: rt.string, - }), - owner: rt.string, - }), - ExternalReferenceNoSORt, - ExternalReferenceSORt, - PersistableStateAttachmentRt, -]); - -export const CommentRequestWithoutRefsRt = rt.union([ - BasicCommentRequestRt, - ExternalReferenceSOWithoutRefsRt, -]); - -export const CommentRt = rt.intersection([ - CommentAttributesRt, - rt.strict({ - id: rt.string, - version: rt.string, - }), -]); - -export const CommentResponseTypeUserRt = rt.intersection([ - AttributesTypeUserRt, - rt.strict({ - id: rt.string, - version: rt.string, - }), -]); - -export const CommentResponseTypeAlertsRt = rt.intersection([ - AttributesTypeAlertsRt, - rt.strict({ - id: rt.string, - version: rt.string, - }), -]); - -export const CommentResponseTypeActionsRt = rt.intersection([ - AttributesTypeActionsRt, - rt.strict({ - id: rt.string, - version: rt.string, - }), -]); - -export const CommentResponseTypeExternalReferenceRt = rt.intersection([ - AttributesTypeExternalReferenceRt, - rt.strict({ - id: rt.string, - version: rt.string, - }), -]); - -export const CommentResponseTypePersistableStateRt = rt.intersection([ - AttributesTypePersistableStateRt, - rt.strict({ - id: rt.string, - version: rt.string, - }), -]); - -export const CommentPatchRequestRt = rt.intersection([ - /** - * Partial updates are not allowed. - * We want to prevent the user for changing the type without removing invalid fields. - * - * injectAttachmentSOAttributesFromRefsForPatch is dependent on this assumption. - * The consumers of the persistable attachment service should always get the - * persistableStateAttachmentState on a patch. - */ - CommentRequestRt, - rt.strict({ id: rt.string, version: rt.string }), -]); - -/** - * This type is used by the CaseService. - * Because the type for the attributes of savedObjectClient update function is Partial - * we need to make all of our attributes partial too. - * We ensure that partial updates of CommentContext is not going to happen inside the patch comment route. - */ -export const CommentPatchAttributesRt = rt.intersection([ - rt.union([ - rt.exact(rt.partial(ContextTypeUserRt.type.props)), - rt.exact(rt.partial(AlertCommentRequestRt.type.props)), - rt.exact(rt.partial(ActionsCommentRequestRt.type.props)), - rt.exact(rt.partial(ExternalReferenceNoSORt.type.props)), - rt.exact(rt.partial(ExternalReferenceSORt.type.props)), - rt.exact(rt.partial(PersistableStateAttachmentRt.type.props)), - ]), - rt.exact(rt.partial(CommentAttributesBasicRt.type.props)), -]); - -export const CommentsFindResponseRt = rt.strict({ - comments: rt.array(CommentRt), - page: rt.number, - per_page: rt.number, - total: rt.number, -}); - -export const CommentsRt = rt.array(CommentRt); - -export const FindCommentsQueryParamsRt = rt.intersection([ - rt.exact( - rt.partial({ - /** - * Order to sort the response - */ - sortOrder: rt.union([rt.literal('desc'), rt.literal('asc')]), - }) - ), - paginationSchema({ maxPerPage: MAX_COMMENTS_PER_PAGE }), -]); - -export const BulkCreateCommentRequestRt = limitedArraySchema({ - codec: CommentRequestRt, - min: 0, - max: MAX_BULK_CREATE_ATTACHMENTS, - fieldName: 'attachments', -}); - -export const BulkGetAttachmentsRequestRt = rt.strict({ - ids: limitedArraySchema({ - codec: rt.string, - min: 1, - max: MAX_BULK_GET_ATTACHMENTS, - fieldName: 'ids', - }), -}); - -export const BulkGetAttachmentsResponseRt = rt.strict({ - attachments: CommentsRt, - errors: rt.array( - rt.strict({ - error: rt.string, - message: rt.string, - status: rt.union([rt.undefined, rt.number]), - attachmentId: rt.string, - }) - ), -}); - -export type FindCommentsQueryParams = rt.TypeOf; -export type AttributesTypeActions = rt.TypeOf; -export type AttributesTypeAlerts = rt.TypeOf; -export type AttributesTypeUser = rt.TypeOf; -export type AttributesTypeExternalReference = rt.TypeOf; -export type AttributesTypeExternalReferenceSO = rt.TypeOf< - typeof AttributesTypeExternalReferenceSORt ->; -export type AttributesTypeExternalReferenceNoSO = rt.TypeOf< - typeof AttributesTypeExternalReferenceNoSORt ->; -export type ExternalReferenceWithoutRefs = rt.TypeOf; -export type AttributesTypePersistableState = rt.TypeOf; -export type CommentAttributes = rt.TypeOf; -export type CommentAttributesNoSO = rt.TypeOf; -export type CommentAttributesWithoutRefs = rt.TypeOf; -export type CommentRequest = rt.TypeOf; -export type BulkCreateCommentRequest = rt.TypeOf; -export type Comment = rt.TypeOf; -export type CommentResponseUserType = rt.TypeOf; -export type CommentResponseAlertsType = rt.TypeOf; -export type CommentResponseTypePersistableState = rt.TypeOf< - typeof CommentResponseTypePersistableStateRt ->; -export type CommentResponseExternalReferenceType = rt.TypeOf< - typeof CommentResponseTypeExternalReferenceRt ->; -export type CommentResponseActionsType = rt.TypeOf; -export type Comments = rt.TypeOf; -export type CommentsFindResponse = rt.TypeOf; -export type CommentPatchRequest = rt.TypeOf; -export type CommentPatchAttributes = rt.TypeOf; -export type CommentRequestUserType = rt.TypeOf; -export type CommentRequestAlertType = rt.TypeOf; -export type CommentRequestActionsType = rt.TypeOf; -export type CommentRequestExternalReferenceType = rt.TypeOf; -export type CommentRequestExternalReferenceSOType = rt.TypeOf; -export type CommentRequestExternalReferenceNoSOType = rt.TypeOf; -export type CommentRequestPersistableStateType = rt.TypeOf; -export type BulkGetAttachmentsResponse = rt.TypeOf; -export type BulkGetAttachmentsRequest = rt.TypeOf; diff --git a/x-pack/plugins/cases/common/api/cases/constants.ts b/x-pack/plugins/cases/common/api/cases/constants.ts deleted file mode 100644 index 92755ec633ecc6..00000000000000 --- a/x-pack/plugins/cases/common/api/cases/constants.ts +++ /dev/null @@ -1,36 +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. - */ - -/** - * This field is used for authorization of the entities within the cases plugin. Each entity within Cases will have the owner field - * set to a string that represents the plugin that "owns" (i.e. the plugin that originally issued the POST request to - * create the entity) the entity. - * - * The Authorization class constructs a string composed of the operation being performed (createCase, getComment, etc), - * and the owner of the entity being acted upon or created. This string is then given to the Security plugin which - * checks to see if the user making the request has that particular string stored within it's privileges. If it does, - * then the operation succeeds, otherwise the operation fails. - * - * APIs that create/update an entity require that the owner field be passed in the body of the request. - * APIs that search for entities typically require that the owner be passed as a query parameter. - * APIs that specify an ID of an entity directly generally don't need to specify the owner field. - * - * For APIs that create/update an entity, the RBAC implementation checks to see if the user making the request has the - * correct privileges for performing that action (a create/update) for the specified owner. - * This check is done through the Security plugin's API. - * - * For APIs that search for entities, the RBAC implementation creates a filter for the saved objects query that limits - * the search to only owners that the user has access to. We also check that the objects returned by the saved objects - * API have the limited owner scope. If we find one that the user does not have permissions for, we throw a 403 error. - * The owner field that is passed in as a query parameter can be used to further limit the results. If a user attempts - * to pass an owner that they do not have access to, the owner is ignored. - * - * For APIs that retrieve/delete entities directly using their ID, the RBAC implementation requests the object first, - * and then checks to see if the user making the request has access to that operation and owner. If the user does, the - * operation continues, otherwise we throw a 403. - */ -export const OWNER_FIELD = 'owner'; diff --git a/x-pack/plugins/cases/common/api/cases/status.test.ts b/x-pack/plugins/cases/common/api/cases/status.test.ts deleted file mode 100644 index d46c0a0d7b1f45..00000000000000 --- a/x-pack/plugins/cases/common/api/cases/status.test.ts +++ /dev/null @@ -1,62 +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 { CasesStatusRequestRt, CasesStatusResponseRt } from './status'; - -describe('status', () => { - describe('CasesStatusRequestRt', () => { - const defaultRequest = { - from: '2022-04-28T15:18:00.000Z', - to: '2022-04-28T15:22:00.000Z', - owner: 'cases', - }; - - it('has expected attributes in request', () => { - const query = CasesStatusRequestRt.decode(defaultRequest); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: defaultRequest, - }); - }); - - it('has removes foo:bar attributes from request', () => { - const query = CasesStatusRequestRt.decode({ ...defaultRequest, foo: 'bar' }); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: defaultRequest, - }); - }); - }); - - describe('CasesStatusResponseRt', () => { - const defaultResponse = { - count_closed_cases: 1, - count_in_progress_cases: 2, - count_open_cases: 1, - }; - - it('has expected attributes in response', () => { - const query = CasesStatusResponseRt.decode(defaultResponse); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: defaultResponse, - }); - }); - - it('removes foo:bar attributes from response', () => { - const query = CasesStatusResponseRt.decode({ ...defaultResponse, foo: 'bar' }); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: defaultResponse, - }); - }); - }); -}); diff --git a/x-pack/plugins/cases/common/api/cases/user_profile.test.ts b/x-pack/plugins/cases/common/api/cases/user_profile.test.ts deleted file mode 100644 index 9d382ac91dd2c1..00000000000000 --- a/x-pack/plugins/cases/common/api/cases/user_profile.test.ts +++ /dev/null @@ -1,124 +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 { PathReporter } from 'io-ts/lib/PathReporter'; -import { MAX_SUGGESTED_PROFILES } from '../../constants'; -import { SuggestUserProfilesRequestRt, CaseUserProfileRt } from './user_profiles'; - -describe('userProfile', () => { - describe('SuggestUserProfilesRequestRt', () => { - const defaultRequest = { - name: 'damaged_raccoon', - owners: ['cases'], - size: 5, - }; - - it('has expected attributes in request', () => { - const query = SuggestUserProfilesRequestRt.decode(defaultRequest); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: { - name: 'damaged_raccoon', - owners: ['cases'], - size: 5, - }, - }); - }); - - it('has only name and owner in request', () => { - const query = SuggestUserProfilesRequestRt.decode({ - name: 'damaged_raccoon', - owners: ['cases'], - foo: 'bar', - }); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: { - name: 'damaged_raccoon', - owners: ['cases'], - }, - }); - }); - - it('missing size parameter works correctly', () => { - const query = SuggestUserProfilesRequestRt.decode({ - name: 'di maria', - owners: ['benfica'], - }); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: { - name: 'di maria', - owners: ['benfica'], - }, - }); - }); - - it('removes foo:bar attributes from request', () => { - const query = SuggestUserProfilesRequestRt.decode({ ...defaultRequest, foo: 'bar' }); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: { - name: 'damaged_raccoon', - owners: ['cases'], - size: 5, - }, - }); - }); - - it(`does not accept size param bigger than ${MAX_SUGGESTED_PROFILES}`, () => { - const query = SuggestUserProfilesRequestRt.decode({ - ...defaultRequest, - size: MAX_SUGGESTED_PROFILES + 1, - }); - - expect(PathReporter.report(query)).toContain('The size field cannot be more than 10.'); - }); - - it('does not accept size param lower than 1', () => { - const query = SuggestUserProfilesRequestRt.decode({ - ...defaultRequest, - size: 0, - }); - - expect(PathReporter.report(query)).toContain('The size field cannot be less than 1.'); - }); - }); - - describe('CaseUserProfileRt', () => { - it('has expected attributes in response', () => { - const query = CaseUserProfileRt.decode({ - uid: 'u_J41Oh6L9ki-Vo2tOogS8WRTENzhHurGtRc87NgEAlkc_0', - }); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: { - uid: 'u_J41Oh6L9ki-Vo2tOogS8WRTENzhHurGtRc87NgEAlkc_0', - }, - }); - }); - - it('removes foo:bar attributes from response', () => { - const query = CaseUserProfileRt.decode({ - uid: 'u_J41Oh6L9ki-Vo2tOogS8WRTENzhHurGtRc87NgEAlkc_0', - foo: 'bar', - }); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: { - uid: 'u_J41Oh6L9ki-Vo2tOogS8WRTENzhHurGtRc87NgEAlkc_0', - }, - }); - }); - }); -}); diff --git a/x-pack/plugins/cases/common/api/index.ts b/x-pack/plugins/cases/common/api/index.ts index 440b8d988d8d7a..1e0a8738f2f417 100644 --- a/x-pack/plugins/cases/common/api/index.ts +++ b/x-pack/plugins/cases/common/api/index.ts @@ -5,9 +5,7 @@ * 2.0. */ -export * from './cases'; export * from './helpers'; export * from './runtime_types'; export * from './saved_object'; -export * from './user'; export * from './metrics'; diff --git a/x-pack/plugins/cases/common/api/runtime_types.test.ts b/x-pack/plugins/cases/common/api/runtime_types.test.ts index 657a07018beebd..a10566e2dc8b2d 100644 --- a/x-pack/plugins/cases/common/api/runtime_types.test.ts +++ b/x-pack/plugins/cases/common/api/runtime_types.test.ts @@ -6,7 +6,6 @@ */ import * as rt from 'io-ts'; -import { BulkCreateCommentRequestRt, CommentType } from './cases'; import { decodeWithExcessOrThrow } from './runtime_types'; @@ -101,15 +100,5 @@ describe('runtime_types', () => { expect(decodeWithExcessOrThrow(schemaRt)({ a: 'hi' })).toStrictEqual({ a: 'hi' }); }); - - describe('BulkCreateCommentRequestRt', () => { - it('does not throw an error for BulkCreateCommentRequestRt', () => { - expect(() => - decodeWithExcessOrThrow(BulkCreateCommentRequestRt)([ - { comment: 'hi', type: CommentType.user, owner: 'owner' }, - ]) - ).not.toThrow(); - }); - }); }); }); diff --git a/x-pack/plugins/cases/common/constants/index.ts b/x-pack/plugins/cases/common/constants/index.ts index 45125e4411f3a8..2b4e576dcf7f11 100644 --- a/x-pack/plugins/cases/common/constants/index.ts +++ b/x-pack/plugins/cases/common/constants/index.ts @@ -199,3 +199,33 @@ export const LOCAL_STORAGE_KEYS = { */ export const NONE_CONNECTOR_ID: string = 'none'; + +/** + * This field is used for authorization of the entities within the cases plugin. Each entity within Cases will have the owner field + * set to a string that represents the plugin that "owns" (i.e. the plugin that originally issued the POST request to + * create the entity) the entity. + * + * The Authorization class constructs a string composed of the operation being performed (createCase, getComment, etc), + * and the owner of the entity being acted upon or created. This string is then given to the Security plugin which + * checks to see if the user making the request has that particular string stored within it's privileges. If it does, + * then the operation succeeds, otherwise the operation fails. + * + * APIs that create/update an entity require that the owner field be passed in the body of the request. + * APIs that search for entities typically require that the owner be passed as a query parameter. + * APIs that specify an ID of an entity directly generally don't need to specify the owner field. + * + * For APIs that create/update an entity, the RBAC implementation checks to see if the user making the request has the + * correct privileges for performing that action (a create/update) for the specified owner. + * This check is done through the Security plugin's API. + * + * For APIs that search for entities, the RBAC implementation creates a filter for the saved objects query that limits + * the search to only owners that the user has access to. We also check that the objects returned by the saved objects + * API have the limited owner scope. If we find one that the user does not have permissions for, we throw a 403 error. + * The owner field that is passed in as a query parameter can be used to further limit the results. If a user attempts + * to pass an owner that they do not have access to, the owner is ignored. + * + * For APIs that retrieve/delete entities directly using their ID, the RBAC implementation requests the object first, + * and then checks to see if the user making the request has access to that operation and owner. If the user does, the + * operation continues, otherwise we throw a 403. + */ +export const OWNER_FIELD = 'owner'; diff --git a/x-pack/plugins/cases/common/index.ts b/x-pack/plugins/cases/common/index.ts index 2f376163a38347..070945d3220394 100644 --- a/x-pack/plugins/cases/common/index.ts +++ b/x-pack/plugins/cases/common/index.ts @@ -15,7 +15,13 @@ // For example, constants below could eventually be in a "kbn-cases-constants" instead. // See: https://docs.elastic.dev/kibana-dev-docs/key-concepts/platform-intro#public-plugin-api -export type { Case, Cases, CasesBulkGetResponse } from './api'; +export type { + CasesBulkGetResponse, + CasePostRequest, + GetRelatedCasesByAlertResponse, + UserActionFindResponse, +} from './types/api'; +export type { Case, Cases, RelatedCase } from './types/domain'; export type { CaseUI, CasesUI, @@ -23,8 +29,11 @@ export type { Ecs, CaseViewRefreshPropInterface, CasesPermissions, + CasesStatus, } from './ui/types'; +export { CaseSeverity } from './types/domain'; + export { APP_ID, CASES_URL, @@ -38,18 +47,14 @@ export { UPDATE_CASES_CAPABILITY, INTERNAL_BULK_GET_CASES_URL, LENS_ATTACHMENT_TYPE, + INTERNAL_BULK_CREATE_ATTACHMENTS_URL, + SAVED_OBJECT_TYPES, + CASE_COMMENT_SAVED_OBJECT, } from './constants'; -export { ConnectorTypes } from './types/domain'; - -export { - getCasesFromAlertsUrl, - throwErrors, - CaseStatuses, - CaseSeverity, - CommentType, - ExternalReferenceStorageType, -} from './api'; +export type { AttachmentAttributes } from './types/domain'; +export { ConnectorTypes, AttachmentType, ExternalReferenceStorageType } from './types/domain'; +export { getCasesFromAlertsUrl, getCaseFindUserActionsUrl, throwErrors } from './api'; export { StatusAll } from './ui/types'; export { createUICapabilities } from './utils/capabilities'; export { getApiTags } from './utils/api_tags'; diff --git a/x-pack/plugins/cases/common/api/cases/index.ts b/x-pack/plugins/cases/common/types/api/alert/latest.ts similarity index 56% rename from x-pack/plugins/cases/common/api/cases/index.ts rename to x-pack/plugins/cases/common/types/api/alert/latest.ts index c1394074f57cbc..25300c97a6d2e1 100644 --- a/x-pack/plugins/cases/common/api/cases/index.ts +++ b/x-pack/plugins/cases/common/types/api/alert/latest.ts @@ -5,10 +5,4 @@ * 2.0. */ -export * from './case'; -export * from './comment'; -export * from './status'; -export * from './constants'; -export * from './alerts'; -export * from './user_profiles'; -export * from './assignee'; +export * from './v1'; diff --git a/x-pack/plugins/cases/common/api/cases/alerts.test.ts b/x-pack/plugins/cases/common/types/api/alert/v1.test.ts similarity index 96% rename from x-pack/plugins/cases/common/api/cases/alerts.test.ts rename to x-pack/plugins/cases/common/types/api/alert/v1.test.ts index eba7e4160724c9..5038e6aabe67c2 100644 --- a/x-pack/plugins/cases/common/api/cases/alerts.test.ts +++ b/x-pack/plugins/cases/common/types/api/alert/v1.test.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { AlertResponseRt } from './alerts'; +import { AlertResponseRt } from './v1'; describe('Alerts', () => { describe('AlertResponseRt', () => { diff --git a/x-pack/plugins/cases/common/api/cases/alerts.ts b/x-pack/plugins/cases/common/types/api/alert/v1.ts similarity index 100% rename from x-pack/plugins/cases/common/api/cases/alerts.ts rename to x-pack/plugins/cases/common/types/api/alert/v1.ts diff --git a/x-pack/plugins/cases/common/api/cases/assignee.ts b/x-pack/plugins/cases/common/types/api/attachment/latest.ts similarity index 55% rename from x-pack/plugins/cases/common/api/cases/assignee.ts rename to x-pack/plugins/cases/common/types/api/attachment/latest.ts index 6f6a23870066bf..25300c97a6d2e1 100644 --- a/x-pack/plugins/cases/common/api/cases/assignee.ts +++ b/x-pack/plugins/cases/common/types/api/attachment/latest.ts @@ -5,9 +5,4 @@ * 2.0. */ -import * as rt from 'io-ts'; -import { CaseUserProfileRt } from './user_profiles'; - -export const CaseAssigneesRt = rt.array(CaseUserProfileRt); - -export type CaseAssignees = rt.TypeOf; +export * from './v1'; diff --git a/x-pack/plugins/cases/common/types/api/attachment/v1.test.ts b/x-pack/plugins/cases/common/types/api/attachment/v1.test.ts new file mode 100644 index 00000000000000..e08cff94717e42 --- /dev/null +++ b/x-pack/plugins/cases/common/types/api/attachment/v1.test.ts @@ -0,0 +1,392 @@ +/* + * 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 { PathReporter } from 'io-ts/lib/PathReporter'; +import { MAX_BULK_CREATE_ATTACHMENTS, MAX_COMMENT_LENGTH } from '../../../constants'; +import { AttachmentType } from '../../domain/attachment/v1'; +import { + AttachmentPatchRequestRt, + AttachmentRequestRt, + AttachmentsFindResponseRt, + BulkCreateAttachmentsRequestRt, + BulkDeleteFileAttachmentsRequestRt, + BulkGetAttachmentsRequestRt, + BulkGetAttachmentsResponseRt, + FindAttachmentsQueryParamsRt, +} from './v1'; + +describe('Attachments', () => { + describe('BulkDeleteFileAttachmentsRequestRt', () => { + it('has expected attributes in request', () => { + const query = BulkDeleteFileAttachmentsRequestRt.decode({ ids: ['abc', 'xyz'] }); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: { ids: ['abc', 'xyz'] }, + }); + }); + + it('removes foo:bar attributes from request', () => { + const query = BulkDeleteFileAttachmentsRequestRt.decode({ + ids: ['abc', 'xyz'], + foo: 'bar', + }); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: { ids: ['abc', 'xyz'] }, + }); + }); + }); + + describe('AttachmentRequestRt', () => { + const defaultRequest = { + comment: 'Solve this fast!', + type: AttachmentType.user, + owner: 'cases', + }; + + it('has expected attributes in request', () => { + const query = AttachmentRequestRt.decode(defaultRequest); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: defaultRequest, + }); + }); + + it('removes foo:bar attributes from request', () => { + const query = AttachmentRequestRt.decode({ ...defaultRequest, foo: 'bar' }); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: defaultRequest, + }); + }); + + describe('errors', () => { + describe('commentType: user', () => { + it('throws error when comment is too long', () => { + const longComment = 'x'.repeat(MAX_COMMENT_LENGTH + 1); + + expect( + PathReporter.report( + AttachmentRequestRt.decode({ ...defaultRequest, comment: longComment }) + ) + ).toContain('The length of the comment is too long. The maximum length is 30000.'); + }); + + it('throws error when comment is empty', () => { + expect( + PathReporter.report(AttachmentRequestRt.decode({ ...defaultRequest, comment: '' })) + ).toContain('The comment field cannot be an empty string.'); + }); + + it('throws error when comment string of empty characters', () => { + expect( + PathReporter.report(AttachmentRequestRt.decode({ ...defaultRequest, comment: ' ' })) + ).toContain('The comment field cannot be an empty string.'); + }); + }); + + describe('commentType: action', () => { + const request = { + type: AttachmentType.actions, + actions: { + targets: [ + { + hostname: 'host1', + endpointId: '001', + }, + ], + type: 'isolate', + }, + owner: 'cases', + }; + + it('throws error when comment is too long', () => { + const longComment = 'x'.repeat(MAX_COMMENT_LENGTH + 1); + + expect( + PathReporter.report(AttachmentRequestRt.decode({ ...request, comment: longComment })) + ).toContain('The length of the comment is too long. The maximum length is 30000.'); + }); + + it('throws error when comment is empty', () => { + expect( + PathReporter.report(AttachmentRequestRt.decode({ ...request, comment: '' })) + ).toContain('The comment field cannot be an empty string.'); + }); + + it('throws error when comment string of empty characters', () => { + expect( + PathReporter.report(AttachmentRequestRt.decode({ ...request, comment: ' ' })) + ).toContain('The comment field cannot be an empty string.'); + }); + }); + }); + }); + + describe('AttachmentPatchRequestRt', () => { + const defaultRequest = { + alertId: 'alert-id-1', + index: 'alert-index-1', + type: AttachmentType.alert, + id: 'alert-comment-id', + owner: 'cases', + rule: { + id: 'rule-id-1', + name: 'Awesome rule', + }, + version: 'WzQ3LDFc', + }; + it('has expected attributes in request', () => { + const query = AttachmentPatchRequestRt.decode(defaultRequest); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: defaultRequest, + }); + }); + + it('removes foo:bar attributes from request', () => { + const query = AttachmentPatchRequestRt.decode({ ...defaultRequest, foo: 'bar' }); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: defaultRequest, + }); + }); + }); + + describe('AttachmentsFindResponseRt', () => { + const defaultRequest = { + comments: [ + { + comment: 'Solve this fast!', + type: AttachmentType.user, + owner: 'cases', + created_at: '2020-02-19T23:06:33.798Z', + created_by: { + full_name: 'Leslie Knope', + username: 'lknope', + email: 'leslie.knope@elastic.co', + }, + pushed_at: null, + pushed_by: null, + updated_at: null, + updated_by: null, + id: 'basic-comment-id', + version: 'WzQ3LDFc', + }, + ], + page: 1, + per_page: 10, + total: 1, + }; + it('has expected attributes in request', () => { + const query = AttachmentsFindResponseRt.decode(defaultRequest); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: defaultRequest, + }); + }); + + it('removes foo:bar attributes from request', () => { + const query = AttachmentsFindResponseRt.decode({ ...defaultRequest, foo: 'bar' }); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: defaultRequest, + }); + }); + + it('removes foo:bar attributes from comments', () => { + const query = AttachmentsFindResponseRt.decode({ + ...defaultRequest, + comments: [{ ...defaultRequest.comments[0], foo: 'bar' }], + }); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: defaultRequest, + }); + }); + }); + + describe('FindAttachmentsQueryParamsRt', () => { + const defaultRequest = { + page: 1, + perPage: 10, + sortOrder: 'asc', + }; + + it('has expected attributes in request', () => { + const query = FindAttachmentsQueryParamsRt.decode(defaultRequest); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: defaultRequest, + }); + }); + + it('removes foo:bar attributes from request', () => { + const query = FindAttachmentsQueryParamsRt.decode({ ...defaultRequest, foo: 'bar' }); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: defaultRequest, + }); + }); + }); + + describe('BulkCreateAttachmentsRequestRt', () => { + const defaultRequest = [ + { + comment: 'Solve this fast!', + type: AttachmentType.user, + owner: 'cases', + }, + ]; + + it('has expected attributes in request', () => { + const query = BulkCreateAttachmentsRequestRt.decode(defaultRequest); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: defaultRequest, + }); + }); + + it('removes foo:bar attributes from request', () => { + const query = BulkCreateAttachmentsRequestRt.decode([ + { comment: 'Solve this fast!', type: AttachmentType.user, owner: 'cases', foo: 'bar' }, + ]); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: defaultRequest, + }); + }); + + describe('errors', () => { + it(`throws error when attachments are more than ${MAX_BULK_CREATE_ATTACHMENTS}`, () => { + const comment = { + comment: 'Solve this fast!', + type: AttachmentType.user, + owner: 'cases', + }; + const attachments = Array(MAX_BULK_CREATE_ATTACHMENTS + 1).fill(comment); + + expect(PathReporter.report(BulkCreateAttachmentsRequestRt.decode(attachments))).toContain( + `The length of the field attachments is too long. Array must be of length <= ${MAX_BULK_CREATE_ATTACHMENTS}.` + ); + }); + + it(`no errors when empty array of attachments`, () => { + expect(PathReporter.report(BulkCreateAttachmentsRequestRt.decode([]))).toStrictEqual([ + 'No errors!', + ]); + }); + }); + }); + + describe('BulkGetAttachmentsRequestRt', () => { + it('has expected attributes in request', () => { + const query = BulkGetAttachmentsRequestRt.decode({ ids: ['abc', 'xyz'] }); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: { ids: ['abc', 'xyz'] }, + }); + }); + + it('removes foo:bar attributes from request', () => { + const query = BulkGetAttachmentsRequestRt.decode({ ids: ['abc', 'xyz'], foo: 'bar' }); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: { ids: ['abc', 'xyz'] }, + }); + }); + }); + + describe('BulkGetAttachmentsResponseRt', () => { + const defaultRequest = { + attachments: [ + { + comment: 'Solve this fast!', + type: AttachmentType.user, + owner: 'cases', + id: 'basic-comment-id', + version: 'WzQ3LDFc', + created_at: '2020-02-19T23:06:33.798Z', + created_by: { + full_name: 'Leslie Knope', + username: 'lknope', + email: 'leslie.knope@elastic.co', + }, + pushed_at: null, + pushed_by: null, + updated_at: null, + updated_by: null, + }, + ], + errors: [ + { + error: 'error', + message: 'not found', + status: 404, + attachmentId: 'abc', + }, + ], + }; + + it('has expected attributes in request', () => { + const query = BulkGetAttachmentsResponseRt.decode(defaultRequest); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: defaultRequest, + }); + }); + + it('removes foo:bar attributes from request', () => { + const query = BulkGetAttachmentsResponseRt.decode({ ...defaultRequest, foo: 'bar' }); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: defaultRequest, + }); + }); + + it('removes foo:bar attributes from attachments', () => { + const query = BulkGetAttachmentsResponseRt.decode({ + ...defaultRequest, + attachments: [{ ...defaultRequest.attachments[0], foo: 'bar' }], + }); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: defaultRequest, + }); + }); + + it('removes foo:bar attributes from errors', () => { + const query = BulkGetAttachmentsResponseRt.decode({ + ...defaultRequest, + errors: [{ ...defaultRequest.errors[0], foo: 'bar' }], + }); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: defaultRequest, + }); + }); + }); +}); diff --git a/x-pack/plugins/cases/common/types/api/attachment/v1.ts b/x-pack/plugins/cases/common/types/api/attachment/v1.ts new file mode 100644 index 00000000000000..3d9cb02a5ce558 --- /dev/null +++ b/x-pack/plugins/cases/common/types/api/attachment/v1.ts @@ -0,0 +1,157 @@ +/* + * 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 * as rt from 'io-ts'; +import { + MAX_BULK_CREATE_ATTACHMENTS, + MAX_BULK_GET_ATTACHMENTS, + MAX_COMMENTS_PER_PAGE, + MAX_COMMENT_LENGTH, + MAX_DELETE_FILES, +} from '../../../constants'; +import { + limitedArraySchema, + limitedStringSchema, + NonEmptyString, + paginationSchema, +} from '../../../schema'; +import { + UserCommentAttachmentPayloadRt, + AlertAttachmentPayloadRt, + ActionsAttachmentPayloadRt, + ExternalReferenceNoSOAttachmentPayloadRt, + ExternalReferenceSOAttachmentPayloadRt, + ExternalReferenceSOWithoutRefsAttachmentPayloadRt, + PersistableStateAttachmentPayloadRt, + AttachmentType, + AttachmentRt, + AttachmentsRt, +} from '../../domain/attachment/v1'; + +/** + * Files + */ + +const MIN_DELETE_IDS = 1; + +export const BulkDeleteFileAttachmentsRequestRt = rt.strict({ + ids: limitedArraySchema({ + codec: NonEmptyString, + min: MIN_DELETE_IDS, + max: MAX_DELETE_FILES, + fieldName: 'ids', + }), +}); + +export type BulkDeleteFileAttachmentsRequest = rt.TypeOf; + +const BasicAttachmentRequestRt = rt.union([ + UserCommentAttachmentPayloadRt, + AlertAttachmentPayloadRt, + ActionsAttachmentPayloadRt, + ExternalReferenceNoSOAttachmentPayloadRt, + PersistableStateAttachmentPayloadRt, +]); + +export const AttachmentRequestRt = rt.union([ + rt.strict({ + comment: limitedStringSchema({ fieldName: 'comment', min: 1, max: MAX_COMMENT_LENGTH }), + type: rt.literal(AttachmentType.user), + owner: rt.string, + }), + AlertAttachmentPayloadRt, + rt.strict({ + type: rt.literal(AttachmentType.actions), + comment: limitedStringSchema({ fieldName: 'comment', min: 1, max: MAX_COMMENT_LENGTH }), + actions: rt.strict({ + targets: rt.array( + rt.strict({ + hostname: rt.string, + endpointId: rt.string, + }) + ), + type: rt.string, + }), + owner: rt.string, + }), + ExternalReferenceNoSOAttachmentPayloadRt, + ExternalReferenceSOAttachmentPayloadRt, + PersistableStateAttachmentPayloadRt, +]); + +export const AttachmentRequestWithoutRefsRt = rt.union([ + BasicAttachmentRequestRt, + ExternalReferenceSOWithoutRefsAttachmentPayloadRt, +]); + +export const AttachmentPatchRequestRt = rt.intersection([ + /** + * Partial updates are not allowed. + * We want to prevent the user for changing the type without removing invalid fields. + * + * injectAttachmentSOAttributesFromRefsForPatch is dependent on this assumption. + * The consumers of the persistable attachment service should always get the + * persistableStateAttachmentState on a patch. + */ + AttachmentRequestRt, + rt.strict({ id: rt.string, version: rt.string }), +]); + +export const AttachmentsFindResponseRt = rt.strict({ + comments: rt.array(AttachmentRt), + page: rt.number, + per_page: rt.number, + total: rt.number, +}); + +export const FindAttachmentsQueryParamsRt = rt.intersection([ + rt.exact( + rt.partial({ + /** + * Order to sort the response + */ + sortOrder: rt.union([rt.literal('desc'), rt.literal('asc')]), + }) + ), + paginationSchema({ maxPerPage: MAX_COMMENTS_PER_PAGE }), +]); + +export const BulkCreateAttachmentsRequestRt = limitedArraySchema({ + codec: AttachmentRequestRt, + min: 0, + max: MAX_BULK_CREATE_ATTACHMENTS, + fieldName: 'attachments', +}); + +export const BulkGetAttachmentsRequestRt = rt.strict({ + ids: limitedArraySchema({ + codec: rt.string, + min: 1, + max: MAX_BULK_GET_ATTACHMENTS, + fieldName: 'ids', + }), +}); + +export const BulkGetAttachmentsResponseRt = rt.strict({ + attachments: AttachmentsRt, + errors: rt.array( + rt.strict({ + error: rt.string, + message: rt.string, + status: rt.union([rt.undefined, rt.number]), + attachmentId: rt.string, + }) + ), +}); + +export type FindAttachmentsQueryParams = rt.TypeOf; +export type AttachmentsFindResponse = rt.TypeOf; +export type AttachmentRequest = rt.TypeOf; +export type AttachmentPatchRequest = rt.TypeOf; +export type BulkCreateAttachmentsRequest = rt.TypeOf; +export type BulkGetAttachmentsResponse = rt.TypeOf; +export type BulkGetAttachmentsRequest = rt.TypeOf; diff --git a/x-pack/plugins/cases/common/types/api/case/latest.ts b/x-pack/plugins/cases/common/types/api/case/latest.ts new file mode 100644 index 00000000000000..25300c97a6d2e1 --- /dev/null +++ b/x-pack/plugins/cases/common/types/api/case/latest.ts @@ -0,0 +1,8 @@ +/* + * 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. + */ + +export * from './v1'; diff --git a/x-pack/plugins/cases/common/types/api/case/v1.test.ts b/x-pack/plugins/cases/common/types/api/case/v1.test.ts new file mode 100644 index 00000000000000..40c980d633545c --- /dev/null +++ b/x-pack/plugins/cases/common/types/api/case/v1.test.ts @@ -0,0 +1,555 @@ +/* + * 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 { PathReporter } from 'io-ts/lib/PathReporter'; +import { AttachmentType } from '../../domain/attachment/v1'; +import { CaseSeverity, CaseStatuses } from '../../domain/case/v1'; +import { ConnectorTypes } from '../../domain/connector/v1'; +import { CasesStatusRequestRt, CasesStatusResponseRt } from '../stats/v1'; +import { + AllReportersFindRequestRt, + CasePatchRequestRt, + CasePostRequestRt, + CasePushRequestParamsRt, + CaseResolveResponseRt, + CasesBulkGetRequestRt, + CasesBulkGetResponseRt, + CasesByAlertIDRequestRt, + CasesFindRequestRt, + CasesFindRequestSearchFieldsRt, + CasesFindRequestSortFieldsRt, + CasesFindResponseRt, + CasesPatchRequestRt, +} from './v1'; + +const basicCase = { + owner: 'cases', + closed_at: null, + closed_by: null, + id: 'basic-case-id', + comments: [ + { + comment: 'Solve this fast!', + type: AttachmentType.user, + id: 'basic-comment-id', + created_at: '2020-02-19T23:06:33.798Z', + created_by: { + full_name: 'Leslie Knope', + username: 'lknope', + email: 'leslie.knope@elastic.co', + }, + owner: 'cases', + pushed_at: null, + pushed_by: null, + updated_at: null, + updated_by: null, + version: 'WzQ3LDFc', + }, + ], + created_at: '2020-02-19T23:06:33.798Z', + created_by: { + full_name: 'Leslie Knope', + username: 'lknope', + email: 'leslie.knope@elastic.co', + }, + connector: { + id: 'none', + name: 'My Connector', + type: ConnectorTypes.none, + fields: null, + }, + description: 'Security banana Issue', + severity: CaseSeverity.LOW, + duration: null, + external_service: null, + status: CaseStatuses.open, + tags: ['coke', 'pepsi'], + title: 'Another horrible breach!!', + totalComment: 1, + totalAlerts: 0, + updated_at: '2020-02-20T15:02:57.995Z', + updated_by: { + full_name: 'Leslie Knope', + username: 'lknope', + email: 'leslie.knope@elastic.co', + }, + version: 'WzQ3LDFd', + settings: { + syncAlerts: true, + }, + // damaged_raccoon uid + assignees: [{ uid: 'u_J41Oh6L9ki-Vo2tOogS8WRTENzhHurGtRc87NgEAlkc_0' }], + category: null, +}; + +describe('Status', () => { + describe('CasesStatusRequestRt', () => { + const defaultRequest = { + from: '2022-04-28T15:18:00.000Z', + to: '2022-04-28T15:22:00.000Z', + owner: 'cases', + }; + + it('has expected attributes in request', () => { + const query = CasesStatusRequestRt.decode(defaultRequest); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: defaultRequest, + }); + }); + + it('has removes foo:bar attributes from request', () => { + const query = CasesStatusRequestRt.decode({ ...defaultRequest, foo: 'bar' }); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: defaultRequest, + }); + }); + }); + + describe('CasesStatusResponseRt', () => { + const defaultResponse = { + count_closed_cases: 1, + count_in_progress_cases: 2, + count_open_cases: 1, + }; + + it('has expected attributes in response', () => { + const query = CasesStatusResponseRt.decode(defaultResponse); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: defaultResponse, + }); + }); + + it('removes foo:bar attributes from response', () => { + const query = CasesStatusResponseRt.decode({ ...defaultResponse, foo: 'bar' }); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: defaultResponse, + }); + }); + }); + + describe('CasePostRequestRt', () => { + const defaultRequest = { + description: 'A description', + tags: ['new', 'case'], + title: 'My new case', + connector: { + id: '123', + name: 'My connector', + type: ConnectorTypes.jira, + fields: { issueType: 'Task', priority: 'High', parent: null }, + }, + settings: { + syncAlerts: true, + }, + owner: 'cases', + severity: CaseSeverity.LOW, + assignees: [{ uid: 'u_J41Oh6L9ki-Vo2tOogS8WRTENzhHurGtRc87NgEAlkc_0' }], + }; + + it('has expected attributes in request', () => { + const query = CasePostRequestRt.decode(defaultRequest); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: defaultRequest, + }); + }); + + it('removes foo:bar attributes from request', () => { + const query = CasePostRequestRt.decode({ ...defaultRequest, foo: 'bar' }); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: defaultRequest, + }); + }); + + it('removes foo:bar attributes from connector', () => { + const query = CasePostRequestRt.decode({ + ...defaultRequest, + connector: { ...defaultRequest.connector, foo: 'bar' }, + }); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: defaultRequest, + }); + }); + }); + + describe('CasesFindRequestRt', () => { + const defaultRequest = { + tags: ['new', 'case'], + status: CaseStatuses.open, + severity: CaseSeverity.LOW, + assignees: ['damaged_racoon'], + reporters: ['damaged_racoon'], + defaultSearchOperator: 'AND', + from: 'now', + page: '1', + perPage: '10', + search: 'search text', + searchFields: ['title', 'description'], + to: '1w', + sortOrder: 'desc', + sortField: 'createdAt', + owner: 'cases', + }; + + it('has expected attributes in request', () => { + const query = CasesFindRequestRt.decode(defaultRequest); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: { ...defaultRequest, page: 1, perPage: 10 }, + }); + }); + + it('removes foo:bar attributes from request', () => { + const query = CasesFindRequestRt.decode({ ...defaultRequest, foo: 'bar' }); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: { ...defaultRequest, page: 1, perPage: 10 }, + }); + }); + + const searchFields = Object.keys(CasesFindRequestSearchFieldsRt.keys); + + it.each(searchFields)('succeeds with %s as searchFields', (field) => { + const query = CasesFindRequestRt.decode({ ...defaultRequest, searchFields: field }); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: { ...defaultRequest, searchFields: field, page: 1, perPage: 10 }, + }); + }); + + const sortFields = Object.keys(CasesFindRequestSortFieldsRt.keys); + + it.each(sortFields)('succeeds with %s as sortField', (sortField) => { + const query = CasesFindRequestRt.decode({ ...defaultRequest, sortField }); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: { ...defaultRequest, sortField, page: 1, perPage: 10 }, + }); + }); + + it('removes rootSearchField when passed', () => { + expect( + PathReporter.report( + CasesFindRequestRt.decode({ ...defaultRequest, rootSearchField: ['foobar'] }) + ) + ).toContain('No errors!'); + }); + + describe('errors', () => { + it('throws error when invalid searchField passed', () => { + expect( + PathReporter.report( + CasesFindRequestRt.decode({ ...defaultRequest, searchFields: 'foobar' }) + ) + ).not.toContain('No errors!'); + }); + + it('throws error when invalid sortField passed', () => { + expect( + PathReporter.report(CasesFindRequestRt.decode({ ...defaultRequest, sortField: 'foobar' })) + ).not.toContain('No errors!'); + }); + + it('succeeds when valid parameters passed', () => { + expect(PathReporter.report(CasesFindRequestRt.decode(defaultRequest))).toContain( + 'No errors!' + ); + }); + }); + }); +}); + +describe('CasesByAlertIDRequestRt', () => { + it('has expected attributes in request', () => { + const query = CasesByAlertIDRequestRt.decode({ owner: 'cases' }); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: { owner: 'cases' }, + }); + }); + + it('removes foo:bar attributes from request', () => { + const query = CasesByAlertIDRequestRt.decode({ owner: ['cases'], foo: 'bar' }); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: { owner: ['cases'] }, + }); + }); +}); + +describe('CaseResolveResponseRt', () => { + const defaultRequest = { + case: { ...basicCase }, + outcome: 'exactMatch', + alias_target_id: 'sample-target-id', + alias_purpose: 'savedObjectConversion', + }; + + it('has expected attributes in request', () => { + const query = CaseResolveResponseRt.decode(defaultRequest); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: defaultRequest, + }); + }); + + it('removes foo:bar attributes from request', () => { + const query = CaseResolveResponseRt.decode({ ...defaultRequest, foo: 'bar' }); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: defaultRequest, + }); + }); +}); + +describe('CasesFindResponseRt', () => { + const defaultRequest = { + cases: [{ ...basicCase }], + page: 1, + per_page: 10, + total: 20, + count_open_cases: 10, + count_in_progress_cases: 5, + count_closed_cases: 5, + }; + + it('has expected attributes in request', () => { + const query = CasesFindResponseRt.decode(defaultRequest); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: defaultRequest, + }); + }); + + it('removes foo:bar attributes from request', () => { + const query = CasesFindResponseRt.decode({ ...defaultRequest, foo: 'bar' }); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: defaultRequest, + }); + }); + + it('removes foo:bar attributes from cases', () => { + const query = CasesFindResponseRt.decode({ + ...defaultRequest, + cases: [{ ...basicCase, foo: 'bar' }], + }); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: defaultRequest, + }); + }); +}); + +describe('CasePatchRequestRt', () => { + const defaultRequest = { + id: 'basic-case-id', + version: 'WzQ3LDFd', + description: 'Updated description', + }; + + it('has expected attributes in request', () => { + const query = CasePatchRequestRt.decode(defaultRequest); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: defaultRequest, + }); + }); + + it('removes foo:bar attributes from request', () => { + const query = CasePatchRequestRt.decode({ ...defaultRequest, foo: 'bar' }); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: defaultRequest, + }); + }); +}); + +describe('CasesPatchRequestRt', () => { + const defaultRequest = { + cases: [ + { + id: 'basic-case-id', + version: 'WzQ3LDFd', + description: 'Updated description', + }, + ], + }; + + it('has expected attributes in request', () => { + const query = CasesPatchRequestRt.decode(defaultRequest); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: defaultRequest, + }); + }); + + it('removes foo:bar attributes from request', () => { + const query = CasesPatchRequestRt.decode({ ...defaultRequest, foo: 'bar' }); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: defaultRequest, + }); + }); +}); + +describe('CasePushRequestParamsRt', () => { + const defaultRequest = { + case_id: 'basic-case-id', + connector_id: 'basic-connector-id', + }; + + it('has expected attributes in request', () => { + const query = CasePushRequestParamsRt.decode(defaultRequest); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: defaultRequest, + }); + }); + + it('removes foo:bar attributes from request', () => { + const query = CasePushRequestParamsRt.decode({ ...defaultRequest, foo: 'bar' }); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: defaultRequest, + }); + }); +}); + +describe('AllReportersFindRequestRt', () => { + const defaultRequest = { + owner: ['cases', 'security-solution'], + }; + + it('has expected attributes in request', () => { + const query = AllReportersFindRequestRt.decode(defaultRequest); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: defaultRequest, + }); + }); + + it('removes foo:bar attributes from request', () => { + const query = AllReportersFindRequestRt.decode({ ...defaultRequest, foo: 'bar' }); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: defaultRequest, + }); + }); +}); + +describe('CasesBulkGetRequestRt', () => { + const defaultRequest = { + ids: ['case-1', 'case-2'], + }; + + it('has expected attributes in request', () => { + const query = CasesBulkGetRequestRt.decode(defaultRequest); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: defaultRequest, + }); + }); + + it('removes foo:bar attributes from request', () => { + const query = CasesBulkGetRequestRt.decode({ ...defaultRequest, foo: 'bar' }); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: defaultRequest, + }); + }); +}); + +describe('CasesBulkGetResponseRt', () => { + const defaultRequest = { + cases: [basicCase], + errors: [ + { + error: 'error', + message: 'error-message', + status: 403, + caseId: 'basic-case-id', + }, + ], + }; + + it('has expected attributes in request', () => { + const query = CasesBulkGetResponseRt.decode(defaultRequest); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: defaultRequest, + }); + }); + + it('removes foo:bar attributes from request', () => { + const query = CasesBulkGetResponseRt.decode({ ...defaultRequest, foo: 'bar' }); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: defaultRequest, + }); + }); + + it('removes foo:bar attributes from cases', () => { + const query = CasesBulkGetResponseRt.decode({ + ...defaultRequest, + cases: [{ ...defaultRequest.cases[0], foo: 'bar' }], + }); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: { ...defaultRequest, cases: defaultRequest.cases }, + }); + }); + + it('removes foo:bar attributes from errors', () => { + const query = CasesBulkGetResponseRt.decode({ + ...defaultRequest, + errors: [{ ...defaultRequest.errors[0], foo: 'bar' }], + }); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: defaultRequest, + }); + }); +}); diff --git a/x-pack/plugins/cases/common/api/cases/case.ts b/x-pack/plugins/cases/common/types/api/case/v1.ts similarity index 70% rename from x-pack/plugins/cases/common/api/cases/case.ts rename to x-pack/plugins/cases/common/types/api/case/v1.ts index 3604d3b43fb810..97981f90fb8dc1 100644 --- a/x-pack/plugins/cases/common/api/cases/case.ts +++ b/x-pack/plugins/cases/common/types/api/case/v1.ts @@ -6,145 +6,41 @@ */ import * as rt from 'io-ts'; - -import { UserRt } from '../user'; -import { CommentRt } from './comment'; -import { CasesStatusResponseRt, CaseStatusRt } from './status'; -import { CaseAssigneesRt } from './assignee'; -import { - limitedArraySchema, - limitedStringSchema, - NonEmptyString, - paginationSchema, -} from '../../schema'; import { - MAX_DELETE_IDS_LENGTH, MAX_DESCRIPTION_LENGTH, - MAX_TITLE_LENGTH, MAX_LENGTH_PER_TAG, - MAX_CATEGORY_LENGTH, MAX_TAGS_PER_CASE, + MAX_TITLE_LENGTH, + MAX_CATEGORY_LENGTH, MAX_ASSIGNEES_FILTER_LENGTH, + MAX_CASES_PER_PAGE, + MAX_DELETE_IDS_LENGTH, MAX_REPORTERS_FILTER_LENGTH, MAX_TAGS_FILTER_LENGTH, MAX_CASES_TO_UPDATE, MAX_BULK_GET_CASES, - MAX_CASES_PER_PAGE, -} from '../../constants'; -import { CaseConnectorRt } from '../../types/domain/connector/v1'; - -export const AttachmentTotalsRt = rt.strict({ - alerts: rt.number, - userComments: rt.number, -}); - -export const RelatedCaseInfoRt = rt.strict({ - id: rt.string, - title: rt.string, - description: rt.string, - status: CaseStatusRt, - createdAt: rt.string, - totals: AttachmentTotalsRt, -}); - -export const CasesByAlertIdRt = rt.array(RelatedCaseInfoRt); - -export const SettingsRt = rt.strict({ - syncAlerts: rt.boolean, -}); - -export enum CaseSeverity { - LOW = 'low', - MEDIUM = 'medium', - HIGH = 'high', - CRITICAL = 'critical', -} - -export const CaseSeverityRt = rt.union([ - rt.literal(CaseSeverity.LOW), - rt.literal(CaseSeverity.MEDIUM), - rt.literal(CaseSeverity.HIGH), - rt.literal(CaseSeverity.CRITICAL), -]); - -const CaseBasicRt = rt.strict({ - /** - * The description of the case - */ - description: rt.string, - /** - * The current status of the case (open, closed, in-progress) - */ - status: CaseStatusRt, - /** - * The identifying strings for filter a case - */ - tags: rt.array(rt.string), - /** - * The title of a case - */ - title: rt.string, - /** - * The external system that the case can be synced with - */ - connector: CaseConnectorRt, - /** - * The alert sync settings - */ - settings: SettingsRt, - /** - * The plugin owner of the case - */ - owner: rt.string, - /** - * The severity of the case - */ - severity: CaseSeverityRt, - /** - * The users assigned to this case - */ - assignees: CaseAssigneesRt, - /** - * The category of the case. - */ - category: rt.union([rt.string, rt.null]), -}); +} from '../../../constants'; +import { + limitedStringSchema, + limitedArraySchema, + NonEmptyString, + paginationSchema, +} from '../../../schema'; +import { + CaseRt, + CaseSettingsRt, + CaseSeverityRt, + CasesRt, + CaseStatusRt, + RelatedCaseRt, +} from '../../domain/case/v1'; +import { CaseConnectorRt } from '../../domain/connector/v1'; +import { CaseAssigneesRt, UserRt } from '../../domain/user/v1'; +import { CasesStatusResponseRt } from '../stats/v1'; /** - * This represents the push to service UserAction. It lacks the connector_id because that is stored in a different field - * within the user action object in the API response. + * Create case */ -export const CaseUserActionExternalServiceRt = rt.strict({ - connector_name: rt.string, - external_id: rt.string, - external_title: rt.string, - external_url: rt.string, - pushed_at: rt.string, - pushed_by: UserRt, -}); - -export const CaseExternalServiceBasicRt = rt.intersection([ - rt.strict({ - connector_id: rt.string, - }), - CaseUserActionExternalServiceRt, -]); - -export const CaseFullExternalServiceRt = rt.union([CaseExternalServiceBasicRt, rt.null]); - -export const CaseAttributesRt = rt.intersection([ - CaseBasicRt, - rt.strict({ - duration: rt.union([rt.number, rt.null]), - closed_at: rt.union([rt.string, rt.null]), - closed_by: rt.union([UserRt, rt.null]), - created_at: rt.string, - created_by: UserRt, - external_service: CaseFullExternalServiceRt, - updated_at: rt.union([rt.string, rt.null]), - updated_by: rt.union([UserRt, rt.null]), - }), -]); export const CasePostRequestRt = rt.intersection([ rt.strict({ @@ -176,7 +72,7 @@ export const CasePostRequestRt = rt.intersection([ /** * Sync settings for alerts */ - settings: SettingsRt, + settings: CaseSettingsRt, /** * The owner here must match the string used when a plugin registers a feature with access to the cases plugin. The user * creating this case must also be granted access to that plugin's feature. @@ -324,6 +220,20 @@ export const CasesFindRequestRt = rt.intersection([ paginationSchema({ maxPerPage: MAX_CASES_PER_PAGE }), ]); +export const CasesFindResponseRt = rt.intersection([ + rt.strict({ + cases: rt.array(CaseRt), + page: rt.number, + per_page: rt.number, + total: rt.number, + }), + CasesStatusResponseRt, +]); + +/** + * Delete cases + */ + export const CasesDeleteRequestRt = limitedArraySchema({ codec: NonEmptyString, min: 1, @@ -331,30 +241,9 @@ export const CasesDeleteRequestRt = limitedArraySchema({ fieldName: 'ids', }); -export const CasesByAlertIDRequestRt = rt.exact( - rt.partial({ - /** - * The type of cases to retrieve given an alert ID. If no owner is provided, all cases - * that the user has access to will be returned. - */ - owner: rt.union([rt.array(rt.string), rt.string]), - }) -); - -export const CaseRt = rt.intersection([ - CaseAttributesRt, - rt.strict({ - id: rt.string, - totalComment: rt.number, - totalAlerts: rt.number, - version: rt.string, - }), - rt.exact( - rt.partial({ - comments: rt.array(CommentRt), - }) - ), -]); +/** + * Resolve case + */ export const CaseResolveResponseRt = rt.intersection([ rt.strict({ @@ -372,16 +261,28 @@ export const CaseResolveResponseRt = rt.intersection([ ), ]); -export const CasesFindResponseRt = rt.intersection([ - rt.strict({ - cases: rt.array(CaseRt), - page: rt.number, - per_page: rt.number, - total: rt.number, - }), - CasesStatusResponseRt, -]); +/** + * Get cases + */ +export const CasesBulkGetRequestRt = rt.strict({ + ids: limitedArraySchema({ codec: rt.string, min: 1, max: MAX_BULK_GET_CASES, fieldName: 'ids' }), +}); + +export const CasesBulkGetResponseRt = rt.strict({ + cases: CasesRt, + errors: rt.array( + rt.strict({ + error: rt.string, + message: rt.string, + status: rt.union([rt.undefined, rt.number]), + caseId: rt.string, + }) + ), +}); +/** + * Update cases + */ export const CasePatchRequestRt = rt.intersection([ rt.exact( rt.partial({ @@ -417,7 +318,7 @@ export const CasePatchRequestRt = rt.intersection([ /** * The alert sync settings */ - settings: SettingsRt, + settings: CaseSettingsRt, /** * The plugin owner of the case */ @@ -454,34 +355,18 @@ export const CasesPatchRequestRt = rt.strict({ }), }); -export const CasesRt = rt.array(CaseRt); +/** + * Push case + */ export const CasePushRequestParamsRt = rt.strict({ case_id: rt.string, connector_id: rt.string, }); -export const ExternalServiceResponseRt = rt.intersection([ - rt.strict({ - title: rt.string, - id: rt.string, - pushedDate: rt.string, - url: rt.string, - }), - rt.exact( - rt.partial({ - comments: rt.array( - rt.intersection([ - rt.strict({ - commentId: rt.string, - pushedDate: rt.string, - }), - rt.exact(rt.partial({ externalCommentId: rt.string })), - ]) - ), - }) - ), -]); +/** + * Taxonomies + */ export const AllTagsFindRequestRt = rt.exact( rt.partial({ @@ -509,28 +394,24 @@ export const GetTagsResponseRt = rt.array(rt.string); export const GetCategoriesResponseRt = rt.array(rt.string); export const GetReportersResponseRt = rt.array(UserRt); -export const CasesBulkGetRequestRt = rt.strict({ - ids: limitedArraySchema({ codec: rt.string, min: 1, max: MAX_BULK_GET_CASES, fieldName: 'ids' }), -}); +/** + * Alerts + */ -export const CasesBulkGetResponseRt = rt.strict({ - cases: CasesRt, - errors: rt.array( - rt.strict({ - error: rt.string, - message: rt.string, - status: rt.union([rt.undefined, rt.number]), - caseId: rt.string, - }) - ), -}); +export const CasesByAlertIDRequestRt = rt.exact( + rt.partial({ + /** + * The type of cases to retrieve given an alert ID. If no owner is provided, all cases + * that the user has access to will be returned. + */ + owner: rt.union([rt.array(rt.string), rt.string]), + }) +); -export type CaseAttributes = rt.TypeOf; +export const GetRelatedCasesByAlertResponseRt = rt.array(RelatedCaseRt); export type CasePostRequest = rt.TypeOf; -export type Case = rt.TypeOf; export type CaseResolveResponse = rt.TypeOf; -export type Cases = rt.TypeOf; export type CasesDeleteRequest = rt.TypeOf; export type CasesByAlertIDRequest = rt.TypeOf; export type CasesFindRequest = rt.TypeOf; @@ -538,18 +419,12 @@ export type CasesFindRequestSortFields = rt.TypeOf; export type CasePatchRequest = rt.TypeOf; export type CasesPatchRequest = rt.TypeOf; -export type CaseFullExternalService = rt.TypeOf; -export type CaseSettings = rt.TypeOf; -export type ExternalServiceResponse = rt.TypeOf; -export type CaseExternalServiceBasic = rt.TypeOf; - export type AllTagsFindRequest = rt.TypeOf; +export type GetTagsResponse = rt.TypeOf; export type AllCategoriesFindRequest = rt.TypeOf; +export type GetCategoriesResponse = rt.TypeOf; export type AllReportersFindRequest = AllTagsFindRequest; - -export type AttachmentTotals = rt.TypeOf; -export type RelatedCaseInfo = rt.TypeOf; -export type CasesByAlertId = rt.TypeOf; - +export type GetReportersResponse = rt.TypeOf; export type CasesBulkGetRequest = rt.TypeOf; export type CasesBulkGetResponse = rt.TypeOf; +export type GetRelatedCasesByAlertResponse = rt.TypeOf; diff --git a/x-pack/plugins/cases/common/types/api/connector/v1.ts b/x-pack/plugins/cases/common/types/api/connector/v1.ts index bfbab672660ce6..4ae76f755acf1e 100644 --- a/x-pack/plugins/cases/common/types/api/connector/v1.ts +++ b/x-pack/plugins/cases/common/types/api/connector/v1.ts @@ -6,28 +6,13 @@ */ import * as rt from 'io-ts'; -import { CaseExternalServiceBasicRt } from '../../../api'; +import { ExternalServiceRt } from '../../domain/external_service/v1'; import { CaseConnectorRt, ConnectorMappingsRt } from '../../domain/connector/v1'; -const ActionConnectorResultRt = rt.intersection([ - rt.strict({ - id: rt.string, - actionTypeId: rt.string, - name: rt.string, - isDeprecated: rt.boolean, - isPreconfigured: rt.boolean, - isSystemAction: rt.boolean, - referencedByCount: rt.number, - }), - rt.exact(rt.partial({ config: rt.record(rt.string, rt.unknown), isMissingSecrets: rt.boolean })), -]); - -export const FindActionConnectorResponseRt = rt.array(ActionConnectorResultRt); - const PushDetailsRt = rt.strict({ latestUserActionPushDate: rt.string, oldestUserActionPushDate: rt.string, - externalService: CaseExternalServiceBasicRt, + externalService: ExternalServiceRt, }); const CaseConnectorPushInfoRt = rt.intersection([ @@ -52,6 +37,21 @@ export const GetCaseConnectorsResponseRt = rt.record( ]) ); +const ActionConnectorResultRt = rt.intersection([ + rt.strict({ + id: rt.string, + actionTypeId: rt.string, + name: rt.string, + isDeprecated: rt.boolean, + isPreconfigured: rt.boolean, + isSystemAction: rt.boolean, + referencedByCount: rt.number, + }), + rt.exact(rt.partial({ config: rt.record(rt.string, rt.unknown), isMissingSecrets: rt.boolean })), +]); + +export const FindActionConnectorResponseRt = rt.array(ActionConnectorResultRt); + export const ConnectorMappingResponseRt = rt.strict({ id: rt.string, version: rt.string, diff --git a/x-pack/plugins/cases/common/types/api/external_service/latest.ts b/x-pack/plugins/cases/common/types/api/external_service/latest.ts new file mode 100644 index 00000000000000..25300c97a6d2e1 --- /dev/null +++ b/x-pack/plugins/cases/common/types/api/external_service/latest.ts @@ -0,0 +1,8 @@ +/* + * 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. + */ + +export * from './v1'; diff --git a/x-pack/plugins/cases/common/types/api/external_service/v1.test.ts b/x-pack/plugins/cases/common/types/api/external_service/v1.test.ts new file mode 100644 index 00000000000000..9287bb1e2ffbff --- /dev/null +++ b/x-pack/plugins/cases/common/types/api/external_service/v1.test.ts @@ -0,0 +1,54 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { ExternalServiceResponseRt } from './v1'; + +describe('ExternalServiceResponseRt', () => { + const defaultRequest = { + title: 'case_title', + id: 'basic-case-id', + pushedDate: '2020-02-19T23:06:33.798Z', + url: 'https://atlassian.com', + comments: [ + { + commentId: 'basic-comment-id', + pushedDate: '2020-02-19T23:06:33.798Z', + externalCommentId: 'external-comment-id', + }, + ], + }; + + it('has expected attributes in request', () => { + const query = ExternalServiceResponseRt.decode(defaultRequest); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: defaultRequest, + }); + }); + + it('removes foo:bar attributes from request', () => { + const query = ExternalServiceResponseRt.decode({ ...defaultRequest, foo: 'bar' }); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: defaultRequest, + }); + }); + + it('removes foo:bar attributes from comments', () => { + const query = ExternalServiceResponseRt.decode({ + ...defaultRequest, + comments: [{ ...defaultRequest.comments[0], foo: 'bar' }], + }); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: defaultRequest, + }); + }); +}); diff --git a/x-pack/plugins/cases/common/types/api/external_service/v1.ts b/x-pack/plugins/cases/common/types/api/external_service/v1.ts new file mode 100644 index 00000000000000..a9ff0b12e77fb0 --- /dev/null +++ b/x-pack/plugins/cases/common/types/api/external_service/v1.ts @@ -0,0 +1,32 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import * as rt from 'io-ts'; + +export const ExternalServiceResponseRt = rt.intersection([ + rt.strict({ + title: rt.string, + id: rt.string, + pushedDate: rt.string, + url: rt.string, + }), + rt.exact( + rt.partial({ + comments: rt.array( + rt.intersection([ + rt.strict({ + commentId: rt.string, + pushedDate: rt.string, + }), + rt.exact(rt.partial({ externalCommentId: rt.string })), + ]) + ), + }) + ), +]); + +export type ExternalServiceResponse = rt.TypeOf; diff --git a/x-pack/plugins/cases/common/types/api/index.ts b/x-pack/plugins/cases/common/types/api/index.ts index 2e504bbd84b4cd..3b4d36ec96198a 100644 --- a/x-pack/plugins/cases/common/types/api/index.ts +++ b/x-pack/plugins/cases/common/types/api/index.ts @@ -8,9 +8,21 @@ // Latest export * from './configure/latest'; export * from './user_action/latest'; +export * from './alert/latest'; +export * from './case/latest'; +export * from './external_service/latest'; +export * from './stats/latest'; +export * from './user/latest'; export * from './connector/latest'; +export * from './attachment/latest'; // V1 export * as configureApiV1 from './configure/v1'; export * as userActionApiV1 from './user_action/v1'; +export * as alertApiV1 from './alert/v1'; +export * as statsApiV1 from './stats/v1'; +export * as caseApiV1 from './case/v1'; +export * as externalServiceApiV1 from './external_service/v1'; +export * as userApiV1 from './user/v1'; export * as connectorApiV1 from './connector/v1'; +export * as attachmentApiV1 from './attachment/v1'; diff --git a/x-pack/plugins/cases/common/types/api/stats/latest.ts b/x-pack/plugins/cases/common/types/api/stats/latest.ts new file mode 100644 index 00000000000000..25300c97a6d2e1 --- /dev/null +++ b/x-pack/plugins/cases/common/types/api/stats/latest.ts @@ -0,0 +1,8 @@ +/* + * 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. + */ + +export * from './v1'; diff --git a/x-pack/plugins/cases/common/api/cases/status.ts b/x-pack/plugins/cases/common/types/api/stats/v1.ts similarity index 78% rename from x-pack/plugins/cases/common/api/cases/status.ts rename to x-pack/plugins/cases/common/types/api/stats/v1.ts index 76aefb7aba765c..002563258d889e 100644 --- a/x-pack/plugins/cases/common/api/cases/status.ts +++ b/x-pack/plugins/cases/common/types/api/stats/v1.ts @@ -6,17 +6,6 @@ */ import * as rt from 'io-ts'; -import { CaseStatuses } from '@kbn/cases-components/src/status/types'; - -export { CaseStatuses }; - -export const CaseStatusRt = rt.union([ - rt.literal(CaseStatuses.open), - rt.literal(CaseStatuses['in-progress']), - rt.literal(CaseStatuses.closed), -]); - -export const caseStatuses = Object.values(CaseStatuses); export const CasesStatusResponseRt = rt.strict({ count_open_cases: rt.number, diff --git a/x-pack/plugins/cases/common/types/api/user/latest.ts b/x-pack/plugins/cases/common/types/api/user/latest.ts new file mode 100644 index 00000000000000..25300c97a6d2e1 --- /dev/null +++ b/x-pack/plugins/cases/common/types/api/user/latest.ts @@ -0,0 +1,8 @@ +/* + * 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. + */ + +export * from './v1'; diff --git a/x-pack/plugins/cases/common/api/user.test.ts b/x-pack/plugins/cases/common/types/api/user/v1.test.ts similarity index 56% rename from x-pack/plugins/cases/common/api/user.test.ts rename to x-pack/plugins/cases/common/types/api/user/v1.test.ts index a24d9df98af9ea..552a7382737fe2 100644 --- a/x-pack/plugins/cases/common/api/user.test.ts +++ b/x-pack/plugins/cases/common/types/api/user/v1.test.ts @@ -5,137 +5,11 @@ * 2.0. */ -import { set } from 'lodash'; -import { UserRt, UserWithProfileInfoRt, UsersRt, GetCaseUsersResponseRt } from './user'; +import { MAX_SUGGESTED_PROFILES } from '../../../constants'; +import { PathReporter } from 'io-ts/lib/PathReporter'; +import { GetCaseUsersResponseRt, SuggestUserProfilesRequestRt } from './v1'; describe('User', () => { - describe('UserRt', () => { - const defaultRequest = { - full_name: 'elastic', - email: 'testemail@elastic.co', - username: 'elastic', - profile_uid: 'profile-uid-1', - }; - it('has expected attributes in request', () => { - const query = UserRt.decode(defaultRequest); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: defaultRequest, - }); - }); - - it('removes foo:bar attributes from request', () => { - const query = UserRt.decode({ - ...defaultRequest, - foo: 'bar', - }); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: defaultRequest, - }); - }); - }); - - describe('UserWithProfileInfoRt', () => { - const defaultRequest = { - uid: '1', - avatar: { - initials: 'SU', - color: 'red', - imageUrl: 'https://google.com/image1', - }, - user: { - username: 'user', - email: 'some.user@google.com', - full_name: 'Some Super User', - }, - }; - - it('has expected attributes in request', () => { - const query = UserWithProfileInfoRt.decode(defaultRequest); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: defaultRequest, - }); - }); - - it.each(['initials', 'color', 'imageUrl'])('does not returns an error if %s is null', (key) => { - const reqWithNullImage = set(defaultRequest, `avatar.${key}`, null); - const query = UserWithProfileInfoRt.decode(reqWithNullImage); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: reqWithNullImage, - }); - }); - - it('removes foo:bar attributes from request', () => { - const query = UserWithProfileInfoRt.decode({ - ...defaultRequest, - foo: 'bar', - }); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: defaultRequest, - }); - }); - - it('removes foo:bar attributes from avatar', () => { - const query = UserWithProfileInfoRt.decode({ - ...defaultRequest, - avatar: { ...defaultRequest.avatar, foo: 'bar' }, - }); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: defaultRequest, - }); - }); - }); - - describe('UsersRt', () => { - const defaultRequest = [ - { - email: 'reporter_no_uid@elastic.co', - full_name: 'Reporter No UID', - username: 'reporter_no_uid', - profile_uid: 'reporter-uid', - }, - { - full_name: 'elastic', - email: 'testemail@elastic.co', - username: 'elastic', - }, - ]; - - it('has expected attributes in request', () => { - const query = UsersRt.decode(defaultRequest); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: defaultRequest, - }); - }); - - it('removes foo:bar attributes from request', () => { - const query = UsersRt.decode([ - { - ...defaultRequest[0], - foo: 'bar', - }, - ]); - - expect(query).toStrictEqual({ - _tag: 'Right', - right: [defaultRequest[0]], - }); - }); - }); - describe('GetCaseUsersResponseRt', () => { const defaultRequest = { assignees: [ @@ -271,4 +145,89 @@ describe('User', () => { }); }); }); + + describe('UserProfile', () => { + describe('SuggestUserProfilesRequestRt', () => { + const defaultRequest = { + name: 'damaged_raccoon', + owners: ['cases'], + size: 5, + }; + + it('has expected attributes in request', () => { + const query = SuggestUserProfilesRequestRt.decode(defaultRequest); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: { + name: 'damaged_raccoon', + owners: ['cases'], + size: 5, + }, + }); + }); + + it('has only name and owner in request', () => { + const query = SuggestUserProfilesRequestRt.decode({ + name: 'damaged_raccoon', + owners: ['cases'], + foo: 'bar', + }); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: { + name: 'damaged_raccoon', + owners: ['cases'], + }, + }); + }); + + it('missing size parameter works correctly', () => { + const query = SuggestUserProfilesRequestRt.decode({ + name: 'di maria', + owners: ['benfica'], + }); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: { + name: 'di maria', + owners: ['benfica'], + }, + }); + }); + + it('removes foo:bar attributes from request', () => { + const query = SuggestUserProfilesRequestRt.decode({ ...defaultRequest, foo: 'bar' }); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: { + name: 'damaged_raccoon', + owners: ['cases'], + size: 5, + }, + }); + }); + + it(`does not accept size param bigger than ${MAX_SUGGESTED_PROFILES}`, () => { + const query = SuggestUserProfilesRequestRt.decode({ + ...defaultRequest, + size: MAX_SUGGESTED_PROFILES + 1, + }); + + expect(PathReporter.report(query)).toContain('The size field cannot be more than 10.'); + }); + + it('does not accept size param lower than 1', () => { + const query = SuggestUserProfilesRequestRt.decode({ + ...defaultRequest, + size: 0, + }); + + expect(PathReporter.report(query)).toContain('The size field cannot be less than 1.'); + }); + }); + }); }); diff --git a/x-pack/plugins/cases/common/api/cases/user_profiles.ts b/x-pack/plugins/cases/common/types/api/user/v1.ts similarity index 56% rename from x-pack/plugins/cases/common/api/cases/user_profiles.ts rename to x-pack/plugins/cases/common/types/api/user/v1.ts index 87117671206e7f..488bcbd91c5e38 100644 --- a/x-pack/plugins/cases/common/api/cases/user_profiles.ts +++ b/x-pack/plugins/cases/common/types/api/user/v1.ts @@ -6,9 +6,22 @@ */ import * as rt from 'io-ts'; -import { MAX_SUGGESTED_PROFILES } from '../../constants'; -import { limitedNumberSchema } from '../../schema'; +import { MAX_SUGGESTED_PROFILES } from '../../../constants'; +import { limitedNumberSchema } from '../../../schema'; +import { UserWithProfileInfoRt } from '../../domain/user/v1'; +export const GetCaseUsersResponseRt = rt.strict({ + assignees: rt.array(UserWithProfileInfoRt), + unassignedUsers: rt.array(UserWithProfileInfoRt), + participants: rt.array(UserWithProfileInfoRt), + reporter: UserWithProfileInfoRt, +}); + +export type GetCaseUsersResponse = rt.TypeOf; + +/** + * User Profiles + */ export const SuggestUserProfilesRequestRt = rt.intersection([ rt.strict({ name: rt.string, @@ -22,9 +35,3 @@ export const SuggestUserProfilesRequestRt = rt.intersection([ ]); export type SuggestUserProfilesRequest = rt.TypeOf; - -export const CaseUserProfileRt = rt.strict({ - uid: rt.string, -}); - -export type CaseUserProfile = rt.TypeOf; diff --git a/x-pack/plugins/cases/common/types/api/user_action/v1.test.ts b/x-pack/plugins/cases/common/types/api/user_action/v1.test.ts index 3c22746f10ffe1..c92ffa955467be 100644 --- a/x-pack/plugins/cases/common/types/api/user_action/v1.test.ts +++ b/x-pack/plugins/cases/common/types/api/user_action/v1.test.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { CommentType } from '../../../api'; +import { AttachmentType } from '../../domain/attachment/v1'; import { UserActionTypes } from '../../domain/user_action/action/v1'; import { CaseUserActionStatsResponseRt, @@ -59,7 +59,7 @@ describe('User actions APIs', () => { payload: { comment: { comment: 'this is a sample comment', - type: CommentType.user, + type: AttachmentType.user, owner: 'cases', }, }, diff --git a/x-pack/plugins/cases/common/types/domain/attachment/latest.ts b/x-pack/plugins/cases/common/types/domain/attachment/latest.ts new file mode 100644 index 00000000000000..25300c97a6d2e1 --- /dev/null +++ b/x-pack/plugins/cases/common/types/domain/attachment/latest.ts @@ -0,0 +1,8 @@ +/* + * 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. + */ + +export * from './v1'; diff --git a/x-pack/plugins/cases/common/types/domain/attachment/v1.test.ts b/x-pack/plugins/cases/common/types/domain/attachment/v1.test.ts new file mode 100644 index 00000000000000..8a193d88b506c2 --- /dev/null +++ b/x-pack/plugins/cases/common/types/domain/attachment/v1.test.ts @@ -0,0 +1,680 @@ +/* + * 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 { + AttachmentAttributesBasicRt, + FileAttachmentMetadataRt, + SingleFileAttachmentMetadataRt, + AttachmentType, + UserCommentAttachmentPayloadRt, + AlertAttachmentPayloadRt, + ActionsAttachmentPayloadRt, + ExternalReferenceStorageType, + ExternalReferenceAttachmentPayloadRt, + PersistableStateAttachmentPayloadRt, + AttachmentRt, + UserCommentAttachmentRt, + AlertAttachmentRt, + ActionsAttachmentRt, + ExternalReferenceAttachmentRt, + PersistableStateAttachmentRt, + AttachmentPatchAttributesRt, +} from './v1'; + +describe('Attachments', () => { + describe('Files', () => { + describe('SingleFileAttachmentMetadataRt', () => { + const defaultRequest = { + created: '2020-02-19T23:06:33.798Z', + extension: 'png', + mimeType: 'image/png', + name: 'my-super-cool-screenshot', + }; + + it('has expected attributes in request', () => { + const query = SingleFileAttachmentMetadataRt.decode(defaultRequest); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: defaultRequest, + }); + }); + + it('removes foo:bar attributes from request', () => { + const query = SingleFileAttachmentMetadataRt.decode({ ...defaultRequest, foo: 'bar' }); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: defaultRequest, + }); + }); + }); + + describe('FileAttachmentMetadataRt', () => { + const defaultRequest = { + created: '2020-02-19T23:06:33.798Z', + extension: 'png', + mimeType: 'image/png', + name: 'my-super-cool-screenshot', + }; + + it('has expected attributes in request', () => { + const query = FileAttachmentMetadataRt.decode({ files: [defaultRequest] }); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: { + files: [ + { + ...defaultRequest, + }, + ], + }, + }); + }); + + it('removes foo:bar attributes from request', () => { + const query = FileAttachmentMetadataRt.decode({ + files: [{ ...defaultRequest, foo: 'bar' }], + }); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: { + files: [ + { + ...defaultRequest, + }, + ], + }, + }); + }); + }); + }); + + describe('AttachmentAttributesBasicRt', () => { + const defaultRequest = { + created_at: '2019-11-25T22:32:30.608Z', + created_by: { + full_name: 'elastic', + email: 'testemail@elastic.co', + username: 'elastic', + }, + owner: 'cases', + updated_at: null, + updated_by: null, + pushed_at: null, + pushed_by: null, + }; + + it('has expected attributes in request', () => { + const query = AttachmentAttributesBasicRt.decode(defaultRequest); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: defaultRequest, + }); + }); + + it('removes foo:bar attributes from request', () => { + const query = AttachmentAttributesBasicRt.decode({ ...defaultRequest, foo: 'bar' }); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: defaultRequest, + }); + }); + }); + + describe('UserCommentAttachmentPayloadRt', () => { + const defaultRequest = { + comment: 'This is a sample comment', + type: AttachmentType.user, + owner: 'cases', + }; + + it('has expected attributes in request', () => { + const query = UserCommentAttachmentPayloadRt.decode(defaultRequest); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: defaultRequest, + }); + }); + + it('removes foo:bar attributes from request', () => { + const query = UserCommentAttachmentPayloadRt.decode({ ...defaultRequest, foo: 'bar' }); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: defaultRequest, + }); + }); + }); + + describe('AlertAttachmentPayloadRt', () => { + const defaultRequest = { + alertId: 'alert-id-1', + index: 'alert-index-1', + type: AttachmentType.alert, + owner: 'cases', + rule: { + id: 'rule-id-1', + name: 'Awesome rule', + }, + }; + + it('has expected attributes in request', () => { + const query = AlertAttachmentPayloadRt.decode(defaultRequest); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: defaultRequest, + }); + }); + + it('removes foo:bar attributes from request', () => { + const query = AlertAttachmentPayloadRt.decode({ ...defaultRequest, foo: 'bar' }); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: defaultRequest, + }); + }); + + it('removes foo:bar attributes from rule', () => { + const query = AlertAttachmentPayloadRt.decode({ + ...defaultRequest, + rule: { id: 'rule-id-1', name: 'Awesome rule', foo: 'bar' }, + }); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: defaultRequest, + }); + }); + }); + + describe('ActionsAttachmentPayloadRt', () => { + const defaultRequest = { + type: AttachmentType.actions, + comment: 'I just isolated the host!', + actions: { + targets: [ + { + hostname: 'host1', + endpointId: '001', + }, + ], + type: 'isolate', + }, + owner: 'cases', + }; + + it('has expected attributes in request', () => { + const query = ActionsAttachmentPayloadRt.decode(defaultRequest); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: defaultRequest, + }); + }); + + it('removes foo:bar attributes from request', () => { + const query = ActionsAttachmentPayloadRt.decode({ ...defaultRequest, foo: 'bar' }); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: defaultRequest, + }); + }); + + it('removes foo:bar attributes from actions', () => { + const query = ActionsAttachmentPayloadRt.decode({ + ...defaultRequest, + actions: { + targets: [ + { + hostname: 'host1', + endpointId: '001', + }, + ], + type: 'isolate', + foo: 'bar', + }, + }); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: defaultRequest, + }); + }); + + it('removes foo:bar attributes from targets', () => { + const query = ActionsAttachmentPayloadRt.decode({ + ...defaultRequest, + actions: { + targets: [ + { + hostname: 'host1', + endpointId: '001', + foo: 'bar', + }, + ], + type: 'isolate', + }, + }); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: defaultRequest, + }); + }); + }); + + describe('ExternalReferenceAttachmentPayloadRt', () => { + const defaultRequest = { + type: AttachmentType.externalReference, + externalReferenceId: 'my-id', + externalReferenceStorage: { type: ExternalReferenceStorageType.elasticSearchDoc }, + externalReferenceAttachmentTypeId: '.test', + externalReferenceMetadata: { test_foo: 'foo' }, + owner: 'cases', + }; + it('has expected attributes in request', () => { + const query = ExternalReferenceAttachmentPayloadRt.decode(defaultRequest); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: defaultRequest, + }); + }); + + it('removes foo:bar attributes from request', () => { + const query = ExternalReferenceAttachmentPayloadRt.decode({ ...defaultRequest, foo: 'bar' }); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: defaultRequest, + }); + }); + + it('removes foo:bar attributes from externalReferenceStorage', () => { + const query = ExternalReferenceAttachmentPayloadRt.decode({ + ...defaultRequest, + externalReferenceStorage: { + type: ExternalReferenceStorageType.elasticSearchDoc, + foo: 'bar', + }, + }); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: defaultRequest, + }); + }); + + it('removes foo:bar attributes from externalReferenceStorage with soType', () => { + const query = ExternalReferenceAttachmentPayloadRt.decode({ + ...defaultRequest, + externalReferenceStorage: { + type: ExternalReferenceStorageType.savedObject, + soType: 'awesome', + foo: 'bar', + }, + }); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: { + ...defaultRequest, + externalReferenceStorage: { + type: ExternalReferenceStorageType.savedObject, + soType: 'awesome', + }, + }, + }); + }); + }); + + describe('PersistableStateAttachmentPayloadRt', () => { + const defaultRequest = { + type: AttachmentType.persistableState, + persistableStateAttachmentState: { test_foo: 'foo' }, + persistableStateAttachmentTypeId: '.test', + owner: 'cases', + }; + it('has expected attributes in request', () => { + const query = PersistableStateAttachmentPayloadRt.decode(defaultRequest); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: defaultRequest, + }); + }); + + it('removes foo:bar attributes from request', () => { + const query = PersistableStateAttachmentPayloadRt.decode({ ...defaultRequest, foo: 'bar' }); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: defaultRequest, + }); + }); + + it('removes foo:bar attributes from persistableStateAttachmentState', () => { + const query = PersistableStateAttachmentPayloadRt.decode({ + ...defaultRequest, + persistableStateAttachmentState: { test_foo: 'foo', foo: 'bar' }, + }); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: { + ...defaultRequest, + persistableStateAttachmentState: { test_foo: 'foo', foo: 'bar' }, + }, + }); + }); + }); + + describe('AttachmentRt', () => { + const defaultRequest = { + comment: 'Solve this fast!', + type: AttachmentType.user, + owner: 'cases', + id: 'basic-comment-id', + version: 'WzQ3LDFc', + created_at: '2020-02-19T23:06:33.798Z', + created_by: { + full_name: 'Leslie Knope', + username: 'lknope', + email: 'leslie.knope@elastic.co', + }, + pushed_at: null, + pushed_by: null, + updated_at: null, + updated_by: null, + }; + it('has expected attributes in request', () => { + const query = AttachmentRt.decode(defaultRequest); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: defaultRequest, + }); + }); + + it('removes foo:bar attributes from request', () => { + const query = AttachmentRt.decode({ ...defaultRequest, foo: 'bar' }); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: defaultRequest, + }); + }); + }); + + describe('UserCommentAttachmentRt', () => { + const defaultRequest = { + comment: 'Solve this fast!', + type: AttachmentType.user, + owner: 'cases', + id: 'basic-comment-id', + version: 'WzQ3LDFc', + created_at: '2020-02-19T23:06:33.798Z', + created_by: { + full_name: 'Leslie Knope', + username: 'lknope', + email: 'leslie.knope@elastic.co', + }, + pushed_at: null, + pushed_by: null, + updated_at: null, + updated_by: null, + }; + it('has expected attributes in request', () => { + const query = UserCommentAttachmentRt.decode(defaultRequest); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: defaultRequest, + }); + }); + + it('removes foo:bar attributes from request', () => { + const query = UserCommentAttachmentRt.decode({ ...defaultRequest, foo: 'bar' }); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: defaultRequest, + }); + }); + }); + + describe('AlertAttachmentRt', () => { + const defaultRequest = { + alertId: 'alert-id-1', + index: 'alert-index-1', + type: AttachmentType.alert, + id: 'alert-comment-id', + owner: 'cases', + rule: { + id: 'rule-id-1', + name: 'Awesome rule', + }, + version: 'WzQ3LDFc', + created_at: '2020-02-19T23:06:33.798Z', + created_by: { + full_name: 'Leslie Knope', + username: 'lknope', + email: 'leslie.knope@elastic.co', + }, + pushed_at: null, + pushed_by: null, + updated_at: null, + updated_by: null, + }; + it('has expected attributes in request', () => { + const query = AlertAttachmentRt.decode(defaultRequest); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: defaultRequest, + }); + }); + + it('removes foo:bar attributes from request', () => { + const query = AlertAttachmentRt.decode({ ...defaultRequest, foo: 'bar' }); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: defaultRequest, + }); + }); + + it('removes foo:bar attributes from created_by', () => { + const query = AlertAttachmentRt.decode({ + ...defaultRequest, + created_by: { + full_name: 'Leslie Knope', + username: 'lknope', + email: 'leslie.knope@elastic.co', + foo: 'bar', + }, + }); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: defaultRequest, + }); + }); + }); + + describe('ActionsAttachmentRt', () => { + const defaultRequest = { + type: AttachmentType.actions, + comment: 'I just isolated the host!', + actions: { + targets: [ + { + hostname: 'host1', + endpointId: '001', + }, + ], + type: 'isolate', + }, + owner: 'cases', + id: 'basic-comment-id', + version: 'WzQ3LDFc', + created_at: '2020-02-19T23:06:33.798Z', + created_by: { + full_name: 'Leslie Knope', + username: 'lknope', + email: 'leslie.knope@elastic.co', + }, + pushed_at: null, + pushed_by: null, + updated_at: null, + updated_by: null, + }; + it('has expected attributes in request', () => { + const query = ActionsAttachmentRt.decode(defaultRequest); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: defaultRequest, + }); + }); + + it('removes foo:bar attributes from request', () => { + const query = ActionsAttachmentRt.decode({ ...defaultRequest, foo: 'bar' }); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: defaultRequest, + }); + }); + }); + + describe('ExternalReferenceAttachmentRt', () => { + const defaultRequest = { + type: AttachmentType.externalReference, + externalReferenceId: 'my-id', + externalReferenceStorage: { type: ExternalReferenceStorageType.elasticSearchDoc }, + externalReferenceAttachmentTypeId: '.test', + externalReferenceMetadata: { test_foo: 'foo' }, + owner: 'cases', + id: 'basic-comment-id', + version: 'WzQ3LDFc', + created_at: '2020-02-19T23:06:33.798Z', + created_by: { + full_name: 'Leslie Knope', + username: 'lknope', + email: 'leslie.knope@elastic.co', + }, + pushed_at: null, + pushed_by: null, + updated_at: null, + updated_by: null, + }; + it('has expected attributes in request', () => { + const query = ExternalReferenceAttachmentRt.decode(defaultRequest); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: defaultRequest, + }); + }); + + it('removes foo:bar attributes from request', () => { + const query = ExternalReferenceAttachmentRt.decode({ + ...defaultRequest, + foo: 'bar', + }); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: defaultRequest, + }); + }); + }); + + describe('PersistableStateAttachmentRt', () => { + const defaultRequest = { + type: AttachmentType.persistableState, + persistableStateAttachmentState: { test_foo: 'foo' }, + persistableStateAttachmentTypeId: '.test', + owner: 'cases', + id: 'basic-comment-id', + version: 'WzQ3LDFc', + created_at: '2020-02-19T23:06:33.798Z', + created_by: { + full_name: 'Leslie Knope', + username: 'lknope', + email: 'leslie.knope@elastic.co', + }, + pushed_at: null, + pushed_by: null, + updated_at: null, + updated_by: null, + }; + it('has expected attributes in request', () => { + const query = PersistableStateAttachmentRt.decode(defaultRequest); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: defaultRequest, + }); + }); + + it('removes foo:bar attributes from request', () => { + const query = PersistableStateAttachmentRt.decode({ + ...defaultRequest, + foo: 'bar', + }); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: defaultRequest, + }); + }); + }); + + describe('AttachmentPatchAttributesRt', () => { + const defaultRequest = { + type: AttachmentType.actions, + actions: { + targets: [ + { + hostname: 'host1', + endpointId: '001', + }, + ], + type: 'isolate', + }, + owner: 'cases', + }; + it('has expected attributes in request', () => { + const query = AttachmentPatchAttributesRt.decode(defaultRequest); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: defaultRequest, + }); + }); + + it('removes foo:bar attributes from request', () => { + const query = AttachmentPatchAttributesRt.decode({ ...defaultRequest, foo: 'bar' }); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: defaultRequest, + }); + }); + }); +}); diff --git a/x-pack/plugins/cases/common/types/domain/attachment/v1.ts b/x-pack/plugins/cases/common/types/domain/attachment/v1.ts new file mode 100644 index 00000000000000..df6193bd3ae36c --- /dev/null +++ b/x-pack/plugins/cases/common/types/domain/attachment/v1.ts @@ -0,0 +1,348 @@ +/* + * 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 * as rt from 'io-ts'; +import { jsonValueRt } from '../../../api'; +import { UserRt } from '../user/v1'; + +/** + * Files + */ +export const SingleFileAttachmentMetadataRt = rt.strict({ + name: rt.string, + extension: rt.string, + mimeType: rt.string, + created: rt.string, +}); + +export const FileAttachmentMetadataRt = rt.strict({ + files: rt.array(SingleFileAttachmentMetadataRt), +}); + +export type FileAttachmentMetadata = rt.TypeOf; + +export const AttachmentAttributesBasicRt = rt.strict({ + created_at: rt.string, + created_by: UserRt, + owner: rt.string, + pushed_at: rt.union([rt.string, rt.null]), + pushed_by: rt.union([UserRt, rt.null]), + updated_at: rt.union([rt.string, rt.null]), + updated_by: rt.union([UserRt, rt.null]), +}); + +/** + * User comment + */ + +export enum AttachmentType { + user = 'user', + alert = 'alert', + actions = 'actions', + externalReference = 'externalReference', + persistableState = 'persistableState', +} + +export const UserCommentAttachmentPayloadRt = rt.strict({ + comment: rt.string, + type: rt.literal(AttachmentType.user), + owner: rt.string, +}); + +const UserCommentAttachmentAttributesRt = rt.intersection([ + UserCommentAttachmentPayloadRt, + AttachmentAttributesBasicRt, +]); + +export const UserCommentAttachmentRt = rt.intersection([ + UserCommentAttachmentAttributesRt, + rt.strict({ + id: rt.string, + version: rt.string, + }), +]); + +export type UserCommentAttachmentPayload = rt.TypeOf; +export type UserCommentAttachmentAttributes = rt.TypeOf; +export type UserCommentAttachment = rt.TypeOf; + +/** + * Alerts + */ + +export const AlertAttachmentPayloadRt = rt.strict({ + type: rt.literal(AttachmentType.alert), + alertId: rt.union([rt.array(rt.string), rt.string]), + index: rt.union([rt.array(rt.string), rt.string]), + rule: rt.strict({ + id: rt.union([rt.string, rt.null]), + name: rt.union([rt.string, rt.null]), + }), + owner: rt.string, +}); + +export const AlertAttachmentAttributesRt = rt.intersection([ + AlertAttachmentPayloadRt, + AttachmentAttributesBasicRt, +]); + +export const AlertAttachmentRt = rt.intersection([ + AlertAttachmentAttributesRt, + rt.strict({ + id: rt.string, + version: rt.string, + }), +]); + +export type AlertAttachmentPayload = rt.TypeOf; +export type AlertAttachmentAttributes = rt.TypeOf; +export type AlertAttachment = rt.TypeOf; + +/** + * Actions + */ + +export enum IsolateHostActionType { + isolate = 'isolate', + unisolate = 'unisolate', +} + +export const ActionsAttachmentPayloadRt = rt.strict({ + type: rt.literal(AttachmentType.actions), + comment: rt.string, + actions: rt.strict({ + targets: rt.array( + rt.strict({ + hostname: rt.string, + endpointId: rt.string, + }) + ), + type: rt.string, + }), + owner: rt.string, +}); + +const ActionsAttachmentAttributesRt = rt.intersection([ + ActionsAttachmentPayloadRt, + AttachmentAttributesBasicRt, +]); + +export const ActionsAttachmentRt = rt.intersection([ + ActionsAttachmentAttributesRt, + rt.strict({ + id: rt.string, + version: rt.string, + }), +]); + +export type ActionsAttachmentPayload = rt.TypeOf; +export type ActionsAttachmentAttributes = rt.TypeOf; +export type ActionsAttachment = rt.TypeOf; + +/** + * External reference + */ + +export enum ExternalReferenceStorageType { + savedObject = 'savedObject', + elasticSearchDoc = 'elasticSearchDoc', +} + +const ExternalReferenceStorageNoSORt = rt.strict({ + type: rt.literal(ExternalReferenceStorageType.elasticSearchDoc), +}); + +const ExternalReferenceStorageSORt = rt.strict({ + type: rt.literal(ExternalReferenceStorageType.savedObject), + soType: rt.string, +}); + +const ExternalReferenceBaseAttachmentPayloadRt = rt.strict({ + externalReferenceAttachmentTypeId: rt.string, + externalReferenceMetadata: rt.union([rt.null, rt.record(rt.string, jsonValueRt)]), + type: rt.literal(AttachmentType.externalReference), + owner: rt.string, +}); + +export const ExternalReferenceNoSOAttachmentPayloadRt = rt.strict({ + ...ExternalReferenceBaseAttachmentPayloadRt.type.props, + externalReferenceId: rt.string, + externalReferenceStorage: ExternalReferenceStorageNoSORt, +}); + +export const ExternalReferenceSOAttachmentPayloadRt = rt.strict({ + ...ExternalReferenceBaseAttachmentPayloadRt.type.props, + externalReferenceId: rt.string, + externalReferenceStorage: ExternalReferenceStorageSORt, +}); + +// externalReferenceId is missing. +export const ExternalReferenceSOWithoutRefsAttachmentPayloadRt = rt.strict({ + ...ExternalReferenceBaseAttachmentPayloadRt.type.props, + externalReferenceStorage: ExternalReferenceStorageSORt, +}); + +export const ExternalReferenceAttachmentPayloadRt = rt.union([ + ExternalReferenceNoSOAttachmentPayloadRt, + ExternalReferenceSOAttachmentPayloadRt, +]); + +export const ExternalReferenceWithoutRefsAttachmentPayloadRt = rt.union([ + ExternalReferenceNoSOAttachmentPayloadRt, + ExternalReferenceSOWithoutRefsAttachmentPayloadRt, +]); + +const ExternalReferenceAttachmentAttributesRt = rt.intersection([ + ExternalReferenceAttachmentPayloadRt, + AttachmentAttributesBasicRt, +]); + +const ExternalReferenceWithoutRefsAttachmentAttributesRt = rt.intersection([ + ExternalReferenceWithoutRefsAttachmentPayloadRt, + AttachmentAttributesBasicRt, +]); + +const ExternalReferenceNoSOAttachmentAttributesRt = rt.intersection([ + ExternalReferenceNoSOAttachmentPayloadRt, + AttachmentAttributesBasicRt, +]); + +const ExternalReferenceSOAttachmentAttributesRt = rt.intersection([ + ExternalReferenceSOAttachmentPayloadRt, + AttachmentAttributesBasicRt, +]); + +export const ExternalReferenceAttachmentRt = rt.intersection([ + ExternalReferenceAttachmentAttributesRt, + rt.strict({ + id: rt.string, + version: rt.string, + }), +]); + +export type ExternalReferenceAttachmentPayload = rt.TypeOf< + typeof ExternalReferenceAttachmentPayloadRt +>; + +export type ExternalReferenceSOAttachmentPayload = rt.TypeOf< + typeof ExternalReferenceSOAttachmentPayloadRt +>; +export type ExternalReferenceNoSOAttachmentPayload = rt.TypeOf< + typeof ExternalReferenceNoSOAttachmentPayloadRt +>; + +export type ExternalReferenceAttachmentAttributes = rt.TypeOf< + typeof ExternalReferenceAttachmentAttributesRt +>; + +export type ExternalReferenceSOAttachmentAttributes = rt.TypeOf< + typeof ExternalReferenceSOAttachmentAttributesRt +>; + +export type ExternalReferenceNoSOAttachmentAttributes = rt.TypeOf< + typeof ExternalReferenceNoSOAttachmentAttributesRt +>; + +export type ExternalReferenceWithoutRefsAttachmentPayload = rt.TypeOf< + typeof ExternalReferenceWithoutRefsAttachmentPayloadRt +>; +export type ExternalReferenceAttachment = rt.TypeOf; + +/** + * Persistable state + */ + +export const PersistableStateAttachmentPayloadRt = rt.strict({ + type: rt.literal(AttachmentType.persistableState), + owner: rt.string, + persistableStateAttachmentTypeId: rt.string, + persistableStateAttachmentState: rt.record(rt.string, jsonValueRt), +}); + +const PersistableStateAttachmentAttributesRt = rt.intersection([ + PersistableStateAttachmentPayloadRt, + AttachmentAttributesBasicRt, +]); + +export const PersistableStateAttachmentRt = rt.intersection([ + PersistableStateAttachmentAttributesRt, + rt.strict({ + id: rt.string, + version: rt.string, + }), +]); + +export type PersistableStateAttachmentPayload = rt.TypeOf< + typeof PersistableStateAttachmentPayloadRt +>; +export type PersistableStateAttachment = rt.TypeOf; +export type PersistableStateAttachmentAttributes = rt.TypeOf< + typeof PersistableStateAttachmentAttributesRt +>; + +/** + * Common + */ + +export const AttachmentAttributesRt = rt.union([ + UserCommentAttachmentAttributesRt, + AlertAttachmentAttributesRt, + ActionsAttachmentAttributesRt, + ExternalReferenceAttachmentAttributesRt, + PersistableStateAttachmentAttributesRt, +]); + +const AttachmentAttributesNoSORt = rt.union([ + UserCommentAttachmentAttributesRt, + AlertAttachmentAttributesRt, + ActionsAttachmentAttributesRt, + ExternalReferenceNoSOAttachmentAttributesRt, + PersistableStateAttachmentAttributesRt, +]); + +const AttachmentAttributesWithoutRefsRt = rt.union([ + UserCommentAttachmentAttributesRt, + AlertAttachmentAttributesRt, + ActionsAttachmentAttributesRt, + ExternalReferenceWithoutRefsAttachmentAttributesRt, + PersistableStateAttachmentAttributesRt, +]); + +export const AttachmentRt = rt.intersection([ + AttachmentAttributesRt, + rt.strict({ + id: rt.string, + version: rt.string, + }), +]); + +export const AttachmentsRt = rt.array(AttachmentRt); + +/** + * This type is used by the CaseService. + * Because the type for the attributes of savedObjectClient update function is Partial + * we need to make all of our attributes partial too. + * We ensure that partial updates of CommentContext is not going to happen inside the patch comment route. + */ +export const AttachmentPatchAttributesRt = rt.intersection([ + rt.union([ + rt.exact(rt.partial(UserCommentAttachmentPayloadRt.type.props)), + rt.exact(rt.partial(AlertAttachmentPayloadRt.type.props)), + rt.exact(rt.partial(ActionsAttachmentPayloadRt.type.props)), + rt.exact(rt.partial(ExternalReferenceNoSOAttachmentPayloadRt.type.props)), + rt.exact(rt.partial(ExternalReferenceSOAttachmentPayloadRt.type.props)), + rt.exact(rt.partial(PersistableStateAttachmentPayloadRt.type.props)), + ]), + rt.exact(rt.partial(AttachmentAttributesBasicRt.type.props)), +]); + +export type AttachmentAttributes = rt.TypeOf; +export type AttachmentAttributesNoSO = rt.TypeOf; +export type AttachmentAttributesWithoutRefs = rt.TypeOf; +export type AttachmentPatchAttributes = rt.TypeOf; +export type Attachment = rt.TypeOf; +export type Attachments = rt.TypeOf; diff --git a/x-pack/plugins/cases/common/types/domain/case/latest.ts b/x-pack/plugins/cases/common/types/domain/case/latest.ts new file mode 100644 index 00000000000000..25300c97a6d2e1 --- /dev/null +++ b/x-pack/plugins/cases/common/types/domain/case/latest.ts @@ -0,0 +1,8 @@ +/* + * 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. + */ + +export * from './v1'; diff --git a/x-pack/plugins/cases/common/types/domain/case/v1.test.ts b/x-pack/plugins/cases/common/types/domain/case/v1.test.ts new file mode 100644 index 00000000000000..ba04082519c8c3 --- /dev/null +++ b/x-pack/plugins/cases/common/types/domain/case/v1.test.ts @@ -0,0 +1,242 @@ +/* + * 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 { AttachmentType } from '../attachment/v1'; +import { ConnectorTypes } from '../connector/v1'; +import { + CaseAttributesRt, + CaseSettingsRt, + CaseSeverity, + CasesRt, + CaseStatuses, + RelatedCaseRt, +} from './v1'; + +const basicCase = { + owner: 'cases', + closed_at: null, + closed_by: null, + id: 'basic-case-id', + comments: [ + { + comment: 'Solve this fast!', + type: AttachmentType.user, + id: 'basic-comment-id', + created_at: '2020-02-19T23:06:33.798Z', + created_by: { + full_name: 'Leslie Knope', + username: 'lknope', + email: 'leslie.knope@elastic.co', + }, + owner: 'cases', + pushed_at: null, + pushed_by: null, + updated_at: null, + updated_by: null, + version: 'WzQ3LDFc', + }, + ], + created_at: '2020-02-19T23:06:33.798Z', + created_by: { + full_name: 'Leslie Knope', + username: 'lknope', + email: 'leslie.knope@elastic.co', + }, + connector: { + id: 'none', + name: 'My Connector', + type: ConnectorTypes.none, + fields: null, + }, + description: 'Security banana Issue', + severity: CaseSeverity.LOW, + duration: null, + external_service: null, + status: CaseStatuses.open, + tags: ['coke', 'pepsi'], + title: 'Another horrible breach!!', + totalComment: 1, + totalAlerts: 0, + updated_at: '2020-02-20T15:02:57.995Z', + updated_by: { + full_name: 'Leslie Knope', + username: 'lknope', + email: 'leslie.knope@elastic.co', + }, + version: 'WzQ3LDFd', + settings: { + syncAlerts: true, + }, + // damaged_raccoon uid + assignees: [{ uid: 'u_J41Oh6L9ki-Vo2tOogS8WRTENzhHurGtRc87NgEAlkc_0' }], + category: null, +}; + +describe('RelatedCaseRt', () => { + const defaultRequest = { + id: 'basic-case-id', + title: 'basic-case-title', + description: 'this is a simple description', + status: CaseStatuses.open, + createdAt: '2023-01-17T09:46:29.813Z', + totals: { + alerts: 5, + userComments: 2, + }, + }; + it('has expected attributes in request', () => { + const query = RelatedCaseRt.decode(defaultRequest); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: defaultRequest, + }); + }); + + it('removes foo:bar attributes from request', () => { + const query = RelatedCaseRt.decode({ ...defaultRequest, foo: 'bar' }); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: defaultRequest, + }); + }); + + it('removes foo:bar attributes from totals', () => { + const query = RelatedCaseRt.decode({ + ...defaultRequest, + totals: { ...defaultRequest.totals, foo: 'bar' }, + }); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: defaultRequest, + }); + }); +}); + +describe('SettingsRt', () => { + it('has expected attributes in request', () => { + const query = CaseSettingsRt.decode({ syncAlerts: true }); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: { syncAlerts: true }, + }); + }); + + it('removes foo:bar attributes from request', () => { + const query = CaseSettingsRt.decode({ syncAlerts: false, foo: 'bar' }); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: { syncAlerts: false }, + }); + }); +}); + +describe('CaseAttributesRt', () => { + const defaultRequest = { + description: 'A description', + status: CaseStatuses.open, + tags: ['new', 'case'], + title: 'My new case', + connector: { + id: '123', + name: 'My connector', + type: ConnectorTypes.jira, + fields: { issueType: 'Task', priority: 'High', parent: null }, + }, + settings: { + syncAlerts: true, + }, + owner: 'cases', + severity: CaseSeverity.LOW, + assignees: [{ uid: 'u_J41Oh6L9ki-Vo2tOogS8WRTENzhHurGtRc87NgEAlkc_0' }], + duration: null, + closed_at: null, + closed_by: null, + created_at: '2020-02-19T23:06:33.798Z', + created_by: { + full_name: 'Leslie Knope', + username: 'lknope', + email: 'leslie.knope@elastic.co', + }, + external_service: null, + updated_at: '2020-02-20T15:02:57.995Z', + updated_by: null, + category: null, + }; + + it('has expected attributes in request', () => { + const query = CaseAttributesRt.decode(defaultRequest); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: defaultRequest, + }); + }); + + it('removes foo:bar attributes from request', () => { + const query = CaseAttributesRt.decode({ ...defaultRequest, foo: 'bar' }); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: defaultRequest, + }); + }); + + it('removes foo:bar attributes from connector', () => { + const query = CaseAttributesRt.decode({ + ...defaultRequest, + connector: { ...defaultRequest.connector, foo: 'bar' }, + }); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: defaultRequest, + }); + }); + + it('removes foo:bar attributes from created_by', () => { + const query = CaseAttributesRt.decode({ + ...defaultRequest, + created_by: { ...defaultRequest.created_by, foo: 'bar' }, + }); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: defaultRequest, + }); + }); +}); + +describe('CasesRt', () => { + const defaultRequest = [ + { + ...basicCase, + }, + ]; + + it('has expected attributes in request', () => { + const query = CasesRt.decode(defaultRequest); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: defaultRequest, + }); + }); + + it('removes foo:bar attributes from request', () => { + const query = CasesRt.decode([{ ...defaultRequest[0], foo: 'bar' }]); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: defaultRequest, + }); + }); +}); diff --git a/x-pack/plugins/cases/common/types/domain/case/v1.ts b/x-pack/plugins/cases/common/types/domain/case/v1.ts new file mode 100644 index 00000000000000..e4e16b7fb33a76 --- /dev/null +++ b/x-pack/plugins/cases/common/types/domain/case/v1.ts @@ -0,0 +1,147 @@ +/* + * 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 * as rt from 'io-ts'; +import { CaseStatuses } from '@kbn/cases-components/src/status/types'; +import { ExternalServiceRt } from '../external_service/v1'; +import { CaseAssigneesRt, UserRt } from '../user/v1'; +import { CaseConnectorRt } from '../connector/v1'; +import { AttachmentRt } from '../attachment/v1'; + +export { CaseStatuses }; + +/** + * Status + */ +export const CaseStatusRt = rt.union([ + rt.literal(CaseStatuses.open), + rt.literal(CaseStatuses['in-progress']), + rt.literal(CaseStatuses.closed), +]); + +export const caseStatuses = Object.values(CaseStatuses); + +/** + * Severity + */ + +export enum CaseSeverity { + LOW = 'low', + MEDIUM = 'medium', + HIGH = 'high', + CRITICAL = 'critical', +} + +export const CaseSeverityRt = rt.union([ + rt.literal(CaseSeverity.LOW), + rt.literal(CaseSeverity.MEDIUM), + rt.literal(CaseSeverity.HIGH), + rt.literal(CaseSeverity.CRITICAL), +]); + +/** + * Case + */ + +export const CaseSettingsRt = rt.strict({ + syncAlerts: rt.boolean, +}); + +const CaseBasicRt = rt.strict({ + /** + * The description of the case + */ + description: rt.string, + /** + * The current status of the case (open, closed, in-progress) + */ + status: CaseStatusRt, + /** + * The identifying strings for filter a case + */ + tags: rt.array(rt.string), + /** + * The title of a case + */ + title: rt.string, + /** + * The external system that the case can be synced with + */ + connector: CaseConnectorRt, + /** + * The alert sync settings + */ + settings: CaseSettingsRt, + /** + * The plugin owner of the case + */ + owner: rt.string, + /** + * The severity of the case + */ + severity: CaseSeverityRt, + /** + * The users assigned to this case + */ + assignees: CaseAssigneesRt, + /** + * The category of the case. + */ + category: rt.union([rt.string, rt.null]), +}); + +export const CaseAttributesRt = rt.intersection([ + CaseBasicRt, + rt.strict({ + duration: rt.union([rt.number, rt.null]), + closed_at: rt.union([rt.string, rt.null]), + closed_by: rt.union([UserRt, rt.null]), + created_at: rt.string, + created_by: UserRt, + external_service: rt.union([ExternalServiceRt, rt.null]), + updated_at: rt.union([rt.string, rt.null]), + updated_by: rt.union([UserRt, rt.null]), + }), +]); + +export const CaseRt = rt.intersection([ + CaseAttributesRt, + rt.strict({ + id: rt.string, + totalComment: rt.number, + totalAlerts: rt.number, + version: rt.string, + }), + rt.exact( + rt.partial({ + comments: rt.array(AttachmentRt), + }) + ), +]); + +export const CasesRt = rt.array(CaseRt); + +export const AttachmentTotalsRt = rt.strict({ + alerts: rt.number, + userComments: rt.number, +}); + +export const RelatedCaseRt = rt.strict({ + id: rt.string, + title: rt.string, + description: rt.string, + status: CaseStatusRt, + createdAt: rt.string, + totals: AttachmentTotalsRt, +}); + +export type Case = rt.TypeOf; +export type Cases = rt.TypeOf; +export type CaseAttributes = rt.TypeOf; +export type CaseSettings = rt.TypeOf; +export type RelatedCase = rt.TypeOf; +export type AttachmentTotals = rt.TypeOf; diff --git a/x-pack/plugins/cases/common/types/domain/configure/v1.ts b/x-pack/plugins/cases/common/types/domain/configure/v1.ts index a93480e282c42b..664793c23b198e 100644 --- a/x-pack/plugins/cases/common/types/domain/configure/v1.ts +++ b/x-pack/plugins/cases/common/types/domain/configure/v1.ts @@ -6,8 +6,8 @@ */ import * as rt from 'io-ts'; -import { UserRt } from '../../../api'; import { CaseConnectorRt, ConnectorMappingsRt } from '../connector/v1'; +import { UserRt } from '../user/v1'; const ClosureTypeRt = rt.union([rt.literal('close-by-user'), rt.literal('close-by-pushing')]); diff --git a/x-pack/plugins/cases/common/types/domain/external_service/latest.ts b/x-pack/plugins/cases/common/types/domain/external_service/latest.ts new file mode 100644 index 00000000000000..25300c97a6d2e1 --- /dev/null +++ b/x-pack/plugins/cases/common/types/domain/external_service/latest.ts @@ -0,0 +1,8 @@ +/* + * 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. + */ + +export * from './v1'; diff --git a/x-pack/plugins/cases/common/types/domain/external_service/v1.test.ts b/x-pack/plugins/cases/common/types/domain/external_service/v1.test.ts new file mode 100644 index 00000000000000..6d3bb100fa69ab --- /dev/null +++ b/x-pack/plugins/cases/common/types/domain/external_service/v1.test.ts @@ -0,0 +1,53 @@ +/* + * 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 { ExternalServiceRt } from './v1'; + +describe('ExternalServiceRt', () => { + const defaultRequest = { + connector_id: 'servicenow-1', + connector_name: 'My SN connector', + external_id: 'external_id', + external_title: 'external title', + external_url: 'basicPush.com', + pushed_at: '2023-01-17T09:46:29.813Z', + pushed_by: { + full_name: 'Leslie Knope', + username: 'lknope', + email: 'leslie.knope@elastic.co', + }, + }; + it('has expected attributes in request', () => { + const query = ExternalServiceRt.decode(defaultRequest); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: defaultRequest, + }); + }); + + it('removes foo:bar attributes from request', () => { + const query = ExternalServiceRt.decode({ ...defaultRequest, foo: 'bar' }); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: defaultRequest, + }); + }); + + it('removes foo:bar attributes from pushed_by', () => { + const query = ExternalServiceRt.decode({ + ...defaultRequest, + pushed_by: { ...defaultRequest.pushed_by, foo: 'bar' }, + }); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: defaultRequest, + }); + }); +}); diff --git a/x-pack/plugins/cases/common/types/domain/external_service/v1.ts b/x-pack/plugins/cases/common/types/domain/external_service/v1.ts new file mode 100644 index 00000000000000..1d76ab7e7bb916 --- /dev/null +++ b/x-pack/plugins/cases/common/types/domain/external_service/v1.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; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import * as rt from 'io-ts'; +import { UserRt } from '../user/v1'; + +/** + * This represents the push to service UserAction. It lacks the connector_id because that is stored in a different field + * within the user action object in the API response. + */ +export const ExternalServiceBasicRt = rt.strict({ + connector_name: rt.string, + external_id: rt.string, + external_title: rt.string, + external_url: rt.string, + pushed_at: rt.string, + pushed_by: UserRt, +}); + +export const ExternalServiceRt = rt.intersection([ + rt.strict({ + connector_id: rt.string, + }), + ExternalServiceBasicRt, +]); + +export type ExternalService = rt.TypeOf; diff --git a/x-pack/plugins/cases/common/types/domain/index.ts b/x-pack/plugins/cases/common/types/domain/index.ts index b8832d3c7db14a..c46b34d1828779 100644 --- a/x-pack/plugins/cases/common/types/domain/index.ts +++ b/x-pack/plugins/cases/common/types/domain/index.ts @@ -8,9 +8,17 @@ // Latest export * from './configure/latest'; export * from './user_action/latest'; +export * from './external_service/latest'; +export * from './case/latest'; +export * from './user/latest'; export * from './connector/latest'; +export * from './attachment/latest'; // V1 export * as configureDomainV1 from './configure/v1'; export * as userActionDomainV1 from './user_action/v1'; +export * as externalServiceDomainV1 from './external_service/v1'; +export * as caseDomainV1 from './case/v1'; +export * as userDomainV1 from './user/v1'; export * as connectorDomainV1 from './connector/v1'; +export * as attachmentDomainV1 from './attachment/v1'; diff --git a/x-pack/plugins/cases/common/types/domain/user/latest.ts b/x-pack/plugins/cases/common/types/domain/user/latest.ts new file mode 100644 index 00000000000000..25300c97a6d2e1 --- /dev/null +++ b/x-pack/plugins/cases/common/types/domain/user/latest.ts @@ -0,0 +1,8 @@ +/* + * 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. + */ + +export * from './v1'; diff --git a/x-pack/plugins/cases/common/types/domain/user/v1.test.ts b/x-pack/plugins/cases/common/types/domain/user/v1.test.ts new file mode 100644 index 00000000000000..56d23fff6fc1a0 --- /dev/null +++ b/x-pack/plugins/cases/common/types/domain/user/v1.test.ts @@ -0,0 +1,202 @@ +/* + * 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 { set } from 'lodash'; +import { UserRt, UserWithProfileInfoRt, UsersRt, CaseUserProfileRt, CaseAssigneesRt } from './v1'; + +describe('User', () => { + describe('UserRt', () => { + const defaultRequest = { + full_name: 'elastic', + email: 'testemail@elastic.co', + username: 'elastic', + profile_uid: 'profile-uid-1', + }; + it('has expected attributes in request', () => { + const query = UserRt.decode(defaultRequest); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: defaultRequest, + }); + }); + + it('removes foo:bar attributes from request', () => { + const query = UserRt.decode({ + ...defaultRequest, + foo: 'bar', + }); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: defaultRequest, + }); + }); + }); + + describe('UserWithProfileInfoRt', () => { + const defaultRequest = { + uid: '1', + avatar: { + initials: 'SU', + color: 'red', + imageUrl: 'https://google.com/image1', + }, + user: { + username: 'user', + email: 'some.user@google.com', + full_name: 'Some Super User', + }, + }; + + it('has expected attributes in request', () => { + const query = UserWithProfileInfoRt.decode(defaultRequest); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: defaultRequest, + }); + }); + + it.each(['initials', 'color', 'imageUrl'])('does not returns an error if %s is null', (key) => { + const reqWithNullImage = set(defaultRequest, `avatar.${key}`, null); + const query = UserWithProfileInfoRt.decode(reqWithNullImage); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: reqWithNullImage, + }); + }); + + it('removes foo:bar attributes from request', () => { + const query = UserWithProfileInfoRt.decode({ + ...defaultRequest, + foo: 'bar', + }); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: defaultRequest, + }); + }); + + it('removes foo:bar attributes from avatar', () => { + const query = UserWithProfileInfoRt.decode({ + ...defaultRequest, + avatar: { ...defaultRequest.avatar, foo: 'bar' }, + }); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: defaultRequest, + }); + }); + }); + + describe('UsersRt', () => { + const defaultRequest = [ + { + email: 'reporter_no_uid@elastic.co', + full_name: 'Reporter No UID', + username: 'reporter_no_uid', + profile_uid: 'reporter-uid', + }, + { + full_name: 'elastic', + email: 'testemail@elastic.co', + username: 'elastic', + }, + ]; + + it('has expected attributes in request', () => { + const query = UsersRt.decode(defaultRequest); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: defaultRequest, + }); + }); + + it('removes foo:bar attributes from request', () => { + const query = UsersRt.decode([ + { + ...defaultRequest[0], + foo: 'bar', + }, + ]); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: [defaultRequest[0]], + }); + }); + }); + + describe('UserProfile', () => { + describe('CaseUserProfileRt', () => { + it('has expected attributes in response', () => { + const query = CaseUserProfileRt.decode({ + uid: 'u_J41Oh6L9ki-Vo2tOogS8WRTENzhHurGtRc87NgEAlkc_0', + }); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: { + uid: 'u_J41Oh6L9ki-Vo2tOogS8WRTENzhHurGtRc87NgEAlkc_0', + }, + }); + }); + + it('removes foo:bar attributes from response', () => { + const query = CaseUserProfileRt.decode({ + uid: 'u_J41Oh6L9ki-Vo2tOogS8WRTENzhHurGtRc87NgEAlkc_0', + foo: 'bar', + }); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: { + uid: 'u_J41Oh6L9ki-Vo2tOogS8WRTENzhHurGtRc87NgEAlkc_0', + }, + }); + }); + }); + }); + + describe('Assignee', () => { + describe('CaseAssigneesRt', () => { + const defaultRequest = [{ uid: '1' }, { uid: '2' }]; + + it('has expected attributes in request', () => { + const query = CaseAssigneesRt.decode(defaultRequest); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: defaultRequest, + }); + }); + + it('removes foo:bar attributes from request', () => { + const query = CaseAssigneesRt.decode([{ ...defaultRequest[0], foo: 'bar' }]); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: [defaultRequest[0]], + }); + }); + + it('removes foo:bar attributes from assignees', () => { + const query = CaseAssigneesRt.decode([{ uid: '1', foo: 'bar' }, { uid: '2' }]); + + expect(query).toStrictEqual({ + _tag: 'Right', + right: [{ uid: '1' }, { uid: '2' }], + }); + }); + }); + }); +}); diff --git a/x-pack/plugins/cases/common/api/user.ts b/x-pack/plugins/cases/common/types/domain/user/v1.ts similarity index 79% rename from x-pack/plugins/cases/common/api/user.ts rename to x-pack/plugins/cases/common/types/domain/user/v1.ts index fe7ad34cab58a9..824fdd35c73058 100644 --- a/x-pack/plugins/cases/common/api/user.ts +++ b/x-pack/plugins/cases/common/types/domain/user/v1.ts @@ -41,11 +41,14 @@ export const UsersRt = rt.array(UserRt); export type User = rt.TypeOf; export type UserWithProfileInfo = rt.TypeOf; -export const GetCaseUsersResponseRt = rt.strict({ - assignees: rt.array(UserWithProfileInfoRt), - unassignedUsers: rt.array(UserWithProfileInfoRt), - participants: rt.array(UserWithProfileInfoRt), - reporter: UserWithProfileInfoRt, +export const CaseUserProfileRt = rt.strict({ + uid: rt.string, }); -export type GetCaseUsersResponse = rt.TypeOf; +export type CaseUserProfile = rt.TypeOf; + +/** + * Assignees + */ +export const CaseAssigneesRt = rt.array(CaseUserProfileRt); +export type CaseAssignees = rt.TypeOf; diff --git a/x-pack/plugins/cases/common/types/domain/user_action/assignees/v1.ts b/x-pack/plugins/cases/common/types/domain/user_action/assignees/v1.ts index 86eae6ab8d003d..f69c0a5efdbe76 100644 --- a/x-pack/plugins/cases/common/types/domain/user_action/assignees/v1.ts +++ b/x-pack/plugins/cases/common/types/domain/user_action/assignees/v1.ts @@ -6,7 +6,7 @@ */ import * as rt from 'io-ts'; -import { CaseAssigneesRt } from '../../../../api'; +import { CaseAssigneesRt } from '../../user/v1'; import { UserActionTypes } from '../action/v1'; export const AssigneesUserActionPayloadRt = rt.strict({ assignees: CaseAssigneesRt }); diff --git a/x-pack/plugins/cases/common/types/domain/user_action/comment/v1.test.ts b/x-pack/plugins/cases/common/types/domain/user_action/comment/v1.test.ts index 71cb479fbeb16b..336981c30e9f41 100644 --- a/x-pack/plugins/cases/common/types/domain/user_action/comment/v1.test.ts +++ b/x-pack/plugins/cases/common/types/domain/user_action/comment/v1.test.ts @@ -5,16 +5,16 @@ * 2.0. */ -import { CommentType } from '../../../../api'; +import { AttachmentType } from '../../attachment/v1'; import { UserActionTypes } from '../action/v1'; import { CommentUserActionPayloadRt, CommentUserActionRt } from './v1'; -describe('Comment', () => { +describe('Attachment', () => { describe('CommentUserActionPayloadRt', () => { const defaultRequest = { comment: { comment: 'this is a sample comment', - type: CommentType.user, + type: AttachmentType.user, owner: 'cases', }, }; @@ -54,7 +54,7 @@ describe('Comment', () => { payload: { comment: { comment: 'this is a sample comment', - type: CommentType.user, + type: AttachmentType.user, owner: 'cases', }, }, diff --git a/x-pack/plugins/cases/common/types/domain/user_action/comment/v1.ts b/x-pack/plugins/cases/common/types/domain/user_action/comment/v1.ts index 3263f955548f7a..a29f95b40d4d63 100644 --- a/x-pack/plugins/cases/common/types/domain/user_action/comment/v1.ts +++ b/x-pack/plugins/cases/common/types/domain/user_action/comment/v1.ts @@ -6,12 +6,12 @@ */ import * as rt from 'io-ts'; -import { CommentRequestRt, CommentRequestWithoutRefsRt } from '../../../../api'; +import { AttachmentRequestRt, AttachmentRequestWithoutRefsRt } from '../../../api/attachment/v1'; import { UserActionTypes } from '../action/v1'; -export const CommentUserActionPayloadRt = rt.strict({ comment: CommentRequestRt }); +export const CommentUserActionPayloadRt = rt.strict({ comment: AttachmentRequestRt }); export const CommentUserActionPayloadWithoutIdsRt = rt.strict({ - comment: CommentRequestWithoutRefsRt, + comment: AttachmentRequestWithoutRefsRt, }); export const CommentUserActionRt = rt.strict({ diff --git a/x-pack/plugins/cases/common/types/domain/user_action/pushed/v1.ts b/x-pack/plugins/cases/common/types/domain/user_action/pushed/v1.ts index c52ecbf40ff2a6..d8047ca0aee9cd 100644 --- a/x-pack/plugins/cases/common/types/domain/user_action/pushed/v1.ts +++ b/x-pack/plugins/cases/common/types/domain/user_action/pushed/v1.ts @@ -6,15 +6,15 @@ */ import * as rt from 'io-ts'; -import { CaseExternalServiceBasicRt, CaseUserActionExternalServiceRt } from '../../../../api'; +import { ExternalServiceBasicRt, ExternalServiceRt } from '../../external_service/v1'; import { UserActionTypes } from '../action/v1'; export const PushedUserActionPayloadWithoutConnectorIdRt = rt.strict({ - externalService: CaseUserActionExternalServiceRt, + externalService: ExternalServiceBasicRt, }); export const PushedUserActionPayloadRt = rt.strict({ - externalService: CaseExternalServiceBasicRt, + externalService: ExternalServiceRt, }); export const PushedUserActionWithoutConnectorIdRt = rt.strict({ diff --git a/x-pack/plugins/cases/common/types/domain/user_action/settings/v1.ts b/x-pack/plugins/cases/common/types/domain/user_action/settings/v1.ts index 933c9dc7be43ee..9e756986652b20 100644 --- a/x-pack/plugins/cases/common/types/domain/user_action/settings/v1.ts +++ b/x-pack/plugins/cases/common/types/domain/user_action/settings/v1.ts @@ -6,10 +6,10 @@ */ import * as rt from 'io-ts'; -import { SettingsRt } from '../../../../api'; +import { CaseSettingsRt } from '../../case/v1'; import { UserActionTypes } from '../action/v1'; -export const SettingsUserActionPayloadRt = rt.strict({ settings: SettingsRt }); +export const SettingsUserActionPayloadRt = rt.strict({ settings: CaseSettingsRt }); export const SettingsUserActionRt = rt.strict({ type: rt.literal(UserActionTypes.settings), diff --git a/x-pack/plugins/cases/common/types/domain/user_action/severity/v1.test.ts b/x-pack/plugins/cases/common/types/domain/user_action/severity/v1.test.ts index 59395c003a946c..0613840e90c08f 100644 --- a/x-pack/plugins/cases/common/types/domain/user_action/severity/v1.test.ts +++ b/x-pack/plugins/cases/common/types/domain/user_action/severity/v1.test.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { CaseSeverity } from '../../../../api'; +import { CaseSeverity } from '../../case/v1'; import { UserActionTypes } from '../action/v1'; import { SeverityUserActionPayloadRt, SeverityUserActionRt } from './v1'; diff --git a/x-pack/plugins/cases/common/types/domain/user_action/severity/v1.ts b/x-pack/plugins/cases/common/types/domain/user_action/severity/v1.ts index e6519540e30fe7..03c69f195939bf 100644 --- a/x-pack/plugins/cases/common/types/domain/user_action/severity/v1.ts +++ b/x-pack/plugins/cases/common/types/domain/user_action/severity/v1.ts @@ -6,7 +6,7 @@ */ import * as rt from 'io-ts'; -import { CaseSeverityRt } from '../../../../api'; +import { CaseSeverityRt } from '../../case/v1'; import { UserActionTypes } from '../action/v1'; export const SeverityUserActionPayloadRt = rt.strict({ severity: CaseSeverityRt }); diff --git a/x-pack/plugins/cases/common/types/domain/user_action/status/v1.ts b/x-pack/plugins/cases/common/types/domain/user_action/status/v1.ts index b7d4fb8743317a..1dd704d61b6249 100644 --- a/x-pack/plugins/cases/common/types/domain/user_action/status/v1.ts +++ b/x-pack/plugins/cases/common/types/domain/user_action/status/v1.ts @@ -6,7 +6,7 @@ */ import * as rt from 'io-ts'; -import { CaseStatusRt } from '../../../../api'; +import { CaseStatusRt } from '../../case/v1'; import { UserActionTypes } from '../action/v1'; export const StatusUserActionPayloadRt = rt.strict({ status: CaseStatusRt }); diff --git a/x-pack/plugins/cases/common/types/domain/user_action/v1.test.ts b/x-pack/plugins/cases/common/types/domain/user_action/v1.test.ts index 01180685e6d33a..b18606e55e21f1 100644 --- a/x-pack/plugins/cases/common/types/domain/user_action/v1.test.ts +++ b/x-pack/plugins/cases/common/types/domain/user_action/v1.test.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { CommentType } from '../../../api'; +import { AttachmentType } from '../attachment/v1'; import { UserActionTypes } from './action/v1'; import { UserActionsRt } from './v1'; @@ -17,7 +17,7 @@ describe('User actions', () => { payload: { comment: { comment: 'this is a sample comment', - type: CommentType.user, + type: AttachmentType.user, owner: 'cases', }, }, diff --git a/x-pack/plugins/cases/common/types/domain/user_action/v1.ts b/x-pack/plugins/cases/common/types/domain/user_action/v1.ts index c03037224c6f82..365e21e305996c 100644 --- a/x-pack/plugins/cases/common/types/domain/user_action/v1.ts +++ b/x-pack/plugins/cases/common/types/domain/user_action/v1.ts @@ -6,7 +6,7 @@ */ import * as rt from 'io-ts'; -import { UserRt } from '../../../api'; +import { UserRt } from '../user/v1'; import { UserActionActionsRt } from './action/v1'; import { AssigneesUserActionRt } from './assignees/v1'; import { CategoryUserActionRt } from './category/v1'; diff --git a/x-pack/plugins/cases/common/ui/types.ts b/x-pack/plugins/cases/common/ui/types.ts index e0cadcc12b6d00..c9a5335f6388cd 100644 --- a/x-pack/plugins/cases/common/ui/types.ts +++ b/x-pack/plugins/cases/common/ui/types.ts @@ -12,28 +12,28 @@ import type { READ_CASES_CAPABILITY, UPDATE_CASES_CAPABILITY, } from '..'; +import type { SingleCaseMetricsResponse, CasesMetricsResponse } from '../api'; +import type { PUSH_CASES_CAPABILITY } from '../constants'; +import type { SnakeToCamelCase } from '../types'; import type { - CasePatchRequest, + CaseSeverity, CaseStatuses, - User, - SingleCaseMetricsResponse, - Comment, + UserAction, Case as CaseSnakeCase, - CommentResponseAlertsType, + User, + ActionConnector, + AlertAttachment, + Attachment, + ExternalReferenceAttachment, + PersistableStateAttachment, +} from '../types/domain'; +import type { + CasePatchRequest, CasesFindResponse, CasesStatusResponse, - CasesMetricsResponse, - CaseSeverity, - CommentResponseExternalReferenceType, - CommentResponseTypePersistableState, - GetCaseUsersResponse, -} from '../api'; -import type { PUSH_CASES_CAPABILITY } from '../constants'; -import type { SnakeToCamelCase } from '../types'; -import type { ActionConnector, UserAction } from '../types/domain'; -import type { CaseUserActionStatsResponse, GetCaseConnectorsResponse, + GetCaseUsersResponse, UserActionFindRequestTypes, UserActionFindResponse, } from '../types/api'; @@ -84,16 +84,18 @@ export type CaseViewRefreshPropInterface = null | { refreshCase: () => Promise; }; -export type CommentUI = SnakeToCamelCase; -export type AlertComment = SnakeToCamelCase; -export type ExternalReferenceComment = SnakeToCamelCase; -export type PersistableComment = SnakeToCamelCase; +export type AttachmentUI = SnakeToCamelCase; +export type AlertAttachmentUI = SnakeToCamelCase; +export type ExternalReferenceAttachmentUI = SnakeToCamelCase; +export type PersistableStateAttachmentUI = SnakeToCamelCase; export type UserActionUI = SnakeToCamelCase; export type FindCaseUserActions = Omit, 'userActions'> & { userActions: UserActionUI[]; }; export type CaseUserActionsStats = SnakeToCamelCase; -export type CaseUI = Omit, 'comments'> & { comments: CommentUI[] }; +export type CaseUI = Omit, 'comments'> & { + comments: AttachmentUI[]; +}; export type CasesUI = CaseUI[]; export type CasesFindResponseUI = Omit, 'cases'> & { cases: CasesUI; diff --git a/x-pack/plugins/cases/common/utils/attachments.test.ts b/x-pack/plugins/cases/common/utils/attachments.test.ts index eec0ecaef5b749..82decfb62bc973 100644 --- a/x-pack/plugins/cases/common/utils/attachments.test.ts +++ b/x-pack/plugins/cases/common/utils/attachments.test.ts @@ -5,8 +5,8 @@ * 2.0. */ -import type { CommentAttributes } from '../api'; -import { CommentType } from '../api'; +import type { AttachmentAttributes } from '../types/domain'; +import { AttachmentType } from '../types/domain'; import { isCommentRequestTypeExternalReference, isCommentRequestTypePersistableState, @@ -15,11 +15,11 @@ import { describe('attachments utils', () => { describe('isCommentRequestTypeExternalReference', () => { const externalReferenceAttachment = { - type: CommentType.externalReference as const, - } as CommentAttributes; + type: AttachmentType.externalReference as const, + } as AttachmentAttributes; - const commentTypeWithoutAlert = Object.values(CommentType).filter( - (type) => type !== CommentType.externalReference + const commentTypeWithoutAlert = Object.values(AttachmentType).filter( + (type) => type !== AttachmentType.externalReference ); it('returns false for type: externalReference', () => { @@ -29,7 +29,7 @@ describe('attachments utils', () => { it.each(commentTypeWithoutAlert)('returns false for type: %s', (type) => { const attachment = { type, - } as CommentAttributes; + } as AttachmentAttributes; expect(isCommentRequestTypeExternalReference(attachment)).toBe(false); }); @@ -37,11 +37,11 @@ describe('attachments utils', () => { describe('isCommentRequestTypePersistableState', () => { const persistableStateAttachment = { - type: CommentType.persistableState as const, - } as CommentAttributes; + type: AttachmentType.persistableState as const, + } as AttachmentAttributes; - const commentTypeWithoutAlert = Object.values(CommentType).filter( - (type) => type !== CommentType.persistableState + const commentTypeWithoutAlert = Object.values(AttachmentType).filter( + (type) => type !== AttachmentType.persistableState ); it('returns false for type: persistableState', () => { @@ -51,7 +51,7 @@ describe('attachments utils', () => { it.each(commentTypeWithoutAlert)('returns false for type: %s', (type) => { const attachment = { type, - } as CommentAttributes; + } as AttachmentAttributes; expect(isCommentRequestTypePersistableState(attachment)).toBe(false); }); diff --git a/x-pack/plugins/cases/common/utils/attachments.ts b/x-pack/plugins/cases/common/utils/attachments.ts index e98df664ed2d46..4b109445d75055 100644 --- a/x-pack/plugins/cases/common/utils/attachments.ts +++ b/x-pack/plugins/cases/common/utils/attachments.ts @@ -5,27 +5,27 @@ * 2.0. */ +import type { AttachmentRequest } from '../types/api'; import type { - CommentRequest, - CommentRequestExternalReferenceType, - CommentRequestPersistableStateType, -} from '../api'; -import { CommentType } from '../api'; + ExternalReferenceAttachmentPayload, + PersistableStateAttachmentPayload, +} from '../types/domain'; +import { AttachmentType } from '../types/domain'; /** * A type narrowing function for external reference attachments. */ export const isCommentRequestTypeExternalReference = ( - context: CommentRequest -): context is CommentRequestExternalReferenceType => { - return context.type === CommentType.externalReference; + context: AttachmentRequest +): context is ExternalReferenceAttachmentPayload => { + return context.type === AttachmentType.externalReference; }; /** * A type narrowing function for persistable state attachments. */ export const isCommentRequestTypePersistableState = ( - context: Partial -): context is CommentRequestPersistableStateType => { - return context.type === CommentType.persistableState; + context: Partial +): context is PersistableStateAttachmentPayload => { + return context.type === AttachmentType.persistableState; }; diff --git a/x-pack/plugins/cases/common/utils/validators.ts b/x-pack/plugins/cases/common/utils/validators.ts index d97405dc7e7dec..9311c3a9a8bae7 100644 --- a/x-pack/plugins/cases/common/utils/validators.ts +++ b/x-pack/plugins/cases/common/utils/validators.ts @@ -5,8 +5,8 @@ * 2.0. */ -import type { CaseAssignees } from '../api'; import { MAX_ASSIGNEES_PER_CASE } from '../constants'; +import type { CaseAssignees } from '../types/domain'; export const areTotalAssigneesInvalid = (assignees?: CaseAssignees): boolean => { if (assignees == null) { diff --git a/x-pack/plugins/cases/public/api/__mocks__/index.ts b/x-pack/plugins/cases/public/api/__mocks__/index.ts index 16707fb6aa9596..aae0368d4c9946 100644 --- a/x-pack/plugins/cases/public/api/__mocks__/index.ts +++ b/x-pack/plugins/cases/public/api/__mocks__/index.ts @@ -5,10 +5,11 @@ * 2.0. */ -import type { CasesFindRequest, CasesMetricsRequest } from '../../../common/api'; +import type { CasesMetricsRequest } from '../../../common/api'; import type { HTTPService } from '..'; import { casesMetrics, casesStatus } from '../../containers/mock'; import type { CasesMetrics, CasesStatus } from '../../containers/types'; +import type { CasesFindRequest } from '../../../common/types/api'; export const getCasesStatus = async ({ http, diff --git a/x-pack/plugins/cases/public/api/decoders.ts b/x-pack/plugins/cases/public/api/decoders.ts index 4b2072ca00b349..ce27fe5ecd89f7 100644 --- a/x-pack/plugins/cases/public/api/decoders.ts +++ b/x-pack/plugins/cases/public/api/decoders.ts @@ -9,20 +9,20 @@ import { fold } from 'fp-ts/lib/Either'; import { identity } from 'fp-ts/lib/function'; import { pipe } from 'fp-ts/lib/pipeable'; -import { createToasterPlainError } from '../containers/utils'; -import { throwErrors } from '../../common'; import type { CasesFindResponse, CasesStatusResponse, - CasesMetricsResponse, CasesBulkGetResponse, -} from '../../common/api'; +} from '../../common/types/api'; import { - CasesBulkGetResponseRt, CasesFindResponseRt, CasesStatusResponseRt, - CasesMetricsResponseRt, -} from '../../common/api'; + CasesBulkGetResponseRt, +} from '../../common/types/api'; +import { createToasterPlainError } from '../containers/utils'; +import { throwErrors } from '../../common'; +import type { CasesMetricsResponse } from '../../common/api'; +import { CasesMetricsResponseRt } from '../../common/api'; export const decodeCasesFindResponse = (respCases?: CasesFindResponse) => pipe(CasesFindResponseRt.decode(respCases), fold(throwErrors(createToasterPlainError), identity)); diff --git a/x-pack/plugins/cases/public/api/index.ts b/x-pack/plugins/cases/public/api/index.ts index 467edbc161cae3..743bb2f2346ba3 100644 --- a/x-pack/plugins/cases/public/api/index.ts +++ b/x-pack/plugins/cases/public/api/index.ts @@ -6,6 +6,14 @@ */ import type { HttpStart } from '@kbn/core/public'; +import type { + CasesFindRequest, + CasesFindResponse, + CasesStatusRequest, + CasesStatusResponse, + CasesBulkGetRequest, + CasesBulkGetResponse, +} from '../../common/types/api'; import type { CasesStatus, CasesMetrics, CasesFindResponseUI } from '../../common/ui'; import { CASE_FIND_URL, @@ -13,16 +21,7 @@ import { CASE_STATUS_URL, INTERNAL_BULK_GET_CASES_URL, } from '../../common/constants'; -import type { - CasesBulkGetRequest, - CasesBulkGetResponse, - CasesFindRequest, - CasesFindResponse, - CasesMetricsRequest, - CasesMetricsResponse, - CasesStatusRequest, - CasesStatusResponse, -} from '../../common/api'; +import type { CasesMetricsRequest, CasesMetricsResponse } from '../../common/api'; import { convertAllCasesToCamel, convertToCamelCase } from './utils'; import { decodeCasesBulkGetResponse, diff --git a/x-pack/plugins/cases/public/api/utils.ts b/x-pack/plugins/cases/public/api/utils.ts index 390b8a1c6062d9..6bb1c23266d651 100644 --- a/x-pack/plugins/cases/public/api/utils.ts +++ b/x-pack/plugins/cases/public/api/utils.ts @@ -7,25 +7,22 @@ import { set } from '@kbn/safer-lodash-set'; import { isArray, camelCase, isObject, omit, get } from 'lodash'; -import type { UserActions } from '../../common/types/domain'; +import type { + AttachmentRequest, + CaseResolveResponse, + CasesFindResponse, +} from '../../common/types/api'; +import type { Attachment, Case, Cases, UserActions } from '../../common/types/domain'; import { isCommentRequestTypeExternalReference, isCommentRequestTypePersistableState, } from '../../common/utils/attachments'; -import type { - CasesFindResponse, - Case, - CommentRequest, - Comment, - CaseResolveResponse, - Cases, -} from '../../common/api'; import { isCommentUserAction } from '../../common/utils/user_actions'; import type { CasesFindResponseUI, CasesUI, CaseUI, - CommentUI, + AttachmentUI, ResolvedCase, } from '../containers/types'; @@ -71,11 +68,11 @@ export const convertCaseResolveToCamelCase = (res: CaseResolveResponse): Resolve }; }; -export const convertAttachmentsToCamelCase = (attachments: Comment[]): CommentUI[] => { +export const convertAttachmentsToCamelCase = (attachments: Attachment[]): AttachmentUI[] => { return attachments.map((attachment) => convertAttachmentToCamelCase(attachment)); }; -export const convertAttachmentToCamelCase = (attachment: CommentRequest): CommentUI => { +export const convertAttachmentToCamelCase = (attachment: AttachmentRequest): AttachmentUI => { if (isCommentRequestTypeExternalReference(attachment)) { return convertAttachmentToCamelExceptProperty(attachment, 'externalReferenceMetadata'); } @@ -84,7 +81,7 @@ export const convertAttachmentToCamelCase = (attachment: CommentRequest): Commen return convertAttachmentToCamelExceptProperty(attachment, 'persistableStateAttachmentState'); } - return convertToCamelCase(attachment); + return convertToCamelCase(attachment); }; export const convertUserActionsToCamelCase = (userActions: UserActions) => { @@ -106,9 +103,9 @@ export const convertUserActionsToCamelCase = (userActions: UserActions) => { }; const convertAttachmentToCamelExceptProperty = ( - attachment: CommentRequest, + attachment: AttachmentRequest, key: string -): CommentUI => { +): AttachmentUI => { const intactValue = get(attachment, key); const attachmentWithoutIntactValue = omit(attachment, key); const camelCaseAttachmentWithoutIntactValue = convertToCamelCase(attachmentWithoutIntactValue); @@ -116,7 +113,7 @@ const convertAttachmentToCamelExceptProperty = ( return { ...camelCaseAttachmentWithoutIntactValue, [key]: intactValue, - } as CommentUI; + } as AttachmentUI; }; export const convertAllCasesToCamel = (snakeCases: CasesFindResponse): CasesFindResponseUI => ({ diff --git a/x-pack/plugins/cases/public/client/api/index.ts b/x-pack/plugins/cases/public/client/api/index.ts index 86a0643cddd098..4c71bc05bc0ee0 100644 --- a/x-pack/plugins/cases/public/client/api/index.ts +++ b/x-pack/plugins/cases/public/client/api/index.ts @@ -7,12 +7,12 @@ import type { HttpStart } from '@kbn/core/public'; import type { - CasesByAlertId, CasesByAlertIDRequest, + GetRelatedCasesByAlertResponse, CasesFindRequest, CasesStatusRequest, - CasesMetricsRequest, -} from '../../../common/api'; +} from '../../../common/types/api'; +import type { CasesMetricsRequest } from '../../../common/api'; import { getCasesFromAlertsUrl } from '../../../common/api'; import { bulkGetCases, getCases, getCasesMetrics, getCasesStatus } from '../../api'; import type { CasesFindResponseUI, CasesStatus, CasesMetrics } from '../../../common/ui'; @@ -23,8 +23,8 @@ export const createClientAPI = ({ http }: { http: HttpStart }): CasesUiStart['ap getRelatedCases: async ( alertId: string, query: CasesByAlertIDRequest - ): Promise => - http.get(getCasesFromAlertsUrl(alertId), { query }), + ): Promise => + http.get(getCasesFromAlertsUrl(alertId), { query }), cases: { find: (query: CasesFindRequest, signal?: AbortSignal): Promise => getCases({ http, query, signal }), diff --git a/x-pack/plugins/cases/public/client/attachment_framework/types.ts b/x-pack/plugins/cases/public/client/attachment_framework/types.ts index 5160903cda288d..cd946c885aaa3a 100644 --- a/x-pack/plugins/cases/public/client/attachment_framework/types.ts +++ b/x-pack/plugins/cases/public/client/attachment_framework/types.ts @@ -8,9 +8,9 @@ import type React from 'react'; import type { EuiCommentProps, IconType, EuiButtonProps } from '@elastic/eui'; import type { - CommentRequestExternalReferenceType, - CommentRequestPersistableStateType, -} from '../../../common/api'; + ExternalReferenceAttachmentPayload, + PersistableStateAttachmentPayload, +} from '../../../common/types/domain'; import type { CaseUI } from '../../containers/types'; export enum AttachmentActionType { @@ -53,13 +53,13 @@ export interface CommonAttachmentViewProps { } export interface ExternalReferenceAttachmentViewProps extends CommonAttachmentViewProps { - externalReferenceId: CommentRequestExternalReferenceType['externalReferenceId']; - externalReferenceMetadata: CommentRequestExternalReferenceType['externalReferenceMetadata']; + externalReferenceId: ExternalReferenceAttachmentPayload['externalReferenceId']; + externalReferenceMetadata: ExternalReferenceAttachmentPayload['externalReferenceMetadata']; } export interface PersistableStateAttachmentViewProps extends CommonAttachmentViewProps { - persistableStateAttachmentTypeId: CommentRequestPersistableStateType['persistableStateAttachmentTypeId']; - persistableStateAttachmentState: CommentRequestPersistableStateType['persistableStateAttachmentState']; + persistableStateAttachmentTypeId: PersistableStateAttachmentPayload['persistableStateAttachmentTypeId']; + persistableStateAttachmentState: PersistableStateAttachmentPayload['persistableStateAttachmentState']; } export interface AttachmentType { diff --git a/x-pack/plugins/cases/public/client/helpers/group_alerts_by_rule.ts b/x-pack/plugins/cases/public/client/helpers/group_alerts_by_rule.ts index 098a59ef2fd3d0..c84100a10a7db5 100644 --- a/x-pack/plugins/cases/public/client/helpers/group_alerts_by_rule.ts +++ b/x-pack/plugins/cases/public/client/helpers/group_alerts_by_rule.ts @@ -5,9 +5,9 @@ * 2.0. */ -import type { CommentRequestAlertType } from '../../../common/api'; +import type { AlertAttachmentPayload } from '../../../common/types/domain'; import type { Ecs } from '../../../common'; -import { CommentType } from '../../../common'; +import { AttachmentType } from '../../../common/types/domain'; import { getRuleIdFromEvent } from './get_rule_id_from_event'; import type { CaseAttachmentsWithoutOwner } from '../../types'; @@ -21,7 +21,7 @@ interface EventNonEcsData { value?: Maybe; } -type CommentRequestAlertTypeWithoutOwner = Omit; +type CommentRequestAlertTypeWithoutOwner = Omit; export type GroupAlertsByRule = (items: Event[]) => CaseAttachmentsWithoutOwner; @@ -33,7 +33,7 @@ export const groupAlertsByRule: GroupAlertsByRule = (items) => { acc[rule.id] = { alertId: [], index: [], - type: CommentType.alert as const, + type: AttachmentType.alert as const, rule, }; } diff --git a/x-pack/plugins/cases/public/common/apm/use_cases_transactions.ts b/x-pack/plugins/cases/public/common/apm/use_cases_transactions.ts index 1a4be4053b7ef0..891726322cb8ec 100644 --- a/x-pack/plugins/cases/public/common/apm/use_cases_transactions.ts +++ b/x-pack/plugins/cases/public/common/apm/use_cases_transactions.ts @@ -7,7 +7,7 @@ import type { Transaction } from '@elastic/apm-rum'; import { useCallback } from 'react'; -import { CommentType } from '../../../common'; +import { AttachmentType } from '../../../common/types/domain'; import type { CaseAttachmentsWithoutOwner } from '../../types'; import { useStartTransaction } from './use_start_transaction'; @@ -77,7 +77,7 @@ export const useAddAttachmentToExistingCaseTransaction = () => { const getAlertCount = (attachments: CaseAttachmentsWithoutOwner) => { return attachments.reduce((total, attachment) => { - if (attachment.type !== CommentType.alert) { + if (attachment.type !== AttachmentType.alert) { return total; } if (!Array.isArray(attachment.alertId)) { diff --git a/x-pack/plugins/cases/public/common/use_cases_toast.tsx b/x-pack/plugins/cases/public/common/use_cases_toast.tsx index d123cc1bdd5e8b..93905eaf642130 100644 --- a/x-pack/plugins/cases/public/common/use_cases_toast.tsx +++ b/x-pack/plugins/cases/public/common/use_cases_toast.tsx @@ -12,7 +12,7 @@ import styled from 'styled-components'; import { toMountPoint } from '@kbn/kibana-react-plugin/public'; import { isValidOwner } from '../../common/utils/owner'; import type { CaseUI } from '../../common'; -import { CommentType } from '../../common'; +import { AttachmentType } from '../../common/types/domain'; import { useKibana, useToasts } from './lib/kibana'; import { generateCaseViewPath } from './navigation'; import type { CaseAttachmentsWithoutOwner, ServerError } from '../types'; @@ -43,7 +43,7 @@ const EuiTextStyled = styled(EuiText)` function getAlertsCount(attachments: CaseAttachmentsWithoutOwner): number { let alertsCount = 0; for (const attachment of attachments) { - if (attachment.type === CommentType.alert) { + if (attachment.type === AttachmentType.alert) { // alertId might be an array if (Array.isArray(attachment.alertId) && attachment.alertId.length > 1) { alertsCount += attachment.alertId.length; @@ -91,7 +91,7 @@ function getToastContent({ } if (attachments !== undefined) { for (const attachment of attachments) { - if (attachment.type === CommentType.alert && theCase.settings.syncAlerts) { + if (attachment.type === AttachmentType.alert && theCase.settings.syncAlerts) { return CASE_ALERT_SUCCESS_SYNC_TEXT; } } diff --git a/x-pack/plugins/cases/public/components/actions/severity/translations.ts b/x-pack/plugins/cases/public/components/actions/severity/translations.ts index 81e0caf848d153..8b1db9c5c7d31b 100644 --- a/x-pack/plugins/cases/public/components/actions/severity/translations.ts +++ b/x-pack/plugins/cases/public/components/actions/severity/translations.ts @@ -6,7 +6,7 @@ */ import { i18n } from '@kbn/i18n'; -import { CaseSeverity } from '../../../../common/api'; +import { CaseSeverity } from '../../../../common/types/domain'; import { severities } from '../../severity/config'; const SET_SEVERITY = ({ diff --git a/x-pack/plugins/cases/public/components/actions/severity/use_severity_action.test.tsx b/x-pack/plugins/cases/public/components/actions/severity/use_severity_action.test.tsx index 50e8f804f4b944..79ae67610d9023 100644 --- a/x-pack/plugins/cases/public/components/actions/severity/use_severity_action.test.tsx +++ b/x-pack/plugins/cases/public/components/actions/severity/use_severity_action.test.tsx @@ -12,7 +12,7 @@ import { useSeverityAction } from './use_severity_action'; import * as api from '../../../containers/api'; import { basicCase } from '../../../containers/mock'; -import { CaseSeverity } from '../../../../common/api'; +import { CaseSeverity } from '../../../../common/types/domain'; jest.mock('../../../containers/api'); diff --git a/x-pack/plugins/cases/public/components/actions/severity/use_severity_action.tsx b/x-pack/plugins/cases/public/components/actions/severity/use_severity_action.tsx index 5e72329ad98737..becdf336542d7b 100644 --- a/x-pack/plugins/cases/public/components/actions/severity/use_severity_action.tsx +++ b/x-pack/plugins/cases/public/components/actions/severity/use_severity_action.tsx @@ -7,7 +7,7 @@ import { useCallback } from 'react'; import type { EuiContextMenuPanelItemDescriptor } from '@elastic/eui'; -import { CaseSeverity } from '../../../../common/api'; +import { CaseSeverity } from '../../../../common/types/domain'; import { useUpdateCases } from '../../../containers/use_bulk_update_case'; import type { CasesUI } from '../../../../common'; diff --git a/x-pack/plugins/cases/public/components/actions/status/use_status_action.test.tsx b/x-pack/plugins/cases/public/components/actions/status/use_status_action.test.tsx index 60f42942f9ec59..bb4aef3379aa36 100644 --- a/x-pack/plugins/cases/public/components/actions/status/use_status_action.test.tsx +++ b/x-pack/plugins/cases/public/components/actions/status/use_status_action.test.tsx @@ -12,7 +12,7 @@ import { useStatusAction } from './use_status_action'; import * as api from '../../../containers/api'; import { basicCase } from '../../../containers/mock'; -import { CaseStatuses } from '../../../../common'; +import { CaseStatuses } from '../../../../common/types/domain'; jest.mock('../../../containers/api'); diff --git a/x-pack/plugins/cases/public/components/actions/status/use_status_action.tsx b/x-pack/plugins/cases/public/components/actions/status/use_status_action.tsx index 5b0ab8665fc224..eb00800961085f 100644 --- a/x-pack/plugins/cases/public/components/actions/status/use_status_action.tsx +++ b/x-pack/plugins/cases/public/components/actions/status/use_status_action.tsx @@ -9,7 +9,7 @@ import { useCallback } from 'react'; import type { EuiContextMenuPanelItemDescriptor } from '@elastic/eui'; import { useUpdateCases } from '../../../containers/use_bulk_update_case'; import type { CasesUI } from '../../../../common'; -import { CaseStatuses } from '../../../../common'; +import { CaseStatuses } from '../../../../common/types/domain'; import * as i18n from './translations'; import type { UseActionProps } from '../types'; diff --git a/x-pack/plugins/cases/public/components/add_comment/index.test.tsx b/x-pack/plugins/cases/public/components/add_comment/index.test.tsx index ac255f266620e4..cb13950b110dec 100644 --- a/x-pack/plugins/cases/public/components/add_comment/index.test.tsx +++ b/x-pack/plugins/cases/public/components/add_comment/index.test.tsx @@ -12,7 +12,7 @@ import { noop } from 'lodash/fp'; import { noCreateCasesPermissions, TestProviders, createAppMockRenderer } from '../../common/mock'; -import { CommentType } from '../../../common/api'; +import { AttachmentType } from '../../../common/types/domain'; import { SECURITY_SOLUTION_OWNER, MAX_COMMENT_LENGTH } from '../../../common/constants'; import { useCreateAttachments } from '../../containers/use_create_attachments'; import type { AddCommentProps, AddCommentRefObject } from '.'; @@ -46,7 +46,7 @@ const defaultResponse = { const sampleData: CaseAttachmentWithoutOwner = { comment: 'what a cool comment', - type: CommentType.user as const, + type: AttachmentType.user as const, }; const appId = 'testAppId'; const draftKey = `cases.${appId}.${addCommentProps.caseId}.${addCommentProps.id}.markdownEditor`; diff --git a/x-pack/plugins/cases/public/components/add_comment/index.tsx b/x-pack/plugins/cases/public/components/add_comment/index.tsx index 59fc1fcde0fac0..b86c9a63240697 100644 --- a/x-pack/plugins/cases/public/components/add_comment/index.tsx +++ b/x-pack/plugins/cases/public/components/add_comment/index.tsx @@ -23,7 +23,7 @@ import { UseField, useFormData, } from '@kbn/es-ui-shared-plugin/static/forms/hook_form_lib'; -import { CommentType } from '../../../common/api'; +import { AttachmentType } from '../../../common/types/domain'; import { useCreateAttachments } from '../../containers/use_create_attachments'; import type { CaseUI } from '../../containers/types'; import type { EuiMarkdownEditorRef } from '../markdown_editor'; @@ -119,7 +119,7 @@ export const AddComment = React.memo( { caseId, caseOwner: owner[0], - attachments: [{ ...data, type: CommentType.user }], + attachments: [{ ...data, type: AttachmentType.user }], }, { onSuccess: (theCase) => { diff --git a/x-pack/plugins/cases/public/components/add_comment/schema.tsx b/x-pack/plugins/cases/public/components/add_comment/schema.tsx index 91fc499baa74d2..3d8c26c796419a 100644 --- a/x-pack/plugins/cases/public/components/add_comment/schema.tsx +++ b/x-pack/plugins/cases/public/components/add_comment/schema.tsx @@ -8,7 +8,7 @@ import type { FormSchema } from '@kbn/es-ui-shared-plugin/static/forms/hook_form_lib'; import { FIELD_TYPES } from '@kbn/es-ui-shared-plugin/static/forms/hook_form_lib'; import { fieldValidators } from '@kbn/es-ui-shared-plugin/static/forms/helpers'; -import type { CommentRequestUserType } from '../../../common/api'; +import type { UserCommentAttachmentPayload } from '../../../common/types/domain'; import { MAX_COMMENT_LENGTH } from '../../../common/constants'; import * as i18n from './translations'; @@ -16,7 +16,7 @@ import * as i18n from './translations'; const { emptyField, maxLengthField } = fieldValidators; export interface AddCommentFormSchema { - comment: CommentRequestUserType['comment']; + comment: UserCommentAttachmentPayload['comment']; } export const schema: FormSchema = { diff --git a/x-pack/plugins/cases/public/components/all_cases/all_cases_list.test.tsx b/x-pack/plugins/cases/public/components/all_cases/all_cases_list.test.tsx index 387231beeff670..180a8828c88b19 100644 --- a/x-pack/plugins/cases/public/components/all_cases/all_cases_list.test.tsx +++ b/x-pack/plugins/cases/public/components/all_cases/all_cases_list.test.tsx @@ -23,7 +23,7 @@ import { import { useGetCasesMockState, connectorsMock } from '../../containers/mock'; import { SortFieldCase, StatusAll } from '../../../common/ui/types'; -import { CaseSeverity, CaseStatuses } from '../../../common/api'; +import { CaseSeverity, CaseStatuses } from '../../../common/types/domain'; import { SECURITY_SOLUTION_OWNER } from '../../../common/constants'; import { getEmptyTagValue } from '../empty_value'; import { useKibana } from '../../common/lib/kibana'; diff --git a/x-pack/plugins/cases/public/components/all_cases/all_cases_list.tsx b/x-pack/plugins/cases/public/components/all_cases/all_cases_list.tsx index ffa5cac99d4b0c..f915dbe0b7e38a 100644 --- a/x-pack/plugins/cases/public/components/all_cases/all_cases_list.tsx +++ b/x-pack/plugins/cases/public/components/all_cases/all_cases_list.tsx @@ -21,7 +21,7 @@ import type { CasesOwners } from '../../client/helpers/can_use_cases'; import type { EuiBasicTableOnChange, Solution } from './types'; import { SortFieldCase, StatusAll } from '../../../common/ui/types'; -import { CaseStatuses, caseStatuses } from '../../../common/api'; +import { CaseStatuses, caseStatuses } from '../../../common/types/domain'; import { OWNER_INFO } from '../../../common/constants'; import { useAvailableCasesOwners } from '../app/use_available_owners'; import { useCasesColumns } from './use_cases_columns'; diff --git a/x-pack/plugins/cases/public/components/all_cases/cases_metrics.tsx b/x-pack/plugins/cases/public/components/all_cases/cases_metrics.tsx index ddf3c7845f2409..80131e3f6f7990 100644 --- a/x-pack/plugins/cases/public/components/all_cases/cases_metrics.tsx +++ b/x-pack/plugins/cases/public/components/all_cases/cases_metrics.tsx @@ -16,7 +16,7 @@ import { } from '@elastic/eui'; import styled, { css } from 'styled-components'; import prettyMilliseconds from 'pretty-ms'; -import { CaseStatuses } from '../../../common/api'; +import { CaseStatuses } from '../../../common/types/domain'; import { useGetCasesStatus } from '../../containers/use_get_cases_status'; import { StatusStats } from '../status/status_stats'; import { useGetCasesMetrics } from '../../containers/use_get_cases_metrics'; diff --git a/x-pack/plugins/cases/public/components/all_cases/selector_modal/use_cases_add_to_existing_case_modal.test.tsx b/x-pack/plugins/cases/public/components/all_cases/selector_modal/use_cases_add_to_existing_case_modal.test.tsx index fa75ac3a8e31ca..2cfaacc8383ca1 100644 --- a/x-pack/plugins/cases/public/components/all_cases/selector_modal/use_cases_add_to_existing_case_modal.test.tsx +++ b/x-pack/plugins/cases/public/components/all_cases/selector_modal/use_cases_add_to_existing_case_modal.test.tsx @@ -11,7 +11,8 @@ import userEvent from '@testing-library/user-event'; import React from 'react'; import AllCasesSelectorModal from '.'; import type { CaseUI } from '../../../../common'; -import { CaseStatuses, StatusAll } from '../../../../common'; +import { StatusAll } from '../../../../common'; +import { CaseStatuses } from '../../../../common/types/domain'; import type { AppMockRenderer } from '../../../common/mock'; import { allCasesPermissions, createAppMockRenderer } from '../../../common/mock'; import { useCasesToast } from '../../../common/use_cases_toast'; diff --git a/x-pack/plugins/cases/public/components/all_cases/selector_modal/use_cases_add_to_existing_case_modal.tsx b/x-pack/plugins/cases/public/components/all_cases/selector_modal/use_cases_add_to_existing_case_modal.tsx index 6d0da66a72cb71..35d15fa7e89e8a 100644 --- a/x-pack/plugins/cases/public/components/all_cases/selector_modal/use_cases_add_to_existing_case_modal.tsx +++ b/x-pack/plugins/cases/public/components/all_cases/selector_modal/use_cases_add_to_existing_case_modal.tsx @@ -6,10 +6,11 @@ */ import { useCallback } from 'react'; -import { CaseStatuses, StatusAll } from '../../../../common'; +import { CaseStatuses } from '../../../../common/types/domain'; import type { AllCasesSelectorModalProps } from '.'; import { useCasesToast } from '../../../common/use_cases_toast'; import type { CaseUI } from '../../../containers/types'; +import { StatusAll } from '../../../containers/types'; import { CasesContextStoreActionsList } from '../../cases_context/cases_context_reducer'; import { useCasesContext } from '../../cases_context/use_cases_context'; import { useCasesAddToNewCaseFlyout } from '../../create/flyout/use_cases_add_to_new_case_flyout'; diff --git a/x-pack/plugins/cases/public/components/all_cases/severity_filter.test.tsx b/x-pack/plugins/cases/public/components/all_cases/severity_filter.test.tsx index af9666211d39af..30d5c75e63589d 100644 --- a/x-pack/plugins/cases/public/components/all_cases/severity_filter.test.tsx +++ b/x-pack/plugins/cases/public/components/all_cases/severity_filter.test.tsx @@ -5,7 +5,7 @@ * 2.0. */ -import { CaseSeverity } from '../../../common/api'; +import { CaseSeverity } from '../../../common/types/domain'; import React from 'react'; import type { AppMockRenderer } from '../../common/mock'; import { createAppMockRenderer } from '../../common/mock'; diff --git a/x-pack/plugins/cases/public/components/all_cases/status_filter.test.tsx b/x-pack/plugins/cases/public/components/all_cases/status_filter.test.tsx index 5471c03a6f181a..e58f885972d475 100644 --- a/x-pack/plugins/cases/public/components/all_cases/status_filter.test.tsx +++ b/x-pack/plugins/cases/public/components/all_cases/status_filter.test.tsx @@ -10,7 +10,7 @@ import { mount } from 'enzyme'; import { waitFor } from '@testing-library/react'; import { StatusAll } from '../../../common/ui/types'; -import { CaseStatuses } from '../../../common/api'; +import { CaseStatuses } from '../../../common/types/domain'; import { StatusFilter } from './status_filter'; const stats = { diff --git a/x-pack/plugins/cases/public/components/all_cases/table_filters.test.tsx b/x-pack/plugins/cases/public/components/all_cases/table_filters.test.tsx index 932d464b0d9a19..831fa63ef7e4df 100644 --- a/x-pack/plugins/cases/public/components/all_cases/table_filters.test.tsx +++ b/x-pack/plugins/cases/public/components/all_cases/table_filters.test.tsx @@ -12,7 +12,7 @@ import { waitForEuiPopoverOpen } from '@elastic/eui/lib/test/rtl'; import { licensingMock } from '@kbn/licensing-plugin/public/mocks'; import { waitForComponentToUpdate } from '../../common/test_utils'; -import { CaseStatuses } from '../../../common/api'; +import { CaseStatuses } from '../../../common/types/domain'; import { OWNER_INFO, SECURITY_SOLUTION_OWNER, diff --git a/x-pack/plugins/cases/public/components/all_cases/table_filters.tsx b/x-pack/plugins/cases/public/components/all_cases/table_filters.tsx index 17aea3a9478996..a6aa406b26329d 100644 --- a/x-pack/plugins/cases/public/components/all_cases/table_filters.tsx +++ b/x-pack/plugins/cases/public/components/all_cases/table_filters.tsx @@ -13,7 +13,7 @@ import { EuiFlexGroup, EuiFlexItem, EuiFieldSearch, EuiFilterGroup, EuiButton } import type { CaseStatusWithAllStatus, CaseSeverityWithAll } from '../../../common/ui/types'; import { MAX_TAGS_FILTER_LENGTH, MAX_CATEGORY_FILTER_LENGTH } from '../../../common/constants'; import { StatusAll } from '../../../common/ui/types'; -import { CaseStatuses } from '../../../common/api'; +import { CaseStatuses } from '../../../common/types/domain'; import type { FilterOptions } from '../../containers/types'; import { FilterPopover } from '../filter_popover'; import { SolutionFilter } from './solution_filter'; diff --git a/x-pack/plugins/cases/public/components/all_cases/use_all_cases_state.test.tsx b/x-pack/plugins/cases/public/components/all_cases/use_all_cases_state.test.tsx index c07b35b424e71c..3fddf315acdb4f 100644 --- a/x-pack/plugins/cases/public/components/all_cases/use_all_cases_state.test.tsx +++ b/x-pack/plugins/cases/public/components/all_cases/use_all_cases_state.test.tsx @@ -17,7 +17,7 @@ import { } from './use_all_cases_state'; import { DEFAULT_FILTER_OPTIONS, DEFAULT_QUERY_PARAMS } from '../../containers/use_get_cases'; import { DEFAULT_TABLE_ACTIVE_PAGE, DEFAULT_TABLE_LIMIT } from '../../containers/constants'; -import { CaseStatuses } from '../../../common'; +import { CaseStatuses } from '../../../common/types/domain'; import { SortFieldCase } from '../../containers/types'; import { stringifyToURL } from '../utils'; diff --git a/x-pack/plugins/cases/public/components/all_cases/use_cases_columns.test.tsx b/x-pack/plugins/cases/public/components/all_cases/use_cases_columns.test.tsx index 42a5ea4c1d1fc5..8c394791836dc3 100644 --- a/x-pack/plugins/cases/public/components/all_cases/use_cases_columns.test.tsx +++ b/x-pack/plugins/cases/public/components/all_cases/use_cases_columns.test.tsx @@ -17,7 +17,7 @@ import { connectors } from '../configure_cases/__mock__'; import type { AppMockRenderer } from '../../common/mock'; import { createAppMockRenderer, readCasesPermissions, TestProviders } from '../../common/mock'; import { renderHook } from '@testing-library/react-hooks'; -import { CaseStatuses } from '../../../common'; +import { CaseStatuses } from '../../../common/types/domain'; import { userProfilesMap } from '../../containers/user_profiles/api.mock'; describe('useCasesColumns ', () => { diff --git a/x-pack/plugins/cases/public/components/all_cases/use_cases_columns.tsx b/x-pack/plugins/cases/public/components/all_cases/use_cases_columns.tsx index 25698abe5da69e..ffcc58b5316933 100644 --- a/x-pack/plugins/cases/public/components/all_cases/use_cases_columns.tsx +++ b/x-pack/plugins/cases/public/components/all_cases/use_cases_columns.tsx @@ -27,8 +27,8 @@ import type { UserProfileWithAvatar } from '@kbn/user-profile-components'; import { euiStyled } from '@kbn/kibana-react-plugin/common'; import type { ActionConnector } from '../../../common/types/domain'; +import { CaseSeverity, CaseStatuses } from '../../../common/types/domain'; import type { CaseUI } from '../../../common/ui/types'; -import { CaseStatuses, CaseSeverity } from '../../../common/api'; import { OWNER_INFO } from '../../../common/constants'; import { getEmptyTagValue } from '../empty_value'; import { FormattedRelativePreferenceDate } from '../formatted_date'; diff --git a/x-pack/plugins/cases/public/components/case_action_bar/helpers.test.ts b/x-pack/plugins/cases/public/components/case_action_bar/helpers.test.ts index f04ef94405db87..71d3cf72f054a9 100644 --- a/x-pack/plugins/cases/public/components/case_action_bar/helpers.test.ts +++ b/x-pack/plugins/cases/public/components/case_action_bar/helpers.test.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { CaseStatuses } from '../../../common/api'; +import { CaseStatuses } from '../../../common/types/domain'; import { basicCase } from '../../containers/mock'; import { getStatusDate, getStatusTitle } from './helpers'; diff --git a/x-pack/plugins/cases/public/components/case_action_bar/helpers.ts b/x-pack/plugins/cases/public/components/case_action_bar/helpers.ts index 2e1e176ff850a1..931f4b099976fc 100644 --- a/x-pack/plugins/cases/public/components/case_action_bar/helpers.ts +++ b/x-pack/plugins/cases/public/components/case_action_bar/helpers.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { CaseStatuses } from '../../../common/api'; +import { CaseStatuses } from '../../../common/types/domain'; import type { CaseUI } from '../../containers/types'; import { statuses } from '../status'; diff --git a/x-pack/plugins/cases/public/components/case_action_bar/index.tsx b/x-pack/plugins/cases/public/components/case_action_bar/index.tsx index f412dd73715619..eb4ff93aac99d1 100644 --- a/x-pack/plugins/cases/public/components/case_action_bar/index.tsx +++ b/x-pack/plugins/cases/public/components/case_action_bar/index.tsx @@ -17,7 +17,7 @@ import { EuiIconTip, } from '@elastic/eui'; import type { CaseUI } from '../../../common/ui/types'; -import type { CaseStatuses } from '../../../common/api'; +import type { CaseStatuses } from '../../../common/types/domain'; import * as i18n from '../case_view/translations'; import { Actions } from './actions'; import { StatusContextMenu } from './status_context_menu'; diff --git a/x-pack/plugins/cases/public/components/case_action_bar/status_context_menu.test.tsx b/x-pack/plugins/cases/public/components/case_action_bar/status_context_menu.test.tsx index 692307229cc847..95d36bb058d797 100644 --- a/x-pack/plugins/cases/public/components/case_action_bar/status_context_menu.test.tsx +++ b/x-pack/plugins/cases/public/components/case_action_bar/status_context_menu.test.tsx @@ -8,7 +8,7 @@ import React from 'react'; import { mount } from 'enzyme'; -import { CaseStatuses } from '../../../common/api'; +import { CaseStatuses } from '../../../common/types/domain'; import { StatusContextMenu } from './status_context_menu'; describe('SyncAlertsSwitch', () => { diff --git a/x-pack/plugins/cases/public/components/case_action_bar/status_context_menu.tsx b/x-pack/plugins/cases/public/components/case_action_bar/status_context_menu.tsx index 9f0270ea85afd4..422cf1aa44b802 100644 --- a/x-pack/plugins/cases/public/components/case_action_bar/status_context_menu.tsx +++ b/x-pack/plugins/cases/public/components/case_action_bar/status_context_menu.tsx @@ -8,8 +8,8 @@ import React, { memo, useCallback, useMemo, useState } from 'react'; import { EuiPopover, EuiContextMenuPanel, EuiContextMenuItem } from '@elastic/eui'; import { Status } from '@kbn/cases-components/src/status/status'; -import type { CaseStatuses } from '../../../common/api'; -import { caseStatuses } from '../../../common/api'; +import type { CaseStatuses } from '../../../common/types/domain'; +import { caseStatuses } from '../../../common/types/domain'; import { StatusPopoverButton } from '../status'; import { CHANGE_STATUS } from '../all_cases/translations'; diff --git a/x-pack/plugins/cases/public/components/case_view/components/assign_users.tsx b/x-pack/plugins/cases/public/components/case_view/components/assign_users.tsx index bd09c49597d9ed..6b29a9df14d91a 100644 --- a/x-pack/plugins/cases/public/components/case_view/components/assign_users.tsx +++ b/x-pack/plugins/cases/public/components/case_view/components/assign_users.tsx @@ -16,9 +16,9 @@ import { } from '@elastic/eui'; import type { UserProfileWithAvatar } from '@kbn/user-profile-components'; +import type { CaseAssignees } from '../../../../common/types/domain'; import type { CasesPermissions } from '../../../../common'; import { useAssignees } from '../../../containers/user_profiles/use_assignees'; -import type { CaseAssignees } from '../../../../common/api/cases/assignee'; import * as i18n from '../translations'; import { SidebarTitle } from './sidebar_title'; import { RemovableUser } from '../../user_profiles/removable_user'; diff --git a/x-pack/plugins/cases/public/components/case_view/components/case_view_activity.tsx b/x-pack/plugins/cases/public/components/case_view/components/case_view_activity.tsx index e3b5395bbd03e5..32dc1be8bbd266 100644 --- a/x-pack/plugins/cases/public/components/case_view/components/case_view_activity.tsx +++ b/x-pack/plugins/cases/public/components/case_view/components/case_view_activity.tsx @@ -16,9 +16,9 @@ import { useGetCaseConnectors } from '../../../containers/use_get_case_connector import { useCasesFeatures } from '../../../common/use_cases_features'; import { useGetCurrentUserProfile } from '../../../containers/user_profiles/use_get_current_user_profile'; import { useGetSupportedActionConnectors } from '../../../containers/configure/use_get_supported_action_connectors'; -import type { CaseSeverity } from '../../../../common/api'; +import type { CaseSeverity, CaseStatuses } from '../../../../common/types/domain'; import type { CaseUsers, UseFetchAlertData } from '../../../../common/ui/types'; -import type { CaseUI, CaseStatuses } from '../../../../common'; +import type { CaseUI } from '../../../../common'; import { EditConnector } from '../../edit_connector'; import type { CasesNavigation } from '../../links'; import { StatusActionButton } from '../../status/button'; diff --git a/x-pack/plugins/cases/public/components/case_view/components/helpers.ts b/x-pack/plugins/cases/public/components/case_view/components/helpers.ts index b3ddc403cc6619..d393054e30f781 100644 --- a/x-pack/plugins/cases/public/components/case_view/components/helpers.ts +++ b/x-pack/plugins/cases/public/components/case_view/components/helpers.ts @@ -5,12 +5,12 @@ * 2.0. */ -import { CommentType } from '../../../../common/api'; -import type { CommentUI } from '../../../containers/types'; +import { AttachmentType } from '../../../../common/types/domain'; +import type { AttachmentUI } from '../../../containers/types'; -export const getManualAlertIds = (comments: CommentUI[]): string[] => { - const dedupeAlerts = comments.reduce((alertIds, comment: CommentUI) => { - if (comment.type === CommentType.alert) { +export const getManualAlertIds = (comments: AttachmentUI[]): string[] => { + const dedupeAlerts = comments.reduce((alertIds, comment: AttachmentUI) => { + if (comment.type === AttachmentType.alert) { const ids = Array.isArray(comment.alertId) ? comment.alertId : [comment.alertId]; ids.forEach((id) => alertIds.add(id)); return alertIds; @@ -20,25 +20,28 @@ export const getManualAlertIds = (comments: CommentUI[]): string[] => { return Array.from(dedupeAlerts); }; -export const getRegistrationContextFromAlerts = (comments: CommentUI[]): string[] => { - const dedupeRegistrationContext = comments.reduce((registrationContexts, comment: CommentUI) => { - if (comment.type === CommentType.alert) { - const indices = Array.isArray(comment.index) ? comment.index : [comment.index]; - indices.forEach((index) => { - // That's legacy code, we created some index alias so everything should work as expected - if (index.startsWith('.siem-signals')) { - registrationContexts.add('security'); - } else { - const registrationContext = getRegistrationContextFromIndex(index); - if (registrationContext) { - registrationContexts.add(registrationContext); +export const getRegistrationContextFromAlerts = (comments: AttachmentUI[]): string[] => { + const dedupeRegistrationContext = comments.reduce( + (registrationContexts, comment: AttachmentUI) => { + if (comment.type === AttachmentType.alert) { + const indices = Array.isArray(comment.index) ? comment.index : [comment.index]; + indices.forEach((index) => { + // That's legacy code, we created some index alias so everything should work as expected + if (index.startsWith('.siem-signals')) { + registrationContexts.add('security'); + } else { + const registrationContext = getRegistrationContextFromIndex(index); + if (registrationContext) { + registrationContexts.add(registrationContext); + } } - } - }); + }); + return registrationContexts; + } return registrationContexts; - } - return registrationContexts; - }, new Set()); + }, + new Set() + ); return Array.from(dedupeRegistrationContext); }; diff --git a/x-pack/plugins/cases/public/components/case_view/use_on_update_field.ts b/x-pack/plugins/cases/public/components/case_view/use_on_update_field.ts index ee9cd2b563b4b3..03747ffd4c5fe8 100644 --- a/x-pack/plugins/cases/public/components/case_view/use_on_update_field.ts +++ b/x-pack/plugins/cases/public/components/case_view/use_on_update_field.ts @@ -8,9 +8,7 @@ import { useCallback, useState } from 'react'; import deepEqual from 'fast-deep-equal'; -import type { CaseConnector } from '../../../common/types/domain'; -import type { CaseAttributes } from '../../../common/api/cases/case'; -import type { CaseStatuses } from '../../../common/api/cases/status'; +import type { CaseStatuses, CaseAttributes, CaseConnector } from '../../../common/types/domain'; import type { CaseUI, UpdateByKey, UpdateKey } from '../../containers/types'; import { useUpdateCase } from '../../containers/use_update_case'; import { getTypedPayload } from '../../containers/utils'; diff --git a/x-pack/plugins/cases/public/components/create/assignees.tsx b/x-pack/plugins/cases/public/components/create/assignees.tsx index 3c5b0bc9b119dc..1e8464dc1a2ed5 100644 --- a/x-pack/plugins/cases/public/components/create/assignees.tsx +++ b/x-pack/plugins/cases/public/components/create/assignees.tsx @@ -24,8 +24,8 @@ import { UseField, getFieldValidityAndErrorMessage, } from '@kbn/es-ui-shared-plugin/static/forms/hook_form_lib'; +import type { CaseAssignees } from '../../../common/types/domain'; import { MAX_ASSIGNEES_PER_CASE } from '../../../common/constants'; -import type { CaseAssignees } from '../../../common/api'; import { useSuggestUserProfiles } from '../../containers/user_profiles/use_suggest_user_profiles'; import { useCasesContext } from '../cases_context/use_cases_context'; import { useGetCurrentUserProfile } from '../../containers/user_profiles/use_get_current_user_profile'; diff --git a/x-pack/plugins/cases/public/components/create/flyout/create_case_flyout.tsx b/x-pack/plugins/cases/public/components/create/flyout/create_case_flyout.tsx index 69a04f0b6b324f..baf3656f122bb8 100644 --- a/x-pack/plugins/cases/public/components/create/flyout/create_case_flyout.tsx +++ b/x-pack/plugins/cases/public/components/create/flyout/create_case_flyout.tsx @@ -11,7 +11,7 @@ import { EuiFlyout, EuiFlyoutHeader, EuiTitle, EuiFlyoutBody } from '@elastic/eu import { ReactQueryDevtools } from '@tanstack/react-query-devtools'; import { noop } from 'lodash'; -import type { CasePostRequest } from '../../../../common/api'; +import type { CasePostRequest } from '../../../../common/types/api'; import * as i18n from '../translations'; import type { CaseUI } from '../../../../common/ui/types'; import { CreateCaseForm } from '../form'; diff --git a/x-pack/plugins/cases/public/components/create/form.tsx b/x-pack/plugins/cases/public/components/create/form.tsx index ff305196e2975e..c36f6a119a5f9f 100644 --- a/x-pack/plugins/cases/public/components/create/form.tsx +++ b/x-pack/plugins/cases/public/components/create/form.tsx @@ -18,13 +18,13 @@ import styled, { css } from 'styled-components'; import { useFormContext } from '@kbn/es-ui-shared-plugin/static/forms/hook_form_lib'; import type { ActionConnector } from '../../../common/types/domain'; +import type { CasePostRequest } from '../../../common/types/api'; import { Title } from './title'; import { Description, fieldName as descriptionFieldName } from './description'; import { Tags } from './tags'; import { Connector } from './connector'; import * as i18n from './translations'; import { SyncAlertsToggle } from './sync_alerts_toggle'; -import type { CasePostRequest } from '../../../common/api'; import type { CaseUI } from '../../containers/types'; import type { CasesTimelineIntegration } from '../timeline_context'; import { CasesTimelineIntegrationProvider } from '../timeline_context'; diff --git a/x-pack/plugins/cases/public/components/create/form_context.test.tsx b/x-pack/plugins/cases/public/components/create/form_context.test.tsx index 048d41241e29e4..758d9d950ce9f1 100644 --- a/x-pack/plugins/cases/public/components/create/form_context.test.tsx +++ b/x-pack/plugins/cases/public/components/create/form_context.test.tsx @@ -10,7 +10,6 @@ import type { Screen } from '@testing-library/react'; import { waitFor, within, screen, act } from '@testing-library/react'; import { waitForEuiPopoverOpen } from '@elastic/eui/lib/test/rtl'; -import { CaseSeverity, CommentType } from '../../../common/api'; import { useKibana } from '../../common/lib/kibana'; import type { AppMockRenderer } from '../../common/mock'; import { createAppMockRenderer } from '../../common/mock'; @@ -48,7 +47,7 @@ import { userProfiles } from '../../containers/user_profiles/api.mock'; import { useLicense } from '../../common/use_license'; import { useGetCategories } from '../../containers/use_get_categories'; import { categories } from '../../containers/mock'; -import { ConnectorTypes } from '../../../common/types/domain'; +import { CaseSeverity, AttachmentType, ConnectorTypes } from '../../../common/types/domain'; jest.mock('../../containers/use_post_case'); jest.mock('../../containers/use_create_attachments'); @@ -716,7 +715,7 @@ describe('Create case', () => { name: 'my rule', }, owner: 'owner', - type: CommentType.alert as const, + type: AttachmentType.alert as const, }, { alertId: '7896', @@ -726,7 +725,7 @@ describe('Create case', () => { name: 'my rule', }, owner: 'second-owner', - type: CommentType.alert as const, + type: AttachmentType.alert as const, }, ]; @@ -792,7 +791,7 @@ describe('Create case', () => { name: 'my rule', }, owner: 'owner', - type: CommentType.alert as const, + type: AttachmentType.alert as const, }, ]; diff --git a/x-pack/plugins/cases/public/components/create/form_context.tsx b/x-pack/plugins/cases/public/components/create/form_context.tsx index e86e6a8bca0ad0..fea7f7a019a864 100644 --- a/x-pack/plugins/cases/public/components/create/form_context.tsx +++ b/x-pack/plugins/cases/public/components/create/form_context.tsx @@ -8,6 +8,7 @@ import React, { useCallback, useMemo } from 'react'; import { Form, useForm } from '@kbn/es-ui-shared-plugin/static/forms/hook_form_lib'; import { NONE_CONNECTOR_ID } from '../../../common/constants'; +import { CaseSeverity } from '../../../common/types/domain'; import type { FormProps } from './schema'; import { schema } from './schema'; import { getNoneConnector, normalizeActionConnector } from '../configure_cases/utils'; @@ -15,8 +16,7 @@ import { usePostCase } from '../../containers/use_post_case'; import { usePostPushToService } from '../../containers/use_post_push_to_service'; import type { CaseUI } from '../../containers/types'; -import type { CasePostRequest } from '../../../common/api'; -import { CaseSeverity } from '../../../common/api'; +import type { CasePostRequest } from '../../../common/types/api'; import type { UseCreateAttachments } from '../../containers/use_create_attachments'; import { useCreateAttachments } from '../../containers/use_create_attachments'; import { useCasesContext } from '../cases_context/use_cases_context'; diff --git a/x-pack/plugins/cases/public/components/create/mock.ts b/x-pack/plugins/cases/public/components/create/mock.ts index 784eebd277e860..ccb11aa0f93e77 100644 --- a/x-pack/plugins/cases/public/components/create/mock.ts +++ b/x-pack/plugins/cases/public/components/create/mock.ts @@ -5,9 +5,8 @@ * 2.0. */ -import { ConnectorTypes } from '../../../common/types/domain'; -import type { CasePostRequest } from '../../../common/api'; -import { CaseSeverity } from '../../../common/api'; +import { CaseSeverity, ConnectorTypes } from '../../../common/types/domain'; +import type { CasePostRequest } from '../../../common/types/api'; import { SECURITY_SOLUTION_OWNER } from '../../../common/constants'; import { choices } from '../connectors/mock'; diff --git a/x-pack/plugins/cases/public/components/create/schema.tsx b/x-pack/plugins/cases/public/components/create/schema.tsx index 86dfa8bc06b90b..778810b0db0045 100644 --- a/x-pack/plugins/cases/public/components/create/schema.tsx +++ b/x-pack/plugins/cases/public/components/create/schema.tsx @@ -9,7 +9,7 @@ import type { FormSchema } from '@kbn/es-ui-shared-plugin/static/forms/hook_form import { FIELD_TYPES, VALIDATION_TYPES } from '@kbn/es-ui-shared-plugin/static/forms/hook_form_lib'; import { fieldValidators } from '@kbn/es-ui-shared-plugin/static/forms/helpers'; import type { ConnectorTypeFields } from '../../../common/types/domain'; -import type { CasePostRequest } from '../../../common/api'; +import type { CasePostRequest } from '../../../common/types/api'; import { MAX_TITLE_LENGTH, MAX_DESCRIPTION_LENGTH, diff --git a/x-pack/plugins/cases/public/components/create/severity.test.tsx b/x-pack/plugins/cases/public/components/create/severity.test.tsx index 629a2e24f7fb5b..328b9b4cd5e00f 100644 --- a/x-pack/plugins/cases/public/components/create/severity.test.tsx +++ b/x-pack/plugins/cases/public/components/create/severity.test.tsx @@ -5,7 +5,7 @@ * 2.0. */ -import { CaseSeverity } from '../../../common/api'; +import { CaseSeverity } from '../../../common/types/domain'; import React from 'react'; import type { AppMockRenderer } from '../../common/mock'; import { createAppMockRenderer } from '../../common/mock'; diff --git a/x-pack/plugins/cases/public/components/create/severity.tsx b/x-pack/plugins/cases/public/components/create/severity.tsx index 3e090272162e85..00c0c3c32642ce 100644 --- a/x-pack/plugins/cases/public/components/create/severity.tsx +++ b/x-pack/plugins/cases/public/components/create/severity.tsx @@ -12,7 +12,7 @@ import { useFormContext, useFormData, } from '@kbn/es-ui-shared-plugin/static/forms/hook_form_lib'; -import { CaseSeverity } from '../../../common/api'; +import { CaseSeverity } from '../../../common/types/domain'; import { SeveritySelector } from '../severity/selector'; import { SEVERITY_TITLE } from '../severity/translations'; diff --git a/x-pack/plugins/cases/public/components/files/add_file.tsx b/x-pack/plugins/cases/public/components/files/add_file.tsx index 0e9c527dc1e07d..ad20db1d51f229 100644 --- a/x-pack/plugins/cases/public/components/files/add_file.tsx +++ b/x-pack/plugins/cases/public/components/files/add_file.tsx @@ -24,7 +24,7 @@ import { FILE_ATTACHMENT_TYPE } from '../../../common/constants'; import { constructFileKindIdByOwner } from '../../../common/files'; import type { Owner } from '../../../common/constants/types'; -import { CommentType, ExternalReferenceStorageType } from '../../../common'; +import { AttachmentType, ExternalReferenceStorageType } from '../../../common'; import { useCasesToast } from '../../common/use_cases_toast'; import { useCreateAttachments } from '../../containers/use_create_attachments'; import { useCasesContext } from '../cases_context/use_cases_context'; @@ -70,7 +70,7 @@ const AddFileComponent: React.FC = ({ caseId }) => { caseOwner: owner[0], attachments: [ { - type: CommentType.externalReference, + type: AttachmentType.externalReference, externalReferenceId: file.id, externalReferenceStorage: { type: ExternalReferenceStorageType.savedObject, diff --git a/x-pack/plugins/cases/public/components/files/types.ts b/x-pack/plugins/cases/public/components/files/types.ts index a211b5ac4053d7..41d83a800c7ffa 100644 --- a/x-pack/plugins/cases/public/components/files/types.ts +++ b/x-pack/plugins/cases/public/components/files/types.ts @@ -6,7 +6,6 @@ */ import type * as rt from 'io-ts'; - -import type { SingleFileAttachmentMetadataRt } from '../../../common/api'; +import type { SingleFileAttachmentMetadataRt } from '../../../common/types/domain'; export type DownloadableFile = rt.TypeOf & { id: string }; diff --git a/x-pack/plugins/cases/public/components/files/utils.tsx b/x-pack/plugins/cases/public/components/files/utils.tsx index 7f7ed09f298745..09d063b19f2bcf 100644 --- a/x-pack/plugins/cases/public/components/files/utils.tsx +++ b/x-pack/plugins/cases/public/components/files/utils.tsx @@ -6,9 +6,10 @@ */ import type { - CommentRequestExternalReferenceType, + ExternalReferenceAttachmentPayload, FileAttachmentMetadata, -} from '../../../common/api'; +} from '../../../common/types/domain'; +import { FileAttachmentMetadataRt } from '../../../common/types/domain'; import { compressionMimeTypes, @@ -16,7 +17,6 @@ import { textMimeTypes, pdfMimeTypes, } from '../../../common/constants/mime_types'; -import { FileAttachmentMetadataRt } from '../../../common/api'; import * as i18n from './translations'; export const isImage = (file: { mimeType?: string }) => file.mimeType?.startsWith('image/'); @@ -52,7 +52,7 @@ export const parseMimeType = (mimeType: string | undefined) => { }; export const isValidFileExternalReferenceMetadata = ( - externalReferenceMetadata: CommentRequestExternalReferenceType['externalReferenceMetadata'] + externalReferenceMetadata: ExternalReferenceAttachmentPayload['externalReferenceMetadata'] ): externalReferenceMetadata is FileAttachmentMetadata => { return ( FileAttachmentMetadataRt.is(externalReferenceMetadata) && diff --git a/x-pack/plugins/cases/public/components/recent_cases/get_filter_options.test.ts b/x-pack/plugins/cases/public/components/recent_cases/get_filter_options.test.ts index 6f1d03040667f9..c2e95a365fa0e1 100644 --- a/x-pack/plugins/cases/public/components/recent_cases/get_filter_options.test.ts +++ b/x-pack/plugins/cases/public/components/recent_cases/get_filter_options.test.ts @@ -5,10 +5,10 @@ * 2.0. */ -import type { User } from '../../../common/api'; import { userProfiles } from '../../containers/user_profiles/api.mock'; import { getReporterFilter, getAssigneeFilter } from './get_filter_options'; import type { ReporterFilter, AssigneeFilter } from './get_filter_options'; +import type { User } from '../../../common/types/domain'; describe('filter options', () => { const currentUserProfile = userProfiles[0]; diff --git a/x-pack/plugins/cases/public/components/recent_cases/get_filter_options.ts b/x-pack/plugins/cases/public/components/recent_cases/get_filter_options.ts index f837065f88865f..737032af3bc128 100644 --- a/x-pack/plugins/cases/public/components/recent_cases/get_filter_options.ts +++ b/x-pack/plugins/cases/public/components/recent_cases/get_filter_options.ts @@ -6,8 +6,8 @@ */ import type { UserProfile } from '@kbn/user-profile-components'; +import type { User } from '../../../common/types/domain'; import type { AuthenticatedElasticUser } from '../../common/lib/kibana'; -import type { User } from '../../../common/api'; import type { FilterMode as RecentCasesFilterMode } from './types'; export interface ReporterFilter { diff --git a/x-pack/plugins/cases/public/components/severity/config.ts b/x-pack/plugins/cases/public/components/severity/config.ts index e22f7bda54665a..6169cfb14d5b35 100644 --- a/x-pack/plugins/cases/public/components/severity/config.ts +++ b/x-pack/plugins/cases/public/components/severity/config.ts @@ -6,7 +6,7 @@ */ import { euiLightVars } from '@kbn/ui-theme'; -import { CaseSeverity } from '../../../common/api'; +import { CaseSeverity } from '../../../common/types/domain'; import { SeverityAll } from '../../containers/types'; import { ALL_SEVERITIES, CRITICAL, HIGH, LOW, MEDIUM } from './translations'; diff --git a/x-pack/plugins/cases/public/components/severity/selector.test.tsx b/x-pack/plugins/cases/public/components/severity/selector.test.tsx index 6f9d4f366ccd7f..9160a87ee3bd58 100644 --- a/x-pack/plugins/cases/public/components/severity/selector.test.tsx +++ b/x-pack/plugins/cases/public/components/severity/selector.test.tsx @@ -5,7 +5,7 @@ * 2.0. */ -import { CaseSeverity } from '../../../common/api'; +import { CaseSeverity } from '../../../common/types/domain'; import { render } from '@testing-library/react'; import { waitForEuiPopoverOpen } from '@elastic/eui/lib/test/rtl'; import React from 'react'; diff --git a/x-pack/plugins/cases/public/components/severity/selector.tsx b/x-pack/plugins/cases/public/components/severity/selector.tsx index 63cd57e1925cdc..90e38fc0a9c166 100644 --- a/x-pack/plugins/cases/public/components/severity/selector.tsx +++ b/x-pack/plugins/cases/public/components/severity/selector.tsx @@ -8,7 +8,7 @@ import type { EuiSuperSelectOption } from '@elastic/eui'; import { EuiFlexGroup, EuiFlexItem, EuiHealth, EuiSuperSelect } from '@elastic/eui'; import React from 'react'; -import type { CaseSeverity } from '../../../common/api'; +import type { CaseSeverity } from '../../../common/types/domain'; import { severities } from './config'; interface Props { diff --git a/x-pack/plugins/cases/public/components/severity/sidebar_selector.tsx b/x-pack/plugins/cases/public/components/severity/sidebar_selector.tsx index 741508942d4623..c9f0897f5d8bd4 100644 --- a/x-pack/plugins/cases/public/components/severity/sidebar_selector.tsx +++ b/x-pack/plugins/cases/public/components/severity/sidebar_selector.tsx @@ -7,7 +7,7 @@ import { EuiFlexItem, EuiHorizontalRule, EuiText } from '@elastic/eui'; import React from 'react'; -import type { CaseSeverity } from '../../../common/api'; +import type { CaseSeverity } from '../../../common/types/domain'; import { SeveritySelector } from './selector'; import { SEVERITY_TITLE } from './translations'; diff --git a/x-pack/plugins/cases/public/components/status/button.test.tsx b/x-pack/plugins/cases/public/components/status/button.test.tsx index 32df83b4b2ddf7..3e575ee8e3f676 100644 --- a/x-pack/plugins/cases/public/components/status/button.test.tsx +++ b/x-pack/plugins/cases/public/components/status/button.test.tsx @@ -8,7 +8,7 @@ import React from 'react'; import { mount } from 'enzyme'; -import { CaseStatuses } from '../../../common/api'; +import { CaseStatuses } from '../../../common/types/domain'; import { StatusActionButton } from './button'; describe('StatusActionButton', () => { diff --git a/x-pack/plugins/cases/public/components/status/button.tsx b/x-pack/plugins/cases/public/components/status/button.tsx index bed36942ed6e8c..e67d66a657e90e 100644 --- a/x-pack/plugins/cases/public/components/status/button.tsx +++ b/x-pack/plugins/cases/public/components/status/button.tsx @@ -8,8 +8,8 @@ import React, { memo, useCallback, useMemo } from 'react'; import { EuiButton } from '@elastic/eui'; -import type { CaseStatuses } from '../../../common/api'; -import { caseStatuses } from '../../../common/api'; +import type { CaseStatuses } from '../../../common/types/domain'; +import { caseStatuses } from '../../../common/types/domain'; import { statuses } from './config'; interface Props { diff --git a/x-pack/plugins/cases/public/components/status/config.ts b/x-pack/plugins/cases/public/components/status/config.ts index f1e9a97144d739..d6f66515580c1c 100644 --- a/x-pack/plugins/cases/public/components/status/config.ts +++ b/x-pack/plugins/cases/public/components/status/config.ts @@ -6,7 +6,7 @@ */ import { getStatusConfiguration } from '@kbn/cases-components/src/status/config'; import { StatusAll } from '../../../common/ui/types'; -import { CaseStatuses } from '../../../common/api'; +import { CaseStatuses } from '../../../common/types/domain'; import * as i18n from './translations'; import type { AllCaseStatus, Statuses } from './types'; diff --git a/x-pack/plugins/cases/public/components/status/status_popover_button.test.tsx b/x-pack/plugins/cases/public/components/status/status_popover_button.test.tsx index 7e157a0939dda5..04de1845f450db 100644 --- a/x-pack/plugins/cases/public/components/status/status_popover_button.test.tsx +++ b/x-pack/plugins/cases/public/components/status/status_popover_button.test.tsx @@ -7,7 +7,7 @@ import React from 'react'; import { mount } from 'enzyme'; -import { CaseStatuses } from '../../../common/api'; +import { CaseStatuses } from '../../../common/types/domain'; import { StatusPopoverButton } from './status_popover_button'; describe('StatusPopoverButton', () => { diff --git a/x-pack/plugins/cases/public/components/status/status_stats.test.tsx b/x-pack/plugins/cases/public/components/status/status_stats.test.tsx index 28292496dd9178..e24e3019f8b9c0 100644 --- a/x-pack/plugins/cases/public/components/status/status_stats.test.tsx +++ b/x-pack/plugins/cases/public/components/status/status_stats.test.tsx @@ -8,7 +8,7 @@ import React from 'react'; import { mount } from 'enzyme'; -import { CaseStatuses } from '../../../common/api'; +import { CaseStatuses } from '../../../common/types/domain'; import { StatusStats } from './status_stats'; describe('Stats', () => { diff --git a/x-pack/plugins/cases/public/components/status/status_stats.tsx b/x-pack/plugins/cases/public/components/status/status_stats.tsx index 515c095b24c281..1f1686c26a4dbb 100644 --- a/x-pack/plugins/cases/public/components/status/status_stats.tsx +++ b/x-pack/plugins/cases/public/components/status/status_stats.tsx @@ -7,7 +7,7 @@ import React, { memo, useMemo } from 'react'; import { EuiDescriptionList, EuiLoadingSpinner } from '@elastic/eui'; -import type { CaseStatuses } from '../../../common/api'; +import type { CaseStatuses } from '../../../common/types/domain'; import { statuses } from './config'; export interface Props { diff --git a/x-pack/plugins/cases/public/components/status/types.ts b/x-pack/plugins/cases/public/components/status/types.ts index 1bd8b553593b6d..b871e51b78f664 100644 --- a/x-pack/plugins/cases/public/components/status/types.ts +++ b/x-pack/plugins/cases/public/components/status/types.ts @@ -6,8 +6,8 @@ */ import type { EuiIconType } from '@elastic/eui/src/components/icon/icon'; +import type { CaseStatuses } from '../../../common/types/domain'; import type { StatusAllType } from '../../../common/ui/types'; -import type { CaseStatuses } from '../../../common/api'; export type AllCaseStatus = Record; diff --git a/x-pack/plugins/cases/public/components/use_push_to_service/index.test.tsx b/x-pack/plugins/cases/public/components/use_push_to_service/index.test.tsx index 3d430cceaacc6f..7b2a30df151719 100644 --- a/x-pack/plugins/cases/public/components/use_push_to_service/index.test.tsx +++ b/x-pack/plugins/cases/public/components/use_push_to_service/index.test.tsx @@ -12,15 +12,14 @@ import '../../common/mock/match_media'; import type { ReturnUsePushToService, UsePushToService } from '.'; import { usePushToService } from '.'; import { noPushCasesPermissions, readCasesPermissions, TestProviders } from '../../common/mock'; -import type { CaseConnector } from '../../../common/types/domain'; -import { ConnectorTypes } from '../../../common/types/domain'; -import { CaseStatuses } from '../../../common/api'; import { usePostPushToService } from '../../containers/use_post_push_to_service'; import { actionLicenses } from '../../containers/mock'; import { CLOSED_CASE_PUSH_ERROR_ID } from './callout/types'; import { useGetActionLicense } from '../../containers/use_get_action_license'; import { getCaseConnectorsMockResponse } from '../../common/mock/connectors'; import { useRefreshCaseViewPage } from '../case_view/use_on_refresh_case_view_page'; +import { CaseStatuses, ConnectorTypes } from '../../../common/types/domain'; +import type { CaseConnector } from '../../../common/types/domain'; jest.mock('../../containers/use_get_action_license', () => { return { diff --git a/x-pack/plugins/cases/public/components/use_push_to_service/index.tsx b/x-pack/plugins/cases/public/components/use_push_to_service/index.tsx index db28ae31ecdbe0..63a016964651e5 100644 --- a/x-pack/plugins/cases/public/components/use_push_to_service/index.tsx +++ b/x-pack/plugins/cases/public/components/use_push_to_service/index.tsx @@ -16,7 +16,7 @@ import { getCaseClosedInfo, } from './helpers'; import type { CaseConnector } from '../../../common/types/domain'; -import { CaseStatuses } from '../../../common/api'; +import { CaseStatuses } from '../../../common/types/domain'; import type { ErrorMessage } from './callout/types'; import { useRefreshCaseViewPage } from '../case_view/use_on_refresh_case_view_page'; import { useGetActionLicense } from '../../containers/use_get_action_license'; diff --git a/x-pack/plugins/cases/public/components/user_actions/assignees.tsx b/x-pack/plugins/cases/public/components/user_actions/assignees.tsx index e17c60195dc060..cd94615ad066c1 100644 --- a/x-pack/plugins/cases/public/components/user_actions/assignees.tsx +++ b/x-pack/plugins/cases/public/components/user_actions/assignees.tsx @@ -8,10 +8,9 @@ import { EuiFlexGroup, EuiFlexItem, EuiText } from '@elastic/eui'; import type { UserProfileWithAvatar } from '@kbn/user-profile-components'; import React, { memo } from 'react'; -import type { AssigneesUserAction } from '../../../common/types/domain'; +import type { AssigneesUserAction, User } from '../../../common/types/domain'; import { UserActionActions } from '../../../common/types/domain'; import type { SnakeToCamelCase } from '../../../common/types'; -import type { User } from '../../../common/api'; import { getName } from '../user_profiles/display_name'; import type { Assignee } from '../user_profiles/types'; import { UserToolTip } from '../user_profiles/user_tooltip'; diff --git a/x-pack/plugins/cases/public/components/user_actions/comment/actions.tsx b/x-pack/plugins/cases/public/components/user_actions/comment/actions.tsx index d4086805d7cd9a..e212456a84fa3a 100644 --- a/x-pack/plugins/cases/public/components/user_actions/comment/actions.tsx +++ b/x-pack/plugins/cases/public/components/user_actions/comment/actions.tsx @@ -8,7 +8,7 @@ import React from 'react'; import classNames from 'classnames'; -import type { CommentResponseActionsType } from '../../../../common/api'; +import type { ActionsAttachment } from '../../../../common/types/domain'; import type { UserActionBuilder, UserActionBuilderArgs } from '../types'; import { UserActionTimestamp } from '../timestamp'; import type { SnakeToCamelCase } from '../../../../common/types'; @@ -21,7 +21,7 @@ type BuilderArgs = Pick< UserActionBuilderArgs, 'userAction' | 'actionsNavigation' | 'userProfiles' > & { - comment: SnakeToCamelCase; + comment: SnakeToCamelCase; }; export const createActionAttachmentUserActionBuilder = ({ diff --git a/x-pack/plugins/cases/public/components/user_actions/comment/alert.test.tsx b/x-pack/plugins/cases/public/components/user_actions/comment/alert.test.tsx index 0edb463860f068..31cb83bee6fe13 100644 --- a/x-pack/plugins/cases/public/components/user_actions/comment/alert.test.tsx +++ b/x-pack/plugins/cases/public/components/user_actions/comment/alert.test.tsx @@ -6,10 +6,10 @@ */ import { omit, merge } from 'lodash'; -import type { CommentResponseAlertsType } from '../../../../common/api'; import type { SnakeToCamelCase } from '../../../../common/types'; import { getRuleId, getRuleInfo, getRuleName } from './alert'; import type { Ecs } from '../../../containers/types'; +import type { AlertAttachment } from '../../../../common/types/domain'; describe('rule getters', () => { describe.each([ @@ -22,7 +22,7 @@ describe('rule getters', () => { id: '', name: '', }, - } as unknown as SnakeToCamelCase; + } as unknown as SnakeToCamelCase; expect(funcToExec(comment)).toBeNull(); }); @@ -33,19 +33,19 @@ describe('rule getters', () => { id: [''], name: [''], }, - } as unknown as SnakeToCamelCase; + } as unknown as SnakeToCamelCase; expect(funcToExec(comment)).toBeNull(); }); it('returns null if the comment does not have a rule field', () => { - const comment = {} as unknown as SnakeToCamelCase; + const comment = {} as unknown as SnakeToCamelCase; expect(funcToExec(comment)).toBeNull(); }); it('returns null if the signals and alert field is an empty string', () => { - const comment = {} as unknown as SnakeToCamelCase; + const comment = {} as unknown as SnakeToCamelCase; const alert = { signal: { rule: { id: '', name: '' } }, kibana: { alert: { rule: { uuid: '', name: '' } } }, @@ -65,20 +65,20 @@ describe('rule getters', () => { id: ['1', '2'], name: ['Rule name1', 'Rule name2'], }, - } as unknown as SnakeToCamelCase; + } as unknown as SnakeToCamelCase; expect(funcToExec(comment)).toEqual(expectedResult); }); it('returns signal field', () => { - const comment = {} as unknown as SnakeToCamelCase; + const comment = {} as unknown as SnakeToCamelCase; const alert = { signal: { rule: { id: '1', name: 'Rule name1' } } } as unknown as Ecs; expect(funcToExec(comment, alert)).toEqual(expectedResult); }); it('returns kibana alert field', () => { - const comment = {} as unknown as SnakeToCamelCase; + const comment = {} as unknown as SnakeToCamelCase; const alert = { kibana: { alert: { rule: { uuid: '1', name: 'Rule name1' } } }, } as unknown as Ecs; @@ -87,7 +87,7 @@ describe('rule getters', () => { }); it('returns signal field even when kibana alert field is defined', () => { - const comment = {} as unknown as SnakeToCamelCase; + const comment = {} as unknown as SnakeToCamelCase; const alert = { signal: { rule: { id: '1', name: 'Rule name1' } }, kibana: { alert: { rule: { uuid: 'rule id1', name: 'other rule name1' } } }, @@ -97,7 +97,7 @@ describe('rule getters', () => { }); it('returns the first entry in the signals field', () => { - const comment = {} as unknown as SnakeToCamelCase; + const comment = {} as unknown as SnakeToCamelCase; const alert = { signal: { rule: { id: '1', name: 'Rule name1' } }, kibana: { alert: { rule: { uuid: 'rule id1', name: 'other rule name1' } } }, @@ -107,7 +107,7 @@ describe('rule getters', () => { }); it('returns the alert field if the signals field is an empty string', () => { - const comment = {} as unknown as SnakeToCamelCase; + const comment = {} as unknown as SnakeToCamelCase; const alert = { signal: { rule: { id: '', name: '' } }, kibana: { alert: { rule: { uuid: '1', name: 'Rule name1' } } }, @@ -117,7 +117,7 @@ describe('rule getters', () => { }); it('returns the alert field if the signals field is an empty string in an array', () => { - const comment = {} as unknown as SnakeToCamelCase; + const comment = {} as unknown as SnakeToCamelCase; const alert = { signal: { rule: { id: [''], name: [''] } }, kibana: { alert: { rule: { uuid: '1', name: 'Rule name1' } } }, @@ -127,7 +127,7 @@ describe('rule getters', () => { }); it('returns the alert field first item if the signals field is an empty string in an array', () => { - const comment = {} as unknown as SnakeToCamelCase; + const comment = {} as unknown as SnakeToCamelCase; const alert = { signal: { rule: { id: [''], name: [''] } }, kibana: { alert: { rule: { uuid: ['1', '2'], name: ['Rule name1', 'Rule name2'] } } }, @@ -145,7 +145,7 @@ describe('rule getters', () => { id: '1', name: 'Rule name1', }, - } as unknown as SnakeToCamelCase; + } as unknown as SnakeToCamelCase; const signal = { rule: { id: '1', name: 'Rule name1' } }; const kibana = { alert: { rule: { uuid: 'rule id1', name: 'other rule name1' } } }; @@ -192,11 +192,7 @@ describe('rule getters', () => { { 'alert-id-1': { kibana } }, ], ] as Array< - [ - Record, - SnakeToCamelCase, - Record - ] + [Record, SnakeToCamelCase, Record] >; it.each(tests)('returns the correct rule info: %s', (expectedResult, comment, alert) => { diff --git a/x-pack/plugins/cases/public/components/user_actions/comment/alert.tsx b/x-pack/plugins/cases/public/components/user_actions/comment/alert.tsx index 1885dd6b160df2..9a405d8b0365da 100644 --- a/x-pack/plugins/cases/public/components/user_actions/comment/alert.tsx +++ b/x-pack/plugins/cases/public/components/user_actions/comment/alert.tsx @@ -11,7 +11,7 @@ import type { EuiCommentProps } from '@elastic/eui'; import { EuiFlexItem } from '@elastic/eui'; import { ALERT_RULE_NAME, ALERT_RULE_UUID } from '@kbn/rule-data-utils'; -import type { CommentResponseAlertsType } from '../../../../common/api'; +import type { AlertAttachment } from '../../../../common/types/domain'; import type { UserActionBuilder, UserActionBuilderArgs } from '../types'; import { UserActionTimestamp } from '../timestamp'; import type { SnakeToCamelCase } from '../../../../common/types'; @@ -34,7 +34,7 @@ type BuilderArgs = Pick< | 'userProfiles' | 'handleDeleteComment' | 'loadingCommentIds' -> & { comment: SnakeToCamelCase }; +> & { comment: SnakeToCamelCase }; const getSingleAlertUserAction = ({ userAction, diff --git a/x-pack/plugins/cases/public/components/user_actions/comment/comment.tsx b/x-pack/plugins/cases/public/components/user_actions/comment/comment.tsx index 16c9189aceb89c..3576364f8ecd76 100644 --- a/x-pack/plugins/cases/public/components/user_actions/comment/comment.tsx +++ b/x-pack/plugins/cases/public/components/user_actions/comment/comment.tsx @@ -9,19 +9,18 @@ import type { EuiCommentProps } from '@elastic/eui'; import type { SnakeToCamelCase } from '../../../../common/types'; import type { CommentUserAction } from '../../../../common/types/domain'; -import { UserActionActions } from '../../../../common/types/domain'; +import { UserActionActions, AttachmentType } from '../../../../common/types/domain'; import type { AttachmentTypeRegistry } from '../../../../common/registry'; -import { CommentType } from '../../../../common/api'; import type { UserActionBuilder, UserActionBuilderArgs } from '../types'; import { createCommonUpdateUserActionBuilder } from '../common'; -import type { CommentUI } from '../../../containers/types'; +import type { AttachmentUI } from '../../../containers/types'; import * as i18n from './translations'; import { createUserAttachmentUserActionBuilder } from './user'; import { createAlertAttachmentUserActionBuilder } from './alert'; import { createActionAttachmentUserActionBuilder } from './actions'; import { createExternalReferenceAttachmentUserActionBuilder } from './external_reference'; import { createPersistableStateAttachmentUserActionBuilder } from './persistable_state'; -import type { AttachmentType } from '../../../client/attachment_framework/types'; +import type { AttachmentType as AttachmentFrameworkAttachmentType } from '../../../client/attachment_framework/types'; const getUpdateLabelTitle = () => `${i18n.EDITED_FIELD} ${i18n.COMMENT.toLowerCase()}`; @@ -40,14 +39,14 @@ const getDeleteLabelTitle = ({ }: DeleteLabelTitle) => { const { comment } = userAction.payload; - if (comment.type === CommentType.alert) { + if (comment.type === AttachmentType.alert) { const totalAlerts = Array.isArray(comment.alertId) ? comment.alertId.length : 1; const alertLabel = i18n.MULTIPLE_ALERTS(totalAlerts); return `${i18n.REMOVED_FIELD} ${alertLabel}`; } - if (comment.type === CommentType.externalReference) { + if (comment.type === AttachmentType.externalReference) { return getDeleteLabelFromRegistry({ caseData, registry: externalReferenceAttachmentTypeRegistry, @@ -59,7 +58,7 @@ const getDeleteLabelTitle = ({ }); } - if (comment.type === CommentType.persistableState) { + if (comment.type === AttachmentType.persistableState) { return getDeleteLabelFromRegistry({ caseData, registry: persistableStateAttachmentTypeRegistry, @@ -77,7 +76,7 @@ const getDeleteLabelTitle = ({ interface GetDeleteLabelFromRegistryArgs { caseData: UserActionBuilderArgs['caseData']; // eslint-disable-next-line @typescript-eslint/no-explicit-any - registry: AttachmentTypeRegistry>; + registry: AttachmentTypeRegistry>; getId: () => string; getAttachmentProps: () => object; } @@ -166,13 +165,13 @@ const getCreateCommentUserAction = ({ actionsNavigation, }: { userAction: SnakeToCamelCase; - comment: CommentUI; + comment: AttachmentUI; } & Omit< UserActionBuilderArgs, 'comments' | 'index' | 'handleOutlineComment' | 'currentUserProfile' >): EuiCommentProps[] => { switch (comment.type) { - case CommentType.user: + case AttachmentType.user: const userBuilder = createUserAttachmentUserActionBuilder({ appId, userProfiles, @@ -190,7 +189,7 @@ const getCreateCommentUserAction = ({ return userBuilder.build(); - case CommentType.alert: + case AttachmentType.alert: const alertBuilder = createAlertAttachmentUserActionBuilder({ userProfiles, alertData, @@ -206,7 +205,7 @@ const getCreateCommentUserAction = ({ return alertBuilder.build(); - case CommentType.actions: + case AttachmentType.actions: const actionBuilder = createActionAttachmentUserActionBuilder({ userProfiles, userAction, @@ -216,7 +215,7 @@ const getCreateCommentUserAction = ({ return actionBuilder.build(); - case CommentType.externalReference: + case AttachmentType.externalReference: const externalReferenceBuilder = createExternalReferenceAttachmentUserActionBuilder({ userAction, userProfiles, @@ -229,7 +228,7 @@ const getCreateCommentUserAction = ({ return externalReferenceBuilder.build(); - case CommentType.persistableState: + case AttachmentType.persistableState: const persistableBuilder = createPersistableStateAttachmentUserActionBuilder({ userAction, userProfiles, diff --git a/x-pack/plugins/cases/public/components/user_actions/comment/external_reference.tsx b/x-pack/plugins/cases/public/components/user_actions/comment/external_reference.tsx index 8e4f627fd73f4b..2ea7e3af6fae63 100644 --- a/x-pack/plugins/cases/public/components/user_actions/comment/external_reference.tsx +++ b/x-pack/plugins/cases/public/components/user_actions/comment/external_reference.tsx @@ -5,7 +5,7 @@ * 2.0. */ -import type { CommentResponseExternalReferenceType } from '../../../../common/api'; +import type { ExternalReferenceAttachment } from '../../../../common/types/domain'; import type { UserActionBuilder, UserActionBuilderArgs } from '../types'; import type { SnakeToCamelCase } from '../../../../common/types'; import { createRegisteredAttachmentUserActionBuilder } from './registered_attachments'; @@ -18,7 +18,7 @@ type BuilderArgs = Pick< | 'handleDeleteComment' | 'userProfiles' > & { - comment: SnakeToCamelCase; + comment: SnakeToCamelCase; isLoading: boolean; }; diff --git a/x-pack/plugins/cases/public/components/user_actions/comment/persistable_state.tsx b/x-pack/plugins/cases/public/components/user_actions/comment/persistable_state.tsx index 040fbe794580d7..0443f67612c4ac 100644 --- a/x-pack/plugins/cases/public/components/user_actions/comment/persistable_state.tsx +++ b/x-pack/plugins/cases/public/components/user_actions/comment/persistable_state.tsx @@ -5,7 +5,7 @@ * 2.0. */ -import type { CommentResponseTypePersistableState } from '../../../../common/api'; +import type { PersistableStateAttachment } from '../../../../common/types/domain'; import type { UserActionBuilder, UserActionBuilderArgs } from '../types'; import type { SnakeToCamelCase } from '../../../../common/types'; import { createRegisteredAttachmentUserActionBuilder } from './registered_attachments'; @@ -18,7 +18,7 @@ type BuilderArgs = Pick< | 'handleDeleteComment' | 'userProfiles' > & { - comment: SnakeToCamelCase; + comment: SnakeToCamelCase; isLoading: boolean; }; diff --git a/x-pack/plugins/cases/public/components/user_actions/comment/registered_attachments.tsx b/x-pack/plugins/cases/public/components/user_actions/comment/registered_attachments.tsx index beb74a87bff9d9..ef52e0c566155c 100644 --- a/x-pack/plugins/cases/public/components/user_actions/comment/registered_attachments.tsx +++ b/x-pack/plugins/cases/public/components/user_actions/comment/registered_attachments.tsx @@ -25,7 +25,7 @@ import type { import { AttachmentActionType } from '../../../client/attachment_framework/types'; import { UserActionTimestamp } from '../timestamp'; import type { AttachmentTypeRegistry } from '../../../../common/registry'; -import type { Comment } from '../../../../common/api'; +import type { Attachment } from '../../../../common/types/domain'; import type { UserActionBuilder, UserActionBuilderArgs } from '../types'; import type { SnakeToCamelCase } from '../../../../common/types'; import { @@ -76,7 +76,7 @@ const getAttachmentRenderer = memoize((cachingKey: string) => { }); export const createRegisteredAttachmentUserActionBuilder = < - C extends Comment, + C extends Attachment, // eslint-disable-next-line @typescript-eslint/no-explicit-any R extends AttachmentTypeRegistry> >({ diff --git a/x-pack/plugins/cases/public/components/user_actions/comment/user.tsx b/x-pack/plugins/cases/public/components/user_actions/comment/user.tsx index 119ae2b9039b33..c456e4046765cf 100644 --- a/x-pack/plugins/cases/public/components/user_actions/comment/user.tsx +++ b/x-pack/plugins/cases/public/components/user_actions/comment/user.tsx @@ -10,7 +10,7 @@ import classNames from 'classnames'; import styled from 'styled-components'; import { EuiText } from '@elastic/eui'; -import type { CommentResponseUserType } from '../../../../common/api'; +import type { UserCommentAttachment } from '../../../../common/types/domain'; import { UserActionTimestamp } from '../timestamp'; import type { SnakeToCamelCase } from '../../../../common/types'; import { UserActionMarkdown } from '../markdown_form'; @@ -32,7 +32,7 @@ type BuilderArgs = Pick< | 'userProfiles' | 'appId' > & { - comment: SnakeToCamelCase; + comment: SnakeToCamelCase; caseId: string; outlined: boolean; isEdit: boolean; diff --git a/x-pack/plugins/cases/public/components/user_actions/helpers.test.ts b/x-pack/plugins/cases/public/components/user_actions/helpers.test.ts index 0e84b9463694b3..a0ffa279530343 100644 --- a/x-pack/plugins/cases/public/components/user_actions/helpers.test.ts +++ b/x-pack/plugins/cases/public/components/user_actions/helpers.test.ts @@ -5,14 +5,14 @@ * 2.0. */ -import { CommentType } from '../../../common/api'; +import { AttachmentType } from '../../../common/types/domain'; import { SECURITY_SOLUTION_OWNER } from '../../../common/constants'; -import type { CommentUI } from '../../containers/types'; +import type { AttachmentUI } from '../../containers/types'; import { isUserActionTypeSupported, getManualAlertIdsWithNoRuleId } from './helpers'; -const comments: CommentUI[] = [ +const comments: AttachmentUI[] = [ { - type: CommentType.alert, + type: AttachmentType.alert, alertId: 'alert-id-1', index: 'alert-index-1', id: 'comment-id', @@ -30,7 +30,7 @@ const comments: CommentUI[] = [ owner: SECURITY_SOLUTION_OWNER, }, { - type: CommentType.alert, + type: AttachmentType.alert, alertId: 'alert-id-2', index: 'alert-index-2', id: 'comment-id', diff --git a/x-pack/plugins/cases/public/components/user_actions/helpers.ts b/x-pack/plugins/cases/public/components/user_actions/helpers.ts index a3bd67bd6e6550..e00bdfbe53784f 100644 --- a/x-pack/plugins/cases/public/components/user_actions/helpers.ts +++ b/x-pack/plugins/cases/public/components/user_actions/helpers.ts @@ -7,17 +7,17 @@ import { isEmpty } from 'lodash'; -import { CommentType } from '../../../common/api'; -import type { CommentUI } from '../../containers/types'; +import { AttachmentType } from '../../../common/types/domain'; +import type { AttachmentUI } from '../../containers/types'; import { SUPPORTED_ACTION_TYPES } from './constants'; import type { SupportedUserActionTypes } from './types'; export const isUserActionTypeSupported = (type: string): type is SupportedUserActionTypes => SUPPORTED_ACTION_TYPES.includes(type as SupportedUserActionTypes); -export const getManualAlertIdsWithNoRuleId = (comments: CommentUI[]): string[] => { - const dedupeAlerts = comments.reduce((alertIds, comment: CommentUI) => { - if (comment.type === CommentType.alert && isEmpty(comment.rule.id)) { +export const getManualAlertIdsWithNoRuleId = (comments: AttachmentUI[]): string[] => { + const dedupeAlerts = comments.reduce((alertIds, comment: AttachmentUI) => { + if (comment.type === AttachmentType.alert && isEmpty(comment.rule.id)) { const ids = Array.isArray(comment.alertId) ? comment.alertId : [comment.alertId]; ids.forEach((id) => alertIds.add(id)); return alertIds; diff --git a/x-pack/plugins/cases/public/components/user_actions/severity.test.tsx b/x-pack/plugins/cases/public/components/user_actions/severity.test.tsx index 8bbfa3946a79b2..4ac3f94b10acc0 100644 --- a/x-pack/plugins/cases/public/components/user_actions/severity.test.tsx +++ b/x-pack/plugins/cases/public/components/user_actions/severity.test.tsx @@ -6,14 +6,13 @@ */ import { EuiCommentList } from '@elastic/eui'; -import { CaseSeverity } from '../../../common/api'; +import { CaseSeverity, UserActionActions } from '../../../common/types/domain'; import React from 'react'; import type { AppMockRenderer } from '../../common/mock'; import { createAppMockRenderer } from '../../common/mock'; import { getUserAction } from '../../containers/mock'; import { getMockBuilderArgs } from './mock'; import { createSeverityUserActionBuilder } from './severity'; -import { UserActionActions } from '../../../common/types/domain'; jest.mock('../../common/lib/kibana'); jest.mock('../../common/navigation/hooks'); diff --git a/x-pack/plugins/cases/public/components/user_actions/status.test.tsx b/x-pack/plugins/cases/public/components/user_actions/status.test.tsx index f6f80758db9cd8..79ed2f79eddfaf 100644 --- a/x-pack/plugins/cases/public/components/user_actions/status.test.tsx +++ b/x-pack/plugins/cases/public/components/user_actions/status.test.tsx @@ -9,12 +9,11 @@ import React from 'react'; import { EuiCommentList } from '@elastic/eui'; import { render, screen } from '@testing-library/react'; -import { CaseStatuses } from '../../../common/api'; +import { CaseStatuses, UserActionActions } from '../../../common/types/domain'; import { getUserAction } from '../../containers/mock'; import { TestProviders } from '../../common/mock'; import { createStatusUserActionBuilder } from './status'; import { getMockBuilderArgs } from './mock'; -import { UserActionActions } from '../../../common/types/domain'; jest.mock('../../common/lib/kibana'); jest.mock('../../common/navigation/hooks'); diff --git a/x-pack/plugins/cases/public/components/user_actions/status.tsx b/x-pack/plugins/cases/public/components/user_actions/status.tsx index 80a965e7ead69d..a58461d89ab87f 100644 --- a/x-pack/plugins/cases/public/components/user_actions/status.tsx +++ b/x-pack/plugins/cases/public/components/user_actions/status.tsx @@ -9,8 +9,7 @@ import React from 'react'; import { EuiFlexGroup, EuiFlexItem } from '@elastic/eui'; import { Status } from '@kbn/cases-components/src/status/status'; import type { SnakeToCamelCase } from '../../../common/types'; -import type { StatusUserAction } from '../../../common/types/domain'; -import type { CaseStatuses } from '../../../common/api'; +import type { StatusUserAction, CaseStatuses } from '../../../common/types/domain'; import type { UserActionBuilder } from './types'; import { createCommonUpdateUserActionBuilder } from './common'; import { statuses } from '../status'; diff --git a/x-pack/plugins/cases/public/components/user_actions/types.ts b/x-pack/plugins/cases/public/components/user_actions/types.ts index 23c44d47b1742e..fc9c81f15bb2b1 100644 --- a/x-pack/plugins/cases/public/components/user_actions/types.ts +++ b/x-pack/plugins/cases/public/components/user_actions/types.ts @@ -12,7 +12,7 @@ import type { CaseUI, CaseConnectors, UserActionUI, - CommentUI, + AttachmentUI, UseFetchAlertData, CaseUserActionsStats, } from '../../containers/types'; @@ -57,7 +57,7 @@ export interface UserActionBuilderArgs { persistableStateAttachmentTypeRegistry: PersistableStateAttachmentTypeRegistry; caseConnectors: CaseConnectors; userAction: UserActionUI; - comments: CommentUI[]; + comments: AttachmentUI[]; index: number; commentRefs: React.MutableRefObject< Record diff --git a/x-pack/plugins/cases/public/components/user_profiles/types.ts b/x-pack/plugins/cases/public/components/user_profiles/types.ts index 08c2cab4858352..0c0fdd1496b09f 100644 --- a/x-pack/plugins/cases/public/components/user_profiles/types.ts +++ b/x-pack/plugins/cases/public/components/user_profiles/types.ts @@ -6,7 +6,7 @@ */ import type { UserProfileWithAvatar } from '@kbn/user-profile-components'; -import type { UserWithProfileInfo } from '../../../common/api'; +import type { UserWithProfileInfo } from '../../../common/types/domain'; export interface Assignee { uid: string; diff --git a/x-pack/plugins/cases/public/components/visualizations/actions/utils.ts b/x-pack/plugins/cases/public/components/visualizations/actions/utils.ts index d5444bf6d8bebe..77bf41a78a7918 100644 --- a/x-pack/plugins/cases/public/components/visualizations/actions/utils.ts +++ b/x-pack/plugins/cases/public/components/visualizations/actions/utils.ts @@ -8,8 +8,8 @@ import type { IEmbeddable } from '@kbn/embeddable-plugin/public'; import type { LensEmbeddableInput, LensSavedObjectAttributes } from '@kbn/lens-plugin/public'; import { LENS_EMBEDDABLE_TYPE, type Embeddable as LensEmbeddable } from '@kbn/lens-plugin/public'; import { LENS_ATTACHMENT_TYPE } from '../../../../common/constants/visualizations'; -import type { CommentRequestPersistableStateType } from '../../../../common/api'; -import { CommentType } from '../../../../common'; +import type { PersistableStateAttachmentPayload } from '../../../../common/types/domain'; +import { AttachmentType } from '../../../../common/types/domain'; export const isLensEmbeddable = (embeddable: IEmbeddable): embeddable is LensEmbeddable => { return embeddable.type === LENS_EMBEDDABLE_TYPE; @@ -21,7 +21,7 @@ export const hasInput = (embeddable: LensEmbeddable) => { return attributes != null && timeRange != null; }; -type PersistableStateAttachmentWithoutOwner = Omit; +type PersistableStateAttachmentWithoutOwner = Omit; export const getLensCaseAttachment = ({ timeRange, @@ -33,5 +33,5 @@ export const getLensCaseAttachment = ({ ({ persistableStateAttachmentState: { attributes, timeRange }, persistableStateAttachmentTypeId: LENS_ATTACHMENT_TYPE, - type: CommentType.persistableState, + type: AttachmentType.persistableState, } as unknown as PersistableStateAttachmentWithoutOwner); diff --git a/x-pack/plugins/cases/public/containers/__mocks__/api.ts b/x-pack/plugins/cases/public/containers/__mocks__/api.ts index 63c5077e3c8d3c..fab73d5b57eec5 100644 --- a/x-pack/plugins/cases/public/containers/__mocks__/api.ts +++ b/x-pack/plugins/cases/public/containers/__mocks__/api.ts @@ -39,17 +39,17 @@ import type { CaseUserActionsStats, } from '../../../common/ui/types'; import { SeverityAll } from '../../../common/ui/types'; -import type { - CasePatchRequest, - CasePostRequest, - CommentRequest, - SingleCaseMetricsResponse, -} from '../../../common/api'; -import { CaseStatuses } from '../../../common/api'; +import type { SingleCaseMetricsResponse } from '../../../common/api'; +import { CaseStatuses } from '../../../common/types/domain'; import type { ValidFeatureId } from '@kbn/rule-data-utils'; import type { UserProfile } from '@kbn/security-plugin/common'; import { userProfiles } from '../user_profiles/api.mock'; import { getCaseConnectorsMockResponse } from '../../common/mock/connectors'; +import type { + CasePostRequest, + CasePatchRequest, + AttachmentRequest, +} from '../../../common/types/api'; export const getCase = async ( caseId: string, @@ -122,7 +122,7 @@ export const updateCases = async ( ): Promise => Promise.resolve(allCases.cases); export const createAttachments = async ( - newComment: CommentRequest, + newComment: AttachmentRequest, caseId: string, signal: AbortSignal ): Promise => Promise.resolve(basicCase); diff --git a/x-pack/plugins/cases/public/containers/api.test.tsx b/x-pack/plugins/cases/public/containers/api.test.tsx index b93b403e79a3ac..aeec96524c6eb9 100644 --- a/x-pack/plugins/cases/public/containers/api.test.tsx +++ b/x-pack/plugins/cases/public/containers/api.test.tsx @@ -9,7 +9,6 @@ import { httpServiceMock } from '@kbn/core/public/mocks'; import { BASE_RAC_ALERTS_API_PATH } from '@kbn/rule-registry-plugin/common'; import { KibanaServices } from '../common/lib/kibana'; -import { CommentType, CaseStatuses, CaseSeverity } from '../../common/api'; import { CASES_INTERNAL_URL, CASES_URL, @@ -73,8 +72,12 @@ import { getCaseConnectorsMockResponse } from '../common/mock/connectors'; import { set } from '@kbn/safer-lodash-set'; import { cloneDeep, omit } from 'lodash'; import type { CaseUserActionTypeWithAll } from './types'; -import { ConnectorTypes } from '../../common/types/domain'; - +import { + CaseSeverity, + CaseStatuses, + ConnectorTypes, + AttachmentType, +} from '../../common/types/domain'; const abortCtrl = new AbortController(); const mockKibanaServices = KibanaServices.get as jest.Mock; jest.mock('../common/lib/kibana'); @@ -753,7 +756,7 @@ describe('Cases API', () => { method: 'PATCH', body: JSON.stringify({ comment: 'updated comment', - type: CommentType.user, + type: AttachmentType.user, id: basicCase.comments[0].id, version: basicCase.comments[0].version, owner: SECURITY_SOLUTION_OWNER, @@ -855,7 +858,7 @@ describe('Cases API', () => { { comment: 'comment', owner: SECURITY_SOLUTION_OWNER, - type: CommentType.user as const, + type: AttachmentType.user as const, }, { alertId: 'test-id', @@ -865,7 +868,7 @@ describe('Cases API', () => { name: 'Test', }, owner: SECURITY_SOLUTION_OWNER, - type: CommentType.alert as const, + type: AttachmentType.alert as const, }, ]; @@ -1011,7 +1014,7 @@ describe('Cases API', () => { const data = { comment: 'Solve this fast!', - type: CommentType.user as const, + type: AttachmentType.user as const, owner: SECURITY_SOLUTION_OWNER, }; diff --git a/x-pack/plugins/cases/public/containers/api.ts b/x-pack/plugins/cases/public/containers/api.ts index 2a4a92f0eaa8a5..cfda3fc86a1902 100644 --- a/x-pack/plugins/cases/public/containers/api.ts +++ b/x-pack/plugins/cases/public/containers/api.ts @@ -7,7 +7,16 @@ import type { ValidFeatureId } from '@kbn/rule-data-utils'; import { BASE_RAC_ALERTS_API_PATH } from '@kbn/rule-registry-plugin/common/constants'; +import type { User } from '../../common/types/domain'; +import { AttachmentType } from '../../common/types/domain'; +import type { Case, Cases } from '../../common'; import type { + AttachmentRequest, + BulkCreateAttachmentsRequest, + CasePatchRequest, + CasePostRequest, + CaseResolveResponse, + CasesFindResponse, CaseUserActionStatsResponse, GetCaseConnectorsResponse, UserActionFindResponse, @@ -25,20 +34,8 @@ import type { CasesUI, } from '../../common/ui/types'; import { SeverityAll, SortFieldCase, StatusAll } from '../../common/ui/types'; -import type { - BulkCreateCommentRequest, - CasePatchRequest, - CasePostRequest, - CaseResolveResponse, - CommentRequest, - User, - SingleCaseMetricsResponse, - CasesFindResponse, - Case, - Cases, -} from '../../common/api'; +import type { SingleCaseMetricsResponse } from '../../common/api'; import { - CommentType, getCaseCommentsUrl, getCasesDeleteFileAttachmentsUrl, getCaseDetailsUrl, @@ -341,7 +338,7 @@ export const updateCases = async ({ }; export const postComment = async ( - newComment: CommentRequest, + newComment: AttachmentRequest, caseId: string, signal: AbortSignal ): Promise => { @@ -372,7 +369,7 @@ export const patchComment = async ({ method: 'PATCH', body: JSON.stringify({ comment: commentUpdate, - type: CommentType.user, + type: AttachmentType.user, id: commentId, version, owner, @@ -450,7 +447,7 @@ export const createAttachments = async ({ caseId, signal, }: { - attachments: BulkCreateCommentRequest; + attachments: BulkCreateAttachmentsRequest; caseId: string; signal?: AbortSignal; }): Promise => { diff --git a/x-pack/plugins/cases/public/containers/mock.ts b/x-pack/plugins/cases/public/containers/mock.ts index 7a50d4e9cd1259..3ce9b449971482 100644 --- a/x-pack/plugins/cases/public/containers/mock.ts +++ b/x-pack/plugins/cases/public/containers/mock.ts @@ -12,38 +12,37 @@ import type { UserAction, UserActions, UserActionType, + Case, + Cases, CaseConnector, + Attachment, +} from '../../common/types/domain'; +import { + CaseSeverity, + CaseStatuses, + UserActionActions, + UserActionTypes, + ConnectorTypes, + AttachmentType, + ExternalReferenceStorageType, } from '../../common/types/domain'; -import { UserActionActions, UserActionTypes, ConnectorTypes } from '../../common/types/domain'; -import type { ActionLicense, CaseUI, CasesStatus, UserActionUI, CommentUI } from './types'; +import type { ActionLicense, CaseUI, CasesStatus, UserActionUI } from './types'; import type { ResolvedCase, SingleCaseMetrics, SingleCaseMetricsFeature, - AlertComment, + AlertAttachmentUI, CasesMetrics, - ExternalReferenceComment, - PersistableComment, + ExternalReferenceAttachmentUI, + PersistableStateAttachmentUI, FindCaseUserActions, CaseUsers, CaseUserActionsStats, CasesFindResponseUI, CasesUI, + AttachmentUI, } from '../../common/ui/types'; -import type { - Case, - CasesFindResponse, - Cases, - CasesStatusResponse, - Comment, -} from '../../common/api'; -import { - CaseStatuses, - CommentType, - CaseSeverity, - ExternalReferenceStorageType, -} from '../../common/api'; import { SECURITY_SOLUTION_OWNER } from '../../common/constants'; import type { SnakeToCamelCase } from '../../common/types'; import { covertToSnakeCase } from './utils'; @@ -52,7 +51,11 @@ import type { AttachmentViewObject, PersistableStateAttachmentType, } from '../client/attachment_framework/types'; -import type { UserActionWithResponse } from '../../common/types/api'; +import type { + CasesFindResponse, + CasesStatusResponse, + UserActionWithResponse, +} from '../../common/types/api'; export { connectorsMock } from '../common/mock/connectors'; export const basicCaseId = 'basic-case-id'; @@ -76,9 +79,9 @@ export const elasticUser = { export const tags: string[] = ['coke', 'pepsi']; export const categories: string[] = ['snickers', 'twix']; -export const basicComment: CommentUI = { +export const basicComment: AttachmentUI = { comment: 'Solve this fast!', - type: CommentType.user, + type: AttachmentType.user, id: basicCommentId, createdAt: basicCreatedAt, createdBy: elasticUser, @@ -90,10 +93,10 @@ export const basicComment: CommentUI = { version: 'WzQ3LDFc', }; -export const alertComment: AlertComment = { +export const alertComment: AlertAttachmentUI = { alertId: 'alert-id-1', index: 'alert-index-1', - type: CommentType.alert, + type: AttachmentType.alert, id: 'alert-comment-id', createdAt: basicCreatedAt, createdBy: elasticUser, @@ -109,10 +112,10 @@ export const alertComment: AlertComment = { version: 'WzQ3LDFc', }; -export const alertCommentWithIndices: AlertComment = { +export const alertCommentWithIndices: AlertAttachmentUI = { alertId: 'alert-id-1', index: '.alerts-matchme.alerts', - type: CommentType.alert, + type: AttachmentType.alert, id: 'alert-comment-id', createdAt: basicCreatedAt, createdBy: elasticUser, @@ -128,9 +131,9 @@ export const alertCommentWithIndices: AlertComment = { version: 'WzQ3LDFc', }; -export const hostIsolationComment = (overrides?: Record): CommentUI => { +export const hostIsolationComment = (overrides?: Record): AttachmentUI => { return { - type: CommentType.actions, + type: AttachmentType.actions, comment: 'I just isolated the host!', id: 'isolate-comment-id', actions: { @@ -154,9 +157,9 @@ export const hostIsolationComment = (overrides?: Record): Comme }; }; -export const hostReleaseComment: () => CommentUI = () => { +export const hostReleaseComment: () => AttachmentUI = () => { return { - type: CommentType.actions, + type: AttachmentType.actions, comment: 'I just released the host!', id: 'isolate-comment-id', actions: { @@ -179,8 +182,8 @@ export const hostReleaseComment: () => CommentUI = () => { }; }; -export const externalReferenceAttachment: ExternalReferenceComment = { - type: CommentType.externalReference, +export const externalReferenceAttachment: ExternalReferenceAttachmentUI = { + type: AttachmentType.externalReference, id: 'external-reference-comment-id', externalReferenceId: 'my-id', externalReferenceStorage: { type: ExternalReferenceStorageType.elasticSearchDoc }, @@ -196,8 +199,8 @@ export const externalReferenceAttachment: ExternalReferenceComment = { version: 'WzQ3LDFc', }; -export const persistableStateAttachment: PersistableComment = { - type: CommentType.persistableState, +export const persistableStateAttachment: PersistableStateAttachmentUI = { + type: AttachmentType.persistableState, id: 'persistable-state-comment-id', persistableStateAttachmentState: { test_foo: 'foo' }, persistableStateAttachmentTypeId: '.test', @@ -368,7 +371,7 @@ export const basicCasePost: CaseUI = { updatedBy: null, }; -export const basicCommentPatch: CommentUI = { +export const basicCommentPatch: AttachmentUI = { ...basicComment, updatedAt: basicUpdatedAt, updatedBy: { @@ -473,9 +476,9 @@ export const elasticUserSnake = { email: 'leslie.knope@elastic.co', }; -export const basicCommentSnake: Comment = { +export const basicCommentSnake: Attachment = { comment: 'Solve this fast!', - type: CommentType.user, + type: AttachmentType.user, id: basicCommentId, created_at: basicCreatedAt, created_by: elasticUserSnake, @@ -487,8 +490,8 @@ export const basicCommentSnake: Comment = { version: 'WzQ3LDFc', }; -export const externalReferenceAttachmentSnake: Comment = { - type: CommentType.externalReference, +export const externalReferenceAttachmentSnake: Attachment = { + type: AttachmentType.externalReference, id: 'external-reference-comment-id', externalReferenceId: 'my-id', externalReferenceMetadata: { test_foo: 'foo' }, @@ -504,8 +507,8 @@ export const externalReferenceAttachmentSnake: Comment = { version: 'WzQ3LDFc', }; -export const persistableStateAttachmentSnake: Comment = { - type: CommentType.persistableState, +export const persistableStateAttachmentSnake: Attachment = { + type: AttachmentType.persistableState, id: 'persistable-state-comment-id', persistableStateAttachmentState: { test_foo: 'foo' }, persistableStateAttachmentTypeId: '.test', @@ -641,7 +644,11 @@ export const getUserAction = ( ...commonProperties, type: UserActionTypes.comment, payload: { - comment: { comment: 'a comment', type: CommentType.user, owner: SECURITY_SOLUTION_OWNER }, + comment: { + comment: 'a comment', + type: AttachmentType.user, + owner: SECURITY_SOLUTION_OWNER, + }, }, commentId: basicCommentId, ...overrides, @@ -774,7 +781,7 @@ export const caseUserActionsWithRegisteredAttachmentsSnake: UserActions = [ id: 'create-comment-id', payload: { comment: { - type: CommentType.externalReference, + type: AttachmentType.externalReference, externalReferenceId: 'my-id', externalReferenceMetadata: { test_foo: 'foo' }, externalReferenceAttachmentTypeId: '.test', @@ -794,7 +801,7 @@ export const caseUserActionsWithRegisteredAttachmentsSnake: UserActions = [ id: 'create-comment-id', payload: { comment: { - type: CommentType.persistableState, + type: AttachmentType.persistableState, persistableStateAttachmentState: { test_foo: 'foo' }, persistableStateAttachmentTypeId: '.test', owner: SECURITY_SOLUTION_OWNER, @@ -825,7 +832,7 @@ export const getAlertUserAction = ( type: UserActionTypes.comment, payload: { comment: { - type: CommentType.alert, + type: AttachmentType.alert, alertId: 'alert-id-1', index: 'index-id-1', owner: SECURITY_SOLUTION_OWNER, @@ -847,7 +854,7 @@ export const getMultipleAlertsUserAction = ( type: UserActionTypes.comment, payload: { comment: { - type: CommentType.alert, + type: AttachmentType.alert, alertId: ['alert-id-1', 'alert-id-2'], index: ['index-id-1', 'index-id-2'], owner: SECURITY_SOLUTION_OWNER, @@ -869,7 +876,7 @@ export const getHostIsolationUserAction = ( commentId: 'isolate-comment-id', payload: { comment: { - type: CommentType.actions, + type: AttachmentType.actions, comment: 'a comment', actions: { targets: [], type: 'test' }, owner: SECURITY_SOLUTION_OWNER, @@ -896,7 +903,7 @@ export const caseUserActionsWithRegisteredAttachments: UserActionUI[] = [ id: 'create-comment-id', payload: { comment: { - type: CommentType.externalReference, + type: AttachmentType.externalReference, externalReferenceId: 'my-id', externalReferenceMetadata: { test_foo: 'foo' }, externalReferenceAttachmentTypeId: '.test', @@ -916,7 +923,7 @@ export const caseUserActionsWithRegisteredAttachments: UserActionUI[] = [ id: 'create-comment-id', payload: { comment: { - type: CommentType.persistableState, + type: AttachmentType.persistableState, persistableStateAttachmentState: { test_foo: 'foo' }, persistableStateAttachmentTypeId: '.test', owner: SECURITY_SOLUTION_OWNER, @@ -962,7 +969,7 @@ export const getExternalReferenceUserAction = ( commentId: 'external-reference-comment-id', payload: { comment: { - type: CommentType.externalReference, + type: AttachmentType.externalReference, externalReferenceId: 'my-id', externalReferenceStorage: { type: ExternalReferenceStorageType.elasticSearchDoc }, externalReferenceAttachmentTypeId: '.test', @@ -995,7 +1002,7 @@ export const getPersistableStateUserAction = ( commentId: 'persistable-state-comment-id', payload: { comment: { - type: CommentType.persistableState, + type: AttachmentType.persistableState, persistableStateAttachmentState: { test_foo: 'foo' }, persistableStateAttachmentTypeId: '.test', owner: SECURITY_SOLUTION_OWNER, diff --git a/x-pack/plugins/cases/public/containers/use_create_attachments.test.tsx b/x-pack/plugins/cases/public/containers/use_create_attachments.test.tsx index 5afe04ca8f9388..14d4477df62daf 100644 --- a/x-pack/plugins/cases/public/containers/use_create_attachments.test.tsx +++ b/x-pack/plugins/cases/public/containers/use_create_attachments.test.tsx @@ -7,7 +7,7 @@ import { renderHook, act } from '@testing-library/react-hooks'; -import { CommentType } from '../../common/api'; +import { AttachmentType } from '../../common/types/domain'; import { SECURITY_SOLUTION_OWNER } from '../../common/constants'; import { useCreateAttachments } from './use_create_attachments'; import { basicCaseId } from './mock'; @@ -33,7 +33,7 @@ describe('useCreateAttachments', () => { const attachmentsWithoutOwner = [ { comment: 'a comment', - type: CommentType.user as const, + type: AttachmentType.user as const, }, ]; diff --git a/x-pack/plugins/cases/public/containers/use_post_case.tsx b/x-pack/plugins/cases/public/containers/use_post_case.tsx index ab17abbf9a9602..62d2c65251d7da 100644 --- a/x-pack/plugins/cases/public/containers/use_post_case.tsx +++ b/x-pack/plugins/cases/public/containers/use_post_case.tsx @@ -6,7 +6,7 @@ */ import { useMutation } from '@tanstack/react-query'; -import type { CasePostRequest } from '../../common/api'; +import type { CasePostRequest } from '../../common/types/api'; import { postCase } from './api'; import * as i18n from './translations'; import { useCasesToast } from '../common/use_cases_toast'; diff --git a/x-pack/plugins/cases/public/containers/user_profiles/use_assignees.ts b/x-pack/plugins/cases/public/containers/user_profiles/use_assignees.ts index 8e1f15d7d979a5..de940be6a1684f 100644 --- a/x-pack/plugins/cases/public/containers/user_profiles/use_assignees.ts +++ b/x-pack/plugins/cases/public/containers/user_profiles/use_assignees.ts @@ -7,7 +7,7 @@ import type { UserProfileWithAvatar } from '@kbn/user-profile-components'; import { useMemo } from 'react'; -import type { CaseAssignees } from '../../../common/api'; +import type { CaseAssignees } from '../../../common/types/domain'; import { sortProfiles } from '../../components/user_profiles/sort'; import type { Assignee, AssigneeWithProfile } from '../../components/user_profiles/types'; diff --git a/x-pack/plugins/cases/public/containers/utils.ts b/x-pack/plugins/cases/public/containers/utils.ts index b9ea0c2bcc5f8a..2a26367885e84f 100644 --- a/x-pack/plugins/cases/public/containers/utils.ts +++ b/x-pack/plugins/cases/public/containers/utils.ts @@ -11,29 +11,33 @@ import { identity } from 'fp-ts/lib/function'; import { pipe } from 'fp-ts/lib/pipeable'; import type { ToastInputFields } from '@kbn/core/public'; -import type { CaseUserActionStatsResponse } from '../../common/types/api'; -import type { Configuration, Configurations, UserActions } from '../../common/types/domain'; -import { ConfigurationRt, ConfigurationsRt, UserActionsRt } from '../../common/types/domain'; -import { NO_ASSIGNEES_FILTERING_KEYWORD } from '../../common/constants'; +import { + AttachmentType, + CaseRt, + CasesRt, + ConfigurationRt, + ConfigurationsRt, + UserActionsRt, +} from '../../common/types/domain'; import type { CasePatchRequest, CaseResolveResponse, - SingleCaseMetricsResponse, - User, + CaseUserActionStatsResponse, +} from '../../common/types/api'; +import { CaseResolveResponseRt, CaseUserActionStatsResponseRt } from '../../common/types/api'; +import type { Case, Cases, -} from '../../common/api'; -import { - CaseRt, - CasesRt, - throwErrors, - CommentType, - CaseResolveResponseRt, - SingleCaseMetricsResponseRt, -} from '../../common/api'; + Configuration, + Configurations, + User, + UserActions, +} from '../../common/types/domain'; +import { NO_ASSIGNEES_FILTERING_KEYWORD } from '../../common/constants'; +import type { SingleCaseMetricsResponse } from '../../common/api'; +import { throwErrors, SingleCaseMetricsResponseRt } from '../../common/api'; import type { CaseUI, FilterOptions, UpdateByKey } from './types'; import * as i18n from './translations'; -import { CaseUserActionStatsResponseRt } from '../../common/types/api'; export const getTypedPayload = (a: unknown): T => a as T; @@ -110,7 +114,7 @@ export const createUpdateSuccessToaster = ( value: UpdateByKey['updateValue'] ): ToastInputFields => { const caseHasAlerts = caseBeforeUpdate.comments.some( - (comment) => comment.type === CommentType.alert + (comment) => comment.type === AttachmentType.alert ); const toast: ToastInputFields = { diff --git a/x-pack/plugins/cases/public/types.ts b/x-pack/plugins/cases/public/types.ts index c5a1fd8c73a690..648b1be30763b0 100644 --- a/x-pack/plugins/cases/public/types.ts +++ b/x-pack/plugins/cases/public/types.ts @@ -27,20 +27,7 @@ import type { SavedObjectsManagementPluginStart } from '@kbn/saved-objects-manag import type { UiActionsStart } from '@kbn/ui-actions-plugin/public'; import type { ServerlessPluginSetup, ServerlessPluginStart } from '@kbn/serverless/public'; -import type { - CasesBulkGetRequest, - CasesBulkGetResponse, - CasesByAlertId, - CasesByAlertIDRequest, - CasesFindRequest, - CasesMetricsRequest, - CasesStatusRequest, - CommentRequestAlertType, - CommentRequestExternalReferenceNoSOType, - CommentRequestExternalReferenceSOType, - CommentRequestPersistableStateType, - CommentRequestUserType, -} from '../common/api'; +import type { CasesMetricsRequest } from '../common/api'; import type { UseCasesAddToExistingCaseModal } from './components/all_cases/selector_modal/use_cases_add_to_existing_case_modal'; import type { UseCasesAddToNewCaseFlyout } from './components/create/flyout/use_cases_add_to_new_case_flyout'; import type { canUseCases } from './client/helpers/can_use_cases'; @@ -55,6 +42,21 @@ import type { getUICapabilities } from './client/helpers/capabilities'; import type { AttachmentFramework } from './client/attachment_framework/types'; import type { ExternalReferenceAttachmentTypeRegistry } from './client/attachment_framework/external_reference_registry'; import type { PersistableStateAttachmentTypeRegistry } from './client/attachment_framework/persistable_state_registry'; +import type { + CasesByAlertIDRequest, + GetRelatedCasesByAlertResponse, + CasesFindRequest, + CasesStatusRequest, + CasesBulkGetRequest, + CasesBulkGetResponse, +} from '../common/types/api'; +import type { + AlertAttachmentPayload, + UserCommentAttachmentPayload, + PersistableStateAttachmentPayload, + ExternalReferenceNoSOAttachmentPayload, + ExternalReferenceSOAttachmentPayload, +} from '../common/types/domain'; export interface CasesPluginSetup { files: FilesSetup; @@ -105,7 +107,10 @@ export interface CasesUiSetup { export interface CasesUiStart { api: { - getRelatedCases: (alertId: string, query: CasesByAlertIDRequest) => Promise; + getRelatedCases: ( + alertId: string, + query: CasesByAlertIDRequest + ) => Promise; cases: { find: (query: CasesFindRequest, signal?: AbortSignal) => Promise; getCasesStatus: (query: CasesStatusRequest, signal?: AbortSignal) => Promise; @@ -158,11 +163,11 @@ export interface CasesUiStart { } export type SupportedCaseAttachment = - | CommentRequestAlertType - | CommentRequestUserType - | CommentRequestPersistableStateType - | CommentRequestExternalReferenceNoSOType - | CommentRequestExternalReferenceSOType; + | AlertAttachmentPayload + | UserCommentAttachmentPayload + | PersistableStateAttachmentPayload + | ExternalReferenceNoSOAttachmentPayload + | ExternalReferenceSOAttachmentPayload; export type CaseAttachments = SupportedCaseAttachment[]; export type CaseAttachmentWithoutOwner = DistributiveOmit; diff --git a/x-pack/plugins/cases/server/attachment_framework/mocks.ts b/x-pack/plugins/cases/server/attachment_framework/mocks.ts index 6fc0e96fa0edf1..d3acd26393cd1d 100644 --- a/x-pack/plugins/cases/server/attachment_framework/mocks.ts +++ b/x-pack/plugins/cases/server/attachment_framework/mocks.ts @@ -6,14 +6,17 @@ */ import { omit } from 'lodash'; -import { CommentType, SECURITY_SOLUTION_OWNER } from '../../common'; import type { - AttributesTypeExternalReferenceNoSO, - AttributesTypeExternalReferenceSO, - AttributesTypePersistableState, - CommentRequestPersistableStateType, -} from '../../common/api'; -import { ExternalReferenceStorageType } from '../../common/api'; + ExternalReferenceSOAttachmentAttributes, + ExternalReferenceNoSOAttachmentAttributes, + PersistableStateAttachmentAttributes, + PersistableStateAttachmentPayload, +} from '../../common/types/domain'; +import { + AttachmentType, + ExternalReferenceStorageType, + SECURITY_SOLUTION_OWNER, +} from '../../common'; import { ExternalReferenceAttachmentTypeRegistry } from './external_reference_registry'; import { PersistableStateAttachmentTypeRegistry } from './persistable_state_registry'; import type { @@ -46,7 +49,7 @@ export const getExternalReferenceAttachment = (): ExternalReferenceAttachmentTyp }); export const externalReferenceAttachmentSO = { - type: CommentType.externalReference as const, + type: AttachmentType.externalReference as const, externalReferenceId: 'my-id', externalReferenceStorage: { type: ExternalReferenceStorageType.savedObject as const, @@ -58,7 +61,7 @@ export const externalReferenceAttachmentSO = { }; export const externalReferenceAttachmentES = { - type: CommentType.externalReference as const, + type: AttachmentType.externalReference as const, externalReferenceId: 'my-id', externalReferenceStorage: { type: ExternalReferenceStorageType.elasticSearchDoc as const, @@ -68,7 +71,7 @@ export const externalReferenceAttachmentES = { owner: SECURITY_SOLUTION_OWNER, }; -export const externalReferenceAttachmentSOAttributes: AttributesTypeExternalReferenceSO = { +export const externalReferenceAttachmentSOAttributes: ExternalReferenceSOAttachmentAttributes = { ...externalReferenceAttachmentSO, created_at: '2019-11-25T22:32:30.608Z', created_by: { @@ -82,7 +85,7 @@ export const externalReferenceAttachmentSOAttributes: AttributesTypeExternalRefe pushed_by: null, }; -export const externalReferenceAttachmentESAttributes: AttributesTypeExternalReferenceNoSO = { +export const externalReferenceAttachmentESAttributes: ExternalReferenceNoSOAttachmentAttributes = { ...externalReferenceAttachmentES, created_at: '2019-11-25T22:32:30.608Z', created_by: { @@ -101,15 +104,15 @@ export const persistableStateAttachmentStateOnly: PersistableStateAttachmentStat persistableStateAttachmentState: { foo: 'foo', injectedId: 'testRef' }, }; -export const persistableStateAttachment: CommentRequestPersistableStateType = { +export const persistableStateAttachment: PersistableStateAttachmentPayload = { ...persistableStateAttachmentStateOnly, - type: CommentType.persistableState, + type: AttachmentType.persistableState, owner: 'securitySolutionFixture', }; -export const persistableStateAttachmentAttributes: AttributesTypePersistableState = { +export const persistableStateAttachmentAttributes: PersistableStateAttachmentAttributes = { ...persistableStateAttachment, - type: CommentType.persistableState, + type: AttachmentType.persistableState, owner: 'securitySolutionFixture', created_at: '2019-11-25T22:32:30.608Z', created_by: { diff --git a/x-pack/plugins/cases/server/attachment_framework/so_references.test.ts b/x-pack/plugins/cases/server/attachment_framework/so_references.test.ts index 7ef88169340598..e4befcff0247b4 100644 --- a/x-pack/plugins/cases/server/attachment_framework/so_references.test.ts +++ b/x-pack/plugins/cases/server/attachment_framework/so_references.test.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { CommentType, SECURITY_SOLUTION_OWNER } from '../../common'; +import { AttachmentType, SECURITY_SOLUTION_OWNER } from '../../common'; import { createPersistableStateAttachmentTypeRegistryMock, persistableStateAttachment, @@ -142,7 +142,7 @@ describe('Persistable state SO references', () => { it('does not extract references for other attachments', async () => { const comment = { comment: 'a comment', - type: CommentType.user as const, + type: AttachmentType.user as const, owner: SECURITY_SOLUTION_OWNER, }; @@ -179,7 +179,7 @@ describe('Persistable state SO references', () => { it('does not inject references for other attachments', async () => { const comment = { comment: 'a comment', - type: CommentType.user as const, + type: AttachmentType.user as const, owner: SECURITY_SOLUTION_OWNER, }; diff --git a/x-pack/plugins/cases/server/attachment_framework/so_references.ts b/x-pack/plugins/cases/server/attachment_framework/so_references.ts index c8ad18e39a7cc1..e0cbfc5b75e3bd 100644 --- a/x-pack/plugins/cases/server/attachment_framework/so_references.ts +++ b/x-pack/plugins/cases/server/attachment_framework/so_references.ts @@ -5,13 +5,14 @@ * 2.0. */ -import type { SavedObjectReference } from '@kbn/core/types'; +import type { SavedObjectReference } from '@kbn/core/server'; +import type { AttachmentRequest } from '../../common/types/api'; +import type { PersistableStateAttachmentPayload } from '../../common/types/domain'; import { isCommentRequestTypePersistableState } from '../../common/utils/attachments'; -import type { CommentRequest, CommentRequestPersistableStateType } from '../../common/api'; import type { PersistableStateAttachmentTypeRegistry } from './persistable_state_registry'; interface SavedObjectAttributesAndReferences { - state: CommentRequestPersistableStateType; + state: PersistableStateAttachmentPayload; references: SavedObjectReference[]; } @@ -22,7 +23,7 @@ interface ExtractDeps { type InjectDeps = ExtractDeps; export function extractPersistableStateReferences( - state: CommentRequestPersistableStateType, + state: PersistableStateAttachmentPayload, deps: ExtractDeps ): SavedObjectAttributesAndReferences { const { persistableStateAttachmentState, persistableStateAttachmentTypeId } = state; @@ -49,7 +50,7 @@ export function extractPersistableStateReferences( export function injectPersistableReferences( { state, references = [] }: SavedObjectAttributesAndReferences, deps: InjectDeps -): CommentRequestPersistableStateType { +): PersistableStateAttachmentPayload { const { persistableStateAttachmentState, persistableStateAttachmentTypeId } = state; if (!deps.persistableStateAttachmentTypeRegistry.has(persistableStateAttachmentTypeId)) { @@ -71,7 +72,7 @@ export function injectPersistableReferences( return { ...state, ...injectedState, persistableStateAttachmentTypeId }; } -export const extractPersistableStateReferencesFromSO = ( +export const extractPersistableStateReferencesFromSO = ( attachmentAttributes: T, deps: ExtractDeps ) => { @@ -91,7 +92,7 @@ export const extractPersistableStateReferencesFromSO = >( +export const injectPersistableReferencesToSO = >( attachmentAttributes: T, references: SavedObjectReference[], deps: InjectDeps diff --git a/x-pack/plugins/cases/server/attachment_framework/types.ts b/x-pack/plugins/cases/server/attachment_framework/types.ts index 4dbc56da91744c..0e0842f4025441 100644 --- a/x-pack/plugins/cases/server/attachment_framework/types.ts +++ b/x-pack/plugins/cases/server/attachment_framework/types.ts @@ -6,10 +6,10 @@ */ import type { PersistableState, PersistableStateDefinition } from '@kbn/kibana-utils-plugin/common'; -import type { CommentRequestPersistableStateType } from '../../common/api'; +import type { PersistableStateAttachmentPayload } from '../../common/types/domain'; export type PersistableStateAttachmentState = Pick< - CommentRequestPersistableStateType, + PersistableStateAttachmentPayload, 'persistableStateAttachmentTypeId' | 'persistableStateAttachmentState' >; diff --git a/x-pack/plugins/cases/server/authorization/utils.test.ts b/x-pack/plugins/cases/server/authorization/utils.test.ts index ec403bec713d35..a96cf7d3a11ff1 100644 --- a/x-pack/plugins/cases/server/authorization/utils.test.ts +++ b/x-pack/plugins/cases/server/authorization/utils.test.ts @@ -5,8 +5,8 @@ * 2.0. */ +import { OWNER_FIELD } from '../../common/constants'; import { nodeBuilder } from '@kbn/es-query'; -import { OWNER_FIELD } from '../../common/api'; import { combineFilterWithAuthorizationFilter, ensureFieldIsSafeForQuery, diff --git a/x-pack/plugins/cases/server/authorization/utils.ts b/x-pack/plugins/cases/server/authorization/utils.ts index 3ca28e3f2d7e32..0daabf0c513e5b 100644 --- a/x-pack/plugins/cases/server/authorization/utils.ts +++ b/x-pack/plugins/cases/server/authorization/utils.ts @@ -9,7 +9,7 @@ import { partition, remove, uniq } from 'lodash'; import type { KueryNode } from '@kbn/es-query'; import { nodeBuilder } from '@kbn/es-query'; import type { SavedObject } from '@kbn/core-saved-objects-server'; -import { OWNER_FIELD } from '../../common/api'; +import { OWNER_FIELD } from '../../common/constants'; export const getOwnersFilter = ( savedObjectType: string, diff --git a/x-pack/plugins/cases/server/client/alerts/types.ts b/x-pack/plugins/cases/server/client/alerts/types.ts index 4ceba5e500d9b8..be1907b0a5e872 100644 --- a/x-pack/plugins/cases/server/client/alerts/types.ts +++ b/x-pack/plugins/cases/server/client/alerts/types.ts @@ -5,7 +5,7 @@ * 2.0. */ -import type { CaseStatuses } from '../../../common/api'; +import type { CaseStatuses } from '../../../common/types/domain'; import type { AlertInfo } from '../../common/types'; interface Alert { diff --git a/x-pack/plugins/cases/server/client/attachments/add.ts b/x-pack/plugins/cases/server/client/attachments/add.ts index 9e41d7e832461e..987b87bdcf52c4 100644 --- a/x-pack/plugins/cases/server/client/attachments/add.ts +++ b/x-pack/plugins/cases/server/client/attachments/add.ts @@ -7,13 +7,12 @@ import { SavedObjectsUtils } from '@kbn/core/server'; -import type { Case } from '../../../common/api'; -import { CommentRequestRt, decodeWithExcessOrThrow } from '../../../common/api'; - +import { AttachmentRequestRt } from '../../../common/types/api'; +import type { Case } from '../../../common/types/domain'; +import { decodeWithExcessOrThrow } from '../../../common/api'; import { CaseCommentModel } from '../../common/models'; import { createCaseError } from '../../common/error'; import type { CasesClientArgs } from '..'; - import { decodeCommentRequest } from '../utils'; import { Operations } from '../../authorization'; import type { AddArgs } from './types'; @@ -35,7 +34,7 @@ export const addComment = async (addArgs: AddArgs, clientArgs: CasesClientArgs): } = clientArgs; try { - const query = decodeWithExcessOrThrow(CommentRequestRt)(comment); + const query = decodeWithExcessOrThrow(AttachmentRequestRt)(comment); decodeCommentRequest(comment, externalReferenceAttachmentTypeRegistry); diff --git a/x-pack/plugins/cases/server/client/attachments/bulk_create.ts b/x-pack/plugins/cases/server/client/attachments/bulk_create.ts index b8986b950008dc..693336ffd31f7e 100644 --- a/x-pack/plugins/cases/server/client/attachments/bulk_create.ts +++ b/x-pack/plugins/cases/server/client/attachments/bulk_create.ts @@ -7,8 +7,10 @@ import { SavedObjectsUtils } from '@kbn/core/server'; -import type { Case, CommentRequest } from '../../../common/api'; -import { BulkCreateCommentRequestRt, decodeWithExcessOrThrow } from '../../../common/api'; +import type { AttachmentRequest } from '../../../common/types/api'; +import { BulkCreateAttachmentsRequestRt } from '../../../common/types/api'; +import type { Case } from '../../../common/types/domain'; +import { decodeWithExcessOrThrow } from '../../../common/api'; import { CaseCommentModel } from '../../common/models'; import { createCaseError } from '../../common/error'; @@ -34,7 +36,7 @@ export const bulkCreate = async ( } = clientArgs; try { - decodeWithExcessOrThrow(BulkCreateCommentRequestRt)(attachments); + decodeWithExcessOrThrow(BulkCreateAttachmentsRequestRt)(attachments); attachments.forEach((attachment) => { decodeCommentRequest(attachment, externalReferenceAttachmentTypeRegistry); @@ -45,17 +47,19 @@ export const bulkCreate = async ( }); }); - const [attachmentsWithIds, entities]: [Array<{ id: string } & CommentRequest>, OwnerEntity[]] = - attachments.reduce<[Array<{ id: string } & CommentRequest>, OwnerEntity[]]>( - ([a, e], attachment) => { - const savedObjectID = SavedObjectsUtils.generateId(); - return [ - [...a, { id: savedObjectID, ...attachment }], - [...e, { owner: attachment.owner, id: savedObjectID }], - ]; - }, - [[], []] - ); + const [attachmentsWithIds, entities]: [ + Array<{ id: string } & AttachmentRequest>, + OwnerEntity[] + ] = attachments.reduce<[Array<{ id: string } & AttachmentRequest>, OwnerEntity[]]>( + ([a, e], attachment) => { + const savedObjectID = SavedObjectsUtils.generateId(); + return [ + [...a, { id: savedObjectID, ...attachment }], + [...e, { owner: attachment.owner, id: savedObjectID }], + ]; + }, + [[], []] + ); await authorization.ensureAuthorized({ operation: Operations.bulkCreateAttachments, diff --git a/x-pack/plugins/cases/server/client/attachments/bulk_delete.ts b/x-pack/plugins/cases/server/client/attachments/bulk_delete.ts index 87f4176f15304c..0d19963ec0dff9 100644 --- a/x-pack/plugins/cases/server/client/attachments/bulk_delete.ts +++ b/x-pack/plugins/cases/server/client/attachments/bulk_delete.ts @@ -14,7 +14,8 @@ import type { Logger } from '@kbn/core/server'; import type { File, FileJSON } from '@kbn/files-plugin/common'; import type { FileServiceStart } from '@kbn/files-plugin/server'; import { FileNotFoundError } from '@kbn/files-plugin/server/file_service/errors'; -import { BulkDeleteFileAttachmentsRequestRt, decodeWithExcessOrThrow } from '../../../common/api'; +import { BulkDeleteFileAttachmentsRequestRt } from '../../../common/types/api'; +import { decodeWithExcessOrThrow } from '../../../common/api'; import { MAX_CONCURRENT_SEARCHES } from '../../../common/constants'; import type { CasesClientArgs } from '../types'; import { createCaseError } from '../../common/error'; diff --git a/x-pack/plugins/cases/server/client/attachments/bulk_get.ts b/x-pack/plugins/cases/server/client/attachments/bulk_get.ts index 553f8ca258669b..f3b3b0d83360f7 100644 --- a/x-pack/plugins/cases/server/client/attachments/bulk_get.ts +++ b/x-pack/plugins/cases/server/client/attachments/bulk_get.ts @@ -6,12 +6,12 @@ */ import { partition } from 'lodash'; -import type { BulkGetAttachmentsResponse, CommentAttributes } from '../../../common/api'; +import type { BulkGetAttachmentsResponse } from '../../../common/types/api'; import { - decodeWithExcessOrThrow, - BulkGetAttachmentsResponseRt, BulkGetAttachmentsRequestRt, -} from '../../../common/api'; + BulkGetAttachmentsResponseRt, +} from '../../../common/types/api'; +import { decodeWithExcessOrThrow } from '../../../common/api'; import { flattenCommentSavedObjects } from '../../common/utils'; import { createCaseError } from '../../common/error'; import type { CasesClientArgs } from '../types'; @@ -22,8 +22,9 @@ import type { CasesClient } from '../client'; import type { AttachmentSavedObject, SOWithErrors } from '../../common/types'; import { partitionByCaseAssociation } from '../../common/partitioning'; import { decodeOrThrow } from '../../../common/api/runtime_types'; +import type { AttachmentAttributes } from '../../../common/types/domain'; -type AttachmentSavedObjectWithErrors = Array>; +type AttachmentSavedObjectWithErrors = Array>; /** * Retrieves multiple attachments by id. @@ -86,7 +87,7 @@ interface PartitionedAttachments { const partitionAttachments = ( caseId: string, - attachments: BulkOptionalAttributes + attachments: BulkOptionalAttributes ): PartitionedAttachments => { const [attachmentsWithoutErrors, errors] = partitionBySOError(attachments.saved_objects); const [caseAttachments, invalidAssociationAttachments] = partitionByCaseAssociation( @@ -101,7 +102,7 @@ const partitionAttachments = ( }; }; -const partitionBySOError = (attachments: Array>) => +const partitionBySOError = (attachments: Array>) => partition( attachments, (attachment) => attachment.error == null && attachment.attributes != null diff --git a/x-pack/plugins/cases/server/client/attachments/client.ts b/x-pack/plugins/cases/server/client/attachments/client.ts index 2c9bfd46a50ca5..9c455cbe750c35 100644 --- a/x-pack/plugins/cases/server/client/attachments/client.ts +++ b/x-pack/plugins/cases/server/client/attachments/client.ts @@ -5,14 +5,12 @@ * 2.0. */ +import type { Case, Attachments, Attachment } from '../../../common/types/domain'; import type { AlertResponse, - Comments, + AttachmentsFindResponse, BulkGetAttachmentsResponse, - Case, - Comment, - CommentsFindResponse, -} from '../../../common/api'; +} from '../../../common/types/api'; import type { CasesClient } from '../client'; import type { CasesClientInternal } from '../client_internal'; @@ -60,7 +58,7 @@ export interface AttachmentsSubClient { /** * Retrieves all comments matching the search criteria. */ - find(findArgs: FindCommentsArgs): Promise; + find(findArgs: FindCommentsArgs): Promise; /** * Retrieves all alerts attach to a case given a single case ID */ @@ -68,11 +66,11 @@ export interface AttachmentsSubClient { /** * Gets all attachments for a single case. */ - getAll(getAllArgs: GetAllArgs): Promise; + getAll(getAllArgs: GetAllArgs): Promise; /** * Retrieves a single attachment for a case. */ - get(getArgs: GetArgs): Promise; + get(getArgs: GetArgs): Promise; /** * Updates a specific attachment. * diff --git a/x-pack/plugins/cases/server/client/attachments/delete.ts b/x-pack/plugins/cases/server/client/attachments/delete.ts index cbbfb23b9b66b3..b21c6b5ae753f1 100644 --- a/x-pack/plugins/cases/server/client/attachments/delete.ts +++ b/x-pack/plugins/cases/server/client/attachments/delete.ts @@ -7,15 +7,17 @@ import Boom from '@hapi/boom'; +import type { AlertAttachmentPayload } from '../../../common/types/domain'; import { UserActionActions, UserActionTypes } from '../../../common/types/domain'; -import type { CommentRequest, CommentRequestAlertType } from '../../../common/api'; -import { CommentRequestRt, decodeOrThrow } from '../../../common/api'; +import { decodeOrThrow } from '../../../common/api'; import { CASE_SAVED_OBJECT } from '../../../common/constants'; import { getAlertInfoFromComments, isCommentRequestTypeAlert } from '../../common/utils'; import type { CasesClientArgs } from '../types'; import { createCaseError } from '../../common/error'; import { Operations } from '../../authorization'; import type { DeleteAllArgs, DeleteArgs } from './types'; +import type { AttachmentRequest } from '../../../common/types/api'; +import { AttachmentRequestRt } from '../../../common/types/api'; /** * Delete all comments for a case. @@ -119,7 +121,7 @@ export async function deleteComment( // we only want to store the fields related to the original request of the attachment, not fields like // created_at etc. So we'll use the decode to strip off the other fields. This is necessary because we don't know // what type of attachment this is. Depending on the type it could have various fields. - const attachmentRequestAttributes = decodeOrThrow(CommentRequestRt)(attachment.attributes); + const attachmentRequestAttributes = decodeOrThrow(AttachmentRequestRt)(attachment.attributes); await userActionService.creator.createUserAction({ type: UserActionTypes.comment, @@ -143,12 +145,12 @@ export async function deleteComment( interface HandleAlertsArgs { alertsService: CasesClientArgs['services']['alertsService']; - attachments: CommentRequest[]; + attachments: AttachmentRequest[]; caseId: string; } const handleAlerts = async ({ alertsService, attachments, caseId }: HandleAlertsArgs) => { - const alertAttachments = attachments.filter((attachment): attachment is CommentRequestAlertType => + const alertAttachments = attachments.filter((attachment): attachment is AlertAttachmentPayload => isCommentRequestTypeAlert(attachment) ); diff --git a/x-pack/plugins/cases/server/client/attachments/get.ts b/x-pack/plugins/cases/server/client/attachments/get.ts index 7e4bc311a65721..c53a8eb3483138 100644 --- a/x-pack/plugins/cases/server/client/attachments/get.ts +++ b/x-pack/plugins/cases/server/client/attachments/get.ts @@ -7,27 +7,25 @@ import type { SavedObject } from '@kbn/core/server'; +import type { + AlertAttachmentAttributes, + Attachment, + Attachments, +} from '../../../common/types/domain'; +import { AttachmentType } from '../../../common'; +import type { AlertResponse, AttachmentsFindResponse } from '../../../common/types/api'; +import { + AlertResponseRt, + FindAttachmentsQueryParamsRt, + AttachmentsFindResponseRt, +} from '../../../common/types/api'; import type { CasesClient } from '../client'; import type { CasesClientArgs } from '../types'; -import type { - AlertResponse, - Comments, - AttributesTypeAlerts, - Comment, - CommentsFindResponse, -} from '../../../common/api'; + import type { FindCommentsArgs, GetAllAlertsAttachToCase, GetAllArgs, GetArgs } from './types'; import { CASE_COMMENT_SAVED_OBJECT, CASE_SAVED_OBJECT } from '../../../common/constants'; -import { - FindCommentsQueryParamsRt, - CommentType, - CommentsRt, - CommentRt, - CommentsFindResponseRt, - decodeWithExcessOrThrow, - AlertResponseRt, -} from '../../../common/api'; +import { decodeWithExcessOrThrow } from '../../../common/api'; import { defaultSortField, transformComments, @@ -40,8 +38,11 @@ import { DEFAULT_PAGE, DEFAULT_PER_PAGE } from '../../routes/api'; import { buildFilter, combineFilters } from '../utils'; import { Operations } from '../../authorization'; import { decodeOrThrow } from '../../../common/api/runtime_types'; +import { AttachmentRt, AttachmentsRt } from '../../../common/types/domain'; -const normalizeAlertResponse = (alerts: Array>): AlertResponse => +const normalizeAlertResponse = ( + alerts: Array> +): AlertResponse => alerts.reduce((acc: AlertResponse, alert) => { const { ids, indices } = getIDsAndIndicesAsArrays(alert.attributes); @@ -113,7 +114,7 @@ export const getAllAlertsAttachToCase = async ( export async function find( { caseID, findQueryParams }: FindCommentsArgs, clientArgs: CasesClientArgs -): Promise { +): Promise { const { services: { attachmentService }, logger, @@ -121,14 +122,14 @@ export async function find( } = clientArgs; try { - const queryParams = decodeWithExcessOrThrow(FindCommentsQueryParamsRt)(findQueryParams); + const queryParams = decodeWithExcessOrThrow(FindAttachmentsQueryParamsRt)(findQueryParams); const { filter: authorizationFilter, ensureSavedObjectsAreAuthorized } = await authorization.getAuthorizationFilter(Operations.findComments); const filter = combineFilters([ buildFilter({ - filters: [CommentType.user], + filters: [AttachmentType.user], field: 'type', operator: 'or', type: CASE_COMMENT_SAVED_OBJECT, @@ -156,7 +157,7 @@ export async function find( const res = transformComments(theComments); - return decodeOrThrow(CommentsFindResponseRt)(res); + return decodeOrThrow(AttachmentsFindResponseRt)(res); } catch (error) { throw createCaseError({ message: `Failed to find comments case id: ${caseID}: ${error}`, @@ -172,7 +173,7 @@ export async function find( export async function get( { attachmentID, caseID }: GetArgs, clientArgs: CasesClientArgs -): Promise { +): Promise { const { services: { attachmentService }, logger, @@ -191,7 +192,7 @@ export async function get( const res = flattenCommentSavedObject(comment); - return decodeOrThrow(CommentRt)(res); + return decodeOrThrow(AttachmentRt)(res); } catch (error) { throw createCaseError({ message: `Failed to get comment case id: ${caseID} attachment id: ${attachmentID}: ${error}`, @@ -207,7 +208,7 @@ export async function get( export async function getAll( { caseID }: GetAllArgs, clientArgs: CasesClientArgs -): Promise { +): Promise { const { services: { caseService }, logger, @@ -233,7 +234,7 @@ export async function getAll( const res = flattenCommentSavedObjects(comments.saved_objects); - return decodeOrThrow(CommentsRt)(res); + return decodeOrThrow(AttachmentsRt)(res); } catch (error) { throw createCaseError({ message: `Failed to get all comments case id: ${caseID}: ${error}`, diff --git a/x-pack/plugins/cases/server/client/attachments/types.ts b/x-pack/plugins/cases/server/client/attachments/types.ts index 75099cdd9f6457..0dd700a8131107 100644 --- a/x-pack/plugins/cases/server/client/attachments/types.ts +++ b/x-pack/plugins/cases/server/client/attachments/types.ts @@ -6,11 +6,11 @@ */ import type { - BulkCreateCommentRequest, - CommentPatchRequest, - CommentRequest, - FindCommentsQueryParams, -} from '../../../common/api'; + BulkCreateAttachmentsRequest, + AttachmentPatchRequest, + AttachmentRequest, + FindAttachmentsQueryParams, +} from '../../../common/types/api'; /** * The arguments needed for creating a new attachment to a case. @@ -23,12 +23,12 @@ export interface AddArgs { /** * The attachment values. */ - comment: CommentRequest; + comment: AttachmentRequest; } export interface BulkCreateArgs { caseId: string; - attachments: BulkCreateCommentRequest; + attachments: BulkCreateAttachmentsRequest; } /** @@ -80,7 +80,7 @@ export interface FindCommentsArgs { /** * Optional parameters for filtering the returned attachments */ - findQueryParams?: FindCommentsQueryParams; + findQueryParams?: FindAttachmentsQueryParams; } /** @@ -130,5 +130,5 @@ export interface UpdateArgs { /** * The full attachment request with the fields updated with appropriate values */ - updateRequest: CommentPatchRequest; + updateRequest: AttachmentPatchRequest; } diff --git a/x-pack/plugins/cases/server/client/attachments/update.ts b/x-pack/plugins/cases/server/client/attachments/update.ts index 670e6fccfe66b7..15d0fc41cfc136 100644 --- a/x-pack/plugins/cases/server/client/attachments/update.ts +++ b/x-pack/plugins/cases/server/client/attachments/update.ts @@ -7,11 +7,12 @@ import Boom from '@hapi/boom'; +import { AttachmentPatchRequestRt } from '../../../common/types/api'; import { CaseCommentModel } from '../../common/models'; import { createCaseError } from '../../common/error'; import { isCommentRequestTypeExternalReference } from '../../../common/utils/attachments'; -import type { Case } from '../../../common/api'; -import { CommentPatchRequestRt, decodeWithExcessOrThrow } from '../../../common/api'; +import type { Case } from '../../../common/types/domain'; +import { decodeWithExcessOrThrow } from '../../../common/api'; import { CASE_SAVED_OBJECT } from '../../../common/constants'; import type { CasesClientArgs } from '..'; import { decodeCommentRequest } from '../utils'; @@ -39,7 +40,7 @@ export async function update( id: queryCommentId, version: queryCommentVersion, ...queryRestAttributes - } = decodeWithExcessOrThrow(CommentPatchRequestRt)(queryParams); + } = decodeWithExcessOrThrow(AttachmentPatchRequestRt)(queryParams); decodeCommentRequest(queryRestAttributes, externalReferenceAttachmentTypeRegistry); diff --git a/x-pack/plugins/cases/server/client/attachments/validators.ts b/x-pack/plugins/cases/server/client/attachments/validators.ts index 4a66d32c31c19c..1461dca566ff7a 100644 --- a/x-pack/plugins/cases/server/client/attachments/validators.ts +++ b/x-pack/plugins/cases/server/client/attachments/validators.ts @@ -10,7 +10,7 @@ import { isCommentRequestTypeExternalReference, isCommentRequestTypePersistableState, } from '../../../common/utils/attachments'; -import type { CommentRequest } from '../../../common/api'; +import type { AttachmentRequest } from '../../../common/types/api'; import type { ExternalReferenceAttachmentTypeRegistry } from '../../attachment_framework/external_reference_registry'; import type { PersistableStateAttachmentTypeRegistry } from '../../attachment_framework/persistable_state_registry'; @@ -19,7 +19,7 @@ export const validateRegisteredAttachments = ({ persistableStateAttachmentTypeRegistry, externalReferenceAttachmentTypeRegistry, }: { - query: CommentRequest; + query: AttachmentRequest; persistableStateAttachmentTypeRegistry: PersistableStateAttachmentTypeRegistry; externalReferenceAttachmentTypeRegistry: ExternalReferenceAttachmentTypeRegistry; }) => { diff --git a/x-pack/plugins/cases/server/client/cases/bulk_get.ts b/x-pack/plugins/cases/server/client/cases/bulk_get.ts index 4665c27cebbf60..02f62471a783e3 100644 --- a/x-pack/plugins/cases/server/client/cases/bulk_get.ts +++ b/x-pack/plugins/cases/server/client/cases/bulk_get.ts @@ -7,16 +7,10 @@ import { partition } from 'lodash'; -import type { - CasesBulkGetResponse, - CasesBulkGetRequest, - CaseAttributes, -} from '../../../common/api'; -import { - CasesBulkGetRequestRt, - decodeWithExcessOrThrow, - CasesBulkGetResponseRt, -} from '../../../common/api'; +import type { CaseAttributes } from '../../../common/types/domain'; +import type { CasesBulkGetRequest, CasesBulkGetResponse } from '../../../common/types/api'; +import { CasesBulkGetResponseRt, CasesBulkGetRequestRt } from '../../../common/types/api'; +import { decodeWithExcessOrThrow } from '../../../common/api'; import { createCaseError } from '../../common/error'; import { flattenCaseSavedObject } from '../../common/utils'; import type { CasesClientArgs } from '../types'; diff --git a/x-pack/plugins/cases/server/client/cases/client.ts b/x-pack/plugins/cases/server/client/cases/client.ts index f2ab1b4982025a..e2e0e6a7f8ec46 100644 --- a/x-pack/plugins/cases/server/client/cases/client.ts +++ b/x-pack/plugins/cases/server/client/cases/client.ts @@ -5,22 +5,20 @@ * 2.0. */ +import type { Case, Cases, User } from '../../../common/types/domain'; import type { CasePostRequest, - CasesPatchRequest, CasesFindRequest, - User, + CasesFindResponse, + CaseResolveResponse, + CasesBulkGetRequest, + CasesPatchRequest, AllTagsFindRequest, AllCategoriesFindRequest, AllReportersFindRequest, - CasesByAlertId, - CasesBulkGetRequest, + GetRelatedCasesByAlertResponse, CasesBulkGetResponse, - Case, - CaseResolveResponse, - Cases, - CasesFindResponse, -} from '../../../common/api'; +} from '../../../common/types/api'; import type { CasesClient } from '../client'; import type { CasesClientInternal } from '../client_internal'; import type { CasesClientArgs } from '../types'; @@ -90,7 +88,7 @@ export interface CasesSubClient { /** * Retrieves the cases ID and title that have the requested alert attached to them */ - getCasesByAlertID(params: CasesByAlertIDParams): Promise; + getCasesByAlertID(params: CasesByAlertIDParams): Promise; } /** diff --git a/x-pack/plugins/cases/server/client/cases/create.test.ts b/x-pack/plugins/cases/server/client/cases/create.test.ts index 650d98d5a8fcf2..9918cc302c033e 100644 --- a/x-pack/plugins/cases/server/client/cases/create.test.ts +++ b/x-pack/plugins/cases/server/client/cases/create.test.ts @@ -12,11 +12,10 @@ import { MAX_TITLE_LENGTH, } from '../../../common/constants'; import { SECURITY_SOLUTION_OWNER } from '../../../common'; -import { CaseSeverity } from '../../../common/api'; -import { ConnectorTypes } from '../../../common/types/domain'; import { mockCases } from '../../mocks'; import { createCasesClientMockArgs } from '../mocks'; import { create } from './create'; +import { CaseSeverity, ConnectorTypes } from '../../../common/types/domain'; describe('create', () => { const theCase = { diff --git a/x-pack/plugins/cases/server/client/cases/create.ts b/x-pack/plugins/cases/server/client/cases/create.ts index 347444bcd66140..9467fe9ecc8875 100644 --- a/x-pack/plugins/cases/server/client/cases/create.ts +++ b/x-pack/plugins/cases/server/client/cases/create.ts @@ -9,14 +9,9 @@ import Boom from '@hapi/boom'; import { SavedObjectsUtils } from '@kbn/core/server'; -import { UserActionTypes } from '../../../common/types/domain'; -import type { Case, CasePostRequest } from '../../../common/api'; -import { - CaseRt, - CasePostRequestRt, - CaseSeverity, - decodeWithExcessOrThrow, -} from '../../../common/api'; +import type { Case } from '../../../common/types/domain'; +import { CaseSeverity, UserActionTypes, CaseRt } from '../../../common/types/domain'; +import { decodeWithExcessOrThrow } from '../../../common/api'; import { MAX_ASSIGNEES_PER_CASE } from '../../../common/constants'; import { areTotalAssigneesInvalid } from '../../../common/utils/validators'; @@ -26,6 +21,8 @@ import { flattenCaseSavedObject, transformNewCase } from '../../common/utils'; import type { CasesClientArgs } from '..'; import { LICENSING_CASE_ASSIGNMENT_FEATURE } from '../../common/constants'; import { decodeOrThrow } from '../../../common/api/runtime_types'; +import type { CasePostRequest } from '../../../common/types/api'; +import { CasePostRequestRt } from '../../../common/types/api'; /** * Creates a new case. diff --git a/x-pack/plugins/cases/server/client/cases/delete.ts b/x-pack/plugins/cases/server/client/cases/delete.ts index 78fffc19a2edca..86b9417851fe18 100644 --- a/x-pack/plugins/cases/server/client/cases/delete.ts +++ b/x-pack/plugins/cases/server/client/cases/delete.ts @@ -10,8 +10,9 @@ import pMap from 'p-map'; import { chunk } from 'lodash'; import type { SavedObjectsBulkDeleteObject } from '@kbn/core/server'; import type { FileServiceStart } from '@kbn/files-plugin/server'; -import type { CasesDeleteRequest } from '../../../common/api'; -import { CasesDeleteRequestRt, decodeWithExcessOrThrow } from '../../../common/api'; +import type { CasesDeleteRequest } from '../../../common/types/api'; +import { CasesDeleteRequestRt } from '../../../common/types/api'; +import { decodeWithExcessOrThrow } from '../../../common/api'; import { CASE_COMMENT_SAVED_OBJECT, CASE_SAVED_OBJECT, diff --git a/x-pack/plugins/cases/server/client/cases/find.test.ts b/x-pack/plugins/cases/server/client/cases/find.test.ts index fc1bd1ef3d2a75..0a09fa8b5b7b27 100644 --- a/x-pack/plugins/cases/server/client/cases/find.test.ts +++ b/x-pack/plugins/cases/server/client/cases/find.test.ts @@ -6,7 +6,7 @@ */ import { v1 as uuidv1 } from 'uuid'; -import type { Case } from '../../../common/api'; +import type { Case } from '../../../common/types/domain'; import { MAX_ASSIGNEES_FILTER_LENGTH, diff --git a/x-pack/plugins/cases/server/client/cases/find.ts b/x-pack/plugins/cases/server/client/cases/find.ts index 49ae281a403a62..9c8699ce9db848 100644 --- a/x-pack/plugins/cases/server/client/cases/find.ts +++ b/x-pack/plugins/cases/server/client/cases/find.ts @@ -8,13 +8,10 @@ import { isEmpty } from 'lodash'; import Boom from '@hapi/boom'; +import type { CasesFindRequest, CasesFindResponse } from '../../../common/types/api'; +import { CasesFindRequestRt, CasesFindResponseRt } from '../../../common/types/api'; import { MAX_CATEGORY_FILTER_LENGTH } from '../../../common/constants'; -import type { CasesFindResponse, CasesFindRequest } from '../../../common/api'; -import { - CasesFindRequestRt, - decodeWithExcessOrThrow, - CasesFindResponseRt, -} from '../../../common/api'; +import { decodeWithExcessOrThrow } from '../../../common/api'; import { createCaseError } from '../../common/error'; import { asArray, transformCases } from '../../common/utils'; diff --git a/x-pack/plugins/cases/server/client/cases/get.ts b/x-pack/plugins/cases/server/client/cases/get.ts index efad909b30266a..343476d284fca8 100644 --- a/x-pack/plugins/cases/server/client/cases/get.ts +++ b/x-pack/plugins/cases/server/client/cases/get.ts @@ -6,31 +6,27 @@ */ import type { SavedObjectsResolveResponse } from '@kbn/core/server'; +import type { AttachmentTotals, Case, CaseAttributes, User } from '../../../common/types/domain'; import type { - Case, - CaseResolveResponse, - User, - AllTagsFindRequest, AllCategoriesFindRequest, AllReportersFindRequest, + AllTagsFindRequest, + CaseResolveResponse, CasesByAlertIDRequest, - CasesByAlertId, - CaseAttributes, - AttachmentTotals, -} from '../../../common/api'; + GetRelatedCasesByAlertResponse, +} from '../../../common/types/api'; import { - AllTagsFindRequestRt, AllCategoriesFindRequestRt, - CaseRt, - CaseResolveResponseRt, - decodeWithExcessOrThrow, AllReportersFindRequestRt, + AllTagsFindRequestRt, + CaseResolveResponseRt, CasesByAlertIDRequestRt, - CasesByAlertIdRt, - GetTagsResponseRt, - GetReportersResponseRt, GetCategoriesResponseRt, -} from '../../../common/api'; + GetRelatedCasesByAlertResponseRt, + GetReportersResponseRt, + GetTagsResponseRt, +} from '../../../common/types/api'; +import { decodeWithExcessOrThrow } from '../../../common/api'; import { createCaseError } from '../../common/error'; import { countAlertsForID, flattenCaseSavedObject, countUserAttachments } from '../../common/utils'; import type { CasesClientArgs } from '..'; @@ -39,6 +35,7 @@ import { combineAuthorizedAndOwnerFilter } from '../utils'; import { CasesService } from '../../services'; import type { CaseSavedObjectTransformed } from '../../common/types/case'; import { decodeOrThrow } from '../../../common/api/runtime_types'; +import { CaseRt } from '../../../common/types/domain'; /** * Parameters for finding cases IDs using an alert ID @@ -63,7 +60,7 @@ export interface CasesByAlertIDParams { export const getCasesByAlertID = async ( { alertID, options }: CasesByAlertIDParams, clientArgs: CasesClientArgs -): Promise => { +): Promise => { const { services: { caseService, attachmentService }, logger, @@ -134,7 +131,7 @@ export const getCasesByAlertID = async ( totals: getAttachmentTotalsForCaseId(caseInfo.id, commentStats), })); - return decodeOrThrow(CasesByAlertIdRt)(res); + return decodeOrThrow(GetRelatedCasesByAlertResponseRt)(res); } catch (error) { throw createCaseError({ message: `Failed to get case IDs using alert ID: ${alertID} options: ${JSON.stringify( diff --git a/x-pack/plugins/cases/server/client/cases/mock.ts b/x-pack/plugins/cases/server/client/cases/mock.ts index ca96d20bad5700..bca6b12b2efd5e 100644 --- a/x-pack/plugins/cases/server/client/cases/mock.ts +++ b/x-pack/plugins/cases/server/client/cases/mock.ts @@ -6,10 +6,14 @@ */ import type { CaseUserActionsDeprecatedResponse } from '../../../common/types/api'; -import { ConnectorTypes, UserActionActions } from '../../../common/types/domain'; -import type { Comment, CommentResponseAlertsType } from '../../../common/api'; -import { CommentType, ExternalReferenceStorageType } from '../../../common/api'; -import { FILE_ATTACHMENT_TYPE, SECURITY_SOLUTION_OWNER } from '../../../common/constants'; +import type { AlertAttachment, Attachment } from '../../../common/types/domain'; +import { + AttachmentType, + ConnectorTypes, + ExternalReferenceStorageType, + UserActionActions, +} from '../../../common/types/domain'; +import { SECURITY_SOLUTION_OWNER, FILE_ATTACHMENT_TYPE } from '../../../common/constants'; export const updateUser = { updated_at: '2020-03-13T08:34:53.450Z', @@ -23,10 +27,10 @@ const entity = { updatedBy: null, }; -export const comment: Comment = { +export const comment: Attachment = { id: 'comment-user-1', comment: 'Wow, good luck catching that bad meanie!', - type: CommentType.user as const, + type: AttachmentType.user as const, created_at: '2019-11-25T21:55:00.177Z', created_by: { full_name: 'elastic', @@ -45,10 +49,10 @@ export const comment: Comment = { version: 'WzEsMV0=', }; -export const isolateCommentActions: Comment = { +export const isolateCommentActions: Attachment = { id: 'mock-action-comment-1', comment: 'Isolating this for investigation', - type: CommentType.actions as const, + type: AttachmentType.actions as const, created_at: '2019-11-25T21:55:00.177Z', actions: { targets: [ @@ -76,10 +80,10 @@ export const isolateCommentActions: Comment = { version: 'WzEsMV0=', }; -export const releaseCommentActions: Comment = { +export const releaseCommentActions: Attachment = { id: 'mock-action-comment-2', comment: 'Releasing this for investigation', - type: CommentType.actions as const, + type: AttachmentType.actions as const, created_at: '2019-11-25T21:55:00.177Z', actions: { targets: [ @@ -107,10 +111,10 @@ export const releaseCommentActions: Comment = { version: 'WzEsMV0=', }; -export const isolateCommentActionsMultipleTargets: Comment = { +export const isolateCommentActionsMultipleTargets: Attachment = { id: 'mock-action-comment-3', comment: 'Isolating this for investigation', - type: CommentType.actions as const, + type: AttachmentType.actions as const, created_at: '2019-11-25T21:55:00.177Z', actions: { targets: [ @@ -142,7 +146,7 @@ export const isolateCommentActionsMultipleTargets: Comment = { version: 'WzEsMV0=', }; -export const commentAlert: Comment = { +export const commentAlert: Attachment = { id: 'comment-alert-1', alertId: 'alert-id-1', index: 'alert-index-1', @@ -150,7 +154,7 @@ export const commentAlert: Comment = { id: 'rule-id-1', name: 'rule-name-1', }, - type: CommentType.alert as const, + type: AttachmentType.alert as const, created_at: '2019-11-25T21:55:00.177Z', created_by: { full_name: 'elastic', @@ -169,18 +173,18 @@ export const commentAlert: Comment = { version: 'WzEsMV0=', }; -export const commentAlertMultipleIds: CommentResponseAlertsType = { +export const commentAlertMultipleIds: AlertAttachment = { ...commentAlert, id: 'comment-alert-2', alertId: ['alert-id-1', 'alert-id-2'], index: 'alert-index-1', - type: CommentType.alert as const, + type: AttachmentType.alert as const, owner: SECURITY_SOLUTION_OWNER, }; -export const commentExternalReference: Comment = { +export const commentExternalReference: Attachment = { id: 'comment-external-reference-1', - type: CommentType.externalReference as const, + type: AttachmentType.externalReference as const, externalReferenceId: 'my-id', externalReferenceStorage: { type: ExternalReferenceStorageType.elasticSearchDoc as const, @@ -205,9 +209,9 @@ export const commentExternalReference: Comment = { version: 'WzEsMV0=', }; -export const commentPersistableState: Comment = { +export const commentPersistableState: Attachment = { id: 'comment-persistable-state-1', - type: CommentType.persistableState, + type: AttachmentType.persistableState, persistableStateAttachmentTypeId: '.test', persistableStateAttachmentState: { foo: 'foo', injectedId: 'testRef' }, created_at: '2019-11-25T21:55:00.177Z', @@ -228,7 +232,7 @@ export const commentPersistableState: Comment = { version: 'WzEsMV0=', }; -export const commentFileExternalReference: Comment = { +export const commentFileExternalReference: Attachment = { ...commentExternalReference, externalReferenceAttachmentTypeId: FILE_ATTACHMENT_TYPE, externalReferenceMetadata: { files: [{ name: '', extension: '', mimeType: '', created: '' }] }, diff --git a/x-pack/plugins/cases/server/client/cases/push.ts b/x-pack/plugins/cases/server/client/cases/push.ts index c8924275d90e37..cf3732c065e23a 100644 --- a/x-pack/plugins/cases/server/client/cases/push.ts +++ b/x-pack/plugins/cases/server/client/cases/push.ts @@ -12,16 +12,24 @@ import type { SavedObjectsFindResponse } from '@kbn/core/server'; import type { UserProfile } from '@kbn/security-plugin/common'; import type { SecurityPluginStart } from '@kbn/security-plugin/server'; import { asSavedObjectExecutionSource } from '@kbn/actions-plugin/server'; -import type { ActionConnector, ConfigurationAttributes } from '../../../common/types/domain'; -import { UserActionTypes } from '../../../common/types/domain'; import type { + ActionConnector, + AlertAttachmentPayload, + AttachmentAttributes, Case, - ExternalServiceResponse, - CommentRequestAlertType, - CommentAttributes, -} from '../../../common/api'; -import { CaseRt, CaseStatuses, OWNER_FIELD, CommentType } from '../../../common/api'; -import { CASE_COMMENT_SAVED_OBJECT, CASE_SAVED_OBJECT } from '../../../common/constants'; + ConfigurationAttributes, +} from '../../../common/types/domain'; +import { + CaseRt, + CaseStatuses, + UserActionTypes, + AttachmentType, +} from '../../../common/types/domain'; +import { + CASE_COMMENT_SAVED_OBJECT, + CASE_SAVED_OBJECT, + OWNER_FIELD, +} from '../../../common/constants'; import { createIncident, getDurationInSeconds, getUserProfiles } from './utils'; import { createCaseError } from '../../common/error'; @@ -36,6 +44,7 @@ import { casesConnectors } from '../../connectors'; import { getAlerts } from '../alerts/get'; import { buildFilter } from '../utils'; import { decodeOrThrow } from '../../../common/api/runtime_types'; +import type { ExternalServiceResponse } from '../../../common/types/api'; /** * Returns true if the case should be closed based on the configuration settings. @@ -57,9 +66,9 @@ const changeAlertsStatusToClose = async ( const alertAttachments = (await caseService.getAllCaseComments({ id: [caseId], options: { - filter: nodeBuilder.is(`${CASE_COMMENT_SAVED_OBJECT}.attributes.type`, CommentType.alert), + filter: nodeBuilder.is(`${CASE_COMMENT_SAVED_OBJECT}.attributes.type`, AttachmentType.alert), }, - })) as SavedObjectsFindResponse; + })) as SavedObjectsFindResponse; const alerts = alertAttachments.saved_objects .map((attachment) => @@ -289,7 +298,7 @@ export const push = async ( attributes: { ...origComment.attributes, ...updatedComment?.attributes, - } as CommentAttributes, + } as AttachmentAttributes, version: updatedComment?.version ?? origComment.version, references: origComment?.references ?? [], }; diff --git a/x-pack/plugins/cases/server/client/cases/update.ts b/x-pack/plugins/cases/server/client/cases/update.ts index a685f3c2a2fc79..c7b2e124dbf76f 100644 --- a/x-pack/plugins/cases/server/client/cases/update.ts +++ b/x-pack/plugins/cases/server/client/cases/update.ts @@ -17,24 +17,9 @@ import type { import { nodeBuilder } from '@kbn/es-query'; +import type { CasePatchRequest, CasesPatchRequest } from '../../../common/types/api'; import { areTotalAssigneesInvalid } from '../../../common/utils/validators'; -import type { - CaseAssignees, - CaseAttributes, - CasePatchRequest, - Case, - CasesPatchRequest, - Cases, - CommentAttributes, - User, -} from '../../../common/api'; -import { - CasesPatchRequestRt, - CasesRt, - CaseStatuses, - CommentType, - decodeWithExcessOrThrow, -} from '../../../common/api'; +import { decodeWithExcessOrThrow } from '../../../common/api'; import { CASE_COMMENT_SAVED_OBJECT, CASE_SAVED_OBJECT, @@ -59,6 +44,16 @@ import { LICENSING_CASE_ASSIGNMENT_FEATURE } from '../../common/constants'; import type { LicensingService } from '../../services/licensing'; import type { CaseSavedObjectTransformed } from '../../common/types/case'; import { decodeOrThrow } from '../../../common/api/runtime_types'; +import type { + Cases, + Case, + CaseAttributes, + User, + CaseAssignees, + AttachmentAttributes, +} from '../../../common/types/domain'; +import { CasesPatchRequestRt } from '../../../common/types/api'; +import { CasesRt, CaseStatuses, AttachmentType } from '../../../common/types/domain'; /** * Throws an error if any of the requests attempt to update the owner of a case. @@ -136,7 +131,7 @@ function throwIfTotalAssigneesAreInvalid(requests: UpdateRequestWithOriginalCase * Get the id from a reference in a comment for a specific type. */ function getID( - comment: SavedObject, + comment: SavedObject, type: typeof CASE_SAVED_OBJECT ): string | undefined { return comment.references.find((ref) => ref.type === type)?.id; @@ -151,14 +146,14 @@ async function getAlertComments({ }: { casesToSync: UpdateRequestWithOriginalCase[]; caseService: CasesService; -}): Promise> { +}): Promise> { const idsOfCasesToSync = casesToSync.map(({ updateReq }) => updateReq.id); // getAllCaseComments will by default get all the comments, unless page or perPage fields are set return caseService.getAllCaseComments({ id: idsOfCasesToSync, options: { - filter: nodeBuilder.is(`${CASE_COMMENT_SAVED_OBJECT}.attributes.type`, CommentType.alert), + filter: nodeBuilder.is(`${CASE_COMMENT_SAVED_OBJECT}.attributes.type`, AttachmentType.alert), }, }); } @@ -170,7 +165,7 @@ function getSyncStatusForComment({ alertComment, casesToSyncToStatus, }: { - alertComment: SavedObjectsFindResult; + alertComment: SavedObjectsFindResult; casesToSyncToStatus: Map; }): CaseStatuses { const id = getID(alertComment, CASE_SAVED_OBJECT); diff --git a/x-pack/plugins/cases/server/client/cases/utils.test.ts b/x-pack/plugins/cases/server/client/cases/utils.test.ts index 6daa3fe218f802..b6f2bafe24f07b 100644 --- a/x-pack/plugins/cases/server/client/cases/utils.test.ts +++ b/x-pack/plugins/cases/server/client/cases/utils.test.ts @@ -28,13 +28,12 @@ import { formatComments, addKibanaInformationToDescription, } from './utils'; -import { CaseStatuses } from '../../../common/api'; +import { CaseStatuses, UserActionActions } from '../../../common/types/domain'; import { flattenCaseSavedObject } from '../../common/utils'; import { SECURITY_SOLUTION_OWNER } from '../../../common/constants'; import { casesConnectors } from '../../connectors'; import { userProfiles, userProfilesMap } from '../user_profiles.mock'; import { mappings, mockCases } from '../../mocks'; -import { UserActionActions } from '../../../common/types/domain'; const allComments = [ commentObj, diff --git a/x-pack/plugins/cases/server/client/cases/utils.ts b/x-pack/plugins/cases/server/client/cases/utils.ts index efc715b9cff24b..5c77986742d54d 100644 --- a/x-pack/plugins/cases/server/client/cases/utils.ts +++ b/x-pack/plugins/cases/server/client/cases/utils.ts @@ -12,23 +12,20 @@ import type { SecurityPluginStart } from '@kbn/security-plugin/server'; import type { UserProfileWithAvatar } from '@kbn/user-profile-components'; import type { ActionConnector, - ConnectorMappingSource, + Attachment, + Case, + CaseAssignees, + CaseAttributes, ConnectorMappings, + ConnectorMappingSource, ConnectorMappingTarget, + ExternalService, + User, } from '../../../common/types/domain'; -import { UserActionTypes } from '../../../common/types/domain'; +import { CaseStatuses, UserActionTypes, AttachmentType } from '../../../common/types/domain'; import type { CaseUserActionsDeprecatedResponse } from '../../../common/types/api'; import { CASE_VIEW_PAGE_TABS } from '../../../common/types'; import { isPushedUserAction } from '../../../common/utils/user_actions'; -import type { - CaseFullExternalService, - Case, - Comment, - User, - CaseAttributes, - CaseAssignees, -} from '../../../common/api'; -import { CommentType, CaseStatuses } from '../../../common/api'; import type { CasesClientGetAlertsResponse } from '../alerts/types'; import type { ExternalServiceComment, ExternalServiceIncident } from './types'; import { getAlertIds } from '../utils'; @@ -55,7 +52,7 @@ export const dedupAssignees = (assignees?: CaseAssignees): CaseAssignees | undef return uniqBy(assignees, 'uid'); }; -type LatestPushInfo = { index: number; pushedInfo: CaseFullExternalService } | null; +type LatestPushInfo = { index: number; pushedInfo: ExternalService | null } | null; export const getLatestPushInfo = ( connectorId: string, @@ -80,14 +77,14 @@ export const getLatestPushInfo = ( return null; }; -const getCommentContent = (comment: Comment): string => { - if (comment.type === CommentType.user) { +const getCommentContent = (comment: Attachment): string => { + if (comment.type === AttachmentType.user) { return comment.comment; - } else if (comment.type === CommentType.alert) { + } else if (comment.type === AttachmentType.alert) { const ids = getAlertIds(comment); return `Alert with ids ${ids.join(', ')} added to case`; } else if ( - comment.type === CommentType.actions && + comment.type === AttachmentType.actions && (comment.actions.type === 'isolate' || comment.actions.type === 'unisolate') ) { const firstHostname = @@ -115,7 +112,7 @@ const getAlertsInfo = ( const res = comments?.reduce(({ totalComments, pushed, totalAlerts }, comment) => { - if (comment.type === CommentType.alert) { + if (comment.type === AttachmentType.alert) { return { totalComments: totalComments + 1, pushed: comment.pushed_at != null ? pushed + 1 : pushed, @@ -258,7 +255,7 @@ export const formatComments = ({ const commentsToBeUpdated = theCase.comments?.filter( (comment) => // We push only user's comments - (comment.type === CommentType.user || comment.type === CommentType.actions) && + (comment.type === AttachmentType.user || comment.type === AttachmentType.actions) && commentsIdsToBeUpdated.has(comment.id) ); diff --git a/x-pack/plugins/cases/server/client/metrics/actions/actions.test.ts b/x-pack/plugins/cases/server/client/metrics/actions/actions.test.ts index 56c81a9a41d597..ab25e206c05cfe 100644 --- a/x-pack/plugins/cases/server/client/metrics/actions/actions.test.ts +++ b/x-pack/plugins/cases/server/client/metrics/actions/actions.test.ts @@ -5,13 +5,13 @@ * 2.0. */ -import type { Case } from '../../../../common/api'; import { createCasesClientMock } from '../../mocks'; import type { CasesClientArgs } from '../../types'; import { loggingSystemMock } from '@kbn/core/server/mocks'; import { createAttachmentServiceMock } from '../../../services/mocks'; import { Actions } from './actions'; +import type { Case } from '../../../../common/types/domain'; const clientMock = createCasesClientMock(); const attachmentService = createAttachmentServiceMock(); diff --git a/x-pack/plugins/cases/server/client/metrics/actions/aggregations/isolate_host.ts b/x-pack/plugins/cases/server/client/metrics/actions/aggregations/isolate_host.ts index b6aa821bee875e..ab6e9a881e6027 100644 --- a/x-pack/plugins/cases/server/client/metrics/actions/aggregations/isolate_host.ts +++ b/x-pack/plugins/cases/server/client/metrics/actions/aggregations/isolate_host.ts @@ -5,8 +5,8 @@ * 2.0. */ +import { IsolateHostActionType } from '../../../../../common/types/domain'; import type { SingleCaseMetricsResponse } from '../../../../../common/api'; -import { IsolateHostActionType } from '../../../../../common/api'; import { CASE_COMMENT_SAVED_OBJECT } from '../../../../../common/constants'; import type { AggregationBuilder, AggregationResponse } from '../../types'; diff --git a/x-pack/plugins/cases/server/client/metrics/alerts/count.test.ts b/x-pack/plugins/cases/server/client/metrics/alerts/count.test.ts index 9fa308f93049ee..3ed678dcea21f8 100644 --- a/x-pack/plugins/cases/server/client/metrics/alerts/count.test.ts +++ b/x-pack/plugins/cases/server/client/metrics/alerts/count.test.ts @@ -5,13 +5,13 @@ * 2.0. */ -import type { Case } from '../../../../common/api'; import { createCasesClientMock } from '../../mocks'; import type { CasesClientArgs } from '../../types'; import { loggingSystemMock } from '@kbn/core/server/mocks'; import { createAttachmentServiceMock } from '../../../services/mocks'; import { AlertsCount } from './count'; +import type { Case } from '../../../../common/types/domain'; const clientMock = createCasesClientMock(); const attachmentService = createAttachmentServiceMock(); diff --git a/x-pack/plugins/cases/server/client/metrics/all_cases/mttr.test.ts b/x-pack/plugins/cases/server/client/metrics/all_cases/mttr.test.ts index bff57ce82a176b..9b2bbbf3ff4123 100644 --- a/x-pack/plugins/cases/server/client/metrics/all_cases/mttr.test.ts +++ b/x-pack/plugins/cases/server/client/metrics/all_cases/mttr.test.ts @@ -5,7 +5,7 @@ * 2.0. */ -import type { Case } from '../../../../common/api'; +import type { Case } from '../../../../common/types/domain'; import { createCasesClientMock } from '../../mocks'; import type { CasesClientArgs } from '../../types'; import { loggingSystemMock } from '@kbn/core/server/mocks'; diff --git a/x-pack/plugins/cases/server/client/metrics/client.ts b/x-pack/plugins/cases/server/client/metrics/client.ts index 6744bb99c9c52c..19cf85b6038101 100644 --- a/x-pack/plugins/cases/server/client/metrics/client.ts +++ b/x-pack/plugins/cases/server/client/metrics/client.ts @@ -5,11 +5,10 @@ * 2.0. */ +import type { CasesStatusRequest, CasesStatusResponse } from '../../../common/types/api'; import type { SingleCaseMetricsResponse, CasesMetricsRequest, - CasesStatusRequest, - CasesStatusResponse, CasesMetricsResponse, } from '../../../common/api'; import type { CasesClient } from '../client'; diff --git a/x-pack/plugins/cases/server/client/metrics/get_case_metrics.test.ts b/x-pack/plugins/cases/server/client/metrics/get_case_metrics.test.ts index 023b951dcbf98c..0148053d565954 100644 --- a/x-pack/plugins/cases/server/client/metrics/get_case_metrics.test.ts +++ b/x-pack/plugins/cases/server/client/metrics/get_case_metrics.test.ts @@ -8,8 +8,8 @@ import { loggingSystemMock, savedObjectsClientMock } from '@kbn/core/server/mocks'; import { getCaseMetrics } from './get_case_metrics'; -import type { Case } from '../../../common/api'; -import { CaseStatuses } from '../../../common/api'; +import type { Case } from '../../../common/types/domain'; +import { CaseStatuses } from '../../../common/types/domain'; import type { CasesClientMock } from '../mocks'; import { createCasesClientMock } from '../mocks'; import type { CasesClientArgs } from '../types'; diff --git a/x-pack/plugins/cases/server/client/metrics/get_status_totals.ts b/x-pack/plugins/cases/server/client/metrics/get_status_totals.ts index 25173172997cd3..13d35bf2110bd9 100644 --- a/x-pack/plugins/cases/server/client/metrics/get_status_totals.ts +++ b/x-pack/plugins/cases/server/client/metrics/get_status_totals.ts @@ -5,12 +5,9 @@ * 2.0. */ -import type { CasesStatusRequest, CasesStatusResponse } from '../../../common/api'; -import { - CasesStatusRequestRt, - decodeWithExcessOrThrow, - CasesStatusResponseRt, -} from '../../../common/api'; +import type { CasesStatusRequest, CasesStatusResponse } from '../../../common/types/api'; +import { CasesStatusRequestRt, CasesStatusResponseRt } from '../../../common/types/api'; +import { decodeWithExcessOrThrow } from '../../../common/api'; import type { CasesClientArgs } from '../types'; import { Operations } from '../../authorization'; import { constructQueryOptions } from '../utils'; diff --git a/x-pack/plugins/cases/server/client/metrics/lifespan.test.ts b/x-pack/plugins/cases/server/client/metrics/lifespan.test.ts index 523fee84b08234..10bf4be55928e8 100644 --- a/x-pack/plugins/cases/server/client/metrics/lifespan.test.ts +++ b/x-pack/plugins/cases/server/client/metrics/lifespan.test.ts @@ -7,7 +7,7 @@ import type { UserActionAttributes } from '../../../common/types/domain'; import type { SavedObject } from '@kbn/core/server'; -import { CaseStatuses } from '../../../common/api'; +import { CaseStatuses } from '../../../common/types/domain'; import { getStatusInfo } from './lifespan'; import { createStatusChangeSavedObject } from './test_utils/lifespan'; diff --git a/x-pack/plugins/cases/server/client/metrics/lifespan.ts b/x-pack/plugins/cases/server/client/metrics/lifespan.ts index 305edae203334b..17f02cc089b6b0 100644 --- a/x-pack/plugins/cases/server/client/metrics/lifespan.ts +++ b/x-pack/plugins/cases/server/client/metrics/lifespan.ts @@ -8,9 +8,8 @@ import type { SavedObject } from '@kbn/core/server'; import type { StatusUserAction, UserActionAttributes } from '../../../common/types/domain'; import type { UserActionWithResponse } from '../../../common/types/api'; -import { StatusUserActionRt } from '../../../common/types/domain'; +import { StatusUserActionRt, CaseStatuses } from '../../../common/types/domain'; import type { SingleCaseMetricsResponse, StatusInfo } from '../../../common/api'; -import { CaseStatuses } from '../../../common/api'; import { Operations } from '../../authorization'; import { createCaseError } from '../../common/error'; import { SingleCaseBaseHandler } from './single_case_base_handler'; diff --git a/x-pack/plugins/cases/server/client/metrics/test_utils/lifespan.ts b/x-pack/plugins/cases/server/client/metrics/test_utils/lifespan.ts index 98cc17a31fdd48..8975ca78fa0b0f 100644 --- a/x-pack/plugins/cases/server/client/metrics/test_utils/lifespan.ts +++ b/x-pack/plugins/cases/server/client/metrics/test_utils/lifespan.ts @@ -6,8 +6,7 @@ */ import type { SavedObject } from '@kbn/core/server'; -import type { UserActionAttributes } from '../../../../common/types/domain'; -import type { CaseStatuses } from '../../../../common/api'; +import type { UserActionAttributes, CaseStatuses } from '../../../../common/types/domain'; export function createStatusChangeSavedObject( status: CaseStatuses, diff --git a/x-pack/plugins/cases/server/client/mocks.ts b/x-pack/plugins/cases/server/client/mocks.ts index 5b5049a2001bd0..f912ce26f581e5 100644 --- a/x-pack/plugins/cases/server/client/mocks.ts +++ b/x-pack/plugins/cases/server/client/mocks.ts @@ -15,7 +15,7 @@ import { actionsClientMock } from '@kbn/actions-plugin/server/actions_client.moc import { makeLensEmbeddableFactory } from '@kbn/lens-plugin/server/embeddable/make_lens_embeddable_factory'; import { serializerMock } from '@kbn/core-saved-objects-base-server-mocks'; -import type { CasesFindRequest } from '../../common/api'; +import type { CasesFindRequest } from '../../common/types/api'; import type { CasesClient, CasesClientInternal } from '.'; import type { AttachmentsSubClient } from './attachments/client'; import type { CasesSubClient } from './cases/client'; @@ -24,8 +24,7 @@ import type { CasesClientFactory } from './factory'; import type { MetricsSubClient } from './metrics/client'; import type { UserActionsSubClient } from './user_actions/client'; -import { CaseStatuses } from '../../common'; -import { CaseSeverity } from '../../common/api'; +import { CaseSeverity, CaseStatuses } from '../../common/types/domain'; import { SortFieldCase } from '../../public/containers/types'; import { createExternalReferenceAttachmentTypeRegistryMock, diff --git a/x-pack/plugins/cases/server/client/types.ts b/x-pack/plugins/cases/server/client/types.ts index 82439d4d5b70d8..23e35b592efa54 100644 --- a/x-pack/plugins/cases/server/client/types.ts +++ b/x-pack/plugins/cases/server/client/types.ts @@ -14,7 +14,7 @@ import type { IBasePath } from '@kbn/core-http-browser'; import type { ISavedObjectsSerializer } from '@kbn/core-saved-objects-server'; import type { KueryNode } from '@kbn/es-query'; import type { FileServiceStart } from '@kbn/files-plugin/server'; -import type { CasesFindRequest, User } from '../../common/api'; +import type { CasesFindRequest } from '../../common/types/api'; import type { Authorization } from '../authorization/authorization'; import type { CaseConfigureService, @@ -28,6 +28,7 @@ import type { PersistableStateAttachmentTypeRegistry } from '../attachment_frame import type { ExternalReferenceAttachmentTypeRegistry } from '../attachment_framework/external_reference_registry'; import type { LicensingService } from '../services/licensing'; import type { NotificationService } from '../services/notifications/types'; +import type { User } from '../common/types/user'; export interface CasesServices { alertsService: AlertService; diff --git a/x-pack/plugins/cases/server/client/user_actions/client.ts b/x-pack/plugins/cases/server/client/user_actions/client.ts index 0f3c26545ce9f0..e89180d5440e7b 100644 --- a/x-pack/plugins/cases/server/client/user_actions/client.ts +++ b/x-pack/plugins/cases/server/client/user_actions/client.ts @@ -9,9 +9,9 @@ import type { CaseUserActionsDeprecatedResponse, CaseUserActionStatsResponse, GetCaseConnectorsResponse, + GetCaseUsersResponse, UserActionFindResponse, } from '../../../common/types/api'; -import type { GetCaseUsersResponse } from '../../../common/api'; import type { CasesClientArgs } from '../types'; import { get } from './get'; import { getConnectors } from './connectors'; diff --git a/x-pack/plugins/cases/server/client/user_actions/connectors.ts b/x-pack/plugins/cases/server/client/user_actions/connectors.ts index f1716bc4ca396d..d45d55dea2cab6 100644 --- a/x-pack/plugins/cases/server/client/user_actions/connectors.ts +++ b/x-pack/plugins/cases/server/client/user_actions/connectors.ts @@ -15,7 +15,6 @@ import type { GetCaseConnectorsResponse, } from '../../../common/types/api'; import { GetCaseConnectorsResponseRt } from '../../../common/types/api'; -import type { CaseExternalServiceBasic } from '../../../common/api'; import { decodeOrThrow } from '../../../common/api'; import { isConnectorUserAction, @@ -29,7 +28,11 @@ import { Operations } from '../../authorization'; import type { GetConnectorsRequest } from './types'; import type { CaseConnectorActivity } from '../../services/user_actions/types'; import type { CaseUserActionService } from '../../services'; -import type { CaseConnector, UserActionAttributes } from '../../../common/types/domain'; +import type { + CaseConnector, + ExternalService, + UserActionAttributes, +} from '../../../common/types/domain'; export const getConnectors = async ( { caseId }: GetConnectorsRequest, @@ -113,7 +116,7 @@ const checkConnectorsAuthorization = async ({ interface EnrichedPushInfo { latestPushDate: Date; oldestPushDate: Date; - externalService: CaseExternalServiceBasic; + externalService: ExternalService; connectorFieldsUsedInPush: CaseConnector; } @@ -158,7 +161,7 @@ const getActionConnectors = async ( interface PushDetails { connectorId: string; - externalService: CaseExternalServiceBasic; + externalService: ExternalService; mostRecentPush: Date; oldestPush: Date; } @@ -225,7 +228,7 @@ const getPushDetails = (activity: CaseConnectorActivity[]) => { const getExternalServiceFromSavedObject = ( savedObject: SavedObject | undefined -): CaseExternalServiceBasic | undefined => { +): ExternalService | undefined => { if (savedObject != null && isPushedUserAction(savedObject.attributes)) { return savedObject.attributes.payload.externalService; } diff --git a/x-pack/plugins/cases/server/client/user_actions/users.ts b/x-pack/plugins/cases/server/client/user_actions/users.ts index 52084d5d0c4122..6179e41c2c632b 100644 --- a/x-pack/plugins/cases/server/client/user_actions/users.ts +++ b/x-pack/plugins/cases/server/client/user_actions/users.ts @@ -7,8 +7,9 @@ import { isString } from 'lodash'; import type { UserProfileAvatarData, UserProfileWithAvatar } from '@kbn/user-profile-components'; -import type { GetCaseUsersResponse, User, UserWithProfileInfo } from '../../../common/api'; -import { decodeOrThrow, GetCaseUsersResponseRt } from '../../../common/api'; +import type { GetCaseUsersResponse } from '../../../common/types/api'; +import { GetCaseUsersResponseRt } from '../../../common/types/api'; +import { decodeOrThrow } from '../../../common/api'; import type { OwnerEntity } from '../../authorization'; import { Operations } from '../../authorization'; import { createCaseError } from '../../common/error'; @@ -16,6 +17,7 @@ import type { CasesClient } from '../client'; import type { CasesClientArgs } from '../types'; import type { GetUsersRequest } from './types'; import { getUserProfiles } from '../cases/utils'; +import type { User, UserWithProfileInfo } from '../../../common/types/domain'; export const getUsers = async ( { caseId }: GetUsersRequest, diff --git a/x-pack/plugins/cases/server/client/utils.test.ts b/x-pack/plugins/cases/server/client/utils.test.ts index 8017d5cfa18669..1b4ae12a3f429d 100644 --- a/x-pack/plugins/cases/server/client/utils.test.ts +++ b/x-pack/plugins/cases/server/client/utils.test.ts @@ -10,8 +10,6 @@ import { v1 as uuidv1 } from 'uuid'; import { DEFAULT_NAMESPACE_STRING } from '@kbn/core-saved-objects-utils-server'; import { toElasticsearchQuery } from '@kbn/es-query'; -import { CaseStatuses } from '../../common'; -import { CaseSeverity } from '../../common/api'; import { createSavedObjectsSerializerMock } from './mocks'; import { arraysDifference, @@ -22,6 +20,7 @@ import { convertSortField, } from './utils'; import { CasePersistedSeverity, CasePersistedStatus } from '../common/types/case'; +import { CaseSeverity, CaseStatuses } from '../../common/types/domain'; describe('utils', () => { describe('buildFilter', () => { diff --git a/x-pack/plugins/cases/server/client/utils.ts b/x-pack/plugins/cases/server/client/utils.ts index 884917a05f4319..4cd8cb84e45f80 100644 --- a/x-pack/plugins/cases/server/client/utils.ts +++ b/x-pack/plugins/cases/server/client/utils.ts @@ -17,27 +17,28 @@ import { nodeBuilder, fromKueryExpression, escapeKuery } from '@kbn/es-query'; import { spaceIdToNamespace } from '@kbn/spaces-plugin/server/lib/utils/namespace'; import type { - CaseStatuses, - CommentRequest, CaseSeverity, - CommentRequestExternalReferenceType, - CasesFindRequestSortFields, -} from '../../common/api'; + CaseStatuses, + ExternalReferenceAttachmentPayload, +} from '../../common/types/domain'; +import { + ActionsAttachmentPayloadRt, + AlertAttachmentPayloadRt, + ExternalReferenceNoSOAttachmentPayloadRt, + ExternalReferenceSOAttachmentPayloadRt, + ExternalReferenceStorageType, + PersistableStateAttachmentPayloadRt, + UserCommentAttachmentPayloadRt, +} from '../../common/types/domain'; import type { SavedObjectFindOptionsKueryNode } from '../common/types'; import type { CasesFindQueryParams } from './types'; +import { decodeWithExcessOrThrow } from '../../common/api'; import { + CASE_SAVED_OBJECT, + NO_ASSIGNEES_FILTERING_KEYWORD, OWNER_FIELD, - AlertCommentRequestRt, - ActionsCommentRequestRt, - ContextTypeUserRt, - ExternalReferenceStorageType, - ExternalReferenceSORt, - ExternalReferenceNoSORt, - PersistableStateAttachmentRt, - decodeWithExcessOrThrow, -} from '../../common/api'; -import { CASE_SAVED_OBJECT, NO_ASSIGNEES_FILTERING_KEYWORD } from '../../common/constants'; +} from '../../common/constants'; import { isCommentRequestTypeExternalReference, isCommentRequestTypePersistableState, @@ -52,18 +53,19 @@ import { assertUnreachable, } from '../common/utils'; import type { ExternalReferenceAttachmentTypeRegistry } from '../attachment_framework/external_reference_registry'; +import type { AttachmentRequest, CasesFindRequestSortFields } from '../../common/types/api'; // TODO: I think we can remove most of this function since we're using a different excess export const decodeCommentRequest = ( - comment: CommentRequest, + comment: AttachmentRequest, externalRefRegistry: ExternalReferenceAttachmentTypeRegistry ) => { if (isCommentRequestTypeUser(comment)) { - decodeWithExcessOrThrow(ContextTypeUserRt)(comment); + decodeWithExcessOrThrow(UserCommentAttachmentPayloadRt)(comment); } else if (isCommentRequestTypeActions(comment)) { - decodeWithExcessOrThrow(ActionsCommentRequestRt)(comment); + decodeWithExcessOrThrow(ActionsAttachmentPayloadRt)(comment); } else if (isCommentRequestTypeAlert(comment)) { - decodeWithExcessOrThrow(AlertCommentRequestRt)(comment); + decodeWithExcessOrThrow(AlertAttachmentPayloadRt)(comment); const { ids, indices } = getIDsAndIndicesAsArrays(comment); @@ -110,7 +112,7 @@ export const decodeCommentRequest = ( } else if (isCommentRequestTypeExternalReference(comment)) { decodeExternalReferenceAttachment(comment, externalRefRegistry); } else if (isCommentRequestTypePersistableState(comment)) { - decodeWithExcessOrThrow(PersistableStateAttachmentRt)(comment); + decodeWithExcessOrThrow(PersistableStateAttachmentPayloadRt)(comment); } else { /** * This assertion ensures that TS will show an error @@ -122,13 +124,13 @@ export const decodeCommentRequest = ( }; const decodeExternalReferenceAttachment = ( - attachment: CommentRequestExternalReferenceType, + attachment: ExternalReferenceAttachmentPayload, externalRefRegistry: ExternalReferenceAttachmentTypeRegistry ) => { if (attachment.externalReferenceStorage.type === ExternalReferenceStorageType.savedObject) { - decodeWithExcessOrThrow(ExternalReferenceSORt)(attachment); + decodeWithExcessOrThrow(ExternalReferenceSOAttachmentPayloadRt)(attachment); } else { - decodeWithExcessOrThrow(ExternalReferenceNoSORt)(attachment); + decodeWithExcessOrThrow(ExternalReferenceNoSOAttachmentPayloadRt)(attachment); } const metadata = attachment.externalReferenceMetadata; @@ -142,7 +144,7 @@ const decodeExternalReferenceAttachment = ( /** * Return the alert IDs from the comment if it is an alert style comment. Otherwise return an empty array. */ -export const getAlertIds = (comment: CommentRequest): string[] => { +export const getAlertIds = (comment: AttachmentRequest): string[] => { if (isCommentRequestTypeAlert(comment)) { return Array.isArray(comment.alertId) ? comment.alertId : [comment.alertId]; } diff --git a/x-pack/plugins/cases/server/common/constants.ts b/x-pack/plugins/cases/server/common/constants.ts index 69c1f3e619c970..e7f2ba1e3ff5be 100644 --- a/x-pack/plugins/cases/server/common/constants.ts +++ b/x-pack/plugins/cases/server/common/constants.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { CaseSeverity, CaseStatuses } from '../../common/api'; +import { CaseSeverity, CaseStatuses } from '../../common/types/domain'; import { CASE_COMMENT_SAVED_OBJECT, CASE_SAVED_OBJECT } from '../../common/constants'; import { CasePersistedSeverity, CasePersistedStatus } from './types/case'; diff --git a/x-pack/plugins/cases/server/common/limiter_checker/base_limiter.ts b/x-pack/plugins/cases/server/common/limiter_checker/base_limiter.ts index f4e72554636aec..8fa860088d73ee 100644 --- a/x-pack/plugins/cases/server/common/limiter_checker/base_limiter.ts +++ b/x-pack/plugins/cases/server/common/limiter_checker/base_limiter.ts @@ -5,12 +5,13 @@ * 2.0. */ -import type { CommentRequest, CommentType } from '../../../common/api'; +import type { AttachmentType } from '../../../common/types/domain'; +import type { AttachmentRequest } from '../../../common/types/api'; import type { Limiter } from './types'; interface LimiterParams { limit: number; - attachmentType: CommentType | CommentType[]; + attachmentType: AttachmentType | AttachmentType[]; field?: string; attachmentNoun: string; } @@ -25,7 +26,7 @@ export abstract class BaseLimiter implements Limiter { } public abstract countOfItemsWithinCase(caseId: string): Promise; - public abstract countOfItemsInRequest(requests: CommentRequest[]): number; + public abstract countOfItemsInRequest(requests: AttachmentRequest[]): number; } const makeErrorMessage = (limit: number, noun: string) => { diff --git a/x-pack/plugins/cases/server/common/limiter_checker/index.ts b/x-pack/plugins/cases/server/common/limiter_checker/index.ts index 1ef34d70e7e257..65c556ff4d2b61 100644 --- a/x-pack/plugins/cases/server/common/limiter_checker/index.ts +++ b/x-pack/plugins/cases/server/common/limiter_checker/index.ts @@ -8,7 +8,7 @@ import Boom from '@hapi/boom'; import type { FileServiceStart } from '@kbn/files-plugin/server'; -import type { CommentRequest } from '../../../common/api'; +import type { AttachmentRequest } from '../../../common/types/api'; import type { AttachmentService } from '../../services'; import type { Limiter } from './types'; import { AlertLimiter } from './limiters/alerts'; @@ -30,7 +30,7 @@ export class AttachmentLimitChecker { ]; } - public async validate(requests: CommentRequest[]) { + public async validate(requests: AttachmentRequest[]) { for (const limiter of this.limiters) { const itemsWithinRequests = limiter.countOfItemsInRequest(requests); const hasItemsInRequests = itemsWithinRequests > 0; diff --git a/x-pack/plugins/cases/server/common/limiter_checker/limiters/alerts.ts b/x-pack/plugins/cases/server/common/limiter_checker/limiters/alerts.ts index b79ae195187715..49adb974c5530f 100644 --- a/x-pack/plugins/cases/server/common/limiter_checker/limiters/alerts.ts +++ b/x-pack/plugins/cases/server/common/limiter_checker/limiters/alerts.ts @@ -5,9 +5,10 @@ * 2.0. */ +import type { AttachmentRequest } from '../../../../common/types/api'; import type { AttachmentService } from '../../../services'; -import { CommentType } from '../../../../common/api'; -import type { CommentRequest, CommentRequestAlertType } from '../../../../common/api'; +import type { AlertAttachmentPayload } from '../../../../common/types/domain'; +import { AttachmentType } from '../../../../common/types/domain'; import { CASE_COMMENT_SAVED_OBJECT, MAX_ALERTS_PER_CASE } from '../../../../common/constants'; import { isCommentRequestTypeAlert } from '../../utils'; import { BaseLimiter } from '../base_limiter'; @@ -16,7 +17,7 @@ export class AlertLimiter extends BaseLimiter { constructor(private readonly attachmentService: AttachmentService) { super({ limit: MAX_ALERTS_PER_CASE, - attachmentType: CommentType.alert, + attachmentType: AttachmentType.alert, attachmentNoun: 'alerts', field: 'alertId', }); @@ -36,15 +37,15 @@ export class AlertLimiter extends BaseLimiter { }>({ caseId, aggregations: limitAggregation, - attachmentType: CommentType.alert, + attachmentType: AttachmentType.alert, }); return itemsAttachedToCase?.limiter?.value ?? 0; } - public countOfItemsInRequest(requests: CommentRequest[]): number { + public countOfItemsInRequest(requests: AttachmentRequest[]): number { const totalAlertsInReq = requests - .filter(isCommentRequestTypeAlert) + .filter(isCommentRequestTypeAlert) .reduce((count, attachment) => { const ids = Array.isArray(attachment.alertId) ? attachment.alertId : [attachment.alertId]; return count + ids.length; diff --git a/x-pack/plugins/cases/server/common/limiter_checker/limiters/files.ts b/x-pack/plugins/cases/server/common/limiter_checker/limiters/files.ts index 77f2a9a0fe6112..37fc78af178633 100644 --- a/x-pack/plugins/cases/server/common/limiter_checker/limiters/files.ts +++ b/x-pack/plugins/cases/server/common/limiter_checker/limiters/files.ts @@ -6,8 +6,8 @@ */ import type { FileServiceStart } from '@kbn/files-plugin/server'; -import { CommentType } from '../../../../common/api'; -import type { CommentRequest } from '../../../../common/api'; +import { AttachmentType } from '../../../../common/types/domain'; +import type { AttachmentRequest } from '../../../../common/types/api'; import { MAX_FILES_PER_CASE } from '../../../../common/constants'; import { isFileAttachmentRequest } from '../../utils'; import { BaseLimiter } from '../base_limiter'; @@ -16,7 +16,7 @@ export class FileLimiter extends BaseLimiter { constructor(private readonly fileService: FileServiceStart) { super({ limit: MAX_FILES_PER_CASE, - attachmentType: CommentType.externalReference, + attachmentType: AttachmentType.externalReference, field: 'externalReferenceAttachmentTypeId', attachmentNoun: 'files', }); @@ -33,7 +33,7 @@ export class FileLimiter extends BaseLimiter { return files.total; } - public countOfItemsInRequest(requests: CommentRequest[]): number { + public countOfItemsInRequest(requests: AttachmentRequest[]): number { let fileRequests = 0; for (const request of requests) { diff --git a/x-pack/plugins/cases/server/common/limiter_checker/limiters/persistable_state_and_external_references.ts b/x-pack/plugins/cases/server/common/limiter_checker/limiters/persistable_state_and_external_references.ts index b16baa919cffdb..3c9fdca6bf5b00 100644 --- a/x-pack/plugins/cases/server/common/limiter_checker/limiters/persistable_state_and_external_references.ts +++ b/x-pack/plugins/cases/server/common/limiter_checker/limiters/persistable_state_and_external_references.ts @@ -5,9 +5,9 @@ * 2.0. */ +import type { AttachmentRequest } from '../../../../common/types/api'; +import { AttachmentType } from '../../../../common/types/domain'; import type { AttachmentService } from '../../../services'; -import { CommentType } from '../../../../common/api'; -import type { CommentRequest } from '../../../../common/api'; import { MAX_PERSISTABLE_STATE_AND_EXTERNAL_REFERENCES } from '../../../../common/constants'; import { isFileAttachmentRequest, isPersistableStateOrExternalReference } from '../../utils'; import { BaseLimiter } from '../base_limiter'; @@ -16,7 +16,7 @@ export class PersistableStateAndExternalReferencesLimiter extends BaseLimiter { constructor(private readonly attachmentService: AttachmentService) { super({ limit: MAX_PERSISTABLE_STATE_AND_EXTERNAL_REFERENCES, - attachmentType: [CommentType.persistableState, CommentType.externalReference], + attachmentType: [AttachmentType.persistableState, AttachmentType.externalReference], attachmentNoun: 'persistable state and external reference attachments', }); } @@ -27,7 +27,7 @@ export class PersistableStateAndExternalReferencesLimiter extends BaseLimiter { }); } - public countOfItemsInRequest(requests: CommentRequest[]): number { + public countOfItemsInRequest(requests: AttachmentRequest[]): number { const totalReferences = requests .filter(isPersistableStateOrExternalReference) .filter((request) => !isFileAttachmentRequest(request)); diff --git a/x-pack/plugins/cases/server/common/limiter_checker/test_utils.ts b/x-pack/plugins/cases/server/common/limiter_checker/test_utils.ts index fc9515c133069a..51995e25cec007 100644 --- a/x-pack/plugins/cases/server/common/limiter_checker/test_utils.ts +++ b/x-pack/plugins/cases/server/common/limiter_checker/test_utils.ts @@ -5,22 +5,22 @@ * 2.0. */ -import { FILE_ATTACHMENT_TYPE } from '../../../common/constants'; -import { CommentType, ExternalReferenceStorageType } from '../../../common/api'; +import { AttachmentType, ExternalReferenceStorageType } from '../../../common/types/domain'; import type { - CommentRequestUserType, - CommentRequestAlertType, + UserCommentAttachmentPayload, FileAttachmentMetadata, - CommentRequestPersistableStateType, - CommentRequestExternalReferenceType, -} from '../../../common/api'; + AlertAttachmentPayload, + PersistableStateAttachmentPayload, + ExternalReferenceAttachmentPayload, +} from '../../../common/types/domain'; +import { FILE_ATTACHMENT_TYPE } from '../../../common/constants'; import type { FileAttachmentRequest } from '../types'; -export const createUserRequests = (num: number): CommentRequestUserType[] => { +export const createUserRequests = (num: number): UserCommentAttachmentPayload[] => { const requests = [...Array(num).keys()].map((value) => { return { comment: `${value}`, - type: CommentType.user as const, + type: AttachmentType.user as const, owner: 'test', }; }); @@ -30,12 +30,12 @@ export const createUserRequests = (num: number): CommentRequestUserType[] => { export const createPersistableStateRequests = ( num: number -): CommentRequestPersistableStateType[] => { +): PersistableStateAttachmentPayload[] => { return [...Array(num).keys()].map(() => { return { persistableStateAttachmentTypeId: '.test', persistableStateAttachmentState: {}, - type: CommentType.persistableState as const, + type: AttachmentType.persistableState as const, owner: 'test', }; }); @@ -43,10 +43,10 @@ export const createPersistableStateRequests = ( export const createExternalReferenceRequests = ( num: number -): CommentRequestExternalReferenceType[] => { +): ExternalReferenceAttachmentPayload[] => { return [...Array(num).keys()].map((value) => { return { - type: CommentType.externalReference as const, + type: AttachmentType.externalReference as const, owner: 'test', externalReferenceAttachmentTypeId: '.test', externalReferenceId: 'so-id', @@ -77,7 +77,7 @@ export const createFileRequests = ({ const requests: FileAttachmentRequest[] = [...Array(numRequests).keys()].map((value) => { return { - type: CommentType.externalReference as const, + type: AttachmentType.externalReference as const, externalReferenceAttachmentTypeId: FILE_ATTACHMENT_TYPE, externalReferenceId: 'so-id', externalReferenceMetadata: { files }, @@ -95,10 +95,10 @@ export const createFileRequests = ({ export const createAlertRequests = ( numberOfRequests: number, alertIds: string | string[] -): CommentRequestAlertType[] => { +): AlertAttachmentPayload[] => { const requests = [...Array(numberOfRequests).keys()].map((value) => { return { - type: CommentType.alert as const, + type: AttachmentType.alert as const, alertId: alertIds, index: alertIds, rule: { diff --git a/x-pack/plugins/cases/server/common/limiter_checker/types.ts b/x-pack/plugins/cases/server/common/limiter_checker/types.ts index 87dcd33478ff72..ef0eecf9a3804d 100644 --- a/x-pack/plugins/cases/server/common/limiter_checker/types.ts +++ b/x-pack/plugins/cases/server/common/limiter_checker/types.ts @@ -5,11 +5,11 @@ * 2.0. */ -import type { CommentRequest } from '../../../common/api'; +import type { AttachmentRequest } from '../../../common/types/api'; export interface Limiter { readonly limit: number; readonly errorMessage: string; countOfItemsWithinCase(caseId: string): Promise; - countOfItemsInRequest: (requests: CommentRequest[]) => number; + countOfItemsInRequest: (requests: AttachmentRequest[]) => number; } diff --git a/x-pack/plugins/cases/server/common/models/case_with_comments.test.ts b/x-pack/plugins/cases/server/common/models/case_with_comments.test.ts index 779ed8767a9b33..3a194645c3fca1 100644 --- a/x-pack/plugins/cases/server/common/models/case_with_comments.test.ts +++ b/x-pack/plugins/cases/server/common/models/case_with_comments.test.ts @@ -5,7 +5,7 @@ * 2.0. */ -import type { AttributesTypeAlerts } from '../../../common/api'; +import type { AlertAttachmentAttributes } from '../../../common/types/domain'; import type { SavedObject } from '@kbn/core-saved-objects-api-server'; import { createCasesClientMockArgs } from '../../client/mocks'; import { alertComment, comment, mockCaseComments, mockCases, multipleAlert } from '../../mocks'; @@ -343,8 +343,8 @@ describe('CaseCommentModel', () => { const attachments = clientArgs.services.attachmentService.bulkCreate.mock.calls[0][0].attachments; - const singleAlertCall = attachments[1] as SavedObject; - const multipleAlertsCall = attachments[2] as SavedObject; + const singleAlertCall = attachments[1] as SavedObject; + const multipleAlertsCall = attachments[2] as SavedObject; expect(attachments.length).toBe(3); expect(attachments[0].attributes.type).toBe('user'); @@ -370,7 +370,7 @@ describe('CaseCommentModel', () => { }); const attachments = clientArgs.services.attachmentService.bulkCreate.mock.calls[0][0] - .attachments as Array>; + .attachments as Array>; expect(attachments.length).toBe(1); expect(attachments[0].attributes.type).toBe('alert'); @@ -389,7 +389,7 @@ describe('CaseCommentModel', () => { }); const attachments = clientArgs.services.attachmentService.bulkCreate.mock.calls[0][0] - .attachments as Array>; + .attachments as Array>; expect(attachments.length).toBe(1); expect(attachments[0].attributes.type).toBe('alert'); @@ -412,7 +412,7 @@ describe('CaseCommentModel', () => { }); const attachments = clientArgs.services.attachmentService.bulkCreate.mock.calls[0][0] - .attachments as Array>; + .attachments as Array>; expect(attachments.length).toBe(1); expect(attachments[0].attributes.type).toBe('alert'); @@ -480,8 +480,8 @@ describe('CaseCommentModel', () => { const attachments = clientArgs.services.attachmentService.bulkCreate.mock.calls[0][0].attachments; - const singleAlertCall = attachments[1] as SavedObject; - const multipleAlertsCall = attachments[2] as SavedObject; + const singleAlertCall = attachments[1] as SavedObject; + const multipleAlertsCall = attachments[2] as SavedObject; expect(attachments.length).toBe(3); expect(attachments[0].attributes.type).toBe('user'); @@ -524,9 +524,9 @@ describe('CaseCommentModel', () => { const attachments = clientArgs.services.attachmentService.bulkCreate.mock.calls[0][0].attachments; - const alertOne = attachments[1] as SavedObject; - const alertTwo = attachments[2] as SavedObject; - const alertThree = attachments[3] as SavedObject; + const alertOne = attachments[1] as SavedObject; + const alertTwo = attachments[2] as SavedObject; + const alertThree = attachments[3] as SavedObject; expect(attachments.length).toBe(4); expect(attachments[0].attributes.type).toBe('user'); @@ -569,7 +569,7 @@ describe('CaseCommentModel', () => { const attachments = clientArgs.services.attachmentService.bulkCreate.mock.calls[0][0].attachments; - const multipleAlertsCall = attachments[1] as SavedObject; + const multipleAlertsCall = attachments[1] as SavedObject; expect(attachments.length).toBe(2); expect(attachments[0].attributes.type).toBe('user'); diff --git a/x-pack/plugins/cases/server/common/models/case_with_comments.ts b/x-pack/plugins/cases/server/common/models/case_with_comments.ts index 2ded93562781cb..5e48c38e67d0d8 100644 --- a/x-pack/plugins/cases/server/common/models/case_with_comments.ts +++ b/x-pack/plugins/cases/server/common/models/case_with_comments.ts @@ -12,16 +12,20 @@ import type { SavedObjectsUpdateOptions, SavedObjectsUpdateResponse, } from '@kbn/core/server'; -import { UserActionActions, UserActionTypes } from '../../../common/types/domain'; import type { + AlertAttachmentPayload, + AttachmentAttributes, Case, - CommentAttributes, - CommentPatchRequest, - CommentRequest, - CommentRequestUserType, - CommentRequestAlertType, -} from '../../../common/api'; -import { CaseRt, CaseStatuses, CommentType } from '../../../common/api'; + UserCommentAttachmentPayload, +} from '../../../common/types/domain'; +import { + CaseRt, + CaseStatuses, + UserActionActions, + UserActionTypes, + AttachmentType, +} from '../../../common/types/domain'; + import { CASE_SAVED_OBJECT, MAX_DOCS_PER_PAGE } from '../../../common/constants'; import type { CasesClientArgs } from '../../client'; import type { RefreshSetting } from '../../services/types'; @@ -39,9 +43,10 @@ import { getIDsAndIndicesAsArrays, } from '../utils'; import { decodeOrThrow } from '../../../common/api/runtime_types'; +import type { AttachmentRequest, AttachmentPatchRequest } from '../../../common/types/api'; type CaseCommentModelParams = Omit; -type CommentRequestWithId = Array<{ id: string } & CommentRequest>; +type CommentRequestWithId = Array<{ id: string } & AttachmentRequest>; /** * This class represents a case that can have a comment attached to it. @@ -78,13 +83,13 @@ export class CaseCommentModel { updatedAt, owner, }: { - updateRequest: CommentPatchRequest; + updateRequest: AttachmentPatchRequest; updatedAt: string; owner: string; }): Promise { try { const { id, version, ...queryRestAttributes } = updateRequest; - const options: SavedObjectsUpdateOptions = { + const options: SavedObjectsUpdateOptions = { version, /** * This is to handle a scenario where an update occurs for an attachment framework style comment. @@ -96,10 +101,10 @@ export class CaseCommentModel { refresh: false, }; - if (queryRestAttributes.type === CommentType.user && queryRestAttributes?.comment) { + if (queryRestAttributes.type === AttachmentType.user && queryRestAttributes?.comment) { const currentComment = (await this.params.services.attachmentService.getter.get({ attachmentId: id, - })) as SavedObject; + })) as SavedObject; const updatedReferences = getOrUpdateLensReferences( this.params.lensEmbeddableFactory, @@ -181,8 +186,8 @@ export class CaseCommentModel { } private async createUpdateCommentUserAction( - comment: SavedObjectsUpdateResponse, - updateRequest: CommentPatchRequest, + comment: SavedObjectsUpdateResponse, + updateRequest: AttachmentPatchRequest, owner: string ) { const { id, version, ...queryRestAttributes } = updateRequest; @@ -207,7 +212,7 @@ export class CaseCommentModel { id, }: { createdDate: string; - commentReq: CommentRequest; + commentReq: AttachmentRequest; id: string; }): Promise { try { @@ -311,13 +316,13 @@ export class CaseCommentModel { return dedupedAlertAttachments; } - private getAlertAttachments(attachments: CommentRequest[]): CommentRequestAlertType[] { + private getAlertAttachments(attachments: AttachmentRequest[]): AlertAttachmentPayload[] { return attachments.filter( - (attachment): attachment is CommentRequestAlertType => attachment.type === CommentType.alert + (attachment): attachment is AlertAttachmentPayload => attachment.type === AttachmentType.alert ); } - private async validateCreateCommentRequest(req: CommentRequest[]) { + private async validateCreateCommentRequest(req: AttachmentRequest[]) { const alertAttachments = this.getAlertAttachments(req); const hasAlertsInRequest = alertAttachments.length > 0; @@ -348,10 +353,10 @@ export class CaseCommentModel { ]; } - private getCommentReferences(commentReq: CommentRequest) { + private getCommentReferences(commentReq: AttachmentRequest) { let references: SavedObjectReference[] = []; - if (commentReq.type === CommentType.user && commentReq?.comment) { + if (commentReq.type === AttachmentType.user && commentReq?.comment) { const commentStringReferences = getOrUpdateLensReferences( this.params.lensEmbeddableFactory, commentReq.comment @@ -362,7 +367,7 @@ export class CaseCommentModel { return references; } - private async handleAlertComments(attachments: CommentRequest[]) { + private async handleAlertComments(attachments: AttachmentRequest[]) { const alertAttachments = this.getAlertAttachments(attachments); const alerts = getAlertInfoFromComments(alertAttachments); @@ -394,8 +399,8 @@ export class CaseCommentModel { } private async createCommentUserAction( - comment: SavedObject, - req: CommentRequest + comment: SavedObject, + req: AttachmentRequest ) { await this.params.services.userActionService.creator.createUserAction({ type: UserActionTypes.comment, @@ -410,7 +415,9 @@ export class CaseCommentModel { }); } - private async bulkCreateCommentUserAction(attachments: Array<{ id: string } & CommentRequest>) { + private async bulkCreateCommentUserAction( + attachments: Array<{ id: string } & AttachmentRequest> + ) { await this.params.services.userActionService.creator.bulkCreateAttachmentCreation({ caseId: this.caseInfo.id, attachments: attachments.map(({ id, ...attachment }) => ({ diff --git a/x-pack/plugins/cases/server/common/types.ts b/x-pack/plugins/cases/server/common/types.ts index c949a8fdfce97b..c79cb96d0d0b66 100644 --- a/x-pack/plugins/cases/server/common/types.ts +++ b/x-pack/plugins/cases/server/common/types.ts @@ -10,10 +10,10 @@ import type { SavedObject } from '@kbn/core-saved-objects-server'; import type { SavedObjectError } from '@kbn/core/types'; import type { KueryNode } from '@kbn/es-query'; import type { - CommentAttributes, - CommentRequestExternalReferenceSOType, + AttachmentAttributes, + ExternalReferenceSOAttachmentPayload, FileAttachmentMetadata, -} from '../../common/api'; +} from '../../common/types/domain'; /** * This structure holds the alert ID and index from an alert comment @@ -43,12 +43,12 @@ export type SavedObjectFindOptionsKueryNode = FindOptions & { }; export type FileAttachmentRequest = Omit< - CommentRequestExternalReferenceSOType, + ExternalReferenceSOAttachmentPayload, 'externalReferenceMetadata' > & { externalReferenceMetadata: FileAttachmentMetadata; }; -export type AttachmentSavedObject = SavedObject; +export type AttachmentSavedObject = SavedObject; export type SOWithErrors = Omit, 'attributes'> & { error: SavedObjectError }; diff --git a/x-pack/plugins/cases/server/common/types/attachments.ts b/x-pack/plugins/cases/server/common/types/attachments.ts index 440b144bb0fc2e..5a73c009c67fdd 100644 --- a/x-pack/plugins/cases/server/common/types/attachments.ts +++ b/x-pack/plugins/cases/server/common/types/attachments.ts @@ -7,8 +7,8 @@ import type { SavedObject } from '@kbn/core/server'; import type { JsonValue } from '@kbn/utility-types'; -import type { CommentAttributes } from '../../../common/api'; -import { CommentAttributesRt, CommentPatchAttributesRt } from '../../../common/api'; +import type { AttachmentAttributes } from '../../../common/types/domain'; +import { AttachmentAttributesRt, AttachmentPatchAttributesRt } from '../../../common/types/domain'; import type { User } from './user'; interface AttachmentCommonPersistedAttributes { @@ -50,8 +50,8 @@ export interface AttachmentRequestAttributes { export type AttachmentPersistedAttributes = AttachmentRequestAttributes & AttachmentCommonPersistedAttributes; -export type AttachmentTransformedAttributes = CommentAttributes; +export type AttachmentTransformedAttributes = AttachmentAttributes; export type AttachmentSavedObjectTransformed = SavedObject; -export const AttachmentTransformedAttributesRt = CommentAttributesRt; -export const AttachmentPartialAttributesRt = CommentPatchAttributesRt; +export const AttachmentTransformedAttributesRt = AttachmentAttributesRt; +export const AttachmentPartialAttributesRt = AttachmentPatchAttributesRt; diff --git a/x-pack/plugins/cases/server/common/types/case.test.ts b/x-pack/plugins/cases/server/common/types/case.test.ts index e5135d7bd1cd6a..3a36b7cdcac305 100644 --- a/x-pack/plugins/cases/server/common/types/case.test.ts +++ b/x-pack/plugins/cases/server/common/types/case.test.ts @@ -6,14 +6,14 @@ */ import { omit } from 'lodash'; -import { CaseStatuses } from '@kbn/cases-components'; -import { ConnectorTypes, CaseSeverity, SECURITY_SOLUTION_OWNER } from '../../../common'; +import { ConnectorTypes, SECURITY_SOLUTION_OWNER } from '../../../common'; import { CaseTransformedAttributesRt, getPartialCaseTransformedAttributesRt, OwnerRt, } from './case'; import { decodeOrThrow } from '../../../common/api'; +import { CaseSeverity, CaseStatuses } from '../../../common/types/domain'; describe('case types', () => { describe('getPartialCaseTransformedAttributesRt', () => { diff --git a/x-pack/plugins/cases/server/common/types/case.ts b/x-pack/plugins/cases/server/common/types/case.ts index f0aecd895323de..e22acd381fbe66 100644 --- a/x-pack/plugins/cases/server/common/types/case.ts +++ b/x-pack/plugins/cases/server/common/types/case.ts @@ -8,8 +8,8 @@ import type { SavedObject } from '@kbn/core-saved-objects-server'; import type { Type } from 'io-ts'; import { exact, partial, strict, string } from 'io-ts'; -import type { CaseAttributes } from '../../../common/api'; -import { CaseAttributesRt } from '../../../common/api'; +import type { CaseAttributes } from '../../../common/types/domain'; +import { CaseAttributesRt } from '../../../common/types/domain'; import type { ConnectorPersisted } from './connectors'; import type { ExternalServicePersisted } from './external_service'; import type { User, UserProfile } from './user'; diff --git a/x-pack/plugins/cases/server/common/utils.test.ts b/x-pack/plugins/cases/server/common/utils.test.ts index ce470b66080ca8..71848e170af03a 100644 --- a/x-pack/plugins/cases/server/common/utils.test.ts +++ b/x-pack/plugins/cases/server/common/utils.test.ts @@ -8,13 +8,6 @@ import type { SavedObject, SavedObjectsFindResponse } from '@kbn/core/server'; import { makeLensEmbeddableFactory } from '@kbn/lens-plugin/server/embeddable/make_lens_embeddable_factory'; import { OWNER_INFO, SECURITY_SOLUTION_OWNER } from '../../common/constants'; -import type { - Case, - CommentAttributes, - CommentRequest, - CommentRequestUserType, -} from '../../common/api'; -import { CaseSeverity, CommentType } from '../../common/api'; import { flattenCaseSavedObject, transformNewComment, @@ -39,8 +32,14 @@ import { newCase } from '../routes/api/__mocks__/request_responses'; import { CASE_VIEW_PAGE_TABS } from '../../common/types'; import { mockCases, mockCaseComments } from '../mocks'; import { createAlertAttachment, createUserAttachment } from '../services/attachments/test_utils'; -import type { CaseConnector } from '../../common/types/domain'; -import { ConnectorTypes } from '../../common/types/domain'; +import type { + AttachmentAttributes, + Case, + CaseConnector, + UserCommentAttachmentPayload, +} from '../../common/types/domain'; +import { ConnectorTypes, CaseSeverity, AttachmentType } from '../../common/types/domain'; +import type { AttachmentRequest } from '../../common/types/api'; import { createAlertRequests, createExternalReferenceRequests, @@ -50,13 +49,13 @@ import { interface CommentReference { ids: string[]; - comments: CommentRequest[]; + comments: AttachmentRequest[]; } function createCommentFindResponse( commentRequests: CommentReference[] -): SavedObjectsFindResponse { - const resp: SavedObjectsFindResponse = { +): SavedObjectsFindResponse { + const resp: SavedObjectsFindResponse = { page: 0, per_page: 0, total: 0, @@ -790,7 +789,7 @@ describe('common utils', () => { it('transforms correctly', () => { const comment = { comment: 'A comment', - type: CommentType.user as const, + type: AttachmentType.user as const, createdDate: '2020-04-09T09:43:51.778Z', email: 'elastic@elastic.co', full_name: 'Elastic', @@ -822,7 +821,7 @@ describe('common utils', () => { it('transform correctly without optional fields', () => { const comment = { comment: 'A comment', - type: CommentType.user as const, + type: AttachmentType.user as const, createdDate: '2020-04-09T09:43:51.778Z', owner: SECURITY_SOLUTION_OWNER, }; @@ -852,7 +851,7 @@ describe('common utils', () => { it('transform correctly with optional fields as null', () => { const comment = { comment: 'A comment', - type: CommentType.user as const, + type: AttachmentType.user as const, createdDate: '2020-04-09T09:43:51.778Z', email: null, full_name: null, @@ -890,7 +889,9 @@ describe('common utils', () => { createCommentFindResponse([ { ids: ['1'], - comments: [{ comment: '', type: CommentType.user, owner: SECURITY_SOLUTION_OWNER }], + comments: [ + { comment: '', type: AttachmentType.user, owner: SECURITY_SOLUTION_OWNER }, + ], }, ]).saved_objects[0] ) @@ -907,7 +908,7 @@ describe('common utils', () => { { alertId: ['a', 'b', 'c'], index: '', - type: CommentType.alert, + type: AttachmentType.alert, rule: { id: 'rule-id-1', name: 'rule-name-1', @@ -934,7 +935,7 @@ describe('common utils', () => { alertId: ['a', 'b'], index: '', owner: SECURITY_SOLUTION_OWNER, - type: CommentType.alert, + type: AttachmentType.alert, rule: { id: 'rule-id-1', name: 'rule-name-1', @@ -943,7 +944,7 @@ describe('common utils', () => { { comment: '', owner: SECURITY_SOLUTION_OWNER, - type: CommentType.user, + type: AttachmentType.user, }, ], }, @@ -963,7 +964,7 @@ describe('common utils', () => { owner: SECURITY_SOLUTION_OWNER, alertId: ['a', 'b'], index: '', - type: CommentType.alert, + type: AttachmentType.alert, rule: { id: 'rule-id-1', name: 'rule-name-1', @@ -977,7 +978,7 @@ describe('common utils', () => { { owner: SECURITY_SOLUTION_OWNER, comment: '', - type: CommentType.user, + type: AttachmentType.user, }, ], }, @@ -1002,7 +1003,7 @@ describe('common utils', () => { owner: SECURITY_SOLUTION_OWNER, alertId: ['a', 'b'], index: '', - type: CommentType.alert, + type: AttachmentType.alert, rule: { id: 'rule-id-1', name: 'rule-name-1', @@ -1034,7 +1035,7 @@ describe('common utils', () => { owner: SECURITY_SOLUTION_OWNER, alertId: ['a', 'b'], index: '', - type: CommentType.alert, + type: AttachmentType.alert, rule: { id: 'rule-id-1', name: 'rule-name-1', @@ -1173,7 +1174,7 @@ describe('common utils', () => { attributes: { comment: currentCommentString, }, - } as SavedObject + } as SavedObject ); const expectedReferences = [ diff --git a/x-pack/plugins/cases/server/common/utils.ts b/x-pack/plugins/cases/server/common/utils.ts index 64e25eb78ac7bd..94ad077e21bf2e 100644 --- a/x-pack/plugins/cases/server/common/utils.ts +++ b/x-pack/plugins/cases/server/common/utils.ts @@ -15,7 +15,23 @@ import type { import { flatMap, uniqWith, xorWith } from 'lodash'; import type { LensServerPluginSetup } from '@kbn/lens-plugin/server'; import { addSpaceIdToPath } from '@kbn/spaces-plugin/common'; -import { ConnectorTypes } from '../../common/types/domain'; +import type { + ActionsAttachmentPayload, + AlertAttachmentPayload, + Attachment, + AttachmentAttributes, + Case, + User, + UserCommentAttachmentPayload, +} from '../../common/types/domain'; +import { + AttachmentType, + ExternalReferenceSOAttachmentPayloadRt, + FileAttachmentMetadataRt, + CaseSeverity, + CaseStatuses, + ConnectorTypes, +} from '../../common/types/domain'; import { isValidOwner } from '../../common/utils/owner'; import { CASE_VIEW_COMMENT_PATH, @@ -27,26 +43,6 @@ import { import type { CASE_VIEW_PAGE_TABS } from '../../common/types'; import type { AlertInfo, FileAttachmentRequest, SOWithErrors } from './types'; -import type { - CasePostRequest, - Case, - CasesFindResponse, - CommentAttributes, - CommentRequest, - CommentRequestActionsType, - CommentRequestAlertType, - CommentRequestUserType, - Comment, - CommentsFindResponse, - User, -} from '../../common/api'; -import { - CaseSeverity, - CaseStatuses, - CommentType, - ExternalReferenceSORt, - FileAttachmentMetadataRt, -} from '../../common/api'; import type { UpdateAlertStatusRequest } from '../client/alerts/types'; import { parseCommentString, @@ -54,6 +50,12 @@ import { } from '../../common/utils/markdown_plugins/utils'; import { dedupAssignees } from '../client/cases/utils'; import type { CaseSavedObjectTransformed, CaseTransformedAttributes } from './types/case'; +import type { + AttachmentRequest, + AttachmentsFindResponse, + CasePostRequest, + CasesFindResponse, +} from '../../common/types/api'; /** * Default sort field for querying saved objects. @@ -120,7 +122,7 @@ export const flattenCaseSavedObject = ({ totalAlerts = 0, }: { savedObject: CaseSavedObjectTransformed; - comments?: Array>; + comments?: Array>; totalComment?: number; totalAlerts?: number; }): Case => ({ @@ -133,8 +135,8 @@ export const flattenCaseSavedObject = ({ }); export const transformComments = ( - comments: SavedObjectsFindResponse -): CommentsFindResponse => ({ + comments: SavedObjectsFindResponse +): AttachmentsFindResponse => ({ page: comments.page, per_page: comments.per_page, total: comments.total, @@ -142,23 +144,23 @@ export const transformComments = ( }); export const flattenCommentSavedObjects = ( - savedObjects: Array> -): Comment[] => - savedObjects.reduce((acc: Comment[], savedObject: SavedObject) => { + savedObjects: Array> +): Attachment[] => + savedObjects.reduce((acc: Attachment[], savedObject: SavedObject) => { acc.push(flattenCommentSavedObject(savedObject)); return acc; }, []); export const flattenCommentSavedObject = ( - savedObject: SavedObject -): Comment => ({ + savedObject: SavedObject +): Attachment => ({ id: savedObject.id, version: savedObject.version ?? '0', ...savedObject.attributes, }); export const getIDsAndIndicesAsArrays = ( - comment: CommentRequestAlertType + comment: AlertAttachmentPayload ): { ids: string[]; indices: string[] } => { return { ids: Array.isArray(comment.alertId) ? comment.alertId : [comment.alertId], @@ -174,7 +176,7 @@ export const getIDsAndIndicesAsArrays = ( * * To reformat the alert comment request requires a migration and a breaking API change. */ -const getAndValidateAlertInfoFromComment = (comment: CommentRequest): AlertInfo[] => { +const getAndValidateAlertInfoFromComment = (comment: AttachmentRequest): AlertInfo[] => { if (!isCommentRequestTypeAlert(comment)) { return []; } @@ -191,14 +193,14 @@ const getAndValidateAlertInfoFromComment = (comment: CommentRequest): AlertInfo[ /** * Builds an AlertInfo object accumulating the alert IDs and indices for the passed in alerts. */ -export const getAlertInfoFromComments = (comments: CommentRequest[] = []): AlertInfo[] => +export const getAlertInfoFromComments = (comments: AttachmentRequest[] = []): AlertInfo[] => comments.reduce((acc: AlertInfo[], comment) => { const alertInfo = getAndValidateAlertInfoFromComment(comment); acc.push(...alertInfo); return acc; }, []); -type NewCommentArgs = CommentRequest & { +type NewCommentArgs = AttachmentRequest & { createdDate: string; owner: string; email?: string | null; @@ -215,7 +217,7 @@ export const transformNewComment = ({ username, profile_uid: profileUid, ...comment -}: NewCommentArgs): CommentAttributes => { +}: NewCommentArgs): AttachmentAttributes => { return { ...comment, created_at: createdDate, @@ -231,36 +233,37 @@ export const transformNewComment = ({ * A type narrowing function for user comments. */ export const isCommentRequestTypeUser = ( - context: CommentRequest -): context is CommentRequestUserType => { - return context.type === CommentType.user; + context: AttachmentRequest +): context is UserCommentAttachmentPayload => { + return context.type === AttachmentType.user; }; /** * A type narrowing function for actions comments. */ export const isCommentRequestTypeActions = ( - context: CommentRequest -): context is CommentRequestActionsType => { - return context.type === CommentType.actions; + context: AttachmentRequest +): context is ActionsAttachmentPayload => { + return context.type === AttachmentType.actions; }; /** * A type narrowing function for alert comments. */ export const isCommentRequestTypeAlert = ( - context: CommentRequest -): context is CommentRequestAlertType => { - return context.type === CommentType.alert; + context: AttachmentRequest +): context is AlertAttachmentPayload => { + return context.type === AttachmentType.alert; }; /** * Returns true if a Comment Request is trying to create either a persistableState or an * externalReference attachment. */ -export const isPersistableStateOrExternalReference = (context: CommentRequest): boolean => { +export const isPersistableStateOrExternalReference = (context: AttachmentRequest): boolean => { return ( - context.type === CommentType.persistableState || context.type === CommentType.externalReference + context.type === AttachmentType.persistableState || + context.type === AttachmentType.externalReference ); }; @@ -268,10 +271,10 @@ export const isPersistableStateOrExternalReference = (context: CommentRequest): * A type narrowing function for file attachments. */ export const isFileAttachmentRequest = ( - context: Partial + context: Partial ): context is FileAttachmentRequest => { return ( - ExternalReferenceSORt.is(context) && + ExternalReferenceSOAttachmentPayloadRt.is(context) && FileAttachmentMetadataRt.is(context.externalReferenceMetadata) ); }; @@ -283,7 +286,7 @@ export function createAlertUpdateStatusRequest({ comment, status, }: { - comment: CommentRequest; + comment: AttachmentRequest; status: CaseStatuses; }): UpdateAlertStatusRequest[] { return getAlertInfoFromComments([comment]).map((alert) => ({ ...alert, status })); @@ -292,9 +295,9 @@ export function createAlertUpdateStatusRequest({ /** * Counts the total alert IDs within a single comment. */ -export const countAlerts = (comment: SavedObjectsFindResult) => { +export const countAlerts = (comment: SavedObjectsFindResult) => { let totalAlerts = 0; - if (comment.attributes.type === CommentType.alert) { + if (comment.attributes.type === AttachmentType.alert) { if (Array.isArray(comment.attributes.alertId)) { totalAlerts += comment.attributes.alertId.length; } else { @@ -310,7 +313,7 @@ export const countAlerts = (comment: SavedObjectsFindResult) export const groupTotalAlertsByID = ({ comments, }: { - comments: SavedObjectsFindResponse; + comments: SavedObjectsFindResponse; }): Map => { return comments.saved_objects.reduce((acc, alertsInfo) => { const alertTotalForComment = countAlerts(alertsInfo); @@ -337,7 +340,7 @@ export const countAlertsForID = ({ comments, id, }: { - comments: SavedObjectsFindResponse; + comments: SavedObjectsFindResponse; id: string; }): number | undefined => { return groupTotalAlertsByID({ comments }).get(id); @@ -382,7 +385,7 @@ export const extractLensReferencesFromCommentString = ( export const getOrUpdateLensReferences = ( lensEmbeddableFactory: LensServerPluginSetup['lensEmbeddableFactory'], newComment: string, - currentComment?: SavedObject + currentComment?: SavedObject ) => { if (!currentComment) { return extractLensReferencesFromCommentString(lensEmbeddableFactory, newComment); @@ -472,12 +475,12 @@ export const getCaseViewPath = (params: { export const isSOError = (so: { error?: unknown }): so is SOWithErrors => so.error != null; export const countUserAttachments = ( - attachments: Array> + attachments: Array> ): number => { let total = 0; for (const attachment of attachments) { - if (attachment.attributes.type === CommentType.user) { + if (attachment.attributes.type === AttachmentType.user) { total += 1; } } diff --git a/x-pack/plugins/cases/server/connectors/jira/format.test.ts b/x-pack/plugins/cases/server/connectors/jira/format.test.ts index acca9c7886ec21..d065a01244726f 100644 --- a/x-pack/plugins/cases/server/connectors/jira/format.test.ts +++ b/x-pack/plugins/cases/server/connectors/jira/format.test.ts @@ -5,7 +5,7 @@ * 2.0. */ -import type { Case } from '../../../common/api'; +import type { Case } from '../../../common/types/domain'; import { format } from './format'; describe('Jira formatter', () => { diff --git a/x-pack/plugins/cases/server/connectors/resilient/format.test.ts b/x-pack/plugins/cases/server/connectors/resilient/format.test.ts index 29ab88e09c388a..16810ed5768998 100644 --- a/x-pack/plugins/cases/server/connectors/resilient/format.test.ts +++ b/x-pack/plugins/cases/server/connectors/resilient/format.test.ts @@ -5,7 +5,7 @@ * 2.0. */ -import type { Case } from '../../../common/api'; +import type { Case } from '../../../common/types/domain'; import { format } from './format'; describe('IBM Resilient formatter', () => { diff --git a/x-pack/plugins/cases/server/connectors/servicenow/itsm_format.test.ts b/x-pack/plugins/cases/server/connectors/servicenow/itsm_format.test.ts index 0edec51ce4f486..3841d15f8aa900 100644 --- a/x-pack/plugins/cases/server/connectors/servicenow/itsm_format.test.ts +++ b/x-pack/plugins/cases/server/connectors/servicenow/itsm_format.test.ts @@ -5,7 +5,7 @@ * 2.0. */ -import type { Case } from '../../../common/api'; +import type { Case } from '../../../common/types/domain'; import { format } from './itsm_format'; describe('ITSM formatter', () => { diff --git a/x-pack/plugins/cases/server/connectors/servicenow/sir_format.test.ts b/x-pack/plugins/cases/server/connectors/servicenow/sir_format.test.ts index 23d14ec6b2d75c..fec26c9b032f2d 100644 --- a/x-pack/plugins/cases/server/connectors/servicenow/sir_format.test.ts +++ b/x-pack/plugins/cases/server/connectors/servicenow/sir_format.test.ts @@ -5,7 +5,7 @@ * 2.0. */ -import type { Case } from '../../../common/api'; +import type { Case } from '../../../common/types/domain'; import { format } from './sir_format'; describe('SIR formatter', () => { diff --git a/x-pack/plugins/cases/server/connectors/swimlane/format.test.ts b/x-pack/plugins/cases/server/connectors/swimlane/format.test.ts index 116b0eef1027c7..3dbb9967aca375 100644 --- a/x-pack/plugins/cases/server/connectors/swimlane/format.test.ts +++ b/x-pack/plugins/cases/server/connectors/swimlane/format.test.ts @@ -5,7 +5,7 @@ * 2.0. */ -import type { Case } from '../../../common/api'; +import type { Case } from '../../../common/types/domain'; import { format } from './format'; describe('Swimlane formatter', () => { diff --git a/x-pack/plugins/cases/server/connectors/types.ts b/x-pack/plugins/cases/server/connectors/types.ts index 28fb18787d9d34..8fd601bed941aa 100644 --- a/x-pack/plugins/cases/server/connectors/types.ts +++ b/x-pack/plugins/cases/server/connectors/types.ts @@ -6,8 +6,7 @@ */ import type { Logger } from '@kbn/core/server'; -import type { ConnectorMappings } from '../../common/types/domain'; -import type { Case } from '../../common/api'; +import type { Case, ConnectorMappings } from '../../common/types/domain'; import type { CasesClientGetAlertsResponse } from '../client/alerts/types'; import type { CasesClientFactory } from '../client/factory'; import type { RegisterActionType } from '../types'; diff --git a/x-pack/plugins/cases/server/internal_attachments/index.ts b/x-pack/plugins/cases/server/internal_attachments/index.ts index d52f8248be10f4..4e68775dd0aaf8 100644 --- a/x-pack/plugins/cases/server/internal_attachments/index.ts +++ b/x-pack/plugins/cases/server/internal_attachments/index.ts @@ -6,10 +6,11 @@ */ import { badRequest } from '@hapi/boom'; +import { FileAttachmentMetadataRt } from '../../common/types/domain'; import { LENS_ATTACHMENT_TYPE } from '../../common/constants/visualizations'; import { FILE_ATTACHMENT_TYPE } from '../../common/constants'; -import { FileAttachmentMetadataRt, decodeWithExcessOrThrow } from '../../common/api'; +import { decodeWithExcessOrThrow } from '../../common/api'; import type { ExternalReferenceAttachmentTypeRegistry } from '../attachment_framework/external_reference_registry'; import type { PersistableStateAttachmentTypeRegistry } from '../attachment_framework/persistable_state_registry'; diff --git a/x-pack/plugins/cases/server/mocks.ts b/x-pack/plugins/cases/server/mocks.ts index 04fd000c4df33e..4a3e3db88c6f54 100644 --- a/x-pack/plugins/cases/server/mocks.ts +++ b/x-pack/plugins/cases/server/mocks.ts @@ -6,20 +6,28 @@ */ import type { SavedObject } from '@kbn/core/server'; -import type { - CasePostRequest, - CommentAttributes, - CommentRequestActionsType, - CommentRequestAlertType, - CommentRequestUserType, -} from '../common/api'; -import { CaseSeverity, CaseStatuses, CommentType } from '../common/api'; + import { SECURITY_SOLUTION_OWNER } from '../common/constants'; import type { CasesStart } from './types'; import { createCasesClientMock } from './client/mocks'; import type { CaseSavedObjectTransformed } from './common/types/case'; -import type { ConnectorMappings, UserActionAttributes } from '../common/types/domain'; -import { UserActionActions, UserActionTypes, ConnectorTypes } from '../common/types/domain'; +import type { + ActionsAttachmentPayload, + AlertAttachmentPayload, + AttachmentAttributes, + ConnectorMappings, + UserActionAttributes, + UserCommentAttachmentPayload, +} from '../common/types/domain'; +import { + UserActionActions, + UserActionTypes, + CaseSeverity, + CaseStatuses, + ConnectorTypes, + AttachmentType, +} from '../common/types/domain'; +import type { CasePostRequest } from '../common/types/api'; const lensPersistableState = { attributes: { @@ -300,13 +308,13 @@ export const mockCasesErrorTriggerData = [ }, ]; -export const mockCaseComments: Array> = [ +export const mockCaseComments: Array> = [ { type: 'cases-comment', id: 'mock-comment-1', attributes: { comment: 'Wow, good luck catching that bad meanie!', - type: CommentType.user, + type: AttachmentType.user, created_at: '2019-11-25T21:55:00.177Z', created_by: { full_name: 'elastic', @@ -338,7 +346,7 @@ export const mockCaseComments: Array> = [ id: 'mock-comment-2', attributes: { comment: 'Well I decided to update my comment. So what? Deal with it.', - type: CommentType.user, + type: AttachmentType.user, created_at: '2019-11-25T21:55:14.633Z', created_by: { full_name: 'elastic', @@ -371,7 +379,7 @@ export const mockCaseComments: Array> = [ id: 'mock-comment-3', attributes: { comment: 'Wow, good luck catching that bad meanie!', - type: CommentType.user, + type: AttachmentType.user, created_at: '2019-11-25T22:32:30.608Z', created_by: { full_name: 'elastic', @@ -402,7 +410,7 @@ export const mockCaseComments: Array> = [ type: 'cases-comment', id: 'mock-comment-4', attributes: { - type: CommentType.alert, + type: AttachmentType.alert, index: 'test-index', alertId: 'test-id', created_at: '2019-11-25T22:32:30.608Z', @@ -439,7 +447,7 @@ export const mockCaseComments: Array> = [ type: 'cases-comment', id: 'mock-comment-5', attributes: { - type: CommentType.alert, + type: AttachmentType.alert, index: 'test-index-2', alertId: 'test-id-2', created_at: '2019-11-25T22:32:30.608Z', @@ -476,7 +484,7 @@ export const mockCaseComments: Array> = [ type: 'cases-comment', id: 'mock-comment-6', attributes: { - type: CommentType.alert, + type: AttachmentType.alert, index: 'test-index-3', alertId: 'test-id-3', created_at: '2019-11-25T22:32:30.608Z', @@ -513,7 +521,7 @@ export const mockCaseComments: Array> = [ type: 'cases-comment', id: 'mock-comment-7', attributes: { - type: CommentType.persistableState, + type: AttachmentType.persistableState, persistableStateAttachmentTypeId: '.lens', persistableStateAttachmentState: lensPersistableState, owner: 'cases', @@ -576,7 +584,7 @@ export const mockUsersActions: Array> = [ action: UserActionActions.update, payload: { comment: { - type: CommentType.persistableState, + type: AttachmentType.persistableState, persistableStateAttachmentTypeId: '.test', persistableStateAttachmentState: {}, owner: 'cases', @@ -609,7 +617,7 @@ export const mockUsersActions: Array> = [ action: UserActionActions.update, payload: { comment: { - type: CommentType.persistableState, + type: AttachmentType.persistableState, persistableStateAttachmentTypeId: '.lens', persistableStateAttachmentState: lensPersistableState, owner: 'cases', @@ -652,14 +660,14 @@ export const newCase: CasePostRequest = { owner: SECURITY_SOLUTION_OWNER, }; -export const comment: CommentRequestUserType = { +export const comment: UserCommentAttachmentPayload = { comment: 'a comment', - type: CommentType.user as const, + type: AttachmentType.user as const, owner: SECURITY_SOLUTION_OWNER, }; -export const actionComment: CommentRequestActionsType = { - type: CommentType.actions, +export const actionComment: ActionsAttachmentPayload = { + type: AttachmentType.actions, comment: 'I just isolated the host!', actions: { targets: [ @@ -673,18 +681,18 @@ export const actionComment: CommentRequestActionsType = { owner: 'cases', }; -export const alertComment: CommentRequestAlertType = { +export const alertComment: AlertAttachmentPayload = { alertId: 'alert-id-1', index: 'alert-index-1', rule: { id: 'rule-id-1', name: 'rule-name-1', }, - type: CommentType.alert as const, + type: AttachmentType.alert as const, owner: SECURITY_SOLUTION_OWNER, }; -export const multipleAlert: CommentRequestAlertType = { +export const multipleAlert: AlertAttachmentPayload = { ...alertComment, alertId: ['test-id-3', 'test-id-4', 'test-id-5'], index: ['test-index-3', 'test-index-4', 'test-index-5'], diff --git a/x-pack/plugins/cases/server/routes/api/__mocks__/request_responses.ts b/x-pack/plugins/cases/server/routes/api/__mocks__/request_responses.ts index f709e9779f4390..652e93fc520cf8 100644 --- a/x-pack/plugins/cases/server/routes/api/__mocks__/request_responses.ts +++ b/x-pack/plugins/cases/server/routes/api/__mocks__/request_responses.ts @@ -5,9 +5,9 @@ * 2.0. */ -import type { CasePostRequest } from '../../../../common/api'; -import { ConnectorTypes } from '../../../../common/types/domain'; +import type { CasePostRequest } from '../../../../common/types/api'; import { SECURITY_SOLUTION_OWNER } from '../../../../common/constants'; +import { ConnectorTypes } from '../../../../common/types/domain'; export const newCase: CasePostRequest = { title: 'My new case', diff --git a/x-pack/plugins/cases/server/routes/api/cases/alerts/get_cases.ts b/x-pack/plugins/cases/server/routes/api/cases/alerts/get_cases.ts index 14dfa6ad35b4f4..841a225eac8f93 100644 --- a/x-pack/plugins/cases/server/routes/api/cases/alerts/get_cases.ts +++ b/x-pack/plugins/cases/server/routes/api/cases/alerts/get_cases.ts @@ -6,8 +6,7 @@ */ import { schema } from '@kbn/config-schema'; - -import type { CasesByAlertIDRequest } from '../../../../../common/api'; +import type { caseApiV1 } from '../../../../../common/types/api'; import { CASE_ALERTS_URL } from '../../../../../common/constants'; import { createCaseError } from '../../../../common/error'; import { createCasesRoute } from '../../create_cases_route'; @@ -26,10 +25,13 @@ export const getCasesByAlertIdRoute = createCasesRoute({ const caseContext = await context.cases; const casesClient = await caseContext.getCasesClient(); - const options = request.query as CasesByAlertIDRequest; + const options = request.query as caseApiV1.CasesByAlertIDRequest; + + const res: caseApiV1.GetRelatedCasesByAlertResponse = + await casesClient.cases.getCasesByAlertID({ alertID, options }); return response.ok({ - body: await casesClient.cases.getCasesByAlertID({ alertID, options }), + body: res, }); } catch (error) { throw createCaseError({ diff --git a/x-pack/plugins/cases/server/routes/api/cases/categories/get_categories.ts b/x-pack/plugins/cases/server/routes/api/cases/categories/get_categories.ts index a71e03f48ea555..fa3d2b6a3ade2b 100644 --- a/x-pack/plugins/cases/server/routes/api/cases/categories/get_categories.ts +++ b/x-pack/plugins/cases/server/routes/api/cases/categories/get_categories.ts @@ -5,11 +5,10 @@ * 2.0. */ -import type { AllCategoriesFindRequest } from '../../../../../common/api'; - import { INTERNAL_GET_CASE_CATEGORIES_URL } from '../../../../../common/constants'; import { createCaseError } from '../../../../common/error'; import { createCasesRoute } from '../../create_cases_route'; +import type { caseApiV1 } from '../../../../../common/types/api'; export const getCategoriesRoute = createCasesRoute({ method: 'get', @@ -18,9 +17,11 @@ export const getCategoriesRoute = createCasesRoute({ try { const caseContext = await context.cases; const client = await caseContext.getCasesClient(); - const options = request.query as AllCategoriesFindRequest; + const options = request.query as caseApiV1.AllCategoriesFindRequest; + + const res: caseApiV1.GetCategoriesResponse = await client.cases.getCategories(options); - return response.ok({ body: await client.cases.getCategories(options) }); + return response.ok({ body: res }); } catch (error) { throw createCaseError({ message: `Failed to retrieve categories in route: ${error}`, diff --git a/x-pack/plugins/cases/server/routes/api/cases/find_cases.ts b/x-pack/plugins/cases/server/routes/api/cases/find_cases.ts index 7d761e98a90dbd..bb14557c58ae5b 100644 --- a/x-pack/plugins/cases/server/routes/api/cases/find_cases.ts +++ b/x-pack/plugins/cases/server/routes/api/cases/find_cases.ts @@ -5,10 +5,10 @@ * 2.0. */ -import type { CasesFindRequest } from '../../../../common/api'; import { CASES_URL } from '../../../../common/constants'; import { createCaseError } from '../../../common/error'; import { createCasesRoute } from '../create_cases_route'; +import type { caseApiV1 } from '../../../../common/types/api'; export const findCaseRoute = createCasesRoute({ method: 'get', @@ -17,10 +17,12 @@ export const findCaseRoute = createCasesRoute({ try { const caseContext = await context.cases; const casesClient = await caseContext.getCasesClient(); - const options = request.query as CasesFindRequest; + const options = request.query as caseApiV1.CasesFindRequest; + + const res: caseApiV1.CasesFindResponse = await casesClient.cases.find({ ...options }); return response.ok({ - body: await casesClient.cases.find({ ...options }), + body: res, }); } catch (error) { throw createCaseError({ diff --git a/x-pack/plugins/cases/server/routes/api/cases/get_case.ts b/x-pack/plugins/cases/server/routes/api/cases/get_case.ts index 736b9b973ce7d9..434ff80fb0c089 100644 --- a/x-pack/plugins/cases/server/routes/api/cases/get_case.ts +++ b/x-pack/plugins/cases/server/routes/api/cases/get_case.ts @@ -7,6 +7,8 @@ import { schema } from '@kbn/config-schema'; +import type { caseApiV1 } from '../../../../common/types/api'; +import type { caseDomainV1 } from '../../../../common/types/domain'; import { getWarningHeader, logDeprecatedEndpoint } from '../utils'; import { CASE_DETAILS_URL } from '../../../../common/constants'; import { createCaseError } from '../../../common/error'; @@ -45,16 +47,18 @@ export const getCaseRoute = createCasesRoute({ const casesClient = await caseContext.getCasesClient(); const id = request.params.case_id; + const res: caseDomainV1.Case = await casesClient.cases.get({ + id, + includeComments: request.query.includeComments, + }); + return response.ok({ ...(isIncludeCommentsParamProvidedByTheUser && { headers: { ...getWarningHeader(kibanaVersion, 'Deprecated query parameter includeComments'), }, }), - body: await casesClient.cases.get({ - id, - includeComments: request.query.includeComments, - }), + body: res, }); } catch (error) { throw createCaseError({ @@ -75,11 +79,13 @@ export const resolveCaseRoute = createCasesRoute({ const casesClient = await caseContext.getCasesClient(); const id = request.params.case_id; + const res: caseApiV1.CaseResolveResponse = await casesClient.cases.resolve({ + id, + includeComments: request.query.includeComments, + }); + return response.ok({ - body: await casesClient.cases.resolve({ - id, - includeComments: request.query.includeComments, - }), + body: res, }); } catch (error) { throw createCaseError({ diff --git a/x-pack/plugins/cases/server/routes/api/cases/patch_cases.ts b/x-pack/plugins/cases/server/routes/api/cases/patch_cases.ts index 4bd0dcc12113cd..16f3c8e6baa600 100644 --- a/x-pack/plugins/cases/server/routes/api/cases/patch_cases.ts +++ b/x-pack/plugins/cases/server/routes/api/cases/patch_cases.ts @@ -5,10 +5,11 @@ * 2.0. */ -import type { CasesPatchRequest } from '../../../../common/api'; import { CASES_URL } from '../../../../common/constants'; import { createCaseError } from '../../../common/error'; import { createCasesRoute } from '../create_cases_route'; +import type { caseApiV1 } from '../../../../common/types/api'; +import type { caseDomainV1 } from '../../../../common/types/domain'; export const patchCaseRoute = createCasesRoute({ method: 'patch', @@ -17,10 +18,12 @@ export const patchCaseRoute = createCasesRoute({ try { const caseContext = await context.cases; const casesClient = await caseContext.getCasesClient(); - const cases = request.body as CasesPatchRequest; + const cases = request.body as caseApiV1.CasesPatchRequest; + + const res: caseDomainV1.Cases = await casesClient.cases.update(cases); return response.ok({ - body: await casesClient.cases.update(cases), + body: res, }); } catch (error) { throw createCaseError({ diff --git a/x-pack/plugins/cases/server/routes/api/cases/post_case.ts b/x-pack/plugins/cases/server/routes/api/cases/post_case.ts index 0ae9081c308513..423722fa959706 100644 --- a/x-pack/plugins/cases/server/routes/api/cases/post_case.ts +++ b/x-pack/plugins/cases/server/routes/api/cases/post_case.ts @@ -5,10 +5,11 @@ * 2.0. */ -import type { CasePostRequest } from '../../../../common/api'; import { CASES_URL } from '../../../../common/constants'; import { createCaseError } from '../../../common/error'; import { createCasesRoute } from '../create_cases_route'; +import type { caseApiV1 } from '../../../../common/types/api'; +import type { caseDomainV1 } from '../../../../common/types/domain'; export const postCaseRoute = createCasesRoute({ method: 'post', @@ -17,10 +18,12 @@ export const postCaseRoute = createCasesRoute({ try { const caseContext = await context.cases; const casesClient = await caseContext.getCasesClient(); - const theCase = request.body as CasePostRequest; + const theCase = request.body as caseApiV1.CasePostRequest; + + const res: caseDomainV1.Case = await casesClient.cases.create({ ...theCase }); return response.ok({ - body: await casesClient.cases.create({ ...theCase }), + body: res, }); } catch (error) { throw createCaseError({ diff --git a/x-pack/plugins/cases/server/routes/api/cases/push_case.ts b/x-pack/plugins/cases/server/routes/api/cases/push_case.ts index f4d96fd910b5e3..ec77bf97e5ab81 100644 --- a/x-pack/plugins/cases/server/routes/api/cases/push_case.ts +++ b/x-pack/plugins/cases/server/routes/api/cases/push_case.ts @@ -5,11 +5,13 @@ * 2.0. */ -import { decodeWithExcessOrThrow, CasePushRequestParamsRt } from '../../../../common/api'; +import { decodeWithExcessOrThrow } from '../../../../common/api'; import { CASE_PUSH_URL } from '../../../../common/constants'; import type { CaseRoute } from '../types'; import { createCaseError } from '../../../common/error'; import { createCasesRoute } from '../create_cases_route'; +import { caseApiV1 } from '../../../../common/types/api'; +import type { caseDomainV1 } from '../../../../common/types/domain'; export const pushCaseRoute: CaseRoute = createCasesRoute({ method: 'post', @@ -19,13 +21,14 @@ export const pushCaseRoute: CaseRoute = createCasesRoute({ const caseContext = await context.cases; const casesClient = await caseContext.getCasesClient(); - const params = decodeWithExcessOrThrow(CasePushRequestParamsRt)(request.params); + const params = decodeWithExcessOrThrow(caseApiV1.CasePushRequestParamsRt)(request.params); + const res: caseDomainV1.Case = await casesClient.cases.push({ + caseId: params.case_id, + connectorId: params.connector_id, + }); return response.ok({ - body: await casesClient.cases.push({ - caseId: params.case_id, - connectorId: params.connector_id, - }), + body: res, }); } catch (error) { throw createCaseError({ diff --git a/x-pack/plugins/cases/server/routes/api/cases/reporters/get_reporters.ts b/x-pack/plugins/cases/server/routes/api/cases/reporters/get_reporters.ts index 1dcdfea68b586f..97c850b89c737e 100644 --- a/x-pack/plugins/cases/server/routes/api/cases/reporters/get_reporters.ts +++ b/x-pack/plugins/cases/server/routes/api/cases/reporters/get_reporters.ts @@ -5,10 +5,10 @@ * 2.0. */ -import type { AllReportersFindRequest } from '../../../../../common/api'; import { CASE_REPORTERS_URL } from '../../../../../common/constants'; import { createCaseError } from '../../../../common/error'; import { createCasesRoute } from '../../create_cases_route'; +import type { caseApiV1 } from '../../../../../common/types/api'; export const getReportersRoute = createCasesRoute({ method: 'get', @@ -17,9 +17,11 @@ export const getReportersRoute = createCasesRoute({ try { const caseContext = await context.cases; const client = await caseContext.getCasesClient(); - const options = request.query as AllReportersFindRequest; + const options = request.query as caseApiV1.AllReportersFindRequest; - return response.ok({ body: await client.cases.getReporters({ ...options }) }); + const res: caseApiV1.GetReportersResponse = await client.cases.getReporters({ ...options }); + + return response.ok({ body: res }); } catch (error) { throw createCaseError({ message: `Failed to find cases in route: ${error}`, diff --git a/x-pack/plugins/cases/server/routes/api/cases/tags/get_tags.ts b/x-pack/plugins/cases/server/routes/api/cases/tags/get_tags.ts index 9a06cc29e72bd1..35c1b80229b5dd 100644 --- a/x-pack/plugins/cases/server/routes/api/cases/tags/get_tags.ts +++ b/x-pack/plugins/cases/server/routes/api/cases/tags/get_tags.ts @@ -5,10 +5,10 @@ * 2.0. */ -import type { AllTagsFindRequest } from '../../../../../common/api'; import { CASE_TAGS_URL } from '../../../../../common/constants'; import { createCaseError } from '../../../../common/error'; import { createCasesRoute } from '../../create_cases_route'; +import type { caseApiV1 } from '../../../../../common/types/api'; export const getTagsRoute = createCasesRoute({ method: 'get', @@ -17,9 +17,11 @@ export const getTagsRoute = createCasesRoute({ try { const caseContext = await context.cases; const client = await caseContext.getCasesClient(); - const options = request.query as AllTagsFindRequest; + const options = request.query as caseApiV1.AllTagsFindRequest; - return response.ok({ body: await client.cases.getTags({ ...options }) }); + const res: caseApiV1.GetTagsResponse = await client.cases.getTags({ ...options }); + + return response.ok({ body: res }); } catch (error) { throw createCaseError({ message: `Failed to retrieve tags in route: ${error}`, diff --git a/x-pack/plugins/cases/server/routes/api/comments/find_comments.ts b/x-pack/plugins/cases/server/routes/api/comments/find_comments.ts index 005d1b76f54fc6..7d0ba2af2a0613 100644 --- a/x-pack/plugins/cases/server/routes/api/comments/find_comments.ts +++ b/x-pack/plugins/cases/server/routes/api/comments/find_comments.ts @@ -7,7 +7,8 @@ import { schema } from '@kbn/config-schema'; -import { FindCommentsQueryParamsRt, decodeWithExcessOrThrow } from '../../../../common/api'; +import { FindAttachmentsQueryParamsRt } from '../../../../common/types/api'; +import { decodeWithExcessOrThrow } from '../../../../common/api'; import { CASE_FIND_ATTACHMENTS_URL } from '../../../../common/constants'; import { createCasesRoute } from '../create_cases_route'; import { createCaseError } from '../../../common/error'; @@ -22,7 +23,7 @@ export const findCommentsRoute = createCasesRoute({ }, handler: async ({ context, request, response }) => { try { - const query = decodeWithExcessOrThrow(FindCommentsQueryParamsRt)(request.query); + const query = decodeWithExcessOrThrow(FindAttachmentsQueryParamsRt)(request.query); const caseContext = await context.cases; const client = await caseContext.getCasesClient(); diff --git a/x-pack/plugins/cases/server/routes/api/comments/get_alerts.ts b/x-pack/plugins/cases/server/routes/api/comments/get_alerts.ts index a0b0da466e7ce6..7ee078e6d06029 100644 --- a/x-pack/plugins/cases/server/routes/api/comments/get_alerts.ts +++ b/x-pack/plugins/cases/server/routes/api/comments/get_alerts.ts @@ -6,6 +6,7 @@ */ import { schema } from '@kbn/config-schema'; +import type { alertApiV1 } from '../../../../common/types/api'; import { CASE_DETAILS_ALERTS_URL } from '../../../../common/constants'; import { createCaseError } from '../../../common/error'; @@ -26,8 +27,12 @@ export const getAllAlertsAttachedToCaseRoute = createCasesRoute({ const caseContext = await context.cases; const casesClient = await caseContext.getCasesClient(); + const res: alertApiV1.AlertResponse = await casesClient.attachments.getAllAlertsAttachToCase({ + caseId, + }); + return response.ok({ - body: await casesClient.attachments.getAllAlertsAttachToCase({ caseId }), + body: res, }); } catch (error) { throw createCaseError({ diff --git a/x-pack/plugins/cases/server/routes/api/comments/patch_comment.ts b/x-pack/plugins/cases/server/routes/api/comments/patch_comment.ts index 2e6cec35cc6675..8130808e51dcb1 100644 --- a/x-pack/plugins/cases/server/routes/api/comments/patch_comment.ts +++ b/x-pack/plugins/cases/server/routes/api/comments/patch_comment.ts @@ -6,8 +6,8 @@ */ import { schema } from '@kbn/config-schema'; - -import { CommentPatchRequestRt, decodeWithExcessOrThrow } from '../../../../common/api'; +import { AttachmentPatchRequestRt } from '../../../../common/types/api'; +import { decodeWithExcessOrThrow } from '../../../../common/api'; import { CASE_COMMENTS_URL } from '../../../../common/constants'; import { createCaseError } from '../../../common/error'; import { createCasesRoute } from '../create_cases_route'; @@ -22,7 +22,7 @@ export const patchCommentRoute = createCasesRoute({ }, handler: async ({ context, request, response }) => { try { - const query = decodeWithExcessOrThrow(CommentPatchRequestRt)(request.body); + const query = decodeWithExcessOrThrow(AttachmentPatchRequestRt)(request.body); const caseContext = await context.cases; const client = await caseContext.getCasesClient(); diff --git a/x-pack/plugins/cases/server/routes/api/comments/post_comment.ts b/x-pack/plugins/cases/server/routes/api/comments/post_comment.ts index daef9f3fa9f044..80ce9386252d71 100644 --- a/x-pack/plugins/cases/server/routes/api/comments/post_comment.ts +++ b/x-pack/plugins/cases/server/routes/api/comments/post_comment.ts @@ -7,7 +7,7 @@ import { schema } from '@kbn/config-schema'; import { CASE_COMMENTS_URL } from '../../../../common/constants'; -import type { CommentRequest } from '../../../../common/api'; +import type { AttachmentRequest } from '../../../../common/types/api'; import { createCaseError } from '../../../common/error'; import { createCasesRoute } from '../create_cases_route'; @@ -24,7 +24,7 @@ export const postCommentRoute = createCasesRoute({ const caseContext = await context.cases; const casesClient = await caseContext.getCasesClient(); const caseId = request.params.case_id; - const comment = request.body as CommentRequest; + const comment = request.body as AttachmentRequest; return response.ok({ body: await casesClient.attachments.add({ caseId, comment }), diff --git a/x-pack/plugins/cases/server/routes/api/internal/bulk_create_attachments.ts b/x-pack/plugins/cases/server/routes/api/internal/bulk_create_attachments.ts index a71d0fc10f6493..e0abb28a58efe1 100644 --- a/x-pack/plugins/cases/server/routes/api/internal/bulk_create_attachments.ts +++ b/x-pack/plugins/cases/server/routes/api/internal/bulk_create_attachments.ts @@ -6,8 +6,8 @@ */ import { schema } from '@kbn/config-schema'; +import type { BulkCreateAttachmentsRequest } from '../../../../common/types/api'; import { INTERNAL_BULK_CREATE_ATTACHMENTS_URL } from '../../../../common/constants'; -import type { BulkCreateCommentRequest } from '../../../../common/api'; import { createCaseError } from '../../../common/error'; import { createCasesRoute } from '../create_cases_route'; import { escapeHatch } from '../utils'; @@ -26,7 +26,7 @@ export const bulkCreateAttachmentsRoute = createCasesRoute({ const casesContext = await context.cases; const casesClient = await casesContext.getCasesClient(); const caseId = request.params.case_id; - const attachments = request.body as BulkCreateCommentRequest; + const attachments = request.body as BulkCreateAttachmentsRequest; return response.ok({ body: await casesClient.attachments.bulkCreate({ caseId, attachments }), diff --git a/x-pack/plugins/cases/server/routes/api/internal/bulk_delete_file_attachments.ts b/x-pack/plugins/cases/server/routes/api/internal/bulk_delete_file_attachments.ts index 09b84ee604afc0..c719d16e7ab16f 100644 --- a/x-pack/plugins/cases/server/routes/api/internal/bulk_delete_file_attachments.ts +++ b/x-pack/plugins/cases/server/routes/api/internal/bulk_delete_file_attachments.ts @@ -7,14 +7,12 @@ import { schema } from '@kbn/config-schema'; +import { BulkDeleteFileAttachmentsRequestRt } from '../../../../common/types/api'; import { INTERNAL_DELETE_FILE_ATTACHMENTS_URL } from '../../../../common/constants'; import { createCasesRoute } from '../create_cases_route'; import { createCaseError } from '../../../common/error'; import { escapeHatch } from '../utils'; -import { - BulkDeleteFileAttachmentsRequestRt, - decodeWithExcessOrThrow, -} from '../../../../common/api'; +import { decodeWithExcessOrThrow } from '../../../../common/api'; export const bulkDeleteFileAttachments = createCasesRoute({ method: 'post', diff --git a/x-pack/plugins/cases/server/routes/api/internal/bulk_get_attachments.ts b/x-pack/plugins/cases/server/routes/api/internal/bulk_get_attachments.ts index 3465d259607626..1e59df016e8c6d 100644 --- a/x-pack/plugins/cases/server/routes/api/internal/bulk_get_attachments.ts +++ b/x-pack/plugins/cases/server/routes/api/internal/bulk_get_attachments.ts @@ -6,7 +6,8 @@ */ import { schema } from '@kbn/config-schema'; -import { BulkGetAttachmentsRequestRt, decodeWithExcessOrThrow } from '../../../../common/api'; +import { BulkGetAttachmentsRequestRt } from '../../../../common/types/api'; +import { decodeWithExcessOrThrow } from '../../../../common/api'; import { INTERNAL_BULK_GET_ATTACHMENTS_URL } from '../../../../common/constants'; import { createCaseError } from '../../../common/error'; diff --git a/x-pack/plugins/cases/server/routes/api/internal/bulk_get_cases.ts b/x-pack/plugins/cases/server/routes/api/internal/bulk_get_cases.ts index fb7f38c6cab682..329cfc2483031a 100644 --- a/x-pack/plugins/cases/server/routes/api/internal/bulk_get_cases.ts +++ b/x-pack/plugins/cases/server/routes/api/internal/bulk_get_cases.ts @@ -5,8 +5,8 @@ * 2.0. */ +import type { caseApiV1 } from '../../../../common/types/api'; import { INTERNAL_BULK_GET_CASES_URL } from '../../../../common/constants'; -import type { CasesBulkGetRequest } from '../../../../common/api'; import { createCaseError } from '../../../common/error'; import { createCasesRoute } from '../create_cases_route'; import { escapeHatch } from '../utils'; @@ -18,14 +18,16 @@ export const bulkGetCasesRoute = createCasesRoute({ body: escapeHatch, }, handler: async ({ context, request, response }) => { - const params = request.body as CasesBulkGetRequest; + const params = request.body as caseApiV1.CasesBulkGetRequest; try { const casesContext = await context.cases; const casesClient = await casesContext.getCasesClient(); + const res: caseApiV1.CasesBulkGetResponse = await casesClient.cases.bulkGet({ ...params }); + return response.ok({ - body: await casesClient.cases.bulkGet({ ...params }), + body: res, }); } catch (error) { const ids = params.ids ?? []; diff --git a/x-pack/plugins/cases/server/routes/api/internal/get_case_users.ts b/x-pack/plugins/cases/server/routes/api/internal/get_case_users.ts index 56b031e548a54e..bbf69e43788869 100644 --- a/x-pack/plugins/cases/server/routes/api/internal/get_case_users.ts +++ b/x-pack/plugins/cases/server/routes/api/internal/get_case_users.ts @@ -9,6 +9,7 @@ import { schema } from '@kbn/config-schema'; import { INTERNAL_CASE_USERS_URL } from '../../../../common/constants'; import { createCaseError } from '../../../common/error'; import { createCasesRoute } from '../create_cases_route'; +import type { userApiV1 } from '../../../../common/types/api'; export const getCaseUsersRoute = createCasesRoute({ method: 'get', @@ -24,8 +25,12 @@ export const getCaseUsersRoute = createCasesRoute({ const casesClient = await casesContext.getCasesClient(); const caseId = request.params.case_id; + const res: userApiV1.GetCaseUsersResponse = await casesClient.userActions.getUsers({ + caseId, + }); + return response.ok({ - body: await casesClient.userActions.getUsers({ caseId }), + body: res, }); } catch (error) { throw createCaseError({ diff --git a/x-pack/plugins/cases/server/routes/api/internal/suggest_user_profiles.ts b/x-pack/plugins/cases/server/routes/api/internal/suggest_user_profiles.ts index 0dc656e6e11e64..747d59f1b6cf4a 100644 --- a/x-pack/plugins/cases/server/routes/api/internal/suggest_user_profiles.ts +++ b/x-pack/plugins/cases/server/routes/api/internal/suggest_user_profiles.ts @@ -5,11 +5,13 @@ * 2.0. */ +import type { KibanaRequest } from '@kbn/core-http-server'; import type { UserProfileService } from '../../../services'; import { INTERNAL_SUGGEST_USER_PROFILES_URL } from '../../../../common/constants'; import { createCaseError } from '../../../common/error'; import { createCasesRoute } from '../create_cases_route'; import { escapeHatch } from '../utils'; +import type { userApiV1 } from '../../../../common/types/api'; export const suggestUserProfilesRoute = (userProfileService: UserProfileService) => createCasesRoute({ @@ -23,8 +25,10 @@ export const suggestUserProfilesRoute = (userProfileService: UserProfileService) }, handler: async ({ request, response }) => { try { + const req = request as KibanaRequest<{}, {}, userApiV1.SuggestUserProfilesRequest>; + return response.ok({ - body: await userProfileService.suggest(request), + body: await userProfileService.suggest(req), }); } catch (error) { throw createCaseError({ diff --git a/x-pack/plugins/cases/server/routes/api/stats/get_status.ts b/x-pack/plugins/cases/server/routes/api/stats/get_status.ts index 3fa4952559be4e..2d28a1ab19fb4f 100644 --- a/x-pack/plugins/cases/server/routes/api/stats/get_status.ts +++ b/x-pack/plugins/cases/server/routes/api/stats/get_status.ts @@ -7,10 +7,10 @@ import type { CaseRoute } from '../types'; -import type { CasesStatusRequest } from '../../../../common/api'; import { CASE_STATUS_URL } from '../../../../common/constants'; import { createCaseError } from '../../../common/error'; import { createCasesRoute } from '../create_cases_route'; +import type { statsApiV1 } from '../../../../common/types/api'; /** * @deprecated since version 8.1.0 @@ -23,8 +23,13 @@ export const getStatusRoute: CaseRoute = createCasesRoute({ try { const caseContext = await context.cases; const client = await caseContext.getCasesClient(); + + const res: statsApiV1.CasesStatusResponse = await client.metrics.getStatusTotalsByType( + request.query as statsApiV1.CasesStatusRequest + ); + return response.ok({ - body: await client.metrics.getStatusTotalsByType(request.query as CasesStatusRequest), + body: res, }); } catch (error) { throw createCaseError({ diff --git a/x-pack/plugins/cases/server/saved_object_types/import_export/export.ts b/x-pack/plugins/cases/server/saved_object_types/import_export/export.ts index 801816d304fc58..d8ae1d4a8554a9 100644 --- a/x-pack/plugins/cases/server/saved_object_types/import_export/export.ts +++ b/x-pack/plugins/cases/server/saved_object_types/import_export/export.ts @@ -12,8 +12,10 @@ import type { SavedObjectsClientContract, SavedObjectsExportTransformContext, } from '@kbn/core/server'; -import type { CaseUserActionWithoutReferenceIds } from '../../../common/types/domain'; -import type { CommentAttributesWithoutRefs } from '../../../common/api'; +import type { + CaseUserActionWithoutReferenceIds, + AttachmentAttributesWithoutRefs, +} from '../../../common/types/domain'; import { CASE_COMMENT_SAVED_OBJECT, CASE_SAVED_OBJECT, @@ -38,7 +40,7 @@ export async function handleExport({ }): Promise< Array< SavedObject< - CasePersistedAttributes | CommentAttributesWithoutRefs | CaseUserActionWithoutReferenceIds + CasePersistedAttributes | AttachmentAttributesWithoutRefs | CaseUserActionWithoutReferenceIds > > > { @@ -71,9 +73,11 @@ export async function handleExport({ async function getAttachmentsAndUserActionsForCases( savedObjectsClient: SavedObjectsClientContract, caseIds: string[] -): Promise>> { +): Promise< + Array> +> { const [attachments, userActions] = await Promise.all([ - getAssociatedObjects({ + getAssociatedObjects({ savedObjectsClient, caseIds, sortField: defaultSortField, diff --git a/x-pack/plugins/cases/server/saved_object_types/migrations/cases.test.ts b/x-pack/plugins/cases/server/saved_object_types/migrations/cases.test.ts index 7fb3730a60bef8..2b8d74e4696ba6 100644 --- a/x-pack/plugins/cases/server/saved_object_types/migrations/cases.test.ts +++ b/x-pack/plugins/cases/server/saved_object_types/migrations/cases.test.ts @@ -5,10 +5,9 @@ * 2.0. */ -import { ConnectorTypes } from '../../../common/types/domain'; +import type { CaseAttributes, ExternalService } from '../../../common/types/domain'; +import { CaseSeverity, CaseStatuses, ConnectorTypes } from '../../../common/types/domain'; import type { SavedObjectSanitizedDoc, SavedObjectUnsanitizedDoc } from '@kbn/core/server'; -import type { CaseAttributes, CaseFullExternalService } from '../../../common/api'; -import { CaseSeverity, CaseStatuses } from '../../../common/api'; import { CASE_SAVED_OBJECT, NONE_CONNECTOR_ID } from '../../../common/constants'; import { CasePersistedSeverity, CasePersistedStatus } from '../../common/types/case'; import { getNoneCaseConnector } from '../../common/utils'; @@ -30,7 +29,7 @@ import { const create_7_14_0_case = ({ connector, externalService, -}: { connector?: ESCaseConnectorWithId; externalService?: CaseFullExternalService } = {}) => ({ +}: { connector?: ESCaseConnectorWithId; externalService?: ExternalService | null } = {}) => ({ type: CASE_SAVED_OBJECT, id: '1', attributes: { diff --git a/x-pack/plugins/cases/server/saved_object_types/migrations/cases.ts b/x-pack/plugins/cases/server/saved_object_types/migrations/cases.ts index cc8532f6a35bec..2edd075ee5e721 100644 --- a/x-pack/plugins/cases/server/saved_object_types/migrations/cases.ts +++ b/x-pack/plugins/cases/server/saved_object_types/migrations/cases.ts @@ -9,11 +9,9 @@ import { cloneDeep, unset, flow } from 'lodash'; import type { SavedObjectUnsanitizedDoc, SavedObjectSanitizedDoc } from '@kbn/core/server'; -import { ConnectorTypes } from '../../../common/types/domain'; +import { CaseSeverity, ConnectorTypes } from '../../../common/types/domain'; import type { SanitizedCaseOwner } from '.'; import { addOwnerToSO } from '.'; -import type { CaseAttributes } from '../../../common/api'; -import { CaseSeverity } from '../../../common/api'; import { CONNECTOR_ID_REFERENCE_NAME, @@ -29,6 +27,7 @@ import { CASE_TYPE_INDIVIDUAL } from './constants'; import { pipeMigrations } from './utils'; import type { ConnectorPersistedFields } from '../../common/types/connectors'; import { CasePersistedSeverity, CasePersistedStatus } from '../../common/types/case'; +import type { CaseAttributes } from '../../../common/types/domain'; interface UnsanitizedCaseConnector { connector_id: string; diff --git a/x-pack/plugins/cases/server/saved_object_types/migrations/comments.test.ts b/x-pack/plugins/cases/server/saved_object_types/migrations/comments.test.ts index dee9bdf95f44a9..dfa62e54c820d5 100644 --- a/x-pack/plugins/cases/server/saved_object_types/migrations/comments.test.ts +++ b/x-pack/plugins/cases/server/saved_object_types/migrations/comments.test.ts @@ -16,8 +16,8 @@ import { getLensVisualizations, parseCommentString, } from '../../../common/utils/markdown_plugins/utils'; -import type { AttributesTypePersistableState } from '../../../common/api'; -import { CommentType } from '../../../common/api'; +import type { PersistableStateAttachmentAttributes } from '../../../common/types/domain'; +import { AttachmentType } from '../../../common/types/domain'; import { savedObjectsServiceMock } from '@kbn/core/server/mocks'; import { makeLensEmbeddableFactory } from '@kbn/lens-plugin/server/embeddable/make_lens_embeddable_factory'; @@ -336,7 +336,7 @@ describe('comments migrations', () => { describe('persistable state lens migrations', () => { it('migrates correctly persistable state lens attachments', () => { const persistableAttachment = - mockCaseComments[6] as SavedObject; + mockCaseComments[6] as SavedObject; const persistableAttachmentState = persistableAttachment.attributes.persistableStateAttachmentState; @@ -372,7 +372,7 @@ describe('comments migrations', () => { it('logs and do not throw in case of a migration error', () => { const persistableAttachment = - mockCaseComments[6] as SavedObject; + mockCaseComments[6] as SavedObject; const migrateFunction = jest.fn().mockImplementation(() => { throw new Error('an error'); @@ -431,7 +431,7 @@ describe('comments migrations', () => { attributes: { comment, owner: 'cases', - type: CommentType.user, + type: AttachmentType.user, created_at: '2021-07-19T08:41:29.951Z', created_by: { email: null, @@ -582,7 +582,7 @@ describe('comments migrations', () => { id: '123', type: 'abc', attributes: { - type: CommentType.alert, + type: AttachmentType.alert, rule: { id: '123', name: 'hello', @@ -622,7 +622,7 @@ describe('comments migrations', () => { id: '123', type: 'abc', attributes: { - type: CommentType.alert, + type: AttachmentType.alert, rule: { id: '123', name: 'hello', diff --git a/x-pack/plugins/cases/server/saved_object_types/migrations/comments.ts b/x-pack/plugins/cases/server/saved_object_types/migrations/comments.ts index 3fc4afac6fd6b3..a1f72ac333107b 100644 --- a/x-pack/plugins/cases/server/saved_object_types/migrations/comments.ts +++ b/x-pack/plugins/cases/server/saved_object_types/migrations/comments.ts @@ -17,8 +17,11 @@ import type { import { mergeSavedObjectMigrationMaps } from '@kbn/core/server'; import type { LensServerPluginSetup } from '@kbn/lens-plugin/server'; import type { SavedObjectMigrationParams } from '@kbn/core-saved-objects-server'; -import type { AttributesTypePersistableState, AttributesTypeUser } from '../../../common/api'; -import { CommentType } from '../../../common/api'; +import type { + PersistableStateAttachmentAttributes, + UserCommentAttachmentAttributes, +} from '../../../common/types/domain'; +import { AttachmentType } from '../../../common/types/domain'; import type { LensMarkdownNode, MarkdownNode } from '../../../common/utils/markdown_plugins/utils'; import { isLensMarkdownNode, @@ -44,12 +47,12 @@ import type { AttachmentPersistedAttributes } from '../../common/types/attachmen interface UnsanitizedComment { comment: string; - type?: CommentType; + type?: AttachmentType; } interface SanitizedComment { comment: string; - type: CommentType; + type: AttachmentType; } enum AssociationType { @@ -82,7 +85,7 @@ export const createCommentsMigrations = ( ...doc, attributes: { ...doc.attributes, - type: CommentType.user, + type: AttachmentType.user, }, references: doc.references || [], }; @@ -95,9 +98,9 @@ export const createCommentsMigrations = ( associationType: AssociationType.case, }; - // only add the rule object for alert comments. Prior to 7.12 we only had CommentType.alert, generated alerts are + // only add the rule object for alert comments. Prior to 7.12 we only had AttachmentType.alert, generated alerts are // introduced in 7.12. - if (doc.attributes.type === CommentType.alert) { + if (doc.attributes.type === AttachmentType.alert) { attributes = { ...attributes, rule: { id: null, name: null } }; } @@ -159,7 +162,7 @@ const migrateLensComment = ({ context, }: { migrate: MigrateFunction; - doc: SavedObjectUnsanitizedDoc; + doc: SavedObjectUnsanitizedDoc; context: SavedObjectMigrationContext; }): SavedObjectSanitizedDoc => { try { @@ -196,7 +199,7 @@ const migratePersistableLensAttachment = ({ context, }: { migrate: MigrateFunction; - doc: SavedObjectUnsanitizedDoc; + doc: SavedObjectUnsanitizedDoc; context: SavedObjectMigrationContext; }): SavedObjectSanitizedDoc => { try { @@ -243,7 +246,7 @@ export const stringifyCommentWithoutTrailingNewline = ( export const removeRuleInformation = ( doc: SavedObjectUnsanitizedDoc> ): SavedObjectSanitizedDoc => { - if (doc.attributes.type === CommentType.alert || doc.attributes.type === GENERATED_ALERT) { + if (doc.attributes.type === AttachmentType.alert || doc.attributes.type === GENERATED_ALERT) { return { ...doc, attributes: { diff --git a/x-pack/plugins/cases/server/saved_object_types/migrations/user_actions/alerts.ts b/x-pack/plugins/cases/server/saved_object_types/migrations/user_actions/alerts.ts index 50e301a0945a8f..7edd9bf44909ab 100644 --- a/x-pack/plugins/cases/server/saved_object_types/migrations/user_actions/alerts.ts +++ b/x-pack/plugins/cases/server/saved_object_types/migrations/user_actions/alerts.ts @@ -10,8 +10,8 @@ import type { SavedObjectSanitizedDoc, SavedObjectUnsanitizedDoc, } from '@kbn/core/server'; -import type { CommentRequestAlertType } from '../../../../common/api'; -import { CommentType } from '../../../../common/api'; +import type { AlertAttachmentPayload } from '../../../../common/types/domain'; +import { AttachmentType } from '../../../../common/types/domain'; import { GENERATED_ALERT } from '../constants'; import { logError } from '../utils'; import type { UserActionVersion800 } from './types'; @@ -84,7 +84,7 @@ function isAlertUserAction(newValue?: unknown | null): newValue is AlertCommentO return ( unsafeAlertData !== undefined && unsafeAlertData !== null && - (unsafeAlertData.type === GENERATED_ALERT || unsafeAlertData.type === CommentType.alert) + (unsafeAlertData.type === GENERATED_ALERT || unsafeAlertData.type === AttachmentType.alert) ); } @@ -97,6 +97,6 @@ function isCreateComment(action?: string, actionFields?: string[]): boolean { ); } -type AlertCommentOptional = Partial> & { - type: CommentType.alert | typeof GENERATED_ALERT; +type AlertCommentOptional = Partial> & { + type: AttachmentType.alert | typeof GENERATED_ALERT; }; diff --git a/x-pack/plugins/cases/server/saved_object_types/migrations/user_actions/connector_id.ts b/x-pack/plugins/cases/server/saved_object_types/migrations/user_actions/connector_id.ts index 852aaa75e0b82d..f6860e0e6a1d7a 100644 --- a/x-pack/plugins/cases/server/saved_object_types/migrations/user_actions/connector_id.ts +++ b/x-pack/plugins/cases/server/saved_object_types/migrations/user_actions/connector_id.ts @@ -16,10 +16,8 @@ import type { SavedObjectUnsanitizedDoc, } from '@kbn/core/server'; import { ACTION_SAVED_OBJECT_TYPE } from '@kbn/actions-plugin/server'; -import type { CaseConnector } from '../../../../common/types/domain'; -import { CaseConnectorRt } from '../../../../common/types/domain'; -import type { CaseAttributes } from '../../../../common/api'; -import { CaseExternalServiceBasicRt } from '../../../../common/api'; +import type { CaseAttributes, CaseConnector } from '../../../../common/types/domain'; +import { CaseConnectorRt, ExternalServiceRt } from '../../../../common/types/domain'; import { CONNECTOR_ID_REFERENCE_NAME, PUSH_CONNECTOR_ID_REFERENCE_NAME, @@ -232,7 +230,7 @@ function isUpdateCaseConnector( } } -type CaseExternalService = rt.TypeOf; +type CaseExternalService = rt.TypeOf; function isPushConnector( action: string, @@ -240,7 +238,7 @@ function isPushConnector( actionDetails: unknown ): actionDetails is CaseExternalService { try { - return isPush(action, actionFields) && CaseExternalServiceBasicRt.is(actionDetails); + return isPush(action, actionFields) && ExternalServiceRt.is(actionDetails); } catch { return false; } diff --git a/x-pack/plugins/cases/server/saved_object_types/migrations/user_actions/payload.test.ts b/x-pack/plugins/cases/server/saved_object_types/migrations/user_actions/payload.test.ts index b4980be136c81c..c0a13b061aa74b 100644 --- a/x-pack/plugins/cases/server/saved_object_types/migrations/user_actions/payload.test.ts +++ b/x-pack/plugins/cases/server/saved_object_types/migrations/user_actions/payload.test.ts @@ -9,7 +9,7 @@ import type { SavedObjectMigrationContext, SavedObjectUnsanitizedDoc } from '@kbn/core/server'; import { migrationMocks } from '@kbn/core/server/mocks'; -import { CommentType } from '../../../../common/api'; +import { AttachmentType } from '../../../../common/types/domain'; import { CASE_USER_ACTION_SAVED_OBJECT, SECURITY_SOLUTION_OWNER, @@ -141,7 +141,7 @@ describe('user action migrations', () => { const userAction = create_7_14_0_userAction({ action: 'create', action_field: ['comment'], - new_value: { comment: 'A comment', type: CommentType.user }, + new_value: { comment: 'A comment', type: AttachmentType.user }, old_value: null, }); diff --git a/x-pack/plugins/cases/server/saved_object_types/migrations/user_actions/payload.ts b/x-pack/plugins/cases/server/saved_object_types/migrations/user_actions/payload.ts index 0d47e78ae54421..6475514d51353e 100644 --- a/x-pack/plugins/cases/server/saved_object_types/migrations/user_actions/payload.ts +++ b/x-pack/plugins/cases/server/saved_object_types/migrations/user_actions/payload.ts @@ -16,8 +16,12 @@ import type { SavedObjectUnsanitizedDoc, } from '@kbn/core/server'; import type { UserActionType } from '../../../../common/types/domain'; -import { UserActionActions, UserActionTypes } from '../../../../common/types/domain'; -import { CaseStatuses, CommentType } from '../../../../common/api'; +import { + UserActionActions, + UserActionTypes, + CaseStatuses, + AttachmentType, +} from '../../../../common/types/domain'; import { USER_ACTION_OLD_ID_REF_NAME, USER_ACTION_OLD_PUSH_ID_REF_NAME } from './constants'; import { getNoneCaseConnector } from '../../../common/utils'; import { logError } from '../utils'; @@ -204,7 +208,7 @@ const getSingleFieldPayload = ( } : { comment: isString(value) ? value : '', - type: CommentType.user, + type: AttachmentType.user, owner, }, }; diff --git a/x-pack/plugins/cases/server/saved_object_types/migrations/user_actions/severity.ts b/x-pack/plugins/cases/server/saved_object_types/migrations/user_actions/severity.ts index b1426052e06642..ada8b8ed6638d2 100644 --- a/x-pack/plugins/cases/server/saved_object_types/migrations/user_actions/severity.ts +++ b/x-pack/plugins/cases/server/saved_object_types/migrations/user_actions/severity.ts @@ -7,8 +7,7 @@ import type { SavedObjectUnsanitizedDoc, SavedObjectSanitizedDoc } from '@kbn/core/server'; import type { CreateCaseUserAction } from '../../../../common/types/domain'; -import { UserActionTypes } from '../../../../common/types/domain'; -import { CaseSeverity } from '../../../../common/api'; +import { CaseSeverity, UserActionTypes } from '../../../../common/types/domain'; export const addSeverityToCreateUserAction = ( doc: SavedObjectUnsanitizedDoc diff --git a/x-pack/plugins/cases/server/saved_object_types/migrations/utils.ts b/x-pack/plugins/cases/server/saved_object_types/migrations/utils.ts index e84d3271f466e5..680da4aaac1c11 100644 --- a/x-pack/plugins/cases/server/saved_object_types/migrations/utils.ts +++ b/x-pack/plugins/cases/server/saved_object_types/migrations/utils.ts @@ -18,8 +18,11 @@ import type { LensServerPluginSetup } from '@kbn/lens-plugin/server'; import type { SavedObjectMigrationParams } from '@kbn/core-saved-objects-server'; import type { MigrateFunction, MigrateFunctionsObject } from '@kbn/kibana-utils-plugin/common'; import type { AttachmentPersistedAttributes } from '../../common/types/attachments'; -import { CommentType } from '../../../common/api'; -import type { AttributesTypePersistableState, AttributesTypeUser } from '../../../common/api'; +import { AttachmentType } from '../../../common/types/domain'; +import type { + PersistableStateAttachmentAttributes, + UserCommentAttachmentAttributes, +} from '../../../common/types/domain'; interface MigrationLogMeta extends LogMeta { migrations: { @@ -73,14 +76,14 @@ export const isDeferredMigration = ( export const isUserCommentSO = ( doc: SavedObjectUnsanitizedDoc -): doc is SavedObjectUnsanitizedDoc => { - return doc.attributes.type === CommentType.user; +): doc is SavedObjectUnsanitizedDoc => { + return doc.attributes.type === AttachmentType.user; }; export const isPersistableStateAttachmentSO = ( doc: SavedObjectUnsanitizedDoc -): doc is SavedObjectUnsanitizedDoc => { - return doc.attributes.type === CommentType.persistableState; +): doc is SavedObjectUnsanitizedDoc => { + return doc.attributes.type === AttachmentType.persistableState; }; interface GetLensMigrationsArgs { diff --git a/x-pack/plugins/cases/server/services/alerts/index.test.ts b/x-pack/plugins/cases/server/services/alerts/index.test.ts index 970494ce2140f5..a18681c6478a39 100644 --- a/x-pack/plugins/cases/server/services/alerts/index.test.ts +++ b/x-pack/plugins/cases/server/services/alerts/index.test.ts @@ -7,7 +7,7 @@ import { elasticsearchServiceMock, loggingSystemMock } from '@kbn/core/server/mocks'; import { alertsClientMock } from '@kbn/rule-registry-plugin/server/alert_data_client/alerts_client.mock'; -import { CaseStatuses } from '../../../common/api'; +import { CaseStatuses } from '../../../common/types/domain'; import { AlertService } from '.'; describe('updateAlertsStatus', () => { diff --git a/x-pack/plugins/cases/server/services/alerts/index.ts b/x-pack/plugins/cases/server/services/alerts/index.ts index 7e094a14b264da..50a8e286cea4ec 100644 --- a/x-pack/plugins/cases/server/services/alerts/index.ts +++ b/x-pack/plugins/cases/server/services/alerts/index.ts @@ -14,7 +14,7 @@ import { ALERT_WORKFLOW_STATUS } from '@kbn/rule-registry-plugin/common/technica import type { MgetResponse } from '@elastic/elasticsearch/lib/api/types'; import type { AlertsClient } from '@kbn/rule-registry-plugin/server'; import type { PublicMethodsOf } from '@kbn/utility-types'; -import { CaseStatuses } from '../../../common/api'; +import { CaseStatuses } from '../../../common/types/domain'; import { MAX_ALERTS_PER_CASE, MAX_CONCURRENT_SEARCHES } from '../../../common/constants'; import { createCaseError } from '../../common/error'; import type { AlertInfo } from '../../common/types'; diff --git a/x-pack/plugins/cases/server/services/attachments/index.test.ts b/x-pack/plugins/cases/server/services/attachments/index.test.ts index 610ce7df5bb9d2..fc12e26b67ed6e 100644 --- a/x-pack/plugins/cases/server/services/attachments/index.test.ts +++ b/x-pack/plugins/cases/server/services/attachments/index.test.ts @@ -22,7 +22,7 @@ import { persistableStateAttachmentAttributesWithoutInjectedId, } from '../../attachment_framework/mocks'; import { createAlertAttachment, createErrorSO, createUserAttachment } from './test_utils'; -import { CommentType } from '../../../common'; +import { AttachmentType } from '../../../common/types/domain'; import { createSOFindResponse } from '../test_utils'; describe('AttachmentService', () => { @@ -278,7 +278,7 @@ describe('AttachmentService', () => { await expect( service.update({ - updatedAttributes: { comment: 'yes', type: CommentType.user, owner: 'hi' }, + updatedAttributes: { comment: 'yes', type: AttachmentType.user, owner: 'hi' }, attachmentId: '1', }) ).resolves.not.toThrow(); @@ -288,7 +288,7 @@ describe('AttachmentService', () => { unsecuredSavedObjectsClient.update.mockResolvedValue(createUserAttachment({ foo: 'bar' })); const res = await service.update({ - updatedAttributes: { comment: 'yes', type: CommentType.user, owner: 'hi' }, + updatedAttributes: { comment: 'yes', type: AttachmentType.user, owner: 'hi' }, attachmentId: '1', }); diff --git a/x-pack/plugins/cases/server/services/attachments/index.ts b/x-pack/plugins/cases/server/services/attachments/index.ts index 8f5c9ee69c07c8..25405749064469 100644 --- a/x-pack/plugins/cases/server/services/attachments/index.ts +++ b/x-pack/plugins/cases/server/services/attachments/index.ts @@ -15,7 +15,8 @@ import type { import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; import { fromKueryExpression } from '@kbn/es-query'; -import { CommentAttributesRt, CommentType, decodeOrThrow } from '../../../common/api'; +import { AttachmentAttributesRt, AttachmentType } from '../../../common/types/domain'; +import { decodeOrThrow } from '../../../common/api'; import { CASE_COMMENT_SAVED_OBJECT, CASE_SAVED_OBJECT, @@ -71,7 +72,7 @@ export class AttachmentService { this.context.log.debug(`Attempting to count alerts for case id ${params.caseId}`); const res = await this.executeCaseAggregations<{ alerts: { value: number } }>({ ...params, - attachmentType: CommentType.alert, + attachmentType: AttachmentType.alert, aggregations: this.buildAlertsAggs(), }); @@ -143,7 +144,7 @@ export class AttachmentService { ); const typeFilter = buildFilter({ - filters: [CommentType.persistableState, CommentType.externalReference], + filters: [AttachmentType.persistableState, AttachmentType.externalReference], field: 'type', operator: 'or', type: CASE_COMMENT_SAVED_OBJECT, @@ -181,7 +182,10 @@ export class AttachmentService { ): Promise { try { this.context.log.debug(`Attempting to count actions for case id ${params.caseId}`); - return await this.executeCaseAggregations({ ...params, attachmentType: CommentType.actions }); + return await this.executeCaseAggregations({ + ...params, + attachmentType: AttachmentType.actions, + }); } catch (error) { this.context.log.error(`Error while counting actions for case id ${params.caseId}: ${error}`); throw error; @@ -216,7 +220,7 @@ export class AttachmentService { try { this.context.log.debug(`Attempting to POST a new comment`); - const decodedAttributes = decodeOrThrow(CommentAttributesRt)(attributes); + const decodedAttributes = decodeOrThrow(AttachmentAttributesRt)(attributes); const { attributes: extractedAttributes, references: extractedReferences } = extractAttachmentSORefsFromAttributes( @@ -261,7 +265,7 @@ export class AttachmentService { const res = await this.context.unsecuredSavedObjectsClient.bulkCreate( attachments.map((attachment) => { - const decodedAttributes = decodeOrThrow(CommentAttributesRt)(attachment.attributes); + const decodedAttributes = decodeOrThrow(AttachmentAttributesRt)(attachment.attributes); const { attributes: extractedAttributes, references: extractedReferences } = extractAttachmentSORefsFromAttributes( diff --git a/x-pack/plugins/cases/server/services/attachments/operations/get.ts b/x-pack/plugins/cases/server/services/attachments/operations/get.ts index 329990cff0777d..dae78b91657573 100644 --- a/x-pack/plugins/cases/server/services/attachments/operations/get.ts +++ b/x-pack/plugins/cases/server/services/attachments/operations/get.ts @@ -12,6 +12,7 @@ import type { } from '@kbn/core/server'; import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; import { FILE_SO_TYPE } from '@kbn/files-plugin/common'; +import { decodeOrThrow } from '../../../../common/api'; import type { AttachmentPersistedAttributes, AttachmentTransformedAttributes, @@ -25,8 +26,8 @@ import { MAX_DOCS_PER_PAGE, } from '../../../../common/constants'; import { buildFilter, combineFilters } from '../../../client/utils'; -import type { AttachmentTotals, AttributesTypeAlerts } from '../../../../common/api'; -import { CommentType, decodeOrThrow, AttributesTypeAlertsRt } from '../../../../common/api'; +import type { AlertAttachmentAttributes, AttachmentTotals } from '../../../../common/types/domain'; +import { AttachmentType, AlertAttachmentAttributesRt } from '../../../../common/types/domain'; import type { AlertIdsAggsResult, BulkOptionalAttributes, @@ -140,11 +141,11 @@ export class AttachmentGetter { public async getAllAlertsAttachToCase({ caseId, filter, - }: GetAllAlertsAttachToCaseArgs): Promise>> { + }: GetAllAlertsAttachToCaseArgs): Promise>> { try { this.context.log.debug(`Attempting to GET all alerts for case id ${caseId}`); const alertsFilter = buildFilter({ - filters: [CommentType.alert], + filters: [AttachmentType.alert], field: 'type', operator: 'or', type: CASE_COMMENT_SAVED_OBJECT, @@ -164,7 +165,7 @@ export class AttachmentGetter { } ); - let result: Array> = []; + let result: Array> = []; for await (const userActionSavedObject of finder.find()) { result = result.concat(AttachmentGetter.decodeAlerts(userActionSavedObject)); } @@ -178,9 +179,9 @@ export class AttachmentGetter { private static decodeAlerts( response: SavedObjectsFindResponse - ): Array> { + ): Array> { return response.saved_objects.map((so) => { - const validatedAttributes = decodeOrThrow(AttributesTypeAlertsRt)(so.attributes); + const validatedAttributes = decodeOrThrow(AlertAttachmentAttributesRt)(so.attributes); return Object.assign(so, { attributes: validatedAttributes }); }); @@ -193,7 +194,7 @@ export class AttachmentGetter { try { this.context.log.debug(`Attempting to GET all alerts ids for case id ${caseId}`); const alertsFilter = buildFilter({ - filters: [CommentType.alert], + filters: [AttachmentType.alert], field: 'type', operator: 'or', type: CASE_COMMENT_SAVED_OBJECT, @@ -321,7 +322,7 @@ export class AttachmentGetter { comments: { filter: { term: { - [`${CASE_COMMENT_SAVED_OBJECT}.attributes.type`]: CommentType.user, + [`${CASE_COMMENT_SAVED_OBJECT}.attributes.type`]: AttachmentType.user, }, }, }, diff --git a/x-pack/plugins/cases/server/services/attachments/test_utils.ts b/x-pack/plugins/cases/server/services/attachments/test_utils.ts index 57b3dc9c724dac..ab3c7a6f710be9 100644 --- a/x-pack/plugins/cases/server/services/attachments/test_utils.ts +++ b/x-pack/plugins/cases/server/services/attachments/test_utils.ts @@ -7,13 +7,13 @@ import type { SavedObject } from '@kbn/core/server'; import { FILE_SO_TYPE } from '@kbn/files-plugin/common'; +import { AttachmentType, ExternalReferenceStorageType } from '../../../common/types/domain'; import type { - AttributesTypeAlerts, - AttributesTypeUser, - CommentAttributesWithoutRefs, - ExternalReferenceWithoutRefs, -} from '../../../common/api'; -import { ExternalReferenceStorageType, CommentType } from '../../../common/api'; + UserCommentAttachmentAttributes, + AlertAttachmentAttributes, + AttachmentAttributesWithoutRefs, + ExternalReferenceWithoutRefsAttachmentPayload, +} from '../../../common/types/domain'; import { CASE_COMMENT_SAVED_OBJECT, CASE_SAVED_OBJECT, @@ -33,15 +33,17 @@ export const createErrorSO = () => }, references: [], // casting because this complains about attributes not being there - } as unknown as SavedObject); + } as unknown as SavedObject); -export const createUserAttachment = (attributes?: object): SavedObject => { +export const createUserAttachment = ( + attributes?: object +): SavedObject => { return { id: '1', type: CASE_COMMENT_SAVED_OBJECT, attributes: { comment: 'Wow, good luck catching that bad meanie!', - type: CommentType.user as const, + type: AttachmentType.user as const, created_at: '2019-11-25T21:55:00.177Z', created_by: { full_name: 'elastic', @@ -63,7 +65,9 @@ export const createUserAttachment = (attributes?: object): SavedObject => { +export const createAlertAttachment = ( + attributes?: object +): SavedObject => { return { id: '1', type: CASE_COMMENT_SAVED_OBJECT, @@ -74,7 +78,7 @@ export const createAlertAttachment = (attributes?: object): SavedObject ({ files: [fileMetadata()], }); -const getFilesAttachmentReq = (): ExternalReferenceWithoutRefs => { +const getFilesAttachmentReq = (): ExternalReferenceWithoutRefsAttachmentPayload => { return { - type: CommentType.externalReference, + type: AttachmentType.externalReference, owner: 'securitySolutionFixture', externalReferenceStorage: { type: ExternalReferenceStorageType.savedObject as const, @@ -122,7 +126,7 @@ const getFilesAttachmentReq = (): ExternalReferenceWithoutRefs => { export const createFileAttachment = ( attributes?: object -): SavedObject => { +): SavedObject => { return { id: '1', type: CASE_COMMENT_SAVED_OBJECT, diff --git a/x-pack/plugins/cases/server/services/attachments/types.ts b/x-pack/plugins/cases/server/services/attachments/types.ts index dbf9075031d831..c9c5de01e3a4a6 100644 --- a/x-pack/plugins/cases/server/services/attachments/types.ts +++ b/x-pack/plugins/cases/server/services/attachments/types.ts @@ -15,11 +15,8 @@ import type { SavedObjectsUpdateOptions, } from '@kbn/core/server'; import type { KueryNode } from '@kbn/es-query'; -import type { CommentType } from '../../../common'; -import type { - CommentAttributes as AttachmentAttributes, - CommentPatchAttributes as AttachmentPatchAttributes, -} from '../../../common/api'; +import type { AttachmentType } from '../../../common'; +import type { AttachmentAttributes, AttachmentPatchAttributes } from '../../../common/types/domain'; import type { PersistableStateAttachmentTypeRegistry } from '../../attachment_framework/persistable_state_registry'; import type { PartialField } from '../../types'; import type { IndexRefresh } from '../types'; @@ -59,7 +56,7 @@ export interface AlertIdsAggsResult { export type AlertsAttachedToCaseArgs = AttachedToCaseArgs; export interface AttachmentsAttachedToCaseArgs extends AttachedToCaseArgs { - attachmentType: CommentType; + attachmentType: AttachmentType; aggregations: Record; } diff --git a/x-pack/plugins/cases/server/services/cases/index.test.ts b/x-pack/plugins/cases/server/services/cases/index.test.ts index 37fc356a15bf57..3f7ab21017b78a 100644 --- a/x-pack/plugins/cases/server/services/cases/index.test.ts +++ b/x-pack/plugins/cases/server/services/cases/index.test.ts @@ -14,8 +14,8 @@ */ import { omit, unset } from 'lodash'; -import type { CaseAttributes, CaseFullExternalService } from '../../../common/api'; -import { CaseSeverity, CaseStatuses } from '../../../common/api'; +import type { CaseAttributes, ExternalService, CaseConnector } from '../../../common/types/domain'; +import { CaseSeverity, CaseStatuses } from '../../../common/types/domain'; import { CASE_SAVED_OBJECT, SECURITY_SOLUTION_OWNER } from '../../../common/constants'; import { savedObjectsClientMock } from '@kbn/core/server/mocks'; import type { @@ -50,7 +50,6 @@ import { CasePersistedStatus, CaseTransformedAttributesRt, } from '../../common/types/case'; -import type { CaseConnector } from '../../../common/types/domain'; const createUpdateSOResponse = ({ connector, @@ -59,7 +58,7 @@ const createUpdateSOResponse = ({ status, }: { connector?: ESCaseConnectorWithId; - externalService?: CaseFullExternalService; + externalService?: ExternalService | null; severity?: CasePersistedSeverity; status?: CasePersistedStatus; } = {}): SavedObjectsUpdateResponse => { @@ -99,7 +98,7 @@ const createUpdateSOResponse = ({ const createFindSO = ( params: { connector?: ESCaseConnectorWithId; - externalService?: CaseFullExternalService; + externalService?: ExternalService | null; overrides?: Partial; caseId?: string; } = {} @@ -115,7 +114,7 @@ const createCaseUpdateParams = ({ status, }: { connector?: CaseConnector; - externalService?: CaseFullExternalService; + externalService?: ExternalService | null; severity?: CaseSeverity; status?: CaseStatuses; }): Partial => ({ @@ -132,7 +131,7 @@ const createCasePostParams = ({ status, }: { connector: CaseConnector; - externalService?: CaseFullExternalService; + externalService?: ExternalService | null; severity?: CaseSeverity; status?: CaseStatuses; }): CaseAttributes => ({ @@ -148,7 +147,7 @@ const createCasePatchParams = ({ externalService, }: { connector?: CaseConnector; - externalService?: CaseFullExternalService; + externalService?: ExternalService | null; } = {}): Partial => ({ ...basicCaseFields, connector, diff --git a/x-pack/plugins/cases/server/services/cases/index.ts b/x-pack/plugins/cases/server/services/cases/index.ts index f2dfd10e5e6fb4..8ead5738d51957 100644 --- a/x-pack/plugins/cases/server/services/cases/index.ts +++ b/x-pack/plugins/cases/server/services/cases/index.ts @@ -23,13 +23,14 @@ import type { import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; import { nodeBuilder } from '@kbn/es-query'; +import type { Case, CaseStatuses, User } from '../../../common/types/domain'; +import { caseStatuses } from '../../../common/types/domain'; import { CASE_COMMENT_SAVED_OBJECT, CASE_SAVED_OBJECT, MAX_DOCS_PER_PAGE, } from '../../../common/constants'; -import type { Case, User, CaseStatuses } from '../../../common/api'; -import { decodeOrThrow, caseStatuses } from '../../../common/api'; +import { decodeOrThrow } from '../../../common/api'; import type { SavedObjectFindOptionsKueryNode, SOWithErrors } from '../../common/types'; import { defaultSortField, flattenCaseSavedObject, isSOError } from '../../common/utils'; import { DEFAULT_PAGE, DEFAULT_PER_PAGE } from '../../routes/api'; diff --git a/x-pack/plugins/cases/server/services/cases/transform.test.ts b/x-pack/plugins/cases/server/services/cases/transform.test.ts index 7e34e5f584550a..e6dc9dfb487688 100644 --- a/x-pack/plugins/cases/server/services/cases/transform.test.ts +++ b/x-pack/plugins/cases/server/services/cases/transform.test.ts @@ -19,14 +19,13 @@ import { transformUpdateResponseToExternalModel, } from './transform'; import { ACTION_SAVED_OBJECT_TYPE } from '@kbn/actions-plugin/server'; -import { CaseSeverity, CaseStatuses } from '../../../common/api'; import { CONNECTOR_ID_REFERENCE_NAME, PUSH_CONNECTOR_ID_REFERENCE_NAME, } from '../../common/constants'; import { getNoneCaseConnector } from '../../common/utils'; import { CasePersistedSeverity, CasePersistedStatus } from '../../common/types/case'; -import { ConnectorTypes } from '../../../common/types/domain'; +import { CaseSeverity, CaseStatuses, ConnectorTypes } from '../../../common/types/domain'; describe('case transforms', () => { describe('transformUpdateResponseToExternalModel', () => { diff --git a/x-pack/plugins/cases/server/services/cases/transform.ts b/x-pack/plugins/cases/server/services/cases/transform.ts index 93ba92f8397fa7..99fafaf80cdb3a 100644 --- a/x-pack/plugins/cases/server/services/cases/transform.ts +++ b/x-pack/plugins/cases/server/services/cases/transform.ts @@ -15,6 +15,8 @@ import type { } from '@kbn/core/server'; import { ACTION_SAVED_OBJECT_TYPE } from '@kbn/actions-plugin/server'; import { NONE_CONNECTOR_ID } from '../../../common/constants'; +import type { ExternalService } from '../../../common/types/domain'; +import { CaseSeverity, CaseStatuses } from '../../../common/types/domain'; import { CONNECTOR_ID_REFERENCE_NAME, PUSH_CONNECTOR_ID_REFERENCE_NAME, @@ -23,8 +25,6 @@ import { STATUS_ESMODEL_TO_EXTERNAL, STATUS_EXTERNAL_TO_ESMODEL, } from '../../common/constants'; -import type { CaseFullExternalService } from '../../../common/api'; -import { CaseSeverity, CaseStatuses } from '../../../common/api'; import { findConnectorIdReference, transformFieldsToESModel, @@ -60,7 +60,7 @@ export function transformUpdateResponseToExternalModel( referenceName: CONNECTOR_ID_REFERENCE_NAME, }); - let externalService: CaseFullExternalService | null | undefined; + let externalService: ExternalService | null | undefined; // if external_service is not defined then we don't want to include it in the response since it wasn't passed it as an // attribute to update @@ -193,7 +193,7 @@ function transformESExternalService( // that's why it can be null here externalService: ExternalServicePersisted | null | undefined, references: SavedObjectReference[] | undefined -): CaseFullExternalService | null { +): ExternalService | null { const connectorIdRef = findConnectorIdReference(PUSH_CONNECTOR_ID_REFERENCE_NAME, references); if (!externalService) { diff --git a/x-pack/plugins/cases/server/services/cases/types.ts b/x-pack/plugins/cases/server/services/cases/types.ts index c66d5edddd9426..14f210134e48d4 100644 --- a/x-pack/plugins/cases/server/services/cases/types.ts +++ b/x-pack/plugins/cases/server/services/cases/types.ts @@ -7,7 +7,7 @@ import type { KueryNode } from '@kbn/es-query'; import type { SavedObjectsClientContract } from '@kbn/core/server'; -import type { Case } from '../../../common/api'; +import type { Case } from '../../../common/types/domain'; import type { IndexRefresh } from '../types'; import type { User } from '../../common/types/user'; import type { diff --git a/x-pack/plugins/cases/server/services/notifications/templates/assignees/renderer.ts b/x-pack/plugins/cases/server/services/notifications/templates/assignees/renderer.ts index d79120f394f507..7c416d75433113 100644 --- a/x-pack/plugins/cases/server/services/notifications/templates/assignees/renderer.ts +++ b/x-pack/plugins/cases/server/services/notifications/templates/assignees/renderer.ts @@ -9,8 +9,8 @@ import fs from 'fs'; import mustache from 'mustache'; import { join } from 'path'; import { assertNever } from '@elastic/eui'; +import { CaseStatuses, CaseSeverity } from '../../../../../common/types/domain'; import type { CaseSavedObjectTransformed } from '../../../../common/types/case'; -import { CaseStatuses, CaseSeverity } from '../../../../../common/api'; import { getTemplateFilePath } from '../utils'; const TAG_LIMIT = 3; diff --git a/x-pack/plugins/cases/server/services/notifications/types.ts b/x-pack/plugins/cases/server/services/notifications/types.ts index 48909c00a77d70..d89184f03b01c9 100644 --- a/x-pack/plugins/cases/server/services/notifications/types.ts +++ b/x-pack/plugins/cases/server/services/notifications/types.ts @@ -5,7 +5,7 @@ * 2.0. */ -import type { CaseAssignees } from '../../../common/api'; +import type { CaseAssignees } from '../../../common/types/domain'; import type { CaseSavedObjectTransformed } from '../../common/types/case'; export interface NotifyArgs { diff --git a/x-pack/plugins/cases/server/services/so_references.ts b/x-pack/plugins/cases/server/services/so_references.ts index e95f3cafafcf1b..b5b0a31eb5aa78 100644 --- a/x-pack/plugins/cases/server/services/so_references.ts +++ b/x-pack/plugins/cases/server/services/so_references.ts @@ -12,10 +12,10 @@ import type { } from '@kbn/core/server'; import { isEqual, uniqWith } from 'lodash'; import type { - CommentAttributes, - CommentAttributesNoSO, - CommentPatchAttributes, -} from '../../common/api'; + AttachmentAttributes, + AttachmentAttributesNoSO, + AttachmentPatchAttributes, +} from '../../common/types/domain'; import type { PersistableStateAttachmentTypeRegistry } from '../attachment_framework/persistable_state_registry'; import { injectPersistableReferencesToSO, @@ -84,7 +84,7 @@ export const injectAttachmentSOAttributesFromRefs = ( }; export const injectAttachmentSOAttributesFromRefsForPatch = ( - updatedAttributes: CommentPatchAttributes, + updatedAttributes: AttachmentPatchAttributes, savedObject: SavedObjectsUpdateResponse, persistableStateAttachmentTypeRegistry: PersistableStateAttachmentTypeRegistry ): SavedObjectsUpdateResponse => { @@ -115,7 +115,7 @@ interface ExtractionResults { } export const extractAttachmentSORefsFromAttributes = ( - attributes: CommentAttributes | CommentPatchAttributes, + attributes: AttachmentAttributes | AttachmentPatchAttributes, references: SavedObjectReference[], persistableStateAttachmentTypeRegistry: PersistableStateAttachmentTypeRegistry ): ExtractionResults => { @@ -125,7 +125,7 @@ export const extractAttachmentSORefsFromAttributes = ( transformedFields, references: refsWithExternalRefId, didDeleteOperation, - } = soExtractor.extractFieldsToReferences({ + } = soExtractor.extractFieldsToReferences({ data: attributes, existingReferences: references, }); diff --git a/x-pack/plugins/cases/server/services/test_utils.ts b/x-pack/plugins/cases/server/services/test_utils.ts index 807880dc9a52cd..22158ef4d656e6 100644 --- a/x-pack/plugins/cases/server/services/test_utils.ts +++ b/x-pack/plugins/cases/server/services/test_utils.ts @@ -13,15 +13,9 @@ import type { SavedObjectsFindResult, } from '@kbn/core/server'; import { ACTION_SAVED_OBJECT_TYPE } from '@kbn/actions-plugin/server'; -import type { CaseConnector } from '../../common/types/domain'; -import { ConnectorTypes } from '../../common/types/domain'; +import type { ExternalService, CaseAttributes, CaseConnector } from '../../common/types/domain'; +import { CaseStatuses, CaseSeverity, ConnectorTypes } from '../../common/types/domain'; import { CONNECTOR_ID_REFERENCE_NAME, PUSH_CONNECTOR_ID_REFERENCE_NAME } from '../common/constants'; -import type { - CaseAttributes, - CaseExternalServiceBasic, - CaseFullExternalService, -} from '../../common/api'; -import { CaseSeverity, CaseStatuses } from '../../common/api'; import { CASE_SAVED_OBJECT, NONE_CONNECTOR_ID, @@ -92,9 +86,7 @@ export const createJiraConnector = ({ }; }; -export const createExternalService = ( - overrides?: Partial -): CaseExternalServiceBasic => ({ +export const createExternalService = (overrides?: Partial): ExternalService => ({ connector_id: '100', connector_name: '.jira', external_id: '100', @@ -180,7 +172,7 @@ export const createCaseSavedObjectResponse = ({ caseId, }: { connector?: ESCaseConnectorWithId; - externalService?: CaseFullExternalService; + externalService?: ExternalService | null; overrides?: Partial; caseId?: string; } = {}): SavedObject => { @@ -232,7 +224,7 @@ export const createSavedObjectReferences = ({ externalService, }: { connector?: ESCaseConnectorWithId; - externalService?: CaseFullExternalService; + externalService?: ExternalService | null; } = {}): SavedObjectReference[] => [ ...(connector && connector.id !== NONE_CONNECTOR_ID ? [ diff --git a/x-pack/plugins/cases/server/services/type_guards.ts b/x-pack/plugins/cases/server/services/type_guards.ts index ec4c100b17585c..a5b8d9cdb7e4ea 100644 --- a/x-pack/plugins/cases/server/services/type_guards.ts +++ b/x-pack/plugins/cases/server/services/type_guards.ts @@ -5,8 +5,8 @@ * 2.0. */ -import type { CommentRequestExternalReferenceSOType } from '../../common/api'; -import { CommentType, ExternalReferenceStorageType } from '../../common/api'; +import type { ExternalReferenceSOAttachmentPayload } from '../../common/types/domain'; +import { AttachmentType, ExternalReferenceStorageType } from '../../common/types/domain'; import type { AttachmentRequestAttributes } from '../common/types/attachments'; /** @@ -14,9 +14,9 @@ import type { AttachmentRequestAttributes } from '../common/types/attachments'; */ export const isCommentRequestTypeExternalReferenceSO = ( context: Partial -): context is CommentRequestExternalReferenceSOType => { +): context is ExternalReferenceSOAttachmentPayload => { return ( - context.type === CommentType.externalReference && + context.type === AttachmentType.externalReference && context.externalReferenceStorage?.type === ExternalReferenceStorageType.savedObject ); }; diff --git a/x-pack/plugins/cases/server/services/user_actions/abstract_builder.ts b/x-pack/plugins/cases/server/services/user_actions/abstract_builder.ts index 337d810691f892..9630cc6c91c684 100644 --- a/x-pack/plugins/cases/server/services/user_actions/abstract_builder.ts +++ b/x-pack/plugins/cases/server/services/user_actions/abstract_builder.ts @@ -7,7 +7,7 @@ import type { SavedObjectReference } from '@kbn/core/server'; import { ACTION_SAVED_OBJECT_TYPE } from '@kbn/actions-plugin/server'; -import type { CaseConnector } from '../../../common/types/domain'; +import type { CaseConnector, ExternalService, User } from '../../../common/types/domain'; import { UserActionTypes } from '../../../common/types/domain'; import { CASE_COMMENT_SAVED_OBJECT, @@ -20,7 +20,6 @@ import { CONNECTOR_ID_REFERENCE_NAME, PUSH_CONNECTOR_ID_REFERENCE_NAME, } from '../../common/constants'; -import type { CaseExternalServiceBasic, User } from '../../../common/api'; import type { BuilderDeps, BuilderParameters, @@ -88,8 +87,8 @@ export abstract class UserActionBuilder { } protected extractConnectorIdFromExternalService( - externalService: CaseExternalServiceBasic - ): Omit { + externalService: ExternalService + ): Omit { const { connector_id: connectorId, ...restExternalService } = externalService; return restExternalService; } diff --git a/x-pack/plugins/cases/server/services/user_actions/builder_factory.test.ts b/x-pack/plugins/cases/server/services/user_actions/builder_factory.test.ts index 896299c29146b4..fdf30f13a5e39a 100644 --- a/x-pack/plugins/cases/server/services/user_actions/builder_factory.test.ts +++ b/x-pack/plugins/cases/server/services/user_actions/builder_factory.test.ts @@ -5,9 +5,15 @@ * 2.0. */ -import { ConnectorTypes, UserActionActions, UserActionTypes } from '../../../common/types/domain'; +import { + AttachmentType, + CaseSeverity, + CaseStatuses, + ConnectorTypes, + UserActionActions, + UserActionTypes, +} from '../../../common/types/domain'; import { SECURITY_SOLUTION_OWNER } from '../../../common'; -import { CaseSeverity, CaseStatuses, CommentType } from '../../../common/api'; import { externalReferenceAttachmentES, externalReferenceAttachmentSO, @@ -150,7 +156,7 @@ describe('UserActionBuilder', () => { payload: { attachment: { comment: 'a comment!', - type: CommentType.user, + type: AttachmentType.user, owner: SECURITY_SOLUTION_OWNER, }, }, @@ -837,7 +843,7 @@ describe('UserActionBuilder', () => { payload: { attachment: { comment: 'a comment!', - type: CommentType.user, + type: AttachmentType.user, owner: SECURITY_SOLUTION_OWNER, }, }, diff --git a/x-pack/plugins/cases/server/services/user_actions/builders/create_case.ts b/x-pack/plugins/cases/server/services/user_actions/builders/create_case.ts index 57b0c13330d96b..32b370ac01ff7b 100644 --- a/x-pack/plugins/cases/server/services/user_actions/builders/create_case.ts +++ b/x-pack/plugins/cases/server/services/user_actions/builders/create_case.ts @@ -5,9 +5,8 @@ * 2.0. */ -import { UserActionActions, UserActionTypes } from '../../../../common/types/domain'; +import { UserActionActions, UserActionTypes, CaseStatuses } from '../../../../common/types/domain'; import { CASE_SAVED_OBJECT } from '../../../../common/constants'; -import { CaseStatuses } from '../../../../common/api'; import { UserActionBuilder } from '../abstract_builder'; import type { EventDetails, UserActionParameters, UserActionEvent } from '../types'; diff --git a/x-pack/plugins/cases/server/services/user_actions/index.test.ts b/x-pack/plugins/cases/server/services/user_actions/index.test.ts index 524dbe2eb56764..b59172b6999b89 100644 --- a/x-pack/plugins/cases/server/services/user_actions/index.test.ts +++ b/x-pack/plugins/cases/server/services/user_actions/index.test.ts @@ -15,8 +15,12 @@ import type { SavedObjectsUpdateResponse, } from '@kbn/core/server'; import { auditLoggerMock } from '@kbn/security-plugin/server/audit/mocks'; -import type { CaseAttributes } from '../../../common/api'; -import { CaseSeverity, CaseStatuses } from '../../../common/api'; +import { + CaseSeverity, + CaseStatuses, + UserActionActions, + UserActionTypes, +} from '../../../common/types/domain'; import { SECURITY_SOLUTION_OWNER } from '../../../common/constants'; import { createCaseSavedObjectResponse, createSOFindResponse } from '../test_utils'; @@ -40,8 +44,10 @@ import { pushConnectorUserAction, } from './test_utils'; import { comment } from '../../mocks'; -import type { CaseUserActionWithoutReferenceIds } from '../../../common/types/domain'; -import { UserActionActions, UserActionTypes } from '../../../common/types/domain'; +import type { + CaseUserActionWithoutReferenceIds, + CaseAttributes, +} from '../../../common/types/domain'; describe('CaseUserActionService', () => { const persistableStateAttachmentTypeRegistry = createPersistableStateAttachmentTypeRegistryMock(); diff --git a/x-pack/plugins/cases/server/services/user_actions/mocks.ts b/x-pack/plugins/cases/server/services/user_actions/mocks.ts index 7d85cc1fbf946f..b3aecb676d296b 100644 --- a/x-pack/plugins/cases/server/services/user_actions/mocks.ts +++ b/x-pack/plugins/cases/server/services/user_actions/mocks.ts @@ -7,12 +7,11 @@ import { CASE_SAVED_OBJECT } from '../../../common/constants'; import { SECURITY_SOLUTION_OWNER } from '../../../common'; -import { ConnectorTypes } from '../../../common/types/domain'; -import type { CasePostRequest } from '../../../common/api'; -import { CaseSeverity, CaseStatuses } from '../../../common/api'; +import type { CasePostRequest } from '../../../common/types/api'; import { createCaseSavedObjectResponse } from '../test_utils'; import { transformSavedObjectToExternalModel } from '../cases/transform'; import { alertComment, comment } from '../../mocks'; +import { CaseSeverity, CaseStatuses, ConnectorTypes } from '../../../common/types/domain'; export const casePayload: CasePostRequest = { title: 'Case SIR', diff --git a/x-pack/plugins/cases/server/services/user_actions/operations/create.test.ts b/x-pack/plugins/cases/server/services/user_actions/operations/create.test.ts index 2534925e7059ab..92f5a6b6c254b8 100644 --- a/x-pack/plugins/cases/server/services/user_actions/operations/create.test.ts +++ b/x-pack/plugins/cases/server/services/user_actions/operations/create.test.ts @@ -17,7 +17,7 @@ import { UserActionPersister } from './create'; import { createUserActionSO } from '../test_utils'; import type { BulkCreateAttachmentUserAction, CreateUserActionClient } from '../types'; import type { UserActionPersistedAttributes } from '../../../common/types/user_actions'; -import { CommentType } from '../../../../common'; +import { AttachmentType } from '../../../../common/types/domain'; describe('UserActionPersister', () => { const unsecuredSavedObjectsClient = savedObjectsClientMock.create(); @@ -56,7 +56,7 @@ describe('UserActionPersister', () => { { id: '1', owner: 'cases', - attachment: { comment: 'test', type: CommentType.user, owner: 'cases' }, + attachment: { comment: 'test', type: AttachmentType.user, owner: 'cases' }, }, ], user: { email: '', full_name: '', username: '' }, diff --git a/x-pack/plugins/cases/server/services/user_actions/operations/create.ts b/x-pack/plugins/cases/server/services/user_actions/operations/create.ts index a9e863b6eb93d8..5713197a653db8 100644 --- a/x-pack/plugins/cases/server/services/user_actions/operations/create.ts +++ b/x-pack/plugins/cases/server/services/user_actions/operations/create.ts @@ -7,14 +7,18 @@ import type { SavedObject, SavedObjectsBulkResponse } from '@kbn/core/server'; import { get, isEmpty } from 'lodash'; -import type { UserActionAction, UserActionType } from '../../../../common/types/domain'; +import type { + CaseAssignees, + CaseUserProfile, + UserActionAction, + UserActionType, +} from '../../../../common/types/domain'; import { UserActionActions, UserActionTypes } from '../../../../common/types/domain'; import type { UserActionPersistedAttributes } from '../../../common/types/user_actions'; import { UserActionPersistedAttributesRt } from '../../../common/types/user_actions'; import { CASE_SAVED_OBJECT, CASE_USER_ACTION_SAVED_OBJECT } from '../../../../common/constants'; import { arraysDifference } from '../../../client/utils'; import { isUserActionType } from '../../../../common/utils/user_actions'; -import type { CaseAssignees, CaseUserProfile } from '../../../../common/api'; import { decodeOrThrow } from '../../../../common/api'; import { BuilderFactory } from '../builder_factory'; import type { diff --git a/x-pack/plugins/cases/server/services/user_actions/operations/find.ts b/x-pack/plugins/cases/server/services/user_actions/operations/find.ts index 96e09b72bed81d..c055a5cf4c81e1 100644 --- a/x-pack/plugins/cases/server/services/user_actions/operations/find.ts +++ b/x-pack/plugins/cases/server/services/user_actions/operations/find.ts @@ -11,7 +11,7 @@ import type { SavedObjectsFindResponse } from '@kbn/core-saved-objects-api-serve import type { UserActionFindRequestTypes } from '../../../../common/types/api'; import { DEFAULT_PAGE, DEFAULT_PER_PAGE } from '../../../routes/api'; import { defaultSortField } from '../../../common/utils'; -import { CommentType, decodeOrThrow } from '../../../../common/api'; +import { decodeOrThrow } from '../../../../common/api'; import { CASE_SAVED_OBJECT, CASE_USER_ACTION_SAVED_OBJECT, @@ -29,7 +29,11 @@ import type { import { bulkDecodeSOAttributes } from '../../utils'; import { UserActionTransformedAttributesRt } from '../../../common/types/user_actions'; import type { UserActionType } from '../../../../common/types/domain'; -import { UserActionActions, UserActionTypes } from '../../../../common/types/domain'; +import { + UserActionActions, + UserActionTypes, + AttachmentType, +} from '../../../../common/types/domain'; export class UserActionFinder { constructor(private readonly context: ServiceContext) {} @@ -103,7 +107,7 @@ export class UserActionFinder { private static buildActionFilter(): KueryNode | undefined { const filterForUserActionsExcludingComment = fromKueryExpression( - `not ${CASE_USER_ACTION_SAVED_OBJECT}.attributes.payload.comment.type: ${CommentType.user}` + `not ${CASE_USER_ACTION_SAVED_OBJECT}.attributes.payload.comment.type: ${AttachmentType.user}` ); return filterForUserActionsExcludingComment; @@ -119,7 +123,7 @@ export class UserActionFinder { type: CASE_USER_ACTION_SAVED_OBJECT, }), buildFilter({ - filters: [CommentType.user], + filters: [AttachmentType.user], field: 'payload.comment.type', operator: 'or', type: CASE_USER_ACTION_SAVED_OBJECT, @@ -139,7 +143,7 @@ export class UserActionFinder { type: CASE_USER_ACTION_SAVED_OBJECT, }), buildFilter({ - filters: [CommentType.alert], + filters: [AttachmentType.alert], field: 'payload.comment.type', operator: 'or', type: CASE_USER_ACTION_SAVED_OBJECT, @@ -159,7 +163,7 @@ export class UserActionFinder { type: CASE_USER_ACTION_SAVED_OBJECT, }), buildFilter({ - filters: [CommentType.persistableState, CommentType.externalReference], + filters: [AttachmentType.persistableState, AttachmentType.externalReference], field: 'payload.comment.type', operator: 'or', type: CASE_USER_ACTION_SAVED_OBJECT, diff --git a/x-pack/plugins/cases/server/services/user_actions/test_utils.ts b/x-pack/plugins/cases/server/services/user_actions/test_utils.ts index a2ce8d353bf19c..5e7ca3971b0c23 100644 --- a/x-pack/plugins/cases/server/services/user_actions/test_utils.ts +++ b/x-pack/plugins/cases/server/services/user_actions/test_utils.ts @@ -17,14 +17,13 @@ import type { CaseUserActionWithoutReferenceIds, ConnectorUserAction, } from '../../../common/types/domain'; -import { UserActionActions } from '../../../common/types/domain'; +import { UserActionActions, CaseSeverity, CaseStatuses } from '../../../common/types/domain'; import { CASE_COMMENT_SAVED_OBJECT, CASE_SAVED_OBJECT, CASE_USER_ACTION_SAVED_OBJECT, SECURITY_SOLUTION_OWNER, } from '../../../common/constants'; -import { CaseSeverity, CaseStatuses } from '../../../common/api'; import { CASE_REF_NAME, COMMENT_REF_NAME, diff --git a/x-pack/plugins/cases/server/services/user_actions/type_guards.ts b/x-pack/plugins/cases/server/services/user_actions/type_guards.ts index ee72239e55bceb..494550923ce8e3 100644 --- a/x-pack/plugins/cases/server/services/user_actions/type_guards.ts +++ b/x-pack/plugins/cases/server/services/user_actions/type_guards.ts @@ -6,8 +6,8 @@ */ import { isString } from 'lodash'; -import type { CaseAssignees } from '../../../common/api/cases/assignee'; -import { CaseAssigneesRt } from '../../../common/api/cases/assignee'; +import type { CaseAssignees } from '../../../common/types/domain'; +import { CaseAssigneesRt } from '../../../common/types/domain'; export const isStringArray = (value: unknown): value is string[] => { return Array.isArray(value) && value.every((val) => isString(val)); diff --git a/x-pack/plugins/cases/server/services/user_actions/types.ts b/x-pack/plugins/cases/server/services/user_actions/types.ts index d1114d3c06cf31..68e60fe6ccc0aa 100644 --- a/x-pack/plugins/cases/server/services/user_actions/types.ts +++ b/x-pack/plugins/cases/server/services/user_actions/types.ts @@ -22,17 +22,13 @@ import type { ConnectorUserAction, PushedUserAction, UserActionType, -} from '../../../common/types/domain'; -import type { CaseAssignees } from '../../../common/api/cases/assignee'; -import type { CaseAttributes, - CasePostRequest, CaseSettings, CaseSeverity, CaseStatuses, - CommentRequest, User, -} from '../../../common/api'; + CaseAssignees, +} from '../../../common/types/domain'; import type { PersistableStateAttachmentTypeRegistry } from '../../attachment_framework/persistable_state_registry'; import type { UserActionPersistedAttributes, @@ -40,7 +36,11 @@ import type { } from '../../common/types/user_actions'; import type { IndexRefresh } from '../types'; import type { CaseSavedObjectTransformed } from '../../common/types/case'; -import type { UserActionFindRequest } from '../../../common/types/api'; +import type { + AttachmentRequest, + CasePostRequest, + UserActionFindRequest, +} from '../../../common/types/api'; export interface BuilderParameters { title: { @@ -291,7 +291,7 @@ export interface BulkCreateBulkUpdateCaseUserActions extends IndexRefresh { export interface BulkCreateAttachmentUserAction extends Omit, IndexRefresh { - attachments: Array<{ id: string; owner: string; attachment: CommentRequest }>; + attachments: Array<{ id: string; owner: string; attachment: AttachmentRequest }>; } export type CreateUserActionClient = CreateUserAction & diff --git a/x-pack/plugins/cases/server/services/user_profiles/index.ts b/x-pack/plugins/cases/server/services/user_profiles/index.ts index d01d15f6fce48c..ab8a9d8cf7d5b6 100644 --- a/x-pack/plugins/cases/server/services/user_profiles/index.ts +++ b/x-pack/plugins/cases/server/services/user_profiles/index.ts @@ -14,7 +14,9 @@ import type { SpacesPluginStart } from '@kbn/spaces-plugin/server'; import { DEFAULT_SPACE_ID } from '@kbn/spaces-plugin/common'; import type { LicensingPluginStart } from '@kbn/licensing-plugin/server'; -import { SuggestUserProfilesRequestRt, decodeWithExcessOrThrow } from '../../../common/api'; +import type { SuggestUserProfilesRequest } from '../../../common/types/api'; +import { SuggestUserProfilesRequestRt } from '../../../common/types/api'; +import { decodeWithExcessOrThrow } from '../../../common/api'; import { Operations } from '../../authorization'; import { createCaseError } from '../../common/error'; import { LicensingService } from '../licensing'; @@ -69,7 +71,9 @@ export class UserProfileService { }); } - public async suggest(request: KibanaRequest): Promise { + public async suggest( + request: KibanaRequest<{}, {}, SuggestUserProfilesRequest> + ): Promise { try { const params = decodeWithExcessOrThrow(SuggestUserProfilesRequestRt)(request.body); diff --git a/x-pack/plugins/cases/tsconfig.json b/x-pack/plugins/cases/tsconfig.json index 26e61c5c923aab..059e132582d00e 100644 --- a/x-pack/plugins/cases/tsconfig.json +++ b/x-pack/plugins/cases/tsconfig.json @@ -68,6 +68,7 @@ "@kbn/core-saved-objects-api-server-mocks", "@kbn/core-theme-browser", "@kbn/serverless", + "@kbn/core-http-server", ], "exclude": [ "target/**/*", diff --git a/x-pack/plugins/exploratory_view/public/components/shared/exploratory_view/hooks/use_add_to_case.ts b/x-pack/plugins/exploratory_view/public/components/shared/exploratory_view/hooks/use_add_to_case.ts index dace0ed9a18a3c..db3bf515eb7088 100644 --- a/x-pack/plugins/exploratory_view/public/components/shared/exploratory_view/hooks/use_add_to_case.ts +++ b/x-pack/plugins/exploratory_view/public/components/shared/exploratory_view/hooks/use_add_to_case.ts @@ -8,7 +8,7 @@ import { useCallback, useState } from 'react'; import { i18n } from '@kbn/i18n'; import { HttpSetup, MountPoint } from '@kbn/core/public'; -import { CaseUI, CommentType } from '@kbn/cases-plugin/common'; +import { CaseUI, AttachmentType } from '@kbn/cases-plugin/common'; import { TypedLensByValueInput } from '@kbn/lens-plugin/public'; import { CasesDeepLinkId, DRAFT_COMMENT_STORAGE_ID } from '@kbn/cases-plugin/public'; import { observabilityFeatureId } from '@kbn/observability-shared-plugin/public'; @@ -29,7 +29,7 @@ async function addToCase( const payload = { persistableStateAttachmentState: { attributes, timeRange }, persistableStateAttachmentTypeId: LENS_ATTACHMENT_TYPE, - type: CommentType.persistableState, + type: AttachmentType.persistableState, owner: owner ?? observabilityFeatureId, }; diff --git a/x-pack/plugins/ml/public/application/contexts/kibana/use_cases_modal.ts b/x-pack/plugins/ml/public/application/contexts/kibana/use_cases_modal.ts index 7a26cd6e62ceba..c6142e715bad7a 100644 --- a/x-pack/plugins/ml/public/application/contexts/kibana/use_cases_modal.ts +++ b/x-pack/plugins/ml/public/application/contexts/kibana/use_cases_modal.ts @@ -7,7 +7,7 @@ import { useCallback } from 'react'; import { stringHash } from '@kbn/ml-string-hash'; -import { CommentType } from '@kbn/cases-plugin/common'; +import { AttachmentType } from '@kbn/cases-plugin/common'; import { useMlKibana } from './kibana_context'; import type { MappedEmbeddableTypeOf, MlEmbeddableTypes } from '../../../embeddables'; @@ -38,7 +38,7 @@ export const useCasesModal = ( selectCaseModal.open({ getAttachments: () => [ { - type: CommentType.persistableState, + type: AttachmentType.persistableState, persistableStateAttachmentTypeId: embeddableType, // TODO Cases: improve type for persistableStateAttachmentState with io-ts persistableStateAttachmentState: JSON.parse( diff --git a/x-pack/plugins/observability/public/pages/alert_details/components/header_actions.tsx b/x-pack/plugins/observability/public/pages/alert_details/components/header_actions.tsx index d603793528a8b9..edb2a1cb03c998 100644 --- a/x-pack/plugins/observability/public/pages/alert_details/components/header_actions.tsx +++ b/x-pack/plugins/observability/public/pages/alert_details/components/header_actions.tsx @@ -9,7 +9,7 @@ import React, { useState } from 'react'; import { i18n } from '@kbn/i18n'; import { noop } from 'lodash'; import { CaseAttachmentsWithoutOwner } from '@kbn/cases-plugin/public/types'; -import { CommentType } from '@kbn/cases-plugin/common'; +import { AttachmentType } from '@kbn/cases-plugin/common'; import { EuiButton, EuiButtonEmpty, EuiFlexGroup, EuiPopover, EuiText } from '@elastic/eui'; import { ALERT_RULE_UUID, ALERT_UUID } from '@kbn/rule-data-utils'; @@ -52,7 +52,7 @@ export function HeaderActions({ alert }: HeaderActionsProps) { id: rule.id, name: rule.name, }, - type: CommentType.alert, + type: AttachmentType.alert, }, ] : []; diff --git a/x-pack/plugins/observability/public/pages/alerts/components/alert_actions.tsx b/x-pack/plugins/observability/public/pages/alerts/components/alert_actions.tsx index ad2d37e125cc4f..11a8e21987ea7d 100644 --- a/x-pack/plugins/observability/public/pages/alerts/components/alert_actions.tsx +++ b/x-pack/plugins/observability/public/pages/alerts/components/alert_actions.tsx @@ -17,7 +17,7 @@ import { import React, { useMemo, useState, useCallback } from 'react'; import { i18n } from '@kbn/i18n'; import { CaseAttachmentsWithoutOwner } from '@kbn/cases-plugin/public'; -import { CommentType } from '@kbn/cases-plugin/common'; +import { AttachmentType } from '@kbn/cases-plugin/common'; import { EcsSecurityExtension as Ecs } from '@kbn/securitysolution-ecs'; import { TimelineNonEcsData } from '@kbn/timelines-plugin/common'; @@ -94,7 +94,7 @@ export function AlertActions({ { alertId: ecsData?._id ?? '', index: ecsData?._index ?? '', - type: CommentType.alert, + type: AttachmentType.alert, rule: getRuleIdFromEvent({ ecs: ecsData, data: data ?? [] }), }, ] diff --git a/x-pack/plugins/osquery/public/cases/add_to_cases_button.tsx b/x-pack/plugins/osquery/public/cases/add_to_cases_button.tsx index 4ecb2d4ebc45e2..44f357f3df0437 100644 --- a/x-pack/plugins/osquery/public/cases/add_to_cases_button.tsx +++ b/x-pack/plugins/osquery/public/cases/add_to_cases_button.tsx @@ -6,7 +6,7 @@ */ import React, { useCallback, useContext, useMemo } from 'react'; -import { CommentType, ExternalReferenceStorageType } from '@kbn/cases-plugin/common'; +import { AttachmentType, ExternalReferenceStorageType } from '@kbn/cases-plugin/common'; import { EuiButtonEmpty, EuiButtonIcon, EuiFlexItem, EuiToolTip } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; import type { CaseAttachmentsWithoutOwner } from '@kbn/cases-plugin/public'; @@ -50,7 +50,7 @@ export const AddToCaseButton: React.FC = ({ ecs: ecsData, data: [], }), - type: CommentType.alert as const, + type: AttachmentType.alert as const, }, ] : [], @@ -66,7 +66,7 @@ export const AddToCaseButton: React.FC = ({ const attachments: CaseAttachmentsWithoutOwner = [ ...alertAttachments, { - type: CommentType.externalReference, + type: AttachmentType.externalReference, externalReferenceId: actionId, externalReferenceStorage: { type: ExternalReferenceStorageType.elasticSearchDoc, diff --git a/x-pack/plugins/security_solution/common/endpoint/data_loaders/index_case.ts b/x-pack/plugins/security_solution/common/endpoint/data_loaders/index_case.ts index ed7e70e6e5207c..34c9c2fbc83afb 100644 --- a/x-pack/plugins/security_solution/common/endpoint/data_loaders/index_case.ts +++ b/x-pack/plugins/security_solution/common/endpoint/data_loaders/index_case.ts @@ -6,10 +6,8 @@ */ import type { KbnClient } from '@kbn/test'; -import type { Case } from '@kbn/cases-plugin/common'; -import { CASES_URL, ConnectorTypes } from '@kbn/cases-plugin/common'; -import type { CasePostRequest } from '@kbn/cases-plugin/common/api'; -import { CaseSeverity } from '@kbn/cases-plugin/common/api'; +import type { Case, CasePostRequest } from '@kbn/cases-plugin/common'; +import { CaseSeverity, CASES_URL, ConnectorTypes } from '@kbn/cases-plugin/common'; import type { AxiosError } from 'axios'; import { EndpointError } from '../errors'; diff --git a/x-pack/plugins/security_solution/cypress/objects/case.ts b/x-pack/plugins/security_solution/cypress/objects/case.ts index 1464da98b733fb..2abdce5fb068cc 100644 --- a/x-pack/plugins/security_solution/cypress/objects/case.ts +++ b/x-pack/plugins/security_solution/cypress/objects/case.ts @@ -4,8 +4,9 @@ * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ +import { CaseStatuses } from '@kbn/cases-components'; import type { Case } from '@kbn/cases-plugin/common'; -import { CaseStatuses, CaseSeverity, ConnectorTypes } from '@kbn/cases-plugin/common'; +import { CaseSeverity, ConnectorTypes } from '@kbn/cases-plugin/common'; import { flatten } from 'lodash'; import type { CompleteTimeline } from './timeline'; import { getTimeline } from './timeline'; diff --git a/x-pack/plugins/security_solution/cypress/tsconfig.json b/x-pack/plugins/security_solution/cypress/tsconfig.json index eaf2dbbe9c4af4..7d674e03fcf4ce 100644 --- a/x-pack/plugins/security_solution/cypress/tsconfig.json +++ b/x-pack/plugins/security_solution/cypress/tsconfig.json @@ -41,5 +41,6 @@ "@kbn/test", "@kbn/tooling-log", "@kbn/fleet-plugin", + "@kbn/cases-components", ] } diff --git a/x-pack/plugins/security_solution/public/assistant/comment_actions/index.tsx b/x-pack/plugins/security_solution/public/assistant/comment_actions/index.tsx index a67a728c2949b9..b7cac488319dc2 100644 --- a/x-pack/plugins/security_solution/public/assistant/comment_actions/index.tsx +++ b/x-pack/plugins/security_solution/public/assistant/comment_actions/index.tsx @@ -6,7 +6,7 @@ */ import { EuiButtonIcon, EuiCopy, EuiFlexGroup, EuiFlexItem, EuiToolTip } from '@elastic/eui'; -import { CommentType } from '@kbn/cases-plugin/common'; +import { AttachmentType } from '@kbn/cases-plugin/common'; import type { Message } from '@kbn/elastic-assistant'; import React, { useCallback } from 'react'; import { useDispatch } from 'react-redux'; @@ -66,7 +66,7 @@ const CommentActionsComponent: React.FC = ({ message }) => { getAttachments: () => [ { comment: message.content, - type: CommentType.user, + type: AttachmentType.user, owner: i18n.ELASTIC_AI_ASSISTANT, }, ], diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/use_add_to_existing_case.test.tsx b/x-pack/plugins/security_solution/public/common/components/visualization_actions/use_add_to_existing_case.test.tsx index 6eb0dd3f2fc6c3..6118bc44414200 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/use_add_to_existing_case.test.tsx +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/use_add_to_existing_case.test.tsx @@ -14,7 +14,7 @@ import { readCasesPermissions, writeCasesPermissions, } from '../../../cases_test_utils'; -import { CommentType } from '@kbn/cases-plugin/common'; +import { AttachmentType } from '@kbn/cases-plugin/common'; const mockedUseKibana = mockUseKibana(); const mockGetUseCasesAddToExistingCaseModal = jest.fn(); @@ -139,7 +139,7 @@ describe('useAddToExistingCase', () => { timeRange, }, persistableStateAttachmentTypeId: '.lens', - type: CommentType.persistableState as const, + type: AttachmentType.persistableState as const, }, ]); expect(mockClick).toHaveBeenCalled(); diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/use_add_to_existing_case.tsx b/x-pack/plugins/security_solution/public/common/components/visualization_actions/use_add_to_existing_case.tsx index 9fb48a0fdbfe10..9a9c239c65e910 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/use_add_to_existing_case.tsx +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/use_add_to_existing_case.tsx @@ -5,7 +5,7 @@ * 2.0. */ import { useCallback, useMemo } from 'react'; -import { CommentType, LENS_ATTACHMENT_TYPE } from '@kbn/cases-plugin/common'; +import { AttachmentType, LENS_ATTACHMENT_TYPE } from '@kbn/cases-plugin/common'; import type { CaseAttachmentsWithoutOwner } from '@kbn/cases-plugin/public'; import { useKibana, useGetUserCasesPermissions } from '../../lib/kibana'; @@ -28,7 +28,7 @@ export const useAddToExistingCase = ({ { persistableStateAttachmentState: { attributes: lensAttributes, timeRange }, persistableStateAttachmentTypeId: LENS_ATTACHMENT_TYPE, - type: CommentType.persistableState as const, + type: AttachmentType.persistableState as const, }, ] as CaseAttachmentsWithoutOwner; }, [lensAttributes, timeRange]); diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/use_add_to_new_case.test.tsx b/x-pack/plugins/security_solution/public/common/components/visualization_actions/use_add_to_new_case.test.tsx index baffe5a10e522b..29969d489a038c 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/use_add_to_new_case.test.tsx +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/use_add_to_new_case.test.tsx @@ -14,7 +14,7 @@ import { readCasesPermissions, writeCasesPermissions, } from '../../../cases_test_utils'; -import { CommentType } from '@kbn/cases-plugin/common'; +import { AttachmentType } from '@kbn/cases-plugin/common'; jest.mock('../../lib/kibana/kibana_react'); @@ -128,7 +128,7 @@ describe('useAddToNewCase', () => { { persistableStateAttachmentState: { attributes: kpiHostMetricLensAttributes, timeRange }, persistableStateAttachmentTypeId: '.lens', - type: CommentType.persistableState as const, + type: AttachmentType.persistableState as const, }, ], }); diff --git a/x-pack/plugins/security_solution/public/common/components/visualization_actions/use_add_to_new_case.tsx b/x-pack/plugins/security_solution/public/common/components/visualization_actions/use_add_to_new_case.tsx index cf393a99a17420..6a395af34b445c 100644 --- a/x-pack/plugins/security_solution/public/common/components/visualization_actions/use_add_to_new_case.tsx +++ b/x-pack/plugins/security_solution/public/common/components/visualization_actions/use_add_to_new_case.tsx @@ -5,7 +5,7 @@ * 2.0. */ import { useCallback, useMemo } from 'react'; -import { CommentType, LENS_ATTACHMENT_TYPE } from '@kbn/cases-plugin/common'; +import { AttachmentType, LENS_ATTACHMENT_TYPE } from '@kbn/cases-plugin/common'; import type { CaseAttachmentsWithoutOwner } from '@kbn/cases-plugin/public'; import { useKibana, useGetUserCasesPermissions } from '../../lib/kibana'; @@ -27,7 +27,7 @@ export const useAddToNewCase = ({ onClick, timeRange, lensAttributes }: UseAddTo { persistableStateAttachmentState: { attributes: lensAttributes, timeRange }, persistableStateAttachmentTypeId: LENS_ATTACHMENT_TYPE, - type: CommentType.persistableState as const, + type: AttachmentType.persistableState as const, }, ] as CaseAttachmentsWithoutOwner; }, [lensAttributes, timeRange]); diff --git a/x-pack/plugins/security_solution/public/common/containers/cases/use_get_related_cases_by_event.ts b/x-pack/plugins/security_solution/public/common/containers/cases/use_get_related_cases_by_event.ts index 9f639d9d030427..fe20d4670f3a79 100644 --- a/x-pack/plugins/security_solution/public/common/containers/cases/use_get_related_cases_by_event.ts +++ b/x-pack/plugins/security_solution/public/common/containers/cases/use_get_related_cases_by_event.ts @@ -6,7 +6,7 @@ */ import { useCallback, useState, useEffect } from 'react'; -import type { RelatedCaseInfo } from '@kbn/cases-plugin/common/api'; +import type { RelatedCase } from '@kbn/cases-plugin/common'; import { useKibana, useToasts } from '../../lib/kibana'; import { CASES_ERROR_TOAST } from '../../components/event_details/insights/translations'; import { APP_ID } from '../../../../common/constants'; @@ -17,13 +17,13 @@ export const useGetRelatedCasesByEvent = (eventId: string) => { } = useKibana(); const toasts = useToasts(); - const [relatedCases, setRelatedCases] = useState(undefined); + const [relatedCases, setRelatedCases] = useState(undefined); const [loading, setLoading] = useState(false); const [error, setError] = useState(null); const getRelatedCases = useCallback(async () => { setLoading(true); - let relatedCasesResponse: RelatedCaseInfo[] = []; + let relatedCasesResponse: RelatedCase[] = []; try { if (eventId) { relatedCasesResponse = diff --git a/x-pack/plugins/security_solution/public/common/lib/kibana/hooks.ts b/x-pack/plugins/security_solution/public/common/lib/kibana/hooks.ts index 2be0e0c3db71e2..1713f35a9a2d2c 100644 --- a/x-pack/plugins/security_solution/public/common/lib/kibana/hooks.ts +++ b/x-pack/plugins/security_solution/public/common/lib/kibana/hooks.ts @@ -14,7 +14,7 @@ import { camelCase, isArray, isObject } from 'lodash'; import { set } from '@kbn/safer-lodash-set'; import type { AuthenticatedUser } from '@kbn/security-plugin/common/model'; import type { Capabilities } from '@kbn/core/public'; -import type { CasesPermissions } from '@kbn/cases-plugin/common/ui'; +import type { CasesPermissions } from '@kbn/cases-plugin/common'; import { useGetAppUrl, useNavigateTo, diff --git a/x-pack/plugins/security_solution/public/detections/components/alerts_table/timeline_actions/use_add_to_case_actions.tsx b/x-pack/plugins/security_solution/public/detections/components/alerts_table/timeline_actions/use_add_to_case_actions.tsx index ea781bf47ab0e0..50e1e11268e5e6 100644 --- a/x-pack/plugins/security_solution/public/detections/components/alerts_table/timeline_actions/use_add_to_case_actions.tsx +++ b/x-pack/plugins/security_solution/public/detections/components/alerts_table/timeline_actions/use_add_to_case_actions.tsx @@ -6,7 +6,7 @@ */ import React, { useCallback, useMemo } from 'react'; -import { CommentType } from '@kbn/cases-plugin/common'; +import { AttachmentType } from '@kbn/cases-plugin/common'; import type { CaseAttachmentsWithoutOwner } from '@kbn/cases-plugin/public'; import type { EcsSecurityExtension as Ecs } from '@kbn/securitysolution-ecs'; import { CasesTourSteps } from '../../../../common/components/guided_onboarding_tour/cases_tour_steps'; @@ -55,7 +55,7 @@ export const useAddToCaseActions = ({ { alertId: ecsData?._id ?? '', index: ecsData?._index ?? '', - type: CommentType.alert, + type: AttachmentType.alert, rule: casesUi.helpers.getRuleIdFromEvent({ ecs: ecsData, data: nonEcsData ?? [] }), }, ] diff --git a/x-pack/plugins/security_solution/public/detections/pages/alert_details/tabs/summary/cases_panel/cases_panel.test.tsx b/x-pack/plugins/security_solution/public/detections/pages/alert_details/tabs/summary/cases_panel/cases_panel.test.tsx index 4bb62e948747af..32905019eb3f8b 100644 --- a/x-pack/plugins/security_solution/public/detections/pages/alert_details/tabs/summary/cases_panel/cases_panel.test.tsx +++ b/x-pack/plugins/security_solution/public/detections/pages/alert_details/tabs/summary/cases_panel/cases_panel.test.tsx @@ -7,8 +7,7 @@ import React from 'react'; import { render } from '@testing-library/react'; -import type { RelatedCaseInfo } from '@kbn/cases-plugin/common/api'; -import { CaseStatuses } from '@kbn/cases-plugin/common/api'; +import type { RelatedCase } from '@kbn/cases-plugin/common'; import { CasesPanel, CASES_PANEL_CASES_COUNT_MAX } from '.'; import { TestProviders } from '../../../../../../common/mock'; import { @@ -18,6 +17,7 @@ import { import { ERROR_LOADING_CASES, LOADING_CASES } from '../translation'; import { useGetRelatedCasesByEvent } from '../../../../../../common/containers/cases/use_get_related_cases_by_event'; import { useGetUserCasesPermissions } from '../../../../../../common/lib/kibana'; +import { CaseStatuses } from '@kbn/cases-components'; jest.mock('../../../../../../common/containers/cases/use_get_related_cases_by_event'); jest.mock('../../../../../../common/lib/kibana'); @@ -137,7 +137,7 @@ describe('AlertDetailsPage - SummaryTab - CasesPanel', () => { }); }); describe('has a single related cases', () => { - const mockRelatedCase: RelatedCaseInfo = { + const mockRelatedCase: RelatedCase = { createdAt: '2022-11-04T17:22:13.267Z', title: 'test case', description: 'Test case description', @@ -174,7 +174,7 @@ describe('AlertDetailsPage - SummaryTab - CasesPanel', () => { }); }); describe(`has more than ${CASES_PANEL_CASES_COUNT_MAX} related cases`, () => { - const mockRelatedCase: RelatedCaseInfo = { + const mockRelatedCase: RelatedCase = { createdAt: '2022-11-04T17:22:13.267Z', title: 'test case', description: 'Test case description', diff --git a/x-pack/plugins/security_solution/public/detections/pages/alert_details/tabs/summary/cases_panel/index.tsx b/x-pack/plugins/security_solution/public/detections/pages/alert_details/tabs/summary/cases_panel/index.tsx index 1aa989a931ad12..72b469780097bd 100644 --- a/x-pack/plugins/security_solution/public/detections/pages/alert_details/tabs/summary/cases_panel/index.tsx +++ b/x-pack/plugins/security_solution/public/detections/pages/alert_details/tabs/summary/cases_panel/index.tsx @@ -14,7 +14,7 @@ import { EuiLoadingSpinner, } from '@elastic/eui'; import type { Ecs } from '@kbn/cases-plugin/common'; -import { CommentType } from '@kbn/cases-plugin/common'; +import { AttachmentType } from '@kbn/cases-plugin/common'; import type { CaseAttachmentsWithoutOwner } from '@kbn/cases-plugin/public'; import styled from 'styled-components'; import type { TimelineEventsDetailsItem } from '../../../../../../../common/search_strategy'; @@ -76,7 +76,7 @@ export const CasesPanel = React.memo( { alertId: eventId, index: dataAsNestedObject._index ?? '', - type: CommentType.alert, + type: AttachmentType.alert, rule: casesUi.helpers.getRuleIdFromEvent({ ecs: dataAsNestedObject, data: detailsData, diff --git a/x-pack/plugins/security_solution/public/detections/pages/alert_details/tabs/summary/cases_panel/related_case.tsx b/x-pack/plugins/security_solution/public/detections/pages/alert_details/tabs/summary/cases_panel/related_case.tsx index ad3ef969a7a680..ef55a3d158a837 100644 --- a/x-pack/plugins/security_solution/public/detections/pages/alert_details/tabs/summary/cases_panel/related_case.tsx +++ b/x-pack/plugins/security_solution/public/detections/pages/alert_details/tabs/summary/cases_panel/related_case.tsx @@ -7,7 +7,7 @@ import { EuiFlexGroup, EuiFlexItem, EuiSpacer, EuiIcon, EuiText } from '@elastic/eui'; import { Status } from '@kbn/cases-components'; -import type { RelatedCaseInfo } from '@kbn/cases-plugin/common/api'; +import type { RelatedCase } from '@kbn/cases-plugin/common'; import React, { useMemo } from 'react'; import styled from 'styled-components'; import { CaseDetailsLink } from '../../../../../../common/components/links'; @@ -38,7 +38,7 @@ export const RelatedCasesList = ({ relatedCases, maximumVisible, }: { - relatedCases: RelatedCaseInfo[]; + relatedCases: RelatedCase[]; maximumVisible?: number; }) => { // Sort related cases, showing the most recently created first. diff --git a/x-pack/plugins/security_solution/public/flyout/left/components/correlations_cases_table.test.tsx b/x-pack/plugins/security_solution/public/flyout/left/components/correlations_cases_table.test.tsx index 7b13204e11c9dc..629fd02072c9ce 100644 --- a/x-pack/plugins/security_solution/public/flyout/left/components/correlations_cases_table.test.tsx +++ b/x-pack/plugins/security_solution/public/flyout/left/components/correlations_cases_table.test.tsx @@ -13,7 +13,8 @@ import { CorrelationsCasesTable, type CorrelationsCasesTableProps, } from './correlations_cases_table'; -import { CaseStatuses, type RelatedCaseInfo } from '@kbn/cases-plugin/common/api'; +import type { RelatedCase } from '@kbn/cases-plugin/common'; +import { CaseStatuses } from '@kbn/cases-components'; jest.mock('../../../common/components/links', () => ({ CaseDetailsLink: jest @@ -21,7 +22,7 @@ jest.mock('../../../common/components/links', () => ({ .mockImplementation(({ title }) => <>{``}), })); -const cases: RelatedCaseInfo[] = [ +const cases: RelatedCase[] = [ { id: 'case-1', title: 'Case 1', diff --git a/x-pack/plugins/security_solution/public/flyout/left/components/correlations_cases_table.tsx b/x-pack/plugins/security_solution/public/flyout/left/components/correlations_cases_table.tsx index 4079a55a798b58..993239ce45d7ed 100644 --- a/x-pack/plugins/security_solution/public/flyout/left/components/correlations_cases_table.tsx +++ b/x-pack/plugins/security_solution/public/flyout/left/components/correlations_cases_table.tsx @@ -6,22 +6,22 @@ */ import { type EuiBasicTableColumn, EuiInMemoryTable } from '@elastic/eui'; -import type { RelatedCaseInfo } from '@kbn/cases-plugin/common/api'; +import type { RelatedCase } from '@kbn/cases-plugin/common'; import React, { type FC } from 'react'; import { CaseDetailsLink } from '../../../common/components/links'; import * as i18n from './translations'; export interface CorrelationsCasesTableProps { - cases: RelatedCaseInfo[]; + cases: RelatedCase[]; } -const columns: Array> = [ +const columns: Array> = [ { field: 'title', name: i18n.CORRELATIONS_CASE_NAME_COLUMN_TITLE, truncateText: true, - render: (value: string, caseData: RelatedCaseInfo) => ( + render: (value: string, caseData: RelatedCase) => ( {caseData.title} diff --git a/x-pack/plugins/security_solution/public/flyout/left/components/correlations_details.test.tsx b/x-pack/plugins/security_solution/public/flyout/left/components/correlations_details.test.tsx index ceb2d5cfba5dbc..ee641e5c691843 100644 --- a/x-pack/plugins/security_solution/public/flyout/left/components/correlations_details.test.tsx +++ b/x-pack/plugins/security_solution/public/flyout/left/components/correlations_details.test.tsx @@ -11,16 +11,17 @@ import { useTimelineEventsDetails } from '../../../timelines/containers/details' import { useSourcererDataView } from '../../../common/containers/sourcerer'; import { useCorrelations, type UseCorrelationsResult } from '../../shared/hooks/use_correlations'; import { CorrelationsDetails } from './correlations_details'; -import { type CasesByAlertId, CaseStatuses } from '@kbn/cases-plugin/common/api'; +import { type GetRelatedCasesByAlertResponse } from '@kbn/cases-plugin/common'; import type { SelectedDataView } from '../../../common/store/sourcerer/model'; import { TestProviders } from '../../../common/mock'; import { LeftPanelContext } from '../context'; +import { CaseStatuses } from '@kbn/cases-components'; jest.mock('../../../timelines/containers/details'); jest.mock('../../../common/containers/sourcerer'); jest.mock('../../shared/hooks/use_correlations'); -const mockCasesByAlertId: CasesByAlertId = [ +const mockCasesByAlertId: GetRelatedCasesByAlertResponse = [ { id: '123', title: 'Mock Case', diff --git a/x-pack/plugins/security_solution/public/flyout/shared/hooks/use_correlations.ts b/x-pack/plugins/security_solution/public/flyout/shared/hooks/use_correlations.ts index d65a220b9a5801..24f328d059d54b 100644 --- a/x-pack/plugins/security_solution/public/flyout/shared/hooks/use_correlations.ts +++ b/x-pack/plugins/security_solution/public/flyout/shared/hooks/use_correlations.ts @@ -8,7 +8,7 @@ import type { TimelineEventsDetailsItem } from '@kbn/timelines-plugin/common'; import type { EcsSecurityExtension as Ecs } from '@kbn/securitysolution-ecs'; import { useEffect, useMemo, useReducer } from 'react'; -import type { CasesByAlertId } from '@kbn/cases-plugin/common/api'; +import type { GetRelatedCasesByAlertResponse } from '@kbn/cases-plugin/common'; import { useFetchRelatedAlertsBySameSourceEvent } from './use_fetch_related_alerts_by_same_source_event'; import { useShowRelatedCases } from './use_show_related_cases'; import { useFetchRelatedCases } from './use_fetch_related_cases'; @@ -84,7 +84,7 @@ export interface UseCorrelationsResult { /** * Cases data, can be used to render correlated cases table */ - cases: CasesByAlertId; + cases: GetRelatedCasesByAlertResponse; } /** diff --git a/x-pack/plugins/security_solution/public/flyout/shared/hooks/use_fetch_related_cases.ts b/x-pack/plugins/security_solution/public/flyout/shared/hooks/use_fetch_related_cases.ts index 426a845f44a8dc..7100f20cf22189 100644 --- a/x-pack/plugins/security_solution/public/flyout/shared/hooks/use_fetch_related_cases.ts +++ b/x-pack/plugins/security_solution/public/flyout/shared/hooks/use_fetch_related_cases.ts @@ -6,7 +6,7 @@ */ import { useQuery } from '@tanstack/react-query'; -import type { CasesByAlertId } from '@kbn/cases-plugin/common/api'; +import type { GetRelatedCasesByAlertResponse } from '@kbn/cases-plugin/common'; import { useMemo } from 'react'; import { useKibana } from '../../../common/lib/kibana'; import { APP_ID } from '../../../../common/constants'; @@ -32,7 +32,7 @@ export interface UseFetchRelatedCasesResult { /** * Cases data retrieved */ - data: CasesByAlertId; + data: GetRelatedCasesByAlertResponse; /** * Number of data entries received */ @@ -48,7 +48,7 @@ export const useFetchRelatedCases = ({ const { services: { cases }, } = useKibana(); - const { data, isLoading, isError } = useQuery( + const { data, isLoading, isError } = useQuery( [QUERY_KEY, eventId], () => cases.api.getRelatedCases(eventId, { diff --git a/x-pack/plugins/security_solution/public/management/cypress/support/data_loaders.ts b/x-pack/plugins/security_solution/public/management/cypress/support/data_loaders.ts index f54c780ab51136..78cb60cc7bcbb2 100644 --- a/x-pack/plugins/security_solution/public/management/cypress/support/data_loaders.ts +++ b/x-pack/plugins/security_solution/public/management/cypress/support/data_loaders.ts @@ -7,7 +7,7 @@ // / -import type { CasePostRequest } from '@kbn/cases-plugin/common/api'; +import type { CasePostRequest } from '@kbn/cases-plugin/common'; import execa from 'execa'; import { startRuntimeServices } from '../../../../scripts/endpoint/endpoint_agent_runner/runtime'; import { runFleetServerIfNeeded } from '../../../../scripts/endpoint/endpoint_agent_runner/fleet_server'; diff --git a/x-pack/plugins/security_solution/public/management/cypress/tasks/add_alerts_to_case.ts b/x-pack/plugins/security_solution/public/management/cypress/tasks/add_alerts_to_case.ts index c8aec4a252d33b..171f2e9d6d6980 100644 --- a/x-pack/plugins/security_solution/public/management/cypress/tasks/add_alerts_to_case.ts +++ b/x-pack/plugins/security_solution/public/management/cypress/tasks/add_alerts_to_case.ts @@ -5,9 +5,11 @@ * 2.0. */ -import { getCaseFindUserActionsUrl } from '@kbn/cases-plugin/common/api'; -import { INTERNAL_BULK_CREATE_ATTACHMENTS_URL } from '@kbn/cases-plugin/common/constants'; -import type { UserActionFindResponse } from '@kbn/cases-plugin/common/types/api'; +import { + INTERNAL_BULK_CREATE_ATTACHMENTS_URL, + getCaseFindUserActionsUrl, +} from '@kbn/cases-plugin/common'; +import type { UserActionFindResponse } from '@kbn/cases-plugin/common'; import { ELASTIC_SECURITY_RULE_ID } from '../../../../common'; import { resolvePathVariables } from '../../../common/utils/resolve_path_variables'; import { DEFAULT_ALERTS_INDEX, DETECTION_ENGINE_RULES_URL } from '../../../../common/constants'; diff --git a/x-pack/plugins/security_solution/public/overview/components/detection_response/cases_by_status/use_cases_by_status.tsx b/x-pack/plugins/security_solution/public/overview/components/detection_response/cases_by_status/use_cases_by_status.tsx index fa6e227cbbf120..93b755f7108795 100644 --- a/x-pack/plugins/security_solution/public/overview/components/detection_response/cases_by_status/use_cases_by_status.tsx +++ b/x-pack/plugins/security_solution/public/overview/components/detection_response/cases_by_status/use_cases_by_status.tsx @@ -5,7 +5,7 @@ * 2.0. */ -import type { CasesStatus } from '@kbn/cases-plugin/common/ui'; +import type { CasesStatus } from '@kbn/cases-plugin/common'; import { useState, useEffect, useMemo } from 'react'; import { v4 as uuidv4 } from 'uuid'; import { APP_ID } from '../../../../../common/constants'; diff --git a/x-pack/plugins/security_solution/public/overview/components/detection_response/cases_table/cases_table.tsx b/x-pack/plugins/security_solution/public/overview/components/detection_response/cases_table/cases_table.tsx index 5cea6eba489300..a3b84aeadee41c 100644 --- a/x-pack/plugins/security_solution/public/overview/components/detection_response/cases_table/cases_table.tsx +++ b/x-pack/plugins/security_solution/public/overview/components/detection_response/cases_table/cases_table.tsx @@ -17,7 +17,7 @@ import { EuiText, EuiToolTip, } from '@elastic/eui'; -import type { CaseStatuses } from '@kbn/cases-plugin/common'; +import type { CaseStatuses } from '@kbn/cases-components'; import { SecurityPageName } from '../../../../app/types'; import { FormattedDate } from '../../../../common/components/formatted_date'; diff --git a/x-pack/plugins/security_solution/public/overview/components/detection_response/cases_table/mock_data.ts b/x-pack/plugins/security_solution/public/overview/components/detection_response/cases_table/mock_data.ts index 14ab6eaa4da8b8..56430ec83691de 100644 --- a/x-pack/plugins/security_solution/public/overview/components/detection_response/cases_table/mock_data.ts +++ b/x-pack/plugins/security_solution/public/overview/components/detection_response/cases_table/mock_data.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { CaseStatuses } from '@kbn/cases-plugin/common'; +import { CaseStatuses } from '@kbn/cases-components'; export const mockCasesResult = { cases: [ diff --git a/x-pack/plugins/security_solution/public/overview/components/detection_response/cases_table/status_badge.tsx b/x-pack/plugins/security_solution/public/overview/components/detection_response/cases_table/status_badge.tsx index 9ae1281d9e6e71..ba3e51d17383c4 100644 --- a/x-pack/plugins/security_solution/public/overview/components/detection_response/cases_table/status_badge.tsx +++ b/x-pack/plugins/security_solution/public/overview/components/detection_response/cases_table/status_badge.tsx @@ -7,7 +7,7 @@ import React from 'react'; -import { CaseStatuses } from '@kbn/cases-plugin/common'; +import { CaseStatuses } from '@kbn/cases-components'; import { EuiBadge } from '@elastic/eui'; import * as i18n from '../translations'; diff --git a/x-pack/plugins/security_solution/public/overview/components/detection_response/cases_table/use_case_items.ts b/x-pack/plugins/security_solution/public/overview/components/detection_response/cases_table/use_case_items.ts index a872172feba0b7..7c25b024eb8dae 100644 --- a/x-pack/plugins/security_solution/public/overview/components/detection_response/cases_table/use_case_items.ts +++ b/x-pack/plugins/security_solution/public/overview/components/detection_response/cases_table/use_case_items.ts @@ -7,9 +7,10 @@ import { useState, useEffect, useMemo } from 'react'; -import type { CaseStatuses, CasesFindResponseUI } from '@kbn/cases-plugin/common'; +import type { CasesFindResponseUI } from '@kbn/cases-plugin/common'; import { v4 as uuidv4 } from 'uuid'; +import type { CaseStatuses } from '@kbn/cases-components'; import { APP_ID } from '../../../../../common/constants'; import { useGlobalTime } from '../../../../common/containers/use_global_time'; import { useKibana } from '../../../../common/lib/kibana'; diff --git a/x-pack/plugins/security_solution/public/overview/pages/data_quality.tsx b/x-pack/plugins/security_solution/public/overview/pages/data_quality.tsx index cd0b0a68c1ad17..248142e7827b37 100644 --- a/x-pack/plugins/security_solution/public/overview/pages/data_quality.tsx +++ b/x-pack/plugins/security_solution/public/overview/pages/data_quality.tsx @@ -5,7 +5,7 @@ * 2.0. */ -import { CommentType } from '@kbn/cases-plugin/common'; +import { AttachmentType } from '@kbn/cases-plugin/common'; import { DataQualityPanel, DATA_QUALITY_SUBTITLE, @@ -193,10 +193,10 @@ const DataQualityComponent: React.FC = () => { ({ comments, headerContent }: { comments: string[]; headerContent?: React.ReactNode }) => { const attachments: Array<{ comment: string; - type: CommentType.user; + type: AttachmentType.user; }> = comments.map((x) => ({ comment: x, - type: CommentType.user, + type: AttachmentType.user, })); createCaseFlyout.open({ attachments, headerContent }); diff --git a/x-pack/plugins/security_solution/server/endpoint/services/actions/create/update_cases.ts b/x-pack/plugins/security_solution/server/endpoint/services/actions/create/update_cases.ts index 7744199d456758..7dd7cd75a63045 100644 --- a/x-pack/plugins/security_solution/server/endpoint/services/actions/create/update_cases.ts +++ b/x-pack/plugins/security_solution/server/endpoint/services/actions/create/update_cases.ts @@ -5,8 +5,8 @@ * 2.0. */ -import type { CasesByAlertId } from '@kbn/cases-plugin/common/api'; -import { CommentType } from '@kbn/cases-plugin/common/api'; +import type { GetRelatedCasesByAlertResponse } from '@kbn/cases-plugin/common'; +import { AttachmentType } from '@kbn/cases-plugin/common'; import type { CasesClient } from '@kbn/cases-plugin/server'; import type { BulkCreateArgs } from '@kbn/cases-plugin/server/client/attachments/types'; import { APP_ID } from '../../../../../common'; @@ -34,7 +34,7 @@ export const updateCases = async ({ if (createActionPayload.alert_ids && createActionPayload.alert_ids.length > 0) { const newIDs: string[][] = await Promise.all( createActionPayload.alert_ids.map(async (alertID: string) => { - const cases: CasesByAlertId = await casesClient.cases.getCasesByAlertID({ + const cases: GetRelatedCasesByAlertResponse = await casesClient.cases.getCasesByAlertID({ alertID, options: { owner: APP_ID }, }); @@ -55,7 +55,7 @@ export const updateCases = async ({ })); const attachments = caseIDs.map(() => ({ - type: CommentType.actions, + type: AttachmentType.actions, comment: createActionPayload.comment || '', actions: { targets, diff --git a/x-pack/plugins/security_solution/server/usage/detections/rules/get_metrics.mocks.ts b/x-pack/plugins/security_solution/server/usage/detections/rules/get_metrics.mocks.ts index 83eb7df28a026c..f154c5538f0105 100644 --- a/x-pack/plugins/security_solution/server/usage/detections/rules/get_metrics.mocks.ts +++ b/x-pack/plugins/security_solution/server/usage/detections/rules/get_metrics.mocks.ts @@ -6,9 +6,9 @@ */ import type { SearchResponse } from '@elastic/elasticsearch/lib/api/types'; +import type { AttachmentAttributes } from '@kbn/cases-plugin/common'; +import { AttachmentType } from '@kbn/cases-plugin/common'; import type { SavedObjectsFindResponse } from '@kbn/core/server'; -import type { CommentAttributes } from '@kbn/cases-plugin/common/api/cases/comment'; -import { CommentType } from '@kbn/cases-plugin/common/api/cases/comment'; import type { AlertAggs, EventLogTypeStatusAggs } from '../../types'; import type { EventLogStatusMetric, SingleEventLogStatusMetric } from './types'; @@ -47,7 +47,7 @@ export const getMockRuleAlertsResponse = (docCount: number): SearchResponse, + Partial, never > => ({ page: 1, @@ -58,7 +58,7 @@ export const getMockAlertCaseCommentsResponse = (): SavedObjectsFindResponse< type: 'cases-comments', id: '3bb5cc10-9249-11eb-85b7-254c8af1a983', attributes: { - type: CommentType.alert, + type: AttachmentType.alert, alertId: '54802763917f521249c9f68d0d4be0c26cc538404c26dfed1ae7dcfa94ea2226', index: '.siem-signals-default-000001', rule: { diff --git a/x-pack/plugins/security_solution/server/usage/detections/rules/transform_utils/get_rule_id_to_cases_map.ts b/x-pack/plugins/security_solution/server/usage/detections/rules/transform_utils/get_rule_id_to_cases_map.ts index c43d15122ddc18..cb3cf7f870b8f4 100644 --- a/x-pack/plugins/security_solution/server/usage/detections/rules/transform_utils/get_rule_id_to_cases_map.ts +++ b/x-pack/plugins/security_solution/server/usage/detections/rules/transform_utils/get_rule_id_to_cases_map.ts @@ -6,10 +6,10 @@ */ import type { SavedObjectsFindResult } from '@kbn/core/server'; -import type { CommentAttributes } from '@kbn/cases-plugin/common/api/cases/comment'; +import type { AttachmentAttributes } from '@kbn/cases-plugin/common'; export const getRuleIdToCasesMap = ( - cases: Array> + cases: Array> ): Map => { return cases.reduce((cache, { attributes: casesObject }) => { if (casesObject.type === 'alert') { diff --git a/x-pack/plugins/security_solution/server/usage/get_internal_saved_objects_client.ts b/x-pack/plugins/security_solution/server/usage/get_internal_saved_objects_client.ts index bb39b9c320b206..0271ac5f0ee783 100644 --- a/x-pack/plugins/security_solution/server/usage/get_internal_saved_objects_client.ts +++ b/x-pack/plugins/security_solution/server/usage/get_internal_saved_objects_client.ts @@ -7,7 +7,7 @@ import type { CoreSetup, SavedObjectsClientContract } from '@kbn/core/server'; -import { SAVED_OBJECT_TYPES } from '@kbn/cases-plugin/common/constants'; +import { SAVED_OBJECT_TYPES } from '@kbn/cases-plugin/common'; // eslint-disable-next-line no-restricted-imports import { legacyRuleActionsSavedObjectType } from '../lib/detection_engine/rule_actions_legacy'; diff --git a/x-pack/plugins/security_solution/server/usage/queries/get_case_comments.ts b/x-pack/plugins/security_solution/server/usage/queries/get_case_comments.ts index c39ad34f14b112..43acb1db00c1bd 100644 --- a/x-pack/plugins/security_solution/server/usage/queries/get_case_comments.ts +++ b/x-pack/plugins/security_solution/server/usage/queries/get_case_comments.ts @@ -13,7 +13,7 @@ import type { } from '@kbn/core/server'; import { CASE_COMMENT_SAVED_OBJECT } from '@kbn/cases-plugin/common/constants'; -import type { CommentAttributes } from '@kbn/cases-plugin/common/api/cases/comment'; +import type { AttachmentAttributes } from '@kbn/cases-plugin/common'; export interface GetCasesOptions { savedObjectsClient: SavedObjectsClientContract; @@ -27,7 +27,7 @@ export const getCaseComments = async ({ maxSize, maxPerPage, logger, -}: GetCasesOptions): Promise>> => { +}: GetCasesOptions): Promise>> => { const query: SavedObjectsCreatePointInTimeFinderOptions = { type: CASE_COMMENT_SAVED_OBJECT, perPage: maxPerPage, @@ -35,8 +35,8 @@ export const getCaseComments = async ({ filter: `${CASE_COMMENT_SAVED_OBJECT}.attributes.type: alert`, }; logger.debug(`Getting cases with point in time (PIT) query:', ${JSON.stringify(query)}`); - const finder = savedObjectsClient.createPointInTimeFinder(query); - let responses: Array> = []; + const finder = savedObjectsClient.createPointInTimeFinder(query); + let responses: Array> = []; for await (const response of finder.find()) { const extra = responses.length + response.saved_objects.length - maxSize; if (extra > 0) { diff --git a/x-pack/plugins/threat_intelligence/cypress/e2e/block_list.cy.ts b/x-pack/plugins/threat_intelligence/cypress/e2e/block_list.cy.ts index ae25a740c2c56d..ffe13397e0ebbe 100644 --- a/x-pack/plugins/threat_intelligence/cypress/e2e/block_list.cy.ts +++ b/x-pack/plugins/threat_intelligence/cypress/e2e/block_list.cy.ts @@ -67,7 +67,7 @@ describe('Block list interactions', () => { esArchiverUnload('threat_intelligence/indicators_data'); }); - it('should add to block list from the indicators table and from flyout', () => { + it.skip('should add to block list from the indicators table and from flyout', () => { // first indicator is a valid indicator for add to blocklist feature const firstIndicatorId = 'd86e656455f985357df3063dff6637f7f3b95bb27d1769a6b88c7adecaf7763f'; openIndicatorsTableMoreActions(0); diff --git a/x-pack/plugins/threat_intelligence/cypress/e2e/cases.cy.ts b/x-pack/plugins/threat_intelligence/cypress/e2e/cases.cy.ts index 0490692b3dcf65..39dffd2da0a321 100644 --- a/x-pack/plugins/threat_intelligence/cypress/e2e/cases.cy.ts +++ b/x-pack/plugins/threat_intelligence/cypress/e2e/cases.cy.ts @@ -43,7 +43,7 @@ describe('Cases with invalid indicators', () => { esArchiverUnload('threat_intelligence/invalid_indicators_data'); }); - it('should disable the indicators table context menu items and flyout context menu items', () => { + it.skip('should disable the indicators table context menu items and flyout context menu items', () => { const documentsNumber = 22; openIndicatorsTableMoreActions(documentsNumber - 1); @@ -69,7 +69,7 @@ describe('Cases interactions', () => { esArchiverUnload('threat_intelligence/indicators_data'); }); - it('should add to new case and to existing case from the indicators table and the flyout', () => { + it.skip('should add to new case and to existing case from the indicators table and the flyout', () => { cy.log('should add to new case when clicking on the button in the indicators table'); openIndicatorsTableMoreActions(0); diff --git a/x-pack/plugins/threat_intelligence/cypress/e2e/indicators.cy.ts b/x-pack/plugins/threat_intelligence/cypress/e2e/indicators.cy.ts index 50fd459731bf5d..3b7e360813c0e0 100644 --- a/x-pack/plugins/threat_intelligence/cypress/e2e/indicators.cy.ts +++ b/x-pack/plugins/threat_intelligence/cypress/e2e/indicators.cy.ts @@ -210,7 +210,7 @@ describe('Indicators', () => { visit(THREAT_INTELLIGENCE); }); - it('should handle all search actions', () => { + it.skip('should handle all search actions', () => { cy.log('should narrow the results to url indicators when respective KQL search is executed'); enterQuery('threat.indicator.type: "url"{enter}'); diff --git a/x-pack/plugins/threat_intelligence/cypress/e2e/query_bar.cy.ts b/x-pack/plugins/threat_intelligence/cypress/e2e/query_bar.cy.ts index 34e6134f2f29bb..379147b900a474 100644 --- a/x-pack/plugins/threat_intelligence/cypress/e2e/query_bar.cy.ts +++ b/x-pack/plugins/threat_intelligence/cypress/e2e/query_bar.cy.ts @@ -42,7 +42,7 @@ describe('Indicators query bar interaction', () => { esArchiverUnload('threat_intelligence/indicators_data'); }); - it('should add filter to kql', () => { + it.skip('should add filter to kql', () => { cy.log('filter in values when clicking in the barchart legend'); waitForViewToBeUpdated(); diff --git a/x-pack/plugins/threat_intelligence/public/modules/cases/utils/attachments.tsx b/x-pack/plugins/threat_intelligence/public/modules/cases/utils/attachments.tsx index 5697311dd89b67..fcb19f2271b86a 100644 --- a/x-pack/plugins/threat_intelligence/public/modules/cases/utils/attachments.tsx +++ b/x-pack/plugins/threat_intelligence/public/modules/cases/utils/attachments.tsx @@ -6,7 +6,7 @@ */ import { CaseAttachmentsWithoutOwner } from '@kbn/cases-plugin/public'; -import { CommentType, ExternalReferenceStorageType } from '@kbn/cases-plugin/common'; +import { AttachmentType, ExternalReferenceStorageType } from '@kbn/cases-plugin/common'; import { JsonValue } from '@kbn/utility-types'; import { ExternalReferenceAttachmentType } from '@kbn/cases-plugin/public/client/attachment_framework/types'; import React from 'react'; @@ -74,7 +74,7 @@ export const generateAttachmentsWithoutOwner = ( return [ { - type: CommentType.externalReference, + type: AttachmentType.externalReference, externalReferenceId, externalReferenceStorage: { type: ExternalReferenceStorageType.elasticSearchDoc, diff --git a/x-pack/test/cases_api_integration/common/lib/alerts.ts b/x-pack/test/cases_api_integration/common/lib/alerts.ts index 6f63c8df257773..e0d4b1537190b9 100644 --- a/x-pack/test/cases_api_integration/common/lib/alerts.ts +++ b/x-pack/test/cases_api_integration/common/lib/alerts.ts @@ -12,7 +12,7 @@ import { ToolingLog } from '@kbn/tooling-log'; import { DETECTION_ENGINE_QUERY_SIGNALS_URL } from '@kbn/security-solution-plugin/common/constants'; import { DetectionAlert } from '@kbn/security-solution-plugin/common/api/detection_engine'; import { RiskEnrichmentFields } from '@kbn/security-solution-plugin/server/lib/detection_engine/rule_types/utils/enrichments/types'; -import { Case, CommentType } from '@kbn/cases-plugin/common'; +import { AttachmentType, Case } from '@kbn/cases-plugin/common'; import { ALERT_CASE_IDS } from '@kbn/rule-data-utils'; import { getRuleForSignalTesting, @@ -229,7 +229,7 @@ export const createCaseAndAttachAlert = async ({ name: 'name', }, owner, - type: CommentType.alert, + type: AttachmentType.alert, }, auth: { user: superUser, space: 'space1' }, }); diff --git a/x-pack/test/cases_api_integration/common/lib/api/attachments.ts b/x-pack/test/cases_api_integration/common/lib/api/attachments.ts index 15e3901dcf9706..1dbee9fbd46160 100644 --- a/x-pack/test/cases_api_integration/common/lib/api/attachments.ts +++ b/x-pack/test/cases_api_integration/common/lib/api/attachments.ts @@ -8,18 +8,18 @@ import type SuperTest from 'supertest'; import { CASES_INTERNAL_URL, CASES_URL } from '@kbn/cases-plugin/common/constants'; import { - Comments, - BulkCreateCommentRequest, - BulkGetAttachmentsResponse, - Case, - CommentPatchRequest, - CommentRequest, - Comment, - CommentsFindResponse, - CommentType, getCaseFindAttachmentsUrl, getCasesDeleteFileAttachmentsUrl, } from '@kbn/cases-plugin/common/api'; +import { Case, AttachmentType } from '@kbn/cases-plugin/common'; +import { + BulkGetAttachmentsResponse, + AttachmentRequest, + BulkCreateAttachmentsRequest, + AttachmentPatchRequest, + AttachmentsFindResponse, +} from '@kbn/cases-plugin/common/types/api'; +import { Attachments, Attachment } from '@kbn/cases-plugin/common/types/domain'; import { User } from '../authentication/types'; import { superUser } from '../authentication/users'; import { getSpaceUrlPrefix, setupAuth } from './helpers'; @@ -59,7 +59,7 @@ export const createComment = async ({ }: { supertest: SuperTest.SuperTest; caseId: string; - params: CommentRequest; + params: AttachmentRequest; auth?: { user: User; space: string | null } | null; expectedHttpCode?: number; headers?: Record; @@ -88,7 +88,7 @@ export const bulkCreateAttachments = async ({ }: { supertest: SuperTest.SuperTest; caseId: string; - params: BulkCreateCommentRequest; + params: BulkCreateAttachmentsRequest; auth?: { user: User; space: string | null }; expectedHttpCode?: number; }): Promise => { @@ -114,7 +114,7 @@ export const createCaseAndBulkCreateAttachments = async ({ numberOfAttachments?: number; auth?: { user: User; space: string | null }; expectedHttpCode?: number; -}): Promise<{ theCase: Case; attachments: BulkCreateCommentRequest }> => { +}): Promise<{ theCase: Case; attachments: BulkCreateAttachmentsRequest }> => { const postedCase = await createCase(supertest, postCaseReq); const attachments = getAttachments(numberOfAttachments); const patchedCase = await bulkCreateAttachments({ @@ -126,18 +126,18 @@ export const createCaseAndBulkCreateAttachments = async ({ return { theCase: patchedCase, attachments }; }; -export const getAttachments = (numberOfAttachments: number): BulkCreateCommentRequest => { +export const getAttachments = (numberOfAttachments: number): BulkCreateAttachmentsRequest => { return [...Array(numberOfAttachments)].map((_, index) => { if (index % 10 === 0) { return { - type: CommentType.user, + type: AttachmentType.user, comment: `Test ${index + 1}`, owner: 'securitySolutionFixture', }; } return { - type: CommentType.alert, + type: AttachmentType.alert, alertId: [`test-id-${index + 1}`], index: [`test-index-${index + 1}`], rule: { @@ -203,7 +203,7 @@ export const getAllComments = async ({ caseId: string; auth?: { user: User; space: string | null }; expectedHttpCode?: number; -}): Promise => { +}): Promise => { const { body: comments } = await supertest .get(`${getSpaceUrlPrefix(auth.space)}${CASES_URL}/${caseId}/comments`) .auth(auth.user.username, auth.user.password) @@ -224,7 +224,7 @@ export const getComment = async ({ commentId: string; expectedHttpCode?: number; auth?: { user: User; space: string | null }; -}): Promise => { +}): Promise => { const { body: comment } = await supertest .get(`${getSpaceUrlPrefix(auth.space)}${CASES_URL}/${caseId}/comments/${commentId}`) .auth(auth.user.username, auth.user.password) @@ -243,7 +243,7 @@ export const updateComment = async ({ }: { supertest: SuperTest.SuperTest; caseId: string; - req: CommentPatchRequest; + req: AttachmentPatchRequest; expectedHttpCode?: number; auth?: { user: User; space: string | null } | null; headers?: Record; @@ -295,7 +295,7 @@ export const findAttachments = async ({ query?: Record; expectedHttpCode?: number; auth?: { user: User; space: string | null }; -}): Promise => { +}): Promise => { const { body } = await supertest .get(`${getSpaceUrlPrefix(auth.space)}${getCaseFindAttachmentsUrl(caseId)}`) .set('kbn-xsrf', 'true') diff --git a/x-pack/test/cases_api_integration/common/lib/api/case.ts b/x-pack/test/cases_api_integration/common/lib/api/case.ts index 29e813c9dd7c12..b2c6ad9435dc34 100644 --- a/x-pack/test/cases_api_integration/common/lib/api/case.ts +++ b/x-pack/test/cases_api_integration/common/lib/api/case.ts @@ -6,7 +6,8 @@ */ import { CASES_URL } from '@kbn/cases-plugin/common'; -import { CasePostRequest, Case } from '@kbn/cases-plugin/common/api'; +import { Case } from '@kbn/cases-plugin/common/types/domain'; +import { CasePostRequest } from '@kbn/cases-plugin/common/types/api'; import type SuperTest from 'supertest'; import { User } from '../authentication/types'; diff --git a/x-pack/test/cases_api_integration/common/lib/api/connectors.ts b/x-pack/test/cases_api_integration/common/lib/api/connectors.ts index 77570d5fd9c395..b5268191fddfe9 100644 --- a/x-pack/test/cases_api_integration/common/lib/api/connectors.ts +++ b/x-pack/test/cases_api_integration/common/lib/api/connectors.ts @@ -10,16 +10,17 @@ import http from 'http'; import type SuperTest from 'supertest'; import { CASE_CONFIGURE_CONNECTORS_URL } from '@kbn/cases-plugin/common/constants'; -import { CasePostRequest, Case, getCaseConnectorsUrl } from '@kbn/cases-plugin/common/api'; +import { getCaseConnectorsUrl } from '@kbn/cases-plugin/common/api'; import { ActionResult, FindActionResult } from '@kbn/actions-plugin/server/types'; import { getServiceNowServer } from '@kbn/actions-simulators-plugin/server/plugin'; import { RecordingServiceNowSimulator } from '@kbn/actions-simulators-plugin/server/servicenow_simulation'; import { + Case, CaseConnector, Configuration, ConnectorTypes, } from '@kbn/cases-plugin/common/types/domain'; -import { GetCaseConnectorsResponse } from '@kbn/cases-plugin/common/types/api'; +import { CasePostRequest, GetCaseConnectorsResponse } from '@kbn/cases-plugin/common/types/api'; import { User } from '../authentication/types'; import { superUser } from '../authentication/users'; import { getPostCaseRequest } from '../mock'; diff --git a/x-pack/test/cases_api_integration/common/lib/api/index.ts b/x-pack/test/cases_api_integration/common/lib/api/index.ts index c816d3c570a241..007efff840ba16 100644 --- a/x-pack/test/cases_api_integration/common/lib/api/index.ts +++ b/x-pack/test/cases_api_integration/common/lib/api/index.ts @@ -26,20 +26,7 @@ import { CASE_USER_ACTION_SAVED_OBJECT, INTERNAL_GET_CASE_CATEGORIES_URL, } from '@kbn/cases-plugin/common/constants'; -import { - Case, - CaseStatuses, - Cases, - CasesFindResponse, - CasesPatchRequest, - CasesStatusResponse, - AlertResponse, - CasesByAlertId, - CaseResolveResponse, - SingleCaseMetricsResponse, - CasesMetricsResponse, - CasesBulkGetResponse, -} from '@kbn/cases-plugin/common/api'; +import { SingleCaseMetricsResponse, CasesMetricsResponse } from '@kbn/cases-plugin/common/api'; import { SignalHit } from '@kbn/security-solution-plugin/server/lib/detection_engine/rule_types/types'; import { ActionResult } from '@kbn/actions-plugin/server/types'; import { CasePersistedAttributes } from '@kbn/cases-plugin/server/common/types/case'; @@ -49,8 +36,20 @@ import { Configurations, Configuration, ConnectorMappingsAttributes, + Case, + Cases, + CaseStatuses, } from '@kbn/cases-plugin/common/types/domain'; -import { ConfigurationPatchRequest } from '@kbn/cases-plugin/common/types/api'; +import { + AlertResponse, + CaseResolveResponse, + CasesBulkGetResponse, + CasesFindResponse, + CasesPatchRequest, + CasesStatusResponse, + ConfigurationPatchRequest, + GetRelatedCasesByAlertResponse, +} from '@kbn/cases-plugin/common/types/api'; import { User } from '../authentication/types'; import { superUser } from '../authentication/users'; import { getSpaceUrlPrefix, setupAuth } from './helpers'; @@ -611,7 +610,7 @@ export const getCasesByAlert = async ({ query?: Record; expectedHttpCode?: number; auth?: { user: User; space: string | null }; -}): Promise => { +}): Promise => { const { body: res } = await supertest .get(`${getSpaceUrlPrefix(auth.space)}${CASES_URL}/alerts/${alertID}`) .auth(auth.user.username, auth.user.password) diff --git a/x-pack/test/cases_api_integration/common/lib/api/omit.ts b/x-pack/test/cases_api_integration/common/lib/api/omit.ts index ea974f83574536..b25506bfaebea0 100644 --- a/x-pack/test/cases_api_integration/common/lib/api/omit.ts +++ b/x-pack/test/cases_api_integration/common/lib/api/omit.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { Case, Comment } from '@kbn/cases-plugin/common/api'; +import { Case, Attachment } from '@kbn/cases-plugin/common/types/domain'; import { omit } from 'lodash'; interface CommonSavedObjectAttributes { @@ -41,9 +41,9 @@ export const removeServerGeneratedPropertiesFromCase = (theCase: Case): Partial< }; export const removeServerGeneratedPropertiesFromComments = ( - comments: Comment[] | undefined -): Array> | undefined => { + comments: Attachment[] | undefined +): Array> | undefined => { return comments?.map((comment) => { - return removeServerGeneratedPropertiesFromSavedObject(comment, []); + return removeServerGeneratedPropertiesFromSavedObject(comment, []); }); }; diff --git a/x-pack/test/cases_api_integration/common/lib/api/user_actions.ts b/x-pack/test/cases_api_integration/common/lib/api/user_actions.ts index ff20f0db8eb0b1..fc4f8382d35087 100644 --- a/x-pack/test/cases_api_integration/common/lib/api/user_actions.ts +++ b/x-pack/test/cases_api_integration/common/lib/api/user_actions.ts @@ -9,13 +9,13 @@ import { getCaseFindUserActionsUrl, getCaseUserActionUrl, getCaseUserActionStatsUrl, - GetCaseUsersResponse, getCaseUsersUrl, } from '@kbn/cases-plugin/common/api'; import { CaseUserActionDeprecatedResponse, CaseUserActionsDeprecatedResponse, CaseUserActionStatsResponse, + GetCaseUsersResponse, UserActionFindRequest, UserActionFindResponse, } from '@kbn/cases-plugin/common/types/api'; diff --git a/x-pack/test/cases_api_integration/common/lib/api/user_profiles.ts b/x-pack/test/cases_api_integration/common/lib/api/user_profiles.ts index f7a41b9af2deb2..25c7f7a7a9ba40 100644 --- a/x-pack/test/cases_api_integration/common/lib/api/user_profiles.ts +++ b/x-pack/test/cases_api_integration/common/lib/api/user_profiles.ts @@ -9,10 +9,10 @@ import type SuperTest from 'supertest'; import { parse as parseCookie, Cookie } from 'tough-cookie'; import { INTERNAL_SUGGEST_USER_PROFILES_URL } from '@kbn/cases-plugin/common/constants'; -import { SuggestUserProfilesRequest } from '@kbn/cases-plugin/common/api'; import { UserProfileService } from '@kbn/cases-plugin/server/services'; import { UserProfileAvatarData } from '@kbn/security-plugin/common'; import { UserProfile, UserProfileWithAvatar } from '@kbn/user-profile-components'; +import { SuggestUserProfilesRequest } from '@kbn/cases-plugin/common/types/api'; import { superUser } from '../authentication/users'; import { User } from '../authentication/types'; import { getSpaceUrlPrefix } from './helpers'; diff --git a/x-pack/test/cases_api_integration/common/lib/mock.ts b/x-pack/test/cases_api_integration/common/lib/mock.ts index ab684f8604157b..b18ea72e028094 100644 --- a/x-pack/test/cases_api_integration/common/lib/mock.ts +++ b/x-pack/test/cases_api_integration/common/lib/mock.ts @@ -6,26 +6,25 @@ */ import { - CasePostRequest, Case, - CasesFindResponse, - Comment, - CommentRequestUserType, - CommentRequestAlertType, - CommentType, + AttachmentType, CaseStatuses, - CommentRequest, - CommentRequestActionsType, CaseSeverity, ExternalReferenceStorageType, - CommentRequestExternalReferenceSOType, - CommentRequestExternalReferenceNoSOType, - CommentRequestPersistableStateType, FileAttachmentMetadata, -} from '@kbn/cases-plugin/common/api'; + AlertAttachmentPayload, + UserCommentAttachmentPayload, + ActionsAttachmentPayload, + ExternalReferenceNoSOAttachmentPayload, + ExternalReferenceSOAttachmentPayload, + PersistableStateAttachmentPayload, + Attachment, +} from '@kbn/cases-plugin/common/types/domain'; +import type { CasePostRequest } from '@kbn/cases-plugin/common/types/api'; import { FILE_ATTACHMENT_TYPE } from '@kbn/cases-plugin/common/constants'; import { ConnectorTypes } from '@kbn/cases-plugin/common/types/domain'; import { FILE_SO_TYPE } from '@kbn/files-plugin/common'; +import { AttachmentRequest, CasesFindResponse } from '@kbn/cases-plugin/common/types/api'; export const defaultUser = { email: null, full_name: null, username: 'elastic' }; /** @@ -59,29 +58,29 @@ export const getPostCaseRequest = (req?: Partial): CasePostRequ ...req, }); -export const postCommentUserReq: CommentRequestUserType = { +export const postCommentUserReq: UserCommentAttachmentPayload = { comment: 'This is a cool comment', - type: CommentType.user, + type: AttachmentType.user, owner: 'securitySolutionFixture', }; -export const postCommentAlertReq: CommentRequestAlertType = { +export const postCommentAlertReq: AlertAttachmentPayload = { alertId: 'test-id', index: 'test-index', rule: { id: 'test-rule-id', name: 'test-index-id' }, - type: CommentType.alert, + type: AttachmentType.alert, owner: 'securitySolutionFixture', }; -export const postCommentAlertMultipleIdsReq: CommentRequestAlertType = { +export const postCommentAlertMultipleIdsReq: AlertAttachmentPayload = { alertId: ['test-id-1', 'test-id-2'], index: ['test-index', 'test-index-2'], rule: { id: 'test-rule-id', name: 'test-index-id' }, - type: CommentType.alert, + type: AttachmentType.alert, owner: 'securitySolutionFixture', }; -export const postCommentActionsReq: CommentRequestActionsType = { +export const postCommentActionsReq: ActionsAttachmentPayload = { comment: 'comment text', actions: { targets: [ @@ -92,11 +91,11 @@ export const postCommentActionsReq: CommentRequestActionsType = { ], type: 'isolate', }, - type: CommentType.actions, + type: AttachmentType.actions, owner: 'securitySolutionFixture', }; -export const postCommentActionsReleaseReq: CommentRequestActionsType = { +export const postCommentActionsReleaseReq: ActionsAttachmentPayload = { comment: 'comment text', actions: { targets: [ @@ -107,12 +106,12 @@ export const postCommentActionsReleaseReq: CommentRequestActionsType = { ], type: 'unisolate', }, - type: CommentType.actions, + type: AttachmentType.actions, owner: 'securitySolutionFixture', }; -export const postExternalReferenceESReq: CommentRequestExternalReferenceNoSOType = { - type: CommentType.externalReference, +export const postExternalReferenceESReq: ExternalReferenceNoSOAttachmentPayload = { + type: AttachmentType.externalReference, externalReferenceStorage: { type: ExternalReferenceStorageType.elasticSearchDoc }, externalReferenceId: 'my-id', externalReferenceAttachmentTypeId: '.test', @@ -120,7 +119,7 @@ export const postExternalReferenceESReq: CommentRequestExternalReferenceNoSOType owner: 'securitySolutionFixture', }; -export const postExternalReferenceSOReq: CommentRequestExternalReferenceSOType = { +export const postExternalReferenceSOReq: ExternalReferenceSOAttachmentPayload = { ...postExternalReferenceESReq, externalReferenceStorage: { type: ExternalReferenceStorageType.savedObject, soType: 'test-type' }, }; @@ -137,8 +136,8 @@ export const fileAttachmentMetadata: FileAttachmentMetadata = { }; export const getFilesAttachmentReq = ( - req?: Partial -): CommentRequestExternalReferenceSOType => { + req?: Partial +): ExternalReferenceSOAttachmentPayload => { return { ...postExternalReferenceSOReq, externalReferenceStorage: { @@ -151,8 +150,8 @@ export const getFilesAttachmentReq = ( }; }; -export const persistableStateAttachment: CommentRequestPersistableStateType = { - type: CommentType.persistableState, +export const persistableStateAttachment: PersistableStateAttachmentPayload = { + type: AttachmentType.persistableState, owner: 'securitySolutionFixture', persistableStateAttachmentTypeId: '.test', persistableStateAttachmentState: { foo: 'foo', injectedId: 'testRef' }, @@ -179,14 +178,14 @@ export const postCaseResp = ( interface CommentRequestWithID { id: string; - comment: CommentRequest; + comment: AttachmentRequest; } export const commentsResp = ({ comments, }: { comments: CommentRequestWithID[]; -}): Array> => { +}): Array> => { return comments.map(({ comment, id }) => { const baseFields = { id, diff --git a/x-pack/test/cases_api_integration/common/lib/validation.ts b/x-pack/test/cases_api_integration/common/lib/validation.ts index dd1ca12a2db15f..a280578e912b80 100644 --- a/x-pack/test/cases_api_integration/common/lib/validation.ts +++ b/x-pack/test/cases_api_integration/common/lib/validation.ts @@ -6,13 +6,9 @@ */ import expect from '@kbn/expect'; -import { - AttachmentTotals, - Case, - CasesByAlertId, - RelatedCaseInfo, -} from '@kbn/cases-plugin/common/api'; +import { AttachmentTotals, Case, RelatedCase } from '@kbn/cases-plugin/common/types/domain'; import { xorWith, isEqual } from 'lodash'; +import { GetRelatedCasesByAlertResponse } from '@kbn/cases-plugin/common/types/api'; type AttachmentTotalsKeys = keyof AttachmentTotals; @@ -25,10 +21,10 @@ export interface TestCaseWithTotals { * Ensure that the result of the alerts API request matches with the cases created for the test. */ export function validateCasesFromAlertIDResponse( - casesFromAPIResponse: CasesByAlertId, + casesFromAPIResponse: GetRelatedCasesByAlertResponse, createdCasesForTest: TestCaseWithTotals[] ) { - const idToResponse = new Map( + const idToResponse = new Map( casesFromAPIResponse.map((response) => [response.id, response]) ); diff --git a/x-pack/test/cases_api_integration/common/plugins/cases/server/routes.ts b/x-pack/test/cases_api_integration/common/plugins/cases/server/routes.ts index 14554254d3a522..d68b87a2b132d5 100644 --- a/x-pack/test/cases_api_integration/common/plugins/cases/server/routes.ts +++ b/x-pack/test/cases_api_integration/common/plugins/cases/server/routes.ts @@ -6,13 +6,13 @@ */ import { createHash } from 'crypto'; -import type { CasesPatchRequest } from '@kbn/cases-plugin/common/api'; import { schema } from '@kbn/config-schema'; import type { CoreSetup, Logger } from '@kbn/core/server'; import type { ExternalReferenceAttachmentType, PersistableStateAttachmentTypeSetup, } from '@kbn/cases-plugin/server/attachment_framework/types'; +import { CasesPatchRequest } from '@kbn/cases-plugin/common/types/api'; import type { FixtureStartDeps } from './plugin'; const hashParts = (parts: string[]): string => { diff --git a/x-pack/test/cases_api_integration/security_and_spaces/tests/common/alerts/get_cases.ts b/x-pack/test/cases_api_integration/security_and_spaces/tests/common/alerts/get_cases.ts index 07ea283247d910..28819c3fb12967 100644 --- a/x-pack/test/cases_api_integration/security_and_spaces/tests/common/alerts/get_cases.ts +++ b/x-pack/test/cases_api_integration/security_and_spaces/tests/common/alerts/get_cases.ts @@ -7,7 +7,7 @@ import expect from '@kbn/expect'; import { CASES_URL } from '@kbn/cases-plugin/common/constants'; -import { Case } from '@kbn/cases-plugin/common/api'; +import { Case } from '@kbn/cases-plugin/common/types/domain'; import { FtrProviderContext } from '../../../../common/ftr_provider_context'; import { diff --git a/x-pack/test/cases_api_integration/security_and_spaces/tests/common/attachments_framework/external_references.ts b/x-pack/test/cases_api_integration/security_and_spaces/tests/common/attachments_framework/external_references.ts index 1de5abaf51b3d7..53b4e7d94c9552 100644 --- a/x-pack/test/cases_api_integration/security_and_spaces/tests/common/attachments_framework/external_references.ts +++ b/x-pack/test/cases_api_integration/security_and_spaces/tests/common/attachments_framework/external_references.ts @@ -8,12 +8,12 @@ import { omit } from 'lodash/fp'; import expect from '@kbn/expect'; -import { CommentRequest, CommentType } from '@kbn/cases-plugin/common/api'; import { CASE_COMMENT_SAVED_OBJECT, CASE_USER_ACTION_SAVED_OBJECT, } from '@kbn/cases-plugin/common/constants'; -import { UserActionTypes } from '@kbn/cases-plugin/common/types/domain'; +import { AttachmentType, UserActionTypes } from '@kbn/cases-plugin/common/types/domain'; +import { AttachmentRequest } from '@kbn/cases-plugin/common/types/api'; import { FtrProviderContext } from '../../../../common/ftr_provider_context'; import { defaultUser, @@ -272,7 +272,7 @@ export default ({ getService }: FtrProviderContext): void => { }); const externalRefComment = patchedCase.comments?.find( - (comment) => comment.type === CommentType.externalReference + (comment) => comment.type === AttachmentType.externalReference ); const esResponse = await getSOFromKibanaIndex({ @@ -315,7 +315,7 @@ export default ({ getService }: FtrProviderContext): void => { }); const externalRefComment = patchedCase.comments?.find( - (comment) => comment.type === CommentType.externalReference + (comment) => comment.type === AttachmentType.externalReference ); const esResponse = await getSOFromKibanaIndex({ @@ -387,7 +387,7 @@ export default ({ getService }: FtrProviderContext): void => { }); it('should return 400 when updating from so to doc', async () => { - const docAttachment: CommentRequest = { + const docAttachment: AttachmentRequest = { ...postExternalReferenceESReq, externalReferenceId: 'my-doc-id', }; @@ -412,7 +412,7 @@ export default ({ getService }: FtrProviderContext): void => { }); it('should return 400 when updating from doc to so', async () => { - const docAttachment: CommentRequest = { + const docAttachment: AttachmentRequest = { ...postExternalReferenceESReq, externalReferenceId: 'my-doc-id', }; diff --git a/x-pack/test/cases_api_integration/security_and_spaces/tests/common/attachments_framework/persistable_state.ts b/x-pack/test/cases_api_integration/security_and_spaces/tests/common/attachments_framework/persistable_state.ts index d20e59daf4ad57..6b449ff0998fcf 100644 --- a/x-pack/test/cases_api_integration/security_and_spaces/tests/common/attachments_framework/persistable_state.ts +++ b/x-pack/test/cases_api_integration/security_and_spaces/tests/common/attachments_framework/persistable_state.ts @@ -8,7 +8,7 @@ import { omit } from 'lodash/fp'; import expect from '@kbn/expect'; -import { CommentType } from '@kbn/cases-plugin/common/api'; +import { AttachmentType } from '@kbn/cases-plugin/common/types/domain'; import { CASE_COMMENT_SAVED_OBJECT, CASE_USER_ACTION_SAVED_OBJECT, @@ -154,7 +154,7 @@ export default ({ getService }: FtrProviderContext): void => { }); const externalRefComment = patchedCase.comments?.find( - (comment) => comment.type === CommentType.persistableState + (comment) => comment.type === AttachmentType.persistableState ); const esResponse = await getSOFromKibanaIndex({ diff --git a/x-pack/test/cases_api_integration/security_and_spaces/tests/common/cases/find_cases.ts b/x-pack/test/cases_api_integration/security_and_spaces/tests/common/cases/find_cases.ts index a5b8bc5617f94f..7b58f32fe630fb 100644 --- a/x-pack/test/cases_api_integration/security_and_spaces/tests/common/cases/find_cases.ts +++ b/x-pack/test/cases_api_integration/security_and_spaces/tests/common/cases/find_cases.ts @@ -16,7 +16,12 @@ import { MAX_REPORTERS_FILTER_LENGTH, MAX_TAGS_FILTER_LENGTH, } from '@kbn/cases-plugin/common/constants'; -import { Case, CaseSeverity, CaseStatuses, CommentType } from '@kbn/cases-plugin/common/api'; +import { + Case, + CaseSeverity, + CaseStatuses, + AttachmentType, +} from '@kbn/cases-plugin/common/types/domain'; import { ALERTING_CASES_SAVED_OBJECT_INDEX } from '@kbn/core-saved-objects-server'; import { FtrProviderContext } from '../../../../common/ftr_provider_context'; @@ -533,7 +538,7 @@ export default ({ getService }: FtrProviderContext): void => { alertId, index: defaultSignalsIndex, rule: { id: 'test-rule-id', name: 'test-index-id' }, - type: CommentType.alert, + type: AttachmentType.alert, owner: 'securitySolutionFixture', }, }); diff --git a/x-pack/test/cases_api_integration/security_and_spaces/tests/common/cases/get_case.ts b/x-pack/test/cases_api_integration/security_and_spaces/tests/common/cases/get_case.ts index 0277758b18df18..2cf3ee4b2cf055 100644 --- a/x-pack/test/cases_api_integration/security_and_spaces/tests/common/cases/get_case.ts +++ b/x-pack/test/cases_api_integration/security_and_spaces/tests/common/cases/get_case.ts @@ -7,8 +7,9 @@ import expect from '@kbn/expect'; -import { AttributesTypeUser, getCaseDetailsUrl } from '@kbn/cases-plugin/common/api'; +import { getCaseDetailsUrl } from '@kbn/cases-plugin/common/api'; import { CASES_URL } from '@kbn/cases-plugin/common/constants'; +import { UserCommentAttachmentAttributes } from '@kbn/cases-plugin/common/types/domain'; import { FtrProviderContext } from '../../../../common/ftr_provider_context'; import { defaultUser, @@ -68,7 +69,7 @@ export default ({ getService }: FtrProviderContext): void => { const theCase = await getCase({ supertest, caseId: postedCase.id, includeComments: true }); const comment = removeServerGeneratedPropertiesFromSavedObject( - theCase.comments![0] as AttributesTypeUser + theCase.comments![0] as UserCommentAttachmentAttributes ); expect(theCase.comments?.length).to.eql(1); @@ -168,7 +169,7 @@ export default ({ getService }: FtrProviderContext): void => { }); const comment = removeServerGeneratedPropertiesFromSavedObject( - theCase.comments![0] as AttributesTypeUser + theCase.comments![0] as UserCommentAttachmentAttributes ); expect(theCase.comments?.length).to.eql(1); diff --git a/x-pack/test/cases_api_integration/security_and_spaces/tests/common/cases/import_export.ts b/x-pack/test/cases_api_integration/security_and_spaces/tests/common/cases/import_export.ts index 10ca2298894524..3f5d757124e4e3 100644 --- a/x-pack/test/cases_api_integration/security_and_spaces/tests/common/cases/import_export.ts +++ b/x-pack/test/cases_api_integration/security_and_spaces/tests/common/cases/import_export.ts @@ -15,12 +15,11 @@ import { CASE_COMMENT_SAVED_OBJECT, } from '@kbn/cases-plugin/common/constants'; import { - AttributesTypeUser, + UserCommentAttachmentAttributes, CaseAttributes, - CasePostRequest, CaseStatuses, CaseSeverity, -} from '@kbn/cases-plugin/common/api'; +} from '@kbn/cases-plugin/common/types/domain'; import { CasePersistedSeverity, CasePersistedStatus, @@ -32,6 +31,7 @@ import { CreateCaseUserAction, PushedUserAction, } from '@kbn/cases-plugin/common/types/domain'; +import { CasePostRequest } from '@kbn/cases-plugin/common'; import { ObjectRemover as ActionsRemover } from '../../../../../alerting_api_integration/common/lib'; import { deleteAllCaseItems, @@ -110,7 +110,7 @@ export default ({ getService }: FtrProviderContext): void => { caseId: findResponse.cases[0].id, }); - const comment = commentsResponse.comments[0] as unknown as AttributesTypeUser; + const comment = commentsResponse.comments[0] as unknown as UserCommentAttachmentAttributes; expect(comment.comment).to.eql('A comment for my case'); const userActions = await getCaseUserActions({ @@ -268,7 +268,10 @@ const expectCreateCommentUserAction = ( }; const expectExportToHaveAComment = (objects: SavedObject[]) => { - const commentSOs = findSavedObjectsByType(objects, CASE_COMMENT_SAVED_OBJECT); + const commentSOs = findSavedObjectsByType( + objects, + CASE_COMMENT_SAVED_OBJECT + ); expect(commentSOs.length).to.eql(1); diff --git a/x-pack/test/cases_api_integration/security_and_spaces/tests/common/cases/migrations.ts b/x-pack/test/cases_api_integration/security_and_spaces/tests/common/cases/migrations.ts index f908e90c58afb2..3be3095ca2830c 100644 --- a/x-pack/test/cases_api_integration/security_and_spaces/tests/common/cases/migrations.ts +++ b/x-pack/test/cases_api_integration/security_and_spaces/tests/common/cases/migrations.ts @@ -7,7 +7,7 @@ import expect from '@kbn/expect'; import { CASES_URL, SECURITY_SOLUTION_OWNER } from '@kbn/cases-plugin/common/constants'; -import { AttributesTypeUser } from '@kbn/cases-plugin/common/api'; +import { UserCommentAttachmentAttributes } from '@kbn/cases-plugin/common/types/domain'; import { CasePersistedSeverity, CasePersistedStatus, @@ -337,7 +337,7 @@ export default function createGetTests({ getService }: FtrProviderContext) { includeComments: true, }); - const comment = theCase.comments![0] as AttributesTypeUser; + const comment = theCase.comments![0] as UserCommentAttachmentAttributes; expect(comment.comment).to.be('a comment'); expect(comment.owner).to.be(SECURITY_SOLUTION_OWNER); }); diff --git a/x-pack/test/cases_api_integration/security_and_spaces/tests/common/cases/patch_cases.ts b/x-pack/test/cases_api_integration/security_and_spaces/tests/common/cases/patch_cases.ts index 568cf12c911c7a..0aa6d673ec55cb 100644 --- a/x-pack/test/cases_api_integration/security_and_spaces/tests/common/cases/patch_cases.ts +++ b/x-pack/test/cases_api_integration/security_and_spaces/tests/common/cases/patch_cases.ts @@ -9,8 +9,13 @@ import expect from '@kbn/expect'; import { ALERT_WORKFLOW_STATUS } from '@kbn/rule-data-utils'; import { DETECTION_ENGINE_QUERY_SIGNALS_URL } from '@kbn/security-solution-plugin/common/constants'; -import { CaseSeverity, Cases, CaseStatuses, CommentType } from '@kbn/cases-plugin/common/api'; -import { ConnectorTypes } from '@kbn/cases-plugin/common/types/domain'; +import { + AttachmentType, + Cases, + CaseSeverity, + CaseStatuses, + ConnectorTypes, +} from '@kbn/cases-plugin/common/types/domain'; import { FtrProviderContext } from '../../../../common/ftr_provider_context'; import { defaultUser, @@ -845,7 +850,7 @@ export default ({ getService }: FtrProviderContext): void => { alertId: signalID, index: defaultSignalsIndex, rule: { id: 'test-rule-id', name: 'test-index-id' }, - type: CommentType.alert, + type: AttachmentType.alert, owner: 'securitySolutionFixture', }, }); @@ -864,7 +869,7 @@ export default ({ getService }: FtrProviderContext): void => { alertId: signalID2, index: defaultSignalsIndex, rule: { id: 'test-rule-id', name: 'test-index-id' }, - type: CommentType.alert, + type: AttachmentType.alert, owner: 'securitySolutionFixture', }, }); @@ -990,7 +995,7 @@ export default ({ getService }: FtrProviderContext): void => { alertId: signalIDInFirstIndex, index: defaultSignalsIndex, rule: { id: 'test-rule-id', name: 'test-index-id' }, - type: CommentType.alert, + type: AttachmentType.alert, owner: 'securitySolutionFixture', }, }); @@ -1002,7 +1007,7 @@ export default ({ getService }: FtrProviderContext): void => { alertId: signalIDInSecondIndex, index: signalsIndex2, rule: { id: 'test-rule-id', name: 'test-index-id' }, - type: CommentType.alert, + type: AttachmentType.alert, owner: 'securitySolutionFixture', }, }); @@ -1113,7 +1118,7 @@ export default ({ getService }: FtrProviderContext): void => { id: 'id', name: 'name', }, - type: CommentType.alert, + type: AttachmentType.alert, owner: 'securitySolutionFixture', }, }); @@ -1172,7 +1177,7 @@ export default ({ getService }: FtrProviderContext): void => { params: { alertId: alert._id, index: alert._index, - type: CommentType.alert, + type: AttachmentType.alert, rule: { id: 'id', name: 'name', @@ -1232,7 +1237,7 @@ export default ({ getService }: FtrProviderContext): void => { id: 'id', name: 'name', }, - type: CommentType.alert, + type: AttachmentType.alert, owner: 'securitySolutionFixture', }, }); @@ -1300,7 +1305,7 @@ export default ({ getService }: FtrProviderContext): void => { params: { alertId: alert._id, index: alert._index, - type: CommentType.alert, + type: AttachmentType.alert, rule: { id: 'id', name: 'name', diff --git a/x-pack/test/cases_api_integration/security_and_spaces/tests/common/cases/post_case.ts b/x-pack/test/cases_api_integration/security_and_spaces/tests/common/cases/post_case.ts index 2bceea9852cfff..c32103ea51fef5 100644 --- a/x-pack/test/cases_api_integration/security_and_spaces/tests/common/cases/post_case.ts +++ b/x-pack/test/cases_api_integration/security_and_spaces/tests/common/cases/post_case.ts @@ -8,7 +8,7 @@ import expect from '@kbn/expect'; import { CASES_URL } from '@kbn/cases-plugin/common/constants'; -import { CaseStatuses, CaseSeverity } from '@kbn/cases-plugin/common/api'; +import { CaseStatuses, CaseSeverity } from '@kbn/cases-plugin/common/types/domain'; import { ConnectorJiraTypeFields, ConnectorTypes } from '@kbn/cases-plugin/common/types/domain'; import { getPostCaseRequest, postCaseResp, defaultUser } from '../../../../common/lib/mock'; import { diff --git a/x-pack/test/cases_api_integration/security_and_spaces/tests/common/cases/resolve_case.ts b/x-pack/test/cases_api_integration/security_and_spaces/tests/common/cases/resolve_case.ts index c4b84fecc19323..042b9856fc45c6 100644 --- a/x-pack/test/cases_api_integration/security_and_spaces/tests/common/cases/resolve_case.ts +++ b/x-pack/test/cases_api_integration/security_and_spaces/tests/common/cases/resolve_case.ts @@ -7,7 +7,7 @@ import expect from '@kbn/expect'; -import { AttributesTypeUser } from '@kbn/cases-plugin/common/api'; +import { UserCommentAttachmentAttributes } from '@kbn/cases-plugin/common/types/domain'; import { CASES_URL } from '@kbn/cases-plugin/common/constants'; import { FtrProviderContext } from '../../../../common/ftr_provider_context'; import { @@ -72,7 +72,7 @@ export default ({ getService }: FtrProviderContext): void => { }); const comment = removeServerGeneratedPropertiesFromSavedObject( - resolvedCase.case.comments![0] as AttributesTypeUser + resolvedCase.case.comments![0] as UserCommentAttachmentAttributes ); expect(resolvedCase.case.comments?.length).to.eql(1); @@ -150,7 +150,7 @@ export default ({ getService }: FtrProviderContext): void => { }); const comment = removeServerGeneratedPropertiesFromSavedObject( - resolvedCase.case.comments![0] as AttributesTypeUser + resolvedCase.case.comments![0] as UserCommentAttachmentAttributes ); expect(resolvedCase.case.comments?.length).to.eql(1); diff --git a/x-pack/test/cases_api_integration/security_and_spaces/tests/common/cases/status/get_status.ts b/x-pack/test/cases_api_integration/security_and_spaces/tests/common/cases/status/get_status.ts index 7e3b49473cb5b0..5a919029ca0d75 100644 --- a/x-pack/test/cases_api_integration/security_and_spaces/tests/common/cases/status/get_status.ts +++ b/x-pack/test/cases_api_integration/security_and_spaces/tests/common/cases/status/get_status.ts @@ -6,7 +6,7 @@ */ import expect from '@kbn/expect'; -import { CaseStatuses } from '@kbn/cases-plugin/common/api'; +import { CaseStatuses } from '@kbn/cases-plugin/common/types/domain'; import { CASE_STATUS_URL } from '@kbn/cases-plugin/common/constants'; import { FtrProviderContext } from '../../../../../common/ftr_provider_context'; diff --git a/x-pack/test/cases_api_integration/security_and_spaces/tests/common/client/update_alert_status.ts b/x-pack/test/cases_api_integration/security_and_spaces/tests/common/client/update_alert_status.ts index be47e250c7a9f5..522a4d88e12c9d 100644 --- a/x-pack/test/cases_api_integration/security_and_spaces/tests/common/client/update_alert_status.ts +++ b/x-pack/test/cases_api_integration/security_and_spaces/tests/common/client/update_alert_status.ts @@ -6,7 +6,7 @@ */ import expect from '@kbn/expect'; -import { Cases, CaseStatuses, CommentType } from '@kbn/cases-plugin/common/api'; +import { Cases, CaseStatuses, AttachmentType } from '@kbn/cases-plugin/common/types/domain'; import { FtrProviderContext } from '../../../../common/ftr_provider_context'; import { postCaseReq } from '../../../../common/lib/mock'; @@ -53,7 +53,7 @@ export default ({ getService }: FtrProviderContext): void => { alertId: signalID, index: defaultSignalsIndex, rule: { id: 'test-rule-id', name: 'test-index-id' }, - type: CommentType.alert, + type: AttachmentType.alert, owner: 'securitySolutionFixture', }, }); @@ -72,7 +72,7 @@ export default ({ getService }: FtrProviderContext): void => { alertId: signalID2, index: defaultSignalsIndex, rule: { id: 'test-rule-id', name: 'test-index-id' }, - type: CommentType.alert, + type: AttachmentType.alert, owner: 'securitySolutionFixture', }, }); diff --git a/x-pack/test/cases_api_integration/security_and_spaces/tests/common/comments/find_comments.ts b/x-pack/test/cases_api_integration/security_and_spaces/tests/common/comments/find_comments.ts index 0256a0ac1e562e..48f2205444c036 100644 --- a/x-pack/test/cases_api_integration/security_and_spaces/tests/common/comments/find_comments.ts +++ b/x-pack/test/cases_api_integration/security_and_spaces/tests/common/comments/find_comments.ts @@ -8,7 +8,7 @@ import expect from '@kbn/expect'; import { CASES_URL, MAX_COMMENTS_PER_PAGE } from '@kbn/cases-plugin/common/constants'; -import { CommentType } from '@kbn/cases-plugin/common/api'; +import { AttachmentType } from '@kbn/cases-plugin/common/types/domain'; import { FtrProviderContext } from '../../../../common/ftr_provider_context'; import { getPostCaseRequest, @@ -106,7 +106,7 @@ export default ({ getService }: FtrProviderContext): void => { }); expect(caseComments.comments.length).to.eql(1); - expect(caseComments.comments[0].type).to.eql(CommentType.user); + expect(caseComments.comments[0].type).to.eql(AttachmentType.user); }); describe('unhappy paths', () => { diff --git a/x-pack/test/cases_api_integration/security_and_spaces/tests/common/comments/migrations.ts b/x-pack/test/cases_api_integration/security_and_spaces/tests/common/comments/migrations.ts index af66682af51553..463cb501f9ff9c 100644 --- a/x-pack/test/cases_api_integration/security_and_spaces/tests/common/comments/migrations.ts +++ b/x-pack/test/cases_api_integration/security_and_spaces/tests/common/comments/migrations.ts @@ -7,7 +7,7 @@ import expect from '@kbn/expect'; import { CASES_URL, SECURITY_SOLUTION_OWNER } from '@kbn/cases-plugin/common/constants'; -import { CommentResponseAlertsType } from '@kbn/cases-plugin/common/api'; +import { AlertAttachment } from '@kbn/cases-plugin/common/types/domain'; import { FtrProviderContext } from '../../../../../common/ftr_provider_context'; import { deleteAllCaseItems, getComment } from '../../../../common/lib/api'; @@ -84,7 +84,7 @@ export default function createGetTests({ getService }: FtrProviderContext) { supertest, caseId: 'e49ad6e0-cf9d-11eb-a603-13e7747d215c', commentId: 'ee59cdd0-cf9d-11eb-a603-13e7747d215c', - })) as CommentResponseAlertsType; + })) as AlertAttachment; expect(comment).to.have.property('rule'); expect(comment.rule.id).to.be(null); @@ -96,7 +96,7 @@ export default function createGetTests({ getService }: FtrProviderContext) { supertest, caseId: 'e49ad6e0-cf9d-11eb-a603-13e7747d215c', commentId: 'ae59cdd0-cf9d-11eb-a603-13e7747d215c', - })) as CommentResponseAlertsType; + })) as AlertAttachment; expect(comment).to.not.have.property('rule'); }); @@ -121,7 +121,7 @@ export default function createGetTests({ getService }: FtrProviderContext) { supertest, caseId: 'e49ad6e0-cf9d-11eb-a603-13e7747d215c', commentId: 'ee59cdd0-cf9d-11eb-a603-13e7747d215c', - })) as CommentResponseAlertsType; + })) as AlertAttachment; expect(comment).not.to.have.property('associationType'); }); @@ -131,7 +131,7 @@ export default function createGetTests({ getService }: FtrProviderContext) { supertest, caseId: 'e49ad6e0-cf9d-11eb-a603-13e7747d215c', commentId: 'ae59cdd0-cf9d-11eb-a603-13e7747d215c', - })) as CommentResponseAlertsType; + })) as AlertAttachment; expect(comment).not.to.have.property('associationType'); }); diff --git a/x-pack/test/cases_api_integration/security_and_spaces/tests/common/comments/patch_comment.ts b/x-pack/test/cases_api_integration/security_and_spaces/tests/common/comments/patch_comment.ts index 16029e3f846150..8c2c356b6090e6 100644 --- a/x-pack/test/cases_api_integration/security_and_spaces/tests/common/comments/patch_comment.ts +++ b/x-pack/test/cases_api_integration/security_and_spaces/tests/common/comments/patch_comment.ts @@ -9,10 +9,10 @@ import { set } from '@kbn/safer-lodash-set'; import { omit } from 'lodash/fp'; import expect from '@kbn/expect'; import { - AttributesTypeAlerts, - AttributesTypeUser, - CommentType, -} from '@kbn/cases-plugin/common/api'; + AlertAttachmentAttributes, + UserCommentAttachmentAttributes, + AttachmentType, +} from '@kbn/cases-plugin/common/types/domain'; import { FtrProviderContext } from '../../../../common/ftr_provider_context'; import { @@ -74,14 +74,14 @@ export default ({ getService }: FtrProviderContext): void => { id: patchedCase.comments![0].id, version: patchedCase.comments![0].version, comment: newComment, - type: CommentType.user, + type: AttachmentType.user, owner: 'securitySolutionFixture', }, }); - const userComment = updatedCase.comments![0] as AttributesTypeUser; + const userComment = updatedCase.comments![0] as UserCommentAttachmentAttributes; expect(userComment.comment).to.eql(newComment); - expect(userComment.type).to.eql(CommentType.user); + expect(userComment.type).to.eql(AttachmentType.user); expect(updatedCase.updated_by).to.eql(defaultUser); }); @@ -98,7 +98,7 @@ export default ({ getService }: FtrProviderContext): void => { req: { id: patchedCase.comments![0].id, version: patchedCase.comments![0].version, - type: CommentType.alert, + type: AttachmentType.alert, alertId: 'new-id', index: postCommentAlertReq.index, rule: { @@ -109,10 +109,10 @@ export default ({ getService }: FtrProviderContext): void => { }, }); - const alertComment = updatedCase.comments![0] as AttributesTypeAlerts; + const alertComment = updatedCase.comments![0] as AlertAttachmentAttributes; expect(alertComment.alertId).to.eql('new-id'); expect(alertComment.index).to.eql(postCommentAlertReq.index); - expect(alertComment.type).to.eql(CommentType.alert); + expect(alertComment.type).to.eql(AttachmentType.alert); expect(alertComment.rule).to.eql({ id: 'id', name: 'name', @@ -134,7 +134,7 @@ export default ({ getService }: FtrProviderContext): void => { req: { id: patchedCase.comments![0].id, version: patchedCase.comments![0].version, - type: CommentType.user, + type: AttachmentType.user, comment: postCommentUserReq.comment, owner: 'changedOwner', }, @@ -150,7 +150,7 @@ export default ({ getService }: FtrProviderContext): void => { req: { id: 'id', version: 'version', - type: CommentType.user, + type: AttachmentType.user, comment: 'comment', owner: 'securitySolutionFixture', }, @@ -165,7 +165,7 @@ export default ({ getService }: FtrProviderContext): void => { req: { id: 'id', version: 'version', - type: CommentType.user, + type: AttachmentType.user, comment: 'comment', owner: 'securitySolutionFixture', }, @@ -188,7 +188,7 @@ export default ({ getService }: FtrProviderContext): void => { req: { id: patchedCase.comments![0].id, version: patchedCase.comments![0].version, - type: CommentType.user, + type: AttachmentType.user, comment: longComment, owner: 'securitySolutionFixture', }, @@ -210,7 +210,7 @@ export default ({ getService }: FtrProviderContext): void => { req: { id: patchedCase.comments![0].id, version: patchedCase.comments![0].version, - type: CommentType.user, + type: AttachmentType.user, comment: '', owner: 'securitySolutionFixture', }, @@ -232,7 +232,7 @@ export default ({ getService }: FtrProviderContext): void => { req: { id: patchedCase.comments![0].id, version: patchedCase.comments![0].version, - type: CommentType.user, + type: AttachmentType.user, comment: ' ', owner: 'securitySolutionFixture', }, @@ -254,7 +254,7 @@ export default ({ getService }: FtrProviderContext): void => { req: { id: patchedCase.comments![0].id, version: patchedCase.comments![0].version, - type: CommentType.alert, + type: AttachmentType.alert, alertId: 'test-id', index: 'test-index', rule: { @@ -303,7 +303,7 @@ export default ({ getService }: FtrProviderContext): void => { id: patchedCase.comments![0].id, version: patchedCase.comments![0].version, comment: 'a comment', - type: CommentType.user, + type: AttachmentType.user, [attribute]: attribute, owner: 'securitySolutionFixture', }, @@ -321,7 +321,7 @@ export default ({ getService }: FtrProviderContext): void => { }); const allRequestAttributes = { - type: CommentType.alert, + type: AttachmentType.alert, index: 'test-index', alertId: 'test-id', rule: { @@ -361,7 +361,7 @@ export default ({ getService }: FtrProviderContext): void => { req: { id: patchedCase.comments![0].id, version: patchedCase.comments![0].version, - type: CommentType.alert, + type: AttachmentType.alert, index: 'test-index', alertId: 'test-id', rule: { @@ -391,7 +391,7 @@ export default ({ getService }: FtrProviderContext): void => { req: { id: patchedCase.comments![0].id, version: 'version-mismatch', - type: CommentType.user, + type: AttachmentType.user, comment: newComment, owner: 'securitySolutionFixture', }, @@ -483,11 +483,11 @@ export default ({ getService }: FtrProviderContext): void => { }); describe('alert format', () => { - type AlertComment = CommentType.alert; + type AlertComment = AttachmentType.alert; for (const [alertId, index, type] of [ - ['1', ['index1', 'index2'], CommentType.alert], - [['1', '2'], 'index', CommentType.alert], + ['1', ['index1', 'index2'], AttachmentType.alert], + [['1', '2'], 'index', AttachmentType.alert], ]) { it(`throws an error with an alert comment with contents id: ${alertId} indices: ${index} type: ${type}`, async () => { const postedCase = await createCase(supertest, postCaseReq); @@ -515,8 +515,8 @@ export default ({ getService }: FtrProviderContext): void => { } for (const [alertId, index, type] of [ - ['1', ['index1'], CommentType.alert], - [['1', '2'], ['index', 'other-index'], CommentType.alert], + ['1', ['index1'], AttachmentType.alert], + [['1', '2'], ['index', 'other-index'], AttachmentType.alert], ]) { it(`does not throw an error with an alert comment with contents id: ${alertId} indices: ${index} type: ${type}`, async () => { const postedCase = await createCase(supertest, postCaseReq); @@ -584,9 +584,9 @@ export default ({ getService }: FtrProviderContext): void => { auth: { user: secOnly, space: 'space1' }, }); - const userComment = updatedCase.comments![0] as AttributesTypeUser; + const userComment = updatedCase.comments![0] as UserCommentAttachmentAttributes; expect(userComment.comment).to.eql(newComment); - expect(userComment.type).to.eql(CommentType.user); + expect(userComment.type).to.eql(AttachmentType.user); expect(updatedCase.updated_by).to.eql(defaultUser); expect(userComment.owner).to.eql('securitySolutionFixture'); }); diff --git a/x-pack/test/cases_api_integration/security_and_spaces/tests/common/comments/post_comment.ts b/x-pack/test/cases_api_integration/security_and_spaces/tests/common/comments/post_comment.ts index 0bcde310a224b9..88723df678f8a4 100644 --- a/x-pack/test/cases_api_integration/security_and_spaces/tests/common/comments/post_comment.ts +++ b/x-pack/test/cases_api_integration/security_and_spaces/tests/common/comments/post_comment.ts @@ -10,14 +10,14 @@ import expect from '@kbn/expect'; import { ALERT_CASE_IDS, ALERT_WORKFLOW_STATUS } from '@kbn/rule-data-utils'; import { - CommentType, - AttributesTypeUser, - AttributesTypeAlerts, + AttachmentType, + UserCommentAttachmentAttributes, + AlertAttachmentAttributes, CaseStatuses, - CommentRequestExternalReferenceSOType, - CommentRequestAlertType, + ExternalReferenceSOAttachmentPayload, + AlertAttachmentPayload, ExternalReferenceStorageType, -} from '@kbn/cases-plugin/common/api'; +} from '@kbn/cases-plugin/common/types/domain'; import { FtrProviderContext } from '../../../../common/ftr_provider_context'; import { defaultUser, @@ -95,7 +95,7 @@ export default ({ getService }: FtrProviderContext): void => { params: postCommentUserReq, }); const comment = removeServerGeneratedPropertiesFromSavedObject( - patchedCase.comments![0] as AttributesTypeUser + patchedCase.comments![0] as UserCommentAttachmentAttributes ); expect(comment).to.eql({ @@ -121,7 +121,7 @@ export default ({ getService }: FtrProviderContext): void => { params: postCommentAlertReq, }); const comment = removeServerGeneratedPropertiesFromSavedObject( - patchedCase.comments![0] as AttributesTypeAlerts + patchedCase.comments![0] as AlertAttachmentAttributes ); expect(comment).to.eql({ @@ -179,7 +179,7 @@ export default ({ getService }: FtrProviderContext): void => { }); const fileAttachment = - caseWithAttachments.comments![0] as CommentRequestExternalReferenceSOType; + caseWithAttachments.comments![0] as ExternalReferenceSOAttachmentPayload; expect(caseWithAttachments.totalComment).to.be(1); expect(fileAttachment.externalReferenceMetadata).to.eql(fileAttachmentMetadata); @@ -270,7 +270,7 @@ export default ({ getService }: FtrProviderContext): void => { caseId: postedCase.id, // @ts-expect-error params: { - type: CommentType.user, + type: AttachmentType.user, }, expectedHttpCode: 400, }); @@ -327,7 +327,7 @@ export default ({ getService }: FtrProviderContext): void => { supertest, caseId: postedCase.id, params: { - type: CommentType.user, + type: AttachmentType.user, [attribute]: attribute, comment: 'a comment', owner: 'securitySolutionFixture', @@ -341,7 +341,7 @@ export default ({ getService }: FtrProviderContext): void => { const postedCase = await createCase(supertest, postCaseReq); const allRequestAttributes = { - type: CommentType.alert, + type: AttachmentType.alert, index: 'test-index', alertId: 'test-id', rule: { @@ -371,7 +371,7 @@ export default ({ getService }: FtrProviderContext): void => { supertest, caseId: postedCase.id, params: { - type: CommentType.alert, + type: AttachmentType.alert, [attribute]: attribute, alertId: 'test-id', index: 'test-index', @@ -475,7 +475,7 @@ export default ({ getService }: FtrProviderContext): void => { const postedCase = await createCase(supertest, postCaseReq); const attachments = Array(100).fill({ - type: CommentType.externalReference as const, + type: AttachmentType.externalReference as const, owner: 'securitySolutionFixture', externalReferenceAttachmentTypeId: '.test', externalReferenceId: 'so-id', @@ -499,7 +499,7 @@ export default ({ getService }: FtrProviderContext): void => { params: { persistableStateAttachmentTypeId: '.test', persistableStateAttachmentState: {}, - type: CommentType.persistableState as const, + type: AttachmentType.persistableState as const, owner: 'securitySolutionFixture', }, expectedHttpCode: 400, @@ -512,7 +512,7 @@ export default ({ getService }: FtrProviderContext): void => { const attachments = Array(100).fill({ persistableStateAttachmentTypeId: '.test', persistableStateAttachmentState: {}, - type: CommentType.persistableState as const, + type: AttachmentType.persistableState as const, owner: 'securitySolutionFixture', }); @@ -527,7 +527,7 @@ export default ({ getService }: FtrProviderContext): void => { supertest, caseId: postedCase.id, params: { - type: CommentType.externalReference as const, + type: AttachmentType.externalReference as const, owner: 'securitySolutionFixture', externalReferenceAttachmentTypeId: '.test', externalReferenceId: 'so-id', @@ -579,7 +579,7 @@ export default ({ getService }: FtrProviderContext): void => { name: 'name', }, owner: 'securitySolutionFixture', - type: CommentType.alert, + type: AttachmentType.alert, }, expectedHttpCode, auth, @@ -873,7 +873,7 @@ export default ({ getService }: FtrProviderContext): void => { name: 'name', }, owner: 'observabilityFixture', - type: CommentType.alert, + type: AttachmentType.alert, }, }); } @@ -915,7 +915,7 @@ export default ({ getService }: FtrProviderContext): void => { name: 'name', }, owner: 'observabilityFixture', - type: CommentType.alert, + type: AttachmentType.alert, }, }); @@ -948,7 +948,7 @@ export default ({ getService }: FtrProviderContext): void => { name: 'name', }, owner: 'observabilityFixture', - type: CommentType.alert, + type: AttachmentType.alert, }, expectedHttpCode: 400, }); @@ -977,7 +977,7 @@ export default ({ getService }: FtrProviderContext): void => { name: 'name', }, owner: 'observabilityFixture', - type: CommentType.alert, + type: AttachmentType.alert, }, auth: { user: obsOnlyReadAlerts, space: 'space1' }, expectedHttpCode: 200, @@ -1007,7 +1007,7 @@ export default ({ getService }: FtrProviderContext): void => { name: 'name', }, owner: 'observabilityFixture', - type: CommentType.alert, + type: AttachmentType.alert, }, auth: { user: obsSec, space: 'space1' }, expectedHttpCode: 403, @@ -1017,11 +1017,11 @@ export default ({ getService }: FtrProviderContext): void => { }); describe('alert format', () => { - type AlertComment = CommentType.alert; + type AlertComment = AttachmentType.alert; for (const [alertId, index, type] of [ - ['1', ['index1', 'index2'], CommentType.alert], - [['1', '2'], 'index', CommentType.alert], + ['1', ['index1', 'index2'], AttachmentType.alert], + [['1', '2'], 'index', AttachmentType.alert], ]) { it(`throws an error with an alert comment with contents id: ${alertId} indices: ${index} type: ${type}`, async () => { const postedCase = await createCase(supertest, postCaseReq); @@ -1035,8 +1035,8 @@ export default ({ getService }: FtrProviderContext): void => { } for (const [alertId, index, type] of [ - ['1', ['index1'], CommentType.alert], - [['1', '2'], ['index', 'other-index'], CommentType.alert], + ['1', ['index1'], AttachmentType.alert], + [['1', '2'], ['index', 'other-index'], AttachmentType.alert], ]) { it(`does not throw an error with an alert comment with contents id: ${alertId} indices: ${index} type: ${type}`, async () => { const postedCase = await createCase(supertest, postCaseReq); @@ -1116,7 +1116,7 @@ export default ({ getService }: FtrProviderContext): void => { const attachments = await getAllComments({ supertest, caseId: postedCase.id }); expect(attachments.length).to.eql(2); - const secondAttachment = attachments[1] as CommentRequestAlertType; + const secondAttachment = attachments[1] as AlertAttachmentPayload; expect(secondAttachment.alertId).to.eql(['test-id-3']); expect(secondAttachment.index).to.eql(['test-index-3']); diff --git a/x-pack/test/cases_api_integration/security_and_spaces/tests/common/internal/bulk_create_attachments.ts b/x-pack/test/cases_api_integration/security_and_spaces/tests/common/internal/bulk_create_attachments.ts index e5eaedb6dae8c5..3c3748a844ea6a 100644 --- a/x-pack/test/cases_api_integration/security_and_spaces/tests/common/internal/bulk_create_attachments.ts +++ b/x-pack/test/cases_api_integration/security_and_spaces/tests/common/internal/bulk_create_attachments.ts @@ -9,14 +9,13 @@ import { omit } from 'lodash/fp'; import expect from '@kbn/expect'; import { ALERT_CASE_IDS, ALERT_WORKFLOW_STATUS } from '@kbn/rule-data-utils'; +import { Case, AttachmentType } from '@kbn/cases-plugin/common'; +import { BulkCreateAttachmentsRequest } from '@kbn/cases-plugin/common/types/api'; import { - BulkCreateCommentRequest, - Case, + ExternalReferenceSOAttachmentPayload, CaseStatuses, - CommentRequestExternalReferenceSOType, - CommentType, ExternalReferenceStorageType, -} from '@kbn/cases-plugin/common/api'; +} from '@kbn/cases-plugin/common/types/domain'; import { FtrProviderContext } from '../../../../common/ftr_provider_context'; import { defaultUser, @@ -83,7 +82,7 @@ export default ({ getService }: FtrProviderContext): void => { const validateCommentsIgnoringOrder = ( comments: Case['comments'], - attachments: BulkCreateCommentRequest + attachments: BulkCreateAttachmentsRequest ) => { expect(comments?.length).to.eql(attachments.length); @@ -183,9 +182,9 @@ export default ({ getService }: FtrProviderContext): void => { }); const firstFileAttachment = - caseWithAttachments.comments![0] as CommentRequestExternalReferenceSOType; + caseWithAttachments.comments![0] as ExternalReferenceSOAttachmentPayload; const secondFileAttachment = - caseWithAttachments.comments![1] as CommentRequestExternalReferenceSOType; + caseWithAttachments.comments![1] as ExternalReferenceSOAttachmentPayload; expect(caseWithAttachments.totalComment).to.be(2); expect(firstFileAttachment.externalReferenceMetadata).to.eql(fileAttachmentMetadata); @@ -369,7 +368,7 @@ export default ({ getService }: FtrProviderContext): void => { it('400s when attempting to add more than 100 attachments', async () => { const comment = { - type: CommentType.user, + type: AttachmentType.user, comment: 'test', owner: 'securitySolutionFixture', }; @@ -395,12 +394,12 @@ export default ({ getService }: FtrProviderContext): void => { caseId: postedCase.id, params: [ { - type: CommentType.user, + type: AttachmentType.user, comment: 'test', owner: 'securitySolutionFixture', }, { - type: CommentType.user, + type: AttachmentType.user, comment: 'test', owner: 'observabilityFixture', }, @@ -416,7 +415,7 @@ export default ({ getService }: FtrProviderContext): void => { caseId: postedCase.id, params: [ { - type: CommentType.user, + type: AttachmentType.user, comment: 'test', owner: 'securitySolutionFixture', }, @@ -436,13 +435,13 @@ export default ({ getService }: FtrProviderContext): void => { caseId: postedCase.id, params: [ { - type: CommentType.user, + type: AttachmentType.user, comment: 'test', owner: 'securitySolutionFixture', }, // @ts-expect-error { - type: CommentType.user, + type: AttachmentType.user, }, ], expectedHttpCode: 400, @@ -457,7 +456,7 @@ export default ({ getService }: FtrProviderContext): void => { caseId: 'case-id', params: [ { - type: CommentType.user, + type: AttachmentType.user, comment: longComment, owner: 'securitySolutionFixture', }, @@ -475,12 +474,12 @@ export default ({ getService }: FtrProviderContext): void => { caseId: postedCase.id, params: [ { - type: CommentType.user, + type: AttachmentType.user, comment: 'test', owner: 'securitySolutionFixture', }, { - type: CommentType.user, + type: AttachmentType.user, [attribute]: attribute, comment: 'a comment', owner: 'securitySolutionFixture', @@ -495,7 +494,7 @@ export default ({ getService }: FtrProviderContext): void => { const postedCase = await createCase(supertest, postCaseReq); const allRequestAttributes = { - type: CommentType.alert, + type: AttachmentType.alert, index: 'test-index', alertId: 'test-id', rule: { @@ -512,7 +511,7 @@ export default ({ getService }: FtrProviderContext): void => { caseId: postedCase.id, params: [ { - type: CommentType.user, + type: AttachmentType.user, comment: 'test', owner: 'securitySolutionFixture', }, @@ -533,12 +532,12 @@ export default ({ getService }: FtrProviderContext): void => { caseId: postedCase.id, params: [ { - type: CommentType.user, + type: AttachmentType.user, comment: 'test', owner: 'securitySolutionFixture', }, { - type: CommentType.alert, + type: AttachmentType.alert, [attribute]: attribute, alertId: 'test-id', index: 'test-index', @@ -560,7 +559,7 @@ export default ({ getService }: FtrProviderContext): void => { caseId: 'not-exists', params: [ { - type: CommentType.user, + type: AttachmentType.user, comment: 'test', owner: 'securitySolutionFixture', }, @@ -589,7 +588,7 @@ export default ({ getService }: FtrProviderContext): void => { caseId: postedCase.id, params: [ { - type: CommentType.alert, + type: AttachmentType.alert, alertId: 'test-id', index: 'test-index', rule: { @@ -728,7 +727,7 @@ export default ({ getService }: FtrProviderContext): void => { supertest, caseId: postedCase.id, params: { - type: CommentType.externalReference as const, + type: AttachmentType.externalReference as const, owner: 'securitySolutionFixture', externalReferenceAttachmentTypeId: '.test', externalReferenceId: 'so-id', @@ -744,7 +743,7 @@ export default ({ getService }: FtrProviderContext): void => { const persistableStateAttachments = Array(100).fill({ persistableStateAttachmentTypeId: '.test', persistableStateAttachmentState: {}, - type: CommentType.persistableState as const, + type: AttachmentType.persistableState as const, owner: 'securitySolutionFixture', }); @@ -765,14 +764,14 @@ export default ({ getService }: FtrProviderContext): void => { params: { persistableStateAttachmentTypeId: '.test', persistableStateAttachmentState: {}, - type: CommentType.persistableState as const, + type: AttachmentType.persistableState as const, owner: 'securitySolutionFixture', }, expectedHttpCode: 200, }); const externalRequestAttachments = Array(100).fill({ - type: CommentType.externalReference as const, + type: AttachmentType.externalReference as const, owner: 'securitySolutionFixture', externalReferenceAttachmentTypeId: '.test', externalReferenceId: 'so-id', @@ -828,7 +827,7 @@ export default ({ getService }: FtrProviderContext): void => { name: 'name', }, owner: 'securitySolutionFixture', - type: CommentType.alert, + type: AttachmentType.alert, })), expectedHttpCode, auth, @@ -1131,7 +1130,7 @@ export default ({ getService }: FtrProviderContext): void => { name: 'name', }, owner: 'observabilityFixture', - type: CommentType.alert, + type: AttachmentType.alert, }, ], }); @@ -1175,7 +1174,7 @@ export default ({ getService }: FtrProviderContext): void => { name: 'name', }, owner: 'observabilityFixture', - type: CommentType.alert, + type: AttachmentType.alert, }, ], }); @@ -1210,7 +1209,7 @@ export default ({ getService }: FtrProviderContext): void => { name: 'name', }, owner: 'securitySolutionFixture', - type: CommentType.alert, + type: AttachmentType.alert, }, ], expectedHttpCode: 400, @@ -1241,7 +1240,7 @@ export default ({ getService }: FtrProviderContext): void => { name: 'name', }, owner: 'observabilityFixture', - type: CommentType.alert, + type: AttachmentType.alert, }, ], auth: { user: obsOnlyReadAlerts, space: 'space1' }, @@ -1273,7 +1272,7 @@ export default ({ getService }: FtrProviderContext): void => { name: 'name', }, owner: 'observabilityFixture', - type: CommentType.alert, + type: AttachmentType.alert, }, ], auth: { user: obsSec, space: 'space1' }, @@ -1284,11 +1283,11 @@ export default ({ getService }: FtrProviderContext): void => { }); describe('alert format', () => { - type AlertComment = CommentType.alert; + type AlertComment = AttachmentType.alert; for (const [alertId, index, type] of [ - ['1', ['index1', 'index2'], CommentType.alert], - [['1', '2'], 'index', CommentType.alert], + ['1', ['index1', 'index2'], AttachmentType.alert], + [['1', '2'], 'index', AttachmentType.alert], ]) { it(`throws an error with an alert comment with contents id: ${alertId} indices: ${index} type: ${type}`, async () => { const postedCase = await createCase(supertest, postCaseReq); @@ -1308,13 +1307,13 @@ export default ({ getService }: FtrProviderContext): void => { ...postCommentAlertReq, alertId: '1', index: ['index1'], - type: CommentType.alert as const, + type: AttachmentType.alert as const, }, { ...postCommentAlertReq, alertId: ['1', '2'], index: ['index', 'other-index'], - type: CommentType.alert as const, + type: AttachmentType.alert as const, }, ]; diff --git a/x-pack/test/cases_api_integration/security_and_spaces/tests/common/internal/bulk_get_attachments.ts b/x-pack/test/cases_api_integration/security_and_spaces/tests/common/internal/bulk_get_attachments.ts index 8907f7e28841cf..40d5b469484816 100644 --- a/x-pack/test/cases_api_integration/security_and_spaces/tests/common/internal/bulk_get_attachments.ts +++ b/x-pack/test/cases_api_integration/security_and_spaces/tests/common/internal/bulk_get_attachments.ts @@ -7,11 +7,11 @@ import expect from '@kbn/expect'; import { - AttributesTypeExternalReference, - AttributesTypeExternalReferenceSO, + ExternalReferenceAttachmentAttributes, + ExternalReferenceSOAttachmentAttributes, Case, - CommentResponseTypePersistableState, -} from '@kbn/cases-plugin/common/api'; + PersistableStateAttachment, +} from '@kbn/cases-plugin/common/types/domain'; import { FtrProviderContext } from '../../../../common/ftr_provider_context'; import { @@ -124,7 +124,7 @@ export default ({ getService }: FtrProviderContext): void => { supertest, }); - const persistableState = response.attachments[0] as CommentResponseTypePersistableState; + const persistableState = response.attachments[0] as PersistableStateAttachment; expect(persistableState.persistableStateAttachmentState).to.eql( persistableStateAttachment.persistableStateAttachmentState @@ -145,7 +145,7 @@ export default ({ getService }: FtrProviderContext): void => { supertest, }); - const externalRefSO = response.attachments[0] as AttributesTypeExternalReferenceSO; + const externalRefSO = response.attachments[0] as ExternalReferenceSOAttachmentAttributes; expect(externalRefSO.externalReferenceId).to.eql( postExternalReferenceSOReq.externalReferenceId @@ -172,7 +172,7 @@ export default ({ getService }: FtrProviderContext): void => { supertest, }); - const externalRefES = response.attachments[0] as AttributesTypeExternalReference; + const externalRefES = response.attachments[0] as ExternalReferenceAttachmentAttributes; expect(externalRefES.externalReferenceId).to.eql( postExternalReferenceESReq.externalReferenceId diff --git a/x-pack/test/cases_api_integration/security_and_spaces/tests/common/internal/bulk_get_cases.ts b/x-pack/test/cases_api_integration/security_and_spaces/tests/common/internal/bulk_get_cases.ts index 449251377a077d..0a30e2ef7bc98b 100644 --- a/x-pack/test/cases_api_integration/security_and_spaces/tests/common/internal/bulk_get_cases.ts +++ b/x-pack/test/cases_api_integration/security_and_spaces/tests/common/internal/bulk_get_cases.ts @@ -6,7 +6,7 @@ */ import expect from '@kbn/expect'; -import { CommentType } from '@kbn/cases-plugin/common'; +import { AttachmentType } from '@kbn/cases-plugin/common'; import { MAX_BULK_GET_CASES } from '@kbn/cases-plugin/common/constants'; import { getPostCaseRequest, postCaseReq } from '../../../../common/lib/mock'; import { FtrProviderContext } from '../../../../common/ftr_provider_context'; @@ -71,7 +71,7 @@ export default ({ getService }: FtrProviderContext): void => { alertId: ['test-id-1', 'test-id-2'], index: ['test-index', 'test-index'], rule: { id: 'test-rule-id', name: 'test-index-id' }, - type: CommentType.alert, + type: AttachmentType.alert, owner: 'securitySolutionFixture', }, }); @@ -83,7 +83,7 @@ export default ({ getService }: FtrProviderContext): void => { alertId: ['test-id-3'], index: ['test-index'], rule: { id: 'test-rule-id', name: 'test-index-id' }, - type: CommentType.alert, + type: AttachmentType.alert, owner: 'securitySolutionFixture', }, }); @@ -93,7 +93,7 @@ export default ({ getService }: FtrProviderContext): void => { caseId: caseOne.id, params: { comment: 'a comment', - type: CommentType.user, + type: AttachmentType.user, owner: 'securitySolutionFixture', }, }); diff --git a/x-pack/test/cases_api_integration/security_and_spaces/tests/common/internal/user_actions_get_users.ts b/x-pack/test/cases_api_integration/security_and_spaces/tests/common/internal/user_actions_get_users.ts index 030f828baf3d72..e49c48fbf2347e 100644 --- a/x-pack/test/cases_api_integration/security_and_spaces/tests/common/internal/user_actions_get_users.ts +++ b/x-pack/test/cases_api_integration/security_and_spaces/tests/common/internal/user_actions_get_users.ts @@ -8,7 +8,7 @@ import expect from '@kbn/expect'; import { Cookie } from 'tough-cookie'; import { UserProfile } from '@kbn/security-plugin/common'; -import { GetCaseUsersResponseRt } from '@kbn/cases-plugin/common/api'; +import { GetCaseUsersResponseRt } from '@kbn/cases-plugin/common/types/api'; import { securitySolutionOnlyAllSpacesRole } from '../../../../common/lib/authentication/roles'; import { getPostCaseRequest } from '../../../../common/lib/mock'; import { diff --git a/x-pack/test/cases_api_integration/security_and_spaces/tests/common/metrics/get_cases_metrics.ts b/x-pack/test/cases_api_integration/security_and_spaces/tests/common/metrics/get_cases_metrics.ts index c191cfc9e6d881..24b3defbc5d883 100644 --- a/x-pack/test/cases_api_integration/security_and_spaces/tests/common/metrics/get_cases_metrics.ts +++ b/x-pack/test/cases_api_integration/security_and_spaces/tests/common/metrics/get_cases_metrics.ts @@ -6,7 +6,7 @@ */ import expect from '@kbn/expect'; -import { CaseStatuses } from '@kbn/cases-plugin/common/api'; +import { CaseStatuses } from '@kbn/cases-plugin/common/types/domain'; import { secOnly, obsOnlyRead, diff --git a/x-pack/test/cases_api_integration/security_and_spaces/tests/common/user_actions/find_user_actions.ts b/x-pack/test/cases_api_integration/security_and_spaces/tests/common/user_actions/find_user_actions.ts index 36d7285e85aae7..9b160116b13508 100644 --- a/x-pack/test/cases_api_integration/security_and_spaces/tests/common/user_actions/find_user_actions.ts +++ b/x-pack/test/cases_api_integration/security_and_spaces/tests/common/user_actions/find_user_actions.ts @@ -6,7 +6,7 @@ */ import expect from '@kbn/expect'; -import { Case, CaseSeverity, CaseStatuses } from '@kbn/cases-plugin/common/api'; +import { Case, CaseSeverity, CaseStatuses } from '@kbn/cases-plugin/common/types/domain'; import { MAX_USER_ACTIONS_PER_PAGE } from '@kbn/cases-plugin/common/constants'; import { UserActionTypes, diff --git a/x-pack/test/cases_api_integration/security_and_spaces/tests/common/user_actions/get_all_user_actions.ts b/x-pack/test/cases_api_integration/security_and_spaces/tests/common/user_actions/get_all_user_actions.ts index d668e3f382b64c..4679a03b4d8af0 100644 --- a/x-pack/test/cases_api_integration/security_and_spaces/tests/common/user_actions/get_all_user_actions.ts +++ b/x-pack/test/cases_api_integration/security_and_spaces/tests/common/user_actions/get_all_user_actions.ts @@ -11,11 +11,12 @@ import { Case, CaseSeverity, CaseStatuses, - CommentRequestUserType, - CommentType, - getCaseUserActionUrl, -} from '@kbn/cases-plugin/common/api'; -import { CreateCaseUserAction, ConnectorTypes } from '@kbn/cases-plugin/common/types/domain'; + UserCommentAttachmentPayload, + AttachmentType, + CreateCaseUserAction, + ConnectorTypes, +} from '@kbn/cases-plugin/common/types/domain'; +import { getCaseUserActionUrl } from '@kbn/cases-plugin/common/api'; import { FtrProviderContext } from '../../../../common/ftr_provider_context'; import { postCaseReq, postCommentUserReq, getPostCaseRequest } from '../../../../common/lib/mock'; import { @@ -293,7 +294,7 @@ export default ({ getService }: FtrProviderContext): void => { id: caseWithComments.comments![0].id, version: caseWithComments.comments![0].version, comment: newComment, - type: CommentType.user, + type: AttachmentType.user, owner: 'securitySolutionFixture', }, }); @@ -308,7 +309,7 @@ export default ({ getService }: FtrProviderContext): void => { expect(commentUserAction.payload).to.eql({ comment: { comment: newComment, - type: CommentType.user, + type: AttachmentType.user, owner: 'securitySolutionFixture', }, }); @@ -332,7 +333,7 @@ export default ({ getService }: FtrProviderContext): void => { const commentUserAction = userActions[2]; const { id, version: _, ...restComment } = caseWithComments.comments![0]; - const castedUserComment = restComment as CommentRequestUserType; + const castedUserComment = restComment as UserCommentAttachmentPayload; expect(userActions.length).to.eql(3); expect(commentUserAction.type).to.eql('comment'); diff --git a/x-pack/test/cases_api_integration/security_and_spaces/tests/common/user_actions/get_user_action_stats.ts b/x-pack/test/cases_api_integration/security_and_spaces/tests/common/user_actions/get_user_action_stats.ts index 29672ab14d7c36..1360bbb966e4ea 100644 --- a/x-pack/test/cases_api_integration/security_and_spaces/tests/common/user_actions/get_user_action_stats.ts +++ b/x-pack/test/cases_api_integration/security_and_spaces/tests/common/user_actions/get_user_action_stats.ts @@ -6,7 +6,7 @@ */ import expect from '@kbn/expect'; -import { Case, CaseSeverity, CaseStatuses } from '@kbn/cases-plugin/common/api'; +import { Case, CaseSeverity, CaseStatuses } from '@kbn/cases-plugin/common/types/domain'; import { ConnectorTypes } from '@kbn/cases-plugin/common/types/domain'; import { diff --git a/x-pack/test/cases_api_integration/security_and_spaces/tests/common/user_actions/migrations.ts b/x-pack/test/cases_api_integration/security_and_spaces/tests/common/user_actions/migrations.ts index 3d16cc32220045..627a3b89eacebc 100644 --- a/x-pack/test/cases_api_integration/security_and_spaces/tests/common/user_actions/migrations.ts +++ b/x-pack/test/cases_api_integration/security_and_spaces/tests/common/user_actions/migrations.ts @@ -7,7 +7,7 @@ import expect from '@kbn/expect'; import { SECURITY_SOLUTION_OWNER } from '@kbn/cases-plugin/common/constants'; -import { CommentType } from '@kbn/cases-plugin/common/api'; +import { AttachmentType } from '@kbn/cases-plugin/common/types/domain'; import { CaseUserActionsDeprecatedResponse } from '@kbn/cases-plugin/common/types/api'; import { UserActionTypes } from '@kbn/cases-plugin/common/types/domain'; import { FtrProviderContext } from '../../../../../common/ftr_provider_context'; @@ -915,7 +915,7 @@ export default function createGetTests({ getService }: FtrProviderContext) { const userAction = getUserActionById(userActions, 'a5509250-cf9d-11eb-a603-13e7747d215c')!; - expect(userAction.payload.comment.type).to.be(CommentType.alert); + expect(userAction.payload.comment.type).to.be(AttachmentType.alert); expect(userAction.payload.comment.alertId).to.be( '4eb4cd05b85bc65c7b9f22b776e0136f970f7538eb0d1b2e6e8c7d35b2e875cb' ); diff --git a/x-pack/test/cases_api_integration/security_and_spaces/tests/trial/cases/find_cases.ts b/x-pack/test/cases_api_integration/security_and_spaces/tests/trial/cases/find_cases.ts index f80cd6742ab86d..a8bfb21c253ca4 100644 --- a/x-pack/test/cases_api_integration/security_and_spaces/tests/trial/cases/find_cases.ts +++ b/x-pack/test/cases_api_integration/security_and_spaces/tests/trial/cases/find_cases.ts @@ -7,7 +7,7 @@ import expect from '@kbn/expect'; import { Cookie } from 'tough-cookie'; -import { User } from '@kbn/cases-plugin/common/api'; +import { User } from '@kbn/cases-plugin/common/types/domain'; import { UserProfile } from '@kbn/security-plugin/common'; import { FtrProviderContext } from '../../../../common/ftr_provider_context'; diff --git a/x-pack/test/cases_api_integration/security_and_spaces/tests/trial/cases/push_case.ts b/x-pack/test/cases_api_integration/security_and_spaces/tests/trial/cases/push_case.ts index 3aa368c631f653..ac335946d105fe 100644 --- a/x-pack/test/cases_api_integration/security_and_spaces/tests/trial/cases/push_case.ts +++ b/x-pack/test/cases_api_integration/security_and_spaces/tests/trial/cases/push_case.ts @@ -10,7 +10,7 @@ import http from 'http'; import expect from '@kbn/expect'; -import { CaseStatuses, CommentType, User } from '@kbn/cases-plugin/common/api'; +import { CaseStatuses, AttachmentType, User } from '@kbn/cases-plugin/common/types/domain'; import { RecordingServiceNowSimulator } from '@kbn/actions-simulators-plugin/server/servicenow_simulation'; import { CaseConnector } from '@kbn/cases-plugin/common/types/domain'; import { FtrProviderContext } from '../../../../common/ftr_provider_context'; @@ -646,7 +646,7 @@ export default ({ getService }: FtrProviderContext): void => { alertId: signalID, index: defaultSignalsIndex, rule: { id: 'test-rule-id', name: 'test-index-id' }, - type: CommentType.alert, + type: AttachmentType.alert, owner: 'securitySolutionFixture', }, }); @@ -660,7 +660,7 @@ export default ({ getService }: FtrProviderContext): void => { alertId: signalID2, index: defaultSignalsIndex, rule: { id: 'test-rule-id', name: 'test-index-id' }, - type: CommentType.alert, + type: AttachmentType.alert, owner: 'securitySolutionFixture', }, }); diff --git a/x-pack/test/cases_api_integration/security_and_spaces/tests/trial/cases/user_actions/get_all_user_actions.ts b/x-pack/test/cases_api_integration/security_and_spaces/tests/trial/cases/user_actions/get_all_user_actions.ts index 381b0f52bfbf92..7e3cdfe00d61bd 100644 --- a/x-pack/test/cases_api_integration/security_and_spaces/tests/trial/cases/user_actions/get_all_user_actions.ts +++ b/x-pack/test/cases_api_integration/security_and_spaces/tests/trial/cases/user_actions/get_all_user_actions.ts @@ -7,7 +7,7 @@ import http from 'http'; import expect from '@kbn/expect'; -import { User } from '@kbn/cases-plugin/common/api'; +import { User } from '@kbn/cases-plugin/common/types/domain'; import { PushedUserAction, UserActionWithDeprecatedResponse, diff --git a/x-pack/test/cases_api_integration/security_and_spaces/tests/trial/internal/get_connectors.ts b/x-pack/test/cases_api_integration/security_and_spaces/tests/trial/internal/get_connectors.ts index fc753bf1a8a3b6..d002cc7086b68e 100644 --- a/x-pack/test/cases_api_integration/security_and_spaces/tests/trial/internal/get_connectors.ts +++ b/x-pack/test/cases_api_integration/security_and_spaces/tests/trial/internal/get_connectors.ts @@ -8,8 +8,12 @@ import http from 'http'; import expect from '@kbn/expect'; -import { CaseSeverity, CaseStatuses } from '@kbn/cases-plugin/common/api'; -import { ConnectorTypes, UserActionTypes } from '@kbn/cases-plugin/common/types/domain'; +import { + ConnectorTypes, + UserActionTypes, + CaseSeverity, + CaseStatuses, +} from '@kbn/cases-plugin/common/types/domain'; import { globalRead, noKibanaPrivileges, diff --git a/x-pack/test/cases_api_integration/security_and_spaces/tests/trial/user_profiles/get_current.ts b/x-pack/test/cases_api_integration/security_and_spaces/tests/trial/user_profiles/get_current.ts index 1423db9a70a2d5..038a8f53b93bcf 100644 --- a/x-pack/test/cases_api_integration/security_and_spaces/tests/trial/user_profiles/get_current.ts +++ b/x-pack/test/cases_api_integration/security_and_spaces/tests/trial/user_profiles/get_current.ts @@ -6,9 +6,8 @@ */ import expect from '@kbn/expect'; -import { CaseStatuses, CommentType } from '@kbn/cases-plugin/common'; -import { User } from '@kbn/cases-plugin/common/api'; -import { CreateCaseUserAction } from '@kbn/cases-plugin/common/types/domain'; +import { AttachmentType } from '@kbn/cases-plugin/common'; +import { CreateCaseUserAction, User, CaseStatuses } from '@kbn/cases-plugin/common/types/domain'; import { setupSuperUserProfile } from '../../../../common/lib/api/user_profiles'; import { FtrProviderContext } from '../../../../common/ftr_provider_context'; import { superUser } from '../../../../common/lib/authentication/users'; @@ -216,7 +215,7 @@ export default function ({ getService }: FtrProviderContext) { id: patchedCase.comments![0].id, version: patchedCase.comments![0].version, comment: 'a new comment', - type: CommentType.user, + type: AttachmentType.user, owner: 'securitySolutionFixture', }, auth: null, @@ -251,7 +250,7 @@ export default function ({ getService }: FtrProviderContext) { id: patchedCase.comments![0].id, version: patchedCase.comments![0].version, comment: 'a new comment', - type: CommentType.user, + type: AttachmentType.user, owner: 'securitySolutionFixture', }, }); diff --git a/x-pack/test/cases_api_integration/spaces_only/tests/common/cases/status/get_status.ts b/x-pack/test/cases_api_integration/spaces_only/tests/common/cases/status/get_status.ts index e8a8ef6147f6fa..934ba92a175d66 100644 --- a/x-pack/test/cases_api_integration/spaces_only/tests/common/cases/status/get_status.ts +++ b/x-pack/test/cases_api_integration/spaces_only/tests/common/cases/status/get_status.ts @@ -6,7 +6,7 @@ */ import expect from '@kbn/expect'; -import { CaseStatuses } from '@kbn/cases-plugin/common/api'; +import { CaseStatuses } from '@kbn/cases-plugin/common/types/domain'; import { FtrProviderContext } from '../../../../../common/ftr_provider_context'; import { postCaseReq } from '../../../../../common/lib/mock'; diff --git a/x-pack/test/cases_api_integration/spaces_only/tests/common/comments/patch_comment.ts b/x-pack/test/cases_api_integration/spaces_only/tests/common/comments/patch_comment.ts index ff30df54f6efe3..1264e5b95591a9 100644 --- a/x-pack/test/cases_api_integration/spaces_only/tests/common/comments/patch_comment.ts +++ b/x-pack/test/cases_api_integration/spaces_only/tests/common/comments/patch_comment.ts @@ -6,7 +6,10 @@ */ import expect from '@kbn/expect'; -import { AttributesTypeUser, CommentType } from '@kbn/cases-plugin/common/api'; +import { + UserCommentAttachmentAttributes, + AttachmentType, +} from '@kbn/cases-plugin/common/types/domain'; import { FtrProviderContext } from '../../../../common/ftr_provider_context'; import { nullUser, postCaseReq, postCommentUserReq } from '../../../../common/lib/mock'; @@ -50,15 +53,15 @@ export default ({ getService }: FtrProviderContext): void => { id: patchedCase.comments![0].id, version: patchedCase.comments![0].version, comment: newComment, - type: CommentType.user, + type: AttachmentType.user, owner: 'securitySolutionFixture', }, auth: authSpace1, }); - const userComment = updatedCase.comments![0] as AttributesTypeUser; + const userComment = updatedCase.comments![0] as UserCommentAttachmentAttributes; expect(userComment.comment).to.eql(newComment); - expect(userComment.type).to.eql(CommentType.user); + expect(userComment.type).to.eql(AttachmentType.user); expect(updatedCase.updated_by).to.eql(nullUser); }); @@ -79,7 +82,7 @@ export default ({ getService }: FtrProviderContext): void => { id: patchedCase.comments![0].id, version: patchedCase.comments![0].version, comment: newComment, - type: CommentType.user, + type: AttachmentType.user, owner: 'securitySolutionFixture', }, auth: getAuthWithSuperUser('space2'), diff --git a/x-pack/test/cases_api_integration/spaces_only/tests/common/comments/post_comment.ts b/x-pack/test/cases_api_integration/spaces_only/tests/common/comments/post_comment.ts index 12793cb83fed9e..dba0351322d8db 100644 --- a/x-pack/test/cases_api_integration/spaces_only/tests/common/comments/post_comment.ts +++ b/x-pack/test/cases_api_integration/spaces_only/tests/common/comments/post_comment.ts @@ -6,7 +6,7 @@ */ import expect from '@kbn/expect'; -import { AttributesTypeUser } from '@kbn/cases-plugin/common/api'; +import { UserCommentAttachmentAttributes } from '@kbn/cases-plugin/common/types/domain'; import { FtrProviderContext } from '../../../../common/ftr_provider_context'; import { nullUser, postCaseReq, postCommentUserReq } from '../../../../common/lib/mock'; @@ -38,7 +38,7 @@ export default ({ getService }: FtrProviderContext): void => { auth: authSpace1, }); const comment = removeServerGeneratedPropertiesFromSavedObject( - patchedCase.comments![0] as AttributesTypeUser + patchedCase.comments![0] as UserCommentAttachmentAttributes ); expect(comment).to.eql({ diff --git a/x-pack/test/cases_api_integration/spaces_only/tests/common/internal/bulk_create_attachments.ts b/x-pack/test/cases_api_integration/spaces_only/tests/common/internal/bulk_create_attachments.ts index b4df80ef5ff1c6..cf4dcdc5c7472b 100644 --- a/x-pack/test/cases_api_integration/spaces_only/tests/common/internal/bulk_create_attachments.ts +++ b/x-pack/test/cases_api_integration/spaces_only/tests/common/internal/bulk_create_attachments.ts @@ -6,7 +6,7 @@ */ import expect from '@kbn/expect'; -import { AttributesTypeUser } from '@kbn/cases-plugin/common/api'; +import { UserCommentAttachmentAttributes } from '@kbn/cases-plugin/common/types/domain'; import { FtrProviderContext } from '../../../../common/ftr_provider_context'; import { nullUser, postCaseReq, postCommentUserReq } from '../../../../common/lib/mock'; @@ -39,7 +39,7 @@ export default ({ getService }: FtrProviderContext): void => { }); const comment = removeServerGeneratedPropertiesFromSavedObject( - patchedCase.comments![0] as AttributesTypeUser + patchedCase.comments![0] as UserCommentAttachmentAttributes ); expect(comment).to.eql({ diff --git a/x-pack/test/functional/services/cases/api.ts b/x-pack/test/functional/services/cases/api.ts index 2322c8b798eb54..461f44a26da3ca 100644 --- a/x-pack/test/functional/services/cases/api.ts +++ b/x-pack/test/functional/services/cases/api.ts @@ -6,7 +6,8 @@ */ import pMap from 'p-map'; -import { CasePostRequest, Case, CaseSeverity, CaseStatuses } from '@kbn/cases-plugin/common/api'; +import { Case, CaseSeverity, CaseStatuses } from '@kbn/cases-plugin/common/types/domain'; +import { CasePostRequest } from '@kbn/cases-plugin/common/types/api'; import { createCase as createCaseAPI, deleteAllCaseItems, diff --git a/x-pack/test/functional/services/cases/common.ts b/x-pack/test/functional/services/cases/common.ts index 4c1ac65882081a..ef7964935ae417 100644 --- a/x-pack/test/functional/services/cases/common.ts +++ b/x-pack/test/functional/services/cases/common.ts @@ -7,8 +7,7 @@ import expect from '@kbn/expect'; import { ProvidedType } from '@kbn/test'; -import { CaseStatuses } from '@kbn/cases-plugin/common'; -import { CaseSeverity } from '@kbn/cases-plugin/common/api'; +import { CaseSeverity, CaseStatuses } from '@kbn/cases-plugin/common/types/domain'; import { FtrProviderContext } from '../../ftr_provider_context'; export type CasesCommon = ProvidedType; diff --git a/x-pack/test/functional/services/cases/create.ts b/x-pack/test/functional/services/cases/create.ts index 05c8be53fd227c..fb018615dd194c 100644 --- a/x-pack/test/functional/services/cases/create.ts +++ b/x-pack/test/functional/services/cases/create.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { CaseSeverity } from '@kbn/cases-plugin/common/api'; +import { CaseSeverity } from '@kbn/cases-plugin/common/types/domain'; import { v4 as uuidv4 } from 'uuid'; import { FtrProviderContext } from '../../ftr_provider_context'; import type { CasesCommon } from './common'; diff --git a/x-pack/test/functional/services/cases/helpers.ts b/x-pack/test/functional/services/cases/helpers.ts index 2dc0d7863bef0e..bedc781f2a8b6c 100644 --- a/x-pack/test/functional/services/cases/helpers.ts +++ b/x-pack/test/functional/services/cases/helpers.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { CasePostRequest } from '@kbn/cases-plugin/common/api'; +import { CasePostRequest } from '@kbn/cases-plugin/common/types/api'; import { CaseConnector } from '@kbn/cases-plugin/common/types/domain'; import { v4 as uuidv4 } from 'uuid'; diff --git a/x-pack/test/functional/services/cases/list.ts b/x-pack/test/functional/services/cases/list.ts index 2a89efeaf9872f..ceebee7a2dde12 100644 --- a/x-pack/test/functional/services/cases/list.ts +++ b/x-pack/test/functional/services/cases/list.ts @@ -6,9 +6,8 @@ */ import expect from '@kbn/expect'; -import { CaseStatuses } from '@kbn/cases-plugin/common'; import { CaseSeverityWithAll } from '@kbn/cases-plugin/common/ui'; -import { CaseSeverity } from '@kbn/cases-plugin/common/api'; +import { CaseSeverity, CaseStatuses } from '@kbn/cases-plugin/common/types/domain'; import { WebElementWrapper } from '../../../../../test/functional/services/lib/web_element_wrapper'; import { FtrProviderContext } from '../../ftr_provider_context'; import { CasesCommon } from './common'; diff --git a/x-pack/test/functional_with_es_ssl/apps/cases/group1/create_case_form.ts b/x-pack/test/functional_with_es_ssl/apps/cases/group1/create_case_form.ts index 55874757be0963..51b6ecbe73d8bd 100644 --- a/x-pack/test/functional_with_es_ssl/apps/cases/group1/create_case_form.ts +++ b/x-pack/test/functional_with_es_ssl/apps/cases/group1/create_case_form.ts @@ -7,7 +7,7 @@ import expect from '@kbn/expect'; import { v4 as uuidv4 } from 'uuid'; -import { CaseSeverity } from '@kbn/cases-plugin/common/api'; +import { CaseSeverity } from '@kbn/cases-plugin/common/types/domain'; import { FtrProviderContext } from '../../../ftr_provider_context'; import { createUsersAndRoles, diff --git a/x-pack/test/functional_with_es_ssl/apps/cases/group1/view_case.ts b/x-pack/test/functional_with_es_ssl/apps/cases/group1/view_case.ts index 72a7c3ac605c12..cc8a8a751bcb04 100644 --- a/x-pack/test/functional_with_es_ssl/apps/cases/group1/view_case.ts +++ b/x-pack/test/functional_with_es_ssl/apps/cases/group1/view_case.ts @@ -7,8 +7,7 @@ import expect from '@kbn/expect'; import { v4 as uuidv4 } from 'uuid'; -import { CaseStatuses } from '@kbn/cases-plugin/common'; -import { CaseSeverity } from '@kbn/cases-plugin/common/api'; +import { CaseSeverity, CaseStatuses } from '@kbn/cases-plugin/common/types/domain'; import { setTimeout as setTimeoutAsync } from 'timers/promises'; import { FtrProviderContext } from '../../../ftr_provider_context'; diff --git a/x-pack/test/functional_with_es_ssl/apps/cases/group2/attachment_framework.ts b/x-pack/test/functional_with_es_ssl/apps/cases/group2/attachment_framework.ts index 45f4607b644b99..648362070907a2 100644 --- a/x-pack/test/functional_with_es_ssl/apps/cases/group2/attachment_framework.ts +++ b/x-pack/test/functional_with_es_ssl/apps/cases/group2/attachment_framework.ts @@ -9,13 +9,13 @@ import type SuperTest from 'supertest'; import { v4 as uuidv4 } from 'uuid'; import { ExternalReferenceStorageType, - CommentType, + AttachmentType, Case, - CommentRequest, - CommentRequestExternalReferenceType, - CommentRequestPersistableStateType, -} from '@kbn/cases-plugin/common/api'; + ExternalReferenceAttachmentPayload, + PersistableStateAttachmentPayload, +} from '@kbn/cases-plugin/common/types/domain'; import { expect } from 'expect'; +import { AttachmentRequest } from '@kbn/cases-plugin/common/types/api'; import { deleteAllCaseItems, findCases, @@ -62,7 +62,7 @@ export default ({ getPageObject, getService }: FtrProviderContext) => { const lens = getPageObject('lens'); const listingTable = getService('listingTable'); - const createAttachmentAndNavigate = async (attachment: CommentRequest) => { + const createAttachmentAndNavigate = async (attachment: AttachmentRequest) => { const caseData = await cases.api.createCase({ title: `Registered attachment of type ${attachment.type}`, }); @@ -104,7 +104,7 @@ export default ({ getPageObject, getService }: FtrProviderContext) => { it('renders an external reference attachment type correctly', async () => { const attachmentId = caseWithAttachment?.comments?.[0].id; - await validateAttachment(CommentType.externalReference, attachmentId); + await validateAttachment(AttachmentType.externalReference, attachmentId); await testSubjects.existOrFail('test-attachment-content'); }); }); @@ -130,7 +130,7 @@ export default ({ getPageObject, getService }: FtrProviderContext) => { it('renders a persistable attachment type correctly', async () => { const attachmentId = caseWithAttachment?.comments?.[0].id; - await validateAttachment(CommentType.persistableState, attachmentId); + await validateAttachment(AttachmentType.persistableState, attachmentId); await retry.waitFor( 'persistable state to exist', async () => await find.existsByCssSelector('.lnsExpressionRenderer') @@ -185,8 +185,8 @@ export default ({ getPageObject, getService }: FtrProviderContext) => { const externalRefAttachmentId = theCase?.comments?.[0].id; const persistableStateAttachmentId = theCase?.comments?.[1].id; - await validateAttachment(CommentType.externalReference, externalRefAttachmentId); - await validateAttachment(CommentType.persistableState, persistableStateAttachmentId); + await validateAttachment(AttachmentType.externalReference, externalRefAttachmentId); + await validateAttachment(AttachmentType.persistableState, persistableStateAttachmentId); await testSubjects.existOrFail('test-attachment-content'); await retry.waitFor( @@ -492,8 +492,8 @@ const getLensState = (dataViewId: string) => ({ }, }); -const getExternalReferenceAttachment = (): CommentRequestExternalReferenceType => ({ - type: CommentType.externalReference, +const getExternalReferenceAttachment = (): ExternalReferenceAttachmentPayload => ({ + type: AttachmentType.externalReference, externalReferenceId: 'my-id', externalReferenceStorage: { type: ExternalReferenceStorageType.elasticSearchDoc }, externalReferenceAttachmentTypeId: '.test', @@ -501,8 +501,8 @@ const getExternalReferenceAttachment = (): CommentRequestExternalReferenceType = owner: 'cases', }); -const getPersistableStateAttachment = (dataViewId: string): CommentRequestPersistableStateType => ({ - type: CommentType.persistableState, +const getPersistableStateAttachment = (dataViewId: string): PersistableStateAttachmentPayload => ({ + type: AttachmentType.persistableState, persistableStateAttachmentTypeId: '.test', persistableStateAttachmentState: getLensState(dataViewId), owner: 'cases', diff --git a/x-pack/test/functional_with_es_ssl/apps/cases/group2/list_view.ts b/x-pack/test/functional_with_es_ssl/apps/cases/group2/list_view.ts index f19d488b4dc250..38dbc575ae4947 100644 --- a/x-pack/test/functional_with_es_ssl/apps/cases/group2/list_view.ts +++ b/x-pack/test/functional_with_es_ssl/apps/cases/group2/list_view.ts @@ -6,8 +6,7 @@ */ import expect from '@kbn/expect'; -import { CaseStatuses } from '@kbn/cases-plugin/common'; -import { CaseSeverity } from '@kbn/cases-plugin/common/api'; +import { CaseSeverity, CaseStatuses } from '@kbn/cases-plugin/common/types/domain'; import { SeverityAll } from '@kbn/cases-plugin/common/ui'; import { UserProfile } from '@kbn/user-profile-components'; import { FtrProviderContext } from '../../../ftr_provider_context'; diff --git a/x-pack/test/functional_with_es_ssl/plugins/cases/public/application.tsx b/x-pack/test/functional_with_es_ssl/plugins/cases/public/application.tsx index 422a74a29bab70..ad28e229e23a63 100644 --- a/x-pack/test/functional_with_es_ssl/plugins/cases/public/application.tsx +++ b/x-pack/test/functional_with_es_ssl/plugins/cases/public/application.tsx @@ -19,7 +19,7 @@ import { import { Router } from '@kbn/shared-ux-router'; import { AppMountParameters, CoreStart } from '@kbn/core/public'; import { CasesUiStart } from '@kbn/cases-plugin/public'; -import { CommentType } from '@kbn/cases-plugin/common'; +import { AttachmentType } from '@kbn/cases-plugin/common'; import { KibanaContextProvider, KibanaThemeProvider } from '@kbn/kibana-react-plugin/public'; import { EuiThemeProvider as StyledComponentsThemeProvider } from '@kbn/kibana-react-plugin/common'; import { EuiErrorBoundary } from '@elastic/eui'; @@ -44,7 +44,7 @@ const permissions = { push: true, }; -const attachments = [{ type: CommentType.user as const, comment: 'test' }]; +const attachments = [{ type: AttachmentType.user as const, comment: 'test' }]; const CasesFixtureAppWithContext: React.FC = (props) => { const { cases } = props; diff --git a/x-pack/test/observability_functional/apps/observability/pages/cases/case_details.ts b/x-pack/test/observability_functional/apps/observability/pages/cases/case_details.ts index 2fe088f7951549..ac6343f8e71707 100644 --- a/x-pack/test/observability_functional/apps/observability/pages/cases/case_details.ts +++ b/x-pack/test/observability_functional/apps/observability/pages/cases/case_details.ts @@ -6,7 +6,7 @@ */ import expect from '@kbn/expect'; -import { CommentType } from '@kbn/cases-plugin/common/api'; +import { AttachmentType } from '@kbn/cases-plugin/common/types/domain'; import { FtrProviderContext } from '../../../../ftr_provider_context'; export default ({ getPageObjects, getService }: FtrProviderContext) => { @@ -50,7 +50,7 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => { alertId: ['alert-id'], index: ['.internal.alerts-observability.alerts-default-000001'], rule: { id: 'rule-id', name: 'My rule name' }, - type: CommentType.alert, + type: AttachmentType.alert, owner, }, }); diff --git a/x-pack/test/screenshot_creation/apps/response_ops_docs/observability_cases/list_view.ts b/x-pack/test/screenshot_creation/apps/response_ops_docs/observability_cases/list_view.ts index c04e4b9fee48db..309c17f6ee4988 100644 --- a/x-pack/test/screenshot_creation/apps/response_ops_docs/observability_cases/list_view.ts +++ b/x-pack/test/screenshot_creation/apps/response_ops_docs/observability_cases/list_view.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { CommentType } from '@kbn/cases-plugin/common/api'; +import { AttachmentType } from '@kbn/cases-plugin/common/types/domain'; import { FtrProviderContext } from '../../../ftr_provider_context'; import { createAndUploadFile } from '../../../../cases_api_integration/common/lib/api'; import { OBSERVABILITY_FILE_KIND } from '../../../../cases_api_integration/common/lib/constants'; @@ -30,11 +30,11 @@ export default function ({ getPageObject, getService }: FtrProviderContext) { }); await cases.api.createAttachment({ caseId: caseIdMetrics, - params: { comment: 'test comment', type: CommentType.user, owner: 'observability' }, + params: { comment: 'test comment', type: AttachmentType.user, owner: 'observability' }, }); await cases.api.createAttachment({ caseId: caseIdMetrics, - params: { comment: '2nd test comment', type: CommentType.user, owner: 'observability' }, + params: { comment: '2nd test comment', type: AttachmentType.user, owner: 'observability' }, }); const { id: caseIdLogs, version: caseVersionLogs } = await cases.api.createCase({ @@ -56,7 +56,7 @@ export default function ({ getPageObject, getService }: FtrProviderContext) { const { version: caseVersionMonitoring } = await cases.api.createAttachment({ caseId: caseIdMonitoring, - params: { comment: 'test comment', type: CommentType.user, owner: 'observability' }, + params: { comment: 'test comment', type: AttachmentType.user, owner: 'observability' }, }); await cases.api.setStatus(caseIdMonitoring, caseVersionMonitoring, 'in-progress'); diff --git a/x-pack/test/screenshot_creation/apps/response_ops_docs/security_cases/list_view.ts b/x-pack/test/screenshot_creation/apps/response_ops_docs/security_cases/list_view.ts index d6156ef208ad62..5d599a43082f67 100644 --- a/x-pack/test/screenshot_creation/apps/response_ops_docs/security_cases/list_view.ts +++ b/x-pack/test/screenshot_creation/apps/response_ops_docs/security_cases/list_view.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { CaseSeverity } from '@kbn/cases-plugin/common/api'; +import { CaseSeverity } from '@kbn/cases-plugin/common/types/domain'; import { FtrProviderContext } from '../../../ftr_provider_context'; import { createAndUploadFile } from '../../../../cases_api_integration/common/lib/api'; import { SECURITY_SOLUTION_FILE_KIND } from '../../../../cases_api_integration/common/lib/constants'; diff --git a/x-pack/test/screenshot_creation/apps/response_ops_docs/stack_cases/list_view.ts b/x-pack/test/screenshot_creation/apps/response_ops_docs/stack_cases/list_view.ts index d79b790c612e6c..136f1d448d3b15 100644 --- a/x-pack/test/screenshot_creation/apps/response_ops_docs/stack_cases/list_view.ts +++ b/x-pack/test/screenshot_creation/apps/response_ops_docs/stack_cases/list_view.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { CommentType } from '@kbn/cases-plugin/common/api'; +import { AttachmentType } from '@kbn/cases-plugin/common/types/domain'; import { FtrProviderContext } from '../../../ftr_provider_context'; export default function ({ getService }: FtrProviderContext) { @@ -23,7 +23,7 @@ export default function ({ getService }: FtrProviderContext) { }); await cases.api.createAttachment({ caseId, - params: { comment: 'test comment', type: CommentType.user, owner: 'cases' }, + params: { comment: 'test comment', type: AttachmentType.user, owner: 'cases' }, }); }); diff --git a/x-pack/test/tsconfig.json b/x-pack/test/tsconfig.json index 8d7ef58f2775ea..fac4791ee18ef4 100644 --- a/x-pack/test/tsconfig.json +++ b/x-pack/test/tsconfig.json @@ -136,6 +136,6 @@ "@kbn/observability-onboarding-plugin", "@kbn/bfetch-plugin", "@kbn/uptime-plugin", - "@kbn/ml-category-validator" + "@kbn/ml-category-validator", ] }