devframe 0.9.7 → 0.9.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (116) hide show
  1. package/dist/{_shared-BM3PdYli.mjs → _shared-C08SdQRl.mjs} +15 -4
  2. package/dist/{_shared-BJ6AmwTu.d.mts → _shared-CK3czkH4.d.mts} +25 -2
  3. package/dist/adapters/build.d.mts +6 -6
  4. package/dist/adapters/build.mjs +32 -22
  5. package/dist/adapters/cac.d.mts +16 -1
  6. package/dist/adapters/cac.mjs +8 -7
  7. package/dist/adapters/dev.d.mts +13 -13
  8. package/dist/adapters/dev.mjs +2 -2
  9. package/dist/adapters/embedded.d.mts +1 -1
  10. package/dist/adapters/initiate.d.mts +28 -26
  11. package/dist/adapters/initiate.mjs +1 -1
  12. package/dist/adapters/mcp.d.mts +28 -14
  13. package/dist/adapters/mcp.mjs +75 -39
  14. package/dist/{agent-tool-name-EgfoFO8C.mjs → agent-tool-name-DGzeuWcO.mjs} +2 -2
  15. package/dist/cli/main.d.mts +1 -1
  16. package/dist/cli/main.mjs +41 -17
  17. package/dist/client/index.d.mts +36 -36
  18. package/dist/client/index.mjs +83 -51
  19. package/dist/client-assets-DNdhagGm.mjs +16 -0
  20. package/dist/constants.d.mts +8 -7
  21. package/dist/constants.mjs +7 -6
  22. package/dist/{context-BhBzOXVa.d.mts → context-4AIVRLYF.d.mts} +173 -122
  23. package/dist/{context-omlma_1n.mjs → context-CwPUinjn.mjs} +126 -88
  24. package/dist/{context-KUqAfawQ.mjs → context-DIUvJW4D.mjs} +3 -3
  25. package/dist/{context-HOnG-WvG.d.mts → context-rgBSPFHS.d.mts} +5 -5
  26. package/dist/{crypto-token-XCqTSMg9.mjs → crypto-token-TVbGGFuj.mjs} +1 -1
  27. package/dist/{dev-Czit5IP4.mjs → dev-Eqq5PX0k.mjs} +37 -18
  28. package/dist/{diagnostics-BXWW3VK-.mjs → diagnostics-BMfN8mb1.mjs} +30 -17
  29. package/dist/{diagnostics-CD8nlgll.mjs → diagnostics-D0EVm5M6.mjs} +2 -2
  30. package/dist/{events-4daw0uK9.mjs → events-BV4Dj59a.mjs} +2 -2
  31. package/dist/{host-h3-fRbF9yor.mjs → host-h3-BJ4siyz7.mjs} +1 -1
  32. package/dist/in-page-channel/index.d.mts +59 -22
  33. package/dist/in-page-channel/index.mjs +71 -56
  34. package/dist/{index-BzyopqxV.d.mts → index-pIVt92jP.d.mts} +9 -9
  35. package/dist/{index-DcKxIMoI.d.mts → index-pKl67H6w.d.mts} +4 -4
  36. package/dist/index.d.mts +11 -13
  37. package/dist/index.mjs +6 -7
  38. package/dist/{instance-registry-BjlMQbFB.mjs → instance-registry-C7-41RSp.mjs} +8 -8
  39. package/dist/{instance-shell-Bh4l9Vz_.d.mts → instance-shell-7Z52PE4_.d.mts} +18 -18
  40. package/dist/{instance-shell-CpVW4zG0.mjs → instance-shell-cdVETpfz.mjs} +227 -58
  41. package/dist/internal/index.d.mts +51 -21
  42. package/dist/internal/index.mjs +10 -9
  43. package/dist/node/auth.d.mts +2 -2
  44. package/dist/node/auth.mjs +2 -2
  45. package/dist/node/hub-internals.d.mts +2 -2
  46. package/dist/node/hub-internals.mjs +2 -2
  47. package/dist/node/index.d.mts +5 -5
  48. package/dist/node/index.mjs +2 -2
  49. package/dist/{nostics-SPGDgHEP.d.mts → nostics-0sKe5HIj.d.mts} +2 -2
  50. package/dist/{nostics-CzECRXpE.mjs → nostics-D0PvLZsn.mjs} +1 -1
  51. package/dist/origin-DGDH8BI9.d.mts +45 -0
  52. package/dist/origin-DZit9g29.mjs +80 -0
  53. package/dist/recipes/common-rpc-functions.d.mts +5 -5
  54. package/dist/recipes/common-rpc-functions.mjs +3 -3
  55. package/dist/recipes/interactive-auth.d.mts +6 -6
  56. package/dist/recipes/interactive-auth.mjs +6 -6
  57. package/dist/{remote-assets-DezQmPQU.mjs → remote-assets-BIFWOlBW.mjs} +26 -6
  58. package/dist/{remote-assets-B13_vRkJ.d.mts → remote-assets-eBvSKZMS.d.mts} +7 -7
  59. package/dist/{revoke-COLW0cOi.mjs → revoke-cqztiCX4.mjs} +1 -1
  60. package/dist/rpc/dump.d.mts +2 -11
  61. package/dist/rpc/dump.mjs +1 -1
  62. package/dist/rpc/index.d.mts +2 -2
  63. package/dist/rpc/index.mjs +3 -3
  64. package/dist/rpc/transports/sse-client.d.mts +1 -1
  65. package/dist/rpc/transports/sse-client.mjs +30 -14
  66. package/dist/rpc/transports/sse-server.d.mts +4 -4
  67. package/dist/rpc/transports/sse-server.mjs +7 -7
  68. package/dist/rpc/transports/ws-bun.d.mts +5 -5
  69. package/dist/rpc/transports/ws-bun.mjs +8 -2
  70. package/dist/rpc/transports/ws-client.d.mts +1 -1
  71. package/dist/rpc/transports/ws-client.mjs +2 -2
  72. package/dist/rpc/transports/ws-deno.d.mts +4 -4
  73. package/dist/rpc/transports/ws-deno.mjs +8 -2
  74. package/dist/rpc/transports/ws-server.d.mts +2 -1
  75. package/dist/rpc/transports/ws-server.mjs +232 -1
  76. package/dist/{rpc-core-BHUsDl7s.d.mts → rpc-core-Ceu6AUz8.d.mts} +4 -4
  77. package/dist/{rpc-core-DlHd276T.mjs → rpc-core-DVQ7xi89.mjs} +14 -2
  78. package/dist/{serialization-BGzEwAdr.mjs → serialization-DTZnPQ1-.mjs} +20 -18
  79. package/dist/{services-install-CqqQVls5.mjs → services-install-P_DV7VYL.mjs} +32 -21
  80. package/dist/session-DPfj6zQG.mjs +16 -0
  81. package/dist/{shared-state-DoXutg_U.mjs → shared-state-CaxB1q0h.mjs} +4 -3
  82. package/dist/{simple-schema-DQPZrAaZ.mjs → simple-schema-Bi40l-P6.mjs} +2 -2
  83. package/dist/{sse-client-DwX021ST.d.mts → sse-client-BQ4jS3eO.d.mts} +4 -4
  84. package/dist/{state-CK9LjrnT.mjs → state-CeQQWzM-.mjs} +4 -4
  85. package/dist/{static-DV_qUSRS.mjs → static-DZ8P2Kn7.mjs} +130 -135
  86. package/dist/{storage-BXNVhKyR.mjs → storage-Dccf_IyD.mjs} +1 -1
  87. package/dist/types/index.d.mts +6 -6
  88. package/dist/{types-CMdPYhOx.d.mts → types-Dq4i156u.d.mts} +17 -17
  89. package/dist/utils/agent-tool-name.d.mts +2 -2
  90. package/dist/utils/agent-tool-name.mjs +2 -2
  91. package/dist/utils/colors.d.mts +1 -1
  92. package/dist/utils/crypto-token.d.mts +1 -1
  93. package/dist/utils/crypto-token.mjs +1 -1
  94. package/dist/utils/events.d.mts +1 -1
  95. package/dist/utils/nostics.d.mts +1 -1
  96. package/dist/utils/nostics.mjs +1 -1
  97. package/dist/utils/open.mjs +1 -1
  98. package/dist/utils/origin.d.mts +2 -0
  99. package/dist/utils/origin.mjs +80 -0
  100. package/dist/utils/remote-assets.d.mts +2 -2
  101. package/dist/utils/remote-assets.mjs +1 -1
  102. package/dist/utils/serve-static.d.mts +4 -4
  103. package/dist/utils/serve-static.mjs +56 -19
  104. package/dist/utils/shared-state.d.mts +1 -1
  105. package/dist/utils/shared-state.mjs +1 -1
  106. package/dist/utils/simple-schema.d.mts +5 -5
  107. package/dist/utils/simple-schema.mjs +2 -2
  108. package/dist/utils/streaming-channel.d.mts +1 -1
  109. package/dist/utils/streaming-channel.mjs +2 -2
  110. package/dist/utils/when.d.mts +5 -5
  111. package/dist/{validation-YrZH6atx.mjs → validation-BOy8IoFZ.mjs} +2 -2
  112. package/dist/{wire-codec-0K-o5MYW.mjs → wire-codec-dcCeXcSo.mjs} +3 -3
  113. package/dist/{ws-client-7_lZi-B9.d.mts → ws-client-Xpxt0oPA.d.mts} +3 -3
  114. package/dist/{ws-server-Di2oqr4q.d.mts → ws-server-D2nv68Hg.d.mts} +13 -22
  115. package/package.json +6 -5
  116. package/dist/ws-server-BdSLrhxE.mjs +0 -267
