@mastra/auth-studio 1.3.12-alpha.0 → 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/index.cjs +26 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +26 -0
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -539,6 +539,8 @@ var MastraAuthStudio = class extends MastraAuthProvider {
|
|
|
539
539
|
* requests after the response is written.
|
|
540
540
|
*/
|
|
541
541
|
pendingResponseHeaders = /* @__PURE__ */ new WeakMap();
|
|
542
|
+
/** The request's current sealed cookie once a shared API call renewed it: the inbound one's refresh token is spent. */
|
|
543
|
+
renewedSessionCookies = /* @__PURE__ */ new WeakMap();
|
|
542
544
|
constructor(options) {
|
|
543
545
|
super({
|
|
544
546
|
name: "mastra-studio",
|
|
@@ -987,6 +989,7 @@ var MastraAuthStudio = class extends MastraAuthProvider {
|
|
|
987
989
|
createdAt: /* @__PURE__ */ new Date()
|
|
988
990
|
});
|
|
989
991
|
this.pendingResponseHeaders.set(rawRequest, reissued);
|
|
992
|
+
this.renewedSessionCookies.set(rawRequest, rotatedValue);
|
|
990
993
|
}
|
|
991
994
|
/**
|
|
992
995
|
* Server middleware hook: emit any response headers the provider
|
|
@@ -1002,6 +1005,29 @@ var MastraAuthStudio = class extends MastraAuthProvider {
|
|
|
1002
1005
|
return headers;
|
|
1003
1006
|
}
|
|
1004
1007
|
/**
|
|
1008
|
+
* Call the shared API as the request's signed-in user. The shared API acts on the
|
|
1009
|
+
* session's active organization, not the pinned one. A renewed session cookie is
|
|
1010
|
+
* queued for {@link consumePendingResponseHeaders} and sent by later calls for the
|
|
1011
|
+
* same request. Returns `null` when the request has no session.
|
|
1012
|
+
*/
|
|
1013
|
+
async fetchAsRequestUser(request, path, init = {}) {
|
|
1014
|
+
const sessionCookie = this.renewedSessionCookies.get(request) ?? this.getSessionIdFromRequest(request);
|
|
1015
|
+
if (!sessionCookie) return null;
|
|
1016
|
+
const headers = new Headers(init.headers);
|
|
1017
|
+
headers.set("Cookie", `${COOKIE_NAME}=${sessionCookie}`);
|
|
1018
|
+
const res = await fetch(`${this.sharedApiUrl}${path}`, {
|
|
1019
|
+
...init,
|
|
1020
|
+
headers,
|
|
1021
|
+
signal: init.signal ?? AbortSignal.timeout(VERIFY_FETCH_TIMEOUT_MS)
|
|
1022
|
+
});
|
|
1023
|
+
const rotatedCookie = this.readRotatedCookie(res, sessionCookie);
|
|
1024
|
+
if (rotatedCookie) {
|
|
1025
|
+
this.verifiedCredentials.delete(await this.verificationKey("cookie", sessionCookie));
|
|
1026
|
+
this.forwardRotatedCookie(rotatedCookie, request);
|
|
1027
|
+
}
|
|
1028
|
+
return res;
|
|
1029
|
+
}
|
|
1030
|
+
/**
|
|
1005
1031
|
* Fetch the shared API's `/auth/me` and return the raw response body, or
|
|
1006
1032
|
* `null` on any non-OK / network error. Split out so `ensureOrganization`
|
|
1007
1033
|
* and `isOrganizationAdmin` can reuse it without duplicating the shape.
|