@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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# @mastra/nestjs
|
|
2
2
|
|
|
3
|
+
## 0.2.16-alpha.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Fixed NestJS auth passing a Web Request to authenticateToken and authorize hooks so cookie-based providers (such as Better Auth) no longer fail with 401 on valid credentials. ([#21258](https://github.com/mastra-ai/mastra/pull/21258))
|
|
8
|
+
|
|
9
|
+
Resolves https://github.com/mastra-ai/mastra/issues/21253
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [[`aa3e7be`](https://github.com/mastra-ai/mastra/commit/aa3e7be30f8addb0278ea74429f4df054517a287), [`90822db`](https://github.com/mastra-ai/mastra/commit/90822dba08fb2169c518e4a6d7f127c098eb46b8), [`3700208`](https://github.com/mastra-ai/mastra/commit/37002080c7838267803a7e579a7d58b908d62f36), [`8b7131e`](https://github.com/mastra-ai/mastra/commit/8b7131eb0407f58f5205e68fb27b81f026488f28), [`79c4f82`](https://github.com/mastra-ai/mastra/commit/79c4f8295f568752eeadf8a9b50010a7d9ec06ae)]:
|
|
12
|
+
- @mastra/core@1.59.0-alpha.1
|
|
13
|
+
- @mastra/server@1.59.0-alpha.1
|
|
14
|
+
|
|
15
|
+
## 0.2.16-alpha.0
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- Updated dependencies [[`088e41e`](https://github.com/mastra-ai/mastra/commit/088e41e434ed05f2c674b254f1034ec46a57a7be), [`b2f0013`](https://github.com/mastra-ai/mastra/commit/b2f0013375588d40c03c13e843b99c0ff8872ca5), [`3b541ae`](https://github.com/mastra-ai/mastra/commit/3b541ae5d410c52b80a7e381d84d021cddb9a449), [`ae79e34`](https://github.com/mastra-ai/mastra/commit/ae79e34c0bd8674fc24c7524217bfc4a051c6136), [`a6c4399`](https://github.com/mastra-ai/mastra/commit/a6c4399763590b3dae21a2c81826e89a3b1deee4)]:
|
|
20
|
+
- @mastra/core@1.59.0-alpha.0
|
|
21
|
+
- @mastra/server@1.59.0-alpha.0
|
|
22
|
+
|
|
3
23
|
## 0.2.15
|
|
4
24
|
|
|
5
25
|
### Patch Changes
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mastra.controller.d.ts","sourceRoot":"","sources":["../../src/controllers/mastra.controller.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"mastra.controller.d.ts","sourceRoot":"","sources":["../../src/controllers/mastra.controller.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAQjD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EAAE,qBAAqB,EAAE,MAAM,qCAAqC,CAAC;AAC5E,OAAO,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AAKxE;;;;;;GAMG;AACH,qBAIa,gBAAgB;IAED,OAAO,CAAC,QAAQ,CAAC,OAAO;IACnB,OAAO,CAAC,QAAQ,CAAC,YAAY;IAC3B,OAAO,CAAC,QAAQ,CAAC,cAAc;gBAFrB,OAAO,EAAE,mBAAmB,EACvB,YAAY,EAAE,mBAAmB,EAC/B,cAAc,EAAE,qBAAqB;IAGvF;;OAEG;IAEG,aAAa,CAAQ,GAAG,EAAE,OAAO,EAA8B,IAAI,EAAE,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC;IAoCtG;;;;;;;;;OASG;IACH,OAAO,CAAC,gBAAgB;IAoBxB;;OAEG;YACW,SAAS;CAsBxB"}
|
package/dist/index.cjs
CHANGED
|
@@ -385,6 +385,22 @@ let MastraExceptionFilter = _MastraExceptionFilter = class MastraExceptionFilter
|
|
|
385
385
|
};
|
|
386
386
|
MastraExceptionFilter = _MastraExceptionFilter = __decorate([(0, _nestjs_common.Catch)()], MastraExceptionFilter);
|
|
387
387
|
//#endregion
|
|
388
|
+
//#region src/utils/to-web-request.ts
|
|
389
|
+
/**
|
|
390
|
+
* Convert an Express request to a Web API Request.
|
|
391
|
+
* Auth providers and route handlers expect this canonical header/cookie shape.
|
|
392
|
+
*/
|
|
393
|
+
function toWebRequest(req) {
|
|
394
|
+
const url = `${req.protocol || "http"}://${req.get("host") || "localhost"}${req.originalUrl || req.url}`;
|
|
395
|
+
const headers = new Headers();
|
|
396
|
+
for (const [key, value] of Object.entries(req.headers)) if (value) if (Array.isArray(value)) value.forEach((v) => headers.append(key, v));
|
|
397
|
+
else headers.set(key, value);
|
|
398
|
+
return new globalThis.Request(url, {
|
|
399
|
+
method: req.method,
|
|
400
|
+
headers
|
|
401
|
+
});
|
|
402
|
+
}
|
|
403
|
+
//#endregion
|
|
388
404
|
//#region src/services/auth.service.ts
|
|
389
405
|
var _AuthService;
|
|
390
406
|
let AuthService = _AuthService = class AuthService {
|
|
@@ -421,7 +437,7 @@ let AuthService = _AuthService = class AuthService {
|
|
|
421
437
|
if (!token) throw new _nestjs_common.UnauthorizedException("Authentication required");
|
|
422
438
|
try {
|
|
423
439
|
let user;
|
|
424
|
-
if (typeof authConfig?.authenticateToken === "function") user = await authConfig.authenticateToken(token, request);
|
|
440
|
+
if (typeof authConfig?.authenticateToken === "function") user = await authConfig.authenticateToken(token, toWebRequest(request));
|
|
425
441
|
else throw new Error("No token verification method configured");
|
|
426
442
|
if (!user) throw new _nestjs_common.UnauthorizedException("Invalid or expired token");
|
|
427
443
|
request.user = user;
|
|
@@ -440,7 +456,7 @@ let AuthService = _AuthService = class AuthService {
|
|
|
440
456
|
*/
|
|
441
457
|
async authorize(request, path, method, user, authConfig) {
|
|
442
458
|
if (typeof authConfig.authorizeUser === "function") {
|
|
443
|
-
if (!await authConfig.authorizeUser(user, request)) throw new _nestjs_common.ForbiddenException("Access denied");
|
|
459
|
+
if (!await authConfig.authorizeUser(user, toWebRequest(request))) throw new _nestjs_common.ForbiddenException("Access denied");
|
|
444
460
|
return;
|
|
445
461
|
}
|
|
446
462
|
if (typeof authConfig.authorize === "function") {
|
|
@@ -449,7 +465,7 @@ let AuthService = _AuthService = class AuthService {
|
|
|
449
465
|
if (key === "mastra") return this.mastra;
|
|
450
466
|
if (key === "customRouteAuthConfig") return this.options.customRouteAuthConfig;
|
|
451
467
|
},
|
|
452
|
-
req: request
|
|
468
|
+
req: toWebRequest(request)
|
|
453
469
|
};
|
|
454
470
|
if (!await authConfig.authorize(path, method, user, context)) throw new _nestjs_common.ForbiddenException("Access denied");
|
|
455
471
|
return;
|
|
@@ -10761,19 +10777,6 @@ function parseMultipartFormData(request, options = {}) {
|
|
|
10761
10777
|
}
|
|
10762
10778
|
//#endregion
|
|
10763
10779
|
//#region src/controllers/mastra.controller.ts
|
|
10764
|
-
/**
|
|
10765
|
-
* Convert Express request to Web API Request for accessing headers, cookies, etc.
|
|
10766
|
-
*/
|
|
10767
|
-
function toWebRequest(req) {
|
|
10768
|
-
const url = `${req.protocol || "http"}://${req.get("host") || "localhost"}${req.originalUrl || req.url}`;
|
|
10769
|
-
const headers = new Headers();
|
|
10770
|
-
for (const [key, value] of Object.entries(req.headers)) if (value) if (Array.isArray(value)) value.forEach((v) => headers.append(key, v));
|
|
10771
|
-
else headers.set(key, value);
|
|
10772
|
-
return new globalThis.Request(url, {
|
|
10773
|
-
method: req.method,
|
|
10774
|
-
headers
|
|
10775
|
-
});
|
|
10776
|
-
}
|
|
10777
10780
|
let MastraController = class MastraController {
|
|
10778
10781
|
options;
|
|
10779
10782
|
routeHandler;
|