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
21 changes: 21 additions & 0 deletions .changeset/39134-hosted-comment-threads-read.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
'@objectstack/runtime': patch
'@objectstack/plugin-audit': patch
'@objectstack/spec': patch
'@objectstack/client': patch
---

feat(runtime, plugin-audit): a hosted kernel serves the comment threads read

Clause-②: yes (widening)
Metadata-protocol: none

`POST /api/v1/comments/threads/query`, the read behind the list page's comment panel, now answers on a kernel with no HTTP server of its own (a hosted tenant kernel), as it already did on a self-hosted one:

- the dispatcher's `/comments` domain claims it beside the three comment doors and forwards the request, body and query string unread, to the `comments` service;
- the service runs the same registration the self-hosted mount runs, so the caller, the strict body, the refusal of any query parameter and the read's own refusals (`400`, `401 UNAUTHENTICATED`, `403 FEEDS_DISABLED`, `403 PERMISSION_DENIED`, `404 OBJECT_NOT_FOUND`) are the same bytes on both shapes;
- on the hosted shape the dispatcher's two preamble gates run before the service: a signed-in caller who is not a member of the request's environment is refused `403 PROJECT_MEMBERSHIP_REQUIRED`, which the self-hosted mount does not answer, and a session that still owes a sign-in step is refused `403` with the authentication policy's own code by the dispatcher's gate instead of by the read. Stricter than the self-hosted mount, never looser;
- the same holds on a host composed as `objectstack serve` / `objectstack dev` composes one, through the dispatcher plugin's fallback;
- a hosted kernel without `@objectstack/plugin-audit` answers `501 NOT_IMPLEMENTED`, never a route miss.

Before, a hosted kernel answered the read `404 ROUTE_NOT_FOUND` and its boot log said the read was not served there; that clause is gone. `client.comments.queryThreads` is unchanged and now reaches both shapes; its JSDoc names both.
22 changes: 15 additions & 7 deletions content/docs/api/data-api.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -685,8 +685,13 @@ the approvals-family read and is unchanged.
## Comment threads

The discussions on the records a list shows, in one read: what a list page's
comment panel asks. Served by `@objectstack/plugin-audit` on a kernel with an
HTTP server; the SDK method is `client.comments.queryThreads`.
comment panel asks. Served by `@objectstack/plugin-audit`, on a self-hosted
kernel from its own HTTP mount and on a hosted tenant kernel through the
dispatcher's `/comments` domain. Both shapes run the same caller rule, body
and the read's own refusals; on the hosted shape the dispatcher's gates run
first and stop a held sign-in and a non-member of the environment before the
read runs (the last two refusals below). The SDK method is
`client.comments.queryThreads`.

### `POST /comments/threads/query`

Expand Down Expand Up @@ -761,11 +766,14 @@ Refusals:
cannot read: `403 PERMISSION_DENIED`, the object read's own refusal, never an
empty answer;
- an object on a driver that cannot run the subquery (MongoDB, OData):
`400 INVALID_FILTER`.

A kernel with no HTTP server (a hosted tenant kernel) serves the other comment
doors through the dispatcher's `/comments` domain, which does not claim this
read, so it is not served there.
`400 INVALID_FILTER`;
- a session that still owes a sign-in step (a password that expired or must be
changed, a required multi-factor enrollment): `403` with the authentication
policy's own code. On a hosted tenant kernel the dispatcher's sign-in gate
answers it before the read runs;
- on a hosted tenant kernel only, before the read runs: a signed-in caller who
is not a member of the request's environment, `403 PROJECT_MEMBERSHIP_REQUIRED`;
a kernel composed without `@objectstack/plugin-audit`, `501 NOT_IMPLEMENTED`.

---

