@oxyhq/services 5.7.3 → 5.7.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,28 +1,96 @@
1
1
  # OxyHQServices
2
2
 
3
- A TypeScript client library for the Oxy API providing authentication, user management, and UI components for React and React Native applications.
3
+ 🚀 **Zero-config authentication and user management** for React, React Native, and Node.js applications. No manual token handling, no interceptor setup, no middleware configuration required.
4
+
5
+ ## ✨ Quick Start (Zero Config)
6
+
7
+ ### Frontend (React/React Native)
8
+
9
+ ```tsx
10
+ import React from 'react';
11
+ import { AuthProvider, useAuth } from '@oxyhq/services';
12
+
13
+ // 1. Wrap your app (that's it for setup!)
14
+ function App() {
15
+ return (
16
+ <AuthProvider baseURL="https://api.oxy.so">
17
+ <MainApp />
18
+ </AuthProvider>
19
+ );
20
+ }
21
+
22
+ // 2. Use authentication anywhere
23
+ function MainApp() {
24
+ const { isAuthenticated, user, login, logout } = useAuth();
25
+
26
+ if (!isAuthenticated) {
27
+ return <button onClick={() => login('user', 'pass')}>Login</button>;
28
+ }
29
+
30
+ return (
31
+ <div>
32
+ <h1>Welcome {user?.username}!</h1>
33
+ <button onClick={logout}>Logout</button>
34
+ </div>
35
+ );
36
+ }
37
+ ```
38
+
39
+ ### Backend (Express.js)
40
+
41
+ ```typescript
42
+ import express from 'express';
43
+ import { authenticateRequest, OxyRequest } from '@oxyhq/services/api';
44
+
45
+ const app = express();
46
+
47
+ // Zero-config authentication - just add the middleware
48
+ app.get('/profile', authenticateRequest(), (req: OxyRequest, res) => {
49
+ // req.user is automatically populated!
50
+ res.json({
51
+ message: `Hello ${req.user!.username}!`,
52
+ user: req.user
53
+ });
54
+ });
55
+ ```
56
+
57
+ That's it! 🎉 Authentication is now fully automated with:
58
+ - ✅ Automatic token management and refresh
59
+ - ✅ Secure storage across app restarts
60
+ - ✅ Built-in error handling and retry logic
61
+ - ✅ Cross-platform support (React Native + Web)
62
+ - ✅ TypeScript support throughout
63
+
64
+ ## 📖 Documentation
65
+
66
+ - **[🚀 Zero-Config Authentication Guide](./packages/services/ZERO_CONFIG_AUTH.md)** - Complete setup guide
67
+ - **[🔧 Migration Guide](./packages/services/ZERO_CONFIG_AUTH.md#migration-from-legacy-authentication)** - Upgrade from legacy auth
68
+ - **[📚 Examples](./packages/services/examples/)** - Complete integration examples
69
+ - **[🔐 API Reference](./packages/services/ZERO_CONFIG_AUTH.md#complete-api-reference)** - All components and hooks
4
70
 
5
71
  ## Table of Contents
6
72
 
7
- - [Features](#features)
8
- - [Quick Start](#quick-start)
9
- - [Documentation](#documentation)
10
- - [UI Components](#ui-components)
73
+ - [Legacy Features](#features)
74
+ - [Legacy Quick Start](#quick-start)
11
75
  - [Package Exports](#package-exports)
12
76
  - [Requirements](#requirements)
13
77
  - [Development](#development)
14
78
  - [Integration](#integration)
15
79
  - [License](#license)
16
80
 
17
- ## Features
81
+ ---
82
+
83
+ ## Legacy Features (Still Supported)
84
+
85
+ A TypeScript client library for the Oxy API providing authentication, user management, and UI components for React and React Native applications.
18
86
 
19
87
  - 🔐 **Authentication**: JWT-based auth with automatic token refresh
20
- - 👥 **User Management**: Profile operations and social features
88
+ - 👥 **User Management**: Profile operations and social features
21
89
  - 🎨 **UI Components**: Pre-built React components for common functionality
22
90
  - 📱 **Cross-Platform**: Works in React Native and web applications
23
91
  - 🔧 **TypeScript**: Full type safety and IntelliSense support
24
92
 
25
- ## Quick Start
93
+ ## Legacy Quick Start
26
94
 
27
95
  ```bash
28
96
  npm install @oxyhq/services
@@ -45,10 +113,6 @@ const response = await oxy.auth.login({
45
113
  const user = await oxy.users.getCurrentUser();
46
114
  ```
47
115
 
48
- ## Documentation
49
-
50
- For comprehensive documentation, API reference, and examples:
51
-
52
116
  - [📚 Full Documentation](./docs/README.md)
53
117
  - [🚀 Quick Start Guide](./docs/quick-start.md)
54
118
  - [🔐 Core API Reference](./docs/core-api.md)
@@ -0,0 +1,440 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.AuthenticationManager = void 0;
7
+ exports.getAuthManager = getAuthManager;
8
+ exports.initializeAuth = initializeAuth;
9
+ var _axios = _interopRequireDefault(require("axios"));
10
+ var _jwtDecode = require("jwt-decode");
11
+ var _asyncStorage = _interopRequireDefault(require("@react-native-async-storage/async-storage"));
12
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
13
+ /**
14
+ * Zero-Config Authentication Manager
15
+ *
16
+ * This module provides automatic token management, session handling,
17
+ * and seamless authentication for Oxy services.
18
+ */
19
+
20
+ class AuthenticationManager {
21
+ tokens = null;
22
+ user = null;
23
+ refreshPromise = null;
24
+ listeners = [];
25
+ storageKey = '@oxy/auth-tokens';
26
+ constructor(baseURL) {
27
+ this.client = _axios.default.create({
28
+ baseURL,
29
+ timeout: 15000,
30
+ withCredentials: true // Enable cookies for session management
31
+ });
32
+ this.setupInterceptors();
33
+ this.initializeFromStorage();
34
+ }
35
+
36
+ /**
37
+ * Setup axios interceptors for automatic token management
38
+ */
39
+ setupInterceptors() {
40
+ // Request interceptor - automatically add auth headers
41
+ this.client.interceptors.request.use(async config => {
42
+ // Skip auth for login/signup endpoints
43
+ if (this.isPublicEndpoint(config.url || '')) {
44
+ return config;
45
+ }
46
+
47
+ // Ensure we have a valid token
48
+ await this.ensureValidToken();
49
+
50
+ // Add authorization header if we have a token
51
+ if (this.tokens?.accessToken) {
52
+ config.headers = config.headers || {};
53
+ config.headers.Authorization = `Bearer ${this.tokens.accessToken}`;
54
+ }
55
+ return config;
56
+ }, error => Promise.reject(error));
57
+
58
+ // Response interceptor - handle token expiration and auto-retry
59
+ this.client.interceptors.response.use(response => response, async error => {
60
+ const originalRequest = error.config;
61
+
62
+ // If it's a 401 and we haven't already retried, attempt token refresh
63
+ if (error.response?.status === 401 && !originalRequest._retry && this.tokens?.refreshToken && !this.isPublicEndpoint(originalRequest?.url || '')) {
64
+ originalRequest._retry = true;
65
+ try {
66
+ await this.refreshTokens();
67
+
68
+ // Retry original request with new token
69
+ if (originalRequest && this.tokens?.accessToken) {
70
+ originalRequest.headers = originalRequest.headers || {};
71
+ originalRequest.headers.Authorization = `Bearer ${this.tokens.accessToken}`;
72
+ return this.client(originalRequest);
73
+ }
74
+ } catch (refreshError) {
75
+ // Refresh failed, clear tokens and notify listeners
76
+ await this.logout();
77
+ return Promise.reject(error);
78
+ }
79
+ }
80
+
81
+ // For non-auth errors or failed retries, reject with formatted error
82
+ return Promise.reject(this.formatError(error));
83
+ });
84
+ }
85
+
86
+ /**
87
+ * Check if endpoint is public (doesn't require authentication)
88
+ */
89
+ isPublicEndpoint(url) {
90
+ const publicPaths = ['/auth/login', '/auth/signup', '/auth/register', '/auth/check-username', '/auth/check-email', '/health', '/'];
91
+ return publicPaths.some(path => url.includes(path));
92
+ }
93
+
94
+ /**
95
+ * Initialize authentication state from persistent storage
96
+ */
97
+ async initializeFromStorage() {
98
+ try {
99
+ const storedData = await _asyncStorage.default.getItem(this.storageKey);
100
+ if (storedData) {
101
+ const tokens = JSON.parse(storedData);
102
+
103
+ // Validate that tokens haven't expired
104
+ if (await this.validateStoredTokens(tokens)) {
105
+ this.tokens = tokens;
106
+ await this.fetchCurrentUser();
107
+ this.notifyStateChange();
108
+ } else {
109
+ // Tokens expired, clear storage
110
+ await _asyncStorage.default.removeItem(this.storageKey);
111
+ }
112
+ }
113
+ } catch (error) {
114
+ console.warn('[OxyAuth] Failed to initialize from storage:', error);
115
+ await _asyncStorage.default.removeItem(this.storageKey);
116
+ }
117
+ }
118
+
119
+ /**
120
+ * Validate stored tokens without making network calls if possible
121
+ */
122
+ async validateStoredTokens(tokens) {
123
+ try {
124
+ // First check if access token is expired
125
+ const decoded = (0, _jwtDecode.jwtDecode)(tokens.accessToken);
126
+ const now = Math.floor(Date.now() / 1000);
127
+
128
+ // If access token is still valid, we're good
129
+ if (decoded.exp > now + 60) {
130
+ // 60 second buffer
131
+ return true;
132
+ }
133
+
134
+ // Access token expired, try refresh token
135
+ const refreshDecoded = (0, _jwtDecode.jwtDecode)(tokens.refreshToken);
136
+ return refreshDecoded.exp > now;
137
+ } catch {
138
+ return false;
139
+ }
140
+ }
141
+
142
+ /**
143
+ * Ensure we have a valid access token
144
+ */
145
+ async ensureValidToken() {
146
+ if (!this.tokens?.accessToken) {
147
+ return;
148
+ }
149
+ try {
150
+ const decoded = (0, _jwtDecode.jwtDecode)(this.tokens.accessToken);
151
+ const now = Math.floor(Date.now() / 1000);
152
+
153
+ // Refresh if token expires within 5 minutes
154
+ if (decoded.exp - now < 300) {
155
+ await this.refreshTokens();
156
+ }
157
+ } catch (error) {
158
+ console.warn('[OxyAuth] Token validation error:', error);
159
+ // If token is malformed, try refresh
160
+ if (this.tokens?.refreshToken) {
161
+ await this.refreshTokens();
162
+ }
163
+ }
164
+ }
165
+
166
+ /**
167
+ * Login with credentials
168
+ */
169
+ async login(credentials) {
170
+ try {
171
+ const response = await this.client.post('/auth/login', credentials);
172
+ const loginData = response.data;
173
+ if (loginData.success && loginData.accessToken && loginData.refreshToken) {
174
+ await this.setTokens({
175
+ accessToken: loginData.accessToken,
176
+ refreshToken: loginData.refreshToken
177
+ });
178
+ this.user = loginData.user;
179
+ this.notifyStateChange();
180
+ return loginData;
181
+ } else {
182
+ throw new Error(loginData.message || 'Login failed');
183
+ }
184
+ } catch (error) {
185
+ throw this.formatError(error);
186
+ }
187
+ }
188
+
189
+ /**
190
+ * Register new user
191
+ */
192
+ async register(userData) {
193
+ try {
194
+ const response = await this.client.post('/auth/register', userData);
195
+ const registerData = response.data;
196
+ if (registerData.success && registerData.accessToken && registerData.refreshToken) {
197
+ await this.setTokens({
198
+ accessToken: registerData.accessToken,
199
+ refreshToken: registerData.refreshToken
200
+ });
201
+ this.user = registerData.user;
202
+ this.notifyStateChange();
203
+ return registerData;
204
+ } else {
205
+ throw new Error(registerData.message || 'Registration failed');
206
+ }
207
+ } catch (error) {
208
+ throw this.formatError(error);
209
+ }
210
+ }
211
+
212
+ /**
213
+ * Logout user and clear all tokens
214
+ */
215
+ async logout() {
216
+ // Attempt server-side logout if we have tokens
217
+ if (this.tokens?.refreshToken) {
218
+ try {
219
+ await this.client.post('/auth/logout', {
220
+ refreshToken: this.tokens.refreshToken
221
+ });
222
+ } catch (error) {
223
+ console.warn('[OxyAuth] Server logout failed:', error);
224
+ }
225
+ }
226
+
227
+ // Clear local state
228
+ this.tokens = null;
229
+ this.user = null;
230
+
231
+ // Clear storage
232
+ try {
233
+ await _asyncStorage.default.removeItem(this.storageKey);
234
+ } catch (error) {
235
+ console.warn('[OxyAuth] Failed to clear storage:', error);
236
+ }
237
+ this.notifyStateChange();
238
+ }
239
+
240
+ /**
241
+ * Refresh access token using refresh token
242
+ */
243
+ async refreshTokens() {
244
+ if (!this.tokens?.refreshToken) {
245
+ throw new Error('No refresh token available');
246
+ }
247
+
248
+ // If refresh is already in progress, return that promise
249
+ if (this.refreshPromise) {
250
+ return this.refreshPromise;
251
+ }
252
+ this.refreshPromise = this.performTokenRefresh();
253
+ try {
254
+ const newTokens = await this.refreshPromise;
255
+ this.refreshPromise = null;
256
+ return newTokens;
257
+ } catch (error) {
258
+ this.refreshPromise = null;
259
+ throw error;
260
+ }
261
+ }
262
+
263
+ /**
264
+ * Perform the actual token refresh
265
+ */
266
+ async performTokenRefresh() {
267
+ try {
268
+ const response = await this.client.post('/auth/refresh', {
269
+ refreshToken: this.tokens.refreshToken
270
+ });
271
+ const newTokens = {
272
+ accessToken: response.data.accessToken,
273
+ refreshToken: response.data.refreshToken
274
+ };
275
+ await this.setTokens(newTokens);
276
+ return newTokens;
277
+ } catch (error) {
278
+ // Refresh failed, clear all tokens
279
+ await this.logout();
280
+ throw this.formatError(error);
281
+ }
282
+ }
283
+
284
+ /**
285
+ * Set tokens and persist to storage
286
+ */
287
+ async setTokens(newTokens) {
288
+ this.tokens = newTokens;
289
+ try {
290
+ await _asyncStorage.default.setItem(this.storageKey, JSON.stringify(newTokens));
291
+ } catch (error) {
292
+ console.warn('[OxyAuth] Failed to persist tokens:', error);
293
+ }
294
+ }
295
+
296
+ /**
297
+ * Fetch current user profile
298
+ */
299
+ async fetchCurrentUser() {
300
+ try {
301
+ const response = await this.client.get('/auth/me');
302
+ this.user = response.data.data || response.data;
303
+ } catch (error) {
304
+ console.warn('[OxyAuth] Failed to fetch current user:', error);
305
+ // Don't throw here, we can still function without user profile
306
+ }
307
+ }
308
+
309
+ /**
310
+ * Get current authentication state
311
+ */
312
+ getAuthState() {
313
+ return {
314
+ isAuthenticated: !!this.tokens?.accessToken,
315
+ user: this.user,
316
+ tokens: this.tokens
317
+ };
318
+ }
319
+
320
+ /**
321
+ * Get current user (loads if not cached)
322
+ */
323
+ async getCurrentUser() {
324
+ if (!this.tokens?.accessToken) {
325
+ throw new Error('Not authenticated');
326
+ }
327
+ if (!this.user) {
328
+ await this.fetchCurrentUser();
329
+ }
330
+ return this.user;
331
+ }
332
+
333
+ /**
334
+ * Subscribe to authentication state changes
335
+ */
336
+ onAuthStateChange(callback) {
337
+ this.listeners.push(callback);
338
+
339
+ // Immediately call with current state
340
+ callback(this.getAuthState());
341
+
342
+ // Return unsubscribe function
343
+ return () => {
344
+ this.listeners = this.listeners.filter(listener => listener !== callback);
345
+ };
346
+ }
347
+
348
+ /**
349
+ * Notify all listeners of state changes
350
+ */
351
+ notifyStateChange() {
352
+ const state = this.getAuthState();
353
+ this.listeners.forEach(listener => {
354
+ try {
355
+ listener(state);
356
+ } catch (error) {
357
+ console.error('[OxyAuth] Listener error:', error);
358
+ }
359
+ });
360
+ }
361
+
362
+ /**
363
+ * Format error responses consistently
364
+ */
365
+ formatError(error) {
366
+ if (error?.response?.data?.message) {
367
+ return new Error(error.response.data.message);
368
+ }
369
+ if (error?.message) {
370
+ return new Error(error.message);
371
+ }
372
+ return new Error('An unexpected error occurred');
373
+ }
374
+
375
+ /**
376
+ * Get authenticated HTTP client for making API calls
377
+ */
378
+ getClient() {
379
+ return this.client;
380
+ }
381
+
382
+ /**
383
+ * Check username availability
384
+ */
385
+ async checkUsernameAvailability(username) {
386
+ try {
387
+ const response = await this.client.get(`/auth/check-username/${encodeURIComponent(username)}`);
388
+ return response.data;
389
+ } catch (error) {
390
+ const axiosError = error;
391
+ if (axiosError?.response?.status === 400) {
392
+ return axiosError.response.data;
393
+ }
394
+ throw this.formatError(error);
395
+ }
396
+ }
397
+
398
+ /**
399
+ * Check email availability
400
+ */
401
+ async checkEmailAvailability(email) {
402
+ try {
403
+ const response = await this.client.post('/auth/check-email', {
404
+ email
405
+ });
406
+ return response.data;
407
+ } catch (error) {
408
+ const axiosError = error;
409
+ if (axiosError?.response?.status === 400) {
410
+ return axiosError.response.data;
411
+ }
412
+ throw this.formatError(error);
413
+ }
414
+ }
415
+ }
416
+
417
+ // Global auth manager instance
418
+ exports.AuthenticationManager = AuthenticationManager;
419
+ let globalAuthManager = null;
420
+
421
+ /**
422
+ * Initialize global authentication manager
423
+ */
424
+ function initializeAuth(baseURL) {
425
+ if (!globalAuthManager) {
426
+ globalAuthManager = new AuthenticationManager(baseURL);
427
+ }
428
+ return globalAuthManager;
429
+ }
430
+
431
+ /**
432
+ * Get global authentication manager instance
433
+ */
434
+ function getAuthManager() {
435
+ if (!globalAuthManager) {
436
+ throw new Error('Authentication manager not initialized. Call initializeAuth() first.');
437
+ }
438
+ return globalAuthManager;
439
+ }
440
+ //# sourceMappingURL=auth-manager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_axios","_interopRequireDefault","require","_jwtDecode","_asyncStorage","e","__esModule","default","AuthenticationManager","tokens","user","refreshPromise","listeners","storageKey","constructor","baseURL","client","axios","create","timeout","withCredentials","setupInterceptors","initializeFromStorage","interceptors","request","use","config","isPublicEndpoint","url","ensureValidToken","accessToken","headers","Authorization","error","Promise","reject","response","originalRequest","status","_retry","refreshToken","refreshTokens","refreshError","logout","formatError","publicPaths","some","path","includes","storedData","AsyncStorage","getItem","JSON","parse","validateStoredTokens","fetchCurrentUser","notifyStateChange","removeItem","console","warn","decoded","jwtDecode","now","Math","floor","Date","exp","refreshDecoded","login","credentials","post","loginData","data","success","setTokens","Error","message","register","userData","registerData","performTokenRefresh","newTokens","setItem","stringify","get","getAuthState","isAuthenticated","getCurrentUser","onAuthStateChange","callback","push","filter","listener","state","forEach","getClient","checkUsernameAvailability","username","encodeURIComponent","axiosError","checkEmailAvailability","email","exports","globalAuthManager","initializeAuth","getAuthManager"],"sourceRoot":"../../../src","sources":["core/auth-manager.ts"],"mappings":";;;;;;;;AAOA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,UAAA,GAAAD,OAAA;AACA,IAAAE,aAAA,GAAAH,sBAAA,CAAAC,OAAA;AAAqE,SAAAD,uBAAAI,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AATrE;AACA;AACA;AACA;AACA;AACA;;AAqCO,MAAMG,qBAAqB,CAAC;EAEzBC,MAAM,GAAsB,IAAI;EAChCC,IAAI,GAAe,IAAI;EACvBC,cAAc,GAA+B,IAAI;EACjDC,SAAS,GAAmC,EAAE;EAC9CC,UAAU,GAAG,kBAAkB;EAEvCC,WAAWA,CAACC,OAAe,EAAE;IAC3B,IAAI,CAACC,MAAM,GAAGC,cAAK,CAACC,MAAM,CAAC;MACzBH,OAAO;MACPI,OAAO,EAAE,KAAK;MACdC,eAAe,EAAE,IAAI,CAAE;IACzB,CAAC,CAAC;IAEF,IAAI,CAACC,iBAAiB,CAAC,CAAC;IACxB,IAAI,CAACC,qBAAqB,CAAC,CAAC;EAC9B;;EAEA;AACF;AACA;EACUD,iBAAiBA,CAAA,EAAS;IAChC;IACA,IAAI,CAACL,MAAM,CAACO,YAAY,CAACC,OAAO,CAACC,GAAG,CAClC,MAAOC,MAAkC,IAAK;MAC5C;MACA,IAAI,IAAI,CAACC,gBAAgB,CAACD,MAAM,CAACE,GAAG,IAAI,EAAE,CAAC,EAAE;QAC3C,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