Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/bearer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ concurrency:

jobs:
bearer:
runs-on: ubuntu-latest
runs-on: [self-hosted, linux]
timeout-minutes: 15
steps:
# Checkout project source
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ concurrency:

jobs:
e2e:
runs-on: ubuntu-latest
runs-on: [self-hosted, linux]
timeout-minutes: 60
strategy:
matrix:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/file-size-checker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ concurrency:
jobs:
check-file-sizes:
name: File Size Check
runs-on: ubuntu-latest
runs-on: [self-hosted, linux]
timeout-minutes: 10

steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ concurrency:

jobs:
Jest:
runs-on: ubuntu-latest
runs-on: [self-hosted, linux]
timeout-minutes: 20
steps:
- uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ concurrency:

jobs:
build:
runs-on: ubuntu-latest
runs-on: [self-hosted, linux]
timeout-minutes: 30

strategy:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/update-algolia.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ concurrency:

jobs:
publish:
runs-on: ubuntu-latest
runs-on: [self-hosted, linux]
timeout-minutes: 20
steps:
- name: Checkout repository
Expand Down
12 changes: 11 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,14 @@ Thumbs.db

# Test coverage
**/coverage/
.nyc_output/
.nyc_output/

# OpenAPI/API Documentation - Private versions with sensitive data
openapi.private.yaml
openapi.private.json
openapi-private.*
**/openapi.private.*
api-docs-private.*
**/api-docs-private.*
swagger-private.*
**/swagger-private.*
202 changes: 202 additions & 0 deletions apps/web/API_DOCUMENTATION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
# Base.org Web API Documentation

This document describes the OpenAPI 3.0 specification for the Base.org Web API.

## Overview

The Base.org Web API provides endpoints for:
- **Basenames**: ENS-like domain naming system for Base
- **Proof Verification**: Discount and eligibility verification for Basenames registration
- **Registry**: Content registry management
- **Mining Statistics**: Bitcoin mining reward data
- **NFT**: NFT proof verification
- **Blockchain**: Block and transaction data
- **Authentication**: User authentication endpoints
- **Farcaster**: Farcaster social network integration

## OpenAPI Specification

The OpenAPI 3.0 specification is located at:
```
apps/web/openapi.yaml
```

## Using the API Documentation

### Viewing the API Documentation

You can view and interact with the API documentation using various tools:

