@authsome/ui-core 0.1.8 → 0.1.9

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.
@@ -171,6 +171,83 @@ interface OrganizationMembership {
171
171
  role: 'owner' | 'admin' | 'member';
172
172
  permissions?: string[];
173
173
  }
174
+ /**
175
+ * Device Flow types (RFC 8628 - OAuth 2.0 Device Authorization Grant)
176
+ */
177
+ /**
178
+ * Request to initiate device flow
179
+ * Used by CLI/device applications to start the authorization process
180
+ */
181
+ interface DeviceFlowInitiateRequest {
182
+ clientId: string;
183
+ scope?: string;
184
+ }
185
+ /**
186
+ * Response from device flow initiation
187
+ * Contains codes and URIs needed for user authorization
188
+ */
189
+ interface DeviceFlowInitiateResponse {
190
+ /** The device verification code (long, secret code for polling) */
191
+ deviceCode: string;
192
+ /** The user-facing code to enter in browser (short, easy-to-type) */
193
+ userCode: string;
194
+ /** The URL to visit for verification */
195
+ verificationUri: string;
196
+ /** Optional complete URL with user_code pre-filled */
197
+ verificationUriComplete?: string;
198
+ /** Lifetime of device_code and user_code in seconds */
199
+ expiresIn: number;
200
+ /** Minimum polling interval in seconds */
201
+ interval: number;
202
+ }
203
+ /**
204
+ * Request to verify a user-entered device code
205
+ * Used by the web UI when user enters their code
206
+ */
207
+ interface DeviceCodeVerifyRequest {
208
+ userCode: string;
209
+ }
210
+ /**
211
+ * Response from device code verification
212
+ * Contains information about the pending authorization
213
+ */
214
+ interface DeviceCodeVerifyResponse {
215
+ /** Whether the code is valid */
216
+ valid: boolean;
217
+ /** Client application name requesting access */
218
+ clientName?: string;
219
+ /** Scopes being requested */
220
+ scopes?: string[];
221
+ /** Time remaining before code expires */
222
+ expiresIn?: number;
223
+ }
224
+ /**
225
+ * Request to authorize/deny a device
226
+ * Used when user approves or denies the authorization request
227
+ */
228
+ interface DeviceAuthorizeRequest {
229
+ userCode: string;
230
+ action: 'approve' | 'deny';
231
+ }
232
+ /**
233
+ * Request to poll for device token
234
+ * Used by CLI/device to check if user has authorized
235
+ */
236
+ interface DeviceTokenPollRequest {
237
+ deviceCode: string;
238
+ clientId: string;
239
+ }
240
+ /**
241
+ * Status returned when polling is not yet complete
242
+ */
243
+ type DeviceTokenPollStatus = 'authorization_pending' | 'slow_down' | 'expired_token' | 'access_denied';
244
+ /**
245
+ * Response from device token polling
246
+ * Either contains the auth response or a status indicator
247
+ */
248
+ interface DeviceTokenPollResponse {
249
+ status: DeviceTokenPollStatus;
250
+ }
174
251
 
175
252
  /**
176
253
  * Sign in request
@@ -782,6 +859,27 @@ interface AuthProvider {
782
859
  * Optional - only available if adapter supports session management
783
860
  */
784
861
  revokeAllSessions?(): Promise<void>;
862
+ /**
863
+ * Initiate device authorization flow
864
+ * Used by CLI/device applications to start the authorization process
865
+ * Returns device code, user code, and verification URI
866
+ */
867
+ initiateDeviceFlow?(request: DeviceFlowInitiateRequest): Promise<DeviceFlowInitiateResponse>;
868
+ /**
869
+ * Verify a user-entered device code
870
+ * Called by web UI when user enters the code shown on their device
871
+ */
872
+ verifyDeviceCode?(request: DeviceCodeVerifyRequest): Promise<DeviceCodeVerifyResponse>;
873
+ /**
874
+ * Authorize or deny the device request
875
+ * Called when user approves or denies the authorization
876
+ */
877
+ authorizeDevice?(request: DeviceAuthorizeRequest): Promise<void>;
878
+ /**
879
+ * Poll for device token (used by CLI/device)
880
+ * Returns auth response when authorized, or status when still pending
881
+ */
882
+ pollDeviceToken?(request: DeviceTokenPollRequest): Promise<AuthResponse | DeviceTokenPollResponse>;
785
883
  }
786
884
 
787
- export { AuthErrorType as A, type FieldDefinition as B, type CookieData as C, type SignupFieldsResponse as D, type AuthResponse as E, type FieldValidation as F, type ProviderConfig as G, type SendVerificationEmailRequest as H, type VerifyEmailRequest as I, type ResendVerificationRequest as J, type MFAFactor as K, type EnrollMFAFactorRequest as L, type MagicLinkRequest as M, type VerifyMFAFactorRequest as N, type OAuthSignInRequest as O, type PasswordChangeRequest as P, type MFAChallengeRequest as Q, type RequestContext as R, type SignInRequest as S, type TwoFactorSetupRequest as T, type UpdateUserRequest as U, type ValidationError as V, type MFAChallengeResponse as W, type Device as X, type SessionInfo as Y, type ListSessionsOptions as Z, type ListSessionsResponse as _, AuthError as a, type AuthContext as b, type AuthProvider as c, type SignUpRequest as d, type PasswordResetRequest as e, type PasswordResetConfirmRequest as f, type OAuthCallbackRequest as g, OAuthProvider as h, type MagicLinkVerifyRequest as i, type PhoneAuthRequest as j, type PhoneVerifyRequest as k, type TwoFactorSetupResponse as l, type TwoFactorVerifyRequest as m, TwoFactorMethod as n, type PasskeyRegisterRequest as o, type PasskeyCredential as p, type PasskeyAuthRequest as q, type Organization as r, type OrganizationMembership as s, type User as t, type Session as u, AuthState as v, type SessionData as w, type OAuthConfig as x, type TwoFactorConfig as y, type FieldType as z };
885
+ export { type EnrollMFAFactorRequest as $, AuthErrorType as A, type DeviceCodeVerifyRequest as B, type CookieData as C, type DeviceFlowInitiateRequest as D, type DeviceCodeVerifyResponse as E, type DeviceAuthorizeRequest as F, type DeviceTokenPollRequest as G, type DeviceTokenPollStatus as H, type DeviceTokenPollResponse as I, type FieldValidation as J, type FieldType as K, type FieldDefinition as L, type MagicLinkRequest as M, type SignupFieldsResponse as N, type OAuthSignInRequest as O, type PasswordChangeRequest as P, type AuthResponse as Q, type ProviderConfig as R, type SignInRequest as S, type TwoFactorSetupRequest as T, type UpdateUserRequest as U, type ValidationError as V, type RequestContext as W, type SendVerificationEmailRequest as X, type VerifyEmailRequest as Y, type ResendVerificationRequest as Z, type MFAFactor as _, AuthError as a, type VerifyMFAFactorRequest as a0, type MFAChallengeRequest as a1, type MFAChallengeResponse as a2, type Device as a3, type SessionInfo as a4, type ListSessionsOptions as a5, type ListSessionsResponse as a6, type AuthContext as b, type AuthProvider as c, type SignUpRequest as d, type PasswordResetRequest as e, type PasswordResetConfirmRequest as f, type OAuthCallbackRequest as g, OAuthProvider as h, type MagicLinkVerifyRequest as i, type PhoneAuthRequest as j, type PhoneVerifyRequest as k, type TwoFactorSetupResponse as l, type TwoFactorVerifyRequest as m, TwoFactorMethod as n, type PasskeyRegisterRequest as o, type PasskeyCredential as p, type PasskeyAuthRequest as q, type Organization as r, type OrganizationMembership as s, type User as t, type Session as u, AuthState as v, type SessionData as w, type OAuthConfig as x, type TwoFactorConfig as y, type DeviceFlowInitiateResponse as z };
@@ -171,6 +171,83 @@ interface OrganizationMembership {
171
171
  role: 'owner' | 'admin' | 'member';
172
172
  permissions?: string[];
173
173
  }
