@hogsend/engine 0.67.0 → 0.68.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/README.md +3 -2
- package/dist/account-links/__fixtures__/fake-fetch.d.ts +38 -0
- package/dist/account-links/__fixtures__/fake-fetch.d.ts.map +1 -0
- package/dist/account-links/battlenet.d.ts +36 -0
- package/dist/account-links/battlenet.d.ts.map +1 -0
- package/dist/account-links/epic.d.ts +36 -0
- package/dist/account-links/epic.d.ts.map +1 -0
- package/dist/account-links/index.d.ts +7 -0
- package/dist/account-links/index.d.ts.map +1 -0
- package/dist/account-links/riot.d.ts +35 -0
- package/dist/account-links/riot.d.ts.map +1 -0
- package/dist/account-links/steam.d.ts +35 -0
- package/dist/account-links/steam.d.ts.map +1 -0
- package/dist/account-links/twitch.d.ts +38 -0
- package/dist/account-links/twitch.d.ts.map +1 -0
- package/dist/account-links/xbox.d.ts +39 -0
- package/dist/account-links/xbox.d.ts.map +1 -0
- package/dist/app.d.ts +50 -0
- package/dist/app.d.ts.map +1 -0
- package/dist/buckets/bucket-access.d.ts +60 -0
- package/dist/buckets/bucket-access.d.ts.map +1 -0
- package/dist/buckets/bucket-reactions.d.ts +100 -0
- package/dist/buckets/bucket-reactions.d.ts.map +1 -0
- package/dist/buckets/check-membership.d.ts +105 -0
- package/dist/buckets/check-membership.d.ts.map +1 -0
- package/dist/buckets/define-bucket.d.ts +53 -0
- package/dist/buckets/define-bucket.d.ts.map +1 -0
- package/dist/buckets/membership-epoch.d.ts +74 -0
- package/dist/buckets/membership-epoch.d.ts.map +1 -0
- package/dist/buckets/registry-singleton.d.ts +6 -0
- package/dist/buckets/registry-singleton.d.ts.map +1 -0
- package/dist/buckets/registry.d.ts +59 -0
- package/dist/buckets/registry.d.ts.map +1 -0
- package/dist/campaigns/cohort-sql.d.ts +54 -0
- package/dist/campaigns/cohort-sql.d.ts.map +1 -0
- package/dist/campaigns/define-campaign.d.ts +105 -0
- package/dist/campaigns/define-campaign.d.ts.map +1 -0
- package/dist/campaigns/reconcile.d.ts +13 -0
- package/dist/campaigns/reconcile.d.ts.map +1 -0
- package/dist/campaigns/steps.d.ts +29 -0
- package/dist/campaigns/steps.d.ts.map +1 -0
- package/dist/cold-connect/index.d.ts +98 -0
- package/dist/cold-connect/index.d.ts.map +1 -0
- package/dist/cold-connect/page.d.ts +69 -0
- package/dist/cold-connect/page.d.ts.map +1 -0
- package/dist/cold-connect/throttle.d.ts +39 -0
- package/dist/cold-connect/throttle.d.ts.map +1 -0
- package/dist/cold-connect/token.d.ts +57 -0
- package/dist/cold-connect/token.d.ts.map +1 -0
- package/dist/connectors/action-registry-singleton.d.ts +21 -0
- package/dist/connectors/action-registry-singleton.d.ts.map +1 -0
- package/dist/connectors/define-action.d.ts +117 -0
- package/dist/connectors/define-action.d.ts.map +1 -0
- package/dist/connectors/define-connector.d.ts +172 -0
- package/dist/connectors/define-connector.d.ts.map +1 -0
- package/dist/connectors/presets/index.d.ts +17 -0
- package/dist/connectors/presets/index.d.ts.map +1 -0
- package/dist/connectors/registry-singleton.d.ts +34 -0
- package/dist/connectors/registry-singleton.d.ts.map +1 -0
- package/dist/connectors/runtime.d.ts +68 -0
- package/dist/connectors/runtime.d.ts.map +1 -0
- package/dist/container.d.ts +678 -0
- package/dist/container.d.ts.map +1 -0
- package/dist/destinations/define-destination.d.ts +96 -0
- package/dist/destinations/define-destination.d.ts.map +1 -0
- package/dist/destinations/presets/index.d.ts +42 -0
- package/dist/destinations/presets/index.d.ts.map +1 -0
- package/dist/destinations/presets/posthog.d.ts +12 -0
- package/dist/destinations/presets/posthog.d.ts.map +1 -0
- package/dist/destinations/presets/segment.d.ts +15 -0
- package/dist/destinations/presets/segment.d.ts.map +1 -0
- package/dist/destinations/presets/slack.d.ts +10 -0
- package/dist/destinations/presets/slack.d.ts.map +1 -0
- package/dist/destinations/presets/webhook.d.ts +14 -0
- package/dist/destinations/presets/webhook.d.ts.map +1 -0
- package/dist/destinations/registry-singleton.d.ts +44 -0
- package/dist/destinations/registry-singleton.d.ts.map +1 -0
- package/dist/env.d.ts +119 -0
- package/dist/env.d.ts.map +1 -0
- package/dist/flags/reconcile.d.ts +36 -0
- package/dist/flags/reconcile.d.ts.map +1 -0
- package/dist/index.d.ts +210 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/journeys/authoring.d.ts +15 -0
- package/dist/journeys/authoring.d.ts.map +1 -0
- package/dist/journeys/client-defaults-singleton.d.ts +16 -0
- package/dist/journeys/client-defaults-singleton.d.ts.map +1 -0
- package/dist/journeys/constants.d.ts +32 -0
- package/dist/journeys/constants.d.ts.map +1 -0
- package/dist/journeys/define-journey.d.ts +33 -0
- package/dist/journeys/define-journey.d.ts.map +1 -0
- package/dist/journeys/durable-law-harness.d.ts +74 -0
- package/dist/journeys/durable-law-harness.d.ts.map +1 -0
- package/dist/journeys/errors.d.ts +13 -0
- package/dist/journeys/errors.d.ts.map +1 -0
- package/dist/journeys/execute-journey-run.d.ts +160 -0
- package/dist/journeys/execute-journey-run.d.ts.map +1 -0
- package/dist/journeys/graph/build-graph.d.ts +24 -0
- package/dist/journeys/graph/build-graph.d.ts.map +1 -0
- package/dist/journeys/group-scope.d.ts +56 -0
- package/dist/journeys/group-scope.d.ts.map +1 -0
- package/dist/journeys/journey-boundary.d.ts +264 -0
- package/dist/journeys/journey-boundary.d.ts.map +1 -0
- package/dist/journeys/journey-context.d.ts +60 -0
- package/dist/journeys/journey-context.d.ts.map +1 -0
- package/dist/journeys/journey-log.d.ts +42 -0
- package/dist/journeys/journey-log.d.ts.map +1 -0
- package/dist/journeys/journey-source-locations-singleton.d.ts +6 -0
- package/dist/journeys/journey-source-locations-singleton.d.ts.map +1 -0
- package/dist/journeys/journey-sources-singleton.d.ts +5 -0
- package/dist/journeys/journey-sources-singleton.d.ts.map +1 -0
- package/dist/journeys/journey-task-factory.d.ts +11 -0
- package/dist/journeys/journey-task-factory.d.ts.map +1 -0
- package/dist/journeys/journey-task-runtime.d.ts +2 -0
- package/dist/journeys/journey-task-runtime.d.ts.map +1 -0
- package/dist/journeys/journey-version.d.ts +71 -0
- package/dist/journeys/journey-version.d.ts.map +1 -0
- package/dist/journeys/record-once.d.ts +56 -0
- package/dist/journeys/record-once.d.ts.map +1 -0
- package/dist/journeys/registry-singleton.d.ts +6 -0
- package/dist/journeys/registry-singleton.d.ts.map +1 -0
- package/dist/journeys/registry.d.ts +59 -0
- package/dist/journeys/registry.d.ts.map +1 -0
- package/dist/journeys/with-durable-gate.d.ts +97 -0
- package/dist/journeys/with-durable-gate.d.ts.map +1 -0
- package/dist/lib/account-link-emit.d.ts +69 -0
- package/dist/lib/account-link-emit.d.ts.map +1 -0
- package/dist/lib/account-link-events.d.ts +128 -0
- package/dist/lib/account-link-events.d.ts.map +1 -0
- package/dist/lib/account-link-hooks.d.ts +32 -0
- package/dist/lib/account-link-hooks.d.ts.map +1 -0
- package/dist/lib/account-link-ingest.d.ts +78 -0
- package/dist/lib/account-link-ingest.d.ts.map +1 -0
- package/dist/lib/account-link-nonce.d.ts +29 -0
- package/dist/lib/account-link-nonce.d.ts.map +1 -0
- package/dist/lib/account-link-origins.d.ts +37 -0
- package/dist/lib/account-link-origins.d.ts.map +1 -0
- package/dist/lib/account-link-pkce.d.ts +48 -0
- package/dist/lib/account-link-pkce.d.ts.map +1 -0
- package/dist/lib/account-link-provider-registry.d.ts +35 -0
- package/dist/lib/account-link-provider-registry.d.ts.map +1 -0
- package/dist/lib/account-link-throttle.d.ts +76 -0
- package/dist/lib/account-link-throttle.d.ts.map +1 -0
- package/dist/lib/account-link-url.d.ts +41 -0
- package/dist/lib/account-link-url.d.ts.map +1 -0
- package/dist/lib/account-links-from-env.d.ts +62 -0
- package/dist/lib/account-links-from-env.d.ts.map +1 -0
- package/dist/lib/account-links.d.ts +353 -0
- package/dist/lib/account-links.d.ts.map +1 -0
- package/dist/lib/agent/config.d.ts +14 -0
- package/dist/lib/agent/config.d.ts.map +1 -0
- package/dist/lib/agent/proposals.d.ts +52 -0
- package/dist/lib/agent/proposals.d.ts.map +1 -0
- package/dist/lib/agent/provider.d.ts +9 -0
- package/dist/lib/agent/provider.d.ts.map +1 -0
- package/dist/lib/agent/risk.d.ts +24 -0
- package/dist/lib/agent/risk.d.ts.map +1 -0
- package/dist/lib/agent/system-prompt.d.ts +8 -0
- package/dist/lib/agent/system-prompt.d.ts.map +1 -0
- package/dist/lib/agent/tools.d.ts +258 -0
- package/dist/lib/agent/tools.d.ts.map +1 -0
- package/dist/lib/alerting.d.ts +7 -0
- package/dist/lib/alerting.d.ts.map +1 -0
- package/dist/lib/analytics-adapter.d.ts +24 -0
- package/dist/lib/analytics-adapter.d.ts.map +1 -0
- package/dist/lib/analytics-identity.d.ts +60 -0
- package/dist/lib/analytics-identity.d.ts.map +1 -0
- package/dist/lib/analytics-provider-registry.d.ts +20 -0
- package/dist/lib/analytics-provider-registry.d.ts.map +1 -0
- package/dist/lib/analytics-providers-from-env.d.ts +41 -0
- package/dist/lib/analytics-providers-from-env.d.ts.map +1 -0
- package/dist/lib/analytics-singleton.d.ts +10 -0
- package/dist/lib/analytics-singleton.d.ts.map +1 -0
- package/dist/lib/api-key-hash.d.ts +9 -0
- package/dist/lib/api-key-hash.d.ts.map +1 -0
- package/dist/lib/app-secret.d.ts +29 -0
- package/dist/lib/app-secret.d.ts.map +1 -0
- package/dist/lib/attachments.d.ts +53 -0
- package/dist/lib/attachments.d.ts.map +1 -0
- package/dist/lib/attribution-backfill.d.ts +48 -0
- package/dist/lib/attribution-backfill.d.ts.map +1 -0
- package/dist/lib/attribution.d.ts +44 -0
- package/dist/lib/attribution.d.ts.map +1 -0
- package/dist/lib/auth.d.ts +136 -0
- package/dist/lib/auth.d.ts.map +1 -0
- package/dist/lib/backfill.d.ts +41 -0
- package/dist/lib/backfill.d.ts.map +1 -0
- package/dist/lib/banner.d.ts +52 -0
- package/dist/lib/banner.d.ts.map +1 -0
- package/dist/lib/blueprint-lock.d.ts +19 -0
- package/dist/lib/blueprint-lock.d.ts.map +1 -0
- package/dist/lib/blueprints.d.ts +573 -0
- package/dist/lib/blueprints.d.ts.map +1 -0
- package/dist/lib/boot-api-key.d.ts +38 -0
- package/dist/lib/boot-api-key.d.ts.map +1 -0
- package/dist/lib/boot.d.ts +23 -0
- package/dist/lib/boot.d.ts.map +1 -0
- package/dist/lib/bootstrap-admin.d.ts +33 -0
- package/dist/lib/bootstrap-admin.d.ts.map +1 -0
- package/dist/lib/bot-prefetch.d.ts +21 -0
- package/dist/lib/bot-prefetch.d.ts.map +1 -0
- package/dist/lib/bucket-emit.d.ts +75 -0
- package/dist/lib/bucket-emit.d.ts.map +1 -0
- package/dist/lib/bucket-posthog-sync.d.ts +29 -0
- package/dist/lib/bucket-posthog-sync.d.ts.map +1 -0
- package/dist/lib/campaign-send-key.d.ts +31 -0
- package/dist/lib/campaign-send-key.d.ts.map +1 -0
- package/dist/lib/connector-actions.d.ts +83 -0
- package/dist/lib/connector-actions.d.ts.map +1 -0
- package/dist/lib/connector-heartbeat.d.ts +35 -0
- package/dist/lib/connector-heartbeat.d.ts.map +1 -0
- package/dist/lib/connector-link-codes.d.ts +105 -0
- package/dist/lib/connector-link-codes.d.ts.map +1 -0
- package/dist/lib/connector-state.d.ts +97 -0
- package/dist/lib/connector-state.d.ts.map +1 -0
- package/dist/lib/contacts.d.ts +622 -0
- package/dist/lib/contacts.d.ts.map +1 -0
- package/dist/lib/conversion-dispatch.d.ts +98 -0
- package/dist/lib/conversion-dispatch.d.ts.map +1 -0
- package/dist/lib/conversions.d.ts +75 -0
- package/dist/lib/conversions.d.ts.map +1 -0
- package/dist/lib/create-admin.d.ts +54 -0
- package/dist/lib/create-admin.d.ts.map +1 -0
- package/dist/lib/crm-deals.d.ts +66 -0
- package/dist/lib/crm-deals.d.ts.map +1 -0
- package/dist/lib/crm-ingest.d.ts +38 -0
- package/dist/lib/crm-ingest.d.ts.map +1 -0
- package/dist/lib/crm-provider-registry.d.ts +20 -0
- package/dist/lib/crm-provider-registry.d.ts.map +1 -0
- package/dist/lib/crm-registry-singleton.d.ts +18 -0
- package/dist/lib/crm-registry-singleton.d.ts.map +1 -0
- package/dist/lib/db.d.ts +3 -0
- package/dist/lib/db.d.ts.map +1 -0
- package/dist/lib/deal-money-events.d.ts +35 -0
- package/dist/lib/deal-money-events.d.ts.map +1 -0
- package/dist/lib/discord-gateway-heartbeat.d.ts +47 -0
- package/dist/lib/discord-gateway-heartbeat.d.ts.map +1 -0
- package/dist/lib/domain-status.d.ts +87 -0
- package/dist/lib/domain-status.d.ts.map +1 -0
- package/dist/lib/email-provider-registry.d.ts +30 -0
- package/dist/lib/email-provider-registry.d.ts.map +1 -0
- package/dist/lib/email-providers-from-env.d.ts +12 -0
- package/dist/lib/email-providers-from-env.d.ts.map +1 -0
- package/dist/lib/email-service-types.d.ts +189 -0
- package/dist/lib/email-service-types.d.ts.map +1 -0
- package/dist/lib/email-stats.d.ts +12 -0
- package/dist/lib/email-stats.d.ts.map +1 -0
- package/dist/lib/email.d.ts +73 -0
- package/dist/lib/email.d.ts.map +1 -0
- package/dist/lib/enrichment-ledger.d.ts +101 -0
- package/dist/lib/enrichment-ledger.d.ts.map +1 -0
- package/dist/lib/enrichment-provider-registry.d.ts +20 -0
- package/dist/lib/enrichment-provider-registry.d.ts.map +1 -0
- package/dist/lib/enrichment-providers-from-env.d.ts +13 -0
- package/dist/lib/enrichment-providers-from-env.d.ts.map +1 -0
- package/dist/lib/enrichment-registry-singleton.d.ts +9 -0
- package/dist/lib/enrichment-registry-singleton.d.ts.map +1 -0
- package/dist/lib/enrollment-guards.d.ts +28 -0
- package/dist/lib/enrollment-guards.d.ts.map +1 -0
- package/dist/lib/enrollment-policy.d.ts +25 -0
- package/dist/lib/enrollment-policy.d.ts.map +1 -0
- package/dist/lib/event-names.d.ts +27 -0
- package/dist/lib/event-names.d.ts.map +1 -0
- package/dist/lib/feed.d.ts +64 -0
- package/dist/lib/feed.d.ts.map +1 -0
- package/dist/lib/flags-registry.d.ts +23 -0
- package/dist/lib/flags-registry.d.ts.map +1 -0
- package/dist/lib/flags.d.ts +143 -0
- package/dist/lib/flags.d.ts.map +1 -0
- package/dist/lib/frequency-cap.d.ts +38 -0
- package/dist/lib/frequency-cap.d.ts.map +1 -0
- package/dist/lib/from-address.d.ts +15 -0
- package/dist/lib/from-address.d.ts.map +1 -0
- package/dist/lib/funnel-progress.d.ts +37 -0
- package/dist/lib/funnel-progress.d.ts.map +1 -0
- package/dist/lib/funnel-registry.d.ts +44 -0
- package/dist/lib/funnel-registry.d.ts.map +1 -0
- package/dist/lib/funnel-transitions.d.ts +63 -0
- package/dist/lib/funnel-transitions.d.ts.map +1 -0
- package/dist/lib/fx.d.ts +118 -0
- package/dist/lib/fx.d.ts.map +1 -0
- package/dist/lib/global-control-readout.d.ts +72 -0
- package/dist/lib/global-control-readout.d.ts.map +1 -0
- package/dist/lib/groups.d.ts +138 -0
- package/dist/lib/groups.d.ts.map +1 -0
- package/dist/lib/hatchet-duration.d.ts +14 -0
- package/dist/lib/hatchet-duration.d.ts.map +1 -0
- package/dist/lib/hatchet.d.ts +3 -0
- package/dist/lib/hatchet.d.ts.map +1 -0
- package/dist/lib/headers.d.ts +8 -0
- package/dist/lib/headers.d.ts.map +1 -0
- package/dist/lib/holdout.d.ts +36 -0
- package/dist/lib/holdout.d.ts.map +1 -0
- package/dist/lib/html.d.ts +5 -0
- package/dist/lib/html.d.ts.map +1 -0
- package/dist/lib/identity-service.d.ts +60 -0
- package/dist/lib/identity-service.d.ts.map +1 -0
- package/dist/lib/identity-token.d.ts +81 -0
- package/dist/lib/identity-token.d.ts.map +1 -0
- package/dist/lib/ingestion.d.ts +218 -0
- package/dist/lib/ingestion.d.ts.map +1 -0
- package/dist/lib/journey-lift.d.ts +56 -0
- package/dist/lib/journey-lift.d.ts.map +1 -0
- package/dist/lib/journey-suppress.d.ts +59 -0
- package/dist/lib/journey-suppress.d.ts.map +1 -0
- package/dist/lib/leader-lease.d.ts +36 -0
- package/dist/lib/leader-lease.d.ts.map +1 -0
- package/dist/lib/lift-stats.d.ts +46 -0
- package/dist/lib/lift-stats.d.ts.map +1 -0
- package/dist/lib/links.d.ts +186 -0
- package/dist/lib/links.d.ts.map +1 -0
- package/dist/lib/load-optional-plugin.d.ts +47 -0
- package/dist/lib/load-optional-plugin.d.ts.map +1 -0
- package/dist/lib/logger.d.ts +4 -0
- package/dist/lib/logger.d.ts.map +1 -0
- package/dist/lib/mailer.d.ts +43 -0
- package/dist/lib/mailer.d.ts.map +1 -0
- package/dist/lib/metrics-sql.d.ts +11 -0
- package/dist/lib/metrics-sql.d.ts.map +1 -0
- package/dist/lib/notifications.d.ts +17 -0
- package/dist/lib/notifications.d.ts.map +1 -0
- package/dist/lib/oauth-token-manager.d.ts +74 -0
- package/dist/lib/oauth-token-manager.d.ts.map +1 -0
- package/dist/lib/operator-settings.d.ts +33 -0
- package/dist/lib/operator-settings.d.ts.map +1 -0
- package/dist/lib/operator.d.ts +20 -0
- package/dist/lib/operator.d.ts.map +1 -0
- package/dist/lib/outbound-endpoint-cache.d.ts +25 -0
- package/dist/lib/outbound-endpoint-cache.d.ts.map +1 -0
- package/dist/lib/outbound.d.ts +687 -0
- package/dist/lib/outbound.d.ts.map +1 -0
- package/dist/lib/phone.d.ts +11 -0
- package/dist/lib/phone.d.ts.map +1 -0
- package/dist/lib/posthog-scopes.d.ts +30 -0
- package/dist/lib/posthog-scopes.d.ts.map +1 -0
- package/dist/lib/posthog.d.ts +16 -0
- package/dist/lib/posthog.d.ts.map +1 -0
- package/dist/lib/preferences.d.ts +72 -0
- package/dist/lib/preferences.d.ts.map +1 -0
- package/dist/lib/provider-credentials.d.ts +149 -0
- package/dist/lib/provider-credentials.d.ts.map +1 -0
- package/dist/lib/provision-posthog-loop.d.ts +100 -0
- package/dist/lib/provision-posthog-loop.d.ts.map +1 -0
- package/dist/lib/recipient-preferences.d.ts +29 -0
- package/dist/lib/recipient-preferences.d.ts.map +1 -0
- package/dist/lib/redis.d.ts +33 -0
- package/dist/lib/redis.d.ts.map +1 -0
- package/dist/lib/referral-intent.d.ts +99 -0
- package/dist/lib/referral-intent.d.ts.map +1 -0
- package/dist/lib/referral-link.d.ts +59 -0
- package/dist/lib/referral-link.d.ts.map +1 -0
- package/dist/lib/referral-registry.d.ts +37 -0
- package/dist/lib/referral-registry.d.ts.map +1 -0
- package/dist/lib/referral-report.d.ts +178 -0
- package/dist/lib/referral-report.d.ts.map +1 -0
- package/dist/lib/referral-runtime.d.ts +43 -0
- package/dist/lib/referral-runtime.d.ts.map +1 -0
- package/dist/lib/referrals.d.ts +184 -0
- package/dist/lib/referrals.d.ts.map +1 -0
- package/dist/lib/refine-chain.d.ts +236 -0
- package/dist/lib/refine-chain.d.ts.map +1 -0
- package/dist/lib/refine-traits.d.ts +78 -0
- package/dist/lib/refine-traits.d.ts.map +1 -0
- package/dist/lib/refine.d.ts +35 -0
- package/dist/lib/refine.d.ts.map +1 -0
- package/dist/lib/reset-email.d.ts +38 -0
- package/dist/lib/reset-email.d.ts.map +1 -0
- package/dist/lib/revenue.d.ts +61 -0
- package/dist/lib/revenue.d.ts.map +1 -0
- package/dist/lib/schemas.d.ts +9 -0
- package/dist/lib/schemas.d.ts.map +1 -0
- package/dist/lib/seed-posthog-destination.d.ts +22 -0
- package/dist/lib/seed-posthog-destination.d.ts.map +1 -0
- package/dist/lib/semantic-click.d.ts +58 -0
- package/dist/lib/semantic-click.d.ts.map +1 -0
- package/dist/lib/sending-domain-guidance.d.ts +40 -0
- package/dist/lib/sending-domain-guidance.d.ts.map +1 -0
- package/dist/lib/singleton.d.ts +24 -0
- package/dist/lib/singleton.d.ts.map +1 -0
- package/dist/lib/sms-frequency-cap.d.ts +16 -0
- package/dist/lib/sms-frequency-cap.d.ts.map +1 -0
- package/dist/lib/sms-inbound.d.ts +37 -0
- package/dist/lib/sms-inbound.d.ts.map +1 -0
- package/dist/lib/sms-link-tracking.d.ts +53 -0
- package/dist/lib/sms-link-tracking.d.ts.map +1 -0
- package/dist/lib/sms-mailer.d.ts +12 -0
- package/dist/lib/sms-mailer.d.ts.map +1 -0
- package/dist/lib/sms-provider-registry.d.ts +20 -0
- package/dist/lib/sms-provider-registry.d.ts.map +1 -0
- package/dist/lib/sms-providers-from-env.d.ts +4 -0
- package/dist/lib/sms-providers-from-env.d.ts.map +1 -0
- package/dist/lib/sms-service-types.d.ts +131 -0
- package/dist/lib/sms-service-types.d.ts.map +1 -0
- package/dist/lib/sms-tracked.d.ts +36 -0
- package/dist/lib/sms-tracked.d.ts.map +1 -0
- package/dist/lib/sms.d.ts +58 -0
- package/dist/lib/sms.d.ts.map +1 -0
- package/dist/lib/snippet.d.ts +32 -0
- package/dist/lib/snippet.d.ts.map +1 -0
- package/dist/lib/stable-stringify.d.ts +12 -0
- package/dist/lib/stable-stringify.d.ts.map +1 -0
- package/dist/lib/studio.d.ts +21 -0
- package/dist/lib/studio.d.ts.map +1 -0
- package/dist/lib/survey.d.ts +35 -0
- package/dist/lib/survey.d.ts.map +1 -0
- package/dist/lib/test-mode.d.ts +77 -0
- package/dist/lib/test-mode.d.ts.map +1 -0
- package/dist/lib/timezone.d.ts +55 -0
- package/dist/lib/timezone.d.ts.map +1 -0
- package/dist/lib/tracked.d.ts +95 -0
- package/dist/lib/tracked.d.ts.map +1 -0
- package/dist/lib/tracking-event-names.d.ts +7 -0
- package/dist/lib/tracking-event-names.d.ts.map +1 -0
- package/dist/lib/tracking-events.d.ts +232 -0
- package/dist/lib/tracking-events.d.ts.map +1 -0
- package/dist/lib/tracking.d.ts +47 -0
- package/dist/lib/tracking.d.ts.map +1 -0
- package/dist/lib/unconfigured-email-provider.d.ts +20 -0
- package/dist/lib/unconfigured-email-provider.d.ts.map +1 -0
- package/dist/lib/unique-violation.d.ts +22 -0
- package/dist/lib/unique-violation.d.ts.map +1 -0
- package/dist/lib/user-token.d.ts +44 -0
- package/dist/lib/user-token.d.ts.map +1 -0
- package/dist/lib/variant.d.ts +44 -0
- package/dist/lib/variant.d.ts.map +1 -0
- package/dist/lib/webhook-signing.d.ts +120 -0
- package/dist/lib/webhook-signing.d.ts.map +1 -0
- package/dist/lib/worker-heartbeat.d.ts +18 -0
- package/dist/lib/worker-heartbeat.d.ts.map +1 -0
- package/dist/lists/channels.d.ts +43 -0
- package/dist/lists/channels.d.ts.map +1 -0
- package/dist/lists/define-list.d.ts +76 -0
- package/dist/lists/define-list.d.ts.map +1 -0
- package/dist/lists/registry-singleton.d.ts +8 -0
- package/dist/lists/registry-singleton.d.ts.map +1 -0
- package/dist/lists/registry.d.ts +66 -0
- package/dist/lists/registry.d.ts.map +1 -0
- package/dist/lists/subscription.d.ts +10 -0
- package/dist/lists/subscription.d.ts.map +1 -0
- package/dist/mcp/authoring-guide.d.ts +33 -0
- package/dist/mcp/authoring-guide.d.ts.map +1 -0
- package/dist/mcp/blueprint-tools.d.ts +266 -0
- package/dist/mcp/blueprint-tools.d.ts.map +1 -0
- package/dist/middleware/api-key.d.ts +45 -0
- package/dist/middleware/api-key.d.ts.map +1 -0
- package/dist/middleware/audit.d.ts +3 -0
- package/dist/middleware/audit.d.ts.map +1 -0
- package/dist/middleware/error-handler.d.ts +4 -0
- package/dist/middleware/error-handler.d.ts.map +1 -0
- package/dist/middleware/publishable-key.d.ts +27 -0
- package/dist/middleware/publishable-key.d.ts.map +1 -0
- package/dist/middleware/rate-limit.d.ts +105 -0
- package/dist/middleware/rate-limit.d.ts.map +1 -0
- package/dist/middleware/request-logger.d.ts +4 -0
- package/dist/middleware/request-logger.d.ts.map +1 -0
- package/dist/middleware/require-admin.d.ts +3 -0
- package/dist/middleware/require-admin.d.ts.map +1 -0
- package/dist/routes/_shared.d.ts +52 -0
- package/dist/routes/_shared.d.ts.map +1 -0
- package/dist/routes/accounts/callback.d.ts +18 -0
- package/dist/routes/accounts/callback.d.ts.map +1 -0
- package/dist/routes/accounts/emit.d.ts +96 -0
- package/dist/routes/accounts/emit.d.ts.map +1 -0
- package/dist/routes/accounts/import-links.d.ts +4 -0
- package/dist/routes/accounts/import-links.d.ts.map +1 -0
- package/dist/routes/accounts/index.d.ts +39 -0
- package/dist/routes/accounts/index.d.ts.map +1 -0
- package/dist/routes/accounts/lookup.d.ts +6 -0
- package/dist/routes/accounts/lookup.d.ts.map +1 -0
- package/dist/routes/accounts/me.d.ts +5 -0
- package/dist/routes/accounts/me.d.ts.map +1 -0
- package/dist/routes/accounts/mint.d.ts +5 -0
- package/dist/routes/accounts/mint.d.ts.map +1 -0
- package/dist/routes/accounts/pages.d.ts +23 -0
- package/dist/routes/accounts/pages.d.ts.map +1 -0
- package/dist/routes/accounts/resolve.d.ts +33 -0
- package/dist/routes/accounts/resolve.d.ts.map +1 -0
- package/dist/routes/accounts/serialize.d.ts +57 -0
- package/dist/routes/accounts/serialize.d.ts.map +1 -0
- package/dist/routes/accounts/shared.d.ts +68 -0
- package/dist/routes/accounts/shared.d.ts.map +1 -0
- package/dist/routes/accounts/start.d.ts +16 -0
- package/dist/routes/accounts/start.d.ts.map +1 -0
- package/dist/routes/accounts/unlink.d.ts +36 -0
- package/dist/routes/accounts/unlink.d.ts.map +1 -0
- package/dist/routes/admin/agent.d.ts +4 -0
- package/dist/routes/admin/agent.d.ts.map +1 -0
- package/dist/routes/admin/alerts.d.ts +190 -0
- package/dist/routes/admin/alerts.d.ts.map +1 -0
- package/dist/routes/admin/analytics.d.ts +137 -0
- package/dist/routes/admin/analytics.d.ts.map +1 -0
- package/dist/routes/admin/api-keys.d.ts +158 -0
- package/dist/routes/admin/api-keys.d.ts.map +1 -0
- package/dist/routes/admin/attribution.d.ts +93 -0
- package/dist/routes/admin/attribution.d.ts.map +1 -0
- package/dist/routes/admin/audit-logs.d.ts +40 -0
- package/dist/routes/admin/audit-logs.d.ts.map +1 -0
- package/dist/routes/admin/blueprints.d.ts +4 -0
- package/dist/routes/admin/blueprints.d.ts.map +1 -0
- package/dist/routes/admin/buckets.d.ts +215 -0
- package/dist/routes/admin/buckets.d.ts.map +1 -0
- package/dist/routes/admin/bulk.d.ts +203 -0
- package/dist/routes/admin/bulk.d.ts.map +1 -0
- package/dist/routes/admin/campaigns.d.ts +198 -0
- package/dist/routes/admin/campaigns.d.ts.map +1 -0
- package/dist/routes/admin/connectors.d.ts +116 -0
- package/dist/routes/admin/connectors.d.ts.map +1 -0
- package/dist/routes/admin/contacts.d.ts +246 -0
- package/dist/routes/admin/contacts.d.ts.map +1 -0
- package/dist/routes/admin/conversions.d.ts +103 -0
- package/dist/routes/admin/conversions.d.ts.map +1 -0
- package/dist/routes/admin/deals.d.ts +136 -0
- package/dist/routes/admin/deals.d.ts.map +1 -0
- package/dist/routes/admin/dlq.d.ts +100 -0
- package/dist/routes/admin/dlq.d.ts.map +1 -0
- package/dist/routes/admin/domain.d.ts +314 -0
- package/dist/routes/admin/domain.d.ts.map +1 -0
- package/dist/routes/admin/emails.d.ts +127 -0
- package/dist/routes/admin/emails.d.ts.map +1 -0
- package/dist/routes/admin/events.d.ts +140 -0
- package/dist/routes/admin/events.d.ts.map +1 -0
- package/dist/routes/admin/flags.d.ts +719 -0
- package/dist/routes/admin/flags.d.ts.map +1 -0
- package/dist/routes/admin/funnels.d.ts +71 -0
- package/dist/routes/admin/funnels.d.ts.map +1 -0
- package/dist/routes/admin/groups.d.ts +169 -0
- package/dist/routes/admin/groups.d.ts.map +1 -0
- package/dist/routes/admin/identity.d.ts +72 -0
- package/dist/routes/admin/identity.d.ts.map +1 -0
- package/dist/routes/admin/impact-schemas.d.ts +48 -0
- package/dist/routes/admin/impact-schemas.d.ts.map +1 -0
- package/dist/routes/admin/impact.d.ts +316 -0
- package/dist/routes/admin/impact.d.ts.map +1 -0
- package/dist/routes/admin/index.d.ts +4 -0
- package/dist/routes/admin/index.d.ts.map +1 -0
- package/dist/routes/admin/journey-impact.d.ts +320 -0
- package/dist/routes/admin/journey-impact.d.ts.map +1 -0
- package/dist/routes/admin/journey-logs.d.ts +57 -0
- package/dist/routes/admin/journey-logs.d.ts.map +1 -0
- package/dist/routes/admin/journeys.d.ts +736 -0
- package/dist/routes/admin/journeys.d.ts.map +1 -0
- package/dist/routes/admin/links.d.ts +382 -0
- package/dist/routes/admin/links.d.ts.map +1 -0
- package/dist/routes/admin/lists.d.ts +22 -0
- package/dist/routes/admin/lists.d.ts.map +1 -0
- package/dist/routes/admin/maintenance.d.ts +72 -0
- package/dist/routes/admin/maintenance.d.ts.map +1 -0
- package/dist/routes/admin/metrics.d.ts +212 -0
- package/dist/routes/admin/metrics.d.ts.map +1 -0
- package/dist/routes/admin/open-editor.d.ts +36 -0
- package/dist/routes/admin/open-editor.d.ts.map +1 -0
- package/dist/routes/admin/preferences.d.ts +109 -0
- package/dist/routes/admin/preferences.d.ts.map +1 -0
- package/dist/routes/admin/provider-credentials.d.ts +108 -0
- package/dist/routes/admin/provider-credentials.d.ts.map +1 -0
- package/dist/routes/admin/readiness.d.ts +24 -0
- package/dist/routes/admin/readiness.d.ts.map +1 -0
- package/dist/routes/admin/referrals.d.ts +230 -0
- package/dist/routes/admin/referrals.d.ts.map +1 -0
- package/dist/routes/admin/reporting.d.ts +149 -0
- package/dist/routes/admin/reporting.d.ts.map +1 -0
- package/dist/routes/admin/settings.d.ts +80 -0
- package/dist/routes/admin/settings.d.ts.map +1 -0
- package/dist/routes/admin/suppressions.d.ts +90 -0
- package/dist/routes/admin/suppressions.d.ts.map +1 -0
- package/dist/routes/admin/targeting.d.ts +58 -0
- package/dist/routes/admin/targeting.d.ts.map +1 -0
- package/dist/routes/admin/templates.d.ts +197 -0
- package/dist/routes/admin/templates.d.ts.map +1 -0
- package/dist/routes/admin/timeline.d.ts +51 -0
- package/dist/routes/admin/timeline.d.ts.map +1 -0
- package/dist/routes/admin/webhooks.d.ts +250 -0
- package/dist/routes/admin/webhooks.d.ts.map +1 -0
- package/dist/routes/campaigns/index.d.ts +239 -0
- package/dist/routes/campaigns/index.d.ts.map +1 -0
- package/dist/routes/connectors/index.d.ts +16 -0
- package/dist/routes/connectors/index.d.ts.map +1 -0
- package/dist/routes/contacts/index.d.ts +187 -0
- package/dist/routes/contacts/index.d.ts.map +1 -0
- package/dist/routes/email/index.d.ts +4 -0
- package/dist/routes/email/index.d.ts.map +1 -0
- package/dist/routes/email/preferences.d.ts +17 -0
- package/dist/routes/email/preferences.d.ts.map +1 -0
- package/dist/routes/email/unsubscribe.d.ts +17 -0
- package/dist/routes/email/unsubscribe.d.ts.map +1 -0
- package/dist/routes/emails/index.d.ts +90 -0
- package/dist/routes/emails/index.d.ts.map +1 -0
- package/dist/routes/events/index.d.ts +116 -0
- package/dist/routes/events/index.d.ts.map +1 -0
- package/dist/routes/feed/index.d.ts +248 -0
- package/dist/routes/feed/index.d.ts.map +1 -0
- package/dist/routes/feed/recipient.d.ts +65 -0
- package/dist/routes/feed/recipient.d.ts.map +1 -0
- package/dist/routes/flags/index.d.ts +94 -0
- package/dist/routes/flags/index.d.ts.map +1 -0
- package/dist/routes/groups/index.d.ts +192 -0
- package/dist/routes/groups/index.d.ts.map +1 -0
- package/dist/routes/health.d.ts +57 -0
- package/dist/routes/health.d.ts.map +1 -0
- package/dist/routes/index.d.ts +8 -0
- package/dist/routes/index.d.ts.map +1 -0
- package/dist/routes/lists/index.d.ts +266 -0
- package/dist/routes/lists/index.d.ts.map +1 -0
- package/dist/routes/referrals/index.d.ts +22 -0
- package/dist/routes/referrals/index.d.ts.map +1 -0
- package/dist/routes/referrals/me.d.ts +4 -0
- package/dist/routes/referrals/me.d.ts.map +1 -0
- package/dist/routes/referrals/report.d.ts +5 -0
- package/dist/routes/referrals/report.d.ts.map +1 -0
- package/dist/routes/referrals/shared.d.ts +16 -0
- package/dist/routes/referrals/shared.d.ts.map +1 -0
- package/dist/routes/referrals/touch.d.ts +5 -0
- package/dist/routes/referrals/touch.d.ts.map +1 -0
- package/dist/routes/snippet.d.ts +12 -0
- package/dist/routes/snippet.d.ts.map +1 -0
- package/dist/routes/tracking/answer.d.ts +56 -0
- package/dist/routes/tracking/answer.d.ts.map +1 -0
- package/dist/routes/tracking/arrive.d.ts +32 -0
- package/dist/routes/tracking/arrive.d.ts.map +1 -0
- package/dist/routes/tracking/click-pipeline.d.ts +213 -0
- package/dist/routes/tracking/click-pipeline.d.ts.map +1 -0
- package/dist/routes/tracking/click.d.ts +26 -0
- package/dist/routes/tracking/click.d.ts.map +1 -0
- package/dist/routes/tracking/identify.d.ts +32 -0
- package/dist/routes/tracking/identify.d.ts.map +1 -0
- package/dist/routes/tracking/index.d.ts +4 -0
- package/dist/routes/tracking/index.d.ts.map +1 -0
- package/dist/routes/tracking/open.d.ts +17 -0
- package/dist/routes/tracking/open.d.ts.map +1 -0
- package/dist/routes/tracking/short.d.ts +17 -0
- package/dist/routes/tracking/short.d.ts.map +1 -0
- package/dist/routes/tracking/vanity.d.ts +17 -0
- package/dist/routes/tracking/vanity.d.ts.map +1 -0
- package/dist/routes/webhooks/crm-provider.d.ts +24 -0
- package/dist/routes/webhooks/crm-provider.d.ts.map +1 -0
- package/dist/routes/webhooks/email-provider.d.ts +21 -0
- package/dist/routes/webhooks/email-provider.d.ts.map +1 -0
- package/dist/routes/webhooks/index.d.ts +8 -0
- package/dist/routes/webhooks/index.d.ts.map +1 -0
- package/dist/routes/webhooks/resend.d.ts +35 -0
- package/dist/routes/webhooks/resend.d.ts.map +1 -0
- package/dist/routes/webhooks/sms-provider.d.ts +23 -0
- package/dist/routes/webhooks/sms-provider.d.ts.map +1 -0
- package/dist/routes/webhooks/sources.d.ts +12 -0
- package/dist/routes/webhooks/sources.d.ts.map +1 -0
- package/dist/sources/define-contact-source.d.ts +114 -0
- package/dist/sources/define-contact-source.d.ts.map +1 -0
- package/dist/sources/registry.d.ts +31 -0
- package/dist/sources/registry.d.ts.map +1 -0
- package/dist/sources/webhook-source.d.ts +53 -0
- package/dist/sources/webhook-source.d.ts.map +1 -0
- package/dist/testing.d.ts +10 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/webhook-sources/define-webhook-source.d.ts +60 -0
- package/dist/webhook-sources/define-webhook-source.d.ts.map +1 -0
- package/dist/webhook-sources/presets/clerk.d.ts +9 -0
- package/dist/webhook-sources/presets/clerk.d.ts.map +1 -0
- package/dist/webhook-sources/presets/index.d.ts +140 -0
- package/dist/webhook-sources/presets/index.d.ts.map +1 -0
- package/dist/webhook-sources/presets/intercom.d.ts +44 -0
- package/dist/webhook-sources/presets/intercom.d.ts.map +1 -0
- package/dist/webhook-sources/presets/segment.d.ts +16 -0
- package/dist/webhook-sources/presets/segment.d.ts.map +1 -0
- package/dist/webhook-sources/presets/stripe.d.ts +20 -0
- package/dist/webhook-sources/presets/stripe.d.ts.map +1 -0
- package/dist/webhook-sources/presets/supabase.d.ts +23 -0
- package/dist/webhook-sources/presets/supabase.d.ts.map +1 -0
- package/dist/webhook-sources/verify.d.ts +48 -0
- package/dist/webhook-sources/verify.d.ts.map +1 -0
- package/dist/worker.d.ts +37 -0
- package/dist/worker.d.ts.map +1 -0
- package/dist/workflows/backfill-contact-id.d.ts +202 -0
- package/dist/workflows/backfill-contact-id.d.ts.map +1 -0
- package/dist/workflows/bucket-backfill.d.ts +64 -0
- package/dist/workflows/bucket-backfill.d.ts.map +1 -0
- package/dist/workflows/bucket-reconcile.d.ts +73 -0
- package/dist/workflows/bucket-reconcile.d.ts.map +1 -0
- package/dist/workflows/check-alerts.d.ts +10 -0
- package/dist/workflows/check-alerts.d.ts.map +1 -0
- package/dist/workflows/confirm-semantic-click.d.ts +15 -0
- package/dist/workflows/confirm-semantic-click.d.ts.map +1 -0
- package/dist/workflows/crm-reconcile.d.ts +27 -0
- package/dist/workflows/crm-reconcile.d.ts.map +1 -0
- package/dist/workflows/deliver-webhook.d.ts +88 -0
- package/dist/workflows/deliver-webhook.d.ts.map +1 -0
- package/dist/workflows/dispatch-conversion.d.ts +14 -0
- package/dist/workflows/dispatch-conversion.d.ts.map +1 -0
- package/dist/workflows/identity-alias-backfill.d.ts +96 -0
- package/dist/workflows/identity-alias-backfill.d.ts.map +1 -0
- package/dist/workflows/impact-digest.d.ts +142 -0
- package/dist/workflows/impact-digest.d.ts.map +1 -0
- package/dist/workflows/import-contacts.d.ts +14 -0
- package/dist/workflows/import-contacts.d.ts.map +1 -0
- package/dist/workflows/import-suppressions.d.ts +55 -0
- package/dist/workflows/import-suppressions.d.ts.map +1 -0
- package/dist/workflows/journey-blueprint-interpreter.d.ts +73 -0
- package/dist/workflows/journey-blueprint-interpreter.d.ts.map +1 -0
- package/dist/workflows/send-campaign.d.ts +128 -0
- package/dist/workflows/send-campaign.d.ts.map +1 -0
- package/dist/workflows/send-email.d.ts +15 -0
- package/dist/workflows/send-email.d.ts.map +1 -0
- package/dist/workflows/send-feed.d.ts +37 -0
- package/dist/workflows/send-feed.d.ts.map +1 -0
- package/package.json +60 -22
- package/src/app.ts +9 -1
- package/src/buckets/check-membership.ts +54 -20
- package/src/env.ts +30 -0
- package/src/journeys/journey-log.ts +25 -8
- package/src/lib/contacts.ts +47 -1
- package/src/lib/email-service-types.ts +10 -0
- package/src/lib/ingestion.ts +30 -19
- package/src/lib/mailer-bounce-idempotency.test.ts +7 -2
- package/src/lib/mailer-replied.test.ts +7 -2
- package/src/lib/mailer.ts +1 -0
- package/src/lib/outbound-endpoint-cache.ts +83 -0
- package/src/lib/outbound.ts +56 -37
- package/src/lib/seed-posthog-destination.ts +5 -1
- package/src/lib/tracked.ts +11 -3
- package/src/lib/tracking-events.ts +20 -3
- package/src/middleware/api-key.ts +69 -60
- package/src/middleware/publishable-key.ts +11 -23
- package/src/middleware/rate-limit.ts +165 -3
- package/src/routes/admin/api-keys.ts +148 -0
- package/src/routes/admin/targeting.ts +6 -1
- package/src/routes/admin/webhooks.ts +4 -0
- package/src/routes/index.ts +67 -24
- package/src/workflows/backfill-contact-id.ts +3 -7
- package/src/workflows/bucket-backfill.ts +2 -2
- package/src/workflows/bucket-reconcile.ts +28 -12
- package/src/workflows/check-alerts.ts +3 -9
- package/src/workflows/crm-reconcile.ts +3 -2
- package/src/workflows/deliver-webhook.ts +21 -8
- package/src/workflows/dispatch-conversion.ts +2 -2
- package/src/workflows/identity-alias-backfill.ts +3 -2
- package/src/workflows/impact-digest.ts +2 -2
- package/src/workflows/import-contacts.ts +3 -4
- package/src/workflows/import-suppressions.ts +4 -5
- package/src/workflows/send-campaign.ts +10 -1
package/src/lib/contacts.ts
CHANGED
|
@@ -46,7 +46,7 @@ import { createLogger } from "./logger.js";
|
|
|
46
46
|
* stays logger-free. */
|
|
47
47
|
const logger = createLogger(process.env.LOG_LEVEL);
|
|
48
48
|
|
|
49
|
-
const UUID_REGEX =
|
|
49
|
+
export const UUID_REGEX =
|
|
50
50
|
/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
51
51
|
|
|
52
52
|
/**
|
|
@@ -2881,12 +2881,23 @@ async function foldEmailPreferences(
|
|
|
2881
2881
|
* pref-fold), stamp-only writes.
|
|
2882
2882
|
*
|
|
2883
2883
|
* Idempotent: a second run finds `contact_id` already set and matches nothing.
|
|
2884
|
+
*
|
|
2885
|
+
* GATED (PRD 09): every warm resolve calls this for the contact's own key,
|
|
2886
|
+
* and almost always there is nothing to adopt. One existence probe
|
|
2887
|
+
* ({@link hasOrphanHistory}) decides first; when it finds no orphan row the
|
|
2888
|
+
* eight statements below are skipped. That is a pure cost cut, not a
|
|
2889
|
+
* behaviour change: each statement below matches only rows with
|
|
2890
|
+
* `user_id = fromKey AND contact_id IS NULL` (the folds' `orphansOnly` loser
|
|
2891
|
+
* scope), so when no such row exists in any of the five tables every one of
|
|
2892
|
+
* them is a no-op.
|
|
2884
2893
|
*/
|
|
2885
2894
|
async function adoptOrphanHistory(
|
|
2886
2895
|
tx: Tx,
|
|
2887
2896
|
fromKey: string,
|
|
2888
2897
|
row: ContactRow,
|
|
2889
2898
|
): Promise<void> {
|
|
2899
|
+
if (!(await hasOrphanHistory(tx, fromKey))) return;
|
|
2900
|
+
|
|
2890
2901
|
const ownKey = contactKey(row);
|
|
2891
2902
|
|
|
2892
2903
|
// user_events + email_sends: no unique constraint involved — plain stamps.
|
|
@@ -2922,6 +2933,41 @@ async function adoptOrphanHistory(
|
|
|
2922
2933
|
// add a test instead if you doubt it.
|
|
2923
2934
|
}
|
|
2924
2935
|
|
|
2936
|
+
/**
|
|
2937
|
+
* The orphan-adoption gate (PRD 09): ONE statement answering "does any of the
|
|
2938
|
+
* five history tables hold a row under `fromKey` that no contact owns?".
|
|
2939
|
+
*
|
|
2940
|
+
* The predicate is exactly the loser scope {@link adoptOrphanHistory}'s
|
|
2941
|
+
* statements use (`user_id = fromKey AND contact_id IS NULL`), deliberately
|
|
2942
|
+
* WITHOUT their `deleted_at` / `status` refinements: the probe only has to be
|
|
2943
|
+
* a superset, so a false positive costs the old eight statements and a false
|
|
2944
|
+
* negative is impossible.
|
|
2945
|
+
*
|
|
2946
|
+
* Every leg is indexed: `user_events` / `email_sends` through their partial
|
|
2947
|
+
* `*_orphan_user_id_idx` (migration 0075, which holds ONLY contactless rows,
|
|
2948
|
+
* so a known contact's probe never walks its history), the other three
|
|
2949
|
+
* through their existing `user_id`-leading indexes. The uncorrelated EXISTS
|
|
2950
|
+
* subqueries are init-plans Postgres evaluates lazily left to right, so the
|
|
2951
|
+
* OR stops at the first leg that finds a row.
|
|
2952
|
+
*/
|
|
2953
|
+
async function hasOrphanHistory(tx: Tx, fromKey: string): Promise<boolean> {
|
|
2954
|
+
const tables = [
|
|
2955
|
+
userEvents,
|
|
2956
|
+
emailSends,
|
|
2957
|
+
journeyStates,
|
|
2958
|
+
bucketMemberships,
|
|
2959
|
+
emailPreferences,
|
|
2960
|
+
] as const;
|
|
2961
|
+
const legs = tables.map(
|
|
2962
|
+
(table) =>
|
|
2963
|
+
sql`exists (select 1 from ${table} where ${table.userId} = ${fromKey} and ${table.contactId} is null)`,
|
|
2964
|
+
);
|
|
2965
|
+
const rows = (await tx.execute(
|
|
2966
|
+
sql`select (${sql.join(legs, sql` or `)}) as "found"`,
|
|
2967
|
+
)) as unknown as Array<{ found: boolean }>;
|
|
2968
|
+
return rows[0]?.found === true;
|
|
2969
|
+
}
|
|
2970
|
+
|
|
2925
2971
|
/** RECORD a contact_aliases row per loser key → survivor (reason 'merge'). */
|
|
2926
2972
|
async function recordMergeAliases(
|
|
2927
2973
|
tx: Tx,
|
|
@@ -52,6 +52,14 @@ export interface SendTrackedEmailOptions<
|
|
|
52
52
|
* transactional sends.
|
|
53
53
|
*/
|
|
54
54
|
campaignId?: string;
|
|
55
|
+
/**
|
|
56
|
+
* The recipient's `contacts.id` when the caller already holds it fresh (a
|
|
57
|
+
* campaign resolver that joined `contacts`). The mailer then stamps
|
|
58
|
+
* `email_sends.contact_id` with it instead of resolving `userId` again. Leave
|
|
59
|
+
* it unset unless the id was read in the same unit of work: a journey's
|
|
60
|
+
* enrollment-time id can go stale across a merge.
|
|
61
|
+
*/
|
|
62
|
+
contactId?: string;
|
|
55
63
|
/** Denormalized recipient identity, persisted on the email_sends row for reporting. */
|
|
56
64
|
userId?: string;
|
|
57
65
|
userEmail?: string;
|
|
@@ -183,6 +191,8 @@ export interface EmailServiceSendOptions<
|
|
|
183
191
|
journeyStateId?: string;
|
|
184
192
|
/** Campaign identity for campaign-dispatched sends (see SendTrackedEmailOptions). */
|
|
185
193
|
campaignId?: string;
|
|
194
|
+
/** A fresh `contacts.id` for the recipient (see SendTrackedEmailOptions). */
|
|
195
|
+
contactId?: string;
|
|
186
196
|
/** Denormalized recipient identity, persisted on the email_sends row for reporting. */
|
|
187
197
|
userId?: string;
|
|
188
198
|
userEmail?: string;
|
package/src/lib/ingestion.ts
CHANGED
|
@@ -17,7 +17,7 @@ import {
|
|
|
17
17
|
import { and, eq, inArray, isNull } from "drizzle-orm";
|
|
18
18
|
import { checkBucketMembership } from "../buckets/check-membership.js";
|
|
19
19
|
import { BLUEPRINT_RUN_EVENT } from "../journeys/constants.js";
|
|
20
|
-
import {
|
|
20
|
+
import { logTransitions } from "../journeys/journey-log.js";
|
|
21
21
|
import {
|
|
22
22
|
logResidualTwins,
|
|
23
23
|
mergeAnalyticsIdentities,
|
|
@@ -1074,16 +1074,26 @@ async function checkExits(
|
|
|
1074
1074
|
): Promise<ExitResult[]> {
|
|
1075
1075
|
const results: ExitResult[] = [];
|
|
1076
1076
|
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
)
|
|
1086
|
-
|
|
1077
|
+
// Only the three columns the exit decision and the cancel need: a state row
|
|
1078
|
+
// carries the journey's whole `context` jsonb, and this read runs on every
|
|
1079
|
+
// ingest for every active enrollment the subject has.
|
|
1080
|
+
const activeStates = await db
|
|
1081
|
+
.select({
|
|
1082
|
+
id: journeyStates.id,
|
|
1083
|
+
journeyId: journeyStates.journeyId,
|
|
1084
|
+
hatchetRunId: journeyStates.hatchetRunId,
|
|
1085
|
+
})
|
|
1086
|
+
.from(journeyStates)
|
|
1087
|
+
.where(
|
|
1088
|
+
and(
|
|
1089
|
+
bySubject(journeyStates, {
|
|
1090
|
+
contactId: event.contactId,
|
|
1091
|
+
userKey: event.userId,
|
|
1092
|
+
}),
|
|
1093
|
+
inArray(journeyStates.status, ["active", "waiting"]),
|
|
1094
|
+
isNull(journeyStates.deletedAt),
|
|
1095
|
+
),
|
|
1096
|
+
);
|
|
1087
1097
|
|
|
1088
1098
|
// Blueprint enrollments share journeyStates but are NOT in the code-journey
|
|
1089
1099
|
// registry — their exitOn lives on the journey_blueprints row (spec §4).
|
|
@@ -1156,17 +1166,18 @@ async function checkExits(
|
|
|
1156
1166
|
})
|
|
1157
1167
|
.where(inArray(journeyStates.id, statesToExit));
|
|
1158
1168
|
|
|
1159
|
-
// Fire-and-forget EXIT transition logs
|
|
1160
|
-
// already best-effort around the hatchet
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1169
|
+
// Fire-and-forget EXIT transition logs, one insert for the batch
|
|
1170
|
+
// (best-effort; the exit path is already best-effort around the hatchet
|
|
1171
|
+
// cancel below). Never throws.
|
|
1172
|
+
logTransitions(
|
|
1173
|
+
db,
|
|
1174
|
+
statesToExit.map((id) => ({
|
|
1164
1175
|
journeyStateId: id,
|
|
1165
1176
|
from: null,
|
|
1166
1177
|
to: "end-exited",
|
|
1167
|
-
action: "exited",
|
|
1168
|
-
})
|
|
1169
|
-
|
|
1178
|
+
action: "exited" as const,
|
|
1179
|
+
})),
|
|
1180
|
+
);
|
|
1170
1181
|
|
|
1171
1182
|
// Cancel the live durable runs so a journey suspended in a sleep or
|
|
1172
1183
|
// `waitForEvent` can't resume and fire after it has exited. Best-effort: a
|
|
@@ -16,6 +16,7 @@ process.env.BETTER_AUTH_SECRET ??= "test-secret";
|
|
|
16
16
|
process.env.HATCHET_CLIENT_TOKEN ??=
|
|
17
17
|
"eyJhbGciOiJFUzI1NiIsImtpZCI6InRlc3QifQ.eyJhdWQiOiJsb2NhbGhvc3QiLCJleHAiOjQ5MzMyNDA5ODMsImdycGNfYnJvYWRjYXN0X2FkZHJlc3MiOiJsb2NhbGhvc3Q6NzA3NyIsImlhdCI6MTc3OTY0MDk4MywiaXNzIjoibG9jYWxob3N0Iiwic2VydmVyX3VybCI6ImxvY2FsaG9zdCIsInN1YiI6InRlc3QtdGVuYW50LWlkIiwidG9rZW5faWQiOiJ0ZXN0LXRva2VuLWlkIn0.test";
|
|
18
18
|
const { createTrackedMailer } = await import("./mailer.js");
|
|
19
|
+
const { WEBHOOK_EVENT_TYPES } = await import("./webhook-signing.js");
|
|
19
20
|
|
|
20
21
|
/**
|
|
21
22
|
* BOUNCE IDEMPOTENCY.
|
|
@@ -203,8 +204,12 @@ function fakeDb(rows: FakeSend[]): FakeDb {
|
|
|
203
204
|
),
|
|
204
205
|
}),
|
|
205
206
|
}),
|
|
206
|
-
// One subscribed
|
|
207
|
-
|
|
207
|
+
// One endpoint subscribed to every event, so the spine has
|
|
208
|
+
// somewhere to deliver whatever the path emits.
|
|
209
|
+
where: () =>
|
|
210
|
+
Promise.resolve([
|
|
211
|
+
{ id: "endpoint-1", eventTypes: [...WEBHOOK_EVENT_TYPES] },
|
|
212
|
+
]),
|
|
208
213
|
};
|
|
209
214
|
},
|
|
210
215
|
};
|
|
@@ -15,6 +15,7 @@ process.env.BETTER_AUTH_SECRET ??= "test-secret";
|
|
|
15
15
|
process.env.HATCHET_CLIENT_TOKEN ??=
|
|
16
16
|
"eyJhbGciOiJFUzI1NiIsImtpZCI6InRlc3QifQ.eyJhdWQiOiJsb2NhbGhvc3QiLCJleHAiOjQ5MzMyNDA5ODMsImdycGNfYnJvYWRjYXN0X2FkZHJlc3MiOiJsb2NhbGhvc3Q6NzA3NyIsImlhdCI6MTc3OTY0MDk4MywiaXNzIjoibG9jYWxob3N0Iiwic2VydmVyX3VybCI6ImxvY2FsaG9zdCIsInN1YiI6InRlc3QtdGVuYW50LWlkIiwidG9rZW5faWQiOiJ0ZXN0LXRva2VuLWlkIn0.test";
|
|
17
17
|
const { createTrackedMailer } = await import("./mailer.js");
|
|
18
|
+
const { WEBHOOK_EVENT_TYPES } = await import("./webhook-signing.js");
|
|
18
19
|
|
|
19
20
|
/**
|
|
20
21
|
* `email.replied` handling (PRD 16 task 5).
|
|
@@ -128,8 +129,12 @@ function recordingDb(selectRows: SendRow[] = []): {
|
|
|
128
129
|
leftJoin: () => ({
|
|
129
130
|
where: () => ({ limit: () => Promise.resolve(selectRows) }),
|
|
130
131
|
}),
|
|
131
|
-
// One subscribed
|
|
132
|
-
|
|
132
|
+
// One endpoint subscribed to every event, so the spine has
|
|
133
|
+
// somewhere to deliver whatever the path emits.
|
|
134
|
+
where: () =>
|
|
135
|
+
Promise.resolve([
|
|
136
|
+
{ id: "endpoint-1", eventTypes: [...WEBHOOK_EVENT_TYPES] },
|
|
137
|
+
]),
|
|
133
138
|
};
|
|
134
139
|
},
|
|
135
140
|
};
|
package/src/lib/mailer.ts
CHANGED
|
@@ -224,6 +224,7 @@ export function createTrackedMailer(
|
|
|
224
224
|
subject: options.subject,
|
|
225
225
|
journeyStateId: options.journeyStateId,
|
|
226
226
|
campaignId: options.campaignId,
|
|
227
|
+
contactId: options.contactId,
|
|
227
228
|
userId: options.userId,
|
|
228
229
|
userEmail: options.userEmail,
|
|
229
230
|
category: options.category,
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { type Database, webhookEndpoints } from "@hogsend/db";
|
|
2
|
+
import { and, eq, isNull } from "drizzle-orm";
|
|
3
|
+
|
|
4
|
+
/** How long the enabled-endpoint list is reused before a re-read. */
|
|
5
|
+
const DEFAULT_ENDPOINT_CACHE_TTL_MS = 30_000;
|
|
6
|
+
|
|
7
|
+
interface CachedEndpoint {
|
|
8
|
+
id: string;
|
|
9
|
+
eventTypes: string[];
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
interface CacheEntry {
|
|
13
|
+
rows: CachedEndpoint[];
|
|
14
|
+
loadedAt: number;
|
|
15
|
+
generation: number;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// One entry per database client, so two databases in one process (tests,
|
|
19
|
+
// a multi-database host) never read each other's endpoints.
|
|
20
|
+
const endpointCache = new WeakMap<Database, CacheEntry>();
|
|
21
|
+
// Bumped by every invalidation. An entry from an older generation is ignored,
|
|
22
|
+
// and a read that started before an admin write can't put the pre-write list
|
|
23
|
+
// back into the cache when it finishes.
|
|
24
|
+
let endpointCacheGeneration = 0;
|
|
25
|
+
|
|
26
|
+
function endpointCacheTtlMs(): number {
|
|
27
|
+
const raw = process.env.OUTBOUND_ENDPOINT_CACHE_TTL_MS;
|
|
28
|
+
if (raw === undefined || raw === "") return DEFAULT_ENDPOINT_CACHE_TTL_MS;
|
|
29
|
+
const ttl = Number(raw);
|
|
30
|
+
return Number.isFinite(ttl) && ttl >= 0 ? ttl : DEFAULT_ENDPOINT_CACHE_TTL_MS;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Drop the cached endpoint list so the next emit re-reads `webhook_endpoints`.
|
|
35
|
+
* Every engine writer of that table calls this (the admin webhook routes and
|
|
36
|
+
* the PostHog destination seed). It only clears THIS process: another API
|
|
37
|
+
* instance or the worker picks the change up when its own copy expires
|
|
38
|
+
* (`OUTBOUND_ENDPOINT_CACHE_TTL_MS`, default 30 s). A disabled or deleted
|
|
39
|
+
* endpoint, or an event it was just unsubscribed from, is still never sent to
|
|
40
|
+
* inside that window: the delivery task re-reads the endpoint row before every
|
|
41
|
+
* attempt. `emitOutbound` retries once on the foreign-key error a deleted
|
|
42
|
+
* cached endpoint causes, so the other endpoints keep their delivery.
|
|
43
|
+
*/
|
|
44
|
+
export function invalidateOutboundEndpointCache(): void {
|
|
45
|
+
endpointCacheGeneration += 1;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Every enabled single-tenant endpoint with its subscriptions, read at most
|
|
50
|
+
* once per TTL. The per-event filter runs in memory: an install has a handful
|
|
51
|
+
* of endpoints, and this saves a query on every outbound emit.
|
|
52
|
+
*/
|
|
53
|
+
export async function loadSubscribableEndpoints(
|
|
54
|
+
db: Database,
|
|
55
|
+
): Promise<CachedEndpoint[]> {
|
|
56
|
+
const ttl = endpointCacheTtlMs();
|
|
57
|
+
const now = Date.now();
|
|
58
|
+
const cached = ttl > 0 ? endpointCache.get(db) : undefined;
|
|
59
|
+
if (
|
|
60
|
+
cached &&
|
|
61
|
+
cached.generation === endpointCacheGeneration &&
|
|
62
|
+
now - cached.loadedAt < ttl
|
|
63
|
+
) {
|
|
64
|
+
return cached.rows;
|
|
65
|
+
}
|
|
66
|
+
const generation = endpointCacheGeneration;
|
|
67
|
+
const rows = await db
|
|
68
|
+
.select({
|
|
69
|
+
id: webhookEndpoints.id,
|
|
70
|
+
eventTypes: webhookEndpoints.eventTypes,
|
|
71
|
+
})
|
|
72
|
+
.from(webhookEndpoints)
|
|
73
|
+
.where(
|
|
74
|
+
and(
|
|
75
|
+
eq(webhookEndpoints.disabled, false),
|
|
76
|
+
isNull(webhookEndpoints.organizationId),
|
|
77
|
+
),
|
|
78
|
+
);
|
|
79
|
+
if (ttl > 0 && generation === endpointCacheGeneration) {
|
|
80
|
+
endpointCache.set(db, { rows, loadedAt: now, generation });
|
|
81
|
+
}
|
|
82
|
+
return rows;
|
|
83
|
+
}
|
package/src/lib/outbound.ts
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
2
|
import type { HatchetClient } from "@hatchet-dev/typescript-sdk/v1/index.js";
|
|
3
|
-
import {
|
|
4
|
-
type Database,
|
|
5
|
-
webhookDeliveries,
|
|
6
|
-
webhookEndpoints,
|
|
7
|
-
} from "@hogsend/db";
|
|
8
|
-
import { and, eq, isNull, sql } from "drizzle-orm";
|
|
3
|
+
import { type Database, webhookDeliveries } from "@hogsend/db";
|
|
9
4
|
import { deliverWebhookTask } from "../workflows/deliver-webhook.js";
|
|
10
5
|
import type { SerializedContact } from "./contacts.js";
|
|
11
6
|
import type { Logger } from "./logger.js";
|
|
7
|
+
import {
|
|
8
|
+
invalidateOutboundEndpointCache,
|
|
9
|
+
loadSubscribableEndpoints,
|
|
10
|
+
} from "./outbound-endpoint-cache.js";
|
|
12
11
|
import {
|
|
13
12
|
WEBHOOK_EVENT_TYPES,
|
|
14
13
|
type WebhookEventType,
|
|
@@ -28,6 +27,16 @@ export {
|
|
|
28
27
|
resolveEmailSendContextByResendId,
|
|
29
28
|
} from "./tracking-events.js";
|
|
30
29
|
|
|
30
|
+
/** Postgres `foreign_key_violation`; drizzle nests the driver error in `cause`. */
|
|
31
|
+
function isForeignKeyViolation(error: unknown): boolean {
|
|
32
|
+
for (let e = error, depth = 0; e && depth < 5; depth++) {
|
|
33
|
+
const candidate = e as { code?: string; cause?: unknown };
|
|
34
|
+
if (candidate.code === "23503") return true;
|
|
35
|
+
e = candidate.cause;
|
|
36
|
+
}
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
|
|
31
40
|
/**
|
|
32
41
|
* The outbound event catalog re-exported for the emit spine. Identical to the
|
|
33
42
|
* signing lib's {@link WEBHOOK_EVENT_TYPES} — the single source of truth.
|
|
@@ -717,19 +726,14 @@ export async function emitOutbound<E extends OutboundEventName>(opts: {
|
|
|
717
726
|
const webhookId = `msg_${randomUUID()}`;
|
|
718
727
|
const timestamp = new Date();
|
|
719
728
|
|
|
720
|
-
// (2) Active, subscribed endpoints
|
|
721
|
-
//
|
|
722
|
-
//
|
|
723
|
-
const
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
.where(
|
|
727
|
-
and(
|
|
728
|
-
eq(webhookEndpoints.disabled, false),
|
|
729
|
-
isNull(webhookEndpoints.organizationId),
|
|
730
|
-
sql`${webhookEndpoints.eventTypes} @> ${JSON.stringify([event])}::jsonb`,
|
|
731
|
-
),
|
|
729
|
+
// (2) Active, subscribed endpoints, from the endpoint cache below.
|
|
730
|
+
// Single-tenant: organizationId IS NULL (NOT a hardcoded tenant — keeps the
|
|
731
|
+
// MT wiring non-breaking).
|
|
732
|
+
const subscribed = async () =>
|
|
733
|
+
(await loadSubscribableEndpoints(db)).filter((endpoint) =>
|
|
734
|
+
endpoint.eventTypes.includes(event),
|
|
732
735
|
);
|
|
736
|
+
let endpoints = await subscribed();
|
|
733
737
|
|
|
734
738
|
if (endpoints.length === 0) return;
|
|
735
739
|
|
|
@@ -743,25 +747,40 @@ export async function emitOutbound<E extends OutboundEventName>(opts: {
|
|
|
743
747
|
|
|
744
748
|
// (4) One delivery row per endpoint, sharing the webhookId. onConflictDoNothing
|
|
745
749
|
// on (endpointId, dedupeKey) is the producer-side fan-out idempotency guard.
|
|
746
|
-
const
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
750
|
+
const insertDeliveries = (targets: typeof endpoints) =>
|
|
751
|
+
db
|
|
752
|
+
.insert(webhookDeliveries)
|
|
753
|
+
.values(
|
|
754
|
+
targets.map((endpoint) => ({
|
|
755
|
+
endpointId: endpoint.id,
|
|
756
|
+
organizationId,
|
|
757
|
+
webhookId,
|
|
758
|
+
eventType: event,
|
|
759
|
+
dedupeKey: dedupeKey ?? null,
|
|
760
|
+
payload: envelope as unknown as Record<string, unknown>,
|
|
761
|
+
status: "pending" as const,
|
|
762
|
+
attemptCount: 0,
|
|
763
|
+
nextRetryAt: timestamp,
|
|
764
|
+
})),
|
|
765
|
+
)
|
|
766
|
+
.onConflictDoNothing({
|
|
767
|
+
target: [webhookDeliveries.endpointId, webhookDeliveries.dedupeKey],
|
|
768
|
+
})
|
|
769
|
+
.returning({ id: webhookDeliveries.id });
|
|
770
|
+
|
|
771
|
+
let inserted: Awaited<ReturnType<typeof insertDeliveries>>;
|
|
772
|
+
try {
|
|
773
|
+
inserted = await insertDeliveries(endpoints);
|
|
774
|
+
} catch (error) {
|
|
775
|
+
// A cached endpoint was deleted on another instance: the FK fails the
|
|
776
|
+
// whole multi-row insert, which would drop the event for every OTHER
|
|
777
|
+
// endpoint too. Re-read the endpoints and retry once without it.
|
|
778
|
+
if (!isForeignKeyViolation(error)) throw error;
|
|
779
|
+
invalidateOutboundEndpointCache();
|
|
780
|
+
endpoints = await subscribed();
|
|
781
|
+
if (endpoints.length === 0) return;
|
|
782
|
+
inserted = await insertDeliveries(endpoints);
|
|
783
|
+
}
|
|
765
784
|
|
|
766
785
|
// (5) Enqueue the durable delivery task per freshly-inserted row,
|
|
767
786
|
// fire-and-forget. A failed enqueue is recovered by the reaper (the row is
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type Database, webhookEndpoints } from "@hogsend/db";
|
|
2
2
|
import { and, eq, isNull, sql } from "drizzle-orm";
|
|
3
3
|
import type { Logger } from "./logger.js";
|
|
4
|
+
import { invalidateOutboundEndpointCache } from "./outbound-endpoint-cache.js";
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Transaction-scoped advisory-lock key serializing the single-tenant PostHog
|
|
@@ -59,7 +60,7 @@ export async function seedPostHogDestination(opts: {
|
|
|
59
60
|
// build the client) with a transaction-scoped advisory lock, so the race can
|
|
60
61
|
// never double-seed. A per-endpoint unique constraint is intentionally avoided
|
|
61
62
|
// — operators may legitimately create multiple PostHog endpoints by hand.
|
|
62
|
-
|
|
63
|
+
const result = await db.transaction(async (tx) => {
|
|
63
64
|
await tx.execute(
|
|
64
65
|
sql`SELECT pg_advisory_xact_lock(${SEED_ADVISORY_LOCK_KEY})`,
|
|
65
66
|
);
|
|
@@ -153,4 +154,7 @@ export async function seedPostHogDestination(opts: {
|
|
|
153
154
|
});
|
|
154
155
|
return { seeded: true };
|
|
155
156
|
});
|
|
157
|
+
// After commit: the outbound spine must see a seeded or reconciled row now.
|
|
158
|
+
invalidateOutboundEndpointCache();
|
|
159
|
+
return result;
|
|
156
160
|
}
|
package/src/lib/tracked.ts
CHANGED
|
@@ -25,7 +25,7 @@ import {
|
|
|
25
25
|
assertAttachmentsSendable,
|
|
26
26
|
attachmentSendMetadata,
|
|
27
27
|
} from "./attachments.js";
|
|
28
|
-
import { lookupContactIdByKey } from "./contacts.js";
|
|
28
|
+
import { lookupContactIdByKey, UUID_REGEX } from "./contacts.js";
|
|
29
29
|
import type { TestModeState } from "./domain-status.js";
|
|
30
30
|
import {
|
|
31
31
|
type FrequencyCapConfig,
|
|
@@ -276,8 +276,16 @@ async function sendTrackedEmailInner<K extends TemplateName>(
|
|
|
276
276
|
//
|
|
277
277
|
// D6 — wrapped: a bookkeeping resolve may never fail the send it rides on.
|
|
278
278
|
// Placed AFTER the idempotency short-circuit so a deduped retry pays nothing.
|
|
279
|
-
|
|
280
|
-
|
|
279
|
+
//
|
|
280
|
+
// PRD 09 part B — a caller that already holds the recipient's contact id
|
|
281
|
+
// (the campaign resolvers join `contacts`) passes it and skips the resolve.
|
|
282
|
+
// A value that is not a uuid (an external id passed by mistake) would fail
|
|
283
|
+
// the `email_sends` insert, so it falls back to the resolve instead (D6).
|
|
284
|
+
let sendContactId: string | null =
|
|
285
|
+
options.contactId && UUID_REGEX.test(options.contactId)
|
|
286
|
+
? options.contactId
|
|
287
|
+
: null;
|
|
288
|
+
if (sendContactId === null && options.userId) {
|
|
281
289
|
try {
|
|
282
290
|
sendContactId = await lookupContactIdByKey(db, options.userId);
|
|
283
291
|
} catch (err) {
|
|
@@ -12,8 +12,21 @@ import type { Logger } from "./logger.js";
|
|
|
12
12
|
import { LINK_CLICKED } from "./tracking-event-names.js";
|
|
13
13
|
|
|
14
14
|
interface EmailSendContext {
|
|
15
|
+
/**
|
|
16
|
+
* Display/attribution identity: the enrollment's key, else the send's
|
|
17
|
+
* recorded `user_id`, else the recipient address. Never re-ingest this as
|
|
18
|
+
* `userId` — use {@link subjectKey}, which is null for a bare-address send.
|
|
19
|
+
*/
|
|
15
20
|
userId: string;
|
|
16
21
|
userEmail: string;
|
|
22
|
+
/**
|
|
23
|
+
* The subject key the send was actually made for (enrollment key, else
|
|
24
|
+
* `email_sends.user_id`), or null for a bare-address send. Bus re-ingests key
|
|
25
|
+
* on this, so a raw send's address is offered as an EMAIL key, never as an
|
|
26
|
+
* external `userId` (which would fill a free `external_id` with the address
|
|
27
|
+
* and flip the contact's canonical key).
|
|
28
|
+
*/
|
|
29
|
+
subjectKey: string | null;
|
|
17
30
|
/**
|
|
18
31
|
* PRD 05 T6 — the send's owning contact (`email_sends.contact_id`, falling
|
|
19
32
|
* back to the enrollment's stamp). The denormalized `userId` string above is
|
|
@@ -54,6 +67,8 @@ export async function resolveEmailSendContext(
|
|
|
54
67
|
userEmail: journeyStates.userEmail,
|
|
55
68
|
journeyId: journeyStates.journeyId,
|
|
56
69
|
enrollmentContactId: journeyStates.contactId,
|
|
70
|
+
sendUserId: emailSends.userId,
|
|
71
|
+
sendUserEmail: emailSends.userEmail,
|
|
57
72
|
})
|
|
58
73
|
.from(emailSends)
|
|
59
74
|
.leftJoin(journeyStates, eq(emailSends.journeyStateId, journeyStates.id))
|
|
@@ -63,9 +78,11 @@ export async function resolveEmailSendContext(
|
|
|
63
78
|
const row = rows[0];
|
|
64
79
|
if (!row) return null;
|
|
65
80
|
|
|
81
|
+
const subjectKey = row.userId ?? row.sendUserId ?? null;
|
|
66
82
|
return {
|
|
67
|
-
userId:
|
|
68
|
-
userEmail: row.userEmail ?? row.toEmail,
|
|
83
|
+
userId: subjectKey ?? row.toEmail,
|
|
84
|
+
userEmail: row.userEmail ?? row.sendUserEmail ?? row.toEmail,
|
|
85
|
+
subjectKey,
|
|
69
86
|
contactId: row.sendContactId ?? row.enrollmentContactId ?? null,
|
|
70
87
|
templateKey: row.templateKey,
|
|
71
88
|
messageId: row.messageId,
|
|
@@ -207,7 +224,7 @@ export async function pushTrackingEvent(
|
|
|
207
224
|
logger,
|
|
208
225
|
event: {
|
|
209
226
|
event,
|
|
210
|
-
userId: ctx.
|
|
227
|
+
userId: ctx.subjectKey ?? undefined,
|
|
211
228
|
userEmail: ctx.userEmail,
|
|
212
229
|
// PRD 05 T6 — pin the send's owning contact so the tracking event
|
|
213
230
|
// resolves to the contact even when the frozen send-time key went stale.
|