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 🙏

© 2024 – Pkg Stats / Ryan Hefner

digest-fetch

v3.1.1

Published

digest auth request plugin for fetch/node-fetch also support http basic auth authentication

Downloads

4,490,513

Readme

digest-fetch

Join the chat at https://gitter.im/devfans/digest-fetch NPM Version NPM Downloads Test Coverage

digest auth request plugin for fetch/node-fetch also supports http basic authentication

Installation

For digest-fetch 3.0.0 or above

npm install digest-fetch@latest node-fetch@latest

For digest-fetch 2.0.3 or below

npm install digest-fetch@v2 node-fetch@v2

Get Started

// Use require for digest-fetch 2.0.3 or below
const DigestClient = require('digest-fetch')

// Use import
import DigestClient from "digest-fetch"

Typescript

For digest-fetch 3.0.0 or above

Since digest-fetch becomes ES module starting 3.0.0, you need to set your project as module to use import.

  • Specify "type": "module" in your package.json
  • Specify --esm for ts-node like npx ts-node --esm src/index.ts
  • Specify "module": "ESNext", "moduleResolution": "node" in your tsconfig.json
// Install dependencies
npm install digest-fetch@latest node-fetch@latest

// Import
import DigestClient from "digest-fetch"

For digest-fetch 2.0.3 or below

// Install dependencies
npm install digest-fetch@v2 node-fetch@v2

// Import
import DigestClient from "digest-fetch"

Http Basic Authentication

Create a client using basic authentication challenge

const client = new DigestClient('user', 'password', { basic: true })
client.fetch(url, options).then(res => res.json).then(console.dir)

Digest Access Authentication

Create a digest authentication request client with default options

const client = new DigestClient('user', 'password') 

Specify options for digest authentication

const client = new DigestClient('user', 'password', { algorithm: 'MD5' }) 

Supported Algorithm

['MD5', 'MD5-sess', 'SHA-256', 'SHA-256-sess', 'SHA-512-256', 'SHA-512-256-sess']

Options fields:

| field | type | default | description | | :------------- | :---------- | :-----------: | :---------- | | algorithm | string | 'MD5' | algorithm to be used: 'MD5', 'SHA-256', 'SHA-512-256' or with '-sess' | | statusCode | number | 401 | custom alternate authentication failure code for avoiding browser prompt, see details below | | cnonceSize | number | 32 | length of the cnonce | | logger | object | none | logger for debug, can use console, default no logging | | basic | bool | false | switch to use basic authentication | | precomputeHash | bool | false | wether to attach hash of credentials to the client instance instead of raw credential |

Details:

  • When using digest authentication in browsers, may encounter prompt window in foreground. Check: https://stackoverflow.com/questions/9859627/how-to-prevent-browser-to-invoke-basic-auth-popup-and-handle-401-error-using-jqu

Do request same way as fetch or node-fetch

const url = ''
const options = {}
client.fetch(url, options)
  .then(resp=>resp.json())
  .then(data=>console.log(data))
  .catch(e=>console.error(e))

Pass in refresh request options factory function for conditions options needs be refreshed when trying again. For example when posting with file stream:

const factory = () => ({ method: 'post', body: fs.createReadStream('path-to-file') })
client.fetch(url, {factory})
  .then(resp=>resp.json())
  .then(data=>console.log(data))
  .catch(e=>console.error(e))

About

Digest authentication: https://en.wikipedia.org/wiki/Digest_access_authentication or https://www.rfc-editor.org/rfc/rfc7616 This plugin is implemented following RFC2069, RFC2617 and RFC7616 supports http basic authentication as well!

Please open issues if you find bugs or meet problems during using this plugin. Feel free to open PRs whenever you have better ideas on this project!