Progressive Delivery Library

The @contractspec/lib.progressive-delivery package helps you ship new specs with confidence: canary + blue-green strategies, metric guardrails, and rollback hooks in one place.

Installation

bun add @contractspec/lib.progressive-delivery

Define a Strategy

import { DeploymentCoordinator, createDefaultCanaryController, TrafficShifter, RollbackManager } from '@contractspec/lib.progressive-delivery';

const strategy = {
  target: { name: 'billing.createInvoice', version: 7 },
  mode: 'canary',
  thresholds: {
    errorRate: 0.01,
    latencyP99: 500,
    latencyP95: 250,
  },
};

Run the Coordinator

const eventBus = new DeploymentEventBus();
const controller = createDefaultCanaryController(strategy, fetchMetrics, eventBus);
const coordinator = new DeploymentCoordinator({
  strategy,
  controller,
  trafficShifter: new TrafficShifter(strategy.mode),
  rollbackManager: new RollbackManager({ rollback: revertSpec }),
  applyTrafficSplit: updateFeatureFlag,
  eventBus,
});

const result = await coordinator.run();

The coordinator emits stage_started, stage_failed, and rolled_back events, making it easy to power dashboards or alerting workflows.

Blue-Green Swap

Switch to mode: 'blue-green' to warm up the new stack in parallel and cut over once smoke tests pass. The same guardrails apply before the final swap.