Skip to content

armgit / kaneo

Public Imported from GitHub
0

⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.

834 B
Raw Blame
import { createHmac } from "node:crypto";
import * as Sentry from "@sentry/node";
import { sendOutboundRequest } from "../../utils/outbound-request";

type GenericWebhookPayload = Record<string, unknown>;

export async function postToGenericWebhook(
  webhookUrl: string,
  payload: GenericWebhookPayload,
  secret?: string,
): Promise<void> {
  Sentry.addBreadcrumb({
    category: "integration",
    level: "info",
    data: { integration: "generic-webhook" },
  });
  const body = JSON.stringify(payload);
  const headers: Record<string, string> = {
    "Content-Type": "application/json",
  };

  if (secret) {
    headers["X-Kaneo-Signature"] = createHmac("sha256", secret)
      .update(body)
      .digest("hex");
  }

  await sendOutboundRequest(
    webhookUrl,
    { headers, body },
    { publicDestination: true },
  );
}