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

@flowcraft/cloudflare-adapter

v1.0.1

Published

[![NPM Version](https://img.shields.io/npm/v/@flowcraft/cloudflare-adapter.svg)](https://www.npmjs.com/package/@flowcraft/cloudflare-adapter) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

Readme

@flowcraft/cloudflare-adapter

NPM Version License: MIT

A distributed adapter for Flowcraft that uses Cloudflare Queues, Durable Objects, and KV for workflow execution in Cloudflare Workers.

Installation

npm install @flowcraft/cloudflare-adapter

Features

  • Distributed Execution - Run workflows across multiple Cloudflare Workers with reliable job distribution
  • Durable State - Workflow state persists in Durable Objects, surviving worker restarts
  • Atomic Coordination - Support for "all" and "any" join strategies with atomic distributed coordination via Durable Objects
  • Workflow Reconciliation - Automatically detect and resume stalled workflows
  • Status Tracking - Real-time workflow status updates in KV
  • TypeScript Support - Full TypeScript support with type definitions included

Prerequisites

  • Cloudflare Workers account
  • Cloudflare Queues enabled
  • Cloudflare KV namespace for status tracking
  • Durable Object for context and atomic coordination

Usage

1. Set up your Cloudflare resources

# Create a KV namespace for status
wrangler kv:namespace create "flowcraft-status"

# Create a queue
wrangler queues create "flowcraft-jobs"

# Define a Durable Object class in your Worker (see Durable Object Setup)

2. Configure your Worker

// wrangler.toml
name = "flowcraft-worker"
main = "src/index.ts"
compatibility_date = "2024-01-01"

[[kv_namespaces]]
binding = "STATUS"
id = "your-status-namespace-id"

[[queues]]
binding = "JOBS"
queue = "flowcraft-jobs"

3. Create the adapter

import { CloudflareQueueAdapter, DurableObjectCoordinationStore } from '@flowcraft/cloudflare-adapter'

export interface Env {
	STATUS: KVNamespace
	JOBS: Queue
}

// Note: In a real Worker, you'd get the Durable Object stub from env
const mockStorage = { /* your Durable Object storage */ }

// Use DurableObjectCoordinationStore for atomic fan-in joins
const coordinationStore = new DurableObjectCoordinationStore({
	namespace: mockStorage,
})

const adapter = new CloudflareQueueAdapter({
	runtimeOptions: {
		blueprints,
		registry,
	},
	coordinationStore,
	queue: env.JOBS,
	durableObjectStorage: mockStorage,
	statusKVNamespace: env.STATUS,
	queueName: 'flowcraft-jobs',
})

4. Handle queue messages

export default {
	async queue(batch: MessageBatch, env: Env): Promise<void> {
		for (const message of batch.messages) {
			try {
				const job = message.body as JobPayload
				await adapter.handleJob(job)
				message.ack()
			} catch (error) {
				console.error('Failed to process job:', error)
				message.nack()
			}
		}
	},
}

Reconciliation

The Cloudflare adapter includes a reconciliation utility that helps detect and resume stalled workflows. This is particularly useful in production environments where workers might crash or be restarted.

Prerequisites for Reconciliation

To use reconciliation, your status KV namespace must include a lastUpdated field that tracks when workflows were last active. The adapter automatically updates this field during job processing.

Usage

import { createCloudflareReconciler } from '@flowcraft/cloudflare-adapter'

const reconciler = createCloudflareReconciler({
	adapter: myCloudflareAdapter,
	statusKVNamespace: env.STATUS,
	stalledThresholdSeconds: 300, // 5 minutes
})

// Run reconciliation
const stats = await reconciler.run()
console.log(`Found ${stats.stalledRuns} stalled runs, reconciled ${stats.reconciledRuns} runs`)

Reconciliation Stats

The reconciler returns detailed statistics:

interface ReconciliationStats {
	stalledRuns: number    // Number of workflows identified as stalled
	reconciledRuns: number // Number of workflows successfully resumed
	failedRuns: number     // Number of reconciliation attempts that failed
}

How It Works

The reconciler queries the status KV namespace for workflows with status = 'running' that haven't been updated within the threshold period. For each stalled workflow, it:

  1. Loads the workflow's current state from the Durable Object context
  2. Determines which nodes are ready to execute based on completed predecessors
  3. Acquires appropriate locks to prevent race conditions
  4. Enqueues jobs for ready nodes via Cloudflare Queues

This ensures that workflows can be resumed even after worker failures or restarts.

API

CloudflareQueueAdapter

The main adapter class for distributed workflow execution.

Constructor Options

  • runtimeOptions - Flowcraft runtime options (blueprints, registry, etc.)
  • coordinationStore - Durable Object-based coordination store for atomic distributed locking
  • queue - Cloudflare Queue for job distribution
  • durableObjectStorage - Durable Object storage for context persistence
  • statusKVNamespace - KV namespace for workflow status tracking
  • queueName - Name of the Cloudflare Queue

Methods

  • handleJob(job) - Process a single job from the queue (use in your queue handler)
  • reconcile(runId) - Reconcile a workflow run after interruption

DurableObjectContext

A distributed context implementation using Durable Object storage.

const context = new DurableObjectContext('run-123', {
	storage: durableObjectStorage,
	runId: 'run-123',
})

Architecture

Job Queue

Uses Cloudflare Queues for reliable job distribution. The adapter enqueues jobs when workflow nodes are ready to execute.

State Persistence

Uses Durable Objects for context storage. Each workflow run has its own Durable Object that maintains the complete workflow state.

Coordination

Uses Durable Objects for atomic distributed coordination:

  • Atomic fan-in join counting
  • Atomic distributed locking for "any" joins

Status Tracking

Uses a separate KV namespace to track workflow status, including:

  • Current status (running, completed, failed)
  • Last updated timestamp
  • Final result when complete

Differences from Other Adapters

Unlike other Flowcraft adapters that use Docker-based Testcontainers for testing, the Cloudflare adapter:

  1. Uses Miniflare for local development and testing
  2. Requires Cloudflare-specific runtime environments
  3. Uses Durable Objects for coordination instead of Redis/DynamoDB
  4. Uses Durable Objects for context instead of database tables

License

This package is licensed under the MIT License.