@ekanos/harness 0.1.5 → 0.3.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.
Files changed (47) hide show
  1. package/README.md +243 -79
  2. package/dist/api.d.ts +42 -0
  3. package/dist/api.js +17 -0
  4. package/dist/internal/components/dev-toolbar.js +4 -2
  5. package/dist/internal/components/harness-providers.d.ts +8 -2
  6. package/dist/internal/components/harness-providers.js +4 -1
  7. package/dist/internal/components/local-oauth-panel.d.ts +29 -0
  8. package/dist/internal/components/local-oauth-panel.js +355 -0
  9. package/dist/internal/lib/actions-transport.d.ts +30 -0
  10. package/dist/internal/lib/actions-transport.js +6 -0
  11. package/dist/internal/lib/harness-fetch-interceptor.d.ts +53 -14
  12. package/dist/internal/lib/harness-fetch-interceptor.js +96 -0
  13. package/dist/internal/lib/oauth-setup-guide.d.ts +43 -0
  14. package/dist/internal/lib/oauth-setup-guide.js +28 -0
  15. package/dist/internal/lib/original-fetch.d.ts +36 -0
  16. package/dist/internal/lib/original-fetch.js +23 -0
  17. package/dist/internal/lib/run-activation-hook.d.ts +2 -8
  18. package/dist/internal/lib/toolbar-context.d.ts +7 -3
  19. package/dist/internal/lib/toolbar-context.js +10 -5
  20. package/dist/internal/lib/trigger-contract.d.ts +99 -0
  21. package/dist/internal/lib/trigger-contract.js +25 -0
  22. package/dist/internal/lib/trigger-runner.d.ts +55 -0
  23. package/dist/internal/lib/trigger-runner.js +153 -0
  24. package/dist/internal/routes/activation-page.js +42 -28
  25. package/dist/internal/routes/integration-layout.js +6 -1
  26. package/dist/internal/routes/triggers-page.js +121 -147
  27. package/dist/internal/server/actions-fixtures-context.d.ts +57 -0
  28. package/dist/internal/server/actions-fixtures-context.js +52 -0
  29. package/dist/internal/server/api-router.d.ts +54 -0
  30. package/dist/internal/server/api-router.js +575 -0
  31. package/dist/internal/server/live-context.d.ts +93 -0
  32. package/dist/internal/server/live-context.js +93 -0
  33. package/dist/internal/server/local-secrets.d.ts +84 -0
  34. package/dist/internal/server/local-secrets.js +144 -0
  35. package/dist/internal/server/loopback-guard.d.ts +33 -0
  36. package/dist/internal/server/loopback-guard.js +38 -0
  37. package/dist/internal/server/nonce-store.d.ts +38 -0
  38. package/dist/internal/server/nonce-store.js +40 -0
  39. package/dist/internal/server/oauth-loop.d.ts +114 -0
  40. package/dist/internal/server/oauth-loop.js +141 -0
  41. package/dist/internal/server/project-root.d.ts +29 -0
  42. package/dist/internal/server/project-root.js +31 -0
  43. package/dist/internal/server/storage-read.d.ts +34 -0
  44. package/dist/internal/server/storage-read.js +53 -0
  45. package/dist/registry.d.ts +73 -1
  46. package/dist/registry.js +21 -1
  47. package/package.json +13 -7
@@ -1,6 +1,6 @@
1
1
  "use client";
2
2
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
3
- import { useState } from "react";
3
+ import { useMemo, useState } from "react";
4
4
  import { notFound } from "next/navigation";
5
5
  import { Alert, AlertDescription, AlertTitle } from "@ekanos/ui/alert";
6
6
  import { Badge } from "@ekanos/ui/badge";
@@ -13,6 +13,7 @@ import {
13
13
  DialogTitle
14
14
  } from "@ekanos/ui/dialog";
15
15
  import { HARNESS_ACCOUNT_ID } from "../../registry.js";
16
+ import { LocalOAuthPanel } from "../components/local-oauth-panel.js";
16
17
  import { useDefinitionMockContext } from "../lib/definition-mock-context.js";
