@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
@@ -3,7 +3,7 @@ import {
3
3
  logDevServerBanner,
4
4
  parseImportMap,
5
5
  startViteDevServer
6
- } from "../chunk-5SZTEZ22.js";
6
+ } from "../chunk-6IGN233M.js";
7
7
  import {
8
8
  trimTrailingSlashes
9
9
  } from "../chunk-AZOYI43J.js";
@@ -13,12 +13,38 @@ import {
13
13
 
14
14
  // src/http/dev-assets.ts
15
15
  import { serveStatic } from "hono/bun";
16
- import { dirname, extname as extname2, resolve as resolve2 } from "path";
16
+ import { dirname, extname as extname2, join, resolve as resolve2 } from "path";
17
17
  import { fileURLToPath } from "url";
18
18
  import { createRequire } from "module";
19
19
 
20
20
  // src/http/public-assets.ts
21
- import { extname, resolve, sep } from "path";
21
+ import { extname, resolve } from "path";
22
+
23
+ // src/support/contained-path.ts
24
+ import { realpath } from "fs/promises";
25
+ import { sep } from "path";
26
+ function isPathWithin(root, candidate) {
27
+ return candidate.startsWith(root.endsWith(sep) ? root : root + sep);
28
+ }
29
+ async function isRealPathWithin(root, candidate) {
30
+ if (!isPathWithin(root, candidate)) {
31
+ return false;
32
+ }
33
+ const [realRoot, realCandidate] = await Promise.all([canonicalize(root), canonicalize(candidate)]);
34
+ if (!realRoot || !realCandidate) {
35
+ return false;
36
+ }
37
+ return isPathWithin(realRoot, realCandidate);
38
+ }
39
+ async function canonicalize(path) {
40
+ try {
41
+ return await realpath(path);
42
+ } catch {
43
+ return void 0;
44
+ }
45
+ }
46
+
47
+ // src/http/public-assets.ts
22
48
  var DEFAULT_CACHE_CONTROL = "public, max-age=31536000, immutable";
23
49
  var DEFAULT_EXTENSIONS = [".svg", ".png", ".jpg", ".jpeg", ".gif", ".ico", ".webp", ".avif", ".webmanifest", ".txt"];
24
50
  var DEFAULT_CONTENT_TYPES = {
@@ -61,13 +87,16 @@ function registerRootPublicAssets(app, publicDir, config) {
61
87
  return next();
62
88
  }
63
89
  const candidatePath = resolve(publicDir, relativePath);
64
- if (!candidatePath.startsWith(publicDir + sep) && candidatePath !== publicDir) {
90
+ if (!isPathWithin(publicDir, candidatePath) && candidatePath !== publicDir) {
65
91
  return next();
66
92
  }
67
93
  const file = Bun.file(candidatePath);
68
94
  if (!await file.exists()) {
69
95
  return next();
70
96
  }
97
+ if (!await isRealPathWithin(publicDir, candidatePath)) {
98
+ return next();
99
+ }
71
100
  const headers = new Headers({
72
101
  "Cache-Control": cacheControlHeader,
73
102
  "Content-Type": contentTypeMap?.[extension] ?? DEFAULT_CONTENT_TYPES[extension] ?? "application/octet-stream"
@@ -112,6 +141,7 @@ function normalizeExtension(value) {
112
141
  var DEFAULT_PREFIX = "/resources/js";
113
142
  var DEFAULT_VENDOR_PATH = "/vendor/inertia-client.tsx";
114
143
  var DEFAULT_JSX_RUNTIME = "https://esm.sh/react@19.0.0/jsx-dev-runtime?dev";
144
+ var REACT_IMPORT_PATTERN = /from\s+['"]react['"]/u;
115
145
  function resolveInertiaClientRoute(inertiaClientPath) {
116
146
  const base = inertiaClientPath.slice(0, inertiaClientPath.lastIndexOf("/") + 1) || "/";
117
147
  return {
@@ -124,6 +154,9 @@ var require2 = createRequire(import.meta.url);
124
154
  function resolveGurenInertiaClient() {
125
155
  return require2.resolve("@guren/inertia-client/app");
126
156
  }
157
+ function resolveInertiaClientDir() {
158
+ return join(dirname(require2.resolve("@guren/inertia-client/package.json")), "dist");
159
+ }
127
160
  function registerDevAssets(app, options) {
128
161
  if (typeof Bun === "undefined") {
129
162
  throw new Error("Bun runtime is required for dev asset serving.");
@@ -140,7 +173,6 @@ function registerDevAssets(app, options) {
140
173
  const inertiaClientSource = options.inertiaClientSource ?? resolveGurenInertiaClient();
141
174
  const jsxRuntimeUrl = options.jsxRuntimeUrl ?? DEFAULT_JSX_RUNTIME;
142
175
  const resourcesJsDir = resolve2(resourcesDir, "js");
143
- const reactImportPattern = /from\s+['"]react['"]/u;
144
176
  const transpilerOptions = {
145
177
  target: "browser",
146
178
  jsx: "transform",
@@ -150,9 +182,12 @@ function registerDevAssets(app, options) {
150
182
  "process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV ?? "development")
151
183
  }
152
184
  };
153
- const tsxTranspiler = new Bun.Transpiler({ loader: "tsx", ...transpilerOptions });
154
- const tsTranspiler = new Bun.Transpiler({ loader: "ts", ...transpilerOptions });
155
- app.hono.get(`${prefix}/*`, (ctx) => handleTranspileRequest(ctx, resourcesJsDir, prefix, reactImportPattern, tsxTranspiler, tsTranspiler, jsxRuntimeUrl));
185
+ const transpile = {
186
+ tsx: new Bun.Transpiler({ loader: "tsx", ...transpilerOptions }),
187
+ ts: new Bun.Transpiler({ loader: "ts", ...transpilerOptions }),
188
+ jsxRuntimeUrl
189
+ };
190
+ app.hono.get(`${prefix}/*`, (ctx) => handleTranspileRequest(ctx, resourcesJsDir, prefix, transpile));
156
191
  if (cssDir) {
157
192
  const cssRewrite = createStaticRewrite(cssRoute);
158
193
  app.use(
@@ -173,13 +208,13 @@ function registerDevAssets(app, options) {
173
208
  app.hono.get(inertiaClientPattern, (ctx) => {
174
209
  const relativeRequest = ctx.req.path.slice(inertiaClientBase.length) || inertiaClientRequestPath;
175
210
  if (relativeRequest === inertiaClientRequestPath) {
176
- return transpileFile(inertiaClientSource, reactImportPattern, tsxTranspiler, tsTranspiler, jsxRuntimeUrl);
211
+ return transpileFile(inertiaClientSource, transpile);
177
212
  }
178
213
  const candidatePath = resolve2(inertiaClientDir, relativeRequest);
179
- if (!candidatePath.startsWith(inertiaClientDir)) {
214
+ if (!isPathWithin(inertiaClientDir, candidatePath)) {
180
215
  return ctx.notFound();
181
216
  }
182
- return transpileFile(candidatePath, reactImportPattern, tsxTranspiler, tsTranspiler, jsxRuntimeUrl);
217
+ return transpileFile(candidatePath, transpile, inertiaClientDir);
183
218
  });
184
219
  }
185
220
  const publicPathOption = options.publicPath === void 0 ? "../public" : options.publicPath;
@@ -219,15 +254,15 @@ function createStaticRewrite(route) {
219
254
  return remainder.startsWith("/") ? remainder : `/${remainder}`;
220
255
  };
221
256
  }
222
- async function handleTranspileRequest(ctx, resourcesJsDir, prefix, reactImportPattern, tsxTranspiler, tsTranspiler, jsxRuntimeUrl) {
257
+ async function handleTranspileRequest(ctx, resourcesJsDir, prefix, transpile) {
223
258
  const relative = ctx.req.path.slice(prefix.length + 1);
224
259
  const fsPath = resolve2(resourcesJsDir, relative);
225
- if (!fsPath.startsWith(resourcesJsDir)) {
260
+ if (!isPathWithin(resourcesJsDir, fsPath)) {
226
261
  return ctx.notFound();
227
262
  }
228
- return transpileFile(fsPath, reactImportPattern, tsxTranspiler, tsTranspiler, jsxRuntimeUrl);
263
+ return transpileFile(fsPath, transpile, resourcesJsDir);
229
264
  }
230
- async function transpileFile(fsPath, reactImportPattern, tsxTranspiler, tsTranspiler, jsxRuntimeUrl) {
265
+ async function transpileFile(fsPath, transpile, containmentRoot) {
231
266
  const candidates = buildCandidatePaths(fsPath);
232
267
  let filePath;
233
268
  let file;
@@ -242,23 +277,23 @@ async function transpileFile(fsPath, reactImportPattern, tsxTranspiler, tsTransp
242
277
  if (!file || !filePath) {
243
278
  return new Response("Not Found", { status: 404 });
244
279
  }
280
+ if (containmentRoot && !await isRealPathWithin(containmentRoot, filePath)) {
281
+ return new Response("Not Found", { status: 404 });
282
+ }
245
283
  const ext = extname2(filePath);
246
284
  let source = await file.text();
247
- if (ext === ".tsx" && !reactImportPattern.test(source)) {
285
+ if (ext === ".tsx" && !REACT_IMPORT_PATTERN.test(source)) {
248
286
  source = "import React from 'react'\n" + source;
249
287
  }
250
288
  if (ext === ".tsx" || ext === ".ts") {
251
- const transpiled = ext === ".tsx" ? tsxTranspiler.transformSync(source, {
252
- loader: "tsx",
253
- sourceMap: isDev() ? "inline" : false,
254
- filename: filePath
255
- }) : tsTranspiler.transformSync(source, {
256
- loader: "ts",
289
+ const loader = ext === ".tsx" ? "tsx" : "ts";
290
+ const transpiled = transpile[loader].transformSync(source, {
291
+ loader,
257
292
  sourceMap: isDev() ? "inline" : false,
258
293
  filename: filePath
259
294
  });
260
295
  const helpers = collectJsxHelpers(transpiled);
261
- const runtimeShim = helpers.size ? createJsxRuntimeShim(helpers, jsxRuntimeUrl) : "";
296
+ const runtimeShim = helpers.size ? createJsxRuntimeShim(helpers, transpile.jsxRuntimeUrl) : "";
262
297
  return new Response(runtimeShim + transpiled, {
263
298
  headers: {
264
299
  "Content-Type": "application/javascript; charset=utf-8",
@@ -315,7 +350,7 @@ function deriveCssRoute(prefix) {
315
350
 
316
351
  // src/http/inertia-assets.ts
317
352
  import { serveStatic as serveStatic2 } from "hono/bun";
318
- import { dirname as dirname2, resolve as resolve3, join } from "path";
353
+ import { dirname as dirname2, resolve as resolve3, join as join2 } from "path";
319
354
  import { fileURLToPath as fileURLToPath2 } from "url";
320
355
  import { readFileSync } from "fs";
321
356
  var DEFAULT_STYLES_ENTRY = "/public/assets/app.css";
@@ -366,55 +401,53 @@ function configureInertiaAssets(app, options) {
366
401
  app.hono.get("/favicon.ico", () => new Response(null, { status: 204 }));
367
402
  }
368
403
  registerRootPublicAssets(app, publicDir, options.rootPublicAssets);
369
- if (isProduction && options.inertiaClient !== false) {
404
+ if (options.inertiaClient !== false) {
370
405
  try {
371
- let inertiaClientEntry;
372
- if (typeof import.meta.resolve === "function") {
373
- try {
374
- const resolved = import.meta.resolve("@guren/inertia-client/app", import.meta.url);
375
- inertiaClientEntry = fileURLToPath2(new URL(resolved));
376
- } catch {
377
- inertiaClientEntry = void 0;
378
- }
379
- }
380
- if (!inertiaClientEntry) {
381
- throw new Error("Unable to resolve @guren/inertia-client entry");
382
- }
383
- const inertiaClientDir = dirname2(inertiaClientEntry);
384
- const inertiaClientPath = options.inertiaClientPath ?? DEFAULT_VENDOR_CLIENT_PATH;
385
- const {
386
- base: inertiaClientBase,
387
- pattern: inertiaClientPattern,
388
- requestPath: inertiaClientRequestPath
389
- } = resolveInertiaClientRoute(inertiaClientPath);
390
- app.hono.get(inertiaClientPattern, async (ctx) => {
391
- const relativeRequest = ctx.req.path.slice(inertiaClientBase.length) || inertiaClientRequestPath;
392
- let targetPath;
393
- if (relativeRequest === inertiaClientRequestPath) {
394
- targetPath = join(inertiaClientDir, "app.js");
395
- } else {
396
- targetPath = resolve3(inertiaClientDir, relativeRequest);
397
- if (!targetPath.startsWith(inertiaClientDir)) {
398
- return ctx.notFound();
399
- }
400
- }
401
- const file = Bun.file(targetPath);
402
- if (!await file.exists()) {
403
- return ctx.notFound();
404
- }
405
- const contentType = file.type || "application/javascript; charset=utf-8";
406
- return new Response(file, {
407
- headers: {
408
- "Content-Type": contentType,
409
- "Cache-Control": "public, max-age=31536000"
410
- }
411
- });
412
- });
406
+ registerBuiltInertiaClient(
407
+ app,
408
+ resolveInertiaClientDir(),
409
+ options.inertiaClientPath ?? DEFAULT_VENDOR_CLIENT_PATH
410
+ );
413
411
  } catch (error) {
414
- console.warn("Unable to resolve @guren/inertia-client/app for production serving.", error);
412
+ console.warn("Unable to resolve @guren/inertia-client for production serving.", error);
415
413
  }
416
414
  }
417
415
  }
416
+ function registerBuiltInertiaClient(app, inertiaClientDir, inertiaClientPath) {
417
+ const {
418
+ base: inertiaClientBase,
419
+ pattern: inertiaClientPattern,
420
+ requestPath: inertiaClientRequestPath
421
+ } = resolveInertiaClientRoute(inertiaClientPath);
422
+ app.hono.get(inertiaClientPattern, async (ctx) => {
423
+ const relativeRequest = ctx.req.path.slice(inertiaClientBase.length) || inertiaClientRequestPath;
424
+ let targetPath;
425
+ let containmentRoot;
426
+ if (relativeRequest === inertiaClientRequestPath) {
427
+ targetPath = join2(inertiaClientDir, "app.js");
428
+ } else {
429
+ targetPath = resolve3(inertiaClientDir, relativeRequest);
430
+ containmentRoot = inertiaClientDir;
431
+ if (!isPathWithin(containmentRoot, targetPath)) {
432
+ return ctx.notFound();
433
+ }
434
+ }
435
+ const file = Bun.file(targetPath);
436
+ if (!await file.exists()) {
437
+ return ctx.notFound();
438
+ }
439
+ if (containmentRoot && !await isRealPathWithin(containmentRoot, targetPath)) {
440
+ return ctx.notFound();
441
+ }
442
+ const contentType = file.type || "application/javascript; charset=utf-8";
443
+ return new Response(file, {
444
+ headers: {
445
+ "Content-Type": contentType,
446
+ "Cache-Control": "public, max-age=31536000"
447
+ }
448
+ });
449
+ });
450
+ }
418
451
  function autoConfigureInertiaAssets(app, options) {
419
452
  const providedEnv = captureInertiaEnvFlags();
420
453
  configureInertiaAssets(app, options);
@@ -0,0 +1,37 @@
1
+ import type { ParsedCron } from './types.js';
2
+ /**
3
+ * Parse a cron expression.
4
+ *
5
+ * Cron format: minute hour dayOfMonth month dayOfWeek
6
+ *
7
+ * Examples:
8
+ * - Every minute: "* * * * *"
9
+ * - Every 5 minutes: "*​/5 * * * *" (step value)
10
+ * - At 3:00 AM daily: "0 3 * * *"
11
+ * - Every Monday at 9:00 AM: "0 9 * * 1"
12
+ */
13
+ export declare function parseCron(expression: string): ParsedCron;
14
+ /**
15
+ * Check if a date matches a parsed cron expression.
16
+ */
17
+ export declare function matchesCron(date: Date, cron: ParsedCron): boolean;
18
+ /**
19
+ * Get the next occurrence of a cron expression.
20
+ */
21
+ export declare function getNextOccurrence(expression: string, from?: Date): Date;
22
+ /**
23
+ * Check if a cron expression is due at the given date.
24
+ */
25
+ export declare function isDue(expression: string, date?: Date): boolean;
26
+ /**
27
+ * Get multiple next occurrences.
28
+ */
29
+ export declare function getNextOccurrences(expression: string, count: number, from?: Date): Date[];
30
+ /**
31
+ * Convert a Date to a specific timezone.
32
+ */
33
+ export declare function toTimezone(date: Date, timezone: string): Date;
34
+ /**
35
+ * Check if a cron expression is due in a specific timezone.
36
+ */
37
+ export declare function isDueInTimezone(expression: string, timezone: string, date?: Date): boolean;
@@ -0,0 +1,229 @@
1
+ import type { TaskCallback, TaskDefinition, JobClass } from './types.js';
2
+ import { ScheduledTask } from './ScheduledTask.js';
3
+ /**
4
+ * Pending schedule builder for fluent API.
5
+ */
6
+ export declare class PendingSchedule {
7
+ private readonly callback;
8
+ private expression;
9
+ private timezone?;
10
+ private taskName?;
11
+ private withoutOverlapping;
12
+ private overlapExpiresAt?;
13
+ private onOneServer;
14
+ private whenCallback?;
15
+ private skipCallback?;
16
+ private beforeCallback?;
17
+ private afterCallback?;
18
+ private successCallback?;
19
+ private failureCallback?;
20
+ constructor(callback: TaskCallback);
21
+ /**
22
+ * Run every minute.
23
+ */
24
+ everyMinute(): this;
25
+ /**
26
+ * Run every two minutes.
27
+ */
28
+ everyTwoMinutes(): this;
29
+ /**
30
+ * Run every three minutes.
31
+ */
32
+ everyThreeMinutes(): this;
33
+ /**
34
+ * Run every four minutes.
35
+ */
36
+ everyFourMinutes(): this;
37
+ /**
38
+ * Run every five minutes.
39
+ */
40
+ everyFiveMinutes(): this;
41
+ /**
42
+ * Run every ten minutes.
43
+ */
44
+ everyTenMinutes(): this;
45
+ /**
46
+ * Run every fifteen minutes.
47
+ */
48
+ everyFifteenMinutes(): this;
49
+ /**
50
+ * Run every thirty minutes.
51
+ */
52
+ everyThirtyMinutes(): this;
53
+ /**
54
+ * Run hourly.
55
+ */
56
+ hourly(): this;
57
+ /**
58
+ * Run hourly at a specific minute.
59
+ */
60
+ hourlyAt(minute: number): this;
61
+ /**
62
+ * Run every two hours.
63
+ */
64
+ everyTwoHours(): this;
65
+ /**
66
+ * Run every three hours.
67
+ */
68
+ everyThreeHours(): this;
69
+ /**
70
+ * Run every four hours.
71
+ */
72
+ everyFourHours(): this;
73
+ /**
74
+ * Run every six hours.
75
+ */
76
+ everySixHours(): this;
77
+ /**
78
+ * Run daily at midnight.
79
+ */
80
+ daily(): this;
81
+ /**
82
+ * Run daily at a specific time.
83
+ * @param time Time in HH:MM format
84
+ */
85
+ dailyAt(time: string): this;
86
+ /**
87
+ * Alias for dailyAt.
88
+ */
89
+ at(time: string): this;
90
+ /**
91
+ * Run twice daily.
92
+ */
93
+ twiceDaily(firstHour?: number, secondHour?: number): this;
94
+ /**
95
+ * Run weekly on Sunday at midnight.
96
+ */
97
+ weekly(): this;
98
+ /**
99
+ * Run weekly on a specific day at a specific time.
100
+ * @param day Day of week (0 = Sunday, 6 = Saturday)
101
+ * @param time Time in HH:MM format
102
+ */
103
+ weeklyOn(day: number, time?: string): this;
104
+ sundays(): this;
105
+ mondays(): this;
106
+ tuesdays(): this;
107
+ wednesdays(): this;
108
+ thursdays(): this;
109
+ fridays(): this;
110
+ saturdays(): this;
111
+ /**
112
+ * Run on weekdays (Monday-Friday).
113
+ */
114
+ weekdays(): this;
115
+ /**
116
+ * Run on weekends (Saturday-Sunday).
117
+ */
118
+ weekends(): this;
119
+ /**
120
+ * Run monthly on the first day at midnight.
121
+ */
122
+ monthly(): this;
123
+ /**
124
+ * Run monthly on a specific day at a specific time.
125
+ */
126
+ monthlyOn(day: number, time?: string): this;
127
+ /**
128
+ * Run on the last day of the month.
129
+ */
130
+ lastDayOfMonth(time?: string): this;
131
+ /**
132
+ * Run quarterly.
133
+ */
134
+ quarterly(): this;
135
+ /**
136
+ * Run yearly on January 1st at midnight.
137
+ */
138
+ yearly(): this;
139
+ /**
140
+ * Run yearly on a specific date.
141
+ */
142
+ yearlyOn(month: number, day: number, time?: string): this;
143
+ /**
144
+ * Set a custom cron expression.
145
+ */
146
+ cron(expression: string): this;
147
+ /**
148
+ * Set the task name.
149
+ */
150
+ name(name: string): this;
151
+ /**
152
+ * Set the timezone.
153
+ */
154
+ tz(timezone: string): this;
155
+ /**
156
+ * Alias for tz().
157
+ */
158
+ setTimezone(timezone: string): this;
159
+ /**
160
+ * Prevent overlapping executions.
161
+ */
162
+ preventOverlapping(expiresAt?: number): this;
163
+ /**
164
+ * Alias for preventOverlapping().
165
+ */
166
+ withoutOverlaps(expiresAt?: number): this;
167
+ /**
168
+ * Only run on one server.
169
+ */
170
+ runOnOneServer(): this;
171
+ /**
172
+ * Set a condition for running.
173
+ */
174
+ when(callback: () => boolean | Promise<boolean>): this;
175
+ /**
176
+ * Set a condition to skip execution.
177
+ */
178
+ skip(callback: () => boolean | Promise<boolean>): this;
179
+ /**
180
+ * Set a before callback.
181
+ */
182
+ before(callback: () => void | Promise<void>): this;
183
+ /**
184
+ * Set an after callback.
185
+ */
186
+ after(callback: () => void | Promise<void>): this;
187
+ /**
188
+ * Set a success callback.
189
+ */
190
+ onSuccess(callback: () => void | Promise<void>): this;
191
+ /**
192
+ * Set a failure callback.
193
+ */
194
+ onFailure(callback: (error: Error) => void | Promise<void>): this;
195
+ /**
196
+ * Build the task definition.
197
+ */
198
+ build(): TaskDefinition;
199
+ /**
200
+ * Build as a ScheduledTask.
201
+ */
202
+ toTask(): ScheduledTask;
203
+ }
204
+ /**
205
+ * Schedule builder for defining multiple tasks.
206
+ */
207
+ export declare class Schedule {
208
+ private readonly tasks;
209
+ /**
210
+ * Schedule a callback.
211
+ */
212
+ call(callback: TaskCallback): PendingSchedule;
213
+ /**
214
+ * Schedule a job.
215
+ */
216
+ job<T>(jobClass: JobClass<T>, payload: T): PendingSchedule;
217
+ /**
218
+ * Schedule a shell command.
219
+ */
220
+ command(cmd: string): PendingSchedule;
221
+ /**
222
+ * Get all pending schedules.
223
+ */
224
+ getPendingSchedules(): PendingSchedule[];
225
+ /**
226
+ * Build all tasks.
227
+ */
228
+ buildTasks(): ScheduledTask[];
229
+ }
@@ -0,0 +1,47 @@
1
+ import type { TaskDefinition } from './types.js';
2
+ /**
3
+ * Represents a scheduled task.
4
+ */
5
+ export declare class ScheduledTask {
6
+ private readonly definition;
7
+ private lastRun;
8
+ private isRunning;
9
+ constructor(definition: TaskDefinition);
10
+ /**
11
+ * Get the task name.
12
+ */
13
+ getName(): string;
14
+ /**
15
+ * Get the cron expression.
16
+ */
17
+ getExpression(): string;
18
+ /**
19
+ * Get the timezone.
20
+ */
21
+ getTimezone(): string | undefined;
22
+ /**
23
+ * Check if the task is due.
24
+ */
25
+ isDue(date?: Date): boolean;
26
+ /**
27
+ * Check if the task should run based on conditions.
28
+ * Note: Overlap checking is handled separately in run() to prevent race conditions.
29
+ */
30
+ shouldRun(): Promise<boolean>;
31
+ /**
32
+ * Run the task.
33
+ */
34
+ run(): Promise<void>;
35
+ /**
36
+ * Get the last run time.
37
+ */
38
+ getLastRun(): Date | null;
39
+ /**
40
+ * Check if the task is currently running.
41
+ */
42
+ isCurrentlyRunning(): boolean;
43
+ /**
44
+ * Get the task definition.
45
+ */
46
+ getDefinition(): TaskDefinition;
47
+ }
@@ -0,0 +1,99 @@
1
+ import type { SchedulerOptions } from './types.js';
2
+ import { Schedule } from './Schedule.js';
3
+ import { ScheduledTask } from './ScheduledTask.js';
4
+ /**
5
+ * Task scheduler for running periodic tasks.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * const scheduler = new Scheduler()
10
+ *
11
+ * scheduler.schedule((schedule) => {
12
+ * schedule.call(async () => {
13
+ * await cleanupOldSessions()
14
+ * }).daily().at('03:00').name('cleanup-sessions')
15
+ *
16
+ * schedule.job(SendWeeklyDigestJob, {})
17
+ * .weekly()
18
+ * .sundays()
19
+ * .at('09:00')
20
+ * .tz('Asia/Tokyo')
21
+ * })
22
+ *
23
+ * scheduler.start()
24
+ * ```
25
+ */
26
+ export declare class Scheduler {
27
+ private tasks;
28
+ private readonly options;
29
+ private interval;
30
+ private isRunning;
31
+ private lastCheck;
32
+ /** This scheduler's claim on its hot-reload slot while it is running. */
33
+ private hotReloadClaim;
34
+ constructor(options?: SchedulerOptions);
35
+ /**
36
+ * Define schedules using a callback.
37
+ */
38
+ schedule(definer: (schedule: Schedule) => void): void;
39
+ /**
40
+ * Add a pre-built task.
41
+ */
42
+ addTask(task: ScheduledTask): void;
43
+ /**
44
+ * Get all scheduled tasks.
45
+ */
46
+ getTasks(): ScheduledTask[];
47
+ /**
48
+ * Get tasks that are due now.
49
+ */
50
+ getDueTasks(date?: Date): ScheduledTask[];
51
+ /**
52
+ * Run all due tasks.
53
+ */
54
+ runDueTasks(date?: Date): Promise<void>;
55
+ /**
56
+ * Start the scheduler.
57
+ */
58
+ start(): void;
59
+ /**
60
+ * Stop the scheduler.
61
+ */
62
+ stop(): void;
63
+ /**
64
+ * Check and run due tasks.
65
+ */
66
+ private tick;
67
+ /**
68
+ * Check if the scheduler is running.
69
+ */
70
+ getIsRunning(): boolean;
71
+ /**
72
+ * Get the check interval.
73
+ */
74
+ getCheckInterval(): number;
75
+ /**
76
+ * Get the default timezone.
77
+ */
78
+ getTimezone(): string;
79
+ /**
80
+ * Clear all tasks.
81
+ */
82
+ clear(): void;
83
+ /**
84
+ * Get the number of tasks.
85
+ */
86
+ count(): number;
87
+ /**
88
+ * Get task by name.
89
+ */
90
+ getTask(name: string): ScheduledTask | undefined;
91
+ /**
92
+ * Remove a task by name.
93
+ */
94
+ removeTask(name: string): boolean;
95
+ }
96
+ /**
97
+ * Create a scheduler instance.
98
+ */
99
+ export declare function createScheduler(options?: SchedulerOptions): Scheduler;