@growth-rail/core 2.1.1 → 2.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @growth-rail/core
2
2
 
3
+ ## 2.2.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Debug mode
8
+
9
+ ## 2.2.0
10
+
11
+ ### Minor Changes
12
+
13
+ - Fixed issues and modified usage
14
+
3
15
  ## 2.1.1
4
16
 
5
17
  ### Patch Changes
package/README.md CHANGED
@@ -27,13 +27,14 @@ pnpm add @growth-rail/core
27
27
 
28
28
  ### Initialization
29
29
 
30
- Initialize the singleton instance with your API Key.
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
- apiKey: 'your_api_key_here'
36
+ projectSecretKey: 'your_project_secret_key_here',
37
+ debug: true // Enable verbose console logging
37
38
  });
38
39
 
39
40
  // Initialize a user session
package/dist/index.d.mts CHANGED
@@ -1,64 +1,113 @@
1
+ /**
2
+ * Configuration options for initializing the GrowthRail SDK.
3
+ */
1
4
  type GrowthRailOptions = {
2
- apiKey: string;
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;
11
+ /** Whether to enable debug mode for verbose console logging. */
12
+ debug?: boolean;
5
13
  };
14
+ /**
15
+ * Information about the current application user.
16
+ */
6
17
  type AppUserType = {
18
+ /** Custom attributes associated with the user. */
7
19
  attributes: Record<string, unknown>;
20
+ /** When the user was first seen by GrowthRail. */
8
21
  firstSeenAt: string;
22
+ /** When the user was last seen by GrowthRail. */
9
23
  lastSeenAt: string | null;
24
+ /** The unique identifier for the user. */
10
25
  uniqueId: string;
26
+ /** The user's unique referral code. */
11
27
  referralCode: string;
28
+ /** The user's unique referral link. */
12
29
  referralLink: string;
30
+ /** Configuration for the referral experience (trigger button and modal). */
13
31
  referrerExperience: ReferrerExperience;
14
32
  };
15
- type AppUserTypeWithId = AppUserType & {
16
- id: string;
17
- };
33
+ /**
34
+ * Referral link information.
35
+ */
18
36
  type ReferralLink = {
19
37
  referralCode: string;
20
38
  referralLink: string;
21
39
  };
22
- type EventPayload = {
23
- event: string;
24
- userId?: string;
25
- properties?: Record<string, any>;
26
- timestamp: string;
27
- };
40
+ /**
41
+ * Response from tracking a referral.
42
+ */
28
43
  type TrackReferralResponse = {
44
+ /** The ID used to track this referral conversion. */
29
45
  referralTrackingId: string;
46
+ /** Recommended promotional text to display to the new user. */
30
47
  promotionalText: string;
31
48
  };
49
+ /** Position options for the floating trigger button. */
32
50
  type TriggerButtonPosition = 'bottom-right' | 'bottom-left' | 'top-right' | 'top-left';
51
+ /**
52
+ * Configuration for the referral trigger button.
53
+ */
33
54
  type ReferrerTriggerButton = {
34
- show: boolean;
55
+ /** Where to position the button on the screen. */
35
56
  position: TriggerButtonPosition;
36
- displayMode: 'floating' | 'edge';
57
+ /** How the button is displayed (floating or attached to the edge). */
58
+ displayMode: 'floating' | 'edge' | 'none';
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. */
58
103
  themeColor: string;
59
104
  };
60
105
  }
61
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
+ */
62
111
  declare class GrowthRail {
63
112
  private static api;
64
113
  private static storage;
@@ -71,22 +120,82 @@ declare class GrowthRail {
71
120
  private static userReadyPromise;
72
121
  private static userReadyResolver;
73
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
+ */
74
129
  static init(options: GrowthRailOptions): void;
130
+ /**
131
+ * Returns whether the SDK has been initialized.
132
+ */
75
133
  static isInitialized(): boolean;
76
134
  private static ensureInitialized;
77
135
  private static loadReferrerExperience;
78
136
  private static createReferralModal;
79
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
+ */
80
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
+ */
81
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
+ */
82
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
+ */
83
167
  static getReferralLink(): string;
168
+ /**
169
+ * Gets the referral code for the currently logged-in user.
170
+ */
84
171
  static getReferralCode(): string | undefined;
172
+ /**
173
+ * Gets the unique ID for the currently logged-in user.
174
+ */
85
175
  static getUserId(): string | undefined;
176
+ /**
177
+ * Returns whether a user has been successfully initialized.
178
+ */
86
179
  static isUserReady(): boolean;
180
+ /**
181
+ * Returns a promise that resolves when the user is initialized and ready.
182
+ */
87
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
+ */
88
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
+ */
89
195
  static createTriggerButton(options: Partial<ReferrerTriggerButton>): void;
196
+ /**
197
+ * Removes the floating trigger button from the screen.
198
+ */
90
199
  static destroyTriggerButton(): void;
91
200
  }
92
201
 
@@ -112,4 +221,4 @@ declare class ReferralModal {
112
221
  private bindEvents;
113
222
  }
114
223
 
115
- export { type AppUserType, type AppUserTypeWithId, type EventPayload, GrowthRail, type GrowthRailOptions, type NewUserExperience, type ReferralLink, ReferralModal, type ReferralModalDependencies, type ReferrerExperience, type ReferrerModalOptions, type ReferrerTriggerButton, type TrackReferralResponse, type TriggerButtonPosition };
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,64 +1,113 @@
1
+ /**
2
+ * Configuration options for initializing the GrowthRail SDK.
3
+ */
1
4
  type GrowthRailOptions = {
2
- apiKey: string;
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;
11
+ /** Whether to enable debug mode for verbose console logging. */
12
+ debug?: boolean;
5
13
  };
14
+ /**
15
+ * Information about the current application user.
16
+ */
6
17
  type AppUserType = {
18
+ /** Custom attributes associated with the user. */
7
19
  attributes: Record<string, unknown>;
20
+ /** When the user was first seen by GrowthRail. */
8
21
  firstSeenAt: string;
22
+ /** When the user was last seen by GrowthRail. */
9
23
  lastSeenAt: string | null;
24
+ /** The unique identifier for the user. */
10
25
  uniqueId: string;
26
+ /** The user's unique referral code. */
11
27
  referralCode: string;
28
+ /** The user's unique referral link. */
12
29
  referralLink: string;
30
+ /** Configuration for the referral experience (trigger button and modal). */
13
31
  referrerExperience: ReferrerExperience;
14
32
  };
15
- type AppUserTypeWithId = AppUserType & {
16
- id: string;
17
- };
33
+ /**
34
+ * Referral link information.
35
+ */
18
36
  type ReferralLink = {
19
37
  referralCode: string;
20
38
  referralLink: string;
21
39
  };
22
- type EventPayload = {
23
- event: string;
24
- userId?: string;
25
- properties?: Record<string, any>;
26
- timestamp: string;
27
- };
40
+ /**
41
+ * Response from tracking a referral.
42
+ */
28
43
  type TrackReferralResponse = {
44
+ /** The ID used to track this referral conversion. */
29
45
  referralTrackingId: string;
46
+ /** Recommended promotional text to display to the new user. */
30
47
  promotionalText: string;
31
48
  };
49
+ /** Position options for the floating trigger button. */
32
50
  type TriggerButtonPosition = 'bottom-right' | 'bottom-left' | 'top-right' | 'top-left';
51
+ /**
52
+ * Configuration for the referral trigger button.
53
+ */
33
54
  type ReferrerTriggerButton = {
34
- show: boolean;
55
+ /** Where to position the button on the screen. */
35
56
  position: TriggerButtonPosition;
36
- displayMode: 'floating' | 'edge';
57
+ /** How the button is displayed (floating or attached to the edge). */
58
+ displayMode: 'floating' | 'edge' | 'none';
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. */
58
103
  themeColor: string;
59
104
  };
60
105
  }
