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

@kowalski21/infra-workflow

v0.1.0

Published

Standalone Medusa workflows-sdk infrastructure: Redis/BullMQ transaction storage, event bus with file-loaded subscribers, and an awilix container bridge

Readme

infra-workflow

Standalone infrastructure for running Medusa's workflows-sdk outside a Medusa app — in any Node service (Express, Hono, Fastify, plain scripts):

  • RedisTransactionStorage — durable workflow checkpoints on Redis + BullMQ: restart-surviving retries, step/transaction timeouts, async (pause/resume) steps, and cron/interval-scheduled workflows.
  • RedisEventBus / LocalEventBus — a BullMQ event bus with at-least-once delivery, per-subscriber retry tracking, and an in-process drop-in for tests/scripts that needs no Redis.
  • loadSubscribers — file-convention subscriber loading (default handler + config export per file).
  • toWorkflowContainer / fromWorkflowContainer — bridges any awilix container (v8–v13 tested) to the MedusaContainer interface the sdk expects, including its internal-symbol parent access and allowUnregistered resolves.

Everything is peer-depended: the package adds no runtime dependencies of its own.

ioredis version: BullMQ pins ioredis exactly. Keep your app's ioredis pinned to the same version as your BullMQ's (e.g. "ioredis": "5.10.1"), or its types will reject your connections.

Install

// package.json of the consuming app
"dependencies": {
  "@kowalski21/infra-workflow": "^0.1.0",
  "@medusajs/workflows-sdk": "^2.15.5",
  "@medusajs/orchestration": "^2.15.5",
  "@medusajs/types": "^2.15.5",
  "@medusajs/utils": "^2.15.5",
  "awilix": "^13",
  "bullmq": "^5",
  "ioredis": "5.10.1"
}

Wiring (server entrypoint)

import {
  DistributedTransaction, WorkflowScheduler
} from "@medusajs/orchestration";
import {
  createRedisConnections, RedisEventBus, RedisTransactionStorage, loadSubscribers
} from "@kowalski21/infra-workflow";

const { redisClient, redisWorkerConnection } = createRedisConnections(REDIS_URL);

const eventBus = new RedisEventBus({ redisClient, redisWorkerConnection, logger });
container.register({ eventBus: asValue(eventBus) });

// Optional: how background executions (retries, scheduled runs, event
// handlers) build their DI scope — register per-execution values here.
const createScope = (root) => {
  const scope = root.createScope();
  scope.register({ requestId: asValue(`bg_${crypto.randomUUID()}`) });
  return scope;
};

const storage = new RedisTransactionStorage({
  redisClient, redisWorkerConnection, container, createScope, logger
});
DistributedTransaction.setStorage(storage);
WorkflowScheduler.setStorage(storage);

await storage.onApplicationStart();
await loadSubscribers(subscribersDir, eventBus, container, { logger, createScope });
eventBus.start();

// shutdown order:
//   storage.onApplicationPrepareShutdown() → eventBus.shutdown()
//   → storage.onApplicationShutdown() → redis connections .quit()

For tests and scripts, register new LocalEventBus(logger) instead — no Redis required, and the default in-memory workflow storage handles synchronous workflows.

Running a workflow with your container

import { toWorkflowContainer, fromWorkflowContainer } from "@kowalski21/infra-workflow";

// in a route handler — pass your (scoped) awilix container:
const { result, errors } = await myWorkflow(toWorkflowContainer(requestScope))
  .run({ input, throwOnError: false });

// inside a step — cast back to your container type:
const scope = fromWorkflowContainer<AppContainer>(container);
const service = scope.resolve("myService");

Error mapping caveat: errors thrown inside steps are serialized by the orchestrator and lose their prototype chain. Match on error.name, not instanceof.

Subscriber files

// subscribers/order-created.ts
import type { SubscriberArgs, SubscriberConfig } from "@kowalski21/infra-workflow";

export default async function handleOrderCreated({
  event, container
}: SubscriberArgs<{ orderId: string }, AppContainer>) {
  await container.resolve("notifier").send(event.data.orderId);
}

export const config: SubscriberConfig = { event: "order.created" };

Subscriber failures retry (3 attempts, exponential backoff) and never propagate to the emitter — side-effects whose failure must roll back the operation belong in the workflow as a compensated step, not in a subscriber.