@aippy/runtime 0.2.7-dev.3 → 0.2.7-dev.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,160 +1,29 @@
1
1
  /**
2
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
3
  */
4
+ export { isInIframe } from '../utils/platform';
10
5
  export interface IOSUserCredentials {
11
6
  uid: string;
12
7
  token: string;
13
8
  apiBaseUrl?: string;
14
9
  }
15
- /**
16
- * User information (extended profile data)
17
- */
18
10
  export interface IOSUserInfo {
19
11
  uid: string;
20
12
  displayName?: string;
21
13
  nickname?: string;
14
+ nickName?: string;
22
15
  username?: string;
23
16
  photoUrl?: string;
24
17
  avatar?: string;
25
- email?: string;
26
- phone?: string;
27
- bio?: string;
28
- online?: boolean;
29
18
  [key: string]: unknown;
30
19
  }
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
- */
20
+ /** Get auth token async, auto-detects environment */
21
+ export declare function getAuthTokenAsync(): Promise<string>;
22
+ /** Get user info async, auto-detects environment */
106
23
  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
- */
24
+ /** Get user info from parent window (iframe only, no cache) */
118
25
  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
- * 异步获取 Auth Token
145
- */
146
- export declare function getAuthTokenAsync(): Promise<string>;
147
- /**
148
- * Get current user ID asynchronously
149
- * Waits for credentials if not already available
150
- * @returns Promise resolving to user ID string, or "" if unavailable
151
- */
152
- export declare function getCurrentUserIdAsync(): Promise<string>;
153
- /**
154
- * Check if credentials have been received
155
- */
156
- export declare function hasCredentials(): boolean;
157
- /**
158
- * Get cached credentials (synchronous, may be null if not yet received)
159
- */
160
- export declare function getCachedCredentials(): IOSUserCredentials | null;
26
+ /** Called by iOS/Android: window.processUserCredentials(data) */
27
+ export declare function processUserCredentials(data: unknown): void;
28
+ /** Called by iOS/Android: window.processUserInfo(data) */
29
+ export declare function processUserInfo(data: unknown): void;
@@ -1,21 +1,12 @@
1
- import { UserSdkConfig } from './types';
2
1
  /**
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
2
+ * User SDK Config (internal)
12
3
  */
4
+ interface UserSdkConfig {
5
+ apiBaseUrl: string;
6
+ authToken: string;
7
+ currentUserId: string | null;
8
+ }
9
+ export declare function initUserSdk(partial: Partial<UserSdkConfig>): void;
13
10
  export declare function setAuthToken(token: string): void;
14
- /**
15
- * Update current user ID
16
- */
17
11
  export declare function setCurrentUserId(userId: string | null): void;
18
- /**
19
- * Get current auth token synchronously
20
- */
21
- export declare function getAuthToken(): string;
12
+ export {};
@@ -1,74 +1,12 @@
1
- import { UserProfileQueryResult, UserProfilesQueryResult, GetUserProfileByIdOptions, GetJoinedUserProfilesOptions } from './types';
2
- import { getAuthToken } from './config';
3
1
  /**
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
- * ```
2
+ * User SDK Hooks
57
3
  */
4
+ /** Hook to get user info (avatar, nickName, username, uid) */
58
5
  export declare function useUserInfo(): {
59
6
  avatar: string;
60
7
  nickName: string;
61
8
  username: string;
62
9
  uid: string;
63
10
  };
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
- */
11
+ /** Clear cached user info */
74
12
  export declare function clearUserInfoCache(): void;
@@ -1,12 +1,6 @@
1
1
  /**
2
- * User SDK module
3
- * Provides user profile fetching and session management
2
+ * User SDK
4
3
  */
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';
4
+ export { useUserInfo, clearUserInfoCache } from './hooks';
5
+ export { getAuthTokenAsync, isInIframe } from './bridge';
12
6
  export type { IOSUserCredentials, IOSUserInfo } from './bridge';
@@ -1,38 +1,9 @@
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-N9ELFpfV.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-DFvsuELU.js";
1
+ import { c as o, u as s } from "../hooks-CE9cjXHP.js";
2
+ import { getAuthTokenAsync as f } from "../bridge-Ca3H2iN1.js";
3
+ import { i as t } from "../ui-y5N62DqC.js";
3
4
  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
