npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@tahag/react-native-feature-system

v1.0.0

Published

Cache-first entitlements and feature flags for React Native

Readme

@tahag/react-native-feature-system

Cache-first entitlements and feature flags for React Native. Owns the caching, hook lifecycle, and foreground refetch. You plug in your own fetchers — Supabase, Firebase, REST, anything.

Install

npm install @tahag/react-native-feature-system

Peer dependencies (you likely already have these)

npm install @react-native-async-storage/async-storage react-native-get-random-values uuid

Migration from inline implementation

App.tsx — initFlags

Before

import { initFlags, refreshBucketingId } from './lib/flags/flagsStore'

initFlags().catch(console.warn)

After

import { initFlags, refreshBucketingId } from '@tahag/react-native-feature-system'
import { supabase } from './lib/supabase'

initFlags({
  fetcher: async () => {
    const { data, error } = await supabase
      .from('feature_flags')
      .select('key, value, rules')
    if (error) throw error
    return data
  },
  getUserId: async () => {
    const { data: { user } } = await supabase.auth.getUser()
    return user?.id ?? null
  },
}).catch(console.warn)

refreshBucketingId import path changes but the call site is identical:

await refreshBucketingId()

App.tsx — clearCachedEntitlements on sign out

Before

import { clearCachedEntitlements } from './lib/entitlements/useEntitlement'

After

import { clearCachedEntitlements } from '@tahag/react-native-feature-system'

Call site is identical:

await clearCachedEntitlements(activeProfile.uid)

HomeScreen.tsx — useFlag

Before

import { useFlag } from '../lib/flags/useFlag'

const showWelcomeBanner = useFlag('show_welcome_banner', false)

After

import { useFlag } from '@tahag/react-native-feature-system'

const showWelcomeBanner = useFlag('show_welcome_banner', false)

No call site changes.


HomeScreen.tsx — useEntitlement

Before

import { useEntitlement } from '../lib/entitlements/useEntitlement'

const { granted: hasProFeature, loading: entitlementLoading } = useEntitlement(
  'demo.pro_feature',
  activeProfile?.uid ?? null
)

After

import { useEntitlement } from '@tahag/react-native-feature-system'
import { supabase } from '../lib/supabase'

const { granted: hasProFeature, loading: entitlementLoading } = useEntitlement(
  'demo.pro_feature',
  {
    userId: activeProfile?.uid ?? null,
    fetcher: async (userId) => {
      const { data, error } = await supabase
        .from('user_entitlements')
        .select('capability')
        .eq('user_id', userId)
      if (error) throw error
      return data.map((row: { capability: string }) => row.capability)
    },
  }
)

API

initFlags(options)

Call once at app startup.

initFlags({
  fetcher: () => Promise<FlagRow[]>,       // required — fetch all flags from your backend
  getUserId?: () => Promise<string | null>, // optional — auth user ID for bucketing; falls back to anon UUID
  cacheKey?: string,                        // default: 'flags.cache.v1'
  anonIdKey?: string,                       // default: 'flags.anon_id'
})

refreshBucketingId()

Call after auth state changes so percent rollouts re-evaluate against the signed-in user.

await refreshBucketingId()

useFlag(key, defaultValue)

const showBanner = useFlag('show_welcome_banner', false)

useEntitlement(capability, options)

const { granted, loading } = useEntitlement('pro_feature', {
  userId: string | null,
  fetcher: (userId: string) => Promise<string[]>,
  cacheKeyPrefix?: string,     // default: 'entitlements.cache'
  cacheVersion?: string,       // default: 'v1'
  refetchOnForeground?: boolean // default: true
})

clearCachedEntitlements(userId)

Call on sign out to clear the entitlements cache for that user.

await clearCachedEntitlements(activeProfile.uid)

Caching behaviour

Both entitlements and flags use a cache-then-refresh strategy:

  1. On mount — serve from AsyncStorage immediately (no loading flash if cache exists)
  2. In background — fetch fresh from your backend and update cache + state
  3. On foreground — re-fetch when app returns to active state (configurable via refetchOnForeground)

Flags — percent rollouts

Flags support percent rollout rules out of the box. The bucketing uses FNV1a hashing on flagKey:bucketingId which is stable per user and requires no backend calls to evaluate.

// Flag row shape your fetcher should return
{
  key: 'new_onboarding',
  value: false,       // default value
  rules: {
    type: 'percent',
    percent: 20,      // show to 20% of users
    value: true       // value for users in the bucket
  }
}