@mastra/auth-supabase 1.1.6 → 1.2.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/dist/_types/{@internal_auth/dist/_types/@internal_core → @internal_auth@0.0.37/dist/_types/@internal_core@0.1.4}/dist/base/index.d.ts +1 -1
- package/dist/_types/{@internal_auth/dist/_types/@internal_core/dist/index-TNVgGNjs.d.ts → @internal_auth@0.0.37/dist/_types/@internal_core@0.1.4/dist/index-Diz1p9N7.d.ts} +3 -2
- package/dist/_types/@internal_auth@0.0.37/dist/ee/capabilities.d.ts +142 -0
- package/dist/_types/@internal_auth@0.0.37/dist/ee/defaults/index.d.ts +8 -0
- package/dist/_types/@internal_auth@0.0.37/dist/ee/defaults/rbac/index.d.ts +7 -0
- package/dist/_types/@internal_auth@0.0.37/dist/ee/defaults/rbac/static.d.ts +106 -0
- package/dist/_types/@internal_auth@0.0.37/dist/ee/defaults/roles.d.ts +92 -0
- package/dist/_types/@internal_auth@0.0.37/dist/ee/fga-check.d.ts +59 -0
- package/dist/_types/@internal_auth@0.0.37/dist/ee/index.d.ts +15 -0
- package/dist/_types/@internal_auth@0.0.37/dist/ee/interfaces/acl.d.ts +140 -0
- package/dist/_types/@internal_auth@0.0.37/dist/ee/interfaces/fga.d.ts +408 -0
- package/dist/_types/@internal_auth@0.0.37/dist/ee/interfaces/index.d.ts +15 -0
- package/dist/_types/@internal_auth@0.0.37/dist/ee/interfaces/permissions.generated.d.ts +551 -0
- package/dist/_types/@internal_auth@0.0.37/dist/ee/interfaces/rbac.d.ts +207 -0
- package/dist/_types/@internal_auth@0.0.37/dist/ee/interfaces/user.d.ts +18 -0
- package/dist/_types/@internal_auth@0.0.37/dist/ee/license.d.ts +171 -0
- package/dist/_types/@internal_auth@0.0.37/dist/index.d.ts +358 -0
- package/dist/_types/{@internal_auth → @internal_auth@0.0.37}/dist/provider/index.d.ts +74 -2
- package/dist/_types/@internal_auth@0.0.37/dist/session/cookie.d.ts +82 -0
- package/dist/_types/@internal_auth@0.0.37/dist/session/index.d.ts +39 -0
- package/dist/_types/@internal_auth@0.0.37/dist/session/memory.d.ts +60 -0
- package/dist/_types/{@internal_auth → @internal_auth@0.0.37}/dist/types/index.d.ts +7 -0
- package/dist/index.cjs +73 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +13 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +73 -0
- package/dist/index.js.map +1 -1
- package/package.json +7 -7
- package/LICENSE.md +0 -32
- /package/dist/_types/{@internal_auth → @internal_auth@0.0.37}/package.json +0 -0
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RBAC provider interface for EE authentication.
|
|
3
|
+
* Enables role-based access control in Studio.
|
|
4
|
+
*
|
|
5
|
+
* RBAC is designed to be separate from authentication.
|
|
6
|
+
* This allows users to mix auth providers with RBAC providers:
|
|
7
|
+
* - Use Better Auth for authentication + StaticRBACProvider for RBAC
|
|
8
|
+
* - Use Clerk for both auth and RBAC via MastraRBACClerk
|
|
9
|
+
* - Use Auth0 for auth + custom RBAC provider
|
|
10
|
+
*/
|
|
11
|
+
import type { PermissionPattern } from './permissions.generated.js';
|
|
12
|
+
/**
|
|
13
|
+
* Definition of a role with its permissions.
|
|
14
|
+
* Uses type-safe permission patterns derived from SERVER_ROUTES.
|
|
15
|
+
*/
|
|
16
|
+
export interface RoleDefinition {
|
|
17
|
+
/** Unique role identifier */
|
|
18
|
+
id: string;
|
|
19
|
+
/** Human-readable role name */
|
|
20
|
+
name: string;
|
|
21
|
+
/** Role description */
|
|
22
|
+
description?: string;
|
|
23
|
+
/** Permissions granted by this role (type-safe) */
|
|
24
|
+
permissions: PermissionPattern[];
|
|
25
|
+
/** Role IDs this role inherits from */
|
|
26
|
+
inherits?: string[];
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Role mapping configuration for translating provider roles to Mastra permissions.
|
|
30
|
+
* Uses type-safe permission patterns derived from SERVER_ROUTES.
|
|
31
|
+
*
|
|
32
|
+
* Use this when your identity provider (WorkOS, Okta, Azure AD, etc.) has its own
|
|
33
|
+
* roles that need to be translated to Mastra's permission model.
|
|
34
|
+
*
|
|
35
|
+
* Special keys:
|
|
36
|
+
* - `_default`: Permissions for roles not explicitly mapped
|
|
37
|
+
*
|
|
38
|
+
* @example
|
|
39
|
+
* ```typescript
|
|
40
|
+
* const roleMapping: RoleMapping = {
|
|
41
|
+
* "Engineering": ["agents:*", "workflows:*"],
|
|
42
|
+
* "Product": ["agents:read", "workflows:read"],
|
|
43
|
+
* "Admin": ["*"],
|
|
44
|
+
* "_default": [], // unmapped roles get no permissions
|
|
45
|
+
* };
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
export type RoleMapping = {
|
|
49
|
+
/** Map role name to array of permission patterns */
|
|
50
|
+
[role: string]: PermissionPattern[];
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Provider interface for role-based access control (read-only).
|
|
54
|
+
*
|
|
55
|
+
* Implement this interface to enable:
|
|
56
|
+
* - Permission-based UI gating
|
|
57
|
+
* - Role display in user menu
|
|
58
|
+
* - Access control checks
|
|
59
|
+
*
|
|
60
|
+
* RBAC providers can be used independently of auth providers:
|
|
61
|
+
*
|
|
62
|
+
* @example Using StaticRBACProvider with Better Auth
|
|
63
|
+
* ```typescript
|
|
64
|
+
* // Better Auth handles authentication only
|
|
65
|
+
* const auth = new MastraAuthBetterAuth({ betterAuth });
|
|
66
|
+
*
|
|
67
|
+
* // Static RBAC handles authorization
|
|
68
|
+
* const rbac = new StaticRBACProvider({
|
|
69
|
+
* roles: DEFAULT_ROLES,
|
|
70
|
+
* getUserRoles: (user) => [user.role],
|
|
71
|
+
* });
|
|
72
|
+
*
|
|
73
|
+
* const mastra = new Mastra({
|
|
74
|
+
* server: {
|
|
75
|
+
* auth,
|
|
76
|
+
* rbac,
|
|
77
|
+
* },
|
|
78
|
+
* });
|
|
79
|
+
* ```
|
|
80
|
+
*
|
|
81
|
+
* @example Using MastraRBACClerk with role mapping
|
|
82
|
+
* ```typescript
|
|
83
|
+
* const mastra = new Mastra({
|
|
84
|
+
* server: {
|
|
85
|
+
* auth: new MastraAuthClerk({ clerk }),
|
|
86
|
+
* rbac: new MastraRBACClerk({
|
|
87
|
+
* clerk,
|
|
88
|
+
* roleMapping: {
|
|
89
|
+
* "org:admin": ["*"],
|
|
90
|
+
* "org:member": ["agents:read", "workflows:read"],
|
|
91
|
+
* },
|
|
92
|
+
* }),
|
|
93
|
+
* },
|
|
94
|
+
* });
|
|
95
|
+
* ```
|
|
96
|
+
*/
|
|
97
|
+
export interface IRBACProvider<TUser = unknown> {
|
|
98
|
+
/**
|
|
99
|
+
* Optional role mapping for translating provider roles to Mastra permissions.
|
|
100
|
+
* If provided, permissions are resolved using this mapping instead of getPermissions().
|
|
101
|
+
*/
|
|
102
|
+
roleMapping?: RoleMapping;
|
|
103
|
+
/**
|
|
104
|
+
* Get all roles for a user.
|
|
105
|
+
*
|
|
106
|
+
* @param user - User to get roles for
|
|
107
|
+
* @returns Array of role IDs
|
|
108
|
+
*/
|
|
109
|
+
getRoles(user: TUser): Promise<string[]>;
|
|
110
|
+
/**
|
|
111
|
+
* Check if user has a specific role.
|
|
112
|
+
*
|
|
113
|
+
* @param user - User to check
|
|
114
|
+
* @param role - Role ID to check for
|
|
115
|
+
* @returns True if user has the role
|
|
116
|
+
*/
|
|
117
|
+
hasRole(user: TUser, role: string): Promise<boolean>;
|
|
118
|
+
/**
|
|
119
|
+
* Get all permissions for a user (resolved from roles).
|
|
120
|
+
*
|
|
121
|
+
* @param user - User to get permissions for
|
|
122
|
+
* @returns Array of permission strings
|
|
123
|
+
*/
|
|
124
|
+
getPermissions(user: TUser): Promise<string[]>;
|
|
125
|
+
/**
|
|
126
|
+
* Check if user has a specific permission.
|
|
127
|
+
*
|
|
128
|
+
* @param user - User to check
|
|
129
|
+
* @param permission - Permission to check for
|
|
130
|
+
* @returns True if user has the permission
|
|
131
|
+
*/
|
|
132
|
+
hasPermission(user: TUser, permission: string): Promise<boolean>;
|
|
133
|
+
/**
|
|
134
|
+
* Check if user has ALL of the specified permissions.
|
|
135
|
+
*
|
|
136
|
+
* @param user - User to check
|
|
137
|
+
* @param permissions - Permissions to check for
|
|
138
|
+
* @returns True if user has all permissions
|
|
139
|
+
*/
|
|
140
|
+
hasAllPermissions(user: TUser, permissions: string[]): Promise<boolean>;
|
|
141
|
+
/**
|
|
142
|
+
* Check if user has ANY of the specified permissions.
|
|
143
|
+
*
|
|
144
|
+
* @param user - User to check
|
|
145
|
+
* @param permissions - Permissions to check for
|
|
146
|
+
* @returns True if user has at least one permission
|
|
147
|
+
*/
|
|
148
|
+
hasAnyPermission(user: TUser, permissions: string[]): Promise<boolean>;
|
|
149
|
+
/**
|
|
150
|
+
* Get all available roles in the system.
|
|
151
|
+
* Used by the "View as role" feature to list roles an admin can impersonate.
|
|
152
|
+
*
|
|
153
|
+
* @returns Array of role descriptors
|
|
154
|
+
*/
|
|
155
|
+
getAvailableRoles?(): Promise<{
|
|
156
|
+
id: string;
|
|
157
|
+
name: string;
|
|
158
|
+
}[]>;
|
|
159
|
+
/**
|
|
160
|
+
* Get the resolved permissions for a specific role.
|
|
161
|
+
* Used by the "View as role" feature to override client-side permissions.
|
|
162
|
+
*
|
|
163
|
+
* @param roleId - Role ID to resolve permissions for
|
|
164
|
+
* @returns Array of permission strings
|
|
165
|
+
*/
|
|
166
|
+
getPermissionsForRole?(roleId: string): Promise<string[]>;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Extended interface for managing roles (write operations).
|
|
170
|
+
*
|
|
171
|
+
* Implement this in addition to IRBACProvider to enable role management.
|
|
172
|
+
*/
|
|
173
|
+
export interface IRBACManager<TUser = unknown> extends IRBACProvider<TUser> {
|
|
174
|
+
/**
|
|
175
|
+
* Assign a role to a user.
|
|
176
|
+
*
|
|
177
|
+
* @param userId - User to assign role to
|
|
178
|
+
* @param roleId - Role to assign
|
|
179
|
+
*/
|
|
180
|
+
assignRole(userId: string, roleId: string): Promise<void>;
|
|
181
|
+
/**
|
|
182
|
+
* Remove a role from a user.
|
|
183
|
+
*
|
|
184
|
+
* @param userId - User to remove role from
|
|
185
|
+
* @param roleId - Role to remove
|
|
186
|
+
*/
|
|
187
|
+
removeRole(userId: string, roleId: string): Promise<void>;
|
|
188
|
+
/**
|
|
189
|
+
* List all available roles.
|
|
190
|
+
*
|
|
191
|
+
* @returns Array of role definitions
|
|
192
|
+
*/
|
|
193
|
+
listRoles(): Promise<RoleDefinition[]>;
|
|
194
|
+
/**
|
|
195
|
+
* Optional: Create a new role.
|
|
196
|
+
*
|
|
197
|
+
* @param role - Role definition to create
|
|
198
|
+
*/
|
|
199
|
+
createRole?(role: RoleDefinition): Promise<void>;
|
|
200
|
+
/**
|
|
201
|
+
* Optional: Delete a role.
|
|
202
|
+
*
|
|
203
|
+
* @param roleId - Role ID to delete
|
|
204
|
+
*/
|
|
205
|
+
deleteRole?(roleId: string): Promise<void>;
|
|
206
|
+
}
|
|
207
|
+
//# sourceMappingURL=rbac.d.ts.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Enterprise user type for EE authentication.
|
|
3
|
+
* Extends the base User type with enterprise-specific fields.
|
|
4
|
+
*
|
|
5
|
+
* @license Mastra Enterprise License - see ee/LICENSE
|
|
6
|
+
*/
|
|
7
|
+
import type { User } from '../../index.js';
|
|
8
|
+
/**
|
|
9
|
+
* Enterprise user type with additional metadata.
|
|
10
|
+
*
|
|
11
|
+
* Extends the base `User` type with fields commonly needed
|
|
12
|
+
* for RBAC, ACL, and organizational features.
|
|
13
|
+
*/
|
|
14
|
+
export interface EEUser extends User {
|
|
15
|
+
/** Additional metadata */
|
|
16
|
+
metadata?: Record<string, unknown>;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=user.d.ts.map
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* License validation for EE features.
|
|
3
|
+
*
|
|
4
|
+
* Validation is delegated to the Mastra license server via `LicenseClient`
|
|
5
|
+
* (POST {MASTRA_LICENSE_URL}/validate). The client validates in the
|
|
6
|
+
* background and caches the result; the synchronous helpers in this module
|
|
7
|
+
* read the cached state:
|
|
8
|
+
*
|
|
9
|
+
* - No license key configured → EE features disabled.
|
|
10
|
+
* - Key configured, validation pending → fail open (features enabled) until
|
|
11
|
+
* the first server response settles the state.
|
|
12
|
+
* - Server says invalid/revoked/expired → EE features disabled.
|
|
13
|
+
* - Server unreachable → fail open with a 72h grace period for previously
|
|
14
|
+
* validated licenses.
|
|
15
|
+
*
|
|
16
|
+
* `MASTRA_LICENSE_KEY` is the primary env var; `MASTRA_EE_LICENSE` is a
|
|
17
|
+
* supported legacy alias.
|
|
18
|
+
*/
|
|
19
|
+
interface IMastraLogger {
|
|
20
|
+
warn(message: string): void;
|
|
21
|
+
info(message: string): void;
|
|
22
|
+
error(message: string): void;
|
|
23
|
+
}
|
|
24
|
+
export interface LicenseValidationSuccess {
|
|
25
|
+
valid: true;
|
|
26
|
+
/** Feature entitlements granted by the license (e.g. 'rbac', 'sso', 'fga') */
|
|
27
|
+
entitlements: string[];
|
|
28
|
+
/** Plan tier the license was issued for (e.g. 'teams', 'enterprise') */
|
|
29
|
+
planTier: string;
|
|
30
|
+
expiresAt: string | null;
|
|
31
|
+
leaseTtlSeconds: number;
|
|
32
|
+
}
|
|
33
|
+
export interface LicenseValidationError {
|
|
34
|
+
valid: false;
|
|
35
|
+
code: 'INVALID_KEY' | 'LICENSE_EXPIRED' | 'LICENSE_REVOKED' | 'RATE_LIMITED';
|
|
36
|
+
reason: string;
|
|
37
|
+
}
|
|
38
|
+
export type LicenseValidationResponse = LicenseValidationSuccess | LicenseValidationError;
|
|
39
|
+
export type LicenseMode = 'enterprise' | 'open-source';
|
|
40
|
+
export type LicenseStatus = 'pending' | 'valid' | 'invalid';
|
|
41
|
+
export interface LicenseSnapshot {
|
|
42
|
+
mode: LicenseMode;
|
|
43
|
+
status: LicenseStatus;
|
|
44
|
+
entitlements: string[] | null;
|
|
45
|
+
planTier: string | null;
|
|
46
|
+
expiresAt: string | null;
|
|
47
|
+
}
|
|
48
|
+
export declare class LicenseClient {
|
|
49
|
+
private static instance;
|
|
50
|
+
private logger?;
|
|
51
|
+
private licenseKey?;
|
|
52
|
+
private licenseUrl?;
|
|
53
|
+
private mode;
|
|
54
|
+
private status;
|
|
55
|
+
private cachedResult;
|
|
56
|
+
private cacheExpiry;
|
|
57
|
+
private gracePeriodEnd;
|
|
58
|
+
private revalidationTimeout;
|
|
59
|
+
private readonly GRACE_PERIOD_MS;
|
|
60
|
+
private readonly DEFAULT_TTL_MS;
|
|
61
|
+
private constructor();
|
|
62
|
+
static getInstance(logger?: IMastraLogger): LicenseClient;
|
|
63
|
+
/**
|
|
64
|
+
* Reset the singleton so the next getInstance() re-reads env vars.
|
|
65
|
+
* Intended for tests.
|
|
66
|
+
*/
|
|
67
|
+
static resetInstance(): void;
|
|
68
|
+
private readonly REQUEST_TIMEOUT_MS;
|
|
69
|
+
private fetchWithRetry;
|
|
70
|
+
private validationPromise;
|
|
71
|
+
validate(): Promise<boolean>;
|
|
72
|
+
/**
|
|
73
|
+
* Contact the server regardless of cache freshness, coalescing concurrent
|
|
74
|
+
* callers (e.g. the Mastra constructor and the auth/ee helpers both kicking
|
|
75
|
+
* off validation at startup) into a single in-flight request so the server
|
|
76
|
+
* is contacted — and the outcome logged — only once. Used directly by the
|
|
77
|
+
* background revalidation timer, which must bypass the cache check.
|
|
78
|
+
*/
|
|
79
|
+
private revalidate;
|
|
80
|
+
private performValidation;
|
|
81
|
+
private scheduleRevalidation;
|
|
82
|
+
private clearCache;
|
|
83
|
+
hasFeature(featureName: string): boolean;
|
|
84
|
+
getEntitlements(): string[] | null;
|
|
85
|
+
getSnapshot(): LicenseSnapshot;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* License information.
|
|
89
|
+
*/
|
|
90
|
+
export interface LicenseInfo {
|
|
91
|
+
/** Whether the license is valid */
|
|
92
|
+
valid: boolean;
|
|
93
|
+
/** License expiration date */
|
|
94
|
+
expiresAt?: Date;
|
|
95
|
+
/** Features enabled by this license */
|
|
96
|
+
features?: string[];
|
|
97
|
+
/** Organization name */
|
|
98
|
+
organization?: string;
|
|
99
|
+
/** License plan tier (e.g. 'teams', 'enterprise') */
|
|
100
|
+
tier?: string;
|
|
101
|
+
}
|
|
102
|
+
export interface SafeLicenseSummary {
|
|
103
|
+
valid: boolean;
|
|
104
|
+
isDevEnvironment: boolean;
|
|
105
|
+
licenseHash?: string;
|
|
106
|
+
anonymousId?: string;
|
|
107
|
+
features?: string[];
|
|
108
|
+
tier?: string;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Start license validation against the license server.
|
|
112
|
+
*
|
|
113
|
+
* Safe to call multiple times — the underlying client caches results and
|
|
114
|
+
* schedules its own background revalidation. Resolves to whether the license
|
|
115
|
+
* is currently considered valid.
|
|
116
|
+
*/
|
|
117
|
+
export declare function startLicenseValidation(): Promise<boolean>;
|
|
118
|
+
/**
|
|
119
|
+
* Validate the configured license and return license information.
|
|
120
|
+
*
|
|
121
|
+
* Reflects the current server-backed validation state. The actual network
|
|
122
|
+
* validation happens in the background via `LicenseClient`, and only the
|
|
123
|
+
* configured key (env var) is ever validated — passing any other key
|
|
124
|
+
* returns invalid.
|
|
125
|
+
*
|
|
126
|
+
* @param licenseKey - Optional key to check; must match the configured key.
|
|
127
|
+
* @returns License information
|
|
128
|
+
*/
|
|
129
|
+
export declare function validateLicense(licenseKey?: string): LicenseInfo;
|
|
130
|
+
/**
|
|
131
|
+
* Check if EE features are enabled (valid or pending server validation).
|
|
132
|
+
*
|
|
133
|
+
* @returns True if EE features should be enabled
|
|
134
|
+
*/
|
|
135
|
+
export declare function isLicenseValid(): boolean;
|
|
136
|
+
/**
|
|
137
|
+
* @deprecated Use `isLicenseValid()` instead. This alias is provided for backward compatibility.
|
|
138
|
+
*/
|
|
139
|
+
export declare const isEELicenseValid: typeof isLicenseValid;
|
|
140
|
+
/**
|
|
141
|
+
* Check if a specific EE feature is enabled by the license entitlements.
|
|
142
|
+
*
|
|
143
|
+
* @param feature - Feature name to check (e.g. 'rbac', 'fga', 'sso')
|
|
144
|
+
* @returns True if the feature is enabled
|
|
145
|
+
*/
|
|
146
|
+
export declare function isFeatureEnabled(feature: string): boolean;
|
|
147
|
+
/**
|
|
148
|
+
* Get the current license information.
|
|
149
|
+
*
|
|
150
|
+
* @returns License info or null if no license key is configured
|
|
151
|
+
*/
|
|
152
|
+
export declare function getLicenseInfo(): LicenseInfo | null;
|
|
153
|
+
export declare function getSafeLicenseSummary(): SafeLicenseSummary;
|
|
154
|
+
export declare function warnIfDevEENeedsLicense(): void;
|
|
155
|
+
/**
|
|
156
|
+
* Clear the license cache (useful for testing).
|
|
157
|
+
* Resets the shared client so the next check re-reads env vars.
|
|
158
|
+
*/
|
|
159
|
+
export declare function clearLicenseCache(): void;
|
|
160
|
+
/**
|
|
161
|
+
* Check if running in a development/testing environment.
|
|
162
|
+
* In dev, EE features work without a license per the ee/LICENSE terms.
|
|
163
|
+
*/
|
|
164
|
+
export declare function isDevEnvironment(): boolean;
|
|
165
|
+
/**
|
|
166
|
+
* Check if EE features should be active.
|
|
167
|
+
* Returns true if running in dev/test environment (always allowed) or if a valid license is present.
|
|
168
|
+
*/
|
|
169
|
+
export declare function isEEEnabled(): boolean;
|
|
170
|
+
export {};
|
|
171
|
+
//# sourceMappingURL=license.d.ts.map
|