Skip to content

bclaud/jobsdone-node

Repository files navigation

jobsdone-sdk

Official Node.js / TypeScript SDK for the Jobs Done API -- a cron-as-a-service platform.

  • Zero runtime dependencies (uses native fetch, Node.js 18+)
  • Full TypeScript support with generated types
  • Webhook signature verification included

Installation

npm install jobsdone-sdk

Quick Start

import { createClient } from 'jobsdone-sdk';

const client = createClient({
  apiKey: process.env.JOBSDONE_API_KEY!,
});

// Create a cron job
const cron = await client.createCron({
  logicId: 'daily-report-001',
  name: 'Daily Report',
  cronExpression: '0 9 * * *',
  webhookUrl: 'https://example.com/hooks/report',
});

// Enqueue a one-off job
await client.enqueue({
  logicId: 'send-email-user-123',
  description: 'Welcome email for new user',
});

API Reference

Configuration

const client = createClient({
  apiKey: 'your-api-key',             // required
  baseUrl: 'https://jobsdone.claudlabs.com', // optional, this is the default
});

Users

client.createUser(name)        // POST /api/users
client.getMe()                 // GET /api/users/me
client.getStats()              // GET /api/users/me/stats

Cron Jobs

client.listCrons()                   // GET /api/crons
client.createCron(data)              // POST /api/crons
client.getCron(logicId)              // GET /api/crons/:id
client.updateCron(logicId, data)     // PATCH /api/crons/:id
client.deleteCron(logicId)           // DELETE /api/crons/:id
client.pauseCron(logicId)            // PATCH /api/crons/:id/pause
client.resumeCron(logicId)           // PATCH /api/crons/:id/resume

Jobs

client.listJobs()              // GET /api/jobs
client.getJob(logicId)         // GET /api/jobs/:id
client.enqueue(data)           // POST /api/enqueue
client.cancelJob(logicId)      // DELETE /api/jobs/:id

Webhook Verification

Verify that incoming webhooks are genuinely from Jobs Done:

import { verifyWebhookSignature } from 'jobsdone-sdk';

// In your webhook handler (e.g. Express)
app.post('/webhooks/jobs-done', express.raw({ type: 'application/json' }), (req, res) => {
  const signature = req.headers['x-jobsdone-signature'] ?? '';
  const isValid = verifyWebhookSignature(WEBHOOK_SECRET, req.body, signature);

  if (!isValid) {
    return res.status(401).json({ error: 'Invalid signature' });
  }

  const payload = JSON.parse(req.body.toString());
  // Process webhook...
  res.status(200).json({ ok: true });
});

Testing with Mocks

The SDK ships a mock client for unit tests -- no network calls needed:

import { createMockClient } from 'jobsdone-sdk';

const mock = createMockClient({
  createCron: async (data) => ({
    logicId: data.logicId,
    name: data.name,
    cronExpression: data.cronExpression,
    // ...
  }),
});

// Use `mock` wherever your code expects a JobsDoneClient

Development

npm install    # install dev dependencies
npm run build  # compile TypeScript

Regenerating types from OpenAPI spec

The src/generated/ directory is auto-generated from the server's OpenAPI spec. To regenerate:

openapi-generator-cli generate \
  -g typescript \
  -i path/to/openapi.json \
  -o src/generated \
  --additional-properties=modelPropertyNaming=camelCase,enumPropertyNaming=PascalCase,supportsES6=true

License

MIT

About

Official Node.js SDK for the Jobs Done API

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages