open-index/open-npm huggingface dataset:
npm package: @growmaxadmin/pdf-annotator-api
Description: Backend API for PDF annotation system - Express/Fastify middleware
Latest version: 1.0.0

# @pdf-annotator/backend-api

Backend API for PDF annotation system. Provides Express middleware for handling annotation CRUD operations and AI-powered product classification.

## Installation

```bash
npm install @pdf-annotator/backend-api express
```

## Quick Start

```typescript
import express from 'express';
import { createAnnotatorAPI } from '@pdf-annotator/backend-api';
import { createPostgresRepositories } from '@pdf-annotator/database-adapters/postgres';

const app = express();

// IMPORTANT: Apply express.json() middleware BEFORE mounting the API
app.use(express.json());

// Create repositories
const repositories = createPostgresRepositories(
  process.env.DATABASE_URL!
);

// Mount annotation API
app.use('/api/pdf-annotator', createAnnotatorAPI({
  repositories,
  ai: {
    provider: 'openai',
    apiKey: process.env.OPENAI_API_KEY!,
  }
}));

app.listen(3000, () => {
  console.log('Server running on port 3000');
});
```

## API Endpoints

### Annotations

- `GET /pdfs/:pdfId/annotations` - Get all annotations for a PDF
- `GET /annotations/:id` - Get a specific annotation
- `POST /annotations` - Create a new annotation
- `PATCH /annotations/:id` - Update an annotation
- `DELETE /annotations/:id` - Delete an annotation
- `DELETE /pdfs/:pdfId/annotations` - Delete all annotations for a PDF

### Products

- `GET /products` - Search products
- `GET /products/:id` - Get product by ID
- `GET /products/by-sku/:sku` - Get product by SKU
- `POST /products` - Create a new product
- `PATCH /products/:id` - Update a product
- `DELETE /products/:id` - Delete a product

### AI Classification

- `POST /ai/classify` - Classify text to identify products
- `POST /ai/classify-batch` - Batch classify multiple text regions

## Configuration

```typescript
interface AnnotatorBackendConfig {
  repositories: RepositoryFactory;
  ai?: AIConfig;
  storage?: StorageConfig;
  auth?: {
    getUserId?: (req: any) => Promise<string | null>;
    isAuthenticated?: (req: any) => Promise<boolean>;
  };
}
```

## License

MIT