@adopture/next
Version:
Next.js SDK for Adopture feature adoption tracking with SSR support
144 lines (139 loc) • 5.18 kB
text/typescript
import { AdoptionEventData, UserProperties } from '@adopture/sdk-core';
export { AdoptionEventData, AdoptionEventType, ExposureEventData, FeatureTrackerConfig, UserProperties, VisibilityTrackingOptions } from '@adopture/sdk-core';
import { S as ServerAdoptureTracker, f as ServerAdoptureConfig, B as BootstrapData } from './types-CXiGQrH7.mjs';
export { M as MiddlewareConfig } from './types-CXiGQrH7.mjs';
export { T as TTLCache, a as extractEnvironmentFromApiKey, e as extractProjectIdFromApiKey, d as extractRoute, g as extractUserId, i as isDevelopment, b as isProduction, f as loadServerConfig, s as shouldExcludeRoute, v as validateConfig } from './utils-C8-K9PXs.mjs';
/**
* Server-side Adopture tracker for Next.js applications
* Designed for server components, API routes, and middleware
*/
declare class NextServerTracker implements ServerAdoptureTracker {
private config;
private isInitialized;
private events;
private sessionId;
constructor();
/**
* Initialize the server tracker
*/
init(manualConfig?: Partial<ServerAdoptureConfig>): Promise<void>;
/**
* Track feature usage
*/
track(featureId: string, userId: string, metadata?: Record<string, unknown>): Promise<void>;
/**
* Track feature adoption
*/
trackAdoption(data: AdoptionEventData): Promise<void>;
/**
* Track feature exposure
*/
expose(featureId: string, userId: string, exposureChannel?: string, metadata?: Record<string, unknown>): Promise<void>;
/**
* Identify user with properties
*/
identify(userId: string, properties?: UserProperties): Promise<void>;
/**
* Flush all queued events (not applicable for server-side, events are sent immediately)
*/
flush(): Promise<void>;
/**
* Check if tracker is ready
*/
isReady(): boolean;
/**
* Get current configuration
*/
getConfig(): ServerAdoptureConfig | null;
/**
* Generate bootstrap data for client-side hydration
*/
generateBootstrapData(userId?: string, userProperties?: UserProperties): BootstrapData | null;
/**
* Send event to API
*/
private sendEvent;
}
/**
* Create a new server tracker instance
*/
declare function createServerTracker(config?: Partial<ServerAdoptureConfig>): NextServerTracker;
/**
* Get or create global server tracker instance
*/
declare function getServerTracker(config?: Partial<ServerAdoptureConfig>): NextServerTracker;
/**
* Initialize global server tracker
*/
declare function initServerTracker(config?: Partial<ServerAdoptureConfig>): Promise<NextServerTracker>;
/**
* Next.js Server Actions integration for Adopture
* Provides server actions that can be called from client components
*/
/**
* Server action to track feature usage
*/
declare function trackFeature(featureId: string, userId?: string, metadata?: Record<string, unknown>): Promise<{
success: boolean;
error?: string;
}>;
/**
* Server action to track feature adoption
*/
declare function trackAdoption(data: Omit<AdoptionEventData, 'userId'> & {
userId?: string;
}): Promise<{
success: boolean;
error?: string;
}>;
/**
* Server action to track feature exposure
*/
declare function exposeFeature(featureId: string, exposureChannel?: string, userId?: string, metadata?: Record<string, unknown>): Promise<{
success: boolean;
error?: string;
}>;
/**
* Server action to identify user
*/
declare function identifyUser(userId: string, properties?: UserProperties): Promise<{
success: boolean;
error?: string;
}>;
/**
* Server action to initialize tracker (should be called from layout or page)
*/
declare function initializeTracker(config?: Partial<ServerAdoptureConfig>): Promise<{
success: boolean;
error?: string;
bootstrapData?: any;
}>;
/**
* Server action to get current tracker status
*/
declare function getTrackerStatus(): Promise<{
isReady: boolean;
config?: ServerAdoptureConfig | null;
error?: string;
}>;
/**
* Higher-order function to wrap server actions with automatic tracking
*/
declare function withTracking<T extends any[], R>(action: (...args: T) => Promise<R>, options: {
featureId: string;
extractUserId?: (...args: T) => string | undefined;
extractMetadata?: (...args: T) => Record<string, unknown>;
trackOnSuccess?: boolean;
trackOnError?: boolean;
}): (...args: T) => Promise<R>;
/**
* Decorator for server actions to add automatic tracking
*/
declare function track(options: {
featureId: string;
extractUserId?: (...args: any[]) => string | undefined;
extractMetadata?: (...args: any[]) => Record<string, unknown>;
trackOnSuccess?: boolean;
trackOnError?: boolean;
}): <T extends any[], R>(target: any, propertyName: string, descriptor: TypedPropertyDescriptor<(...args: T) => Promise<R>>) => TypedPropertyDescriptor<(...args: T) => Promise<R>>;
export { BootstrapData, NextServerTracker, ServerAdoptureConfig, ServerAdoptureTracker, createServerTracker, exposeFeature, getServerTracker, getTrackerStatus, identifyUser, initServerTracker, initializeTracker, track, trackAdoption, trackFeature, withTracking };