Wala pang Filipino na bersyon ang page na ito, kaya naka-English muna.
Scheduled jobs and plugin API routes
Jobs run from the maintenance tick; API routes are published under /api/plugins/<id> and must authenticate every call.
Jobs
Declare { id, everyMinutes } in module.json → jobs and implement register().jobs[<id>]: async (ctx) => string | void with ctx = { pluginId, log, now }. The maintenance tick (every 5 minutes by default) runs each job whose interval has elapsed, so the real granularity is about 5 minutes. The returned string (≤ 500 chars) is shown as the last result; Run now is on the plugin page.
jobs: {
"today-digest": async (ctx) => {
const start = new Date(ctx.now); start.setUTCHours(0, 0, 0, 0);
const end = new Date(start); end.setUTCDate(end.getUTCDate() + 1);
const n = await prisma.siteVisit.count({ where: { status: "PLANNED", plannedAt: { gte: start, lt: end } } });
return n + " visit(s) today";
},
},pluginStore. For “on every event” work use a hook instead of polling.API routes
app/api/<path>/route.ts exporting GET / POST / … is published at /api/plugins/<id>/<path>. The generated wrapper answers 404 while the plugin is disabled and 405 for methods you do not export. The proxy's api rate limit (300 burst, 5 req/s per IP) applies.
import { NextResponse } from "next/server";
import { currentUser, can } from "@/lib/auth/guards";
import { prisma } from "@/lib/prisma";
export async function GET() {
const user = await currentUser();
if (!user || !can(user, "sitevisits.view")) return NextResponse.json({ error: "forbidden" }, { status: 403 });
const rows = await prisma.siteVisit.findMany({ where: { status: "PLANNED" }, orderBy: { plannedAt: "asc" }, take: 50 });
return NextResponse.json({ data: rows.map((r) => ({ id: r.id, customerName: r.customerName, plannedAt: r.plannedAt })) });
}Authentication: use the session (currentUser + can) for calls from the admin, or a plugin-issued token stored hashed in pluginStore for machine clients. The REST API v1 key checker is not exported for plugins yet. Always validate the body with zod and never echo secrets.
Written from: docs/PLUGIN-DEVELOPER-GUIDE.md, docs/PLUGINS.md, modules/example-checklist/app/api/items/route.ts, src/lib/plugins/types.ts