
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
XState v5 Actor Mailbox - Queue and process messages sequentially for XState machines
XState v5 Actor Mailbox - Queue and process messages sequentially for XState machines.
👉 Blog Post: From Message Chaos to Order: How I Rebuilt the Mailbox Library for XState@5, Huan, 2026, Ship.Fail
Mailbox implements the Actor Mailbox pattern on top of XState v5:
Mailbox.actions.idle() to receive next messagenpm install mailbox xstate
Requirements: Node.js >= 18, XState >= 5.0.0
import * as Mailbox from 'mailbox'
import { setup, assign } from 'xstate'
// Create a machine that processes work one item at a time
const workerMachine = setup({
types: {} as {
context: { result: string | null }
events: { type: 'WORK'; data: string } | { type: 'DONE'; result: string | null }
},
}).createMachine({
id: 'worker',
initial: 'idle',
context: { result: null },
states: {
idle: {
// RULE 1: Signal readiness in idle state
entry: Mailbox.actions.idle('worker'),
on: {
WORK: 'processing',
},
},
processing: {
entry: assign({ result: ({ event }) => event.data }),
after: {
100: {
target: 'idle',
// RULE 2: Reply when done
actions: Mailbox.actions.reply(
({ context }) => ({ type: 'DONE', result: context.result })
),
},
},
},
},
})
// Wrap with mailbox
const mailbox = Mailbox.from(workerMachine)
// Subscribe to replies
mailbox.subscribe({
next: (event) => console.log('Reply:', event),
})
// Open and send messages
mailbox.open()
mailbox.send({ type: 'WORK', data: 'task1' })
mailbox.send({ type: 'WORK', data: 'task2' })
mailbox.send({ type: 'WORK', data: 'task3' })
// All 3 will be processed sequentially, each receiving a DONE reply
Idle Action: Your machine MUST call Mailbox.actions.idle('machine-id') in the entry action of the state where it's ready to accept messages.
External Transitions: Use external transitions to re-enter the idle state, triggering the entry action again.
Reply Action: Use Mailbox.actions.reply(event) to send responses back to the message sender.
Mailbox.from(machine, options?)Wraps an XState machine with mailbox functionality.
const mailbox = Mailbox.from(machine, {
capacity: 100, // Max queue size (default: Infinity)
logger: console.log, // Custom logger
clock: new SimulatedClock(), // For testing
})
mailbox.send(event)Send an event to the mailbox queue.
mailbox.open() / mailbox.close()Start/stop the mailbox actor.
mailbox.subscribe(observer)Subscribe to outgoing events (replies).
mailbox.addressGet the mailbox address for external communication.
Mailbox.actions.idle(id) - Signal the machine is ready for next messageMailbox.actions.reply(event) - Reply to the message senderMailbox.actions.proxy(id)(target) - Forward events to another mailboxMailbox.isMailbox(value) - Check if value is a MailboxMailbox.isAddress(value) - Check if value is an AddressMailbox.isMailboxType(type) - Check if event type is internal Mailbox typeMailbox.Type - Internal event types (ACTOR_IDLE, ACTOR_REPLY, DEAD_LETTER)Mailbox.Event - Event factory functionsMailbox.State - Mailbox states (Idle, Processing)// Validate a machine satisfies the Mailbox protocol
Mailbox.validate(myMachine) // throws MailboxValidationError if invalid
Mailbox implements the Observable protocol for RxJS interoperability:
import { from } from 'rxjs'
import * as Mailbox from 'mailbox'
const mailbox = Mailbox.from(machine)
mailbox.open()
// Use RxJS operators
from(mailbox)
.pipe(filter(e => e.type === 'DONE'))
.subscribe(console.log)
Use SimulatedClock for deterministic tests:
import * as Mailbox from 'mailbox'
const clock = new Mailbox.SimulatedClock()
const mailbox = Mailbox.from(machine, { clock })
mailbox.open()
mailbox.send({ type: 'WORK' })
// Advance time
clock.increment(100)
await new Promise(r => setTimeout(r, 0))
// Assert results...
XState machines process events immediately. When multiple events arrive while processing, they can be lost:
Customer A: MAKE_COFFEE → Processing...
Customer B: MAKE_COFFEE → LOST! (machine is busy)
Customer C: MAKE_COFFEE → LOST! (machine is busy)
With Mailbox, events are queued and processed sequentially:
Customer A: MAKE_COFFEE → Queued → Processing → Done
Customer B: MAKE_COFFEE → Queued → Processing → Done
Customer C: MAKE_COFFEE → Queued → Processing → Done
This version is a complete rewrite for XState v5. Breaking changes from v0.x:
duckularize() - Use native XState v5 typed events insteadwrap() - Use from() insteadBefore (v0.x):
import { createAction } from 'typesafe-actions'
const Event = { DING: createAction('DING')() }
const duckula = Mailbox.duckularize({ id: 'test', events: Event, ... })
After (v1.0):
// Use plain objects and XState v5 native typing
const Type = { DING: 'DING' } as const
const Event = { DING: () => ({ type: Type.DING }) as const }
const machine = setup({
types: { events: {} as { type: 'DING' } }
}).createMachine({ ... })
Apache-2.0
FAQs
XState v5 Actor Mailbox - Queue and process messages sequentially for XState machines
The npm package mailbox receives a total of 16 weekly downloads. As such, mailbox popularity was classified as not popular.
We found that mailbox demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.