@vertz/ui-server 0.2.30 → 0.2.31

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,10 +1,15 @@
1
+ import {
2
+ createSSRHandler
3
+ } from "./shared/chunk-wb5fv233.js";
4
+ import {
5
+ createNodeHandler
6
+ } from "./shared/chunk-es0406qq.js";
1
7
  import {
2
8
  collectStreamChunks,
3
9
  compileThemeCached,
4
10
  createAccessSetScript,
5
11
  createRequestContext,
6
12
  createSSRDataChunk,
7
- createSSRHandler,
8
13
  createSessionScript,
9
14
  createSlotPlaceholder,
10
15
  createTemplateChunk,
@@ -25,7 +30,7 @@ import {
25
30
  ssrRenderToString,
26
31
  streamToString,
27
32
  toPrefetchSession
28
- } from "./shared/chunk-bd0sgykf.js";
33
+ } from "./shared/chunk-34fexgex.js";
29
34
  import {
30
35
  clearGlobalSSRTimeout,
31
36
  createSSRAdapter,
@@ -39,7 +44,7 @@ import {
39
44
  setGlobalSSRTimeout,
40
45
  ssrStorage,
41
46
  toVNode
42
- } from "./shared/chunk-gcwqkynf.js";
47
+ } from "./shared/chunk-ybftdw1r.js";
43
48
 
44
49
  // src/aot-manifest-build.ts
45
50
  import { readdirSync, readFileSync } from "node:fs";