Expand Down
8 changes: 6 additions & 2 deletions packages/client/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7473,8 +7473,12 @@ export class ObjectStackClient {
* [NOT_IMPLEMENTED] on deployments without the sharing service.
*/
/**
* Comment threads across records. Served by plugin-audit's comment
* registrar on a kernel with an HTTP server.
* Comment threads across records. Served by `@objectstack/plugin-audit`
* on both server shapes: on a self-hosted kernel from its own HTTP mount,
* and on a hosted tenant kernel (no HTTP server of its own) through the
* runtime dispatcher's `/comments` domain, which forwards the request to
* the same registration. A hosted kernel composed without plugin-audit
* answers `501 NOT_IMPLEMENTED`.
*/
comments = {
/**
Expand Down
25 changes: 11 additions & 14 deletions packages/plugins/plugin-audit/src/audit-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,8 @@ export class AuditPlugin implements Plugin {
// (`ICommentDoorsService.handleCommentDoor`): the runtime dispatcher's
// `/comments` domain forwards to it on a kernel with no `http.server` (a
// hosted tenant kernel), where `mountCommentDoors` has nothing to mount
// on. Same registration as the mount; nothing is read until a request.
// on. Same registration as the mount, the comment threads read included
// (#39134); nothing is read until a request.
const commentDoors: ICommentDoorsService = {
handleCommentDoor: createCommentDoorMember((http) => registerCommentDoors(http, ctx)),
};
Expand Down Expand Up @@ -1162,14 +1163,13 @@ export class AuditPlugin implements Plugin {
* 7063285032 and 7069889899), past the row floor and without a `delete`
* grant;
* - the comment threads read (`comment-threads-query.ts`): the threads on
* the records a list filter selects, as the caller. It is mounted here
* only: the dispatcher's `/comments` domain does not claim it, so a kernel
* with no HTTP server does not serve it, and the line below says so.
* the records a list filter selects, as the caller.
*
* Every service the doors read is read per request, so a provider that
* registers after this hook is still seen. A kernel with no HTTP server (a
* hosted tenant kernel) mounts nothing here: the `comments` slot serves the
* same doors to the dispatcher (#36469), and the line says so.
* same doors and the same threads read to the dispatcher (#36469, #39134),
* and the line says so.
*/
private mountCommentDoors(ctx: PluginContext): void {
const optional = <T>(name: string): T | undefined => {
Expand All @@ -1183,15 +1183,13 @@ export class AuditPlugin implements Plugin {
const http = optional<IHttpServer>('http.server') ?? optional<IHttpServer>('http-server');
if (!http) {
// [#36469] The hosted shape: a tenant kernel owns no socket. The doors
// are not lost there: the `comments` slot (registered in `init()`) serves
// them to the runtime dispatcher's `/comments` domain, which the host's
// `createHonoApp` reaches.
// and the threads read (#39134) are not lost there: the `comments` slot
// (registered in `init()`) serves them to the runtime dispatcher's
// `/comments` domain, which the host's `createHonoApp` reaches.
ctx.logger.info(
`AuditPlugin: comment doors mounted on the 'comments' service for the dispatcher's /comments domain ` +
`(no HTTP server on this kernel): DELETE ${COMMENT_REACTION_REMOVE_ROUTE}, PUT ${COMMENT_RESOLUTION_ROUTE} ` +
`and DELETE ${COMMENT_REMOVE_ROUTE}; the comment threads read POST ${COMMENT_THREADS_QUERY_ROUTE} is not ` +
`served on this kernel (the dispatcher's /comments domain does not claim it; it is mounted only on a kernel ` +
`with an HTTP server)`,
`and DELETE ${COMMENT_REMOVE_ROUTE}, and the comment threads read at POST ${COMMENT_THREADS_QUERY_ROUTE}`,
);
return;
}
Expand Down Expand Up @@ -1236,9 +1234,8 @@ export class AuditPlugin implements Plugin {
* on the kernel's `http.server` (`mountCommentDoors`) and the private table
* behind the `comments` slot's `handleCommentDoor` (`comment-doors-member.ts`),
* so the two cannot answer a request differently. `registerCommentDoorsRoutes`
* also mounts the comment threads read; the member's table carries it too, but
* the member matches only the three doors, so only the self-hosted mount
* serves it.
* also mounts the comment threads read, and the member serves it as well
* (#39134), so both faces answer it alike.
*/
function registerCommentDoors(http: IHttpServer, ctx: PluginContext): void {
const optional = <T>(name: string): T | undefined => {
Expand Down
32 changes: 21 additions & 11 deletions packages/plugins/plugin-audit/src/comment-doors-member.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
/**
* [#36469] The comment doors, served transport-neutrally:
* `ICommentDoorsService.handleCommentDoor` (`@objectstack/spec/contracts`).
* [#39134] The comment threads read rides the same member.
*
* ## Why this exists
*
Expand All @@ -28,15 +29,21 @@
* no second copy of a door to drift from the first. The table is built on the
* first request, and every service the doors read is still read per request.
*
* The routes it serves are the three doors and the comment threads read
* (`POST /api/v1/comments/threads/query`, `comment-threads-query.ts`), which
* `registerCommentDoorsRoutes` mounts beside them: the list page's comment
* panel reads it, so a hosted kernel serves it exactly as a self-hosted one
* does (same caller, same strict body, same refusals).
*
* ⛔ The table never listens and is never the kernel's `http.server`: a
* self-hosted kernel keeps its own mount unchanged, and no path is mounted
* twice on a socket.
*
* ## What it answers outside the three routes
* ## What it answers outside the four routes
*
* A method and path that match none of the three routes answers
* A method and path that match none of the four routes answers
* `404 ENDPOINT_NOT_FOUND`, the transport's own unmatched answer, without
* reaching any door. The dispatcher claims exactly the three shapes and never
* reaching any door. The dispatcher claims exactly the four shapes and never
* forwards one.
*/

Expand All @@ -45,22 +52,25 @@ import { HonoHttpServer } from '@objectstack/plugin-hono-server';

import { COMMENT_REACTION_REMOVE_ROUTE } from './comment-reaction-routes.js';
import { COMMENT_REMOVE_ROUTE, COMMENT_RESOLUTION_ROUTE } from './comment-routes.js';
import { COMMENT_THREADS_QUERY_ROUTE } from './comment-threads-query.js';

/** One comment door's method and route pattern. */
/** One comment route's method and route pattern. */
export interface CommentDoorRoute {
method: 'DELETE' | 'PUT';
method: 'DELETE' | 'PUT' | 'POST';
route: string;
}

/**
* The three comment doors, in the self-hosted mount's registration order (the
* order a request is matched in): the unreact door, then the resolution door,
* then the own-comment delete door.
* The four comment routes the member serves, in the self-hosted mount's
* registration order (the order a request is matched in): the unreact door,
* the resolution door, the own-comment delete door, then the comment threads
* read.
*/
export const COMMENT_DOOR_ROUTES: readonly CommentDoorRoute[] = [
{ method: 'DELETE', route: COMMENT_REACTION_REMOVE_ROUTE },
{ method: 'PUT', route: COMMENT_RESOLUTION_ROUTE },
{ method: 'DELETE', route: COMMENT_REMOVE_ROUTE },
{ method: 'POST', route: COMMENT_THREADS_QUERY_ROUTE },
];

/** Does `pathname` match `pattern`, whose `:name` segments match one non-empty segment each? */
Expand All @@ -72,8 +82,8 @@ function matchesRoute(pattern: string, pathname: string): boolean {
}

/**
* The comment door `method` and `pathname` name, or `undefined`. Exported so
* the runtime's claim and this member can be pinned to the same three shapes.
* The comment route `method` and `pathname` name, or `undefined`. Exported so
* the runtime's claim and this member can be pinned to the same four shapes.
*/
export function matchCommentDoor(method: string, pathname: string): CommentDoorRoute | undefined {
const verb = method.toUpperCase();
Expand All @@ -90,7 +100,7 @@ function unmatched(): Response {

/**
* Build `handleCommentDoor` over `mount`, the function that registers the
* three doors on an `IHttpServer` (the one the self-hosted mount calls too).
* four routes on an `IHttpServer` (the one the self-hosted mount calls too).
*/
export function createCommentDoorMember(mount: (http: IHttpServer) => void): (request: Request) => Promise<Response> {
let table: HonoHttpServer | undefined;
Expand Down
18 changes: 12 additions & 6 deletions packages/plugins/plugin-audit/src/comment-threads-query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,19 @@ import { COMMENT_RESOLVED_FIELD, isReplyRow } from './comment-resolution.js';
* of that millisecond read again ordered by `id`, so the page and the cursor
* agree on which of them were answered, at any precision the column keeps.
*
* ## What is not served here
* ## Where it is served
*
* A kernel with no `http.server` (a hosted tenant kernel) reaches the other
* comment doors through the runtime dispatcher's `/comments` domain. That
* domain does not claim this route, so this read is served by the
* self-hosted mount only; `AuditPlugin` says so in its boot line on a kernel
* with no HTTP server.
* On a self-hosted kernel, from the kernel's `http.server`
* ({@link registerCommentThreadsQueryRoute}). A kernel with no `http.server`
* (a hosted tenant kernel) reaches it, as it reaches the other comment doors,
* through the runtime dispatcher's `/comments` domain, which forwards the
* request unread to the `comments` service. That service's member
* (`comment-doors-member.ts`) runs the mount's own registration, and
* `registerCommentDoorsRoutes` (`comment-routes.ts`) calls this one, so this
* handler answers on both shapes. On the hosted shape the dispatcher's two preamble gates run first:
* a signed-in caller who is not a member of the request's environment is
* refused `403 PROJECT_MEMBERSHIP_REQUIRED` there, and a held sign-in is
* refused by the dispatcher's gate before step 1 runs.
*/

/** The read's route. */
Expand Down
Loading
Loading