@hogsend/core 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hogsend/core",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -31,7 +31,7 @@
31
31
  "drizzle-orm": "^0.45.2",
32
32
  "iana-db-timezones": "^0.3.0",
33
33
  "zod": "^4.4.3",
34
- "@hogsend/db": "^0.3.0"
34
+ "@hogsend/db": "^0.4.0"
35
35
  },
36
36
  "devDependencies": {
37
37
  "@types/node": "latest",
@@ -96,12 +96,47 @@ export interface EmailHistoryResult {
96
96
  count: number;
97
97
  }
98
98
 
99
+ export interface WaitForEventOptions {
100
+ /** Event name to wait for (use your `Events` constant). Matched verbatim. */
101
+ event: string;
102
+ /**
103
+ * Max time to wait before resolving as timed-out. Required: an unbounded wait
104
+ * is only capped by the task's execution timeout and would fail rather than
105
+ * resume. Keep it within the journey execution timeout (720h / 30 days).
106
+ */
107
+ timeout: DurationObject;
108
+ /** Optional observability label written to `currentNodeId` while waiting. */
109
+ label?: string;
110
+ }
111
+
112
+ export interface WaitForEventResult {
113
+ /** `true` when the `timeout` elapsed first; `false` when the event fired. */
114
+ timedOut: boolean;
115
+ }
116
+
99
117
  export interface JourneyContext {
100
118
  sleep(opts: SleepOptions): Promise<SleepResult>;
101
119
 
102
120
  /** Durable sleep until an absolute instant (`Date` or ISO string). */
103
121
  sleepUntil(at: Date | string, opts?: SleepUntilOptions): Promise<SleepResult>;
104
122
 
123
+ /**
124
+ * Durably wait until THIS user emits `event`, or `timeout` elapses —
125
+ * whichever comes first. The state is marked `"waiting"` while suspended and
126
+ * `"active"` again on resume. Returns `{ timedOut }` so the journey can branch
127
+ * (e.g. send a nudge on timeout, do nothing if the event arrived).
128
+ *
129
+ * Forward-looking: only events emitted AFTER the wait is established count —
130
+ * use `ctx.history.hasEvent` to check whether something already happened.
131
+ *
132
+ * If the journey exits (via `exitOn`) or is cancelled while waiting, the run
133
+ * is aborted cleanly (a `JourneyExitedError` is thrown and handled by the
134
+ * engine) so no post-wait side effects fire. After a long wait you should
135
+ * still re-check `ctx.guard.isSubscribed()` before sending, since an
136
+ * unsubscribe does not exit the journey.
137
+ */
138
+ waitForEvent(opts: WaitForEventOptions): Promise<WaitForEventResult>;
139
+
105
140
  /** Timezone-bound fluent scheduler. Always terminates in a `Date`. */
106
141
  when: WhenBuilder;
107
142