@contractspec/example.analytics-dashboard 0.0.0-canary-20260113170453

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 (98) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +281 -0
  3. package/dist/dashboard/dashboard.enum.d.ts +18 -0
  4. package/dist/dashboard/dashboard.enum.d.ts.map +1 -0
  5. package/dist/dashboard/dashboard.enum.js +43 -0
  6. package/dist/dashboard/dashboard.enum.js.map +1 -0
  7. package/dist/dashboard/dashboard.operation.d.ts +537 -0
  8. package/dist/dashboard/dashboard.operation.d.ts.map +1 -0
  9. package/dist/dashboard/dashboard.operation.js +213 -0
  10. package/dist/dashboard/dashboard.operation.js.map +1 -0
  11. package/dist/dashboard/dashboard.presentation.d.ts +9 -0
  12. package/dist/dashboard/dashboard.presentation.d.ts.map +1 -0
  13. package/dist/dashboard/dashboard.presentation.js +90 -0
  14. package/dist/dashboard/dashboard.presentation.js.map +1 -0
  15. package/dist/dashboard/dashboard.schema.d.ts +333 -0
  16. package/dist/dashboard/dashboard.schema.d.ts.map +1 -0
  17. package/dist/dashboard/dashboard.schema.js +236 -0
  18. package/dist/dashboard/dashboard.schema.js.map +1 -0
  19. package/dist/dashboard/dashboard.test-spec.d.ts +10 -0
  20. package/dist/dashboard/dashboard.test-spec.d.ts.map +1 -0
  21. package/dist/dashboard/dashboard.test-spec.js +233 -0
  22. package/dist/dashboard/dashboard.test-spec.js.map +1 -0
  23. package/dist/dashboard/index.d.ts +4 -0
  24. package/dist/dashboard/index.js +5 -0
  25. package/dist/dashboard.feature.d.ts +17 -0
  26. package/dist/dashboard.feature.d.ts.map +1 -0
  27. package/dist/dashboard.feature.js +177 -0
  28. package/dist/dashboard.feature.js.map +1 -0
  29. package/dist/docs/analytics-dashboard.docblock.d.ts +1 -0
  30. package/dist/docs/analytics-dashboard.docblock.js +114 -0
  31. package/dist/docs/analytics-dashboard.docblock.js.map +1 -0
  32. package/dist/docs/index.d.ts +1 -0
  33. package/dist/docs/index.js +1 -0
  34. package/dist/events.d.ts +149 -0
  35. package/dist/events.d.ts.map +1 -0
  36. package/dist/events.js +128 -0
  37. package/dist/events.js.map +1 -0
  38. package/dist/example.d.ts +7 -0
  39. package/dist/example.d.ts.map +1 -0
  40. package/dist/example.js +58 -0
  41. package/dist/example.js.map +1 -0
  42. package/dist/handlers/analytics.handlers.d.ts +122 -0
  43. package/dist/handlers/analytics.handlers.d.ts.map +1 -0
  44. package/dist/handlers/analytics.handlers.js +310 -0
  45. package/dist/handlers/analytics.handlers.js.map +1 -0
  46. package/dist/handlers/index.d.ts +2 -0
  47. package/dist/handlers/index.js +3 -0
  48. package/dist/index.d.ts +12 -0
  49. package/dist/index.js +13 -0
  50. package/dist/query/index.d.ts +4 -0
  51. package/dist/query/index.js +5 -0
  52. package/dist/query/query.enum.d.ts +10 -0
  53. package/dist/query/query.enum.d.ts.map +1 -0
  54. package/dist/query/query.enum.js +16 -0
  55. package/dist/query/query.enum.js.map +1 -0
  56. package/dist/query/query.operation.d.ts +181 -0
  57. package/dist/query/query.operation.d.ts.map +1 -0
  58. package/dist/query/query.operation.js +113 -0
  59. package/dist/query/query.operation.js.map +1 -0
  60. package/dist/query/query.presentation.d.ts +8 -0
  61. package/dist/query/query.presentation.d.ts.map +1 -0
  62. package/dist/query/query.presentation.js +60 -0
  63. package/dist/query/query.presentation.js.map +1 -0
  64. package/dist/query/query.schema.d.ts +143 -0
  65. package/dist/query/query.schema.d.ts.map +1 -0
  66. package/dist/query/query.schema.js +157 -0
  67. package/dist/query/query.schema.js.map +1 -0
  68. package/dist/query/query.test-spec.d.ts +8 -0
  69. package/dist/query/query.test-spec.d.ts.map +1 -0
  70. package/dist/query/query.test-spec.js +124 -0
  71. package/dist/query/query.test-spec.js.map +1 -0
  72. package/dist/query-engine/index.d.ts +106 -0
  73. package/dist/query-engine/index.d.ts.map +1 -0
  74. package/dist/query-engine/index.js +189 -0
  75. package/dist/query-engine/index.js.map +1 -0
  76. package/dist/seeders/index.d.ts +10 -0
  77. package/dist/seeders/index.d.ts.map +1 -0
  78. package/dist/seeders/index.js +19 -0
  79. package/dist/seeders/index.js.map +1 -0
  80. package/dist/ui/AnalyticsDashboard.d.ts +7 -0
  81. package/dist/ui/AnalyticsDashboard.d.ts.map +1 -0
  82. package/dist/ui/AnalyticsDashboard.js +265 -0
  83. package/dist/ui/AnalyticsDashboard.js.map +1 -0
  84. package/dist/ui/hooks/index.d.ts +2 -0
  85. package/dist/ui/hooks/index.js +5 -0
  86. package/dist/ui/hooks/useAnalyticsData.d.ts +23 -0
  87. package/dist/ui/hooks/useAnalyticsData.d.ts.map +1 -0
  88. package/dist/ui/hooks/useAnalyticsData.js +73 -0
  89. package/dist/ui/hooks/useAnalyticsData.js.map +1 -0
  90. package/dist/ui/index.d.ts +6 -0
  91. package/dist/ui/index.js +6 -0
  92. package/dist/ui/renderers/analytics.markdown.d.ts +28 -0
  93. package/dist/ui/renderers/analytics.markdown.d.ts.map +1 -0
  94. package/dist/ui/renderers/analytics.markdown.js +264 -0
  95. package/dist/ui/renderers/analytics.markdown.js.map +1 -0
  96. package/dist/ui/renderers/index.d.ts +2 -0
  97. package/dist/ui/renderers/index.js +3 -0
  98. package/package.json +101 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Chaman Ventures, SASU
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,281 @@
1
+ # @contractspec/example.analytics-dashboard
2
+
3
+ Website: https://contractspec.io/
4
+
5
+
6
+ > Analytics Dashboard Example - Comprehensive data visualization and reporting solution
7
+
8
+ ## Overview
9
+
10
+ This example demonstrates a full-featured analytics and dashboarding system built with ContractSpec, showcasing:
11
+
12
+ - **Customizable Dashboards** - Drag-and-drop widget layouts
13
+ - **Visual Query Builder** - Build queries without writing SQL
14
+ - **Multiple Widget Types** - Charts, metrics, tables, maps
15
+ - **Scheduled Reports** - Automated report generation and delivery
16
+ - **Public Sharing** - Share dashboards with external stakeholders
17
+
18
+ ## Entities
19
+
20
+ ### Dashboard
21
+
22
+ Main container for widgets and visualizations.
23
+
24
+ | Field | Type | Description |
25
+ |-------|------|-------------|
26
+ | id | string | Unique identifier |
27
+ | organizationId | string | Organization owner |
28
+ | name | string | Dashboard name |
29
+ | slug | string | URL-friendly identifier |
30
+ | description | string? | Dashboard description |
31
+ | status | DashboardStatus | DRAFT, PUBLISHED, ARCHIVED |
32
+ | refreshInterval | RefreshInterval | Auto-refresh frequency |
33
+ | defaultDateRange | TimeRange | Default time filter |
34
+ | isPublic | boolean | Public visibility |
35
+ | shareToken | string? | Public access token |
36
+
37
+ ### Widget
38
+
39
+ Individual visualization component on a dashboard.
40
+
41
+ | Field | Type | Description |
42
+ |-------|------|-------------|
43
+ | id | string | Unique identifier |
44
+ | dashboardId | string | Parent dashboard |
45
+ | name | string | Widget title |
46
+ | type | WidgetType | LINE_CHART, BAR_CHART, PIE_CHART, METRIC, TABLE, etc. |
47
+ | gridX, gridY | number | Grid position |
48
+ | gridWidth, gridHeight | number | Grid dimensions |
49
+ | queryId | string? | Linked query |
50
+ | config | JSON | Widget-specific configuration |
51
+
52
+ ### Query
53
+
54
+ Reusable data query definition.
55
+
56
+ | Field | Type | Description |
57
+ |-------|------|-------------|
58
+ | id | string | Unique identifier |
59
+ | name | string | Query name |
60
+ | type | QueryType | SQL, METRIC, AGGREGATION, CUSTOM |
61
+ | definition | JSON | Query definition |
62
+ | sql | string? | Raw SQL for SQL type |
63
+ | metricIds | string[] | Metrics for METRIC type |
64
+ | cacheTtlSeconds | number | Cache duration |
65
+ | isShared | boolean | Shared across org |
66
+
67
+ ### Report
68
+
69
+ Scheduled report definition.
70
+
71
+ | Field | Type | Description |
72
+ |-------|------|-------------|
73
+ | id | string | Unique identifier |
74
+ | dashboardId | string | Source dashboard |
75
+ | name | string | Report name |
76
+ | schedule | string | Cron expression |
77
+ | format | ReportFormat | PDF, PNG, CSV |
78
+ | recipients | string[] | Email addresses |
79
+ | lastRunAt | DateTime? | Last execution time |
80
+
81
+ ## Contracts
82
+
83
+ ### Dashboard Management
84
+
85
+ ```typescript
86
+ // Create a new dashboard
87
+ CreateDashboardContract
88
+ Input: { name, slug, description?, refreshInterval? }
89
+ Output: Dashboard
90
+
91
+ // Add widget to dashboard
92
+ AddWidgetContract
93
+ Input: { dashboardId, name, type, gridX?, gridY?, queryId?, config? }
94
+ Output: Widget
95
+
96
+ // Get dashboard with widgets
97
+ GetDashboardContract
98
+ Input: { dashboardId? | slug? | shareToken? }
99
+ Output: Dashboard (with widgets)
100
+
101
+ // List user's dashboards
102
+ ListDashboardsContract
103
+ Input: { status?, search?, limit?, offset? }
104
+ Output: { dashboards, total }
105
+ ```
106
+
107
+ ### Query Management
108
+
109
+ ```typescript
110
+ // Create a query
111
+ CreateQueryContract
112
+ Input: { name, type, definition, sql?, metricIds?, cacheTtlSeconds? }
113
+ Output: Query
114
+
115
+ // Execute query
116
+ ExecuteQueryContract
117
+ Input: { queryId, parameters?, dateRange?, filters?, forceRefresh? }
118
+ Output: { data, columns, rowCount, executionTimeMs, cached }
119
+ ```
120
+
121
+ ## Events
122
+
123
+ | Event | Description |
124
+ |-------|-------------|
125
+ | `analytics.dashboard.created` | Dashboard created |
126
+ | `analytics.dashboard.published` | Dashboard published |
127
+ | `analytics.widget.added` | Widget added to dashboard |
128
+ | `analytics.query.created` | Query created |
129
+ | `analytics.query.executed` | Query executed |
130
+ | `analytics.dashboard.viewed` | Dashboard viewed |
131
+ | `analytics.report.generated` | Scheduled report generated |
132
+
133
+ ## Widget Types
134
+
135
+ - **Line Chart** - Time series data
136
+ - **Bar Chart** - Categorical comparisons
137
+ - **Pie Chart** - Part-to-whole relationships
138
+ - **Area Chart** - Stacked time series
139
+ - **Scatter Plot** - Correlation analysis
140
+ - **Metric** - Single KPI display
141
+ - **Table** - Tabular data
142
+ - **Heatmap** - Density visualization
143
+ - **Funnel** - Conversion analysis
144
+ - **Map** - Geographic data
145
+ - **Text** - Markdown content
146
+ - **Embed** - External iframe
147
+
148
+ ## Query Types
149
+
150
+ ### Metric Query
151
+
152
+ Query usage metrics from the metering system.
153
+
154
+ ```json
155
+ {
156
+ "type": "METRIC",
157
+ "metricIds": ["active_users", "api_calls", "storage_used"]
158
+ }
159
+ ```
160
+
161
+ ### Aggregation Query
162
+
163
+ Build aggregations with measures and dimensions.
164
+
165
+ ```json
166
+ {
167
+ "type": "AGGREGATION",
168
+ "source": "events",
169
+ "measures": [
170
+ { "name": "total_count", "field": "id", "aggregation": "COUNT" }
171
+ ],
172
+ "dimensions": [
173
+ { "name": "date", "field": "created_at", "type": "TIME", "granularity": "DAY" }
174
+ ],
175
+ "filters": [
176
+ { "field": "event_type", "operator": "eq", "value": "page_view" }
177
+ ]
178
+ }
179
+ ```
180
+
181
+ ### SQL Query
182
+
183
+ Write custom SQL (requires feature flag).
184
+
185
+ ```json
186
+ {
187
+ "type": "SQL",
188
+ "sql": "SELECT date_trunc('day', created_at) as day, count(*) FROM events GROUP BY 1"
189
+ }
190
+ ```
191
+
192
+ ## Usage
193
+
194
+ ```typescript
195
+ import {
196
+ AnalyticsDashboardFeature,
197
+ CreateDashboardContract,
198
+ AddWidgetContract,
199
+ createQueryEngine,
200
+ } from '@contractspec/example.analytics-dashboard';
201
+
202
+ // Create a dashboard
203
+ const dashboard = await execute(CreateDashboardContract, {
204
+ name: 'Sales Overview',
205
+ slug: 'sales-overview',
206
+ description: 'Key sales metrics and trends',
207
+ refreshInterval: 'FIFTEEN_MINUTES',
208
+ });
209
+
210
+ // Add a metric widget
211
+ const widget = await execute(AddWidgetContract, {
212
+ dashboardId: dashboard.id,
213
+ name: 'Total Revenue',
214
+ type: 'METRIC',
215
+ gridX: 0,
216
+ gridY: 0,
217
+ gridWidth: 3,
218
+ gridHeight: 2,
219
+ queryId: revenueQueryId,
220
+ config: {
221
+ format: 'currency',
222
+ prefix: '$',
223
+ showChange: true,
224
+ },
225
+ });
226
+
227
+ // Execute a query
228
+ const queryEngine = createQueryEngine();
229
+ const result = await queryEngine.execute(
230
+ { type: 'METRIC', metricIds: ['daily_revenue'] },
231
+ { dateRange: { start: new Date('2024-01-01'), end: new Date() } }
232
+ );
233
+ ```
234
+
235
+ ## Dependencies
236
+
237
+ - `@contractspec/lib.schema` - Entity definitions
238
+ - `@contractspec/lib.contracts` - Contract definitions
239
+ - `@contractspec/lib.identity-rbac` - Access control
240
+ - `@contractspec/lib.metering` - Usage metrics integration
241
+ - `@contractspec/module.audit-trail` - Change tracking
242
+ - `@contractspec/module.notifications` - Report delivery
243
+
244
+ ## Feature Flags
245
+
246
+ | Flag | Description | Default |
247
+ |------|-------------|---------|
248
+ | `ANALYTICS_SQL_QUERIES` | Enable SQL query support | false |
249
+ | `ANALYTICS_SCHEDULED_REPORTS` | Enable scheduled reports | true |
250
+ | `ANALYTICS_PUBLIC_DASHBOARDS` | Allow public sharing | false |
251
+ | `ANALYTICS_ADVANCED_WIDGETS` | Enable maps, funnels | true |
252
+ | `ANALYTICS_QUERY_CACHING` | Enable result caching | true |
253
+
254
+ ## Permissions
255
+
256
+ | Permission | Description | Default Roles |
257
+ |------------|-------------|---------------|
258
+ | `dashboard:view` | View dashboards | viewer, analyst, admin |
259
+ | `dashboard:create` | Create dashboards | analyst, admin |
260
+ | `dashboard:edit` | Edit dashboards | analyst, admin |
261
+ | `dashboard:delete` | Delete dashboards | admin |
262
+ | `dashboard:share` | Share externally | analyst, admin |
263
+ | `query:create` | Create queries | analyst, admin |
264
+ | `query:execute` | Execute queries | viewer, analyst, admin |
265
+ | `report:schedule` | Schedule reports | analyst, admin |
266
+
267
+
268
+
269
+
270
+
271
+
272
+
273
+
274
+
275
+
276
+
277
+
278
+
279
+
280
+
281
+
@@ -0,0 +1,18 @@
1
+ import * as _contractspec_lib_schema37 from "@contractspec/lib.schema";
2
+
3
+ //#region src/dashboard/dashboard.enum.d.ts
4
+ /**
5
+ * Dashboard status enum.
6
+ */
7
+ declare const DashboardStatusEnum: _contractspec_lib_schema37.EnumType<[string, string, string]>;
8
+ /**
9
+ * Widget type enum.
10
+ */
11
+ declare const WidgetTypeEnum: _contractspec_lib_schema37.EnumType<[string, string, string, string, string, string, string, string, string, string, string, string]>;
12
+ /**
13
+ * Refresh interval enum.
14
+ */
15
+ declare const RefreshIntervalEnum: _contractspec_lib_schema37.EnumType<[string, string, string, string, string, string]>;
16
+ //#endregion
17
+ export { DashboardStatusEnum, RefreshIntervalEnum, WidgetTypeEnum };
18
+ //# sourceMappingURL=dashboard.enum.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dashboard.enum.d.ts","names":[],"sources":["../../src/dashboard/dashboard.enum.ts"],"sourcesContent":[],"mappings":";;;;;;AAKa,cAAA,mBAIX,EAAA,0BAAA,CAJ8B,QAAA,CAAA,CAAA,MAAA,EAAA,MAAA,EAAA,MAAA,CAAA,CAAA;AAShC;AAkBA;;cAlBa,gBAaX,0BAAA,CAbyB;;;;cAkBd,qBAOX,0BAAA,CAP8B"}
@@ -0,0 +1,43 @@
1
+ import { defineEnum } from "@contractspec/lib.schema";
2
+
3
+ //#region src/dashboard/dashboard.enum.ts
4
+ /**
5
+ * Dashboard status enum.
6
+ */
7
+ const DashboardStatusEnum = defineEnum("DashboardStatus", [
8
+ "DRAFT",
9
+ "PUBLISHED",
10
+ "ARCHIVED"
11
+ ]);
12
+ /**
13
+ * Widget type enum.
14
+ */
15
+ const WidgetTypeEnum = defineEnum("WidgetType", [
16
+ "LINE_CHART",
17
+ "BAR_CHART",
18
+ "PIE_CHART",
19
+ "AREA_CHART",
20
+ "SCATTER_PLOT",
21
+ "METRIC",
22
+ "TABLE",
23
+ "HEATMAP",
24
+ "FUNNEL",
25
+ "MAP",
26
+ "TEXT",
27
+ "EMBED"
28
+ ]);
29
+ /**
30
+ * Refresh interval enum.
31
+ */
32
+ const RefreshIntervalEnum = defineEnum("RefreshInterval", [
33
+ "NONE",
34
+ "MINUTE",
35
+ "FIVE_MINUTES",
36
+ "FIFTEEN_MINUTES",
37
+ "HOUR",
38
+ "DAY"
39
+ ]);
40
+
41
+ //#endregion
42
+ export { DashboardStatusEnum, RefreshIntervalEnum, WidgetTypeEnum };
43
+ //# sourceMappingURL=dashboard.enum.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dashboard.enum.js","names":[],"sources":["../../src/dashboard/dashboard.enum.ts"],"sourcesContent":["import { defineEnum } from '@contractspec/lib.schema';\n\n/**\n * Dashboard status enum.\n */\nexport const DashboardStatusEnum = defineEnum('DashboardStatus', [\n 'DRAFT',\n 'PUBLISHED',\n 'ARCHIVED',\n]);\n\n/**\n * Widget type enum.\n */\nexport const WidgetTypeEnum = defineEnum('WidgetType', [\n 'LINE_CHART',\n 'BAR_CHART',\n 'PIE_CHART',\n 'AREA_CHART',\n 'SCATTER_PLOT',\n 'METRIC',\n 'TABLE',\n 'HEATMAP',\n 'FUNNEL',\n 'MAP',\n 'TEXT',\n 'EMBED',\n]);\n\n/**\n * Refresh interval enum.\n */\nexport const RefreshIntervalEnum = defineEnum('RefreshInterval', [\n 'NONE',\n 'MINUTE',\n 'FIVE_MINUTES',\n 'FIFTEEN_MINUTES',\n 'HOUR',\n 'DAY',\n]);\n"],"mappings":";;;;;;AAKA,MAAa,sBAAsB,WAAW,mBAAmB;CAC/D;CACA;CACA;CACD,CAAC;;;;AAKF,MAAa,iBAAiB,WAAW,cAAc;CACrD;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD,CAAC;;;;AAKF,MAAa,sBAAsB,WAAW,mBAAmB;CAC/D;CACA;CACA;CACA;CACA;CACA;CACD,CAAC"}