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,373 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Enterprise - Marketing & Acquisition Analytics
|
|
3
|
+
* @module features/enterprise/acquisition
|
|
4
|
+
*
|
|
5
|
+
* @description
|
|
6
|
+
* Deep attribution and acquisition insights including CAC breakdown,
|
|
7
|
+
* trial-to-paid funnel tracking, and campaign performance by cohort.
|
|
8
|
+
*
|
|
9
|
+
* @useCases
|
|
10
|
+
* - Track customer acquisition cost by channel
|
|
11
|
+
* - Monitor trial → paid → upgrade funnel
|
|
12
|
+
* - Analyze campaign performance
|
|
13
|
+
* - Multi-touch attribution
|
|
14
|
+
* - Marketing ROI calculation
|
|
15
|
+
*
|
|
16
|
+
* @metrics
|
|
17
|
+
* - Customer Acquisition Cost (CAC)
|
|
18
|
+
* - Trial conversion rate
|
|
19
|
+
* - Paid conversion rate
|
|
20
|
+
* - Campaign ROI
|
|
21
|
+
* - Channel effectiveness
|
|
22
|
+
*
|
|
23
|
+
* @chartData
|
|
24
|
+
* - Bar chart: CAC by channel
|
|
25
|
+
* - Funnel: Trial to paid conversion
|
|
26
|
+
* - Line chart: Campaign performance
|
|
27
|
+
* - Pie chart: Acquisition source mix
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* const acquisition = new AcquisitionAnalytics(webId, endpoint, apiKey);
|
|
32
|
+
*
|
|
33
|
+
* // Track acquisition
|
|
34
|
+
* await acquisition.trackAcquisition({
|
|
35
|
+
* userId: 'user_123',
|
|
36
|
+
* source: 'google_ads',
|
|
37
|
+
* campaign: 'summer_2026'
|
|
38
|
+
* });
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
import { EnterpriseFTRPC } from "../../client/enterprise-ftrpc";
|
|
42
|
+
import { DateRangeFilter, TimeSeriesData, TimeGranularity, MoneyValue, CurrencyCode } from "../../types";
|
|
43
|
+
/**
|
|
44
|
+
* Acquisition source types.
|
|
45
|
+
*/
|
|
46
|
+
export type AcquisitionSource = 'organic' | 'paid_search' | 'paid_social' | 'organic_social' | 'email' | 'referral' | 'affiliate' | 'direct' | 'content' | 'other';
|
|
47
|
+
/**
|
|
48
|
+
* User lifecycle stage.
|
|
49
|
+
*/
|
|
50
|
+
export type LifecycleStage = 'visitor' | 'lead' | 'trial' | 'paid' | 'churned' | 'resurrected';
|
|
51
|
+
/**
|
|
52
|
+
* Acquisition tracking configuration.
|
|
53
|
+
*/
|
|
54
|
+
export interface AcquisitionConfig {
|
|
55
|
+
/** User ID */
|
|
56
|
+
userId: string;
|
|
57
|
+
/** Acquisition source */
|
|
58
|
+
source: AcquisitionSource;
|
|
59
|
+
/** Campaign name/ID */
|
|
60
|
+
campaign?: string;
|
|
61
|
+
/** Medium */
|
|
62
|
+
medium?: string;
|
|
63
|
+
/** Channel */
|
|
64
|
+
channel?: string;
|
|
65
|
+
/** Referring URL */
|
|
66
|
+
referrer?: string;
|
|
67
|
+
/** Landing page */
|
|
68
|
+
landingPage?: string;
|
|
69
|
+
/** UTM parameters */
|
|
70
|
+
utmParams?: {
|
|
71
|
+
source?: string;
|
|
72
|
+
medium?: string;
|
|
73
|
+
campaign?: string;
|
|
74
|
+
term?: string;
|
|
75
|
+
content?: string;
|
|
76
|
+
};
|
|
77
|
+
/** Acquisition cost (if known) */
|
|
78
|
+
cost?: MoneyValue;
|
|
79
|
+
/** Custom properties */
|
|
80
|
+
properties?: Record<string, unknown>;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Campaign definition.
|
|
84
|
+
*/
|
|
85
|
+
export interface CampaignDefinition {
|
|
86
|
+
/** Campaign ID */
|
|
87
|
+
campaignId: string;
|
|
88
|
+
/** Campaign name */
|
|
89
|
+
name: string;
|
|
90
|
+
/** Description */
|
|
91
|
+
description?: string;
|
|
92
|
+
/** Start date */
|
|
93
|
+
startDate: string;
|
|
94
|
+
/** End date */
|
|
95
|
+
endDate?: string;
|
|
96
|
+
/** Budget */
|
|
97
|
+
budget: MoneyValue;
|
|
98
|
+
/** Target acquisition count */
|
|
99
|
+
targetAcquisitions?: number;
|
|
100
|
+
/** Channel */
|
|
101
|
+
channel: AcquisitionSource;
|
|
102
|
+
/** Tags */
|
|
103
|
+
tags?: string[];
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Campaign spend tracking.
|
|
107
|
+
*/
|
|
108
|
+
export interface CampaignSpendConfig {
|
|
109
|
+
/** Campaign ID */
|
|
110
|
+
campaignId: string;
|
|
111
|
+
/** Spend amount */
|
|
112
|
+
amount: MoneyValue;
|
|
113
|
+
/** Spend date */
|
|
114
|
+
date: string;
|
|
115
|
+
/** Impressions */
|
|
116
|
+
impressions?: number;
|
|
117
|
+
/** Clicks */
|
|
118
|
+
clicks?: number;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Lifecycle transition configuration.
|
|
122
|
+
*/
|
|
123
|
+
export interface LifecycleTransitionConfig {
|
|
124
|
+
/** User ID */
|
|
125
|
+
userId: string;
|
|
126
|
+
/** Previous stage */
|
|
127
|
+
fromStage: LifecycleStage;
|
|
128
|
+
/** New stage */
|
|
129
|
+
toStage: LifecycleStage;
|
|
130
|
+
/** Revenue associated (if applicable) */
|
|
131
|
+
revenue?: MoneyValue;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* CAC configuration.
|
|
135
|
+
*/
|
|
136
|
+
export interface CACConfig {
|
|
137
|
+
/** Date range */
|
|
138
|
+
filter?: DateRangeFilter;
|
|
139
|
+
/** Breakdown dimension */
|
|
140
|
+
breakdown?: 'channel' | 'campaign' | 'source';
|
|
141
|
+
/** Include only paid channels */
|
|
142
|
+
paidOnly?: boolean;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* CAC result.
|
|
146
|
+
*/
|
|
147
|
+
export interface CACResult {
|
|
148
|
+
/** Overall CAC */
|
|
149
|
+
cac: MoneyValue;
|
|
150
|
+
/** Total spend */
|
|
151
|
+
totalSpend: MoneyValue;
|
|
152
|
+
/** Total acquisitions */
|
|
153
|
+
totalAcquisitions: number;
|
|
154
|
+
/** Breakdown (if requested) */
|
|
155
|
+
breakdown?: Array<{
|
|
156
|
+
dimension: string;
|
|
157
|
+
cac: MoneyValue;
|
|
158
|
+
spend: MoneyValue;
|
|
159
|
+
acquisitions: number;
|
|
160
|
+
}>;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Trial funnel configuration.
|
|
164
|
+
*/
|
|
165
|
+
export interface TrialFunnelConfig {
|
|
166
|
+
/** Date range */
|
|
167
|
+
filter?: DateRangeFilter;
|
|
168
|
+
/** Segment by attribute */
|
|
169
|
+
segmentBy?: string;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Trial funnel result.
|
|
173
|
+
*/
|
|
174
|
+
export interface TrialFunnelResult {
|
|
175
|
+
/** Visitors */
|
|
176
|
+
visitors: number;
|
|
177
|
+
/** Signups */
|
|
178
|
+
signups: number;
|
|
179
|
+
/** Trial starts */
|
|
180
|
+
trialStarts: number;
|
|
181
|
+
/** Trial to paid conversions */
|
|
182
|
+
trialToPaid: number;
|
|
183
|
+
/** Paid upgrades */
|
|
184
|
+
upgrades: number;
|
|
185
|
+
/** Conversion rates */
|
|
186
|
+
rates: {
|
|
187
|
+
visitorToSignup: number;
|
|
188
|
+
signupToTrial: number;
|
|
189
|
+
trialToPaid: number;
|
|
190
|
+
paidToUpgrade: number;
|
|
191
|
+
overallConversion: number;
|
|
192
|
+
};
|
|
193
|
+
/** Average time in trial */
|
|
194
|
+
avgTrialDays: number;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Campaign performance result.
|
|
198
|
+
*/
|
|
199
|
+
export interface CampaignPerformance {
|
|
200
|
+
campaignId: string;
|
|
201
|
+
name: string;
|
|
202
|
+
spend: MoneyValue;
|
|
203
|
+
impressions: number;
|
|
204
|
+
clicks: number;
|
|
205
|
+
acquisitions: number;
|
|
206
|
+
revenue: MoneyValue;
|
|
207
|
+
metrics: {
|
|
208
|
+
ctr: number;
|
|
209
|
+
cpc: MoneyValue;
|
|
210
|
+
cpa: MoneyValue;
|
|
211
|
+
roas: number;
|
|
212
|
+
roi: number;
|
|
213
|
+
};
|
|
214
|
+
trend: 'improving' | 'stable' | 'declining';
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Attribution model types.
|
|
218
|
+
*/
|
|
219
|
+
export type AttributionModel = 'first_touch' | 'last_touch' | 'linear' | 'time_decay' | 'position_based';
|
|
220
|
+
/**
|
|
221
|
+
* Attribution analysis configuration.
|
|
222
|
+
*/
|
|
223
|
+
export interface AttributionAnalysisConfig {
|
|
224
|
+
/** Attribution model */
|
|
225
|
+
model: AttributionModel;
|
|
226
|
+
/** Date range */
|
|
227
|
+
filter?: DateRangeFilter;
|
|
228
|
+
/** Conversion event */
|
|
229
|
+
conversionEvent?: string;
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Attribution result.
|
|
233
|
+
*/
|
|
234
|
+
export interface AttributionResult {
|
|
235
|
+
model: AttributionModel;
|
|
236
|
+
channels: Array<{
|
|
237
|
+
channel: string;
|
|
238
|
+
conversions: number;
|
|
239
|
+
revenue: MoneyValue;
|
|
240
|
+
contribution: number;
|
|
241
|
+
}>;
|
|
242
|
+
touchpointAnalysis: {
|
|
243
|
+
avgTouchpoints: number;
|
|
244
|
+
avgDaysToConvert: number;
|
|
245
|
+
topPaths: Array<{
|
|
246
|
+
path: string[];
|
|
247
|
+
count: number;
|
|
248
|
+
conversionRate: number;
|
|
249
|
+
}>;
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Acquisition analytics result.
|
|
254
|
+
*/
|
|
255
|
+
export interface AcquisitionAnalytics {
|
|
256
|
+
totalAcquisitions: number;
|
|
257
|
+
cac: MoneyValue;
|
|
258
|
+
ltv: MoneyValue;
|
|
259
|
+
ltvCacRatio: number;
|
|
260
|
+
topChannels: Array<{
|
|
261
|
+
channel: AcquisitionSource;
|
|
262
|
+
acquisitions: number;
|
|
263
|
+
percentage: number;
|
|
264
|
+
cac: MoneyValue;
|
|
265
|
+
}>;
|
|
266
|
+
trialConversionRate: number;
|
|
267
|
+
paidConversionRate: number;
|
|
268
|
+
trend: TimeSeriesData;
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Calculate CAC.
|
|
272
|
+
*/
|
|
273
|
+
export declare function calculateCAC(totalSpend: number, totalAcquisitions: number, currency: CurrencyCode): MoneyValue;
|
|
274
|
+
/**
|
|
275
|
+
* Calculate ROAS (Return on Ad Spend).
|
|
276
|
+
*/
|
|
277
|
+
export declare function calculateROAS(revenue: number, spend: number): number;
|
|
278
|
+
/**
|
|
279
|
+
* Calculate LTV:CAC ratio.
|
|
280
|
+
*/
|
|
281
|
+
export declare function calculateLTVCACRatio(ltv: number, cac: number): number;
|
|
282
|
+
/**
|
|
283
|
+
* Parse UTM parameters from URL.
|
|
284
|
+
*/
|
|
285
|
+
export declare function parseUTMParams(url: string): Record<string, string>;
|
|
286
|
+
/**
|
|
287
|
+
* Classify acquisition source from UTM parameters.
|
|
288
|
+
*/
|
|
289
|
+
export declare function classifySource(utmSource?: string, utmMedium?: string): AcquisitionSource;
|
|
290
|
+
/**
|
|
291
|
+
* Marketing and acquisition analytics class.
|
|
292
|
+
*/
|
|
293
|
+
export declare class AcquisitionAnalytics extends EnterpriseFTRPC {
|
|
294
|
+
/**
|
|
295
|
+
* Track user acquisition.
|
|
296
|
+
*/
|
|
297
|
+
trackAcquisition(config: AcquisitionConfig): Promise<{
|
|
298
|
+
tracked: boolean;
|
|
299
|
+
}>;
|
|
300
|
+
/**
|
|
301
|
+
* Track lifecycle transition.
|
|
302
|
+
*/
|
|
303
|
+
trackLifecycleTransition(config: LifecycleTransitionConfig): Promise<{
|
|
304
|
+
tracked: boolean;
|
|
305
|
+
}>;
|
|
306
|
+
/**
|
|
307
|
+
* Create campaign.
|
|
308
|
+
*/
|
|
309
|
+
createCampaign(definition: CampaignDefinition): Promise<{
|
|
310
|
+
created: boolean;
|
|
311
|
+
}>;
|
|
312
|
+
/**
|
|
313
|
+
* Track campaign spend.
|
|
314
|
+
*/
|
|
315
|
+
trackCampaignSpend(config: CampaignSpendConfig): Promise<{
|
|
316
|
+
tracked: boolean;
|
|
317
|
+
}>;
|
|
318
|
+
/**
|
|
319
|
+
* Get CAC.
|
|
320
|
+
*/
|
|
321
|
+
getCAC(config?: CACConfig): Promise<CACResult>;
|
|
322
|
+
/**
|
|
323
|
+
* Get trial funnel.
|
|
324
|
+
*/
|
|
325
|
+
getTrialFunnel(config?: TrialFunnelConfig): Promise<TrialFunnelResult>;
|
|
326
|
+
/**
|
|
327
|
+
* Get campaign performance.
|
|
328
|
+
*/
|
|
329
|
+
getCampaignPerformance(campaignId?: string, filter?: DateRangeFilter): Promise<CampaignPerformance[]>;
|
|
330
|
+
/**
|
|
331
|
+
* Get attribution analysis.
|
|
332
|
+
*/
|
|
333
|
+
getAttribution(config: AttributionAnalysisConfig): Promise<AttributionResult>;
|
|
334
|
+
/**
|
|
335
|
+
* Get LTV:CAC ratio.
|
|
336
|
+
*/
|
|
337
|
+
getLTVCACRatio(filter?: DateRangeFilter): Promise<{
|
|
338
|
+
ltv: MoneyValue;
|
|
339
|
+
cac: MoneyValue;
|
|
340
|
+
ratio: number;
|
|
341
|
+
healthy: boolean;
|
|
342
|
+
}>;
|
|
343
|
+
/**
|
|
344
|
+
* Get acquisition analytics.
|
|
345
|
+
*/
|
|
346
|
+
getAnalytics(filter?: DateRangeFilter): Promise<AcquisitionAnalytics>;
|
|
347
|
+
/**
|
|
348
|
+
* Get acquisition trend.
|
|
349
|
+
*/
|
|
350
|
+
getAcquisitionTrend(filter?: DateRangeFilter, granularity?: TimeGranularity): Promise<TimeSeriesData>;
|
|
351
|
+
/**
|
|
352
|
+
* Get channel effectiveness.
|
|
353
|
+
*/
|
|
354
|
+
getChannelEffectiveness(filter?: DateRangeFilter): Promise<Array<{
|
|
355
|
+
channel: AcquisitionSource;
|
|
356
|
+
acquisitions: number;
|
|
357
|
+
cac: MoneyValue;
|
|
358
|
+
ltv: MoneyValue;
|
|
359
|
+
paybackMonths: number;
|
|
360
|
+
score: number;
|
|
361
|
+
}>>;
|
|
362
|
+
/**
|
|
363
|
+
* Get cohort-based campaign analysis.
|
|
364
|
+
*/
|
|
365
|
+
getCohortCampaignAnalysis(campaignId: string, periods: number): Promise<{
|
|
366
|
+
cohorts: Array<{
|
|
367
|
+
cohortDate: string;
|
|
368
|
+
acquisitions: number;
|
|
369
|
+
retention: number[];
|
|
370
|
+
ltv: MoneyValue;
|
|
371
|
+
}>;
|
|
372
|
+
}>;
|
|
373
|
+
}
|
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Enterprise - Alerts & Anomaly Detection
|
|
3
|
+
* @module features/enterprise/alerts
|
|
4
|
+
*
|
|
5
|
+
* @description
|
|
6
|
+
* Proactively monitor anomalies in key metrics and trigger alerts.
|
|
7
|
+
* Detect activation drops, error spikes, and custom threshold breaches.
|
|
8
|
+
*
|
|
9
|
+
* @useCases
|
|
10
|
+
* - Monitor for activation drops
|
|
11
|
+
* - Detect error/churn spikes
|
|
12
|
+
* - Set custom alert rules
|
|
13
|
+
* - Threshold monitoring
|
|
14
|
+
* - Real-time anomaly detection
|
|
15
|
+
*
|
|
16
|
+
* @metrics
|
|
17
|
+
* - Alert frequency
|
|
18
|
+
* - Time to detection
|
|
19
|
+
* - False positive rate
|
|
20
|
+
* - Alert resolution time
|
|
21
|
+
* - Metric anomaly score
|
|
22
|
+
*
|
|
23
|
+
* @chartData
|
|
24
|
+
* - Line chart: Metric with anomaly markers
|
|
25
|
+
* - Timeline: Alert history
|
|
26
|
+
* - Bar chart: Alerts by type
|
|
27
|
+
* - Dashboard: Alert status
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* const alerts = new AlertsAnalytics(webId, endpoint, apiKey);
|
|
32
|
+
*
|
|
33
|
+
* // Create an alert rule
|
|
34
|
+
* await alerts.createAlert({
|
|
35
|
+
* name: 'Activation Drop',
|
|
36
|
+
* metric: 'activation_rate',
|
|
37
|
+
* condition: 'drops_below',
|
|
38
|
+
* threshold: 50,
|
|
39
|
+
* severity: 'high'
|
|
40
|
+
* });
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
import { EnterpriseFTRPC } from "../../client/enterprise-ftrpc";
|
|
44
|
+
import { DateRangeFilter, TimeSeriesData, TimeGranularity } from "../../types";
|
|
45
|
+
/**
|
|
46
|
+
* Alert condition types.
|
|
47
|
+
*/
|
|
48
|
+
export type AlertCondition = 'exceeds' | 'drops_below' | 'changes_by' | 'anomaly_detected' | 'no_data';
|
|
49
|
+
/**
|
|
50
|
+
* Alert severity levels.
|
|
51
|
+
*/
|
|
52
|
+
export type AlertSeverity = 'info' | 'warning' | 'high' | 'critical';
|
|
53
|
+
/**
|
|
54
|
+
* Alert status.
|
|
55
|
+
*/
|
|
56
|
+
export type AlertStatus = 'active' | 'acknowledged' | 'resolved' | 'muted';
|
|
57
|
+
/**
|
|
58
|
+
* Notification channel.
|
|
59
|
+
*/
|
|
60
|
+
export type NotificationChannel = 'email' | 'slack' | 'webhook' | 'pagerduty' | 'sms';
|
|
61
|
+
/**
|
|
62
|
+
* Alert rule definition.
|
|
63
|
+
*/
|
|
64
|
+
export interface AlertRuleDefinition {
|
|
65
|
+
/** Alert ID */
|
|
66
|
+
alertId?: string;
|
|
67
|
+
/** Alert name */
|
|
68
|
+
name: string;
|
|
69
|
+
/** Description */
|
|
70
|
+
description?: string;
|
|
71
|
+
/** Metric to monitor */
|
|
72
|
+
metric: string;
|
|
73
|
+
/** Condition type */
|
|
74
|
+
condition: AlertCondition;
|
|
75
|
+
/** Threshold value */
|
|
76
|
+
threshold: number;
|
|
77
|
+
/** Change percentage (for changes_by condition) */
|
|
78
|
+
changePercent?: number;
|
|
79
|
+
/** Comparison window */
|
|
80
|
+
window?: {
|
|
81
|
+
value: number;
|
|
82
|
+
unit: 'minutes' | 'hours' | 'days';
|
|
83
|
+
};
|
|
84
|
+
/** Alert severity */
|
|
85
|
+
severity: AlertSeverity;
|
|
86
|
+
/** Notification channels */
|
|
87
|
+
channels: NotificationChannel[];
|
|
88
|
+
/** Notification recipients */
|
|
89
|
+
recipients?: string[];
|
|
90
|
+
/** Custom filters */
|
|
91
|
+
filters?: Record<string, unknown>;
|
|
92
|
+
/** Is alert enabled */
|
|
93
|
+
enabled?: boolean;
|
|
94
|
+
/** Cooldown period (minutes) */
|
|
95
|
+
cooldownMinutes?: number;
|
|
96
|
+
/** Tags */
|
|
97
|
+
tags?: string[];
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Alert instance (triggered alert).
|
|
101
|
+
*/
|
|
102
|
+
export interface AlertInstance {
|
|
103
|
+
/** Instance ID */
|
|
104
|
+
instanceId: string;
|
|
105
|
+
/** Alert rule ID */
|
|
106
|
+
alertId: string;
|
|
107
|
+
/** Alert name */
|
|
108
|
+
alertName: string;
|
|
109
|
+
/** Triggered at */
|
|
110
|
+
triggeredAt: string;
|
|
111
|
+
/** Current value that triggered alert */
|
|
112
|
+
currentValue: number;
|
|
113
|
+
/** Threshold value */
|
|
114
|
+
thresholdValue: number;
|
|
115
|
+
/** Severity */
|
|
116
|
+
severity: AlertSeverity;
|
|
117
|
+
/** Status */
|
|
118
|
+
status: AlertStatus;
|
|
119
|
+
/** Acknowledged by */
|
|
120
|
+
acknowledgedBy?: string;
|
|
121
|
+
/** Acknowledged at */
|
|
122
|
+
acknowledgedAt?: string;
|
|
123
|
+
/** Resolved at */
|
|
124
|
+
resolvedAt?: string;
|
|
125
|
+
/** Resolution notes */
|
|
126
|
+
resolutionNotes?: string;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Anomaly detection configuration.
|
|
130
|
+
*/
|
|
131
|
+
export interface AnomalyDetectionConfig {
|
|
132
|
+
/** Metric to analyze */
|
|
133
|
+
metric: string;
|
|
134
|
+
/** Lookback period */
|
|
135
|
+
lookbackDays: number;
|
|
136
|
+
/** Sensitivity (0-1, higher = more sensitive) */
|
|
137
|
+
sensitivity?: number;
|
|
138
|
+
/** Detection method */
|
|
139
|
+
method?: 'statistical' | 'ml' | 'hybrid';
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Detected anomaly.
|
|
143
|
+
*/
|
|
144
|
+
export interface Anomaly {
|
|
145
|
+
/** Anomaly ID */
|
|
146
|
+
anomalyId: string;
|
|
147
|
+
/** Metric */
|
|
148
|
+
metric: string;
|
|
149
|
+
/** Detected at */
|
|
150
|
+
detectedAt: string;
|
|
151
|
+
/** Expected value */
|
|
152
|
+
expectedValue: number;
|
|
153
|
+
/** Actual value */
|
|
154
|
+
actualValue: number;
|
|
155
|
+
/** Deviation percentage */
|
|
156
|
+
deviationPercent: number;
|
|
157
|
+
/** Anomaly score (0-1) */
|
|
158
|
+
anomalyScore: number;
|
|
159
|
+
/** Direction */
|
|
160
|
+
direction: 'up' | 'down';
|
|
161
|
+
/** Severity */
|
|
162
|
+
severity: AlertSeverity;
|
|
163
|
+
/** Is confirmed anomaly */
|
|
164
|
+
isConfirmed: boolean;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Alert notification configuration.
|
|
168
|
+
*/
|
|
169
|
+
export interface NotificationConfig {
|
|
170
|
+
/** Channel */
|
|
171
|
+
channel: NotificationChannel;
|
|
172
|
+
/** Channel-specific config */
|
|
173
|
+
config: {
|
|
174
|
+
/** Email addresses (for email channel) */
|
|
175
|
+
emails?: string[];
|
|
176
|
+
/** Slack webhook URL (for slack channel) */
|
|
177
|
+
slackWebhook?: string;
|
|
178
|
+
/** Webhook URL (for webhook channel) */
|
|
179
|
+
webhookUrl?: string;
|
|
180
|
+
/** PagerDuty routing key */
|
|
181
|
+
pagerDutyKey?: string;
|
|
182
|
+
/** Phone numbers (for SMS) */
|
|
183
|
+
phoneNumbers?: string[];
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Alert analytics filter.
|
|
188
|
+
*/
|
|
189
|
+
export interface AlertAnalyticsFilter extends DateRangeFilter {
|
|
190
|
+
/** Filter by severity */
|
|
191
|
+
severity?: AlertSeverity;
|
|
192
|
+
/** Filter by status */
|
|
193
|
+
status?: AlertStatus;
|
|
194
|
+
/** Filter by metric */
|
|
195
|
+
metric?: string;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Alert analytics result.
|
|
199
|
+
*/
|
|
200
|
+
export interface AlertAnalytics {
|
|
201
|
+
/** Total alerts triggered */
|
|
202
|
+
totalAlerts: number;
|
|
203
|
+
/** By severity */
|
|
204
|
+
bySeverity: Record<AlertSeverity, number>;
|
|
205
|
+
/** By status */
|
|
206
|
+
byStatus: Record<AlertStatus, number>;
|
|
207
|
+
/** Average time to acknowledge (ms) */
|
|
208
|
+
avgTimeToAcknowledgeMs: number;
|
|
209
|
+
/** Average time to resolve (ms) */
|
|
210
|
+
avgTimeToResolveMs: number;
|
|
211
|
+
/** Top triggered alerts */
|
|
212
|
+
topAlerts: Array<{
|
|
213
|
+
alertId: string;
|
|
214
|
+
name: string;
|
|
215
|
+
count: number;
|
|
216
|
+
}>;
|
|
217
|
+
/** Alert trend */
|
|
218
|
+
trend: TimeSeriesData;
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Calculate standard deviation.
|
|
222
|
+
*/
|
|
223
|
+
export declare function calculateStdDev(values: number[]): number;
|
|
224
|
+
/**
|
|
225
|
+
* Calculate Z-score for anomaly detection.
|
|
226
|
+
*/
|
|
227
|
+
export declare function calculateZScore(value: number, mean: number, stdDev: number): number;
|
|
228
|
+
/**
|
|
229
|
+
* Determine if value is anomalous based on Z-score.
|
|
230
|
+
*/
|
|
231
|
+
export declare function isAnomaly(zScore: number, sensitivity?: number): boolean;
|
|
232
|
+
/**
|
|
233
|
+
* Calculate anomaly score (0-1).
|
|
234
|
+
*/
|
|
235
|
+
export declare function calculateAnomalyScore(zScore: number): number;
|
|
236
|
+
/**
|
|
237
|
+
* Classify severity from anomaly score.
|
|
238
|
+
*/
|
|
239
|
+
export declare function classifySeverity(anomalyScore: number): AlertSeverity;
|
|
240
|
+
/**
|
|
241
|
+
* Check if alert condition is met.
|
|
242
|
+
*/
|
|
243
|
+
export declare function checkAlertCondition(currentValue: number, condition: AlertCondition, threshold: number, previousValue?: number, changePercent?: number): boolean;
|
|
244
|
+
/**
|
|
245
|
+
* Alerts and anomaly detection class.
|
|
246
|
+
*/
|
|
247
|
+
export declare class AlertsAnalytics extends EnterpriseFTRPC {
|
|
248
|
+
/**
|
|
249
|
+
* Create an alert rule.
|
|
250
|
+
*/
|
|
251
|
+
createAlert(definition: AlertRuleDefinition): Promise<{
|
|
252
|
+
alertId: string;
|
|
253
|
+
}>;
|
|
254
|
+
/**
|
|
255
|
+
* Update an alert rule.
|
|
256
|
+
*/
|
|
257
|
+
updateAlert(alertId: string, updates: Partial<AlertRuleDefinition>): Promise<{
|
|
258
|
+
updated: boolean;
|
|
259
|
+
}>;
|
|
260
|
+
/**
|
|
261
|
+
* Delete an alert rule.
|
|
262
|
+
*/
|
|
263
|
+
deleteAlert(alertId: string): Promise<{
|
|
264
|
+
deleted: boolean;
|
|
265
|
+
}>;
|
|
266
|
+
/**
|
|
267
|
+
* Enable/disable an alert.
|
|
268
|
+
*/
|
|
269
|
+
toggleAlert(alertId: string, enabled: boolean): Promise<{
|
|
270
|
+
updated: boolean;
|
|
271
|
+
}>;
|
|
272
|
+
/**
|
|
273
|
+
* Get alert rule.
|
|
274
|
+
*/
|
|
275
|
+
getAlert(alertId: string): Promise<AlertRuleDefinition & {
|
|
276
|
+
alertId: string;
|
|
277
|
+
}>;
|
|
278
|
+
/**
|
|
279
|
+
* List all alert rules.
|
|
280
|
+
*/
|
|
281
|
+
listAlerts(enabled?: boolean): Promise<Array<AlertRuleDefinition & {
|
|
282
|
+
alertId: string;
|
|
283
|
+
}>>;
|
|
284
|
+
/**
|
|
285
|
+
* Get triggered alerts.
|
|
286
|
+
*/
|
|
287
|
+
getTriggeredAlerts(filter?: AlertAnalyticsFilter): Promise<AlertInstance[]>;
|
|
288
|
+
/**
|
|
289
|
+
* Acknowledge an alert.
|
|
290
|
+
*/
|
|
291
|
+
acknowledgeAlert(instanceId: string, acknowledgedBy: string): Promise<{
|
|
292
|
+
acknowledged: boolean;
|
|
293
|
+
}>;
|
|
294
|
+
/**
|
|
295
|
+
* Resolve an alert.
|
|
296
|
+
*/
|
|
297
|
+
resolveAlert(instanceId: string, notes?: string): Promise<{
|
|
298
|
+
resolved: boolean;
|
|
299
|
+
}>;
|
|
300
|
+
/**
|
|
301
|
+
* Mute an alert temporarily.
|
|
302
|
+
*/
|
|
303
|
+
muteAlert(alertId: string, durationMinutes: number): Promise<{
|
|
304
|
+
muted: boolean;
|
|
305
|
+
}>;
|
|
306
|
+
/**
|
|
307
|
+
* Run anomaly detection.
|
|
308
|
+
*/
|
|
309
|
+
detectAnomalies(config: AnomalyDetectionConfig): Promise<Anomaly[]>;
|
|
310
|
+
/**
|
|
311
|
+
* Get historical anomalies.
|
|
312
|
+
*/
|
|
313
|
+
getAnomalies(filter?: AlertAnalyticsFilter): Promise<Anomaly[]>;
|
|
314
|
+
/**
|
|
315
|
+
* Configure notification channel.
|
|
316
|
+
*/
|
|
317
|
+
configureNotification(config: NotificationConfig): Promise<{
|
|
318
|
+
configured: boolean;
|
|
319
|
+
}>;
|
|
320
|
+
/**
|
|
321
|
+
* Test notification channel.
|
|
322
|
+
*/
|
|
323
|
+
testNotification(channel: NotificationChannel): Promise<{
|
|
324
|
+
success: boolean;
|
|
325
|
+
}>;
|
|
326
|
+
/**
|
|
327
|
+
* Get alert analytics.
|
|
328
|
+
*/
|
|
329
|
+
getAnalytics(filter?: AlertAnalyticsFilter): Promise<AlertAnalytics>;
|
|
330
|
+
/**
|
|
331
|
+
* Get metric with anomaly overlay.
|
|
332
|
+
*/
|
|
333
|
+
getMetricWithAnomalies(metric: string, filter?: DateRangeFilter, granularity?: TimeGranularity): Promise<{
|
|
334
|
+
data: TimeSeriesData;
|
|
335
|
+
anomalies: Array<{
|
|
336
|
+
timestamp: string;
|
|
337
|
+
score: number;
|
|
338
|
+
}>;
|
|
339
|
+
}>;
|
|
340
|
+
/**
|
|
341
|
+
* Get alert correlation analysis.
|
|
342
|
+
*/
|
|
343
|
+
getAlertCorrelation(filter?: DateRangeFilter): Promise<Array<{
|
|
344
|
+
alertPair: [string, string];
|
|
345
|
+
correlation: number;
|
|
346
|
+
coOccurrences: number;
|
|
347
|
+
}>>;
|
|
348
|
+
}
|