@marktiderman/genesis-widgets-core
v0.1.0
Published
Genesis Widget Platform shared core — boot contract types, boot client, identity, and per-widget intake clients. Zero-dependency, framework-agnostic. Part of the Genesis framework (PRD-09).
Readme
@marktiderman/genesis-widgets-core
Shared core for the Genesis Widget Platform (PRD-09) — the wire contract plus a zero-dependency, isomorphic client for the two edge functions the platform exposes. Imported by the CDN loader (@marktiderman/genesis-widgets-web) and every widget package so the boot handshake, identity, and intake payloads have exactly one definition.
What's in here
contract.ts—BootConfig,WidgetType,IdentityMode,ThemeTokens, the feedback payloads,WIDGET_HEADERS, andCONTRACT_VERSION. Additive-only; old embeds must tolerate unknown fields/widget types.client.ts—fetchBoot,submitFeedback,listReports, andWidgetError. Uses globalfetch(browser / Deno / Node ≥18);fetchImplis injectable for tests.identity.ts—getOrCreateDeviceId(anonymous) andidentityHeaders(anonymous device id vs. thesignedshort-lived JWT).
Usage
import { fetchBoot, submitFeedback, getOrCreateDeviceId } from "@marktiderman/genesis-widgets-core";
const cfg = {
endpoint: "https://<ref>.supabase.co",
publishableKey: "pk_live_…",
getIdentity: () => ({ deviceId: getOrCreateDeviceId() }),
};
const boot = await fetchBoot(cfg); // → BootConfig (public projection)
await submitFeedback(cfg, { body: "found a bug", type: "bug" });Identity
signed projects use a short-lived JWT (HS256, exp) minted by the client's trusted backend with the project secret key — the browser host page receives only the resulting token and never the secret (exposing it would let any visitor forge identities). The whole claim set is signed, verified constant-time at the edge. This supersedes the deprecated Intercom-style raw-HMAC user_hash. Anonymous projects use a persisted device id.
Zero runtime dependencies by design: this package is bundled into the CDN loader, which has a tight size budget.
