@mastra/auth-cloud 0.0.1 → 1.1.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 +63 -0
- package/LICENSE.md +30 -0
- package/README.md +65 -1
- package/dist/auth-provider.d.ts +198 -0
- package/dist/auth-provider.d.ts.map +1 -0
- package/dist/client.d.ts +110 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/error.d.ts +65 -0
- package/dist/error.d.ts.map +1 -0
- package/dist/index.cjs +855 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +850 -0
- package/dist/index.js.map +1 -0
- package/dist/oauth/index.d.ts +9 -0
- package/dist/oauth/index.d.ts.map +1 -0
- package/dist/oauth/network.d.ts +20 -0
- package/dist/oauth/network.d.ts.map +1 -0
- package/dist/oauth/oauth.d.ts +68 -0
- package/dist/oauth/oauth.d.ts.map +1 -0
- package/dist/oauth/state.d.ts +47 -0
- package/dist/oauth/state.d.ts.map +1 -0
- package/dist/pkce/cookie.d.ts +42 -0
- package/dist/pkce/cookie.d.ts.map +1 -0
- package/dist/pkce/error.d.ts +31 -0
- package/dist/pkce/error.d.ts.map +1 -0
- package/dist/pkce/index.d.ts +10 -0
- package/dist/pkce/index.d.ts.map +1 -0
- package/dist/pkce/pkce.d.ts +26 -0
- package/dist/pkce/pkce.d.ts.map +1 -0
- package/dist/rbac/index.d.ts +2 -0
- package/dist/rbac/index.d.ts.map +1 -0
- package/dist/rbac/rbac-provider.d.ts +124 -0
- package/dist/rbac/rbac-provider.d.ts.map +1 -0
- package/dist/session/cookie.d.ts +32 -0
- package/dist/session/cookie.d.ts.map +1 -0
- package/dist/session/index.d.ts +9 -0
- package/dist/session/index.d.ts.map +1 -0
- package/dist/session/session.d.ts +56 -0
- package/dist/session/session.d.ts.map +1 -0
- package/dist/types.d.ts +64 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +54 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/session/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AACzG,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACvF,YAAY,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Session lifecycle functions.
|
|
3
|
+
* Handles token verification, session validation, and logout.
|
|
4
|
+
*
|
|
5
|
+
* @internal This module is not exported from the main package.
|
|
6
|
+
*/
|
|
7
|
+
import type { CloudSession, VerifyResponse } from '../types.js';
|
|
8
|
+
/**
|
|
9
|
+
* Options for verifyToken.
|
|
10
|
+
*/
|
|
11
|
+
export interface VerifyTokenOptions {
|
|
12
|
+
projectId: string;
|
|
13
|
+
cloudBaseUrl: string;
|
|
14
|
+
token: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Options for validateSession and destroySession.
|
|
18
|
+
*/
|
|
19
|
+
export interface SessionOptions {
|
|
20
|
+
projectId: string;
|
|
21
|
+
cloudBaseUrl: string;
|
|
22
|
+
sessionToken: string;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Verify an access token with Cloud API.
|
|
26
|
+
*
|
|
27
|
+
* @param options - Verification options
|
|
28
|
+
* @returns User and role information
|
|
29
|
+
* @throws AuthError with code 'verification_failed' if verification fails
|
|
30
|
+
* @throws AuthError with code 'network_error' if network request fails
|
|
31
|
+
*/
|
|
32
|
+
export declare function verifyToken(options: VerifyTokenOptions): Promise<VerifyResponse>;
|
|
33
|
+
/**
|
|
34
|
+
* Validate an existing session with Cloud API.
|
|
35
|
+
*
|
|
36
|
+
* @param options - Session options
|
|
37
|
+
* @returns Session data if valid, null otherwise
|
|
38
|
+
*/
|
|
39
|
+
export declare function validateSession(options: SessionOptions): Promise<CloudSession | null>;
|
|
40
|
+
/**
|
|
41
|
+
* Destroy a session with Cloud API.
|
|
42
|
+
* Note: X-Project-ID not required for this endpoint.
|
|
43
|
+
*
|
|
44
|
+
* @param options - Session options
|
|
45
|
+
*/
|
|
46
|
+
export declare function destroySession(options: SessionOptions): Promise<void>;
|
|
47
|
+
/**
|
|
48
|
+
* Get the logout URL for redirecting users.
|
|
49
|
+
*
|
|
50
|
+
* @param cloudBaseUrl - Cloud API base URL
|
|
51
|
+
* @param postLogoutRedirectUri - URL to redirect to after logout (required)
|
|
52
|
+
* @param idTokenHint - The access token (required by Cloud)
|
|
53
|
+
* @returns Full logout URL with redirect and token parameters
|
|
54
|
+
*/
|
|
55
|
+
export declare function getLogoutUrl(cloudBaseUrl: string, postLogoutRedirectUri: string, idTokenHint: string): string;
|
|
56
|
+
//# sourceMappingURL=session.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session.d.ts","sourceRoot":"","sources":["../../src/session/session.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAE7D;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;IACrB,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;CACtB;AAED;;;;;;;GAOG;AACH,wBAAsB,WAAW,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,cAAc,CAAC,CAqDtF;AAED;;;;;GAKG;AACH,wBAAsB,eAAe,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CAsB3F;AAED;;;;;GAKG;AACH,wBAAsB,cAAc,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAW3E;AAED;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,YAAY,EAAE,MAAM,EAAE,qBAAqB,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM,CAK7G"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core types for Mastra Cloud authentication.
|
|
3
|
+
*
|
|
4
|
+
* These types define the data structures used throughout
|
|
5
|
+
* the OAuth flow and session management.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Authenticated user from Mastra Cloud.
|
|
9
|
+
*/
|
|
10
|
+
export interface CloudUser {
|
|
11
|
+
/** Unique user identifier (or 'api-token' for project API tokens) */
|
|
12
|
+
id: string;
|
|
13
|
+
/** User's email address (undefined for project API tokens) */
|
|
14
|
+
email?: string;
|
|
15
|
+
/** User's display name */
|
|
16
|
+
name?: string;
|
|
17
|
+
/** URL to user's avatar image */
|
|
18
|
+
avatar?: string;
|
|
19
|
+
/** User's role from /verify endpoint (not JWT claims) */
|
|
20
|
+
role?: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Session data stored for an authenticated user.
|
|
24
|
+
*/
|
|
25
|
+
export interface CloudSession {
|
|
26
|
+
/** ID of the user this session belongs to */
|
|
27
|
+
userId: string;
|
|
28
|
+
/** Unix timestamp (ms) when session expires */
|
|
29
|
+
expiresAt: number;
|
|
30
|
+
/** Unix timestamp (ms) when session was created */
|
|
31
|
+
createdAt: number;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Response from the Cloud /verify endpoint.
|
|
35
|
+
*/
|
|
36
|
+
export interface VerifyResponse {
|
|
37
|
+
/** Authenticated user information */
|
|
38
|
+
user: CloudUser;
|
|
39
|
+
/** User's role in the organization */
|
|
40
|
+
role: string;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Result from processing OAuth callback.
|
|
44
|
+
*/
|
|
45
|
+
export interface CallbackResult {
|
|
46
|
+
/** Authenticated user information */
|
|
47
|
+
user: CloudUser;
|
|
48
|
+
/** Access token for API calls */
|
|
49
|
+
accessToken: string;
|
|
50
|
+
/** URL to redirect user to after login */
|
|
51
|
+
returnTo: string;
|
|
52
|
+
/** Cookies to set on response (session, clear PKCE, etc.) */
|
|
53
|
+
cookies: string[];
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Result from generating login URL.
|
|
57
|
+
*/
|
|
58
|
+
export interface LoginUrlResult {
|
|
59
|
+
/** Full authorization URL to redirect to */
|
|
60
|
+
url: string;
|
|
61
|
+
/** Cookies to set on response (PKCE state, etc.) */
|
|
62
|
+
cookies: string[];
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB,qEAAqE;IACrE,EAAE,EAAE,MAAM,CAAC;IACX,8DAA8D;IAC9D,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,0BAA0B;IAC1B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,iCAAiC;IACjC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,yDAAyD;IACzD,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,6CAA6C;IAC7C,MAAM,EAAE,MAAM,CAAC;IACf,+CAA+C;IAC/C,SAAS,EAAE,MAAM,CAAC;IAClB,mDAAmD;IACnD,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,qCAAqC;IACrC,IAAI,EAAE,SAAS,CAAC;IAChB,sCAAsC;IACtC,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,qCAAqC;IACrC,IAAI,EAAE,SAAS,CAAC;IAChB,iCAAiC;IACjC,WAAW,EAAE,MAAM,CAAC;IACpB,0CAA0C;IAC1C,QAAQ,EAAE,MAAM,CAAC;IACjB,6DAA6D;IAC7D,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,4CAA4C;IAC5C,GAAG,EAAE,MAAM,CAAC;IACZ,oDAAoD;IACpD,OAAO,EAAE,MAAM,EAAE,CAAC;CACnB"}
|
package/package.json
CHANGED
|
@@ -1,12 +1,63 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mastra/auth-cloud",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "Mastra Cloud
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"description": "Mastra Cloud authentication with PKCE OAuth",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"import": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"default": "./dist/index.js"
|
|
13
|
+
},
|
|
14
|
+
"require": {
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"default": "./dist/index.cjs"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
19
|
+
"./package.json": "./package.json"
|
|
20
|
+
},
|
|
5
21
|
"license": "Apache-2.0",
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@mastra/auth": "1.0.0"
|
|
24
|
+
},
|
|
25
|
+
"peerDependencies": {
|
|
26
|
+
"@mastra/core": ">=1.0.0-0 <2.0.0-0"
|
|
27
|
+
},
|
|
28
|
+
"devDependencies": {
|
|
29
|
+
"@types/node": "22.19.7",
|
|
30
|
+
"hono": "^4.11.9",
|
|
31
|
+
"@vitest/coverage-v8": "4.0.18",
|
|
32
|
+
"@vitest/ui": "4.0.18",
|
|
33
|
+
"eslint": "^9.37.0",
|
|
34
|
+
"tsup": "^8.5.1",
|
|
35
|
+
"typescript": "^5.9.3",
|
|
36
|
+
"vitest": "4.0.18",
|
|
37
|
+
"@internal/types-builder": "0.0.39",
|
|
38
|
+
"@internal/lint": "0.0.64",
|
|
39
|
+
"@mastra/core": "1.9.0"
|
|
40
|
+
},
|
|
41
|
+
"files": [
|
|
42
|
+
"dist",
|
|
43
|
+
"CHANGELOG.md"
|
|
44
|
+
],
|
|
6
45
|
"homepage": "https://mastra.ai",
|
|
7
46
|
"repository": {
|
|
8
47
|
"type": "git",
|
|
9
48
|
"url": "git+https://github.com/mastra-ai/mastra.git",
|
|
10
49
|
"directory": "auth/cloud"
|
|
50
|
+
},
|
|
51
|
+
"bugs": {
|
|
52
|
+
"url": "https://github.com/mastra-ai/mastra/issues"
|
|
53
|
+
},
|
|
54
|
+
"engines": {
|
|
55
|
+
"node": ">=22.13.0"
|
|
56
|
+
},
|
|
57
|
+
"scripts": {
|
|
58
|
+
"build": "tsup --silent --config tsup.config.ts",
|
|
59
|
+
"build:watch": "tsup --watch --silent --config tsup.config.ts",
|
|
60
|
+
"test": "vitest run",
|
|
61
|
+
"lint": "eslint ."
|
|
11
62
|
}
|
|
12
|
-
}
|
|
63
|
+
}
|