flowgrid-sdk 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/LICENSE +21 -0
  2. package/dist/browser.d.ts +119 -0
  3. package/dist/flowgrid.min.js +2 -0
  4. package/dist/flowgrid.min.js.map +1 -0
  5. package/dist/index.d.ts +44 -0
  6. package/dist/index.js +2 -0
  7. package/dist/index.js.map +1 -0
  8. package/dist/lib/client/enterprise-ftrpc.d.ts +51 -0
  9. package/dist/lib/client/ftrpc.d.ts +43 -0
  10. package/dist/lib/client/modules.d.ts +104 -0
  11. package/dist/lib/features/analytics/attribution.d.ts +257 -0
  12. package/dist/lib/features/analytics/events.d.ts +304 -0
  13. package/dist/lib/features/analytics/funnels.d.ts +291 -0
  14. package/dist/lib/features/analytics/heatmaps.d.ts +247 -0
  15. package/dist/lib/features/analytics/identify.d.ts +273 -0
  16. package/dist/lib/features/analytics/index.d.ts +22 -0
  17. package/dist/lib/features/analytics/page-views.d.ts +250 -0
  18. package/dist/lib/features/analytics/performance.d.ts +281 -0
  19. package/dist/lib/features/analytics/retention.d.ts +294 -0
  20. package/dist/lib/features/analytics/sessions.d.ts +277 -0
  21. package/dist/lib/features/core/activation.d.ts +239 -0
  22. package/dist/lib/features/core/experiment.d.ts +286 -0
  23. package/dist/lib/features/core/feature-flag.d.ts +264 -0
  24. package/dist/lib/features/core/index.d.ts +14 -0
  25. package/dist/lib/features/core/track-feature.d.ts +220 -0
  26. package/dist/lib/features/core/track-prompt.d.ts +247 -0
  27. package/dist/lib/features/ecommerce/cart.d.ts +298 -0
  28. package/dist/lib/features/ecommerce/checkout.d.ts +324 -0
  29. package/dist/lib/features/ecommerce/index.d.ts +26 -0
  30. package/dist/lib/features/ecommerce/inventory.d.ts +221 -0
  31. package/dist/lib/features/ecommerce/ltv.d.ts +258 -0
  32. package/dist/lib/features/ecommerce/products.d.ts +268 -0
  33. package/dist/lib/features/ecommerce/promotions.d.ts +266 -0
  34. package/dist/lib/features/ecommerce/purchases.d.ts +287 -0
  35. package/dist/lib/features/ecommerce/refunds.d.ts +232 -0
  36. package/dist/lib/features/ecommerce/search.d.ts +225 -0
  37. package/dist/lib/features/ecommerce/subscriptions.d.ts +281 -0
  38. package/dist/lib/features/ecommerce/wishlist.d.ts +236 -0
  39. package/dist/lib/features/enterprise/acquisition.d.ts +373 -0
  40. package/dist/lib/features/enterprise/alerts.d.ts +348 -0
  41. package/dist/lib/features/enterprise/churn.d.ts +288 -0
  42. package/dist/lib/features/enterprise/cohorts.d.ts +270 -0
  43. package/dist/lib/features/enterprise/engagement.d.ts +233 -0
  44. package/dist/lib/features/enterprise/forecasting.d.ts +351 -0
  45. package/dist/lib/features/enterprise/index.d.ts +20 -0
  46. package/dist/lib/features/enterprise/monetization.d.ts +356 -0
  47. package/dist/lib/features/enterprise/multi-path-funnels.d.ts +327 -0
  48. package/dist/lib/features/enterprise/paths.d.ts +332 -0
  49. package/dist/lib/features/enterprise/security.d.ts +387 -0
  50. package/dist/lib/features/enterprise/support.d.ts +329 -0
  51. package/dist/lib/frameworks/index.d.ts +9 -0
  52. package/dist/lib/frameworks/nextjs/client.d.ts +208 -0
  53. package/dist/lib/frameworks/nextjs/index.d.ts +29 -0
  54. package/dist/lib/frameworks/nextjs/server.d.ts +201 -0
  55. package/dist/lib/frameworks/node/index.d.ts +265 -0
  56. package/dist/lib/frameworks/nuxt/index.d.ts +190 -0
  57. package/dist/lib/frameworks/react/index.d.ts +245 -0
  58. package/dist/lib/frameworks/vue/index.d.ts +275 -0
  59. package/dist/lib/types/analytics.d.ts +365 -0
  60. package/dist/lib/types/common.d.ts +230 -0
  61. package/dist/lib/types/ecommerce.d.ts +309 -0
  62. package/dist/lib/types/index.d.ts +7 -0
  63. package/dist/lib/utils/functions.d.ts +1 -0
  64. package/package.json +139 -0
