@ekanos/harness 0.31.0 → 0.32.0

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.
@@ -0,0 +1,10 @@
1
+ import type { CatalogSnapshot } from '@ekanos/integration-schema';
2
+ /**
3
+ * Which of the developer's Sources the harness reads: its catalog (global
4
+ * packages plus the ones attached to that Source) and its publish status.
5
+ * Shown only when there is a choice to make; it never changes where
6
+ * `ekanos publish` sends a package.
7
+ */
8
+ export declare function SourceSwitcher({ snapshot }: {
9
+ snapshot: CatalogSnapshot;
10
+ }): import("react").JSX.Element | null;
@@ -0,0 +1,82 @@
1
+ "use client";
2
+ import { jsx, jsxs } from "react/jsx-runtime";
3
+ import { useId } from "react";
4
+ import {
5
+ Select,
6
+ SelectContent,
7
+ SelectItem,
8
+ SelectTrigger,
9
+ SelectValue
10
+ } from "@ekanos/ui/select";
11
+ import { useSelectSource } from "../lib/host-data.js";
12
+ function SourceSwitcher({ snapshot }) {
13
+ const labelId = useId();
14
+ const select = useSelectSource();
15
+ const seats = snapshot.seats ?? [];
16
+ const current = snapshot.scope === "source" ? snapshot.source?.slug : null;
17
+ if (seats.length === 0) return null;
18
+ if (seats.length === 1 && current === seats[0]?.slug) return null;
19
+ const switching = select.isPending || select.isSuccess && select.variables !== current;
20
+ return /* @__PURE__ */ jsxs(
21
+ "div",
22
+ {
23
+ className: "flex flex-wrap items-center gap-x-2 gap-y-1 text-sm",
24
+ "data-test": "source-switcher",
25
+ children: [
26
+ /* @__PURE__ */ jsx("span", { id: labelId, className: "text-muted-foreground", children: "Source" }),
27
+ /* @__PURE__ */ jsxs(
28
+ Select,
29
+ {
30
+ value: (switching ? select.variables : current) ?? null,
31
+ onValueChange: (value) => {
32
+ if (typeof value === "string" && value !== current) {
33
+ select.mutate(value);
34
+ }
35
+ },
36
+ disabled: select.isPending,
37
+ children: [
38
+ /* @__PURE__ */ jsx(
39
+ SelectTrigger,
40
+ {
41
+ size: "sm",
42
+ className: "min-w-40",
43
+ "aria-labelledby": labelId,
44
+ "data-test": "source-switcher-trigger",
45
+ children: /* @__PURE__ */ jsx(SelectValue, { placeholder: "Pick a Source" })
46
+ }
47
+ ),
48
+ /* @__PURE__ */ jsx(SelectContent, { children: seats.map((seat) => /* @__PURE__ */ jsx(
49
+ SelectItem,
50
+ {
51
+ value: seat.slug,
52
+ "data-test": `source-switcher-${seat.slug}`,
53
+ children: seat.name ?? seat.slug
54
+ },
55
+ seat.slug
56
+ )) })
57
+ ]
58
+ }
59
+ ),
60
+ switching ? /* @__PURE__ */ jsx(
61
+ "span",
62
+ {
63
+ className: "text-muted-foreground text-xs",
64
+ "data-test": "source-switching",
65
+ children: "Reading its catalog\u2026"
66
+ }
67
+ ) : null,
68
+ select.isError ? /* @__PURE__ */ jsx(
69
+ "span",
70
+ {
71
+ className: "text-destructive text-xs",
72
+ "data-test": "source-switch-error",
73
+ children: select.error.message
74
+ }
75
+ ) : null
76
+ ]
77
+ }
78
+ );
79
+ }
80
+ export {
81
+ SourceSwitcher
82
+ };
@@ -11,6 +11,11 @@ export declare function usePublishSnapshot(): import("@tanstack/react-query").Us
11
11
  }, Error>;
12
12
  /** Ask `ekanos dev` for a fresh read; the polled files pick it up a moment later. */