#### 1. Swagger UI (Online)
Upload the `openapi.yaml` file to [Swagger Editor](https://editor.swagger.io/) to view and test the API.

#### 2. Swagger UI (Local)
Run Swagger UI locally with Docker:

```bash
docker run -p 8080:8080 -e SWAGGER_JSON=/openapi.yaml -v $(pwd)/apps/web/openapi.yaml:/openapi.yaml swaggerapi/swagger-ui
```

Then open http://localhost:8080 in your browser.

#### 3. Redoc (Local)
Run Redoc locally with Docker:

```bash
docker run -p 8080:80 -e SPEC_URL=openapi.yaml -v $(pwd)/apps/web/openapi.yaml:/usr/share/nginx/html/openapi.yaml redocly/redoc
```

Then open http://localhost:8080 in your browser.

#### 4. VS Code Extension
Install the "OpenAPI (Swagger) Editor" extension in VS Code to view and edit the specification with autocomplete and validation.

### Generating API Clients

You can generate API clients in various languages using [OpenAPI Generator](https://openapi-generator.tech/):

#### TypeScript/JavaScript Client
```bash
npx @openapitools/openapi-generator-cli generate \
-i apps/web/openapi.yaml \
-g typescript-fetch \
-o ./generated-client/typescript
```

#### Python Client
```bash
npx @openapitools/openapi-generator-cli generate \
-i apps/web/openapi.yaml \
-g python \
-o ./generated-client/python
```

#### Go Client
```bash
npx @openapitools/openapi-generator-cli generate \
-i apps/web/openapi.yaml \
-g go \
-o ./generated-client/go
```

### Validating the OpenAPI Spec

You can validate the OpenAPI specification using:

```bash
npx @stoplight/spectral-cli lint apps/web/openapi.yaml
```

Or using swagger-cli:

```bash
npx swagger-cli validate apps/web/openapi.yaml
```

## API Endpoints Summary

### Core APIs

| Endpoint | Method | Description |
|----------|--------|-------------|
| `/api/mining/reward-stats` | GET | Get Bitcoin mining reward statistics |
| `/api/block/{blockHash}/txs` | GET | Get transactions for a block |
| `/api/_health` | GET | Health check endpoint |
| `/api/cloudinaryUrl` | POST | Get Cloudinary upload URL |
| `/api/registry/entries` | GET | Get registry entries with pagination |
| `/api/registry/featured` | GET | Get featured registry entries |
| `/api/auth` | GET | Authentication challenge |
| `/api/auth/register` | POST | Register new user |
| `/api/checkNftProof` | POST | Verify NFT ownership proof |

### Basenames APIs

| Endpoint | Method | Description |
|----------|--------|-------------|
| `/api/basenames/getUsernames` | GET | Get usernames for an address |
| `/api/basenames/{name}/assets/cardImage.svg` | GET | Get Basename card image |
| `/api/basenames/avatar/ipfsUpload` | POST | Upload avatar to IPFS |
| `/api/basenames/talentprotocol/{address}` | GET | Get Talent Protocol data |
| `/api/basenames/metadata/{tokenId}` | GET | Get Basename NFT metadata |
| `/api/basenames/contract-uri` | GET | Get contract URI |
| `/api/basenames/contract-uri.json` | GET | Get contract metadata JSON |

### Proofs APIs

| Endpoint | Method | Description |
|----------|--------|-------------|
| `/api/proofs/discountCode` | POST | Verify discount code |
| `/api/proofs/discountCode/consume` | POST | Consume discount code |
| `/api/proofs/bns` | GET | Get BNS proof |
| `/api/proofs/baseEthHolders` | GET | Get Base ETH holder proof |
| `/api/proofs/cb1` | GET | Get CB1 proof |
| `/api/proofs/coinbase` | GET | Get Coinbase verified account proof |
| `/api/proofs/cbid` | GET | Get CBID proof |

### Other APIs

| Endpoint | Method | Description |
|----------|--------|-------------|
| `/api/proxy` | GET/POST | Proxy requests to external services |
| `/farcaster/user` | GET | Get Farcaster user information |

## Authentication

The API supports two authentication methods:

1. **Bearer Token (JWT)**: Include in Authorization header
```
Authorization: Bearer <your-jwt-token>
```

2. **Basic Auth**: Username and password authentication
```
Authorization: Basic <base64-encoded-credentials>
```

## Rate Limiting

Rate limiting details are not currently specified in the API. Please refer to the Base.org terms of service for usage limits.

## Error Responses

All endpoints return errors in the following format:

```json
{
"error": "Error message",
"details": "Additional error details (optional)"
}
```

Common HTTP status codes:
- `400`: Bad Request - Invalid parameters
- `401`: Unauthorized - Authentication required
- `404`: Not Found - Resource not found
- `409`: Conflict - Resource conflict (e.g., already claimed)
- `500`: Internal Server Error

## Private API Documentation

If you need to maintain a private version of the API documentation with sensitive information (API keys, internal endpoints, etc.), create a file named `openapi.private.yaml`. This file is automatically excluded by `.gitignore`.

## Contributing

When adding new API endpoints:

1. Add the endpoint definition to `openapi.yaml`
2. Include request/response schemas
3. Document all parameters and responses
4. Add examples where helpful
5. Test the specification using a validator

## Support

For API support and questions, please visit:
- Website: https://base.org
- Documentation: https://docs.base.org
- GitHub: https://github.com/base-org/web

## License

Apache 2.0 - See [LICENSE.md](../../LICENSE.md) for details.
102 changes: 102 additions & 0 deletions apps/web/OPENAPI_QUICKREF.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# OpenAPI 3.0 Quick Reference

## Files Created/Modified

### New Files
1. **apps/web/openapi.yaml** (1,284 lines)
- Complete OpenAPI 3.0 specification
- Documents 25+ API endpoints
- Includes all schemas and authentication

2. **apps/web/API_DOCUMENTATION.md** (202 lines)
- User guide for the OpenAPI specification
- Instructions for viewing and generating clients
- Endpoint reference table

3. **This file** (Quick reference)

### Modified Files
1. **.gitignore**
- Added protection for private API documentation
- Excludes: openapi.private.*, api-docs-private.*, swagger-private.*

2. **GitHub Actions Workflows** (6 files)
- All workflows now use `[self-hosted, linux]` runners
- Files: main.yml, node.js.yml, e2e-tests.yml, bearer.yml, file-size-checker.yml, update-algolia.yml

## Quick Commands

### View API Documentation
```bash
# Swagger UI (Docker)
docker run -p 8080:8080 -e SWAGGER_JSON=/openapi.yaml \
-v $(pwd)/apps/web/openapi.yaml:/openapi.yaml \
swaggerapi/swagger-ui

# Open http://localhost:8080
```

### Validate OpenAPI Spec
```bash
npx swagger-cli validate apps/web/openapi.yaml
```

### Generate TypeScript Client
```bash
npx @openapitools/openapi-generator-cli generate \
-i apps/web/openapi.yaml \
-g typescript-fetch \
-o ./generated-client/typescript
```

## API Endpoint Categories

| Category | Endpoints | Description |
|----------|-----------|-------------|
| Mining | 1 | Bitcoin mining statistics |
| Block | 1 | Blockchain data |
| Health | 1 | Service health checks |
| Registry | 2 | Content registry |
| Auth | 2 | Authentication |
| NFT | 1 | NFT verification |
| Basenames | 7 | Domain naming system |
| Proofs | 7 | Discount proofs |
| Proxy | 2 | External proxying |
| Farcaster | 1 | Social integration |
| Media | 1 | Media processing |

**Total: 26 endpoints**

## Key Features

✅ OpenAPI 3.0.3 compliant
✅ Complete request/response schemas
✅ Authentication schemes (Bearer + Basic)
✅ Server configurations (prod + dev)
✅ Validated with swagger-cli and spectral
✅ Security-scanned with CodeQL
✅ Code-reviewed with no issues

## Self-Hosted Runners

All GitHub Actions workflows now use self-hosted Linux runners for:
- Better performance
- Cost efficiency
- Custom environment control
- Private infrastructure

## Private Documentation

To create a private version with sensitive data:
```bash
cp apps/web/openapi.yaml apps/web/openapi.private.yaml
# Edit openapi.private.yaml with sensitive information
# This file is automatically excluded by .gitignore
```

## Support

- Main documentation: `apps/web/API_DOCUMENTATION.md`
- OpenAPI spec: `apps/web/openapi.yaml`
- Base.org: https://base.org
- Docs: https://docs.base.org
Loading