@mastra/auth-cloud 0.0.0-studio-cli-20260504022012 → 0.0.0-subconscious-alpha-20260901173138

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.
Files changed (36) hide show
  1. package/dist/_types/@internal_auth/dist/_types/@internal_core/dist/base/index.d.ts +31 -0
  2. package/dist/_types/@internal_auth/dist/_types/@internal_core/dist/index-Biaf3BmX.d.ts +319 -0
  3. package/dist/_types/@internal_auth/dist/ee/capabilities.d.ts +142 -0
  4. package/dist/_types/@internal_auth/dist/ee/defaults/index.d.ts +8 -0
  5. package/dist/_types/@internal_auth/dist/ee/defaults/rbac/index.d.ts +7 -0
  6. package/dist/_types/@internal_auth/dist/ee/defaults/rbac/static.d.ts +106 -0
  7. package/dist/_types/@internal_auth/dist/ee/defaults/roles.d.ts +92 -0
  8. package/dist/_types/@internal_auth/dist/ee/fga-check.d.ts +59 -0
  9. package/dist/_types/@internal_auth/dist/ee/index.d.ts +15 -0
  10. package/dist/_types/@internal_auth/dist/ee/interfaces/acl.d.ts +140 -0
  11. package/dist/_types/@internal_auth/dist/ee/interfaces/fga.d.ts +408 -0
  12. package/dist/_types/@internal_auth/dist/ee/interfaces/index.d.ts +15 -0
  13. package/dist/_types/@internal_auth/dist/ee/interfaces/permissions.generated.d.ts +533 -0
  14. package/dist/_types/@internal_auth/dist/ee/interfaces/rbac.d.ts +207 -0
  15. package/dist/_types/@internal_auth/dist/ee/interfaces/user.d.ts +18 -0
  16. package/dist/_types/@internal_auth/dist/ee/license.d.ts +171 -0
  17. package/dist/_types/@internal_auth/dist/index.d.ts +343 -0
  18. package/dist/_types/@internal_auth/dist/provider/index.d.ts +169 -0
  19. package/dist/_types/@internal_auth/dist/session/cookie.d.ts +82 -0
  20. package/dist/_types/@internal_auth/dist/session/index.d.ts +30 -0
  21. package/dist/_types/@internal_auth/dist/session/memory.d.ts +60 -0
  22. package/dist/_types/@internal_auth/dist/types/index.d.ts +56 -0
  23. package/dist/auth-provider.d.ts +12 -10
  24. package/dist/auth-provider.d.ts.map +1 -1
  25. package/dist/client.d.ts.map +1 -1
  26. package/dist/error.d.ts.map +1 -1
  27. package/dist/index.cjs +1471 -805
  28. package/dist/index.cjs.map +1 -1
  29. package/dist/index.js +1469 -802
  30. package/dist/index.js.map +1 -1
  31. package/dist/pkce/error.d.ts.map +1 -1
  32. package/dist/rbac/rbac-provider.d.ts +1 -1
  33. package/dist/rbac/rbac-provider.d.ts.map +1 -1
  34. package/package.json +18 -19
  35. package/CHANGELOG.md +0 -103
  36. package/LICENSE.md +0 -30