@@ -0,0 +1,258 @@
1
+ /**
2
+ * @fileoverview Ecommerce - Customer Lifetime Value (LTV)
3
+ * @module features/ecommerce/ltv
4
+ *
5
+ * @description
6
+ * Calculate and track customer lifetime value to understand
7
+ * customer worth and optimize acquisition costs.
8
+ *
9
+ * @useCases
10
+ * - Calculate customer LTV
11
+ * - Segment customers by value
12
+ * - Track LTV trends over time
13
+ * - Identify high-value customers
14
+ * - Optimize acquisition spend (LTV:CAC)
15
+ *
16
+ * @metrics
17
+ * - Average LTV
18
+ * - LTV by cohort
19
+ * - LTV by segment
20
+ * - LTV:CAC ratio
21
+ * - Customer value distribution
22
+ *
23
+ * @chartData
24
+ * - Line chart: LTV by cohort over time
25
+ * - Bar chart: LTV by segment
26
+ * - Histogram: Customer value distribution
27
+ * - KPI: Average LTV, LTV:CAC
28
+ *
29
+ * @example
30
+ * ```typescript
31
+ * const ltv = new CustomerLTV(webId, endpoint, apiKey);
32
+ *
33
+ * // Get customer LTV
34
+ * const customerValue = await ltv.getCustomerValue('user_123');
35
+ *
36
+ * // Get LTV analytics
37
+ * const analytics = await ltv.getAnalytics({ range: 'last90days' });
38
+ * ```
39
+ */
40
+ import { FTRPC } from "../../client/ftrpc";
41
+ import { MoneyValue, DateRangeFilter, TimeSeriesData } from "../../types";
42
+ /**
43
+ * Customer value data.
44
+ */
45
+ export interface CustomerValueData {
46
+ /** Customer/user ID */
47
+ userId: string;
48
+ /** Total revenue from customer */
49
+ totalRevenue: MoneyValue;
50
+ /** Number of orders */
51
+ orderCount: number;
52
+ /** Average order value */
53
+ averageOrderValue: MoneyValue;
54
+ /** Predicted future value */
55
+ predictedLTV: MoneyValue;
56
+ /** Customer segment */
57
+ segment: 'low' | 'medium' | 'high' | 'vip';
58
+ /** Days since first purchase */
59
+ customerAge: number;
60
+ /** Days since last purchase */
61
+ daysSinceLastPurchase: number;
62
+ /** Purchase frequency (orders per month) */
63
+ purchaseFrequency: number;
64
+ }
65
+ /**
66
+ * Configuration for recording acquisition cost.
67
+ */
68
+ export interface AcquisitionCostConfig {
69
+ /** Customer/user ID */
70
+ userId: string;
71
+ /** Acquisition cost */
72
+ cost: MoneyValue;
73
+ /** Acquisition channel */
74
+ channel: string;
75
+ /** Campaign (if applicable) */
76
+ campaign?: string;
77
+ }
78
+ /**
79
+ * LTV event response from API.
80
+ */
81
+ export interface LTVResponse {
82
+ eventName: string;
83
+ properties: Record<string, unknown>;
84
+ response: {
85
+ userId: string;
86
+ ltv: number;
87
+ tracked: boolean;
88
+ };
89
+ timestamp: string;
90
+ }
91
+ /**
92
+ * LTV analytics data for charts.
93
+ */
94
+ export interface LTVAnalyticsData {
95
+ /** Summary metrics */
96
+ summary: {
97
+ averageLTV: MoneyValue;
98
+ medianLTV: MoneyValue;
99
+ totalCustomerValue: MoneyValue;
100
+ averageCAC: MoneyValue;
101
+ ltvCacRatio: number;
102
+ averageOrderValue: MoneyValue;
103
+ averageOrdersPerCustomer: number;
104
+ };
105
+ /** LTV by customer segment */
106
+ bySegment: Array<{
107
+ segment: string;
108
+ customerCount: number;
109
+ averageLTV: MoneyValue;
110
+ totalRevenue: MoneyValue;
111
+ percentageOfCustomers: number;
112
+ percentageOfRevenue: number;
113
+ }>;
114
+ /** LTV by cohort */
115
+ byCohort: Array<{
116
+ cohort: string;
117
+ customerCount: number;
118
+ averageLTV: MoneyValue;
119
+ ltvProgression: number[];
120
+ }>;
121
+ /** LTV by acquisition channel */
122
+ byChannel: Array<{
123
+ channel: string;
124
+ customers: number;
125
+ averageLTV: MoneyValue;
126
+ averageCAC: MoneyValue;
127
+ ltvCacRatio: number;
128
+ roi: number;
129
+ }>;
130
+ /** LTV distribution */
131
+ distribution: Array<{
132
+ range: string;
133
+ count: number;
134
+ percentage: number;
135
+ }>;
136
+ /** LTV trend over time */
137
+ trendData: TimeSeriesData;
138
+ }
139
+ /**
140
+ * CustomerLTV - Calculate and track customer lifetime value.
141
+ *
142
+ * @extends FTRPC
143
+ *
144
+ * @description
145
+ * Provides LTV tracking capabilities including:
146
+ * - Customer value calculation
147
+ * - Acquisition cost tracking
148
+ * - LTV:CAC ratio analysis
149
+ * - Customer segmentation by value
150
+ * - Cohort-based LTV analysis
151
+ *
152
+ * @example
153
+ * ```typescript
154
+ * const ltv = new CustomerLTV(webId, endpoint, apiKey);
155
+ *
156
+ * // Get individual customer value
157
+ * const value = await ltv.getCustomerValue('user_123');
158
+ * console.log(`LTV: $${value.totalRevenue.amount / 100}`);
159
+ *
160
+ * // Record acquisition cost
161
+ * await ltv.recordAcquisitionCost({
162
+ * userId: 'user_123',
163
+ * cost: { amount: 5000, currency: 'USD' },
164
+ * channel: 'facebook_ads',
165
+ * campaign: 'spring_campaign'
166
+ * });
167
+ *
168
+ * // Get LTV analytics
169
+ * const analytics = await ltv.getAnalytics();
170
+ * console.log(`LTV:CAC Ratio: ${analytics.summary.ltvCacRatio}`);
171
+ * ```
172
+ */
173
+ export declare class CustomerLTV extends FTRPC {
174
+ /**
175
+ * Gets lifetime value data for a specific customer.
176
+ *
177
+ * @param userId - Customer/user identifier
178
+ * @returns Promise resolving to customer value data
179
+ *
180
+ * @example
181
+ * ```typescript
182
+ * const value = await ltv.getCustomerValue('user_123');
183
+ *
184
+ * console.log(`Total Revenue: $${value.totalRevenue.amount / 100}`);
185
+ * console.log(`Orders: ${value.orderCount}`);
186
+ * console.log(`Segment: ${value.segment}`);
187
+ * console.log(`Predicted LTV: $${value.predictedLTV.amount / 100}`);
188
+ * ```
189
+ */
190
+ getCustomerValue(userId: string): Promise<CustomerValueData>;
191
+ /**
192
+ * Records customer acquisition cost.
193
+ *
194
+ * @param config - Acquisition cost configuration
195
+ * @returns Promise resolving to LTV response
196
+ *
197
+ * @example
198
+ * ```typescript
199
+ * await ltv.recordAcquisitionCost({
200
+ * userId: 'user_123',
201
+ * cost: { amount: 2500, currency: 'USD' }, // $25.00
202
+ * channel: 'google_ads',
203
+ * campaign: 'brand_terms'
204
+ * });
205
+ * ```
206
+ */
207
+ recordAcquisitionCost(config: AcquisitionCostConfig): Promise<LTVResponse>;
208
+ /**
209
+ * Updates customer segment based on value.
210
+ *
211
+ * @param userId - Customer/user identifier
212
+ * @param segment - New segment
213
+ * @returns Promise resolving to LTV response
214
+ */
215
+ updateSegment(userId: string, segment: 'low' | 'medium' | 'high' | 'vip'): Promise<LTVResponse>;
216
+ /**
217
+ * Gets high-value customers.
218
+ *
219
+ * @param limit - Number of customers to return
220
+ * @returns Promise resolving to list of high-value customers
221
+ */
222
+ getTopCustomers(limit?: number): Promise<CustomerValueData[]>;
223
+ /**
224
+ * Retrieves LTV analytics for dashboards and charts.
225
+ *
226
+ * @param filter - Date range filter
227
+ * @returns Promise resolving to LTV analytics
228
+ *
229
+ * @example
230
+ * ```typescript
231
+ * const analytics = await ltv.getAnalytics({
232
+ * range: 'last90days'
233
+ * });
234
+ *
235
+ * // KPI cards
236
+ * const kpis = [
237
+ * { label: 'Avg LTV', value: analytics.summary.averageLTV.amount },
238
+ * { label: 'LTV:CAC', value: analytics.summary.ltvCacRatio },
239
+ * { label: 'Avg AOV', value: analytics.summary.averageOrderValue.amount }
240
+ * ];
241
+ *
242
+ * // Bar chart - LTV by channel
243
+ * const channelChart = analytics.byChannel.map(c => ({
244
+ * name: c.channel,
245
+ * ltv: c.averageLTV.amount,
246
+ * cac: c.averageCAC.amount
247
+ * }));
248
+ *
249
+ * // Histogram - value distribution
250
+ * const distribution = analytics.distribution.map(d => ({
251
+ * range: d.range,
252
+ * count: d.count
253
+ * }));
254
+ * ```
255
+ */
256
+ getAnalytics(filter?: DateRangeFilter): Promise<LTVAnalyticsData>;
257
+ }
258
+ export default CustomerLTV;
@@ -0,0 +1,268 @@
1
+ /**
2
+ * @fileoverview Ecommerce - Product Tracking
3
+ * @module features/ecommerce/products
4
+ *
5
+ * @description
6
+ * Track product interactions including views, impressions, clicks,
7
+ * and product list interactions.
8
+ *
9
+ * @useCases
10
+ * - Track product page views
11
+ * - Measure product list/search impressions
12
+ * - Analyze product click-through rates
13
+ * - Monitor product detail engagement
14
+ * - Compare product performance
15
+ *
16
+ * @metrics
17
+ * - Product views
18
+ * - Product impressions
19
+ * - Click-through rate
20
+ * - View-to-cart rate
21
+ * - Revenue per product
22
+ *
23
+ * @chartData
24
+ * - Bar chart: Top products by views
25
+ * - Line chart: Product views over time
26
+ * - Table: Product performance comparison
27
+ * - Scatter: Price vs conversion rate
28
+ *
29
+ * @example
30
+ * ```typescript
31
+ * const products = new Products(webId, endpoint, apiKey);
32
+ *
33
+ * // Track product view
34
+ * await products.view({
35
+ * productId: 'SKU-123',
36
+ * name: 'Premium Headphones',
37
+ * price: 299.99,
38
+ * currency: 'USD',
39
+ * category: 'Electronics/Audio'
40
+ * });
41
+ * ```
42
+ */
43
+ import { FTRPC } from "../../client/ftrpc";
44
+ import { Product, ProductList, ProductPerformance, DateRangeFilter, PaginationParams, TimeSeriesData } from "../../types";
45
+ /**
46
+ * Configuration for tracking a product view.
47
+ */
48
+ export interface ProductViewConfig extends Product {
49
+ /** User ID (if authenticated) */
50
+ userId?: string;
51
+ /** Session ID */
52
+ sessionId?: string;
53
+ /** How user arrived at product (search, category, recommendation) */
54
+ source?: 'search' | 'category' | 'recommendation' | 'direct' | 'ad';
55
+ /** Search query if from search */
56
+ searchQuery?: string;
57
+ /** Custom properties */
58
+ properties?: Record<string, unknown>;
59
+ }
60
+ /**
61
+ * Configuration for tracking product impressions.
62
+ */
63
+ export interface ProductImpressionConfig {
64
+ /** List information */
65
+ list: ProductList;
66
+ /** User ID */
67
+ userId?: string;
68
+ /** Session ID */
69
+ sessionId?: string;
70
+ }
71
+ /**
72
+ * Configuration for tracking product clicks.
73
+ */
74
+ export interface ProductClickConfig {
75
+ /** Product clicked */
76
+ product: Product;
77
+ /** List where product was clicked */
78
+ listId?: string;
79
+ /** Position in list */
80
+ position?: number;
81
+ /** User ID */
82
+ userId?: string;
83
+ }
84
+ /**
85
+ * Product event response from API.
86
+ */
87
+ export interface ProductResponse {
88
+ eventName: string;
89
+ properties: Record<string, unknown>;
90
+ response: {
91
+ productId: string;
92
+ tracked: boolean;
93
+ };
94
+ timestamp: string;
95
+ }
96
+ /**
97
+ * Product analytics data for charts.
98
+ */
99
+ export interface ProductAnalyticsData {
100
+ /** Top products by various metrics */
101
+ topProducts: {
102
+ byViews: ProductPerformance[];
103
+ byRevenue: ProductPerformance[];
104
+ byConversion: ProductPerformance[];
105
+ };
106
+ /** Product views time series */
107
+ viewsTimeSeries: TimeSeriesData;
108
+ /** Summary metrics */
109
+ summary: {
110
+ totalProductViews: number;
111
+ uniqueProductsViewed: number;
112
+ avgViewsPerProduct: number;
113
+ topCategory: string;
114
+ topBrand: string;
115
+ };
116
+ /** Performance by category */
117
+ byCategory: Array<{
118
+ category: string;
119
+ views: number;
120
+ revenue: number;
121
+ conversionRate: number;
122
+ }>;
123
+ }
124
+ /**
125
+ * Products - Track product interactions.
126
+ *
127
+ * @extends FTRPC
128
+ *
129
+ * @description
130
+ * Provides product tracking capabilities including:
131
+ * - Product page views
132
+ * - Product list impressions
133
+ * - Product clicks from lists
134
+ * - Product detail interactions
135
+ * - Quick view tracking
136
+ *
137
+ * @example
138
+ * ```typescript
139
+ * const products = new Products(webId, endpoint, apiKey);
140
+ *
141
+ * // Track product page view
142
+ * await products.view({
143
+ * productId: 'PROD-001',
144
+ * name: 'Wireless Earbuds',
145
+ * price: 79.99,
146
+ * currency: 'USD',
147
+ * category: 'Electronics/Audio',
148
+ * brand: 'AudioTech'
149
+ * });
150
+ *
151
+ * // Track list impressions
152
+ * await products.impression({
153
+ * list: {
154
+ * listId: 'search-results',
155
+ * listName: 'Search Results',
156
+ * products: searchResults
157
+ * }
158
+ * });
159
+ * ```
160
+ */
161
+ export declare class Products extends FTRPC {
162
+ /**
163
+ * Tracks a product page view.
164
+ *
165
+ * @param config - Product view configuration
166
+ * @returns Promise resolving to product response
167
+ *
168
+ * @example
169
+ * ```typescript
170
+ * await products.view({
171
+ * productId: 'SKU-12345',
172
+ * name: 'Premium Widget',
173
+ * price: 49.99,
174
+ * currency: 'USD',
175
+ * category: 'Widgets/Premium',
176
+ * brand: 'WidgetCo',
177
+ * source: 'search',
178
+ * searchQuery: 'premium widget'
179
+ * });
180
+ * ```
181
+ */
182
+ view(config: ProductViewConfig): Promise<ProductResponse>;
183
+ /**
184
+ * Tracks product list impressions.
185
+ *
186
+ * @param config - Impression configuration
187
+ * @returns Promise resolving to impression response
188
+ *
189
+ * @example
190
+ * ```typescript
191
+ * // Track products shown in search results
192
+ * await products.impression({
193
+ * list: {
194
+ * listId: 'search-results',
195
+ * listName: 'Search Results',
196
+ * products: products.map((p, i) => ({ ...p, position: i + 1 }))
197
+ * }
198
+ * });
199
+ * ```
200
+ */
201
+ impression(config: ProductImpressionConfig): Promise<ProductResponse>;
202
+ /**
203
+ * Tracks a product click from a list.
204
+ *
205
+ * @param config - Click configuration
206
+ * @returns Promise resolving to click response
207
+ *
208
+ * @example
209
+ * ```typescript
210
+ * await products.click({
211
+ * product: selectedProduct,
212
+ * listId: 'homepage-featured',
213
+ * position: 3
214
+ * });
215
+ * ```
216
+ */
217
+ click(config: ProductClickConfig): Promise<ProductResponse>;
218
+ /**
219
+ * Tracks a quick view interaction (modal product view).
220
+ *
221
+ * @param product - Product being quick-viewed
222
+ * @param listId - List where quick view was triggered
223
+ * @returns Promise resolving to quick view response
224
+ */
225
+ quickView(product: Product, listId?: string): Promise<ProductResponse>;
226
+ /**
227
+ * Tracks product detail interaction (zoom, read reviews, etc.).
228
+ *
229
+ * @param productId - Product identifier
230
+ * @param action - Interaction type
231
+ * @param properties - Additional properties
232
+ * @returns Promise resolving to interaction response
233
+ */
234
+ interaction(productId: string, action: 'zoom' | 'read_reviews' | 'size_guide' | 'compare' | 'share' | 'notify_stock', properties?: Record<string, unknown>): Promise<ProductResponse>;
235
+ /**
236
+ * Retrieves product analytics data for dashboards and charts.
237
+ *
238
+ * @param filter - Date range filter
239
+ * @param pagination - Pagination options
240
+ * @returns Promise resolving to product analytics
241
+ *
242
+ * @example
243
+ * ```typescript
244
+ * const analytics = await products.getAnalytics({
245
+ * range: 'last30days'
246
+ * });
247
+ *
248
+ * // Bar chart - top products by views
249
+ * const topByViews = analytics.topProducts.byViews.map(p => ({
250
+ * name: p.product.name,
251
+ * value: p.views
252
+ * }));
253
+ *
254
+ * // Line chart - views over time
255
+ * const viewsTrend = analytics.viewsTimeSeries.data;
256
+ * ```
257
+ */
258
+ getAnalytics(filter?: DateRangeFilter, pagination?: PaginationParams): Promise<ProductAnalyticsData>;
259
+ /**
260
+ * Gets performance data for a specific product.
261
+ *
262
+ * @param productId - Product identifier
263
+ * @param filter - Date range filter
264
+ * @returns Promise resolving to product performance
265
+ */
266
+ getProductPerformance(productId: string, filter?: DateRangeFilter): Promise<ProductPerformance>;
267
+ }
268
+ export default Products;