@mastra/auth-cloud 1.2.2 → 1.2.3

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 CHANGED
@@ -1,5 +1,17 @@
1
1
  # @mastra/auth-cloud
2
2
 
3
+ ## 1.2.3
4
+
5
+ ### Patch Changes
6
+
7
+ - Fixed a race condition in the Mastra Cloud auth provider where two users signing in with SSO at the same time could receive each other's PKCE verifier cookies. Login state is now tracked per request, keyed by the OAuth state parameter, so concurrent logins can no longer cross-wire cookies. Fixes [#20203](https://github.com/mastra-ai/mastra/issues/20203) ([#20233](https://github.com/mastra-ai/mastra/pull/20233))
8
+
9
+ ## 1.2.3-alpha.0
10
+
11
+ ### Patch Changes
12
+
13
+ - Fixed a race condition in the Mastra Cloud auth provider where two users signing in with SSO at the same time could receive each other's PKCE verifier cookies. Login state is now tracked per request, keyed by the OAuth state parameter, so concurrent logins can no longer cross-wire cookies. Fixes [#20203](https://github.com/mastra-ai/mastra/issues/20203) ([#20233](https://github.com/mastra-ai/mastra/pull/20233))
14
+
3
15
  ## 1.2.2
4
16
 
5
17
  ### Patch Changes
