Skip to main content
defineDurable() is a function in the open-source @zapier/zapier-durable package. Use it to write a workflow in TypeScript as a series of steps that survive crashes, pause for minutes or days, and pick up where they left off. Deploy your workflow to Zapier and it runs as a Next Gen Zap, an automated workflow on Zapier.
@zapier/zapier-durable is pre-1.0, so expect breaking changes between minor versions. The library is free to run anywhere under the MIT license. Running it on Zapier needs a Zapier account. Next Gen Zaps are included in every Zapier plan. Free accounts get them through a Professional plan trial in December 2026. On an Enterprise plan, an account owner or super admin must first opt in to Next Gen Zaps on the Beta features page of the Admin Center, for each workspace that needs them.

Example

This workflow looks up a user, asks someone to approve their access request, and waits up to 24 hours for an answer:
workflow.ts
fetchUser and sendApprovalRequest stand for your own code, such as a database lookup and a Slack message. Find more examples on GitHub.

How steps and replays work

Think of each step as a save point. When a step finishes, its result is saved to a journal. If the execution stops for any reason, it starts again from the top and reads each saved result instead of running that step again. Your code reaches the point where it stopped without repeating work, such as sending the same email twice. Your code passes a run function to defineDurable(). The run function gets a context object, ctx, with three building blocks. When an execution reaches a wait or a callback, it suspends until it is time to resume. In this execution, the code suspends on a callback. When it resumes, it reads the saved result of step 1 instead of running it again.

Rules for safe replays

  • Put every side effect inside ctx.step(). Code outside a step runs again on every replay.
  • Create random values, timestamps, and IDs inside a step. Outside a step, Math.random() or Date.now() returns a new value on every replay. A check that is on by default, locally and on Zapier, stops the execution with a DeterminismViolation error.
  • Give each step a unique, stable name. The name is how a replay finds the saved result. Two steps with the same name in one execution stop it with a DuplicateNameError.
  • Do not use Promise.race() on steps, waits, or callbacks. A replay cannot guarantee that the same step wins, and the step that loses is still saved as unfinished. Nothing checks for it, so a local test can appear to work. Promise.all() is supported. For a deadline, set timeoutSeconds on the callback and check the result’s status.
  • Use zod 4.2 or later for callback payload schemas. Input and step schemas accept any zod version.

Where your code runs

You can run the same defineDurable() code in three places:
  • On Zapier: your code runs as a Next Gen Zap. Zapier runs each step, saves its result, and resumes the workflow after a wait. Build a Next Gen Zap in code
  • On your servers (push mode): your servers run the code. Zapier saves each step’s result and tells your servers when to resume. It does not create a Next Gen Zap, so it has no versions, triggers, or run history in the Workflow Manager. Run on your own servers
  • Fully on your own: your code runs and saves its own results, with no Zapier account. Use FilesystemClient on one machine, or MemoryClient for tests. Package README on GitHub

Test your workflow locally

Unit test a workflow with MemoryClient from @zapier/zapier-durable/testing. It keeps step results in memory, so you do not need a Zapier account. To test long waits quickly in CI, cap them with test-mode variables:
With these set, a workflow that waits for days finishes in seconds. For details, check test mode in the package README.

Why run it on Zapier

When your workflow runs as a Next Gen Zap, Zapier handles the work around your code: Running on Zapier uses tasks. Each app action and each external call your code makes uses 1 task.

When to write a Next Gen Zap in code

Write a Next Gen Zap in code when your workflow:
  • Has several steps across apps, and a retry must not repeat a step, such as writing the same record twice.
  • Waits for a person or an outside system, such as an approval, before it continues.
  • Belongs in version control, with new versions published from a script or CI pipeline.
  • Is written by your coding agent, and you want to review the code.
Already have a Classic Zap? Run import-workflow to convert it into code. Your Classic Zap keeps running, and the code goes into a draft for you to review and publish.

When to use something else

Build a Next Gen Zap in code

Write a workflow with defineDurable(), test it locally, then deploy it and run it as a Next Gen Zap.

Run on your own servers

Keep your code on your servers while Zapier stores the journal and resumes executions.

Package README on GitHub

Full API, configuration variables, and test mode for @zapier/zapier-durable.

CLI reference

Commands to create Next Gen Zaps, publish versions, and run them from your terminal.
Last modified on December 1, 2026