5
+ o as clearUserInfoCache,
6
+ f as getAuthTokenAsync,
7
+ t as isInIframe,
8
+ s as useUserInfo
38
9
  };
@@ -1,113 +1,10 @@
1
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
2
+ * User SDK Types
7
3
  */
8
4
  declare global {
9
5
  interface Window {
10
- /** User credentials callback from iOS */
11
6
  processUserCredentials?: (data: unknown) => void;
12
- /** User info callback from iOS */
13
7
  processUserInfo?: (data: unknown) => void;
14
8
  }
15
9
  }
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
- }
10
+ export {};
@@ -1,11 +1,13 @@
1
- import { P as a, p as s, s as t } from "../ui-D6IZ1jrR.js";
2
- import { a as p, P as f, p as m, b as P } from "../pwa-CilSlaik.js";
1
+ import { P as o, c as s, i as e, p as t, s as m } from "../ui-y5N62DqC.js";
2
+ import { a as f, P as i, p as n, b as c } from "../pwa-CilSlaik.js";
3
3
  export {
4
- p as PWAUtils,
5
- f as PerformanceMonitor,
6
- a as PlatformDetector,
7
- m as performanceMonitor,
8
- s as platform,
9
- P as pwa,
10
- t as showAlert
4
+ f as PWAUtils,
5
+ i as PerformanceMonitor,
6
+ o as PlatformDetector,
7
+ s as compareVersions,
8
+ e as isInIframe,
9
+ n as performanceMonitor,
10
+ t as platform,
11
+ c as pwa,
12
+ m as showAlert
11
13
  };
@@ -7,6 +7,34 @@ interface PlatformInfo {
7
7
  isMobile: boolean;
8
8
  isDesktop: boolean;
9
9
  }
10
+ /**
11
+ * Minimum app version configuration
12
+ */
13
+ export interface AppVersionConfig {
14
+ iOS: string;
15
+ Android: string;
16
+ }
17
+ /**
18
+ * App environment check result
19
+ */
20
+ export interface AppEnvironmentCheckResult {
21
+ type: 'new_app' | 'old_ios_app' | 'old_android_app' | 'iframe' | 'web';
22
+ isValid: boolean;
23
+ aippyInfo?: {
24
+ platform: 'iOS' | 'Android';
25
+ version: string;
26
+ } | null;
27
+ message?: string;
28
+ }
29
+ /**
30
+ * Check if running inside an iframe
31
+ */
32
+ export declare function isInIframe(): boolean;
33
+ /**
34
+ * Compare version numbers
35
+ * @returns -1 if v1 < v2, 0 if v1 == v2, 1 if v1 > v2
36
+ */
37
+ export declare function compareVersions(version1: string, version2: string): number;
10
38
  /**
11
39
  * Platform detection utilities
12
40
  */
@@ -17,6 +45,10 @@ export declare class PlatformDetector {
17
45
  * Get platform information
18
46
  */
19
47
  getPlatformInfo(): PlatformInfo;
48
+ /**
49
+ * Get raw UA parser result
50
+ */
51
+ getRawParserResult(): import('ua-parser-js').IResult;
20
52
  /**
21
53
  * Get platform capabilities
22
54
  */
@@ -42,7 +74,16 @@ export declare class PlatformDetector {
42
74
  */
43
75
  isAndroidChrome(): boolean;
44
76
  /**
45
- * 解析 User-Agent 中的 Aippy App 信息
77
+ * Check if running in Android WebView (old app version)
78
+ * Detects by checking if browser name contains "webview"
79
+ */
80
+ isAndroidWebView(): boolean;
81
+ /**
82
+ * Check app environment and validate version
83
+ */
84
+ checkAppEnvironment(minVersions: AppVersionConfig): AppEnvironmentCheckResult;
85
+ /**
86
+ * Parse Aippy App info from User-Agent
46
87
  */
47
88
  parseAippyInfo(): {
48
89
  platform: 'iOS' | 'Android';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aippy/runtime",
3
- "version": "0.2.7-dev.3",
3
+ "version": "0.2.7-dev.5",
4
4
  "description": "Aippy Runtime SDK - Runtime SDK for Aippy projects",
5
5
  "private": false,
6
6
  "type": "module",