ee5ae8af62
* explicitly ordering global middlewares * various subscription fixes & WIP project invite middleware * SSR invite accept & toast notifs seem to work * backend support for mixpanel * mixpanel be logic -> shared * minor fix * finissh * lint fix * minor comment adjustments * better adblock handling
40 lines
1016 B
TypeScript
40 lines
1016 B
TypeScript
import { LogicError } from '@speckle/ui-components'
|
|
import { fakeMixpanelClient, type MixpanelClient } from '~/lib/common/helpers/mp'
|
|
import { useServersideMixpanelClientBuilder } from '~/lib/core/clients/mpServer'
|
|
|
|
/**
|
|
* mixpanel only supports being ran on the server-side! So it's only going to be accessible
|
|
* in SSR execution branches
|
|
*/
|
|
|
|
type LimitedMixpanel = MixpanelClient
|
|
|
|
const fakeLimitedMixpanel = fakeMixpanelClient
|
|
|
|
export default defineNuxtPlugin(async () => {
|
|
const logger = useLogger()
|
|
|
|
let mixpanel: LimitedMixpanel | undefined = undefined
|
|
|
|
try {
|
|
const build = useServersideMixpanelClientBuilder()
|
|
mixpanel = (await build()) || undefined
|
|
} catch (e) {
|
|
logger.warn(e, 'Failed to load mixpanel in SSR')
|
|
}
|
|
|
|
if (!mixpanel) {
|
|
// Implement mocked version
|
|
mixpanel = fakeLimitedMixpanel()
|
|
}
|
|
|
|
return {
|
|
provide: {
|
|
mixpanel: () => {
|
|
if (!mixpanel) throw new LogicError('Mixpanel unexpectedly not defined')
|
|
return mixpanel
|
|
}
|
|
}
|
|
}
|
|
})
|