@growmaxadmin/pdf-annotator-api
v1.0.0
Published
Backend API for PDF annotation system - Express/Fastify middleware
Readme
@pdf-annotator/backend-api
Backend API for PDF annotation system. Provides Express middleware for handling annotation CRUD operations and AI-powered product classification.
Installation
npm install @pdf-annotator/backend-api expressQuick Start
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 PDFGET /annotations/:id- Get a specific annotationPOST /annotations- Create a new annotationPATCH /annotations/:id- Update an annotationDELETE /annotations/:id- Delete an annotationDELETE /pdfs/:pdfId/annotations- Delete all annotations for a PDF
Products
GET /products- Search productsGET /products/:id- Get product by IDGET /products/by-sku/:sku- Get product by SKUPOST /products- Create a new productPATCH /products/:id- Update a productDELETE /products/:id- Delete a product
AI Classification
POST /ai/classify- Classify text to identify productsPOST /ai/classify-batch- Batch classify multiple text regions
Configuration
interface AnnotatorBackendConfig {
repositories: RepositoryFactory;
ai?: AIConfig;
storage?: StorageConfig;
auth?: {
getUserId?: (req: any) => Promise<string | null>;
isAuthenticated?: (req: any) => Promise<boolean>;
};
}License
MIT
