@mastra/auth-cloud 0.0.0-auth-rbac-cms-20260211172515

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.
Files changed (44) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/LICENSE.md +15 -0
  3. package/README.md +67 -0
  4. package/dist/auth-provider.d.ts +197 -0
  5. package/dist/auth-provider.d.ts.map +1 -0
  6. package/dist/client.d.ts +110 -0
  7. package/dist/client.d.ts.map +1 -0
  8. package/dist/error.d.ts +65 -0
  9. package/dist/error.d.ts.map +1 -0
  10. package/dist/index.cjs +855 -0
  11. package/dist/index.cjs.map +1 -0
  12. package/dist/index.d.ts +19 -0
  13. package/dist/index.d.ts.map +1 -0
  14. package/dist/index.js +850 -0
  15. package/dist/index.js.map +1 -0
  16. package/dist/oauth/index.d.ts +9 -0
  17. package/dist/oauth/index.d.ts.map +1 -0
  18. package/dist/oauth/network.d.ts +20 -0
  19. package/dist/oauth/network.d.ts.map +1 -0
  20. package/dist/oauth/oauth.d.ts +68 -0
  21. package/dist/oauth/oauth.d.ts.map +1 -0
  22. package/dist/oauth/state.d.ts +47 -0
  23. package/dist/oauth/state.d.ts.map +1 -0
  24. package/dist/pkce/cookie.d.ts +42 -0
  25. package/dist/pkce/cookie.d.ts.map +1 -0
  26. package/dist/pkce/error.d.ts +31 -0
  27. package/dist/pkce/error.d.ts.map +1 -0
  28. package/dist/pkce/index.d.ts +10 -0
  29. package/dist/pkce/index.d.ts.map +1 -0
  30. package/dist/pkce/pkce.d.ts +26 -0
  31. package/dist/pkce/pkce.d.ts.map +1 -0
  32. package/dist/rbac/index.d.ts +2 -0
  33. package/dist/rbac/index.d.ts.map +1 -0
  34. package/dist/rbac/rbac-provider.d.ts +124 -0
  35. package/dist/rbac/rbac-provider.d.ts.map +1 -0
  36. package/dist/session/cookie.d.ts +32 -0
  37. package/dist/session/cookie.d.ts.map +1 -0
  38. package/dist/session/index.d.ts +9 -0
  39. package/dist/session/index.d.ts.map +1 -0
  40. package/dist/session/session.d.ts +56 -0
  41. package/dist/session/session.d.ts.map +1 -0
  42. package/dist/types.d.ts +64 -0
  43. package/dist/types.d.ts.map +1 -0
  44. package/package.json +63 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,9 @@
