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

@dna-codes/dna-react

v0.1.0

Published

React bindings for DNA — DnaProvider, Operation gate, and useOperation hook for authorization, feature flags, and audit logging.

Readme

@dna-codes/dna-react

React bindings for DNA — authorization gates, audit capture, and feature flag integration driven by your operational DNA document.

Installation

npm install @dna-codes/dna-react

Peer dependencies: react >= 18, react-dom >= 18.

Quick start

import { DnaProvider, Operation, useOperation } from '@dna-codes/dna-react'
import operationalDna from './dna/lending/operational.json'

function App() {
  return (
    <DnaProvider
      dna={operationalDna}
      userId="alice"
      roles={["Underwriter"]}
      onAudit={event => console.log(event)}
    >
      <LoanActions />
    </DnaProvider>
  )
}

// Declarative gate — renders children only if the current user is permitted
function LoanActions() {
  return (
    <Operation name="Loan.Approve" fallback={<span>No access</span>}>
      <ApproveButton />
    </Operation>
  )
}

// Imperative hook — for perform() and direct permitted checks
function ApproveButton() {
  const { permitted, perform } = useOperation('Loan.Approve')

  async function handleClick() {
    const { permitted } = await perform({ loanId: 'LOAN-001' })
    if (!permitted) return
    // call your API here
  }

  return <button onClick={handleClick} disabled={!permitted}>Approve</button>
}

API

<DnaProvider>

Context root. All <Operation> and useOperation calls must be descendants.

| Prop | Type | Required | Description | |---|---|---|---| | dna | OperationalDNA | ✓ | The operational DNA document | | userId | string | ✓ | Current user's identifier | | roles | string[] | one of three | Pre-resolved role names (sync, SSR-safe) | | resolveRoles | (userId) => Promise<string[]> | one of three | Async role resolver (bridges any auth system) | | store | DnaDataStore | one of three | Resolve roles via link traversal | | onAudit | (event: AuditEvent) => void | | Audit sink — called on every perform(), fire-and-forget | | flags | (opName: string) => boolean \| Promise<boolean> | | Feature flag resolver |

<Operation>

Declarative rendering gate. Renders children when the current user is permitted and the flag resolver returns true. Renders fallback otherwise.

<Operation
  name="Loan.Approve"
  fallback={<span>No access</span>}
  loading={<Skeleton />}
>
  <ApproveButton />
</Operation>

| Prop | Type | Default | Description | |---|---|---|---| | name | string | required | Operation name (e.g. "Loan.Approve") | | fallback | ReactNode | null | Rendered when gate is closed | | loading | ReactNode | null | Rendered while roles or flags are resolving |

useOperation(name)

Imperative hook. Returns { permitted, perform }.

const { permitted, perform } = useOperation('Loan.Approve')

// Check permission directly
if (!permitted) return null

// Call perform() when the user acts — fires audit before returning
const { permitted } = await perform({ loanId })
  • permitted — reactive boolean. true when the current user has an allowed role.
  • perform(payload?) — re-checks permission, fires onAudit, returns Promise<{ permitted: boolean }>.

AuditEvent

Emitted by perform() to the onAudit sink.

type AuditEvent = {
  operation: string    // "Loan.Approve"
  resource:  string    // "Loan"
  action:    string    // "Approve"
  userId:    string
  timestamp: string    // ISO 8601
  permitted: boolean
  payload?:  unknown   // value passed to perform()
}

Two-gate model

<Operation> combines two independent gates:

| Gate | Source | Closed when | |---|---|---| | Permission | DNA access rules + resolved roles | user's roles not in the allow list | | Feature flag | flags resolver | resolver returns false |

Both must be open for children to render.

Audit

onAudit is fire-and-forget. The sink receives every perform() call — permitted and blocked alike. Errors thrown by the sink are swallowed. Use this for UI analytics or console logging; authoritative audit logs should be written server-side when your API validates the operation.

Example app

See examples/react-app/ for a Vite + React demo using the lending DNA with a user-switcher and mock API.