17
18
  import {
18
19
  useHarnessDataMode,
@@ -20,20 +21,25 @@ import {
20
21
  } from "../lib/harness-hooks.js";
21
22
  import { clearLiveActivationData } from "../lib/live-activation-store.js";
22
23
  import { hasSensitiveValues, redactSensitive } from "../lib/redact.js";
23
- import {
24
- runOnActivateHook
25
- } from "../lib/run-activation-hook.js";
26
24
  import { useToolbar } from "../lib/toolbar-context.js";
25
+ import {
26
+ createLocalTriggerRunner,
27
+ createServerTriggerRunner
28
+ } from "../lib/trigger-runner.js";
27
29
  import { useHarnessIntegration } from "../registry-context.js";
28
30
  function ActivationPage() {
29
- const [flow, setFlow] = useState({
30
- open: true,
31
+ const integration = useHarnessIntegration();
32
+ const [flow, setFlow] = useState(() => ({
33
+ // An OAuth integration starts with the dialog CLOSED: its Connect button
34
+ // needs the Local OAuth credentials saved first, and the panel that takes
35
+ // them sits on this page — under a modal backdrop if the dialog opened
36
+ // on top of it. Everything else opens straight into the connect flow.
37
+ open: !integration?.definition?.oauth,
31
38
  connected: false,
32
39
  result: null,
33
40
  revealed: false,
34
41
  activationHook: null
35
- });
36
- const integration = useHarnessIntegration();
42
+ }));
37
43
  const { state: toolbar } = useToolbar();
38
44
  const mode = useHarnessDataMode();
39
45
  const activationData = useLiveActivationData();
@@ -41,9 +47,14 @@ function ActivationPage() {
41
47
  integration ?? { slug: "", name: "", description: "", widgets: [] },
42
48
  toolbar.variant
43
49
  );
50
+ const definition = integration?.definition;
51
+ const runner = useMemo(() => {
52
+ if (!integration || !definition) return null;
53
+ if (mode === "live") return createServerTriggerRunner(integration.slug);
54
+ return ctx ? createLocalTriggerRunner(definition, ctx) : null;
55
+ }, [integration, definition, mode, ctx]);
44
56
  if (!integration) notFound();
45
57
  const ActivationForm = integration.activationForm;
46
- const definition = integration.definition;
47
58
  const capabilities = definition?.capabilities ?? [];
48
59
  const permissions = definition?.permissions ?? [];
49
60
  const summary = definition?.description ?? integration.description;
@@ -54,30 +65,24 @@ function ActivationPage() {
54
65
  "data-test": "activation",
55
66
  children: [
56
67
  /* @__PURE__ */ jsxs(Alert, { children: [
57
- /* @__PURE__ */ jsx(AlertTitle, { children: "Submissions go nowhere" }),
68
+ /* @__PURE__ */ jsx(AlertTitle, { children: mode === "live" ? "Submissions run onActivate on the dev server" : "Submissions go nowhere" }),
58
69
  /* @__PURE__ */ jsxs(AlertDescription, { children: [
59
70
  /* @__PURE__ */ jsxs("p", { children: [
60
- "The harness has no backend. Submitting shows you the",
71
+ "The harness has no Fusion backend. Submitting shows you the",
61
72
  " ",
62
73
  /* @__PURE__ */ jsx("code", { children: "ActivationResult" }),
63
- " your form handed back instead of posting it \u2014 which is the part worth checking, since that payload is what the real activation action would persist. The dialog, the capability and permission sections and the connected state are the real ones, rendered from your ",
74
+ " your form handed back instead of persisting it \u2014 which is the part worth checking, since that payload is what the real activation action would store. The dialog, the capability and permission sections and the connected state are the real ones, rendered from your ",
64
75
  /* @__PURE__ */ jsx("code", { children: "defineIntegration()" }),
65
76
  " ",
66
77
  "declaration."
67
78
  ] }),
68
- /* @__PURE__ */ jsxs("p", { children: [
69
- /* @__PURE__ */ jsx("code", { children: "onActivate" }),
70
- " below always runs against this mock context, live toggle or not \u2014 its network calls never leave your machine here. A widget on this integration is different: it already reaches real vendors through",
71
- " ",
72
- /* @__PURE__ */ jsx("code", { children: "useIntegrationFetch()" }),
73
- " once you flip the toolbar to Live API. Both reach real systems for real only after you publish to the dev host."
74
- ] })
79
+ /* @__PURE__ */ jsx("p", { "data-test": "activation-mode-notice-top", children: mode === "live" ? "Live API: an OAuth form\u2019s Connect runs the real loop through the generated shell (see Local OAuth below), onActivate runs on the server-held context that loop stored tokens in, and widgets reach real vendors through useIntegrationFetch(). The host runs the same declarations, with real enforcement, after you publish." : "Fixtures: an OAuth form reads its connection status from oauth.connected in your harness entry, onActivate runs in this browser against a context seeded from triggerMocks, and nothing leaves your machine." })
75
80
  ] })
76
81
  ] }),
77
82
  /* @__PURE__ */ jsxs("div", { className: "bg-card flex flex-wrap items-center justify-between gap-3 rounded-lg border p-5", children: [
78
83
  /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1", children: [
79
84
  /* @__PURE__ */ jsx("span", { className: "text-sm font-medium", children: flow.connected ? "Connected" : "Not connected" }),
80
- /* @__PURE__ */ jsx("span", { className: "text-muted-foreground text-sm", children: flow.connected ? "The dialog now shows the manage view, whose only action is Disconnect." : "The dialog shows the scope disclosure and your activation form." })
85
+ /* @__PURE__ */ jsx("span", { className: "text-muted-foreground text-sm", children: flow.connected ? "The dialog now shows the manage view, whose only action is Disconnect." : definition?.oauth ? "Save your local OAuth credentials below, then open the connect dialog and click Connect." : "The dialog shows the scope disclosure and your activation form." })
81
86
  ] }),
82
87
  /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
83
88
  /* @__PURE__ */ jsx(
@@ -110,6 +115,15 @@ function ActivationPage() {
110
115
  )
111
116
  ] })
112
117
  ] }),
