@oxyhq/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.
Files changed (119) hide show
  1. package/README.md +56 -0
  2. package/dist/cjs/WebOxyProvider.js +287 -0
  3. package/dist/cjs/hooks/mutations/index.js +23 -0
  4. package/dist/cjs/hooks/mutations/mutationFactory.js +126 -0
  5. package/dist/cjs/hooks/mutations/useAccountMutations.js +275 -0
  6. package/dist/cjs/hooks/mutations/useServicesMutations.js +149 -0
  7. package/dist/cjs/hooks/queries/index.js +35 -0
  8. package/dist/cjs/hooks/queries/queryKeys.js +82 -0
  9. package/dist/cjs/hooks/queries/useAccountQueries.js +141 -0
  10. package/dist/cjs/hooks/queries/useSecurityQueries.js +45 -0
  11. package/dist/cjs/hooks/queries/useServicesQueries.js +113 -0
  12. package/dist/cjs/hooks/queryClient.js +110 -0
  13. package/dist/cjs/hooks/useAssets.js +225 -0
  14. package/dist/cjs/hooks/useFileDownloadUrl.js +91 -0
  15. package/dist/cjs/hooks/useFileFiltering.js +81 -0
  16. package/dist/cjs/hooks/useFollow.js +159 -0
  17. package/dist/cjs/hooks/useFollow.types.js +4 -0
  18. package/dist/cjs/hooks/useQueryClient.js +16 -0
  19. package/dist/cjs/hooks/useSessionSocket.js +215 -0
  20. package/dist/cjs/hooks/useWebSSO.js +146 -0
  21. package/dist/cjs/index.js +115 -0
  22. package/dist/cjs/stores/accountStore.js +226 -0
  23. package/dist/cjs/stores/assetStore.js +192 -0
  24. package/dist/cjs/stores/authStore.js +47 -0
  25. package/dist/cjs/stores/followStore.js +154 -0
  26. package/dist/cjs/utils/authHelpers.js +154 -0
  27. package/dist/cjs/utils/avatarUtils.js +77 -0
  28. package/dist/cjs/utils/errorHandlers.js +128 -0
  29. package/dist/cjs/utils/sessionHelpers.js +90 -0
  30. package/dist/cjs/utils/storageHelpers.js +147 -0
  31. package/dist/esm/WebOxyProvider.js +282 -0
  32. package/dist/esm/hooks/mutations/index.js +10 -0
  33. package/dist/esm/hooks/mutations/mutationFactory.js +122 -0
  34. package/dist/esm/hooks/mutations/useAccountMutations.js +267 -0
  35. package/dist/esm/hooks/mutations/useServicesMutations.js +141 -0
  36. package/dist/esm/hooks/queries/index.js +14 -0
  37. package/dist/esm/hooks/queries/queryKeys.js +76 -0
  38. package/dist/esm/hooks/queries/useAccountQueries.js +131 -0
  39. package/dist/esm/hooks/queries/useSecurityQueries.js +40 -0
  40. package/dist/esm/hooks/queries/useServicesQueries.js +105 -0
  41. package/dist/esm/hooks/queryClient.js +104 -0
  42. package/dist/esm/hooks/useAssets.js +220 -0
  43. package/dist/esm/hooks/useFileDownloadUrl.js +86 -0
  44. package/dist/esm/hooks/useFileFiltering.js +78 -0
  45. package/dist/esm/hooks/useFollow.js +154 -0
  46. package/dist/esm/hooks/useFollow.types.js +3 -0
  47. package/dist/esm/hooks/useQueryClient.js +12 -0
  48. package/dist/esm/hooks/useSessionSocket.js +209 -0
  49. package/dist/esm/hooks/useWebSSO.js +143 -0
  50. package/dist/esm/index.js +48 -0
  51. package/dist/esm/stores/accountStore.js +219 -0
  52. package/dist/esm/stores/assetStore.js +180 -0
  53. package/dist/esm/stores/authStore.js +44 -0
  54. package/dist/esm/stores/followStore.js +151 -0
  55. package/dist/esm/utils/authHelpers.js +145 -0
  56. package/dist/esm/utils/avatarUtils.js +72 -0
  57. package/dist/esm/utils/errorHandlers.js +121 -0
  58. package/dist/esm/utils/sessionHelpers.js +84 -0
  59. package/dist/esm/utils/storageHelpers.js +108 -0
  60. package/dist/types/WebOxyProvider.d.ts +97 -0
  61. package/dist/types/hooks/mutations/index.d.ts +8 -0
  62. package/dist/types/hooks/mutations/mutationFactory.d.ts +75 -0
  63. package/dist/types/hooks/mutations/useAccountMutations.d.ts +68 -0
  64. package/dist/types/hooks/mutations/useServicesMutations.d.ts +22 -0
  65. package/dist/types/hooks/queries/index.d.ts +10 -0
  66. package/dist/types/hooks/queries/queryKeys.d.ts +64 -0
  67. package/dist/types/hooks/queries/useAccountQueries.d.ts +42 -0
  68. package/dist/types/hooks/queries/useSecurityQueries.d.ts +14 -0
  69. package/dist/types/hooks/queries/useServicesQueries.d.ts +31 -0
  70. package/dist/types/hooks/queryClient.d.ts +18 -0
  71. package/dist/types/hooks/useAssets.d.ts +34 -0
  72. package/dist/types/hooks/useFileDownloadUrl.d.ts +18 -0
  73. package/dist/types/hooks/useFileFiltering.d.ts +28 -0
  74. package/dist/types/hooks/useFollow.d.ts +61 -0
  75. package/dist/types/hooks/useFollow.types.d.ts +32 -0
  76. package/dist/types/hooks/useQueryClient.d.ts +6 -0
  77. package/dist/types/hooks/useSessionSocket.d.ts +13 -0
  78. package/dist/types/hooks/useWebSSO.d.ts +57 -0
  79. package/dist/types/index.d.ts +46 -0
  80. package/dist/types/stores/accountStore.d.ts +33 -0
  81. package/dist/types/stores/assetStore.d.ts +53 -0
  82. package/dist/types/stores/authStore.d.ts +16 -0
  83. package/dist/types/stores/followStore.d.ts +24 -0
  84. package/dist/types/utils/authHelpers.d.ts +98 -0
  85. package/dist/types/utils/avatarUtils.d.ts +33 -0
  86. package/dist/types/utils/errorHandlers.d.ts +34 -0
  87. package/dist/types/utils/sessionHelpers.d.ts +63 -0
  88. package/dist/types/utils/storageHelpers.d.ts +27 -0
  89. package/package.json +71 -0
  90. package/src/WebOxyProvider.tsx +372 -0
  91. package/src/global.d.ts +1 -0
  92. package/src/hooks/mutations/index.ts +25 -0
  93. package/src/hooks/mutations/mutationFactory.ts +215 -0
  94. package/src/hooks/mutations/useAccountMutations.ts +344 -0
  95. package/src/hooks/mutations/useServicesMutations.ts +164 -0
  96. package/src/hooks/queries/index.ts +36 -0
  97. package/src/hooks/queries/queryKeys.ts +88 -0
  98. package/src/hooks/queries/useAccountQueries.ts +152 -0
  99. package/src/hooks/queries/useSecurityQueries.ts +64 -0
  100. package/src/hooks/queries/useServicesQueries.ts +126 -0
  101. package/src/hooks/queryClient.ts +112 -0
  102. package/src/hooks/useAssets.ts +291 -0
  103. package/src/hooks/useFileDownloadUrl.ts +118 -0
  104. package/src/hooks/useFileFiltering.ts +115 -0
  105. package/src/hooks/useFollow.ts +175 -0
  106. package/src/hooks/useFollow.types.ts +33 -0
  107. package/src/hooks/useQueryClient.ts +17 -0
  108. package/src/hooks/useSessionSocket.ts +233 -0
  109. package/src/hooks/useWebSSO.ts +187 -0
  110. package/src/index.ts +144 -0
  111. package/src/stores/accountStore.ts +296 -0
  112. package/src/stores/assetStore.ts +281 -0
  113. package/src/stores/authStore.ts +63 -0
  114. package/src/stores/followStore.ts +181 -0
  115. package/src/utils/authHelpers.ts +183 -0
  116. package/src/utils/avatarUtils.ts +103 -0
  117. package/src/utils/errorHandlers.ts +194 -0
  118. package/src/utils/sessionHelpers.ts +151 -0
  119. package/src/utils/storageHelpers.ts +130 -0
