@guren/server 2.1.1 → 2.3.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 (281) 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/AuthManager.d.ts +30 -0
  4. package/dist/auth/AuthenticatableModel.d.ts +25 -0
  5. package/dist/auth/RequestAuthContext.d.ts +24 -0
  6. package/dist/auth/SessionGuard.d.ts +31 -0
  7. package/dist/auth/api-token.d.ts +299 -0
  8. package/dist/auth/email-verification.d.ts +203 -0
  9. package/dist/auth/index.d.ts +18 -110
  10. package/dist/auth/index.js +4 -1
  11. package/dist/auth/oauth/index.d.ts +239 -0
  12. package/dist/auth/password/DefaultHasher.d.ts +13 -0
  13. package/dist/auth/password/NodeHasher.d.ts +22 -0
  14. package/dist/auth/password/PasswordHasher.d.ts +5 -0
  15. package/dist/auth/password/ScryptHasher.d.ts +26 -0
  16. package/dist/auth/password-reset.d.ts +91 -0
  17. package/dist/auth/providers/ModelUserProvider.d.ts +36 -0
  18. package/dist/auth/providers/UserProvider.d.ts +9 -0
  19. package/dist/auth/types.d.ts +102 -0
  20. package/dist/auth/utils.d.ts +39 -0
  21. package/dist/{Gate-CynjZCtS.d.ts → authorization/Gate.d.ts} +30 -111
  22. package/dist/authorization/Policy.d.ts +77 -0
  23. package/dist/authorization/index.d.ts +5 -129
  24. package/dist/authorization/index.js +3 -1
  25. package/dist/authorization/middleware.d.ts +49 -0
  26. package/dist/authorization/types.d.ts +108 -0
  27. package/dist/broadcasting/BroadcastManager.d.ts +205 -0
  28. package/dist/broadcasting/channels/Channel.d.ts +28 -0
  29. package/dist/broadcasting/channels/PresenceChannel.d.ts +72 -0
  30. package/dist/broadcasting/channels/PrivateChannel.d.ts +32 -0
  31. package/dist/broadcasting/channels/index.d.ts +3 -0
  32. package/dist/broadcasting/drivers/MemoryDriver.d.ts +93 -0
  33. package/dist/broadcasting/drivers/RedisDriver.d.ts +112 -0
  34. package/dist/broadcasting/drivers/index.d.ts +2 -0
  35. package/dist/broadcasting/index.d.ts +6 -233
  36. package/dist/broadcasting/index.js +1 -1
  37. package/dist/broadcasting/typed.d.ts +23 -0
  38. package/dist/broadcasting/types.d.ts +155 -0
  39. package/dist/cache/CacheManager.d.ts +87 -0
  40. package/dist/cache/TaggedCache.d.ts +62 -0
  41. package/dist/cache/index.d.ts +6 -233
  42. package/dist/cache/index.js +1 -1
  43. package/dist/cache/stores/FileStore.d.ts +64 -0
  44. package/dist/cache/stores/MemoryStore.d.ts +52 -0
  45. package/dist/cache/stores/RedisStore.d.ts +53 -0
  46. package/dist/{CacheManager-BmDzUKrF.d.ts → cache/types.d.ts} +26 -99
  47. package/dist/chunk-3KV5X2FL.js +31 -0
  48. package/dist/{chunk-TVY72CLV.js → chunk-4VE3LYOM.js} +3 -2
  49. package/dist/{chunk-DSDX3ASM.js → chunk-5WL2FTC4.js} +67 -85
  50. package/dist/{chunk-5SZTEZ22.js → chunk-6IGN233M.js} +15 -8
  51. package/dist/{chunk-FZD2AKJI.js → chunk-7OB2YXRE.js} +56 -28
  52. package/dist/{chunk-WIXGT4TN.js → chunk-A5JJ7XTH.js} +8 -2
  53. package/dist/{chunk-CWI4AJ47.js → chunk-HPET6XY5.js} +13 -9
  54. package/dist/{chunk-A3ISJVEV.js → chunk-HR2KZ3WL.js} +23 -5
  55. package/dist/{chunk-BZMZEFRG.js → chunk-LHR6OHI7.js} +11 -0
  56. package/dist/{chunk-JBG4AR24.js → chunk-Q2P6YLRR.js} +8 -2
  57. package/dist/{chunk-J6ETA476.js → chunk-TVV5YNEC.js} +101 -9
  58. package/dist/console/Command.d.ts +179 -0
  59. package/dist/{ConsoleKernel-CJg975mp.d.ts → console/ConsoleKernel.d.ts} +4 -6
  60. package/dist/console/Input.d.ts +140 -0
  61. package/dist/console/Output.d.ts +161 -0
  62. package/dist/console/index.d.ts +5 -0
  63. package/dist/console/types.d.ts +106 -0
  64. package/dist/container/Container.d.ts +148 -0
  65. package/dist/container/ServiceProvider.d.ts +103 -0
  66. package/dist/container/bindings.d.ts +55 -0
  67. package/dist/container/defineModule.d.ts +88 -0
  68. package/dist/container/definePlugin.d.ts +62 -0
  69. package/dist/container/index.d.ts +8 -0
  70. package/dist/container/types.d.ts +73 -0
  71. package/dist/database/Factory.d.ts +82 -0
  72. package/dist/database/Seeder.d.ts +35 -0
  73. package/dist/database/SeederRunner.d.ts +41 -0
  74. package/dist/database/index.d.ts +4 -0
  75. package/dist/database/types.d.ts +49 -0
  76. package/dist/discovery/AutoDiscovery.d.ts +113 -0
  77. package/dist/discovery/index.d.ts +2 -0
  78. package/dist/docs-viewer/DocsViewerServiceProvider.d.ts +12 -0
  79. package/dist/docs-viewer/endpoint.d.ts +29 -0
  80. package/dist/encryption/Encrypter.d.ts +96 -0
  81. package/dist/encryption/Hash.d.ts +69 -0
  82. package/dist/encryption/MessageSigner.d.ts +21 -0
  83. package/dist/encryption/Random.d.ts +119 -0
  84. package/dist/encryption/app-key.d.ts +12 -0
  85. package/dist/encryption/index.d.ts +10 -222
  86. package/dist/encryption/signed-url.d.ts +9 -0
  87. package/dist/encryption/types.d.ts +103 -0
  88. package/dist/errors/ExceptionHandler.d.ts +118 -0
  89. package/dist/errors/HttpException.d.ts +106 -0
  90. package/dist/errors/debug-page.d.ts +22 -0
  91. package/dist/errors/error-page.d.ts +1 -0
  92. package/dist/errors/exceptions/AuthenticationException.d.ts +32 -0
  93. package/dist/errors/exceptions/AuthorizationException.d.ts +32 -0
  94. package/dist/errors/exceptions/MethodNotAllowedException.d.ts +31 -0
  95. package/dist/errors/exceptions/NotFoundHttpException.d.ts +36 -0
  96. package/dist/errors/exceptions/ValidationException.d.ts +60 -0
  97. package/dist/errors/exceptions/index.d.ts +5 -0
  98. package/dist/errors/index.d.ts +5 -0
  99. package/dist/errors/types.d.ts +43 -0
  100. package/dist/events/Event.d.ts +33 -0
  101. package/dist/{EventManager-CmIoLt7r.d.ts → events/EventManager.d.ts} +4 -86
  102. package/dist/events/Listener.d.ts +79 -0
  103. package/dist/events/builtin.d.ts +73 -0
  104. package/dist/events/index.d.ts +6 -155
  105. package/dist/events/types.d.ts +48 -0
  106. package/dist/facades/index.d.ts +31 -0
  107. package/dist/health/HealthCheck.d.ts +34 -0
  108. package/dist/health/HealthManager.d.ts +53 -0
  109. package/dist/health/checks/CacheCheck.d.ts +35 -0
  110. package/dist/health/checks/CustomCheck.d.ts +23 -0
  111. package/dist/health/checks/DatabaseCheck.d.ts +33 -0
  112. package/dist/health/checks/MemoryCheck.d.ts +32 -0
  113. package/dist/health/checks/RedisCheck.d.ts +27 -0
  114. package/dist/health/checks/StorageCheck.d.ts +35 -0
  115. package/dist/health/checks/index.d.ts +12 -0
  116. package/dist/health/index.d.ts +5 -185
  117. package/dist/health/types.d.ts +52 -0
  118. package/dist/hot-reload/hot-disposables.d.ts +96 -0
  119. package/dist/hot-reload/testing.d.ts +14 -0
  120. package/dist/http/Application.d.ts +199 -0
  121. package/dist/http/FormRequest.d.ts +73 -0
  122. package/dist/http/dev-assets.d.ts +62 -0
  123. package/dist/http/dev-banner.d.ts +7 -0
  124. package/dist/http/inertia-assets.d.ts +31 -0
  125. package/dist/http/middleware/auth.d.ts +13 -0
  126. package/dist/http/middleware/capabilities.d.ts +22 -0
  127. package/dist/http/middleware/cors.d.ts +40 -0
  128. package/dist/http/middleware/csp.d.ts +59 -0
  129. package/dist/http/middleware/csrf.d.ts +121 -0
  130. package/dist/http/middleware/detect-locale.d.ts +65 -0
  131. package/dist/http/middleware/force-https.d.ts +34 -0
  132. package/dist/http/middleware/host-authorization.d.ts +24 -0
  133. package/dist/http/middleware/index.d.ts +19 -0
  134. package/dist/http/middleware/loopback-guard.d.ts +51 -0
  135. package/dist/{rate-limit-D9J2b4S1.d.ts → http/middleware/rate-limit.d.ts} +22 -50
  136. package/dist/http/middleware/redirect-safety.d.ts +29 -0
  137. package/dist/http/middleware/request-id.d.ts +19 -0
  138. package/dist/http/middleware/request-logging.d.ts +16 -0
  139. package/dist/http/middleware/response-headers.d.ts +18 -0
  140. package/dist/http/middleware/security-headers.d.ts +49 -0
  141. package/dist/http/middleware/session.d.ts +93 -0
  142. package/dist/http/middleware/validation.d.ts +94 -0
  143. package/dist/http/public-assets.d.ts +15 -0
  144. package/dist/http/request.d.ts +24 -0
  145. package/dist/http/resources/CursorPaginator.d.ts +106 -0
  146. package/dist/http/resources/Paginator.d.ts +130 -0
  147. package/dist/http/resources/Resource.d.ts +67 -0
  148. package/dist/http/resources/ResourceCollection.d.ts +60 -0
  149. package/dist/http/resources/index.d.ts +6 -0
  150. package/dist/http/resources/types.d.ts +91 -0
  151. package/dist/http/validation/Validator.d.ts +128 -0
  152. package/dist/http/validation/index.d.ts +3 -0
  153. package/dist/http/validation/rules.d.ts +196 -0
  154. package/dist/http/validation/types.d.ts +96 -0
  155. package/dist/http/vite-dev-server.d.ts +27 -0
  156. package/dist/i18n/I18nManager.d.ts +114 -0
  157. package/dist/i18n/Translator.d.ts +80 -0
  158. package/dist/i18n/index.d.ts +6 -101
  159. package/dist/i18n/index.js +5 -3
  160. package/dist/i18n/loaders/JsonLoader.d.ts +47 -0
  161. package/dist/i18n/loaders/MemoryLoader.d.ts +37 -0
  162. package/dist/i18n/pluralization.d.ts +19 -0
  163. package/dist/i18n/types.d.ts +106 -0
  164. package/dist/index.d.ts +69 -2605
  165. package/dist/index.js +405 -180
  166. package/dist/lambda/index.d.ts +17 -37
  167. package/dist/logging/LogManager.d.ts +83 -0
  168. package/dist/logging/Logger.d.ts +76 -0
  169. package/dist/logging/channels/ConsoleChannel.d.ts +11 -0
  170. package/dist/logging/channels/DailyFileChannel.d.ts +20 -0
  171. package/dist/logging/channels/FileChannel.d.ts +15 -0
  172. package/dist/logging/index.d.ts +8 -50
  173. package/dist/logging/types.d.ts +96 -0
  174. package/dist/mail/Mail.d.ts +138 -0
  175. package/dist/mail/MailManager.d.ts +79 -0
  176. package/dist/mail/address.d.ts +8 -0
  177. package/dist/mail/index.d.ts +7 -316
  178. package/dist/mail/transports/LogTransport.d.ts +19 -0
  179. package/dist/mail/transports/MemoryTransport.d.ts +84 -0
  180. package/dist/mail/transports/ResendTransport.d.ts +32 -0
  181. package/dist/mail/transports/SmtpTransport.d.ts +40 -0
  182. package/dist/{MailManager-DpMvYiP9.d.ts → mail/types.d.ts} +11 -92
  183. package/dist/mcp/McpServiceProvider.d.ts +17 -0
  184. package/dist/mcp/create-mcp-server.d.ts +152 -0
  185. package/dist/mcp/endpoint.d.ts +47 -0
  186. package/dist/mcp/index.d.ts +3 -185
  187. package/dist/mcp/index.js +3 -3
  188. package/dist/mvc/Controller.d.ts +326 -0
  189. package/dist/mvc/Router.d.ts +239 -0
  190. package/dist/mvc/ViewEngine.d.ts +11 -0
  191. package/dist/mvc/inertia/InertiaEngine.d.ts +114 -0
  192. package/dist/mvc/inertia/shared.d.ts +90 -0
  193. package/dist/mvc/mount-route.d.ts +10 -0
  194. package/dist/notifications/Notification.d.ts +99 -0
  195. package/dist/notifications/NotificationManager.d.ts +150 -0
  196. package/dist/notifications/channels/DatabaseChannel.d.ts +55 -0
  197. package/dist/notifications/channels/MailChannel.d.ts +45 -0
  198. package/dist/notifications/channels/MemoryChannel.d.ts +85 -0
  199. package/dist/notifications/channels/SlackChannel.d.ts +73 -0
  200. package/dist/notifications/channels/index.d.ts +4 -0
  201. package/dist/notifications/index.d.ts +6 -322
  202. package/dist/notifications/notifiable-type.d.ts +10 -0
  203. package/dist/notifications/registry.d.ts +39 -0
  204. package/dist/notifications/types.d.ts +162 -0
  205. package/dist/providers/AuthServiceProvider.d.ts +7 -0
  206. package/dist/providers/AuthorizationServiceProvider.d.ts +9 -0
  207. package/dist/providers/BroadcastServiceProvider.d.ts +7 -0
  208. package/dist/providers/CacheServiceProvider.d.ts +7 -0
  209. package/dist/providers/EncryptionServiceProvider.d.ts +7 -0
  210. package/dist/providers/ErrorServiceProvider.d.ts +9 -0
  211. package/dist/providers/EventServiceProvider.d.ts +7 -0
  212. package/dist/providers/HealthServiceProvider.d.ts +7 -0
  213. package/dist/providers/I18nServiceProvider.d.ts +27 -0
  214. package/dist/providers/InertiaServiceProvider.d.ts +20 -0
  215. package/dist/providers/LogServiceProvider.d.ts +7 -0
  216. package/dist/providers/MailServiceProvider.d.ts +7 -0
  217. package/dist/providers/NotificationServiceProvider.d.ts +8 -0
  218. package/dist/providers/OAuthServiceProvider.d.ts +7 -0
  219. package/dist/providers/QueueServiceProvider.d.ts +7 -0
  220. package/dist/providers/SchedulingServiceProvider.d.ts +7 -0
  221. package/dist/providers/StorageServiceProvider.d.ts +7 -0
  222. package/dist/providers/index.d.ts +17 -0
  223. package/dist/queue/FailedJobReporter.d.ts +40 -0
  224. package/dist/queue/Job.d.ts +140 -0
  225. package/dist/queue/QueueManager.d.ts +79 -0
  226. package/dist/queue/Worker.d.ts +99 -0
  227. package/dist/queue/drivers/MemoryDriver.d.ts +60 -0
  228. package/dist/queue/drivers/RedisDriver.d.ts +96 -0
  229. package/dist/queue/drivers/SqsDriver.d.ts +108 -0
  230. package/dist/queue/drivers/SyncDriver.d.ts +28 -0
  231. package/dist/queue/index.d.ts +9 -453
  232. package/dist/queue/types.d.ts +171 -0
  233. package/dist/redis/RedisApiTokenStore.d.ts +78 -0
  234. package/dist/redis/RedisEmailVerificationStore.d.ts +54 -0
  235. package/dist/redis/RedisOAuthStateStore.d.ts +26 -0
  236. package/dist/redis/RedisPasswordResetStore.d.ts +57 -0
  237. package/dist/redis/RedisRateLimitStore.d.ts +77 -0
  238. package/dist/redis/RedisSessionStore.d.ts +61 -0
  239. package/dist/redis/client.d.ts +41 -0
  240. package/dist/redis/index.d.ts +14 -356
  241. package/dist/redis/index.js +45 -9
  242. package/dist/redis/redis-values.d.ts +17 -0
  243. package/dist/redis/scan-keys.d.ts +6 -0
  244. package/dist/runtime/index.d.ts +8 -95
  245. package/dist/runtime/index.js +101 -68
  246. package/dist/scheduling/CronParser.d.ts +37 -0
  247. package/dist/scheduling/Schedule.d.ts +229 -0
  248. package/dist/scheduling/ScheduledTask.d.ts +47 -0
  249. package/dist/scheduling/Scheduler.d.ts +99 -0
  250. package/dist/scheduling/index.d.ts +5 -41
  251. package/dist/scheduling/types.d.ts +97 -0
  252. package/dist/storage/StorageManager.d.ts +65 -0
  253. package/dist/storage/drivers/LocalDriver.d.ts +55 -0
  254. package/dist/storage/drivers/MemoryDriver.d.ts +66 -0
  255. package/dist/storage/drivers/S3Driver.d.ts +72 -0
  256. package/dist/storage/index.d.ts +5 -197
  257. package/dist/{StorageManager-oZTHqaza.d.ts → storage/types.d.ts} +10 -77
  258. package/dist/support/contained-path.d.ts +26 -0
  259. package/dist/support/error-polyfill.d.ts +9 -0
  260. package/dist/support/expiry.d.ts +47 -0
  261. package/dist/support/expiry.js +12 -0
  262. package/dist/support/import-map.d.ts +13 -0
  263. package/dist/support/redirect-target.d.ts +11 -0
  264. package/dist/support/stack-frames.d.ts +56 -0
  265. package/dist/support/trim-slashes.d.ts +11 -0
  266. package/dist/vite/index.d.ts +2 -35
  267. package/dist/vite/index.js +0 -3
  268. package/dist/vite/plugin.d.ts +34 -0
  269. package/package.json +7 -3
  270. package/dist/AuthManager-DBP4KYsx.d.ts +0 -79
  271. package/dist/BroadcastManager-D8KoJxiV.d.ts +0 -492
  272. package/dist/HealthManager-DUyMIzsZ.d.ts +0 -141
  273. package/dist/I18nManager-BiSoczfV.d.ts +0 -275
  274. package/dist/LogManager-7mxnkaPM.d.ts +0 -256
  275. package/dist/McpServiceProvider-7BB5FPF3.js +0 -8
  276. package/dist/Scheduler-pZiT8i57.d.ts +0 -471
  277. package/dist/api-token-D24VPr_E.d.ts +0 -663
  278. package/dist/app-key-CsBfRC_Q.d.ts +0 -214
  279. package/dist/email-verification-Dx426KLn.d.ts +0 -336
  280. package/dist/index-9_Jzj5jo.d.ts +0 -7
  281. package/dist/validation-yAL53e1S.d.ts +0 -2610
