A powerful Trigger.dev extension that enables seamless integration between SvelteKit and Trigger.dev by allowing you to use your SvelteKit functions, classes, and exports directly in your Trigger.dev projects with zero code changes.
npm add -D triggerkit
// trigger.config.ts
import { defineConfig } from "@trigger.dev/sdk/v3";
import { triggerkit } from "triggerkit";
export default defineConfig({
project: "your-project-id",
runtime: "node",
build: {
extensions: [
triggerkit(), // Zero config - just works!
],
},
});
// src/lib/server/email.ts
import { EMAIL_API_KEY } from "$env/static/private";
import { PUBLIC_APP_URL } from "$env/static/public";
export async function sendWelcomeEmail(userId: string, email: string) {
// Your existing SvelteKit function - no changes needed!
const response = await fetch(`${PUBLIC_APP_URL}/api/email`, {
method: "POST",
headers: { "Authorization": `Bearer ${EMAIL_API_KEY}` },
body: JSON.stringify({ userId, email, type: "welcome" }),
});
return { success: response.ok, userId };
}
// Classes work too!
export class UserService {
constructor(private apiKey: string) {}
async getUser(id: string): Promise<User> {
// Your service logic
}
static validateEmail(email: string): boolean {
return /\S+@\S+\.\S+/.test(email);
}
}
// src/trigger/welcome.ts
import { sendWelcomeEmail, UserService } from "virtual:triggerkit";
import { task } from "@trigger.dev/sdk/v3";
export const welcomeEmailTask = task({
id: "welcome-email",
run: async (payload: { userId: string; email: string }) => {
// Full IntelliSense and type checking!
const userService = new UserService(process.env.USER_API_KEY);
const user = await userService.getUser(payload.userId);
const result = await sendWelcomeEmail(payload.userId, payload.email);
return { result, user };
},
});
interface PluginOptions {
/**
* Directories to scan for exportable items
* @default ["src/lib"]
*/
includeDirs?: string[];
/**
* File extensions to look for
* @default [".ts", ".js"]
*/
filePatterns?: string[];
/**
* Patterns to exclude from scanning
* @default ["test.", "spec.", ".d.ts"]
*/
exclude?: string[];
/**
* Export organization strategy
* @default { mode: "individual" }
*/
exportStrategy?: {
mode: "individual" | "grouped" | "mixed";
groupBy?: "file" | "folder";
groupPrefix?: string;
};
/**
* What types of exports to include
* @default { functions: true, classes: true, constants: false }
*/
includeTypes?: {
functions?: boolean;
classes?: boolean;
constants?: boolean;
variables?: boolean;
};
/**
* Debug logging level
* @default "minimal"
*/
debugLevel?: "minimal" | "verbose" | "off";
}
// Simple imports
import { getTimestamp, sendEmail, UserService } from "virtual:triggerkit";
triggerkit({
exportStrategy: {
mode: "grouped",
groupBy: "folder", // or "file" or "custom"
groupPrefix: "api",
},
});
// Organized imports
import { api_auth, api_email, api_users } from "virtual:triggerkit";
api_auth.login(credentials);
api_users.getUser(id);
api_email.sendWelcome(email);
// Both individual AND grouped exports available
import {
api_auth, // Grouped
sendEmail, // Individual
UserService, // Individual class
} from "virtual:triggerkit";
Control how much information Triggerkit logs
triggerkit({
debugLevel: "minimal", // Default - clean output
// debugLevel: "verbose" // Detailed debugging info
// debugLevel: "off" // Silent (production)
});
You can access all discovered functions through the functions object:
import { functions } from "virtual:triggerkit";
// Call a discovered function
await functions.sendWelcomeEmail(userId);
// src/lib/server/services.ts
export class PaymentService {
constructor(private apiKey: string) {}
async processPayment<T extends PaymentData>(
data: T,
): Promise<PaymentResult<T>> {
// Your payment logic
}
static validateCard(cardNumber: string): boolean {
// Validation logic
}
}
// In Trigger.dev - full type support!
import { PaymentService } from "virtual:triggerkit";
const service = new PaymentService(process.env.STRIPE_KEY);
const result = await service.processPayment({ amount: 100, currency: "USD" });
Triggerkit automatically handles SvelteKit environment variables:
// SvelteKit code
import { DATABASE_URL } from "$env/static/private";
import { PUBLIC_API_URL } from "$env/static/public";
export async function connectDB() {
// Uses DATABASE_URL automatically
}
// In Trigger.dev - works seamlessly!
import { connectDB } from "virtual:triggerkit";
await connectDB(); // DATABASE_URL is available via process.env
// Generated types preserve everything:
export declare function processUser<T extends User>(
user: T,
options: ProcessOptions,
): Promise<ProcessedUser<T>>;
export declare class UserService {
constructor(apiKey: string);
getUser(id: string): Promise<User>;
static validateEmail(email: string): boolean;
}
Already have SvelteKit functions? No changes needed! Just:
Your existing SvelteKit code works as-is in Trigger.dev.
Contributions are welcome! Please read our Contributing Guide for details on our code of conduct and the process for submitting pull requests.
This project is licensed under the MIT License - see the LICENSE file for details.
Made with ❤️ for the SvelteKit and Trigger.dev communities