@nestjs-ssr/react 0.2.0 → 0.2.2

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.d.ts CHANGED
@@ -1,139 +1,14 @@
1
- import { H as HeadData, R as RenderResponse } from './index-C5Knql-9.js';
2
- export { E as ErrorPageDevelopment, f as ErrorPageProduction, d as RenderConfig, c as RenderInterceptor, a as RenderModule, b as RenderService, e as SSRMode, S as StreamingErrorHandler, T as TemplateParserService } from './index-C5Knql-9.js';
3
- import React$1, { ComponentType, ReactNode } from 'react';
4
- import * as react_jsx_runtime from 'react/jsx-runtime';
1
+ export { E as ErrorPageDevelopment, e as ErrorPageProduction, c as RenderConfig, b as RenderInterceptor, R as RenderModule, a as RenderService, d as SSRMode, S as StreamingErrorHandler, T as TemplateParserService } from './index-CaGD266H.js';
2
+ import React, { ComponentType, ReactNode } from 'react';
3
+ import { RenderContext, PageProps } from './client.js';
4
+ export { PageContextProvider, createSSRHooks } from './client.js';
5
+ import { H as HeadData, R as RenderResponse } from './render-response.interface-Dc-Kwb09.js';
5
6
  import '@nestjs/common';
6
7
  import 'vite';
7
8
  import 'express';
8
9
  import '@nestjs/core';
9
10
  import 'rxjs';
10
-
11
- /**
12
- * Request context available to all React components.
13
- * Contains safe request metadata that can be exposed to the client.
14
- *
15
- * Extend this interface to add app-specific properties (user, tenant, feature flags, etc.).
16
- * Use module configuration to pass additional headers or cookies safely.
17
- *
18
- * @example
19
- * // Basic usage - use as-is
20
- * const context: RenderContext = {
21
- * url: '/users/123',
22
- * path: '/users/123',
23
- * query: { tab: 'profile' },
24
- * params: { id: '123' },
25
- * method: 'GET',
26
- * };
27
- *
28
- * @example
29
- * // Extended usage - add custom properties for your app
30
- * interface AppRenderContext extends RenderContext {
31
- * user?: {
32
- * id: string;
33
- * name: string;
34
- * email: string;
35
- * roles: string[];
36
- * };
37
- * tenant?: {
38
- * id: string;
39
- * name: string;
40
- * };
41
- * featureFlags?: Record<string, boolean>;
42
- * theme?: string; // From cookie
43
- * }
44
- *
45
- * // Configure module to pass specific cookies/headers
46
- * ReactSSRModule.forRoot({
47
- * allowedCookies: ['theme', 'locale'],
48
- * allowedHeaders: ['x-tenant-id'],
49
- * })
50
- *
51
- * // Use in interceptor/controller
52
- * const context: AppRenderContext = {
53
- * ...baseContext,
54
- * user: req.user,
55
- * tenant: req.tenant,
56
- * featureFlags: await featureFlagService.getFlags(req),
57
- * };
58
- */
59
- interface RenderContext {
60
- url: string;
61
- path: string;
62
- query: Record<string, string | string[]>;
63
- params: Record<string, string>;
64
- method: string;
65
- }
66
-
67
- /**
68
- * Generic type for React page component props.
69
- * Spreads controller data directly as props (React-standard pattern).
70
- *
71
- * Request context is available via typed hooks created with createSSRHooks().
72
- *
73
- * @template TProps - The shape of props returned by the controller
74
- *
75
- * @example
76
- * ```typescript
77
- * // src/lib/ssr-hooks.ts
78
- * import { createSSRHooks, RenderContext } from '@nestjs-ssr/react';
79
- *
80
- * interface AppRenderContext extends RenderContext {
81
- * user?: User;
82
- * }
83
- *
84
- * export const { usePageContext } = createSSRHooks<AppRenderContext>();
85
- *
86
- * // src/views/product.tsx
87
- * import { usePageContext } from '@/lib/ssr-hooks';
88
- *
89
- * interface ProductPageProps {
90
- * product: Product;
91
- * relatedProducts: Product[];
92
- * }
93
- *
94
- * export default function ProductDetail(props: PageProps<ProductPageProps>) {
95
- * const { product, relatedProducts, head } = props;
96
- * const context = usePageContext(); // Fully typed!
97
- *
98
- * return (
99
- * <html>
100
- * <head>
101
- * <title>{head?.title || product.name}</title>
102
- * </head>
103
- * <body>
104
- * <h1>{product.name}</h1>
105
- * <p>Current path: {context.path}</p>
106
- * </body>
107
- * </html>
108
- * );
109
- * }
110
- * ```
111
- */
112
- type PageProps<TProps = {}> = TProps & {
113
- /**
114
- * Optional head metadata for SEO (title, description, og tags, etc.)
115
- * Pass from controller to populate meta tags, Open Graph, etc.
116
- *
117
- * @example
118
- * ```typescript
119
- * // In controller:
120
- * return {
121
- * product,
122
- * head: {
123
- * title: product.name,
124
- * description: product.description,
125
- * }
126
- * };
127
- *
128
- * // In component:
129
- * <head>
130
- * <title>{props.head?.title}</title>
131
- * <meta name="description" content={props.head?.description} />
132
- * </head>
133
- * ```
134
- */
135
- head?: HeadData;
136
- };
11
+ import 'react/jsx-runtime';
137
12
 
