@guren/server 2.2.0 → 2.4.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.
Files changed (40) hide show
  1. package/dist/{DocsViewerServiceProvider-D7RGJPGM.js → DocsViewerServiceProvider-RUYDFBMW.js} +2 -2
  2. package/dist/McpServiceProvider-FRJ5O7LT.js +8 -0
  3. package/dist/auth/index.js +2 -1
  4. package/dist/broadcasting/index.js +2 -1
  5. package/dist/{chunk-SIP34GBE.js → chunk-2SC566CD.js} +14 -18
  6. package/dist/chunk-3KV5X2FL.js +31 -0
  7. package/dist/{chunk-CDZUNKI6.js → chunk-5WL2FTC4.js} +3 -3
  8. package/dist/{chunk-WIXGT4TN.js → chunk-A5JJ7XTH.js} +8 -2
  9. package/dist/{chunk-4VE3LYOM.js → chunk-DRNPVBAA.js} +20 -5
  10. package/dist/{chunk-LVJCZCAV.js → chunk-H3B23O6T.js} +10 -118
  11. package/dist/{chunk-BZMZEFRG.js → chunk-LHR6OHI7.js} +11 -0
  12. package/dist/{chunk-PZKUDFMW.js → chunk-NENDACRP.js} +20 -4
  13. package/dist/{chunk-JBG4AR24.js → chunk-Q2P6YLRR.js} +8 -2
  14. package/dist/{chunk-BUQXOZCT.js → chunk-TVV5YNEC.js} +8 -4
  15. package/dist/chunk-V4DNC2ER.js +114 -0
  16. package/dist/docs-viewer/endpoint.d.ts +11 -1
  17. package/dist/encryption/index.js +17 -15
  18. package/dist/health/index.js +1 -1
  19. package/dist/http/Application.d.ts +67 -1
  20. package/dist/http/FormRequest.d.ts +10 -7
  21. package/dist/http/dev-assets.d.ts +11 -0
  22. package/dist/http/dev-banner.d.ts +11 -0
  23. package/dist/http/inertia-assets.d.ts +9 -0
  24. package/dist/http/middleware/loopback-guard.d.ts +16 -3
  25. package/dist/http/middleware/response-headers.d.ts +18 -0
  26. package/dist/http/middleware/validation-errors-cookie.d.ts +31 -0
  27. package/dist/index.d.ts +1 -1
  28. package/dist/index.js +376 -112
  29. package/dist/mcp/create-mcp-server.d.ts +8 -0
  30. package/dist/mcp/endpoint.d.ts +19 -1
  31. package/dist/mcp/index.js +3 -3
  32. package/dist/redis/index.js +43 -8
  33. package/dist/redis/redis-values.d.ts +17 -0
  34. package/dist/runtime/index.js +102 -69
  35. package/dist/support/contained-path.d.ts +26 -0
  36. package/dist/support/expiry.d.ts +47 -0
  37. package/dist/support/expiry.js +12 -0
  38. package/dist/support/inertia-defaults.d.ts +13 -0
  39. package/package.json +6 -2
  40. package/dist/McpServiceProvider-GRDYNEQG.js +0 -8
