@guren/server 1.3.0 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/dist/{Application-DImeY-VW.d.ts → Application-Bi-olFMF.d.ts} +387 -18
  2. package/dist/{AuthManager-BU8ZvenF.d.ts → AuthManager-C84xF5ks.d.ts} +1 -1
  3. package/dist/{BroadcastManager-CGWl9rUO.d.ts → BroadcastManager-D8KoJxiV.d.ts} +21 -0
  4. package/dist/{CacheManager-BkvHEOZX.d.ts → CacheManager-BmDzUKrF.d.ts} +17 -0
  5. package/dist/ConsoleKernel-D0dkFt6u.d.ts +101 -0
  6. package/dist/{McpServiceProvider-RNTDHZAZ.js → McpServiceProvider-TZWQWXCT.js} +2 -2
  7. package/dist/{Scheduler-BstvSca7.d.ts → Scheduler-pZiT8i57.d.ts} +2 -0
  8. package/dist/{api-token-CB12xnVg.d.ts → api-token-COQHXyM_.d.ts} +68 -1
  9. package/dist/auth/index.d.ts +5 -5
  10. package/dist/auth/index.js +1 -1
  11. package/dist/authorization/index.js +2 -2
  12. package/dist/broadcasting/index.d.ts +2 -2
  13. package/dist/broadcasting/index.js +2 -1
  14. package/dist/cache/index.d.ts +2 -2
  15. package/dist/cache/index.js +2 -1
  16. package/dist/{chunk-EGU5KB7V.js → chunk-4SBGSJNT.js} +31 -1
  17. package/dist/{chunk-CSDKWLFD.js → chunk-5AD7LYWO.js} +111 -35
  18. package/dist/{chunk-THSX7OOR.js → chunk-63SKW5PS.js} +3 -0
  19. package/dist/{chunk-R2TCP7D7.js → chunk-6J6B5KOB.js} +18 -2
  20. package/dist/{chunk-VY2JPS6V.js → chunk-AUXQISW5.js} +83 -11
  21. package/dist/chunk-DCYKSYAT.js +63 -0
  22. package/dist/{chunk-ZRBLZY3M.js → chunk-FZD2AKJI.js} +1 -1
  23. package/dist/{chunk-HKQSAFSN.js → chunk-MC752CQT.js} +15 -0
  24. package/dist/{chunk-J753UWAY.js → chunk-NQCZQAJL.js} +93 -28
  25. package/dist/{chunk-STZUODC3.js → chunk-NYQGAWDN.js} +44 -1
  26. package/dist/{chunk-EDRGAM6G.js → chunk-RNXTRWKL.js} +2 -1
  27. package/dist/{chunk-CSP7W3WY.js → chunk-SHYRVOMJ.js} +2 -2
  28. package/dist/{chunk-44F7JQ7I.js → chunk-XMQZENBP.js} +35 -1
  29. package/dist/{chunk-WJJ5CTNI.js → chunk-Z3HXKWI6.js} +2 -2
  30. package/dist/{client-CKXJLsTe.d.ts → client-BQwF2b9Y.d.ts} +7 -0
  31. package/dist/{email-verification-D9u7krkn.d.ts → email-verification-H_WlpsVH.d.ts} +1 -1
  32. package/dist/{errors-JOOPDDQ6.js → errors-PUNHAFL2.js} +1 -1
  33. package/dist/index.d.ts +35 -17
  34. package/dist/index.js +329 -132
  35. package/dist/lambda/index.d.ts +7 -7
  36. package/dist/lambda/index.js +1 -1
  37. package/dist/mail/index.js +3 -3
  38. package/dist/mcp/index.d.ts +53 -19
  39. package/dist/mcp/index.js +2 -2
  40. package/dist/notifications/index.d.ts +57 -8
  41. package/dist/notifications/index.js +11 -3
  42. package/dist/queue/index.d.ts +7 -7
  43. package/dist/queue/index.js +4 -2
  44. package/dist/redis/index.d.ts +11 -21
  45. package/dist/redis/index.js +42 -6
  46. package/dist/runtime/index.d.ts +7 -7
  47. package/dist/runtime/index.js +1 -1
  48. package/dist/scheduling/index.d.ts +2 -2
  49. package/dist/scheduling/index.js +2 -1
  50. package/package.json +2 -2
  51. package/dist/ConsoleKernel-COKndy_V.d.ts +0 -207
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@ import {
2
2
  logDevServerBanner,
3
3
  parseImportMap,
4
4
  startViteDevServer
5
- } from "./chunk-CSP7W3WY.js";
5
+ } from "./chunk-SHYRVOMJ.js";
6
6
  import {
7
7
  PendingSchedule,
8
8
  Schedule,
@@ -16,7 +16,7 @@ import {
16
16
  matchesCron,
17
17
  parseCron,
18
18
  toTimezone
19
- } from "./chunk-HKQSAFSN.js";
19
+ } from "./chunk-MC752CQT.js";
20
20
  import {
21
21
  LocalDriver,
22
22
  MemoryDriver as MemoryDriver3,
@@ -61,11 +61,13 @@ import {
61
61
  getMailManager,
62
62
  mail,
63
63
  setMailManager
64
- } from "./chunk-EDRGAM6G.js";
64
+ } from "./chunk-RNXTRWKL.js";
65
65
  import {
66
+ MCP_ENDPOINT_PATH,
66
67
  ProviderManager,
67
- ServiceProvider
68
- } from "./chunk-STZUODC3.js";
68
+ ServiceProvider,
69
+ isMcpEndpointEnabled
70
+ } from "./chunk-NYQGAWDN.js";
69
71
  import {
70
72
  DatabaseChannel,
71
73
  MailChannel,
@@ -73,10 +75,14 @@ import {
73
75
  Notification,
74
76
  NotificationManager,
75
77
  SlackChannel,
78
+ clearNotificationRegistry,
76
79
  createNotificationManager,
80
+ getNotification,
77
81
  getNotificationManager,
82
+ registerNotification,
83
+ resolveNotifiableType,
78
84
  setNotificationManager
79
- } from "./chunk-CSDKWLFD.js";
85
+ } from "./chunk-5AD7LYWO.js";
80
86
  import {
81
87
  FailedJobReporter,
82
88
  MemoryDriver,
@@ -88,7 +94,7 @@ import {
88
94
  createQueueManager,
89
95
  createSqsAdapter,
90
96
  processJob
91
- } from "./chunk-WJJ5CTNI.js";
97
+ } from "./chunk-Z3HXKWI6.js";
92
98
  import {
93
99
  Container,
94
100
  Job,
@@ -100,9 +106,10 @@ import {
100
106
  getRegisteredJobs,
101
107
  registerJob,
102
108
  resolve,
109
+ resolveJobName,
103
110
  setContainer,
104
111
  setQueueDriver
105
- } from "./chunk-R2TCP7D7.js";
112
+ } from "./chunk-6J6B5KOB.js";
106
113
  import {
107
114
  createRedisClient
108
115
  } from "./chunk-UY3AZSYL.js";
