Registry / security / with-digest-fetch

with-digest-fetch

JSON →
library0.7.0jsnpmunverified

A lightweight library for HTTP Digest Authentication, compatible with both the Fetch API and node-fetch. Version 0.7.0 (stable, with regular releases) provides both ESM and CJS bundles, as well as TypeScript declarations. Forked from digest-fetch to add multi-format module support and improved TypeScript integration. Ideal for Node.js environments that need to authenticate against HTTP Digest servers with minimal overhead, offering a simple client that wraps fetch calls.

npm install with-digest-fetch
INSTALL
IMPORT
SIG · WITH-DIGEST-FETCH
W
with-digest-fetch
securityjavascriptv0.7.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

DigestClient
✓ import DigestClient from 'with-digest-fetch'
✗ const DigestClient = require('with-digest-fetch')
Default import only; the module exports a single class. CommonJS users should use the default import syntax in TypeScript or 'const DigestClient = require('with-digest-fetch').default' with esModuleInterop.
DigestClientOptions
✓ import type { DigestClientOptions } from 'with-digest-fetch'
TypeScript users can import the options interface for better type safety.
DigestAuthContext
✓ import type { DigestAuthContext } from 'with-digest-fetch'
TypeScript type for the internal auth context; rarely needed but available.

Creates a DigestClient with credentials and fetches a protected URL, printing the response.

import DigestClient from 'with-digest-fetch'; import fetch from 'node-fetch'; async function main() { const client = new DigestClient('user', 'password', { algorithm: 'MD5' }); const url = 'https://httpbin.org/digest-auth/auth/user/password/MD5'; const response = await client.fetch(url, { method: 'GET' }); console.log(await response.text()); } main().catch(console.error);
Debug
Known issues
gotchaThe client expects the fetch function to be compatible with the standard Response object. Using older versions of node-fetch (<=2.x) may require explicit import.
fix
Ensure node-fetch is installed and imported if using Node <18.
affects: >=0.0.0
breakingThe package switched from digest-fetch's CommonJS-only to dual ESM/CJS. Consumers using require() without esModuleInterop may need to access .default.
fix
Use import syntax or set esModuleInterop: true in tsconfig.json and use require('with-digest-fetch').default.
affects: >=0.0.0
deprecatedThe 'auth' option in fetch is not used; authentication is handled automatically by the client. Passing credentials in options may cause confusion.
fix
Do not include 'Authorization' header; the client manages it.
affects: >=0.0.0
gotchaThe client only supports Digest and Basic authentication schemes. NTLM or other schemes are not supported.
fix
Use a different library for non-Digest/Basic auth.
affects: >=0.0.0
deprecatedThe 'qop' option has a default value of 'auth' in some implementations; ensure server compatibility.
fix
Explicitly set qop: 'auth' or omit to use default.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: fetch is not a function
Node.js version <18 or missing node-fetch import.
fix
Install node-fetch: npm install node-fetch and import it: import fetch from 'node-fetch';
DigestClient is not a constructor
CommonJS require() without .default when esModuleInterop is false.
fix
Use import DigestClient from 'with-digest-fetch' or const DigestClient = require('with-digest-fetch').default;
Cannot find module 'with-digest-fetch' or its corresponding type declarations.
Missing package installation or TypeScript unable to resolve types.
fix
Run npm install with-digest-fetch and ensure tsconfig.json has 'moduleResolution': 'node' or 'node16'.
Request failed with status 401 Unauthorized
Incorrect username, password, or server configuration (e.g., realm, nonce).
fix
Verify credentials and check if server requires Digest or Basic auth. Ensure algorithm matches (e.g., MD5, SHA-256).
Upgrade
Version history
0.7.0latest on npm
Audit
Dependencies
node-fetchoptionalRequired for Node.js environments that lack native fetch (v2.x). Optional when using native fetch in Node 18+ or browsers.
Agent activity
47 hits · last 30 days
node
42
OpenAI (training)
1
Resources
with-digest-fetch — npm install with-digest-fetch · libregistry