@authsome/ui-core 0.1.7 → 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.
@@ -1,4 +1,4 @@
1
- import { c as AuthProvider, G as ProviderConfig, S as SignInRequest, E as AuthResponse, d as SignUpRequest, t as User, u as Session, w as SessionData, U as UpdateUserRequest, P as PasswordChangeRequest, e as PasswordResetRequest, f as PasswordResetConfirmRequest, O as OAuthSignInRequest, g as OAuthCallbackRequest, h as OAuthProvider, M as MagicLinkRequest, i as MagicLinkVerifyRequest, j as PhoneAuthRequest, k as PhoneVerifyRequest, T as TwoFactorSetupRequest, l as TwoFactorSetupResponse, m as TwoFactorVerifyRequest, n as TwoFactorMethod, o as PasskeyRegisterRequest, p as PasskeyCredential, q as PasskeyAuthRequest, R as RequestContext, C as CookieData, a as AuthError } from '../provider-Du6Oe4tD.mjs';
1
+ import { c as AuthProvider, R as ProviderConfig, S as SignInRequest, Q as AuthResponse, d as SignUpRequest, t as User, u as Session, w as SessionData, U as UpdateUserRequest, P as PasswordChangeRequest, e as PasswordResetRequest, f as PasswordResetConfirmRequest, O as OAuthSignInRequest, g as OAuthCallbackRequest, h as OAuthProvider, M as MagicLinkRequest, i as MagicLinkVerifyRequest, j as PhoneAuthRequest, k as PhoneVerifyRequest, T as TwoFactorSetupRequest, l as TwoFactorSetupResponse, m as TwoFactorVerifyRequest, n as TwoFactorMethod, o as PasskeyRegisterRequest, p as PasskeyCredential, q as PasskeyAuthRequest, D as DeviceFlowInitiateRequest, z as DeviceFlowInitiateResponse, B as DeviceCodeVerifyRequest, E as DeviceCodeVerifyResponse, F as DeviceAuthorizeRequest, G as DeviceTokenPollRequest, I as DeviceTokenPollResponse, W as RequestContext, C as CookieData, a as AuthError } from '../provider-DWklI8Wr.mjs';
2
2
 
