@guren/server 2.3.0 → 2.4.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.
- package/dist/broadcasting/index.js +2 -1
- package/dist/{chunk-SIP34GBE.js → chunk-2SC566CD.js} +14 -18
- package/dist/{chunk-4VE3LYOM.js → chunk-DRNPVBAA.js} +20 -5
- package/dist/{chunk-LVJCZCAV.js → chunk-H3B23O6T.js} +10 -118
- package/dist/{chunk-6IGN233M.js → chunk-NENDACRP.js} +16 -4
- package/dist/chunk-V4DNC2ER.js +114 -0
- package/dist/encryption/index.js +17 -15
- package/dist/health/index.js +1 -1
- package/dist/http/Application.d.ts +55 -1
- package/dist/http/FormRequest.d.ts +10 -7
- package/dist/http/dev-banner.d.ts +11 -0
- package/dist/http/middleware/validation-errors-cookie.d.ts +31 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +301 -82
- package/dist/redis/index.js +6 -4
- package/dist/runtime/index.js +2 -2
- package/dist/support/inertia-defaults.d.ts +13 -0
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { Application, createApp } from './http/Application.js';
|
|
2
|
-
export type { Context, ApplicationListenOptions, ServiceProviderConstructor } from './http/Application.js';
|
|
2
|
+
export type { Context, ApplicationListenOptions, ListenAddress, ServiceProviderConstructor, } from './http/Application.js';
|
|
3
3
|
export { parseRequestPayload, formatValidationErrors } from './http/request.js';
|
|
4
4
|
export { Controller } from './mvc/Controller.js';
|
|
5
5
|
export type { InertiaResponse, InferInertiaProps, ControllerInertiaProps, AuthPayload } from './mvc/Controller.js';
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
|
+
DEFAULT_DEV_STYLES_ENTRY,
|
|
3
|
+
formatHostPort,
|
|
4
|
+
isWildcardHost,
|
|
2
5
|
logDevServerBanner,
|
|
3
6
|
parseImportMap,
|
|
4
7
|
startViteDevServer
|
|
5
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-NENDACRP.js";
|
|
6
9
|
import {
|
|
7
10
|
PendingSchedule,
|
|
8
11
|
Schedule,
|
|
@@ -231,7 +234,7 @@ import {
|
|
|
231
234
|
getBroadcastManager,
|
|
232
235
|
parseRequestPayload,
|
|
233
236
|
setBroadcastManager
|
|
234
|
-
} from "./chunk-
|
|
237
|
+
} from "./chunk-DRNPVBAA.js";
|
|
235
238
|
import {
|
|
236
239
|
CacheManager,
|
|
237
240
|
FileStore,
|
|
@@ -251,25 +254,11 @@ import {
|
|
|
251
254
|
decrypt,
|
|
252
255
|
encrypt,
|
|
253
256
|
generateKey,
|
|
254
|
-
generateOtp,
|
|
255
|
-
generatePassword,
|
|
256
|
-
generateSlug,
|
|
257
257
|
getEncrypter,
|
|
258
|
-
pick,
|
|
259
|
-
random,
|
|
260
|
-
randomBase64,
|
|
261
|
-
randomBase64Url,
|
|
262
|
-
randomHex,
|
|
263
|
-
randomInt,
|
|
264
|
-
randomString,
|
|
265
|
-
sample,
|
|
266
258
|
setEncrypter,
|
|
267
|
-
shuffle,
|
|
268
259
|
signUrl,
|
|
269
|
-
urlSafeToken,
|
|
270
|
-
uuid,
|
|
271
260
|
verifySignedUrl
|
|
272
|
-
} from "./chunk-
|
|
261
|
+
} from "./chunk-H3B23O6T.js";
|
|
273
262
|
import {
|
|
274
263
|
MessageSigner,
|
|
275
264
|
deriveAppKey,
|
|
@@ -294,6 +283,22 @@ import {
|
|
|
294
283
|
verifyHmac,
|
|
295
284
|
verifyPassword
|
|
296
285
|
} from "./chunk-QQKTH5KX.js";
|
|
286
|
+
import {
|
|
287
|
+
generateOtp,
|
|
288
|
+
generatePassword,
|
|
289
|
+
generateSlug,
|
|
290
|
+
pick,
|
|
291
|
+
random,
|
|
292
|
+
randomBase64,
|
|
293
|
+
randomBase64Url,
|
|
294
|
+
randomHex,
|
|
295
|
+
randomInt,
|
|
296
|
+
randomString,
|
|
297
|
+
sample,
|
|
298
|
+
shuffle,
|
|
299
|
+
urlSafeToken,
|
|
300
|
+
uuid
|
|
301
|
+
} from "./chunk-V4DNC2ER.js";
|
|
297
302
|
import {
|
|
298
303
|
ApplicationShutdown,
|
|
299
304
|
ApplicationStarted,
|
|
@@ -319,7 +324,7 @@ import {
|
|
|
319
324
|
StorageCheck,
|
|
320
325
|
createHealthManager,
|
|
321
326
|
customCheck
|
|
322
|
-
} from "./chunk-
|
|
327
|
+
} from "./chunk-2SC566CD.js";
|
|
323
328
|
|
|
324
329
|
// src/support/error-polyfill.ts
|
|
325
330
|
var patched = false;
|
|
@@ -2232,7 +2237,7 @@ async function inertia(component, props, options = {}) {
|
|
|
2232
2237
|
const page = {
|
|
2233
2238
|
component,
|
|
2234
2239
|
props,
|
|
2235
|
-
url: options.url ?? "",
|
|
2240
|
+
url: options.url ?? inertiaPageUrl(options.request) ?? "",
|
|
2236
2241
|
version: resolvedVersion
|
|
2237
2242
|
};
|
|
2238
2243
|
const request = options.request;
|
|
@@ -2275,15 +2280,23 @@ async function inertia(component, props, options = {}) {
|
|
|
2275
2280
|
}
|
|
2276
2281
|
});
|
|
2277
2282
|
}
|
|
2283
|
+
function inertiaPageUrl(request) {
|
|
2284
|
+
if (!request) {
|
|
2285
|
+
return void 0;
|
|
2286
|
+
}
|
|
2287
|
+
const { pathname, search } = new URL(request.url);
|
|
2288
|
+
return `${pathname}${search}`;
|
|
2289
|
+
}
|
|
2278
2290
|
async function renderDocument(page, options) {
|
|
2279
2291
|
const defaultEntry = process.env.GUREN_INERTIA_ENTRY ?? "/resources/js/app.tsx";
|
|
2280
2292
|
const entry = options.entry ?? defaultEntry;
|
|
2281
2293
|
const title = escapeHtml(options.title ?? DEFAULT_TITLE);
|
|
2282
|
-
const
|
|
2294
|
+
const isProduction = process.env.NODE_ENV === "production";
|
|
2295
|
+
const configuredStyles = options.styles ?? parseStylesEnv(process.env.GUREN_INERTIA_STYLES);
|
|
2296
|
+
const styles = !isProduction && options.styles === void 0 && isDevServerEntry(entry) ? configuredStyles.filter((href) => href !== DEFAULT_DEV_STYLES_ENTRY) : configuredStyles;
|
|
2283
2297
|
const envImportMap = parseImportMap(process.env.GUREN_INERTIA_IMPORT_MAP, {
|
|
2284
2298
|
context: "GUREN_INERTIA_IMPORT_MAP"
|
|
2285
2299
|
});
|
|
2286
|
-
const isProduction = process.env.NODE_ENV === "production";
|
|
2287
2300
|
const importMapEntries = {
|
|
2288
2301
|
...isProduction ? {} : DEV_FALLBACK_IMPORT_MAP,
|
|
2289
2302
|
...envImportMap,
|
|
@@ -2417,6 +2430,9 @@ function normalizeSsrSpecifier(specifier) {
|
|
|
2417
2430
|
function isUrlLike(specifier) {
|
|
2418
2431
|
return /^[a-zA-Z][a-zA-Z\d+\-.]*:/.test(specifier);
|
|
2419
2432
|
}
|
|
2433
|
+
function isDevServerEntry(entry) {
|
|
2434
|
+
return /^https?:\/\//iu.test(entry);
|
|
2435
|
+
}
|
|
2420
2436
|
function renderStyles(styles) {
|
|
2421
2437
|
if (!styles.length) {
|
|
2422
2438
|
return "";
|
|
@@ -2514,12 +2530,79 @@ var ViewEngine = class {
|
|
|
2514
2530
|
}
|
|
2515
2531
|
};
|
|
2516
2532
|
|
|
2533
|
+
// src/http/middleware/validation-errors-cookie.ts
|
|
2534
|
+
import { deleteCookie, getCookie as getCookie3 } from "hono/cookie";
|
|
2535
|
+
import { serialize } from "hono/utils/cookie";
|
|
2536
|
+
var VALIDATION_ERRORS_COOKIE = "guren_validation_errors";
|
|
2537
|
+
var COOKIE_MAX_AGE_SECONDS = 60;
|
|
2538
|
+
var MAX_COOKIE_VALUE_LENGTH = 3800;
|
|
2539
|
+
var CONSUMED_CONTEXT_KEY = "gurenValidationErrorsCookieConsumed";
|
|
2540
|
+
function validationErrorsSetCookie(errors) {
|
|
2541
|
+
const kept = {};
|
|
2542
|
+
for (const [field, message] of Object.entries(errors)) {
|
|
2543
|
+
const next = encodeURIComponent(JSON.stringify({ ...kept, [field]: message }));
|
|
2544
|
+
if (next.length > MAX_COOKIE_VALUE_LENGTH) {
|
|
2545
|
+
continue;
|
|
2546
|
+
}
|
|
2547
|
+
kept[field] = message;
|
|
2548
|
+
}
|
|
2549
|
+
return serialize(VALIDATION_ERRORS_COOKIE, JSON.stringify(kept), {
|
|
2550
|
+
path: "/",
|
|
2551
|
+
httpOnly: true,
|
|
2552
|
+
sameSite: "Lax",
|
|
2553
|
+
maxAge: COOKIE_MAX_AGE_SECONDS
|
|
2554
|
+
});
|
|
2555
|
+
}
|
|
2556
|
+
function readValidationErrorsCookie(ctx) {
|
|
2557
|
+
const raw = getCookie3(ctx, VALIDATION_ERRORS_COOKIE);
|
|
2558
|
+
if (!raw) {
|
|
2559
|
+
return void 0;
|
|
2560
|
+
}
|
|
2561
|
+
ctx.set(CONSUMED_CONTEXT_KEY, true);
|
|
2562
|
+
let parsed;
|
|
2563
|
+
try {
|
|
2564
|
+
parsed = JSON.parse(raw);
|
|
2565
|
+
} catch {
|
|
2566
|
+
return void 0;
|
|
2567
|
+
}
|
|
2568
|
+
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
2569
|
+
return void 0;
|
|
2570
|
+
}
|
|
2571
|
+
const errors = {};
|
|
2572
|
+
for (const [field, message] of Object.entries(parsed)) {
|
|
2573
|
+
if (typeof message === "string") {
|
|
2574
|
+
errors[field] = message;
|
|
2575
|
+
}
|
|
2576
|
+
}
|
|
2577
|
+
return Object.keys(errors).length > 0 ? errors : void 0;
|
|
2578
|
+
}
|
|
2579
|
+
function createValidationErrorsCookieCleanup() {
|
|
2580
|
+
return async (ctx, next) => {
|
|
2581
|
+
await next();
|
|
2582
|
+
if (!ctx.get(CONSUMED_CONTEXT_KEY)) {
|
|
2583
|
+
return;
|
|
2584
|
+
}
|
|
2585
|
+
const setCookies = ctx.res.headers.getSetCookie?.() ?? [];
|
|
2586
|
+
if (setCookies.some((header) => header.startsWith(`${VALIDATION_ERRORS_COOKIE}=`))) {
|
|
2587
|
+
return;
|
|
2588
|
+
}
|
|
2589
|
+
deleteCookie(ctx, VALIDATION_ERRORS_COOKIE, { path: "/" });
|
|
2590
|
+
};
|
|
2591
|
+
}
|
|
2592
|
+
|
|
2517
2593
|
// src/providers/InertiaServiceProvider.ts
|
|
2518
2594
|
var InertiaServiceProvider = class extends ServiceProvider {
|
|
2519
2595
|
register() {
|
|
2520
2596
|
if (!ViewEngine.has("inertia")) {
|
|
2521
2597
|
ViewEngine.register("inertia", inertia);
|
|
2522
2598
|
}
|
|
2599
|
+
let hono;
|
|
2600
|
+
try {
|
|
2601
|
+
hono = this.container.make("hono");
|
|
2602
|
+
} catch {
|
|
2603
|
+
return;
|
|
2604
|
+
}
|
|
2605
|
+
hono.use("*", createValidationErrorsCookieCleanup());
|
|
2523
2606
|
}
|
|
2524
2607
|
boot() {
|
|
2525
2608
|
this.registerValidationRenderer();
|
|
@@ -2547,18 +2630,21 @@ var InertiaServiceProvider = class extends ServiceProvider {
|
|
|
2547
2630
|
422
|
|
2548
2631
|
);
|
|
2549
2632
|
}
|
|
2633
|
+
const flattened = {};
|
|
2634
|
+
for (const [key, messages] of Object.entries(error.errors ?? {})) {
|
|
2635
|
+
flattened[key] = messages[0] ?? "";
|
|
2636
|
+
}
|
|
2637
|
+
const referer = ctx.req.header("Referer") ?? "/";
|
|
2638
|
+
const headers = { Location: referer };
|
|
2550
2639
|
const session = getSessionFromContext(ctx);
|
|
2551
2640
|
if (session) {
|
|
2552
|
-
const flattened = {};
|
|
2553
|
-
for (const [key, messages] of Object.entries(error.errors ?? {})) {
|
|
2554
|
-
flattened[key] = messages[0] ?? "";
|
|
2555
|
-
}
|
|
2556
2641
|
session.flash("errors", flattened);
|
|
2642
|
+
} else {
|
|
2643
|
+
headers["Set-Cookie"] = validationErrorsSetCookie(flattened);
|
|
2557
2644
|
}
|
|
2558
|
-
const referer = ctx.req.header("Referer") ?? "/";
|
|
2559
2645
|
return new Response(null, {
|
|
2560
2646
|
status: 303,
|
|
2561
|
-
headers
|
|
2647
|
+
headers
|
|
2562
2648
|
});
|
|
2563
2649
|
});
|
|
2564
2650
|
}
|
|
@@ -2570,8 +2656,12 @@ var InertiaServiceProvider = class extends ServiceProvider {
|
|
|
2570
2656
|
registerSharedErrors() {
|
|
2571
2657
|
shareInertiaProps(async (ctx) => {
|
|
2572
2658
|
const session = getSessionFromContext(ctx);
|
|
2573
|
-
|
|
2574
|
-
|
|
2659
|
+
if (session) {
|
|
2660
|
+
const errors2 = session.getFlash("errors");
|
|
2661
|
+
return errors2 && Object.keys(errors2).length > 0 ? { errors: errors2 } : {};
|
|
2662
|
+
}
|
|
2663
|
+
const errors = readValidationErrorsCookie(ctx);
|
|
2664
|
+
return errors ? { errors } : {};
|
|
2575
2665
|
}, this.container);
|
|
2576
2666
|
}
|
|
2577
2667
|
};
|
|
@@ -2579,6 +2669,29 @@ var InertiaServiceProvider = class extends ServiceProvider {
|
|
|
2579
2669
|
// src/http/Application.ts
|
|
2580
2670
|
var MANAGED_VITE_ENV_FLAG = "GUREN_MANAGED_VITE_DEV_SERVER";
|
|
2581
2671
|
var DEFAULT_DEV_ENTRY_PATH = "/resources/js/dev-entry.ts";
|
|
2672
|
+
var STRICT_PORT_ENV_FLAG = "GUREN_STRICT_PORT";
|
|
2673
|
+
var DEFAULT_PORT_WALK_ATTEMPTS = 20;
|
|
2674
|
+
function isAddressInUse(error) {
|
|
2675
|
+
return Boolean(
|
|
2676
|
+
error && typeof error === "object" && "code" in error && error.code === "EADDRINUSE"
|
|
2677
|
+
);
|
|
2678
|
+
}
|
|
2679
|
+
function resolvePortAttempts(option, port) {
|
|
2680
|
+
if (port === 0) {
|
|
2681
|
+
return 1;
|
|
2682
|
+
}
|
|
2683
|
+
if (typeof process !== "undefined" && process.env?.[STRICT_PORT_ENV_FLAG] === "1") {
|
|
2684
|
+
return 1;
|
|
2685
|
+
}
|
|
2686
|
+
if (typeof option === "boolean") {
|
|
2687
|
+
return option ? DEFAULT_PORT_WALK_ATTEMPTS : 1;
|
|
2688
|
+
}
|
|
2689
|
+
return typeof process !== "undefined" && process.env.NODE_ENV === "production" ? 1 : DEFAULT_PORT_WALK_ATTEMPTS;
|
|
2690
|
+
}
|
|
2691
|
+
function toConnectableUrl(hostname, port) {
|
|
2692
|
+
const host = isWildcardHost(hostname) ? hostname === "::" ? "::1" : "127.0.0.1" : hostname;
|
|
2693
|
+
return `http://${formatHostPort(host, port)}`;
|
|
2694
|
+
}
|
|
2582
2695
|
function clearManagedViteEnv() {
|
|
2583
2696
|
if (typeof process === "undefined") {
|
|
2584
2697
|
return;
|
|
@@ -2604,7 +2717,7 @@ function syncManagedInertiaDevEntry(devServerUrl) {
|
|
|
2604
2717
|
function getGlobalState() {
|
|
2605
2718
|
return globalThis;
|
|
2606
2719
|
}
|
|
2607
|
-
async function stopActiveBunServer() {
|
|
2720
|
+
async function stopActiveBunServer(closeActiveConnections = false) {
|
|
2608
2721
|
const state = getGlobalState();
|
|
2609
2722
|
const previous = state.__gurenActiveServer;
|
|
2610
2723
|
if (!previous?.stop) {
|
|
@@ -2612,7 +2725,7 @@ async function stopActiveBunServer() {
|
|
|
2612
2725
|
return;
|
|
2613
2726
|
}
|
|
2614
2727
|
try {
|
|
2615
|
-
await Promise.resolve(previous.stop());
|
|
2728
|
+
await Promise.resolve(previous.stop(closeActiveConnections));
|
|
2616
2729
|
} catch (error) {
|
|
2617
2730
|
console.warn("Failed to stop previous Bun server:", error);
|
|
2618
2731
|
} finally {
|
|
@@ -2622,25 +2735,59 @@ async function stopActiveBunServer() {
|
|
|
2622
2735
|
function setActiveBunServer(server) {
|
|
2623
2736
|
getGlobalState().__gurenActiveServer = server;
|
|
2624
2737
|
}
|
|
2625
|
-
|
|
2626
|
-
const
|
|
2627
|
-
|
|
2628
|
-
|
|
2629
|
-
|
|
2630
|
-
|
|
2631
|
-
|
|
2738
|
+
function viteCloseTimeoutMs() {
|
|
2739
|
+
const parsed = typeof process !== "undefined" ? Number.parseInt(process.env.GUREN_VITE_CLOSE_TIMEOUT_MS ?? "", 10) : Number.NaN;
|
|
2740
|
+
return Number.isInteger(parsed) && parsed > 0 ? parsed : 5e3;
|
|
2741
|
+
}
|
|
2742
|
+
async function closeViteDevServerBounded(server) {
|
|
2743
|
+
let timer;
|
|
2744
|
+
const close = server.close().catch((error) => {
|
|
2745
|
+
console.warn("Failed to stop Vite dev server:", error);
|
|
2746
|
+
});
|
|
2747
|
+
try {
|
|
2748
|
+
const timeoutMs = viteCloseTimeoutMs();
|
|
2749
|
+
const timedOut = await Promise.race([
|
|
2750
|
+
close.then(() => false),
|
|
2751
|
+
new Promise((resolve2) => {
|
|
2752
|
+
timer = setTimeout(() => resolve2(true), timeoutMs);
|
|
2753
|
+
})
|
|
2754
|
+
]);
|
|
2755
|
+
if (timedOut) {
|
|
2756
|
+
console.warn(
|
|
2757
|
+
`Vite dev server did not close within ${timeoutMs}ms \u2014 abandoning it. A stale asset server may still hold its port.`
|
|
2758
|
+
);
|
|
2759
|
+
}
|
|
2760
|
+
} finally {
|
|
2761
|
+
clearTimeout(timer);
|
|
2632
2762
|
}
|
|
2763
|
+
}
|
|
2764
|
+
async function stopActiveViteDevServer() {
|
|
2765
|
+
const previous = getGlobalState().__gurenActiveViteDevServer;
|
|
2633
2766
|
try {
|
|
2634
|
-
|
|
2635
|
-
|
|
2636
|
-
|
|
2767
|
+
if (previous) {
|
|
2768
|
+
await closeViteDevServerBounded(previous);
|
|
2769
|
+
}
|
|
2637
2770
|
} finally {
|
|
2638
|
-
|
|
2771
|
+
setActiveViteDevServer();
|
|
2639
2772
|
clearManagedViteEnv();
|
|
2640
2773
|
}
|
|
2641
2774
|
}
|
|
2642
|
-
function setActiveViteDevServer(server) {
|
|
2643
|
-
getGlobalState()
|
|
2775
|
+
function setActiveViteDevServer(server, localUrl) {
|
|
2776
|
+
const state = getGlobalState();
|
|
2777
|
+
state.__gurenActiveViteDevServer = server;
|
|
2778
|
+
state.__gurenActiveViteDevServerUrl = server ? localUrl : void 0;
|
|
2779
|
+
}
|
|
2780
|
+
function reusableActiveViteDevServer(viteOption) {
|
|
2781
|
+
if (typeof viteOption === "object") {
|
|
2782
|
+
return void 0;
|
|
2783
|
+
}
|
|
2784
|
+
const state = getGlobalState();
|
|
2785
|
+
const server = state.__gurenActiveViteDevServer;
|
|
2786
|
+
const localUrl = state.__gurenActiveViteDevServerUrl;
|
|
2787
|
+
if (!server || !localUrl || !server.httpServer?.listening) {
|
|
2788
|
+
return void 0;
|
|
2789
|
+
}
|
|
2790
|
+
return { server, localUrl };
|
|
2644
2791
|
}
|
|
2645
2792
|
var Application = class {
|
|
2646
2793
|
constructor(options = {}) {
|
|
@@ -2700,6 +2847,7 @@ var Application = class {
|
|
|
2700
2847
|
authManager;
|
|
2701
2848
|
viteDevServer;
|
|
2702
2849
|
bunServer;
|
|
2850
|
+
boundAddress;
|
|
2703
2851
|
viteTeardownRegistered = false;
|
|
2704
2852
|
bunTeardownRegistered = false;
|
|
2705
2853
|
autoSessionAttached = false;
|
|
@@ -2830,13 +2978,30 @@ var Application = class {
|
|
|
2830
2978
|
if (!Bun) {
|
|
2831
2979
|
throw new Error("Bun runtime is required to call Application.listen");
|
|
2832
2980
|
}
|
|
2833
|
-
await stopActiveBunServer();
|
|
2834
|
-
|
|
2835
|
-
const { port = 3e3, hostname = "0.0.0.0", assetsUrl, vite } = options;
|
|
2981
|
+
await stopActiveBunServer(true);
|
|
2982
|
+
const { port = 3e3, hostname = "0.0.0.0", assetsUrl, vite, portFallback } = options;
|
|
2836
2983
|
const externalAssetsUrl = typeof process !== "undefined" && process.env?.[MANAGED_VITE_ENV_FLAG] !== "1" ? process.env?.VITE_DEV_SERVER_URL : void 0;
|
|
2837
2984
|
let resolvedAssetsUrl = assetsUrl ?? externalAssetsUrl;
|
|
2838
|
-
const shouldStartVite = vite !== false && typeof process !== "undefined" && process.env
|
|
2839
|
-
|
|
2985
|
+
const shouldStartVite = vite !== false && typeof process !== "undefined" && process.env.NODE_ENV !== "production" && !resolvedAssetsUrl && process.env?.GUREN_DEV_VITE !== "0";
|
|
2986
|
+
const adoptViteDevServer = (viteServer, localUrl) => {
|
|
2987
|
+
this.viteDevServer = viteServer;
|
|
2988
|
+
setActiveViteDevServer(viteServer, localUrl);
|
|
2989
|
+
resolvedAssetsUrl = localUrl;
|
|
2990
|
+
if (typeof process !== "undefined") {
|
|
2991
|
+
process.env.VITE_DEV_SERVER_URL = localUrl;
|
|
2992
|
+
process.env[MANAGED_VITE_ENV_FLAG] = "1";
|
|
2993
|
+
}
|
|
2994
|
+
syncManagedInertiaDevEntry(localUrl);
|
|
2995
|
+
this.registerViteTeardown();
|
|
2996
|
+
};
|
|
2997
|
+
const reusableVite = shouldStartVite ? reusableActiveViteDevServer(vite) : void 0;
|
|
2998
|
+
let startedViteHere = false;
|
|
2999
|
+
if (reusableVite) {
|
|
3000
|
+
adoptViteDevServer(reusableVite.server, reusableVite.localUrl);
|
|
3001
|
+
} else {
|
|
3002
|
+
await stopActiveViteDevServer();
|
|
3003
|
+
}
|
|
3004
|
+
if (shouldStartVite && !reusableVite) {
|
|
2840
3005
|
const viteOptions = typeof vite === "object" ? vite : void 0;
|
|
2841
3006
|
try {
|
|
2842
3007
|
await this.closeViteDevServer();
|
|
@@ -2846,39 +3011,94 @@ var Application = class {
|
|
|
2846
3011
|
host: viteOptions?.host,
|
|
2847
3012
|
port: viteOptions?.port
|
|
2848
3013
|
});
|
|
2849
|
-
|
|
2850
|
-
|
|
2851
|
-
resolvedAssetsUrl = localUrl;
|
|
2852
|
-
if (typeof process !== "undefined") {
|
|
2853
|
-
process.env.VITE_DEV_SERVER_URL = resolvedAssetsUrl;
|
|
2854
|
-
process.env[MANAGED_VITE_ENV_FLAG] = "1";
|
|
2855
|
-
}
|
|
2856
|
-
syncManagedInertiaDevEntry(resolvedAssetsUrl);
|
|
2857
|
-
this.registerViteTeardown();
|
|
3014
|
+
adoptViteDevServer(server2, localUrl);
|
|
3015
|
+
startedViteHere = true;
|
|
2858
3016
|
} catch (error) {
|
|
2859
3017
|
console.error("Failed to start Vite dev server:", error);
|
|
2860
3018
|
process.exit(1);
|
|
2861
3019
|
}
|
|
2862
3020
|
}
|
|
2863
|
-
const
|
|
2864
|
-
|
|
2865
|
-
|
|
2866
|
-
|
|
2867
|
-
|
|
2868
|
-
|
|
2869
|
-
|
|
2870
|
-
|
|
3021
|
+
const attempts = resolvePortAttempts(portFallback, port);
|
|
3022
|
+
let server;
|
|
3023
|
+
let attemptPort = port;
|
|
3024
|
+
for (let offset = 0; offset < attempts; offset += 1) {
|
|
3025
|
+
attemptPort = port + offset;
|
|
3026
|
+
try {
|
|
3027
|
+
server = Bun.serve({
|
|
3028
|
+
port: attemptPort,
|
|
3029
|
+
hostname,
|
|
3030
|
+
// `{ server }` is Bun's convention for reaching the live server from a
|
|
3031
|
+
// handler; middleware reads `ctx.env.server.requestIP()` through it to
|
|
3032
|
+
// learn the socket peer (the MCP access guard, the rate limiter).
|
|
3033
|
+
fetch: (request, server2) => this.fetch(request, { server: server2 })
|
|
3034
|
+
});
|
|
3035
|
+
break;
|
|
3036
|
+
} catch (error) {
|
|
3037
|
+
if (offset === attempts - 1 || !isAddressInUse(error)) {
|
|
3038
|
+
if (startedViteHere) {
|
|
3039
|
+
await this.closeViteDevServer();
|
|
3040
|
+
}
|
|
3041
|
+
throw error;
|
|
3042
|
+
}
|
|
3043
|
+
console.warn(`[guren] Port ${attemptPort} is in use, trying ${attemptPort + 1}...`);
|
|
3044
|
+
}
|
|
3045
|
+
}
|
|
3046
|
+
if (!server) {
|
|
3047
|
+
throw new Error("Bun.serve did not return a server instance");
|
|
3048
|
+
}
|
|
3049
|
+
let boundPort = server.port;
|
|
3050
|
+
if (typeof boundPort !== "number") {
|
|
3051
|
+
if (port === 0) {
|
|
3052
|
+
await server.stop?.(true);
|
|
3053
|
+
throw new Error(
|
|
3054
|
+
"Bun.serve did not report a bound port for `port: 0`. Application.listen cannot report the address it is serving on."
|
|
3055
|
+
);
|
|
3056
|
+
}
|
|
3057
|
+
boundPort = attemptPort;
|
|
3058
|
+
}
|
|
3059
|
+
const boundHostname = server.hostname ?? hostname;
|
|
3060
|
+
const address = {
|
|
3061
|
+
port: boundPort,
|
|
3062
|
+
hostname: boundHostname,
|
|
3063
|
+
url: toConnectableUrl(boundHostname, boundPort)
|
|
3064
|
+
};
|
|
2871
3065
|
this.bunServer = server;
|
|
3066
|
+
this.boundAddress = address;
|
|
2872
3067
|
setActiveBunServer(server);
|
|
2873
3068
|
this.registerBunTeardown();
|
|
2874
|
-
const shouldLogBanner = typeof process === "undefined" || process.env
|
|
3069
|
+
const shouldLogBanner = typeof process === "undefined" || process.env.NODE_ENV !== "production" && process.env?.GUREN_DEV_BANNER !== "0";
|
|
2875
3070
|
if (shouldLogBanner) {
|
|
2876
3071
|
this.logDevServerBanner({
|
|
2877
|
-
hostname,
|
|
2878
|
-
port,
|
|
3072
|
+
hostname: boundHostname,
|
|
3073
|
+
port: boundPort,
|
|
2879
3074
|
assetsUrl: resolvedAssetsUrl ?? "http://localhost:5173"
|
|
2880
3075
|
});
|
|
2881
3076
|
}
|
|
3077
|
+
return address;
|
|
3078
|
+
}
|
|
3079
|
+
/**
|
|
3080
|
+
* The address {@link Application.listen} bound, or `undefined` before it has
|
|
3081
|
+
* been called and once this app's server has been superseded or torn down.
|
|
3082
|
+
*
|
|
3083
|
+
* The same object `listen()` returned, so callers that need the address
|
|
3084
|
+
* later — an OpenAPI `servers` entry, an absolute URL, a health report —
|
|
3085
|
+
* read it here instead of threading it out of the entrypoint.
|
|
3086
|
+
*
|
|
3087
|
+
* The stored value is preferred over re-reading the live server, because
|
|
3088
|
+
* `listen()` resolves the port through a fallback the socket no longer
|
|
3089
|
+
* carries.
|
|
3090
|
+
*
|
|
3091
|
+
* Liveness is only as good as the signal available: a server stopped through
|
|
3092
|
+
* the framework — a later `listen()`, the process-exit teardown — clears the
|
|
3093
|
+
* slot this reads, but one stopped by calling `stop()` on the Bun server
|
|
3094
|
+
* directly does not, and this keeps reporting its address. Treat it as
|
|
3095
|
+
* "where `listen()` put this app", not as a health check.
|
|
3096
|
+
*/
|
|
3097
|
+
get address() {
|
|
3098
|
+
if (!this.bunServer || getGlobalState().__gurenActiveServer !== this.bunServer) {
|
|
3099
|
+
return void 0;
|
|
3100
|
+
}
|
|
3101
|
+
return this.boundAddress;
|
|
2882
3102
|
}
|
|
2883
3103
|
/**
|
|
2884
3104
|
* Register a service provider.
|
|
@@ -2905,9 +3125,7 @@ var Application = class {
|
|
|
2905
3125
|
return;
|
|
2906
3126
|
}
|
|
2907
3127
|
try {
|
|
2908
|
-
await this.viteDevServer
|
|
2909
|
-
} catch (error) {
|
|
2910
|
-
console.error("Error while shutting down Vite dev server:", error);
|
|
3128
|
+
await closeViteDevServerBounded(this.viteDevServer);
|
|
2911
3129
|
} finally {
|
|
2912
3130
|
if (getGlobalState().__gurenActiveViteDevServer === this.viteDevServer) {
|
|
2913
3131
|
setActiveViteDevServer();
|
|
@@ -3117,17 +3335,14 @@ var Controller = class {
|
|
|
3117
3335
|
}
|
|
3118
3336
|
async inertia(componentOrPage, props, options = {}) {
|
|
3119
3337
|
const ctx = this.ctx;
|
|
3120
|
-
const { url: overrideUrl, ...rest } = options;
|
|
3121
|
-
const url2 = overrideUrl ?? ctx.req.path ?? ctx.req.url ?? "";
|
|
3122
3338
|
const component = typeof componentOrPage === "string" ? componentOrPage : componentOrPage.component ?? componentOrPage.id;
|
|
3123
3339
|
const sharedProps = await resolveSharedInertiaProps(ctx, this._container);
|
|
3124
3340
|
const propsWithShared = { ...sharedProps, ...props };
|
|
3125
3341
|
const response = await inertia(component, propsWithShared, {
|
|
3126
|
-
...
|
|
3342
|
+
...options,
|
|
3127
3343
|
// No 'en' fallback here (unlike the locale getter): unconfigured apps
|
|
3128
3344
|
// keep the Inertia engine's own default lang.
|
|
3129
|
-
lang:
|
|
3130
|
-
url: url2,
|
|
3345
|
+
lang: options.lang ?? this.#resolveLocale(),
|
|
3131
3346
|
request: ctx.req.raw
|
|
3132
3347
|
});
|
|
3133
3348
|
response.__gurenInertia = {
|
|
@@ -3772,14 +3987,18 @@ var FormRequest = class {
|
|
|
3772
3987
|
}
|
|
3773
3988
|
/**
|
|
3774
3989
|
* Get the authenticated user from the request context.
|
|
3990
|
+
*
|
|
3991
|
+
* Awaiting is load-bearing: `this.user() !== null` compiles and is always
|
|
3992
|
+
* true, because an unawaited call is a pending promise.
|
|
3775
3993
|
*/
|
|
3776
|
-
user() {
|
|
3994
|
+
async user() {
|
|
3777
3995
|
const auth = this.ctx.get(AUTH_CONTEXT_KEY);
|
|
3778
|
-
return auth?.user
|
|
3996
|
+
return await auth?.user() ?? null;
|
|
3779
3997
|
}
|
|
3780
3998
|
/**
|
|
3781
3999
|
* Handle the form request: authorize, parse body, validate, return typed data.
|
|
3782
|
-
*
|
|
4000
|
+
* Call it from a controller with the request context:
|
|
4001
|
+
* `const data = await new StorePostRequest().handle(this.ctx)`.
|
|
3783
4002
|
*/
|
|
3784
4003
|
async handle(ctx) {
|
|
3785
4004
|
this.ctx = ctx;
|
|
@@ -6795,7 +7014,7 @@ function debugErrorMiddleware() {
|
|
|
6795
7014
|
try {
|
|
6796
7015
|
await next();
|
|
6797
7016
|
} catch (err) {
|
|
6798
|
-
const isProduction = typeof process !== "undefined" && process.env
|
|
7017
|
+
const isProduction = typeof process !== "undefined" && process.env.NODE_ENV === "production";
|
|
6799
7018
|
if (isProduction) {
|
|
6800
7019
|
throw err;
|
|
6801
7020
|
}
|
|
@@ -6917,7 +7136,7 @@ function renderRequestSection(request) {
|
|
|
6917
7136
|
</section>`;
|
|
6918
7137
|
}
|
|
6919
7138
|
function renderEnvironmentSection() {
|
|
6920
|
-
const nodeEnv = typeof process !== "undefined" ? process.env
|
|
7139
|
+
const nodeEnv = typeof process !== "undefined" ? process.env.NODE_ENV ?? "undefined" : "undefined";
|
|
6921
7140
|
const bunVersion = typeof process !== "undefined" ? process.versions?.bun ?? "N/A" : "N/A";
|
|
6922
7141
|
const platform = typeof process !== "undefined" ? process.platform ?? "unknown" : "unknown";
|
|
6923
7142
|
return `
|
package/dist/redis/index.js
CHANGED
|
@@ -373,10 +373,12 @@ var RedisApiTokenStore = class {
|
|
|
373
373
|
userId: data.userId,
|
|
374
374
|
abilities: decodeAbilities(data.abilities),
|
|
375
375
|
lastUsedAt: toDate(data.lastUsedAt),
|
|
376
|
-
//
|
|
377
|
-
//
|
|
378
|
-
//
|
|
379
|
-
|
|
376
|
+
// A never-expiring token serializes `expiresAt` as '' (a Redis hash has no
|
|
377
|
+
// null), so an empty string is "absent" here, not a corrupt value. Map it
|
|
378
|
+
// to undefined before `toOptionalExpiry`, which would otherwise degrade ''
|
|
379
|
+
// to epoch and reject every non-expiring token. A genuinely unparseable
|
|
380
|
+
// value still degrades to epoch and reads as expired.
|
|
381
|
+
expiresAt: toOptionalExpiry(data.expiresAt === "" ? void 0 : data.expiresAt),
|
|
380
382
|
createdAt: toDate(data.createdAt) ?? /* @__PURE__ */ new Date(0)
|
|
381
383
|
};
|
|
382
384
|
}
|
package/dist/runtime/index.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
|
+
DEFAULT_DEV_STYLES_ENTRY,
|
|
2
3
|
GUREN_ASCII_ART,
|
|
3
4
|
logDevServerBanner,
|
|
4
5
|
parseImportMap,
|
|
5
6
|
startViteDevServer
|
|
6
|
-
} from "../chunk-
|
|
7
|
+
} from "../chunk-NENDACRP.js";
|
|
7
8
|
import {
|
|
8
9
|
trimTrailingSlashes
|
|
9
10
|
} from "../chunk-AZOYI43J.js";
|
|
@@ -354,7 +355,6 @@ import { dirname as dirname2, resolve as resolve3, join as join2 } from "path";
|
|
|
354
355
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
355
356
|
import { readFileSync } from "fs";
|
|
356
357
|
var DEFAULT_STYLES_ENTRY = "/public/assets/app.css";
|
|
357
|
-
var DEFAULT_DEV_STYLES_ENTRY = "/resources/css/app.css";
|
|
358
358
|
var DEFAULT_SCRIPT_ENTRY = "/assets/app.js";
|
|
359
359
|
var DEFAULT_VENDOR_CLIENT_PATH = "/vendor/inertia-client.tsx";
|
|
360
360
|
function configureInertiaAssets(app, options) {
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The stylesheet *source* path the dev asset configuration falls back to.
|
|
3
|
+
*
|
|
4
|
+
* Lives in a leaf module because two sides read it and must agree: the dev
|
|
5
|
+
* configuration in `http/inertia-assets.ts` publishes it into
|
|
6
|
+
* `GUREN_INERTIA_STYLES`, and the document renderer in
|
|
7
|
+
* `mvc/inertia/InertiaEngine.ts` drops exactly this path again when a dev
|
|
8
|
+
* server owns the script entry (the compiled CSS then arrives through the
|
|
9
|
+
* module graph). Importing either of those modules from the other would drag
|
|
10
|
+
* runtime-specific dependencies across the Workers/Lambda boundary or create
|
|
11
|
+
* an import cycle.
|
|
12
|
+
*/
|
|
13
|
+
export declare const DEFAULT_DEV_STYLES_ENTRY = "/resources/css/app.css";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@guren/server",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -113,7 +113,7 @@
|
|
|
113
113
|
"test": "bun test"
|
|
114
114
|
},
|
|
115
115
|
"dependencies": {
|
|
116
|
-
"@guren/orm": "^2.2.
|
|
116
|
+
"@guren/orm": "^2.2.2",
|
|
117
117
|
"@modelcontextprotocol/sdk": "^1.30.0",
|
|
118
118
|
"chalk": "^5.3.0",
|
|
119
119
|
"consola": "^3.4.2",
|