@guren/server 2.28.1 → 2.29.1
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/dist/{DocsViewerServiceProvider-BMbcTYVw.js → DocsViewerServiceProvider-BVPZjwQp.js} +7 -1
- package/dist/{Gate-CYfoGQqh.js → Gate-DFiuutZm.js} +1 -25
- package/dist/{McpServiceProvider-PGFPlYTy.js → McpServiceProvider-CvFExxdJ.js} +45 -2
- package/dist/{MessageSigner-Bd25ZJAV.js → MessageSigner-DIUT1Yao.js} +4 -2
- package/dist/{Resource-BhOua2OB.js → Resource-ZMJH4lyD.js} +2 -1
- package/dist/auth/index.js +1 -1
- package/dist/{auth-DIugW0O-.js → auth-DRMeSwev.js} +1 -1
- package/dist/authorization/index.js +2 -2
- package/dist/{authorization-CKOLYWvi.js → authorization-DUjeyGWh.js} +2 -1
- package/dist/{dev-banner-DnaL8Ku6.js → dev-banner-wz0V_g0R.js} +1 -1
- package/dist/encryption/index.js +2 -2
- package/dist/{encryption-CWK5l22W.js → encryption-DF8lZkpj.js} +1 -1
- package/dist/http/Application.d.ts +10 -54
- package/dist/http/boot-sequence.d.ts +8 -0
- package/dist/http/server-lifecycle.d.ts +88 -0
- package/dist/index.js +171 -318
- package/dist/internal/testing.js +1 -1
- package/dist/introspection/types.d.ts +6 -0
- package/dist/mcp/McpServiceProvider.d.ts +7 -0
- package/dist/mcp/index.js +1 -1
- package/dist/mcp/runtime-error-capture.d.ts +24 -0
- package/dist/mcp/runtime-errors.d.ts +59 -0
- package/dist/mvc/Router.d.ts +2 -0
- package/dist/request-container-BbuH0JJy.js +25 -0
- package/dist/runtime/index.js +2 -2
- package/dist/runtime-error-capture-BclelWhA.js +48 -0
- package/dist/runtime-errors-DOPBX0Ox.js +135 -0
- package/dist/vite-manifest-DO0pU1vm.js +391 -0
- package/package.json +3 -3
- package/dist/endpoint-Coq0K_6I.js +0 -26
- package/dist/vite-manifest-wPxfAzjW.js +0 -146
|
@@ -0,0 +1,391 @@
|
|
|
1
|
+
import { a as trimTrailingSlashes } from "./contained-path-BkNSBljW.js";
|
|
2
|
+
import { resolve } from "node:path";
|
|
3
|
+
import { readFileSync } from "node:fs";
|
|
4
|
+
//#region src/http/server-lifecycle.ts
|
|
5
|
+
const MANAGED_VITE_ENV_FLAG = "GUREN_MANAGED_VITE_DEV_SERVER";
|
|
6
|
+
const DEFAULT_DEV_ENTRY_PATH = "/resources/js/dev-entry.ts";
|
|
7
|
+
function clearManagedViteEnv() {
|
|
8
|
+
if (typeof process === "undefined") return;
|
|
9
|
+
if (process.env["GUREN_MANAGED_VITE_DEV_SERVER"] === "1") {
|
|
10
|
+
delete process.env.VITE_DEV_SERVER_URL;
|
|
11
|
+
if (process.env.GUREN_INERTIA_ENTRY?.endsWith(DEFAULT_DEV_ENTRY_PATH)) delete process.env.GUREN_INERTIA_ENTRY;
|
|
12
|
+
}
|
|
13
|
+
delete process.env[MANAGED_VITE_ENV_FLAG];
|
|
14
|
+
}
|
|
15
|
+
function normalizeDevEntryUrl(baseUrl) {
|
|
16
|
+
return `${baseUrl.replace(/\/$/u, "")}${DEFAULT_DEV_ENTRY_PATH}`;
|
|
17
|
+
}
|
|
18
|
+
function syncManagedInertiaDevEntry(devServerUrl) {
|
|
19
|
+
if (typeof process === "undefined") return;
|
|
20
|
+
const nextEntry = normalizeDevEntryUrl(devServerUrl);
|
|
21
|
+
const currentEntry = process.env.GUREN_INERTIA_ENTRY;
|
|
22
|
+
if (!currentEntry || currentEntry.endsWith(DEFAULT_DEV_ENTRY_PATH)) process.env.GUREN_INERTIA_ENTRY = nextEntry;
|
|
23
|
+
}
|
|
24
|
+
function getGlobalState() {
|
|
25
|
+
return globalThis;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* How long a server `stop()` may take before shutdown stops waiting. Abandoning
|
|
29
|
+
* this wait is safe in a way abandoning a Vite close is not: the socket has
|
|
30
|
+
* already stopped accepting connections, so what is left is a drain.
|
|
31
|
+
*/
|
|
32
|
+
function bunStopTimeoutMs() {
|
|
33
|
+
return shutdownTimeoutMs("GUREN_BUN_STOP_TIMEOUT_MS");
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* How long a `bun --hot` reload waits on the server it replaces. That stop is
|
|
37
|
+
* forced, and the hot-reload teardown has already server-closed every broadcast
|
|
38
|
+
* WebSocket, so nothing is draining; on Bun 1.3.x `stop()` then never resolves
|
|
39
|
+
* (1.4.0 resolves at once). Quoted in docs/{en,ja}/guides/architecture.md.
|
|
40
|
+
*/
|
|
41
|
+
const HOT_RELOAD_STOP_TIMEOUT_MS = 250;
|
|
42
|
+
function defaultStopBound() {
|
|
43
|
+
return {
|
|
44
|
+
timeoutMs: bunStopTimeoutMs(),
|
|
45
|
+
warn: true
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Silent: on Bun 1.3.x it is hit on every reload, and there is nothing to
|
|
50
|
+
* report. `GUREN_BUN_STOP_TIMEOUT_MS` can only shorten it: it is set for a
|
|
51
|
+
* production drain, which a reload never is.
|
|
52
|
+
*/
|
|
53
|
+
function hotReloadStopBound() {
|
|
54
|
+
return {
|
|
55
|
+
timeoutMs: Math.min(bunStopTimeoutMs(), HOT_RELOAD_STOP_TIMEOUT_MS),
|
|
56
|
+
warn: false
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* A positive integer of milliseconds, or 5000 when unset or unparseable. One
|
|
61
|
+
* parse for both bounds, so they cannot drift apart.
|
|
62
|
+
*/
|
|
63
|
+
function shutdownTimeoutMs(envName) {
|
|
64
|
+
const parsed = typeof process !== "undefined" ? Number.parseInt(process.env[envName] ?? "", 10) : NaN;
|
|
65
|
+
return Number.isInteger(parsed) && parsed > 0 ? parsed : 5e3;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Awaits `work`, giving up after `timeoutMs`. Resolves either way: every caller
|
|
69
|
+
* is a shutdown path, and one that hangs is worse than one that gives up.
|
|
70
|
+
*/
|
|
71
|
+
async function awaitBounded(work, timeoutMs, onTimeout) {
|
|
72
|
+
let timer;
|
|
73
|
+
try {
|
|
74
|
+
if (await Promise.race([work.then(() => false), new Promise((resolve) => {
|
|
75
|
+
timer = setTimeout(() => resolve(true), timeoutMs);
|
|
76
|
+
})])) onTimeout(timeoutMs);
|
|
77
|
+
} finally {
|
|
78
|
+
clearTimeout(timer);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/** `stop()` bounded by `bound` ({@link bunStopTimeoutMs} by default), warning rather than throwing. */
|
|
82
|
+
async function stopBunServerBounded(server, closeActiveConnections, bound = defaultStopBound()) {
|
|
83
|
+
await awaitBounded((async () => {
|
|
84
|
+
try {
|
|
85
|
+
await server.stop?.(closeActiveConnections);
|
|
86
|
+
} catch (error) {
|
|
87
|
+
console.warn("Failed to stop Bun server:", error);
|
|
88
|
+
}
|
|
89
|
+
})(), bound.timeoutMs, (timeoutMs) => {
|
|
90
|
+
if (!bound.warn) return;
|
|
91
|
+
console.warn(`Bun server did not stop within ${timeoutMs}ms — no longer waiting on it. In-flight requests may still be draining.`);
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
async function stopActiveBunServer(closeActiveConnections = false, bound) {
|
|
95
|
+
const state = getGlobalState();
|
|
96
|
+
const previous = state.__gurenActiveServer;
|
|
97
|
+
if (!previous?.stop) {
|
|
98
|
+
state.__gurenActiveServer = void 0;
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
try {
|
|
102
|
+
await stopBunServerBounded(previous, closeActiveConnections, bound);
|
|
103
|
+
} finally {
|
|
104
|
+
releaseActiveBunServer(previous);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
function setActiveBunServer(server) {
|
|
108
|
+
getGlobalState().__gurenActiveServer = server;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Gives up the process-wide slot, but only while it still holds `server`: a
|
|
112
|
+
* `listen()` that completed inside the caller's await has repointed it at a
|
|
113
|
+
* live server, which clearing would strip of its exit teardown.
|
|
114
|
+
*/
|
|
115
|
+
function releaseActiveBunServer(server) {
|
|
116
|
+
if (getGlobalState().__gurenActiveServer === server) setActiveBunServer();
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Attaches one SIGINT/SIGTERM/exit trio and returns the disposer for it. A
|
|
120
|
+
* boolean-guarded registrar would leave handlers attached and let the next
|
|
121
|
+
* `listen()` stack a second set on top — and `process.once` fires in
|
|
122
|
+
* registration order, so a stale handler's `process.exit()` can end the process
|
|
123
|
+
* ahead of the live set's shutdown.
|
|
124
|
+
*/
|
|
125
|
+
function registerProcessTeardown(onSignal, onExit) {
|
|
126
|
+
process.once("SIGINT", onSignal);
|
|
127
|
+
process.once("SIGTERM", onSignal);
|
|
128
|
+
process.on("exit", onExit);
|
|
129
|
+
return () => {
|
|
130
|
+
process.off("SIGINT", onSignal);
|
|
131
|
+
process.off("SIGTERM", onSignal);
|
|
132
|
+
process.off("exit", onExit);
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* How long a Vite `close()` may take before shutdown abandons it — a browser tab
|
|
137
|
+
* holding its HMR socket can keep that wait alive indefinitely. A stranded asset
|
|
138
|
+
* server is recoverable noise; a `listen()` that never returns is not.
|
|
139
|
+
*/
|
|
140
|
+
function viteCloseTimeoutMs() {
|
|
141
|
+
return shutdownTimeoutMs("GUREN_VITE_CLOSE_TIMEOUT_MS");
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* `close()` bounded by {@link viteCloseTimeoutMs}: resolves once the server
|
|
145
|
+
* closed, failed (warned), or ran out the clock (warned, abandoned).
|
|
146
|
+
*/
|
|
147
|
+
async function closeViteDevServerBounded(server) {
|
|
148
|
+
await awaitBounded((async () => {
|
|
149
|
+
try {
|
|
150
|
+
await server.close();
|
|
151
|
+
} catch (error) {
|
|
152
|
+
console.warn("Failed to stop Vite dev server:", error);
|
|
153
|
+
}
|
|
154
|
+
})(), viteCloseTimeoutMs(), (timeoutMs) => {
|
|
155
|
+
console.warn(`Vite dev server did not close within ${timeoutMs}ms — abandoning it. A stale asset server may still hold its port.`);
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Closes the managed Vite dev server whoever owns it. Only `listen()`'s restart
|
|
160
|
+
* path calls this — the one case where an owner's claim does not survive.
|
|
161
|
+
*/
|
|
162
|
+
async function stopActiveViteDevServer() {
|
|
163
|
+
const previous = getGlobalState().__gurenActiveViteDevServer;
|
|
164
|
+
try {
|
|
165
|
+
if (previous) await closeViteDevServerBounded(previous.server);
|
|
166
|
+
} finally {
|
|
167
|
+
previous?.disposeTeardown();
|
|
168
|
+
if (getGlobalState().__gurenActiveViteDevServer === previous) setActiveViteDevServer();
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
function publishManagedViteEnv(localUrl) {
|
|
172
|
+
if (typeof process === "undefined") return;
|
|
173
|
+
process.env.VITE_DEV_SERVER_URL = localUrl;
|
|
174
|
+
process.env[MANAGED_VITE_ENV_FLAG] = "1";
|
|
175
|
+
syncManagedInertiaDevEntry(localUrl);
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* The one write point for the active-record slot. `VITE_DEV_SERVER_URL` and the
|
|
179
|
+
* managed flag travel with it, so a stale close cannot unpublish an adopter's
|
|
180
|
+
* URL while its record stays live, or the reverse.
|
|
181
|
+
*/
|
|
182
|
+
function setActiveViteDevServer(active) {
|
|
183
|
+
getGlobalState().__gurenActiveViteDevServer = active;
|
|
184
|
+
if (active) publishManagedViteEnv(active.localUrl);
|
|
185
|
+
else clearManagedViteEnv();
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* The managed Vite dev server a previous `listen()` left running. Reusing it
|
|
189
|
+
* keeps the browser's HMR socket connected and skips the
|
|
190
|
+
* {@link viteCloseTimeoutMs} wait. Explicit `vite` options veto reuse: the
|
|
191
|
+
* running server was built from the *previous* call's options.
|
|
192
|
+
*/
|
|
193
|
+
function reusableActiveViteDevServer(viteOption) {
|
|
194
|
+
if (typeof viteOption === "object") return;
|
|
195
|
+
const active = getGlobalState().__gurenActiveViteDevServer;
|
|
196
|
+
if (!active || !active.server.httpServer?.listening) return;
|
|
197
|
+
return active;
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Closes the managed Vite dev server, but only while this application still
|
|
201
|
+
* owns it: another `listen()` may have adopted the same object, and closing it
|
|
202
|
+
* then would take the asset server out from under an app serving from it. The
|
|
203
|
+
* slot's record is the one place that distinction exists.
|
|
204
|
+
*/
|
|
205
|
+
async function closeOwnedViteDevServer(owner) {
|
|
206
|
+
const active = getGlobalState().__gurenActiveViteDevServer;
|
|
207
|
+
if (active?.owner !== owner) return;
|
|
208
|
+
try {
|
|
209
|
+
await closeViteDevServerBounded(active.server);
|
|
210
|
+
} finally {
|
|
211
|
+
active.disposeTeardown();
|
|
212
|
+
if (getGlobalState().__gurenActiveViteDevServer === active) setActiveViteDevServer();
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
function registerViteTeardown(owner) {
|
|
216
|
+
if (typeof process === "undefined") return () => {};
|
|
217
|
+
return registerProcessTeardown(() => {
|
|
218
|
+
closeOwnedViteDevServer(owner).then(() => process.exit(0)).catch(() => process.exit(1));
|
|
219
|
+
}, () => {
|
|
220
|
+
const active = getGlobalState().__gurenActiveViteDevServer;
|
|
221
|
+
if (active?.owner === owner) active.server.close();
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
function registerBunTeardown() {
|
|
225
|
+
if (typeof process === "undefined") return () => {};
|
|
226
|
+
return registerProcessTeardown(() => {
|
|
227
|
+
stopActiveBunServer().then(() => process.exit(0)).catch(() => process.exit(1));
|
|
228
|
+
}, () => {
|
|
229
|
+
stopActiveBunServer();
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
function adoptViteDevServer(owner, viteServer, localUrl) {
|
|
233
|
+
const displaced = getGlobalState().__gurenActiveViteDevServer;
|
|
234
|
+
displaced?.disposeTeardown();
|
|
235
|
+
if (displaced && displaced.server !== viteServer) closeViteDevServerBounded(displaced.server);
|
|
236
|
+
setActiveViteDevServer({
|
|
237
|
+
server: viteServer,
|
|
238
|
+
localUrl,
|
|
239
|
+
owner,
|
|
240
|
+
disposeTeardown: registerViteTeardown(owner)
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
//#endregion
|
|
244
|
+
//#region src/http/vite-dev-server.ts
|
|
245
|
+
/**
|
|
246
|
+
* Build the inline config the managed dev server starts with. `server.host` is
|
|
247
|
+
* left undefined unless asked for, so Vite's config merge drops it and the
|
|
248
|
+
* project's own `vite.config.ts` decides.
|
|
249
|
+
*/
|
|
250
|
+
function resolveViteDevServerConfig(options = {}) {
|
|
251
|
+
const { root = process.cwd(), config = {}, host, port } = options;
|
|
252
|
+
return {
|
|
253
|
+
clearScreen: false,
|
|
254
|
+
...config,
|
|
255
|
+
root: config.root ?? root,
|
|
256
|
+
server: {
|
|
257
|
+
host,
|
|
258
|
+
port,
|
|
259
|
+
...config.server
|
|
260
|
+
}
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
async function startViteDevServer(options = {}) {
|
|
264
|
+
const { host, port } = options;
|
|
265
|
+
const { createServer } = await import("vite");
|
|
266
|
+
const server = await createServer(resolveViteDevServerConfig(options));
|
|
267
|
+
try {
|
|
268
|
+
await server.listen();
|
|
269
|
+
const resolved = server.resolvedUrls;
|
|
270
|
+
const localUrls = resolved?.local?.length ? resolved.local : [`http://${typeof host === "string" ? host : "localhost"}:${server.config.server.port ?? port ?? 5173}`];
|
|
271
|
+
const networkUrls = resolved?.network ?? [];
|
|
272
|
+
return {
|
|
273
|
+
server,
|
|
274
|
+
localUrl: localUrls[0],
|
|
275
|
+
networkUrls
|
|
276
|
+
};
|
|
277
|
+
} catch (error) {
|
|
278
|
+
await closeViteDevServerBounded(server);
|
|
279
|
+
throw error;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
//#endregion
|
|
283
|
+
//#region src/http/vite-manifest.ts
|
|
284
|
+
/**
|
|
285
|
+
* The one rule for how Vite build output is found and addressed, shared by the
|
|
286
|
+
* Inertia asset wiring (`inertia-assets.ts`) and `viteAsset()` (`vite-assets.ts`,
|
|
287
|
+
* RFC 0014) so the two cannot drift: what counts as a manifest, where one may
|
|
288
|
+
* live, which URL prefix serves the hashed files, and what "the dev server is
|
|
289
|
+
* on" means.
|
|
290
|
+
*/
|
|
291
|
+
/**
|
|
292
|
+
* Where `configureInertiaAssets` serves hashed build output from. The deploy
|
|
293
|
+
* builds restate it as `CLIENT_ASSETS_URL_PREFIX` in @guren/core's
|
|
294
|
+
* internal/deploy-build.ts; tests/http/vite-manifest.test.ts pins the two equal.
|
|
295
|
+
*/
|
|
296
|
+
const PUBLIC_ASSETS_URL_PREFIX = "/public/assets/";
|
|
297
|
+
/** The Vite default the framework assumes when no dev-server URL is set. */
|
|
298
|
+
const DEFAULT_DEV_SERVER_URL = "http://localhost:5173";
|
|
299
|
+
/**
|
|
300
|
+
* Production for *asset* purposes: `NODE_ENV` says so and no dev server is
|
|
301
|
+
* configured — a configured dev server means dev asset serving even when
|
|
302
|
+
* `NODE_ENV` is `production` (E2E runs do exactly this).
|
|
303
|
+
*/
|
|
304
|
+
function isViteProduction(devServerUrl = process.env.VITE_DEV_SERVER_URL) {
|
|
305
|
+
return process.env.NODE_ENV === "production" && typeof devServerUrl !== "string";
|
|
306
|
+
}
|
|
307
|
+
function normalizeDevServerUrl(value) {
|
|
308
|
+
if (!value) return value;
|
|
309
|
+
const trimmed = value.trim();
|
|
310
|
+
if (!trimmed) return trimmed;
|
|
311
|
+
const stripped = trimTrailingSlashes(trimmed);
|
|
312
|
+
return stripped.length > 0 ? stripped : "/";
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* Candidate client-manifest locations, `.vite/manifest.json` first: Vite >= 5
|
|
316
|
+
* writes it there, so a flat `manifest.json` is likely a stale leftover. The
|
|
317
|
+
* deploy plugins order the same pair through `@guren/core`'s deploy-build
|
|
318
|
+
* helpers and must agree, or an app with both layouts resolves different asset
|
|
319
|
+
* versions after a serverless deploy; `tests/http/vite-manifest.test.ts` pins it.
|
|
320
|
+
*/
|
|
321
|
+
function clientManifestCandidates(baseDir) {
|
|
322
|
+
const root = baseDir ?? process.cwd();
|
|
323
|
+
return [resolve(root, "public/assets/.vite/manifest.json"), resolve(root, "public/assets/manifest.json")];
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* `__path__` label for an injected manifest, so "entry not in the manifest"
|
|
327
|
+
* errors name the real source rather than a path that was never read.
|
|
328
|
+
*/
|
|
329
|
+
const INJECTED_CLIENT_MANIFEST_SOURCE = "GUREN_VITE_MANIFEST (injected by the deploy build)";
|
|
330
|
+
const INJECTED_MANIFEST_HINT = "It must hold the Vite client manifest text (deploy plugins inject it at build time), not a path.";
|
|
331
|
+
/**
|
|
332
|
+
* Attach one of the manifest's bookkeeping fields. `enumerable: false` is the
|
|
333
|
+
* invariant: a stamped field must never leak into `Object.keys` or a
|
|
334
|
+
* re-serialization of the manifest.
|
|
335
|
+
*/
|
|
336
|
+
function defineHidden(manifest, key, value) {
|
|
337
|
+
Object.defineProperty(manifest, key, {
|
|
338
|
+
value,
|
|
339
|
+
enumerable: false
|
|
340
|
+
});
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* The client manifest a deploy build injected for runtimes that do not ship
|
|
344
|
+
* `public/assets/manifest.json`: `GUREN_VITE_MANIFEST` holds the manifest *JSON
|
|
345
|
+
* text*, not a path. Fails loudly on a value that is set but not a manifest,
|
|
346
|
+
* because falling through to the filesystem would end in "run `bunx vite build`"
|
|
347
|
+
* — a diagnosis pointing away from the variable that is actually broken.
|
|
348
|
+
*/
|
|
349
|
+
function injectedClientManifest() {
|
|
350
|
+
const raw = process.env.GUREN_VITE_MANIFEST;
|
|
351
|
+
if (typeof raw !== "string" || raw.length === 0) return;
|
|
352
|
+
let parsed;
|
|
353
|
+
try {
|
|
354
|
+
parsed = JSON.parse(raw);
|
|
355
|
+
} catch (error) {
|
|
356
|
+
throw new Error(`GUREN_VITE_MANIFEST is set but is not valid JSON. ${INJECTED_MANIFEST_HINT}`, { cause: error });
|
|
357
|
+
}
|
|
358
|
+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) throw new Error(`GUREN_VITE_MANIFEST is set but does not hold a manifest object. ${INJECTED_MANIFEST_HINT}`);
|
|
359
|
+
const manifest = parsed;
|
|
360
|
+
defineHidden(manifest, "__path__", INJECTED_CLIENT_MANIFEST_SOURCE);
|
|
361
|
+
return manifest;
|
|
362
|
+
}
|
|
363
|
+
function loadViteManifest(candidatePaths, label, options = {}) {
|
|
364
|
+
const warnOnMissing = options.warnOnMissing ?? true;
|
|
365
|
+
const command = label === "SSR" ? "bunx vite build --ssr" : "bunx vite build";
|
|
366
|
+
for (const manifestPath of candidatePaths) try {
|
|
367
|
+
const raw = readFileSync(manifestPath, "utf8");
|
|
368
|
+
const manifest = JSON.parse(raw);
|
|
369
|
+
defineHidden(manifest, "__path__", manifestPath);
|
|
370
|
+
if (options.includeRaw) defineHidden(manifest, "__raw__", raw);
|
|
371
|
+
return manifest;
|
|
372
|
+
} catch (error) {
|
|
373
|
+
if (error.code !== "ENOENT") {
|
|
374
|
+
console.warn(`Unable to load ${label} Vite manifest at ${manifestPath}.`, error);
|
|
375
|
+
return;
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
if (warnOnMissing && candidatePaths.length) console.warn(`Unable to load ${label} Vite manifest. Checked paths:\n${candidatePaths.map((p) => ` - ${p}`).join("\n")}\nRun \`${command}\` before starting in production.`);
|
|
379
|
+
}
|
|
380
|
+
function getManifestFile(entry) {
|
|
381
|
+
if (!entry) return;
|
|
382
|
+
if (Array.isArray(entry)) return entry[0];
|
|
383
|
+
if (typeof entry === "string") return entry;
|
|
384
|
+
if ("file" in entry && typeof entry.file === "string") return entry.file;
|
|
385
|
+
}
|
|
386
|
+
function getManifestCss(entry) {
|
|
387
|
+
if (!entry || Array.isArray(entry) || typeof entry === "string") return;
|
|
388
|
+
return entry.css;
|
|
389
|
+
}
|
|
390
|
+
//#endregion
|
|
391
|
+
export { stopBunServerBounded as C, stopActiveViteDevServer as S, registerBunTeardown as _, getManifestCss as a, setActiveBunServer as b, isViteProduction as c, startViteDevServer as d, MANAGED_VITE_ENV_FLAG as f, hotReloadStopBound as g, getGlobalState as h, clientManifestCandidates as i, loadViteManifest as l, closeOwnedViteDevServer as m, INJECTED_CLIENT_MANIFEST_SOURCE as n, getManifestFile as o, adoptViteDevServer as p, PUBLIC_ASSETS_URL_PREFIX as r, injectedClientManifest as s, DEFAULT_DEV_SERVER_URL as t, normalizeDevServerUrl as u, releaseActiveBunServer as v, stopActiveBunServer as x, reusableActiveViteDevServer as y };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@guren/server",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.29.1",
|
|
4
4
|
"description": "HTTP layer of the Guren framework, on Hono: routing, controllers, middleware, auth, sessions, queues and the AWS Lambda adapter. Applications import it through @guren/core.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"guren",
|
|
@@ -164,13 +164,13 @@
|
|
|
164
164
|
"test": "bun test"
|
|
165
165
|
},
|
|
166
166
|
"dependencies": {
|
|
167
|
-
"@guren/orm": "^2.
|
|
167
|
+
"@guren/orm": "^2.14.0",
|
|
168
168
|
"chalk": "^5.3.0",
|
|
169
169
|
"consola": "^3.4.2",
|
|
170
170
|
"figlet": "^1.7.0",
|
|
171
171
|
"hono": "^4.13.7",
|
|
172
172
|
"ioredis": "^5.11.1",
|
|
173
|
-
"nodemailer": "^
|
|
173
|
+
"nodemailer": "^10.0.2"
|
|
174
174
|
},
|
|
175
175
|
"peerDependencies": {
|
|
176
176
|
"@aws-sdk/client-s3": "^3.0.0",
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { t as createLoopbackGuard } from "./loopback-guard-CG8xB4v0.js";
|
|
2
|
-
//#region src/mcp/endpoint.ts
|
|
3
|
-
const MCP_ENDPOINT_PATH = "/_guren/mcp";
|
|
4
|
-
/**
|
|
5
|
-
* Whether the MCP endpoint is mounted: opt-in via `GUREN_MCP=1`, never in
|
|
6
|
-
* production (it exposes project introspection and code generation). The env
|
|
7
|
-
* reads are plain member access on purpose: the deploy plugins settle NODE_ENV
|
|
8
|
-
* with `--define`, which matches one exact expression, so an optional chain
|
|
9
|
-
* leaves a runtime read that reopens the gate on workerd; `tests/mcp/endpoint.test.ts` pins the form.
|
|
10
|
-
*/
|
|
11
|
-
function isMcpEndpointEnabled() {
|
|
12
|
-
if (typeof process === "undefined") return false;
|
|
13
|
-
if (process.env.NODE_ENV === "production") return false;
|
|
14
|
-
return process.env.GUREN_MCP === "1";
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Restricts the MCP endpoint to the developer's own machine. The endpoint is
|
|
18
|
-
* CSRF-exempt (agent clients carry no token), so this guard takes over: a web
|
|
19
|
-
* page is rejected unless its `Origin` is loopback, and every caller unless its
|
|
20
|
-
* socket peer is. It fails closed when the runtime reports no peer at all.
|
|
21
|
-
*/
|
|
22
|
-
function createMcpAccessGuard() {
|
|
23
|
-
return createLoopbackGuard("the MCP endpoint");
|
|
24
|
-
}
|
|
25
|
-
//#endregion
|
|
26
|
-
export { createMcpAccessGuard as n, isMcpEndpointEnabled as r, MCP_ENDPOINT_PATH as t };
|
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
import { a as trimTrailingSlashes } from "./contained-path-BkNSBljW.js";
|
|
2
|
-
import { resolve } from "node:path";
|
|
3
|
-
import { readFileSync } from "node:fs";
|
|
4
|
-
//#region src/http/vite-dev-server.ts
|
|
5
|
-
/**
|
|
6
|
-
* Build the inline config the managed dev server starts with. `server.host` is
|
|
7
|
-
* left undefined unless asked for, so Vite's config merge drops it and the
|
|
8
|
-
* project's own `vite.config.ts` decides.
|
|
9
|
-
*/
|
|
10
|
-
function resolveViteDevServerConfig(options = {}) {
|
|
11
|
-
const { root = process.cwd(), config = {}, host, port } = options;
|
|
12
|
-
return {
|
|
13
|
-
clearScreen: false,
|
|
14
|
-
...config,
|
|
15
|
-
root: config.root ?? root,
|
|
16
|
-
server: {
|
|
17
|
-
host,
|
|
18
|
-
port,
|
|
19
|
-
...config.server
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
async function startViteDevServer(options = {}) {
|
|
24
|
-
const { host, port } = options;
|
|
25
|
-
const { createServer } = await import("vite");
|
|
26
|
-
const server = await createServer(resolveViteDevServerConfig(options));
|
|
27
|
-
await server.listen();
|
|
28
|
-
const resolved = server.resolvedUrls;
|
|
29
|
-
const localUrls = resolved?.local?.length ? resolved.local : [`http://${typeof host === "string" ? host : "localhost"}:${server.config.server.port ?? port ?? 5173}`];
|
|
30
|
-
const networkUrls = resolved?.network ?? [];
|
|
31
|
-
return {
|
|
32
|
-
server,
|
|
33
|
-
localUrl: localUrls[0],
|
|
34
|
-
networkUrls
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
//#endregion
|
|
38
|
-
//#region src/http/vite-manifest.ts
|
|
39
|
-
/**
|
|
40
|
-
* The one rule for how Vite build output is found and addressed, shared by the
|
|
41
|
-
* Inertia asset wiring (`inertia-assets.ts`) and `viteAsset()` (`vite-assets.ts`,
|
|
42
|
-
* RFC 0014) so the two cannot drift: what counts as a manifest, where one may
|
|
43
|
-
* live, which URL prefix serves the hashed files, and what "the dev server is
|
|
44
|
-
* on" means.
|
|
45
|
-
*/
|
|
46
|
-
/**
|
|
47
|
-
* Where `configureInertiaAssets` serves hashed build output from. The deploy
|
|
48
|
-
* builds restate it as `CLIENT_ASSETS_URL_PREFIX` in @guren/core's
|
|
49
|
-
* internal/deploy-build.ts; tests/http/vite-manifest.test.ts pins the two equal.
|
|
50
|
-
*/
|
|
51
|
-
const PUBLIC_ASSETS_URL_PREFIX = "/public/assets/";
|
|
52
|
-
/** The Vite default the framework assumes when no dev-server URL is set. */
|
|
53
|
-
const DEFAULT_DEV_SERVER_URL = "http://localhost:5173";
|
|
54
|
-
/**
|
|
55
|
-
* Production for *asset* purposes: `NODE_ENV` says so and no dev server is
|
|
56
|
-
* configured — a configured dev server means dev asset serving even when
|
|
57
|
-
* `NODE_ENV` is `production` (E2E runs do exactly this).
|
|
58
|
-
*/
|
|
59
|
-
function isViteProduction(devServerUrl = process.env.VITE_DEV_SERVER_URL) {
|
|
60
|
-
return process.env.NODE_ENV === "production" && typeof devServerUrl !== "string";
|
|
61
|
-
}
|
|
62
|
-
function normalizeDevServerUrl(value) {
|
|
63
|
-
if (!value) return value;
|
|
64
|
-
const trimmed = value.trim();
|
|
65
|
-
if (!trimmed) return trimmed;
|
|
66
|
-
const stripped = trimTrailingSlashes(trimmed);
|
|
67
|
-
return stripped.length > 0 ? stripped : "/";
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Candidate client-manifest locations, `.vite/manifest.json` first: Vite >= 5
|
|
71
|
-
* writes it there, so a flat `manifest.json` is likely a stale leftover. The
|
|
72
|
-
* deploy plugins order the same pair through `@guren/core`'s deploy-build
|
|
73
|
-
* helpers and must agree, or an app with both layouts resolves different asset
|
|
74
|
-
* versions after a serverless deploy; `tests/http/vite-manifest.test.ts` pins it.
|
|
75
|
-
*/
|
|
76
|
-
function clientManifestCandidates(baseDir) {
|
|
77
|
-
const root = baseDir ?? process.cwd();
|
|
78
|
-
return [resolve(root, "public/assets/.vite/manifest.json"), resolve(root, "public/assets/manifest.json")];
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* `__path__` label for an injected manifest, so "entry not in the manifest"
|
|
82
|
-
* errors name the real source rather than a path that was never read.
|
|
83
|
-
*/
|
|
84
|
-
const INJECTED_CLIENT_MANIFEST_SOURCE = "GUREN_VITE_MANIFEST (injected by the deploy build)";
|
|
85
|
-
const INJECTED_MANIFEST_HINT = "It must hold the Vite client manifest text (deploy plugins inject it at build time), not a path.";
|
|
86
|
-
/**
|
|
87
|
-
* Attach one of the manifest's bookkeeping fields. `enumerable: false` is the
|
|
88
|
-
* invariant: a stamped field must never leak into `Object.keys` or a
|
|
89
|
-
* re-serialization of the manifest.
|
|
90
|
-
*/
|
|
91
|
-
function defineHidden(manifest, key, value) {
|
|
92
|
-
Object.defineProperty(manifest, key, {
|
|
93
|
-
value,
|
|
94
|
-
enumerable: false
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* The client manifest a deploy build injected for runtimes that do not ship
|
|
99
|
-
* `public/assets/manifest.json`: `GUREN_VITE_MANIFEST` holds the manifest *JSON
|
|
100
|
-
* text*, not a path. Fails loudly on a value that is set but not a manifest,
|
|
101
|
-
* because falling through to the filesystem would end in "run `bunx vite build`"
|
|
102
|
-
* — a diagnosis pointing away from the variable that is actually broken.
|
|
103
|
-
*/
|
|
104
|
-
function injectedClientManifest() {
|
|
105
|
-
const raw = process.env.GUREN_VITE_MANIFEST;
|
|
106
|
-
if (typeof raw !== "string" || raw.length === 0) return;
|
|
107
|
-
let parsed;
|
|
108
|
-
try {
|
|
109
|
-
parsed = JSON.parse(raw);
|
|
110
|
-
} catch (error) {
|
|
111
|
-
throw new Error(`GUREN_VITE_MANIFEST is set but is not valid JSON. ${INJECTED_MANIFEST_HINT}`, { cause: error });
|
|
112
|
-
}
|
|
113
|
-
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) throw new Error(`GUREN_VITE_MANIFEST is set but does not hold a manifest object. ${INJECTED_MANIFEST_HINT}`);
|
|
114
|
-
const manifest = parsed;
|
|
115
|
-
defineHidden(manifest, "__path__", INJECTED_CLIENT_MANIFEST_SOURCE);
|
|
116
|
-
return manifest;
|
|
117
|
-
}
|
|
118
|
-
function loadViteManifest(candidatePaths, label, options = {}) {
|
|
119
|
-
const warnOnMissing = options.warnOnMissing ?? true;
|
|
120
|
-
const command = label === "SSR" ? "bunx vite build --ssr" : "bunx vite build";
|
|
121
|
-
for (const manifestPath of candidatePaths) try {
|
|
122
|
-
const raw = readFileSync(manifestPath, "utf8");
|
|
123
|
-
const manifest = JSON.parse(raw);
|
|
124
|
-
defineHidden(manifest, "__path__", manifestPath);
|
|
125
|
-
if (options.includeRaw) defineHidden(manifest, "__raw__", raw);
|
|
126
|
-
return manifest;
|
|
127
|
-
} catch (error) {
|
|
128
|
-
if (error.code !== "ENOENT") {
|
|
129
|
-
console.warn(`Unable to load ${label} Vite manifest at ${manifestPath}.`, error);
|
|
130
|
-
return;
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
if (warnOnMissing && candidatePaths.length) console.warn(`Unable to load ${label} Vite manifest. Checked paths:\n${candidatePaths.map((p) => ` - ${p}`).join("\n")}\nRun \`${command}\` before starting in production.`);
|
|
134
|
-
}
|
|
135
|
-
function getManifestFile(entry) {
|
|
136
|
-
if (!entry) return;
|
|
137
|
-
if (Array.isArray(entry)) return entry[0];
|
|
138
|
-
if (typeof entry === "string") return entry;
|
|
139
|
-
if ("file" in entry && typeof entry.file === "string") return entry.file;
|
|
140
|
-
}
|
|
141
|
-
function getManifestCss(entry) {
|
|
142
|
-
if (!entry || Array.isArray(entry) || typeof entry === "string") return;
|
|
143
|
-
return entry.css;
|
|
144
|
-
}
|
|
145
|
-
//#endregion
|
|
146
|
-
export { getManifestCss as a, isViteProduction as c, startViteDevServer as d, clientManifestCandidates as i, loadViteManifest as l, INJECTED_CLIENT_MANIFEST_SOURCE as n, getManifestFile as o, PUBLIC_ASSETS_URL_PREFIX as r, injectedClientManifest as s, DEFAULT_DEV_SERVER_URL as t, normalizeDevServerUrl as u };
|