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

@sidneyroberto9/sentret-react

v1.0.0

Published

Browser client for the sentret inactivity hub: heartbeat, status poll, expiry warning and cross-tab sync, with React bindings.

Readme

@sidneyroberto9/sentret-react

Browser client for the sentret inactivity hub served by @sidneyroberto9/sentret-fastify (or by the Java sentret-session, same wire contract). It sends a throttled heartbeat on user activity, polls the session status, shows an expiry warning with a countdown, and keeps every tab in sync. The session cookie is HttpOnly: the client never reads it, it only calls the hub with credentials: 'include'.

Install

npm install @sidneyroberto9/sentret-react

Requires React 18+.

Usage (Vite)

import { SentretProvider } from '@sidneyroberto9/sentret-react'

createRoot(document.getElementById('root')!).render(
  <SentretProvider
    hubUrl={import.meta.env.VITE_API_URL + '/session'}
    appLogoutUrl={import.meta.env.VITE_API_URL + '/auth/logout'}
  >
    <App />
  </SentretProvider>,
)
import { useSentret } from '@sidneyroberto9/sentret-react'

function LoginForm() {
  const { refresh } = useSentret()

  async function onSubmit(credentials: { email: string; password: string }) {
    await fetch(import.meta.env.VITE_API_URL + '/auth/login', {
      method: 'POST',
      credentials: 'include',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify(credentials),
    })
    await refresh() // the provider flips to authenticated now, no waiting for the poll
  }
  // ...
}

function Header() {
  const { user, authenticated, logout } = useSentret()
  if (!authenticated) return null
  return <button onClick={() => void logout()}>Sign out {user?.email}</button>
}

useSentret() returns { status, user, authenticated, warning, renew, logout, refresh } and throws outside a <SentretProvider>. user is { userId, email? } | null.

Every API call (fetch or axios) must send the cookie: credentials: 'include' for fetch, withCredentials: true for axios. Your API also needs CORS with credentials: true for your origin.

Provider props

| Prop | Description | |---|---| | hubUrl | Full hub base URL, e.g. https://api.example.com/session. /status, /heartbeat and /renew are appended; trailing slashes are stripped. | | appLogoutUrl | Your own logout endpoint. POSTed (with credentials) before redirecting when the session ends. | | renderWarning | Replaces the warning card. Receives { remainingMs, remainingSeconds, formattedRemaining, cause, renew }. | | labels | Overrides the default card copy (title, message, continueLabel; pt-BR by default). |

<SentretProvider
  hubUrl={url}
  labels={{ title: 'Session expiring', message: 'You will be signed out in', continueLabel: 'Stay signed in' }}
/>

<SentretProvider
  hubUrl={url}
  renderWarning={({ formattedRemaining, renew }) => (
    <Dialog>
      Signing out in {formattedRemaining} <button onClick={renew}>Stay</button>
    </Dialog>
  )}
/>

Behaviour

  • Timings (heartbeatIntervalMs, statusPollIntervalMs, warningBeforeMs) and loginUrl come from the hub; nothing is hardcoded in the client.
  • The heartbeat fires on mouse, keyboard, touch and scroll activity, leading-edge throttled.
  • The status poll is the authority. When the hub reports the user is no longer authenticated (after having been authenticated), the client terminates once: broadcasts to other tabs, POSTs appLogoutUrl, redirects to loginUrl if the hub has one. An anonymous first status never redirects, so the login page does not loop.
  • While the warning is shown, activity does not heartbeat: only renew() dismisses it.
  • Tabs sync through a BroadcastChannel named sentret-session (logout and renew propagate).
  • After logout() (or an expiry) the client is finished. Remount the provider, or let the redirect to loginUrl reload the page, before logging in again.

Core without React

SentretClient / createSentretClient({ hubUrl, appLogoutUrl, listeners }) is exported for other frameworks: start(), stop(), renew(), logout(), refresh(), notifyActivity().

License

MIT