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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@bedrock/web-session

v6.0.0

Published

Session management for Bedrock Web Apps

Readme

bedrock-web-session

Session management for Bedrock Web Apps

About

This module exports a function to create a singleton Session instance that is shared across an entire web application. The singleton instance is exposed via the exported session symbol. This instance represents the current state that binds asynchronous communications between the client and the server, i.e., the server uses a session to link requests together as coming from the same client and may store data associated with that client as "session data".

The most commonly stored "session data" is an identifier, e.g., an account ID, that can be used to link users across multiple sessions. This sort of information will only be present in session data if the user authenticates with the server (using some APIs / methods that are external to this library).

The current session may be ended (severing the above linkage and connection to the current session's data) by calling end() on the session instance or at any time by the server, e.g., if a session expires.

If the server ends the session or changes its data in any way, this can only be detected by calling refresh() on the session instance. This call will retrieve the latest session data from the server, which may have changed. If the data has changed, then a change event will be emitted to any listeners that have registered with the session instance via the on() method. This event will include the old session data and the new session data. If a call to end() is made, then a change event will also be emitted and it will include an oldEnded boolean that indicates that the old session ended.

If the server has ended a session, then this property will not be set on a change event, a listener will need to determine its behavior based on the available session data as this library cannot automatically determine if a session is new or not.

Usage

npm install bedrock-web-session
import {createSession, session} from 'bedrock-web-session';

async someInitializingFunction() {
  // the session instance is now ready
  await createSession();
}

async someOtherFunctionCalledLater() {
  console.log('session data from backend', session.data);
  console.log('session id from backend: ', session.data.id);

  // listen for changes to the session
  session.on('change', async function({oldEnded, oldData, newData}) {
    // either the old session ended (`oldEnded === true`) or `oldData` does
    // not deep equal `newData`, inspect and take action,
    // such as clearing data associated with a previously authenticated user
  });

  // ... some time later, refresh the session to get updated data from the
  // server that is linked to the client; this will cause all `change`
  // listeners to be called *if* the new session data does not match the
  // old session data
  await session.refresh();

  // ... some time later, sever the linkage between the client and server
  // by ending the session; cause the server to see the client as new and
  // trigger `change` listeners (which will receive `oldEnded === true`)
  await session.end();
}