@@ -0,0 +1,80 @@
1
+ //#region src/utils/origin.ts
2
+ /**
3
+ * Origin and hostname predicates shared by the RPC transports (the WS upgrade,
4
+ * SSE, and MCP origin gates) and the instance shell's authentication-link
5
+ * origin validation. Kept dependency-free and runtime-agnostic so any consumer
6
+ * can pull in a single check without dragging in a transport's `crossws`
7
+ * import.
8
+ */
9
+ /**
10
+ * Whether `hostname` names a loopback host: `localhost` (or any `*.localhost`
11
+ * subdomain), the IPv6 loopback `::1`, or an IPv4 literal inside the
12
+ * `127.0.0.0/8` loopback block.
13
+ *
14
+ * The IPv4 case is matched **structurally**: the whole hostname must be a
15
+ * canonical dotted-decimal IPv4 literal whose first octet is `127`. A bare
16
+ * `startsWith('127.')` prefix check would also accept an attacker-controlled
17
+ * DNS name that merely *begins* with `127.` (`127.attacker.example`,
18
+ * `127.0.0.1.attacker.example`), letting a cross-origin browser page defeat
19
+ * the loopback origin gate that guards the RPC/MCP surface (a DNS-rebinding /
20
+ * cross-site WebSocket-hijacking bypass). Requiring a real IPv4 literal keeps
21
+ * genuine loopback addresses (`127.0.0.1`, `127.5.5.5`) allowed while rejecting
22
+ * those DNS names.
23
+ */
24
+ function isLoopbackHostname(hostname) {
25
+ const h = hostname.replace(/^\[|\]$/g, "");
26
+ if (h === "localhost" || h.endsWith(".localhost") || h === "::1") return true;
27
+ return isLoopbackIPv4(h);
28
+ }
29
+ /** A canonical dotted-decimal IPv4 literal in `127.0.0.0/8`. */
30
+ function isLoopbackIPv4(hostname) {
31
+ const octets = hostname.split(".");
32
+ if (octets.length !== 4 || !octets.every(isDecimalOctet)) return false;
33
+ return Number(octets[0]) === 127;
34
+ }
35
+ /** A single canonical IPv4 octet: 1–3 digits, no leading zero, value 0–255. */
36
+ function isDecimalOctet(part) {
37
+ if (!/^\d{1,3}$/.test(part) || part.length > 1 && part[0] === "0") return false;
38
+ return Number(part) <= 255;
39
+ }
40
+ /**
41
+ * Default origin policy for a localhost dev tool: allow requests with no
42
+ * `Origin` header (native, non-browser clients), allow any loopback origin
43
+ * (so cross-port localhost dev setups keep working), and allow explicitly
44
+ * configured origins. Everything else, such as a real remote page in the dev's
45
+ * browser, is rejected.
46
+ */
47
+ function isAllowedOrigin(origin, allowedOrigins) {
48
+ if (!origin) return true;
49
+ if (allowedOrigins.includes(origin)) return true;
50
+ try {
51
+ return isLoopbackHostname(new URL(origin).hostname);
52
+ } catch {
53
+ return false;
54
+ }
55
+ }
56
+ /**
57
+ * Decide whether a request-derived origin candidate may back a devframe's
58
+ * advertised public origin, the destination of the OTP magic link. Stricter
59
+ * than {@link isAllowedOrigin}: it rejects credentials, a path, a query, a
60
+ * fragment, a malformed port, and non-HTTP(S) schemes, and adopts a candidate
61
+ * only when its hostname is loopback or its canonical origin exactly matches
62
+ * an `allowedOrigins` entry (a caller with no static list passes none, so only
63
+ * loopback qualifies). Returns the canonical origin to adopt, or `undefined`
64
+ * to reject. Forwarded headers are never consulted.
65
+ */
66
+ function validateOriginCandidate(candidate, allowedOrigins) {
67
+ let url;
68
+ try {
69
+ url = new URL(candidate);
70
+ } catch {
71
+ return;
72
+ }
73
+ if (url.protocol !== "http:" && url.protocol !== "https:") return void 0;
74
+ if (url.username || url.password || url.search || url.hash || url.pathname !== "/" && url.pathname !== "") return void 0;
75
+ const canonical = url.origin;
76
+ if (canonical === "null") return void 0;
77
+ if (isLoopbackHostname(url.hostname) || allowedOrigins?.includes(canonical)) return canonical;
78
+ }
79
+ //#endregion
80
+ export { isAllowedOrigin, isLoopbackHostname, validateOriginCandidate };
@@ -1,4 +1,4 @@
1
- import { a as RemoteAssetsStore, o as StaticAssetsSource } from "../remote-assets-B13_vRkJ.mjs";
1
+ import { a as RemoteAssetsStore, o as StaticAssetsSource } from "../remote-assets-eBvSKZMS.mjs";
2
2
  //#region src/utils/remote-assets.d.ts