package/dist/index.js CHANGED
@@ -2,7 +2,7 @@ import {
2
2
  logDevServerBanner,
3
3
  parseImportMap,
4
4
  startViteDevServer
5
- } from "./chunk-5SZTEZ22.js";
5
+ } from "./chunk-6IGN233M.js";
6
6
  import {
7
7
  PendingSchedule,
8
8
  Schedule,
@@ -29,7 +29,7 @@ import {
29
29
  } from "./chunk-AZOYI43J.js";
30
30
  import {
31
31
  isDocsViewerEnabled
32
- } from "./chunk-WIXGT4TN.js";
32
+ } from "./chunk-A5JJ7XTH.js";
33
33
  import {
34
34
  I18nManager,
35
35
  JsonLoader,
@@ -42,8 +42,9 @@ import {
42
42
  selectPluralForm,
43
43
  setI18n,
44
44
  t,
45
- tc
46
- } from "./chunk-A3ISJVEV.js";
45
+ tc,
46
+ tryGetI18n
47
+ } from "./chunk-HR2KZ3WL.js";
47
48
  import {
48
49
  ConsoleChannel,
49
50
  DailyFileChannel,
@@ -71,11 +72,11 @@ import {
71
72
  import {
72
73
  MCP_ENDPOINT_PATH,
73
74
  isMcpEndpointEnabled
74
- } from "./chunk-JBG4AR24.js";
75
+ } from "./chunk-Q2P6YLRR.js";
75
76
  import {
76
77
  ProviderManager,
77
78
  ServiceProvider
78
- } from "./chunk-BZMZEFRG.js";
79
+ } from "./chunk-LHR6OHI7.js";
79
80
  import {
80
81
  DatabaseChannel,
81
82
  MailChannel,
@@ -134,6 +135,7 @@ import {
134
135
  MemorySessionStore,
135
136
  ModelUserProvider,
136
137
  NodeHasher,
138
+ OAUTH_SESSION_BINDING_KEY,
137
139
  OAuthManager,
138
140
  ScryptHasher,
139
141
  SessionGuard,
@@ -178,7 +180,8 @@ import {
178
180
  verifyEmailToken,
179
181
  verifyOAuthState,
180
182
  verifyPasswordResetToken
181
- } from "./chunk-J6ETA476.js";
183
+ } from "./chunk-TVV5YNEC.js";
184
+ import "./chunk-3KV5X2FL.js";
182
185
  import {
183
186
  Gate,
184
187
  Policy,
@@ -195,7 +198,7 @@ import {
195
198
  getGate,
196
199
  setGate,
197
200
  withAuthorization
198
- } from "./chunk-FZD2AKJI.js";
201
+ } from "./chunk-7OB2YXRE.js";
199
202
  import {
200
203
  AuthorizationException,
201
204
  ExceptionHandler,
@@ -228,7 +231,7 @@ import {
228
231
  getBroadcastManager,
229
232
  parseRequestPayload,
230
233
  setBroadcastManager
231
- } from "./chunk-TVY72CLV.js";
234
+ } from "./chunk-4VE3LYOM.js";
232
235
  import {
233
236
  CacheManager,
234
237
  FileStore,
@@ -236,7 +239,7 @@ import {
236
239
  RedisStore,
237
240
  TaggedCache,
238
241
  createCacheManager
239
- } from "./chunk-CWI4AJ47.js";
242
+ } from "./chunk-HPET6XY5.js";
240
243
  import {
241
244
  claimHotDisposable,
242
245
  isHotReloadRuntime,
@@ -904,11 +907,11 @@ async function resolveModelBindings(c, modelBindings, path) {
904
907
  const params = c.req.param();
905
908
  const pathParams = path?.match(/:([a-zA-Z0-9_-]+)/g)?.map((p) => p.slice(1)) ?? [];
906
909
  for (const param of pathParams) {
907
- const resolver2 = modelBindings.get(param);
908
- if (!resolver2) continue;
910
+ const resolver = modelBindings.get(param);
911
+ if (!resolver) continue;
909
912
  const value = params[param];
910
913
  if (value !== void 0) {
911
- const model = await resolver2(value);
914
+ const model = await resolver(value);
912
915
  resolved.push(model);
913
916
  }
914
917
  }
@@ -1032,7 +1035,10 @@ function randomNonce() {
1032
1035
  return Array.from(bytes, (byte) => byte.toString(16).padStart(2, "0")).join("");
1033
1036
  }
1034
1037
  function bindableSessionId(session) {
1035
- return session && !session.isNew ? session.id : void 0;
1038
+ if (!session) {
1039
+ return void 0;
1040
+ }
1041
+ return session.willPersist?.() ?? !session.isNew ? session.id : void 0;
1036
1042
  }
1037
1043
  function mintCsrfToken(sessionId) {
1038
1044
  const signer = createCsrfSigner();
@@ -1042,7 +1048,10 @@ function verifiedClaims(token) {
1042
1048
  return createCsrfSigner().verify(token, { purpose: CSRF_PURPOSE });
1043
1049
  }
1044
1050
  function claimsUsableFor(claims, boundId) {
1045
- return claims.sid !== void 0 ? claims.sid === boundId : boundId === void 0;
1051
+ if (claims.sid === void 0) {
1052
+ return boundId === void 0;
1053
+ }
1054
+ return boundId !== void 0 && secureCompare(claims.sid, boundId);
1046
1055
  }
1047
1056
  function matchesPattern(path, pattern) {
1048
1057
  if (pattern.endsWith("/*")) {
@@ -1058,21 +1067,23 @@ function isMcpEndpointRequest(path) {
1058
1067
  return path === MCP_ENDPOINT_PATH && isMcpEndpointEnabled();
1059
1068
  }
1060
1069
  function getCsrfToken(ctx) {
1061
- const pending = ctx.get(CSRF_CONTEXT_KEY);
1062
- if (pending) {
1063
- return pending;
1064
- }
1065
1070
  const boundId = bindableSessionId(getSessionFromContext(ctx));
1071
+ const issued = ctx.get(CSRF_CONTEXT_KEY);
1072
+ if (issued && issued.boundId === boundId) {
1073
+ return issued.token;
1074
+ }
1075
+ return remember(ctx, reusableCookieToken(ctx, boundId) ?? mintCsrfToken(boundId), boundId);
1076
+ }
1077
+ function reusableCookieToken(ctx, boundId) {
1066
1078
  const cookieToken = getCookie(ctx, XSRF_COOKIE_NAME);
1067
- if (cookieToken) {
1068
- const claims = verifiedClaims(cookieToken);
1069
- if (claims && claimsUsableFor(claims, boundId)) {
1070
- ctx.set(CSRF_CONTEXT_KEY, cookieToken);
1071
- return cookieToken;
1072
- }
1079
+ if (!cookieToken) {
1080
+ return void 0;
1073
1081
  }
1074
- const token = mintCsrfToken(boundId);
1075
- ctx.set(CSRF_CONTEXT_KEY, token);
1082
+ const claims = verifiedClaims(cookieToken);
1083
+ return claims && claimsUsableFor(claims, boundId) ? cookieToken : void 0;
1084
+ }
1085
+ function remember(ctx, token, boundId) {
1086
+ ctx.set(CSRF_CONTEXT_KEY, { token, boundId });
1076
1087
  return token;
1077
1088
  }
1078
1089
  function csrfField(ctx) {
@@ -1084,17 +1095,13 @@ function verifyCsrfToken(ctx, token) {
1084
1095
  return false;
1085
1096
  }
1086
1097
  const claims = verifiedClaims(token);
1087
- if (claims) {
1098
+ if (claims && claimsUsableFor(claims, bindableSessionId(getSessionFromContext(ctx)))) {
1088
1099
  if (claims.sid !== void 0) {
1089
- const boundId = bindableSessionId(getSessionFromContext(ctx));
1090
- if (boundId !== void 0 && secureCompare(claims.sid, boundId)) {
1091
- return true;
1092
- }
1093
- } else {
1094
- const cookieToken = getCookie(ctx, XSRF_COOKIE_NAME);
1095
- if (cookieToken && secureCompare(token, cookieToken)) {
1096
- return true;
1097
- }
1100
+ return true;
1101
+ }
1102
+ const cookieToken = getCookie(ctx, XSRF_COOKIE_NAME);
1103
+ if (cookieToken && secureCompare(token, cookieToken)) {
1104
+ return true;
1098
1105
  }
1099
1106
  }
1100
1107
  const sessionToken = getSessionFromContext(ctx)?.get(CSRF_TOKEN_KEY);
@@ -1143,19 +1150,22 @@ function createCsrfMiddleware(options = {}) {
1143
1150
  cookieOptions = {}
1144
1151
  } = options;
1145
1152
  const protectedMethods = new Set(methods.map((m) => m.toUpperCase()));
1153
+ const settleCookie = (ctx) => {
1154
+ if (enableCookie) {
1155
+ setXsrfCookie(ctx, getCsrfToken(ctx), cookieOptions);
1156
+ }
1157
+ };
1146
1158
  return async (ctx, next) => {
1147
1159
  const method = ctx.req.method.toUpperCase();
1148
1160
  const path = new URL(ctx.req.url).pathname;
1149
1161
  if (!protectedMethods.has(method)) {
1150
- const token = getCsrfToken(ctx);
1151
1162
  await next();
1152
- if (enableCookie) {
1153
- setXsrfCookie(ctx, token, cookieOptions);
1154
- }
1163
+ settleCookie(ctx);
1155
1164
  return;
1156
1165
  }
1157
1166
  if (isExcluded(path, exclude) || isMcpEndpointRequest(path)) {
1158
1167
  await next();
1168
+ settleCookie(ctx);
1159
1169
  return;
1160
1170
  }
1161
1171
  const requestToken = await getTokenFromRequest(ctx);
@@ -1167,9 +1177,7 @@ function createCsrfMiddleware(options = {}) {
1167
1177
  return jsonResponse({ message: "CSRF token mismatch" }, 403);
1168
1178
  }
1169
1179
  await next();
1170
- if (enableCookie) {
1171
- setXsrfCookie(ctx, getCsrfToken(ctx), cookieOptions);
1172
- }
1180
+ settleCookie(ctx);
1173
1181
  };
1174
1182
  }
1175
1183
  function setXsrfCookie(ctx, token, options = {}) {
@@ -1232,15 +1240,8 @@ function validateSafe(schema, data) {
1232
1240
 
1233
1241
  // src/http/middleware/rate-limit.ts
1234
1242
  var BaseMemoryStore = class {
1235
- cleanupInterval;
1236
- /**
1237
- * This store's claim on its hot-reload slot, if it holds one.
1238
- *
1239
- * Unlike the cache sweep, this interval is not `unref()`ed, so a leaked one
1240
- * both duplicates work and keeps the process alive on its own.
1241
- */
1242
- hotReloadClaim;
1243
- constructor(cleanupIntervalMs = 6e4) {
1243
+ constructor(cleanupIntervalMs = 6e4, now = () => Date.now()) {
1244
+ this.now = now;
1244
1245
  if (cleanupIntervalMs <= 0) {
1245
1246
  return;
1246
1247
  }
@@ -1252,6 +1253,15 @@ var BaseMemoryStore = class {
1252
1253
  () => this.destroy()
1253
1254
  );
1254
1255
  }
1256
+ now;
1257
+ cleanupInterval;
1258
+ /**
1259
+ * This store's claim on its hot-reload slot, if it holds one.
1260
+ *
1261
+ * Unlike the cache sweep, this interval is not `unref()`ed, so a leaked one
1262
+ * both duplicates work and keeps the process alive on its own.
1263
+ */
1264
+ hotReloadClaim;
1255
1265
  destroy() {
1256
1266
  if (this.cleanupInterval) {
1257
1267
  clearInterval(this.cleanupInterval);
@@ -1265,14 +1275,14 @@ var MemoryRateLimitStore = class extends BaseMemoryStore {
1265
1275
  async get(key) {
1266
1276
  const entry = this.entries.get(key);
1267
1277
  if (!entry) return null;
1268
- if (Date.now() >= entry.resetAt) {
1278
+ if (this.now() >= entry.resetAt) {
1269
1279
  this.entries.delete(key);
1270
1280
  return null;
1271
1281
  }
1272
1282
  return entry;
1273
1283
  }
1274
1284
  async increment(key, windowMs) {
1275
- const now = Date.now();
1285
+ const now = this.now();
1276
1286
  const existing = this.entries.get(key);
1277
1287
  if (existing && now < existing.resetAt) {
1278
1288
  existing.count++;
@@ -1286,7 +1296,7 @@ var MemoryRateLimitStore = class extends BaseMemoryStore {
1286
1296
  this.entries.delete(key);
1287
1297
  }
1288
1298
  cleanup() {
1289
- const now = Date.now();
1299
+ const now = this.now();
1290
1300
  for (const [key, entry] of this.entries.entries()) {
1291
1301
  if (now >= entry.resetAt) {
1292
1302
  this.entries.delete(key);
@@ -1353,13 +1363,19 @@ function createRateLimitMiddleware(options = {}) {
1353
1363
  windowMs = 6e4,
1354
1364
  trustProxy = false,
1355
1365
  keyGenerator = trustProxy ? proxyAwareKeyGenerator : defaultKeyGenerator,
1356
- store = getDefaultStore(),
1366
+ // An injected clock must drive the default store too, or expiry would run
1367
+ // on real time while Retry-After runs on the fake clock. The shared default
1368
+ // store stays on real time, so build a dedicated store instead — without
1369
+ // auto-cleanup, since a real-time sweep is meaningless on a fake clock and
1370
+ // its interval would outlive tests.
1371
+ store = options.now ? new MemoryRateLimitStore(0, options.now) : getDefaultStore(),
1357
1372
  skip,
1358
1373
  onRateLimited,
1359
1374
  headers = true,
1360
1375
  message = "Too many requests, please try again later.",
1361
1376
  statusCode = 429,
1362
- keyPrefix = "rl:"
1377
+ keyPrefix = "rl:",
1378
+ now = () => Date.now()
1363
1379
  } = options;
1364
1380
  return async (ctx, next) => {
1365
1381
  if (skip && await skip(ctx)) {
@@ -1369,7 +1385,7 @@ function createRateLimitMiddleware(options = {}) {
1369
1385
  const key = `${keyPrefix}${baseKey}`;
1370
1386
  const entry = await store.increment(key, windowMs);
1371
1387
  const remaining = Math.max(0, limit - entry.count);
1372
- const resetSeconds = Math.ceil((entry.resetAt - Date.now()) / 1e3);
1388
+ const resetSeconds = Math.max(0, Math.ceil((entry.resetAt - now()) / 1e3));
1373
1389
  if (headers) {
1374
1390
  ctx.header("X-RateLimit-Limit", limit.toString());
1375
1391
  ctx.header("X-RateLimit-Remaining", remaining.toString());
@@ -1416,7 +1432,7 @@ var SlidingWindowRateLimitStore = class extends BaseMemoryStore {
1416
1432
  async get(key) {
1417
1433
  const entry = this.requests.get(key);
1418
1434
  if (!entry || entry.timestamps.length === 0) return null;
1419
- const now = Date.now();
1435
+ const now = this.now();
1420
1436
  const windowStart = now - entry.windowMs;
1421
1437
  const timestamps = entry.timestamps.filter((t2) => t2 > windowStart);
1422
1438
  if (timestamps.length === 0) {
@@ -1429,7 +1445,7 @@ var SlidingWindowRateLimitStore = class extends BaseMemoryStore {
1429
1445
  return { count: timestamps.length, resetAt: timestamps[0] + entry.windowMs };
1430
1446
  }
1431
1447
  async increment(key, windowMs) {
1432
- const now = Date.now();
1448
+ const now = this.now();
1433
1449
  const windowStart = now - windowMs;
1434
1450
  const entry = this.requests.get(key);
1435
1451
  let timestamps = entry ? entry.timestamps.filter((t2) => t2 > windowStart) : [];
@@ -1441,7 +1457,7 @@ var SlidingWindowRateLimitStore = class extends BaseMemoryStore {
1441
1457
  this.requests.delete(key);
1442
1458
  }
1443
1459
  cleanup() {
1444
- const now = Date.now();
1460
+ const now = this.now();
1445
1461
  for (const [key, entry] of this.requests.entries()) {
1446
1462
  const windowStart = now - entry.windowMs;
1447
1463
  const valid = entry.timestamps.filter((t2) => t2 > windowStart);
@@ -1460,6 +1476,31 @@ var SlidingWindowRateLimitStore = class extends BaseMemoryStore {
1460
1476
  }
1461
1477
  };
1462
1478
 
1479
+ // src/http/middleware/response-headers.ts
1480
+ function applyResponseHeaders(ctx, headers) {
1481
+ const response = ctx.res;
1482
+ try {
1483
+ for (const [name, value] of headers) {
1484
+ if (!response.headers.has(name)) response.headers.set(name, value);
1485
+ }
1486
+ return;
1487
+ } catch (error) {
1488
+ if (!isImmutableHeadersError(error)) throw error;
1489
+ }
1490
+ const merged = new Headers(response.headers);
1491
+ for (const [name, value] of headers) {
1492
+ if (!merged.has(name)) merged.set(name, value);
1493
+ }
1494
+ ctx.res = new Response(response.body, {
1495
+ status: response.status,
1496
+ statusText: response.statusText,
1497
+ headers: merged
1498
+ });
1499
+ }
1500
+ function isImmutableHeadersError(error) {
1501
+ return error instanceof TypeError && /immutable/i.test(error.message);
1502
+ }
1503
+
1463
1504
  // src/http/middleware/security-headers.ts
1464
1505
  function createSecurityHeaders(options = {}) {
1465
1506
  const {
@@ -1471,26 +1512,21 @@ function createSecurityHeaders(options = {}) {
1471
1512
  hsts = process.env.NODE_ENV === "production" ? { maxAge: 31536e3 } : false
1472
1513
  } = options;
1473
1514
  const hstsValue = hsts !== false ? buildHstsValue(hsts) : null;
1515
+ const headers = [];
1516
+ if (frameOptions !== false) headers.push(["X-Frame-Options", frameOptions]);
1517
+ if (contentTypeOptions !== false) headers.push(["X-Content-Type-Options", contentTypeOptions]);
1518
+ if (xssProtection !== false) headers.push(["X-XSS-Protection", xssProtection]);
1519
+ if (referrerPolicy !== false) headers.push(["Referrer-Policy", referrerPolicy]);
1520
+ if (crossDomainPolicies !== false) {
1521
+ headers.push(["X-Permitted-Cross-Domain-Policies", crossDomainPolicies]);
1522
+ }
1523
+ if (hstsValue) headers.push(["Strict-Transport-Security", hstsValue]);
1474
1524
  return async (ctx, next) => {
1475
- if (frameOptions !== false) {
1476
- ctx.header("X-Frame-Options", frameOptions);
1477
- }
1478
- if (contentTypeOptions !== false) {
1479
- ctx.header("X-Content-Type-Options", contentTypeOptions);
1480
- }
1481
- if (xssProtection !== false) {
1482
- ctx.header("X-XSS-Protection", xssProtection);
1483
- }
1484
- if (referrerPolicy !== false) {
1485
- ctx.header("Referrer-Policy", referrerPolicy);
1486
- }
1487
- if (crossDomainPolicies !== false) {
1488
- ctx.header("X-Permitted-Cross-Domain-Policies", crossDomainPolicies);
1489
- }
1490
- if (hstsValue) {
1491
- ctx.header("Strict-Transport-Security", hstsValue);
1525
+ try {
1526
+ await next();
1527
+ } finally {
1528
+ applyResponseHeaders(ctx, headers);
1492
1529
  }
1493
- await next();
1494
1530
  };
1495
1531
  }
1496
1532
  function buildHstsValue(options) {
@@ -1527,10 +1563,11 @@ function createCspMiddleware(options = {}) {
1527
1563
  ctx.set(CSP_NONCE_KEY, nonce);
1528
1564
  }
1529
1565
  const headerValue = buildCspHeader(directives, nonce, reportUri);
1530
- if (headerValue) {
1531
- ctx.header(headerName, headerValue);
1566
+ try {
1567
+ await next();
1568
+ } finally {
1569
+ if (headerValue) applyResponseHeaders(ctx, [[headerName, headerValue]]);
1532
1570
  }
1533
- await next();
1534
1571
  };
1535
1572
  }
1536
1573
  function camelToKebab(str) {
@@ -1710,8 +1747,11 @@ function createForceHttpsMiddleware(options = {}) {
1710
1747
  url2.protocol = "https:";
1711
1748
  return ctx.redirect(url2.toString(), 301);
1712
1749
  }
1713
- ctx.header("Strict-Transport-Security", hstsValue);
1714
- await next();
1750
+ try {
1751
+ await next();
1752
+ } finally {
1753
+ applyResponseHeaders(ctx, [["Strict-Transport-Security", hstsValue]]);
1754
+ }
1715
1755
  };
1716
1756
  }
1717
1757
 
@@ -1754,6 +1794,16 @@ import { createMiddleware as createMiddleware3 } from "hono/factory";
1754
1794
  import { getCookie as getCookie2 } from "hono/cookie";
1755
1795
  import { parseAccept } from "hono/utils/accept";
1756
1796
  var LOCALE_CONTEXT_KEY = "locale";
1797
+ function getRequestLocale(c) {
1798
+ const locale = c.var?.[LOCALE_CONTEXT_KEY];
1799
+ return typeof locale === "string" && locale.length > 0 ? locale : void 0;
1800
+ }
1801
+ function getRequestTranslator(c) {
1802
+ const vars = c.var;
1803
+ const t2 = vars?.["t"];
1804
+ const tc2 = vars?.["tc"];
1805
+ return typeof t2 === "function" && typeof tc2 === "function" ? { t: t2, tc: tc2 } : void 0;
1806
+ }
1757
1807
  var DEFAULT_SOURCES = ["query", "cookie", "header"];
1758
1808
  function detectLocaleMiddleware(options) {
1759
1809
  const supported = options.supported.map((locale) => locale.trim()).filter(Boolean);
@@ -1788,26 +1838,20 @@ function detectLocaleMiddleware(options) {
1788
1838
  return void 0;
1789
1839
  };
1790
1840
  const translators = /* @__PURE__ */ new Map();
1791
- const resolveTranslator = async (locale) => {
1792
- if (options.i18n === false) {
1793
- return void 0;
1794
- }
1841
+ const supportedSet = new Set(supported);
1842
+ const bindingFor = (locale, i18n) => {
1795
1843
  const cached = translators.get(locale);
1796
1844
  if (cached) {
1797
1845
  return cached;
1798
1846
  }
1799
- const i18n = options.i18n ?? tryGlobalI18n();
1800
- if (!i18n) {
1801
- return void 0;
1802
- }
1803
- await i18n.loadLocale(locale).catch(() => {
1804
- });
1805
1847
  const translator = i18n.forLocale(locale);
1806
1848
  const binding = {
1807
1849
  t: translator.t.bind(translator),
1808
1850
  tc: translator.tc.bind(translator)
1809
1851
  };
1810
- translators.set(locale, binding);
1852
+ if (supportedSet.has(locale) && i18n.isLocaleLoaded(locale)) {
1853
+ translators.set(locale, binding);
1854
+ }
1811
1855
  return binding;
1812
1856
  };
1813
1857
  return createMiddleware3(async (c, next) => {
@@ -1825,21 +1869,17 @@ function detectLocaleMiddleware(options) {
1825
1869
  }
1826
1870
  }
1827
1871
  c.set(LOCALE_CONTEXT_KEY, resolved);
1828
- const binding = await resolveTranslator(resolved);
1829
- if (binding) {
1830
- c.set("t", binding.t);
1831
- c.set("tc", binding.tc);
1872
+ const i18n = options.i18n === false ? void 0 : options.i18n ?? tryGetI18n();
1873
+ if (i18n) {
1874
+ await i18n.loadLocale(resolved).catch(() => {
1875
+ });
1876
+ const current = () => bindingFor(getRequestLocale(c) ?? resolved, i18n);
1877
+ c.set("t", (key, replacements) => current().t(key, replacements));
1878
+ c.set("tc", (key, count, replacements) => current().tc(key, count, replacements));
1832
1879
  }
1833
1880
  await next();
1834
1881
  });
1835
1882
  }
1836
- function tryGlobalI18n() {
1837
- try {
1838
- return getI18n();
1839
- } catch {
1840
- return void 0;
1841
- }
1842
- }
1843
1883
 
1844
1884
  // src/http/middleware/index.ts
1845
1885
  function defineMiddleware(handler) {
@@ -2009,6 +2049,163 @@ var ErrorServiceProvider = class extends ServiceProvider {
2009
2049
  }
2010
2050
  };
2011
2051
 
2052
+ // src/mvc/inertia/shared.ts
2053
+ var INERTIA_SHARED_PROPS_BINDING = "inertia.sharedProps";
2054
+ var registrationSequence = 0;
2055
+ var SharedInertiaPropsRegistry = class {
2056
+ resolvers = [];
2057
+ /** Replace every resolver registered in this scope. */
2058
+ set(resolverFn) {
2059
+ this.resolvers = resolverFn ? [orderedResolver(resolverFn)] : [];
2060
+ }
2061
+ /**
2062
+ * Register additional shared props without replacing resolvers registered
2063
+ * earlier — the new resolver's props are merged over the previous ones.
2064
+ */
2065
+ share(resolverFn) {
2066
+ this.resolvers.push(orderedResolver(resolverFn));
2067
+ }
2068
+ /** The resolvers registered in this scope, ordered by registration. */
2069
+ entries() {
2070
+ return this.resolvers;
2071
+ }
2072
+ /**
2073
+ * The scope's registrations composed into one resolver, or null when empty.
2074
+ * The composition is a snapshot: resolvers registered later are not picked up.
2075
+ */
2076
+ get() {
2077
+ if (this.resolvers.length === 0) return null;
2078
+ if (this.resolvers.length === 1) return this.resolvers[0].resolve;
2079
+ const snapshot = [...this.resolvers];
2080
+ return (ctx) => applyResolvers(snapshot, ctx);
2081
+ }
2082
+ async resolve(ctx) {
2083
+ return applyResolvers(this.resolvers, ctx);
2084
+ }
2085
+ };
2086
+ function orderedResolver(resolverFn) {
2087
+ return {
2088
+ seq: registrationSequence++,
2089
+ resolve: resolverFn
2090
+ };
2091
+ }
2092
+ async function applyResolvers(entries, ctx) {
2093
+ const merged = {};
2094
+ for (const entry of entries) {
2095
+ const props = await entry.resolve(ctx);
2096
+ if (props && typeof props === "object") {
2097
+ Object.assign(merged, props);
2098
+ }
2099
+ }
2100
+ return merged;
2101
+ }
2102
+ var globalRegistry = new SharedInertiaPropsRegistry();
2103
+ function scopedRegistry(container) {
2104
+ if (!container?.has?.(INERTIA_SHARED_PROPS_BINDING)) return null;
2105
+ return container.make(INERTIA_SHARED_PROPS_BINDING);
2106
+ }
2107
+ function ensureSharedInertiaPropsRegistry(container) {
2108
+ const existing = scopedRegistry(container);
2109
+ if (existing) return existing;
2110
+ const registry = new SharedInertiaPropsRegistry();
2111
+ container.instance(INERTIA_SHARED_PROPS_BINDING, registry);
2112
+ return registry;
2113
+ }
2114
+ function setInertiaSharedProps(resolverFn) {
2115
+ globalRegistry.set(resolverFn);
2116
+ }
2117
+ function getInertiaSharedPropsResolver() {
2118
+ return globalRegistry.get();
2119
+ }
2120
+ function shareInertiaProps(resolverFn, container) {
2121
+ const registry = container ? ensureSharedInertiaPropsRegistry(container) : globalRegistry;
2122
+ registry.share(resolverFn);
2123
+ }
2124
+ async function resolveSharedInertiaProps(ctx, container) {
2125
+ const scoped = scopedRegistry(container);
2126
+ if (!scoped) return globalRegistry.resolve(ctx);
2127
+ const globalEntries = globalRegistry.entries();
2128
+ if (globalEntries.length === 0) return scoped.resolve(ctx);
2129
+ const ordered = [...globalEntries, ...scoped.entries()].sort((a, b) => a.seq - b.seq);
2130
+ return applyResolvers(ordered, ctx);
2131
+ }
2132
+
2133
+ // src/providers/I18nServiceProvider.ts
2134
+ var I18nServiceProvider = class extends ServiceProvider {
2135
+ register() {
2136
+ const app = this.application();
2137
+ const options = app?.i18nOptions;
2138
+ if (options) {
2139
+ if (options.supported.length === 0) {
2140
+ throw new Error("createApp({ i18n }) requires at least one supported locale.");
2141
+ }
2142
+ if (options.fallback && !options.supported.includes(options.fallback)) {
2143
+ throw new Error(
2144
+ `createApp({ i18n }): fallback locale '${options.fallback}' must be one of the supported locales (${options.supported.join(", ")}).`
2145
+ );
2146
+ }
2147
+ }
2148
+ this.container.singleton("i18n", () => {
2149
+ if (!options) {
2150
+ return createI18n({ locale: "en" });
2151
+ }
2152
+ const fallback = options.fallback ?? options.supported[0];
2153
+ return createI18n({
2154
+ locale: fallback,
2155
+ fallbackLocale: fallback,
2156
+ path: options.loader ? void 0 : options.path ?? "lang",
2157
+ loader: options.loader
2158
+ });
2159
+ });
2160
+ if (app && options && options.detect !== false) {
2161
+ const manager = this.container.make("i18n");
2162
+ app.use("*", detectLocaleMiddleware({
2163
+ ...options.detect,
2164
+ supported: options.supported,
2165
+ fallback: manager.getLocale(),
2166
+ i18n: manager
2167
+ }));
2168
+ }
2169
+ }
2170
+ async boot() {
2171
+ const options = this.application()?.i18nOptions;
2172
+ if (!options) return;
2173
+ const manager = this.container.make("i18n");
2174
+ await manager.loadLocales([...options.supported]);
2175
+ for (const locale of options.supported) {
2176
+ if (Object.keys(manager.getMessages(locale)).length === 0) {
2177
+ console.warn(
2178
+ `[guren] i18n: no translations loaded for locale '${locale}'` + (options.loader ? "." : ` \u2014 expected ${options.path ?? "lang"}/${locale}/*.json.`)
2179
+ );
2180
+ }
2181
+ }
2182
+ if (options.share !== false) {
2183
+ const fallback = manager.getFallbackLocale() ?? manager.getLocale();
2184
+ const supported = new Set(options.supported);
2185
+ const propsByLocale = /* @__PURE__ */ new Map();
2186
+ shareInertiaProps((ctx) => {
2187
+ const locale = getRequestLocale(ctx) ?? fallback;
2188
+ let i18nProps = propsByLocale.get(locale);
2189
+ if (!i18nProps) {
2190
+ i18nProps = {
2191
+ locale,
2192
+ fallbackLocale: fallback,
2193
+ messages: manager.messagesForLocale(locale)
2194
+ };
2195
+ if (supported.has(locale)) {
2196
+ propsByLocale.set(locale, i18nProps);
2197
+ }
2198
+ }
2199
+ return { _i18n: i18nProps };
2200
+ }, this.container);
2201
+ }
2202
+ }
2203
+ /** The provider works standalone on a bare container (no `app` binding). */
2204
+ application() {
2205
+ return this.container.has("app") ? this.container.make("app") : void 0;
2206
+ }
2207
+ };
2208
+
2012
2209
  // src/mvc/inertia/InertiaEngine.ts
2013
2210
  import { isAbsolute, resolve as resolvePath } from "path";
2014
2211
  import { pathToFileURL } from "url";
@@ -2317,31 +2514,6 @@ var ViewEngine = class {
2317
2514
  }
2318
2515
  };
2319
2516
 
2320
- // src/mvc/inertia/shared.ts
2321
- var resolver = null;
2322
- function setInertiaSharedProps(resolverFn) {
2323
- resolver = resolverFn;
2324
- }
2325
- function getInertiaSharedPropsResolver() {
2326
- return resolver;
2327
- }
2328
- function shareInertiaProps(resolverFn) {
2329
- const previous = resolver;
2330
- resolver = async (ctx) => {
2331
- const prev = previous ? await previous(ctx) : {};
2332
- const next = await resolverFn(ctx);
2333
- return { ...prev, ...next };
2334
- };
2335
- }
2336
- async function resolveSharedInertiaProps(ctx) {
2337
- if (!resolver) return {};
2338
- const shared = await resolver(ctx);
2339
- if (shared && typeof shared === "object") {
2340
- return shared;
2341
- }
2342
- return {};
2343
- }
2344
-
2345
2517
  // src/providers/InertiaServiceProvider.ts
2346
2518
  var InertiaServiceProvider = class extends ServiceProvider {
2347
2519
  register() {
@@ -2391,19 +2563,16 @@ var InertiaServiceProvider = class extends ServiceProvider {
2391
2563
  });
2392
2564
  }
2393
2565
  /**
2394
- * Wrap existing shared props resolver to auto-inject flashed `errors`.
2566
+ * Auto-inject flashed `errors` into shared props. Scoped to this app's
2567
+ * container so a second Application booted in the same process keeps its
2568
+ * own registrations.
2395
2569
  */
2396
2570
  registerSharedErrors() {
2397
- const previous = getInertiaSharedPropsResolver();
2398
- setInertiaSharedProps(async (ctx) => {
2399
- const prev = previous ? await previous(ctx) : {};
2571
+ shareInertiaProps(async (ctx) => {
2400
2572
  const session = getSessionFromContext(ctx);
2401
2573
  const errors = session?.getFlash("errors");
2402
- return {
2403
- ...prev,
2404
- ...errors && Object.keys(errors).length > 0 ? { errors } : {}
2405
- };
2406
- });
2574
+ return errors && Object.keys(errors).length > 0 ? { errors } : {};
2575
+ }, this.container);
2407
2576
  }
2408
2577
  };
2409
2578
 
@@ -2481,6 +2650,7 @@ var Application = class {
2481
2650
  this.router = new Router();
2482
2651
  this.authManager = new AuthManager();
2483
2652
  this.providerManager = new ProviderManager(this.container);
2653
+ this.mountSecurityDefaults();
2484
2654
  this.container.instance("app", this);
2485
2655
  this.container.instance("hono", this.hono);
2486
2656
  this.container.instance("auth", this.authManager);
@@ -2508,19 +2678,17 @@ var Application = class {
2508
2678
  ...Array.isArray(this.options.providers) ? this.options.providers : [],
2509
2679
  ...moduleProviders
2510
2680
  ];
2511
- const hasUserErrorProvider = userProviders.some(
2512
- (provider) => provider === ErrorServiceProvider || provider.prototype instanceof ErrorServiceProvider
2513
- );
2514
- if (!hasUserErrorProvider) {
2681
+ const hasUserProviderOf = (base) => userProviders.some((provider) => provider === base || provider.prototype instanceof base);
2682
+ if (this.options.i18n && !hasUserProviderOf(I18nServiceProvider)) {
2683
+ this.providerManager.register(I18nServiceProvider);
2684
+ }
2685
+ if (!hasUserProviderOf(ErrorServiceProvider)) {
2515
2686
  this.providerManager.register(ErrorServiceProvider);
2516
2687
  }
2517
2688
  if (userProviders.length > 0) {
2518
2689
  this.providerManager.registerMany(userProviders);
2519
2690
  }
2520
- const hasUserInertiaProvider = userProviders.some(
2521
- (provider) => provider === InertiaServiceProvider || provider.prototype instanceof InertiaServiceProvider
2522
- );
2523
- if (!hasUserInertiaProvider) {
2691
+ if (!hasUserProviderOf(InertiaServiceProvider)) {
2524
2692
  this.providerManager.register(InertiaServiceProvider);
2525
2693
  }
2526
2694
  }
@@ -2536,12 +2704,16 @@ var Application = class {
2536
2704
  bunTeardownRegistered = false;
2537
2705
  autoSessionAttached = false;
2538
2706
  routesRegistered = false;
2707
+ bootPromise;
2539
2708
  get auth() {
2540
2709
  return this.authManager;
2541
2710
  }
2542
2711
  get authOptions() {
2543
2712
  return this.options.auth;
2544
2713
  }
2714
+ get i18nOptions() {
2715
+ return this.options.i18n;
2716
+ }
2545
2717
  markAutoSessionAttached() {
2546
2718
  this.autoSessionAttached = true;
2547
2719
  }
@@ -2571,26 +2743,44 @@ var Application = class {
2571
2743
  }
2572
2744
  /**
2573
2745
  * Executes provider registration, boot callback, mounts routes, and boots providers.
2746
+ *
2747
+ * Booting twice is a no-op: the first call's promise is reused, so providers
2748
+ * and routes are never mounted a second time — including when two callers
2749
+ * boot concurrently, before the first has finished. A boot that throws is not
2750
+ * remembered, so a later call attempts boot again (it resumes on a partially
2751
+ * mounted app rather than starting clean). The security defaults are mounted
2752
+ * by the constructor and so are outside this entirely.
2574
2753
  */
2575
2754
  async boot() {
2576
- this.mountSecurityDefaults();
2755
+ this.bootPromise ??= this.bootOnce();
2756
+ try {
2757
+ await this.bootPromise;
2758
+ } catch (error) {
2759
+ this.bootPromise = void 0;
2760
+ throw error;
2761
+ }
2762
+ }
2763
+ async bootOnce() {
2577
2764
  await this.providerManager.registerAll();
2578
2765
  await this.options.boot?.(this.hono);
2579
2766
  await this.mountRoutes();
2580
2767
  await this.mountDevEndpoint(
2581
2768
  isMcpEndpointEnabled(),
2582
- async () => (await import("./McpServiceProvider-7BB5FPF3.js")).McpServiceProvider,
2769
+ async () => (await import("./McpServiceProvider-FRJ5O7LT.js")).McpServiceProvider,
2583
2770
  "GUREN_MCP=1 but the MCP endpoint could not load \u2014 is @modelcontextprotocol/sdk installed?"
2584
2771
  );
2585
2772
  await this.mountDevEndpoint(
2586
2773
  isDocsViewerEnabled(),
2587
- async () => (await import("./DocsViewerServiceProvider-D7RGJPGM.js")).DocsViewerServiceProvider,
2774
+ async () => (await import("./DocsViewerServiceProvider-RUYDFBMW.js")).DocsViewerServiceProvider,
2588
2775
  "GUREN_DOCS=1 but the docs viewer could not load \u2014 is @guren/cli resolvable from this app?"
2589
2776
  );
2590
2777
  await this.providerManager.bootAll();
2591
2778
  }
2592
2779
  /**
2593
2780
  * Registers default security middleware (headers + host authorization).
2781
+ *
2782
+ * Called once, from the constructor — see the note there for why it does
2783
+ * not belong in boot().
2594
2784
  */
2595
2785
  mountSecurityDefaults() {
2596
2786
  const { securityHeaders } = this.options;
@@ -2653,7 +2843,7 @@ var Application = class {
2653
2843
  const { server: server2, localUrl } = await startViteDevServer({
2654
2844
  root: viteOptions?.root ?? process.cwd(),
2655
2845
  config: viteOptions?.config,
2656
- host: viteOptions?.host ?? true,
2846
+ host: viteOptions?.host,
2657
2847
  port: viteOptions?.port
2658
2848
  });
2659
2849
  this.viteDevServer = server2;
@@ -2930,11 +3120,13 @@ var Controller = class {
2930
3120
  const { url: overrideUrl, ...rest } = options;
2931
3121
  const url2 = overrideUrl ?? ctx.req.path ?? ctx.req.url ?? "";
2932
3122
  const component = typeof componentOrPage === "string" ? componentOrPage : componentOrPage.component ?? componentOrPage.id;
2933
- const sharedProps = await resolveSharedInertiaProps(ctx);
3123
+ const sharedProps = await resolveSharedInertiaProps(ctx, this._container);
2934
3124
  const propsWithShared = { ...sharedProps, ...props };
2935
3125
  const response = await inertia(component, propsWithShared, {
2936
3126
  ...rest,
2937
- lang: rest.lang ?? this.#defaultInertiaLang(),
3127
+ // No 'en' fallback here (unlike the locale getter): unconfigured apps
3128
+ // keep the Inertia engine's own default lang.
3129
+ lang: rest.lang ?? this.#resolveLocale(),
2938
3130
  url: url2,
2939
3131
  request: ctx.req.raw
2940
3132
  });
@@ -2945,29 +3137,65 @@ var Controller = class {
2945
3137
  return response;
2946
3138
  }
2947
3139
  /**
2948
- * Default `<html lang>` for Inertia responses when `options.lang` is not
2949
- * provided: the request-scoped `locale` context variable (set by locale
2950
- * middleware) wins over the app-wide i18n locale (the router-injected
2951
- * container binding, then the `setI18n()` global).
3140
+ * Locale resolved for the current request: the request-scoped `locale`
3141
+ * context variable (set by locale middleware) wins over the app-wide i18n
3142
+ * locale (the router-injected container binding, then the `setI18n()`
3143
+ * global). Falls back to `'en'` when no i18n is configured.
3144
+ */
3145
+ get locale() {
3146
+ return this.#resolveLocale() ?? "en";
3147
+ }
3148
+ /**
3149
+ * Translate a key for the current request locale.
3150
+ *
3151
+ * Uses the request-scoped translator bound by the locale detection
3152
+ * middleware when present, falling back to a translator scoped to
3153
+ * `this.locale` from the container's `i18n` binding (then the `setI18n()`
3154
+ * global).
3155
+ *
3156
+ * @example
3157
+ * ```typescript
3158
+ * this.t('posts.created')
3159
+ * this.t('posts.greeting', { name: user.name })
3160
+ * ```
2952
3161
  */
2953
- #defaultInertiaLang() {
2954
- const vars = this.ctx.var;
2955
- const requestLocale = vars?.[LOCALE_CONTEXT_KEY];
2956
- if (typeof requestLocale === "string" && requestLocale.length > 0) {
3162
+ t(key, replacements) {
3163
+ return this.#requestTranslator().t(key, replacements);
3164
+ }
3165
+ /**
3166
+ * Translate a key with a count for pluralization, using the same locale
3167
+ * resolution as {@link Controller.t}.
3168
+ */
3169
+ tc(key, count, replacements) {
3170
+ return this.#requestTranslator().tc(key, count, replacements);
3171
+ }
3172
+ #requestTranslator() {
3173
+ const bound = getRequestTranslator(this.ctx);
3174
+ if (bound) {
3175
+ return bound;
3176
+ }
3177
+ const i18n = this.#resolveI18n();
3178
+ if (!i18n) {
3179
+ throw new Error(
3180
+ "Controller i18n helpers require i18n to be configured. Pass createApp({ i18n }) or register an I18nManager."
3181
+ );
3182
+ }
3183
+ const locale = getRequestLocale(this.ctx);
3184
+ return locale && locale !== i18n.getLocale() ? i18n.forLocale(locale) : i18n;
3185
+ }
3186
+ #resolveLocale() {
3187
+ const requestLocale = getRequestLocale(this.ctx);
3188
+ if (requestLocale) {
2957
3189
  return requestLocale;
2958
3190
  }
2959
- let i18n;
3191
+ const locale = this.#resolveI18n()?.getLocale();
3192
+ return typeof locale === "string" && locale.length > 0 ? locale : void 0;
3193
+ }
3194
+ #resolveI18n() {
2960
3195
  if (this._container?.has?.("i18n")) {
2961
- i18n = this._container.make("i18n");
2962
- } else {
2963
- try {
2964
- i18n = getI18n();
2965
- } catch {
2966
- i18n = void 0;
2967
- }
3196
+ return this._container.make("i18n");
2968
3197
  }
2969
- const locale = i18n?.getLocale?.();
2970
- return typeof locale === "string" && locale.length > 0 ? locale : void 0;
3198
+ return tryGetI18n();
2971
3199
  }
2972
3200
  json(data, init = {}) {
2973
3201
  return new Response(JSON.stringify(data), {
@@ -3239,13 +3467,6 @@ var LogServiceProvider = class extends ServiceProvider {
3239
3467
  }
3240
3468
  };
3241
3469
 
3242
- // src/providers/I18nServiceProvider.ts
3243
- var I18nServiceProvider = class extends ServiceProvider {
3244
- register() {
3245
- this.container.singleton("i18n", () => createI18n({ locale: "en" }));
3246
- }
3247
- };
3248
-
3249
3470
  // src/providers/NotificationServiceProvider.ts
3250
3471
  var NotificationServiceProvider = class extends ServiceProvider {
3251
3472
  register() {
@@ -6833,6 +7054,7 @@ export {
6833
7054
  Notification,
6834
7055
  NotificationManager,
6835
7056
  NotificationServiceProvider,
7057
+ OAUTH_SESSION_BINDING_KEY,
6836
7058
  OAuthManager,
6837
7059
  OAuthServiceProvider,
6838
7060
  Output,
@@ -7013,6 +7235,8 @@ export {
7013
7235
  getQueueDriver,
7014
7236
  getRateLimitInfo,
7015
7237
  getRegisteredJobs,
7238
+ getRequestLocale,
7239
+ getRequestTranslator,
7016
7240
  getSessionFromContext,
7017
7241
  getUserApiTokens,
7018
7242
  getValidatedData,
@@ -7122,6 +7346,7 @@ export {
7122
7346
  tokenCan,
7123
7347
  tokenCanAll,
7124
7348
  tokenCanAny,
7349
+ tryGetI18n,
7125
7350
  unique,
7126
7351
  url as urlRule,
7127
7352
  urlSafeToken,