@pushary/durable
v0.3.1
Published
Phone approvals for Inngest, Temporal and Vercel Workflow runs. Your workflow asks, your user taps Approve or Deny.
Maintainers
Readme
@pushary/durable
Phone approvals for Inngest, Temporal and Vercel Workflow runs. Your workflow asks, your user taps Approve or Deny.
Human in the loop for AI agents · Durable workflows guide · Report a problem
What you need
- A Pushary Partner plan, from $99 a month. Start the trial.
- An API key from Partner onboarding, set as
PUSHARY_API_KEY. - Your users install the free Pushary app (iPhone, Android). They never sign up or pay.
What your customer gets
- They open your connect link once. It shows your product's name and logo and connects their phone.
- When your workflow reaches the approval step, a push notification titled with your product name arrives, such as Acme needs your approval. The run is parked and uses no compute while they decide, for minutes or hours.
- They tap Approve or Deny. Pushary posts the signed answer to your callback, and your code runs the action only on a yes.
Pushary hosts the phone delivery, the decision record and the audit log. Inngest, Temporal or Vercel Workflow keeps the parked run. Your app keeps its own sign-in, the correlationId to run mapping and the action itself.
Quick start
npm i @pushary/durableimport { connect, createApproval, deterministicKey, resolveTimestampedApproval } from '@pushary/durable'
const config = { apiKey: process.env.PUSHARY_API_KEY! }
const { universalLink } = await connect(config, user.id) // once per user: show them this link
const { correlationId, status } = await createApproval(config, {
externalId: user.id,
question: 'Approve a $480 refund?',
callbackUrl: `${process.env.PUBLIC_URL}/pushary/callback`,
idempotencyKey: deterministicKey([runId, 'refund-approval']),
})
if (status === 'stopped') throw new Error('The agent was stopped in Pushary.') // nobody was asked, nothing to wait for
// Save correlationId against the run, then park it. Nothing runs while it waits.
const approval = resolveTimestampedApproval(rawBody, request.headers.get('pushary-signature'), process.env.PUSHARY_WEBHOOK_SECRET!)
if (approval?.approved) await resumeRun(approval.correlationId)The last two lines go in your callback route. PUSHARY_WEBHOOK_SECRET comes from decisions.getWebhookSecret().
Works with Inngest, Temporal, and Vercel Workflow, or any runner that can wait on an external event. It adds no framework dependency of its own, so it drops into whichever one you already run.
The shape
connect(config, externalId)once per end-user. Show them the link, they tap to connect their phone.createApproval(config, { callbackUrl, idempotencyKey, ... })opens a durable decision and returns immediately. Store thecorrelationIdagainst your run and park the workflow.- When the human answers, Pushary POSTs your
callbackUrl.resolveTimestampedApproval(raw, request.headers.get('pushary-signature'), secret)verifies the timestamped signature, refuses a replay, and hands you{ approved, answer }. Look up the parked run bycorrelationIdand resume it.
The wait is durable on Pushary's side (a decisions ledger) and on yours (the orchestrator's snapshot), so nothing is lost across a restart.
Try the refund callback locally
A store asks its customer to approve a refund. The customer taps Approve, but the delivery service sends that same answer twice. How many refunds does the store record?
From a clone of this repository, run the following with Node 24 or later:
npm install
npm run build
node examples/refund-receipt.mjsThe example signs test answers locally and reopens a temporary SQLite database for each delivery. Two approvals for the same decision record one simulated refund. A denial or a missing answer records zero. No phone, account, model or payment provider is needed. In a live app, enroll the customer through Partner and give your payment provider a stable refund idempotency key as well.
Inngest
import { createApproval, resolveTimestampedApproval, deterministicKey } from '@pushary/durable'
export const refund = inngest.createFunction(
{ id: 'refund', triggers: { event: 'app/refund.requested' } },
async ({ event, step }) => {
const { correlationId, status } = await step.run('ask-human', () =>
createApproval(
{ apiKey: process.env.PUSHARY_API_KEY! },
{
externalId: event.data.userId,
question: `Approve a $${event.data.amount} refund?`,
callbackUrl: `${process.env.PUBLIC_URL}/api/inngest/pushary`,
idempotencyKey: deterministicKey([event.id, 'refund-approval']),
},
),
)
if (status === 'stopped') return
const answered = await step.waitForEvent('wait-for-answer', {
event: 'pushary/decision.resolved',
timeout: '1d',
// the correlationId is generated inside the step, so match on it with `if`
if: `async.data.correlationId == "${correlationId}"`,
})
if (answered?.data.approved) await step.run('refund', () => issueRefund(event.data))
},
)
// mount one route that turns Pushary callbacks into Inngest events:
export async function POST(req: Request) {
const raw = await req.text()
const approval = resolveTimestampedApproval(raw, req.headers.get('pushary-signature'), process.env.PUSHARY_WEBHOOK_SECRET!)
if (!approval) return new Response('bad signature', { status: 401 })
await inngest.send({ id: deterministicKey([approval.correlationId, 'resolved']), name: 'pushary/decision.resolved', data: { ...approval } })
return new Response('ok')
}Temporal
// activity
export async function askHuman(userId: string, amount: number, runId: string) {
return createApproval(
{ apiKey: process.env.PUSHARY_API_KEY! },
{
externalId: userId,
question: `Approve a $${amount} refund?`,
callbackUrl: `${process.env.PUBLIC_URL}/api/temporal/pushary`,
idempotencyKey: deterministicKey([runId, 'refund-approval']),
},
)
}
// workflow: create in an activity, then wait for a signal
export async function refundWorkflow(userId: string, amount: number) {
const approve = defineSignal<[{ answer: string; approved: boolean }]>('pushary_answer')
let result: { approved: boolean } | null = null
setHandler(approve, (a) => { result = a })
const { status } = await askHuman(userId, amount, workflowInfo().workflowId)
if (status === 'stopped') return
await condition(() => result !== null, '1 day')
if (result?.approved) await issueRefund(userId, amount)
}
// callback route signals the workflow (map correlationId -> workflowId in your store)Vercel Workflow
import { createWebhook } from 'workflow'
import { createApproval, resolveTimestampedApproval, deterministicKey } from '@pushary/durable'
export async function refundWorkflow(userId: string, amount: number, runId: string) {
'use workflow'
using webhook = createWebhook()
const { status } = await createApproval(
{ apiKey: process.env.PUSHARY_API_KEY! },
{
externalId: userId,
question: `Approve a $${amount} refund?`,
callbackUrl: webhook.url, // Pushary posts straight to the run's resume URL
idempotencyKey: deterministicKey([runId, 'refund-approval']),
},
)
if (status === 'stopped') return
const request = await webhook // parks here until the callback arrives
const approval = resolveTimestampedApproval(
await request.text(),
request.headers.get('pushary-signature'),
process.env.PUSHARY_WEBHOOK_SECRET!,
)
if (approval?.approved) await issueRefund(userId, amount)
}The resume URL is not authentication on its own, so always resolveTimestampedApproval
(which verifies the timestamped HMAC signature) before you act.
API
connect(config, externalId): enroll an end-user's phone, returnsEnrollResult.createApproval(config, input): open a durable decision, returns{ decisionId, correlationId, reachable, ... }.createApprovalreturnsstatus: 'stopped'when the agent was stopped. No decision was opened and no callback will come, so end the run instead of parking it.resolveTimestampedApproval(rawBody, signature, secret): verify thePushary-Signatureheader and parse the callback into{ correlationId, answer, value, approved, context? }, ornullif invalid. Refuses a body-only signature and a timestamp more than 300 seconds from now, so a captured callback cannot be replayed.resolveApproval(rawBody, signature, secret): the same over the body-onlyX-Pushary-Signature, which has no replay protection. Kept for existing routes; move them toresolveTimestampedApproval.isAffirmative(answer): fail-closed yes/no check for a confirm answer.deterministicKey(parts): a stable idempotency key from your run + step ids.- Re-exports:
verifyTimestampedWebhookSignature,TIMESTAMPED_SIGNATURE_HEADER,verifyWebhookSignature,parseDecisionCallback,SIGNATURE_HEADER.
Example
A runnable example is in examples/.
Links
- Durable workflows guide in the Pushary docs.
- Partner plan, from $99 a month. All plans are on the pricing page.
- Browser demo of one approval.
- Other adapters: Mastra, LangGraph, and the server SDK this package is built on.
License
MIT
