luxlabs 1.0.9 → 1.0.10

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "luxlabs",
3
- "version": "1.0.9",
3
+ "version": "1.0.10",
4
4
  "description": "CLI tool for Lux - Upload and deploy interfaces from your terminal",
5
5
  "author": "Jason Henkel <jason@uselux.ai>",
6
6
  "license": "SEE LICENSE IN LICENSE",
@@ -10,9 +10,33 @@ const POSTHOG_HOST = process.env.NEXT_PUBLIC_POSTHOG_HOST || 'https://us.i.posth
10
10
  const LUX_INTERFACE_ID = process.env.NEXT_PUBLIC_LUX_INTERFACE_ID
11
11
  const LUX_ORG_ID = process.env.NEXT_PUBLIC_LUX_ORG_ID
12
12
 
13
+ /**
14
+ * Parse Lux Studio flag overrides from URL query params.
15
+ * When previewing A/B test variants in Lux Studio, the preview URL includes
16
+ * ?__lux_flag_overrides={"flag-key":"variant-key"} to force specific variants.
17
+ */
18
+ function getLuxFlagOverrides(): Record<string, string> | undefined {
19
+ if (typeof window === 'undefined') return undefined
20
+
21
+ try {
22
+ const params = new URLSearchParams(window.location.search)
23
+ const overrides = params.get('__lux_flag_overrides')
24
+ if (overrides) {
25
+ const parsed = JSON.parse(overrides)
26
+ console.log('[PostHog] Lux Studio flag overrides detected:', parsed)
27
+ return parsed
28
+ }
29
+ } catch (e) {
30
+ console.warn('[PostHog] Failed to parse __lux_flag_overrides:', e)
31
+ }
32
+ return undefined
33
+ }
34
+
13
35
  export function PostHogProvider({ children }: { children: React.ReactNode }) {
14
36
  const initialized = useRef(false)
37
+ const searchParams = useSearchParams()
15
38
 
39
+ // Initialize PostHog once
16
40
  useEffect(() => {
17
41
  if (!POSTHOG_KEY || initialized.current) {
18
42
  if (!POSTHOG_KEY) {
@@ -40,6 +64,22 @@ export function PostHogProvider({ children }: { children: React.ReactNode }) {
40
64
  initialized.current = true
41
65
  }, [])
42
66
 
67
+ // Apply Lux Studio flag overrides whenever URL changes
68
+ // This uses posthog.featureFlags.override() which works even after init
69
+ useEffect(() => {
70
+ if (!POSTHOG_KEY) return
71
+
72
+ const flagOverrides = getLuxFlagOverrides()
73
+ if (flagOverrides) {
74
+ // Override feature flags for Lux Studio preview
75
+ posthog.featureFlags.override(flagOverrides)
76
+ console.log('[PostHog] Applied Lux Studio flag overrides:', flagOverrides)
77
+ } else {
78
+ // Clear any previous overrides when not in preview mode
79
+ posthog.featureFlags.override(false)
80
+ }
81
+ }, [searchParams])
82
+
43
83
  if (!POSTHOG_KEY) {
44
84
  return <>{children}</>
45
85
  }