UNPKG

@feedinbox/sdk

Version:

Secure TypeScript SDK for FeedInbox - API client for feedback collection and user engagement

199 lines (197 loc) 5.86 kB
/** * FeedInbox SDK - Secure TypeScript client for feedback collection * * This SDK provides a secure interface to the FeedInbox API with: * - Domain validation * - API key security * - Rate limiting * - Retry logic * - Input sanitization */ interface FeedInboxConfig { apiKey?: string; apiUrl?: string; timeout?: number; retries?: number; customBackendUrl?: string; } interface FeedbackData { userEmail: string; message: string; subject?: string; priority?: 'low' | 'medium' | 'high'; workspaceId?: string; metadata?: Record<string, any>; } interface SubscriptionObject { id: string; title: string; description: string; } interface SubscriptionData { email: string; subscriptions: SubscriptionObject[]; consent?: boolean; workspaceId?: string; metadata?: Record<string, any>; } interface ContactData { firstName: string; lastName?: string; email: string; subject?: string; message: string; workspaceId?: string; metadata?: Record<string, any>; } interface PreferenceObject { id: string; title: string; description: string; value?: any; } interface PreferencesData { preferences: PreferenceObject[]; workspaceId?: string; metadata?: Record<string, any>; } interface ApiResponse<T = any> { success: boolean; data?: T; error?: string; message?: string; } interface UnsubscribeInfo { email: string; subscriptions: SubscriptionObject[]; active: boolean; token: string; requires_confirmation: boolean; } interface UnsubscribeResult { email: string; unsubscribed_from: string; remaining_subscriptions: SubscriptionObject[]; completely_unsubscribed: boolean; } declare class FeedInboxSDK { private readonly apiKey; private readonly apiUrl; private readonly timeout; private readonly retries; private readonly rateLimiter; private readonly headers; constructor(config?: FeedInboxConfig); private getApiKeyFromEnv; private getDefaultApiUrl; private makeRequest; private delay; /** * Create feedback entry */ createFeedback(feedback: FeedbackData): Promise<ApiResponse>; /** * Get feedback entries */ getFeedback(params?: { userEmail?: string; limit?: number; page?: number; status?: 'open' | 'responded' | 'closed'; }): Promise<ApiResponse>; /** * Update feedback entry */ updateFeedback(feedbackId: string, updates: Partial<FeedbackData>): Promise<ApiResponse>; /** * Delete feedback entry */ deleteFeedback(feedbackId: string): Promise<ApiResponse>; /** * Create subscriber (newsletter subscription) */ createSubscriber(subscription: SubscriptionData): Promise<ApiResponse>; /** * Get subscriber data */ getSubscriber(userEmail: string): Promise<ApiResponse>; /** * Update subscriber subscriptions */ updateSubscriber(userEmail: string, subscriptions: SubscriptionObject[]): Promise<ApiResponse>; /** * Delete subscriber */ deleteSubscriber(userEmail: string): Promise<ApiResponse>; /** * Create contact form submission */ createContact(contact: ContactData): Promise<ApiResponse>; /** * Get contact submissions */ getContacts(params?: { userEmail?: string; limit?: number; page?: number; }): Promise<ApiResponse>; /** * Update contact submission */ updateContact(contactId: string, updates: Partial<ContactData>): Promise<ApiResponse>; /** * Delete contact submission */ deleteContact(contactId: string): Promise<ApiResponse>; /** * Create user preferences */ createPreferences(userEmail: string, preferences: PreferencesData): Promise<ApiResponse>; /** * Get user preferences */ getPreferences(userEmail: string): Promise<ApiResponse>; /** * Update user preferences */ updatePreferences(userEmail: string, preferences: PreferencesData): Promise<ApiResponse>; /** * Delete user preferences */ deletePreferences(userEmail: string): Promise<ApiResponse>; /** * Combined user data fetch - gets preferences, subscriptions, and metadata in one call * Optimized to replace multiple separate API calls */ getUserProfile(userEmail: string, options?: { includePreferences?: boolean; includeSubscriptions?: boolean; includeMetadata?: boolean; preferenceIds?: string[]; subscriptionIds?: string[]; }): Promise<ApiResponse>; /** * Check if user has any data (preferences or subscriptions) without fetching full objects * Optimized for existence checks */ hasUserData(userEmail: string): Promise<ApiResponse<{ hasPreferences: boolean; hasSubscriptions: boolean; hasAnyData: boolean; }>>; /** * Toggle single subscription on/off by ID - optimized for subscription management */ toggleSubscription(userEmail: string, subscriptionId: string, enabled: boolean, metadata?: Record<string, any>): Promise<ApiResponse>; /** * Subscribe to newsletter (alias for createSubscriber) * @deprecated Use createSubscriber instead */ subscribe(subscription: SubscriptionData): Promise<ApiResponse>; /** * Submit contact form (alias for createContact) * @deprecated Use createContact instead */ submitContact(contact: ContactData): Promise<ApiResponse>; } export { type ApiResponse, type ContactData, type FeedInboxConfig, FeedInboxSDK, type FeedbackData, type PreferenceObject, type PreferencesData, type SubscriptionData, type SubscriptionObject, type UnsubscribeInfo, type UnsubscribeResult, FeedInboxSDK as default };