@mastra/nestjs 0.2.29 → 0.2.30-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/dist/controllers/mastra.controller.d.ts +6 -2
- package/dist/controllers/mastra.controller.d.ts.map +1 -1
- package/dist/guards/mastra-auth.guard.d.ts +3 -9
- package/dist/guards/mastra-auth.guard.d.ts.map +1 -1
- package/dist/guards/mastra-route.guard.d.ts +1 -3
- package/dist/guards/mastra-route.guard.d.ts.map +1 -1
- package/dist/index.cjs +261 -84
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +256 -85
- package/dist/index.js.map +1 -1
- package/dist/mastra.module.d.ts.map +1 -1
- package/dist/services/auth.service.d.ts +25 -15
- package/dist/services/auth.service.d.ts.map +1 -1
- package/dist/services/custom-route.service.d.ts +30 -0
- package/dist/services/custom-route.service.d.ts.map +1 -0
- package/package.json +8 -7
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mastra.module.d.ts","sourceRoot":"","sources":["../src/mastra.module.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAElE,OAAO,KAAK,EAAE,aAAa,EAAE,kBAAkB,EAAE,UAAU,EAAY,IAAI,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"mastra.module.d.ts","sourceRoot":"","sources":["../src/mastra.module.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BA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;;;;;;;;;;;;;;;GAsCG;AACH,qBACa,YAAa,YAAW,UAAU;IAC7C;;;;;OAKG;IACH,MAAM,CAAC,QAAQ,CAAC,OAAO,EAAE,mBAAmB,GAAG,aAAa,CA6C3D;IAED;;;;;OAKG;IACH,MAAM,CAAC,aAAa,CAAC,OAAO,EAAE,wBAAwB,GAAG,aAAa,CAmFrE;IAED;;;;;;OAMG;IACH,SAAS,CAAC,QAAQ,EAAE,kBAAkB,GAAG,IAAI,CAI5C;CACF"}
|
|
@@ -1,30 +1,40 @@
|
|
|
1
1
|
import type { Mastra } from '@mastra/core/mastra';
|
|
2
|
-
import
|
|
2
|
+
import { RequestContext } from '@mastra/core/request-context';
|
|
3
|
+
import type { Request, Response } from 'express';
|
|
3
4
|
import type { MastraModuleOptions } from '../mastra.module.js';
|
|
5
|
+
import { CustomRouteService } from './custom-route.service.js';
|
|
6
|
+
export interface AuthenticateOptions {
|
|
7
|
+
/** Request context that receives the user, auth token, and mapped resource ID. */
|
|
8
|
+
requestContext?: RequestContext;
|
|
9
|
+
/** Response used to forward session refresh headers (e.g. Set-Cookie). */
|
|
10
|
+
response?: Response;
|
|
11
|
+
/** Force authentication even for publicly accessible paths. */
|
|
12
|
+
requiresAuth?: boolean;
|
|
13
|
+
/** Set when `requiresAuth` comes from a matched `server.apiRoutes` entry. */
|
|
14
|
+
customRoute?: boolean;
|
|
15
|
+
}
|
|
4
16
|
/**
|
|
5
17
|
* Service that handles authentication for Mastra routes.
|
|
6
|
-
*
|
|
18
|
+
* Delegates to the shared `coreAuthMiddleware` so NestJS behaves like the
|
|
19
|
+
* other server adapters (cookie sessions, session refresh, RBAC,
|
|
20
|
+
* `mapUserToResourceId`).
|
|
7
21
|
*/
|
|
8
22
|
export declare class AuthService {
|
|
9
23
|
private readonly mastra;
|
|
10
24
|
private readonly options;
|
|
11
|
-
private readonly
|
|
12
|
-
constructor(mastra: Mastra, options: MastraModuleOptions);
|
|
25
|
+
private readonly customRoutes;
|
|
26
|
+
constructor(mastra: Mastra, options: MastraModuleOptions, customRoutes: CustomRouteService);
|
|
13
27
|
/**
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* Throws UnauthorizedException or ForbiddenException if auth fails.
|
|
17
|
-
*
|
|
18
|
-
* Type assertions (`as any`) are used because `@mastra/server/auth` types
|
|
19
|
-
* are Hono-centric. The runtime values work with Express requests.
|
|
28
|
+
* Whether Mastra auth should run: module options enable it, or the Mastra
|
|
29
|
+
* server has auth configured (unless module options explicitly disable it).
|
|
20
30
|
*/
|
|
21
|
-
|
|
31
|
+
isEnabled(): boolean;
|
|
22
32
|
/**
|
|
23
|
-
* Check
|
|
24
|
-
*
|
|
25
|
-
*
|
|
33
|
+
* Check authentication for a request.
|
|
34
|
+
* Returns the authenticated user if auth succeeds, undefined if no auth required.
|
|
35
|
+
* Throws UnauthorizedException or ForbiddenException if auth fails.
|
|
26
36
|
*/
|
|
27
|
-
|
|
37
|
+
authenticate(request: Request, options?: AuthenticateOptions): Promise<unknown>;
|
|
28
38
|
/**
|
|
29
39
|
* Extract authentication token from request.
|
|
30
40
|
* Supports Authorization header (Bearer token) and API key query param.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.service.d.ts","sourceRoot":"","sources":["../../src/services/auth.service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"auth.service.d.ts","sourceRoot":"","sources":["../../src/services/auth.service.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAI9D,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAGjD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAE5D,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAE5D,MAAM,WAAW,mBAAmB;IAClC,kFAAkF;IAClF,cAAc,CAAC,EAAE,cAAc,CAAC;IAChC,0EAA0E;IAC1E,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,+DAA+D;IAC/D,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,6EAA6E;IAC7E,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAED;;;;;GAKG;AACH,qBACa,WAAW;IAEJ,OAAO,CAAC,QAAQ,CAAC,MAAM;IACf,OAAO,CAAC,QAAQ,CAAC,OAAO;IACpB,OAAO,CAAC,QAAQ,CAAC,YAAY;IAH3D,YACmC,MAAM,EAAE,MAAM,EACN,OAAO,EAAE,mBAAmB,EACxB,YAAY,EAAE,kBAAkB,EAC3E;IAEJ;;;OAGG;IACH,SAAS,IAAI,OAAO,CAGnB;IAED;;;;OAIG;IACG,YAAY,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,GAAE,mBAAwB,GAAG,OAAO,CAAC,OAAO,CAAC,CAiExF;IAED;;;OAGG;IACH,OAAO,CAAC,YAAY;CAuBrB"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { Mastra } from '@mastra/core/mastra';
|
|
2
|
+
import { RequestContext } from '@mastra/core/request-context';
|
|
3
|
+
import type { Request, Response as ExpressResponse } from 'express';
|
|
4
|
+
import type { MastraModuleOptions } from '../mastra.module.js';
|
|
5
|
+
/** Authenticates a matched custom route. Throws to reject the request. */
|
|
6
|
+
export type CustomRouteAuthenticate = (requiresAuth: boolean) => Promise<void>;
|
|
7
|
+
/**
|
|
8
|
+
* Serves custom routes registered with `registerApiRoute()` via `server.apiRoutes`,
|
|
9
|
+
* matching the behavior of the other Mastra server adapters.
|
|
10
|
+
*/
|
|
11
|
+
export declare class CustomRouteService {
|
|
12
|
+
private readonly mastra;
|
|
13
|
+
private readonly routes;
|
|
14
|
+
private readonly authConfig;
|
|
15
|
+
private fetchPromise?;
|
|
16
|
+
constructor(mastra: Mastra, options: MastraModuleOptions);
|
|
17
|
+
/** Auth config for custom routes, keyed by `METHOD:path`. */
|
|
18
|
+
get customRouteAuthConfig(): Map<string, boolean>;
|
|
19
|
+
/**
|
|
20
|
+
* Runs a matched custom route and writes its response.
|
|
21
|
+
* Returns false if no custom route handled the request.
|
|
22
|
+
*
|
|
23
|
+
* `authenticate` runs after Hono's router selects the route, so auth is enforced
|
|
24
|
+
* for exactly the routes Hono dispatches (including regex-constrained params).
|
|
25
|
+
*/
|
|
26
|
+
handle(req: Request, res: ExpressResponse, requestContext: RequestContext, authenticate: CustomRouteAuthenticate): Promise<boolean>;
|
|
27
|
+
private build;
|
|
28
|
+
private toFetchRequest;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=custom-route.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"custom-route.service.d.ts","sourceRoot":"","sources":["../../src/services/custom-route.service.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAG9D,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,IAAI,eAAe,EAAE,MAAM,SAAS,CAAC;AAIpE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAM5D,0EAA0E;AAC1E,MAAM,MAAM,uBAAuB,GAAG,CAAC,YAAY,EAAE,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;AAM/E;;;GAGG;AACH,qBACa,kBAAkB;IAMX,OAAO,CAAC,QAAQ,CAAC,MAAM;IALzC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAiB;IACxC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAuB;IAClD,OAAO,CAAC,YAAY,CAAC,CAA4B;IAEjD,YACmC,MAAM,EAAE,MAAM,EACvB,OAAO,EAAE,mBAAmB,EAYrD;IAED,6DAA6D;IAC7D,IAAI,qBAAqB,IAAI,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAEhD;IAED;;;;;;OAMG;IACG,MAAM,CACV,GAAG,EAAE,OAAO,EACZ,GAAG,EAAE,eAAe,EACpB,cAAc,EAAE,cAAc,EAC9B,YAAY,EAAE,uBAAuB,GACpC,OAAO,CAAC,OAAO,CAAC,CAmDlB;YAEa,KAAK;IAiEnB,OAAO,CAAC,cAAc;CAgCvB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/nestjs",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.30-alpha.1",
|
|
4
4
|
"description": "Mastra NestJS adapter for the server",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -21,7 +21,8 @@
|
|
|
21
21
|
"license": "Apache-2.0",
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"@fastify/busboy": "^3.2.2",
|
|
24
|
-
"
|
|
24
|
+
"hono": "^4.13.7",
|
|
25
|
+
"@mastra/server": "1.71.0-alpha.1"
|
|
25
26
|
},
|
|
26
27
|
"devDependencies": {
|
|
27
28
|
"@ai-sdk/openai": "^2.0.115",
|
|
@@ -43,15 +44,15 @@
|
|
|
43
44
|
"typescript": "^7.0.2",
|
|
44
45
|
"vitest": "^4.1.11",
|
|
45
46
|
"zod": "^3.25.0",
|
|
46
|
-
"@internal/types-builder": "0.0.111",
|
|
47
47
|
"@internal/lint": "0.0.136",
|
|
48
48
|
"@mastra/server-adapters-test-suite": "0.1.0",
|
|
49
|
+
"@internal/types-builder": "0.0.111",
|
|
49
50
|
"@internal/storage-test-utils": "0.0.132",
|
|
50
|
-
"@mastra/core": "1.70.0",
|
|
51
51
|
"@mastra/evals": "1.10.2",
|
|
52
|
-
"@mastra/libsql": "1.23.
|
|
53
|
-
"@mastra/
|
|
54
|
-
"@mastra/memory": "1.32.0"
|
|
52
|
+
"@mastra/libsql": "1.23.3-alpha.0",
|
|
53
|
+
"@mastra/core": "1.71.0-alpha.1",
|
|
54
|
+
"@mastra/memory": "1.32.1-alpha.0",
|
|
55
|
+
"@mastra/observability": "1.18.1-alpha.0"
|
|
55
56
|
},
|
|
56
57
|
"peerDependencies": {
|
|
57
58
|
"@mastra/core": ">=1.58.0-0 <2.0.0-0",
|