Seedy Pea

seedypea

seedypea is the server package. It ships a small Fetch-standard edge helper and a CLI for topology config.

import { pea } from "seedypea";

The package is ESM and includes .d.ts types.

Exports

Export From Use
pea seedypea or seedypea/edge Create visitor cookie and edge-scoped Seedy Pea helpers.
InboxEventLog seedypea or seedypea/inbox In-memory event log for ops mailbox ingestion.
createInboxEventLog seedypea or seedypea/inbox Convenience constructor for InboxEventLog.
foldInboxEvents seedypea or seedypea/inbox Fold inbox events into a snapshot.

pea(request, env, options)

pea() accepts a standard Request, an optional environment object, and optional overrides. It returns { cookie, cooked }.

const sp = pea(request, env, {
  cookieName: "__seedypea",
  sameSite: "Lax",
  apiUrl: "https://app.seedy-pea.com"
});

Environment

Name Required For Description
SEEDYPEA_PROJECT_ID collect, serveProfile, forgetProfile Project id for write-key authenticated browser traffic.
SEEDYPEA_WRITE_KEY collect, serveProfile, forgetProfile Project write key.
SEEDYPEA_API_URL Optional Hosted API base URL. Defaults to https://app.seedy-pea.com for write-key routes.
SEEDYPEA_TOKEN profile, upgradeSSE Bearer token for signed profile routes.

Options

Option Default Description
apiUrl env or hosted default API base URL.
token SEEDYPEA_TOKEN Bearer token for signed profile reads and streams.
projectId SEEDYPEA_PROJECT_ID Project id override.
writeKey SEEDYPEA_WRITE_KEY Write key override.
cookieName __seedypea First-party visitor cookie name.
maxAge 31536000 Cookie lifetime in seconds.
sameSite Lax Cookie SameSite value.
domain unset Optional cookie domain.
alwaysSetCookie false Set the cookie on every response.
profileScriptRole profile data-role value for injected profile JSON.
streamPath /sp/profile/sse Default stream path for injectStream.
streamEventName seedypea:profile Browser event name for stream config.

cookie owns first-party visitor identity.

const { cookie } = pea(request, env);

cookie.id;
cookie.changed;
cookie.header();
cookie.apply(response);
cookie.clear(response);

cookie.apply(response) appends Set-Cookie when the visitor is new, or when alwaysSetCookie is true. cookie.clear(response) expires the cookie.

Cookies are Secure, HttpOnly, path-scoped to /, and SameSite=Lax by default.

cooked

cooked is scoped to the visitor id from the cookie.

Method Description
profile() Fetches a signed live profile using apiUrl and token.
injectProfile(html, profile?) Inserts an inert JSON profile script into HTML.
injectStream(html, streamPath?) Inserts inert stream config into HTML.
collect(request) Forwards an event body to POST /v1/events with the cookie anonymous id.
serveProfile(request) Proxies POST /v1/profile with the cookie anonymous id.
forgetProfile(request) Proxies POST /v1/profile/delete with the cookie anonymous id.
upgradeSSE(request) Proxies a signed profile stream request.

collect() also forwards capture hints from Cloudflare request metadata when present: country, device class, and browser family.

Edge Collector

import { pea } from "seedypea/edge";

export default {
  async fetch(request, env) {
    const url = new URL(request.url);
    const sp = pea(request, env);

    if (url.pathname === "/sp/events") {
      return sp.cooked.collect(request);
    }

    if (url.pathname === "/sp/profile") {
      return sp.cooked.serveProfile(request);
    }

    if (url.pathname === "/sp/profile/delete") {
      const upstream = await sp.cooked.forgetProfile(request);
      return sp.cookie.clear(upstream);
    }

    const response = await env.ASSETS.fetch(request);
    return sp.cookie.apply(response);
  }
};

Inbox Helpers

The inbox helpers model ops email as an event log.

import { createInboxEventLog } from "seedypea/inbox";

const inbox = createInboxEventLog();

const result = inbox.ingest({
  mailbox: "ops",
  provider: "gmail",
  provider_message_id: "abc123",
  from: "npm@example.com",
  subject: "Package published",
  snippet: "seedypea 0.0.3 was published"
});

result.accepted;
result.events;
result.state.alerts;

InboxEventLog deduplicates by mailbox:provider:provider_message_id, emits OpsMailReceived, and can generate alert events from trigger rules.