118
+ definition ? /* @__PURE__ */ jsx(
119
+ LocalOAuthPanel,
120
+ {
121
+ integration,
122
+ definition,
123
+ mode,
124
+ variant: toolbar.variant
125
+ }
126
+ ) : null,
113
127
  ActivationForm ? /* @__PURE__ */ jsx(
114
128
  Dialog,
115
129
  {
@@ -156,10 +170,7 @@ function ActivationPage() {
156
170
  productSlug: integration.slug,
157
171
  inline: true,
158
172
  onSuccess: async (result) => {
159
- const activationHook = await runOnActivateHook(
160
- definition,
161
- ctx
162
- );
173
+ const activationHook = runner ? await runner.activate() : { status: "skipped" };
163
174
  setFlow({
164
175
  open: false,
165
176
  connected: true,
@@ -224,12 +235,15 @@ function ActivationPage() {
224
235
  2
225
236
  ) })
226
237
  ] }) : null,
227
- flow.activationHook ? /* @__PURE__ */ jsx(OnActivatePanel, { outcome: flow.activationHook }) : null
238
+ flow.activationHook ? /* @__PURE__ */ jsx(OnActivatePanel, { outcome: flow.activationHook, mode }) : null
228
239
  ]
229
240
  }
230
241
  );
231
242
  }
232
- function OnActivatePanel({ outcome }) {
243
+ function OnActivatePanel({
244
+ outcome,
245
+ mode
246
+ }) {
233
247
  const badge = outcome.status === "ran" ? { variant: "default", label: "onActivate ran" } : outcome.status === "skipped" ? {
234
248
  variant: "secondary",
235
249
  label: "onActivate skipped \u2014 not declared"
@@ -250,7 +264,7 @@ function OnActivatePanel({ outcome }) {
250
264
  ] }) : outcome.status === "threw" ? /* @__PURE__ */ jsxs(Fragment, { children: [
251
265
  /* @__PURE__ */ jsx("p", { className: "text-muted-foreground text-sm", children: "In production this is NON-FATAL: the throw is logged and shown to the user as a warning, and the activation stays connected \u2014 this hook is for cache seeding and eager validation, not a connect gate." }),
252
266
  /* @__PURE__ */ jsx("pre", { className: "bg-muted overflow-x-auto rounded-md p-3 text-xs", children: outcome.message })
253
- ] }) : /* @__PURE__ */ jsx("p", { className: "text-muted-foreground text-sm", children: "Ran against the same kind of capability context (storage, secrets, egress) your schedules and webhooks run against." })
267
+ ] }) : /* @__PURE__ */ jsx("p", { className: "text-muted-foreground text-sm", children: mode === "live" ? "Ran on the dev server against the live context \u2014 the same storage and secrets the OAuth loop and your schedules use, with ctx.fetch reaching your vendor under the declared egress." : "Ran against the same kind of capability context (storage, secrets, egress) your schedules and webhooks run against." })
254
268
  ]
255
269
  }
256
270
  );
