@azsiaz/jobs-kit (0.1.0)

Published 2026-04-19 17:56:34 +02:00 by AzSiAz in AzSiAz/jobs-kit

Installation

@azsiaz:registry=
npm install @azsiaz/jobs-kit@0.1.0
"@azsiaz/jobs-kit": "0.1.0"

About this package

@azsiaz/jobs-kit

Typed BullMQ job runtime for declaring jobs with Zod validation, dispatching them with inferred inputs, registering typed workers, composing flows, applying job-local deduplication, enforcing keyed Redis-backed rate limits, and querying normalized dashboard data.

import { z } from "zod"
import { createBullmqRuntime, createRegistry, defineJob, defineLimiter, defineLimiters } from "@azsiaz/jobs-kit"

const limiters = defineLimiters({
  tenant: defineLimiter({
    windowMs: 60_000,
    max: 30,
    key: z.object({ tenantId: z.string() }),
  }),
})

const sendEmail = defineJob({
  key: "sendEmail",
  queue: "outbound",
  input: z.object({
    tenantId: z.string(),
    to: z.string().email(),
    subject: z.string(),
  }),
  result: z.object({ messageId: z.string() }),
  dedup: {
    mode: "unique",
    select: input => ({ tenantId: input.tenantId, to: input.to, subject: input.subject }),
  },
  limits: [
    limiters.tenant(input => ({ tenantId: input.tenantId })),
  ],
})

const registry = createRegistry({ limiters, jobs: { sendEmail } })

const runtime = createBullmqRuntime({
  registry,
  connection: { host: "127.0.0.1", port: 6379 },
  prefix: "app",
})

await runtime.dispatch("sendEmail", {
  tenantId: "t_123",
  to: "hello@example.com",
  subject: "Hi",
})

runtime.registerWorker("sendEmail", async ({ input }) => {
  return { messageId: "msg_123" }
})

Run npm run check before publishing.

CI and publishing

Woodpecker runs the full suite with Redis available at redis://redis:6379.

Publishing is limited to tag builds and targets the Forgejo npm registry:

https://forge.netserv.fr/api/packages/AzSiAz/npm/

Configure this Woodpecker secret before publishing:

forgejo_npm_token

The token must belong to the Forgejo package owner and have permission to publish packages.

Dependencies

Dependencies

ID Version
bullmq ^5.74.1
ioredis ^5.8.2

Development dependencies

ID Version
@types/node ^24.10.1
tsd ^0.33.0
typescript ^5.9.3
vitest ^4.0.15
zod ^4.3.6

Peer dependencies

ID Version
zod ^4.3.6
Details
npm
2026-04-19 17:56:34 +02:00
4
MIT
22 KiB
Assets (1)
Versions (7) View all
3.0.0 2026-05-28
2.0.1 2026-05-27
2.0.0 2026-05-17
1.0.0 2026-05-17
0.3.0 2026-04-20