heliumts 0.8.4 → 0.8.6

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 (43) hide show
  1. package/README.md +9 -0
  2. package/dist/bin/helium.js +0 -0
  3. package/dist/client/Router.d.ts.map +1 -1
  4. package/dist/client/Router.js +35 -7
  5. package/dist/client/Router.js.map +1 -1
  6. package/dist/server/config.d.ts +21 -0
  7. package/dist/server/config.d.ts.map +1 -1
  8. package/dist/server/config.js.map +1 -1
  9. package/dist/server/defineServerSideProps.d.ts +11 -1
  10. package/dist/server/defineServerSideProps.d.ts.map +1 -1
  11. package/dist/server/defineServerSideProps.js.map +1 -1
  12. package/dist/server/devServer.d.ts.map +1 -1
  13. package/dist/server/devServer.js +41 -7
  14. package/dist/server/devServer.js.map +1 -1
  15. package/dist/server/prodServer.d.ts +7 -0
  16. package/dist/server/prodServer.d.ts.map +1 -1
  17. package/dist/server/prodServer.js +57 -16
  18. package/dist/server/prodServer.js.map +1 -1
  19. package/dist/server/serverPropsRouter.d.ts +1 -0
  20. package/dist/server/serverPropsRouter.d.ts.map +1 -0
  21. package/dist/server/serverPropsRouter.js +2 -0
  22. package/dist/server/serverPropsRouter.js.map +1 -0
  23. package/dist/server/ssr.d.ts +26 -4
  24. package/dist/server/ssr.d.ts.map +1 -1
  25. package/dist/server/ssr.js +48 -5
  26. package/dist/server/ssr.js.map +1 -1
  27. package/package.json +1 -1
  28. package/dist/server/ipExtractor.d.ts +0 -48
  29. package/dist/server/ipExtractor.d.ts.map +0 -1
  30. package/dist/server/ipExtractor.js +0 -96
  31. package/dist/server/ipExtractor.js.map +0 -1
  32. package/dist/server/requestRouting.d.ts +0 -4
  33. package/dist/server/requestRouting.d.ts.map +0 -1
  34. package/dist/server/requestRouting.js +0 -67
  35. package/dist/server/requestRouting.js.map +0 -1
  36. package/dist/utils/deepEqual.d.ts +0 -1
  37. package/dist/utils/deepEqual.d.ts.map +0 -1
  38. package/dist/utils/deepEqual.js +0 -2
  39. package/dist/utils/deepEqual.js.map +0 -1
  40. package/dist/utils/formatError.d.ts +0 -2
  41. package/dist/utils/formatError.d.ts.map +0 -1
  42. package/dist/utils/formatError.js +0 -18
  43. package/dist/utils/formatError.js.map +0 -1
package/README.md CHANGED
@@ -285,6 +285,15 @@ import type { HeliumConfig } from "heliumts/server";
285
285
 
