@hogsend/engine 0.55.0 → 0.57.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 (37) hide show
  1. package/package.json +11 -11
  2. package/src/buckets/bucket-access.ts +5 -10
  3. package/src/buckets/check-membership.ts +91 -6
  4. package/src/index.ts +31 -1
  5. package/src/journeys/execute-journey-run.ts +56 -1
  6. package/src/journeys/journey-context.ts +59 -0
  7. package/src/lib/bucket-emit.test.ts +83 -2
  8. package/src/lib/bucket-emit.ts +16 -0
  9. package/src/lib/contacts.ts +1031 -141
  10. package/src/lib/crm-ingest.ts +9 -0
  11. package/src/lib/enrichment-ledger.ts +1 -1
  12. package/src/lib/feed.ts +64 -3
  13. package/src/lib/identity-service.ts +15 -2
  14. package/src/lib/ingestion.ts +191 -14
  15. package/src/lib/outbound.ts +3 -3
  16. package/src/lib/refine-chain.test.ts +83 -25
  17. package/src/lib/refine-chain.ts +124 -23
  18. package/src/lib/refine-traits.test.ts +74 -41
  19. package/src/lib/refine-traits.ts +107 -52
  20. package/src/lib/refine.ts +28 -27
  21. package/src/lib/tracking-events.ts +33 -6
  22. package/src/routes/admin/agent.ts +26 -0
  23. package/src/routes/admin/contacts.ts +65 -5
  24. package/src/routes/admin/identity.ts +197 -0
  25. package/src/routes/admin/index.ts +2 -0
  26. package/src/routes/contacts/index.ts +50 -7
  27. package/src/routes/events/index.ts +94 -6
  28. package/src/routes/feed/index.ts +36 -0
  29. package/src/routes/feed/recipient.ts +44 -2
  30. package/src/routes/lists/index.ts +21 -0
  31. package/src/routes/tracking/arrive.ts +42 -3
  32. package/src/worker.ts +18 -0
  33. package/src/workflows/bucket-backfill.ts +1 -1
  34. package/src/workflows/bucket-reconcile.ts +129 -4
  35. package/src/workflows/identity-alias-backfill.ts +448 -0
  36. package/src/workflows/import-contacts.ts +10 -0
  37. package/src/workflows/send-campaign.ts +31 -13
@@ -51,6 +51,17 @@ export async function emitBucketTransition(opts: {
51
51
  * the pin-less resolve (exactly the pre-pin behaviour).
52
52
  */
53
53
  contactId?: string;
54
+ /**
55
+ * D1 creation guard for BOTH re-ingests below, inherited from the originating
56
+ * ingest via `checkBucketMembership`. `false` ⇒ the transition event stores
57
+ * and routes exactly as always, but mints no `contacts` row. This is the
58
+ * ONLY correct behavior when the producer has no `contactId` to pin with:
59
+ * degrading the pin instead would make the resolver read this transition's
60
+ * `userId` (the subject's canonical key, often its `anonymous_id`) as an
61
+ * EXTERNAL key and mint a phantom `external_id` twin (issue #608). Producers
62
+ * that legitimately create (the reconcile cron, backfill) leave it unset.
63
+ */
64
+ allowCreate?: boolean;
54
65
  epoch: number;
55
66
  source?: BucketTransitionSource;
56
67
  /** Carried on a `left` transition's properties → `ctx.reason`. */
@@ -80,6 +91,7 @@ export async function emitBucketTransition(opts: {
80
91
  userId,
81
92
  userEmail,
82
93
  contactId,
94
+ allowCreate,
83
95
  epoch,
84
96
  source = "event",
85
97
  reason,
@@ -141,6 +153,7 @@ export async function emitBucketTransition(opts: {
141
153
  registry,
142
154
  hatchet,
143
155
  logger,
156
+ allowCreate,
144
157
  event: {
145
158
  event: eventName,
146
159
  userId,
@@ -161,6 +174,9 @@ export async function emitBucketTransition(opts: {
161
174
  registry,
162
175
  hatchet,
163
176
  logger,
177
+ // Same inherited refusal as the alias emit above — forwarding it on ONLY
178
+ // one leg would leave the ghost half-alive for generic-bound journeys.
179
+ allowCreate,
164
180
  event: {
165
181
  event: genericEvent,
166
182
  userId,