@mastra/auth-cloud 1.2.8-alpha.0 → 1.2.9-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.
- 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
- 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
- package/dist/_types/{@internal_auth → @internal_auth@0.0.36}/dist/ee/interfaces/permissions.generated.d.ts +12 -2
- package/dist/_types/{@internal_auth → @internal_auth@0.0.36}/dist/index.d.ts +15 -0
- package/dist/_types/{@internal_auth → @internal_auth@0.0.36}/dist/provider/index.d.ts +74 -2
- package/dist/_types/{@internal_auth → @internal_auth@0.0.36}/dist/types/index.d.ts +7 -0
- package/dist/auth-provider.d.ts +9 -4
- package/dist/auth-provider.d.ts.map +1 -1
- package/dist/index.cjs +57 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +57 -1
- package/dist/index.js.map +1 -1
- package/dist/rbac/rbac-provider.d.ts +1 -1
- package/package.json +8 -8
- /package/dist/_types/{@internal_auth → @internal_auth@0.0.36}/dist/ee/capabilities.d.ts +0 -0
- /package/dist/_types/{@internal_auth → @internal_auth@0.0.36}/dist/ee/defaults/index.d.ts +0 -0
- /package/dist/_types/{@internal_auth → @internal_auth@0.0.36}/dist/ee/defaults/rbac/index.d.ts +0 -0
- /package/dist/_types/{@internal_auth → @internal_auth@0.0.36}/dist/ee/defaults/rbac/static.d.ts +0 -0
- /package/dist/_types/{@internal_auth → @internal_auth@0.0.36}/dist/ee/defaults/roles.d.ts +0 -0
- /package/dist/_types/{@internal_auth → @internal_auth@0.0.36}/dist/ee/fga-check.d.ts +0 -0
- /package/dist/_types/{@internal_auth → @internal_auth@0.0.36}/dist/ee/index.d.ts +0 -0
- /package/dist/_types/{@internal_auth → @internal_auth@0.0.36}/dist/ee/interfaces/acl.d.ts +0 -0
- /package/dist/_types/{@internal_auth → @internal_auth@0.0.36}/dist/ee/interfaces/fga.d.ts +0 -0
- /package/dist/_types/{@internal_auth → @internal_auth@0.0.36}/dist/ee/interfaces/index.d.ts +0 -0
- /package/dist/_types/{@internal_auth → @internal_auth@0.0.36}/dist/ee/interfaces/rbac.d.ts +0 -0
- /package/dist/_types/{@internal_auth → @internal_auth@0.0.36}/dist/ee/interfaces/user.d.ts +0 -0
- /package/dist/_types/{@internal_auth → @internal_auth@0.0.36}/dist/ee/license.d.ts +0 -0
- /package/dist/_types/{@internal_auth → @internal_auth@0.0.36}/dist/session/cookie.d.ts +0 -0
- /package/dist/_types/{@internal_auth → @internal_auth@0.0.36}/dist/session/index.d.ts +0 -0
- /package/dist/_types/{@internal_auth → @internal_auth@0.0.36}/dist/session/memory.d.ts +0 -0
- /package/dist/_types/{@internal_auth → @internal_auth@0.0.36}/package.json +0 -0
package/dist/index.js
CHANGED
|
@@ -949,6 +949,41 @@ var MastraBase = class {
|
|
|
949
949
|
}
|
|
950
950
|
};
|
|
951
951
|
// ../../packages/_internals/auth/dist/provider/index.js
|
|
952
|
+
function pickString(...values) {
|
|
953
|
+
for (const value of values) if (typeof value === "string" && value.trim()) return value;
|
|
954
|
+
}
|
|
955
|
+
/**
|
|
956
|
+
* Normalize an arbitrary provider-specific user object to the stable
|
|
957
|
+
* {@link MastraUser} shape surfaced to `DynamicArgument` callbacks.
|
|
958
|
+
*
|
|
959
|
+
* Picks `id` from `id`/`sub`/`userId` (numeric ids are stringified),
|
|
960
|
+
* `avatarUrl` from `avatarUrl`/`picture`, and passes `name`/`email`/`role`
|
|
961
|
+
* through when they are non-empty strings.
|
|
962
|
+
*
|
|
963
|
+
* @throws when no id can be derived — override `toMastraUser()` on the auth
|
|
964
|
+
* provider for user shapes this default cannot handle.
|
|
965
|
+
*/
|
|
966
|
+
function normalizeMastraUser(user) {
|
|
967
|
+
if (typeof user === "string" && user.trim()) return { id: user };
|
|
968
|
+
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.`);
|
|
969
|
+
const record = user;
|
|
970
|
+
const rawId = [
|
|
971
|
+
record.id,
|
|
972
|
+
record.sub,
|
|
973
|
+
record.userId
|
|
974
|
+
].find((value) => typeof value === "string" && value.trim() || typeof value === "number");
|
|
975
|
+
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.");
|
|
976
|
+
const normalized = { id: typeof rawId === "number" ? String(rawId) : rawId };
|
|
977
|
+
const name = pickString(record.name);
|
|
978
|
+
const email = pickString(record.email);
|
|
979
|
+
const avatarUrl = pickString(record.avatarUrl, record.picture);
|
|
980
|
+
const role = pickString(record.role);
|
|
981
|
+
if (name) normalized.name = name;
|
|
982
|
+
if (email) normalized.email = email;
|
|
983
|
+
if (avatarUrl) normalized.avatarUrl = avatarUrl;
|
|
984
|
+
if (role) normalized.role = role;
|
|
985
|
+
return normalized;
|
|
986
|
+
}
|
|
952
987
|
var MastraAuthProvider = class extends MastraBase {
|
|
953
988
|
protected;
|
|
954
989
|
public;
|
|
@@ -962,6 +997,18 @@ var MastraAuthProvider = class extends MastraBase {
|
|
|
962
997
|
this.public = options?.public;
|
|
963
998
|
if (options?.mapUserToResourceId) this.mapUserToResourceId = options.mapUserToResourceId;
|
|
964
999
|
}
|
|
1000
|
+
/**
|
|
1001
|
+
* Normalize the authenticated provider-specific user to the stable
|
|
1002
|
+
* {@link MastraUser} shape surfaced to `DynamicArgument` callbacks as the
|
|
1003
|
+
* optional `user` argument.
|
|
1004
|
+
*
|
|
1005
|
+
* The default implementation handles common user shapes (see
|
|
1006
|
+
* {@link normalizeMastraUser}); override it when your provider's user type
|
|
1007
|
+
* needs custom mapping.
|
|
1008
|
+
*/
|
|
1009
|
+
toMastraUser(user) {
|
|
1010
|
+
return normalizeMastraUser(user);
|
|
1011
|
+
}
|
|
965
1012
|
registerOptions(opts) {
|
|
966
1013
|
if (opts?.authorizeUser) this.authorizeUser = opts.authorizeUser.bind(this);
|
|
967
1014
|
if (opts?.mapUserToResourceId) this.mapUserToResourceId = opts.mapUserToResourceId;
|
|
@@ -969,7 +1016,7 @@ var MastraAuthProvider = class extends MastraBase {
|
|
|
969
1016
|
if (opts?.public) this.public = opts.public;
|
|
970
1017
|
}
|
|
971
1018
|
};
|
|
972
|
-
// ../../packages/_internals/auth/dist/ee-
|
|
1019
|
+
// ../../packages/_internals/auth/dist/ee-iTj2bRDt.js
|
|
973
1020
|
/**
|
|
974
1021
|
* FGA enforcement utility for checking fine-grained authorization.
|
|
975
1022
|
*
|
|
@@ -1174,6 +1221,15 @@ var MastraCloudAuthProvider = class extends MastraAuthProvider {
|
|
|
1174
1221
|
return !!user?.id;
|
|
1175
1222
|
}
|
|
1176
1223
|
/**
|
|
1224
|
+
* Normalize the Cloud user; the default normalization cannot see the
|
|
1225
|
+
* `avatar` field (it expects `avatarUrl`/`picture`).
|
|
1226
|
+
*/
|
|
1227
|
+
toMastraUser(user) {
|
|
1228
|
+
const normalized = normalizeMastraUser(user);
|
|
1229
|
+
if (!normalized.avatarUrl && user.avatar) normalized.avatarUrl = user.avatar;
|
|
1230
|
+
return normalized;
|
|
1231
|
+
}
|
|
1232
|
+
/**
|
|
1177
1233
|
* Cached login results for getLoginCookies() to retrieve cookies.
|
|
1178
1234
|
* Keyed by the OAuth state parameter to prevent race conditions.
|
|
1179
1235
|
* @internal
|