[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-116909":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":9,"language":10,"languages":9,"totalLinesOfCode":9,"stars":11,"forks":12,"watchers":13,"openIssues":12,"contributorsCount":12,"subscribersCount":12,"size":12,"stars1d":12,"stars7d":14,"stars30d":14,"stars90d":12,"forks30d":12,"starsTrendScore":14,"compositeScore":15,"rankGlobal":9,"rankLanguage":9,"license":16,"archived":17,"fork":17,"defaultBranch":18,"hasWiki":17,"hasPages":17,"topics":19,"createdAt":9,"pushedAt":32,"updatedAt":33,"readmeContent":34,"aiSummary":9,"trendingCount":12,"starSnapshotCount":12,"syncStatus":35,"lastSyncTime":36,"discoverSource":37},116909,"durable","zapier\u002Fdurable","zapier","Durable execution for TypeScript and Node.js. Write workflows as plain async code with replayable steps, callbacks, and waits that survive restarts. Powers Zaps. Runs on Zapier or your own compute.",null,"TypeScript",69,0,52,4,42.4,"MIT License",false,"main",[20,21,22,23,24,25,26,27,28,29,30,7,31],"ai-agents","durable-execution","durable-workflows","human-in-the-loop","long-running-tasks","nodejs","npm-package","typescript","workflow-automation","workflow-engine","workflow-orchestration","zapier-sdk","2026-11-19 16:19:43","2026-11-23 20:04:34","# @zapier\u002Fzapier-durable\n\nDurable execution for the Zapier SDK. Pluggable adapter model for different runtimes.\n\n> **Pre-1.0**: This package is published on the `latest` dist-tag while the API\n> stabilises. Expect breaking changes between minor versions until 1.0.\n\n## Features\n\n- **Clean ergonomics**: Two consistent call styles everywhere (`({ name, run, ...options })` or `(name, run)`)\n- **Optional schemas**: zod schemas for the input, a step's result and a callback's payload. Input and step schemas take any zod version; callback payload schemas need zod 4.2 or later. Schemas are always optional; without one, the input is typed `Record\u003Cstring, unknown>`\n- **Adapter-based**: Pluggable for different runtimes\n\n## Installation\n\n```bash\npnpm add @zapier\u002Fzapier-durable\n```\n\n## Quick Start\n\n```typescript\nimport { defineDurable } from \"@zapier\u002Fzapier-durable\";\nimport { z } from \"zod\";\n\nconst myDurable = defineDurable({\n  name: \"my-durable\",\n  description: \"My durable example\",\n  inputSchema: z.object({ userId: z.string() }),\n  run: async (ctx, input) => {\n    \u002F\u002F Steps are durable - they only run once even if the execution replays\n    const result = await ctx.step(\"fetch-data\", async () => {\n      const response = await fetch(\"https:\u002F\u002Fapi.example.com\u002Fdata\");\n      return response.json();\n    });\n\n    \u002F\u002F Create a callback for external approval\n    const [approvalPromise, callbackUrl] = await ctx.createCallback({\n      name: \"wait-for-approval\",\n      payloadSchema: z.object({ approved: z.boolean() }),\n    });\n\n    \u002F\u002F Send the callback URL (wrapped in a step so it only runs once)\n    await ctx.step(\"notify-approver\", async () => {\n      await notifyApprover(callbackUrl);\n    });\n\n    \u002F\u002F Wait for the callback to be delivered\n    const approval = await approvalPromise;\n\n    if (!approval.approved) {\n      throw new Error(\"Not approved\");\n    }\n\n    return { approved: true, userId: input.userId };\n  },\n});\n\nconst response = await myDurable({ userId: \"123\" });\n\n\u002F\u002F Technically, we'd wait for an approval callback, and resume with the execution ID:\n\u002F\u002F   await myDurable(response.executionId)\n\u002F\u002F ...but imagine we had instant approval!\n\nif (response.done) {\n  console.log(response.result);\n  \u002F\u002F { approved: true, userId: \"123\" }\n} else {\n  console.log(response.error);\n  \u002F\u002F { message: \"Not approved\", name: \"Error\", stack?: string }\n}\n```\n\n## CLI\n\nDurable runs are executed remotely on code-substrate-runner via the Zapier\nSDK CLI, gated behind the experimental stability tier: `run-durable`,\n`get-durable-run`, `list-durable-runs`, and `cancel-durable-run`. Opt in with\n`--stability experimental`, or `ZAPIER_STABILITY=experimental` in the\nenvironment. See the\n[CLI reference](https:\u002F\u002Fdocs.zapier.com\u002Fsdk\u002Fcli-reference#next-gen-zaps-experimental)\nfor the full command list and options, or run `--help` for any command\n(the opt-in is required even for `--help`, since these commands aren't\nregistered on the stable CLI surface):\n\n```bash\nnpx zapier-sdk run-durable --help --stability experimental\n```\n\n## Running outside Zapier\n\ndefineDurable is a library, and it runs anywhere Node.js runs. You can run it\nin three ways:\n\n- **On Zapier.** Zapier's hosted runner runs your code, keeps the journal, and\n  resumes each execution for you. This is how Next Gen Zaps run: a Next Gen\n  Zap's code is a `defineDurable` workflow, and the runner runs it with a\n  pinned version of this package. See\n  [Create your first Next Gen Zap](https:\u002F\u002Fdocs.zapier.com\u002Fmcp\u002Fget-started\u002Fbuild-a-workflow).\n- **Bring your own compute (push mode).** Zapier's runner keeps the journal and\n  tells your servers when to resume. Your code runs on your servers. See\n  [Bring your own compute](#bring-your-own-compute-push-mode).\n- **Fully on your own.** Your process runs the code and keeps the journal. This\n  needs no Zapier account. See [Fully on your own](#fully-on-your-own).\n\n### Bring your own compute (push mode)\n\nZapier's runner keeps the journal and schedules each wake. Your code runs on\nyour servers. Use a `RestClient` with a Zapier SDK token, and set\n`notificationUrl` to a public URL on your servers:\n\n```typescript\nimport { RestClient } from \"@zapier\u002Fzapier-durable\";\nimport { resolveAuthToken } from \"@zapier\u002Fzapier-sdk\";\n\n\u002F\u002F Reads the token that `npx zapier-sdk login` stores, or ZAPIER_CREDENTIALS.\nconst token = await resolveAuthToken();\nconst client = new RestClient({\n  token: token!,\n  notificationUrl: \"https:\u002F\u002Fmy-app.example.com\u002Fdurable\u002Fresume\",\n});\n\nconst first = await myDurable({ userId: \"u_123\" }, { client });\nawait myExecutions.add(first.executionId!);\n```\n\n`myExecutions` stands for the store where your app keeps the IDs of the\nexecutions it started.\n\nWhen a wait ends or a callback arrives, the runner POSTs\n`{ \"execution_id\": \"...\" }` to the notification URL. The POST can arrive up to\na minute later. Resume the execution in that handler:\n\n```typescript\n\u002F\u002F In the handler for POST \u002Fdurable\u002Fresume:\nconst { execution_id } = JSON.parse(body);\n\u002F\u002F The POST is unauthenticated: only resume IDs your app recorded when it started them.\nif (\n  typeof execution_id !== \"string\" ||\n  !(await myExecutions.has(execution_id))\n) {\n  return; \u002F\u002F reply 2xx and do nothing\n}\nawait myDurable(execution_id, { client });\n```\n\n- The notification URL must be public. The runner does not follow redirects.\n- Reply with a 2xx status. After 5 failed deliveries in a row, the runner fails\n  the execution. A `410` reply stops the wakes.\n- The POST carries no credentials. Treat it as a signal, and check that\n  `execution_id` is an execution you started.\n- Zapier's runner must be enabled for your Zapier account.\n\n### Fully on your own\n\nYour process runs the code, as in push mode. It also does the runner's part:\nit keeps the journal and decides when to resume each execution. This needs no\nZapier account.\n\n**Storage.** Pass a client to choose where the journal lives:\n\n- `FilesystemClient` keeps each execution's journal in a directory on local\n  disk. Use it from a single process: it always grants the lease, so it does\n  not stop two workers from running the same execution.\n- `MemoryClient` keeps the journal in memory. Use it in tests.\n- For production, keep the journal in Postgres, MySQL, or SQLite. Write a\n  `DurableClient` for your database: the `callbackBaseUrl` property and the\n  `create`, `checkout`, `checkpoint`, `release`, and `callback` methods. The\n  interface is small, and `MemoryClient` and `FilesystemClient` implement the\n  same one. `checkout` must return each operation with its current status: a\n  wait whose time has passed is completed, and a callback whose timeout has\n  passed is expired. It also takes a lease. Return `{ leased: false }` while\n  another worker holds an unexpired lease, so several workers can share one\n  store without running the same execution at the same time.\n\n**Running.** Call a durable with input to start an execution. It runs until\nit completes or suspends. Call it with the execution ID to resume it:\n\n```typescript\nimport { FilesystemClient } from \"@zapier\u002Fzapier-durable\";\n\nconst client = new FilesystemClient({ baseDir: \"\u002Fvar\u002Flib\u002Fmy-app\u002Fdurable\" });\n\nconst first = await myDurable({ userId: \"u_123\" }, { client });\n\u002F\u002F Later, after a wait ends or a callback arrives:\nconst next = await myDurable(first.executionId!, { client });\nconsole.log(next.done ? next.result : \"still waiting\");\n```\n\n**Scheduling.** The library does not include a scheduler. Your process keeps\nthe IDs of suspended executions. It resumes each one when its wait ends (the\njournal records each wait's `resume_at`) or after it delivers a callback with\n`client.callback(token, payload)`. On Zapier and in push mode, Zapier's runner\ndecides when to resume.\n\n## API\n\n### `defineDurable`\n\nDefine a durable execution with optional input\u002Foutput schemas.\n\n```typescript\n\u002F\u002F Object signature, preferred\ndefineDurable({ name, inputSchema?, run, description?, outputSchema? })\n\n\u002F\u002F Positional signature\ndefineDurable(name, run)\n```\n\n**Options:**\n\n- `inputSchema?` - Optional zod schema for the input, from any zod version. It types `input` in `run`, and Zapier reads it to find the workflow's input fields, so write it with zod in the workflow's file. It is checked only when you call the workflow directly with an input object, not when Zapier starts a run, and `run` gets the input as passed. Parse it in `run` when you need validation, defaults or transforms\n- `outputSchema?` - Optional zod schema for output validation, from any zod version\n- `description?: string` - Optional description for the durable\n\n### `ctx.step`\n\nExecute a durable step. Steps are memoized - they only execute once even if the execution replays.\n\n```typescript\n\u002F\u002F Simple signature\nawait ctx.step(name, run)\n\n\u002F\u002F Object signature with options\nawait ctx.step({ name, run, outputSchema?, maxAttempts?, retryDelaySeconds? })\n```\n\n**Options:**\n\n- `outputSchema?` - Optional zod schema for the step's result, from any zod version. It types the result; it is not checked at runtime\n- `maxAttempts?: number` - Optional max retry attempts on failure\n- `retryDelaySeconds?: number` - Optional base delay between retries (backs off exponentially)\n\n### `ctx.createCallback`\n\nCreate a callback that can be awaited later. Returns `[promise, callbackUrl]`.\n\n```typescript\n\u002F\u002F Simple signature - awaiting resolves the delivered payload\nconst [promise, callbackUrl] = await ctx.createCallback(\"my-callback\");\n\n\u002F\u002F With a payload schema (edge validation + typing), no deadline\nconst [promise, callbackUrl] = await ctx.createCallback({\n  name: \"my-callback\",\n  payloadSchema: z.object({ result: z.string() }),\n});\n\n\u002F\u002F Send callbackUrl somewhere, then await the promise\nconst result = await promise;\n```\n\n`payloadSchema` needs zod 4.2 or later: the callback sends the schema to the\nserver as JSON Schema, using the schema's `toJSONSchema` method.\n\n**With a deadline (`timeoutSeconds`):** the callback gets a server-enforced\nexpiry, and awaiting it resolves a `CallbackResult` - exactly one journaled\noutcome, delivered in time or expired:\n\n```typescript\nconst [promise, callbackUrl] = await ctx.createCallback({\n  name: \"approval\",\n  timeoutSeconds: 24 * 60 * 60, \u002F\u002F 24h SLA\n  payloadSchema: z.object({ approved: z.boolean() }),\n});\n\nconst result = await promise;\nif (result.status === \"delivered\") {\n  \u002F\u002F result.value is the delivered payload, typed from payloadSchema;\n  \u002F\u002F result.at is the server-journaled delivery time\n} else {\n  \u002F\u002F result.status === \"expired\": the deadline elapsed and result.at is\n  \u002F\u002F the server-journaled deadline. The outcome is decided once: a late\n  \u002F\u002F delivery to the callback URL cannot flip it back to delivered.\n}\n```\n\nThe outcome is decided once by the server and read back from the journal on\nreplay - the SDK's clock never participates in deadlines. Without\n`timeoutSeconds` the callback never expires and awaiting resolves the bare\npayload, as in the simple signature.\n\n**Racing durable operations is unsupported.** Do not use `Promise.race`\nover steps, waits, or callbacks; express deadline patterns with\n`timeoutSeconds` and branch on `result.status` instead. (`Promise.all`\nover durable operations is supported.)\n\n### `ctx.wait`\n\nWait for a specified duration.\n\n```typescript\n\u002F\u002F Simple signature\nawait ctx.wait(\"delay-step\", 60);\n\n\u002F\u002F Object signature\nawait ctx.wait({ name: \"delay-step\", seconds: 60 });\n```\n\n## Configuration\n\nConfiguration is via environment variables:\n\n| Variable                                          | Default                                                      | Description                                                                                        |\n| ------------------------------------------------- | ------------------------------------------------------------ | -------------------------------------------------------------------------------------------------- |\n| `ZAPIER_DURABLE_ADAPTER`                          | `\"filesystem\"`                                               | Adapter type: `\"filesystem\"`, `\"zapier\"`, or `\"memory\"`                                            |\n| `ZAPIER_DURABLE_FS_DIR`                           | `~\u002F.config\u002Fzapier-sdk\u002Fdurable`                               | Directory for filesystem adapter                                                                   |\n| `ZAPIER_DURABLE_DETERMINISM_GUARD`                | `\"on\"`                                                       | Enable determinism checking (`\"on\"` or `\"off\"`)                                                    |\n| `ZAPIER_DURABLE_API_URL`                          | `https:\u002F\u002Fsdkapi.zapier.com\u002Fapi\u002Fv0\u002Fsdk\u002Fcode-substrate-runner` | Base URL for the API (when adapter=zapier)                                                         |\n| `ZAPIER_DURABLE_API_JWT`                          | (auto for localhost)                                         | JWT token for API authentication                                                                   |\n| `ZAPIER_DURABLE_DEBUG`                            | `\"false\"`                                                    | Enable debug logging (`\"true\"` or `\"false\"`)                                                       |\n| `ZAPIER_DURABLE_WAIT_INPROCESS_THRESHOLD_SECONDS` | `0` (disabled)                                               | Waits at or below the remaining threshold at first await complete in-process instead of suspending |\n| `ZAPIER_DURABLE_WAIT_INPROCESS_BUDGET_SECONDS`    | `120`                                                        | Cap on total in-process wait seconds per tick                                                      |\n\n### Test Mode (Integration Tests)\n\nFor faster integration tests, these env vars cap durations:\n\n| Variable                                           | Default | Description                                           |\n| -------------------------------------------------- | ------- | ----------------------------------------------------- |\n| `ZAPIER_DURABLE_TEST_MAX_WAIT_SECONDS`             | (none)  | Cap `ctx.wait()` durations                            |\n| `ZAPIER_DURABLE_TEST_MAX_RETRY_DELAY_MILLISECONDS` | (none)  | Cap retry backoff delays (deprecated alias: `..._MS`) |\n\nExample:\n\n```bash\nZAPIER_DURABLE_TEST_MAX_WAIT_SECONDS=2 \\\nZAPIER_DURABLE_TEST_MAX_RETRY_DELAY_MILLISECONDS=500 \\\npnpm test\n```\n\n## Contributing\n\nThe GitHub repository for this package is a read-only mirror. Zapier does not\naccept outside pull requests or other code contributions. To report a problem,\ncontact [Zapier support](https:\u002F\u002Fzapier.com\u002Fapp\u002Fget-help).\n\n## License\n\nThis SDK's source code is licensed under the MIT License (see `LICENSE`). The MIT License covers the code only. Using the Zapier service and APIs through this SDK is governed separately by the Zapier Terms of Service (https:\u002F\u002Fzapier.com\u002Flegal\u002Fterms-of-service) or your other agreement with Zapier for use of the Zapier service, which apply regardless of the code license.\n",2,"2026-11-24 04:54:32","CREATED_QUERY"]