npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@map-colonies/jobnik-sdk

v0.3.0

Published

Map Colonies Jobnik SDK

Readme

Jobnik SDK

TypeScript SDK for interacting with the Jobnik job management system. Provides type-safe clients for creating jobs, processing tasks, and monitoring workflows with built-in observability and resilience patterns.

Features

  • Type-Safe API: Full TypeScript support with custom job and stage type definitions
  • Producer Client: Create and manage jobs, stages, and tasks
  • Worker Client: Automated task processing with configurable concurrency
  • Circuit Breaker Protection: Built-in resilience for handling failures
  • Observability: Prometheus metrics and OpenTelemetry distributed tracing
  • Graceful Shutdown: Coordinated shutdown with running task completion

Installation

npm install @map-colonies/jobnik-sdk

Requirements: Node.js >= 24

Quick Start

Initialize the SDK

import { JobnikSDK } from '@map-colonies/jobnik-sdk';

const sdk = new JobnikSDK({
  baseUrl: 'https://api.jobnik.example.com'
  metricsRegistry: new Registry()
});

Define Custom Types (Optional)

interface MyJobTypes {
  'image-processing': {
    userMetadata: { userId: string };
    data: { imageUrl: string };
  };
}

interface MyStageTypes {
  'resize': {
    userMetadata: { quality: number };
    data: { width: number; height: number };
    task: {
      userMetadata: { batchId: string };
      data: { sourceUrl: string; targetPath: string };
    };
  };
}

const sdk = new JobnikSDK<MyJobTypes, MyStageTypes>({
  baseUrl: 'https://api.jobnik.example.com'
  metricsRegistry: new Registry()
});

Create Jobs (Producer)

const producer = sdk.getProducer();

// Create a job
const job = await producer.createJob({
  name: 'image-processing',
  data: { imageUrl: 'https://example.com/image.jpg' },
  userMetadata: { userId: 'user-123' },
  priority: 'HIGH'
});

// Add a stage to the job
const stage = await producer.createStage(job.id, {
  type: 'resize',
  data: { width: 800, height: 600 },
  userMetadata: { quality: 90 }
});

// Add tasks to the stage
const task = await producer.createTask(stage.id, {
  data: { sourceUrl: 'https://example.com/image.jpg', targetPath: '/output/resized.jpg' },
  userMetadata: { batchId: 'batch-1' }
});

Process Tasks (Worker)

// Define task handler
const taskHandler = async (task, context) => {
  const { sourceUrl, targetPath } = task.data;
  
  context.logger.info('Processing task', { taskId: task.id });
  
  // Your processing logic here
  await resizeImage(sourceUrl, targetPath);
  
  // Check for cancellation during shutdown
  if (context.signal.aborted) {
    throw new Error('Task cancelled');
  }
};

// Create and start worker using the SDK
const worker = sdk.createWorker(
  'resize',
  taskHandler,
  {
    concurrency: 5,
    backoffOptions: {
      initialBaseRetryDelayMs: 1000,
      maxDelayMs: 60000,
      backoffFactor: 2
    }
  }
);

await worker.start();

// Graceful shutdown
process.on('SIGTERM', async () => {
  await worker.stop();
});

Observability

Prometheus Metrics

import { Registry } from 'prom-client';

const registry = new Registry();
const sdk = new JobnikSDK({
  baseUrl: 'https://api.jobnik.example.com',
  metricsRegistry: registry
});

// Expose metrics endpoint
app.get('/metrics', async (req, res) => {
  res.set('Content-Type', registry.contentType);
  res.send(await registry.metrics());
});

OpenTelemetry Tracing

The SDK automatically creates spans for all operations when OpenTelemetry is configured in your application. Trace context is propagated through jobs, stages, and tasks.

Configuration Options

const sdk = new JobnikSDK({
  baseUrl: string;                    // Required: Jobnik API base URL
  httpClientOptions?: {               // Optional: HTTP client configuration
    retry?: {                         // Retry configuration
      maxRetries?: number;            // Maximum number of retries
      statusCodes?: number[];         // HTTP status codes to retry
      errorCodes?: string[];          // Error codes to retry
      initialBaseRetryDelayMs?: number; // Initial base delay in ms
      disableJitter?: boolean;        // Disable random jitter in delay
      maxJitterFactor?: number;       // Maximum jitter factor
    };
    agentOptions?: Agent.Options;     // HTTP agent options
  };
  logger?: Logger;                    // Optional: Custom logger (defaults to NoopLogger)
  metricsRegistry: Registry;          // Required: Prometheus registry for metrics
});

Documentation

Full API documentation is available at https://mapcolonies.github.io/jobnik-sdk/

License

ISC