Files
orangecat/docs/api
Georgy ButaevandClaude Opus 4.7 8511674285 feat(sdk): @orangecat/sdk v0.1.0 — TypeScript client for the v1 API
Step 3 of the platform-ification. The SDK is the first integration
artefact FleetCrown (and the rest) will install. Lives at
packages/sdk/ as an npm workspace member of the orangecat repo —
single source of truth, one CI pipeline, lock-step PRs when schemas
change.

Package layout (packages/sdk/):
- package.json — ESM-only, "type": "module", clean "exports" map,
  declares Node ≥18, sideEffects: false for tree-shaking, marked
  public so it can be published to npm later (UNLICENSED for now).
- tsconfig.json (type-check) + tsconfig.build.json (emit to dist/).
- src/errors.ts — OrangeCatError + OrangeCatErrorCode enum mirroring
  CONVENTIONS.md §3. `.isRetryable` for SDK retry logic and consumer
  branches.
- src/http.ts — fetch transport. Built-in: 20s timeout (matches
  FleetCrown's useFetch), exp backoff retry (3 attempts) on network /
  5xx / 429 honouring Retry-After, auto-generated Idempotency-Key on
  mutating requests (forward-compatible — server dedup planned),
  bearer + X-OrangeCat-Key headers, User-Agent identifying the SDK,
  AbortSignal composition.
- src/types.ts — request/response types for the 9 v1 entity creates.
  Hand-written for v0.1 (OpenAPI codegen is a follow-up). Each response
  type intersects Record<string, unknown> so additive server fields
  don't break consumers.
- src/client.ts — OrangeCatClient with resource namespaces
  (client.products.create(…), .services.create(…), etc.) +
  client.discovery() for startup-time version sanity check.
- src/index.ts — public exports.
- README.md — quickstart, auth, error handling, reliability features,
  versioning policy.

OrangeCat root package.json gains `"workspaces": ["packages/*"]`.
`npm install` symlinks @orangecat/sdk into node_modules.

Contract reality check while building the SDK exposed two drifts from
the conventions doc — fixed both:
- Server returns `error: { code, message, details }` (nested object),
  not `error: string + code` (flat) as the doc claimed. Fixed
  src/lib/openapi/responses.ts to describe the real shape and updated
  CONVENTIONS.md §3 with the actual wire format + the SDK's
  case-normalisation (server sends UPPERCASE, SDK matches lowercase).
- This is what end-to-end SDK testing is FOR. The doc is the
  aspirational contract; the server is the running reality; the SDK
  is what proves they match.

Smoke test (against local /api/v1):
- DISCOVERY OK: v1 - 9 entities, /api/v1/openapi.json
- AUTH ERROR (expected): unauthorized / HTTP 401 - Unauthorized

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-06-03 15:05:48 +02:00
..
2025-12-10 16:56:40 +01:00

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

👤 Profile Management

💰 Campaign Management

📁 File Upload

🤖 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