@pixygon/auth 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,233 @@
1
+ import { A as AuthContextValue, a as AuthConfig, U as User, b as AuthError, c as AuthStatus, d as UserRole, e as AuthStorage, T as TokenPair, L as LoginRequest, f as LoginResponse, R as RegisterRequest, g as RegisterResponse, V as VerifyRequest, h as VerifyResponse, i as ResendVerificationRequest, j as ResendVerificationResponse, F as ForgotPasswordRequest, k as ForgotPasswordResponse, l as RecoverPasswordRequest, m as RecoverPasswordResponse, n as RefreshTokenRequest, o as RefreshTokenResponse } from './index-CIK2MKl9.js';
2
+ export { p as AuthErrorCode, q as AuthState, r as ForgotPasswordFormProps, s as LoginFormProps, P as PixygonAuthProps, t as RegisterFormProps, S as SubscriptionTier, u as TokenPayload, v as VerifyFormProps } from './index-CIK2MKl9.js';
3
+ import * as react_jsx_runtime from 'react/jsx-runtime';
4
+ import * as react from 'react';
5
+ import { ReactNode } from 'react';
6
+
7
+ declare const AuthContext: react.Context<AuthContextValue | null>;
8
+ interface AuthProviderProps {
9
+ config: AuthConfig;
10
+ children: ReactNode;
11
+ }
12
+ declare function AuthProvider({ config: userConfig, children }: AuthProviderProps): react_jsx_runtime.JSX.Element;
13
+ declare function useAuthContext(): AuthContextValue;
14
+
15
+ /**
16
+ * Profile Sync Hook
17
+ * Synchronizes user profile data across Pixygon applications
18
+ */
19
+
20
+ interface UserProfile extends User {
21
+ displayName?: string;
22
+ avatar?: string;
23
+ bio?: string;
24
+ preferences?: Record<string, unknown>;
25
+ linkedApps?: string[];
26
+ lastSyncedAt?: string;
27
+ }
28
+ interface UseProfileSyncReturn {
29
+ /** Current user profile */
30
+ profile: UserProfile | null;
31
+ /** Whether the profile is loading */
32
+ isLoading: boolean;
33
+ /** Whether the profile is syncing */
34
+ isSyncing: boolean;
35
+ /** Error if any */
36
+ error: Error | null;
37
+ /** Update profile */
38
+ updateProfile: (updates: Partial<UserProfile>) => Promise<void>;
39
+ /** Force sync profile from server */
40
+ syncProfile: () => Promise<void>;
41
+ /** Update preferences */
42
+ updatePreferences: (preferences: Record<string, unknown>) => Promise<void>;
43
+ /** Link another app to profile */
44
+ linkApp: (appId: string) => Promise<void>;
45
+ }
46
+ /**
47
+ * Hook to sync user profile across apps
48
+ */
49
+ declare function useProfileSync(): UseProfileSyncReturn;
50
+
51
+ /**
52
+ * @pixygon/auth - Custom Hooks
53
+ * Convenient hooks for accessing auth state and actions
54
+ */
55
+
56
+ interface UseAuthReturn {
57
+ user: User | null;
58
+ status: AuthStatus;
59
+ isLoading: boolean;
60
+ isAuthenticated: boolean;
61
+ isVerified: boolean;
62
+ error: AuthError | null;
63
+ login: ReturnType<typeof useAuthContext>['login'];
64
+ register: ReturnType<typeof useAuthContext>['register'];
65
+ logout: ReturnType<typeof useAuthContext>['logout'];
66
+ verify: ReturnType<typeof useAuthContext>['verify'];
67
+ resendVerification: ReturnType<typeof useAuthContext>['resendVerification'];
68
+ forgotPassword: ReturnType<typeof useAuthContext>['forgotPassword'];
69
+ recoverPassword: ReturnType<typeof useAuthContext>['recoverPassword'];
70
+ hasRole: (role: UserRole | UserRole[]) => boolean;
71
+ }
72
+ /**
73
+ * Main auth hook providing all auth state and actions
74
+ */
75
+ declare function useAuth(): UseAuthReturn;
76
+ interface UseUserReturn {
77
+ user: User | null;
78
+ isAuthenticated: boolean;
79
+ isVerified: boolean;
80
+ role: UserRole | null;
81
+ hasRole: (role: UserRole | UserRole[]) => boolean;
82
+ userId: string | null;
83
+ userName: string | null;
84
+ email: string | null;
85
+ profilePicture: string | null;
86
+ subscriptionTier: User['subscriptionTier'] | null;
87
+ dailyTokens: number;
88
+ purchasedTokens: number;
89
+ bonusTokens: number;
90
+ subscriptionTokens: number;
91
+ totalTokens: number;
92
+ }
93
+ /**
94
+ * Hook for accessing user data with convenient shortcuts
95
+ */
96
+ declare function useUser(): UseUserReturn;
97
+ interface UseTokenReturn {
98
+ accessToken: string | null;
99
+ refreshToken: string | null;
100
+ getAccessToken: () => string | null;
101
+ refreshTokens: () => Promise<void>;
102
+ isAuthenticated: boolean;
103
+ }
104
+ /**
105
+ * Hook for accessing and managing auth tokens
106
+ */
107
+ declare function useToken(): UseTokenReturn;
108
+ interface UseAuthStatusReturn {
109
+ status: AuthStatus;
110
+ isIdle: boolean;
111
+ isLoading: boolean;
112
+ isAuthenticated: boolean;
113
+ isUnauthenticated: boolean;
114
+ isVerifying: boolean;
115
+ }
116
+ /**
117
+ * Hook for auth status checks
118
+ */
119
+ declare function useAuthStatus(): UseAuthStatusReturn;
120
+ interface UseRequireAuthOptions {
121
+ /** Redirect path when not authenticated */
122
+ redirectTo?: string;
123
+ /** Required roles (any of) */
124
+ roles?: UserRole[];
125
+ /** Callback when auth check fails */
126
+ onUnauthorized?: () => void;
127
+ }
128
+ interface UseRequireAuthReturn {
129
+ isAuthorized: boolean;
130
+ isLoading: boolean;
131
+ user: User | null;
132
+ }
133
+ /**
134
+ * Hook for protected routes/components
135
+ * Returns authorization state and user
136
+ */
137
+ declare function useRequireAuth(options?: UseRequireAuthOptions): UseRequireAuthReturn;
138
+
139
+ interface UseAuthErrorReturn {
140
+ error: AuthError | null;
141
+ hasError: boolean;
142
+ errorMessage: string | null;
143
+ errorCode: AuthError['code'] | null;
144
+ clearError: () => void;
145
+ }
146
+ /**
147
+ * Hook for auth error handling
148
+ */
149
+ declare function useAuthError(): UseAuthErrorReturn;
150
+
151
+ /**
152
+ * @pixygon/auth - Token Storage Utilities
153
+ * Unified storage for auth tokens across all Pixygon apps
154
+ */
155
+
156
+ /**
157
+ * Create a token storage manager for a specific app
158
+ */
159
+ declare function createTokenStorage(appId: string, storage?: AuthStorage): {
160
+ /**
161
+ * Get the stored access token
162
+ */
163
+ getAccessToken: () => Promise<string | null>;
164
+ /**
165
+ * Get the stored refresh token
166
+ */
167
+ getRefreshToken: () => Promise<string | null>;
168
+ /**
169
+ * Get the stored user
170
+ */
171
+ getUser: () => Promise<User | null>;
172
+ /**
173
+ * Get token expiration time
174
+ */
175
+ getExpiresAt: () => Promise<number | null>;
176
+ /**
177
+ * Check if access token is expired
178
+ */
179
+ isTokenExpired: () => Promise<boolean>;
180
+ /**
181
+ * Check if token will expire within threshold (in seconds)
182
+ */
183
+ willExpireSoon: (thresholdSeconds?: number) => Promise<boolean>;
184
+ /**
185
+ * Store tokens and user data
186
+ */
187
+ setTokens: (accessToken: string, refreshToken: string | null, expiresIn: number | null, user: User) => Promise<void>;
188
+ /**
189
+ * Update tokens after refresh
190
+ */
191
+ updateTokens: (tokens: TokenPair) => Promise<void>;
192
+ /**
193
+ * Update user data
194
+ */
195
+ updateUser: (user: User) => Promise<void>;
196
+ /**
197
+ * Clear all stored auth data
198
+ */
199
+ clear: () => Promise<void>;
200
+ /**
201
+ * Get all stored auth data
202
+ */
203
+ getAll: () => Promise<{
204
+ accessToken: string | null;
205
+ refreshToken: string | null;
206
+ user: any;
207
+ expiresAt: number | null;
208
+ }>;
209
+ };
210
+ type TokenStorage = ReturnType<typeof createTokenStorage>;
211
+
212
+ /**
213
+ * @pixygon/auth - API Client
214
+ * Unified API client with automatic token injection and refresh
215
+ */
216
+
217
+ interface AuthApiClient {
218
+ login: (data: LoginRequest) => Promise<LoginResponse>;
219
+ register: (data: RegisterRequest) => Promise<RegisterResponse>;
220
+ verify: (data: VerifyRequest) => Promise<VerifyResponse>;
221
+ resendVerification: (data: ResendVerificationRequest) => Promise<ResendVerificationResponse>;
222
+ forgotPassword: (data: ForgotPasswordRequest) => Promise<ForgotPasswordResponse>;
223
+ recoverPassword: (data: RecoverPasswordRequest) => Promise<RecoverPasswordResponse>;
224
+ refreshToken: (data: RefreshTokenRequest) => Promise<RefreshTokenResponse>;
225
+ getMe: () => Promise<User>;
226
+ updateProfile: (data: Partial<User>) => Promise<User>;
227
+ setAccessToken: (token: string | null) => void;
228
+ getAccessToken: () => string | null;
229
+ request: <T>(endpoint: string, options?: RequestInit) => Promise<T>;
230
+ }
231
+ declare function createAuthApiClient(config: AuthConfig, tokenStorage: TokenStorage): AuthApiClient;
232
+
233
+ export { type AuthApiClient, AuthConfig, AuthContext, AuthContextValue, AuthError, AuthProvider, type AuthProviderProps, AuthStatus, AuthStorage, ForgotPasswordRequest, ForgotPasswordResponse, LoginRequest, LoginResponse, RecoverPasswordRequest, RecoverPasswordResponse, RefreshTokenRequest, RefreshTokenResponse, RegisterRequest, RegisterResponse, ResendVerificationRequest, ResendVerificationResponse, TokenPair, type TokenStorage, type UseAuthErrorReturn, type UseAuthReturn, type UseAuthStatusReturn, type UseProfileSyncReturn, type UseRequireAuthOptions, type UseRequireAuthReturn, type UseTokenReturn, type UseUserReturn, User, type UserProfile, UserRole, VerifyRequest, VerifyResponse, createAuthApiClient, createTokenStorage, useAuth, useAuthContext, useAuthError, useAuthStatus, useProfileSync, useRequireAuth, useToken, useUser };