@mastra/auth-workos 1.6.0 → 1.6.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 +3 -3
- package/dist/auth-provider.d.ts.map +1 -1
- package/dist/fga-provider.d.ts +2 -2
- package/dist/fga-provider.d.ts.map +1 -1
- package/dist/index.cjs +316 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +307 -3
- package/dist/index.js.map +1 -1
- package/dist/rbac-provider.d.ts +1 -1
- package/dist/rbac-provider.d.ts.map +1 -1
- package/dist/types.d.ts +3 -4
- package/dist/types.d.ts.map +1 -1
- package/package.json +6 -6
- package/LICENSE.md +0 -30
package/dist/index.js
CHANGED
|
@@ -1,11 +1,188 @@
|
|
|
1
1
|
import { verifyJwks } from '@mastra/auth';
|
|
2
|
-
import { MastraAuthProvider } from '@mastra/core/server';
|
|
3
2
|
import { CookieSessionStorage, AuthService, sessionEncryption } from '@workos/authkit-session';
|
|
4
3
|
import { WorkOS, GeneratePortalLinkIntent } from '@workos-inc/node';
|
|
5
4
|
import { LRUCache } from 'lru-cache';
|
|
6
|
-
import { resolvePermissionsFromMapping, matchesPermission, FGADeniedError } from '@mastra/core/auth/ee';
|
|
7
5
|
|
|
8
|
-
//
|
|
6
|
+
// ../../packages/_internal-core/dist/chunk-3M4SEWMI.js
|
|
7
|
+
var RegisteredLogger = {
|
|
8
|
+
LLM: "LLM"};
|
|
9
|
+
var LogLevel = {
|
|
10
|
+
DEBUG: "debug",
|
|
11
|
+
INFO: "info",
|
|
12
|
+
WARN: "warn",
|
|
13
|
+
ERROR: "error"};
|
|
14
|
+
var MastraLogger = class {
|
|
15
|
+
name;
|
|
16
|
+
level;
|
|
17
|
+
transports;
|
|
18
|
+
constructor(options = {}) {
|
|
19
|
+
this.name = options.name || "Mastra";
|
|
20
|
+
this.level = options.level || LogLevel.ERROR;
|
|
21
|
+
this.transports = new Map(Object.entries(options.transports || {}));
|
|
22
|
+
}
|
|
23
|
+
getTransports() {
|
|
24
|
+
return this.transports;
|
|
25
|
+
}
|
|
26
|
+
trackException(_error, _metadata) {
|
|
27
|
+
}
|
|
28
|
+
async listLogs(transportId, params) {
|
|
29
|
+
if (!transportId || !this.transports.has(transportId)) {
|
|
30
|
+
return { logs: [], total: 0, page: params?.page ?? 1, perPage: params?.perPage ?? 100, hasMore: false };
|
|
31
|
+
}
|
|
32
|
+
return this.transports.get(transportId).listLogs?.(params) ?? {
|
|
33
|
+
logs: [],
|
|
34
|
+
total: 0,
|
|
35
|
+
page: params?.page ?? 1,
|
|
36
|
+
perPage: params?.perPage ?? 100,
|
|
37
|
+
hasMore: false
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
async listLogsByRunId({
|
|
41
|
+
transportId,
|
|
42
|
+
runId,
|
|
43
|
+
fromDate,
|
|
44
|
+
toDate,
|
|
45
|
+
logLevel,
|
|
46
|
+
filters,
|
|
47
|
+
page,
|
|
48
|
+
perPage
|
|
49
|
+
}) {
|
|
50
|
+
if (!transportId || !this.transports.has(transportId) || !runId) {
|
|
51
|
+
return { logs: [], total: 0, page: page ?? 1, perPage: perPage ?? 100, hasMore: false };
|
|
52
|
+
}
|
|
53
|
+
return this.transports.get(transportId).listLogsByRunId?.({ runId, fromDate, toDate, logLevel, filters, page, perPage }) ?? {
|
|
54
|
+
logs: [],
|
|
55
|
+
total: 0,
|
|
56
|
+
page: page ?? 1,
|
|
57
|
+
perPage: perPage ?? 100,
|
|
58
|
+
hasMore: false
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
var ConsoleLogger = class _ConsoleLogger extends MastraLogger {
|
|
63
|
+
component;
|
|
64
|
+
filter;
|
|
65
|
+
constructor(options = {}) {
|
|
66
|
+
super(options);
|
|
67
|
+
this.component = options.component;
|
|
68
|
+
this.filter = options.filter;
|
|
69
|
+
}
|
|
70
|
+
child(componentOrBindings) {
|
|
71
|
+
const component = typeof componentOrBindings === "string" ? componentOrBindings : componentOrBindings?.component ?? this.component;
|
|
72
|
+
return new _ConsoleLogger({
|
|
73
|
+
name: this.name,
|
|
74
|
+
level: this.level,
|
|
75
|
+
component,
|
|
76
|
+
filter: this.filter
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
shouldLog(level, message, args) {
|
|
80
|
+
if (!this.filter) return true;
|
|
81
|
+
try {
|
|
82
|
+
return this.filter({ component: this.component, level, message, args });
|
|
83
|
+
} catch (e) {
|
|
84
|
+
console.error(`[Logger] Filter error for component=${this.component} level=${level}:`, e);
|
|
85
|
+
return true;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
prefix() {
|
|
89
|
+
return this.component ? `[${this.component}] ` : "";
|
|
90
|
+
}
|
|
91
|
+
debug(message, ...args) {
|
|
92
|
+
if (this.level === LogLevel.DEBUG && this.shouldLog(LogLevel.DEBUG, message, args)) {
|
|
93
|
+
console.info(`${this.prefix()}${message}`, ...args);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
info(message, ...args) {
|
|
97
|
+
if ((this.level === LogLevel.INFO || this.level === LogLevel.DEBUG) && this.shouldLog(LogLevel.INFO, message, args)) {
|
|
98
|
+
console.info(`${this.prefix()}${message}`, ...args);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
warn(message, ...args) {
|
|
102
|
+
if ((this.level === LogLevel.WARN || this.level === LogLevel.INFO || this.level === LogLevel.DEBUG) && this.shouldLog(LogLevel.WARN, message, args)) {
|
|
103
|
+
console.warn(`${this.prefix()}${message}`, ...args);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
error(message, ...args) {
|
|
107
|
+
if ((this.level === LogLevel.ERROR || this.level === LogLevel.WARN || this.level === LogLevel.INFO || this.level === LogLevel.DEBUG) && this.shouldLog(LogLevel.ERROR, message, args)) {
|
|
108
|
+
console.error(`${this.prefix()}${message}`, ...args);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
async listLogs(_transportId, _params) {
|
|
112
|
+
return { logs: [], total: 0, page: _params?.page ?? 1, perPage: _params?.perPage ?? 100, hasMore: false };
|
|
113
|
+
}
|
|
114
|
+
async listLogsByRunId(_args) {
|
|
115
|
+
return { logs: [], total: 0, page: _args.page ?? 1, perPage: _args.perPage ?? 100, hasMore: false };
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
// ../../packages/_internal-core/dist/base/index.js
|
|
120
|
+
var MastraBase = class {
|
|
121
|
+
component = RegisteredLogger.LLM;
|
|
122
|
+
logger;
|
|
123
|
+
name;
|
|
124
|
+
#rawConfig;
|
|
125
|
+
constructor({
|
|
126
|
+
component,
|
|
127
|
+
name,
|
|
128
|
+
rawConfig
|
|
129
|
+
}) {
|
|
130
|
+
this.component = component || RegisteredLogger.LLM;
|
|
131
|
+
this.name = name;
|
|
132
|
+
this.#rawConfig = rawConfig;
|
|
133
|
+
this.logger = new ConsoleLogger({ name: `${this.component} - ${this.name}` });
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Returns the raw storage configuration this primitive was created from,
|
|
137
|
+
* or undefined if it was created from code.
|
|
138
|
+
*/
|
|
139
|
+
toRawConfig() {
|
|
140
|
+
return this.#rawConfig;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Sets the raw storage configuration for this primitive.
|
|
144
|
+
* @internal
|
|
145
|
+
*/
|
|
146
|
+
__setRawConfig(rawConfig) {
|
|
147
|
+
this.#rawConfig = rawConfig;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Set the logger for the agent
|
|
151
|
+
* @param logger
|
|
152
|
+
*/
|
|
153
|
+
__setLogger(logger) {
|
|
154
|
+
this.logger = "child" in logger && typeof logger.child === "function" ? logger.child({ component: this.component }) : logger;
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
// ../../packages/_internals/auth/dist/chunk-XG6GH2VJ.js
|
|
159
|
+
var MastraAuthProvider = class extends MastraBase {
|
|
160
|
+
protected;
|
|
161
|
+
public;
|
|
162
|
+
constructor(options) {
|
|
163
|
+
super({ component: "AUTH", name: options?.name });
|
|
164
|
+
if (options?.authorizeUser) {
|
|
165
|
+
this.authorizeUser = options.authorizeUser.bind(this);
|
|
166
|
+
}
|
|
167
|
+
this.protected = options?.protected;
|
|
168
|
+
this.public = options?.public;
|
|
169
|
+
this.mapUserToResourceId = options?.mapUserToResourceId;
|
|
170
|
+
}
|
|
171
|
+
registerOptions(opts) {
|
|
172
|
+
if (opts?.authorizeUser) {
|
|
173
|
+
this.authorizeUser = opts.authorizeUser.bind(this);
|
|
174
|
+
}
|
|
175
|
+
if (opts?.mapUserToResourceId) {
|
|
176
|
+
this.mapUserToResourceId = opts.mapUserToResourceId;
|
|
177
|
+
}
|
|
178
|
+
if (opts?.protected) {
|
|
179
|
+
this.protected = opts.protected;
|
|
180
|
+
}
|
|
181
|
+
if (opts?.public) {
|
|
182
|
+
this.public = opts.public;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
};
|
|
9
186
|
var WebSessionStorage = class extends CookieSessionStorage {
|
|
10
187
|
constructor(config) {
|
|
11
188
|
super(config);
|
|
@@ -607,6 +784,101 @@ var MastraAuthWorkos = class extends MastraAuthProvider {
|
|
|
607
784
|
return this.redirectUri;
|
|
608
785
|
}
|
|
609
786
|
};
|
|
787
|
+
|
|
788
|
+
// ../../packages/_internals/auth/dist/chunk-JCX4XB6F.js
|
|
789
|
+
var FGADeniedError = class extends Error {
|
|
790
|
+
user;
|
|
791
|
+
resource;
|
|
792
|
+
permission;
|
|
793
|
+
status;
|
|
794
|
+
constructor(user, resource, permission, reason) {
|
|
795
|
+
const userId = user?.id || user?.workosId || "unknown";
|
|
796
|
+
const permissionLabel = Array.isArray(permission) ? `any of [${permission.join(", ")}]` : permission;
|
|
797
|
+
super(
|
|
798
|
+
reason ? `FGA authorization denied: ${reason}` : `FGA authorization denied: user ${userId} cannot ${permissionLabel} on ${resource.type}:${resource.id}`
|
|
799
|
+
);
|
|
800
|
+
this.name = "FGADeniedError";
|
|
801
|
+
this.user = user;
|
|
802
|
+
this.resource = resource;
|
|
803
|
+
this.permission = permission;
|
|
804
|
+
this.status = 403;
|
|
805
|
+
}
|
|
806
|
+
};
|
|
807
|
+
var RESOURCE_EXPANSIONS = {
|
|
808
|
+
stored: [
|
|
809
|
+
"stored-agents",
|
|
810
|
+
"stored-mcp-clients",
|
|
811
|
+
"stored-prompt-blocks",
|
|
812
|
+
"stored-scorers",
|
|
813
|
+
"stored-skills",
|
|
814
|
+
"stored-workspaces"
|
|
815
|
+
]
|
|
816
|
+
};
|
|
817
|
+
function matchesPermission(userPermission, requiredPermission) {
|
|
818
|
+
if (userPermission === "*") {
|
|
819
|
+
return true;
|
|
820
|
+
}
|
|
821
|
+
const grantedParts = userPermission.split(":");
|
|
822
|
+
const requiredParts = requiredPermission.split(":");
|
|
823
|
+
const expandedFamilies = RESOURCE_EXPANSIONS[grantedParts[0] ?? ""];
|
|
824
|
+
if (expandedFamilies && expandedFamilies.includes(requiredParts[0] ?? "")) {
|
|
825
|
+
const aliased = [requiredParts[0], ...grantedParts.slice(1)].join(":");
|
|
826
|
+
return matchesPermission(aliased, requiredPermission);
|
|
827
|
+
}
|
|
828
|
+
if (grantedParts.length < 2 || requiredParts.length < 2) {
|
|
829
|
+
return userPermission === requiredPermission;
|
|
830
|
+
}
|
|
831
|
+
const [grantedResource, grantedAction, grantedId] = grantedParts;
|
|
832
|
+
const [requiredResource, requiredAction, requiredId] = requiredParts;
|
|
833
|
+
if (grantedResource === "*") {
|
|
834
|
+
if (grantedAction === "*") {
|
|
835
|
+
if (grantedId === void 0) {
|
|
836
|
+
return true;
|
|
837
|
+
}
|
|
838
|
+
return grantedId === requiredId;
|
|
839
|
+
}
|
|
840
|
+
if (grantedAction !== requiredAction) {
|
|
841
|
+
return false;
|
|
842
|
+
}
|
|
843
|
+
if (grantedId === void 0) {
|
|
844
|
+
return true;
|
|
845
|
+
}
|
|
846
|
+
return grantedId === requiredId;
|
|
847
|
+
}
|
|
848
|
+
if (grantedResource !== requiredResource) {
|
|
849
|
+
return false;
|
|
850
|
+
}
|
|
851
|
+
if (grantedAction === "*") {
|
|
852
|
+
if (grantedId === void 0) {
|
|
853
|
+
return true;
|
|
854
|
+
}
|
|
855
|
+
return grantedId === requiredId;
|
|
856
|
+
}
|
|
857
|
+
if (grantedAction !== requiredAction) {
|
|
858
|
+
return false;
|
|
859
|
+
}
|
|
860
|
+
if (grantedId === void 0) {
|
|
861
|
+
return true;
|
|
862
|
+
}
|
|
863
|
+
return grantedId === requiredId;
|
|
864
|
+
}
|
|
865
|
+
function resolvePermissionsFromMapping(roles, mapping) {
|
|
866
|
+
const permissions = /* @__PURE__ */ new Set();
|
|
867
|
+
const defaultPerms = mapping["_default"] ?? [];
|
|
868
|
+
for (const role of roles) {
|
|
869
|
+
const rolePerms = mapping[role];
|
|
870
|
+
if (rolePerms) {
|
|
871
|
+
for (const perm of rolePerms) {
|
|
872
|
+
permissions.add(perm);
|
|
873
|
+
}
|
|
874
|
+
} else {
|
|
875
|
+
for (const perm of defaultPerms) {
|
|
876
|
+
permissions.add(perm);
|
|
877
|
+
}
|
|
878
|
+
}
|
|
879
|
+
}
|
|
880
|
+
return Array.from(permissions);
|
|
881
|
+
}
|
|
610
882
|
var DEFAULT_CACHE_TTL_MS = 60 * 1e3;
|
|
611
883
|
var DEFAULT_CACHE_MAX_SIZE = 1e3;
|
|
612
884
|
var MastraRBACWorkos = class {
|
|
@@ -1509,6 +1781,38 @@ var WorkOSAdminPortal = class {
|
|
|
1509
1781
|
return result.link;
|
|
1510
1782
|
}
|
|
1511
1783
|
};
|
|
1784
|
+
/**
|
|
1785
|
+
* EE Authentication Interfaces
|
|
1786
|
+
*
|
|
1787
|
+
* Enterprise interfaces for RBAC, ACL, and advanced authorization.
|
|
1788
|
+
*
|
|
1789
|
+
* @license Mastra Enterprise License - see ee/LICENSE
|
|
1790
|
+
* @packageDocumentation
|
|
1791
|
+
*/
|
|
1792
|
+
/**
|
|
1793
|
+
* FGA enforcement utility for checking fine-grained authorization.
|
|
1794
|
+
*
|
|
1795
|
+
* @license Mastra Enterprise License - see ee/LICENSE
|
|
1796
|
+
*/
|
|
1797
|
+
/**
|
|
1798
|
+
* RBAC provider implementations.
|
|
1799
|
+
*
|
|
1800
|
+
* @license Mastra Enterprise License - see ee/LICENSE
|
|
1801
|
+
*/
|
|
1802
|
+
/**
|
|
1803
|
+
* Default implementations for EE authentication.
|
|
1804
|
+
*
|
|
1805
|
+
* @license Mastra Enterprise License - see ee/LICENSE
|
|
1806
|
+
*/
|
|
1807
|
+
/**
|
|
1808
|
+
* @mastra/core/auth/ee
|
|
1809
|
+
*
|
|
1810
|
+
* Enterprise authentication capabilities for Mastra.
|
|
1811
|
+
* This code is licensed under the Mastra Enterprise License - see ee/LICENSE.
|
|
1812
|
+
*
|
|
1813
|
+
* @license Mastra Enterprise License - see ee/LICENSE
|
|
1814
|
+
* @packageDocumentation
|
|
1815
|
+
*/
|
|
1512
1816
|
/**
|
|
1513
1817
|
* WorkOS FGA provider for Mastra.
|
|
1514
1818
|
*
|