Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -496,6 +496,7 @@ src/platform/packages/shared/kbn-connector-schemas @elastic/response-ops
src/platform/packages/shared/kbn-connector-specs @elastic/response-ops
src/platform/packages/shared/kbn-content-management-utils @elastic/kibana-data-discovery
src/platform/packages/shared/kbn-core-server-benchmarks @elastic/kibana-core
src/platform/packages/shared/kbn-cps-server-utils @elastic/kibana-core
src/platform/packages/shared/kbn-cps-utils @elastic/kibana-presentation
src/platform/packages/shared/kbn-crypto @elastic/kibana-security
src/platform/packages/shared/kbn-crypto-browser @elastic/kibana-core
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,7 @@
"@kbn/core-user-settings-server-internal": "link:src/core/packages/user-settings/server-internal",
"@kbn/core-user-settings-server-mocks": "link:src/core/packages/user-settings/server-mocks",
"@kbn/cps": "link:src/platform/plugins/shared/cps",
"@kbn/cps-server-utils": "link:src/platform/packages/shared/kbn-cps-server-utils",
"@kbn/cps-utils": "link:src/platform/packages/shared/kbn-cps-utils",
"@kbn/cross-cluster-replication-plugin": "link:x-pack/platform/plugins/private/cross_cluster_replication",
"@kbn/crypto": "link:src/platform/packages/shared/kbn-crypto",
Expand Down
20 changes: 20 additions & 0 deletions src/platform/packages/shared/kbn-cps-server-utils/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# @kbn/cps-server-utils

Server-side Cross-Project Search (CPS) utilities.

## `getSpaceNPRE`

Returns the Named Project Routing Expression (NPRE) for a given space, using the convention `kibana_space_${spaceId}_default`.

Accepts either a `spaceId` string or a `KibanaRequest` (from which the space is derived via the request URL path, without a dependency on the `spaces` plugin).

```ts
import { getSpaceNPRE } from '@kbn/cps-server-utils';

// From a space ID string
getSpaceNPRE('my-space'); // 'kibana_space_my-space_default'
getSpaceNPRE(''); // 'kibana_space_default_default'

// From a KibanaRequest (extracts space from the URL path)
getSpaceNPRE(request); // e.g. 'kibana_space_my-space_default'
```
10 changes: 10 additions & 0 deletions src/platform/packages/shared/kbn-cps-server-utils/index.ts
Original file line number Diff line number Diff line change
@@ -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 { getSpaceNPRE } from './src/get_space_npre';
Original file line number Diff line number Diff line change
@@ -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: ['<rootDir>/src/platform/packages/shared/kbn-cps-server-utils'],
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"type": "shared-server",
"id": "@kbn/cps-server-utils",
"owner": [
"@elastic/kibana-core"
],
"group": "platform",
"visibility": "shared"
}
46 changes: 46 additions & 0 deletions src/platform/packages/shared/kbn-cps-server-utils/moon.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# This file is generated by the @kbn/moon package. Any manual edits will be erased!
# To extend this, write your extensions/overrides to 'moon.extend.yml'
# then regenerate this file with: 'node scripts/regenerate_moon_projects.js --update --filter @kbn/cps-server-utils'

$schema: https://moonrepo.dev/schemas/project.json
id: '@kbn/cps-server-utils'
type: unknown
owners:
defaultOwner: '@elastic/kibana-core'
toolchain:
default: node
language: typescript
project:
name: '@kbn/cps-server-utils'
description: Moon project for @kbn/cps-server-utils
channel: ''
owner: '@elastic/kibana-core'
metadata:
sourceRoot: src/platform/packages/shared/kbn-cps-server-utils
dependsOn:
- '@kbn/core-http-server'
- '@kbn/spaces-utils'
tags:
- shared-server
- package
- prod
- group-platform
- shared
- jest-unit-tests
fileGroups:
src:
- '**/*'
- '!target/**/*'
tasks:
jest:
args:
- '--config'
- $projectRoot/jest.config.js
inputs:
- '@group(src)'
jestCI:
args:
- '--config'
- $projectRoot/jest.config.js
inputs:
- '@group(src)'
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "@kbn/cps-server-utils",
"version": "1.0.0",
"private": true,
"license": "Elastic License 2.0 OR AGPL-3.0-only OR SSPL-1.0",
"sideEffects": false
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* 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".
*/

