import { CollectorConfig } from '@junctionjs/core'; import { AstroIntegration } from 'astro'; /** * @junctionjs/astro - Astro v5+ Integration * * Provides: * 1. An Astro integration (auto-injects client script, handles View Transitions) * 2. A middleware factory (server-side event collection) * 3. Helper components for declarative tracking * * Design decisions: * - View Transitions are first-class. We hook into astro:page-load and * astro:before-preparation to track navigations correctly. * - Middleware collects server-side context (IP, UA, geo) and makes it * available to the client via a serialized data attribute. * - The integration injects at "page" stage so tracking runs on every * page as a module script, including those with no client islands. */ interface JunctionAstroConfig { /** * Junction collector config — destinations, consent, contracts, etc. * This will be serialized and injected into the client. * IMPORTANT: don't put server-side secrets here! Use the middleware * for server-side destinations. */ config: Omit & { /** * Client-side destination configs. * Destinations are referenced by package name and resolved at build time. */ destinations: Array<{ /** Package name (e.g., "@junctionjs/destination-amplitude") */ package: string; /** Export name (default: "default") */ export?: string; /** Destination-specific config */ config: Record; /** Consent overrides */ consent?: string[]; /** Enable/disable */ enabled?: boolean; }>; }; /** * Window global name (default: "jct"). * Set to false to disable. */ globalName?: string | false; /** * Auto-track page views (default: true). * Handles both initial load and View Transitions. */ autoPageView?: boolean; /** * Server-side collect endpoint path (default: "/api/collect"). * Set to false to disable server-side collection. */ collectEndpoint?: string | false; /** * Enable debug mode (default: false). * When true, injects the @junctionjs/debug panel into the page. * Tip: use `debug: import.meta.env.DEV` to auto-enable in dev only. */ debug?: boolean; /** * Debug panel options (only used when debug: true). */ debugOptions?: { /** Keyboard shortcut to toggle (default: "ctrl+shift+j") */ shortcut?: string; /** Max events in ring buffer (default: 500) */ maxEvents?: number; /** Start with panel open (default: false) */ startOpen?: boolean; /** Panel position (default: "bottom-right") */ position?: "top-left" | "top-right" | "bottom-left" | "bottom-right"; }; } /** * Creates the Astro integration for Junction. * * Usage in astro.config.mjs: * * import { junction } from "@junctionjs/astro"; * import { amplitude } from "@junctionjs/destination-amplitude"; * * export default defineConfig({ * integrations: [ * junction({ * config: { * name: "my-site", * environment: import.meta.env.MODE, * consent: { * defaultState: {}, * queueTimeout: 30000, * respectDNT: true, * respectGPC: true, * }, * destinations: [ * { * package: "@junctionjs/destination-amplitude", * config: { apiKey: import.meta.env.AMPLITUDE_KEY, mode: "client" }, * }, * { * package: "@junctionjs/destination-ga4", * config: { measurementId: "G-XXXXXXXXXX" }, * }, * ], * }, * debug: import.meta.env.DEV, * }), * ], * }); */ declare function junction(options: JunctionAstroConfig): AstroIntegration; export { type JunctionAstroConfig, junction as default, junction };