@mastra/auth-studio 1.3.11 → 1.4.0-alpha.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/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/provider/index.d.ts +1 -1
- package/dist/index.cjs +69 -26
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +17 -12
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +69 -26
- package/dist/index.js.map +1 -1
- package/package.json +7 -7
- /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/index.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}/dist/types/index.d.ts +0 -0
- /package/dist/_types/{@internal_auth → @internal_auth@0.0.36}/package.json +0 -0
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { IOrganizationsProvider, ISSOProvider, ISessionProvider, IUserProvider, MastraAuthRequest, Session, SSOCallbackResult, SSOLoginConfig } from './_types/@internal_auth/dist/index.js';
|
|
2
|
-
import type { EEUser, IRBACProvider, RoleMapping } from './_types/@internal_auth/dist/ee/index.js';
|
|
3
|
-
import { MastraAuthProvider } from './_types/@internal_auth/dist/provider/index.js';
|
|
4
|
-
import type { MastraAuthProviderOptions } from './_types/@internal_auth/dist/provider/index.js';
|
|
1
|
+
import type { IOrganizationsProvider, ISSOProvider, ISessionProvider, IUserProvider, MastraAuthRequest, Session, SSOCallbackResult, SSOLoginConfig } from './_types/@internal_auth@0.0.36/dist/index.js';
|
|
2
|
+
import type { EEUser, IRBACProvider, RoleMapping } from './_types/@internal_auth@0.0.36/dist/ee/index.js';
|
|
3
|
+
import { MastraAuthProvider } from './_types/@internal_auth@0.0.36/dist/provider/index.js';
|
|
4
|
+
import type { MastraAuthProviderOptions } from './_types/@internal_auth@0.0.36/dist/provider/index.js';
|
|
5
5
|
export interface StudioUser extends EEUser {
|
|
6
6
|
id: string;
|
|
7
7
|
email?: string;
|
|
@@ -115,6 +115,7 @@ export declare class MastraAuthStudio extends MastraAuthProvider<StudioUser> imp
|
|
|
115
115
|
* caller's promise is reused by every follower until it settles.
|
|
116
116
|
*/
|
|
117
117
|
private organizationBootstrapInFlight;
|
|
118
|
+
private sessionVerificationsInFlight;
|
|
118
119
|
/**
|
|
119
120
|
* Per-request response headers to forward to the browser — specifically a
|
|
120
121
|
* rotated `wos-session` `Set-Cookie` returned by the shared API when the
|
|
@@ -128,6 +129,8 @@ export declare class MastraAuthStudio extends MastraAuthProvider<StudioUser> imp
|
|
|
128
129
|
* requests after the response is written.
|
|
129
130
|
*/
|
|
130
131
|
private pendingResponseHeaders;
|
|
132
|
+
/** The request's current sealed cookie once a shared API call renewed it: the inbound one's refresh token is spent. */
|
|
133
|
+
private renewedSessionCookies;
|
|
131
134
|
constructor(options?: MastraAuthStudioOptions);
|
|
132
135
|
/**
|
|
133
136
|
* Authenticate an incoming request by forwarding the sealed session cookie
|
|
@@ -215,20 +218,21 @@ export declare class MastraAuthStudio extends MastraAuthProvider<StudioUser> imp
|
|
|
215
218
|
* single-value accessor on runtimes without `Headers.getSetCookie()`.
|
|
216
219
|
*/
|
|
217
220
|
private readSetCookieHeaders;
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
* response, stash the `Set-Cookie` header against the inbound request so
|
|
221
|
-
* the server middleware can forward it to the browser, and invalidate the
|
|
222
|
-
* short-TTL verification cache entry for the old cookie value. Returns the
|
|
223
|
-
* rotated sealed value, or null when the cookie was not rotated.
|
|
224
|
-
*/
|
|
225
|
-
private captureRotatedCookie;
|
|
221
|
+
private readRotatedCookie;
|
|
222
|
+
private forwardRotatedCookie;
|
|
226
223
|
/**
|
|
227
224
|
* Server middleware hook: emit any response headers the provider
|
|
228
225
|
* accumulated for this request (currently a rotated `Set-Cookie`) and
|
|
229
226
|
* clear them from the provider's per-request state.
|
|
230
227
|
*/
|
|
231
228
|
consumePendingResponseHeaders(request: MastraAuthRequest): Record<string, string> | undefined;
|
|
229
|
+
/**
|
|
230
|
+
* Call the shared API as the request's signed-in user. The shared API acts on the
|
|
231
|
+
* session's active organization, not the pinned one. A renewed session cookie is
|
|
232
|
+
* queued for {@link consumePendingResponseHeaders} and sent by later calls for the
|
|
233
|
+
* same request. Returns `null` when the request has no session.
|
|
234
|
+
*/
|
|
235
|
+
fetchAsRequestUser(request: Request, path: string, init?: RequestInit): Promise<Response | null>;
|
|
232
236
|
/**
|
|
233
237
|
* Fetch the shared API's `/auth/me` and return the raw response body, or
|
|
234
238
|
* `null` on any non-OK / network error. Split out so `ensureOrganization`
|
|
@@ -240,6 +244,7 @@ export declare class MastraAuthStudio extends MastraAuthProvider<StudioUser> imp
|
|
|
240
244
|
* to validate it and get user info.
|
|
241
245
|
*/
|
|
242
246
|
private verifySessionCookie;
|
|
247
|
+
private doVerifySessionCookie;
|
|
243
248
|
/**
|
|
244
249
|
* Forward a Bearer token to the shared API's /auth/verify endpoint
|
|
245
250
|
* to validate it and get user info (used for CLI tokens).
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,sBAAsB,EACtB,YAAY,EACZ,gBAAgB,EAChB,aAAa,EACb,iBAAiB,EACjB,OAAO,EACP,iBAAiB,EACjB,cAAc,EACf,MAAM,gBAAgB,CAAC;AAExB,OAAO,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAE5E,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,yBAAyB,CAAC;AAEzE,MAAM,WAAW,UAAW,SAAQ,MAAM;IACxC,EAAE,EAAE,MAAM,CA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AAC,OAAO,CAAC,CAGjF;IAEK,gBAAgB,CAAC,IAAI,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC,CAGhF;CACF"}
|
package/dist/index.js
CHANGED
|
@@ -312,7 +312,7 @@ var MastraAuthProvider = class extends MastraBase {
|
|
|
312
312
|
if (opts?.public) this.public = opts.public;
|
|
313
313
|
}
|
|
314
314
|
};
|
|
315
|
-
// ../../packages/_internals/auth/dist/ee-
|
|
315
|
+
// ../../packages/_internals/auth/dist/ee-iTj2bRDt.js
|
|
316
316
|
/**
|
|
317
317
|
* FGA enforcement utility for checking fine-grained authorization.
|
|
318
318
|
*
|
|
@@ -524,6 +524,7 @@ var MastraAuthStudio = class extends MastraAuthProvider {
|
|
|
524
524
|
* caller's promise is reused by every follower until it settles.
|
|
525
525
|
*/
|
|
526
526
|
organizationBootstrapInFlight = /* @__PURE__ */ new Map();
|
|
527
|
+
sessionVerificationsInFlight = /* @__PURE__ */ new Map();
|
|
527
528
|
/**
|
|
528
529
|
* Per-request response headers to forward to the browser — specifically a
|
|
529
530
|
* rotated `wos-session` `Set-Cookie` returned by the shared API when the
|
|
@@ -537,6 +538,8 @@ var MastraAuthStudio = class extends MastraAuthProvider {
|
|
|
537
538
|
* requests after the response is written.
|
|
538
539
|
*/
|
|
539
540
|
pendingResponseHeaders = /* @__PURE__ */ new WeakMap();
|
|
541
|
+
/** The request's current sealed cookie once a shared API call renewed it: the inbound one's refresh token is spent. */
|
|
542
|
+
renewedSessionCookies = /* @__PURE__ */ new WeakMap();
|
|
540
543
|
constructor(options) {
|
|
541
544
|
super({
|
|
542
545
|
name: "mastra-studio",
|
|
@@ -964,33 +967,28 @@ var MastraAuthStudio = class extends MastraAuthProvider {
|
|
|
964
967
|
const single = res.headers.get("Set-Cookie");
|
|
965
968
|
return single ? [single] : [];
|
|
966
969
|
}
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
* response, stash the `Set-Cookie` header against the inbound request so
|
|
970
|
-
* the server middleware can forward it to the browser, and invalidate the
|
|
971
|
-
* short-TTL verification cache entry for the old cookie value. Returns the
|
|
972
|
-
* rotated sealed value, or null when the cookie was not rotated.
|
|
973
|
-
*/
|
|
974
|
-
captureRotatedCookie(res, oldSessionCookie, oldCacheKey, request) {
|
|
975
|
-
const setCookies = this.readSetCookieHeaders(res);
|
|
976
|
-
if (setCookies.length === 0) return null;
|
|
977
|
-
const rotatedCookieHeader = setCookies.find((h) => parseCookieFromHeader(h, COOKIE_NAME) !== null);
|
|
970
|
+
readRotatedCookie(res, oldSessionCookie) {
|
|
971
|
+
const rotatedCookieHeader = this.readSetCookieHeaders(res).find((h) => parseCookieFromHeader(h, COOKIE_NAME) !== null);
|
|
978
972
|
if (!rotatedCookieHeader) return null;
|
|
979
973
|
const rotatedValue = parseCookieFromHeader(rotatedCookieHeader, COOKIE_NAME);
|
|
980
974
|
if (!rotatedValue || rotatedValue === oldSessionCookie) return null;
|
|
975
|
+
return rotatedValue;
|
|
976
|
+
}
|
|
977
|
+
forwardRotatedCookie(rotatedValue, request) {
|
|
978
|
+
if (!request) return;
|
|
979
|
+
const rawRequest = getWebRequest(request);
|
|
980
|
+
if (!rawRequest) {
|
|
981
|
+
this.logger.warn("forwardRotatedCookie: renewed session cookie cannot be forwarded (no web Request)");
|
|
982
|
+
return;
|
|
983
|
+
}
|
|
981
984
|
const reissued = this.getSessionHeaders({
|
|
982
985
|
id: rotatedValue,
|
|
983
986
|
userId: "",
|
|
984
987
|
expiresAt: /* @__PURE__ */ new Date(),
|
|
985
988
|
createdAt: /* @__PURE__ */ new Date()
|
|
986
989
|
});
|
|
987
|
-
this.
|
|
988
|
-
|
|
989
|
-
const rawRequest = getWebRequest(request);
|
|
990
|
-
if (rawRequest) this.pendingResponseHeaders.set(rawRequest, reissued);
|
|
991
|
-
else this.logger.warn("captureRotatedCookie: renewed session cookie cannot be forwarded (no web Request)");
|
|
992
|
-
}
|
|
993
|
-
return rotatedValue;
|
|
990
|
+
this.pendingResponseHeaders.set(rawRequest, reissued);
|
|
991
|
+
this.renewedSessionCookies.set(rawRequest, rotatedValue);
|
|
994
992
|
}
|
|
995
993
|
/**
|
|
996
994
|
* Server middleware hook: emit any response headers the provider
|
|
@@ -1006,6 +1004,29 @@ var MastraAuthStudio = class extends MastraAuthProvider {
|
|
|
1006
1004
|
return headers;
|
|
1007
1005
|
}
|
|
1008
1006
|
/**
|
|
1007
|
+
* Call the shared API as the request's signed-in user. The shared API acts on the
|
|
1008
|
+
* session's active organization, not the pinned one. A renewed session cookie is
|
|
1009
|
+
* queued for {@link consumePendingResponseHeaders} and sent by later calls for the
|
|
1010
|
+
* same request. Returns `null` when the request has no session.
|
|
1011
|
+
*/
|
|
1012
|
+
async fetchAsRequestUser(request, path, init = {}) {
|
|
1013
|
+
const sessionCookie = this.renewedSessionCookies.get(request) ?? this.getSessionIdFromRequest(request);
|
|
1014
|
+
if (!sessionCookie) return null;
|
|
1015
|
+
const headers = new Headers(init.headers);
|
|
1016
|
+
headers.set("Cookie", `${COOKIE_NAME}=${sessionCookie}`);
|
|
1017
|
+
const res = await fetch(`${this.sharedApiUrl}${path}`, {
|
|
1018
|
+
...init,
|
|
1019
|
+
headers,
|
|
1020
|
+
signal: init.signal ?? AbortSignal.timeout(VERIFY_FETCH_TIMEOUT_MS)
|
|
1021
|
+
});
|
|
1022
|
+
const rotatedCookie = this.readRotatedCookie(res, sessionCookie);
|
|
1023
|
+
if (rotatedCookie) {
|
|
1024
|
+
this.verifiedCredentials.delete(await this.verificationKey("cookie", sessionCookie));
|
|
1025
|
+
this.forwardRotatedCookie(rotatedCookie, request);
|
|
1026
|
+
}
|
|
1027
|
+
return res;
|
|
1028
|
+
}
|
|
1029
|
+
/**
|
|
1009
1030
|
* Fetch the shared API's `/auth/me` and return the raw response body, or
|
|
1010
1031
|
* `null` on any non-OK / network error. Split out so `ensureOrganization`
|
|
1011
1032
|
* and `isOrganizationAdmin` can reuse it without duplicating the shape.
|
|
@@ -1033,22 +1054,38 @@ var MastraAuthStudio = class extends MastraAuthProvider {
|
|
|
1033
1054
|
this.rememberUserSession(cached.id, sessionCookie);
|
|
1034
1055
|
return cached;
|
|
1035
1056
|
}
|
|
1057
|
+
let verification = this.sessionVerificationsInFlight.get(cacheKey);
|
|
1058
|
+
if (!verification) {
|
|
1059
|
+
verification = this.doVerifySessionCookie(cacheKey, sessionCookie).finally(() => {
|
|
1060
|
+
this.sessionVerificationsInFlight.delete(cacheKey);
|
|
1061
|
+
});
|
|
1062
|
+
this.sessionVerificationsInFlight.set(cacheKey, verification);
|
|
1063
|
+
}
|
|
1064
|
+
const { user, rotatedCookie } = await verification;
|
|
1065
|
+
if (rotatedCookie) this.forwardRotatedCookie(rotatedCookie, request);
|
|
1066
|
+
if (user) this.rememberUserSession(user.id, rotatedCookie ?? sessionCookie);
|
|
1067
|
+
return user;
|
|
1068
|
+
}
|
|
1069
|
+
async doVerifySessionCookie(cacheKey, sessionCookie) {
|
|
1070
|
+
let rotatedCookie = null;
|
|
1036
1071
|
try {
|
|
1037
1072
|
const res = await fetch(`${this.sharedApiUrl}/auth/me`, {
|
|
1038
1073
|
headers: { Cookie: `${COOKIE_NAME}=${sessionCookie}` },
|
|
1039
1074
|
signal: AbortSignal.timeout(VERIFY_FETCH_TIMEOUT_MS)
|
|
1040
1075
|
});
|
|
1041
|
-
|
|
1076
|
+
rotatedCookie = this.readRotatedCookie(res, sessionCookie);
|
|
1042
1077
|
if (!res.ok) {
|
|
1043
1078
|
this.logger.warn("verifySessionCookie: shared API returned non-OK status", {
|
|
1044
1079
|
status: res.status,
|
|
1045
1080
|
statusText: res.statusText,
|
|
1046
1081
|
url: `${this.sharedApiUrl}/auth/me`
|
|
1047
1082
|
});
|
|
1048
|
-
return
|
|
1083
|
+
return {
|
|
1084
|
+
user: null,
|
|
1085
|
+
rotatedCookie
|
|
1086
|
+
};
|
|
1049
1087
|
}
|
|
1050
1088
|
const data = await res.json();
|
|
1051
|
-
this.rememberUserSession(data.user.id, rotated ?? sessionCookie);
|
|
1052
1089
|
const sessionUser = {
|
|
1053
1090
|
id: data.user.id,
|
|
1054
1091
|
email: data.user.email,
|
|
@@ -1059,9 +1096,12 @@ var MastraAuthStudio = class extends MastraAuthProvider {
|
|
|
1059
1096
|
permissions: data.permissions,
|
|
1060
1097
|
memberOrgIds: data.memberOrgIds
|
|
1061
1098
|
};
|
|
1062
|
-
const user = await this.asPinnedOrganizationMember(sessionUser, sessionCookie);
|
|
1063
|
-
if (user.organizationId && !
|
|
1064
|
-
return
|
|
1099
|
+
const user = await this.asPinnedOrganizationMember(sessionUser, rotatedCookie ?? sessionCookie);
|
|
1100
|
+
if (user.organizationId && !rotatedCookie) this.cacheVerification(cacheKey, user);
|
|
1101
|
+
return {
|
|
1102
|
+
user,
|
|
1103
|
+
rotatedCookie
|
|
1104
|
+
};
|
|
1065
1105
|
} catch (error) {
|
|
1066
1106
|
this.logger.error("verifySessionCookie: fetch to shared API failed", {
|
|
1067
1107
|
url: `${this.sharedApiUrl}/auth/me`,
|
|
@@ -1070,7 +1110,10 @@ var MastraAuthStudio = class extends MastraAuthProvider {
|
|
|
1070
1110
|
stack: error.stack
|
|
1071
1111
|
} : String(error)
|
|
1072
1112
|
});
|
|
1073
|
-
return
|
|
1113
|
+
return {
|
|
1114
|
+
user: null,
|
|
1115
|
+
rotatedCookie
|
|
1116
|
+
};
|
|
1074
1117
|
}
|
|
1075
1118
|
}
|
|
1076
1119
|
/**
|