@mastra/auth-supabase 1.1.6-alpha.0 → 1.2.0-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.
Files changed (31) hide show
  1. package/dist/_types/{@internal_auth/dist/_types/@internal_core → @internal_auth@0.0.36/dist/_types/@internal_core@0.1.4}/dist/base/index.d.ts +1 -1
  2. package/dist/_types/{@internal_auth/dist/_types/@internal_core/dist/index-TNVgGNjs.d.ts → @internal_auth@0.0.36/dist/_types/@internal_core@0.1.4/dist/index-Diz1p9N7.d.ts} +3 -2
  3. package/dist/_types/@internal_auth@0.0.36/dist/ee/capabilities.d.ts +142 -0
  4. package/dist/_types/@internal_auth@0.0.36/dist/ee/defaults/index.d.ts +8 -0
  5. package/dist/_types/@internal_auth@0.0.36/dist/ee/defaults/rbac/index.d.ts +7 -0
  6. package/dist/_types/@internal_auth@0.0.36/dist/ee/defaults/rbac/static.d.ts +106 -0
  7. package/dist/_types/@internal_auth@0.0.36/dist/ee/defaults/roles.d.ts +92 -0
  8. package/dist/_types/@internal_auth@0.0.36/dist/ee/fga-check.d.ts +59 -0
  9. package/dist/_types/@internal_auth@0.0.36/dist/ee/index.d.ts +15 -0
  10. package/dist/_types/@internal_auth@0.0.36/dist/ee/interfaces/acl.d.ts +140 -0
  11. package/dist/_types/@internal_auth@0.0.36/dist/ee/interfaces/fga.d.ts +408 -0
  12. package/dist/_types/@internal_auth@0.0.36/dist/ee/interfaces/index.d.ts +15 -0
  13. package/dist/_types/@internal_auth@0.0.36/dist/ee/interfaces/permissions.generated.d.ts +551 -0
  14. package/dist/_types/@internal_auth@0.0.36/dist/ee/interfaces/rbac.d.ts +207 -0
  15. package/dist/_types/@internal_auth@0.0.36/dist/ee/interfaces/user.d.ts +18 -0
  16. package/dist/_types/@internal_auth@0.0.36/dist/ee/license.d.ts +171 -0
  17. package/dist/_types/@internal_auth@0.0.36/dist/index.d.ts +358 -0
  18. package/dist/_types/{@internal_auth → @internal_auth@0.0.36}/dist/provider/index.d.ts +74 -2
  19. package/dist/_types/@internal_auth@0.0.36/dist/session/cookie.d.ts +82 -0
  20. package/dist/_types/@internal_auth@0.0.36/dist/session/index.d.ts +39 -0
  21. package/dist/_types/@internal_auth@0.0.36/dist/session/memory.d.ts +60 -0
  22. package/dist/_types/{@internal_auth → @internal_auth@0.0.36}/dist/types/index.d.ts +7 -0
  23. package/dist/index.cjs +73 -0
  24. package/dist/index.cjs.map +1 -1
  25. package/dist/index.d.ts +13 -2
  26. package/dist/index.d.ts.map +1 -1
  27. package/dist/index.js +73 -0
  28. package/dist/index.js.map +1 -1
  29. package/package.json +7 -7
  30. package/LICENSE.md +0 -32
  31. /package/dist/_types/{@internal_auth → @internal_auth@0.0.36}/package.json +0 -0
