[data-reveal]{opacity:1!important;transform:none!important}
AntelopeJS DMS
DocumentationInter-module interface

Inter-module interface

What the Marketing interface lets other backend modules do, how its declarations and imports reuse the module's own rules, and how the interface package is released.

The Marketing module implements @antelopejs/interface-dms-marketing, declared in antelopeJs.implements. The interface lets other backend modules read the click heatmap and ship content as code. Extending shows the calls, and the consumer reference defines them.

Content from code follows the dashboard's rules

EnsureWebsite and EnsureFunnel (services/declared-website.ts and services/declared-funnel.ts) require an explicit tenant ID, as EnsurePageSnapshot and ImportAnalytics do. A missing, blank or padded ID rejects before any model access (services/declarations.ts). These four APIs have no tenant fallback.

Projects call them from a Hook.TENANT_BEING_PROVISIONED handler, which the DMS fires once per tenant, after DATABASE_INITIALIZED has settled. None of the calls waits for anything, because the provisioning hook runs after the module's own DATABASE_INITIALIZED handler has loaded the settings.

The declarations write once, through the same field and lifecycle rules as the dashboard. An ID that already exists is kept, nothing is written, and no hash is stored.

EnsurePageSnapshot (services/declared-snapshot.ts) stores a snapshot under the key that a capture of the same page and layout takes. The same function as for captures sanitizes it, and it is marked with its scroll root like a capture. A later capture replaces it, and a declaration never replaces a stored snapshot.

Imports replay through the collect pipeline

ImportAnalytics (services/analytics-import.ts) replays history through ingestPreparedBatch, the same function behind POST /collect, with a trusted clock.

A permanent marketing_imports row deduplicates the import ID and stores its chronology boundary. A reserved row per website serializes imports across instances. Its holder replaces the row's token every few seconds, so an instance that sees the token unchanged for 30 s of its own time takes the claim over, wherever the holder stopped and however long a live one takes. The replay commits one UTC day at a time. The day's events and sessions carry the import ID, its rollup is held in memory, and then the counters and a ledger entry (appliedImports) land in one write to the day row. A later call with the same ID takes back rows on days the ledger does not name and replays those days, so each day counts once after a failure or a crash. An import for an earlier window than one already applied rejects before replay. Imported batches bypass the session cache, so they see other instances' writes.

Why the heatmap read lives here

GetClickHeatmap has no consumer in this repository since the dms-api heatmap tab was removed. It stays because every /modules/ page is platform-owner-only by DMS design. The interface is therefore the only way for a project module to build a heatmap that tenants can see.

The heatmap used to live in the route detail of dms-api. That design was wrong in principle. The identifier dms-api can produce is a registered backend route (getRegisteredRoutes()), matched with a strict eq against visitor pathnames, so a location that carries :id never matches anything. Its default preview origin was also the DMS API itself, which framed a JSON endpoint. dms-api no longer uses the Marketing interface.

The interface is released before the module

The interface is a separate workspace package at packages/interface-dms-marketing, beside the module at packages/dms-marketing. Each package keeps its own lockfile, and the module's lockfile links the interface from the workspace sibling.

The module names the interface as workspace:^, so pnpm pack writes ^<interface version in the tree>, which stops below the next interface minor while the interface is below 1.0.0. A breaking interface minor then never reaches a module that does not implement it. Each package has its own release workflow, dispatched by hand. The module's workflow refuses to run until the interface version in the tree is on npm, so the interface is always released first. The compatibility table in the package README lists the versions that work together.