174
+ /**
175
+ * Device Flow types (RFC 8628 - OAuth 2.0 Device Authorization Grant)
176
+ */
177
+ /**
178
+ * Request to initiate device flow
179
+ * Used by CLI/device applications to start the authorization process
180
+ */
181
+ interface DeviceFlowInitiateRequest {
182
+ clientId: string;
183
+ scope?: string;
184
+ }
185
+ /**
186
+ * Response from device flow initiation
187
+ * Contains codes and URIs needed for user authorization
188
+ */
189
+ interface DeviceFlowInitiateResponse {
190
+ /** The device verification code (long, secret code for polling) */
191
+ deviceCode: string;
192
+ /** The user-facing code to enter in browser (short, easy-to-type) */
193
+ userCode: string;
194
+ /** The URL to visit for verification */
195
+ verificationUri: string;
196
+ /** Optional complete URL with user_code pre-filled */
197
+ verificationUriComplete?: string;
198
+ /** Lifetime of device_code and user_code in seconds */
199
+ expiresIn: number;
200
+ /** Minimum polling interval in seconds */
201
+ interval: number;
202
+ }
203
+ /**
204
+ * Request to verify a user-entered device code
205
+ * Used by the web UI when user enters their code
206
+ */
207
+ interface DeviceCodeVerifyRequest {
208
+ userCode: string;
209
+ }
210
+ /**
211
+ * Response from device code verification
212
+ * Contains information about the pending authorization
213
+ */
214
+ interface DeviceCodeVerifyResponse {
215
+ /** Whether the code is valid */
216
+ valid: boolean;
217
+ /** Client application name requesting access */
218
+ clientName?: string;
219
+ /** Scopes being requested */
220
+ scopes?: string[];
221
+ /** Time remaining before code expires */
222
+ expiresIn?: number;
223
+ }
224
+ /**
225
+ * Request to authorize/deny a device
226
+ * Used when user approves or denies the authorization request
227
+ */
228
+ interface DeviceAuthorizeRequest {
229
+ userCode: string;
230
+ action: 'approve' | 'deny';
231
+ }
232
+ /**
233
+ * Request to poll for device token
234
+ * Used by CLI/device to check if user has authorized
235
+ */
236
+ interface DeviceTokenPollRequest {
237
+ deviceCode: string;
238
+ clientId: string;
239
+ }
240
+ /**
241
+ * Status returned when polling is not yet complete
242
+ */
243
+ type DeviceTokenPollStatus = 'authorization_pending' | 'slow_down' | 'expired_token' | 'access_denied';
244
+ /**
245
+ * Response from device token polling
246
+ * Either contains the auth response or a status indicator
247
+ */
248
+ interface DeviceTokenPollResponse {
249
+ status: DeviceTokenPollStatus;
250
+ }
174
251
 
175
252
  /**
176
253
  * Sign in request
@@ -782,6 +859,27 @@ interface AuthProvider {
782
859
  * Optional - only available if adapter supports session management
783
860
  */
784
861
  revokeAllSessions?(): Promise<void>;
862
+ /**
863
+ * Initiate device authorization flow
864
+ * Used by CLI/device applications to start the authorization process
865
+ * Returns device code, user code, and verification URI
866
+ */
867
+ initiateDeviceFlow?(request: DeviceFlowInitiateRequest): Promise<DeviceFlowInitiateResponse>;
868
+ /**
869
+ * Verify a user-entered device code
870
+ * Called by web UI when user enters the code shown on their device
871
+ */
872
+ verifyDeviceCode?(request: DeviceCodeVerifyRequest): Promise<DeviceCodeVerifyResponse>;
873
+ /**
874
+ * Authorize or deny the device request
875
+ * Called when user approves or denies the authorization
876
+ */
877
+ authorizeDevice?(request: DeviceAuthorizeRequest): Promise<void>;
878
+ /**
879
+ * Poll for device token (used by CLI/device)
880
+ * Returns auth response when authorized, or status when still pending
881
+ */
882
+ pollDeviceToken?(request: DeviceTokenPollRequest): Promise<AuthResponse | DeviceTokenPollResponse>;
785
883
  }
786
884
 
787
- export { AuthErrorType as A, type FieldDefinition as B, type CookieData as C, type SignupFieldsResponse as D, type AuthResponse as E, type FieldValidation as F, type ProviderConfig as G, type SendVerificationEmailRequest as H, type VerifyEmailRequest as I, type ResendVerificationRequest as J, type MFAFactor as K, type EnrollMFAFactorRequest as L, type MagicLinkRequest as M, type VerifyMFAFactorRequest as N, type OAuthSignInRequest as O, type PasswordChangeRequest as P, type MFAChallengeRequest as Q, type RequestContext as R, type SignInRequest as S, type TwoFactorSetupRequest as T, type UpdateUserRequest as U, type ValidationError as V, type MFAChallengeResponse as W, type Device as X, type SessionInfo as Y, type ListSessionsOptions as Z, type ListSessionsResponse as _, AuthError as a, type AuthContext as b, type AuthProvider as c, type SignUpRequest as d, type PasswordResetRequest as e, type PasswordResetConfirmRequest as f, type OAuthCallbackRequest as g, OAuthProvider as h, type MagicLinkVerifyRequest as i, type PhoneAuthRequest as j, type PhoneVerifyRequest as k, type TwoFactorSetupResponse as l, type TwoFactorVerifyRequest as m, TwoFactorMethod as n, type PasskeyRegisterRequest as o, type PasskeyCredential as p, type PasskeyAuthRequest as q, type Organization as r, type OrganizationMembership as s, type User as t, type Session as u, AuthState as v, type SessionData as w, type OAuthConfig as x, type TwoFactorConfig as y, type FieldType as z };
885
+ export { type EnrollMFAFactorRequest as $, AuthErrorType as A, type DeviceCodeVerifyRequest as B, type CookieData as C, type DeviceFlowInitiateRequest as D, type DeviceCodeVerifyResponse as E, type DeviceAuthorizeRequest as F, type DeviceTokenPollRequest as G, type DeviceTokenPollStatus as H, type DeviceTokenPollResponse as I, type FieldValidation as J, type FieldType as K, type FieldDefinition as L, type MagicLinkRequest as M, type SignupFieldsResponse as N, type OAuthSignInRequest as O, type PasswordChangeRequest as P, type AuthResponse as Q, type ProviderConfig as R, type SignInRequest as S, type TwoFactorSetupRequest as T, type UpdateUserRequest as U, type ValidationError as V, type RequestContext as W, type SendVerificationEmailRequest as X, type VerifyEmailRequest as Y, type ResendVerificationRequest as Z, type MFAFactor as _, AuthError as a, type VerifyMFAFactorRequest as a0, type MFAChallengeRequest as a1, type MFAChallengeResponse as a2, type Device as a3, type SessionInfo as a4, type ListSessionsOptions as a5, type ListSessionsResponse as a6, type AuthContext as b, type AuthProvider as c, type SignUpRequest as d, type PasswordResetRequest as e, type PasswordResetConfirmRequest as f, type OAuthCallbackRequest as g, OAuthProvider as h, type MagicLinkVerifyRequest as i, type PhoneAuthRequest as j, type PhoneVerifyRequest as k, type TwoFactorSetupResponse as l, type TwoFactorVerifyRequest as m, TwoFactorMethod as n, type PasskeyRegisterRequest as o, type PasskeyCredential as p, type PasskeyAuthRequest as q, type Organization as r, type OrganizationMembership as s, type User as t, type Session as u, AuthState as v, type SessionData as w, type OAuthConfig as x, type TwoFactorConfig as y, type DeviceFlowInitiateResponse as z };
@@ -1,4 +1,4 @@
1
- export { b as AuthContext, a as AuthError, A as AuthErrorType, c as AuthProvider, E as AuthResponse, v as AuthState, C as CookieData, X as Device, L as EnrollMFAFactorRequest, B as FieldDefinition, z as FieldType, F as FieldValidation, Z as ListSessionsOptions, _ as ListSessionsResponse, Q as MFAChallengeRequest, W as MFAChallengeResponse, K as MFAFactor, M as MagicLinkRequest, i as MagicLinkVerifyRequest, g as OAuthCallbackRequest, x as OAuthConfig, h as OAuthProvider, O as OAuthSignInRequest, r as Organization, s as OrganizationMembership, q as PasskeyAuthRequest, p as PasskeyCredential, o as PasskeyRegisterRequest, P as PasswordChangeRequest, f as PasswordResetConfirmRequest, e as PasswordResetRequest, j as PhoneAuthRequest, k as PhoneVerifyRequest, G as ProviderConfig, R as RequestContext, J as ResendVerificationRequest, H as SendVerificationEmailRequest, u as Session, w as SessionData, Y as SessionInfo, S as SignInRequest, d as SignUpRequest, D as SignupFieldsResponse, y as TwoFactorConfig, n as TwoFactorMethod, T as TwoFactorSetupRequest, l as TwoFactorSetupResponse, m as TwoFactorVerifyRequest, U as UpdateUserRequest, t as User, V as ValidationError, I as VerifyEmailRequest, N as VerifyMFAFactorRequest } from '../provider-S9ZY5hsp.mjs';
1
+ export { b as AuthContext, a as AuthError, A as AuthErrorType, c as AuthProvider, Q as AuthResponse, v as AuthState, C as CookieData, a3 as Device, F as DeviceAuthorizeRequest, B as DeviceCodeVerifyRequest, E as DeviceCodeVerifyResponse, D as DeviceFlowInitiateRequest, z as DeviceFlowInitiateResponse, G as DeviceTokenPollRequest, I as DeviceTokenPollResponse, H as DeviceTokenPollStatus, $ as EnrollMFAFactorRequest, L as FieldDefinition, K as FieldType, J as FieldValidation, a5 as ListSessionsOptions, a6 as ListSessionsResponse, a1 as MFAChallengeRequest, a2 as MFAChallengeResponse, _ as MFAFactor, M as MagicLinkRequest, i as MagicLinkVerifyRequest, g as OAuthCallbackRequest, x as OAuthConfig, h as OAuthProvider, O as OAuthSignInRequest, r as Organization, s as OrganizationMembership, q as PasskeyAuthRequest, p as PasskeyCredential, o as PasskeyRegisterRequest, P as PasswordChangeRequest, f as PasswordResetConfirmRequest, e as PasswordResetRequest, j as PhoneAuthRequest, k as PhoneVerifyRequest, R as ProviderConfig, W as RequestContext, Z as ResendVerificationRequest, X as SendVerificationEmailRequest, u as Session, w as SessionData, a4 as SessionInfo, S as SignInRequest, d as SignUpRequest, N as SignupFieldsResponse, y as TwoFactorConfig, n as TwoFactorMethod, T as TwoFactorSetupRequest, l as TwoFactorSetupResponse, m as TwoFactorVerifyRequest, U as UpdateUserRequest, t as User, V as ValidationError, Y as VerifyEmailRequest, a0 as VerifyMFAFactorRequest } from '../provider-DWklI8Wr.mjs';
2
2
 