138
13
  /**
139
14
  * Props passed to layout components
@@ -237,7 +112,7 @@ type ExtractPagePropsData<P> = P extends PageProps<infer T> ? T : P extends {
237
112
  /**
238
113
  * Extract controller return type from a React component's props.
239
114
  */
240
- type ExtractComponentData<T> = T extends React$1.ComponentType<infer P> ? ExtractPagePropsData<P> : never;
115
+ type ExtractComponentData<T> = T extends React.ComponentType<infer P> ? ExtractPagePropsData<P> : never;
241
116
  /**
242
117
  * Valid return types for a @Render decorated controller method.
243
118
  * Supports both simple props format and RenderResponse format with layoutProps.
@@ -302,7 +177,7 @@ interface RenderOptions {
302
177
  * }
303
178
  * ```
304
179
  */
305
- declare function Render<T extends React$1.ComponentType<any>>(component: T, options?: RenderOptions): <TMethod extends (...args: any[]) => RenderReturnType<ExtractComponentData<T>> | Promise<RenderReturnType<ExtractComponentData<T>>>>(target: any, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<TMethod>) => TypedPropertyDescriptor<TMethod> | void;
180
+ declare function Render<T extends React.ComponentType<any>>(component: T, options?: RenderOptions): <TMethod extends (...args: any[]) => RenderReturnType<ExtractComponentData<T>> | Promise<RenderReturnType<ExtractComponentData<T>>>>(target: any, propertyKey: string | symbol, descriptor: TypedPropertyDescriptor<TMethod>) => TypedPropertyDescriptor<TMethod> | void;
306
181
 
307
182
  /**
308
183
  * Options for the Layout decorator
@@ -347,191 +222,4 @@ interface LayoutDecoratorOptions {
347
222
  */
348
223
  declare function Layout(layout: LayoutComponent<any>, options?: LayoutDecoratorOptions): ClassDecorator;
349
224
 