@@ -22,6 +22,11 @@ export interface ScaffoldOptions {
22
22
  * found nothing to describe and wrote no file (a project with no page
23
23
  * components, for instance).
24
24
  *
25
+ * `skipped` is an optional sentence explaining that empty `outputPath` when
26
+ * "nothing to describe" would be wrong — the pages generator declines to write
27
+ * a manifest into an app that cannot compile one, and an agent reading this
28
+ * result is exactly who needs to hear that a page it just wrote was ignored.
29
+ *
25
30
  * `definitions` is the route manifest `generateRouteTypes` builds. It stays
26
31
  * opaque here — this package only carries it from one CLI call to the next
27
32
  * (`generateApiClientTypes` consumes it) and never reads inside it, so
@@ -30,6 +35,9 @@ export interface ScaffoldOptions {
30
35
  export interface CodegenResult {
31
36
  outputPath?: string;
32
37
  definitions?: unknown[];
38
+ skipped?: {
39
+ message: string;
40
+ } | null;
33
41
  }
34
42
  /**
35
43
  * CLI functions that the MCP server wraps.
@@ -16,6 +16,22 @@ export declare const MCP_ENDPOINT_PATH = "/_guren/mcp";
16
16
  * Opt-in via `GUREN_MCP=1` and never active in production: the endpoint
17
17
  * exposes project introspection and code generation, so it must not be
18
18
  * reachable unless the developer asked for it.
19
+ *
20
+ * The environment reads below are deliberately written as plain member
21
+ * access. Do not "harden" them with optional chaining: the deploy plugins
22
+ * bundle server code with `--define 'process.env.NODE_ENV="production"'`,
23
+ * and a define matches one exact expression. Inserting `?.` produces a
24
+ * different expression that no define touches, leaving this gate a runtime
25
+ * read — and on hosts where the platform's environment is not in
26
+ * `process.env` by the time the module graph evaluates (workerd is the
27
+ * documented case; see the comment on the Cloudflare plugin's `define`),
28
+ * that runtime read answers "not production" and the gate silently reopens.
29
+ * A test in `tests/mcp/endpoint.test.ts` reads this file and fails on any
30
+ * optional chain after `process.env`, because nothing observable at runtime
31
+ * distinguishes the two forms.
32
+ *
33
+ * The `typeof process` check covers the only runtimes without `process`;
34
+ * every runtime the framework supports that has `process` has `process.env`.
19
35
  */
20
36
  export declare function isMcpEndpointEnabled(): boolean;
21
37
  /**
@@ -24,6 +40,8 @@ export declare function isMcpEndpointEnabled(): boolean;
24
40
  * The endpoint is exempt from CSRF — agent clients carry no token — so
25
41
  * the loopback guard takes over that job: web pages are rejected unless
26
42
  * their `Origin` is loopback (the check the MCP specification asks local
27
- * servers for), and non-browser clients unless their socket peer is.
43
+ * servers for), and every caller is rejected unless its socket peer is
44
+ * loopback. The guard fails closed when the runtime reports no peer at
45
+ * all; see `http/middleware/loopback-guard.ts` for the opt-out.
28
46
  */
29
47
  export declare function createMcpAccessGuard(): MiddlewareHandler;
package/dist/mcp/index.js CHANGED
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  McpServiceProvider,
3
3
  createMcpServer
4
- } from "../chunk-CDZUNKI6.js";
5
- import "../chunk-JBG4AR24.js";
6
- import "../chunk-BZMZEFRG.js";
4
+ } from "../chunk-5WL2FTC4.js";
5
+ import "../chunk-Q2P6YLRR.js";
6
+ import "../chunk-LHR6OHI7.js";
7
7
  export {
8
8
  McpServiceProvider,
9
9
  createMcpServer
@@ -2,6 +2,10 @@ import {
2
2
  Redis,
3
3
  createRedisClient
4
4
  } from "../chunk-UY3AZSYL.js";
5
+ import {
6
+ toDate,
7
+ toOptionalExpiry
8
+ } from "../chunk-3KV5X2FL.js";
5
9
 
6
10
  // src/redis/scan-keys.ts
7
11
  async function scanKeys(redis, pattern) {
@@ -230,6 +234,20 @@ var RedisSlidingWindowRateLimitStore = class {
230
234
  }
231
235
  };
232
236
 
237
+ // src/redis/redis-values.ts
238
+ function decodeAbilities(value) {
239
+ if (value == null || value === "") return [];
240
+ let parsed = value;
241
+ if (typeof value === "string") {
242
+ try {
243
+ parsed = JSON.parse(value);
244
+ } catch {
245
+ return [];
246
+ }
247
+ }
248
+ return Array.isArray(parsed) ? parsed.filter((ability) => typeof ability === "string") : [];
249
+ }
250
+
233
251
  // src/redis/RedisApiTokenStore.ts
234
252
  var RedisApiTokenStore = class {
235
253
  constructor(redis, options = {}) {
@@ -353,10 +371,15 @@ var RedisApiTokenStore = class {
353
371
  name: data.name,
354
372
  hashedToken: data.hashedToken,
355
373
  userId: data.userId,
356
- abilities: JSON.parse(data.abilities),
357
- lastUsedAt: data.lastUsedAt ? new Date(data.lastUsedAt) : null,
358
- expiresAt: data.expiresAt ? new Date(data.expiresAt) : null,
359
- createdAt: new Date(data.createdAt)
374
+ abilities: decodeAbilities(data.abilities),
375
+ lastUsedAt: toDate(data.lastUsedAt),
376
+ // A never-expiring token serializes `expiresAt` as '' (a Redis hash has no
377
+ // null), so an empty string is "absent" here, not a corrupt value. Map it
378
+ // to undefined before `toOptionalExpiry`, which would otherwise degrade ''
379
+ // to epoch and reject every non-expiring token. A genuinely unparseable
380
+ // value still degrades to epoch and reads as expired.
381
+ expiresAt: toOptionalExpiry(data.expiresAt === "" ? void 0 : data.expiresAt),
382
+ createdAt: toDate(data.createdAt) ?? /* @__PURE__ */ new Date(0)
360
383
  };
361
384
  }
362
385
  /**
@@ -406,9 +429,13 @@ var RedisPasswordResetStore = class {
406
429
  }
407
430
  try {
408
431
  const parsed = JSON.parse(data);
432
+ const expiresAt = toDate(parsed.expiresAt);
433
+ if (expiresAt === null) {
434
+ return null;
435
+ }
409
436
  return {
410
437
  email: parsed.email,
411
- expiresAt: new Date(parsed.expiresAt)
438
+ expiresAt
412
439
  };
413
440
  } catch {
414
441
  return null;
@@ -495,11 +522,15 @@ var RedisEmailVerificationStore = class {
495
522
  }
496
523
  try {
497
524
  const parsed = JSON.parse(data);
525
+ const expiresAt = toDate(parsed.expiresAt);
526
+ if (expiresAt === null) {
527
+ return null;
528
+ }
498
529
  return {
499
530
  tokenId: parsed.tokenId,
500
531
  email: parsed.email,
501
- expiresAt: new Date(parsed.expiresAt),
502
- createdAt: new Date(parsed.createdAt)
532
+ expiresAt,
533
+ createdAt: toDate(parsed.createdAt) ?? /* @__PURE__ */ new Date(0)
503
534
  };
504
535
  } catch {
505
536
  return null;
@@ -607,10 +638,14 @@ var RedisOAuthStateStore = class {
607
638
  parsePayload(data) {
608
639
  try {
609
640
  const parsed = JSON.parse(data);
641
+ const expiresAt = toDate(parsed.expiresAt);
642
+ if (expiresAt === null) {
643
+ return null;
644
+ }
610
645
  return {
611
646
  provider: parsed.provider,
612
647
  redirectTo: parsed.redirectTo,
613
- expiresAt: new Date(parsed.expiresAt),
648
+ expiresAt,
614
649
  binding: parsed.binding
615
650
  };
616
651
  } catch {
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Decoding rules shared by the Redis-backed stores.
3
+ *
4
+ * Expiry coercion lives in `../support/expiry` — every store reads its expiry
5
+ * through `toDate`/`toOptionalExpiry`/`isExpired` there, so there is one rule
6
+ * rather than one per store.
7
+ */
8
+ /**
9
+ * Decode a JSON-encoded ability list.
10
+ *
11
+ * Corrupt text degrades to no abilities (deny-by-default) instead of throwing
12
+ * on every verification of the affected token. A value that decodes to
13
+ * something other than a list of strings degrades the same way: `tokenCan`
14
+ * would otherwise run `String.prototype.includes` on it, so a stored `'"*"'`
15
+ * would grant every ability.
16
+ */
17
+ export declare function decodeAbilities(value: unknown): string[];
@@ -1,9 +1,10 @@
1
1
  import {
2
+ DEFAULT_DEV_STYLES_ENTRY,
2
3
  GUREN_ASCII_ART,
3
4
  logDevServerBanner,
4
5
  parseImportMap,
5
6
  startViteDevServer
6
- } from "../chunk-PZKUDFMW.js";
7
+ } from "../chunk-NENDACRP.js";
7
8
  import {
8
9
  trimTrailingSlashes
9
10
  } from "../chunk-AZOYI43J.js";
@@ -13,12 +14,38 @@ import {
13
14
 
14
15
  // src/http/dev-assets.ts
15
16
  import { serveStatic } from "hono/bun";
16
- import { dirname, extname as extname2, resolve as resolve2 } from "path";
17
+ import { dirname, extname as extname2, join, resolve as resolve2 } from "path";
17
18
  import { fileURLToPath } from "url";
18
19
  import { createRequire } from "module";
19
20
 
20
21
  // src/http/public-assets.ts
21
- import { extname, resolve, sep } from "path";
22
+ import { extname, resolve } from "path";
23
+
24
+ // src/support/contained-path.ts
25
+ import { realpath } from "fs/promises";
26
+ import { sep } from "path";
27
+ function isPathWithin(root, candidate) {
28
+ return candidate.startsWith(root.endsWith(sep) ? root : root + sep);
29
+ }
30
+ async function isRealPathWithin(root, candidate) {
31
+ if (!isPathWithin(root, candidate)) {
32
+ return false;
33
+ }
34
+ const [realRoot, realCandidate] = await Promise.all([canonicalize(root), canonicalize(candidate)]);
35
+ if (!realRoot || !realCandidate) {
36
+ return false;
37
+ }
38
+ return isPathWithin(realRoot, realCandidate);
39
+ }
40
+ async function canonicalize(path) {
41
+ try {
42
+ return await realpath(path);
43
+ } catch {
44
+ return void 0;
45
+ }
46
+ }
47
+
48
+ // src/http/public-assets.ts
22
49
  var DEFAULT_CACHE_CONTROL = "public, max-age=31536000, immutable";
23
50
  var DEFAULT_EXTENSIONS = [".svg", ".png", ".jpg", ".jpeg", ".gif", ".ico", ".webp", ".avif", ".webmanifest", ".txt"];
24
51
  var DEFAULT_CONTENT_TYPES = {
@@ -61,13 +88,16 @@ function registerRootPublicAssets(app, publicDir, config) {
61
88
  return next();
62
89
  }
63
90
  const candidatePath = resolve(publicDir, relativePath);
64
- if (!candidatePath.startsWith(publicDir + sep) && candidatePath !== publicDir) {
91
+ if (!isPathWithin(publicDir, candidatePath) && candidatePath !== publicDir) {
65
92
  return next();
66
93
  }
67
94
  const file = Bun.file(candidatePath);
68
95
  if (!await file.exists()) {
69
96
  return next();
70
97
  }
98
+ if (!await isRealPathWithin(publicDir, candidatePath)) {
99
+ return next();
100
+ }
71
101
  const headers = new Headers({
72
102
  "Cache-Control": cacheControlHeader,
73
103
  "Content-Type": contentTypeMap?.[extension] ?? DEFAULT_CONTENT_TYPES[extension] ?? "application/octet-stream"
@@ -112,6 +142,7 @@ function normalizeExtension(value) {
112
142
  var DEFAULT_PREFIX = "/resources/js";
113
143
  var DEFAULT_VENDOR_PATH = "/vendor/inertia-client.tsx";
114
144
  var DEFAULT_JSX_RUNTIME = "https://esm.sh/react@19.0.0/jsx-dev-runtime?dev";
145
+ var REACT_IMPORT_PATTERN = /from\s+['"]react['"]/u;
115
146
  function resolveInertiaClientRoute(inertiaClientPath) {
116
147
  const base = inertiaClientPath.slice(0, inertiaClientPath.lastIndexOf("/") + 1) || "/";
117
148
  return {
@@ -124,6 +155,9 @@ var require2 = createRequire(import.meta.url);
124
155
  function resolveGurenInertiaClient() {
125
156
  return require2.resolve("@guren/inertia-client/app");
126
157
  }
158
+ function resolveInertiaClientDir() {
159
+ return join(dirname(require2.resolve("@guren/inertia-client/package.json")), "dist");
160
+ }
127
161
  function registerDevAssets(app, options) {
128
162
  if (typeof Bun === "undefined") {
129
163
  throw new Error("Bun runtime is required for dev asset serving.");
@@ -140,7 +174,6 @@ function registerDevAssets(app, options) {
140
174
  const inertiaClientSource = options.inertiaClientSource ?? resolveGurenInertiaClient();
141
175
  const jsxRuntimeUrl = options.jsxRuntimeUrl ?? DEFAULT_JSX_RUNTIME;
142
176
  const resourcesJsDir = resolve2(resourcesDir, "js");
143
- const reactImportPattern = /from\s+['"]react['"]/u;
144
177
  const transpilerOptions = {
145
178
  target: "browser",
146
179
  jsx: "transform",
@@ -150,9 +183,12 @@ function registerDevAssets(app, options) {
150
183
  "process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV ?? "development")
151
184
  }
152
185
  };
153
- const tsxTranspiler = new Bun.Transpiler({ loader: "tsx", ...transpilerOptions });
154
- const tsTranspiler = new Bun.Transpiler({ loader: "ts", ...transpilerOptions });
155
- app.hono.get(`${prefix}/*`, (ctx) => handleTranspileRequest(ctx, resourcesJsDir, prefix, reactImportPattern, tsxTranspiler, tsTranspiler, jsxRuntimeUrl));
186
+ const transpile = {
187
+ tsx: new Bun.Transpiler({ loader: "tsx", ...transpilerOptions }),
188
+ ts: new Bun.Transpiler({ loader: "ts", ...transpilerOptions }),
189
+ jsxRuntimeUrl
190
+ };
191
+ app.hono.get(`${prefix}/*`, (ctx) => handleTranspileRequest(ctx, resourcesJsDir, prefix, transpile));
156
192
  if (cssDir) {
157
193
  const cssRewrite = createStaticRewrite(cssRoute);
158
194
  app.use(
@@ -173,13 +209,13 @@ function registerDevAssets(app, options) {
173
209
  app.hono.get(inertiaClientPattern, (ctx) => {
174
210
  const relativeRequest = ctx.req.path.slice(inertiaClientBase.length) || inertiaClientRequestPath;
175
211
  if (relativeRequest === inertiaClientRequestPath) {
176
- return transpileFile(inertiaClientSource, reactImportPattern, tsxTranspiler, tsTranspiler, jsxRuntimeUrl);
212
+ return transpileFile(inertiaClientSource, transpile);
177
213
  }
178
214
  const candidatePath = resolve2(inertiaClientDir, relativeRequest);
179
- if (!candidatePath.startsWith(inertiaClientDir)) {
215
+ if (!isPathWithin(inertiaClientDir, candidatePath)) {
180
216
  return ctx.notFound();
181
217
  }
182
- return transpileFile(candidatePath, reactImportPattern, tsxTranspiler, tsTranspiler, jsxRuntimeUrl);
218
+ return transpileFile(candidatePath, transpile, inertiaClientDir);
183
219
  });
184
220
  }
185
221
  const publicPathOption = options.publicPath === void 0 ? "../public" : options.publicPath;
@@ -219,15 +255,15 @@ function createStaticRewrite(route) {
219
255
  return remainder.startsWith("/") ? remainder : `/${remainder}`;
220
256
  };
221
257
  }
222
- async function handleTranspileRequest(ctx, resourcesJsDir, prefix, reactImportPattern, tsxTranspiler, tsTranspiler, jsxRuntimeUrl) {
258
+ async function handleTranspileRequest(ctx, resourcesJsDir, prefix, transpile) {
223
259
  const relative = ctx.req.path.slice(prefix.length + 1);
224
260
  const fsPath = resolve2(resourcesJsDir, relative);
225
- if (!fsPath.startsWith(resourcesJsDir)) {
261
+ if (!isPathWithin(resourcesJsDir, fsPath)) {
226
262
  return ctx.notFound();
227
263
  }
228
- return transpileFile(fsPath, reactImportPattern, tsxTranspiler, tsTranspiler, jsxRuntimeUrl);
264
+ return transpileFile(fsPath, transpile, resourcesJsDir);
229
265
  }
230
- async function transpileFile(fsPath, reactImportPattern, tsxTranspiler, tsTranspiler, jsxRuntimeUrl) {
266
+ async function transpileFile(fsPath, transpile, containmentRoot) {
231
267
  const candidates = buildCandidatePaths(fsPath);
232
268
  let filePath;
233
269
  let file;
@@ -242,23 +278,23 @@ async function transpileFile(fsPath, reactImportPattern, tsxTranspiler, tsTransp
242
278
  if (!file || !filePath) {
243
279
  return new Response("Not Found", { status: 404 });
244
280
  }
281
+ if (containmentRoot && !await isRealPathWithin(containmentRoot, filePath)) {
282
+ return new Response("Not Found", { status: 404 });
283
+ }
245
284
  const ext = extname2(filePath);
246
285
  let source = await file.text();
247
- if (ext === ".tsx" && !reactImportPattern.test(source)) {
286
+ if (ext === ".tsx" && !REACT_IMPORT_PATTERN.test(source)) {
248
287
  source = "import React from 'react'\n" + source;
249
288
  }
250
289
  if (ext === ".tsx" || ext === ".ts") {
251
- const transpiled = ext === ".tsx" ? tsxTranspiler.transformSync(source, {
252
- loader: "tsx",
253
- sourceMap: isDev() ? "inline" : false,
254
- filename: filePath
255
- }) : tsTranspiler.transformSync(source, {
256
- loader: "ts",
290
+ const loader = ext === ".tsx" ? "tsx" : "ts";
291
+ const transpiled = transpile[loader].transformSync(source, {
292
+ loader,
257
293
  sourceMap: isDev() ? "inline" : false,
258
294
  filename: filePath
259
295
  });
260
296
  const helpers = collectJsxHelpers(transpiled);
261
- const runtimeShim = helpers.size ? createJsxRuntimeShim(helpers, jsxRuntimeUrl) : "";
297
+ const runtimeShim = helpers.size ? createJsxRuntimeShim(helpers, transpile.jsxRuntimeUrl) : "";
262
298
  return new Response(runtimeShim + transpiled, {
263
299
  headers: {
264
300
  "Content-Type": "application/javascript; charset=utf-8",
@@ -315,11 +351,10 @@ function deriveCssRoute(prefix) {
315
351
 
316
352
  // src/http/inertia-assets.ts
317
353
  import { serveStatic as serveStatic2 } from "hono/bun";
318
- import { dirname as dirname2, resolve as resolve3, join } from "path";
354
+ import { dirname as dirname2, resolve as resolve3, join as join2 } from "path";
319
355
  import { fileURLToPath as fileURLToPath2 } from "url";
320
356
  import { readFileSync } from "fs";
321
357
  var DEFAULT_STYLES_ENTRY = "/public/assets/app.css";
322
- var DEFAULT_DEV_STYLES_ENTRY = "/resources/css/app.css";
323
358
  var DEFAULT_SCRIPT_ENTRY = "/assets/app.js";
324
359
  var DEFAULT_VENDOR_CLIENT_PATH = "/vendor/inertia-client.tsx";
325
360
  function configureInertiaAssets(app, options) {
@@ -366,55 +401,53 @@ function configureInertiaAssets(app, options) {
366
401
  app.hono.get("/favicon.ico", () => new Response(null, { status: 204 }));
367
402
  }
368
403
  registerRootPublicAssets(app, publicDir, options.rootPublicAssets);
369
- if (isProduction && options.inertiaClient !== false) {
404
+ if (options.inertiaClient !== false) {
370
405
  try {
371
- let inertiaClientEntry;
372
- if (typeof import.meta.resolve === "function") {
373
- try {
374
- const resolved = import.meta.resolve("@guren/inertia-client/app", import.meta.url);
375
- inertiaClientEntry = fileURLToPath2(new URL(resolved));
376
- } catch {
377
- inertiaClientEntry = void 0;
378
- }
379
- }
380
- if (!inertiaClientEntry) {
381
- throw new Error("Unable to resolve @guren/inertia-client entry");
382
- }
383
- const inertiaClientDir = dirname2(inertiaClientEntry);
384
- const inertiaClientPath = options.inertiaClientPath ?? DEFAULT_VENDOR_CLIENT_PATH;
385
- const {
386
- base: inertiaClientBase,
387
- pattern: inertiaClientPattern,
388
- requestPath: inertiaClientRequestPath
389
- } = resolveInertiaClientRoute(inertiaClientPath);
390
- app.hono.get(inertiaClientPattern, async (ctx) => {
391
- const relativeRequest = ctx.req.path.slice(inertiaClientBase.length) || inertiaClientRequestPath;
392
- let targetPath;
393
- if (relativeRequest === inertiaClientRequestPath) {
394
- targetPath = join(inertiaClientDir, "app.js");
395
- } else {
396
- targetPath = resolve3(inertiaClientDir, relativeRequest);
397
- if (!targetPath.startsWith(inertiaClientDir)) {
398
- return ctx.notFound();
399
- }
400
- }
401
- const file = Bun.file(targetPath);
402
- if (!await file.exists()) {
403
- return ctx.notFound();
404
- }
405
- const contentType = file.type || "application/javascript; charset=utf-8";
406
- return new Response(file, {
407
- headers: {
408
- "Content-Type": contentType,
409
- "Cache-Control": "public, max-age=31536000"
410
- }
411
- });
412
- });
406
+ registerBuiltInertiaClient(
407
+ app,
408
+ resolveInertiaClientDir(),
409
+ options.inertiaClientPath ?? DEFAULT_VENDOR_CLIENT_PATH
410
+ );
413
411
  } catch (error) {
414
- console.warn("Unable to resolve @guren/inertia-client/app for production serving.", error);
412
+ console.warn("Unable to resolve @guren/inertia-client for production serving.", error);
415
413
  }
416
414
  }
417
415
  }
416
+ function registerBuiltInertiaClient(app, inertiaClientDir, inertiaClientPath) {
417
+ const {
418
+ base: inertiaClientBase,
419
+ pattern: inertiaClientPattern,
420
+ requestPath: inertiaClientRequestPath
421
+ } = resolveInertiaClientRoute(inertiaClientPath);
422
+ app.hono.get(inertiaClientPattern, async (ctx) => {
423
+ const relativeRequest = ctx.req.path.slice(inertiaClientBase.length) || inertiaClientRequestPath;
424
+ let targetPath;
425
+ let containmentRoot;
426
+ if (relativeRequest === inertiaClientRequestPath) {
427
+ targetPath = join2(inertiaClientDir, "app.js");
428
+ } else {
429
+ targetPath = resolve3(inertiaClientDir, relativeRequest);
430
+ containmentRoot = inertiaClientDir;
431
+ if (!isPathWithin(containmentRoot, targetPath)) {
432
+ return ctx.notFound();
433
+ }
434
+ }
435
+ const file = Bun.file(targetPath);
436
+ if (!await file.exists()) {
437
+ return ctx.notFound();
438
+ }
439
+ if (containmentRoot && !await isRealPathWithin(containmentRoot, targetPath)) {
440
+ return ctx.notFound();
441
+ }
442
+ const contentType = file.type || "application/javascript; charset=utf-8";
443
+ return new Response(file, {
444
+ headers: {
445
+ "Content-Type": contentType,
446
+ "Cache-Control": "public, max-age=31536000"
447
+ }
448
+ });
449
+ });
450
+ }
418
451
  function autoConfigureInertiaAssets(app, options) {
419
452
  const providedEnv = captureInertiaEnvFlags();
420
453
  configureInertiaAssets(app, options);
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Is `candidate` a path strictly below `root`, judged lexically?
3
+ *
4
+ * The trailing separator is what keeps out a sibling directory whose name
5
+ * merely extends the root's (`…/inertia` vs `…/inertia-secrets`), and what
6
+ * rejects an absolute `candidate` — which `resolve()` returns verbatim when a
7
+ * doubled slash in the request path left the relative part rooted.
8
+ *
9
+ * Cheap, but not sufficient on its own: `resolve()` collapses `..` without
10
+ * following symlinks. Use {@link isRealPathWithin} before reading the file.
11
+ */
12
+ export declare function isPathWithin(root: string, candidate: string): boolean;
13
+ /**
14
+ * Is `candidate` a path strictly below `root` once both are canonicalized?
15
+ *
16
+ * Every reader downstream of these checks (`Bun.file().text()`,
17
+ * `.arrayBuffer()`, `new Response(file)`) follows symlinks, so a lexical check
18
+ * alone accepts `<root>/link/secret` where `link` points out of the tree.
19
+ * *Both* sides are canonicalized: a root reached through a symlink itself is
20
+ * routine (workspace and pnpm layouts, macOS `/var` → `/private/var`), and
21
+ * canonicalizing only the candidate would 404 every asset such an app serves.
22
+ *
23
+ * Call this on a path already known to exist — a path that does not exist
24
+ * cannot be read, and `realpath` rejects it, so either way this fails closed.
25
+ */
26
+ export declare function isRealPathWithin(root: string, candidate: string): Promise<boolean>;
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Expiry coercion and the one predicate that decides whether a stored expiry
3
+ * has passed.
4
+ *
5
+ * This is the single copy. `packages/core/src/store-utils.ts` re-exports
6
+ * `toDate`/`isExpired`/`toOptionalExpiry` from here through the
7
+ * `@guren/server/support/expiry` subpath, so the database-backed stores and
8
+ * the Redis ones decide expiry with the same code. It lives in this package
9
+ * because `@guren/core` depends on `@guren/server` and not the other way
10
+ * around — core is unreachable from here without a dependency cycle.
11
+ *
12
+ * Not part of the public API: the subpath exists for that re-export, and
13
+ * neither package's index exposes these.
14
+ */
15
+ /**
16
+ * Coerce a stored timestamp, rejecting anything unparseable.
17
+ *
18
+ * Accepts every shape a driver or a Redis value can hand back: Date, number,
19
+ * bigint (MySQL / postgres.js BIGINT), digit-only strings as epoch
20
+ * milliseconds, and ISO strings. A Date wrapping garbage is a parse failure,
21
+ * not a value — `new Date(garbage)` yields an Invalid Date whose comparisons
22
+ * are all false, which is exactly how a corrupt expiry reads as "not past".
23
+ */
24
+ export declare function toDate(value: unknown): Date | null;
25
+ /**
26
+ * Whether an expiry that is required to be present has passed.
27
+ *
28
+ * Missing or unparseable counts as expired, so a malformed record can never be
29
+ * accepted indefinitely. Use for sessions and OAuth state, whose writers always
30
+ * supply an expiry.
31
+ */
32
+ export declare function isExpired(value: unknown, now?: number): boolean;
33
+ /**
34
+ * Whether an expiry that is allowed to be absent has passed.
35
+ *
36
+ * Absent means "never expires" and is never past. Present-but-unparseable is a
37
+ * malformed record and counts as expired — collapsing the two is the fail-open
38
+ * this exists to close. Use at the point of comparison, so the check holds for
39
+ * every store implementation including ones this package never sees.
40
+ */
41
+ export declare function isOptionalExpiryPast(value: unknown, now?: number): boolean;
42
+ /**
43
+ * Coerce an expiry that is allowed to be absent into a value callers can
44
+ * compare directly: absent stays null, present-but-unparseable degrades to a
45
+ * long-past date rather than to null, which would read as "never expires".
46
+ */
47
+ export declare function toOptionalExpiry(value: unknown): Date | null;
@@ -0,0 +1,12 @@
1
+ import {
2
+ isExpired,
3
+ isOptionalExpiryPast,
4
+ toDate,
5
+ toOptionalExpiry
6
+ } from "../chunk-3KV5X2FL.js";
7
+ export {
8
+ isExpired,
9
+ isOptionalExpiryPast,
10
+ toDate,
11
+ toOptionalExpiry
12
+ };
@@ -0,0 +1,13 @@
1
+ /**
2
+ * The stylesheet *source* path the dev asset configuration falls back to.
3
+ *
4
+ * Lives in a leaf module because two sides read it and must agree: the dev
5
+ * configuration in `http/inertia-assets.ts` publishes it into
6
+ * `GUREN_INERTIA_STYLES`, and the document renderer in
7
+ * `mvc/inertia/InertiaEngine.ts` drops exactly this path again when a dev
8
+ * server owns the script entry (the compiled CSS then arrives through the
9
+ * module graph). Importing either of those modules from the other would drag
10
+ * runtime-specific dependencies across the Workers/Lambda boundary or create
11
+ * an import cycle.
12
+ */
13
+ export declare const DEFAULT_DEV_STYLES_ENTRY = "/resources/css/app.css";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@guren/server",
3
- "version": "2.2.0",
3
+ "version": "2.4.0",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -100,6 +100,10 @@
100
100
  "./redis": {
101
101
  "types": "./dist/redis/index.d.ts",
102
102
  "default": "./dist/redis/index.js"
103
+ },
104
+ "./support/expiry": {
105
+ "types": "./dist/support/expiry.d.ts",
106
+ "default": "./dist/support/expiry.js"
103
107
  }
104
108
  },
105
109
  "scripts": {
@@ -109,7 +113,7 @@
109
113
  "test": "bun test"
110
114
  },
111
115
  "dependencies": {
112
- "@guren/orm": "^2.2.0",
116
+ "@guren/orm": "^2.2.2",
113
117
  "@modelcontextprotocol/sdk": "^1.30.0",
114
118
  "chalk": "^5.3.0",
115
119
  "consola": "^3.4.2",
@@ -1,8 +0,0 @@
1
- import {
2
- McpServiceProvider
3
- } from "./chunk-CDZUNKI6.js";
4
- import "./chunk-JBG4AR24.js";
5
- import "./chunk-BZMZEFRG.js";
6
- export {
7
- McpServiceProvider
8
- };