(insight: Insight)
| 166 | } |
| 167 | |
| 168 | async 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" |
| 188 | function hasId(x: unknown): x is { id: string | number } { |
no test coverage detected