@mastra/nestjs 0.2.15 → 0.2.16-alpha.1
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/CHANGELOG.md +20 -0
- package/dist/controllers/mastra.controller.d.ts.map +1 -1
- package/dist/index.cjs +19 -16
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +19 -16
- package/dist/index.js.map +1 -1
- package/dist/services/auth.service.d.ts.map +1 -1
- package/dist/utils/to-web-request.d.ts +7 -0
- package/dist/utils/to-web-request.d.ts.map +1 -0
- package/package.json +7 -7
package/dist/index.js
CHANGED
|
@@ -363,6 +363,22 @@ let MastraExceptionFilter = _MastraExceptionFilter = class MastraExceptionFilter
|
|
|
363
363
|
};
|
|
364
364
|
MastraExceptionFilter = _MastraExceptionFilter = __decorate([Catch()], MastraExceptionFilter);
|
|
365
365
|
//#endregion
|
|
366
|
+
//#region src/utils/to-web-request.ts
|
|
367
|
+
/**
|
|
368
|
+
* Convert an Express request to a Web API Request.
|
|
369
|
+
* Auth providers and route handlers expect this canonical header/cookie shape.
|
|
370
|
+
*/
|
|
371
|
+
function toWebRequest(req) {
|
|
372
|
+
const url = `${req.protocol || "http"}://${req.get("host") || "localhost"}${req.originalUrl || req.url}`;
|
|
373
|
+
const headers = new Headers();
|
|
374
|
+
for (const [key, value] of Object.entries(req.headers)) if (value) if (Array.isArray(value)) value.forEach((v) => headers.append(key, v));
|
|
375
|
+
else headers.set(key, value);
|
|
376
|
+
return new globalThis.Request(url, {
|
|
377
|
+
method: req.method,
|
|
378
|
+
headers
|
|
379
|
+
});
|
|
380
|
+
}
|
|
381
|
+
//#endregion
|
|
366
382
|
//#region src/services/auth.service.ts
|
|
367
383
|
var _AuthService;
|
|
368
384
|
let AuthService = _AuthService = class AuthService {
|
|
@@ -399,7 +415,7 @@ let AuthService = _AuthService = class AuthService {
|
|
|
399
415
|
if (!token) throw new UnauthorizedException("Authentication required");
|
|
400
416
|
try {
|
|
401
417
|
let user;
|
|
402
|
-
if (typeof authConfig?.authenticateToken === "function") user = await authConfig.authenticateToken(token, request);
|
|
418
|
+
if (typeof authConfig?.authenticateToken === "function") user = await authConfig.authenticateToken(token, toWebRequest(request));
|
|
403
419
|
else throw new Error("No token verification method configured");
|
|
404
420
|
if (!user) throw new UnauthorizedException("Invalid or expired token");
|
|
405
421
|
request.user = user;
|
|
@@ -418,7 +434,7 @@ let AuthService = _AuthService = class AuthService {
|
|
|
418
434
|
*/
|
|
419
435
|
async authorize(request, path, method, user, authConfig) {
|
|
420
436
|
if (typeof authConfig.authorizeUser === "function") {
|
|
421
|
-
if (!await authConfig.authorizeUser(user, request)) throw new ForbiddenException("Access denied");
|
|
437
|
+
if (!await authConfig.authorizeUser(user, toWebRequest(request))) throw new ForbiddenException("Access denied");
|
|
422
438
|
return;
|
|
423
439
|
}
|
|
424
440
|
if (typeof authConfig.authorize === "function") {
|
|
@@ -427,7 +443,7 @@ let AuthService = _AuthService = class AuthService {
|
|
|
427
443
|
if (key === "mastra") return this.mastra;
|
|
428
444
|
if (key === "customRouteAuthConfig") return this.options.customRouteAuthConfig;
|
|
429
445
|
},
|
|
430
|
-
req: request
|
|
446
|
+
req: toWebRequest(request)
|
|
431
447
|
};
|
|
432
448
|
if (!await authConfig.authorize(path, method, user, context)) throw new ForbiddenException("Access denied");
|
|
433
449
|
return;
|
|
@@ -10739,19 +10755,6 @@ function parseMultipartFormData(request, options = {}) {
|
|
|
10739
10755
|
}
|
|
10740
10756
|
//#endregion
|
|
10741
10757
|
//#region src/controllers/mastra.controller.ts
|
|
10742
|
-
/**
|
|
10743
|
-
* Convert Express request to Web API Request for accessing headers, cookies, etc.
|
|
10744
|
-
*/
|
|
10745
|
-
function toWebRequest(req) {
|
|
10746
|
-
const url = `${req.protocol || "http"}://${req.get("host") || "localhost"}${req.originalUrl || req.url}`;
|
|
10747
|
-
const headers = new Headers();
|
|
10748
|
-
for (const [key, value] of Object.entries(req.headers)) if (value) if (Array.isArray(value)) value.forEach((v) => headers.append(key, v));
|
|
10749
|
-
else headers.set(key, value);
|
|
10750
|
-
return new globalThis.Request(url, {
|
|
10751
|
-
method: req.method,
|
|
10752
|
-
headers
|
|
10753
|
-
});
|
|
10754
|
-
}
|
|
10755
10758
|
let MastraController = class MastraController {
|
|
10756
10759
|
options;
|
|
10757
10760
|
routeHandler;
|