tapq-sdk
v0.3.0
Published
Tapq SDK for enqueueing and handling jobs
Readme
tapq
TypeScript SDK for enqueueing background jobs and handling Tapq callbacks.
Install
npm install tapq-sdkUsage
import { Hono } from "hono";
import { defineJob, enqueueJob, makeRequestHandler } from "tapq-sdk";
const app = new Hono();
const sendWelcomeEmailJob = defineJob<
{ userId: string; email: string },
{ delivered: boolean }
>(
"users.send_welcome_email",
async ({ userId, email }) => {
// Replace with your email provider call.
console.log("Sending welcome email", { userId, email });
return { delivered: true };
},
);
const tapqHandler = makeRequestHandler({
jobTypes: [sendWelcomeEmailJob],
onError: (error) => console.error("Tapq handler error:", error),
});
app.post("/signup", async (c) => {
const { email } = await c.req.json<{ email: string }>();
// Replace with your real DB create operation.
const user = { id: crypto.randomUUID(), email };
await enqueueJob(sendWelcomeEmailJob, {
userId: user.id,
email: user.email,
});
return c.json({ ok: true, user }, 201);
});
app.post("/tapq-handler", (c) => tapqHandler(c.req.raw));
export default app;Environment variables
TAPQ_API_URL(default:http://localhost:4000)TAPQ_API_KEY(required in production and used to authorize/tapq-handler)
