@hogsend/engine 0.66.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/container.ts +77 -0
- package/src/env.ts +30 -0
- package/src/index.ts +78 -0
- package/src/journeys/journey-log.ts +25 -8
- package/src/lib/contacts.ts +117 -1
- package/src/lib/email-service-types.ts +10 -0
- package/src/lib/ingestion.ts +91 -19
- package/src/lib/links.ts +94 -11
- 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 +150 -37
- package/src/lib/referral-intent.ts +723 -0
- package/src/lib/referral-link.ts +200 -0
- package/src/lib/referral-registry.ts +83 -0
- package/src/lib/referral-report.ts +739 -0
- package/src/lib/referral-runtime.ts +49 -0
- package/src/lib/referrals-no-emit.test.ts +109 -0
- package/src/lib/referrals.ts +712 -0
- 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/lib/webhook-signing.ts +10 -0
- 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 +153 -0
- package/src/routes/admin/index.ts +2 -0
- package/src/routes/admin/links.ts +14 -5
- package/src/routes/admin/referrals.ts +565 -0
- package/src/routes/admin/targeting.ts +6 -1
- package/src/routes/admin/webhooks.ts +4 -0
- package/src/routes/contacts/index.ts +78 -0
- package/src/routes/index.ts +104 -22
- package/src/routes/referrals/index.ts +41 -0
- package/src/routes/referrals/me.ts +123 -0
- package/src/routes/referrals/report.ts +285 -0
- package/src/routes/referrals/shared.ts +34 -0
- package/src/routes/referrals/touch.ts +313 -0
- package/src/routes/tracking/arrive.ts +90 -0
- package/src/routes/tracking/click-pipeline.ts +8 -0
- 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
|
@@ -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.
|
|
@@ -118,6 +118,16 @@ export const WEBHOOK_EVENT_TYPES = [
|
|
|
118
118
|
"account.linked",
|
|
119
119
|
"account.unlinked",
|
|
120
120
|
"account.link_failed",
|
|
121
|
+
// Referrals (`defineReferral`, PRD 05). Emitted from the referral INTENT
|
|
122
|
+
// layer only (`lib/referral-intent.ts`), never from the store, which never
|
|
123
|
+
// emits. `level` on `referral.tree_converted` is a FACT on the event, not
|
|
124
|
+
// program config: depth and weights stay report-time parameters.
|
|
125
|
+
"referral.touched",
|
|
126
|
+
"referral.bound",
|
|
127
|
+
"referral.qualified",
|
|
128
|
+
"referral.converted",
|
|
129
|
+
"referral.tree_converted",
|
|
130
|
+
"referral.rejected",
|
|
121
131
|
// Weekly impact digest (impact experiments D5). Self-referential: the
|
|
122
132
|
// cron watermarks off its own delivery rows.
|
|
123
133
|
"impact.digest",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { apiKeys } from "@hogsend/db";
|
|
1
|
+
import { apiKeys, type Database } from "@hogsend/db";
|
|
2
2
|
import { and, eq, isNull } from "drizzle-orm";
|
|
3
3
|
import { createMiddleware } from "hono/factory";
|
|
4
4
|
import type { AppEnv } from "../app.js";
|
|
@@ -52,16 +52,75 @@ export function hasScope(keyScopes: string[], required: string): boolean {
|
|
|
52
52
|
return maxRank >= requiredRank;
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
55
|
+
/** An `api_keys` row as both auth guards need it, cached per process. */
|
|
56
|
+
export interface CachedApiKey extends ApiKeyContext {
|
|
57
|
+
expiresAt: Date | null;
|
|
58
|
+
lastUsedAt: Date | null;
|
|
59
|
+
allowedOrigins: string[] | null;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const KEY_CACHE = new Map<string, { data: CachedApiKey; cachedAt: number }>();
|
|
62
63
|
const CACHE_TTL = 60_000;
|
|
63
64
|
const LAST_USED_DEBOUNCE = 5 * 60_000;
|
|
64
65
|
|
|
66
|
+
/**
|
|
67
|
+
* Drop a key's cached auth entry so THIS process re-reads the row on the key's
|
|
68
|
+
* next request. Called after a revoke or a rotation changes the row. The cache
|
|
69
|
+
* is per process: other API instances keep their entry until its TTL (60s)
|
|
70
|
+
* runs out, which is the documented revocation lag.
|
|
71
|
+
*/
|
|
72
|
+
export function evictCachedApiKey(keyHash: string): void {
|
|
73
|
+
KEY_CACHE.delete(keyHash);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Read a live (unrevoked) key by hash through the 60s per-process cache, for
|
|
78
|
+
* secret and publishable keys alike. Misses are not cached, so a key minted a
|
|
79
|
+
* moment ago works on its first request. Expiry is the caller's check (it is
|
|
80
|
+
* re-evaluated on every request, cached or not). On a cache fill, `lastUsedAt`
|
|
81
|
+
* is bumped fire-and-forget at most once per five minutes.
|
|
82
|
+
*/
|
|
83
|
+
export async function loadApiKey(
|
|
84
|
+
db: Database,
|
|
85
|
+
keyHash: string,
|
|
86
|
+
): Promise<CachedApiKey | null> {
|
|
87
|
+
const cached = KEY_CACHE.get(keyHash);
|
|
88
|
+
if (cached && Date.now() - cached.cachedAt < CACHE_TTL) {
|
|
89
|
+
return cached.data;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const rows = await db
|
|
93
|
+
.select()
|
|
94
|
+
.from(apiKeys)
|
|
95
|
+
.where(and(eq(apiKeys.keyHash, keyHash), isNull(apiKeys.revokedAt)))
|
|
96
|
+
.limit(1);
|
|
97
|
+
const key = rows[0];
|
|
98
|
+
if (!key) return null;
|
|
99
|
+
|
|
100
|
+
const data: CachedApiKey = {
|
|
101
|
+
id: key.id,
|
|
102
|
+
name: key.name,
|
|
103
|
+
scopes: key.scopes as string[],
|
|
104
|
+
expiresAt: key.expiresAt,
|
|
105
|
+
lastUsedAt: key.lastUsedAt,
|
|
106
|
+
allowedOrigins: key.allowedOrigins ?? null,
|
|
107
|
+
};
|
|
108
|
+
KEY_CACHE.set(keyHash, { data, cachedAt: Date.now() });
|
|
109
|
+
|
|
110
|
+
if (
|
|
111
|
+
!key.lastUsedAt ||
|
|
112
|
+
Date.now() - key.lastUsedAt.getTime() > LAST_USED_DEBOUNCE
|
|
113
|
+
) {
|
|
114
|
+
db.update(apiKeys)
|
|
115
|
+
.set({ lastUsedAt: new Date() })
|
|
116
|
+
.where(eq(apiKeys.id, key.id))
|
|
117
|
+
.then(() => {})
|
|
118
|
+
.catch(() => {});
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return data;
|
|
122
|
+
}
|
|
123
|
+
|
|
65
124
|
export const requireApiKey = createMiddleware<AppEnv>(async (c, next) => {
|
|
66
125
|
const { env, db } = c.get("container");
|
|
67
126
|
|
|
@@ -81,65 +140,15 @@ export const requireApiKey = createMiddleware<AppEnv>(async (c, next) => {
|
|
|
81
140
|
return next();
|
|
82
141
|
}
|
|
83
142
|
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
const cached = KEY_CACHE.get(keyHash);
|
|
87
|
-
if (cached && Date.now() - cached.cachedAt < CACHE_TTL) {
|
|
88
|
-
if (cached.data.expiresAt && cached.data.expiresAt < new Date()) {
|
|
89
|
-
return c.json({ error: "API key expired" }, 401);
|
|
90
|
-
}
|
|
91
|
-
c.set("apiKey", {
|
|
92
|
-
id: cached.data.id,
|
|
93
|
-
name: cached.data.name,
|
|
94
|
-
scopes: cached.data.scopes,
|
|
95
|
-
});
|
|
96
|
-
return next();
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
const rows = await db
|
|
100
|
-
.select()
|
|
101
|
-
.from(apiKeys)
|
|
102
|
-
.where(and(eq(apiKeys.keyHash, keyHash), isNull(apiKeys.revokedAt)))
|
|
103
|
-
.limit(1);
|
|
104
|
-
|
|
105
|
-
const key = rows[0];
|
|
143
|
+
const key = await loadApiKey(db, hashApiKey(provided));
|
|
106
144
|
if (!key) {
|
|
107
145
|
return c.json({ error: "Unauthorized" }, 401);
|
|
108
146
|
}
|
|
109
|
-
|
|
110
147
|
if (key.expiresAt && key.expiresAt < new Date()) {
|
|
111
148
|
return c.json({ error: "API key expired" }, 401);
|
|
112
149
|
}
|
|
113
150
|
|
|
114
|
-
|
|
115
|
-
id: key.id,
|
|
116
|
-
name: key.name,
|
|
117
|
-
scopes: key.scopes as string[],
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
c.set("apiKey", keyContext);
|
|
121
|
-
|
|
122
|
-
KEY_CACHE.set(keyHash, {
|
|
123
|
-
data: {
|
|
124
|
-
...keyContext,
|
|
125
|
-
expiresAt: key.expiresAt,
|
|
126
|
-
lastUsedAt: key.lastUsedAt,
|
|
127
|
-
},
|
|
128
|
-
cachedAt: Date.now(),
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
const shouldUpdateLastUsed =
|
|
132
|
-
!key.lastUsedAt ||
|
|
133
|
-
Date.now() - key.lastUsedAt.getTime() > LAST_USED_DEBOUNCE;
|
|
134
|
-
|
|
135
|
-
if (shouldUpdateLastUsed) {
|
|
136
|
-
db.update(apiKeys)
|
|
137
|
-
.set({ lastUsedAt: new Date() })
|
|
138
|
-
.where(eq(apiKeys.id, key.id))
|
|
139
|
-
.then(() => {})
|
|
140
|
-
.catch(() => {});
|
|
141
|
-
}
|
|
142
|
-
|
|
151
|
+
c.set("apiKey", { id: key.id, name: key.name, scopes: key.scopes });
|
|
143
152
|
return next();
|
|
144
153
|
});
|
|
145
154
|
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import { apiKeys } from "@hogsend/db";
|
|
2
|
-
import { and, eq, isNull } from "drizzle-orm";
|
|
3
1
|
import { createMiddleware } from "hono/factory";
|
|
4
2
|
import type { AppEnv } from "../app.js";
|
|
5
3
|
import { hashApiKey } from "../lib/api-key-hash.js";
|
|
6
|
-
import { hasScope, requireApiKey } from "./api-key.js";
|
|
4
|
+
import { hasScope, loadApiKey, requireApiKey } from "./api-key.js";
|
|
7
5
|
|
|
8
6
|
/**
|
|
9
7
|
* Data-plane guard for the BROWSER-REACHABLE subset of `/v1` (POST /events, the
|
|
@@ -17,8 +15,9 @@ import { hasScope, requireApiKey } from "./api-key.js";
|
|
|
17
15
|
* byte-for-byte behaviorally identical to the existing
|
|
18
16
|
* `requireApiKey` → `requireScope("ingest")` stack.
|
|
19
17
|
*
|
|
20
|
-
* - PUBLISHABLE key (`pk_` bearer):
|
|
21
|
-
*
|
|
18
|
+
* - PUBLISHABLE key (`pk_` bearer): read through the same 60s key cache
|
|
19
|
+
* (`loadApiKey`, which carries `allowed_origins`) with the same debounced
|
|
20
|
+
* `lastUsedAt` bump as secret keys. Requires scope `ingest-public`
|
|
22
21
|
* and REJECTS any pk_ token that somehow also carries `ingest`/`full-admin`
|
|
23
22
|
* (defence in depth — a prefix never implies privilege). Enforces the
|
|
24
23
|
* per-key Origin allowlist FAIL-CLOSED (no/empty allowlist ⇒ reject; Origin
|
|
@@ -61,17 +60,13 @@ export const requirePublishableOrIngest = createMiddleware<AppEnv>(
|
|
|
61
60
|
return next();
|
|
62
61
|
}
|
|
63
62
|
|
|
64
|
-
// PUBLISHABLE path: pk_ token.
|
|
65
|
-
//
|
|
66
|
-
//
|
|
63
|
+
// PUBLISHABLE path: pk_ token. Same cached read as the secret path (a
|
|
64
|
+
// browser key is hit on every page view, so an uncached lookup plus an
|
|
65
|
+
// undebounced `lastUsedAt` write was two statements per request). Revoking
|
|
66
|
+
// or rotating evicts it here at once; other instances pick it up within
|
|
67
|
+
// the 60s TTL, the same lag secret keys have.
|
|
67
68
|
const { db } = c.get("container");
|
|
68
|
-
const
|
|
69
|
-
const rows = await db
|
|
70
|
-
.select()
|
|
71
|
-
.from(apiKeys)
|
|
72
|
-
.where(and(eq(apiKeys.keyHash, keyHash), isNull(apiKeys.revokedAt)))
|
|
73
|
-
.limit(1);
|
|
74
|
-
const key = rows[0];
|
|
69
|
+
const key = await loadApiKey(db, hashApiKey(provided));
|
|
75
70
|
if (!key) {
|
|
76
71
|
return c.json({ error: "Unauthorized" }, 401);
|
|
77
72
|
}
|
|
@@ -79,7 +74,7 @@ export const requirePublishableOrIngest = createMiddleware<AppEnv>(
|
|
|
79
74
|
return c.json({ error: "API key expired" }, 401);
|
|
80
75
|
}
|
|
81
76
|
|
|
82
|
-
const scopes = key.scopes
|
|
77
|
+
const scopes = key.scopes;
|
|
83
78
|
// A pk_ key MUST be exactly a publishable key. Reject a pk_-prefixed token
|
|
84
79
|
// that somehow carries `ingest`/`full-admin` — the mint route forces
|
|
85
80
|
// `["ingest-public"]`, but never trust the prefix alone to imply privilege.
|
|
@@ -107,13 +102,6 @@ export const requirePublishableOrIngest = createMiddleware<AppEnv>(
|
|
|
107
102
|
});
|
|
108
103
|
c.set("publishable", true);
|
|
109
104
|
|
|
110
|
-
// Best-effort last-used bump (mirror requireApiKey's fire-and-forget).
|
|
111
|
-
db.update(apiKeys)
|
|
112
|
-
.set({ lastUsedAt: new Date() })
|
|
113
|
-
.where(eq(apiKeys.id, key.id))
|
|
114
|
-
.then(() => {})
|
|
115
|
-
.catch(() => {});
|
|
116
|
-
|
|
117
105
|
return next();
|
|
118
106
|
},
|
|
119
107
|
);
|
|
@@ -8,6 +8,22 @@ const DEFAULT_MAX_REQUESTS = 100;
|
|
|
8
8
|
const DEFAULT_PREFIX = "ratelimit";
|
|
9
9
|
const MAX_KEYS = 10_000;
|
|
10
10
|
|
|
11
|
+
/**
|
|
12
|
+
* Every header `createRateLimit` can set. `app.ts` passes this list to the CORS
|
|
13
|
+
* `exposeHeaders` option: none of these is a CORS-safelisted response header,
|
|
14
|
+
* so without it a browser (`@hogsend/js` on a pk_ key) could not read them —
|
|
15
|
+
* including `Retry-After`, which the SDK maps to `RateLimitError.retryAfter`.
|
|
16
|
+
*/
|
|
17
|
+
export const RATE_LIMIT_HEADERS = [
|
|
18
|
+
"RateLimit-Limit",
|
|
19
|
+
"RateLimit-Remaining",
|
|
20
|
+
"RateLimit-Reset",
|
|
21
|
+
"RateLimit-Policy",
|
|
22
|
+
"X-RateLimit-Limit",
|
|
23
|
+
"X-RateLimit-Remaining",
|
|
24
|
+
"Retry-After",
|
|
25
|
+
] as const;
|
|
26
|
+
|
|
11
27
|
export interface RateLimitOptions {
|
|
12
28
|
windowMs?: number;
|
|
13
29
|
max?: number;
|
|
@@ -46,6 +62,52 @@ export function clientIpKey(c: Context<AppEnv>): string {
|
|
|
46
62
|
return `ip:${clientIp(c)}`;
|
|
47
63
|
}
|
|
48
64
|
|
|
65
|
+
/**
|
|
66
|
+
* Bucket key for the browser-reachable ingest surface (the routes behind
|
|
67
|
+
* `requirePublishableOrIngest`). Runs AFTER that guard, so `apiKey` is set.
|
|
68
|
+
*
|
|
69
|
+
* - Secret key: one bucket per key. A secret key is one server integration.
|
|
70
|
+
* - Publishable (pk_) key: one bucket per key PER CLIENT IP. A pk_ key is
|
|
71
|
+
* public and shared by every visitor of the site, so a per-key bucket
|
|
72
|
+
* would 429 the whole site once its aggregate traffic crossed the limit,
|
|
73
|
+
* and would let one client holding the (public) key exhaust everyone's
|
|
74
|
+
* budget.
|
|
75
|
+
* - No resolved key (not reachable behind the guard): client IP, so a
|
|
76
|
+
* misordered mount still never collapses onto one shared bucket.
|
|
77
|
+
*/
|
|
78
|
+
export function ingestRateLimitKey(c: Context<AppEnv>): string {
|
|
79
|
+
const apiKey = c.get("apiKey");
|
|
80
|
+
if (!apiKey) return clientIpKey(c);
|
|
81
|
+
if (c.get("publishable")) return `pk:${apiKey.id}:${clientIpKey(c)}`;
|
|
82
|
+
return `key:${apiKey.id}`;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* When the next quota unit frees, in ms epoch, for a sliding log.
|
|
87
|
+
*
|
|
88
|
+
* `oldest` is the oldest entry still in the window and `pivot` the max-th
|
|
89
|
+
* newest entry (counting the current request), present only once the log holds
|
|
90
|
+
* `max` or more entries. With room left, the next unit frees when the oldest
|
|
91
|
+
* entry ages out. With none left, the next request is accepted only once the
|
|
92
|
+
* pivot ages out: every entry after it fits under `max`. Rejected requests are
|
|
93
|
+
* logged too, which is why the pivot and not the oldest entry decides.
|
|
94
|
+
*/
|
|
95
|
+
function nextSlotAt(
|
|
96
|
+
windowMs: number,
|
|
97
|
+
now: number,
|
|
98
|
+
oldest: number | undefined,
|
|
99
|
+
pivot: number | undefined,
|
|
100
|
+
): number {
|
|
101
|
+
return (pivot ?? oldest ?? now) + windowMs;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** Parse the `[member, score]` reply of `ZRANGE … WITHSCORES` for one rank. */
|
|
105
|
+
function scoreOf(reply: unknown): number | undefined {
|
|
106
|
+
if (!Array.isArray(reply) || reply.length < 2) return undefined;
|
|
107
|
+
const score = Number(reply[1]);
|
|
108
|
+
return Number.isFinite(score) ? score : undefined;
|
|
109
|
+
}
|
|
110
|
+
|
|
49
111
|
/**
|
|
50
112
|
* Build a sliding-window rate-limit middleware.
|
|
51
113
|
*
|
|
@@ -53,20 +115,42 @@ export function clientIpKey(c: Context<AppEnv>): string {
|
|
|
53
115
|
* and a distinct Redis key namespace, so two middlewares with different
|
|
54
116
|
* prefixes (e.g. "ratelimit" vs "ratelimit:emails") never share a budget —
|
|
55
117
|
* an email send must not consume the contact-upsert sliding window.
|
|
118
|
+
*
|
|
119
|
+
* Headers, on every limited response (allowed or 429):
|
|
120
|
+
* - `RateLimit-Limit` / `RateLimit-Remaining` / `RateLimit-Reset` /
|
|
121
|
+
* `RateLimit-Policy` (IETF draft-ietf-httpapi-ratelimit-headers, the
|
|
122
|
+
* separate-header form). `RateLimit-Reset` is the seconds until the window
|
|
123
|
+
* frees the next unit; `RateLimit-Policy` is `<max>;w=<window seconds>`.
|
|
124
|
+
* - `X-RateLimit-Limit` / `X-RateLimit-Remaining`, kept for existing readers.
|
|
125
|
+
* - `Retry-After` (seconds) on a 429 only: when the next request is accepted.
|
|
126
|
+
*
|
|
127
|
+
* An instance counts a request at most ONCE, however many matching `use`
|
|
128
|
+
* registrations reach it. Hono runs every matching `use`, and a `/<prefix>/*`
|
|
129
|
+
* pattern also matches the bare `/<prefix>`, so the same instance mounted on
|
|
130
|
+
* overlapping patterns would otherwise log two entries per request and halve
|
|
131
|
+
* the effective budget.
|
|
56
132
|
*/
|
|
57
133
|
export function createRateLimit(opts: RateLimitOptions = {}) {
|
|
58
134
|
const windowMs = opts.windowMs ?? DEFAULT_WINDOW_MS;
|
|
59
135
|
const max = opts.max ?? DEFAULT_MAX_REQUESTS;
|
|
60
136
|
const prefix = opts.prefix ?? DEFAULT_PREFIX;
|
|
61
137
|
const disableInTest = opts.disableInTest ?? true;
|
|
138
|
+
const windowSeconds = Math.ceil(windowMs / 1000);
|
|
139
|
+
const policy = `${max};w=${windowSeconds}`;
|
|
62
140
|
|
|
63
141
|
// Per-instance memory store so prefixes stay budget-isolated in the
|
|
64
142
|
// Redis-less fallback path too.
|
|
65
143
|
const memoryStore = new Map<string, number[]>();
|
|
66
144
|
let cleanupCounter = 0;
|
|
145
|
+
// Requests this instance has already counted (see the doc comment above).
|
|
146
|
+
// Keyed on the raw Request, which is the same object for every middleware a
|
|
147
|
+
// request passes through; entries go with the request.
|
|
148
|
+
const counted = new WeakSet<Request>();
|
|
67
149
|
|
|
68
150
|
return createMiddleware<AppEnv>(async (c, next) => {
|
|
69
151
|
if (disableInTest && process.env.NODE_ENV === "test") return next();
|
|
152
|
+
if (counted.has(c.req.raw)) return next();
|
|
153
|
+
counted.add(c.req.raw);
|
|
70
154
|
|
|
71
155
|
const keyId = opts.keyFn
|
|
72
156
|
? opts.keyFn(c)
|
|
@@ -74,6 +158,8 @@ export function createRateLimit(opts: RateLimitOptions = {}) {
|
|
|
74
158
|
const now = Date.now();
|
|
75
159
|
|
|
76
160
|
let count: number;
|
|
161
|
+
let oldest: number | undefined;
|
|
162
|
+
let pivot: number | undefined;
|
|
77
163
|
|
|
78
164
|
try {
|
|
79
165
|
const redis = getRedis();
|
|
@@ -83,10 +169,16 @@ export function createRateLimit(opts: RateLimitOptions = {}) {
|
|
|
83
169
|
pipeline.zremrangebyscore(windowKey, 0, now - windowMs);
|
|
84
170
|
pipeline.zcard(windowKey);
|
|
85
171
|
pipeline.zadd(windowKey, now, `${now}:${Math.random()}`);
|
|
86
|
-
pipeline.expire(windowKey,
|
|
172
|
+
pipeline.expire(windowKey, windowSeconds);
|
|
173
|
+
// Two O(log n) rank reads for RateLimit-Reset / Retry-After: the
|
|
174
|
+
// oldest entry, and the max-th newest (empty while under `max`).
|
|
175
|
+
pipeline.zrange(windowKey, 0, 0, "WITHSCORES");
|
|
176
|
+
pipeline.zrange(windowKey, -max, -max, "WITHSCORES");
|
|
87
177
|
|
|
88
178
|
const results = await pipeline.exec();
|
|
89
179
|
count = (results?.[1]?.[1] as number) ?? 0;
|
|
180
|
+
oldest = scoreOf(results?.[4]?.[1]);
|
|
181
|
+
pivot = scoreOf(results?.[5]?.[1]);
|
|
90
182
|
} else {
|
|
91
183
|
throw new Error("No Redis");
|
|
92
184
|
}
|
|
@@ -97,6 +189,8 @@ export function createRateLimit(opts: RateLimitOptions = {}) {
|
|
|
97
189
|
valid.push(now);
|
|
98
190
|
memoryStore.set(keyId, valid);
|
|
99
191
|
count = valid.length - 1;
|
|
192
|
+
oldest = valid[0];
|
|
193
|
+
pivot = valid.length >= max ? valid[valid.length - max] : undefined;
|
|
100
194
|
|
|
101
195
|
if (++cleanupCounter % 100 === 0 && memoryStore.size > MAX_KEYS) {
|
|
102
196
|
const sweepCutoff = now - windowMs;
|
|
@@ -108,12 +202,22 @@ export function createRateLimit(opts: RateLimitOptions = {}) {
|
|
|
108
202
|
}
|
|
109
203
|
}
|
|
110
204
|
|
|
205
|
+
const remaining = Math.max(0, max - count - 1);
|
|
206
|
+
const resetSeconds = Math.max(
|
|
207
|
+
1,
|
|
208
|
+
Math.ceil((nextSlotAt(windowMs, now, oldest, pivot) - now) / 1000),
|
|
209
|
+
);
|
|
210
|
+
|
|
211
|
+
c.header("RateLimit-Limit", String(max));
|
|
212
|
+
c.header("RateLimit-Remaining", String(remaining));
|
|
213
|
+
c.header("RateLimit-Reset", String(resetSeconds));
|
|
214
|
+
c.header("RateLimit-Policy", policy);
|
|
111
215
|
c.header("X-RateLimit-Limit", String(max));
|
|
112
|
-
c.header("X-RateLimit-Remaining", String(
|
|
216
|
+
c.header("X-RateLimit-Remaining", String(remaining));
|
|
113
217
|
|
|
114
218
|
if (count >= max) {
|
|
115
219
|
// SDKs map Retry-After to RateLimitError.retryAfter (seconds).
|
|
116
|
-
c.header("Retry-After", String(
|
|
220
|
+
c.header("Retry-After", String(resetSeconds));
|
|
117
221
|
return c.json({ error: "Rate limit exceeded" }, 429);
|
|
118
222
|
}
|
|
119
223
|
|
|
@@ -122,3 +226,61 @@ export function createRateLimit(opts: RateLimitOptions = {}) {
|
|
|
122
226
|
}
|
|
123
227
|
|
|
124
228
|
export const rateLimit = createRateLimit();
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* Data-plane budget defaults. `env.ts` declares the matching variables as
|
|
232
|
+
* optional so these stay the one place the numbers live.
|
|
233
|
+
*
|
|
234
|
+
* - Secret key on the ingest routes: 3000/min (50 req/s sustained). A secret
|
|
235
|
+
* key is usually one backend forwarding every user's events, and there is no
|
|
236
|
+
* batch event endpoint, so the budget has to cover a busy production app; it
|
|
237
|
+
* still stops a runaway loop well before it saturates an API instance.
|
|
238
|
+
* - Publishable key on the ingest routes: 1000/min per client IP. A browser on
|
|
239
|
+
* `@hogsend/js` makes a few requests a minute (one per captured event, plus a
|
|
240
|
+
* feed poll every 12s), so this leaves room for many visitors behind one
|
|
241
|
+
* office or carrier NAT while capping a single client that holds the public
|
|
242
|
+
* key.
|
|
243
|
+
* - `/v1/emails`: 30/min per key (unchanged). A loop sending more than that is
|
|
244
|
+
* almost certainly a runaway.
|
|
245
|
+
*/
|
|
246
|
+
export const DEFAULT_INGEST_RATE_LIMIT_MAX = 3000;
|
|
247
|
+
export const DEFAULT_INGEST_PUBLIC_RATE_LIMIT_MAX = 1000;
|
|
248
|
+
export const DEFAULT_INGEST_RATE_LIMIT_WINDOW_MS = 60_000;
|
|
249
|
+
export const DEFAULT_EMAIL_RATE_LIMIT_MAX = 30;
|
|
250
|
+
|
|
251
|
+
export interface IngestRateLimitOptions {
|
|
252
|
+
/** Requests per window per secret key. */
|
|
253
|
+
max?: number;
|
|
254
|
+
/** Requests per window per publishable key per client IP. */
|
|
255
|
+
publicMax?: number;
|
|
256
|
+
windowMs?: number;
|
|
257
|
+
disableInTest?: boolean;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* The rate limit for the browser-reachable ingest routes. Two isolated budgets
|
|
262
|
+
* (own prefixes, so neither shares a window with `/v1/emails` or the admin
|
|
263
|
+
* plane), picked by the key class `requirePublishableOrIngest` resolved. Mount
|
|
264
|
+
* it AFTER that guard: the bucket key and the budget both read what the guard
|
|
265
|
+
* set (`apiKey`, `publishable`).
|
|
266
|
+
*/
|
|
267
|
+
export function createIngestRateLimit(opts: IngestRateLimitOptions = {}) {
|
|
268
|
+
const windowMs = opts.windowMs ?? DEFAULT_INGEST_RATE_LIMIT_WINDOW_MS;
|
|
269
|
+
const secret = createRateLimit({
|
|
270
|
+
prefix: "ratelimit:ingest",
|
|
271
|
+
max: opts.max ?? DEFAULT_INGEST_RATE_LIMIT_MAX,
|
|
272
|
+
windowMs,
|
|
273
|
+
keyFn: ingestRateLimitKey,
|
|
274
|
+
disableInTest: opts.disableInTest,
|
|
275
|
+
});
|
|
276
|
+
const publishable = createRateLimit({
|
|
277
|
+
prefix: "ratelimit:ingest-public",
|
|
278
|
+
max: opts.publicMax ?? DEFAULT_INGEST_PUBLIC_RATE_LIMIT_MAX,
|
|
279
|
+
windowMs,
|
|
280
|
+
keyFn: ingestRateLimitKey,
|
|
281
|
+
disableInTest: opts.disableInTest,
|
|
282
|
+
});
|
|
283
|
+
return createMiddleware<AppEnv>((c, next) =>
|
|
284
|
+
c.get("publishable") ? publishable(c, next) : secret(c, next),
|
|
285
|
+
);
|
|
286
|
+
}
|