13
13
  export declare function useRefreshHostData(): import("@tanstack/react-query").UseMutationResult<void, Error, void, unknown>;
14
+ /**
15
+ * Point the harness at another of the developer's Sources: `ekanos dev`
16
+ * re-reads the catalog and publish status for it a moment later.
17
+ */
18
+ export declare function useSelectSource(): import("@tanstack/react-query").UseMutationResult<void, Error, string, unknown>;
14
19
  export type PublishTone = 'clear' | 'success' | 'warning' | 'destructive' | 'info' | 'neutral';
15
20
  export declare function describePublishState(state: string): {
16
21
  label: string;
@@ -50,6 +50,29 @@ function useRefreshHostData() {
50
50
  }
51
51
  });
52
52
  }
53
+ function useSelectSource() {
54
+ const queryClient = useQueryClient();
55
+ return useMutation({
56
+ mutationFn: async (source) => {
57
+ const response = await fetch(`${HOST_API}/source`, {
58
+ method: "POST",
59
+ headers: { "content-type": "application/json" },
60
+ body: JSON.stringify({ source })
61
+ });
62
+ if (!response.ok) {
63
+ const body = await response.json().catch(() => null);
64
+ throw new Error(body?.error ?? `Switching answered ${response.status}`);
65
+ }
66
+ },
67
+ onSuccess: () => {
68
+ for (const delay of [1500, 4e3]) {
69
+ setTimeout(() => {
70
+ void queryClient.invalidateQueries({ queryKey: ["host"] });
71
+ }, delay);
72
+ }
73
+ }
74
+ });
75
+ }
53
76
  const STATE_WORDS = {
54
77
  submitted: {
55
78
  label: "Waiting for checks",
@@ -155,5 +178,6 @@ export {
155
178
  sortVersions,
156
179
  useCatalogSnapshot,
157
180
  usePublishSnapshot,
158
- useRefreshHostData
181
+ useRefreshHostData,
182
+ useSelectSource
159
183
  };
@@ -19,6 +19,7 @@ import { RunLogCopyButton } from "../components/run-log-copy.js";
19
19
  import { FOCUS_RING } from "../components/scrollable-nav.js";
20
20
  import { SegmentedControl } from "../components/segmented-control.js";
21
21
  import { ShellHeader } from "../components/shell-header.js";
22
+ import { SourceSwitcher } from "../components/source-switcher.js";
22
23
  import {
23
24
  catalogHref,
24
25
  catalogPackageName,
@@ -93,10 +94,10 @@ function productReach(product) {
93
94
  function scopeLine(snapshot) {
94
95
  if (!snapshot) return null;
95
96
  if (snapshot.scope === "source") {
96
- return `Everything ${snapshot.source?.name ?? snapshot.source?.slug ?? "your Source"} can use, including what it has not turned on yet.`;
97
+ return `Everything global on Ekanos, plus what is attached to ${snapshot.source?.name ?? snapshot.source?.slug ?? "your Source"}, including what it has not turned on yet.`;
97
98
  }
98
99
  if (snapshot.scope === "public") {
99
- return "Everything available on Ekanos to any Source. Log in with a Source to see its own integrations too.";
100
+ return snapshot.seats?.length ? "Everything global on Ekanos. Pick one of your Sources to add what is attached to it." : "Everything global on Ekanos. Log in with a Source to see what is attached to it too.";
100
101
  }
101
102
  return null;
102
103
  }
@@ -135,6 +136,7 @@ function CatalogPage() {
135
136
  /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1", children: [
136
137
  /* @__PURE__ */ jsx("h2", { className: "font-heading text-xl font-normal", children: "Integrations and experiences to build on" }),
137
138
  /* @__PURE__ */ jsx("p", { className: "text-muted-foreground text-sm", children: scopeLine(snapshot) }),
139
+ /* @__PURE__ */ jsx(SourceSwitcher, { snapshot }),
138
140
  /* @__PURE__ */ jsx(HostFreshness, { fetchedAt: snapshot.fetchedAt, host: snapshot.host })
139
141
  ] }),
140
142
  snapshot.unavailable ? /* @__PURE__ */ jsx(Alert, { variant: "warning", "data-test": "catalog-unavailable", children: /* @__PURE__ */ jsx(AlertDescription, { children: snapshot.unavailable.message }) }) : null,
@@ -341,7 +341,7 @@ function createEkanosApiRouter(partial = {}) {
341
341
  const method = request.method.toUpperCase();
342
342
  const [head, ...rest] = segments;
343
343
  if (head === "host") {
344
- const hosted = handleHostRoute(root.root, method, rest);
344
+ const hosted = await handleHostRoute(root.root, method, rest, request);
345
345
  if (hosted) return hosted;
346
346
  }
347
347
  try {
@@ -11,8 +11,19 @@ export declare function readPublishSnapshot(root: string): PublishStatusSnapshot
11
11
  /** Ask the running `ekanos dev` for a fresh read of both snapshots. */
12
12
  export declare function requestHostRefresh(root: string): void;
13
13
  /**
14
- * `GET host/catalog`, `GET host/publish-status`, `POST host/refresh`, served
15
- * from `root` (the project, or the repo root). Null for anything else, so the
16
- * caller answers its own 404.
14
+ * Pick the Source the harness reads, among the seats `ekanos dev` last
15
+ * listed, and ask for a fresh read. The CLI checks the pick against the seats
16
+ * again and the host checks the seat itself; this only keeps a typo out.
17
17
  */
18
- export declare function handleHostRoute(root: string, method: string, rest: readonly string[]): Response | null;
18
+ export declare function selectSource(root: string, source: string): {
19
+ ok: true;
20
+ } | {
21
+ ok: false;
22
+ error: string;
23
+ };
24
+ /**
25
+ * `GET host/catalog`, `GET host/publish-status`, `POST host/refresh`,
26
+ * `POST host/source` (`{ source }`), served from `root` (the project, or the
27
+ * repo root). Null for anything else, so the caller answers its own 404.
28
+ */
29
+ export declare function handleHostRoute(root: string, method: string, rest: readonly string[], request?: Request): Promise<Response | null>;
@@ -1,12 +1,14 @@
1
1
  import {
2
2
  CatalogSnapshotSchema,
3
- PublishStatusSnapshotSchema
3
+ PublishStatusSnapshotSchema,
4
+ SourceSelectionSchema
4
5
  } from "@ekanos/integration-schema";
5
6
  import * as fs from "node:fs";
6
7
  import * as path from "node:path";
7
8
  const CATALOG_FILE = path.join(".ekanos", "catalog.json");
8
9
  const PUBLISH_FILE = path.join(".ekanos", "publish-status.json");
9
10
  const REFRESH_REQUEST = path.join(".ekanos", "refresh-request");
11
+ const SOURCE_SELECTION = path.join(".ekanos", "source-selection.json");
10
12
  function readJson(root, file) {
11
13
  try {
12
14
  return JSON.parse(fs.readFileSync(path.join(root, file), "utf8"));
@@ -30,6 +32,20 @@ function requestHostRefresh(root) {
30
32
  fs.writeFileSync(file, `${(/* @__PURE__ */ new Date()).toISOString()}
31
33
  `);
32
34
  }
35
+ function selectSource(root, source) {
36
+ const seats = readCatalogSnapshot(root)?.seats ?? [];
37
+ if (!seats.some((seat) => seat.slug === source)) {
38
+ return { ok: false, error: `You hold no seat on "${source}".` };
39
+ }
40
+ const file = path.join(root, SOURCE_SELECTION);
41
+ fs.mkdirSync(path.dirname(file), { recursive: true });
42
+ const temp = `${file}.tmp`;
43
+ fs.writeFileSync(temp, `${JSON.stringify({ source })}
44
+ `, { mode: 384 });
45
+ fs.renameSync(temp, file);
46
+ requestHostRefresh(root);
47
+ return { ok: true };
48
+ }
33
49
  function json(body, status = 200) {
34
50
  return new Response(JSON.stringify(body), {
35
51
  status,
@@ -39,7 +55,7 @@ function json(body, status = 200) {
39
55
  }
40
56
  });
41
57
  }
42
- function handleHostRoute(root, method, rest) {
58
+ async function handleHostRoute(root, method, rest, request) {
43
59
  const [name] = rest;
44
60
  if (rest.length !== 1) return null;
45
61
  if (name === "catalog") {
@@ -57,11 +73,28 @@ function handleHostRoute(root, method, rest) {
57
73
  requestHostRefresh(root);
58
74
  return json({ requested: true }, 202);
59
75
  }
76
+ if (name === "source") {
77
+ if (method !== "POST") return json({ error: "POST only." }, 405);
78
+ let body = null;
79
+ try {
80
+ body = await request?.json();
81
+ } catch {
82
+ body = null;
83
+ }
84
+ const parsed = SourceSelectionSchema.safeParse(body);
85
+ if (!parsed.success) {
86
+ return json({ error: 'Send { "source": "<slug>" }.' }, 400);
87
+ }
88
+ const picked = selectSource(root, parsed.data.source);
89
+ if (!picked.ok) return json({ error: picked.error }, 400);
90
+ return json({ requested: true, source: parsed.data.source }, 202);
91
+ }
60
92
  return null;
61
93
  }
62
94
  export {
63
95
  handleHostRoute,
64
96
  readCatalogSnapshot,
65
97
  readPublishSnapshot,
66
- requestHostRefresh
98
+ requestHostRefresh,
99
+ selectSource
67
100
  };
@@ -330,10 +330,11 @@ function createRepoApiRouter(partial) {
330
330
  const method = request.method.toUpperCase();
331
331
  const [head, second, third, fourth] = segments;
332
332
  if (head === "host") {
333
- const hosted = handleHostRoute(
333
+ const hosted = await handleHostRoute(
334
334
  partial.repoRoot,
335
335
  method,
336
- segments.slice(1)
336
+ segments.slice(1),
337
+ request
337
338
  );
338
339
  if (hosted) return hosted;
339
340
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ekanos/harness",
3
- "version": "0.31.0",
3
+ "version": "0.32.0",
4
4
  "private": false,
5
5
  "description": "The Ekanos integration dev harness — every surface of an integration rendered in real Ekanos chrome, from fixtures, with no Supabase or auth; and, in live mode, a real localhost OAuth loop over your own dev-app credentials.",
6
6
  "homepage": "https://sdk.ekanos.dev/harness/overview",
@@ -72,13 +72,13 @@
72
72
  "access": "public"
73
73
  },
74
74
  "dependencies": {
75
- "@ekanos/integration-schema": "0.31.0",
75
+ "@ekanos/integration-schema": "0.32.0",
76
76
  "next-themes": "0.4.6",
77
77
  "tw-animate-css": "1.4.0"
78
78
  },
79
79
  "devDependencies": {
80
- "@ekanos/sdk": "0.31.0",
81
- "@ekanos/ui": "0.31.0",
80
+ "@ekanos/sdk": "0.32.0",
81
+ "@ekanos/ui": "0.32.0",
82
82
  "@kit/tsconfig": "0.1.0",
83
83
  "@tailwindcss/postcss": "4.3.5",
84
84
  "@tanstack/react-query": "5.107.1",
@@ -98,8 +98,8 @@
98
98
  "zod": "4.6.7"
99
99
  },
100
100
  "peerDependencies": {
101
- "@ekanos/sdk": "^0.31.0",
102
- "@ekanos/ui": "^0.31.0",
101
+ "@ekanos/sdk": "^0.32.0",
102
+ "@ekanos/ui": "^0.32.0",
103
103
  "@tanstack/react-query": "^5.101.4",
104
104
  "next": "^16.0.0",
105
105
  "next-intl": "^4.14.7",