@@ -1,31 +1,31 @@
1
- import { RegisteredLogger, IMastraLogger } from '../logger/index.js';
2
- import 'node:stream';
3
-
1
+ import { i as IMastraLogger, u as RegisteredLogger } from "../index-S1lgaKO7.js";
2
+ //#region src/base/MastraBase.d.ts
4
3
  declare class MastraBase {
5
- #private;
6
- component: RegisteredLogger;
7
- protected logger: IMastraLogger;
4
+ #private;
5
+ component: RegisteredLogger;
6
+ protected logger: IMastraLogger;
7
+ name?: string;
8
+ constructor({ component, name, rawConfig }: {
9
+ component?: RegisteredLogger;
8
10
  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;
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;
29
28
  }
30
-
29
+ //#endregion
31
30
  export { MastraBase };
31
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,218 @@
1
+ import { Transform } from "stream";
2
+ //#region src/logger/index.d.ts
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
+ //#endregion
217
+ export { LogFilter as a, LoggerTransport as c, createCustomTransport as d, IMastraLogger as i, MastraLogger as l, ConsoleLogger as n, LogFilterContext as o, ConsoleLoggerOptions as r, LogLevel as s, BaseLogMessage as t, RegisteredLogger as u };
218
+ //# sourceMappingURL=index-S1lgaKO7.d.ts.map
@@ -3,12 +3,9 @@
3
3
  *
4
4
  * @license Mastra Enterprise License - see ee/LICENSE
5
5
  */
6
- import type { FGACheckContext, IFGAProvider } from './interfaces/fga.js';
6
+ import type { ActorSignal, FGACheckContext, IFGAProvider } from './interfaces/fga.js';
7
7
  import type { MastraFGAPermissionInput } from './interfaces/permissions.generated.js';
8
- export type ActorSignal = true | {
9
- actorKind: 'system';
10
- sourceWorkflow?: string;
11
- };
8
+ export type { ActorSignal };
12
9
  export interface CheckFGAOptions {
13
10
  fgaProvider: IFGAProvider | undefined;
14
11
  user: any;
@@ -8,6 +8,34 @@
8
8
  * @license Mastra Enterprise License - see ee/LICENSE
9
9
  */
10
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
+ };
11
39
  /**
12
40
  * Optional context for an authorization check.
13
41
  */
@@ -306,6 +334,25 @@ export interface IFGAProvider<TUser = unknown> {
306
334
  filterAccessible<T extends {
307
335
  id: string;
308
336
  }>(user: TUser, resources: T[], resourceType: string, permission: MastraFGAPermissionInput): Promise<T[]>;
337
+ /**
338
+ * Authorize a non-user (system / autonomous agent) actor.
339
+ *
340
+ * System actors bypass the user-centric `require()` path. Implement this
341
+ * method to opt in to provider-driven least privilege for those actors:
342
+ * decide whether the actor (identified by `actor.agentId` and constrained by
343
+ * `actor.permissions` / `actor.scope`) may perform `permission` on
344
+ * `resource`, and throw {@link FGADeniedError} to deny.
345
+ *
346
+ * When this method is not implemented, Mastra preserves the legacy
347
+ * trusted-actor bypass (allow after the tenant-scope check). Adding it is
348
+ * therefore fully backward compatible.
349
+ *
350
+ * @param actor - The system actor signal (`true` shorthand, or an object with
351
+ * `agentId`, `permissions`, `scope`).
352
+ * @param params - The resource and permission being attempted.
353
+ * @throws FGADeniedError if the actor may not perform the action.
354
+ */
355
+ requireActor?(actor: ActorSignal, params: FGACheckParams): Promise<void>;
309
356
  }
310
357
  /**
311
358
  * Extended FGA interface with write operations for managing resources and role assignments.
@@ -10,7 +10,7 @@
10
10
  * All known API resources.
11
11
  * Derived from SERVER_ROUTES paths in @mastra/server.
12
12
  */
13
- export declare const RESOURCES: readonly ["a2a", "agent-builder", "agent-controller", "agents", "auth", "background-tasks", "channels", "datasets", "embedders", "experiments", "heartbeats", "infrastructure", "logs", "mcp", "memory", "observability", "processor-providers", "processors", "schedules", "scores", "stored-agents", "stored-mcp-clients", "stored-prompt-blocks", "stored-scorers", "stored-skills", "stored-workspaces", "system", "tool-providers", "tools", "vector", "vectors", "workflows", "workspaces"];
13
+ export declare const RESOURCES: readonly ["a2a", "agent-builder", "agent-controller", "agents", "auth", "background-tasks", "channels", "datasets", "embedders", "experiments", "infrastructure", "logs", "mcp", "memory", "observability", "processor-providers", "processors", "schedules", "scores", "stored-agents", "stored-mcp-clients", "stored-prompt-blocks", "stored-scorers", "stored-skills", "stored-workspaces", "system", "tool-providers", "tools", "vector", "vectors", "workflows", "workspaces"];
14
14
  /**
15
15
  * Resource type union.
16
16
  */
@@ -70,8 +70,6 @@ export declare const PERMISSION_PATTERNS: {
70
70
  readonly 'embedders:*': "embedders:*";
71
71
  /** Full access to experiments */
72
72
  readonly 'experiments:*': "experiments:*";
73
- /** Full access to heartbeats */
74
- readonly 'heartbeats:*': "heartbeats:*";
75
73
  /** Full access to infrastructure */
76
74
  readonly 'infrastructure:*': "infrastructure:*";
77
75
  /** Full access to logs */
@@ -160,14 +158,6 @@ export declare const PERMISSION_PATTERNS: {
160
158
  readonly 'embedders:read': "embedders:read";
161
159
  /** View experiments */
162
160
  readonly 'experiments:read': "experiments:read";
163
- /** Delete heartbeats */
164
- readonly 'heartbeats:delete': "heartbeats:delete";
165
- /** Execute heartbeats */
166
- readonly 'heartbeats:execute': "heartbeats:execute";
167
- /** View heartbeats */
168
- readonly 'heartbeats:read': "heartbeats:read";
169
- /** Create and modify heartbeats */
170
- readonly 'heartbeats:write': "heartbeats:write";
171
161
  /** View infrastructure */
172
162
  readonly 'infrastructure:read': "infrastructure:read";
173
163
  /** View logs */
@@ -196,6 +186,8 @@ export declare const PERMISSION_PATTERNS: {
196
186
  readonly 'processors:execute': "processors:execute";
197
187
  /** View processors */
198
188
  readonly 'processors:read': "processors:read";
189
+ /** Delete schedules */
190
+ readonly 'schedules:delete': "schedules:delete";
199
191
  /** Execute schedules */
200
192
  readonly 'schedules:execute': "schedules:execute";
201
193
  /** View schedules */
@@ -313,7 +305,7 @@ export type PermissionPattern = keyof typeof PERMISSION_PATTERNS;
313
305
  /**
314
306
  * All valid resource:action permission combinations (excludes wildcards).
315
307
  */
316
- export declare const PERMISSIONS: readonly ["a2a:read", "a2a:write", "agent-builder:execute", "agent-builder:read", "agent-builder:write", "agent-controller:execute", "agent-controller:read", "agents:create", "agents:delete", "agents:execute", "agents:read", "agents:write", "auth:read", "background-tasks:read", "channels:read", "channels:write", "datasets:delete", "datasets:execute", "datasets:read", "datasets:write", "embedders:read", "experiments:read", "heartbeats:delete", "heartbeats:execute", "heartbeats:read", "heartbeats:write", "infrastructure:read", "logs:read", "mcp:execute", "mcp:read", "mcp:write", "memory:delete", "memory:execute", "memory:read", "memory:write", "observability:read", "observability:write", "processor-providers:read", "processors:execute", "processors:read", "schedules:execute", "schedules:read", "schedules:write", "scores:read", "scores:write", "stored-agents:delete", "stored-agents:publish", "stored-agents:read", "stored-agents:write", "stored-mcp-clients:delete", "stored-mcp-clients:publish", "stored-mcp-clients:read", "stored-mcp-clients:write", "stored-prompt-blocks:delete", "stored-prompt-blocks:publish", "stored-prompt-blocks:read", "stored-prompt-blocks:write", "stored-scorers:delete", "stored-scorers:publish", "stored-scorers:read", "stored-scorers:write", "stored-skills:delete", "stored-skills:publish", "stored-skills:read", "stored-skills:write", "stored-workspaces:delete", "stored-workspaces:read", "stored-workspaces:write", "system:read", "tool-providers:delete", "tool-providers:read", "tool-providers:write", "tools:execute", "tools:read", "vector:delete", "vector:execute", "vector:read", "vector:write", "vectors:read", "workflows:delete", "workflows:execute", "workflows:read", "workflows:write", "workspaces:delete", "workspaces:read", "workspaces:write"];
308
+ export declare const PERMISSIONS: readonly ["a2a:read", "a2a:write", "agent-builder:execute", "agent-builder:read", "agent-builder:write", "agent-controller:execute", "agent-controller:read", "agents:create", "agents:delete", "agents:execute", "agents:read", "agents:write", "auth:read", "background-tasks:read", "channels:read", "channels:write", "datasets:delete", "datasets:execute", "datasets:read", "datasets:write", "embedders:read", "experiments:read", "infrastructure:read", "logs:read", "mcp:execute", "mcp:read", "mcp:write", "memory:delete", "memory:execute", "memory:read", "memory:write", "observability:read", "observability:write", "processor-providers:read", "processors:execute", "processors:read", "schedules:delete", "schedules:execute", "schedules:read", "schedules:write", "scores:read", "scores:write", "stored-agents:delete", "stored-agents:publish", "stored-agents:read", "stored-agents:write", "stored-mcp-clients:delete", "stored-mcp-clients:publish", "stored-mcp-clients:read", "stored-mcp-clients:write", "stored-prompt-blocks:delete", "stored-prompt-blocks:publish", "stored-prompt-blocks:read", "stored-prompt-blocks:write", "stored-scorers:delete", "stored-scorers:publish", "stored-scorers:read", "stored-scorers:write", "stored-skills:delete", "stored-skills:publish", "stored-skills:read", "stored-skills:write", "stored-workspaces:delete", "stored-workspaces:read", "stored-workspaces:write", "system:read", "tool-providers:delete", "tool-providers:read", "tool-providers:write", "tools:execute", "tools:read", "vector:delete", "vector:execute", "vector:read", "vector:write", "vectors:read", "workflows:delete", "workflows:execute", "workflows:read", "workflows:write", "workspaces:delete", "workspaces:read", "workspaces:write"];
317
309
  /**
318
310
  * Specific permission type (e.g., 'agents:read', 'workflows:execute').
319
311
  */
@@ -369,14 +361,6 @@ export declare const MastraFGAPermissions: {
369
361
  readonly EMBEDDERS_READ: "embedders:read";
370
362
  /** View experiments */
371
363
  readonly EXPERIMENTS_READ: "experiments:read";
372
- /** Delete heartbeats */
373
- readonly HEARTBEATS_DELETE: "heartbeats:delete";
374
- /** Execute heartbeats */
375
- readonly HEARTBEATS_EXECUTE: "heartbeats:execute";
376
- /** View heartbeats */
377
- readonly HEARTBEATS_READ: "heartbeats:read";
378
- /** Create and modify heartbeats */
379
- readonly HEARTBEATS_WRITE: "heartbeats:write";
380
364
  /** View infrastructure */
381
365
  readonly INFRASTRUCTURE_READ: "infrastructure:read";
382
366
  /** View logs */
@@ -405,6 +389,8 @@ export declare const MastraFGAPermissions: {
405
389
  readonly PROCESSORS_EXECUTE: "processors:execute";
406
390
  /** View processors */
407
391
  readonly PROCESSORS_READ: "processors:read";
392
+ /** Delete schedules */
393
+ readonly SCHEDULES_DELETE: "schedules:delete";
408
394
  /** Execute schedules */
409
395
  readonly SCHEDULES_EXECUTE: "schedules:execute";
410
396
  /** View schedules */
@@ -270,6 +270,72 @@ export interface ICredentialsProvider<TUser extends User = User> {
270
270
  */
271
271
  isSignUpEnabled?(): boolean;
272
272
  }
273
+ /**
274
+ * Provider interface for organization membership management.
275
+ *
276
+ * Implement this interface to enable multi-tenant hosts (e.g. the Mastra Code
277
+ * web factory) to bootstrap a personal organization for new users and to
278
+ * authorize organization-level administrative mutations.
279
+ */
280
+ export interface IOrganizationsProvider {
281
+ /**
282
+ * Ensure the user belongs to an organization, bootstrapping a personal org
283
+ * on first use when they have none. Must be idempotent under
284
+ * concurrent/retried first logins.
285
+ *
286
+ * @param userId - Stable provider user id
287
+ * @returns The organization id, or `undefined` when the user genuinely
288
+ * stays no-org (bootstrap is best-effort)
289
+ */
290
+ ensureOrganization(userId: string): Promise<string | undefined>;
291
+ /**
292
+ * Whether the user holds an admin-equivalent role in the organization.
293
+ * Provider errors should resolve to `false` rather than throw.
294
+ *
295
+ * @param organizationId - Organization id
296
+ * @param userId - Stable provider user id
297
+ */
298
+ isOrganizationAdmin(organizationId: string, userId: string): Promise<boolean>;
299
+ }
300
+ /**
301
+ * Host-level context handed to {@link IAuthInit.init} once during server
302
+ * preparation. Storage-agnostic: hosts pass whatever database handle their
303
+ * storage backend exposes.
304
+ */
305
+ export interface AuthInitContext {
306
+ /**
307
+ * Database handle for providers that persist their own auth tables
308
+ * (e.g. better-auth). Shape is provider-defined; hosts pass their storage
309
+ * backend's auth database as-is.
310
+ */
311
+ database?: unknown;
312
+ /** Browser-facing origin (no trailing slash), e.g. `https://factory.acme.com`. */
313
+ publicUrl?: string;
314
+ /**
315
+ * Extra browser origins allowed to talk to the API (cross-origin SPA
316
+ * deploys). Providers that enforce their own origin allow-list (e.g.
317
+ * better-auth `trustedOrigins`) must honor these.
318
+ */
319
+ allowedOrigins?: string[];
320
+ }
321
+ /**
322
+ * Optional one-time initialization hook for auth providers. Hosts call
323
+ * `init()` once during preparation with host-level context (database, public
324
+ * origin) so providers can consume it without the deploy entry passing it
325
+ * twice. Providers should fail fast here for requirements only satisfiable at
326
+ * prepare time.
327
+ */
328
+ export interface IAuthInit {
329
+ init(ctx: AuthInitContext): Promise<void>;
330
+ }
331
+ /**
332
+ * Provider interface for handling raw auth HTTP requests. Providers that ship
333
+ * their own HTTP API surface (e.g. better-auth's `/api/auth/*` handler)
334
+ * implement this so hosts can mount it (typically under `/auth/api/*`).
335
+ */
336
+ export interface IAuthHttpHandler {
337
+ handleAuthRequest(request: Request): Promise<Response>;
338
+ }
273
339
  export * from './session/index.js';
274
340
  export * from './provider/index.js';
275
341
  export * from './types/index.js';
@@ -1,5 +1,5 @@
1
1
  import { MastraBase } from '../_types/@internal_core/dist/base/index.d.ts';
2
- import type { CredentialsResult, ISSOProvider, ISessionProvider, IUserProvider, Session, SSOCallbackResult, SSOLoginConfig, User } from '..';
2
+ import type { CredentialsResult, IAuthHttpHandler, IAuthInit, ICredentialsProvider, IOrganizationsProvider, ISSOProvider, ISessionProvider, IUserProvider, Session, SSOCallbackResult, SSOLoginConfig, User } from '..';
3
3
  import type { AuthorizeUserFn, MastraAuthConfig, MastraAuthRequest } from '../types/index.js';
4
4
  export interface MastraAuthProviderOptions<TUser = unknown> {
5
5
  name?: string;
@@ -72,6 +72,13 @@ export declare abstract class MastraAuthProvider<TUser = unknown> extends Mastra
72
72
  abstract authorizeUser(user: TUser, request: MastraAuthRequest): Promise<boolean> | boolean;
73
73
  protected registerOptions(opts?: MastraAuthProviderOptions<TUser>): void;
74
74
  }
75
+ export declare function isSSOProvider(p: unknown): p is ISSOProvider;
76
+ export declare function isSessionProvider(p: unknown): p is ISessionProvider;
77
+ export declare function isUserProvider(p: unknown): p is IUserProvider;
78
+ export declare function isCredentialsProvider(p: unknown): p is ICredentialsProvider;
79
+ export declare function isOrganizationsProvider(p: unknown): p is IOrganizationsProvider;
80
+ export declare function isAuthHttpHandler(p: unknown): p is IAuthHttpHandler;
81
+ export declare function hasAuthInit(p: unknown): p is IAuthInit;
75
82
  export declare class CompositeAuth extends MastraAuthProvider implements ISSOProvider<User>, ISessionProvider<Session>, IUserProvider<User> {
76
83
  private providers;
77
84
  private authenticatedProviderByObject;
@@ -91,10 +91,11 @@ export declare class MastraCloudAuthProvider extends MastraAuthProvider<CloudUse
91
91
  */
92
92
  authorizeUser(user: CloudUser): boolean;
93
93
  /**
94
- * Cached login result for getLoginCookies() to retrieve cookies.
94
+ * Cached login results for getLoginCookies() to retrieve cookies.
95
+ * Keyed by the OAuth state parameter to prevent race conditions.
95
96
  * @internal
96
97
  */
97
- private _lastLoginResult;
98
+ private _loginResults;
98
99
  /**
99
100
  * Get URL to redirect user to for SSO login.
100
101
  *
@@ -107,9 +108,11 @@ export declare class MastraCloudAuthProvider extends MastraAuthProvider<CloudUse
107
108
  * Get cookies to set during login redirect (PKCE verifier).
108
109
  * Must be called after getLoginUrl() in same request.
109
110
  *
111
+ * @param _redirectUri - OAuth callback URL
112
+ * @param state - State parameter
110
113
  * @returns Array of Set-Cookie header values
111
114
  */
112
- getLoginCookies(): string[] | undefined;
115
+ getLoginCookies(_redirectUri: string, state: string): string[] | undefined;
113
116
  /**
114
117
  * Handle OAuth callback, exchange code for tokens and user.
115
118
  *
@@ -1 +1 @@
1
- {"version":3,"file":"auth-provider.d.ts","sourceRoot":"","sources":["../src/auth-provider.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EACV,aAAa,EACb,YAAY,EACZ,gBAAgB,EAChB,OAAO,EACP,iBAAiB,EACjB,cAAc,EACf,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,yBAAyB,CAAC;AACzE,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAI7D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEzC,KAAK,eAAe,GAAG;IACrB,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;CAC1C,CAAC;AAEF,KAAK,iBAAiB,GAAG,OAAO,GAAG,eAAe,CAAC;AAUnD;;GAEG;AACH,MAAM,WAAW,8BAA+B,SAAQ,yBAAyB,CAAC,SAAS,CAAC;IAC1F,8BAA8B;IAC9B,SAAS,EAAE,MAAM,CAAC;IAClB,mEAAmE;IACnE,YAAY,EAAE,MAAM,CAAC;IACrB,8CAA8C;IAC9C,WAAW,EAAE,MAAM,CAAC;IACpB,kEAAkE;IACl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