Skip to content

feat(pds): implement XRPC endpoints, auth, and TypeScript fixes - #3

Merged
ascorbic merged 3 commits into
mainfrom
feat/xrpc-endpoints-and-typescript-fixes
Dec 27, 2025
Merged

feat(pds): implement XRPC endpoints, auth, and TypeScript fixes#3
ascorbic merged 3 commits into
mainfrom
feat/xrpc-endpoints-and-typescript-fixes

Conversation

@ascorbic

Copy link
Copy Markdown
Owner

Summary

This PR implements the core XRPC endpoints, authentication, and resolves all TypeScript diagnostic errors, completing Phases 3, 6, and 7 of the Edge PDS implementation plan.

  • XRPC Endpoints - Full implementation of sync, repo, and server identity endpoints
  • Authentication - Bearer token middleware for write operations
  • Environment Validation - Fail-fast validation for all required environment variables
  • TypeScript Fixes - Resolved all module resolution issues and diagnostic errors
  • Health Endpoint - Now returns version information
  • Durable Objects Best Practices - RPC-first architecture, proper error handling
  • Comprehensive Tests - 34 tests passing, including integration tests

Test Plan

All tests passing:

  • Storage layer tests (16 tests)
  • XRPC endpoint tests (12 tests)
  • Environment validation tests (6 tests)
pnpm test
# ✓ 34 tests passed

Technical Details

XRPC Endpoints Implemented

Tier 1: Sync (Federation)

  • com.atproto.sync.getRepo - Export repository as CAR file
  • com.atproto.sync.getRepoStatus - Get repository status

Tier 2: Repository Operations

  • com.atproto.repo.describeRepo - Describe repository metadata
  • com.atproto.repo.getRecord - Get a single record
  • com.atproto.repo.listRecords - List records in a collection
  • com.atproto.repo.createRecord - Create a new record (authenticated)
  • com.atproto.repo.deleteRecord - Delete a record (authenticated)

Tier 3: Server Identity

  • com.atproto.server.describeServer - Server metadata
  • com.atproto.identity.resolveHandle - Handle resolution

TypeScript Fixes

  • Added moduleResolution: "bundler" to tsconfig.json
  • Created custom type declarations in src/types/modules.d.ts for packages with broken exports
  • Fixed cloudflare:test module resolution by adding @cloudflare/vitest-pool-workers/types
  • Used Rpc.Serializable<T> for DO RPC return types
  • Fixed all verbatimModuleSyntax compatibility issues

Architecture Improvements

  • Removed legacy DO fetch handler in favor of RPC-first approach
  • Implemented proper error propagation (no try/catch blocks)
  • Fresh DO stubs created per request
  • Lazy initialization with blockConcurrencyWhile

🤖 Generated with Claude Code

ascorbic and others added 3 commits December 27, 2025 08:03
- Implement full XRPC endpoint suite (sync, repo, server identity)
- Add bearer token authentication for write operations
- Fix TypeScript module resolution for multiformats packages
- Add environment variable validation with fail-fast startup
- Implement health endpoint with version info
- Add comprehensive integration tests (34 tests passing)
- Follow Durable Objects best practices (RPC-first architecture)
- Update documentation (EDGE_PDS_PLAN.md, CLAUDE.md)

Completes Phase 3 (XRPC), Phase 6 (Identity), and Phase 7 (Auth).
All TypeScript diagnostics resolved.