3
3
  /**
4
4
  * Storage abstraction for auth tokens and data
@@ -1,4 +1,4 @@
1
- export { b as AuthContext, a as AuthError, A as AuthErrorType, c as AuthProvider, E as AuthResponse, v as AuthState, C as CookieData, X as Device, L as EnrollMFAFactorRequest, B as FieldDefinition, z as FieldType, F as FieldValidation, Z as ListSessionsOptions, _ as ListSessionsResponse, Q as MFAChallengeRequest, W as MFAChallengeResponse, K as MFAFactor, M as MagicLinkRequest, i as MagicLinkVerifyRequest, g as OAuthCallbackRequest, x as OAuthConfig, h as OAuthProvider, O as OAuthSignInRequest, r as Organization, s as OrganizationMembership, q as PasskeyAuthRequest, p as PasskeyCredential, o as PasskeyRegisterRequest, P as PasswordChangeRequest, f as PasswordResetConfirmRequest, e as PasswordResetRequest, j as PhoneAuthRequest, k as PhoneVerifyRequest, G as ProviderConfig, R as RequestContext, J as ResendVerificationRequest, H as SendVerificationEmailRequest, u as Session, w as SessionData, Y as SessionInfo, S as SignInRequest, d as SignUpRequest, D as SignupFieldsResponse, y as TwoFactorConfig, n as TwoFactorMethod, T as TwoFactorSetupRequest, l as TwoFactorSetupResponse, m as TwoFactorVerifyRequest, U as UpdateUserRequest, t as User, V as ValidationError, I as VerifyEmailRequest, N as VerifyMFAFactorRequest } from '../provider-S9ZY5hsp.js';
1
+ export { b as AuthContext, a as AuthError, A as AuthErrorType, c as AuthProvider, Q as AuthResponse, v as AuthState, C as CookieData, a3 as Device, F as DeviceAuthorizeRequest, B as DeviceCodeVerifyRequest, E as DeviceCodeVerifyResponse, D as DeviceFlowInitiateRequest, z as DeviceFlowInitiateResponse, G as DeviceTokenPollRequest, I as DeviceTokenPollResponse, H as DeviceTokenPollStatus, $ as EnrollMFAFactorRequest, L as FieldDefinition, K as FieldType, J as FieldValidation, a5 as ListSessionsOptions, a6 as ListSessionsResponse, a1 as MFAChallengeRequest, a2 as MFAChallengeResponse, _ as MFAFactor, M as MagicLinkRequest, i as MagicLinkVerifyRequest, g as OAuthCallbackRequest, x as OAuthConfig, h as OAuthProvider, O as OAuthSignInRequest, r as Organization, s as OrganizationMembership, q as PasskeyAuthRequest, p as PasskeyCredential, o as PasskeyRegisterRequest, P as PasswordChangeRequest, f as PasswordResetConfirmRequest, e as PasswordResetRequest, j as PhoneAuthRequest, k as PhoneVerifyRequest, R as ProviderConfig, W as RequestContext, Z as ResendVerificationRequest, X as SendVerificationEmailRequest, u as Session, w as SessionData, a4 as SessionInfo, S as SignInRequest, d as SignUpRequest, N as SignupFieldsResponse, y as TwoFactorConfig, n as TwoFactorMethod, T as TwoFactorSetupRequest, l as TwoFactorSetupResponse, m as TwoFactorVerifyRequest, U as UpdateUserRequest, t as User, V as ValidationError, Y as VerifyEmailRequest, a0 as VerifyMFAFactorRequest } from '../provider-DWklI8Wr.js';
2
2
 
3
3
  /**
4
4
  * Storage abstraction for auth tokens and data
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/types/auth.ts","../../src/types/storage.ts","../../src/types/observable.ts"],"names":["AuthState","AuthErrorType","OAuthProvider","TwoFactorMethod"],"mappings":";;;AAOO,IAAK,SAAA,qBAAAA,UAAAA,KAAL;AACL,EAAAA,WAAA,eAAA,CAAA,GAAgB,eAAA;AAChB,EAAAA,WAAA,iBAAA,CAAA,GAAkB,iBAAA;AAClB,EAAAA,WAAA,SAAA,CAAA,GAAU,SAAA;AACV,EAAAA,WAAA,OAAA,CAAA,GAAQ,OAAA;AAJE,EAAA,OAAAA,UAAAA;AAAA,CAAA,EAAA,SAAA,IAAA,EAAA;AAwDL,IAAK,aAAA,qBAAAC,cAAAA,KAAL;AACL,EAAAA,eAAA,qBAAA,CAAA,GAAsB,qBAAA;AACtB,EAAAA,eAAA,gBAAA,CAAA,GAAiB,gBAAA;AACjB,EAAAA,eAAA,qBAAA,CAAA,GAAsB,qBAAA;AACtB,EAAAA,eAAA,eAAA,CAAA,GAAgB,eAAA;AAChB,EAAAA,eAAA,eAAA,CAAA,GAAgB,eAAA;AAChB,EAAAA,eAAA,eAAA,CAAA,GAAgB,eAAA;AAChB,EAAAA,eAAA,kBAAA,CAAA,GAAmB,kBAAA;AACnB,EAAAA,eAAA,cAAA,CAAA,GAAe,cAAA;AACf,EAAAA,eAAA,oBAAA,CAAA,GAAqB,oBAAA;AACrB,EAAAA,eAAA,oBAAA,CAAA,GAAqB,oBAAA;AACrB,EAAAA,eAAA,qBAAA,CAAA,GAAsB,qBAAA;AACtB,EAAAA,eAAA,eAAA,CAAA,GAAgB,eAAA;AAZN,EAAA,OAAAA,cAAAA;AAAA,CAAA,EAAA,aAAA,IAAA,EAAA;AAoBL,IAAM,SAAA,GAAN,MAAM,UAAA,SAAkB,KAAA,CAAM;AAAA,EAMnC,WAAA,CACE,OAAA,EACA,IAAA,GAAsB,eAAA,sBACtB,OAAA,EAKA;AACA,IAAA,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,OAAO,MAAM;AACX,MAAA,IAAA,CAAK,SAAA,CAAU,OAAO,QAAQ,CAAA;AAAA,IAChC,CAAA;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKQ,MAAA,GAAe;AACrB,IAAA,IAAA,CAAK,UAAU,OAAA,CAAQ,CAAC,aAAa,QAAA,CAAS,IAAA,CAAK,KAAK,CAAC,CAAA;AAAA,EAC3D;AAAA;AAAA;AAAA;AAAA,EAKA,cAAA,GAAuB;AACrB,IAAA,IAAA,CAAK,UAAU,KAAA,EAAM;AAAA,EACvB;AAAA;AAAA;AAAA;AAAA,EAKA,gBAAA,GAA2B;AACzB,IAAA,OAAO,KAAK,SAAA,CAAU,IAAA;AAAA,EACxB;AACF","file":"index.js","sourcesContent":["/**\n * Core authentication types and interfaces\n */\n\n/**\n * Authentication state enum\n */\nexport enum AuthState {\n AUTHENTICATED = 'authenticated',\n UNAUTHENTICATED = 'unauthenticated',\n LOADING = 'loading',\n ERROR = 'error',\n}\n\n/**\n * User profile interface\n */\nexport interface User {\n id: string;\n email?: string;\n username?: string;\n phone?: string;\n emailVerified?: boolean;\n phoneVerified?: boolean;\n name?: string;\n firstName?: string;\n lastName?: string;\n avatar?: string;\n metadata?: Record<string, unknown>;\n createdAt?: Date;\n updatedAt?: Date;\n \n // Organization fields\n organizationId?: string;\n organizationRole?: string;\n organizationMemberships?: OrganizationMembership[];\n}\n\n/**\n * Session interface\n */\nexport interface Session {\n id: string;\n userId: string;\n token: string;\n expiresAt?: Date;\n createdAt?: Date;\n metadata?: Record<string, unknown>;\n}\n\n/**\n * Session data with user and session combined\n * Used for efficient retrieval of both user and session in one call\n */\nexport interface SessionData {\n user: User;\n session: Session;\n expiresAt: number;\n}\n\n/**\n * Auth error types\n */\nexport enum AuthErrorType {\n INVALID_CREDENTIALS = 'invalid_credentials',\n USER_NOT_FOUND = 'user_not_found',\n USER_ALREADY_EXISTS = 'user_already_exists',\n INVALID_TOKEN = 'invalid_token',\n TOKEN_EXPIRED = 'token_expired',\n NETWORK_ERROR = 'network_error',\n VALIDATION_ERROR = 'validation_error',\n MFA_REQUIRED = 'mfa_required',\n EMAIL_NOT_VERIFIED = 'email_not_verified',\n PHONE_NOT_VERIFIED = 'phone_not_verified',\n RATE_LIMIT_EXCEEDED = 'rate_limit_exceeded',\n UNKNOWN_ERROR = 'unknown_error',\n}\n\n/**\n * Auth error class\n * \n * Extends Error to provide proper error handling with auth-specific context\n */\nexport class AuthError extends Error {\n public readonly type: AuthErrorType;\n public readonly details?: Record<string, unknown>;\n public readonly code?: string | number;\n public readonly originalError?: unknown;\n\n constructor(\n message: string,\n type: AuthErrorType = AuthErrorType.UNKNOWN_ERROR,\n options?: {\n details?: Record<string, unknown>;\n code?: string | number;\n originalError?: unknown;\n }\n ) {\n super(message);\n this.name = 'AuthError';\n this.type = type;\n this.details = options?.details;\n this.code = options?.code;\n this.originalError = options?.originalError;\n\n // Maintains proper stack trace for where our error was thrown (only available on V8)\n if (Error.captureStackTrace) {\n Error.captureStackTrace(this, AuthError);\n }\n }\n}\n\n/**\n * Auth context state\n */\nexport interface AuthContext {\n state: AuthState;\n user: User | null;\n session: Session | null;\n error: AuthError | null;\n isAuthenticated: boolean;\n isLoading: boolean;\n}\n\n/**\n * OAuth provider types\n */\nexport enum OAuthProvider {\n GOOGLE = 'google',\n GITHUB = 'github',\n FACEBOOK = 'facebook',\n TWITTER = 'twitter',\n MICROSOFT = 'microsoft',\n APPLE = 'apple',\n LINKEDIN = 'linkedin',\n DISCORD = 'discord',\n}\n\n/**\n * OAuth configuration\n */\nexport interface OAuthConfig {\n provider: OAuthProvider;\n clientId: string;\n redirectUri: string;\n scope?: string[];\n state?: string;\n}\n\n/**\n * 2FA method types\n */\nexport enum TwoFactorMethod {\n TOTP = 'totp',\n SMS = 'sms',\n EMAIL = 'email',\n BACKUP_CODE = 'backup_code',\n}\n\n/**\n * 2FA configuration\n */\nexport interface TwoFactorConfig {\n method: TwoFactorMethod;\n enabled: boolean;\n verified?: boolean;\n}\n\n/**\n * Passkey/WebAuthn types\n */\nexport interface PasskeyCredential {\n id: string;\n name?: string;\n createdAt?: Date;\n lastUsedAt?: Date;\n}\n\n/**\n * Validation error\n */\nexport interface ValidationError {\n field: string;\n message: string;\n code?: string;\n}\n\n/**\n * Organization interface\n */\nexport interface Organization {\n id: string;\n name: string;\n slug: string;\n logoUrl?: string;\n createdAt?: Date;\n metadata?: Record<string, unknown>;\n}\n\n/**\n * Organization membership interface\n */\nexport interface OrganizationMembership {\n organization: Organization;\n role: 'owner' | 'admin' | 'member';\n permissions?: string[];\n}\n\n","/**\n * Storage abstraction for auth tokens and data\n */\n\n/**\n * Storage interface\n */\nexport interface Storage {\n /**\n * Get item from storage\n */\n getItem(key: string): Promise<string | null> | string | null;\n\n /**\n * Set item in storage\n */\n setItem(key: string, value: string): Promise<void> | void;\n\n /**\n * Remove item from storage\n */\n removeItem(key: string): Promise<void> | void;\n\n /**\n * Clear all items from storage\n */\n clear(): Promise<void> | void;\n}\n\n/**\n * Storage adapter for localStorage\n */\nexport class LocalStorageAdapter implements Storage {\n getItem(key: string): string | null {\n if (typeof window === 'undefined') return null;\n return window.localStorage.getItem(key);\n }\n\n setItem(key: string, value: string): void {\n if (typeof window === 'undefined') return;\n window.localStorage.setItem(key, value);\n }\n\n removeItem(key: string): void {\n if (typeof window === 'undefined') return;\n window.localStorage.removeItem(key);\n }\n\n clear(): void {\n if (typeof window === 'undefined') return;\n window.localStorage.clear();\n }\n}\n\n/**\n * Storage adapter for sessionStorage\n */\nexport class SessionStorageAdapter implements Storage {\n getItem(key: string): string | null {\n if (typeof window === 'undefined') return null;\n return window.sessionStorage.getItem(key);\n }\n\n setItem(key: string, value: string): void {\n if (typeof window === 'undefined') return;\n window.sessionStorage.setItem(key, value);\n }\n\n removeItem(key: string): void {\n if (typeof window === 'undefined') return;\n window.sessionStorage.removeItem(key);\n }\n\n clear(): void {\n if (typeof window === 'undefined') return;\n window.sessionStorage.clear();\n }\n}\n\n/**\n * In-memory storage adapter (for testing or SSR)\n */\nexport class MemoryStorageAdapter implements Storage {\n private store: Map<string, string> = new Map();\n\n getItem(key: string): string | null {\n return this.store.get(key) ?? null;\n }\n\n setItem(key: string, value: string): void {\n this.store.set(key, value);\n }\n\n removeItem(key: string): void {\n this.store.delete(key);\n }\n\n clear(): void {\n this.store.clear();\n }\n}\n\n","/**\n * Observable pattern for state management across frameworks\n */\n\nexport type Listener<T> = (value: T) => void;\nexport type Unsubscribe = () => void;\n\n/**\n * Observable state container\n */\nexport class Observable<T> {\n private value: T;\n private listeners: Set<Listener<T>> = new Set();\n\n constructor(initialValue: T) {\n this.value = initialValue;\n }\n\n /**\n * Get current value\n */\n getValue(): T {\n return this.value;\n }\n\n /**\n * Set new value and notify listeners\n */\n setValue(newValue: T): void {\n if (this.value !== newValue) {\n this.value = newValue;\n this.notify();\n }\n }\n\n /**\n * Update value with a function\n */\n update(updater: (current: T) => T): void {\n this.setValue(updater(this.value));\n }\n\n /**\n * Subscribe to value changes\n */\n subscribe(listener: Listener<T>): Unsubscribe {\n this.listeners.add(listener);\n // Immediately call listener with current value\n listener(this.value);\n\n // Return unsubscribe function\n return () => {\n this.listeners.delete(listener);\n };\n }\n\n /**\n * Notify all listeners\n */\n private notify(): void {\n this.listeners.forEach((listener) => listener(this.value));\n }\n\n /**\n * Clear all listeners\n */\n clearListeners(): void {\n this.listeners.clear();\n }\n\n /**\n * Get number of listeners\n */\n getListenerCount(): number {\n return this.listeners.size;\n }\n}\n\n"]}
1
+ {"version":3,"sources":["../../src/types/auth.ts","../../src/types/storage.ts","../../src/types/observable.ts"],"names":["AuthState","AuthErrorType","OAuthProvider","TwoFactorMethod"],"mappings":";;;AAOO,IAAK,SAAA,qBAAAA,UAAAA,KAAL;AACL,EAAAA,WAAA,eAAA,CAAA,GAAgB,eAAA;AAChB,EAAAA,WAAA,iBAAA,CAAA,GAAkB,iBAAA;AAClB,EAAAA,WAAA,SAAA,CAAA,GAAU,SAAA;AACV,EAAAA,WAAA,O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AAAA;AAAA;AAAA,EAKA,gBAAA,GAA2B;AACzB,IAAA,OAAO,KAAK,SAAA,CAAU,IAAA;AAAA,EACxB;AACF","file":"index.js","sourcesContent":["/**\n * Core authentication types and interfaces\n */\n\n/**\n * Authentication state enum\n */\nexport enum AuthState {\n AUTHENTICATED = 'authenticated',\n UNAUTHENTICATED = 'unauthenticated',\n LOADING = 'loading',\n ERROR = 'error',\n}\n\n/**\n * User profile interface\n */\nexport interface User {\n id: string;\n email?: string;\n username?: string;\n phone?: string;\n emailVerified?: boolean;\n phoneVerified?: boolean;\n name?: string;\n firstName?: string;\n lastName?: string;\n avatar?: string;\n metadata?: Record<string, unknown>;\n createdAt?: Date;\n updatedAt?: Date;\n \n // Organization fields\n organizationId?: string;\n organizationRole?: string;\n organizationMemberships?: OrganizationMembership[];\n}\n\n/**\n * Session interface\n */\nexport interface Session {\n id: string;\n userId: string;\n token: string;\n expiresAt?: Date;\n createdAt?: Date;\n metadata?: Record<string, unknown>;\n}\n\n/**\n * Session data with user and session combined\n * Used for efficient retrieval of both user and session in one call\n */\nexport interface SessionData {\n user: User;\n session: Session;\n expiresAt: number;\n}\n\n/**\n * Auth error types\n */\nexport enum AuthErrorType {\n INVALID_CREDENTIALS = 'invalid_credentials',\n USER_NOT_FOUND = 'user_not_found',\n USER_ALREADY_EXISTS = 'user_already_exists',\n INVALID_TOKEN = 'invalid_token',\n TOKEN_EXPIRED = 'token_expired',\n NETWORK_ERROR = 'network_error',\n VALIDATION_ERROR = 'validation_error',\n MFA_REQUIRED = 'mfa_required',\n EMAIL_NOT_VERIFIED = 'email_not_verified',\n PHONE_NOT_VERIFIED = 'phone_not_verified',\n RATE_LIMIT_EXCEEDED = 'rate_limit_exceeded',\n UNKNOWN_ERROR = 'unknown_error',\n}\n\n/**\n * Auth error class\n * \n * Extends Error to provide proper error handling with auth-specific context\n */\nexport class AuthError extends Error {\n public readonly type: AuthErrorType;\n public readonly details?: Record<string, unknown>;\n public readonly code?: string | number;\n public readonly originalError?: unknown;\n\n constructor(\n message: string,\n type: AuthErrorType = AuthErrorType.UNKNOWN_ERROR,\n options?: {\n details?: Record<string, unknown>;\n code?: string | number;\n originalError?: unknown;\n }\n ) {\n super(message);\n this.name = 'AuthError';\n this.type = type;\n this.details = options?.details;\n this.code = options?.code;\n this.originalError = options?.originalError;\n\n // Maintains proper stack trace for where our error was thrown (only available on V8)\n if (Error.captureStackTrace) {\n Error.captureStackTrace(this, AuthError);\n }\n }\n}\n\n/**\n * Auth context state\n */\nexport interface AuthContext {\n state: AuthState;\n user: User | null;\n session: Session | null;\n error: AuthError | null;\n isAuthenticated: boolean;\n isLoading: boolean;\n}\n\n/**\n * OAuth provider types\n */\nexport enum OAuthProvider {\n GOOGLE = 'google',\n GITHUB = 'github',\n FACEBOOK = 'facebook',\n TWITTER = 'twitter',\n MICROSOFT = 'microsoft',\n APPLE = 'apple',\n LINKEDIN = 'linkedin',\n DISCORD = 'discord',\n}\n\n/**\n * OAuth configuration\n */\nexport interface OAuthConfig {\n provider: OAuthProvider;\n clientId: string;\n redirectUri: string;\n scope?: string[];\n state?: string;\n}\n\n/**\n * 2FA method types\n */\nexport enum TwoFactorMethod {\n TOTP = 'totp',\n SMS = 'sms',\n EMAIL = 'email',\n BACKUP_CODE = 'backup_code',\n}\n\n/**\n * 2FA configuration\n */\nexport interface TwoFactorConfig {\n method: TwoFactorMethod;\n enabled: boolean;\n verified?: boolean;\n}\n\n/**\n * Passkey/WebAuthn types\n */\nexport interface PasskeyCredential {\n id: string;\n name?: string;\n createdAt?: Date;\n lastUsedAt?: Date;\n}\n\n/**\n * Validation error\n */\nexport interface ValidationError {\n field: string;\n message: string;\n code?: string;\n}\n\n/**\n * Organization interface\n */\nexport interface Organization {\n id: string;\n name: string;\n slug: string;\n logoUrl?: string;\n createdAt?: Date;\n metadata?: Record<string, unknown>;\n}\n\n/**\n * Organization membership interface\n */\nexport interface OrganizationMembership {\n organization: Organization;\n role: 'owner' | 'admin' | 'member';\n permissions?: string[];\n}\n\n/**\n * Device Flow types (RFC 8628 - OAuth 2.0 Device Authorization Grant)\n */\n\n/**\n * Request to initiate device flow\n * Used by CLI/device applications to start the authorization process\n */\nexport interface DeviceFlowInitiateRequest {\n clientId: string;\n scope?: string;\n}\n\n/**\n * Response from device flow initiation\n * Contains codes and URIs needed for user authorization\n */\nexport interface DeviceFlowInitiateResponse {\n /** The device verification code (long, secret code for polling) */\n deviceCode: string;\n /** The user-facing code to enter in browser (short, easy-to-type) */\n userCode: string;\n /** The URL to visit for verification */\n verificationUri: string;\n /** Optional complete URL with user_code pre-filled */\n verificationUriComplete?: string;\n /** Lifetime of device_code and user_code in seconds */\n expiresIn: number;\n /** Minimum polling interval in seconds */\n interval: number;\n}\n\n/**\n * Request to verify a user-entered device code\n * Used by the web UI when user enters their code\n */\nexport interface DeviceCodeVerifyRequest {\n userCode: string;\n}\n\n/**\n * Response from device code verification\n * Contains information about the pending authorization\n */\nexport interface DeviceCodeVerifyResponse {\n /** Whether the code is valid */\n valid: boolean;\n /** Client application name requesting access */\n clientName?: string;\n /** Scopes being requested */\n scopes?: string[];\n /** Time remaining before code expires */\n expiresIn?: number;\n}\n\n/**\n * Request to authorize/deny a device\n * Used when user approves or denies the authorization request\n */\nexport interface DeviceAuthorizeRequest {\n userCode: string;\n action: 'approve' | 'deny';\n}\n\n/**\n * Request to poll for device token\n * Used by CLI/device to check if user has authorized\n */\nexport interface DeviceTokenPollRequest {\n deviceCode: string;\n clientId: string;\n}\n\n/**\n * Status returned when polling is not yet complete\n */\nexport type DeviceTokenPollStatus = \n | 'authorization_pending' // User hasn't authorized yet\n | 'slow_down' // Polling too frequently\n | 'expired_token' // Device code expired\n | 'access_denied'; // User denied authorization\n\n/**\n * Response from device token polling\n * Either contains the auth response or a status indicator\n */\nexport interface DeviceTokenPollResponse {\n status: DeviceTokenPollStatus;\n}\n","/**\n * Storage abstraction for auth tokens and data\n */\n\n/**\n * Storage interface\n */\nexport interface Storage {\n /**\n * Get item from storage\n */\n getItem(key: string): Promise<string | null> | string | null;\n\n /**\n * Set item in storage\n */\n setItem(key: string, value: string): Promise<void> | void;\n\n /**\n * Remove item from storage\n */\n removeItem(key: string): Promise<void> | void;\n\n /**\n * Clear all items from storage\n */\n clear(): Promise<void> | void;\n}\n\n/**\n * Storage adapter for localStorage\n */\nexport class LocalStorageAdapter implements Storage {\n getItem(key: string): string | null {\n if (typeof window === 'undefined') return null;\n return window.localStorage.getItem(key);\n }\n\n setItem(key: string, value: string): void {\n if (typeof window === 'undefined') return;\n window.localStorage.setItem(key, value);\n }\n\n removeItem(key: string): void {\n if (typeof window === 'undefined') return;\n window.localStorage.removeItem(key);\n }\n\n clear(): void {\n if (typeof window === 'undefined') return;\n window.localStorage.clear();\n }\n}\n\n/**\n * Storage adapter for sessionStorage\n */\nexport class SessionStorageAdapter implements Storage {\n getItem(key: string): string | null {\n if (typeof window === 'undefined') return null;\n return window.sessionStorage.getItem(key);\n }\n\n setItem(key: string, value: string): void {\n if (typeof window === 'undefined') return;\n window.sessionStorage.setItem(key, value);\n }\n\n removeItem(key: string): void {\n if (typeof window === 'undefined') return;\n window.sessionStorage.removeItem(key);\n }\n\n clear(): void {\n if (typeof window === 'undefined') return;\n window.sessionStorage.clear();\n }\n}\n\n/**\n * In-memory storage adapter (for testing or SSR)\n */\nexport class MemoryStorageAdapter implements Storage {\n private store: Map<string, string> = new Map();\n\n getItem(key: string): string | null {\n return this.store.get(key) ?? null;\n }\n\n setItem(key: string, value: string): void {\n this.store.set(key, value);\n }\n\n removeItem(key: string): void {\n this.store.delete(key);\n }\n\n clear(): void {\n this.store.clear();\n }\n}\n\n","/**\n * Observable pattern for state management across frameworks\n */\n\nexport type Listener<T> = (value: T) => void;\nexport type Unsubscribe = () => void;\n\n/**\n * Observable state container\n */\nexport class Observable<T> {\n private value: T;\n private listeners: Set<Listener<T>> = new Set();\n\n constructor(initialValue: T) {\n this.value = initialValue;\n }\n\n /**\n * Get current value\n */\n getValue(): T {\n return this.value;\n }\n\n /**\n * Set new value and notify listeners\n */\n setValue(newValue: T): void {\n if (this.value !== newValue) {\n this.value = newValue;\n this.notify();\n }\n }\n\n /**\n * Update value with a function\n */\n update(updater: (current: T) => T): void {\n this.setValue(updater(this.value));\n }\n\n /**\n * Subscribe to value changes\n */\n subscribe(listener: Listener<T>): Unsubscribe {\n this.listeners.add(listener);\n // Immediately call listener with current value\n listener(this.value);\n\n // Return unsubscribe function\n return () => {\n this.listeners.delete(listener);\n };\n }\n\n /**\n * Notify all listeners\n */\n private notify(): void {\n this.listeners.forEach((listener) => listener(this.value));\n }\n\n /**\n * Clear all listeners\n */\n clearListeners(): void {\n this.listeners.clear();\n }\n\n /**\n * Get number of listeners\n */\n getListenerCount(): number {\n return this.listeners.size;\n }\n}\n\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/types/auth.ts","../../src/types/storage.ts","../../src/types/observable.ts"],"names":["AuthState","AuthErrorType","OAuthProvider","TwoFactorMethod"],"mappings":";AAOO,IAAK,SAAA,qBAAAA,UAAAA,KAAL;AACL,EAAAA,WAAA,eAAA,CAAA,GAAgB,eAAA;AAChB,EAAAA,WAAA,iBAAA,CAAA,GAAkB,iBAAA;AAClB,EAAAA,WAAA,SAAA,CAAA,GAAU,SAAA;AACV,EAAAA,WAAA,OAAA,CAAA,GAAQ,OAAA;AAJE,EAAA,OAAAA,UAAAA;AAAA,CAAA,EAAA,SAAA,IAAA,EAAA;AAwDL,IAAK,aAAA,qBAAAC,cAAAA,KAAL;AACL,EAAAA,eAAA,qBAAA,CAAA,GAAsB,qBAAA;AACtB,EAAAA,eAAA,gBAAA,CAAA,GAAiB,gBAAA;AACjB,EAAAA,eAAA,qBAAA,CAAA,GAAsB,qBAAA;AACtB,EAAAA,eAAA,eAAA,CAAA,GAAgB,eAAA;AAChB,EAAAA,eAAA,eAAA,CAAA,GAAgB,eAAA;AAChB,EAAAA,eAAA,eAAA,CAAA,GAAgB,eAAA;AAChB,EAAAA,eAAA,kBAAA,CAAA,GA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AA,IAAI,IAAA,CAAK,UAAU,QAAA,EAAU;AAC3B,MAAA,IAAA,CAAK,KAAA,GAAQ,QAAA;AACb,MAAA,IAAA,CAAK,MAAA,EAAO;AAAA,IACd;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,OAAO,OAAA,EAAkC;AACvC,IAAA,IAAA,CAAK,QAAA,CAAS,OAAA,CAAQ,IAAA,CAAK,KAAK,CAAC,CAAA;AAAA,EACnC;AAAA;AAAA;AAAA;AAAA,EAKA,UAAU,QAAA,EAAoC;AAC5C,IAAA,IAAA,CAAK,SAAA,CAAU,IAAI,QAAQ,CAAA;AAE3B,IAAA,QAAA,CAAS,KAAK,KAAK,CAAA;AAGnB,IAAA,OAAO,MAAM;AACX,MAAA,IAAA,CAAK,SAAA,CAAU,OAAO,QAAQ,CAAA;AAAA,IAChC,CAAA;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKQ,MAAA,GAAe;AACrB,IAAA,IAAA,CAAK,UAAU,OAAA,CAAQ,CAAC,aAAa,QAAA,CAAS,IAAA,CAAK,KAAK,CAAC,CAAA;AAAA,EAC3D;AAAA;AAAA;AAAA;AAAA,EAKA,cAAA,GAAuB;AACrB,IAAA,IAAA,CAAK,UAAU,KAAA,EAAM;AAAA,EACvB;AAAA;AAAA;AAAA;AAAA,EAKA,gBAAA,GAA2B;AACzB,IAAA,OAAO,KAAK,SAAA,CAAU,IAAA;AAAA,EACxB;AACF","file":"index.mjs","sourcesContent":["/**\n * Core authentication types and interfaces\n */\n\n/**\n * Authentication state enum\n */\nexport enum AuthState {\n AUTHENTICATED = 'authenticated',\n UNAUTHENTICATED = 'unauthenticated',\n LOADING = 'loading',\n ERROR = 'error',\n}\n\n/**\n * User profile interface\n */\nexport interface User {\n id: string;\n email?: string;\n username?: string;\n phone?: string;\n emailVerified?: boolean;\n phoneVerified?: boolean;\n name?: string;\n firstName?: string;\n lastName?: string;\n avatar?: string;\n metadata?: Record<string, unknown>;\n createdAt?: Date;\n updatedAt?: Date;\n \n // Organization fields\n organizationId?: string;\n organizationRole?: string;\n organizationMemberships?: OrganizationMembership[];\n}\n\n/**\n * Session interface\n */\nexport interface Session {\n id: string;\n userId: string;\n token: string;\n expiresAt?: Date;\n createdAt?: Date;\n metadata?: Record<string, unknown>;\n}\n\n/**\n * Session data with user and session combined\n * Used for efficient retrieval of both user and session in one call\n */\nexport interface SessionData {\n user: User;\n session: Session;\n expiresAt: number;\n}\n\n/**\n * Auth error types\n */\nexport enum AuthErrorType {\n INVALID_CREDENTIALS = 'invalid_credentials',\n USER_NOT_FOUND = 'user_not_found',\n USER_ALREADY_EXISTS = 'user_already_exists',\n INVALID_TOKEN = 'invalid_token',\n TOKEN_EXPIRED = 'token_expired',\n NETWORK_ERROR = 'network_error',\n VALIDATION_ERROR = 'validation_error',\n MFA_REQUIRED = 'mfa_required',\n EMAIL_NOT_VERIFIED = 'email_not_verified',\n PHONE_NOT_VERIFIED = 'phone_not_verified',\n RATE_LIMIT_EXCEEDED = 'rate_limit_exceeded',\n UNKNOWN_ERROR = 'unknown_error',\n}\n\n/**\n * Auth error class\n * \n * Extends Error to provide proper error handling with auth-specific context\n */\nexport class AuthError extends Error {\n public readonly type: AuthErrorType;\n public readonly details?: Record<string, unknown>;\n public readonly code?: string | number;\n public readonly originalError?: unknown;\n\n constructor(\n message: string,\n type: AuthErrorType = AuthErrorType.UNKNOWN_ERROR,\n options?: {\n details?: Record<string, unknown>;\n code?: string | number;\n originalError?: unknown;\n }\n ) {\n super(message);\n this.name = 'AuthError';\n this.type = type;\n this.details = options?.details;\n this.code = options?.code;\n this.originalError = options?.originalError;\n\n // Maintains proper stack trace for where our error was thrown (only available on V8)\n if (Error.captureStackTrace) {\n Error.captureStackTrace(this, AuthError);\n }\n }\n}\n\n/**\n * Auth context state\n */\nexport interface AuthContext {\n state: AuthState;\n user: User | null;\n session: Session | null;\n error: AuthError | null;\n isAuthenticated: boolean;\n isLoading: boolean;\n}\n\n/**\n * OAuth provider types\n */\nexport enum OAuthProvider {\n GOOGLE = 'google',\n GITHUB = 'github',\n FACEBOOK = 'facebook',\n TWITTER = 'twitter',\n MICROSOFT = 'microsoft',\n APPLE = 'apple',\n LINKEDIN = 'linkedin',\n DISCORD = 'discord',\n}\n\n/**\n * OAuth configuration\n */\nexport interface OAuthConfig {\n provider: OAuthProvider;\n clientId: string;\n redirectUri: string;\n scope?: string[];\n state?: string;\n}\n\n/**\n * 2FA method types\n */\nexport enum TwoFactorMethod {\n TOTP = 'totp',\n SMS = 'sms',\n EMAIL = 'email',\n BACKUP_CODE = 'backup_code',\n}\n\n/**\n * 2FA configuration\n */\nexport interface TwoFactorConfig {\n method: TwoFactorMethod;\n enabled: boolean;\n verified?: boolean;\n}\n\n/**\n * Passkey/WebAuthn types\n */\nexport interface PasskeyCredential {\n id: string;\n name?: string;\n createdAt?: Date;\n lastUsedAt?: Date;\n}\n\n/**\n * Validation error\n */\nexport interface ValidationError {\n field: string;\n message: string;\n code?: string;\n}\n\n/**\n * Organization interface\n */\nexport interface Organization {\n id: string;\n name: string;\n slug: string;\n logoUrl?: string;\n createdAt?: Date;\n metadata?: Record<string, unknown>;\n}\n\n/**\n * Organization membership interface\n */\nexport interface OrganizationMembership {\n organization: Organization;\n role: 'owner' | 'admin' | 'member';\n permissions?: string[];\n}\n\n","/**\n * Storage abstraction for auth tokens and data\n */\n\n/**\n * Storage interface\n */\nexport interface Storage {\n /**\n * Get item from storage\n */\n getItem(key: string): Promise<string | null> | string | null;\n\n /**\n * Set item in storage\n */\n setItem(key: string, value: string): Promise<void> | void;\n\n /**\n * Remove item from storage\n */\n removeItem(key: string): Promise<void> | void;\n\n /**\n * Clear all items from storage\n */\n clear(): Promise<void> | void;\n}\n\n/**\n * Storage adapter for localStorage\n */\nexport class LocalStorageAdapter implements Storage {\n getItem(key: string): string | null {\n if (typeof window === 'undefined') return null;\n return window.localStorage.getItem(key);\n }\n\n setItem(key: string, value: string): void {\n if (typeof window === 'undefined') return;\n window.localStorage.setItem(key, value);\n }\n\n removeItem(key: string): void {\n if (typeof window === 'undefined') return;\n window.localStorage.removeItem(key);\n }\n\n clear(): void {\n if (typeof window === 'undefined') return;\n window.localStorage.clear();\n }\n}\n\n/**\n * Storage adapter for sessionStorage\n */\nexport class SessionStorageAdapter implements Storage {\n getItem(key: string): string | null {\n if (typeof window === 'undefined') return null;\n return window.sessionStorage.getItem(key);\n }\n\n setItem(key: string, value: string): void {\n if (typeof window === 'undefined') return;\n window.sessionStorage.setItem(key, value);\n }\n\n removeItem(key: string): void {\n if (typeof window === 'undefined') return;\n window.sessionStorage.removeItem(key);\n }\n\n clear(): void {\n if (typeof window === 'undefined') return;\n window.sessionStorage.clear();\n }\n}\n\n/**\n * In-memory storage adapter (for testing or SSR)\n */\nexport class MemoryStorageAdapter implements Storage {\n private store: Map<string, string> = new Map();\n\n getItem(key: string): string | null {\n return this.store.get(key) ?? null;\n }\n\n setItem(key: string, value: string): void {\n this.store.set(key, value);\n }\n\n removeItem(key: string): void {\n this.store.delete(key);\n }\n\n clear(): void {\n this.store.clear();\n }\n}\n\n","/**\n * Observable pattern for state management across frameworks\n */\n\nexport type Listener<T> = (value: T) => void;\nexport type Unsubscribe = () => void;\n\n/**\n * Observable state container\n */\nexport class Observable<T> {\n private value: T;\n private listeners: Set<Listener<T>> = new Set();\n\n constructor(initialValue: T) {\n this.value = initialValue;\n }\n\n /**\n * Get current value\n */\n getValue(): T {\n return this.value;\n }\n\n /**\n * Set new value and notify listeners\n */\n setValue(newValue: T): void {\n if (this.value !== newValue) {\n this.value = newValue;\n this.notify();\n }\n }\n\n /**\n * Update value with a function\n */\n update(updater: (current: T) => T): void {\n this.setValue(updater(this.value));\n }\n\n /**\n * Subscribe to value changes\n */\n subscribe(listener: Listener<T>): Unsubscribe {\n this.listeners.add(listener);\n // Immediately call listener with current value\n listener(this.value);\n\n // Return unsubscribe function\n return () => {\n this.listeners.delete(listener);\n };\n }\n\n /**\n * Notify all listeners\n */\n private notify(): void {\n this.listeners.forEach((listener) => listener(this.value));\n }\n\n /**\n * Clear all listeners\n */\n clearListeners(): void {\n this.listeners.clear();\n }\n\n /**\n * Get number of listeners\n */\n getListenerCount(): number {\n return this.listeners.size;\n }\n}\n\n"]}
1
+ {"version":3,"sources":["../../src/types/auth.ts","../../src/types/storage.ts","../../src/types/observable.ts"],"names":["AuthState","AuthErrorType","OAuthProvider","TwoFactorMethod"],"mappings":";AAOO,IAAK,SAAA,qBAAAA,UAAAA,KAAL;AACL,EAAAA,WAAA,eAAA,CAAA,GAAgB,eAAA;AAChB,EAAAA,WAAA,iBAAA,CAAA,GAAkB,iBAAA;AAClB,EAAAA,WAAA,SAAA,CAAA,GAAU,SAAA;AACV,EAAAA,WAAA,OAAA,CAAA,GAAQ,OAAA;AAJE,EAAA,OAAAA,UAAAA;AAAA,CAAA,EAAA,SAAA,IAAA,EAAA;AAwDL,IAAK,aAAA,qBAAAC,cAAAA,KAAL;AACL,EAAAA,eAAA,qBAAA,CAAA,GAAsB,qBAAA;AACtB,EAAAA,eAAA,gBAAA,CAAA,GAAiB,gBAAA;AACjB,EAAAA,eAAA,qBAAA,CAAA,GAAsB,qBAAA;AACtB,EAAAA,eAAA,eAAA,CAAA,GAAgB,eAAA;AAChB,EAAAA,eAAA,eAAA,CAAA,GAAgB,eAAA;AAChB,EAAAA,eAAA,eAAA,CAAA,GAAgB,eAAA;AAChB,EAAAA,eAAA,kBAAA,CAAA,GAAmB,kBAAA;AACnB,EAAAA,eAAA,cAAA,CAAA,GAAe,cAAA;AACf,EAAAA,eAAA,oBAAA,CAAA,GAAqB,oBAAA;AACrB,EAAAA,eAAA,oBAAA,CAAA,GAAqB,oBAAA;AACrB,EAAAA,eAAA,qBAAA,CAAA,GAAsB,qBAAA;AACtB,EAAAA,eAAA,eAAA,CAAA,GAAgB,eAAA;AAZN,EAAA,OAAAA,cAAAA;AAAA,CAAA,EAAA,aAAA,IAAA,EAAA;AAoBL,IAAM,SAAA,GAAN,MAAM,UAAA,SAAkB,KAAA,C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K,SAAA,CAAU,IAAI,QAAQ,CAAA;AAE3B,IAAA,QAAA,CAAS,KAAK,KAAK,CAAA;AAGnB,IAAA,OAAO,MAAM;AACX,MAAA,IAAA,CAAK,SAAA,CAAU,OAAO,QAAQ,CAAA;AAAA,IAChC,CAAA;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKQ,MAAA,GAAe;AACrB,IAAA,IAAA,CAAK,UAAU,OAAA,CAAQ,CAAC,aAAa,QAAA,CAAS,IAAA,CAAK,KAAK,CAAC,CAAA;AAAA,EAC3D;AAAA;AAAA;AAAA;AAAA,EAKA,cAAA,GAAuB;AACrB,IAAA,IAAA,CAAK,UAAU,KAAA,EAAM;AAAA,EACvB;AAAA;AAAA;AAAA;AAAA,EAKA,gBAAA,GAA2B;AACzB,IAAA,OAAO,KAAK,SAAA,CAAU,IAAA;AAAA,EACxB;AACF","file":"index.mjs","sourcesContent":["/**\n * Core authentication types and interfaces\n */\n\n/**\n * Authentication state enum\n */\nexport enum AuthState {\n AUTHENTICATED = 'authenticated',\n UNAUTHENTICATED = 'unauthenticated',\n LOADING = 'loading',\n ERROR = 'error',\n}\n\n/**\n * User profile interface\n */\nexport interface User {\n id: string;\n email?: string;\n username?: string;\n phone?: string;\n emailVerified?: boolean;\n phoneVerified?: boolean;\n name?: string;\n firstName?: string;\n lastName?: string;\n avatar?: string;\n metadata?: Record<string, unknown>;\n createdAt?: Date;\n updatedAt?: Date;\n \n // Organization fields\n organizationId?: string;\n organizationRole?: string;\n organizationMemberships?: OrganizationMembership[];\n}\n\n/**\n * Session interface\n */\nexport interface Session {\n id: string;\n userId: string;\n token: string;\n expiresAt?: Date;\n createdAt?: Date;\n metadata?: Record<string, unknown>;\n}\n\n/**\n * Session data with user and session combined\n * Used for efficient retrieval of both user and session in one call\n */\nexport interface SessionData {\n user: User;\n session: Session;\n expiresAt: number;\n}\n\n/**\n * Auth error types\n */\nexport enum AuthErrorType {\n INVALID_CREDENTIALS = 'invalid_credentials',\n USER_NOT_FOUND = 'user_not_found',\n USER_ALREADY_EXISTS = 'user_already_exists',\n INVALID_TOKEN = 'invalid_token',\n TOKEN_EXPIRED = 'token_expired',\n NETWORK_ERROR = 'network_error',\n VALIDATION_ERROR = 'validation_error',\n MFA_REQUIRED = 'mfa_required',\n EMAIL_NOT_VERIFIED = 'email_not_verified',\n PHONE_NOT_VERIFIED = 'phone_not_verified',\n RATE_LIMIT_EXCEEDED = 'rate_limit_exceeded',\n UNKNOWN_ERROR = 'unknown_error',\n}\n\n/**\n * Auth error class\n * \n * Extends Error to provide proper error handling with auth-specific context\n */\nexport class AuthError extends Error {\n public readonly type: AuthErrorType;\n public readonly details?: Record<string, unknown>;\n public readonly code?: string | number;\n public readonly originalError?: unknown;\n\n constructor(\n message: string,\n type: AuthErrorType = AuthErrorType.UNKNOWN_ERROR,\n options?: {\n details?: Record<string, unknown>;\n code?: string | number;\n originalError?: unknown;\n }\n ) {\n super(message);\n this.name = 'AuthError';\n this.type = type;\n this.details = options?.details;\n this.code = options?.code;\n this.originalError = options?.originalError;\n\n // Maintains proper stack trace for where our error was thrown (only available on V8)\n if (Error.captureStackTrace) {\n Error.captureStackTrace(this, AuthError);\n }\n }\n}\n\n/**\n * Auth context state\n */\nexport interface AuthContext {\n state: AuthState;\n user: User | null;\n session: Session | null;\n error: AuthError | null;\n isAuthenticated: boolean;\n isLoading: boolean;\n}\n\n/**\n * OAuth provider types\n */\nexport enum OAuthProvider {\n GOOGLE = 'google',\n GITHUB = 'github',\n FACEBOOK = 'facebook',\n TWITTER = 'twitter',\n MICROSOFT = 'microsoft',\n APPLE = 'apple',\n LINKEDIN = 'linkedin',\n DISCORD = 'discord',\n}\n\n/**\n * OAuth configuration\n */\nexport interface OAuthConfig {\n provider: OAuthProvider;\n clientId: string;\n redirectUri: string;\n scope?: string[];\n state?: string;\n}\n\n/**\n * 2FA method types\n */\nexport enum TwoFactorMethod {\n TOTP = 'totp',\n SMS = 'sms',\n EMAIL = 'email',\n BACKUP_CODE = 'backup_code',\n}\n\n/**\n * 2FA configuration\n */\nexport interface TwoFactorConfig {\n method: TwoFactorMethod;\n enabled: boolean;\n verified?: boolean;\n}\n\n/**\n * Passkey/WebAuthn types\n */\nexport interface PasskeyCredential {\n id: string;\n name?: string;\n createdAt?: Date;\n lastUsedAt?: Date;\n}\n\n/**\n * Validation error\n */\nexport interface ValidationError {\n field: string;\n message: string;\n code?: string;\n}\n\n/**\n * Organization interface\n */\nexport interface Organization {\n id: string;\n name: string;\n slug: string;\n logoUrl?: string;\n createdAt?: Date;\n metadata?: Record<string, unknown>;\n}\n\n/**\n * Organization membership interface\n */\nexport interface OrganizationMembership {\n organization: Organization;\n role: 'owner' | 'admin' | 'member';\n permissions?: string[];\n}\n\n/**\n * Device Flow types (RFC 8628 - OAuth 2.0 Device Authorization Grant)\n */\n\n/**\n * Request to initiate device flow\n * Used by CLI/device applications to start the authorization process\n */\nexport interface DeviceFlowInitiateRequest {\n clientId: string;\n scope?: string;\n}\n\n/**\n * Response from device flow initiation\n * Contains codes and URIs needed for user authorization\n */\nexport interface DeviceFlowInitiateResponse {\n /** The device verification code (long, secret code for polling) */\n deviceCode: string;\n /** The user-facing code to enter in browser (short, easy-to-type) */\n userCode: string;\n /** The URL to visit for verification */\n verificationUri: string;\n /** Optional complete URL with user_code pre-filled */\n verificationUriComplete?: string;\n /** Lifetime of device_code and user_code in seconds */\n expiresIn: number;\n /** Minimum polling interval in seconds */\n interval: number;\n}\n\n/**\n * Request to verify a user-entered device code\n * Used by the web UI when user enters their code\n */\nexport interface DeviceCodeVerifyRequest {\n userCode: string;\n}\n\n/**\n * Response from device code verification\n * Contains information about the pending authorization\n */\nexport interface DeviceCodeVerifyResponse {\n /** Whether the code is valid */\n valid: boolean;\n /** Client application name requesting access */\n clientName?: string;\n /** Scopes being requested */\n scopes?: string[];\n /** Time remaining before code expires */\n expiresIn?: number;\n}\n\n/**\n * Request to authorize/deny a device\n * Used when user approves or denies the authorization request\n */\nexport interface DeviceAuthorizeRequest {\n userCode: string;\n action: 'approve' | 'deny';\n}\n\n/**\n * Request to poll for device token\n * Used by CLI/device to check if user has authorized\n */\nexport interface DeviceTokenPollRequest {\n deviceCode: string;\n clientId: string;\n}\n\n/**\n * Status returned when polling is not yet complete\n */\nexport type DeviceTokenPollStatus = \n | 'authorization_pending' // User hasn't authorized yet\n | 'slow_down' // Polling too frequently\n | 'expired_token' // Device code expired\n | 'access_denied'; // User denied authorization\n\n/**\n * Response from device token polling\n * Either contains the auth response or a status indicator\n */\nexport interface DeviceTokenPollResponse {\n status: DeviceTokenPollStatus;\n}\n","/**\n * Storage abstraction for auth tokens and data\n */\n\n/**\n * Storage interface\n */\nexport interface Storage {\n /**\n * Get item from storage\n */\n getItem(key: string): Promise<string | null> | string | null;\n\n /**\n * Set item in storage\n */\n setItem(key: string, value: string): Promise<void> | void;\n\n /**\n * Remove item from storage\n */\n removeItem(key: string): Promise<void> | void;\n\n /**\n * Clear all items from storage\n */\n clear(): Promise<void> | void;\n}\n\n/**\n * Storage adapter for localStorage\n */\nexport class LocalStorageAdapter implements Storage {\n getItem(key: string): string | null {\n if (typeof window === 'undefined') return null;\n return window.localStorage.getItem(key);\n }\n\n setItem(key: string, value: string): void {\n if (typeof window === 'undefined') return;\n window.localStorage.setItem(key, value);\n }\n\n removeItem(key: string): void {\n if (typeof window === 'undefined') return;\n window.localStorage.removeItem(key);\n }\n\n clear(): void {\n if (typeof window === 'undefined') return;\n window.localStorage.clear();\n }\n}\n\n/**\n * Storage adapter for sessionStorage\n */\nexport class SessionStorageAdapter implements Storage {\n getItem(key: string): string | null {\n if (typeof window === 'undefined') return null;\n return window.sessionStorage.getItem(key);\n }\n\n setItem(key: string, value: string): void {\n if (typeof window === 'undefined') return;\n window.sessionStorage.setItem(key, value);\n }\n\n removeItem(key: string): void {\n if (typeof window === 'undefined') return;\n window.sessionStorage.removeItem(key);\n }\n\n clear(): void {\n if (typeof window === 'undefined') return;\n window.sessionStorage.clear();\n }\n}\n\n/**\n * In-memory storage adapter (for testing or SSR)\n */\nexport class MemoryStorageAdapter implements Storage {\n private store: Map<string, string> = new Map();\n\n getItem(key: string): string | null {\n return this.store.get(key) ?? null;\n }\n\n setItem(key: string, value: string): void {\n this.store.set(key, value);\n }\n\n removeItem(key: string): void {\n this.store.delete(key);\n }\n\n clear(): void {\n this.store.clear();\n }\n}\n\n","/**\n * Observable pattern for state management across frameworks\n */\n\nexport type Listener<T> = (value: T) => void;\nexport type Unsubscribe = () => void;\n\n/**\n * Observable state container\n */\nexport class Observable<T> {\n private value: T;\n private listeners: Set<Listener<T>> = new Set();\n\n constructor(initialValue: T) {\n this.value = initialValue;\n }\n\n /**\n * Get current value\n */\n getValue(): T {\n return this.value;\n }\n\n /**\n * Set new value and notify listeners\n */\n setValue(newValue: T): void {\n if (this.value !== newValue) {\n this.value = newValue;\n this.notify();\n }\n }\n\n /**\n * Update value with a function\n */\n update(updater: (current: T) => T): void {\n this.setValue(updater(this.value));\n }\n\n /**\n * Subscribe to value changes\n */\n subscribe(listener: Listener<T>): Unsubscribe {\n this.listeners.add(listener);\n // Immediately call listener with current value\n listener(this.value);\n\n // Return unsubscribe function\n return () => {\n this.listeners.delete(listener);\n };\n }\n\n /**\n * Notify all listeners\n */\n private notify(): void {\n this.listeners.forEach((listener) => listener(this.value));\n }\n\n /**\n * Clear all listeners\n */\n clearListeners(): void {\n this.listeners.clear();\n }\n\n /**\n * Get number of listeners\n */\n getListenerCount(): number {\n return this.listeners.size;\n }\n}\n\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@authsome/ui-core",
3
- "version": "0.1.8",
3
+ "version": "0.1.9",
4
4
  "description": "Framework-agnostic authentication core for AuthSome UI",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",