@guren/server 1.5.0 → 2.1.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 (53) hide show
  1. package/dist/{AuthManager-C84xF5ks.d.ts → AuthManager-DBP4KYsx.d.ts} +1 -1
  2. package/dist/{ConsoleKernel-D0dkFt6u.d.ts → ConsoleKernel-CJg975mp.d.ts} +1 -1
  3. package/dist/DocsViewerServiceProvider-D7RGJPGM.js +75 -0
  4. package/dist/{I18nManager-CmUqj6bU.d.ts → I18nManager-BiSoczfV.d.ts} +1 -1
  5. package/dist/McpServiceProvider-7BB5FPF3.js +8 -0
  6. package/dist/auth/index.d.ts +39 -29
  7. package/dist/auth/index.js +2 -2
  8. package/dist/broadcasting/index.js +2 -2
  9. package/dist/cache/index.js +2 -2
  10. package/dist/chunk-2V3YID4H.js +20 -0
  11. package/dist/chunk-AZOYI43J.js +18 -0
  12. package/dist/{chunk-DCYKSYAT.js → chunk-B5E5VBDI.js} +54 -2
  13. package/dist/{chunk-NYQGAWDN.js → chunk-BZMZEFRG.js} +7 -11
  14. package/dist/{chunk-4SBGSJNT.js → chunk-CWI4AJ47.js} +2 -1
  15. package/dist/{chunk-NQCZQAJL.js → chunk-DSDX3ASM.js} +21 -2
  16. package/dist/{chunk-SHYRVOMJ.js → chunk-EARA7JM4.js} +3 -3
  17. package/dist/{chunk-MC752CQT.js → chunk-EI5GYMAT.js} +2 -1
  18. package/dist/{chunk-AUXQISW5.js → chunk-HONCNQXZ.js} +38 -5
  19. package/dist/{chunk-CSRQTEQA.js → chunk-HWEWL6TE.js} +6 -1
  20. package/dist/chunk-JBG4AR24.js +18 -0
  21. package/dist/{chunk-RNXTRWKL.js → chunk-K6CUBJX6.js} +9 -15
  22. package/dist/{chunk-Z3HXKWI6.js → chunk-KTNJG7R7.js} +4 -0
  23. package/dist/{chunk-74HTZG3V.js → chunk-LAJQCSSF.js} +24 -0
  24. package/dist/{chunk-H32L2NE3.js → chunk-LVJCZCAV.js} +20 -13
  25. package/dist/{chunk-5AD7LYWO.js → chunk-N7PLD7MB.js} +9 -8
  26. package/dist/{chunk-ONSDE37A.js → chunk-SFQP6O52.js} +1 -0
  27. package/dist/{chunk-XMQZENBP.js → chunk-TVY72CLV.js} +3 -1
  28. package/dist/chunk-WIXGT4TN.js +18 -0
  29. package/dist/{email-verification-H_WlpsVH.d.ts → email-verification-D60YF2ZO.d.ts} +5 -3
  30. package/dist/encryption/index.js +2 -2
  31. package/dist/events/index.js +1 -1
  32. package/dist/i18n/index.d.ts +2 -2
  33. package/dist/index.d.ts +333 -333
  34. package/dist/index.js +242 -88
  35. package/dist/lambda/index.d.ts +5 -5
  36. package/dist/mail/index.js +3 -2
  37. package/dist/mcp/index.d.ts +14 -4
  38. package/dist/mcp/index.js +3 -2
  39. package/dist/notifications/index.d.ts +5 -5
  40. package/dist/notifications/index.js +3 -2
  41. package/dist/queue/index.d.ts +5 -5
  42. package/dist/queue/index.js +1 -1
  43. package/dist/redis/index.d.ts +4 -4
  44. package/dist/redis/index.js +7 -0
  45. package/dist/runtime/index.d.ts +5 -5
  46. package/dist/runtime/index.js +24 -9
  47. package/dist/scheduling/index.js +2 -2
  48. package/dist/storage/index.js +2 -1
  49. package/dist/{Application-Bi-olFMF.d.ts → validation-yAL53e1S.d.ts} +776 -721
  50. package/package.json +3 -3
  51. package/dist/McpServiceProvider-TZWQWXCT.js +0 -7
  52. package/dist/{api-token-COQHXyM_.d.ts → api-token-D24VPr_E.d.ts} +101 -101
  53. package/dist/{client-BQwF2b9Y.d.ts → rate-limit-D9J2b4S1.d.ts} +36 -36
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@ import {
2
2
  logDevServerBanner,
3
3
  parseImportMap,
4
4
  startViteDevServer
5
- } from "./chunk-SHYRVOMJ.js";
5
+ } from "./chunk-EARA7JM4.js";
6
6
  import {
7
7
  PendingSchedule,
8
8
  Schedule,
@@ -16,14 +16,20 @@ import {
16
16
  matchesCron,
17
17
  parseCron,
18
18
  toTimezone
19
- } from "./chunk-MC752CQT.js";
19
+ } from "./chunk-EI5GYMAT.js";
20
20
  import {
21
21
  LocalDriver,
22
22
  MemoryDriver as MemoryDriver3,
23
23
  S3Driver,
24
24
  StorageManager,
25
25
  createStorageManager
26
- } from "./chunk-CSRQTEQA.js";
26
+ } from "./chunk-HWEWL6TE.js";
27
+ import {
28
+ trimSlashes
29
+ } from "./chunk-AZOYI43J.js";
30
+ import {
31
+ isDocsViewerEnabled
32
+ } from "./chunk-WIXGT4TN.js";
27
33
  import {
28
34
  I18nManager,
29
35
  JsonLoader,
@@ -61,13 +67,15 @@ import {
61
67
  getMailManager,
62
68
  mail,
63
69
  setMailManager
64
- } from "./chunk-RNXTRWKL.js";
70
+ } from "./chunk-K6CUBJX6.js";
65
71
  import {
66
72
  MCP_ENDPOINT_PATH,
67
- ProviderManager,
68
- ServiceProvider,
69
73
  isMcpEndpointEnabled
70
- } from "./chunk-NYQGAWDN.js";
74
+ } from "./chunk-JBG4AR24.js";
75
+ import {
76
+ ProviderManager,
77
+ ServiceProvider
78
+ } from "./chunk-BZMZEFRG.js";
71
79
  import {
72
80
  DatabaseChannel,
73
81
  MailChannel,
@@ -82,7 +90,8 @@ import {
82
90
  registerNotification,
83
91
  resolveNotifiableType,
84
92
  setNotificationManager
85
- } from "./chunk-5AD7LYWO.js";
93
+ } from "./chunk-N7PLD7MB.js";
94
+ import "./chunk-2V3YID4H.js";
86
95
  import {
87
96
  FailedJobReporter,
88
97
  MemoryDriver,
@@ -94,7 +103,7 @@ import {
94
103
  createQueueManager,
95
104
  createSqsAdapter,
96
105
  processJob
97
- } from "./chunk-Z3HXKWI6.js";
106
+ } from "./chunk-KTNJG7R7.js";
98
107
  import {
99
108
  Container,
100
109
  Job,
@@ -169,7 +178,7 @@ import {
169
178
  verifyEmailToken,
170
179
  verifyOAuthState,
171
180
  verifyPasswordResetToken
172
- } from "./chunk-AUXQISW5.js";
181
+ } from "./chunk-HONCNQXZ.js";
173
182
  import {
174
183
  Gate,
175
184
  Policy,
@@ -219,7 +228,7 @@ import {
219
228
  getBroadcastManager,
220
229
  parseRequestPayload,
221
230
  setBroadcastManager
222
- } from "./chunk-XMQZENBP.js";
231
+ } from "./chunk-TVY72CLV.js";
223
232
  import {
224
233
  CacheManager,
225
234
  FileStore,
@@ -227,11 +236,12 @@ import {
227
236
  RedisStore,
228
237
  TaggedCache,
229
238
  createCacheManager
230
- } from "./chunk-4SBGSJNT.js";
239
+ } from "./chunk-CWI4AJ47.js";
231
240
  import {
232
241
  claimHotDisposable,
233
- isHotReloadRuntime
234
- } from "./chunk-DCYKSYAT.js";
242
+ isHotReloadRuntime,
243
+ matchingOpenParen
244
+ } from "./chunk-B5E5VBDI.js";
235
245
  import {
236
246
  Encrypter,
237
247
  createEncrypter,
@@ -256,7 +266,7 @@ import {
256
266
  urlSafeToken,
257
267
  uuid,
258
268
  verifySignedUrl
259
- } from "./chunk-H32L2NE3.js";
269
+ } from "./chunk-LVJCZCAV.js";
260
270
  import {
261
271
  MessageSigner,
262
272
  deriveAppKey,
@@ -267,7 +277,7 @@ import {
267
277
  normalizeAppKey,
268
278
  parseAppKey,
269
279
  parsePreviousAppKeys
270
- } from "./chunk-ONSDE37A.js";
280
+ } from "./chunk-SFQP6O52.js";
271
281
  import {
272
282
  check,
273
283
  hash,
@@ -294,7 +304,7 @@ import {
294
304
  UserAuthenticated,
295
305
  UserLoggedOut,
296
306
  createEventManager
297
- } from "./chunk-74HTZG3V.js";
307
+ } from "./chunk-LAJQCSSF.js";
298
308
  import {
299
309
  CacheCheck,
300
310
  CustomCheck,
@@ -378,7 +388,33 @@ function mountRoute(app, method, path, ...handlers) {
378
388
  app.on(method, path, ...handlers);
379
389
  }
380
390
 
391
+ // src/http/middleware/capabilities.ts
392
+ var CAPABILITIES = /* @__PURE__ */ Symbol.for("guren.capabilities");
393
+ function stampCapabilities(handler, capabilities) {
394
+ Object.defineProperty(handler, CAPABILITIES, { value: capabilities, enumerable: false });
395
+ return handler;
396
+ }
397
+ function capabilitiesOf(handler) {
398
+ if (typeof handler !== "function") return void 0;
399
+ return handler[CAPABILITIES];
400
+ }
401
+
381
402
  // src/mvc/Router.ts
403
+ function assertSyncGroupCallback(result, method) {
404
+ if (typeof result?.then !== "function") return;
405
+ throw new Error(
406
+ `Router.${method}() callback returned a promise. Group scopes are applied synchronously, so routes registered after an await would silently lose the group's prefix and middleware. Register the routes synchronously, and await anything they depend on before opening the group.`
407
+ );
408
+ }
409
+ function partitionMiddleware(items) {
410
+ const names = [];
411
+ const handlers = [];
412
+ for (const item of items) {
413
+ if (typeof item === "string") names.push(item);
414
+ else handlers.push(item);
415
+ }
416
+ return { names, handlers };
417
+ }
382
418
  var RESOURCE_ACTIONS = [
383
419
  { method: "index", suffix: "", httpMethod: "get" },
384
420
  { method: "create", suffix: "/create", httpMethod: "get" },
@@ -406,8 +442,12 @@ var Router = class {
406
442
  this.middlewareGroups.set(name, middlewareNames);
407
443
  return this;
408
444
  }
409
- middleware(...names) {
410
- return new RouterMiddlewareGroupBuilder(this, names);
445
+ /**
446
+ * Open a middleware scope for the routes registered through the returned
447
+ * builder. See {@link RouteMiddlewareInput}.
448
+ */
449
+ middleware(...items) {
450
+ return new RouterMiddlewareGroupBuilder(this, items);
411
451
  }
412
452
  bind(param, modelOrResolver) {
413
453
  if (typeof modelOrResolver === "function" && "findOrFail" in modelOrResolver) {
@@ -446,8 +486,11 @@ var Router = class {
446
486
  }
447
487
  group(prefix, callback) {
448
488
  this.prefixStack.push(prefix);
449
- callback(this);
450
- this.prefixStack.pop();
489
+ try {
490
+ assertSyncGroupCallback(callback(this), "group");
491
+ } finally {
492
+ this.prefixStack.pop();
493
+ }
451
494
  return this;
452
495
  }
453
496
  route(name, params = {}) {
@@ -480,7 +523,8 @@ var Router = class {
480
523
  const resolvedMiddlewares = this.resolveMiddlewareNames(route.routeMiddlewareNames);
481
524
  const handler = resolveHandler(route.handler, this.modelBindings, options.container, route.bindings, route.path);
482
525
  const contractMiddleware = createContractValidationMiddleware(route);
483
- const allMiddlewares = contractMiddleware ? [...resolvedMiddlewares, ...route.middlewares, contractMiddleware, handler] : [...resolvedMiddlewares, ...route.middlewares, handler];
526
+ const inlineMiddlewares = [...route.scopedMiddlewares, ...route.middlewares];
527
+ const allMiddlewares = contractMiddleware ? [...resolvedMiddlewares, ...inlineMiddlewares, contractMiddleware, handler] : [...resolvedMiddlewares, ...inlineMiddlewares, handler];
484
528
  mountRoute(app, route.method, route.path, ...allMiddlewares);
485
529
  }
486
530
  }
@@ -497,20 +541,24 @@ var Router = class {
497
541
  this.modelBindingNames.clear();
498
542
  }
499
543
  definitions() {
500
- return this.registry.map(({ method, path, name, schemas, openapi, routeMiddlewareNames, middlewares, handler, bindings }) => ({
544
+ return this.registry.map(({ method, path, name, schemas, openapi, routeMiddlewareNames, middlewares, scopedMiddlewares, handler, bindings }) => ({
501
545
  method,
502
546
  path,
503
547
  name,
504
548
  schemas,
505
549
  middlewareNames: [...routeMiddlewareNames],
550
+ // Route-local only, so a group-scoped handler does not make every route
551
+ // in the group report middleware it never attached (`guren audit` warns
552
+ // per route on this flag). Capabilities still see the whole chain.
506
553
  hasInlineMiddleware: middlewares.length > 0,
554
+ capabilities: this.aggregateCapabilities(routeMiddlewareNames, [...scopedMiddlewares, ...middlewares]),
507
555
  controller: isControllerAction(handler) ? { name: handler[0].name, action: String(handler[1]) } : void 0,
508
556
  bindings: serializeBindings(path, bindings, this.modelBindingNames),
509
557
  ...openapi
510
558
  }));
511
559
  }
512
- applyMiddlewareScope(names, callback) {
513
- this.middlewareStack.push(names);
560
+ applyMiddlewareScope(items, callback) {
561
+ this.middlewareStack.push([...items]);
514
562
  try {
515
563
  return callback();
516
564
  } finally {
@@ -545,17 +593,51 @@ var Router = class {
545
593
  }
546
594
  add(method, path, handler, middlewares = []) {
547
595
  const fullPath = joinPaths(this.prefixStack, path);
548
- const stackMiddleware = this.middlewareStack.flat();
596
+ const scope = partitionMiddleware(this.middlewareStack.flat());
549
597
  const route = {
550
598
  method,
551
599
  path: fullPath,
552
600
  handler,
553
- middlewares,
554
- routeMiddlewareNames: [...stackMiddleware]
601
+ // Copied, never aliased: `RouteBuilder.middleware()` pushes here, and the
602
+ // caller's `options.middlewares` array may be shared across routes.
603
+ middlewares: [...middlewares],
604
+ scopedMiddlewares: scope.handlers,
605
+ routeMiddlewareNames: scope.names
555
606
  };
556
607
  this.registry.push(route);
557
608
  return createRouteBuilder(route, this.namedRoutes);
558
609
  }
610
+ /**
611
+ * Security capabilities present on a route's middleware chain, aggregated
612
+ * across named aliases (group-expanded) and inline handlers. Unlike
613
+ * `resolveMiddlewareNames`, unregistered names are skipped rather than
614
+ * thrown: `definitions()` must stay side-effect-free for introspection of
615
+ * routers that never mount (audit, codegen), and an unresolvable alias
616
+ * simply contributes no capabilities.
617
+ */
618
+ aggregateCapabilities(names, inline, seen) {
619
+ const aggregated = {};
620
+ const visited = seen ?? /* @__PURE__ */ new Set();
621
+ const absorb = (capabilities) => {
622
+ const auth = capabilities?.authentication;
623
+ if (!auth) return;
624
+ if (!aggregated.authentication || auth.mode === "required") {
625
+ aggregated.authentication = auth;
626
+ }
627
+ };
628
+ for (const name of names) {
629
+ if (visited.has(name)) continue;
630
+ visited.add(name);
631
+ const groupNames = this.middlewareGroups.get(name);
632
+ if (groupNames) {
633
+ absorb(this.aggregateCapabilities(groupNames, [], visited));
634
+ continue;
635
+ }
636
+ absorb(capabilitiesOf(this.middlewareAliases.get(name)));
637
+ }
638
+ for (const handler of inline) absorb(capabilitiesOf(handler));
639
+ return aggregated;
640
+ }
559
641
  resolveMiddlewareNames(names, seen) {
560
642
  const handlers = [];
561
643
  const visited = seen ?? /* @__PURE__ */ new Set();
@@ -594,30 +676,32 @@ function applyRouteContract(route, options) {
594
676
  }
595
677
  }
596
678
  var RouterMiddlewareGroupBuilder = class {
597
- constructor(router, names) {
679
+ constructor(router, items) {
598
680
  this.router = router;
599
- this.names = names;
681
+ this.items = items;
600
682
  }
683
+ router;
684
+ items;
601
685
  group(callback) {
602
- return this.router.applyMiddlewareScope(this.names, () => {
603
- callback(this.router);
686
+ return this.router.applyMiddlewareScope(this.items, () => {
687
+ assertSyncGroupCallback(callback(this.router), "middleware(...).group");
604
688
  return this.router;
605
689
  });
606
690
  }
607
691
  get(path, handlerOrOptions, ...rest) {
608
- return this.router.applyMiddlewareScope(this.names, () => this.router.get(path, handlerOrOptions, ...rest));
692
+ return this.router.applyMiddlewareScope(this.items, () => this.router.get(path, handlerOrOptions, ...rest));
609
693
  }
610
694
  post(path, handlerOrOptions, ...rest) {
611
- return this.router.applyMiddlewareScope(this.names, () => this.router.post(path, handlerOrOptions, ...rest));
695
+ return this.router.applyMiddlewareScope(this.items, () => this.router.post(path, handlerOrOptions, ...rest));
612
696
  }
613
697
  put(path, handlerOrOptions, ...rest) {
614
- return this.router.applyMiddlewareScope(this.names, () => this.router.put(path, handlerOrOptions, ...rest));
698
+ return this.router.applyMiddlewareScope(this.items, () => this.router.put(path, handlerOrOptions, ...rest));
615
699
  }
616
700
  patch(path, handlerOrOptions, ...rest) {
617
- return this.router.applyMiddlewareScope(this.names, () => this.router.patch(path, handlerOrOptions, ...rest));
701
+ return this.router.applyMiddlewareScope(this.items, () => this.router.patch(path, handlerOrOptions, ...rest));
618
702
  }
619
703
  delete(path, handlerOrOptions, ...rest) {
620
- return this.router.applyMiddlewareScope(this.names, () => this.router.delete(path, handlerOrOptions, ...rest));
704
+ return this.router.applyMiddlewareScope(this.items, () => this.router.delete(path, handlerOrOptions, ...rest));
621
705
  }
622
706
  };
623
707
  function createRouteBuilder(route, namedRoutes) {
@@ -627,8 +711,10 @@ function createRouteBuilder(route, namedRoutes) {
627
711
  namedRoutes.set(routeName, route);
628
712
  return this;
629
713
  },
630
- middleware(...names) {
714
+ middleware(...items) {
715
+ const { names, handlers } = partitionMiddleware(items);
631
716
  route.routeMiddlewareNames.push(...names);
717
+ route.middlewares.push(...handlers);
632
718
  return this;
633
719
  }
634
720
  };
@@ -665,30 +751,41 @@ function createContractHandler(path, options, handler) {
665
751
  if (!options.output) {
666
752
  return result;
667
753
  }
754
+ let outputValue = result;
755
+ let sourceBody;
668
756
  if (result instanceof Response) {
669
757
  try {
670
- const cloned = result.clone();
671
- const body2 = await cloned.json();
672
- const output2 = options.output.safeParse(body2);
673
- if (!output2.success) {
674
- throw new Error(
675
- `Route output validation failed for ${options.name ?? path}: ${JSON.stringify(formatValidationErrors(output2.error))}`
676
- );
677
- }
678
- } catch (err) {
679
- if (err instanceof Error && err.message.includes("output validation failed")) throw err;
758
+ sourceBody = await result.clone().text();
759
+ outputValue = JSON.parse(sourceBody);
760
+ } catch {
761
+ return result;
680
762
  }
681
- return result;
682
763
  }
683
- const output = options.output.safeParse(result);
684
- if (output.success) {
764
+ const output = options.output.safeParse(outputValue);
765
+ if (!output.success) {
766
+ throw new Error(
767
+ `Route output validation failed for ${options.name ?? path}: ${JSON.stringify(formatValidationErrors(output.error))}`
768
+ );
769
+ }
770
+ if (!(result instanceof Response)) {
685
771
  return output.data;
686
772
  }
687
- throw new Error(
688
- `Route output validation failed for ${options.name ?? path}: ${JSON.stringify(formatValidationErrors(output.error))}`
689
- );
773
+ return rebuildJsonResponse(result, sourceBody, output.data) ?? result;
690
774
  };
691
775
  }
776
+ function rebuildJsonResponse(source, sourceBody, data) {
777
+ const body = JSON.stringify(data);
778
+ if (body === sourceBody) {
779
+ return null;
780
+ }
781
+ const headers = new Headers(source.headers);
782
+ dropStaleBodyHeaders(headers);
783
+ return new Response(body, { status: source.status, headers });
784
+ }
785
+ function dropStaleBodyHeaders(headers) {
786
+ headers.delete("content-length");
787
+ headers.delete("etag");
788
+ }
692
789
  function parseRouteSegment(schema, data, status) {
693
790
  if (!schema) {
694
791
  return data;
@@ -733,15 +830,24 @@ function createContractValidationMiddleware(route) {
733
830
  }
734
831
  await next();
735
832
  if (schemas.output && c.res) {
833
+ let sourceBody;
834
+ let parsedBody;
736
835
  try {
737
- const cloned = c.res.clone();
738
- const body = await cloned.json();
739
- const parsed = schemas.output.safeParse(body);
740
- if (!parsed.success) {
741
- const errors = "flatten" in parsed.error && typeof parsed.error.flatten === "function" ? parsed.error.flatten() : parsed.error;
742
- c.res = c.json({ message: "Response validation failed", errors }, 500);
743
- }
836
+ sourceBody = await c.res.clone().text();
837
+ parsedBody = JSON.parse(sourceBody);
744
838
  } catch {
839
+ return;
840
+ }
841
+ const parsed = schemas.output.safeParse(parsedBody);
842
+ if (!parsed.success) {
843
+ const errors = "flatten" in parsed.error && typeof parsed.error.flatten === "function" ? parsed.error.flatten() : parsed.error;
844
+ c.res = c.json({ message: "Response validation failed", errors }, 500);
845
+ return;
846
+ }
847
+ const rebuilt = rebuildJsonResponse(c.res, sourceBody, parsed.data);
848
+ if (rebuilt) {
849
+ c.res = rebuilt;
850
+ dropStaleBodyHeaders(c.res.headers);
745
851
  }
746
852
  }
747
853
  };
@@ -855,7 +961,7 @@ function isRouteContractOptions(value) {
855
961
  return "params" in value || "query" in value || "body" in value || "output" in value || "bind" in value || "name" in value || "middlewares" in value || "summary" in value || "description" in value || "tags" in value || "operationId" in value || "deprecated" in value;
856
962
  }
857
963
  function joinPaths(prefixStack, path) {
858
- const segments = [...prefixStack, path].filter(Boolean).map((segment) => segment.replace(/\/*$/u, "").replace(/^\/*/u, "")).filter(Boolean);
964
+ const segments = [...prefixStack, path].filter(Boolean).map(trimSlashes).filter(Boolean);
859
965
  if (segments.length === 0) {
860
966
  return "/";
861
967
  }
@@ -1458,7 +1564,7 @@ function createHostAuthorizationMiddleware(options) {
1458
1564
  const { allowedHosts, exclude = [], onError } = options;
1459
1565
  const matchers = allowedHosts.map(compileHostMatcher);
1460
1566
  return async (ctx, next) => {
1461
- const path = new URL(ctx.req.url).pathname;
1567
+ const path = ctx.req.path;
1462
1568
  if (isExcluded2(path, exclude)) {
1463
1569
  await next();
1464
1570
  return;
@@ -1494,7 +1600,9 @@ function compileHostMatcher(pattern) {
1494
1600
  const hostname = pattern.slice(0, -2).toLowerCase();
1495
1601
  return (host) => {
1496
1602
  const h = host.toLowerCase();
1497
- return h === hostname || h.startsWith(hostname + ":");
1603
+ if (h === hostname) return true;
1604
+ if (!h.startsWith(hostname + ":")) return false;
1605
+ return /^\d+$/.test(h.slice(hostname.length + 1));
1498
1606
  };
1499
1607
  }
1500
1608
  const lower = pattern.toLowerCase();
@@ -1800,7 +1908,7 @@ function resolveAuth(ctx) {
1800
1908
  }
1801
1909
  function requireAuthenticated(options = {}) {
1802
1910
  const { redirectTo, status = 401, responseFactory } = options;
1803
- return async (ctx, next) => {
1911
+ return stampCapabilities(async (ctx, next) => {
1804
1912
  const auth = resolveAuth(ctx);
1805
1913
  if (!auth) {
1806
1914
  throw new Error("Auth context has not been attached. Did you register the auth middleware?");
@@ -1815,11 +1923,11 @@ function requireAuthenticated(options = {}) {
1815
1923
  return jsonResponse({ message: "Unauthorized" }, status);
1816
1924
  }
1817
1925
  await next();
1818
- };
1926
+ }, { authentication: { mode: "required" } });
1819
1927
  }
1820
1928
  function requireGuest(options = {}) {
1821
1929
  const { redirectTo, status = 403, responseFactory } = options;
1822
- return async (ctx, next) => {
1930
+ return stampCapabilities(async (ctx, next) => {
1823
1931
  const auth = resolveAuth(ctx);
1824
1932
  if (!auth) {
1825
1933
  throw new Error("Auth context has not been attached. Did you register the auth middleware?");
@@ -1834,7 +1942,7 @@ function requireGuest(options = {}) {
1834
1942
  return jsonResponse({ message: "Already authenticated" }, status);
1835
1943
  }
1836
1944
  await next();
1837
- };
1945
+ }, { authentication: { mode: "guest-only" } });
1838
1946
  }
1839
1947
 
1840
1948
  // src/providers/AuthServiceProvider.ts
@@ -2416,6 +2524,7 @@ var Application = class {
2416
2524
  this.providerManager.register(InertiaServiceProvider);
2417
2525
  }
2418
2526
  }
2527
+ options;
2419
2528
  hono;
2420
2529
  container;
2421
2530
  router;
@@ -2468,7 +2577,16 @@ var Application = class {
2468
2577
  await this.providerManager.registerAll();
2469
2578
  await this.options.boot?.(this.hono);
2470
2579
  await this.mountRoutes();
2471
- await this.mountMcpEndpoint();
2580
+ await this.mountDevEndpoint(
2581
+ isMcpEndpointEnabled(),
2582
+ async () => (await import("./McpServiceProvider-7BB5FPF3.js")).McpServiceProvider,
2583
+ "GUREN_MCP=1 but the MCP endpoint could not load \u2014 is @modelcontextprotocol/sdk installed?"
2584
+ );
2585
+ await this.mountDevEndpoint(
2586
+ isDocsViewerEnabled(),
2587
+ async () => (await import("./DocsViewerServiceProvider-D7RGJPGM.js")).DocsViewerServiceProvider,
2588
+ "GUREN_DOCS=1 but the docs viewer could not load \u2014 is @guren/cli resolvable from this app?"
2589
+ );
2472
2590
  await this.providerManager.bootAll();
2473
2591
  }
2474
2592
  /**
@@ -2487,20 +2605,27 @@ var Application = class {
2487
2605
  this.hono.use("*", createHostAuthorizationMiddleware(hostAuthorization));
2488
2606
  }
2489
2607
  /**
2490
- * Mounts the MCP endpoint at /_guren/mcp when enabled.
2491
- * This allows AI coding agents to introspect the project.
2492
- */
2493
- async mountMcpEndpoint() {
2494
- if (!isMcpEndpointEnabled()) {
2495
- return;
2496
- }
2608
+ * Mounts an opt-in, dev-only framework endpoint: the MCP endpoint
2609
+ * (/_guren/mcp) and the docs viewer (/_guren/docs) both work this way.
2610
+ *
2611
+ * Only the dynamic import is allowed to fail silently — these
2612
+ * providers reach optional dependencies (the MCP SDK, @guren/cli) that
2613
+ * an app need not have installed, and `missing` names that case. A
2614
+ * failure inside the provider's own boot is a real problem and is
2615
+ * rethrown, rather than leaving the developer with a silent 404.
2616
+ */
2617
+ async mountDevEndpoint(enabled, load, missing) {
2618
+ if (!enabled) return;
2619
+ let provider;
2497
2620
  try {
2498
- const { McpServiceProvider } = await import("./McpServiceProvider-TZWQWXCT.js");
2499
- const provider = new McpServiceProvider(this.container);
2500
- provider.register();
2501
- await provider.boot();
2621
+ const Provider = await load();
2622
+ provider = new Provider(this.container);
2502
2623
  } catch {
2624
+ console.warn(`[guren] ${missing}`);
2625
+ return;
2503
2626
  }
2627
+ provider.register?.();
2628
+ await provider.boot?.();
2504
2629
  }
2505
2630
  /**
2506
2631
  * Fetch handler to integrate with Bun.serve or any standard Fetch runtime.
@@ -3180,6 +3305,7 @@ var FieldValidator = class {
3180
3305
  constructor(field) {
3181
3306
  this.field = field;
3182
3307
  }
3308
+ field;
3183
3309
  _rules = [];
3184
3310
  isNullable = false;
3185
3311
  isSometimes = false;
@@ -3570,13 +3696,23 @@ function email() {
3570
3696
  if (typeof value !== "string") {
3571
3697
  return "The :attribute must be a valid email address.";
3572
3698
  }
3573
- const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
3574
- if (!emailRegex.test(value)) {
3699
+ if (!isPlausibleEmail(value)) {
3575
3700
  return "The :attribute must be a valid email address.";
3576
3701
  }
3577
3702
  return true;
3578
3703
  };
3579
3704
  }
3705
+ function isPlausibleEmail(value) {
3706
+ const at = value.indexOf("@");
3707
+ if (at <= 0 || value.indexOf("@", at + 1) !== -1) {
3708
+ return false;
3709
+ }
3710
+ if (/\s/u.test(value)) {
3711
+ return false;
3712
+ }
3713
+ const domain = value.slice(at + 1);
3714
+ return domain.slice(1, -1).includes(".");
3715
+ }
3580
3716
  function url() {
3581
3717
  return (value) => {
3582
3718
  if (value === void 0 || value === null || value === "") return true;
@@ -6452,16 +6588,34 @@ function debugErrorMiddleware() {
6452
6588
  }
6453
6589
  };
6454
6590
  }
6591
+ function splitLocation(location) {
6592
+ const lastColon = location.lastIndexOf(":");
6593
+ if (lastColon <= 0) return null;
6594
+ const prevColon = location.lastIndexOf(":", lastColon - 1);
6595
+ if (prevColon <= 0) return null;
6596
+ const line = location.slice(prevColon + 1, lastColon);
6597
+ const col = location.slice(lastColon + 1);
6598
+ if (!/^\d+$/.test(line) || !/^\d+$/.test(col)) return null;
6599
+ return { file: location.slice(0, prevColon), line, col };
6600
+ }
6455
6601
  function parseStackTrace(stack) {
6456
6602
  const lines = stack.split("\n").slice(1);
6457
6603
  return lines.map((line) => {
6458
- const match = line.match(/\s+at\s+(.+?)\s+\((.+?):(\d+):(\d+)\)/);
6459
- if (match) {
6460
- return { func: match[1], file: match[2], line: match[3], col: match[4] };
6604
+ const trimmed = line.trim();
6605
+ if (!/^at\s/u.test(trimmed)) return null;
6606
+ const rest = trimmed.slice(2).trim();
6607
+ if (rest.endsWith(")")) {
6608
+ const open = matchingOpenParen(rest, rest.length - 1);
6609
+ if (open !== void 0 && open > 0) {
6610
+ const location2 = splitLocation(rest.slice(open + 1, -1));
6611
+ if (location2) {
6612
+ return { func: rest.slice(0, open).trim(), ...location2 };
6613
+ }
6614
+ }
6461
6615
  }
6462
- const match2 = line.match(/\s+at\s+(.+?):(\d+):(\d+)/);
6463
- if (match2) {
6464
- return { func: "<anonymous>", file: match2[1], line: match2[2], col: match2[3] };
6616
+ const location = splitLocation(rest);
6617
+ if (location) {
6618
+ return { func: "<anonymous>", ...location };
6465
6619
  }
6466
6620
  return null;
6467
6621
  }).filter((frame) => frame !== null);
@@ -1,18 +1,18 @@
1
1
  import * as hono_aws_lambda from 'hono/aws-lambda';
2
2
  export { APIGatewayProxyResult, LambdaEvent } from 'hono/aws-lambda';
3
- import { A as Application } from '../Application-Bi-olFMF.js';
3
+ import { A as Application } from '../validation-yAL53e1S.js';
4
4
  import { S as Scheduler } from '../Scheduler-pZiT8i57.js';
5
- import { C as ConsoleKernel } from '../ConsoleKernel-D0dkFt6u.js';
5
+ import { C as ConsoleKernel } from '../ConsoleKernel-CJg975mp.js';
6
6
  import 'hono';
7
- import '../api-token-COQHXyM_.js';
8
- import '../AuthManager-C84xF5ks.js';
7
+ import '../api-token-D24VPr_E.js';
8
+ import '../AuthManager-DBP4KYsx.js';
9
9
  import '@guren/orm';
10
10
  import 'vite';
11
11
  import '../EventManager-CmIoLt7r.js';
12
12
  import '../CacheManager-BmDzUKrF.js';
13
13
  import '../MailManager-DpMvYiP9.js';
14
14
  import '../LogManager-7mxnkaPM.js';
15
- import '../I18nManager-CmUqj6bU.js';
15
+ import '../I18nManager-BiSoczfV.js';
16
16
  import '../BroadcastManager-D8KoJxiV.js';
17
17
  import '../index-9_Jzj5jo.js';
18
18
  import '../app-key-CsBfRC_Q.js';
@@ -9,8 +9,9 @@ import {
9
9
  getMailManager,
10
10
  mail,
11
11
  setMailManager
12
- } from "../chunk-RNXTRWKL.js";
13
- import "../chunk-Z3HXKWI6.js";
12
+ } from "../chunk-K6CUBJX6.js";
13
+ import "../chunk-2V3YID4H.js";
14
+ import "../chunk-KTNJG7R7.js";
14
15
  import "../chunk-6J6B5KOB.js";
15
16
  export {
16
17
  LogTransport,