@@ -1110,6 +1115,7 @@ export {
1110
1115
  createSSRDataChunk,
1111
1116
  createSSRAdapter,
1112
1117
  createPrefetchManifestManager,
1118
+ createNodeHandler,
1113
1119
  createHoles,
1114
1120
  createAotManifestManager,
1115
1121
  createAccessSetScript,
@@ -0,0 +1,170 @@
1
+ import { IncomingMessage, ServerResponse } from "node:http";
2
+ import { FontFallbackMetrics as FontFallbackMetrics3 } from "@vertz/ui";
3
+ import { CompiledRoute, Theme } from "@vertz/ui";
4
+ interface SSRModule {
5
+ default?: () => unknown;
6
+ App?: () => unknown;
7
+ theme?: Theme;
8
+ /** Global CSS strings to include in every SSR response (e.g. resets, body styles). */
9
+ styles?: string[];
10
+ /**
11
+ * Return all CSS tracked by the bundled @vertz/ui instance.
12
+ * The Vite SSR build inlines @vertz/ui into the server bundle, creating
13
+ * a separate module instance from @vertz/ui-server's dependency. Without
14
+ * this, component CSS from module-level css() calls is invisible to the
15
+ * SSR renderer. Export `getInjectedCSS` from @vertz/ui in the app entry.
16
+ */
17
+ getInjectedCSS?: () => string[];
18
+ /** Compiled routes exported from the app for build-time SSG with generateParams. */
19
+ routes?: CompiledRoute[];
20
+ /** Code-generated API client for manifest-driven zero-discovery prefetching. */
21
+ api?: Record<string, Record<string, (...args: unknown[]) => unknown>>;
22
+ }
23
+ import { ExtractedQuery } from "@vertz/ui-compiler";
24
+ /**
25
+ * SSR prefetch access rule evaluator.
26
+ *
27
+ * Evaluates serialized entity access rules against the current session
28
+ * to determine whether a query should be prefetched during SSR.
29
+ *
30
+ * The serialized rules come from the prefetch manifest (generated at build time).
31
+ * The session comes from the JWT decoded at request time.
32
+ */
33
+ /**
34
+ * Serialized access rule — the JSON-friendly format stored in the manifest.
35
+ * Mirrors SerializedRule from @vertz/server/auth/rules but defined here
36
+ * to avoid importing the server package into the SSR pipeline.
37
+ */
38
+ type SerializedAccessRule = {
39
+ type: "public";
40
+ } | {
41
+ type: "authenticated";
42
+ } | {
43
+ type: "role";
44
+ roles: string[];
45
+ } | {
46
+ type: "entitlement";
47
+ value: string;
48
+ } | {
49
+ type: "where";
50
+ conditions: Record<string, unknown>;
51
+ } | {
52
+ type: "all";
53
+ rules: SerializedAccessRule[];
54
+ } | {
55
+ type: "any";
56
+ rules: SerializedAccessRule[];
57
+ } | {
58
+ type: "fva";
59
+ maxAge: number;
60
+ } | {
61
+ type: "deny";
62
+ };
63
+ /** Serialized entity access rules from the prefetch manifest. */
64
+ type EntityAccessMap = Record<string, Partial<Record<string, SerializedAccessRule>>>;
65
+ interface SSRPrefetchManifest {
66
+ /** Route patterns present in the manifest. */
67
+ routePatterns: string[];
68
+ /** Entity access rules keyed by entity name → operation → serialized rule. */
69
+ entityAccess?: EntityAccessMap;
70
+ /** Route entries with query binding metadata for zero-discovery prefetch. */
71
+ routeEntries?: Record<string, {
72
+ queries: ExtractedQuery[];
73
+ }>;
74
+ }
75
+ import { AccessSet } from "@vertz/ui/auth";
76
+ interface SessionData {
77
+ user: {
78
+ id: string;
79
+ email: string;
80
+ role: string;
81
+ [key: string]: unknown;
82
+ };
83
+ /** Unix timestamp in milliseconds (JWT exp * 1000). */
84
+ expiresAt: number;
85
+ }
86
+ /** Resolved session data for SSR injection. */
87
+ interface SSRSessionInfo {
88
+ session: SessionData;
89
+ /**
90
+ * Access set from JWT acl claim.
91
+ * - Present (object): inline access set (no overflow)
92
+ * - null: access control is configured but the set overflowed the JWT
93
+ * - undefined: access control is not configured
94
+ */
95
+ accessSet?: AccessSet | null;
96
+ }
97
+ /**
98
+ * Callback that extracts session data from a request.
99
+ * Returns null when no valid session exists (expired, missing, or invalid cookie).
100
+ */
101
+ type SessionResolver = (request: Request) => Promise<SSRSessionInfo | null>;
102
+ interface SSRHandlerOptions {
103
+ /** The loaded SSR module (import('./dist/server/index.js')) */
104
+ module: SSRModule;
105
+ /** HTML template string (contents of dist/client/index.html) */
106
+ template: string;
107
+ /** SSR timeout for queries (default: 300ms) */
108
+ ssrTimeout?: number;
109
+ /**
110
+ * Map of CSS asset URLs to their content for inlining.
111
+ * Replaces `<link rel="stylesheet" href="...">` tags with inline `<style>` tags.
112
+ * Eliminates extra network requests, preventing FOUC on slow connections.
113
+ *
114
+ * @example
115
+ * ```ts
116
+ * inlineCSS: { '/assets/vertz.css': await Bun.file('./dist/client/assets/vertz.css').text() }
117
+ * ```
118
+ */
119
+ inlineCSS?: Record<string, string>;
120
+ /**
121
+ * CSP nonce to inject on all inline `<script>` tags emitted during SSR.
122
+ *
123
+ * When set, the SSR data hydration script will include `nonce="<value>"`
124
+ * so that strict Content-Security-Policy headers do not block it.
125
+ */
126
+ nonce?: string;
127
+ /** Pre-computed font fallback metrics (computed at server startup). */
128
+ fallbackMetrics?: Record<string, FontFallbackMetrics3>;
129
+ /** Paths to inject as `<link rel="modulepreload">` in `<head>`. */
130
+ modulepreload?: string[];
131
+ /**
132
+ * Route chunk manifest for per-route modulepreload injection.
133
+ * When provided, only chunks for the matched route are preloaded instead of all chunks.
134
+ */
135
+ routeChunkManifest?: {
136
+ routes: Record<string, string[]>;
137
+ };
138
+ /** Cache-Control header for HTML responses. Omit or undefined = no header (safe default). */
139
+ cacheControl?: string;
140
+ /**
141
+ * Resolves session data from request cookies for SSR injection.
142
+ * When provided, SSR HTML includes `window.__VERTZ_SESSION__` and
143
+ * optionally `window.__VERTZ_ACCESS_SET__` for instant auth hydration.
144
+ */
145
+ sessionResolver?: SessionResolver;
146
+ /**
147
+ * Prefetch manifest for single-pass SSR optimization.
148
+ *
149
+ * When provided with route entries and an API client export, enables
150
+ * zero-discovery rendering — queries are prefetched from the manifest
151
+ * without executing the component tree, then a single render pass
152
+ * produces the HTML. Without a manifest, SSR still uses the single-pass
153
+ * discovery-then-render approach (cheaper than two-pass).
154
+ */
155
+ manifest?: SSRPrefetchManifest;
156
+ /**
157
+ * Enable progressive HTML streaming. Default: false.
158
+ *
159
+ * When true, the Response body is a ReadableStream that sends `<head>`
160
+ * content (CSS, preloads, fonts) before `<body>` rendering is complete.
161
+ * This improves TTFB and FCP.
162
+ *
163
+ * Has no effect on zero-discovery routes (manifest with routeEntries),
164
+ * which always use buffered rendering.
165
+ */
166
+ progressiveHTML?: boolean;
167
+ }
168
+ type NodeHandlerOptions = SSRHandlerOptions;
169
+ declare function createNodeHandler(options: NodeHandlerOptions): (req: IncomingMessage, res: ServerResponse) => void;
170
+ export { createNodeHandler, NodeHandlerOptions };
@@ -0,0 +1,8 @@
1
+ import {
2
+ createNodeHandler
3
+ } from "./shared/chunk-es0406qq.js";
4
+ import"./shared/chunk-34fexgex.js";
5
+ import"./shared/chunk-ybftdw1r.js";
6
+ export {
7
+ createNodeHandler
8
+ };