import type { AbTest, AbTestAssignment, IBlobStore } from '../types'; /** * Cached test data with pre-computed weights and lookups for fast middleware execution. */ export interface CachedAbTest extends AbTest { /** Pre-computed weights map: variantId/control -> weight */ readyWeights: Record; /** Pre-computed lookup: variantId/control -> slug */ variantLookup: Record; /** Pre-computed lookup: variantId/control -> variant_label */ variantLabelLookup: Record; /** Pre-computed lookup: variantId/control -> reporting event name */ reportingEventLookup: Record; /** Pre-computed lookup: variantId/control -> url_params */ urlParamsLookup: Record | undefined>; /** Pre-computed lookup: variantId/control -> reporting_params */ reportingParamsLookup: Record | undefined>; } /** * In-memory cache structure for A/B tests. */ export interface TestsCache { /** Timestamp when the cache was last refreshed */ timestamp: number; /** Tests indexed by normalized control path */ testsByPath: Map; } /** * Configuration for the A/B test middleware. */ export interface AbTestMiddlewareConfig { /** * Factory function that returns the blob store instance. * Called when the cache needs to be refreshed. */ getStore: () => IBlobStore | Promise>; /** * Cache time-to-live in milliseconds. * @default 60000 (60 seconds) */ cacheTtlMs?: number; /** * Name of the cookie used to store A/B test assignments. * @default "ab-test-info" */ cookieName?: string; /** * Cookie max age in seconds. * @default 2592000 (30 days) */ cookieMaxAge?: number; /** * Optional function to determine if middleware should process this request. * Return false to skip A/B testing for this request. * @default Always returns true */ shouldProcess?: (pathname: string) => boolean; /** * Optional test data for development mode. * When provided and in development, this data is used instead of fetching from store. */ devTestData?: AbTest[]; /** * Optional callback for validation failures. * Called when a cookie assignment fails validation against current config. */ onValidationFailure?: (testId: string, assignment: AbTestAssignment) => void; /** * Path prefix to prepend when rewriting to a variant. * e.g. "/page-test" → rewrites to "/page-test/slug" instead of "/slug". * Useful to keep variant URLs on an internal route excluded from robots.txt. * @default "" (no prefix — rewrite directly to slug) */ variantPathPrefix?: string; /** * Remove cookie entries for tests no longer in the active config. * @default true */ pruneStaleAssignments?: boolean; /** * When injecting url_params, skip keys already present on the request URL. * @default true */ respectExistingUrlParams?: boolean; } /** * Result of processing an A/B test request. */ export interface AbTestResult { /** Whether a test was matched and processed */ matched: boolean; /** The test that was matched (if any) */ test?: CachedAbTest; /** The assignment for this user (if any) */ assignment?: AbTestAssignment; /** The URL to rewrite to (if variant assigned) */ rewriteUrl?: string; /** Updated cookie value to set */ cookieValue?: string; /** Whether stale cookie keys were pruned */ prunedStale?: boolean; } //# sourceMappingURL=types.d.ts.map