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

@mitralab.io/feature-flags-sdk-react

v1.0.0

Published

Feature flag SDK for Mitra React applications

Readme

Mitra Feature Flags SDK React

SDK para carregar feature flags em aplicações React da Mitra e avaliá-las localmente. Cada frontend informa seu serviceName, recebe somente flags cujo serviceNames contém explicitamente esse frontend e mantém o último snapshot válido em memória e no localStorage.

Instalação

npm install @mitralab.io/feature-flags-sdk-react

Provider

import { FeatureFlagsProvider } from "@mitralab.io/feature-flags-sdk-react"
import { useCallback } from "react"

export function AppProviders({ children }: { children: React.ReactNode }) {
  const { getAccessToken } = useAuth()
  const tokenProvider = useCallback(() => getAccessToken(), [getAccessToken])

  return (
    <FeatureFlagsProvider
      serviceName="mitra-web"
      tokenProvider={tokenProvider}
      baseUrl={import.meta.env.VITE_API_URL}
    >
      {children}
    </FeatureFlagsProvider>
  )
}

O tokenProvider pode retornar o JWT atual de forma síncrona ou assíncrona. Mantenha a função estável com useCallback, pois uma nova referência recria o client e reinicia o polling. O endpoint de snapshot é autenticado e o ambiente é definido pelo backend, então o frontend não envia environment nem secret interno. O serviceName usa lower kebab case e aceita até 100 caracteres.

Flags e Hooks

import {
  booleanFlag,
  stringListFlag,
  useBooleanFlag,
  useStringListFlag,
} from "@mitralab.io/feature-flags-sdk-react"

const EMBEDDED_IDE = booleanFlag("EMBEDDED_IDE", false)
const TENANTS_IN_ROLLOUT = stringListFlag("TENANTS_IN_ROLLOUT")

function Editor({ tenantId }: { tenantId: string }) {
  const embeddedIde = useBooleanFlag(EMBEDDED_IDE)
  const rollout = useStringListFlag(TENANTS_IN_ROLLOUT)

  if (!embeddedIde || !rollout.includes(tenantId)) return null
  return <EmbeddedIde />
}

Use um serviceName diferente para cada aplicação, como mitra-web e mitra-backoffice. O endpoint de browser devolve apenas flags cujo serviceNames contém esse nome. Flags com serviceNames: null são globais para consumidores internos e não entram no snapshot entregue ao browser.

Nomes de flags usam UPPER_SNAKE_CASE e aceitam até 100 caracteres.

Cache e Falhas

  • Avaliação acontece somente em memória, sem I/O durante render.
  • O SDK atualiza o snapshot em segundo plano a cada 60 segundos por padrão.
  • refreshJitterMs adiciona de 0 até 10 segundos de variação por padrão depois de cada atualização, evitando que várias abas sincronizem as chamadas. Use 0 para desativar.
  • Requests que excedem 3 segundos são abortados por padrão; requestTimeoutMs permite ajustar esse limite.
  • ETag evita baixar payload sem alteração.
  • Payload inválido, falha HTTP ou token ausente preserva o último snapshot válido.
  • O cache do localStorage é validado antes do uso e pode ser desativado com storage={null}.
  • O polling e requests pendentes são limpos quando o provider desmonta.

Feature flag no browser controla experiência visual, nunca autorização. APIs continuam responsáveis por validar permissões e regras de negócio no servidor.

Desenvolvimento

npm run lint
npm run format:check
npm run typecheck
npm test
npm run build