@growth-rail/core 2.1.0 → 2.2.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/CHANGELOG.md +12 -0
- package/README.md +2 -2
- package/dist/index.d.mts +121 -11
- package/dist/index.d.ts +121 -11
- package/dist/index.js +16 -17
- package/dist/index.mjs +15 -16
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -27,13 +27,13 @@ pnpm add @growth-rail/core
|
|
|
27
27
|
|
|
28
28
|
### Initialization
|
|
29
29
|
|
|
30
|
-
Initialize the singleton instance with your
|
|
30
|
+
Initialize the singleton instance with your Project Secret Key.
|
|
31
31
|
|
|
32
32
|
```typescript
|
|
33
33
|
import { GrowthRail } from '@growth-rail/core';
|
|
34
34
|
|
|
35
35
|
GrowthRail.init({
|
|
36
|
-
|
|
36
|
+
projectSecretKey: 'your_project_secret_key_here'
|
|
37
37
|
});
|
|
38
38
|
|
|
39
39
|
// Initialize a user session
|
package/dist/index.d.mts
CHANGED
|
@@ -1,63 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration options for initializing the GrowthRail SDK.
|
|
3
|
+
*/
|
|
1
4
|
type GrowthRailOptions = {
|
|
2
|
-
|
|
5
|
+
/** The project secret key for your GrowthRail project. */
|
|
6
|
+
projectSecretKey: string;
|
|
7
|
+
/** The domain to set cookies on. Defaults to the current domain. */
|
|
3
8
|
cookieDomain?: string;
|
|
9
|
+
/** Whether to automatically track page views. */
|
|
4
10
|
autoPageTrack?: boolean;
|
|
5
11
|
};
|
|
12
|
+
/**
|
|
13
|
+
* Information about the current application user.
|
|
14
|
+
*/
|
|
6
15
|
type AppUserType = {
|
|
16
|
+
/** Custom attributes associated with the user. */
|
|
7
17
|
attributes: Record<string, unknown>;
|
|
18
|
+
/** When the user was first seen by GrowthRail. */
|
|
8
19
|
firstSeenAt: string;
|
|
20
|
+
/** When the user was last seen by GrowthRail. */
|
|
9
21
|
lastSeenAt: string | null;
|
|
22
|
+
/** The unique identifier for the user. */
|
|
10
23
|
uniqueId: string;
|
|
24
|
+
/** The user's unique referral code. */
|
|
11
25
|
referralCode: string;
|
|
26
|
+
/** The user's unique referral link. */
|
|
12
27
|
referralLink: string;
|
|
28
|
+
/** Configuration for the referral experience (trigger button and modal). */
|
|
13
29
|
referrerExperience: ReferrerExperience;
|
|
14
30
|
};
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
31
|
+
/**
|
|
32
|
+
* Referral link information.
|
|
33
|
+
*/
|
|
18
34
|
type ReferralLink = {
|
|
19
35
|
referralCode: string;
|
|
20
36
|
referralLink: string;
|
|
21
37
|
};
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
properties?: Record<string, any>;
|
|
26
|
-
timestamp: string;
|
|
27
|
-
};
|
|
38
|
+
/**
|
|
39
|
+
* Response from tracking a referral.
|
|
40
|
+
*/
|
|
28
41
|
type TrackReferralResponse = {
|
|
42
|
+
/** The ID used to track this referral conversion. */
|
|
29
43
|
referralTrackingId: string;
|
|
44
|
+
/** Recommended promotional text to display to the new user. */
|
|
30
45
|
promotionalText: string;
|
|
31
46
|
};
|
|
47
|
+
/** Position options for the floating trigger button. */
|
|
32
48
|
type TriggerButtonPosition = 'bottom-right' | 'bottom-left' | 'top-right' | 'top-left';
|
|
49
|
+
/**
|
|
50
|
+
* Configuration for the referral trigger button.
|
|
51
|
+
*/
|
|
33
52
|
type ReferrerTriggerButton = {
|
|
53
|
+
/** Whether to show the button. */
|
|
34
54
|
show: boolean;
|
|
55
|
+
/** Where to position the button on the screen. */
|
|
35
56
|
position: TriggerButtonPosition;
|
|
57
|
+
/** How the button is displayed (floating or attached to the edge). */
|
|
36
58
|
displayMode: 'floating' | 'edge';
|
|
37
59
|
};
|
|
60
|
+
/**
|
|
61
|
+
* Configuration for the referral dashboard / modal.
|
|
62
|
+
*/
|
|
38
63
|
type ReferrerModalOptions = {
|
|
64
|
+
/** Title of the referral modal. */
|
|
39
65
|
title: string;
|
|
66
|
+
/** Description or call to action in the modal. */
|
|
40
67
|
description: string;
|
|
68
|
+
/** Type of component to use (modal or drawer). */
|
|
41
69
|
componentType: 'modal' | 'drawer';
|
|
70
|
+
/** Theme overrides for the modal. */
|
|
42
71
|
theme: {
|
|
72
|
+
/** Primary brand color. */
|
|
43
73
|
primaryColor: string;
|
|
74
|
+
/** Color for the background overlay. */
|
|
44
75
|
tintColor: string;
|
|
76
|
+
/** Alpha transparency for the tint (0-1). */
|
|
45
77
|
tintAlpha: number;
|
|
78
|
+
/** Background color of the modal content. */
|
|
46
79
|
backgroundColor: string;
|
|
47
80
|
};
|
|
48
81
|
};
|
|
82
|
+
/**
|
|
83
|
+
* Full configuration for a user's referral experience.
|
|
84
|
+
*/
|
|
49
85
|
interface ReferrerExperience {
|
|
86
|
+
/** Trigger button configuration. */
|
|
50
87
|
trigger: ReferrerTriggerButton;
|
|
88
|
+
/** Referral modal configuration. */
|
|
51
89
|
modal: ReferrerModalOptions;
|
|
52
90
|
}
|
|
91
|
+
/**
|
|
92
|
+
* Configuration for the experience shown to a new (referred) user.
|
|
93
|
+
*/
|
|
53
94
|
interface NewUserExperience {
|
|
54
95
|
banner: {
|
|
96
|
+
/** Whether to show a promotional banner. */
|
|
55
97
|
show: boolean;
|
|
98
|
+
/** Position of the banner. */
|
|
56
99
|
position: 'center-top' | 'center-bottom' | 'left-top' | 'left-bottom' | 'right-top' | 'right-bottom';
|
|
100
|
+
/** Text to display on the banner. */
|
|
57
101
|
text: string;
|
|
102
|
+
/** Theme color for the banner. */
|
|
103
|
+
themeColor: string;
|
|
58
104
|
};
|
|
59
105
|
}
|
|
60
106
|
|
|
107
|
+
/**
|
|
108
|
+
* The main entry point for the GrowthRail SDK.
|
|
109
|
+
* Use this class to initialize the SDK, track users, and show the referral dashboard.
|
|
110
|
+
*/
|
|
61
111
|
declare class GrowthRail {
|
|
62
112
|
private static api;
|
|
63
113
|
private static storage;
|
|
@@ -70,22 +120,82 @@ declare class GrowthRail {
|
|
|
70
120
|
private static userReadyPromise;
|
|
71
121
|
private static userReadyResolver;
|
|
72
122
|
private constructor();
|
|
123
|
+
/**
|
|
124
|
+
* Initializes the GrowthRail SDK with the provided options.
|
|
125
|
+
* This should be called once, typically at the root of your application.
|
|
126
|
+
*
|
|
127
|
+
* @param options - Configuration options for the SDK.
|
|
128
|
+
*/
|
|
73
129
|
static init(options: GrowthRailOptions): void;
|
|
130
|
+
/**
|
|
131
|
+
* Returns whether the SDK has been initialized.
|
|
132
|
+
*/
|
|
74
133
|
static isInitialized(): boolean;
|
|
75
134
|
private static ensureInitialized;
|
|
76
135
|
private static loadReferrerExperience;
|
|
77
136
|
private static createReferralModal;
|
|
78
137
|
private static autoTrackReferral;
|
|
138
|
+
/**
|
|
139
|
+
* Initializes the current user within the GrowthRail system.
|
|
140
|
+
* This is required before showing the referral dashboard or tracking reward events.
|
|
141
|
+
*
|
|
142
|
+
* @param clientProvidedId - A unique ID for the user from your system (e.g., database ID or email).
|
|
143
|
+
* @returns A promise that resolves to the initialized user's data.
|
|
144
|
+
*/
|
|
79
145
|
static initAppUser(clientProvidedId: string): Promise<AppUserType>;
|
|
146
|
+
/**
|
|
147
|
+
* Manually tracks a referral click.
|
|
148
|
+
* Note: The SDK automatically tracks referrals if a `referralCode` is present in the URL.
|
|
149
|
+
*
|
|
150
|
+
* @param referralCode - The referral code to track.
|
|
151
|
+
* @param rewardEventName - Optional name of the event that should trigger a reward.
|
|
152
|
+
* @returns A promise resolving to the tracking response.
|
|
153
|
+
*/
|
|
80
154
|
static trackReferral(referralCode: string, rewardEventName?: string): Promise<TrackReferralResponse>;
|
|
155
|
+
/**
|
|
156
|
+
* Tracks a reward event for the current user.
|
|
157
|
+
* Use this when a user completes an action that should satisfy a referral requirement.
|
|
158
|
+
*
|
|
159
|
+
* @param eventName - Optional specific event name to track.
|
|
160
|
+
*/
|
|
81
161
|
static trackRewardEvent(eventName?: string): Promise<void>;
|
|
162
|
+
/**
|
|
163
|
+
* Gets the referral link for the currently logged-in user.
|
|
164
|
+
*
|
|
165
|
+
* @throws Error if the user is not initialized.
|
|
166
|
+
*/
|
|
82
167
|
static getReferralLink(): string;
|
|
168
|
+
/**
|
|
169
|
+
* Gets the referral code for the currently logged-in user.
|
|
170
|
+
*/
|
|
83
171
|
static getReferralCode(): string | undefined;
|
|
172
|
+
/**
|
|
173
|
+
* Gets the unique ID for the currently logged-in user.
|
|
174
|
+
*/
|
|
84
175
|
static getUserId(): string | undefined;
|
|
176
|
+
/**
|
|
177
|
+
* Returns whether a user has been successfully initialized.
|
|
178
|
+
*/
|
|
85
179
|
static isUserReady(): boolean;
|
|
180
|
+
/**
|
|
181
|
+
* Returns a promise that resolves when the user is initialized and ready.
|
|
182
|
+
*/
|
|
86
183
|
static ensureUserReady(): Promise<AppUserType>;
|
|
184
|
+
/**
|
|
185
|
+
* Displays the referral dashboard (modal or drawer) to the user.
|
|
186
|
+
*
|
|
187
|
+
* @param options - Optional theme or content overrides for the dashboard.
|
|
188
|
+
*/
|
|
87
189
|
static showReferralDashboard(options?: Partial<ReferrerModalOptions>): Promise<void>;
|
|
190
|
+
/**
|
|
191
|
+
* Manually creates or updates the floating trigger button.
|
|
192
|
+
*
|
|
193
|
+
* @param options - Configuration options for the trigger button.
|
|
194
|
+
*/
|
|
88
195
|
static createTriggerButton(options: Partial<ReferrerTriggerButton>): void;
|
|
196
|
+
/**
|
|
197
|
+
* Removes the floating trigger button from the screen.
|
|
198
|
+
*/
|
|
89
199
|
static destroyTriggerButton(): void;
|
|
90
200
|
}
|
|
91
201
|
|
|
@@ -111,4 +221,4 @@ declare class ReferralModal {
|
|
|
111
221
|
private bindEvents;
|
|
112
222
|
}
|
|
113
223
|
|
|
114
|
-
export { type AppUserType,
|
|
224
|
+
export { type AppUserType, GrowthRail, type GrowthRailOptions, type NewUserExperience, type ReferralLink, ReferralModal, type ReferralModalDependencies, type ReferrerExperience, type ReferrerModalOptions, type ReferrerTriggerButton, type TrackReferralResponse, type TriggerButtonPosition };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,63 +1,113 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration options for initializing the GrowthRail SDK.
|
|
3
|
+
*/
|
|
1
4
|
type GrowthRailOptions = {
|
|
2
|
-
|
|
5
|
+
/** The project secret key for your GrowthRail project. */
|
|
6
|
+
projectSecretKey: string;
|
|
7
|
+
/** The domain to set cookies on. Defaults to the current domain. */
|
|
3
8
|
cookieDomain?: string;
|
|
9
|
+
/** Whether to automatically track page views. */
|
|
4
10
|
autoPageTrack?: boolean;
|
|
5
11
|
};
|
|
12
|
+
/**
|
|
13
|
+
* Information about the current application user.
|
|
14
|
+
*/
|
|
6
15
|
type AppUserType = {
|
|
16
|
+
/** Custom attributes associated with the user. */
|
|
7
17
|
attributes: Record<string, unknown>;
|
|
18
|
+
/** When the user was first seen by GrowthRail. */
|
|
8
19
|
firstSeenAt: string;
|
|
20
|
+
/** When the user was last seen by GrowthRail. */
|
|
9
21
|
lastSeenAt: string | null;
|
|
22
|
+
/** The unique identifier for the user. */
|
|
10
23
|
uniqueId: string;
|
|
24
|
+
/** The user's unique referral code. */
|
|
11
25
|
referralCode: string;
|
|
26
|
+
/** The user's unique referral link. */
|
|
12
27
|
referralLink: string;
|
|
28
|
+
/** Configuration for the referral experience (trigger button and modal). */
|
|
13
29
|
referrerExperience: ReferrerExperience;
|
|
14
30
|
};
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
31
|
+
/**
|
|
32
|
+
* Referral link information.
|
|
33
|
+
*/
|
|
18
34
|
type ReferralLink = {
|
|
19
35
|
referralCode: string;
|
|
20
36
|
referralLink: string;
|
|
21
37
|
};
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
properties?: Record<string, any>;
|
|
26
|
-
timestamp: string;
|
|
27
|
-
};
|
|
38
|
+
/**
|
|
39
|
+
* Response from tracking a referral.
|
|
40
|
+
*/
|
|
28
41
|
type TrackReferralResponse = {
|
|
42
|
+
/** The ID used to track this referral conversion. */
|
|
29
43
|
referralTrackingId: string;
|
|
44
|
+
/** Recommended promotional text to display to the new user. */
|
|
30
45
|
promotionalText: string;
|
|
31
46
|
};
|
|
47
|
+
/** Position options for the floating trigger button. */
|
|
32
48
|
type TriggerButtonPosition = 'bottom-right' | 'bottom-left' | 'top-right' | 'top-left';
|
|
49
|
+
/**
|
|
50
|
+
* Configuration for the referral trigger button.
|
|
51
|
+
*/
|
|
33
52
|
type ReferrerTriggerButton = {
|
|
53
|
+
/** Whether to show the button. */
|
|
34
54
|
show: boolean;
|
|
55
|
+
/** Where to position the button on the screen. */
|
|
35
56
|
position: TriggerButtonPosition;
|
|
57
|
+
/** How the button is displayed (floating or attached to the edge). */
|
|
36
58
|
displayMode: 'floating' | 'edge';
|
|
37
59
|
};
|
|
60
|
+
/**
|
|
61
|
+
* Configuration for the referral dashboard / modal.
|
|
62
|
+
*/
|
|
38
63
|
type ReferrerModalOptions = {
|
|
64
|
+
/** Title of the referral modal. */
|
|
39
65
|
title: string;
|
|
66
|
+
/** Description or call to action in the modal. */
|
|
40
67
|
description: string;
|
|
68
|
+
/** Type of component to use (modal or drawer). */
|
|
41
69
|
componentType: 'modal' | 'drawer';
|
|
70
|
+
/** Theme overrides for the modal. */
|
|
42
71
|
theme: {
|
|
72
|
+
/** Primary brand color. */
|
|
43
73
|
primaryColor: string;
|
|
74
|
+
/** Color for the background overlay. */
|
|
44
75
|
tintColor: string;
|
|
76
|
+
/** Alpha transparency for the tint (0-1). */
|
|
45
77
|
tintAlpha: number;
|
|
78
|
+
/** Background color of the modal content. */
|
|
46
79
|
backgroundColor: string;
|
|
47
80
|
};
|
|
48
81
|
};
|
|
82
|
+
/**
|
|
83
|
+
* Full configuration for a user's referral experience.
|
|
84
|
+
*/
|
|
49
85
|
interface ReferrerExperience {
|
|
86
|
+
/** Trigger button configuration. */
|
|
50
87
|
trigger: ReferrerTriggerButton;
|
|
88
|
+
/** Referral modal configuration. */
|
|
51
89
|
modal: ReferrerModalOptions;
|
|
52
90
|
}
|
|
91
|
+
/**
|
|
92
|
+
* Configuration for the experience shown to a new (referred) user.
|
|
93
|
+
*/
|
|
53
94
|
interface NewUserExperience {
|
|
54
95
|
banner: {
|
|
96
|
+
/** Whether to show a promotional banner. */
|
|
55
97
|
show: boolean;
|
|
98
|
+
/** Position of the banner. */
|
|
56
99
|
position: 'center-top' | 'center-bottom' | 'left-top' | 'left-bottom' | 'right-top' | 'right-bottom';
|
|
100
|
+
/** Text to display on the banner. */
|
|
57
101
|
text: string;
|
|
102
|
+
/** Theme color for the banner. */
|
|
103
|
+
themeColor: string;
|
|
58
104
|
};
|
|
59
105
|
}
|
|
60
106
|
|
|
107
|
+
/**
|
|
108
|
+
* The main entry point for the GrowthRail SDK.
|
|
109
|
+
* Use this class to initialize the SDK, track users, and show the referral dashboard.
|
|
110
|
+
*/
|
|
61
111
|
declare class GrowthRail {
|
|
62
112
|
private static api;
|
|
63
113
|
private static storage;
|
|
@@ -70,22 +120,82 @@ declare class GrowthRail {
|
|
|
70
120
|
private static userReadyPromise;
|
|
71
121
|
private static userReadyResolver;
|
|
72
122
|
private constructor();
|
|
123
|
+
/**
|
|
124
|
+
* Initializes the GrowthRail SDK with the provided options.
|
|
125
|
+
* This should be called once, typically at the root of your application.
|
|
126
|
+
*
|
|
127
|
+
* @param options - Configuration options for the SDK.
|
|
128
|
+
*/
|
|
73
129
|
static init(options: GrowthRailOptions): void;
|
|
130
|
+
/**
|
|
131
|
+
* Returns whether the SDK has been initialized.
|
|
132
|
+
*/
|
|
74
133
|
static isInitialized(): boolean;
|
|
75
134
|
private static ensureInitialized;
|
|
76
135
|
private static loadReferrerExperience;
|
|
77
136
|
private static createReferralModal;
|
|
78
137
|
private static autoTrackReferral;
|
|
138
|
+
/**
|
|
139
|
+
* Initializes the current user within the GrowthRail system.
|
|
140
|
+
* This is required before showing the referral dashboard or tracking reward events.
|
|
141
|
+
*
|
|
142
|
+
* @param clientProvidedId - A unique ID for the user from your system (e.g., database ID or email).
|
|
143
|
+
* @returns A promise that resolves to the initialized user's data.
|
|
144
|
+
*/
|
|
79
145
|
static initAppUser(clientProvidedId: string): Promise<AppUserType>;
|
|
146
|
+
/**
|
|
147
|
+
* Manually tracks a referral click.
|
|
148
|
+
* Note: The SDK automatically tracks referrals if a `referralCode` is present in the URL.
|
|
149
|
+
*
|
|
150
|
+
* @param referralCode - The referral code to track.
|
|
151
|
+
* @param rewardEventName - Optional name of the event that should trigger a reward.
|
|
152
|
+
* @returns A promise resolving to the tracking response.
|
|
153
|
+
*/
|
|
80
154
|
static trackReferral(referralCode: string, rewardEventName?: string): Promise<TrackReferralResponse>;
|
|
155
|
+
/**
|
|
156
|
+
* Tracks a reward event for the current user.
|
|
157
|
+
* Use this when a user completes an action that should satisfy a referral requirement.
|
|
158
|
+
*
|
|
159
|
+
* @param eventName - Optional specific event name to track.
|
|
160
|
+
*/
|
|
81
161
|
static trackRewardEvent(eventName?: string): Promise<void>;
|
|
162
|
+
/**
|
|
163
|
+
* Gets the referral link for the currently logged-in user.
|
|
164
|
+
*
|
|
165
|
+
* @throws Error if the user is not initialized.
|
|
166
|
+
*/
|
|
82
167
|
static getReferralLink(): string;
|
|
168
|
+
/**
|
|
169
|
+
* Gets the referral code for the currently logged-in user.
|
|
170
|
+
*/
|
|
83
171
|
static getReferralCode(): string | undefined;
|
|
172
|
+
/**
|
|
173
|
+
* Gets the unique ID for the currently logged-in user.
|
|
174
|
+
*/
|
|
84
175
|
static getUserId(): string | undefined;
|
|
176
|
+
/**
|
|
177
|
+
* Returns whether a user has been successfully initialized.
|
|
178
|
+
*/
|
|
85
179
|
static isUserReady(): boolean;
|
|
180
|
+
/**
|
|
181
|
+
* Returns a promise that resolves when the user is initialized and ready.
|
|
182
|
+
*/
|
|
86
183
|
static ensureUserReady(): Promise<AppUserType>;
|
|
184
|
+
/**
|
|
185
|
+
* Displays the referral dashboard (modal or drawer) to the user.
|
|
186
|
+
*
|
|
187
|
+
* @param options - Optional theme or content overrides for the dashboard.
|
|
188
|
+
*/
|
|
87
189
|
static showReferralDashboard(options?: Partial<ReferrerModalOptions>): Promise<void>;
|
|
190
|
+
/**
|
|
191
|
+
* Manually creates or updates the floating trigger button.
|
|
192
|
+
*
|
|
193
|
+
* @param options - Configuration options for the trigger button.
|
|
194
|
+
*/
|
|
88
195
|
static createTriggerButton(options: Partial<ReferrerTriggerButton>): void;
|
|
196
|
+
/**
|
|
197
|
+
* Removes the floating trigger button from the screen.
|
|
198
|
+
*/
|
|
89
199
|
static destroyTriggerButton(): void;
|
|
90
200
|
}
|
|
91
201
|
|
|
@@ -111,4 +221,4 @@ declare class ReferralModal {
|
|
|
111
221
|
private bindEvents;
|
|
112
222
|
}
|
|
113
223
|
|
|
114
|
-
export { type AppUserType,
|
|
224
|
+
export { type AppUserType, GrowthRail, type GrowthRailOptions, type NewUserExperience, type ReferralLink, ReferralModal, type ReferralModalDependencies, type ReferrerExperience, type ReferrerModalOptions, type ReferrerTriggerButton, type TrackReferralResponse, type TriggerButtonPosition };
|
package/dist/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
"use strict";var b=Object.defineProperty;var C=Object.getOwnPropertyDescriptor;var T=Object.getOwnPropertyNames;var P=Object.prototype.hasOwnProperty;var z=(p,e,r)=>e in p?b(p,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):p[e]=r;var U=(p,e)=>{for(var r in e)b(p,r,{get:e[r],enumerable:!0})},M=(p,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of T(e))!P.call(p,i)&&i!==r&&b(p,i,{get:()=>e[i],enumerable:!(n=C(e,i))||n.enumerable});return p};var L=p=>M(b({},"__esModule",{value:!0}),p);var a=(p,e,r)=>z(p,typeof e!="symbol"?e+"":e,r);var A={};U(A,{GrowthRail:()=>x,ReferralModal:()=>m});module.exports=L(A);var y=class{constructor(e){a(this,"baseUrl");a(this,"apiKey");let r=typeof process<"u"&&process.env?.ENV_BASE_URL;this.baseUrl=r||"https://api.growthrail.dev",this.apiKey=e.apiKey}async request(e,r,n){let i={"Content-Type":"application/json","X-GrowthRail-ProjectSecret":this.apiKey};try{let o=await fetch(`${this.baseUrl}${e}`,{method:r,headers:i,body:n?JSON.stringify(n):void 0});if(!o.ok)throw new Error(`GrowthRail API Error: ${o.statusText}`);return o.json()}catch(o){throw console.error("GrowthRail SDK Error:",o),o}}async getNewUserExperience(){return this.request("/api/v1/sdk/new-user-experience","POST")}async initAppUser(e){return this.request("/api/v1/sdk/init-app-user","POST",{clientProvidedId:e})}async createReferralLink(e,r){return this.request("/api/v1/sdk/create-referral-link","POST",{referrerId:e,rewardEventName:r})}async trackReferral(e,r){return this.request("/api/v1/sdk/track-referral","POST",{referralCode:e,rewardEventName:r})}async trackRewardEvent(e,r,n){return this.request("/api/v1/sdk/track-reward-event","POST",{refereeId:e,referralTrackingId:r,eventName:n})}};var u=class u{constructor(e){a(this,"options",{});e&&(this.options=e)}setCookie(e,r,n=30){if(typeof document>"u")return;let i="";if(n){let s=new Date;s.setTime(s.getTime()+n*24*60*60*1e3),i=`; expires=${s.toUTCString()}`}let o="";this.options.cookieDomain&&(o=`; domain=${this.options.cookieDomain}`),document.cookie=`${e}=${r||""}${i}${o}; path=/; SameSite=Lax`}getCookie(e){if(typeof document>"u")return null;let r=`${e}=`,n=document.cookie.split(";");for(let i=0;i<n.length;i++){let o=n[i];for(;o.charAt(0)===" ";)o=o.substring(1,o.length);if(o.indexOf(r)===0)return o.substring(r.length,o.length)}return null}getReferralCode(){return this.getCookie(u.REFERRAL_CODE_KEY)}setReferralCode(e){this.setCookie(u.REFERRAL_CODE_KEY,e,30)}setTrackedReferral(e){this.setCookie(u.TRACKED_REFERRAL_KEY,e,30)}getTrackedReferral(){return this.getCookie(u.TRACKED_REFERRAL_KEY)}};a(u,"REFERRAL_CODE_KEY","gr_ref_code"),a(u,"TRACKED_REFERRAL_KEY","gr_tracked_referral");var v=u;var m=class{constructor(e,r){a(this,"referrerExperience");a(this,"deps");a(this,"host",null);a(this,"shadow",null);a(this,"overlay",null);a(this,"content",null);this.deps=e,this.referrerExperience=r}show(e,r){this.host||(this.createDom(e,r),this.bindEvents(),r||(document.body.style.overflow="hidden"))}hide(){this.host&&(this.host&&this.host.parentNode&&this.host.parentNode.removeChild(this.host),this.host=null,this.overlay=null,this.content=null,this.shadow=null,document.body.style.overflow="")}createDom(e,r){let n={...this.referrerExperience,modal:{...this.referrerExperience.modal,...e??{},theme:{...this.referrerExperience.modal?.theme,...e?.theme??{}}}},i=this.getTheme(),o={...i,colorPrimary:n.modal?.theme?.primaryColor||i.colorPrimary,colorBackground:n.modal?.theme?.backgroundColor||i.colorBackground,colorTint:n.modal?.theme?.tintColor||i.colorTint,tintAlpha:n.modal?.theme?.tintAlpha??i.tintAlpha},s=!!r;this.host=document.createElement("div"),this.host.style.all="initial",s?(this.host.style.display="block",this.host.style.width="100%",this.host.style.height="100%"):(this.host.style.position="absolute",this.host.style.zIndex="2147483647"),this.host.id="growth-rail-modal-host",this.host.style.setProperty("--gr-primary",o.colorPrimary),this.host.style.setProperty("--gr-text",o.colorText),this.host.style.setProperty("--gr-text-secondary",o.colorTextSecondary),this.host.style.setProperty("--gr-bg",o.colorBackground),this.host.style.setProperty("--gr-tint",o.colorTint);let l=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(o.colorTint),d=o.tintAlpha>1?o.tintAlpha/100:o.tintAlpha,c=l?`rgba(${parseInt(l[1],16)}, ${parseInt(l[2],16)}, ${parseInt(l[3],16)}, ${d})`:`rgba(0, 0, 0, ${d})`;this.host.style.setProperty("--gr-tint-rgba",c),this.host.style.setProperty("--gr-surface",o.colorSurface),this.host.style.setProperty("--gr-border",o.colorBorder),this.host.style.setProperty("--gr-error",o.colorError),this.host.style.setProperty("--gr-radius",o.borderRadius),this.host.style.setProperty("--gr-font",'Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif'),this.shadow=this.host.attachShadow({mode:"open"});let h=document.createElement("style");h.textContent=":host{all:initial;display:block}*{box-sizing:border-box}@keyframes gr-fade-in{from{opacity:0}to{opacity:1}}@keyframes gr-slide-up{from{opacity:0;transform:translateY(20px) scale(.98)}to{opacity:1;transform:translateY(0) scale(1)}}@keyframes gr-slide-in-right{from{opacity:0;transform:translateX(100%)}to{opacity:1;transform:translateX(0)}}@keyframes gr-slide-in-left{from{opacity:0;transform:translateX(-100%)}to{opacity:1;transform:translateX(0)}}.gr-overlay{position:fixed;top:0;left:0;width:100vw;height:100vh;display:flex;z-index:2147483647;font-family:var(--gr-font);animation:gr-fade-in .2s ease-out forwards;backdrop-filter:blur(4px);background-color:var(--gr-tint-rgba)}.gr-overlay--modal{align-items:center;justify-content:center}.gr-overlay--drawer{align-items:flex-start;justify-content:flex-start}.gr-container{position:relative;background-color:var(--gr-bg);color:var(--gr-text);padding:32px;box-shadow:0 0 50px -12px rgba(0,0,0,0.25), 0 0 30px -10px rgba(0,0,0,0.15)}.gr-container--embedded{width:100%;height:100%;box-shadow:none;border:1px solid var(--gr-border);border-radius:var(--gr-radius)}.gr-container--modal{width:90%;max-width:480px;border-radius:var(--gr-radius);animation:gr-slide-up .3s cubic-bezier(.16,1,.3,1) forwards}.gr-container--drawer{position:absolute;width:400px;max-width:calc(100vw - 20px);max-height:calc(100vh - 40px);overflow-y:auto}.gr-container--right{right:0;border-top-left-radius:var(--gr-radius);border-bottom-left-radius:var(--gr-radius);animation:gr-slide-in-right .3s cubic-bezier(.16,1,.3,1) forwards}.gr-container--left{left:0;border-top-right-radius:var(--gr-radius);border-bottom-right-radius:var(--gr-radius);animation:gr-slide-in-left .3s cubic-bezier(.16,1,.3,1) forwards}.gr-container--top{top:100px}.gr-container--bottom{bottom:100px}.gr-close-btn{position:absolute;top:20px;right:20px;background:0 0;border:none;cursor:pointer;color:#9ca3af;padding:4px;border-radius:50%;display:flex;align-items:center;justify-content:center;transition:all .2s}.gr-close-btn:hover{background-color:var(--gr-surface);color:var(--gr-text)}.gr-header{text-align:center;margin-bottom:28px}.gr-icon-lg{font-size:32px;margin-bottom:12px}.gr-title{margin:0 0 8px 0;font-size:22px;font-weight:700;letter-spacing:-.02em}.gr-subtitle{margin:0;font-size:14px;line-height:1.5;color:var(--gr-text-secondary)}.gr-loading{padding:16px;background-color:var(--gr-surface);border-radius:8px;text-align:center;color:var(--gr-text-secondary);font-size:14px}.gr-label{display:block;font-size:12px;font-weight:600;color:var(--gr-text-secondary);margin-bottom:8px;text-transform:uppercase;letter-spacing:.05em}.gr-share-label{text-align:center;margin-bottom:16px;font-size:13px;font-weight:500;color:var(--gr-text-secondary);display:flex;align-items:center;gap:12px}.gr-divider{flex:1;height:1px;background:var(--gr-border)}.gr-social-container{display:flex;gap:16px;justify-content:center;flex-wrap:wrap}.gr-btn{padding:14px;font-size:15px;font-weight:600;background-color:var(--gr-primary);color:#fff;border:none;border-radius:var(--gr-radius);cursor:pointer;transition:all .2s ease;text-align:center;width:100%;display:block}.gr-btn:hover{transform:translateY(-1px);filter:brightness(1.05)}.gr-btn:active{transform:translateY(0);filter:brightness(.95)}.gr-btn:disabled{opacity:.7;cursor:not-allowed}.gr-btn--sm{padding:8px 16px;font-size:13px;width:auto;border-radius:calc(var(--gr-radius) - 4px)}.gr-input-group{display:flex;align-items:center;background-color:var(--gr-surface);border:1px solid var(--gr-border);border-radius:var(--gr-radius);padding:4px;margin-bottom:24px}.gr-input-group:focus-within{border-color:var(--gr-primary);box-shadow:0 0 0 3px var(--gr-surface)}.gr-input{flex:1;padding:10px 12px;font-size:14px;border:none;background:0 0;color:var(--gr-text);outline:none;font-family:monospace}.gr-social-btn{display:flex;align-items:center;justify-content:center;width:42px;height:42px;border-radius:50%;background-color:var(--gr-surface);color:var(--gr-text-secondary);border:1px solid var(--gr-border);transition:transform .2s cubic-bezier(.34,1.56,.64,1);cursor:pointer}.gr-social-btn:hover{transform:scale(1.15) rotate(3deg);color:#fff}.gr-powered-by{margin-top:24px;text-align:center;font-size:11px;color:#9ca3af;display:flex;align-items:center;justify-content:center;gap:4px;opacity:.8}.gr-powered-by a{color:inherit;text-decoration:none;font-weight:600;transition:opacity .2s}.gr-powered-by a:hover{opacity:1;text-decoration:underline}",this.shadow.appendChild(h),this.content=document.createElement("div");let g=n.modal.componentType==="drawer",R=n.trigger.position||"top-right",f=["gr-container"];s?(f.push("gr-container--embedded"),this.content.className=f.join(" "),this.renderInternalContent(o,e,s),this.shadow.appendChild(this.content),r&&r.appendChild(this.host)):(this.overlay=document.createElement("div"),this.overlay.className=`gr-overlay ${g?"gr-overlay--drawer":"gr-overlay--modal"}`,g?(f.push("gr-container--drawer"),R.includes("right")?f.push("gr-container--right"):f.push("gr-container--left"),R.includes("bottom")?f.push("gr-container--bottom"):f.push("gr-container--top")):f.push("gr-container--modal"),this.content.className=f.join(" "),this.renderInternalContent(o,e,s),this.overlay.appendChild(this.content),this.shadow.appendChild(this.overlay),document.body.appendChild(this.host),this.overlay.onclick=E=>{E.target===this.overlay&&this.hide()})}getTheme(){return{colorPrimary:"#2563eb",colorText:"#111827",colorTextSecondary:"#6b7280",colorBackground:"#ffffff",colorTint:"#f9fafb",tintAlpha:.8,colorSurface:"#f9fafb",colorBorder:"#e5e7eb",colorError:"#ef4444",borderRadius:"16px"}}async renderInternalContent(e,r,n=!1){if(!this.content)return;if(this.content.innerHTML="",!n){let g=document.createElement("button");g.className="gr-close-btn",g.innerHTML=`
|
|
1
|
+
"use strict";var b=Object.defineProperty;var C=Object.getOwnPropertyDescriptor;var T=Object.getOwnPropertyNames;var z=Object.prototype.hasOwnProperty;var P=(p,e,t)=>e in p?b(p,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):p[e]=t;var M=(p,e)=>{for(var t in e)b(p,t,{get:e[t],enumerable:!0})},U=(p,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of T(e))!z.call(p,i)&&i!==t&&b(p,i,{get:()=>e[i],enumerable:!(n=C(e,i))||n.enumerable});return p};var L=p=>U(b({},"__esModule",{value:!0}),p);var a=(p,e,t)=>P(p,typeof e!="symbol"?e+"":e,t);var B={};M(B,{GrowthRail:()=>x,ReferralModal:()=>m});module.exports=L(B);var y=class{constructor(e){a(this,"baseUrl");a(this,"projectSecretKey");let t=typeof process<"u"&&process.env?.ENV_BASE_URL;this.baseUrl=t||"https://api.growthrail.dev",this.projectSecretKey=e.projectSecretKey}async request(e,t,n){let i={"Content-Type":"application/json","X-GrowthRail-ProjectSecret":this.projectSecretKey};try{let o=await fetch(`${this.baseUrl}${e}`,{method:t,headers:i,body:n?JSON.stringify(n):void 0});if(!o.ok)throw new Error(`GrowthRail API Error: ${o.statusText}`);return o.json()}catch(o){throw console.error("GrowthRail SDK Error:",o),o}}async getNewUserExperience(){return this.request("/api/v1/sdk/new-user-experience","POST")}async initAppUser(e){return this.request("/api/v1/sdk/init-app-user","POST",{clientProvidedId:e})}async trackReferral(e,t){return this.request("/api/v1/sdk/track-referral","POST",{referralCode:e,rewardEventName:t})}async trackRewardEvent(e,t,n){return this.request("/api/v1/sdk/track-reward-event","POST",{refereeId:e,referralTrackingId:t,eventName:n})}};var u=class u{constructor(e){a(this,"options",{});e&&(this.options=e)}setCookie(e,t,n=30){if(typeof document>"u")return;let i="";if(n){let s=new Date;s.setTime(s.getTime()+n*24*60*60*1e3),i=`; expires=${s.toUTCString()}`}let o="";this.options.cookieDomain&&(o=`; domain=${this.options.cookieDomain}`),document.cookie=`${e}=${t||""}${i}${o}; path=/; SameSite=Lax`}getCookie(e){if(typeof document>"u")return null;let t=`${e}=`,n=document.cookie.split(";");for(let i=0;i<n.length;i++){let o=n[i];for(;o.charAt(0)===" ";)o=o.substring(1,o.length);if(o.indexOf(t)===0)return o.substring(t.length,o.length)}return null}getReferralCode(){return this.getCookie(u.REFERRAL_CODE_KEY)}setReferralCode(e){this.setCookie(u.REFERRAL_CODE_KEY,e,30)}setTrackedReferral(e){this.setCookie(u.TRACKED_REFERRAL_KEY,e,30)}getTrackedReferral(){return this.getCookie(u.TRACKED_REFERRAL_KEY)}};a(u,"REFERRAL_CODE_KEY","gr_ref_code"),a(u,"TRACKED_REFERRAL_KEY","gr_tracked_referral");var v=u;var m=class{constructor(e,t){a(this,"referrerExperience");a(this,"deps");a(this,"host",null);a(this,"shadow",null);a(this,"overlay",null);a(this,"content",null);this.deps=e,this.referrerExperience=t}show(e,t){this.host||(this.createDom(e,t),this.bindEvents(),t||(document.body.style.overflow="hidden"))}hide(){this.host&&(this.host&&this.host.parentNode&&this.host.parentNode.removeChild(this.host),this.host=null,this.overlay=null,this.content=null,this.shadow=null,document.body.style.overflow="")}createDom(e,t){let n={...this.referrerExperience,modal:{...this.referrerExperience.modal,...e??{},theme:{...this.referrerExperience.modal?.theme,...e?.theme??{}}}},i=this.getTheme(),o={...i,colorPrimary:n.modal?.theme?.primaryColor||i.colorPrimary,colorBackground:n.modal?.theme?.backgroundColor||i.colorBackground,colorTint:n.modal?.theme?.tintColor||i.colorTint,tintAlpha:n.modal?.theme?.tintAlpha??i.tintAlpha},s=!!t;this.host=document.createElement("div"),this.host.style.all="initial",s?(this.host.style.display="block",this.host.style.width="100%",this.host.style.height="100%"):(this.host.style.position="absolute",this.host.style.zIndex="2147483647"),this.host.id="growth-rail-modal-host",this.host.style.setProperty("--gr-primary",o.colorPrimary),this.host.style.setProperty("--gr-text",o.colorText),this.host.style.setProperty("--gr-text-secondary",o.colorTextSecondary),this.host.style.setProperty("--gr-bg",o.colorBackground),this.host.style.setProperty("--gr-tint",o.colorTint);let l=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(o.colorTint),d=o.tintAlpha>1?o.tintAlpha/100:o.tintAlpha,c=l?`rgba(${parseInt(l[1],16)}, ${parseInt(l[2],16)}, ${parseInt(l[3],16)}, ${d})`:`rgba(0, 0, 0, ${d})`;this.host.style.setProperty("--gr-tint-rgba",c),this.host.style.setProperty("--gr-surface",o.colorSurface),this.host.style.setProperty("--gr-border",o.colorBorder),this.host.style.setProperty("--gr-error",o.colorError),this.host.style.setProperty("--gr-radius",o.borderRadius),this.host.style.setProperty("--gr-font",'Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif'),this.shadow=this.host.attachShadow({mode:"open"});let g=document.createElement("style");g.textContent=":host{all:initial;display:block}*{box-sizing:border-box}@keyframes gr-fade-in{from{opacity:0}to{opacity:1}}@keyframes gr-slide-up{from{opacity:0;transform:translateY(20px) scale(.98)}to{opacity:1;transform:translateY(0) scale(1)}}@keyframes gr-slide-in-right{from{opacity:0;transform:translateX(100%)}to{opacity:1;transform:translateX(0)}}@keyframes gr-slide-in-left{from{opacity:0;transform:translateX(-100%)}to{opacity:1;transform:translateX(0)}}.gr-overlay{position:fixed;top:0;left:0;width:100vw;height:100vh;display:flex;z-index:2147483647;font-family:var(--gr-font);animation:gr-fade-in .2s ease-out forwards;backdrop-filter:blur(4px);background-color:var(--gr-tint-rgba)}.gr-overlay--modal{align-items:center;justify-content:center}.gr-overlay--drawer{align-items:flex-start;justify-content:flex-start}.gr-container{position:relative;background-color:var(--gr-bg);color:var(--gr-text);padding:32px;box-shadow:0 0 50px -12px rgba(0,0,0,0.25), 0 0 30px -10px rgba(0,0,0,0.15)}.gr-container--embedded{width:100%;height:100%;box-shadow:none;border:1px solid var(--gr-border);border-radius:var(--gr-radius)}.gr-container--modal{width:90%;max-width:480px;border-radius:var(--gr-radius);animation:gr-slide-up .3s cubic-bezier(.16,1,.3,1) forwards}.gr-container--drawer{position:absolute;width:400px;max-width:calc(100vw - 20px);max-height:calc(100vh - 40px);overflow-y:auto}.gr-container--right{right:0;border-top-left-radius:var(--gr-radius);border-bottom-left-radius:var(--gr-radius);animation:gr-slide-in-right .3s cubic-bezier(.16,1,.3,1) forwards}.gr-container--left{left:0;border-top-right-radius:var(--gr-radius);border-bottom-right-radius:var(--gr-radius);animation:gr-slide-in-left .3s cubic-bezier(.16,1,.3,1) forwards}.gr-container--top{top:100px}.gr-container--bottom{bottom:100px}.gr-close-btn{position:absolute;top:20px;right:20px;background:0 0;border:none;cursor:pointer;color:#9ca3af;padding:4px;border-radius:50%;display:flex;align-items:center;justify-content:center;transition:all .2s}.gr-close-btn:hover{background-color:var(--gr-surface);color:var(--gr-text)}.gr-header{text-align:center;margin-bottom:28px}.gr-icon-lg{font-size:32px;margin-bottom:12px}.gr-title{margin:0 0 8px 0;font-size:22px;font-weight:700;letter-spacing:-.02em}.gr-subtitle{margin:0;font-size:14px;line-height:1.5;color:var(--gr-text-secondary)}.gr-loading{padding:16px;background-color:var(--gr-surface);border-radius:8px;text-align:center;color:var(--gr-text-secondary);font-size:14px}.gr-label{display:block;font-size:12px;font-weight:600;color:var(--gr-text-secondary);margin-bottom:8px;text-transform:uppercase;letter-spacing:.05em}.gr-share-label{text-align:center;margin-bottom:16px;font-size:13px;font-weight:500;color:var(--gr-text-secondary);display:flex;align-items:center;gap:12px}.gr-divider{flex:1;height:1px;background:var(--gr-border)}.gr-social-container{display:flex;gap:16px;justify-content:center;flex-wrap:wrap}.gr-btn{padding:14px;font-size:15px;font-weight:600;background-color:var(--gr-primary);color:#fff;border:none;border-radius:var(--gr-radius);cursor:pointer;transition:all .2s ease;text-align:center;width:100%;display:block}.gr-btn:hover{transform:translateY(-1px);filter:brightness(1.05)}.gr-btn:active{transform:translateY(0);filter:brightness(.95)}.gr-btn:disabled{opacity:.7;cursor:not-allowed}.gr-btn--sm{padding:8px 16px;font-size:13px;width:auto;border-radius:calc(var(--gr-radius) - 4px)}.gr-input-group{display:flex;align-items:center;background-color:var(--gr-surface);border:1px solid var(--gr-border);border-radius:var(--gr-radius);padding:4px;margin-bottom:24px}.gr-input-group:focus-within{border-color:var(--gr-primary);box-shadow:0 0 0 3px var(--gr-surface)}.gr-input{flex:1;padding:10px 12px;font-size:14px;border:none;background:0 0;color:var(--gr-text);outline:none;font-family:monospace}.gr-social-btn{display:flex;align-items:center;justify-content:center;width:42px;height:42px;border-radius:50%;background-color:var(--gr-surface);color:var(--gr-text-secondary);border:1px solid var(--gr-border);transition:transform .2s cubic-bezier(.34,1.56,.64,1);cursor:pointer}.gr-social-btn:hover{transform:scale(1.15) rotate(3deg);color:#fff}.gr-powered-by{margin-top:24px;text-align:center;font-size:11px;color:#9ca3af;display:flex;align-items:center;justify-content:center;gap:4px;opacity:.8}.gr-powered-by a{color:inherit;text-decoration:none;font-weight:600;transition:opacity .2s}.gr-powered-by a:hover{opacity:1;text-decoration:underline}",this.shadow.appendChild(g),this.content=document.createElement("div");let h=n.modal.componentType==="drawer",k=n.trigger.position||"top-right",f=["gr-container"];s?(f.push("gr-container--embedded"),this.content.className=f.join(" "),this.renderInternalContent(o,e,s),this.shadow.appendChild(this.content),t&&t.appendChild(this.host)):(this.overlay=document.createElement("div"),this.overlay.className=`gr-overlay ${h?"gr-overlay--drawer":"gr-overlay--modal"}`,h?(f.push("gr-container--drawer"),k.includes("right")?f.push("gr-container--right"):f.push("gr-container--left"),k.includes("bottom")?f.push("gr-container--bottom"):f.push("gr-container--top")):f.push("gr-container--modal"),this.content.className=f.join(" "),this.renderInternalContent(o,e,s),this.overlay.appendChild(this.content),this.shadow.appendChild(this.overlay),document.body.appendChild(this.host),this.overlay.onclick=E=>{E.target===this.overlay&&this.hide()})}getTheme(){return{colorPrimary:"#2563eb",colorText:"#111827",colorTextSecondary:"#6b7280",colorBackground:"#ffffff",colorTint:"#f9fafb",tintAlpha:.8,colorSurface:"#f9fafb",colorBorder:"#e5e7eb",colorError:"#ef4444",borderRadius:"16px"}}async renderInternalContent(e,t,n=!1){if(!this.content)return;if(this.content.innerHTML="",!n){let h=document.createElement("button");h.className="gr-close-btn",h.innerHTML=`
|
|
2
2
|
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
3
3
|
<line x1="18" y1="6" x2="6" y2="18"></line>
|
|
4
4
|
<line x1="6" y1="6" x2="18" y2="18"></line>
|
|
5
5
|
</svg>
|
|
6
|
-
`,
|
|
6
|
+
`,h.onclick=()=>this.hide(),this.content.appendChild(h)}let i=document.createElement("div");i.className="gr-header";let o=document.createElement("div");o.className="gr-icon-lg",o.innerHTML="\u{1F381}",i.appendChild(o);let s=document.createElement("h3");s.className="gr-title",s.textContent=t?.title??this.referrerExperience.modal.title??"Invite Friends & Earn",i.appendChild(s);let l=document.createElement("p");if(l.className="gr-subtitle",l.textContent="Share your unique link and earn rewards for every friend who signs up.",i.appendChild(l),this.content.appendChild(i),!this.deps.isUserReady()){let h=document.createElement("div");h.className="gr-loading",h.textContent="Please log in to view your referral dashboard.",this.content.appendChild(h);return}let d=this.deps.getReferralLink(),c=document.createElement("div");this.renderLinkView(c,d,e),this.content.appendChild(c),d&&this.renderSocialShare(this.content,d,e);let g=document.createElement("div");g.className="gr-powered-by",g.innerHTML=`
|
|
7
7
|
Powered by <a href="https://growthrail.com" target="_blank" rel="noopener noreferrer">Growth Rail</a>
|
|
8
|
-
`,this.content.appendChild(
|
|
8
|
+
`,this.content.appendChild(g)}renderLinkView(e,t,n){let i=document.createElement("label");i.className="gr-label",i.textContent="Your unique link",e.appendChild(i);let o=document.createElement("div");o.className="gr-input-group";let s=document.createElement("input");s.className="gr-input",s.type="text",s.value=t,s.readOnly=!0;let l=document.createElement("button");l.className="gr-btn gr-btn--sm",l.textContent="Copy",l.onclick=async()=>{try{await navigator.clipboard.writeText(t);let d=l.textContent;l.textContent="Copied!",l.style.backgroundColor="#10b981",setTimeout(()=>{l.textContent=d,l.style.backgroundColor=""},2e3)}catch(d){console.error("Failed to copy",d)}},o.appendChild(s),o.appendChild(l),e.appendChild(o)}renderSocialShare(e,t,n){let i=document.createElement("div"),o=document.createElement("div");o.className="gr-share-label",o.innerHTML='<span class="gr-divider"></span>Share via<span class="gr-divider"></span>',i.appendChild(o);let s=document.createElement("div");s.className="gr-social-container",[{name:"Twitter",color:"#000000",icon:'<svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor"><path d="M18.244 2.25h3.308l-7.227 8.26 8.502 11.24H16.17l-5.214-6.817L4.99 21.75H1.68l7.73-8.835L1.254 2.25H8.08l4.713 6.231zm-1.161 17.52h1.833L7.084 4.126H5.117z"/></svg>',url:`https://twitter.com/intent/tweet?url=${encodeURIComponent(t)}&text=Check+this+out!`},{name:"Facebook",color:"#1877F2",icon:'<svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor"><path d="M9.101 23.691v-7.98H6.627v-3.667h2.474v-1.58c0-4.085 1.848-5.978 5.858-5.978.401 0 .955.042 1.468.103a8.68 8.68 0 0 1 1.141.195v3.325a8.623 8.623 0 0 0-.653-.036c-2.648 0-2.928 1.67-2.928 3.403v1.596h3.949l-.577 3.667h-3.372v7.98h-4.938z"/></svg>',url:`https://www.facebook.com/sharer/sharer.php?u=${encodeURIComponent(t)}`},{name:"LinkedIn",color:"#0A66C2",icon:'<svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor"><path d="M20.447 20.452h-3.554v-5.569c0-1.328-.027-3.037-1.852-3.037-1.853 0-2.136 1.445-2.136 2.939v5.667H9.351V9h3.414v1.561h.046c.477-.9 1.637-1.85 3.37-1.85 3.601 0 4.267 2.37 4.267 5.455v6.286zM5.337 7.433c-1.144 0-2.063-.926-2.063-2.065 0-1.138.92-2.063 2.063-2.063 1.14 0 2.064.925 2.064 2.063 0 1.139-.925 2.065-2.064 2.065zm1.782 13.019H3.555V9h3.564v11.452zM22.225 0H1.771C.792 0 0 .774 0 1.729v20.542C0 23.227.792 24 1.771 24h20.451C23.2 24 24 23.227 24 22.271V1.729C24 .774 23.2 0 22.222 0h.003z"/></svg>',url:`https://www.linkedin.com/sharing/share-offsite/?url=${encodeURIComponent(t)}`},{name:"WhatsApp",color:"#25D366",icon:'<svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor"><path d="M17.472 14.382c-.297-.149-1.758-.867-2.03-.967-.273-.099-.471-.148-.67.15-.197.297-.767.966-.94 1.164-.173.199-.347.223-.644.075-.297-.15-1.255-.463-2.39-1.475-.883-.788-1.48-1.761-1.653-2.059-.173-.297-.018-.458.13-.606.134-.133.298-.347.446-.52.149-.174.198-.298.298-.497.099-.198.05-.371-.025-.52-.075-.149-.669-1.612-.916-2.207-.242-.579-.487-.5-.669-.51-.173-.008-.371-.01-.57-.01-.198 0-.52.074-.792.372-.272.297-1.04 1.016-1.04 2.479 0 1.462 1.065 2.875 1.213 3.074.149.198 2.096 3.2 5.077 4.487.709.306 1.262.489 1.694.625.712.227 1.36.195 1.871.118.571-.085 1.758-.719 2.006-1.413.248-.694.248-1.289.173-1.413-.074-.124-.272-.198-.57-.347m-5.421 7.403h-.004a9.87 9.87 0 01-5.031-1.378l-.361-.214-3.741.982.998-3.648-.235-.374a9.86 9.86 0 01-1.51-5.26c.001-5.45 4.436-9.884 9.888-9.884 2.64 0 5.122 1.03 6.988 2.898a9.825 9.825 0 012.893 6.994c-.003 5.45-4.437 9.884-9.885 9.884m8.413-18.297A11.815 11.815 0 0012.05 0C5.495 0 .16 5.335.157 11.892c0 2.096.547 4.142 1.588 5.945L.057 24l6.305-1.654a11.882 11.882 0 005.683 1.448h.005c6.554 0 11.89-5.335 11.893-11.893a11.821 11.821 0 00-3.48-8.413z"/></svg>',url:`https://api.whatsapp.com/send?text=${encodeURIComponent(t)}`},{name:"Email",color:"#888888",icon:'<svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor"><path d="M20 4H4c-1.1 0-1.99.9-1.99 2L2 18c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2zm0 4l-8 5-8-5V6l8 5 8-5v2z"/></svg>',url:`mailto:?subject=Check this out&body=${encodeURIComponent(t)}`}].forEach(d=>{let c=document.createElement("a");c.href=d.url,c.target="_blank",c.rel="noopener noreferrer",c.className="gr-social-btn",c.innerHTML=d.icon,c.title=`Share on ${d.name}`,c.onmouseenter=()=>{c.style.backgroundColor=d.color,c.style.color="#ffffff",c.style.borderColor=d.color},c.onmouseleave=()=>{c.style.backgroundColor="",c.style.color="",c.style.borderColor=""},s.appendChild(c)}),i.appendChild(s),e.appendChild(i)}bindEvents(){this.overlay&&(this.overlay.onclick=e=>{e.target===this.overlay&&this.hide()})}};var w=class{constructor(e){a(this,"options");a(this,"host",null);a(this,"shadow",null);a(this,"element",null);this.options=e}mount(){this.host||this.createDom()}unmount(){this.host&&this.host.parentNode&&document.body.removeChild(this.host),this.host=null,this.shadow=null,this.element=null}createDom(){this.host=document.createElement("div"),this.host.style.all="initial",this.host.style.position="absolute",this.host.style.zIndex="2147483646";let e={x:0,y:100};this.host.style.setProperty("--gr-offset-y",`${e.y}px`),this.shadow=this.host.attachShadow({mode:"open"});let t=document.createElement("style"),n=this.options.trigger?.displayMode||"edge";t.textContent=`
|
|
9
9
|
:host { all: initial; display: block; }
|
|
10
10
|
@keyframes gr-shimmer {
|
|
11
11
|
0% { transform: translateX(-150%) skewX(-15deg); }
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
animation: gr-shimmer 3s infinite;
|
|
65
65
|
}
|
|
66
66
|
.gr-icon { color: #fff; width: 24px; height: 24px; position: relative; z-index: 10; }
|
|
67
|
-
`,this.shadow.appendChild(
|
|
67
|
+
`,this.shadow.appendChild(t),this.element=document.createElement("div");let i=this.options.trigger?.position||"bottom-right",o=["gr-btn",`gr-btn--${n}`];i.includes("right")?o.push("gr-btn--right"):o.push("gr-btn--left"),i.includes("bottom")?o.push("gr-btn--bottom"):o.push("gr-btn--top"),this.element.className=o.join(" "),this.element.innerHTML=`
|
|
68
68
|
<svg class="gr-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
69
69
|
<polyline points="20 12 20 22 4 22 4 12"></polyline>
|
|
70
70
|
<rect x="2" y="7" width="20" height="5"></rect>
|
|
@@ -72,24 +72,23 @@
|
|
|
72
72
|
<path d="M12 7H7.5a2.5 2.5 0 0 1 0-5C11 2 12 7 12 7z"></path>
|
|
73
73
|
<path d="M12 7h4.5a2.5 2.5 0 0 0 0-5C13 2 12 7 12 7z"></path>
|
|
74
74
|
</svg>
|
|
75
|
-
`,this.element.onclick=()=>{x.showReferralDashboard()},this.shadow.appendChild(this.element),document.body.appendChild(this.host)}};var
|
|
75
|
+
`,this.element.onclick=()=>{x.showReferralDashboard()},this.shadow.appendChild(this.element),document.body.appendChild(this.host)}};var R=class{static show(e){if(typeof document>"u")return;let t=document.createElement("div");t.id="gr-banner-host",document.body.appendChild(t);let n=t.attachShadow({mode:"open"}),i=(e.banner.position||"center-top").toLowerCase(),o=i.includes("bottom")?"bottom":"top",s=i.includes("left")?"left":i.includes("right")?"right":"center",l="",d="";s==="center"?(l="left: 50%;",d="translateX(-50%)"):(l=`${s}: 20px;`,d="translateX(0)");let c=e.banner.themeColor||"#0070f3",g=document.createElement("style");g.textContent=`
|
|
76
76
|
.gr-banner {
|
|
77
77
|
position: fixed;
|
|
78
78
|
${o}: 20px;
|
|
79
79
|
${l}
|
|
80
80
|
z-index: 2147483647;
|
|
81
81
|
font-family: Inter, system-ui, -apple-system, sans-serif;
|
|
82
|
-
background:
|
|
83
|
-
color: #
|
|
82
|
+
background: var(--gr-theme-color);
|
|
83
|
+
color: #ffffff;
|
|
84
84
|
padding: 12px 20px;
|
|
85
85
|
border-radius: 12px;
|
|
86
|
-
box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.
|
|
86
|
+
box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.2), 0 4px 6px -2px rgba(0, 0, 0, 0.1);
|
|
87
87
|
display: flex;
|
|
88
88
|
align-items: center;
|
|
89
89
|
gap: 12px;
|
|
90
90
|
width: max-content;
|
|
91
91
|
max-width: 500px;
|
|
92
|
-
border: 1px solid #e5e7eb;
|
|
93
92
|
animation: gr-slide-in 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
|
|
94
93
|
box-sizing: border-box;
|
|
95
94
|
}
|
|
@@ -106,16 +105,16 @@
|
|
|
106
105
|
}
|
|
107
106
|
|
|
108
107
|
.gr-icon {
|
|
109
|
-
width:
|
|
110
|
-
height:
|
|
111
|
-
color: #
|
|
108
|
+
width: 20px;
|
|
109
|
+
height: 20px;
|
|
110
|
+
color: #ffffff;
|
|
112
111
|
flex-shrink: 0;
|
|
113
112
|
}
|
|
114
|
-
.gr-text { font-size: 14px; font-weight:
|
|
113
|
+
.gr-text { font-size: 14px; font-weight: 600; line-height: 1.4; margin: 0; color: #ffffff; flex: 1; }
|
|
115
114
|
.gr-close {
|
|
116
115
|
background: transparent;
|
|
117
116
|
border: none;
|
|
118
|
-
color:
|
|
117
|
+
color: rgba(255, 255, 255, 0.8);
|
|
119
118
|
cursor: pointer;
|
|
120
119
|
padding: 4px;
|
|
121
120
|
margin-left: 8px;
|
|
@@ -126,8 +125,8 @@
|
|
|
126
125
|
transition: all 0.2s;
|
|
127
126
|
flex-shrink: 0;
|
|
128
127
|
}
|
|
129
|
-
.gr-close:hover { background:
|
|
130
|
-
`;let h=document.createElement("div");h.className="gr-banner",h.innerHTML=`
|
|
128
|
+
.gr-close:hover { background: rgba(255, 255, 255, 0.2); color: #ffffff; }
|
|
129
|
+
`;let h=document.createElement("div");h.className="gr-banner",h.style.setProperty("--gr-theme-color",c),h.innerHTML=`
|
|
131
130
|
<svg class="gr-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
132
131
|
<polyline points="20 12 20 22 4 22 4 12"></polyline>
|
|
133
132
|
<rect x="2" y="7" width="20" height="5"></rect>
|
|
@@ -142,4 +141,4 @@
|
|
|
142
141
|
<line x1="6" y1="6" x2="18" y2="18"></line>
|
|
143
142
|
</svg>
|
|
144
143
|
</button>
|
|
145
|
-
`,h.querySelector(".gr-close")?.addEventListener("click",()=>{
|
|
144
|
+
`,h.querySelector(".gr-close")?.addEventListener("click",()=>{t.remove()}),n.appendChild(g),n.appendChild(h)}};var r=class r{constructor(){}static init(e){r.initialized||(r.options=e,r.api=new y(e),r.storage=new v({cookieDomain:e.cookieDomain}),r.initialized=!0,r.autoTrackReferral())}static isInitialized(){return r.initialized}static ensureInitialized(){if(!r.initialized)throw new Error("GrowthRail.init() must be called before using the SDK")}static async loadReferrerExperience(e){try{r.createReferralModal(e),e.trigger.show&&r.createTriggerButton(e.trigger)}catch(t){throw console.error("GrowthRail: Failed to load referrer experience",t),t}}static createReferralModal(e){r.referralModal=new m({isUserReady:()=>r.isUserReady(),getReferralLink:()=>r.currentUser?.referralLink||""},e)}static async autoTrackReferral(){if(typeof window>"u")return;let e=new URLSearchParams(window.location.search),t=e.get("referralCode"),n=e.get("rewardEventName");if(t){let i=await r.api.getNewUserExperience(),o=await r.trackReferral(t,n??void 0);r.storage.setTrackedReferral(o.referralTrackingId),i.banner.show&&R.show(i)}}static async initAppUser(e){r.ensureInitialized();let t=await r.api.initAppUser(e);return r.currentUser={...t,id:e},r.experience=t.referrerExperience,r.loadReferrerExperience(t.referrerExperience),r.userReadyResolver?r.userReadyResolver(r.currentUser):r.userReadyPromise=Promise.resolve(r.currentUser),t}static async trackReferral(e,t){return r.ensureInitialized(),r.api.trackReferral(e,t)}static async trackRewardEvent(e){r.ensureInitialized();let t=r.currentUser?.id;if(!t)throw new Error("GrowthRail: User must be initialized before tracking a reward event.");let n=r.storage.getTrackedReferral();if(!n)throw new Error("GrowthRail: Referral Tracking Id must be initialized before tracking a reward event.");return r.api.trackRewardEvent(t,n,e)}static getReferralLink(){if(!r.currentUser?.referralLink)throw new Error("GrowthRail: Referral Link not loaded or user not initialized");return r.currentUser.referralLink}static getReferralCode(){return r.currentUser?.referralCode}static getUserId(){return r.currentUser?.id}static isUserReady(){return r.currentUser!==null}static ensureUserReady(){return r.currentUser?Promise.resolve(r.currentUser):(r.userReadyPromise||(r.userReadyPromise=new Promise(e=>{r.userReadyResolver=e})),r.userReadyPromise)}static async showReferralDashboard(e){if(r.ensureInitialized(),!r.experience)throw new Error("GrowthRail: Experience not loaded");r.referralModal&&r.referralModal.hide(),r.referralModal?.show(e)}static createTriggerButton(e){if(typeof window>"u")return;if(!r.experience)throw new Error("GrowthRail: Experience not loaded");r.floatingButton&&r.floatingButton.unmount();let t={...r.experience?.trigger,...e},n={modal:{...r.experience.modal},trigger:t};r.floatingButton=new w(n),r.floatingButton.mount()}static destroyTriggerButton(){r.floatingButton&&(r.floatingButton.unmount(),r.floatingButton=null)}};a(r,"api"),a(r,"storage"),a(r,"options"),a(r,"currentUser",null),a(r,"initialized",!1),a(r,"referralModal",null),a(r,"floatingButton",null),a(r,"experience",null),a(r,"userReadyPromise",null),a(r,"userReadyResolver",null);var x=r;0&&(module.exports={GrowthRail,ReferralModal});
|
package/dist/index.mjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
var E=Object.defineProperty;var C=(g,e,t)=>e in g?E(g,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):g[e]=t;var a=(g,e,t)=>C(g,typeof e!="symbol"?e+"":e,t);var m=class{constructor(e){a(this,"baseUrl");a(this,"apiKey");let t=typeof process<"u"&&process.env?.ENV_BASE_URL;this.baseUrl=t||"https://api.growthrail.dev",this.apiKey=e.apiKey}async request(e,t,n){let i={"Content-Type":"application/json","X-GrowthRail-ProjectSecret":this.apiKey};try{let o=await fetch(`${this.baseUrl}${e}`,{method:t,headers:i,body:n?JSON.stringify(n):void 0});if(!o.ok)throw new Error(`GrowthRail API Error: ${o.statusText}`);return o.json()}catch(o){throw console.error("GrowthRail SDK Error:",o),o}}async getNewUserExperience(){return this.request("/api/v1/sdk/new-user-experience","POST")}async initAppUser(e){return this.request("/api/v1/sdk/init-app-user","POST",{clientProvidedId:e})}async createReferralLink(e,t){return this.request("/api/v1/sdk/create-referral-link","POST",{referrerId:e,rewardEventName:t})}async trackReferral(e,t){return this.request("/api/v1/sdk/track-referral","POST",{referralCode:e,rewardEventName:t})}async trackRewardEvent(e,t,n){return this.request("/api/v1/sdk/track-reward-event","POST",{refereeId:e,referralTrackingId:t,eventName:n})}};var u=class u{constructor(e){a(this,"options",{});e&&(this.options=e)}setCookie(e,t,n=30){if(typeof document>"u")return;let i="";if(n){let s=new Date;s.setTime(s.getTime()+n*24*60*60*1e3),i=`; expires=${s.toUTCString()}`}let o="";this.options.cookieDomain&&(o=`; domain=${this.options.cookieDomain}`),document.cookie=`${e}=${t||""}${i}${o}; path=/; SameSite=Lax`}getCookie(e){if(typeof document>"u")return null;let t=`${e}=`,n=document.cookie.split(";");for(let i=0;i<n.length;i++){let o=n[i];for(;o.charAt(0)===" ";)o=o.substring(1,o.length);if(o.indexOf(t)===0)return o.substring(t.length,o.length)}return null}getReferralCode(){return this.getCookie(u.REFERRAL_CODE_KEY)}setReferralCode(e){this.setCookie(u.REFERRAL_CODE_KEY,e,30)}setTrackedReferral(e){this.setCookie(u.TRACKED_REFERRAL_KEY,e,30)}getTrackedReferral(){return this.getCookie(u.TRACKED_REFERRAL_KEY)}};a(u,"REFERRAL_CODE_KEY","gr_ref_code"),a(u,"TRACKED_REFERRAL_KEY","gr_tracked_referral");var x=u;var b=class{constructor(e,t){a(this,"referrerExperience");a(this,"deps");a(this,"host",null);a(this,"shadow",null);a(this,"overlay",null);a(this,"content",null);this.deps=e,this.referrerExperience=t}show(e,t){this.host||(this.createDom(e,t),this.bindEvents(),t||(document.body.style.overflow="hidden"))}hide(){this.host&&(this.host&&this.host.parentNode&&this.host.parentNode.removeChild(this.host),this.host=null,this.overlay=null,this.content=null,this.shadow=null,document.body.style.overflow="")}createDom(e,t){let n={...this.referrerExperience,modal:{...this.referrerExperience.modal,...e??{},theme:{...this.referrerExperience.modal?.theme,...e?.theme??{}}}},i=this.getTheme(),o={...i,colorPrimary:n.modal?.theme?.primaryColor||i.colorPrimary,colorBackground:n.modal?.theme?.backgroundColor||i.colorBackground,colorTint:n.modal?.theme?.tintColor||i.colorTint,tintAlpha:n.modal?.theme?.tintAlpha??i.tintAlpha},s=!!t;this.host=document.createElement("div"),this.host.style.all="initial",s?(this.host.style.display="block",this.host.style.width="100%",this.host.style.height="100%"):(this.host.style.position="absolute",this.host.style.zIndex="2147483647"),this.host.id="growth-rail-modal-host",this.host.style.setProperty("--gr-primary",o.colorPrimary),this.host.style.setProperty("--gr-text",o.colorText),this.host.style.setProperty("--gr-text-secondary",o.colorTextSecondary),this.host.style.setProperty("--gr-bg",o.colorBackground),this.host.style.setProperty("--gr-tint",o.colorTint);let l=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(o.colorTint),d=o.tintAlpha>1?o.tintAlpha/100:o.tintAlpha,c=l?`rgba(${parseInt(l[1],16)}, ${parseInt(l[2],16)}, ${parseInt(l[3],16)}, ${d})`:`rgba(0, 0, 0, ${d})`;this.host.style.setProperty("--gr-tint-rgba",c),this.host.style.setProperty("--gr-surface",o.colorSurface),this.host.style.setProperty("--gr-border",o.colorBorder),this.host.style.setProperty("--gr-error",o.colorError),this.host.style.setProperty("--gr-radius",o.borderRadius),this.host.style.setProperty("--gr-font",'Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif'),this.shadow=this.host.attachShadow({mode:"open"});let p=document.createElement("style");p.textContent=":host{all:initial;display:block}*{box-sizing:border-box}@keyframes gr-fade-in{from{opacity:0}to{opacity:1}}@keyframes gr-slide-up{from{opacity:0;transform:translateY(20px) scale(.98)}to{opacity:1;transform:translateY(0) scale(1)}}@keyframes gr-slide-in-right{from{opacity:0;transform:translateX(100%)}to{opacity:1;transform:translateX(0)}}@keyframes gr-slide-in-left{from{opacity:0;transform:translateX(-100%)}to{opacity:1;transform:translateX(0)}}.gr-overlay{position:fixed;top:0;left:0;width:100vw;height:100vh;display:flex;z-index:2147483647;font-family:var(--gr-font);animation:gr-fade-in .2s ease-out forwards;backdrop-filter:blur(4px);background-color:var(--gr-tint-rgba)}.gr-overlay--modal{align-items:center;justify-content:center}.gr-overlay--drawer{align-items:flex-start;justify-content:flex-start}.gr-container{position:relative;background-color:var(--gr-bg);color:var(--gr-text);padding:32px;box-shadow:0 0 50px -12px rgba(0,0,0,0.25), 0 0 30px -10px rgba(0,0,0,0.15)}.gr-container--embedded{width:100%;height:100%;box-shadow:none;border:1px solid var(--gr-border);border-radius:var(--gr-radius)}.gr-container--modal{width:90%;max-width:480px;border-radius:var(--gr-radius);animation:gr-slide-up .3s cubic-bezier(.16,1,.3,1) forwards}.gr-container--drawer{position:absolute;width:400px;max-width:calc(100vw - 20px);max-height:calc(100vh - 40px);overflow-y:auto}.gr-container--right{right:0;border-top-left-radius:var(--gr-radius);border-bottom-left-radius:var(--gr-radius);animation:gr-slide-in-right .3s cubic-bezier(.16,1,.3,1) forwards}.gr-container--left{left:0;border-top-right-radius:var(--gr-radius);border-bottom-right-radius:var(--gr-radius);animation:gr-slide-in-left .3s cubic-bezier(.16,1,.3,1) forwards}.gr-container--top{top:100px}.gr-container--bottom{bottom:100px}.gr-close-btn{position:absolute;top:20px;right:20px;background:0 0;border:none;cursor:pointer;color:#9ca3af;padding:4px;border-radius:50%;display:flex;align-items:center;justify-content:center;transition:all .2s}.gr-close-btn:hover{background-color:var(--gr-surface);color:var(--gr-text)}.gr-header{text-align:center;margin-bottom:28px}.gr-icon-lg{font-size:32px;margin-bottom:12px}.gr-title{margin:0 0 8px 0;font-size:22px;font-weight:700;letter-spacing:-.02em}.gr-subtitle{margin:0;font-size:14px;line-height:1.5;color:var(--gr-text-secondary)}.gr-loading{padding:16px;background-color:var(--gr-surface);border-radius:8px;text-align:center;color:var(--gr-text-secondary);font-size:14px}.gr-label{display:block;font-size:12px;font-weight:600;color:var(--gr-text-secondary);margin-bottom:8px;text-transform:uppercase;letter-spacing:.05em}.gr-share-label{text-align:center;margin-bottom:16px;font-size:13px;font-weight:500;color:var(--gr-text-secondary);display:flex;align-items:center;gap:12px}.gr-divider{flex:1;height:1px;background:var(--gr-border)}.gr-social-container{display:flex;gap:16px;justify-content:center;flex-wrap:wrap}.gr-btn{padding:14px;font-size:15px;font-weight:600;background-color:var(--gr-primary);color:#fff;border:none;border-radius:var(--gr-radius);cursor:pointer;transition:all .2s ease;text-align:center;width:100%;display:block}.gr-btn:hover{transform:translateY(-1px);filter:brightness(1.05)}.gr-btn:active{transform:translateY(0);filter:brightness(.95)}.gr-btn:disabled{opacity:.7;cursor:not-allowed}.gr-btn--sm{padding:8px 16px;font-size:13px;width:auto;border-radius:calc(var(--gr-radius) - 4px)}.gr-input-group{display:flex;align-items:center;background-color:var(--gr-surface);border:1px solid var(--gr-border);border-radius:var(--gr-radius);padding:4px;margin-bottom:24px}.gr-input-group:focus-within{border-color:var(--gr-primary);box-shadow:0 0 0 3px var(--gr-surface)}.gr-input{flex:1;padding:10px 12px;font-size:14px;border:none;background:0 0;color:var(--gr-text);outline:none;font-family:monospace}.gr-social-btn{display:flex;align-items:center;justify-content:center;width:42px;height:42px;border-radius:50%;background-color:var(--gr-surface);color:var(--gr-text-secondary);border:1px solid var(--gr-border);transition:transform .2s cubic-bezier(.34,1.56,.64,1);cursor:pointer}.gr-social-btn:hover{transform:scale(1.15) rotate(3deg);color:#fff}.gr-powered-by{margin-top:24px;text-align:center;font-size:11px;color:#9ca3af;display:flex;align-items:center;justify-content:center;gap:4px;opacity:.8}.gr-powered-by a{color:inherit;text-decoration:none;font-weight:600;transition:opacity .2s}.gr-powered-by a:hover{opacity:1;text-decoration:underline}",this.shadow.appendChild(p),this.content=document.createElement("div");let h=n.modal.componentType==="drawer",k=n.trigger.position||"top-right",f=["gr-container"];s?(f.push("gr-container--embedded"),this.content.className=f.join(" "),this.renderInternalContent(o,e,s),this.shadow.appendChild(this.content),t&&t.appendChild(this.host)):(this.overlay=document.createElement("div"),this.overlay.className=`gr-overlay ${h?"gr-overlay--drawer":"gr-overlay--modal"}`,h?(f.push("gr-container--drawer"),k.includes("right")?f.push("gr-container--right"):f.push("gr-container--left"),k.includes("bottom")?f.push("gr-container--bottom"):f.push("gr-container--top")):f.push("gr-container--modal"),this.content.className=f.join(" "),this.renderInternalContent(o,e,s),this.overlay.appendChild(this.content),this.shadow.appendChild(this.overlay),document.body.appendChild(this.host),this.overlay.onclick=R=>{R.target===this.overlay&&this.hide()})}getTheme(){return{colorPrimary:"#2563eb",colorText:"#111827",colorTextSecondary:"#6b7280",colorBackground:"#ffffff",colorTint:"#f9fafb",tintAlpha:.8,colorSurface:"#f9fafb",colorBorder:"#e5e7eb",colorError:"#ef4444",borderRadius:"16px"}}async renderInternalContent(e,t,n=!1){if(!this.content)return;if(this.content.innerHTML="",!n){let h=document.createElement("button");h.className="gr-close-btn",h.innerHTML=`
|
|
1
|
+
var E=Object.defineProperty;var C=(h,e,t)=>e in h?E(h,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):h[e]=t;var a=(h,e,t)=>C(h,typeof e!="symbol"?e+"":e,t);var b=class{constructor(e){a(this,"baseUrl");a(this,"projectSecretKey");let t=typeof process<"u"&&process.env?.ENV_BASE_URL;this.baseUrl=t||"https://api.growthrail.dev",this.projectSecretKey=e.projectSecretKey}async request(e,t,n){let i={"Content-Type":"application/json","X-GrowthRail-ProjectSecret":this.projectSecretKey};try{let o=await fetch(`${this.baseUrl}${e}`,{method:t,headers:i,body:n?JSON.stringify(n):void 0});if(!o.ok)throw new Error(`GrowthRail API Error: ${o.statusText}`);return o.json()}catch(o){throw console.error("GrowthRail SDK Error:",o),o}}async getNewUserExperience(){return this.request("/api/v1/sdk/new-user-experience","POST")}async initAppUser(e){return this.request("/api/v1/sdk/init-app-user","POST",{clientProvidedId:e})}async trackReferral(e,t){return this.request("/api/v1/sdk/track-referral","POST",{referralCode:e,rewardEventName:t})}async trackRewardEvent(e,t,n){return this.request("/api/v1/sdk/track-reward-event","POST",{refereeId:e,referralTrackingId:t,eventName:n})}};var u=class u{constructor(e){a(this,"options",{});e&&(this.options=e)}setCookie(e,t,n=30){if(typeof document>"u")return;let i="";if(n){let s=new Date;s.setTime(s.getTime()+n*24*60*60*1e3),i=`; expires=${s.toUTCString()}`}let o="";this.options.cookieDomain&&(o=`; domain=${this.options.cookieDomain}`),document.cookie=`${e}=${t||""}${i}${o}; path=/; SameSite=Lax`}getCookie(e){if(typeof document>"u")return null;let t=`${e}=`,n=document.cookie.split(";");for(let i=0;i<n.length;i++){let o=n[i];for(;o.charAt(0)===" ";)o=o.substring(1,o.length);if(o.indexOf(t)===0)return o.substring(t.length,o.length)}return null}getReferralCode(){return this.getCookie(u.REFERRAL_CODE_KEY)}setReferralCode(e){this.setCookie(u.REFERRAL_CODE_KEY,e,30)}setTrackedReferral(e){this.setCookie(u.TRACKED_REFERRAL_KEY,e,30)}getTrackedReferral(){return this.getCookie(u.TRACKED_REFERRAL_KEY)}};a(u,"REFERRAL_CODE_KEY","gr_ref_code"),a(u,"TRACKED_REFERRAL_KEY","gr_tracked_referral");var y=u;var m=class{constructor(e,t){a(this,"referrerExperience");a(this,"deps");a(this,"host",null);a(this,"shadow",null);a(this,"overlay",null);a(this,"content",null);this.deps=e,this.referrerExperience=t}show(e,t){this.host||(this.createDom(e,t),this.bindEvents(),t||(document.body.style.overflow="hidden"))}hide(){this.host&&(this.host&&this.host.parentNode&&this.host.parentNode.removeChild(this.host),this.host=null,this.overlay=null,this.content=null,this.shadow=null,document.body.style.overflow="")}createDom(e,t){let n={...this.referrerExperience,modal:{...this.referrerExperience.modal,...e??{},theme:{...this.referrerExperience.modal?.theme,...e?.theme??{}}}},i=this.getTheme(),o={...i,colorPrimary:n.modal?.theme?.primaryColor||i.colorPrimary,colorBackground:n.modal?.theme?.backgroundColor||i.colorBackground,colorTint:n.modal?.theme?.tintColor||i.colorTint,tintAlpha:n.modal?.theme?.tintAlpha??i.tintAlpha},s=!!t;this.host=document.createElement("div"),this.host.style.all="initial",s?(this.host.style.display="block",this.host.style.width="100%",this.host.style.height="100%"):(this.host.style.position="absolute",this.host.style.zIndex="2147483647"),this.host.id="growth-rail-modal-host",this.host.style.setProperty("--gr-primary",o.colorPrimary),this.host.style.setProperty("--gr-text",o.colorText),this.host.style.setProperty("--gr-text-secondary",o.colorTextSecondary),this.host.style.setProperty("--gr-bg",o.colorBackground),this.host.style.setProperty("--gr-tint",o.colorTint);let l=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(o.colorTint),d=o.tintAlpha>1?o.tintAlpha/100:o.tintAlpha,c=l?`rgba(${parseInt(l[1],16)}, ${parseInt(l[2],16)}, ${parseInt(l[3],16)}, ${d})`:`rgba(0, 0, 0, ${d})`;this.host.style.setProperty("--gr-tint-rgba",c),this.host.style.setProperty("--gr-surface",o.colorSurface),this.host.style.setProperty("--gr-border",o.colorBorder),this.host.style.setProperty("--gr-error",o.colorError),this.host.style.setProperty("--gr-radius",o.borderRadius),this.host.style.setProperty("--gr-font",'Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif'),this.shadow=this.host.attachShadow({mode:"open"});let g=document.createElement("style");g.textContent=":host{all:initial;display:block}*{box-sizing:border-box}@keyframes gr-fade-in{from{opacity:0}to{opacity:1}}@keyframes gr-slide-up{from{opacity:0;transform:translateY(20px) scale(.98)}to{opacity:1;transform:translateY(0) scale(1)}}@keyframes gr-slide-in-right{from{opacity:0;transform:translateX(100%)}to{opacity:1;transform:translateX(0)}}@keyframes gr-slide-in-left{from{opacity:0;transform:translateX(-100%)}to{opacity:1;transform:translateX(0)}}.gr-overlay{position:fixed;top:0;left:0;width:100vw;height:100vh;display:flex;z-index:2147483647;font-family:var(--gr-font);animation:gr-fade-in .2s ease-out forwards;backdrop-filter:blur(4px);background-color:var(--gr-tint-rgba)}.gr-overlay--modal{align-items:center;justify-content:center}.gr-overlay--drawer{align-items:flex-start;justify-content:flex-start}.gr-container{position:relative;background-color:var(--gr-bg);color:var(--gr-text);padding:32px;box-shadow:0 0 50px -12px rgba(0,0,0,0.25), 0 0 30px -10px rgba(0,0,0,0.15)}.gr-container--embedded{width:100%;height:100%;box-shadow:none;border:1px solid var(--gr-border);border-radius:var(--gr-radius)}.gr-container--modal{width:90%;max-width:480px;border-radius:var(--gr-radius);animation:gr-slide-up .3s cubic-bezier(.16,1,.3,1) forwards}.gr-container--drawer{position:absolute;width:400px;max-width:calc(100vw - 20px);max-height:calc(100vh - 40px);overflow-y:auto}.gr-container--right{right:0;border-top-left-radius:var(--gr-radius);border-bottom-left-radius:var(--gr-radius);animation:gr-slide-in-right .3s cubic-bezier(.16,1,.3,1) forwards}.gr-container--left{left:0;border-top-right-radius:var(--gr-radius);border-bottom-right-radius:var(--gr-radius);animation:gr-slide-in-left .3s cubic-bezier(.16,1,.3,1) forwards}.gr-container--top{top:100px}.gr-container--bottom{bottom:100px}.gr-close-btn{position:absolute;top:20px;right:20px;background:0 0;border:none;cursor:pointer;color:#9ca3af;padding:4px;border-radius:50%;display:flex;align-items:center;justify-content:center;transition:all .2s}.gr-close-btn:hover{background-color:var(--gr-surface);color:var(--gr-text)}.gr-header{text-align:center;margin-bottom:28px}.gr-icon-lg{font-size:32px;margin-bottom:12px}.gr-title{margin:0 0 8px 0;font-size:22px;font-weight:700;letter-spacing:-.02em}.gr-subtitle{margin:0;font-size:14px;line-height:1.5;color:var(--gr-text-secondary)}.gr-loading{padding:16px;background-color:var(--gr-surface);border-radius:8px;text-align:center;color:var(--gr-text-secondary);font-size:14px}.gr-label{display:block;font-size:12px;font-weight:600;color:var(--gr-text-secondary);margin-bottom:8px;text-transform:uppercase;letter-spacing:.05em}.gr-share-label{text-align:center;margin-bottom:16px;font-size:13px;font-weight:500;color:var(--gr-text-secondary);display:flex;align-items:center;gap:12px}.gr-divider{flex:1;height:1px;background:var(--gr-border)}.gr-social-container{display:flex;gap:16px;justify-content:center;flex-wrap:wrap}.gr-btn{padding:14px;font-size:15px;font-weight:600;background-color:var(--gr-primary);color:#fff;border:none;border-radius:var(--gr-radius);cursor:pointer;transition:all .2s ease;text-align:center;width:100%;display:block}.gr-btn:hover{transform:translateY(-1px);filter:brightness(1.05)}.gr-btn:active{transform:translateY(0);filter:brightness(.95)}.gr-btn:disabled{opacity:.7;cursor:not-allowed}.gr-btn--sm{padding:8px 16px;font-size:13px;width:auto;border-radius:calc(var(--gr-radius) - 4px)}.gr-input-group{display:flex;align-items:center;background-color:var(--gr-surface);border:1px solid var(--gr-border);border-radius:var(--gr-radius);padding:4px;margin-bottom:24px}.gr-input-group:focus-within{border-color:var(--gr-primary);box-shadow:0 0 0 3px var(--gr-surface)}.gr-input{flex:1;padding:10px 12px;font-size:14px;border:none;background:0 0;color:var(--gr-text);outline:none;font-family:monospace}.gr-social-btn{display:flex;align-items:center;justify-content:center;width:42px;height:42px;border-radius:50%;background-color:var(--gr-surface);color:var(--gr-text-secondary);border:1px solid var(--gr-border);transition:transform .2s cubic-bezier(.34,1.56,.64,1);cursor:pointer}.gr-social-btn:hover{transform:scale(1.15) rotate(3deg);color:#fff}.gr-powered-by{margin-top:24px;text-align:center;font-size:11px;color:#9ca3af;display:flex;align-items:center;justify-content:center;gap:4px;opacity:.8}.gr-powered-by a{color:inherit;text-decoration:none;font-weight:600;transition:opacity .2s}.gr-powered-by a:hover{opacity:1;text-decoration:underline}",this.shadow.appendChild(g),this.content=document.createElement("div");let p=n.modal.componentType==="drawer",R=n.trigger.position||"top-right",f=["gr-container"];s?(f.push("gr-container--embedded"),this.content.className=f.join(" "),this.renderInternalContent(o,e,s),this.shadow.appendChild(this.content),t&&t.appendChild(this.host)):(this.overlay=document.createElement("div"),this.overlay.className=`gr-overlay ${p?"gr-overlay--drawer":"gr-overlay--modal"}`,p?(f.push("gr-container--drawer"),R.includes("right")?f.push("gr-container--right"):f.push("gr-container--left"),R.includes("bottom")?f.push("gr-container--bottom"):f.push("gr-container--top")):f.push("gr-container--modal"),this.content.className=f.join(" "),this.renderInternalContent(o,e,s),this.overlay.appendChild(this.content),this.shadow.appendChild(this.overlay),document.body.appendChild(this.host),this.overlay.onclick=k=>{k.target===this.overlay&&this.hide()})}getTheme(){return{colorPrimary:"#2563eb",colorText:"#111827",colorTextSecondary:"#6b7280",colorBackground:"#ffffff",colorTint:"#f9fafb",tintAlpha:.8,colorSurface:"#f9fafb",colorBorder:"#e5e7eb",colorError:"#ef4444",borderRadius:"16px"}}async renderInternalContent(e,t,n=!1){if(!this.content)return;if(this.content.innerHTML="",!n){let p=document.createElement("button");p.className="gr-close-btn",p.innerHTML=`
|
|
2
2
|
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
3
3
|
<line x1="18" y1="6" x2="6" y2="18"></line>
|
|
4
4
|
<line x1="6" y1="6" x2="18" y2="18"></line>
|
|
5
5
|
</svg>
|
|
6
|
-
`,
|
|
6
|
+
`,p.onclick=()=>this.hide(),this.content.appendChild(p)}let i=document.createElement("div");i.className="gr-header";let o=document.createElement("div");o.className="gr-icon-lg",o.innerHTML="\u{1F381}",i.appendChild(o);let s=document.createElement("h3");s.className="gr-title",s.textContent=t?.title??this.referrerExperience.modal.title??"Invite Friends & Earn",i.appendChild(s);let l=document.createElement("p");if(l.className="gr-subtitle",l.textContent="Share your unique link and earn rewards for every friend who signs up.",i.appendChild(l),this.content.appendChild(i),!this.deps.isUserReady()){let p=document.createElement("div");p.className="gr-loading",p.textContent="Please log in to view your referral dashboard.",this.content.appendChild(p);return}let d=this.deps.getReferralLink(),c=document.createElement("div");this.renderLinkView(c,d,e),this.content.appendChild(c),d&&this.renderSocialShare(this.content,d,e);let g=document.createElement("div");g.className="gr-powered-by",g.innerHTML=`
|
|
7
7
|
Powered by <a href="https://growthrail.com" target="_blank" rel="noopener noreferrer">Growth Rail</a>
|
|
8
|
-
`,this.content.appendChild(
|
|
8
|
+
`,this.content.appendChild(g)}renderLinkView(e,t,n){let i=document.createElement("label");i.className="gr-label",i.textContent="Your unique link",e.appendChild(i);let o=document.createElement("div");o.className="gr-input-group";let s=document.createElement("input");s.className="gr-input",s.type="text",s.value=t,s.readOnly=!0;let l=document.createElement("button");l.className="gr-btn gr-btn--sm",l.textContent="Copy",l.onclick=async()=>{try{await navigator.clipboard.writeText(t);let d=l.textContent;l.textContent="Copied!",l.style.backgroundColor="#10b981",setTimeout(()=>{l.textContent=d,l.style.backgroundColor=""},2e3)}catch(d){console.error("Failed to copy",d)}},o.appendChild(s),o.appendChild(l),e.appendChild(o)}renderSocialShare(e,t,n){let i=document.createElement("div"),o=document.createElement("div");o.className="gr-share-label",o.innerHTML='<span class="gr-divider"></span>Share via<span class="gr-divider"></span>',i.appendChild(o);let s=document.createElement("div");s.className="gr-social-container",[{name:"Twitter",color:"#000000",icon:'<svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor"><path d="M18.244 2.25h3.308l-7.227 8.26 8.502 11.24H16.17l-5.214-6.817L4.99 21.75H1.68l7.73-8.835L1.254 2.25H8.08l4.713 6.231zm-1.161 17.52h1.833L7.084 4.126H5.117z"/></svg>',url:`https://twitter.com/intent/tweet?url=${encodeURIComponent(t)}&text=Check+this+out!`},{name:"Facebook",color:"#1877F2",icon:'<svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor"><path d="M9.101 23.691v-7.98H6.627v-3.667h2.474v-1.58c0-4.085 1.848-5.978 5.858-5.978.401 0 .955.042 1.468.103a8.68 8.68 0 0 1 1.141.195v3.325a8.623 8.623 0 0 0-.653-.036c-2.648 0-2.928 1.67-2.928 3.403v1.596h3.949l-.577 3.667h-3.372v7.98h-4.938z"/></svg>',url:`https://www.facebook.com/sharer/sharer.php?u=${encodeURIComponent(t)}`},{name:"LinkedIn",color:"#0A66C2",icon:'<svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor"><path d="M20.447 20.452h-3.554v-5.569c0-1.328-.027-3.037-1.852-3.037-1.853 0-2.136 1.445-2.136 2.939v5.667H9.351V9h3.414v1.561h.046c.477-.9 1.637-1.85 3.37-1.85 3.601 0 4.267 2.37 4.267 5.455v6.286zM5.337 7.433c-1.144 0-2.063-.926-2.063-2.065 0-1.138.92-2.063 2.063-2.063 1.14 0 2.064.925 2.064 2.063 0 1.139-.925 2.065-2.064 2.065zm1.782 13.019H3.555V9h3.564v11.452zM22.225 0H1.771C.792 0 0 .774 0 1.729v20.542C0 23.227.792 24 1.771 24h20.451C23.2 24 24 23.227 24 22.271V1.729C24 .774 23.2 0 22.222 0h.003z"/></svg>',url:`https://www.linkedin.com/sharing/share-offsite/?url=${encodeURIComponent(t)}`},{name:"WhatsApp",color:"#25D366",icon:'<svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor"><path d="M17.472 14.382c-.297-.149-1.758-.867-2.03-.967-.273-.099-.471-.148-.67.15-.197.297-.767.966-.94 1.164-.173.199-.347.223-.644.075-.297-.15-1.255-.463-2.39-1.475-.883-.788-1.48-1.761-1.653-2.059-.173-.297-.018-.458.13-.606.134-.133.298-.347.446-.52.149-.174.198-.298.298-.497.099-.198.05-.371-.025-.52-.075-.149-.669-1.612-.916-2.207-.242-.579-.487-.5-.669-.51-.173-.008-.371-.01-.57-.01-.198 0-.52.074-.792.372-.272.297-1.04 1.016-1.04 2.479 0 1.462 1.065 2.875 1.213 3.074.149.198 2.096 3.2 5.077 4.487.709.306 1.262.489 1.694.625.712.227 1.36.195 1.871.118.571-.085 1.758-.719 2.006-1.413.248-.694.248-1.289.173-1.413-.074-.124-.272-.198-.57-.347m-5.421 7.403h-.004a9.87 9.87 0 01-5.031-1.378l-.361-.214-3.741.982.998-3.648-.235-.374a9.86 9.86 0 01-1.51-5.26c.001-5.45 4.436-9.884 9.888-9.884 2.64 0 5.122 1.03 6.988 2.898a9.825 9.825 0 012.893 6.994c-.003 5.45-4.437 9.884-9.885 9.884m8.413-18.297A11.815 11.815 0 0012.05 0C5.495 0 .16 5.335.157 11.892c0 2.096.547 4.142 1.588 5.945L.057 24l6.305-1.654a11.882 11.882 0 005.683 1.448h.005c6.554 0 11.89-5.335 11.893-11.893a11.821 11.821 0 00-3.48-8.413z"/></svg>',url:`https://api.whatsapp.com/send?text=${encodeURIComponent(t)}`},{name:"Email",color:"#888888",icon:'<svg width="20" height="20" viewBox="0 0 24 24" fill="currentColor"><path d="M20 4H4c-1.1 0-1.99.9-1.99 2L2 18c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2zm0 4l-8 5-8-5V6l8 5 8-5v2z"/></svg>',url:`mailto:?subject=Check this out&body=${encodeURIComponent(t)}`}].forEach(d=>{let c=document.createElement("a");c.href=d.url,c.target="_blank",c.rel="noopener noreferrer",c.className="gr-social-btn",c.innerHTML=d.icon,c.title=`Share on ${d.name}`,c.onmouseenter=()=>{c.style.backgroundColor=d.color,c.style.color="#ffffff",c.style.borderColor=d.color},c.onmouseleave=()=>{c.style.backgroundColor="",c.style.color="",c.style.borderColor=""},s.appendChild(c)}),i.appendChild(s),e.appendChild(i)}bindEvents(){this.overlay&&(this.overlay.onclick=e=>{e.target===this.overlay&&this.hide()})}};var v=class{constructor(e){a(this,"options");a(this,"host",null);a(this,"shadow",null);a(this,"element",null);this.options=e}mount(){this.host||this.createDom()}unmount(){this.host&&this.host.parentNode&&document.body.removeChild(this.host),this.host=null,this.shadow=null,this.element=null}createDom(){this.host=document.createElement("div"),this.host.style.all="initial",this.host.style.position="absolute",this.host.style.zIndex="2147483646";let e={x:0,y:100};this.host.style.setProperty("--gr-offset-y",`${e.y}px`),this.shadow=this.host.attachShadow({mode:"open"});let t=document.createElement("style"),n=this.options.trigger?.displayMode||"edge";t.textContent=`
|
|
9
9
|
:host { all: initial; display: block; }
|
|
10
10
|
@keyframes gr-shimmer {
|
|
11
11
|
0% { transform: translateX(-150%) skewX(-15deg); }
|
|
@@ -72,24 +72,23 @@ var E=Object.defineProperty;var C=(g,e,t)=>e in g?E(g,e,{enumerable:!0,configura
|
|
|
72
72
|
<path d="M12 7H7.5a2.5 2.5 0 0 1 0-5C11 2 12 7 12 7z"></path>
|
|
73
73
|
<path d="M12 7h4.5a2.5 2.5 0 0 0 0-5C13 2 12 7 12 7z"></path>
|
|
74
74
|
</svg>
|
|
75
|
-
`,this.element.onclick=()=>{
|
|
75
|
+
`,this.element.onclick=()=>{x.showReferralDashboard()},this.shadow.appendChild(this.element),document.body.appendChild(this.host)}};var w=class{static show(e){if(typeof document>"u")return;let t=document.createElement("div");t.id="gr-banner-host",document.body.appendChild(t);let n=t.attachShadow({mode:"open"}),i=(e.banner.position||"center-top").toLowerCase(),o=i.includes("bottom")?"bottom":"top",s=i.includes("left")?"left":i.includes("right")?"right":"center",l="",d="";s==="center"?(l="left: 50%;",d="translateX(-50%)"):(l=`${s}: 20px;`,d="translateX(0)");let c=e.banner.themeColor||"#0070f3",g=document.createElement("style");g.textContent=`
|
|
76
76
|
.gr-banner {
|
|
77
77
|
position: fixed;
|
|
78
78
|
${o}: 20px;
|
|
79
79
|
${l}
|
|
80
80
|
z-index: 2147483647;
|
|
81
81
|
font-family: Inter, system-ui, -apple-system, sans-serif;
|
|
82
|
-
background:
|
|
83
|
-
color: #
|
|
82
|
+
background: var(--gr-theme-color);
|
|
83
|
+
color: #ffffff;
|
|
84
84
|
padding: 12px 20px;
|
|
85
85
|
border-radius: 12px;
|
|
86
|
-
box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.
|
|
86
|
+
box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.2), 0 4px 6px -2px rgba(0, 0, 0, 0.1);
|
|
87
87
|
display: flex;
|
|
88
88
|
align-items: center;
|
|
89
89
|
gap: 12px;
|
|
90
90
|
width: max-content;
|
|
91
91
|
max-width: 500px;
|
|
92
|
-
border: 1px solid #e5e7eb;
|
|
93
92
|
animation: gr-slide-in 0.4s cubic-bezier(0.16, 1, 0.3, 1) forwards;
|
|
94
93
|
box-sizing: border-box;
|
|
95
94
|
}
|
|
@@ -106,16 +105,16 @@ var E=Object.defineProperty;var C=(g,e,t)=>e in g?E(g,e,{enumerable:!0,configura
|
|
|
106
105
|
}
|
|
107
106
|
|
|
108
107
|
.gr-icon {
|
|
109
|
-
width:
|
|
110
|
-
height:
|
|
111
|
-
color: #
|
|
108
|
+
width: 20px;
|
|
109
|
+
height: 20px;
|
|
110
|
+
color: #ffffff;
|
|
112
111
|
flex-shrink: 0;
|
|
113
112
|
}
|
|
114
|
-
.gr-text { font-size: 14px; font-weight:
|
|
113
|
+
.gr-text { font-size: 14px; font-weight: 600; line-height: 1.4; margin: 0; color: #ffffff; flex: 1; }
|
|
115
114
|
.gr-close {
|
|
116
115
|
background: transparent;
|
|
117
116
|
border: none;
|
|
118
|
-
color:
|
|
117
|
+
color: rgba(255, 255, 255, 0.8);
|
|
119
118
|
cursor: pointer;
|
|
120
119
|
padding: 4px;
|
|
121
120
|
margin-left: 8px;
|
|
@@ -126,8 +125,8 @@ var E=Object.defineProperty;var C=(g,e,t)=>e in g?E(g,e,{enumerable:!0,configura
|
|
|
126
125
|
transition: all 0.2s;
|
|
127
126
|
flex-shrink: 0;
|
|
128
127
|
}
|
|
129
|
-
.gr-close:hover { background:
|
|
130
|
-
`;let p=document.createElement("div");p.className="gr-banner",p.innerHTML=`
|
|
128
|
+
.gr-close:hover { background: rgba(255, 255, 255, 0.2); color: #ffffff; }
|
|
129
|
+
`;let p=document.createElement("div");p.className="gr-banner",p.style.setProperty("--gr-theme-color",c),p.innerHTML=`
|
|
131
130
|
<svg class="gr-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
132
131
|
<polyline points="20 12 20 22 4 22 4 12"></polyline>
|
|
133
132
|
<rect x="2" y="7" width="20" height="5"></rect>
|
|
@@ -142,4 +141,4 @@ var E=Object.defineProperty;var C=(g,e,t)=>e in g?E(g,e,{enumerable:!0,configura
|
|
|
142
141
|
<line x1="6" y1="6" x2="18" y2="18"></line>
|
|
143
142
|
</svg>
|
|
144
143
|
</button>
|
|
145
|
-
`,p.querySelector(".gr-close")?.addEventListener("click",()=>{t.remove()}),n.appendChild(
|
|
144
|
+
`,p.querySelector(".gr-close")?.addEventListener("click",()=>{t.remove()}),n.appendChild(g),n.appendChild(p)}};var r=class r{constructor(){}static init(e){r.initialized||(r.options=e,r.api=new b(e),r.storage=new y({cookieDomain:e.cookieDomain}),r.initialized=!0,r.autoTrackReferral())}static isInitialized(){return r.initialized}static ensureInitialized(){if(!r.initialized)throw new Error("GrowthRail.init() must be called before using the SDK")}static async loadReferrerExperience(e){try{r.createReferralModal(e),e.trigger.show&&r.createTriggerButton(e.trigger)}catch(t){throw console.error("GrowthRail: Failed to load referrer experience",t),t}}static createReferralModal(e){r.referralModal=new m({isUserReady:()=>r.isUserReady(),getReferralLink:()=>r.currentUser?.referralLink||""},e)}static async autoTrackReferral(){if(typeof window>"u")return;let e=new URLSearchParams(window.location.search),t=e.get("referralCode"),n=e.get("rewardEventName");if(t){let i=await r.api.getNewUserExperience(),o=await r.trackReferral(t,n??void 0);r.storage.setTrackedReferral(o.referralTrackingId),i.banner.show&&w.show(i)}}static async initAppUser(e){r.ensureInitialized();let t=await r.api.initAppUser(e);return r.currentUser={...t,id:e},r.experience=t.referrerExperience,r.loadReferrerExperience(t.referrerExperience),r.userReadyResolver?r.userReadyResolver(r.currentUser):r.userReadyPromise=Promise.resolve(r.currentUser),t}static async trackReferral(e,t){return r.ensureInitialized(),r.api.trackReferral(e,t)}static async trackRewardEvent(e){r.ensureInitialized();let t=r.currentUser?.id;if(!t)throw new Error("GrowthRail: User must be initialized before tracking a reward event.");let n=r.storage.getTrackedReferral();if(!n)throw new Error("GrowthRail: Referral Tracking Id must be initialized before tracking a reward event.");return r.api.trackRewardEvent(t,n,e)}static getReferralLink(){if(!r.currentUser?.referralLink)throw new Error("GrowthRail: Referral Link not loaded or user not initialized");return r.currentUser.referralLink}static getReferralCode(){return r.currentUser?.referralCode}static getUserId(){return r.currentUser?.id}static isUserReady(){return r.currentUser!==null}static ensureUserReady(){return r.currentUser?Promise.resolve(r.currentUser):(r.userReadyPromise||(r.userReadyPromise=new Promise(e=>{r.userReadyResolver=e})),r.userReadyPromise)}static async showReferralDashboard(e){if(r.ensureInitialized(),!r.experience)throw new Error("GrowthRail: Experience not loaded");r.referralModal&&r.referralModal.hide(),r.referralModal?.show(e)}static createTriggerButton(e){if(typeof window>"u")return;if(!r.experience)throw new Error("GrowthRail: Experience not loaded");r.floatingButton&&r.floatingButton.unmount();let t={...r.experience?.trigger,...e},n={modal:{...r.experience.modal},trigger:t};r.floatingButton=new v(n),r.floatingButton.mount()}static destroyTriggerButton(){r.floatingButton&&(r.floatingButton.unmount(),r.floatingButton=null)}};a(r,"api"),a(r,"storage"),a(r,"options"),a(r,"currentUser",null),a(r,"initialized",!1),a(r,"referralModal",null),a(r,"floatingButton",null),a(r,"experience",null),a(r,"userReadyPromise",null),a(r,"userReadyResolver",null);var x=r;export{x as GrowthRail,m as ReferralModal};
|