@contractspec/example.saas-boilerplate 3.7.6 → 3.8.2
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/.turbo/turbo-build.log +39 -27
- package/AGENTS.md +50 -27
- package/CHANGELOG.md +36 -0
- package/README.md +65 -144
- package/dist/billing/billing.event.js +1 -1
- package/dist/billing/index.d.ts +6 -6
- package/dist/billing/index.js +1 -1
- package/dist/browser/billing/billing.event.js +1 -1
- package/dist/browser/billing/index.js +1 -1
- package/dist/browser/index.js +1147 -869
- package/dist/browser/project/index.js +209 -209
- package/dist/browser/project/project.event.js +1 -1
- package/dist/browser/saas-boilerplate.feature.js +208 -0
- package/dist/browser/ui/SaasDashboard.js +356 -105
- package/dist/browser/ui/SaasDashboard.visualizations.js +249 -0
- package/dist/browser/ui/SaasProjectList.js +7 -7
- package/dist/browser/ui/SaasSettingsPanel.js +12 -12
- package/dist/browser/ui/hooks/index.js +2 -2
- package/dist/browser/ui/hooks/useProjectList.js +1 -1
- package/dist/browser/ui/hooks/useProjectMutations.js +1 -1
- package/dist/browser/ui/index.js +790 -521
- package/dist/browser/ui/modals/CreateProjectModal.js +10 -10
- package/dist/browser/ui/modals/ProjectActionsModal.js +13 -13
- package/dist/browser/ui/modals/index.js +23 -23
- package/dist/browser/ui/renderers/index.js +341 -115
- package/dist/browser/ui/renderers/project-list.markdown.js +229 -3
- package/dist/browser/ui/renderers/project-list.renderer.js +7 -7
- package/dist/browser/visualizations/catalog.js +155 -0
- package/dist/browser/visualizations/index.js +217 -0
- package/dist/browser/visualizations/selectors.js +210 -0
- package/dist/handlers/index.d.ts +2 -2
- package/dist/index.d.ts +5 -4
- package/dist/index.js +1147 -869
- package/dist/node/billing/billing.event.js +1 -1
- package/dist/node/billing/index.js +1 -1
- package/dist/node/index.js +1147 -869
- package/dist/node/project/index.js +209 -209
- package/dist/node/project/project.event.js +1 -1
- package/dist/node/saas-boilerplate.feature.js +208 -0
- package/dist/node/ui/SaasDashboard.js +356 -105
- package/dist/node/ui/SaasDashboard.visualizations.js +249 -0
- package/dist/node/ui/SaasProjectList.js +7 -7
- package/dist/node/ui/SaasSettingsPanel.js +12 -12
- package/dist/node/ui/hooks/index.js +2 -2
- package/dist/node/ui/hooks/useProjectList.js +1 -1
- package/dist/node/ui/hooks/useProjectMutations.js +1 -1
- package/dist/node/ui/index.js +790 -521
- package/dist/node/ui/modals/CreateProjectModal.js +10 -10
- package/dist/node/ui/modals/ProjectActionsModal.js +13 -13
- package/dist/node/ui/modals/index.js +23 -23
- package/dist/node/ui/renderers/index.js +341 -115
- package/dist/node/ui/renderers/project-list.markdown.js +229 -3
- package/dist/node/ui/renderers/project-list.renderer.js +7 -7
- package/dist/node/visualizations/catalog.js +155 -0
- package/dist/node/visualizations/index.js +217 -0
- package/dist/node/visualizations/selectors.js +210 -0
- package/dist/presentations/index.d.ts +1 -1
- package/dist/project/index.d.ts +7 -7
- package/dist/project/index.js +209 -209
- package/dist/project/project.event.js +1 -1
- package/dist/saas-boilerplate.feature.js +208 -0
- package/dist/settings/index.d.ts +1 -1
- package/dist/ui/SaasDashboard.js +356 -105
- package/dist/ui/SaasDashboard.visualizations.d.ts +5 -0
- package/dist/ui/SaasDashboard.visualizations.js +250 -0
- package/dist/ui/SaasProjectList.js +7 -7
- package/dist/ui/SaasSettingsPanel.js +12 -12
- package/dist/ui/hooks/index.d.ts +2 -2
- package/dist/ui/hooks/index.js +2 -2
- package/dist/ui/hooks/useProjectList.d.ts +5 -0
- package/dist/ui/hooks/useProjectList.js +1 -1
- package/dist/ui/hooks/useProjectMutations.d.ts +8 -0
- package/dist/ui/hooks/useProjectMutations.js +1 -1
- package/dist/ui/index.d.ts +4 -4
- package/dist/ui/index.js +790 -521
- package/dist/ui/modals/CreateProjectModal.js +10 -10
- package/dist/ui/modals/ProjectActionsModal.js +13 -13
- package/dist/ui/modals/index.js +23 -23
- package/dist/ui/renderers/index.d.ts +1 -1
- package/dist/ui/renderers/index.js +341 -115
- package/dist/ui/renderers/project-list.markdown.js +229 -3
- package/dist/ui/renderers/project-list.renderer.d.ts +1 -1
- package/dist/ui/renderers/project-list.renderer.js +7 -7
- package/dist/visualizations/catalog.d.ts +11 -0
- package/dist/visualizations/catalog.js +156 -0
- package/dist/visualizations/index.d.ts +2 -0
- package/dist/visualizations/index.js +218 -0
- package/dist/visualizations/selectors.d.ts +8 -0
- package/dist/visualizations/selectors.js +211 -0
- package/dist/visualizations/selectors.test.d.ts +1 -0
- package/package.json +70 -14
- package/src/billing/billing.entity.ts +132 -132
- package/src/billing/billing.enum.ts +9 -9
- package/src/billing/billing.event.ts +71 -71
- package/src/billing/billing.handler.ts +87 -87
- package/src/billing/billing.operations.ts +158 -158
- package/src/billing/billing.presentation.ts +45 -45
- package/src/billing/billing.schema.ts +76 -76
- package/src/billing/index.ts +43 -48
- package/src/dashboard/dashboard.presentation.ts +45 -45
- package/src/dashboard/index.ts +2 -2
- package/src/docs/saas-boilerplate.docblock.ts +43 -43
- package/src/example.ts +32 -32
- package/src/handlers/index.ts +9 -9
- package/src/handlers/saas.handlers.ts +250 -249
- package/src/index.ts +41 -41
- package/src/presentations/index.ts +18 -20
- package/src/project/index.ts +45 -50
- package/src/project/project.entity.ts +68 -68
- package/src/project/project.enum.ts +8 -8
- package/src/project/project.event.ts +79 -79
- package/src/project/project.handler.ts +103 -103
- package/src/project/project.operations.ts +236 -236
- package/src/project/project.presentation.ts +46 -46
- package/src/project/project.schema.ts +90 -90
- package/src/saas-boilerplate.feature.ts +103 -100
- package/src/seeders/index.ts +20 -20
- package/src/settings/index.ts +2 -3
- package/src/settings/settings.entity.ts +65 -65
- package/src/settings/settings.enum.ts +4 -4
- package/src/shared/mock-data.ts +92 -92
- package/src/shared/overlay-types.ts +23 -23
- package/src/tests/operations.test-spec.ts +96 -96
- package/src/ui/SaasDashboard.tsx +278 -270
- package/src/ui/SaasDashboard.visualizations.tsx +41 -0
- package/src/ui/SaasProjectList.tsx +90 -90
- package/src/ui/SaasSettingsPanel.tsx +84 -84
- package/src/ui/hooks/index.ts +3 -3
- package/src/ui/hooks/useProjectList.ts +69 -68
- package/src/ui/hooks/useProjectMutations.ts +144 -143
- package/src/ui/index.ts +8 -12
- package/src/ui/modals/CreateProjectModal.tsx +154 -154
- package/src/ui/modals/ProjectActionsModal.tsx +321 -321
- package/src/ui/overlays/demo-overlays.ts +49 -49
- package/src/ui/renderers/index.ts +5 -4
- package/src/ui/renderers/project-list.markdown.ts +229 -205
- package/src/ui/renderers/project-list.renderer.tsx +14 -13
- package/src/visualizations/catalog.ts +153 -0
- package/src/visualizations/index.ts +2 -0
- package/src/visualizations/selectors.test.ts +25 -0
- package/src/visualizations/selectors.ts +85 -0
- package/tsconfig.json +7 -8
- package/tsdown.config.js +7 -3
|
@@ -345,7 +345,226 @@ function createSaasHandlers(db) {
|
|
|
345
345
|
getSubscription
|
|
346
346
|
};
|
|
347
347
|
}
|
|
348
|
+
// src/visualizations/catalog.ts
|
|
349
|
+
import {
|
|
350
|
+
defineVisualization,
|
|
351
|
+
VisualizationRegistry
|
|
352
|
+
} from "@contractspec/lib.contracts-spec/visualizations";
|
|
353
|
+
var PROJECT_LIST_REF = {
|
|
354
|
+
key: "saas.project.list",
|
|
355
|
+
version: "1.0.0"
|
|
356
|
+
};
|
|
357
|
+
var META = {
|
|
358
|
+
version: "1.0.0",
|
|
359
|
+
domain: "saas",
|
|
360
|
+
stability: "experimental",
|
|
361
|
+
owners: ["@example.saas-boilerplate"],
|
|
362
|
+
tags: ["saas", "visualization", "projects"]
|
|
363
|
+
};
|
|
364
|
+
var SaasProjectUsageVisualization = defineVisualization({
|
|
365
|
+
meta: {
|
|
366
|
+
...META,
|
|
367
|
+
key: "saas-boilerplate.visualization.project-usage",
|
|
368
|
+
title: "Project Capacity",
|
|
369
|
+
description: "Current project count against the current plan limit.",
|
|
370
|
+
goal: "Show usage against the active plan allowance.",
|
|
371
|
+
context: "SaaS account overview."
|
|
372
|
+
},
|
|
373
|
+
source: { primary: PROJECT_LIST_REF, resultPath: "data" },
|
|
374
|
+
visualization: {
|
|
375
|
+
kind: "metric",
|
|
376
|
+
measure: "totalProjects",
|
|
377
|
+
comparisonMeasure: "projectLimit",
|
|
378
|
+
measures: [
|
|
379
|
+
{
|
|
380
|
+
key: "totalProjects",
|
|
381
|
+
label: "Projects",
|
|
382
|
+
dataPath: "totalProjects",
|
|
383
|
+
format: "number"
|
|
384
|
+
},
|
|
385
|
+
{
|
|
386
|
+
key: "projectLimit",
|
|
387
|
+
label: "Plan Limit",
|
|
388
|
+
dataPath: "projectLimit",
|
|
389
|
+
format: "number"
|
|
390
|
+
}
|
|
391
|
+
],
|
|
392
|
+
table: { caption: "Current project count and plan limit." }
|
|
393
|
+
}
|
|
394
|
+
});
|
|
395
|
+
var SaasProjectStatusVisualization = defineVisualization({
|
|
396
|
+
meta: {
|
|
397
|
+
...META,
|
|
398
|
+
key: "saas-boilerplate.visualization.project-status",
|
|
399
|
+
title: "Project Status",
|
|
400
|
+
description: "Distribution of project states.",
|
|
401
|
+
goal: "Show the mix of active, draft, and archived projects.",
|
|
402
|
+
context: "Project portfolio overview."
|
|
403
|
+
},
|
|
404
|
+
source: { primary: PROJECT_LIST_REF, resultPath: "data" },
|
|
405
|
+
visualization: {
|
|
406
|
+
kind: "pie",
|
|
407
|
+
nameDimension: "status",
|
|
408
|
+
valueMeasure: "projects",
|
|
409
|
+
dimensions: [
|
|
410
|
+
{ key: "status", label: "Status", dataPath: "status", type: "category" }
|
|
411
|
+
],
|
|
412
|
+
measures: [
|
|
413
|
+
{
|
|
414
|
+
key: "projects",
|
|
415
|
+
label: "Projects",
|
|
416
|
+
dataPath: "projects",
|
|
417
|
+
format: "number"
|
|
418
|
+
}
|
|
419
|
+
],
|
|
420
|
+
table: { caption: "Project counts by status." }
|
|
421
|
+
}
|
|
422
|
+
});
|
|
423
|
+
var SaasProjectTierVisualization = defineVisualization({
|
|
424
|
+
meta: {
|
|
425
|
+
...META,
|
|
426
|
+
key: "saas-boilerplate.visualization.project-tiers",
|
|
427
|
+
title: "Tier Comparison",
|
|
428
|
+
description: "Distribution of projects across tiers.",
|
|
429
|
+
goal: "Compare how the current portfolio is distributed by tier.",
|
|
430
|
+
context: "Plan and packaging overview."
|
|
431
|
+
},
|
|
432
|
+
source: { primary: PROJECT_LIST_REF, resultPath: "data" },
|
|
433
|
+
visualization: {
|
|
434
|
+
kind: "cartesian",
|
|
435
|
+
variant: "bar",
|
|
436
|
+
xDimension: "tier",
|
|
437
|
+
yMeasures: ["projects"],
|
|
438
|
+
dimensions: [
|
|
439
|
+
{ key: "tier", label: "Tier", dataPath: "tier", type: "category" }
|
|
440
|
+
],
|
|
441
|
+
measures: [
|
|
442
|
+
{
|
|
443
|
+
key: "projects",
|
|
444
|
+
label: "Projects",
|
|
445
|
+
dataPath: "projects",
|
|
446
|
+
format: "number",
|
|
447
|
+
color: "#1d4ed8"
|
|
448
|
+
}
|
|
449
|
+
],
|
|
450
|
+
table: { caption: "Project counts by tier." }
|
|
451
|
+
}
|
|
452
|
+
});
|
|
453
|
+
var SaasProjectActivityVisualization = defineVisualization({
|
|
454
|
+
meta: {
|
|
455
|
+
...META,
|
|
456
|
+
key: "saas-boilerplate.visualization.project-activity",
|
|
457
|
+
title: "Recent Project Activity",
|
|
458
|
+
description: "Daily project creation activity.",
|
|
459
|
+
goal: "Show recent project activity over time.",
|
|
460
|
+
context: "Project portfolio trend view."
|
|
461
|
+
},
|
|
462
|
+
source: { primary: PROJECT_LIST_REF, resultPath: "data" },
|
|
463
|
+
visualization: {
|
|
464
|
+
kind: "cartesian",
|
|
465
|
+
variant: "line",
|
|
466
|
+
xDimension: "day",
|
|
467
|
+
yMeasures: ["projects"],
|
|
468
|
+
dimensions: [{ key: "day", label: "Day", dataPath: "day", type: "time" }],
|
|
469
|
+
measures: [
|
|
470
|
+
{
|
|
471
|
+
key: "projects",
|
|
472
|
+
label: "Projects",
|
|
473
|
+
dataPath: "projects",
|
|
474
|
+
format: "number",
|
|
475
|
+
color: "#0f766e"
|
|
476
|
+
}
|
|
477
|
+
],
|
|
478
|
+
table: { caption: "Daily project creation counts." }
|
|
479
|
+
}
|
|
480
|
+
});
|
|
481
|
+
var SaasVisualizationSpecs = [
|
|
482
|
+
SaasProjectUsageVisualization,
|
|
483
|
+
SaasProjectStatusVisualization,
|
|
484
|
+
SaasProjectTierVisualization,
|
|
485
|
+
SaasProjectActivityVisualization
|
|
486
|
+
];
|
|
487
|
+
var SaasVisualizationRegistry = new VisualizationRegistry([
|
|
488
|
+
...SaasVisualizationSpecs
|
|
489
|
+
]);
|
|
490
|
+
var SaasVisualizationRefs = SaasVisualizationSpecs.map((spec) => ({
|
|
491
|
+
key: spec.meta.key,
|
|
492
|
+
version: spec.meta.version
|
|
493
|
+
}));
|
|
494
|
+
|
|
495
|
+
// src/visualizations/selectors.ts
|
|
496
|
+
function toDayKey(value) {
|
|
497
|
+
const date = value instanceof Date ? value : new Date(value);
|
|
498
|
+
return date.toISOString().slice(0, 10);
|
|
499
|
+
}
|
|
500
|
+
function createSaasVisualizationItems(projects, projectLimit = 10) {
|
|
501
|
+
const statusCounts = new Map;
|
|
502
|
+
const tierCounts = new Map;
|
|
503
|
+
const activityCounts = new Map;
|
|
504
|
+
for (const project of projects) {
|
|
505
|
+
statusCounts.set(project.status, (statusCounts.get(project.status) ?? 0) + 1);
|
|
506
|
+
tierCounts.set(project.tier, (tierCounts.get(project.tier) ?? 0) + 1);
|
|
507
|
+
const day = toDayKey(project.createdAt);
|
|
508
|
+
activityCounts.set(day, (activityCounts.get(day) ?? 0) + 1);
|
|
509
|
+
}
|
|
510
|
+
return [
|
|
511
|
+
{
|
|
512
|
+
key: "saas-capacity",
|
|
513
|
+
spec: SaasProjectUsageVisualization,
|
|
514
|
+
data: { data: [{ totalProjects: projects.length, projectLimit }] },
|
|
515
|
+
title: "Project Capacity",
|
|
516
|
+
description: "Current project count compared to the active limit.",
|
|
517
|
+
height: 220
|
|
518
|
+
},
|
|
519
|
+
{
|
|
520
|
+
key: "saas-status",
|
|
521
|
+
spec: SaasProjectStatusVisualization,
|
|
522
|
+
data: {
|
|
523
|
+
data: Array.from(statusCounts.entries()).map(([status, count]) => ({
|
|
524
|
+
status,
|
|
525
|
+
projects: count
|
|
526
|
+
}))
|
|
527
|
+
},
|
|
528
|
+
title: "Project Status",
|
|
529
|
+
description: "Status mix across the current project portfolio.",
|
|
530
|
+
height: 260
|
|
531
|
+
},
|
|
532
|
+
{
|
|
533
|
+
key: "saas-tier",
|
|
534
|
+
spec: SaasProjectTierVisualization,
|
|
535
|
+
data: {
|
|
536
|
+
data: Array.from(tierCounts.entries()).map(([tier, count]) => ({
|
|
537
|
+
tier,
|
|
538
|
+
projects: count
|
|
539
|
+
}))
|
|
540
|
+
},
|
|
541
|
+
title: "Tier Comparison",
|
|
542
|
+
description: "How projects are distributed across tiers."
|
|
543
|
+
},
|
|
544
|
+
{
|
|
545
|
+
key: "saas-activity",
|
|
546
|
+
spec: SaasProjectActivityVisualization,
|
|
547
|
+
data: {
|
|
548
|
+
data: Array.from(activityCounts.entries()).sort(([left], [right]) => left.localeCompare(right)).map(([day, count]) => ({ day, projects: count }))
|
|
549
|
+
},
|
|
550
|
+
title: "Recent Project Activity",
|
|
551
|
+
description: "Daily project creation activity."
|
|
552
|
+
}
|
|
553
|
+
];
|
|
554
|
+
}
|
|
348
555
|
// src/ui/renderers/project-list.markdown.ts
|
|
556
|
+
var PROJECT_TIERS = [
|
|
557
|
+
"FREE",
|
|
558
|
+
"PRO",
|
|
559
|
+
"ENTERPRISE"
|
|
560
|
+
];
|
|
561
|
+
function toVisualizationProject(project, index) {
|
|
562
|
+
return {
|
|
563
|
+
status: project.status === "DELETED" ? "ARCHIVED" : project.status,
|
|
564
|
+
tier: PROJECT_TIERS[index % PROJECT_TIERS.length] ?? "FREE",
|
|
565
|
+
createdAt: project.createdAt
|
|
566
|
+
};
|
|
567
|
+
}
|
|
349
568
|
var projectListMarkdownRenderer = {
|
|
350
569
|
target: "markdown",
|
|
351
570
|
render: async (desc, _ctx) => {
|
|
@@ -356,7 +575,7 @@ var projectListMarkdownRenderer = {
|
|
|
356
575
|
limit: 20,
|
|
357
576
|
offset: 0
|
|
358
577
|
});
|
|
359
|
-
const items = data.projects ??
|
|
578
|
+
const items = data.projects ?? [];
|
|
360
579
|
const lines = [
|
|
361
580
|
"# Projects",
|
|
362
581
|
"",
|
|
@@ -393,6 +612,7 @@ var saasDashboardMarkdownRenderer = {
|
|
|
393
612
|
const projects = projectsData.projects ?? [];
|
|
394
613
|
const activeProjects = projects.filter((p) => p.status === "ACTIVE").length;
|
|
395
614
|
const archivedProjects = projects.filter((p) => p.status === "ARCHIVED").length;
|
|
615
|
+
const visualizations = createSaasVisualizationItems(projects.map(toVisualizationProject), 10);
|
|
396
616
|
const lines = [
|
|
397
617
|
"# SaaS Dashboard",
|
|
398
618
|
"",
|
|
@@ -407,10 +627,16 @@ var saasDashboardMarkdownRenderer = {
|
|
|
407
627
|
`| Archived Projects | ${archivedProjects} |`,
|
|
408
628
|
`| Subscription Plan | ${subscription.planName} |`,
|
|
409
629
|
`| Subscription Status | ${subscription.status} |`,
|
|
410
|
-
"",
|
|
411
|
-
"## Projects",
|
|
412
630
|
""
|
|
413
631
|
];
|
|
632
|
+
lines.push("## Visualization Overview");
|
|
633
|
+
lines.push("");
|
|
634
|
+
for (const item of visualizations) {
|
|
635
|
+
lines.push(`- **${item.title}** via \`${item.spec.meta.key}\``);
|
|
636
|
+
}
|
|
637
|
+
lines.push("");
|
|
638
|
+
lines.push("## Projects");
|
|
639
|
+
lines.push("");
|
|
414
640
|
if (projects.length === 0) {
|
|
415
641
|
lines.push("_No projects yet._");
|
|
416
642
|
} else {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* React renderer for SaaS Project List presentation
|
|
3
3
|
*/
|
|
4
|
-
import * as React from 'react';
|
|
5
4
|
import type { PresentationRenderer } from '@contractspec/lib.contracts-spec/presentations/transform-engine';
|
|
5
|
+
import * as React from 'react';
|
|
6
6
|
export declare const projectListReactRenderer: PresentationRenderer<React.ReactElement>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
// src/ui/hooks/useProjectList.ts
|
|
3
|
-
import { useCallback, useEffect, useMemo, useState } from "react";
|
|
4
3
|
import { useTemplateRuntime } from "@contractspec/lib.example-shared-ui";
|
|
4
|
+
import { useCallback, useEffect, useMemo, useState } from "react";
|
|
5
5
|
function useProjectList(options = {}) {
|
|
6
6
|
const { handlers, projectId } = useTemplateRuntime();
|
|
7
7
|
const { saas } = handlers;
|
|
@@ -65,14 +65,14 @@ function useProjectList(options = {}) {
|
|
|
65
65
|
|
|
66
66
|
// src/ui/SaasProjectList.tsx
|
|
67
67
|
import {
|
|
68
|
-
|
|
69
|
-
StatCardGroup,
|
|
70
|
-
StatusChip,
|
|
71
|
-
EntityCard,
|
|
68
|
+
Button,
|
|
72
69
|
EmptyState,
|
|
73
|
-
|
|
70
|
+
EntityCard,
|
|
74
71
|
ErrorState,
|
|
75
|
-
|
|
72
|
+
LoaderBlock,
|
|
73
|
+
StatCard,
|
|
74
|
+
StatCardGroup,
|
|
75
|
+
StatusChip
|
|
76
76
|
} from "@contractspec/lib.design-system";
|
|
77
77
|
import { jsxDEV } from "react/jsx-dev-runtime";
|
|
78
78
|
"use client";
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { VisualizationRegistry } from '@contractspec/lib.contracts-spec/visualizations';
|
|
2
|
+
export declare const SaasProjectUsageVisualization: import("@contractspec/lib.contracts-spec").VisualizationSpec;
|
|
3
|
+
export declare const SaasProjectStatusVisualization: import("@contractspec/lib.contracts-spec").VisualizationSpec;
|
|
4
|
+
export declare const SaasProjectTierVisualization: import("@contractspec/lib.contracts-spec").VisualizationSpec;
|
|
5
|
+
export declare const SaasProjectActivityVisualization: import("@contractspec/lib.contracts-spec").VisualizationSpec;
|
|
6
|
+
export declare const SaasVisualizationSpecs: readonly [import("@contractspec/lib.contracts-spec").VisualizationSpec, import("@contractspec/lib.contracts-spec").VisualizationSpec, import("@contractspec/lib.contracts-spec").VisualizationSpec, import("@contractspec/lib.contracts-spec").VisualizationSpec];
|
|
7
|
+
export declare const SaasVisualizationRegistry: VisualizationRegistry;
|
|
8
|
+
export declare const SaasVisualizationRefs: {
|
|
9
|
+
key: string;
|
|
10
|
+
version: string;
|
|
11
|
+
}[];
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// src/visualizations/catalog.ts
|
|
3
|
+
import {
|
|
4
|
+
defineVisualization,
|
|
5
|
+
VisualizationRegistry
|
|
6
|
+
} from "@contractspec/lib.contracts-spec/visualizations";
|
|
7
|
+
var PROJECT_LIST_REF = {
|
|
8
|
+
key: "saas.project.list",
|
|
9
|
+
version: "1.0.0"
|
|
10
|
+
};
|
|
11
|
+
var META = {
|
|
12
|
+
version: "1.0.0",
|
|
13
|
+
domain: "saas",
|
|
14
|
+
stability: "experimental",
|
|
15
|
+
owners: ["@example.saas-boilerplate"],
|
|
16
|
+
tags: ["saas", "visualization", "projects"]
|
|
17
|
+
};
|
|
18
|
+
var SaasProjectUsageVisualization = defineVisualization({
|
|
19
|
+
meta: {
|
|
20
|
+
...META,
|
|
21
|
+
key: "saas-boilerplate.visualization.project-usage",
|
|
22
|
+
title: "Project Capacity",
|
|
23
|
+
description: "Current project count against the current plan limit.",
|
|
24
|
+
goal: "Show usage against the active plan allowance.",
|
|
25
|
+
context: "SaaS account overview."
|
|
26
|
+
},
|
|
27
|
+
source: { primary: PROJECT_LIST_REF, resultPath: "data" },
|
|
28
|
+
visualization: {
|
|
29
|
+
kind: "metric",
|
|
30
|
+
measure: "totalProjects",
|
|
31
|
+
comparisonMeasure: "projectLimit",
|
|
32
|
+
measures: [
|
|
33
|
+
{
|
|
34
|
+
key: "totalProjects",
|
|
35
|
+
label: "Projects",
|
|
36
|
+
dataPath: "totalProjects",
|
|
37
|
+
format: "number"
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
key: "projectLimit",
|
|
41
|
+
label: "Plan Limit",
|
|
42
|
+
dataPath: "projectLimit",
|
|
43
|
+
format: "number"
|
|
44
|
+
}
|
|
45
|
+
],
|
|
46
|
+
table: { caption: "Current project count and plan limit." }
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
var SaasProjectStatusVisualization = defineVisualization({
|
|
50
|
+
meta: {
|
|
51
|
+
...META,
|
|
52
|
+
key: "saas-boilerplate.visualization.project-status",
|
|
53
|
+
title: "Project Status",
|
|
54
|
+
description: "Distribution of project states.",
|
|
55
|
+
goal: "Show the mix of active, draft, and archived projects.",
|
|
56
|
+
context: "Project portfolio overview."
|
|
57
|
+
},
|
|
58
|
+
source: { primary: PROJECT_LIST_REF, resultPath: "data" },
|
|
59
|
+
visualization: {
|
|
60
|
+
kind: "pie",
|
|
61
|
+
nameDimension: "status",
|
|
62
|
+
valueMeasure: "projects",
|
|
63
|
+
dimensions: [
|
|
64
|
+
{ key: "status", label: "Status", dataPath: "status", type: "category" }
|
|
65
|
+
],
|
|
66
|
+
measures: [
|
|
67
|
+
{
|
|
68
|
+
key: "projects",
|
|
69
|
+
label: "Projects",
|
|
70
|
+
dataPath: "projects",
|
|
71
|
+
format: "number"
|
|
72
|
+
}
|
|
73
|
+
],
|
|
74
|
+
table: { caption: "Project counts by status." }
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
var SaasProjectTierVisualization = defineVisualization({
|
|
78
|
+
meta: {
|
|
79
|
+
...META,
|
|
80
|
+
key: "saas-boilerplate.visualization.project-tiers",
|
|
81
|
+
title: "Tier Comparison",
|
|
82
|
+
description: "Distribution of projects across tiers.",
|
|
83
|
+
goal: "Compare how the current portfolio is distributed by tier.",
|
|
84
|
+
context: "Plan and packaging overview."
|
|
85
|
+
},
|
|
86
|
+
source: { primary: PROJECT_LIST_REF, resultPath: "data" },
|
|
87
|
+
visualization: {
|
|
88
|
+
kind: "cartesian",
|
|
89
|
+
variant: "bar",
|
|
90
|
+
xDimension: "tier",
|
|
91
|
+
yMeasures: ["projects"],
|
|
92
|
+
dimensions: [
|
|
93
|
+
{ key: "tier", label: "Tier", dataPath: "tier", type: "category" }
|
|
94
|
+
],
|
|
95
|
+
measures: [
|
|
96
|
+
{
|
|
97
|
+
key: "projects",
|
|
98
|
+
label: "Projects",
|
|
99
|
+
dataPath: "projects",
|
|
100
|
+
format: "number",
|
|
101
|
+
color: "#1d4ed8"
|
|
102
|
+
}
|
|
103
|
+
],
|
|
104
|
+
table: { caption: "Project counts by tier." }
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
var SaasProjectActivityVisualization = defineVisualization({
|
|
108
|
+
meta: {
|
|
109
|
+
...META,
|
|
110
|
+
key: "saas-boilerplate.visualization.project-activity",
|
|
111
|
+
title: "Recent Project Activity",
|
|
112
|
+
description: "Daily project creation activity.",
|
|
113
|
+
goal: "Show recent project activity over time.",
|
|
114
|
+
context: "Project portfolio trend view."
|
|
115
|
+
},
|
|
116
|
+
source: { primary: PROJECT_LIST_REF, resultPath: "data" },
|
|
117
|
+
visualization: {
|
|
118
|
+
kind: "cartesian",
|
|
119
|
+
variant: "line",
|
|
120
|
+
xDimension: "day",
|
|
121
|
+
yMeasures: ["projects"],
|
|
122
|
+
dimensions: [{ key: "day", label: "Day", dataPath: "day", type: "time" }],
|
|
123
|
+
measures: [
|
|
124
|
+
{
|
|
125
|
+
key: "projects",
|
|
126
|
+
label: "Projects",
|
|
127
|
+
dataPath: "projects",
|
|
128
|
+
format: "number",
|
|
129
|
+
color: "#0f766e"
|
|
130
|
+
}
|
|
131
|
+
],
|
|
132
|
+
table: { caption: "Daily project creation counts." }
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
var SaasVisualizationSpecs = [
|
|
136
|
+
SaasProjectUsageVisualization,
|
|
137
|
+
SaasProjectStatusVisualization,
|
|
138
|
+
SaasProjectTierVisualization,
|
|
139
|
+
SaasProjectActivityVisualization
|
|
140
|
+
];
|
|
141
|
+
var SaasVisualizationRegistry = new VisualizationRegistry([
|
|
142
|
+
...SaasVisualizationSpecs
|
|
143
|
+
]);
|
|
144
|
+
var SaasVisualizationRefs = SaasVisualizationSpecs.map((spec) => ({
|
|
145
|
+
key: spec.meta.key,
|
|
146
|
+
version: spec.meta.version
|
|
147
|
+
}));
|
|
148
|
+
export {
|
|
149
|
+
SaasVisualizationSpecs,
|
|
150
|
+
SaasVisualizationRegistry,
|
|
151
|
+
SaasVisualizationRefs,
|
|
152
|
+
SaasProjectUsageVisualization,
|
|
153
|
+
SaasProjectTierVisualization,
|
|
154
|
+
SaasProjectStatusVisualization,
|
|
155
|
+
SaasProjectActivityVisualization
|
|
156
|
+
};
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// src/visualizations/catalog.ts
|
|
3
|
+
import {
|
|
4
|
+
defineVisualization,
|
|
5
|
+
VisualizationRegistry
|
|
6
|
+
} from "@contractspec/lib.contracts-spec/visualizations";
|
|
7
|
+
var PROJECT_LIST_REF = {
|
|
8
|
+
key: "saas.project.list",
|
|
9
|
+
version: "1.0.0"
|
|
10
|
+
};
|
|
11
|
+
var META = {
|
|
12
|
+
version: "1.0.0",
|
|
13
|
+
domain: "saas",
|
|
14
|
+
stability: "experimental",
|
|
15
|
+
owners: ["@example.saas-boilerplate"],
|
|
16
|
+
tags: ["saas", "visualization", "projects"]
|
|
17
|
+
};
|
|
18
|
+
var SaasProjectUsageVisualization = defineVisualization({
|
|
19
|
+
meta: {
|
|
20
|
+
...META,
|
|
21
|
+
key: "saas-boilerplate.visualization.project-usage",
|
|
22
|
+
title: "Project Capacity",
|
|
23
|
+
description: "Current project count against the current plan limit.",
|
|
24
|
+
goal: "Show usage against the active plan allowance.",
|
|
25
|
+
context: "SaaS account overview."
|
|
26
|
+
},
|
|
27
|
+
source: { primary: PROJECT_LIST_REF, resultPath: "data" },
|
|
28
|
+
visualization: {
|
|
29
|
+
kind: "metric",
|
|
30
|
+
measure: "totalProjects",
|
|
31
|
+
comparisonMeasure: "projectLimit",
|
|
32
|
+
measures: [
|
|
33
|
+
{
|
|
34
|
+
key: "totalProjects",
|
|
35
|
+
label: "Projects",
|
|
36
|
+
dataPath: "totalProjects",
|
|
37
|
+
format: "number"
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
key: "projectLimit",
|
|
41
|
+
label: "Plan Limit",
|
|
42
|
+
dataPath: "projectLimit",
|
|
43
|
+
format: "number"
|
|
44
|
+
}
|
|
45
|
+
],
|
|
46
|
+
table: { caption: "Current project count and plan limit." }
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
var SaasProjectStatusVisualization = defineVisualization({
|
|
50
|
+
meta: {
|
|
51
|
+
...META,
|
|
52
|
+
key: "saas-boilerplate.visualization.project-status",
|
|
53
|
+
title: "Project Status",
|
|
54
|
+
description: "Distribution of project states.",
|
|
55
|
+
goal: "Show the mix of active, draft, and archived projects.",
|
|
56
|
+
context: "Project portfolio overview."
|
|
57
|
+
},
|
|
58
|
+
source: { primary: PROJECT_LIST_REF, resultPath: "data" },
|
|
59
|
+
visualization: {
|
|
60
|
+
kind: "pie",
|
|
61
|
+
nameDimension: "status",
|
|
62
|
+
valueMeasure: "projects",
|
|
63
|
+
dimensions: [
|
|
64
|
+
{ key: "status", label: "Status", dataPath: "status", type: "category" }
|
|
65
|
+
],
|
|
66
|
+
measures: [
|
|
67
|
+
{
|
|
68
|
+
key: "projects",
|
|
69
|
+
label: "Projects",
|
|
70
|
+
dataPath: "projects",
|
|
71
|
+
format: "number"
|
|
72
|
+
}
|
|
73
|
+
],
|
|
74
|
+
table: { caption: "Project counts by status." }
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
var SaasProjectTierVisualization = defineVisualization({
|
|
78
|
+
meta: {
|
|
79
|
+
...META,
|
|
80
|
+
key: "saas-boilerplate.visualization.project-tiers",
|
|
81
|
+
title: "Tier Comparison",
|
|
82
|
+
description: "Distribution of projects across tiers.",
|
|
83
|
+
goal: "Compare how the current portfolio is distributed by tier.",
|
|
84
|
+
context: "Plan and packaging overview."
|
|
85
|
+
},
|
|
86
|
+
source: { primary: PROJECT_LIST_REF, resultPath: "data" },
|
|
87
|
+
visualization: {
|
|
88
|
+
kind: "cartesian",
|
|
89
|
+
variant: "bar",
|
|
90
|
+
xDimension: "tier",
|
|
91
|
+
yMeasures: ["projects"],
|
|
92
|
+
dimensions: [
|
|
93
|
+
{ key: "tier", label: "Tier", dataPath: "tier", type: "category" }
|
|
94
|
+
],
|
|
95
|
+
measures: [
|
|
96
|
+
{
|
|
97
|
+
key: "projects",
|
|
98
|
+
label: "Projects",
|
|
99
|
+
dataPath: "projects",
|
|
100
|
+
format: "number",
|
|
101
|
+
color: "#1d4ed8"
|
|
102
|
+
}
|
|
103
|
+
],
|
|
104
|
+
table: { caption: "Project counts by tier." }
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
var SaasProjectActivityVisualization = defineVisualization({
|
|
108
|
+
meta: {
|
|
109
|
+
...META,
|
|
110
|
+
key: "saas-boilerplate.visualization.project-activity",
|
|
111
|
+
title: "Recent Project Activity",
|
|
112
|
+
description: "Daily project creation activity.",
|
|
113
|
+
goal: "Show recent project activity over time.",
|
|
114
|
+
context: "Project portfolio trend view."
|
|
115
|
+
},
|
|
116
|
+
source: { primary: PROJECT_LIST_REF, resultPath: "data" },
|
|
117
|
+
visualization: {
|
|
118
|
+
kind: "cartesian",
|
|
119
|
+
variant: "line",
|
|
120
|
+
xDimension: "day",
|
|
121
|
+
yMeasures: ["projects"],
|
|
122
|
+
dimensions: [{ key: "day", label: "Day", dataPath: "day", type: "time" }],
|
|
123
|
+
measures: [
|
|
124
|
+
{
|
|
125
|
+
key: "projects",
|
|
126
|
+
label: "Projects",
|
|
127
|
+
dataPath: "projects",
|
|
128
|
+
format: "number",
|
|
129
|
+
color: "#0f766e"
|
|
130
|
+
}
|
|
131
|
+
],
|
|
132
|
+
table: { caption: "Daily project creation counts." }
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
var SaasVisualizationSpecs = [
|
|
136
|
+
SaasProjectUsageVisualization,
|
|
137
|
+
SaasProjectStatusVisualization,
|
|
138
|
+
SaasProjectTierVisualization,
|
|
139
|
+
SaasProjectActivityVisualization
|
|
140
|
+
];
|
|
141
|
+
var SaasVisualizationRegistry = new VisualizationRegistry([
|
|
142
|
+
...SaasVisualizationSpecs
|
|
143
|
+
]);
|
|
144
|
+
var SaasVisualizationRefs = SaasVisualizationSpecs.map((spec) => ({
|
|
145
|
+
key: spec.meta.key,
|
|
146
|
+
version: spec.meta.version
|
|
147
|
+
}));
|
|
148
|
+
|
|
149
|
+
// src/visualizations/selectors.ts
|
|
150
|
+
function toDayKey(value) {
|
|
151
|
+
const date = value instanceof Date ? value : new Date(value);
|
|
152
|
+
return date.toISOString().slice(0, 10);
|
|
153
|
+
}
|
|
154
|
+
function createSaasVisualizationItems(projects, projectLimit = 10) {
|
|
155
|
+
const statusCounts = new Map;
|
|
156
|
+
const tierCounts = new Map;
|
|
157
|
+
const activityCounts = new Map;
|
|
158
|
+
for (const project of projects) {
|
|
159
|
+
statusCounts.set(project.status, (statusCounts.get(project.status) ?? 0) + 1);
|
|
160
|
+
tierCounts.set(project.tier, (tierCounts.get(project.tier) ?? 0) + 1);
|
|
161
|
+
const day = toDayKey(project.createdAt);
|
|
162
|
+
activityCounts.set(day, (activityCounts.get(day) ?? 0) + 1);
|
|
163
|
+
}
|
|
164
|
+
return [
|
|
165
|
+
{
|
|
166
|
+
key: "saas-capacity",
|
|
167
|
+
spec: SaasProjectUsageVisualization,
|
|
168
|
+
data: { data: [{ totalProjects: projects.length, projectLimit }] },
|
|
169
|
+
title: "Project Capacity",
|
|
170
|
+
description: "Current project count compared to the active limit.",
|
|
171
|
+
height: 220
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
key: "saas-status",
|
|
175
|
+
spec: SaasProjectStatusVisualization,
|
|
176
|
+
data: {
|
|
177
|
+
data: Array.from(statusCounts.entries()).map(([status, count]) => ({
|
|
178
|
+
status,
|
|
179
|
+
projects: count
|
|
180
|
+
}))
|
|
181
|
+
},
|
|
182
|
+
title: "Project Status",
|
|
183
|
+
description: "Status mix across the current project portfolio.",
|
|
184
|
+
height: 260
|
|
185
|
+
},
|
|
186
|
+
{
|
|
187
|
+
key: "saas-tier",
|
|
188
|
+
spec: SaasProjectTierVisualization,
|
|
189
|
+
data: {
|
|
190
|
+
data: Array.from(tierCounts.entries()).map(([tier, count]) => ({
|
|
191
|
+
tier,
|
|
192
|
+
projects: count
|
|
193
|
+
}))
|
|
194
|
+
},
|
|
195
|
+
title: "Tier Comparison",
|
|
196
|
+
description: "How projects are distributed across tiers."
|
|
197
|
+
},
|
|
198
|
+
{
|
|
199
|
+
key: "saas-activity",
|
|
200
|
+
spec: SaasProjectActivityVisualization,
|
|
201
|
+
data: {
|
|
202
|
+
data: Array.from(activityCounts.entries()).sort(([left], [right]) => left.localeCompare(right)).map(([day, count]) => ({ day, projects: count }))
|
|
203
|
+
},
|
|
204
|
+
title: "Recent Project Activity",
|
|
205
|
+
description: "Daily project creation activity."
|
|
206
|
+
}
|
|
207
|
+
];
|
|
208
|
+
}
|
|
209
|
+
export {
|
|
210
|
+
createSaasVisualizationItems,
|
|
211
|
+
SaasVisualizationSpecs,
|
|
212
|
+
SaasVisualizationRegistry,
|
|
213
|
+
SaasVisualizationRefs,
|
|
214
|
+
SaasProjectUsageVisualization,
|
|
215
|
+
SaasProjectTierVisualization,
|
|
216
|
+
SaasProjectStatusVisualization,
|
|
217
|
+
SaasProjectActivityVisualization
|
|
218
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { VisualizationSurfaceItem } from '@contractspec/lib.design-system';
|
|
2
|
+
import type { Project } from '../handlers/saas.handlers';
|
|
3
|
+
type DateLike = Date | string;
|
|
4
|
+
interface ProjectLike extends Pick<Project, 'status' | 'tier'> {
|
|
5
|
+
createdAt: DateLike;
|
|
6
|
+
}
|
|
7
|
+
export declare function createSaasVisualizationItems(projects: ProjectLike[], projectLimit?: number): VisualizationSurfaceItem[];
|
|
8
|
+
export {};
|