350
- /**
351
- * Provider component that makes page context available to all child components.
352
- * Should wrap the entire app in entry-server and entry-client.
353
- */
354
- declare function PageContextProvider({ context, children, }: {
355
- context: RenderContext;
356
- children: React.ReactNode;
357
- }): react_jsx_runtime.JSX.Element;
358
- /**
359
- * Factory function to create typed SSR hooks bound to your app's context type.
360
- * Use this once in your app to create hooks with full type safety.
361
- *
362
- * This eliminates the need to pass generic types to every hook call,
363
- * providing excellent DX with full IntelliSense support.
364
- *
365
- * @template T - Your extended RenderContext type with app-specific properties
366
- *
367
- * @example
368
- * ```typescript
369
- * // src/lib/ssr-hooks.ts - Define once
370
- * import { createSSRHooks, RenderContext } from '@nestjs-ssr/react';
371
- *
372
- * interface AppRenderContext extends RenderContext {
373
- * user?: {
374
- * id: string;
375
- * name: string;
376
- * email: string;
377
- * };
378
- * tenant?: { id: string; name: string };
379
- * featureFlags?: Record<string, boolean>;
380
- * theme?: string; // From cookie
381
- * }
382
- *
383
- * export const {
384
- * usePageContext,
385
- * useParams,
386
- * useQuery,
387
- * useRequest,
388
- * useHeaders,
389
- * useHeader,
390
- * useCookies,
391
- * useCookie,
392
- * } = createSSRHooks<AppRenderContext>();
393
- *
394
- * // Create custom helper hooks
395
- * export const useUser = () => usePageContext().user;
396
- * export const useTheme = () => useCookie('theme');
397
- * export const useUserAgent = () => useHeader('user-agent');
398
- * ```
399
- *
400
- * @example
401
- * ```typescript
402
- * // src/views/home.tsx - Use everywhere with full types
403
- * import { usePageContext, useUser, useTheme, useCookie, useHeader } from '@/lib/ssr-hooks';
404
- *
405
- * export default function Home() {
406
- * const { user, featureFlags } = usePageContext(); // ✅ Fully typed!
407
- * const user = useUser(); // ✅ Also typed!
408
- * const theme = useTheme(); // ✅ From cookie
409
- * const locale = useCookie('locale'); // ✅ Access specific cookie
410
- * const tenantId = useHeader('x-tenant-id'); // ✅ Access specific header
411
- *
412
- * return (
413
- * <div>
414
- * <h1>Welcome {user?.name}</h1>
415
- * <p>Theme: {theme}</p>
416
- * <p>Locale: {locale}</p>
417
- * <p>Tenant: {tenantId}</p>
418
- * </div>
419
- * );
420
- * }
421
- * ```
422
- */
423
- declare function createSSRHooks<T extends RenderContext = RenderContext>(): {
424
- /**
425
- * Hook to access the full page context with your app's type.
426
- * Contains URL metadata, headers, and any custom properties you've added.
427
- */
428
- usePageContext: () => T;
429
- /**
430
- * Hook to access route parameters.
431
- *
432
- * @example
433
- * ```tsx
434
- * // Route: /users/:id
435
- * const params = useParams();
436
- * console.log(params.id); // '123'
437
- * ```
438
- */
439
- useParams: () => Record<string, string>;
440
- /**
441
- * Hook to access query string parameters.
442
- *
443
- * @example
444
- * ```tsx
445
- * // URL: /search?q=react&sort=date
446
- * const query = useQuery();
447
- * console.log(query.q); // 'react'
448
- * console.log(query.sort); // 'date'
449
- * ```
450
- */
451
- useQuery: () => Record<string, string | string[]>;
452
- /**
453
- * Alias for usePageContext() with a more intuitive name.
454
- * Returns the full request context with your app's type.
455
- *
456
- * @example
457
- * ```tsx
458
- * const request = useRequest();
459
- * console.log(request.path); // '/users/123'
460
- * console.log(request.method); // 'GET'
461
- * console.log(request.params); // { id: '123' }
462
- * console.log(request.query); // { search: 'foo' }
463
- * ```
464
- */
465
- useRequest: () => T;
466
- /**
467
- * Hook to access headers configured via allowedHeaders.
468
- * Returns all headers as a Record.
469
- *
470
- * Configure in module registration:
471
- * ```typescript
472
- * RenderModule.register({
473
- * allowedHeaders: ['user-agent', 'x-tenant-id', 'x-api-version']
474
- * })
475
- * ```
476
- *
477
- * @example
478
- * ```tsx
479
- * const headers = useHeaders();
480
- * console.log(headers['user-agent']); // 'Mozilla/5.0...'
481
- * console.log(headers['x-tenant-id']); // 'tenant-123'
482
- * console.log(headers['x-api-version']); // 'v2'
483
- * ```
484
- */
485
- useHeaders: () => Record<string, string>;
486
- /**
487
- * Hook to access a specific custom header by name.
488
- * Returns undefined if the header is not configured or not present.
489
- *
490
- * @param name - The header name (as configured in allowedHeaders)
491
- *
492
- * @example
493
- * ```tsx
494
- * const tenantId = useHeader('x-tenant-id');
495
- * if (tenantId) {
496
- * console.log(`Tenant: ${tenantId}`);
497
- * }
498
- * ```
499
- */
500
- useHeader: (name: string) => string | undefined;
501
- /**
502
- * Hook to access cookies configured via allowedCookies.
503
- * Returns all allowed cookies as a Record.
504
- *
505
- * Configure in module registration:
506
- * ```typescript
507
- * RenderModule.register({
508
- * allowedCookies: ['theme', 'locale', 'consent']
509
- * })
510
- * ```
511
- *
512
- * @example
513
- * ```tsx
514
- * const cookies = useCookies();
515
- * console.log(cookies.theme); // 'dark'
516
- * console.log(cookies.locale); // 'en-US'
517
- * ```
518
- */
519
- useCookies: () => Record<string, string>;
520
- /**
521
- * Hook to access a specific cookie by name.
522
- * Returns undefined if the cookie is not configured or not present.
523
- *
524
- * @param name - The cookie name (as configured in allowedCookies)
525
- *
526
- * @example
527
- * ```tsx
528
- * const theme = useCookie('theme');
529
- * if (theme === 'dark') {
530
- * console.log('Dark mode enabled');
531
- * }
532
- * ```
533
- */
534
- useCookie: (name: string) => string | undefined;
535
- };
536
-
537
- export { HeadData, Layout, type LayoutComponent, type LayoutDecoratorOptions, type LayoutProps, type PageComponentWithLayout, PageContextProvider, type PageProps, Render, type RenderContext, type RenderOptions, RenderResponse, createSSRHooks };
225
+ export { HeadData, Layout, type LayoutComponent, type LayoutDecoratorOptions, type LayoutProps, type PageComponentWithLayout, PageProps, Render, RenderContext, type RenderOptions, RenderResponse };