@contractspec/example.analytics-dashboard 1.56.1 → 1.58.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 (171) hide show
  1. package/dist/browser/dashboard/dashboard.enum.js +34 -0
  2. package/dist/browser/dashboard/dashboard.operation.js +289 -0
  3. package/dist/browser/dashboard/dashboard.presentation.js +197 -0
  4. package/dist/browser/dashboard/dashboard.schema.js +126 -0
  5. package/dist/browser/dashboard/dashboard.test-spec.js +213 -0
  6. package/dist/browser/dashboard/index.js +299 -0
  7. package/dist/browser/dashboard.feature.js +84 -0
  8. package/dist/browser/datasource/posthog-datasource.js +289 -0
  9. package/dist/browser/docs/analytics-dashboard.docblock.js +103 -0
  10. package/dist/browser/docs/index.js +103 -0
  11. package/dist/browser/events.js +81 -0
  12. package/dist/browser/example.js +42 -0
  13. package/dist/browser/handlers/analytics.handlers.js +278 -0
  14. package/dist/browser/handlers/index.js +571 -0
  15. package/dist/browser/handlers/query.handlers.js +294 -0
  16. package/dist/browser/index.js +1677 -0
  17. package/dist/browser/query/index.js +159 -0
  18. package/dist/browser/query/query.enum.js +11 -0
  19. package/dist/browser/query/query.operation.js +154 -0
  20. package/dist/browser/query/query.presentation.js +119 -0
  21. package/dist/browser/query/query.schema.js +70 -0
  22. package/dist/browser/query/query.test-spec.js +113 -0
  23. package/dist/browser/query-engine/index.js +491 -0
  24. package/dist/browser/seeders/index.js +20 -0
  25. package/dist/browser/ui/AnalyticsDashboard.js +394 -0
  26. package/dist/browser/ui/hooks/index.js +69 -0
  27. package/dist/browser/ui/hooks/useAnalyticsData.js +66 -0
  28. package/dist/browser/ui/index.js +671 -0
  29. package/dist/browser/ui/renderers/analytics.markdown.js +275 -0
  30. package/dist/browser/ui/renderers/index.js +275 -0
  31. package/dist/dashboard/dashboard.enum.d.ts +3 -8
  32. package/dist/dashboard/dashboard.enum.d.ts.map +1 -1
  33. package/dist/dashboard/dashboard.enum.js +31 -39
  34. package/dist/dashboard/dashboard.operation.d.ts +444 -450
  35. package/dist/dashboard/dashboard.operation.d.ts.map +1 -1
  36. package/dist/dashboard/dashboard.operation.js +284 -207
  37. package/dist/dashboard/dashboard.presentation.d.ts +3 -8
  38. package/dist/dashboard/dashboard.presentation.d.ts.map +1 -1
  39. package/dist/dashboard/dashboard.presentation.js +193 -85
  40. package/dist/dashboard/dashboard.schema.d.ts +289 -294
  41. package/dist/dashboard/dashboard.schema.d.ts.map +1 -1
  42. package/dist/dashboard/dashboard.schema.js +119 -228
  43. package/dist/dashboard/dashboard.test-spec.d.ts +4 -9
  44. package/dist/dashboard/dashboard.test-spec.d.ts.map +1 -1
  45. package/dist/dashboard/dashboard.test-spec.js +209 -228
  46. package/dist/dashboard/index.d.ts +7 -4
  47. package/dist/dashboard/index.d.ts.map +1 -0
  48. package/dist/dashboard/index.js +299 -4
  49. package/dist/dashboard.feature.d.ts +1 -7
  50. package/dist/dashboard.feature.d.ts.map +1 -1
  51. package/dist/dashboard.feature.js +83 -175
  52. package/dist/datasource/posthog-datasource.d.ts +18 -0
  53. package/dist/datasource/posthog-datasource.d.ts.map +1 -0
  54. package/dist/datasource/posthog-datasource.js +290 -0
  55. package/dist/docs/analytics-dashboard.docblock.d.ts +2 -1
  56. package/dist/docs/analytics-dashboard.docblock.d.ts.map +1 -0
  57. package/dist/docs/analytics-dashboard.docblock.js +46 -56
  58. package/dist/docs/index.d.ts +2 -1
  59. package/dist/docs/index.d.ts.map +1 -0
  60. package/dist/docs/index.js +104 -1
  61. package/dist/events.d.ts +109 -115
  62. package/dist/events.d.ts.map +1 -1
  63. package/dist/events.js +74 -120
  64. package/dist/example.d.ts +2 -6
  65. package/dist/example.d.ts.map +1 -1
  66. package/dist/example.js +40 -55
  67. package/dist/handlers/analytics.handlers.d.ts +110 -110
  68. package/dist/handlers/analytics.handlers.d.ts.map +1 -1
  69. package/dist/handlers/analytics.handlers.js +267 -298
  70. package/dist/handlers/index.d.ts +3 -2
  71. package/dist/handlers/index.d.ts.map +1 -0
  72. package/dist/handlers/index.js +571 -2
  73. package/dist/handlers/query.handlers.d.ts +9 -0
  74. package/dist/handlers/query.handlers.d.ts.map +1 -0
  75. package/dist/handlers/query.handlers.js +295 -0
  76. package/dist/index.d.ts +12 -12
  77. package/dist/index.d.ts.map +1 -0
  78. package/dist/index.js +1678 -13
  79. package/dist/node/dashboard/dashboard.enum.js +34 -0
  80. package/dist/node/dashboard/dashboard.operation.js +289 -0
  81. package/dist/node/dashboard/dashboard.presentation.js +197 -0
  82. package/dist/node/dashboard/dashboard.schema.js +126 -0
  83. package/dist/node/dashboard/dashboard.test-spec.js +213 -0
  84. package/dist/node/dashboard/index.js +299 -0
  85. package/dist/node/dashboard.feature.js +84 -0
  86. package/dist/node/datasource/posthog-datasource.js +289 -0
  87. package/dist/node/docs/analytics-dashboard.docblock.js +103 -0
  88. package/dist/node/docs/index.js +103 -0
  89. package/dist/node/events.js +81 -0
  90. package/dist/node/example.js +42 -0
  91. package/dist/node/handlers/analytics.handlers.js +278 -0
  92. package/dist/node/handlers/index.js +571 -0
  93. package/dist/node/handlers/query.handlers.js +294 -0
  94. package/dist/node/index.js +1677 -0
  95. package/dist/node/query/index.js +159 -0
  96. package/dist/node/query/query.enum.js +11 -0
  97. package/dist/node/query/query.operation.js +154 -0
  98. package/dist/node/query/query.presentation.js +119 -0
  99. package/dist/node/query/query.schema.js +70 -0
  100. package/dist/node/query/query.test-spec.js +113 -0
  101. package/dist/node/query-engine/index.js +491 -0
  102. package/dist/node/seeders/index.js +20 -0
  103. package/dist/node/ui/AnalyticsDashboard.js +394 -0
  104. package/dist/node/ui/hooks/index.js +69 -0
  105. package/dist/node/ui/hooks/useAnalyticsData.js +66 -0
  106. package/dist/node/ui/index.js +671 -0
  107. package/dist/node/ui/renderers/analytics.markdown.js +275 -0
  108. package/dist/node/ui/renderers/index.js +275 -0
  109. package/dist/query/index.d.ts +7 -4
  110. package/dist/query/index.d.ts.map +1 -0
  111. package/dist/query/index.js +159 -4
  112. package/dist/query/query.enum.d.ts +1 -6
  113. package/dist/query/query.enum.d.ts.map +1 -1
  114. package/dist/query/query.enum.js +10 -14
  115. package/dist/query/query.operation.d.ts +148 -154
  116. package/dist/query/query.operation.d.ts.map +1 -1
  117. package/dist/query/query.operation.js +151 -109
  118. package/dist/query/query.presentation.d.ts +2 -7
  119. package/dist/query/query.presentation.d.ts.map +1 -1
  120. package/dist/query/query.presentation.js +116 -56
  121. package/dist/query/query.schema.d.ts +121 -126
  122. package/dist/query/query.schema.d.ts.map +1 -1
  123. package/dist/query/query.schema.js +66 -152
  124. package/dist/query/query.test-spec.d.ts +2 -7
  125. package/dist/query/query.test-spec.d.ts.map +1 -1
  126. package/dist/query/query.test-spec.js +111 -121
  127. package/dist/query-engine/index.d.ts +84 -86
  128. package/dist/query-engine/index.d.ts.map +1 -1
  129. package/dist/query-engine/index.js +490 -187
  130. package/dist/seeders/index.d.ts +4 -8
  131. package/dist/seeders/index.d.ts.map +1 -1
  132. package/dist/seeders/index.js +18 -16
  133. package/dist/ui/AnalyticsDashboard.d.ts +1 -6
  134. package/dist/ui/AnalyticsDashboard.d.ts.map +1 -1
  135. package/dist/ui/AnalyticsDashboard.js +389 -259
  136. package/dist/ui/hooks/index.d.ts +2 -2
  137. package/dist/ui/hooks/index.d.ts.map +1 -0
  138. package/dist/ui/hooks/index.js +69 -4
  139. package/dist/ui/hooks/useAnalyticsData.d.ts +16 -20
  140. package/dist/ui/hooks/useAnalyticsData.d.ts.map +1 -1
  141. package/dist/ui/hooks/useAnalyticsData.js +63 -69
  142. package/dist/ui/index.d.ts +7 -6
  143. package/dist/ui/index.d.ts.map +1 -0
  144. package/dist/ui/index.js +671 -5
  145. package/dist/ui/renderers/analytics.markdown.d.ts +13 -15
  146. package/dist/ui/renderers/analytics.markdown.d.ts.map +1 -1
  147. package/dist/ui/renderers/analytics.markdown.js +266 -254
  148. package/dist/ui/renderers/index.d.ts +2 -2
  149. package/dist/ui/renderers/index.d.ts.map +1 -0
  150. package/dist/ui/renderers/index.js +275 -2
  151. package/package.json +329 -62
  152. package/dist/dashboard/dashboard.enum.js.map +0 -1
  153. package/dist/dashboard/dashboard.operation.js.map +0 -1
  154. package/dist/dashboard/dashboard.presentation.js.map +0 -1
  155. package/dist/dashboard/dashboard.schema.js.map +0 -1
  156. package/dist/dashboard/dashboard.test-spec.js.map +0 -1
  157. package/dist/dashboard.feature.js.map +0 -1
  158. package/dist/docs/analytics-dashboard.docblock.js.map +0 -1
  159. package/dist/events.js.map +0 -1
  160. package/dist/example.js.map +0 -1
  161. package/dist/handlers/analytics.handlers.js.map +0 -1
  162. package/dist/query/query.enum.js.map +0 -1
  163. package/dist/query/query.operation.js.map +0 -1
  164. package/dist/query/query.presentation.js.map +0 -1
  165. package/dist/query/query.schema.js.map +0 -1
  166. package/dist/query/query.test-spec.js.map +0 -1
  167. package/dist/query-engine/index.js.map +0 -1
  168. package/dist/seeders/index.js.map +0 -1
  169. package/dist/ui/AnalyticsDashboard.js.map +0 -1
  170. package/dist/ui/hooks/useAnalyticsData.js.map +0 -1
  171. package/dist/ui/renderers/analytics.markdown.js.map +0 -1
