@sheepit-ai/server
v1.0.0
Published
Sheepit server-side SDK — flags, experiments, and event tracking for Node.js / Next.js
Maintainers
Readme
@goatech/server
Server-side SDK for the GoaTech release-intelligence platform. Evaluate flags, run experiments, and track events from Node.js, Next.js server components, Fastify, Express, and beyond.
Install
npm install @goatech/serverQuickstart
import { GoaTechServer } from "@goatech/server";
const gt = new GoaTechServer({
apiKey: process.env.GT_SECRET_KEY!, // lp_sec_* — NEVER ship in a browser bundle
apiUrl: "https://api.goatech.ai", // optional
});
// Track an event
await gt.track("course_purchased", {
userId: "user_abc",
course_id: "c_123",
revenue_usd: 99,
});
// Evaluate a flag for a specific user context
const showBeta = await gt.flag(
"show_beta_ui",
{ userId: "user_abc", traits: { country: "US", plan: "pro" } },
false,
);Next.js (App Router / Server Components)
The Next.js subexport ships an env-driven singleton — no constructor needed. Set GT_SECRET_KEY (or legacy LP_SECRET_KEY) and optionally GT_ENVIRONMENT / GT_API_URL.
// app/page.tsx — server component
import { getGoaTech } from "@goatech/server/nextjs";
export default async function Home() {
const gt = getGoaTech();
const showBeta = await gt.flag("show_beta_ui", { userId: "user_abc" }, false);
return <main>{showBeta ? <BetaLanding /> : <ClassicLanding />}</main>;
}Keys
Server SDK requires a secret key (lp_sec_*). If you pass a publishable key, the SDK will error at initialization. Never expose secret keys to the client.
API
new GoaTechServer(config)
Required: apiKey. Other options:
apiUrl— defaults tohttps://api.goatech.aienvironment— defaults toproductioncacheTtl— config cache TTL in ms (default 60_000)flushInterval— batch flush cadence in ms (default 5_000)flushSize— batch size before auto-flush (default 50)maxBufferSize— hard cap on buffered events (default 10_000; oldest dropped)autoCaptureErrors— installprocess.on("uncaughtException" | "unhandledRejection")(defaulttrue)appVersion— attached to every event for Release attribution
gt.track(eventName, { userId, ...properties })
Fire-and-forget event ingest. Returns a promise that resolves when the event is either flushed or enqueued.
gt.flag(flagKey, context, defaultValue?)
Evaluate a flag for a given user/context. context is { userId?, traits? }. Server-side evaluation — bit-identical to browser-side result for the same inputs.
gt.experiment(experimentKey, { userId, traits? })
Return the variant assignment for a given user. Sticky across calls.
gt.identify(userId, traits)
Persist user traits server-side.
gt.flush()
Wait for all queued events to drain. Call before Lambda/Vercel functions return.
Environment variables
Read by the Next.js subexport's auto-singleton:
| Variable | Legacy fallback | Purpose |
| ---------------- | ---------------- | ---------------------------------------------------------------- |
| GT_SECRET_KEY | LP_SECRET_KEY | Server-side lp_sec_* API key. Required. |
| GT_ENVIRONMENT | LP_ENVIRONMENT | Environment slug (defaults to production). |
| GT_API_URL | LP_API_URL | Override the API base URL. Defaults to https://api.goatech.ai. |
The legacy LP_* names are accepted unchanged so existing deploys keep working through the rename — see the LaunchPad → GoaTech note in the root CLAUDE.md.
License
MIT © GoaTech
