mirror of
https://github.com/bitbaum/orangecat.git
synced 2026-12-05 01:08:23 +01:00
Step 2 of the platform-ification. The /api/v1/ surface is now described in a machine-readable contract that can never drift from the server, because it's generated from the same Zod schemas the server validates against. What ships: - @asteasolutions/zod-to-openapi@7.3.4 added (peers on zod ^3.20.2, we run 3.25.76 — compatible without a Zod upgrade). - src/lib/openapi/registry.ts — extends Zod with .openapi(), single shared OpenAPIRegistry. - src/lib/openapi/responses.ts — apiSuccess<T> and apiError envelope schemas matching src/lib/api/standardResponse.ts. - src/lib/openapi/registerV1Routes.ts — maps every public entity type in PUBLIC_API_ENTITY_TYPES to its Zod schema and builds the operation (request body, response shape, common error responses, IntegrationKey security scheme). - src/lib/openapi/spec.ts — memoised generator. One call per process. - GET /api/v1/openapi.json — public, cached 5 minutes, returns the spec. - Discovery endpoint (/api/v1) now exposes the spec URL + conventions link so SDKs and curious devs can find them. - /settings/integrations page links openapi.json and discovery so users see the contract they're integrating against. docs/api/CONVENTIONS.md — the rulebook everything under /v1 follows: versioning policy, response envelope, canonical error codes, idempotency (planned), rate limits, pagination (planned, cursor-based), naming, timestamps, Bitcoin amount handling (BTC not sats), webhooks (planned — HMAC-SHA-256 signed with the integration key), SDK guidance, and a discipline checklist for landing new public endpoints. Smoke test: `curl /api/v1/openapi.json` returns a ~41 KB OpenAPI 3.1 document with 10 paths (9 entity POSTs + discovery), 26 schemas, and the IntegrationKey security scheme. Next: TypeScript SDK package (probably dev/orangecat-sdk as a new repo) generated from this spec. After that, the first FleetCrown-side integration spike consumes the SDK. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
created_date, last_modified_date, last_modified_summary
| created_date | last_modified_date | last_modified_summary |
|---|---|---|
| 2025-06-05 | 2025-06-05 | Added documentation standards including creation and modification dates |
�� API Documentation
REST API Reference for OrangeCat
📋 Overview
OrangeCat provides a comprehensive REST API for managing Bitcoin fundraising projects, user profiles, and authentication. All API endpoints follow RESTful conventions and return JSON responses.
Base URL: /api/
Authentication: JWT tokens via Supabase Auth
Rate Limiting: Applied per endpoint
🔐 Authentication
All protected endpoints require authentication via JWT tokens:
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type': 'application/json'
}
📚 API Sections
🔐 Authentication Endpoints
- Authentication API - Login, register, password reset
👤 Profile Management
- Profile API - User profile CRUD operations
💰 Campaign Management
- Campaign API - Fundraising project operations
📁 File Upload
- Upload API - Avatar and banner image uploads
🤖 AI Chat
- Chat API - AI assistant integration using Google Gemini
🎯 Quick Start
1. Authentication
// Login
POST /api/auth/login
{
"email": "user@example.com",
"password": "password"
}
2. Get Profile
// Get current user profile
GET /api/profile
Authorization: Bearer {token}
3. Create Campaign
// Create new project
POST /api/projects
Authorization: Bearer {token}
{
"title": "My Campaign",
"description": "Campaign description",
"goal_amount": 1000000
}
📊 Response Format
Success Response
{
"success": true,
"data": { ... },
"message": "Operation successful"
}
Error Response
{
"success": false,
"error": "Error message",
"code": "ERROR_CODE"
}
🔒 Security
- Input Validation - All inputs validated and sanitized
- Rate Limiting - Protection against abuse
- CORS - Configured for secure cross-origin requests
- HTTPS Only - All API calls must use HTTPS in production
📈 Rate Limits
| Endpoint Type | Limit | Window |
|---|---|---|
| Authentication | 5 requests | 1 minute |
| Profile Updates | 10 requests | 1 minute |
| File Uploads | 3 requests | 1 minute |
| General API | 100 requests | 1 minute |
🐛 Error Codes
| Code | Description |
|---|---|
AUTH_REQUIRED |
Authentication required |
INVALID_TOKEN |
Invalid or expired token |
VALIDATION_ERROR |
Input validation failed |
RATE_LIMIT_EXCEEDED |
Too many requests |
RESOURCE_NOT_FOUND |
Resource not found |
PERMISSION_DENIED |
Insufficient permissions |
📚 Related Documentation
- Authentication System - Complete auth flow
- Security Guidelines - Security best practices
- Development Setup - Local API development