@@ -0,0 +1,290 @@
1
+ // @bun
2
+ // src/datasource/posthog-datasource.ts
3
+ class PosthogQueryEngine {
4
+ reader;
5
+ defaultLimit;
6
+ constructor(reader, options = {}) {
7
+ this.reader = reader;
8
+ this.defaultLimit = options.defaultLimit ?? 100;
9
+ }
10
+ async execute(definition, params) {
11
+ const startTime = Date.now();
12
+ const validation = this.validateQuery(definition);
13
+ if (!validation.valid) {
14
+ return {
15
+ data: [],
16
+ columns: [],
17
+ rowCount: 0,
18
+ executionTimeMs: Date.now() - startTime,
19
+ cached: false,
20
+ error: validation.errors.join(", ")
21
+ };
22
+ }
23
+ if (!this.reader.queryHogQL) {
24
+ return {
25
+ data: [],
26
+ columns: [],
27
+ rowCount: 0,
28
+ executionTimeMs: Date.now() - startTime,
29
+ cached: false,
30
+ error: "Analytics reader does not support HogQL queries."
31
+ };
32
+ }
33
+ try {
34
+ const result = await this.executeHogQL(definition, params);
35
+ return {
36
+ data: result.data,
37
+ columns: result.columns,
38
+ rowCount: result.rowCount,
39
+ executionTimeMs: Date.now() - startTime,
40
+ cached: false
41
+ };
42
+ } catch (error) {
43
+ return {
44
+ data: [],
45
+ columns: [],
46
+ rowCount: 0,
47
+ executionTimeMs: Date.now() - startTime,
48
+ cached: false,
49
+ error: error instanceof Error ? error.message : "Unknown error"
50
+ };
51
+ }
52
+ }
53
+ validateQuery(definition) {
54
+ const errors = [];
55
+ if (definition.type === "SQL" && !definition.sql) {
56
+ errors.push("SQL query is missing.");
57
+ }
58
+ if (definition.type === "AGGREGATION" && !definition.aggregation) {
59
+ errors.push("Aggregation definition is missing.");
60
+ }
61
+ if (definition.type === "METRIC" && !definition.metricIds?.length) {
62
+ errors.push("Metric IDs are missing.");
63
+ }
64
+ if (definition.type === "CUSTOM" && !definition.custom?.handler) {
65
+ errors.push("Custom handler is missing.");
66
+ }
67
+ return { valid: errors.length === 0, errors };
68
+ }
69
+ async executeHogQL(definition, params) {
70
+ if (!this.reader.queryHogQL) {
71
+ throw new Error("Analytics reader does not support HogQL queries.");
72
+ }
73
+ if (definition.type === "SQL") {
74
+ const result = await this.reader.queryHogQL({
75
+ query: definition.sql ?? "",
76
+ values: params.parameters ?? {}
77
+ });
78
+ return mapHogqlResult(result);
79
+ }
80
+ if (definition.type === "AGGREGATION" && definition.aggregation) {
81
+ const { query, values } = buildAggregationQuery(definition.aggregation, params);
82
+ const result = await this.reader.queryHogQL({ query, values });
83
+ return mapHogqlResult(result);
84
+ }
85
+ if (definition.type === "METRIC" && definition.metricIds) {
86
+ const { query, values } = buildMetricQuery(definition.metricIds, params);
87
+ const result = await this.reader.queryHogQL({ query, values });
88
+ return mapHogqlResult(result);
89
+ }
90
+ throw new Error("Unsupported query type for PostHog datasource.");
91
+ }
92
+ }
93
+ function createPosthogQueryEngine(reader, options) {
94
+ return new PosthogQueryEngine(reader, options);
95
+ }
96
+ function buildMetricQuery(metricIds, params) {
97
+ const range = resolveDateRange(params);
98
+ const values = {
99
+ dateFrom: range?.from.toISOString(),
100
+ dateTo: range?.to.toISOString()
101
+ };
102
+ const metricClauses = metricIds.map((metricId, index) => {
103
+ values[`metric${index}`] = metricId;
104
+ return `event = {metric${index}}`;
105
+ });
106
+ const whereClauses = [
107
+ metricClauses.length ? `(${metricClauses.join(" or ")})` : "",
108
+ range ? "timestamp >= {dateFrom} and timestamp < {dateTo}" : ""
109
+ ].filter(Boolean).join(" and ");
110
+ return {
111
+ query: [
112
+ "select",
113
+ " event as metric,",
114
+ " count() as total",
115
+ "from events",
116
+ whereClauses ? `where ${whereClauses}` : "",
117
+ "group by metric"
118
+ ].filter(Boolean).join(`
119
+ `),
120
+ values
121
+ };
122
+ }
123
+ function buildAggregationQuery(aggregation, params) {
124
+ const measures = aggregation.measures.map((measure) => ({
125
+ ...measure,
126
+ expression: buildMeasureExpression(measure.field, measure.aggregation)
127
+ }));
128
+ const dimensions = aggregation.dimensions.map((dimension) => ({
129
+ ...dimension,
130
+ expression: buildDimensionExpression(dimension.field, dimension.type, dimension.granularity)
131
+ }));
132
+ const selections = [
133
+ ...dimensions.map((dimension) => `${dimension.expression} as ${dimension.name}`),
134
+ ...measures.map((measure) => `${measure.expression} as ${measure.name}`)
135
+ ];
136
+ const values = {};
137
+ const filters = buildFilterClauses(aggregation, params, values);
138
+ const limit = aggregation.limit ?? 100;
139
+ const orderBy = aggregation.orderBy?.length ? `order by ${aggregation.orderBy.map((order) => `${order.field} ${order.direction}`).join(", ")}` : "";
140
+ return {
141
+ query: [
142
+ "select",
143
+ ` ${selections.join(`,
144
+ `)}`,
145
+ `from ${aggregation.source}`,
146
+ filters.length ? `where ${filters.join(" and ")}` : "",
147
+ dimensions.length ? `group by ${dimensions.map((d) => d.name).join(", ")}` : "",
148
+ orderBy,
149
+ `limit ${limit}`
150
+ ].filter(Boolean).join(`
151
+ `),
152
+ values
153
+ };
154
+ }
155
+ function buildMeasureExpression(field, aggregation) {
156
+ switch (aggregation) {
157
+ case "COUNT":
158
+ return field === "*" ? "count()" : `count(${field})`;
159
+ case "COUNT_DISTINCT":
160
+ return `countDistinct(${field})`;
161
+ case "SUM":
162
+ return `sum(${field})`;
163
+ case "AVG":
164
+ return `avg(${field})`;
165
+ case "MIN":
166
+ return `min(${field})`;
167
+ case "MAX":
168
+ return `max(${field})`;
169
+ default:
170
+ return `count(${field})`;
171
+ }
172
+ }
173
+ function buildDimensionExpression(field, type, granularity) {
174
+ if (type === "TIME") {
175
+ switch (granularity) {
176
+ case "HOUR":
177
+ return `toStartOfHour(${field})`;
178
+ case "WEEK":
179
+ return `toStartOfWeek(${field})`;
180
+ case "MONTH":
181
+ return `toStartOfMonth(${field})`;
182
+ case "YEAR":
183
+ return `toStartOfYear(${field})`;
184
+ case "DAY":
185
+ default:
186
+ return `toStartOfDay(${field})`;
187
+ }
188
+ }
189
+ return field;
190
+ }
191
+ function buildFilterClauses(aggregation, params, values) {
192
+ const clauses = [];
193
+ const range = resolveDateRange(params);
194
+ if (range) {
195
+ values.dateFrom = range.from.toISOString();
196
+ values.dateTo = range.to.toISOString();
197
+ clauses.push(`timestamp >= {dateFrom} and timestamp < {dateTo}`);
198
+ }
199
+ aggregation.filters?.forEach((filter, index) => {
200
+ const key = `filter${index}`;
201
+ switch (filter.operator) {
202
+ case "eq":
203
+ values[key] = filter.value;
204
+ clauses.push(`${filter.field} = {${key}}`);
205
+ break;
206
+ case "neq":
207
+ values[key] = filter.value;
208
+ clauses.push(`${filter.field} != {${key}}`);
209
+ break;
210
+ case "gt":
211
+ values[key] = filter.value;
212
+ clauses.push(`${filter.field} > {${key}}`);
213
+ break;
214
+ case "gte":
215
+ values[key] = filter.value;
216
+ clauses.push(`${filter.field} >= {${key}}`);
217
+ break;
218
+ case "lt":
219
+ values[key] = filter.value;
220
+ clauses.push(`${filter.field} < {${key}}`);
221
+ break;
222
+ case "lte":
223
+ values[key] = filter.value;
224
+ clauses.push(`${filter.field} <= {${key}}`);
225
+ break;
226
+ case "contains":
227
+ values[key] = filter.value;
228
+ clauses.push(`${filter.field} LIKE '%' || {${key}} || '%'`);
229
+ break;
230
+ case "between": {
231
+ if (Array.isArray(filter.value) && filter.value.length >= 2) {
232
+ values[`${key}Start`] = filter.value[0];
233
+ values[`${key}End`] = filter.value[1];
234
+ clauses.push(`${filter.field} BETWEEN {${key}Start} AND {${key}End}`);
235
+ }
236
+ break;
237
+ }
238
+ case "in":
239
+ case "nin":
240
+ if (Array.isArray(filter.value)) {
241
+ const placeholders = [];
242
+ filter.value.forEach((value, valueIndex) => {
243
+ const valueKey = `${key}_${valueIndex}`;
244
+ values[valueKey] = value;
245
+ placeholders.push(`{${valueKey}}`);
246
+ });
247
+ if (placeholders.length) {
248
+ clauses.push(`${filter.field} ${filter.operator === "in" ? "IN" : "NOT IN"} (${placeholders.join(", ")})`);
249
+ }
250
+ }
251
+ break;
252
+ default:
253
+ break;
254
+ }
255
+ });
256
+ return clauses;
257
+ }
258
+ function resolveDateRange(params) {
259
+ const range = params.dateRange;
260
+ if (!range)
261
+ return null;
262
+ return { from: range.start, to: range.end };
263
+ }
264
+ function mapHogqlResult(result) {
265
+ if (!Array.isArray(result.results) || !Array.isArray(result.columns)) {
266
+ return { data: [], columns: [], rowCount: 0 };
267
+ }
268
+ const columns = result.columns.map((name) => ({
269
+ name,
270
+ type: "STRING"
271
+ }));
272
+ const data = result.results.map((row) => {
273
+ if (!Array.isArray(row))
274
+ return {};
275
+ const record = {};
276
+ result.columns?.forEach((column, index) => {
277
+ record[column] = row[index];
278
+ });
279
+ return record;
280
+ });
281
+ return {
282
+ data,
283
+ columns,
284
+ rowCount: data.length
285
+ };
286
+ }
287
+ export {
288
+ createPosthogQueryEngine,
289
+ PosthogQueryEngine
290
+ };
@@ -1 +1,2 @@
1
- export { };
1
+ export {};
2
+ //# sourceMappingURL=analytics-dashboard.docblock.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"analytics-dashboard.docblock.d.ts","sourceRoot":"","sources":["../../src/docs/analytics-dashboard.docblock.ts"],"names":[],"mappings":""}
@@ -1,21 +1,16 @@
1
+ // @bun
2
+ // src/docs/analytics-dashboard.docblock.ts
1
3
  import { registerDocBlocks } from "@contractspec/lib.contracts/docs";