3
3
  /**
4
4
  * Normalize a {@link StaticAssetsSource} into something servable: a local
@@ -7,7 +7,7 @@ import { a as RemoteAssetsStore, o as StaticAssetsSource } from "../remote-asset
7
7
  * {@link RemoteAssetsStore} back-proxy. Remote caches live under
8
8
  * `<projectStorageDir>/.remote-assets/<package>@<version>/`.
9
9
  *
10
- * A remote source's `package`/`version` are validated first (`DF0065`) — both
10
+ * A remote source's `package`/`version` are validated first (`DF0065`); both
11
11
  * are interpolated into CDN URLs and the cache path.
12
12
  *
13
13
  * `defaultResolveFrom` (typically the declaring devframe's `importMetaUrl`)
@@ -1,2 +1,2 @@
1
- import { t as resolveStaticAssetsSource } from "../remote-assets-DezQmPQU.mjs";
1
+ import { t as resolveStaticAssetsSource } from "../remote-assets-BIFWOlBW.mjs";
2
2
  export { resolveStaticAssetsSource };
@@ -1,4 +1,4 @@
1
- import { a as RemoteAssetsStore } from "../remote-assets-B13_vRkJ.mjs";
1
+ import { a as RemoteAssetsStore } from "../remote-assets-eBvSKZMS.mjs";
2
2
  import { IncomingMessage, ServerResponse } from "node:http";
3
3
  import { EventHandler, H3 } from "h3";
4
4
  //#region src/utils/serve-static.d.ts
@@ -14,12 +14,12 @@ interface ServeStaticOptions {
14
14
  single?: boolean;
15
15
  }
16
16
  /**
17
- * h3 event handler that serves files from `source` with SPA fallback — a
17
+ * h3 event handler that serves files from `source` with SPA fallback: a
18
18
  * local directory, or a {@link RemoteAssetsStore} whose files stream through
19
19
  * the CDN back-proxy into the local cache.
20
20
  *
21
21
  * Drop-in replacement for `fromNodeMiddleware(sirv(dir, { dev: true, single: true }))`
22
- * when the surrounding server is an h3 app — no `Cache-Control` beyond
22
+ * when the surrounding server is an h3 app: no `Cache-Control` beyond
23
23
  * `no-store`, `Content-Type` resolved via `mrmime`, and a miss with no
24
24
  * file extension falls back to `<dir>/index.html` so client-side routing
25
25
  * works.
@@ -37,7 +37,7 @@ declare function mountStaticHandler(app: H3, base: string, source: ServableAsset
37
37
  * Connect/Express-style Node middleware variant of {@link serveStaticHandler}.
38
38
  *
39
39
  * Use when mounting onto `viteServer.middlewares.use(base, …)` or any other
40
- * Connect stack — avoids forcing the host package to depend on h3 just to
40
+ * Connect stack; avoids forcing the host package to depend on h3 just to
41
41
  * adapt an event handler back into Node middleware.
42
42
  */
43
43
  declare function serveStaticNodeMiddleware(source: ServableAssets, options?: ServeStaticOptions): (req: IncomingMessage, res: ServerResponse, next?: (err?: Error) => void) => void;
@@ -1,16 +1,30 @@
1
- import { t as DEVFRAME_EVENTS } from "../events-4daw0uK9.mjs";
1
+ import { t as DEVFRAME_EVENTS } from "../events-BV4Dj59a.mjs";
2
2
  import { extname, join, normalize, resolve, sep } from "pathe";
3
3
  import { createReadStream } from "node:fs";
4
- import { stat } from "node:fs/promises";
4
+ import { realpath, stat } from "node:fs/promises";
5
5
  import { Readable } from "node:stream";
