npm package: @flightdev/adapter-vercel
Description: Vercel adapter for Flight Framework - deploy to Vercel Edge/Serverless
Latest version: 0.0.7

# @flightdev/adapter-vercel

Vercel deployment adapter for Flight Framework. Supports both Serverless and Edge runtimes.

## Table of Contents

- [Installation](#installation)
- [Quick Start](#quick-start)
- [Configuration](#configuration)
- [Edge Runtime](#edge-runtime)
- [ISR (Incremental Static Regeneration)](#isr)
- [Build Output](#build-output)
- [Deployment](#deployment)
- [Environment Variables](#environment-variables)
- [API Reference](#api-reference)
- [License](#license)

---

## Installation

```bash
npm install @flightdev/adapter-vercel
```

---

## Quick Start

```typescript
// flight.config.ts
import { defineConfig } from '@flightdev/core';
import vercel from '@flightdev/adapter-vercel';

export default defineConfig({
    adapter: vercel(),
});
```

Deploy:

```bash
npm run build
vercel --prod
```

---

## Configuration

```typescript
vercel({
    // Node.js runtime version
    runtime: 'nodejs20.x',
    
    // Deployment regions
    regions: ['iad1', 'sfo1', 'cdg1'],
    
    // Function memory (MB)
    memory: 1024,
    
    // Max execution time (seconds)
    maxDuration: 30,
    
    // Split routes into separate functions
    split: true,
    
    // Enable ISR
    isr: {
        expiration: 60,
        bypassToken: process.env.ISR_BYPASS_TOKEN,
    },
    
    // Images configuration
    images: {
        domains: ['example.com'],
        sizes: [640, 750, 828, 1080, 1200],
    },
});
```

---

## Edge Runtime

Deploy API routes to the edge for low latency:

```typescript
// Per-route configuration
// src/routes/api/fast.get.ts
export const config = {
    runtime: 'edge',
    regions: ['iad1', 'sfo1', 'cdg1', 'hnd1'],
};

export async function GET(request: Request) {
    return Response.json({ fast: true });
}
```

Or configure globally:

```typescript
vercel({
    runtime: 'edge',
    regions: ['iad1', 'sfo1'],
});
```

---

## ISR

Incremental Static Regeneration for dynamic content:

```typescript
// flight.config.ts
vercel({
    isr: {
        expiration: 60,  // Revalidate every 60 seconds
    },
});
```

Per-route configuration:

```typescript
// src/routes/products/[id].page.tsx
export const config = {
    isr: {
        expiration: 3600,  // 1 hour
    },
};
```

On-demand revalidation:

```typescript
// src/routes/api/revalidate.post.ts
import { revalidatePath } from '@flightdev/adapter-vercel';

export async function POST(request: Request) {
    const { path, secret } = await request.json();
    
    if (secret !== process.env.REVALIDATE_SECRET) {
        return Response.json({ error: 'Invalid secret' }, { status: 401 });
    }
    
    await revalidatePath(path);
    return Response.json({ revalidated: true });
}
```

---

## Build Output

The adapter generates Vercel Build Output API format:

```
.vercel/
└── output/
    ├── config.json              # Vercel configuration
    ├── functions/
    │   ├── index.func/          # SSR function
    │   └── api/
    │       └── [...path].func/  # API routes
    └── static/
        ├── assets/              # Hashed static files
        └── _next/               # Client bundles
```

---

## Deployment

### Vercel CLI

```bash
# Install Vercel CLI
npm install -g vercel

# Build
npm run build

# Deploy to preview
vercel

# Deploy to production
vercel --prod
```

### Git Integration

Connect your repository in the Vercel dashboard for automatic deployments on push.

### Environment Variables

Set in Vercel dashboard or via CLI:

```bash
vercel env add DATABASE_URL production
vercel env add API_KEY production preview development
```

---

## Environment Variables

| Variable | Description |
|----------|-------------|
| `VERCEL` | Set to `1` when running on Vercel |
| `VERCEL_ENV` | `production`, `preview`, or `development` |
| `VERCEL_URL` | Deployment URL |
| `VERCEL_REGION` | Current region code |

---

## API Reference

### Adapter Options

| Option | Type | Default | Description |
|--------|------|---------|-------------|
| `runtime` | `string` | `'nodejs20.x'` | Runtime version |
| `regions` | `string[]` | `['iad1']` | Deployment regions |
| `memory` | `number` | `1024` | Function memory (MB) |
| `maxDuration` | `number` | `30` | Max execution (seconds) |
| `split` | `boolean` | `true` | Split into functions |
| `isr` | `object` | - | ISR configuration |

### Regions

| Code | Location |
|------|----------|
| `iad1` | Washington, D.C. |
| `sfo1` | San Francisco |
| `cdg1` | Paris |
| `hnd1` | Tokyo |
| `syd1` | Sydney |
| `gru1` | Sao Paulo |

---

## License

MIT