Registry / devops / d2l-fetch-dedupe

d2l-fetch-dedupe

JSON →
library2.1.1jsnpmunverified

A middleware function for de-duplicating fetch requests in the d2l-fetch ecosystem. Version 2.1.1 is the latest. It deduplicates concurrent requests based on url+Authorization header combination, returning a cloned response for duplicate requests. Designed for Brightspace's d2l-fetch library, it is ESM-only and requires a browser environment. Compared to generic dedup patterns, it integrates natively with d2l-fetch's middleware chain.

npm install d2l-fetch-dedupe
INSTALL
IMPORT
SIG · D2L-FETCH-DEDUPE
D
d2l-fetch-dedupe
devopsjavascriptv2.1.1
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.

fetchDedupe
import { fetchDedupe } from 'd2l-fetch-dedupe'
const { fetchDedupe } = require('d2l-fetch-dedupe')
ESM-only package; CJS require will fail. Named export is fetchDedupe.
default import
import { fetchDedupe } from 'd2l-fetch-dedupe'
import fetchDedupe from 'd2l-fetch-dedupe'
There is no default export; must use named import.
d2lFetch.use
d2lfetch.use({name: 'dedupe', fn: fetchDedupe})
d2lfetch.use(fetchDedupe)
The middleware must be passed as an object with `name` and `fn` properties to d2lFetch.use().

Registers dedupe middleware, then makes two concurrent fetch calls to same URL+auth to demonstrate deduplication.

import d2lfetch from 'd2l-fetch'; import { fetchDedupe } from 'd2l-fetch-dedupe'; // Register the dedupe middleware d2lfetch.use({name: 'dedupe', fn: fetchDedupe}); // Make two concurrent requests to the same URL with same auth const request = new Request('https://api.example.com/data', { headers: { Authorization: 'Bearer token123' } }); const [response1, response2] = await Promise.all([ d2lfetch.fetch(request.clone()), d2lfetch.fetch(request.clone()) ]); console.log(await response1.text(), await response2.text()); // Both succeed, but only one network request
Debug
Known issues
breakingd2l-fetch-dedupe is ESM-only. require() will throw an error.
fix
Use import syntax or ensure your environment supports ES modules.
affects: >=2.0.0
gotchaDeduplication key is url+Authorization header only. Other headers are ignored.
fix
Ensure requests that should be separate have different URLs or Authorization headers.
affects: >=1.0.0
gotchaThe middleware must be registered before making requests; it won't deduplicate requests made before registration.
fix
Call d2lfetch.use({name:'dedupe', fn: fetchDedupe}) before any fetch calls.
affects: >=1.0.0
Errors
Common errors & fixes
Error [ERR_REQUIRE_ESM]: require() of ES Module
Using CommonJS require() to import an ESM-only package in Node.js < v12 or without experimental modules.
fix
Switch to import statement or set type: module in package.json.
TypeError: d2lfetch.use is not a function
d2l-fetch is not properly initialized or the d2lfetch object is undefined.
fix
Ensure d2l-fetch is correctly imported and d2lfetch is the export from d2l-fetch.
TypeError: fetchDedupe is not a function
Importing incorrectly (e.g., default import instead of named).
fix
Use `import { fetchDedupe } from 'd2l-fetch-dedupe'`.
Upgrade
Version history
2.1.1latest on npm
Audit
Dependencies
d2l-fetchrequiredPeer dependency; middleware is designed to be used with d2l-fetch's `use` method
Agent activity
9 hits · last 30 days
node
8
Amazon
1
Resources
d2l-fetch-dedupe — npm install d2l-fetch-dedupe · libregistry