@mastra/auth-cloud 1.2.7 → 1.2.8-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/dist/_types/@internal_auth/dist/_types/@internal_core/dist/base/index.d.ts +2 -5
- package/dist/_types/@internal_auth/dist/_types/@internal_core/dist/{index-Biaf3BmX.d.ts → index-TNVgGNjs.d.ts} +1 -5
- package/dist/_types/@internal_auth/dist/session/index.d.ts +9 -0
- package/dist/index.cjs +18 -35
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +18 -35
- package/dist/index.js.map +1 -1
- package/package.json +9 -9
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createHash } from "crypto";
|
|
2
|
-
|
|
2
|
+
// src/error.ts
|
|
3
3
|
/**
|
|
4
4
|
* Error class for authentication-related failures.
|
|
5
5
|
* Uses a code discriminator for programmatic error handling.
|
|
@@ -74,8 +74,7 @@ var AuthError = class AuthError extends Error {
|
|
|
74
74
|
return new AuthError("cloud_api_error", message, options);
|
|
75
75
|
}
|
|
76
76
|
};
|
|
77
|
-
|
|
78
|
-
//#region src/oauth/state.ts
|
|
77
|
+
// src/oauth/state.ts
|
|
79
78
|
/**
|
|
80
79
|
* OAuth state parameter encoding/decoding.
|
|
81
80
|
*
|
|
@@ -137,8 +136,7 @@ function validateReturnTo(returnTo, requestOrigin) {
|
|
|
137
136
|
} catch {}
|
|
138
137
|
return "/";
|
|
139
138
|
}
|
|
140
|
-
|
|
141
|
-
//#region src/oauth/network.ts
|
|
139
|
+
// src/oauth/network.ts
|
|
142
140
|
/**
|
|
143
141
|
* Network utilities for OAuth flow.
|
|
144
142
|
*
|
|
@@ -168,8 +166,7 @@ async function fetchWithRetry(url, options) {
|
|
|
168
166
|
}
|
|
169
167
|
}
|
|
170
168
|
}
|
|
171
|
-
|
|
172
|
-
//#region src/pkce/error.ts
|
|
169
|
+
// src/pkce/error.ts
|
|
173
170
|
/**
|
|
174
171
|
* Error class for PKCE-related failures.
|
|
175
172
|
* Uses a code discriminator for programmatic error handling.
|
|
@@ -203,8 +200,7 @@ var PKCEError = class PKCEError extends Error {
|
|
|
203
200
|
return new PKCEError("INVALID", "PKCE verifier cookie is malformed or invalid.", cause);
|
|
204
201
|
}
|
|
205
202
|
};
|
|
206
|
-
|
|
207
|
-
//#region src/pkce/cookie.ts
|
|
203
|
+
// src/pkce/cookie.ts
|
|
208
204
|
/**
|
|
209
205
|
* PKCE cookie storage utilities.
|
|
210
206
|
* Handles serialization, parsing, and clearing of PKCE verifier cookies.
|
|
@@ -263,8 +259,7 @@ function parsePKCECookie(cookieHeader) {
|
|
|
263
259
|
function clearPKCECookie() {
|
|
264
260
|
return `${PKCE_COOKIE_NAME}=; HttpOnly; SameSite=Lax; Path=/; Max-Age=0`;
|
|
265
261
|
}
|
|
266
|
-
|
|
267
|
-
//#region src/pkce/pkce.ts
|
|
262
|
+
// src/pkce/pkce.ts
|
|
268
263
|
/**
|
|
269
264
|
* PKCE (Proof Key for Code Exchange) cryptographic utilities.
|
|
270
265
|
* Implements RFC 7636 S256 challenge method.
|
|
@@ -296,8 +291,7 @@ function computeCodeChallenge(verifier) {
|
|
|
296
291
|
function generateState() {
|
|
297
292
|
return Buffer.from(globalThis.crypto.getRandomValues(/* @__PURE__ */ new Uint8Array(16))).toString("base64url");
|
|
298
293
|
}
|
|
299
|
-
|
|
300
|
-
//#region src/oauth/oauth.ts
|
|
294
|
+
// src/oauth/oauth.ts
|
|
301
295
|
/**
|
|
302
296
|
* OAuth authorization flow functions.
|
|
303
297
|
*
|
|
@@ -400,8 +394,7 @@ async function handleCallback(options) {
|
|
|
400
394
|
cookies: [clearCookie]
|
|
401
395
|
};
|
|
402
396
|
}
|
|
403
|
-
|
|
404
|
-
//#region src/session/cookie.ts
|
|
397
|
+
// src/session/cookie.ts
|
|
405
398
|
/**
|
|
406
399
|
* Session cookie utilities.
|
|
407
400
|
* Handles setting, parsing, and clearing of session cookies.
|
|
@@ -442,8 +435,7 @@ function parseSessionCookie(cookieHeader) {
|
|
|
442
435
|
function clearSessionCookie() {
|
|
443
436
|
return `${SESSION_COOKIE_NAME}=; HttpOnly; SameSite=Lax; Path=/; Max-Age=0`;
|
|
444
437
|
}
|
|
445
|
-
|
|
446
|
-
//#region src/session/session.ts
|
|
438
|
+
// src/session/session.ts
|
|
447
439
|
/**
|
|
448
440
|
* Session lifecycle functions.
|
|
449
441
|
* Handles token verification, session validation, and logout.
|
|
@@ -538,8 +530,7 @@ function getLogoutUrl(cloudBaseUrl, postLogoutRedirectUri, idTokenHint) {
|
|
|
538
530
|
url.searchParams.set("id_token_hint", idTokenHint);
|
|
539
531
|
return url.toString();
|
|
540
532
|
}
|
|
541
|
-
|
|
542
|
-
//#region src/client.ts
|
|
533
|
+
// src/client.ts
|
|
543
534
|
/**
|
|
544
535
|
* MastraCloudAuth client class.
|
|
545
536
|
* Facade composing OAuth and session modules into unified API.
|
|
@@ -670,8 +661,7 @@ var MastraCloudAuth = class {
|
|
|
670
661
|
return clearSessionCookie();
|
|
671
662
|
}
|
|
672
663
|
};
|
|
673
|
-
|
|
674
|
-
//#region ../../packages/_internals/auth/dist/types/index.js
|
|
664
|
+
// ../../packages/_internals/auth/dist/types/index.js
|
|
675
665
|
function headerFromPlainObject(headers, name) {
|
|
676
666
|
const normalizedName = name.toLowerCase();
|
|
677
667
|
const matchingKey = Object.keys(headers).find((key) => key.toLowerCase() === normalizedName);
|
|
@@ -691,8 +681,7 @@ function getRequestHeader(request, name) {
|
|
|
691
681
|
if (headers && typeof headers === "object") return headerFromPlainObject(headers, name);
|
|
692
682
|
return null;
|
|
693
683
|
}
|
|
694
|
-
|
|
695
|
-
//#region ../../packages/_internal-core/dist/logger/index.js
|
|
684
|
+
// ../../packages/_internal-core/dist/logger/index.js
|
|
696
685
|
/**
|
|
697
686
|
* Export a tracked exception through the adapter sink, mirroring the
|
|
698
687
|
* DualLogger dual-write shape (`errorId`/`domain`/`category`/`details`/`cause`
|
|
@@ -925,8 +914,7 @@ var ConsoleLogger = class ConsoleLogger extends MastraLogger {
|
|
|
925
914
|
};
|
|
926
915
|
}
|
|
927
916
|
};
|
|
928
|
-
|
|
929
|
-
//#region ../../packages/_internal-core/dist/base/index.js
|
|
917
|
+
// ../../packages/_internal-core/dist/base/index.js
|
|
930
918
|
var MastraBase = class {
|
|
931
919
|
component = RegisteredLogger.LLM;
|
|
932
920
|
logger;
|
|
@@ -960,8 +948,7 @@ var MastraBase = class {
|
|
|
960
948
|
this.logger = "child" in logger && typeof logger.child === "function" ? logger.child({ component: this.component }) : logger;
|
|
961
949
|
}
|
|
962
950
|
};
|
|
963
|
-
|
|
964
|
-
//#region ../../packages/_internals/auth/dist/provider/index.js
|
|
951
|
+
// ../../packages/_internals/auth/dist/provider/index.js
|
|
965
952
|
var MastraAuthProvider = class extends MastraBase {
|
|
966
953
|
protected;
|
|
967
954
|
public;
|
|
@@ -973,7 +960,7 @@ var MastraAuthProvider = class extends MastraBase {
|
|
|
973
960
|
if (options?.authorizeUser) this.authorizeUser = options.authorizeUser.bind(this);
|
|
974
961
|
this.protected = options?.protected;
|
|
975
962
|
this.public = options?.public;
|
|
976
|
-
this.mapUserToResourceId = options
|
|
963
|
+
if (options?.mapUserToResourceId) this.mapUserToResourceId = options.mapUserToResourceId;
|
|
977
964
|
}
|
|
978
965
|
registerOptions(opts) {
|
|
979
966
|
if (opts?.authorizeUser) this.authorizeUser = opts.authorizeUser.bind(this);
|
|
@@ -982,8 +969,7 @@ var MastraAuthProvider = class extends MastraBase {
|
|
|
982
969
|
if (opts?.public) this.public = opts.public;
|
|
983
970
|
}
|
|
984
971
|
};
|
|
985
|
-
|
|
986
|
-
//#region ../../packages/_internals/auth/dist/ee-XRuijAiF.js
|
|
972
|
+
// ../../packages/_internals/auth/dist/ee-CnZdF0Vm.js
|
|
987
973
|
/**
|
|
988
974
|
* FGA enforcement utility for checking fine-grained authorization.
|
|
989
975
|
*
|
|
@@ -1092,8 +1078,7 @@ function resolvePermissionsFromMapping(roles, mapping) {
|
|
|
1092
1078
|
* @license Mastra Enterprise License - see ee/LICENSE
|
|
1093
1079
|
* @packageDocumentation
|
|
1094
1080
|
*/
|
|
1095
|
-
|
|
1096
|
-
//#region src/auth-provider.ts
|
|
1081
|
+
// src/auth-provider.ts
|
|
1097
1082
|
/**
|
|
1098
1083
|
* Mastra Cloud authentication provider for server integration.
|
|
1099
1084
|
*
|
|
@@ -1394,8 +1379,7 @@ var MastraCloudAuthProvider = class extends MastraAuthProvider {
|
|
|
1394
1379
|
return null;
|
|
1395
1380
|
}
|
|
1396
1381
|
};
|
|
1397
|
-
|
|
1398
|
-
//#region src/rbac/rbac-provider.ts
|
|
1382
|
+
// src/rbac/rbac-provider.ts
|
|
1399
1383
|
/**
|
|
1400
1384
|
* RBAC provider for Mastra Cloud authentication.
|
|
1401
1385
|
*
|
|
@@ -1512,7 +1496,6 @@ var MastraRBACCloud = class {
|
|
|
1512
1496
|
return permissions.some((required) => userPermissions.some((p) => matchesPermission(p, required)));
|
|
1513
1497
|
}
|
|
1514
1498
|
};
|
|
1515
|
-
//#endregion
|
|
1516
1499
|
export { AuthError, MastraCloudAuth, MastraCloudAuthProvider, MastraRBACCloud };
|
|
1517
1500
|
|
|
1518
1501
|
//# sourceMappingURL=index.js.map
|