The email gate

An optional page in front of a share link. A reader gives an address, gets a signed pass, and the artifact loads. Off by default — a deployment that does not configure it behaves exactly as before. The decision and its trade-offs are in ADR 0004; this page is how to run it.

What the reader sees

GET  /s/<token>            →  the gate: title, one email field, one consent line, one button
POST /s/<token>            →  stores the lead, sets the pass, 303 → /s/<token>
GET  /s/<token> + pass     →  the artifact, as before

The gate page is written by artifactkit, not by the artifact's author: inline CSS, system fonts, no script, no external asset. If scripting is off, the form still submits — it is a plain POST. The page is no-store, noindex, and refuses to be framed.

/v/<id> (staff views) and /api/* are never gated, gate on or off.

Enable it

import { createArtifactHandler } from '@artifactkitdev/core/http';
import { posthogTelemetry } from '@artifactkitdev/core/adapters/telemetry';

const handler = createArtifactHandler({
  deps,
  artifactsHost: env.ARTIFACTS_HOST,
  frameAncestors: [],
  gate: {
    enabled: true,
    leads: adapter.leads,              // the LeadStore port: memory, fs, or your own
    analytics: posthogTelemetry({ apiKey: env.POSTHOG_KEY }),  // optional but this is the lead list
    consent: 'We’ll email you about this artifact. No list-sharing.',
  },
});

gate.analytics is any object with capture({ name, distinctId, properties }) — the telemetry adapters already have that shape, so nothing needs wrapping.

optiondefaultmeaning
enabledfalsegates every share link on this deployment; staff views are never gated
leadsrequired when enableda LeadStore
analyticsnonewhere artifact.lead.captured goes; without it leads exist only in leads
consentthe built-in sentencethe line above the button
passTtlSeconds30 dayshow long one reader's pass lasts
limiterin-process, 5 / 10 min per reader and 50 / hour per artifacta RateLimiter

Where the leads are

Each accepted address is one row: { artifactId, email, version, capturedAt }. A repeat submission of the same address for the same artifact is ignored (record returns false) — a second visit is not a second lead — and no second event is emitted, so the count and the event stream agree.

The event is the durable list:

artifact.lead.captured   distinct_id = the address   properties = { artifact_id, version }

That event is published to gate.analytics only. It is not written to the artifact event log, is not returned by GET /api/artifacts/{id}/events, and is not delivered to webhook subscribers — because an address in that log is an address in an API response. If you want leads in a CRM, write a LeadStore adapter for the CRM; do not subscribe a webhook to the address.

The local store keeps rows for 400 days. Nothing deletes them on a timer — serverless has no timer you can trust — so run prune from whatever cron you already have:

const cutoff = new Date(Date.now() - 400 * 24 * 60 * 60 * 1000).toISOString();
const removed = await leads.prune(cutoff);
console.log(`pruned ${removed} leads older than ${cutoff}`);

To honour a deletion request, prune with that address's date or delete the row through your own adapter; the gate does not ship a mailing list and has no unsubscribe flow. Unsubscribing happens in whatever tool sends the mail, and that tool is the operator's.

The pass

__Host-akg=g1.<artifactId>.<exp>.<signature>; Path=/; Secure; HttpOnly; SameSite=Lax; Max-Age=2592000

While the gate is on, share responses are Cache-Control: private, no-store with Vary: Cookie, instead of the usual private, max-age=60. A gated artifact must not be replayed from a cache after the pass expires.

Rate limiting

The default is in-process and deliberately blunt: 5 attempts per 10 minutes per (artifact, reader address) and 50 per hour per artifact, 429 with Retry-After. Addresses are used as bucket keys in memory only — never stored, never logged, never sent anywhere — and the map is swept when it grows.

On more than one instance each instance counts separately, so the effective limit is instances × 5. That is fine for a bored script and not a defence against a botnet. To do better, pass a RateLimiter backed by KV or Redis:

gate: { enabled: true, leads, limiter: { check: (key, nowMs) => myBucket(key, nowMs) } }

Operating notes

What it does not do