// `orders.approve` — EXECUTOR (server-only). // // Injects the `approval` signal that wakes the parked `orders.fulfill` // run for this order. The workflow's `idempotencyKey` (`fulfill:`) // makes its executionId a deterministic function of the payload, so we // re-derive it from `{ orderId, tenantId }` and address the signal by // executionId — no need to track the run handle from the place mutation. // // `ctx.workflows.signal(target, name, payload)` writes a `signal-sent` // row to the run's events log; the workflow's `awaitSignal('approval')` // poll picks it up (sub-second) and parses the payload against its // `{ approved: boolean }` schema. import { assertOwnTenant } from '@voltro/plugin-multitenancy/guard' import type { AppContext } from '@voltro/runtime' const execute = async ( input: { orderId: string; tenantId: string; approved: boolean }, ctx: AppContext, ) => { assertOwnTenant(input.tenantId, ctx.request.subject) if (!ctx.workflows) { throw new Error('orders.approve: workflow runtime is not available in this context') } // Deterministic executionId for the running fulfillment workflow — // same payload the `order.placed` trigger started it with. const executionId = await ctx.workflows.executionId('orders.fulfill', { orderId: input.orderId, tenantId: input.tenantId, }) const { eventId } = await ctx.workflows.signal( { executionId }, 'approval', { approved: input.approved }, ) return { orderId: input.orderId, eventId } } export default execute