@guren/server 0.2.0-alpha.7 → 1.0.0-rc.9

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 (54) hide show
  1. package/dist/Application-DtWDHXr1.d.ts +2110 -0
  2. package/dist/BroadcastManager-AkIWUGJo.d.ts +466 -0
  3. package/dist/CacheManager-BkvHEOZX.d.ts +244 -0
  4. package/dist/ConsoleKernel-CqCVrdZs.d.ts +207 -0
  5. package/dist/EventManager-CmIoLt7r.d.ts +207 -0
  6. package/dist/Gate-CNkBYf8m.d.ts +268 -0
  7. package/dist/HealthManager-DUyMIzsZ.d.ts +141 -0
  8. package/dist/I18nManager-Dtgzsf5n.d.ts +270 -0
  9. package/dist/LogManager-7mxnkaPM.d.ts +256 -0
  10. package/dist/MailManager-DpMvYiP9.d.ts +292 -0
  11. package/dist/Scheduler-BstvSca7.d.ts +469 -0
  12. package/dist/StorageManager-oZTHqaza.d.ts +337 -0
  13. package/dist/api-token-JOif2CtG.d.ts +1792 -0
  14. package/dist/app-key-CsBfRC_Q.d.ts +214 -0
  15. package/dist/auth/index.d.ts +418 -0
  16. package/dist/auth/index.js +6742 -0
  17. package/dist/authorization/index.d.ts +129 -0
  18. package/dist/authorization/index.js +621 -0
  19. package/dist/broadcasting/index.d.ts +233 -0
  20. package/dist/broadcasting/index.js +907 -0
  21. package/dist/cache/index.d.ts +233 -0
  22. package/dist/cache/index.js +817 -0
  23. package/dist/encryption/index.d.ts +222 -0
  24. package/dist/encryption/index.js +602 -0
  25. package/dist/events/index.d.ts +155 -0
  26. package/dist/events/index.js +330 -0
  27. package/dist/health/index.d.ts +185 -0
  28. package/dist/health/index.js +379 -0
  29. package/dist/i18n/index.d.ts +101 -0
  30. package/dist/i18n/index.js +597 -0
  31. package/dist/index-9_Jzj5jo.d.ts +7 -0
  32. package/dist/index.d.ts +2628 -619
  33. package/dist/index.js +22229 -3116
  34. package/dist/lambda/index.d.ts +156 -0
  35. package/dist/lambda/index.js +91 -0
  36. package/dist/logging/index.d.ts +50 -0
  37. package/dist/logging/index.js +557 -0
  38. package/dist/mail/index.d.ts +288 -0
  39. package/dist/mail/index.js +695 -0
  40. package/dist/mcp/index.d.ts +139 -0
  41. package/dist/mcp/index.js +382 -0
  42. package/dist/notifications/index.d.ts +271 -0
  43. package/dist/notifications/index.js +741 -0
  44. package/dist/queue/index.d.ts +423 -0
  45. package/dist/queue/index.js +958 -0
  46. package/dist/runtime/index.d.ts +93 -0
  47. package/dist/runtime/index.js +834 -0
  48. package/dist/scheduling/index.d.ts +41 -0
  49. package/dist/scheduling/index.js +836 -0
  50. package/dist/storage/index.d.ts +196 -0
  51. package/dist/storage/index.js +832 -0
  52. package/dist/vite/index.js +203 -3
  53. package/package.json +93 -6
  54. package/dist/chunk-FK2XQSBF.js +0 -160
