@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.
- package/README.md +243 -79
- package/dist/api.d.ts +42 -0
- package/dist/api.js +17 -0
- package/dist/internal/components/dev-toolbar.js +4 -2
- package/dist/internal/components/harness-providers.d.ts +8 -2
- package/dist/internal/components/harness-providers.js +4 -1
- package/dist/internal/components/local-oauth-panel.d.ts +29 -0
- package/dist/internal/components/local-oauth-panel.js +355 -0
- package/dist/internal/lib/actions-transport.d.ts +30 -0
- package/dist/internal/lib/actions-transport.js +6 -0
- package/dist/internal/lib/harness-fetch-interceptor.d.ts +53 -14
- package/dist/internal/lib/harness-fetch-interceptor.js +96 -0
- package/dist/internal/lib/oauth-setup-guide.d.ts +43 -0
- package/dist/internal/lib/oauth-setup-guide.js +28 -0
- package/dist/internal/lib/original-fetch.d.ts +36 -0
- package/dist/internal/lib/original-fetch.js +23 -0
- package/dist/internal/lib/run-activation-hook.d.ts +2 -8
- package/dist/internal/lib/toolbar-context.d.ts +7 -3
- package/dist/internal/lib/toolbar-context.js +10 -5
- package/dist/internal/lib/trigger-contract.d.ts +99 -0
- package/dist/internal/lib/trigger-contract.js +25 -0
- package/dist/internal/lib/trigger-runner.d.ts +55 -0
- package/dist/internal/lib/trigger-runner.js +153 -0
- package/dist/internal/routes/activation-page.js +42 -28
- package/dist/internal/routes/integration-layout.js +6 -1
- package/dist/internal/routes/triggers-page.js +121 -147
- package/dist/internal/server/actions-fixtures-context.d.ts +57 -0
- package/dist/internal/server/actions-fixtures-context.js +52 -0
- package/dist/internal/server/api-router.d.ts +54 -0
- package/dist/internal/server/api-router.js +575 -0
- package/dist/internal/server/live-context.d.ts +93 -0
- package/dist/internal/server/live-context.js +93 -0
- package/dist/internal/server/local-secrets.d.ts +84 -0
- package/dist/internal/server/local-secrets.js +144 -0
- package/dist/internal/server/loopback-guard.d.ts +33 -0
- package/dist/internal/server/loopback-guard.js +38 -0
- package/dist/internal/server/nonce-store.d.ts +38 -0
- package/dist/internal/server/nonce-store.js +40 -0
- package/dist/internal/server/oauth-loop.d.ts +114 -0
- package/dist/internal/server/oauth-loop.js +141 -0
- package/dist/internal/server/project-root.d.ts +29 -0
- package/dist/internal/server/project-root.js +31 -0
- package/dist/internal/server/storage-read.d.ts +34 -0
- package/dist/internal/server/storage-read.js +53 -0
- package/dist/registry.d.ts +73 -1
- package/dist/registry.js +21 -1
- package/package.json +13 -7
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { IntegrationDefinition } from '@ekanos/sdk/integration';
|
|
2
|
+
import { type DataMode, type FixtureVariant, type HarnessIntegration } from '../../registry.js';
|
|
3
|
+
/**
|
|
4
|
+
* ─────────────────────────────────────────────────────────────────────────────
|
|
5
|
+
* LOCAL OAUTH — register one URI, paste your keys, click Connect
|
|
6
|
+
* ─────────────────────────────────────────────────────────────────────────────
|
|
7
|
+
*
|
|
8
|
+
* The thing a partner most needs to know about the localhost OAuth loop is
|
|
9
|
+
* not how it works but what THEY have to do — and the answer should be "type
|
|
10
|
+
* it here", not "open this JSON file". So this panel is a form: one password
|
|
11
|
+
* field per secret name the definition declares, saved through the shell's
|
|
12
|
+
* own `PUT /api/integrations/<slug>/local-setup` route, which writes
|
|
13
|
+
* `.ekanos/local-secrets.json` server-side. Values leave the browser once,
|
|
14
|
+
* over loopback; the route answers filled/missing and never a value, so a
|
|
15
|
+
* saved key shows as `filled` beside an EMPTY field. Leave a field blank to
|
|
16
|
+
* keep what is saved.
|
|
17
|
+
*
|
|
18
|
+
* Mode-independent: configuring credentials is a harness matter, not a
|
|
19
|
+
* data-mode one, so the panel reads and saves in fixtures mode too (the
|
|
20
|
+
* interceptor passes exactly this route through). What the mode changes is
|
|
21
|
+
* what the STATUS means — real in live, `oauth.connected` in fixtures — and
|
|
22
|
+
* the panel says which.
|
|
23
|
+
*/
|
|
24
|
+
export declare function LocalOAuthPanel({ integration, definition, mode, variant, }: {
|
|
25
|
+
integration: HarnessIntegration;
|
|
26
|
+
definition: IntegrationDefinition;
|
|
27
|
+
mode: DataMode;
|
|
28
|
+
variant: FixtureVariant;
|
|
29
|
+
}): import("react").JSX.Element | null;
|
|
@@ -0,0 +1,355 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useState } from "react";
|
|
4
|
+
import { Alert, AlertDescription, AlertTitle } from "@ekanos/ui/alert";
|
|
5
|
+
import { Badge } from "@ekanos/ui/badge";
|
|
6
|
+
import { Button } from "@ekanos/ui/button";
|
|
7
|
+
import {
|
|
8
|
+
Form,
|
|
9
|
+
FormControl,
|
|
10
|
+
FormField,
|
|
11
|
+
FormItem,
|
|
12
|
+
FormLabel,
|
|
13
|
+
FormMessage
|
|
14
|
+
} from "@ekanos/ui/form";
|
|
15
|
+
import { Input } from "@ekanos/ui/input";
|
|
16
|
+
import { useQuery, useQueryClient } from "@tanstack/react-query";
|
|
17
|
+
import { useForm } from "react-hook-form";
|
|
18
|
+
import {
|
|
19
|
+
resolveOAuthConnected
|
|
20
|
+
} from "../../registry.js";
|
|
21
|
+
import {
|
|
22
|
+
buildOAuthSetupGuide
|
|
23
|
+
} from "../lib/oauth-setup-guide.js";
|
|
24
|
+
import { fetchLocalSetup, saveLocalSetup } from "../lib/trigger-runner.js";
|
|
25
|
+
function LocalOAuthPanel({
|
|
26
|
+
integration,
|
|
27
|
+
definition,
|
|
28
|
+
mode,
|
|
29
|
+
variant
|
|
30
|
+
}) {
|
|
31
|
+
const oauth = definition.oauth;
|
|
32
|
+
const live = mode === "live";
|
|
33
|
+
const queryClient = useQueryClient();
|
|
34
|
+
const queryKey = ["ekanos-harness", "local-setup", integration.slug];
|
|
35
|
+
const setup = useQuery({
|
|
36
|
+
queryKey,
|
|
37
|
+
queryFn: () => fetchLocalSetup(integration.slug),
|
|
38
|
+
enabled: oauth !== void 0,
|
|
39
|
+
staleTime: 0
|
|
40
|
+
});
|
|
41
|
+
if (!oauth) return null;
|
|
42
|
+
return /* @__PURE__ */ jsxs(
|
|
43
|
+
"div",
|
|
44
|
+
{
|
|
45
|
+
className: "bg-card flex flex-col gap-5 rounded-lg border p-6",
|
|
46
|
+
"data-test": "local-oauth",
|
|
47
|
+
children: [
|
|
48
|
+
/* @__PURE__ */ jsxs("div", { className: "flex flex-wrap items-center gap-3", children: [
|
|
49
|
+
/* @__PURE__ */ jsx("h3", { className: "font-heading text-lg tracking-tight", children: "Local OAuth" }),
|
|
50
|
+
/* @__PURE__ */ jsx(Badge, { variant: "outline", children: live ? "live" : "fixtures" }),
|
|
51
|
+
live && setup.data ? /* @__PURE__ */ jsx(Badge, { variant: setup.data.connected ? "default" : "secondary", children: setup.data.connected ? "connected" : "not connected" }) : null
|
|
52
|
+
] }),
|
|
53
|
+
setup.isPending ? /* @__PURE__ */ jsx("p", { className: "text-muted-foreground text-sm", children: "Reading local setup\u2026" }) : setup.isError ? /* @__PURE__ */ jsxs(Alert, { variant: "destructive", children: [
|
|
54
|
+
/* @__PURE__ */ jsx(AlertTitle, { children: "The harness API did not answer" }),
|
|
55
|
+
/* @__PURE__ */ jsxs(AlertDescription, { children: [
|
|
56
|
+
/* @__PURE__ */ jsx("p", { children: setup.error.message }),
|
|
57
|
+
/* @__PURE__ */ jsxs("p", { children: [
|
|
58
|
+
"The API routes live in the generated shell. If you upgraded",
|
|
59
|
+
" ",
|
|
60
|
+
/* @__PURE__ */ jsx("code", { children: "@ekanos/harness" }),
|
|
61
|
+
", re-run ",
|
|
62
|
+
/* @__PURE__ */ jsx("code", { children: "ekanos dev" }),
|
|
63
|
+
" so the shell is regenerated with them."
|
|
64
|
+
] })
|
|
65
|
+
] })
|
|
66
|
+
] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
67
|
+
/* @__PURE__ */ jsxs("ol", { className: "flex flex-col gap-5 text-sm", children: [
|
|
68
|
+
/* @__PURE__ */ jsxs("li", { className: "flex flex-col gap-2", children: [
|
|
69
|
+
/* @__PURE__ */ jsx("span", { className: "font-medium", children: "1. Set up the OAuth app at your provider \u2014 this part is yours" }),
|
|
70
|
+
setup.data.redirectUri ? /* @__PURE__ */ jsx(
|
|
71
|
+
SetupChecklist,
|
|
72
|
+
{
|
|
73
|
+
guide: buildOAuthSetupGuide({
|
|
74
|
+
definition,
|
|
75
|
+
entry: integration,
|
|
76
|
+
redirectUri: setup.data.redirectUri
|
|
77
|
+
})
|
|
78
|
+
}
|
|
79
|
+
) : null
|
|
80
|
+
] }),
|
|
81
|
+
/* @__PURE__ */ jsxs("li", { className: "flex flex-col gap-3", children: [
|
|
82
|
+
/* @__PURE__ */ jsx("span", { className: "font-medium", children: "2. Paste the credentials from that app" }),
|
|
83
|
+
/* @__PURE__ */ jsx(
|
|
84
|
+
CredentialsForm,
|
|
85
|
+
{
|
|
86
|
+
slug: integration.slug,
|
|
87
|
+
keys: setup.data.keys,
|
|
88
|
+
onSaved: (next) => queryClient.setQueryData(queryKey, next)
|
|
89
|
+
}
|
|
90
|
+
),
|
|
91
|
+
/* @__PURE__ */ jsxs("span", { className: "text-muted-foreground text-xs", children: [
|
|
92
|
+
"Saved to ",
|
|
93
|
+
/* @__PURE__ */ jsx("code", { children: setup.data.file }),
|
|
94
|
+
" in your project \u2014 gitignored, never packed, read on every request. A saved key shows as filled beside an empty field; leave a field blank to keep it. Saving forgets any current connection."
|
|
95
|
+
] })
|
|
96
|
+
] }),
|
|
97
|
+
/* @__PURE__ */ jsxs("li", { className: "flex flex-col gap-1", children: [
|
|
98
|
+
/* @__PURE__ */ jsx("span", { className: "font-medium", children: "3. Open the connect dialog (above) and click Connect" }),
|
|
99
|
+
/* @__PURE__ */ jsxs("span", { className: "text-muted-foreground text-xs", children: [
|
|
100
|
+
"The browser goes to the provider, comes back to the redirect URI above, the shell exchanges the code through your declared egress and calls ",
|
|
101
|
+
/* @__PURE__ */ jsx("code", { children: "onTokens" }),
|
|
102
|
+
" on a server-held context. Widgets then read what your handlers wrote through the normal storage route."
|
|
103
|
+
] })
|
|
104
|
+
] })
|
|
105
|
+
] }),
|
|
106
|
+
live ? /* @__PURE__ */ jsxs(
|
|
107
|
+
"p",
|
|
108
|
+
{
|
|
109
|
+
className: "text-muted-foreground text-xs",
|
|
110
|
+
"data-test": "local-oauth-connection",
|
|
111
|
+
children: [
|
|
112
|
+
setup.data.connection ? `Connected since ${setup.data.connection.obtainedAt}` + (setup.data.connection.expiresAt ? `; access token expires ${setup.data.connection.expiresAt}` : "") + ". " : "Not connected on this server. ",
|
|
113
|
+
"The connection lives in the dev server's memory only \u2014 a restart forgets it, and you Connect again."
|
|
114
|
+
]
|
|
115
|
+
}
|
|
116
|
+
) : /* @__PURE__ */ jsx(
|
|
117
|
+
FixturesModeNotice,
|
|
118
|
+
{
|
|
119
|
+
integration,
|
|
120
|
+
variant,
|
|
121
|
+
supportsLive: integration.live !== void 0
|
|
122
|
+
}
|
|
123
|
+
)
|
|
124
|
+
] })
|
|
125
|
+
]
|
|
126
|
+
}
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
function SetupChecklist({ guide }) {
|
|
130
|
+
if (!guide) return null;
|
|
131
|
+
return /* @__PURE__ */ jsxs(
|
|
132
|
+
"ul",
|
|
133
|
+
{
|
|
134
|
+
className: "text-muted-foreground flex flex-col gap-2 text-sm",
|
|
135
|
+
"data-test": "local-oauth-checklist",
|
|
136
|
+
children: [
|
|
137
|
+
/* @__PURE__ */ jsx("li", { children: guide.console ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
138
|
+
"Open",
|
|
139
|
+
" ",
|
|
140
|
+
/* @__PURE__ */ jsx(
|
|
141
|
+
"a",
|
|
142
|
+
{
|
|
143
|
+
href: guide.console.url,
|
|
144
|
+
target: "_blank",
|
|
145
|
+
rel: "noreferrer",
|
|
146
|
+
className: "text-foreground underline underline-offset-2",
|
|
147
|
+
"data-test": "local-oauth-console-link",
|
|
148
|
+
children: guide.console.label
|
|
149
|
+
}
|
|
150
|
+
),
|
|
151
|
+
" ",
|
|
152
|
+
"and create an OAuth app, or open the one you use for development."
|
|
153
|
+
] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
154
|
+
"In ",
|
|
155
|
+
/* @__PURE__ */ jsx("code", { children: guide.providerHost }),
|
|
156
|
+
"'s developer console, create an OAuth app, or open the one you use for development."
|
|
157
|
+
] }) }),
|
|
158
|
+
/* @__PURE__ */ jsxs("li", { className: "flex flex-col gap-1", children: [
|
|
159
|
+
/* @__PURE__ */ jsx("span", { children: "Add this redirect URI to the app, exactly:" }),
|
|
160
|
+
/* @__PURE__ */ jsx(
|
|
161
|
+
CopyableCode,
|
|
162
|
+
{
|
|
163
|
+
value: guide.redirectUri,
|
|
164
|
+
testId: "local-oauth-redirect-uri"
|
|
165
|
+
}
|
|
166
|
+
)
|
|
167
|
+
] }),
|
|
168
|
+
guide.scopes.length > 0 ? /* @__PURE__ */ jsxs("li", { children: [
|
|
169
|
+
"Enable these scopes:",
|
|
170
|
+
" ",
|
|
171
|
+
guide.scopes.map((scope) => /* @__PURE__ */ jsx("code", { className: "mr-1 text-xs", children: scope }, scope))
|
|
172
|
+
] }) : null,
|
|
173
|
+
/* @__PURE__ */ jsx("li", { children: guide.pkce ? "The app must allow the Authorization Code grant with PKCE (S256) \u2014 the loop sends a code challenge." : "The app must allow the Authorization Code grant." }),
|
|
174
|
+
/* @__PURE__ */ jsxs("li", { children: [
|
|
175
|
+
"Copy the app's client id into",
|
|
176
|
+
" ",
|
|
177
|
+
/* @__PURE__ */ jsx("code", { children: guide.credentials.clientId }),
|
|
178
|
+
" and its client secret into",
|
|
179
|
+
" ",
|
|
180
|
+
/* @__PURE__ */ jsx("code", { children: guide.credentials.clientSecret }),
|
|
181
|
+
" below."
|
|
182
|
+
] }),
|
|
183
|
+
guide.notes.map((note) => /* @__PURE__ */ jsx("li", { "data-test": "local-oauth-note", children: note }, note))
|
|
184
|
+
]
|
|
185
|
+
}
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
function CopyableCode({ value, testId }) {
|
|
189
|
+
const [copied, setCopied] = useState(false);
|
|
190
|
+
return /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
191
|
+
/* @__PURE__ */ jsx(
|
|
192
|
+
"code",
|
|
193
|
+
{
|
|
194
|
+
className: "bg-muted flex-1 rounded-md px-3 py-2 text-xs break-all",
|
|
195
|
+
"data-test": testId,
|
|
196
|
+
children: value
|
|
197
|
+
}
|
|
198
|
+
),
|
|
199
|
+
/* @__PURE__ */ jsx(
|
|
200
|
+
Button,
|
|
201
|
+
{
|
|
202
|
+
type: "button",
|
|
203
|
+
variant: "outline",
|
|
204
|
+
size: "sm",
|
|
205
|
+
onClick: async () => {
|
|
206
|
+
try {
|
|
207
|
+
await navigator.clipboard.writeText(value);
|
|
208
|
+
setCopied(true);
|
|
209
|
+
setTimeout(() => setCopied(false), 1500);
|
|
210
|
+
} catch (error) {
|
|
211
|
+
console.warn("[harness] could not copy to the clipboard:", error);
|
|
212
|
+
}
|
|
213
|
+
},
|
|
214
|
+
"data-test": `${testId}-copy`,
|
|
215
|
+
children: copied ? "Copied" : "Copy"
|
|
216
|
+
}
|
|
217
|
+
)
|
|
218
|
+
] });
|
|
219
|
+
}
|
|
220
|
+
function CredentialsForm({
|
|
221
|
+
slug,
|
|
222
|
+
keys,
|
|
223
|
+
onSaved
|
|
224
|
+
}) {
|
|
225
|
+
const blank = () => Object.fromEntries(keys.map((key) => [key.name, ""]));
|
|
226
|
+
const form = useForm({ defaultValues: blank() });
|
|
227
|
+
const [status, setStatus] = useState({ kind: "idle" });
|
|
228
|
+
const submit = form.handleSubmit(async (values) => {
|
|
229
|
+
const typed = Object.fromEntries(
|
|
230
|
+
Object.entries(values).filter(([, value]) => value.trim().length > 0)
|
|
231
|
+
);
|
|
232
|
+
if (Object.keys(typed).length === 0) {
|
|
233
|
+
setStatus({
|
|
234
|
+
kind: "error",
|
|
235
|
+
message: "Nothing to save \u2014 every field is blank."
|
|
236
|
+
});
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
try {
|
|
240
|
+
const next = await saveLocalSetup(slug, { values: typed });
|
|
241
|
+
onSaved(next);
|
|
242
|
+
form.reset(blank());
|
|
243
|
+
setStatus({ kind: "saved", count: Object.keys(typed).length });
|
|
244
|
+
} catch (error) {
|
|
245
|
+
setStatus({
|
|
246
|
+
kind: "error",
|
|
247
|
+
message: error instanceof Error ? error.message : String(error)
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
});
|
|
251
|
+
if (keys.length === 0) {
|
|
252
|
+
return /* @__PURE__ */ jsx("p", { className: "text-muted-foreground text-xs", children: "This definition declares no secret names, so there is nothing to save." });
|
|
253
|
+
}
|
|
254
|
+
return /* @__PURE__ */ jsx(Form, { ...form, children: /* @__PURE__ */ jsxs(
|
|
255
|
+
"form",
|
|
256
|
+
{
|
|
257
|
+
onSubmit: submit,
|
|
258
|
+
className: "flex flex-col gap-3",
|
|
259
|
+
"data-test": "local-oauth-form",
|
|
260
|
+
autoComplete: "off",
|
|
261
|
+
children: [
|
|
262
|
+
keys.map((key) => /* @__PURE__ */ jsx(
|
|
263
|
+
FormField,
|
|
264
|
+
{
|
|
265
|
+
control: form.control,
|
|
266
|
+
name: key.name,
|
|
267
|
+
render: ({ field }) => /* @__PURE__ */ jsxs(FormItem, { children: [
|
|
268
|
+
/* @__PURE__ */ jsxs(FormLabel, { className: "flex items-center gap-2", children: [
|
|
269
|
+
/* @__PURE__ */ jsx("code", { className: "text-xs", children: key.name }),
|
|
270
|
+
/* @__PURE__ */ jsx(Badge, { variant: key.filled ? "secondary" : "destructive", children: key.filled ? "filled" : "missing" })
|
|
271
|
+
] }),
|
|
272
|
+
/* @__PURE__ */ jsx(FormControl, { children: /* @__PURE__ */ jsx(
|
|
273
|
+
Input,
|
|
274
|
+
{
|
|
275
|
+
...field,
|
|
276
|
+
type: "password",
|
|
277
|
+
autoComplete: "off",
|
|
278
|
+
spellCheck: false,
|
|
279
|
+
placeholder: key.filled ? "saved \u2014 leave blank to keep" : "paste the value",
|
|
280
|
+
"data-test": `local-oauth-input-${key.name}`
|
|
281
|
+
}
|
|
282
|
+
) }),
|
|
283
|
+
/* @__PURE__ */ jsx(FormMessage, {})
|
|
284
|
+
] })
|
|
285
|
+
},
|
|
286
|
+
key.name
|
|
287
|
+
)),
|
|
288
|
+
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-3", children: [
|
|
289
|
+
/* @__PURE__ */ jsx(
|
|
290
|
+
Button,
|
|
291
|
+
{
|
|
292
|
+
type: "submit",
|
|
293
|
+
size: "sm",
|
|
294
|
+
disabled: form.formState.isSubmitting,
|
|
295
|
+
"data-test": "local-oauth-save",
|
|
296
|
+
children: form.formState.isSubmitting ? "Saving\u2026" : "Save credentials"
|
|
297
|
+
}
|
|
298
|
+
),
|
|
299
|
+
status.kind === "saved" ? /* @__PURE__ */ jsxs(
|
|
300
|
+
"span",
|
|
301
|
+
{
|
|
302
|
+
className: "text-muted-foreground text-xs",
|
|
303
|
+
"data-test": "local-oauth-saved",
|
|
304
|
+
children: [
|
|
305
|
+
"Saved ",
|
|
306
|
+
status.count,
|
|
307
|
+
" ",
|
|
308
|
+
status.count === 1 ? "value" : "values",
|
|
309
|
+
"."
|
|
310
|
+
]
|
|
311
|
+
}
|
|
312
|
+
) : status.kind === "error" ? /* @__PURE__ */ jsx(
|
|
313
|
+
"span",
|
|
314
|
+
{
|
|
315
|
+
className: "text-destructive text-xs",
|
|
316
|
+
"data-test": "local-oauth-error",
|
|
317
|
+
children: status.message
|
|
318
|
+
}
|
|
319
|
+
) : null
|
|
320
|
+
] })
|
|
321
|
+
]
|
|
322
|
+
}
|
|
323
|
+
) });
|
|
324
|
+
}
|
|
325
|
+
function FixturesModeNotice({
|
|
326
|
+
integration,
|
|
327
|
+
variant,
|
|
328
|
+
supportsLive
|
|
329
|
+
}) {
|
|
330
|
+
const connected = resolveOAuthConnected(integration, variant);
|
|
331
|
+
return /* @__PURE__ */ jsxs(
|
|
332
|
+
"p",
|
|
333
|
+
{
|
|
334
|
+
className: "text-muted-foreground text-xs",
|
|
335
|
+
"data-test": "local-oauth-fixtures",
|
|
336
|
+
children: [
|
|
337
|
+
"Fixtures mode: the status route is answered from",
|
|
338
|
+
" ",
|
|
339
|
+
/* @__PURE__ */ jsx("code", { children: "oauth.connected" }),
|
|
340
|
+
" in your harness entry \u2014 currently",
|
|
341
|
+
" ",
|
|
342
|
+
/* @__PURE__ */ jsx("strong", { children: connected ? "connected" : "not connected" }),
|
|
343
|
+
" for the",
|
|
344
|
+
" ",
|
|
345
|
+
/* @__PURE__ */ jsx("code", { children: variant }),
|
|
346
|
+
" variant \u2014 and Connect still runs the real loop above.",
|
|
347
|
+
" ",
|
|
348
|
+
supportsLive ? "Switch the toolbar\u2019s Data dropdown to Live API to have widgets and Triggers use the real connection." : "Add a `live` block to this entry in your harness config to enable the Live API switch."
|
|
349
|
+
]
|
|
350
|
+
}
|
|
351
|
+
);
|
|
352
|
+
}
|
|
353
|
+
export {
|
|
354
|
+
LocalOAuthPanel
|
|
355
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ─────────────────────────────────────────────────────────────────────────────
|
|
3
|
+
* THE ONE THING THE BROWSER TELLS THE SERVER ABOUT ITSELF, FOR ACTIONS ONLY
|
|
4
|
+
* ─────────────────────────────────────────────────────────────────────────────
|
|
5
|
+
*
|
|
6
|
+
* Every other harness surface (`storage`, `trigger`, `oauth/*`) decides
|
|
7
|
+
* fixtures vs. live BEFORE it ever reaches the network: fixtures-mode
|
|
8
|
+
* triggers run entirely in the browser (`createLocalTriggerRunner` +
|
|
9
|
+
* `useDefinitionMockContext`), and the server route only exists for the
|
|
10
|
+
* live half of that split, so it never needed to ask which mode is active —
|
|
11
|
+
* being reached at all meant live.
|
|
12
|
+
*
|
|
13
|
+
* `useIntegrationAction` breaks that pattern on purpose (the widget-actions
|
|
14
|
+
* design decision): it always makes a real `fetch()`, in both modes, because a
|
|
15
|
+
* production widget has no browser-side execution path to fall back to —
|
|
16
|
+
* there is no admin-secret-bearing context in a browser tab. So the
|
|
17
|
+
* harness's actions route is reached in BOTH modes, and unlike every route
|
|
18
|
+
* before it, has to be told which one is live right now.
|
|
19
|
+
*
|
|
20
|
+
* These two headers are that seam. They are written by
|
|
21
|
+
* `harness-fetch-interceptor.ts`, which already holds `active.mode` and
|
|
22
|
+
* `active.variant` at the exact moment it decides to let an actions request
|
|
23
|
+
* through, and read by `internal/server/api-router.ts`'s action handler.
|
|
24
|
+
* Neither is a production concept — they never leave this process, an
|
|
25
|
+
* absent or garbled value on the server side falls back to fixtures (never
|
|
26
|
+
* to live), and no real Fusion host route reads either header because a
|
|
27
|
+
* real host route has no "mode" to be told.
|
|
28
|
+
*/
|
|
29
|
+
export declare const HARNESS_ACTIONS_MODE_HEADER = "x-ekanos-harness-data-mode";
|
|
30
|
+
export declare const HARNESS_ACTIONS_VARIANT_HEADER = "x-ekanos-harness-fixture-variant";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { HttpFixture } from '../../registry.js';
|
|
1
|
+
import type { FixtureVariant, HttpFixture } from '../../registry.js';
|
|
2
2
|
import { type CompiledFixture, NoRecordedResponseError } from './http-fixtures.js';
|
|
3
3
|
/**
|
|
4
4
|
* ─────────────────────────────────────────────────────────────────────────────
|
|
@@ -33,7 +33,7 @@ import { type CompiledFixture, NoRecordedResponseError } from './http-fixtures.j
|
|
|
33
33
|
* framework's own plumbing, none of it the integration talking to an API.
|
|
34
34
|
* Intercepting it would break the app to no purpose.
|
|
35
35
|
*
|
|
36
|
-
* ── `/api/`
|
|
36
|
+
* ── `/api/` — fixtures in fixtures mode, the shell's own routes in live ──────
|
|
37
37
|
*
|
|
38
38
|
* `/api/` is the one same-origin exception, because it is the integration's
|
|
39
39
|
* own namespace. A first-party integration's widgets call
|
|
@@ -41,18 +41,32 @@ import { type CompiledFixture, NoRecordedResponseError } from './http-fixtures.j
|
|
|
41
41
|
* call happens server-side, where the credential lives — and our own Acme
|
|
42
42
|
* example is shaped exactly that way.
|
|
43
43
|
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
* the
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
*
|
|
44
|
+
* In FIXTURES mode this is answered from the registry's `fixtures`, and a miss
|
|
45
|
+
* is `NoRecordedResponseError` — a refusal that names the URL and says to add
|
|
46
|
+
* one.
|
|
47
|
+
*
|
|
48
|
+
* In LIVE mode, requests under `/api/integrations/<active slug>/` PASS THROUGH
|
|
49
|
+
* to the shell's own API routes (`@ekanos/harness/api`, scaffolded by
|
|
50
|
+
* `ekanos dev`). Those routes serve, over one server-held context per
|
|
51
|
+
* integration: the real OAuth loop (`oauth/connect|callback|status`), the
|
|
52
|
+
* storage bridge partner widgets read (`storage`), and the trigger route the
|
|
53
|
+
* Triggers/Activation surfaces post to. That is what "live" means for this
|
|
54
|
+
* traffic — the data `onTokens` and the partner's schedules actually wrote.
|
|
55
|
+
* Every OTHER `/api/` path stays on fixtures in live mode too: the harness
|
|
56
|
+
* serves nothing else, so passing it through would only trade a named
|
|
57
|
+
* refusal for a 404.
|
|
58
|
+
*
|
|
59
|
+
* Third-party traffic — a different origin — is unchanged: in live mode it
|
|
60
|
+
* reaches the real vendor under the egress allowlist below; in fixtures mode
|
|
61
|
+
* it is answered from fixtures or refused by name.
|
|
62
|
+
*
|
|
63
|
+
* ── The server sees this patch too ───────────────────────────────────────────
|
|
64
|
+
*
|
|
65
|
+
* `harness-providers.tsx` installs this at import, and Next evaluates that
|
|
66
|
+
* module during the SERVER render as well — in the same process the API route
|
|
67
|
+
* handlers run in. The wrapper is therefore tagged with the fetch it wraps
|
|
68
|
+
* (`original-fetch.ts`), and server code that must reach the network unwraps
|
|
69
|
+
* it at call time rather than trusting `globalThis.fetch`.
|
|
56
70
|
*
|
|
57
71
|
* Scoped to `/api/` rather than "everything except `/_next/`" deliberately: a
|
|
58
72
|
* rule that has to enumerate the framework's internals is a rule that breaks
|
|
@@ -68,6 +82,19 @@ import { type CompiledFixture, NoRecordedResponseError } from './http-fixtures.j
|
|
|
68
82
|
/** How the interceptor should answer third-party requests right now. */
|
|
69
83
|
export interface HarnessRoutingTable {
|
|
70
84
|
mode: 'fixtures' | 'live';
|
|
85
|
+
/**
|
|
86
|
+
* The integration currently rendering. In live mode, same-origin requests
|
|
87
|
+
* under `/api/integrations/<slug>/` pass through to the shell's API routes;
|
|
88
|
+
* absent (the fail-closed default), nothing passes.
|
|
89
|
+
*/
|
|
90
|
+
slug?: string;
|
|
91
|
+
/**
|
|
92
|
+
* The active fixture variant. Forwarded to the server on an `actions/`
|
|
93
|
+
* call (see below) so the harness's fixtures-mode actions context reads
|
|
94
|
+
* the same `HttpFixture[]` the rest of the surface is rendering from.
|
|
95
|
+
* Meaningless outside that one path. Defaults to `'default'` when absent.
|
|
96
|
+
*/
|
|
97
|
+
variant?: FixtureVariant;
|
|
71
98
|
/** Compiled fixtures for the active variant. */
|
|
72
99
|
fixtures: readonly CompiledFixture[];
|
|
73
100
|
/** Origins live mode may reach. Empty in fixtures mode. */
|
|
@@ -78,6 +105,18 @@ export interface HarnessRoutingTable {
|
|
|
78
105
|
method: string;
|
|
79
106
|
outcome: 'fixture' | 'network' | 'refused';
|
|
80
107
|
}) => void;
|
|
108
|
+
/**
|
|
109
|
+
* Test seam for the live-actions confirmation prompt (see
|
|
110
|
+
* `confirmLiveAction` below). Defaults to `globalThis.confirm`.
|
|
111
|
+
*/
|
|
112
|
+
confirm?: (message: string) => boolean;
|
|
113
|
+
}
|
|
114
|
+
/** Test seam: forget every live-actions confirmation, as a fresh session would. */
|
|
115
|
+
export declare function resetLiveActionConfirmations(): void;
|
|
116
|
+
export declare class LiveActionNotConfirmedError extends Error {
|
|
117
|
+
readonly slug: string;
|
|
118
|
+
readonly actionName: string;
|
|
119
|
+
constructor(slug: string, actionName: string);
|
|
81
120
|
}
|
|
82
121
|
/**
|
|
83
122
|
* Publish the table the interceptor answers from.
|
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { EgressDeniedError, isEgressAllowed } from "@ekanos/sdk/context";
|
|
3
|
+
import {
|
|
4
|
+
HARNESS_ACTIONS_MODE_HEADER,
|
|
5
|
+
HARNESS_ACTIONS_VARIANT_HEADER
|
|
6
|
+
} from "./actions-transport.js";
|
|
3
7
|
import {
|
|
4
8
|
NoRecordedResponseError,
|
|
5
9
|
fixtureResponse,
|
|
6
10
|
matchHttpFixture
|
|
7
11
|
} from "./http-fixtures.js";
|
|
12
|
+
import { tagInterceptor } from "./original-fetch.js";
|
|
8
13
|
const CLOSED = {
|
|
9
14
|
mode: "fixtures",
|
|
10
15
|
fixtures: [],
|
|
@@ -12,6 +17,62 @@ const CLOSED = {
|
|
|
12
17
|
};
|
|
13
18
|
let active = CLOSED;
|
|
14
19
|
let installed = false;
|
|
20
|
+
const CONFIRMED_KEY_PREFIX = "ekanos-harness-live-action-confirmed:";
|
|
21
|
+
const confirmedInMemory = /* @__PURE__ */ new Set();
|
|
22
|
+
function readSessionStorage() {
|
|
23
|
+
try {
|
|
24
|
+
return globalThis.sessionStorage;
|
|
25
|
+
} catch {
|
|
26
|
+
return void 0;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
function isLiveActionConfirmed(slug) {
|
|
30
|
+
if (confirmedInMemory.has(slug)) return true;
|
|
31
|
+
try {
|
|
32
|
+
return readSessionStorage()?.getItem(CONFIRMED_KEY_PREFIX + slug) === "1";
|
|
33
|
+
} catch {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
function markLiveActionConfirmed(slug) {
|
|
38
|
+
confirmedInMemory.add(slug);
|
|
39
|
+
try {
|
|
40
|
+
readSessionStorage()?.setItem(CONFIRMED_KEY_PREFIX + slug, "1");
|
|
41
|
+
} catch {
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
function resetLiveActionConfirmations() {
|
|
45
|
+
confirmedInMemory.clear();
|
|
46
|
+
const storage = readSessionStorage();
|
|
47
|
+
if (!storage) return;
|
|
48
|
+
try {
|
|
49
|
+
for (let index = storage.length - 1; index >= 0; index--) {
|
|
50
|
+
const key = storage.key(index);
|
|
51
|
+
if (key?.startsWith(CONFIRMED_KEY_PREFIX)) storage.removeItem(key);
|
|
52
|
+
}
|
|
53
|
+
} catch {
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
class LiveActionNotConfirmedError extends Error {
|
|
57
|
+
constructor(slug, actionName) {
|
|
58
|
+
super(
|
|
59
|
+
`Live action "${actionName}" on "${slug}" was not confirmed, so the request was never sent. Run it again and accept the "this runs against real data" prompt \u2014 declining or dismissing it answers no.`
|
|
60
|
+
);
|
|
61
|
+
this.slug = slug;
|
|
62
|
+
this.actionName = actionName;
|
|
63
|
+
this.name = "LiveActionNotConfirmedError";
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
function confirmLiveAction(slug, actionName, ask) {
|
|
67
|
+
if (isLiveActionConfirmed(slug)) return true;
|
|
68
|
+
const accepted = ask(
|
|
69
|
+
`"${slug}" wants to run "${actionName}" against REAL, live ${slug} data \u2014 this is not a fixture.
|
|
70
|
+
|
|
71
|
+
Choose OK to allow this action, and every other action on this integration, for the rest of this browser session.`
|
|
72
|
+
);
|
|
73
|
+
if (accepted) markLiveActionConfirmed(slug);
|
|
74
|
+
return accepted;
|
|
75
|
+
}
|
|
15
76
|
let originalFetch;
|
|
16
77
|
let patchedFetch;
|
|
17
78
|
function redact(url) {
|
|
@@ -55,6 +116,37 @@ function installHarnessFetch() {
|
|
|
55
116
|
return original(input, init);
|
|
56
117
|
}
|
|
57
118
|
if (isSameOrigin) {
|
|
119
|
+
if (active.slug !== void 0) {
|
|
120
|
+
const slug = active.slug;
|
|
121
|
+
const own = `/api/integrations/${slug}/`;
|
|
122
|
+
const isLocalSetup = url.pathname === `${own}local-setup`;
|
|
123
|
+
const actionsPrefix = `${own}actions/`;
|
|
124
|
+
const isActionsCall = url.pathname.startsWith(actionsPrefix);
|
|
125
|
+
if (isActionsCall) {
|
|
126
|
+
const actionName = url.pathname.slice(actionsPrefix.length);
|
|
127
|
+
if (active.mode === "live") {
|
|
128
|
+
const ask = active.confirm ?? ((message) => globalThis.confirm(message));
|
|
129
|
+
if (!confirmLiveAction(slug, actionName, ask)) {
|
|
130
|
+
notify(url, method, "refused");
|
|
131
|
+
throw new LiveActionNotConfirmedError(slug, actionName);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
notify(url, method, "network");
|
|
135
|
+
const headers = new Headers(
|
|
136
|
+
init?.headers ?? (input instanceof Request ? input.headers : void 0)
|
|
137
|
+
);
|
|
138
|
+
headers.set(HARNESS_ACTIONS_MODE_HEADER, active.mode);
|
|
139
|
+
headers.set(
|
|
140
|
+
HARNESS_ACTIONS_VARIANT_HEADER,
|
|
141
|
+
active.variant ?? "default"
|
|
142
|
+
);
|
|
143
|
+
return original(input, { ...init, headers });
|
|
144
|
+
}
|
|
145
|
+
if (isLocalSetup || active.mode === "live" && url.pathname.startsWith(own)) {
|
|
146
|
+
notify(url, method, "network");
|
|
147
|
+
return original(input, init);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
58
150
|
const fixture2 = matchHttpFixture(method, url.toString(), active.fixtures);
|
|
59
151
|
if (!fixture2) {
|
|
60
152
|
notify(url, method, "refused");
|
|
@@ -91,6 +183,7 @@ function installHarnessFetch() {
|
|
|
91
183
|
notify(url, method, "fixture");
|
|
92
184
|
return fixtureResponse(fixture);
|
|
93
185
|
};
|
|
186
|
+
tagInterceptor(intercept, original);
|
|
94
187
|
globalThis.fetch = intercept;
|
|
95
188
|
patchedFetch = intercept;
|
|
96
189
|
return original;
|
|
@@ -101,11 +194,14 @@ function uninstallHarnessFetch(original) {
|
|
|
101
194
|
originalFetch = void 0;
|
|
102
195
|
patchedFetch = void 0;
|
|
103
196
|
closeHarnessRouting();
|
|
197
|
+
resetLiveActionConfirmations();
|
|
104
198
|
}
|
|
105
199
|
export {
|
|
200
|
+
LiveActionNotConfirmedError,
|
|
106
201
|
NoRecordedResponseError,
|
|
107
202
|
closeHarnessRouting,
|
|
108
203
|
installHarnessFetch,
|
|
109
204
|
publishHarnessRouting,
|
|
205
|
+
resetLiveActionConfirmations,
|
|
110
206
|
uninstallHarnessFetch
|
|
111
207
|
};
|