import type { KibanaRequest } from '@kbn/core-http-server';
import { getSpaceNPRE } from './get_space_npre';

const mockRequest = (pathname: string) =>
({ url: new URL(`http://localhost:5601${pathname}`) } as unknown as KibanaRequest);

describe('getSpaceNPRE', () => {
describe('when called with a spaceId string', () => {
it('returns the NPRE for the given space', () => {
expect(getSpaceNPRE('my-space')).toBe('kibana_space_my-space_default');
});

it('uses "default" when spaceId is an empty string', () => {
expect(getSpaceNPRE('')).toBe('kibana_space_default_default');
});

it('returns the NPRE for the default space when spaceId is "default"', () => {
expect(getSpaceNPRE('default')).toBe('kibana_space_default_default');
});
});

describe('when called with a KibanaRequest', () => {
it('extracts the space from the request URL and returns the NPRE', () => {
expect(getSpaceNPRE(mockRequest('/s/my-space/api/foo'))).toBe(
'kibana_space_my-space_default'
);
});

it('returns the default space NPRE when the request URL has no space segment', () => {
expect(getSpaceNPRE(mockRequest('/api/foo'))).toBe('kibana_space_default_default');
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* 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".
*/

import type { KibanaRequest } from '@kbn/core-http-server';
import { DEFAULT_SPACE_ID, getSpaceIdFromPath } from '@kbn/spaces-utils';

export function getSpaceNPRE(spaceIdOrRequest: string | KibanaRequest): string {
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.

nit: can you add TSDocs?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Will add them in a follow-up PR, I don't want to retrigger a whole CI just for that.

const spaceId =
typeof spaceIdOrRequest === 'string'
? spaceIdOrRequest || DEFAULT_SPACE_ID
: getSpaceIdFromPath(spaceIdOrRequest.url.pathname).spaceId;

return `kibana_space_${spaceId}_default`;
}
17 changes: 17 additions & 0 deletions src/platform/packages/shared/kbn-cps-server-utils/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"extends": "@kbn/tsconfig-base/tsconfig.json",
"compilerOptions": {
"outDir": "target/types",
},
"include": [
"**/*",
"../../../../../typings/**/*",
],
"kbn_references": [
"@kbn/core-http-server",
"@kbn/spaces-utils",
],
"exclude": [
"target/**/*"
]
}
2 changes: 2 additions & 0 deletions tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,8 @@
"@kbn/core-user-settings-server-mocks/*": ["src/core/packages/user-settings/server-mocks/*"],
"@kbn/cps": ["src/platform/plugins/shared/cps"],
"@kbn/cps/*": ["src/platform/plugins/shared/cps/*"],
"@kbn/cps-server-utils": ["src/platform/packages/shared/kbn-cps-server-utils"],
"@kbn/cps-server-utils/*": ["src/platform/packages/shared/kbn-cps-server-utils/*"],
"@kbn/cps-utils": ["src/platform/packages/shared/kbn-cps-utils"],
"@kbn/cps-utils/*": ["src/platform/packages/shared/kbn-cps-utils/*"],
"@kbn/cross-cluster-replication-plugin": ["x-pack/platform/plugins/private/cross_cluster_replication"],
Expand Down
42 changes: 38 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2705,7 +2705,7 @@
resolved "https://registry.yarnpkg.com/@elastic/filesaver/-/filesaver-1.1.2.tgz#1998ffb3cd89c9da4ec12a7793bfcae10e30c77a"
integrity sha512-YZbSufYFBhAj+S2cJgiKALoxIJevqXN2MSr6Yqr42rJdaPuM31cj6pUDwflkql1oDjupqD9la+MfxPFjXI1JFQ==

"@elastic/kibana-d3-color@npm:@elastic/kibana-d3-color@2.0.1", "d3-color@1 - 2", "d3-color@npm:@elastic/kibana-d3-color@2.0.1":
"@elastic/kibana-d3-color@npm:@elastic/kibana-d3-color@2.0.1":
version "2.0.1"
resolved "https://registry.yarnpkg.com/@elastic/kibana-d3-color/-/kibana-d3-color-2.0.1.tgz#f83b9c2fea09273a918659de04d5e8098c82f65c"
integrity sha512-YZ8hV2bWNyYi833Yj3UWczmTxdHzmo/Xc2IVkNXr/ZqtkrTDlTLysCyJm7SfAt9iBy6EVRGWTn8cPz8QOY6Ixw==
Expand Down Expand Up @@ -6357,6 +6357,10 @@
version "0.0.0"
uid ""

"@kbn/cps-server-utils@link:src/platform/packages/shared/kbn-cps-server-utils":
version "0.0.0"
uid ""

"@kbn/cps-utils@link:src/platform/packages/shared/kbn-cps-utils":
version "0.0.0"
uid ""
Expand Down Expand Up @@ -19053,6 +19057,11 @@ d3-collection@^1.0.7:
resolved "https://registry.yarnpkg.com/d3-collection/-/d3-collection-1.0.7.tgz#349bd2aa9977db071091c13144d5e4f16b5b310e"
integrity sha512-ii0/r5f4sjKNTfh84Di+DpztYwqKhEyUlKoPrzUFfeSkWxjW49xU2QzO9qrPrNkpdI0XJkfzvmTu8V2Zylln6A==

"d3-color@1 - 2", "d3-color@npm:@elastic/kibana-d3-color@2.0.1":
version "2.0.1"
resolved "https://registry.yarnpkg.com/@elastic/kibana-d3-color/-/kibana-d3-color-2.0.1.tgz#f83b9c2fea09273a918659de04d5e8098c82f65c"
integrity sha512-YZ8hV2bWNyYi833Yj3UWczmTxdHzmo/Xc2IVkNXr/ZqtkrTDlTLysCyJm7SfAt9iBy6EVRGWTn8cPz8QOY6Ixw==

"d3-color@1 - 3", d3-color@^3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/d3-color/-/d3-color-3.1.0.tgz#395b2833dfac71507f12ac2f7af23bf819de24e2"
Expand Down Expand Up @@ -32379,7 +32388,7 @@ string-length@^4.0.1:
char-regex "^1.0.2"
strip-ansi "^6.0.0"

"string-width-cjs@npm:string-width@^4.2.0", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
"string-width-cjs@npm:string-width@^4.2.0":
version "4.2.3"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
Expand All @@ -32397,6 +32406,15 @@ string-width@^1.0.1:
is-fullwidth-code-point "^1.0.0"
strip-ansi "^3.0.0"

string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
version "4.2.3"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
dependencies:
emoji-regex "^8.0.0"
is-fullwidth-code-point "^3.0.0"
strip-ansi "^6.0.1"

string-width@^5.0.1, string-width@^5.1.2:
version "5.1.2"
resolved "https://registry.yarnpkg.com/string-width/-/string-width-5.1.2.tgz#14f8daec6d81e7221d2a357e668cab73bdbca794"
Expand Down Expand Up @@ -32489,7 +32507,14 @@ stringify-object@^3.2.1:
is-obj "^1.0.1"
is-regexp "^1.0.0"

"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@6.0.1, strip-ansi@^6.0.0, strip-ansi@^6.0.1:
"strip-ansi-cjs@npm:strip-ansi@^6.0.1":
version "6.0.1"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
dependencies:
ansi-regex "^5.0.1"

strip-ansi@6.0.1, strip-ansi@^6.0.0, strip-ansi@^6.0.1:
version "6.0.1"
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
Expand Down Expand Up @@ -35301,7 +35326,7 @@ workerpool@^6.5.1:
resolved "https://registry.yarnpkg.com/workerpool/-/workerpool-6.5.1.tgz#060f73b39d0caf97c6db64da004cd01b4c099544"
integrity sha512-Fs4dNYcsdpYSAfVxhnl1L5zTksjvOJxtC5hzMNl+1t9B8hTJTdKDyZ5ju7ztgPy+ft9tBFXoOlDNiOT9WUXZlA==

"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0:
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0":
version "7.0.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
Expand All @@ -35327,6 +35352,15 @@ wrap-ansi@^6.0.1, wrap-ansi@^6.2.0:
string-width "^4.1.0"
strip-ansi "^6.0.0"

wrap-ansi@^7.0.0:
version "7.0.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
dependencies:
ansi-styles "^4.0.0"
string-width "^4.1.0"
strip-ansi "^6.0.0"

wrap-ansi@^8.1.0:
version "8.1.0"
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-8.1.0.tgz#56dc22368ee570face1b49819975d9b9a5ead214"
Expand Down