@@ -162,7 +169,7 @@ import {
162
169
  verifyEmailToken,
163
170
  verifyOAuthState,
164
171
  verifyPasswordResetToken
165
- } from "./chunk-VY2JPS6V.js";
172
+ } from "./chunk-AUXQISW5.js";
166
173
  import {
167
174
  Gate,
168
175
  Policy,
@@ -179,7 +186,7 @@ import {
179
186
  getGate,
180
187
  setGate,
181
188
  withAuthorization
182
- } from "./chunk-ZRBLZY3M.js";
189
+ } from "./chunk-FZD2AKJI.js";
183
190
  import {
184
191
  AuthorizationException,
185
192
  ExceptionHandler,
@@ -193,7 +200,7 @@ import {
193
200
  getExceptionHandler,
194
201
  renderErrorPage,
195
202
  setExceptionHandler
196
- } from "./chunk-THSX7OOR.js";
203
+ } from "./chunk-63SKW5PS.js";
197
204
  import {
198
205
  AuthenticationException,
199
206
  HttpException
@@ -212,7 +219,7 @@ import {
212
219
  getBroadcastManager,
213
220
  parseRequestPayload,
214
221
  setBroadcastManager
215
- } from "./chunk-44F7JQ7I.js";
222
+ } from "./chunk-XMQZENBP.js";
216
223
  import {
217
224
  CacheManager,
218
225
  FileStore,
@@ -220,7 +227,11 @@ import {
220
227
  RedisStore,
221
228
  TaggedCache,
222
229
  createCacheManager
223
- } from "./chunk-EGU5KB7V.js";
230
+ } from "./chunk-4SBGSJNT.js";
231
+ import {
232
+ claimHotDisposable,
233
+ isHotReloadRuntime
234
+ } from "./chunk-DCYKSYAT.js";
224
235
  import {
225
236
  Encrypter,
226
237
  createEncrypter,
@@ -385,6 +396,8 @@ var Router = class {
385
396
  middlewareAliases = /* @__PURE__ */ new Map();
386
397
  middlewareGroups = /* @__PURE__ */ new Map();
387
398
  modelBindings = /* @__PURE__ */ new Map();
399
+ /** Model class names for router-level bind(param, Model) calls — resolver-only binds carry no name. */
400
+ modelBindingNames = /* @__PURE__ */ new Map();
388
401
  aliasMiddleware(name, handler) {
389
402
  this.middlewareAliases.set(name, handler);
390
403
  return this;
@@ -399,6 +412,7 @@ var Router = class {
399
412
  bind(param, modelOrResolver) {
400
413
  if (typeof modelOrResolver === "function" && "findOrFail" in modelOrResolver) {
401
414
  const model = modelOrResolver;
415
+ if (model.name) this.modelBindingNames.set(param, model.name);
402
416
  this.modelBindings.set(param, async (value) => {
403
417
  return model.findOrFail(value);
404
418
  });
@@ -480,9 +494,10 @@ var Router = class {
480
494
  this.middlewareAliases.clear();
481
495
  this.middlewareGroups.clear();
482
496
  this.modelBindings.clear();
497
+ this.modelBindingNames.clear();
483
498
  }
484
499
  definitions() {
485
- return this.registry.map(({ method, path, name, schemas, openapi, routeMiddlewareNames, middlewares, handler }) => ({
500
+ return this.registry.map(({ method, path, name, schemas, openapi, routeMiddlewareNames, middlewares, handler, bindings }) => ({
486
501
  method,
487
502
  path,
488
503
  name,
@@ -490,6 +505,7 @@ var Router = class {
490
505
  middlewareNames: [...routeMiddlewareNames],
491
506
  hasInlineMiddleware: middlewares.length > 0,
492
507
  controller: isControllerAction(handler) ? { name: handler[0].name, action: String(handler[1]) } : void 0,
508
+ bindings: serializeBindings(path, bindings, this.modelBindingNames),
493
509
  ...openapi
494
510
  }));
495
511
  }
@@ -818,6 +834,17 @@ function buildResponse(result) {
818
834
  }
819
835
  return new Response(String(result));
820
836
  }
837
+ function serializeBindings(path, routeBindings, routerBindingNames) {
838
+ const entries = /* @__PURE__ */ new Map();
839
+ for (const param of path.match(/:(\w+)/g) ?? []) {
840
+ const name = routerBindingNames.get(param.slice(1));
841
+ if (name) entries.set(param.slice(1), name);
842
+ }
843
+ for (const [param, model] of routeBindings ?? []) {
844
+ if (model.name) entries.set(param, model.name);
845
+ }
846
+ return entries.size > 0 ? Object.fromEntries(entries) : void 0;
847
+ }
821
848
  function isControllerAction(action) {
822
849
  return Array.isArray(action);
823
850
  }
@@ -855,7 +882,32 @@ function definePlugin(definition) {
855
882
  };
856
883
  }
857
884
 
885
+ // src/container/defineModule.ts
886
+ function defineModule(definition) {
887
+ return {
888
+ name: definition.name,
889
+ prefix: definition.prefix,
890
+ routes: definition.routes,
891
+ providers: definition.providers ?? [],
892
+ commands: definition.commands ?? []
893
+ };
894
+ }
895
+ async function mountModuleRoutes(router, gurenModule) {
896
+ const registrar = gurenModule.routes;
897
+ if (!registrar) return;
898
+ if (!gurenModule.prefix) {
899
+ await registrar(router);
900
+ return;
901
+ }
902
+ let pending = void 0;
903
+ router.group(gurenModule.prefix, (grouped) => {
904
+ pending = registrar(grouped);
905
+ });
906
+ await pending;
907
+ }
908
+
858
909
  // src/http/middleware/csrf.ts
910
+ import { getCookie } from "hono/cookie";
859
911
  var CSRF_TOKEN_KEY = "_csrf_token";
860
912
  var CSRF_HEADER_NAME = "X-CSRF-TOKEN";
861
913
  var XSRF_HEADER_NAME = "X-XSRF-TOKEN";
@@ -863,11 +915,29 @@ var XSRF_COOKIE_NAME = "XSRF-TOKEN";
863
915
  var CSRF_FORM_FIELD = "_token";
864
916
  var DEFAULT_PROTECTED_METHODS = ["POST", "PUT", "PATCH", "DELETE"];
865
917
  var DEFAULT_COOKIE_SECURE = typeof process !== "undefined" ? process.env.NODE_ENV === "production" : true;
866
- function generateToken() {
867
- const bytes = new Uint8Array(32);
918
+ var CSRF_CONTEXT_KEY = "guren:csrf-token";
919
+ var CSRF_PURPOSE = "csrf";
920
+ function createCsrfSigner() {
921
+ return new MessageSigner(deriveAppKeyring(getAppKeyringFromEnv(), "csrf-token"));
922
+ }
923
+ function randomNonce() {
924
+ const bytes = new Uint8Array(16);
868
925
  globalThis.crypto.getRandomValues(bytes);
869
926
  return Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("");
870
927
  }
928
+ function bindableSessionId(session) {
929
+ return session && !session.isNew ? session.id : void 0;
930
+ }
931
+ function mintCsrfToken(sessionId) {
932
+ const signer = createCsrfSigner();
933
+ return sessionId ? signer.sign({ sid: sessionId }, { purpose: CSRF_PURPOSE }) : signer.sign({ n: randomNonce() }, { purpose: CSRF_PURPOSE });
934
+ }
935
+ function verifiedClaims(token) {
936
+ return createCsrfSigner().verify(token, { purpose: CSRF_PURPOSE });
937
+ }
938
+ function claimsUsableFor(claims, boundId) {
939
+ return claims.sid !== void 0 ? claims.sid === boundId : boundId === void 0;
940
+ }
871
941
  function matchesPattern(path, pattern) {
872
942
  if (pattern.endsWith("/*")) {
873
943
  const prefix = pattern.slice(0, -2);
@@ -878,16 +948,25 @@ function matchesPattern(path, pattern) {
878
948
  function isExcluded(path, excludePatterns) {
879
949
  return excludePatterns.some((pattern) => matchesPattern(path, pattern));
880
950
  }
951
+ function isMcpEndpointRequest(path) {
952
+ return path === MCP_ENDPOINT_PATH && isMcpEndpointEnabled();
953
+ }
881
954
  function getCsrfToken(ctx) {
882
- const session = getSessionFromContext(ctx);
883
- if (!session) {
884
- throw new Error("CSRF middleware requires session middleware to be registered first.");
955
+ const pending = ctx.get(CSRF_CONTEXT_KEY);
956
+ if (pending) {
957
+ return pending;
885
958
  }
886
- let token = session.get(CSRF_TOKEN_KEY);
887
- if (!token) {
888
- token = generateToken();
889
- session.set(CSRF_TOKEN_KEY, token);
959
+ const boundId = bindableSessionId(getSessionFromContext(ctx));
960
+ const cookieToken = getCookie(ctx, XSRF_COOKIE_NAME);
961
+ if (cookieToken) {
962
+ const claims = verifiedClaims(cookieToken);
963
+ if (claims && claimsUsableFor(claims, boundId)) {
964
+ ctx.set(CSRF_CONTEXT_KEY, cookieToken);
965
+ return cookieToken;
966
+ }
890
967
  }
968
+ const token = mintCsrfToken(boundId);
969
+ ctx.set(CSRF_CONTEXT_KEY, token);
891
970
  return token;
892
971
  }
893
972
  function csrfField(ctx) {
@@ -898,22 +977,22 @@ function verifyCsrfToken(ctx, token) {
898
977
  if (!token) {
899
978
  return false;
900
979
  }
901
- const session = getSessionFromContext(ctx);
902
- if (!session) {
903
- return false;
904
- }
905
- const sessionToken = session.get(CSRF_TOKEN_KEY);
906
- if (!sessionToken) {
907
- return false;
908
- }
909
- if (token.length !== sessionToken.length) {
910
- return false;
911
- }
912
- let result = 0;
913
- for (let i = 0; i < token.length; i++) {
914
- result |= token.charCodeAt(i) ^ sessionToken.charCodeAt(i);
980
+ const claims = verifiedClaims(token);
981
+ if (claims) {
982
+ if (claims.sid !== void 0) {
983
+ const boundId = bindableSessionId(getSessionFromContext(ctx));
984
+ if (boundId !== void 0 && secureCompare(claims.sid, boundId)) {
985
+ return true;
986
+ }
987
+ } else {
988
+ const cookieToken = getCookie(ctx, XSRF_COOKIE_NAME);
989
+ if (cookieToken && secureCompare(token, cookieToken)) {
990
+ return true;
991
+ }
992
+ }
915
993
  }
916
- return result === 0;
994
+ const sessionToken = getSessionFromContext(ctx)?.get(CSRF_TOKEN_KEY);
995
+ return sessionToken !== void 0 && secureCompare(token, sessionToken);
917
996
  }
918
997
  async function getTokenFromRequest(ctx) {
919
998
  const headerToken = ctx.req.header(CSRF_HEADER_NAME);
@@ -959,10 +1038,6 @@ function createCsrfMiddleware(options = {}) {
959
1038
  } = options;
960
1039
  const protectedMethods = new Set(methods.map((m) => m.toUpperCase()));
961
1040
  return async (ctx, next) => {
962
- const session = getSessionFromContext(ctx);
963
- if (!session) {
964
- throw new Error("CSRF middleware requires session middleware to be registered first.");
965
- }
966
1041
  const method = ctx.req.method.toUpperCase();
967
1042
  const path = new URL(ctx.req.url).pathname;
968
1043
  if (!protectedMethods.has(method)) {
@@ -973,7 +1048,7 @@ function createCsrfMiddleware(options = {}) {
973
1048
  }
974
1049
  return;
975
1050
  }
976
- if (isExcluded(path, exclude)) {
1051
+ if (isExcluded(path, exclude) || isMcpEndpointRequest(path)) {
977
1052
  await next();
978
1053
  return;
979
1054
  }
@@ -1052,16 +1127,31 @@ function validateSafe(schema, data) {
1052
1127
  // src/http/middleware/rate-limit.ts
1053
1128
  var BaseMemoryStore = class {
1054
1129
  cleanupInterval;
1130
+ /**
1131
+ * This store's claim on its hot-reload slot, if it holds one.
1132
+ *
1133
+ * Unlike the cache sweep, this interval is not `unref()`ed, so a leaked one
1134
+ * both duplicates work and keeps the process alive on its own.
1135
+ */
1136
+ hotReloadClaim;
1055
1137
  constructor(cleanupIntervalMs = 6e4) {
1056
- if (cleanupIntervalMs > 0) {
1057
- this.cleanupInterval = setInterval(() => this.cleanup(), cleanupIntervalMs);
1138
+ if (cleanupIntervalMs <= 0) {
1139
+ return;
1058
1140
  }
1141
+ this.cleanupInterval = setInterval(() => this.cleanup(), cleanupIntervalMs);
1142
+ this.hotReloadClaim = claimHotDisposable(
1143
+ "rate-limit-store",
1144
+ isHotReloadRuntime() ? new Error().stack : void 0,
1145
+ this.constructor.name,
1146
+ () => this.destroy()
1147
+ );
1059
1148
  }
1060
1149
  destroy() {
1061
1150
  if (this.cleanupInterval) {
1062
1151
  clearInterval(this.cleanupInterval);
1063
1152
  this.cleanupInterval = void 0;
1064
1153
  }
1154
+ this.hotReloadClaim?.release();
1065
1155
  }
1066
1156
  };
1067
1157
  var MemoryRateLimitStore = class extends BaseMemoryStore {
@@ -1553,7 +1643,7 @@ function requestLoggingMiddleware() {
1553
1643
 
1554
1644
  // src/http/middleware/detect-locale.ts
1555
1645
  import { createMiddleware as createMiddleware3 } from "hono/factory";
1556
- import { getCookie } from "hono/cookie";
1646
+ import { getCookie as getCookie2 } from "hono/cookie";
1557
1647
  import { parseAccept } from "hono/utils/accept";
1558
1648
  var LOCALE_CONTEXT_KEY = "locale";
1559
1649
  var DEFAULT_SOURCES = ["query", "cookie", "header"];
@@ -1615,7 +1705,7 @@ function detectLocaleMiddleware(options) {
1615
1705
  return createMiddleware3(async (c, next) => {
1616
1706
  const readers = {
1617
1707
  query: () => match(c.req.query(queryParam)),
1618
- cookie: () => match(getCookie(c, cookieName)),
1708
+ cookie: () => match(getCookie2(c, cookieName)),
1619
1709
  header: () => matchHeader(c.req.header("Accept-Language"))
1620
1710
  };
1621
1711
  let resolved = fallback;
@@ -1815,6 +1905,14 @@ var ErrorServiceProvider = class extends ServiceProvider {
1815
1905
  import { isAbsolute, resolve as resolvePath } from "path";
1816
1906
  import { pathToFileURL } from "url";
1817
1907
  ensureErrorStackTracePolyfill();
1908
+ var documentOptions;
1909
+ function setInertiaDocument(options) {
1910
+ documentOptions = options;
1911
+ }
1912
+ var defaultSsrRenderer;
1913
+ function setInertiaSsrRenderer(renderer) {
1914
+ defaultSsrRenderer = renderer;
1915
+ }
1818
1916
  var DEFAULT_TITLE = "Guren";
1819
1917
  var DEV_FALLBACK_IMPORT_MAP = {
1820
1918
  react: "https://esm.sh/react@19.0.0?dev",
@@ -1889,7 +1987,17 @@ async function renderDocument(page, options) {
1889
1987
  const importMap = JSON.stringify({ imports: importMapEntries }, null, 2);
1890
1988
  const serializedPage = serializePage(page);
1891
1989
  const stylesheetLinks = renderStyles(styles);
1892
- const docsHeadBootstrap = renderDocsHeadBootstrap(page.component);
1990
+ const criticalCss = resolveDocumentValue(
1991
+ "criticalCss",
1992
+ options,
1993
+ page.component
1994
+ );
1995
+ const prepaintScript = resolveDocumentValue(
1996
+ "prepaintScript",
1997
+ options,
1998
+ page.component
1999
+ );
2000
+ const headMarkup = resolveDocumentValue("head", options, page.component);
1893
2001
  const ssrResult = await tryRenderSsr(page, options);
1894
2002
  const headElements = (ssrResult?.head ?? []).map(normalizeHeadElement);
1895
2003
  const hasCustomTitle = headElements.some(
@@ -1899,14 +2007,18 @@ async function renderDocument(page, options) {
1899
2007
  '<meta charset="utf-8" />',
1900
2008
  '<meta name="viewport" content="width=device-width, initial-scale=1" />',
1901
2009
  hasCustomTitle ? "" : `<title>${title}</title>`,
1902
- docsHeadBootstrap,
2010
+ headMarkup ?? "",
2011
+ // Both must precede the stylesheet links: they exist to settle the first
2012
+ // paint before the app's own CSS arrives.
2013
+ criticalCss ? `<style id="guren-critical">${criticalCss}</style>` : "",
2014
+ prepaintScript ? `<script>${prepaintScript}</script>` : "",
1903
2015
  stylesheetLinks,
1904
2016
  ...headElements,
1905
2017
  Object.keys(importMapEntries).length > 0 ? `<script type="importmap">${importMap}</script>` : "",
1906
2018
  `<script>window.__INERTIA_PAGE__ = ${serializedPage};</script>`
1907
2019
  ].filter((segment) => segment && segment.length > 0);
1908
2020
  const appMarkup = ssrResult?.body ?? `<script data-page="app" type="application/json">${serializedPage}</script><div id="app"></div>`;
1909
- const bodyClass = resolveBodyClass(page.component);
2021
+ const bodyClass = resolveDocumentValue("bodyClass", options, page.component);
1910
2022
  const bodyAttributes = bodyClass ? ` class="${escapeAttribute(bodyClass)}"` : "";
1911
2023
  const lang = escapeAttribute(options.lang ?? "en");
1912
2024
  return `<!DOCTYPE html>
@@ -1926,7 +2038,7 @@ async function tryRenderSsr(page, options) {
1926
2038
  return void 0;
1927
2039
  }
1928
2040
  const manifest = (ssrOptions?.manifest ?? process.env.GUREN_INERTIA_SSR_MANIFEST)?.trim() || void 0;
1929
- const renderer = ssrOptions?.render ?? await loadSsrRenderer(
2041
+ const renderer = ssrOptions?.render ?? defaultSsrRenderer ?? await loadSsrRenderer(
1930
2042
  ssrOptions?.entry ?? process.env.GUREN_INERTIA_SSR_ENTRY
1931
2043
  );
1932
2044
  if (!renderer) {
@@ -2014,36 +2126,13 @@ function normalizeHeadElement(element) {
2014
2126
  (_match, file2, query = "") => `href="/public/assets/${file2}${query}"`
2015
2127
  );
2016
2128
  }
2017
- function resolveBodyClass(componentName) {
2018
- return componentName.startsWith("Docs/") ? "docs-theme" : "";
2019
- }
2020
- function renderDocsHeadBootstrap(componentName) {
2021
- if (!componentName.startsWith("Docs/")) {
2022
- return "";
2129
+ function resolveDocumentValue(key, options, componentName) {
2130
+ const override = options[key];
2131
+ if (override !== void 0) {
2132
+ return override;
2023
2133
  }
2024
- const criticalStyles = [
2025
- "html,body{background:#ffffff;color:#1f2937;}",
2026
- "body.docs-theme{background:#ffffff;color:#1f2937;}",
2027
- "html.dark,html.dark body,html.dark body.docs-theme{background:#1a1a2e;color:#e0def4;}",
2028
- ".size-4{width:1rem;height:1rem;}",
2029
- ".size-5{width:1.25rem;height:1.25rem;}",
2030
- ".size-6{width:1.5rem;height:1.5rem;}",
2031
- ".size-8{width:2rem;height:2rem;}",
2032
- ".size-9{width:2.25rem;height:2.25rem;}"
2033
- ].join("");
2034
- const prepaintScript = [
2035
- "(function(){",
2036
- "try{",
2037
- "var mode=localStorage.getItem('guren-color-mode')||'system';",
2038
- "var dark=mode==='dark'||(mode!=='light'&&window.matchMedia&&window.matchMedia('(prefers-color-scheme: dark)').matches);",
2039
- "var root=document.documentElement;",
2040
- "root.classList.toggle('dark',dark);",
2041
- "root.style.colorScheme=dark?'dark':'light';",
2042
- "}catch(_){",
2043
- "}",
2044
- "})();"
2045
- ].join("");
2046
- return `<style id="guren-docs-critical">${criticalStyles}</style><script>${prepaintScript}</script>`;
2134
+ const value = documentOptions?.[key];
2135
+ return (typeof value === "function" ? value({ component: componentName }) : value) ?? "";
2047
2136
  }
2048
2137
  function serializePage(page) {
2049
2138
  return JSON.stringify(page).replace(/[<\u2028\u2029]/gu, (char) => {
@@ -2306,7 +2395,11 @@ var Application = class {
2306
2395
  this.hono.use("*", attachAuthContext((ctx) => this.authManager.createAuthContext(ctx)));
2307
2396
  }
2308
2397
  this.providerManager.register(AuthorizationServiceProvider);
2309
- const userProviders = Array.isArray(this.options.providers) ? this.options.providers : [];
2398
+ const moduleProviders = (this.options.modules ?? []).flatMap((module) => module.providers);
2399
+ const userProviders = [
2400
+ ...Array.isArray(this.options.providers) ? this.options.providers : [],
2401
+ ...moduleProviders
2402
+ ];
2310
2403
  const hasUserErrorProvider = userProviders.some(
2311
2404
  (provider) => provider === ErrorServiceProvider || provider.prototype instanceof ErrorServiceProvider
2312
2405
  );
@@ -2350,8 +2443,13 @@ var Application = class {
2350
2443
  * Mounts the application router onto the Hono instance.
2351
2444
  */
2352
2445
  async mountRoutes() {
2353
- if (this.options.routes && !this.routesRegistered) {
2354
- await this.options.routes(this.router);
2446
+ if (!this.routesRegistered) {
2447
+ if (this.options.routes) {
2448
+ await this.options.routes(this.router);
2449
+ }
2450
+ for (const gurenModule of this.options.modules ?? []) {
2451
+ await mountModuleRoutes(this.router, gurenModule);
2452
+ }
2355
2453
  this.routesRegistered = true;
2356
2454
  }
2357
2455
  this.router.mount(this.hono, { container: this.container });
@@ -2389,16 +2487,15 @@ var Application = class {
2389
2487
  this.hono.use("*", createHostAuthorizationMiddleware(hostAuthorization));
2390
2488
  }
2391
2489
  /**
2392
- * Mounts the MCP endpoint at /_guren/mcp when explicitly enabled.
2393
- * Requires GUREN_MCP=1 environment variable. Never active in production.
2490
+ * Mounts the MCP endpoint at /_guren/mcp when enabled.
2394
2491
  * This allows AI coding agents to introspect the project.
2395
2492
  */
2396
2493
  async mountMcpEndpoint() {
2397
- if (typeof process === "undefined" || process.env?.NODE_ENV === "production" || process.env?.GUREN_MCP !== "1") {
2494
+ if (!isMcpEndpointEnabled()) {
2398
2495
  return;
2399
2496
  }
2400
2497
  try {
2401
- const { McpServiceProvider } = await import("./McpServiceProvider-RNTDHZAZ.js");
2498
+ const { McpServiceProvider } = await import("./McpServiceProvider-TZWQWXCT.js");
2402
2499
  const provider = new McpServiceProvider(this.container);
2403
2500
  provider.register();
2404
2501
  await provider.boot();
@@ -2451,7 +2548,10 @@ var Application = class {
2451
2548
  const server = Bun.serve({
2452
2549
  port,
2453
2550
  hostname,
2454
- fetch: (request) => this.fetch(request)
2551
+ // `{ server }` is Bun's convention for reaching the live server from a
2552
+ // handler; middleware reads `ctx.env.server.requestIP()` through it to
2553
+ // learn the socket peer (the MCP access guard, the rate limiter).
2554
+ fetch: (request, server2) => this.fetch(request, { server: server2 })
2455
2555
  });
2456
2556
  this.bunServer = server;
2457
2557
  setActiveBunServer(server);
@@ -3026,6 +3126,9 @@ var NotificationServiceProvider = class extends ServiceProvider {
3026
3126
  register() {
3027
3127
  this.container.singleton("notifications", () => createNotificationManager());
3028
3128
  }
3129
+ boot() {
3130
+ this.container.make("notifications").registerQueueJob();
3131
+ }
3029
3132
  };
3030
3133
 
3031
3134
  // src/providers/BroadcastServiceProvider.ts
@@ -3268,7 +3371,7 @@ var Validator = class _Validator {
3268
3371
  async validateOrThrow(data) {
3269
3372
  const result = await this.validate(data);
3270
3373
  if (!result.success) {
3271
- const { ValidationException: ValidationException2 } = await import("./errors-JOOPDDQ6.js");
3374
+ const { ValidationException: ValidationException2 } = await import("./errors-PUNHAFL2.js");
3272
3375
  throw new ValidationException2(result.errors);
3273
3376
  }
3274
3377
  return result.data;
@@ -4840,26 +4943,84 @@ function cursorPaginate(items, perPage, hasMore, options) {
4840
4943
 
4841
4944
  // src/console/Input.ts
4842
4945
  function parseSignature(signature) {
4843
- const parts = signature.split(/\s+/);
4844
- const name = parts[0];
4946
+ const { name, tokens } = tokenizeSignature(signature);
4845
4947
  const args = [];
4846
4948
  const options = [];
4847
- for (let i = 1; i < parts.length; i++) {
4848
- const part = parts[i];
4849
- if (!part) continue;
4850
- if (!part.startsWith("{") || !part.endsWith("}")) {
4851
- continue;
4852
- }
4853
- const content = part.slice(1, -1).trim();
4854
- if (content.startsWith("--") || content.startsWith("-")) {
4855
- options.push(parseOption(content));
4949
+ for (const token of tokens) {
4950
+ const [content, description] = splitSpacedDescription(token);
4951
+ if (!content) continue;
4952
+ if (content.startsWith("-")) {
4953
+ options.push(parseOption(content, description));
4856
4954
  } else {
4857
- args.push(parseArgument(content));
4955
+ args.push(parseArgument(content, description));
4858
4956
  }
4859
4957
  }
4860
4958
  return { name, arguments: args, options };
4861
4959
  }
4862
- function parseArgument(content) {
4960
+ function tokenizeSignature(signature) {
4961
+ const firstBrace = signature.indexOf("{");
4962
+ const head = firstBrace === -1 ? signature : signature.slice(0, firstBrace);
4963
+ const name = head.trim().split(/\s+/)[0];
4964
+ if (firstBrace === -1) {
4965
+ return { name, tokens: [] };
4966
+ }
4967
+ const tokens = [];
4968
+ let depth = 0;
4969
+ let start = -1;
4970
+ for (let i = firstBrace; i < signature.length; i++) {
4971
+ const char = signature[i];
4972
+ if (char === "{") {
4973
+ if (depth === 0) start = i;
4974
+ depth++;
4975
+ } else if (char === "}" && depth > 0) {
4976
+ depth--;
4977
+ if (depth === 0) {
4978
+ tokens.push(signature.slice(start + 1, i));
4979
+ }
4980
+ }
4981
+ }
4982
+ return { name, tokens };
4983
+ }
4984
+ var DESCRIPTION_SEPARATOR = /\s+:\s*|:\s+/;
4985
+ function splitSpacedDescription(token) {
4986
+ const match = DESCRIPTION_SEPARATOR.exec(token);
4987
+ if (!match) {
4988
+ return [token.trim(), void 0];
4989
+ }
4990
+ const content = token.slice(0, match.index).trim();
4991
+ const description = token.slice(match.index + match[0].length).trim();
4992
+ return [content, description || void 0];
4993
+ }
4994
+ function resolveNameAndDescription(name, description) {
4995
+ if (description === void 0) {
4996
+ const colonIndex = name.indexOf(":");
4997
+ if (colonIndex !== -1) {
4998
+ description = name.slice(colonIndex + 1).trim() || void 0;
4999
+ name = name.slice(0, colonIndex);
5000
+ }
5001
+ }
5002
+ return { name: name.trim(), description };
5003
+ }
5004
+ function argumentLabel(arg) {
5005
+ return arg.array ? `${arg.name}...` : arg.name;
5006
+ }
5007
+ function optionLabel(opt) {
5008
+ if (opt.array) return `--${opt.name}=<value>...`;
5009
+ if (opt.requiresValue) return `--${opt.name}=<value>`;
5010
+ return `--${opt.name}`;
5011
+ }
5012
+ function formatUsage(parsed) {
5013
+ const parts = [parsed.name];
5014
+ if (parsed.options.length > 0) {
5015
+ parts.push("[options]");
5016
+ }
5017
+ for (const arg of parsed.arguments) {
5018
+ const label = argumentLabel(arg);
5019
+ parts.push(arg.required ? `<${label}>` : `[${label}]`);
5020
+ }
5021
+ return parts.join(" ");
5022
+ }
5023
+ function parseArgument(content, description) {
4863
5024
  let name = content;
4864
5025
  let required2 = true;
4865
5026
  let array2 = false;
@@ -4878,15 +5039,14 @@ function parseArgument(content) {
4878
5039
  name = name.slice(0, eqIndex);
4879
5040
  required2 = false;
4880
5041
  }
4881
- let description;
4882
- const colonIndex = name.indexOf(":");
4883
- if (colonIndex !== -1) {
4884
- description = name.slice(colonIndex + 1);
4885
- name = name.slice(0, colonIndex);
4886
- }
4887
- return { name, description, required: required2, array: array2, defaultValue };
5042
+ return {
5043
+ ...resolveNameAndDescription(name, description),
5044
+ required: required2,
5045
+ array: array2,
5046
+ defaultValue
5047
+ };
4888
5048
  }
4889
- function parseOption(content) {
5049
+ function parseOption(content, description) {
4890
5050
  let name = content;
4891
5051
  let shortcut;
4892
5052
  let requiresValue = false;
@@ -4913,16 +5073,16 @@ function parseOption(content) {
4913
5073
  requiresValue = true;
4914
5074
  }
4915
5075
  }
4916
- let description;
4917
- const colonIndex = name.indexOf(":");
4918
- if (colonIndex !== -1) {
4919
- description = name.slice(colonIndex + 1);
4920
- name = name.slice(0, colonIndex);
4921
- }
4922
5076
  if (!requiresValue && defaultValue === void 0) {
4923
5077
  defaultValue = false;
4924
5078
  }
4925
- return { name, shortcut, description, requiresValue, defaultValue, array: array2 };
5079
+ return {
5080
+ ...resolveNameAndDescription(name, description),
5081
+ shortcut,
5082
+ requiresValue,
5083
+ defaultValue,
5084
+ array: array2
5085
+ };
4926
5086
  }
4927
5087
  var Input = class {
4928
5088
  /**
@@ -5126,6 +5286,8 @@ var Command = class {
5126
5286
  /**
5127
5287
  * The command signature.
5128
5288
  * Format: 'command:name {arg} {--option}'
5289
+ * Tokens may carry a description: 'command:name {arg : What it is}'
5290
+ * See `parseSignature` for the full grammar.
5129
5291
  */
5130
5292
  static signature;
5131
5293
  /**
@@ -5654,6 +5816,13 @@ var BufferedOutput = class extends Output {
5654
5816
  };
5655
5817
 
5656
5818
  // src/console/ConsoleKernel.ts
5819
+ function helpColumn(labels, min2) {
5820
+ return Math.max(min2, ...labels.map((label) => label.length + 2));
5821
+ }
5822
+ function helpRow(output, indent, label, column, annotations) {
5823
+ const padding = " ".repeat(Math.max(2, column - label.length));
5824
+ output.line(`${indent}${label}${padding}${annotations.filter(Boolean).join(" ")}`);
5825
+ }
5657
5826
  var ConsoleKernel = class {
5658
5827
  /**
5659
5828
  * Registered commands.
@@ -5766,15 +5935,23 @@ var ConsoleKernel = class {
5766
5935
  this.output.line("");
5767
5936
  this.output.info("Available Commands:");
5768
5937
  this.output.line("");
5769
- const grouped = this.groupCommands();
5770
- for (const [namespace, commands] of grouped) {
5771
- if (namespace) {
5772
- this.output.line(` ${namespace}`);
5938
+ const groups = Array.from(this.groupCommands(), ([namespace, commands]) => ({
5939
+ namespace,
5940
+ entries: Array.from(commands, ([name, cmd]) => ({
5941
+ label: namespace ? name.slice(namespace.length + 1) : name,
5942
+ description: cmd.description
5943
+ }))
5944
+ }));
5945
+ const column = helpColumn(
5946
+ groups.flatMap((group) => group.entries.map((entry) => entry.label)),
5947
+ 20
5948
+ );
5949
+ for (const group of groups) {
5950
+ if (group.namespace) {
5951
+ this.output.line(` ${group.namespace}`);
5773
5952
  }
5774
- for (const [name, cmd] of commands) {
5775
- const displayName = namespace ? name.slice(namespace.length + 1) : name;
5776
- const padding = " ".repeat(Math.max(2, 20 - displayName.length));
5777
- this.output.line(` ${displayName}${padding}${cmd.description}`);
5953
+ for (const entry of group.entries) {
5954
+ helpRow(this.output, " ", entry.label, column, [entry.description]);
5778
5955
  }
5779
5956
  this.output.line("");
5780
5957
  }
@@ -5794,23 +5971,34 @@ var ConsoleKernel = class {
5794
5971
  this.output.line("");
5795
5972
  this.output.line(` ${CommandClass.description || "No description"}`);
5796
5973
  this.output.line("");
5797
- this.output.line(`Usage: ${CommandClass.signature}`);
5974
+ this.output.line(`Usage: ${formatUsage(parsed)}`);
5975
+ const optionShortcut = (opt) => opt.shortcut ? `-${opt.shortcut}, ` : " ";
5976
+ const column = helpColumn(
5977
+ [
5978
+ ...parsed.arguments.map(argumentLabel),
5979
+ ...parsed.options.map((opt) => optionShortcut(opt) + optionLabel(opt))
5980
+ ],
5981
+ 24
5982
+ );
5798
5983
  if (parsed.arguments.length > 0) {
5799
5984
  this.output.line("");
5800
5985
  this.output.line("Arguments:");
5801
5986
  for (const arg of parsed.arguments) {
5802
- const required2 = arg.required ? "(required)" : "(optional)";
5803
- const defaultVal = arg.defaultValue ? ` [default: ${arg.defaultValue}]` : "";
5804
- this.output.line(` ${arg.name} ${required2}${defaultVal}`);
5987
+ helpRow(this.output, " ", argumentLabel(arg), column, [
5988
+ arg.description,
5989
+ arg.required ? "(required)" : "(optional)",
5990
+ arg.defaultValue ? `[default: ${arg.defaultValue}]` : void 0
5991
+ ]);
5805
5992
  }
5806
5993
  }
5807
5994
  if (parsed.options.length > 0) {
5808
5995
  this.output.line("");
5809
5996
  this.output.line("Options:");
5810
5997
  for (const opt of parsed.options) {
5811
- const shortcut = opt.shortcut ? `-${opt.shortcut}, ` : " ";
5812
- const defaultVal = opt.defaultValue !== void 0 && opt.defaultValue !== false ? ` [default: ${opt.defaultValue}]` : "";
5813
- this.output.line(` ${shortcut}--${opt.name}${defaultVal}`);
5998
+ helpRow(this.output, " ", optionShortcut(opt) + optionLabel(opt), column, [
5999
+ opt.description,
6000
+ opt.defaultValue !== void 0 && opt.defaultValue !== false ? `[default: ${opt.defaultValue}]` : void 0
6001
+ ]);
5814
6002
  }
5815
6003
  }
5816
6004
  this.output.line("");
@@ -6567,6 +6755,7 @@ export {
6567
6755
  cannot,
6568
6756
  check as checkHash,
6569
6757
  clearJobRegistry,
6758
+ clearNotificationRegistry,
6570
6759
  collect,
6571
6760
  completeEmailVerification,
6572
6761
  completePasswordReset,
@@ -6625,6 +6814,7 @@ export {
6625
6814
  defineFactory,
6626
6815
  defineGate,
6627
6816
  defineMiddleware,
6817
+ defineModule,
6628
6818
  definePlugin,
6629
6819
  definePolicy,
6630
6820
  deriveAppKey,
@@ -6663,6 +6853,7 @@ export {
6663
6853
  getMailManager,
6664
6854
  getNextOccurrence,
6665
6855
  getNextOccurrences,
6856
+ getNotification,
6666
6857
  getNotificationManager,
6667
6858
  getPluralizationRule,
6668
6859
  getQueueDriver,
@@ -6695,6 +6886,7 @@ export {
6695
6886
  mimes,
6696
6887
  min,
6697
6888
  minFileSize,
6889
+ mountModuleRoutes,
6698
6890
  needsRehash,
6699
6891
  normalizeAppKey,
6700
6892
  notIn,
@@ -6724,6 +6916,7 @@ export {
6724
6916
  randomString,
6725
6917
  regex,
6726
6918
  registerJob,
6919
+ registerNotification,
6727
6920
  renderDebugPage,
6728
6921
  renderErrorPage,
6729
6922
  requestIdMiddleware,
@@ -6739,6 +6932,8 @@ export {
6739
6932
  resetCalledSeeders,
6740
6933
  resetRateLimit,
6741
6934
  resolve,
6935
+ resolveJobName,
6936
+ resolveNotifiableType,
6742
6937
  revokeAllApiTokens,
6743
6938
  revokeApiToken,
6744
6939
  same,
@@ -6752,7 +6947,9 @@ export {
6752
6947
  setExceptionHandler,
6753
6948
  setGate,
6754
6949
  setI18n,
6950
+ setInertiaDocument,
6755
6951
  setInertiaSharedProps,
6952
+ setInertiaSsrRenderer,
6756
6953
  setLogManager,
6757
6954
  setMailManager,
6758
6955
  setNotificationManager,