@hogsend/engine 0.27.0 → 0.28.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.
Files changed (2) hide show
  1. package/package.json +7 -7
  2. package/src/lib/contacts.ts +15 -13
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hogsend/engine",
3
- "version": "0.27.0",
3
+ "version": "0.28.0",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -40,14 +40,14 @@
40
40
  "svix": "^1.95.1",
41
41
  "winston": "^3.19.0",
42
42
  "zod": "^4.4.3",
43
- "@hogsend/core": "^0.27.0",
44
- "@hogsend/db": "^0.27.0",
45
- "@hogsend/email": "^0.27.0",
46
- "@hogsend/plugin-posthog": "^0.27.0",
47
- "@hogsend/plugin-resend": "^0.27.0"
43
+ "@hogsend/core": "^0.28.0",
44
+ "@hogsend/db": "^0.28.0",
45
+ "@hogsend/email": "^0.28.0",
46
+ "@hogsend/plugin-posthog": "^0.28.0",
47
+ "@hogsend/plugin-resend": "^0.28.0"
48
48
  },
49
49
  "optionalDependencies": {
50
- "@hogsend/plugin-postmark": "^0.27.0"
50
+ "@hogsend/plugin-postmark": "^0.28.0"
51
51
  },
52
52
  "devDependencies": {
53
53
  "@types/node": "^22.15.3",
@@ -200,7 +200,7 @@ async function findByKey(tx: Tx, key: ResolveKey): Promise<ContactRow | null> {
200
200
  * additive — siblings stay strictly shallow, preserving the documented contract
201
201
  * for everything else. NON-KEY metadata only; never an identity-resolution key.
202
202
  */
203
- const DEEP_MERGE_KEYS = ["discord"] as const;
203
+ const DEEP_MERGE_KEYS = ["discord", "telegram"] as const;
204
204
 
205
205
  /**
206
206
  * Merge `patch` onto the existing jsonb properties (§2.1 contract): additive
@@ -798,21 +798,23 @@ async function mergeContacts(
798
798
  }
799
799
 
800
800
  /**
801
- * journey_states fold. `uq_user_journey_active` is a FULL (non-partial) unique
802
- * index on `(user_id, journey_id, status)` — it constrains EVERY status, not
803
- * just active/waiting. So a blind rewrite of loser rows onto the survivor key
804
- * collides whenever the survivor already holds a row for the SAME
805
- * (journey_id, status) — including the common terminal case where both
806
- * identities completed/failed/exited the same journey.
801
+ * journey_states fold. `uq_user_journey_active` is a PARTIAL unique index on
802
+ * `(user_id, journey_id) WHERE status IN ('active','waiting')` — it constrains
803
+ * only LIVE rows, so terminal rows (completed/failed/exited) may legitimately
804
+ * duplicate across the merged identities. A rewrite of a loser's LIVE row onto
805
+ * the survivor key still collides whenever the survivor already holds a live row
806
+ * for that journey.
807
807
  *
808
808
  * Fix: build the survivor's occupied (journey_id|status) set over ALL statuses.
809
809
  * For active/waiting collisions, EXIT the loser's row first (preserve the
810
- * survivor's live run). For any OTHER collision (terminal, or an active row that
811
- * collides after exiting), DELETE the loser's duplicate — the survivor already
812
- * records that state. Rewrite only the non-colliding remainder onto the survivor
813
- * key (+ survivor email). Re-check 'exited' occupancy after exiting so a
814
- * just-exited loser row that would now duplicate a pre-existing survivor
815
- * 'exited' row is dropped rather than rewritten.
810
+ * survivor's live run) so the rewrite lands an 'exited' (out-of-predicate) row.
811
+ * For any OTHER collision (terminal), DELETE the loser's duplicate — no longer
812
+ * REQUIRED by the constraint (terminal rows are outside the predicate), but kept
813
+ * as hygiene so the survivor doesn't carry two identical terminal rows (which
814
+ * would inflate the count()-based ctx.history.journey.entryCount). Rewrite only
815
+ * the non-colliding remainder onto the survivor key (+ survivor email). Re-check
816
+ * 'exited' occupancy after exiting so a just-exited loser row that would now
817
+ * duplicate a pre-existing survivor 'exited' row is dropped rather than rewritten.
816
818
  */
817
819
  async function foldJourneyStates(
818
820
  tx: Tx,