@@ -0,0 +1,33 @@
1
+ import type { OxyServices } from '@oxyhq/core';
2
+ export interface QuickAccount {
3
+ sessionId: string;
4
+ userId?: string;
5
+ username: string;
6
+ displayName: string;
7
+ avatar?: string;
8
+ avatarUrl?: string;
9
+ }
10
+ interface AccountState {
11
+ accounts: Record<string, QuickAccount>;
12
+ accountOrder: string[];
13
+ accountsArray: QuickAccount[];
14
+ loading: boolean;
15
+ loadingSessionIds: Set<string>;
16
+ error: string | null;
17
+ setAccounts: (accounts: QuickAccount[]) => void;
18
+ addAccount: (account: QuickAccount) => void;
19
+ updateAccount: (sessionId: string, updates: Partial<QuickAccount>) => void;
20
+ removeAccount: (sessionId: string) => void;
21
+ moveAccountToTop: (sessionId: string) => void;
22
+ setLoading: (loading: boolean) => void;
23
+ setLoadingSession: (sessionId: string, loading: boolean) => void;
24
+ setError: (error: string | null) => void;
25
+ loadAccounts: (sessionIds: string[], oxyServices: OxyServices, existingAccounts?: QuickAccount[], preserveOrder?: boolean) => Promise<void>;
26
+ reset: () => void;
27
+ }
28
+ export declare const useAccountStore: import("zustand").UseBoundStore<import("zustand").StoreApi<AccountState>>;
29
+ export declare const useAccounts: () => QuickAccount[];
30
+ export declare const useAccountLoading: () => boolean;
31
+ export declare const useAccountError: () => string | null;
32
+ export declare const useAccountLoadingSession: (sessionId: string) => boolean;
33
+ export {};
@@ -0,0 +1,53 @@
1
+ import { Asset, AssetUploadProgress, AssetLink } from '@oxyhq/core';
2
+ interface AssetState {
3
+ assets: Record<string, Asset>;
4
+ uploadProgress: Record<string, AssetUploadProgress>;
5
+ loading: {
6
+ uploading: boolean;
7
+ linking: boolean;
8
+ deleting: boolean;
9
+ };
10
+ errors: {
11
+ upload?: string;
12
+ link?: string;
13
+ delete?: string;
14
+ };
15
+ setAsset: (asset: Asset) => void;
16
+ setAssets: (assets: Asset[]) => void;
17
+ removeAsset: (assetId: string) => void;
18
+ setUploadProgress: (fileId: string, progress: AssetUploadProgress) => void;
19
+ removeUploadProgress: (fileId: string) => void;
20
+ addLink: (assetId: string, link: AssetLink) => void;
21
+ removeLink: (assetId: string, app: string, entityType: string, entityId: string) => void;
22
+ setUploading: (uploading: boolean) => void;
23
+ setLinking: (linking: boolean) => void;
24
+ setDeleting: (deleting: boolean) => void;
25
+ setUploadError: (error?: string) => void;
26
+ setLinkError: (error?: string) => void;
27
+ setDeleteError: (error?: string) => void;
28
+ clearErrors: () => void;
29
+ getAssetsByApp: (app: string) => Asset[];
30
+ getAssetsByEntity: (app: string, entityType: string, entityId: string) => Asset[];
31
+ getAssetUsageCount: (assetId: string) => number;
32
+ isAssetLinked: (assetId: string, app: string, entityType: string, entityId: string) => boolean;
33
+ reset: () => void;
34
+ }
35
+ export declare const useAssetStore: import("zustand").UseBoundStore<import("zustand").StoreApi<AssetState>>;
36
+ export declare const useAssets: () => Asset[];
37
+ export declare const useAsset: (assetId: string) => Asset;
38
+ export declare const useUploadProgress: () => Record<string, AssetUploadProgress>;
39
+ export declare const useAssetLoading: () => {
40
+ uploading: boolean;
41
+ linking: boolean;
42
+ deleting: boolean;
43
+ };
44
+ export declare const useAssetErrors: () => {
45
+ upload?: string;
46
+ link?: string;
47
+ delete?: string;
48
+ };
49
+ export declare const useAssetsByApp: (app: string) => Asset[];
50
+ export declare const useAssetsByEntity: (app: string, entityType: string, entityId: string) => Asset[];
51
+ export declare const useAssetUsageCount: (assetId: string) => number;
52
+ export declare const useIsAssetLinked: (assetId: string, app: string, entityType: string, entityId: string) => boolean;
53
+ export {};
@@ -0,0 +1,16 @@
1
+ import type { User } from '@oxyhq/core';
2
+ export interface AuthState {
3
+ user: User | null;
4
+ isAuthenticated: boolean;
5
+ isLoading: boolean;
6
+ error: string | null;
7
+ lastUserFetch: number | null;
8
+ loginSuccess: (user: User) => void;
9
+ loginFailure: (error: string) => void;
10
+ logout: () => void;
11
+ fetchUser: (oxyServices: {
12
+ getCurrentUser: () => Promise<User>;
13
+ }, forceRefresh?: boolean) => Promise<void>;
14
+ setUser: (user: User) => void;
15
+ }
16
+ export declare const useAuthStore: import("zustand").UseBoundStore<import("zustand").StoreApi<AuthState>>;
@@ -0,0 +1,24 @@
1
+ import type { OxyServices } from '@oxyhq/core';
2
+ interface FollowState {
3
+ followingUsers: Record<string, boolean>;
4
+ loadingUsers: Record<string, boolean>;
5
+ fetchingUsers: Record<string, boolean>;
6
+ errors: Record<string, string | null>;
7
+ followerCounts: Record<string, number>;
8
+ followingCounts: Record<string, number>;
9
+ loadingCounts: Record<string, boolean>;
10
+ setFollowingStatus: (userId: string, isFollowing: boolean) => void;
11
+ clearFollowError: (userId: string) => void;
12
+ resetFollowState: () => void;
13
+ fetchFollowStatus: (userId: string, oxyServices: OxyServices) => Promise<void>;
14
+ toggleFollowUser: (userId: string, oxyServices: OxyServices, isCurrentlyFollowing: boolean) => Promise<void>;
15
+ setFollowerCount: (userId: string, count: number) => void;
16
+ setFollowingCount: (userId: string, count: number) => void;
17
+ updateCountsFromFollowAction: (targetUserId: string, action: 'follow' | 'unfollow', counts: {
18
+ followers: number;
19
+ following: number;
20
+ }, currentUserId?: string) => void;
21
+ fetchUserCounts: (userId: string, oxyServices: OxyServices) => Promise<void>;
22
+ }
23
+ export declare const useFollowStore: import("zustand").UseBoundStore<import("zustand").StoreApi<FollowState>>;
24
+ export {};
@@ -0,0 +1,98 @@
1
+ /**
2
+ * Authentication helper utilities to reduce code duplication across hooks and utilities.
3
+ * These functions handle common token validation and authentication error patterns.
4
+ */
5
+ import type { OxyServices } from '@oxyhq/core';
6
+ /**
7
+ * Error thrown when session sync is required
8
+ */
9
+ export declare class SessionSyncRequiredError extends Error {
10
+ constructor(message?: string);
11
+ }
12
+ /**
13
+ * Error thrown when authentication fails
14
+ */
15
+ export declare class AuthenticationFailedError extends Error {
16
+ constructor(message?: string);
17
+ }
18
+ /**
19
+ * Ensures a valid token exists before making authenticated API calls.
20
+ * If no valid token exists and an active session ID is available,
21
+ * attempts to refresh the token using the session.
22
+ *
23
+ * @param oxyServices - The OxyServices instance
24
+ * @param activeSessionId - The active session ID (if available)
25
+ * @throws {SessionSyncRequiredError} If the session needs to be synced (offline session)
26
+ * @throws {Error} If token refresh fails for other reasons
27
+ *
28
+ * @example
29
+ * ```ts
30
+ * // In a mutation or query function:
31
+ * await ensureValidToken(oxyServices, activeSessionId);
32
+ * return await oxyServices.updateProfile(updates);
33
+ * ```
34
+ */
35
+ export declare function ensureValidToken(oxyServices: OxyServices, activeSessionId: string | null | undefined): Promise<void>;
36
+ /**
37
+ * Options for handling API authentication errors
38
+ */
39
+ export interface HandleApiErrorOptions {
40
+ /** Optional callback to attempt session sync and retry */
41
+ syncSession?: () => Promise<unknown>;
42
+ /** The active session ID for retry attempts */
43
+ activeSessionId?: string | null;
44
+ /** The OxyServices instance for retry attempts */
45
+ oxyServices?: OxyServices;
46
+ }
47
+ /**
48
+ * Checks if an error is an authentication error (401 or auth-related message)
49
+ *
50
+ * @param error - The error to check
51
+ * @returns True if the error is an authentication error
52
+ */
53
+ export declare function isAuthenticationError(error: unknown): boolean;
54
+ /**
55
+ * Wraps an API call with authentication error handling.
56
+ * If an authentication error occurs, it can optionally attempt to sync the session and retry.
57
+ *
58
+ * @param apiCall - The API call function to execute
59
+ * @param options - Optional error handling configuration
60
+ * @returns The result of the API call
61
+ * @throws {AuthenticationFailedError} If authentication fails and cannot be recovered
62
+ * @throws {Error} If the API call fails for non-auth reasons
63
+ *
64
+ * @example
65
+ * ```ts
66
+ * // Simple usage:
67
+ * const result = await withAuthErrorHandling(
68
+ * () => oxyServices.updateProfile(updates)
69
+ * );
70
+ *
71
+ * // With retry on auth failure:
72
+ * const result = await withAuthErrorHandling(
73
+ * () => oxyServices.updateProfile(updates),
74
+ * { syncSession, activeSessionId, oxyServices }
75
+ * );
76
+ * ```
77
+ */
78
+ export declare function withAuthErrorHandling<T>(apiCall: () => Promise<T>, options?: HandleApiErrorOptions): Promise<T>;
79
+ /**
80
+ * Combines token validation and auth error handling for a complete authenticated API call.
81
+ * This is the recommended helper for most authenticated API operations.
82
+ *
83
+ * @param oxyServices - The OxyServices instance
84
+ * @param activeSessionId - The active session ID
85
+ * @param apiCall - The API call function to execute
86
+ * @param syncSession - Optional callback to sync session on auth failure
87
+ * @returns The result of the API call
88
+ *
89
+ * @example
90
+ * ```ts
91
+ * return await authenticatedApiCall(
92
+ * oxyServices,
93
+ * activeSessionId,
94
+ * () => oxyServices.updateProfile(updates)
95
+ * );
96
+ * ```
97
+ */
98
+ export declare function authenticatedApiCall<T>(oxyServices: OxyServices, activeSessionId: string | null | undefined, apiCall: () => Promise<T>, syncSession?: () => Promise<unknown>): Promise<T>;
@@ -0,0 +1,33 @@
1
+ import type { OxyServices } from '@oxyhq/core';
2
+ import type { User } from '@oxyhq/core';
3
+ import { QueryClient } from '@tanstack/react-query';
4
+ /**
5
+ * Updates file visibility to public for avatar use.
6
+ * Handles errors gracefully, only logging non-404 errors.
7
+ *
8
+ * @param fileId - The file ID to update visibility for
9
+ * @param oxyServices - OxyServices instance
10
+ * @param contextName - Optional context name for logging
11
+ * @returns Promise that resolves when visibility is updated (or skipped)
12
+ */
13
+ export declare function updateAvatarVisibility(fileId: string | undefined, oxyServices: OxyServices, contextName?: string): Promise<void>;
14
+ /**
15
+ * Refreshes avatar in accountStore with cache-busted URL to force image reload.
16
+ *
17
+ * @param sessionId - The session ID for the account to update
18
+ * @param avatarFileId - The new avatar file ID
19
+ * @param oxyServices - OxyServices instance to generate download URL
20
+ */
21
+ export declare function refreshAvatarInStore(sessionId: string, avatarFileId: string, oxyServices: OxyServices): void;
22
+ /**
23
+ * Updates user profile with avatar and handles all side effects (query invalidation, accountStore update).
24
+ * This function can be used from within OxyContext provider without requiring useOxy hook.
25
+ *
26
+ * @param updates - Profile updates including avatar
27
+ * @param oxyServices - OxyServices instance
28
+ * @param activeSessionId - Active session ID
29
+ * @param queryClient - TanStack Query client
30
+ * @param syncSession - Optional function to sync session/refresh token when auth errors occur
31
+ * @returns Promise that resolves with updated user data
32
+ */
33
+ export declare function updateProfileWithAvatar(updates: Partial<User>, oxyServices: OxyServices, activeSessionId: string | null, queryClient: QueryClient, syncSession?: () => Promise<User>): Promise<User>;
@@ -0,0 +1,34 @@
1
+ import type { ApiError } from '@oxyhq/core';
2
+ export interface HandleAuthErrorOptions {
3
+ defaultMessage: string;
4
+ code: string;
5
+ status?: number;
6
+ onError?: (error: ApiError) => void;
7
+ setAuthError?: (message: string) => void;
8
+ logger?: (message: string, error?: unknown) => void;
9
+ }
10
+ /**
11
+ * Determine whether the error represents an invalid session condition.
12
+ * This centralizes 401 detection across different fetch clients.
13
+ */
14
+ export declare const isInvalidSessionError: (error: unknown) => boolean;
15
+ /**
16
+ * Determine whether the error represents a timeout or network error.
17
+ * These are expected when the device is offline or has poor connectivity.
18
+ */
19
+ export declare const isTimeoutOrNetworkError: (error: unknown) => boolean;
20
+ /**
21
+ * Extract a consistent error message from unknown error shapes.
22
+ *
23
+ * @param error - The unknown error payload
24
+ * @param fallbackMessage - Message to return when no concrete message is available
25
+ */
26
+ export declare const extractErrorMessage: (error: unknown, fallbackMessage?: string) => string;
27
+ /**
28
+ * Centralized error handler for auth-related operations.
29
+ *
30
+ * @param error - Unknown error object
31
+ * @param options - Error handling configuration
32
+ * @returns Resolved error message
33
+ */
34
+ export declare const handleAuthError: (error: unknown, { defaultMessage, code, status, onError, setAuthError, logger, }: HandleAuthErrorOptions) => string;
@@ -0,0 +1,63 @@
1
+ import type { ClientSession } from '@oxyhq/core';
2
+ interface DeviceSession {
3
+ sessionId: string;
4
+ deviceId?: string;
5
+ deviceName?: string;
6
+ expiresAt?: string;
7
+ lastActive?: string;
8
+ user?: {
9
+ id?: string;
10
+ _id?: {
11
+ toString(): string;
12
+ };
13
+ };
14
+ userId?: string;
15
+ isCurrent?: boolean;
16
+ }
17
+ /**
18
+ * Service type for session helpers.
19
+ * Uses 'any' to work around TypeScript mixin composition type inference issues.
20
+ * The OxyServices class has these methods but TypeScript can't see them due to the mixin pattern.
21
+ */
22
+ type OxyServicesAny = any;
23
+ export interface FetchSessionsWithFallbackOptions {
24
+ fallbackDeviceId?: string;
25
+ fallbackUserId?: string;
26
+ logger?: (message: string, error?: unknown) => void;
27
+ }
28
+ export interface ValidateSessionBatchOptions {
29
+ useHeaderValidation?: boolean;
30
+ maxConcurrency?: number;
31
+ }
32
+ export interface SessionValidationResult {
33
+ sessionId: string;
34
+ valid: boolean;
35
+ user?: unknown;
36
+ raw?: unknown;
37
+ error?: unknown;
38
+ }
39
+ /**
40
+ * Normalize backend session payloads into `ClientSession` objects.
41
+ *
42
+ * @param sessions - Raw session array returned from the API
43
+ * @param fallbackDeviceId - Device identifier to use when missing from payload
44
+ * @param fallbackUserId - User identifier to use when missing from payload
45
+ */
46
+ export declare const mapSessionsToClient: (sessions: DeviceSession[], fallbackDeviceId?: string, fallbackUserId?: string) => ClientSession[];
47
+ /**
48
+ * Fetch device sessions with fallback to the legacy session endpoint when needed.
49
+ *
50
+ * @param oxyServices - Oxy service instance
51
+ * @param sessionId - Session identifier to fetch
52
+ * @param options - Optional fallback options
53
+ */
54
+ export declare const fetchSessionsWithFallback: (oxyServices: OxyServicesAny, sessionId: string, { fallbackDeviceId, fallbackUserId, logger, }?: FetchSessionsWithFallbackOptions) => Promise<ClientSession[]>;
55
+ /**
56
+ * Validate multiple sessions concurrently with configurable concurrency.
57
+ *
58
+ * @param oxyServices - Oxy service instance
59
+ * @param sessionIds - Session identifiers to validate
60
+ * @param options - Validation options
61
+ */
62
+ export declare const validateSessionBatch: (oxyServices: OxyServicesAny, sessionIds: string[], { useHeaderValidation, maxConcurrency }?: ValidateSessionBatchOptions) => Promise<SessionValidationResult[]>;
63
+ export {};
@@ -0,0 +1,27 @@
1
+ export interface StorageInterface {
2
+ getItem: (key: string) => Promise<string | null>;
3
+ setItem: (key: string, value: string) => Promise<void>;
4
+ removeItem: (key: string) => Promise<void>;
5
+ clear: () => Promise<void>;
6
+ }
7
+ export interface SessionStorageKeys {
8
+ activeSessionId: string;
9
+ sessionIds: string;
10
+ language: string;
11
+ }
12
+ /**
13
+ * Detect whether the current runtime is React Native.
14
+ */
15
+ export declare const isReactNative: () => boolean;
16
+ /**
17
+ * Create a platform-appropriate storage implementation.
18
+ * Defaults to in-memory storage when no platform storage is available.
19
+ */
20
+ export declare const createPlatformStorage: () => Promise<StorageInterface>;
21
+ export declare const STORAGE_KEY_PREFIX = "oxy_session";
22
+ /**
23
+ * Produce strongly typed storage key names for the supplied prefix.
24
+ *
25
+ * @param prefix - Storage key prefix
26
+ */
27
+ export declare const getStorageKeys: (prefix?: string) => SessionStorageKeys;
package/package.json ADDED
@@ -0,0 +1,71 @@
1
+ {
2
+ "name": "@oxyhq/auth",
3
+ "version": "1.0.0",
4
+ "description": "OxyHQ Web Authentication SDK — headless auth with React hooks for Next.js, Vite, and web apps",
5
+ "main": "dist/cjs/index.js",
6
+ "module": "dist/esm/index.js",
7
+ "types": "dist/types/index.d.ts",
8
+ "sideEffects": false,
9
+ "publishConfig": {
10
+ "access": "public"
11
+ },
12
+ "exports": {
13
+ ".": {
14
+ "types": "./dist/types/index.d.ts",
15
+ "import": "./dist/esm/index.js",
16
+ "require": "./dist/cjs/index.js",
17
+ "default": "./dist/esm/index.js"
18
+ },
19
+ "./package.json": "./package.json"
20
+ },
21
+ "files": [
22
+ "dist",
23
+ "src"
24
+ ],
25
+ "keywords": [
26
+ "oxyhq",
27
+ "sdk",
28
+ "authentication",
29
+ "react",
30
+ "hooks",
31
+ "web",
32
+ "fedcm",
33
+ "sso"
34
+ ],
35
+ "repository": {
36
+ "type": "git",
37
+ "url": "https://github.com/oxyhq/sdk",
38
+ "directory": "packages/auth-sdk"
39
+ },
40
+ "author": "OxyHQ",
41
+ "license": "MIT",
42
+ "homepage": "https://oxy.so",
43
+ "engines": {
44
+ "node": ">=18.0.0"
45
+ },
46
+ "scripts": {
47
+ "build": "npm run build:cjs && npm run build:esm && npm run build:types",
48
+ "build:cjs": "tsc -p tsconfig.cjs.json",
49
+ "build:esm": "tsc -p tsconfig.esm.json",
50
+ "build:types": "tsc -p tsconfig.types.json",
51
+ "clean": "rm -rf dist",
52
+ "typescript": "tsc --noEmit",
53
+ "lint": "biome lint --error-on-warnings ./src"
54
+ },
55
+ "dependencies": {
56
+ "@tanstack/react-query": "^5.59.0",
57
+ "socket.io-client": "^4.8.1",
58
+ "sonner": "^2.0.4",
59
+ "zustand": "^5.0.6"
60
+ },
61
+ "peerDependencies": {
62
+ "@oxyhq/core": "*",
63
+ "react": ">=18.0.0"
64
+ },
65
+ "devDependencies": {
66
+ "@biomejs/biome": "^1.9.4",
67
+ "@types/react": "^19.2.0",
68
+ "@types/node": "^20.19.9",
69
+ "typescript": "^5.9.2"
70
+ }
71
+ }