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

cf-workflow-rollback

v1.5.0

Published

Saga-pattern rollback utility for Cloudflare Workflows

Readme

cf-workflow-rollback

Saga-pattern rollback utility for Cloudflare Workflows.

Installation

npm install cf-workflow-rollback
# or
bun add cf-workflow-rollback

Usage

import { WorkflowEntrypoint, type WorkflowEvent, type WorkflowStep } from "cloudflare:workers";
import { withRollback } from "cf-workflow-rollback";

export class MyWorkflow extends WorkflowEntrypoint<Env, Params> {
  async run(event: WorkflowEvent<Params>, workflowStep: WorkflowStep) {
    const step = withRollback(workflowStep);

    try {
      // Regular step (no rollback needed)
      const data = await step.do("fetch data", async () => {
        return fetchExternalData();
      });

      // Step with rollback - if a later step fails, this will be undone
      const id = await step.doWithRollback("save to database", {
        run: async () => {
          return await db.insert(data);
        },
        undo: async (error, id) => {
          await db.delete(id);
        },
      });

      // Another step with rollback
      await step.doWithRollback("charge payment", {
        run: async () => {
          return await payments.charge(event.payload.amount);
        },
        undo: async (error, chargeId) => {
          await payments.refund(chargeId);
        },
      });

      // Final step (no rollback - if this fails, previous steps are undone)
      await step.do("send confirmation", async () => {
        await sendEmail(event.payload.email);
      });

    } catch (error) {
      // Rollback all successful steps in reverse order
      await step.rollbackAll(error);

      // Optionally: cleanup steps that always run on failure
      await step.do("notify failure", async () => {
        await sendFailureNotification();
      });

      throw error;
    }
  }
}

API

withRollback(workflowStep: WorkflowStep)

Wraps a Cloudflare Workflow step with rollback capabilities.

Returns an object with:

| Method | Description | |--------|-------------| | do(name, callback) | The original step.do method | | do(name, config, callback) | The original step.do method with config | | doWithRollback(name, handler, config?) | Execute a step with an undo handler | | rollbackAll(error) | Execute all registered undo handlers in LIFO order |

RollbackHandler<T>

type RollbackHandler<T> = {
  run: () => Promise<T>;
  undo: (err: unknown, value: T) => Promise<void>;
};
  • run - The step function to execute
  • undo - Called with the error and the return value of run if a later step fails

How It Works

This utility implements the Saga pattern for Cloudflare Workflows:

  1. Each doWithRollback step registers an undo handler after successful execution
  2. Undo handlers are stored in a LIFO (last-in-first-out) stack
  3. On failure, rollbackAll executes undo handlers in reverse order
  4. Each undo operation is wrapped in step.do for durability and retry

Replay Safety

The undo stack is correctly rebuilt on workflow replay because:

  • step.do returns cached results for completed steps
  • Undo handlers are registered after each successful step
  • The same sequence of steps produces the same undo stack

License

MIT