@mastra/auth 1.1.0 → 1.1.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 +12 -0
- package/dist/_types/@internal_auth/dist/_types/@internal_core/dist/base/index.d.ts +31 -0
- package/dist/_types/@internal_auth/dist/_types/@internal_core/dist/logger/index.d.ts +217 -0
- package/dist/_types/@internal_auth/dist/ee/capabilities.d.ts +142 -0
- package/dist/_types/@internal_auth/dist/ee/defaults/index.d.ts +8 -0
- package/dist/_types/@internal_auth/dist/ee/defaults/rbac/index.d.ts +7 -0
- package/dist/_types/@internal_auth/dist/ee/defaults/rbac/static.d.ts +106 -0
- package/dist/_types/@internal_auth/dist/ee/defaults/roles.d.ts +92 -0
- package/dist/_types/@internal_auth/dist/ee/fga-check.d.ts +62 -0
- package/dist/_types/@internal_auth/dist/ee/index.d.ts +15 -0
- package/dist/_types/@internal_auth/dist/ee/interfaces/acl.d.ts +140 -0
- package/dist/_types/@internal_auth/dist/ee/interfaces/fga.d.ts +350 -0
- package/dist/_types/@internal_auth/dist/ee/interfaces/index.d.ts +15 -0
- package/dist/_types/@internal_auth/dist/ee/interfaces/permissions.generated.d.ts +519 -0
- package/dist/_types/@internal_auth/dist/ee/interfaces/rbac.d.ts +207 -0
- package/dist/_types/@internal_auth/dist/ee/interfaces/user.d.ts +18 -0
- package/dist/_types/@internal_auth/dist/ee/license.d.ts +171 -0
- package/dist/_types/@internal_auth/dist/index.d.ts +277 -0
- package/dist/_types/@internal_auth/dist/provider/index.d.ts +125 -0
- package/dist/_types/@internal_auth/dist/session/cookie.d.ts +82 -0
- package/dist/_types/@internal_auth/dist/session/index.d.ts +30 -0
- package/dist/_types/@internal_auth/dist/session/memory.d.ts +60 -0
- package/dist/_types/@internal_auth/dist/types/index.d.ts +52 -0
- package/dist/docs/SKILL.md +1 -1
- package/dist/docs/assets/SOURCE_MAP.json +1 -1
- package/dist/docs/references/docs-server-auth.md +2 -1
- package/dist/index.cjs +182 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +181 -1
- package/dist/index.js.map +1 -1
- package/dist/jwt.d.ts +3 -3
- package/dist/jwt.d.ts.map +1 -1
- package/package.json +4 -7
- package/LICENSE.md +0 -30
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { MastraBase } from '../_types/@internal_core/dist/base/index.d.ts';
|
|
2
|
+
import type { CredentialsResult, ISSOProvider, ISessionProvider, IUserProvider, Session, SSOCallbackResult, SSOLoginConfig, User } from '..';
|
|
3
|
+
import type { AuthorizeUserFn, MastraAuthConfig, MastraAuthRequest } from '../types/index.js';
|
|
4
|
+
export interface MastraAuthProviderOptions<TUser = unknown> {
|
|
5
|
+
name?: string;
|
|
6
|
+
authorizeUser?: AuthorizeUserFn<TUser>;
|
|
7
|
+
mapUserToResourceId?(user: TUser): string | undefined | null;
|
|
8
|
+
/**
|
|
9
|
+
* Protected paths for the auth provider
|
|
10
|
+
*/
|
|
11
|
+
protected?: MastraAuthConfig['protected'];
|
|
12
|
+
/**
|
|
13
|
+
* Public paths for the auth provider
|
|
14
|
+
*/
|
|
15
|
+
public?: MastraAuthConfig['public'];
|
|
16
|
+
}
|
|
17
|
+
export declare abstract class MastraAuthProvider<TUser = unknown> extends MastraBase {
|
|
18
|
+
protected?: MastraAuthConfig['protected'];
|
|
19
|
+
public?: MastraAuthConfig['public'];
|
|
20
|
+
mapUserToResourceId?(user: TUser): string | undefined | null;
|
|
21
|
+
constructor(options?: MastraAuthProviderOptions<TUser>);
|
|
22
|
+
/**
|
|
23
|
+
* Authenticate a token and return the payload
|
|
24
|
+
* @param token - The token to authenticate
|
|
25
|
+
* @param request - The request
|
|
26
|
+
* @returns The payload
|
|
27
|
+
*/
|
|
28
|
+
abstract authenticateToken(token: string, request: MastraAuthRequest): Promise<TUser | null>;
|
|
29
|
+
/**
|
|
30
|
+
* Authorize a user for a path and method
|
|
31
|
+
* @param user - The user to authorize
|
|
32
|
+
* @param request - The request
|
|
33
|
+
* @returns The authorization result
|
|
34
|
+
*/
|
|
35
|
+
abstract authorizeUser(user: TUser, request: MastraAuthRequest): Promise<boolean> | boolean;
|
|
36
|
+
protected registerOptions(opts?: MastraAuthProviderOptions<TUser>): void;
|
|
37
|
+
}
|
|
38
|
+
export declare class CompositeAuth extends MastraAuthProvider implements ISSOProvider<User>, ISessionProvider<Session>, IUserProvider<User> {
|
|
39
|
+
private providers;
|
|
40
|
+
private authenticatedProviderByObject;
|
|
41
|
+
private authenticatedProviderByPrimitive;
|
|
42
|
+
constructor(providers: MastraAuthProvider[]);
|
|
43
|
+
private findProvider;
|
|
44
|
+
private rememberAuthenticatedProvider;
|
|
45
|
+
private takeAuthenticatedProvider;
|
|
46
|
+
private mapAuthenticatedUserToResourceId;
|
|
47
|
+
/**
|
|
48
|
+
* True if any provider is MastraCloudAuth (exempt from license requirement).
|
|
49
|
+
*/
|
|
50
|
+
get isMastraCloudAuth(): boolean;
|
|
51
|
+
/**
|
|
52
|
+
* True if any provider is SimpleAuth (exempt from license requirement).
|
|
53
|
+
*/
|
|
54
|
+
get isSimpleAuth(): boolean;
|
|
55
|
+
authenticateToken(token: string, request: MastraAuthRequest): Promise<unknown | null>;
|
|
56
|
+
authorizeUser(user: unknown, request: MastraAuthRequest): Promise<boolean>;
|
|
57
|
+
/**
|
|
58
|
+
* Forward cookie header to SSO provider for PKCE validation.
|
|
59
|
+
* Called by auth handler before handleCallback().
|
|
60
|
+
*/
|
|
61
|
+
setCallbackCookieHeader(cookieHeader: string | null): void;
|
|
62
|
+
getLoginUrl(redirectUri: string, state: string): string | Promise<string>;
|
|
63
|
+
getLoginCookies(redirectUri: string, state: string): string[] | undefined;
|
|
64
|
+
handleCallback(code: string, state: string): Promise<SSOCallbackResult<User>>;
|
|
65
|
+
getLoginButtonConfig(): SSOLoginConfig;
|
|
66
|
+
getLogoutUrl(redirectUri: string, request?: Request): Promise<string | null>;
|
|
67
|
+
createSession(userId: string, metadata?: Record<string, unknown>): Promise<Session>;
|
|
68
|
+
validateSession(sessionId: string): Promise<Session | null>;
|
|
69
|
+
destroySession(sessionId: string): Promise<void>;
|
|
70
|
+
refreshSession(sessionId: string): Promise<Session | null>;
|
|
71
|
+
getSessionIdFromRequest(request: Request): string | null;
|
|
72
|
+
getSessionHeaders(session: Session): Record<string, string>;
|
|
73
|
+
getClearSessionHeaders(): Record<string, string>;
|
|
74
|
+
getCurrentUser(request: Request): Promise<User | null>;
|
|
75
|
+
getUser(userId: string): Promise<User | null>;
|
|
76
|
+
getUsers(userIds: string[]): Promise<Array<User | null>>;
|
|
77
|
+
}
|
|
78
|
+
type TokenToUser<TUser> = Record<string, TUser>;
|
|
79
|
+
export interface SimpleAuthOptions<TUser> extends MastraAuthProviderOptions<TUser> {
|
|
80
|
+
/**
|
|
81
|
+
* Valid tokens to authenticate against
|
|
82
|
+
*/
|
|
83
|
+
tokens: TokenToUser<TUser>;
|
|
84
|
+
/**
|
|
85
|
+
* Headers to check for authentication
|
|
86
|
+
* @default ['Authorization', 'X-Playground-Access']
|
|
87
|
+
*/
|
|
88
|
+
headers?: string | string[];
|
|
89
|
+
}
|
|
90
|
+
export declare class SimpleAuth<TUser> extends MastraAuthProvider<TUser> {
|
|
91
|
+
/**
|
|
92
|
+
* Marker to exempt SimpleAuth from EE license requirement.
|
|
93
|
+
* SimpleAuth is for development/testing and should work without a license.
|
|
94
|
+
*/
|
|
95
|
+
readonly isSimpleAuth = true;
|
|
96
|
+
private tokens;
|
|
97
|
+
private headers;
|
|
98
|
+
private users;
|
|
99
|
+
private userById;
|
|
100
|
+
constructor(options: SimpleAuthOptions<TUser>);
|
|
101
|
+
authenticateToken(token: string, request: MastraAuthRequest): Promise<TUser | null>;
|
|
102
|
+
authorizeUser(user: TUser, _request: MastraAuthRequest): Promise<boolean>;
|
|
103
|
+
/** Get current user from request headers or cookie. */
|
|
104
|
+
getCurrentUser(request: Request): Promise<TUser | null>;
|
|
105
|
+
private getUserFromCookie;
|
|
106
|
+
/** Get user by ID. */
|
|
107
|
+
getUser(userId: string): Promise<TUser | null>;
|
|
108
|
+
getUsers(userIds: string[]): Promise<Array<TUser | null>>;
|
|
109
|
+
/**
|
|
110
|
+
* Sign in with token (passed as password field).
|
|
111
|
+
* The email field is ignored - only the token matters.
|
|
112
|
+
*/
|
|
113
|
+
signIn(_email: string, password: string, _request: Request): Promise<CredentialsResult<TUser>>;
|
|
114
|
+
signUp(): Promise<CredentialsResult<TUser>>;
|
|
115
|
+
isSignUpEnabled(): boolean;
|
|
116
|
+
/**
|
|
117
|
+
* Get headers to clear the session cookie on logout.
|
|
118
|
+
* Partial ISessionProvider implementation for logout support.
|
|
119
|
+
*/
|
|
120
|
+
getClearSessionHeaders(): Record<string, string>;
|
|
121
|
+
private stripBearerPrefix;
|
|
122
|
+
private getTokensFromHeaders;
|
|
123
|
+
}
|
|
124
|
+
export {};
|
|
125
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Signed cookie session provider.
|
|
3
|
+
*
|
|
4
|
+
* Stores session data in signed cookies. No server-side storage required.
|
|
5
|
+
*/
|
|
6
|
+
import type { Session, ISessionProvider } from '..';
|
|
7
|
+
/**
|
|
8
|
+
* Options for CookieSessionProvider.
|
|
9
|
+
*/
|
|
10
|
+
export interface CookieSessionProviderOptions {
|
|
11
|
+
/** Secret for signing cookies (required) */
|
|
12
|
+
secret: string;
|
|
13
|
+
/** Session TTL in milliseconds (default: 7 days) */
|
|
14
|
+
ttl?: number;
|
|
15
|
+
/** Cookie name (default: 'mastra_session') */
|
|
16
|
+
cookieName?: string;
|
|
17
|
+
/** Cookie path (default: '/') */
|
|
18
|
+
cookiePath?: string;
|
|
19
|
+
/** Cookie domain */
|
|
20
|
+
cookieDomain?: string;
|
|
21
|
+
/** Use secure cookies (default: true in production) */
|
|
22
|
+
secure?: boolean;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Signed cookie session provider.
|
|
26
|
+
*
|
|
27
|
+
* Stores session data in signed cookies. The session is validated
|
|
28
|
+
* by verifying the signature on each request.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```typescript
|
|
32
|
+
* const sessionProvider = new CookieSessionProvider({
|
|
33
|
+
* secret: process.env.SESSION_SECRET!,
|
|
34
|
+
* ttl: 7 * 24 * 60 * 60 * 1000, // 7 days
|
|
35
|
+
* });
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export declare class CookieSessionProvider implements ISessionProvider {
|
|
39
|
+
private secret;
|
|
40
|
+
private ttl;
|
|
41
|
+
private cookieName;
|
|
42
|
+
private cookiePath;
|
|
43
|
+
private cookieDomain?;
|
|
44
|
+
private secure;
|
|
45
|
+
constructor(options: CookieSessionProviderOptions);
|
|
46
|
+
createSession(userId: string, metadata?: Record<string, unknown>): Promise<Session>;
|
|
47
|
+
validateSession(_sessionId: string): Promise<Session | null>;
|
|
48
|
+
destroySession(_sessionId: string): Promise<void>;
|
|
49
|
+
refreshSession(_sessionId: string): Promise<Session | null>;
|
|
50
|
+
getSessionIdFromRequest(request: Request): string | null;
|
|
51
|
+
/**
|
|
52
|
+
* Get full session from cookie.
|
|
53
|
+
*/
|
|
54
|
+
getSessionFromCookie(request: Request): Session | null;
|
|
55
|
+
getSessionHeaders(session: Session): Record<string, string>;
|
|
56
|
+
getClearSessionHeaders(): Record<string, string>;
|
|
57
|
+
/**
|
|
58
|
+
* Sign and encode session data.
|
|
59
|
+
*/
|
|
60
|
+
private signAndEncode;
|
|
61
|
+
/**
|
|
62
|
+
* Decode and verify session cookie.
|
|
63
|
+
*/
|
|
64
|
+
private decodeAndVerify;
|
|
65
|
+
/**
|
|
66
|
+
* Create HMAC-SHA256 signature.
|
|
67
|
+
*/
|
|
68
|
+
private sign;
|
|
69
|
+
/**
|
|
70
|
+
* Base64 encode (consistent across Node.js and browser runtimes).
|
|
71
|
+
*/
|
|
72
|
+
private base64Encode;
|
|
73
|
+
/**
|
|
74
|
+
* Base64 decode (consistent across Node.js and browser runtimes).
|
|
75
|
+
*/
|
|
76
|
+
private base64Decode;
|
|
77
|
+
/**
|
|
78
|
+
* Constant-time string comparison.
|
|
79
|
+
*/
|
|
80
|
+
private secureCompare;
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=cookie.d.ts.map
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Session object representing an authenticated session.
|
|
3
|
+
*/
|
|
4
|
+
export interface Session {
|
|
5
|
+
/** Unique session identifier */
|
|
6
|
+
id: string;
|
|
7
|
+
/** User ID this session belongs to */
|
|
8
|
+
userId: string;
|
|
9
|
+
/** When the session expires */
|
|
10
|
+
expiresAt: Date;
|
|
11
|
+
/** When the session was created */
|
|
12
|
+
createdAt: Date;
|
|
13
|
+
/** Additional session metadata */
|
|
14
|
+
metadata?: Record<string, unknown>;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Provider interface for session management.
|
|
18
|
+
*/
|
|
19
|
+
export interface ISessionProvider<TSession extends Session = Session> {
|
|
20
|
+
createSession(userId: string, metadata?: Record<string, unknown>): Promise<TSession>;
|
|
21
|
+
validateSession(sessionId: string): Promise<TSession | null>;
|
|
22
|
+
destroySession(sessionId: string): Promise<void>;
|
|
23
|
+
refreshSession(sessionId: string): Promise<TSession | null>;
|
|
24
|
+
getSessionIdFromRequest(request: Request): string | null;
|
|
25
|
+
getSessionHeaders(session: TSession): Record<string, string>;
|
|
26
|
+
getClearSessionHeaders(): Record<string, string>;
|
|
27
|
+
}
|
|
28
|
+
export { MemorySessionProvider, type MemorySessionProviderOptions } from './memory.js';
|
|
29
|
+
export { CookieSessionProvider, type CookieSessionProviderOptions } from './cookie.js';
|
|
30
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* In-memory session provider for development.
|
|
3
|
+
*
|
|
4
|
+
* WARNING: Sessions are lost on server restart. Not for production use.
|
|
5
|
+
*/
|
|
6
|
+
import type { Session, ISessionProvider } from '..';
|
|
7
|
+
/**
|
|
8
|
+
* Options for MemorySessionProvider.
|
|
9
|
+
*/
|
|
10
|
+
export interface MemorySessionProviderOptions {
|
|
11
|
+
/** Session TTL in milliseconds (default: 7 days) */
|
|
12
|
+
ttl?: number;
|
|
13
|
+
/** Cookie name (default: 'mastra_session') */
|
|
14
|
+
cookieName?: string;
|
|
15
|
+
/** Cookie path (default: '/') */
|
|
16
|
+
cookiePath?: string;
|
|
17
|
+
/** Cleanup interval in milliseconds (default: 60000) */
|
|
18
|
+
cleanupInterval?: number;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* In-memory session provider.
|
|
22
|
+
*
|
|
23
|
+
* Stores sessions in a Map. Useful for development but not suitable
|
|
24
|
+
* for production as sessions are lost on restart.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```typescript
|
|
28
|
+
* const sessionProvider = new MemorySessionProvider({
|
|
29
|
+
* ttl: 24 * 60 * 60 * 1000, // 24 hours
|
|
30
|
+
* });
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export declare class MemorySessionProvider implements ISessionProvider {
|
|
34
|
+
private sessions;
|
|
35
|
+
private ttl;
|
|
36
|
+
private cookieName;
|
|
37
|
+
private cookiePath;
|
|
38
|
+
private cleanupTimer;
|
|
39
|
+
constructor(options?: MemorySessionProviderOptions);
|
|
40
|
+
createSession(userId: string, metadata?: Record<string, unknown>): Promise<Session>;
|
|
41
|
+
validateSession(sessionId: string): Promise<Session | null>;
|
|
42
|
+
destroySession(sessionId: string): Promise<void>;
|
|
43
|
+
refreshSession(sessionId: string): Promise<Session | null>;
|
|
44
|
+
getSessionIdFromRequest(request: Request): string | null;
|
|
45
|
+
getSessionHeaders(session: Session): Record<string, string>;
|
|
46
|
+
getClearSessionHeaders(): Record<string, string>;
|
|
47
|
+
/**
|
|
48
|
+
* Clean up expired sessions.
|
|
49
|
+
*/
|
|
50
|
+
private cleanup;
|
|
51
|
+
/**
|
|
52
|
+
* Stop the cleanup timer.
|
|
53
|
+
*/
|
|
54
|
+
dispose(): void;
|
|
55
|
+
/**
|
|
56
|
+
* Get the number of active sessions (for debugging).
|
|
57
|
+
*/
|
|
58
|
+
getSessionCount(): number;
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=memory.d.ts.map
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
export interface HonoRequestLike {
|
|
2
|
+
raw?: Request;
|
|
3
|
+
headers?: Headers;
|
|
4
|
+
header(name: string): string | undefined;
|
|
5
|
+
}
|
|
6
|
+
export type MastraAuthRequest = Request | HonoRequestLike;
|
|
7
|
+
export type AuthenticateTokenFn<TUser, TResult = Promise<TUser | null>> = {
|
|
8
|
+
bivarianceHack(token: string, request: MastraAuthRequest): TResult;
|
|
9
|
+
}['bivarianceHack'];
|
|
10
|
+
export type AuthorizeUserFn<TUser, TResult = Promise<boolean> | boolean> = {
|
|
11
|
+
bivarianceHack(user: TUser, request: MastraAuthRequest): TResult;
|
|
12
|
+
}['bivarianceHack'];
|
|
13
|
+
export declare function getRequestHeader(request: MastraAuthRequest, name: string): string | null;
|
|
14
|
+
export declare function getWebRequest(request: MastraAuthRequest): Request | undefined;
|
|
15
|
+
export type Methods = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'ALL';
|
|
16
|
+
export type MastraAuthConfig<TUser = unknown, TContext = unknown> = {
|
|
17
|
+
/**
|
|
18
|
+
* Protected paths for the server.
|
|
19
|
+
*/
|
|
20
|
+
protected?: (RegExp | string | [string, Methods | Methods[]])[];
|
|
21
|
+
/**
|
|
22
|
+
* Public paths for the server.
|
|
23
|
+
*/
|
|
24
|
+
public?: (RegExp | string | [string, Methods | Methods[]])[];
|
|
25
|
+
/**
|
|
26
|
+
* Authenticate a token and return the user.
|
|
27
|
+
*/
|
|
28
|
+
authenticateToken?: AuthenticateTokenFn<TUser, Promise<TUser>>;
|
|
29
|
+
/**
|
|
30
|
+
* Maps the authenticated user to a resource ID for memory/thread scoping.
|
|
31
|
+
*/
|
|
32
|
+
mapUserToResourceId?(user: TUser): string | undefined | null;
|
|
33
|
+
/**
|
|
34
|
+
* Authorization function for the server.
|
|
35
|
+
*/
|
|
36
|
+
authorize?: (path: string, method: string, user: TUser, context: TContext) => Promise<boolean>;
|
|
37
|
+
/**
|
|
38
|
+
* Rules for the server.
|
|
39
|
+
*/
|
|
40
|
+
rules?: {
|
|
41
|
+
/** Path for the rule. */
|
|
42
|
+
path?: RegExp | string | string[];
|
|
43
|
+
/** Method for the rule. */
|
|
44
|
+
methods?: Methods | Methods[];
|
|
45
|
+
/** Condition for the rule. */
|
|
46
|
+
condition?: (user: TUser) => Promise<boolean> | boolean;
|
|
47
|
+
/** Allow the rule. */
|
|
48
|
+
allow?: boolean;
|
|
49
|
+
}[];
|
|
50
|
+
};
|
|
51
|
+
export type { MastraAuthProviderOptions } from '../provider/index.js';
|
|
52
|
+
//# sourceMappingURL=index.d.ts.map
|
package/dist/docs/SKILL.md
CHANGED
|
@@ -15,7 +15,7 @@ Authentication is optional. If no auth is configured, all routes and Studio are
|
|
|
15
15
|
|
|
16
16
|
See [Custom API Routes](https://mastra.ai/docs/server/custom-api-routes) for controlling authentication on custom endpoints. Visit the [Studio Auth docs](https://mastra.ai/docs/studio/auth) for more on securing your Studio deployment.
|
|
17
17
|
|
|
18
|
-
> **Note:** Authentication for Studio is currently supported by the following providers: Simple Auth, JWT, WorkOS,
|
|
18
|
+
> **Note:** Authentication for Studio is currently supported by the following providers: Simple Auth, JWT, WorkOS, Better Auth, and Google.
|
|
19
19
|
|
|
20
20
|
## Available providers
|
|
21
21
|
|
|
@@ -30,6 +30,7 @@ See [Custom API Routes](https://mastra.ai/docs/server/custom-api-routes) for con
|
|
|
30
30
|
- [Better Auth](https://mastra.ai/docs/server/auth/better-auth)
|
|
31
31
|
- [Clerk](https://mastra.ai/docs/server/auth/clerk)
|
|
32
32
|
- [Firebase](https://mastra.ai/docs/server/auth/firebase)
|
|
33
|
+
- [Google](https://mastra.ai/docs/server/auth/google)
|
|
33
34
|
- [Okta](https://mastra.ai/docs/server/auth/okta)
|
|
34
35
|
- [Supabase](https://mastra.ai/docs/server/auth/supabase)
|
|
35
36
|
- [WorkOS](https://mastra.ai/docs/server/auth/workos)
|
package/dist/index.cjs
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
var jwt = require('jsonwebtoken');
|
|
4
4
|
var jwksClient = require('jwks-rsa');
|
|
5
|
-
var server = require('@mastra/core/server');
|
|
6
5
|
|
|
7
6
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
8
7
|
|
|
@@ -33,6 +32,187 @@ async function verifyJwks(accessToken, jwksUri) {
|
|
|
33
32
|
const signingKey = key.getPublicKey();
|
|
34
33
|
return jwt__default.default.verify(accessToken, signingKey);
|
|
35
34
|
}
|
|
35
|
+
|
|
36
|
+
// ../_internal-core/dist/chunk-3M4SEWMI.js
|
|
37
|
+
var RegisteredLogger = {
|
|
38
|
+
LLM: "LLM"};
|
|
39
|
+
var LogLevel = {
|
|
40
|
+
DEBUG: "debug",
|
|
41
|
+
INFO: "info",
|
|
42
|
+
WARN: "warn",
|
|
43
|
+
ERROR: "error"};
|
|
44
|
+
var MastraLogger = class {
|
|
45
|
+
name;
|
|
46
|
+
level;
|
|
47
|
+
transports;
|
|
48
|
+
constructor(options = {}) {
|
|
49
|
+
this.name = options.name || "Mastra";
|
|
50
|
+
this.level = options.level || LogLevel.ERROR;
|
|
51
|
+
this.transports = new Map(Object.entries(options.transports || {}));
|
|
52
|
+
}
|
|
53
|
+
getTransports() {
|
|
54
|
+
return this.transports;
|
|
55
|
+
}
|
|
56
|
+
trackException(_error, _metadata) {
|
|
57
|
+
}
|
|
58
|
+
async listLogs(transportId, params) {
|
|
59
|
+
if (!transportId || !this.transports.has(transportId)) {
|
|
60
|
+
return { logs: [], total: 0, page: params?.page ?? 1, perPage: params?.perPage ?? 100, hasMore: false };
|
|
61
|
+
}
|
|
62
|
+
return this.transports.get(transportId).listLogs?.(params) ?? {
|
|
63
|
+
logs: [],
|
|
64
|
+
total: 0,
|
|
65
|
+
page: params?.page ?? 1,
|
|
66
|
+
perPage: params?.perPage ?? 100,
|
|
67
|
+
hasMore: false
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
async listLogsByRunId({
|
|
71
|
+
transportId,
|
|
72
|
+
runId,
|
|
73
|
+
fromDate,
|
|
74
|
+
toDate,
|
|
75
|
+
logLevel,
|
|
76
|
+
filters,
|
|
77
|
+
page,
|
|
78
|
+
perPage
|
|
79
|
+
}) {
|
|
80
|
+
if (!transportId || !this.transports.has(transportId) || !runId) {
|
|
81
|
+
return { logs: [], total: 0, page: page ?? 1, perPage: perPage ?? 100, hasMore: false };
|
|
82
|
+
}
|
|
83
|
+
return this.transports.get(transportId).listLogsByRunId?.({ runId, fromDate, toDate, logLevel, filters, page, perPage }) ?? {
|
|
84
|
+
logs: [],
|
|
85
|
+
total: 0,
|
|
86
|
+
page: page ?? 1,
|
|
87
|
+
perPage: perPage ?? 100,
|
|
88
|
+
hasMore: false
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
var ConsoleLogger = class _ConsoleLogger extends MastraLogger {
|
|
93
|
+
component;
|
|
94
|
+
filter;
|
|
95
|
+
constructor(options = {}) {
|
|
96
|
+
super(options);
|
|
97
|
+
this.component = options.component;
|
|
98
|
+
this.filter = options.filter;
|
|
99
|
+
}
|
|
100
|
+
child(componentOrBindings) {
|
|
101
|
+
const component = typeof componentOrBindings === "string" ? componentOrBindings : componentOrBindings?.component ?? this.component;
|
|
102
|
+
return new _ConsoleLogger({
|
|
103
|
+
name: this.name,
|
|
104
|
+
level: this.level,
|
|
105
|
+
component,
|
|
106
|
+
filter: this.filter
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
shouldLog(level, message, args) {
|
|
110
|
+
if (!this.filter) return true;
|
|
111
|
+
try {
|
|
112
|
+
return this.filter({ component: this.component, level, message, args });
|
|
113
|
+
} catch (e) {
|
|
114
|
+
console.error(`[Logger] Filter error for component=${this.component} level=${level}:`, e);
|
|
115
|
+
return true;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
prefix() {
|
|
119
|
+
return this.component ? `[${this.component}] ` : "";
|
|
120
|
+
}
|
|
121
|
+
debug(message, ...args) {
|
|
122
|
+
if (this.level === LogLevel.DEBUG && this.shouldLog(LogLevel.DEBUG, message, args)) {
|
|
123
|
+
console.info(`${this.prefix()}${message}`, ...args);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
info(message, ...args) {
|
|
127
|
+
if ((this.level === LogLevel.INFO || this.level === LogLevel.DEBUG) && this.shouldLog(LogLevel.INFO, message, args)) {
|
|
128
|
+
console.info(`${this.prefix()}${message}`, ...args);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
warn(message, ...args) {
|
|
132
|
+
if ((this.level === LogLevel.WARN || this.level === LogLevel.INFO || this.level === LogLevel.DEBUG) && this.shouldLog(LogLevel.WARN, message, args)) {
|
|
133
|
+
console.warn(`${this.prefix()}${message}`, ...args);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
error(message, ...args) {
|
|
137
|
+
if ((this.level === LogLevel.ERROR || this.level === LogLevel.WARN || this.level === LogLevel.INFO || this.level === LogLevel.DEBUG) && this.shouldLog(LogLevel.ERROR, message, args)) {
|
|
138
|
+
console.error(`${this.prefix()}${message}`, ...args);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
async listLogs(_transportId, _params) {
|
|
142
|
+
return { logs: [], total: 0, page: _params?.page ?? 1, perPage: _params?.perPage ?? 100, hasMore: false };
|
|
143
|
+
}
|
|
144
|
+
async listLogsByRunId(_args) {
|
|
145
|
+
return { logs: [], total: 0, page: _args.page ?? 1, perPage: _args.perPage ?? 100, hasMore: false };
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
// ../_internal-core/dist/base/index.js
|
|
150
|
+
var MastraBase = class {
|
|
151
|
+
component = RegisteredLogger.LLM;
|
|
152
|
+
logger;
|
|
153
|
+
name;
|
|
154
|
+
#rawConfig;
|
|
155
|
+
constructor({
|
|
156
|
+
component,
|
|
157
|
+
name,
|
|
158
|
+
rawConfig
|
|
159
|
+
}) {
|
|
160
|
+
this.component = component || RegisteredLogger.LLM;
|
|
161
|
+
this.name = name;
|
|
162
|
+
this.#rawConfig = rawConfig;
|
|
163
|
+
this.logger = new ConsoleLogger({ name: `${this.component} - ${this.name}` });
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Returns the raw storage configuration this primitive was created from,
|
|
167
|
+
* or undefined if it was created from code.
|
|
168
|
+
*/
|
|
169
|
+
toRawConfig() {
|
|
170
|
+
return this.#rawConfig;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Sets the raw storage configuration for this primitive.
|
|
174
|
+
* @internal
|
|
175
|
+
*/
|
|
176
|
+
__setRawConfig(rawConfig) {
|
|
177
|
+
this.#rawConfig = rawConfig;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Set the logger for the agent
|
|
181
|
+
* @param logger
|
|
182
|
+
*/
|
|
183
|
+
__setLogger(logger) {
|
|
184
|
+
this.logger = "child" in logger && typeof logger.child === "function" ? logger.child({ component: this.component }) : logger;
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
// ../_internals/auth/dist/chunk-XG6GH2VJ.js
|
|
189
|
+
var MastraAuthProvider = class extends MastraBase {
|
|
190
|
+
protected;
|
|
191
|
+
public;
|
|
192
|
+
constructor(options) {
|
|
193
|
+
super({ component: "AUTH", name: options?.name });
|
|
194
|
+
if (options?.authorizeUser) {
|
|
195
|
+
this.authorizeUser = options.authorizeUser.bind(this);
|
|
196
|
+
}
|
|
197
|
+
this.protected = options?.protected;
|
|
198
|
+
this.public = options?.public;
|
|
199
|
+
this.mapUserToResourceId = options?.mapUserToResourceId;
|
|
200
|
+
}
|
|
201
|
+
registerOptions(opts) {
|
|
202
|
+
if (opts?.authorizeUser) {
|
|
203
|
+
this.authorizeUser = opts.authorizeUser.bind(this);
|
|
204
|
+
}
|
|
205
|
+
if (opts?.mapUserToResourceId) {
|
|
206
|
+
this.mapUserToResourceId = opts.mapUserToResourceId;
|
|
207
|
+
}
|
|
208
|
+
if (opts?.protected) {
|
|
209
|
+
this.protected = opts.protected;
|
|
210
|
+
}
|
|
211
|
+
if (opts?.public) {
|
|
212
|
+
this.public = opts.public;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
};
|
|
36
216
|
function str(value) {
|
|
37
217
|
return typeof value === "string" ? value : void 0;
|
|
38
218
|
}
|
|
@@ -48,7 +228,7 @@ function defaultMapUser(payload) {
|
|
|
48
228
|
avatarUrl: str(payload.avatarUrl) || str(payload.avatar_url) || str(payload.picture)
|
|
49
229
|
};
|
|
50
230
|
}
|
|
51
|
-
var MastraJwtAuth = class extends
|
|
231
|
+
var MastraJwtAuth = class extends MastraAuthProvider {
|
|
52
232
|
secret;
|
|
53
233
|
mapUser;
|
|
54
234
|
constructor(options) {
|