Skip to content

Commit b44c413

Browse files
gsoldevilacursoragent
authored andcommitted
[core][http] Add spaceId to KibanaRequestState and KibanaRequest (US-001) (#269158)
## Summary Phase 1, US-001 of [elastic/kibana-team#3204](elastic/kibana-team#3204): _First-Class Space ID on Core Request_. Adds `spaceId: string` as a first-class property on `KibanaRequest` and `KibanaRequestState` (server side), with the backing implementation in `CoreKibanaRequest`. ### What this PR does - Adds `spaceId: string` to `KibanaRequestState` (the per-request Hapi app state). - Adds `readonly spaceId: string` to the `KibanaRequest` public interface with JSDoc. - Implements `spaceId` on `CoreKibanaRequest`, reading from `appState.spaceId` and defaulting to `'default'`. This means the property is **always populated** — never `undefined` — even before US-002 writes the resolved space into the app state. - Updates the `createKibanaRequest` mock fixture default to include `spaceId: 'default'` so existing tests compile without changes. ### What this PR does NOT do - No space extraction from the URL yet (that is US-002, which will write to `app.spaceId` in the `onRequest` handler in `http_server.ts`). - No changes to the Spaces plugin, `@kbn/spaces-utils`, or any downstream consumers. ### Checklist - [x] `node scripts/type_check --project src/core/packages/http/server/tsconfig.json` ✅ - [x] `node scripts/type_check --project src/core/packages/http/router-server-internal/tsconfig.json` ✅ - [x] `node scripts/type_check --project src/core/packages/http/router-server-mocks/tsconfig.json` ✅ - [x] `node scripts/type_check --project src/core/packages/http/server-internal/tsconfig.json` ✅ - [x] `node scripts/check_changes.ts` ✅ Made with [Cursor](https://cursor.com) Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent d979b6d commit b44c413

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

src/core/packages/http/router-server-internal/src/request.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,8 @@ export class CoreKibanaRequest<
154154
public readonly authzResult?: Record<string, boolean>;
155155
/** {@inheritDoc KibanaRequest.timing} */
156156
public readonly serverTiming: RequestTiming;
157+
/** {@inheritDoc KibanaRequest.spaceId} */
158+
public readonly spaceId: string;
157159

158160
/** @internal */
159161
protected readonly [requestSymbol]!: Request;
@@ -182,6 +184,7 @@ export class CoreKibanaRequest<
182184
this.uuid = appState?.requestUuid ?? uuidv4();
183185
this.rewrittenUrl = appState?.rewrittenUrl;
184186
this.authzResult = appState?.authzResult;
187+
this.spaceId = appState?.spaceId ?? 'default';
185188
this.serverTiming = new RequestTimingImpl(appState?.timingState ?? { events: [] });
186189
this.injectHostInfo(request);
187190

src/core/packages/http/server/src/router/request.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ export interface KibanaRequestState extends RequestApplicationState {
6363
startTime: number;
6464
redactedSessionId?: string;
6565
timingState?: RequestTimingState;
66+
/** The resolved Kibana space ID for this request. Set by Core's onRequest handler; defaults to `'default'` when absent. */
67+
spaceId?: string;
6668
}
6769

6870
/**
@@ -245,6 +247,15 @@ export interface KibanaRequest<
245247
* Only available during development.
246248
*/
247249
readonly serverTiming: RequestTiming;
250+
251+
/**
252+
* The resolved Kibana space ID for this request.
253+
*
254+
* @remarks
255+
* Always populated. Defaults to `'default'` for requests that do not target an explicit space
256+
* (i.e. requests whose URL does not contain a `/s/{spaceId}` prefix).
257+
*/
258+
readonly spaceId: string;
248259
}
249260

250261
/**

0 commit comments

Comments
 (0)