diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index ef65393288fbf..d8fce960cfb6a 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -528,6 +528,7 @@ src/platform/packages/shared/kbn-server-route-repository-utils @elastic/obs-know src/platform/packages/shared/kbn-shared-svg @elastic/obs-ux-infra_services-team src/platform/packages/shared/kbn-shared-ux-utility @elastic/appex-sharedux src/platform/packages/shared/kbn-sort-predicates @elastic/kibana-visualizations +src/platform/packages/shared/kbn-spaces-utils @elastic/kibana-security src/platform/packages/shared/kbn-sse-utils @elastic/obs-knowledge-team src/platform/packages/shared/kbn-sse-utils-client @elastic/obs-knowledge-team src/platform/packages/shared/kbn-sse-utils-server @elastic/obs-knowledge-team diff --git a/package.json b/package.json index 0c44396a75748..2bb2ecfb5ea17 100644 --- a/package.json +++ b/package.json @@ -941,6 +941,7 @@ "@kbn/sort-predicates": "link:src/platform/packages/shared/kbn-sort-predicates", "@kbn/spaces-plugin": "link:x-pack/platform/plugins/shared/spaces", "@kbn/spaces-test-plugin": "link:x-pack/test/spaces_api_integration/common/plugins/spaces_test_plugin", + "@kbn/spaces-utils": "link:src/platform/packages/shared/kbn-spaces-utils", "@kbn/sse-example-plugin": "link:examples/sse_example", "@kbn/sse-utils": "link:src/platform/packages/shared/kbn-sse-utils", "@kbn/sse-utils-client": "link:src/platform/packages/shared/kbn-sse-utils-client", diff --git a/src/platform/packages/shared/kbn-spaces-utils/README.md b/src/platform/packages/shared/kbn-spaces-utils/README.md new file mode 100644 index 0000000000000..9697af8586613 --- /dev/null +++ b/src/platform/packages/shared/kbn-spaces-utils/README.md @@ -0,0 +1,3 @@ +# @kbn/spaces-utils + +Package containing utils related to Spaces. \ No newline at end of file diff --git a/src/platform/packages/shared/kbn-spaces-utils/index.ts b/src/platform/packages/shared/kbn-spaces-utils/index.ts new file mode 100644 index 0000000000000..7c9adca0d857a --- /dev/null +++ b/src/platform/packages/shared/kbn-spaces-utils/index.ts @@ -0,0 +1,11 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the "Elastic License + * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side + * Public License v 1"; you may not use this file except in compliance with, at + * your election, the "Elastic License 2.0", the "GNU Affero General Public + * License v3.0 only", or the "Server Side Public License, v 1". + */ + +export { DEFAULT_SPACE_ID } from './src/common/constants'; +export { addSpaceIdToPath, getSpaceIdFromPath } from './src/common/spaces_url_parser'; diff --git a/src/platform/packages/shared/kbn-spaces-utils/jest.config.js b/src/platform/packages/shared/kbn-spaces-utils/jest.config.js new file mode 100644 index 0000000000000..b6744df3784ce --- /dev/null +++ b/src/platform/packages/shared/kbn-spaces-utils/jest.config.js @@ -0,0 +1,14 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the "Elastic License + * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side + * Public License v 1"; you may not use this file except in compliance with, at + * your election, the "Elastic License 2.0", the "GNU Affero General Public + * License v3.0 only", or the "Server Side Public License, v 1". + */ + +module.exports = { + preset: '@kbn/test/jest_node', + rootDir: '../../../../..', + roots: ['/src/platform/packages/shared/kbn-spaces-utils'], +}; diff --git a/src/platform/packages/shared/kbn-spaces-utils/kibana.jsonc b/src/platform/packages/shared/kbn-spaces-utils/kibana.jsonc new file mode 100644 index 0000000000000..33aff9bd01d8f --- /dev/null +++ b/src/platform/packages/shared/kbn-spaces-utils/kibana.jsonc @@ -0,0 +1,9 @@ +{ + "type": "shared-common", + "id": "@kbn/spaces-utils", + "owner": [ + "@elastic/kibana-security" + ], + "group": "platform", + "visibility": "shared" +} diff --git a/src/platform/packages/shared/kbn-spaces-utils/src/common/constants.ts b/src/platform/packages/shared/kbn-spaces-utils/src/common/constants.ts new file mode 100644 index 0000000000000..aca5c2be7cb75 --- /dev/null +++ b/src/platform/packages/shared/kbn-spaces-utils/src/common/constants.ts @@ -0,0 +1,10 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the "Elastic License + * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side + * Public License v 1"; you may not use this file except in compliance with, at + * your election, the "Elastic License 2.0", the "GNU Affero General Public + * License v3.0 only", or the "Server Side Public License, v 1". + */ + +export const DEFAULT_SPACE_ID = `default`; diff --git a/x-pack/platform/plugins/shared/spaces/common/lib/spaces_url_parser.test.ts b/src/platform/packages/shared/kbn-spaces-utils/src/common/spaces_url_parser.test.ts similarity index 89% rename from x-pack/platform/plugins/shared/spaces/common/lib/spaces_url_parser.test.ts rename to src/platform/packages/shared/kbn-spaces-utils/src/common/spaces_url_parser.test.ts index 52ccd8c9c3bd1..75d813ccc5f73 100644 --- a/x-pack/platform/plugins/shared/spaces/common/lib/spaces_url_parser.test.ts +++ b/src/platform/packages/shared/kbn-spaces-utils/src/common/spaces_url_parser.test.ts @@ -1,12 +1,14 @@ /* * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. + * or more contributor license agreements. Licensed under the "Elastic License + * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side + * Public License v 1"; you may not use this file except in compliance with, at + * your election, the "Elastic License 2.0", the "GNU Affero General Public + * License v3.0 only", or the "Server Side Public License, v 1". */ import { addSpaceIdToPath, getSpaceIdFromPath } from './spaces_url_parser'; -import { DEFAULT_SPACE_ID } from '../constants'; +import { DEFAULT_SPACE_ID } from './constants'; describe('getSpaceIdFromPath', () => { describe('without a serverBasePath defined', () => { diff --git a/x-pack/platform/plugins/shared/spaces/common/lib/spaces_url_parser.ts b/src/platform/packages/shared/kbn-spaces-utils/src/common/spaces_url_parser.ts similarity index 85% rename from x-pack/platform/plugins/shared/spaces/common/lib/spaces_url_parser.ts rename to src/platform/packages/shared/kbn-spaces-utils/src/common/spaces_url_parser.ts index 9b24a70792030..4e3caa443e5c4 100644 --- a/x-pack/platform/plugins/shared/spaces/common/lib/spaces_url_parser.ts +++ b/src/platform/packages/shared/kbn-spaces-utils/src/common/spaces_url_parser.ts @@ -1,11 +1,13 @@ /* * 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. + * or more contributor license agreements. Licensed under the "Elastic License + * 2.0", the "GNU Affero General Public License v3.0 only", and the "Server Side + * Public License v 1"; you may not use this file except in compliance with, at + * your election, the "Elastic License 2.0", the "GNU Affero General Public + * License v3.0 only", or the "Server Side Public License, v 1". */ -import { DEFAULT_SPACE_ID } from '../constants'; +import { DEFAULT_SPACE_ID } from './constants'; const spaceContextRegex = /^\/s\/([a-z0-9_\-]+)/; diff --git a/src/platform/packages/shared/kbn-spaces-utils/tsconfig.json b/src/platform/packages/shared/kbn-spaces-utils/tsconfig.json new file mode 100644 index 0000000000000..7aba1b1a9378a --- /dev/null +++ b/src/platform/packages/shared/kbn-spaces-utils/tsconfig.json @@ -0,0 +1,17 @@ +{ + "extends": "../../../../../tsconfig.base.json", + "compilerOptions": { + "outDir": "target/types", + "types": [ + "jest", + "node" + ] + }, + "include": [ + "**/*.ts", + ], + "exclude": [ + "target/**/*" + ], + "kbn_references": [] +} diff --git a/tsconfig.base.json b/tsconfig.base.json index d8f4ee2aac0fe..ad8c32e129b25 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -1898,6 +1898,8 @@ "@kbn/spaces-plugin/*": ["x-pack/platform/plugins/shared/spaces/*"], "@kbn/spaces-test-plugin": ["x-pack/test/spaces_api_integration/common/plugins/spaces_test_plugin"], "@kbn/spaces-test-plugin/*": ["x-pack/test/spaces_api_integration/common/plugins/spaces_test_plugin/*"], + "@kbn/spaces-utils": ["src/platform/packages/shared/kbn-spaces-utils"], + "@kbn/spaces-utils/*": ["src/platform/packages/shared/kbn-spaces-utils/*"], "@kbn/sse-example-plugin": ["examples/sse_example"], "@kbn/sse-example-plugin/*": ["examples/sse_example/*"], "@kbn/sse-utils": ["src/platform/packages/shared/kbn-sse-utils"], diff --git a/x-pack/platform/plugins/shared/spaces/common/index.ts b/x-pack/platform/plugins/shared/spaces/common/index.ts index 21fee91bf979d..571c7f5694d64 100644 --- a/x-pack/platform/plugins/shared/spaces/common/index.ts +++ b/x-pack/platform/plugins/shared/spaces/common/index.ts @@ -13,7 +13,7 @@ export { DEFAULT_SPACE_ID, API_VERSIONS, } from './constants'; -export { addSpaceIdToPath, getSpaceIdFromPath } from './lib/spaces_url_parser'; +export { addSpaceIdToPath, getSpaceIdFromPath } from '@kbn/spaces-utils'; export type { Space, GetAllSpacesOptions, diff --git a/x-pack/platform/plugins/shared/spaces/server/spaces_service/spaces_service.test.ts b/x-pack/platform/plugins/shared/spaces/server/spaces_service/spaces_service.test.ts index b6be690e0e9dd..49cceec1978a0 100644 --- a/x-pack/platform/plugins/shared/spaces/server/spaces_service/spaces_service.test.ts +++ b/x-pack/platform/plugins/shared/spaces/server/spaces_service/spaces_service.test.ts @@ -11,10 +11,10 @@ import type { HttpServiceSetup, KibanaRequest, SavedObjectsRepository } from '@k import { SavedObjectsErrorHelpers } from '@kbn/core/server'; import { coreMock, httpServerMock } from '@kbn/core/server/mocks'; import { featuresPluginMock } from '@kbn/features-plugin/server/mocks'; +import { getSpaceIdFromPath } from '@kbn/spaces-utils'; import { SpacesService } from './spaces_service'; import { DEFAULT_SPACE_ID } from '../../common/constants'; -import { getSpaceIdFromPath } from '../../common/lib/spaces_url_parser'; import { spacesConfig } from '../lib/__fixtures__'; import { SpacesClientService } from '../spaces_client'; const createService = (serverBasePath: string = '') => { diff --git a/x-pack/platform/plugins/shared/spaces/tsconfig.json b/x-pack/platform/plugins/shared/spaces/tsconfig.json index a2ca002f092dd..a32c75a306265 100644 --- a/x-pack/platform/plugins/shared/spaces/tsconfig.json +++ b/x-pack/platform/plugins/shared/spaces/tsconfig.json @@ -54,7 +54,8 @@ "@kbn/ui-theme", "@kbn/core-chrome-browser", "@kbn/core-lifecycle-server", - "@kbn/core-user-profile-browser-mocks" + "@kbn/core-user-profile-browser-mocks", + "@kbn/spaces-utils" ], "exclude": ["target/**/*"] } diff --git a/yarn.lock b/yarn.lock index 5a061d55b4d24..f48c1a93ee317 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7492,6 +7492,10 @@ version "0.0.0" uid "" +"@kbn/spaces-utils@link:src/platform/packages/shared/kbn-spaces-utils": + version "0.0.0" + uid "" + "@kbn/sse-example-plugin@link:examples/sse_example": version "0.0.0" uid ""