61
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
+ */
62
111
  declare class GrowthRail {
63
112
  private static api;
64
113
  private static storage;
@@ -71,22 +120,82 @@ declare class GrowthRail {
71
120
  private static userReadyPromise;
72
121
  private static userReadyResolver;
73
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
+ */
74
129
  static init(options: GrowthRailOptions): void;
130
+ /**
131
+ * Returns whether the SDK has been initialized.
132
+ */
75
133
  static isInitialized(): boolean;
76
134
  private static ensureInitialized;
77
135
  private static loadReferrerExperience;
78
136
  private static createReferralModal;
79
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
+ */
80
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
+ */
81
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
+ */
82
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
+ */
83
167
  static getReferralLink(): string;
168
+ /**
169
+ * Gets the referral code for the currently logged-in user.
170
+ */
84
171
  static getReferralCode(): string | undefined;
172
+ /**
173
+ * Gets the unique ID for the currently logged-in user.
174
+ */
85
175
  static getUserId(): string | undefined;
176
+ /**
177
+ * Returns whether a user has been successfully initialized.
178
+ */
86
179
  static isUserReady(): boolean;
180
+ /**
181
+ * Returns a promise that resolves when the user is initialized and ready.
182
+ */
87
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
+ */
88
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
+ */
89
195
  static createTriggerButton(options: Partial<ReferrerTriggerButton>): void;
196
+ /**
197
+ * Removes the floating trigger button from the screen.
198
+ */
90
199
  static destroyTriggerButton(): void;
91
200
  }
92
201
 
@@ -112,4 +221,4 @@ declare class ReferralModal {
112
221
  private bindEvents;
113
222
  }
114
223
 
115
- export { type AppUserType, type AppUserTypeWithId, type EventPayload, GrowthRail, type GrowthRailOptions, type NewUserExperience, type ReferralLink, ReferralModal, type ReferralModalDependencies, type ReferrerExperience, type ReferrerModalOptions, type ReferrerTriggerButton, type TrackReferralResponse, type TriggerButtonPosition };
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,82 +1,15 @@
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 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",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 ${h?"gr-overlay--drawer":"gr-overlay--modal"}`,h?(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 h=document.createElement("button");h.className="gr-close-btn",h.innerHTML=`
1
+ "use strict";var b=Object.defineProperty;var C=Object.getOwnPropertyDescriptor;var T=Object.getOwnPropertyNames;var U=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 L=(p,e)=>{for(var t in e)b(p,t,{get:e[t],enumerable:!0})},z=(p,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of T(e))!U.call(p,o)&&o!==t&&b(p,o,{get:()=>e[o],enumerable:!(n=C(e,o))||n.enumerable});return p};var $=p=>z(b({},"__esModule",{value:!0}),p);var l=(p,e,t)=>P(p,typeof e!="symbol"?e+"":e,t);var A={};L(A,{GrowthRail:()=>R,ReferralModal:()=>y});module.exports=$(A);var M="[GrowthRail]",g={log(p,e,t,n){let o=`${M} [${e}] ${t}`;switch(p){case"error":console.error(o,n||"");break;case"warn":console.warn(o,n||"");break;default:console.log(o,n||"");break}}};var x=class{constructor(e){l(this,"baseUrl");l(this,"projectSecretKey");l(this,"_debug",!1);let t=typeof process<"u"&&process.env?.ENV_BASE_URL;this.baseUrl=t||"https://api.growthrail.dev",this.projectSecretKey=e.projectSecretKey}setDebug(e){this._debug=e}async request(e,t,n){let o={"Content-Type":"application/json","X-GrowthRail-ProjectSecret":this.projectSecretKey},i=Date.now();this._debug&&g.log("api","APIClient",`${t} ${e}`,{method:t,endpoint:e,body:n??null});try{let a=await fetch(`${this.baseUrl}${e}`,{method:t,headers:o,body:n?JSON.stringify(n):void 0}),s=Date.now()-i;if(!a.ok){let c="";try{c=await a.text()}catch{}let d=`GrowthRail API Error ${a.status} (${this.baseUrl}${e}): ${a.statusText} - ${c}`;throw this._debug&&g.log("api","APIClient",`\u2717 ${t} ${e}`,{method:t,endpoint:e,status:a.status,duration:s,error:c}),new Error(d)}return this._debug&&g.log("api","APIClient",`\u2713 ${t} ${e}`,{method:t,endpoint:e,status:a.status,duration:s}),a.json()}catch(a){let s=Date.now()-i;throw this._debug&&g.log("api","APIClient",`\u2717 ${t} ${e} \u2014 Network error`,{method:t,endpoint:e,duration:s,error:String(a)}),console.error("GrowthRail SDK Error:",a),a}}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 m=class m{constructor(e){l(this,"options",{});e&&(this.options=e)}setCookie(e,t,n=30){if(typeof document>"u")return;let o="";if(n){let a=new Date;a.setTime(a.getTime()+n*24*60*60*1e3),o=`; expires=${a.toUTCString()}`}let i="";this.options.cookieDomain&&(i=`; domain=${this.options.cookieDomain}`),document.cookie=`${e}=${t||""}${o}${i}; path=/; SameSite=Lax`}getCookie(e){if(typeof document>"u")return null;let t=`${e}=`,n=document.cookie.split(";");for(let o=0;o<n.length;o++){let i=n[o];for(;i.charAt(0)===" ";)i=i.substring(1,i.length);if(i.indexOf(t)===0)return i.substring(t.length,i.length)}return null}getReferralCode(){return this.getCookie(m.REFERRAL_CODE_KEY)}setReferralCode(e){this.setCookie(m.REFERRAL_CODE_KEY,e,30)}setTrackedReferral(e){this.setCookie(m.TRACKED_REFERRAL_KEY,e,30)}getTrackedReferral(){return this.getCookie(m.TRACKED_REFERRAL_KEY)}};l(m,"REFERRAL_CODE_KEY","gr_ref_code"),l(m,"TRACKED_REFERRAL_KEY","gr_tracked_referral");var v=m;var y=class{constructor(e,t){l(this,"referrerExperience");l(this,"deps");l(this,"host",null);l(this,"shadow",null);l(this,"overlay",null);l(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??{}}}},o=this.getTheme(),i={...o,colorPrimary:n.modal?.theme?.primaryColor||o.colorPrimary,colorBackground:n.modal?.theme?.backgroundColor||o.colorBackground,colorTint:n.modal?.theme?.tintColor||o.colorTint,tintAlpha:n.modal?.theme?.tintAlpha??o.tintAlpha},a=!!t;this.host=document.createElement("div"),this.host.style.all="initial",a?(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",i.colorPrimary),this.host.style.setProperty("--gr-text",i.colorText),this.host.style.setProperty("--gr-text-secondary",i.colorTextSecondary),this.host.style.setProperty("--gr-bg",i.colorBackground),this.host.style.setProperty("--gr-tint",i.colorTint);let s=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(i.colorTint),c=i.tintAlpha>1?i.tintAlpha/100:i.tintAlpha,d=s?`rgba(${parseInt(s[1],16)}, ${parseInt(s[2],16)}, ${parseInt(s[3],16)}, ${c})`:`rgba(0, 0, 0, ${c})`;this.host.style.setProperty("--gr-tint-rgba",d),this.host.style.setProperty("--gr-surface",i.colorSurface),this.host.style.setProperty("--gr-border",i.colorBorder),this.host.style.setProperty("--gr-error",i.colorError),this.host.style.setProperty("--gr-radius",i.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 f=n.modal.componentType==="drawer",k=n.trigger.position||"top-right",u=["gr-container"];a?(u.push("gr-container--embedded"),this.content.className=u.join(" "),this.renderInternalContent(i,e,a),this.shadow.appendChild(this.content),t&&t.appendChild(this.host)):(this.overlay=document.createElement("div"),this.overlay.className=`gr-overlay ${f?"gr-overlay--drawer":"gr-overlay--modal"}`,f?(u.push("gr-container--drawer"),k.includes("right")?u.push("gr-container--right"):u.push("gr-container--left"),k.includes("bottom")?u.push("gr-container--bottom"):u.push("gr-container--top")):u.push("gr-container--modal"),this.content.className=u.join(" "),this.renderInternalContent(i,e,a),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 f=document.createElement("button");f.className="gr-close-btn",f.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
- `,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=r?.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=`
6
+ `,f.onclick=()=>this.hide(),this.content.appendChild(f)}let o=document.createElement("div");o.className="gr-header";let i=document.createElement("div");i.className="gr-icon-lg",i.innerHTML="\u{1F381}",o.appendChild(i);let a=document.createElement("h3");a.className="gr-title",a.textContent=t?.title??this.referrerExperience.modal.title??"Invite Friends & Earn",o.appendChild(a);let s=document.createElement("p");if(s.className="gr-subtitle",s.textContent="Share your unique link and earn rewards for every friend who signs up.",o.appendChild(s),this.content.appendChild(o),!this.deps.isUserReady()){let f=document.createElement("div");f.className="gr-loading",f.textContent="Please log in to view your referral dashboard.",this.content.appendChild(f);return}let c=this.deps.getReferralLink(),d=document.createElement("div");this.renderLinkView(d,c,e),this.content.appendChild(d),c&&this.renderSocialShare(this.content,c,e);let h=document.createElement("div");h.className="gr-powered-by",h.innerHTML=`
7
7
  Powered by <a href="https://growthrail.com" target="_blank" rel="noopener noreferrer">Growth Rail</a>
8
- `,this.content.appendChild(g)}renderLinkView(e,r,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=r,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(r);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,r,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(r)}&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(r)}`},{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(r)}`},{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(r)}`},{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(r)}`}].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 r=document.createElement("style"),n=this.options.trigger?.displayMode||"edge";r.textContent=`
9
- :host { all: initial; display: block; }
10
- @keyframes gr-shimmer {
11
- 0% { transform: translateX(-150%) skewX(-15deg); }
12
- 50% { transform: translateX(150%) skewX(-15deg); }
13
- 100% { transform: translateX(150%) skewX(-15deg); }
14
- }
15
- .gr-btn {
16
- position: fixed;
17
- width: 50px;
18
- height: 50px;
19
- background: ${this.options.modal?.theme?.primaryColor||"#000"};
20
- box-shadow: 0 4px 6px -1px rgba(0,0,0,.1), 0 2px 4px -1px rgba(0,0,0,0.06);
21
- cursor: pointer;
22
- z-index: 2147483646;
23
- display: flex;
24
- align-items: center;
25
- justify-content: center;
26
- transition: transform .2s cubic-bezier(.34,1.56,.64,1), box-shadow .2s ease, width .2s, border-radius .2s;
27
- overflow: hidden;
28
- font-family: system-ui, -apple-system, sans-serif;
29
- box-sizing: border-box;
30
- }
31
- .gr-btn * { box-sizing: border-box; }
32
- .gr-btn:hover {
33
- transform: scale(1.05);
34
- box-shadow: 0 10px 15px -3px rgba(0,0,0,.1), 0 4px 6px -2px rgba(0,0,0,0.05);
35
- }
36
-
37
- /* Edge Mode Radii */
38
- .gr-btn--edge.gr-btn--right { border-radius: 8px 0 0 8px; padding-left: 4px; right: 0; }
39
- .gr-btn--edge.gr-btn--left { border-radius: 0 8px 8px 0; padding-right: 4px; left: 0; }
40
-
41
- /* Floating Mode Radii & Position */
42
- .gr-btn--floating {
43
- border-radius: 50%;
44
- box-shadow: 0 8px 24px color-mix(in srgb, ${this.options.modal?.theme?.primaryColor||"#000"}, transparent 60%);
45
- }
46
- .gr-btn--floating:hover {
47
- box-shadow: 0 12px 32px color-mix(in srgb, ${this.options.modal?.theme?.primaryColor||"#000"}, transparent 40%);
48
- }
49
- .gr-btn--floating.gr-btn--right { right: 20px; }
50
- .gr-btn--floating.gr-btn--left { left: 20px; }
51
-
52
- .gr-btn--bottom { bottom: var(--gr-offset-y); }
53
- .gr-btn--top { top: var(--gr-offset-y); }
54
-
55
- .gr-btn::after {
56
- content: '';
57
- position: absolute;
58
- top: 0;
59
- left: 0;
60
- width: 100%;
61
- height: 100%;
62
- background: linear-gradient(to right, transparent 0%, rgba(255,255,255,0.4) 50%, transparent 100%);
63
- transform: translateX(-150%) skewX(-15deg);
64
- animation: gr-shimmer 3s infinite;
65
- }
66
- .gr-icon { color: #fff; width: 24px; height: 24px; position: relative; z-index: 10; }
67
- `,this.shadow.appendChild(r),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
- <svg class="gr-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
69
- <polyline points="20 12 20 22 4 22 4 12"></polyline>
70
- <rect x="2" y="7" width="20" height="5"></rect>
71
- <line x1="12" y1="22" x2="12" y2="7"></line>
72
- <path d="M12 7H7.5a2.5 2.5 0 0 1 0-5C11 2 12 7 12 7z"></path>
73
- <path d="M12 7h4.5a2.5 2.5 0 0 0 0-5C13 2 12 7 12 7z"></path>
74
- </svg>
75
- `,this.element.onclick=()=>{x.showReferralDashboard()},this.shadow.appendChild(this.element),document.body.appendChild(this.host)}};var k=class{static show(e){if(typeof document>"u")return;let r=document.createElement("div");r.id="gr-banner-host",document.body.appendChild(r);let n=r.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=`
8
+ `,this.content.appendChild(h)}renderLinkView(e,t,n){let o=document.createElement("label");o.className="gr-label",o.textContent="Your unique link",e.appendChild(o);let i=document.createElement("div");i.className="gr-input-group";let a=document.createElement("input");a.className="gr-input",a.type="text",a.value=t,a.readOnly=!0;let s=document.createElement("button");s.className="gr-btn gr-btn--sm",s.textContent="Copy",s.onclick=async()=>{try{await navigator.clipboard.writeText(t);let c=s.textContent;s.textContent="Copied!",s.style.backgroundColor="#10b981",setTimeout(()=>{s.textContent=c,s.style.backgroundColor=""},2e3)}catch(c){console.error("Failed to copy",c)}},i.appendChild(a),i.appendChild(s),e.appendChild(i)}renderSocialShare(e,t,n){let o=document.createElement("div"),i=document.createElement("div");i.className="gr-share-label",i.innerHTML='<span class="gr-divider"></span>Share via<span class="gr-divider"></span>',o.appendChild(i);let a=document.createElement("div");a.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(c=>{let d=document.createElement("a");d.href=c.url,d.target="_blank",d.rel="noopener noreferrer",d.className="gr-social-btn",d.innerHTML=c.icon,d.title=`Share on ${c.name}`,d.onmouseenter=()=>{d.style.backgroundColor=c.color,d.style.color="#ffffff",d.style.borderColor=c.color},d.onmouseleave=()=>{d.style.backgroundColor="",d.style.color="",d.style.borderColor=""},a.appendChild(d)}),o.appendChild(a),e.appendChild(o)}bindEvents(){this.overlay&&(this.overlay.onclick=e=>{e.target===this.overlay&&this.hide()})}};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"}),o=(e.banner.position||"center-top").toLowerCase(),i=o.includes("bottom")?"bottom":"top",a=o.includes("left")?"left":o.includes("right")?"right":"center",s="",c="";a==="center"?(s="left: 50%;",c="translateX(-50%)"):(s=`${a}: 20px;`,c="translateX(0)");let d=e.banner.themeColor||"#0070f3",h=document.createElement("style");h.textContent=`
76
9
  .gr-banner {
77
10
  position: fixed;
78
- ${o}: 20px;
79
- ${l}
11
+ ${i}: 20px;
12
+ ${s}
80
13
  z-index: 2147483647;
81
14
  font-family: Inter, system-ui, -apple-system, sans-serif;
82
15
  background: var(--gr-theme-color);
@@ -96,11 +29,11 @@
96
29
  @keyframes gr-slide-in {
97
30
  from {
98
31
  opacity: 0;
99
- transform: ${d} translateY(${o==="top"?"-20px":"20px"});
32
+ transform: ${c} translateY(${i==="top"?"-20px":"20px"});
100
33
  }
101
34
  to {
102
35
  opacity: 1;
103
- transform: ${d} translateY(0);
36
+ transform: ${c} translateY(0);
104
37
  }
105
38
  }
106
39
 
@@ -126,7 +59,7 @@
126
59
  flex-shrink: 0;
127
60
  }
