This code might be useful to someone!
Here’s the Eleventy global data file used on 11ty.dev to show the lifetime npm downloads for the package in the footer.
https://github.com/11ty/11ty-website/blob/main/src/_data/npm.js
Features:
1. Works around the 18 month data limitation in the npm API.
2. Only the current year is refetched and updated. Previous years are cached forever (assuming your cache folder sticks around).