@@ -308,7 +322,7 @@ function ConnectedState({
308
322
  {
309
323
  className: "text-muted-foreground text-sm",
310
324
  "data-test": "activation-mode-notice",
311
- children: mode === "live" ? hasLiveActivationData ? "The toolbar is on Live API \u2014 this activation data is available to live-mode widgets on this visit." : "The toolbar is on Live API, but this activation submitted no data for live-mode widgets to authenticate with." : "This surface is Fusion-mocked; widgets read fixtures \u2014 switch the toolbar to Live API to exercise real requests."
325
+ children: mode === "live" ? hasLiveActivationData ? "The toolbar is on Live API \u2014 this activation data is available to live-mode widgets on this visit." : "The toolbar is on Live API. This activation submitted no data of its own; an OAuth integration\u2019s credentials live on the dev server, where onTokens stored them." : "This surface is Fusion-mocked; widgets read fixtures \u2014 switch the toolbar to Live API to exercise real requests."
312
326
  }
313
327
  ),
314
328
  /* @__PURE__ */ jsx(
@@ -5,6 +5,7 @@ import { notFound } from "next/navigation";
5
5
  import { Alert, AlertDescription, AlertTitle } from "@ekanos/ui/alert";
6
6
  import {
7
7
  findEgressMismatch,
8
+ oauthStatusFixtures,
8
9
  resolveEffectiveDataMode,
9
10
  resolveEgress,
10
11
  seedsForMode
@@ -32,7 +33,10 @@ function IntegrationLayout({ children }) {
32
33
  );
33
34
  const httpFixtures = useMemo(() => {
34
35
  if (!integration) return [];
35
- const declared = integration.fixtures?.[state.variant] ?? [];
36
+ const declared = [
37
+ ...integration.fixtures?.[state.variant] ?? [],
38
+ ...oauthStatusFixtures(integration, state.variant)
39
+ ];
36
40
  const selfOrigin = globalThis.location?.origin;
37
41
  if (selfOrigin !== void 0) {
38
42
  return compileFixtures(declared, egress, selfOrigin);
@@ -51,6 +55,7 @@ function IntegrationLayout({ children }) {
51
55
  {
52
56
  seeds,
53
57
  mode,
58
+ variant: state.variant,
54
59
  ...integration.live && !egressMismatch ? { live: integration.live } : {},
55
60
  egress,
56
61
  httpFixtures,
@@ -1,18 +1,20 @@
1
1
  "use client";
2
2
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
3
- import { useState } from "react";
3
+ import { useMemo, useState } from "react";
4
4
  import { notFound } from "next/navigation";
5
5
  import { isEgressAllowed } from "@ekanos/sdk/context";
6
- import {
7
- invokeSchedule,
8
- invokeWebhook
9
- } from "@ekanos/sdk/testing";
10
6
  import { Alert, AlertDescription, AlertTitle } from "@ekanos/ui/alert";
11
7
  import { Badge } from "@ekanos/ui/badge";
12
8
  import { Button } from "@ekanos/ui/button";
13
9
  import { Textarea } from "@ekanos/ui/textarea";
10
+ import { LocalOAuthPanel } from "../components/local-oauth-panel.js";
14
11
  import { useDefinitionMockContext } from "../lib/definition-mock-context.js";
12
+ import { useHarnessDataMode } from "../lib/harness-hooks.js";
15
13
  import { useToolbar } from "../lib/toolbar-context.js";
14
+ import {
15
+ createLocalTriggerRunner,
16
+ createServerTriggerRunner
17
+ } from "../lib/trigger-runner.js";
16
18
  import { useHarnessIntegration } from "../registry-context.js";
17
19
  function OutcomePanel({ outcome }) {
18
20
  return /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3", "data-test": "trigger-outcome", children: [
@@ -34,13 +36,9 @@ function OutcomePanel({ outcome }) {
34
36
  ] }, scope)) })
35
37
  ] });
36
38
  }