1
+ # @mastra/auth-cloud
2
+
3
+ ## 0.0.0-auth-rbac-cms-20260211172515
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [[`717ffab`](https://github.com/mastra-ai/mastra/commit/717ffab42cfd58ff723b5c19ada4939997773004), [`5719fa8`](https://github.com/mastra-ai/mastra/commit/5719fa8880e86e8affe698ec4b3807c7e0e0a06f), [`83cda45`](https://github.com/mastra-ai/mastra/commit/83cda4523e588558466892bff8f80f631a36945a), [`aa95f95`](https://github.com/mastra-ai/mastra/commit/aa95f958b186ae5c9f4219c88e268f5565c277a2), [`90f7894`](https://github.com/mastra-ai/mastra/commit/90f7894568dc9481f40a4d29672234fae23090bb), [`8109aee`](https://github.com/mastra-ai/mastra/commit/8109aeeab758e16cd4255a6c36f044b70eefc6a6), [`fdad759`](https://github.com/mastra-ai/mastra/commit/fdad75939ff008b27625f5ec0ce9c6915d99d9ec), [`e4569c5`](https://github.com/mastra-ai/mastra/commit/e4569c589e00c4061a686c9eb85afe1b7050b0a8), [`7309a85`](https://github.com/mastra-ai/mastra/commit/7309a85427281a8be23f4fb80ca52e18eaffd596), [`99424f6`](https://github.com/mastra-ai/mastra/commit/99424f6862ffb679c4ec6765501486034754a4c2), [`a211248`](https://github.com/mastra-ai/mastra/commit/a21124845b1b1321b6075a8377c341c7f5cda1b6), [`8c1135d`](https://github.com/mastra-ai/mastra/commit/8c1135dfb91b057283eae7ee11f9ec28753cc64f)]:
8
+ - @mastra/core@0.0.0-auth-rbac-cms-20260211172515
9
+ - @mastra/auth@1.0.0
package/LICENSE.md ADDED
@@ -0,0 +1,15 @@
1
+ # Apache License 2.0
2
+
3
+ Copyright (c) 2025 Kepler Software, Inc.
4
+
5
+ Licensed under the Apache License, Version 2.0 (the "License");
6
+ you may not use this file except in compliance with the License.
7
+ You may obtain a copy of the License at
8
+
9
+ http://www.apache.org/licenses/LICENSE-2.0
10
+
11
+ Unless required by applicable law or agreed to in writing, software
12
+ distributed under the License is distributed on an "AS IS" BASIS,
13
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ See the License for the specific language governing permissions and
15
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,67 @@
1
+ # @mastra/auth-cloud
2
+
3
+ Mastra Cloud authentication provider with PKCE OAuth flow.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pnpm add @mastra/auth-cloud
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```typescript
14
+ import { Mastra } from '@mastra/core/mastra';
15
+ import { MastraCloudAuth } from '@mastra/auth-cloud';
16
+
17
+ const auth = new MastraCloudAuth({
18
+ projectId: process.env.MASTRA_PROJECT_ID!,
19
+ // Optional: defaults to https://cloud.mastra.ai
20
+ baseUrl: process.env.MASTRA_CLOUD_URL,
21
+ // Optional: defaults to /auth/callback
22
+ redirectPath: '/auth/callback',
23
+ });
24
+
25
+ const mastra = new Mastra({
26
+ server: {
27
+ auth,
28
+ },
29
+ });
30
+ ```
31
+
32
+ ## Configuration
33
+
34
+ | Option | Required | Default | Description |
35
+ | -------------- | -------- | ------------------------- | ---------------------------------- |
36
+ | `projectId` | Yes | - | Project ID from cloud.mastra.ai |
37
+ | `baseUrl` | No | `https://cloud.mastra.ai` | Mastra Cloud base URL |
38
+ | `redirectPath` | No | `/auth/callback` | OAuth callback path |
39
+ | `cookieName` | No | `mastra_session` | Session cookie name |
40
+
41
+ ## Authentication Flow
42
+
43
+ This package implements PKCE OAuth flow with Mastra Cloud:
44
+
45
+ 1. User clicks login, redirected to Mastra Cloud with code challenge
46
+ 2. User authenticates via Mastra Cloud (GitHub OAuth)
47
+ 3. Mastra Cloud redirects back with authorization code
48
+ 4. Package exchanges code + verifier for session token
49
+ 5. Session token stored in HttpOnly cookie
50
+
51
+ ## API
52
+
53
+ ### `MastraCloudAuth`
54
+
55
+ The main authentication provider class implementing `MastraAuthProvider`.
56
+
57
+ ### Methods
58
+
59
+ - `getLoginUrl(state?)` - Get OAuth login URL with PKCE
60
+ - `handleCallback(code, verifier)` - Exchange code for session
61
+ - `verifyToken(token)` - Verify session and get user with role
62
+ - `refreshSession(token)` - Refresh expiring session
63
+ - `logout(token)` - Invalidate session
64
+
65
+ ## License
66
+
67
+ Apache-2.0
@@ -0,0 +1,197 @@
1
+ /**
2
+ * MastraCloudAuthProvider - Server integration for Mastra Cloud authentication.
3
+ *
4
+ * Extends MastraAuthProvider and implements ISSOProvider, ISessionProvider,
5
+ * and IUserProvider interfaces to integrate with Mastra server middleware.
6
+ *
7
+ * @packageDocumentation
8
+ */
9
+ import type { IUserProvider, ISSOProvider, ISessionProvider, EEUser, Session, SSOCallbackResult, SSOLoginConfig } from '@mastra/core/auth';
10
+ import type { MastraAuthProviderOptions } from '@mastra/core/server';
11
+ import { MastraAuthProvider } from '@mastra/core/server';
12
+ import type { HonoRequest } from 'hono';
13
+ import type { CloudUser } from './types.js';
14
+ /**
15
+ * Configuration options for MastraCloudAuthProvider.
16
+ */
17
+ export interface MastraCloudAuthProviderOptions extends MastraAuthProviderOptions<CloudUser> {
18
+ /** Mastra Cloud project ID */
19
+ projectId: string;
20
+ /** Base URL of Mastra Cloud API (e.g., https://cloud.mastra.ai) */
21
+ cloudBaseUrl: string;
22
+ /** OAuth callback URL for your application */
23
+ callbackUrl: string;
24
+ /** Whether running in production (adds Secure flag to cookies) */
25
+ isProduction?: boolean;
26
+ }
27
+ /**
28
+ * Mastra Cloud authentication provider for server integration.
29
+ *
30
+ * Wraps the MastraCloudAuth client and implements the required interfaces
31
+ * for Mastra server middleware. Provides SSO login, session management,
32
+ * and user awareness.
33
+ *
34
+ * @example
35
+ * ```typescript
36
+ * import { MastraCloudAuthProvider } from '@mastra/auth-cloud';
37
+ *
38
+ * const auth = new MastraCloudAuthProvider({
39
+ * cloudBaseUrl: 'https://cloud.mastra.ai',
40
+ * callbackUrl: 'https://myapp.com/auth/callback',
41
+ * });
42
+ *
43
+ * const mastra = new Mastra({
44
+ * auth,
45
+ * // ...
46
+ * });
47
+ * ```
48
+ */
49
+ export declare class MastraCloudAuthProvider extends MastraAuthProvider<CloudUser> implements IUserProvider<EEUser>, ISSOProvider<EEUser>, ISessionProvider<Session> {
50
+ private client;
51
+ /** Marker for EE license exemption - MastraCloudAuth is exempt */
52
+ readonly isMastraCloudAuth = true;
53
+ /**
54
+ * Cookie header for handleCallback PKCE validation.
55
+ * Set via setCallbackCookieHeader() before handleCallback() is called.
56
+ * @internal
57
+ */
58
+ private _lastCallbackCookieHeader;
59
+ constructor(options: MastraCloudAuthProviderOptions);
60
+ /**
61
+ * Set cookie header for handleCallback PKCE validation.
62
+ * Must be called before handleCallback() to pass cookie header.
63
+ *
64
+ * @param cookieHeader - Cookie header from original request
65
+ */
66
+ setCallbackCookieHeader(cookieHeader: string | null): void;
67
+ /**
68
+ * Authenticate a bearer token or session cookie.
69
+ *
70
+ * Checks session cookie first, falls back to bearer token for API clients.
71
+ *
72
+ * @param token - Bearer token (from Authorization header)
73
+ * @param request - Hono or raw Request
74
+ * @returns Authenticated user with role, or null if invalid
75
+ */
76
+ authenticateToken(token: string, request: HonoRequest | Request): Promise<CloudUser | null>;
77
+ /**
78
+ * Authorize a user for access.
79
+ *
80
+ * Simple validation - detailed permission checking happens in server
81
+ * middleware via checkRoutePermission(), not authorizeUser().
82
+ *
83
+ * @param user - Authenticated user
84
+ * @returns True if user has valid id
85
+ */
86
+ authorizeUser(user: CloudUser): boolean;
87
+ /**
88
+ * Cached login result for getLoginCookies() to retrieve cookies.
89
+ * @internal
90
+ */
91
+ private _lastLoginResult;
92
+ /**
93
+ * Get URL to redirect user to for SSO login.
94
+ *
95
+ * @param redirectUri - Callback URL after authentication
96
+ * @param state - State parameter (format: uuid|encodedPostLoginRedirect)
97
+ * @returns Full authorization URL
98
+ */
99
+ getLoginUrl(redirectUri: string, state: string): string;
100
+ /**
101
+ * Get cookies to set during login redirect (PKCE verifier).
102
+ * Must be called after getLoginUrl() in same request.
103
+ *
104
+ * @returns Array of Set-Cookie header values
105
+ */
106
+ getLoginCookies(): string[] | undefined;
107
+ /**
108
+ * Handle OAuth callback, exchange code for tokens and user.
109
+ *
110
+ * @param code - Authorization code from callback
111
+ * @param state - State parameter for CSRF validation
112
+ * @returns User, tokens, and session cookies
113
+ */
114
+ handleCallback(code: string, state: string): Promise<SSOCallbackResult<EEUser>>;
115
+ /**
116
+ * Get configuration for rendering login button in UI.
117
+ *
118
+ * @returns Login button configuration
119
+ */
120
+ getLoginButtonConfig(): SSOLoginConfig;
121
+ /**
122
+ * Get logout URL for client-side redirect.
123
+ * Requires the request to extract the session token for id_token_hint.
124
+ *
125
+ * @param redirectUri - URL to redirect to after logout
126
+ * @param request - Request to extract session token from
127
+ * @returns Logout URL with redirect and token parameters, or null if no session
128
+ */
129
+ getLogoutUrl(redirectUri: string, request?: Request): string | null;
130
+ /**
131
+ * Create a new session for a user.
132
+ *
133
+ * For Cloud auth, sessions are created via handleCallback.
134
+ * This method builds a Session object for interface compatibility.
135
+ *
136
+ * @param userId - User to create session for
137
+ * @param metadata - Optional metadata (accessToken can be passed here)
138
+ * @returns Session object
139
+ */
140
+ createSession(userId: string, metadata?: Record<string, unknown>): Promise<Session>;
141
+ /**
142
+ * Validate a session and return it if valid.
143
+ *
144
+ * @param sessionId - Session token to validate
145
+ * @returns Session object or null if invalid/expired
146
+ */
147
+ validateSession(sessionId: string): Promise<Session | null>;
148
+ /**
149
+ * Destroy a session (logout).
150
+ *
151
+ * @param sessionId - Session token to destroy
152
+ */
153
+ destroySession(sessionId: string): Promise<void>;
154
+ /**
155
+ * Refresh a session, extending its expiry.
156
+ * Cloud handles refresh internally, so just validate.
157
+ *
158
+ * @param sessionId - Session token to refresh
159
+ * @returns Session object or null if invalid
160
+ */
161
+ refreshSession(sessionId: string): Promise<Session | null>;
162
+ /**
163
+ * Extract session ID from an incoming request.
164
+ *
165
+ * @param request - Incoming HTTP request
166
+ * @returns Session token or null if not present
167
+ */
168
+ getSessionIdFromRequest(request: Request): string | null;
169
+ /**
170
+ * Create response headers to set session cookie.
171
+ *
172
+ * @param session - Session to encode (id is the access token)
173
+ * @returns Headers object with Set-Cookie
174
+ */
175
+ getSessionHeaders(session: Session): Record<string, string>;
176
+ /**
177
+ * Create response headers to clear session (for logout).
178
+ *
179
+ * @returns Headers object to clear session cookie
180
+ */
181
+ getClearSessionHeaders(): Record<string, string>;
182
+ /**
183
+ * Get current user from request (session cookie).
184
+ *
185
+ * @param request - Incoming HTTP request
186
+ * @returns User with role or null if not authenticated
187
+ */
188
+ getCurrentUser(request: Request): Promise<CloudUser | null>;
189
+ /**
190
+ * Get user by ID.
191
+ * Cloud API doesn't have a /users/:id endpoint.
192
+ *
193
+ * @returns Always null (not supported)
194
+ */
195
+ getUser(_userId: string): Promise<CloudUser | null>;
196
+ }
197
+ //# sourceMappingURL=auth-provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth-provider.d.ts","sourceRoot":"","sources":["../src/auth-provider.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EACV,aAAa,EACb,YAAY,EACZ,gBAAgB,EAChB,MAAM,EACN,OAAO,EACP,iBAAiB,EACjB,cAAc,EACf,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AACrE,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AACzD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,MAAM,CAAC;AAIxC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEzC;;GAEG;AACH,MAAM,WAAW,8BAA+B,SAAQ,yBAAyB,CAAC,SAAS,CAAC;IAC1F,8BAA8B;IAC9B,SAAS,E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C,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI;IAanE;;;;;;;;;OASG;IACG,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC;IAazF;;;;;OAKG;IACG,eAAe,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC;IAYjE;;;;OAIG;IACG,cAAc,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAItD;;;;;;OAMG;IACG,cAAc,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC;IAIhE;;;;;OAKG;IACH,uBAAuB,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI;IAIxD;;;;;OAKG;IACH,iBAAiB,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IAI3D;;;;OAIG;IACH,sBAAsB,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC;IAQhD;;;;;OAKG;IACG,cAAc,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC;IAYjE;;;;;OAKG;IACG,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC;CAG1D"}
@@ -0,0 +1,110 @@
1
+ /**
2
+ * MastraCloudAuth client class.
3
+ * Facade composing OAuth and session modules into unified API.
4
+ */
5
+ import type { LoginUrlResult, CallbackResult, VerifyResponse, CloudSession } from './types.js';
6
+ /**
7
+ * Configuration for MastraCloudAuth client.
8
+ */
9
+ export interface MastraCloudAuthConfig {
10
+ /** Mastra Cloud project ID */
11
+ projectId: string;
12
+ /** Base URL of the Cloud API (e.g., https://cloud.mastra.ai) */
13
+ cloudBaseUrl: string;
14
+ /** OAuth callback URL for your application */
15
+ callbackUrl: string;
16
+ /** Whether running in production (adds Secure flag to cookies) */
17
+ isProduction?: boolean;
18
+ }
19
+ /**
20
+ * Mastra Cloud authentication client.
21
+ *
22
+ * Provides unified API for OAuth flow and session management.
23
+ *
24
+ * @example
25
+ * ```typescript
26
+ * const auth = new MastraCloudAuth({
27
+ * cloudBaseUrl: 'https://cloud.mastra.ai',
28
+ * callbackUrl: 'https://myapp.com/auth/callback',
29
+ * });
30
+ *
31
+ * // Start login flow
32
+ * const { url, cookies } = auth.getLoginUrl({
33
+ * requestOrigin: 'https://myapp.com',
34
+ * });
35
+ *
36
+ * // After callback
37
+ * const result = await auth.handleCallback({
38
+ * code: 'auth_code',
39
+ * state: 'state_param',
40
+ * cookieHeader: request.headers.get('cookie'),
41
+ * });
42
+ * ```
43
+ */
44
+ export declare class MastraCloudAuth {
45
+ private readonly config;
46
+ constructor(config: MastraCloudAuthConfig);
47
+ /**
48
+ * Generate login URL for OAuth authorization.
49
+ *
50
+ * @param options - Login options
51
+ * @returns URL to redirect to and cookies to set
52
+ */
53
+ getLoginUrl(options: {
54
+ returnTo?: string;
55
+ requestOrigin: string;
56
+ }): LoginUrlResult;
57
+ /**
58
+ * Handle OAuth callback after authorization.
59
+ *
60
+ * @param options - Callback parameters
61
+ * @returns User info, tokens, and redirect URL
62
+ */
63
+ handleCallback(options: {
64
+ code: string;
65
+ state: string;
66
+ cookieHeader: string | null;
67
+ }): Promise<CallbackResult>;
68
+ /**
69
+ * Verify an access token.
70
+ *
71
+ * @param token - Access token to verify
72
+ * @returns User and role information
73
+ */
74
+ verifyToken(token: string): Promise<VerifyResponse>;
75
+ /**
76
+ * Validate an existing session.
77
+ *
78
+ * @param sessionToken - Session token to validate
79
+ * @returns Session data if valid, null otherwise
80
+ */
81
+ validateSession(sessionToken: string): Promise<CloudSession | null>;
82
+ /**
83
+ * Destroy a session (server-side logout).
84
+ *
85
+ * @param sessionToken - Session token to destroy
86
+ */
87
+ destroySession(sessionToken: string): Promise<void>;
88
+ /**
89
+ * Get the logout URL for client-side redirect.
90
+ *
91
+ * @param postLogoutRedirectUri - URL to redirect to after logout
92
+ * @param idTokenHint - The access token
93
+ * @returns Full logout URL with redirect and token parameters
94
+ */
95
+ getLogoutUrl(postLogoutRedirectUri: string, idTokenHint: string): string;
96
+ /**
97
+ * Create Set-Cookie header value for session token.
98
+ *
99
+ * @param token - Session token to store
100
+ * @returns Set-Cookie header value
101
+ */
102
+ setSessionCookie(token: string): string;
103
+ /**
104
+ * Create Set-Cookie header value to clear session cookie.
105
+ *
106
+ * @returns Set-Cookie header value
107
+ */
108
+ clearSessionCookie(): string;
109
+ }
110
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAWH,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE5F;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,8BAA8B;IAC9B,SAAS,EAAE,MAAM,CAAC;IAClB,gEAAgE;IAChE,YAAY,EAAE,MAAM,CAAC;IACrB,8CAA8C;IAC9C,WAAW,EAAE,MAAM,CAAC;IACpB,kEAAkE;IAClE,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,qBAAa,eAAe;IAC1B,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAwB;gBAEnC,MAAM,EAAE,qBAAqB;IAIzC;;;;;OAKG;IACH,WAAW,CAAC,OAAO,EAAE;QAAE,QAAQ,CAAC,EAAE,MAAM,CAAC;QAAC,aAAa,EAAE,MAAM,CAAA;KAAE,GAAG,cAAc;IAWlF;;;;;OAKG;IACH,cAAc,CAAC,OAAO,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,YAAY,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,GAAG,OAAO,CAAC,cAAc,CAAC;IAS9G;;;;;OAKG;IACH,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC;IAInD;;;;;OAKG;IACH,eAAe,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC;IAInE;;;;OAIG;IACH,cAAc,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAInD;;;;;;OAMG;IACH,YAAY,CAAC,qBAAqB,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM;IAIxE;;;;;OAKG;IACH,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IAIvC;;;;OAIG;IACH,kBAAkB,IAAI,MAAM;CAG7B"}
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Auth error types and error class.
3
+ *
4
+ * Provides typed error handling for OAuth flow and session management.
5
+ */
6
+ /**
7
+ * Error codes for authentication-related failures.
8
+ */
9
+ export type AuthErrorCode = 'invalid_state' | 'state_mismatch' | 'missing_code' | 'token_exchange_failed' | 'verification_failed' | 'session_invalid' | 'session_expired' | 'network_error' | 'cloud_api_error';
10
+ /**
11
+ * Options for AuthError constructor.
12
+ */
13
+ export interface AuthErrorOptions {
14
+ cause?: Error;
15
+ cloudCode?: string;
16
+ cloudMessage?: string;
17
+ }
18
+ /**
19
+ * Error class for authentication-related failures.
20
+ * Uses a code discriminator for programmatic error handling.
21
+ */
22
+ export declare class AuthError extends Error {
23
+ readonly code: AuthErrorCode;
24
+ readonly cause?: Error;
25
+ readonly cloudCode?: string;
26
+ readonly cloudMessage?: string;
27
+ constructor(code: AuthErrorCode, message: string, options?: AuthErrorOptions);
28
+ /**
29
+ * Factory: OAuth state parameter is invalid or malformed.
30
+ */
31
+ static invalidState(): AuthError;
32
+ /**
33
+ * Factory: OAuth state parameter does not match expected value.
34
+ */
35
+ static stateMismatch(): AuthError;
36
+ /**
37
+ * Factory: Authorization code is missing from callback.
38
+ */
39
+ static missingCode(): AuthError;
40
+ /**
41
+ * Factory: Token exchange with Cloud API failed.
42
+ */
43
+ static tokenExchangeFailed(options?: AuthErrorOptions): AuthError;
44
+ /**
45
+ * Factory: Token verification failed.
46
+ */
47
+ static verificationFailed(): AuthError;
48
+ /**
49
+ * Factory: Session is invalid.
50
+ */
51
+ static sessionInvalid(): AuthError;
52
+ /**
53
+ * Factory: Session has expired.
54
+ */
55
+ static sessionExpired(): AuthError;
56
+ /**
57
+ * Factory: Network error during API call.
58
+ */
59
+ static networkError(cause?: Error): AuthError;
60
+ /**
61
+ * Factory: Cloud API returned an error.
62
+ */
63
+ static cloudApiError(options?: AuthErrorOptions): AuthError;
64
+ }
65
+ //# sourceMappingURL=error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../src/error.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;GAEG;AACH,MAAM,MAAM,aAAa,GACrB,eAAe,GACf,gBAAgB,GAChB,cAAc,GACd,uBAAuB,GACvB,qBAAqB,GACrB,iBAAiB,GACjB,iBAAiB,GACjB,eAAe,GACf,iBAAiB,CAAC;AAEtB;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED;;;GAGG;AACH,qBAAa,SAAU,SAAQ,KAAK;IAClC,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC;IAC7B,SAAkB,KAAK,CAAC,EAAE,KAAK,CAAC;IAChC,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;gBAEnB,IAAI,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE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