3
3
  /**
4
4
  * Base auth provider implementation
@@ -49,6 +49,26 @@ declare abstract class BaseAuthProvider implements AuthProvider {
49
49
  abstract authenticatePasskey(request: PasskeyAuthRequest): Promise<AuthResponse>;
50
50
  abstract listPasskeys(): Promise<PasskeyCredential[]>;
51
51
  abstract deletePasskey(credentialId: string): Promise<void>;
52
+ /**
53
+ * Initiate device authorization flow
54
+ * Returns device code, user code, and verification URI
55
+ */
56
+ abstract initiateDeviceFlow(request: DeviceFlowInitiateRequest): Promise<DeviceFlowInitiateResponse>;
57
+ /**
58
+ * Verify a user-entered device code
59
+ * Called by web UI when user enters the code shown on their device
60
+ */
61
+ abstract verifyDeviceCode(request: DeviceCodeVerifyRequest): Promise<DeviceCodeVerifyResponse>;
62
+ /**
63
+ * Authorize or deny the device request
64
+ * Called when user approves or denies the authorization
65
+ */
66
+ abstract authorizeDevice(request: DeviceAuthorizeRequest): Promise<void>;
67
+ /**
68
+ * Poll for device token (used by CLI/device)
69
+ * Returns auth response when authorized, or status when still pending
70
+ */
71
+ abstract pollDeviceToken(request: DeviceTokenPollRequest): Promise<AuthResponse | DeviceTokenPollResponse>;
52
72
  /**
53
73
  * Optional edge runtime context methods
54
74
  * Default implementations do nothing - subclasses can override
@@ -1,4 +1,4 @@
1
- import { c as AuthProvider, G as ProviderConfig, S as SignInRequest, E as AuthResponse, d as SignUpRequest, t as User, u as Session, w as SessionData, U as UpdateUserRequest, P as PasswordChangeRequest, e as PasswordResetRequest, f as PasswordResetConfirmRequest, O as OAuthSignInRequest, g as OAuthCallbackRequest, h as OAuthProvider, M as MagicLinkRequest, i as MagicLinkVerifyRequest, j as PhoneAuthRequest, k as PhoneVerifyRequest, T as TwoFactorSetupRequest, l as TwoFactorSetupResponse, m as TwoFactorVerifyRequest, n as TwoFactorMethod, o as PasskeyRegisterRequest, p as PasskeyCredential, q as PasskeyAuthRequest, R as RequestContext, C as CookieData, a as AuthError } from '../provider-Du6Oe4tD.js';
1
+ import { c as AuthProvider, R as ProviderConfig, S as SignInRequest, Q as AuthResponse, d as SignUpRequest, t as User, u as Session, w as SessionData, U as UpdateUserRequest, P as PasswordChangeRequest, e as PasswordResetRequest, f as PasswordResetConfirmRequest, O as OAuthSignInRequest, g as OAuthCallbackRequest, h as OAuthProvider, M as MagicLinkRequest, i as MagicLinkVerifyRequest, j as PhoneAuthRequest, k as PhoneVerifyRequest, T as TwoFactorSetupRequest, l as TwoFactorSetupResponse, m as TwoFactorVerifyRequest, n as TwoFactorMethod, o as PasskeyRegisterRequest, p as PasskeyCredential, q as PasskeyAuthRequest, D as DeviceFlowInitiateRequest, z as DeviceFlowInitiateResponse, B as DeviceCodeVerifyRequest, E as DeviceCodeVerifyResponse, F as DeviceAuthorizeRequest, G as DeviceTokenPollRequest, I as DeviceTokenPollResponse, W as RequestContext, C as CookieData, a as AuthError } from '../provider-DWklI8Wr.js';
2
2
 
3
3
  /**
4
4
  * Base auth provider implementation
@@ -49,6 +49,26 @@ declare abstract class BaseAuthProvider implements AuthProvider {
49
49
  abstract authenticatePasskey(request: PasskeyAuthRequest): Promise<AuthResponse>;
50
50
  abstract listPasskeys(): Promise<PasskeyCredential[]>;
51
51
  abstract deletePasskey(credentialId: string): Promise<void>;
52
+ /**
53
+ * Initiate device authorization flow
54
+ * Returns device code, user code, and verification URI
55
+ */
56
+ abstract initiateDeviceFlow(request: DeviceFlowInitiateRequest): Promise<DeviceFlowInitiateResponse>;
57
+ /**
58
+ * Verify a user-entered device code
59
+ * Called by web UI when user enters the code shown on their device
60
+ */
61
+ abstract verifyDeviceCode(request: DeviceCodeVerifyRequest): Promise<DeviceCodeVerifyResponse>;
62
+ /**
63
+ * Authorize or deny the device request
64
+ * Called when user approves or denies the authorization
65
+ */
66
+ abstract authorizeDevice(request: DeviceAuthorizeRequest): Promise<void>;
67
+ /**
68
+ * Poll for device token (used by CLI/device)
69
+ * Returns auth response when authorized, or status when still pending
70
+ */
71
+ abstract pollDeviceToken(request: DeviceTokenPollRequest): Promise<AuthResponse | DeviceTokenPollResponse>;
52
72
  /**
53
73
  * Optional edge runtime context methods
54
74
  * Default implementations do nothing - subclasses can override
@@ -1 +1 @@
1
- {"version":3,"sources":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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 * Error handling utilities\n */\n\nimport { AuthError, AuthErrorType } from '../types';\n\n/**\n * Create an auth error\n * \n * @deprecated Use `new AuthError()` directly instead\n */\nexport function createAuthError(\n type: AuthErrorType,\n message: string,\n details?: Record<string, unknown>,\n code?: string | number\n): AuthError {\n return new AuthError(message, type, { details, code });\n}\n\n/**\n * Check if an error is an auth error\n */\nexport function isAuthError(error: unknown): error is AuthError {\n return error instanceof AuthError;\n}\n\n/**\n * Convert unknown error to auth error\n */\nexport function toAuthError(error: unknown): AuthError {\n if (isAuthError(error)) {\n return error;\n }\n\n if (error instanceof Error) {\n return new AuthError(error.message, AuthErrorType.UNKNOWN_ERROR, {\n details: {\n originalError: error.name,\n stack: error.stack,\n },\n });\n }\n\n if (typeof error === 'string') {\n return new AuthError(error, AuthErrorType.UNKNOWN_ERROR);\n }\n\n return new AuthError(\n 'An unknown error occurred',\n AuthErrorType.UNKNOWN_ERROR,\n { details: { error } }\n );\n}\n\n/**\n * Check if error is a network error\n */\nexport function isNetworkError(error: unknown): boolean {\n if (error instanceof Error) {\n return (\n error.name === 'NetworkError' ||\n error.message.includes('network') ||\n error.message.includes('fetch')\n );\n }\n return false;\n}\n\n/**\n * Check if error indicates authentication is required\n */\nexport function isUnauthenticatedError(error: unknown): boolean {\n if (isAuthError(error)) {\n return (\n error.type === AuthErrorType.INVALID_TOKEN ||\n error.type === AuthErrorType.TOKEN_EXPIRED\n );\n }\n return false;\n}\n\n/**\n * Check if error requires MFA\n */\nexport function isMFARequiredError(error: unknown): boolean {\n if (isAuthError(error)) {\n return error.type === AuthErrorType.MFA_REQUIRED;\n }\n return false;\n}\n","/**\n * Base auth provider implementation\n */\n\nimport type {\n AuthProvider,\n AuthResponse,\n SignInRequest,\n SignUpRequest,\n UpdateUserRequest,\n PasswordChangeRequest,\n PasswordResetRequest,\n PasswordResetConfirmRequest,\n OAuthSignInRequest,\n OAuthCallbackRequest,\n MagicLinkRequest,\n MagicLinkVerifyRequest,\n PhoneAuthRequest,\n PhoneVerifyRequest,\n TwoFactorSetupRequest,\n TwoFactorSetupResponse,\n TwoFactorVerifyRequest,\n PasskeyRegisterRequest,\n PasskeyAuthRequest,\n User,\n Session,\n SessionData,\n OAuthProvider,\n TwoFactorMethod,\n PasskeyCredential,\n AuthError,\n ProviderConfig,\n RequestContext,\n CookieData,\n} from '../types';\nimport { toAuthError } from '../utils';\n\n/**\n * Base provider class with common functionality\n */\nexport abstract class BaseAuthProvider implements AuthProvider {\n abstract readonly name: string;\n protected config: ProviderConfig = {};\n protected initialized = false;\n\n /**\n * Initialize the provider\n */\n async initialize(config: ProviderConfig): Promise<void> {\n this.config = config;\n this.initialized = true;\n }\n\n /**\n * Ensure provider is initialized\n */\n protected ensureInitialized(): void {\n if (!this.initialized) {\n throw new Error(`Provider ${this.name} is not initialized`);\n }\n }\n\n /**\n * Make HTTP request\n */\n protected async request<T>(\n url: string,\n options: RequestInit = {}\n ): Promise<T> {\n const response = await fetch(url, {\n ...options,\n headers: {\n 'Content-Type': 'application/json',\n ...options.headers,\n },\n });\n\n if (!response.ok) {\n const error = await response.json().catch(() => ({\n message: response.statusText,\n }));\n throw error;\n }\n\n return response.json();\n }\n\n // Abstract methods that must be implemented by subclasses\n abstract signIn(request: SignInRequest): Promise<AuthResponse>;\n abstract signUp(request: SignUpRequest): Promise<AuthResponse>;\n abstract signOut(): Promise<void>;\n abstract getCurrentUser(): Promise<User | null>;\n abstract getCurrentSession(): Promise<Session | null>;\n abstract getCurrentSessionData(): Promise<SessionData | null>;\n abstract refreshSession(): Promise<Session>;\n abstract updateUser(request: UpdateUserRequest): Promise<User>;\n abstract changePassword(request: PasswordChangeRequest): Promise<void>;\n abstract requestPasswordReset(request: PasswordResetRequest): Promise<void>;\n abstract confirmPasswordReset(request: PasswordResetConfirmRequest): Promise<void>;\n abstract oauthSignIn(request: OAuthSignInRequest): Promise<string>;\n abstract oauthCallback(request: OAuthCallbackRequest): Promise<AuthResponse>;\n abstract getOAuthProviders(): Promise<OAuthProvider[]>;\n abstract sendMagicLink(request: MagicLinkRequest): Promise<void>;\n abstract verifyMagicLink(request: MagicLinkVerifyRequest): Promise<AuthResponse>;\n abstract sendPhoneCode(request: PhoneAuthRequest): Promise<void>;\n abstract verifyPhoneCode(request: PhoneVerifyRequest): Promise<AuthResponse>;\n abstract setupTwoFactor(request: TwoFactorSetupRequest): Promise<TwoFactorSetupResponse>;\n abstract verifyTwoFactor(request: TwoFactorVerifyRequest): Promise<AuthResponse>;\n abstract disableTwoFactor(): Promise<void>;\n abstract getTwoFactorStatus(): Promise<TwoFactorMethod[]>;\n abstract registerPasskey(request: PasskeyRegisterRequest): Promise<PasskeyCredential>;\n abstract authenticatePasskey(request: PasskeyAuthRequest): Promise<AuthResponse>;\n abstract listPasskeys(): Promise<PasskeyCredential[]>;\n abstract deletePasskey(credentialId: string): Promise<void>;\n\n /**\n * Optional edge runtime context methods\n * Default implementations do nothing - subclasses can override\n */\n setContext?(context: RequestContext): void;\n getCookies?(): CookieData[];\n clearContext?(): void;\n\n /**\n * Normalize error to AuthError\n */\n normalizeError(error: unknown): AuthError {\n return toAuthError(error);\n }\n}\n\n"]}
1
+ {"version":3,"sources":["../../src/types/auth.ts","../../src/utils/errors.ts","../../src/adapters/base-provider.ts"],"names":[],"mappings":";;;AAmFO,IAAM,SAAA,GAAN,MAAM,UAAA,SAAkB,KAAA,CAAM;AAAA,EAMnC,WAAA,CACE,OAAA,EACA,IAAA,GAAsB,eAAA,sBACtB,OAAA,EAKA;AACA,IAAA,KAAA,CAAM,OAAO,CAAA;AACb,IAAA,IAAA,CAAK,IAAA,GAAO,WAAA;AACZ,IAAA,IAAA,CAAK,IAAA,GAAO,IAAA;AACZ,IAAA,IAAA,CAAK,UAAU,OAAA,EAAS,OAAA;AACxB,IAAA,IAAA,CAAK,OAAO,OAAA,EAAS,IAAA;AACrB,IAAA,IAAA,CAAK,gBAAgB,OAAA,EAAS,aAAA;AAG9B,IAAA,IAAI,MAAM,iBAAA,EAAmB;AAC3B,MAAA,KAAA,CAAM,iBAAA,CAAkB,MAAM,UAAS,CAAA;AAAA,IACzC;AAAA,EACF;AACF,CAAA;;;ACvFO,SAAS,YAAY,KAAA,EAAoC;AAC9D,EAAA,OAAO,KAAA,YAA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MAAM,KAAA,CAAM,GAAA,EAAK;AAAA,MAChC,GAAG,OAAA;AAAA,MACH,OAAA,EAAS;AAAA,QACP,cAAA,EAAgB,kBAAA;AAAA,QAChB,GAAG,OAAA,CAAQ;AAAA;AACb,KACD,CAAA;AAED,IAAA,IAAI,CAAC,SAAS,EAAA,EAAI;AAChB,MAAA,MAAM,QAAQ,MAAM,QAAA,CAAS,IAAA,EAAK,CAAE,MAAM,OAAO;AAAA,QAC/C,SAAS,QAAA,CAAS;AAAA,OACpB,CAAE,CAAA;AACF,MAAA,MAAM,KAAA;AAAA,IACR;AAEA,IAAA,OAAO,SAAS,IAAA,EAAK;AAAA,EACvB;AAAA;AAAA;AAAA;AAAA,EAkEA,eAAe,KAAA,EAA2B;AACxC,IAAA,OAAO,YAAY,KAAK,CAAA;AAAA,EAC1B;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 * Error handling utilities\n */\n\nimport { AuthError, AuthErrorType } from '../types';\n\n/**\n * Create an auth error\n * \n * @deprecated Use `new AuthError()` directly instead\n */\nexport function createAuthError(\n type: AuthErrorType,\n message: string,\n details?: Record<string, unknown>,\n code?: string | number\n): AuthError {\n return new AuthError(message, type, { details, code });\n}\n\n/**\n * Check if an error is an auth error\n */\nexport function isAuthError(error: unknown): error is AuthError {\n return error instanceof AuthError;\n}\n\n/**\n * Convert unknown error to auth error\n */\nexport function toAuthError(error: unknown): AuthError {\n if (isAuthError(error)) {\n return error;\n }\n\n if (error instanceof Error) {\n return new AuthError(error.message, AuthErrorType.UNKNOWN_ERROR, {\n details: {\n originalError: error.name,\n stack: error.stack,\n },\n });\n }\n\n if (typeof error === 'string') {\n return new AuthError(error, AuthErrorType.UNKNOWN_ERROR);\n }\n\n return new AuthError(\n 'An unknown error occurred',\n AuthErrorType.UNKNOWN_ERROR,\n { details: { error } }\n );\n}\n\n/**\n * Check if error is a network error\n */\nexport function isNetworkError(error: unknown): boolean {\n if (error instanceof Error) {\n return (\n error.name === 'NetworkError' ||\n error.message.includes('network') ||\n error.message.includes('fetch')\n );\n }\n return false;\n}\n\n/**\n * Check if error indicates authentication is required\n */\nexport function isUnauthenticatedError(error: unknown): boolean {\n if (isAuthError(error)) {\n return (\n error.type === AuthErrorType.INVALID_TOKEN ||\n error.type === AuthErrorType.TOKEN_EXPIRED\n );\n }\n return false;\n}\n\n/**\n * Check if error requires MFA\n */\nexport function isMFARequiredError(error: unknown): boolean {\n if (isAuthError(error)) {\n return error.type === AuthErrorType.MFA_REQUIRED;\n }\n return false;\n}\n","/**\n * Base auth provider implementation\n */\n\nimport type {\n AuthProvider,\n AuthResponse,\n SignInRequest,\n SignUpRequest,\n UpdateUserRequest,\n PasswordChangeRequest,\n PasswordResetRequest,\n PasswordResetConfirmRequest,\n OAuthSignInRequest,\n OAuthCallbackRequest,\n MagicLinkRequest,\n MagicLinkVerifyRequest,\n PhoneAuthRequest,\n PhoneVerifyRequest,\n TwoFactorSetupRequest,\n TwoFactorSetupResponse,\n TwoFactorVerifyRequest,\n PasskeyRegisterRequest,\n PasskeyAuthRequest,\n User,\n Session,\n SessionData,\n OAuthProvider,\n TwoFactorMethod,\n PasskeyCredential,\n AuthError,\n ProviderConfig,\n RequestContext,\n CookieData,\n DeviceFlowInitiateRequest,\n DeviceFlowInitiateResponse,\n DeviceCodeVerifyRequest,\n DeviceCodeVerifyResponse,\n DeviceAuthorizeRequest,\n DeviceTokenPollRequest,\n DeviceTokenPollResponse,\n} from '../types';\nimport { toAuthError } from '../utils';\n\n/**\n * Base provider class with common functionality\n */\nexport abstract class BaseAuthProvider implements AuthProvider {\n abstract readonly name: string;\n protected config: ProviderConfig = {};\n protected initialized = false;\n\n /**\n * Initialize the provider\n */\n async initialize(config: ProviderConfig): Promise<void> {\n this.config = config;\n this.initialized = true;\n }\n\n /**\n * Ensure provider is initialized\n */\n protected ensureInitialized(): void {\n if (!this.initialized) {\n throw new Error(`Provider ${this.name} is not initialized`);\n }\n }\n\n /**\n * Make HTTP request\n */\n protected async request<T>(\n url: string,\n options: RequestInit = {}\n ): Promise<T> {\n const response = await fetch(url, {\n ...options,\n headers: {\n 'Content-Type': 'application/json',\n ...options.headers,\n },\n });\n\n if (!response.ok) {\n const error = await response.json().catch(() => ({\n message: response.statusText,\n }));\n throw error;\n }\n\n return response.json();\n }\n\n // Abstract methods that must be implemented by subclasses\n abstract signIn(request: SignInRequest): Promise<AuthResponse>;\n abstract signUp(request: SignUpRequest): Promise<AuthResponse>;\n abstract signOut(): Promise<void>;\n abstract getCurrentUser(): Promise<User | null>;\n abstract getCurrentSession(): Promise<Session | null>;\n abstract getCurrentSessionData(): Promise<SessionData | null>;\n abstract refreshSession(): Promise<Session>;\n abstract updateUser(request: UpdateUserRequest): Promise<User>;\n abstract changePassword(request: PasswordChangeRequest): Promise<void>;\n abstract requestPasswordReset(request: PasswordResetRequest): Promise<void>;\n abstract confirmPasswordReset(request: PasswordResetConfirmRequest): Promise<void>;\n abstract oauthSignIn(request: OAuthSignInRequest): Promise<string>;\n abstract oauthCallback(request: OAuthCallbackRequest): Promise<AuthResponse>;\n abstract getOAuthProviders(): Promise<OAuthProvider[]>;\n abstract sendMagicLink(request: MagicLinkRequest): Promise<void>;\n abstract verifyMagicLink(request: MagicLinkVerifyRequest): Promise<AuthResponse>;\n abstract sendPhoneCode(request: PhoneAuthRequest): Promise<void>;\n abstract verifyPhoneCode(request: PhoneVerifyRequest): Promise<AuthResponse>;\n abstract setupTwoFactor(request: TwoFactorSetupRequest): Promise<TwoFactorSetupResponse>;\n abstract verifyTwoFactor(request: TwoFactorVerifyRequest): Promise<AuthResponse>;\n abstract disableTwoFactor(): Promise<void>;\n abstract getTwoFactorStatus(): Promise<TwoFactorMethod[]>;\n abstract registerPasskey(request: PasskeyRegisterRequest): Promise<PasskeyCredential>;\n abstract authenticatePasskey(request: PasskeyAuthRequest): Promise<AuthResponse>;\n abstract listPasskeys(): Promise<PasskeyCredential[]>;\n abstract deletePasskey(credentialId: string): Promise<void>;\n\n // Device Flow methods (RFC 8628 - OAuth 2.0 Device Authorization Grant)\n /**\n * Initiate device authorization flow\n * Returns device code, user code, and verification URI\n */\n abstract initiateDeviceFlow(request: DeviceFlowInitiateRequest): Promise<DeviceFlowInitiateResponse>;\n \n /**\n * Verify a user-entered device code\n * Called by web UI when user enters the code shown on their device\n */\n abstract verifyDeviceCode(request: DeviceCodeVerifyRequest): Promise<DeviceCodeVerifyResponse>;\n \n /**\n * Authorize or deny the device request\n * Called when user approves or denies the authorization\n */\n abstract authorizeDevice(request: DeviceAuthorizeRequest): Promise<void>;\n \n /**\n * Poll for device token (used by CLI/device)\n * Returns auth response when authorized, or status when still pending\n */\n abstract pollDeviceToken(request: DeviceTokenPollRequest): Promise<AuthResponse | DeviceTokenPollResponse>;\n\n /**\n * Optional edge runtime context methods\n * Default implementations do nothing - subclasses can override\n */\n setContext?(context: RequestContext): void;\n getCookies?(): CookieData[];\n clearContext?(): void;\n\n /**\n * Normalize error to AuthError\n */\n normalizeError(error: unknown): AuthError {\n return toAuthError(error);\n }\n}\n\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/types/auth.ts","../../src/utils/errors.ts","../../src/adapters/base-provider.ts"],"names":[],"mappings":";AAmFO,IAAM,SAAA,GAAN,MAAM,UAAA,SAAkB,KAAA,CAAM;AAAA,EAMnC,WAAA,CACE,OAAA,EACA,IAAA,GAAsB,eAAA,sBACtB,OAAA,EAKA;AACA,IAAA,KAAA,CAAM,OAAO,CAAA;AACb,IAAA,IAAA,CAAK,IAAA,GAAO,WAAA;AACZ,IAAA,IAAA,CAAK,IAAA,GAAO,IAAA;AACZ,IAAA,IAAA,CAAK,UAAU,OAAA,EAAS,OAAA;AACxB,IAAA,IAAA,CAAK,OAAO,OAAA,EAAS,IAAA;AACrB,IAAA,IAAA,CAAK,gBAAgB,OAAA,EAAS,aAAA;AAG9B,IAAA,IAAI,MAAM,iBAAA,EAAmB;AAC3B,MAAA,KAAA,CAAM,iBAAA,CAAkB,MAAM,UAAS,CAAA;AAAA,IACzC;AAAA,EACF;AACF,CAAA;;;ACvFO,SAAS,YAAY,KAAA,EAAoC;AAC9D,EAAA,OAAO,KAAA,YAAiB,SAAA;AAC1B;AAKO,SAAS,YAAY,KAAA,EAA2B;AACrD,EAAA,IAAI,WAAA,CAAY,KAAK,CAAA,EAAG;AACtB,IAAA,OAAO,KAAA;A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AAG,OAAA,CAAQ;AAAA;AACb,KACD,CAAA;AAED,IAAA,IAAI,CAAC,SAAS,EAAA,EAAI;AAChB,MAAA,MAAM,QAAQ,MAAM,QAAA,CAAS,IAAA,EAAK,CAAE,MAAM,OAAO;AAAA,QAC/C,SAAS,QAAA,CAAS;AAAA,OACpB,CAAE,CAAA;AACF,MAAA,MAAM,KAAA;AAAA,IACR;AAEA,IAAA,OAAO,SAAS,IAAA,EAAK;AAAA,EACvB;AAAA;AAAA;AAAA;AAAA,EAyCA,eAAe,KAAA,EAA2B;AACxC,IAAA,OAAO,YAAY,KAAK,CAAA;AAAA,EAC1B;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 * Error handling utilities\n */\n\nimport { AuthError, AuthErrorType } from '../types';\n\n/**\n * Create an auth error\n * \n * @deprecated Use `new AuthError()` directly instead\n */\nexport function createAuthError(\n type: AuthErrorType,\n message: string,\n details?: Record<string, unknown>,\n code?: string | number\n): AuthError {\n return new AuthError(message, type, { details, code });\n}\n\n/**\n * Check if an error is an auth error\n */\nexport function isAuthError(error: unknown): error is AuthError {\n return error instanceof AuthError;\n}\n\n/**\n * Convert unknown error to auth error\n */\nexport function toAuthError(error: unknown): AuthError {\n if (isAuthError(error)) {\n return error;\n }\n\n if (error instanceof Error) {\n return new AuthError(error.message, AuthErrorType.UNKNOWN_ERROR, {\n details: {\n originalError: error.name,\n stack: error.stack,\n },\n });\n }\n\n if (typeof error === 'string') {\n return new AuthError(error, AuthErrorType.UNKNOWN_ERROR);\n }\n\n return new AuthError(\n 'An unknown error occurred',\n AuthErrorType.UNKNOWN_ERROR,\n { details: { error } }\n );\n}\n\n/**\n * Check if error is a network error\n */\nexport function isNetworkError(error: unknown): boolean {\n if (error instanceof Error) {\n return (\n error.name === 'NetworkError' ||\n error.message.includes('network') ||\n error.message.includes('fetch')\n );\n }\n return false;\n}\n\n/**\n * Check if error indicates authentication is required\n */\nexport function isUnauthenticatedError(error: unknown): boolean {\n if (isAuthError(error)) {\n return (\n error.type === AuthErrorType.INVALID_TOKEN ||\n error.type === AuthErrorType.TOKEN_EXPIRED\n );\n }\n return false;\n}\n\n/**\n * Check if error requires MFA\n */\nexport function isMFARequiredError(error: unknown): boolean {\n if (isAuthError(error)) {\n return error.type === AuthErrorType.MFA_REQUIRED;\n }\n return false;\n}\n","/**\n * Base auth provider implementation\n */\n\nimport type {\n AuthProvider,\n AuthResponse,\n SignInRequest,\n SignUpRequest,\n UpdateUserRequest,\n PasswordChangeRequest,\n PasswordResetRequest,\n PasswordResetConfirmRequest,\n OAuthSignInRequest,\n OAuthCallbackRequest,\n MagicLinkRequest,\n MagicLinkVerifyRequest,\n PhoneAuthRequest,\n PhoneVerifyRequest,\n TwoFactorSetupRequest,\n TwoFactorSetupResponse,\n TwoFactorVerifyRequest,\n PasskeyRegisterRequest,\n PasskeyAuthRequest,\n User,\n Session,\n SessionData,\n OAuthProvider,\n TwoFactorMethod,\n PasskeyCredential,\n AuthError,\n ProviderConfig,\n RequestContext,\n CookieData,\n} from '../types';\nimport { toAuthError } from '../utils';\n\n/**\n * Base provider class with common functionality\n */\nexport abstract class BaseAuthProvider implements AuthProvider {\n abstract readonly name: string;\n protected config: ProviderConfig = {};\n protected initialized = false;\n\n /**\n * Initialize the provider\n */\n async initialize(config: ProviderConfig): Promise<void> {\n this.config = config;\n this.initialized = true;\n }\n\n /**\n * Ensure provider is initialized\n */\n protected ensureInitialized(): void {\n if (!this.initialized) {\n throw new Error(`Provider ${this.name} is not initialized`);\n }\n }\n\n /**\n * Make HTTP request\n */\n protected async request<T>(\n url: string,\n options: RequestInit = {}\n ): Promise<T> {\n const response = await fetch(url, {\n ...options,\n headers: {\n 'Content-Type': 'application/json',\n ...options.headers,\n },\n });\n\n if (!response.ok) {\n const error = await response.json().catch(() => ({\n message: response.statusText,\n }));\n throw error;\n }\n\n return response.json();\n }\n\n // Abstract methods that must be implemented by subclasses\n abstract signIn(request: SignInRequest): Promise<AuthResponse>;\n abstract signUp(request: SignUpRequest): Promise<AuthResponse>;\n abstract signOut(): Promise<void>;\n abstract getCurrentUser(): Promise<User | null>;\n abstract getCurrentSession(): Promise<Session | null>;\n abstract getCurrentSessionData(): Promise<SessionData | null>;\n abstract refreshSession(): Promise<Session>;\n abstract updateUser(request: UpdateUserRequest): Promise<User>;\n abstract changePassword(request: PasswordChangeRequest): Promise<void>;\n abstract requestPasswordReset(request: PasswordResetRequest): Promise<void>;\n abstract confirmPasswordReset(request: PasswordResetConfirmRequest): Promise<void>;\n abstract oauthSignIn(request: OAuthSignInRequest): Promise<string>;\n abstract oauthCallback(request: OAuthCallbackRequest): Promise<AuthResponse>;\n abstract getOAuthProviders(): Promise<OAuthProvider[]>;\n abstract sendMagicLink(request: MagicLinkRequest): Promise<void>;\n abstract verifyMagicLink(request: MagicLinkVerifyRequest): Promise<AuthResponse>;\n abstract sendPhoneCode(request: PhoneAuthRequest): Promise<void>;\n abstract verifyPhoneCode(request: PhoneVerifyRequest): Promise<AuthResponse>;\n abstract setupTwoFactor(request: TwoFactorSetupRequest): Promise<TwoFactorSetupResponse>;\n abstract verifyTwoFactor(request: TwoFactorVerifyRequest): Promise<AuthResponse>;\n abstract disableTwoFactor(): Promise<void>;\n abstract getTwoFactorStatus(): Promise<TwoFactorMethod[]>;\n abstract registerPasskey(request: PasskeyRegisterRequest): Promise<PasskeyCredential>;\n abstract authenticatePasskey(request: PasskeyAuthRequest): Promise<AuthResponse>;\n abstract listPasskeys(): Promise<PasskeyCredential[]>;\n abstract deletePasskey(credentialId: string): Promise<void>;\n\n /**\n * Optional edge runtime context methods\n * Default implementations do nothing - subclasses can override\n */\n setContext?(context: RequestContext): void;\n getCookies?(): CookieData[];\n clearContext?(): void;\n\n /**\n * Normalize error to AuthError\n */\n normalizeError(error: unknown): AuthError {\n return toAuthError(error);\n }\n}\n\n"]}
1
+ {"version":3,"sources":["../../src/types/auth.ts","../../src/utils/errors.ts","../../src/adapters/base-provider.ts"],"names":[],"mappings":";AAmFO,IAAM,SAAA,GAAN,MAAM,UAAA,SAAkB,KAAA,CAAM;AAAA,EAMnC,WAAA,CACE,OAAA,EACA,IAAA,GAAsB,eAAA,sBACtB,OAAA,EAKA;AACA,I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A,EAKxB,MAAM,WAAW,MAAA,EAAuC;AACtD,IAAA,IAAA,CAAK,MAAA,GAAS,MAAA;AACd,IAAA,IAAA,CAAK,WAAA,GAAc,IAAA;AAAA,EACrB;AAAA;AAAA;AAAA;AAAA,EAKU,iBAAA,GAA0B;AAClC,IAAA,IAAI,CAAC,KAAK,WAAA,EAAa;AACrB,MAAA,MAAM,IAAI,KAAA,CAAM,CAAA,SAAA,EAAY,IAAA,CAAK,IAAI,CAAA,mBAAA,CAAqB,CAAA;AAAA,IAC5D;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,MAAgB,OAAA,CACd,GAAA,EACA,OAAA,GAAuB,EAAC,EACZ;AACZ,IAAA,MAAM,QAAA,GAAW,MAAM,KAAA,CAAM,GAAA,EAAK;AAAA,MAChC,GAAG,OAAA;AAAA,MACH,OAAA,EAAS;AAAA,QACP,cAAA,EAAgB,kBAAA;AAAA,QAChB,GAAG,OAAA,CAAQ;AAAA;AACb,KACD,CAAA;AAED,IAAA,IAAI,CAAC,SAAS,EAAA,EAAI;AAChB,MAAA,MAAM,QAAQ,MAAM,QAAA,CAAS,IAAA,EAAK,CAAE,MAAM,OAAO;AAAA,QAC/C,SAAS,QAAA,CAAS;AAAA,OACpB,CAAE,CAAA;AACF,MAAA,MAAM,KAAA;AAAA,IACR;AAEA,IAAA,OAAO,SAAS,IAAA,EAAK;AAAA,EACvB;AAAA;AAAA;AAAA;AAAA,EAkEA,eAAe,KAAA,EAA2B;AACxC,IAAA,OAAO,YAAY,KAAK,CAAA;AAAA,EAC1B;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 * Error handling utilities\n */\n\nimport { AuthError, AuthErrorType } from '../types';\n\n/**\n * Create an auth error\n * \n * @deprecated Use `new AuthError()` directly instead\n */\nexport function createAuthError(\n type: AuthErrorType,\n message: string,\n details?: Record<string, unknown>,\n code?: string | number\n): AuthError {\n return new AuthError(message, type, { details, code });\n}\n\n/**\n * Check if an error is an auth error\n */\nexport function isAuthError(error: unknown): error is AuthError {\n return error instanceof AuthError;\n}\n\n/**\n * Convert unknown error to auth error\n */\nexport function toAuthError(error: unknown): AuthError {\n if (isAuthError(error)) {\n return error;\n }\n\n if (error instanceof Error) {\n return new AuthError(error.message, AuthErrorType.UNKNOWN_ERROR, {\n details: {\n originalError: error.name,\n stack: error.stack,\n },\n });\n }\n\n if (typeof error === 'string') {\n return new AuthError(error, AuthErrorType.UNKNOWN_ERROR);\n }\n\n return new AuthError(\n 'An unknown error occurred',\n AuthErrorType.UNKNOWN_ERROR,\n { details: { error } }\n );\n}\n\n/**\n * Check if error is a network error\n */\nexport function isNetworkError(error: unknown): boolean {\n if (error instanceof Error) {\n return (\n error.name === 'NetworkError' ||\n error.message.includes('network') ||\n error.message.includes('fetch')\n );\n }\n return false;\n}\n\n/**\n * Check if error indicates authentication is required\n */\nexport function isUnauthenticatedError(error: unknown): boolean {\n if (isAuthError(error)) {\n return (\n error.type === AuthErrorType.INVALID_TOKEN ||\n error.type === AuthErrorType.TOKEN_EXPIRED\n );\n }\n return false;\n}\n\n/**\n * Check if error requires MFA\n */\nexport function isMFARequiredError(error: unknown): boolean {\n if (isAuthError(error)) {\n return error.type === AuthErrorType.MFA_REQUIRED;\n }\n return false;\n}\n","/**\n * Base auth provider implementation\n */\n\nimport type {\n AuthProvider,\n AuthResponse,\n SignInRequest,\n SignUpRequest,\n UpdateUserRequest,\n PasswordChangeRequest,\n PasswordResetRequest,\n PasswordResetConfirmRequest,\n OAuthSignInRequest,\n OAuthCallbackRequest,\n MagicLinkRequest,\n MagicLinkVerifyRequest,\n PhoneAuthRequest,\n PhoneVerifyRequest,\n TwoFactorSetupRequest,\n TwoFactorSetupResponse,\n TwoFactorVerifyRequest,\n PasskeyRegisterRequest,\n PasskeyAuthRequest,\n User,\n Session,\n SessionData,\n OAuthProvider,\n TwoFactorMethod,\n PasskeyCredential,\n AuthError,\n ProviderConfig,\n RequestContext,\n CookieData,\n DeviceFlowInitiateRequest,\n DeviceFlowInitiateResponse,\n DeviceCodeVerifyRequest,\n DeviceCodeVerifyResponse,\n DeviceAuthorizeRequest,\n DeviceTokenPollRequest,\n DeviceTokenPollResponse,\n} from '../types';\nimport { toAuthError } from '../utils';\n\n/**\n * Base provider class with common functionality\n */\nexport abstract class BaseAuthProvider implements AuthProvider {\n abstract readonly name: string;\n protected config: ProviderConfig = {};\n protected initialized = false;\n\n /**\n * Initialize the provider\n */\n async initialize(config: ProviderConfig): Promise<void> {\n this.config = config;\n this.initialized = true;\n }\n\n /**\n * Ensure provider is initialized\n */\n protected ensureInitialized(): void {\n if (!this.initialized) {\n throw new Error(`Provider ${this.name} is not initialized`);\n }\n }\n\n /**\n * Make HTTP request\n */\n protected async request<T>(\n url: string,\n options: RequestInit = {}\n ): Promise<T> {\n const response = await fetch(url, {\n ...options,\n headers: {\n 'Content-Type': 'application/json',\n ...options.headers,\n },\n });\n\n if (!response.ok) {\n const error = await response.json().catch(() => ({\n message: response.statusText,\n }));\n throw error;\n }\n\n return response.json();\n }\n\n // Abstract methods that must be implemented by subclasses\n abstract signIn(request: SignInRequest): Promise<AuthResponse>;\n abstract signUp(request: SignUpRequest): Promise<AuthResponse>;\n abstract signOut(): Promise<void>;\n abstract getCurrentUser(): Promise<User | null>;\n abstract getCurrentSession(): Promise<Session | null>;\n abstract getCurrentSessionData(): Promise<SessionData | null>;\n abstract refreshSession(): Promise<Session>;\n abstract updateUser(request: UpdateUserRequest): Promise<User>;\n abstract changePassword(request: PasswordChangeRequest): Promise<void>;\n abstract requestPasswordReset(request: PasswordResetRequest): Promise<void>;\n abstract confirmPasswordReset(request: PasswordResetConfirmRequest): Promise<void>;\n abstract oauthSignIn(request: OAuthSignInRequest): Promise<string>;\n abstract oauthCallback(request: OAuthCallbackRequest): Promise<AuthResponse>;\n abstract getOAuthProviders(): Promise<OAuthProvider[]>;\n abstract sendMagicLink(request: MagicLinkRequest): Promise<void>;\n abstract verifyMagicLink(request: MagicLinkVerifyRequest): Promise<AuthResponse>;\n abstract sendPhoneCode(request: PhoneAuthRequest): Promise<void>;\n abstract verifyPhoneCode(request: PhoneVerifyRequest): Promise<AuthResponse>;\n abstract setupTwoFactor(request: TwoFactorSetupRequest): Promise<TwoFactorSetupResponse>;\n abstract verifyTwoFactor(request: TwoFactorVerifyRequest): Promise<AuthResponse>;\n abstract disableTwoFactor(): Promise<void>;\n abstract getTwoFactorStatus(): Promise<TwoFactorMethod[]>;\n abstract registerPasskey(request: PasskeyRegisterRequest): Promise<PasskeyCredential>;\n abstract authenticatePasskey(request: PasskeyAuthRequest): Promise<AuthResponse>;\n abstract listPasskeys(): Promise<PasskeyCredential[]>;\n abstract deletePasskey(credentialId: string): Promise<void>;\n\n // Device Flow methods (RFC 8628 - OAuth 2.0 Device Authorization Grant)\n /**\n * Initiate device authorization flow\n * Returns device code, user code, and verification URI\n */\n abstract initiateDeviceFlow(request: DeviceFlowInitiateRequest): Promise<DeviceFlowInitiateResponse>;\n \n /**\n * Verify a user-entered device code\n * Called by web UI when user enters the code shown on their device\n */\n abstract verifyDeviceCode(request: DeviceCodeVerifyRequest): Promise<DeviceCodeVerifyResponse>;\n \n /**\n * Authorize or deny the device request\n * Called when user approves or denies the authorization\n */\n abstract authorizeDevice(request: DeviceAuthorizeRequest): Promise<void>;\n \n /**\n * Poll for device token (used by CLI/device)\n * Returns auth response when authorized, or status when still pending\n */\n abstract pollDeviceToken(request: DeviceTokenPollRequest): Promise<AuthResponse | DeviceTokenPollResponse>;\n\n /**\n * Optional edge runtime context methods\n * Default implementations do nothing - subclasses can override\n */\n setContext?(context: RequestContext): void;\n getCookies?(): CookieData[];\n clearContext?(): void;\n\n /**\n * Normalize error to AuthError\n */\n normalizeError(error: unknown): AuthError {\n return toAuthError(error);\n }\n}\n\n"]}
package/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { A as AuthErrorType, a as AuthError, V as ValidationError, C as CookieData, b as AuthContext, c as AuthProvider, S as SignInRequest, d as SignUpRequest, U as UpdateUserRequest, P as PasswordChangeRequest, e as PasswordResetRequest, f as PasswordResetConfirmRequest, O as OAuthSignInRequest, g as OAuthCallbackRequest, h as OAuthProvider, M as MagicLinkRequest, i as MagicLinkVerifyRequest, j as PhoneAuthRequest, k as PhoneVerifyRequest, T as TwoFactorSetupRequest, l as TwoFactorSetupResponse, m as TwoFactorVerifyRequest, n as TwoFactorMethod, o as PasskeyRegisterRequest, p as PasskeyCredential, q as PasskeyAuthRequest, r as Organization, s as OrganizationMembership, t as User, u as Session } from './provider-Du6Oe4tD.mjs';
2
- export { E as AuthResponse, v as AuthState, B as FieldDefinition, z as FieldType, F as FieldValidation, x as OAuthConfig, G as ProviderConfig, R as RequestContext, w as SessionData, D as SignupFieldsResponse, y as TwoFactorConfig } from './provider-Du6Oe4tD.mjs';
1
+ import { A as AuthErrorType, a as AuthError, V as ValidationError, C as CookieData, b as AuthContext, c as AuthProvider, S as SignInRequest, d as SignUpRequest, U as UpdateUserRequest, P as PasswordChangeRequest, e as PasswordResetRequest, f as PasswordResetConfirmRequest, O as OAuthSignInRequest, g as OAuthCallbackRequest, h as OAuthProvider, M as MagicLinkRequest, i as MagicLinkVerifyRequest, j as PhoneAuthRequest, k as PhoneVerifyRequest, T as TwoFactorSetupRequest, l as TwoFactorSetupResponse, m as TwoFactorVerifyRequest, n as TwoFactorMethod, o as PasskeyRegisterRequest, p as PasskeyCredential, q as PasskeyAuthRequest, r as Organization, s as OrganizationMembership, t as User, u as Session } from './provider-DWklI8Wr.mjs';
2
+ export { Q as AuthResponse, v as AuthState, 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, x as OAuthConfig, R as ProviderConfig, W as RequestContext, Z as ResendVerificationRequest, X as SendVerificationEmailRequest, w as SessionData, a4 as SessionInfo, N as SignupFieldsResponse, y as TwoFactorConfig, Y as VerifyEmailRequest, a0 as VerifyMFAFactorRequest } from './provider-DWklI8Wr.mjs';
3
3
  import { Storage, Observable, Unsubscribe } from './types/index.mjs';
