4 Commits

Author SHA1 Message Date
a485092767 feat: add WebFinger resource discovery (RFC 7033)
Implemented complete WebFinger support for resource discovery with dual-mode configuration:

## Core Implementation

### Types (src/types.ts)
- WebFingerConfig: Main configuration with static resources + content collections
- WebFingerResource: JRD (JSON Resource Descriptor) structure
- WebFingerLink: RFC 7033 compliant link relations
- Content collection integration with builder functions

### Generator (src/generators/webfinger.ts)
- RFC 7033 compliant JRD generation
- Static resource lookup from config
- Async content collection integration
- Template variable replacement: {slug}, {id}, {data.fieldName}, {siteURL}
- Optional rel filtering for link relations

### Route Handler (src/routes/webfinger.ts)
- Dynamic route at /.well-known/webfinger
- Required 'resource' query parameter validation
- Optional 'rel' parameter filtering (can be multiple)
- Proper RFC 7033 compliance:
  - CORS headers (Access-Control-Allow-Origin: *)
  - Media type: application/jrd+json
  - Error responses (400, 404, 500)
- Configurable caching (default: 1 hour)

### Integration Updates
- Added webfinger to DiscoveryConfig
- Route injection when enabled (prerender: false for dynamic queries)
- Build output notification: "/.well-known/webfinger (dynamic)"
- Caching config: webfinger: 3600 (1 hour)

## Features

**Static Resources Mode:**
Configure resources directly in astro.config.mjs for simple use cases.

**Content Collection Mode:**
Automatically expose content collections (team, authors, etc.) via WebFinger
with customizable template URIs and link builders.

**RFC 7033 Compliance:**
- HTTPS required (dev mode allows HTTP)
- Proper JRD format with subject, aliases, properties, links
- CORS support for cross-origin discovery
- Rel filtering for targeted link queries

Opt-in by default (enabled: false) - requires explicit configuration.
2025-11-03 09:05:17 -07:00
6de34f55a9 feat: add security.txt (RFC 9116) and canary.txt support
Implemented two major new discovery file formats:

## security.txt (RFC 9116 - Industry Standard)
- Standardized security contact information
- Required fields: Contact, Expires, Canonical
- Optional fields: Encryption, Acknowledgments, Policy, Hiring, Languages
- Auto-expiration calculation (1 year by default)
- Proper mailto: prefix handling
- Located at /.well-known/security.txt

## canary.txt (NEW SPECIFICATION)
- First standardized format for warrant canaries
- Machine-readable transparency statements
- Auto-expiring based on update frequency
- Support for multiple statement types (NSL, FISA, gag orders, etc.)
- Optional blockchain proof
- Personnel duress statement
- See CANARY_SPEC.md for full specification
- Located at /.well-known/canary.txt

Changes:
- Added SecurityConfig and CanaryConfig type definitions
- Created generators for both formats with smart defaults
- Added API route handlers with virtual module config
- Updated integration to inject /.well-known/ routes
- Added to cache configuration (security: 24h, canary: 1h)
- Exported new types for TypeScript users
- Updated CLAUDE.md with feature priorities
- Created comprehensive CANARY_SPEC.md specification document

Testing: Both features verified in test project with full configuration.
All files generate correctly with proper formatting and validation.
2025-11-03 08:12:42 -07:00
c7b47bba5c fix: use Vite virtual module for configuration instead of global state
The initial config-store approach failed because Astro's injected routes
run in isolated contexts during prerendering and don't have access to
global state set during astro:config:setup.

Solution: Created a Vite plugin that provides the configuration through
a virtual module (virtual:@astrojs/discovery/config) which routes can
import at build time.

Changes:
- Added Vite plugin in astro:config:setup hook
- Updated all route handlers to import from virtual module
- Changed version from date-based (2025.11.03) to semantic (1.0.0) per npm requirements
- Added @ts-ignore comments for virtual module imports

Testing: Verified in test project that all configuration now properly
passes through to generated files (robots.txt, llms.txt, humans.txt).
2025-11-03 07:51:14 -07:00
d25dde4627 feat: initial implementation of @astrojs/discovery integration
This commit introduces a comprehensive Astro integration that automatically
generates discovery files for websites:

Features:
- robots.txt with LLM bot support (Anthropic-AI, GPTBot, etc.)
- llms.txt for AI assistant context and instructions
- humans.txt for team credits and site information
- Automatic sitemap integration via @astrojs/sitemap

Technical Details:
- TypeScript implementation with full type safety
- Configurable HTTP caching headers
- Custom template support for all generated files
- Sensible defaults with extensive customization options
- Date-based versioning (2025.11.03)

Testing:
- 34 unit tests covering all generators
- Test coverage for robots.txt, llms.txt, and humans.txt
- Integration with Vitest

Documentation:
- Comprehensive README with examples
- API reference documentation
- Contributing guidelines
- Example configurations (minimal and full)
2025-11-03 07:36:39 -07:00