@@ -0,0 +1,31 @@
1
+ import { i as IMastraLogger, u as RegisteredLogger } from "../index-Biaf3BmX.js";
2
+ //#region src/base/MastraBase.d.ts
3
+ declare class MastraBase {
4
+ #private;
5
+ component: RegisteredLogger;
6
+ protected logger: IMastraLogger;
7
+ name?: string;
8
+ constructor({ component, name, rawConfig }: {
9
+ component?: RegisteredLogger;
10
+ name?: string;
11
+ rawConfig?: Record<string, unknown>;
12
+ });
13
+ /**
14
+ * Returns the raw storage configuration this primitive was created from,
15
+ * or undefined if it was created from code.
16
+ */
17
+ toRawConfig(): Record<string, unknown> | undefined;
18
+ /**
19
+ * Sets the raw storage configuration for this primitive.
20
+ * @internal
21
+ */
22
+ __setRawConfig(rawConfig: Record<string, unknown>): void;
23
+ /**
24
+ * Set the logger for the agent
25
+ * @param logger
26
+ */
27
+ __setLogger(logger: IMastraLogger): void;
28
+ }
29
+ //#endregion
30
+ export { MastraBase };
31
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,319 @@
1
+ import { Transform } from "stream";
2
+ //#region src/logger/adapter.d.ts
3
+ /**
4
+ * OpenTelemetry-compatible trace correlation fields, injected at the top
5
+ * level of a logger's native record.
6
+ *
7
+ * Field names are part of the platform contract (snake_case, W3C formats):
8
+ * external consumers (e.g. the Studio logs view reading Railway stdout)
9
+ * parse structured log lines and look for exactly these keys.
10
+ */
11
+ interface TraceFields {
12
+ /** 32-char lowercase hex W3C trace id */
13
+ trace_id: string;
14
+ /**
15
+ * 16-char lowercase hex W3C span id.
16
+ *
17
+ * Optional, and omitted rather than emitted empty: the active span may be
18
+ * one observability never exports (an internal span, or one dropped by
19
+ * `excludeSpanTypes`), leaving no span id a consumer could look up. The
20
+ * trace is still addressable in that case, so the line keeps `trace_id` and
21
+ * drops only this field. Consumers must treat `span_id` as possibly absent.
22
+ */
23
+ span_id?: string;
24
+ }
25
+ /**
26
+ * Destination for log records derived from the logger's native record,
27
+ * exported to Mastra observability. Structurally compatible with
28
+ * `LoggerContext` from `@mastra/core/observability`.
29
+ */
30
+ interface AdapterLogSink {
31
+ debug(message: string, data?: Record<string, unknown>): void;
32
+ info(message: string, data?: Record<string, unknown>): void;
33
+ warn(message: string, data?: Record<string, unknown>): void;
34
+ error(message: string, data?: Record<string, unknown>): void;
35
+ }
36
+ interface LoggerAdapterOptions {
37
+ /** Inject trace_id/span_id into the logger's native records. */
38
+ correlation: boolean;
39
+ /** Export records derived from the native record to Mastra observability. */
40
+ export: boolean;
41
+ }
42
+ /**
43
+ * Context handed to an adaptable logger by Mastra when observability is
44
+ * wired up. All members are safe to call on every log call (synchronous,
45
+ * never throw).
46
+ */
47
+ interface LoggerAdapterContext {
48
+ /**
49
+ * Resolve correlation fields for the currently active span, or undefined
50
+ * when no span is active (in which case no trace fields are added).
51
+ */
52
+ resolveTraceFields: () => TraceFields | undefined;
53
+ /**
54
+ * Resolve the observability log sink at call time. Returns the
55
+ * span-correlated sink when a span is active, the global sink otherwise,
56
+ * and undefined when export is disabled or observability is not
57
+ * initialized. Records must still be written to the native destination
58
+ * regardless.
59
+ */
60
+ getLogSink: () => AdapterLogSink | undefined;
61
+ options: LoggerAdapterOptions;
62
+ }
63
+ /**
64
+ * Capability marker a logger implements to opt into native trace
65
+ * correlation and observability export. When a configured logger implements
66
+ * this, Mastra attaches observability directly instead of wrapping the
67
+ * logger in the deprecated `DualLogger`.
68
+ */
69
+ interface AdaptableLogger extends IMastraLogger {
70
+ __attachObservability(ctx: LoggerAdapterContext): void;
71
+ /**
72
+ * Stable identity for the attachment target. Loggers whose adapter context
73
+ * lives in state shared across a root/child family (e.g. PinoLogger's
74
+ * mixin ref cell) return that shared object, so attaching any family
75
+ * member is recognized as re-attaching the whole family. Defaults to the
76
+ * logger instance itself when absent.
77
+ */
78
+ __observabilityAttachmentKey?(): object;
79
+ }
80
+ declare function isAdaptableLogger(logger: IMastraLogger): logger is AdaptableLogger;
81
+ /**
82
+ * Export a tracked exception through the adapter sink, mirroring the
83
+ * DualLogger dual-write shape (`errorId`/`domain`/`category`/`details`/`cause`
84
+ * when present on a MastraError-like value). Never throws into the caller.
85
+ */
86
+ declare function exportTrackedException(ctx: LoggerAdapterContext | undefined, error: Error, metadata?: Record<string, unknown>): void;
87
+ /**
88
+ * Adapt IMastraLogger's variadic args into the structured `data` payload of
89
+ * an exported log record. Extracts the first plain object as data,
90
+ * serializes an Error arg, and collects remaining primitives under `args`
91
+ * so the derived record preserves all context from the native call.
92
+ */
93
+ declare function buildLogRecordData(args: unknown[]): Record<string, unknown> | undefined;
94
+ //#endregion
95
+ //#region src/logger/index.d.ts
96
+ declare const RegisteredLogger: {
97
+ readonly AGENT: 'AGENT';
98
+ readonly OBSERVABILITY: 'OBSERVABILITY';
99
+ readonly AUTH: 'AUTH';
100
+ readonly BROWSER: 'BROWSER';
101
+ readonly NETWORK: 'NETWORK';
102
+ readonly WORKFLOW: 'WORKFLOW';
103
+ readonly LLM: 'LLM';
104
+ readonly TTS: 'TTS';
105
+ readonly VOICE: 'VOICE';
106
+ readonly VECTOR: 'VECTOR';
107
+ readonly BUNDLER: 'BUNDLER';
108
+ readonly DEPLOYER: 'DEPLOYER';
109
+ readonly MEMORY: 'MEMORY';
110
+ readonly STORAGE: 'STORAGE';
111
+ readonly EMBEDDINGS: 'EMBEDDINGS';
112
+ readonly MCP_SERVER: 'MCP_SERVER';
113
+ readonly SERVER_CACHE: 'SERVER_CACHE';
114
+ readonly SERVER: 'SERVER';
115
+ readonly WORKSPACE: 'WORKSPACE';
116
+ readonly CHANNEL: 'CHANNEL';
117
+ };
118
+ type RegisteredLogger = (typeof RegisteredLogger)[keyof typeof RegisteredLogger];
119
+ declare const LogLevel: {
120
+ readonly DEBUG: 'debug';
121
+ readonly INFO: 'info';
122
+ readonly WARN: 'warn';
123
+ readonly ERROR: 'error';
124
+ readonly NONE: 'silent';
125
+ };
126
+ type LogLevel = (typeof LogLevel)[keyof typeof LogLevel];
127
+ interface BaseLogMessage {
128
+ runId?: string;
129
+ msg: string;
130
+ level: LogLevel;
131
+ time: Date;
132
+ pid: number;
133
+ hostname: string;
134
+ name: string;
135
+ }
136
+ declare abstract class LoggerTransport extends Transform {
137
+ constructor(opts?: any);
138
+ listLogsByRunId(_args: {
139
+ runId: string;
140
+ fromDate?: Date;
141
+ toDate?: Date;
142
+ logLevel?: LogLevel;
143
+ filters?: Record<string, any>;
144
+ page?: number;
145
+ perPage?: number;
146
+ }): Promise<{
147
+ logs: BaseLogMessage[];
148
+ total: number;
149
+ page: number;
150
+ perPage: number;
151
+ hasMore: boolean;
152
+ }>;
153
+ listLogs(_args?: {
154
+ fromDate?: Date;
155
+ toDate?: Date;
156
+ logLevel?: LogLevel;
157
+ filters?: Record<string, any>;
158
+ returnPaginationResults?: boolean;
159
+ page?: number;
160
+ perPage?: number;
161
+ }): Promise<{
162
+ logs: BaseLogMessage[];
163
+ total: number;
164
+ page: number;
165
+ perPage: number;
166
+ hasMore: boolean;
167
+ }>;
168
+ }
169
+ declare const createCustomTransport: (stream: Transform, listLogs?: LoggerTransport['listLogs'], listLogsByRunId?: LoggerTransport['listLogsByRunId']) => LoggerTransport;
170
+ interface IMastraLogger {
171
+ debug(message: string, ...args: any[]): void;
172
+ info(message: string, ...args: any[]): void;
173
+ warn(message: string, ...args: any[]): void;
174
+ error(message: string, ...args: any[]): void;
175
+ trackException(error: Error, metadata?: Record<string, unknown>): void;
176
+ getTransports(): Map<string, LoggerTransport>;
177
+ listLogs(_transportId: string, _params?: {
178
+ fromDate?: Date;
179
+ toDate?: Date;
180
+ logLevel?: LogLevel;
181
+ filters?: Record<string, any>;
182
+ page?: number;
183
+ perPage?: number;
184
+ }): Promise<{
185
+ logs: BaseLogMessage[];
186
+ total: number;
187
+ page: number;
188
+ perPage: number;
189
+ hasMore: boolean;
190
+ }>;
191
+ listLogsByRunId(_args: {
192
+ transportId: string;
193
+ runId: string;
194
+ fromDate?: Date;
195
+ toDate?: Date;
196
+ logLevel?: LogLevel;
197
+ filters?: Record<string, any>;
198
+ page?: number;
199
+ perPage?: number;
200
+ }): Promise<{
201
+ logs: BaseLogMessage[];
202
+ total: number;
203
+ page: number;
204
+ perPage: number;
205
+ hasMore: boolean;
206
+ }>;
207
+ }
208
+ declare abstract class MastraLogger implements IMastraLogger {
209
+ protected name: string;
210
+ protected level: LogLevel;
211
+ protected transports: Map<string, LoggerTransport>;
212
+ constructor(options?: {
213
+ name?: string;
214
+ level?: LogLevel;
215
+ transports?: Record<string, LoggerTransport>;
216
+ });
217
+ abstract debug(message: string, ...args: any[]): void;
218
+ abstract info(message: string, ...args: any[]): void;
219
+ abstract warn(message: string, ...args: any[]): void;
220
+ abstract error(message: string, ...args: any[]): void;
221
+ getTransports(): Map<string, LoggerTransport>;
222
+ trackException(_error: Error, _metadata?: Record<string, unknown>): void;
223
+ listLogs(transportId: string, params?: {
224
+ fromDate?: Date;
225
+ toDate?: Date;
226
+ logLevel?: LogLevel;
227
+ filters?: Record<string, any>;
228
+ page?: number;
229
+ perPage?: number;
230
+ }): Promise<{
231
+ logs: BaseLogMessage[];
232
+ total: number;
233
+ page: number;
234
+ perPage: number;
235
+ hasMore: boolean;
236
+ }>;
237
+ listLogsByRunId({ transportId, runId, fromDate, toDate, logLevel, filters, page, perPage }: {
238
+ transportId: string;
239
+ runId: string;
240
+ fromDate?: Date;
241
+ toDate?: Date;
242
+ logLevel?: LogLevel;
243
+ filters?: Record<string, any>;
244
+ page?: number;
245
+ perPage?: number;
246
+ }): Promise<{
247
+ logs: BaseLogMessage[];
248
+ total: number;
249
+ page: number;
250
+ perPage: number;
251
+ hasMore: boolean;
252
+ }>;
253
+ }
254
+ type LogFilterContext = {
255
+ component?: RegisteredLogger;
256
+ level: LogLevel;
257
+ message: string;
258
+ args: unknown[];
259
+ };
260
+ type LogFilter = (ctx: LogFilterContext) => boolean;
261
+ interface ConsoleLoggerOptions {
262
+ name?: string;
263
+ level?: LogLevel;
264
+ component?: RegisteredLogger;
265
+ filter?: LogFilter;
266
+ }
267
+ declare class ConsoleLogger extends MastraLogger {
268
+ #private;
269
+ protected component?: RegisteredLogger;
270
+ protected filter?: LogFilter;
271
+ constructor(options?: ConsoleLoggerOptions);
272
+ /**
273
+ * Adapter hook (see `AdaptableLogger`): enables native trace correlation
274
+ * (trace_id/span_id appended to console output) and observability export
275
+ * derived from the same record. Called by Mastra during setup.
276
+ */
277
+ __attachObservability(ctx: LoggerAdapterContext): void;
278
+ child(componentOrBindings: RegisteredLogger | Record<string, unknown>): ConsoleLogger;
279
+ private shouldLog;
280
+ private prefix;
281
+ debug(message: string, ...args: any[]): void;
282
+ info(message: string, ...args: any[]): void;
283
+ warn(message: string, ...args: any[]): void;
284
+ error(message: string, ...args: any[]): void;
285
+ trackException(error: Error, metadata?: Record<string, unknown>): void;
286
+ listLogs(_transportId: string, _params?: {
287
+ fromDate?: Date;
288
+ toDate?: Date;
289
+ logLevel?: LogLevel;
290
+ filters?: Record<string, any>;
291
+ page?: number;
292
+ perPage?: number;
293
+ }): Promise<{
294
+ logs: never[];
295
+ total: number;
296
+ page: number;
297
+ perPage: number;
298
+ hasMore: boolean;
299
+ }>;
300
+ listLogsByRunId(_args: {
301
+ transportId: string;
302
+ runId: string;
303
+ fromDate?: Date;
304
+ toDate?: Date;
305
+ logLevel?: LogLevel;
306
+ filters?: Record<string, any>;
307
+ page?: number;
308
+ perPage?: number;
309
+ }): Promise<{
310
+ logs: never[];
311
+ total: number;
312
+ page: number;
313
+ perPage: number;
314
+ hasMore: boolean;
315
+ }>;
316
+ }
317
+ //#endregion
318
+ export { buildLogRecordData as _, LogFilter as a, LoggerTransport as c, createCustomTransport as d, AdaptableLogger as f, TraceFields as g, LoggerAdapterOptions as h, IMastraLogger as i, MastraLogger as l, LoggerAdapterContext as m, ConsoleLogger as n, LogFilterContext as o, AdapterLogSink as p, ConsoleLoggerOptions as r, LogLevel as s, BaseLogMessage as t, RegisteredLogger as u, exportTrackedException as v, isAdaptableLogger as y };
319
+ //# sourceMappingURL=index-Biaf3BmX.d.ts.map
@@ -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,7 @@
1
+ /**
2
+ * RBAC provider implementations.
3
+ *
4
+ * @license Mastra Enterprise License - see ee/LICENSE
5
+ */
6
+ export { StaticRBACProvider, type StaticRBACProviderOptions } from './static.js';
7
+ //# 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