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

pict-sessionmanager

v1.0.2

Published

A session management service for pict that handles authenticated REST requests across multiple security contexts.

Readme

Pict Session Manager

Authenticated REST session management for the Pict ecosystem. Manages multiple named sessions with automatic credential injection, configurable authentication flows, and domain-based request matching. Built on Pict's template engine, Manyfest address resolution, and the expression parser.

License: MIT


Features

  • Multi-Session Management - Maintain any number of named sessions with independent authentication state, credentials, and configuration
  • Automatic Credential Injection - Headers and cookies are injected into outgoing REST requests by matching the request URL against configured domain patterns
  • Template-Driven Configuration - URI templates, header value templates, and POST body templates use Pict's {~D:Record.Key~} syntax for dynamic resolution
  • Flexible Session Checks - Verify session validity with boolean markers, existence checks, or expression-based solves via the Pict ExpressionParser
  • Authentication Retry - Configurable retry count and debounce interval for failed authentication attempts
  • GET and POST Authentication - Support for GET-based (credentials in URL) and POST-based (credentials in request body) authentication flows
  • Header and Cookie Injection - Inject credentials as HTTP headers, cookies, or both
  • REST Client Integration - Connect to a Fable RestClient and transparently inject credentials on every request
  • Overridable Hooks - Customize session check processing, authentication response handling, and credential injection by subclassing

Documentation

Comprehensive documentation is available in the docs folder:

Installation

npm install pict-sessionmanager

Quick Start

const libPict = require('pict');
const libPictSessionManager = require('pict-sessionmanager');

// Create a Pict instance and register the SessionManager service
let tmpPict = new libPict();
tmpPict.serviceManager.addServiceType('SessionManager', libPictSessionManager);
tmpPict.serviceManager.instantiateServiceProvider('SessionManager');

// Add a session with header-based authentication
tmpPict.SessionManager.addSession('MyAPI',
	{
		Type: 'Header',
		AuthenticationURITemplate: '/api/login/{~D:Record.UserName~}/{~D:Record.Password~}',
		CheckSessionURITemplate: '/api/session/check',
		CheckSessionLoginMarkerType: 'boolean',
		CheckSessionLoginMarker: 'LoggedIn',
		HeaderName: 'Authorization',
		HeaderValueTemplate: 'Bearer {~D:Record.Token~}',
		DomainMatch: 'api.example.com'
	});

// Authenticate
tmpPict.SessionManager.authenticate('MyAPI',
	{ UserName: 'alice', Password: 'secret' },
	(pError, pSessionState) =>
	{
		if (pError) return console.error('Auth failed:', pError.message);
		console.log('Authenticated:', pSessionState.Authenticated);
	});

Automatic Credential Injection

Connect the session manager to the REST client so credentials are injected automatically on every matching request:

// Wire session manager into the REST client
tmpPict.SessionManager.connectToRestClient(tmpPict.RestClient);

// All requests to matching domains get session credentials injected
tmpPict.RestClient.getJSON({ url: 'https://api.example.com/data' },
	(pError, pResponse, pData) =>
	{
		// The Authorization header was automatically added
		console.log('Data:', pData);
	});

// Disconnect when done
tmpPict.SessionManager.disconnectRestClient();

Session Types

| Type | Injects | Use Case | |------|---------|----------| | Header | HTTP headers (e.g. Authorization) | Token-based REST APIs | | Cookie | HTTP cookies on the request | Cookie-based web applications | | Both | Headers and cookies | Hybrid authentication systems |

Session Check Markers

| Marker Type | Description | |-------------|-------------| | boolean | Resolve an address in the response and check truthiness | | existence | Check that the resolved value is not undefined or null | | solver | Evaluate a Pict ExpressionParser expression against the response |

Configuration

Sessions are configured with a plain object passed to addSession(). All options have sensible defaults:

tmpPict.SessionManager.addSession('MyAPI',
	{
		Type: 'Header',                    // 'Header', 'Cookie', 'Both'
		AuthenticationMethod: 'post',      // 'get' or 'post'
		AuthenticationURITemplate: '/login',
		AuthenticationRequestBody:
			{
				username: '{~D:Record.UserName~}',
				password: '{~D:Record.Password~}'
			},
		CheckSessionURITemplate: '/session/check',
		CheckSessionDebounce: 5000,        // ms between checks
		AuthenticationRetryCount: 3,
		AuthenticationRetryDebounce: 500,
		HeaderName: 'Authorization',
		HeaderValueTemplate: 'Bearer {~D:Record.Token~}',
		DomainMatch: 'api.example.com'
	});

See the Configuration Reference for all options.

Testing

npm test
npm run coverage

Part of the Retold Framework

Pict Session Manager is a service provider in the Pict ecosystem:

Related Packages

License

MIT

Contributing

Pull requests are welcome. For details on our code of conduct, contribution process, and testing requirements, see the Retold Contributing Guide.