~ knotless Search/
↑↓ move↵ open⇧↵ all results

chadtmiller.com/pds.js

An atproto PDS in JavaScript, for Cloudflare Workers and Node

0
0

A Cloudflare PDS reaches Workers on its own account through service bindings

Merged
Merged chadtmiller.com asked to merge into main from chadtmiller.com/pds.js:fix/fetch-bindings

What changes

The Cloudflare adapter reads PDS_FETCH_BINDINGS, comma-separated host=BINDING pairs. The lexicon resolver and the DID resolver fetch a named host through that service binding, and everything else over the network as before (createBoundFetch in packages/cloudflare/src/index.js). A pair whose binding is missing, or is not a service, is ignored. docs/deploy-cloudflare.md has a new section, "Other Workers on your account", with an example.

Why

A Worker cannot fetch another Worker's workers.dev address on the same Cloudflare account. A PDS on such an account therefore can't resolve lexicons or DIDs published on a sibling Worker's PDS, and the resolver reads each one as not published. pds.js now writes a space type's declared collections into a bare space: scope. The pds worker is meant to resolve dev.knotless.space from knotless-lexicons-pds.chad-53c.workers.dev on the same account, but tokens it issued after that change still carried no collections.

How it was checked

  • packages/cloudflare/test/fetch-bindings.test.js:
    • A bound host, case and spaces aside, goes to its binding, given as a URL string and as a Request.
    • Another host goes to the network with its init.
    • Pairs naming no binding, a non-service, or no host fall back to the network, as does an env with no setting.
  • Run here: that file and emailer.test.js pass. tsc (both projects) and biome are clean. The full gate is left to CI.

Shortcomings

The same-account block is Cloudflare's documented behavior (error 1042), but this PDS's failure to resolve was not seen directly. The resolver records nothing when a lookup fails. The deploy that adds the binding is the test: a login should then be granted the collections.

🤖 Generated with Claude Code

Approved

This adds createBoundFetch, which sends the hosts named in PDS_FETCH_BINDINGS to their service bindings and everything else to the network. The lexicon resolver and the DID resolver now use it. I found nothing that needs to change.

  • Input handling: it copes with Request, string and URL inputs.
  • Bad config: malformed pairs, missing bindings and non-service values are skipped without throwing.
  • Matching: host matching is lowercased on both sides, and URL.hostname ignores the port.
  • Tests, docs, changeset: the tests cover the main paths, and the docs and changeset are present.

I did not run the code or the checks. The PR body says the failure to resolve was not observed directly, so the deploy is the real test.

Merged as 1fc7abc