Skip to content

Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.

973 B
Raw Blame
// SPDX-License-Identifier: AGPL-3.0-only
// Carbon (github.com/crbnos/carbon). Modified or adapted versions of this file,
// including ports, remain AGPLv3; serving them over a network requires releasing their source.

export async function sendToProxyBox({
  url,
  apiKey,
  content
}: {
  url: string;
  apiKey?: string | null;
  content: string | Buffer;
}) {
  const headers: Record<string, string> = {
    "Content-Type": "application/octet-stream"
  };

  if (apiKey) {
    headers["X-API-Key"] = apiKey;
  }

  const body = typeof content === "string" ? content : new Uint8Array(content);

  const response = await fetch(url, {
    method: "POST",
    headers,
    body,
    signal: AbortSignal.timeout(30_000)
  });

  if (!response.ok) {
    const text = await response.text().catch(() => "");
    throw new Error(
      `ProxyBox delivery failed: ${response.status} ${response.statusText}${text ? ` — ${text}` : ""}`
    );
  }

  return { success: true };
}