Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
99 commits
Select commit Hold shift + click to select a range
77d172f
add link attachment type
dominiqueclarke Jun 10, 2025
3bcb4d4
[CI] Auto-commit changed files from 'node scripts/yarn_deduplicate'
kibanamachine Jun 10, 2025
bc5c03d
remove dashboard dependency from triggers actions ui
dominiqueclarke Jun 11, 2025
192116f
Merge branch 'feat/cases-link-attachment' of github.com:dominiqueclar…
dominiqueclarke Jun 11, 2025
8f3782f
Merge branch 'main' of https://github.com/elastic/kibana into feat/ca…
dominiqueclarke Jun 13, 2025
0aeebda
integrate screenshot
benakansara Jun 13, 2025
6037685
merge upstream
dominiqueclarke Jun 13, 2025
5266320
adjust types
dominiqueclarke Jun 16, 2025
14e8f82
[CI] Auto-commit changed files from 'node scripts/styled_components_m…
kibanamachine Jun 16, 2025
ac2ef57
quick checks
dominiqueclarke Jun 16, 2025
22cc56a
Merge branch 'feat/cases-link-attachment' of github.com:dominiqueclar…
dominiqueclarke Jun 16, 2025
9d0d253
remove unnecessary dashboard dependency
dominiqueclarke Jun 16, 2025
b45cdba
[CI] Auto-commit changed files from 'node scripts/styled_components_m…
kibanamachine Jun 16, 2025
6d1c98b
split and merge screenshot images
benakansara Jun 17, 2025
5bd0383
add actions
dominiqueclarke Jun 17, 2025
d28a975
merge upstream
dominiqueclarke Jun 17, 2025
e9818ad
remove screenshot functionality
dominiqueclarke Jun 17, 2025
b988b67
adjust rendered component
dominiqueclarke Jun 17, 2025
6565e1b
adjust types and linting
dominiqueclarke Jun 17, 2025
711442b
adjust types
dominiqueclarke Jun 17, 2025
ad3b528
adjust test
dominiqueclarke Jun 17, 2025
beb55d4
Merge branch 'main' of https://github.com/elastic/kibana into feat/ca…
dominiqueclarke Jun 17, 2025
f612f90
Merge branch 'main' into feat/cases-page-attachment
dominiqueclarke Jun 18, 2025
072a087
adjust types
dominiqueclarke Jun 18, 2025
da1e7a7
Merge branch 'feat/cases-page-attachment' of github.com:dominiqueclar…
dominiqueclarke Jun 18, 2025
d81aec3
adjust tests
dominiqueclarke Jun 18, 2025
c7166c5
adjust types
dominiqueclarke Jun 18, 2025
479cf7c
remove dashboard implementation
dominiqueclarke Jun 25, 2025
87dd13f
Update use_dashboard_menu_items.tsx
dominiqueclarke Jun 25, 2025
5bde52d
Update use_dashboard_menu_items.tsx
dominiqueclarke Jun 25, 2025
07f312a
add attachment type to observability
dominiqueclarke Jun 25, 2025
ddf1838
remove attachment type from cases
dominiqueclarke Jun 25, 2025
83bfd87
adjust license
dominiqueclarke Jun 25, 2025
58bb176
Merge branch 'feat/observability-generic-attachment' of github.com:do…
dominiqueclarke Jun 25, 2025
60067a9
remove additional references in cases
dominiqueclarke Jun 25, 2025
d42f848
merge main
dominiqueclarke Jun 25, 2025
ca0ddcb
adjust test
dominiqueclarke Jun 25, 2025
f9c39a1
Merge branch 'main' of https://github.com/elastic/kibana into feat/ob…
dominiqueclarke Jun 25, 2025
905c668
adjust tests
dominiqueclarke Jun 25, 2025
3a6f626
add "add to case" button to Synthetics monitor details
dominiqueclarke Jun 26, 2025
15fa00f
adjust types
dominiqueclarke Jun 26, 2025
a866930
[CI] Auto-commit changed files from 'node scripts/styled_components_m…
kibanamachine Jun 26, 2025
8e4bc8e
Merge branch 'feat/observability-generic-attachment' of github.com:do…
dominiqueclarke Jun 26, 2025
6f88fc2
adjust security start plugin
dominiqueclarke Jun 26, 2025
3fa8b3e
[CI] Auto-commit changed files from 'node scripts/yarn_deduplicate'
kibanamachine Jun 26, 2025
7b944e8
adjust import
dominiqueclarke Jun 26, 2025
2b165df
Merge branch 'feat/observability-generic-attachment' of github.com:do…
dominiqueclarke Jun 26, 2025
0478977
Update assignees.test.tsx
dominiqueclarke Jun 26, 2025
041df8d
adjust import
dominiqueclarke Jun 26, 2025
660c524
Merge branch 'feat/observability-generic-attachment' of github.com:do…
dominiqueclarke Jun 26, 2025
6febbcf
adjust limit
dominiqueclarke Jun 26, 2025
3ed6892
adjust tests
dominiqueclarke Jun 27, 2025
6949dfd
add feature flag
dominiqueclarke Jun 27, 2025
552bc73
[CI] Auto-commit changed files from 'node scripts/styled_components_m…
kibanamachine Jun 27, 2025
aad339b
add test
dominiqueclarke Jun 27, 2025
aab1ad9
Merge branch 'feat/observability-generic-attachment' of github.com:do…
dominiqueclarke Jun 27, 2025
386d1bd
adjust import
dominiqueclarke Jun 27, 2025
c31efa7
adjust test
dominiqueclarke Jun 30, 2025
af34ae3
Merge branch 'main' into feat/observability-generic-attachment
dominiqueclarke Jun 30, 2025
f5ef416
sanitize url
dominiqueclarke Jul 1, 2025
7f10f86
Merge branch 'feat/observability-generic-attachment' of github.com:do…
dominiqueclarke Jul 1, 2025
e5788c3
Merge branch 'main' into feat/observability-generic-attachment
dominiqueclarke Jul 2, 2025
b3c182e
Merge branch 'main' into feat/observability-generic-attachment
dominiqueclarke Jul 7, 2025
567b490
Update x-pack/solutions/observability/plugins/observability_shared/co…
dominiqueclarke Jul 7, 2025
58b8d28
Update x-pack/solutions/observability/plugins/synthetics/public/apps/…
dominiqueclarke Jul 8, 2025
6563239
Update x-pack/solutions/observability/plugins/synthetics/public/apps/…
dominiqueclarke Jul 8, 2025
11730cb
Update x-pack/solutions/observability/plugins/synthetics/public/apps/…
dominiqueclarke Jul 8, 2025
f5c9d46
adjust URL parsing
dominiqueclarke Jul 9, 2025
9c437d1
adjust types
dominiqueclarke Jul 9, 2025
9d31b5d
adjust tests
dominiqueclarke Jul 9, 2025
3724b5b
Merge branch 'main' of https://github.com/elastic/kibana into feat/ob…
dominiqueclarke Jul 9, 2025
0cc84e4
adjust types
dominiqueclarke Jul 10, 2025
35bb2db
handle external urls client side
dominiqueclarke Jul 11, 2025
ecb7fd2
merge main
dominiqueclarke Jul 14, 2025
dc1779f
adjust test
dominiqueclarke Jul 14, 2025
a18c17f
Merge branch 'main' of https://github.com/elastic/kibana into feat/ob…
dominiqueclarke Jul 15, 2025
973b650
add page attachment schema package
dominiqueclarke Jul 15, 2025
5745c78
add validation for page attachment type to prevent saving external urls
dominiqueclarke Jul 15, 2025
6c1029e
[CI] Auto-commit changed files from 'node scripts/generate codeowners'
kibanamachine Jul 15, 2025
867bd02
[CI] Auto-commit changed files from 'node scripts/notice'
kibanamachine Jul 15, 2025
9c69465
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Jul 15, 2025
d064307
adjust types
dominiqueclarke Jul 16, 2025
941403f
Merge branch 'feat/observability-generic-attachment' of github.com:do…
dominiqueclarke Jul 16, 2025
08be407
Merge branch 'main' into feat/observability-generic-attachment
dominiqueclarke Jul 16, 2025
37a3f9d
adjust test
dominiqueclarke Jul 17, 2025
59379f2
Merge branch 'feat/observability-generic-attachment' of github.com:do…
dominiqueclarke Jul 17, 2025
5560306
hide attachment registration behind feature flag
dominiqueclarke Jul 18, 2025
41167a9
adjust test
dominiqueclarke Jul 18, 2025
c9f0f43
update translations
dominiqueclarke Jul 18, 2025
c3378bf
adjust config
dominiqueclarke Jul 18, 2025
e8037be
add link to EuiIcon
dominiqueclarke Jul 18, 2025
2f40548
adjust comment
dominiqueclarke Jul 18, 2025
d63072c
Merge branch 'main' into feat/observability-generic-attachment
dominiqueclarke Jul 21, 2025
b5d9da5
Update x-pack/solutions/observability/plugins/synthetics/public/apps/…
dominiqueclarke Jul 21, 2025
932bf1a
adjust tests
dominiqueclarke Jul 21, 2025
cf31a52
Merge branch 'feat/observability-generic-attachment' of github.com:do…
dominiqueclarke Jul 21, 2025
8c045a8
Update x-pack/solutions/observability/plugins/synthetics/public/apps/…
dominiqueclarke Jul 21, 2025
8ef4b60
Update x-pack/solutions/observability/plugins/synthetics/public/apps/…
dominiqueclarke Jul 21, 2025
dbb5783
Update x-pack/solutions/observability/plugins/synthetics/public/apps/…
dominiqueclarke Jul 21, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -873,6 +873,7 @@ x-pack/platform/packages/shared/kbn-inference-tracing-config @elastic/appex-ai-i
x-pack/platform/packages/shared/kbn-key-value-metadata-table @elastic/obs-ux-infra_services-team @elastic/obs-ux-logs-team
x-pack/platform/packages/shared/kbn-kibana-api-cli @elastic/appex-ai-infra
x-pack/platform/packages/shared/kbn-langchain @elastic/security-generative-ai
x-pack/platform/packages/shared/kbn-page-attachment-schema @elastic/obs-ux-management-team
x-pack/platform/packages/shared/kbn-profiler-cli @elastic/obs-knowledge-team
x-pack/platform/packages/shared/kbn-sample-parser @elastic/streams-program-team
x-pack/platform/packages/shared/kbn-search-index-documents @elastic/search-kibana
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,7 @@
"@kbn/osquery-io-ts-types": "link:src/platform/packages/shared/kbn-osquery-io-ts-types",
"@kbn/osquery-plugin": "link:x-pack/platform/plugins/shared/osquery",
"@kbn/paertial-results-example-plugin": "link:examples/partial_results_example",
"@kbn/page-attachment-schema": "link:x-pack/platform/packages/shared/kbn-page-attachment-schema",
"@kbn/painless-lab-plugin": "link:x-pack/platform/plugins/private/painless_lab",
"@kbn/palettes": "link:src/platform/packages/shared/kbn-palettes",
"@kbn/panel-loader": "link:src/platform/packages/private/kbn-panel-loader",
Expand Down
2 changes: 1 addition & 1 deletion packages/kbn-optimizer/limits.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ pageLoadAssetSize:
navigation: 13598
newsfeed: 12371
noDataPage: 1749
observability: 107869
observability: 160191

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Did we look into reducing this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure I can with the addition of add to case flyout from the cases plugin, at least without it being pulled out into a package. cc: @cnasikas @michaelolo24

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

