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,266 @@
1
+ /**
2
+ * @fileoverview Ecommerce - Promotion Tracking
3
+ * @module features/ecommerce/promotions
4
+ *
5
+ * @description
6
+ * Track promotional content, coupon usage, and discount
7
+ * effectiveness across your ecommerce store.
8
+ *
9
+ * @useCases
10
+ * - Track promotional banner views
11
+ * - Measure promotion click-through rates
12
+ * - Analyze coupon usage and effectiveness
13
+ * - Monitor discount impact on revenue
14
+ * - Compare promotion performance
15
+ *
16
+ * @metrics
17
+ * - Promotion impressions
18
+ * - Promotion CTR
19
+ * - Coupon redemption rate
20
+ * - Revenue attributed to promotions
21
+ * - Discount impact on margins
22
+ *
23
+ * @chartData
24
+ * - Bar chart: Top promotions by revenue
25
+ * - Line chart: Coupon usage over time
26
+ * - Table: Promotion performance comparison
27
+ * - Pie chart: Revenue by promotion type
28
+ *
29
+ * @example
30
+ * ```typescript
31
+ * const promotions = new Promotions(webId, endpoint, apiKey);
32
+ *
33
+ * // Track promotion view
34
+ * await promotions.view({
35
+ * promotionId: 'PROMO-SUMMER',
36
+ * name: 'Summer Sale 20% Off',
37
+ * creative: 'homepage-banner'
38
+ * });
39
+ *
40
+ * // Track coupon usage
41
+ * await promotions.couponUsed({
42
+ * code: 'SAVE20',
43
+ * discountValue: 20,
44
+ * orderId: 'ORD-123'
45
+ * });
46
+ * ```
47
+ */
48
+ import { FTRPC } from "../../client/ftrpc";
49
+ import { Promotion, MoneyValue, DateRangeFilter, TimeSeriesData } from "../../types";
50
+ /**
51
+ * Configuration for tracking promotion view.
52
+ */
53
+ export interface PromotionViewConfig extends Promotion {
54
+ /** User ID */
55
+ userId?: string;
56
+ /** Page where promotion was shown */
57
+ page?: string;
58
+ }
59
+ /**
60
+ * Configuration for tracking promotion click.
61
+ */
62
+ export interface PromotionClickConfig extends Promotion {
63
+ /** User ID */
64
+ userId?: string;
65
+ /** Destination URL */
66
+ destinationUrl?: string;
67
+ }
68
+ /**
69
+ * Configuration for tracking coupon usage.
70
+ */
71
+ export interface CouponUsageConfig {
72
+ /** Coupon code */
73
+ code: string;
74
+ /** Order ID where coupon was applied */
75
+ orderId: string;
76
+ /** Discount amount */
77
+ discountValue: number;
78
+ /** Discount type */
79
+ discountType: 'percentage' | 'fixed';
80
+ /** Order value before discount */
81
+ orderValueBefore: number;
82
+ /** Order value after discount */
83
+ orderValueAfter: number;
84
+ /** User ID */
85
+ userId?: string;
86
+ }
87
+ /**
88
+ * Promotion event response from API.
89
+ */
90
+ export interface PromotionResponse {
91
+ eventName: string;
92
+ properties: Record<string, unknown>;
93
+ response: {
94
+ promotionId: string;
95
+ tracked: boolean;
96
+ };
97
+ timestamp: string;
98
+ }
99
+ /**
100
+ * Promotion analytics data for charts.
101
+ */
102
+ export interface PromotionAnalyticsData {
103
+ /** Summary metrics */
104
+ summary: {
105
+ totalPromotionViews: number;
106
+ totalPromotionClicks: number;
107
+ overallCTR: number;
108
+ totalCouponsUsed: number;
109
+ totalDiscountGiven: MoneyValue;
110
+ revenueFromPromotions: MoneyValue;
111
+ };
112
+ /** Top performing promotions */
113
+ topPromotions: Array<{
114
+ promotionId: string;
115
+ name: string;
116
+ views: number;
117
+ clicks: number;
118
+ ctr: number;
119
+ conversions: number;
120
+ revenue: number;
121
+ }>;
122
+ /** Coupon performance */
123
+ coupons: Array<{
124
+ code: string;
125
+ usageCount: number;
126
+ totalDiscount: number;
127
+ avgOrderValue: number;
128
+ conversionLift: number;
129
+ }>;
130
+ /** Promotions over time */
131
+ timeSeries: TimeSeriesData;
132
+ /** Revenue impact */
133
+ revenueImpact: {
134
+ promotedRevenue: MoneyValue;
135
+ nonPromotedRevenue: MoneyValue;
136
+ promotionRevenueShare: number;
137
+ avgDiscountPercent: number;
138
+ };
139
+ }
140
+ /**
141
+ * Promotions - Track promotions and coupons.
142
+ *
143
+ * @extends FTRPC
144
+ *
145
+ * @description
146
+ * Provides promotion tracking capabilities including:
147
+ * - Promotion/banner impressions
148
+ * - Promotion clicks
149
+ * - Coupon applications
150
+ * - Coupon success/failure
151
+ * - Revenue attribution
152
+ *
153
+ * @example
154
+ * ```typescript
155
+ * const promotions = new Promotions(webId, endpoint, apiKey);
156
+ *
157
+ * // Track banner impression
158
+ * await promotions.view({
159
+ * promotionId: 'FLASH-SALE',
160
+ * name: 'Flash Sale - 30% Off',
161
+ * creative: 'hero-banner',
162
+ * position: 'homepage-top'
163
+ * });
164
+ *
165
+ * // Track banner click
166
+ * await promotions.click({
167
+ * promotionId: 'FLASH-SALE',
168
+ * name: 'Flash Sale - 30% Off',
169
+ * destinationUrl: '/sale'
170
+ * });
171
+ * ```
172
+ */
173
+ export declare class Promotions extends FTRPC {
174
+ /**
175
+ * Tracks promotion view/impression.
176
+ *
177
+ * @param config - Promotion view configuration
178
+ * @returns Promise resolving to promotion response
179
+ *
180
+ * @example
181
+ * ```typescript
182
+ * await promotions.view({
183
+ * promotionId: 'SUMMER-2026',
184
+ * name: 'Summer Collection Launch',
185
+ * creative: 'collection-banner',
186
+ * position: 'homepage-hero',
187
+ * page: '/home'
188
+ * });
189
+ * ```
190
+ */
191
+ view(config: PromotionViewConfig): Promise<PromotionResponse>;
192
+ /**
193
+ * Tracks promotion click.
194
+ *
195
+ * @param config - Promotion click configuration
196
+ * @returns Promise resolving to promotion response
197
+ *
198
+ * @example
199
+ * ```typescript
200
+ * await promotions.click({
201
+ * promotionId: 'SUMMER-2026',
202
+ * name: 'Summer Collection Launch',
203
+ * destinationUrl: '/collections/summer-2026'
204
+ * });
205
+ * ```
206
+ */
207
+ click(config: PromotionClickConfig): Promise<PromotionResponse>;
208
+ /**
209
+ * Tracks successful coupon usage.
210
+ *
211
+ * @param config - Coupon usage configuration
212
+ * @returns Promise resolving to coupon response
213
+ *
214
+ * @example
215
+ * ```typescript
216
+ * await promotions.couponUsed({
217
+ * code: 'SAVE20',
218
+ * orderId: 'ORD-12345',
219
+ * discountValue: 20,
220
+ * discountType: 'percentage',
221
+ * orderValueBefore: 100,
222
+ * orderValueAfter: 80
223
+ * });
224
+ * ```
225
+ */
226
+ couponUsed(config: CouponUsageConfig): Promise<PromotionResponse>;
227
+ /**
228
+ * Tracks coupon application attempt (including failures).
229
+ *
230
+ * @param code - Coupon code attempted
231
+ * @param success - Whether coupon was valid
232
+ * @param failureReason - Reason for failure (if failed)
233
+ * @returns Promise resolving to attempt response
234
+ */
235
+ couponAttempt(code: string, success: boolean, failureReason?: 'expired' | 'invalid' | 'minimum_not_met' | 'already_used' | 'not_applicable'): Promise<PromotionResponse>;
236
+ /**
237
+ * Retrieves promotion analytics for dashboards and charts.
238
+ *
239
+ * @param filter - Date range filter
240
+ * @returns Promise resolving to promotion analytics
241
+ *
242
+ * @example
243
+ * ```typescript
244
+ * const analytics = await promotions.getAnalytics({
245
+ * range: 'last30days'
246
+ * });
247
+ *
248
+ * // Bar chart - top promotions
249
+ * const topPromoChart = analytics.topPromotions.map(p => ({
250
+ * name: p.name,
251
+ * value: p.revenue
252
+ * }));
253
+ *
254
+ * // Table - coupon performance
255
+ * const couponTable = analytics.coupons;
256
+ *
257
+ * // Pie chart - promoted vs non-promoted revenue
258
+ * const revenuePie = [
259
+ * { name: 'Promoted', value: analytics.revenueImpact.promotedRevenue.amount },
260
+ * { name: 'Non-Promoted', value: analytics.revenueImpact.nonPromotedRevenue.amount }
261
+ * ];
262
+ * ```
263
+ */
264
+ getAnalytics(filter?: DateRangeFilter): Promise<PromotionAnalyticsData>;
265
+ }
266
+ export default Promotions;
@@ -0,0 +1,287 @@
1
+ /**
2
+ * @fileoverview Ecommerce - Purchase/Transaction Tracking
3
+ * @module features/ecommerce/purchases
4
+ *
5
+ * @description
6
+ * Track completed purchases, transactions, and revenue with
7
+ * full order details and customer information.
8
+ *
9
+ * @useCases
10
+ * - Track completed purchases
11
+ * - Calculate revenue metrics
12
+ * - Monitor order values
13
+ * - Analyze purchase patterns
14
+ * - Track customer lifetime value
15
+ *
16
+ * @metrics
17
+ * - Total revenue
18
+ * - Number of orders
19
+ * - Average order value
20
+ * - Revenue per customer
21
+ * - Items per order
22
+ *
23
+ * @chartData
24
+ * - Line chart: Revenue over time
25
+ * - Bar chart: Revenue by product/category
26
+ * - KPI cards: Revenue, AOV, Orders
27
+ * - Table: Recent transactions
28
+ *
29
+ * @example
30
+ * ```typescript
31
+ * const purchases = new Purchases(webId, endpoint, apiKey);
32
+ *
33
+ * // Track a purchase
34
+ * await purchases.track({
35
+ * order: {
36
+ * orderId: 'ORD-12345',
37
+ * items: orderItems,
38
+ * total: 299.99,
39
+ * currency: 'USD'
40
+ * }
41
+ * });
42
+ * ```
43
+ */
44
+ import { FTRPC } from "../../client/ftrpc";
45
+ import { Order, ShippingInfo, MoneyValue, DateRangeFilter, TimeSeriesData, PaginationParams } from "../../types";
46
+ /**
47
+ * Configuration for tracking a purchase.
48
+ */
49
+ export interface PurchaseConfig {
50
+ /** Order details */
51
+ order: Order;
52
+ /** User ID */
53
+ userId?: string;
54
+ /** Session ID */
55
+ sessionId?: string;
56
+ /** Attribution data */
57
+ attribution?: {
58
+ source?: string;
59
+ medium?: string;
60
+ campaign?: string;
61
+ affiliate?: string;
62
+ };
63
+ /** Custom properties */
64
+ properties?: Record<string, unknown>;
65
+ }
66
+ /**
67
+ * Purchase event response from API.
68
+ */
69
+ export interface PurchaseResponse {
70
+ eventName: string;
71
+ properties: Record<string, unknown>;
72
+ response: {
73
+ orderId: string;
74
+ tracked: boolean;
75
+ revenue: number;
76
+ isFirstPurchase: boolean;
77
+ };
78
+ timestamp: string;
79
+ }
80
+ /**
81
+ * Revenue analytics data for charts.
82
+ */
83
+ export interface RevenueAnalyticsData {
84
+ /** Revenue summary */
85
+ summary: {
86
+ totalRevenue: MoneyValue;
87
+ netRevenue: MoneyValue;
88
+ totalOrders: number;
89
+ averageOrderValue: MoneyValue;
90
+ itemsSold: number;
91
+ uniqueCustomers: number;
92
+ repeatPurchaseRate: number;
93
+ };
94
+ /** Revenue time series */
95
+ revenueTimeSeries: TimeSeriesData;
96
+ /** Orders time series */
97
+ ordersTimeSeries: TimeSeriesData;
98
+ /** Revenue by category */
99
+ byCategory: Array<{
100
+ category: string;
101
+ revenue: number;
102
+ orders: number;
103
+ percentage: number;
104
+ }>;
105
+ /** Revenue by product */
106
+ byProduct: Array<{
107
+ productId: string;
108
+ productName: string;
109
+ revenue: number;
110
+ unitsSold: number;
111
+ }>;
112
+ /** Revenue by geography */
113
+ byCountry: Array<{
114
+ country: string;
115
+ revenue: number;
116
+ orders: number;
117
+ }>;
118
+ /** Customer segments */
119
+ customerSegments: Array<{
120
+ segment: 'new' | 'returning' | 'vip';
121
+ customers: number;
122
+ revenue: number;
123
+ avgOrderValue: number;
124
+ }>;
125
+ }
126
+ /**
127
+ * Recent orders data.
128
+ */
129
+ export interface RecentOrdersData {
130
+ orders: Array<{
131
+ orderId: string;
132
+ total: MoneyValue;
133
+ itemCount: number;
134
+ status: string;
135
+ createdAt: string;
136
+ customer?: {
137
+ userId: string;
138
+ isNew: boolean;
139
+ };
140
+ }>;
141
+ pagination: {
142
+ page: number;
143
+ limit: number;
144
+ total: number;
145
+ hasMore: boolean;
146
+ };
147
+ }
148
+ /**
149
+ * Purchases - Track completed purchases and revenue.
150
+ *
151
+ * @extends FTRPC
152
+ *
153
+ * @description
154
+ * Provides purchase tracking capabilities including:
155
+ * - Purchase completion events
156
+ * - Revenue tracking
157
+ * - Order details capture
158
+ * - Customer LTV tracking
159
+ * - Attribution tracking
160
+ *
161
+ * @example
162
+ * ```typescript
163
+ * const purchases = new Purchases(webId, endpoint, apiKey);
164
+ *
165
+ * // Track completed purchase
166
+ * await purchases.track({
167
+ * order: {
168
+ * orderId: 'ORD-12345',
169
+ * items: cartItems,
170
+ * subtotal: 279.99,
171
+ * discountTotal: 30.00,
172
+ * shippingTotal: 9.99,
173
+ * taxTotal: 26.00,
174
+ * total: 285.98,
175
+ * currency: 'USD',
176
+ * shipping: { method: 'express', cost: 9.99 },
177
+ * payment: { method: 'credit_card' }
178
+ * },
179
+ * userId: 'user_123'
180
+ * });
181
+ *
182
+ * // Get revenue analytics
183
+ * const revenue = await purchases.getRevenue({ range: 'thisMonth' });
184
+ * ```
185
+ */
186
+ export declare class Purchases extends FTRPC {
187
+ /**
188
+ * Tracks a completed purchase.
189
+ *
190
+ * @param config - Purchase configuration
191
+ * @returns Promise resolving to purchase response
192
+ *
193
+ * @example
194
+ * ```typescript
195
+ * await purchases.track({
196
+ * order: {
197
+ * orderId: 'ORD-98765',
198
+ * items: [
199
+ * { productId: 'PROD-1', name: 'Widget', price: 29.99, quantity: 2, lineTotal: 59.98 }
200
+ * ],
201
+ * subtotal: 59.98,
202
+ * discountTotal: 0,
203
+ * shippingTotal: 5.99,
204
+ * taxTotal: 5.40,
205
+ * total: 71.37,
206
+ * currency: 'USD'
207
+ * },
208
+ * attribution: {
209
+ * source: 'google',
210
+ * medium: 'cpc',
211
+ * campaign: 'spring_sale'
212
+ * }
213
+ * });
214
+ * ```
215
+ */
216
+ track(config: PurchaseConfig): Promise<PurchaseResponse>;
217
+ /**
218
+ * Tracks order status change.
219
+ *
220
+ * @param orderId - Order identifier
221
+ * @param newStatus - New order status
222
+ * @param previousStatus - Previous status (optional)
223
+ * @returns Promise resolving to status change response
224
+ */
225
+ statusChange(orderId: string, newStatus: Order['status'], previousStatus?: Order['status']): Promise<PurchaseResponse>;
226
+ /**
227
+ * Tracks order shipped event.
228
+ *
229
+ * @param orderId - Order identifier
230
+ * @param shipping - Shipping details with tracking
231
+ * @returns Promise resolving to shipped response
232
+ */
233
+ shipped(orderId: string, shipping: ShippingInfo): Promise<PurchaseResponse>;
234
+ /**
235
+ * Tracks order delivered event.
236
+ *
237
+ * @param orderId - Order identifier
238
+ * @param deliveredAt - Delivery timestamp
239
+ * @returns Promise resolving to delivered response
240
+ */
241
+ delivered(orderId: string, deliveredAt?: string): Promise<PurchaseResponse>;
242
+ /**
243
+ * Retrieves revenue analytics for dashboards and charts.
244
+ *
245
+ * @param filter - Date range filter
246
+ * @returns Promise resolving to revenue analytics
247
+ *
248
+ * @example
249
+ * ```typescript
250
+ * const revenue = await purchases.getRevenue({
251
+ * range: 'last30days'
252
+ * });
253
+ *
254
+ * // KPI cards
255
+ * const kpis = [
256
+ * { label: 'Revenue', value: revenue.summary.totalRevenue.amount },
257
+ * { label: 'Orders', value: revenue.summary.totalOrders },
258
+ * { label: 'AOV', value: revenue.summary.averageOrderValue.amount }
259
+ * ];
260
+ *
261
+ * // Revenue chart
262
+ * const revenueChart = revenue.revenueTimeSeries.data;
263
+ *
264
+ * // Category breakdown
265
+ * const categoryPie = revenue.byCategory.map(c => ({
266
+ * name: c.category,
267
+ * value: c.revenue
268
+ * }));
269
+ * ```
270
+ */
271
+ getRevenue(filter?: DateRangeFilter): Promise<RevenueAnalyticsData>;
272
+ /**
273
+ * Gets recent orders for display.
274
+ *
275
+ * @param pagination - Pagination options
276
+ * @returns Promise resolving to recent orders
277
+ */
278
+ getRecentOrders(pagination?: PaginationParams): Promise<RecentOrdersData>;
279
+ /**
280
+ * Gets order details by ID.
281
+ *
282
+ * @param orderId - Order identifier
283
+ * @returns Promise resolving to order details
284
+ */
285
+ getOrder(orderId: string): Promise<Order>;
286
+ }
287
+ export default Purchases;