37
- function describeError(error) {
38
- return error instanceof Error ? error.message : String(error);
39
- }
40
39
  function WebhookCard({
41
- definition,
42
40
  webhook,
43
- ctx
41
+ runner
44
42
  }) {
45
43
  const [state, setState] = useState(() => ({
46
44
  payload: JSON.stringify(webhook.examplePayload ?? {}, null, 2),
@@ -49,29 +47,17 @@ function WebhookCard({
49
47
  }));
50
48
  const deliver = async () => {
51
49
  setState((s) => ({ ...s, busy: true }));
52
- const logsBefore = ctx.logs.length;
53
50
  let outcome;
54
51
  try {
55
52
  const payload = JSON.parse(state.payload);
56
- const { result } = await invokeWebhook(definition, webhook.id, payload, {
57
- context: ctx,
58
- headers: webhook.signature === "none" ? {} : { [webhook.signature.header]: "(unverified \u2014 local transport)" }
59
- });
60
- outcome = {
61
- ok: true,
62
- summary: result.status,
63
- ...result.detail ? { detail: result.detail } : {},
64
- logs: ctx.logs.slice(logsBefore),
65
- storage: ctx.dumpStorage()
66
- };
53
+ outcome = await runner.webhook(webhook.id, payload);
67
54
  } catch (error) {
68
- console.error("[harness] webhook invocation failed:", error);
69
55
  outcome = {
70
56
  ok: false,
71
57
  summary: "failed",
72
- detail: describeError(error),
73
- logs: ctx.logs.slice(logsBefore),
74
- storage: ctx.dumpStorage()
58
+ detail: error instanceof Error ? error.message : String(error),
59
+ logs: [],
60
+ storage: { account: {}, user: {} }
75
61
  };
76
62
  }
77
63
  setState((s) => ({ ...s, outcome, busy: false }));
@@ -127,36 +113,13 @@ function WebhookCard({
127
113
  );
128
114
  }
129
115
  function ScheduleCard({
130
- definition,
131
116
  schedule,
132
- ctx
117
+ runner
133
118
  }) {
134
119
  const [state, setState] = useState({ outcome: null, busy: false });
135
120
  const runNow = async () => {
136
121
  setState((s) => ({ ...s, busy: true }));
137
- const logsBefore = ctx.logs.length;
138
- let outcome;
139
- try {
140
- const { result } = await invokeSchedule(definition, schedule.id, {
141
- context: ctx
142
- });
143
- outcome = {
144
- ok: true,
145
- summary: result.status,
146
- ...result.detail ? { detail: result.detail } : {},
147
- logs: ctx.logs.slice(logsBefore),
148
- storage: ctx.dumpStorage()
149
- };
150
- } catch (error) {
151
- console.error("[harness] schedule invocation failed:", error);
152
- outcome = {
153
- ok: false,
154
- summary: "failed",
155
- detail: describeError(error),
156
- logs: ctx.logs.slice(logsBefore),
157
- storage: ctx.dumpStorage()
158
- };
159
- }
122
+ const outcome = await runner.schedule(schedule.id);
160
123
  setState({ outcome, busy: false });
161
124
  };
162
125
  return /* @__PURE__ */ jsxs(
@@ -193,7 +156,12 @@ function ScheduleCard({
193
156
  }
194
157
  );
195
158
  }
196
- function OAuthCard({ definition }) {
159
+ function OAuthCard({
160
+ integration,
161
+ definition,
162
+ mode
163
+ }) {
164
+ const { state } = useToolbar();
197
165
  const oauth = definition.oauth;
198
166
  if (!oauth) return null;
199
167
  const egress = definition.egress ?? [];
@@ -205,103 +173,103 @@ function OAuthCard({ definition }) {
205
173
  ["Client id secret", oauth.credentials.clientIdSecretName],
206
174
  ["Client secret secret", oauth.credentials.clientSecretSecretName]
207
175
  ];
208
- return /* @__PURE__ */ jsxs(
209
- "div",
210
- {
211
- className: "bg-card flex flex-col gap-5 rounded-lg border p-6",
212
- "data-test": "oauth-declaration",
213
- children: [
214
- /* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-center gap-3", children: [
215
- /* @__PURE__ */ jsx("h3", { className: "font-heading text-lg tracking-tight", children: "OAuth declaration" }),
216
- /* @__PURE__ */ jsx(Badge, { variant: "outline", children: "oauth" })
217
- ] }),
218
- /* @__PURE__ */ jsxs("dl", { className: "grid grid-cols-1 gap-x-6 gap-y-2 text-sm sm:grid-cols-[auto_1fr]", children: [
219
- rows.map(([label, value]) => /* @__PURE__ */ jsxs("div", { className: "contents", children: [
220
- /* @__PURE__ */ jsx("dt", { className: "text-muted-foreground", children: label }),
221
- /* @__PURE__ */ jsx("dd", { children: /* @__PURE__ */ jsx("code", { className: "break-all", children: value }) })
222
- ] }, label)),
223
- /* @__PURE__ */ jsxs("div", { className: "contents", children: [
224
- /* @__PURE__ */ jsx("dt", { className: "text-muted-foreground", children: "Egress coverage" }),
225
- /* @__PURE__ */ jsx("dd", { className: "flex gap-2", children: [
226
- ...new Map(
227
- [oauth.provider.authorizationUrl, oauth.provider.tokenUrl].map(
228
- (url) => [new URL(url).origin, url]
176
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
177
+ /* @__PURE__ */ jsxs(
178
+ "div",
179
+ {
180
+ className: "bg-card flex flex-col gap-5 rounded-lg border p-6",
181
+ "data-test": "oauth-declaration",
182
+ children: [
183
+ /* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-center gap-3", children: [
184
+ /* @__PURE__ */ jsx("h3", { className: "font-heading text-lg tracking-tight", children: "OAuth declaration" }),
185
+ /* @__PURE__ */ jsx(Badge, { variant: "outline", children: "oauth" })
186
+ ] }),
187
+ /* @__PURE__ */ jsxs("dl", { className: "grid grid-cols-1 gap-x-6 gap-y-2 text-sm sm:grid-cols-[auto_1fr]", children: [
188
+ rows.map(([label, value]) => /* @__PURE__ */ jsxs("div", { className: "contents", children: [
189
+ /* @__PURE__ */ jsx("dt", { className: "text-muted-foreground", children: label }),
190
+ /* @__PURE__ */ jsx("dd", { children: /* @__PURE__ */ jsx("code", { className: "break-all", children: value }) })
191
+ ] }, label)),
192
+ /* @__PURE__ */ jsxs("div", { className: "contents", children: [
193
+ /* @__PURE__ */ jsx("dt", { className: "text-muted-foreground", children: "Egress coverage" }),
194
+ /* @__PURE__ */ jsx("dd", { className: "flex gap-2", children: [
195
+ ...new Map(
196
+ [
197
+ oauth.provider.authorizationUrl,
198
+ oauth.provider.tokenUrl
199
+ ].map((url) => [new URL(url).origin, url])
229
200
  )
230
- )
231
- ].map(([origin]) => {
232
- const covered = [
233
- oauth.provider.authorizationUrl,
234
- oauth.provider.tokenUrl
235
- ].filter((url) => new URL(url).origin === origin).every((url) => isEgressAllowed(url, egress));
236
- return /* @__PURE__ */ jsx(
237
- Badge,
238
- {
239
- variant: covered ? "secondary" : "destructive",
240
- children: origin
241
- },
242
- origin
243
- );
244
- }) })
245
- ] })
246
- ] }),
247
- /* @__PURE__ */ jsxs(Alert, { children: [
248
- /* @__PURE__ */ jsx(AlertTitle, { children: "Declaration only \u2014 the flow is the transport" }),
249
- /* @__PURE__ */ jsxs(AlertDescription, { children: [
250
- /* @__PURE__ */ jsxs("p", { children: [
251
- "The authorize \u2192 callback \u2192 code-exchange loop is owned by the transport, not by integration code: your package declares the endpoints and persists tokens in ",
252
- /* @__PURE__ */ jsx("code", { children: "onTokens" }),
253
- " via",
254
- " ",
255
- /* @__PURE__ */ jsx("code", { children: "ctx.secrets" }),
256
- ". This harness renders the declaration and checks its egress coverage; it does not run the flow."
257
- ] }),
258
- /* @__PURE__ */ jsxs("p", { children: [
259
- /* @__PURE__ */ jsx("strong", { children: "Redirect URI \u2014 host-derived, and not something you declare." }),
260
- " ",
261
- "The host owns the callback route and builds the URI from its own origin, so there is no field for it in",
262
- " ",
263
- /* @__PURE__ */ jsx("code", { children: "defineIntegration()" }),
264
- " and adding one would either be ignored or point the host's callback somewhere it should not go. Register this with your provider, against whichever host will run the flow:"
265
- ] }),
266
- /* @__PURE__ */ jsx("p", { children: /* @__PURE__ */ jsxs("code", { children: [
267
- "https://<your-fusion-host>/api/integrations/",
268
- definition.slug,
269
- "/oauth/callback"
270
- ] }) }),
271
- /* @__PURE__ */ jsxs("p", { children: [
272
- "The harness does not serve that route, so you cannot complete a round trip here. What you CAN check is above: that the endpoints you declared are inside your egress list. For a real round trip, run the hosted transport against a local Fusion host \u2014 register",
273
- " ",
274
- /* @__PURE__ */ jsxs("code", { children: [
275
- "http://localhost:3000/api/integrations/",
276
- definition.slug,
277
- "/oauth/callback"
201
+ ].map(([origin]) => {
202
+ const covered = [
203
+ oauth.provider.authorizationUrl,
204
+ oauth.provider.tokenUrl
205
+ ].filter((url) => new URL(url).origin === origin).every((url) => isEgressAllowed(url, egress));
206
+ return /* @__PURE__ */ jsx(
207
+ Badge,
208
+ {
209
+ variant: covered ? "secondary" : "destructive",
210
+ children: origin
211
+ },
212
+ origin
213
+ );
214
+ }) })
215
+ ] })
216
+ ] }),
217
+ /* @__PURE__ */ jsxs(Alert, { children: [
218
+ /* @__PURE__ */ jsx(AlertTitle, { children: "The flow is the transport's \u2014 and the harness has one" }),
219
+ /* @__PURE__ */ jsxs(AlertDescription, { children: [
220
+ /* @__PURE__ */ jsxs("p", { children: [
221
+ "The authorize \u2192 callback \u2192 code-exchange loop is owned by the transport, not by integration code: your package declares the endpoints and persists tokens in ",
222
+ /* @__PURE__ */ jsx("code", { children: "onTokens" }),
223
+ " via",
224
+ " ",
225
+ /* @__PURE__ */ jsx("code", { children: "ctx.secrets" }),
226
+ ". The hosted transport runs it in Fusion; in live mode the generated shell runs the same loop here, on localhost, against your own developer app \u2014 see Local OAuth below."
278
227
  ] }),
279
- " ",
280
- "with your provider and click Connect from the marketplace; the host exchanges the code through your declared egress and calls",
281
- " ",
282
- /* @__PURE__ */ jsx("code", { children: "onTokens" }),
283
- ". For unit coverage, call ",
284
- /* @__PURE__ */ jsx("code", { children: "onTokens" }),
285
- " ",
286
- "directly with ",
287
- /* @__PURE__ */ jsx("code", { children: "createMockContext()" }),
288
- " \u2014 it is an ordinary async function."
228
+ /* @__PURE__ */ jsxs("p", { children: [
229
+ /* @__PURE__ */ jsx("strong", { children: "Redirect URI \u2014 host-derived, and not something you declare." }),
230
+ " ",
231
+ "Whichever host runs the flow builds it from its own origin, so there is no field for it in ",
232
+ /* @__PURE__ */ jsx("code", { children: "defineIntegration()" }),
233
+ ". You register one per environment with your provider: the harness's (below, in live mode) and the Fusion host's,",
234
+ " ",
235
+ /* @__PURE__ */ jsxs("code", { children: [
236
+ "https://<your-fusion-host>/api/integrations/",
237
+ definition.slug,
238
+ "/oauth/callback"
239
+ ] }),
240
+ "."
241
+ ] })
289
242
  ] })
290
243
  ] })
291
- ] })
292
- ]
293
- }
294
- );
244
+ ]
245
+ }
246
+ ),
247
+ /* @__PURE__ */ jsx(
248
+ LocalOAuthPanel,
249
+ {
250
+ integration,
251
+ definition,
252
+ mode,
253
+ variant: state.variant
254
+ }
255
+ )
256
+ ] });
295
257
  }
296
258
  function TriggersPage() {
297
259
  const integration = useHarnessIntegration();
298
260
  const { state } = useToolbar();
261
+ const mode = useHarnessDataMode();
299
262
  const ctx = useDefinitionMockContext(
300
263
  integration ?? { slug: "", name: "", description: "", widgets: [] },
301
264
  state.variant
302
265
  );
266
+ const definition = integration?.definition;
267
+ const runner = useMemo(() => {
268
+ if (!integration || !definition) return null;
269
+ if (mode === "live") return createServerTriggerRunner(integration.slug);
270
+ return ctx ? createLocalTriggerRunner(definition, ctx) : null;
271
+ }, [integration, definition, mode, ctx]);
303
272
  if (!integration) notFound();
304
- const definition = integration.definition;
305
273
  const webhooks = definition?.webhooks ?? [];
306
274
  const schedules = definition?.schedules ?? [];
307
275
  const declaresAnything = webhooks.length > 0 || schedules.length > 0 || Boolean(definition?.oauth);
@@ -315,15 +283,16 @@ function TriggersPage() {
315
283
  /* @__PURE__ */ jsx(AlertTitle, { children: "The local transport for declared event surfaces" }),
316
284
  /* @__PURE__ */ jsxs(AlertDescription, { children: [
317
285
  /* @__PURE__ */ jsxs("p", { children: [
318
- "Webhooks and schedules below run their REAL handlers against one in-memory mock context (state accumulates until you leave the page). Payloads are validated against each webhook's",
319
- " ",
286
+ "Webhooks and schedules below run their REAL handlers against one context whose state accumulates like a real account's. Payloads are validated against each webhook's ",
320
287
  /* @__PURE__ */ jsx("code", { children: "payloadSchema" }),
321
288
  ", signature checks are logged as skipped, and egress is enforced from the definition \u2014 the same declarations the host's ingress, scheduler, and hosted OAuth callback bind to later."
322
289
  ] }),
290
+ /* @__PURE__ */ jsx("p", { "data-test": "triggers-mode-notice", children: mode === "live" ? "Live API: handlers run on the dev server, against the context the OAuth loop stored tokens in, with ctx.fetch reaching your vendor under the declared egress." : "Fixtures: handlers run in this browser against an in-memory context seeded from triggerMocks; ctx.fetch answers from your fixtures and never touches the network." }),
323
291
  /* @__PURE__ */ jsxs("p", { children: [
324
- "This is fixtures every time, whatever the toolbar says \u2014 nothing below reaches a real system until you publish to the dev host. A widget on this integration is different: it already reaches real vendors through ",
292
+ "Widgets on this integration reach real vendors through",
293
+ " ",
325
294
  /* @__PURE__ */ jsx("code", { children: "useIntegrationFetch()" }),
326
- " once you flip the toolbar to Live API."
295
+ " in Live API too \u2014 browser-side, with the egress check as a convenience rather than a guarantee. The host runs these same declarations, with real enforcement, after you publish."
327
296
  ] })
328
297
  ] })
329
298
  ] }),
@@ -340,25 +309,30 @@ function TriggersPage() {
340
309
  /* @__PURE__ */ jsx("code", { children: "@ekanos/sdk" }),
341
310
  " README has a worked example of each, under \u201CDeclarable surfaces\u201D."
342
311
  ] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
343
- ctx ? webhooks.map((webhook) => /* @__PURE__ */ jsx(
312
+ runner ? webhooks.map((webhook) => /* @__PURE__ */ jsx(
344
313
  WebhookCard,
345
314
  {
346
- definition,
347
315
  webhook,
348
- ctx
316
+ runner
349
317
  },
350
318
  webhook.id
351
319
  )) : null,
352
- ctx ? schedules.map((schedule) => /* @__PURE__ */ jsx(
320
+ runner ? schedules.map((schedule) => /* @__PURE__ */ jsx(
353
321
  ScheduleCard,
354
322
  {
355
- definition,
356
323
  schedule,
357
- ctx
324
+ runner
358
325
  },
359
326
  schedule.id
360
327
  )) : null,
361
- /* @__PURE__ */ jsx(OAuthCard, { definition })
328
+ /* @__PURE__ */ jsx(
329
+ OAuthCard,
330
+ {
331
+ integration,
332
+ definition,
333
+ mode
334
+ }
335
+ )
362
336
  ] })
363
337
  ]
364
338
  }
@@ -0,0 +1,57 @@
1
+ import type { IntegrationDefinition } from '@ekanos/sdk/integration';
2
+ import { type MockIntegrationContext } from '@ekanos/sdk/testing';
3
+ import { type FixtureVariant, type HarnessIntegration } from '../../registry.js';
4
+ /**
5
+ * ─────────────────────────────────────────────────────────────────────────────
6
+ * THE FIXTURES-MODE ACTIONS CONTEXT — one per (slug, variant), held server-side
7
+ * ─────────────────────────────────────────────────────────────────────────────
8
+ *
9
+ * `useIntegrationAction` always makes a real `fetch()` (the widget-actions
10
+ * design decision) — there is no browser-side execution path the way
11
+ * fixtures-mode triggers have (`createLocalTriggerRunner` +
12
+ * `useDefinitionMockContext`, both browser-only, built from a `useState`
13
+ * initializer that never runs on the server). So fixtures-mode ACTIONS need
14
+ * a server-side mock context of their own, built the identical way — same
15
+ * `createMockContext`, same fetchHandlers dispatch order (a partner's own
16
+ * `triggerMocks.fetchHandlers` first, then the fixture-compiled catch-all)
17
+ * — just reachable from `api-router.ts`'s action handler instead of from a
18
+ * React hook.
19
+ *
20
+ * Kept on `globalThis` under a `Symbol.for` key, exactly like
21
+ * `live-context.ts`'s `LiveState` store, so a dev-server recompile of the
22
+ * route module does not drop storage a previous action call wrote in the
23
+ * same variant. Keyed by `slug:variant` rather than just `slug` —
24
+ * switching the toolbar's fixture variant is already a deliberate "start
25
+ * over" (`IntegrationLayout` keys its whole provider subtree on it), so the
26
+ * actions context resets with it too, rather than leaking state seeded
27
+ * under one variant into another.
28
+ *
29
+ * NEVER carries a network-passthrough handler — that is the entire
30
+ * difference from `live-context.ts`'s `LiveState`. An action's `ctx.fetch`
31
+ * in fixtures mode can only ever resolve to a partner's own
32
+ * `triggerMocks.fetchHandlers` or a compiled `HttpFixture`; anything else is
33
+ * `NoRecordedResponseError`, never the real network — fixtures mode's whole
34
+ * promise, held for actions exactly as it already is for widgets and
35
+ * triggers.
36
+ */
37
+ export interface FixturesActionsState {
38
+ key: string;
39
+ ctx: MockIntegrationContext;
40
+ }
41
+ /** Test seam: forget every fixtures-mode actions context. */
42
+ export declare function resetFixturesActionsStore(): void;
43
+ export interface FixturesActionsStateInput {
44
+ integration: HarnessIntegration;
45
+ definition: IntegrationDefinition;
46
+ variant: FixtureVariant;
47
+ }
48
+ /**
49
+ * One context per `slug:variant`, built on first use and reused after —
50
+ * state (storage, secrets, logs) accumulates across action calls within the
51
+ * same variant, like a real account across a visit.
52
+ *
53
+ * Can throw `FixtureRequestError` (from `compileFixtures`) when a declared
54
+ * `HttpFixture`'s request line is malformed — the caller's job to turn that
55
+ * into a clear response, not this function's.
56
+ */
57
+ export declare function getFixturesActionsState(input: FixturesActionsStateInput): FixturesActionsState;