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.
- package/LICENSE +21 -0
- package/dist/browser.d.ts +119 -0
- package/dist/flowgrid.min.js +2 -0
- package/dist/flowgrid.min.js.map +1 -0
- package/dist/index.d.ts +44 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/client/enterprise-ftrpc.d.ts +51 -0
- package/dist/lib/client/ftrpc.d.ts +43 -0
- package/dist/lib/client/modules.d.ts +104 -0
- package/dist/lib/features/analytics/attribution.d.ts +257 -0
- package/dist/lib/features/analytics/events.d.ts +304 -0
- package/dist/lib/features/analytics/funnels.d.ts +291 -0
- package/dist/lib/features/analytics/heatmaps.d.ts +247 -0
- package/dist/lib/features/analytics/identify.d.ts +273 -0
- package/dist/lib/features/analytics/index.d.ts +22 -0
- package/dist/lib/features/analytics/page-views.d.ts +250 -0
- package/dist/lib/features/analytics/performance.d.ts +281 -0
- package/dist/lib/features/analytics/retention.d.ts +294 -0
- package/dist/lib/features/analytics/sessions.d.ts +277 -0
- package/dist/lib/features/core/activation.d.ts +239 -0
- package/dist/lib/features/core/experiment.d.ts +286 -0
- package/dist/lib/features/core/feature-flag.d.ts +264 -0
- package/dist/lib/features/core/index.d.ts +14 -0
- package/dist/lib/features/core/track-feature.d.ts +220 -0
- package/dist/lib/features/core/track-prompt.d.ts +247 -0
- package/dist/lib/features/ecommerce/cart.d.ts +298 -0
- package/dist/lib/features/ecommerce/checkout.d.ts +324 -0
- package/dist/lib/features/ecommerce/index.d.ts +26 -0
- package/dist/lib/features/ecommerce/inventory.d.ts +221 -0
- package/dist/lib/features/ecommerce/ltv.d.ts +258 -0
- package/dist/lib/features/ecommerce/products.d.ts +268 -0
- package/dist/lib/features/ecommerce/promotions.d.ts +266 -0
- package/dist/lib/features/ecommerce/purchases.d.ts +287 -0
- package/dist/lib/features/ecommerce/refunds.d.ts +232 -0
- package/dist/lib/features/ecommerce/search.d.ts +225 -0
- package/dist/lib/features/ecommerce/subscriptions.d.ts +281 -0
- package/dist/lib/features/ecommerce/wishlist.d.ts +236 -0
- package/dist/lib/features/enterprise/acquisition.d.ts +373 -0
- package/dist/lib/features/enterprise/alerts.d.ts +348 -0
- package/dist/lib/features/enterprise/churn.d.ts +288 -0
- package/dist/lib/features/enterprise/cohorts.d.ts +270 -0
- package/dist/lib/features/enterprise/engagement.d.ts +233 -0
- package/dist/lib/features/enterprise/forecasting.d.ts +351 -0
- package/dist/lib/features/enterprise/index.d.ts +20 -0
- package/dist/lib/features/enterprise/monetization.d.ts +356 -0
- package/dist/lib/features/enterprise/multi-path-funnels.d.ts +327 -0
- package/dist/lib/features/enterprise/paths.d.ts +332 -0
- package/dist/lib/features/enterprise/security.d.ts +387 -0
- package/dist/lib/features/enterprise/support.d.ts +329 -0
- package/dist/lib/frameworks/index.d.ts +9 -0
- package/dist/lib/frameworks/nextjs/client.d.ts +208 -0
- package/dist/lib/frameworks/nextjs/index.d.ts +29 -0
- package/dist/lib/frameworks/nextjs/server.d.ts +201 -0
- package/dist/lib/frameworks/node/index.d.ts +265 -0
- package/dist/lib/frameworks/nuxt/index.d.ts +190 -0
- package/dist/lib/frameworks/react/index.d.ts +245 -0
- package/dist/lib/frameworks/vue/index.d.ts +275 -0
- package/dist/lib/types/analytics.d.ts +365 -0
- package/dist/lib/types/common.d.ts +230 -0
- package/dist/lib/types/ecommerce.d.ts +309 -0
- package/dist/lib/types/index.d.ts +7 -0
- package/dist/lib/utils/functions.d.ts +1 -0
- package/package.json +139 -0
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Ecommerce - Checkout Tracking
|
|
3
|
+
* @module features/ecommerce/checkout
|
|
4
|
+
*
|
|
5
|
+
* @description
|
|
6
|
+
* Track checkout flow progress, payment attempts, and checkout
|
|
7
|
+
* optimization opportunities.
|
|
8
|
+
*
|
|
9
|
+
* @useCases
|
|
10
|
+
* - Track checkout step progression
|
|
11
|
+
* - Identify checkout drop-off points
|
|
12
|
+
* - Monitor payment success rates
|
|
13
|
+
* - Analyze shipping method preferences
|
|
14
|
+
* - Optimize checkout UX
|
|
15
|
+
*
|
|
16
|
+
* @metrics
|
|
17
|
+
* - Checkout initiation rate
|
|
18
|
+
* - Step completion rates
|
|
19
|
+
* - Payment success rate
|
|
20
|
+
* - Checkout abandonment rate
|
|
21
|
+
* - Average time to complete
|
|
22
|
+
*
|
|
23
|
+
* @chartData
|
|
24
|
+
* - Funnel chart: Checkout steps
|
|
25
|
+
* - Bar chart: Abandonment by step
|
|
26
|
+
* - Pie chart: Payment methods
|
|
27
|
+
* - Line chart: Checkout completions over time
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* const checkout = new Checkout(webId, endpoint, apiKey);
|
|
32
|
+
*
|
|
33
|
+
* // Begin checkout
|
|
34
|
+
* await checkout.begin({
|
|
35
|
+
* cart: shoppingCart,
|
|
36
|
+
* userId: 'user_123'
|
|
37
|
+
* });
|
|
38
|
+
*
|
|
39
|
+
* // Track step progress
|
|
40
|
+
* await checkout.step({
|
|
41
|
+
* step: 'add_payment_info',
|
|
42
|
+
* stepNumber: 3,
|
|
43
|
+
* cart: shoppingCart
|
|
44
|
+
* });
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
import { FTRPC } from "../../client/ftrpc";
|
|
48
|
+
import { Cart, CheckoutStep, ShippingInfo, PaymentInfo, DateRangeFilter, TimeSeriesData } from "../../types";
|
|
49
|
+
/**
|
|
50
|
+
* Configuration for beginning checkout.
|
|
51
|
+
*/
|
|
52
|
+
export interface BeginCheckoutConfig {
|
|
53
|
+
/** Cart being checked out */
|
|
54
|
+
cart: Cart;
|
|
55
|
+
/** User ID */
|
|
56
|
+
userId?: string;
|
|
57
|
+
/** Session ID */
|
|
58
|
+
sessionId?: string;
|
|
59
|
+
/** Custom properties */
|
|
60
|
+
properties?: Record<string, unknown>;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Configuration for tracking checkout step.
|
|
64
|
+
*/
|
|
65
|
+
export interface CheckoutStepConfig {
|
|
66
|
+
/** Checkout step */
|
|
67
|
+
step: CheckoutStep;
|
|
68
|
+
/** Step number */
|
|
69
|
+
stepNumber: number;
|
|
70
|
+
/** Cart state at this step */
|
|
71
|
+
cart: Cart;
|
|
72
|
+
/** Option selected at this step (e.g., shipping method) */
|
|
73
|
+
option?: string;
|
|
74
|
+
/** User ID */
|
|
75
|
+
userId?: string;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Configuration for adding shipping info.
|
|
79
|
+
*/
|
|
80
|
+
export interface AddShippingConfig {
|
|
81
|
+
/** Cart being checked out */
|
|
82
|
+
cart: Cart;
|
|
83
|
+
/** Shipping information */
|
|
84
|
+
shipping: ShippingInfo;
|
|
85
|
+
/** User ID */
|
|
86
|
+
userId?: string;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Configuration for adding payment info.
|
|
90
|
+
*/
|
|
91
|
+
export interface AddPaymentConfig {
|
|
92
|
+
/** Cart being checked out */
|
|
93
|
+
cart: Cart;
|
|
94
|
+
/** Payment information (non-sensitive) */
|
|
95
|
+
payment: PaymentInfo;
|
|
96
|
+
/** User ID */
|
|
97
|
+
userId?: string;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Checkout event response from API.
|
|
101
|
+
*/
|
|
102
|
+
export interface CheckoutResponse {
|
|
103
|
+
eventName: string;
|
|
104
|
+
properties: Record<string, unknown>;
|
|
105
|
+
response: {
|
|
106
|
+
checkoutId: string;
|
|
107
|
+
step: string;
|
|
108
|
+
tracked: boolean;
|
|
109
|
+
};
|
|
110
|
+
timestamp: string;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Checkout analytics data for charts.
|
|
114
|
+
*/
|
|
115
|
+
export interface CheckoutAnalyticsData {
|
|
116
|
+
/** Checkout funnel data */
|
|
117
|
+
funnel: Array<{
|
|
118
|
+
step: CheckoutStep;
|
|
119
|
+
stepNumber: number;
|
|
120
|
+
started: number;
|
|
121
|
+
completed: number;
|
|
122
|
+
conversionRate: number;
|
|
123
|
+
dropOffRate: number;
|
|
124
|
+
avgTimeToComplete: number;
|
|
125
|
+
}>;
|
|
126
|
+
/** Summary metrics */
|
|
127
|
+
summary: {
|
|
128
|
+
checkoutsStarted: number;
|
|
129
|
+
checkoutsCompleted: number;
|
|
130
|
+
overallConversionRate: number;
|
|
131
|
+
avgCheckoutTime: number;
|
|
132
|
+
avgOrderValue: number;
|
|
133
|
+
abandonmentRate: number;
|
|
134
|
+
};
|
|
135
|
+
/** Checkouts over time */
|
|
136
|
+
timeSeries: TimeSeriesData;
|
|
137
|
+
/** Shipping methods used */
|
|
138
|
+
shippingMethods: Array<{
|
|
139
|
+
method: string;
|
|
140
|
+
count: number;
|
|
141
|
+
percentage: number;
|
|
142
|
+
avgShippingCost: number;
|
|
143
|
+
}>;
|
|
144
|
+
/** Payment methods used */
|
|
145
|
+
paymentMethods: Array<{
|
|
146
|
+
method: string;
|
|
147
|
+
count: number;
|
|
148
|
+
percentage: number;
|
|
149
|
+
successRate: number;
|
|
150
|
+
}>;
|
|
151
|
+
/** Abandonment analysis */
|
|
152
|
+
abandonmentByStep: Array<{
|
|
153
|
+
step: CheckoutStep;
|
|
154
|
+
abandonments: number;
|
|
155
|
+
percentage: number;
|
|
156
|
+
avgCartValue: number;
|
|
157
|
+
}>;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Checkout - Track checkout flow and payments.
|
|
161
|
+
*
|
|
162
|
+
* @extends FTRPC
|
|
163
|
+
*
|
|
164
|
+
* @description
|
|
165
|
+
* Provides checkout tracking capabilities including:
|
|
166
|
+
* - Checkout initiation
|
|
167
|
+
* - Step-by-step progress
|
|
168
|
+
* - Shipping info capture
|
|
169
|
+
* - Payment info capture
|
|
170
|
+
* - Checkout abandonment
|
|
171
|
+
*
|
|
172
|
+
* @example
|
|
173
|
+
* ```typescript
|
|
174
|
+
* const checkout = new Checkout(webId, endpoint, apiKey);
|
|
175
|
+
*
|
|
176
|
+
* // Start checkout
|
|
177
|
+
* await checkout.begin({ cart: shoppingCart });
|
|
178
|
+
*
|
|
179
|
+
* // Track shipping step
|
|
180
|
+
* await checkout.addShipping({
|
|
181
|
+
* cart: shoppingCart,
|
|
182
|
+
* shipping: {
|
|
183
|
+
* method: 'express',
|
|
184
|
+
* carrier: 'FedEx',
|
|
185
|
+
* cost: 9.99
|
|
186
|
+
* }
|
|
187
|
+
* });
|
|
188
|
+
*
|
|
189
|
+
* // Track payment step
|
|
190
|
+
* await checkout.addPayment({
|
|
191
|
+
* cart: shoppingCart,
|
|
192
|
+
* payment: {
|
|
193
|
+
* method: 'credit_card',
|
|
194
|
+
* cardBrand: 'Visa'
|
|
195
|
+
* }
|
|
196
|
+
* });
|
|
197
|
+
* ```
|
|
198
|
+
*/
|
|
199
|
+
export declare class Checkout extends FTRPC {
|
|
200
|
+
/**
|
|
201
|
+
* Tracks checkout initiation.
|
|
202
|
+
*
|
|
203
|
+
* @param config - Begin checkout configuration
|
|
204
|
+
* @returns Promise resolving to checkout response
|
|
205
|
+
*
|
|
206
|
+
* @example
|
|
207
|
+
* ```typescript
|
|
208
|
+
* await checkout.begin({
|
|
209
|
+
* cart: {
|
|
210
|
+
* cartId: 'cart_123',
|
|
211
|
+
* items: cartItems,
|
|
212
|
+
* total: 199.99,
|
|
213
|
+
* currency: 'USD',
|
|
214
|
+
* itemCount: 3
|
|
215
|
+
* }
|
|
216
|
+
* });
|
|
217
|
+
* ```
|
|
218
|
+
*/
|
|
219
|
+
begin(config: BeginCheckoutConfig): Promise<CheckoutResponse>;
|
|
220
|
+
/**
|
|
221
|
+
* Tracks checkout step progress.
|
|
222
|
+
*
|
|
223
|
+
* @param config - Checkout step configuration
|
|
224
|
+
* @returns Promise resolving to checkout response
|
|
225
|
+
*
|
|
226
|
+
* @example
|
|
227
|
+
* ```typescript
|
|
228
|
+
* await checkout.step({
|
|
229
|
+
* step: 'add_shipping_info',
|
|
230
|
+
* stepNumber: 2,
|
|
231
|
+
* cart: shoppingCart,
|
|
232
|
+
* option: 'express_shipping'
|
|
233
|
+
* });
|
|
234
|
+
* ```
|
|
235
|
+
*/
|
|
236
|
+
step(config: CheckoutStepConfig): Promise<CheckoutResponse>;
|
|
237
|
+
/**
|
|
238
|
+
* Tracks adding shipping information.
|
|
239
|
+
*
|
|
240
|
+
* @param config - Shipping info configuration
|
|
241
|
+
* @returns Promise resolving to checkout response
|
|
242
|
+
*
|
|
243
|
+
* @example
|
|
244
|
+
* ```typescript
|
|
245
|
+
* await checkout.addShipping({
|
|
246
|
+
* cart: shoppingCart,
|
|
247
|
+
* shipping: {
|
|
248
|
+
* method: 'standard',
|
|
249
|
+
* carrier: 'USPS',
|
|
250
|
+
* cost: 5.99,
|
|
251
|
+
* estimatedDelivery: '2026-02-07'
|
|
252
|
+
* }
|
|
253
|
+
* });
|
|
254
|
+
* ```
|
|
255
|
+
*/
|
|
256
|
+
addShipping(config: AddShippingConfig): Promise<CheckoutResponse>;
|
|
257
|
+
/**
|
|
258
|
+
* Tracks adding payment information.
|
|
259
|
+
*
|
|
260
|
+
* @param config - Payment info configuration
|
|
261
|
+
* @returns Promise resolving to checkout response
|
|
262
|
+
*
|
|
263
|
+
* @example
|
|
264
|
+
* ```typescript
|
|
265
|
+
* await checkout.addPayment({
|
|
266
|
+
* cart: shoppingCart,
|
|
267
|
+
* payment: {
|
|
268
|
+
* method: 'credit_card',
|
|
269
|
+
* provider: 'Stripe',
|
|
270
|
+
* cardBrand: 'Mastercard',
|
|
271
|
+
* cardLast4: '4242'
|
|
272
|
+
* }
|
|
273
|
+
* });
|
|
274
|
+
* ```
|
|
275
|
+
*/
|
|
276
|
+
addPayment(config: AddPaymentConfig): Promise<CheckoutResponse>;
|
|
277
|
+
/**
|
|
278
|
+
* Tracks checkout abandonment.
|
|
279
|
+
*
|
|
280
|
+
* @param cart - Cart at abandonment
|
|
281
|
+
* @param step - Last completed step
|
|
282
|
+
* @param reason - Abandonment reason (if known)
|
|
283
|
+
* @returns Promise resolving to checkout response
|
|
284
|
+
*/
|
|
285
|
+
abandon(cart: Cart, step: CheckoutStep, reason?: string): Promise<CheckoutResponse>;
|
|
286
|
+
/**
|
|
287
|
+
* Tracks payment attempt (success or failure).
|
|
288
|
+
*
|
|
289
|
+
* @param success - Whether payment succeeded
|
|
290
|
+
* @param cart - Cart being paid for
|
|
291
|
+
* @param payment - Payment information
|
|
292
|
+
* @param errorCode - Error code (if failed)
|
|
293
|
+
* @returns Promise resolving to checkout response
|
|
294
|
+
*/
|
|
295
|
+
paymentAttempt(success: boolean, cart: Cart, payment: PaymentInfo, errorCode?: string): Promise<CheckoutResponse>;
|
|
296
|
+
/**
|
|
297
|
+
* Retrieves checkout analytics data for dashboards and charts.
|
|
298
|
+
*
|
|
299
|
+
* @param filter - Date range filter
|
|
300
|
+
* @returns Promise resolving to checkout analytics
|
|
301
|
+
*
|
|
302
|
+
* @example
|
|
303
|
+
* ```typescript
|
|
304
|
+
* const analytics = await checkout.getAnalytics({
|
|
305
|
+
* range: 'last30days'
|
|
306
|
+
* });
|
|
307
|
+
*
|
|
308
|
+
* // Funnel chart
|
|
309
|
+
* const funnelData = analytics.funnel.map(step => ({
|
|
310
|
+
* name: step.step,
|
|
311
|
+
* value: step.started,
|
|
312
|
+
* conversion: step.conversionRate
|
|
313
|
+
* }));
|
|
314
|
+
*
|
|
315
|
+
* // Pie chart - payment methods
|
|
316
|
+
* const paymentData = analytics.paymentMethods.map(p => ({
|
|
317
|
+
* name: p.method,
|
|
318
|
+
* value: p.count
|
|
319
|
+
* }));
|
|
320
|
+
* ```
|
|
321
|
+
*/
|
|
322
|
+
getAnalytics(filter?: DateRangeFilter): Promise<CheckoutAnalyticsData>;
|
|
323
|
+
}
|
|
324
|
+
export default Checkout;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Ecommerce features barrel export
|
|
3
|
+
* @module features/ecommerce
|
|
4
|
+
*/
|
|
5
|
+
export { Products } from './products';
|
|
6
|
+
export { CartTracking } from './cart';
|
|
7
|
+
export { Checkout } from './checkout';
|
|
8
|
+
export { Purchases } from './purchases';
|
|
9
|
+
export { Refunds } from './refunds';
|
|
10
|
+
export { Promotions } from './promotions';
|
|
11
|
+
export { WishlistTracking } from './wishlist';
|
|
12
|
+
export { CustomerLTV } from './ltv';
|
|
13
|
+
export { SearchAnalytics } from './search';
|
|
14
|
+
export { Inventory } from './inventory';
|
|
15
|
+
export { Subscriptions } from './subscriptions';
|
|
16
|
+
export type { ProductViewConfig, ProductImpressionConfig, ProductClickConfig, ProductResponse, ProductAnalyticsData } from './products';
|
|
17
|
+
export type { AddToCartConfig, RemoveFromCartConfig, UpdateCartItemConfig, ViewCartConfig, CartResponse, CartAnalyticsData } from './cart';
|
|
18
|
+
export type { BeginCheckoutConfig, CheckoutStepConfig, AddShippingConfig, AddPaymentConfig, CheckoutResponse, CheckoutAnalyticsData } from './checkout';
|
|
19
|
+
export type { PurchaseConfig, PurchaseResponse, RevenueAnalyticsData, RecentOrdersData } from './purchases';
|
|
20
|
+
export type { RefundConfig, RefundResponse, RefundAnalyticsData } from './refunds';
|
|
21
|
+
export type { PromotionViewConfig, PromotionClickConfig, CouponUsageConfig, PromotionResponse, PromotionAnalyticsData } from './promotions';
|
|
22
|
+
export type { AddToWishlistConfig, RemoveFromWishlistConfig, WishlistResponse, WishlistAnalyticsData } from './wishlist';
|
|
23
|
+
export type { CustomerValueData, AcquisitionCostConfig, LTVResponse, LTVAnalyticsData } from './ltv';
|
|
24
|
+
export type { SearchConfig, SearchClickConfig, SearchResponse, SearchAnalyticsData } from './search';
|
|
25
|
+
export type { StockUpdateConfig, OutOfStockConfig, InventoryResponse, InventoryAnalyticsData } from './inventory';
|
|
26
|
+
export type { SubscriptionStartConfig, SubscriptionChangeConfig, SubscriptionCancelConfig, SubscriptionResponse, SubscriptionAnalyticsData } from './subscriptions';
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Ecommerce - Inventory Tracking
|
|
3
|
+
* @module features/ecommerce/inventory
|
|
4
|
+
*
|
|
5
|
+
* @description
|
|
6
|
+
* Track inventory-related events for stock management insights
|
|
7
|
+
* and demand forecasting.
|
|
8
|
+
*
|
|
9
|
+
* @useCases
|
|
10
|
+
* - Track stock level changes
|
|
11
|
+
* - Monitor out-of-stock events
|
|
12
|
+
* - Analyze demand patterns
|
|
13
|
+
* - Track restock events
|
|
14
|
+
* - Correlate stock with lost sales
|
|
15
|
+
*
|
|
16
|
+
* @metrics
|
|
17
|
+
* - Out-of-stock rate
|
|
18
|
+
* - Stock turnover
|
|
19
|
+
* - Demand vs supply
|
|
20
|
+
* - Lost sales from stockouts
|
|
21
|
+
* - Restock frequency
|
|
22
|
+
*
|
|
23
|
+
* @chartData
|
|
24
|
+
* - Line chart: Stock levels over time
|
|
25
|
+
* - Bar chart: Products with low stock
|
|
26
|
+
* - Alert table: Out-of-stock products
|
|
27
|
+
* - Heatmap: Demand by product/time
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* const inventory = new Inventory(webId, endpoint, apiKey);
|
|
32
|
+
*
|
|
33
|
+
* // Track stock update
|
|
34
|
+
* await inventory.updateStock({
|
|
35
|
+
* productId: 'PROD-123',
|
|
36
|
+
* previousStock: 50,
|
|
37
|
+
* newStock: 45,
|
|
38
|
+
* reason: 'sale'
|
|
39
|
+
* });
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
import { FTRPC } from "../../client/ftrpc";
|
|
43
|
+
import { DateRangeFilter, TimeSeriesData } from "../../types";
|
|
44
|
+
/**
|
|
45
|
+
* Stock update configuration.
|
|
46
|
+
*/
|
|
47
|
+
export interface StockUpdateConfig {
|
|
48
|
+
/** Product ID */
|
|
49
|
+
productId: string;
|
|
50
|
+
/** Product name */
|
|
51
|
+
productName?: string;
|
|
52
|
+
/** Stock before change */
|
|
53
|
+
previousStock: number;
|
|
54
|
+
/** Stock after change */
|
|
55
|
+
newStock: number;
|
|
56
|
+
/** Reason for change */
|
|
57
|
+
reason: 'sale' | 'restock' | 'return' | 'adjustment' | 'damage' | 'transfer';
|
|
58
|
+
/** Location/warehouse */
|
|
59
|
+
location?: string;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Out-of-stock event configuration.
|
|
63
|
+
*/
|
|
64
|
+
export interface OutOfStockConfig {
|
|
65
|
+
/** Product ID */
|
|
66
|
+
productId: string;
|
|
67
|
+
/** Product name */
|
|
68
|
+
productName?: string;
|
|
69
|
+
/** Whether there was demand (user tried to buy) */
|
|
70
|
+
hadDemand: boolean;
|
|
71
|
+
/** Number of users who viewed while out of stock */
|
|
72
|
+
viewsWhileOOS?: number;
|
|
73
|
+
/** Expected restock date */
|
|
74
|
+
expectedRestock?: string;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Inventory response from API.
|
|
78
|
+
*/
|
|
79
|
+
export interface InventoryResponse {
|
|
80
|
+
eventName: string;
|
|
81
|
+
properties: Record<string, unknown>;
|
|
82
|
+
response: {
|
|
83
|
+
productId: string;
|
|
84
|
+
tracked: boolean;
|
|
85
|
+
currentStock: number;
|
|
86
|
+
};
|
|
87
|
+
timestamp: string;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Inventory analytics data.
|
|
91
|
+
*/
|
|
92
|
+
export interface InventoryAnalyticsData {
|
|
93
|
+
/** Summary metrics */
|
|
94
|
+
summary: {
|
|
95
|
+
totalProducts: number;
|
|
96
|
+
inStockProducts: number;
|
|
97
|
+
outOfStockProducts: number;
|
|
98
|
+
lowStockProducts: number;
|
|
99
|
+
outOfStockRate: number;
|
|
100
|
+
avgStockLevel: number;
|
|
101
|
+
estimatedLostSales: number;
|
|
102
|
+
};
|
|
103
|
+
/** Out of stock products */
|
|
104
|
+
outOfStock: Array<{
|
|
105
|
+
productId: string;
|
|
106
|
+
productName: string;
|
|
107
|
+
daysSinceOOS: number;
|
|
108
|
+
demandWhileOOS: number;
|
|
109
|
+
estimatedLostRevenue: number;
|
|
110
|
+
}>;
|
|
111
|
+
/** Low stock alerts */
|
|
112
|
+
lowStock: Array<{
|
|
113
|
+
productId: string;
|
|
114
|
+
productName: string;
|
|
115
|
+
currentStock: number;
|
|
116
|
+
reorderPoint: number;
|
|
117
|
+
avgDailySales: number;
|
|
118
|
+
daysOfStockLeft: number;
|
|
119
|
+
}>;
|
|
120
|
+
/** Stock turnover by product */
|
|
121
|
+
turnover: Array<{
|
|
122
|
+
productId: string;
|
|
123
|
+
productName: string;
|
|
124
|
+
turnoverRate: number;
|
|
125
|
+
avgStockLevel: number;
|
|
126
|
+
totalSold: number;
|
|
127
|
+
}>;
|
|
128
|
+
/** Stock levels over time */
|
|
129
|
+
trends: TimeSeriesData;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Inventory - Track inventory and stock events.
|
|
133
|
+
*
|
|
134
|
+
* @extends FTRPC
|
|
135
|
+
*
|
|
136
|
+
* @description
|
|
137
|
+
* Provides inventory tracking including:
|
|
138
|
+
* - Stock level updates
|
|
139
|
+
* - Out-of-stock events
|
|
140
|
+
* - Restock tracking
|
|
141
|
+
* - Lost sales from stockouts
|
|
142
|
+
* - Demand forecasting data
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* ```typescript
|
|
146
|
+
* const inventory = new Inventory(webId, endpoint, apiKey);
|
|
147
|
+
*
|
|
148
|
+
* // Track sale reducing stock
|
|
149
|
+
* await inventory.updateStock({
|
|
150
|
+
* productId: 'SKU-123',
|
|
151
|
+
* previousStock: 25,
|
|
152
|
+
* newStock: 23,
|
|
153
|
+
* reason: 'sale'
|
|
154
|
+
* });
|
|
155
|
+
*
|
|
156
|
+
* // Track out of stock
|
|
157
|
+
* await inventory.outOfStock({
|
|
158
|
+
* productId: 'SKU-456',
|
|
159
|
+
* productName: 'Popular Widget',
|
|
160
|
+
* hadDemand: true,
|
|
161
|
+
* viewsWhileOOS: 150
|
|
162
|
+
* });
|
|
163
|
+
* ```
|
|
164
|
+
*/
|
|
165
|
+
export declare class Inventory extends FTRPC {
|
|
166
|
+
/**
|
|
167
|
+
* Tracks stock level update.
|
|
168
|
+
*
|
|
169
|
+
* @param config - Stock update configuration
|
|
170
|
+
* @returns Promise resolving to inventory response
|
|
171
|
+
*/
|
|
172
|
+
updateStock(config: StockUpdateConfig): Promise<InventoryResponse>;
|
|
173
|
+
/**
|
|
174
|
+
* Tracks out-of-stock event.
|
|
175
|
+
*
|
|
176
|
+
* @param config - Out-of-stock configuration
|
|
177
|
+
* @returns Promise resolving to inventory response
|
|
178
|
+
*/
|
|
179
|
+
outOfStock(config: OutOfStockConfig): Promise<InventoryResponse>;
|
|
180
|
+
/**
|
|
181
|
+
* Tracks restock event.
|
|
182
|
+
*
|
|
183
|
+
* @param productId - Product ID
|
|
184
|
+
* @param quantity - Quantity restocked
|
|
185
|
+
* @param newTotal - New total stock
|
|
186
|
+
* @returns Promise resolving to inventory response
|
|
187
|
+
*/
|
|
188
|
+
restock(productId: string, quantity: number, newTotal: number): Promise<InventoryResponse>;
|
|
189
|
+
/**
|
|
190
|
+
* Tracks back-in-stock notification request.
|
|
191
|
+
*
|
|
192
|
+
* @param productId - Product ID
|
|
193
|
+
* @param userId - User requesting notification
|
|
194
|
+
* @returns Promise resolving to inventory response
|
|
195
|
+
*/
|
|
196
|
+
notifyRequest(productId: string, userId?: string): Promise<InventoryResponse>;
|
|
197
|
+
/**
|
|
198
|
+
* Gets inventory analytics for dashboards.
|
|
199
|
+
*
|
|
200
|
+
* @param filter - Date range filter
|
|
201
|
+
* @returns Promise resolving to inventory analytics
|
|
202
|
+
*
|
|
203
|
+
* @example
|
|
204
|
+
* ```typescript
|
|
205
|
+
* const analytics = await inventory.getAnalytics({
|
|
206
|
+
* range: 'last30days'
|
|
207
|
+
* });
|
|
208
|
+
*
|
|
209
|
+
* // Alert table - out of stock
|
|
210
|
+
* const alerts = analytics.outOfStock;
|
|
211
|
+
*
|
|
212
|
+
* // Low stock warnings
|
|
213
|
+
* const warnings = analytics.lowStock;
|
|
214
|
+
*
|
|
215
|
+
* // Lost sales estimate
|
|
216
|
+
* const lostSales = analytics.summary.estimatedLostSales;
|
|
217
|
+
* ```
|
|
218
|
+
*/
|
|
219
|
+
getAnalytics(filter?: DateRangeFilter): Promise<InventoryAnalyticsData>;
|
|
220
|
+
}
|
|
221
|
+
export default Inventory;
|