@anythink-cloud/sdk 0.2.1 → 0.3.1
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/dist/index.d.mts +142 -1
- package/dist/index.d.ts +142 -1
- package/dist/index.js +262 -8
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +261 -9
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -2
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import * as zustand_middleware from 'zustand/middleware';
|
|
2
2
|
import * as zustand from 'zustand';
|
|
3
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
4
|
+
import { ReactNode } from 'react';
|
|
3
5
|
import { AxiosInstance, AxiosRequestConfig } from 'axios';
|
|
4
6
|
|
|
5
7
|
/**
|
|
@@ -120,9 +122,11 @@ interface CookieStorageOptions {
|
|
|
120
122
|
|
|
121
123
|
interface AuthState {
|
|
122
124
|
session: Session | null;
|
|
125
|
+
user: User | null;
|
|
123
126
|
isLoading: boolean;
|
|
124
127
|
error: Error | null;
|
|
125
128
|
setSession: (session: Session | null) => void;
|
|
129
|
+
setUser: (user: User | null) => void;
|
|
126
130
|
signOut: () => void;
|
|
127
131
|
clearError: () => void;
|
|
128
132
|
setLoading: (isLoading: boolean) => void;
|
|
@@ -231,12 +235,149 @@ declare class AuthClient {
|
|
|
231
235
|
* Check if user is authenticated
|
|
232
236
|
*/
|
|
233
237
|
isAuthenticated(): boolean;
|
|
238
|
+
/**
|
|
239
|
+
* Fetch user information from the API
|
|
240
|
+
* @returns User object or null if failed
|
|
241
|
+
*/
|
|
242
|
+
fetchUserInfo(): Promise<{
|
|
243
|
+
data: {
|
|
244
|
+
user: User | null;
|
|
245
|
+
};
|
|
246
|
+
error: Error | null;
|
|
247
|
+
}>;
|
|
248
|
+
/**
|
|
249
|
+
* Get the current user
|
|
250
|
+
* @returns User object or null if not available
|
|
251
|
+
*/
|
|
252
|
+
getUser(): User | null;
|
|
234
253
|
/**
|
|
235
254
|
* Get the Zustand store (for React hooks)
|
|
236
255
|
*/
|
|
237
256
|
getStore(): ReturnType<typeof createAuthStore>;
|
|
238
257
|
}
|
|
239
258
|
|
|
259
|
+
/**
|
|
260
|
+
* Callback functions for auth events
|
|
261
|
+
*/
|
|
262
|
+
interface AuthCallbacks {
|
|
263
|
+
/**
|
|
264
|
+
* Called after successful sign in
|
|
265
|
+
*/
|
|
266
|
+
onSignIn?: (session: Session) => void | Promise<void>;
|
|
267
|
+
/**
|
|
268
|
+
* Called after sign out
|
|
269
|
+
*/
|
|
270
|
+
onSignOut?: () => void | Promise<void>;
|
|
271
|
+
/**
|
|
272
|
+
* Called when token refresh fails and user is signed out
|
|
273
|
+
*/
|
|
274
|
+
onTokenRefreshFailed?: () => void | Promise<void>;
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Auth context value
|
|
278
|
+
*/
|
|
279
|
+
interface AuthContextValue {
|
|
280
|
+
/**
|
|
281
|
+
* Current session
|
|
282
|
+
*/
|
|
283
|
+
session: Session | null;
|
|
284
|
+
/**
|
|
285
|
+
* Current user information
|
|
286
|
+
*/
|
|
287
|
+
user: User | null;
|
|
288
|
+
/**
|
|
289
|
+
* Whether auth operations are in progress
|
|
290
|
+
*/
|
|
291
|
+
isLoading: boolean;
|
|
292
|
+
/**
|
|
293
|
+
* Current error, if any
|
|
294
|
+
*/
|
|
295
|
+
error: Error | null;
|
|
296
|
+
/**
|
|
297
|
+
* Whether user is authenticated
|
|
298
|
+
*/
|
|
299
|
+
isAuthenticated: boolean;
|
|
300
|
+
/**
|
|
301
|
+
* Sign in with email and password
|
|
302
|
+
*/
|
|
303
|
+
signIn: (email: string, password: string, orgId?: number) => Promise<SignInResponse>;
|
|
304
|
+
/**
|
|
305
|
+
* Sign out and clear session
|
|
306
|
+
*/
|
|
307
|
+
signOut: () => Promise<{
|
|
308
|
+
error: Error | null;
|
|
309
|
+
}>;
|
|
310
|
+
/**
|
|
311
|
+
* Register a new user
|
|
312
|
+
*/
|
|
313
|
+
register: (firstName: string, lastName: string, email: string, password: string) => Promise<{
|
|
314
|
+
error: Error | null;
|
|
315
|
+
}>;
|
|
316
|
+
/**
|
|
317
|
+
* Change password
|
|
318
|
+
*/
|
|
319
|
+
changePassword: (currentPassword: string, newPassword: string) => Promise<{
|
|
320
|
+
error: Error | null;
|
|
321
|
+
}>;
|
|
322
|
+
/**
|
|
323
|
+
* Refresh the session token
|
|
324
|
+
*/
|
|
325
|
+
refreshSession: () => Promise<RefreshResponse>;
|
|
326
|
+
/**
|
|
327
|
+
* Get the current access token
|
|
328
|
+
*/
|
|
329
|
+
getAccessToken: () => string | null;
|
|
330
|
+
/**
|
|
331
|
+
* Get the current refresh token
|
|
332
|
+
*/
|
|
333
|
+
getRefreshToken: () => string | null;
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
336
|
+
* Props for AuthProvider
|
|
337
|
+
*/
|
|
338
|
+
interface AuthProviderProps {
|
|
339
|
+
/**
|
|
340
|
+
* AuthClient instance
|
|
341
|
+
*/
|
|
342
|
+
authClient: AuthClient;
|
|
343
|
+
/**
|
|
344
|
+
* Optional callbacks for auth events
|
|
345
|
+
*/
|
|
346
|
+
callbacks?: AuthCallbacks;
|
|
347
|
+
/**
|
|
348
|
+
* Whether to automatically refresh tokens before they expire
|
|
349
|
+
* @default true
|
|
350
|
+
*/
|
|
351
|
+
autoRefresh?: boolean;
|
|
352
|
+
/**
|
|
353
|
+
* How many seconds before expiration to refresh the token
|
|
354
|
+
* @default 60
|
|
355
|
+
*/
|
|
356
|
+
refreshThreshold?: number;
|
|
357
|
+
/**
|
|
358
|
+
* URL to redirect to when user is not authenticated or token refresh fails
|
|
359
|
+
*/
|
|
360
|
+
loginUrl: string;
|
|
361
|
+
/**
|
|
362
|
+
* Path prefix for auth pages (e.g., "/auth"). Pages starting with this prefix
|
|
363
|
+
* will skip session checks and redirects
|
|
364
|
+
*/
|
|
365
|
+
authPrefix: string;
|
|
366
|
+
/**
|
|
367
|
+
* Child components
|
|
368
|
+
*/
|
|
369
|
+
children: ReactNode;
|
|
370
|
+
}
|
|
371
|
+
/**
|
|
372
|
+
* AuthProvider component that wraps your app and provides auth state
|
|
373
|
+
*/
|
|
374
|
+
declare function AuthProvider({ authClient, callbacks, autoRefresh, refreshThreshold, loginUrl, authPrefix, children, }: AuthProviderProps): react_jsx_runtime.JSX.Element;
|
|
375
|
+
/**
|
|
376
|
+
* Hook to access auth context
|
|
377
|
+
* @throws Error if used outside AuthProvider
|
|
378
|
+
*/
|
|
379
|
+
declare function useAuth(): AuthContextValue;
|
|
380
|
+
|
|
240
381
|
/**
|
|
241
382
|
* Base service class with automatic token injection and refresh handling
|
|
242
383
|
*/
|
|
@@ -279,4 +420,4 @@ declare class AuthenticatedBaseService {
|
|
|
279
420
|
getClient(): AxiosInstance;
|
|
280
421
|
}
|
|
281
422
|
|
|
282
|
-
export { AuthClient, type AuthConfig, AuthenticatedBaseService, type CookieStorageConfig, type RefreshResponse, type Session, type SignInResponse, type TokenPair, type User, createAuthStore };
|
|
423
|
+
export { type AuthCallbacks, AuthClient, type AuthConfig, type AuthContextValue, AuthProvider, type AuthProviderProps, AuthenticatedBaseService, type CookieStorageConfig, type RefreshResponse, type Session, type SignInResponse, type TokenPair, type User, createAuthStore, useAuth };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import * as zustand_middleware from 'zustand/middleware';
|
|
2
2
|
import * as zustand from 'zustand';
|
|
3
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
4
|
+
import { ReactNode } from 'react';
|
|
3
5
|
import { AxiosInstance, AxiosRequestConfig } from 'axios';
|
|
4
6
|
|
|
5
7
|
/**
|
|
@@ -120,9 +122,11 @@ interface CookieStorageOptions {
|
|
|
120
122
|
|
|
121
123
|
interface AuthState {
|
|
122
124
|
session: Session | null;
|
|
125
|
+
user: User | null;
|
|
123
126
|
isLoading: boolean;
|
|
124
127
|
error: Error | null;
|
|
125
128
|
setSession: (session: Session | null) => void;
|
|
129
|
+
setUser: (user: User | null) => void;
|
|
126
130
|
signOut: () => void;
|
|
127
131
|
clearError: () => void;
|
|
128
132
|
setLoading: (isLoading: boolean) => void;
|
|
@@ -231,12 +235,149 @@ declare class AuthClient {
|
|
|
231
235
|
* Check if user is authenticated
|
|
232
236
|
*/
|
|
233
237
|
isAuthenticated(): boolean;
|
|
238
|
+
/**
|
|
239
|
+
* Fetch user information from the API
|
|
240
|
+
* @returns User object or null if failed
|
|
241
|
+
*/
|
|
242
|
+
fetchUserInfo(): Promise<{
|
|
243
|
+
data: {
|
|
244
|
+
user: User | null;
|
|
245
|
+
};
|
|
246
|
+
error: Error | null;
|
|
247
|
+
}>;
|
|
248
|
+
/**
|
|
249
|
+
* Get the current user
|
|
250
|
+
* @returns User object or null if not available
|
|
251
|
+
*/
|
|
252
|
+
getUser(): User | null;
|
|
234
253
|
/**
|
|
235
254
|
* Get the Zustand store (for React hooks)
|
|
236
255
|
*/
|
|
237
256
|
getStore(): ReturnType<typeof createAuthStore>;
|
|
238
257
|
}
|
|
239
258
|
|
|
259
|
+
/**
|
|
260
|
+
* Callback functions for auth events
|
|
261
|
+
*/
|
|
262
|
+
interface AuthCallbacks {
|
|
263
|
+
/**
|
|
264
|
+
* Called after successful sign in
|
|
265
|
+
*/
|
|
266
|
+
onSignIn?: (session: Session) => void | Promise<void>;
|
|
267
|
+
/**
|
|
268
|
+
* Called after sign out
|
|
269
|
+
*/
|
|
270
|
+
onSignOut?: () => void | Promise<void>;
|
|
271
|
+
/**
|
|
272
|
+
* Called when token refresh fails and user is signed out
|
|
273
|
+
*/
|
|
274
|
+
onTokenRefreshFailed?: () => void | Promise<void>;
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Auth context value
|
|
278
|
+
*/
|
|
279
|
+
interface AuthContextValue {
|
|
280
|
+
/**
|
|
281
|
+
* Current session
|
|
282
|
+
*/
|
|
283
|
+
session: Session | null;
|
|
284
|
+
/**
|
|
285
|
+
* Current user information
|
|
286
|
+
*/
|
|
287
|
+
user: User | null;
|
|
288
|
+
/**
|
|
289
|
+
* Whether auth operations are in progress
|
|
290
|
+
*/
|
|
291
|
+
isLoading: boolean;
|
|
292
|
+
/**
|
|
293
|
+
* Current error, if any
|
|
294
|
+
*/
|
|
295
|
+
error: Error | null;
|
|
296
|
+
/**
|
|
297
|
+
* Whether user is authenticated
|
|
298
|
+
*/
|
|
299
|
+
isAuthenticated: boolean;
|
|
300
|
+
/**
|
|
301
|
+
* Sign in with email and password
|
|
302
|
+
*/
|
|
303
|
+
signIn: (email: string, password: string, orgId?: number) => Promise<SignInResponse>;
|
|
304
|
+
/**
|
|
305
|
+
* Sign out and clear session
|
|
306
|
+
*/
|
|
307
|
+
signOut: () => Promise<{
|
|
308
|
+
error: Error | null;
|
|
309
|
+
}>;
|
|
310
|
+
/**
|
|
311
|
+
* Register a new user
|
|
312
|
+
*/
|
|
313
|
+
register: (firstName: string, lastName: string, email: string, password: string) => Promise<{
|
|
314
|
+
error: Error | null;
|
|
315
|
+
}>;
|
|
316
|
+
/**
|
|
317
|
+
* Change password
|
|
318
|
+
*/
|
|
319
|
+
changePassword: (currentPassword: string, newPassword: string) => Promise<{
|
|
320
|
+
error: Error | null;
|
|
321
|
+
}>;
|
|
322
|
+
/**
|
|
323
|
+
* Refresh the session token
|
|
324
|
+
*/
|
|
325
|
+
refreshSession: () => Promise<RefreshResponse>;
|
|
326
|
+
/**
|
|
327
|
+
* Get the current access token
|
|
328
|
+
*/
|
|
329
|
+
getAccessToken: () => string | null;
|
|
330
|
+
/**
|
|
331
|
+
* Get the current refresh token
|
|
332
|
+
*/
|
|
333
|
+
getRefreshToken: () => string | null;
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
336
|
+
* Props for AuthProvider
|
|
337
|
+
*/
|
|
338
|
+
interface AuthProviderProps {
|
|
339
|
+
/**
|
|
340
|
+
* AuthClient instance
|
|
341
|
+
*/
|
|
342
|
+
authClient: AuthClient;
|
|
343
|
+
/**
|
|
344
|
+
* Optional callbacks for auth events
|
|
345
|
+
*/
|
|
346
|
+
callbacks?: AuthCallbacks;
|
|
347
|
+
/**
|
|
348
|
+
* Whether to automatically refresh tokens before they expire
|
|
349
|
+
* @default true
|
|
350
|
+
*/
|
|
351
|
+
autoRefresh?: boolean;
|
|
352
|
+
/**
|
|
353
|
+
* How many seconds before expiration to refresh the token
|
|
354
|
+
* @default 60
|
|
355
|
+
*/
|
|
356
|
+
refreshThreshold?: number;
|
|
357
|
+
/**
|
|
358
|
+
* URL to redirect to when user is not authenticated or token refresh fails
|
|
359
|
+
*/
|
|
360
|
+
loginUrl: string;
|
|
361
|
+
/**
|
|
362
|
+
* Path prefix for auth pages (e.g., "/auth"). Pages starting with this prefix
|
|
363
|
+
* will skip session checks and redirects
|
|
364
|
+
*/
|
|
365
|
+
authPrefix: string;
|
|
366
|
+
/**
|
|
367
|
+
* Child components
|
|
368
|
+
*/
|
|
369
|
+
children: ReactNode;
|
|
370
|
+
}
|
|
371
|
+
/**
|
|
372
|
+
* AuthProvider component that wraps your app and provides auth state
|
|
373
|
+
*/
|
|
374
|
+
declare function AuthProvider({ authClient, callbacks, autoRefresh, refreshThreshold, loginUrl, authPrefix, children, }: AuthProviderProps): react_jsx_runtime.JSX.Element;
|
|
375
|
+
/**
|
|
376
|
+
* Hook to access auth context
|
|
377
|
+
* @throws Error if used outside AuthProvider
|
|
378
|
+
*/
|
|
379
|
+
declare function useAuth(): AuthContextValue;
|
|
380
|
+
|
|
240
381
|
/**
|
|
241
382
|
* Base service class with automatic token injection and refresh handling
|
|
242
383
|
*/
|
|
@@ -279,4 +420,4 @@ declare class AuthenticatedBaseService {
|
|
|
279
420
|
getClient(): AxiosInstance;
|
|
280
421
|
}
|
|
281
422
|
|
|
282
|
-
export { AuthClient, type AuthConfig, AuthenticatedBaseService, type CookieStorageConfig, type RefreshResponse, type Session, type SignInResponse, type TokenPair, type User, createAuthStore };
|
|
423
|
+
export { type AuthCallbacks, AuthClient, type AuthConfig, type AuthContextValue, AuthProvider, type AuthProviderProps, AuthenticatedBaseService, type CookieStorageConfig, type RefreshResponse, type Session, type SignInResponse, type TokenPair, type User, createAuthStore, useAuth };
|