chadtmiller.com/knotless
git that lives in your Atmosphere account
1
10
knotless-serve answers npm's registry for a repository's packages
Merged Approved
This adds an npm registry to knotless-serve at /npm/<did>/<repo key>/, built on the same release records as the Cargo one. It adds an optional npm.manifest object to dev.knotless.release. The code shared with Cargo moves into web/registry.rs, and the docs and a change file are included. All seven checks pass at 39d65c61. I read the lexicon, npm.rs, registry.rs, the cargo.rs refactor, the records and release changes, and the routes. I did not read tests/web.rs or the docs diffs; the passing checks cover them.
- Lexicon: The
npmobject is a single requiredmanifeststring, kept as npm's own JSON. Optional fields can be added later, so the shape leaves room to grow.keptlimits the manifest to 100,000 bytes, and the lexicon'smaxLengthcounts bytes too, so the two agree. keptandpublish:- A publish checks the name and version in the manifest.
- It checks
dist.integrityanddist.shasumagainst the tarball. - It checks that
package/package.jsonnames the same package and version. - It strips
readme,deprecatedanddist.tarballbefore keeping the manifest. - Only the repository owner, logged in with an app password, can write.
- A tarball read from the PDS can't be swapped for different bytes, because the stored SHA-256 and the signed SHA-512 and SHA-1 all pin it.
- Refactor: The
cargo.rsrefactor keeps its behavior. The newfile_inmatches the same<dir>/<name>shape as the oldmanifest_of, and its test covers the case where the file is missing, is too large, has a bad header size or isn't gzip. - Routes: Static routes such as
-/pingand-/user/{user}don't clash with{name}/-/{file}, and the real-npm test passes through them.
I left no line comments.
All checks have passed
9 passed, 1 skipped
Merged as e293763
knotless-serve now answers npm's registry protocol for each repository's releases, the same way it answers Cargo's.
npm login(your handle and an app password),npm publish,npm install,npm viewandnpm searchwork, andnpm deprecateyanks a version. Worth a look: thenpmobject this adds todev.knotless.release, since a lexicon can only grow once published.Claude Opus 5.5 · high
What changes
knotless-serve serves an npm registry for each repository at
/npm/<did>/<repo key>/. A scope is pointed at it with@scope:registry=in.npmrc. It answers the packument (each version's manifest,dist.tarballpointing back here,deprecatedon a yanked version, anddist-tags.latestworked out from the versions there are), tarball downloads,npm publish,npm deprecateand taking it back with"", legacynpm login,whoami,ping,dist-tag lsandsearch.npm unpublish,npm dist-tag addand--provenanceare refused, each with its reason. A web login answers 404, so plainnpm loginasks for a handle and a password and needs no flag.A release gains an optional
npmobject: itsmanifest, the version's manifest asnpm publishsent it, without itsreadmeordist.tarball. A publish checks the manifest'sdist.integrity(SHA-512) anddist.shasum(SHA-1) against the tarball, and thatpackage/package.jsonnames the same package and version. So the hash npm checks an install against is signed in the owner's account beside the file's SHA-256. The file is<name without scope>-<version>.tgz.What the two registries share is moved out of
web/cargo.rsintoweb/registry.rs: opening the repository by what the index has, logging in by<handle>:<app password>, reading a file out of a gzipped tar, an answer sentno-cachewith an ETag, sending a release's file, and putting a publish or a yank in the index at once. Each registry still writes refusals in its own error format.release::latest_offinds the latest of one package's releases without copying them.docs/design/packages.mdhas a new npm packages section, andnpm protocolis gone from its Not yet list.docs/reference/api.mdlists the routes. There is a change file.Why
Package names were kept to npm's rules so that npm's protocol could be served from the same records, and it was the next item in packages.md's Not yet list. It follows the Cargo registry's choices, for the same reasons. The address holds a DID and a repository key, as lockfiles keep each tarball's URL. Its manifest is npm's own JSON, kept in the record. What it reads is what the index has, so a takedown holds.
npm loginworks.How it was checked
an_npm_registryruns real npm against a served registry and the PDS:whoamiandpingdist-tag ls, and the refuseddist-tag addandunpublishdeprecateand taking it back, checked against the yank record and withnpm cifrom nothing keptsearchUnit tests cover the packument, tarball names, what a publish keeps, and a file found in a tarball. All seven checks passed at 39d65c61.
Shortcomings
npm loginitself is not run, since it reads from a terminal. The test sends the samePUT -/user/org.couchdb.user:<name>instead.As with crates: public repositories only; no
commitorcheckon a release made this way; and an app password, which can do far more than publish, sits in.npmrcin plain text. Deprecation messages are not kept: a yanked version readsyanked by its owner. A package name with~can't publish, since its tarball name would not be a release file's name.The releases page does not show how to install an npm package yet. That comes in the next pull of this stack.
Review
The lexicon first, then
crates/knotless-serve/src/web/npm.rs'skeptandWriting::publish.