@hansenexus/hud 0.3.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 +782 -6
- package/dist/a11y-B5DUaiCs.js +246 -0
- package/dist/a11y-panel-p_t4eD7p.js +207 -0
- package/dist/access-C7zlaqj6.js +100 -0
- package/dist/access-D_ewAEJG.d.ts +61 -0
- 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-CApnbI0r.d.ts +19 -0
- package/dist/env-CaiFPIhF.js +31 -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-BaqWsmrf.js +153 -0
- package/dist/force-state-CCqoTfVB.d.ts +23 -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-DtYVCZY6.d.ts +39 -0
- 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-gCZBO53s.d.ts +73 -0
- package/dist/index.d.ts +6 -36
- package/dist/index.js +798 -240
- package/dist/inspect-C9Ft8fqn.js +142 -0
- package/dist/inspect-root-BkaupBMp.js +429 -0
- package/dist/marker-C66LxOhJ.d.ts +9 -0
- package/dist/marker-CMrvxPmS.d.ts +12 -0
- package/dist/marker-DjeGvL-F.js +9 -0
- package/dist/marker-uZYPOJ4M.js +12 -0
- package/dist/markers.d.ts +3 -0
- package/dist/markers.js +3 -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 -19
- package/dist/next.js +7 -30
- 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-MUQ9ciER.d.ts +92 -0
- package/dist/plugins/a11y.d.ts +2 -0
- package/dist/plugins/a11y.js +2 -0
- package/dist/plugins/access/server.d.ts +122 -0
- package/dist/plugins/access/server.js +340 -0
- package/dist/plugins/access.d.ts +41 -0
- package/dist/plugins/access.js +51 -0
- package/dist/plugins/agent/server.d.ts +94 -0
- package/dist/plugins/agent/server.js +455 -0
- package/dist/plugins/agent.d.ts +37 -0
- package/dist/plugins/agent.js +69 -0
- 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 +5 -0
- package/dist/plugins/design.js +4 -0
- 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 -0
- package/dist/plugins/observe.js +2 -0
- package/dist/plugins/ops/server.d.ts +82 -0
- package/dist/plugins/ops/server.js +381 -0
- package/dist/plugins/ops.d.ts +27 -0
- package/dist/plugins/ops.js +41 -0
- 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 +4 -86
- package/dist/plugins-BZvDqGx5.d.ts +144 -0
- package/dist/{plugins-CzUiTn_r.js → plugins-DVy_vaYr.js} +3 -1
- 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.d.ts +181 -0
- package/dist/review.js +1017 -0
- package/dist/same-origin-BGet22CC.js +21 -0
- package/dist/scan-DzJNXqOk.js +165 -0
- package/dist/selector-NSYSe7AZ.js +28 -0
- package/dist/seo-Dq9q_QkO.js +551 -0
- package/dist/seo-panel-CfiY-TnT.js +124 -0
- package/dist/server.d.ts +3 -39
- package/dist/server.js +2 -105
- package/dist/sessions-panel-COvhPAzv.js +98 -0
- package/dist/shortcut-s_mjGeU8.js +179 -0
- package/dist/state-CjjZPjPJ.js +40 -0
- package/dist/state-boundary.d.ts +26 -0
- package/dist/state-boundary.js +61 -0
- package/dist/store/convex.d.ts +33 -0
- package/dist/store/convex.js +52 -0
- package/dist/store-CQqIIKTc.js +59 -0
- package/dist/store-Ync9eb1G.js +67 -0
- package/dist/store.d.ts +76 -0
- package/dist/store.js +188 -0
- package/dist/styles-BA8ueHoV.js +342 -0
- 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-Cxh4twqc.d.ts +50 -0
- 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-f3jlNxzw.d.ts +92 -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 +85 -5
- package/dist/define-hud-BHQR8Lbv.d.ts +0 -31
- package/dist/plugins-1QmTmZyL.d.ts +0 -76
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { i as hudUnlockTtlMs, o as resolveHudAccess } from "./access-C7zlaqj6.js";
|
|
2
|
+
import { n as useUnlockState, t as submitPassword } from "./unlock-store-4V3vR4Eg.js";
|
|
3
|
+
import { useState } from "react";
|
|
4
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
+
//#region src/plugins/access/access-panel.tsx
|
|
6
|
+
const ACCESS_TEXT = {
|
|
7
|
+
open: "open, no password",
|
|
8
|
+
password: "password",
|
|
9
|
+
flag: "password, observe-only",
|
|
10
|
+
denied: "disabled"
|
|
11
|
+
};
|
|
12
|
+
const field = {
|
|
13
|
+
flex: 1,
|
|
14
|
+
minWidth: 0,
|
|
15
|
+
padding: "3px 6px",
|
|
16
|
+
font: "inherit",
|
|
17
|
+
fontFamily: "var(--hud-mono)",
|
|
18
|
+
color: "var(--hud-fg)",
|
|
19
|
+
background: "var(--hud-bg-subtle)",
|
|
20
|
+
border: "1px solid var(--hud-border)",
|
|
21
|
+
borderRadius: 4
|
|
22
|
+
};
|
|
23
|
+
const button = {
|
|
24
|
+
padding: "3px 10px",
|
|
25
|
+
border: "1px solid var(--hud-border)",
|
|
26
|
+
borderRadius: 4
|
|
27
|
+
};
|
|
28
|
+
/** The panel a locked deployed HUD shows instead of every other plugin. Loaded on first open. */
|
|
29
|
+
function AccessPanel({ ctx, matrix }) {
|
|
30
|
+
const { env, status, error } = useUnlockState();
|
|
31
|
+
const [password, setPassword] = useState("");
|
|
32
|
+
const [submitting, setSubmitting] = useState(false);
|
|
33
|
+
const access = resolveHudAccess(env);
|
|
34
|
+
const ttlHours = hudUnlockTtlMs(access) / 36e5;
|
|
35
|
+
async function onSubmit(event) {
|
|
36
|
+
event.preventDefault();
|
|
37
|
+
if (!password || submitting) return;
|
|
38
|
+
setSubmitting(true);
|
|
39
|
+
const ok = await submitPassword(ctx.api, password);
|
|
40
|
+
setSubmitting(false);
|
|
41
|
+
if (ok) setPassword("");
|
|
42
|
+
}
|
|
43
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
44
|
+
style: {
|
|
45
|
+
display: "grid",
|
|
46
|
+
gap: 8
|
|
47
|
+
},
|
|
48
|
+
children: [
|
|
49
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
50
|
+
/* @__PURE__ */ jsx("strong", { children: env }),
|
|
51
|
+
" ",
|
|
52
|
+
/* @__PURE__ */ jsxs("span", {
|
|
53
|
+
className: "empty",
|
|
54
|
+
children: ["· ", ACCESS_TEXT[access]]
|
|
55
|
+
})
|
|
56
|
+
] }),
|
|
57
|
+
status === "unconfigured" && /* @__PURE__ */ jsx("p", {
|
|
58
|
+
className: "empty",
|
|
59
|
+
style: { margin: 0 },
|
|
60
|
+
children: "No unlock password is configured on this deployment's server, so the HUD cannot be unlocked here."
|
|
61
|
+
}),
|
|
62
|
+
status !== "unconfigured" && access !== "open" && status !== "unlocked" && /* @__PURE__ */ jsxs("form", {
|
|
63
|
+
style: {
|
|
64
|
+
display: "flex",
|
|
65
|
+
gap: 6
|
|
66
|
+
},
|
|
67
|
+
onSubmit,
|
|
68
|
+
children: [/* @__PURE__ */ jsx("input", {
|
|
69
|
+
type: "password",
|
|
70
|
+
autoComplete: "off",
|
|
71
|
+
value: password,
|
|
72
|
+
onChange: (event) => setPassword(event.target.value),
|
|
73
|
+
placeholder: "hud password",
|
|
74
|
+
"aria-label": "hud password",
|
|
75
|
+
style: field
|
|
76
|
+
}), /* @__PURE__ */ jsx("button", {
|
|
77
|
+
type: "submit",
|
|
78
|
+
style: button,
|
|
79
|
+
disabled: !password || submitting,
|
|
80
|
+
children: submitting ? "Checking…" : "Unlock"
|
|
81
|
+
})]
|
|
82
|
+
}),
|
|
83
|
+
error && /* @__PURE__ */ jsx("p", {
|
|
84
|
+
role: "alert",
|
|
85
|
+
style: {
|
|
86
|
+
margin: 0,
|
|
87
|
+
color: "var(--hud-poor)"
|
|
88
|
+
},
|
|
89
|
+
children: error
|
|
90
|
+
}),
|
|
91
|
+
access !== "open" && status === "unlocked" && /* @__PURE__ */ jsxs("p", {
|
|
92
|
+
className: "empty",
|
|
93
|
+
style: { margin: 0 },
|
|
94
|
+
children: [
|
|
95
|
+
"Unlocked for up to ",
|
|
96
|
+
ttlHours,
|
|
97
|
+
" h."
|
|
98
|
+
]
|
|
99
|
+
}),
|
|
100
|
+
access !== "open" && status !== "unlocked" && ttlHours > 0 && /* @__PURE__ */ jsxs("p", {
|
|
101
|
+
className: "empty",
|
|
102
|
+
style: { margin: 0 },
|
|
103
|
+
children: [
|
|
104
|
+
"An unlock lasts ",
|
|
105
|
+
ttlHours,
|
|
106
|
+
" h."
|
|
107
|
+
]
|
|
108
|
+
}),
|
|
109
|
+
/* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("div", {
|
|
110
|
+
className: "empty",
|
|
111
|
+
children: "Capabilities"
|
|
112
|
+
}), /* @__PURE__ */ jsx("code", {
|
|
113
|
+
style: {
|
|
114
|
+
fontFamily: "var(--hud-mono)",
|
|
115
|
+
whiteSpace: "pre-wrap"
|
|
116
|
+
},
|
|
117
|
+
children: env === "development" ? "all" : matrix[env].join("\n") || "none"
|
|
118
|
+
})] })
|
|
119
|
+
]
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
//#endregion
|
|
123
|
+
export { AccessPanel as default };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { ComponentType } from "react";
|
|
2
|
+
//#region src/plugins/inspect/adapter.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* An inspect adapter adds a tab to the Inspect panel for one data source:
|
|
5
|
+
* Convex, React Query, SWR, sockets. Each adapter is its own subpath export
|
|
6
|
+
* (`@hansenexus/hud/plugins/inspect/<id>`), so an app that omits one ships
|
|
7
|
+
* none of its code; the inspect core only knows this interface.
|
|
8
|
+
*/
|
|
9
|
+
interface InspectAdapter {
|
|
10
|
+
/** Tab id, unique among the adapters of one inspect plugin. */
|
|
11
|
+
id: string;
|
|
12
|
+
/** Tab label. */
|
|
13
|
+
title: string;
|
|
14
|
+
/** Tab content. Rendered inside the Inspect panel, so `.insp-*` classes apply. */
|
|
15
|
+
Panel: ComponentType;
|
|
16
|
+
/** Hook returning the count shown next to the tab label. */
|
|
17
|
+
useCount?: () => number;
|
|
18
|
+
/**
|
|
19
|
+
* Called when the HUD mounts (and again after a StrictMode re-mount), for
|
|
20
|
+
* work that must run after the app's bootstrap: re-checking a patched
|
|
21
|
+
* global, say.
|
|
22
|
+
*/
|
|
23
|
+
install?: () => void;
|
|
24
|
+
/** Undoes what the factory installed (patches, subscriptions). Test seam. */
|
|
25
|
+
dispose?: () => void;
|
|
26
|
+
}
|
|
27
|
+
interface Preview {
|
|
28
|
+
/** Redacted JSON, at most `MAX_BODY` characters. */
|
|
29
|
+
text: string;
|
|
30
|
+
truncated: boolean;
|
|
31
|
+
}
|
|
32
|
+
//#endregion
|
|
33
|
+
export { Preview as n, InspectAdapter as t };
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { p as redactBody, t as MAX_BODY } from "./requests-BwD6MKEq.js";
|
|
2
|
+
import { useEffect, useState } from "react";
|
|
3
|
+
//#region src/plugins/inspect/adapter.ts
|
|
4
|
+
/**
|
|
5
|
+
* A value as the inspector shows it: JSON with sensitive keys redacted,
|
|
6
|
+
* capped at the request body limit. Values that cannot be serialised
|
|
7
|
+
* (cycles, bigints) are described instead.
|
|
8
|
+
*/
|
|
9
|
+
function preview(value) {
|
|
10
|
+
let json;
|
|
11
|
+
try {
|
|
12
|
+
json = value === void 0 ? "undefined" : JSON.stringify(value) ?? String(value);
|
|
13
|
+
} catch (error) {
|
|
14
|
+
return {
|
|
15
|
+
text: `[unserialisable: ${error instanceof Error ? error.message : String(error)}]`,
|
|
16
|
+
truncated: false
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
const truncated = json.length > MAX_BODY;
|
|
20
|
+
return {
|
|
21
|
+
text: redactBody(truncated ? json.slice(0, MAX_BODY) : json, "application/json"),
|
|
22
|
+
truncated
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
/** Pretty-printed form of a `preview()` text, for a detail view. */
|
|
26
|
+
function prettyPreview({ text, truncated }) {
|
|
27
|
+
let body = text;
|
|
28
|
+
try {
|
|
29
|
+
body = JSON.stringify(JSON.parse(text), null, 2);
|
|
30
|
+
} catch {}
|
|
31
|
+
return truncated ? `${body}\n… (truncated)` : body;
|
|
32
|
+
}
|
|
33
|
+
/** `3 s ago`, `2 min ago`, `just now`; `never` without a timestamp. */
|
|
34
|
+
function ago(ts, now) {
|
|
35
|
+
if (ts === void 0 || ts === 0) return "never";
|
|
36
|
+
const seconds = Math.max(0, Math.round((now - ts) / 1e3));
|
|
37
|
+
if (seconds < 1) return "just now";
|
|
38
|
+
if (seconds < 60) return `${seconds} s ago`;
|
|
39
|
+
const minutes = Math.round(seconds / 60);
|
|
40
|
+
if (minutes < 60) return `${minutes} min ago`;
|
|
41
|
+
return `${Math.round(minutes / 60)} h ago`;
|
|
42
|
+
}
|
|
43
|
+
/** The current time, refreshed every `intervalMs` while mounted, for relative timestamps. */
|
|
44
|
+
function useNow(intervalMs = 1e3) {
|
|
45
|
+
const [now, setNow] = useState(() => Date.now());
|
|
46
|
+
useEffect(() => {
|
|
47
|
+
const timer = window.setInterval(() => setNow(Date.now()), intervalMs);
|
|
48
|
+
return () => window.clearInterval(timer);
|
|
49
|
+
}, [intervalMs]);
|
|
50
|
+
return now;
|
|
51
|
+
}
|
|
52
|
+
/** A short one-line form of a value for a row: a string as is, anything else as compact JSON. */
|
|
53
|
+
function oneLine(value, max = 60) {
|
|
54
|
+
const text = typeof value === "string" ? value : preview(value).text;
|
|
55
|
+
return text.length > max ? `${text.slice(0, max - 1)}…` : text;
|
|
56
|
+
}
|
|
57
|
+
/** Bytes of a frame or body, for sockets and blobs. */
|
|
58
|
+
function byteSize(data) {
|
|
59
|
+
if (typeof data === "string") return new TextEncoder().encode(data).byteLength;
|
|
60
|
+
if (typeof Blob !== "undefined" && data instanceof Blob) return data.size;
|
|
61
|
+
if (data instanceof ArrayBuffer || ArrayBuffer.isView(data)) return data.byteLength;
|
|
62
|
+
return 0;
|
|
63
|
+
}
|
|
64
|
+
//#endregion
|
|
65
|
+
export { preview as a, prettyPreview as i, byteSize as n, useNow as o, oneLine as r, ago as t };
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { t as HudAutoDetected } from "../detect-BxHZ0pxW.js";
|
|
2
|
+
import { o as HudPlugin } from "../plugins-BZvDqGx5.js";
|
|
3
|
+
import { n as a11y, t as A11yOptions } from "../index-DqOyNf1u.js";
|
|
4
|
+
import { n as data } from "../index-DstI_ike.js";
|
|
5
|
+
import { t as forceState } from "../index-Hhh7OXzU.js";
|
|
6
|
+
import { t as InspectAdapter } from "../adapter-BYoxPYTI.js";
|
|
7
|
+
import { n as InspectOptions, r as inspect } from "../index-CwfX-W87.js";
|
|
8
|
+
import { r as inspectConvex, t as ConvexClientLike } from "../index-BJ26pse9.js";
|
|
9
|
+
import { i as inspectReactQuery, n as QueryClientLike } from "../index-RgXfMBuW.js";
|
|
10
|
+
import { o as inspectSwr, t as InspectSwrOptions } from "../index-Dxz4fn4j.js";
|
|
11
|
+
import { n as observe, t as ObserveOptions } from "../index-BAV_1W8a.js";
|
|
12
|
+
import { t as routes } from "../index-BnQ0dTZf.js";
|
|
13
|
+
import { t as seo } from "../index-DcH9V3cU.js";
|
|
14
|
+
import { t as vitals } from "../index-ReFbhQ9p.js";
|
|
15
|
+
//#region src/auto/runtime.d.ts
|
|
16
|
+
/**
|
|
17
|
+
* What `auto()` takes: the instances a detected adapter wraps (a package can
|
|
18
|
+
* find a dependency, not the app's client object) and the options of the base
|
|
19
|
+
* plugins. Everything is optional; a detected adapter without its instance
|
|
20
|
+
* shows a tab that says what to pass.
|
|
21
|
+
*/
|
|
22
|
+
export interface HudAutoOptions {
|
|
23
|
+
/** The app's Convex client, when `convex` is detected: the Convex tab wraps it in place. */
|
|
24
|
+
convex?: ConvexClientLike | undefined;
|
|
25
|
+
/** The app's `QueryClient`, when `@tanstack/react-query` is detected. */
|
|
26
|
+
queryClient?: QueryClientLike | undefined;
|
|
27
|
+
/** The SWR cache and `mutate`, when `swr` is detected. */
|
|
28
|
+
swr?: InspectSwrOptions | undefined;
|
|
29
|
+
/** Passed on to `observe()`: env values and the user hook for the Info tab. */
|
|
30
|
+
observe?: ObserveOptions | undefined;
|
|
31
|
+
/** Passed on to `inspect()`: URLs to leave out of the capture. */
|
|
32
|
+
inspect?: Pick<InspectOptions, "ignore"> | undefined;
|
|
33
|
+
/** Passed on to `a11y()`: your own axe loader. */
|
|
34
|
+
a11y?: A11yOptions | undefined;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* The factories the generated module imports. Base ones are always there;
|
|
38
|
+
* the rest only when detection turned the feature on, so an undetected
|
|
39
|
+
* plugin is not in the module graph.
|
|
40
|
+
*/
|
|
41
|
+
export interface HudAutoFactories {
|
|
42
|
+
vitals: typeof vitals;
|
|
43
|
+
observe: typeof observe;
|
|
44
|
+
inspect: typeof inspect;
|
|
45
|
+
forceState: typeof forceState;
|
|
46
|
+
a11y: typeof a11y;
|
|
47
|
+
seo: typeof seo;
|
|
48
|
+
routes?: typeof routes | undefined;
|
|
49
|
+
data?: typeof data | undefined;
|
|
50
|
+
inspectConvex?: typeof inspectConvex | undefined;
|
|
51
|
+
inspectReactQuery?: typeof inspectReactQuery | undefined;
|
|
52
|
+
inspectSwr?: typeof inspectSwr | undefined;
|
|
53
|
+
}
|
|
54
|
+
/** A tab standing in for a detected adapter whose instance was not passed. */
|
|
55
|
+
export declare function unwired(id: string, title: string, dep: string, hint: string): InspectAdapter;
|
|
56
|
+
/**
|
|
57
|
+
* The plugin list behind `auto()`: the base plugins (vitals, observe, inspect
|
|
58
|
+
* with one tab per detected data source, force-state, a11y, seo), plus
|
|
59
|
+
* routes for a Next app and data where an auth library or MSW is installed.
|
|
60
|
+
* Pill order is this order; `defineHud({ auto, plugins })` replaces an entry
|
|
61
|
+
* by id and appends the rest.
|
|
62
|
+
*/
|
|
63
|
+
export declare function assembleAuto(detected: HudAutoDetected, factories: HudAutoFactories, options?: HudAutoOptions): HudPlugin[];
|
|
64
|
+
//#endregion
|
|
65
|
+
export type { HudAutoDetected };
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
//#region src/auto/runtime.tsx
|
|
3
|
+
/** A tab standing in for a detected adapter whose instance was not passed. */
|
|
4
|
+
function unwired(id, title, dep, hint) {
|
|
5
|
+
return {
|
|
6
|
+
id,
|
|
7
|
+
title,
|
|
8
|
+
Panel: () => /* @__PURE__ */ jsxs("p", {
|
|
9
|
+
className: "empty",
|
|
10
|
+
"data-auto-unwired": id,
|
|
11
|
+
children: [
|
|
12
|
+
/* @__PURE__ */ jsx("code", { children: dep }),
|
|
13
|
+
" is installed. Pass its instance to see it here:",
|
|
14
|
+
" ",
|
|
15
|
+
/* @__PURE__ */ jsxs("code", { children: [
|
|
16
|
+
"auto(",
|
|
17
|
+
`{ ${hint} }`,
|
|
18
|
+
")"
|
|
19
|
+
] })
|
|
20
|
+
]
|
|
21
|
+
})
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* The plugin list behind `auto()`: the base plugins (vitals, observe, inspect
|
|
26
|
+
* with one tab per detected data source, force-state, a11y, seo), plus
|
|
27
|
+
* routes for a Next app and data where an auth library or MSW is installed.
|
|
28
|
+
* Pill order is this order; `defineHud({ auto, plugins })` replaces an entry
|
|
29
|
+
* by id and appends the rest.
|
|
30
|
+
*/
|
|
31
|
+
function assembleAuto(detected, factories, options = {}) {
|
|
32
|
+
const adapters = [];
|
|
33
|
+
if (factories.inspectConvex) adapters.push(options.convex ? factories.inspectConvex({ client: options.convex }) : unwired("convex", "Convex", "convex", "convex: client"));
|
|
34
|
+
if (factories.inspectReactQuery) adapters.push(options.queryClient ? factories.inspectReactQuery({ queryClient: options.queryClient }) : unwired("react-query", "Query", "@tanstack/react-query", "queryClient"));
|
|
35
|
+
if (factories.inspectSwr) adapters.push(options.swr ? factories.inspectSwr(options.swr) : unwired("swr", "SWR", "swr", "swr: { cache, mutate }"));
|
|
36
|
+
const plugins = [
|
|
37
|
+
factories.vitals(),
|
|
38
|
+
factories.observe(options.observe),
|
|
39
|
+
factories.inspect({
|
|
40
|
+
...options.inspect,
|
|
41
|
+
adapters
|
|
42
|
+
})
|
|
43
|
+
];
|
|
44
|
+
if (factories.routes && detected.next) plugins.push(factories.routes());
|
|
45
|
+
if (factories.data && (detected.betterAuth || detected.convexAuth || detected.msw)) plugins.push(factories.data());
|
|
46
|
+
plugins.push(factories.forceState(), factories.a11y(options.a11y), factories.seo());
|
|
47
|
+
return plugins;
|
|
48
|
+
}
|
|
49
|
+
//#endregion
|
|
50
|
+
export { assembleAuto, unwired };
|
package/dist/auto.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { t as HudAutoDetected } from "./detect-BxHZ0pxW.js";
|
|
2
|
+
import { o as HudPlugin } from "./plugins-BZvDqGx5.js";
|
|
3
|
+
import "./index-gCZBO53s.js";
|
|
4
|
+
import { HudAutoFactories, HudAutoOptions } from "./auto/runtime.js";
|
|
5
|
+
//#region src/auto/index.d.ts
|
|
6
|
+
/** Nothing detected: this is the stand-in (`configured: false`). */
|
|
7
|
+
export declare const detected: HudAutoDetected;
|
|
8
|
+
/**
|
|
9
|
+
* The base plugins only. The generated module, served when `hud()` is in
|
|
10
|
+
* vite.config or `withHud()` wraps next.config, adds one inspect tab per
|
|
11
|
+
* detected data source, routes for Next and data for an auth library or MSW.
|
|
12
|
+
*/
|
|
13
|
+
export declare function auto(options?: HudAutoOptions): HudPlugin[];
|
|
14
|
+
//#endregion
|
|
15
|
+
export { type HudAutoDetected, type HudAutoFactories, type HudAutoOptions, auto as default };
|
package/dist/auto.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { t as NOTHING_DETECTED } from "./detect-CHZiSeZs.js";
|
|
2
|
+
import { t as a11y } from "./a11y-B5DUaiCs.js";
|
|
3
|
+
import { t as forceState } from "./design-D0kGgPoP.js";
|
|
4
|
+
import { n as inspect } from "./inspect-C9Ft8fqn.js";
|
|
5
|
+
import { t as observe } from "./observe-CdDnDBRP.js";
|
|
6
|
+
import { t as seo } from "./seo-Dq9q_QkO.js";
|
|
7
|
+
import { vitals } from "./plugins/vitals.js";
|
|
8
|
+
import { assembleAuto } from "./auto/runtime.js";
|
|
9
|
+
//#region src/auto/index.ts
|
|
10
|
+
/** Nothing detected: this is the stand-in (`configured: false`). */
|
|
11
|
+
const detected = NOTHING_DETECTED;
|
|
12
|
+
let warned = false;
|
|
13
|
+
/**
|
|
14
|
+
* The base plugins only. The generated module, served when `hud()` is in
|
|
15
|
+
* vite.config or `withHud()` wraps next.config, adds one inspect tab per
|
|
16
|
+
* detected data source, routes for Next and data for an auth library or MSW.
|
|
17
|
+
*/
|
|
18
|
+
function auto(options) {
|
|
19
|
+
if (!warned) {
|
|
20
|
+
warned = true;
|
|
21
|
+
console.warn("hud: @hansenexus/hud/auto is the stand-in, no bundler plugin read package.json. Add hud() from @hansenexus/hud/vite to vite.config, or wrap next.config with withHud() from @hansenexus/hud/next/config, to enable plugins per dependency.");
|
|
22
|
+
}
|
|
23
|
+
return assembleAuto(detected, {
|
|
24
|
+
vitals,
|
|
25
|
+
observe,
|
|
26
|
+
inspect,
|
|
27
|
+
forceState,
|
|
28
|
+
a11y,
|
|
29
|
+
seo
|
|
30
|
+
}, options);
|
|
31
|
+
}
|
|
32
|
+
//#endregion
|
|
33
|
+
export { auto, auto as default, detected };
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
//#region src/plugins/access/capabilities.ts
|
|
2
|
+
/** The capability vocabulary of the default matrix. Development grants these and any other. */
|
|
3
|
+
const HUD_CAPABILITIES = [
|
|
4
|
+
"observe.app",
|
|
5
|
+
"observe.estate",
|
|
6
|
+
"cicd.read",
|
|
7
|
+
"cicd.trigger",
|
|
8
|
+
"inject.seed",
|
|
9
|
+
"mock.toggle",
|
|
10
|
+
"auth.impersonate",
|
|
11
|
+
"dispatch.local",
|
|
12
|
+
"dispatch.hermes",
|
|
13
|
+
"variants.switch",
|
|
14
|
+
"variants.vote",
|
|
15
|
+
"variants.generate",
|
|
16
|
+
"state.force",
|
|
17
|
+
"routes.read",
|
|
18
|
+
"inspect.read",
|
|
19
|
+
"data.read",
|
|
20
|
+
"data.write",
|
|
21
|
+
"capture.screenshot"
|
|
22
|
+
];
|
|
23
|
+
/**
|
|
24
|
+
* Capabilities no production matrix may grant. `data.*` switches who the
|
|
25
|
+
* page is signed in as and what the app reads: on production that is a
|
|
26
|
+
* breach, not a tool, so `hasCapability` denies it there whatever an app's
|
|
27
|
+
* `matrix` says, and `resolveMatrix` strips it from a production override.
|
|
28
|
+
*/
|
|
29
|
+
function isProductionDenied(capability) {
|
|
30
|
+
return capability.startsWith("data.");
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* The access plugin's own capability. The guard lets the unlock route through
|
|
34
|
+
* on every enabled tier, so it never needs a matrix entry; nothing else may use it.
|
|
35
|
+
*/
|
|
36
|
+
const ACCESS_UNLOCK_CAPABILITY = "access.unlock";
|
|
37
|
+
/**
|
|
38
|
+
* Default-deny capability matrix. Client filtering is convenience only: the
|
|
39
|
+
* guard re-checks every route against the same matrix server side.
|
|
40
|
+
* Staging's `auth.impersonate` is further flag-gated by the plugin that uses it.
|
|
41
|
+
*/
|
|
42
|
+
const CAPABILITY_MATRIX = {
|
|
43
|
+
development: HUD_CAPABILITIES,
|
|
44
|
+
staging: [
|
|
45
|
+
"observe.app",
|
|
46
|
+
"observe.estate",
|
|
47
|
+
"cicd.read",
|
|
48
|
+
"mock.toggle",
|
|
49
|
+
"auth.impersonate",
|
|
50
|
+
"variants.switch",
|
|
51
|
+
"variants.vote",
|
|
52
|
+
"routes.read",
|
|
53
|
+
"inspect.read"
|
|
54
|
+
],
|
|
55
|
+
preview: [
|
|
56
|
+
"observe.app",
|
|
57
|
+
"observe.estate",
|
|
58
|
+
"cicd.read",
|
|
59
|
+
"mock.toggle",
|
|
60
|
+
"variants.switch",
|
|
61
|
+
"variants.vote",
|
|
62
|
+
"routes.read",
|
|
63
|
+
"inspect.read"
|
|
64
|
+
],
|
|
65
|
+
production: [
|
|
66
|
+
"observe.app",
|
|
67
|
+
"observe.estate",
|
|
68
|
+
"cicd.read"
|
|
69
|
+
],
|
|
70
|
+
disabled: []
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* The default matrix with an app's tier lists swapped in. `access.unlock` is
|
|
74
|
+
* stripped from them (it is the guard's exemption, never a grant), and so is
|
|
75
|
+
* `data.*` from production (see `isProductionDenied`).
|
|
76
|
+
*/
|
|
77
|
+
function resolveMatrix(override = {}) {
|
|
78
|
+
const matrix = { ...CAPABILITY_MATRIX };
|
|
79
|
+
for (const [tier, list] of Object.entries(override)) if (list) matrix[tier] = list.filter((capability) => capability !== "access.unlock" && !(tier === "production" && isProductionDenied(capability)));
|
|
80
|
+
return matrix;
|
|
81
|
+
}
|
|
82
|
+
/** Core assumes development, so development grants every capability, listed or not. */
|
|
83
|
+
function hasCapability(env, capability, matrix = CAPABILITY_MATRIX) {
|
|
84
|
+
if (env === "disabled") return false;
|
|
85
|
+
if (env === "development") return true;
|
|
86
|
+
if (env === "production" && isProductionDenied(capability)) return false;
|
|
87
|
+
return matrix[env].includes(capability);
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Whether the HUD exists at all. Outside development a deployed tier also
|
|
91
|
+
* needs its overlay to set `NEXT_PUBLIC_HUD_ENABLED=true`.
|
|
92
|
+
*/
|
|
93
|
+
function isHudVisible(env, enabled = process.env.NEXT_PUBLIC_HUD_ENABLED === "true") {
|
|
94
|
+
if (env === "disabled") return false;
|
|
95
|
+
if (env === "development") return true;
|
|
96
|
+
return enabled;
|
|
97
|
+
}
|
|
98
|
+
const ENVS = [
|
|
99
|
+
"development",
|
|
100
|
+
"preview",
|
|
101
|
+
"staging",
|
|
102
|
+
"production",
|
|
103
|
+
"disabled"
|
|
104
|
+
];
|
|
105
|
+
/** Narrows the loader's env string; anything unrecognised is treated as disabled. */
|
|
106
|
+
function toHudEnv(env) {
|
|
107
|
+
return ENVS.includes(env) ? env : "disabled";
|
|
108
|
+
}
|
|
109
|
+
//#endregion
|
|
110
|
+
export { isHudVisible as a, toHudEnv as c, hasCapability as i, CAPABILITY_MATRIX as n, isProductionDenied as o, HUD_CAPABILITIES as r, resolveMatrix as s, ACCESS_UNLOCK_CAPABILITY as t };
|