@mastra/auth-studio 1.4.0-alpha.1 → 1.4.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@0.0.36 → @internal_auth@0.0.37}/dist/index.d.ts +15 -0
- package/dist/_types/{@internal_auth@0.0.36 → @internal_auth@0.0.37}/dist/provider/index.d.ts +73 -1
- package/dist/_types/{@internal_auth@0.0.36 → @internal_auth@0.0.37}/dist/types/index.d.ts +7 -0
- package/dist/index.cjs +47 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.js +47 -0
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- /package/dist/_types/{@internal_auth@0.0.36 → @internal_auth@0.0.37}/dist/_types/@internal_core@0.1.4/dist/base/index.d.ts +0 -0
- /package/dist/_types/{@internal_auth@0.0.36 → @internal_auth@0.0.37}/dist/_types/@internal_core@0.1.4/dist/index-Diz1p9N7.d.ts +0 -0
- /package/dist/_types/{@internal_auth@0.0.36 → @internal_auth@0.0.37}/dist/ee/capabilities.d.ts +0 -0
- /package/dist/_types/{@internal_auth@0.0.36 → @internal_auth@0.0.37}/dist/ee/defaults/index.d.ts +0 -0
- /package/dist/_types/{@internal_auth@0.0.36 → @internal_auth@0.0.37}/dist/ee/defaults/rbac/index.d.ts +0 -0
- /package/dist/_types/{@internal_auth@0.0.36 → @internal_auth@0.0.37}/dist/ee/defaults/rbac/static.d.ts +0 -0
- /package/dist/_types/{@internal_auth@0.0.36 → @internal_auth@0.0.37}/dist/ee/defaults/roles.d.ts +0 -0
- /package/dist/_types/{@internal_auth@0.0.36 → @internal_auth@0.0.37}/dist/ee/fga-check.d.ts +0 -0
- /package/dist/_types/{@internal_auth@0.0.36 → @internal_auth@0.0.37}/dist/ee/index.d.ts +0 -0
- /package/dist/_types/{@internal_auth@0.0.36 → @internal_auth@0.0.37}/dist/ee/interfaces/acl.d.ts +0 -0
- /package/dist/_types/{@internal_auth@0.0.36 → @internal_auth@0.0.37}/dist/ee/interfaces/fga.d.ts +0 -0
- /package/dist/_types/{@internal_auth@0.0.36 → @internal_auth@0.0.37}/dist/ee/interfaces/index.d.ts +0 -0
- /package/dist/_types/{@internal_auth@0.0.36 → @internal_auth@0.0.37}/dist/ee/interfaces/permissions.generated.d.ts +0 -0
- /package/dist/_types/{@internal_auth@0.0.36 → @internal_auth@0.0.37}/dist/ee/interfaces/rbac.d.ts +0 -0
- /package/dist/_types/{@internal_auth@0.0.36 → @internal_auth@0.0.37}/dist/ee/interfaces/user.d.ts +0 -0
- /package/dist/_types/{@internal_auth@0.0.36 → @internal_auth@0.0.37}/dist/ee/license.d.ts +0 -0
- /package/dist/_types/{@internal_auth@0.0.36 → @internal_auth@0.0.37}/dist/session/cookie.d.ts +0 -0
- /package/dist/_types/{@internal_auth@0.0.36 → @internal_auth@0.0.37}/dist/session/index.d.ts +0 -0
- /package/dist/_types/{@internal_auth@0.0.36 → @internal_auth@0.0.37}/dist/session/memory.d.ts +0 -0
- /package/dist/_types/{@internal_auth@0.0.36 → @internal_auth@0.0.37}/package.json +0 -0
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { IOrganizationsProvider, ISSOProvider, ISessionProvider, IUserProvider, MastraAuthRequest, Session, SSOCallbackResult, SSOLoginConfig } from './_types/@internal_auth@0.0.
|
|
2
|
-
import type { EEUser, IRBACProvider, RoleMapping } from './_types/@internal_auth@0.0.
|
|
3
|
-
import { MastraAuthProvider } from './_types/@internal_auth@0.0.
|
|
4
|
-
import type { MastraAuthProviderOptions } from './_types/@internal_auth@0.0.
|
|
1
|
+
import type { IOrganizationsProvider, ISSOProvider, ISessionProvider, IUserProvider, MastraAuthRequest, Session, SSOCallbackResult, SSOLoginConfig } from './_types/@internal_auth@0.0.37/dist/index.js';
|
|
2
|
+
import type { EEUser, IRBACProvider, RoleMapping } from './_types/@internal_auth@0.0.37/dist/ee/index.js';
|
|
3
|
+
import { MastraAuthProvider } from './_types/@internal_auth@0.0.37/dist/provider/index.js';
|
|
4
|
+
import type { MastraAuthProviderOptions } from './_types/@internal_auth@0.0.37/dist/provider/index.js';
|
|
5
5
|
export interface StudioUser extends EEUser {
|
|
6
6
|
id: string;
|
|
7
7
|
email?: string;
|
package/dist/index.js
CHANGED
|
@@ -292,6 +292,41 @@ var MastraBase = class {
|
|
|
292
292
|
}
|
|
293
293
|
};
|
|
294
294
|
// ../../packages/_internals/auth/dist/provider/index.js
|
|
295
|
+
function pickString(...values) {
|
|
296
|
+
for (const value of values) if (typeof value === "string" && value.trim()) return value;
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Normalize an arbitrary provider-specific user object to the stable
|
|
300
|
+
* {@link MastraUser} shape surfaced to `DynamicArgument` callbacks.
|
|
301
|
+
*
|
|
302
|
+
* Picks `id` from `id`/`sub`/`userId` (numeric ids are stringified),
|
|
303
|
+
* `avatarUrl` from `avatarUrl`/`picture`, and passes `name`/`email`/`role`
|
|
304
|
+
* through when they are non-empty strings.
|
|
305
|
+
*
|
|
306
|
+
* @throws when no id can be derived — override `toMastraUser()` on the auth
|
|
307
|
+
* provider for user shapes this default cannot handle.
|
|
308
|
+
*/
|
|
309
|
+
function normalizeMastraUser(user) {
|
|
310
|
+
if (typeof user === "string" && user.trim()) return { id: user };
|
|
311
|
+
if (user === null || typeof user !== "object") throw new Error(`Unable to normalize authenticated user of type "${typeof user}" to a MastraUser. Override toMastraUser() on your auth provider to supply a normalized user.`);
|
|
312
|
+
const record = user;
|
|
313
|
+
const rawId = [
|
|
314
|
+
record.id,
|
|
315
|
+
record.sub,
|
|
316
|
+
record.userId
|
|
317
|
+
].find((value) => typeof value === "string" && value.trim() || typeof value === "number");
|
|
318
|
+
if (rawId === void 0) throw new Error("Unable to derive a user id (looked at `id`, `sub`, and `userId`) while normalizing the authenticated user. Override toMastraUser() on your auth provider to supply a normalized user.");
|
|
319
|
+
const normalized = { id: typeof rawId === "number" ? String(rawId) : rawId };
|
|
320
|
+
const name = pickString(record.name);
|
|
321
|
+
const email = pickString(record.email);
|
|
322
|
+
const avatarUrl = pickString(record.avatarUrl, record.picture);
|
|
323
|
+
const role = pickString(record.role);
|
|
324
|
+
if (name) normalized.name = name;
|
|
325
|
+
if (email) normalized.email = email;
|
|
326
|
+
if (avatarUrl) normalized.avatarUrl = avatarUrl;
|
|
327
|
+
if (role) normalized.role = role;
|
|
328
|
+
return normalized;
|
|
329
|
+
}
|
|
295
330
|
var MastraAuthProvider = class extends MastraBase {
|
|
296
331
|
protected;
|
|
297
332
|
public;
|
|
@@ -305,6 +340,18 @@ var MastraAuthProvider = class extends MastraBase {
|
|
|
305
340
|
this.public = options?.public;
|
|
306
341
|
if (options?.mapUserToResourceId) this.mapUserToResourceId = options.mapUserToResourceId;
|
|
307
342
|
}
|
|
343
|
+
/**
|
|
344
|
+
* Normalize the authenticated provider-specific user to the stable
|
|
345
|
+
* {@link MastraUser} shape surfaced to `DynamicArgument` callbacks as the
|
|
346
|
+
* optional `user` argument.
|
|
347
|
+
*
|
|
348
|
+
* The default implementation handles common user shapes (see
|
|
349
|
+
* {@link normalizeMastraUser}); override it when your provider's user type
|
|
350
|
+
* needs custom mapping.
|
|
351
|
+
*/
|
|
352
|
+
toMastraUser(user) {
|
|
353
|
+
return normalizeMastraUser(user);
|
|
354
|
+
}
|
|
308
355
|
registerOptions(opts) {
|
|
309
356
|
if (opts?.authorizeUser) this.authorizeUser = opts.authorizeUser.bind(this);
|
|
310
357
|
if (opts?.mapUserToResourceId) this.mapUserToResourceId = opts.mapUserToResourceId;
|