@zhin.js/console-contract 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from './layout.js';
2
2
  export * from './navigation.js';
3
3
  export * from './page.js';
4
+ export * from './topology.js';
package/lib/index.js CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from './layout.js';
2
2
  export * from './navigation.js';
3
3
  export * from './page.js';
4
+ export * from './topology.js';
package/lib/page.js CHANGED
@@ -45,6 +45,11 @@ export function pageRoute(owner, root, localName) {
45
45
  throw new Error(`Page owner ${owner} is outside Root ${root}`);
46
46
  }
47
47
  const relative = owner === root ? '' : owner.slice(root.length + 1);
48
+ // `pages/index.tsx` maps to the plugin path itself (e.g. sandbox → `/sandbox`),
49
+ // so demos can open the chat UI without the `/p-` leaf segment.
50
+ if (localName === 'index') {
51
+ return relative ? `/${relative}` : '/';
52
+ }
48
53
  return `/${relative ? `${relative}/` : ''}p-${localName}`;
49
54
  }
50
55
  export function assertPageLocalName(value) {
@@ -0,0 +1,41 @@
1
+ import type { LayoutManifest } from './layout.js';
2
+ import type { NavNode } from './navigation.js';
3
+ import type { PageManifest } from './page.js';
4
+ /** The two optional layout slots resolved for a concrete page route. */
5
+ export interface ConsoleLayoutSlots {
6
+ readonly nav?: Readonly<LayoutManifest>;
7
+ readonly footer?: Readonly<LayoutManifest>;
8
+ }
9
+ /**
10
+ * A route result that is safe to return to a Console client.
11
+ *
12
+ * Forbidden routes intentionally omit their page manifest, so an access check
13
+ * cannot be used to enumerate otherwise hidden page metadata.
14
+ */
15
+ export type ConsoleRouteResolution = {
16
+ readonly status: 'found';
17
+ readonly page: Readonly<PageManifest>;
18
+ readonly layouts: Readonly<ConsoleLayoutSlots>;
19
+ } | {
20
+ readonly status: 'forbidden';
21
+ } | {
22
+ readonly status: 'missing';
23
+ };
24
+ /**
25
+ * A generation-bound view of the Console. Call `resolve()` only while the
26
+ * originating ConsoleRuntime view lease is active.
27
+ */
28
+ export interface ConsoleTopology {
29
+ readonly generation: number;
30
+ readonly pages: readonly Readonly<PageManifest>[];
31
+ readonly navigation: readonly Readonly<NavNode>[];
32
+ resolve(path: string): Readonly<ConsoleRouteResolution>;
33
+ }
34
+ /** JSON shape returned by a Host topology query. */
35
+ export interface ConsoleTopologyResponse {
36
+ readonly generation: number;
37
+ readonly pages: readonly Readonly<PageManifest>[];
38
+ readonly navigation: readonly Readonly<NavNode>[];
39
+ readonly route?: string;
40
+ readonly resolution?: Readonly<ConsoleRouteResolution>;
41
+ }
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zhin.js/console-contract",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Zero-dependency Page, Layout, route and navigation contracts for Zhin.js plugins",
5
5
  "type": "module",
6
6
  "main": "./lib/index.js",
@@ -17,7 +17,7 @@
17
17
  "src"
18
18
  ],
19
19
  "devDependencies": {
20
- "@types/node": "^26.1.0",
20
+ "@types/node": "^26.1.2",
21
21
  "typescript": "^6.0.3"
22
22
  },
23
23
  "repository": {
package/src/index.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from './layout.js';
2
2
  export * from './navigation.js';
3
3
  export * from './page.js';
4
+ export * from './topology.js';
package/src/page.ts CHANGED
@@ -87,6 +87,11 @@ export function pageRoute(owner: string, root: string, localName: string): strin
87
87
  throw new Error(`Page owner ${owner} is outside Root ${root}`);
88
88
  }
89
89
  const relative = owner === root ? '' : owner.slice(root.length + 1);
90
+ // `pages/index.tsx` maps to the plugin path itself (e.g. sandbox → `/sandbox`),
91
+ // so demos can open the chat UI without the `/p-` leaf segment.
92
+ if (localName === 'index') {
93
+ return relative ? `/${relative}` : '/';
94
+ }
90
95
  return `/${relative ? `${relative}/` : ''}p-${localName}`;
91
96
  }
92
97
 
@@ -0,0 +1,44 @@
1
+ import type { LayoutManifest } from './layout.js';
2
+ import type { NavNode } from './navigation.js';
3
+ import type { PageManifest } from './page.js';
4
+
5
+ /** The two optional layout slots resolved for a concrete page route. */
6
+ export interface ConsoleLayoutSlots {
7
+ readonly nav?: Readonly<LayoutManifest>;
8
+ readonly footer?: Readonly<LayoutManifest>;
9
+ }
10
+
11
+ /**
12
+ * A route result that is safe to return to a Console client.
13
+ *
14
+ * Forbidden routes intentionally omit their page manifest, so an access check
15
+ * cannot be used to enumerate otherwise hidden page metadata.
16
+ */
17
+ export type ConsoleRouteResolution =
18
+ | {
19
+ readonly status: 'found';
20
+ readonly page: Readonly<PageManifest>;
21
+ readonly layouts: Readonly<ConsoleLayoutSlots>;
22
+ }
23
+ | { readonly status: 'forbidden' }
24
+ | { readonly status: 'missing' };
25
+
26
+ /**
27
+ * A generation-bound view of the Console. Call `resolve()` only while the
28
+ * originating ConsoleRuntime view lease is active.
29
+ */
30
+ export interface ConsoleTopology {
31
+ readonly generation: number;
32
+ readonly pages: readonly Readonly<PageManifest>[];
33
+ readonly navigation: readonly Readonly<NavNode>[];
34
+ resolve(path: string): Readonly<ConsoleRouteResolution>;
35
+ }
36
+
37
+ /** JSON shape returned by a Host topology query. */
38
+ export interface ConsoleTopologyResponse {
39
+ readonly generation: number;
40
+ readonly pages: readonly Readonly<PageManifest>[];
41
+ readonly navigation: readonly Readonly<NavNode>[];
42
+ readonly route?: string;
43
+ readonly resolution?: Readonly<ConsoleRouteResolution>;
44
+ }