Skip to content

jackall3n/trigger-adapters

Repository files navigation

trigger-adapters

Framework-agnostic HTTP handlers for Trigger.dev – expose your background tasks via REST endpoints in any web framework.

npm version License: MIT

Features

  • 🚀 Simple Integration - Drop-in handlers for your existing web framework
  • 🎯 Framework Support - Pre-built adapters for Next.js, Hono, and Express
  • 📦 Lightweight - Minimal dependencies, tiny bundle size
  • 🛠️ TypeScript First - Full type safety and autocompletion
  • 🔄 Consistent API - Same pattern across all frameworks

Installation

npm install trigger-adapters

Or using your preferred package manager:

yarn add trigger-adapters
pnpm add trigger-adapters
bun add trigger-adapters

Quick Start

Next.js (App Router)

// app/api/trigger/[id]/route.ts
import { handler } from 'trigger-adapters/nextjs';

export const POST = handler();

Hono

import { Hono } from 'hono';
import { handler } from 'trigger-adapters/hono';

const app = new Hono();

app.post('/api/trigger/:id', handler());

export default app;

Express

import express from 'express';
import { handler } from 'trigger-adapters/express';

const app = express();

app.use(express.json());
app.post('/api/trigger/:id', handler());

app.listen(3000);

How It Works

Trigger Adapters provides a simple, consistent interface for exposing Trigger.dev tasks via HTTP endpoints:

  1. Extract Task ID from the route parameters
  2. Parse Request Body to get the task payload
  3. Trigger the Task using Trigger.dev SDK
  4. Return Response in the appropriate format for the framework

Each adapter handles framework-specific details like request/response formats, middleware integration, and error handling.

Documentation

Visit https://trigger-adapters.dev for full documentation, including:

Examples

With Authentication (Next.js)

import { handler } from 'trigger-adapters/nextjs';
import { NextRequest, NextResponse } from 'next/server';
import { verifyToken } from '@/lib/auth';

export async function POST(
  request: NextRequest,
  context: { params: { id: string } }
) {
  const token = request.headers.get('Authorization');

  if (!token || !await verifyToken(token)) {
    return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
  }

  return handler()(request, context);
}

With Middleware (Hono)

import { Hono } from 'hono';
import { bearerAuth } from 'hono/bearer-auth';
import { cors } from 'hono/cors';
import { handler } from 'trigger-adapters/hono';

const app = new Hono();

app.use('/api/*', cors());
app.use('/api/trigger/*', bearerAuth({ token: process.env.API_TOKEN }));

app.post('/api/trigger/:id', handler());

With Rate Limiting (Express)

import express from 'express';
import rateLimit from 'express-rate-limit';
import { handler } from 'trigger-adapters/express';

const app = express();

const limiter = rateLimit({
  windowMs: 15 * 60 * 1000,
  max: 100
});

app.use(express.json());
app.post('/api/trigger/:id', limiter, handler());

Development

This is a monorepo managed with Turborepo and Bun.

Project Structure

trigger-adapters/
├── packages/
│   └── trigger-adapters/    # Main library package
├── apps/
│   └── www/                 # Documentation site (VitePress)
└── README.md

Getting Started

# Clone the repository
git clone https://github.com/jackall3n/trigger-adapters.git
cd trigger-adapters

# Install dependencies
bun install

# Build all packages
bun run build

# Run development mode
bun run dev

# Run tests
cd packages/trigger-adapters
bun run test

Commands

Command Description
bun run build Build all packages
bun run dev Start development mode
bun run check Run Biome linter/formatter check
bun run check:write Fix linting/formatting issues
bun run check-types Run TypeScript type checking

Package Development

The main library is in packages/trigger-adapters/:

cd packages/trigger-adapters

# Build the library
bun run build

# Watch mode for development
bun run dev

# Run tests
bun run test

# Type checking
bun run typecheck

# Release new version
bun run release

Documentation Development

The documentation site is in apps/www/:

cd apps/www

# Start dev server
bun run dev

# Build documentation
bun run build

# Preview built docs
bun run preview

API Reference

handler()

All adapters export a handler() function that returns a framework-specific request handler.

Next.js

import { handler } from 'trigger-adapters/nextjs';

// App Router
export const POST = handler();

// Pages Router
export default handler();

Hono

import { handler } from 'trigger-adapters/hono';

app.post('/trigger/:id', handler());

Express

import { handler } from 'trigger-adapters/express';

app.post('/trigger/:id', handler());

Prerequisites

  • Trigger.dev account and SDK configured
  • One of the supported frameworks (Next.js, Hono, Express)
  • Node.js 18+ or Bun

Contributing

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Development Guidelines

  • Use Bun as the package manager
  • Follow the existing code style (enforced by Biome)
  • Add tests for new features
  • Update documentation as needed

Support

License

MIT © Jack Allen

Acknowledgments

  • Built for Trigger.dev
  • Inspired by the need for simple, consistent HTTP handlers across frameworks
  • Thanks to all contributors and users

Made with ❤️ by Jack Allen

About

Trigger Adapters - HTTP handlers for Trigger.dev

Resources

Stars

Watchers

Forks

Contributors 2

  •  
  •