MCPcopy Create free account
hub / github.com/Kilo-Org/cloud / patchInsight

Function patchInsight

apps/web/src/scripts/posthog/audit-microdollar-usage.ts:168–185  ·  view source on GitHub ↗
(insight: Insight)

Source from the content-addressed store, hash-verified

166}
167
168async function patchInsight(insight: Insight): Promise<void> {
169 const updatedQuery = replaceInQuery(insight.query);
170
171 const url = `${POSTHOG_API_BASE}/api/environments/${PROJECT_ID}/insights/${insight.id}`;
172 console.log(`\n🔄 Patching insight "${insight.name}" (ID: ${insight.id})`);
173 console.log(` URL: ${url}`);
174 console.log(` Old query:`, JSON.stringify(insight.query, null, 2));
175 console.log(` New query:`, JSON.stringify(updatedQuery, null, 2));
176
177 const response = await fetchWithAuth(url, {
178 method: 'PATCH',
179 body: JSON.stringify({ query: updatedQuery }),
180 });
181
182 const result = await response.json();
183 console.log(`✅ Successfully patched insight "${insight.name}"`);
184 console.log(` Response:`, JSON.stringify(result, null, 2));
185}
186
187// Type guard to avoid "any"
188function hasId(x: unknown): x is { id: string | number } {

Callers 1

runFunction · 0.85

Calls 4

replaceInQueryFunction · 0.85
fetchWithAuthFunction · 0.70
logMethod · 0.65
jsonMethod · 0.65

Tested by

no test coverage detected