286
286
  const config: HeliumConfig = {
287
287
  trustProxyDepth: 1, // Trust 1 proxy level (e.g., Vercel)
288
+ security: {
289
+ defaultHeaders: true,
290
+ headerOverrides: {
291
+ "X-Frame-Options": "SAMEORIGIN",
292
+ },
293
+ contentSecurityPolicy: "default-src 'self'; frame-ancestors 'self'",
294
+ hsts: true,
295
+ corsOrigins: ["https://app.example.com"],
296
+ },
288
297
  rpc: {
289
298
  encoding: "msgpack", // or "json"
290
299
  compression: {
File without changes
@@ -1 +1 @@
1
- {"version":3,"file":"Router.d.ts","sourceRoot":"","sources":["../../src/client/Router.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAC3C,OAAO,KAAuD,MAAM,OAAO,CAAC;AA2D5E,KAAK,WAAW,GAAG,YAAY,GAAG,mBAAmB,CAAC;AACtD,KAAK,aAAa,GAAG,CAAC,KAAK,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,cAAc,CAAC,EAAE,MAAM,IAAI,CAAA;CAAE,KAAK,IAAI,CAAC;AAiKhG,kDAAkD;AAClD,MAAM,WAAW,uBAAuB;IACpC,qDAAqD;IACrD,WAAW,CAAC,EAAE,OAAO,CAAC;CACzB;AAGD,KAAK,aAAa,GAAG;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC,CAAC;IAC1C,YAAY,EAAE,eAAe,CAAC;IAC9B,IAAI,EAAE,CAAC,IAAI,EAAE,MAAM,E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AC;CACtB,CAAC;AAEF,eAAO,MAAM,aAAa,qCAAkD,CAAC;AAE7E;;;;;;;;GAQG;AACH,wBAAgB,SAAS,kBAmCxB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,QAAQ,CAAC,EAAE,EAAE,EAAE,OAAe,EAAE,EAAE;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,OAAO,CAAA;CAAE,QAyBlF;AA6CD,MAAM,MAAM,SAAS,GAAG,KAAK,CAAC,iBAAiB,CAC3C,IAAI,CAAC,KAAK,CAAC,oBAAoB,CAAC,iBAAiB,CAAC,EAAE,MAAM,CAAC,GAAG;IAC1D,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,0EAA0E;IAC1E,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,qDAAqD;IACrD,WAAW,CAAC,EAAE,OAAO,CAAC;CACzB,CACJ,CAAC;AA+BF;;;;;;;;;GASG;AACH,wBAAgB,IAAI,CAAC,KAAK,EAAE,SAAS,2CA4DpC;AAGD;;;;GAIG;AACH,MAAM,MAAM,aAAa,CAAC,UAAU,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI;IAC9F,SAAS,EAAE,aAAa,CAAC,UAAU,CAAC,CAAC;IACrC,SAAS,EAAE,UAAU,CAAC;IACtB,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC9B,CAAC;AAGF,wBAAgB,SAAS,CAAC,EAAE,QAAQ,EAAE,EAAE;IAAE,QAAQ,CAAC,EAAE,aAAa,CAAC,aAAa,CAAC,CAAA;CAAE,2CA8LlF"}
@@ -24,16 +24,28 @@ async function fetchSSRPageProps(path) {
24
24
  },
25
25
  });
26
26
  if (!response.ok) {
27
- return null;
27
+ return { kind: "none" };
28
28
  }
29
29
  const payload = (await response.json());
30
- if (!payload.ssr || !payload.props) {
31
- return null;
30
+ if (!payload.ssr) {
31
+ return { kind: "none" };
32
32
  }
33
- return payload.props;
33
+ if (payload.redirect && typeof payload.redirect.destination === "string" && payload.redirect.destination.length > 0) {
34
+ return {
35
+ kind: "redirect",
36
+ redirect: payload.redirect,
37
+ };
38
+ }
39
+ if (!payload.props) {
40
+ return { kind: "none" };
41
+ }
42
+ return {
43
+ kind: "props",
44
+ props: payload.props,
45
+ };
34
46
  }
35
47
  catch {
36
- return null;
48
+ return { kind: "none" };
37
49
  }
38
50
  }
39
51
  class RouterEventEmitter {
@@ -431,11 +443,27 @@ export function AppRouter({ AppShell }) {
431
443
  }
432
444
  let cancelled = false;
433
445
  const load = async () => {
434
- const props = await fetchSSRPageProps(targetPath);
446
+ const ssrPayload = await fetchSSRPageProps(targetPath);
435
447
  if (cancelled) {
436
448
  return;
437
449
  }
438
- setRuntimeSSRProps(props ?? {});
450
+ if (ssrPayload.kind === "redirect") {
451
+ const destination = ssrPayload.redirect.destination;
452
+ if (isExternalUrl(destination)) {
453
+ window.location.assign(destination);
454
+ return;
455
+ }
456
+ navigate(destination, {
457
+ replace: ssrPayload.redirect.replace ?? true,
458
+ scrollToTop: true,
459
+ });
460
+ return;
461
+ }
462
+ if (ssrPayload.kind === "props") {
463
+ setRuntimeSSRProps(ssrPayload.props);
464
+ return;
465
+ }
466
+ setRuntimeSSRProps({});
439
467
  };
440
468
  void load();
441
469
  return () => {
@@ -1 +1 @@
1
- {"version":3,"file":"Router.js","sourceRoot":"","sources":["../../src/client/Router.tsx"],"names":[],"mappings":";AACA,OAAO,KAAK,EAAE,EAAE,OAAO,EAAE,oBAAoB,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAE5E,OAAO,EAAE,uBAAuB,EAAE,MAAM,+BAA+B,CAAC;AACxE,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAE5C,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,yBAAyB,EAAE,iB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AC,KAAK,MAAM,EAAE,CAAC;YAClD,IAAI,CAAC,MAAM,EAAE,CAAC;YACd,SAAS;QACb,CAAC;QAED,IAAI,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,KAAK,MAAM,EAAE,CAAC;YACxC,MAAM,GAAG,GAAG,CAAC,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC;YAC3D,IAAI,GAAG,KAAK,WAAW,EAAE,CAAC;gBACtB,IAAI,CAAC,MAAM,EAAE,CAAC;YAClB,CAAC;YACD,SAAS;QACb,CAAC;QAED,MAAM,IAAI,GAAG,CAAC,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC;QAC7D,MAAM,QAAQ,GAAG,CAAC,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC;QAErE,IAAI,IAAI,KAAK,aAAa,IAAI,IAAI,KAAK,QAAQ,IAAI,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;YAC7E,IAAI,CAAC,MAAM,EAAE,CAAC;YACd,SAAS;QACb,CAAC;QAED,IAAI,QAAQ,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC;YAC7B,IAAI,CAAC,MAAM,EAAE,CAAC;QAClB,CAAC;IACL,CAAC;AACL,CAAC","sourcesContent":["import type { ComponentType } from \"react\";\nimport React, { useMemo, useSyncExternalStore, useTransition } from \"react\";\n\nimport { SEO_METADATA_RPC_METHOD } from \"../runtime/internalMethods.js\";\nimport { isDevEnvironment } from \"./env.js\";\nimport type { RouteEntry } from \"./routerManifest.js\";\nimport { buildRoutes } from \"./routerManifest.js\";\nimport { isAutoHttpOnMobileEnabled, isMobileRpcDevice, rpcCallWithOptions } from \"./rpcClient.js\";\n\ntype HeliumSSRBootstrap = {\n path: string;\n props: Record<string, unknown>;\n};\n\nfunction getInitialSSRBootstrap(): HeliumSSRBootstrap | null {\n if (typeof window === \"undefined\") {\n return null;\n }\n\n const globalWindow = window as typeof window & {\n __HELIUM_SSR_DATA__?: HeliumSSRBootstrap;\n };\n\n const payload = globalWindow.__HELIUM_SSR_DATA__;\n if (!payload || typeof payload !== \"object\" || typeof payload.path !== \"string\" || typeof payload.props !== \"object\" || payload.props === null) {\n return null;\n }\n\n return payload;\n}\n\nasync function fetchSSRPageProps(path: string): Promise<Record<string, unknown> | null> {\n try {\n const response = await fetch(`/__helium__/page-props?path=${encodeURIComponent(path)}`, {\n method: \"GET\",\n headers: {\n Accept: \"application/json\",\n },\n });\n\n if (!response.ok) {\n return null;\n }\n\n const payload = (await response.json()) as {\n ssr?: boolean;\n props?: Record<string, unknown> | null;\n };\n\n if (!payload.ssr || !payload.props) {\n return null;\n }\n\n return payload.props;\n } catch {\n return null;\n }\n}\n\n// Event emitter for router events\ntype RouterEvent = \"navigation\" | \"before-navigation\";\ntype EventListener = (event: { from: string; to: string; preventDefault?: () => void }) => void;\n\nclass RouterEventEmitter {\n private listeners: Map<RouterEvent, Set<EventListener>> = new Map();\n\n on(event: RouterEvent, listener: EventListener): () => void {\n if (!this.listeners.has(event)) {\n this.listeners.set(event, new Set());\n }\n this.listeners.get(event)!.add(listener);\n\n // Return unsubscribe function\n return () => {\n this.listeners.get(event)?.delete(listener);\n };\n }\n\n emit(event: RouterEvent, data: { from: string; to: string }): boolean {\n const eventListeners = this.listeners.get(event);\n if (!eventListeners || eventListeners.size === 0) {\n return true;\n }\n\n let prevented = false;\n const preventDefault = () => {\n prevented = true;\n };\n\n const eventData = event === \"before-navigation\" ? { ...data, preventDefault } : data;\n\n eventListeners.forEach((listener) => {\n listener(eventData);\n });\n\n return !prevented;\n }\n\n // Clear all listeners - useful for HMR\n clear() {\n this.listeners.clear();\n }\n}\n\n// Use a singleton that survives HMR by attaching to window in dev mode\nlet routerEventEmitter: RouterEventEmitter;\n\nif (typeof window !== \"undefined\" && isDevEnvironment()) {\n // In dev mode, reuse the same emitter instance across HMR\n const globalWindow = window as typeof window & { __heliumRouterEmitter?: RouterEventEmitter };\n if (!globalWindow.__heliumRouterEmitter) {\n globalWindow.__heliumRouterEmitter = new RouterEventEmitter();\n }\n routerEventEmitter = globalWindow.__heliumRouterEmitter;\n} else {\n routerEventEmitter = new RouterEventEmitter();\n}\n\ntype RouterState = {\n path: string;\n searchParams: URLSearchParams;\n isNavigating: boolean;\n};\n\nfunction getLocation(): RouterState {\n const { pathname, search } = window.location;\n return {\n path: pathname,\n searchParams: new URLSearchParams(search),\n isNavigating: false,\n };\n}\n\nfunction matchRoute(path: string, routes: RouteEntry[]) {\n for (const r of routes) {\n const m = r.matcher(path);\n if (m) {\n return { params: m.params, route: r };\n }\n }\n return null;\n}\n\n// Location store for useSyncExternalStore\n// Preserve across HMR by attaching to window in dev mode\nlet currentLocation: RouterState;\nlet locationListeners: Set<() => void>;\n\nif (typeof window !== \"undefined\" && isDevEnvironment()) {\n const globalWindow = window as typeof window & {\n __heliumCurrentLocation?: RouterState;\n __heliumLocationListeners?: Set<() => void>;\n };\n if (!globalWindow.__heliumCurrentLocation) {\n globalWindow.__heliumCurrentLocation = getLocation();\n }\n if (!globalWindow.__heliumLocationListeners) {\n globalWindow.__heliumLocationListeners = new Set();\n }\n currentLocation = globalWindow.__heliumCurrentLocation;\n locationListeners = globalWindow.__heliumLocationListeners;\n} else if (typeof window !== \"undefined\") {\n currentLocation = getLocation();\n locationListeners = new Set();\n} else {\n currentLocation = { path: \"/\", searchParams: new URLSearchParams(), isNavigating: false };\n locationListeners = new Set();\n}\n\n// Helper to re-extract params from path using stored routes during HMR\nfunction extractParamsFromPath(path: string): Record<string, string | string[]> {\n if (typeof window !== \"undefined\" && isDevEnvironment()) {\n const globalWindow = window as typeof window & { __heliumGlobalRoutes?: RouteEntry[] };\n const routes = globalWindow.__heliumGlobalRoutes;\n if (routes && routes.length > 0) {\n const match = matchRoute(path, routes);\n if (match) {\n return match.params;\n }\n }\n }\n return {};\n}\n\nfunction subscribeToLocation(callback: () => void) {\n locationListeners.add(callback);\n return () => locationListeners.delete(callback);\n}\n\nfunction getLocationSnapshot() {\n return currentLocation;\n}\n\nconst SERVER_SNAPSHOT: RouterState = { path: \"/\", searchParams: new URLSearchParams(), isNavigating: false };\nfunction getServerSnapshot() {\n return SERVER_SNAPSHOT;\n}\n\nfunction updateLocation(isNavigating = false) {\n const newLocation = { ...getLocation(), isNavigating };\n currentLocation = newLocation;\n // Update the global reference in dev mode\n if (typeof window !== \"undefined\" && isDevEnvironment()) {\n (window as typeof window & { __heliumCurrentLocation?: RouterState }).__heliumCurrentLocation = newLocation;\n }\n locationListeners.forEach((listener) => listener());\n}\n\n// Set up global listeners once\nif (typeof window !== \"undefined\") {\n // Only set up once, survives HMR\n const globalWindow = window as typeof window & { __heliumLocationListenerSetup?: boolean };\n if (!globalWindow.__heliumLocationListenerSetup) {\n globalWindow.__heliumLocationListenerSetup = true;\n\n window.addEventListener(\"popstate\", () => updateLocation(false));\n\n // Also listen to navigation events from the emitter\n routerEventEmitter.on(\"navigation\", () => updateLocation(false));\n }\n}\n\n/** Options for push/replace navigation methods */\nexport interface RouterNavigationOptions {\n /** Scroll to top after navigation (default: true) */\n scrollToTop?: boolean;\n}\n\n// Context for useRouter hook\ntype RouterContext = {\n path: string;\n params: Record<string, string | string[]>;\n searchParams: URLSearchParams;\n push: (href: string, options?: RouterNavigationOptions) => void;\n replace: (href: string, options?: RouterNavigationOptions) => void;\n on: (event: RouterEvent, listener: EventListener) => () => void;\n status: 200 | 404;\n isNavigating: boolean;\n /** Indicates content is stale (old content shown while new content renders) - React 18+ concurrent feature */\n isPending: boolean;\n};\n\nexport const RouterContext = React.createContext<RouterContext | null>(null);\n\n/**\n * Access router context inside a component tree managed by <AppRouter />.\n *\n * Provides current path, route params, URL search params and navigation helpers\n * (\\`push\\`, \\`replace\\`) as well as an \\`on\\` method to subscribe to navigation events.\n * The \\`isNavigating\\` property indicates when a navigation is in progress.\n * The \\`isPending\\` property indicates when content is stale (React concurrent features).\n * Throws when used outside of an <AppRouter /> provider.\n */\nexport function useRouter() {\n const ctx = React.useContext(RouterContext);\n if (!ctx) {\n // During HMR in development, context might be temporarily unavailable\n // Provide a temporary fallback to prevent white screen of death\n // Re-extract params from current path using stored routes\n if (typeof window !== \"undefined\" && isDevEnvironment()) {\n const currentPath = window.location.pathname;\n return {\n path: currentPath,\n params: extractParamsFromPath(currentPath),\n searchParams: new URLSearchParams(window.location.search),\n push: (href: string, options?: RouterNavigationOptions) => {\n window.history.pushState({}, \"\", href);\n if (options?.scrollToTop !== false) {\n window.scrollTo({ top: 0, left: 0, behavior: \"smooth\" });\n }\n window.dispatchEvent(new PopStateEvent(\"popstate\"));\n },\n replace: (href: string, options?: RouterNavigationOptions) => {\n window.history.replaceState({}, \"\", href);\n if (options?.scrollToTop !== false) {\n window.scrollTo({ top: 0, left: 0, behavior: \"smooth\" });\n }\n window.dispatchEvent(new PopStateEvent(\"popstate\"));\n },\n on: () => () => {},\n status: 200 as const,\n isNavigating: false,\n isPending: false,\n };\n }\n throw new Error(\"useRouter must be used inside <AppRouter>\");\n }\n return ctx;\n}\n\n/**\n * Redirect component for declarative navigation.\n * Use this instead of calling router.push() during render.\n *\n * @example\n * \\`\\`\\`tsx\n * export default function Docs() {\n * return <Redirect to=\"/docs/getting-started\" />;\n * }\n * \\`\\`\\`\n */\nexport function Redirect({ to, replace = false }: { to: string; replace?: boolean }) {\n const hasRedirected = React.useRef(false);\n\n // Use useLayoutEffect to redirect before paint\n React.useLayoutEffect(() => {\n const targetPath = to.split(\"?\")[0];\n if (!hasRedirected.current && window.location.pathname !== targetPath) {\n hasRedirected.current = true;\n\n // Perform navigation\n if (replace) {\n window.history.replaceState(null, \"\", to);\n } else {\n window.history.pushState(null, \"\", to);\n }\n\n // Emit navigation event to update router state\n routerEventEmitter.emit(\"navigation\", {\n from: window.location.pathname,\n to: targetPath,\n });\n }\n }, [to, replace]);\n\n return null;\n}\n\n/** Options for navigation */\ninterface NavigateOptions {\n replace?: boolean;\n scrollToTop?: boolean;\n}\n\n// Navigation helper\nfunction navigate(href: string, options: NavigateOptions = {}) {\n const { replace = false, scrollToTop = true } = options;\n const from = window.location.pathname;\n const to = href.split(\"?\")[0]; // Extract pathname from href\n\n // Emit before-navigation event (can be prevented)\n const canNavigate = routerEventEmitter.emit(\"before-navigation\", { from, to });\n if (!canNavigate) {\n return; // Navigation was prevented\n }\n\n // Set navigating state to true before navigation\n currentLocation = { ...currentLocation, isNavigating: true };\n locationListeners.forEach((listener) => listener());\n\n if (replace) {\n window.history.replaceState(null, \"\", href);\n } else {\n window.history.pushState(null, \"\", href);\n }\n\n // Scroll to top immediately after pushState, before React re-renders.\n // Using instant scroll avoids race conditions where smooth scrolling\n // gets interrupted by React DOM updates, especially on Safari mobile.\n if (scrollToTop) {\n window.scrollTo({ top: 0, left: 0, behavior: \"instant\" });\n }\n\n // Update location state synchronously so there is no stale-state window\n // between pushState and the next render.\n updateLocation(false);\n\n // Emit navigation event after state is consistent\n routerEventEmitter.emit(\"navigation\", { from, to });\n}\n\nexport type LinkProps = React.PropsWithChildren<\n Omit<React.AnchorHTMLAttributes<HTMLAnchorElement>, \"href\"> & {\n href: string;\n replace?: boolean;\n /** Disable prefetching on hover (default: false - prefetch is enabled) */\n prefetch?: boolean;\n /** Scroll to top after navigation (default: true) */\n scrollToTop?: boolean;\n }\n>;\n\n/**\n * Check if a URL is external (different origin).\n */\nfunction isExternalUrl(href: string): boolean {\n if (typeof window === \"undefined\") {\n return false;\n }\n try {\n const url = new URL(href, window.location.origin);\n return url.origin !== window.location.origin;\n } catch {\n return false;\n }\n}\n\n// Store routes globally for prefetching (set by AppRouter)\n// Preserve across HMR in dev mode\nlet globalRoutes: RouteEntry[];\n\nif (typeof window !== \"undefined\" && isDevEnvironment()) {\n const globalWindow = window as typeof window & { __heliumGlobalRoutes?: RouteEntry[] };\n if (!globalWindow.__heliumGlobalRoutes) {\n globalWindow.__heliumGlobalRoutes = [];\n }\n globalRoutes = globalWindow.__heliumGlobalRoutes;\n} else {\n globalRoutes = [];\n}\n\n/**\n * Client-side navigation link.\n *\n * Intercepts left-clicks and uses the router's navigation helpers for SPA\n * navigation. Keeps normal anchor behaviour when modifier keys are used,\n * when the link is external, or when `target` / `download` attributes\n * are present.\n *\n * Automatically prefetches page chunks on hover for faster navigation.\n */\nexport function Link(props: LinkProps) {\n const {\n children,\n href,\n className,\n prefetch: prefetchProp = true,\n scrollToTop = true,\n replace: replaceProp,\n target,\n download,\n onClick: userOnClick,\n onMouseEnter: userOnMouseEnter,\n onFocus: userOnFocus,\n ...restProps\n } = props;\n\n const onClick = (e: React.MouseEvent<HTMLAnchorElement>) => {\n // Let user's onClick run first so they can call e.preventDefault()\n userOnClick?.(e);\n\n if (\n e.defaultPrevented ||\n e.button !== 0 || // only left click\n e.metaKey ||\n e.ctrlKey ||\n e.shiftKey ||\n e.altKey ||\n target || // let browser handle target=\"_blank\" etc.\n download != null || // let browser handle downloads\n isExternalUrl(href) // let browser handle external links\n ) {\n return;\n }\n e.preventDefault();\n navigate(href, { replace: replaceProp, scrollToTop });\n };\n\n const onMouseEnter = async (e: React.MouseEvent<HTMLAnchorElement>) => {\n // Prefetch the route on hover if enabled and not external (lazy-load prefetch logic)\n if (prefetchProp && !isExternalUrl(href) && globalRoutes.length > 0) {\n const { prefetchRoute } = await import(\"./prefetch.js\");\n prefetchRoute(href, globalRoutes);\n }\n userOnMouseEnter?.(e);\n };\n\n const onFocus = async (e: React.FocusEvent<HTMLAnchorElement>) => {\n // Also prefetch on focus (keyboard navigation)\n if (prefetchProp && !isExternalUrl(href) && globalRoutes.length > 0) {\n const { prefetchRoute } = await import(\"./prefetch.js\");\n prefetchRoute(href, globalRoutes);\n }\n userOnFocus?.(e);\n };\n\n return (\n <a {...restProps} href={href} target={target} download={download} onClick={onClick} onMouseEnter={onMouseEnter} onFocus={onFocus} className={className}>\n {children}\n </a>\n );\n}\n\n// AppShell props type\n/**\n * Props passed to an optional \\`AppShell\\` wrapper component used by <AppRouter />.\n *\n * \\`Component\\` — the page component to render. \\`pageProps\\` — props provided to the page.\n */\nexport type AppShellProps<TPageProps extends Record<string, unknown> = Record<string, unknown>> = {\n Component: ComponentType<TPageProps>;\n pageProps: TPageProps;\n children?: React.ReactNode;\n};\n\n// Main router component\nexport function AppRouter({ AppShell }: { AppShell?: ComponentType<AppShellProps> }) {\n // useTransition for concurrent rendering - allows React to keep UI responsive during navigation\n const [isPending, startTransition] = useTransition();\n\n // Build routes once on mount (client-side only)\n const { routes, NotFound } = useMemo(() => {\n if (typeof window === \"undefined\") {\n return { routes: [], NotFound: undefined };\n }\n const result = buildRoutes();\n // Store routes globally for Link prefetching\n // In dev mode, also update the global reference to survive HMR\n if (isDevEnvironment()) {\n const globalWindow = window as typeof window & { __heliumGlobalRoutes?: RouteEntry[] };\n globalWindow.__heliumGlobalRoutes = result.routes;\n // Update the module-level reference as well\n globalRoutes.length = 0;\n globalRoutes.push(...result.routes);\n } else {\n globalRoutes = result.routes;\n }\n return result;\n }, []);\n\n // Use useSyncExternalStore to subscribe to location changes\n // This ensures synchronous updates when location changes\n const state = useSyncExternalStore(subscribeToLocation, getLocationSnapshot, getServerSnapshot);\n const [runtimeSSRProps, setRuntimeSSRProps] = React.useState<Record<string, unknown>>(() => {\n const payload = getInitialSSRBootstrap();\n if (!payload) {\n return {};\n }\n\n if (payload.path === window.location.pathname) {\n return payload.props;\n }\n\n return {};\n });\n const [hydrationDone, setHydrationDone] = React.useState(false);\n\n const match = useMemo(() => matchRoute(state.path, routes), [state.path, routes]);\n\n // Use matched params, or fall back to re-extracting from path using global routes during HMR\n const currentParams = match?.params ?? (isDevEnvironment() ? extractParamsFromPath(state.path) : {});\n\n // In dev mode, always read fresh searchParams from URL to handle HMR edge cases\n const currentSearchParams = isDevEnvironment() ? new URLSearchParams(window.location.search) : state.searchParams;\n\n const routerValue: RouterContext = {\n path: state.path,\n params: currentParams,\n searchParams: currentSearchParams,\n push: (href, options) => {\n // Wrap navigation in startTransition for smoother updates\n startTransition(() => {\n navigate(href, { scrollToTop: options?.scrollToTop });\n });\n },\n replace: (href, options) => {\n startTransition(() => {\n navigate(href, { replace: true, scrollToTop: options?.scrollToTop });\n });\n },\n on: (event, listener) => routerEventEmitter.on(event, listener),\n status: match ? 200 : 404,\n isNavigating: state.isNavigating,\n isPending,\n };\n\n React.useEffect(() => {\n const targetPath = `${state.path}${window.location.search || \"\"}`;\n\n // On first client render, if SSR payload already exists for this path, keep it.\n if (!hydrationDone) {\n const bootstrap = getInitialSSRBootstrap();\n if (bootstrap && bootstrap.path === state.path) {\n setHydrationDone(true);\n return;\n }\n setHydrationDone(true);\n }\n\n let cancelled = false;\n\n const load = async () => {\n const props = await fetchSSRPageProps(targetPath);\n if (cancelled) {\n return;\n }\n\n setRuntimeSSRProps(props ?? {});\n };\n\n void load();\n\n return () => {\n cancelled = true;\n };\n }, [state.path, currentSearchParams.toString(), hydrationDone]);\n\n React.useEffect(() => {\n const controller = new AbortController();\n const targetPath = `${state.path}${window.location.search || \"\"}`;\n\n const syncMetadata = async () => {\n try {\n if (controller.signal.aborted) {\n return;\n }\n\n const result = await rpcCallWithOptions<ClientSocialMeta | null, { path: string }>(\n SEO_METADATA_RPC_METHOD,\n { path: targetPath },\n {\n forceHttp: isAutoHttpOnMobileEnabled() && isMobileRpcDevice(),\n }\n );\n\n if (controller.signal.aborted) {\n return;\n }\n\n applyRouteMetadata(result.data ?? null);\n } catch (error) {\n if ((error as { name?: string })?.name === \"AbortError\") {\n return;\n }\n }\n };\n\n syncMetadata();\n\n return () => controller.abort();\n }, [state.path, currentSearchParams.toString()]);\n\n if (!match) {\n const NotFoundComp = NotFound ?? (() => <div>Not found</div>);\n const content = <NotFoundComp />;\n\n return <RouterContext.Provider value={routerValue}>{AppShell ? <AppShell Component={NotFoundComp} pageProps={{}} /> : content}</RouterContext.Provider>;\n }\n\n const Page = match.route.Component as ComponentType<{ params: Record<string, string | string[]>; searchParams: URLSearchParams }>;\n const pageProps = {\n ...runtimeSSRProps,\n params: match.params,\n searchParams: currentSearchParams,\n };\n\n // Create a wrapped component that includes all layouts\n const WrappedPage = () => {\n let content = <Page {...pageProps} />;\n // Wrap page with layouts (from outer to inner)\n for (let i = match.route.layouts.length - 1; i >= 0; i--) {\n const Layout = match.route.layouts[i];\n content = <Layout>{content}</Layout>;\n }\n return content;\n };\n\n const finalContent = AppShell ? (\n <AppShell Component={WrappedPage} pageProps={pageProps}>\n <WrappedPage />\n </AppShell>\n ) : (\n <WrappedPage />\n );\n\n return <RouterContext.Provider value={routerValue}>{finalContent}</RouterContext.Provider>;\n}\n\ntype ClientSocialMeta = {\n title: string;\n description?: string;\n image?: string;\n canonicalUrl?: string;\n siteName?: string;\n type?: string;\n robots?: string;\n twitterCard?: \"summary\" | \"summary_large_image\" | \"app\" | \"player\";\n twitterSite?: string;\n twitterCreator?: string;\n};\n\nfunction applyRouteMetadata(meta: ClientSocialMeta | null) {\n if (typeof document === \"undefined\") {\n return;\n }\n\n removeExistingSeoTags();\n\n if (!meta) {\n return;\n }\n\n document.title = meta.title;\n\n const entries: Array<{ tag: \"meta\" | \"link\"; attrs: Record<string, string> }> = [];\n\n entries.push({ tag: \"meta\", attrs: { property: \"og:title\", content: meta.title } });\n entries.push({ tag: \"meta\", attrs: { property: \"og:type\", content: meta.type ?? \"website\" } });\n entries.push({ tag: \"meta\", attrs: { name: \"twitter:card\", content: meta.twitterCard ?? \"summary_large_image\" } });\n entries.push({ tag: \"meta\", attrs: { name: \"twitter:title\", content: meta.title } });\n\n if (meta.description) {\n entries.push({ tag: \"meta\", attrs: { name: \"description\", content: meta.description } });\n entries.push({ tag: \"meta\", attrs: { property: \"og:description\", content: meta.description } });\n entries.push({ tag: \"meta\", attrs: { name: \"twitter:description\", content: meta.description } });\n }\n\n if (meta.image) {\n entries.push({ tag: \"meta\", attrs: { property: \"og:image\", content: meta.image } });\n entries.push({ tag: \"meta\", attrs: { name: \"twitter:image\", content: meta.image } });\n }\n\n if (meta.canonicalUrl) {\n entries.push({ tag: \"meta\", attrs: { property: \"og:url\", content: meta.canonicalUrl } });\n entries.push({ tag: \"link\", attrs: { rel: \"canonical\", href: meta.canonicalUrl } });\n }\n\n if (meta.siteName) {\n entries.push({ tag: \"meta\", attrs: { property: \"og:site_name\", content: meta.siteName } });\n }\n\n if (meta.robots) {\n entries.push({ tag: \"meta\", attrs: { name: \"robots\", content: meta.robots } });\n }\n\n if (meta.twitterSite) {\n entries.push({ tag: \"meta\", attrs: { name: \"twitter:site\", content: meta.twitterSite } });\n }\n\n if (meta.twitterCreator) {\n entries.push({ tag: \"meta\", attrs: { name: \"twitter:creator\", content: meta.twitterCreator } });\n }\n\n for (const entry of entries) {\n const node = document.createElement(entry.tag);\n for (const [key, value] of Object.entries(entry.attrs)) {\n node.setAttribute(key, value);\n }\n node.setAttribute(\"data-helium-seo\", \"true\");\n document.head.appendChild(node);\n }\n}\n\nfunction removeExistingSeoTags() {\n const headNodes = Array.from(document.head.querySelectorAll(\"meta, link\"));\n\n for (const node of headNodes) {\n if (node.getAttribute(\"data-helium-seo\") === \"true\") {\n node.remove();\n continue;\n }\n\n if (node.tagName.toLowerCase() === \"link\") {\n const rel = (node.getAttribute(\"rel\") || \"\").toLowerCase();\n if (rel === \"canonical\") {\n node.remove();\n }\n continue;\n }\n\n const name = (node.getAttribute(\"name\") || \"\").toLowerCase();\n const property = (node.getAttribute(\"property\") || \"\").toLowerCase();\n\n if (name === \"description\" || name === \"robots\" || name.startsWith(\"twitter:\")) {\n node.remove();\n continue;\n }\n\n if (property.startsWith(\"og:\")) {\n node.remove();\n }\n }\n}\n"]}
1
+ {"version":3,"file":"Router.js","sourceRoot":"","sources":["../../src/client/Router.tsx"],"names":[],"mappings":";AACA,OAAO,KAAK,EAAE,EAAE,OAAO,EAAE,oBAAoB,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAE5E,OAAO,EAAE,uBAAuB,EAAE,MAAM,+BAA+B,CAAC;A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,CAAC,OAAO,CAAC,WAAW,EAAE,KAAK,MAAM,EAAE,CAAC;YACxC,MAAM,GAAG,GAAG,CAAC,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC;YAC3D,IAAI,GAAG,KAAK,WAAW,EAAE,CAAC;gBACtB,IAAI,CAAC,MAAM,EAAE,CAAC;YAClB,CAAC;YACD,SAAS;QACb,CAAC;QAED,MAAM,IAAI,GAAG,CAAC,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC;QAC7D,MAAM,QAAQ,GAAG,CAAC,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC;QAErE,IAAI,IAAI,KAAK,aAAa,IAAI,IAAI,KAAK,QAAQ,IAAI,IAAI,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;YAC7E,IAAI,CAAC,MAAM,EAAE,CAAC;YACd,SAAS;QACb,CAAC;QAED,IAAI,QAAQ,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC;YAC7B,IAAI,CAAC,MAAM,EAAE,CAAC;QAClB,CAAC;IACL,CAAC;AACL,CAAC","sourcesContent":["import type { ComponentType } from \"react\";\nimport React, { useMemo, useSyncExternalStore, useTransition } from \"react\";\n\nimport { SEO_METADATA_RPC_METHOD } from \"../runtime/internalMethods.js\";\nimport { isDevEnvironment } from \"./env.js\";\nimport type { RouteEntry } from \"./routerManifest.js\";\nimport { buildRoutes } from \"./routerManifest.js\";\nimport { isAutoHttpOnMobileEnabled, isMobileRpcDevice, rpcCallWithOptions } from \"./rpcClient.js\";\n\ntype HeliumSSRBootstrap = {\n path: string;\n props: Record<string, unknown>;\n};\n\ntype SSRRedirectPayload = {\n destination: string;\n statusCode?: 301 | 302 | 303 | 307 | 308;\n replace?: boolean;\n};\n\ntype SSRPagePropsPayload =\n | {\n kind: \"props\";\n props: Record<string, unknown>;\n }\n | {\n kind: \"redirect\";\n redirect: SSRRedirectPayload;\n }\n | {\n kind: \"none\";\n };\n\nfunction getInitialSSRBootstrap(): HeliumSSRBootstrap | null {\n if (typeof window === \"undefined\") {\n return null;\n }\n\n const globalWindow = window as typeof window & {\n __HELIUM_SSR_DATA__?: HeliumSSRBootstrap;\n };\n\n const payload = globalWindow.__HELIUM_SSR_DATA__;\n if (!payload || typeof payload !== \"object\" || typeof payload.path !== \"string\" || typeof payload.props !== \"object\" || payload.props === null) {\n return null;\n }\n\n return payload;\n}\n\nasync function fetchSSRPageProps(path: string): Promise<SSRPagePropsPayload> {\n try {\n const response = await fetch(`/__helium__/page-props?path=${encodeURIComponent(path)}`, {\n method: \"GET\",\n headers: {\n Accept: \"application/json\",\n },\n });\n\n if (!response.ok) {\n return { kind: \"none\" };\n }\n\n const payload = (await response.json()) as {\n ssr?: boolean;\n props?: Record<string, unknown> | null;\n redirect?: SSRRedirectPayload;\n };\n\n if (!payload.ssr) {\n return { kind: \"none\" };\n }\n\n if (payload.redirect && typeof payload.redirect.destination === \"string\" && payload.redirect.destination.length > 0) {\n return {\n kind: \"redirect\",\n redirect: payload.redirect,\n };\n }\n\n if (!payload.props) {\n return { kind: \"none\" };\n }\n\n return {\n kind: \"props\",\n props: payload.props,\n };\n } catch {\n return { kind: \"none\" };\n }\n}\n\n// Event emitter for router events\ntype RouterEvent = \"navigation\" | \"before-navigation\";\ntype EventListener = (event: { from: string; to: string; preventDefault?: () => void }) => void;\n\nclass RouterEventEmitter {\n private listeners: Map<RouterEvent, Set<EventListener>> = new Map();\n\n on(event: RouterEvent, listener: EventListener): () => void {\n if (!this.listeners.has(event)) {\n this.listeners.set(event, new Set());\n }\n this.listeners.get(event)!.add(listener);\n\n // Return unsubscribe function\n return () => {\n this.listeners.get(event)?.delete(listener);\n };\n }\n\n emit(event: RouterEvent, data: { from: string; to: string }): boolean {\n const eventListeners = this.listeners.get(event);\n if (!eventListeners || eventListeners.size === 0) {\n return true;\n }\n\n let prevented = false;\n const preventDefault = () => {\n prevented = true;\n };\n\n const eventData = event === \"before-navigation\" ? { ...data, preventDefault } : data;\n\n eventListeners.forEach((listener) => {\n listener(eventData);\n });\n\n return !prevented;\n }\n\n // Clear all listeners - useful for HMR\n clear() {\n this.listeners.clear();\n }\n}\n\n// Use a singleton that survives HMR by attaching to window in dev mode\nlet routerEventEmitter: RouterEventEmitter;\n\nif (typeof window !== \"undefined\" && isDevEnvironment()) {\n // In dev mode, reuse the same emitter instance across HMR\n const globalWindow = window as typeof window & { __heliumRouterEmitter?: RouterEventEmitter };\n if (!globalWindow.__heliumRouterEmitter) {\n globalWindow.__heliumRouterEmitter = new RouterEventEmitter();\n }\n routerEventEmitter = globalWindow.__heliumRouterEmitter;\n} else {\n routerEventEmitter = new RouterEventEmitter();\n}\n\ntype RouterState = {\n path: string;\n searchParams: URLSearchParams;\n isNavigating: boolean;\n};\n\nfunction getLocation(): RouterState {\n const { pathname, search } = window.location;\n return {\n path: pathname,\n searchParams: new URLSearchParams(search),\n isNavigating: false,\n };\n}\n\nfunction matchRoute(path: string, routes: RouteEntry[]) {\n for (const r of routes) {\n const m = r.matcher(path);\n if (m) {\n return { params: m.params, route: r };\n }\n }\n return null;\n}\n\n// Location store for useSyncExternalStore\n// Preserve across HMR by attaching to window in dev mode\nlet currentLocation: RouterState;\nlet locationListeners: Set<() => void>;\n\nif (typeof window !== \"undefined\" && isDevEnvironment()) {\n const globalWindow = window as typeof window & {\n __heliumCurrentLocation?: RouterState;\n __heliumLocationListeners?: Set<() => void>;\n };\n if (!globalWindow.__heliumCurrentLocation) {\n globalWindow.__heliumCurrentLocation = getLocation();\n }\n if (!globalWindow.__heliumLocationListeners) {\n globalWindow.__heliumLocationListeners = new Set();\n }\n currentLocation = globalWindow.__heliumCurrentLocation;\n locationListeners = globalWindow.__heliumLocationListeners;\n} else if (typeof window !== \"undefined\") {\n currentLocation = getLocation();\n locationListeners = new Set();\n} else {\n currentLocation = { path: \"/\", searchParams: new URLSearchParams(), isNavigating: false };\n locationListeners = new Set();\n}\n\n// Helper to re-extract params from path using stored routes during HMR\nfunction extractParamsFromPath(path: string): Record<string, string | string[]> {\n if (typeof window !== \"undefined\" && isDevEnvironment()) {\n const globalWindow = window as typeof window & { __heliumGlobalRoutes?: RouteEntry[] };\n const routes = globalWindow.__heliumGlobalRoutes;\n if (routes && routes.length > 0) {\n const match = matchRoute(path, routes);\n if (match) {\n return match.params;\n }\n }\n }\n return {};\n}\n\nfunction subscribeToLocation(callback: () => void) {\n locationListeners.add(callback);\n return () => locationListeners.delete(callback);\n}\n\nfunction getLocationSnapshot() {\n return currentLocation;\n}\n\nconst SERVER_SNAPSHOT: RouterState = { path: \"/\", searchParams: new URLSearchParams(), isNavigating: false };\nfunction getServerSnapshot() {\n return SERVER_SNAPSHOT;\n}\n\nfunction updateLocation(isNavigating = false) {\n const newLocation = { ...getLocation(), isNavigating };\n currentLocation = newLocation;\n // Update the global reference in dev mode\n if (typeof window !== \"undefined\" && isDevEnvironment()) {\n (window as typeof window & { __heliumCurrentLocation?: RouterState }).__heliumCurrentLocation = newLocation;\n }\n locationListeners.forEach((listener) => listener());\n}\n\n// Set up global listeners once\nif (typeof window !== \"undefined\") {\n // Only set up once, survives HMR\n const globalWindow = window as typeof window & { __heliumLocationListenerSetup?: boolean };\n if (!globalWindow.__heliumLocationListenerSetup) {\n globalWindow.__heliumLocationListenerSetup = true;\n\n window.addEventListener(\"popstate\", () => updateLocation(false));\n\n // Also listen to navigation events from the emitter\n routerEventEmitter.on(\"navigation\", () => updateLocation(false));\n }\n}\n\n/** Options for push/replace navigation methods */\nexport interface RouterNavigationOptions {\n /** Scroll to top after navigation (default: true) */\n scrollToTop?: boolean;\n}\n\n// Context for useRouter hook\ntype RouterContext = {\n path: string;\n params: Record<string, string | string[]>;\n searchParams: URLSearchParams;\n push: (href: string, options?: RouterNavigationOptions) => void;\n replace: (href: string, options?: RouterNavigationOptions) => void;\n on: (event: RouterEvent, listener: EventListener) => () => void;\n status: 200 | 404;\n isNavigating: boolean;\n /** Indicates content is stale (old content shown while new content renders) - React 18+ concurrent feature */\n isPending: boolean;\n};\n\nexport const RouterContext = React.createContext<RouterContext | null>(null);\n\n/**\n * Access router context inside a component tree managed by <AppRouter />.\n *\n * Provides current path, route params, URL search params and navigation helpers\n * (\\`push\\`, \\`replace\\`) as well as an \\`on\\` method to subscribe to navigation events.\n * The \\`isNavigating\\` property indicates when a navigation is in progress.\n * The \\`isPending\\` property indicates when content is stale (React concurrent features).\n * Throws when used outside of an <AppRouter /> provider.\n */\nexport function useRouter() {\n const ctx = React.useContext(RouterContext);\n if (!ctx) {\n // During HMR in development, context might be temporarily unavailable\n // Provide a temporary fallback to prevent white screen of death\n // Re-extract params from current path using stored routes\n if (typeof window !== \"undefined\" && isDevEnvironment()) {\n const currentPath = window.location.pathname;\n return {\n path: currentPath,\n params: extractParamsFromPath(currentPath),\n searchParams: new URLSearchParams(window.location.search),\n push: (href: string, options?: RouterNavigationOptions) => {\n window.history.pushState({}, \"\", href);\n if (options?.scrollToTop !== false) {\n window.scrollTo({ top: 0, left: 0, behavior: \"smooth\" });\n }\n window.dispatchEvent(new PopStateEvent(\"popstate\"));\n },\n replace: (href: string, options?: RouterNavigationOptions) => {\n window.history.replaceState({}, \"\", href);\n if (options?.scrollToTop !== false) {\n window.scrollTo({ top: 0, left: 0, behavior: \"smooth\" });\n }\n window.dispatchEvent(new PopStateEvent(\"popstate\"));\n },\n on: () => () => {},\n status: 200 as const,\n isNavigating: false,\n isPending: false,\n };\n }\n throw new Error(\"useRouter must be used inside <AppRouter>\");\n }\n return ctx;\n}\n\n/**\n * Redirect component for declarative navigation.\n * Use this instead of calling router.push() during render.\n *\n * @example\n * \\`\\`\\`tsx\n * export default function Docs() {\n * return <Redirect to=\"/docs/getting-started\" />;\n * }\n * \\`\\`\\`\n */\nexport function Redirect({ to, replace = false }: { to: string; replace?: boolean }) {\n const hasRedirected = React.useRef(false);\n\n // Use useLayoutEffect to redirect before paint\n React.useLayoutEffect(() => {\n const targetPath = to.split(\"?\")[0];\n if (!hasRedirected.current && window.location.pathname !== targetPath) {\n hasRedirected.current = true;\n\n // Perform navigation\n if (replace) {\n window.history.replaceState(null, \"\", to);\n } else {\n window.history.pushState(null, \"\", to);\n }\n\n // Emit navigation event to update router state\n routerEventEmitter.emit(\"navigation\", {\n from: window.location.pathname,\n to: targetPath,\n });\n }\n }, [to, replace]);\n\n return null;\n}\n\n/** Options for navigation */\ninterface NavigateOptions {\n replace?: boolean;\n scrollToTop?: boolean;\n}\n\n// Navigation helper\nfunction navigate(href: string, options: NavigateOptions = {}) {\n const { replace = false, scrollToTop = true } = options;\n const from = window.location.pathname;\n const to = href.split(\"?\")[0]; // Extract pathname from href\n\n // Emit before-navigation event (can be prevented)\n const canNavigate = routerEventEmitter.emit(\"before-navigation\", { from, to });\n if (!canNavigate) {\n return; // Navigation was prevented\n }\n\n // Set navigating state to true before navigation\n currentLocation = { ...currentLocation, isNavigating: true };\n locationListeners.forEach((listener) => listener());\n\n if (replace) {\n window.history.replaceState(null, \"\", href);\n } else {\n window.history.pushState(null, \"\", href);\n }\n\n // Scroll to top immediately after pushState, before React re-renders.\n // Using instant scroll avoids race conditions where smooth scrolling\n // gets interrupted by React DOM updates, especially on Safari mobile.\n if (scrollToTop) {\n window.scrollTo({ top: 0, left: 0, behavior: \"instant\" });\n }\n\n // Update location state synchronously so there is no stale-state window\n // between pushState and the next render.\n updateLocation(false);\n\n // Emit navigation event after state is consistent\n routerEventEmitter.emit(\"navigation\", { from, to });\n}\n\nexport type LinkProps = React.PropsWithChildren<\n Omit<React.AnchorHTMLAttributes<HTMLAnchorElement>, \"href\"> & {\n href: string;\n replace?: boolean;\n /** Disable prefetching on hover (default: false - prefetch is enabled) */\n prefetch?: boolean;\n /** Scroll to top after navigation (default: true) */\n scrollToTop?: boolean;\n }\n>;\n\n/**\n * Check if a URL is external (different origin).\n */\nfunction isExternalUrl(href: string): boolean {\n if (typeof window === \"undefined\") {\n return false;\n }\n try {\n const url = new URL(href, window.location.origin);\n return url.origin !== window.location.origin;\n } catch {\n return false;\n }\n}\n\n// Store routes globally for prefetching (set by AppRouter)\n// Preserve across HMR in dev mode\nlet globalRoutes: RouteEntry[];\n\nif (typeof window !== \"undefined\" && isDevEnvironment()) {\n const globalWindow = window as typeof window & { __heliumGlobalRoutes?: RouteEntry[] };\n if (!globalWindow.__heliumGlobalRoutes) {\n globalWindow.__heliumGlobalRoutes = [];\n }\n globalRoutes = globalWindow.__heliumGlobalRoutes;\n} else {\n globalRoutes = [];\n}\n\n/**\n * Client-side navigation link.\n *\n * Intercepts left-clicks and uses the router's navigation helpers for SPA\n * navigation. Keeps normal anchor behaviour when modifier keys are used,\n * when the link is external, or when `target` / `download` attributes\n * are present.\n *\n * Automatically prefetches page chunks on hover for faster navigation.\n */\nexport function Link(props: LinkProps) {\n const {\n children,\n href,\n className,\n prefetch: prefetchProp = true,\n scrollToTop = true,\n replace: replaceProp,\n target,\n download,\n onClick: userOnClick,\n onMouseEnter: userOnMouseEnter,\n onFocus: userOnFocus,\n ...restProps\n } = props;\n\n const onClick = (e: React.MouseEvent<HTMLAnchorElement>) => {\n // Let user's onClick run first so they can call e.preventDefault()\n userOnClick?.(e);\n\n if (\n e.defaultPrevented ||\n e.button !== 0 || // only left click\n e.metaKey ||\n e.ctrlKey ||\n e.shiftKey ||\n e.altKey ||\n target || // let browser handle target=\"_blank\" etc.\n download != null || // let browser handle downloads\n isExternalUrl(href) // let browser handle external links\n ) {\n return;\n }\n e.preventDefault();\n navigate(href, { replace: replaceProp, scrollToTop });\n };\n\n const onMouseEnter = async (e: React.MouseEvent<HTMLAnchorElement>) => {\n // Prefetch the route on hover if enabled and not external (lazy-load prefetch logic)\n if (prefetchProp && !isExternalUrl(href) && globalRoutes.length > 0) {\n const { prefetchRoute } = await import(\"./prefetch.js\");\n prefetchRoute(href, globalRoutes);\n }\n userOnMouseEnter?.(e);\n };\n\n const onFocus = async (e: React.FocusEvent<HTMLAnchorElement>) => {\n // Also prefetch on focus (keyboard navigation)\n if (prefetchProp && !isExternalUrl(href) && globalRoutes.length > 0) {\n const { prefetchRoute } = await import(\"./prefetch.js\");\n prefetchRoute(href, globalRoutes);\n }\n userOnFocus?.(e);\n };\n\n return (\n <a {...restProps} href={href} target={target} download={download} onClick={onClick} onMouseEnter={onMouseEnter} onFocus={onFocus} className={className}>\n {children}\n </a>\n );\n}\n\n// AppShell props type\n/**\n * Props passed to an optional \\`AppShell\\` wrapper component used by <AppRouter />.\n *\n * \\`Component\\` — the page component to render. \\`pageProps\\` — props provided to the page.\n */\nexport type AppShellProps<TPageProps extends Record<string, unknown> = Record<string, unknown>> = {\n Component: ComponentType<TPageProps>;\n pageProps: TPageProps;\n children?: React.ReactNode;\n};\n\n// Main router component\nexport function AppRouter({ AppShell }: { AppShell?: ComponentType<AppShellProps> }) {\n // useTransition for concurrent rendering - allows React to keep UI responsive during navigation\n const [isPending, startTransition] = useTransition();\n\n // Build routes once on mount (client-side only)\n const { routes, NotFound } = useMemo(() => {\n if (typeof window === \"undefined\") {\n return { routes: [], NotFound: undefined };\n }\n const result = buildRoutes();\n // Store routes globally for Link prefetching\n // In dev mode, also update the global reference to survive HMR\n if (isDevEnvironment()) {\n const globalWindow = window as typeof window & { __heliumGlobalRoutes?: RouteEntry[] };\n globalWindow.__heliumGlobalRoutes = result.routes;\n // Update the module-level reference as well\n globalRoutes.length = 0;\n globalRoutes.push(...result.routes);\n } else {\n globalRoutes = result.routes;\n }\n return result;\n }, []);\n\n // Use useSyncExternalStore to subscribe to location changes\n // This ensures synchronous updates when location changes\n const state = useSyncExternalStore(subscribeToLocation, getLocationSnapshot, getServerSnapshot);\n const [runtimeSSRProps, setRuntimeSSRProps] = React.useState<Record<string, unknown>>(() => {\n const payload = getInitialSSRBootstrap();\n if (!payload) {\n return {};\n }\n\n if (payload.path === window.location.pathname) {\n return payload.props;\n }\n\n return {};\n });\n const [hydrationDone, setHydrationDone] = React.useState(false);\n\n const match = useMemo(() => matchRoute(state.path, routes), [state.path, routes]);\n\n // Use matched params, or fall back to re-extracting from path using global routes during HMR\n const currentParams = match?.params ?? (isDevEnvironment() ? extractParamsFromPath(state.path) : {});\n\n // In dev mode, always read fresh searchParams from URL to handle HMR edge cases\n const currentSearchParams = isDevEnvironment() ? new URLSearchParams(window.location.search) : state.searchParams;\n\n const routerValue: RouterContext = {\n path: state.path,\n params: currentParams,\n searchParams: currentSearchParams,\n push: (href, options) => {\n // Wrap navigation in startTransition for smoother updates\n startTransition(() => {\n navigate(href, { scrollToTop: options?.scrollToTop });\n });\n },\n replace: (href, options) => {\n startTransition(() => {\n navigate(href, { replace: true, scrollToTop: options?.scrollToTop });\n });\n },\n on: (event, listener) => routerEventEmitter.on(event, listener),\n status: match ? 200 : 404,\n isNavigating: state.isNavigating,\n isPending,\n };\n\n React.useEffect(() => {\n const targetPath = `${state.path}${window.location.search || \"\"}`;\n\n // On first client render, if SSR payload already exists for this path, keep it.\n if (!hydrationDone) {\n const bootstrap = getInitialSSRBootstrap();\n if (bootstrap && bootstrap.path === state.path) {\n setHydrationDone(true);\n return;\n }\n setHydrationDone(true);\n }\n\n let cancelled = false;\n\n const load = async () => {\n const ssrPayload = await fetchSSRPageProps(targetPath);\n if (cancelled) {\n return;\n }\n\n if (ssrPayload.kind === \"redirect\") {\n const destination = ssrPayload.redirect.destination;\n\n if (isExternalUrl(destination)) {\n window.location.assign(destination);\n return;\n }\n\n navigate(destination, {\n replace: ssrPayload.redirect.replace ?? true,\n scrollToTop: true,\n });\n return;\n }\n\n if (ssrPayload.kind === \"props\") {\n setRuntimeSSRProps(ssrPayload.props);\n return;\n }\n\n setRuntimeSSRProps({});\n };\n\n void load();\n\n return () => {\n cancelled = true;\n };\n }, [state.path, currentSearchParams.toString(), hydrationDone]);\n\n React.useEffect(() => {\n const controller = new AbortController();\n const targetPath = `${state.path}${window.location.search || \"\"}`;\n\n const syncMetadata = async () => {\n try {\n if (controller.signal.aborted) {\n return;\n }\n\n const result = await rpcCallWithOptions<ClientSocialMeta | null, { path: string }>(\n SEO_METADATA_RPC_METHOD,\n { path: targetPath },\n {\n forceHttp: isAutoHttpOnMobileEnabled() && isMobileRpcDevice(),\n }\n );\n\n if (controller.signal.aborted) {\n return;\n }\n\n applyRouteMetadata(result.data ?? null);\n } catch (error) {\n if ((error as { name?: string })?.name === \"AbortError\") {\n return;\n }\n }\n };\n\n syncMetadata();\n\n return () => controller.abort();\n }, [state.path, currentSearchParams.toString()]);\n\n if (!match) {\n const NotFoundComp = NotFound ?? (() => <div>Not found</div>);\n const content = <NotFoundComp />;\n\n return <RouterContext.Provider value={routerValue}>{AppShell ? <AppShell Component={NotFoundComp} pageProps={{}} /> : content}</RouterContext.Provider>;\n }\n\n const Page = match.route.Component as ComponentType<{ params: Record<string, string | string[]>; searchParams: URLSearchParams }>;\n const pageProps = {\n ...runtimeSSRProps,\n params: match.params,\n searchParams: currentSearchParams,\n };\n\n // Create a wrapped component that includes all layouts\n const WrappedPage = () => {\n let content = <Page {...pageProps} />;\n // Wrap page with layouts (from outer to inner)\n for (let i = match.route.layouts.length - 1; i >= 0; i--) {\n const Layout = match.route.layouts[i];\n content = <Layout>{content}</Layout>;\n }\n return content;\n };\n\n const finalContent = AppShell ? (\n <AppShell Component={WrappedPage} pageProps={pageProps}>\n <WrappedPage />\n </AppShell>\n ) : (\n <WrappedPage />\n );\n\n return <RouterContext.Provider value={routerValue}>{finalContent}</RouterContext.Provider>;\n}\n\ntype ClientSocialMeta = {\n title: string;\n description?: string;\n image?: string;\n canonicalUrl?: string;\n siteName?: string;\n type?: string;\n robots?: string;\n twitterCard?: \"summary\" | \"summary_large_image\" | \"app\" | \"player\";\n twitterSite?: string;\n twitterCreator?: string;\n};\n\nfunction applyRouteMetadata(meta: ClientSocialMeta | null) {\n if (typeof document === \"undefined\") {\n return;\n }\n\n removeExistingSeoTags();\n\n if (!meta) {\n return;\n }\n\n document.title = meta.title;\n\n const entries: Array<{ tag: \"meta\" | \"link\"; attrs: Record<string, string> }> = [];\n\n entries.push({ tag: \"meta\", attrs: { property: \"og:title\", content: meta.title } });\n entries.push({ tag: \"meta\", attrs: { property: \"og:type\", content: meta.type ?? \"website\" } });\n entries.push({ tag: \"meta\", attrs: { name: \"twitter:card\", content: meta.twitterCard ?? \"summary_large_image\" } });\n entries.push({ tag: \"meta\", attrs: { name: \"twitter:title\", content: meta.title } });\n\n if (meta.description) {\n entries.push({ tag: \"meta\", attrs: { name: \"description\", content: meta.description } });\n entries.push({ tag: \"meta\", attrs: { property: \"og:description\", content: meta.description } });\n entries.push({ tag: \"meta\", attrs: { name: \"twitter:description\", content: meta.description } });\n }\n\n if (meta.image) {\n entries.push({ tag: \"meta\", attrs: { property: \"og:image\", content: meta.image } });\n entries.push({ tag: \"meta\", attrs: { name: \"twitter:image\", content: meta.image } });\n }\n\n if (meta.canonicalUrl) {\n entries.push({ tag: \"meta\", attrs: { property: \"og:url\", content: meta.canonicalUrl } });\n entries.push({ tag: \"link\", attrs: { rel: \"canonical\", href: meta.canonicalUrl } });\n }\n\n if (meta.siteName) {\n entries.push({ tag: \"meta\", attrs: { property: \"og:site_name\", content: meta.siteName } });\n }\n\n if (meta.robots) {\n entries.push({ tag: \"meta\", attrs: { name: \"robots\", content: meta.robots } });\n }\n\n if (meta.twitterSite) {\n entries.push({ tag: \"meta\", attrs: { name: \"twitter:site\", content: meta.twitterSite } });\n }\n\n if (meta.twitterCreator) {\n entries.push({ tag: \"meta\", attrs: { name: \"twitter:creator\", content: meta.twitterCreator } });\n }\n\n for (const entry of entries) {\n const node = document.createElement(entry.tag);\n for (const [key, value] of Object.entries(entry.attrs)) {\n node.setAttribute(key, value);\n }\n node.setAttribute(\"data-helium-seo\", \"true\");\n document.head.appendChild(node);\n }\n}\n\nfunction removeExistingSeoTags() {\n const headNodes = Array.from(document.head.querySelectorAll(\"meta, link\"));\n\n for (const node of headNodes) {\n if (node.getAttribute(\"data-helium-seo\") === \"true\") {\n node.remove();\n continue;\n }\n\n if (node.tagName.toLowerCase() === \"link\") {\n const rel = (node.getAttribute(\"rel\") || \"\").toLowerCase();\n if (rel === \"canonical\") {\n node.remove();\n }\n continue;\n }\n\n const name = (node.getAttribute(\"name\") || \"\").toLowerCase();\n const property = (node.getAttribute(\"property\") || \"\").toLowerCase();\n\n if (name === \"description\" || name === \"robots\" || name.startsWith(\"twitter:\")) {\n node.remove();\n continue;\n }\n\n if (property.startsWith(\"og:\")) {\n node.remove();\n }\n }\n}\n"]}
@@ -60,9 +60,29 @@ export interface HeliumRpcSecurityConfig {
60
60
  * Security configuration for HTTP responses.
61
61
  */
62
62
  export interface HeliumSecurityConfig {
63
+ /**
64
+ * Apply Helium's built-in default security headers.
65
+ *
66
+ * When set to `false`, Helium will not set default security headers,
67
+ * allowing full manual control via `headerOverrides` and your own server logic.
68
+ *
69
+ * @default true
70
+ */
71
+ defaultHeaders?: boolean;
72
+ /**
73
+ * Header overrides applied after Helium's default security headers.
74
+ *
75
+ * - Set a header value to override (or add) that header.
76
+ * - Set a header value to `null` to remove that header.
77
+ *
78
+ * This is useful for custom framing policies, custom permissions policy,
79
+ * or disabling a specific default header.
80
+ */
81
+ headerOverrides?: Record<string, string | null>;
63
82
  /**
64
83
  * Content-Security-Policy header value.
65
84
  * Set to a CSP string to enable, or omit to skip CSP.
85
+ * Applied when `defaultHeaders` is enabled.
66
86
  *
67
87
  * @default undefined (no CSP header)
68
88
  */
@@ -70,6 +90,7 @@ export interface HeliumSecurityConfig {
70
90
  /**
71
91
  * Enable Strict-Transport-Security header.
72
92
  * Set to false to disable HSTS.
93
+ * Applied when `defaultHeaders` is enabled.
73
94
  *
74
95
  * @default true
75
96
  */
@@ -1 +1 @@
1
- {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/server/config.ts"],"names":[],"mappings":"AAIA;;;GAGG;AACH,MAAM,WAAW,uBAAuB;IACpC;;;;;OAKG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB;;;;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E,YAAY,IAAI,OAAS;KACtD,CAAC;AACN,CAAC;AAYD;;;;;GAKG;AACH,MAAM,UAAU,kBAAkB,CAAC,SAAuB,EAAE;IACxD,OAAO;QACH,SAAS,EAAE,MAAM,CAAC,GAAG,EAAE,SAAS,IAAI,WAAW;QAC/C,gBAAgB,EAAE,MAAM,CAAC,GAAG,EAAE,gBAAgB,IAAI,KAAK;QACvD,eAAe,EAAE,oBAAoB,CAAC,MAAM,CAAC,CAAC,eAAe;KAChE,CAAC;AACN,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB;IAC5B,YAAY,GAAG,IAAI,CAAC;AACxB,CAAC","sourcesContent":["import fs from \"fs\";\nimport path from \"path\";\nimport { pathToFileURL } from \"url\";\n\n/**\n * WebSocket per-message compression configuration.\n * Uses the permessage-deflate extension to compress messages on the wire.\n */\nexport interface HeliumCompressionConfig {\n /**\n * Enable WebSocket per-message compression (permessage-deflate extension).\n * When enabled, messages are compressed before sending to reduce bandwidth usage.\n *\n * @default true\n */\n enabled?: boolean;\n\n /**\n * Minimum message size in bytes to apply compression.\n * Messages smaller than this threshold will not be compressed to avoid overhead.\n * Only applies when compression is enabled.\n *\n * @default 1024 (1KB)\n */\n threshold?: number;\n}\n\n/**\n * RPC security and rate limiting configuration.\n * Controls WebSocket connection limits, message rate limits, and token-based authentication.\n */\nexport interface HeliumRpcSecurityConfig {\n /**\n * Maximum number of concurrent WebSocket connections allowed per IP address.\n * Helps prevent a single client from exhausting connection resources.\n * Set to 0 to disable this limit.\n *\n * @default 10\n */\n maxConnectionsPerIP?: number;\n\n /**\n * Maximum number of RPC messages allowed per connection within the time window.\n * Helps prevent abuse by limiting message throughput per connection.\n * Set to 0 to disable rate limiting.\n *\n * @default 100\n */\n maxMessagesPerWindow?: number;\n\n /**\n * Time window in milliseconds for rate limiting.\n * Rate limits reset after this duration.\n *\n * @default 60000 (1 minute)\n */\n rateLimitWindowMs?: number;\n\n /**\n * WebSocket connection token validity duration in milliseconds.\n * Tokens are generated server-side and must be used within this timeframe.\n * Shorter durations improve security but may cause issues with slow networks.\n *\n * @default 30000 (30 seconds)\n */\n tokenValidityMs?: number;\n}\n\n/**\n * Security configuration for HTTP responses.\n */\nexport interface HeliumSecurityConfig {\n /**\n * Content-Security-Policy header value.\n * Set to a CSP string to enable, or omit to skip CSP.\n *\n * @default undefined (no CSP header)\n */\n contentSecurityPolicy?: string;\n\n /**\n * Enable Strict-Transport-Security header.\n * Set to false to disable HSTS.\n *\n * @default true\n */\n hsts?: boolean;\n\n /**\n * Allowed CORS origins.\n * Set to [\"*\"] to allow all origins, or provide specific origins.\n * Empty array or omit to restrict to same-origin only (default, most secure).\n *\n * @default [] (same-origin only)\n */\n corsOrigins?: string[];\n}\n\n/**\n * Helium framework configuration.\n *\n * Configure your Helium application behavior including RPC transport settings,\n * compression, security, and proxy configuration for production deployments.\n */\nexport interface HeliumConfig {\n /**\n * Number of proxy levels to trust when extracting client IP addresses.\n *\n * This setting is crucial for deployments behind reverse proxies, load balancers,\n * or CDNs (like Vercel, Cloudflare, AWS ALB, etc.). It determines how the framework\n * extracts the real client IP from headers like X-Forwarded-For.\n *\n * **How it works:**\n * When behind proxies, the X-Forwarded-For header contains a chain of IPs:\n * `X-Forwarded-For: <client-ip>, <proxy1-ip>, <proxy2-ip>`\n *\n * This setting tells Helium how many proxy IPs to skip from the right to find the real client IP.\n *\n * **Values:**\n * - `0`: Don't trust any proxies, use direct connection IP (default, most secure)\n * - `1`: Trust 1 proxy level (recommended for most platforms: Vercel, Netlify, Railway)\n * - `2+`: Trust multiple proxy levels (for complex setups like Cloudflare → Load Balancer → Your Server)\n *\n * **Common configurations:**\n * - Local development: `0`\n * - Vercel/Netlify/Railway: `1`\n * - Cloudflare → Your server: `1` or `2`\n * - AWS ALB → EC2: `1`\n * - Nginx → Node.js: `1`\n * - Cloudflare → AWS ALB → EC2: `2`\n *\n * **Security note:** Setting this too high can allow IP spoofing. Only trust as many\n * proxy levels as you actually have in your infrastructure.\n *\n * This setting applies to both HTTP requests and WebSocket connections.\n *\n * @default 0\n */\n trustProxyDepth?: number;\n\n /**\n * HTTP response security configuration.\n * Controls CORS, CSP, HSTS, and other security headers.\n */\n security?: HeliumSecurityConfig;\n\n /**\n * RPC transport configuration.\n *\n * Configure the WebSocket-based RPC layer including compression\n * and security settings.\n */\n rpc?: {\n /**\n * Client-side transport mode for RPC calls.\n *\n * - `\"websocket\"` (default): Uses persistent WebSocket connection\n * - ✅ Lower latency for subsequent calls (connection reuse)\n * - ✅ Real-time bidirectional communication ready\n * - ⚠️ Higher initial connection overhead\n *\n * - `\"http\"`: Uses HTTP POST requests for each RPC call\n * - ✅ Better performance on mobile/cellular networks (HTTP/2 optimizations)\n * - ✅ No connection state to maintain\n * - ⚠️ Slightly higher per-request overhead on fast networks\n *\n * - `\"auto\"`: Automatically selects based on network conditions\n * - Uses HTTP on cellular/slow networks when `autoHttpOnMobile` is true\n * - Uses WebSocket on fast networks (WiFi, wired)\n *\n * @default \"websocket\"\n */\n transport?: \"http\" | \"websocket\" | \"auto\";\n\n /**\n * Automatically switch to HTTP transport on mobile/cellular networks.\n *\n * When enabled and `transport` is `\"auto\"`, the client will use HTTP\n * instead of WebSocket on cellular connections (4G/LTE, 5G) and slow\n * connections (2G, 3G). This improves performance on mobile networks\n * where HTTP/2 is more efficient due to carrier network optimizations.\n *\n * @default false\n */\n autoHttpOnMobile?: boolean;\n\n /**\n * WebSocket per-message compression configuration.\n *\n * Enable and configure the permessage-deflate extension to compress\n * messages on the wire, reducing bandwidth usage.\n */\n compression?: HeliumCompressionConfig;\n\n /**\n * RPC security and rate limiting configuration.\n *\n * Configure connection limits, message rate limits, and token validity\n * to protect your RPC endpoints from abuse.\n */\n security?: HeliumRpcSecurityConfig;\n\n /**\n * Maximum HTTP request body size in bytes.\n * Requests exceeding this limit receive a 413 status.\n *\n * @default 1048576 (1 MB)\n */\n maxBodySize?: number;\n\n /**\n * Maximum number of RPC calls in a single batch request.\n * Batches exceeding this limit are rejected.\n *\n * @default 20\n */\n maxBatchSize?: number;\n\n /**\n * Maximum WebSocket message payload size in bytes.\n * Messages exceeding this limit cause the connection to be closed.\n *\n * @default 1048576 (1 MB)\n */\n maxWsPayload?: number;\n };\n}\n\nconst DEFAULT_RPC_SECURITY: Required<HeliumRpcSecurityConfig> = {\n maxConnectionsPerIP: 10,\n maxMessagesPerWindow: 100,\n rateLimitWindowMs: 60000,\n tokenValidityMs: 30000,\n};\n\nconst DEFAULT_COMPRESSION: Required<HeliumCompressionConfig> = {\n enabled: true,\n threshold: 1024,\n};\n\nlet cachedConfig: HeliumConfig | null = null;\n\n/**\n * Load Helium configuration from the project root.\n * Searches for helium.config.js, helium.config.mjs, or helium.config.ts.\n * Results are cached for the lifetime of the process.\n *\n * In production, the build process automatically transpiles .ts config files\n * to .js in the dist directory. The loader checks dist/ first when available.\n *\n * @internal - Used by framework internals only\n */\nexport async function loadConfig(root: string = process.cwd()): Promise<HeliumConfig> {\n if (cachedConfig) {\n return cachedConfig;\n }\n\n // Check if there's a custom config directory (used in production)\n const configDir = process.env.HELIUM_CONFIG_DIR || root;\n\n // Prioritize .js/.mjs (work in both dev and production)\n // .ts files work in dev with Vite but fail in production without transpilation\n const configFiles = [\"helium.config.js\", \"helium.config.mjs\", \"helium.config.ts\"];\n\n // In production with HELIUM_CONFIG_DIR set, check dist directory first\n const searchPaths = configDir !== root ? [configDir, root] : [root];\n\n for (const searchPath of searchPaths) {\n for (const configFile of configFiles) {\n const configPath = path.join(searchPath, configFile);\n if (fs.existsSync(configPath)) {\n try {\n const fileUrl = pathToFileURL(configPath).href;\n const module = await import(/* @vite-ignore */ `${fileUrl}?t=${Date.now()}`);\n const config = module.default || {};\n cachedConfig = config;\n return config;\n } catch (err) {\n // In production, .ts files will fail to load without a TypeScript loader\n if (configFile.endsWith(\".ts\") && err instanceof Error && \"code\" in err && err.code === \"ERR_UNKNOWN_FILE_EXTENSION\") {\n console.warn(`[Helium] Cannot load ${configFile} in production. The build process should have transpiled it.`);\n } else {\n console.warn(`[Helium] Failed to load config from ${configFile}:`, err);\n }\n }\n }\n }\n }\n\n cachedConfig = {};\n return cachedConfig;\n}\n\n/**\n * Get the proxy trust depth from config.\n * Used for extracting client IPs from X-Forwarded-For headers.\n *\n * @internal - Used by framework internals only\n */\nexport function getTrustProxyDepth(config: HeliumConfig = {}): number {\n return config.trustProxyDepth ?? 0;\n}\n\n/**\n * Get RPC security configuration with defaults applied.\n * Returns rate limiting, connection limits, and token settings.\n *\n * @internal - Used by framework internals only\n */\nexport function getRpcSecurityConfig(config: HeliumConfig = {}): Required<HeliumRpcSecurityConfig> {\n const src = config.rpc?.security;\n\n return {\n maxConnectionsPerIP: src?.maxConnectionsPerIP ?? DEFAULT_RPC_SECURITY.maxConnectionsPerIP,\n maxMessagesPerWindow: src?.maxMessagesPerWindow ?? DEFAULT_RPC_SECURITY.maxMessagesPerWindow,\n rateLimitWindowMs: src?.rateLimitWindowMs ?? DEFAULT_RPC_SECURITY.rateLimitWindowMs,\n tokenValidityMs: src?.tokenValidityMs ?? DEFAULT_RPC_SECURITY.tokenValidityMs,\n };\n}\n\n/**\n * Get WebSocket compression configuration with defaults applied.\n *\n * @internal - Used by framework internals only\n */\nexport function getCompressionConfig(config: HeliumConfig = {}): Required<HeliumCompressionConfig> {\n const src = config.rpc?.compression;\n\n return {\n enabled: src?.enabled ?? DEFAULT_COMPRESSION.enabled,\n threshold: src?.threshold ?? DEFAULT_COMPRESSION.threshold,\n };\n}\n\n/**\n * Get complete RPC configuration including compression, and security.\n *\n * @internal - Used by framework internals only\n */\nexport function getRpcConfig(config: HeliumConfig = {}) {\n return {\n compression: getCompressionConfig(config),\n security: getRpcSecurityConfig(config),\n maxBodySize: config.rpc?.maxBodySize ?? 1_048_576,\n maxBatchSize: config.rpc?.maxBatchSize ?? 20,\n maxWsPayload: config.rpc?.maxWsPayload ?? 1_048_576,\n };\n}\n\n/**\n * Client-side RPC transport configuration.\n * This is injected into the client bundle at build time.\n */\nexport interface RpcClientTransportConfig {\n transport: \"http\" | \"websocket\" | \"auto\";\n autoHttpOnMobile: boolean;\n tokenValidityMs: number;\n}\n\n/**\n * Get client-side RPC transport configuration.\n * This configuration is injected into the client bundle via Vite defines.\n *\n * @internal - Used by framework internals only\n */\nexport function getRpcClientConfig(config: HeliumConfig = {}): RpcClientTransportConfig {\n return {\n transport: config.rpc?.transport ?? \"websocket\",\n autoHttpOnMobile: config.rpc?.autoHttpOnMobile ?? false,\n tokenValidityMs: getRpcSecurityConfig(config).tokenValidityMs,\n };\n}\n\n/**\n * Clear the cached configuration.\n * Useful for testing or when you need to reload config.\n *\n * @internal - Used by framework internals only\n */\nexport function clearConfigCache() {\n cachedConfig = null;\n}\n"]}
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/server/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AAyPpC,MAAM,oBAAoB,GAAsC;IAC5D,mBAAmB,EAAE,EAAE;IACvB,oBAAoB,EAAE,GAAG;IACzB,iBAAiB,EAAE,KAAK;IACxB,eAAe,EAAE,KAAK;CACzB,CAAC;AAEF,MAAM,mBAAmB,GAAsC;IAC3D,OAAO,EAAE,IAAI;IACb,SAAS,EAAE,IAAI;CAClB,CAAC;AAEF,IAAI,YAAY,GAAwB,IAAI,CAAC;AAE7C;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,OAAe,OAAO,CAAC,GAAG,EAAE;IACzD,IAAI,YAAY,EAAE,CAAC;QACf,OAAO,YAAY,CAAC;IACxB,CAAC;IAED,kEAAkE;IAClE,MAAM,SAAS,GAAG,OAAO,CAAC,GAAG,CAAC,iBAAiB,IAAI,IAAI,CAAC;IAExD,wDAAwD;IACxD,+EAA+E;IAC/E,MAAM,WAAW,GAAG,CAAC,kBAAkB,EAAE,mBAAmB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kBAAkB,CAAC,SAAuB,EAAE;IACxD,OAAO;QACH,SAAS,EAAE,MAAM,CAAC,GAAG,EAAE,SAAS,IAAI,WAAW;QAC/C,gBAAgB,EAAE,MAAM,CAAC,GAAG,EAAE,gBAAgB,IAAI,KAAK;QACvD,eAAe,EAAE,oBAAoB,CAAC,MAAM,CAAC,CAAC,eAAe;KAChE,CAAC;AACN,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB;IAC5B,YAAY,GAAG,IAAI,CAAC;AACxB,CAAC","sourcesContent":["import fs from \"fs\";\nimport path from \"path\";\nimport { pathToFileURL } from \"url\";\n\n/**\n * WebSocket per-message compression configuration.\n * Uses the permessage-deflate extension to compress messages on the wire.\n */\nexport interface HeliumCompressionConfig {\n /**\n * Enable WebSocket per-message compression (permessage-deflate extension).\n * When enabled, messages are compressed before sending to reduce bandwidth usage.\n *\n * @default true\n */\n enabled?: boolean;\n\n /**\n * Minimum message size in bytes to apply compression.\n * Messages smaller than this threshold will not be compressed to avoid overhead.\n * Only applies when compression is enabled.\n *\n * @default 1024 (1KB)\n */\n threshold?: number;\n}\n\n/**\n * RPC security and rate limiting configuration.\n * Controls WebSocket connection limits, message rate limits, and token-based authentication.\n */\nexport interface HeliumRpcSecurityConfig {\n /**\n * Maximum number of concurrent WebSocket connections allowed per IP address.\n * Helps prevent a single client from exhausting connection resources.\n * Set to 0 to disable this limit.\n *\n * @default 10\n */\n maxConnectionsPerIP?: number;\n\n /**\n * Maximum number of RPC messages allowed per connection within the time window.\n * Helps prevent abuse by limiting message throughput per connection.\n * Set to 0 to disable rate limiting.\n *\n * @default 100\n */\n maxMessagesPerWindow?: number;\n\n /**\n * Time window in milliseconds for rate limiting.\n * Rate limits reset after this duration.\n *\n * @default 60000 (1 minute)\n */\n rateLimitWindowMs?: number;\n\n /**\n * WebSocket connection token validity duration in milliseconds.\n * Tokens are generated server-side and must be used within this timeframe.\n * Shorter durations improve security but may cause issues with slow networks.\n *\n * @default 30000 (30 seconds)\n */\n tokenValidityMs?: number;\n}\n\n/**\n * Security configuration for HTTP responses.\n */\nexport interface HeliumSecurityConfig {\n /**\n * Apply Helium's built-in default security headers.\n *\n * When set to `false`, Helium will not set default security headers,\n * allowing full manual control via `headerOverrides` and your own server logic.\n *\n * @default true\n */\n defaultHeaders?: boolean;\n\n /**\n * Header overrides applied after Helium's default security headers.\n *\n * - Set a header value to override (or add) that header.\n * - Set a header value to `null` to remove that header.\n *\n * This is useful for custom framing policies, custom permissions policy,\n * or disabling a specific default header.\n */\n headerOverrides?: Record<string, string | null>;\n\n /**\n * Content-Security-Policy header value.\n * Set to a CSP string to enable, or omit to skip CSP.\n * Applied when `defaultHeaders` is enabled.\n *\n * @default undefined (no CSP header)\n */\n contentSecurityPolicy?: string;\n\n /**\n * Enable Strict-Transport-Security header.\n * Set to false to disable HSTS.\n * Applied when `defaultHeaders` is enabled.\n *\n * @default true\n */\n hsts?: boolean;\n\n /**\n * Allowed CORS origins.\n * Set to [\"*\"] to allow all origins, or provide specific origins.\n * Empty array or omit to restrict to same-origin only (default, most secure).\n *\n * @default [] (same-origin only)\n */\n corsOrigins?: string[];\n}\n\n/**\n * Helium framework configuration.\n *\n * Configure your Helium application behavior including RPC transport settings,\n * compression, security, and proxy configuration for production deployments.\n */\nexport interface HeliumConfig {\n /**\n * Number of proxy levels to trust when extracting client IP addresses.\n *\n * This setting is crucial for deployments behind reverse proxies, load balancers,\n * or CDNs (like Vercel, Cloudflare, AWS ALB, etc.). It determines how the framework\n * extracts the real client IP from headers like X-Forwarded-For.\n *\n * **How it works:**\n * When behind proxies, the X-Forwarded-For header contains a chain of IPs:\n * `X-Forwarded-For: <client-ip>, <proxy1-ip>, <proxy2-ip>`\n *\n * This setting tells Helium how many proxy IPs to skip from the right to find the real client IP.\n *\n * **Values:**\n * - `0`: Don't trust any proxies, use direct connection IP (default, most secure)\n * - `1`: Trust 1 proxy level (recommended for most platforms: Vercel, Netlify, Railway)\n * - `2+`: Trust multiple proxy levels (for complex setups like Cloudflare → Load Balancer → Your Server)\n *\n * **Common configurations:**\n * - Local development: `0`\n * - Vercel/Netlify/Railway: `1`\n * - Cloudflare → Your server: `1` or `2`\n * - AWS ALB → EC2: `1`\n * - Nginx → Node.js: `1`\n * - Cloudflare → AWS ALB → EC2: `2`\n *\n * **Security note:** Setting this too high can allow IP spoofing. Only trust as many\n * proxy levels as you actually have in your infrastructure.\n *\n * This setting applies to both HTTP requests and WebSocket connections.\n *\n * @default 0\n */\n trustProxyDepth?: number;\n\n /**\n * HTTP response security configuration.\n * Controls CORS, CSP, HSTS, and other security headers.\n */\n security?: HeliumSecurityConfig;\n\n /**\n * RPC transport configuration.\n *\n * Configure the WebSocket-based RPC layer including compression\n * and security settings.\n */\n rpc?: {\n /**\n * Client-side transport mode for RPC calls.\n *\n * - `\"websocket\"` (default): Uses persistent WebSocket connection\n * - ✅ Lower latency for subsequent calls (connection reuse)\n * - ✅ Real-time bidirectional communication ready\n * - ⚠️ Higher initial connection overhead\n *\n * - `\"http\"`: Uses HTTP POST requests for each RPC call\n * - ✅ Better performance on mobile/cellular networks (HTTP/2 optimizations)\n * - ✅ No connection state to maintain\n * - ⚠️ Slightly higher per-request overhead on fast networks\n *\n * - `\"auto\"`: Automatically selects based on network conditions\n * - Uses HTTP on cellular/slow networks when `autoHttpOnMobile` is true\n * - Uses WebSocket on fast networks (WiFi, wired)\n *\n * @default \"websocket\"\n */\n transport?: \"http\" | \"websocket\" | \"auto\";\n\n /**\n * Automatically switch to HTTP transport on mobile/cellular networks.\n *\n * When enabled and `transport` is `\"auto\"`, the client will use HTTP\n * instead of WebSocket on cellular connections (4G/LTE, 5G) and slow\n * connections (2G, 3G). This improves performance on mobile networks\n * where HTTP/2 is more efficient due to carrier network optimizations.\n *\n * @default false\n */\n autoHttpOnMobile?: boolean;\n\n /**\n * WebSocket per-message compression configuration.\n *\n * Enable and configure the permessage-deflate extension to compress\n * messages on the wire, reducing bandwidth usage.\n */\n compression?: HeliumCompressionConfig;\n\n /**\n * RPC security and rate limiting configuration.\n *\n * Configure connection limits, message rate limits, and token validity\n * to protect your RPC endpoints from abuse.\n */\n security?: HeliumRpcSecurityConfig;\n\n /**\n * Maximum HTTP request body size in bytes.\n * Requests exceeding this limit receive a 413 status.\n *\n * @default 1048576 (1 MB)\n */\n maxBodySize?: number;\n\n /**\n * Maximum number of RPC calls in a single batch request.\n * Batches exceeding this limit are rejected.\n *\n * @default 20\n */\n maxBatchSize?: number;\n\n /**\n * Maximum WebSocket message payload size in bytes.\n * Messages exceeding this limit cause the connection to be closed.\n *\n * @default 1048576 (1 MB)\n */\n maxWsPayload?: number;\n };\n}\n\nconst DEFAULT_RPC_SECURITY: Required<HeliumRpcSecurityConfig> = {\n maxConnectionsPerIP: 10,\n maxMessagesPerWindow: 100,\n rateLimitWindowMs: 60000,\n tokenValidityMs: 30000,\n};\n\nconst DEFAULT_COMPRESSION: Required<HeliumCompressionConfig> = {\n enabled: true,\n threshold: 1024,\n};\n\nlet cachedConfig: HeliumConfig | null = null;\n\n/**\n * Load Helium configuration from the project root.\n * Searches for helium.config.js, helium.config.mjs, or helium.config.ts.\n * Results are cached for the lifetime of the process.\n *\n * In production, the build process automatically transpiles .ts config files\n * to .js in the dist directory. The loader checks dist/ first when available.\n *\n * @internal - Used by framework internals only\n */\nexport async function loadConfig(root: string = process.cwd()): Promise<HeliumConfig> {\n if (cachedConfig) {\n return cachedConfig;\n }\n\n // Check if there's a custom config directory (used in production)\n const configDir = process.env.HELIUM_CONFIG_DIR || root;\n\n // Prioritize .js/.mjs (work in both dev and production)\n // .ts files work in dev with Vite but fail in production without transpilation\n const configFiles = [\"helium.config.js\", \"helium.config.mjs\", \"helium.config.ts\"];\n\n // In production with HELIUM_CONFIG_DIR set, check dist directory first\n const searchPaths = configDir !== root ? [configDir, root] : [root];\n\n for (const searchPath of searchPaths) {\n for (const configFile of configFiles) {\n const configPath = path.join(searchPath, configFile);\n if (fs.existsSync(configPath)) {\n try {\n const fileUrl = pathToFileURL(configPath).href;\n const module = await import(/* @vite-ignore */ `${fileUrl}?t=${Date.now()}`);\n const config = module.default || {};\n cachedConfig = config;\n return config;\n } catch (err) {\n // In production, .ts files will fail to load without a TypeScript loader\n if (configFile.endsWith(\".ts\") && err instanceof Error && \"code\" in err && err.code === \"ERR_UNKNOWN_FILE_EXTENSION\") {\n console.warn(`[Helium] Cannot load ${configFile} in production. The build process should have transpiled it.`);\n } else {\n console.warn(`[Helium] Failed to load config from ${configFile}:`, err);\n }\n }\n }\n }\n }\n\n cachedConfig = {};\n return cachedConfig;\n}\n\n/**\n * Get the proxy trust depth from config.\n * Used for extracting client IPs from X-Forwarded-For headers.\n *\n * @internal - Used by framework internals only\n */\nexport function getTrustProxyDepth(config: HeliumConfig = {}): number {\n return config.trustProxyDepth ?? 0;\n}\n\n/**\n * Get RPC security configuration with defaults applied.\n * Returns rate limiting, connection limits, and token settings.\n *\n * @internal - Used by framework internals only\n */\nexport function getRpcSecurityConfig(config: HeliumConfig = {}): Required<HeliumRpcSecurityConfig> {\n const src = config.rpc?.security;\n\n return {\n maxConnectionsPerIP: src?.maxConnectionsPerIP ?? DEFAULT_RPC_SECURITY.maxConnectionsPerIP,\n maxMessagesPerWindow: src?.maxMessagesPerWindow ?? DEFAULT_RPC_SECURITY.maxMessagesPerWindow,\n rateLimitWindowMs: src?.rateLimitWindowMs ?? DEFAULT_RPC_SECURITY.rateLimitWindowMs,\n tokenValidityMs: src?.tokenValidityMs ?? DEFAULT_RPC_SECURITY.tokenValidityMs,\n };\n}\n\n/**\n * Get WebSocket compression configuration with defaults applied.\n *\n * @internal - Used by framework internals only\n */\nexport function getCompressionConfig(config: HeliumConfig = {}): Required<HeliumCompressionConfig> {\n const src = config.rpc?.compression;\n\n return {\n enabled: src?.enabled ?? DEFAULT_COMPRESSION.enabled,\n threshold: src?.threshold ?? DEFAULT_COMPRESSION.threshold,\n };\n}\n\n/**\n * Get complete RPC configuration including compression, and security.\n *\n * @internal - Used by framework internals only\n */\nexport function getRpcConfig(config: HeliumConfig = {}) {\n return {\n compression: getCompressionConfig(config),\n security: getRpcSecurityConfig(config),\n maxBodySize: config.rpc?.maxBodySize ?? 1_048_576,\n maxBatchSize: config.rpc?.maxBatchSize ?? 20,\n maxWsPayload: config.rpc?.maxWsPayload ?? 1_048_576,\n };\n}\n\n/**\n * Client-side RPC transport configuration.\n * This is injected into the client bundle at build time.\n */\nexport interface RpcClientTransportConfig {\n transport: \"http\" | \"websocket\" | \"auto\";\n autoHttpOnMobile: boolean;\n tokenValidityMs: number;\n}\n\n/**\n * Get client-side RPC transport configuration.\n * This configuration is injected into the client bundle via Vite defines.\n *\n * @internal - Used by framework internals only\n */\nexport function getRpcClientConfig(config: HeliumConfig = {}): RpcClientTransportConfig {\n return {\n transport: config.rpc?.transport ?? \"websocket\",\n autoHttpOnMobile: config.rpc?.autoHttpOnMobile ?? false,\n tokenValidityMs: getRpcSecurityConfig(config).tokenValidityMs,\n };\n}\n\n/**\n * Clear the cached configuration.\n * Useful for testing or when you need to reload config.\n *\n * @internal - Used by framework internals only\n */\nexport function clearConfigCache() {\n cachedConfig = null;\n}\n"]}
@@ -6,7 +6,17 @@ export interface ServerSidePropsRequest {
6
6
  query: Record<string, string>;
7
7
  params: Record<string, string | string[]>;
8
8
  }
9
- export type ServerSidePropsHandler = (req: ServerSidePropsRequest, ctx: HeliumContext) => Promise<Record<string, unknown> | null | undefined> | Record<string, unknown> | null | undefined;
9
+ export interface ServerSideRedirect {
10
+ destination: string;
11
+ permanent?: boolean;
12
+ statusCode?: 301 | 302 | 303 | 307 | 308;
13
+ replace?: boolean;
14
+ }
15
+ export interface ServerSideRedirectResult {
16
+ redirect: ServerSideRedirect;
17
+ }
18
+ export type ServerSidePropsResult = Record<string, unknown> | ServerSideRedirectResult | null | undefined;
19
+ export type ServerSidePropsHandler = (req: ServerSidePropsRequest, ctx: HeliumContext) => Promise<ServerSidePropsResult> | ServerSidePropsResult;
10
20
  /**
11
21
  * Type for convention-based page server props functions:
12
22
  *
@@ -1 +1 @@
1
- {"version":3,"file":"defineServerSideProps.d.ts","sourceRoot":"","sources":["../../src/server/defineServerSideProps.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAElD,MAAM,WAAW,sBAAsB;IACnC,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,CAAC,CAAC;IACvD,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC9B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC,CAAC;CAC7C;AAED,MAAM,MAAM,sBAAsB,GAAG,CACjC,GAAG,EAAE,sBAAsB,EAC3B,GAAG,EAAE,aAAa,KACjB,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC;AAEtG;;;;;;;;;;GAUG;AACH,MAAM,MAAM,kBAAkB,GAAG,sBAAsB,CAAC"}
1
+ {"version":3,"file":"defineServerSideProps.d.ts","sourceRoot":"","sources":["../../src/server/defineServerSideProps.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAElD,MAAM,WAAW,sBAAsB;IACnC,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,CAAC,CAAC;IACvD,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC9B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC,CAAC;CAC7C;AAED,MAAM,WAAW,kBAAkB;IAC/B,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,UAAU,CAAC,EAAE,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC;IACzC,OAAO,CAAC,EAAE,OAAO,CAAC;CACrB;AAED,MAAM,WAAW,wBAAwB;IACrC,QAAQ,EAAE,kBAAkB,CAAC;CAChC;AAED,MAAM,MAAM,qBAAqB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,wBAAwB,GAAG,IAAI,GAAG,SAAS,CAAC;AAE1G,MAAM,MAAM,sBAAsB,GAAG,CAAC,GAAG,EAAE,sBAAsB,EAAE,GAAG,EAAE,aAAa,KAAK,OAAO,CAAC,qBAAqB,CAAC,GAAG,qBAAqB,CAAC;AAEjJ;;;;;;;;;;GAUG;AACH,MAAM,MAAM,kBAAkB,GAAG,sBAAsB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"defineServerSideProps.js","sourceRoot":"","sources":["../../src/server/defineServerSideProps.ts"],"names":[],"mappings":"","sourcesContent":["import type { HeliumContext } from \"./context.js\";\n\nexport interface ServerSidePropsRequest {\n method: string;\n path: string;\n headers: Record<string, string | string[] | undefined>;\n query: Record<string, string>;\n params: Record<string, string | string[]>;\n}\n\nexport type ServerSidePropsHandler = (\n req: ServerSidePropsRequest,\n ctx: HeliumContext\n) => Promise<Record<string, unknown> | null | undefined> | Record<string, unknown> | null | undefined;\n\n/**\n * Type for convention-based page server props functions:\n *\n * ```ts\n * import type { GetServerSideProps } from \"heliumts/server\";\n *\n * export const getServerSideProps: GetServerSideProps = async (req, ctx) => {\n * return { user: await getUser(req) };\n * };\n * ```\n */\nexport type GetServerSideProps = ServerSidePropsHandler;\n"]}
1
+ {"version":3,"file":"defineServerSideProps.js","sourceRoot":"","sources":["../../src/server/defineServerSideProps.ts"],"names":[],"mappings":"","sourcesContent":["import type { HeliumContext } from \"./context.js\";\n\nexport interface ServerSidePropsRequest {\n method: string;\n path: string;\n headers: Record<string, string | string[] | undefined>;\n query: Record<string, string>;\n params: Record<string, string | string[]>;\n}\n\nexport interface ServerSideRedirect {\n destination: string;\n permanent?: boolean;\n statusCode?: 301 | 302 | 303 | 307 | 308;\n replace?: boolean;\n}\n\nexport interface ServerSideRedirectResult {\n redirect: ServerSideRedirect;\n}\n\nexport type ServerSidePropsResult = Record<string, unknown> | ServerSideRedirectResult | null | undefined;\n\nexport type ServerSidePropsHandler = (req: ServerSidePropsRequest, ctx: HeliumContext) => Promise<ServerSidePropsResult> | ServerSidePropsResult;\n\n/**\n * Type for convention-based page server props functions:\n *\n * ```ts\n * import type { GetServerSideProps } from \"heliumts/server\";\n *\n * export const getServerSideProps: GetServerSideProps = async (req, ctx) => {\n * return { user: await getUser(req) };\n * };\n * ```\n */\nexport type GetServerSideProps = ServerSidePropsHandler;\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"devServer.d.ts","sourceRoot":"","sources":["../../src/server/devServer.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAC7B,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAUtD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAGhD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEzD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAG7C,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAE3D,OAAO,EAA6D,UAAU,EAAE,MAAM,UAAU,CAAC;AAMjG,KAAK,cAAc,GAAG,CAAC,QAAQ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AE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAE3D,OAAO,EAAuD,UAAU,EAAE,MAAM,UAAU,CAAC;AAM3F,KAAK,cAAc,GAAG,CAAC,QAAQ,EAAE,WAAW,EAAE,UAAU,EAAE,UAAU,EAAE,SAAS,EAAE,iBAAiB,KAAK,IAAI,CAAC;AAC5G,KAAK,UAAU,GAAG,IAAI,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,GAAG,KAAK,CAAC,WAAW,GAAG,KAAK,CAAC,iBAAiB,CAAC;AAE3F,UAAU,WAAW;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,eAAe,CAAC;CAC3B;AAED,KAAK,cAAc,GAAG,CAAC,MAAM,OAAO,CAAC,aAAa,CAAC;IAAE,SAAS,EAAE,aAAa,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAAC,QAAQ,CAAC,EAAE,SAAS,CAAA;CAAE,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;AAY7K;;;GAGG;AACH,wBAAgB,iBAAiB,CAC7B,UAAU,EAAE,UAAU,EACtB,YAAY,EAAE,cAAc,EAC5B,MAAM,GAAE,YAAiB,EACzB,OAAO,GAAE,WAAW,EAAO,EAC3B,QAAQ,GAAE,UAAU,EAAO,EAC3B,QAAQ,GAAE,cAAqB,QA8lBlC"}
@@ -16,7 +16,7 @@ import { RpcRegistry } from "./rpcRegistry.js";
16
16
  import { initializeSecurity, verifyConnectionToken } from "./security.js";
17
17
  import { SEOMetadataRouter } from "./seoMetadataRouter.js";
18
18
  import { prepareForMsgpack } from "./serializer.js";
19
- import { createServerSidePropsRequest, matchSSRPage, renderSSRHTML } from "./ssr.js";
19
+ import { matchSSRPage, renderSSRHTML, resolveServerSideProps } from "./ssr.js";
20
20
  const gzipAsync = promisify(gzip);
21
21
  const deflateAsync = promisify(deflate);
22
22
  const brotliCompressAsync = promisify(brotliCompress);
@@ -280,13 +280,20 @@ export function attachToDevServer(httpServer, loadHandlers, config = {}, workers
280
280
  },
281
281
  };
282
282
  try {
283
- let result = {};
284
- if (ssrMatch.page.getServerSideProps) {
285
- const request = createServerSidePropsRequest(req, targetPathname, ssrMatch.params);
286
- result = (await ssrMatch.page.getServerSideProps(request, httpCtx)) ?? {};
283
+ const ssrResult = await resolveServerSideProps({
284
+ req,
285
+ pathname: targetPathname,
286
+ params: ssrMatch.params,
287
+ page: ssrMatch.page,
288
+ ctx: httpCtx,
289
+ });
290
+ if (ssrResult.kind === "redirect") {
291
+ res.writeHead(200, { "Content-Type": "application/json", "Cache-Control": "no-store" });
292
+ res.end(JSON.stringify({ ssr: true, redirect: ssrResult.redirect }));
293
+ return;
287
294
  }
288
295
  res.writeHead(200, { "Content-Type": "application/json", "Cache-Control": "no-store" });
289
- res.end(JSON.stringify({ ssr: true, props: result ?? {} }));
296
+ res.end(JSON.stringify({ ssr: true, props: ssrResult.props }));
290
297
  }
291
298
  catch (error) {
292
299
  log("error", "Failed to resolve SSR page props:", error);
@@ -428,6 +435,18 @@ export function attachToDevServer(httpServer, loadHandlers, config = {}, workers
428
435
  const originalEnd = res.end.bind(res);
429
436
  const bufferedChunks = [];
430
437
  let capturedContentType = "";
438
+ let pendingWriteHead;
439
+ const flushPendingWriteHead = () => {
440
+ if (!pendingWriteHead) {
441
+ return;
442
+ }
443
+ const { statusCode, statusMessageOrHeaders, headers } = pendingWriteHead;
444
+ if (typeof statusMessageOrHeaders === "string") {
445
+ originalWriteHead(statusCode, statusMessageOrHeaders, headers);
446
+ return;
447
+ }
448
+ originalWriteHead(statusCode, statusMessageOrHeaders);
449
+ };
431
450
  res.writeHead = (statusCode, statusMessageOrHeaders, headers) => {
432
451
  const providedHeaders = typeof statusMessageOrHeaders === "string" ? headers : statusMessageOrHeaders;
433
452
  if (providedHeaders) {
@@ -446,7 +465,12 @@ export function attachToDevServer(httpServer, loadHandlers, config = {}, workers
446
465
  }
447
466
  }
448
467
  }
449
- return originalWriteHead(statusCode, statusMessageOrHeaders, headers);
468
+ pendingWriteHead = {
469
+ statusCode,
470
+ statusMessageOrHeaders,
471
+ headers,
472
+ };
473
+ return res;
450
474
  };
451
475
  res.write = (chunk, encoding, callback) => {
452
476
  if (chunk !== undefined && chunk !== null) {
@@ -479,6 +503,7 @@ export function attachToDevServer(httpServer, loadHandlers, config = {}, workers
479
503
  res.write = originalWrite;
480
504
  res.end = originalEnd;
481
505
  if (!(contentType.includes("text/html") || looksLikeHtml)) {
506
+ flushPendingWriteHead();
482
507
  originalEnd(bodyBuffer);
483
508
  return;
484
509
  }
@@ -505,6 +530,14 @@ export function attachToDevServer(httpServer, loadHandlers, config = {}, workers
505
530
  ctx: httpCtx,
506
531
  loadAppShell: currentAppShell,
507
532
  });
533
+ if ("redirect" in rendered) {
534
+ originalWriteHead(rendered.redirect.statusCode, {
535
+ Location: rendered.redirect.destination,
536
+ "Cache-Control": "no-store",
537
+ });
538
+ originalEnd();
539
+ return;
540
+ }
508
541
  html = rendered.html;
509
542
  }
510
543
  catch (error) {
@@ -521,6 +554,7 @@ export function attachToDevServer(httpServer, loadHandlers, config = {}, workers
521
554
  if (devResolvedMetadata) {
522
555
  html = injectSocialMetaIntoHtml(html, devResolvedMetadata);
523
556
  }
557
+ flushPendingWriteHead();
524
558
  originalEnd(Buffer.from(html, "utf-8"));
525
559
  };
526
560
  void finalize();