128
61
  .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=`
62
+ `;let f=document.createElement("div");f.className="gr-banner",f.style.setProperty("--gr-theme-color",d),f.innerHTML=`
130
63
  <svg class="gr-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
131
64
  <polyline points="20 12 20 22 4 22 4 12"></polyline>
132
65
  <rect x="2" y="7" width="20" height="5"></rect>
@@ -141,4 +74,4 @@
141
74
  <line x1="6" y1="6" x2="18" y2="18"></line>
142
75
  </svg>
143
76
  </button>
144
- `,h.querySelector(".gr-close")?.addEventListener("click",()=>{r.remove()}),n.appendChild(g),n.appendChild(h)}};var t=class t{constructor(){}static init(e){t.initialized||(t.options=e,t.api=new y(e),t.storage=new v({cookieDomain:e.cookieDomain}),t.initialized=!0,t.autoTrackReferral())}static isInitialized(){return t.initialized}static ensureInitialized(){if(!t.initialized)throw new Error("GrowthRail.init() must be called before using the SDK")}static async loadReferrerExperience(e){try{t.createReferralModal(e),e.trigger.show&&t.createTriggerButton(e.trigger)}catch(r){throw console.error("GrowthRail: Failed to load referrer experience",r),r}}static createReferralModal(e){t.referralModal=new m({isUserReady:()=>t.isUserReady(),getReferralLink:()=>t.currentUser?.referralLink||""},e)}static async autoTrackReferral(){if(typeof window>"u")return;let e=new URLSearchParams(window.location.search),r=e.get("referralCode"),n=e.get("rewardEventName");if(r){let i=await t.api.getNewUserExperience(),o=await t.trackReferral(r,n??void 0);t.storage.setTrackedReferral(o.referralTrackingId),i.banner.show&&k.show(i)}}static async initAppUser(e){t.ensureInitialized();let r=await t.api.initAppUser(e);return t.currentUser={...r,id:e},t.experience=r.referrerExperience,t.loadReferrerExperience(r.referrerExperience),t.userReadyResolver?t.userReadyResolver(t.currentUser):t.userReadyPromise=Promise.resolve(t.currentUser),r}static async trackReferral(e,r){return t.ensureInitialized(),t.api.trackReferral(e,r)}static async trackRewardEvent(e){t.ensureInitialized();let r=t.currentUser?.id;if(!r)throw new Error("GrowthRail: User must be initialized before tracking a reward event.");let n=t.storage.getTrackedReferral();if(!n)throw new Error("GrowthRail: Referral Tracking Id must be initialized before tracking a reward event.");return t.api.trackRewardEvent(r,n,e)}static getReferralLink(){if(!t.currentUser?.referralLink)throw new Error("GrowthRail: Referral Link not loaded or user not initialized");return t.currentUser.referralLink}static getReferralCode(){return t.currentUser?.referralCode}static getUserId(){return t.currentUser?.id}static isUserReady(){return t.currentUser!==null}static ensureUserReady(){return t.currentUser?Promise.resolve(t.currentUser):(t.userReadyPromise||(t.userReadyPromise=new Promise(e=>{t.userReadyResolver=e})),t.userReadyPromise)}static async showReferralDashboard(e){if(t.ensureInitialized(),!t.experience)throw new Error("GrowthRail: Experience not loaded");t.referralModal&&t.referralModal.hide(),t.referralModal?.show(e)}static createTriggerButton(e){if(typeof window>"u")return;if(!t.experience)throw new Error("GrowthRail: Experience not loaded");t.floatingButton&&t.floatingButton.unmount();let r={...t.experience?.trigger,...e},n={modal:{...t.experience.modal},trigger:r};t.floatingButton=new w(n),t.floatingButton.mount()}static destroyTriggerButton(){t.floatingButton&&(t.floatingButton.unmount(),t.floatingButton=null)}};a(t,"api"),a(t,"storage"),a(t,"options"),a(t,"currentUser",null),a(t,"initialized",!1),a(t,"referralModal",null),a(t,"floatingButton",null),a(t,"experience",null),a(t,"userReadyPromise",null),a(t,"userReadyResolver",null);var x=t;0&&(module.exports={GrowthRail,ReferralModal});
77
+ `,f.querySelector(".gr-close")?.addEventListener("click",()=>{t.remove()}),n.appendChild(h),n.appendChild(f)}};var r=class r{constructor(){}static init(e){r.initialized||(r.options=e,r.api=new x(e),e.debug&&(r.api.setDebug(!0),g.log("info","Core","SDK Initializing...",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.displayMode!=="none"&&r.createTriggerButton(e.trigger)}catch(t){throw console.error("GrowthRail: Failed to load referrer experience",t),t}}static createReferralModal(e){r.referralModal=new y({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){r.options.debug&&g.log("info","DeepLink",`Found referral code in URL: ${t}`,{refCode:t,refEventName:n});let o=await r.api.getNewUserExperience(),i=await r.trackReferral(t,n??void 0);r.storage.setTrackedReferral(i.referralTrackingId),o.banner.show&&(r.options.debug&&g.log("info","UI","Showing promotional banner"),w.show(o))}}static async initAppUser(e){r.ensureInitialized(),r.options.debug&&g.log("info","User",`Initializing user: ${e}`);let t=await r.api.initAppUser(e);return r.currentUser={...t,id:e},r.experience=t.referrerExperience,r.loadReferrerExperience(t.referrerExperience),r.options.debug&&g.log("success","User",`User initialized: ${e}`,t),r.userReadyResolver?r.userReadyResolver(r.currentUser):r.userReadyPromise=Promise.resolve(r.currentUser),t}static async trackReferral(e,t){r.ensureInitialized(),r.options.debug&&g.log("info","Referral",`Tracking referral: ${e}`,{referralCode:e,rewardEventName:t});let n=await r.api.trackReferral(e,t);return r.options.debug&&g.log("success","Referral","Referral tracked successfully",n),n}static async trackRewardEvent(e){r.ensureInitialized(),r.options.debug&&g.log("info","Reward",`Tracking reward event: ${e||"(default)"}`);let t=r.currentUser?.id;if(!t)throw r.options.debug&&g.log("error","Reward","User not initialized"),new Error("GrowthRail: User must be initialized before tracking a reward event.");let n=r.storage.getTrackedReferral();if(!n)throw r.options.debug&&g.log("error","Reward","Referral tracking ID not found"),new Error("GrowthRail: Referral Tracking Id must be initialized before tracking a reward event.");let o=await r.api.trackRewardEvent(t,n,e);return r.options.debug&&g.log("success","Reward","Reward event tracked successfully"),o}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&&(r.options.debug&&g.log("info","UI","Trigger button shown"),r.floatingButton.mount())}static destroyTriggerButton(){r.floatingButton&&(r.floatingButton.unmount(),r.floatingButton=null)}};l(r,"api"),l(r,"storage"),l(r,"options"),l(r,"currentUser",null),l(r,"initialized",!1),l(r,"referralModal",null),l(r,"floatingButton",null),l(r,"experience",null),l(r,"userReadyPromise",null),l(r,"userReadyResolver",null);var R=r;0&&(module.exports={GrowthRail,ReferralModal});
package/dist/index.mjs CHANGED
@@ -1,82 +1,15 @@
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 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 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",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 ${p?"gr-overlay--drawer":"gr-overlay--modal"}`,p?(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 p=document.createElement("button");p.className="gr-close-btn",p.innerHTML=`
1
+ var E=Object.defineProperty;var C=(f,e,t)=>e in f?E(f,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):f[e]=t;var l=(f,e,t)=>C(f,typeof e!="symbol"?e+"":e,t);var T="[GrowthRail]",p={log(f,e,t,n){let i=`${T} [${e}] ${t}`;switch(f){case"error":console.error(i,n||"");break;case"warn":console.warn(i,n||"");break;default:console.log(i,n||"");break}}};var b=class{constructor(e){l(this,"baseUrl");l(this,"projectSecretKey");l(this,"_debug",!1);let t=typeof process<"u"&&process.env?.ENV_BASE_URL;this.baseUrl=t||"https://api.growthrail.dev",this.projectSecretKey=e.projectSecretKey}setDebug(e){this._debug=e}async request(e,t,n){let i={"Content-Type":"application/json","X-GrowthRail-ProjectSecret":this.projectSecretKey},o=Date.now();this._debug&&p.log("api","APIClient",`${t} ${e}`,{method:t,endpoint:e,body:n??null});try{let a=await fetch(`${this.baseUrl}${e}`,{method:t,headers:i,body:n?JSON.stringify(n):void 0}),s=Date.now()-o;if(!a.ok){let c="";try{c=await a.text()}catch{}let d=`GrowthRail API Error ${a.status} (${this.baseUrl}${e}): ${a.statusText} - ${c}`;throw this._debug&&p.log("api","APIClient",`\u2717 ${t} ${e}`,{method:t,endpoint:e,status:a.status,duration:s,error:c}),new Error(d)}return this._debug&&p.log("api","APIClient",`\u2713 ${t} ${e}`,{method:t,endpoint:e,status:a.status,duration:s}),a.json()}catch(a){let s=Date.now()-o;throw this._debug&&p.log("api","APIClient",`\u2717 ${t} ${e} \u2014 Network error`,{method:t,endpoint:e,duration:s,error:String(a)}),console.error("GrowthRail SDK Error:",a),a}}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 m=class m{constructor(e){l(this,"options",{});e&&(this.options=e)}setCookie(e,t,n=30){if(typeof document>"u")return;let i="";if(n){let a=new Date;a.setTime(a.getTime()+n*24*60*60*1e3),i=`; expires=${a.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(m.REFERRAL_CODE_KEY)}setReferralCode(e){this.setCookie(m.REFERRAL_CODE_KEY,e,30)}setTrackedReferral(e){this.setCookie(m.TRACKED_REFERRAL_KEY,e,30)}getTrackedReferral(){return this.getCookie(m.TRACKED_REFERRAL_KEY)}};l(m,"REFERRAL_CODE_KEY","gr_ref_code"),l(m,"TRACKED_REFERRAL_KEY","gr_tracked_referral");var x=m;var y=class{constructor(e,t){l(this,"referrerExperience");l(this,"deps");l(this,"host",null);l(this,"shadow",null);l(this,"overlay",null);l(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},a=!!t;this.host=document.createElement("div"),this.host.style.all="initial",a?(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 s=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(o.colorTint),c=o.tintAlpha>1?o.tintAlpha/100:o.tintAlpha,d=s?`rgba(${parseInt(s[1],16)}, ${parseInt(s[2],16)}, ${parseInt(s[3],16)}, ${c})`:`rgba(0, 0, 0, ${c})`;this.host.style.setProperty("--gr-tint-rgba",d),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",u=["gr-container"];a?(u.push("gr-container--embedded"),this.content.className=u.join(" "),this.renderInternalContent(o,e,a),this.shadow.appendChild(this.content),t&&t.appendChild(this.host)):(this.overlay=document.createElement("div"),this.overlay.className=`gr-overlay ${g?"gr-overlay--drawer":"gr-overlay--modal"}`,g?(u.push("gr-container--drawer"),R.includes("right")?u.push("gr-container--right"):u.push("gr-container--left"),R.includes("bottom")?u.push("gr-container--bottom"):u.push("gr-container--top")):u.push("gr-container--modal"),this.content.className=u.join(" "),this.renderInternalContent(o,e,a),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 g=document.createElement("button");g.className="gr-close-btn",g.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
- `,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=`
6
+ `,g.onclick=()=>this.hide(),this.content.appendChild(g)}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 a=document.createElement("h3");a.className="gr-title",a.textContent=t?.title??this.referrerExperience.modal.title??"Invite Friends & Earn",i.appendChild(a);let s=document.createElement("p");if(s.className="gr-subtitle",s.textContent="Share your unique link and earn rewards for every friend who signs up.",i.appendChild(s),this.content.appendChild(i),!this.deps.isUserReady()){let g=document.createElement("div");g.className="gr-loading",g.textContent="Please log in to view your referral dashboard.",this.content.appendChild(g);return}let c=this.deps.getReferralLink(),d=document.createElement("div");this.renderLinkView(d,c,e),this.content.appendChild(d),c&&this.renderSocialShare(this.content,c,e);let h=document.createElement("div");h.className="gr-powered-by",h.innerHTML=`
7
7
  Powered by <a href="https://growthrail.com" target="_blank" rel="noopener noreferrer">Growth Rail</a>
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 y=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
- :host { all: initial; display: block; }
10
- @keyframes gr-shimmer {
11
- 0% { transform: translateX(-150%) skewX(-15deg); }
12
- 50% { transform: translateX(150%) skewX(-15deg); }
13
- 100% { transform: translateX(150%) skewX(-15deg); }
14
- }
15
- .gr-btn {
16
- position: fixed;
17
- width: 50px;
18
- height: 50px;
19
- background: ${this.options.modal?.theme?.primaryColor||"#000"};
20
- box-shadow: 0 4px 6px -1px rgba(0,0,0,.1), 0 2px 4px -1px rgba(0,0,0,0.06);
21
- cursor: pointer;
22
- z-index: 2147483646;
23
- display: flex;
24
- align-items: center;
25
- justify-content: center;
26
- transition: transform .2s cubic-bezier(.34,1.56,.64,1), box-shadow .2s ease, width .2s, border-radius .2s;
27
- overflow: hidden;
28
- font-family: system-ui, -apple-system, sans-serif;
29
- box-sizing: border-box;
30
- }
31
- .gr-btn * { box-sizing: border-box; }
32
- .gr-btn:hover {
33
- transform: scale(1.05);
34
- box-shadow: 0 10px 15px -3px rgba(0,0,0,.1), 0 4px 6px -2px rgba(0,0,0,0.05);
35
- }
36
-
37
- /* Edge Mode Radii */
38
- .gr-btn--edge.gr-btn--right { border-radius: 8px 0 0 8px; padding-left: 4px; right: 0; }
39
- .gr-btn--edge.gr-btn--left { border-radius: 0 8px 8px 0; padding-right: 4px; left: 0; }
40
-
41
- /* Floating Mode Radii & Position */
42
- .gr-btn--floating {
43
- border-radius: 50%;
44
- box-shadow: 0 8px 24px color-mix(in srgb, ${this.options.modal?.theme?.primaryColor||"#000"}, transparent 60%);
45
- }
46
- .gr-btn--floating:hover {
47
- box-shadow: 0 12px 32px color-mix(in srgb, ${this.options.modal?.theme?.primaryColor||"#000"}, transparent 40%);
48
- }
49
- .gr-btn--floating.gr-btn--right { right: 20px; }
50
- .gr-btn--floating.gr-btn--left { left: 20px; }
51
-
52
- .gr-btn--bottom { bottom: var(--gr-offset-y); }
53
- .gr-btn--top { top: var(--gr-offset-y); }
54
-
55
- .gr-btn::after {
56
- content: '';
57
- position: absolute;
58
- top: 0;
59
- left: 0;
60
- width: 100%;
61
- height: 100%;
62
- background: linear-gradient(to right, transparent 0%, rgba(255,255,255,0.4) 50%, transparent 100%);
63
- transform: translateX(-150%) skewX(-15deg);
64
- animation: gr-shimmer 3s infinite;
65
- }
66
- .gr-icon { color: #fff; width: 24px; height: 24px; position: relative; z-index: 10; }
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
- <svg class="gr-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
69
- <polyline points="20 12 20 22 4 22 4 12"></polyline>
70
- <rect x="2" y="7" width="20" height="5"></rect>
71
- <line x1="12" y1="22" x2="12" y2="7"></line>
72
- <path d="M12 7H7.5a2.5 2.5 0 0 1 0-5C11 2 12 7 12 7z"></path>
73
- <path d="M12 7h4.5a2.5 2.5 0 0 0 0-5C13 2 12 7 12 7z"></path>
74
- </svg>
75
- `,this.element.onclick=()=>{v.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=`
8
+ `,this.content.appendChild(h)}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 a=document.createElement("input");a.className="gr-input",a.type="text",a.value=t,a.readOnly=!0;let s=document.createElement("button");s.className="gr-btn gr-btn--sm",s.textContent="Copy",s.onclick=async()=>{try{await navigator.clipboard.writeText(t);let c=s.textContent;s.textContent="Copied!",s.style.backgroundColor="#10b981",setTimeout(()=>{s.textContent=c,s.style.backgroundColor=""},2e3)}catch(c){console.error("Failed to copy",c)}},o.appendChild(a),o.appendChild(s),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 a=document.createElement("div");a.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(c=>{let d=document.createElement("a");d.href=c.url,d.target="_blank",d.rel="noopener noreferrer",d.className="gr-social-btn",d.innerHTML=c.icon,d.title=`Share on ${c.name}`,d.onmouseenter=()=>{d.style.backgroundColor=c.color,d.style.color="#ffffff",d.style.borderColor=c.color},d.onmouseleave=()=>{d.style.backgroundColor="",d.style.color="",d.style.borderColor=""},a.appendChild(d)}),i.appendChild(a),e.appendChild(i)}bindEvents(){this.overlay&&(this.overlay.onclick=e=>{e.target===this.overlay&&this.hide()})}};var v=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",a=i.includes("left")?"left":i.includes("right")?"right":"center",s="",c="";a==="center"?(s="left: 50%;",c="translateX(-50%)"):(s=`${a}: 20px;`,c="translateX(0)");let d=e.banner.themeColor||"#0070f3",h=document.createElement("style");h.textContent=`
76
9
  .gr-banner {
77
10
  position: fixed;
78
11
  ${o}: 20px;
79
- ${l}
12
+ ${s}
80
13
  z-index: 2147483647;
81
14
  font-family: Inter, system-ui, -apple-system, sans-serif;
82
15
  background: var(--gr-theme-color);
@@ -96,11 +29,11 @@ var E=Object.defineProperty;var C=(h,e,t)=>e in h?E(h,e,{enumerable:!0,configura
96
29
  @keyframes gr-slide-in {
97
30
  from {
98
31
  opacity: 0;
99
- transform: ${d} translateY(${o==="top"?"-20px":"20px"});
32
+ transform: ${c} translateY(${o==="top"?"-20px":"20px"});
100
33
  }
101
34
  to {
102
35
  opacity: 1;
103
- transform: ${d} translateY(0);
36
+ transform: ${c} translateY(0);
104
37
  }
105
38
  }
106
39
 
@@ -126,7 +59,7 @@ var E=Object.defineProperty;var C=(h,e,t)=>e in h?E(h,e,{enumerable:!0,configura
126
59
  flex-shrink: 0;
127
60
  }
128
61
  .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=`
62
+ `;let g=document.createElement("div");g.className="gr-banner",g.style.setProperty("--gr-theme-color",d),g.innerHTML=`
130
63
  <svg class="gr-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
131
64
  <polyline points="20 12 20 22 4 22 4 12"></polyline>
132
65
  <rect x="2" y="7" width="20" height="5"></rect>
@@ -141,4 +74,4 @@ var E=Object.defineProperty;var C=(h,e,t)=>e in h?E(h,e,{enumerable:!0,configura
141
74
  <line x1="6" y1="6" x2="18" y2="18"></line>
142
75
  </svg>
143
76
  </button>
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 m(e),r.storage=new x({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 b({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 y(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 v=r;export{v as GrowthRail,b as ReferralModal};
77
+ `,g.querySelector(".gr-close")?.addEventListener("click",()=>{t.remove()}),n.appendChild(h),n.appendChild(g)}};var r=class r{constructor(){}static init(e){r.initialized||(r.options=e,r.api=new b(e),e.debug&&(r.api.setDebug(!0),p.log("info","Core","SDK Initializing...",e)),r.storage=new x({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.displayMode!=="none"&&r.createTriggerButton(e.trigger)}catch(t){throw console.error("GrowthRail: Failed to load referrer experience",t),t}}static createReferralModal(e){r.referralModal=new y({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){r.options.debug&&p.log("info","DeepLink",`Found referral code in URL: ${t}`,{refCode:t,refEventName:n});let i=await r.api.getNewUserExperience(),o=await r.trackReferral(t,n??void 0);r.storage.setTrackedReferral(o.referralTrackingId),i.banner.show&&(r.options.debug&&p.log("info","UI","Showing promotional banner"),v.show(i))}}static async initAppUser(e){r.ensureInitialized(),r.options.debug&&p.log("info","User",`Initializing user: ${e}`);let t=await r.api.initAppUser(e);return r.currentUser={...t,id:e},r.experience=t.referrerExperience,r.loadReferrerExperience(t.referrerExperience),r.options.debug&&p.log("success","User",`User initialized: ${e}`,t),r.userReadyResolver?r.userReadyResolver(r.currentUser):r.userReadyPromise=Promise.resolve(r.currentUser),t}static async trackReferral(e,t){r.ensureInitialized(),r.options.debug&&p.log("info","Referral",`Tracking referral: ${e}`,{referralCode:e,rewardEventName:t});let n=await r.api.trackReferral(e,t);return r.options.debug&&p.log("success","Referral","Referral tracked successfully",n),n}static async trackRewardEvent(e){r.ensureInitialized(),r.options.debug&&p.log("info","Reward",`Tracking reward event: ${e||"(default)"}`);let t=r.currentUser?.id;if(!t)throw r.options.debug&&p.log("error","Reward","User not initialized"),new Error("GrowthRail: User must be initialized before tracking a reward event.");let n=r.storage.getTrackedReferral();if(!n)throw r.options.debug&&p.log("error","Reward","Referral tracking ID not found"),new Error("GrowthRail: Referral Tracking Id must be initialized before tracking a reward event.");let i=await r.api.trackRewardEvent(t,n,e);return r.options.debug&&p.log("success","Reward","Reward event tracked successfully"),i}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&&(r.options.debug&&p.log("info","UI","Trigger button shown"),r.floatingButton.mount())}static destroyTriggerButton(){r.floatingButton&&(r.floatingButton.unmount(),r.floatingButton=null)}};l(r,"api"),l(r,"storage"),l(r,"options"),l(r,"currentUser",null),l(r,"initialized",!1),l(r,"referralModal",null),l(r,"floatingButton",null),l(r,"experience",null),l(r,"userReadyPromise",null),l(r,"userReadyResolver",null);var w=r;export{w as GrowthRail,y as ReferralModal};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@growth-rail/core",
3
- "version": "2.1.1",
3
+ "version": "2.2.1",
4
4
  "description": "Growth Rail SDK",
5
5
  "keywords": [
6
6
  "sdk",
@@ -39,4 +39,4 @@
39
39
  "publishConfig": {
40
40
  "access": "public"
41
41
  }
42
- }
42
+ }