/** * A/B Testing Types * * Core type definitions for server-side A/B testing. */ /** * Represents a single variant in an A/B test. */ export interface AbTestVariant { /** Contentful entry ID of the PageVariant */ id: string; /** URL slug of the variant page */ slug: string; } /** * Configuration for a single variant in an A/B test. * Index 0 is the control, subsequent indices correspond to variants. */ export interface AbTestVariantConfig { /** Traffic weight for this variant (0-1, all weights should sum to 1) */ weight: number; /** CMS label for this bucket; drives variant_id suffix */ variant_label?: string; /** Optional per-bucket analytics event name */ reporting_event?: string; /** Query params to inject when injectUrlParams is enabled on the test */ url_params?: Record; /** Arbitrary key-value pairs merged into experiment_impression payloads */ reporting_params?: Record; } /** * A/B test configuration stored in the blob store. * This is the runtime representation of a PageTest entry. */ export interface AbTest { /** Contentful entry ID of the PageTest */ id: string; /** Internal CMS label for the test */ cmsLabel: string; /** URL path slug of the control page (e.g., "pricing" or "lp/special-offer") */ controlSlug: string; /** Optional URL query parameters to match (e.g., "utm_source=google") */ searchParameters?: string; /** Analytics experiment name (defaults to cmsLabel) */ trackingLabel?: string; /** Whether the test is currently active */ enabled: boolean; /** When true, inject url_params from the assigned bucket into the request URL */ injectUrlParams?: boolean; /** Array of variant configurations with weights. Index 0 = control, 1+ = variants */ configuration: AbTestVariantConfig[]; /** Array of variants to test against the control */ variants: AbTestVariant[]; } /** * Assignment data stored in the A/B test cookie. * Each test has its own assignment keyed by test ID. */ export interface AbTestAssignment { /** Analytics experiment name for this test */ experiment_name: string; /** Bucket identifier, e.g. "control:normal-cta" or "variant:home-kids" */ variant_id: string; /** Slug of the assigned variant, or "control" */ variant_slug: string; /** Original URL path where the test was assigned */ original_path: string; /** Optional per-bucket analytics event name */ reporting_event?: string; /** URL params to inject when injectUrlParams is enabled */ url_params?: Record; /** Arbitrary key-value pairs for analytics adapters */ reporting_params?: Record; } /** * Cookie structure for A/B test assignments. * Key is the test ID, value is the assignment data. */ export type AbTestCookie = Record; /** * Generic blob store interface for A/B test configuration storage. * * Projects must implement this interface for their hosting platform: * - Vercel: Use Vercel KV * - Netlify: Use Netlify Blobs * - Local development: Use file system * * @example Vercel KV implementation * ```typescript * import { kv } from '@vercel/kv'; * import type { IBlobStore, AbTest } from '@se-studio/ab-testing'; * * export function getAbTestStore(): IBlobStore { * return { * async get(key) { return kv.get(`ab-test:${key}`); }, * async set(key, value) { await kv.set(`ab-test:${key}`, value); }, * async bulkWrite(entries) { * const pipeline = kv.pipeline(); * for (const [key, value] of entries) { * pipeline.set(`ab-test:${key}`, value); * } * await pipeline.exec(); * }, * async size() { return (await kv.keys('ab-test:*')).length; }, * async values() { return kv.mget(...(await kv.keys('ab-test:*'))); }, * }; * } * ``` */ export interface IBlobStore { /** * Get a value by key * @param key - The key to look up * @returns The value, or undefined if not found */ get(key: string): Promise; /** * Set a value by key * @param key - The key to store under * @param value - The value to store */ set(key: string, value: T): Promise; /** * Replace all entries in the store with new entries * @param entries - Array of [key, value] tuples to store */ bulkWrite(entries: [string, T][]): Promise; /** * Get the number of entries in the store * @returns The count of stored entries */ size(): Promise; /** * Get all values in the store * @returns Array of all stored values */ values(): Promise; } //# sourceMappingURL=types.d.ts.map