@@ -0,0 +1,834 @@
1
+ // src/http/dev-assets.ts
2
+ import { serveStatic } from "hono/bun";
3
+ import { dirname, extname as extname2, resolve as resolve2 } from "path";
4
+ import { fileURLToPath } from "url";
5
+ import { createRequire } from "module";
6
+
7
+ // src/http/public-assets.ts
8
+ import { extname, resolve, sep } from "path";
9
+ var DEFAULT_CACHE_CONTROL = "public, max-age=31536000, immutable";
10
+ var DEFAULT_EXTENSIONS = [".svg", ".png", ".jpg", ".jpeg", ".gif", ".ico", ".webp", ".avif", ".webmanifest", ".txt"];
11
+ var DEFAULT_CONTENT_TYPES = {
12
+ ".svg": "image/svg+xml",
13
+ ".png": "image/png",
14
+ ".jpg": "image/jpeg",
15
+ ".jpeg": "image/jpeg",
16
+ ".gif": "image/gif",
17
+ ".ico": "image/x-icon",
18
+ ".webp": "image/webp",
19
+ ".avif": "image/avif",
20
+ ".webmanifest": "application/manifest+json",
21
+ ".txt": "text/plain; charset=utf-8"
22
+ };
23
+ function registerRootPublicAssets(app, publicDir, config) {
24
+ const normalized = normalizeConfig(config);
25
+ if (!normalized) {
26
+ return;
27
+ }
28
+ if (typeof Bun === "undefined") {
29
+ console.warn("Root public asset serving is only available when running on Bun; skipping registration.");
30
+ return;
31
+ }
32
+ const { extensions, cacheControlHeader, routePrefix, contentTypeMap } = normalized;
33
+ const normalizedPrefix = routePrefix ? routePrefix.replace(/\/+$/u, "") || "/" : void 0;
34
+ app.hono.use(async (ctx, next) => {
35
+ const path = ctx.req.path;
36
+ if (!path || path === "/" || path.startsWith("/public/")) {
37
+ return next();
38
+ }
39
+ if (normalizedPrefix && !path.startsWith(normalizedPrefix)) {
40
+ return next();
41
+ }
42
+ const extension = extname(path).toLowerCase();
43
+ if (!extensions.has(extension)) {
44
+ return next();
45
+ }
46
+ const relativePath = path.replace(/^\/+/, "");
47
+ if (!relativePath) {
48
+ return next();
49
+ }
50
+ const candidatePath = resolve(publicDir, relativePath);
51
+ if (!candidatePath.startsWith(publicDir + sep) && candidatePath !== publicDir) {
52
+ return next();
53
+ }
54
+ const file = Bun.file(candidatePath);
55
+ if (!await file.exists()) {
56
+ return next();
57
+ }
58
+ const headers = new Headers({
59
+ "Cache-Control": cacheControlHeader,
60
+ "Content-Type": contentTypeMap?.[extension] ?? DEFAULT_CONTENT_TYPES[extension] ?? "application/octet-stream"
61
+ });
62
+ return new Response(file, { headers });
63
+ });
64
+ }
65
+ function normalizeConfig(config) {
66
+ if (config === false) {
67
+ return void 0;
68
+ }
69
+ if (config === void 0 || config === true) {
70
+ return {
71
+ extensions: new Set(DEFAULT_EXTENSIONS),
72
+ cacheControlHeader: DEFAULT_CACHE_CONTROL
73
+ };
74
+ }
75
+ const enabled = config.enabled ?? true;
76
+ if (!enabled) {
77
+ return void 0;
78
+ }
79
+ const extensions = new Set(
80
+ (config.extensions && config.extensions.length > 0 ? config.extensions : DEFAULT_EXTENSIONS).map(
81
+ (ext) => normalizeExtension(ext)
82
+ )
83
+ );
84
+ return {
85
+ extensions,
86
+ cacheControlHeader: config.cacheControlHeader ?? DEFAULT_CACHE_CONTROL,
87
+ routePrefix: config.routePrefix,
88
+ contentTypeMap: config.contentTypeMap
89
+ };
90
+ }
91
+ function normalizeExtension(value) {
92
+ if (!value) {
93
+ return value;
94
+ }
95
+ return value.startsWith(".") ? value.toLowerCase() : `.${value.toLowerCase()}`;
96
+ }
97
+
98
+ // src/http/dev-assets.ts
99
+ var DEFAULT_PREFIX = "/resources/js";
100
+ var DEFAULT_VENDOR_PATH = "/vendor/inertia-client.tsx";
101
+ var DEFAULT_JSX_RUNTIME = "https://esm.sh/react@19.0.0/jsx-dev-runtime?dev";
102
+ var require2 = createRequire(import.meta.url);
103
+ var gurenInertiaClient = require2.resolve("@guren/inertia-client/app");
104
+ function registerDevAssets(app, options) {
105
+ if (typeof Bun === "undefined") {
106
+ throw new Error("Bun runtime is required for dev asset serving.");
107
+ }
108
+ const moduleDir = options.importMeta ? dirname(fileURLToPath(options.importMeta.url)) : void 0;
109
+ const resourcesDir = options.resourcesDir ?? (moduleDir ? resolve2(moduleDir, options.resourcesPath ?? "../resources") : void 0);
110
+ if (!resourcesDir) {
111
+ throw new Error("registerDevAssets requires either `resourcesDir` or `importMeta`.");
112
+ }
113
+ const prefix = options.prefix ?? DEFAULT_PREFIX;
114
+ const cssDir = options.cssDir ?? resolve2(resourcesDir, "css");
115
+ const cssRoute = options.cssRoute ?? deriveCssRoute(prefix);
116
+ const inertiaClientPath = options.inertiaClientPath ?? DEFAULT_VENDOR_PATH;
117
+ const inertiaClientSource = options.inertiaClientSource ?? gurenInertiaClient;
118
+ const jsxRuntimeUrl = options.jsxRuntimeUrl ?? DEFAULT_JSX_RUNTIME;
119
+ const resourcesJsDir = resolve2(resourcesDir, "js");
120
+ const reactImportPattern = /from\s+['"]react['"]/u;
121
+ const transpilerOptions = {
122
+ target: "browser",
123
+ jsx: "transform",
124
+ jsxFactory: "React.createElement",
125
+ jsxFragment: "React.Fragment",
126
+ define: {
127
+ "process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV ?? "development")
128
+ }
129
+ };
130
+ const tsxTranspiler = new Bun.Transpiler({ loader: "tsx", ...transpilerOptions });
131
+ const tsTranspiler = new Bun.Transpiler({ loader: "ts", ...transpilerOptions });
132
+ app.hono.get(`${prefix}/*`, (ctx) => handleTranspileRequest(ctx, resourcesJsDir, prefix, reactImportPattern, tsxTranspiler, tsTranspiler, jsxRuntimeUrl));
133
+ if (cssDir) {
134
+ const cssRewrite = createStaticRewrite(cssRoute);
135
+ app.use(
136
+ cssRoute,
137
+ serveStatic({
138
+ root: cssDir,
139
+ rewriteRequestPath: cssRewrite
140
+ })
141
+ );
142
+ }
143
+ if (options.inertiaClient !== false) {
144
+ const inertiaClientDir = dirname(inertiaClientSource);
145
+ const inertiaClientBase = inertiaClientPath.replace(/[^/]*$/u, "") || "/";
146
+ const inertiaClientPattern = `${inertiaClientBase.endsWith("/") ? inertiaClientBase : `${inertiaClientBase}/`}*`;
147
+ const inertiaClientRequestPath = inertiaClientPath.slice(inertiaClientBase.length);
148
+ app.hono.get(inertiaClientPattern, (ctx) => {
149
+ const relativeRequest = ctx.req.path.slice(inertiaClientBase.length) || inertiaClientRequestPath;
150
+ if (relativeRequest === inertiaClientRequestPath) {
151
+ return transpileFile(inertiaClientSource, reactImportPattern, tsxTranspiler, tsTranspiler, jsxRuntimeUrl);
152
+ }
153
+ const candidatePath = resolve2(inertiaClientDir, relativeRequest);
154
+ if (!candidatePath.startsWith(inertiaClientDir)) {
155
+ return ctx.notFound();
156
+ }
157
+ return transpileFile(candidatePath, reactImportPattern, tsxTranspiler, tsTranspiler, jsxRuntimeUrl);
158
+ });
159
+ }
160
+ const publicPathOption = options.publicPath === void 0 ? "../public" : options.publicPath;
161
+ const publicDir = options.publicDir ?? (moduleDir && publicPathOption ? resolve2(moduleDir, publicPathOption) : void 0);
162
+ const shouldServePublic = publicDir && publicPathOption !== false;
163
+ if (shouldServePublic) {
164
+ const publicRoute = options.publicRoute ?? "/public/*";
165
+ const rewriteRequestPath = createStaticRewrite(publicRoute);
166
+ app.use(
167
+ publicRoute,
168
+ serveStatic({
169
+ root: publicDir,
170
+ rewriteRequestPath
171
+ })
172
+ );
173
+ if (options.favicon !== false) {
174
+ app.hono.get("/favicon.ico", () => new Response(null, { status: 204 }));
175
+ }
176
+ registerRootPublicAssets(app, publicDir, options.rootPublicAssets);
177
+ }
178
+ }
179
+ function createStaticRewrite(route) {
180
+ const wildcardIndex = route.indexOf("*");
181
+ const base = wildcardIndex >= 0 ? route.slice(0, wildcardIndex) : route;
182
+ const normalizedBase = base.endsWith("/") ? base.slice(0, -1) : base;
183
+ if (!normalizedBase) {
184
+ return (path) => path || "/";
185
+ }
186
+ return (path) => {
187
+ if (!path.startsWith(normalizedBase)) {
188
+ return path || "/";
189
+ }
190
+ const remainder = path.slice(normalizedBase.length);
191
+ if (!remainder) {
192
+ return "/";
193
+ }
194
+ return remainder.startsWith("/") ? remainder : `/${remainder}`;
195
+ };
196
+ }
197
+ async function handleTranspileRequest(ctx, resourcesJsDir, prefix, reactImportPattern, tsxTranspiler, tsTranspiler, jsxRuntimeUrl) {
198
+ const relative = ctx.req.path.slice(prefix.length + 1);
199
+ const fsPath = resolve2(resourcesJsDir, relative);
200
+ if (!fsPath.startsWith(resourcesJsDir)) {
201
+ return ctx.notFound();
202
+ }
203
+ return transpileFile(fsPath, reactImportPattern, tsxTranspiler, tsTranspiler, jsxRuntimeUrl);
204
+ }
205
+ async function transpileFile(fsPath, reactImportPattern, tsxTranspiler, tsTranspiler, jsxRuntimeUrl) {
206
+ const candidates = buildCandidatePaths(fsPath);
207
+ let filePath;
208
+ let file;
209
+ for (const candidate of candidates) {
210
+ const bunFile = Bun.file(candidate);
211
+ if (await bunFile.exists()) {
212
+ filePath = candidate;
213
+ file = bunFile;
214
+ break;
215
+ }
216
+ }
217
+ if (!file || !filePath) {
218
+ return new Response("Not Found", { status: 404 });
219
+ }
220
+ const ext = extname2(filePath);
221
+ let source = await file.text();
222
+ if (ext === ".tsx" && !reactImportPattern.test(source)) {
223
+ source = "import React from 'react'\n" + source;
224
+ }
225
+ if (ext === ".tsx" || ext === ".ts") {
226
+ const transpiled = ext === ".tsx" ? tsxTranspiler.transformSync(source, {
227
+ loader: "tsx",
228
+ sourceMap: isDev() ? "inline" : false,
229
+ filename: filePath
230
+ }) : tsTranspiler.transformSync(source, {
231
+ loader: "ts",
232
+ sourceMap: isDev() ? "inline" : false,
233
+ filename: filePath
234
+ });
235
+ const helpers = collectJsxHelpers(transpiled);
236
+ const runtimeShim = helpers.size ? createJsxRuntimeShim(helpers, jsxRuntimeUrl) : "";
237
+ return new Response(runtimeShim + transpiled, {
238
+ headers: {
239
+ "Content-Type": "application/javascript; charset=utf-8",
240
+ "Cache-Control": isDev() ? "no-cache" : "public, max-age=31536000"
241
+ }
242
+ });
243
+ }
244
+ const body = await file.arrayBuffer();
245
+ return new Response(body, {
246
+ headers: {
247
+ "Content-Type": file.type || "application/octet-stream",
248
+ "Cache-Control": isDev() ? "no-cache" : "public, max-age=31536000"
249
+ }
250
+ });
251
+ }
252
+ function buildCandidatePaths(fsPath) {
253
+ const ext = extname2(fsPath);
254
+ if (ext) {
255
+ return [fsPath];
256
+ }
257
+ return [
258
+ `${fsPath}.tsx`,
259
+ `${fsPath}.ts`,
260
+ `${fsPath}.jsx`,
261
+ `${fsPath}.js`
262
+ ];
263
+ }
264
+ function collectJsxHelpers(code) {
265
+ const helpers = /* @__PURE__ */ new Set();
266
+ const pattern = /(jsxDEV|jsx|jsxs|Fragment)_[0-9a-z]+/gu;
267
+ for (const match of code.matchAll(pattern)) {
268
+ helpers.add(match[0]);
269
+ }
270
+ return helpers;
271
+ }
272
+ function createJsxRuntimeShim(helpers, runtimeUrl) {
273
+ const assignments = Array.from(helpers).map((helper) => {
274
+ const base = helper.split("_")[0];
275
+ return `const ${helper} = __jsxRuntime.${base};`;
276
+ });
277
+ return `import * as __jsxRuntime from "${runtimeUrl}";
278
+ ${assignments.join("\n")}
279
+ `;
280
+ }
281
+ function isDev() {
282
+ return (process.env.NODE_ENV ?? "development") !== "production";
283
+ }
284
+ function deriveCssRoute(prefix) {
285
+ const base = prefix.endsWith("/js") ? prefix.slice(0, -3) : prefix;
286
+ const normalizedBase = base.endsWith("/") ? base.slice(0, -1) : base;
287
+ const resolvedBase = normalizedBase.startsWith("/") ? normalizedBase : `/${normalizedBase}`;
288
+ return `${resolvedBase}/css/*`;
289
+ }
290
+
291
+ // src/http/inertia-assets.ts
292
+ import { serveStatic as serveStatic2 } from "hono/bun";
293
+ import { dirname as dirname2, resolve as resolve3, join } from "path";
294
+ import { fileURLToPath as fileURLToPath2 } from "url";
295
+ import { readFileSync } from "fs";
296
+
297
+ // src/support/import-map.ts
298
+ function parseImportMap(value, options = {}) {
299
+ if (!value) {
300
+ return {};
301
+ }
302
+ try {
303
+ const parsed = JSON.parse(value);
304
+ const result = {};
305
+ for (const [key, entry] of Object.entries(parsed)) {
306
+ if (typeof entry === "string" && entry.length > 0) {
307
+ result[key] = entry;
308
+ }
309
+ }
310
+ return result;
311
+ } catch (error) {
312
+ const label = options.context ?? "import map";
313
+ console.warn(`Failed to parse ${label}. Expected JSON object.`, error);
314
+ return {};
315
+ }
316
+ }
317
+
318
+ // src/http/inertia-assets.ts
319
+ var DEFAULT_STYLES_ENTRY = "/public/assets/app.css";
320
+ var DEFAULT_DEV_STYLES_ENTRY = "/resources/css/app.css";
321
+ var DEFAULT_SCRIPT_ENTRY = "/assets/app.js";
322
+ var DEFAULT_VENDOR_CLIENT_PATH = "/vendor/inertia-client.tsx";
323
+ function configureInertiaAssets(app, options) {
324
+ const stylesEntry = options.stylesEntry ?? DEFAULT_STYLES_ENTRY;
325
+ process.env.GUREN_INERTIA_STYLES = process.env.GUREN_INERTIA_STYLES ?? stylesEntry;
326
+ const providedSsrEntry = options.ssrEntry;
327
+ const providedSsrManifest = options.ssrManifest;
328
+ const isProduction = process.env.NODE_ENV === "production";
329
+ if (!isProduction) {
330
+ const devSsrEntry = resolveDevSsrEntry(options);
331
+ if (!process.env.GUREN_INERTIA_SSR_ENTRY && devSsrEntry) {
332
+ process.env.GUREN_INERTIA_SSR_ENTRY = devSsrEntry;
333
+ }
334
+ if (!process.env.GUREN_INERTIA_SSR_MANIFEST) {
335
+ process.env.GUREN_INERTIA_SSR_MANIFEST = providedSsrManifest ?? "";
336
+ }
337
+ registerDevAssets(app, options);
338
+ return;
339
+ }
340
+ const scriptEntry = options.scriptEntry ?? DEFAULT_SCRIPT_ENTRY;
341
+ process.env.GUREN_INERTIA_ENTRY = process.env.GUREN_INERTIA_ENTRY ?? scriptEntry;
342
+ if (!process.env.GUREN_INERTIA_SSR_ENTRY && providedSsrEntry) {
343
+ process.env.GUREN_INERTIA_SSR_ENTRY = providedSsrEntry;
344
+ }
345
+ if (!process.env.GUREN_INERTIA_SSR_MANIFEST && providedSsrManifest) {
346
+ process.env.GUREN_INERTIA_SSR_MANIFEST = providedSsrManifest;
347
+ }
348
+ const moduleDir = options.importMeta ? dirname2(fileURLToPath2(options.importMeta.url)) : void 0;
349
+ const publicPathOption = options.publicPath === void 0 ? "../public" : options.publicPath;
350
+ const publicDir = options.publicDir ?? (moduleDir && publicPathOption ? resolve3(moduleDir, publicPathOption) : void 0);
351
+ if (!publicDir || publicPathOption === false) {
352
+ return;
353
+ }
354
+ const publicRoute = options.publicRoute ?? "/public/*";
355
+ const rewriteRequestPath = createStaticRewrite(publicRoute);
356
+ app.use(
357
+ publicRoute,
358
+ serveStatic2({
359
+ root: publicDir,
360
+ rewriteRequestPath
361
+ })
362
+ );
363
+ if (options.favicon !== false) {
364
+ app.hono.get("/favicon.ico", () => new Response(null, { status: 204 }));
365
+ }
366
+ registerRootPublicAssets(app, publicDir, options.rootPublicAssets);
367
+ if (isProduction && options.inertiaClient !== false) {
368
+ try {
369
+ let inertiaClientEntry;
370
+ if (typeof import.meta.resolve === "function") {
371
+ try {
372
+ const resolved = import.meta.resolve("@guren/inertia-client/app", import.meta.url);
373
+ inertiaClientEntry = fileURLToPath2(new URL(resolved));
374
+ } catch {
375
+ inertiaClientEntry = void 0;
376
+ }
377
+ }
378
+ if (!inertiaClientEntry) {
379
+ throw new Error("Unable to resolve @guren/inertia-client entry");
380
+ }
381
+ const inertiaClientDir = dirname2(inertiaClientEntry);
382
+ const inertiaClientPath = options.inertiaClientPath ?? DEFAULT_VENDOR_CLIENT_PATH;
383
+ const inertiaClientBase = inertiaClientPath.replace(/[^/]*$/u, "") || "/";
384
+ const inertiaClientPattern = `${inertiaClientBase.endsWith("/") ? inertiaClientBase : `${inertiaClientBase}/`}*`;
385
+ const inertiaClientRequestPath = inertiaClientPath.slice(inertiaClientBase.length);
386
+ app.hono.get(inertiaClientPattern, async (ctx) => {
387
+ const relativeRequest = ctx.req.path.slice(inertiaClientBase.length) || inertiaClientRequestPath;
388
+ let targetPath;
389
+ if (relativeRequest === inertiaClientRequestPath) {
390
+ targetPath = join(inertiaClientDir, "app.js");
391
+ } else {
392
+ targetPath = resolve3(inertiaClientDir, relativeRequest);
393
+ if (!targetPath.startsWith(inertiaClientDir)) {
394
+ return ctx.notFound();
395
+ }
396
+ }
397
+ const file = Bun.file(targetPath);
398
+ if (!await file.exists()) {
399
+ return ctx.notFound();
400
+ }
401
+ const contentType = file.type || "application/javascript; charset=utf-8";
402
+ return new Response(file, {
403
+ headers: {
404
+ "Content-Type": contentType,
405
+ "Cache-Control": "public, max-age=31536000"
406
+ }
407
+ });
408
+ });
409
+ } catch (error) {
410
+ console.warn("Unable to resolve @guren/inertia-client/app for production serving.", error);
411
+ }
412
+ }
413
+ }
414
+ function autoConfigureInertiaAssets(app, options) {
415
+ const providedEnv = captureInertiaEnvFlags();
416
+ configureInertiaAssets(app, options);
417
+ const moduleDir = options.importMeta ? dirname2(fileURLToPath2(options.importMeta.url)) : void 0;
418
+ const resourcesDir = resolveResourcesDir(options, moduleDir);
419
+ const ssrOutDir = options.ssrOutDir ?? ".guren/ssr";
420
+ const importMapEntries = parseImportMap(process.env.GUREN_INERTIA_IMPORT_MAP, {
421
+ context: "GUREN_INERTIA_IMPORT_MAP from environment"
422
+ });
423
+ const ssrEnabled = options.enableSsr ?? true;
424
+ const setEnvIfUserDidNotProvide = (key, value) => {
425
+ if (providedEnv[key]) {
426
+ return;
427
+ }
428
+ process.env[key] = value;
429
+ };
430
+ if (!moduleDir) {
431
+ return;
432
+ }
433
+ const isProduction = (process.env.NODE_ENV ?? "development") === "production" && typeof process.env.VITE_DEV_SERVER_URL !== "string";
434
+ if (!isProduction) {
435
+ const devServerUrl = options.devServerUrl ?? process.env.VITE_DEV_SERVER_URL ?? "http://localhost:5173";
436
+ const normalizedDevServerUrl = normalizeDevServerUrl(devServerUrl);
437
+ setEnvIfUserDidNotProvide("GUREN_INERTIA_ENTRY", `${normalizedDevServerUrl}/resources/js/dev-entry.ts`);
438
+ setEnvIfUserDidNotProvide("GUREN_INERTIA_STYLES", options.stylesEntry ?? DEFAULT_DEV_STYLES_ENTRY);
439
+ importMapEntries["@guren/inertia-client"] = DEFAULT_VENDOR_CLIENT_PATH;
440
+ if (ssrEnabled) {
441
+ const ssrEntryPath = options.ssrEntry ?? (resourcesDir ? resolve3(resourcesDir, "js/ssr.tsx") : void 0);
442
+ if (ssrEntryPath) {
443
+ setEnvIfUserDidNotProvide("GUREN_INERTIA_SSR_ENTRY", ssrEntryPath);
444
+ }
445
+ setEnvIfUserDidNotProvide("GUREN_INERTIA_SSR_MANIFEST", "");
446
+ } else {
447
+ setEnvIfUserDidNotProvide("GUREN_INERTIA_SSR_ENTRY", "");
448
+ setEnvIfUserDidNotProvide("GUREN_INERTIA_SSR_MANIFEST", "");
449
+ }
450
+ process.env.GUREN_INERTIA_IMPORT_MAP = JSON.stringify(importMapEntries);
451
+ return;
452
+ }
453
+ const clientManifest = loadViteManifest(
454
+ [
455
+ resolve3(moduleDir, "../public/assets/manifest.json"),
456
+ resolve3(moduleDir, "../public/assets/.vite/manifest.json")
457
+ ],
458
+ "client"
459
+ );
460
+ const clientEntry = clientManifest?.["resources/js/app.tsx"];
461
+ const clientEntryFile = getManifestFile(clientEntry);
462
+ const clientCssFiles = getManifestCss(clientEntry);
463
+ if (clientEntryFile) {
464
+ setEnvIfUserDidNotProvide("GUREN_INERTIA_ENTRY", `/public/assets/${clientEntryFile.replace(/^\//u, "")}`);
465
+ }
466
+ if (clientCssFiles?.length) {
467
+ setEnvIfUserDidNotProvide(
468
+ "GUREN_INERTIA_STYLES",
469
+ clientCssFiles.map((href) => `/public/assets/${href.replace(/^\//u, "")}`).join(",")
470
+ );
471
+ }
472
+ importMapEntries["@guren/inertia-client"] = DEFAULT_VENDOR_CLIENT_PATH;
473
+ if (!ssrEnabled) {
474
+ if (Object.keys(importMapEntries).length > 0) {
475
+ process.env.GUREN_INERTIA_IMPORT_MAP = JSON.stringify(importMapEntries);
476
+ }
477
+ setEnvIfUserDidNotProvide("GUREN_INERTIA_SSR_ENTRY", "");
478
+ setEnvIfUserDidNotProvide("GUREN_INERTIA_SSR_MANIFEST", "");
479
+ return;
480
+ }
481
+ const ssrManifestPaths = [
482
+ options.ssrManifest,
483
+ resolve3(moduleDir, `../${ssrOutDir}/manifest.json`),
484
+ resolve3(moduleDir, `../${ssrOutDir}/.vite/manifest.json`),
485
+ resolve3(moduleDir, `../${ssrOutDir}/ssr-manifest.json`),
486
+ resolve3(moduleDir, "../build/ssr/manifest.json"),
487
+ resolve3(moduleDir, "../build/ssr/.vite/manifest.json"),
488
+ resolve3(moduleDir, "../build/ssr/ssr-manifest.json"),
489
+ resolve3(moduleDir, "../public/assets/.ssr/manifest.json"),
490
+ resolve3(moduleDir, "../public/assets/.ssr/.vite/manifest.json"),
491
+ resolve3(moduleDir, "../public/assets/.ssr/ssr-manifest.json"),
492
+ resolve3(moduleDir, "../public/assets/.vite/ssr-manifest.json")
493
+ ].filter((value) => Boolean(value));
494
+ const ssrManifest = loadViteManifest(ssrManifestPaths, "SSR");
495
+ const ssrEntry = ssrManifest?.["resources/js/ssr.tsx"];
496
+ const ssrEntryFile = getManifestFile(ssrEntry);
497
+ const ssrEntryRoot = deriveAssetRoot(ssrManifest, resolve3(moduleDir, `../${ssrOutDir}`));
498
+ if (ssrEntryFile && ssrEntryRoot) {
499
+ setEnvIfUserDidNotProvide(
500
+ "GUREN_INERTIA_SSR_ENTRY",
501
+ resolve3(ssrEntryRoot, ssrEntryFile.replace(/^\//u, ""))
502
+ );
503
+ }
504
+ if (Object.keys(importMapEntries).length > 0) {
505
+ process.env.GUREN_INERTIA_IMPORT_MAP = JSON.stringify(importMapEntries);
506
+ }
507
+ if (ssrManifest?.__path__) {
508
+ setEnvIfUserDidNotProvide("GUREN_INERTIA_SSR_MANIFEST", ssrManifest.__path__);
509
+ }
510
+ }
511
+ function captureInertiaEnvFlags() {
512
+ return {
513
+ GUREN_INERTIA_ENTRY: process.env.GUREN_INERTIA_ENTRY !== void 0,
514
+ GUREN_INERTIA_STYLES: process.env.GUREN_INERTIA_STYLES !== void 0,
515
+ GUREN_INERTIA_SSR_ENTRY: process.env.GUREN_INERTIA_SSR_ENTRY !== void 0,
516
+ GUREN_INERTIA_SSR_MANIFEST: process.env.GUREN_INERTIA_SSR_MANIFEST !== void 0
517
+ };
518
+ }
519
+ function resolveDevSsrEntry(options) {
520
+ if (options.ssrEntry) {
521
+ return options.ssrEntry;
522
+ }
523
+ if (options.resourcesDir) {
524
+ return resolve3(options.resourcesDir, "js/ssr.tsx");
525
+ }
526
+ const moduleDir = options.importMeta ? dirname2(fileURLToPath2(options.importMeta.url)) : void 0;
527
+ if (!moduleDir) {
528
+ return void 0;
529
+ }
530
+ const resourcesPath = options.resourcesPath ?? "../resources";
531
+ const resourcesDir = resolve3(moduleDir, resourcesPath);
532
+ return resolve3(resourcesDir, "js/ssr.tsx");
533
+ }
534
+ function normalizeDevServerUrl(value) {
535
+ if (!value) {
536
+ return value;
537
+ }
538
+ const trimmed = value.trim();
539
+ if (!trimmed) {
540
+ return trimmed;
541
+ }
542
+ const stripped = trimmed.replace(/\/+$/u, "");
543
+ return stripped.length > 0 ? stripped : "/";
544
+ }
545
+ function loadViteManifest(candidatePaths, label) {
546
+ const command = label === "SSR" ? "bunx vite build --ssr" : "bunx vite build";
547
+ for (const manifestPath of candidatePaths) {
548
+ try {
549
+ const raw = readFileSync(manifestPath, "utf8");
550
+ const manifest = JSON.parse(raw);
551
+ Object.defineProperty(manifest, "__path__", {
552
+ value: manifestPath,
553
+ enumerable: false
554
+ });
555
+ return manifest;
556
+ } catch (error) {
557
+ if (error.code !== "ENOENT") {
558
+ console.warn(`Unable to load ${label} Vite manifest at ${manifestPath}.`, error);
559
+ return void 0;
560
+ }
561
+ }
562
+ }
563
+ if (candidatePaths.length) {
564
+ console.warn(
565
+ `Unable to load ${label} Vite manifest. Checked paths:
566
+ ${candidatePaths.map((p) => ` - ${p}`).join("\n")}
567
+ Run \`${command}\` before starting in production.`
568
+ );
569
+ }
570
+ return void 0;
571
+ }
572
+ function deriveAssetRoot(manifest, fallback) {
573
+ if (!manifest?.__path__) {
574
+ return fallback;
575
+ }
576
+ return resolve3(dirname2(manifest.__path__), "..");
577
+ }
578
+ function getManifestFile(entry) {
579
+ if (!entry) {
580
+ return void 0;
581
+ }
582
+ if (Array.isArray(entry)) {
583
+ return entry[0];
584
+ }
585
+ if (typeof entry === "string") {
586
+ return entry;
587
+ }
588
+ if ("file" in entry && typeof entry.file === "string") {
589
+ return entry.file;
590
+ }
591
+ return void 0;
592
+ }
593
+ function getManifestCss(entry) {
594
+ if (!entry || Array.isArray(entry) || typeof entry === "string") {
595
+ return void 0;
596
+ }
597
+ return entry.css;
598
+ }
599
+ function resolveResourcesDir(options, moduleDir) {
600
+ if (options.resourcesDir) {
601
+ return options.resourcesDir;
602
+ }
603
+ if (!moduleDir) {
604
+ return void 0;
605
+ }
606
+ const resourcesPath = options.resourcesPath ?? "../resources";
607
+ return resolve3(moduleDir, resourcesPath);
608
+ }
609
+
610
+ // src/http/dev-banner.ts
611
+ import chalk from "chalk";
612
+ import figlet from "figlet";
613
+
614
+ // package.json
615
+ var package_default = {
616
+ name: "@guren/server",
617
+ version: "1.0.0-rc.9",
618
+ type: "module",
619
+ license: "MIT",
620
+ repository: {
621
+ type: "git",
622
+ url: "https://github.com/gurenjs/guren",
623
+ directory: "packages/server"
624
+ },
625
+ homepage: "https://github.com/gurenjs/guren#readme",
626
+ bugs: {
627
+ url: "https://github.com/gurenjs/guren/issues"
628
+ },
629
+ publishConfig: {
630
+ access: "public"
631
+ },
632
+ files: [
633
+ "dist"
634
+ ],
635
+ main: "dist/index.js",
636
+ types: "dist/index.d.ts",
637
+ exports: {
638
+ ".": {
639
+ types: "./dist/index.d.ts",
640
+ default: "./dist/index.js"
641
+ },
642
+ "./auth": {
643
+ types: "./dist/auth/index.d.ts",
644
+ default: "./dist/auth/index.js"
645
+ },
646
+ "./authorization": {
647
+ types: "./dist/authorization/index.d.ts",
648
+ default: "./dist/authorization/index.js"
649
+ },
650
+ "./broadcasting": {
651
+ types: "./dist/broadcasting/index.d.ts",
652
+ default: "./dist/broadcasting/index.js"
653
+ },
654
+ "./cache": {
655
+ types: "./dist/cache/index.d.ts",
656
+ default: "./dist/cache/index.js"
657
+ },
658
+ "./encryption": {
659
+ types: "./dist/encryption/index.d.ts",
660
+ default: "./dist/encryption/index.js"
661
+ },
662
+ "./events": {
663
+ types: "./dist/events/index.d.ts",
664
+ default: "./dist/events/index.js"
665
+ },
666
+ "./health": {
667
+ types: "./dist/health/index.d.ts",
668
+ default: "./dist/health/index.js"
669
+ },
670
+ "./i18n": {
671
+ types: "./dist/i18n/index.d.ts",
672
+ default: "./dist/i18n/index.js"
673
+ },
674
+ "./logging": {
675
+ types: "./dist/logging/index.d.ts",
676
+ default: "./dist/logging/index.js"
677
+ },
678
+ "./mail": {
679
+ types: "./dist/mail/index.d.ts",
680
+ default: "./dist/mail/index.js"
681
+ },
682
+ "./notifications": {
683
+ types: "./dist/notifications/index.d.ts",
684
+ default: "./dist/notifications/index.js"
685
+ },
686
+ "./queue": {
687
+ types: "./dist/queue/index.d.ts",
688
+ default: "./dist/queue/index.js"
689
+ },
690
+ "./runtime": {
691
+ types: "./dist/runtime/index.d.ts",
692
+ default: "./dist/runtime/index.js"
693
+ },
694
+ "./scheduling": {
695
+ types: "./dist/scheduling/index.d.ts",
696
+ default: "./dist/scheduling/index.js"
697
+ },
698
+ "./storage": {
699
+ types: "./dist/storage/index.d.ts",
700
+ default: "./dist/storage/index.js"
701
+ },
702
+ "./vite": {
703
+ types: "./dist/vite/index.d.ts",
704
+ default: "./dist/vite/index.js"
705
+ },
706
+ "./mcp": {
707
+ types: "./dist/mcp/index.d.ts",
708
+ default: "./dist/mcp/index.js"
709
+ },
710
+ "./lambda": {
711
+ types: "./dist/lambda/index.d.ts",
712
+ default: "./dist/lambda/index.js"
713
+ }
714
+ },
715
+ scripts: {
716
+ build: "NODE_OPTIONS='--max-old-space-size=8192' tsup",
717
+ dev: "bun --watch src/index.ts",
718
+ typecheck: "tsc --noEmit",
719
+ test: "bun test"
720
+ },
721
+ dependencies: {
722
+ "@guren/inertia-client": "^1.0.0-rc.9",
723
+ "@modelcontextprotocol/sdk": "^1.27.1",
724
+ chalk: "^5.3.0",
725
+ consola: "^3.4.2",
726
+ figlet: "^1.7.0",
727
+ hono: "^4.12.8",
728
+ ioredis: "^5.9.1",
729
+ nodemailer: "^7.0.12"
730
+ },
731
+ peerDependencies: {
732
+ "@aws-sdk/client-s3": "^3.0.0",
733
+ "@aws-sdk/client-sqs": "^3.0.0",
734
+ "@aws-sdk/s3-request-presigner": "^3.0.0",
735
+ vite: ">=7.0.0"
736
+ },
737
+ peerDependenciesMeta: {
738
+ "@aws-sdk/client-s3": {
739
+ optional: true
740
+ },
741
+ "@aws-sdk/client-sqs": {
742
+ optional: true
743
+ },
744
+ "@aws-sdk/s3-request-presigner": {
745
+ optional: true
746
+ }
747
+ },
748
+ devDependencies: {
749
+ "@types/ioredis": "^5.0.0",
750
+ "@types/node": "^20.14.10",
751
+ "@types/nodemailer": "^7.0.5",
752
+ tsup: "^8.5.0",
753
+ typescript: "^5.4.0",
754
+ vite: "^8.0.0"
755
+ }
756
+ };
757
+
758
+ // src/http/dev-banner.ts
759
+ function generateAsciiArt(text) {
760
+ try {
761
+ const rendered = figlet.textSync(text, {
762
+ font: "Standard",
763
+ horizontalLayout: "default",
764
+ verticalLayout: "default"
765
+ });
766
+ return rendered;
767
+ } catch (error) {
768
+ console.error("Failed to generate FIGlet banner, falling back to plain text:", error);
769
+ return text.toUpperCase();
770
+ }
771
+ }
772
+ var GUREN_ASCII_ART = chalk.redBright.bold(generateAsciiArt("GUREN"));
773
+ var GUREN_VERSION = package_default.version;
774
+ function logDevServerBanner({
775
+ hostname,
776
+ port,
777
+ assetsUrl = "http://localhost:5173"
778
+ }) {
779
+ const localUrl = `http://localhost:${port}`;
780
+ const boundUrl = `http://${hostname}:${port}`;
781
+ const boundLabel = hostname === "0.0.0.0" || hostname === "::" ? " (all interfaces)" : "";
782
+ const header = [
783
+ GUREN_ASCII_ART,
784
+ chalk.magentaBright.bold(
785
+ `Guren v${GUREN_VERSION} ignites \u2014 burning bright like a crimson lotus.`
786
+ ),
787
+ ""
788
+ ];
789
+ const detail = (label, value) => `${chalk.magentaBright(" \u2022")} ${chalk.bold(label.padEnd(14))}: ${chalk.cyanBright(value)}`;
790
+ const banner = [
791
+ ...header,
792
+ detail("App URL", localUrl),
793
+ detail("Bound address", `${boundUrl}${boundLabel}`),
794
+ detail("Asset server", `${assetsUrl} (Vite)`),
795
+ "",
796
+ chalk.yellowBright("Press Ctrl+C to douse the flames."),
797
+ ""
798
+ ].join("\n");
799
+ console.log(banner);
800
+ }
801
+
802
+ // src/http/vite-dev-server.ts
803
+ async function startViteDevServer(options = {}) {
804
+ const { root = process.cwd(), config = {}, host = true, port } = options;
805
+ const { createServer } = await import("vite");
806
+ const mergedConfig = {
807
+ clearScreen: false,
808
+ ...config,
809
+ root: config.root ?? root,
810
+ server: {
811
+ host,
812
+ port,
813
+ ...config.server ?? {}
814
+ }
815
+ };
816
+ const server = await createServer(mergedConfig);
817
+ await server.listen();
818
+ const resolved = server.resolvedUrls;
819
+ const localUrls = resolved?.local?.length ? resolved.local : [`http://${typeof host === "string" ? host : "localhost"}:${server.config.server.port ?? port ?? 5173}`];
820
+ const networkUrls = resolved?.network ?? [];
821
+ return {
822
+ server,
823
+ localUrl: localUrls[0],
824
+ networkUrls
825
+ };
826
+ }
827
+ export {
828
+ GUREN_ASCII_ART,
829
+ autoConfigureInertiaAssets,
830
+ configureInertiaAssets,
831
+ logDevServerBanner,
832
+ registerDevAssets,
833
+ startViteDevServer
834
+ };