@hansenexus/hud 0.4.0 → 0.5.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 +603 -9
- package/dist/a11y-B5DUaiCs.js +246 -0
- package/dist/a11y-panel-p_t4eD7p.js +207 -0
- package/dist/{capabilities-CjulXFQX.js → access-C7zlaqj6.js} +1 -90
- package/dist/{access-CNvJOwKM.d.ts → access-D_ewAEJG.d.ts} +11 -4
- package/dist/access-panel-CEfTr9ZI.js +123 -0
- package/dist/adapter-BYoxPYTI.d.ts +33 -0
- package/dist/adapter-hcwmJtNx.js +65 -0
- package/dist/auto/runtime.d.ts +65 -0
- package/dist/auto/runtime.js +50 -0
- package/dist/auto.d.ts +15 -0
- package/dist/auto.js +33 -0
- package/dist/capabilities-rDSKjXpq.js +110 -0
- package/dist/capture-CwrIwLqi.js +300 -0
- package/dist/capture-buffer-Bbbo6omF.d.ts +35 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +275 -0
- package/dist/data-panel-DhxAmP91.js +817 -0
- package/dist/data-store-ChF1td_P.js +164 -0
- package/dist/define-hud-CHPedaQ5.d.ts +50 -0
- package/dist/design-D0kGgPoP.js +87 -0
- package/dist/detect-BxHZ0pxW.d.ts +25 -0
- package/dist/detect-CHZiSeZs.js +63 -0
- package/dist/dispatch-panel-B-xr_Giy.js +279 -0
- package/dist/{env-vEjyJfPW.d.ts → env-CApnbI0r.d.ts} +2 -0
- package/dist/{env-DfxpPfs9.js → env-CaiFPIhF.js} +3 -0
- package/dist/file-xdSaQ2uR.js +103 -0
- package/dist/flags-DVtaJ8pQ.d.ts +58 -0
- package/dist/flags.d.ts +2 -0
- package/dist/flags.js +82 -0
- package/dist/force-state-panel-_otVYh9i.js +97 -0
- package/dist/generate-C8lQl3Eh.js +53 -0
- package/dist/handler-BpVhxEmU.js +106 -0
- package/dist/{handler-WmE4Lu7l.d.ts → handler-DtYVCZY6.d.ts} +1 -1
- package/dist/index-BAV_1W8a.d.ts +43 -0
- package/dist/index-BJ26pse9.d.ts +70 -0
- package/dist/index-BnQ0dTZf.d.ts +19 -0
- package/dist/index-CwfX-W87.d.ts +72 -0
- package/dist/index-DcH9V3cU.d.ts +48 -0
- package/dist/index-DqOyNf1u.d.ts +65 -0
- package/dist/index-DstI_ike.d.ts +66 -0
- package/dist/index-Dxz4fn4j.d.ts +42 -0
- package/dist/index-Hhh7OXzU.d.ts +129 -0
- package/dist/index-ReFbhQ9p.d.ts +25 -0
- package/dist/index-RgXfMBuW.d.ts +48 -0
- package/dist/{index-BYsdS-7d.d.ts → index-gCZBO53s.d.ts} +21 -3
- package/dist/index.d.ts +5 -5
- package/dist/index.js +710 -69
- package/dist/inspect-C9Ft8fqn.js +142 -0
- package/dist/inspect-root-BkaupBMp.js +429 -0
- package/dist/meta-Bv0sEao3.js +6 -0
- package/dist/meta-C_G7MB5w.d.ts +49 -0
- package/dist/mocks-CA-wM2SB.d.ts +109 -0
- package/dist/mocks-ESiRqk9o.js +150 -0
- package/dist/msw-browser-wjaYgkB7.d.ts +31 -0
- package/dist/next/config.d.ts +52 -0
- package/dist/next/config.js +78 -0
- package/dist/next.d.ts +14 -4
- package/dist/next.js +5 -3
- package/dist/observe-CdDnDBRP.js +89 -0
- package/dist/observe-panel-Cgp1M8oT.js +347 -0
- package/dist/ops-panel-CEqDe_UT.js +234 -0
- package/dist/{payload-CLKDVZWl.d.ts → payload-MUQ9ciER.d.ts} +25 -1
- package/dist/plugins/a11y.d.ts +2 -0
- package/dist/plugins/a11y.js +2 -0
- package/dist/plugins/access/server.d.ts +5 -5
- package/dist/plugins/access/server.js +4 -3
- package/dist/plugins/access.d.ts +5 -5
- package/dist/plugins/access.js +16 -215
- package/dist/plugins/agent/server.d.ts +3 -38
- package/dist/plugins/agent/server.js +47 -21
- package/dist/plugins/agent.d.ts +4 -4
- package/dist/plugins/agent.js +6 -348
- package/dist/plugins/capture/server.d.ts +92 -0
- package/dist/plugins/capture/server.js +248 -0
- package/dist/plugins/capture.d.ts +24 -0
- package/dist/plugins/capture.js +70 -0
- package/dist/plugins/data/msw-browser.d.ts +2 -0
- package/dist/plugins/data/msw-browser.js +39 -0
- package/dist/plugins/data/msw-node.d.ts +36 -0
- package/dist/plugins/data/msw-node.js +68 -0
- package/dist/plugins/data/server.d.ts +257 -0
- package/dist/plugins/data/server.js +717 -0
- package/dist/plugins/data.d.ts +6 -0
- package/dist/plugins/data.js +51 -0
- package/dist/plugins/design/server.d.ts +54 -0
- package/dist/plugins/design/server.js +198 -0
- package/dist/plugins/design.d.ts +4 -124
- package/dist/plugins/design.js +4 -619
- package/dist/plugins/inspect/convex.d.ts +2 -0
- package/dist/plugins/inspect/convex.js +486 -0
- package/dist/plugins/inspect/react-query.d.ts +2 -0
- package/dist/plugins/inspect/react-query.js +225 -0
- package/dist/plugins/inspect/sockets.d.ts +51 -0
- package/dist/plugins/inspect/sockets.js +397 -0
- package/dist/plugins/inspect/swr.d.ts +2 -0
- package/dist/plugins/inspect/swr.js +218 -0
- package/dist/plugins/inspect.d.ts +4 -0
- package/dist/plugins/inspect.js +3 -0
- package/dist/plugins/observe.d.ts +4 -64
- package/dist/plugins/observe.js +1 -616
- package/dist/plugins/ops/server.d.ts +1 -1
- package/dist/plugins/ops/server.js +2 -1
- package/dist/plugins/ops.d.ts +2 -1
- package/dist/plugins/ops.js +15 -336
- package/dist/plugins/routes/server.d.ts +88 -0
- package/dist/plugins/routes/server.js +62 -0
- package/dist/plugins/routes.d.ts +3 -0
- package/dist/plugins/routes.js +216 -0
- package/dist/plugins/seo.d.ts +2 -0
- package/dist/plugins/seo.js +2 -0
- package/dist/plugins/vitals.d.ts +2 -25
- package/dist/plugins/vitals.js +3 -2
- package/dist/{plugins-CQ_0w1ot.d.ts → plugins-BZvDqGx5.d.ts} +33 -3
- package/dist/poll-CjKsWZi8.js +89 -0
- package/dist/requests-BwD6MKEq.js +282 -0
- package/dist/requests-CJrUf465.d.ts +50 -0
- package/dist/review.js +2 -2
- package/dist/same-origin-BGet22CC.js +21 -0
- package/dist/scan-DzJNXqOk.js +165 -0
- package/dist/seo-Dq9q_QkO.js +551 -0
- package/dist/seo-panel-CfiY-TnT.js +124 -0
- package/dist/server.d.ts +2 -2
- package/dist/server.js +2 -105
- package/dist/sessions-panel-COvhPAzv.js +98 -0
- package/dist/{shortcut-U6ftVY06.js → shortcut-s_mjGeU8.js} +1 -44
- package/dist/{types-QJUajwWq.js → state-CjjZPjPJ.js} +13 -8
- package/dist/store/convex.d.ts +33 -0
- package/dist/store/convex.js +52 -0
- package/dist/{vitals-panel-Dvc5dnR-.js → store-CQqIIKTc.js} +1 -29
- package/dist/store-Ync9eb1G.js +67 -0
- package/dist/store.d.ts +76 -0
- package/dist/store.js +188 -0
- package/dist/{styles--slk86ZQ.js → styles-BA8ueHoV.js} +13 -3
- package/dist/styles-DKU_P8MH.js +139 -0
- package/dist/styles-DPpDPmzi.js +68 -0
- package/dist/tokens-panel-CbMQfasZ.js +142 -0
- package/dist/types-B-ulf2Jp.js +8 -0
- package/dist/types-BIgGf-0C.d.ts +25 -0
- package/dist/types-BIkI-qN8.js +30 -0
- package/dist/{types-DADBRiGk.d.ts → types-Cxh4twqc.d.ts} +1 -1
- package/dist/types-DIdPfjtV.js +6 -0
- package/dist/types-DaJcsEjO.d.ts +44 -0
- package/dist/types-Dn68psVz.d.ts +118 -0
- package/dist/types-szkr2QOF.d.ts +39 -0
- package/dist/unlock-store-4V3vR4Eg.js +96 -0
- package/dist/variant-groups-TIfO3NIj.js +137 -0
- package/dist/variant-groups-aAIrcNK5.d.ts +36 -0
- package/dist/variants-panel-BDoSkwBJ.js +457 -0
- package/dist/variants-types-CcRf119M.d.ts +63 -0
- package/dist/variants.d.ts +43 -0
- package/dist/variants.js +83 -0
- package/dist/vitals-panel-BCmMUntW.js +30 -0
- package/dist/vite.d.ts +37 -0
- package/dist/vite.js +134 -0
- package/package.json +65 -5
- package/dist/define-hud-BBzsSl8b.d.ts +0 -36
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { r as GrabPayload } from "../payload-MUQ9ciER.js";
|
|
2
|
+
import { s as HudPluginContext } from "../plugins-BZvDqGx5.js";
|
|
3
|
+
import "../index-gCZBO53s.js";
|
|
4
|
+
import { n as ScreenshotRequest, r as ScreenshotResponse, t as CAPTURE_CAPABILITY } from "../types-BIgGf-0C.js";
|
|
5
|
+
//#region src/plugins/capture/index.d.ts
|
|
6
|
+
export interface ScreenshotOptions {
|
|
7
|
+
/** Give up on a screenshot after this long. Default 30 s. */
|
|
8
|
+
timeoutMs?: number;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Client half of the `capture` plugin. No panel: on every grab it asks the
|
|
12
|
+
* server half to render the page headless and crop to the grabbed element,
|
|
13
|
+
* then attaches the PNG to the grab (`payload.screenshot`), where the Dispatch
|
|
14
|
+
* panel shows it and sends it along. Without Playwright on the server the
|
|
15
|
+
* grab carries the reason and a setup hint instead.
|
|
16
|
+
*/
|
|
17
|
+
export declare function screenshot({ timeoutMs }?: ScreenshotOptions): {
|
|
18
|
+
readonly id: "capture";
|
|
19
|
+
readonly title: "Screenshot";
|
|
20
|
+
readonly capability: "capture.screenshot";
|
|
21
|
+
readonly onGrab: (payload: GrabPayload, ctx: HudPluginContext) => void;
|
|
22
|
+
};
|
|
23
|
+
//#endregion
|
|
24
|
+
export { CAPTURE_CAPABILITY, type ScreenshotRequest, type ScreenshotResponse };
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { i as definePlugin, n as HudApiError } from "../plugins-DVy_vaYr.js";
|
|
2
|
+
import { n as CAPTURE_ID, t as CAPTURE_CAPABILITY } from "../types-DIdPfjtV.js";
|
|
3
|
+
//#region src/plugins/capture/index.tsx
|
|
4
|
+
function failure(error) {
|
|
5
|
+
if (error instanceof HudApiError) {
|
|
6
|
+
const body = error.body;
|
|
7
|
+
if (body && typeof body.error === "string") return body.hint ? {
|
|
8
|
+
reason: body.error,
|
|
9
|
+
hint: body.hint
|
|
10
|
+
} : { reason: body.error };
|
|
11
|
+
if (error.status === 404) return {
|
|
12
|
+
reason: "no screenshot route",
|
|
13
|
+
hint: "Mount screenshot() from @hansenexus/hud/plugins/capture/server in the HUD route."
|
|
14
|
+
};
|
|
15
|
+
return { reason: `screenshot route answered ${error.status}` };
|
|
16
|
+
}
|
|
17
|
+
return { reason: error instanceof Error ? error.message : String(error) };
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Client half of the `capture` plugin. No panel: on every grab it asks the
|
|
21
|
+
* server half to render the page headless and crop to the grabbed element,
|
|
22
|
+
* then attaches the PNG to the grab (`payload.screenshot`), where the Dispatch
|
|
23
|
+
* panel shows it and sends it along. Without Playwright on the server the
|
|
24
|
+
* grab carries the reason and a setup hint instead.
|
|
25
|
+
*/
|
|
26
|
+
function screenshot({ timeoutMs = 3e4 } = {}) {
|
|
27
|
+
return definePlugin({
|
|
28
|
+
id: CAPTURE_ID,
|
|
29
|
+
title: "Screenshot",
|
|
30
|
+
capability: CAPTURE_CAPABILITY,
|
|
31
|
+
onGrab: (payload, ctx) => {
|
|
32
|
+
const current = () => ctx.grab.getState().payload;
|
|
33
|
+
const mine = () => current()?.grabbedAt === payload.grabbedAt;
|
|
34
|
+
ctx.grab.amend({ screenshot: { status: "pending" } });
|
|
35
|
+
ctx.api("/screenshot", {
|
|
36
|
+
method: "POST",
|
|
37
|
+
headers: { "content-type": "application/json" },
|
|
38
|
+
body: JSON.stringify({
|
|
39
|
+
url: payload.url,
|
|
40
|
+
selector: payload.anchor.selector,
|
|
41
|
+
viewport: payload.viewport
|
|
42
|
+
}),
|
|
43
|
+
signal: AbortSignal.timeout(timeoutMs)
|
|
44
|
+
}).then((res) => {
|
|
45
|
+
if (!mine()) return;
|
|
46
|
+
if (res.ok) {
|
|
47
|
+
const { ok: _ok, ...image } = res;
|
|
48
|
+
ctx.grab.amend({ screenshot: {
|
|
49
|
+
status: "ready",
|
|
50
|
+
...image
|
|
51
|
+
} });
|
|
52
|
+
} else {
|
|
53
|
+
const { error: reason, hint } = res;
|
|
54
|
+
ctx.grab.amend({ screenshot: {
|
|
55
|
+
status: "unavailable",
|
|
56
|
+
reason,
|
|
57
|
+
...hint ? { hint } : {}
|
|
58
|
+
} });
|
|
59
|
+
}
|
|
60
|
+
}).catch((error) => {
|
|
61
|
+
if (mine()) ctx.grab.amend({ screenshot: {
|
|
62
|
+
status: "unavailable",
|
|
63
|
+
...failure(error)
|
|
64
|
+
} });
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
//#endregion
|
|
70
|
+
export { CAPTURE_CAPABILITY, screenshot };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
//#region src/plugins/data/msw-browser.ts
|
|
2
|
+
/**
|
|
3
|
+
* `msw/browser` resolves to nothing under the `node` condition, and Next
|
|
4
|
+
* compiles a client component for SSR too, so the import sits in a branch
|
|
5
|
+
* the server build can see is dead (`typeof window` is defined per layer).
|
|
6
|
+
*/
|
|
7
|
+
async function loadMsw() {
|
|
8
|
+
if (typeof window !== "undefined") {
|
|
9
|
+
const [{ http }, { setupWorker }] = await Promise.all([import("msw"), import("msw/browser")]);
|
|
10
|
+
return {
|
|
11
|
+
http,
|
|
12
|
+
setupWorker
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
throw new Error("the MSW worker needs a browser");
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Starts an MSW worker whose one handler asks the HUD's resolver, so client
|
|
19
|
+
* fetches follow the active scenarios. The data plugin loads this module on
|
|
20
|
+
* demand through the `worker` loader:
|
|
21
|
+
*
|
|
22
|
+
* ```ts
|
|
23
|
+
* data({ mocks: { scenarios, worker: () => import("@hansenexus/hud/plugins/data/msw-browser") } })
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* Needs `msw` and its worker script in the app's public directory.
|
|
27
|
+
*/
|
|
28
|
+
async function startMockWorker(resolve, { workerUrl } = {}) {
|
|
29
|
+
const { http, setupWorker } = await loadMsw();
|
|
30
|
+
const worker = setupWorker(http.all("*", ({ request }) => resolve(request)));
|
|
31
|
+
await worker.start({
|
|
32
|
+
onUnhandledFrame: "bypass",
|
|
33
|
+
quiet: true,
|
|
34
|
+
...workerUrl ? { serviceWorker: { url: workerUrl } } : {}
|
|
35
|
+
});
|
|
36
|
+
return { stop: () => worker.stop() };
|
|
37
|
+
}
|
|
38
|
+
//#endregion
|
|
39
|
+
export { startMockWorker };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { i as HudMockNodeStatus, s as HudMockScenario } from "../../mocks-CA-wM2SB.js";
|
|
2
|
+
import { t as HudStore } from "../../types-DaJcsEjO.js";
|
|
3
|
+
//#region src/plugins/data/msw-node.d.ts
|
|
4
|
+
export interface MockServerOptions {
|
|
5
|
+
/** The scenarios, the same list `dataServer({ mocks })` gets. */
|
|
6
|
+
scenarios: readonly HudMockScenario[];
|
|
7
|
+
/** Where the active set persists; the same store `dataServer()` writes. Default `file()`: `.hud/mocks.json`. */
|
|
8
|
+
store?: HudStore;
|
|
9
|
+
}
|
|
10
|
+
export interface HudMockServer {
|
|
11
|
+
status: HudMockNodeStatus;
|
|
12
|
+
/** Stops intercepting and forgets the registry. */
|
|
13
|
+
close: () => void;
|
|
14
|
+
}
|
|
15
|
+
export declare const MSW_INSTALL_HINT = "bun add -d msw";
|
|
16
|
+
/**
|
|
17
|
+
* Starts MSW in Node for the mock scenarios, so server-side fetches (React
|
|
18
|
+
* Server Components, Server Actions, route handlers) follow the active set
|
|
19
|
+
* like the browser's. Call it once from `instrumentation.ts`:
|
|
20
|
+
*
|
|
21
|
+
* ```ts
|
|
22
|
+
* export async function register() {
|
|
23
|
+
* if (process.env.NEXT_RUNTIME === "nodejs" && process.env.NODE_ENV === "development") {
|
|
24
|
+
* const { startMockServer } = await import("@hansenexus/hud/plugins/data/msw-node");
|
|
25
|
+
* const { scenarios } = await import("./hud/scenarios");
|
|
26
|
+
* await startMockServer({ scenarios });
|
|
27
|
+
* }
|
|
28
|
+
* }
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* The active set is read from the store at start and updated in process by
|
|
32
|
+
* `dataServer()` on every toggle. `msw` is loaded here and nowhere else: when
|
|
33
|
+
* it is missing the HUD reports a setup hint instead of failing the server.
|
|
34
|
+
*/
|
|
35
|
+
export declare function startMockServer({ scenarios, store }: MockServerOptions): Promise<HudMockServer>;
|
|
36
|
+
//#endregion
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { c as readMockRegistry, d as validateScenarios, f as writeMockRegistry, i as createMockResolver, n as MOCKS_DOCUMENT, t as MOCKS_COLLECTION, u as toMockActive } from "../../mocks-ESiRqk9o.js";
|
|
2
|
+
import { t as file } from "../../file-xdSaQ2uR.js";
|
|
3
|
+
//#region src/plugins/data/msw-node.ts
|
|
4
|
+
const MSW_INSTALL_HINT = "bun add -d msw";
|
|
5
|
+
/**
|
|
6
|
+
* Starts MSW in Node for the mock scenarios, so server-side fetches (React
|
|
7
|
+
* Server Components, Server Actions, route handlers) follow the active set
|
|
8
|
+
* like the browser's. Call it once from `instrumentation.ts`:
|
|
9
|
+
*
|
|
10
|
+
* ```ts
|
|
11
|
+
* export async function register() {
|
|
12
|
+
* if (process.env.NEXT_RUNTIME === "nodejs" && process.env.NODE_ENV === "development") {
|
|
13
|
+
* const { startMockServer } = await import("@hansenexus/hud/plugins/data/msw-node");
|
|
14
|
+
* const { scenarios } = await import("./hud/scenarios");
|
|
15
|
+
* await startMockServer({ scenarios });
|
|
16
|
+
* }
|
|
17
|
+
* }
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* The active set is read from the store at start and updated in process by
|
|
21
|
+
* `dataServer()` on every toggle. `msw` is loaded here and nowhere else: when
|
|
22
|
+
* it is missing the HUD reports a setup hint instead of failing the server.
|
|
23
|
+
*/
|
|
24
|
+
async function startMockServer({ scenarios, store = file() }) {
|
|
25
|
+
const table = validateScenarios(scenarios);
|
|
26
|
+
readMockRegistry()?.close();
|
|
27
|
+
let active = {};
|
|
28
|
+
try {
|
|
29
|
+
active = toMockActive(await store.get(MOCKS_COLLECTION, MOCKS_DOCUMENT), table);
|
|
30
|
+
} catch (error) {
|
|
31
|
+
console.warn("hud mocks: could not read the active scenarios; starting with none", error);
|
|
32
|
+
}
|
|
33
|
+
const resolve = createMockResolver(table, () => active);
|
|
34
|
+
let stop = () => {};
|
|
35
|
+
const registry = {
|
|
36
|
+
status: { status: "off" },
|
|
37
|
+
active: () => active,
|
|
38
|
+
apply(next) {
|
|
39
|
+
active = next;
|
|
40
|
+
},
|
|
41
|
+
close() {
|
|
42
|
+
const current = stop;
|
|
43
|
+
stop = () => {};
|
|
44
|
+
current();
|
|
45
|
+
if (readMockRegistry() === registry) writeMockRegistry(void 0);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
writeMockRegistry(registry);
|
|
49
|
+
try {
|
|
50
|
+
const [{ http }, { setupServer }] = await Promise.all([import("msw"), import("msw/node")]);
|
|
51
|
+
const server = setupServer(http.all("*", ({ request }) => resolve(request)));
|
|
52
|
+
server.listen({ onUnhandledFrame: "bypass" });
|
|
53
|
+
stop = () => server.close();
|
|
54
|
+
registry.status = { status: "live" };
|
|
55
|
+
} catch (error) {
|
|
56
|
+
registry.status = {
|
|
57
|
+
status: "failed",
|
|
58
|
+
hint: `Server fetches are not mocked: msw could not start (${error instanceof Error ? error.message : String(error)}). Install it: ${MSW_INSTALL_HINT}.`
|
|
59
|
+
};
|
|
60
|
+
console.warn(`hud mocks: ${registry.status.hint}`);
|
|
61
|
+
}
|
|
62
|
+
return {
|
|
63
|
+
status: registry.status,
|
|
64
|
+
close: registry.close
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
//#endregion
|
|
68
|
+
export { MSW_INSTALL_HINT, startMockServer };
|
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
import { l as HudRouteContext } from "../../plugins-BZvDqGx5.js";
|
|
2
|
+
import { _ as validateScenarios, a as HudMockRegistry, c as HudMockScenarioInfo, d as MOCK_SCENARIO_ID, f as createMockResolver, g as toMockActive, h as readMockRegistry, i as HudMockNodeStatus, l as MOCKS_COLLECTION, m as parseEndpoint, n as HudMockContext, o as HudMockResolve, p as matchEndpoint, r as HudMockMethod, s as HudMockScenario, t as HudMockActive, u as MOCKS_DOCUMENT } from "../../mocks-CA-wM2SB.js";
|
|
3
|
+
import { c as HudFlagValue, g as serializeFlagOverrides, h as readFlagOverrides, l as flagCookieString, n as FLAGS_STORAGE_KEY, o as HudFlagOverride, r as FLAG_KEY, s as HudFlagScope, t as FLAGS_COOKIE } from "../../flags-DVtaJ8pQ.js";
|
|
4
|
+
import { a as FlagsResponse, c as HudFlagDefinition, d as HudSeedInfo, f as MocksResponse, h as SeedRunResponse, i as FlagOverrideBody, l as HudFlagType, m as RoleSwitchResponse, n as FLAGS_COLLECTION, o as HudAuthUser, p as RoleSwitchBody, r as FLAGS_DOCUMENT, s as HudAuthUserInfo, t as DataStateResponse, u as HudSeed } from "../../types-Dn68psVz.js";
|
|
5
|
+
import { t as HudStore } from "../../types-DaJcsEjO.js";
|
|
6
|
+
import "../../server.js";
|
|
7
|
+
//#region src/plugins/data/auth/types.d.ts
|
|
8
|
+
/**
|
|
9
|
+
* What a sign-in or sign-out leaves behind: `Set-Cookie` headers the route
|
|
10
|
+
* appends to its response, and `localStorage` writes the browser performs
|
|
11
|
+
* before it reloads (`null` removes a key), for sessions that live there.
|
|
12
|
+
*/
|
|
13
|
+
interface AuthSwitch {
|
|
14
|
+
setCookie: string[];
|
|
15
|
+
storage: Record<string, string | null>;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The auth seam. One adapter per auth library; each knows where that
|
|
19
|
+
* library keeps its session and takes from the app the one thing only the
|
|
20
|
+
* app can do: produce a session for a fixture user. Runs server side only.
|
|
21
|
+
*/
|
|
22
|
+
interface HudAuthAdapter {
|
|
23
|
+
/** `convex-auth`, `better-auth`, `cookie`, or the app's own. */
|
|
24
|
+
id: string;
|
|
25
|
+
label: string;
|
|
26
|
+
/** The fixture users the panel offers, or a loader called on each listing. */
|
|
27
|
+
users: readonly HudAuthUser[] | (() => Promise<readonly HudAuthUser[]>);
|
|
28
|
+
/** Who the request is signed in as, judged from its cookies. */
|
|
29
|
+
current: (request: Request) => Promise<HudAuthUser | null>;
|
|
30
|
+
/** Signs the browser in as `user`. */
|
|
31
|
+
signIn: (user: HudAuthUser, request: Request) => Promise<AuthSwitch>;
|
|
32
|
+
/** Ends the current session. */
|
|
33
|
+
signOut: (request: Request) => Promise<AuthSwitch>;
|
|
34
|
+
}
|
|
35
|
+
export declare class HudAuthError extends Error {
|
|
36
|
+
/** HTTP status the route answers with. */
|
|
37
|
+
readonly status: number;
|
|
38
|
+
constructor(message: string,
|
|
39
|
+
/** HTTP status the route answers with. */
|
|
40
|
+
status?: number);
|
|
41
|
+
}
|
|
42
|
+
//#endregion
|
|
43
|
+
//#region src/plugins/data/flags-source.d.ts
|
|
44
|
+
/**
|
|
45
|
+
* The flag-source seam: where the app's real flags come from (its config, a
|
|
46
|
+
* PostHog or Unleash client, a database table). The HUD only lists them and
|
|
47
|
+
* lays overrides over them; it never writes to the source.
|
|
48
|
+
*/
|
|
49
|
+
interface HudFlagSource {
|
|
50
|
+
/** The flags and their real values, as the app would read them for this request. */
|
|
51
|
+
list: (request: Request) => Promise<readonly HudFlagDefinition[]> | readonly HudFlagDefinition[];
|
|
52
|
+
}
|
|
53
|
+
/** A source that is just a list: the flags the app declares in code. */
|
|
54
|
+
export declare function staticFlags(definitions: readonly HudFlagDefinition[]): HudFlagSource;
|
|
55
|
+
//#endregion
|
|
56
|
+
//#region src/plugins/data/auth/better-auth.d.ts
|
|
57
|
+
/**
|
|
58
|
+
* The slice of a better-auth server instance the adapter calls. Structural,
|
|
59
|
+
* so the package has no dependency on better-auth: pass `auth` from
|
|
60
|
+
* `betterAuth({...})` and the shapes line up.
|
|
61
|
+
*/
|
|
62
|
+
interface BetterAuthApi {
|
|
63
|
+
api: {
|
|
64
|
+
signInEmail: (input: {
|
|
65
|
+
body: {
|
|
66
|
+
email: string;
|
|
67
|
+
password: string;
|
|
68
|
+
};
|
|
69
|
+
headers?: Headers;
|
|
70
|
+
asResponse: true;
|
|
71
|
+
}) => Promise<Response>;
|
|
72
|
+
getSession?: (input: {
|
|
73
|
+
headers: Headers;
|
|
74
|
+
}) => Promise<unknown>;
|
|
75
|
+
signOut?: (input: {
|
|
76
|
+
headers: Headers;
|
|
77
|
+
asResponse: true;
|
|
78
|
+
}) => Promise<Response>;
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
interface BetterAuthOptions {
|
|
82
|
+
/** The fixture users: `email` and `password` are what `signInEmail` takes. */
|
|
83
|
+
users: readonly HudAuthUser[] | (() => Promise<readonly HudAuthUser[]>);
|
|
84
|
+
/** The app's better-auth instance. */
|
|
85
|
+
auth: BetterAuthApi;
|
|
86
|
+
/** better-auth's `advanced.cookiePrefix`. Default `better-auth`. */
|
|
87
|
+
cookiePrefix?: string;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Role switch for better-auth apps (proveno, mailnexus). Signing in runs the
|
|
91
|
+
* app's own `auth.api.signInEmail` for the fixture user's email and password
|
|
92
|
+
* and forwards the cookies better-auth sets; "signed in as" asks
|
|
93
|
+
* `auth.api.getSession` with the request's headers.
|
|
94
|
+
*/
|
|
95
|
+
export declare function betterAuth(options: BetterAuthOptions): HudAuthAdapter;
|
|
96
|
+
//#endregion
|
|
97
|
+
//#region src/plugins/data/auth/convex-auth.d.ts
|
|
98
|
+
/** Convex Auth's cookie and `localStorage` key names (the Next.js and browser flavours). */
|
|
99
|
+
export declare const CONVEX_AUTH_JWT_KEY = "__convexAuthJWT";
|
|
100
|
+
export declare const CONVEX_AUTH_REFRESH_KEY = "__convexAuthRefreshToken";
|
|
101
|
+
interface ConvexAuthTokens {
|
|
102
|
+
token: string;
|
|
103
|
+
refreshToken: string;
|
|
104
|
+
}
|
|
105
|
+
interface ConvexAuthOptions {
|
|
106
|
+
/** The fixture users the panel offers. */
|
|
107
|
+
users: readonly HudAuthUser[] | (() => Promise<readonly HudAuthUser[]>);
|
|
108
|
+
/**
|
|
109
|
+
* Mints a Convex Auth session for the user: the app's own development-only
|
|
110
|
+
* Convex action that creates a session and signs its tokens, called with
|
|
111
|
+
* the deployment's admin key or an internal function. The HUD never knows
|
|
112
|
+
* how; it only stores what comes back where Convex Auth looks for it.
|
|
113
|
+
*/
|
|
114
|
+
mint: (user: HudAuthUser) => Promise<ConvexAuthTokens>;
|
|
115
|
+
/**
|
|
116
|
+
* Write the Next.js cookies (`__convexAuthJWT`, `__convexAuthRefreshToken`,
|
|
117
|
+
* `__Host-` prefixed off localhost like `@convex-dev/auth/nextjs`). Default true.
|
|
118
|
+
*/
|
|
119
|
+
cookies?: boolean;
|
|
120
|
+
/**
|
|
121
|
+
* The browser flavour: the Convex deployment URL `ConvexAuthProvider` was
|
|
122
|
+
* given, so the tokens also go into `localStorage` under Convex Auth's
|
|
123
|
+
* namespaced keys. Needed in a Vite app; harmless beside the cookies.
|
|
124
|
+
*/
|
|
125
|
+
storageNamespace?: string;
|
|
126
|
+
}
|
|
127
|
+
/** `${key}_${namespace}` with the namespace stripped to alphanumerics, as Convex Auth does. */
|
|
128
|
+
export declare function convexAuthStorageKey(key: string, namespace: string): string;
|
|
129
|
+
/** The user id out of a Convex Auth JWT: `sub` is `<userId>|<sessionId>`. */
|
|
130
|
+
export declare function convexAuthSubject(token: string | undefined): string | undefined;
|
|
131
|
+
/**
|
|
132
|
+
* Role switch for Convex Auth apps (fachwerk, lexilink-next). The app mints
|
|
133
|
+
* the session; the adapter puts the tokens where `@convex-dev/auth` reads
|
|
134
|
+
* them and reads `sub` back out of the JWT cookie for "signed in as".
|
|
135
|
+
*/
|
|
136
|
+
export declare function convexAuth(options: ConvexAuthOptions): HudAuthAdapter;
|
|
137
|
+
//#endregion
|
|
138
|
+
//#region src/plugins/data/auth/cookie-impersonation.d.ts
|
|
139
|
+
/** Default cookie the impersonation is carried in. */
|
|
140
|
+
export declare const IMPERSONATION_COOKIE = "hud-impersonate";
|
|
141
|
+
interface CookieImpersonationOptions {
|
|
142
|
+
/** The fixture users the panel offers. */
|
|
143
|
+
users: readonly HudAuthUser[] | (() => Promise<readonly HudAuthUser[]>);
|
|
144
|
+
/**
|
|
145
|
+
* Resolves the user behind an id, for the panel's "signed in as" and for
|
|
146
|
+
* refusing ids the app does not know. Default: look it up in `users`.
|
|
147
|
+
*/
|
|
148
|
+
getUser?: (id: string) => HudAuthUser | null | undefined | Promise<HudAuthUser | null | undefined>;
|
|
149
|
+
/** Cookie name. Default `hud-impersonate`. */
|
|
150
|
+
cookie?: string;
|
|
151
|
+
/**
|
|
152
|
+
* Signs the cookie. Default: `HUD_ACCESS_SECRET`, else `HUD_ACCESS_PASSWORD`,
|
|
153
|
+
* read at call time, so on a deployed tier the cookie is signed with the
|
|
154
|
+
* HUD's own secret and cannot be forged. Without any the cookie is unsigned,
|
|
155
|
+
* which is fine in development and nowhere else.
|
|
156
|
+
*/
|
|
157
|
+
secret?: string | (() => string | undefined);
|
|
158
|
+
/** How long an impersonation lasts. Default 12 h. */
|
|
159
|
+
ttlMs?: number;
|
|
160
|
+
}
|
|
161
|
+
interface ImpersonationReadOptions {
|
|
162
|
+
cookie?: string;
|
|
163
|
+
secret?: string | (() => string | undefined);
|
|
164
|
+
ttlMs?: number;
|
|
165
|
+
now?: number;
|
|
166
|
+
}
|
|
167
|
+
interface Impersonation {
|
|
168
|
+
id: string;
|
|
169
|
+
issuedAt: number;
|
|
170
|
+
/** Whether the cookie carried a signature that verified. */
|
|
171
|
+
signed: boolean;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* The impersonation a request carries, or null. This is what the app's own
|
|
175
|
+
* auth layer calls to honour the switch: `readImpersonation(request)` and,
|
|
176
|
+
* when it names a user, treat the request as that user. With a secret the
|
|
177
|
+
* signature must verify; without one only an unsigned cookie is accepted.
|
|
178
|
+
*/
|
|
179
|
+
export declare function readImpersonation(source: Request | string | null | undefined, options?: ImpersonationReadOptions): Promise<Impersonation | null>;
|
|
180
|
+
/**
|
|
181
|
+
* Impersonation by cookie, for apps whose auth the HUD does not know (team-pulse,
|
|
182
|
+
* the Vite apps): picking a role sets `hud-impersonate=<user>` and the app's
|
|
183
|
+
* auth layer honours it through `readImpersonation()`. Self-contained: no
|
|
184
|
+
* session is minted anywhere, so it only works where the app chooses to read it.
|
|
185
|
+
*/
|
|
186
|
+
export declare function cookieImpersonation(options: CookieImpersonationOptions): HudAuthAdapter;
|
|
187
|
+
//#endregion
|
|
188
|
+
//#region src/plugins/data/server.d.ts
|
|
189
|
+
export interface DataServerOptions {
|
|
190
|
+
/** The auth seam: `convexAuth()`, `betterAuth()` or `cookieImpersonation()`. Without it there is no role switch. */
|
|
191
|
+
auth?: HudAuthAdapter | undefined;
|
|
192
|
+
/** The flag source, or the definitions themselves. Without it there are no flags. */
|
|
193
|
+
flags?: HudFlagSource | readonly HudFlagDefinition[] | undefined;
|
|
194
|
+
/** Seed functions the panel runs. Without them there is no Seeds section. */
|
|
195
|
+
seeds?: readonly HudSeed[] | undefined;
|
|
196
|
+
/**
|
|
197
|
+
* The mock scenarios, the same list `startMockServer()` and the client's
|
|
198
|
+
* `data({ mocks })` get. Without it there is no Mock scenarios section.
|
|
199
|
+
*/
|
|
200
|
+
mocks?: readonly HudMockScenario[] | undefined;
|
|
201
|
+
/** Where overrides and the active scenarios persist. Default `file()`: `.hud/flags.json`, `.hud/mocks.json`. */
|
|
202
|
+
store?: HudStore;
|
|
203
|
+
}
|
|
204
|
+
/** What the browser may know about a user: everything but the password. */
|
|
205
|
+
export declare function publicUser({ password: _password, ...user }: HudAuthUser): HudAuthUserInfo;
|
|
206
|
+
/** The overrides out of the store's one document, dropping anything malformed. */
|
|
207
|
+
export declare function toFlagOverrides(value: unknown): HudFlagOverride[];
|
|
208
|
+
/** What the browser may know about a seed: everything but `run`. */
|
|
209
|
+
export declare function seedInfo({ run: _run, ...seed }: HudSeed): HudSeedInfo;
|
|
210
|
+
/** The seed's result as JSON; what does not serialise is described instead. */
|
|
211
|
+
export declare function toSeedResult(value: unknown): unknown;
|
|
212
|
+
/**
|
|
213
|
+
* Server half of `data()`: the role switch through the auth seam and
|
|
214
|
+
* feature-flag overrides through the storage seam. Carries `data.write`,
|
|
215
|
+
* which `access` hard-denies on production and grants on staging only when
|
|
216
|
+
* the app's matrix says so.
|
|
217
|
+
*
|
|
218
|
+
* ```ts
|
|
219
|
+
* dataServer({
|
|
220
|
+
* auth: cookieImpersonation({ users }),
|
|
221
|
+
* flags: [{ key: "new-checkout", value: false }],
|
|
222
|
+
* store: file(),
|
|
223
|
+
* })
|
|
224
|
+
* ```
|
|
225
|
+
*/
|
|
226
|
+
export declare function dataServer({ auth, flags, seeds, mocks, store }?: DataServerOptions): {
|
|
227
|
+
readonly id: "data";
|
|
228
|
+
readonly capability: "data.write";
|
|
229
|
+
readonly routes: {
|
|
230
|
+
readonly "/": {
|
|
231
|
+
readonly GET: (request: Request) => Promise<Response>;
|
|
232
|
+
};
|
|
233
|
+
readonly "/role": {
|
|
234
|
+
readonly POST: (request: Request) => Promise<Response>;
|
|
235
|
+
readonly DELETE: (request: Request) => Promise<Response>;
|
|
236
|
+
};
|
|
237
|
+
readonly "/flags": {
|
|
238
|
+
readonly DELETE: (request: Request) => Promise<Response>;
|
|
239
|
+
};
|
|
240
|
+
readonly "/seeds/:id": {
|
|
241
|
+
readonly POST: (request: Request, { params }: HudRouteContext) => Promise<Response>;
|
|
242
|
+
};
|
|
243
|
+
readonly "/mocks": {
|
|
244
|
+
readonly DELETE: (request: Request) => Promise<Response>;
|
|
245
|
+
};
|
|
246
|
+
readonly "/mocks/:id": {
|
|
247
|
+
readonly PUT: (request: Request, { params }: HudRouteContext) => Promise<Response>;
|
|
248
|
+
readonly DELETE: (request: Request, { params }: HudRouteContext) => Promise<Response>;
|
|
249
|
+
};
|
|
250
|
+
readonly "/flags/:key": {
|
|
251
|
+
readonly PUT: (request: Request, { params }: HudRouteContext) => Promise<Response>;
|
|
252
|
+
readonly DELETE: (request: Request, { params }: HudRouteContext) => Promise<Response>;
|
|
253
|
+
};
|
|
254
|
+
};
|
|
255
|
+
};
|
|
256
|
+
//#endregion
|
|
257
|
+
export { type AuthSwitch, type BetterAuthApi, type BetterAuthOptions, type ConvexAuthOptions, type ConvexAuthTokens, type CookieImpersonationOptions, type DataStateResponse, FLAGS_COLLECTION, FLAGS_COOKIE, FLAGS_DOCUMENT, FLAGS_STORAGE_KEY, FLAG_KEY, type FlagOverrideBody, type FlagsResponse, type HudAuthAdapter, type HudAuthUser, type HudAuthUserInfo, type HudFlagDefinition, type HudFlagOverride, type HudFlagScope, type HudFlagSource, type HudFlagType, type HudFlagValue, type HudMockActive, type HudMockContext, type HudMockMethod, type HudMockNodeStatus, type HudMockRegistry, type HudMockResolve, type HudMockScenario, type HudMockScenarioInfo, type HudSeed, type HudSeedInfo, type Impersonation, type ImpersonationReadOptions, MOCKS_COLLECTION, MOCKS_DOCUMENT, MOCK_SCENARIO_ID, type MocksResponse, type RoleSwitchBody, type RoleSwitchResponse, type SeedRunResponse, createMockResolver, flagCookieString, matchEndpoint, parseEndpoint, readFlagOverrides, readMockRegistry, serializeFlagOverrides, toMockActive, validateScenarios };
|