🤖 Generated with [Claude Code](https://claude.com/claude-code)
Replace manual CAR building and low-level encoding with official @atproto packages:

- Replace manual CAR file building (~30 lines) with blocksToCarFile from @atproto/repo
- Switch all CID operations to @atproto/lex-data (resolves deprecation warnings)
- Use @atproto/lex-cbor for CBOR encoding/decoding in tests

Dependencies:
- Add @atproto/lex-cbor, @atproto/lex-data
- Remove varint, @types/varint, cborg, uint8arrays (replaced by blocksToCarFile)
- Remove @ipld/dag-cbor, multiformats (replaced by @atproto/lex-cbor)

Files:
- Delete src/types/modules.d.ts (no longer needed)
- Delete test/types.d.ts (no longer needed)
- Update src/account-do.ts: use blocksToCarFile and @atproto/lex-data CID
- Update src/storage.ts: use @atproto/lex-data CID
- Update test/storage.test.ts: use @atproto/lex-cbor for test fixtures

All encoding and format operations now use official @atproto stable APIs.
Tests: 34/34 passing

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Replace manual protocol operations with official @atproto utilities for better
standards compliance and maintainability.

Record Key Generation:
- Replace custom Date.now() + Math.random() with TID.nextStr() from @atproto/common-web
- Ensures proper chronological ordering with microsecond precision
- Provides monotonic incrementing per AT Protocol standard
- Remove generateRkey() helper in favor of direct TID.nextStr() calls

AT URI Construction:
- Replace manual template literal URIs with AtUri.make() from @atproto/syntax
- Ensures proper URI encoding and structure validation
- Updated in account-do.ts (rpcListRecords, rpcCreateRecord) and repo.ts (getRecord)

DID Validation:
- Add ensureValidDid() validation in all XRPC endpoints that accept DID parameters
- Validates DID format before processing requests
- Updated: repo.ts (describeRepo, getRecord, listRecords), sync.ts (getRepo, getRepoStatus)

Handle Validation:
- Add ensureValidHandle() validation in server.ts resolveHandle endpoint
- Validates handle format before processing requests

Environment Variable Validation:
- Move validation to module scope using cloudflare:workers env import
- Validates once at worker startup instead of per-request
- Worker fails fast at initialization if misconfigured
- Remove test/env-validation.test.ts (incompatible with module-scope validation)

Dependencies:
- Add @atproto/common-web for TID utilities

All protocol-adjacent operations now use official @atproto helpers for consistency
and standards compliance.

Tests: 28/28 passing

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@ascorbic
ascorbic merged commit a5f322b into main Dec 27, 2025
2 checks passed
@ascorbic
ascorbic deleted the feat/xrpc-endpoints-and-typescript-fixes branch December 27, 2025 10:03
ascorbic added a commit that referenced this pull request Aug 30, 2026
check.cirrus.earth gains a 'space conformance' view: point it at any
spaces host and it runs the discovery and request-shape checks against
it. It imports only the dependency-free package root, so the alpha
crypto libs never enter the browser bundle (verified: no
atproto-space/node markers in dist) — the credential, sync and
host-role checks declare capabilities the browser cannot provide and
are reported as not-testable rather than silently skipped.

Third of the three runners, all over the same catalog: in-process
(vitest), CLI, and now browser — each honest about what it can and
cannot exercise.
ascorbic added a commit that referenced this pull request Aug 30, 2026
check.cirrus.earth gains a 'space conformance' view: point it at any
spaces host and it runs the discovery and request-shape checks against
it. It imports only the dependency-free package root, so the alpha
crypto libs never enter the browser bundle (verified: no
atproto-space/node markers in dist) — the credential, sync and
host-role checks declare capabilities the browser cannot provide and
are reported as not-testable rather than silently skipped.

Third of the three runners, all over the same catalog: in-process
(vitest), CLI, and now browser — each honest about what it can and
cannot exercise.
ascorbic added a commit that referenced this pull request Aug 30, 2026
check.cirrus.earth gains a 'space conformance' view: point it at any
spaces host and it runs the discovery and request-shape checks against
it. It imports only the dependency-free package root, so the alpha
crypto libs never enter the browser bundle (verified: no
atproto-space/node markers in dist) — the credential, sync and
host-role checks declare capabilities the browser cannot provide and
are reported as not-testable rather than silently skipped.

Third of the three runners, all over the same catalog: in-process
(vitest), CLI, and now browser — each honest about what it can and
cannot exercise.
ascorbic added a commit that referenced this pull request Aug 30, 2026
check.cirrus.earth gains a 'space conformance' view: point it at any
spaces host and it runs the discovery and request-shape checks against
it. It imports only the dependency-free package root, so the alpha
crypto libs never enter the browser bundle (verified: no
atproto-space/node markers in dist) — the credential, sync and
host-role checks declare capabilities the browser cannot provide and
are reported as not-testable rather than silently skipped.

Third of the three runners, all over the same catalog: in-process
(vitest), CLI, and now browser — each honest about what it can and
cannot exercise.
ascorbic added a commit that referenced this pull request Aug 30, 2026
check.cirrus.earth gains a 'space conformance' view: point it at any
spaces host and it runs the discovery and request-shape checks against
it. It imports only the dependency-free package root, so the alpha
crypto libs never enter the browser bundle (verified: no
atproto-space/node markers in dist) — the credential, sync and
host-role checks declare capabilities the browser cannot provide and
are reported as not-testable rather than silently skipped.

Third of the three runners, all over the same catalog: in-process
(vitest), CLI, and now browser — each honest about what it can and
cannot exercise.
ascorbic added a commit that referenced this pull request Aug 30, 2026
check.cirrus.earth gains a 'space conformance' view: point it at any
spaces host and it runs the discovery and request-shape checks against
it. It imports only the dependency-free package root, so the alpha
crypto libs never enter the browser bundle (verified: no
atproto-space/node markers in dist) — the credential, sync and
host-role checks declare capabilities the browser cannot provide and
are reported as not-testable rather than silently skipped.

Third of the three runners, all over the same catalog: in-process
(vitest), CLI, and now browser — each honest about what it can and
cannot exercise.
ascorbic added a commit that referenced this pull request Aug 30, 2026
check.cirrus.earth gains a 'space conformance' view: point it at any
spaces host and it runs the discovery and request-shape checks against
it. It imports only the dependency-free package root, so the alpha
crypto libs never enter the browser bundle (verified: no
atproto-space/node markers in dist) — the credential, sync and
host-role checks declare capabilities the browser cannot provide and
are reported as not-testable rather than silently skipped.

Third of the three runners, all over the same catalog: in-process
(vitest), CLI, and now browser — each honest about what it can and
cannot exercise.
ascorbic added a commit that referenced this pull request Aug 30, 2026
check.cirrus.earth gains a 'space conformance' view: point it at any
spaces host and it runs the discovery and request-shape checks against
it. It imports only the dependency-free package root, so the alpha
crypto libs never enter the browser bundle (verified: no
atproto-space/node markers in dist) — the credential, sync and
host-role checks declare capabilities the browser cannot provide and
are reported as not-testable rather than silently skipped.

Third of the three runners, all over the same catalog: in-process
(vitest), CLI, and now browser — each honest about what it can and
cannot exercise.
ascorbic added a commit that referenced this pull request Aug 30, 2026
check.cirrus.earth gains a 'space conformance' view: point it at any
spaces host and it runs the discovery and request-shape checks against
it. It imports only the dependency-free package root, so the alpha
crypto libs never enter the browser bundle (verified: no
atproto-space/node markers in dist) — the credential, sync and
host-role checks declare capabilities the browser cannot provide and
are reported as not-testable rather than silently skipped.

Third of the three runners, all over the same catalog: in-process
(vitest), CLI, and now browser — each honest about what it can and
cannot exercise.
ascorbic added a commit that referenced this pull request Aug 30, 2026
check.cirrus.earth gains a 'space conformance' view: point it at any
spaces host and it runs the discovery and request-shape checks against
it. It imports only the dependency-free package root, so the alpha
crypto libs never enter the browser bundle (verified: no
atproto-space/node markers in dist) — the credential, sync and
host-role checks declare capabilities the browser cannot provide and
are reported as not-testable rather than silently skipped.

Third of the three runners, all over the same catalog: in-process
(vitest), CLI, and now browser — each honest about what it can and
cannot exercise.
ascorbic added a commit that referenced this pull request Aug 30, 2026
check.cirrus.earth gains a 'space conformance' view: point it at any
spaces host and it runs the discovery and request-shape checks against
it. It imports only the dependency-free package root, so the alpha
crypto libs never enter the browser bundle (verified: no
atproto-space/node markers in dist) — the credential, sync and
host-role checks declare capabilities the browser cannot provide and
are reported as not-testable rather than silently skipped.

Third of the three runners, all over the same catalog: in-process
(vitest), CLI, and now browser — each honest about what it can and
cannot exercise.
ascorbic added a commit that referenced this pull request Aug 30, 2026
check.cirrus.earth gains a 'space conformance' view: point it at any
spaces host and it runs the discovery and request-shape checks against
it. It imports only the dependency-free package root, so the alpha
crypto libs never enter the browser bundle (verified: no
atproto-space/node markers in dist) — the credential, sync and
host-role checks declare capabilities the browser cannot provide and
are reported as not-testable rather than silently skipped.

Third of the three runners, all over the same catalog: in-process
(vitest), CLI, and now browser — each honest about what it can and
cannot exercise.
ascorbic added a commit that referenced this pull request Aug 31, 2026
check.cirrus.earth gains a 'space conformance' view: point it at any
spaces host and it runs the discovery and request-shape checks against
it. It imports only the dependency-free package root, so the alpha
crypto libs never enter the browser bundle (verified: no
atproto-space/node markers in dist) — the credential, sync and
host-role checks declare capabilities the browser cannot provide and
are reported as not-testable rather than silently skipped.

Third of the three runners, all over the same catalog: in-process
(vitest), CLI, and now browser — each honest about what it can and
cannot exercise.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant