@hogsend/engine 0.38.0 → 0.38.1
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 +7 -7
- package/src/journeys/define-journey.ts +55 -44
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hogsend/engine",
|
|
3
|
-
"version": "0.38.
|
|
3
|
+
"version": "0.38.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -42,14 +42,14 @@
|
|
|
42
42
|
"svix": "^1.95.1",
|
|
43
43
|
"winston": "^3.19.0",
|
|
44
44
|
"zod": "^4.4.3",
|
|
45
|
-
"@hogsend/core": "^0.38.
|
|
46
|
-
"@hogsend/db": "^0.38.
|
|
47
|
-
"@hogsend/email": "^0.38.
|
|
48
|
-
"@hogsend/plugin-posthog": "^0.38.
|
|
49
|
-
"@hogsend/plugin-resend": "^0.38.
|
|
45
|
+
"@hogsend/core": "^0.38.1",
|
|
46
|
+
"@hogsend/db": "^0.38.1",
|
|
47
|
+
"@hogsend/email": "^0.38.1",
|
|
48
|
+
"@hogsend/plugin-posthog": "^0.38.1",
|
|
49
|
+
"@hogsend/plugin-resend": "^0.38.1"
|
|
50
50
|
},
|
|
51
51
|
"optionalDependencies": {
|
|
52
|
-
"@hogsend/plugin-postmark": "^0.38.
|
|
52
|
+
"@hogsend/plugin-postmark": "^0.38.1"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"@types/node": "^22.15.3",
|
|
@@ -103,42 +103,6 @@ export function defineJourney(options: {
|
|
|
103
103
|
string | number | boolean | null
|
|
104
104
|
>;
|
|
105
105
|
|
|
106
|
-
if (!meta.enabled) {
|
|
107
|
-
return { status: "skipped", reason: "journey_disabled" };
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
const configOverride = await db.query.journeyConfigs.findFirst({
|
|
111
|
-
where: eq(journeyConfigs.journeyId, meta.id),
|
|
112
|
-
});
|
|
113
|
-
if (configOverride && !configOverride.enabled) {
|
|
114
|
-
return { status: "skipped", reason: "journey_disabled_by_admin" };
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
if (meta.trigger.where?.length) {
|
|
118
|
-
if (
|
|
119
|
-
!evaluatePropertyConditions({
|
|
120
|
-
conditions: meta.trigger.where,
|
|
121
|
-
properties,
|
|
122
|
-
})
|
|
123
|
-
) {
|
|
124
|
-
return { status: "skipped", reason: "trigger_conditions_not_met" };
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
const entryAllowed = await checkEntryLimit({
|
|
129
|
-
db,
|
|
130
|
-
journey: meta,
|
|
131
|
-
userId,
|
|
132
|
-
});
|
|
133
|
-
if (!entryAllowed.allowed) {
|
|
134
|
-
return { status: "skipped", reason: entryAllowed.reason };
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
const prefs = await checkEmailPreferences({ db, userId });
|
|
138
|
-
if (prefs.unsubscribed) {
|
|
139
|
-
return { status: "skipped", reason: "user_unsubscribed" };
|
|
140
|
-
}
|
|
141
|
-
|
|
142
106
|
// The replay-stable anchor for this enrollment: the Hatchet run id is
|
|
143
107
|
// preserved across replays of the SAME logical durable run (crash / OOM /
|
|
144
108
|
// eviction / redeploy mid-run), whereas a freshly-minted journeyStates.id
|
|
@@ -146,14 +110,19 @@ export function defineJourney(options: {
|
|
|
146
110
|
// on it so a replay re-derives the SAME stateId and the SAME keys.
|
|
147
111
|
const workflowRunId = hatchetCtx.workflowRunId();
|
|
148
112
|
|
|
149
|
-
// REPLAY RECOVERY
|
|
150
|
-
//
|
|
151
|
-
//
|
|
152
|
-
//
|
|
153
|
-
//
|
|
154
|
-
//
|
|
155
|
-
//
|
|
156
|
-
//
|
|
113
|
+
// REPLAY RECOVERY — must run BEFORE the enrollment guards below. An
|
|
114
|
+
// eviction-capable Hatchet engine (hatchet-lite >= v0.80.0) replays `fn`
|
|
115
|
+
// from the top on every durable-wait resume, so every statement above the
|
|
116
|
+
// first durable primitive re-runs on each resume. The enrollment guards
|
|
117
|
+
// (entryLimit / preferences / trigger conditions / enabled / active-state)
|
|
118
|
+
// are ENTRY gates: re-running them on a resume is wrong. In particular a
|
|
119
|
+
// `once` journey's own entry-limit guard would find the row it created on
|
|
120
|
+
// first entry and skip EVERY resume, stranding the journey in `waiting` and
|
|
121
|
+
// silently dropping all sends after the first. Recovering by the run-stable
|
|
122
|
+
// id first lets a resume reuse its enrollment and bypass the entry gates (a
|
|
123
|
+
// resume is not an entry). It also keeps the original purpose: a journey
|
|
124
|
+
// whose prior enrollment reached a TERMINAL status (unlimited /
|
|
125
|
+
// once_per_period) recovers the SAME stateId so derived keys still collide.
|
|
157
126
|
const recovered = workflowRunId
|
|
158
127
|
? await db.query.journeyStates.findFirst({
|
|
159
128
|
where: and(
|
|
@@ -164,7 +133,49 @@ export function defineJourney(options: {
|
|
|
164
133
|
: undefined;
|
|
165
134
|
|
|
166
135
|
let state = recovered;
|
|
136
|
+
|
|
137
|
+
// FIRST ENTRY ONLY — the enrollment guards gate ENTRY, not resume. A
|
|
138
|
+
// recovered enrollment already passed them on first entry, so it skips
|
|
139
|
+
// straight to resuming the run. (Sends inside `run` still re-check
|
|
140
|
+
// subscription via `ctx.guard.isSubscribed()` after every wait, so
|
|
141
|
+
// bypassing the entry-time preference gate never emails an unsubscriber.)
|
|
167
142
|
if (!state) {
|
|
143
|
+
if (!meta.enabled) {
|
|
144
|
+
return { status: "skipped", reason: "journey_disabled" };
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
const configOverride = await db.query.journeyConfigs.findFirst({
|
|
148
|
+
where: eq(journeyConfigs.journeyId, meta.id),
|
|
149
|
+
});
|
|
150
|
+
if (configOverride && !configOverride.enabled) {
|
|
151
|
+
return { status: "skipped", reason: "journey_disabled_by_admin" };
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
if (meta.trigger.where?.length) {
|
|
155
|
+
if (
|
|
156
|
+
!evaluatePropertyConditions({
|
|
157
|
+
conditions: meta.trigger.where,
|
|
158
|
+
properties,
|
|
159
|
+
})
|
|
160
|
+
) {
|
|
161
|
+
return { status: "skipped", reason: "trigger_conditions_not_met" };
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
const entryAllowed = await checkEntryLimit({
|
|
166
|
+
db,
|
|
167
|
+
journey: meta,
|
|
168
|
+
userId,
|
|
169
|
+
});
|
|
170
|
+
if (!entryAllowed.allowed) {
|
|
171
|
+
return { status: "skipped", reason: entryAllowed.reason };
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
const prefs = await checkEmailPreferences({ db, userId });
|
|
175
|
+
if (prefs.unsubscribed) {
|
|
176
|
+
return { status: "skipped", reason: "user_unsubscribed" };
|
|
177
|
+
}
|
|
178
|
+
|
|
168
179
|
const activeState = await db.query.journeyStates.findFirst({
|
|
169
180
|
where: and(
|
|
170
181
|
eq(journeyStates.userId, userId),
|