4
4
  export { Listener, LocalStorageAdapter, MemoryStorageAdapter, SessionStorageAdapter } from './types/index.mjs';
5
5
  export { BaseAuthProvider } from './adapters/index.mjs';
@@ -104,6 +104,40 @@ interface AuthLocale {
104
104
  register: string;
105
105
  usePasskey: string;
106
106
  };
107
+ deviceFlow: {
108
+ title: string;
109
+ subtitle: string;
110
+ enterCode: string;
111
+ enterCodeDescription: string;
112
+ codeLabel: string;
113
+ codePlaceholder: string;
114
+ codeHint: string;
115
+ verify: string;
116
+ verifyCode: string;
117
+ invalidCode: string;
118
+ noCode: string;
119
+ getCodeHelp: string;
120
+ authorizationTitle: string;
121
+ authorizationSubtitle: string;
122
+ authorizeTitle: string;
123
+ authorizeDescription: string;
124
+ requestingAccess: string;
125
+ codeConfirm: string;
126
+ requestedPermissions: string;
127
+ securityWarning: string;
128
+ scopes: string;
129
+ approve: string;
130
+ deny: string;
131
+ authorizedTitle: string;
132
+ authorizedMessage: string;
133
+ authorizedDescription: string;
134
+ authorizedHint: string;
135
+ returnToCli: string;
136
+ deniedTitle: string;
137
+ deniedMessage: string;
138
+ deniedDescription: string;
139
+ deniedHint: string;
140
+ };
107
141
  signUp: {
108
142
  title: string;
109
143
  subtitle: string;
@@ -554,6 +588,13 @@ declare enum FlowStep {
554
588
  PASSWORD_CHANGE = "password_change",
555
589
  PROFILE_UPDATE = "profile_update",
556
590
  PROFILE_COMPLETE = "profile_complete",
591
+ DEVICE_FLOW_INITIATE = "device_flow_initiate",
592
+ DEVICE_CODE_ENTRY = "device_code_entry",
593
+ DEVICE_CODE_VERIFY = "device_code_verify",
594
+ DEVICE_AUTHORIZE = "device_authorize",
595
+ DEVICE_POLLING = "device_polling",
596
+ DEVICE_AUTHORIZED = "device_authorized",
597
+ DEVICE_DENIED = "device_denied",
557
598
  SUCCESS = "success",
558
599
  ERROR = "error",
559
600
  CANCELLED = "cancelled"
@@ -569,6 +610,7 @@ interface FlowState {
569
610
  email?: string;
570
611
  phone?: string;
571
612
  username?: string;
613
+ token?: string;
572
614
  mfaRequired?: boolean;
573
615
  mfaMethods?: TwoFactorMethod[];
574
616
  mfaToken?: string;
@@ -577,6 +619,15 @@ interface FlowState {
577
619
  verificationRequired?: boolean;
578
620
  verificationToken?: string;
579
621
  verificationSent?: boolean;
622
+ deviceCode?: string;
623
+ userCode?: string;
624
+ verificationUri?: string;
625
+ verificationUriComplete?: string;
626
+ deviceCodeExpiresIn?: number;
627
+ devicePollingInterval?: number;
628
+ deviceClientId?: string;
629
+ deviceScopes?: string[];
630
+ deviceAuthorized?: boolean;
580
631
  error?: AuthError;
581
632
  metadata?: Record<string, unknown>;
582
633
  }
@@ -627,6 +678,7 @@ declare enum FlowConfigType {
627
678
  SECURE_SIGN_IN_FLOW = "secure_sign_in_flow",// signin → MFA → success
628
679
  PASSWORD_RESET_FLOW = "password_reset_flow",
629
680
  EMAIL_VERIFICATION_FLOW = "email_verification_flow",
681
+ DEVICE_FLOW = "device_flow",
630
682
  CUSTOM = "custom"
631
683
  }
632
684
  /**
@@ -767,6 +819,7 @@ declare const predefinedFlows: {
767
819
  oauth_sign_in: FlowConfig;
768
820
  password_reset_flow: FlowConfig;
769
821
  email_verification_flow: FlowConfig;
822
+ device_flow: FlowConfig;
770
823
  };
771
824
 
772
825
  export { AuthClient, type AuthClientConfig, AuthContext, AuthError, AuthErrorType, type AuthLocale, AuthProvider, CookieData, type DeepPartial, FlowAction, type FlowConfig, FlowConfigType, FlowEngine, type FlowEvent, type FlowState, FlowStep, type FlowTransition, MagicLinkRequest, MagicLinkVerifyRequest, OAuthCallbackRequest, OAuthProvider, OAuthSignInRequest, Observable, Organization, OrganizationMembership, PasskeyAuthRequest, PasskeyCredential, PasskeyRegisterRequest, PasswordChangeRequest, PasswordResetConfirmRequest, PasswordResetRequest, PhoneAuthRequest, PhoneVerifyRequest, Session, SignInRequest, SignUpRequest, Storage, TokenManager, TwoFactorMethod, TwoFactorSetupRequest, TwoFactorSetupResponse, TwoFactorVerifyRequest, Unsubscribe, UpdateUserRequest, User, ValidationError, completeSignUpFlow, createAuthError, createLocale, defaultLocale, emailVerificationFlow, extractCookiesFromHeaders, getFlowConfig, interpolate, isAuthError, isMFARequiredError, isNetworkError, isUnauthenticatedError, magicLinkFlow, oauthSignInFlow, parseCookie, parseCookieOptions, passwordResetFlow, phoneAuthFlow, predefinedFlows, serializeCookie, serializeCookies, signInWithMFAFlow, simpleSignInFlow, toAuthError, validate2FACode, validateEmail, validatePassword, validatePhone, validateRequired, validateUsername };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { A as AuthErrorType, a as AuthError, V as ValidationError, C as CookieData, b as AuthContext, c as AuthProvider, S as SignInRequest, d as SignUpRequest, U as UpdateUserRequest, P as PasswordChangeRequest, e as PasswordResetRequest, f as PasswordResetConfirmRequest, O as OAuthSignInRequest, g as OAuthCallbackRequest, h as OAuthProvider, M as MagicLinkRequest, i as MagicLinkVerifyRequest, j as PhoneAuthRequest, k as PhoneVerifyRequest, T as TwoFactorSetupRequest, l as TwoFactorSetupResponse, m as TwoFactorVerifyRequest, n as TwoFactorMethod, o as PasskeyRegisterRequest, p as PasskeyCredential, q as PasskeyAuthRequest, r as Organization, s as OrganizationMembership, t as User, u as Session } from './provider-Du6Oe4tD.js';
2
- export { E as AuthResponse, v as AuthState, B as FieldDefinition, z as FieldType, F as FieldValidation, x as OAuthConfig, G as ProviderConfig, R as RequestContext, w as SessionData, D as SignupFieldsResponse, y as TwoFactorConfig } from './provider-Du6Oe4tD.js';
1
+ import { A as AuthErrorType, a as AuthError, V as ValidationError, C as CookieData, b as AuthContext, c as AuthProvider, S as SignInRequest, d as SignUpRequest, U as UpdateUserRequest, P as PasswordChangeRequest, e as PasswordResetRequest, f as PasswordResetConfirmRequest, O as OAuthSignInRequest, g as OAuthCallbackRequest, h as OAuthProvider, M as MagicLinkRequest, i as MagicLinkVerifyRequest, j as PhoneAuthRequest, k as PhoneVerifyRequest, T as TwoFactorSetupRequest, l as TwoFactorSetupResponse, m as TwoFactorVerifyRequest, n as TwoFactorMethod, o as PasskeyRegisterRequest, p as PasskeyCredential, q as PasskeyAuthRequest, r as Organization, s as OrganizationMembership, t as User, u as Session } from './provider-DWklI8Wr.js';
2
+ export { Q as AuthResponse, v as AuthState, 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, x as OAuthConfig, R as ProviderConfig, W as RequestContext, Z as ResendVerificationRequest, X as SendVerificationEmailRequest, w as SessionData, a4 as SessionInfo, N as SignupFieldsResponse, y as TwoFactorConfig, Y as VerifyEmailRequest, a0 as VerifyMFAFactorRequest } from './provider-DWklI8Wr.js';
3
3
  import { Storage, Observable, Unsubscribe } from './types/index.js';
4
4
  export { Listener, LocalStorageAdapter, MemoryStorageAdapter, SessionStorageAdapter } from './types/index.js';
5
5
  export { BaseAuthProvider } from './adapters/index.js';
@@ -104,6 +104,40 @@ interface AuthLocale {
104
104
  register: string;
105
105
  usePasskey: string;
106
106
  };
107
+ deviceFlow: {
108
+ title: string;
109
+ subtitle: string;
110
+ enterCode: string;
111
+ enterCodeDescription: string;
112
+ codeLabel: string;
113
+ codePlaceholder: string;
114
+ codeHint: string;
115
+ verify: string;
116
+ verifyCode: string;
117
+ invalidCode: string;
118
+ noCode: string;
119
+ getCodeHelp: string;
120
+ authorizationTitle: string;
121
+ authorizationSubtitle: string;
122
+ authorizeTitle: string;
123
+ authorizeDescription: string;
124
+ requestingAccess: string;
125
+ codeConfirm: string;
126
+ requestedPermissions: string;
127
+ securityWarning: string;
128
+ scopes: string;
129
+ approve: string;
130
+ deny: string;
131
+ authorizedTitle: string;
132
+ authorizedMessage: string;
133
+ authorizedDescription: string;
134
+ authorizedHint: string;
135
+ returnToCli: string;
136
+ deniedTitle: string;
137
+ deniedMessage: string;
138
+ deniedDescription: string;
139
+ deniedHint: string;
140
+ };
107
141
  signUp: {
108
142
  title: string;
109
143
  subtitle: string;
@@ -554,6 +588,13 @@ declare enum FlowStep {
554
588
  PASSWORD_CHANGE = "password_change",
555
589
  PROFILE_UPDATE = "profile_update",
556
590
  PROFILE_COMPLETE = "profile_complete",
591
+ DEVICE_FLOW_INITIATE = "device_flow_initiate",
592
+ DEVICE_CODE_ENTRY = "device_code_entry",
593
+ DEVICE_CODE_VERIFY = "device_code_verify",
594
+ DEVICE_AUTHORIZE = "device_authorize",
595
+ DEVICE_POLLING = "device_polling",
596
+ DEVICE_AUTHORIZED = "device_authorized",
597
+ DEVICE_DENIED = "device_denied",
557
598
  SUCCESS = "success",
558
599
  ERROR = "error",
559
600
  CANCELLED = "cancelled"
@@ -569,6 +610,7 @@ interface FlowState {
569
610
  email?: string;
570
611
  phone?: string;
571
612
  username?: string;
613
+ token?: string;
572
614
  mfaRequired?: boolean;
573
615
  mfaMethods?: TwoFactorMethod[];
574
616
  mfaToken?: string;
@@ -577,6 +619,15 @@ interface FlowState {
577
619
  verificationRequired?: boolean;
578
620
  verificationToken?: string;
579
621
  verificationSent?: boolean;
622
+ deviceCode?: string;
623
+ userCode?: string;
624
+ verificationUri?: string;
625
+ verificationUriComplete?: string;
626
+ deviceCodeExpiresIn?: number;
627
+ devicePollingInterval?: number;
628
+ deviceClientId?: string;
629
+ deviceScopes?: string[];
630
+ deviceAuthorized?: boolean;
580
631
  error?: AuthError;
581
632
  metadata?: Record<string, unknown>;
582
633
  }
@@ -627,6 +678,7 @@ declare enum FlowConfigType {
627
678
  SECURE_SIGN_IN_FLOW = "secure_sign_in_flow",// signin → MFA → success
628
679
  PASSWORD_RESET_FLOW = "password_reset_flow",
629
680
  EMAIL_VERIFICATION_FLOW = "email_verification_flow",
681
+ DEVICE_FLOW = "device_flow",
630
682
  CUSTOM = "custom"
631
683
  }
632
684
  /**
@@ -767,6 +819,7 @@ declare const predefinedFlows: {
767
819
  oauth_sign_in: FlowConfig;
768
820
  password_reset_flow: FlowConfig;
769
821
  email_verification_flow: FlowConfig;
822
+ device_flow: FlowConfig;
770
823
  };
771
824
 
772
825
  export { AuthClient, type AuthClientConfig, AuthContext, AuthError, AuthErrorType, type AuthLocale, AuthProvider, CookieData, type DeepPartial, FlowAction, type FlowConfig, FlowConfigType, FlowEngine, type FlowEvent, type FlowState, FlowStep, type FlowTransition, MagicLinkRequest, MagicLinkVerifyRequest, OAuthCallbackRequest, OAuthProvider, OAuthSignInRequest, Observable, Organization, OrganizationMembership, PasskeyAuthRequest, PasskeyCredential, PasskeyRegisterRequest, PasswordChangeRequest, PasswordResetConfirmRequest, PasswordResetRequest, PhoneAuthRequest, PhoneVerifyRequest, Session, SignInRequest, SignUpRequest, Storage, TokenManager, TwoFactorMethod, TwoFactorSetupRequest, TwoFactorSetupResponse, TwoFactorVerifyRequest, Unsubscribe, UpdateUserRequest, User, ValidationError, completeSignUpFlow, createAuthError, createLocale, defaultLocale, emailVerificationFlow, extractCookiesFromHeaders, getFlowConfig, interpolate, isAuthError, isMFARequiredError, isNetworkError, isUnauthenticatedError, magicLinkFlow, oauthSignInFlow, parseCookie, parseCookieOptions, passwordResetFlow, phoneAuthFlow, predefinedFlows, serializeCookie, serializeCookies, signInWithMFAFlow, simpleSignInFlow, toAuthError, validate2FACode, validateEmail, validatePassword, validatePhone, validateRequired, validateUsername };
package/dist/index.js CHANGED
@@ -278,6 +278,40 @@ var enLocale = {
278
278
  register: "Register passkey",
279
279
  usePasskey: "Use passkey"
280
280
  },
281
+ deviceFlow: {
282
+ title: "Authorize Device",
283
+ subtitle: "Enter the code displayed on your device",
284
+ enterCode: "Authorize Device",
285
+ enterCodeDescription: "Enter the code displayed on your device or CLI",
286
+ codeLabel: "Device Code",
287
+ codePlaceholder: "XXXX-XXXX",
288
+ codeHint: "Enter the 8-character code shown on your device",
289
+ verify: "Verify Code",
290
+ verifyCode: "Verify Code",
291
+ invalidCode: "Invalid code. Please check and try again.",
292
+ noCode: "Don't have a code?",
293
+ getCodeHelp: "Get help",
294
+ authorizationTitle: "Authorize Application",
295
+ authorizationSubtitle: "An application is requesting access to your account",
296
+ authorizeTitle: "Authorize Device",
297
+ authorizeDescription: "An application is requesting access to your account",
298
+ requestingAccess: "is requesting access to:",
299
+ codeConfirm: "Confirm this is your code:",
300
+ requestedPermissions: "Requested permissions:",
301
+ securityWarning: "Only approve this request if you initiated it",
302
+ scopes: "Requested permissions",
303
+ approve: "Approve",
304
+ deny: "Deny",
305
+ authorizedTitle: "Device Authorized",
306
+ authorizedMessage: "You can now return to your device to continue",
307
+ authorizedDescription: "Your device has been successfully authorized",
308
+ authorizedHint: "You can close this window and return to your CLI or device",
309
+ returnToCli: "Return to CLI",
310
+ deniedTitle: "Access Denied",
311
+ deniedMessage: "You have denied access to this device",
312
+ deniedDescription: "The device authorization request has been denied",
313
+ deniedHint: "You can close this window"
314
+ },
281
315
  signUp: {
282
316
  title: "Create Account",
283
317
  subtitle: "Get started with your account",
@@ -1235,6 +1269,13 @@ var FlowStep = /* @__PURE__ */ ((FlowStep2) => {
1235
1269
  FlowStep2["PASSWORD_CHANGE"] = "password_change";
1236
1270
  FlowStep2["PROFILE_UPDATE"] = "profile_update";
1237
1271
  FlowStep2["PROFILE_COMPLETE"] = "profile_complete";
1272
+ FlowStep2["DEVICE_FLOW_INITIATE"] = "device_flow_initiate";
1273
+ FlowStep2["DEVICE_CODE_ENTRY"] = "device_code_entry";
1274
+ FlowStep2["DEVICE_CODE_VERIFY"] = "device_code_verify";
1275
+ FlowStep2["DEVICE_AUTHORIZE"] = "device_authorize";
1276
+ FlowStep2["DEVICE_POLLING"] = "device_polling";
1277
+ FlowStep2["DEVICE_AUTHORIZED"] = "device_authorized";
1278
+ FlowStep2["DEVICE_DENIED"] = "device_denied";
1238
1279
  FlowStep2["SUCCESS"] = "success";
1239
1280
  FlowStep2["ERROR"] = "error";
1240
1281
  FlowStep2["CANCELLED"] = "cancelled";
@@ -1252,6 +1293,7 @@ var FlowConfigType = /* @__PURE__ */ ((FlowConfigType2) => {
1252
1293
  FlowConfigType2["SECURE_SIGN_IN_FLOW"] = "secure_sign_in_flow";
1253
1294
  FlowConfigType2["PASSWORD_RESET_FLOW"] = "password_reset_flow";
1254
1295
  FlowConfigType2["EMAIL_VERIFICATION_FLOW"] = "email_verification_flow";
1296
+ FlowConfigType2["DEVICE_FLOW"] = "device_flow";
1255
1297
  FlowConfigType2["CUSTOM"] = "custom";
1256
1298
  return FlowConfigType2;
1257
1299
  })(FlowConfigType || {});
@@ -1461,6 +1503,8 @@ var simpleSignInFlow = {
1461
1503
  initialStep: "email_password_sign_in" /* EMAIL_PASSWORD_SIGN_IN */,
1462
1504
  allowedSteps: [
1463
1505
  "email_password_sign_in" /* EMAIL_PASSWORD_SIGN_IN */,
1506
+ "email_verification_required" /* EMAIL_VERIFICATION_REQUIRED */,
1507
+ "email_verification_sent" /* EMAIL_VERIFICATION_SENT */,
1464
1508
  "password_reset_request" /* PASSWORD_RESET_REQUEST */,
1465
1509
  "password_reset_sent" /* PASSWORD_RESET_SENT */,
1466
1510
  "success" /* SUCCESS */,
@@ -1471,6 +1515,14 @@ var simpleSignInFlow = {
1471
1515
  onSuccess: "success" /* SUCCESS */,
1472
1516
  onError: "email_password_sign_in" /* EMAIL_PASSWORD_SIGN_IN */
1473
1517
  },
1518
+ ["email_verification_required" /* EMAIL_VERIFICATION_REQUIRED */]: {
1519
+ onSuccess: "email_verification_sent" /* EMAIL_VERIFICATION_SENT */,
1520
+ onError: "email_verification_required" /* EMAIL_VERIFICATION_REQUIRED */
1521
+ },
1522
+ ["email_verification_sent" /* EMAIL_VERIFICATION_SENT */]: {
1523
+ onSuccess: "email_password_sign_in" /* EMAIL_PASSWORD_SIGN_IN */,
1524
+ onError: "email_verification_required" /* EMAIL_VERIFICATION_REQUIRED */
1525
+ },
1474
1526
  ["password_reset_request" /* PASSWORD_RESET_REQUEST */]: {
1475
1527
  onSuccess: "password_reset_sent" /* PASSWORD_RESET_SENT */,
1476
1528
  onBack: "email_password_sign_in" /* EMAIL_PASSWORD_SIGN_IN */
@@ -1486,6 +1538,8 @@ var signInWithMFAFlow = {
1486
1538
  initialStep: "email_password_sign_in" /* EMAIL_PASSWORD_SIGN_IN */,
1487
1539
  allowedSteps: [
1488
1540
  "email_password_sign_in" /* EMAIL_PASSWORD_SIGN_IN */,
1541
+ "email_verification_required" /* EMAIL_VERIFICATION_REQUIRED */,
1542
+ "email_verification_sent" /* EMAIL_VERIFICATION_SENT */,
1489
1543
  "mfa_required" /* MFA_REQUIRED */,
1490
1544
  "mfa_select_method" /* MFA_SELECT_METHOD */,
1491
1545
  "mfa_verify" /* MFA_VERIFY */,
@@ -1505,6 +1559,14 @@ var signInWithMFAFlow = {
1505
1559
  }
1506
1560
  ]
1507
1561
  },
1562
+ ["email_verification_required" /* EMAIL_VERIFICATION_REQUIRED */]: {
1563
+ onSuccess: "email_verification_sent" /* EMAIL_VERIFICATION_SENT */,
1564
+ onError: "email_verification_required" /* EMAIL_VERIFICATION_REQUIRED */
1565
+ },
1566
+ ["email_verification_sent" /* EMAIL_VERIFICATION_SENT */]: {
1567
+ onSuccess: "email_password_sign_in" /* EMAIL_PASSWORD_SIGN_IN */,
1568
+ onError: "email_verification_required" /* EMAIL_VERIFICATION_REQUIRED */
1569
+ },
1508
1570
  ["mfa_required" /* MFA_REQUIRED */]: {
1509
1571
  onSuccess: "mfa_verify" /* MFA_VERIFY */,
1510
1572
  conditions: [
@@ -1678,6 +1740,43 @@ var emailVerificationFlow = {
1678
1740
  }
1679
1741
  }
1680
1742
  };
1743
+ var deviceFlow = {
1744
+ name: "Device Flow",
1745
+ description: "OAuth 2.0 Device Authorization Grant for CLI/device login",
1746
+ initialStep: "device_code_entry" /* DEVICE_CODE_ENTRY */,
1747
+ allowedSteps: [
1748
+ "device_code_entry" /* DEVICE_CODE_ENTRY */,
1749
+ "device_code_verify" /* DEVICE_CODE_VERIFY */,
1750
+ "device_authorize" /* DEVICE_AUTHORIZE */,
1751
+ "device_authorized" /* DEVICE_AUTHORIZED */,
1752
+ "device_denied" /* DEVICE_DENIED */,
1753
+ "success" /* SUCCESS */,
1754
+ "error" /* ERROR */
1755
+ ],
1756
+ transitions: {
1757
+ ["device_code_entry" /* DEVICE_CODE_ENTRY */]: {
1758
+ onSuccess: "device_code_verify" /* DEVICE_CODE_VERIFY */,
1759
+ onError: "device_code_entry" /* DEVICE_CODE_ENTRY */,
1760
+ onCancel: "cancelled" /* CANCELLED */
1761
+ },
1762
+ ["device_code_verify" /* DEVICE_CODE_VERIFY */]: {
1763
+ onSuccess: "device_authorize" /* DEVICE_AUTHORIZE */,
1764
+ onError: "device_code_entry" /* DEVICE_CODE_ENTRY */,
1765
+ onBack: "device_code_entry" /* DEVICE_CODE_ENTRY */
1766
+ },
1767
+ ["device_authorize" /* DEVICE_AUTHORIZE */]: {
1768
+ onSuccess: "device_authorized" /* DEVICE_AUTHORIZED */,
1769
+ onError: "device_denied" /* DEVICE_DENIED */,
1770
+ onCancel: "device_denied" /* DEVICE_DENIED */
1771
+ },
1772
+ ["device_authorized" /* DEVICE_AUTHORIZED */]: {
1773
+ onSuccess: "success" /* SUCCESS */
1774
+ },
1775
+ ["device_denied" /* DEVICE_DENIED */]: {
1776
+ onSuccess: "error" /* ERROR */
1777
+ }
1778
+ }
1779
+ };
1681
1780
  function getFlowConfig(type) {
1682
1781
  switch (type) {
1683
1782
  case "simple_sign_in" /* SIMPLE_SIGN_IN */:
@@ -1696,6 +1795,8 @@ function getFlowConfig(type) {
1696
1795
  return passwordResetFlow;
1697
1796
  case "email_verification_flow" /* EMAIL_VERIFICATION_FLOW */:
1698
1797
  return emailVerificationFlow;
1798
+ case "device_flow" /* DEVICE_FLOW */:
1799
+ return deviceFlow;
1699
1800
  default:
1700
1801
  throw new Error(`Unknown flow type: ${type}`);
1701
1802
  }
@@ -1708,7 +1809,8 @@ var predefinedFlows = {
1708
1809
  ["phone_auth_flow" /* PHONE_AUTH_FLOW */]: phoneAuthFlow,
1709
1810
  ["oauth_sign_in" /* OAUTH_SIGN_IN */]: oauthSignInFlow,
1710
1811
  ["password_reset_flow" /* PASSWORD_RESET_FLOW */]: passwordResetFlow,
1711
- ["email_verification_flow" /* EMAIL_VERIFICATION_FLOW */]: emailVerificationFlow
1812
+ ["email_verification_flow" /* EMAIL_VERIFICATION_FLOW */]: emailVerificationFlow,
1813
+ ["device_flow" /* DEVICE_FLOW */]: deviceFlow
1712
1814
  };
1713
1815
 
1714
1816
  exports.AuthClient = AuthClient;