MCPcopy Index your code
hub / github.com/CapSoftware/Cap / tinybirdIngest

Function tinybirdIngest

scripts/analytics/populate-test-data.js:92–114  ·  view source on GitHub ↗
({ host, token, datasource, ndjson })

Source from the content-addressed store, hash-verified

90}
91
92async function tinybirdIngest({ host, token, datasource, ndjson }) {
93 const search = new URLSearchParams({ name: datasource, format: "ndjson" });
94 const url = `${host.replace(/\/$/, "")}/v0/events?${search.toString()}`;
95 const response = await fetch(url, {
96 method: "POST",
97 headers: {
98 Authorization: `Bearer ${token}`,
99 "Content-Type": "application/x-ndjson",
100 Accept: "application/json",
101 },
102 body: ndjson,
103 });
104 const text = await response.text();
105 if (!response.ok) {
106 let message = text;
107 try {
108 const payload = JSON.parse(text || "{}");
109 message = payload?.error || payload?.message || text;
110 } catch {}
111 throw new Error(`Tinybird ingest failed (${response.status}): ${message}`);
112 }
113 return text ? JSON.parse(text) : {};
114}
115
116function parseDatabaseUrl(url) {
117 if (!url) throw new Error("DATABASE_URL not found");

Callers 1

mainFunction · 0.70

Calls 1

fetchFunction · 0.50

Tested by

no test coverage detected