@arponascension/express-inertia 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,175 @@
1
+ import { RequestHandler, Request } from 'express';
2
+ import { I as InertiaOptions, D as DirectiveHandler, P as PropCallback, A as AlwaysProp, a as DeferredProp, L as LazyProp, M as MergeProp, O as OptionalProp, b as PageProps, c as Page, S as SSROptions, d as SSRResult } from './types-Co2XESgs.mjs';
3
+ export { B as BladeEngineOptions, C as CircuitBreaker, e as CircuitBreakerOptions, f as InertiaRequestHelper, g as InertiaResponseHandler, R as RetryOptions, h as SSRResilienceOptions, i as SecurityOptions, V as ViteConfig, j as calculateBackoff, s as shouldRetry } from './types-Co2XESgs.mjs';
4
+ export { TemplateLocals, clearEngineCache, createInertiaEngine, inertiaEngine } from './engine.mjs';
5
+ import { ViteHelper } from './vite.mjs';
6
+ export { InertiaVitePlugin, InertiaVitePluginOptions, ViteManifest, ViteManifestChunk, createViteHelper, defaultViteHelper, inertiaVitePlugin } from './vite.mjs';
7
+
8
+ /**
9
+ * Creates the Inertia Express middleware.
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * import express from 'express';
14
+ * import inertia from 'express-inertia';
15
+ *
16
+ * const app = express();
17
+ * app.use(inertia({
18
+ * rootView: 'base.ejs',
19
+ * version: '1.0.0',
20
+ * shared: (req) => ({
21
+ * user: req.user,
22
+ * flash: req.flash?.() || {},
23
+ * }),
24
+ * }));
25
+ * ```
26
+ */
27
+ declare function createInertia(options?: InertiaOptions): RequestHandler;
28
+
29
+ /**
30
+ * Middleware that assigns a unique request ID for correlation across logs.
31
+ * Uses X-Request-ID header if present, otherwise generates a short ID.
32
+ */
33
+ declare function requestIdMiddleware(): RequestHandler;
34
+
35
+ /**
36
+ * Register a global custom Blade directive.
37
+ * @param name Directive name without the @ (e.g. 'datetime' for @datetime($date))
38
+ * @param handler Function returning the compiled EJS string or HTML
39
+ */
40
+ declare function registerDirective(name: string, handler: DirectiveHandler): void;
41
+ /**
42
+ * Compiles Blade-style directives and Blade-style component tags into valid EJS syntax.
43
+ */
44
+ declare function compileBladeDirectives(templateSource: string, localDirectives?: Record<string, DirectiveHandler>): string;
45
+
46
+ /**
47
+ * Marks a prop as lazy. Lazy props are ONLY evaluated during partial reloads
48
+ * when specifically requested in the `only` array by the client.
49
+ */
50
+ declare function lazy<T = any>(callback: PropCallback<T>): LazyProp<T>;
51
+ /**
52
+ * Marks a prop as always included. Always props are evaluated and returned
53
+ * on every request, including partial reloads, even if not explicitly requested.
54
+ */
55
+ declare function always<T = any>(value: T | PropCallback<T>): AlwaysProp<T>;
56
+ /**
57
+ * Marks a prop as deferred (Inertia v2).
58
+ */
59
+ declare function defer<T = any>(callback: PropCallback<T>, options?: {
60
+ group?: string;
61
+ }): DeferredProp<T>;
62
+ /**
63
+ * Marks a prop as mergeable (Inertia v2).
64
+ */
65
+ declare function merge<T = any>(value: T | PropCallback<T>): MergeProp<T>;
66
+ /**
67
+ * Marks a prop as optional.
68
+ */
69
+ declare function optional<T = any>(callback: PropCallback<T>): OptionalProp<T>;
70
+ declare function isLazy(val: any): val is LazyProp;
71
+ declare function isAlways(val: any): val is AlwaysProp;
72
+ declare function isDeferred(val: any): val is DeferredProp;
73
+ declare function isMerge(val: any): val is MergeProp;
74
+ declare function isOptional(val: any): val is OptionalProp;
75
+ /**
76
+ * Evaluates and resolves all props (promises, functions, lazy, always, merge, deferred)
77
+ * based on current Inertia request context and partial reload headers.
78
+ */
79
+ declare function resolveProps(rawProps: PageProps, req: Request, component: string): Promise<{
80
+ resolvedProps: PageProps;
81
+ deferredProps?: Record<string, string[]>;
82
+ mergeProps?: string[];
83
+ }>;
84
+ /**
85
+ * Escapes characters for HTML attribute insertion to prevent XSS.
86
+ */
87
+ declare function escapeHtmlAttr(str: string): string;
88
+ /**
89
+ * Serializes Page object safely for data-page HTML attribute.
90
+ */
91
+ declare function serializePage(page: Page): string;
92
+ /**
93
+ * Safely stringifies an object, replacing circular references with null.
94
+ */
95
+ declare function safeStringify(obj: any): string;
96
+ /**
97
+ * Default pattern for safe component names: alphanumeric, hyphens, and underscores,
98
+ * optionally separated by single forward slashes. Blocks path traversal sequences
99
+ * like `..`, leading/trailing slashes, and consecutive slashes.
100
+ */
101
+ declare const DEFAULT_COMPONENT_NAME_PATTERN: RegExp;
102
+ /**
103
+ * Validates a component name to prevent path traversal and injection attacks.
104
+ * Throws a TypeError if the name contains suspicious characters.
105
+ */
106
+ declare function validateComponentName(component: string, pattern?: RegExp): void;
107
+ /**
108
+ * Recursively sanitizes viewData by stripping functions and undefined values.
109
+ * Only plain objects and primitive values are preserved.
110
+ */
111
+ declare function sanitizeViewData(data: Record<string, any>): Record<string, any>;
112
+ /**
113
+ * Generates a Subresource Integrity (SRI) hash for a given string.
114
+ * Returns the base64-encoded SHA-384 hash prefixed with 'sha384-'.
115
+ */
116
+ declare function generateSriHash(content: string | Buffer): Promise<string>;
117
+
118
+ declare function resetAllCircuitBreakers(): void;
119
+ /**
120
+ * Executes Server-Side Rendering (SSR) for the given Inertia page.
121
+ * Returns head elements and rendered HTML body, or null if SSR is disabled or fails.
122
+ */
123
+ declare function renderSSR(page: Page, options?: boolean | SSROptions): Promise<SSRResult | null>;
124
+
125
+ interface PrefetchOptions {
126
+ /**
127
+ * Whether to include crossorigin attribute.
128
+ * @default false
129
+ */
130
+ crossorigin?: boolean;
131
+ /**
132
+ * Whether to include integrity attribute (requires async SRI calculation).
133
+ * @default false
134
+ */
135
+ integrity?: boolean;
136
+ /**
137
+ * Prefetch mode: 'prefetch' (default) or 'preload'.
138
+ */
139
+ mode?: 'prefetch' | 'preload';
140
+ }
141
+ interface PrefetchEntry {
142
+ entrypoints: string[];
143
+ assets?: string[];
144
+ }
145
+ declare class PrefetchHelper {
146
+ private viteHelper;
147
+ constructor(viteHelper: ViteHelper);
148
+ /**
149
+ * Generates prefetch tags for the given entrypoints.
150
+ * Uses the Vite manifest to resolve actual asset paths in production.
151
+ */
152
+ prefetch(entries: string | string[], options?: PrefetchOptions): string;
153
+ /**
154
+ * Generates preload tags for critical assets.
155
+ */
156
+ preload(entries: string | string[], options?: Omit<PrefetchOptions, 'mode'>): string;
157
+ private resolveChunk;
158
+ }
159
+ declare function createPrefetchHelper(viteHelper: ViteHelper): PrefetchHelper;
160
+
161
+ interface Logger {
162
+ warn(message: string, meta?: Record<string, any>): void;
163
+ error(message: string, meta?: Record<string, any>): void;
164
+ info(message: string, meta?: Record<string, any>): void;
165
+ debug(message: string, meta?: Record<string, any>): void;
166
+ }
167
+ interface LoggerOptions {
168
+ prefix?: string;
169
+ logger?: Logger;
170
+ }
171
+ declare function setGlobalLogger(logger: Logger): void;
172
+ declare function getGlobalLogger(): Logger;
173
+ declare function createLogger(options?: LoggerOptions): Logger;
174
+
175
+ export { AlwaysProp, DEFAULT_COMPONENT_NAME_PATTERN, DeferredProp, DirectiveHandler, InertiaOptions, LazyProp, type Logger, type LoggerOptions, MergeProp, OptionalProp, Page, PageProps, type PrefetchEntry, PrefetchHelper, type PrefetchOptions, PropCallback, SSROptions, SSRResult, ViteHelper, always, compileBladeDirectives, createInertia, createLogger, createPrefetchHelper, createInertia as default, defer, escapeHtmlAttr, generateSriHash, getGlobalLogger, createInertia as inertia, isAlways, isDeferred, isLazy, isMerge, isOptional, lazy, merge, optional, registerDirective, renderSSR, requestIdMiddleware, resetAllCircuitBreakers, resolveProps, safeStringify, sanitizeViewData, serializePage, setGlobalLogger, validateComponentName };
@@ -0,0 +1,175 @@
1
+ import { RequestHandler, Request } from 'express';
2
+ import { I as InertiaOptions, D as DirectiveHandler, P as PropCallback, A as AlwaysProp, a as DeferredProp, L as LazyProp, M as MergeProp, O as OptionalProp, b as PageProps, c as Page, S as SSROptions, d as SSRResult } from './types-Co2XESgs.js';
3
+ export { B as BladeEngineOptions, C as CircuitBreaker, e as CircuitBreakerOptions, f as InertiaRequestHelper, g as InertiaResponseHandler, R as RetryOptions, h as SSRResilienceOptions, i as SecurityOptions, V as ViteConfig, j as calculateBackoff, s as shouldRetry } from './types-Co2XESgs.js';
4
+ export { TemplateLocals, clearEngineCache, createInertiaEngine, inertiaEngine } from './engine.js';
5
+ import { ViteHelper } from './vite.js';
6
+ export { InertiaVitePlugin, InertiaVitePluginOptions, ViteManifest, ViteManifestChunk, createViteHelper, defaultViteHelper, inertiaVitePlugin } from './vite.js';
7
+
8
+ /**
9
+ * Creates the Inertia Express middleware.
10
+ *
11
+ * @example
12
+ * ```ts
13
+ * import express from 'express';
14
+ * import inertia from 'express-inertia';
15
+ *
16
+ * const app = express();
17
+ * app.use(inertia({
18
+ * rootView: 'base.ejs',
19
+ * version: '1.0.0',
20
+ * shared: (req) => ({
21
+ * user: req.user,
22
+ * flash: req.flash?.() || {},
23
+ * }),
24
+ * }));
25
+ * ```
26
+ */
27
+ declare function createInertia(options?: InertiaOptions): RequestHandler;
28
+
29
+ /**
30
+ * Middleware that assigns a unique request ID for correlation across logs.
31
+ * Uses X-Request-ID header if present, otherwise generates a short ID.
32
+ */
33
+ declare function requestIdMiddleware(): RequestHandler;
34
+
35
+ /**
36
+ * Register a global custom Blade directive.
37
+ * @param name Directive name without the @ (e.g. 'datetime' for @datetime($date))
38
+ * @param handler Function returning the compiled EJS string or HTML
39
+ */
40
+ declare function registerDirective(name: string, handler: DirectiveHandler): void;
41
+ /**
42
+ * Compiles Blade-style directives and Blade-style component tags into valid EJS syntax.
43
+ */
44
+ declare function compileBladeDirectives(templateSource: string, localDirectives?: Record<string, DirectiveHandler>): string;
45
+
46
+ /**
47
+ * Marks a prop as lazy. Lazy props are ONLY evaluated during partial reloads
48
+ * when specifically requested in the `only` array by the client.
49
+ */
50
+ declare function lazy<T = any>(callback: PropCallback<T>): LazyProp<T>;
51
+ /**
52
+ * Marks a prop as always included. Always props are evaluated and returned
53
+ * on every request, including partial reloads, even if not explicitly requested.
54
+ */
55
+ declare function always<T = any>(value: T | PropCallback<T>): AlwaysProp<T>;
56
+ /**
57
+ * Marks a prop as deferred (Inertia v2).
58
+ */
59
+ declare function defer<T = any>(callback: PropCallback<T>, options?: {
60
+ group?: string;
61
+ }): DeferredProp<T>;
62
+ /**
63
+ * Marks a prop as mergeable (Inertia v2).
64
+ */
65
+ declare function merge<T = any>(value: T | PropCallback<T>): MergeProp<T>;
66
+ /**
67
+ * Marks a prop as optional.
68
+ */
69
+ declare function optional<T = any>(callback: PropCallback<T>): OptionalProp<T>;
70
+ declare function isLazy(val: any): val is LazyProp;
71
+ declare function isAlways(val: any): val is AlwaysProp;
72
+ declare function isDeferred(val: any): val is DeferredProp;
73
+ declare function isMerge(val: any): val is MergeProp;
74
+ declare function isOptional(val: any): val is OptionalProp;
75
+ /**
76
+ * Evaluates and resolves all props (promises, functions, lazy, always, merge, deferred)
77
+ * based on current Inertia request context and partial reload headers.
78
+ */
79
+ declare function resolveProps(rawProps: PageProps, req: Request, component: string): Promise<{
80
+ resolvedProps: PageProps;
81
+ deferredProps?: Record<string, string[]>;
82
+ mergeProps?: string[];
83
+ }>;
84
+ /**
85
+ * Escapes characters for HTML attribute insertion to prevent XSS.
86
+ */
87
+ declare function escapeHtmlAttr(str: string): string;
88
+ /**
89
+ * Serializes Page object safely for data-page HTML attribute.
90
+ */
91
+ declare function serializePage(page: Page): string;
92
+ /**
93
+ * Safely stringifies an object, replacing circular references with null.
94
+ */
95
+ declare function safeStringify(obj: any): string;
96
+ /**
97
+ * Default pattern for safe component names: alphanumeric, hyphens, and underscores,
98
+ * optionally separated by single forward slashes. Blocks path traversal sequences
99
+ * like `..`, leading/trailing slashes, and consecutive slashes.
100
+ */
101
+ declare const DEFAULT_COMPONENT_NAME_PATTERN: RegExp;
102
+ /**
103
+ * Validates a component name to prevent path traversal and injection attacks.
104
+ * Throws a TypeError if the name contains suspicious characters.
105
+ */
106
+ declare function validateComponentName(component: string, pattern?: RegExp): void;
107
+ /**
108
+ * Recursively sanitizes viewData by stripping functions and undefined values.
109
+ * Only plain objects and primitive values are preserved.
110
+ */
111
+ declare function sanitizeViewData(data: Record<string, any>): Record<string, any>;
112
+ /**
113
+ * Generates a Subresource Integrity (SRI) hash for a given string.
114
+ * Returns the base64-encoded SHA-384 hash prefixed with 'sha384-'.
115
+ */
116
+ declare function generateSriHash(content: string | Buffer): Promise<string>;
117
+
118
+ declare function resetAllCircuitBreakers(): void;
119
+ /**
120
+ * Executes Server-Side Rendering (SSR) for the given Inertia page.
121
+ * Returns head elements and rendered HTML body, or null if SSR is disabled or fails.
122
+ */
123
+ declare function renderSSR(page: Page, options?: boolean | SSROptions): Promise<SSRResult | null>;
124
+
125
+ interface PrefetchOptions {
126
+ /**
127
+ * Whether to include crossorigin attribute.
128
+ * @default false
129
+ */
130
+ crossorigin?: boolean;
131
+ /**
132
+ * Whether to include integrity attribute (requires async SRI calculation).
133
+ * @default false
134
+ */
135
+ integrity?: boolean;
136
+ /**
137
+ * Prefetch mode: 'prefetch' (default) or 'preload'.
138
+ */
139
+ mode?: 'prefetch' | 'preload';
140
+ }
141
+ interface PrefetchEntry {
142
+ entrypoints: string[];
143
+ assets?: string[];
144
+ }
145
+ declare class PrefetchHelper {
146
+ private viteHelper;
147
+ constructor(viteHelper: ViteHelper);
148
+ /**
149
+ * Generates prefetch tags for the given entrypoints.
150
+ * Uses the Vite manifest to resolve actual asset paths in production.
151
+ */
152
+ prefetch(entries: string | string[], options?: PrefetchOptions): string;
153
+ /**
154
+ * Generates preload tags for critical assets.
155
+ */
156
+ preload(entries: string | string[], options?: Omit<PrefetchOptions, 'mode'>): string;
157
+ private resolveChunk;
158
+ }
159
+ declare function createPrefetchHelper(viteHelper: ViteHelper): PrefetchHelper;
160
+
161
+ interface Logger {
162
+ warn(message: string, meta?: Record<string, any>): void;
163
+ error(message: string, meta?: Record<string, any>): void;
164
+ info(message: string, meta?: Record<string, any>): void;
165
+ debug(message: string, meta?: Record<string, any>): void;
166
+ }
167
+ interface LoggerOptions {
168
+ prefix?: string;
169
+ logger?: Logger;
170
+ }
171
+ declare function setGlobalLogger(logger: Logger): void;
172
+ declare function getGlobalLogger(): Logger;
173
+ declare function createLogger(options?: LoggerOptions): Logger;
174
+
175
+ export { AlwaysProp, DEFAULT_COMPONENT_NAME_PATTERN, DeferredProp, DirectiveHandler, InertiaOptions, LazyProp, type Logger, type LoggerOptions, MergeProp, OptionalProp, Page, PageProps, type PrefetchEntry, PrefetchHelper, type PrefetchOptions, PropCallback, SSROptions, SSRResult, ViteHelper, always, compileBladeDirectives, createInertia, createLogger, createPrefetchHelper, createInertia as default, defer, escapeHtmlAttr, generateSriHash, getGlobalLogger, createInertia as inertia, isAlways, isDeferred, isLazy, isMerge, isOptional, lazy, merge, optional, registerDirective, renderSSR, requestIdMiddleware, resetAllCircuitBreakers, resolveProps, safeStringify, sanitizeViewData, serializePage, setGlobalLogger, validateComponentName };