mirror of
https://github.com/hanzoai/insights-js.git
synced 2026-10-30 18:34:19 +00:00
We own the ingestion server (hanzoai/insights: Django + rust/capture + nodejs plugin) AND this SDK, so there is no external wire contract to preserve. The server is already 100% posthog-free; this SDK was the last laggard. - $last_posthog_reset -> $last_insights_reset. This FIXES A LIVE MISMATCH: the server taxonomy (insights/taxonomy/taxonomy.py, insights/insightsql/ai.py) already expected the insights form while the SDK emitted the posthog form. - __PosthogExtensions__ -> __InsightsExtensions__; all PostHog/posthog/POSTHOG identifiers -> Insights/insights/INSIGHTS (src, tests, playground, playwright, scripts, rrweb subpackages, package.json keywords). - Hosts: DEFAULT_PLUGIN_HOST + DEFAULT_NUXT_HOST + the core host default pointed at PostHog's cloud (us.i.posthog.com) — a real bug. All -> insights.hanzo.ai. - Removed the us-assets/eu-assets CDN split in getRemoteConfig (PostHog-specific; Hanzo serves remote config from the same host) — it had degenerated to a no-op. - Fixed generate-docs writing to a stray references/@hanzo/ subdir. - Renamed the 3 posthog-named test files; dropped 58MB of stale reference snapshots named for upstream posthog versions we never shipped (they are generated output — references/ is now gitignored). Verified: typecheck errors 42 (HEAD) -> 18 (all pre-existing test-mock looseness); types package 0; every package.json valid with @hanzo/* names. Guard: grep -rioE 'posthog' packages ... | wc -l => 0
64 lines
1.8 KiB
JavaScript
64 lines
1.8 KiB
JavaScript
import assert from 'node:assert/strict'
|
|
import { readFileSync } from 'node:fs'
|
|
|
|
const source = readFileSync(new URL('../src/runtime/vue-plugin.ts', import.meta.url), 'utf8')
|
|
|
|
const executableSource = source
|
|
.replace(/^import .*$/gm, '')
|
|
.replace('export default defineNuxtPlugin({', 'return defineNuxtPlugin({')
|
|
.replace(/ as (InsightsCommon|InsightsClientConfig)/g, '')
|
|
.replace('function autocaptureEnabled(config: InsightsClientConfig): boolean', 'function autocaptureEnabled(config)')
|
|
|
|
function loadPlugin({ insights, useRuntimeConfig }) {
|
|
return new Function('defineNuxtPlugin', 'useRuntimeConfig', 'insights', 'window', executableSource)(
|
|
plugin => plugin,
|
|
useRuntimeConfig,
|
|
insights,
|
|
{},
|
|
)
|
|
}
|
|
|
|
function testVueErrorHandlerCapturesInfoString() {
|
|
const captureExceptionCalls = []
|
|
const insights = {
|
|
__loaded: false,
|
|
init() {},
|
|
debug() {},
|
|
captureException(...args) {
|
|
captureExceptionCalls.push(args)
|
|
},
|
|
}
|
|
const useRuntimeConfig = () => ({
|
|
public: {
|
|
insights: {
|
|
publicKey: 'test-token',
|
|
host: 'https://insights.hanzo.ai',
|
|
},
|
|
insightsClientConfig: {
|
|
capture_exceptions: true,
|
|
},
|
|
},
|
|
})
|
|
const hookCalls = []
|
|
const plugin = loadPlugin({ insights, useRuntimeConfig })
|
|
|
|
plugin.setup({
|
|
hook(name, handler) {
|
|
hookCalls.push([name, handler])
|
|
},
|
|
})
|
|
|
|
const vueErrorHandler = hookCalls.find(([name]) => name === 'vue:error')?.[1]
|
|
assert.equal(typeof vueErrorHandler, 'function')
|
|
|
|
const error = new Error('test Vue render error')
|
|
const target = { component: 'instance' }
|
|
|
|
vueErrorHandler(error, target, 'setup function')
|
|
|
|
assert.deepEqual(captureExceptionCalls, [[error, { info: 'setup function' }]])
|
|
assert.notEqual(captureExceptionCalls[0][1].info, target)
|
|
}
|
|
|
|
testVueErrorHandlerCapturesInfoString()
|