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