@growth-rail/react-native 2.0.5 → 2.0.6

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,11 @@
1
1
  # @growth-rail/react-native
2
2
 
3
+ ## 2.0.6
4
+
5
+ ### Patch Changes
6
+
7
+ - Safe area
8
+
3
9
  ## 2.0.5
4
10
 
5
11
  ### Patch Changes
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var Te=Object.create;var q=Object.defineProperty;var ve=Object.getOwnPropertyDescriptor;var Le=Object.getOwnPropertyNames;var Se=Object.getPrototypeOf,Ie=Object.prototype.hasOwnProperty;var De=(n,e,r)=>e in n?q(n,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):n[e]=r;var Be=(n,e)=>{for(var r in e)q(n,r,{get:e[r],enumerable:!0})},he=(n,e,r,l)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of Le(e))!Ie.call(n,i)&&i!==r&&q(n,i,{get:()=>e[i],enumerable:!(l=ve(e,i))||l.enumerable});return n};var H=(n,e,r)=>(r=n!=null?Te(Se(n)):{},he(e||!n||!n.__esModule?q(r,"default",{value:n,enumerable:!0}):r,n)),Oe=n=>he(q({},"__esModule",{value:!0}),n);var te=(n,e,r)=>De(n,typeof e!="symbol"?e+"":e,r);var Ee={};Be(Ee,{GrowthRailProvider:()=>ye,ReferralDashboard:()=>ne,TriggerButton:()=>se,useGrowthRail:()=>Re});module.exports=Oe(Ee);var a=H(require("react")),L=require("react-native"),be=H(require("react-native-play-install-referrer"));var Ve="[GrowthRail]",g={log(n,e,r,l){let i=`${Ve} [${e}] ${r}`;switch(n){case"error":console.error(i,l||"");break;case"warn":console.warn(i,l||"");break;default:console.log(i,l||"");break}}};var oe=class{constructor(e){te(this,"baseUrl");te(this,"projectSecretKey");te(this,"_debug",!1);let r=typeof process<"u"&&process.env?.ENV_BASE_URL;this.baseUrl=r||"https://api.growthrail.dev",this.projectSecretKey=e.projectSecretKey}setDebug(e){this._debug=e}async request(e,r,l){let i={"Content-Type":"application/json","X-GrowthRail-ProjectSecret":this.projectSecretKey,Origin:this.baseUrl},R=Date.now();this._debug&&g.log("api","APIClient",`${r} ${e}`,{method:r,endpoint:e,body:l??null});try{let p=await fetch(`${this.baseUrl}${e}`,{method:r,headers:i,body:l?JSON.stringify(l):void 0}),k=Date.now()-R;if(!p.ok){let c="";try{c=await p.text()}catch{}let C=`GrowthRail API Error ${p.status} (${this.baseUrl}${e}): ${p.statusText} - ${c}`;throw this._debug&&g.log("api","APIClient",`\u2717 ${r} ${e}`,{method:r,endpoint:e,status:p.status,duration:k,error:c}),new Error(C)}return this._debug&&g.log("api","APIClient",`\u2713 ${r} ${e}`,{method:r,endpoint:e,status:p.status,duration:k}),p.json()}catch(p){let k=Date.now()-R;throw this._debug&&g.log("api","APIClient",`\u2717 ${r} ${e} \u2014 Network error`,{method:r,endpoint:e,duration:k,error:String(p)}),console.error("GrowthRail SDK Error:",p),p}}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,r){return this.request("/api/v1/sdk/track-referral","POST",{referralCode:e,rewardEventName:r})}async trackRewardEvent(e,r,l){return this.request("/api/v1/sdk/track-reward-event","POST",{refereeId:e,referralTrackingId:r,eventName:l})}async checkDeferredDeepLink(e){return this.request("/api/v1/sdk/match-link","POST",{fingerprint:e})}};var Y=H(require("@react-native-async-storage/async-storage")),ie={TRACKED_REFERRAL:"growth-rail-tracked-referral",IS_FIRST_LAUNCH:"growth-rail-is-first-launch"},B=class{static async setTrackedReferral(e){await Y.default.setItem(ie.TRACKED_REFERRAL,e)}static async getTrackedReferral(){return await Y.default.getItem(ie.TRACKED_REFERRAL)}static async isFirstLaunch(){return await Y.default.getItem(ie.IS_FIRST_LAUNCH)===null?(await Y.default.setItem(ie.IS_FIRST_LAUNCH,"false"),!0):!1}};var o=H(require("react")),t=require("react-native");var{width:Ne,height:pe}=t.Dimensions.get("window"),ne=({visible:n,options:e,onClose:r})=>{let l=ae(),[i,R]=(0,o.useState)(null),[p,k]=(0,o.useState)(!1),[c,C]=(0,o.useState)(!1),h=(0,o.useRef)(new t.Animated.Value(0)).current,O=(0,o.useRef)(new t.Animated.Value(0)).current,I=(0,t.useColorScheme)(),v=(e?.appearance||I||"light")==="dark",N=e?.title||"Invite Friends & Earn",V=e?.theme?.primaryColor||"#2563eb",E=(e?.componentType||"modal")==="drawer",F=e?.position||"bottom-right",f={background:v?"#111827":"#ffffff",text:v?"#f9fafb":"#111827",textSecondary:v?"#9ca3af":"#6b7280",border:v?"#374151":"#e5e7eb",inputBg:v?"#1f2937":"#f9fafb",closeBtnBg:v?"#1f2937":"#f3f4f6",closeIcon:v?"#6b7280":"#9ca3af",drawerHandle:v?"#4b5563":"#e5e7eb",overlay:"#000000",overlayOpacity:.5};(0,o.useEffect)(()=>{n?(i||Q(),t.Animated.parallel([t.Animated.timing(O,{toValue:1,duration:300,useNativeDriver:!0}),t.Animated.spring(h,{toValue:1,useNativeDriver:!0,tension:50,friction:8})]).start()):(h.setValue(0),O.setValue(0))},[n]);let j=()=>{t.Animated.parallel([t.Animated.timing(O,{toValue:0,duration:250,useNativeDriver:!0}),t.Animated.timing(h,{toValue:0,duration:250,useNativeDriver:!0})]).start(()=>{r()})},Q=async()=>{k(!0);try{if(l.isUserReady){let P=await l.getReferralLink();R(P||null)}}catch(P){console.error("GrowthRail: Failed to load referral link",P)}finally{k(!1)}},le=()=>{i&&(t.Clipboard.setString(i),C(!0),setTimeout(()=>C(!1),2e3))},$=P=>{if(!i)return;let D="",A=encodeURIComponent(i),_=encodeURIComponent("Check this out!");switch(P){case"twitter":D=`https://twitter.com/intent/tweet?url=${A}&text=${_}`;break;case"facebook":D=`https://www.facebook.com/sharer/sharer.php?u=${A}`;break;case"linkedin":D=`https://www.linkedin.com/sharing/share-offsite/?url=${A}`;break;case"whatsapp":D=`whatsapp://send?text=${_}%20${A}`;break;case"email":D=`mailto:?subject=Check this out&body=${_}%20${A}`;break}D&&t.Linking.openURL(D).catch(()=>{})},Z=()=>f.overlay,z=[];E?z=[{translateY:h.interpolate({inputRange:[0,1],outputRange:[pe,0]})}]:z=[{scale:h.interpolate({inputRange:[0,1],outputRange:[.9,1]})},{translateY:h.interpolate({inputRange:[0,1],outputRange:[20,0]})}];let ee=F.includes("top"),K=F.includes("right"),ke=F.includes("left"),M=E?{position:"absolute",bottom:0,left:0,right:0,width:"100%",maxHeight:"90%"}:{};return o.default.createElement(t.Modal,{visible:n,transparent:!0,animationType:"none",onRequestClose:j},o.default.createElement(t.View,{style:s.fullScreen},o.default.createElement(t.Animated.View,{style:[s.overlay,{backgroundColor:Z(),opacity:O.interpolate({inputRange:[0,1],outputRange:[0,f.overlayOpacity]})}]},o.default.createElement(t.TouchableOpacity,{style:s.fullScreen,activeOpacity:1,onPress:j})),o.default.createElement(t.Animated.View,{style:[E?M:s.centeredModalContainer,{backgroundColor:f.background,transform:z},E&&{borderTopLeftRadius:24,borderTopRightRadius:24,borderBottomLeftRadius:0,borderBottomRightRadius:0},!E&&{borderRadius:24,opacity:h,borderColor:f.border,borderWidth:v?1:0}]},o.default.createElement(t.View,{style:s.contentWrapper},E&&o.default.createElement(t.View,{style:[s.drawerHandle,{backgroundColor:f.drawerHandle}]}),o.default.createElement(t.TouchableOpacity,{style:[s.closeBtn,{backgroundColor:f.closeBtnBg}],onPress:j},o.default.createElement(t.Text,{style:[s.closeIcon,{color:f.closeIcon}]},"\u2715")),o.default.createElement(t.ScrollView,{contentContainerStyle:s.scrollContent,showsVerticalScrollIndicator:!1},o.default.createElement(t.View,{style:s.header},o.default.createElement(t.View,{style:s.iconLgContainer},o.default.createElement(t.View,{style:s.bowContainerLg},o.default.createElement(t.View,{style:[s.bowLoopLg,s.bowLeftLg,{borderColor:V}]}),o.default.createElement(t.View,{style:[s.bowLoopLg,s.bowRightLg,{borderColor:V}]})),o.default.createElement(t.View,{style:[s.giftLidLg,{backgroundColor:V}]}),o.default.createElement(t.View,{style:[s.giftBodyLg,{borderColor:V}]},o.default.createElement(t.View,{style:[s.ribbonVerticalLg,{backgroundColor:"#fff",opacity:.3}]}))),o.default.createElement(t.Text,{style:[s.title,{color:f.text}]},N),o.default.createElement(t.Text,{style:[s.subtitle,{color:f.textSecondary}]},e?.description||"Share your unique link and earn rewards for every friend who signs up.")),l.isUserReady?p?o.default.createElement(t.ActivityIndicator,{size:"large",color:V,style:s.loader}):o.default.createElement(t.View,{style:s.mainContent},o.default.createElement(t.Text,{style:[s.label,{color:f.textSecondary}]},"YOUR UNIQUE LINK"),o.default.createElement(t.View,{style:[s.inputGroup,{backgroundColor:f.inputBg,borderColor:f.border}]},o.default.createElement(t.Text,{numberOfLines:1,style:[s.input,{color:f.text}]},i||"Initializing..."),o.default.createElement(t.TouchableOpacity,{style:[s.copyBtn,{backgroundColor:c?"#10b981":V}],onPress:le},o.default.createElement(t.Text,{style:s.copyBtnText},c?"Copied!":"Copy"))),o.default.createElement(t.View,{style:s.shareLabelContainer},o.default.createElement(t.View,{style:[s.divider,{backgroundColor:f.border}]}),o.default.createElement(t.Text,{style:[s.shareLabel,{color:f.textSecondary}]},"Share via"),o.default.createElement(t.View,{style:[s.divider,{backgroundColor:f.border}]})),o.default.createElement(t.View,{style:s.socialContainer},o.default.createElement(X,{platform:"twitter",color:v?"#FFFFFF":"#000000",onPress:()=>$("twitter"),icon:"\u{1D54F}",borderColor:f.border,bgColor:f.background}),o.default.createElement(X,{platform:"facebook",color:"#1877F2",onPress:()=>$("facebook"),icon:"f",borderColor:f.border,bgColor:f.background}),o.default.createElement(X,{platform:"linkedin",color:"#0A66C2",onPress:()=>$("linkedin"),icon:"in",borderColor:f.border,bgColor:f.background}),o.default.createElement(X,{platform:"whatsapp",color:"#25D366",onPress:()=>$("whatsapp"),icon:"W",borderColor:f.border,bgColor:f.background}),o.default.createElement(X,{platform:"email",color:f.textSecondary,onPress:()=>$("email"),icon:"\u2709",borderColor:f.border,bgColor:f.background}))):o.default.createElement(t.View,{style:[s.loadingBox,{backgroundColor:f.inputBg,borderColor:f.border}]},o.default.createElement(t.Text,{style:{color:f.textSecondary,textAlign:"center"}},"Please log in to view your referral dashboard.")),o.default.createElement(t.View,{style:s.footer},o.default.createElement(t.Text,{style:[s.poweredBy,{color:f.textSecondary}]},"Powered by ",o.default.createElement(t.Text,{style:[s.brand,{color:V}],onPress:()=>t.Linking.openURL("https://growthrail.com")},"Growth Rail"))))))))},X=({color:n,onPress:e,icon:r,borderColor:l,bgColor:i})=>o.default.createElement(t.TouchableOpacity,{style:[s.socialBtn,{borderColor:l,backgroundColor:i}],onPress:e},o.default.createElement(t.Text,{style:[s.socialIcon,{color:n}]},r)),s=t.StyleSheet.create({fullScreen:{flex:1},overlay:{...t.StyleSheet.absoluteFillObject},centeredModalContainer:{width:"90%",maxWidth:400,alignSelf:"center",marginTop:pe*.15,overflow:"hidden",shadowColor:"#000",shadowOffset:{width:0,height:20},shadowOpacity:.25,shadowRadius:30,elevation:20},contentWrapper:{paddingTop:t.Platform.OS==="ios"?20:0},drawerHandle:{width:40,height:4,backgroundColor:"#e5e7eb",borderRadius:2,alignSelf:"center",marginTop:12},scrollContent:{padding:32,alignItems:"center"},closeBtn:{position:"absolute",top:20,right:20,zIndex:10,width:32,height:32,borderRadius:16,backgroundColor:"#f3f4f6",justifyContent:"center",alignItems:"center"},closeIcon:{fontSize:14,color:"#9ca3af"},header:{alignItems:"center",marginBottom:28,width:"100%"},socialIcon:{fontSize:18,fontWeight:"bold"},title:{fontSize:22,fontWeight:"700",letterSpacing:-.5,marginBottom:8,textAlign:"center"},subtitle:{fontSize:14,lineHeight:20,textAlign:"center",paddingHorizontal:10},loadingBox:{padding:16,backgroundColor:"#f9fafb",borderRadius:12,width:"100%",alignItems:"center",borderWidth:1,borderColor:"#e5e7eb",marginTop:20},loader:{marginVertical:20},mainContent:{width:"100%"},label:{fontSize:12,fontWeight:"600",color:"#6b7280",marginBottom:8,letterSpacing:.5},inputGroup:{flexDirection:"row",alignItems:"center",backgroundColor:"#f9fafb",borderWidth:1,borderColor:"#e5e7eb",borderRadius:12,padding:6,marginBottom:24},input:{flex:1,paddingHorizontal:12,fontSize:14,color:"#111827",fontFamily:t.Platform.OS==="ios"?"Menlo":"monospace"},copyBtn:{paddingVertical:8,paddingHorizontal:16,borderRadius:8,justifyContent:"center",alignItems:"center"},copyBtnText:{color:"#fff",fontSize:13,fontWeight:"600"},shareLabelContainer:{flexDirection:"row",alignItems:"center",marginBottom:16,marginTop:8},divider:{flex:1,height:1,backgroundColor:"#e5e7eb"},shareLabel:{marginHorizontal:12,fontSize:13,fontWeight:"500",color:"#6b7280"},socialContainer:{flexDirection:"row",justifyContent:"center",gap:12},socialBtn:{width:44,height:44,borderRadius:22,backgroundColor:"#fff",borderWidth:1,justifyContent:"center",alignItems:"center"},iconLgContainer:{width:60,height:60,justifyContent:"center",alignItems:"center",marginBottom:16},bowContainerLg:{flexDirection:"row",position:"absolute",top:2,zIndex:2},bowLoopLg:{width:20,height:16,borderWidth:3,borderColor:"#e5e7eb",borderRadius:10},bowLeftLg:{marginRight:-2,transform:[{rotate:"-15deg"}]},bowRightLg:{marginLeft:-2,transform:[{rotate:"15deg"}]},giftLidLg:{width:44,height:10,backgroundColor:"#f3f4f6",borderRadius:2,marginTop:12,zIndex:3},giftBodyLg:{width:36,height:24,borderWidth:3,borderTopWidth:0,borderBottomLeftRadius:4,borderBottomRightRadius:4,justifyContent:"center",alignItems:"center",marginTop:-2},ribbonVerticalLg:{width:4,height:"100%",opacity:.1},footer:{marginTop:32,alignItems:"center"},poweredBy:{fontSize:11,color:"#9ca3af"},brand:{fontWeight:"600",textDecorationLine:"underline"}});var T=H(require("react")),m=require("react-native"),se=({onPress:n,options:e})=>{let r=e?.modal?.theme?.primaryColor||"#2563eb",l=e?.trigger?.position||"bottom-right",R=(e?.trigger?.displayMode||"floating")==="edge",p=l.includes("right"),k=l.includes("top"),c=(0,T.useRef)(new m.Animated.Value(-1)).current;(0,T.useEffect)(()=>{let I=()=>{c.setValue(-1),m.Animated.timing(c,{toValue:2,duration:3e3,easing:m.Easing.linear,useNativeDriver:!0}).start(()=>{setTimeout(I,1e3)})};I()},[]);let C=c.interpolate({inputRange:[-1,2],outputRange:R?[-50,100]:[-60,120]}),h={"bottom-right":{bottom:100,right:0},"bottom-left":{bottom:100,left:0},"top-right":{top:100,right:0},"top-left":{top:100,left:0}};R||(h["bottom-right"]={bottom:30,right:20},h["bottom-left"]={bottom:30,left:20},h["top-right"]={top:60,right:20},h["top-left"]={top:60,left:20});let O=()=>T.default.createElement(m.View,{style:x.iconContainer},T.default.createElement(m.View,{style:x.bowContainer},T.default.createElement(m.View,{style:[x.bowLoop,x.bowLeft]}),T.default.createElement(m.View,{style:[x.bowLoop,x.bowRight]})),T.default.createElement(m.View,{style:x.giftLid}),T.default.createElement(m.View,{style:x.giftBody},T.default.createElement(m.View,{style:x.ribbonVertical})));return T.default.createElement(m.TouchableOpacity,{style:[R?x.edgeButton:x.floatingButton,{backgroundColor:r},h[l],R&&(p?x.edgeRight:x.edgeLeft)],onPress:n,activeOpacity:.9},T.default.createElement(m.View,{style:x.content},O()),T.default.createElement(m.Animated.View,{style:[x.shimmer,{transform:[{translateX:C},{skewX:"-15deg"}]}]}))},x=m.StyleSheet.create({floatingButton:{position:"absolute",width:60,height:60,borderRadius:30,justifyContent:"center",alignItems:"center",overflow:"hidden",shadowColor:"#000",shadowOffset:{width:0,height:8},shadowOpacity:.2,shadowRadius:12,elevation:8,zIndex:2147483646},edgeButton:{position:"absolute",width:50,height:50,justifyContent:"center",alignItems:"center",overflow:"hidden",shadowColor:"#000",shadowOffset:{width:0,height:4},shadowOpacity:.1,shadowRadius:8,elevation:4,zIndex:2147483646},edgeRight:{borderTopLeftRadius:8,borderBottomLeftRadius:8,paddingLeft:4},edgeLeft:{borderTopRightRadius:8,borderBottomRightRadius:8,paddingRight:4},content:{justifyContent:"center",alignItems:"center"},iconContainer:{width:28,height:28,justifyContent:"center",alignItems:"center"},bowContainer:{flexDirection:"row",position:"absolute",top:0,zIndex:2},bowLoop:{width:10,height:8,borderWidth:2,borderColor:"#fff",borderRadius:5},bowLeft:{marginRight:-1,transform:[{rotate:"-15deg"}]},bowRight:{marginLeft:-1,transform:[{rotate:"15deg"}]},giftLid:{width:22,height:5,backgroundColor:"#fff",borderRadius:1,marginTop:6,zIndex:3},giftBody:{width:18,height:12,borderWidth:2,borderColor:"#fff",borderTopWidth:0,borderBottomLeftRadius:2,borderBottomRightRadius:2,justifyContent:"center",alignItems:"center",marginTop:-1},ribbonVertical:{width:2,height:"100%",backgroundColor:"#fff",opacity:.8},shimmer:{position:"absolute",top:0,left:0,width:50,height:"100%",backgroundColor:"rgba(255, 255, 255, 0.25)"}});var S=H(require("react")),y=require("react-native"),{width:Ue}=y.Dimensions.get("window"),we=({visible:n,options:e,onClose:r})=>{let l=(0,S.useRef)(new y.Animated.Value(0)).current,[i,R]=(0,S.useState)(n),p=e.position.includes("bottom")?"bottom":"top",k=e.position.includes("left")?"left":e.position.includes("right")?"right":"center";if((0,S.useEffect)(()=>{n?(R(!0),y.Animated.spring(l,{toValue:1,useNativeDriver:!0,tension:50,friction:8}).start()):y.Animated.timing(l,{toValue:0,duration:250,useNativeDriver:!0}).start(()=>{R(!1)})},[n]),!i)return null;let c=l.interpolate({inputRange:[0,1],outputRange:[p==="top"?-100:100,0]}),C=l.interpolate({inputRange:[0,1],outputRange:[0,1]}),h={position:"absolute",[p]:y.Platform.OS==="ios"?60:40,zIndex:9999};return k==="center"?(h.left=20,h.right=20,h.alignItems="center"):h[k]=20,S.default.createElement(y.Animated.View,{style:[h,{transform:[{translateY:c}],opacity:C}]},S.default.createElement(y.View,{style:[J.banner,{backgroundColor:e.themeColor||"#2563eb"}]},S.default.createElement(y.Text,{style:J.icon},"\u{1F381}"),S.default.createElement(y.Text,{style:J.text},e.text),S.default.createElement(y.TouchableOpacity,{onPress:r,style:J.closeBtn},S.default.createElement(y.Text,{style:J.closeIcon},"\u2715"))))},J=y.StyleSheet.create({banner:{flexDirection:"row",alignItems:"center",padding:12,paddingHorizontal:16,borderRadius:12,shadowColor:"#000",shadowOffset:{width:0,height:4},shadowOpacity:.15,shadowRadius:10,elevation:5,maxWidth:Ue-40},icon:{fontSize:18,marginRight:10},text:{color:"#fff",fontSize:14,fontWeight:"600",flex:1},closeBtn:{marginLeft:10,padding:4},closeIcon:{color:"rgba(255, 255, 255, 0.8)",fontSize:14,fontWeight:"bold"}});var me=(0,a.createContext)(void 0),ye=({children:n,userId:e,debug:r=!1,...l})=>{let[i,R]=(0,a.useState)(!1),[p,k]=(0,a.useState)(!1),[c,C]=(0,a.useState)(null),h=(0,a.useRef)(new oe(l)),O=(0,a.useRef)(!1),I=(0,a.useRef)(null),[de,v]=(0,a.useState)(!1),[N,V]=(0,a.useState)(),[fe,E]=(0,a.useState)(!1),[F,f]=(0,a.useState)(),[j,Q]=(0,a.useState)(!1),[le,$]=(0,a.useState)();(0,a.useEffect)(()=>{h.current.setDebug(r),r&&g.log("info","Provider","Debug mode enabled")},[r]);let Z=(0,a.useCallback)(()=>{let{width:d,height:u}=L.Dimensions.get("window"),w=Intl.DateTimeFormat().resolvedOptions().locale,b=L.PixelRatio.get(),U,re;if(L.Platform.OS==="android"){let ce=L.Platform.constants;U=ce.Model,re=ce.Brand||ce.Manufacturer}return{os:L.Platform.OS,platform:L.Platform.OS,osVersion:String(L.Platform.Version),screenWidth:d,screenHeight:u,timezoneOffsetInMinutes:String(new Date().getTimezoneOffset()),locale:w,language:w,deviceModel:U,deviceBrand:re,pixelRatio:b}},[]),z=(0,a.useCallback)(async(d,u)=>{r&&g.log("info","Referral",`Tracking referral code: ${d}`,{referralCode:d,rewardEventName:u});let w=await h.current.trackReferral(d,u);return await B.setTrackedReferral(w.referralTrackingId),r&&g.log("success","Referral",`Referral tracked \u2192 ${w.referralTrackingId}`,w),w},[r]),ee=(0,a.useCallback)(async d=>{try{r&&g.log("info","DeepLink",`Received deep link: ${d}`);let u=d.match(/[?&]referralCode=([^&]+)/);u&&(console.log("GrowthRail: Tracking referral from deep link",u[1]),r&&g.log("info","DeepLink",`Found referral code in deep link: ${u[1]}`),await z(u[1]))}catch(u){console.warn("GrowthRail: Error handling deep link",u),r&&g.log("error","DeepLink","Deep link handling failed",{error:String(u)})}},[z,r]),K=(0,a.useCallback)(async()=>{try{r&&g.log("info","Deferred","Checking deferred deep link via fingerprint");let d=Z(),{referralTrackingId:u}=await h.current.checkDeferredDeepLink(d);u?(console.log("GrowthRail: Found deferred referral via fingerprinting",u),r&&g.log("success","Deferred",`Deferred referral matched \u2192 ${u}`),await B.setTrackedReferral(u)):r&&g.log("info","Deferred","No deferred referral match found")}catch(d){console.warn("GrowthRail: Fingerprint check failed",d),r&&g.log("error","Deferred","Fingerprint check failed",{error:String(d)})}},[Z,r]),ke=(0,a.useCallback)(()=>new Promise(d=>{be.default.getInstallReferrerInfo(async(u,w)=>{if(!w&&u&&u.installReferrer)try{let U=decodeURIComponent(u.installReferrer).match(/[?&]referralCode=([^&]+)/);if(U){let{referralTrackingId:re}=await z(U[1]);await B.setTrackedReferral(re),console.log("GrowthRail: Tracked referral via Install Referrer")}}catch(b){console.warn("GrowthRail: Failed to process install referrer",b)}else await K();d()})}),[z,K]),M=(0,a.useCallback)(async d=>{if(c?.id===d&&p)return r&&g.log("info","User",`User ${d} already initialized, skipping`),c;r&&g.log("info","User",`Initializing user: ${d}`);let u=(async()=>{try{let w=await h.current.initAppUser(d),b={...w,id:d};return C(b),k(!0),r&&g.log("success","User",`User initialized: ${d}`,{referralCode:w.referralCode,referralLink:w.referralLink}),w.referrerExperience?.trigger?.displayMode!=="none"&&(E(!0),r&&g.log("info","UI","Trigger button shown (server-configured)")),b}catch(w){throw I.current=null,r&&g.log("error","User",`User init failed for ${d}`,{error:String(w)}),w}})();return I.current=u,u},[c,p,r]),P=(0,a.useCallback)(async d=>{r&&g.log("info","Reward",`Tracking reward event: ${d||"(default)"}`);let u=c;!u&&I.current&&(u=await I.current);let w=u?.id||e;if(!w)throw r&&g.log("error","Reward","Cannot track reward \u2014 user not initialized"),new Error("GrowthRail: User must be initialized before tracking a reward event.");let b=await B.getTrackedReferral();if(!b){console.warn("GrowthRail: No referral tracking ID found. Reward event not attributed."),r&&g.log("warn","Reward","No referral tracking ID in storage \u2014 reward not attributed");return}let U=await h.current.trackRewardEvent(w,b,d);return r&&g.log("success","Reward",`Reward event tracked for user ${w}`),U},[c,e,r]),D=(0,a.useCallback)(async()=>await B.getTrackedReferral(),[]),A=(0,a.useCallback)(async()=>{if(c)return c.referralLink;if(I.current)return(await I.current).referralLink},[c]);(0,a.useEffect)(()=>{if(O.current)return;O.current=!0,r&&g.log("info","Provider","SDK initializing\u2026",{platform:L.Platform.OS});let d;return(async()=>{try{let b=await L.Linking.getInitialURL();r&&g.log("info","DeepLink",`Initial URL: ${b??"(none)"}`),b&&await ee(b)}catch(b){console.warn("GrowthRail: Error getting initial URL",b)}d=L.Linking.addEventListener("url",({url:b})=>ee(b));let w=await B.isFirstLaunch();r&&g.log("info","Provider",`First launch: ${w}`),w&&await K(),e&&await M(e);try{let b=await h.current.getNewUserExperience(),U=await B.getTrackedReferral();b.banner?.show&&U&&($(b.banner),Q(!0),r&&g.log("info","UI","Banner shown for new user experience"))}catch(b){r&&g.log("warn","Provider","New user experience fetch failed",{error:String(b)})}R(!0),r&&g.log("success","Provider","SDK initialization complete \u2713")})(),()=>{d&&d.remove()}},[r,ee,K,M,e]),(0,a.useEffect)(()=>{i&&e&&c?.id!==e&&M(e)},[e,i]);let _=(0,a.useCallback)(d=>{V(d),v(!0)},[]),ge=(0,a.useCallback)(()=>{v(!1)},[]),ue=(0,a.useMemo)(()=>({isInitialized:i,isUserReady:p,currentUser:c,referralCode:c?.referralCode,referralLink:c?.referralLink,showDashboard:_,hideDashboard:ge,initUser:M,trackReward:P,getReferralTrackingId:D,getReferralLink:A,isDebugEnabled:r}),[i,p,c,_,ge,M,P,D,A,r]),W=c?.referrerExperience,Ce=(0,a.useMemo)(()=>({...W?.modal,...N,appearance:N?.appearance||W?.modal?.appearance||l.appearance,theme:{...W?.modal?.theme||{},...N?.theme||{}}}),[W?.modal,N,l.appearance]),xe=(0,a.useMemo)(()=>({...W,...F,trigger:{...W?.trigger||{},...F?.trigger||{}}}),[W,F]);return i?a.default.createElement(me.Provider,{value:ue},n,a.default.createElement(ne,{visible:de,options:Ce,onClose:()=>v(!1)}),fe&&a.default.createElement(se,{options:xe,onPress:()=>ue.showDashboard()}),j&&a.default.createElement(we,{visible:j,options:le,onClose:()=>Q(!1)})):null},ae=()=>{let n=(0,a.useContext)(me);if(!n)throw new Error("useGrowthRail must be used within a GrowthRailProvider");return n};var G=require("react");var Re=()=>{let[n,e]=(0,G.useState)(!1),[r,l]=(0,G.useState)(null),i=ae(),R=(0,G.useCallback)(async k=>{e(!0),l(null);try{return await i.initUser(k)}catch(c){let C=c instanceof Error?c:new Error(String(c));throw l(C),C}finally{e(!1)}},[i]),p=(0,G.useCallback)(async k=>{e(!0),l(null);try{await i.trackReward(k)}catch(c){let C=c instanceof Error?c:new Error(String(c));throw l(C),C}finally{e(!1)}},[i]);return(0,G.useMemo)(()=>({initAppUser:R,trackRewardEvent:p,showReferralDashboard:i.showDashboard,hideReferralDashboard:i.hideDashboard,getReferralTrackingId:i.getReferralTrackingId,getReferralLink:i.getReferralLink,isLoading:n,isInitialized:i.isInitialized,isUserReady:i.isUserReady,error:r,isDebugEnabled:i.isDebugEnabled}),[R,p,i.showDashboard,i.hideDashboard,i.getReferralTrackingId,i.getReferralLink,n,i.isInitialized,i.isUserReady,r,i.isDebugEnabled])};0&&(module.exports={GrowthRailProvider,ReferralDashboard,TriggerButton,useGrowthRail});
1
+ "use strict";var Ie=Object.create;var q=Object.defineProperty;var Se=Object.getOwnPropertyDescriptor;var De=Object.getOwnPropertyNames;var Be=Object.getPrototypeOf,Ve=Object.prototype.hasOwnProperty;var Oe=(n,r,e)=>r in n?q(n,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[r]=e;var Ue=(n,r)=>{for(var e in r)q(n,e,{get:r[e],enumerable:!0})},pe=(n,r,e,l)=>{if(r&&typeof r=="object"||typeof r=="function")for(let i of De(r))!Ve.call(n,i)&&i!==e&&q(n,i,{get:()=>r[i],enumerable:!(l=Se(r,i))||l.enumerable});return n};var H=(n,r,e)=>(e=n!=null?Ie(Be(n)):{},pe(r||!n||!n.__esModule?q(e,"default",{value:n,enumerable:!0}):e,n)),Ee=n=>pe(q({},"__esModule",{value:!0}),n);var te=(n,r,e)=>Oe(n,typeof r!="symbol"?r+"":r,e);var Pe={};Ue(Pe,{GrowthRailProvider:()=>Ce,ReferralDashboard:()=>ne,TriggerButton:()=>se,useGrowthRail:()=>xe});module.exports=Ee(Pe);var a=H(require("react")),L=require("react-native"),Re=H(require("react-native-play-install-referrer"));var Ae="[GrowthRail]",g={log(n,r,e,l){let i=`${Ae} [${r}] ${e}`;switch(n){case"error":console.error(i,l||"");break;case"warn":console.warn(i,l||"");break;default:console.log(i,l||"");break}}};var oe=class{constructor(r){te(this,"baseUrl");te(this,"projectSecretKey");te(this,"_debug",!1);let e=typeof process<"u"&&process.env?.ENV_BASE_URL;this.baseUrl=e||"https://api.growthrail.dev",this.projectSecretKey=r.projectSecretKey}setDebug(r){this._debug=r}async request(r,e,l){let i={"Content-Type":"application/json","X-GrowthRail-ProjectSecret":this.projectSecretKey,Origin:this.baseUrl},I=Date.now();this._debug&&g.log("api","APIClient",`${e} ${r}`,{method:e,endpoint:r,body:l??null});try{let u=await fetch(`${this.baseUrl}${r}`,{method:e,headers:i,body:l?JSON.stringify(l):void 0}),b=Date.now()-I;if(!u.ok){let c="";try{c=await u.text()}catch{}let R=`GrowthRail API Error ${u.status} (${this.baseUrl}${r}): ${u.statusText} - ${c}`;throw this._debug&&g.log("api","APIClient",`\u2717 ${e} ${r}`,{method:e,endpoint:r,status:u.status,duration:b,error:c}),new Error(R)}return this._debug&&g.log("api","APIClient",`\u2713 ${e} ${r}`,{method:e,endpoint:r,status:u.status,duration:b}),u.json()}catch(u){let b=Date.now()-I;throw this._debug&&g.log("api","APIClient",`\u2717 ${e} ${r} \u2014 Network error`,{method:e,endpoint:r,duration:b,error:String(u)}),console.error("GrowthRail SDK Error:",u),u}}async getNewUserExperience(){return this.request("/api/v1/sdk/new-user-experience","POST")}async initAppUser(r){return this.request("/api/v1/sdk/init-app-user","POST",{clientProvidedId:r})}async trackReferral(r,e){return this.request("/api/v1/sdk/track-referral","POST",{referralCode:r,rewardEventName:e})}async trackRewardEvent(r,e,l){return this.request("/api/v1/sdk/track-reward-event","POST",{refereeId:r,referralTrackingId:e,eventName:l})}async checkDeferredDeepLink(r){return this.request("/api/v1/sdk/match-link","POST",{fingerprint:r})}};var Y=H(require("@react-native-async-storage/async-storage")),ie={TRACKED_REFERRAL:"growth-rail-tracked-referral",IS_FIRST_LAUNCH:"growth-rail-is-first-launch"},O=class{static async setTrackedReferral(r){await Y.default.setItem(ie.TRACKED_REFERRAL,r)}static async getTrackedReferral(){return await Y.default.getItem(ie.TRACKED_REFERRAL)}static async isFirstLaunch(){return await Y.default.getItem(ie.IS_FIRST_LAUNCH)===null?(await Y.default.setItem(ie.IS_FIRST_LAUNCH,"false"),!0):!1}};var o=H(require("react")),t=require("react-native"),he=require("react-native-safe-area-context");var{width:He,height:we}=t.Dimensions.get("window"),ne=({visible:n,options:r,onClose:e})=>{let l=ae(),[i,I]=(0,o.useState)(null),[u,b]=(0,o.useState)(!1),[c,R]=(0,o.useState)(!1),C=(0,he.useSafeAreaInsets)(),m=(0,o.useRef)(new t.Animated.Value(0)).current,S=(0,o.useRef)(new t.Animated.Value(0)).current,M=(0,t.useColorScheme)(),x=(r?.appearance||M||"light")==="dark",le=r?.title||"Invite Friends & Earn",U=r?.theme?.primaryColor||"#2563eb",B=(r?.componentType||"modal")==="drawer",Z=r?.position||"bottom-right",d={background:x?"#111827":"#ffffff",text:x?"#f9fafb":"#111827",textSecondary:x?"#9ca3af":"#6b7280",border:x?"#374151":"#e5e7eb",inputBg:x?"#1f2937":"#f9fafb",closeBtnBg:x?"#1f2937":"#f3f4f6",closeIcon:x?"#6b7280":"#9ca3af",drawerHandle:x?"#4b5563":"#e5e7eb",overlay:"#000000",overlayOpacity:.5};(0,o.useEffect)(()=>{n?(i||ce(),t.Animated.parallel([t.Animated.timing(S,{toValue:1,duration:300,useNativeDriver:!0}),t.Animated.spring(m,{toValue:1,useNativeDriver:!0,tension:50,friction:8})]).start()):(m.setValue(0),S.setValue(0))},[n]);let W=()=>{t.Animated.parallel([t.Animated.timing(S,{toValue:0,duration:250,useNativeDriver:!0}),t.Animated.timing(m,{toValue:0,duration:250,useNativeDriver:!0})]).start(()=>{e()})},ce=async()=>{b(!0);try{if(l.isUserReady){let z=await l.getReferralLink();I(z||null)}}catch(z){console.error("GrowthRail: Failed to load referral link",z)}finally{b(!1)}},de=()=>{i&&(t.Clipboard.setString(i),R(!0),setTimeout(()=>R(!1),2e3))},A=z=>{if(!i)return;let V="",P=encodeURIComponent(i),_=encodeURIComponent("Check this out!");switch(z){case"twitter":V=`https://twitter.com/intent/tweet?url=${P}&text=${_}`;break;case"facebook":V=`https://www.facebook.com/sharer/sharer.php?u=${P}`;break;case"linkedin":V=`https://www.linkedin.com/sharing/share-offsite/?url=${P}`;break;case"whatsapp":V=`whatsapp://send?text=${_}%20${P}`;break;case"email":V=`mailto:?subject=Check this out&body=${_}%20${P}`;break}V&&t.Linking.openURL(V).catch(()=>{})},N=()=>d.overlay,F=[];B?F=[{translateY:m.interpolate({inputRange:[0,1],outputRange:[we,0]})}]:F=[{scale:m.interpolate({inputRange:[0,1],outputRange:[.9,1]})},{translateY:m.interpolate({inputRange:[0,1],outputRange:[20,0]})}];let K=Z.includes("top"),Te=Z.includes("right"),j=Z.includes("left"),ee=B?{position:"absolute",bottom:0,left:0,right:0,width:"100%",maxHeight:"90%"}:{};return o.default.createElement(t.Modal,{visible:n,transparent:!0,animationType:"none",onRequestClose:W},o.default.createElement(t.View,{style:s.fullScreen},o.default.createElement(t.Animated.View,{style:[s.overlay,{backgroundColor:N(),opacity:S.interpolate({inputRange:[0,1],outputRange:[0,d.overlayOpacity]})}]},o.default.createElement(t.TouchableOpacity,{style:s.fullScreen,activeOpacity:1,onPress:W})),o.default.createElement(t.Animated.View,{style:[B?ee:s.centeredModalContainer,{backgroundColor:d.background,transform:F},B&&{borderTopLeftRadius:24,borderTopRightRadius:24,borderBottomLeftRadius:0,borderBottomRightRadius:0,paddingBottom:C.bottom},!B&&{borderRadius:24,opacity:m,borderColor:d.border,borderWidth:x?1:0}]},o.default.createElement(t.View,{style:[s.contentWrapper,{paddingTop:Math.max(C.top,16)}]},B&&o.default.createElement(t.View,{style:[s.drawerHandle,{backgroundColor:d.drawerHandle}]}),o.default.createElement(t.TouchableOpacity,{style:[s.closeBtn,{backgroundColor:d.closeBtnBg,top:Math.max(C.top,16)}],onPress:W},o.default.createElement(t.Text,{style:[s.closeIcon,{color:d.closeIcon}]},"\u2715")),o.default.createElement(t.ScrollView,{contentContainerStyle:s.scrollContent,showsVerticalScrollIndicator:!1},o.default.createElement(t.View,{style:s.header},o.default.createElement(t.View,{style:s.iconLgContainer},o.default.createElement(t.View,{style:s.bowContainerLg},o.default.createElement(t.View,{style:[s.bowLoopLg,s.bowLeftLg,{borderColor:U}]}),o.default.createElement(t.View,{style:[s.bowLoopLg,s.bowRightLg,{borderColor:U}]})),o.default.createElement(t.View,{style:[s.giftLidLg,{backgroundColor:U}]}),o.default.createElement(t.View,{style:[s.giftBodyLg,{borderColor:U}]},o.default.createElement(t.View,{style:[s.ribbonVerticalLg,{backgroundColor:"#fff",opacity:.3}]}))),o.default.createElement(t.Text,{style:[s.title,{color:d.text}]},le),o.default.createElement(t.Text,{style:[s.subtitle,{color:d.textSecondary}]},r?.description||"Share your unique link and earn rewards for every friend who signs up.")),l.isUserReady?u?o.default.createElement(t.ActivityIndicator,{size:"large",color:U,style:s.loader}):o.default.createElement(t.View,{style:s.mainContent},o.default.createElement(t.Text,{style:[s.label,{color:d.textSecondary}]},"YOUR UNIQUE LINK"),o.default.createElement(t.View,{style:[s.inputGroup,{backgroundColor:d.inputBg,borderColor:d.border}]},o.default.createElement(t.Text,{numberOfLines:1,style:[s.input,{color:d.text}]},i||"Initializing..."),o.default.createElement(t.TouchableOpacity,{style:[s.copyBtn,{backgroundColor:c?"#10b981":U}],onPress:de},o.default.createElement(t.Text,{style:s.copyBtnText},c?"Copied!":"Copy"))),o.default.createElement(t.View,{style:s.shareLabelContainer},o.default.createElement(t.View,{style:[s.divider,{backgroundColor:d.border}]}),o.default.createElement(t.Text,{style:[s.shareLabel,{color:d.textSecondary}]},"Share via"),o.default.createElement(t.View,{style:[s.divider,{backgroundColor:d.border}]})),o.default.createElement(t.View,{style:s.socialContainer},o.default.createElement(X,{platform:"twitter",color:x?"#FFFFFF":"#000000",onPress:()=>A("twitter"),icon:"\u{1D54F}",borderColor:d.border,bgColor:d.background}),o.default.createElement(X,{platform:"facebook",color:"#1877F2",onPress:()=>A("facebook"),icon:"f",borderColor:d.border,bgColor:d.background}),o.default.createElement(X,{platform:"linkedin",color:"#0A66C2",onPress:()=>A("linkedin"),icon:"in",borderColor:d.border,bgColor:d.background}),o.default.createElement(X,{platform:"whatsapp",color:"#25D366",onPress:()=>A("whatsapp"),icon:"W",borderColor:d.border,bgColor:d.background}),o.default.createElement(X,{platform:"email",color:d.textSecondary,onPress:()=>A("email"),icon:"\u2709",borderColor:d.border,bgColor:d.background}))):o.default.createElement(t.View,{style:[s.loadingBox,{backgroundColor:d.inputBg,borderColor:d.border}]},o.default.createElement(t.Text,{style:{color:d.textSecondary,textAlign:"center"}},"Please log in to view your referral dashboard.")),o.default.createElement(t.View,{style:s.footer},o.default.createElement(t.Text,{style:[s.poweredBy,{color:d.textSecondary}]},"Powered by ",o.default.createElement(t.Text,{style:[s.brand,{color:U}],onPress:()=>t.Linking.openURL("https://growthrail.com")},"Growth Rail"))))))))},X=({color:n,onPress:r,icon:e,borderColor:l,bgColor:i})=>o.default.createElement(t.TouchableOpacity,{style:[s.socialBtn,{borderColor:l,backgroundColor:i}],onPress:r},o.default.createElement(t.Text,{style:[s.socialIcon,{color:n}]},e)),s=t.StyleSheet.create({fullScreen:{flex:1},overlay:{...t.StyleSheet.absoluteFillObject},centeredModalContainer:{width:"90%",maxWidth:400,alignSelf:"center",marginTop:we*.15,overflow:"hidden",shadowColor:"#000",shadowOffset:{width:0,height:20},shadowOpacity:.25,shadowRadius:30,elevation:20},contentWrapper:{},drawerHandle:{width:40,height:4,backgroundColor:"#e5e7eb",borderRadius:2,alignSelf:"center",marginTop:12},scrollContent:{padding:32,alignItems:"center"},closeBtn:{position:"absolute",top:20,right:20,zIndex:10,width:32,height:32,borderRadius:16,backgroundColor:"#f3f4f6",justifyContent:"center",alignItems:"center"},closeIcon:{fontSize:14,color:"#9ca3af"},header:{alignItems:"center",marginBottom:28,width:"100%"},socialIcon:{fontSize:18,fontWeight:"bold"},title:{fontSize:22,fontWeight:"700",letterSpacing:-.5,marginBottom:8,textAlign:"center"},subtitle:{fontSize:14,lineHeight:20,textAlign:"center",paddingHorizontal:10},loadingBox:{padding:16,backgroundColor:"#f9fafb",borderRadius:12,width:"100%",alignItems:"center",borderWidth:1,borderColor:"#e5e7eb",marginTop:20},loader:{marginVertical:20},mainContent:{width:"100%"},label:{fontSize:12,fontWeight:"600",color:"#6b7280",marginBottom:8,letterSpacing:.5},inputGroup:{flexDirection:"row",alignItems:"center",backgroundColor:"#f9fafb",borderWidth:1,borderColor:"#e5e7eb",borderRadius:12,padding:6,marginBottom:24},input:{flex:1,paddingHorizontal:12,fontSize:14,color:"#111827",fontFamily:t.Platform.OS==="ios"?"Menlo":"monospace"},copyBtn:{paddingVertical:8,paddingHorizontal:16,borderRadius:8,justifyContent:"center",alignItems:"center"},copyBtnText:{color:"#fff",fontSize:13,fontWeight:"600"},shareLabelContainer:{flexDirection:"row",alignItems:"center",marginBottom:16,marginTop:8},divider:{flex:1,height:1,backgroundColor:"#e5e7eb"},shareLabel:{marginHorizontal:12,fontSize:13,fontWeight:"500",color:"#6b7280"},socialContainer:{flexDirection:"row",justifyContent:"center",gap:12},socialBtn:{width:44,height:44,borderRadius:22,backgroundColor:"#fff",borderWidth:1,justifyContent:"center",alignItems:"center"},iconLgContainer:{width:60,height:60,justifyContent:"center",alignItems:"center",marginBottom:16},bowContainerLg:{flexDirection:"row",position:"absolute",top:2,zIndex:2},bowLoopLg:{width:20,height:16,borderWidth:3,borderColor:"#e5e7eb",borderRadius:10},bowLeftLg:{marginRight:-2,transform:[{rotate:"-15deg"}]},bowRightLg:{marginLeft:-2,transform:[{rotate:"15deg"}]},giftLidLg:{width:44,height:10,backgroundColor:"#f3f4f6",borderRadius:2,marginTop:12,zIndex:3},giftBodyLg:{width:36,height:24,borderWidth:3,borderTopWidth:0,borderBottomLeftRadius:4,borderBottomRightRadius:4,justifyContent:"center",alignItems:"center",marginTop:-2},ribbonVerticalLg:{width:4,height:"100%",opacity:.1},footer:{marginTop:32,alignItems:"center"},poweredBy:{fontSize:11,color:"#9ca3af"},brand:{fontWeight:"600",textDecorationLine:"underline"}});var v=H(require("react")),y=require("react-native"),me=require("react-native-safe-area-context"),se=({onPress:n,options:r})=>{let e=(0,me.useSafeAreaInsets)(),l=r?.modal?.theme?.primaryColor||"#2563eb",i=r?.trigger?.position||"bottom-right",u=(r?.trigger?.displayMode||"floating")==="edge",b=i.includes("right"),c=i.includes("top"),R=(0,v.useRef)(new y.Animated.Value(-1)).current;(0,v.useEffect)(()=>{let M=()=>{R.setValue(-1),y.Animated.timing(R,{toValue:2,duration:3e3,easing:y.Easing.linear,useNativeDriver:!0}).start(()=>{setTimeout(M,1e3)})};M()},[]);let C=R.interpolate({inputRange:[-1,2],outputRange:u?[-50,100]:[-60,120]}),m={"bottom-right":{bottom:100+e.bottom,right:0},"bottom-left":{bottom:100+e.bottom,left:0},"top-right":{top:100+e.top,right:0},"top-left":{top:100+e.top,left:0}};u||(m["bottom-right"]={bottom:30+e.bottom,right:20},m["bottom-left"]={bottom:30+e.bottom,left:20},m["top-right"]={top:60+e.top,right:20},m["top-left"]={top:60+e.top,left:20});let S=()=>v.default.createElement(y.View,{style:T.iconContainer},v.default.createElement(y.View,{style:T.bowContainer},v.default.createElement(y.View,{style:[T.bowLoop,T.bowLeft]}),v.default.createElement(y.View,{style:[T.bowLoop,T.bowRight]})),v.default.createElement(y.View,{style:T.giftLid}),v.default.createElement(y.View,{style:T.giftBody},v.default.createElement(y.View,{style:T.ribbonVertical})));return v.default.createElement(y.TouchableOpacity,{style:[u?T.edgeButton:T.floatingButton,{backgroundColor:l},m[i],u&&(b?T.edgeRight:T.edgeLeft)],onPress:n,activeOpacity:.9},v.default.createElement(y.View,{style:T.content},S()),v.default.createElement(y.Animated.View,{style:[T.shimmer,{transform:[{translateX:C},{skewX:"-15deg"}]}]}))},T=y.StyleSheet.create({floatingButton:{position:"absolute",width:60,height:60,borderRadius:30,justifyContent:"center",alignItems:"center",overflow:"hidden",shadowColor:"#000",shadowOffset:{width:0,height:8},shadowOpacity:.2,shadowRadius:12,elevation:8,zIndex:2147483646},edgeButton:{position:"absolute",width:50,height:50,justifyContent:"center",alignItems:"center",overflow:"hidden",shadowColor:"#000",shadowOffset:{width:0,height:4},shadowOpacity:.1,shadowRadius:8,elevation:4,zIndex:2147483646},edgeRight:{borderTopLeftRadius:8,borderBottomLeftRadius:8,paddingLeft:4},edgeLeft:{borderTopRightRadius:8,borderBottomRightRadius:8,paddingRight:4},content:{justifyContent:"center",alignItems:"center"},iconContainer:{width:28,height:28,justifyContent:"center",alignItems:"center"},bowContainer:{flexDirection:"row",position:"absolute",top:0,zIndex:2},bowLoop:{width:10,height:8,borderWidth:2,borderColor:"#fff",borderRadius:5},bowLeft:{marginRight:-1,transform:[{rotate:"-15deg"}]},bowRight:{marginLeft:-1,transform:[{rotate:"15deg"}]},giftLid:{width:22,height:5,backgroundColor:"#fff",borderRadius:1,marginTop:6,zIndex:3},giftBody:{width:18,height:12,borderWidth:2,borderColor:"#fff",borderTopWidth:0,borderBottomLeftRadius:2,borderBottomRightRadius:2,justifyContent:"center",alignItems:"center",marginTop:-1},ribbonVertical:{width:2,height:"100%",backgroundColor:"#fff",opacity:.8},shimmer:{position:"absolute",top:0,left:0,width:50,height:"100%",backgroundColor:"rgba(255, 255, 255, 0.25)"}});var D=H(require("react")),k=require("react-native"),be=require("react-native-safe-area-context"),{width:ze}=k.Dimensions.get("window"),ye=({visible:n,options:r,onClose:e})=>{let l=(0,D.useRef)(new k.Animated.Value(0)).current,[i,I]=(0,D.useState)(n),u=(0,be.useSafeAreaInsets)(),b=r.position.includes("bottom")?"bottom":"top",c=r.position.includes("left")?"left":r.position.includes("right")?"right":"center";if((0,D.useEffect)(()=>{n?(I(!0),k.Animated.spring(l,{toValue:1,useNativeDriver:!0,tension:50,friction:8}).start()):k.Animated.timing(l,{toValue:0,duration:250,useNativeDriver:!0}).start(()=>{I(!1)})},[n]),!i)return null;let R=l.interpolate({inputRange:[0,1],outputRange:[b==="top"?-100:100,0]}),C=l.interpolate({inputRange:[0,1],outputRange:[0,1]}),m={position:"absolute",[b]:b==="top"?16+u.top:16+u.bottom,zIndex:9999};return c==="center"?(m.left=20,m.right=20,m.alignItems="center"):m[c]=20,D.default.createElement(k.Animated.View,{style:[m,{transform:[{translateY:R}],opacity:C}]},D.default.createElement(k.View,{style:[J.banner,{backgroundColor:r.themeColor||"#2563eb"}]},D.default.createElement(k.Text,{style:J.icon},"\u{1F381}"),D.default.createElement(k.Text,{style:J.text},r.text),D.default.createElement(k.TouchableOpacity,{onPress:e,style:J.closeBtn},D.default.createElement(k.Text,{style:J.closeIcon},"\u2715"))))},J=k.StyleSheet.create({banner:{flexDirection:"row",alignItems:"center",padding:12,paddingHorizontal:16,borderRadius:12,shadowColor:"#000",shadowOffset:{width:0,height:4},shadowOpacity:.15,shadowRadius:10,elevation:5,maxWidth:ze-40},icon:{fontSize:18,marginRight:10},text:{color:"#fff",fontSize:14,fontWeight:"600",flex:1},closeBtn:{marginLeft:10,padding:4},closeIcon:{color:"rgba(255, 255, 255, 0.8)",fontSize:14,fontWeight:"bold"}});var ke=(0,a.createContext)(void 0),Ce=({children:n,userId:r,debug:e=!1,...l})=>{let[i,I]=(0,a.useState)(!1),[u,b]=(0,a.useState)(!1),[c,R]=(0,a.useState)(null),C=(0,a.useRef)(new oe(l)),m=(0,a.useRef)(!1),S=(0,a.useRef)(null),[M,Q]=(0,a.useState)(!1),[x,le]=(0,a.useState)(),[U,ge]=(0,a.useState)(!1),[B,Z]=(0,a.useState)(),[d,W]=(0,a.useState)(!1),[ce,de]=(0,a.useState)();(0,a.useEffect)(()=>{C.current.setDebug(e),e&&g.log("info","Provider","Debug mode enabled")},[e]);let A=(0,a.useCallback)(()=>{let{width:f,height:p}=L.Dimensions.get("window"),h=Intl.DateTimeFormat().resolvedOptions().locale,w=L.PixelRatio.get(),E,re;if(L.Platform.OS==="android"){let fe=L.Platform.constants;E=fe.Model,re=fe.Brand||fe.Manufacturer}return{os:L.Platform.OS,platform:L.Platform.OS,osVersion:String(L.Platform.Version),screenWidth:f,screenHeight:p,timezoneOffsetInMinutes:String(new Date().getTimezoneOffset()),locale:h,language:h,deviceModel:E,deviceBrand:re,pixelRatio:w}},[]),N=(0,a.useCallback)(async(f,p)=>{e&&g.log("info","Referral",`Tracking referral code: ${f}`,{referralCode:f,rewardEventName:p});let h=await C.current.trackReferral(f,p);return await O.setTrackedReferral(h.referralTrackingId),e&&g.log("success","Referral",`Referral tracked \u2192 ${h.referralTrackingId}`,h),h},[e]),F=(0,a.useCallback)(async f=>{try{e&&g.log("info","DeepLink",`Received deep link: ${f}`);let p=f.match(/[?&]referralCode=([^&]+)/);p&&(console.log("GrowthRail: Tracking referral from deep link",p[1]),e&&g.log("info","DeepLink",`Found referral code in deep link: ${p[1]}`),await N(p[1]))}catch(p){console.warn("GrowthRail: Error handling deep link",p),e&&g.log("error","DeepLink","Deep link handling failed",{error:String(p)})}},[N,e]),K=(0,a.useCallback)(async()=>{try{e&&g.log("info","Deferred","Checking deferred deep link via fingerprint");let f=A(),{referralTrackingId:p}=await C.current.checkDeferredDeepLink(f);p?(console.log("GrowthRail: Found deferred referral via fingerprinting",p),e&&g.log("success","Deferred",`Deferred referral matched \u2192 ${p}`),await O.setTrackedReferral(p)):e&&g.log("info","Deferred","No deferred referral match found")}catch(f){console.warn("GrowthRail: Fingerprint check failed",f),e&&g.log("error","Deferred","Fingerprint check failed",{error:String(f)})}},[A,e]),Te=(0,a.useCallback)(()=>new Promise(f=>{Re.default.getInstallReferrerInfo(async(p,h)=>{if(!h&&p&&p.installReferrer)try{let E=decodeURIComponent(p.installReferrer).match(/[?&]referralCode=([^&]+)/);if(E){let{referralTrackingId:re}=await N(E[1]);await O.setTrackedReferral(re),console.log("GrowthRail: Tracked referral via Install Referrer")}}catch(w){console.warn("GrowthRail: Failed to process install referrer",w)}else await K();f()})}),[N,K]),j=(0,a.useCallback)(async f=>{if(c?.id===f&&u)return e&&g.log("info","User",`User ${f} already initialized, skipping`),c;e&&g.log("info","User",`Initializing user: ${f}`);let p=(async()=>{try{let h=await C.current.initAppUser(f),w={...h,id:f};return R(w),b(!0),e&&g.log("success","User",`User initialized: ${f}`,{referralCode:h.referralCode,referralLink:h.referralLink}),h.referrerExperience?.trigger?.displayMode!=="none"&&(ge(!0),e&&g.log("info","UI","Trigger button shown (server-configured)")),w}catch(h){throw S.current=null,e&&g.log("error","User",`User init failed for ${f}`,{error:String(h)}),h}})();return S.current=p,p},[c,u,e]),ee=(0,a.useCallback)(async f=>{e&&g.log("info","Reward",`Tracking reward event: ${f||"(default)"}`);let p=c;!p&&S.current&&(p=await S.current);let h=p?.id||r;if(!h)throw e&&g.log("error","Reward","Cannot track reward \u2014 user not initialized"),new Error("GrowthRail: User must be initialized before tracking a reward event.");let w=await O.getTrackedReferral();if(!w){console.warn("GrowthRail: No referral tracking ID found. Reward event not attributed."),e&&g.log("warn","Reward","No referral tracking ID in storage \u2014 reward not attributed");return}let E=await C.current.trackRewardEvent(h,w,f);return e&&g.log("success","Reward",`Reward event tracked for user ${h}`),E},[c,r,e]),z=(0,a.useCallback)(async()=>await O.getTrackedReferral(),[]),V=(0,a.useCallback)(async()=>{if(c)return c.referralLink;if(S.current)return(await S.current).referralLink},[c]);(0,a.useEffect)(()=>{if(m.current)return;m.current=!0,e&&g.log("info","Provider","SDK initializing\u2026",{platform:L.Platform.OS});let f;return(async()=>{try{let w=await L.Linking.getInitialURL();e&&g.log("info","DeepLink",`Initial URL: ${w??"(none)"}`),w&&await F(w)}catch(w){console.warn("GrowthRail: Error getting initial URL",w)}f=L.Linking.addEventListener("url",({url:w})=>F(w));let h=await O.isFirstLaunch();e&&g.log("info","Provider",`First launch: ${h}`),h&&await K(),r&&await j(r);try{let w=await C.current.getNewUserExperience(),E=await O.getTrackedReferral();w.banner?.show&&E&&(de(w.banner),W(!0),e&&g.log("info","UI","Banner shown for new user experience"))}catch(w){e&&g.log("warn","Provider","New user experience fetch failed",{error:String(w)})}I(!0),e&&g.log("success","Provider","SDK initialization complete \u2713")})(),()=>{f&&f.remove()}},[e,F,K,j,r]),(0,a.useEffect)(()=>{i&&r&&c?.id!==r&&j(r)},[r,i]);let P=(0,a.useCallback)(f=>{le(f),Q(!0)},[]),_=(0,a.useCallback)(()=>{Q(!1)},[]),ue=(0,a.useMemo)(()=>({isInitialized:i,isUserReady:u,currentUser:c,referralCode:c?.referralCode,referralLink:c?.referralLink,showDashboard:P,hideDashboard:_,initUser:j,trackReward:ee,getReferralTrackingId:z,getReferralLink:V,isDebugEnabled:e}),[i,u,c,P,_,j,ee,z,V,e]),$=c?.referrerExperience,ve=(0,a.useMemo)(()=>({...$?.modal,...x,appearance:x?.appearance||$?.modal?.appearance||l.appearance,theme:{...$?.modal?.theme||{},...x?.theme||{}}}),[$?.modal,x,l.appearance]),Le=(0,a.useMemo)(()=>({...$,...B,trigger:{...$?.trigger||{},...B?.trigger||{}}}),[$,B]);return i?a.default.createElement(ke.Provider,{value:ue},n,a.default.createElement(ne,{visible:M,options:ve,onClose:()=>Q(!1)}),U&&a.default.createElement(se,{options:Le,onPress:()=>ue.showDashboard()}),d&&a.default.createElement(ye,{visible:d,options:ce,onClose:()=>W(!1)})):null},ae=()=>{let n=(0,a.useContext)(ke);if(!n)throw new Error("useGrowthRail must be used within a GrowthRailProvider");return n};var G=require("react");var xe=()=>{let[n,r]=(0,G.useState)(!1),[e,l]=(0,G.useState)(null),i=ae(),I=(0,G.useCallback)(async b=>{r(!0),l(null);try{return await i.initUser(b)}catch(c){let R=c instanceof Error?c:new Error(String(c));throw l(R),R}finally{r(!1)}},[i]),u=(0,G.useCallback)(async b=>{r(!0),l(null);try{await i.trackReward(b)}catch(c){let R=c instanceof Error?c:new Error(String(c));throw l(R),R}finally{r(!1)}},[i]);return(0,G.useMemo)(()=>({initAppUser:I,trackRewardEvent:u,showReferralDashboard:i.showDashboard,hideReferralDashboard:i.hideDashboard,getReferralTrackingId:i.getReferralTrackingId,getReferralLink:i.getReferralLink,isLoading:n,isInitialized:i.isInitialized,isUserReady:i.isUserReady,error:e,isDebugEnabled:i.isDebugEnabled}),[I,u,i.showDashboard,i.hideDashboard,i.getReferralTrackingId,i.getReferralLink,n,i.isInitialized,i.isUserReady,e,i.isDebugEnabled])};0&&(module.exports={GrowthRailProvider,ReferralDashboard,TriggerButton,useGrowthRail});
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- var ze=Object.defineProperty;var Pe=(d,e,r)=>e in d?ze(d,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):d[e]=r;var ee=(d,e,r)=>Pe(d,typeof e!="symbol"?e+"":e,r);import se,{createContext as nr,useContext as ar,useEffect as pe,useState as V,useRef as we,useCallback as T,useMemo as be}from"react";import{Linking as Ie,Platform as H,Dimensions as sr,PixelRatio as lr}from"react-native";import cr from"react-native-play-install-referrer";var Ae="[GrowthRail]",c={log(d,e,r,a){let o=`${Ae} [${e}] ${r}`;switch(d){case"error":console.error(o,a||"");break;case"warn":console.warn(o,a||"");break;default:console.log(o,a||"");break}}};var re=class{constructor(e){ee(this,"baseUrl");ee(this,"projectSecretKey");ee(this,"_debug",!1);let r=typeof process<"u"&&process.env?.ENV_BASE_URL;this.baseUrl=r||"https://api.growthrail.dev",this.projectSecretKey=e.projectSecretKey}setDebug(e){this._debug=e}async request(e,r,a){let o={"Content-Type":"application/json","X-GrowthRail-ProjectSecret":this.projectSecretKey,Origin:this.baseUrl},b=Date.now();this._debug&&c.log("api","APIClient",`${r} ${e}`,{method:r,endpoint:e,body:a??null});try{let u=await fetch(`${this.baseUrl}${e}`,{method:r,headers:o,body:a?JSON.stringify(a):void 0}),m=Date.now()-b;if(!u.ok){let n="";try{n=await u.text()}catch{}let y=`GrowthRail API Error ${u.status} (${this.baseUrl}${e}): ${u.statusText} - ${n}`;throw this._debug&&c.log("api","APIClient",`\u2717 ${r} ${e}`,{method:r,endpoint:e,status:u.status,duration:m,error:n}),new Error(y)}return this._debug&&c.log("api","APIClient",`\u2713 ${r} ${e}`,{method:r,endpoint:e,status:u.status,duration:m}),u.json()}catch(u){let m=Date.now()-b;throw this._debug&&c.log("api","APIClient",`\u2717 ${r} ${e} \u2014 Network error`,{method:r,endpoint:e,duration:m,error:String(u)}),console.error("GrowthRail SDK Error:",u),u}}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,r){return this.request("/api/v1/sdk/track-referral","POST",{referralCode:e,rewardEventName:r})}async trackRewardEvent(e,r,a){return this.request("/api/v1/sdk/track-reward-event","POST",{refereeId:e,referralTrackingId:r,eventName:a})}async checkDeferredDeepLink(e){return this.request("/api/v1/sdk/match-link","POST",{fingerprint:e})}};import te from"@react-native-async-storage/async-storage";var oe={TRACKED_REFERRAL:"growth-rail-tracked-referral",IS_FIRST_LAUNCH:"growth-rail-is-first-launch"},L=class{static async setTrackedReferral(e){await te.setItem(oe.TRACKED_REFERRAL,e)}static async getTrackedReferral(){return await te.getItem(oe.TRACKED_REFERRAL)}static async isFirstLaunch(){return await te.getItem(oe.IS_FIRST_LAUNCH)===null?(await te.setItem(oe.IS_FIRST_LAUNCH,"false"),!0):!1}};import t,{useEffect as Ge,useState as de,useRef as Ce}from"react";import{Modal as Fe,View as w,Text as x,StyleSheet as xe,TouchableOpacity as ie,Clipboard as $e,ActivityIndicator as Me,Linking as Te,ScrollView as We,Platform as ve,Animated as S,Dimensions as Ne,useColorScheme as je}from"react-native";var{width:Tr,height:Le}=Ne.get("window"),fe=({visible:d,options:e,onClose:r})=>{let a=ne(),[o,b]=de(null),[u,m]=de(!1),[n,y]=de(!1),g=Ce(new S.Value(0)).current,D=Ce(new S.Value(0)).current,C=je(),k=(e?.appearance||C||"light")==="dark",W=e?.title||"Invite Friends & Earn",B=e?.theme?.primaryColor||"#2563eb",U=(e?.componentType||"modal")==="drawer",G=e?.position||"bottom-right",l={background:k?"#111827":"#ffffff",text:k?"#f9fafb":"#111827",textSecondary:k?"#9ca3af":"#6b7280",border:k?"#374151":"#e5e7eb",inputBg:k?"#1f2937":"#f9fafb",closeBtnBg:k?"#1f2937":"#f3f4f6",closeIcon:k?"#6b7280":"#9ca3af",drawerHandle:k?"#4b5563":"#e5e7eb",overlay:"#000000",overlayOpacity:.5};Ge(()=>{d?(o||X(),S.parallel([S.timing(D,{toValue:1,duration:300,useNativeDriver:!0}),S.spring(g,{toValue:1,useNativeDriver:!0,tension:50,friction:8})]).start()):(g.setValue(0),D.setValue(0))},[d]);let N=()=>{S.parallel([S.timing(D,{toValue:0,duration:250,useNativeDriver:!0}),S.timing(g,{toValue:0,duration:250,useNativeDriver:!0})]).start(()=>{r()})},X=async()=>{m(!0);try{if(a.isUserReady){let z=await a.getReferralLink();b(z||null)}}catch(z){console.error("GrowthRail: Failed to load referral link",z)}finally{m(!1)}},le=()=>{o&&($e.setString(o),y(!0),setTimeout(()=>y(!1),2e3))},F=z=>{if(!o)return;let v="",P=encodeURIComponent(o),j=encodeURIComponent("Check this out!");switch(z){case"twitter":v=`https://twitter.com/intent/tweet?url=${P}&text=${j}`;break;case"facebook":v=`https://www.facebook.com/sharer/sharer.php?u=${P}`;break;case"linkedin":v=`https://www.linkedin.com/sharing/share-offsite/?url=${P}`;break;case"whatsapp":v=`whatsapp://send?text=${j}%20${P}`;break;case"email":v=`mailto:?subject=Check this out&body=${j}%20${P}`;break}v&&Te.openURL(v).catch(()=>{})},J=()=>l.overlay,E=[];U?E=[{translateY:g.interpolate({inputRange:[0,1],outputRange:[Le,0]})}]:E=[{scale:g.interpolate({inputRange:[0,1],outputRange:[.9,1]})},{translateY:g.interpolate({inputRange:[0,1],outputRange:[20,0]})}];let Q=G.includes("top"),K=G.includes("right"),Ve=G.includes("left"),$=U?{position:"absolute",bottom:0,left:0,right:0,width:"100%",maxHeight:"90%"}:{};return t.createElement(Fe,{visible:d,transparent:!0,animationType:"none",onRequestClose:N},t.createElement(w,{style:i.fullScreen},t.createElement(S.View,{style:[i.overlay,{backgroundColor:J(),opacity:D.interpolate({inputRange:[0,1],outputRange:[0,l.overlayOpacity]})}]},t.createElement(ie,{style:i.fullScreen,activeOpacity:1,onPress:N})),t.createElement(S.View,{style:[U?$:i.centeredModalContainer,{backgroundColor:l.background,transform:E},U&&{borderTopLeftRadius:24,borderTopRightRadius:24,borderBottomLeftRadius:0,borderBottomRightRadius:0},!U&&{borderRadius:24,opacity:g,borderColor:l.border,borderWidth:k?1:0}]},t.createElement(w,{style:i.contentWrapper},U&&t.createElement(w,{style:[i.drawerHandle,{backgroundColor:l.drawerHandle}]}),t.createElement(ie,{style:[i.closeBtn,{backgroundColor:l.closeBtnBg}],onPress:N},t.createElement(x,{style:[i.closeIcon,{color:l.closeIcon}]},"\u2715")),t.createElement(We,{contentContainerStyle:i.scrollContent,showsVerticalScrollIndicator:!1},t.createElement(w,{style:i.header},t.createElement(w,{style:i.iconLgContainer},t.createElement(w,{style:i.bowContainerLg},t.createElement(w,{style:[i.bowLoopLg,i.bowLeftLg,{borderColor:B}]}),t.createElement(w,{style:[i.bowLoopLg,i.bowRightLg,{borderColor:B}]})),t.createElement(w,{style:[i.giftLidLg,{backgroundColor:B}]}),t.createElement(w,{style:[i.giftBodyLg,{borderColor:B}]},t.createElement(w,{style:[i.ribbonVerticalLg,{backgroundColor:"#fff",opacity:.3}]}))),t.createElement(x,{style:[i.title,{color:l.text}]},W),t.createElement(x,{style:[i.subtitle,{color:l.textSecondary}]},e?.description||"Share your unique link and earn rewards for every friend who signs up.")),a.isUserReady?u?t.createElement(Me,{size:"large",color:B,style:i.loader}):t.createElement(w,{style:i.mainContent},t.createElement(x,{style:[i.label,{color:l.textSecondary}]},"YOUR UNIQUE LINK"),t.createElement(w,{style:[i.inputGroup,{backgroundColor:l.inputBg,borderColor:l.border}]},t.createElement(x,{numberOfLines:1,style:[i.input,{color:l.text}]},o||"Initializing..."),t.createElement(ie,{style:[i.copyBtn,{backgroundColor:n?"#10b981":B}],onPress:le},t.createElement(x,{style:i.copyBtnText},n?"Copied!":"Copy"))),t.createElement(w,{style:i.shareLabelContainer},t.createElement(w,{style:[i.divider,{backgroundColor:l.border}]}),t.createElement(x,{style:[i.shareLabel,{color:l.textSecondary}]},"Share via"),t.createElement(w,{style:[i.divider,{backgroundColor:l.border}]})),t.createElement(w,{style:i.socialContainer},t.createElement(q,{platform:"twitter",color:k?"#FFFFFF":"#000000",onPress:()=>F("twitter"),icon:"\u{1D54F}",borderColor:l.border,bgColor:l.background}),t.createElement(q,{platform:"facebook",color:"#1877F2",onPress:()=>F("facebook"),icon:"f",borderColor:l.border,bgColor:l.background}),t.createElement(q,{platform:"linkedin",color:"#0A66C2",onPress:()=>F("linkedin"),icon:"in",borderColor:l.border,bgColor:l.background}),t.createElement(q,{platform:"whatsapp",color:"#25D366",onPress:()=>F("whatsapp"),icon:"W",borderColor:l.border,bgColor:l.background}),t.createElement(q,{platform:"email",color:l.textSecondary,onPress:()=>F("email"),icon:"\u2709",borderColor:l.border,bgColor:l.background}))):t.createElement(w,{style:[i.loadingBox,{backgroundColor:l.inputBg,borderColor:l.border}]},t.createElement(x,{style:{color:l.textSecondary,textAlign:"center"}},"Please log in to view your referral dashboard.")),t.createElement(w,{style:i.footer},t.createElement(x,{style:[i.poweredBy,{color:l.textSecondary}]},"Powered by ",t.createElement(x,{style:[i.brand,{color:B}],onPress:()=>Te.openURL("https://growthrail.com")},"Growth Rail"))))))))},q=({color:d,onPress:e,icon:r,borderColor:a,bgColor:o})=>t.createElement(ie,{style:[i.socialBtn,{borderColor:a,backgroundColor:o}],onPress:e},t.createElement(x,{style:[i.socialIcon,{color:d}]},r)),i=xe.create({fullScreen:{flex:1},overlay:{...xe.absoluteFillObject},centeredModalContainer:{width:"90%",maxWidth:400,alignSelf:"center",marginTop:Le*.15,overflow:"hidden",shadowColor:"#000",shadowOffset:{width:0,height:20},shadowOpacity:.25,shadowRadius:30,elevation:20},contentWrapper:{paddingTop:ve.OS==="ios"?20:0},drawerHandle:{width:40,height:4,backgroundColor:"#e5e7eb",borderRadius:2,alignSelf:"center",marginTop:12},scrollContent:{padding:32,alignItems:"center"},closeBtn:{position:"absolute",top:20,right:20,zIndex:10,width:32,height:32,borderRadius:16,backgroundColor:"#f3f4f6",justifyContent:"center",alignItems:"center"},closeIcon:{fontSize:14,color:"#9ca3af"},header:{alignItems:"center",marginBottom:28,width:"100%"},socialIcon:{fontSize:18,fontWeight:"bold"},title:{fontSize:22,fontWeight:"700",letterSpacing:-.5,marginBottom:8,textAlign:"center"},subtitle:{fontSize:14,lineHeight:20,textAlign:"center",paddingHorizontal:10},loadingBox:{padding:16,backgroundColor:"#f9fafb",borderRadius:12,width:"100%",alignItems:"center",borderWidth:1,borderColor:"#e5e7eb",marginTop:20},loader:{marginVertical:20},mainContent:{width:"100%"},label:{fontSize:12,fontWeight:"600",color:"#6b7280",marginBottom:8,letterSpacing:.5},inputGroup:{flexDirection:"row",alignItems:"center",backgroundColor:"#f9fafb",borderWidth:1,borderColor:"#e5e7eb",borderRadius:12,padding:6,marginBottom:24},input:{flex:1,paddingHorizontal:12,fontSize:14,color:"#111827",fontFamily:ve.OS==="ios"?"Menlo":"monospace"},copyBtn:{paddingVertical:8,paddingHorizontal:16,borderRadius:8,justifyContent:"center",alignItems:"center"},copyBtnText:{color:"#fff",fontSize:13,fontWeight:"600"},shareLabelContainer:{flexDirection:"row",alignItems:"center",marginBottom:16,marginTop:8},divider:{flex:1,height:1,backgroundColor:"#e5e7eb"},shareLabel:{marginHorizontal:12,fontSize:13,fontWeight:"500",color:"#6b7280"},socialContainer:{flexDirection:"row",justifyContent:"center",gap:12},socialBtn:{width:44,height:44,borderRadius:22,backgroundColor:"#fff",borderWidth:1,justifyContent:"center",alignItems:"center"},iconLgContainer:{width:60,height:60,justifyContent:"center",alignItems:"center",marginBottom:16},bowContainerLg:{flexDirection:"row",position:"absolute",top:2,zIndex:2},bowLoopLg:{width:20,height:16,borderWidth:3,borderColor:"#e5e7eb",borderRadius:10},bowLeftLg:{marginRight:-2,transform:[{rotate:"-15deg"}]},bowRightLg:{marginLeft:-2,transform:[{rotate:"15deg"}]},giftLidLg:{width:44,height:10,backgroundColor:"#f3f4f6",borderRadius:2,marginTop:12,zIndex:3},giftBodyLg:{width:36,height:24,borderWidth:3,borderTopWidth:0,borderBottomLeftRadius:4,borderBottomRightRadius:4,justifyContent:"center",alignItems:"center",marginTop:-2},ribbonVerticalLg:{width:4,height:"100%",opacity:.1},footer:{marginTop:32,alignItems:"center"},poweredBy:{fontSize:11,color:"#9ca3af"},brand:{fontWeight:"600",textDecorationLine:"underline"}});import I,{useEffect as _e,useRef as He}from"react";import{TouchableOpacity as Ke,View as A,StyleSheet as qe,Animated as ge,Easing as Ye}from"react-native";var ue=({onPress:d,options:e})=>{let r=e?.modal?.theme?.primaryColor||"#2563eb",a=e?.trigger?.position||"bottom-right",b=(e?.trigger?.displayMode||"floating")==="edge",u=a.includes("right"),m=a.includes("top"),n=He(new ge.Value(-1)).current;_e(()=>{let C=()=>{n.setValue(-1),ge.timing(n,{toValue:2,duration:3e3,easing:Ye.linear,useNativeDriver:!0}).start(()=>{setTimeout(C,1e3)})};C()},[]);let y=n.interpolate({inputRange:[-1,2],outputRange:b?[-50,100]:[-60,120]}),g={"bottom-right":{bottom:100,right:0},"bottom-left":{bottom:100,left:0},"top-right":{top:100,right:0},"top-left":{top:100,left:0}};b||(g["bottom-right"]={bottom:30,right:20},g["bottom-left"]={bottom:30,left:20},g["top-right"]={top:60,right:20},g["top-left"]={top:60,left:20});let D=()=>I.createElement(A,{style:R.iconContainer},I.createElement(A,{style:R.bowContainer},I.createElement(A,{style:[R.bowLoop,R.bowLeft]}),I.createElement(A,{style:[R.bowLoop,R.bowRight]})),I.createElement(A,{style:R.giftLid}),I.createElement(A,{style:R.giftBody},I.createElement(A,{style:R.ribbonVertical})));return I.createElement(Ke,{style:[b?R.edgeButton:R.floatingButton,{backgroundColor:r},g[a],b&&(u?R.edgeRight:R.edgeLeft)],onPress:d,activeOpacity:.9},I.createElement(A,{style:R.content},D()),I.createElement(ge.View,{style:[R.shimmer,{transform:[{translateX:y},{skewX:"-15deg"}]}]}))},R=qe.create({floatingButton:{position:"absolute",width:60,height:60,borderRadius:30,justifyContent:"center",alignItems:"center",overflow:"hidden",shadowColor:"#000",shadowOffset:{width:0,height:8},shadowOpacity:.2,shadowRadius:12,elevation:8,zIndex:2147483646},edgeButton:{position:"absolute",width:50,height:50,justifyContent:"center",alignItems:"center",overflow:"hidden",shadowColor:"#000",shadowOffset:{width:0,height:4},shadowOpacity:.1,shadowRadius:8,elevation:4,zIndex:2147483646},edgeRight:{borderTopLeftRadius:8,borderBottomLeftRadius:8,paddingLeft:4},edgeLeft:{borderTopRightRadius:8,borderBottomRightRadius:8,paddingRight:4},content:{justifyContent:"center",alignItems:"center"},iconContainer:{width:28,height:28,justifyContent:"center",alignItems:"center"},bowContainer:{flexDirection:"row",position:"absolute",top:0,zIndex:2},bowLoop:{width:10,height:8,borderWidth:2,borderColor:"#fff",borderRadius:5},bowLeft:{marginRight:-1,transform:[{rotate:"-15deg"}]},bowRight:{marginLeft:-1,transform:[{rotate:"15deg"}]},giftLid:{width:22,height:5,backgroundColor:"#fff",borderRadius:1,marginTop:6,zIndex:3},giftBody:{width:18,height:12,borderWidth:2,borderColor:"#fff",borderTopWidth:0,borderBottomLeftRadius:2,borderBottomRightRadius:2,justifyContent:"center",alignItems:"center",marginTop:-1},ribbonVertical:{width:2,height:"100%",backgroundColor:"#fff",opacity:.8},shimmer:{position:"absolute",top:0,left:0,width:50,height:"100%",backgroundColor:"rgba(255, 255, 255, 0.25)"}});import _,{useEffect as Xe,useRef as Je,useState as Qe}from"react";import{View as Ze,Text as he,StyleSheet as er,Animated as ae,Dimensions as rr,TouchableOpacity as tr,Platform as or}from"react-native";var{width:ir}=rr.get("window"),Se=({visible:d,options:e,onClose:r})=>{let a=Je(new ae.Value(0)).current,[o,b]=Qe(d),u=e.position.includes("bottom")?"bottom":"top",m=e.position.includes("left")?"left":e.position.includes("right")?"right":"center";if(Xe(()=>{d?(b(!0),ae.spring(a,{toValue:1,useNativeDriver:!0,tension:50,friction:8}).start()):ae.timing(a,{toValue:0,duration:250,useNativeDriver:!0}).start(()=>{b(!1)})},[d]),!o)return null;let n=a.interpolate({inputRange:[0,1],outputRange:[u==="top"?-100:100,0]}),y=a.interpolate({inputRange:[0,1],outputRange:[0,1]}),g={position:"absolute",[u]:or.OS==="ios"?60:40,zIndex:9999};return m==="center"?(g.left=20,g.right=20,g.alignItems="center"):g[m]=20,_.createElement(ae.View,{style:[g,{transform:[{translateY:n}],opacity:y}]},_.createElement(Ze,{style:[Y.banner,{backgroundColor:e.themeColor||"#2563eb"}]},_.createElement(he,{style:Y.icon},"\u{1F381}"),_.createElement(he,{style:Y.text},e.text),_.createElement(tr,{onPress:r,style:Y.closeBtn},_.createElement(he,{style:Y.closeIcon},"\u2715"))))},Y=er.create({banner:{flexDirection:"row",alignItems:"center",padding:12,paddingHorizontal:16,borderRadius:12,shadowColor:"#000",shadowOffset:{width:0,height:4},shadowOpacity:.15,shadowRadius:10,elevation:5,maxWidth:ir-40},icon:{fontSize:18,marginRight:10},text:{color:"#fff",fontSize:14,fontWeight:"600",flex:1},closeBtn:{marginLeft:10,padding:4},closeIcon:{color:"rgba(255, 255, 255, 0.8)",fontSize:14,fontWeight:"bold"}});var De=nr(void 0),dr=({children:d,userId:e,debug:r=!1,...a})=>{let[o,b]=V(!1),[u,m]=V(!1),[n,y]=V(null),g=we(new re(a)),D=we(!1),C=we(null),[me,k]=V(!1),[W,B]=V(),[ye,U]=V(!1),[G,l]=V(),[N,X]=V(!1),[le,F]=V();pe(()=>{g.current.setDebug(r),r&&c.log("info","Provider","Debug mode enabled")},[r]);let J=T(()=>{let{width:s,height:f}=sr.get("window"),h=Intl.DateTimeFormat().resolvedOptions().locale,p=lr.get(),O,Z;if(H.OS==="android"){let ce=H.constants;O=ce.Model,Z=ce.Brand||ce.Manufacturer}return{os:H.OS,platform:H.OS,osVersion:String(H.Version),screenWidth:s,screenHeight:f,timezoneOffsetInMinutes:String(new Date().getTimezoneOffset()),locale:h,language:h,deviceModel:O,deviceBrand:Z,pixelRatio:p}},[]),E=T(async(s,f)=>{r&&c.log("info","Referral",`Tracking referral code: ${s}`,{referralCode:s,rewardEventName:f});let h=await g.current.trackReferral(s,f);return await L.setTrackedReferral(h.referralTrackingId),r&&c.log("success","Referral",`Referral tracked \u2192 ${h.referralTrackingId}`,h),h},[r]),Q=T(async s=>{try{r&&c.log("info","DeepLink",`Received deep link: ${s}`);let f=s.match(/[?&]referralCode=([^&]+)/);f&&(console.log("GrowthRail: Tracking referral from deep link",f[1]),r&&c.log("info","DeepLink",`Found referral code in deep link: ${f[1]}`),await E(f[1]))}catch(f){console.warn("GrowthRail: Error handling deep link",f),r&&c.log("error","DeepLink","Deep link handling failed",{error:String(f)})}},[E,r]),K=T(async()=>{try{r&&c.log("info","Deferred","Checking deferred deep link via fingerprint");let s=J(),{referralTrackingId:f}=await g.current.checkDeferredDeepLink(s);f?(console.log("GrowthRail: Found deferred referral via fingerprinting",f),r&&c.log("success","Deferred",`Deferred referral matched \u2192 ${f}`),await L.setTrackedReferral(f)):r&&c.log("info","Deferred","No deferred referral match found")}catch(s){console.warn("GrowthRail: Fingerprint check failed",s),r&&c.log("error","Deferred","Fingerprint check failed",{error:String(s)})}},[J,r]),Ve=T(()=>new Promise(s=>{cr.getInstallReferrerInfo(async(f,h)=>{if(!h&&f&&f.installReferrer)try{let O=decodeURIComponent(f.installReferrer).match(/[?&]referralCode=([^&]+)/);if(O){let{referralTrackingId:Z}=await E(O[1]);await L.setTrackedReferral(Z),console.log("GrowthRail: Tracked referral via Install Referrer")}}catch(p){console.warn("GrowthRail: Failed to process install referrer",p)}else await K();s()})}),[E,K]),$=T(async s=>{if(n?.id===s&&u)return r&&c.log("info","User",`User ${s} already initialized, skipping`),n;r&&c.log("info","User",`Initializing user: ${s}`);let f=(async()=>{try{let h=await g.current.initAppUser(s),p={...h,id:s};return y(p),m(!0),r&&c.log("success","User",`User initialized: ${s}`,{referralCode:h.referralCode,referralLink:h.referralLink}),h.referrerExperience?.trigger?.displayMode!=="none"&&(U(!0),r&&c.log("info","UI","Trigger button shown (server-configured)")),p}catch(h){throw C.current=null,r&&c.log("error","User",`User init failed for ${s}`,{error:String(h)}),h}})();return C.current=f,f},[n,u,r]),z=T(async s=>{r&&c.log("info","Reward",`Tracking reward event: ${s||"(default)"}`);let f=n;!f&&C.current&&(f=await C.current);let h=f?.id||e;if(!h)throw r&&c.log("error","Reward","Cannot track reward \u2014 user not initialized"),new Error("GrowthRail: User must be initialized before tracking a reward event.");let p=await L.getTrackedReferral();if(!p){console.warn("GrowthRail: No referral tracking ID found. Reward event not attributed."),r&&c.log("warn","Reward","No referral tracking ID in storage \u2014 reward not attributed");return}let O=await g.current.trackRewardEvent(h,p,s);return r&&c.log("success","Reward",`Reward event tracked for user ${h}`),O},[n,e,r]),v=T(async()=>await L.getTrackedReferral(),[]),P=T(async()=>{if(n)return n.referralLink;if(C.current)return(await C.current).referralLink},[n]);pe(()=>{if(D.current)return;D.current=!0,r&&c.log("info","Provider","SDK initializing\u2026",{platform:H.OS});let s;return(async()=>{try{let p=await Ie.getInitialURL();r&&c.log("info","DeepLink",`Initial URL: ${p??"(none)"}`),p&&await Q(p)}catch(p){console.warn("GrowthRail: Error getting initial URL",p)}s=Ie.addEventListener("url",({url:p})=>Q(p));let h=await L.isFirstLaunch();r&&c.log("info","Provider",`First launch: ${h}`),h&&await K(),e&&await $(e);try{let p=await g.current.getNewUserExperience(),O=await L.getTrackedReferral();p.banner?.show&&O&&(F(p.banner),X(!0),r&&c.log("info","UI","Banner shown for new user experience"))}catch(p){r&&c.log("warn","Provider","New user experience fetch failed",{error:String(p)})}b(!0),r&&c.log("success","Provider","SDK initialization complete \u2713")})(),()=>{s&&s.remove()}},[r,Q,K,$,e]),pe(()=>{o&&e&&n?.id!==e&&$(e)},[e,o]);let j=T(s=>{B(s),k(!0)},[]),Re=T(()=>{k(!1)},[]),ke=be(()=>({isInitialized:o,isUserReady:u,currentUser:n,referralCode:n?.referralCode,referralLink:n?.referralLink,showDashboard:j,hideDashboard:Re,initUser:$,trackReward:z,getReferralTrackingId:v,getReferralLink:P,isDebugEnabled:r}),[o,u,n,j,Re,$,z,v,P,r]),M=n?.referrerExperience,Ue=be(()=>({...M?.modal,...W,appearance:W?.appearance||M?.modal?.appearance||a.appearance,theme:{...M?.modal?.theme||{},...W?.theme||{}}}),[M?.modal,W,a.appearance]),Ee=be(()=>({...M,...G,trigger:{...M?.trigger||{},...G?.trigger||{}}}),[M,G]);return o?se.createElement(De.Provider,{value:ke},d,se.createElement(fe,{visible:me,options:Ue,onClose:()=>k(!1)}),ye&&se.createElement(ue,{options:Ee,onPress:()=>ke.showDashboard()}),N&&se.createElement(Se,{visible:N,options:le,onClose:()=>X(!1)})):null},ne=()=>{let d=ar(De);if(!d)throw new Error("useGrowthRail must be used within a GrowthRailProvider");return d};import{useState as Be,useCallback as Oe,useMemo as fr}from"react";var gr=()=>{let[d,e]=Be(!1),[r,a]=Be(null),o=ne(),b=Oe(async m=>{e(!0),a(null);try{return await o.initUser(m)}catch(n){let y=n instanceof Error?n:new Error(String(n));throw a(y),y}finally{e(!1)}},[o]),u=Oe(async m=>{e(!0),a(null);try{await o.trackReward(m)}catch(n){let y=n instanceof Error?n:new Error(String(n));throw a(y),y}finally{e(!1)}},[o]);return fr(()=>({initAppUser:b,trackRewardEvent:u,showReferralDashboard:o.showDashboard,hideReferralDashboard:o.hideDashboard,getReferralTrackingId:o.getReferralTrackingId,getReferralLink:o.getReferralLink,isLoading:d,isInitialized:o.isInitialized,isUserReady:o.isUserReady,error:r,isDebugEnabled:o.isDebugEnabled}),[b,u,o.showDashboard,o.hideDashboard,o.getReferralTrackingId,o.getReferralLink,d,o.isInitialized,o.isUserReady,r,o.isDebugEnabled])};export{dr as GrowthRailProvider,fe as ReferralDashboard,ue as TriggerButton,gr as useGrowthRail};
1
+ var Ee=Object.defineProperty;var Ae=(d,r,e)=>r in d?Ee(d,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):d[r]=e;var ee=(d,r,e)=>Ae(d,typeof r!="symbol"?r+"":r,e);import se,{createContext as sr,useContext as lr,useEffect as me,useState as U,useRef as be,useCallback as v,useMemo as ye}from"react";import{Linking as Ie,Platform as H,Dimensions as cr,PixelRatio as dr}from"react-native";import fr from"react-native-play-install-referrer";var ze="[GrowthRail]",c={log(d,r,e,l){let t=`${ze} [${r}] ${e}`;switch(d){case"error":console.error(t,l||"");break;case"warn":console.warn(t,l||"");break;default:console.log(t,l||"");break}}};var re=class{constructor(r){ee(this,"baseUrl");ee(this,"projectSecretKey");ee(this,"_debug",!1);let e=typeof process<"u"&&process.env?.ENV_BASE_URL;this.baseUrl=e||"https://api.growthrail.dev",this.projectSecretKey=r.projectSecretKey}setDebug(r){this._debug=r}async request(r,e,l){let t={"Content-Type":"application/json","X-GrowthRail-ProjectSecret":this.projectSecretKey,Origin:this.baseUrl},C=Date.now();this._debug&&c.log("api","APIClient",`${e} ${r}`,{method:e,endpoint:r,body:l??null});try{let f=await fetch(`${this.baseUrl}${r}`,{method:e,headers:t,body:l?JSON.stringify(l):void 0}),w=Date.now()-C;if(!f.ok){let n="";try{n=await f.text()}catch{}let b=`GrowthRail API Error ${f.status} (${this.baseUrl}${r}): ${f.statusText} - ${n}`;throw this._debug&&c.log("api","APIClient",`\u2717 ${e} ${r}`,{method:e,endpoint:r,status:f.status,duration:w,error:n}),new Error(b)}return this._debug&&c.log("api","APIClient",`\u2713 ${e} ${r}`,{method:e,endpoint:r,status:f.status,duration:w}),f.json()}catch(f){let w=Date.now()-C;throw this._debug&&c.log("api","APIClient",`\u2717 ${e} ${r} \u2014 Network error`,{method:e,endpoint:r,duration:w,error:String(f)}),console.error("GrowthRail SDK Error:",f),f}}async getNewUserExperience(){return this.request("/api/v1/sdk/new-user-experience","POST")}async initAppUser(r){return this.request("/api/v1/sdk/init-app-user","POST",{clientProvidedId:r})}async trackReferral(r,e){return this.request("/api/v1/sdk/track-referral","POST",{referralCode:r,rewardEventName:e})}async trackRewardEvent(r,e,l){return this.request("/api/v1/sdk/track-reward-event","POST",{refereeId:r,referralTrackingId:e,eventName:l})}async checkDeferredDeepLink(r){return this.request("/api/v1/sdk/match-link","POST",{fingerprint:r})}};import te from"@react-native-async-storage/async-storage";var oe={TRACKED_REFERRAL:"growth-rail-tracked-referral",IS_FIRST_LAUNCH:"growth-rail-is-first-launch"},S=class{static async setTrackedReferral(r){await te.setItem(oe.TRACKED_REFERRAL,r)}static async getTrackedReferral(){return await te.getItem(oe.TRACKED_REFERRAL)}static async isFirstLaunch(){return await te.getItem(oe.IS_FIRST_LAUNCH)===null?(await te.setItem(oe.IS_FIRST_LAUNCH,"false"),!0):!1}};import o,{useEffect as Pe,useState as ge,useRef as Ce}from"react";import{Modal as Ge,View as m,Text as T,StyleSheet as xe,TouchableOpacity as ie,Clipboard as Fe,ActivityIndicator as $e,Linking as Te,ScrollView as Me,Platform as We,Animated as D,Dimensions as Ne,useColorScheme as je}from"react-native";import{useSafeAreaInsets as _e}from"react-native-safe-area-context";var{width:Ir,height:ve}=Ne.get("window"),ue=({visible:d,options:r,onClose:e})=>{let l=ne(),[t,C]=ge(null),[f,w]=ge(!1),[n,b]=ge(!1),y=_e(),h=Ce(new D.Value(0)).current,x=Ce(new D.Value(0)).current,$=je(),R=(r?.appearance||$||"light")==="dark",le=r?.title||"Invite Friends & Earn",V=r?.theme?.primaryColor||"#2563eb",L=(r?.componentType||"modal")==="drawer",J=r?.position||"bottom-right",a={background:R?"#111827":"#ffffff",text:R?"#f9fafb":"#111827",textSecondary:R?"#9ca3af":"#6b7280",border:R?"#374151":"#e5e7eb",inputBg:R?"#1f2937":"#f9fafb",closeBtnBg:R?"#1f2937":"#f3f4f6",closeIcon:R?"#6b7280":"#9ca3af",drawerHandle:R?"#4b5563":"#e5e7eb",overlay:"#000000",overlayOpacity:.5};Pe(()=>{d?(t||ce(),D.parallel([D.timing(x,{toValue:1,duration:300,useNativeDriver:!0}),D.spring(h,{toValue:1,useNativeDriver:!0,tension:50,friction:8})]).start()):(h.setValue(0),x.setValue(0))},[d]);let M=()=>{D.parallel([D.timing(x,{toValue:0,duration:250,useNativeDriver:!0}),D.timing(h,{toValue:0,duration:250,useNativeDriver:!0})]).start(()=>{e()})},ce=async()=>{w(!0);try{if(l.isUserReady){let A=await l.getReferralLink();C(A||null)}}catch(A){console.error("GrowthRail: Failed to load referral link",A)}finally{w(!1)}},de=()=>{t&&(Fe.setString(t),b(!0),setTimeout(()=>b(!1),2e3))},E=A=>{if(!t)return;let I="",z=encodeURIComponent(t),j=encodeURIComponent("Check this out!");switch(A){case"twitter":I=`https://twitter.com/intent/tweet?url=${z}&text=${j}`;break;case"facebook":I=`https://www.facebook.com/sharer/sharer.php?u=${z}`;break;case"linkedin":I=`https://www.linkedin.com/sharing/share-offsite/?url=${z}`;break;case"whatsapp":I=`whatsapp://send?text=${j}%20${z}`;break;case"email":I=`mailto:?subject=Check this out&body=${j}%20${z}`;break}I&&Te.openURL(I).catch(()=>{})},W=()=>a.overlay,G=[];L?G=[{translateY:h.interpolate({inputRange:[0,1],outputRange:[ve,0]})}]:G=[{scale:h.interpolate({inputRange:[0,1],outputRange:[.9,1]})},{translateY:h.interpolate({inputRange:[0,1],outputRange:[20,0]})}];let K=J.includes("top"),Ve=J.includes("right"),N=J.includes("left"),Q=L?{position:"absolute",bottom:0,left:0,right:0,width:"100%",maxHeight:"90%"}:{};return o.createElement(Ge,{visible:d,transparent:!0,animationType:"none",onRequestClose:M},o.createElement(m,{style:i.fullScreen},o.createElement(D.View,{style:[i.overlay,{backgroundColor:W(),opacity:x.interpolate({inputRange:[0,1],outputRange:[0,a.overlayOpacity]})}]},o.createElement(ie,{style:i.fullScreen,activeOpacity:1,onPress:M})),o.createElement(D.View,{style:[L?Q:i.centeredModalContainer,{backgroundColor:a.background,transform:G},L&&{borderTopLeftRadius:24,borderTopRightRadius:24,borderBottomLeftRadius:0,borderBottomRightRadius:0,paddingBottom:y.bottom},!L&&{borderRadius:24,opacity:h,borderColor:a.border,borderWidth:R?1:0}]},o.createElement(m,{style:[i.contentWrapper,{paddingTop:Math.max(y.top,16)}]},L&&o.createElement(m,{style:[i.drawerHandle,{backgroundColor:a.drawerHandle}]}),o.createElement(ie,{style:[i.closeBtn,{backgroundColor:a.closeBtnBg,top:Math.max(y.top,16)}],onPress:M},o.createElement(T,{style:[i.closeIcon,{color:a.closeIcon}]},"\u2715")),o.createElement(Me,{contentContainerStyle:i.scrollContent,showsVerticalScrollIndicator:!1},o.createElement(m,{style:i.header},o.createElement(m,{style:i.iconLgContainer},o.createElement(m,{style:i.bowContainerLg},o.createElement(m,{style:[i.bowLoopLg,i.bowLeftLg,{borderColor:V}]}),o.createElement(m,{style:[i.bowLoopLg,i.bowRightLg,{borderColor:V}]})),o.createElement(m,{style:[i.giftLidLg,{backgroundColor:V}]}),o.createElement(m,{style:[i.giftBodyLg,{borderColor:V}]},o.createElement(m,{style:[i.ribbonVerticalLg,{backgroundColor:"#fff",opacity:.3}]}))),o.createElement(T,{style:[i.title,{color:a.text}]},le),o.createElement(T,{style:[i.subtitle,{color:a.textSecondary}]},r?.description||"Share your unique link and earn rewards for every friend who signs up.")),l.isUserReady?f?o.createElement($e,{size:"large",color:V,style:i.loader}):o.createElement(m,{style:i.mainContent},o.createElement(T,{style:[i.label,{color:a.textSecondary}]},"YOUR UNIQUE LINK"),o.createElement(m,{style:[i.inputGroup,{backgroundColor:a.inputBg,borderColor:a.border}]},o.createElement(T,{numberOfLines:1,style:[i.input,{color:a.text}]},t||"Initializing..."),o.createElement(ie,{style:[i.copyBtn,{backgroundColor:n?"#10b981":V}],onPress:de},o.createElement(T,{style:i.copyBtnText},n?"Copied!":"Copy"))),o.createElement(m,{style:i.shareLabelContainer},o.createElement(m,{style:[i.divider,{backgroundColor:a.border}]}),o.createElement(T,{style:[i.shareLabel,{color:a.textSecondary}]},"Share via"),o.createElement(m,{style:[i.divider,{backgroundColor:a.border}]})),o.createElement(m,{style:i.socialContainer},o.createElement(q,{platform:"twitter",color:R?"#FFFFFF":"#000000",onPress:()=>E("twitter"),icon:"\u{1D54F}",borderColor:a.border,bgColor:a.background}),o.createElement(q,{platform:"facebook",color:"#1877F2",onPress:()=>E("facebook"),icon:"f",borderColor:a.border,bgColor:a.background}),o.createElement(q,{platform:"linkedin",color:"#0A66C2",onPress:()=>E("linkedin"),icon:"in",borderColor:a.border,bgColor:a.background}),o.createElement(q,{platform:"whatsapp",color:"#25D366",onPress:()=>E("whatsapp"),icon:"W",borderColor:a.border,bgColor:a.background}),o.createElement(q,{platform:"email",color:a.textSecondary,onPress:()=>E("email"),icon:"\u2709",borderColor:a.border,bgColor:a.background}))):o.createElement(m,{style:[i.loadingBox,{backgroundColor:a.inputBg,borderColor:a.border}]},o.createElement(T,{style:{color:a.textSecondary,textAlign:"center"}},"Please log in to view your referral dashboard.")),o.createElement(m,{style:i.footer},o.createElement(T,{style:[i.poweredBy,{color:a.textSecondary}]},"Powered by ",o.createElement(T,{style:[i.brand,{color:V}],onPress:()=>Te.openURL("https://growthrail.com")},"Growth Rail"))))))))},q=({color:d,onPress:r,icon:e,borderColor:l,bgColor:t})=>o.createElement(ie,{style:[i.socialBtn,{borderColor:l,backgroundColor:t}],onPress:r},o.createElement(T,{style:[i.socialIcon,{color:d}]},e)),i=xe.create({fullScreen:{flex:1},overlay:{...xe.absoluteFillObject},centeredModalContainer:{width:"90%",maxWidth:400,alignSelf:"center",marginTop:ve*.15,overflow:"hidden",shadowColor:"#000",shadowOffset:{width:0,height:20},shadowOpacity:.25,shadowRadius:30,elevation:20},contentWrapper:{},drawerHandle:{width:40,height:4,backgroundColor:"#e5e7eb",borderRadius:2,alignSelf:"center",marginTop:12},scrollContent:{padding:32,alignItems:"center"},closeBtn:{position:"absolute",top:20,right:20,zIndex:10,width:32,height:32,borderRadius:16,backgroundColor:"#f3f4f6",justifyContent:"center",alignItems:"center"},closeIcon:{fontSize:14,color:"#9ca3af"},header:{alignItems:"center",marginBottom:28,width:"100%"},socialIcon:{fontSize:18,fontWeight:"bold"},title:{fontSize:22,fontWeight:"700",letterSpacing:-.5,marginBottom:8,textAlign:"center"},subtitle:{fontSize:14,lineHeight:20,textAlign:"center",paddingHorizontal:10},loadingBox:{padding:16,backgroundColor:"#f9fafb",borderRadius:12,width:"100%",alignItems:"center",borderWidth:1,borderColor:"#e5e7eb",marginTop:20},loader:{marginVertical:20},mainContent:{width:"100%"},label:{fontSize:12,fontWeight:"600",color:"#6b7280",marginBottom:8,letterSpacing:.5},inputGroup:{flexDirection:"row",alignItems:"center",backgroundColor:"#f9fafb",borderWidth:1,borderColor:"#e5e7eb",borderRadius:12,padding:6,marginBottom:24},input:{flex:1,paddingHorizontal:12,fontSize:14,color:"#111827",fontFamily:We.OS==="ios"?"Menlo":"monospace"},copyBtn:{paddingVertical:8,paddingHorizontal:16,borderRadius:8,justifyContent:"center",alignItems:"center"},copyBtnText:{color:"#fff",fontSize:13,fontWeight:"600"},shareLabelContainer:{flexDirection:"row",alignItems:"center",marginBottom:16,marginTop:8},divider:{flex:1,height:1,backgroundColor:"#e5e7eb"},shareLabel:{marginHorizontal:12,fontSize:13,fontWeight:"500",color:"#6b7280"},socialContainer:{flexDirection:"row",justifyContent:"center",gap:12},socialBtn:{width:44,height:44,borderRadius:22,backgroundColor:"#fff",borderWidth:1,justifyContent:"center",alignItems:"center"},iconLgContainer:{width:60,height:60,justifyContent:"center",alignItems:"center",marginBottom:16},bowContainerLg:{flexDirection:"row",position:"absolute",top:2,zIndex:2},bowLoopLg:{width:20,height:16,borderWidth:3,borderColor:"#e5e7eb",borderRadius:10},bowLeftLg:{marginRight:-2,transform:[{rotate:"-15deg"}]},bowRightLg:{marginLeft:-2,transform:[{rotate:"15deg"}]},giftLidLg:{width:44,height:10,backgroundColor:"#f3f4f6",borderRadius:2,marginTop:12,zIndex:3},giftBodyLg:{width:36,height:24,borderWidth:3,borderTopWidth:0,borderBottomLeftRadius:4,borderBottomRightRadius:4,justifyContent:"center",alignItems:"center",marginTop:-2},ribbonVerticalLg:{width:4,height:"100%",opacity:.1},footer:{marginTop:32,alignItems:"center"},poweredBy:{fontSize:11,color:"#9ca3af"},brand:{fontWeight:"600",textDecorationLine:"underline"}});import B,{useEffect as He,useRef as Ke}from"react";import{TouchableOpacity as qe,View as P,StyleSheet as Ye,Animated as pe,Easing as Xe}from"react-native";import{useSafeAreaInsets as Je}from"react-native-safe-area-context";var he=({onPress:d,options:r})=>{let e=Je(),l=r?.modal?.theme?.primaryColor||"#2563eb",t=r?.trigger?.position||"bottom-right",f=(r?.trigger?.displayMode||"floating")==="edge",w=t.includes("right"),n=t.includes("top"),b=Ke(new pe.Value(-1)).current;He(()=>{let $=()=>{b.setValue(-1),pe.timing(b,{toValue:2,duration:3e3,easing:Xe.linear,useNativeDriver:!0}).start(()=>{setTimeout($,1e3)})};$()},[]);let y=b.interpolate({inputRange:[-1,2],outputRange:f?[-50,100]:[-60,120]}),h={"bottom-right":{bottom:100+e.bottom,right:0},"bottom-left":{bottom:100+e.bottom,left:0},"top-right":{top:100+e.top,right:0},"top-left":{top:100+e.top,left:0}};f||(h["bottom-right"]={bottom:30+e.bottom,right:20},h["bottom-left"]={bottom:30+e.bottom,left:20},h["top-right"]={top:60+e.top,right:20},h["top-left"]={top:60+e.top,left:20});let x=()=>B.createElement(P,{style:k.iconContainer},B.createElement(P,{style:k.bowContainer},B.createElement(P,{style:[k.bowLoop,k.bowLeft]}),B.createElement(P,{style:[k.bowLoop,k.bowRight]})),B.createElement(P,{style:k.giftLid}),B.createElement(P,{style:k.giftBody},B.createElement(P,{style:k.ribbonVertical})));return B.createElement(qe,{style:[f?k.edgeButton:k.floatingButton,{backgroundColor:l},h[t],f&&(w?k.edgeRight:k.edgeLeft)],onPress:d,activeOpacity:.9},B.createElement(P,{style:k.content},x()),B.createElement(pe.View,{style:[k.shimmer,{transform:[{translateX:y},{skewX:"-15deg"}]}]}))},k=Ye.create({floatingButton:{position:"absolute",width:60,height:60,borderRadius:30,justifyContent:"center",alignItems:"center",overflow:"hidden",shadowColor:"#000",shadowOffset:{width:0,height:8},shadowOpacity:.2,shadowRadius:12,elevation:8,zIndex:2147483646},edgeButton:{position:"absolute",width:50,height:50,justifyContent:"center",alignItems:"center",overflow:"hidden",shadowColor:"#000",shadowOffset:{width:0,height:4},shadowOpacity:.1,shadowRadius:8,elevation:4,zIndex:2147483646},edgeRight:{borderTopLeftRadius:8,borderBottomLeftRadius:8,paddingLeft:4},edgeLeft:{borderTopRightRadius:8,borderBottomRightRadius:8,paddingRight:4},content:{justifyContent:"center",alignItems:"center"},iconContainer:{width:28,height:28,justifyContent:"center",alignItems:"center"},bowContainer:{flexDirection:"row",position:"absolute",top:0,zIndex:2},bowLoop:{width:10,height:8,borderWidth:2,borderColor:"#fff",borderRadius:5},bowLeft:{marginRight:-1,transform:[{rotate:"-15deg"}]},bowRight:{marginLeft:-1,transform:[{rotate:"15deg"}]},giftLid:{width:22,height:5,backgroundColor:"#fff",borderRadius:1,marginTop:6,zIndex:3},giftBody:{width:18,height:12,borderWidth:2,borderColor:"#fff",borderTopWidth:0,borderBottomLeftRadius:2,borderBottomRightRadius:2,justifyContent:"center",alignItems:"center",marginTop:-1},ribbonVertical:{width:2,height:"100%",backgroundColor:"#fff",opacity:.8},shimmer:{position:"absolute",top:0,left:0,width:50,height:"100%",backgroundColor:"rgba(255, 255, 255, 0.25)"}});import _,{useEffect as Qe,useRef as Ze,useState as er}from"react";import{View as rr,Text as we,StyleSheet as tr,Animated as ae,Dimensions as or,TouchableOpacity as ir}from"react-native";import{useSafeAreaInsets as nr}from"react-native-safe-area-context";var{width:ar}=or.get("window"),Le=({visible:d,options:r,onClose:e})=>{let l=Ze(new ae.Value(0)).current,[t,C]=er(d),f=nr(),w=r.position.includes("bottom")?"bottom":"top",n=r.position.includes("left")?"left":r.position.includes("right")?"right":"center";if(Qe(()=>{d?(C(!0),ae.spring(l,{toValue:1,useNativeDriver:!0,tension:50,friction:8}).start()):ae.timing(l,{toValue:0,duration:250,useNativeDriver:!0}).start(()=>{C(!1)})},[d]),!t)return null;let b=l.interpolate({inputRange:[0,1],outputRange:[w==="top"?-100:100,0]}),y=l.interpolate({inputRange:[0,1],outputRange:[0,1]}),h={position:"absolute",[w]:w==="top"?16+f.top:16+f.bottom,zIndex:9999};return n==="center"?(h.left=20,h.right=20,h.alignItems="center"):h[n]=20,_.createElement(ae.View,{style:[h,{transform:[{translateY:b}],opacity:y}]},_.createElement(rr,{style:[Y.banner,{backgroundColor:r.themeColor||"#2563eb"}]},_.createElement(we,{style:Y.icon},"\u{1F381}"),_.createElement(we,{style:Y.text},r.text),_.createElement(ir,{onPress:e,style:Y.closeBtn},_.createElement(we,{style:Y.closeIcon},"\u2715"))))},Y=tr.create({banner:{flexDirection:"row",alignItems:"center",padding:12,paddingHorizontal:16,borderRadius:12,shadowColor:"#000",shadowOffset:{width:0,height:4},shadowOpacity:.15,shadowRadius:10,elevation:5,maxWidth:ar-40},icon:{fontSize:18,marginRight:10},text:{color:"#fff",fontSize:14,fontWeight:"600",flex:1},closeBtn:{marginLeft:10,padding:4},closeIcon:{color:"rgba(255, 255, 255, 0.8)",fontSize:14,fontWeight:"bold"}});var Se=sr(void 0),gr=({children:d,userId:r,debug:e=!1,...l})=>{let[t,C]=U(!1),[f,w]=U(!1),[n,b]=U(null),y=be(new re(l)),h=be(!1),x=be(null),[$,X]=U(!1),[R,le]=U(),[V,Re]=U(!1),[L,J]=U(),[a,M]=U(!1),[ce,de]=U();me(()=>{y.current.setDebug(e),e&&c.log("info","Provider","Debug mode enabled")},[e]);let E=v(()=>{let{width:s,height:g}=cr.get("window"),u=Intl.DateTimeFormat().resolvedOptions().locale,p=dr.get(),O,Z;if(H.OS==="android"){let fe=H.constants;O=fe.Model,Z=fe.Brand||fe.Manufacturer}return{os:H.OS,platform:H.OS,osVersion:String(H.Version),screenWidth:s,screenHeight:g,timezoneOffsetInMinutes:String(new Date().getTimezoneOffset()),locale:u,language:u,deviceModel:O,deviceBrand:Z,pixelRatio:p}},[]),W=v(async(s,g)=>{e&&c.log("info","Referral",`Tracking referral code: ${s}`,{referralCode:s,rewardEventName:g});let u=await y.current.trackReferral(s,g);return await S.setTrackedReferral(u.referralTrackingId),e&&c.log("success","Referral",`Referral tracked \u2192 ${u.referralTrackingId}`,u),u},[e]),G=v(async s=>{try{e&&c.log("info","DeepLink",`Received deep link: ${s}`);let g=s.match(/[?&]referralCode=([^&]+)/);g&&(console.log("GrowthRail: Tracking referral from deep link",g[1]),e&&c.log("info","DeepLink",`Found referral code in deep link: ${g[1]}`),await W(g[1]))}catch(g){console.warn("GrowthRail: Error handling deep link",g),e&&c.log("error","DeepLink","Deep link handling failed",{error:String(g)})}},[W,e]),K=v(async()=>{try{e&&c.log("info","Deferred","Checking deferred deep link via fingerprint");let s=E(),{referralTrackingId:g}=await y.current.checkDeferredDeepLink(s);g?(console.log("GrowthRail: Found deferred referral via fingerprinting",g),e&&c.log("success","Deferred",`Deferred referral matched \u2192 ${g}`),await S.setTrackedReferral(g)):e&&c.log("info","Deferred","No deferred referral match found")}catch(s){console.warn("GrowthRail: Fingerprint check failed",s),e&&c.log("error","Deferred","Fingerprint check failed",{error:String(s)})}},[E,e]),Ve=v(()=>new Promise(s=>{fr.getInstallReferrerInfo(async(g,u)=>{if(!u&&g&&g.installReferrer)try{let O=decodeURIComponent(g.installReferrer).match(/[?&]referralCode=([^&]+)/);if(O){let{referralTrackingId:Z}=await W(O[1]);await S.setTrackedReferral(Z),console.log("GrowthRail: Tracked referral via Install Referrer")}}catch(p){console.warn("GrowthRail: Failed to process install referrer",p)}else await K();s()})}),[W,K]),N=v(async s=>{if(n?.id===s&&f)return e&&c.log("info","User",`User ${s} already initialized, skipping`),n;e&&c.log("info","User",`Initializing user: ${s}`);let g=(async()=>{try{let u=await y.current.initAppUser(s),p={...u,id:s};return b(p),w(!0),e&&c.log("success","User",`User initialized: ${s}`,{referralCode:u.referralCode,referralLink:u.referralLink}),u.referrerExperience?.trigger?.displayMode!=="none"&&(Re(!0),e&&c.log("info","UI","Trigger button shown (server-configured)")),p}catch(u){throw x.current=null,e&&c.log("error","User",`User init failed for ${s}`,{error:String(u)}),u}})();return x.current=g,g},[n,f,e]),Q=v(async s=>{e&&c.log("info","Reward",`Tracking reward event: ${s||"(default)"}`);let g=n;!g&&x.current&&(g=await x.current);let u=g?.id||r;if(!u)throw e&&c.log("error","Reward","Cannot track reward \u2014 user not initialized"),new Error("GrowthRail: User must be initialized before tracking a reward event.");let p=await S.getTrackedReferral();if(!p){console.warn("GrowthRail: No referral tracking ID found. Reward event not attributed."),e&&c.log("warn","Reward","No referral tracking ID in storage \u2014 reward not attributed");return}let O=await y.current.trackRewardEvent(u,p,s);return e&&c.log("success","Reward",`Reward event tracked for user ${u}`),O},[n,r,e]),A=v(async()=>await S.getTrackedReferral(),[]),I=v(async()=>{if(n)return n.referralLink;if(x.current)return(await x.current).referralLink},[n]);me(()=>{if(h.current)return;h.current=!0,e&&c.log("info","Provider","SDK initializing\u2026",{platform:H.OS});let s;return(async()=>{try{let p=await Ie.getInitialURL();e&&c.log("info","DeepLink",`Initial URL: ${p??"(none)"}`),p&&await G(p)}catch(p){console.warn("GrowthRail: Error getting initial URL",p)}s=Ie.addEventListener("url",({url:p})=>G(p));let u=await S.isFirstLaunch();e&&c.log("info","Provider",`First launch: ${u}`),u&&await K(),r&&await N(r);try{let p=await y.current.getNewUserExperience(),O=await S.getTrackedReferral();p.banner?.show&&O&&(de(p.banner),M(!0),e&&c.log("info","UI","Banner shown for new user experience"))}catch(p){e&&c.log("warn","Provider","New user experience fetch failed",{error:String(p)})}C(!0),e&&c.log("success","Provider","SDK initialization complete \u2713")})(),()=>{s&&s.remove()}},[e,G,K,N,r]),me(()=>{t&&r&&n?.id!==r&&N(r)},[r,t]);let z=v(s=>{le(s),X(!0)},[]),j=v(()=>{X(!1)},[]),ke=ye(()=>({isInitialized:t,isUserReady:f,currentUser:n,referralCode:n?.referralCode,referralLink:n?.referralLink,showDashboard:z,hideDashboard:j,initUser:N,trackReward:Q,getReferralTrackingId:A,getReferralLink:I,isDebugEnabled:e}),[t,f,n,z,j,N,Q,A,I,e]),F=n?.referrerExperience,Oe=ye(()=>({...F?.modal,...R,appearance:R?.appearance||F?.modal?.appearance||l.appearance,theme:{...F?.modal?.theme||{},...R?.theme||{}}}),[F?.modal,R,l.appearance]),Ue=ye(()=>({...F,...L,trigger:{...F?.trigger||{},...L?.trigger||{}}}),[F,L]);return t?se.createElement(Se.Provider,{value:ke},d,se.createElement(ue,{visible:$,options:Oe,onClose:()=>X(!1)}),V&&se.createElement(he,{options:Ue,onPress:()=>ke.showDashboard()}),a&&se.createElement(Le,{visible:a,options:ce,onClose:()=>M(!1)})):null},ne=()=>{let d=lr(Se);if(!d)throw new Error("useGrowthRail must be used within a GrowthRailProvider");return d};import{useState as De,useCallback as Be,useMemo as ur}from"react";var pr=()=>{let[d,r]=De(!1),[e,l]=De(null),t=ne(),C=Be(async w=>{r(!0),l(null);try{return await t.initUser(w)}catch(n){let b=n instanceof Error?n:new Error(String(n));throw l(b),b}finally{r(!1)}},[t]),f=Be(async w=>{r(!0),l(null);try{await t.trackReward(w)}catch(n){let b=n instanceof Error?n:new Error(String(n));throw l(b),b}finally{r(!1)}},[t]);return ur(()=>({initAppUser:C,trackRewardEvent:f,showReferralDashboard:t.showDashboard,hideReferralDashboard:t.hideDashboard,getReferralTrackingId:t.getReferralTrackingId,getReferralLink:t.getReferralLink,isLoading:d,isInitialized:t.isInitialized,isUserReady:t.isUserReady,error:e,isDebugEnabled:t.isDebugEnabled}),[C,f,t.showDashboard,t.hideDashboard,t.getReferralTrackingId,t.getReferralLink,d,t.isInitialized,t.isUserReady,e,t.isDebugEnabled])};export{gr as GrowthRailProvider,ue as ReferralDashboard,he as TriggerButton,pr as useGrowthRail};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@growth-rail/react-native",
3
- "version": "2.0.5",
3
+ "version": "2.0.6",
4
4
  "description": "Growth Rail SDK for React Native",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -34,13 +34,15 @@
34
34
  },
35
35
  "peerDependencies": {
36
36
  "react": ">=16.8.0",
37
- "react-native": ">=0.60.0"
37
+ "react-native": ">=0.60.0",
38
+ "react-native-safe-area-context": ">=3.0.0"
38
39
  },
39
40
  "devDependencies": {
40
41
  "@growth-rail/eslint-config": "*",
41
42
  "@growth-rail/tsconfig": "*",
42
43
  "@types/react": "^18.0.0",
43
44
  "@types/react-native": "^0.72.0",
45
+ "react-native-safe-area-context": "^4.12.0",
44
46
  "tsup": "^8.0.0",
45
47
  "typescript": "^5.0.0"
46
48
  },