@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.
- package/README.md +56 -0
- package/dist/cjs/WebOxyProvider.js +287 -0
- package/dist/cjs/hooks/mutations/index.js +23 -0
- package/dist/cjs/hooks/mutations/mutationFactory.js +126 -0
- package/dist/cjs/hooks/mutations/useAccountMutations.js +275 -0
- package/dist/cjs/hooks/mutations/useServicesMutations.js +149 -0
- package/dist/cjs/hooks/queries/index.js +35 -0
- package/dist/cjs/hooks/queries/queryKeys.js +82 -0
- package/dist/cjs/hooks/queries/useAccountQueries.js +141 -0
- package/dist/cjs/hooks/queries/useSecurityQueries.js +45 -0
- package/dist/cjs/hooks/queries/useServicesQueries.js +113 -0
- package/dist/cjs/hooks/queryClient.js +110 -0
- package/dist/cjs/hooks/useAssets.js +225 -0
- package/dist/cjs/hooks/useFileDownloadUrl.js +91 -0
- package/dist/cjs/hooks/useFileFiltering.js +81 -0
- package/dist/cjs/hooks/useFollow.js +159 -0
- package/dist/cjs/hooks/useFollow.types.js +4 -0
- package/dist/cjs/hooks/useQueryClient.js +16 -0
- package/dist/cjs/hooks/useSessionSocket.js +215 -0
- package/dist/cjs/hooks/useWebSSO.js +146 -0
- package/dist/cjs/index.js +115 -0
- package/dist/cjs/stores/accountStore.js +226 -0
- package/dist/cjs/stores/assetStore.js +192 -0
- package/dist/cjs/stores/authStore.js +47 -0
- package/dist/cjs/stores/followStore.js +154 -0
- package/dist/cjs/utils/authHelpers.js +154 -0
- package/dist/cjs/utils/avatarUtils.js +77 -0
- package/dist/cjs/utils/errorHandlers.js +128 -0
- package/dist/cjs/utils/sessionHelpers.js +90 -0
- package/dist/cjs/utils/storageHelpers.js +147 -0
- package/dist/esm/WebOxyProvider.js +282 -0
- package/dist/esm/hooks/mutations/index.js +10 -0
- package/dist/esm/hooks/mutations/mutationFactory.js +122 -0
- package/dist/esm/hooks/mutations/useAccountMutations.js +267 -0
- package/dist/esm/hooks/mutations/useServicesMutations.js +141 -0
- package/dist/esm/hooks/queries/index.js +14 -0
- package/dist/esm/hooks/queries/queryKeys.js +76 -0
- package/dist/esm/hooks/queries/useAccountQueries.js +131 -0
- package/dist/esm/hooks/queries/useSecurityQueries.js +40 -0
- package/dist/esm/hooks/queries/useServicesQueries.js +105 -0
- package/dist/esm/hooks/queryClient.js +104 -0
- package/dist/esm/hooks/useAssets.js +220 -0
- package/dist/esm/hooks/useFileDownloadUrl.js +86 -0
- package/dist/esm/hooks/useFileFiltering.js +78 -0
- package/dist/esm/hooks/useFollow.js +154 -0
- package/dist/esm/hooks/useFollow.types.js +3 -0
- package/dist/esm/hooks/useQueryClient.js +12 -0
- package/dist/esm/hooks/useSessionSocket.js +209 -0
- package/dist/esm/hooks/useWebSSO.js +143 -0
- package/dist/esm/index.js +48 -0
- package/dist/esm/stores/accountStore.js +219 -0
- package/dist/esm/stores/assetStore.js +180 -0
- package/dist/esm/stores/authStore.js +44 -0
- package/dist/esm/stores/followStore.js +151 -0
- package/dist/esm/utils/authHelpers.js +145 -0
- package/dist/esm/utils/avatarUtils.js +72 -0
- package/dist/esm/utils/errorHandlers.js +121 -0
- package/dist/esm/utils/sessionHelpers.js +84 -0
- package/dist/esm/utils/storageHelpers.js +108 -0
- package/dist/types/WebOxyProvider.d.ts +97 -0
- package/dist/types/hooks/mutations/index.d.ts +8 -0
- package/dist/types/hooks/mutations/mutationFactory.d.ts +75 -0
- package/dist/types/hooks/mutations/useAccountMutations.d.ts +68 -0
- package/dist/types/hooks/mutations/useServicesMutations.d.ts +22 -0
- package/dist/types/hooks/queries/index.d.ts +10 -0
- package/dist/types/hooks/queries/queryKeys.d.ts +64 -0
- package/dist/types/hooks/queries/useAccountQueries.d.ts +42 -0
- package/dist/types/hooks/queries/useSecurityQueries.d.ts +14 -0
- package/dist/types/hooks/queries/useServicesQueries.d.ts +31 -0
- package/dist/types/hooks/queryClient.d.ts +18 -0
- package/dist/types/hooks/useAssets.d.ts +34 -0
- package/dist/types/hooks/useFileDownloadUrl.d.ts +18 -0
- package/dist/types/hooks/useFileFiltering.d.ts +28 -0
- package/dist/types/hooks/useFollow.d.ts +61 -0
- package/dist/types/hooks/useFollow.types.d.ts +32 -0
- package/dist/types/hooks/useQueryClient.d.ts +6 -0
- package/dist/types/hooks/useSessionSocket.d.ts +13 -0
- package/dist/types/hooks/useWebSSO.d.ts +57 -0
- package/dist/types/index.d.ts +46 -0
- package/dist/types/stores/accountStore.d.ts +33 -0
- package/dist/types/stores/assetStore.d.ts +53 -0
- package/dist/types/stores/authStore.d.ts +16 -0
- package/dist/types/stores/followStore.d.ts +24 -0
- package/dist/types/utils/authHelpers.d.ts +98 -0
- package/dist/types/utils/avatarUtils.d.ts +33 -0
- package/dist/types/utils/errorHandlers.d.ts +34 -0
- package/dist/types/utils/sessionHelpers.d.ts +63 -0
- package/dist/types/utils/storageHelpers.d.ts +27 -0
- package/package.json +71 -0
- package/src/WebOxyProvider.tsx +372 -0
- package/src/global.d.ts +1 -0
- package/src/hooks/mutations/index.ts +25 -0
- package/src/hooks/mutations/mutationFactory.ts +215 -0
- package/src/hooks/mutations/useAccountMutations.ts +344 -0
- package/src/hooks/mutations/useServicesMutations.ts +164 -0
- package/src/hooks/queries/index.ts +36 -0
- package/src/hooks/queries/queryKeys.ts +88 -0
- package/src/hooks/queries/useAccountQueries.ts +152 -0
- package/src/hooks/queries/useSecurityQueries.ts +64 -0
- package/src/hooks/queries/useServicesQueries.ts +126 -0
- package/src/hooks/queryClient.ts +112 -0
- package/src/hooks/useAssets.ts +291 -0
- package/src/hooks/useFileDownloadUrl.ts +118 -0
- package/src/hooks/useFileFiltering.ts +115 -0
- package/src/hooks/useFollow.ts +175 -0
- package/src/hooks/useFollow.types.ts +33 -0
- package/src/hooks/useQueryClient.ts +17 -0
- package/src/hooks/useSessionSocket.ts +233 -0
- package/src/hooks/useWebSSO.ts +187 -0
- package/src/index.ts +144 -0
- package/src/stores/accountStore.ts +296 -0
- package/src/stores/assetStore.ts +281 -0
- package/src/stores/authStore.ts +63 -0
- package/src/stores/followStore.ts +181 -0
- package/src/utils/authHelpers.ts +183 -0
- package/src/utils/avatarUtils.ts +103 -0
- package/src/utils/errorHandlers.ts +194 -0
- package/src/utils/sessionHelpers.ts +151 -0
- package/src/utils/storageHelpers.ts +130 -0
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mutation Factory - Creates standardized mutations with optimistic updates
|
|
3
|
+
*
|
|
4
|
+
* This factory reduces boilerplate code for mutations that follow the common pattern:
|
|
5
|
+
* 1. Cancel outgoing queries
|
|
6
|
+
* 2. Snapshot previous data
|
|
7
|
+
* 3. Apply optimistic update
|
|
8
|
+
* 4. On error: rollback and show toast
|
|
9
|
+
* 5. On success: update cache, stores, and invalidate queries
|
|
10
|
+
*/
|
|
11
|
+
import { QueryClient, UseMutationOptions } from '@tanstack/react-query';
|
|
12
|
+
import type { User } from '@oxyhq/core';
|
|
13
|
+
/**
|
|
14
|
+
* Configuration for creating a standard profile mutation
|
|
15
|
+
*/
|
|
16
|
+
export interface ProfileMutationConfig<TData, TVariables> {
|
|
17
|
+
/** The mutation function that makes the API call */
|
|
18
|
+
mutationFn: (variables: TVariables) => Promise<TData>;
|
|
19
|
+
/** Query keys to cancel before mutation */
|
|
20
|
+
cancelQueryKeys?: unknown[][];
|
|
21
|
+
/** Function to apply optimistic update to the user data */
|
|
22
|
+
optimisticUpdate?: (previousUser: User, variables: TVariables) => Partial<User>;
|
|
23
|
+
/** Error message to show on failure */
|
|
24
|
+
errorMessage?: string | ((error: Error) => string);
|
|
25
|
+
/** Success message to show (optional) */
|
|
26
|
+
successMessage?: string;
|
|
27
|
+
/** Whether to update authStore on success (default: true) */
|
|
28
|
+
updateAuthStore?: boolean;
|
|
29
|
+
/** Whether to invalidate user queries on success (default: true) */
|
|
30
|
+
invalidateUserQueries?: boolean;
|
|
31
|
+
/** Whether to invalidate account queries on success (default: true) */
|
|
32
|
+
invalidateAccountQueries?: boolean;
|
|
33
|
+
/** Custom onSuccess handler */
|
|
34
|
+
onSuccess?: (data: TData, variables: TVariables, queryClient: QueryClient) => void;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Creates a standard profile mutation with optimistic updates
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```ts
|
|
41
|
+
* const updateProfile = createProfileMutation({
|
|
42
|
+
* mutationFn: (updates) => oxyServices.updateProfile(updates),
|
|
43
|
+
* optimisticUpdate: (user, updates) => updates,
|
|
44
|
+
* errorMessage: 'Failed to update profile',
|
|
45
|
+
* });
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
export declare function createProfileMutation<TVariables>(config: ProfileMutationConfig<User, TVariables>, queryClient: QueryClient, activeSessionId: string | null): UseMutationOptions<User, Error, TVariables, {
|
|
49
|
+
previousUser?: User;
|
|
50
|
+
}>;
|
|
51
|
+
/**
|
|
52
|
+
* Configuration for creating a generic mutation (non-profile)
|
|
53
|
+
*/
|
|
54
|
+
export interface GenericMutationConfig<TData, TVariables, TContext> {
|
|
55
|
+
/** The mutation function */
|
|
56
|
+
mutationFn: (variables: TVariables) => Promise<TData>;
|
|
57
|
+
/** Query key for optimistic data */
|
|
58
|
+
queryKey: unknown[];
|
|
59
|
+
/** Function to create optimistic data */
|
|
60
|
+
optimisticData?: (previous: TData | undefined, variables: TVariables) => TData;
|
|
61
|
+
/** Error message */
|
|
62
|
+
errorMessage?: string;
|
|
63
|
+
/** Success message */
|
|
64
|
+
successMessage?: string;
|
|
65
|
+
/** Additional queries to invalidate on success */
|
|
66
|
+
invalidateQueries?: unknown[][];
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Creates a generic mutation with optimistic updates
|
|
70
|
+
*/
|
|
71
|
+
export declare function createGenericMutation<TData, TVariables>(config: GenericMutationConfig<TData, TVariables, {
|
|
72
|
+
previous?: TData;
|
|
73
|
+
}>, queryClient: QueryClient): UseMutationOptions<TData, Error, TVariables, {
|
|
74
|
+
previous?: TData;
|
|
75
|
+
}>;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { User } from '@oxyhq/core';
|
|
2
|
+
/**
|
|
3
|
+
* Update user profile with optimistic updates and offline queue support
|
|
4
|
+
*/
|
|
5
|
+
export declare const useUpdateProfile: () => import("@tanstack/react-query").UseMutationResult<User, Error, Partial<User>, {
|
|
6
|
+
previousUser: User | undefined;
|
|
7
|
+
}>;
|
|
8
|
+
/**
|
|
9
|
+
* Upload avatar with progress tracking and offline queue support
|
|
10
|
+
*/
|
|
11
|
+
export declare const useUploadAvatar: () => import("@tanstack/react-query").UseMutationResult<User, Error, {
|
|
12
|
+
uri: string;
|
|
13
|
+
type?: string;
|
|
14
|
+
name?: string;
|
|
15
|
+
size?: number;
|
|
16
|
+
}, {
|
|
17
|
+
previousUser: User | undefined;
|
|
18
|
+
}>;
|
|
19
|
+
/**
|
|
20
|
+
* Update account settings
|
|
21
|
+
*/
|
|
22
|
+
export declare const useUpdateAccountSettings: () => import("@tanstack/react-query").UseMutationResult<any, Error, Record<string, any>, {
|
|
23
|
+
previousUser: User | undefined;
|
|
24
|
+
}>;
|
|
25
|
+
/**
|
|
26
|
+
* Update privacy settings with optimistic updates and authentication handling
|
|
27
|
+
*/
|
|
28
|
+
export declare const useUpdatePrivacySettings: () => import("@tanstack/react-query").UseMutationResult<Record<string, unknown>, Error, {
|
|
29
|
+
settings: Record<string, any>;
|
|
30
|
+
userId?: string;
|
|
31
|
+
}, {
|
|
32
|
+
previousPrivacySettings: unknown;
|
|
33
|
+
previousUser: User | undefined;
|
|
34
|
+
} | undefined>;
|
|
35
|
+
/** Uploaded file data structure from API */
|
|
36
|
+
interface UploadedFile {
|
|
37
|
+
id: string;
|
|
38
|
+
originalName?: string;
|
|
39
|
+
sha256?: string;
|
|
40
|
+
mime?: string;
|
|
41
|
+
size?: number;
|
|
42
|
+
createdAt?: string;
|
|
43
|
+
metadata?: Record<string, unknown>;
|
|
44
|
+
variants?: Array<{
|
|
45
|
+
type: string;
|
|
46
|
+
key: string;
|
|
47
|
+
width?: number;
|
|
48
|
+
height?: number;
|
|
49
|
+
readyAt?: string;
|
|
50
|
+
metadata?: Record<string, unknown>;
|
|
51
|
+
}>;
|
|
52
|
+
}
|
|
53
|
+
/** Upload result type that supports both single file and batch responses */
|
|
54
|
+
interface UploadResult {
|
|
55
|
+
file?: UploadedFile;
|
|
56
|
+
files?: UploadedFile[];
|
|
57
|
+
id?: string;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Upload file with authentication handling and progress tracking
|
|
61
|
+
*/
|
|
62
|
+
export declare const useUploadFile: () => import("@tanstack/react-query").UseMutationResult<UploadResult, Error, {
|
|
63
|
+
file: File;
|
|
64
|
+
visibility?: "private" | "public" | "unlisted";
|
|
65
|
+
metadata?: Record<string, any>;
|
|
66
|
+
onProgress?: (progress: number) => void;
|
|
67
|
+
}, unknown>;
|
|
68
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Switch active session
|
|
3
|
+
*/
|
|
4
|
+
export declare const useSwitchSession: () => import("@tanstack/react-query").UseMutationResult<void, Error, string, unknown>;
|
|
5
|
+
/**
|
|
6
|
+
* Logout from a session
|
|
7
|
+
*/
|
|
8
|
+
export declare const useLogoutSession: () => import("@tanstack/react-query").UseMutationResult<string, Error, string | undefined, {
|
|
9
|
+
previousSessions: unknown;
|
|
10
|
+
}>;
|
|
11
|
+
/**
|
|
12
|
+
* Logout from all sessions
|
|
13
|
+
*/
|
|
14
|
+
export declare const useLogoutAll: () => import("@tanstack/react-query").UseMutationResult<void, Error, void, unknown>;
|
|
15
|
+
/**
|
|
16
|
+
* Update device name
|
|
17
|
+
*/
|
|
18
|
+
export declare const useUpdateDeviceName: () => import("@tanstack/react-query").UseMutationResult<any, Error, string, unknown>;
|
|
19
|
+
/**
|
|
20
|
+
* Remove a device
|
|
21
|
+
*/
|
|
22
|
+
export declare const useRemoveDevice: () => import("@tanstack/react-query").UseMutationResult<string, Error, string, unknown>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Query Hooks
|
|
3
|
+
*
|
|
4
|
+
* TanStack Query hooks for fetching Oxy services data.
|
|
5
|
+
* All hooks follow the same pattern with optional `enabled` parameter.
|
|
6
|
+
*/
|
|
7
|
+
export { useUserProfile, useUserProfiles, useCurrentUser, useUserById, useUserByUsername, useUsersBySessions, usePrivacySettings, } from './useAccountQueries';
|
|
8
|
+
export { useSessions, useSession, useDeviceSessions, useUserDevices, useSecurityInfo, } from './useServicesQueries';
|
|
9
|
+
export { useSecurityActivity, useRecentSecurityActivity, } from './useSecurityQueries';
|
|
10
|
+
export { queryKeys, invalidateAccountQueries, invalidateUserQueries, invalidateSessionQueries } from './queryKeys';
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Centralized query keys for TanStack Query
|
|
3
|
+
*
|
|
4
|
+
* Following best practices:
|
|
5
|
+
* - Use arrays for hierarchical keys
|
|
6
|
+
* - Include all parameters in the key
|
|
7
|
+
* - Use consistent naming conventions
|
|
8
|
+
*/
|
|
9
|
+
export declare const queryKeys: {
|
|
10
|
+
readonly accounts: {
|
|
11
|
+
readonly all: readonly ["accounts"];
|
|
12
|
+
readonly lists: () => readonly ["accounts", "list"];
|
|
13
|
+
readonly list: (sessionIds: string[]) => readonly ["accounts", "list", string[]];
|
|
14
|
+
readonly details: () => readonly ["accounts", "detail"];
|
|
15
|
+
readonly detail: (sessionId: string) => readonly ["accounts", "detail", string];
|
|
16
|
+
readonly current: () => readonly ["accounts", "current"];
|
|
17
|
+
readonly settings: () => readonly ["accounts", "settings"];
|
|
18
|
+
};
|
|
19
|
+
readonly users: {
|
|
20
|
+
readonly all: readonly ["users"];
|
|
21
|
+
readonly lists: () => readonly ["users", "list"];
|
|
22
|
+
readonly list: (userIds: string[]) => readonly ["users", "list", string[]];
|
|
23
|
+
readonly details: () => readonly ["users", "detail"];
|
|
24
|
+
readonly detail: (userId: string) => readonly ["users", "detail", string];
|
|
25
|
+
readonly profile: (sessionId: string) => readonly ["users", "detail", string, "profile"];
|
|
26
|
+
};
|
|
27
|
+
readonly sessions: {
|
|
28
|
+
readonly all: readonly ["sessions"];
|
|
29
|
+
readonly lists: () => readonly ["sessions", "list"];
|
|
30
|
+
readonly list: (userId?: string) => readonly ["sessions", "list", string | undefined];
|
|
31
|
+
readonly details: () => readonly ["sessions", "detail"];
|
|
32
|
+
readonly detail: (sessionId: string) => readonly ["sessions", "detail", string];
|
|
33
|
+
readonly active: () => readonly ["sessions", "active"];
|
|
34
|
+
readonly device: (deviceId: string) => readonly ["sessions", "device", string];
|
|
35
|
+
};
|
|
36
|
+
readonly devices: {
|
|
37
|
+
readonly all: readonly ["devices"];
|
|
38
|
+
readonly lists: () => readonly ["devices", "list"];
|
|
39
|
+
readonly list: (userId?: string) => readonly ["devices", "list", string | undefined];
|
|
40
|
+
readonly details: () => readonly ["devices", "detail"];
|
|
41
|
+
readonly detail: (deviceId: string) => readonly ["devices", "detail", string];
|
|
42
|
+
};
|
|
43
|
+
readonly privacy: {
|
|
44
|
+
readonly all: readonly ["privacy"];
|
|
45
|
+
readonly settings: (userId?: string) => readonly ["privacy", "settings", string];
|
|
46
|
+
};
|
|
47
|
+
readonly security: {
|
|
48
|
+
readonly all: readonly ["security"];
|
|
49
|
+
readonly activity: (limit?: number, offset?: number, eventType?: string) => readonly ["security", "activity", number | undefined, number | undefined, string | undefined];
|
|
50
|
+
readonly recent: (limit: number) => readonly ["security", "recent", number];
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Helper to invalidate all account-related queries
|
|
55
|
+
*/
|
|
56
|
+
export declare const invalidateAccountQueries: (queryClient: any) => void;
|
|
57
|
+
/**
|
|
58
|
+
* Helper to invalidate all user-related queries
|
|
59
|
+
*/
|
|
60
|
+
export declare const invalidateUserQueries: (queryClient: any) => void;
|
|
61
|
+
/**
|
|
62
|
+
* Helper to invalidate all session-related queries
|
|
63
|
+
*/
|
|
64
|
+
export declare const invalidateSessionQueries: (queryClient: any) => void;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get user profile by session ID
|
|
3
|
+
*/
|
|
4
|
+
export declare const useUserProfile: (sessionId: string | null, options?: {
|
|
5
|
+
enabled?: boolean;
|
|
6
|
+
}) => import("@tanstack/react-query").UseQueryResult<any, Error>;
|
|
7
|
+
/**
|
|
8
|
+
* Get multiple user profiles by session IDs (batch query)
|
|
9
|
+
*/
|
|
10
|
+
export declare const useUserProfiles: (sessionIds: string[], options?: {
|
|
11
|
+
enabled?: boolean;
|
|
12
|
+
}) => import("@tanstack/react-query").UseQueryResult<any, Error>[];
|
|
13
|
+
/**
|
|
14
|
+
* Get current authenticated user
|
|
15
|
+
*/
|
|
16
|
+
export declare const useCurrentUser: (options?: {
|
|
17
|
+
enabled?: boolean;
|
|
18
|
+
}) => import("@tanstack/react-query").UseQueryResult<any, Error>;
|
|
19
|
+
/**
|
|
20
|
+
* Get user by ID
|
|
21
|
+
*/
|
|
22
|
+
export declare const useUserById: (userId: string | null, options?: {
|
|
23
|
+
enabled?: boolean;
|
|
24
|
+
}) => import("@tanstack/react-query").UseQueryResult<any, Error>;
|
|
25
|
+
/**
|
|
26
|
+
* Get user profile by username
|
|
27
|
+
*/
|
|
28
|
+
export declare const useUserByUsername: (username: string | null, options?: {
|
|
29
|
+
enabled?: boolean;
|
|
30
|
+
}) => import("@tanstack/react-query").UseQueryResult<any, Error>;
|
|
31
|
+
/**
|
|
32
|
+
* Batch get users by session IDs (optimized single API call)
|
|
33
|
+
*/
|
|
34
|
+
export declare const useUsersBySessions: (sessionIds: string[], options?: {
|
|
35
|
+
enabled?: boolean;
|
|
36
|
+
}) => import("@tanstack/react-query").UseQueryResult<any, Error>;
|
|
37
|
+
/**
|
|
38
|
+
* Get privacy settings for a user
|
|
39
|
+
*/
|
|
40
|
+
export declare const usePrivacySettings: (userId?: string, options?: {
|
|
41
|
+
enabled?: boolean;
|
|
42
|
+
}) => import("@tanstack/react-query").UseQueryResult<unknown, Error>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { SecurityActivity, SecurityEventType } from '@oxyhq/core';
|
|
2
|
+
/**
|
|
3
|
+
* Get user's security activity with pagination
|
|
4
|
+
*/
|
|
5
|
+
export declare const useSecurityActivity: (options?: {
|
|
6
|
+
limit?: number;
|
|
7
|
+
offset?: number;
|
|
8
|
+
eventType?: SecurityEventType;
|
|
9
|
+
enabled?: boolean;
|
|
10
|
+
}) => import("@tanstack/react-query").UseQueryResult<any, Error>;
|
|
11
|
+
/**
|
|
12
|
+
* Get recent security activity (convenience hook)
|
|
13
|
+
*/
|
|
14
|
+
export declare const useRecentSecurityActivity: (limit?: number) => import("@tanstack/react-query").UseQueryResult<SecurityActivity[], Error>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { ClientSession } from '@oxyhq/core';
|
|
2
|
+
/**
|
|
3
|
+
* Get all active sessions for the current user
|
|
4
|
+
*/
|
|
5
|
+
export declare const useSessions: (userId?: string, options?: {
|
|
6
|
+
enabled?: boolean;
|
|
7
|
+
}) => import("@tanstack/react-query").UseQueryResult<ClientSession[], Error>;
|
|
8
|
+
/**
|
|
9
|
+
* Get specific session by ID
|
|
10
|
+
*/
|
|
11
|
+
export declare const useSession: (sessionId: string | null, options?: {
|
|
12
|
+
enabled?: boolean;
|
|
13
|
+
}) => import("@tanstack/react-query").UseQueryResult<ClientSession, Error>;
|
|
14
|
+
/**
|
|
15
|
+
* Get device sessions for the current active session
|
|
16
|
+
*/
|
|
17
|
+
export declare const useDeviceSessions: (options?: {
|
|
18
|
+
enabled?: boolean;
|
|
19
|
+
}) => import("@tanstack/react-query").UseQueryResult<any, Error>;
|
|
20
|
+
/**
|
|
21
|
+
* Get user devices
|
|
22
|
+
*/
|
|
23
|
+
export declare const useUserDevices: (options?: {
|
|
24
|
+
enabled?: boolean;
|
|
25
|
+
}) => import("@tanstack/react-query").UseQueryResult<unknown, Error>;
|
|
26
|
+
/**
|
|
27
|
+
* Get security information
|
|
28
|
+
*/
|
|
29
|
+
export declare const useSecurityInfo: (options?: {
|
|
30
|
+
enabled?: boolean;
|
|
31
|
+
}) => import("@tanstack/react-query").UseQueryResult<any, Error>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { QueryClient } from '@tanstack/react-query';
|
|
2
|
+
import type { StorageInterface } from '../utils/storageHelpers';
|
|
3
|
+
/**
|
|
4
|
+
* Custom persistence adapter for TanStack Query using our StorageInterface
|
|
5
|
+
*/
|
|
6
|
+
export declare const createPersistenceAdapter: (storage: StorageInterface) => {
|
|
7
|
+
persistClient: (client: any) => Promise<void>;
|
|
8
|
+
restoreClient: () => Promise<any>;
|
|
9
|
+
removeClient: () => Promise<void>;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Create a QueryClient with offline-first configuration
|
|
13
|
+
*/
|
|
14
|
+
export declare const createQueryClient: (storage?: StorageInterface | null) => QueryClient;
|
|
15
|
+
/**
|
|
16
|
+
* Clear persisted query cache
|
|
17
|
+
*/
|
|
18
|
+
export declare const clearQueryCache: (storage: StorageInterface) => Promise<void>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { OxyServices } from '@oxyhq/core';
|
|
2
|
+
import { Asset, AssetUploadProgress } from '@oxyhq/core';
|
|
3
|
+
export declare const setOxyAssetInstance: (instance: OxyServices) => void;
|
|
4
|
+
/**
|
|
5
|
+
* Hook for managing assets with Zustand store integration
|
|
6
|
+
*/
|
|
7
|
+
export declare const useAssets: () => {
|
|
8
|
+
assets: Asset[];
|
|
9
|
+
uploadProgress: Record<string, AssetUploadProgress>;
|
|
10
|
+
loading: {
|
|
11
|
+
uploading: boolean;
|
|
12
|
+
linking: boolean;
|
|
13
|
+
deleting: boolean;
|
|
14
|
+
};
|
|
15
|
+
errors: {
|
|
16
|
+
upload?: string;
|
|
17
|
+
link?: string;
|
|
18
|
+
delete?: string;
|
|
19
|
+
};
|
|
20
|
+
upload: (file: File, metadata?: Record<string, any>) => Promise<Asset | null>;
|
|
21
|
+
link: (assetId: string, app: string, entityType: string, entityId: string) => Promise<void>;
|
|
22
|
+
unlink: (assetId: string, app: string, entityType: string, entityId: string) => Promise<void>;
|
|
23
|
+
getUrl: (assetId: string, variant?: string, expiresIn?: number) => Promise<string>;
|
|
24
|
+
getAsset: (assetId: string) => Promise<Asset>;
|
|
25
|
+
deleteAsset: (assetId: string, force?: boolean) => Promise<void>;
|
|
26
|
+
restore: (assetId: string) => Promise<void>;
|
|
27
|
+
getVariants: (assetId: string) => Promise<any>;
|
|
28
|
+
getAssetsByApp: (app: string) => Asset[];
|
|
29
|
+
getAssetsByEntity: (app: string, entityType: string, entityId: string) => Asset[];
|
|
30
|
+
getAssetUsageCount: (assetId: string) => number;
|
|
31
|
+
isAssetLinked: (assetId: string, app: string, entityType: string, entityId: string) => boolean;
|
|
32
|
+
clearErrors: () => void;
|
|
33
|
+
reset: () => void;
|
|
34
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { OxyServices } from '@oxyhq/core';
|
|
2
|
+
export declare const setOxyFileUrlInstance: (instance: OxyServices) => void;
|
|
3
|
+
export interface UseFileDownloadUrlOptions {
|
|
4
|
+
variant?: string;
|
|
5
|
+
expiresIn?: number;
|
|
6
|
+
}
|
|
7
|
+
export interface UseFileDownloadUrlResult {
|
|
8
|
+
url: string | null;
|
|
9
|
+
loading: boolean;
|
|
10
|
+
error: Error | null;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Hook to resolve a file's download URL asynchronously.
|
|
14
|
+
*
|
|
15
|
+
* Prefers `getFileDownloadUrlAsync` and falls back to the synchronous
|
|
16
|
+
* `getFileDownloadUrl` helper if the async call fails.
|
|
17
|
+
*/
|
|
18
|
+
export declare const useFileDownloadUrl: (fileId?: string | null, options?: UseFileDownloadUrlOptions) => UseFileDownloadUrlResult;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { FileMetadata } from '@oxyhq/core';
|
|
2
|
+
export type ViewMode = 'all' | 'photos' | 'videos' | 'documents' | 'audio';
|
|
3
|
+
export type SortBy = 'date' | 'size' | 'name' | 'type';
|
|
4
|
+
export type SortOrder = 'asc' | 'desc';
|
|
5
|
+
interface UseFileFilteringOptions {
|
|
6
|
+
files: FileMetadata[];
|
|
7
|
+
initialViewMode?: ViewMode;
|
|
8
|
+
initialSortBy?: SortBy;
|
|
9
|
+
initialSortOrder?: SortOrder;
|
|
10
|
+
}
|
|
11
|
+
interface UseFileFilteringReturn {
|
|
12
|
+
filteredFiles: FileMetadata[];
|
|
13
|
+
viewMode: ViewMode;
|
|
14
|
+
setViewMode: (mode: ViewMode) => void;
|
|
15
|
+
searchQuery: string;
|
|
16
|
+
setSearchQuery: (query: string) => void;
|
|
17
|
+
sortBy: SortBy;
|
|
18
|
+
setSortBy: (sort: SortBy) => void;
|
|
19
|
+
sortOrder: SortOrder;
|
|
20
|
+
setSortOrder: (order: SortOrder) => void;
|
|
21
|
+
toggleSortOrder: () => void;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Hook for file filtering, sorting, and search functionality
|
|
25
|
+
* Extracts common file management logic for reuse across components
|
|
26
|
+
*/
|
|
27
|
+
export declare function useFileFiltering({ files, initialViewMode, initialSortBy, initialSortOrder, }: UseFileFilteringOptions): UseFileFilteringReturn;
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
export declare const useFollow: (userId?: string | string[]) => {
|
|
2
|
+
isFollowing: boolean;
|
|
3
|
+
isLoading: boolean;
|
|
4
|
+
error: string | null;
|
|
5
|
+
toggleFollow: () => Promise<void>;
|
|
6
|
+
setFollowStatus: (following: boolean) => void;
|
|
7
|
+
fetchStatus: () => Promise<void>;
|
|
8
|
+
clearError: () => void;
|
|
9
|
+
followerCount: number | null;
|
|
10
|
+
followingCount: number | null;
|
|
11
|
+
isLoadingCounts: boolean;
|
|
12
|
+
fetchUserCounts: () => Promise<void>;
|
|
13
|
+
setFollowerCount: (count: number) => void;
|
|
14
|
+
setFollowingCount: (count: number) => void;
|
|
15
|
+
followData?: undefined;
|
|
16
|
+
toggleFollowForUser?: undefined;
|
|
17
|
+
setFollowStatusForUser?: undefined;
|
|
18
|
+
fetchStatusForUser?: undefined;
|
|
19
|
+
fetchAllStatuses?: undefined;
|
|
20
|
+
clearErrorForUser?: undefined;
|
|
21
|
+
isAnyLoading?: undefined;
|
|
22
|
+
hasAnyError?: undefined;
|
|
23
|
+
allFollowing?: undefined;
|
|
24
|
+
allNotFollowing?: undefined;
|
|
25
|
+
} | {
|
|
26
|
+
followData: Record<string, {
|
|
27
|
+
isFollowing: boolean;
|
|
28
|
+
isLoading: boolean;
|
|
29
|
+
error: string | null;
|
|
30
|
+
}>;
|
|
31
|
+
toggleFollowForUser: (targetUserId: string) => Promise<void>;
|
|
32
|
+
setFollowStatusForUser: (targetUserId: string, following: boolean) => void;
|
|
33
|
+
fetchStatusForUser: (targetUserId: string) => Promise<void>;
|
|
34
|
+
fetchAllStatuses: () => Promise<void>;
|
|
35
|
+
clearErrorForUser: (targetUserId: string) => void;
|
|
36
|
+
isAnyLoading: boolean;
|
|
37
|
+
hasAnyError: boolean;
|
|
38
|
+
allFollowing: boolean;
|
|
39
|
+
allNotFollowing: boolean;
|
|
40
|
+
isFollowing?: undefined;
|
|
41
|
+
isLoading?: undefined;
|
|
42
|
+
error?: undefined;
|
|
43
|
+
toggleFollow?: undefined;
|
|
44
|
+
setFollowStatus?: undefined;
|
|
45
|
+
fetchStatus?: undefined;
|
|
46
|
+
clearError?: undefined;
|
|
47
|
+
followerCount?: undefined;
|
|
48
|
+
followingCount?: undefined;
|
|
49
|
+
isLoadingCounts?: undefined;
|
|
50
|
+
fetchUserCounts?: undefined;
|
|
51
|
+
setFollowerCount?: undefined;
|
|
52
|
+
setFollowingCount?: undefined;
|
|
53
|
+
};
|
|
54
|
+
export declare const useFollowerCounts: (userId: string) => {
|
|
55
|
+
followerCount: number;
|
|
56
|
+
followingCount: number;
|
|
57
|
+
isLoadingCounts: boolean;
|
|
58
|
+
fetchUserCounts: () => Promise<void>;
|
|
59
|
+
setFollowerCount: (count: number) => void;
|
|
60
|
+
setFollowingCount: (count: number) => void;
|
|
61
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export type SingleFollowResult = {
|
|
2
|
+
isFollowing: boolean;
|
|
3
|
+
isLoading: boolean;
|
|
4
|
+
error: string | null;
|
|
5
|
+
toggleFollow: () => Promise<void>;
|
|
6
|
+
setFollowStatus: (following: boolean) => void;
|
|
7
|
+
fetchStatus: () => Promise<void>;
|
|
8
|
+
clearError: () => void;
|
|
9
|
+
followerCount: number | null;
|
|
10
|
+
followingCount: number | null;
|
|
11
|
+
isLoadingCounts: boolean;
|
|
12
|
+
fetchUserCounts: () => Promise<void>;
|
|
13
|
+
setFollowerCount: (count: number) => void;
|
|
14
|
+
setFollowingCount: (count: number) => void;
|
|
15
|
+
};
|
|
16
|
+
export type MultiFollowResult = {
|
|
17
|
+
followData: Record<string, {
|
|
18
|
+
isFollowing: boolean;
|
|
19
|
+
isLoading: boolean;
|
|
20
|
+
error: string | null;
|
|
21
|
+
}>;
|
|
22
|
+
toggleFollowForUser: (userId: string) => Promise<void>;
|
|
23
|
+
setFollowStatusForUser: (userId: string, following: boolean) => void;
|
|
24
|
+
fetchStatusForUser: (userId: string) => Promise<void>;
|
|
25
|
+
fetchAllStatuses: () => Promise<void>;
|
|
26
|
+
clearErrorForUser: (userId: string) => void;
|
|
27
|
+
isAnyLoading: boolean;
|
|
28
|
+
hasAnyError: boolean;
|
|
29
|
+
allFollowing: boolean;
|
|
30
|
+
allNotFollowing: boolean;
|
|
31
|
+
};
|
|
32
|
+
export type UseFollowHook = (userId?: string | string[]) => SingleFollowResult | MultiFollowResult;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
interface UseSessionSocketProps {
|
|
2
|
+
userId: string | null | undefined;
|
|
3
|
+
activeSessionId: string | null | undefined;
|
|
4
|
+
currentDeviceId: string | null | undefined;
|
|
5
|
+
refreshSessions: () => Promise<void>;
|
|
6
|
+
logout: () => Promise<void>;
|
|
7
|
+
clearSessionState: () => Promise<void>;
|
|
8
|
+
baseURL: string;
|
|
9
|
+
onRemoteSignOut?: () => void;
|
|
10
|
+
onSessionRemoved?: (sessionId: string) => void;
|
|
11
|
+
}
|
|
12
|
+
export declare function useSessionSocket({ userId, activeSessionId, currentDeviceId, refreshSessions, logout, clearSessionState, baseURL, onRemoteSignOut, onSessionRemoved }: UseSessionSocketProps): void;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Web SSO Hook
|
|
3
|
+
*
|
|
4
|
+
* Handles cross-domain SSO for web apps using FedCM (Federated Credential Management).
|
|
5
|
+
*
|
|
6
|
+
* FedCM is the modern, privacy-preserving standard for cross-domain identity federation.
|
|
7
|
+
* It works across completely different TLDs (alia.onl, mention.earth, homiio.com, etc.)
|
|
8
|
+
* without relying on third-party cookies.
|
|
9
|
+
*
|
|
10
|
+
* For browsers without FedCM support, users will need to click a sign-in button
|
|
11
|
+
* which triggers a popup-based authentication flow.
|
|
12
|
+
*
|
|
13
|
+
* This is called automatically by OxyContext on web platforms.
|
|
14
|
+
*
|
|
15
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/FedCM_API
|
|
16
|
+
*/
|
|
17
|
+
import type { OxyServices } from '@oxyhq/core';
|
|
18
|
+
import type { SessionLoginResponse } from '@oxyhq/core';
|
|
19
|
+
interface UseWebSSOOptions {
|
|
20
|
+
oxyServices: OxyServices;
|
|
21
|
+
onSessionFound: (session: SessionLoginResponse) => Promise<void>;
|
|
22
|
+
onSSOUnavailable?: () => void;
|
|
23
|
+
onError?: (error: Error) => void;
|
|
24
|
+
enabled?: boolean;
|
|
25
|
+
}
|
|
26
|
+
interface UseWebSSOResult {
|
|
27
|
+
/** Manually trigger SSO check */
|
|
28
|
+
checkSSO: () => Promise<SessionLoginResponse | null>;
|
|
29
|
+
/** Trigger interactive FedCM sign-in (shows browser UI) */
|
|
30
|
+
signInWithFedCM: () => Promise<SessionLoginResponse | null>;
|
|
31
|
+
/** Whether SSO check is in progress */
|
|
32
|
+
isChecking: boolean;
|
|
33
|
+
/** Whether FedCM is supported in this browser */
|
|
34
|
+
isFedCMSupported: boolean;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Check if we're running in a web browser environment (not React Native)
|
|
38
|
+
*/
|
|
39
|
+
declare function isWebBrowser(): boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Hook for automatic cross-domain web SSO
|
|
42
|
+
*
|
|
43
|
+
* Uses FedCM (Federated Credential Management) - the modern browser-native
|
|
44
|
+
* identity federation API. This is the same technology that powers
|
|
45
|
+
* Google's cross-domain SSO (YouTube, Gmail, Maps, etc.).
|
|
46
|
+
*
|
|
47
|
+
* Key benefits:
|
|
48
|
+
* - Works across different TLDs (alia.onl ↔ mention.earth ↔ homiio.com)
|
|
49
|
+
* - No third-party cookies required
|
|
50
|
+
* - Privacy-preserving (browser mediates identity, IdP can't track)
|
|
51
|
+
* - Automatic silent sign-in after initial authentication
|
|
52
|
+
*
|
|
53
|
+
* For browsers without FedCM (Firefox, older browsers), automatic SSO
|
|
54
|
+
* is not possible. Users will see a sign-in button instead.
|
|
55
|
+
*/
|
|
56
|
+
export declare function useWebSSO({ oxyServices, onSessionFound, onSSOUnavailable, onError, enabled, }: UseWebSSOOptions): UseWebSSOResult;
|
|
57
|
+
export { isWebBrowser };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @oxyhq/auth — OxyHQ Web Authentication SDK
|
|
3
|
+
*
|
|
4
|
+
* Headless authentication for React web apps (Next.js, Vite, CRA).
|
|
5
|
+
* Zero React Native / Expo dependencies.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```tsx
|
|
9
|
+
* import { WebOxyProvider, useAuth } from '@oxyhq/auth';
|
|
10
|
+
*
|
|
11
|
+
* function App() {
|
|
12
|
+
* return (
|
|
13
|
+
* <WebOxyProvider baseURL="https://api.oxy.so">
|
|
14
|
+
* <YourApp />
|
|
15
|
+
* </WebOxyProvider>
|
|
16
|
+
* );
|
|
17
|
+
* }
|
|
18
|
+
*
|
|
19
|
+
* function YourApp() {
|
|
20
|
+
* const { user, isAuthenticated, signIn, signOut } = useAuth();
|
|
21
|
+
* // ...
|
|
22
|
+
* }
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export { WebOxyProvider, useWebOxy, useAuth } from './WebOxyProvider';
|
|
26
|
+
export type { WebOxyProviderProps, WebAuthState, WebAuthActions, WebOxyContextValue, } from './WebOxyProvider';
|
|
27
|
+
export { useAuthStore } from './stores/authStore';
|
|
28
|
+
export { useAssetStore, useAssets as useAssetsStore, useAsset, useUploadProgress, useAssetLoading, useAssetErrors, useAssetsByApp, useAssetsByEntity, useAssetUsageCount, useIsAssetLinked, } from './stores/assetStore';
|
|
29
|
+
export { useUserProfile, useUserProfiles, useCurrentUser, useUserById, useUserByUsername, useUsersBySessions, usePrivacySettings, useSessions, useSession, useDeviceSessions, useUserDevices, useSecurityInfo, useSecurityActivity, useRecentSecurityActivity, } from './hooks/queries';
|
|
30
|
+
export { useUpdateProfile, useUploadAvatar, useUpdateAccountSettings, useUpdatePrivacySettings, useUploadFile, useSwitchSession, useLogoutSession, useLogoutAll, useUpdateDeviceName, useRemoveDevice, } from './hooks/mutations';
|
|
31
|
+
export { createProfileMutation, createGenericMutation, } from './hooks/mutations/mutationFactory';
|
|
32
|
+
export type { ProfileMutationConfig, GenericMutationConfig, } from './hooks/mutations/mutationFactory';
|
|
33
|
+
export { useSessionSocket } from './hooks/useSessionSocket';
|
|
34
|
+
export { useAssets, setOxyAssetInstance } from './hooks/useAssets';
|
|
35
|
+
export { useFileDownloadUrl, setOxyFileUrlInstance } from './hooks/useFileDownloadUrl';
|
|
36
|
+
export { useFollow, useFollowerCounts } from './hooks/useFollow';
|
|
37
|
+
export { useFileFiltering } from './hooks/useFileFiltering';
|
|
38
|
+
export type { ViewMode, SortBy, SortOrder } from './hooks/useFileFiltering';
|
|
39
|
+
export { ensureValidToken, withAuthErrorHandling, authenticatedApiCall, isAuthenticationError, SessionSyncRequiredError, AuthenticationFailedError, } from './utils/authHelpers';
|
|
40
|
+
export type { HandleApiErrorOptions } from './utils/authHelpers';
|
|
41
|
+
export { handleAuthError, isInvalidSessionError, isTimeoutOrNetworkError, extractErrorMessage, } from './utils/errorHandlers';
|
|
42
|
+
export type { HandleAuthErrorOptions } from './utils/errorHandlers';
|
|
43
|
+
export { OxyServices, CrossDomainAuth, AuthManager, createAuthManager, createCrossDomainAuth, } from '@oxyhq/core';
|
|
44
|
+
export type { User, LoginResponse, ApiError, SessionLoginResponse, ClientSession, MinimalUserData, OxyConfig, StorageAdapter, AuthStateChangeCallback, AuthMethod, AuthManagerConfig, CrossDomainAuthOptions, } from '@oxyhq/core';
|
|
45
|
+
import { WebOxyProvider as _WebOxyProvider } from './WebOxyProvider';
|
|
46
|
+
export default _WebOxyProvider;
|