import { M as MaybePromise, D as Duration, W as WorkflowConfig, a as WorkflowDefinition } from "../packem_shared/types.d-CcjfiGpo.d-DuZME7ry.js"; import { C as ChannelPayloadMap, N as Notification } from "../packem_shared/notification.d-D0ado_cy.js"; import { C as ChannelType, c as Receipt } from "../packem_shared/types.d-C7l7qdMG.js"; import '@standard-schema/spec'; import "../packem_shared/types.d-CRs03TYV.js"; import "../packem_shared/provider.d-Dh32nRm9.js"; /** The context handed to a step resolver / skip predicate. */ interface StepResolverContext { /** The validated trigger payload of the run. */ payload: PayloadT; } /** Resolves the payload sent by a channel step (or decides to skip it). */ type StepResolver = (context: StepResolverContext) => MaybePromise; /** Per-step options for a channel step. */ interface ChannelStepOptions { /** Skip the send when this returns `true`; the step records `undefined`. */ skip?: (context: StepResolverContext) => MaybePromise; /** * Treat a `FailureReceipt` as a thrown error so the run fails and the step * re-runs on the next resume/sweep. Defaults to `false`. */ throwOnFailure?: boolean; } /** * A durable channel step. Resolves a channel payload and delivers it through the * bound {@link Notification} facade exactly once; the receipt is recorded and * returned on replay without re-sending. Returns `undefined` when `skip` matches. * * IMPORTANT: a delivery failure surfaces as a `FailureReceipt` (the facade does not * throw), so by default a failed send is **recorded as a completed step and not * retried** — inspect `receipt.successful`, or pass `throwOnFailure: true` to turn * a failure into a thrown error that re-runs the step on the next activation. */ type ChannelStep = (id: string, resolve: StepResolver, options?: ChannelStepOptions) => Promise; /** * The `step` object handed to a notification workflow body. Channel steps deliver * exactly once; `delay` pauses durably; `custom` is an escape hatch to the raw * engine step. */ interface NotificationStep { chat: ChannelStep<"chat", PayloadT>; custom: (id: string, function_: () => MaybePromise) => Promise; delay: (id: string, duration: Duration) => Promise; email: ChannelStep<"email", PayloadT>; inApp: ChannelStep<"inapp", PayloadT>; push: ChannelStep<"push", PayloadT>; sms: ChannelStep<"sms", PayloadT>; webhook: ChannelStep<"webhook", PayloadT>; } /** The body of a notification workflow, driven by {@link NotificationStep}. */ type NotificationWorkflowRun = (context: { payload: PayloadT; runId: string; step: NotificationStep; }) => MaybePromise; /** Config for {@link createNotificationWorkflow}: a {@link WorkflowConfig} whose `run` is notification-flavoured. */ interface NotificationWorkflowConfig extends Omit, "run"> { run: NotificationWorkflowRun; } /** * Define a durable notification workflow on top of [`@visulima/workflow`](https://visulima.com/packages/workflow). * * The returned value is a plain `WorkflowDefinition`, so it plugs straight into a * workflow runtime (`createRuntime({ workflows: [wf] })` → `runtime.trigger(wf, payload)`). * Channel steps deliver through the bound `notification` facade exactly once. * @param notification The multi-channel facade messages are delivered through. * @param config The workflow id, optional payload schema, and notification-flavoured `run`. * @returns A {@link WorkflowDefinition} ready to register/trigger on a runtime. * @example * ```ts * const onComment = createNotificationWorkflow(notify, { * id: "comment-posted", * payload: z.object({ subscriberId: z.string(), author: z.string() }), * run: async ({ step, payload }) => { * await step.inApp("inbox", () => ({ to: payload.subscriberId, body: `${payload.author} commented` })); * await step.delay("cooldown", { amount: 1, unit: "hours" }); * await step.email("nudge", () => ({ from: "x@y.com", to: payload.subscriberId, subject: "New comment", html: "

" })); * }, * }); * ``` */ declare const createNotificationWorkflow: (notification: Notification, config: NotificationWorkflowConfig) => WorkflowDefinition; export { type ChannelStep, type ChannelStepOptions, type NotificationStep, type NotificationWorkflowConfig, type NotificationWorkflowRun, type StepResolver, type StepResolverContext, createNotificationWorkflow };