@growth-rail/react-native 2.0.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var Ce=Object.create;var _=Object.defineProperty;var ke=Object.getOwnPropertyDescriptor;var Te=Object.getOwnPropertyNames;var xe=Object.getPrototypeOf,ve=Object.prototype.hasOwnProperty;var Le=(o,e,a)=>e in o?_(o,e,{enumerable:!0,configurable:!0,writable:!0,value:a}):o[e]=a;var Ie=(o,e)=>{for(var a in e)_(o,a,{get:e[a],enumerable:!0})},ue=(o,e,a,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let l of Te(e))!ve.call(o,l)&&l!==a&&_(o,l,{get:()=>e[l],enumerable:!(s=ke(e,l))||s.enumerable});return o};var W=(o,e,a)=>(a=o!=null?Ce(xe(o)):{},ue(e||!o||!o.__esModule?_(a,"default",{value:o,enumerable:!0}):a,o)),Se=o=>ue(_({},"__esModule",{value:!0}),o);var de=(o,e,a)=>Le(o,typeof e!="symbol"?e+"":e,a);var Be={};Ie(Be,{GrowthRailProvider:()=>be,ReferralDashboard:()=>te,TriggerButton:()=>oe,useGrowthRail:()=>ye});module.exports=Se(Be);var n=W(require("react")),C=require("react-native"),we=W(require("react-native-play-install-referrer"));var Z=class{constructor(e){de(this,"baseUrl");de(this,"projectSecretKey");let a=typeof process<"u"&&process.env?.ENV_BASE_URL;this.baseUrl=a||"https://api.growthrail.dev",this.projectSecretKey=e.projectSecretKey}async request(e,a,s){let l={"Content-Type":"application/json","X-GrowthRail-ProjectSecret":this.projectSecretKey,Origin:this.baseUrl};try{let f=await fetch(`${this.baseUrl}${e}`,{method:a,headers:l,body:s?JSON.stringify(s):void 0});if(!f.ok){let k="";try{k=await f.text()}catch{}throw new Error(`GrowthRail API Error ${f.status} (${this.baseUrl}${e}): ${f.statusText} - ${k}`)}return f.json()}catch(f){throw console.error("GrowthRail SDK Error:",f),f}}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,a){return this.request("/api/v1/sdk/track-referral","POST",{referralCode:e,rewardEventName:a})}async trackRewardEvent(e,a,s){return this.request("/api/v1/sdk/track-reward-event","POST",{refereeId:e,referralTrackingId:a,eventName:s})}async checkDeferredDeepLink(e){return this.request("/api/v1/sdk/match-link","POST",{fingerprint:e})}};var K=W(require("@react-native-async-storage/async-storage")),ee={TRACKED_REFERRAL:"growth-rail-tracked-referral",IS_FIRST_LAUNCH:"growth-rail-is-first-launch"},D=class{static async setTrackedReferral(e){await K.default.setItem(ee.TRACKED_REFERRAL,e)}static async getTrackedReferral(){return await K.default.getItem(ee.TRACKED_REFERRAL)}static async isFirstLaunch(){return await K.default.getItem(ee.IS_FIRST_LAUNCH)===null?(await K.default.setItem(ee.IS_FIRST_LAUNCH,"false"),!0):!1}};var r=W(require("react")),t=require("react-native");var{width:pe,height:fe}=t.Dimensions.get("window"),te=({visible:o,options:e,onClose:a})=>{let s=re(),[l,f]=(0,r.useState)(null),[k,d]=(0,r.useState)(!1),[p,m]=(0,r.useState)(!1),g=(0,r.useRef)(new t.Animated.Value(0)).current,T=(0,r.useRef)(new t.Animated.Value(0)).current,z=e?.title||"Invite Friends & Earn",B=e?.theme?.primaryColor||"#2563eb",M=e?.theme?.backgroundColor||"#ffffff",ie=e?.theme?.tintColor||"#000000",ne=e?.theme?.tintAlpha??.5,v=(e?.componentType||"modal")==="drawer",E=e?.position||"bottom-right",Y="#111827",j="#6b7280";(0,r.useEffect)(()=>{o?(l||ae(),t.Animated.parallel([t.Animated.timing(T,{toValue:1,duration:300,useNativeDriver:!0}),t.Animated.spring(g,{toValue:1,useNativeDriver:!0,tension:50,friction:8})]).start()):(g.setValue(0),T.setValue(0))},[o]);let $=()=>{t.Animated.parallel([t.Animated.timing(T,{toValue:0,duration:250,useNativeDriver:!0}),t.Animated.timing(g,{toValue:0,duration:250,useNativeDriver:!0})]).start(()=>{a()})},ae=async()=>{d(!0);try{if(s.isUserReady){let G=await s.getReferralLink();f(G||null)}}catch(G){console.error("GrowthRail: Failed to load referral link",G)}finally{d(!1)}},J=()=>{l&&(t.Clipboard.setString(l),m(!0),setTimeout(()=>m(!1),2e3))},V=G=>{if(!l)return;let O="",I=encodeURIComponent(l),H=encodeURIComponent("Check this out!");switch(G){case"twitter":O=`https://twitter.com/intent/tweet?url=${I}&text=${H}`;break;case"facebook":O=`https://www.facebook.com/sharer/sharer.php?u=${I}`;break;case"linkedin":O=`https://www.linkedin.com/sharing/share-offsite/?url=${I}`;break;case"whatsapp":O=`whatsapp://send?text=${H}%20${I}`;break;case"email":O=`mailto:?subject=Check this out&body=${H}%20${I}`;break}O&&t.Linking.openURL(O).catch(()=>{})},Q=()=>ie||"#000000",U=[];v?E.includes("right")?U=[{translateX:g.interpolate({inputRange:[0,1],outputRange:[pe,0]})}]:E.includes("left")?U=[{translateX:g.interpolate({inputRange:[0,1],outputRange:[-pe,0]})}]:U=[{translateY:g.interpolate({inputRange:[0,1],outputRange:[fe,0]})}]:U=[{scale:g.interpolate({inputRange:[0,1],outputRange:[.9,1]})},{translateY:g.interpolate({inputRange:[0,1],outputRange:[20,0]})}];let se=E.includes("top"),L=E.includes("right"),A=E.includes("left"),le=v?{position:"absolute",...se?{top:100}:{bottom:100},...L?{right:0}:A?{left:0}:{left:0,right:0},width:L||A?"85%":"100%",maxHeight:L||A?fe-200:"80%"}:{};return r.default.createElement(t.Modal,{visible:o,transparent:!0,animationType:"none",onRequestClose:$},r.default.createElement(t.View,{style:i.fullScreen},r.default.createElement(t.Animated.View,{style:[i.overlay,{backgroundColor:Q(),opacity:T.interpolate({inputRange:[0,1],outputRange:[0,ne]})}]},r.default.createElement(t.TouchableOpacity,{style:i.fullScreen,activeOpacity:1,onPress:$})),r.default.createElement(t.Animated.View,{style:[v?le:i.centeredModalContainer,{backgroundColor:M,transform:U},v&&L&&{borderTopLeftRadius:24,borderBottomLeftRadius:24},v&&A&&{borderTopRightRadius:24,borderBottomRightRadius:24},v&&!L&&!A&&E.includes("bottom")&&{borderTopLeftRadius:24,borderTopRightRadius:24},v&&!L&&!A&&E.includes("top")&&{borderBottomLeftRadius:24,borderBottomRightRadius:24},!v&&{borderRadius:24,opacity:g}]},r.default.createElement(t.View,{style:i.contentWrapper},v&&!L&&!A&&E.includes("bottom")&&r.default.createElement(t.View,{style:i.drawerHandle}),r.default.createElement(t.TouchableOpacity,{style:i.closeBtn,onPress:$},r.default.createElement(t.Text,{style:i.closeIcon},"\u2715")),r.default.createElement(t.ScrollView,{contentContainerStyle:i.scrollContent,showsVerticalScrollIndicator:!1},r.default.createElement(t.View,{style:i.header},r.default.createElement(t.View,{style:i.iconLgContainer},r.default.createElement(t.View,{style:i.bowContainerLg},r.default.createElement(t.View,{style:[i.bowLoopLg,i.bowLeftLg,{borderColor:B}]}),r.default.createElement(t.View,{style:[i.bowLoopLg,i.bowRightLg,{borderColor:B}]})),r.default.createElement(t.View,{style:[i.giftLidLg,{backgroundColor:B}]}),r.default.createElement(t.View,{style:[i.giftBodyLg,{borderColor:B}]},r.default.createElement(t.View,{style:[i.ribbonVerticalLg,{backgroundColor:"#fff",opacity:.3}]}))),r.default.createElement(t.Text,{style:[i.title,{color:Y}]},z),r.default.createElement(t.Text,{style:[i.subtitle,{color:j}]},e?.description||"Share your unique link and earn rewards for every friend who signs up.")),s.isUserReady?k?r.default.createElement(t.ActivityIndicator,{size:"large",color:B,style:i.loader}):r.default.createElement(t.View,{style:i.mainContent},r.default.createElement(t.Text,{style:i.label},"YOUR UNIQUE LINK"),r.default.createElement(t.View,{style:i.inputGroup},r.default.createElement(t.Text,{numberOfLines:1,style:i.input},l||"Initializing..."),r.default.createElement(t.TouchableOpacity,{style:[i.copyBtn,{backgroundColor:p?"#10b981":B}],onPress:J},r.default.createElement(t.Text,{style:i.copyBtnText},p?"Copied!":"Copy"))),r.default.createElement(t.View,{style:i.shareLabelContainer},r.default.createElement(t.View,{style:i.divider}),r.default.createElement(t.Text,{style:i.shareLabel},"Share via"),r.default.createElement(t.View,{style:i.divider})),r.default.createElement(t.View,{style:i.socialContainer},r.default.createElement(q,{platform:"twitter",color:"#000000",onPress:()=>V("twitter"),icon:"\u{1D54F}"}),r.default.createElement(q,{platform:"facebook",color:"#1877F2",onPress:()=>V("facebook"),icon:"f"}),r.default.createElement(q,{platform:"linkedin",color:"#0A66C2",onPress:()=>V("linkedin"),icon:"in"}),r.default.createElement(q,{platform:"whatsapp",color:"#25D366",onPress:()=>V("whatsapp"),icon:"W"}),r.default.createElement(q,{platform:"email",color:"#888888",onPress:()=>V("email"),icon:"\u2709"}))):r.default.createElement(t.View,{style:i.loadingBox},r.default.createElement(t.Text,{style:{color:j,textAlign:"center"}},"Please log in to view your referral dashboard.")),r.default.createElement(t.View,{style:i.footer},r.default.createElement(t.Text,{style:i.poweredBy},"Powered by ",r.default.createElement(t.Text,{style:i.brand,onPress:()=>t.Linking.openURL("https://growthrail.com")},"Growth Rail"))))))))},q=({color:o,onPress:e,icon:a})=>r.default.createElement(t.TouchableOpacity,{style:[i.socialBtn,{borderColor:"#e5e7eb"}],onPress:e},r.default.createElement(t.Text,{style:[i.socialIcon,{color:o}]},a)),i=t.StyleSheet.create({fullScreen:{flex:1},overlay:{...t.StyleSheet.absoluteFillObject},centeredModalContainer:{width:"90%",maxWidth:400,alignSelf:"center",marginTop:fe*.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 R=W(require("react")),h=require("react-native"),oe=({onPress:o,options:e})=>{let a=e?.modal?.theme?.primaryColor||"#2563eb",s=e?.trigger?.position||"bottom-right",f=(e?.trigger?.displayMode||"floating")==="edge",k=s.includes("right"),d=s.includes("top"),p=(0,R.useRef)(new h.Animated.Value(-1)).current;(0,R.useEffect)(()=>{let z=()=>{p.setValue(-1),h.Animated.timing(p,{toValue:2,duration:3e3,easing:h.Easing.linear,useNativeDriver:!0}).start(()=>{setTimeout(z,1e3)})};z()},[]);let m=p.interpolate({inputRange:[-1,2],outputRange:f?[-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}};f||(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 T=()=>R.default.createElement(h.View,{style:y.iconContainer},R.default.createElement(h.View,{style:y.bowContainer},R.default.createElement(h.View,{style:[y.bowLoop,y.bowLeft]}),R.default.createElement(h.View,{style:[y.bowLoop,y.bowRight]})),R.default.createElement(h.View,{style:y.giftLid}),R.default.createElement(h.View,{style:y.giftBody},R.default.createElement(h.View,{style:y.ribbonVertical})));return R.default.createElement(h.TouchableOpacity,{style:[f?y.edgeButton:y.floatingButton,{backgroundColor:a},g[s],f&&(k?y.edgeRight:y.edgeLeft)],onPress:o,activeOpacity:.9},R.default.createElement(h.View,{style:y.content},T()),R.default.createElement(h.Animated.View,{style:[y.shimmer,{transform:[{translateX:m},{skewX:"-15deg"}]}]}))},y=h.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 x=W(require("react")),w=require("react-native"),{width:Pe}=w.Dimensions.get("window"),he=({visible:o,options:e,onClose:a})=>{let s=(0,x.useRef)(new w.Animated.Value(0)).current,[l,f]=(0,x.useState)(o),k=e.position.includes("bottom")?"bottom":"top",d=e.position.includes("left")?"left":e.position.includes("right")?"right":"center";if((0,x.useEffect)(()=>{o?(f(!0),w.Animated.spring(s,{toValue:1,useNativeDriver:!0,tension:50,friction:8}).start()):w.Animated.timing(s,{toValue:0,duration:250,useNativeDriver:!0}).start(()=>{f(!1)})},[o]),!l)return null;let p=s.interpolate({inputRange:[0,1],outputRange:[k==="top"?-100:100,0]}),m=s.interpolate({inputRange:[0,1],outputRange:[0,1]}),g={position:"absolute",[k]:w.Platform.OS==="ios"?60:40,zIndex:9999};return d==="center"?(g.left=20,g.right=20,g.alignItems="center"):g[d]=20,x.default.createElement(w.Animated.View,{style:[g,{transform:[{translateY:p}],opacity:m}]},x.default.createElement(w.View,{style:[X.banner,{backgroundColor:e.themeColor||"#2563eb"}]},x.default.createElement(w.Text,{style:X.icon},"\u{1F381}"),x.default.createElement(w.Text,{style:X.text},e.text),x.default.createElement(w.TouchableOpacity,{onPress:a,style:X.closeBtn},x.default.createElement(w.Text,{style:X.closeIcon},"\u2715"))))},X=w.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:Pe-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,n.createContext)(void 0),be=({children:o,userId:e,...a})=>{let[s,l]=(0,n.useState)(!1),[f,k]=(0,n.useState)(!1),[d,p]=(0,n.useState)(null),m=(0,n.useRef)(new Z(a)),g=(0,n.useRef)(!1),T=(0,n.useRef)(null),[z,B]=(0,n.useState)(!1),[M,ie]=(0,n.useState)(),[ne,ge]=(0,n.useState)(!1),[v,E]=(0,n.useState)(),[Y,j]=(0,n.useState)(!1),[$,ae]=(0,n.useState)(),J=(0,n.useCallback)(()=>{let{width:u,height:c}=C.Dimensions.get("window"),b=Intl.DateTimeFormat().resolvedOptions().locale,S=C.PixelRatio.get(),P,F;if(C.Platform.OS==="android"){let ce=C.Platform.constants;P=ce.Model,F=ce.Brand||ce.Manufacturer}return{os:C.Platform.OS,platform:C.Platform.OS,osVersion:String(C.Platform.Version),screenWidth:u,screenHeight:c,timezoneOffsetInMinutes:String(new Date().getTimezoneOffset()),locale:b,language:b,deviceModel:P,deviceBrand:F,pixelRatio:S}},[]),V=(0,n.useCallback)(async(u,c)=>{let b=await m.current.trackReferral(u,c);return await D.setTrackedReferral(b.referralTrackingId),b},[]),Q=(0,n.useCallback)(async u=>{try{let c=u.match(/[?&]referralCode=([^&]+)/);c&&(console.log("GrowthRail: Tracking referral from deep link",c[1]),await V(c[1]))}catch(c){console.warn("GrowthRail: Error handling deep link",c)}},[V]),U=(0,n.useCallback)(async()=>{try{let u=J(),{referralTrackingId:c}=await m.current.checkDeferredDeepLink(u);c&&(console.log("GrowthRail: Found deferred referral via fingerprinting",c),await D.setTrackedReferral(c))}catch(u){console.warn("GrowthRail: Fingerprint check failed",u)}},[J]),se=(0,n.useCallback)(()=>new Promise(u=>{we.default.getInstallReferrerInfo(async(c,b)=>{if(!b&&c&&c.installReferrer)try{let P=decodeURIComponent(c.installReferrer).match(/[?&]referralCode=([^&]+)/);if(P){let{referralTrackingId:F}=await V(P[1]);await D.setTrackedReferral(F),console.log("GrowthRail: Tracked referral via Install Referrer")}}catch(S){console.warn("GrowthRail: Failed to process install referrer",S)}else await U();u()})}),[V,U]),L=(0,n.useCallback)(async u=>{if(d?.id===u&&f)return d;let c=(async()=>{try{let b=await m.current.initAppUser(u),S={...b,id:u};return p(S),k(!0),b.referrerExperience?.trigger?.show&&ge(!0),S}catch(b){throw T.current=null,b}})();return T.current=c,c},[d,f]),A=(0,n.useCallback)(async u=>{let c=d;!c&&T.current&&(c=await T.current);let b=c?.id||e;if(!b)throw new Error("GrowthRail: User must be initialized before tracking a reward event.");let S=await D.getTrackedReferral();if(!S){console.warn("GrowthRail: No referral tracking ID found. Reward event not attributed.");return}return m.current.trackRewardEvent(b,S,u)},[d,e]),le=(0,n.useCallback)(async()=>await D.getTrackedReferral(),[]),G=(0,n.useCallback)(async()=>{if(d)return d.referralLink;if(T.current)return(await T.current).referralLink},[d]);(0,n.useEffect)(()=>{if(g.current)return;g.current=!0,(async()=>{let c=await C.Linking.getInitialURL();c&&await Q(c);let b=C.Linking.addEventListener("url",({url:P})=>Q(P));await D.isFirstLaunch()&&(C.Platform.OS==="android"?await se():await U()),e&&await L(e);try{let P=await m.current.getNewUserExperience(),F=await D.getTrackedReferral();P.banner?.show&&F&&(ae(P.banner),j(!0))}catch{}return l(!0),()=>b.remove()})()},[]),(0,n.useEffect)(()=>{s&&e&&d?.id!==e&&L(e)},[e,s]);let O={isInitialized:s,isUserReady:f,currentUser:d,referralCode:d?.referralCode,referralLink:d?.referralLink,showDashboard:u=>{ie(u),B(!0)},hideDashboard:()=>B(!1),initUser:L,trackReward:A,getReferralTrackingId:le,getReferralLink:G};if(!s)return null;let I=d?.referrerExperience,H={...I?.modal,...M,position:I?.trigger?.position||M?.position||"bottom-right",theme:{...I?.modal?.theme||{},...M?.theme||{}}},Re={...I,...v,trigger:{...I?.trigger||{},...v?.trigger||{}}};return n.default.createElement(me.Provider,{value:O},o,n.default.createElement(te,{visible:z,options:H,onClose:()=>B(!1)}),ne&&n.default.createElement(oe,{options:Re,onPress:()=>O.showDashboard()}),Y&&n.default.createElement(he,{visible:Y,options:$,onClose:()=>j(!1)}))},re=()=>{let o=(0,n.useContext)(me);if(!o)throw new Error("useGrowthRail must be used within a GrowthRailProvider");return o};var N=require("react");var ye=()=>{let[o,e]=(0,N.useState)(!1),[a,s]=(0,N.useState)(null),l=re(),f=(0,N.useCallback)(async d=>{e(!0),s(null);try{return await l.initUser(d)}catch(p){let m=p instanceof Error?p:new Error(String(p));throw s(m),m}finally{e(!1)}},[l]),k=(0,N.useCallback)(async d=>{e(!0),s(null);try{await l.trackReward(d)}catch(p){let m=p instanceof Error?p:new Error(String(p));throw s(m),m}finally{e(!1)}},[l]);return{initAppUser:f,trackRewardEvent:k,showReferralDashboard:l.showDashboard,hideReferralDashboard:l.hideDashboard,getReferralTrackingId:l.getReferralTrackingId,getReferralLink:l.getReferralLink,isLoading:o,isInitialized:l.isInitialized,isUserReady:l.isUserReady,error:a}};0&&(module.exports={GrowthRailProvider,ReferralDashboard,TriggerButton,useGrowthRail});
|
|
1
|
+
"use strict";var Ce=Object.create;var _=Object.defineProperty;var ke=Object.getOwnPropertyDescriptor;var Te=Object.getOwnPropertyNames;var xe=Object.getPrototypeOf,ve=Object.prototype.hasOwnProperty;var Le=(o,e,a)=>e in o?_(o,e,{enumerable:!0,configurable:!0,writable:!0,value:a}):o[e]=a;var Ie=(o,e)=>{for(var a in e)_(o,a,{get:e[a],enumerable:!0})},ue=(o,e,a,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let l of Te(e))!ve.call(o,l)&&l!==a&&_(o,l,{get:()=>e[l],enumerable:!(s=ke(e,l))||s.enumerable});return o};var W=(o,e,a)=>(a=o!=null?Ce(xe(o)):{},ue(e||!o||!o.__esModule?_(a,"default",{value:o,enumerable:!0}):a,o)),Se=o=>ue(_({},"__esModule",{value:!0}),o);var ce=(o,e,a)=>Le(o,typeof e!="symbol"?e+"":e,a);var Be={};Ie(Be,{GrowthRailProvider:()=>be,ReferralDashboard:()=>te,TriggerButton:()=>oe,useGrowthRail:()=>ye});module.exports=Se(Be);var n=W(require("react")),C=require("react-native"),we=W(require("react-native-play-install-referrer"));var Z=class{constructor(e){ce(this,"baseUrl");ce(this,"projectSecretKey");let a=typeof process<"u"&&process.env?.ENV_BASE_URL;this.baseUrl=a||"https://api.growthrail.dev",this.projectSecretKey=e.projectSecretKey}async request(e,a,s){let l={"Content-Type":"application/json","X-GrowthRail-ProjectSecret":this.projectSecretKey,Origin:this.baseUrl};try{let f=await fetch(`${this.baseUrl}${e}`,{method:a,headers:l,body:s?JSON.stringify(s):void 0});if(!f.ok){let k="";try{k=await f.text()}catch{}throw new Error(`GrowthRail API Error ${f.status} (${this.baseUrl}${e}): ${f.statusText} - ${k}`)}return f.json()}catch(f){throw console.error("GrowthRail SDK Error:",f),f}}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,a){return this.request("/api/v1/sdk/track-referral","POST",{referralCode:e,rewardEventName:a})}async trackRewardEvent(e,a,s){return this.request("/api/v1/sdk/track-reward-event","POST",{refereeId:e,referralTrackingId:a,eventName:s})}async checkDeferredDeepLink(e){return this.request("/api/v1/sdk/match-link","POST",{fingerprint:e})}};var K=W(require("@react-native-async-storage/async-storage")),ee={TRACKED_REFERRAL:"growth-rail-tracked-referral",IS_FIRST_LAUNCH:"growth-rail-is-first-launch"},E=class{static async setTrackedReferral(e){await K.default.setItem(ee.TRACKED_REFERRAL,e)}static async getTrackedReferral(){return await K.default.getItem(ee.TRACKED_REFERRAL)}static async isFirstLaunch(){return await K.default.getItem(ee.IS_FIRST_LAUNCH)===null?(await K.default.setItem(ee.IS_FIRST_LAUNCH,"false"),!0):!1}};var r=W(require("react")),t=require("react-native");var{width:pe,height:de}=t.Dimensions.get("window"),te=({visible:o,options:e,onClose:a})=>{let s=re(),[l,f]=(0,r.useState)(null),[k,d]=(0,r.useState)(!1),[p,m]=(0,r.useState)(!1),g=(0,r.useRef)(new t.Animated.Value(0)).current,T=(0,r.useRef)(new t.Animated.Value(0)).current,z=e?.title||"Invite Friends & Earn",B=e?.theme?.primaryColor||"#2563eb",M=e?.theme?.backgroundColor||"#ffffff",ie=e?.theme?.tintColor||"#000000",ne=e?.theme?.tintAlpha??.5,v=(e?.componentType||"modal")==="drawer",U=e?.position||"bottom-right",Y="#111827",j="#6b7280";(0,r.useEffect)(()=>{o?(l||ae(),t.Animated.parallel([t.Animated.timing(T,{toValue:1,duration:300,useNativeDriver:!0}),t.Animated.spring(g,{toValue:1,useNativeDriver:!0,tension:50,friction:8})]).start()):(g.setValue(0),T.setValue(0))},[o]);let $=()=>{t.Animated.parallel([t.Animated.timing(T,{toValue:0,duration:250,useNativeDriver:!0}),t.Animated.timing(g,{toValue:0,duration:250,useNativeDriver:!0})]).start(()=>{a()})},ae=async()=>{d(!0);try{if(s.isUserReady){let G=await s.getReferralLink();f(G||null)}}catch(G){console.error("GrowthRail: Failed to load referral link",G)}finally{d(!1)}},J=()=>{l&&(t.Clipboard.setString(l),m(!0),setTimeout(()=>m(!1),2e3))},V=G=>{if(!l)return;let D="",I=encodeURIComponent(l),H=encodeURIComponent("Check this out!");switch(G){case"twitter":D=`https://twitter.com/intent/tweet?url=${I}&text=${H}`;break;case"facebook":D=`https://www.facebook.com/sharer/sharer.php?u=${I}`;break;case"linkedin":D=`https://www.linkedin.com/sharing/share-offsite/?url=${I}`;break;case"whatsapp":D=`whatsapp://send?text=${H}%20${I}`;break;case"email":D=`mailto:?subject=Check this out&body=${H}%20${I}`;break}D&&t.Linking.openURL(D).catch(()=>{})},Q=()=>ie||"#000000",O=[];v?U.includes("right")?O=[{translateX:g.interpolate({inputRange:[0,1],outputRange:[pe,0]})}]:U.includes("left")?O=[{translateX:g.interpolate({inputRange:[0,1],outputRange:[-pe,0]})}]:O=[{translateY:g.interpolate({inputRange:[0,1],outputRange:[de,0]})}]:O=[{scale:g.interpolate({inputRange:[0,1],outputRange:[.9,1]})},{translateY:g.interpolate({inputRange:[0,1],outputRange:[20,0]})}];let ge=U.includes("top"),L=U.includes("right"),A=U.includes("left"),se=v?{position:"absolute",...ge?{top:100}:{bottom:100},...L?{right:0}:A?{left:0}:{left:0,right:0},width:L||A?"85%":"100%",maxHeight:L||A?de-200:"80%"}:{};return r.default.createElement(t.Modal,{visible:o,transparent:!0,animationType:"none",onRequestClose:$},r.default.createElement(t.View,{style:i.fullScreen},r.default.createElement(t.Animated.View,{style:[i.overlay,{backgroundColor:Q(),opacity:T.interpolate({inputRange:[0,1],outputRange:[0,ne]})}]},r.default.createElement(t.TouchableOpacity,{style:i.fullScreen,activeOpacity:1,onPress:$})),r.default.createElement(t.Animated.View,{style:[v?se:i.centeredModalContainer,{backgroundColor:M,transform:O},v&&L&&{borderTopLeftRadius:24,borderBottomLeftRadius:24},v&&A&&{borderTopRightRadius:24,borderBottomRightRadius:24},v&&!L&&!A&&U.includes("bottom")&&{borderTopLeftRadius:24,borderTopRightRadius:24},v&&!L&&!A&&U.includes("top")&&{borderBottomLeftRadius:24,borderBottomRightRadius:24},!v&&{borderRadius:24,opacity:g}]},r.default.createElement(t.View,{style:i.contentWrapper},v&&!L&&!A&&U.includes("bottom")&&r.default.createElement(t.View,{style:i.drawerHandle}),r.default.createElement(t.TouchableOpacity,{style:i.closeBtn,onPress:$},r.default.createElement(t.Text,{style:i.closeIcon},"\u2715")),r.default.createElement(t.ScrollView,{contentContainerStyle:i.scrollContent,showsVerticalScrollIndicator:!1},r.default.createElement(t.View,{style:i.header},r.default.createElement(t.View,{style:i.iconLgContainer},r.default.createElement(t.View,{style:i.bowContainerLg},r.default.createElement(t.View,{style:[i.bowLoopLg,i.bowLeftLg,{borderColor:B}]}),r.default.createElement(t.View,{style:[i.bowLoopLg,i.bowRightLg,{borderColor:B}]})),r.default.createElement(t.View,{style:[i.giftLidLg,{backgroundColor:B}]}),r.default.createElement(t.View,{style:[i.giftBodyLg,{borderColor:B}]},r.default.createElement(t.View,{style:[i.ribbonVerticalLg,{backgroundColor:"#fff",opacity:.3}]}))),r.default.createElement(t.Text,{style:[i.title,{color:Y}]},z),r.default.createElement(t.Text,{style:[i.subtitle,{color:j}]},e?.description||"Share your unique link and earn rewards for every friend who signs up.")),s.isUserReady?k?r.default.createElement(t.ActivityIndicator,{size:"large",color:B,style:i.loader}):r.default.createElement(t.View,{style:i.mainContent},r.default.createElement(t.Text,{style:i.label},"YOUR UNIQUE LINK"),r.default.createElement(t.View,{style:i.inputGroup},r.default.createElement(t.Text,{numberOfLines:1,style:i.input},l||"Initializing..."),r.default.createElement(t.TouchableOpacity,{style:[i.copyBtn,{backgroundColor:p?"#10b981":B}],onPress:J},r.default.createElement(t.Text,{style:i.copyBtnText},p?"Copied!":"Copy"))),r.default.createElement(t.View,{style:i.shareLabelContainer},r.default.createElement(t.View,{style:i.divider}),r.default.createElement(t.Text,{style:i.shareLabel},"Share via"),r.default.createElement(t.View,{style:i.divider})),r.default.createElement(t.View,{style:i.socialContainer},r.default.createElement(q,{platform:"twitter",color:"#000000",onPress:()=>V("twitter"),icon:"\u{1D54F}"}),r.default.createElement(q,{platform:"facebook",color:"#1877F2",onPress:()=>V("facebook"),icon:"f"}),r.default.createElement(q,{platform:"linkedin",color:"#0A66C2",onPress:()=>V("linkedin"),icon:"in"}),r.default.createElement(q,{platform:"whatsapp",color:"#25D366",onPress:()=>V("whatsapp"),icon:"W"}),r.default.createElement(q,{platform:"email",color:"#888888",onPress:()=>V("email"),icon:"\u2709"}))):r.default.createElement(t.View,{style:i.loadingBox},r.default.createElement(t.Text,{style:{color:j,textAlign:"center"}},"Please log in to view your referral dashboard.")),r.default.createElement(t.View,{style:i.footer},r.default.createElement(t.Text,{style:i.poweredBy},"Powered by ",r.default.createElement(t.Text,{style:i.brand,onPress:()=>t.Linking.openURL("https://growthrail.com")},"Growth Rail"))))))))},q=({color:o,onPress:e,icon:a})=>r.default.createElement(t.TouchableOpacity,{style:[i.socialBtn,{borderColor:"#e5e7eb"}],onPress:e},r.default.createElement(t.Text,{style:[i.socialIcon,{color:o}]},a)),i=t.StyleSheet.create({fullScreen:{flex:1},overlay:{...t.StyleSheet.absoluteFillObject},centeredModalContainer:{width:"90%",maxWidth:400,alignSelf:"center",marginTop:de*.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 R=W(require("react")),h=require("react-native"),oe=({onPress:o,options:e})=>{let a=e?.modal?.theme?.primaryColor||"#2563eb",s=e?.trigger?.position||"bottom-right",f=(e?.trigger?.displayMode||"floating")==="edge",k=s.includes("right"),d=s.includes("top"),p=(0,R.useRef)(new h.Animated.Value(-1)).current;(0,R.useEffect)(()=>{let z=()=>{p.setValue(-1),h.Animated.timing(p,{toValue:2,duration:3e3,easing:h.Easing.linear,useNativeDriver:!0}).start(()=>{setTimeout(z,1e3)})};z()},[]);let m=p.interpolate({inputRange:[-1,2],outputRange:f?[-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}};f||(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 T=()=>R.default.createElement(h.View,{style:y.iconContainer},R.default.createElement(h.View,{style:y.bowContainer},R.default.createElement(h.View,{style:[y.bowLoop,y.bowLeft]}),R.default.createElement(h.View,{style:[y.bowLoop,y.bowRight]})),R.default.createElement(h.View,{style:y.giftLid}),R.default.createElement(h.View,{style:y.giftBody},R.default.createElement(h.View,{style:y.ribbonVertical})));return R.default.createElement(h.TouchableOpacity,{style:[f?y.edgeButton:y.floatingButton,{backgroundColor:a},g[s],f&&(k?y.edgeRight:y.edgeLeft)],onPress:o,activeOpacity:.9},R.default.createElement(h.View,{style:y.content},T()),R.default.createElement(h.Animated.View,{style:[y.shimmer,{transform:[{translateX:m},{skewX:"-15deg"}]}]}))},y=h.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 x=W(require("react")),w=require("react-native"),{width:Pe}=w.Dimensions.get("window"),he=({visible:o,options:e,onClose:a})=>{let s=(0,x.useRef)(new w.Animated.Value(0)).current,[l,f]=(0,x.useState)(o),k=e.position.includes("bottom")?"bottom":"top",d=e.position.includes("left")?"left":e.position.includes("right")?"right":"center";if((0,x.useEffect)(()=>{o?(f(!0),w.Animated.spring(s,{toValue:1,useNativeDriver:!0,tension:50,friction:8}).start()):w.Animated.timing(s,{toValue:0,duration:250,useNativeDriver:!0}).start(()=>{f(!1)})},[o]),!l)return null;let p=s.interpolate({inputRange:[0,1],outputRange:[k==="top"?-100:100,0]}),m=s.interpolate({inputRange:[0,1],outputRange:[0,1]}),g={position:"absolute",[k]:w.Platform.OS==="ios"?60:40,zIndex:9999};return d==="center"?(g.left=20,g.right=20,g.alignItems="center"):g[d]=20,x.default.createElement(w.Animated.View,{style:[g,{transform:[{translateY:p}],opacity:m}]},x.default.createElement(w.View,{style:[X.banner,{backgroundColor:e.themeColor||"#2563eb"}]},x.default.createElement(w.Text,{style:X.icon},"\u{1F381}"),x.default.createElement(w.Text,{style:X.text},e.text),x.default.createElement(w.TouchableOpacity,{onPress:a,style:X.closeBtn},x.default.createElement(w.Text,{style:X.closeIcon},"\u2715"))))},X=w.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:Pe-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,n.createContext)(void 0),be=({children:o,userId:e,...a})=>{let[s,l]=(0,n.useState)(!1),[f,k]=(0,n.useState)(!1),[d,p]=(0,n.useState)(null),m=(0,n.useRef)(new Z(a)),g=(0,n.useRef)(!1),T=(0,n.useRef)(null),[z,B]=(0,n.useState)(!1),[M,ie]=(0,n.useState)(),[ne,fe]=(0,n.useState)(!1),[v,U]=(0,n.useState)(),[Y,j]=(0,n.useState)(!1),[$,ae]=(0,n.useState)(),J=(0,n.useCallback)(()=>{let{width:u,height:c}=C.Dimensions.get("window"),b=Intl.DateTimeFormat().resolvedOptions().locale,S=C.PixelRatio.get(),P,F;if(C.Platform.OS==="android"){let le=C.Platform.constants;P=le.Model,F=le.Brand||le.Manufacturer}return{os:C.Platform.OS,platform:C.Platform.OS,osVersion:String(C.Platform.Version),screenWidth:u,screenHeight:c,timezoneOffsetInMinutes:String(new Date().getTimezoneOffset()),locale:b,language:b,deviceModel:P,deviceBrand:F,pixelRatio:S}},[]),V=(0,n.useCallback)(async(u,c)=>{let b=await m.current.trackReferral(u,c);return await E.setTrackedReferral(b.referralTrackingId),b},[]),Q=(0,n.useCallback)(async u=>{try{let c=u.match(/[?&]referralCode=([^&]+)/);c&&(console.log("GrowthRail: Tracking referral from deep link",c[1]),await V(c[1]))}catch(c){console.warn("GrowthRail: Error handling deep link",c)}},[V]),O=(0,n.useCallback)(async()=>{try{let u=J(),{referralTrackingId:c}=await m.current.checkDeferredDeepLink(u);c&&(console.log("GrowthRail: Found deferred referral via fingerprinting",c),await E.setTrackedReferral(c))}catch(u){console.warn("GrowthRail: Fingerprint check failed",u)}},[J]),ge=(0,n.useCallback)(()=>new Promise(u=>{we.default.getInstallReferrerInfo(async(c,b)=>{if(!b&&c&&c.installReferrer)try{let P=decodeURIComponent(c.installReferrer).match(/[?&]referralCode=([^&]+)/);if(P){let{referralTrackingId:F}=await V(P[1]);await E.setTrackedReferral(F),console.log("GrowthRail: Tracked referral via Install Referrer")}}catch(S){console.warn("GrowthRail: Failed to process install referrer",S)}else await O();u()})}),[V,O]),L=(0,n.useCallback)(async u=>{if(d?.id===u&&f)return d;let c=(async()=>{try{let b=await m.current.initAppUser(u),S={...b,id:u};return p(S),k(!0),b.referrerExperience?.trigger?.show&&fe(!0),S}catch(b){throw T.current=null,b}})();return T.current=c,c},[d,f]),A=(0,n.useCallback)(async u=>{let c=d;!c&&T.current&&(c=await T.current);let b=c?.id||e;if(!b)throw new Error("GrowthRail: User must be initialized before tracking a reward event.");let S=await E.getTrackedReferral();if(!S){console.warn("GrowthRail: No referral tracking ID found. Reward event not attributed.");return}return m.current.trackRewardEvent(b,S,u)},[d,e]),se=(0,n.useCallback)(async()=>await E.getTrackedReferral(),[]),G=(0,n.useCallback)(async()=>{if(d)return d.referralLink;if(T.current)return(await T.current).referralLink},[d]);(0,n.useEffect)(()=>{if(g.current)return;g.current=!0,(async()=>{let c=await C.Linking.getInitialURL();c&&await Q(c);let b=C.Linking.addEventListener("url",({url:P})=>Q(P));await E.isFirstLaunch()&&(C.Platform.OS==="android"?await O():await O()),e&&await L(e);try{let P=await m.current.getNewUserExperience(),F=await E.getTrackedReferral();P.banner?.show&&F&&(ae(P.banner),j(!0))}catch{}return l(!0),()=>b.remove()})()},[]),(0,n.useEffect)(()=>{s&&e&&d?.id!==e&&L(e)},[e,s]);let D={isInitialized:s,isUserReady:f,currentUser:d,referralCode:d?.referralCode,referralLink:d?.referralLink,showDashboard:u=>{ie(u),B(!0)},hideDashboard:()=>B(!1),initUser:L,trackReward:A,getReferralTrackingId:se,getReferralLink:G};if(!s)return null;let I=d?.referrerExperience,H={...I?.modal,...M,position:I?.trigger?.position||M?.position||"bottom-right",theme:{...I?.modal?.theme||{},...M?.theme||{}}},Re={...I,...v,trigger:{...I?.trigger||{},...v?.trigger||{}}};return n.default.createElement(me.Provider,{value:D},o,n.default.createElement(te,{visible:z,options:H,onClose:()=>B(!1)}),ne&&n.default.createElement(oe,{options:Re,onPress:()=>D.showDashboard()}),Y&&n.default.createElement(he,{visible:Y,options:$,onClose:()=>j(!1)}))},re=()=>{let o=(0,n.useContext)(me);if(!o)throw new Error("useGrowthRail must be used within a GrowthRailProvider");return o};var N=require("react");var ye=()=>{let[o,e]=(0,N.useState)(!1),[a,s]=(0,N.useState)(null),l=re(),f=(0,N.useCallback)(async d=>{e(!0),s(null);try{return await l.initUser(d)}catch(p){let m=p instanceof Error?p:new Error(String(p));throw s(m),m}finally{e(!1)}},[l]),k=(0,N.useCallback)(async d=>{e(!0),s(null);try{await l.trackReward(d)}catch(p){let m=p instanceof Error?p:new Error(String(p));throw s(m),m}finally{e(!1)}},[l]);return{initAppUser:f,trackRewardEvent:k,showReferralDashboard:l.showDashboard,hideReferralDashboard:l.hideDashboard,getReferralTrackingId:l.getReferralTrackingId,getReferralLink:l.getReferralLink,isLoading:o,isInitialized:l.isInitialized,isUserReady:l.isUserReady,error:a}};0&&(module.exports={GrowthRailProvider,ReferralDashboard,TriggerButton,useGrowthRail});
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var Ve=Object.defineProperty;var Oe=(n,e,s)=>e in n?Ve(n,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):n[e]=s;var de=(n,e,s)=>Oe(n,typeof e!="symbol"?e+"":e,s);import oe,{createContext as Ze,useContext as et,useEffect as ve,useState as E,useRef as me,useCallback as U}from"react";import{Linking as Le,Platform as N,Dimensions as tt,PixelRatio as rt}from"react-native";import ot from"react-native-play-install-referrer";var J=class{constructor(e){de(this,"baseUrl");de(this,"projectSecretKey");let s=typeof process<"u"&&process.env?.ENV_BASE_URL;this.baseUrl=s||"https://api.growthrail.dev",this.projectSecretKey=e.projectSecretKey}async request(e,s,o){let l={"Content-Type":"application/json","X-GrowthRail-ProjectSecret":this.projectSecretKey,Origin:this.baseUrl};try{let c=await fetch(`${this.baseUrl}${e}`,{method:s,headers:l,body:o?JSON.stringify(o):void 0});if(!c.ok){let m="";try{m=await c.text()}catch{}throw new Error(`GrowthRail API Error ${c.status} (${this.baseUrl}${e}): ${c.statusText} - ${m}`)}return c.json()}catch(c){throw console.error("GrowthRail SDK Error:",c),c}}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,s){return this.request("/api/v1/sdk/track-referral","POST",{referralCode:e,rewardEventName:s})}async trackRewardEvent(e,s,o){return this.request("/api/v1/sdk/track-reward-event","POST",{refereeId:e,referralTrackingId:s,eventName:o})}async checkDeferredDeepLink(e){return this.request("/api/v1/sdk/match-link","POST",{fingerprint:e})}};import Q from"@react-native-async-storage/async-storage";var Z={TRACKED_REFERRAL:"growth-rail-tracked-referral",IS_FIRST_LAUNCH:"growth-rail-is-first-launch"},S=class{static async setTrackedReferral(e){await Q.setItem(Z.TRACKED_REFERRAL,e)}static async getTrackedReferral(){return await Q.getItem(Z.TRACKED_REFERRAL)}static async isFirstLaunch(){return await Q.getItem(Z.IS_FIRST_LAUNCH)===null?(await Q.setItem(Z.IS_FIRST_LAUNCH,"false"),!0):!1}};import t,{useEffect as De,useState as fe,useRef as ye}from"react";import{Modal as Ee,View as u,Text as x,StyleSheet as Re,TouchableOpacity as ee,Clipboard as Ue,ActivityIndicator as Ae,Linking as Ce,ScrollView as Ge,Platform as ke,Animated as P,Dimensions as ze}from"react-native";var{width:Te,height:ge}=ze.get("window"),ue=({visible:n,options:e,onClose:s})=>{let o=te(),[l,c]=fe(null),[m,a]=fe(!1),[g,p]=fe(!1),d=ye(new P.Value(0)).current,b=ye(new P.Value(0)).current,z=e?.title||"Invite Friends & Earn",v=e?.theme?.primaryColor||"#2563eb",M=e?.theme?.backgroundColor||"#ffffff",ie=e?.theme?.tintColor||"#000000",ne=e?.theme?.tintAlpha??.5,y=(e?.componentType||"modal")==="drawer",V=e?.position||"bottom-right",q="#111827",j="#6b7280";De(()=>{n?(l||ae(),P.parallel([P.timing(b,{toValue:1,duration:300,useNativeDriver:!0}),P.spring(d,{toValue:1,useNativeDriver:!0,tension:50,friction:8})]).start()):(d.setValue(0),b.setValue(0))},[n]);let $=()=>{P.parallel([P.timing(b,{toValue:0,duration:250,useNativeDriver:!0}),P.timing(d,{toValue:0,duration:250,useNativeDriver:!0})]).start(()=>{s()})},ae=async()=>{a(!0);try{if(o.isUserReady){let G=await o.getReferralLink();c(G||null)}}catch(G){console.error("GrowthRail: Failed to load referral link",G)}finally{a(!1)}},X=()=>{l&&(Ue.setString(l),p(!0),setTimeout(()=>p(!1),2e3))},L=G=>{if(!l)return;let I="",C=encodeURIComponent(l),H=encodeURIComponent("Check this out!");switch(G){case"twitter":I=`https://twitter.com/intent/tweet?url=${C}&text=${H}`;break;case"facebook":I=`https://www.facebook.com/sharer/sharer.php?u=${C}`;break;case"linkedin":I=`https://www.linkedin.com/sharing/share-offsite/?url=${C}`;break;case"whatsapp":I=`whatsapp://send?text=${H}%20${C}`;break;case"email":I=`mailto:?subject=Check this out&body=${H}%20${C}`;break}I&&Ce.openURL(I).catch(()=>{})},Y=()=>ie||"#000000",O=[];y?V.includes("right")?O=[{translateX:d.interpolate({inputRange:[0,1],outputRange:[Te,0]})}]:V.includes("left")?O=[{translateX:d.interpolate({inputRange:[0,1],outputRange:[-Te,0]})}]:O=[{translateY:d.interpolate({inputRange:[0,1],outputRange:[ge,0]})}]:O=[{scale:d.interpolate({inputRange:[0,1],outputRange:[.9,1]})},{translateY:d.interpolate({inputRange:[0,1],outputRange:[20,0]})}];let se=V.includes("top"),R=V.includes("right"),D=V.includes("left"),le=y?{position:"absolute",...se?{top:100}:{bottom:100},...R?{right:0}:D?{left:0}:{left:0,right:0},width:R||D?"85%":"100%",maxHeight:R||D?ge-200:"80%"}:{};return t.createElement(Ee,{visible:n,transparent:!0,animationType:"none",onRequestClose:$},t.createElement(u,{style:r.fullScreen},t.createElement(P.View,{style:[r.overlay,{backgroundColor:Y(),opacity:b.interpolate({inputRange:[0,1],outputRange:[0,ne]})}]},t.createElement(ee,{style:r.fullScreen,activeOpacity:1,onPress:$})),t.createElement(P.View,{style:[y?le:r.centeredModalContainer,{backgroundColor:M,transform:O},y&&R&&{borderTopLeftRadius:24,borderBottomLeftRadius:24},y&&D&&{borderTopRightRadius:24,borderBottomRightRadius:24},y&&!R&&!D&&V.includes("bottom")&&{borderTopLeftRadius:24,borderTopRightRadius:24},y&&!R&&!D&&V.includes("top")&&{borderBottomLeftRadius:24,borderBottomRightRadius:24},!y&&{borderRadius:24,opacity:d}]},t.createElement(u,{style:r.contentWrapper},y&&!R&&!D&&V.includes("bottom")&&t.createElement(u,{style:r.drawerHandle}),t.createElement(ee,{style:r.closeBtn,onPress:$},t.createElement(x,{style:r.closeIcon},"\u2715")),t.createElement(Ge,{contentContainerStyle:r.scrollContent,showsVerticalScrollIndicator:!1},t.createElement(u,{style:r.header},t.createElement(u,{style:r.iconLgContainer},t.createElement(u,{style:r.bowContainerLg},t.createElement(u,{style:[r.bowLoopLg,r.bowLeftLg,{borderColor:v}]}),t.createElement(u,{style:[r.bowLoopLg,r.bowRightLg,{borderColor:v}]})),t.createElement(u,{style:[r.giftLidLg,{backgroundColor:v}]}),t.createElement(u,{style:[r.giftBodyLg,{borderColor:v}]},t.createElement(u,{style:[r.ribbonVerticalLg,{backgroundColor:"#fff",opacity:.3}]}))),t.createElement(x,{style:[r.title,{color:q}]},z),t.createElement(x,{style:[r.subtitle,{color:j}]},e?.description||"Share your unique link and earn rewards for every friend who signs up.")),o.isUserReady?m?t.createElement(Ae,{size:"large",color:v,style:r.loader}):t.createElement(u,{style:r.mainContent},t.createElement(x,{style:r.label},"YOUR UNIQUE LINK"),t.createElement(u,{style:r.inputGroup},t.createElement(x,{numberOfLines:1,style:r.input},l||"Initializing..."),t.createElement(ee,{style:[r.copyBtn,{backgroundColor:g?"#10b981":v}],onPress:X},t.createElement(x,{style:r.copyBtnText},g?"Copied!":"Copy"))),t.createElement(u,{style:r.shareLabelContainer},t.createElement(u,{style:r.divider}),t.createElement(x,{style:r.shareLabel},"Share via"),t.createElement(u,{style:r.divider})),t.createElement(u,{style:r.socialContainer},t.createElement(_,{platform:"twitter",color:"#000000",onPress:()=>L("twitter"),icon:"\u{1D54F}"}),t.createElement(_,{platform:"facebook",color:"#1877F2",onPress:()=>L("facebook"),icon:"f"}),t.createElement(_,{platform:"linkedin",color:"#0A66C2",onPress:()=>L("linkedin"),icon:"in"}),t.createElement(_,{platform:"whatsapp",color:"#25D366",onPress:()=>L("whatsapp"),icon:"W"}),t.createElement(_,{platform:"email",color:"#888888",onPress:()=>L("email"),icon:"\u2709"}))):t.createElement(u,{style:r.loadingBox},t.createElement(x,{style:{color:j,textAlign:"center"}},"Please log in to view your referral dashboard.")),t.createElement(u,{style:r.footer},t.createElement(x,{style:r.poweredBy},"Powered by ",t.createElement(x,{style:r.brand,onPress:()=>Ce.openURL("https://growthrail.com")},"Growth Rail"))))))))},_=({color:n,onPress:e,icon:s})=>t.createElement(ee,{style:[r.socialBtn,{borderColor:"#e5e7eb"}],onPress:e},t.createElement(x,{style:[r.socialIcon,{color:n}]},s)),r=Re.create({fullScreen:{flex:1},overlay:{...Re.absoluteFillObject},centeredModalContainer:{width:"90%",maxWidth:400,alignSelf:"center",marginTop:ge*.15,overflow:"hidden",shadowColor:"#000",shadowOffset:{width:0,height:20},shadowOpacity:.25,shadowRadius:30,elevation:20},contentWrapper:{paddingTop:ke.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:ke.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 Fe,useRef as We}from"react";import{TouchableOpacity as Ne,View as A,StyleSheet as Me,Animated as pe,Easing as je}from"react-native";var he=({onPress:n,options:e})=>{let s=e?.modal?.theme?.primaryColor||"#2563eb",o=e?.trigger?.position||"bottom-right",c=(e?.trigger?.displayMode||"floating")==="edge",m=o.includes("right"),a=o.includes("top"),g=We(new pe.Value(-1)).current;Fe(()=>{let z=()=>{g.setValue(-1),pe.timing(g,{toValue:2,duration:3e3,easing:je.linear,useNativeDriver:!0}).start(()=>{setTimeout(z,1e3)})};z()},[]);let p=g.interpolate({inputRange:[-1,2],outputRange:c?[-50,100]:[-60,120]}),d={"bottom-right":{bottom:100,right:0},"bottom-left":{bottom:100,left:0},"top-right":{top:100,right:0},"top-left":{top:100,left:0}};c||(d["bottom-right"]={bottom:30,right:20},d["bottom-left"]={bottom:30,left:20},d["top-right"]={top:60,right:20},d["top-left"]={top:60,left:20});let b=()=>B.createElement(A,{style:w.iconContainer},B.createElement(A,{style:w.bowContainer},B.createElement(A,{style:[w.bowLoop,w.bowLeft]}),B.createElement(A,{style:[w.bowLoop,w.bowRight]})),B.createElement(A,{style:w.giftLid}),B.createElement(A,{style:w.giftBody},B.createElement(A,{style:w.ribbonVertical})));return B.createElement(Ne,{style:[c?w.edgeButton:w.floatingButton,{backgroundColor:s},d[o],c&&(m?w.edgeRight:w.edgeLeft)],onPress:n,activeOpacity:.9},B.createElement(A,{style:w.content},b()),B.createElement(pe.View,{style:[w.shimmer,{transform:[{translateX:p},{skewX:"-15deg"}]}]}))},w=Me.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 W,{useEffect as $e,useRef as He,useState as _e}from"react";import{View as Ke,Text as we,StyleSheet as qe,Animated as re,Dimensions as Xe,TouchableOpacity as Ye,Platform as Je}from"react-native";var{width:Qe}=Xe.get("window"),xe=({visible:n,options:e,onClose:s})=>{let o=He(new re.Value(0)).current,[l,c]=_e(n),m=e.position.includes("bottom")?"bottom":"top",a=e.position.includes("left")?"left":e.position.includes("right")?"right":"center";if($e(()=>{n?(c(!0),re.spring(o,{toValue:1,useNativeDriver:!0,tension:50,friction:8}).start()):re.timing(o,{toValue:0,duration:250,useNativeDriver:!0}).start(()=>{c(!1)})},[n]),!l)return null;let g=o.interpolate({inputRange:[0,1],outputRange:[m==="top"?-100:100,0]}),p=o.interpolate({inputRange:[0,1],outputRange:[0,1]}),d={position:"absolute",[m]:Je.OS==="ios"?60:40,zIndex:9999};return a==="center"?(d.left=20,d.right=20,d.alignItems="center"):d[a]=20,W.createElement(re.View,{style:[d,{transform:[{translateY:g}],opacity:p}]},W.createElement(Ke,{style:[K.banner,{backgroundColor:e.themeColor||"#2563eb"}]},W.createElement(we,{style:K.icon},"\u{1F381}"),W.createElement(we,{style:K.text},e.text),W.createElement(Ye,{onPress:s,style:K.closeBtn},W.createElement(we,{style:K.closeIcon},"\u2715"))))},K=qe.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:Qe-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 Ie=Ze(void 0),it=({children:n,userId:e,...s})=>{let[o,l]=E(!1),[c,m]=E(!1),[a,g]=E(null),p=me(new J(s)),d=me(!1),b=me(null),[z,v]=E(!1),[M,ie]=E(),[ne,be]=E(!1),[y,V]=E(),[q,j]=E(!1),[$,ae]=E(),X=U(()=>{let{width:f,height:i}=tt.get("window"),h=Intl.DateTimeFormat().resolvedOptions().locale,k=rt.get(),T,F;if(N.OS==="android"){let ce=N.constants;T=ce.Model,F=ce.Brand||ce.Manufacturer}return{os:N.OS,platform:N.OS,osVersion:String(N.Version),screenWidth:f,screenHeight:i,timezoneOffsetInMinutes:String(new Date().getTimezoneOffset()),locale:h,language:h,deviceModel:T,deviceBrand:F,pixelRatio:k}},[]),L=U(async(f,i)=>{let h=await p.current.trackReferral(f,i);return await S.setTrackedReferral(h.referralTrackingId),h},[]),Y=U(async f=>{try{let i=f.match(/[?&]referralCode=([^&]+)/);i&&(console.log("GrowthRail: Tracking referral from deep link",i[1]),await L(i[1]))}catch(i){console.warn("GrowthRail: Error handling deep link",i)}},[L]),O=U(async()=>{try{let f=X(),{referralTrackingId:i}=await p.current.checkDeferredDeepLink(f);i&&(console.log("GrowthRail: Found deferred referral via fingerprinting",i),await S.setTrackedReferral(i))}catch(f){console.warn("GrowthRail: Fingerprint check failed",f)}},[X]),se=U(()=>new Promise(f=>{ot.getInstallReferrerInfo(async(i,h)=>{if(!h&&i&&i.installReferrer)try{let T=decodeURIComponent(i.installReferrer).match(/[?&]referralCode=([^&]+)/);if(T){let{referralTrackingId:F}=await L(T[1]);await S.setTrackedReferral(F),console.log("GrowthRail: Tracked referral via Install Referrer")}}catch(k){console.warn("GrowthRail: Failed to process install referrer",k)}else await O();f()})}),[L,O]),R=U(async f=>{if(a?.id===f&&c)return a;let i=(async()=>{try{let h=await p.current.initAppUser(f),k={...h,id:f};return g(k),m(!0),h.referrerExperience?.trigger?.show&&be(!0),k}catch(h){throw b.current=null,h}})();return b.current=i,i},[a,c]),D=U(async f=>{let i=a;!i&&b.current&&(i=await b.current);let h=i?.id||e;if(!h)throw new Error("GrowthRail: User must be initialized before tracking a reward event.");let k=await S.getTrackedReferral();if(!k){console.warn("GrowthRail: No referral tracking ID found. Reward event not attributed.");return}return p.current.trackRewardEvent(h,k,f)},[a,e]),le=U(async()=>await S.getTrackedReferral(),[]),G=U(async()=>{if(a)return a.referralLink;if(b.current)return(await b.current).referralLink},[a]);ve(()=>{if(d.current)return;d.current=!0,(async()=>{let i=await Le.getInitialURL();i&&await Y(i);let h=Le.addEventListener("url",({url:T})=>Y(T));await S.isFirstLaunch()&&(N.OS==="android"?await se():await O()),e&&await R(e);try{let T=await p.current.getNewUserExperience(),F=await S.getTrackedReferral();T.banner?.show&&F&&(ae(T.banner),j(!0))}catch{}return l(!0),()=>h.remove()})()},[]),ve(()=>{o&&e&&a?.id!==e&&R(e)},[e,o]);let I={isInitialized:o,isUserReady:c,currentUser:a,referralCode:a?.referralCode,referralLink:a?.referralLink,showDashboard:f=>{ie(f),v(!0)},hideDashboard:()=>v(!1),initUser:R,trackReward:D,getReferralTrackingId:le,getReferralLink:G};if(!o)return null;let C=a?.referrerExperience,H={...C?.modal,...M,position:C?.trigger?.position||M?.position||"bottom-right",theme:{...C?.modal?.theme||{},...M?.theme||{}}},Be={...C,...y,trigger:{...C?.trigger||{},...y?.trigger||{}}};return oe.createElement(Ie.Provider,{value:I},n,oe.createElement(ue,{visible:z,options:H,onClose:()=>v(!1)}),ne&&oe.createElement(he,{options:Be,onPress:()=>I.showDashboard()}),q&&oe.createElement(xe,{visible:q,options:$,onClose:()=>j(!1)}))},te=()=>{let n=et(Ie);if(!n)throw new Error("useGrowthRail must be used within a GrowthRailProvider");return n};import{useState as Se,useCallback as Pe}from"react";var nt=()=>{let[n,e]=Se(!1),[s,o]=Se(null),l=te(),c=Pe(async a=>{e(!0),o(null);try{return await l.initUser(a)}catch(g){let p=g instanceof Error?g:new Error(String(g));throw o(p),p}finally{e(!1)}},[l]),m=Pe(async a=>{e(!0),o(null);try{await l.trackReward(a)}catch(g){let p=g instanceof Error?g:new Error(String(g));throw o(p),p}finally{e(!1)}},[l]);return{initAppUser:c,trackRewardEvent:m,showReferralDashboard:l.showDashboard,hideReferralDashboard:l.hideDashboard,getReferralTrackingId:l.getReferralTrackingId,getReferralLink:l.getReferralLink,isLoading:n,isInitialized:l.isInitialized,isUserReady:l.isUserReady,error:s}};export{it as GrowthRailProvider,ue as ReferralDashboard,he as TriggerButton,nt as useGrowthRail};
|
|
1
|
+
var Ve=Object.defineProperty;var Oe=(n,e,s)=>e in n?Ve(n,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):n[e]=s;var ce=(n,e,s)=>Oe(n,typeof e!="symbol"?e+"":e,s);import oe,{createContext as Ze,useContext as et,useEffect as ve,useState as E,useRef as we,useCallback as U}from"react";import{Linking as Le,Platform as N,Dimensions as tt,PixelRatio as rt}from"react-native";import ot from"react-native-play-install-referrer";var J=class{constructor(e){ce(this,"baseUrl");ce(this,"projectSecretKey");let s=typeof process<"u"&&process.env?.ENV_BASE_URL;this.baseUrl=s||"https://api.growthrail.dev",this.projectSecretKey=e.projectSecretKey}async request(e,s,o){let l={"Content-Type":"application/json","X-GrowthRail-ProjectSecret":this.projectSecretKey,Origin:this.baseUrl};try{let c=await fetch(`${this.baseUrl}${e}`,{method:s,headers:l,body:o?JSON.stringify(o):void 0});if(!c.ok){let m="";try{m=await c.text()}catch{}throw new Error(`GrowthRail API Error ${c.status} (${this.baseUrl}${e}): ${c.statusText} - ${m}`)}return c.json()}catch(c){throw console.error("GrowthRail SDK Error:",c),c}}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,s){return this.request("/api/v1/sdk/track-referral","POST",{referralCode:e,rewardEventName:s})}async trackRewardEvent(e,s,o){return this.request("/api/v1/sdk/track-reward-event","POST",{refereeId:e,referralTrackingId:s,eventName:o})}async checkDeferredDeepLink(e){return this.request("/api/v1/sdk/match-link","POST",{fingerprint:e})}};import Q from"@react-native-async-storage/async-storage";var Z={TRACKED_REFERRAL:"growth-rail-tracked-referral",IS_FIRST_LAUNCH:"growth-rail-is-first-launch"},P=class{static async setTrackedReferral(e){await Q.setItem(Z.TRACKED_REFERRAL,e)}static async getTrackedReferral(){return await Q.getItem(Z.TRACKED_REFERRAL)}static async isFirstLaunch(){return await Q.getItem(Z.IS_FIRST_LAUNCH)===null?(await Q.setItem(Z.IS_FIRST_LAUNCH,"false"),!0):!1}};import t,{useEffect as De,useState as de,useRef as ye}from"react";import{Modal as Ee,View as u,Text as x,StyleSheet as Re,TouchableOpacity as ee,Clipboard as Ue,ActivityIndicator as Ae,Linking as Ce,ScrollView as Ge,Platform as ke,Animated as B,Dimensions as ze}from"react-native";var{width:Te,height:fe}=ze.get("window"),ge=({visible:n,options:e,onClose:s})=>{let o=te(),[l,c]=de(null),[m,a]=de(!1),[g,p]=de(!1),d=ye(new B.Value(0)).current,b=ye(new B.Value(0)).current,z=e?.title||"Invite Friends & Earn",v=e?.theme?.primaryColor||"#2563eb",M=e?.theme?.backgroundColor||"#ffffff",ie=e?.theme?.tintColor||"#000000",ne=e?.theme?.tintAlpha??.5,y=(e?.componentType||"modal")==="drawer",O=e?.position||"bottom-right",q="#111827",j="#6b7280";De(()=>{n?(l||ae(),B.parallel([B.timing(b,{toValue:1,duration:300,useNativeDriver:!0}),B.spring(d,{toValue:1,useNativeDriver:!0,tension:50,friction:8})]).start()):(d.setValue(0),b.setValue(0))},[n]);let $=()=>{B.parallel([B.timing(b,{toValue:0,duration:250,useNativeDriver:!0}),B.timing(d,{toValue:0,duration:250,useNativeDriver:!0})]).start(()=>{s()})},ae=async()=>{a(!0);try{if(o.isUserReady){let G=await o.getReferralLink();c(G||null)}}catch(G){console.error("GrowthRail: Failed to load referral link",G)}finally{a(!1)}},X=()=>{l&&(Ue.setString(l),p(!0),setTimeout(()=>p(!1),2e3))},L=G=>{if(!l)return;let S="",C=encodeURIComponent(l),H=encodeURIComponent("Check this out!");switch(G){case"twitter":S=`https://twitter.com/intent/tweet?url=${C}&text=${H}`;break;case"facebook":S=`https://www.facebook.com/sharer/sharer.php?u=${C}`;break;case"linkedin":S=`https://www.linkedin.com/sharing/share-offsite/?url=${C}`;break;case"whatsapp":S=`whatsapp://send?text=${H}%20${C}`;break;case"email":S=`mailto:?subject=Check this out&body=${H}%20${C}`;break}S&&Ce.openURL(S).catch(()=>{})},Y=()=>ie||"#000000",I=[];y?O.includes("right")?I=[{translateX:d.interpolate({inputRange:[0,1],outputRange:[Te,0]})}]:O.includes("left")?I=[{translateX:d.interpolate({inputRange:[0,1],outputRange:[-Te,0]})}]:I=[{translateY:d.interpolate({inputRange:[0,1],outputRange:[fe,0]})}]:I=[{scale:d.interpolate({inputRange:[0,1],outputRange:[.9,1]})},{translateY:d.interpolate({inputRange:[0,1],outputRange:[20,0]})}];let be=O.includes("top"),R=O.includes("right"),D=O.includes("left"),se=y?{position:"absolute",...be?{top:100}:{bottom:100},...R?{right:0}:D?{left:0}:{left:0,right:0},width:R||D?"85%":"100%",maxHeight:R||D?fe-200:"80%"}:{};return t.createElement(Ee,{visible:n,transparent:!0,animationType:"none",onRequestClose:$},t.createElement(u,{style:r.fullScreen},t.createElement(B.View,{style:[r.overlay,{backgroundColor:Y(),opacity:b.interpolate({inputRange:[0,1],outputRange:[0,ne]})}]},t.createElement(ee,{style:r.fullScreen,activeOpacity:1,onPress:$})),t.createElement(B.View,{style:[y?se:r.centeredModalContainer,{backgroundColor:M,transform:I},y&&R&&{borderTopLeftRadius:24,borderBottomLeftRadius:24},y&&D&&{borderTopRightRadius:24,borderBottomRightRadius:24},y&&!R&&!D&&O.includes("bottom")&&{borderTopLeftRadius:24,borderTopRightRadius:24},y&&!R&&!D&&O.includes("top")&&{borderBottomLeftRadius:24,borderBottomRightRadius:24},!y&&{borderRadius:24,opacity:d}]},t.createElement(u,{style:r.contentWrapper},y&&!R&&!D&&O.includes("bottom")&&t.createElement(u,{style:r.drawerHandle}),t.createElement(ee,{style:r.closeBtn,onPress:$},t.createElement(x,{style:r.closeIcon},"\u2715")),t.createElement(Ge,{contentContainerStyle:r.scrollContent,showsVerticalScrollIndicator:!1},t.createElement(u,{style:r.header},t.createElement(u,{style:r.iconLgContainer},t.createElement(u,{style:r.bowContainerLg},t.createElement(u,{style:[r.bowLoopLg,r.bowLeftLg,{borderColor:v}]}),t.createElement(u,{style:[r.bowLoopLg,r.bowRightLg,{borderColor:v}]})),t.createElement(u,{style:[r.giftLidLg,{backgroundColor:v}]}),t.createElement(u,{style:[r.giftBodyLg,{borderColor:v}]},t.createElement(u,{style:[r.ribbonVerticalLg,{backgroundColor:"#fff",opacity:.3}]}))),t.createElement(x,{style:[r.title,{color:q}]},z),t.createElement(x,{style:[r.subtitle,{color:j}]},e?.description||"Share your unique link and earn rewards for every friend who signs up.")),o.isUserReady?m?t.createElement(Ae,{size:"large",color:v,style:r.loader}):t.createElement(u,{style:r.mainContent},t.createElement(x,{style:r.label},"YOUR UNIQUE LINK"),t.createElement(u,{style:r.inputGroup},t.createElement(x,{numberOfLines:1,style:r.input},l||"Initializing..."),t.createElement(ee,{style:[r.copyBtn,{backgroundColor:g?"#10b981":v}],onPress:X},t.createElement(x,{style:r.copyBtnText},g?"Copied!":"Copy"))),t.createElement(u,{style:r.shareLabelContainer},t.createElement(u,{style:r.divider}),t.createElement(x,{style:r.shareLabel},"Share via"),t.createElement(u,{style:r.divider})),t.createElement(u,{style:r.socialContainer},t.createElement(_,{platform:"twitter",color:"#000000",onPress:()=>L("twitter"),icon:"\u{1D54F}"}),t.createElement(_,{platform:"facebook",color:"#1877F2",onPress:()=>L("facebook"),icon:"f"}),t.createElement(_,{platform:"linkedin",color:"#0A66C2",onPress:()=>L("linkedin"),icon:"in"}),t.createElement(_,{platform:"whatsapp",color:"#25D366",onPress:()=>L("whatsapp"),icon:"W"}),t.createElement(_,{platform:"email",color:"#888888",onPress:()=>L("email"),icon:"\u2709"}))):t.createElement(u,{style:r.loadingBox},t.createElement(x,{style:{color:j,textAlign:"center"}},"Please log in to view your referral dashboard.")),t.createElement(u,{style:r.footer},t.createElement(x,{style:r.poweredBy},"Powered by ",t.createElement(x,{style:r.brand,onPress:()=>Ce.openURL("https://growthrail.com")},"Growth Rail"))))))))},_=({color:n,onPress:e,icon:s})=>t.createElement(ee,{style:[r.socialBtn,{borderColor:"#e5e7eb"}],onPress:e},t.createElement(x,{style:[r.socialIcon,{color:n}]},s)),r=Re.create({fullScreen:{flex:1},overlay:{...Re.absoluteFillObject},centeredModalContainer:{width:"90%",maxWidth:400,alignSelf:"center",marginTop:fe*.15,overflow:"hidden",shadowColor:"#000",shadowOffset:{width:0,height:20},shadowOpacity:.25,shadowRadius:30,elevation:20},contentWrapper:{paddingTop:ke.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:ke.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 V,{useEffect as Fe,useRef as We}from"react";import{TouchableOpacity as Ne,View as A,StyleSheet as Me,Animated as ue,Easing as je}from"react-native";var pe=({onPress:n,options:e})=>{let s=e?.modal?.theme?.primaryColor||"#2563eb",o=e?.trigger?.position||"bottom-right",c=(e?.trigger?.displayMode||"floating")==="edge",m=o.includes("right"),a=o.includes("top"),g=We(new ue.Value(-1)).current;Fe(()=>{let z=()=>{g.setValue(-1),ue.timing(g,{toValue:2,duration:3e3,easing:je.linear,useNativeDriver:!0}).start(()=>{setTimeout(z,1e3)})};z()},[]);let p=g.interpolate({inputRange:[-1,2],outputRange:c?[-50,100]:[-60,120]}),d={"bottom-right":{bottom:100,right:0},"bottom-left":{bottom:100,left:0},"top-right":{top:100,right:0},"top-left":{top:100,left:0}};c||(d["bottom-right"]={bottom:30,right:20},d["bottom-left"]={bottom:30,left:20},d["top-right"]={top:60,right:20},d["top-left"]={top:60,left:20});let b=()=>V.createElement(A,{style:w.iconContainer},V.createElement(A,{style:w.bowContainer},V.createElement(A,{style:[w.bowLoop,w.bowLeft]}),V.createElement(A,{style:[w.bowLoop,w.bowRight]})),V.createElement(A,{style:w.giftLid}),V.createElement(A,{style:w.giftBody},V.createElement(A,{style:w.ribbonVertical})));return V.createElement(Ne,{style:[c?w.edgeButton:w.floatingButton,{backgroundColor:s},d[o],c&&(m?w.edgeRight:w.edgeLeft)],onPress:n,activeOpacity:.9},V.createElement(A,{style:w.content},b()),V.createElement(ue.View,{style:[w.shimmer,{transform:[{translateX:p},{skewX:"-15deg"}]}]}))},w=Me.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 W,{useEffect as $e,useRef as He,useState as _e}from"react";import{View as Ke,Text as he,StyleSheet as qe,Animated as re,Dimensions as Xe,TouchableOpacity as Ye,Platform as Je}from"react-native";var{width:Qe}=Xe.get("window"),xe=({visible:n,options:e,onClose:s})=>{let o=He(new re.Value(0)).current,[l,c]=_e(n),m=e.position.includes("bottom")?"bottom":"top",a=e.position.includes("left")?"left":e.position.includes("right")?"right":"center";if($e(()=>{n?(c(!0),re.spring(o,{toValue:1,useNativeDriver:!0,tension:50,friction:8}).start()):re.timing(o,{toValue:0,duration:250,useNativeDriver:!0}).start(()=>{c(!1)})},[n]),!l)return null;let g=o.interpolate({inputRange:[0,1],outputRange:[m==="top"?-100:100,0]}),p=o.interpolate({inputRange:[0,1],outputRange:[0,1]}),d={position:"absolute",[m]:Je.OS==="ios"?60:40,zIndex:9999};return a==="center"?(d.left=20,d.right=20,d.alignItems="center"):d[a]=20,W.createElement(re.View,{style:[d,{transform:[{translateY:g}],opacity:p}]},W.createElement(Ke,{style:[K.banner,{backgroundColor:e.themeColor||"#2563eb"}]},W.createElement(he,{style:K.icon},"\u{1F381}"),W.createElement(he,{style:K.text},e.text),W.createElement(Ye,{onPress:s,style:K.closeBtn},W.createElement(he,{style:K.closeIcon},"\u2715"))))},K=qe.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:Qe-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 Ie=Ze(void 0),it=({children:n,userId:e,...s})=>{let[o,l]=E(!1),[c,m]=E(!1),[a,g]=E(null),p=we(new J(s)),d=we(!1),b=we(null),[z,v]=E(!1),[M,ie]=E(),[ne,me]=E(!1),[y,O]=E(),[q,j]=E(!1),[$,ae]=E(),X=U(()=>{let{width:f,height:i}=tt.get("window"),h=Intl.DateTimeFormat().resolvedOptions().locale,k=rt.get(),T,F;if(N.OS==="android"){let le=N.constants;T=le.Model,F=le.Brand||le.Manufacturer}return{os:N.OS,platform:N.OS,osVersion:String(N.Version),screenWidth:f,screenHeight:i,timezoneOffsetInMinutes:String(new Date().getTimezoneOffset()),locale:h,language:h,deviceModel:T,deviceBrand:F,pixelRatio:k}},[]),L=U(async(f,i)=>{let h=await p.current.trackReferral(f,i);return await P.setTrackedReferral(h.referralTrackingId),h},[]),Y=U(async f=>{try{let i=f.match(/[?&]referralCode=([^&]+)/);i&&(console.log("GrowthRail: Tracking referral from deep link",i[1]),await L(i[1]))}catch(i){console.warn("GrowthRail: Error handling deep link",i)}},[L]),I=U(async()=>{try{let f=X(),{referralTrackingId:i}=await p.current.checkDeferredDeepLink(f);i&&(console.log("GrowthRail: Found deferred referral via fingerprinting",i),await P.setTrackedReferral(i))}catch(f){console.warn("GrowthRail: Fingerprint check failed",f)}},[X]),be=U(()=>new Promise(f=>{ot.getInstallReferrerInfo(async(i,h)=>{if(!h&&i&&i.installReferrer)try{let T=decodeURIComponent(i.installReferrer).match(/[?&]referralCode=([^&]+)/);if(T){let{referralTrackingId:F}=await L(T[1]);await P.setTrackedReferral(F),console.log("GrowthRail: Tracked referral via Install Referrer")}}catch(k){console.warn("GrowthRail: Failed to process install referrer",k)}else await I();f()})}),[L,I]),R=U(async f=>{if(a?.id===f&&c)return a;let i=(async()=>{try{let h=await p.current.initAppUser(f),k={...h,id:f};return g(k),m(!0),h.referrerExperience?.trigger?.show&&me(!0),k}catch(h){throw b.current=null,h}})();return b.current=i,i},[a,c]),D=U(async f=>{let i=a;!i&&b.current&&(i=await b.current);let h=i?.id||e;if(!h)throw new Error("GrowthRail: User must be initialized before tracking a reward event.");let k=await P.getTrackedReferral();if(!k){console.warn("GrowthRail: No referral tracking ID found. Reward event not attributed.");return}return p.current.trackRewardEvent(h,k,f)},[a,e]),se=U(async()=>await P.getTrackedReferral(),[]),G=U(async()=>{if(a)return a.referralLink;if(b.current)return(await b.current).referralLink},[a]);ve(()=>{if(d.current)return;d.current=!0,(async()=>{let i=await Le.getInitialURL();i&&await Y(i);let h=Le.addEventListener("url",({url:T})=>Y(T));await P.isFirstLaunch()&&(N.OS==="android"?await I():await I()),e&&await R(e);try{let T=await p.current.getNewUserExperience(),F=await P.getTrackedReferral();T.banner?.show&&F&&(ae(T.banner),j(!0))}catch{}return l(!0),()=>h.remove()})()},[]),ve(()=>{o&&e&&a?.id!==e&&R(e)},[e,o]);let S={isInitialized:o,isUserReady:c,currentUser:a,referralCode:a?.referralCode,referralLink:a?.referralLink,showDashboard:f=>{ie(f),v(!0)},hideDashboard:()=>v(!1),initUser:R,trackReward:D,getReferralTrackingId:se,getReferralLink:G};if(!o)return null;let C=a?.referrerExperience,H={...C?.modal,...M,position:C?.trigger?.position||M?.position||"bottom-right",theme:{...C?.modal?.theme||{},...M?.theme||{}}},Be={...C,...y,trigger:{...C?.trigger||{},...y?.trigger||{}}};return oe.createElement(Ie.Provider,{value:S},n,oe.createElement(ge,{visible:z,options:H,onClose:()=>v(!1)}),ne&&oe.createElement(pe,{options:Be,onPress:()=>S.showDashboard()}),q&&oe.createElement(xe,{visible:q,options:$,onClose:()=>j(!1)}))},te=()=>{let n=et(Ie);if(!n)throw new Error("useGrowthRail must be used within a GrowthRailProvider");return n};import{useState as Se,useCallback as Pe}from"react";var nt=()=>{let[n,e]=Se(!1),[s,o]=Se(null),l=te(),c=Pe(async a=>{e(!0),o(null);try{return await l.initUser(a)}catch(g){let p=g instanceof Error?g:new Error(String(g));throw o(p),p}finally{e(!1)}},[l]),m=Pe(async a=>{e(!0),o(null);try{await l.trackReward(a)}catch(g){let p=g instanceof Error?g:new Error(String(g));throw o(p),p}finally{e(!1)}},[l]);return{initAppUser:c,trackRewardEvent:m,showReferralDashboard:l.showDashboard,hideReferralDashboard:l.hideDashboard,getReferralTrackingId:l.getReferralTrackingId,getReferralLink:l.getReferralLink,isLoading:n,isInitialized:l.isInitialized,isUserReady:l.isUserReady,error:s}};export{it as GrowthRailProvider,ge as ReferralDashboard,pe as TriggerButton,nt as useGrowthRail};
|