@inertia-node/nest 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.
- package/LICENSE +21 -0
- package/dist/index.d.ts +108 -0
- package/dist/index.js +558 -0
- package/dist/index.js.map +1 -0
- package/package.json +68 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Inertia Node Adapter contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { RenderOptions, InputProps, ValidationErrorInput, ValidationErrorOptions, CreateInertiaOptions, InertiaInstance, SessionStore, AuthConfig, AuthRuntime } from '@inertia-node/core';
|
|
2
|
+
export { AuthConfig, AuthRuntime, CreateInertiaOptions, InertiaInstance, InputProps, ProtocolResponse, RenderOptions, SessionStore, ValidationErrorInput, ValidationErrorOptions, ValidationErrorPayload, always, createInertia, defer, inertiaAuth, merge, optional, validationError } from '@inertia-node/core';
|
|
3
|
+
import { ModuleMetadata, Type, CanActivate, ExecutionContext, NestInterceptor, CallHandler, DynamicModule } from '@nestjs/common';
|
|
4
|
+
import { Request } from 'express';
|
|
5
|
+
import { Reflector } from '@nestjs/core';
|
|
6
|
+
import { Observable } from 'rxjs';
|
|
7
|
+
|
|
8
|
+
interface NestInertiaOptions extends CreateInertiaOptions {
|
|
9
|
+
instance?: InertiaInstance;
|
|
10
|
+
session?: (request: Request) => SessionStore | undefined;
|
|
11
|
+
auth?: AuthConfig<Request, any, any>;
|
|
12
|
+
withAllErrors?: boolean;
|
|
13
|
+
}
|
|
14
|
+
type NestRenderOptions = RenderOptions;
|
|
15
|
+
interface NestInertiaOptionsFactory {
|
|
16
|
+
createInertiaOptions(): Promise<NestInertiaOptions> | NestInertiaOptions;
|
|
17
|
+
}
|
|
18
|
+
interface NestInertiaAsyncOptions extends Pick<ModuleMetadata, "imports"> {
|
|
19
|
+
inject?: any[];
|
|
20
|
+
useExisting?: Type<NestInertiaOptionsFactory>;
|
|
21
|
+
useClass?: Type<NestInertiaOptionsFactory>;
|
|
22
|
+
useFactory?: (...args: any[]) => Promise<NestInertiaOptions> | NestInertiaOptions;
|
|
23
|
+
}
|
|
24
|
+
type InertiaControllerResult = InertiaRenderResult | InertiaRedirectResult | InertiaLocationResult | InertiaBackWithErrorsResult;
|
|
25
|
+
interface InertiaRenderResult {
|
|
26
|
+
readonly __inertiaNest: "render";
|
|
27
|
+
component: string;
|
|
28
|
+
props?: InputProps;
|
|
29
|
+
options?: NestRenderOptions;
|
|
30
|
+
}
|
|
31
|
+
interface InertiaRedirectResult {
|
|
32
|
+
readonly __inertiaNest: "redirect";
|
|
33
|
+
location: string;
|
|
34
|
+
status?: number;
|
|
35
|
+
}
|
|
36
|
+
interface InertiaLocationResult {
|
|
37
|
+
readonly __inertiaNest: "location";
|
|
38
|
+
location: string;
|
|
39
|
+
}
|
|
40
|
+
interface InertiaBackWithErrorsResult {
|
|
41
|
+
readonly __inertiaNest: "backWithErrors";
|
|
42
|
+
errors: ValidationErrorInput;
|
|
43
|
+
options?: ValidationErrorOptions;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
declare function inertiaDecorator(component: string, options?: NestRenderOptions): MethodDecorator;
|
|
47
|
+
declare const Inertia: typeof inertiaDecorator & {
|
|
48
|
+
render(component: string, props?: InputProps, options?: NestRenderOptions): InertiaRenderResult;
|
|
49
|
+
redirect(location: string, status?: number): InertiaRedirectResult;
|
|
50
|
+
location(location: string): InertiaLocationResult;
|
|
51
|
+
backWithErrors(errors: ValidationErrorInput, options?: ValidationErrorOptions): InertiaBackWithErrorsResult;
|
|
52
|
+
};
|
|
53
|
+
declare function InertiaRenderOptions(options: NestRenderOptions): MethodDecorator;
|
|
54
|
+
|
|
55
|
+
declare class InertiaAuthGuard implements CanActivate {
|
|
56
|
+
private readonly options;
|
|
57
|
+
constructor(options: NestInertiaOptions);
|
|
58
|
+
canActivate(context: ExecutionContext): Promise<boolean>;
|
|
59
|
+
}
|
|
60
|
+
declare class InertiaGuestGuard implements CanActivate {
|
|
61
|
+
private readonly options;
|
|
62
|
+
constructor(options: NestInertiaOptions);
|
|
63
|
+
canActivate(context: ExecutionContext): Promise<boolean>;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
declare class InertiaInterceptor implements NestInterceptor {
|
|
67
|
+
private readonly options;
|
|
68
|
+
private readonly reflector;
|
|
69
|
+
private readonly inertia;
|
|
70
|
+
constructor(options: NestInertiaOptions, reflector: Reflector);
|
|
71
|
+
intercept(context: ExecutionContext, next: CallHandler): Observable<unknown>;
|
|
72
|
+
private handleResult;
|
|
73
|
+
private sendRender;
|
|
74
|
+
private sendRedirect;
|
|
75
|
+
private sendLocation;
|
|
76
|
+
private sendBackWithErrors;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
declare class InertiaModule {
|
|
80
|
+
static forRoot(options?: NestInertiaOptions): DynamicModule;
|
|
81
|
+
static forRootAsync(options: NestInertiaAsyncOptions): DynamicModule;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
declare function nestExpressSessionAdapter(): (request: Request) => SessionStore | undefined;
|
|
85
|
+
|
|
86
|
+
declare class InertiaService {
|
|
87
|
+
readonly options: NestInertiaOptions;
|
|
88
|
+
constructor(options: NestInertiaOptions);
|
|
89
|
+
render(component: string, props?: InputProps, options?: NestRenderOptions): InertiaRenderResult;
|
|
90
|
+
redirect(location: string, status?: number): InertiaRedirectResult;
|
|
91
|
+
location(location: string): InertiaLocationResult;
|
|
92
|
+
backWithErrors(errors: ValidationErrorInput, options?: ValidationErrorOptions): InertiaBackWithErrorsResult;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
type NestInertiaRequest<User = unknown> = Request & {
|
|
96
|
+
user?: User;
|
|
97
|
+
auth?: AuthRuntime<User>;
|
|
98
|
+
flash(key: string, value: unknown): Promise<void>;
|
|
99
|
+
};
|
|
100
|
+
declare module "express-serve-static-core" {
|
|
101
|
+
interface Request {
|
|
102
|
+
user?: unknown;
|
|
103
|
+
auth?: AuthRuntime<unknown>;
|
|
104
|
+
flash(key: string, value: unknown): Promise<void>;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export { Inertia, InertiaAuthGuard, type InertiaBackWithErrorsResult, type InertiaControllerResult, InertiaGuestGuard, InertiaInterceptor, type InertiaLocationResult, InertiaModule, type InertiaRedirectResult, InertiaRenderOptions, type InertiaRenderResult, InertiaService, type NestInertiaAsyncOptions, type NestInertiaOptions, type NestInertiaOptionsFactory, type NestInertiaRequest, type NestRenderOptions, nestExpressSessionAdapter };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,558 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
4
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
5
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
6
|
+
if (decorator = decorators[i])
|
|
7
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
8
|
+
if (kind && result) __defProp(target, key, result);
|
|
9
|
+
return result;
|
|
10
|
+
};
|
|
11
|
+
var __decorateParam = (index, decorator) => (target, key) => decorator(target, key, index);
|
|
12
|
+
|
|
13
|
+
// src/decorators.ts
|
|
14
|
+
import { SetMetadata } from "@nestjs/common";
|
|
15
|
+
|
|
16
|
+
// src/constants.ts
|
|
17
|
+
var INERTIA_MODULE_OPTIONS = /* @__PURE__ */ Symbol("INERTIA_MODULE_OPTIONS");
|
|
18
|
+
var INERTIA_COMPONENT_METADATA = "inertia-node:component";
|
|
19
|
+
var INERTIA_RENDER_OPTIONS_METADATA = "inertia-node:render-options";
|
|
20
|
+
|
|
21
|
+
// src/decorators.ts
|
|
22
|
+
function inertiaDecorator(component, options = {}) {
|
|
23
|
+
return (target, propertyKey, descriptor) => {
|
|
24
|
+
SetMetadata(INERTIA_COMPONENT_METADATA, component)(
|
|
25
|
+
target,
|
|
26
|
+
propertyKey,
|
|
27
|
+
descriptor
|
|
28
|
+
);
|
|
29
|
+
SetMetadata(INERTIA_RENDER_OPTIONS_METADATA, options)(
|
|
30
|
+
target,
|
|
31
|
+
propertyKey,
|
|
32
|
+
descriptor
|
|
33
|
+
);
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
var Inertia = Object.assign(inertiaDecorator, {
|
|
37
|
+
render(component, props = {}, options = {}) {
|
|
38
|
+
return {
|
|
39
|
+
__inertiaNest: "render",
|
|
40
|
+
component,
|
|
41
|
+
props,
|
|
42
|
+
options
|
|
43
|
+
};
|
|
44
|
+
},
|
|
45
|
+
redirect(location, status) {
|
|
46
|
+
return {
|
|
47
|
+
__inertiaNest: "redirect",
|
|
48
|
+
location,
|
|
49
|
+
status
|
|
50
|
+
};
|
|
51
|
+
},
|
|
52
|
+
location(location) {
|
|
53
|
+
return {
|
|
54
|
+
__inertiaNest: "location",
|
|
55
|
+
location
|
|
56
|
+
};
|
|
57
|
+
},
|
|
58
|
+
backWithErrors(errors, options = {}) {
|
|
59
|
+
return {
|
|
60
|
+
__inertiaNest: "backWithErrors",
|
|
61
|
+
errors,
|
|
62
|
+
options
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
function InertiaRenderOptions(options) {
|
|
67
|
+
return SetMetadata(INERTIA_RENDER_OPTIONS_METADATA, options);
|
|
68
|
+
}
|
|
69
|
+
function isInertiaControllerResult(value) {
|
|
70
|
+
return typeof value === "object" && value !== null && "__inertiaNest" in value && typeof value.__inertiaNest === "string";
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// src/guards.ts
|
|
74
|
+
import {
|
|
75
|
+
Inject,
|
|
76
|
+
Injectable
|
|
77
|
+
} from "@nestjs/common";
|
|
78
|
+
|
|
79
|
+
// src/runtime.ts
|
|
80
|
+
import {
|
|
81
|
+
always,
|
|
82
|
+
validationError
|
|
83
|
+
} from "@inertia-node/core";
|
|
84
|
+
function prepareInertiaRequest(request, options) {
|
|
85
|
+
const sessionStore = options.session?.(request);
|
|
86
|
+
const inertiaRequest = request;
|
|
87
|
+
inertiaRequest.flash = async (key, value) => {
|
|
88
|
+
await sessionStore?.flash("flash", {
|
|
89
|
+
...await sessionStore.get("flash") ?? {},
|
|
90
|
+
[key]: value
|
|
91
|
+
});
|
|
92
|
+
};
|
|
93
|
+
if (options.auth && !inertiaRequest.auth) {
|
|
94
|
+
installAuth(inertiaRequest, options.auth);
|
|
95
|
+
}
|
|
96
|
+
return sessionStore;
|
|
97
|
+
}
|
|
98
|
+
function sendProtocolResponse(request, response, sessionStore, protocol) {
|
|
99
|
+
if (protocol.status === 409) {
|
|
100
|
+
void sessionStore?.reflash();
|
|
101
|
+
void request.session?.save?.();
|
|
102
|
+
}
|
|
103
|
+
response.status(protocol.status);
|
|
104
|
+
for (const [name, value] of Object.entries(protocol.headers)) {
|
|
105
|
+
response.setHeader(name, value);
|
|
106
|
+
}
|
|
107
|
+
response.send(protocol.body);
|
|
108
|
+
}
|
|
109
|
+
function toInertiaRequest(request) {
|
|
110
|
+
return {
|
|
111
|
+
headers: request.headers,
|
|
112
|
+
method: request.method,
|
|
113
|
+
url: request.url,
|
|
114
|
+
originalUrl: request.originalUrl,
|
|
115
|
+
protocol: request.protocol,
|
|
116
|
+
host: request.get("host"),
|
|
117
|
+
raw: request
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
async function resolveUserShare(options, context) {
|
|
121
|
+
const request = context.request.raw;
|
|
122
|
+
if (!request || !options.auth) {
|
|
123
|
+
return {};
|
|
124
|
+
}
|
|
125
|
+
prepareInertiaRequest(request, options);
|
|
126
|
+
return {
|
|
127
|
+
auth: always({
|
|
128
|
+
user: await request.auth?.serializedUser()
|
|
129
|
+
})
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
async function flashErrors(session, payload, withAllErrors = false) {
|
|
133
|
+
const normalized = normalizeErrors(payload.errors, withAllErrors);
|
|
134
|
+
if (payload.bag) {
|
|
135
|
+
await session.flash("errors", {
|
|
136
|
+
[payload.bag]: normalized
|
|
137
|
+
});
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
await session.flash("errors", normalized);
|
|
141
|
+
}
|
|
142
|
+
async function pullErrors(session, request, withAllErrors = false) {
|
|
143
|
+
const errors = await session.pull("errors");
|
|
144
|
+
if (!errors) {
|
|
145
|
+
return {};
|
|
146
|
+
}
|
|
147
|
+
const bag = typeof request?.headers["x-inertia-error-bag"] === "string" ? request.headers["x-inertia-error-bag"] : void 0;
|
|
148
|
+
if (bag && bag in errors) {
|
|
149
|
+
return {
|
|
150
|
+
[bag]: normalizeErrors(
|
|
151
|
+
errors[bag],
|
|
152
|
+
withAllErrors
|
|
153
|
+
)
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
return normalizeErrors(errors, withAllErrors);
|
|
157
|
+
}
|
|
158
|
+
function validationPayloadForRequest(request, errors, options = {}) {
|
|
159
|
+
return validationError(errors, {
|
|
160
|
+
bag: options.bag ?? (typeof request.headers["x-inertia-error-bag"] === "string" ? request.headers["x-inertia-error-bag"] : void 0)
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
function installAuth(request, config) {
|
|
164
|
+
let loaded = false;
|
|
165
|
+
let cachedUser = null;
|
|
166
|
+
async function user() {
|
|
167
|
+
if (!loaded) {
|
|
168
|
+
cachedUser = await config.getUser(request);
|
|
169
|
+
loaded = true;
|
|
170
|
+
request.user = cachedUser ?? void 0;
|
|
171
|
+
}
|
|
172
|
+
return cachedUser;
|
|
173
|
+
}
|
|
174
|
+
const runtime = {
|
|
175
|
+
user,
|
|
176
|
+
check: async () => await user() !== null,
|
|
177
|
+
login: async (loginUser) => {
|
|
178
|
+
await config.login(request, loginUser);
|
|
179
|
+
cachedUser = loginUser;
|
|
180
|
+
loaded = true;
|
|
181
|
+
request.user = loginUser;
|
|
182
|
+
},
|
|
183
|
+
logout: async () => {
|
|
184
|
+
await config.logout(request);
|
|
185
|
+
cachedUser = null;
|
|
186
|
+
loaded = true;
|
|
187
|
+
request.user = void 0;
|
|
188
|
+
},
|
|
189
|
+
serializedUser: async () => {
|
|
190
|
+
const currentUser = await user();
|
|
191
|
+
if (!currentUser) {
|
|
192
|
+
return null;
|
|
193
|
+
}
|
|
194
|
+
return config.serializeUser ? await config.serializeUser(currentUser) : currentUser;
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
request.auth = runtime;
|
|
198
|
+
}
|
|
199
|
+
function normalizeErrors(errors, withAllErrors) {
|
|
200
|
+
const normalized = {};
|
|
201
|
+
for (const [field, value] of Object.entries(errors)) {
|
|
202
|
+
const messages = Array.isArray(value) ? value.flat().map(String) : [String(value)];
|
|
203
|
+
normalized[field] = withAllErrors ? messages : messages[0] ?? "";
|
|
204
|
+
}
|
|
205
|
+
return normalized;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// src/guards.ts
|
|
209
|
+
var InertiaAuthGuard = class {
|
|
210
|
+
constructor(options) {
|
|
211
|
+
this.options = options;
|
|
212
|
+
}
|
|
213
|
+
options;
|
|
214
|
+
async canActivate(context) {
|
|
215
|
+
const request = context.switchToHttp().getRequest();
|
|
216
|
+
const response = context.switchToHttp().getResponse();
|
|
217
|
+
prepareInertiaRequest(request, this.options);
|
|
218
|
+
if (request.auth && await request.auth.check()) {
|
|
219
|
+
request.user = await request.auth.user();
|
|
220
|
+
return true;
|
|
221
|
+
}
|
|
222
|
+
response.redirect(303, this.options.auth?.redirectTo ?? "/login");
|
|
223
|
+
return false;
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
InertiaAuthGuard = __decorateClass([
|
|
227
|
+
Injectable(),
|
|
228
|
+
__decorateParam(0, Inject(INERTIA_MODULE_OPTIONS))
|
|
229
|
+
], InertiaAuthGuard);
|
|
230
|
+
var InertiaGuestGuard = class {
|
|
231
|
+
constructor(options) {
|
|
232
|
+
this.options = options;
|
|
233
|
+
}
|
|
234
|
+
options;
|
|
235
|
+
async canActivate(context) {
|
|
236
|
+
const request = context.switchToHttp().getRequest();
|
|
237
|
+
const response = context.switchToHttp().getResponse();
|
|
238
|
+
prepareInertiaRequest(request, this.options);
|
|
239
|
+
if (request.auth && await request.auth.check()) {
|
|
240
|
+
response.redirect(303, this.options.auth?.home ?? "/dashboard");
|
|
241
|
+
return false;
|
|
242
|
+
}
|
|
243
|
+
return true;
|
|
244
|
+
}
|
|
245
|
+
};
|
|
246
|
+
InertiaGuestGuard = __decorateClass([
|
|
247
|
+
Injectable(),
|
|
248
|
+
__decorateParam(0, Inject(INERTIA_MODULE_OPTIONS))
|
|
249
|
+
], InertiaGuestGuard);
|
|
250
|
+
|
|
251
|
+
// src/interceptor.ts
|
|
252
|
+
import {
|
|
253
|
+
Inject as Inject2,
|
|
254
|
+
Injectable as Injectable2
|
|
255
|
+
} from "@nestjs/common";
|
|
256
|
+
import { Reflector } from "@nestjs/core";
|
|
257
|
+
import {
|
|
258
|
+
always as always2,
|
|
259
|
+
createInertia
|
|
260
|
+
} from "@inertia-node/core";
|
|
261
|
+
import { mergeMap } from "rxjs";
|
|
262
|
+
var InertiaInterceptor = class {
|
|
263
|
+
constructor(options, reflector) {
|
|
264
|
+
this.options = options;
|
|
265
|
+
this.reflector = reflector;
|
|
266
|
+
this.inertia = options.instance ?? createInertia({
|
|
267
|
+
...options,
|
|
268
|
+
share: async (context) => {
|
|
269
|
+
const request = context.request.raw;
|
|
270
|
+
const sessionStore = request ? options.session?.(request) : void 0;
|
|
271
|
+
const userShare = await resolveUserShare(options, context);
|
|
272
|
+
const baseShare = typeof options.share === "function" ? await options.share(context) : options.share ?? {};
|
|
273
|
+
return {
|
|
274
|
+
errors: always2(
|
|
275
|
+
sessionStore ? await pullErrors(sessionStore, request, options.withAllErrors) : {}
|
|
276
|
+
),
|
|
277
|
+
flash: always2(
|
|
278
|
+
sessionStore ? await sessionStore.pull("flash") ?? {} : {}
|
|
279
|
+
),
|
|
280
|
+
...userShare,
|
|
281
|
+
...baseShare
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
options;
|
|
287
|
+
reflector;
|
|
288
|
+
inertia;
|
|
289
|
+
intercept(context, next) {
|
|
290
|
+
const http = context.switchToHttp();
|
|
291
|
+
const request = http.getRequest();
|
|
292
|
+
prepareInertiaRequest(request, this.options);
|
|
293
|
+
return next.handle().pipe(
|
|
294
|
+
mergeMap(async (result) => {
|
|
295
|
+
const handled = await this.handleResult(context, result);
|
|
296
|
+
return handled.handled ? void 0 : result;
|
|
297
|
+
})
|
|
298
|
+
);
|
|
299
|
+
}
|
|
300
|
+
async handleResult(context, result) {
|
|
301
|
+
const http = context.switchToHttp();
|
|
302
|
+
const request = http.getRequest();
|
|
303
|
+
const response = http.getResponse();
|
|
304
|
+
const sessionStore = prepareInertiaRequest(request, this.options);
|
|
305
|
+
if (isInertiaControllerResult(result)) {
|
|
306
|
+
switch (result.__inertiaNest) {
|
|
307
|
+
case "render":
|
|
308
|
+
await this.sendRender(request, response, sessionStore, result);
|
|
309
|
+
return { handled: true };
|
|
310
|
+
case "redirect":
|
|
311
|
+
this.sendRedirect(request, response, sessionStore, result);
|
|
312
|
+
return { handled: true };
|
|
313
|
+
case "location":
|
|
314
|
+
this.sendLocation(request, response, sessionStore, result);
|
|
315
|
+
return { handled: true };
|
|
316
|
+
case "backWithErrors":
|
|
317
|
+
await this.sendBackWithErrors(
|
|
318
|
+
request,
|
|
319
|
+
response,
|
|
320
|
+
sessionStore,
|
|
321
|
+
result
|
|
322
|
+
);
|
|
323
|
+
return { handled: true };
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
const component = this.reflector.get(
|
|
327
|
+
INERTIA_COMPONENT_METADATA,
|
|
328
|
+
context.getHandler()
|
|
329
|
+
);
|
|
330
|
+
if (!component) {
|
|
331
|
+
return { handled: false };
|
|
332
|
+
}
|
|
333
|
+
const decoratorOptions = this.reflector.get(
|
|
334
|
+
INERTIA_RENDER_OPTIONS_METADATA,
|
|
335
|
+
context.getHandler()
|
|
336
|
+
) ?? {};
|
|
337
|
+
const props = result && typeof result === "object" && !Array.isArray(result) ? result : {};
|
|
338
|
+
await this.sendRender(request, response, sessionStore, {
|
|
339
|
+
__inertiaNest: "render",
|
|
340
|
+
component,
|
|
341
|
+
props,
|
|
342
|
+
options: decoratorOptions
|
|
343
|
+
});
|
|
344
|
+
return { handled: true };
|
|
345
|
+
}
|
|
346
|
+
async sendRender(request, response, sessionStore, result) {
|
|
347
|
+
sendProtocolResponse(
|
|
348
|
+
request,
|
|
349
|
+
response,
|
|
350
|
+
sessionStore,
|
|
351
|
+
await this.inertia.render(
|
|
352
|
+
toInertiaRequest(request),
|
|
353
|
+
result.component,
|
|
354
|
+
result.props,
|
|
355
|
+
result.options
|
|
356
|
+
)
|
|
357
|
+
);
|
|
358
|
+
}
|
|
359
|
+
sendRedirect(request, response, sessionStore, result) {
|
|
360
|
+
sendProtocolResponse(
|
|
361
|
+
request,
|
|
362
|
+
response,
|
|
363
|
+
sessionStore,
|
|
364
|
+
this.inertia.redirect(
|
|
365
|
+
toInertiaRequest(request),
|
|
366
|
+
result.location,
|
|
367
|
+
result.status
|
|
368
|
+
)
|
|
369
|
+
);
|
|
370
|
+
}
|
|
371
|
+
sendLocation(request, response, sessionStore, result) {
|
|
372
|
+
sendProtocolResponse(
|
|
373
|
+
request,
|
|
374
|
+
response,
|
|
375
|
+
sessionStore,
|
|
376
|
+
this.inertia.location(result.location)
|
|
377
|
+
);
|
|
378
|
+
}
|
|
379
|
+
async sendBackWithErrors(request, response, sessionStore, result) {
|
|
380
|
+
if (!sessionStore) {
|
|
381
|
+
throw new Error("backWithErrors requires a configured session adapter");
|
|
382
|
+
}
|
|
383
|
+
await flashErrors(
|
|
384
|
+
sessionStore,
|
|
385
|
+
validationPayloadForRequest(request, result.errors, result.options),
|
|
386
|
+
this.options.withAllErrors
|
|
387
|
+
);
|
|
388
|
+
this.sendRedirect(request, response, sessionStore, {
|
|
389
|
+
__inertiaNest: "redirect",
|
|
390
|
+
location: request.get("Referrer") ?? request.get("Referer") ?? "/"
|
|
391
|
+
});
|
|
392
|
+
}
|
|
393
|
+
};
|
|
394
|
+
InertiaInterceptor = __decorateClass([
|
|
395
|
+
Injectable2(),
|
|
396
|
+
__decorateParam(0, Inject2(INERTIA_MODULE_OPTIONS)),
|
|
397
|
+
__decorateParam(1, Inject2(Reflector))
|
|
398
|
+
], InertiaInterceptor);
|
|
399
|
+
|
|
400
|
+
// src/module.ts
|
|
401
|
+
import { Module } from "@nestjs/common";
|
|
402
|
+
|
|
403
|
+
// src/service.ts
|
|
404
|
+
import { Inject as Inject3, Injectable as Injectable3 } from "@nestjs/common";
|
|
405
|
+
var InertiaService = class {
|
|
406
|
+
constructor(options) {
|
|
407
|
+
this.options = options;
|
|
408
|
+
}
|
|
409
|
+
options;
|
|
410
|
+
render(component, props = {}, options = {}) {
|
|
411
|
+
return Inertia.render(component, props, options);
|
|
412
|
+
}
|
|
413
|
+
redirect(location, status) {
|
|
414
|
+
return Inertia.redirect(location, status);
|
|
415
|
+
}
|
|
416
|
+
location(location) {
|
|
417
|
+
return Inertia.location(location);
|
|
418
|
+
}
|
|
419
|
+
backWithErrors(errors, options = {}) {
|
|
420
|
+
return Inertia.backWithErrors(errors, options);
|
|
421
|
+
}
|
|
422
|
+
};
|
|
423
|
+
InertiaService = __decorateClass([
|
|
424
|
+
Injectable3(),
|
|
425
|
+
__decorateParam(0, Inject3(INERTIA_MODULE_OPTIONS))
|
|
426
|
+
], InertiaService);
|
|
427
|
+
|
|
428
|
+
// src/module.ts
|
|
429
|
+
var InertiaModule = class {
|
|
430
|
+
static forRoot(options = {}) {
|
|
431
|
+
return {
|
|
432
|
+
module: InertiaModule,
|
|
433
|
+
providers: [
|
|
434
|
+
{ provide: INERTIA_MODULE_OPTIONS, useValue: options },
|
|
435
|
+
InertiaService,
|
|
436
|
+
InertiaInterceptor,
|
|
437
|
+
InertiaAuthGuard,
|
|
438
|
+
InertiaGuestGuard
|
|
439
|
+
],
|
|
440
|
+
exports: [
|
|
441
|
+
INERTIA_MODULE_OPTIONS,
|
|
442
|
+
InertiaService,
|
|
443
|
+
InertiaInterceptor,
|
|
444
|
+
InertiaAuthGuard,
|
|
445
|
+
InertiaGuestGuard
|
|
446
|
+
]
|
|
447
|
+
};
|
|
448
|
+
}
|
|
449
|
+
static forRootAsync(options) {
|
|
450
|
+
return {
|
|
451
|
+
module: InertiaModule,
|
|
452
|
+
imports: options.imports,
|
|
453
|
+
providers: [
|
|
454
|
+
...createAsyncProviders(options),
|
|
455
|
+
InertiaService,
|
|
456
|
+
InertiaInterceptor,
|
|
457
|
+
InertiaAuthGuard,
|
|
458
|
+
InertiaGuestGuard
|
|
459
|
+
],
|
|
460
|
+
exports: [
|
|
461
|
+
INERTIA_MODULE_OPTIONS,
|
|
462
|
+
InertiaService,
|
|
463
|
+
InertiaInterceptor,
|
|
464
|
+
InertiaAuthGuard,
|
|
465
|
+
InertiaGuestGuard
|
|
466
|
+
]
|
|
467
|
+
};
|
|
468
|
+
}
|
|
469
|
+
};
|
|
470
|
+
InertiaModule = __decorateClass([
|
|
471
|
+
Module({})
|
|
472
|
+
], InertiaModule);
|
|
473
|
+
function createAsyncProviders(options) {
|
|
474
|
+
if (options.useFactory) {
|
|
475
|
+
return [
|
|
476
|
+
{
|
|
477
|
+
provide: INERTIA_MODULE_OPTIONS,
|
|
478
|
+
useFactory: options.useFactory,
|
|
479
|
+
inject: options.inject ?? []
|
|
480
|
+
}
|
|
481
|
+
];
|
|
482
|
+
}
|
|
483
|
+
const useClass = options.useClass ?? options.useExisting;
|
|
484
|
+
if (!useClass) {
|
|
485
|
+
throw new Error(
|
|
486
|
+
"InertiaModule.forRootAsync requires useFactory, useClass, or useExisting."
|
|
487
|
+
);
|
|
488
|
+
}
|
|
489
|
+
const providers = [
|
|
490
|
+
{
|
|
491
|
+
provide: INERTIA_MODULE_OPTIONS,
|
|
492
|
+
useFactory: async (factory) => factory.createInertiaOptions(),
|
|
493
|
+
inject: [useClass]
|
|
494
|
+
}
|
|
495
|
+
];
|
|
496
|
+
if (options.useClass) {
|
|
497
|
+
providers.push({
|
|
498
|
+
provide: useClass,
|
|
499
|
+
useClass
|
|
500
|
+
});
|
|
501
|
+
}
|
|
502
|
+
return providers;
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
// src/session.ts
|
|
506
|
+
function nestExpressSessionAdapter() {
|
|
507
|
+
return (request) => {
|
|
508
|
+
const session = request.session;
|
|
509
|
+
if (!session) {
|
|
510
|
+
return void 0;
|
|
511
|
+
}
|
|
512
|
+
return {
|
|
513
|
+
get: (key) => session[key],
|
|
514
|
+
set: (key, value) => {
|
|
515
|
+
session[key] = value;
|
|
516
|
+
},
|
|
517
|
+
pull: (key) => {
|
|
518
|
+
const value = session[key];
|
|
519
|
+
delete session[key];
|
|
520
|
+
return value;
|
|
521
|
+
},
|
|
522
|
+
flash: (key, value) => {
|
|
523
|
+
session[key] = value;
|
|
524
|
+
},
|
|
525
|
+
reflash: () => {
|
|
526
|
+
}
|
|
527
|
+
};
|
|
528
|
+
};
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
// src/index.ts
|
|
532
|
+
import {
|
|
533
|
+
always as always3,
|
|
534
|
+
createInertia as createInertia2,
|
|
535
|
+
defer,
|
|
536
|
+
inertiaAuth,
|
|
537
|
+
merge,
|
|
538
|
+
optional,
|
|
539
|
+
validationError as validationError2
|
|
540
|
+
} from "@inertia-node/core";
|
|
541
|
+
export {
|
|
542
|
+
Inertia,
|
|
543
|
+
InertiaAuthGuard,
|
|
544
|
+
InertiaGuestGuard,
|
|
545
|
+
InertiaInterceptor,
|
|
546
|
+
InertiaModule,
|
|
547
|
+
InertiaRenderOptions,
|
|
548
|
+
InertiaService,
|
|
549
|
+
always3 as always,
|
|
550
|
+
createInertia2 as createInertia,
|
|
551
|
+
defer,
|
|
552
|
+
inertiaAuth,
|
|
553
|
+
merge,
|
|
554
|
+
nestExpressSessionAdapter,
|
|
555
|
+
optional,
|
|
556
|
+
validationError2 as validationError
|
|
557
|
+
};
|
|
558
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/decorators.ts","../src/constants.ts","../src/guards.ts","../src/runtime.ts","../src/interceptor.ts","../src/module.ts","../src/service.ts","../src/session.ts","../src/index.ts"],"sourcesContent":["import { SetMetadata } from \"@nestjs/common\";\nimport {\n INERTIA_COMPONENT_METADATA,\n INERTIA_RENDER_OPTIONS_METADATA,\n} from \"./constants.js\";\nimport type {\n InertiaBackWithErrorsResult,\n InertiaLocationResult,\n InertiaRedirectResult,\n InertiaRenderResult,\n NestRenderOptions,\n} from \"./types.js\";\nimport type {\n InputProps,\n ValidationErrorInput,\n ValidationErrorOptions,\n} from \"@inertia-node/core\";\n\nfunction inertiaDecorator(\n component: string,\n options: NestRenderOptions = {},\n): MethodDecorator {\n return (target, propertyKey, descriptor) => {\n SetMetadata(INERTIA_COMPONENT_METADATA, component)(\n target,\n propertyKey,\n descriptor,\n );\n SetMetadata(INERTIA_RENDER_OPTIONS_METADATA, options)(\n target,\n propertyKey,\n descriptor,\n );\n };\n}\n\nexport const Inertia = Object.assign(inertiaDecorator, {\n render(\n component: string,\n props: InputProps = {},\n options: NestRenderOptions = {},\n ): InertiaRenderResult {\n return {\n __inertiaNest: \"render\",\n component,\n props,\n options,\n };\n },\n\n redirect(location: string, status?: number): InertiaRedirectResult {\n return {\n __inertiaNest: \"redirect\",\n location,\n status,\n };\n },\n\n location(location: string): InertiaLocationResult {\n return {\n __inertiaNest: \"location\",\n location,\n };\n },\n\n backWithErrors(\n errors: ValidationErrorInput,\n options: ValidationErrorOptions = {},\n ): InertiaBackWithErrorsResult {\n return {\n __inertiaNest: \"backWithErrors\",\n errors,\n options,\n };\n },\n});\n\nexport function InertiaRenderOptions(\n options: NestRenderOptions,\n): MethodDecorator {\n return SetMetadata(INERTIA_RENDER_OPTIONS_METADATA, options);\n}\n\nexport function isInertiaControllerResult(\n value: unknown,\n): value is\n | InertiaRenderResult\n | InertiaRedirectResult\n | InertiaLocationResult\n | InertiaBackWithErrorsResult {\n return (\n typeof value === \"object\" &&\n value !== null &&\n \"__inertiaNest\" in value &&\n typeof (value as { __inertiaNest?: unknown }).__inertiaNest === \"string\"\n );\n}\n","export const INERTIA_MODULE_OPTIONS = Symbol(\"INERTIA_MODULE_OPTIONS\");\nexport const INERTIA_COMPONENT_METADATA = \"inertia-node:component\";\nexport const INERTIA_RENDER_OPTIONS_METADATA = \"inertia-node:render-options\";\n","import {\n CanActivate,\n ExecutionContext,\n Inject,\n Injectable,\n} from \"@nestjs/common\";\nimport type { Request, Response } from \"express\";\nimport { INERTIA_MODULE_OPTIONS } from \"./constants.js\";\nimport { prepareInertiaRequest } from \"./runtime.js\";\nimport type { NestInertiaOptions } from \"./types.js\";\n\n@Injectable()\nexport class InertiaAuthGuard implements CanActivate {\n constructor(\n @Inject(INERTIA_MODULE_OPTIONS)\n private readonly options: NestInertiaOptions,\n ) {}\n\n async canActivate(context: ExecutionContext): Promise<boolean> {\n const request = context.switchToHttp().getRequest<Request>();\n const response = context.switchToHttp().getResponse<Response>();\n prepareInertiaRequest(request, this.options);\n\n if (request.auth && (await request.auth.check())) {\n request.user = await request.auth.user();\n return true;\n }\n\n response.redirect(303, this.options.auth?.redirectTo ?? \"/login\");\n return false;\n }\n}\n\n@Injectable()\nexport class InertiaGuestGuard implements CanActivate {\n constructor(\n @Inject(INERTIA_MODULE_OPTIONS)\n private readonly options: NestInertiaOptions,\n ) {}\n\n async canActivate(context: ExecutionContext): Promise<boolean> {\n const request = context.switchToHttp().getRequest<Request>();\n const response = context.switchToHttp().getResponse<Response>();\n prepareInertiaRequest(request, this.options);\n\n if (request.auth && (await request.auth.check())) {\n response.redirect(303, this.options.auth?.home ?? \"/dashboard\");\n return false;\n }\n\n return true;\n }\n}\n","import {\n always,\n validationError,\n type AuthConfig,\n type AuthRuntime,\n type InertiaRequest,\n type InputProps,\n type ProtocolResponse,\n type SessionStore,\n type ValidationErrorInput,\n type ValidationErrorPayload,\n} from \"@inertia-node/core\";\nimport type { Request, Response } from \"express\";\nimport type { NestInertiaOptions } from \"./types.js\";\n\nexport type NestInertiaRequest<User = unknown> = Request & {\n user?: User;\n auth?: AuthRuntime<User>;\n flash(key: string, value: unknown): Promise<void>;\n};\n\ndeclare module \"express-serve-static-core\" {\n interface Request {\n user?: unknown;\n auth?: AuthRuntime<unknown>;\n flash(key: string, value: unknown): Promise<void>;\n }\n}\n\nexport function prepareInertiaRequest(\n request: Request,\n options: NestInertiaOptions,\n): SessionStore | undefined {\n const sessionStore = options.session?.(request);\n const inertiaRequest = request as NestInertiaRequest;\n\n inertiaRequest.flash = async (key: string, value: unknown) => {\n await sessionStore?.flash(\"flash\", {\n ...((await sessionStore.get<Record<string, unknown>>(\"flash\")) ?? {}),\n [key]: value,\n });\n };\n\n if (options.auth && !inertiaRequest.auth) {\n installAuth(inertiaRequest, options.auth);\n }\n\n return sessionStore;\n}\n\nexport function sendProtocolResponse(\n request: Request,\n response: Response,\n sessionStore: SessionStore | undefined,\n protocol: ProtocolResponse,\n): void {\n if (protocol.status === 409) {\n void sessionStore?.reflash();\n void (\n request as Request & { session?: Record<string, any> }\n ).session?.save?.();\n }\n\n response.status(protocol.status);\n\n for (const [name, value] of Object.entries(protocol.headers)) {\n response.setHeader(name, value);\n }\n\n response.send(protocol.body);\n}\n\nexport function toInertiaRequest(request: Request): InertiaRequest {\n return {\n headers: request.headers,\n method: request.method,\n url: request.url,\n originalUrl: request.originalUrl,\n protocol: request.protocol,\n host: request.get(\"host\"),\n raw: request,\n };\n}\n\nexport async function resolveUserShare(\n options: NestInertiaOptions,\n context: { request: InertiaRequest },\n): Promise<InputProps> {\n const request = context.request.raw as Request | undefined;\n\n if (!request || !options.auth) {\n return {};\n }\n\n prepareInertiaRequest(request, options);\n\n return {\n auth: always({\n user: await request.auth?.serializedUser(),\n }),\n };\n}\n\nexport async function flashErrors(\n session: SessionStore,\n payload: ValidationErrorPayload,\n withAllErrors = false,\n): Promise<void> {\n const normalized = normalizeErrors(payload.errors, withAllErrors);\n\n if (payload.bag) {\n await session.flash(\"errors\", {\n [payload.bag]: normalized,\n });\n return;\n }\n\n await session.flash(\"errors\", normalized);\n}\n\nexport async function pullErrors(\n session: SessionStore,\n request?: Request,\n withAllErrors = false,\n): Promise<Record<string, unknown>> {\n const errors = await session.pull<ValidationErrorInput>(\"errors\");\n\n if (!errors) {\n return {};\n }\n\n const bag =\n typeof request?.headers[\"x-inertia-error-bag\"] === \"string\"\n ? request.headers[\"x-inertia-error-bag\"]\n : undefined;\n\n if (bag && bag in errors) {\n return {\n [bag]: normalizeErrors(\n errors[bag] as unknown as ValidationErrorInput,\n withAllErrors,\n ),\n };\n }\n\n return normalizeErrors(errors, withAllErrors);\n}\n\nexport function validationPayloadForRequest(\n request: Request,\n errors: ValidationErrorInput,\n options: { bag?: string } = {},\n): ValidationErrorPayload {\n return validationError(errors, {\n bag:\n options.bag ??\n (typeof request.headers[\"x-inertia-error-bag\"] === \"string\"\n ? request.headers[\"x-inertia-error-bag\"]\n : undefined),\n });\n}\n\nfunction installAuth<User, Serialized>(\n request: NestInertiaRequest<User>,\n config: AuthConfig<Request, User, Serialized>,\n): void {\n let loaded = false;\n let cachedUser: User | null = null;\n\n async function user(): Promise<User | null> {\n if (!loaded) {\n cachedUser = await config.getUser(request);\n loaded = true;\n request.user = cachedUser ?? undefined;\n }\n\n return cachedUser;\n }\n\n const runtime = {\n user,\n check: async () => (await user()) !== null,\n login: async (loginUser: User) => {\n await config.login(request, loginUser);\n cachedUser = loginUser;\n loaded = true;\n request.user = loginUser;\n },\n logout: async () => {\n await config.logout(request);\n cachedUser = null;\n loaded = true;\n request.user = undefined;\n },\n serializedUser: async () => {\n const currentUser = await user();\n\n if (!currentUser) {\n return null;\n }\n\n return config.serializeUser\n ? await config.serializeUser(currentUser)\n : (currentUser as unknown as Serialized);\n },\n } satisfies AuthRuntime<User, Serialized>;\n\n (request as Request & { auth?: AuthRuntime<User, Serialized> }).auth =\n runtime;\n}\n\nfunction normalizeErrors(\n errors: ValidationErrorInput,\n withAllErrors: boolean,\n): Record<string, string | string[]> {\n const normalized: Record<string, string | string[]> = {};\n\n for (const [field, value] of Object.entries(errors)) {\n const messages = Array.isArray(value)\n ? value.flat().map(String)\n : [String(value)];\n normalized[field] = withAllErrors ? messages : (messages[0] ?? \"\");\n }\n\n return normalized;\n}\n","import {\n CallHandler,\n ExecutionContext,\n Inject,\n Injectable,\n NestInterceptor,\n} from \"@nestjs/common\";\nimport { Reflector } from \"@nestjs/core\";\nimport {\n always,\n createInertia,\n type InertiaInstance,\n type InputProps,\n} from \"@inertia-node/core\";\nimport type { Request, Response } from \"express\";\nimport { mergeMap, type Observable } from \"rxjs\";\nimport {\n INERTIA_COMPONENT_METADATA,\n INERTIA_MODULE_OPTIONS,\n INERTIA_RENDER_OPTIONS_METADATA,\n} from \"./constants.js\";\nimport { isInertiaControllerResult } from \"./decorators.js\";\nimport {\n flashErrors,\n prepareInertiaRequest,\n pullErrors,\n resolveUserShare,\n sendProtocolResponse,\n toInertiaRequest,\n validationPayloadForRequest,\n} from \"./runtime.js\";\nimport type {\n InertiaBackWithErrorsResult,\n InertiaLocationResult,\n InertiaRedirectResult,\n InertiaRenderResult,\n NestInertiaOptions,\n NestRenderOptions,\n} from \"./types.js\";\nimport type { SessionStore } from \"@inertia-node/core\";\n\n@Injectable()\nexport class InertiaInterceptor implements NestInterceptor {\n private readonly inertia: InertiaInstance;\n\n constructor(\n @Inject(INERTIA_MODULE_OPTIONS)\n private readonly options: NestInertiaOptions,\n @Inject(Reflector)\n private readonly reflector: Reflector,\n ) {\n this.inertia =\n options.instance ??\n createInertia({\n ...options,\n share: async (context) => {\n const request = context.request.raw as Request | undefined;\n const sessionStore = request ? options.session?.(request) : undefined;\n const userShare = await resolveUserShare(options, context);\n const baseShare =\n typeof options.share === \"function\"\n ? await options.share(context)\n : (options.share ?? {});\n\n return {\n errors: always(\n sessionStore\n ? await pullErrors(sessionStore, request, options.withAllErrors)\n : {},\n ),\n flash: always(\n sessionStore ? ((await sessionStore.pull(\"flash\")) ?? {}) : {},\n ),\n ...userShare,\n ...baseShare,\n };\n },\n });\n }\n\n intercept(context: ExecutionContext, next: CallHandler): Observable<unknown> {\n const http = context.switchToHttp();\n const request = http.getRequest<Request>();\n prepareInertiaRequest(request, this.options);\n\n return next.handle().pipe(\n mergeMap(async (result: unknown) => {\n const handled = await this.handleResult(context, result);\n return handled.handled ? undefined : result;\n }),\n );\n }\n\n private async handleResult(\n context: ExecutionContext,\n result: unknown,\n ): Promise<{ handled: boolean }> {\n const http = context.switchToHttp();\n const request = http.getRequest<Request>();\n const response = http.getResponse<Response>();\n const sessionStore = prepareInertiaRequest(request, this.options);\n\n if (isInertiaControllerResult(result)) {\n switch (result.__inertiaNest) {\n case \"render\":\n await this.sendRender(request, response, sessionStore, result);\n return { handled: true };\n case \"redirect\":\n this.sendRedirect(request, response, sessionStore, result);\n return { handled: true };\n case \"location\":\n this.sendLocation(request, response, sessionStore, result);\n return { handled: true };\n case \"backWithErrors\":\n await this.sendBackWithErrors(\n request,\n response,\n sessionStore,\n result,\n );\n return { handled: true };\n }\n }\n\n const component = this.reflector.get<string>(\n INERTIA_COMPONENT_METADATA,\n context.getHandler(),\n );\n\n if (!component) {\n return { handled: false };\n }\n\n const decoratorOptions =\n this.reflector.get<NestRenderOptions>(\n INERTIA_RENDER_OPTIONS_METADATA,\n context.getHandler(),\n ) ?? {};\n\n const props =\n result && typeof result === \"object\" && !Array.isArray(result)\n ? (result as InputProps)\n : {};\n\n await this.sendRender(request, response, sessionStore, {\n __inertiaNest: \"render\",\n component,\n props,\n options: decoratorOptions,\n });\n\n return { handled: true };\n }\n\n private async sendRender(\n request: Request,\n response: Response,\n sessionStore: SessionStore | undefined,\n result: InertiaRenderResult,\n ): Promise<void> {\n sendProtocolResponse(\n request,\n response,\n sessionStore,\n await this.inertia.render(\n toInertiaRequest(request),\n result.component,\n result.props,\n result.options,\n ),\n );\n }\n\n private sendRedirect(\n request: Request,\n response: Response,\n sessionStore: SessionStore | undefined,\n result: InertiaRedirectResult,\n ): void {\n sendProtocolResponse(\n request,\n response,\n sessionStore,\n this.inertia.redirect(\n toInertiaRequest(request),\n result.location,\n result.status,\n ),\n );\n }\n\n private sendLocation(\n request: Request,\n response: Response,\n sessionStore: SessionStore | undefined,\n result: InertiaLocationResult,\n ): void {\n sendProtocolResponse(\n request,\n response,\n sessionStore,\n this.inertia.location(result.location),\n );\n }\n\n private async sendBackWithErrors(\n request: Request,\n response: Response,\n sessionStore: SessionStore | undefined,\n result: InertiaBackWithErrorsResult,\n ): Promise<void> {\n if (!sessionStore) {\n throw new Error(\"backWithErrors requires a configured session adapter\");\n }\n\n await flashErrors(\n sessionStore,\n validationPayloadForRequest(request, result.errors, result.options),\n this.options.withAllErrors,\n );\n\n this.sendRedirect(request, response, sessionStore, {\n __inertiaNest: \"redirect\",\n location: request.get(\"Referrer\") ?? request.get(\"Referer\") ?? \"/\",\n });\n }\n}\n","import { DynamicModule, Module, Provider, type Type } from \"@nestjs/common\";\nimport { INERTIA_MODULE_OPTIONS } from \"./constants.js\";\nimport { InertiaAuthGuard, InertiaGuestGuard } from \"./guards.js\";\nimport { InertiaInterceptor } from \"./interceptor.js\";\nimport { InertiaService } from \"./service.js\";\nimport type {\n NestInertiaAsyncOptions,\n NestInertiaOptions,\n NestInertiaOptionsFactory,\n} from \"./types.js\";\n\n@Module({})\nexport class InertiaModule {\n static forRoot(options: NestInertiaOptions = {}): DynamicModule {\n return {\n module: InertiaModule,\n providers: [\n { provide: INERTIA_MODULE_OPTIONS, useValue: options },\n InertiaService,\n InertiaInterceptor,\n InertiaAuthGuard,\n InertiaGuestGuard,\n ],\n exports: [\n INERTIA_MODULE_OPTIONS,\n InertiaService,\n InertiaInterceptor,\n InertiaAuthGuard,\n InertiaGuestGuard,\n ],\n };\n }\n\n static forRootAsync(options: NestInertiaAsyncOptions): DynamicModule {\n return {\n module: InertiaModule,\n imports: options.imports,\n providers: [\n ...createAsyncProviders(options),\n InertiaService,\n InertiaInterceptor,\n InertiaAuthGuard,\n InertiaGuestGuard,\n ],\n exports: [\n INERTIA_MODULE_OPTIONS,\n InertiaService,\n InertiaInterceptor,\n InertiaAuthGuard,\n InertiaGuestGuard,\n ],\n };\n }\n}\n\nfunction createAsyncProviders(options: NestInertiaAsyncOptions): Provider[] {\n if (options.useFactory) {\n return [\n {\n provide: INERTIA_MODULE_OPTIONS,\n useFactory: options.useFactory,\n inject: options.inject ?? [],\n },\n ];\n }\n\n const useClass = options.useClass ?? options.useExisting;\n\n if (!useClass) {\n throw new Error(\n \"InertiaModule.forRootAsync requires useFactory, useClass, or useExisting.\",\n );\n }\n\n const providers: Provider[] = [\n {\n provide: INERTIA_MODULE_OPTIONS,\n useFactory: async (factory: NestInertiaOptionsFactory) =>\n factory.createInertiaOptions(),\n inject: [useClass],\n },\n ];\n\n if (options.useClass) {\n providers.push({\n provide: useClass,\n useClass: useClass as Type<NestInertiaOptionsFactory>,\n });\n }\n\n return providers;\n}\n","import { Inject, Injectable } from \"@nestjs/common\";\nimport type {\n InputProps,\n ValidationErrorInput,\n ValidationErrorOptions,\n} from \"@inertia-node/core\";\nimport { INERTIA_MODULE_OPTIONS } from \"./constants.js\";\nimport { Inertia } from \"./decorators.js\";\nimport type { NestInertiaOptions, NestRenderOptions } from \"./types.js\";\n\n@Injectable()\nexport class InertiaService {\n constructor(\n @Inject(INERTIA_MODULE_OPTIONS)\n readonly options: NestInertiaOptions,\n ) {}\n\n render(\n component: string,\n props: InputProps = {},\n options: NestRenderOptions = {},\n ) {\n return Inertia.render(component, props, options);\n }\n\n redirect(location: string, status?: number) {\n return Inertia.redirect(location, status);\n }\n\n location(location: string) {\n return Inertia.location(location);\n }\n\n backWithErrors(\n errors: ValidationErrorInput,\n options: ValidationErrorOptions = {},\n ) {\n return Inertia.backWithErrors(errors, options);\n }\n}\n","import type { SessionStore } from \"@inertia-node/core\";\nimport type { Request } from \"express\";\n\nexport function nestExpressSessionAdapter(): (\n request: Request,\n) => SessionStore | undefined {\n return (request: Request) => {\n const session = (request as Request & { session?: Record<string, any> })\n .session;\n\n if (!session) {\n return undefined;\n }\n\n return {\n get: <T = unknown>(key: string) => session[key] as T | undefined,\n set: <T = unknown>(key: string, value: T) => {\n session[key] = value;\n },\n pull: <T = unknown>(key: string) => {\n const value = session[key] as T | undefined;\n delete session[key];\n return value;\n },\n flash: <T = unknown>(key: string, value: T) => {\n session[key] = value;\n },\n reflash: () => {\n // express-session keeps values until explicitly pulled.\n },\n };\n };\n}\n","export { Inertia, InertiaRenderOptions } from \"./decorators.js\";\nexport { InertiaAuthGuard, InertiaGuestGuard } from \"./guards.js\";\nexport { InertiaInterceptor } from \"./interceptor.js\";\nexport { InertiaModule } from \"./module.js\";\nexport { nestExpressSessionAdapter } from \"./session.js\";\nexport { InertiaService } from \"./service.js\";\nexport type {\n InertiaBackWithErrorsResult,\n InertiaControllerResult,\n InertiaLocationResult,\n InertiaRedirectResult,\n InertiaRenderResult,\n NestInertiaAsyncOptions,\n NestInertiaOptions,\n NestInertiaOptionsFactory,\n NestRenderOptions,\n} from \"./types.js\";\nexport type { NestInertiaRequest } from \"./runtime.js\";\nexport {\n always,\n createInertia,\n defer,\n inertiaAuth,\n merge,\n optional,\n validationError,\n} from \"@inertia-node/core\";\nexport type {\n AuthConfig,\n AuthRuntime,\n CreateInertiaOptions,\n InertiaInstance,\n InputProps,\n ProtocolResponse,\n RenderOptions,\n SessionStore,\n ValidationErrorInput,\n ValidationErrorOptions,\n ValidationErrorPayload,\n} from \"@inertia-node/core\";\n"],"mappings":";;;;;;;;;;;;;AAAA,SAAS,mBAAmB;;;ACArB,IAAM,yBAAyB,uBAAO,wBAAwB;AAC9D,IAAM,6BAA6B;AACnC,IAAM,kCAAkC;;;ADgB/C,SAAS,iBACP,WACA,UAA6B,CAAC,GACb;AACjB,SAAO,CAAC,QAAQ,aAAa,eAAe;AAC1C,gBAAY,4BAA4B,SAAS;AAAA,MAC/C;AAAA,MACA;AAAA,MACA;AAAA,IACF;AACA,gBAAY,iCAAiC,OAAO;AAAA,MAClD;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACF;AAEO,IAAM,UAAU,OAAO,OAAO,kBAAkB;AAAA,EACrD,OACE,WACA,QAAoB,CAAC,GACrB,UAA6B,CAAC,GACT;AACrB,WAAO;AAAA,MACL,eAAe;AAAA,MACf;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF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,CAAC;AAAA,EACH;AAEA,SAAO;AACT;;;AExFO,SAAS,4BAEc;AAC5B,SAAO,CAAC,YAAqB;AAC3B,UAAM,UAAW,QACd;AAEH,QAAI,CAAC,SAAS;AACZ,aAAO;AAAA,IACT;AAEA,WAAO;AAAA,MACL,KAAK,CAAc,QAAgB,QAAQ,GAAG;AAAA,MAC9C,KAAK,CAAc,KAAa,UAAa;AAC3C,gBAAQ,GAAG,IAAI;AAAA,MACjB;AAAA,MACA,MAAM,CAAc,QAAgB;AAClC,cAAM,QAAQ,QAAQ,GAAG;AACzB,eAAO,QAAQ,GAAG;AAClB,eAAO;AAAA,MACT;AAAA,MACA,OAAO,CAAc,KAAa,UAAa;AAC7C,gBAAQ,GAAG,IAAI;AAAA,MACjB;AAAA,MACA,SAAS,MAAM;AAAA,MAEf;AAAA,IACF;AAAA,EACF;AACF;;;ACdA;AAAA,EACE,UAAAC;AAAA,EACA,iBAAAC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,mBAAAC;AAAA,OACK;","names":["Inject","Injectable","always","always","Injectable","Inject","Inject","Injectable","Injectable","Inject","always","createInertia","validationError"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@inertia-node/nest",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "NestJS adapter for Inertia.js on Node.js.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Inertia Node Adapter contributors",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "https://github.com/inertia-node/inertia-node-adapter.git",
|
|
11
|
+
"directory": "packages/nest"
|
|
12
|
+
},
|
|
13
|
+
"homepage": "https://github.com/inertia-node/inertia-node-adapter#readme",
|
|
14
|
+
"bugs": {
|
|
15
|
+
"url": "https://github.com/inertia-node/inertia-node-adapter/issues"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"inertia",
|
|
19
|
+
"inertiajs",
|
|
20
|
+
"nestjs",
|
|
21
|
+
"node",
|
|
22
|
+
"react",
|
|
23
|
+
"typescript"
|
|
24
|
+
],
|
|
25
|
+
"publishConfig": {
|
|
26
|
+
"access": "public"
|
|
27
|
+
},
|
|
28
|
+
"exports": {
|
|
29
|
+
".": {
|
|
30
|
+
"types": "./dist/index.d.ts",
|
|
31
|
+
"import": "./dist/index.js"
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
"files": [
|
|
35
|
+
"dist"
|
|
36
|
+
],
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"@inertia-node/core": "0.1.0"
|
|
39
|
+
},
|
|
40
|
+
"peerDependencies": {
|
|
41
|
+
"@nestjs/common": ">=10 <12",
|
|
42
|
+
"@nestjs/core": ">=10 <12",
|
|
43
|
+
"express": ">=4.18 <6",
|
|
44
|
+
"reflect-metadata": ">=0.1 <1",
|
|
45
|
+
"rxjs": ">=7 <8"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"@nestjs/common": "^11.1.9",
|
|
49
|
+
"@nestjs/core": "^11.1.9",
|
|
50
|
+
"@nestjs/platform-express": "^11.1.9",
|
|
51
|
+
"@nestjs/testing": "^11.1.9",
|
|
52
|
+
"@types/express": "^5.0.6",
|
|
53
|
+
"@types/express-session": "^1.18.2",
|
|
54
|
+
"@types/supertest": "^6.0.3",
|
|
55
|
+
"express": "^5.2.1",
|
|
56
|
+
"express-session": "^1.18.2",
|
|
57
|
+
"reflect-metadata": "^0.2.2",
|
|
58
|
+
"rxjs": "^7.8.2",
|
|
59
|
+
"supertest": "^7.1.4"
|
|
60
|
+
},
|
|
61
|
+
"engines": {
|
|
62
|
+
"node": ">=20"
|
|
63
|
+
},
|
|
64
|
+
"scripts": {
|
|
65
|
+
"build": "tsup src/index.ts --format esm --dts --sourcemap",
|
|
66
|
+
"clean": "rm -rf dist"
|
|
67
|
+
}
|
|
68
|
+
}
|