@followgate/js 0.4.0 → 0.6.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/dist/index.d.mts CHANGED
@@ -6,6 +6,13 @@ type Platform = 'twitter' | 'bluesky' | 'linkedin';
6
6
  * Supported social actions
7
7
  */
8
8
  type SocialAction = 'follow' | 'repost' | 'like';
9
+ /**
10
+ * Twitter/X configuration
11
+ */
12
+ interface TwitterConfig {
13
+ handle: string;
14
+ tweetId?: string;
15
+ }
9
16
  /**
10
17
  * SDK Configuration
11
18
  */
@@ -14,6 +21,10 @@ interface FollowGateConfig {
14
21
  apiKey: string;
15
22
  apiUrl?: string;
16
23
  debug?: boolean;
24
+ twitter?: TwitterConfig;
25
+ onComplete?: () => void;
26
+ theme?: 'dark' | 'light';
27
+ accentColor?: string;
17
28
  }
18
29
  /**
19
30
  * SDK Error class with helpful messages
@@ -24,49 +35,35 @@ declare class FollowGateError extends Error {
24
35
  constructor(message: string, code: string, hint?: string | undefined);
25
36
  }
26
37
  /**
27
- * Open action options
38
+ * Complete action options
28
39
  */
29
- interface OpenOptions {
40
+ interface CompleteOptions {
30
41
  platform: Platform;
31
42
  action: SocialAction;
32
43
  target: string;
33
- userId?: string;
34
44
  }
35
- /**
36
- * LinkedIn target type
37
- */
38
- type LinkedInTargetType = 'company' | 'profile';
39
45
  /**
40
46
  * Event types
41
47
  */
42
- type EventType = 'complete' | 'error' | 'cancel' | 'authenticated';
48
+ type EventType = 'complete' | 'error' | 'unlocked';
43
49
  /**
44
50
  * Event callback
45
51
  */
46
52
  type EventCallback = (data: unknown) => void;
47
53
  /**
48
- * Authenticated user info
54
+ * User info (stored locally)
49
55
  */
50
- interface AuthenticatedUser {
51
- userId: string;
56
+ interface UserInfo {
52
57
  username: string;
53
58
  platform: Platform;
54
59
  }
55
60
  /**
56
- * Auth state when username input is needed
57
- */
58
- interface PendingUsernameState {
59
- needsUsername: true;
60
- token: string;
61
- }
62
- /**
63
- * Authentication options
61
+ * Unlock status
64
62
  */
65
- interface AuthOptions {
66
- /** Where to redirect after auth (defaults to current page) */
67
- redirectUri?: string;
68
- /** Open in popup instead of redirect */
69
- popup?: boolean;
63
+ interface UnlockStatus {
64
+ unlocked: boolean;
65
+ username?: string;
66
+ completedActions?: CompleteOptions[];
70
67
  }
71
68
  /**
72
69
  * FollowGate SDK Client
@@ -75,75 +72,74 @@ declare class FollowGateClient {
75
72
  private config;
76
73
  private listeners;
77
74
  private currentUser;
78
- private authToken;
79
- private pendingUsername;
75
+ private completedActions;
76
+ private modalElement;
77
+ private stylesInjected;
80
78
  /**
81
79
  * Initialize the SDK
82
- * @throws {FollowGateError} If configuration is invalid
83
80
  */
84
81
  init(config: FollowGateConfig): void;
85
82
  /**
86
- * Authenticate user via Twitter OAuth (handled by FollowGate)
87
- * This identifies WHO is completing the social actions.
88
- */
89
- authenticate(options?: AuthOptions): void;
90
- /**
91
- * Get current authenticated user
92
- */
93
- getUser(): AuthenticatedUser | null;
94
- /**
95
- * Check if user is authenticated
96
- */
97
- isAuthenticated(): boolean;
98
- /**
99
- * Logout - clear stored session
83
+ * Show the FollowGate modal
84
+ * If user is already unlocked, calls onComplete immediately
100
85
  */
101
- logout(): void;
86
+ show(): void;
102
87
  /**
103
- * Check if username input is needed (Twitter Free Tier limitation)
88
+ * Hide the modal
104
89
  */
105
- needsUsernameInput(): boolean;
90
+ hide(): void;
91
+ private injectStyles;
92
+ private createModal;
93
+ private getContentElement;
94
+ private renderUsernameStep;
95
+ private handleUsernameSubmit;
96
+ private renderFollowStep;
97
+ private handleFollowClick;
98
+ private showFollowConfirmation;
99
+ private handleFollowConfirm;
100
+ private renderRepostStep;
101
+ private handleRepostClick;
102
+ private showRepostConfirmation;
103
+ private handleRepostConfirm;
104
+ private renderConfirmStep;
105
+ private handleFinish;
106
+ private renderStepIndicator;
106
107
  /**
107
- * Set username manually (when needsUsernameInput() returns true)
108
+ * Set the user's social username
108
109
  */
109
- setUsername(username: string): void;
110
+ setUsername(username: string, platform?: Platform): void;
110
111
  /**
111
- * Handle auth callback from URL params
112
+ * Get current user
112
113
  */
113
- private handleAuthCallback;
114
+ getUser(): UserInfo | null;
114
115
  /**
115
- * Restore session from localStorage
116
+ * Check if username is set
116
117
  */
117
- private restoreSession;
118
- /**
119
- * Open social action popup
120
- */
121
- open(options: OpenOptions): Promise<void>;
122
- /**
123
- * Verify follow status (for Pro/Business tiers with OAuth)
124
- */
125
- verify(options: OpenOptions): Promise<boolean>;
126
- /**
127
- * Track analytics event
128
- */
129
- private trackEvent;
118
+ hasUsername(): boolean;
130
119
  /**
131
- * Register event listener
120
+ * Clear stored session
132
121
  */
122
+ reset(): void;
123
+ getFollowUrl(platform: Platform, target: string): string;
124
+ getRepostUrl(platform: Platform, target: string): string;
125
+ getLikeUrl(platform: Platform, target: string): string;
126
+ openIntent(options: CompleteOptions): Promise<void>;
127
+ complete(options: CompleteOptions): Promise<void>;
128
+ unlock(): Promise<void>;
129
+ isUnlocked(): boolean;
130
+ getUnlockStatus(): UnlockStatus;
131
+ getCompletedActions(): CompleteOptions[];
133
132
  on(event: EventType, callback: EventCallback): void;
134
- /**
135
- * Remove event listener
136
- */
137
133
  off(event: EventType, callback: EventCallback): void;
138
- /**
139
- * Build intent URL for platform
140
- */
134
+ private restoreSession;
135
+ private saveCompletedActions;
141
136
  private buildIntentUrl;
142
137
  private buildTwitterUrl;
143
138
  private buildBlueskyUrl;
144
139
  private buildLinkedInUrl;
140
+ private trackEvent;
145
141
  private emit;
146
142
  }
147
143
  declare const FollowGate: FollowGateClient;
148
144
 
149
- export { type AuthOptions, type AuthenticatedUser, type EventCallback, type EventType, FollowGate, FollowGateClient, type FollowGateConfig, FollowGateError, type LinkedInTargetType, type OpenOptions, type PendingUsernameState, type Platform, type SocialAction };
145
+ export { type CompleteOptions, type EventCallback, type EventType, FollowGate, FollowGateClient, type FollowGateConfig, FollowGateError, type Platform, type SocialAction, type TwitterConfig, type UnlockStatus, type UserInfo };
package/dist/index.d.ts CHANGED
@@ -6,6 +6,13 @@ type Platform = 'twitter' | 'bluesky' | 'linkedin';
6
6
  * Supported social actions
7
7
  */
8
8
  type SocialAction = 'follow' | 'repost' | 'like';
9
+ /**
10
+ * Twitter/X configuration
11
+ */
12
+ interface TwitterConfig {
13
+ handle: string;
14
+ tweetId?: string;
15
+ }
9
16
  /**
10
17
  * SDK Configuration
11
18
  */
@@ -14,6 +21,10 @@ interface FollowGateConfig {
14
21
  apiKey: string;
15
22
  apiUrl?: string;
16
23
  debug?: boolean;
24
+ twitter?: TwitterConfig;
25
+ onComplete?: () => void;
26
+ theme?: 'dark' | 'light';
27
+ accentColor?: string;
17
28
  }
18
29
  /**
19
30
  * SDK Error class with helpful messages
@@ -24,49 +35,35 @@ declare class FollowGateError extends Error {
24
35
  constructor(message: string, code: string, hint?: string | undefined);
25
36
  }
26
37
  /**
27
- * Open action options
38
+ * Complete action options
28
39
  */
29
- interface OpenOptions {
40
+ interface CompleteOptions {
30
41
  platform: Platform;
31
42
  action: SocialAction;
32
43
  target: string;
33
- userId?: string;
34
44
  }
35
- /**
36
- * LinkedIn target type
37
- */
38
- type LinkedInTargetType = 'company' | 'profile';
39
45
  /**
40
46
  * Event types
41
47
  */
42
- type EventType = 'complete' | 'error' | 'cancel' | 'authenticated';
48
+ type EventType = 'complete' | 'error' | 'unlocked';
43
49
  /**
44
50
  * Event callback
45
51
  */
46
52
  type EventCallback = (data: unknown) => void;
47
53
  /**
48
- * Authenticated user info
54
+ * User info (stored locally)
49
55
  */
50
- interface AuthenticatedUser {
51
- userId: string;
56
+ interface UserInfo {
52
57
  username: string;
53
58
  platform: Platform;
54
59
  }
55
60
  /**
56
- * Auth state when username input is needed
57
- */
58
- interface PendingUsernameState {
59
- needsUsername: true;
60
- token: string;
61
- }
62
- /**
63
- * Authentication options
61
+ * Unlock status
64
62
  */
65
- interface AuthOptions {
66
- /** Where to redirect after auth (defaults to current page) */
67
- redirectUri?: string;
68
- /** Open in popup instead of redirect */
69
- popup?: boolean;
63
+ interface UnlockStatus {
64
+ unlocked: boolean;
65
+ username?: string;
66
+ completedActions?: CompleteOptions[];
70
67
  }
71
68
  /**
72
69
  * FollowGate SDK Client
@@ -75,75 +72,74 @@ declare class FollowGateClient {
75
72
  private config;
76
73
  private listeners;
77
74
  private currentUser;
78
- private authToken;
79
- private pendingUsername;
75
+ private completedActions;
76
+ private modalElement;
77
+ private stylesInjected;
80
78
  /**
81
79
  * Initialize the SDK
82
- * @throws {FollowGateError} If configuration is invalid
83
80
  */
84
81
  init(config: FollowGateConfig): void;
85
82
  /**
86
- * Authenticate user via Twitter OAuth (handled by FollowGate)
87
- * This identifies WHO is completing the social actions.
88
- */
89
- authenticate(options?: AuthOptions): void;
90
- /**
91
- * Get current authenticated user
92
- */
93
- getUser(): AuthenticatedUser | null;
94
- /**
95
- * Check if user is authenticated
96
- */
97
- isAuthenticated(): boolean;
98
- /**
99
- * Logout - clear stored session
83
+ * Show the FollowGate modal
84
+ * If user is already unlocked, calls onComplete immediately
100
85
  */
101
- logout(): void;
86
+ show(): void;
102
87
  /**
103
- * Check if username input is needed (Twitter Free Tier limitation)
88
+ * Hide the modal
104
89
  */
105
- needsUsernameInput(): boolean;
90
+ hide(): void;
91
+ private injectStyles;
92
+ private createModal;
93
+ private getContentElement;
94
+ private renderUsernameStep;
95
+ private handleUsernameSubmit;
96
+ private renderFollowStep;
97
+ private handleFollowClick;
98
+ private showFollowConfirmation;
99
+ private handleFollowConfirm;
100
+ private renderRepostStep;
101
+ private handleRepostClick;
102
+ private showRepostConfirmation;
103
+ private handleRepostConfirm;
104
+ private renderConfirmStep;
105
+ private handleFinish;
106
+ private renderStepIndicator;
106
107
  /**
107
- * Set username manually (when needsUsernameInput() returns true)
108
+ * Set the user's social username
108
109
  */
109
- setUsername(username: string): void;
110
+ setUsername(username: string, platform?: Platform): void;
110
111
  /**
111
- * Handle auth callback from URL params
112
+ * Get current user
112
113
  */
113
- private handleAuthCallback;
114
+ getUser(): UserInfo | null;
114
115
  /**
115
- * Restore session from localStorage
116
+ * Check if username is set
116
117
  */
117
- private restoreSession;
118
- /**
119
- * Open social action popup
120
- */
121
- open(options: OpenOptions): Promise<void>;
122
- /**
123
- * Verify follow status (for Pro/Business tiers with OAuth)
124
- */
125
- verify(options: OpenOptions): Promise<boolean>;
126
- /**
127
- * Track analytics event
128
- */
129
- private trackEvent;
118
+ hasUsername(): boolean;
130
119
  /**
131
- * Register event listener
120
+ * Clear stored session
132
121
  */
122
+ reset(): void;
123
+ getFollowUrl(platform: Platform, target: string): string;
124
+ getRepostUrl(platform: Platform, target: string): string;
125
+ getLikeUrl(platform: Platform, target: string): string;
126
+ openIntent(options: CompleteOptions): Promise<void>;
127
+ complete(options: CompleteOptions): Promise<void>;
128
+ unlock(): Promise<void>;
129
+ isUnlocked(): boolean;
130
+ getUnlockStatus(): UnlockStatus;
131
+ getCompletedActions(): CompleteOptions[];
133
132
  on(event: EventType, callback: EventCallback): void;
134
- /**
135
- * Remove event listener
136
- */
137
133
  off(event: EventType, callback: EventCallback): void;
138
- /**
139
- * Build intent URL for platform
140
- */
134
+ private restoreSession;
135
+ private saveCompletedActions;
141
136
  private buildIntentUrl;
142
137
  private buildTwitterUrl;
143
138
  private buildBlueskyUrl;
144
139
  private buildLinkedInUrl;
140
+ private trackEvent;
145
141
  private emit;
146
142
  }
147
143
  declare const FollowGate: FollowGateClient;
148
144
 
149
- export { type AuthOptions, type AuthenticatedUser, type EventCallback, type EventType, FollowGate, FollowGateClient, type FollowGateConfig, FollowGateError, type LinkedInTargetType, type OpenOptions, type PendingUsernameState, type Platform, type SocialAction };
145
+ export { type CompleteOptions, type EventCallback, type EventType, FollowGate, FollowGateClient, type FollowGateConfig, FollowGateError, type Platform, type SocialAction, type TwitterConfig, type UnlockStatus, type UserInfo };