Skip to main content

KONGO INTEGRATION

kongo-integration.ts

Landing page engine: authenticated client, from-PRD page generation, growth signal polling, webhook handlers.

Stark avatarStark

WHAT THIS PATTERN TEACHES

How to build a first-party API integration with typed client, HMAC-verified webhooks, and a closed-loop feedback pipeline (generate → track → analyze → feed back).

WHEN TO USE THIS

Integrating an external landing page engine with growth/campaign systems. Unlike adapter patterns, there's no abstraction layer — the client talks directly to the API.

AT A GLANCE

interface KongoClientConfig {
  apiKey: string;     // ke_live_ prefix, vault-sourced
  baseUrl?: string;   // Default: https://kongo.io/api/v1
  rateLimitPerMinute?: number;
}

FRAMEWORK IMPLEMENTATIONS

TypeScript
// Webhook route at /api/webhooks/kongo
import { NextRequest, NextResponse } from "next/server";
import { timingSafeEqual, createHmac } from "crypto";

function verifySignature(body: string, signature: string, secret: string): boolean {
  const expected = createHmac("sha256", secret).update(body).digest("hex");
  return timingSafeEqual(Buffer.from(signature), Buffer.from(expected));
}

export async function POST(req: NextRequest) {
  const body = await req.text();
  const sig = req.headers.get("x-kongo-signature") ?? "";
  if (!verifySignature(body, sig, process.env.KONGO_WEBHOOK_SECRET!)) {
    return NextResponse.json({ error: "Invalid signature" }, { status: 401 });
  }
  const event = JSON.parse(body);
  // Route: page.completed, page.failed, variant.winner
  return NextResponse.json({ received: true });
}
← All Patterns