@hogsend/engine 0.59.0 → 0.61.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 +11 -11
- package/src/buckets/bucket-access.ts +34 -11
- package/src/buckets/check-membership.ts +74 -10
- package/src/buckets/membership-epoch.ts +11 -1
- package/src/campaigns/cohort-sql.ts +10 -0
- package/src/index.ts +10 -6
- package/src/journeys/execute-journey-run.ts +139 -70
- package/src/journeys/journey-context.ts +43 -7
- package/src/lib/agent/tools.ts +29 -4
- package/src/lib/attribution-backfill.ts +35 -4
- package/src/lib/attribution.ts +22 -3
- package/src/lib/connector-actions.ts +17 -17
- package/src/lib/contacts.ts +541 -175
- package/src/lib/conversion-dispatch.ts +16 -2
- package/src/lib/enrollment-guards.ts +19 -12
- package/src/lib/feed.ts +5 -5
- package/src/lib/flags.ts +26 -9
- package/src/lib/ingestion.ts +14 -2
- package/src/lib/journey-lift.ts +17 -5
- package/src/lib/preferences.ts +78 -29
- package/src/lib/recipient-preferences.ts +16 -2
- package/src/lib/refine.ts +16 -10
- package/src/lib/revenue.ts +20 -5
- package/src/lib/sms-inbound.ts +6 -1
- package/src/lib/sms-tracked.ts +18 -1
- package/src/lib/timezone.ts +11 -1
- package/src/lib/tracked.ts +19 -8
- package/src/lib/tracking-events.ts +28 -0
- package/src/lib/unique-violation.ts +44 -0
- package/src/routes/admin/buckets.ts +21 -1
- package/src/routes/admin/bulk.ts +14 -2
- package/src/routes/admin/contacts.ts +20 -7
- package/src/routes/admin/conversions.ts +20 -4
- package/src/routes/admin/emails.ts +17 -2
- package/src/routes/admin/events.ts +32 -41
- package/src/routes/admin/funnels.ts +6 -1
- package/src/routes/admin/groups.ts +4 -0
- package/src/routes/admin/impact.ts +30 -10
- package/src/routes/admin/journey-impact.ts +18 -9
- package/src/routes/admin/journeys.ts +8 -1
- package/src/routes/admin/maintenance.ts +7 -1
- package/src/routes/admin/preferences.ts +85 -46
- package/src/routes/admin/reporting.ts +25 -5
- package/src/routes/admin/targeting.ts +1 -0
- package/src/routes/admin/timeline.ts +16 -10
- package/src/routes/email/preferences.ts +18 -1
- package/src/routes/feed/recipient.ts +5 -0
- package/src/routes/lists/index.ts +6 -6
- package/src/workflows/backfill-contact-id.ts +210 -30
- package/src/workflows/bucket-backfill.ts +145 -67
- package/src/workflows/bucket-reconcile.ts +164 -51
- package/src/workflows/check-alerts.ts +4 -0
- package/src/workflows/impact-digest.ts +10 -3
- package/src/workflows/journey-blueprint-interpreter.ts +8 -1
- package/src/workflows/send-campaign.ts +18 -11
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
isColdChannelAllowed,
|
|
18
18
|
} from "../sources/define-contact-source.js";
|
|
19
19
|
import { getContactSourceRegistry } from "../sources/registry.js";
|
|
20
|
+
import { lookupContactIdByKey } from "./contacts.js";
|
|
20
21
|
import { getDb } from "./db.js";
|
|
21
22
|
import { createLogger } from "./logger.js";
|
|
22
23
|
import { readRecipientPreferences } from "./recipient-preferences.js";
|
|
@@ -27,15 +28,6 @@ import { readRecipientPreferences } from "./recipient-preferences.js";
|
|
|
27
28
|
// validates env at boot.
|
|
28
29
|
const logger = createLogger(process.env.LOG_LEVEL);
|
|
29
30
|
|
|
30
|
-
/**
|
|
31
|
-
* Matches the canonical UUID form of `contacts.id` (8-4-4-4-12 hex). Gates the
|
|
32
|
-
* `eq(contacts.id, ref)` leg so a uuid comparison only runs for a genuinely
|
|
33
|
-
* uuid-shaped ref — an email/snowflake ref would otherwise raise a Postgres
|
|
34
|
-
* `22P02 invalid input syntax for type uuid`.
|
|
35
|
-
*/
|
|
36
|
-
const CONTACT_ID_UUID =
|
|
37
|
-
/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
38
|
-
|
|
39
31
|
/**
|
|
40
32
|
* Matches a NAMESPACED platform ref (`telegram:<chatId>`, `discord:<id>`, …):
|
|
41
33
|
* a leading `<namespace>:` followed by a non-empty value. Captures the namespace
|
|
@@ -49,10 +41,10 @@ const NAMESPACED_REF = /^([a-z][a-z0-9_-]*):(.+)$/i;
|
|
|
49
41
|
* when the ref is uuid-shaped — the contact's row `id`. Matching every canonical
|
|
50
42
|
* key form (the journey subject key is `external_id ?? anonymous_id ?? id`) lets
|
|
51
43
|
* `member: user.id` resolve a member who has NOT linked (an anonymous Discord
|
|
52
|
-
* contact keyed by its uuid) or an email-only member.
|
|
53
|
-
*
|
|
54
|
-
*
|
|
55
|
-
* match wins.
|
|
44
|
+
* contact keyed by its uuid) or an email-only member. Those three canonical
|
|
45
|
+
* forms — plus a merged-away key that survives only as an identity row — are
|
|
46
|
+
* resolved by `lookupContactIdByKey` (which owns the uuid shape-gate: an
|
|
47
|
+
* unguarded `id = <text ref>` throws 22P02). First live match wins.
|
|
56
48
|
*
|
|
57
49
|
* NAMESPACED refs (`telegram:<chatId>`) ADDITIONALLY match the platform metadata
|
|
58
50
|
* under `properties.<namespace>` (the `chat_id`/`id` fields). This is load-bearing
|
|
@@ -82,6 +74,13 @@ async function resolveContact(
|
|
|
82
74
|
sql`${contacts.properties} -> ${nsMatch[1]}::text ->> 'id' = ${nsMatch[2]}`,
|
|
83
75
|
]
|
|
84
76
|
: [];
|
|
77
|
+
// The three CANONICAL-key legs (external_id / anonymous_id / uuid id) are
|
|
78
|
+
// resolved by the alias-aware primitive instead of probed as columns: same
|
|
79
|
+
// row for a live key, same miss for an unknown one, and — new — the SURVIVOR
|
|
80
|
+
// for a merged-away key, which no column probe can see (the loser's row is
|
|
81
|
+
// soft-deleted). The email / discord / namespaced-jsonb legs stay columns:
|
|
82
|
+
// `lookupContactIdByKey` deliberately answers only for canonical keys.
|
|
83
|
+
const canonicalId = await lookupContactIdByKey(db, ref);
|
|
85
84
|
const rows = await db
|
|
86
85
|
.select({
|
|
87
86
|
id: contacts.id,
|
|
@@ -96,11 +95,9 @@ async function resolveContact(
|
|
|
96
95
|
and(
|
|
97
96
|
isNull(contacts.deletedAt),
|
|
98
97
|
or(
|
|
98
|
+
...(canonicalId ? [eq(contacts.id, canonicalId)] : []),
|
|
99
99
|
eq(contacts.email, ref),
|
|
100
|
-
eq(contacts.externalId, ref),
|
|
101
100
|
eq(contacts.discordId, ref),
|
|
102
|
-
eq(contacts.anonymousId, ref),
|
|
103
|
-
...(CONTACT_ID_UUID.test(ref) ? [eq(contacts.id, ref)] : []),
|
|
104
101
|
...namespacedLegs,
|
|
105
102
|
),
|
|
106
103
|
),
|
|
@@ -224,9 +221,12 @@ export async function checkActionAudience(
|
|
|
224
221
|
});
|
|
225
222
|
}
|
|
226
223
|
|
|
224
|
+
// PRD 05 T6 — the contact row is in hand, so the read is contact-scoped
|
|
225
|
+
// directly; the old `externalId ?? id` string derivation is the idiom the
|
|
226
|
+
// flip retires.
|
|
227
227
|
const prefs = await readRecipientPreferences(db, {
|
|
228
228
|
email: contact.email,
|
|
229
|
-
|
|
229
|
+
contactId: contact.id,
|
|
230
230
|
});
|
|
231
231
|
if (prefs.unsubscribedAll) {
|
|
232
232
|
return {
|