@mastra/auth-cloud 1.2.0 → 1.2.1
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 +18 -0
- package/dist/_types/@internal_auth/dist/_types/@internal_core/dist/base/index.d.ts +31 -0
- package/dist/_types/@internal_auth/dist/_types/@internal_core/dist/logger/index.d.ts +217 -0
- package/dist/_types/@internal_auth/dist/ee/capabilities.d.ts +142 -0
- package/dist/_types/@internal_auth/dist/ee/defaults/index.d.ts +8 -0
- package/dist/_types/@internal_auth/dist/ee/defaults/rbac/index.d.ts +7 -0
- package/dist/_types/@internal_auth/dist/ee/defaults/rbac/static.d.ts +106 -0
- package/dist/_types/@internal_auth/dist/ee/defaults/roles.d.ts +92 -0
- package/dist/_types/@internal_auth/dist/ee/fga-check.d.ts +62 -0
- package/dist/_types/@internal_auth/dist/ee/index.d.ts +15 -0
- package/dist/_types/@internal_auth/dist/ee/interfaces/acl.d.ts +140 -0
- package/dist/_types/@internal_auth/dist/ee/interfaces/fga.d.ts +350 -0
- package/dist/_types/@internal_auth/dist/ee/interfaces/index.d.ts +15 -0
- package/dist/_types/@internal_auth/dist/ee/interfaces/permissions.generated.d.ts +519 -0
- package/dist/_types/@internal_auth/dist/ee/interfaces/rbac.d.ts +207 -0
- package/dist/_types/@internal_auth/dist/ee/interfaces/user.d.ts +18 -0
- package/dist/_types/@internal_auth/dist/ee/license.d.ts +171 -0
- package/dist/_types/@internal_auth/dist/index.d.ts +277 -0
- package/dist/_types/@internal_auth/dist/provider/index.d.ts +125 -0
- package/dist/_types/@internal_auth/dist/session/cookie.d.ts +82 -0
- package/dist/_types/@internal_auth/dist/session/index.d.ts +30 -0
- package/dist/_types/@internal_auth/dist/session/memory.d.ts +60 -0
- package/dist/_types/@internal_auth/dist/types/index.d.ts +52 -0
- package/dist/auth-provider.d.ts +4 -4
- package/dist/auth-provider.d.ts.map +1 -1
- package/dist/index.cjs +301 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +296 -4
- package/dist/index.js.map +1 -1
- package/dist/rbac/rbac-provider.d.ts +1 -1
- package/dist/rbac/rbac-provider.d.ts.map +1 -1
- package/package.json +6 -6
- package/LICENSE.md +0 -30
package/dist/index.cjs
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var crypto$1 = require('crypto');
|
|
4
|
-
var server = require('@mastra/core/server');
|
|
5
|
-
var ee = require('@mastra/core/auth/ee');
|
|
6
4
|
|
|
7
5
|
// src/error.ts
|
|
8
6
|
var AuthError = class _AuthError extends Error {
|
|
@@ -466,13 +464,196 @@ var MastraCloudAuth = class {
|
|
|
466
464
|
return clearSessionCookie();
|
|
467
465
|
}
|
|
468
466
|
};
|
|
469
|
-
|
|
467
|
+
|
|
468
|
+
// ../../packages/_internal-core/dist/chunk-3M4SEWMI.js
|
|
469
|
+
var RegisteredLogger = {
|
|
470
|
+
LLM: "LLM"};
|
|
471
|
+
var LogLevel = {
|
|
472
|
+
DEBUG: "debug",
|
|
473
|
+
INFO: "info",
|
|
474
|
+
WARN: "warn",
|
|
475
|
+
ERROR: "error"};
|
|
476
|
+
var MastraLogger = class {
|
|
477
|
+
name;
|
|
478
|
+
level;
|
|
479
|
+
transports;
|
|
480
|
+
constructor(options = {}) {
|
|
481
|
+
this.name = options.name || "Mastra";
|
|
482
|
+
this.level = options.level || LogLevel.ERROR;
|
|
483
|
+
this.transports = new Map(Object.entries(options.transports || {}));
|
|
484
|
+
}
|
|
485
|
+
getTransports() {
|
|
486
|
+
return this.transports;
|
|
487
|
+
}
|
|
488
|
+
trackException(_error, _metadata) {
|
|
489
|
+
}
|
|
490
|
+
async listLogs(transportId, params) {
|
|
491
|
+
if (!transportId || !this.transports.has(transportId)) {
|
|
492
|
+
return { logs: [], total: 0, page: params?.page ?? 1, perPage: params?.perPage ?? 100, hasMore: false };
|
|
493
|
+
}
|
|
494
|
+
return this.transports.get(transportId).listLogs?.(params) ?? {
|
|
495
|
+
logs: [],
|
|
496
|
+
total: 0,
|
|
497
|
+
page: params?.page ?? 1,
|
|
498
|
+
perPage: params?.perPage ?? 100,
|
|
499
|
+
hasMore: false
|
|
500
|
+
};
|
|
501
|
+
}
|
|
502
|
+
async listLogsByRunId({
|
|
503
|
+
transportId,
|
|
504
|
+
runId,
|
|
505
|
+
fromDate,
|
|
506
|
+
toDate,
|
|
507
|
+
logLevel,
|
|
508
|
+
filters,
|
|
509
|
+
page,
|
|
510
|
+
perPage
|
|
511
|
+
}) {
|
|
512
|
+
if (!transportId || !this.transports.has(transportId) || !runId) {
|
|
513
|
+
return { logs: [], total: 0, page: page ?? 1, perPage: perPage ?? 100, hasMore: false };
|
|
514
|
+
}
|
|
515
|
+
return this.transports.get(transportId).listLogsByRunId?.({ runId, fromDate, toDate, logLevel, filters, page, perPage }) ?? {
|
|
516
|
+
logs: [],
|
|
517
|
+
total: 0,
|
|
518
|
+
page: page ?? 1,
|
|
519
|
+
perPage: perPage ?? 100,
|
|
520
|
+
hasMore: false
|
|
521
|
+
};
|
|
522
|
+
}
|
|
523
|
+
};
|
|
524
|
+
var ConsoleLogger = class _ConsoleLogger extends MastraLogger {
|
|
525
|
+
component;
|
|
526
|
+
filter;
|
|
527
|
+
constructor(options = {}) {
|
|
528
|
+
super(options);
|
|
529
|
+
this.component = options.component;
|
|
530
|
+
this.filter = options.filter;
|
|
531
|
+
}
|
|
532
|
+
child(componentOrBindings) {
|
|
533
|
+
const component = typeof componentOrBindings === "string" ? componentOrBindings : componentOrBindings?.component ?? this.component;
|
|
534
|
+
return new _ConsoleLogger({
|
|
535
|
+
name: this.name,
|
|
536
|
+
level: this.level,
|
|
537
|
+
component,
|
|
538
|
+
filter: this.filter
|
|
539
|
+
});
|
|
540
|
+
}
|
|
541
|
+
shouldLog(level, message, args) {
|
|
542
|
+
if (!this.filter) return true;
|
|
543
|
+
try {
|
|
544
|
+
return this.filter({ component: this.component, level, message, args });
|
|
545
|
+
} catch (e) {
|
|
546
|
+
console.error(`[Logger] Filter error for component=${this.component} level=${level}:`, e);
|
|
547
|
+
return true;
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
prefix() {
|
|
551
|
+
return this.component ? `[${this.component}] ` : "";
|
|
552
|
+
}
|
|
553
|
+
debug(message, ...args) {
|
|
554
|
+
if (this.level === LogLevel.DEBUG && this.shouldLog(LogLevel.DEBUG, message, args)) {
|
|
555
|
+
console.info(`${this.prefix()}${message}`, ...args);
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
info(message, ...args) {
|
|
559
|
+
if ((this.level === LogLevel.INFO || this.level === LogLevel.DEBUG) && this.shouldLog(LogLevel.INFO, message, args)) {
|
|
560
|
+
console.info(`${this.prefix()}${message}`, ...args);
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
warn(message, ...args) {
|
|
564
|
+
if ((this.level === LogLevel.WARN || this.level === LogLevel.INFO || this.level === LogLevel.DEBUG) && this.shouldLog(LogLevel.WARN, message, args)) {
|
|
565
|
+
console.warn(`${this.prefix()}${message}`, ...args);
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
error(message, ...args) {
|
|
569
|
+
if ((this.level === LogLevel.ERROR || this.level === LogLevel.WARN || this.level === LogLevel.INFO || this.level === LogLevel.DEBUG) && this.shouldLog(LogLevel.ERROR, message, args)) {
|
|
570
|
+
console.error(`${this.prefix()}${message}`, ...args);
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
async listLogs(_transportId, _params) {
|
|
574
|
+
return { logs: [], total: 0, page: _params?.page ?? 1, perPage: _params?.perPage ?? 100, hasMore: false };
|
|
575
|
+
}
|
|
576
|
+
async listLogsByRunId(_args) {
|
|
577
|
+
return { logs: [], total: 0, page: _args.page ?? 1, perPage: _args.perPage ?? 100, hasMore: false };
|
|
578
|
+
}
|
|
579
|
+
};
|
|
580
|
+
|
|
581
|
+
// ../../packages/_internal-core/dist/base/index.js
|
|
582
|
+
var MastraBase = class {
|
|
583
|
+
component = RegisteredLogger.LLM;
|
|
584
|
+
logger;
|
|
585
|
+
name;
|
|
586
|
+
#rawConfig;
|
|
587
|
+
constructor({
|
|
588
|
+
component,
|
|
589
|
+
name,
|
|
590
|
+
rawConfig
|
|
591
|
+
}) {
|
|
592
|
+
this.component = component || RegisteredLogger.LLM;
|
|
593
|
+
this.name = name;
|
|
594
|
+
this.#rawConfig = rawConfig;
|
|
595
|
+
this.logger = new ConsoleLogger({ name: `${this.component} - ${this.name}` });
|
|
596
|
+
}
|
|
597
|
+
/**
|
|
598
|
+
* Returns the raw storage configuration this primitive was created from,
|
|
599
|
+
* or undefined if it was created from code.
|
|
600
|
+
*/
|
|
601
|
+
toRawConfig() {
|
|
602
|
+
return this.#rawConfig;
|
|
603
|
+
}
|
|
604
|
+
/**
|
|
605
|
+
* Sets the raw storage configuration for this primitive.
|
|
606
|
+
* @internal
|
|
607
|
+
*/
|
|
608
|
+
__setRawConfig(rawConfig) {
|
|
609
|
+
this.#rawConfig = rawConfig;
|
|
610
|
+
}
|
|
611
|
+
/**
|
|
612
|
+
* Set the logger for the agent
|
|
613
|
+
* @param logger
|
|
614
|
+
*/
|
|
615
|
+
__setLogger(logger) {
|
|
616
|
+
this.logger = "child" in logger && typeof logger.child === "function" ? logger.child({ component: this.component }) : logger;
|
|
617
|
+
}
|
|
618
|
+
};
|
|
619
|
+
|
|
620
|
+
// ../../packages/_internals/auth/dist/chunk-XG6GH2VJ.js
|
|
621
|
+
var MastraAuthProvider = class extends MastraBase {
|
|
622
|
+
protected;
|
|
623
|
+
public;
|
|
624
|
+
constructor(options) {
|
|
625
|
+
super({ component: "AUTH", name: options?.name });
|
|
626
|
+
if (options?.authorizeUser) {
|
|
627
|
+
this.authorizeUser = options.authorizeUser.bind(this);
|
|
628
|
+
}
|
|
629
|
+
this.protected = options?.protected;
|
|
630
|
+
this.public = options?.public;
|
|
631
|
+
this.mapUserToResourceId = options?.mapUserToResourceId;
|
|
632
|
+
}
|
|
633
|
+
registerOptions(opts) {
|
|
634
|
+
if (opts?.authorizeUser) {
|
|
635
|
+
this.authorizeUser = opts.authorizeUser.bind(this);
|
|
636
|
+
}
|
|
637
|
+
if (opts?.mapUserToResourceId) {
|
|
638
|
+
this.mapUserToResourceId = opts.mapUserToResourceId;
|
|
639
|
+
}
|
|
640
|
+
if (opts?.protected) {
|
|
641
|
+
this.protected = opts.protected;
|
|
642
|
+
}
|
|
643
|
+
if (opts?.public) {
|
|
644
|
+
this.public = opts.public;
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
};
|
|
648
|
+
|
|
649
|
+
// src/auth-provider.ts
|
|
650
|
+
function getRequestHeader2(request, name) {
|
|
470
651
|
if (request instanceof Request) {
|
|
471
652
|
return request.headers.get(name);
|
|
472
653
|
}
|
|
473
654
|
return request.raw?.headers.get(name) ?? request.headers?.get(name) ?? request.header(name) ?? null;
|
|
474
655
|
}
|
|
475
|
-
var MastraCloudAuthProvider = class extends
|
|
656
|
+
var MastraCloudAuthProvider = class extends MastraAuthProvider {
|
|
476
657
|
client;
|
|
477
658
|
/** Marker for EE license exemption - MastraCloudAuth is exempt */
|
|
478
659
|
isMastraCloudAuth = true;
|
|
@@ -515,7 +696,7 @@ var MastraCloudAuthProvider = class extends server.MastraAuthProvider {
|
|
|
515
696
|
*/
|
|
516
697
|
async authenticateToken(token, request) {
|
|
517
698
|
try {
|
|
518
|
-
const cookieHeader =
|
|
699
|
+
const cookieHeader = getRequestHeader2(request, "cookie");
|
|
519
700
|
const sessionToken = parseSessionCookie(cookieHeader);
|
|
520
701
|
if (sessionToken) {
|
|
521
702
|
const { user, role } = await this.client.verifyToken(sessionToken);
|
|
@@ -754,6 +935,85 @@ var MastraCloudAuthProvider = class extends server.MastraAuthProvider {
|
|
|
754
935
|
return null;
|
|
755
936
|
}
|
|
756
937
|
};
|
|
938
|
+
|
|
939
|
+
// ../../packages/_internals/auth/dist/chunk-7SVOHBXQ.js
|
|
940
|
+
var RESOURCE_EXPANSIONS = {
|
|
941
|
+
stored: [
|
|
942
|
+
"stored-agents",
|
|
943
|
+
"stored-mcp-clients",
|
|
944
|
+
"stored-prompt-blocks",
|
|
945
|
+
"stored-scorers",
|
|
946
|
+
"stored-skills",
|
|
947
|
+
"stored-workspaces"
|
|
948
|
+
]
|
|
949
|
+
};
|
|
950
|
+
function matchesPermission(userPermission, requiredPermission) {
|
|
951
|
+
if (userPermission === "*") {
|
|
952
|
+
return true;
|
|
953
|
+
}
|
|
954
|
+
const grantedParts = userPermission.split(":");
|
|
955
|
+
const requiredParts = requiredPermission.split(":");
|
|
956
|
+
const expandedFamilies = RESOURCE_EXPANSIONS[grantedParts[0] ?? ""];
|
|
957
|
+
if (expandedFamilies && expandedFamilies.includes(requiredParts[0] ?? "")) {
|
|
958
|
+
const aliased = [requiredParts[0], ...grantedParts.slice(1)].join(":");
|
|
959
|
+
return matchesPermission(aliased, requiredPermission);
|
|
960
|
+
}
|
|
961
|
+
if (grantedParts.length < 2 || requiredParts.length < 2) {
|
|
962
|
+
return userPermission === requiredPermission;
|
|
963
|
+
}
|
|
964
|
+
const [grantedResource, grantedAction, grantedId] = grantedParts;
|
|
965
|
+
const [requiredResource, requiredAction, requiredId] = requiredParts;
|
|
966
|
+
if (grantedResource === "*") {
|
|
967
|
+
if (grantedAction === "*") {
|
|
968
|
+
if (grantedId === void 0) {
|
|
969
|
+
return true;
|
|
970
|
+
}
|
|
971
|
+
return grantedId === requiredId;
|
|
972
|
+
}
|
|
973
|
+
if (grantedAction !== requiredAction) {
|
|
974
|
+
return false;
|
|
975
|
+
}
|
|
976
|
+
if (grantedId === void 0) {
|
|
977
|
+
return true;
|
|
978
|
+
}
|
|
979
|
+
return grantedId === requiredId;
|
|
980
|
+
}
|
|
981
|
+
if (grantedResource !== requiredResource) {
|
|
982
|
+
return false;
|
|
983
|
+
}
|
|
984
|
+
if (grantedAction === "*") {
|
|
985
|
+
if (grantedId === void 0) {
|
|
986
|
+
return true;
|
|
987
|
+
}
|
|
988
|
+
return grantedId === requiredId;
|
|
989
|
+
}
|
|
990
|
+
if (grantedAction !== requiredAction) {
|
|
991
|
+
return false;
|
|
992
|
+
}
|
|
993
|
+
if (grantedId === void 0) {
|
|
994
|
+
return true;
|
|
995
|
+
}
|
|
996
|
+
return grantedId === requiredId;
|
|
997
|
+
}
|
|
998
|
+
function resolvePermissionsFromMapping(roles, mapping) {
|
|
999
|
+
const permissions = /* @__PURE__ */ new Set();
|
|
1000
|
+
const defaultPerms = mapping["_default"] ?? [];
|
|
1001
|
+
for (const role of roles) {
|
|
1002
|
+
const rolePerms = mapping[role];
|
|
1003
|
+
if (rolePerms) {
|
|
1004
|
+
for (const perm of rolePerms) {
|
|
1005
|
+
permissions.add(perm);
|
|
1006
|
+
}
|
|
1007
|
+
} else {
|
|
1008
|
+
for (const perm of defaultPerms) {
|
|
1009
|
+
permissions.add(perm);
|
|
1010
|
+
}
|
|
1011
|
+
}
|
|
1012
|
+
}
|
|
1013
|
+
return Array.from(permissions);
|
|
1014
|
+
}
|
|
1015
|
+
|
|
1016
|
+
// src/rbac/rbac-provider.ts
|
|
757
1017
|
var MastraRBACCloud = class {
|
|
758
1018
|
options;
|
|
759
1019
|
/**
|
|
@@ -812,7 +1072,7 @@ var MastraRBACCloud = class {
|
|
|
812
1072
|
if (roles.length === 0) {
|
|
813
1073
|
return this.options.roleMapping["_default"] ?? [];
|
|
814
1074
|
}
|
|
815
|
-
return
|
|
1075
|
+
return resolvePermissionsFromMapping(roles, this.options.roleMapping);
|
|
816
1076
|
}
|
|
817
1077
|
/**
|
|
818
1078
|
* Check if a user has a specific permission.
|
|
@@ -826,7 +1086,7 @@ var MastraRBACCloud = class {
|
|
|
826
1086
|
*/
|
|
827
1087
|
async hasPermission(user, permission) {
|
|
828
1088
|
const permissions = await this.getPermissions(user);
|
|
829
|
-
return permissions.some((p) =>
|
|
1089
|
+
return permissions.some((p) => matchesPermission(p, permission));
|
|
830
1090
|
}
|
|
831
1091
|
/**
|
|
832
1092
|
* Check if a user has ALL of the specified permissions.
|
|
@@ -837,7 +1097,7 @@ var MastraRBACCloud = class {
|
|
|
837
1097
|
*/
|
|
838
1098
|
async hasAllPermissions(user, permissions) {
|
|
839
1099
|
const userPermissions = await this.getPermissions(user);
|
|
840
|
-
return permissions.every((required) => userPermissions.some((p) =>
|
|
1100
|
+
return permissions.every((required) => userPermissions.some((p) => matchesPermission(p, required)));
|
|
841
1101
|
}
|
|
842
1102
|
/**
|
|
843
1103
|
* Check if a user has ANY of the specified permissions.
|
|
@@ -848,9 +1108,41 @@ var MastraRBACCloud = class {
|
|
|
848
1108
|
*/
|
|
849
1109
|
async hasAnyPermission(user, permissions) {
|
|
850
1110
|
const userPermissions = await this.getPermissions(user);
|
|
851
|
-
return permissions.some((required) => userPermissions.some((p) =>
|
|
1111
|
+
return permissions.some((required) => userPermissions.some((p) => matchesPermission(p, required)));
|
|
852
1112
|
}
|
|
853
1113
|
};
|
|
1114
|
+
/**
|
|
1115
|
+
* EE Authentication Interfaces
|
|
1116
|
+
*
|
|
1117
|
+
* Enterprise interfaces for RBAC, ACL, and advanced authorization.
|
|
1118
|
+
*
|
|
1119
|
+
* @license Mastra Enterprise License - see ee/LICENSE
|
|
1120
|
+
* @packageDocumentation
|
|
1121
|
+
*/
|
|
1122
|
+
/**
|
|
1123
|
+
* FGA enforcement utility for checking fine-grained authorization.
|
|
1124
|
+
*
|
|
1125
|
+
* @license Mastra Enterprise License - see ee/LICENSE
|
|
1126
|
+
*/
|
|
1127
|
+
/**
|
|
1128
|
+
* RBAC provider implementations.
|
|
1129
|
+
*
|
|
1130
|
+
* @license Mastra Enterprise License - see ee/LICENSE
|
|
1131
|
+
*/
|
|
1132
|
+
/**
|
|
1133
|
+
* Default implementations for EE authentication.
|
|
1134
|
+
*
|
|
1135
|
+
* @license Mastra Enterprise License - see ee/LICENSE
|
|
1136
|
+
*/
|
|
1137
|
+
/**
|
|
1138
|
+
* @mastra/core/auth/ee
|
|
1139
|
+
*
|
|
1140
|
+
* Enterprise authentication capabilities for Mastra.
|
|
1141
|
+
* This code is licensed under the Mastra Enterprise License - see ee/LICENSE.
|
|
1142
|
+
*
|
|
1143
|
+
* @license Mastra Enterprise License - see ee/LICENSE
|
|
1144
|
+
* @packageDocumentation
|
|
1145
|
+
*/
|
|
854
1146
|
|
|
855
1147
|
exports.AuthError = AuthError;
|
|
856
1148
|
exports.MastraCloudAuth = MastraCloudAuth;
|