@adminforth/dashboard 1.0.0 → 1.1.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 (41) hide show
  1. package/README.md +116 -54
  2. package/custom/api/dashboardApi.ts +9 -0
  3. package/custom/model/dashboard.types.ts +158 -1
  4. package/custom/queries/useWidgetData.ts +8 -4
  5. package/custom/runtime/WidgetShell.vue +8 -4
  6. package/custom/widgets/chart/chart.utils.ts +2 -2
  7. package/custom/widgets/gauge-card/GaugeCardWidget.vue +94 -12
  8. package/custom/widgets/pivot-table/PivotTableWidget.vue +27 -5
  9. package/custom/widgets/table/TableWidget.vue +155 -30
  10. package/dist/custom/api/dashboardApi.d.ts +7 -1
  11. package/dist/custom/api/dashboardApi.js +4 -6
  12. package/dist/custom/api/dashboardApi.ts +9 -0
  13. package/dist/custom/model/dashboard.types.d.ts +45 -0
  14. package/dist/custom/model/dashboard.types.js +82 -1
  15. package/dist/custom/model/dashboard.types.ts +158 -1
  16. package/dist/custom/queries/useDashboardConfig.d.ts +42 -0
  17. package/dist/custom/queries/useWidgetData.d.ts +44 -1
  18. package/dist/custom/queries/useWidgetData.js +3 -3
  19. package/dist/custom/queries/useWidgetData.ts +8 -4
  20. package/dist/custom/runtime/WidgetShell.vue +8 -4
  21. package/dist/custom/widgets/chart/chart.utils.d.ts +1 -1
  22. package/dist/custom/widgets/chart/chart.utils.js +2 -2
  23. package/dist/custom/widgets/chart/chart.utils.ts +2 -2
  24. package/dist/custom/widgets/gauge-card/GaugeCardWidget.vue +94 -12
  25. package/dist/custom/widgets/pivot-table/PivotTableWidget.vue +27 -5
  26. package/dist/custom/widgets/table/TableWidget.vue +155 -30
  27. package/dist/endpoint/widgets.d.ts +6 -1
  28. package/dist/endpoint/widgets.js +22 -4
  29. package/dist/schema/api.d.ts +882 -212
  30. package/dist/schema/api.js +11 -2
  31. package/dist/schema/widget.d.ts +542 -4
  32. package/dist/schema/widget.js +111 -1
  33. package/dist/services/widgetConfigValidator.js +32 -6
  34. package/dist/services/widgetDataService.d.ts +8 -6
  35. package/dist/services/widgetDataService.js +133 -11
  36. package/endpoint/widgets.ts +31 -4
  37. package/package.json +1 -1
  38. package/schema/api.ts +11 -1
  39. package/schema/widget.ts +114 -1
  40. package/services/widgetConfigValidator.ts +45 -6
  41. package/services/widgetDataService.ts +201 -19
@@ -8,7 +8,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import { randomUUID } from 'crypto';
11
- import { DashboardApiResponseSchema, DashboardWidgetDataResponseSchema, GroupIdRequestSchema, MoveWidgetRequestSchema, SetWidgetConfigRequestSchema, WidgetIdRequestSchema, } from '../schema/api.js';
11
+ import { normalizeDashboardWidgetConfig, } from '../custom/model/dashboard.types.js';
12
+ import { DashboardApiResponseSchema, DashboardWidgetDataResponseSchema, GroupIdRequestSchema, MoveWidgetRequestSchema, SetWidgetConfigRequestSchema, WidgetDataRequestSchema, WidgetIdRequestSchema, } from '../schema/api.js';
13
+ import { StoredWidgetConfigSchema } from '../schema/widget.js';
14
+ function formatWidgetConfigValidationErrors(error) {
15
+ return error.issues.map((issue) => ({
16
+ field: issue.path.length ? issue.path.map(String).join('.') : 'config',
17
+ message: issue.message,
18
+ }));
19
+ }
12
20
  export function registerWidgetEndpoints(server, ctx) {
13
21
  server.endpoint({
14
22
  method: 'POST',
@@ -140,7 +148,15 @@ export function registerWidgetEndpoints(server, ctx) {
140
148
  response.setStatus(404);
141
149
  return { error: 'Dashboard widget not found' };
142
150
  }
143
- const typedWidgetConfig = body.config;
151
+ const parsedWidgetConfig = StoredWidgetConfigSchema.safeParse(normalizeDashboardWidgetConfig(body.config));
152
+ if (!parsedWidgetConfig.success) {
153
+ response.setStatus(422);
154
+ return {
155
+ error: 'Invalid widget config',
156
+ validationErrors: formatWidgetConfigValidationErrors(parsedWidgetConfig.error),
157
+ };
158
+ }
159
+ const typedWidgetConfig = parsedWidgetConfig.data;
144
160
  const apiValidationErrors = ctx.validateDashboardWidgetApiConfig(typedWidgetConfig);
145
161
  if (apiValidationErrors.length) {
146
162
  response.setStatus(422);
@@ -157,7 +173,7 @@ export function registerWidgetEndpoints(server, ctx) {
157
173
  method: 'POST',
158
174
  path: '/dashboard/get_dashboard_widget_data',
159
175
  description: 'Loads query result data for one dashboard widget by dashboard slug and widget id.',
160
- request_schema: WidgetIdRequestSchema,
176
+ request_schema: WidgetDataRequestSchema,
161
177
  response_schema: DashboardWidgetDataResponseSchema,
162
178
  handler: (_a) => __awaiter(this, [_a], void 0, function* ({ body, response }) {
163
179
  const slug = String((body === null || body === void 0 ? void 0 : body.slug) || 'default');
@@ -175,7 +191,9 @@ export function registerWidgetEndpoints(server, ctx) {
175
191
  }
176
192
  return {
177
193
  widget,
178
- data: yield ctx.getWidgetData(widget),
194
+ data: yield ctx.getWidgetData(widget, {
195
+ pagination: body === null || body === void 0 ? void 0 : body.pagination,
196
+ }),
179
197
  };
180
198
  }),
181
199
  });