Skip to content

Build and serve

Build

npx initiative-plugin build              # writes manifest.json
npx initiative-plugin build --check      # CI: fails if manifest.json is stale

build reads src/plugin.ts (--plugin <file> for another), bundles the widgets, checks the result with validateManifest, and writes manifest.json. Commit it and ship it with the plug-in: the server serves it, and refuses to start if it no longer matches the definition.

Serve

// src/main.ts
import plugin from "./plugin.js";
import { createPlugin, serve } from "initiative-plugin-sdk/server";

serve(createPlugin(plugin));

createPlugin(plugin, options) returns a web-standard (Request) => Promise<Response> handler, so the same plug-in runs on any runtime, or behind any framework, that speaks Request and Response. serve runs it on node:http, on PORT (default 8080).

Route
GET /healthz, GET /readyz Answer once the process is up.
GET /.well-known/jwks.json The plug-in's public key.
GET /.well-known/initiative-plugin.json The manifest document: the manifest with the plug-in's id, uid and name.
GET, POST /v1/endpoints What the plug-in declares; Initiative's endpoint calls, on a context token.
POST /v1/hooks/{name} Initiative's hook calls, on a lifecycle token for that hook.
a page's path The page's handler.

Every call's token is an EdDSA JWT, verified against the deployment's JWKS. The key set is cached for five minutes, and fetched again for a key it does not know or a signature none of its keys verifies, but never sooner than 30 seconds after the last fetch; a fetch that fails keeps the set already held. A token naming no key, from a deployment configured without a key id, is checked against every key published. Only the set's Ed25519 keys are read, and a token signed any other way (RS256, ES256, none) is refused. Each kind carries its own typ (initiative-context+jwt on endpoint and hook calls, initiative-handoff+jwt on a page handoff), and each path takes only its own kind. exp and iat are allowed 30 seconds of clock skew. Bodies are capped at 5 MiB. A refusal answers { "error": code, "detail": sentence }.

Each token is taken once. Initiative signs a fresh token for every call, every retry and every page it opens, so the server records each token's jti as it takes it, until five minutes past its expiry, and refuses one it has seen. The record is this process's own by default; a plug-in run as more than one replica gives them one they share as spentTokens, any object with spend(jti, until) that records a jti and answers whether it was new, in one step, such as a table with a unique jti.

Option Default
baseUrl INITIATIVE_BASE_URL Initiative's API as the plug-in reaches it, such as http://initiative:8173/api/v1.
publicBaseUrl INITIATIVE_PUBLIC_BASE_URL, else baseUrl Initiative's API at its public address, such as https://initiative.example.com/api/v1, when baseUrl is another. Initiative takes the plug-in's assertions only when they are addressed to its public token endpoint, and Sign in with Initiative sends people there. In a listing's runtime, map it from the app_api_public fact.
spentTokens this process's own Where the tokens the plug-in has taken are recorded. Give replicas one they share.
key INITIATIVE_PLUGIN_PRIVATE_KEY, INITIATIVE_PLUGIN_KEY_ID The plug-in's key: PEM, PEM with literal \n, or base64 of the PEM, and the kid it is registered under (default: its RFC 7638 thumbprint).
dataDir INITIATIVE_PLUGIN_DATA_DIR, else data With no key given, one is generated on first start and kept here as plugin-key.pem. Replicas must share it, or be given the same key: Initiative reads the plug-in's keys from whichever replica answers.
manifest manifest.json The built manifest.
context Handed to every handler as context.
fetch, now, log, env For tests and other runtimes.

The plug-in's key. With no key given, the plug-in generates an Ed25519 key the first time it starts, keeps it, and serves its public half at /.well-known/jwks.json. The deployment running it registers that JWKS with Initiative, beside where the plug-in runs, in its PLUGIN_SERVICES_CONFIG entry or under Settings → Platform → Integrations → Plug-in services. At every start the plug-in logs each key it serves:

plug-in key fingerprint: <thumbprint> (kid <kid>)

The fingerprint is the key's RFC 7638 SHA-256 thumbprint, base64url without padding, the value Initiative shows when the operator connects the plug-in, so the two can be compared. jwkThumbprint from initiative-plugin-sdk/client computes it for a JWKS entry. To bring your own key:

npx initiative-plugin keygen --out ./secrets

private-key.pem (mode 0600) stays with the plug-in; jwks.json is its public half. To rotate, publish a JWKS holding both keys, switch the plug-in to the new one, then drop the old entry.

Every plug-in key is Ed25519, signing EdDSA, as is the deployment's own key. Its signatures are deterministic, so there is no per-signature nonce whose reuse or bias would give the key away. loadPrivateKey refuses any other kind of key. A deployment that runs the plug-in from its package mints the key for it.

Context. Your own services reach handlers as context. Say what it holds once:

declare module "initiative-plugin-sdk/manifest" {
  interface PluginContext {
    tracker: TrackerClient;
  }
}

serve(createPlugin(plugin, { context: { tracker: new TrackerClient() } }));