6
6
  import { lookup } from "mrmime";
7
7
  import { H3, defineHandler } from "h3";
8
8
  //#region src/utils/serve-static.ts
9
9
  const HTML_EXTENSIONS = [".html", ".htm"];
10
- async function statFile(abs) {
10
+ /**
11
+ * The canonical (symlink-resolved) served root, falling back to the lexical
12
+ * path when the directory doesn't exist yet (an empty deployment then serves
13
+ * nothing rather than throwing).
14
+ */
15
+ async function canonicalRoot(absDir) {
16
+ return realpath(absDir).then(normalize, () => absDir);
17
+ }
18
+ /**
19
+ * Stat a candidate file, confirming its canonical target stays inside the
20
+ * canonical served root; a symlink inside the root can only resolve to a
21
+ * file still within it; one escaping the root reads as a miss, not a leak.
22
+ */
23
+ async function statFile(abs, realRoot) {
11
24
  try {
12
25
  const s = await stat(abs);
13
- if (!s.isFile()) return null;
26
+ const real = normalize(await realpath(abs));
27
+ if (!s.isFile() || real !== realRoot && !real.startsWith(realRoot + sep)) return null;
14
28
  return {
15
29
  abs,
16
30
  size: s.size,
@@ -20,7 +34,7 @@ async function statFile(abs) {
20
34
  return null;
21
35
  }
22
36
  }
23
- async function resolveTarget(absDir, urlPath, indexNames, single) {
37
+ function cleanUrlPath(urlPath) {
24
38
  let cleaned;
25
39
  try {
26
40
  cleaned = decodeURIComponent(urlPath || "/");
@@ -30,23 +44,44 @@ async function resolveTarget(absDir, urlPath, indexNames, single) {
30
44
  cleaned = cleaned.replace(/[?#].*$/, "");
31
45
  if (cleaned.endsWith("/")) cleaned = cleaned.slice(0, -1);
32
46
  if (cleaned.startsWith("/")) cleaned = cleaned.slice(1);
33
- const abs = normalize(join(absDir, cleaned));
34
- if (abs !== absDir && !abs.startsWith(absDir + sep)) return null;
35
- const direct = await statFile(abs);
36
- if (direct) return direct;
47
+ return cleaned;
48
+ }
49
+ async function resolveDirectoryIndex(abs, realRoot, indexNames) {
37
50
  try {
38
51
  if ((await stat(abs)).isDirectory()) for (const name of indexNames) {
39
- const candidate = await statFile(join(abs, name));
52
+ const candidate = await statFile(join(abs, name), realRoot);
40
53
  if (candidate) return candidate;
41
54
  }
42
55
  } catch {}
43
- if (!extname(cleaned)) for (const ext of HTML_EXTENSIONS) {
44
- const candidate = await statFile(abs + ext);
56
+ return null;
57
+ }
58
+ /**
59
+ * Mirror sirv's `extensions: ['html', 'htm']` default: an extension-less
60
+ * request tries `${path}.html` / `${path}.htm` so pretty-URL deployments
61
+ * resolve to the right page before the SPA fallback.
62
+ */
63
+ async function resolveHtmlExtension(abs, cleaned, realRoot) {
64
+ if (extname(cleaned)) return null;
65
+ for (const ext of HTML_EXTENSIONS) {
66
+ const candidate = await statFile(abs + ext, realRoot);
45
67
  if (candidate) return candidate;
46
68
  }
69
+ return null;
70
+ }
71
+ async function resolveTarget(absDir, realRoot, urlPath, indexNames, single) {
72
+ const cleaned = cleanUrlPath(urlPath);
73
+ if (cleaned === null) return null;
74
+ const abs = normalize(join(absDir, cleaned));
75
+ if (abs !== absDir && !abs.startsWith(absDir + sep)) return null;
76
+ const direct = await statFile(abs, realRoot);
77
+ if (direct) return direct;
78
+ const indexed = await resolveDirectoryIndex(abs, realRoot, indexNames);
79
+ if (indexed) return indexed;
80
+ const htmlExt = await resolveHtmlExtension(abs, cleaned, realRoot);
81
+ if (htmlExt) return htmlExt;
47
82
  const fallbackIndex = indexNames[0];
48
83
  if (single && fallbackIndex && !/\.[a-z0-9]+$/i.test(cleaned)) {
49
- const indexFile = await statFile(join(absDir, fallbackIndex));
84
+ const indexFile = await statFile(join(absDir, fallbackIndex), realRoot);
50
85
  if (indexFile) return indexFile;
51
86
  }
52
87
  return null;
@@ -77,7 +112,7 @@ function normalizeOptions(options) {
77
112
  /**
78
113
  * Drive one request through a {@link RemoteAssetsStore}: the store's
79
114
  * `Response` on a hit, a 404 on a miss, or a 502 (styled error page for HTML
80
- * navigations) on provider failure — shared between the h3 and connect flavors.
115
+ * navigations) on provider failure, shared between the h3 and connect flavors.
81
116
  */
82
117
  async function remoteResponse(store, urlPath, accept) {
83
118
  try {
@@ -109,12 +144,12 @@ function serveRemoteAssetsHandler(store) {
109
144
  });
110
145
  }
111
146
  /**
112
- * h3 event handler that serves files from `source` with SPA fallback — a
147
+ * h3 event handler that serves files from `source` with SPA fallback: a
113
148
  * local directory, or a {@link RemoteAssetsStore} whose files stream through
114
149
  * the CDN back-proxy into the local cache.
115
150
  *
116
151
  * Drop-in replacement for `fromNodeMiddleware(sirv(dir, { dev: true, single: true }))`
117
- * when the surrounding server is an h3 app — no `Cache-Control` beyond
152
+ * when the surrounding server is an h3 app: no `Cache-Control` beyond
118
153
  * `no-store`, `Content-Type` resolved via `mrmime`, and a miss with no
119
154
  * file extension falls back to `<dir>/index.html` so client-side routing
120
155
  * works.
@@ -123,6 +158,7 @@ function serveStaticHandler(source, options) {
123
158
  if (typeof source !== "string") return serveRemoteAssetsHandler(source);
124
159
  const absDir = resolve(source);
125
160
  const opts = normalizeOptions(options);
161
+ const realRoot = canonicalRoot(absDir);
126
162
  return defineHandler(async (event) => {
127
163
  const method = event.req.method;
128
164
  if (method !== "GET" && method !== "HEAD") {
@@ -130,7 +166,7 @@ function serveStaticHandler(source, options) {
130
166
  event.res.headers.set("Allow", "GET, HEAD");
131
167
  return "";
132
168
  }
133
- const file = await resolveTarget(absDir, event.url.pathname, opts.indexNames, opts.single);
169
+ const file = await resolveTarget(absDir, await realRoot, event.url.pathname, opts.indexNames, opts.single);
134
170
  if (!file) {
135
171
  event.res.status = 404;
136
172
  return "";
@@ -156,12 +192,13 @@ function mountStaticHandler(app, base, source, options) {
156
192
  * Connect/Express-style Node middleware variant of {@link serveStaticHandler}.
157
193
  *
158
194
  * Use when mounting onto `viteServer.middlewares.use(base, …)` or any other
159
- * Connect stack — avoids forcing the host package to depend on h3 just to
195
+ * Connect stack; avoids forcing the host package to depend on h3 just to
160
196
  * adapt an event handler back into Node middleware.
161
197
  */
162
198
  function serveStaticNodeMiddleware(source, options) {
163
199
  const absDir = typeof source === "string" ? resolve(source) : void 0;
164
200
  const opts = normalizeOptions(options);
201
+ const realRoot = absDir === void 0 ? void 0 : canonicalRoot(absDir);
165
202
  return (req, res, next) => {
166
203
  (async () => {
167
204
  const method = req.method;
@@ -192,7 +229,7 @@ function serveStaticNodeMiddleware(source, options) {
192
229
  Readable.fromWeb(response.body).pipe(res);
193
230
  return;
194
231
  }
195
- const file = await resolveTarget(absDir, url, opts.indexNames, opts.single);
232
+ const file = await resolveTarget(absDir, await realRoot, url, opts.indexNames, opts.single);
196
233
  if (!file) {
197
234
  if (next) {
198
235
  next();
@@ -1,2 +1,2 @@
1
- import { A as SharedStateEvents, D as ImmutableObject, E as ImmutableMap, M as SharedStatePatch, N as createSharedState, O as ImmutableSet, T as ImmutableArray, j as SharedStateOptions, k as SharedState, w as Immutable } from "../context-BhBzOXVa.mjs";
1
+ import { A as SharedStateEvents, D as ImmutableObject, E as ImmutableMap, M as SharedStatePatch, N as createSharedState, O as ImmutableSet, T as ImmutableArray, j as SharedStateOptions, k as SharedState, w as Immutable } from "../context-4AIVRLYF.mjs";
2
2
  export { Immutable, ImmutableArray, ImmutableMap, ImmutableObject, ImmutableSet, SharedState, SharedStateEvents, SharedStateOptions, SharedStatePatch, createSharedState };
@@ -1,2 +1,2 @@
1
- import { t as createSharedState } from "../shared-state-DoXutg_U.mjs";
1
+ import { t as createSharedState } from "../shared-state-CaxB1q0h.mjs";
2
2
  export { createSharedState };
@@ -8,10 +8,10 @@ import { StandardSchemaV1 } from "@standard-schema/spec";
8
8
  * best-effort validator that exists only so devframe's own first-party
9
9
  * packages (recipes, built-in plugins) can declare `args`/`returns`/flag
10
10
  * schemas without taking on a validator dependency. It implements a small
11
- * subset of primitives and approximates refinements — it is not a
11
+ * subset of primitives and approximates refinements; it is not a
12
12
  * general-purpose validator.
13
13
  *
14
- * For your own code, prefer a real Standard Schema validator — **valibot**,
14
+ * For your own code, prefer a real Standard Schema validator: **valibot**,
15
15
  * **zod**, or **arktype**. Devframe's RPC and CLI-flag layers accept any of
16
16
  * them; install the one you like and use it directly:
17
17
  *
@@ -46,7 +46,7 @@ declare function string(): SimpleSchema<string>;
46
46
  declare function number(): SimpleSchema<number>;
47
47
  /** A boolean. */
48
48
  declare function boolean(): SimpleSchema<boolean>;
49
- /** `undefined` — mirrors valibot's `void`. */
49
+ /** `undefined`, mirroring valibot's `void`. */
50
50
  declare function voidType(): SimpleSchema<void>;
51
51
  /** `null`. */
52
52
  declare function nullType(): SimpleSchema<null>;
@@ -64,7 +64,7 @@ declare function array<T extends StandardSchemaV1>(item: T): SimpleSchema<Standa
64
64
  type Prettify<T> = { [K in keyof T]: T[K]; } & {};
65
65
  /**
66
66
  * Map a shape to its object type, turning fields whose type includes
67
- * `undefined` (i.e. `optional()`) into optional keys — mirroring how
67
+ * `undefined` (i.e. `optional()`) into optional keys, mirroring how
68
68
  * valibot/zod render `optional` object entries.
69
69
  */
70
70
  type InferField<T extends StandardSchemaV1, Mode extends 'input' | 'output'> = Mode extends 'input' ? StandardSchemaV1.InferInput<T> : StandardSchemaV1.InferOutput<T>;
@@ -78,7 +78,7 @@ declare function nullable<T extends StandardSchemaV1>(inner: T): SimpleSchema<St
78
78
  /** Attach a human-readable description (used for CLI option help). */
79
79
  declare function describe<T extends SimpleSchema<any, any>>(schema: T, description: string): T;
80
80
  /**
81
- * Grouped access to every builder — `s.string()`, `s.object({ ... })`,
81
+ * Grouped access to every builder: `s.string()`, `s.object({ ... })`,
82
82
  * `s.void()`, etc. Handy for a valibot-like `import { s } from
83
83
  * 'devframe/utils/simple-schema'` call site.
84
84
  */
@@ -37,7 +37,7 @@ function number() {
37
37
  function boolean() {
38
38
  return make("boolean", (v) => typeof v === "boolean" ? ok(v) : fail("Expected a boolean"));
39
39
  }
40
- /** `undefined` — mirrors valibot's `void`. */
40
+ /** `undefined`, mirroring valibot's `void`. */
41
41
  function voidType() {
42
42
  return make("void", (v) => v === void 0 ? ok(void 0) : fail("Expected undefined"));
43
43
  }
@@ -130,7 +130,7 @@ function describe(schema, description) {
130
130
  };
131
131
  }
132
132
  /**
133
- * Grouped access to every builder — `s.string()`, `s.object({ ... })`,
133
+ * Grouped access to every builder: `s.string()`, `s.object({ ... })`,
134
134
  * `s.void()`, etc. Handy for a valibot-like `import { s } from
135
135
  * 'devframe/utils/simple-schema'` call site.
136
136
  */
@@ -1,2 +1,2 @@
1
- import { C as createStreamSink, S as createStreamReader, _ as CreateStreamSinkOptions, b as StreamSink, g as CreateStreamReaderOptions, h as BufferedChunk, v as StreamErrorPayload, x as StreamSinkEvents, y as StreamReader } from "../context-BhBzOXVa.mjs";
1
+ import { C as createStreamSink, S as createStreamReader, _ as CreateStreamSinkOptions, b as StreamSink, g as CreateStreamReaderOptions, h as BufferedChunk, v as StreamErrorPayload, x as StreamSinkEvents, y as StreamReader } from "../context-4AIVRLYF.mjs";
2
2
  export { BufferedChunk, CreateStreamReaderOptions, CreateStreamSinkOptions, StreamErrorPayload, StreamReader, StreamSink, StreamSinkEvents, createStreamReader, createStreamSink };
@@ -6,7 +6,7 @@ var StreamClosedError = class extends Error {
6
6
  name = "StreamClosedError";
7
7
  };
8
8
  /**
9
- * Build a server-side stream sink. RPC-agnostic — the RPC host wires
9
+ * Build a server-side stream sink. RPC-agnostic; the RPC host wires
10
10
  * `events.on('chunk' | 'end')` to broadcast, and reads `buffer` to replay
11
11
  * for late or reconnecting subscribers.
12
12
  */
@@ -77,7 +77,7 @@ function createStreamSink(options = {}) {
77
77
  };
78
78
  }
79
79
  /**
80
- * Build a client-side stream reader. RPC-agnostic — the RPC host calls
80
+ * Build a client-side stream reader. RPC-agnostic; the RPC host calls
81
81
  * `_push(seq, chunk)` on each incoming chunk and `_end(error?)` on the
82
82
  * terminal frame. Consumers iterate with `for await` or pipe `readable`.
83
83
  */
@@ -4,13 +4,13 @@ import { WhenExpression as WhenExpression$1 } from "whenexpr";
4
4
  * Context object for evaluating `when` expressions.
5
5
  *
6
6
  * Built-in variables:
7
- * - `clientType` — `'embedded' | 'standalone'`
8
- * - `dockOpen` — whether the dock panel is open
9
- * - `paletteOpen` — whether the command palette is open
10
- * - `dockSelectedId` — ID of the selected dock entry (empty string if none)
7
+ * - `clientType`: `'embedded' | 'standalone'`
8
+ * - `dockOpen`: whether the dock panel is open
9
+ * - `paletteOpen`: whether the command palette is open
10
+ * - `dockSelectedId`: ID of the selected dock entry (empty string if none)
11
11
  *
12
12
  * Plugins can add namespaced variables using dot or colon separators:
13
- * - `vite.mode`, `vite:mode` — stored as `{ 'vite.mode': 'development' }` or nested `{ vite: { mode: 'development' } }`
13
+ * - `vite.mode`, `vite:mode`: stored as `{ 'vite.mode': 'development' }` or nested `{ vite: { mode: 'development' } }`
14
14
  *
15
15
  * Supported operators: `!`, `==`, `!=`, `===`, `!==`, `<`, `<=`, `>`, `>=`,
16
16
  * `&&`, `||`, `+`, `-`, `*`, `/`, `%`. Parentheses, number and string literals
@@ -1,4 +1,4 @@
1
- import { t as diagnostics } from "./diagnostics-CD8nlgll.mjs";
1
+ import { t as diagnostics } from "./diagnostics-D0EVm5M6.mjs";
2
2
  import { createHash } from "node:crypto";
3
3
  //#region ../../node_modules/.pnpm/ohash@2.0.12/node_modules/ohash/dist/_chunks/is-equal.mjs
4
4
  function serialize(input) {
@@ -220,7 +220,7 @@ async function validateRpcArgs(name, argsSchema, args) {
220
220
  /**
221
221
  * Validate a handler's resolved return value against its declared schema.
222
222
  * Throws `DF0039` when the value fails the schema, otherwise returns the
223
- * original value unchanged (guard-only, never rewriting the payload — see
223
+ * original value unchanged (guard-only, never rewriting the payload; see
224
224
  * {@link validateRpcArgs}). Passes through when no return schema is set.
225
225
  *
226
226
  * @internal
@@ -1,4 +1,4 @@
1
- import { n as strictJsonStringify } from "./serialization-BGzEwAdr.mjs";
1
+ import { n as strictJsonStringify } from "./serialization-DTZnPQ1-.mjs";
2
2
  import { n as structuredCloneStringify, t as structuredCloneParse } from "./structured-clone-CbAV5rFI.mjs";
3
3
  //#region src/rpc/wire-codec.ts
4
4
  const EMPTY_WIRE_DEFS = /* @__PURE__ */ new Map();
@@ -8,7 +8,7 @@ const EMPTY_WIRE_DEFS = /* @__PURE__ */ new Map();
8
8
  * JSON (methods declared `jsonSerializable: true`) and `s:`-prefixed
9
9
  * structured-clone (everything else, including all error envelopes), with a
10
10
  * request-id → method map so a response independently picks the same
11
- * encoder as its request. One codec per connection — request-id spaces
11
+ * encoder as its request. One codec per connection; request-id spaces
12
12
  * don't collide across connections.
13
13
  *
14
14
  * @internal
@@ -35,7 +35,7 @@ function createRpcWireCodec(definitions = EMPTY_WIRE_DEFS) {
35
35
  }
36
36
  /**
37
37
  * Peek at a wire frame's birpc envelope without engaging a codec's
38
- * request-id bookkeeping — used by the SSE transport to route a frame
38
+ * request-id bookkeeping; used by the SSE transport to route a frame
39
39
  * (park a POST for its response / answer with a bare 202) before it is
40
40
  * handed to birpc proper.
41
41
  *
@@ -1,4 +1,4 @@
1
- import { v as RpcFunctionDefinitionAny } from "./types-CMdPYhOx.mjs";
1
+ import { v as RpcFunctionDefinitionAny } from "./types-Dq4i156u.mjs";
2
2
  import { ChannelOptions } from "birpc";
3
3
  //#region src/rpc/transports/ws-client.d.ts
4
4
  interface WsRpcChannelOptions {
@@ -10,7 +10,7 @@ interface WsRpcChannelOptions {
10
10
  /**
11
11
  * RPC function definitions (or just the `jsonSerializable` flag per
12
12
  * method) used to dispatch the per-call wire serializer. Pass an
13
- * empty / partial map on clients that don't have the full registry —
13
+ * empty / partial map on clients that don't have the full registry;
14
14
  * encoding falls back to structured-clone (the safer superset) and
15
15
  * decoding still routes correctly via the wire prefix.
16
16
  */
@@ -20,7 +20,7 @@ interface WsRpcChannelOptions {
20
20
  * Build a birpc `ChannelOptions` object backed by a browser `WebSocket`.
21
21
  * Pass the result straight to `createRpcClient`'s `channel` option.
22
22
  *
23
- * Also returns `close()`, closing the underlying socket — mirroring the server transport's
23
+ * Also returns `close()`, closing the underlying socket, mirroring the server transport's
24
24
  * existing `WsRpcTransport.close()`. `birpc`'s own `ChannelOptions` has no teardown of its own.
25
25
  */
26
26
  declare function createWsRpcChannel(options: WsRpcChannelOptions): ChannelOptions & {
@@ -1,4 +1,4 @@
1
- import { v as RpcFunctionDefinitionAny } from "./types-CMdPYhOx.mjs";
1
+ import { v as RpcFunctionDefinitionAny } from "./types-Dq4i156u.mjs";
2
2
  import { BirpcGroup, ChannelOptions } from "birpc";
3
3
  import { Hooks, Peer } from "crossws";
4
4
  import { NodeAdapter } from "crossws/adapters/node";
@@ -16,8 +16,8 @@ import { Duplex } from "node:stream";
16
16
  */
17
17
  type DevframeRpcTransportKind = 'websocket' | 'sse';
18
18
  /**
19
- * Structural view of the connect-time HTTP request behind an RPC connection
20
- * — the WS upgrade request, or the request opening an SSE stream. Shaped to
19
+ * Structural view of the connect-time HTTP request behind an RPC connection:
20
+ * the WS upgrade request, or the request opening an SSE stream. Shaped to
21
21
  * match both the web `Request` a crossws peer exposes and a plain
22
22
  * `node:http` request wrapper, so auth hooks can read the bearer-token
23
23
  * query param and the `Origin` header without caring which transport (or
@@ -38,7 +38,7 @@ interface DevframeRpcConnectionRequest {
38
38
  * (`onPeerConnect` / `onPeerDisconnect`, {@link DevframeAuthHandler.onConnect}).
39
39
  */
40
40
  interface DevframeRpcConnection {
41
- /** Session id — the same value as the session meta's `id`. */
41
+ /** Session id, the same value as the session meta's `id`. */
42
42
  id: number;
43
43
  /** The transport carrying this connection. */
44
44
  transport: DevframeRpcTransportKind;
@@ -49,7 +49,7 @@ interface DevframeRpcConnection {
49
49
  /** Terminate the connection from the server side. */
50
50
  close?: (code?: number, reason?: string) => void;
51
51
  /**
52
- * The crossws peer backing a `websocket` connection — the WS-specific
52
+ * The crossws peer backing a `websocket` connection: the WS-specific
53
53
  * escape hatch (pub/sub, raw socket access). Absent on other transports.
54
54
  */
55
55
  peer?: Peer;
@@ -81,7 +81,7 @@ interface WsRpcTransportOptions {
81
81
  * Attach to an existing HTTP(S) server, sharing its port. Combine with
82
82
  * `path` to bind the WS endpoint to a single route so it coexists with
83
83
  * other upgrade handlers on the same server (e.g. a Vite dev server's HMR
84
- * socket). The shared server's lifecycle is owned by the caller — closing
84
+ * socket). The shared server's lifecycle is owned by the caller; closing
85
85
  * this transport detaches the upgrade listener without closing the server.
86
86
  */
87
87
  server?: Server | Server$1;
@@ -130,7 +130,7 @@ interface WsRpcTransportOptions {
130
130
  * dispatch between strict-JSON and structured-clone encoding based
131
131
  * on each function's `jsonSerializable` flag.
132
132
  *
133
- * When omitted, all messages fall back to structured-clone — safe but
133
+ * When omitted, all messages fall back to structured-clone: safe but
134
134
  * loses dev-time validation for `jsonSerializable: true` declarations.
135
135
  */
136
136
  definitions?: ReadonlyMap<string, Pick<RpcFunctionDefinitionAny, 'jsonSerializable'>>;
@@ -164,7 +164,7 @@ interface WsOriginRegistry {
164
164
  declare function createWsOriginRegistry(options?: CreateWsOriginRegistryOptions): WsOriginRegistry;
165
165
  interface WsRpcTransport {
166
166
  /**
167
- * The crossws node adapter driving the socket — exposes the connected
167
+ * The crossws node adapter driving the socket; exposes the connected
168
168
  * `peers` and pub/sub. See https://crossws.h3.dev.
169
169
  */
170
170
  ws: NodeAdapter;
@@ -175,15 +175,15 @@ interface WsRpcTransport {
175
175
  /**
176
176
  * Complete a `node:http` `upgrade` event on this transport, applying the
177
177
  * same `path` filter and origin gate the transport's own listener uses.
178
- * Wire it into a host server directly — `server.on('upgrade',
179
- * transport.handleUpgrade)` — or call it from an existing listener.
178
+ * Wire it into a host server directly (`server.on('upgrade',
179
+ * transport.handleUpgrade)`) or call it from an existing listener.
180
180
  */
181
181
  handleUpgrade: (req: IncomingMessage, socket: Duplex, head: Buffer) => void;
182
182
  /**
183
183
  * Route a server's `upgrade` events to this transport, returning a detach
184
184
  * function. Use it to bind an `unbound` transport once the host server
185
185
  * exists; {@link WsRpcTransport.close} detaches every server attached this
186
- * way (without closing them — the caller owns their lifecycle).
186
+ * way (without closing them, since the caller owns their lifecycle).
187
187
  */
188
188
  attach: (server: Server | Server$1) => () => void;
189
189
  /** Remove the upgrade listener from a shared `server` (a no-op otherwise). */
@@ -195,21 +195,12 @@ interface WsRpcTransport {
195
195
  */
196
196
  close: () => Promise<void>;
197
197
  }
198
- declare function isLoopbackHostname(hostname: string): boolean;
199
- /**
200
- * Default origin policy for a localhost dev tool: allow requests with no
201
- * `Origin` header (native, non-browser clients), allow any loopback origin
202
- * (so cross-port localhost dev setups keep working), and allow explicitly
203
- * configured origins. Everything else — a real remote page in the dev's
204
- * browser — is rejected.
205
- */
206
- declare function isAllowedOrigin(origin: string | undefined, allowedOrigins: readonly string[]): boolean;
207
198
  /**
208
199
  * The per-peer lifecycle hooks driving a devframe RPC WebSocket, shaped for
209
200
  * any [crossws](https://crossws.h3.dev) adapter. {@link attachWsRpcTransport}
210
201
  * feeds them to the Node adapter; runtime-specific attachments (e.g. Bun's
211
202
  * fetch-upgrade adapter) reuse the same hooks so every transport speaks the
212
- * identical wire protocol — one birpc channel per peer, per-method
203
+ * identical wire protocol: one birpc channel per peer, per-method
213
204
  * `jsonSerializable` dispatch between strict JSON and structured-clone.
214
205
  */
215
206
  declare function createWsRpcPeerHooks<ClientFunctions extends object, ServerFunctions extends object>(rpcGroup: BirpcGroup<ClientFunctions, ServerFunctions, false>, options?: Pick<WsRpcTransportOptions, 'onConnected' | 'onDisconnected' | 'definitions' | 'serialize' | 'deserialize'>): Partial<Hooks>;
@@ -225,4 +216,4 @@ declare function createWsRpcPeerHooks<ClientFunctions extends object, ServerFunc
225
216
  */
226
217
  declare function attachWsRpcTransport<ClientFunctions extends object, ServerFunctions extends object>(rpcGroup: BirpcGroup<ClientFunctions, ServerFunctions, false>, options?: WsRpcTransportOptions): WsRpcTransport;
227
218
  //#endregion
228
- export { attachWsRpcTransport as a, isAllowedOrigin as c, DevframeRpcConnection as d, DevframeRpcConnectionRequest as f, WsRpcTransportOptions as i, isLoopbackHostname as l, WsOriginRegistry as n, createWsOriginRegistry as o, DevframeRpcTransportKind as p, WsRpcTransport as r, createWsRpcPeerHooks as s, CreateWsOriginRegistryOptions as t, DevframeNodeRpcSessionMeta as u };
219
+ export { attachWsRpcTransport as a, DevframeNodeRpcSessionMeta as c, DevframeRpcTransportKind as d, WsRpcTransportOptions as i, DevframeRpcConnection as l, WsOriginRegistry as n, createWsOriginRegistry as o, WsRpcTransport as r, createWsRpcPeerHooks as s, CreateWsOriginRegistryOptions as t, DevframeRpcConnectionRequest as u };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "devframe",
3
3
  "type": "module",
4
- "version": "0.9.7",
4
+ "version": "0.9.9",
5
5
  "description": "Framework for building one portable devtool integration that runs in any viewer.",
6
6
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
7
7
  "license": "MIT",
@@ -56,6 +56,7 @@
56
56
  "./utils/nanoid": "./dist/utils/nanoid.mjs",
57
57
  "./utils/nostics": "./dist/utils/nostics.mjs",
58
58
  "./utils/open": "./dist/utils/open.mjs",
59
+ "./utils/origin": "./dist/utils/origin.mjs",
59
60
  "./utils/remote-assets": "./dist/utils/remote-assets.mjs",
60
61
  "./utils/simple-schema": "./dist/utils/simple-schema.mjs",
61
62
  "./utils/serve-static": "./dist/utils/serve-static.mjs",
@@ -92,9 +93,9 @@
92
93
  },
93
94
  "dependencies": {
94
95
  "@standard-schema/spec": "^1.1.0",
95
- "birpc": "^4.1.0",
96
- "crossws": "^0.4.10",
97
- "h3": "^2.0.1-rc.26",
96
+ "birpc": "^4.2.0",
97
+ "crossws": "^0.4.12",
98
+ "h3": "^2.0.1-rc.29",
98
99
  "mrmime": "^2.0.1",
99
100
  "nostics": "^1.2.0",
100
101
  "pathe": "^2.0.3",
@@ -105,7 +106,7 @@
105
106
  "@modelcontextprotocol/server": "^2.0.0",
106
107
  "cac": "^7.0.0",
107
108
  "get-port-please": "^3.2.0",
108
- "immer": "^11.1.17",
109
+ "immer": "^11.1.18",
109
110
  "launch-editor": "^2.14.1",
110
111
  "mlly": "^1.8.2",
111
112
  "obug": "^2.1.4",