@growth-rail/react 2.1.0 → 2.1.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 +8 -0
- package/README.md +1 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -39,6 +39,7 @@ function App() {
|
|
|
39
39
|
<GrowthRailProvider
|
|
40
40
|
projectSecretKey="your_project_secret_key_here"
|
|
41
41
|
userId="user_123" // Optional: initialize for a specific user
|
|
42
|
+
debug={true} // Enable verbose console logging
|
|
42
43
|
>
|
|
43
44
|
<your-application-code />
|
|
44
45
|
</GrowthRailProvider>
|
package/dist/index.d.mts
CHANGED
|
@@ -10,6 +10,8 @@ interface GrowthRailProviderProps extends GrowthRailOptions {
|
|
|
10
10
|
userId?: string;
|
|
11
11
|
/** Your application components. */
|
|
12
12
|
children: ReactNode;
|
|
13
|
+
/** Whether to enable debug mode for verbose console logging. */
|
|
14
|
+
debug?: boolean;
|
|
13
15
|
}
|
|
14
16
|
/**
|
|
15
17
|
* Root provider component for GrowthRail in React applications.
|
package/dist/index.d.ts
CHANGED
|
@@ -10,6 +10,8 @@ interface GrowthRailProviderProps extends GrowthRailOptions {
|
|
|
10
10
|
userId?: string;
|
|
11
11
|
/** Your application components. */
|
|
12
12
|
children: ReactNode;
|
|
13
|
+
/** Whether to enable debug mode for verbose console logging. */
|
|
14
|
+
debug?: boolean;
|
|
13
15
|
}
|
|
14
16
|
/**
|
|
15
17
|
* Root provider component for GrowthRail in React applications.
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.tsx","../src/GrowthRailProvider.tsx","../src/useGrowthRail.ts","../src/ReferralDashboard.tsx"],"sourcesContent":["/**\n * GrowthRail React SDK\n * \n * This package provide React components and hooks for the GrowthRail referral system.\n * It is built on top of the `@growth-rail/core` package.\n */\n\n/** Root provider component for initializing GrowthRail. */\nexport { GrowthRailProvider } from './GrowthRailProvider';\n\n/** Hook for accessing GrowthRail methods and state. */\nexport { useGrowthRail, type UseGrowthRailReturn } from './useGrowthRail';\n\n/** Inline referral dashboard component. */\nexport { \n ReferralDashboard, \n type ReferralDashboardProps,\n} from './ReferralDashboard';\n\n/** Re-exported core types. */\nexport type { \n GrowthRailOptions, \n AppUserType,\n ReferrerModalOptions,\n ReferrerExperience,\n ReferrerTriggerButton \n} from '@growth-rail/core';\n","import React, { useEffect, useRef, useState, ReactNode } from 'react';\nimport { GrowthRail, GrowthRailOptions } from '@growth-rail/core';\n\n/**\n * Props for the GrowthRailProvider component.\n */\ninterface GrowthRailProviderProps extends GrowthRailOptions {\n /** The unique ID for the current application user. */\n userId?: string;\n /** Your application components. */\n children: ReactNode;\n}\n\n/**\n * Root provider component for GrowthRail in React applications.\n * This component initializes the SDK and manages the user's authentication state.\n * \n * Wrap your app (or a specific feature tree) with this provider.\n * \n * @example\n * <GrowthRailProvider projectSecretKey=\"your-api-key\" userId=\"user-123\">\n * <App />\n * </GrowthRailProvider>\n */\nexport const GrowthRailProvider: React.FC<GrowthRailProviderProps> = ({ \n children, \n userId,\n ...options \n}) => {\n\n const [isReady, setIsReady] = useState(GrowthRail.isInitialized());\n const initialized = useRef(false);\n\n useEffect(() => {\n if (initialized.current) return;\n initialized.current = true;\n\n GrowthRail.init(options);\n if (userId) {\n GrowthRail.initAppUser(userId).catch(console.error);\n }\n setIsReady(true);\n }, []);\n\n useEffect(() => {\n if (initialized.current && userId && GrowthRail.getUserId() !== userId) {\n GrowthRail.initAppUser(userId).catch(console.error);\n }\n }, [userId]);\n\n if (!isReady) return null;\n\n return <>{children}</>;\n};\n","import { useState, useCallback } from 'react';\nimport { GrowthRail, AppUserType, ReferrerTriggerButton } from '@growth-rail/core';\n\n/**\n * The return type of the useGrowthRail hook.\n */\nexport interface UseGrowthRailReturn {\n /** \n * Initializes a user in the GrowthRail system. \n * @param userId - Unique identifier for the user.\n */\n initAppUser: (userId: string) => Promise<AppUserType>;\n /** \n * Tracks a reward-eligible event for the current user.\n * @param eventName - Optional name of the event.\n */\n trackRewardEvent: (eventName?: string) => Promise<void>;\n /** \n * Manually triggers the referral dashboard modal.\n * @param options - Customization options for the modal.\n */\n showReferralDashboard: (options?: Parameters<typeof GrowthRail.showReferralDashboard>[0]) => void;\n /** \n * Manually shows or updates the floating referral trigger button.\n * @param options - Configuration for the button.\n */\n showFloatingButton: (options: Partial<ReferrerTriggerButton>) => void;\n /** Hides the floating referral trigger button. */\n hideFloatingButton: () => void;\n /** Whether an asynchronous operation (like init or track) is in progress. */\n isLoading: boolean;\n /** The last error that occurred during an operation. */\n error: Error | null;\n}\n\n/**\n * A hook that provides access to GrowthRail SDK methods and state.\n * \n * @returns An object containing methods to manage referrals and track state.\n * \n * @example\n * const { showReferralDashboard, trackRewardEvent } = useGrowthRail();\n */\nexport const useGrowthRail = (): UseGrowthRailReturn => {\n\n const [isLoading, setIsLoading] = useState(false);\n const [error, setError] = useState<Error | null>(null);\n\n const initAppUser = useCallback(async (userId: string) => {\n setIsLoading(true);\n setError(null);\n try {\n const user = await GrowthRail.initAppUser(userId);\n return user;\n } catch (err) {\n const error = err instanceof Error ? err : new Error(String(err));\n setError(error);\n throw error;\n } finally {\n setIsLoading(false);\n }\n }, []);\n\n const trackRewardEvent = useCallback(async (eventName?: string) => {\n setIsLoading(true);\n setError(null);\n try {\n await GrowthRail.trackRewardEvent(eventName);\n } catch (err) {\n const error = err instanceof Error ? err : new Error(String(err));\n setError(error);\n throw error;\n } finally {\n setIsLoading(false);\n }\n }, []);\n\n const showReferralDashboard = useCallback((options?: Parameters<typeof GrowthRail.showReferralDashboard>[0]) => {\n GrowthRail.showReferralDashboard(options);\n }, []);\n\n const showFloatingButton = useCallback((options: Partial<ReferrerTriggerButton>) => {\n GrowthRail.createTriggerButton(options);\n }, []);\n\n const hideFloatingButton = useCallback(() => {\n GrowthRail.destroyTriggerButton();\n }, []);\n\n return {\n initAppUser,\n trackRewardEvent,\n showReferralDashboard,\n showFloatingButton,\n hideFloatingButton,\n isLoading,\n error,\n };\n};\n","import React, { useEffect, useRef } from 'react';\nimport { GrowthRail, ReferrerModalOptions, ReferralModal, ReferrerExperience } from '@growth-rail/core';\n\n/**\n * Props for the ReferralDashboard component.\n */\nexport interface ReferralDashboardProps {\n /** Optional override for the dashboard title. */\n title?: string;\n /** Customization options for the dashboard's appearance. */\n appearance?: ReferrerModalOptions;\n /** Callback fired when the referral link is copied to the clipboard. */\n onLinkCopied?: () => void;\n}\n\n/**\n * An inline referral dashboard component.\n * Unlike the global modal, this component renders directly within your layout.\n * \n * @example\n * <div style={{ height: '500px' }}>\n * <ReferralDashboard title=\"Invite your team\" />\n * </div>\n */\nexport const ReferralDashboard: React.FC<ReferralDashboardProps> = ({\n title,\n appearance = {},\n onLinkCopied,\n}) => {\n\n const containerRef = useRef<HTMLDivElement>(null);\n const modalRef = useRef<ReferralModal | null>(null);\n\n useEffect(() => {\n let mounted = true;\n if (!containerRef.current) return;\n\n GrowthRail.ensureUserReady().then((user) => {\n if (!mounted || !containerRef.current) return;\n\n const deps = {\n isUserReady: () => GrowthRail.isUserReady(),\n getReferralLink: () => {\n try {\n return GrowthRail.getReferralLink();\n } catch {\n return '';\n }\n },\n };\n\n // Construct experience config directly from BE\n const experience: ReferrerExperience = {\n trigger: user.referrerExperience.trigger,\n modal: {\n ...user.referrerExperience.modal,\n ...(title ? { title } : {}),\n ...appearance,\n },\n };\n\n modalRef.current = new ReferralModal(deps, experience);\n modalRef.current.show(appearance, containerRef.current);\n }).catch((err) => {\n console.error('GrowthRail: User initialization failed', err);\n });\n\n return () => {\n mounted = false;\n if (modalRef.current) {\n modalRef.current.hide();\n modalRef.current = null;\n }\n };\n }, [title, appearance]);\n\n return (\n <div \n ref={containerRef} \n style={{ \n width: '100%', \n height: '100%', \n minHeight: '400px',\n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;AACF,mBAAO,wBAAW,gBAAgB;AAAA,UACpC,QAAQ;AACN,mBAAO;AAAA,UACT;AAAA,QACF;AAAA,MACF;AAGA,YAAM,aAAiC;AAAA,QACrC,SAAS,KAAK,mBAAmB;AAAA,QACjC,OAAO;AAAA,UACL,GAAG,KAAK,mBAAmB;AAAA,UAC3B,GAAI,QAAQ,EAAE,MAAM,IAAI,CAAC;AAAA,UACzB,GAAG;AAAA,QACL;AAAA,MACF;AAEA,eAAS,UAAU,IAAI,2BAAc,MAAM,UAAU;AACrD,eAAS,QAAQ,KAAK,YAAY,aAAa,OAAO;AAAA,IACxD,CAAC,EAAE,MAAM,CAAC,QAAQ;AAChB,cAAQ,MAAM,0CAA0C,GAAG;AAAA,IAC7D,CAAC;AAED,WAAO,MAAM;AACX,gBAAU;AACV,UAAI,SAAS,SAAS;AACpB,iBAAS,QAAQ,KAAK;AACtB,iBAAS,UAAU;AAAA,MACrB;AAAA,IACF;AAAA,EACF,GAAG,CAAC,OAAO,UAAU,CAAC;AAEtB,SACE;AAAA,IAAC;AAAA;AAAA,MACC,KAAK;AAAA,MACL,OAAO;AAAA,QACL,OAAO;AAAA,QACP,QAAQ;AAAA,QACR,WAAW;AAAA,QACX,UAAU;AAAA,MACZ;AAAA;AAAA,EACF;AAEJ;","names":["import_react","import_core","error","import_react","import_core","import_jsx_runtime"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.tsx","../src/GrowthRailProvider.tsx","../src/useGrowthRail.ts","../src/ReferralDashboard.tsx"],"sourcesContent":["/**\n * GrowthRail React SDK\n * \n * This package provide React components and hooks for the GrowthRail referral system.\n * It is built on top of the `@growth-rail/core` package.\n */\n\n/** Root provider component for initializing GrowthRail. */\nexport { GrowthRailProvider } from './GrowthRailProvider';\n\n/** Hook for accessing GrowthRail methods and state. */\nexport { useGrowthRail, type UseGrowthRailReturn } from './useGrowthRail';\n\n/** Inline referral dashboard component. */\nexport { \n ReferralDashboard, \n type ReferralDashboardProps,\n} from './ReferralDashboard';\n\n/** Re-exported core types. */\nexport type { \n GrowthRailOptions, \n AppUserType,\n ReferrerModalOptions,\n ReferrerExperience,\n ReferrerTriggerButton \n} from '@growth-rail/core';\n","import React, { useEffect, useRef, useState, ReactNode } from 'react';\nimport { GrowthRail, GrowthRailOptions } from '@growth-rail/core';\n\n/**\n * Props for the GrowthRailProvider component.\n */\ninterface GrowthRailProviderProps extends GrowthRailOptions {\n /** The unique ID for the current application user. */\n userId?: string;\n /** Your application components. */\n children: ReactNode;\n /** Whether to enable debug mode for verbose console logging. */\n debug?: boolean;\n}\n\n/**\n * Root provider component for GrowthRail in React applications.\n * This component initializes the SDK and manages the user's authentication state.\n * \n * Wrap your app (or a specific feature tree) with this provider.\n * \n * @example\n * <GrowthRailProvider projectSecretKey=\"your-api-key\" userId=\"user-123\">\n * <App />\n * </GrowthRailProvider>\n */\nexport const GrowthRailProvider: React.FC<GrowthRailProviderProps> = ({ \n children, \n userId,\n ...options \n}) => {\n\n const [isReady, setIsReady] = useState(GrowthRail.isInitialized());\n const initialized = useRef(false);\n\n useEffect(() => {\n if (initialized.current) return;\n initialized.current = true;\n\n GrowthRail.init(options);\n if (userId) {\n GrowthRail.initAppUser(userId).catch(console.error);\n }\n setIsReady(true);\n }, []);\n\n useEffect(() => {\n if (initialized.current && userId && GrowthRail.getUserId() !== userId) {\n GrowthRail.initAppUser(userId).catch(console.error);\n }\n }, [userId]);\n\n if (!isReady) return null;\n\n return <>{children}</>;\n};\n","import { useState, useCallback } from 'react';\nimport { GrowthRail, AppUserType, ReferrerTriggerButton } from '@growth-rail/core';\n\n/**\n * The return type of the useGrowthRail hook.\n */\nexport interface UseGrowthRailReturn {\n /** \n * Initializes a user in the GrowthRail system. \n * @param userId - Unique identifier for the user.\n */\n initAppUser: (userId: string) => Promise<AppUserType>;\n /** \n * Tracks a reward-eligible event for the current user.\n * @param eventName - Optional name of the event.\n */\n trackRewardEvent: (eventName?: string) => Promise<void>;\n /** \n * Manually triggers the referral dashboard modal.\n * @param options - Customization options for the modal.\n */\n showReferralDashboard: (options?: Parameters<typeof GrowthRail.showReferralDashboard>[0]) => void;\n /** \n * Manually shows or updates the floating referral trigger button.\n * @param options - Configuration for the button.\n */\n showFloatingButton: (options: Partial<ReferrerTriggerButton>) => void;\n /** Hides the floating referral trigger button. */\n hideFloatingButton: () => void;\n /** Whether an asynchronous operation (like init or track) is in progress. */\n isLoading: boolean;\n /** The last error that occurred during an operation. */\n error: Error | null;\n}\n\n/**\n * A hook that provides access to GrowthRail SDK methods and state.\n * \n * @returns An object containing methods to manage referrals and track state.\n * \n * @example\n * const { showReferralDashboard, trackRewardEvent } = useGrowthRail();\n */\nexport const useGrowthRail = (): UseGrowthRailReturn => {\n\n const [isLoading, setIsLoading] = useState(false);\n const [error, setError] = useState<Error | null>(null);\n\n const initAppUser = useCallback(async (userId: string) => {\n setIsLoading(true);\n setError(null);\n try {\n const user = await GrowthRail.initAppUser(userId);\n return user;\n } catch (err) {\n const error = err instanceof Error ? err : new Error(String(err));\n setError(error);\n throw error;\n } finally {\n setIsLoading(false);\n }\n }, []);\n\n const trackRewardEvent = useCallback(async (eventName?: string) => {\n setIsLoading(true);\n setError(null);\n try {\n await GrowthRail.trackRewardEvent(eventName);\n } catch (err) {\n const error = err instanceof Error ? err : new Error(String(err));\n setError(error);\n throw error;\n } finally {\n setIsLoading(false);\n }\n }, []);\n\n const showReferralDashboard = useCallback((options?: Parameters<typeof GrowthRail.showReferralDashboard>[0]) => {\n GrowthRail.showReferralDashboard(options);\n }, []);\n\n const showFloatingButton = useCallback((options: Partial<ReferrerTriggerButton>) => {\n GrowthRail.createTriggerButton(options);\n }, []);\n\n const hideFloatingButton = useCallback(() => {\n GrowthRail.destroyTriggerButton();\n }, []);\n\n return {\n initAppUser,\n trackRewardEvent,\n showReferralDashboard,\n showFloatingButton,\n hideFloatingButton,\n isLoading,\n error,\n };\n};\n","import React, { useEffect, useRef } from 'react';\nimport { GrowthRail, ReferrerModalOptions, ReferralModal, ReferrerExperience } from '@growth-rail/core';\n\n/**\n * Props for the ReferralDashboard component.\n */\nexport interface ReferralDashboardProps {\n /** Optional override for the dashboard title. */\n title?: string;\n /** Customization options for the dashboard's appearance. */\n appearance?: ReferrerModalOptions;\n /** Callback fired when the referral link is copied to the clipboard. */\n onLinkCopied?: () => void;\n}\n\n/**\n * An inline referral dashboard component.\n * Unlike the global modal, this component renders directly within your layout.\n * \n * @example\n * <div style={{ height: '500px' }}>\n * <ReferralDashboard title=\"Invite your team\" />\n * </div>\n */\nexport const ReferralDashboard: React.FC<ReferralDashboardProps> = ({\n title,\n appearance = {},\n onLinkCopied,\n}) => {\n\n const containerRef = useRef<HTMLDivElement>(null);\n const modalRef = useRef<ReferralModal | null>(null);\n\n useEffect(() => {\n let mounted = true;\n if (!containerRef.current) return;\n\n GrowthRail.ensureUserReady().then((user) => {\n if (!mounted || !containerRef.current) return;\n\n const deps = {\n isUserReady: () => GrowthRail.isUserReady(),\n getReferralLink: () => {\n try {\n return GrowthRail.getReferralLink();\n } catch {\n return '';\n }\n },\n };\n\n // Construct experience config directly from BE\n const experience: ReferrerExperience = {\n trigger: user.referrerExperience.trigger,\n modal: {\n ...user.referrerExperience.modal,\n ...(title ? { title } : {}),\n ...appearance,\n },\n };\n\n modalRef.current = new ReferralModal(deps, experience);\n modalRef.current.show(appearance, containerRef.current);\n }).catch((err) => {\n console.error('GrowthRail: User initialization failed', err);\n });\n\n return () => {\n mounted = false;\n if (modalRef.current) {\n modalRef.current.hide();\n modalRef.current = null;\n }\n };\n }, [title, appearance]);\n\n return (\n <div \n ref={containerRef} \n style={{ \n width: '100%', \n height: '100%', \n minHeight: '400px',\n position: 'relative' \n }} \n />\n );\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAA8D;AAC9D,kBAA8C;AAqDrC;AA5BF,IAAM,qBAAwD,CAAC;AAAA,EACpE;AAAA,EACA;AAAA,EACA,GAAG;AACL,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AAQ,EAAE,MAAM,IAAI,CAAC;AAAA,UACzB,GAAG;AAAA,QACL;AAAA,MACF;AAEA,eAAS,UAAU,IAAI,2BAAc,MAAM,UAAU;AACrD,eAAS,QAAQ,KAAK,YAAY,aAAa,OAAO;AAAA,IACxD,CAAC,EAAE,MAAM,CAAC,QAAQ;AAChB,cAAQ,MAAM,0CAA0C,GAAG;AAAA,IAC7D,CAAC;AAED,WAAO,MAAM;AACX,gBAAU;AACV,UAAI,SAAS,SAAS;AACpB,iBAAS,QAAQ,KAAK;AACtB,iBAAS,UAAU;AAAA,MACrB;AAAA,IACF;AAAA,EACF,GAAG,CAAC,OAAO,UAAU,CAAC;AAEtB,SACE;AAAA,IAAC;AAAA;AAAA,MACC,KAAK;AAAA,MACL,OAAO;AAAA,QACL,OAAO;AAAA,QACP,QAAQ;AAAA,QACR,WAAW;AAAA,QACX,UAAU;AAAA,MACZ;AAAA;AAAA,EACF;AAEJ;","names":["import_react","import_core","error","import_react","import_core","import_jsx_runtime"]}
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/GrowthRailProvider.tsx","../src/useGrowthRail.ts","../src/ReferralDashboard.tsx"],"sourcesContent":["import React, { useEffect, useRef, useState, ReactNode } from 'react';\nimport { GrowthRail, GrowthRailOptions } from '@growth-rail/core';\n\n/**\n * Props for the GrowthRailProvider component.\n */\ninterface GrowthRailProviderProps extends GrowthRailOptions {\n /** The unique ID for the current application user. */\n userId?: string;\n /** Your application components. */\n children: ReactNode;\n}\n\n/**\n * Root provider component for GrowthRail in React applications.\n * This component initializes the SDK and manages the user's authentication state.\n * \n * Wrap your app (or a specific feature tree) with this provider.\n * \n * @example\n * <GrowthRailProvider projectSecretKey=\"your-api-key\" userId=\"user-123\">\n * <App />\n * </GrowthRailProvider>\n */\nexport const GrowthRailProvider: React.FC<GrowthRailProviderProps> = ({ \n children, \n userId,\n ...options \n}) => {\n\n const [isReady, setIsReady] = useState(GrowthRail.isInitialized());\n const initialized = useRef(false);\n\n useEffect(() => {\n if (initialized.current) return;\n initialized.current = true;\n\n GrowthRail.init(options);\n if (userId) {\n GrowthRail.initAppUser(userId).catch(console.error);\n }\n setIsReady(true);\n }, []);\n\n useEffect(() => {\n if (initialized.current && userId && GrowthRail.getUserId() !== userId) {\n GrowthRail.initAppUser(userId).catch(console.error);\n }\n }, [userId]);\n\n if (!isReady) return null;\n\n return <>{children}</>;\n};\n","import { useState, useCallback } from 'react';\nimport { GrowthRail, AppUserType, ReferrerTriggerButton } from '@growth-rail/core';\n\n/**\n * The return type of the useGrowthRail hook.\n */\nexport interface UseGrowthRailReturn {\n /** \n * Initializes a user in the GrowthRail system. \n * @param userId - Unique identifier for the user.\n */\n initAppUser: (userId: string) => Promise<AppUserType>;\n /** \n * Tracks a reward-eligible event for the current user.\n * @param eventName - Optional name of the event.\n */\n trackRewardEvent: (eventName?: string) => Promise<void>;\n /** \n * Manually triggers the referral dashboard modal.\n * @param options - Customization options for the modal.\n */\n showReferralDashboard: (options?: Parameters<typeof GrowthRail.showReferralDashboard>[0]) => void;\n /** \n * Manually shows or updates the floating referral trigger button.\n * @param options - Configuration for the button.\n */\n showFloatingButton: (options: Partial<ReferrerTriggerButton>) => void;\n /** Hides the floating referral trigger button. */\n hideFloatingButton: () => void;\n /** Whether an asynchronous operation (like init or track) is in progress. */\n isLoading: boolean;\n /** The last error that occurred during an operation. */\n error: Error | null;\n}\n\n/**\n * A hook that provides access to GrowthRail SDK methods and state.\n * \n * @returns An object containing methods to manage referrals and track state.\n * \n * @example\n * const { showReferralDashboard, trackRewardEvent } = useGrowthRail();\n */\nexport const useGrowthRail = (): UseGrowthRailReturn => {\n\n const [isLoading, setIsLoading] = useState(false);\n const [error, setError] = useState<Error | null>(null);\n\n const initAppUser = useCallback(async (userId: string) => {\n setIsLoading(true);\n setError(null);\n try {\n const user = await GrowthRail.initAppUser(userId);\n return user;\n } catch (err) {\n const error = err instanceof Error ? err : new Error(String(err));\n setError(error);\n throw error;\n } finally {\n setIsLoading(false);\n }\n }, []);\n\n const trackRewardEvent = useCallback(async (eventName?: string) => {\n setIsLoading(true);\n setError(null);\n try {\n await GrowthRail.trackRewardEvent(eventName);\n } catch (err) {\n const error = err instanceof Error ? err : new Error(String(err));\n setError(error);\n throw error;\n } finally {\n setIsLoading(false);\n }\n }, []);\n\n const showReferralDashboard = useCallback((options?: Parameters<typeof GrowthRail.showReferralDashboard>[0]) => {\n GrowthRail.showReferralDashboard(options);\n }, []);\n\n const showFloatingButton = useCallback((options: Partial<ReferrerTriggerButton>) => {\n GrowthRail.createTriggerButton(options);\n }, []);\n\n const hideFloatingButton = useCallback(() => {\n GrowthRail.destroyTriggerButton();\n }, []);\n\n return {\n initAppUser,\n trackRewardEvent,\n showReferralDashboard,\n showFloatingButton,\n hideFloatingButton,\n isLoading,\n error,\n };\n};\n","import React, { useEffect, useRef } from 'react';\nimport { GrowthRail, ReferrerModalOptions, ReferralModal, ReferrerExperience } from '@growth-rail/core';\n\n/**\n * Props for the ReferralDashboard component.\n */\nexport interface ReferralDashboardProps {\n /** Optional override for the dashboard title. */\n title?: string;\n /** Customization options for the dashboard's appearance. */\n appearance?: ReferrerModalOptions;\n /** Callback fired when the referral link is copied to the clipboard. */\n onLinkCopied?: () => void;\n}\n\n/**\n * An inline referral dashboard component.\n * Unlike the global modal, this component renders directly within your layout.\n * \n * @example\n * <div style={{ height: '500px' }}>\n * <ReferralDashboard title=\"Invite your team\" />\n * </div>\n */\nexport const ReferralDashboard: React.FC<ReferralDashboardProps> = ({\n title,\n appearance = {},\n onLinkCopied,\n}) => {\n\n const containerRef = useRef<HTMLDivElement>(null);\n const modalRef = useRef<ReferralModal | null>(null);\n\n useEffect(() => {\n let mounted = true;\n if (!containerRef.current) return;\n\n GrowthRail.ensureUserReady().then((user) => {\n if (!mounted || !containerRef.current) return;\n\n const deps = {\n isUserReady: () => GrowthRail.isUserReady(),\n getReferralLink: () => {\n try {\n return GrowthRail.getReferralLink();\n } catch {\n return '';\n }\n },\n };\n\n // Construct experience config directly from BE\n const experience: ReferrerExperience = {\n trigger: user.referrerExperience.trigger,\n modal: {\n ...user.referrerExperience.modal,\n ...(title ? { title } : {}),\n ...appearance,\n },\n };\n\n modalRef.current = new ReferralModal(deps, experience);\n modalRef.current.show(appearance, containerRef.current);\n }).catch((err) => {\n console.error('GrowthRail: User initialization failed', err);\n });\n\n return () => {\n mounted = false;\n if (modalRef.current) {\n modalRef.current.hide();\n modalRef.current = null;\n }\n };\n }, [title, appearance]);\n\n return (\n <div \n ref={containerRef} \n style={{ \n width: '100%', \n height: '100%', \n minHeight: '400px',\n position: 'relative' \n }} \n />\n );\n};\n"],"mappings":";AAAA,SAAgB,WAAW,QAAQ,gBAA2B;AAC9D,SAAS,kBAAqC;AAmDrC;AA5BF,IAAM,qBAAwD,CAAC;AAAA,EACpE;AAAA,EACA;AAAA,EACA,GAAG;AACL,MAAM;AAEJ,QAAM,CAAC,SAAS,UAAU,IAAI,SAAS,WAAW,cAAc,CAAC;AACjE,QAAM,cAAc,OAAO,KAAK;AAEhC,YAAU,MAAM;AACd,QAAI,YAAY,QAAS;AACzB,gBAAY,UAAU;AAEtB,eAAW,KAAK,OAAO;AACvB,QAAI,QAAQ;AACV,iBAAW,YAAY,MAAM,EAAE,MAAM,QAAQ,KAAK;AAAA,IACpD;AACA,eAAW,IAAI;AAAA,EACjB,GAAG,CAAC,CAAC;AAEL,YAAU,MAAM;AACd,QAAI,YAAY,WAAW,UAAU,WAAW,UAAU,MAAM,QAAQ;AACtE,iBAAW,YAAY,MAAM,EAAE,MAAM,QAAQ,KAAK;AAAA,IACpD;AAAA,EACF,GAAG,CAAC,MAAM,CAAC;AAEX,MAAI,CAAC,QAAS,QAAO;AAErB,SAAO,gCAAG,UAAS;AACrB;;;ACrDA,SAAS,YAAAA,WAAU,mBAAmB;AACtC,SAAS,cAAAC,mBAAsD;AA0CxD,IAAM,gBAAgB,MAA2B;AAEtD,QAAM,CAAC,WAAW,YA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Rail","error","useEffect","useRef","GrowthRail","jsx"]}
|
|
1
|
+
{"version":3,"sources":["../src/GrowthRailProvider.tsx","../src/useGrowthRail.ts","../src/ReferralDashboard.tsx"],"sourcesContent":["import React, { useEffect, useRef, useState, ReactNode } from 'react';\nimport { GrowthRail, GrowthRailOptions } from '@growth-rail/core';\n\n/**\n * Props for the GrowthRailProvider component.\n */\ninterface GrowthRailProviderProps extends GrowthRailOptions {\n /** The unique ID for the current application user. */\n userId?: string;\n /** Your application components. */\n children: ReactNode;\n /** Whether to enable debug mode for verbose console logging. */\n debug?: boolean;\n}\n\n/**\n * Root provider component for GrowthRail in React applications.\n * This component initializes the SDK and manages the user's authentication state.\n * \n * Wrap your app (or a specific feature tree) with this provider.\n * \n * @example\n * <GrowthRailProvider projectSecretKey=\"your-api-key\" userId=\"user-123\">\n * <App />\n * </GrowthRailProvider>\n */\nexport const GrowthRailProvider: React.FC<GrowthRailProviderProps> = ({ \n children, \n userId,\n ...options \n}) => {\n\n const [isReady, setIsReady] = useState(GrowthRail.isInitialized());\n const initialized = useRef(false);\n\n useEffect(() => {\n if (initialized.current) return;\n initialized.current = true;\n\n GrowthRail.init(options);\n if (userId) {\n GrowthRail.initAppUser(userId).catch(console.error);\n }\n setIsReady(true);\n }, []);\n\n useEffect(() => {\n if (initialized.current && userId && GrowthRail.getUserId() !== userId) {\n GrowthRail.initAppUser(userId).catch(console.error);\n }\n }, [userId]);\n\n if (!isReady) return null;\n\n return <>{children}</>;\n};\n","import { useState, useCallback } from 'react';\nimport { GrowthRail, AppUserType, ReferrerTriggerButton } from '@growth-rail/core';\n\n/**\n * The return type of the useGrowthRail hook.\n */\nexport interface UseGrowthRailReturn {\n /** \n * Initializes a user in the GrowthRail system. \n * @param userId - Unique identifier for the user.\n */\n initAppUser: (userId: string) => Promise<AppUserType>;\n /** \n * Tracks a reward-eligible event for the current user.\n * @param eventName - Optional name of the event.\n */\n trackRewardEvent: (eventName?: string) => Promise<void>;\n /** \n * Manually triggers the referral dashboard modal.\n * @param options - Customization options for the modal.\n */\n showReferralDashboard: (options?: Parameters<typeof GrowthRail.showReferralDashboard>[0]) => void;\n /** \n * Manually shows or updates the floating referral trigger button.\n * @param options - Configuration for the button.\n */\n showFloatingButton: (options: Partial<ReferrerTriggerButton>) => void;\n /** Hides the floating referral trigger button. */\n hideFloatingButton: () => void;\n /** Whether an asynchronous operation (like init or track) is in progress. */\n isLoading: boolean;\n /** The last error that occurred during an operation. */\n error: Error | null;\n}\n\n/**\n * A hook that provides access to GrowthRail SDK methods and state.\n * \n * @returns An object containing methods to manage referrals and track state.\n * \n * @example\n * const { showReferralDashboard, trackRewardEvent } = useGrowthRail();\n */\nexport const useGrowthRail = (): UseGrowthRailReturn => {\n\n const [isLoading, setIsLoading] = useState(false);\n const [error, setError] = useState<Error | null>(null);\n\n const initAppUser = useCallback(async (userId: string) => {\n setIsLoading(true);\n setError(null);\n try {\n const user = await GrowthRail.initAppUser(userId);\n return user;\n } catch (err) {\n const error = err instanceof Error ? err : new Error(String(err));\n setError(error);\n throw error;\n } finally {\n setIsLoading(false);\n }\n }, []);\n\n const trackRewardEvent = useCallback(async (eventName?: string) => {\n setIsLoading(true);\n setError(null);\n try {\n await GrowthRail.trackRewardEvent(eventName);\n } catch (err) {\n const error = err instanceof Error ? err : new Error(String(err));\n setError(error);\n throw error;\n } finally {\n setIsLoading(false);\n }\n }, []);\n\n const showReferralDashboard = useCallback((options?: Parameters<typeof GrowthRail.showReferralDashboard>[0]) => {\n GrowthRail.showReferralDashboard(options);\n }, []);\n\n const showFloatingButton = useCallback((options: Partial<ReferrerTriggerButton>) => {\n GrowthRail.createTriggerButton(options);\n }, []);\n\n const hideFloatingButton = useCallback(() => {\n GrowthRail.destroyTriggerButton();\n }, []);\n\n return {\n initAppUser,\n trackRewardEvent,\n showReferralDashboard,\n showFloatingButton,\n hideFloatingButton,\n isLoading,\n error,\n };\n};\n","import React, { useEffect, useRef } from 'react';\nimport { GrowthRail, ReferrerModalOptions, ReferralModal, ReferrerExperience } from '@growth-rail/core';\n\n/**\n * Props for the ReferralDashboard component.\n */\nexport interface ReferralDashboardProps {\n /** Optional override for the dashboard title. */\n title?: string;\n /** Customization options for the dashboard's appearance. */\n appearance?: ReferrerModalOptions;\n /** Callback fired when the referral link is copied to the clipboard. */\n onLinkCopied?: () => void;\n}\n\n/**\n * An inline referral dashboard component.\n * Unlike the global modal, this component renders directly within your layout.\n * \n * @example\n * <div style={{ height: '500px' }}>\n * <ReferralDashboard title=\"Invite your team\" />\n * </div>\n */\nexport const ReferralDashboard: React.FC<ReferralDashboardProps> = ({\n title,\n appearance = {},\n onLinkCopied,\n}) => {\n\n const containerRef = useRef<HTMLDivElement>(null);\n const modalRef = useRef<ReferralModal | null>(null);\n\n useEffect(() => {\n let mounted = true;\n if (!containerRef.current) return;\n\n GrowthRail.ensureUserReady().then((user) => {\n if (!mounted || !containerRef.current) return;\n\n const deps = {\n isUserReady: () => GrowthRail.isUserReady(),\n getReferralLink: () => {\n try {\n return GrowthRail.getReferralLink();\n } catch {\n return '';\n }\n },\n };\n\n // Construct experience config directly from BE\n const experience: ReferrerExperience = {\n trigger: user.referrerExperience.trigger,\n modal: {\n ...user.referrerExperience.modal,\n ...(title ? { title } : {}),\n ...appearance,\n },\n };\n\n modalRef.current = new ReferralModal(deps, experience);\n modalRef.current.show(appearance, containerRef.current);\n }).catch((err) => {\n console.error('GrowthRail: User initialization failed', err);\n });\n\n return () => {\n mounted = false;\n if (modalRef.current) {\n modalRef.current.hide();\n modalRef.current = null;\n }\n };\n }, [title, appearance]);\n\n return (\n <div \n ref={containerRef} \n style={{ \n width: '100%', \n height: '100%', \n minHeight: '400px',\n position: 'relative' \n }} \n />\n );\n};\n"],"mappings":";AAAA,SAAgB,WAAW,QAAQ,gBAA2B;AAC9D,SAAS,kBAAqC;AAqDrC;AA5BF,IAAM,qBAAwD,CAAC;AAAA,EACpE;AAAA,EACA;AAAA,EACA,GAAG;AACL,MAAM;AAEJ,QAAM,CAAC,SAA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AAK,mBAAmB;AAAA,UAC3B,GAAI,QAAQ,EAAE,MAAM,IAAI,CAAC;AAAA,UACzB,GAAG;AAAA,QACL;AAAA,MACF;AAEA,eAAS,UAAU,IAAI,cAAc,MAAM,UAAU;AACrD,eAAS,QAAQ,KAAK,YAAY,aAAa,OAAO;AAAA,IACxD,CAAC,EAAE,MAAM,CAAC,QAAQ;AAChB,cAAQ,MAAM,0CAA0C,GAAG;AAAA,IAC7D,CAAC;AAED,WAAO,MAAM;AACX,gBAAU;AACV,UAAI,SAAS,SAAS;AACpB,iBAAS,QAAQ,KAAK;AACtB,iBAAS,UAAU;AAAA,MACrB;AAAA,IACF;AAAA,EACF,GAAG,CAAC,OAAO,UAAU,CAAC;AAEtB,SACE,gBAAAC;AAAA,IAAC;AAAA;AAAA,MACC,KAAK;AAAA,MACL,OAAO;AAAA,QACL,OAAO;AAAA,QACP,QAAQ;AAAA,QACR,WAAW;AAAA,QACX,UAAU;AAAA,MACZ;AAAA;AAAA,EACF;AAEJ;","names":["useState","GrowthRail","error","useEffect","useRef","GrowthRail","jsx"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@growth-rail/react",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.1",
|
|
4
4
|
"description": "Growth Rail React SDK",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"react-dom": ">=16.8"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@growth-rail/core": "^2.2.
|
|
32
|
+
"@growth-rail/core": "^2.2.1"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@growth-rail/eslint-config": "*",
|