👍 thanks for looking. Don't want to block, but it would be helpful to follow up at some point.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

In syncing with Christos last week, the option of moving it out to a package has been proposed, so definitely something we can investigate

observabilityAIAssistant: 46941
observabilityAIAssistantApp: 18553
observabilityAiAssistantManagement: 6438
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ export default function ({ getService }: PluginFunctionalProviderContext) {
'xpack.observabilityAiAssistantManagement.logSourcesEnabled (boolean?)',
'xpack.observabilityAiAssistantManagement.spacesEnabled (boolean?)',
'xpack.observabilityAiAssistantManagement.visibilityEnabled (boolean?)',
'xpack.observabilityShared.unsafe.investigativeExperienceEnabled (boolean?)',
'share.new_version.enabled (boolean?)',
'aiAssistantManagementSelection.preferredAIAssistantType (default?|never?|observability?|security?)',
/**
Expand Down
2 changes: 2 additions & 0 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -1462,6 +1462,8 @@
"@kbn/osquery-plugin/*": ["x-pack/platform/plugins/shared/osquery/*"],
"@kbn/paertial-results-example-plugin": ["examples/partial_results_example"],
"@kbn/paertial-results-example-plugin/*": ["examples/partial_results_example/*"],
"@kbn/page-attachment-schema": ["x-pack/platform/packages/shared/kbn-page-attachment-schema"],
"@kbn/page-attachment-schema/*": ["x-pack/platform/packages/shared/kbn-page-attachment-schema/*"],
"@kbn/painless-lab-plugin": ["x-pack/platform/plugins/private/painless_lab"],
"@kbn/painless-lab-plugin/*": ["x-pack/platform/plugins/private/painless_lab/*"],
"@kbn/palettes": ["src/platform/packages/shared/kbn-palettes"],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# @kbn/page-attachment-schema

This shared package contains the zod schema definition for persisted state of the page attachment type used in cases.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* 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 './src/latest';
export * from './src/constants';
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* 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.
*/

module.exports = {
preset: '@kbn/test',
rootDir: '../../../../..',
roots: ['<rootDir>/x-pack/platform/packages/shared/kbn-page-attachment-schema'],
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"type": "shared-common",
"id": "@kbn/page-attachment-schema",
"owner": [
"@elastic/obs-ux-management-team"
],
"group": "platform",
"visibility": "shared"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "@kbn/page-attachment-schema",
"description": "Page attachment zod schema definition and constants.",
"private": true,
"version": "1.0.0",
"license": "Elastic License 2.0"
}
Original file line number Diff line number Diff line change
@@ -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 const PAGE_ATTACHMENT_TYPE = '.page';
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

export {
type PageAttachmentPersistedState,
pageAttachmentPersistedStateSchema,
} from './schema/latest';
Original file line number Diff line number Diff line change
@@ -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 { type PageAttachmentPersistedState, pageAttachmentPersistedStateSchema } from './v1';
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* 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 { z } from '@kbn/zod';

export const pageAttachmentPersistedStateSchema = z.object({
/**
* The type of page or page asset, e.g., 'dashboard', 'synthetics-test-run', 'slo-history', etc

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why do we need type here?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It's basically a sub-type to help us make future decisions about how to render this page, how to evaluate it in LLM analysis, etc.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@jasonrhodes Michael and I had actually discussed this over zoom last week. I should have put the reply here for reference.

*/
type: z.string(),
url: z.object({
/**
* The URL to the page or page asset, excluding the base path.
*/
pathAndQuery: z.string(),
/**
* The label to render in the "Go to" action, example "View in Dashboard" for the asset
*/
actionLabel: z.string(),
/**
* The label to render in the attachment comment for the page or page asset
*/
label: z.string(),
/**
* The icon, rendered via {@link EuiIcon}, representing the page type, displayed in the comment and action.
*/
iconType: z.string().optional(),
}),
/**
* Optional screen context for the page. A plain text description that
* can be provided to an LLM to generate a summary or perform analysis
*/
screenContext: z.array(z.object({ screenDescription: z.string() })).optional(),
});

export type PageAttachmentPersistedState = z.infer<typeof pageAttachmentPersistedStateSchema>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"extends": "../../../../../tsconfig.base.json",
"compilerOptions": {
"outDir": "target/types",
"types": [
"jest",
"node"
]
},
"include": [
"**/*.ts"
],
"kbn_references": [
"@kbn/zod",
],
"exclude": [
"target/**/*",
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -262,12 +262,13 @@ export type ExternalReferenceAttachment = rt.TypeOf<typeof ExternalReferenceAtta
/**
* Persistable state
*/
export const PersistableStateAttachmentStateRt = rt.record(rt.string, jsonValueRt);

export const PersistableStateAttachmentPayloadRt = rt.strict({
type: rt.literal(AttachmentType.persistableState),
owner: rt.string,
persistableStateAttachmentTypeId: rt.string,
persistableStateAttachmentState: rt.record(rt.string, jsonValueRt),
persistableStateAttachmentState: PersistableStateAttachmentStateRt,
});

const PersistableStateAttachmentAttributesRt = rt.intersection([
Expand All @@ -286,6 +287,7 @@ export const PersistableStateAttachmentRt = rt.intersection([
export type PersistableStateAttachmentPayload = rt.TypeOf<
typeof PersistableStateAttachmentPayloadRt
>;
export type PersistableStateAttachmentState = rt.TypeOf<typeof PersistableStateAttachmentStateRt>;
export type PersistableStateAttachment = rt.TypeOf<typeof PersistableStateAttachmentRt>;
export type PersistableStateAttachmentAttributes = rt.TypeOf<
typeof PersistableStateAttachmentAttributesRt
Expand Down
3 changes: 2 additions & 1 deletion x-pack/platform/plugins/shared/cases/kibana.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@
"savedObjectsFinder"
],
"extraPublicDirs": [
"common"
"common",
"public/client/attachment_framework/types"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I wonder if we should move these types to common?

]
}
}
2 changes: 2 additions & 0 deletions x-pack/platform/plugins/shared/cases/public/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@ export type { CaseAttachments, CaseAttachmentsWithoutOwner } from './types';

export type { ICasesDeepLinkId } from './common/navigation';
export { getCasesDeepLinks, CasesDeepLinkId, generateCaseViewPath } from './common/navigation';

export { AttachmentActionType } from './client/attachment_framework/types';
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@

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 { FILE_ATTACHMENT_TYPE, LENS_ATTACHMENT_TYPE } from '../../common/constants';

import { decodeWithExcessOrThrow } from '../common/runtime_types';
import type { ExternalReferenceAttachmentTypeRegistry } from '../attachment_framework/external_reference_registry';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { schema } from '@kbn/config-schema';
import { INTERNAL_BULK_CREATE_ATTACHMENTS_URL } from '../../../../common/constants';
import { createCaseError } from '../../../common/error';
import { createCasesRoute } from '../create_cases_route';
import { escapeHatch } from '../utils';
import { validAttachment } from '../utils';
import type { attachmentApiV1 } from '../../../../common/types/api';
import type { caseDomainV1 } from '../../../../common/types/domain';
import { DEFAULT_CASES_ROUTE_SECURITY } from '../constants';
Expand All @@ -22,7 +22,7 @@ export const bulkCreateAttachmentsRoute = createCasesRoute({
params: schema.object({
case_id: schema.string(),
}),
body: schema.arrayOf(escapeHatch),
body: schema.arrayOf(validAttachment),
},
routerOptions: {
access: 'internal',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,15 @@

import { isBoom, boomify } from '@hapi/boom';
import { loggingSystemMock } from '@kbn/core/server/mocks';
import { PAGE_ATTACHMENT_TYPE } from '@kbn/page-attachment-schema';
import type { HTTPError } from '../../common/error';
import { extractWarningValueFromWarningHeader, logDeprecatedEndpoint, wrapError } from './utils';
import {
extractWarningValueFromWarningHeader,
logDeprecatedEndpoint,
wrapError,
validAttachment,
isPersistableStatePageAttachment,
} from './utils';

describe('Utils', () => {
describe('wrapError', () => {
Expand Down Expand Up @@ -83,4 +90,57 @@ describe('Utils', () => {
);
});
});

describe('validAttachment', () => {
it('validates a valid attachment', () => {
const attachment = {
persistableStateAttachmentTypeId: PAGE_ATTACHMENT_TYPE,
persistableStateAttachmentState: {
url: { pathAndQuery: '/internal/safe-url' },
},
};

expect(validAttachment.validate(attachment)).toEqual(attachment);
});

it('throws an error for an external URL', () => {
const invalidAttachment = {
persistableStateAttachmentTypeId: PAGE_ATTACHMENT_TYPE,
persistableStateAttachmentState: {
url: { pathAndQuery: 'http://external-url.com' },
},
};

expect(() => validAttachment.validate(invalidAttachment)).toThrow(
'External urls are not supported for page attachments. The provided url is: http://external-url.com'
);
});
});

describe('isPersistableStatePageAttachment', () => {
it('returns true for a valid persistable state page attachment', () => {
const attachment = {
persistableStateAttachmentTypeId: PAGE_ATTACHMENT_TYPE,
persistableStateAttachmentState: {},
};

expect(isPersistableStatePageAttachment(attachment)).toBe(true);
});

it('returns false for an invalid attachment', () => {
const invalidAttachment = {
someOtherProperty: 'value',
};

expect(isPersistableStatePageAttachment(invalidAttachment)).toBe(false);
});

it('returns false for a null value', () => {
expect(isPersistableStatePageAttachment(null)).toBe(false);
});

it('returns false for a non-object value', () => {
expect(isPersistableStatePageAttachment('string')).toBe(false);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ import type { Boom } from '@hapi/boom';
import { boomify, isBoom } from '@hapi/boom';
import { schema } from '@kbn/config-schema';
import type { CustomHttpResponseOptions, ResponseError, Headers, Logger } from '@kbn/core/server';
import { isInternalURL } from '@kbn/std';
import {
type PageAttachmentPersistedState,
PAGE_ATTACHMENT_TYPE,
} from '@kbn/page-attachment-schema';
import type { AttachmentRequestAttributes } from '../../common/types/attachments';
import type { CaseError, HTTPError } from '../../common/error';
import { isCaseError, isHTTPError } from '../../common/error';

Expand All @@ -35,7 +41,45 @@ export function wrapError(
};
}

export const escapeHatch = schema.object({}, { unknowns: 'allow' });
export const escapeHatch = schema.object(
{},
{
unknowns: 'allow',
}
);

export const validAttachment = schema.object(
{},
{
unknowns: 'allow',
validate: (value) => {
if (
isPersistableStatePageAttachment(value) &&
value.persistableStateAttachmentTypeId === PAGE_ATTACHMENT_TYPE
) {
const persistedState =
value.persistableStateAttachmentState as PageAttachmentPersistedState;
const url = persistedState?.url?.pathAndQuery;
if (url && !isInternalURL(url)) {
return `External urls are not supported for page attachments. The provided url is: ${url}`;
}
}
},
}
);

/**
* Checks if the given value is a persistable state page attachment type.
*/
export const isPersistableStatePageAttachment = (

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: This isn't actually checking if it's a pageAttachment type, just that it's a persistableState type and is a valid value. Not sure if you want to move value.persistableStateAttachmentTypeId === PAGE_ATTACHMENT_TYPE here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This particularly util wasn't intended to check if it's a pageAttachment. Just that it's a persistable state attachment type so that the types would later recognize value.persistableStateAttachmentTypeId.

I suppose I could move all the checks here. That just wasn't my original intent.

value: unknown
): value is AttachmentRequestAttributes => {
return (
typeof value === 'object' &&
value !== null &&
Boolean((value as AttachmentRequestAttributes).persistableStateAttachmentTypeId)
);
};

/**
* Creates a warning header with a message formatted according to RFC7234.
Expand Down
3 changes: 2 additions & 1 deletion x-pack/platform/plugins/shared/cases/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@
"@kbn/elastic-assistant-common",
"@kbn/test",
"@kbn/dev-utils",
"@kbn/tooling-log"
"@kbn/tooling-log",
"@kbn/page-attachment-schema"
],
"exclude": ["target/**/*"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
"dataViewEditor",
"alerting",
"actions",
"dashboard",
Comment thread
michaelolo24 marked this conversation as resolved.
"licensing",
"expressions",
"lens",
Expand Down
Loading