@happyvertical/smrt-analytics 0.30.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 (72) hide show
  1. package/AGENTS.md +68 -0
  2. package/CLAUDE.md +1 -0
  3. package/LICENSE +7 -0
  4. package/README.md +131 -0
  5. package/dist/__smrt-register__.d.ts +2 -0
  6. package/dist/__smrt-register__.d.ts.map +1 -0
  7. package/dist/collections/AnalyticsDataStreamCollection.d.ts +69 -0
  8. package/dist/collections/AnalyticsDataStreamCollection.d.ts.map +1 -0
  9. package/dist/collections/AnalyticsEventCollection.d.ts +131 -0
  10. package/dist/collections/AnalyticsEventCollection.d.ts.map +1 -0
  11. package/dist/collections/AnalyticsPropertyCollection.d.ts +66 -0
  12. package/dist/collections/AnalyticsPropertyCollection.d.ts.map +1 -0
  13. package/dist/collections/AnalyticsReportCollection.d.ts +69 -0
  14. package/dist/collections/AnalyticsReportCollection.d.ts.map +1 -0
  15. package/dist/collections/index.d.ts +8 -0
  16. package/dist/collections/index.d.ts.map +1 -0
  17. package/dist/index.d.ts +6 -0
  18. package/dist/index.d.ts.map +1 -0
  19. package/dist/index.js +1623 -0
  20. package/dist/index.js.map +1 -0
  21. package/dist/manifest.json +4161 -0
  22. package/dist/models/AnalyticsDataStream.d.ts +94 -0
  23. package/dist/models/AnalyticsDataStream.d.ts.map +1 -0
  24. package/dist/models/AnalyticsEvent.d.ts +142 -0
  25. package/dist/models/AnalyticsEvent.d.ts.map +1 -0
  26. package/dist/models/AnalyticsProperty.d.ts +142 -0
  27. package/dist/models/AnalyticsProperty.d.ts.map +1 -0
  28. package/dist/models/AnalyticsReport.d.ts +206 -0
  29. package/dist/models/AnalyticsReport.d.ts.map +1 -0
  30. package/dist/models/index.d.ts +8 -0
  31. package/dist/models/index.d.ts.map +1 -0
  32. package/dist/playground.d.ts +2 -0
  33. package/dist/playground.d.ts.map +1 -0
  34. package/dist/playground.js +99 -0
  35. package/dist/playground.js.map +1 -0
  36. package/dist/prompts.d.ts +57 -0
  37. package/dist/prompts.d.ts.map +1 -0
  38. package/dist/smrt-knowledge.json +1570 -0
  39. package/dist/svelte/AnalyticsSummary.svelte +63 -0
  40. package/dist/svelte/AnalyticsSummary.svelte.d.ts +8 -0
  41. package/dist/svelte/AnalyticsSummary.svelte.d.ts.map +1 -0
  42. package/dist/svelte/EventsTable.svelte +161 -0
  43. package/dist/svelte/EventsTable.svelte.d.ts +16 -0
  44. package/dist/svelte/EventsTable.svelte.d.ts.map +1 -0
  45. package/dist/svelte/PropertyInfo.svelte +139 -0
  46. package/dist/svelte/PropertyInfo.svelte.d.ts +12 -0
  47. package/dist/svelte/PropertyInfo.svelte.d.ts.map +1 -0
  48. package/dist/svelte/PropertyStatusBadge.svelte +65 -0
  49. package/dist/svelte/PropertyStatusBadge.svelte.d.ts +7 -0
  50. package/dist/svelte/PropertyStatusBadge.svelte.d.ts.map +1 -0
  51. package/dist/svelte/StatCard.svelte +63 -0
  52. package/dist/svelte/StatCard.svelte.d.ts +11 -0
  53. package/dist/svelte/StatCard.svelte.d.ts.map +1 -0
  54. package/dist/svelte/TrendBadge.svelte +49 -0
  55. package/dist/svelte/TrendBadge.svelte.d.ts +8 -0
  56. package/dist/svelte/TrendBadge.svelte.d.ts.map +1 -0
  57. package/dist/svelte/i18n.d.ts +10 -0
  58. package/dist/svelte/i18n.d.ts.map +1 -0
  59. package/dist/svelte/i18n.js +10 -0
  60. package/dist/svelte/index.d.ts +29 -0
  61. package/dist/svelte/index.d.ts.map +1 -0
  62. package/dist/svelte/index.js +39 -0
  63. package/dist/svelte/playground.d.ts +88 -0
  64. package/dist/svelte/playground.d.ts.map +1 -0
  65. package/dist/svelte/playground.js +95 -0
  66. package/dist/types/index.d.ts +267 -0
  67. package/dist/types/index.d.ts.map +1 -0
  68. package/dist/ui.d.ts +10 -0
  69. package/dist/ui.d.ts.map +1 -0
  70. package/dist/ui.js +79 -0
  71. package/dist/ui.js.map +1 -0
  72. package/package.json +95 -0
