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

dis-authorisation-client-js

v1.0.1

Published

JS library for client side token renewal

Readme

dis-authorisation-client-js

JS library for client side token renewal

Getting started

  • Run make help to see full list of make targets

Usage

  1. Initialising with custom configuration. You can call init with a custom config, this allows you to specify callbacks and settings. See defaultConfig below for more details on what is provided in the default config:
import SessionManagement from 'dis-authorisation-client-js';

// Define configuration
const config = {
  timeOffsets: { passiveRenewal: 300000 }, // Session renewal offset: 5 minutes
  onRenewSuccess: (sessionExpiryTime, refreshExpiryTime) => {
    console.debug(`[APP] Session renewed successfully! Session: ${sessionExpiryTime} and refresh: ${refreshExpiryTime}`);
  },
  onRenewFailure: (error) => {
    console.error('[APP] Session renewal failed:', error);
  },
  onSessionValid: (sessionExpiryTime, refreshExpiryTime) => {
    console.debug(`[APP] Session is valid. Session: ${sessionExpiryTime} and refresh: ${refreshExpiryTime}`);
  },
  onSessionInvalid: () => {
    console.warn('[APP] Session is invalid.');
  },
  onError: (error) => {
    console.error('[APP] Error:', error);
  },
};

// Initialise the SessionManagement library
SessionManagement.init(config);
  1. Setting Session Expiry Times. You can set the session and refresh expiry times either by creating default expiry times using createDefaultExpiryTimes or by setting them directly. If init has not been called yet, the library will automatically initialise with default settings.

Using createDefaultExpiryTimes

You can create default expiry times for session and refresh using createDefaultExpiryTimes:

import SessionManagement, { createDefaultExpiryTimes } from 'dis-authorisation-client-js';

// Create default expiry times
const { session_expiry_time, refresh_expiry_time } = createDefaultExpiryTimes(12); // 12 hours

// Set the expiry timers
SessionManagement.setSessionExpiryTime(session_expiry_time, refresh_expiry_time);

Setting Expiry Times Directly

You can manually set the session and refresh expiry times using setSessionExpiryTime.

import SessionManagement from 'dis-authorisation-client-js';

// Define session and refresh expiry times
const sessionExpiryTime = new Date(new Date().getTime() + 60 * 60 * 1000); // 1 hour from now
const refreshExpiryTime = new Date(new Date().getTime() + 24 * 60 * 60 * 1000); // 24 hours from now

// Set the expiry timers
SessionManagement.setSessionExpiryTime(sessionExpiryTime, refreshExpiryTime);

Note

If expiry times are found in local storage or cookies, those times will be used by default, even if provided times are not. You can also call setSessionExpiryTime without providing times, and the library will use the times found in local storage or cookies. To check if times need to be provided or not, you can use isSessionValid.

import { isSessionExpired } from 'dis-authorisation-client-js';

async function renewSession() {
  const isExpired = await isSessionExpired();

  if (isExpired) {
    // Define session and refresh expiry times
    const sessionExpiryTime = new Date(new Date().getTime() + 60 * 60 * 1000); // 1 hour from now
    const refreshExpiryTime = new Date(new Date().getTime() + 24 * 60 * 60 * 1000); // 24 hours from now

    // Set the expiry timers
    SessionManagement.setSessionExpiryTime(sessionExpiryTime, refreshExpiryTime);
  } else {
    SessionManagement.setSessionExpiryTime();
  }
}

Dependencies

  • No further dependencies other than those defined in package.json

Configuration

defaultConfig

| Option | Type | Default Value | Description | |---------------------|----------|---------------|-----------------------------------------------------------------------------| | timeOffsets | Object | { passiveRenewal: 300000 } | Time offsets for session renewal in milliseconds. | | onRenewSuccess | Function | (sessionExpiryTime, refreshExpiryTime) => console.debug('[LIBRARY] Session renewed successfully. Session: ${sessionExpiryTime} and refresh: ${refreshExpiryTime}') | Callback function to be called on successful session renewal. | | onRenewFailure | Function | () => console.warn('[LIBRARY] Session renewal failed') | Callback function to be called on session renewal failure. | | onSessionValid | Function | (sessionExpiryTime, refreshExpiryTime) => console.debug('[LIBRARY] Session Valid. Session: ${sessionExpiryTime} and refresh: ${refreshExpiryTime}') | Callback function to be called when the session is valid. | | onSessionInvalid | Function | () => console.warn('[LIBRARY] Session is invalid') | Callback function to be called when the session is invalid. | | apiEndpoints | String | { renewSession: "/api/v1/tokens/self" } | The API endpoint for renewing the session. | |

Contributing

See CONTRIBUTING for details.

License

Copyright © 2024, Office for National Statistics (https://www.ons.gov.uk)

Released under MIT license, see LICENSE for details.