@mastra/auth-cloud 1.2.0 → 1.2.1-alpha.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/CHANGELOG.md +9 -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/auth-provider.d.ts +4 -4
- package/dist/auth-provider.d.ts.map +1 -1
- package/dist/index.cjs +301 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +296 -4
- package/dist/index.js.map +1 -1
- package/dist/rbac/rbac-provider.d.ts +1 -1
- package/dist/rbac/rbac-provider.d.ts.map +1 -1
- package/package.json +6 -6
- package/LICENSE.md +0 -30
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# @mastra/auth-cloud
|
|
2
2
|
|
|
3
|
+
## 1.2.1-alpha.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Improved auth package builds by removing the direct core dependency from auth providers while preserving the existing public auth APIs. ([#17142](https://github.com/mastra-ai/mastra/pull/17142))
|
|
8
|
+
|
|
9
|
+
- Updated dependencies [[`5c0df77`](https://github.com/mastra-ai/mastra/commit/5c0df776c40efa420f8c07a2f3ee66010296618e)]:
|
|
10
|
+
- @mastra/auth@1.1.1-alpha.0
|
|
11
|
+
|
|
3
12
|
## 1.2.0
|
|
4
13
|
|
|
5
14
|
### Minor Changes
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { RegisteredLogger, IMastraLogger } from '../logger/index.js';
|
|
2
|
+
import 'node:stream';
|
|
3
|
+
|
|
4
|
+
declare class MastraBase {
|
|
5
|
+
#private;
|
|
6
|
+
component: RegisteredLogger;
|
|
7
|
+
protected logger: IMastraLogger;
|
|
8
|
+
name?: string;
|
|
9
|
+
constructor({ component, name, rawConfig, }: {
|
|
10
|
+
component?: RegisteredLogger;
|
|
11
|
+
name?: string;
|
|
12
|
+
rawConfig?: Record<string, unknown>;
|
|
13
|
+
});
|
|
14
|
+
/**
|
|
15
|
+
* Returns the raw storage configuration this primitive was created from,
|
|
16
|
+
* or undefined if it was created from code.
|
|
17
|
+
*/
|
|
18
|
+
toRawConfig(): Record<string, unknown> | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* Sets the raw storage configuration for this primitive.
|
|
21
|
+
* @internal
|
|
22
|
+
*/
|
|
23
|
+
__setRawConfig(rawConfig: Record<string, unknown>): void;
|
|
24
|
+
/**
|
|
25
|
+
* Set the logger for the agent
|
|
26
|
+
* @param logger
|
|
27
|
+
*/
|
|
28
|
+
__setLogger(logger: IMastraLogger): void;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export { MastraBase };
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import { Transform } from 'node:stream';
|
|
2
|
+
|
|
3
|
+
declare const RegisteredLogger: {
|
|
4
|
+
readonly AGENT: "AGENT";
|
|
5
|
+
readonly OBSERVABILITY: "OBSERVABILITY";
|
|
6
|
+
readonly AUTH: "AUTH";
|
|
7
|
+
readonly BROWSER: "BROWSER";
|
|
8
|
+
readonly NETWORK: "NETWORK";
|
|
9
|
+
readonly WORKFLOW: "WORKFLOW";
|
|
10
|
+
readonly LLM: "LLM";
|
|
11
|
+
readonly TTS: "TTS";
|
|
12
|
+
readonly VOICE: "VOICE";
|
|
13
|
+
readonly VECTOR: "VECTOR";
|
|
14
|
+
readonly BUNDLER: "BUNDLER";
|
|
15
|
+
readonly DEPLOYER: "DEPLOYER";
|
|
16
|
+
readonly MEMORY: "MEMORY";
|
|
17
|
+
readonly STORAGE: "STORAGE";
|
|
18
|
+
readonly EMBEDDINGS: "EMBEDDINGS";
|
|
19
|
+
readonly MCP_SERVER: "MCP_SERVER";
|
|
20
|
+
readonly SERVER_CACHE: "SERVER_CACHE";
|
|
21
|
+
readonly SERVER: "SERVER";
|
|
22
|
+
readonly WORKSPACE: "WORKSPACE";
|
|
23
|
+
readonly CHANNEL: "CHANNEL";
|
|
24
|
+
};
|
|
25
|
+
type RegisteredLogger = (typeof RegisteredLogger)[keyof typeof RegisteredLogger];
|
|
26
|
+
declare const LogLevel: {
|
|
27
|
+
readonly DEBUG: "debug";
|
|
28
|
+
readonly INFO: "info";
|
|
29
|
+
readonly WARN: "warn";
|
|
30
|
+
readonly ERROR: "error";
|
|
31
|
+
readonly NONE: "silent";
|
|
32
|
+
};
|
|
33
|
+
type LogLevel = (typeof LogLevel)[keyof typeof LogLevel];
|
|
34
|
+
interface BaseLogMessage {
|
|
35
|
+
runId?: string;
|
|
36
|
+
msg: string;
|
|
37
|
+
level: LogLevel;
|
|
38
|
+
time: Date;
|
|
39
|
+
pid: number;
|
|
40
|
+
hostname: string;
|
|
41
|
+
name: string;
|
|
42
|
+
}
|
|
43
|
+
declare abstract class LoggerTransport extends Transform {
|
|
44
|
+
constructor(opts?: any);
|
|
45
|
+
listLogsByRunId(_args: {
|
|
46
|
+
runId: string;
|
|
47
|
+
fromDate?: Date;
|
|
48
|
+
toDate?: Date;
|
|
49
|
+
logLevel?: LogLevel;
|
|
50
|
+
filters?: Record<string, any>;
|
|
51
|
+
page?: number;
|
|
52
|
+
perPage?: number;
|
|
53
|
+
}): Promise<{
|
|
54
|
+
logs: BaseLogMessage[];
|
|
55
|
+
total: number;
|
|
56
|
+
page: number;
|
|
57
|
+
perPage: number;
|
|
58
|
+
hasMore: boolean;
|
|
59
|
+
}>;
|
|
60
|
+
listLogs(_args?: {
|
|
61
|
+
fromDate?: Date;
|
|
62
|
+
toDate?: Date;
|
|
63
|
+
logLevel?: LogLevel;
|
|
64
|
+
filters?: Record<string, any>;
|
|
65
|
+
returnPaginationResults?: boolean;
|
|
66
|
+
page?: number;
|
|
67
|
+
perPage?: number;
|
|
68
|
+
}): Promise<{
|
|
69
|
+
logs: BaseLogMessage[];
|
|
70
|
+
total: number;
|
|
71
|
+
page: number;
|
|
72
|
+
perPage: number;
|
|
73
|
+
hasMore: boolean;
|
|
74
|
+
}>;
|
|
75
|
+
}
|
|
76
|
+
declare const createCustomTransport: (stream: Transform, listLogs?: LoggerTransport["listLogs"], listLogsByRunId?: LoggerTransport["listLogsByRunId"]) => LoggerTransport;
|
|
77
|
+
interface IMastraLogger {
|
|
78
|
+
debug(message: string, ...args: any[]): void;
|
|
79
|
+
info(message: string, ...args: any[]): void;
|
|
80
|
+
warn(message: string, ...args: any[]): void;
|
|
81
|
+
error(message: string, ...args: any[]): void;
|
|
82
|
+
trackException(error: Error, metadata?: Record<string, unknown>): void;
|
|
83
|
+
getTransports(): Map<string, LoggerTransport>;
|
|
84
|
+
listLogs(_transportId: string, _params?: {
|
|
85
|
+
fromDate?: Date;
|
|
86
|
+
toDate?: Date;
|
|
87
|
+
logLevel?: LogLevel;
|
|
88
|
+
filters?: Record<string, any>;
|
|
89
|
+
page?: number;
|
|
90
|
+
perPage?: number;
|
|
91
|
+
}): Promise<{
|
|
92
|
+
logs: BaseLogMessage[];
|
|
93
|
+
total: number;
|
|
94
|
+
page: number;
|
|
95
|
+
perPage: number;
|
|
96
|
+
hasMore: boolean;
|
|
97
|
+
}>;
|
|
98
|
+
listLogsByRunId(_args: {
|
|
99
|
+
transportId: string;
|
|
100
|
+
runId: string;
|
|
101
|
+
fromDate?: Date;
|
|
102
|
+
toDate?: Date;
|
|
103
|
+
logLevel?: LogLevel;
|
|
104
|
+
filters?: Record<string, any>;
|
|
105
|
+
page?: number;
|
|
106
|
+
perPage?: number;
|
|
107
|
+
}): Promise<{
|
|
108
|
+
logs: BaseLogMessage[];
|
|
109
|
+
total: number;
|
|
110
|
+
page: number;
|
|
111
|
+
perPage: number;
|
|
112
|
+
hasMore: boolean;
|
|
113
|
+
}>;
|
|
114
|
+
}
|
|
115
|
+
declare abstract class MastraLogger implements IMastraLogger {
|
|
116
|
+
protected name: string;
|
|
117
|
+
protected level: LogLevel;
|
|
118
|
+
protected transports: Map<string, LoggerTransport>;
|
|
119
|
+
constructor(options?: {
|
|
120
|
+
name?: string;
|
|
121
|
+
level?: LogLevel;
|
|
122
|
+
transports?: Record<string, LoggerTransport>;
|
|
123
|
+
});
|
|
124
|
+
abstract debug(message: string, ...args: any[]): void;
|
|
125
|
+
abstract info(message: string, ...args: any[]): void;
|
|
126
|
+
abstract warn(message: string, ...args: any[]): void;
|
|
127
|
+
abstract error(message: string, ...args: any[]): void;
|
|
128
|
+
getTransports(): Map<string, LoggerTransport>;
|
|
129
|
+
trackException(_error: Error, _metadata?: Record<string, unknown>): void;
|
|
130
|
+
listLogs(transportId: string, params?: {
|
|
131
|
+
fromDate?: Date;
|
|
132
|
+
toDate?: Date;
|
|
133
|
+
logLevel?: LogLevel;
|
|
134
|
+
filters?: Record<string, any>;
|
|
135
|
+
page?: number;
|
|
136
|
+
perPage?: number;
|
|
137
|
+
}): Promise<{
|
|
138
|
+
logs: BaseLogMessage[];
|
|
139
|
+
total: number;
|
|
140
|
+
page: number;
|
|
141
|
+
perPage: number;
|
|
142
|
+
hasMore: boolean;
|
|
143
|
+
}>;
|
|
144
|
+
listLogsByRunId({ transportId, runId, fromDate, toDate, logLevel, filters, page, perPage, }: {
|
|
145
|
+
transportId: string;
|
|
146
|
+
runId: string;
|
|
147
|
+
fromDate?: Date;
|
|
148
|
+
toDate?: Date;
|
|
149
|
+
logLevel?: LogLevel;
|
|
150
|
+
filters?: Record<string, any>;
|
|
151
|
+
page?: number;
|
|
152
|
+
perPage?: number;
|
|
153
|
+
}): Promise<{
|
|
154
|
+
logs: BaseLogMessage[];
|
|
155
|
+
total: number;
|
|
156
|
+
page: number;
|
|
157
|
+
perPage: number;
|
|
158
|
+
hasMore: boolean;
|
|
159
|
+
}>;
|
|
160
|
+
}
|
|
161
|
+
type LogFilterContext = {
|
|
162
|
+
component?: RegisteredLogger;
|
|
163
|
+
level: LogLevel;
|
|
164
|
+
message: string;
|
|
165
|
+
args: unknown[];
|
|
166
|
+
};
|
|
167
|
+
type LogFilter = (ctx: LogFilterContext) => boolean;
|
|
168
|
+
interface ConsoleLoggerOptions {
|
|
169
|
+
name?: string;
|
|
170
|
+
level?: LogLevel;
|
|
171
|
+
component?: RegisteredLogger;
|
|
172
|
+
filter?: LogFilter;
|
|
173
|
+
}
|
|
174
|
+
declare class ConsoleLogger extends MastraLogger {
|
|
175
|
+
protected component?: RegisteredLogger;
|
|
176
|
+
protected filter?: LogFilter;
|
|
177
|
+
constructor(options?: ConsoleLoggerOptions);
|
|
178
|
+
child(componentOrBindings: RegisteredLogger | Record<string, unknown>): ConsoleLogger;
|
|
179
|
+
private shouldLog;
|
|
180
|
+
private prefix;
|
|
181
|
+
debug(message: string, ...args: any[]): void;
|
|
182
|
+
info(message: string, ...args: any[]): void;
|
|
183
|
+
warn(message: string, ...args: any[]): void;
|
|
184
|
+
error(message: string, ...args: any[]): void;
|
|
185
|
+
listLogs(_transportId: string, _params?: {
|
|
186
|
+
fromDate?: Date;
|
|
187
|
+
toDate?: Date;
|
|
188
|
+
logLevel?: LogLevel;
|
|
189
|
+
filters?: Record<string, any>;
|
|
190
|
+
page?: number;
|
|
191
|
+
perPage?: number;
|
|
192
|
+
}): Promise<{
|
|
193
|
+
logs: never[];
|
|
194
|
+
total: number;
|
|
195
|
+
page: number;
|
|
196
|
+
perPage: number;
|
|
197
|
+
hasMore: boolean;
|
|
198
|
+
}>;
|
|
199
|
+
listLogsByRunId(_args: {
|
|
200
|
+
transportId: string;
|
|
201
|
+
runId: string;
|
|
202
|
+
fromDate?: Date;
|
|
203
|
+
toDate?: Date;
|
|
204
|
+
logLevel?: LogLevel;
|
|
205
|
+
filters?: Record<string, any>;
|
|
206
|
+
page?: number;
|
|
207
|
+
perPage?: number;
|
|
208
|
+
}): Promise<{
|
|
209
|
+
logs: never[];
|
|
210
|
+
total: number;
|
|
211
|
+
page: number;
|
|
212
|
+
perPage: number;
|
|
213
|
+
hasMore: boolean;
|
|
214
|
+
}>;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
export { type BaseLogMessage, ConsoleLogger, type ConsoleLoggerOptions, type IMastraLogger, type LogFilter, type LogFilterContext, LogLevel, LoggerTransport, MastraLogger, RegisteredLogger, createCustomTransport };
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Capabilities detection and response building for EE authentication.
|
|
3
|
+
*/
|
|
4
|
+
import type { MastraAuthProvider } from '../provider/index.js';
|
|
5
|
+
import type { IFGAProvider } from './interfaces/fga.js';
|
|
6
|
+
import type { IRBACProvider } from './interfaces/rbac.js';
|
|
7
|
+
import type { EEUser } from './interfaces/user.js';
|
|
8
|
+
/**
|
|
9
|
+
* Public capabilities response (no authentication required).
|
|
10
|
+
* Contains just enough info to render the login page.
|
|
11
|
+
*/
|
|
12
|
+
export interface PublicAuthCapabilities {
|
|
13
|
+
/** Whether auth is enabled */
|
|
14
|
+
enabled: boolean;
|
|
15
|
+
/** Login configuration (null if no auth or no SSO) */
|
|
16
|
+
login: {
|
|
17
|
+
/** Type of login available */
|
|
18
|
+
type: 'sso' | 'credentials' | 'both';
|
|
19
|
+
/** Whether sign-up is enabled (defaults to true) */
|
|
20
|
+
signUpEnabled?: boolean;
|
|
21
|
+
/** Optional description explaining the auth requirement and what credentials to use */
|
|
22
|
+
description?: string;
|
|
23
|
+
/** SSO configuration */
|
|
24
|
+
sso?: {
|
|
25
|
+
/** Provider name */
|
|
26
|
+
provider: string;
|
|
27
|
+
/** Button text */
|
|
28
|
+
text: string;
|
|
29
|
+
/** Icon URL */
|
|
30
|
+
icon?: string;
|
|
31
|
+
/** Description of the auth requirement */
|
|
32
|
+
description?: string;
|
|
33
|
+
/** Login URL */
|
|
34
|
+
url: string;
|
|
35
|
+
};
|
|
36
|
+
} | null;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* User info for authenticated response.
|
|
40
|
+
*/
|
|
41
|
+
export interface AuthenticatedUser {
|
|
42
|
+
/** User ID */
|
|
43
|
+
id: string;
|
|
44
|
+
/** User email */
|
|
45
|
+
email?: string;
|
|
46
|
+
/** Display name */
|
|
47
|
+
name?: string;
|
|
48
|
+
/** Avatar URL */
|
|
49
|
+
avatarUrl?: string;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Capability flags indicating which EE features are available.
|
|
53
|
+
*/
|
|
54
|
+
export interface CapabilityFlags {
|
|
55
|
+
/** IUserProvider is implemented and licensed */
|
|
56
|
+
user: boolean;
|
|
57
|
+
/** ISessionProvider is implemented and licensed */
|
|
58
|
+
session: boolean;
|
|
59
|
+
/** ISSOProvider is implemented and licensed */
|
|
60
|
+
sso: boolean;
|
|
61
|
+
/** IRBACProvider is implemented and licensed */
|
|
62
|
+
rbac: boolean;
|
|
63
|
+
/** IACLProvider is implemented and licensed */
|
|
64
|
+
acl: boolean;
|
|
65
|
+
/** IFGAProvider is implemented and licensed */
|
|
66
|
+
fga: boolean;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* User's access (roles and permissions).
|
|
70
|
+
*/
|
|
71
|
+
export interface UserAccess {
|
|
72
|
+
/** User's roles */
|
|
73
|
+
roles: string[];
|
|
74
|
+
/** User's resolved permissions */
|
|
75
|
+
permissions: string[];
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Authenticated capabilities response.
|
|
79
|
+
* Extends public capabilities with user context and feature flags.
|
|
80
|
+
*/
|
|
81
|
+
export interface AuthenticatedCapabilities extends PublicAuthCapabilities {
|
|
82
|
+
/** Current authenticated user */
|
|
83
|
+
user: AuthenticatedUser;
|
|
84
|
+
/** Available EE capabilities */
|
|
85
|
+
capabilities: CapabilityFlags;
|
|
86
|
+
/** User's access (if RBAC available) */
|
|
87
|
+
access: UserAccess | null;
|
|
88
|
+
/** Available roles in the system (only present for admin users) */
|
|
89
|
+
availableRoles?: {
|
|
90
|
+
id: string;
|
|
91
|
+
name: string;
|
|
92
|
+
}[];
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Type guard to check if response is authenticated.
|
|
96
|
+
*/
|
|
97
|
+
export declare function isAuthenticated(caps: PublicAuthCapabilities | AuthenticatedCapabilities): caps is AuthenticatedCapabilities;
|
|
98
|
+
/**
|
|
99
|
+
* Options for building capabilities.
|
|
100
|
+
*/
|
|
101
|
+
export interface BuildCapabilitiesOptions {
|
|
102
|
+
/**
|
|
103
|
+
* RBAC provider for role-based access control (EE feature).
|
|
104
|
+
* Separate from the auth provider to allow mixing different providers.
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* ```typescript
|
|
108
|
+
* const rbac = new StaticRBACProvider({
|
|
109
|
+
* roles: DEFAULT_ROLES,
|
|
110
|
+
* getUserRoles: (user) => [user.role],
|
|
111
|
+
* });
|
|
112
|
+
*
|
|
113
|
+
* buildCapabilities(auth, request, { rbac });
|
|
114
|
+
* ```
|
|
115
|
+
*/
|
|
116
|
+
rbac?: IRBACProvider<EEUser>;
|
|
117
|
+
/**
|
|
118
|
+
* FGA provider for fine-grained authorization (EE feature).
|
|
119
|
+
* Separate from the auth provider to allow mixing different providers.
|
|
120
|
+
*/
|
|
121
|
+
fga?: IFGAProvider<EEUser>;
|
|
122
|
+
/**
|
|
123
|
+
* API route prefix used to construct SSO login URLs.
|
|
124
|
+
* Defaults to `/api` when not provided.
|
|
125
|
+
*
|
|
126
|
+
* @example `/mastra` results in SSO URL `/mastra/auth/sso/login`
|
|
127
|
+
*/
|
|
128
|
+
apiPrefix?: string;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Build capabilities response based on auth configuration and request state.
|
|
132
|
+
*
|
|
133
|
+
* This function determines what capabilities are available and, if the user
|
|
134
|
+
* is authenticated, includes their user info and access permissions.
|
|
135
|
+
*
|
|
136
|
+
* @param auth - Auth provider (or null if no auth configured)
|
|
137
|
+
* @param request - Incoming HTTP request
|
|
138
|
+
* @param options - Optional configuration (roleMapping, etc.)
|
|
139
|
+
* @returns Capabilities response (public or authenticated)
|
|
140
|
+
*/
|
|
141
|
+
export declare function buildCapabilities(auth: MastraAuthProvider | null, request: Request, options?: BuildCapabilitiesOptions): Promise<PublicAuthCapabilities | AuthenticatedCapabilities>;
|
|
142
|
+
//# sourceMappingURL=capabilities.d.ts.map
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Default implementations for EE authentication.
|
|
3
|
+
*
|
|
4
|
+
* @license Mastra Enterprise License - see ee/LICENSE
|
|
5
|
+
*/
|
|
6
|
+
export { DEFAULT_ROLES, type Permission, type PermissionPattern, type RoleMapping, getDefaultRole, resolvePermissions, resolvePermissionsFromMapping, matchesPermission, hasPermission, } from './roles.js';
|
|
7
|
+
export { StaticRBACProvider, type StaticRBACProviderOptions } from './rbac/index.js';
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Static RBAC provider with config-based roles.
|
|
3
|
+
*/
|
|
4
|
+
import type { RoleDefinition, RoleMapping, IRBACProvider } from '../../interfaces/index.js';
|
|
5
|
+
/**
|
|
6
|
+
* Options for StaticRBACProvider.
|
|
7
|
+
*
|
|
8
|
+
* Use ONE of the following approaches:
|
|
9
|
+
* - `roles`: Define role structures with permissions (Mastra's native role system)
|
|
10
|
+
* - `roleMapping`: Map provider roles directly to permissions (simpler for external providers)
|
|
11
|
+
*/
|
|
12
|
+
export type StaticRBACProviderOptions<TUser = unknown> = {
|
|
13
|
+
/** Role definitions (Mastra's native role system) */
|
|
14
|
+
roles: RoleDefinition[];
|
|
15
|
+
/** Function to get user's role IDs */
|
|
16
|
+
getUserRoles: (user: TUser) => string[] | Promise<string[]>;
|
|
17
|
+
roleMapping?: never;
|
|
18
|
+
} | {
|
|
19
|
+
/**
|
|
20
|
+
* Role mapping for translating provider roles to permissions.
|
|
21
|
+
* Use this when your identity provider has roles that need to be
|
|
22
|
+
* mapped to Mastra permissions.
|
|
23
|
+
*/
|
|
24
|
+
roleMapping: RoleMapping;
|
|
25
|
+
/** Function to get user's role IDs from the provider */
|
|
26
|
+
getUserRoles: (user: TUser) => string[] | Promise<string[]>;
|
|
27
|
+
roles?: never;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Static RBAC provider.
|
|
31
|
+
*
|
|
32
|
+
* Supports two modes:
|
|
33
|
+
* 1. **Role definitions**: Use Mastra's native role system with structured roles
|
|
34
|
+
* 2. **Role mapping**: Directly map provider roles to permissions
|
|
35
|
+
*
|
|
36
|
+
* @example Using role definitions (Mastra's native system)
|
|
37
|
+
* ```typescript
|
|
38
|
+
* const rbac = new StaticRBACProvider({
|
|
39
|
+
* roles: DEFAULT_ROLES,
|
|
40
|
+
* getUserRoles: (user) => [user.role],
|
|
41
|
+
* });
|
|
42
|
+
* ```
|
|
43
|
+
*
|
|
44
|
+
* @example Using role mapping (for external providers)
|
|
45
|
+
* ```typescript
|
|
46
|
+
* const rbac = new StaticRBACProvider({
|
|
47
|
+
* roleMapping: {
|
|
48
|
+
* "Engineering": ["agents:*", "workflows:*"],
|
|
49
|
+
* "Product": ["agents:read", "workflows:read"],
|
|
50
|
+
* "_default": [],
|
|
51
|
+
* },
|
|
52
|
+
* getUserRoles: (user) => user.providerRoles,
|
|
53
|
+
* });
|
|
54
|
+
* ```
|
|
55
|
+
*
|
|
56
|
+
* @example Async role lookup
|
|
57
|
+
* ```typescript
|
|
58
|
+
* const rbac = new StaticRBACProvider({
|
|
59
|
+
* roles: DEFAULT_ROLES,
|
|
60
|
+
* getUserRoles: async (user) => {
|
|
61
|
+
* return db.getUserRoles(user.id);
|
|
62
|
+
* },
|
|
63
|
+
* });
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
export declare class StaticRBACProvider<TUser = unknown> implements IRBACProvider<TUser> {
|
|
67
|
+
private roles?;
|
|
68
|
+
private _roleMapping?;
|
|
69
|
+
private getUserRolesFn;
|
|
70
|
+
private permissionCache;
|
|
71
|
+
/** Expose roleMapping for middleware access */
|
|
72
|
+
get roleMapping(): RoleMapping | undefined;
|
|
73
|
+
constructor(options: StaticRBACProviderOptions<TUser>);
|
|
74
|
+
getRoles(user: TUser): Promise<string[]>;
|
|
75
|
+
hasRole(user: TUser, role: string): Promise<boolean>;
|
|
76
|
+
getPermissions(user: TUser): Promise<string[]>;
|
|
77
|
+
hasPermission(user: TUser, permission: string): Promise<boolean>;
|
|
78
|
+
hasAllPermissions(user: TUser, permissions: string[]): Promise<boolean>;
|
|
79
|
+
hasAnyPermission(user: TUser, permissions: string[]): Promise<boolean>;
|
|
80
|
+
/**
|
|
81
|
+
* Clear the permission cache.
|
|
82
|
+
*/
|
|
83
|
+
clearCache(): void;
|
|
84
|
+
/**
|
|
85
|
+
* Get all role definitions.
|
|
86
|
+
* Only available when using role definitions mode (not role mapping).
|
|
87
|
+
*/
|
|
88
|
+
getRoleDefinitions(): RoleDefinition[];
|
|
89
|
+
/**
|
|
90
|
+
* Get a specific role definition.
|
|
91
|
+
* Only available when using role definitions mode (not role mapping).
|
|
92
|
+
*/
|
|
93
|
+
getRoleDefinition(roleId: string): RoleDefinition | undefined;
|
|
94
|
+
/**
|
|
95
|
+
* Get all available roles in the system.
|
|
96
|
+
*/
|
|
97
|
+
getAvailableRoles(): Promise<{
|
|
98
|
+
id: string;
|
|
99
|
+
name: string;
|
|
100
|
+
}[]>;
|
|
101
|
+
/**
|
|
102
|
+
* Get the resolved permissions for a specific role.
|
|
103
|
+
*/
|
|
104
|
+
getPermissionsForRole(roleId: string): Promise<string[]>;
|
|
105
|
+
}
|
|
106
|
+
//# sourceMappingURL=static.d.ts.map
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Default roles and permissions for Mastra Studio.
|
|
3
|
+
*/
|
|
4
|
+
import type { RoleDefinition, RoleMapping } from '../interfaces/index.js';
|
|
5
|
+
export type { RoleMapping };
|
|
6
|
+
/**
|
|
7
|
+
* Default role definitions for Studio.
|
|
8
|
+
*
|
|
9
|
+
* These roles provide a sensible starting point for most applications:
|
|
10
|
+
* - **owner**: Full access to everything
|
|
11
|
+
* - **admin**: Manage agents, workflows, and users
|
|
12
|
+
* - **member**: Execute agents and workflows, read-only settings
|
|
13
|
+
* - **viewer**: Read-only access
|
|
14
|
+
*
|
|
15
|
+
* Permission patterns:
|
|
16
|
+
* - `*` - Full access to everything
|
|
17
|
+
* - `resource:*` - All actions on a specific resource
|
|
18
|
+
* - `*:action` - An action across all resources (e.g., `*:read` for read-only)
|
|
19
|
+
*/
|
|
20
|
+
export declare const DEFAULT_ROLES: RoleDefinition[];
|
|
21
|
+
export type { Permission, PermissionPattern } from '../interfaces/permissions.generated.js';
|
|
22
|
+
/**
|
|
23
|
+
* Get role by ID from default roles.
|
|
24
|
+
*
|
|
25
|
+
* @param roleId - Role ID to find
|
|
26
|
+
* @returns Role definition or undefined
|
|
27
|
+
*/
|
|
28
|
+
export declare function getDefaultRole(roleId: string): RoleDefinition | undefined;
|
|
29
|
+
/**
|
|
30
|
+
* Resolve all permissions for a set of role IDs.
|
|
31
|
+
*
|
|
32
|
+
* Handles role inheritance and deduplication.
|
|
33
|
+
*
|
|
34
|
+
* @param roleIds - Role IDs to resolve
|
|
35
|
+
* @param roles - Role definitions (defaults to DEFAULT_ROLES)
|
|
36
|
+
* @returns Array of resolved permissions
|
|
37
|
+
*/
|
|
38
|
+
export declare function resolvePermissions(roleIds: string[], roles?: RoleDefinition[]): string[];
|
|
39
|
+
/**
|
|
40
|
+
* Check if a permission matches (including wildcard support).
|
|
41
|
+
*
|
|
42
|
+
* Permission format: `{resource}:{action}[:{resource-id}]`
|
|
43
|
+
*
|
|
44
|
+
* Examples:
|
|
45
|
+
* - `*` matches everything
|
|
46
|
+
* - `agents:*` matches `agents:read`, `agents:read:my-agent`
|
|
47
|
+
* - `*:read` matches `agents:read`, `workflows:read` (action across all resources)
|
|
48
|
+
* - `agents:read` matches `agents:read`, `agents:read:my-agent`
|
|
49
|
+
* - `agents:read:my-agent` matches only `agents:read:my-agent`
|
|
50
|
+
* - `agents:*:my-agent` matches `agents:read:my-agent`, `agents:write:my-agent`
|
|
51
|
+
*
|
|
52
|
+
* @param userPermission - Permission the user has
|
|
53
|
+
* @param requiredPermission - Permission being checked
|
|
54
|
+
* @returns True if permission matches
|
|
55
|
+
*/
|
|
56
|
+
export declare function matchesPermission(userPermission: string, requiredPermission: string): boolean;
|
|
57
|
+
/**
|
|
58
|
+
* Check if a user has a specific permission.
|
|
59
|
+
*
|
|
60
|
+
* @param userPermissions - Permissions the user has
|
|
61
|
+
* @param requiredPermission - Permission being checked
|
|
62
|
+
* @returns True if user has the permission
|
|
63
|
+
*/
|
|
64
|
+
export declare function hasPermission(userPermissions: string[], requiredPermission: string): boolean;
|
|
65
|
+
/**
|
|
66
|
+
* Resolve permissions from user roles using a role mapping.
|
|
67
|
+
*
|
|
68
|
+
* This function translates provider-defined roles (from WorkOS, Okta, etc.)
|
|
69
|
+
* to Mastra permissions using a configurable mapping.
|
|
70
|
+
*
|
|
71
|
+
* @example
|
|
72
|
+
* ```typescript
|
|
73
|
+
* const roleMapping = {
|
|
74
|
+
* "Engineering": ["agents:*", "workflows:*"],
|
|
75
|
+
* "Product": ["agents:read"],
|
|
76
|
+
* "_default": [],
|
|
77
|
+
* };
|
|
78
|
+
*
|
|
79
|
+
* // User has "Engineering" and "QA" roles
|
|
80
|
+
* const permissions = resolvePermissionsFromMapping(
|
|
81
|
+
* ["Engineering", "QA"],
|
|
82
|
+
* roleMapping
|
|
83
|
+
* );
|
|
84
|
+
* // Result: ["agents:*", "workflows:*"] (QA is unmapped, gets _default)
|
|
85
|
+
* ```
|
|
86
|
+
*
|
|
87
|
+
* @param roles - User's roles from the identity provider
|
|
88
|
+
* @param mapping - Role to permission mapping
|
|
89
|
+
* @returns Array of resolved permissions
|
|
90
|
+
*/
|
|
91
|
+
export declare function resolvePermissionsFromMapping(roles: string[], mapping: RoleMapping): string[];
|
|
92
|
+
//# sourceMappingURL=roles.d.ts.map
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FGA enforcement utility for checking fine-grained authorization.
|
|
3
|
+
*
|
|
4
|
+
* @license Mastra Enterprise License - see ee/LICENSE
|
|
5
|
+
*/
|
|
6
|
+
import type { FGACheckContext, IFGAProvider } from './interfaces/fga.js';
|
|
7
|
+
import type { MastraFGAPermissionInput } from './interfaces/permissions.generated.js';
|
|
8
|
+
export type ActorSignal = true | {
|
|
9
|
+
actorKind: 'system';
|
|
10
|
+
sourceWorkflow?: string;
|
|
11
|
+
};
|
|
12
|
+
export interface CheckFGAOptions {
|
|
13
|
+
fgaProvider: IFGAProvider | undefined;
|
|
14
|
+
user: any;
|
|
15
|
+
resource: {
|
|
16
|
+
type: string;
|
|
17
|
+
id: string;
|
|
18
|
+
};
|
|
19
|
+
permission: MastraFGAPermissionInput | MastraFGAPermissionInput[];
|
|
20
|
+
context?: FGACheckContext;
|
|
21
|
+
requestContext?: FGACheckContext['requestContext'];
|
|
22
|
+
actor?: ActorSignal;
|
|
23
|
+
}
|
|
24
|
+
export interface RequireFGAOptions extends CheckFGAOptions {
|
|
25
|
+
metadata?: Record<string, unknown>;
|
|
26
|
+
}
|
|
27
|
+
export declare function getAgentFGAResourceId(agentId: string): string;
|
|
28
|
+
export declare function getWorkflowFGAResourceId(workflowId: string): string;
|
|
29
|
+
export declare function getStandaloneToolFGAResourceId(toolName: string): string;
|
|
30
|
+
export declare function getAgentToolFGAResourceId(agentId: string, toolName: string): string;
|
|
31
|
+
export declare function getMCPToolFGAResourceId(serverName: string, toolName: string): string;
|
|
32
|
+
/**
|
|
33
|
+
* Check fine-grained authorization for a resource.
|
|
34
|
+
*
|
|
35
|
+
* No-op if no FGA provider is configured (backward compatibility).
|
|
36
|
+
* Delegates to fgaProvider.require() which throws FGADeniedError if denied.
|
|
37
|
+
*/
|
|
38
|
+
export declare function checkFGA(options: CheckFGAOptions): Promise<void>;
|
|
39
|
+
/**
|
|
40
|
+
* Require fine-grained authorization for a resource.
|
|
41
|
+
*
|
|
42
|
+
* No-op if no FGA provider is configured. When FGA is configured, a missing
|
|
43
|
+
* user fails closed.
|
|
44
|
+
*/
|
|
45
|
+
export declare function requireFGA(options: RequireFGAOptions): Promise<void>;
|
|
46
|
+
/**
|
|
47
|
+
* Error thrown when an FGA authorization check is denied.
|
|
48
|
+
*/
|
|
49
|
+
export declare class FGADeniedError extends Error {
|
|
50
|
+
readonly user: any;
|
|
51
|
+
readonly resource: {
|
|
52
|
+
type: string;
|
|
53
|
+
id: string;
|
|
54
|
+
};
|
|
55
|
+
readonly permission: MastraFGAPermissionInput | MastraFGAPermissionInput[];
|
|
56
|
+
readonly status: number;
|
|
57
|
+
constructor(user: any, resource: {
|
|
58
|
+
type: string;
|
|
59
|
+
id: string;
|
|
60
|
+
}, permission: MastraFGAPermissionInput | MastraFGAPermissionInput[], reason?: string);
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=fga-check.d.ts.map
|