@mastra/auth-cloud 1.2.3 → 1.2.4-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/CHANGELOG.md +8 -0
- package/dist/_types/@internal_auth/dist/ee/interfaces/permissions.generated.d.ts +12 -2
- package/dist/_types/@internal_auth/dist/types/index.d.ts +6 -2
- package/dist/auth-provider.d.ts +1 -8
- package/dist/auth-provider.d.ts.map +1 -1
- package/dist/index.cjs +130 -113
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +130 -113
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -671,6 +671,27 @@ var MastraCloudAuth = class {
|
|
|
671
671
|
}
|
|
672
672
|
};
|
|
673
673
|
//#endregion
|
|
674
|
+
//#region ../../packages/_internals/auth/dist/types/index.js
|
|
675
|
+
function headerFromPlainObject(headers, name) {
|
|
676
|
+
const normalizedName = name.toLowerCase();
|
|
677
|
+
const matchingKey = Object.keys(headers).find((key) => key.toLowerCase() === normalizedName);
|
|
678
|
+
const value = matchingKey === void 0 ? void 0 : headers[matchingKey];
|
|
679
|
+
return Array.isArray(value) ? value[0] ?? null : value ?? null;
|
|
680
|
+
}
|
|
681
|
+
/**
|
|
682
|
+
* Read a request header across fetch, Hono, and Express-style request shapes.
|
|
683
|
+
* Must not throw when `headers` is a plain object (Express `IncomingHttpHeaders`).
|
|
684
|
+
*/
|
|
685
|
+
function getRequestHeader(request, name) {
|
|
686
|
+
if (request instanceof Request) return request.headers.get(name);
|
|
687
|
+
if (request.raw instanceof Request) return request.raw.headers.get(name);
|
|
688
|
+
const headers = request.headers;
|
|
689
|
+
if (headers instanceof Headers) return headers.get(name);
|
|
690
|
+
if (typeof request.header === "function") return request.header(name) ?? null;
|
|
691
|
+
if (headers && typeof headers === "object") return headerFromPlainObject(headers, name);
|
|
692
|
+
return null;
|
|
693
|
+
}
|
|
694
|
+
//#endregion
|
|
674
695
|
//#region ../../packages/_internal-core/dist/logger/index.js
|
|
675
696
|
const RegisteredLogger = {
|
|
676
697
|
AGENT: "AGENT",
|
|
@@ -878,12 +899,117 @@ var MastraAuthProvider = class extends MastraBase {
|
|
|
878
899
|
}
|
|
879
900
|
};
|
|
880
901
|
//#endregion
|
|
881
|
-
//#region
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
902
|
+
//#region ../../packages/_internals/auth/dist/ee-DXvSoTl7.js
|
|
903
|
+
/**
|
|
904
|
+
* FGA enforcement utility for checking fine-grained authorization.
|
|
905
|
+
*
|
|
906
|
+
* @license Mastra Enterprise License - see ee/LICENSE
|
|
907
|
+
*/
|
|
908
|
+
/**
|
|
909
|
+
* Compound resource keys that expand to a set of per-family resources.
|
|
910
|
+
* A granted `stored:<action>` is treated as matching any `stored-<family>:<action>`
|
|
911
|
+
* (and `stored:*` matches any `stored-<family>:*`).
|
|
912
|
+
*/
|
|
913
|
+
const RESOURCE_EXPANSIONS = { stored: [
|
|
914
|
+
"stored-agents",
|
|
915
|
+
"stored-mcp-clients",
|
|
916
|
+
"stored-prompt-blocks",
|
|
917
|
+
"stored-scorers",
|
|
918
|
+
"stored-skills",
|
|
919
|
+
"stored-workspaces"
|
|
920
|
+
] };
|
|
921
|
+
/**
|
|
922
|
+
* Check if a permission matches (including wildcard support).
|
|
923
|
+
*
|
|
924
|
+
* Permission format: `{resource}:{action}[:{resource-id}]`
|
|
925
|
+
*
|
|
926
|
+
* Examples:
|
|
927
|
+
* - `*` matches everything
|
|
928
|
+
* - `agents:*` matches `agents:read`, `agents:read:my-agent`
|
|
929
|
+
* - `*:read` matches `agents:read`, `workflows:read` (action across all resources)
|
|
930
|
+
* - `agents:read` matches `agents:read`, `agents:read:my-agent`
|
|
931
|
+
* - `agents:read:my-agent` matches only `agents:read:my-agent`
|
|
932
|
+
* - `agents:*:my-agent` matches `agents:read:my-agent`, `agents:write:my-agent`
|
|
933
|
+
*
|
|
934
|
+
* @param userPermission - Permission the user has
|
|
935
|
+
* @param requiredPermission - Permission being checked
|
|
936
|
+
* @returns True if permission matches
|
|
937
|
+
*/
|
|
938
|
+
function matchesPermission(userPermission, requiredPermission) {
|
|
939
|
+
if (userPermission === "*") return true;
|
|
940
|
+
const grantedParts = userPermission.split(":");
|
|
941
|
+
const requiredParts = requiredPermission.split(":");
|
|
942
|
+
const expandedFamilies = RESOURCE_EXPANSIONS[grantedParts[0] ?? ""];
|
|
943
|
+
if (expandedFamilies && expandedFamilies.includes(requiredParts[0] ?? "")) return matchesPermission([requiredParts[0], ...grantedParts.slice(1)].join(":"), requiredPermission);
|
|
944
|
+
if (grantedParts.length < 2 || requiredParts.length < 2) return userPermission === requiredPermission;
|
|
945
|
+
const [grantedResource, grantedAction, grantedId] = grantedParts;
|
|
946
|
+
const [requiredResource, requiredAction, requiredId] = requiredParts;
|
|
947
|
+
if (grantedResource === "*") {
|
|
948
|
+
if (grantedAction === "*") {
|
|
949
|
+
if (grantedId === void 0) return true;
|
|
950
|
+
return grantedId === requiredId;
|
|
951
|
+
}
|
|
952
|
+
if (grantedAction !== requiredAction) return false;
|
|
953
|
+
if (grantedId === void 0) return true;
|
|
954
|
+
return grantedId === requiredId;
|
|
955
|
+
}
|
|
956
|
+
if (grantedResource !== requiredResource) return false;
|
|
957
|
+
if (grantedAction === "*") {
|
|
958
|
+
if (grantedId === void 0) return true;
|
|
959
|
+
return grantedId === requiredId;
|
|
960
|
+
}
|
|
961
|
+
if (grantedAction !== requiredAction) return false;
|
|
962
|
+
if (grantedId === void 0) return true;
|
|
963
|
+
return grantedId === requiredId;
|
|
964
|
+
}
|
|
965
|
+
/**
|
|
966
|
+
* Resolve permissions from user roles using a role mapping.
|
|
967
|
+
*
|
|
968
|
+
* This function translates provider-defined roles (from WorkOS, Okta, etc.)
|
|
969
|
+
* to Mastra permissions using a configurable mapping.
|
|
970
|
+
*
|
|
971
|
+
* @example
|
|
972
|
+
* ```typescript
|
|
973
|
+
* const roleMapping = {
|
|
974
|
+
* "Engineering": ["agents:*", "workflows:*"],
|
|
975
|
+
* "Product": ["agents:read"],
|
|
976
|
+
* "_default": [],
|
|
977
|
+
* };
|
|
978
|
+
*
|
|
979
|
+
* // User has "Engineering" and "QA" roles
|
|
980
|
+
* const permissions = resolvePermissionsFromMapping(
|
|
981
|
+
* ["Engineering", "QA"],
|
|
982
|
+
* roleMapping
|
|
983
|
+
* );
|
|
984
|
+
* // Result: ["agents:*", "workflows:*"] (QA is unmapped, gets _default)
|
|
985
|
+
* ```
|
|
986
|
+
*
|
|
987
|
+
* @param roles - User's roles from the identity provider
|
|
988
|
+
* @param mapping - Role to permission mapping
|
|
989
|
+
* @returns Array of resolved permissions
|
|
990
|
+
*/
|
|
991
|
+
function resolvePermissionsFromMapping(roles, mapping) {
|
|
992
|
+
const permissions = /* @__PURE__ */ new Set();
|
|
993
|
+
const defaultPerms = mapping["_default"] ?? [];
|
|
994
|
+
for (const role of roles) {
|
|
995
|
+
const rolePerms = mapping[role];
|
|
996
|
+
if (rolePerms) for (const perm of rolePerms) permissions.add(perm);
|
|
997
|
+
else for (const perm of defaultPerms) permissions.add(perm);
|
|
998
|
+
}
|
|
999
|
+
return Array.from(permissions);
|
|
885
1000
|
}
|
|
886
1001
|
/**
|
|
1002
|
+
* @mastra/core/auth/ee
|
|
1003
|
+
*
|
|
1004
|
+
* Enterprise authentication capabilities for Mastra.
|
|
1005
|
+
* This code is licensed under the Mastra Enterprise License - see ee/LICENSE.
|
|
1006
|
+
*
|
|
1007
|
+
* @license Mastra Enterprise License - see ee/LICENSE
|
|
1008
|
+
* @packageDocumentation
|
|
1009
|
+
*/
|
|
1010
|
+
//#endregion
|
|
1011
|
+
//#region src/auth-provider.ts
|
|
1012
|
+
/**
|
|
887
1013
|
* Mastra Cloud authentication provider for server integration.
|
|
888
1014
|
*
|
|
889
1015
|
* Wraps the MastraCloudAuth client and implements the required interfaces
|
|
@@ -1184,115 +1310,6 @@ var MastraCloudAuthProvider = class extends MastraAuthProvider {
|
|
|
1184
1310
|
}
|
|
1185
1311
|
};
|
|
1186
1312
|
//#endregion
|
|
1187
|
-
//#region ../../packages/_internals/auth/dist/ee-C8o0LZ3r.js
|
|
1188
|
-
/**
|
|
1189
|
-
* FGA enforcement utility for checking fine-grained authorization.
|
|
1190
|
-
*
|
|
1191
|
-
* @license Mastra Enterprise License - see ee/LICENSE
|
|
1192
|
-
*/
|
|
1193
|
-
/**
|
|
1194
|
-
* Compound resource keys that expand to a set of per-family resources.
|
|
1195
|
-
* A granted `stored:<action>` is treated as matching any `stored-<family>:<action>`
|
|
1196
|
-
* (and `stored:*` matches any `stored-<family>:*`).
|
|
1197
|
-
*/
|
|
1198
|
-
const RESOURCE_EXPANSIONS = { stored: [
|
|
1199
|
-
"stored-agents",
|
|
1200
|
-
"stored-mcp-clients",
|
|
1201
|
-
"stored-prompt-blocks",
|
|
1202
|
-
"stored-scorers",
|
|
1203
|
-
"stored-skills",
|
|
1204
|
-
"stored-workspaces"
|
|
1205
|
-
] };
|
|
1206
|
-
/**
|
|
1207
|
-
* Check if a permission matches (including wildcard support).
|
|
1208
|
-
*
|
|
1209
|
-
* Permission format: `{resource}:{action}[:{resource-id}]`
|
|
1210
|
-
*
|
|
1211
|
-
* Examples:
|
|
1212
|
-
* - `*` matches everything
|
|
1213
|
-
* - `agents:*` matches `agents:read`, `agents:read:my-agent`
|
|
1214
|
-
* - `*:read` matches `agents:read`, `workflows:read` (action across all resources)
|
|
1215
|
-
* - `agents:read` matches `agents:read`, `agents:read:my-agent`
|
|
1216
|
-
* - `agents:read:my-agent` matches only `agents:read:my-agent`
|
|
1217
|
-
* - `agents:*:my-agent` matches `agents:read:my-agent`, `agents:write:my-agent`
|
|
1218
|
-
*
|
|
1219
|
-
* @param userPermission - Permission the user has
|
|
1220
|
-
* @param requiredPermission - Permission being checked
|
|
1221
|
-
* @returns True if permission matches
|
|
1222
|
-
*/
|
|
1223
|
-
function matchesPermission(userPermission, requiredPermission) {
|
|
1224
|
-
if (userPermission === "*") return true;
|
|
1225
|
-
const grantedParts = userPermission.split(":");
|
|
1226
|
-
const requiredParts = requiredPermission.split(":");
|
|
1227
|
-
const expandedFamilies = RESOURCE_EXPANSIONS[grantedParts[0] ?? ""];
|
|
1228
|
-
if (expandedFamilies && expandedFamilies.includes(requiredParts[0] ?? "")) return matchesPermission([requiredParts[0], ...grantedParts.slice(1)].join(":"), requiredPermission);
|
|
1229
|
-
if (grantedParts.length < 2 || requiredParts.length < 2) return userPermission === requiredPermission;
|
|
1230
|
-
const [grantedResource, grantedAction, grantedId] = grantedParts;
|
|
1231
|
-
const [requiredResource, requiredAction, requiredId] = requiredParts;
|
|
1232
|
-
if (grantedResource === "*") {
|
|
1233
|
-
if (grantedAction === "*") {
|
|
1234
|
-
if (grantedId === void 0) return true;
|
|
1235
|
-
return grantedId === requiredId;
|
|
1236
|
-
}
|
|
1237
|
-
if (grantedAction !== requiredAction) return false;
|
|
1238
|
-
if (grantedId === void 0) return true;
|
|
1239
|
-
return grantedId === requiredId;
|
|
1240
|
-
}
|
|
1241
|
-
if (grantedResource !== requiredResource) return false;
|
|
1242
|
-
if (grantedAction === "*") {
|
|
1243
|
-
if (grantedId === void 0) return true;
|
|
1244
|
-
return grantedId === requiredId;
|
|
1245
|
-
}
|
|
1246
|
-
if (grantedAction !== requiredAction) return false;
|
|
1247
|
-
if (grantedId === void 0) return true;
|
|
1248
|
-
return grantedId === requiredId;
|
|
1249
|
-
}
|
|
1250
|
-
/**
|
|
1251
|
-
* Resolve permissions from user roles using a role mapping.
|
|
1252
|
-
*
|
|
1253
|
-
* This function translates provider-defined roles (from WorkOS, Okta, etc.)
|
|
1254
|
-
* to Mastra permissions using a configurable mapping.
|
|
1255
|
-
*
|
|
1256
|
-
* @example
|
|
1257
|
-
* ```typescript
|
|
1258
|
-
* const roleMapping = {
|
|
1259
|
-
* "Engineering": ["agents:*", "workflows:*"],
|
|
1260
|
-
* "Product": ["agents:read"],
|
|
1261
|
-
* "_default": [],
|
|
1262
|
-
* };
|
|
1263
|
-
*
|
|
1264
|
-
* // User has "Engineering" and "QA" roles
|
|
1265
|
-
* const permissions = resolvePermissionsFromMapping(
|
|
1266
|
-
* ["Engineering", "QA"],
|
|
1267
|
-
* roleMapping
|
|
1268
|
-
* );
|
|
1269
|
-
* // Result: ["agents:*", "workflows:*"] (QA is unmapped, gets _default)
|
|
1270
|
-
* ```
|
|
1271
|
-
*
|
|
1272
|
-
* @param roles - User's roles from the identity provider
|
|
1273
|
-
* @param mapping - Role to permission mapping
|
|
1274
|
-
* @returns Array of resolved permissions
|
|
1275
|
-
*/
|
|
1276
|
-
function resolvePermissionsFromMapping(roles, mapping) {
|
|
1277
|
-
const permissions = /* @__PURE__ */ new Set();
|
|
1278
|
-
const defaultPerms = mapping["_default"] ?? [];
|
|
1279
|
-
for (const role of roles) {
|
|
1280
|
-
const rolePerms = mapping[role];
|
|
1281
|
-
if (rolePerms) for (const perm of rolePerms) permissions.add(perm);
|
|
1282
|
-
else for (const perm of defaultPerms) permissions.add(perm);
|
|
1283
|
-
}
|
|
1284
|
-
return Array.from(permissions);
|
|
1285
|
-
}
|
|
1286
|
-
/**
|
|
1287
|
-
* @mastra/core/auth/ee
|
|
1288
|
-
*
|
|
1289
|
-
* Enterprise authentication capabilities for Mastra.
|
|
1290
|
-
* This code is licensed under the Mastra Enterprise License - see ee/LICENSE.
|
|
1291
|
-
*
|
|
1292
|
-
* @license Mastra Enterprise License - see ee/LICENSE
|
|
1293
|
-
* @packageDocumentation
|
|
1294
|
-
*/
|
|
1295
|
-
//#endregion
|
|
1296
1313
|
//#region src/rbac/rbac-provider.ts
|
|
1297
1314
|
/**
|
|
1298
1315
|
* RBAC provider for Mastra Cloud authentication.
|