newsource-token-caching-manager

1.1.2 • Public • Published

newsource-token-caching-manager

Installation

~$: npm install --save newsource-token-caching-manager

Usage

To create an instance of the token caching manager you will need to provide a url, a string name for the cache location, a string name of the expiration key, a string name of the token key, and an optional api method type. When called successfully will return an async function that can be used to retrive a token from cache or an api.

const { createTokenManager } = require("newsource-token-caching-manager");
const tokenRetriever = createTokenManager({
  url: "url goes here, required",
  cacheName: "cache name goes here, required",
  expirationParameter: "object key of expiration retrieved from api, required",
  tokenParameter: "object key of token retreived from api, required",
  methodType: "optional api method type goes here (eg., post, get)"
});
const token = await tokenRetreiver();

// You may also pass in a forceRetrieve flag to tokenRetriever to get a new token from api and write it to cache

const newToken = await tokenRetriever(true);

Readme

Keywords

Package Sidebar

Install

npm i newsource-token-caching-manager

Weekly Downloads

13

Version

1.1.2

License

ISC

Unpacked Size

13.1 kB

Total Files

10

Last publish

Collaborators

  • mss-npm-user