@@ -0,0 +1,408 @@
1
+ /**
2
+ * FGA (Fine-Grained Authorization) provider interface for EE authentication.
3
+ * Enables relationship-based, resource-level authorization.
4
+ *
5
+ * FGA complements RBAC by answering "Can this user do this action on this specific resource?"
6
+ * rather than "Can this role do this action?"
7
+ *
8
+ * @license Mastra Enterprise License - see ee/LICENSE
9
+ */
10
+ import type { MastraFGAPermissionInput } from './permissions.generated.js';
11
+ /**
12
+ * Signals that a call is made by a trusted non-user actor rather than an
13
+ * authenticated end user.
14
+ *
15
+ * - `true` is the anonymous system shorthand.
16
+ * - The object form additionally names the acting agent (`agentId`) and carries
17
+ * the permission grants / scope a provider can enforce for least privilege.
18
+ */
19
+ export type ActorSignal = true | {
20
+ actorKind: 'system';
21
+ sourceWorkflow?: string;
22
+ /**
23
+ * Identity of the acting system agent. Unlike the check `resource` (the
24
+ * target), this names the actor itself so a provider can enforce
25
+ * per-agent least privilege.
26
+ */
27
+ agentId?: string;
28
+ /**
29
+ * Permission grants *claimed* for this actor — the actor analog of a
30
+ * user's resolved permissions. This is an untrusted, self-asserted hint:
31
+ * a provider enforcing real least privilege should resolve the actor's
32
+ * authoritative grants from a trusted source (e.g. a manifest or FGA,
33
+ * keyed by `agentId`) rather than trusting these values directly.
34
+ */
35
+ permissions?: MastraFGAPermissionInput[];
36
+ /** Additional provider-specific scope for the actor (e.g. tenant, environment). */
37
+ scope?: Record<string, string>;
38
+ /**
39
+ * Opt in to propagating this actor into the agent/tool calls the framework
40
+ * makes for declarative workflow steps (`.then(agent)` / `.then(tool)`)
41
+ * within this run's own execution tree.
42
+ *
43
+ * Never implicit, and ignored by authorization itself. Custom step
44
+ * `execute` closures are not covered — they already receive `actor` on the
45
+ * step context and must pass it explicitly. The `true` shorthand cannot
46
+ * opt in; use this object form.
47
+ */
48
+ propagate?: boolean;
49
+ };
50
+ /**
51
+ * Optional context for an authorization check.
52
+ */
53
+ export interface FGACheckContext {
54
+ /**
55
+ * The owning application resource ID for the target resource.
56
+ * Useful when the authorization resource ID differs from the route-level ID,
57
+ * such as thread checks scoped by a thread's owning tenant/resource.
58
+ */
59
+ resourceId?: string;
60
+ /**
61
+ * Optional request context for providers that need additional request-scoped
62
+ * data to derive the authorization resource identifier.
63
+ */
64
+ requestContext?: any;
65
+ /**
66
+ * Optional provider-specific metadata about the attempted action.
67
+ */
68
+ metadata?: Record<string, unknown>;
69
+ }
70
+ /**
71
+ * Parameters for an authorization check.
72
+ */
73
+ export interface FGACheckParams {
74
+ /** The resource being accessed */
75
+ resource: {
76
+ type: string;
77
+ id: string;
78
+ };
79
+ /**
80
+ * The permission(s) being checked.
81
+ * When an array is provided, the user needs ANY ONE of the listed permissions
82
+ * (the check passes if any single permission resolves to allow).
83
+ */
84
+ permission: MastraFGAPermissionInput | MastraFGAPermissionInput[];
85
+ /** Optional provider-specific context for resource resolution */
86
+ context?: FGACheckContext;
87
+ }
88
+ /**
89
+ * Route-level FGA metadata.
90
+ */
91
+ export interface FGARouteConfig {
92
+ /** Resource type slug to authorize against, e.g. `agent`, `workflow`, or `thread`. */
93
+ resourceType: string;
94
+ /** Path/body/query parameter name that contains the resource ID. */
95
+ resourceIdParam?: string;
96
+ /** Static or dynamic resource ID resolver. */
97
+ resourceId?: string | ((params: Record<string, unknown>, context: {
98
+ requestContext?: any;
99
+ }) => string | undefined);
100
+ /**
101
+ * Permission(s) to check for this route. Falls back to the route permission when omitted.
102
+ * When an array is provided, the user needs ANY ONE of the listed permissions.
103
+ */
104
+ permission?: MastraFGAPermissionInput | MastraFGAPermissionInput[];
105
+ }
106
+ /**
107
+ * Minimal route information exposed to global FGA route resolvers.
108
+ */
109
+ export interface FGARouteInfo {
110
+ path: string;
111
+ method: string;
112
+ requiresAuth?: boolean;
113
+ /**
114
+ * Permission(s) required by this route.
115
+ * When an array is provided, the user needs ANY ONE of the listed permissions.
116
+ */
117
+ requiresPermission?: MastraFGAPermissionInput | MastraFGAPermissionInput[];
118
+ fga?: FGARouteConfig;
119
+ }
120
+ /**
121
+ * Context passed to global FGA route resolvers.
122
+ */
123
+ export interface FGARouteResolverContext {
124
+ route: FGARouteInfo;
125
+ params: Record<string, unknown>;
126
+ requestContext?: any;
127
+ }
128
+ /**
129
+ * Resolves route-level FGA metadata without mutating each route registration.
130
+ */
131
+ export type FGARouteResolver = (context: FGARouteResolverContext) => FGARouteConfig | null | undefined | Promise<FGARouteConfig | null | undefined>;
132
+ /**
133
+ * An authorization resource in the FGA system.
134
+ */
135
+ export interface FGAResource {
136
+ /** Internal resource ID */
137
+ id: string;
138
+ /** External ID (your application's resource identifier) */
139
+ externalId: string;
140
+ /** Display name */
141
+ name: string;
142
+ /** Optional description */
143
+ description?: string | null;
144
+ /** Resource type slug (e.g., 'team', 'project', 'workspace') */
145
+ resourceTypeSlug: string;
146
+ /** Organization ID the resource belongs to */
147
+ organizationId: string;
148
+ /** Parent resource ID for hierarchical resources */
149
+ parentResourceId?: string | null;
150
+ }
151
+ /**
152
+ * Parameters for creating an authorization resource.
153
+ */
154
+ export interface FGACreateResourceParams {
155
+ /** External ID (your application's resource identifier) */
156
+ externalId: string;
157
+ /** Display name */
158
+ name: string;
159
+ /** Optional description */
160
+ description?: string | null;
161
+ /** Resource type slug */
162
+ resourceTypeSlug: string;
163
+ /** Organization ID */
164
+ organizationId: string;
165
+ /** Parent resource ID (by internal ID) */
166
+ parentResourceId?: string;
167
+ /** Parent resource external ID (alternative to parentResourceId) */
168
+ parentResourceExternalId?: string;
169
+ /** Parent resource type slug (required with parentResourceExternalId) */
170
+ parentResourceTypeSlug?: string;
171
+ }
172
+ /**
173
+ * Parameters for updating an authorization resource.
174
+ */
175
+ export interface FGAUpdateResourceParams {
176
+ /** Internal resource ID */
177
+ resourceId: string;
178
+ /** New name */
179
+ name?: string;
180
+ /** New description */
181
+ description?: string | null;
182
+ }
183
+ /**
184
+ * Parameters for deleting an authorization resource.
185
+ */
186
+ export interface FGADeleteResourceParams {
187
+ /** Delete by internal resource ID */
188
+ resourceId?: string;
189
+ /** Delete by external ID (use with resourceTypeSlug and organizationId) */
190
+ externalId?: string;
191
+ /** Resource type slug (required when using externalId) */
192
+ resourceTypeSlug?: string;
193
+ /** Organization ID (required when using externalId) */
194
+ organizationId?: string;
195
+ }
196
+ /**
197
+ * A role assignment binding a membership to a role on a resource.
198
+ */
199
+ export interface FGARoleAssignment {
200
+ /** Assignment ID */
201
+ id: string;
202
+ /** The role */
203
+ role: {
204
+ slug: string;
205
+ };
206
+ /** The resource the role is assigned on */
207
+ resource: {
208
+ id: string;
209
+ externalId: string;
210
+ resourceTypeSlug: string;
211
+ };
212
+ }
213
+ /**
214
+ * Parameters for assigning or removing a role on a resource.
215
+ */
216
+ export interface FGARoleParams {
217
+ /** Organization membership ID */
218
+ organizationMembershipId: string;
219
+ /** Role slug to assign/remove */
220
+ roleSlug: string;
221
+ /** Resource ID to scope the role to */
222
+ resourceId?: string;
223
+ /** Resource external ID (alternative to resourceId) */
224
+ resourceExternalId?: string;
225
+ /** Resource type slug (required when using resourceExternalId) */
226
+ resourceTypeSlug?: string;
227
+ }
228
+ /**
229
+ * Options for listing role assignments.
230
+ */
231
+ export interface FGAListRoleAssignmentsOptions {
232
+ /** Organization membership ID */
233
+ organizationMembershipId: string;
234
+ /** Pagination limit */
235
+ limit?: number;
236
+ /** Pagination cursor */
237
+ after?: string;
238
+ }
239
+ /**
240
+ * Options for listing authorization resources.
241
+ */
242
+ export interface FGAListResourcesOptions {
243
+ /** Filter by organization */
244
+ organizationId?: string;
245
+ /** Filter by resource type */
246
+ resourceTypeSlug?: string;
247
+ /** Filter by parent resource */
248
+ parentResourceId?: string;
249
+ /** Search by name */
250
+ search?: string;
251
+ /** Pagination limit */
252
+ limit?: number;
253
+ /** Pagination cursor */
254
+ after?: string;
255
+ }
256
+ /**
257
+ * Provider interface for fine-grained authorization (read-only).
258
+ *
259
+ * This interface follows a user-centric model:
260
+ * - `check()` answers "Can this user perform this permission on this resource?"
261
+ * - `require()` throws if the user lacks permission
262
+ * - `filterAccessible()` filters a list of resources to only those the user can access
263
+ *
264
+ * The provider is responsible for translating between Mastra's resource/permission
265
+ * model and the underlying FGA provider's API (e.g., WorkOS Authorization).
266
+ *
267
+ * @example
268
+ * ```typescript
269
+ * import { MastraFGAPermissions } from '@mastra/core/auth/ee';
270
+ *
271
+ * const fga = new MastraFGAWorkos({
272
+ * resourceMapping: {
273
+ * agent: { fgaResourceType: 'team', deriveId: (ctx) => ctx.user.teamId },
274
+ * workflow: { fgaResourceType: 'team', deriveId: (ctx) => ctx.user.teamId },
275
+ * thread: { fgaResourceType: 'user', deriveId: (ctx) => ctx.resourceId ?? ctx.user.userId },
276
+ * },
277
+ * permissionMapping: {
278
+ * [MastraFGAPermissions.AGENTS_READ]: 'read',
279
+ * [MastraFGAPermissions.AGENTS_EXECUTE]: 'manage-workflows',
280
+ * [MastraFGAPermissions.WORKFLOWS_EXECUTE]: 'manage-workflows',
281
+ * [MastraFGAPermissions.MEMORY_READ]: 'read',
282
+ * [MastraFGAPermissions.MEMORY_WRITE]: 'update',
283
+ * },
284
+ * });
285
+ *
286
+ * // Check if a user can execute an agent
287
+ * const allowed = await fga.check(user, {
288
+ * resource: { type: 'agent', id: 'chef-agent' },
289
+ * permission: MastraFGAPermissions.AGENTS_EXECUTE,
290
+ * });
291
+ * ```
292
+ */
293
+ export interface IFGAProvider<TUser = unknown> {
294
+ /**
295
+ * When true, protected routes without route-level FGA metadata or resolver
296
+ * output are denied instead of being allowed through.
297
+ *
298
+ * @default false
299
+ */
300
+ requireForProtectedRoutes?: boolean;
301
+ /**
302
+ * Audits protected routes that do not have built-in FGA metadata.
303
+ * Use `true` or `'warn'` to log a startup warning, `'error'` to fail startup,
304
+ * or `false` to disable the audit.
305
+ *
306
+ * @default false
307
+ */
308
+ auditProtectedRoutes?: boolean | 'warn' | 'error';
309
+ /**
310
+ * Global route FGA resolver. This can derive resource type, resource ID, and
311
+ * permission from the route, parsed params, and request context.
312
+ */
313
+ resolveRouteFGA?: FGARouteResolver;
314
+ /**
315
+ * Optional startup validation for provider-specific permission mappings.
316
+ * Providers can throw when a permission Mastra may emit is not mapped.
317
+ */
318
+ validatePermissions?: (permissions: MastraFGAPermissionInput[]) => void | Promise<void>;
319
+ /**
320
+ * Check if a user has a specific permission on a resource.
321
+ *
322
+ * @param user - The user to check
323
+ * @param params - The resource and permission to check
324
+ * @returns true if the user has permission, false otherwise
325
+ */
326
+ check(user: TUser, params: FGACheckParams): Promise<boolean>;
327
+ /**
328
+ * Require that a user has a specific permission on a resource.
329
+ * Throws FGADeniedError if the user does not have permission.
330
+ *
331
+ * @param user - The user to check
332
+ * @param params - The resource and permission to check
333
+ * @throws FGADeniedError if the user does not have permission
334
+ */
335
+ require(user: TUser, params: FGACheckParams): Promise<void>;
336
+ /**
337
+ * Filter a list of resources to only those the user can access.
338
+ *
339
+ * @param user - The user to check
340
+ * @param resources - The resources to filter
341
+ * @param resourceType - The type of resources being filtered
342
+ * @param permission - The permission to check for
343
+ * @returns The filtered list of resources the user can access
344
+ */
345
+ filterAccessible<T extends {
346
+ id: string;
347
+ }>(user: TUser, resources: T[], resourceType: string, permission: MastraFGAPermissionInput): Promise<T[]>;
348
+ /**
349
+ * Authorize a non-user (system / autonomous agent) actor.
350
+ *
351
+ * System actors bypass the user-centric `require()` path. Implement this
352
+ * method to opt in to provider-driven least privilege for those actors:
353
+ * decide whether the actor (identified by `actor.agentId` and constrained by
354
+ * `actor.permissions` / `actor.scope`) may perform `permission` on
355
+ * `resource`, and throw {@link FGADeniedError} to deny.
356
+ *
357
+ * When this method is not implemented, Mastra preserves the legacy
358
+ * trusted-actor bypass (allow after the tenant-scope check). Adding it is
359
+ * therefore fully backward compatible.
360
+ *
361
+ * @param actor - The system actor signal (`true` shorthand, or an object with
362
+ * `agentId`, `permissions`, `scope`).
363
+ * @param params - The resource and permission being attempted.
364
+ * @throws FGADeniedError if the actor may not perform the action.
365
+ */
366
+ requireActor?(actor: ActorSignal, params: FGACheckParams): Promise<void>;
367
+ }
368
+ /**
369
+ * Extended FGA interface with write operations for managing resources and role assignments.
370
+ *
371
+ * Implement this interface when the FGA provider also manages the authorization
372
+ * model (creating resources, assigning roles, etc.).
373
+ */
374
+ export interface IFGAManager<TUser = unknown> extends IFGAProvider<TUser> {
375
+ /**
376
+ * Create an authorization resource.
377
+ */
378
+ createResource(params: FGACreateResourceParams): Promise<FGAResource>;
379
+ /**
380
+ * Get an authorization resource by ID.
381
+ */
382
+ getResource(resourceId: string): Promise<FGAResource>;
383
+ /**
384
+ * List authorization resources.
385
+ */
386
+ listResources(options?: FGAListResourcesOptions): Promise<FGAResource[]>;
387
+ /**
388
+ * Update an authorization resource.
389
+ */
390
+ updateResource(params: FGAUpdateResourceParams): Promise<FGAResource>;
391
+ /**
392
+ * Delete an authorization resource.
393
+ */
394
+ deleteResource(params: FGADeleteResourceParams): Promise<void>;
395
+ /**
396
+ * Assign a role to an organization membership on a specific resource.
397
+ */
398
+ assignRole(params: FGARoleParams): Promise<FGARoleAssignment>;
399
+ /**
400
+ * Remove a role assignment.
401
+ */
402
+ removeRole(params: FGARoleParams): Promise<void>;
403
+ /**
404
+ * List role assignments for an organization membership.
405
+ */
406
+ listRoleAssignments(options: FGAListRoleAssignmentsOptions): Promise<FGARoleAssignment[]>;
407
+ }
408
+ //# sourceMappingURL=fga.d.ts.map
@@ -0,0 +1,15 @@
1
+ /**
2
+ * EE Authentication Interfaces
3
+ *
4
+ * Enterprise interfaces for RBAC, ACL, and advanced authorization.
5
+ *
6
+ * @license Mastra Enterprise License - see ee/LICENSE
7
+ * @packageDocumentation
8
+ */
9
+ export type { EEUser } from './user.js';
10
+ export type { RoleDefinition, RoleMapping, IRBACProvider, IRBACManager } from './rbac.js';
11
+ export type { Resource, Action, Permission, PermissionPattern, MastraFGAPermission, MastraFGAPermissionInput, TypedRoleMapping, } from './permissions.generated.js';
12
+ export { RESOURCES, ACTIONS, PERMISSIONS, PERMISSION_PATTERNS, MastraFGAPermissions, isValidPermissionPattern, validatePermissions, } from './permissions.generated.js';
13
+ export type { ResourceIdentifier, ACLGrant, IACLProvider, IACLManager } from './acl.js';
14
+ export type { FGACheckContext, FGACheckParams, FGARouteConfig, FGARouteInfo, FGARouteResolver, FGARouteResolverContext, FGAResource, FGACreateResourceParams, FGAUpdateResourceParams, FGADeleteResourceParams, FGARoleAssignment, FGARoleParams, FGAListRoleAssignmentsOptions, FGAListResourcesOptions, IFGAProvider, IFGAManager, } from './fga.js';
15
+ //# sourceMappingURL=index.d.ts.map