@geejay/use-feature-flags 1.0.8 → 1.0.9

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.
@@ -1,11 +1,13 @@
1
1
  import { useEffect, useRef, useState } from 'react';
2
2
  import { createClient } from '@supabase/supabase-js';
3
+ import { featureFlagsAtom } from './store';
4
+ import { useAtom } from 'jotai';
3
5
  export const DEFAULT_SUPABASE_URL = 'https://khppgsehvvlukzfdqbuo.supabase.co';
4
6
  export const DEFAULT_SUPABASE_KEY = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImtocHBnc2VodnZsdWt6ZmRxYnVvIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NTI2ODU1MzQsImV4cCI6MjA2ODI2MTUzNH0.8Z4VY4HFMm95UgO21c-DnDkbLPN_0mbDBZJPExaghDk';
5
7
  const EDGE_FN_URL = `${DEFAULT_SUPABASE_URL}/functions/v1/get-feature-flags`;
6
8
  let initialized = false;
7
9
  export function useFeatureFlags(passedKey, environment = 'localhost') {
8
- const [state, setState] = useState({ flags: [], loading: true });
10
+ const [state, setState] = useAtom(featureFlagsAtom);
9
11
  const [envId, setEnvId] = useState(null);
10
12
  const debounceTimeout = useRef(null);
11
13
  const cleanupRef = useRef();
@@ -36,6 +38,7 @@ export function useFeatureFlags(passedKey, environment = 'localhost') {
36
38
  }
37
39
  const flags = json.flags || [];
38
40
  setState({ flags, loading: false });
41
+ console.log(`Flags are cool man ${JSON.stringify(flags)}`);
39
42
  // Store environment_id from first flag (assumes all have same env)
40
43
  if (flags.length > 0 && flags[0].environment_id) {
41
44
  setEnvId(flags[0].environment_id);
@@ -85,7 +88,7 @@ export function useFeatureFlags(passedKey, environment = 'localhost') {
85
88
  };
86
89
  }, [envId]);
87
90
  return {
88
- isActive: (key) => state.flags.some((f) => f.key === key && f.enabled),
91
+ isActive: (key) => state.flags.some((f) => f.key === key && f.enabled === true),
89
92
  flags: state.flags,
90
93
  loading: state.loading,
91
94
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geejay/use-feature-flags",
3
- "version": "1.0.8",
3
+ "version": "1.0.9",
4
4
  "description": "React hook for feature flag management using Supabase",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",