@aippy/runtime 0.2.6 → 0.2.7-dev.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/README.md +34 -0
- package/dist/ai/config/bridge.d.ts +23 -0
- package/dist/ai/config/helper.d.ts +43 -0
- package/dist/ai/config/index.d.ts +11 -0
- package/dist/ai/config/parser.d.ts +60 -0
- package/dist/ai/config/types.d.ts +80 -0
- package/dist/ai/errors.d.ts +25 -0
- package/dist/ai/index.d.ts +46 -0
- package/dist/ai/index.js +25 -0
- package/dist/ai/openai/index.d.ts +11 -0
- package/dist/ai/openai/provider.d.ts +51 -0
- package/dist/ai/shared/config.d.ts +54 -0
- package/dist/ai/shared/fetch.d.ts +28 -0
- package/dist/ai/shared/index.d.ts +6 -0
- package/dist/ai/ui/config.d.ts +25 -0
- package/dist/ai/ui/endpoints.d.ts +12 -0
- package/dist/ai/ui/index.d.ts +13 -0
- package/dist/ai/ui/types.d.ts +21 -0
- package/dist/ai.d.ts +2 -0
- package/dist/bridge-D2d8hnO_.js +395 -0
- package/dist/container-message-DGrno17o.js +31 -0
- package/dist/core/container-message.d.ts +81 -0
- package/dist/core/index.d.ts +1 -0
- package/dist/core/index.js +21 -18
- package/dist/core/native-bridge.d.ts +9 -0
- package/dist/device/index.js +121 -129
- package/dist/device/sensors.d.ts +5 -1
- package/dist/errors-CDEBaBxB.js +26 -0
- package/dist/helper-CRGxnlsu.js +261 -0
- package/dist/index/index.js +113 -52
- package/dist/index.d.ts +2 -0
- package/dist/native-bridge-BnvipFJc.js +6 -0
- package/dist/{runtime-DjBdOttl.js → runtime-CmoG3v2m.js} +55 -76
- package/dist/user/api.d.ts +9 -0
- package/dist/user/bridge.d.ts +162 -0
- package/dist/user/config.d.ts +21 -0
- package/dist/user/hooks.d.ts +74 -0
- package/dist/user/index.d.ts +12 -0
- package/dist/user/index.js +38 -0
- package/dist/user/types.d.ts +113 -0
- package/dist/user/userSessionInfo.d.ts +6 -0
- package/dist/user.d.ts +2 -0
- package/dist/userSessionInfo-SbuNZ7JR.js +229 -0
- package/package.json +50 -36
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { UserProfile } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Fetch user profile by ID from API
|
|
4
|
+
*/
|
|
5
|
+
export declare function fetchUserProfile(userId: string): Promise<UserProfile | null>;
|
|
6
|
+
/**
|
|
7
|
+
* Clear profile cache
|
|
8
|
+
*/
|
|
9
|
+
export declare function clearProfileCache(userId?: string): void;
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* User SDK Bridge
|
|
3
|
+
* Handles communication with:
|
|
4
|
+
* - iOS native layer via window.webkit.aippyListener
|
|
5
|
+
* - Parent window via postMessage (iframe scenario)
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* User credentials
|
|
9
|
+
*/
|
|
10
|
+
export interface IOSUserCredentials {
|
|
11
|
+
uid: string;
|
|
12
|
+
token: string;
|
|
13
|
+
apiBaseUrl?: string;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* User information (extended profile data)
|
|
17
|
+
*/
|
|
18
|
+
export interface IOSUserInfo {
|
|
19
|
+
uid: string;
|
|
20
|
+
displayName?: string;
|
|
21
|
+
nickname?: string;
|
|
22
|
+
username?: string;
|
|
23
|
+
photoUrl?: string;
|
|
24
|
+
avatar?: string;
|
|
25
|
+
email?: string;
|
|
26
|
+
phone?: string;
|
|
27
|
+
bio?: string;
|
|
28
|
+
online?: boolean;
|
|
29
|
+
[key: string]: unknown;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Check if running inside an iframe
|
|
33
|
+
*/
|
|
34
|
+
export declare function isInIframe(): boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Request user credentials from parent window (iframe scenario)
|
|
37
|
+
* Parent window should respond with postMessage containing credentials
|
|
38
|
+
*
|
|
39
|
+
* @param timeoutMs - Timeout in milliseconds (default: 5000)
|
|
40
|
+
* @returns Promise resolving to user credentials
|
|
41
|
+
*/
|
|
42
|
+
export declare function requestCredentialsFromParent(timeoutMs?: number): Promise<IOSUserCredentials>;
|
|
43
|
+
/**
|
|
44
|
+
* Request user info from parent window (iframe scenario)
|
|
45
|
+
* Parent window should respond with postMessage containing user info
|
|
46
|
+
* IMPORTANT: This method does NOT cache - it always requests fresh data
|
|
47
|
+
*
|
|
48
|
+
* @param timeoutMs - Timeout in milliseconds (default: 5000)
|
|
49
|
+
* @returns Promise resolving to user info (null if unavailable)
|
|
50
|
+
*/
|
|
51
|
+
export declare function requestUserInfoFromParent(timeoutMs?: number): Promise<IOSUserInfo | null>;
|
|
52
|
+
/**
|
|
53
|
+
* Try to get credentials from parent localStorage directly
|
|
54
|
+
* This works when same-origin, otherwise falls back to postMessage
|
|
55
|
+
*
|
|
56
|
+
* localStorage format:
|
|
57
|
+
* - token: JWT string
|
|
58
|
+
* - user: JSON string with { uid, nickName, ... }
|
|
59
|
+
*/
|
|
60
|
+
export declare function tryGetCredentialsFromParentStorage(): IOSUserCredentials | null;
|
|
61
|
+
/**
|
|
62
|
+
* Try to get user info from parent localStorage directly
|
|
63
|
+
* This works when same-origin, otherwise falls back to postMessage
|
|
64
|
+
* IMPORTANT: This method does NOT cache - it always reads fresh data from parent
|
|
65
|
+
*
|
|
66
|
+
* localStorage format:
|
|
67
|
+
* - user: JSON string with { uid, nickName, username, avatar, ... }
|
|
68
|
+
*
|
|
69
|
+
* @returns User info or null if unavailable
|
|
70
|
+
*/
|
|
71
|
+
export declare function tryGetUserInfoFromParentStorage(): IOSUserInfo | null;
|
|
72
|
+
/**
|
|
73
|
+
* Request user credentials from iOS native layer
|
|
74
|
+
* Uses aippyRuntime's message passing mechanism
|
|
75
|
+
*
|
|
76
|
+
* @param timeoutMs - Timeout in milliseconds (default: 5000)
|
|
77
|
+
* @returns Promise resolving to user credentials (empty if unavailable)
|
|
78
|
+
*/
|
|
79
|
+
export declare function requestCredentialsFromiOS(timeoutMs?: number): Promise<IOSUserCredentials>;
|
|
80
|
+
/**
|
|
81
|
+
* Receive credentials directly from iOS or parent window
|
|
82
|
+
* Called via: window.processUserCredentials(data)
|
|
83
|
+
*/
|
|
84
|
+
export declare function processUserCredentials(data: unknown): void;
|
|
85
|
+
/**
|
|
86
|
+
* Receive user info directly from iOS or parent window
|
|
87
|
+
* Called via: window.processUserInfo(data)
|
|
88
|
+
*/
|
|
89
|
+
export declare function processUserInfo(data: unknown): void;
|
|
90
|
+
/**
|
|
91
|
+
* Request user info from iOS native layer
|
|
92
|
+
* This method caches the result and won't request again unless forced
|
|
93
|
+
*
|
|
94
|
+
* @param forceRefresh - Force refresh even if cached (default: false)
|
|
95
|
+
* @param timeoutMs - Timeout in milliseconds (default: 5000)
|
|
96
|
+
* @returns Promise resolving to user info (null if unavailable)
|
|
97
|
+
*/
|
|
98
|
+
export declare function requestUserInfoFromiOS(forceRefresh?: boolean, timeoutMs?: number): Promise<IOSUserInfo | null>;
|
|
99
|
+
/**
|
|
100
|
+
* Get user info asynchronously
|
|
101
|
+
* Returns cached user info if available, otherwise requests from iOS
|
|
102
|
+
*
|
|
103
|
+
* @param forceRefresh - Force refresh even if cached (default: false)
|
|
104
|
+
* @returns Promise resolving to user info, or null if unavailable
|
|
105
|
+
*/
|
|
106
|
+
export declare function getUserInfoAsync(forceRefresh?: boolean): Promise<IOSUserInfo | null>;
|
|
107
|
+
/**
|
|
108
|
+
* Get user info from parent window (iframe scenario)
|
|
109
|
+
* IMPORTANT: This method ALWAYS fetches fresh data, NO caching
|
|
110
|
+
*
|
|
111
|
+
* Strategy:
|
|
112
|
+
* 1. Try to get from parent localStorage (same-origin, faster)
|
|
113
|
+
* 2. If cross-origin, use postMessage (slower but works cross-origin)
|
|
114
|
+
*
|
|
115
|
+
* @param timeoutMs - Timeout for postMessage request (default: 5000)
|
|
116
|
+
* @returns Promise resolving to fresh user info, or null if unavailable
|
|
117
|
+
*/
|
|
118
|
+
export declare function getUserInfoFromParent(timeoutMs?: number): Promise<IOSUserInfo | null>;
|
|
119
|
+
/**
|
|
120
|
+
* Get cached user info (synchronous, may be null if not yet received)
|
|
121
|
+
*/
|
|
122
|
+
export declare function getCachedUserInfo(): IOSUserInfo | null;
|
|
123
|
+
/**
|
|
124
|
+
* Check if user info has been received
|
|
125
|
+
*/
|
|
126
|
+
export declare function hasUserInfo(): boolean;
|
|
127
|
+
/**
|
|
128
|
+
* Clear cached user info (useful for logout)
|
|
129
|
+
*/
|
|
130
|
+
export declare function clearCachedUserInfo(): void;
|
|
131
|
+
/**
|
|
132
|
+
* Initialize bridge and expose to window
|
|
133
|
+
*/
|
|
134
|
+
export declare function initUserBridge(): void;
|
|
135
|
+
/**
|
|
136
|
+
* Auto-request credentials on SDK load
|
|
137
|
+
* Tries multiple sources in order:
|
|
138
|
+
* 1. iOS native bridge (if available)
|
|
139
|
+
* 2. Parent localStorage (if in iframe, same-origin)
|
|
140
|
+
* 3. Parent postMessage (if in iframe, cross-origin)
|
|
141
|
+
*/
|
|
142
|
+
export declare function autoRequestCredentials(): Promise<void>;
|
|
143
|
+
/**
|
|
144
|
+
* Get auth token asynchronously
|
|
145
|
+
* Waits for credentials if not already available
|
|
146
|
+
* @returns Promise resolving to token string, or "" if unavailable
|
|
147
|
+
*/
|
|
148
|
+
export declare function getAuthTokenAsync(): Promise<string>;
|
|
149
|
+
/**
|
|
150
|
+
* Get current user ID asynchronously
|
|
151
|
+
* Waits for credentials if not already available
|
|
152
|
+
* @returns Promise resolving to user ID string, or "" if unavailable
|
|
153
|
+
*/
|
|
154
|
+
export declare function getCurrentUserIdAsync(): Promise<string>;
|
|
155
|
+
/**
|
|
156
|
+
* Check if credentials have been received
|
|
157
|
+
*/
|
|
158
|
+
export declare function hasCredentials(): boolean;
|
|
159
|
+
/**
|
|
160
|
+
* Get cached credentials (synchronous, may be null if not yet received)
|
|
161
|
+
*/
|
|
162
|
+
export declare function getCachedCredentials(): IOSUserCredentials | null;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { UserSdkConfig } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Initialize user SDK configuration
|
|
4
|
+
*/
|
|
5
|
+
export declare function initUserSdk(config: Partial<UserSdkConfig>): void;
|
|
6
|
+
/**
|
|
7
|
+
* Get current user SDK configuration
|
|
8
|
+
*/
|
|
9
|
+
export declare function getUserSdkConfig(): UserSdkConfig;
|
|
10
|
+
/**
|
|
11
|
+
* Update auth token
|
|
12
|
+
*/
|
|
13
|
+
export declare function setAuthToken(token: string): void;
|
|
14
|
+
/**
|
|
15
|
+
* Update current user ID
|
|
16
|
+
*/
|
|
17
|
+
export declare function setCurrentUserId(userId: string | null): void;
|
|
18
|
+
/**
|
|
19
|
+
* Get current auth token synchronously
|
|
20
|
+
*/
|
|
21
|
+
export declare function getAuthToken(): string;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { UserProfileQueryResult, UserProfilesQueryResult, GetUserProfileByIdOptions, GetJoinedUserProfilesOptions } from './types';
|
|
2
|
+
import { getAuthToken } from './config';
|
|
3
|
+
/**
|
|
4
|
+
* Hook to get current user ID
|
|
5
|
+
* @returns Current user ID or null
|
|
6
|
+
*/
|
|
7
|
+
export declare function useCurrentUserId(): string | null;
|
|
8
|
+
/**
|
|
9
|
+
* Hook to get current auth token
|
|
10
|
+
* @returns Current auth token string
|
|
11
|
+
*/
|
|
12
|
+
export declare function useAuthToken(): string;
|
|
13
|
+
/**
|
|
14
|
+
* Hook to get current user's profile
|
|
15
|
+
* @returns Query result with current user profile data
|
|
16
|
+
*/
|
|
17
|
+
export declare function useGetCurrentUserProfileQuery(): UserProfileQueryResult;
|
|
18
|
+
/**
|
|
19
|
+
* Hook to get user profile by ID
|
|
20
|
+
* @param options - Options containing user ID to fetch
|
|
21
|
+
* @returns Query result with user profile data
|
|
22
|
+
*/
|
|
23
|
+
export declare function useGetUserProfileByIdQuery(options: GetUserProfileByIdOptions): UserProfileQueryResult;
|
|
24
|
+
/**
|
|
25
|
+
* Hook to get all joined user profiles
|
|
26
|
+
* @param options - Options for filtering users
|
|
27
|
+
* @returns Query result with user profiles array
|
|
28
|
+
*
|
|
29
|
+
* Note: This is a simplified implementation that only fetches the current user.
|
|
30
|
+
* In production, this would fetch all users from a users list API.
|
|
31
|
+
*/
|
|
32
|
+
export declare function useGetJoinedUserProfilesQuery(options?: GetJoinedUserProfilesOptions): UserProfilesQueryResult;
|
|
33
|
+
/**
|
|
34
|
+
* Synchronous function to get current user ID
|
|
35
|
+
* Use this in non-React contexts
|
|
36
|
+
*/
|
|
37
|
+
export declare function getCurrentUserId(): string | null;
|
|
38
|
+
export { getAuthToken };
|
|
39
|
+
/**
|
|
40
|
+
* Hook to get user info from iOS or parent window (no backend API)
|
|
41
|
+
* Automatically detects environment (iOS App or iframe) and uses appropriate method
|
|
42
|
+
*
|
|
43
|
+
* Uses module-level cache to avoid duplicate requests when used in multiple components
|
|
44
|
+
*
|
|
45
|
+
* @returns User info with avatar, nickName, username, uid
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```typescript
|
|
49
|
+
* const { avatar, nickName, username, uid } = useUserInfo();
|
|
50
|
+
*
|
|
51
|
+
* <Avatar>
|
|
52
|
+
* <AvatarImage src={avatar} />
|
|
53
|
+
* <AvatarFallback>{nickName[0]}</AvatarFallback>
|
|
54
|
+
* </Avatar>
|
|
55
|
+
* <span>{nickName}</span>
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
export declare function useUserInfo(): {
|
|
59
|
+
avatar: string;
|
|
60
|
+
nickName: string;
|
|
61
|
+
username: string;
|
|
62
|
+
uid: string;
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* Clear the cached user info
|
|
66
|
+
* Useful when user logs out or switches account
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```typescript
|
|
70
|
+
* // When user logs out
|
|
71
|
+
* clearUserInfoCache();
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
export declare function clearUserInfoCache(): void;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* User SDK module
|
|
3
|
+
* Provides user profile fetching and session management
|
|
4
|
+
*/
|
|
5
|
+
export type { UserProfile, UserProfileQueryResult, UserProfilesQueryResult, GetUserProfileByIdOptions, GetJoinedUserProfilesOptions, FormatDateOptions, UserSessionInfoInterface, UserSdkConfig, } from './types';
|
|
6
|
+
export { initUserSdk, getUserSdkConfig, setAuthToken, setCurrentUserId, } from './config';
|
|
7
|
+
export { useCurrentUserId, useAuthToken, useGetCurrentUserProfileQuery, useGetUserProfileByIdQuery, useGetJoinedUserProfilesQuery, getCurrentUserId, getAuthToken, useUserInfo, // Simple hook for iOS/iframe user info
|
|
8
|
+
clearUserInfoCache, } from './hooks';
|
|
9
|
+
export { fetchUserProfile, clearProfileCache } from './api';
|
|
10
|
+
export { userSessionInfo } from './userSessionInfo';
|
|
11
|
+
export { isInIframe, requestCredentialsFromiOS, requestCredentialsFromParent, tryGetCredentialsFromParentStorage, initUserBridge, autoRequestCredentials, getAuthTokenAsync, getCurrentUserIdAsync, hasCredentials, getCachedCredentials, requestUserInfoFromiOS, getUserInfoAsync, getCachedUserInfo, hasUserInfo, clearCachedUserInfo, requestUserInfoFromParent, tryGetUserInfoFromParentStorage, getUserInfoFromParent, } from './bridge';
|
|
12
|
+
export type { IOSUserCredentials, IOSUserInfo } from './bridge';
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { f as r, q as a, b as t, h as n, l as o, o as u, j as i, n as f, w as U, g as d, k as I, p as C, e as g, i as l, c, d as h, r as m, u as P, m as y, s as k, a as A, t as F, v as S } from "../bridge-D2d8hnO_.js";
|
|
2
|
+
import { i as G, f as T, h as p, g as Q, a as b, u as j, b as x, d as B, c as O, e as v, j as w } from "../userSessionInfo-SbuNZ7JR.js";
|
|
3
|
+
export {
|
|
4
|
+
r as autoRequestCredentials,
|
|
5
|
+
a as clearCachedUserInfo,
|
|
6
|
+
G as clearProfileCache,
|
|
7
|
+
T as clearUserInfoCache,
|
|
8
|
+
p as fetchUserProfile,
|
|
9
|
+
t as getAuthToken,
|
|
10
|
+
n as getAuthTokenAsync,
|
|
11
|
+
o as getCachedCredentials,
|
|
12
|
+
u as getCachedUserInfo,
|
|
13
|
+
Q as getCurrentUserId,
|
|
14
|
+
i as getCurrentUserIdAsync,
|
|
15
|
+
f as getUserInfoAsync,
|
|
16
|
+
U as getUserInfoFromParent,
|
|
17
|
+
d as getUserSdkConfig,
|
|
18
|
+
I as hasCredentials,
|
|
19
|
+
C as hasUserInfo,
|
|
20
|
+
g as initUserBridge,
|
|
21
|
+
l as initUserSdk,
|
|
22
|
+
c as isInIframe,
|
|
23
|
+
h as requestCredentialsFromParent,
|
|
24
|
+
m as requestCredentialsFromiOS,
|
|
25
|
+
P as requestUserInfoFromParent,
|
|
26
|
+
y as requestUserInfoFromiOS,
|
|
27
|
+
k as setAuthToken,
|
|
28
|
+
A as setCurrentUserId,
|
|
29
|
+
F as tryGetCredentialsFromParentStorage,
|
|
30
|
+
S as tryGetUserInfoFromParentStorage,
|
|
31
|
+
b as useAuthToken,
|
|
32
|
+
j as useCurrentUserId,
|
|
33
|
+
x as useGetCurrentUserProfileQuery,
|
|
34
|
+
B as useGetJoinedUserProfilesQuery,
|
|
35
|
+
O as useGetUserProfileByIdQuery,
|
|
36
|
+
v as useUserInfo,
|
|
37
|
+
w as userSessionInfo
|
|
38
|
+
};
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* User SDK types and interfaces
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Global type declarations for User SDK iOS bridge
|
|
6
|
+
* Note: webkit.messageHandlers.aippyListener is already declared in tweaks/types.ts
|
|
7
|
+
*/
|
|
8
|
+
declare global {
|
|
9
|
+
interface Window {
|
|
10
|
+
/** User credentials callback from iOS */
|
|
11
|
+
processUserCredentials?: (data: unknown) => void;
|
|
12
|
+
/** User info callback from iOS */
|
|
13
|
+
processUserInfo?: (data: unknown) => void;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* User profile data structure
|
|
18
|
+
*/
|
|
19
|
+
export interface UserProfile {
|
|
20
|
+
/** User unique identifier */
|
|
21
|
+
id: string;
|
|
22
|
+
/** Display name */
|
|
23
|
+
displayName: string;
|
|
24
|
+
/** Username (for @mentions) */
|
|
25
|
+
username: string;
|
|
26
|
+
/** Avatar URL */
|
|
27
|
+
photoUrl?: string;
|
|
28
|
+
/** Online status */
|
|
29
|
+
online?: boolean;
|
|
30
|
+
/** User bio */
|
|
31
|
+
bio?: string;
|
|
32
|
+
/** Cover image URL */
|
|
33
|
+
coverImageUrl?: string;
|
|
34
|
+
/** Additional metadata */
|
|
35
|
+
[key: string]: unknown;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Query result for user profile
|
|
39
|
+
*/
|
|
40
|
+
export interface UserProfileQueryResult {
|
|
41
|
+
/** User profile data */
|
|
42
|
+
data: UserProfile | null;
|
|
43
|
+
/** Loading state */
|
|
44
|
+
isLoading: boolean;
|
|
45
|
+
/** Error state */
|
|
46
|
+
isError: boolean;
|
|
47
|
+
/** Error object */
|
|
48
|
+
error: Error | null;
|
|
49
|
+
/** Refetch function */
|
|
50
|
+
refetch: () => Promise<void>;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Options for getting user profile by ID
|
|
54
|
+
*/
|
|
55
|
+
export interface GetUserProfileByIdOptions {
|
|
56
|
+
/** User ID to fetch */
|
|
57
|
+
id: string;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Options for getting joined user profiles
|
|
61
|
+
*/
|
|
62
|
+
export interface GetJoinedUserProfilesOptions {
|
|
63
|
+
/** Whether to include current user */
|
|
64
|
+
includeSelf?: boolean;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Query result for multiple user profiles
|
|
68
|
+
*/
|
|
69
|
+
export interface UserProfilesQueryResult {
|
|
70
|
+
/** User profiles array */
|
|
71
|
+
data: UserProfile[];
|
|
72
|
+
/** Loading state */
|
|
73
|
+
isLoading: boolean;
|
|
74
|
+
/** Error state */
|
|
75
|
+
isError: boolean;
|
|
76
|
+
/** Error object */
|
|
77
|
+
error: Error | null;
|
|
78
|
+
/** Refetch function */
|
|
79
|
+
refetch: () => Promise<void>;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Date format options
|
|
83
|
+
*/
|
|
84
|
+
export interface FormatDateOptions {
|
|
85
|
+
/** Timestamp in milliseconds */
|
|
86
|
+
timestampMs: number;
|
|
87
|
+
/** Format string (e.g., 'MMM d, h:mm a') */
|
|
88
|
+
formatString: string;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* User session info interface
|
|
92
|
+
*/
|
|
93
|
+
export interface UserSessionInfoInterface {
|
|
94
|
+
/** Get current user ID synchronously */
|
|
95
|
+
getCurrentUserId: () => string | null;
|
|
96
|
+
/** Get current timestamp in milliseconds */
|
|
97
|
+
getTimestampInMs: () => number;
|
|
98
|
+
/** Format date with given format string */
|
|
99
|
+
formatDate: (options: FormatDateOptions) => string;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* User SDK configuration
|
|
103
|
+
*/
|
|
104
|
+
export interface UserSdkConfig {
|
|
105
|
+
/** API base URL */
|
|
106
|
+
apiBaseUrl: string;
|
|
107
|
+
/** Auth token */
|
|
108
|
+
authToken: string;
|
|
109
|
+
/** Current user ID */
|
|
110
|
+
currentUserId: string | null;
|
|
111
|
+
/** Cache time in milliseconds */
|
|
112
|
+
cacheTime?: number;
|
|
113
|
+
}
|
package/dist/user.d.ts
ADDED
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
import { useState as o, useEffect as y, useCallback as U } from "react";
|
|
2
|
+
import { g as I, b as k } from "./bridge-D2d8hnO_.js";
|
|
3
|
+
const w = /* @__PURE__ */ new Map();
|
|
4
|
+
async function S(e) {
|
|
5
|
+
const t = I(), n = w.get(e);
|
|
6
|
+
if (n && Date.now() - n.timestamp < (t.cacheTime || 3e5))
|
|
7
|
+
return n.data;
|
|
8
|
+
try {
|
|
9
|
+
const r = await fetch(
|
|
10
|
+
`${t.apiBaseUrl}/user/profile?targetUid=${e}`,
|
|
11
|
+
{
|
|
12
|
+
method: "GET",
|
|
13
|
+
headers: {
|
|
14
|
+
Authorization: `Bearer ${t.authToken}`,
|
|
15
|
+
"Content-Type": "application/json"
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
);
|
|
19
|
+
if (!r.ok)
|
|
20
|
+
throw new Error(`Failed to fetch user profile: ${r.status}`);
|
|
21
|
+
const a = await r.json(), i = C(a, e);
|
|
22
|
+
return w.set(e, { data: i, timestamp: Date.now() }), i;
|
|
23
|
+
} catch (r) {
|
|
24
|
+
return console.error("[UserSDK] Failed to fetch user profile:", r), null;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function C(e, t) {
|
|
28
|
+
const n = typeof e == "object" && e !== null ? e : {}, r = n.data || n.user || n;
|
|
29
|
+
return {
|
|
30
|
+
id: r.id || r.uid || t,
|
|
31
|
+
displayName: r.displayName || r.nickname || r.name || "Unknown User",
|
|
32
|
+
username: r.username || r.id || t,
|
|
33
|
+
photoUrl: r.photoUrl || r.avatar || r.avatarUrl,
|
|
34
|
+
online: r.online ?? !1,
|
|
35
|
+
bio: r.bio,
|
|
36
|
+
coverImageUrl: r.coverImageUrl,
|
|
37
|
+
...r
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
function D(e) {
|
|
41
|
+
e ? w.delete(e) : w.clear();
|
|
42
|
+
}
|
|
43
|
+
function M() {
|
|
44
|
+
const [e, t] = o(
|
|
45
|
+
I().currentUserId
|
|
46
|
+
);
|
|
47
|
+
return y(() => {
|
|
48
|
+
t(I().currentUserId);
|
|
49
|
+
}, []), e;
|
|
50
|
+
}
|
|
51
|
+
function N() {
|
|
52
|
+
const [e, t] = o(k());
|
|
53
|
+
return y(() => {
|
|
54
|
+
t(k());
|
|
55
|
+
}, []), e;
|
|
56
|
+
}
|
|
57
|
+
function T() {
|
|
58
|
+
const e = M(), [t, n] = o(null), [r, a] = o(!0), [i, u] = o(!1), [h, s] = o(null), l = U(async () => {
|
|
59
|
+
if (!e) {
|
|
60
|
+
n(null), a(!1);
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
a(!0), u(!1), s(null);
|
|
64
|
+
try {
|
|
65
|
+
const c = await S(e);
|
|
66
|
+
n(c);
|
|
67
|
+
} catch (c) {
|
|
68
|
+
u(!0), s(c instanceof Error ? c : new Error(String(c)));
|
|
69
|
+
} finally {
|
|
70
|
+
a(!1);
|
|
71
|
+
}
|
|
72
|
+
}, [e]);
|
|
73
|
+
y(() => {
|
|
74
|
+
l();
|
|
75
|
+
}, [l]);
|
|
76
|
+
const f = U(async () => {
|
|
77
|
+
e && D(e), await l();
|
|
78
|
+
}, [e, l]);
|
|
79
|
+
return { data: t, isLoading: r, isError: i, error: h, refetch: f };
|
|
80
|
+
}
|
|
81
|
+
function b(e) {
|
|
82
|
+
const { id: t } = e, [n, r] = o(null), [a, i] = o(!0), [u, h] = o(!1), [s, l] = o(null), f = U(async () => {
|
|
83
|
+
if (!t) {
|
|
84
|
+
r(null), i(!1);
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
i(!0), h(!1), l(null);
|
|
88
|
+
try {
|
|
89
|
+
const d = await S(t);
|
|
90
|
+
r(d);
|
|
91
|
+
} catch (d) {
|
|
92
|
+
h(!0), l(d instanceof Error ? d : new Error(String(d)));
|
|
93
|
+
} finally {
|
|
94
|
+
i(!1);
|
|
95
|
+
}
|
|
96
|
+
}, [t]);
|
|
97
|
+
y(() => {
|
|
98
|
+
f();
|
|
99
|
+
}, [f]);
|
|
100
|
+
const c = U(async () => {
|
|
101
|
+
D(t), await f();
|
|
102
|
+
}, [t, f]);
|
|
103
|
+
return { data: n, isLoading: a, isError: u, error: s, refetch: c };
|
|
104
|
+
}
|
|
105
|
+
function A(e = {}) {
|
|
106
|
+
const { includeSelf: t = !0 } = e, n = M(), [r, a] = o([]), [i, u] = o(!0), [h, s] = o(!1), [l, f] = o(null), c = U(async () => {
|
|
107
|
+
u(!0), s(!1), f(null);
|
|
108
|
+
try {
|
|
109
|
+
const m = [];
|
|
110
|
+
if (t && n) {
|
|
111
|
+
const E = await S(n);
|
|
112
|
+
E && m.push(E);
|
|
113
|
+
}
|
|
114
|
+
a(m);
|
|
115
|
+
} catch (m) {
|
|
116
|
+
s(!0), f(m instanceof Error ? m : new Error(String(m)));
|
|
117
|
+
} finally {
|
|
118
|
+
u(!1);
|
|
119
|
+
}
|
|
120
|
+
}, [t, n]);
|
|
121
|
+
y(() => {
|
|
122
|
+
c();
|
|
123
|
+
}, [c]);
|
|
124
|
+
const d = U(async () => {
|
|
125
|
+
D(), await c();
|
|
126
|
+
}, [c]);
|
|
127
|
+
return { data: r, isLoading: i, isError: h, error: l, refetch: d };
|
|
128
|
+
}
|
|
129
|
+
function L() {
|
|
130
|
+
return I().currentUserId;
|
|
131
|
+
}
|
|
132
|
+
let g = null, p = null;
|
|
133
|
+
function j() {
|
|
134
|
+
const [e, t] = o(g || {
|
|
135
|
+
avatar: "",
|
|
136
|
+
nickName: "用户",
|
|
137
|
+
username: "",
|
|
138
|
+
uid: ""
|
|
139
|
+
});
|
|
140
|
+
return y(() => {
|
|
141
|
+
let n = !0;
|
|
142
|
+
return (async () => {
|
|
143
|
+
try {
|
|
144
|
+
if (g) {
|
|
145
|
+
console.log("[useUserInfo] Using cached user info"), n && t(g);
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
if (p) {
|
|
149
|
+
console.log("[useUserInfo] Waiting for existing request"), await p, n && g && t(g);
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
console.log("[useUserInfo] Fetching user info"), p = (async () => {
|
|
153
|
+
const { getUserInfoAsync: a, getUserInfoFromParent: i, isInIframe: u } = await import("./bridge-D2d8hnO_.js").then((l) => l.x), { hasNativeBridge: h } = await import("./native-bridge-BnvipFJc.js");
|
|
154
|
+
let s = null;
|
|
155
|
+
h() ? s = await a() : u() ? s = await i() : s = await a(), s && (g = {
|
|
156
|
+
avatar: String(s.avatar || s.photoUrl || ""),
|
|
157
|
+
nickName: String(s.nickName || s.displayName || "用户"),
|
|
158
|
+
username: String(s.username || ""),
|
|
159
|
+
uid: String(s.uid || "")
|
|
160
|
+
});
|
|
161
|
+
})(), await p, p = null, n && g && t(g);
|
|
162
|
+
} catch (a) {
|
|
163
|
+
console.error("[useUserInfo] Failed to fetch user info:", a), p = null;
|
|
164
|
+
}
|
|
165
|
+
})(), () => {
|
|
166
|
+
n = !1;
|
|
167
|
+
};
|
|
168
|
+
}, []), e;
|
|
169
|
+
}
|
|
170
|
+
function B() {
|
|
171
|
+
g = null, p = null, console.log("[useUserInfo] Cache cleared");
|
|
172
|
+
}
|
|
173
|
+
function P(e, t) {
|
|
174
|
+
const n = [
|
|
175
|
+
"Jan",
|
|
176
|
+
"Feb",
|
|
177
|
+
"Mar",
|
|
178
|
+
"Apr",
|
|
179
|
+
"May",
|
|
180
|
+
"Jun",
|
|
181
|
+
"Jul",
|
|
182
|
+
"Aug",
|
|
183
|
+
"Sep",
|
|
184
|
+
"Oct",
|
|
185
|
+
"Nov",
|
|
186
|
+
"Dec"
|
|
187
|
+
], r = e.getHours(), a = r % 12 || 12, i = r >= 12 ? "PM" : "AM";
|
|
188
|
+
return t.replace("MMM", n[e.getMonth()]).replace("dd", String(e.getDate()).padStart(2, "0")).replace("d", String(e.getDate())).replace("hh", String(a).padStart(2, "0")).replace("h", String(a)).replace("mm", String(e.getMinutes()).padStart(2, "0")).replace("a", i).replace("yyyy", String(e.getFullYear())).replace("yy", String(e.getFullYear()).slice(-2));
|
|
189
|
+
}
|
|
190
|
+
const G = {
|
|
191
|
+
/**
|
|
192
|
+
* Get current user ID synchronously
|
|
193
|
+
*/
|
|
194
|
+
getCurrentUserId() {
|
|
195
|
+
return I().currentUserId;
|
|
196
|
+
},
|
|
197
|
+
/**
|
|
198
|
+
* Get current timestamp in milliseconds
|
|
199
|
+
*/
|
|
200
|
+
getTimestampInMs() {
|
|
201
|
+
return Date.now();
|
|
202
|
+
},
|
|
203
|
+
/**
|
|
204
|
+
* Format date with given format string
|
|
205
|
+
* @param options - Format options with timestamp and format string
|
|
206
|
+
* @returns Formatted date string
|
|
207
|
+
*
|
|
208
|
+
* @example
|
|
209
|
+
* userSessionInfo.formatDate({ timestampMs: Date.now(), formatString: 'MMM d, h:mm a' })
|
|
210
|
+
* // Returns: "Jan 7, 10:30 PM"
|
|
211
|
+
*/
|
|
212
|
+
formatDate(e) {
|
|
213
|
+
const { timestampMs: t, formatString: n } = e, r = new Date(t);
|
|
214
|
+
return P(r, n);
|
|
215
|
+
}
|
|
216
|
+
};
|
|
217
|
+
export {
|
|
218
|
+
N as a,
|
|
219
|
+
T as b,
|
|
220
|
+
b as c,
|
|
221
|
+
A as d,
|
|
222
|
+
j as e,
|
|
223
|
+
B as f,
|
|
224
|
+
L as g,
|
|
225
|
+
S as h,
|
|
226
|
+
D as i,
|
|
227
|
+
G as j,
|
|
228
|
+
M as u
|
|
229
|
+
};
|