diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 070c960e8f03e..6ab9ef9a7be7c 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -952,6 +952,7 @@ packages/kbn-sort-package-json @elastic/kibana-operations src/platform/packages/shared/kbn-sort-predicates @elastic/kibana-visualizations x-pack/platform/plugins/shared/spaces @elastic/kibana-security x-pack/test/spaces_api_integration/common/plugins/spaces_test_plugin @elastic/kibana-security +src/platform/packages/shared/kbn-spaces-utils @elastic/kibana-security packages/kbn-spec-to-console @elastic/kibana-management src/platform/packages/shared/kbn-sse-utils @elastic/obs-knowledge-team src/platform/packages/shared/kbn-sse-utils-client @elastic/obs-knowledge-team diff --git a/package.json b/package.json index 01d70d1300bbc..2c318c392ccf6 100644 --- a/package.json +++ b/package.json @@ -940,6 +940,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-utils": "link:src/platform/packages/shared/kbn-sse-utils", "@kbn/sse-utils-client": "link:src/platform/packages/shared/kbn-sse-utils-client", "@kbn/sse-utils-server": "link:src/platform/packages/shared/kbn-sse-utils-server", 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 a5eb30bf1b727..d4a9ab5687e43 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/spec-to-console": ["packages/kbn-spec-to-console"], "@kbn/spec-to-console/*": ["packages/kbn-spec-to-console/*"], "@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 993d446edf354..7122523569fb1 100644 --- a/x-pack/platform/plugins/shared/spaces/tsconfig.json +++ b/x-pack/platform/plugins/shared/spaces/tsconfig.json @@ -55,6 +55,7 @@ "@kbn/core-chrome-browser", "@kbn/core-lifecycle-server", "@kbn/core-user-profile-browser-mocks", + "@kbn/spaces-utils" ], "exclude": [ "target/**/*", diff --git a/yarn.lock b/yarn.lock index 6b89b20066724..0cf28b4b26a08 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7439,6 +7439,10 @@ version "0.0.0" uid "" +"@kbn/spaces-utils@link:src/platform/packages/shared/kbn-spaces-utils": + version "0.0.0" + uid "" + "@kbn/spec-to-console@link:packages/kbn-spec-to-console": version "0.0.0" uid ""