import dynamic from 'next/dynamic' import type { ComponentType } from 'react' import { listenForAdminShellEvents } from './message' import { withChallenge } from './components/challenge' import { BootstrapOptions } from './types' import { loadActivityFlowScript } from './scripts/activity-flow' import { IS_DEV } from '@vtex/raccoon-core' export function connect(options?: BootstrapOptions) { if (typeof window === 'undefined') return // Raccoon applications running with no proxy // go through this path to listen for events // from the Admin Shell to retrieve context. listenForAdminShellEvents(options) // Load Activity Flow script conditionally: // In development, only load if explicitly enabled via enableActivityFlow option const shouldLoadActivityFlow = !IS_DEV || options?.enableActivityFlow if (shouldLoadActivityFlow) { loadActivityFlowScript() } } export function bootstrap
( Component: ComponentType
, options?: BootstrapOptions, ) { return dynamic(() => Promise.resolve(withChallenge(Component, options)), { ssr: false, }) }