@@ -0,0 +1,94 @@
1
+ import { SmrtObject } from '@happyvertical/smrt-core';
2
+ import { DataStreamStatus, DataStreamType } from '../types/index.js';
3
+ /**
4
+ * AnalyticsDataStream represents a data stream (web, iOS, Android) for an analytics property.
5
+ *
6
+ * @example
7
+ * ```typescript
8
+ * const stream = await streams.create({
9
+ * propertyId: property.id,
10
+ * displayName: 'Web Stream',
11
+ * streamType: DataStreamType.WEB,
12
+ * measurementId: 'G-XXXXXXXXXX',
13
+ * defaultUri: 'https://example.com'
14
+ * });
15
+ * ```
16
+ */
17
+ export declare class AnalyticsDataStream extends SmrtObject {
18
+ /**
19
+ * Tenant ID for multi-tenancy isolation (#1410).
20
+ *
21
+ * Data streams expose tenant-private platform configuration (measurement
22
+ * IDs, Firebase app IDs, bundle/package names, default URIs). Without tenant
23
+ * scoping the generated `list`/`get` API returns every tenant's streams.
24
+ * `@TenantScoped` auto-filters reads and binds writes to the active tenant.
25
+ */
26
+ tenantId: string | null;
27
+ /**
28
+ * Parent property ID (references AnalyticsProperty)
29
+ */
30
+ propertyId: string;
31
+ /**
32
+ * Human-readable display name
33
+ */
34
+ displayName: string;
35
+ /**
36
+ * Stream type (WEB, ANDROID, IOS)
37
+ */
38
+ streamType: DataStreamType;
39
+ /**
40
+ * External stream ID from provider
41
+ */
42
+ externalId: string;
43
+ /**
44
+ * Measurement ID for web streams (G-XXXXXXX)
45
+ */
46
+ measurementId: string;
47
+ /**
48
+ * Firebase App ID for app streams
49
+ */
50
+ firebaseAppId: string;
51
+ /**
52
+ * Default URI for web streams
53
+ */
54
+ defaultUri: string;
55
+ /**
56
+ * Bundle ID for iOS apps
57
+ */
58
+ bundleId: string;
59
+ /**
60
+ * Package name for Android apps
61
+ */
62
+ packageName: string;
63
+ /**
64
+ * Stream status
65
+ */
66
+ status: DataStreamStatus;
67
+ /**
68
+ * Enhanced measurement enabled
69
+ */
70
+ enhancedMeasurement: boolean;
71
+ constructor(options?: any);
72
+ /**
73
+ * Check if this is a web stream
74
+ */
75
+ isWeb(): boolean;
76
+ /**
77
+ * Check if this is an iOS app stream
78
+ */
79
+ isIOS(): boolean;
80
+ /**
81
+ * Check if this is an Android app stream
82
+ */
83
+ isAndroid(): boolean;
84
+ /**
85
+ * Check if this is a mobile app stream (iOS or Android)
86
+ */
87
+ isMobileApp(): boolean;
88
+ /**
89
+ * Get the platform identifier (measurementId for web, firebaseAppId for apps)
90
+ */
91
+ getPlatformId(): string;
92
+ }
93
+ export default AnalyticsDataStream;
94
+ //# sourceMappingURL=AnalyticsDataStream.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AnalyticsDataStream.d.ts","sourceRoot":"","sources":["../../src/models/AnalyticsDataStream.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAc,UAAU,EAAQ,MAAM,0BAA0B,CAAC;AAExE,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAErE;;;;;;;;;;;;;GAaG;AACH,qBAOa,mBAAoB,SAAQ,UAAU;IACjD;;;;;;;OAOG;IAEH,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAQ;IAE/B;;OAEG;IAEH,UAAU,EAAE,MAAM,CAAM;IAExB;;OAEG;IACH,WAAW,EAAE,MAAM,CAAM;IAEzB;;OAEG;IACH,UAAU,EAAE,cAAc,CAAsB;IAEhD;;OAEG;IACH,UAAU,EAAE,MAAM,CAAM;IAExB;;OAEG;IACH,aAAa,EAAE,MAAM,CAAM;IAE3B;;OAEG;IACH,aAAa,EAAE,MAAM,CAAM;IAE3B;;OAEG;IACH,UAAU,EAAE,MAAM,CAAM;IAExB;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAM;IAEtB;;OAEG;IACH,WAAW,EAAE,MAAM,CAAM;IAEzB;;OAEG;IACH,MAAM,EAAE,gBAAgB,CAA2B;IAEnD;;OAEG;IACH,mBAAmB,EAAE,OAAO,CAAQ;gBAExB,OAAO,GAAE,GAAQ;IAqB7B;;OAEG;IACH,KAAK,IAAI,OAAO;IAIhB;;OAEG;IACH,KAAK,IAAI,OAAO;IAIhB;;OAEG;IACH,SAAS,IAAI,OAAO;IAIpB;;OAEG;IACH,WAAW,IAAI,OAAO;IAItB;;OAEG;IACH,aAAa,IAAI,MAAM;CAMxB;AAED,eAAe,mBAAmB,CAAC"}
@@ -0,0 +1,142 @@
1
+ import { SmrtObject } from '@happyvertical/smrt-core';
2
+ import { TrackingEventStatus } from '../types/index.js';
3
+ /**
4
+ * AnalyticsEvent represents a tracked analytics event (server-side tracking log).
5
+ *
6
+ * @example
7
+ * ```typescript
8
+ * const event = await events.create({
9
+ * propertyId: property.id,
10
+ * eventName: 'purchase',
11
+ * clientId: 'user-123',
12
+ * params: JSON.stringify({ value: 99.99, currency: 'USD' })
13
+ * });
14
+ * await event.send();
15
+ * ```
16
+ */
17
+ export declare class AnalyticsEvent extends SmrtObject {
18
+ /**
19
+ * Tenant ID for multi-tenancy isolation (#1410).
20
+ *
21
+ * Analytics events carry end-user PII (`userId`, `clientId`, `ipAddress`,
22
+ * `userAgent`, `sessionId`). Without tenant scoping the generated
23
+ * `list`/`get` API leaks every tenant's visitor data, and `create` lets a
24
+ * caller write events bound to another tenant's `propertyId`. `@TenantScoped`
25
+ * auto-filters reads and binds writes to the active tenant context.
26
+ */
27
+ tenantId: string | null;
28
+ /**
29
+ * Parent property ID (references AnalyticsProperty)
30
+ */
31
+ propertyId: string;
32
+ /**
33
+ * Event name (e.g., 'purchase', 'page_view', 'sign_up')
34
+ */
35
+ eventName: string;
36
+ /**
37
+ * Client ID for anonymous tracking
38
+ */
39
+ clientId: string;
40
+ /**
41
+ * User ID for identified tracking
42
+ */
43
+ userId: string;
44
+ /**
45
+ * Event parameters (JSON)
46
+ */
47
+ params: string;
48
+ /**
49
+ * Event timestamp
50
+ */
51
+ eventTimestamp: Date;
52
+ /**
53
+ * Tracking status
54
+ */
55
+ status: TrackingEventStatus;
56
+ /**
57
+ * Timestamp when sent to provider
58
+ */
59
+ sentAt: Date | null;
60
+ /**
61
+ * Error message if sending failed
62
+ */
63
+ errorMessage: string;
64
+ /**
65
+ * Retry count
66
+ */
67
+ retryCount: number;
68
+ /**
69
+ * Disable personalized ads
70
+ */
71
+ nonPersonalizedAds: boolean;
72
+ /**
73
+ * Session ID
74
+ */
75
+ sessionId: string;
76
+ /**
77
+ * Page path (for pageview events)
78
+ */
79
+ pagePath: string;
80
+ /**
81
+ * Page title (for pageview events)
82
+ */
83
+ pageTitle: string;
84
+ /**
85
+ * User agent
86
+ */
87
+ userAgent: string;
88
+ /**
89
+ * IP address (anonymized)
90
+ */
91
+ ipAddress: string;
92
+ constructor(options?: any);
93
+ /**
94
+ * Get parsed event parameters
95
+ */
96
+ getParams(): Record<string, string | number | boolean>;
97
+ /**
98
+ * Set event parameters
99
+ */
100
+ setParams(params: Record<string, string | number | boolean>): void;
101
+ /**
102
+ * Add a parameter to the event
103
+ */
104
+ addParam(key: string, value: string | number | boolean): void;
105
+ /**
106
+ * Check if this is a pageview event
107
+ */
108
+ isPageview(): boolean;
109
+ /**
110
+ * Check if this is a conversion event
111
+ */
112
+ isConversion(): boolean;
113
+ /**
114
+ * Mark as sent successfully
115
+ */
116
+ markSent(): void;
117
+ /**
118
+ * Mark as failed
119
+ */
120
+ markFailed(error: string): void;
121
+ /**
122
+ * Reset for retry
123
+ */
124
+ resetForRetry(): void;
125
+ /**
126
+ * Check if event should be retried
127
+ */
128
+ shouldRetry(maxRetries?: number): boolean;
129
+ /**
130
+ * Build SDK TrackEvent object
131
+ */
132
+ toTrackEvent(): {
133
+ name: string;
134
+ params?: Record<string, string | number | boolean>;
135
+ clientId?: string;
136
+ userId?: string;
137
+ timestamp?: number;
138
+ nonPersonalizedAds?: boolean;
139
+ };
140
+ }
141
+ export default AnalyticsEvent;
142
+ //# sourceMappingURL=AnalyticsEvent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AnalyticsEvent.d.ts","sourceRoot":"","sources":["../../src/models/Analytics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H,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI;IAM7D;;OAEG;IACH,UAAU,IAAI,OAAO;IAIrB;;OAEG;IACH,YAAY,IAAI,OAAO;IAUvB;;OAEG;IACH,QAAQ,IAAI,IAAI;IAMhB;;OAEG;IACH,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAM/B;;OAEG;IACH,aAAa,IAAI,IAAI;IAKrB;;OAEG;IACH,WAAW,CAAC,UAAU,GAAE,MAAU,GAAG,OAAO;IAM5C;;OAEG;IACH,YAAY,IAAI;QACd,IAAI,EAAE,MAAM,CAAC;QACb,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,CAAC;QACnD,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,kBAAkB,CAAC,EAAE,OAAO,CAAC;KAC9B;CAUF;AAED,eAAe,cAAc,CAAC"}
@@ -0,0 +1,142 @@
1
+ import { SmrtObject } from '@happyvertical/smrt-core';
2
+ import { AnalyticsPropertyStatus, AnalyticsProvider } from '../types/index.js';
3
+ /**
4
+ * AnalyticsProperty represents an analytics property (GA4 property,
5
+ * Plausible site, or Matomo site).
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * const property = await properties.create({
10
+ * name: 'My Website',
11
+ * displayName: 'My Website Analytics',
12
+ * provider: AnalyticsProvider.GA4,
13
+ * externalId: 'properties/123456789',
14
+ * measurementId: 'G-XXXXXXXXXX'
15
+ * });
16
+ * ```
17
+ */
18
+ export declare class AnalyticsProperty extends SmrtObject {
19
+ /**
20
+ * Tenant ID for multi-tenancy isolation (#1410).
21
+ *
22
+ * Without tenant scoping the generated `list`/`get` API and any raw query
23
+ * return every tenant's properties — including the `@field({ sensitive })`
24
+ * `apiSecret` / `providerMetadata` credentials. `@TenantScoped` registers
25
+ * this class with the tenant interceptor so reads are auto-filtered and
26
+ * writes are bound to the active tenant context.
27
+ */
28
+ tenantId: string | null;
29
+ /**
30
+ * Internal name/identifier
31
+ */
32
+ name: string;
33
+ /**
34
+ * Human-readable display name
35
+ */
36
+ displayName: string;
37
+ /**
38
+ * Analytics provider (ga4, plausible, matomo)
39
+ */
40
+ provider: AnalyticsProvider;
41
+ /**
42
+ * External ID from the provider (e.g., "properties/123456789" for GA4,
43
+ * idSite for Matomo)
44
+ */
45
+ externalId: string;
46
+ /**
47
+ * Measurement ID for GA4 (G-XXXXXXXXXX)
48
+ */
49
+ measurementId: string;
50
+ /**
51
+ * Provider API secret/token (GA4 API secret, Matomo token_auth)
52
+ *
53
+ * Sensitive (#1540): excluded from generated API/MCP responses and rejected
54
+ * as a `where` filter key so it can't be probed.
55
+ */
56
+ apiSecret: string;
57
+ /**
58
+ * Site domain for Plausible/Matomo
59
+ */
60
+ siteDomain: string;
61
+ /**
62
+ * Property timezone
63
+ */
64
+ timeZone: string;
65
+ /**
66
+ * Currency code (e.g., 'USD', 'EUR')
67
+ */
68
+ currencyCode: string;
69
+ /**
70
+ * Industry category
71
+ */
72
+ industryCategory: string;
73
+ /**
74
+ * Service level (STANDARD, PREMIUM)
75
+ */
76
+ serviceLevel: string;
77
+ /**
78
+ * Property status
79
+ */
80
+ status: AnalyticsPropertyStatus;
81
+ /**
82
+ * Last sync timestamp with provider
83
+ */
84
+ lastSyncAt: Date | null;
85
+ /**
86
+ * Metadata from provider (JSON)
87
+ *
88
+ * Sensitive (#1540): may carry provider credentials/tokens, so it is excluded
89
+ * from generated API/MCP responses and rejected as a `where` filter key.
90
+ */
91
+ providerMetadata: string;
92
+ constructor(options?: any);
93
+ /**
94
+ * Check if this is a GA4 property
95
+ */
96
+ isGA4(): boolean;
97
+ /**
98
+ * Check if this is a Plausible site
99
+ */
100
+ isPlausible(): boolean;
101
+ /**
102
+ * Check if this is a Matomo site
103
+ */
104
+ isMatomo(): boolean;
105
+ /**
106
+ * Get parsed provider metadata
107
+ */
108
+ getProviderMetadata(): Record<string, unknown>;
109
+ /**
110
+ * Set provider metadata
111
+ */
112
+ setProviderMetadata(metadata: Record<string, unknown>): void;
113
+ /**
114
+ * Mark as synced with provider
115
+ */
116
+ markSynced(): void;
117
+ /**
118
+ * AI-powered: Analyze property performance.
119
+ *
120
+ * Uses the `smrtAnalytics.property.analyzePerformance` prompt registered
121
+ * via `@happyvertical/smrt-prompts`, allowing tenant- or instance-level
122
+ * overrides of the template, model, and parameters at runtime.
123
+ *
124
+ * Only non-PII fields (display name, provider label, requested period)
125
+ * are sent to the AI provider. Internal identifiers (`id`, `externalId`,
126
+ * `measurementId`, `apiSecret`, `providerMetadata`) are intentionally
127
+ * excluded — see `../prompts.ts` for the full exclusion rationale.
128
+ */
129
+ analyzePerformance(options?: {
130
+ period?: string;
131
+ }): Promise<{
132
+ action: string;
133
+ period: string;
134
+ analysis: string;
135
+ }>;
136
+ /**
137
+ * AI-powered: Check if property is performing well
138
+ */
139
+ isPerformingWell(): Promise<boolean>;
140
+ }
141
+ export default AnalyticsProperty;
142
+ //# sourceMappingURL=AnalyticsProperty.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AnalyticsProperty.d.ts","sourceRoot":"","sources":["../../src/models/AnalyticsProperty.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAS,UAAU,EAAQ,MAAM,0BAA0B,CAAC;AAOnE,OAAO,EAAE,uBAAuB,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAE/E;;;;;;;;;;;;;;GAcG;AACH,qBAOa,iBAAkB,SAAQ,UAAU;IAC/C;;;;;;;;OAQG;IAEH,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAQ;IAE/B;;OAEG;IACH,IAAI,EAAE,MAAM,CAAM;IAElB;;OAEG;IACH,WAAW,EAAE,MAAM,CAAM;IAEzB;;OAEG;IACH,QAAQ,E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-core';
2
+ import { ReportFrequency, ReportStatus } from '../types/index.js';
3
+ /**
4
+ * AnalyticsReport represents a saved report configuration with optional scheduling.
5
+ *
6
+ * @example
7
+ * ```typescript
8
+ * const report = await reports.create({
9
+ * propertyId: property.id,
10
+ * name: 'Weekly Traffic Report',
11
+ * dimensions: JSON.stringify([{ name: 'country' }, { name: 'deviceCategory' }]),
12
+ * metrics: JSON.stringify([{ name: 'activeUsers' }, { name: 'sessions' }]),
13
+ * frequency: ReportFrequency.WEEKLY
14
+ * });
15
+ * ```
16
+ */
17
+ export declare class AnalyticsReport extends SmrtObject {
18
+ /**
19
+ * Tenant ID for multi-tenancy isolation (#1410).
20
+ *
21
+ * Reports persist `resultData` rows that may contain tenant-private metrics
22
+ * and PII-bearing dimensions. Without tenant scoping the generated
23
+ * `list`/`get` API returns every tenant's cached report data, and the
24
+ * AI-powered `analyze`/`run` operations could run over another tenant's
25
+ * rows. `@TenantScoped` auto-filters reads and binds writes to the tenant.
26
+ */
27
+ tenantId: string | null;
28
+ /**
29
+ * Parent property ID (references AnalyticsProperty)
30
+ */
31
+ propertyId: string;
32
+ /**
33
+ * Report name
34
+ */
35
+ name: string;
36
+ /**
37
+ * Report description
38
+ */
39
+ description: string;
40
+ /**
41
+ * Dimensions to group by (JSON array)
42
+ */
43
+ dimensions: string;
44
+ /**
45
+ * Metrics to retrieve (JSON array)
46
+ */
47
+ metrics: string;
48
+ /**
49
+ * Date range start (relative or absolute)
50
+ */
51
+ dateRangeStart: string;
52
+ /**
53
+ * Date range end (relative or absolute)
54
+ */
55
+ dateRangeEnd: string;
56
+ /**
57
+ * Dimension filter expression (JSON)
58
+ */
59
+ dimensionFilter: string;
60
+ /**
61
+ * Metric filter expression (JSON)
62
+ */
63
+ metricFilter: string;
64
+ /**
65
+ * Sort order (JSON array)
66
+ */
67
+ orderBy: string;
68
+ /**
69
+ * Maximum results to return
70
+ */
71
+ maxResults: number;
72
+ /**
73
+ * Report status
74
+ */
75
+ status: ReportStatus;
76
+ /**
77
+ * Scheduling frequency
78
+ */
79
+ frequency: ReportFrequency;
80
+ /**
81
+ * Last run timestamp
82
+ */
83
+ lastRunAt: Date | null;
84
+ /**
85
+ * Next scheduled run
86
+ */
87
+ nextRunAt: Date | null;
88
+ /**
89
+ * Cached result data (JSON)
90
+ */
91
+ resultData: string;
92
+ /**
93
+ * Row count from last run
94
+ */
95
+ rowCount: number;
96
+ /**
97
+ * Error message from last failed run
98
+ */
99
+ lastError: string;
100
+ constructor(options?: any);
101
+ /**
102
+ * Get parsed dimensions
103
+ */
104
+ getDimensions(): Array<{
105
+ name: string;
106
+ }>;
107
+ /**
108
+ * Set dimensions
109
+ */
110
+ setDimensions(dimensions: Array<{
111
+ name: string;
112
+ }>): void;
113
+ /**
114
+ * Get parsed metrics
115
+ */
116
+ getMetrics(): Array<{
117
+ name: string;
118
+ }>;
119
+ /**
120
+ * Set metrics
121
+ */
122
+ setMetrics(metrics: Array<{
123
+ name: string;
124
+ }>): void;
125
+ /**
126
+ * Get parsed result data
127
+ */
128
+ getResultData(): Record<string, unknown> | null;
129
+ /**
130
+ * Set result data
131
+ */
132
+ setResultData(data: Record<string, unknown>): void;
133
+ /**
134
+ * Mark report as running
135
+ */
136
+ markRunning(): void;
137
+ /**
138
+ * Mark report as completed with results
139
+ */
140
+ markCompleted(rowCount: number): void;
141
+ /**
142
+ * Mark report as failed
143
+ */
144
+ markFailed(error: string): void;
145
+ /**
146
+ * Calculate next scheduled run based on frequency
147
+ */
148
+ calculateNextRun(): void;
149
+ /**
150
+ * Check if report is due to run
151
+ */
152
+ isDue(): boolean;
153
+ /**
154
+ * AI-powered: Analyze report results.
155
+ *
156
+ * Uses the `smrtAnalytics.report.analyzeResults` prompt registered via
157
+ * `@happyvertical/smrt-prompts`, allowing tenant- or instance-level
158
+ * overrides of the template, model, and parameters at runtime.
159
+ *
160
+ * Internal identifiers (`id`, `propertyId`, `tenantId`, `lastError`, raw
161
+ * `dimensionFilter` / `metricFilter` JSON) are excluded from the prompt
162
+ * variables — see `../prompts.ts` for the exclusion rationale.
163
+ *
164
+ * **`resultData` is FORWARDED VERBATIM.** The persisted result rows are
165
+ * JSON-stringified into the `reportData` variable; this package cannot
166
+ * strip PII because the row schema is determined by which dimensions /
167
+ * metrics the caller asked the analytics provider to return. If the
168
+ * persisted rows contain `userPseudoId`, `clientId`, IP-derived
169
+ * geolocation, or any other identifier, those fields WILL reach the AI
170
+ * provider. Callers are responsible for excluding PII-bearing dimensions
171
+ * before persisting, applying a column allowlist at the call site, or
172
+ * overriding the prompt template via `PromptOverride`. The forwarding is
173
+ * pinned by a regression test in
174
+ * `__tests__/analytics-report-prompt.test.ts`.
175
+ *
176
+ * The previous implementation issued a second freeform `this.do()` call
177
+ * to re-summarize "top 3 insights"; that behaviour is now folded into
178
+ * the single registered template (which already asks for findings,
179
+ * trends, and recommendations) — `insights` mirrors `analysis` so the
180
+ * return shape is preserved without a redundant AI round-trip.
181
+ */
182
+ analyzeResults(_options?: any): Promise<{
183
+ action: string;
184
+ analysis: string;
185
+ insights: string;
186
+ }>;
187
+ /**
188
+ * AI-powered: Check if results show positive trends.
189
+ *
190
+ * Uses the `smrtAnalytics.report.hasPositiveTrends` prompt registered
191
+ * via `@happyvertical/smrt-prompts`. Only the metric labels and the
192
+ * aggregate `resultData` JSON are sent to the AI provider — though as
193
+ * with `analyzeResults`, `resultData` is forwarded verbatim and may
194
+ * carry PII the caller persisted; see `analyzeResults` docstring and
195
+ * `../prompts.ts`.
196
+ *
197
+ * Boolean coercion uses `/^\s*(yes|true)\b/i` against the trimmed
198
+ * response. The registered prompt template explicitly instructs the
199
+ * model to begin its answer with the literal word "yes" or "no" so
200
+ * this regex is reliable; tenant overrides MUST preserve that leading-
201
+ * word convention or the boolean will silently fall to `false`.
202
+ */
203
+ hasPositiveTrends(): Promise<boolean>;
204
+ }
205
+ export default AnalyticsReport;
206
+ //# sourceMappingURL=AnalyticsReport.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Analy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E,CAAC;IAQxC;;OAEG;IACH,aAAa,CAAC,UAAU,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,GAAG,IAAI;IAIxD;;OAEG;IACH,UAAU,IAAI,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IAQrC;;OAEG;IACH,UAAU,CAAC,OAAO,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,GAAG,IAAI;IAIlD;;OAEG;IACH,aAAa,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;IAS/C;;OAEG;IACH,aAAa,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI;IAIlD;;OAEG;IACH,WAAW,IAAI,IAAI;IAKnB;;OAEG;IACH,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI;IAQrC;;OAEG;IACH,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAO/B;;OAEG;IACH,gBAAgB,IAAI,IAAI;IAwBxB;;OAEG;IACH,KAAK,IAAI,OAAO;IAQhB;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA4BG;IACG,cAAc,CAAC,QAAQ,GAAE,GAAQ,GAAG,OAAO,CAAC;QAChD,MAAM,EAAE,MAAM,CAAC;QACf,QAAQ,EAAE,MAAM,CAAC;QACjB,QAAQ,EAAE,MAAM,CAAC;KAClB,CAAC;IAiDF;;;;;;;;;;;;;;;OAeG;IACG,iBAAiB,IAAI,OAAO,CAAC,OAAO,CAAC;CA2B5C;AAED,eAAe,eAAe,CAAC"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Model exports for smrt-analytics
3
+ */
4
+ export { AnalyticsDataStream } from './AnalyticsDataStream.js';
5
+ export { AnalyticsEvent } from './AnalyticsEvent.js';
6
+ export { AnalyticsProperty } from './AnalyticsProperty.js';
7
+ export { AnalyticsReport } from './AnalyticsReport.js';
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/models/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { default } from './svelte/playground.js';
2
+ //# sourceMappingURL=playground.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"playground.d.ts","sourceRoot":"","sources":["../src/playground.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC"}