2
-
3
- //#region src/docs/analytics-dashboard.docblock.ts
4
- registerDocBlocks([
5
- {
6
- id: "docs.examples.analytics-dashboard",
7
- title: "Analytics Dashboard",
8
- summary: "Multi-tenant analytics with dashboards, widgets, query builder, and scheduled reports built on the Event Bus.",
9
- kind: "reference",
10
- visibility: "public",
11
- route: "/docs/examples/analytics-dashboard",
12
- tags: [
13
- "analytics",
14
- "dashboards",
15
- "bi",
16
- "queries"
17
- ],
18
- body: `## Entities
4
+ var analyticsDashboardDocBlocks = [
5
+ {
6
+ id: "docs.examples.analytics-dashboard",
7
+ title: "Analytics Dashboard",
8
+ summary: "Multi-tenant analytics with dashboards, widgets, query builder, and scheduled reports built on the Event Bus.",
9
+ kind: "reference",
10
+ visibility: "public",
11
+ route: "/docs/examples/analytics-dashboard",
12
+ tags: ["analytics", "dashboards", "bi", "queries"],
13
+ body: `## Entities
19
14
 
20
15
  - Dashboard, Widget, Query, Report.
21
16
  - Widget/query configs stay declarative for regeneration.
@@ -39,17 +34,18 @@ registerDocBlocks([
39
34
 
40
35
  - Enforce org scoping for multi-tenant isolation.
41
36
  - Use Feature Flags for beta widgets; Metering to track query volume.
37
+ - PostHog datasource can back query execution via HogQL for dashboard widgets.
42
38
  `
43
- },
44
- {
45
- id: "docs.examples.analytics-dashboard.goal",
46
- title: "Analytics Dashboard Goal",
47
- summary: "Why this template matters and what success looks like.",
48
- kind: "goal",
49
- visibility: "public",
50
- route: "/docs/examples/analytics-dashboard/goal",
51
- tags: ["analytics", "goal"],
52
- body: `## Why it matters
39
+ },
40
+ {
41
+ id: "docs.examples.analytics-dashboard.goal",
42
+ title: "Analytics Dashboard \u2014 Goal",
43
+ summary: "Why this template matters and what success looks like.",
44
+ kind: "goal",
45
+ visibility: "public",
46
+ route: "/docs/examples/analytics-dashboard/goal",
47
+ tags: ["analytics", "goal"],
48
+ body: `## Why it matters
53
49
  - Give teams a regenerable analytics workspace that stays in sync with Event Bus, Usage/Metering, and presentations.
54
50
  - Avoid dashboard drift by keeping schema-first widgets/queries.
55
51
 
@@ -60,16 +56,16 @@ registerDocBlocks([
60
56
  ## Success criteria
61
57
  - Dashboards can be regenerated safely from spec changes.
62
58
  - Queries/widgets have enforced validation; PII is redacted per policy.`
63
- },
64
- {
65
- id: "docs.examples.analytics-dashboard.usage",
66
- title: "Analytics Dashboard Usage",
67
- summary: "How to seed, extend, and safely regenerate dashboards.",
68
- kind: "usage",
69
- visibility: "public",
70
- route: "/docs/examples/analytics-dashboard/usage",
71
- tags: ["analytics", "usage"],
72
- body: `## Setup
59
+ },
60
+ {
61
+ id: "docs.examples.analytics-dashboard.usage",
62
+ title: "Analytics Dashboard \u2014 Usage",
63
+ summary: "How to seed, extend, and safely regenerate dashboards.",
64
+ kind: "usage",
65
+ visibility: "public",
66
+ route: "/docs/examples/analytics-dashboard/usage",
67
+ tags: ["analytics", "usage"],
68
+ body: `## Setup
73
69
  1) Seed dashboards/widgets (via template registry) to preload sample queries.
74
70
  2) Configure org/tenant scope and attach Usage/Metering for cost/sampling controls.
75
71
 
@@ -81,20 +77,16 @@ registerDocBlocks([
81
77
  ## Guardrails
82
78
  - Keep all query inputs validated; mark PII paths in policy.
83
79
  - Use Audit Trail for report deliveries; Notifications for scheduled sends.`
84
- },
85
- {
86
- id: "docs.examples.analytics-dashboard.constraints",
87
- title: "Analytics Dashboard Constraints & Safety",
88
- summary: "Internal guardrails for queries, widgets, and regeneration.",
89
- kind: "reference",
90
- visibility: "internal",
91
- route: "/docs/examples/analytics-dashboard/constraints",
92
- tags: [
93
- "analytics",
94
- "constraints",
95
- "internal"
96
- ],
97
- body: `## Constraints
80
+ },
81
+ {
82
+ id: "docs.examples.analytics-dashboard.constraints",
83
+ title: "Analytics Dashboard \u2014 Constraints & Safety",
84
+ summary: "Internal guardrails for queries, widgets, and regeneration.",
85
+ kind: "reference",
86
+ visibility: "internal",
87
+ route: "/docs/examples/analytics-dashboard/constraints",
88
+ tags: ["analytics", "constraints", "internal"],
89
+ body: `## Constraints
98
90
  - Queries and widgets must declare inputs/validation in spec; no ad-hoc query strings.
99
91
  - Regeneration must preserve sampling/windowing semantics; document changes explicitly.
100
92
  - Events/usage metrics should remain consistent with Metering/Audit wiring.
@@ -107,8 +99,6 @@ registerDocBlocks([
107
99
  - Add fixtures for widget/query schema changes and scheduled reports.
108
100
  - Run regeneration diff when adjusting query builders; ensure UI/markdown targets updated.
109
101
  - Confirm feature-flagged widgets default to safe/off for new tenants.`
110
- }
111
- ]);
112
-
113
- //#endregion
114
- //# sourceMappingURL=analytics-dashboard.docblock.js.map
102
+ }
103
+ ];
104
+ registerDocBlocks(analyticsDashboardDocBlocks);
@@ -1 +1,2 @@
1
- export { };
1
+ import './analytics-dashboard.docblock';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/docs/index.ts"],"names":[],"mappings":"AAAA,OAAO,gCAAgC,CAAC"}
@@ -1 +1,104 @@
1
- import "./analytics-dashboard.docblock.js";
1
+ // @bun
2
+ // src/docs/analytics-dashboard.docblock.ts
3
+ import { registerDocBlocks } from "@contractspec/lib.contracts/docs";
4
+ var analyticsDashboardDocBlocks = [
5
+ {
6
+ id: "docs.examples.analytics-dashboard",
7
+ title: "Analytics Dashboard",
8
+ summary: "Multi-tenant analytics with dashboards, widgets, query builder, and scheduled reports built on the Event Bus.",
9
+ kind: "reference",
10
+ visibility: "public",
11
+ route: "/docs/examples/analytics-dashboard",
12
+ tags: ["analytics", "dashboards", "bi", "queries"],
13
+ body: `## Entities
14
+
15
+ - Dashboard, Widget, Query, Report.
16
+ - Widget/query configs stay declarative for regeneration.
17
+
18
+ ## Contracts
19
+
20
+ - \`analytics.dashboard.create\`, \`analytics.widget.add\`, \`analytics.query.execute\`, \`analytics.dashboard.get\`.
21
+ - Metrics can source from Event Bus schemas and Usage/Metering module.
22
+
23
+ ## Events
24
+
25
+ - dashboard.created/updated, widget.added, report.scheduled/sent.
26
+ - Emitted for audit + notification hooks.
27
+
28
+ ## UI / Presentations
29
+
30
+ - Dashboard list, dashboard view, query builder, widget gallery.
31
+ - Registered under \`analytics-dashboard\` template in Template Registry.
32
+
33
+ ## Notes
34
+
35
+ - Enforce org scoping for multi-tenant isolation.
36
+ - Use Feature Flags for beta widgets; Metering to track query volume.
37
+ - PostHog datasource can back query execution via HogQL for dashboard widgets.
38
+ `
39
+ },
40
+ {
41
+ id: "docs.examples.analytics-dashboard.goal",
42
+ title: "Analytics Dashboard \u2014 Goal",
43
+ summary: "Why this template matters and what success looks like.",
44
+ kind: "goal",
45
+ visibility: "public",
46
+ route: "/docs/examples/analytics-dashboard/goal",
47
+ tags: ["analytics", "goal"],
48
+ body: `## Why it matters
49
+ - Give teams a regenerable analytics workspace that stays in sync with Event Bus, Usage/Metering, and presentations.
50
+ - Avoid dashboard drift by keeping schema-first widgets/queries.
51
+
52
+ ## Business/Product goal
53
+ - Deliver tenant-scoped dashboards, governed queries, and scheduled reports with clear ownership and auditability.
54
+ - Enable feature-flagged rollout of new widgets and sampling for cost control.
55
+
56
+ ## Success criteria
57
+ - Dashboards can be regenerated safely from spec changes.
58
+ - Queries/widgets have enforced validation; PII is redacted per policy.`
59
+ },
60
+ {
61
+ id: "docs.examples.analytics-dashboard.usage",
62
+ title: "Analytics Dashboard \u2014 Usage",
63
+ summary: "How to seed, extend, and safely regenerate dashboards.",
64
+ kind: "usage",
65
+ visibility: "public",
66
+ route: "/docs/examples/analytics-dashboard/usage",
67
+ tags: ["analytics", "usage"],
68
+ body: `## Setup
69
+ 1) Seed dashboards/widgets (via template registry) to preload sample queries.
70
+ 2) Configure org/tenant scope and attach Usage/Metering for cost/sampling controls.
71
+
72
+ ## Extend & regenerate
73
+ 1) Add or modify widget/query schemas in the spec (inputs, validation, PII paths).
74
+ 2) Regenerate to update UI + API + events; review presentations for redaction.
75
+ 3) Use Feature Flags to roll out new widgets or sampling knobs gradually.
76
+
77
+ ## Guardrails
78
+ - Keep all query inputs validated; mark PII paths in policy.
79
+ - Use Audit Trail for report deliveries; Notifications for scheduled sends.`
80
+ },
81
+ {
82
+ id: "docs.examples.analytics-dashboard.constraints",
83
+ title: "Analytics Dashboard \u2014 Constraints & Safety",
84
+ summary: "Internal guardrails for queries, widgets, and regeneration.",
85
+ kind: "reference",
86
+ visibility: "internal",
87
+ route: "/docs/examples/analytics-dashboard/constraints",
88
+ tags: ["analytics", "constraints", "internal"],
89
+ body: `## Constraints
90
+ - Queries and widgets must declare inputs/validation in spec; no ad-hoc query strings.
91
+ - Regeneration must preserve sampling/windowing semantics; document changes explicitly.
92
+ - Events/usage metrics should remain consistent with Metering/Audit wiring.
93
+
94
+ ## PII & Data
95
+ - Mark PII paths (user ids, emails) in presentations for redaction.
96
+ - Avoid exposing raw query payloads in MCP/web without policy checks.
97
+
98
+ ## Verification
99
+ - Add fixtures for widget/query schema changes and scheduled reports.
100
+ - Run regeneration diff when adjusting query builders; ensure UI/markdown targets updated.
101
+ - Confirm feature-flagged widgets default to safe/off for new tenants.`
102
+ }
103
+ ];
104
+ registerDocBlocks(analyticsDashboardDocBlocks);