@svgrid/enterprise 1.2.0 → 2.0.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 (159) hide show
  1. package/dist/cdn/svgrid-enterprise.svelte-external.js +26039 -805
  2. package/dist/designer/assets/index-Dp44bTid.js +939 -0
  3. package/dist/designer/assets/index-RJp6x8tw.css +1 -0
  4. package/dist/designer/assets/jszip.min-CjMo-QGg.js +2 -0
  5. package/dist/designer/index.html +13 -0
  6. package/dist/node/studio.js +22554 -0
  7. package/package.json +10 -3
  8. package/src/SvAuthGate.svelte +115 -0
  9. package/src/SvBoard.dom.test.ts +67 -0
  10. package/src/SvBoard.svelte +192 -0
  11. package/src/SvExportMenu.svelte +553 -0
  12. package/src/SvFileInput.svelte +113 -0
  13. package/src/SvGridEditPanel.dom.test.ts +146 -0
  14. package/src/SvGridEditPanel.svelte +793 -0
  15. package/src/SvGridMasterDetail.svelte +95 -0
  16. package/src/SvImportDialog.svelte +1020 -0
  17. package/src/SvLookupInput.svelte +180 -0
  18. package/src/SvRecordDetail.dom.test.ts +137 -0
  19. package/src/SvRecordDetail.svelte +288 -0
  20. package/src/SvSchedule.dom.test.ts +57 -0
  21. package/src/SvSchedule.svelte +156 -0
  22. package/src/SvSchemaChart.svelte +233 -0
  23. package/src/SvSchemaDashboard.svelte +130 -0
  24. package/src/ai-export-pdf.test.ts +74 -0
  25. package/src/ai-export-xlsx.test.ts +87 -0
  26. package/src/ai-export.test.ts +110 -0
  27. package/src/ai.ts +1188 -782
  28. package/src/edit-panel.test.ts +213 -0
  29. package/src/edit-panel.ts +228 -0
  30. package/src/export-conditional.test.ts +60 -0
  31. package/src/export-conditional.ts +94 -0
  32. package/src/export-ooxml.test.ts +152 -0
  33. package/src/export-ooxml.ts +485 -0
  34. package/src/export-pdf.test.ts +138 -0
  35. package/src/export-pdf.ts +245 -0
  36. package/src/export-print.test.ts +66 -0
  37. package/src/export-print.ts +132 -0
  38. package/src/export-serialize.test.ts +56 -0
  39. package/src/export-serialize.ts +24 -0
  40. package/src/export-xls.ts +196 -0
  41. package/src/export-xlsx-roundtrip.test.ts +120 -0
  42. package/src/export-xlsx.test.ts +150 -0
  43. package/src/export.test.ts +349 -0
  44. package/src/export.ts +1452 -549
  45. package/src/import-automap.test.ts +131 -0
  46. package/src/import-hardening.test.ts +158 -0
  47. package/src/import.ts +1042 -648
  48. package/src/index.ts +282 -0
  49. package/src/install.ts +134 -114
  50. package/src/license-core.test.ts +23 -0
  51. package/src/license-core.ts +35 -0
  52. package/src/license.ts +103 -90
  53. package/src/master-detail.test.ts +61 -0
  54. package/src/master-detail.ts +42 -0
  55. package/src/print.ts +107 -127
  56. package/src/schema-designer.test.ts +121 -0
  57. package/src/schema-designer.ts +142 -0
  58. package/src/schema.test.ts +268 -0
  59. package/src/schema.ts +499 -0
  60. package/src/smart-shim.ts +107 -105
  61. package/src/sources/aggregate.test.ts +79 -0
  62. package/src/sources/aggregate.ts +102 -0
  63. package/src/sources/auth-supabase.test.ts +80 -0
  64. package/src/sources/auth-supabase.ts +87 -0
  65. package/src/sources/dashboard.kpi.test.ts +50 -0
  66. package/src/sources/dashboard.test.ts +61 -0
  67. package/src/sources/dashboard.ts +136 -0
  68. package/src/sources/field-inference.test.ts +60 -0
  69. package/src/sources/field-inference.ts +63 -0
  70. package/src/sources/filters.test.ts +58 -0
  71. package/src/sources/filters.ts +64 -0
  72. package/src/sources/index.ts +67 -0
  73. package/src/sources/introspect-supabase.test.ts +100 -0
  74. package/src/sources/introspect-supabase.ts +119 -0
  75. package/src/sources/realtime-supabase.test.ts +93 -0
  76. package/src/sources/realtime-supabase.ts +99 -0
  77. package/src/sources/relation-lookup.test.ts +99 -0
  78. package/src/sources/relation-lookup.ts +128 -0
  79. package/src/sources/rest-adapters.test.ts +95 -0
  80. package/src/sources/rest-adapters.ts +120 -0
  81. package/src/sources/rest.test.ts +104 -0
  82. package/src/sources/rest.ts +129 -0
  83. package/src/sources/schema-from-columns.test.ts +106 -0
  84. package/src/sources/schema-from-columns.ts +88 -0
  85. package/src/sources/supabase.test.ts +110 -0
  86. package/src/sources/supabase.ts +99 -0
  87. package/src/sources/with-entity-rules.test.ts +104 -0
  88. package/src/sources/with-entity-rules.ts +78 -0
  89. package/src/sources/with-relation-labels.test.ts +75 -0
  90. package/src/sources/with-relation-labels.ts +73 -0
  91. package/src/studio/bug-report.test.ts +101 -0
  92. package/src/studio/bug-report.ts +165 -0
  93. package/src/studio/cli.test.ts +187 -0
  94. package/src/studio/cli.ts +112 -0
  95. package/src/studio/csv.test.ts +90 -0
  96. package/src/studio/csv.ts +165 -0
  97. package/src/studio/db-connect-string.test.ts +94 -0
  98. package/src/studio/db-connect-string.ts +128 -0
  99. package/src/studio/emit-project.test.ts +923 -0
  100. package/src/studio/emit-project.ts +1273 -0
  101. package/src/studio/emit-schema.test.ts +94 -0
  102. package/src/studio/emit-schema.ts +920 -0
  103. package/src/studio/index.ts +195 -0
  104. package/src/studio/introspect-db.test.ts +186 -0
  105. package/src/studio/introspect-db.ts +312 -0
  106. package/src/studio/introspect-prisma.test.ts +99 -0
  107. package/src/studio/introspect-prisma.ts +175 -0
  108. package/src/studio/introspect.test.ts +172 -0
  109. package/src/studio/introspect.ts +310 -0
  110. package/src/studio/pipeline.test.ts +42 -0
  111. package/src/studio/project-robust.test.ts +157 -0
  112. package/src/studio/project.test.ts +473 -0
  113. package/src/studio/project.ts +916 -0
  114. package/src/studio/sample-data.test.ts +58 -0
  115. package/src/studio/sample-data.ts +200 -0
  116. package/src/studio/samples/ats.ts +202 -0
  117. package/src/studio/samples/clinic.ts +177 -0
  118. package/src/studio/samples/crm.ts +250 -0
  119. package/src/studio/samples/ecommerce.ts +187 -0
  120. package/src/studio/samples/events.ts +199 -0
  121. package/src/studio/samples/fleet.ts +184 -0
  122. package/src/studio/samples/gym.ts +213 -0
  123. package/src/studio/samples/hr.ts +193 -0
  124. package/src/studio/samples/index.ts +55 -0
  125. package/src/studio/samples/insurance.ts +195 -0
  126. package/src/studio/samples/inventory.ts +182 -0
  127. package/src/studio/samples/invoicing.ts +162 -0
  128. package/src/studio/samples/library.ts +180 -0
  129. package/src/studio/samples/live-data.test.ts +98 -0
  130. package/src/studio/samples/live-data.ts +308 -0
  131. package/src/studio/samples/projects.ts +190 -0
  132. package/src/studio/samples/realestate.ts +196 -0
  133. package/src/studio/samples/restaurant.ts +187 -0
  134. package/src/studio/samples/samples.test.ts +208 -0
  135. package/src/studio/samples/school.ts +197 -0
  136. package/src/studio/samples/seed-floor.test.ts +25 -0
  137. package/src/studio/samples/shared.ts +305 -0
  138. package/src/studio/samples/subscriptions.ts +183 -0
  139. package/src/studio/samples/support.ts +182 -0
  140. package/src/studio/scaffold-app.test.ts +91 -0
  141. package/src/studio/scaffold-app.ts +161 -0
  142. package/src/studio/scaffold.test.ts +178 -0
  143. package/src/studio/scaffold.ts +374 -0
  144. package/src/studio/themes.ts +172 -0
  145. package/src/studio/verify.test.ts +47 -0
  146. package/src/studio/verify.ts +79 -0
  147. package/src/sveltekit/in-memory.test.ts +104 -0
  148. package/src/sveltekit/in-memory.ts +129 -0
  149. package/src/sveltekit/index.ts +23 -0
  150. package/src/sveltekit/query-plan.test.ts +109 -0
  151. package/src/sveltekit/query-plan.ts +125 -0
  152. package/src/sveltekit/sql-source.test.ts +185 -0
  153. package/src/sveltekit/sql-source.ts +166 -0
  154. package/src/sveltekit/sql.test.ts +80 -0
  155. package/src/sveltekit/sql.ts +131 -0
  156. package/src/sveltekit/transport.test.ts +175 -0
  157. package/src/sveltekit/transport.ts +254 -0
  158. package/src/sveltekit/types.ts +11 -0
  159. package/src/upgrade-prompt.ts +149 -148
@@ -0,0 +1,195 @@
1
+ import type { EntitySchema } from '../../schema.js'
2
+ import type { FormatRule } from '../project.js'
3
+ import { screen, formScreen, boardScreen, calendarScreen, detailScreen, project, dashScreen, statusPills, pad, ids, type SampleApp } from './shared.js'
4
+
5
+ const policies: EntitySchema = {
6
+ name: 'policies',
7
+ label: 'Policy',
8
+ idField: 'id',
9
+ fields: [
10
+ { field: 'id', type: 'text', primaryKey: true, readonly: true },
11
+ { field: 'policyNumber', type: 'text', label: 'Policy #', required: true, input: { editorType: 'mask', mask: 'POL-######', help: 'Policy identifier' } },
12
+ { field: 'holder', type: 'text', label: 'Policy holder', required: true, minLength: 2 },
13
+ { field: 'email', type: 'text', label: 'Email', format: 'email', required: true, input: { placeholder: 'holder@example.com' } },
14
+ { field: 'type', type: 'enum', label: 'Line', required: true, options: [
15
+ { value: 'auto', label: 'Auto', color: '#6366f1' },
16
+ { value: 'home', label: 'Home', color: '#10b981' },
17
+ { value: 'life', label: 'Life', color: '#f59e0b' },
18
+ { value: 'health', label: 'Health', color: '#ef4444' },
19
+ ] },
20
+ { field: 'region', type: 'text', label: 'Region', input: { editorType: 'country', help: 'Underwriting region' } },
21
+ { field: 'premium', type: 'number', label: 'Premium ($)', min: 0, required: true },
22
+ { field: 'coverage', type: 'number', label: 'Coverage ($)', min: 0, required: true },
23
+ { field: 'riskScore', type: 'number', label: 'Risk', min: 1, max: 5, defaultValue: 3, input: { editorType: 'rating', help: '1 (low) - 5 (high) underwriting risk' } },
24
+ { field: 'status', type: 'enum', label: 'Status', defaultValue: 'active', options: [
25
+ { value: 'active', label: 'Active', color: '#10b981' },
26
+ { value: 'lapsed', label: 'Lapsed', color: '#f59e0b' },
27
+ { value: 'cancelled', label: 'Cancelled', color: '#ef4444' },
28
+ ] },
29
+ { field: 'startDate', type: 'date', label: 'Start date' },
30
+ ],
31
+ }
32
+
33
+ const adjusters: EntitySchema = {
34
+ name: 'adjusters',
35
+ label: 'Adjuster',
36
+ idField: 'id',
37
+ fields: [
38
+ { field: 'id', type: 'text', primaryKey: true, readonly: true },
39
+ { field: 'name', type: 'text', required: true, minLength: 2 },
40
+ { field: 'email', type: 'text', format: 'email', required: true },
41
+ { field: 'phone', type: 'text', input: { editorType: 'phone' } },
42
+ { field: 'region', type: 'text', label: 'Region', input: { editorType: 'country' } },
43
+ { field: 'specialty', type: 'enum', label: 'Specialty', options: [
44
+ { value: 'auto', label: 'Auto', color: '#6366f1' },
45
+ { value: 'property', label: 'Property', color: '#10b981' },
46
+ { value: 'medical', label: 'Medical', color: '#ef4444' },
47
+ { value: 'liability', label: 'Liability', color: '#f59e0b' },
48
+ ] },
49
+ { field: 'rating', type: 'number', label: 'Rating', min: 1, max: 5, defaultValue: 4, input: { editorType: 'rating', help: 'Resolution quality' } },
50
+ { field: 'color', type: 'text', label: 'Accent', defaultValue: '#0ea5e9', input: { editorType: 'color', help: 'Chart accent color' } },
51
+ { field: 'active', type: 'boolean', label: 'Active', defaultValue: true },
52
+ ],
53
+ }
54
+
55
+ const claims: EntitySchema = {
56
+ name: 'claims',
57
+ label: 'Claim',
58
+ idField: 'id',
59
+ fields: [
60
+ { field: 'id', type: 'text', primaryKey: true, readonly: true },
61
+ { field: 'claimNumber', type: 'text', label: 'Claim #', required: true, input: { editorType: 'mask', mask: 'CLM-######', help: 'Claim reference' } },
62
+ { field: 'policyId', type: 'relation', label: 'Policy', required: true, relation: { entity: 'policies', foreignKey: 'policyId', labelField: 'policyNumber' } },
63
+ { field: 'adjusterId', type: 'relation', label: 'Adjuster', relation: { entity: 'adjusters', foreignKey: 'adjusterId', labelField: 'name' } },
64
+ { field: 'type', type: 'enum', label: 'Type', required: true, options: [
65
+ { value: 'collision', label: 'Collision', color: '#6366f1' },
66
+ { value: 'theft', label: 'Theft', color: '#8b5cf6' },
67
+ { value: 'fire', label: 'Fire', color: '#ef4444' },
68
+ { value: 'water', label: 'Water', color: '#0ea5e9' },
69
+ { value: 'medical', label: 'Medical', color: '#10b981' },
70
+ ] },
71
+ { field: 'status', type: 'enum', label: 'Status', required: true, defaultValue: 'filed', options: [
72
+ { value: 'filed', label: 'Filed', color: '#94a3b8' },
73
+ { value: 'review', label: 'In review', color: '#0ea5e9' },
74
+ { value: 'approved', label: 'Approved', color: '#6366f1' },
75
+ { value: 'paid', label: 'Paid', color: '#10b981' },
76
+ { value: 'denied', label: 'Denied', color: '#ef4444' },
77
+ ] },
78
+ { field: 'amount', type: 'number', label: 'Amount ($)', min: 0, required: true },
79
+ { field: 'deductible', type: 'number', label: 'Deductible ($)', min: 0, defaultValue: 500 },
80
+ // Derived: net payout after the deductible (display-only, never stored).
81
+ { field: 'net', type: 'number', label: 'Net payout ($)', readonly: true, formula: 'amount - deductible' },
82
+ { field: 'severity', type: 'number', label: 'Severity', min: 0, max: 100, defaultValue: 40, input: { editorType: 'slider', suffix: '%', help: 'Loss severity 0-100' } },
83
+ { field: 'fraudRisk', type: 'number', label: 'Fraud risk', min: 1, max: 5, defaultValue: 1, input: { editorType: 'rating', help: 'Fraud indicators 1-5' } },
84
+ { field: 'tags', type: 'text', label: 'Tags', input: { editorType: 'chips', help: 'Triage keywords' } },
85
+ { field: 'incidentDate', type: 'date', label: 'Incident date' },
86
+ { field: 'filedAt', type: 'datetime', label: 'Filed at', input: { editorType: 'datetime', help: 'When the claim was filed' } },
87
+ ],
88
+ }
89
+
90
+ const seed = {
91
+ policies: [
92
+ { id: 'pl1', policyNumber: 'POL-100001', holder: 'Oliver Grant', email: 'oliver.grant@example.com', type: 'auto', region: 'United States', premium: 1200, coverage: 45000, riskScore: 2, status: 'active', startDate: '2024-03-01' },
93
+ { id: 'pl2', policyNumber: 'POL-100002', holder: 'Maya Fernandez', email: 'maya.fernandez@example.com', type: 'home', region: 'Spain', premium: 980, coverage: 320000, riskScore: 3, status: 'active', startDate: '2023-11-15' },
94
+ { id: 'pl3', policyNumber: 'POL-100003', holder: 'Noah Kim', email: 'noah.kim@example.com', type: 'health', region: 'South Korea', premium: 2100, coverage: 150000, riskScore: 4, status: 'active', startDate: '2025-01-08' },
95
+ { id: 'pl4', policyNumber: 'POL-100004', holder: 'Sophia Rossi', email: 'sophia.rossi@example.com', type: 'life', region: 'Italy', premium: 1650, coverage: 500000, riskScore: 2, status: 'lapsed', startDate: '2022-06-20' },
96
+ { id: 'pl5', policyNumber: 'POL-100005', holder: 'Ethan Walsh', email: 'ethan.walsh@example.com', type: 'auto', region: 'United States', premium: 1420, coverage: 52000, riskScore: 5, status: 'active', startDate: '2024-09-12' },
97
+ { id: 'pl6', policyNumber: 'POL-100006', holder: 'Amara Okafor', email: 'amara.okafor@example.com', type: 'home', region: 'Nigeria', premium: 760, coverage: 210000, riskScore: 3, status: 'cancelled', startDate: '2023-02-28' },
98
+ { id: 'pl7', policyNumber: 'POL-100007', holder: 'Liam Murphy', email: 'liam.murphy@example.com', type: 'health', region: 'Ireland', premium: 1890, coverage: 180000, riskScore: 4, status: 'active', startDate: '2024-12-01' },
99
+ { id: 'pl8', policyNumber: 'POL-100008', holder: 'Hana Sato', email: 'hana.sato@example.com', type: 'auto', region: 'Japan', premium: 1310, coverage: 48000, riskScore: 2, status: 'active', startDate: '2025-02-19' },
100
+ ],
101
+ adjusters: [
102
+ { id: 'ad1', name: 'Grace Okonkwo', email: 'grace.okonkwo@insureco.com', phone: '+1 (415) 555-0301', region: 'United States', specialty: 'auto', rating: 5, color: '#6366f1', active: true },
103
+ { id: 'ad2', name: 'Marcus Bauer', email: 'marcus.bauer@insureco.com', phone: '+49 30 5550302', region: 'Germany', specialty: 'property', rating: 4, color: '#10b981', active: true },
104
+ { id: 'ad3', name: 'Priya Nair', email: 'priya.nair@insureco.com', phone: '+91 22 5550 303', region: 'India', specialty: 'medical', rating: 5, color: '#ef4444', active: true },
105
+ { id: 'ad4', name: 'Diego Santos', email: 'diego.santos@insureco.com', phone: '+55 11 95555-0304', region: 'Brazil', specialty: 'liability', rating: 3, color: '#f59e0b', active: true },
106
+ { id: 'ad5', name: 'Elena Popova', email: 'elena.popova@insureco.com', phone: '+7 495 555 0305', region: 'Russia', specialty: 'property', rating: 4, color: '#8b5cf6', active: false },
107
+ { id: 'ad6', name: 'Thomas Becker', email: 'thomas.becker@insureco.com', phone: '+1 (206) 555-0306', region: 'United States', specialty: 'auto', rating: 4, color: '#0ea5e9', active: true },
108
+ ],
109
+ claims: [
110
+ { id: 'cl1', claimNumber: 'CLM-500001', policyId: 'pl1', adjusterId: 'ad1', type: 'collision', status: 'paid', amount: 8400, deductible: 500, severity: 55, fraudRisk: 1, tags: ['rear-end', 'no-injury'], incidentDate: '2026-01-04', filedAt: '2026-01-06T09:30:00.000Z' },
111
+ { id: 'cl2', claimNumber: 'CLM-500002', policyId: 'pl2', adjusterId: 'ad2', type: 'water', status: 'review', amount: 15200, deductible: 1000, severity: 70, fraudRisk: 2, tags: ['burst-pipe'], incidentDate: '2026-02-01', filedAt: '2026-02-03T14:15:00.000Z' },
112
+ { id: 'cl3', claimNumber: 'CLM-500003', policyId: 'pl3', adjusterId: 'ad3', type: 'medical', status: 'approved', amount: 6200, deductible: 750, severity: 40, fraudRisk: 1, tags: ['surgery'], incidentDate: '2026-02-10', filedAt: '2026-02-12T11:00:00.000Z' },
113
+ { id: 'cl4', claimNumber: 'CLM-500004', policyId: 'pl5', adjusterId: 'ad1', type: 'theft', status: 'denied', amount: 22000, deductible: 500, severity: 90, fraudRisk: 5, tags: ['suspicious', 'late-report'], incidentDate: '2026-01-20', filedAt: '2026-01-28T16:45:00.000Z' },
114
+ { id: 'cl5', claimNumber: 'CLM-500005', policyId: 'pl6', adjusterId: 'ad4', type: 'fire', status: 'paid', amount: 41000, deductible: 2000, severity: 95, fraudRisk: 2, tags: ['kitchen', 'total-loss'], incidentDate: '2026-03-01', filedAt: '2026-03-02T08:20:00.000Z' },
115
+ { id: 'cl6', claimNumber: 'CLM-500006', policyId: 'pl7', adjusterId: 'ad3', type: 'medical', status: 'filed', amount: 3100, deductible: 750, severity: 25, fraudRisk: 1, tags: ['ER-visit'], incidentDate: '2026-03-11', filedAt: '2026-03-12T13:10:00.000Z' },
116
+ { id: 'cl7', claimNumber: 'CLM-500007', policyId: 'pl8', adjusterId: 'ad6', type: 'collision', status: 'review', amount: 9700, deductible: 500, severity: 60, fraudRisk: 3, tags: ['intersection'], incidentDate: '2026-03-15', filedAt: '2026-03-17T10:05:00.000Z' },
117
+ { id: 'cl8', claimNumber: 'CLM-500008', policyId: 'pl1', adjusterId: 'ad6', type: 'theft', status: 'approved', amount: 5400, deductible: 500, severity: 50, fraudRisk: 2, tags: ['catalytic-converter'], incidentDate: '2026-02-22', filedAt: '2026-02-24T15:30:00.000Z' },
118
+ ],
119
+ }
120
+
121
+ // Claim grid formatting: status pills + a red-bold high-fraud threshold and a
122
+ // green highlight on large approved payouts - data-driven, not just pills.
123
+ const claimFormats: FormatRule[] = [
124
+ ...statusPills(claims, 'status'),
125
+ { field: 'fraudRisk', op: 'gte', value: 4, color: '#dc2626', bold: true },
126
+ { field: 'amount', op: 'gte', value: 20000, color: '#b45309', bold: true },
127
+ ]
128
+
129
+ export const insurance: SampleApp = {
130
+ id: 'insurance',
131
+ name: 'Insurance Claims',
132
+ description: 'Policies, adjusters and claims - a claims pipeline board (Filed -> Paid), payout + approval dashboards (target KPIs, a filings sparkline, a severity gauge, type/status breakdowns, an adjuster x status pivot, tabbed views), a fraud-risk red grid, policy master/detail with a claims timeline, and rich edit forms (policy/claim number masks, region, adjuster phone, risk + fraud ratings, severity slider, triage chips, filing datetime).',
133
+ emoji: '\u{1F6E1}\u{FE0F}',
134
+ accent: '#1e5eff',
135
+ build: () => {
136
+ const policyRows = pad(policies, seed.policies, 40)
137
+ const adjusterRows = pad(adjusters, seed.adjusters, 16)
138
+ const claimRows = pad(claims, seed.claims, 90, { policyId: ids(policyRows), adjusterId: ids(adjusterRows) })
139
+ return project({
140
+ title: 'Claims',
141
+ brand: 'Assurance',
142
+ accent: '#1e5eff',
143
+ preset: 'sap',
144
+ footer: '',
145
+ entities: [policies, adjusters, claims],
146
+ seed: { policies: policyRows, adjusters: adjusterRows, claims: claimRows },
147
+ screens: [
148
+ // Claims dashboard: payout + approval KPIs (total payout carries a target,
149
+ // filings trend as a sparkline), a severity gauge, type/status breakdowns,
150
+ // an adjuster x status pivot, tabs, and a fraud-risk status-pill grid that
151
+ // drills into the claim detail.
152
+ dashScreen(claims, { id: 'overview', title: 'Claims', order: 0 }, [
153
+ { kpi: 'Claims', reduce: 'count', span: 1 },
154
+ { kpi: 'Total payout', measure: 'net', reduce: 'sum', format: 'currency', target: 200000, span: 1 },
155
+ { kpi: 'Filings', measure: 'amount', reduce: 'count', trendField: 'filedAt', trendReduce: 'count', span: 1 },
156
+ { gauge: 'Avg severity', measure: 'severity', reduce: 'avg', min: 0, max: 100, unit: '%', span: 1 },
157
+ { chart: 'status', measure: 'amount', reduce: 'sum', type: 'bar', span: 2 },
158
+ { chart: 'type', reduce: 'count', type: 'pie', span: 1 },
159
+ { chart: 'filedAt', measure: 'amount', reduce: 'sum', type: 'area', span: 3 },
160
+ { pivot: { rows: ['adjusterId'], cols: ['status'], measure: 'amount', aggregate: 'sum' }, span: 3 },
161
+ { tabs: [
162
+ { label: 'Payout by status', tiles: [{ chart: 'status', measure: 'net', reduce: 'sum', type: 'bar' }] },
163
+ { label: 'Claims by type', tiles: [{ chart: 'type', reduce: 'count', type: 'bar' }] },
164
+ ], span: 3 },
165
+ { grid: true, format: claimFormats, summaries: true, rowActions: [{ kind: 'edit' }], rowLink: { screen: 'claim-detail', sourceField: 'id', targetField: 'id' }, span: 3 },
166
+ ]),
167
+ // The signature view: the claims pipeline as draggable Kanban columns by
168
+ // status, each card the claim number + policy + payout; opens the detail.
169
+ boardScreen(claims, { id: 'pipeline', title: 'Pipeline', order: 1 }, { groupBy: 'status', titleField: 'claimNumber', subtitleField: 'policyId', badgeField: 'amount', filter: ['status', 'type', 'adjusterId'], openScreen: 'claim-detail' }),
170
+ // Claim detail: header (claim # + policy + status pill), payout metric
171
+ // tiles, and Overview sections.
172
+ detailScreen(claims, { id: 'claim-detail', title: 'Claim detail', order: 2 }, {
173
+ titleField: 'claimNumber', subtitleField: 'policyId', statusField: 'status',
174
+ metricFields: ['amount', 'net'],
175
+ sections: [
176
+ { label: 'Assessment', fields: ['type', 'severity', 'fraudRisk', 'tags'] },
177
+ { label: 'Handling', fields: ['adjusterId', 'deductible', 'incidentDate', 'filedAt'] },
178
+ ],
179
+ }),
180
+ // Policy 360: a full policy record with a timeline of its claims.
181
+ detailScreen(policies, { id: 'policy-360', title: 'Policy 360', order: 3 }, {
182
+ titleField: 'policyNumber', subtitleField: 'holder', statusField: 'status',
183
+ metricFields: ['premium', 'coverage'],
184
+ sections: [{ label: 'Underwriting', fields: ['type', 'region', 'riskScore', 'startDate'] }],
185
+ related: [{ entity: 'claims', foreignKey: 'policyId', label: 'Claims', titleField: 'claimNumber', subtitleField: 'amount', dateField: 'filedAt', statusField: 'status' }],
186
+ }),
187
+ screen(policies, 'master-detail', { id: 'policies', title: 'Policies', order: 4, child: claims, foreignKey: 'policyId', linkScreen: 'policy-360' }),
188
+ formScreen(claims, { id: 'claims', title: 'Claims list', order: 5 }, undefined, { format: claimFormats, summaries: true, rowActions: [{ kind: 'edit' }], rowLink: { screen: 'claim-detail', sourceField: 'id', targetField: 'id' } }, ['status', 'type', 'policyId']),
189
+ formScreen(adjusters, { id: 'adjusters', title: 'Adjusters', order: 6 }, undefined, {}, ['specialty', 'region', 'active']),
190
+ // Incident calendar: claims placed on a month calendar by incident date.
191
+ calendarScreen(claims, { id: 'calendar', title: 'Incidents', order: 7 }, { dateField: 'incidentDate', titleField: 'claimNumber', filter: ['status', 'type', 'adjusterId'] }),
192
+ ],
193
+ })
194
+ },
195
+ }
@@ -0,0 +1,182 @@
1
+ import type { EntitySchema } from '../../schema.js'
2
+ import type { FormatRule } from '../project.js'
3
+ import { screen, formScreen, boardScreen, detailScreen, project, dashScreen, statusPills, pad, ids, type SampleApp } from './shared.js'
4
+
5
+ const suppliers: EntitySchema = {
6
+ name: 'suppliers',
7
+ label: 'Supplier',
8
+ idField: 'id',
9
+ fields: [
10
+ { field: 'id', type: 'text', primaryKey: true, readonly: true },
11
+ { field: 'name', type: 'text', required: true, minLength: 2 },
12
+ { field: 'country', type: 'text', label: 'Country', input: { editorType: 'country', help: 'Country of dispatch' } },
13
+ { field: 'email', type: 'text', format: 'email', required: true, input: { placeholder: 'orders@supplier.com' } },
14
+ { field: 'phone', type: 'text', input: { editorType: 'phone' } },
15
+ { field: 'rating', type: 'number', label: 'Rating', min: 1, max: 5, defaultValue: 3, input: { editorType: 'rating', help: '1-5 quality score' } },
16
+ { field: 'leadDays', type: 'number', label: 'Lead time (days)', min: 0, defaultValue: 14, input: { help: 'Typical days from order to delivery' } },
17
+ { field: 'color', type: 'text', label: 'Accent', defaultValue: '#f59e0b', input: { editorType: 'color', help: 'Chart accent color' } },
18
+ { field: 'active', type: 'boolean', label: 'Active', defaultValue: true },
19
+ ],
20
+ }
21
+
22
+ const products: EntitySchema = {
23
+ name: 'products',
24
+ label: 'Product',
25
+ idField: 'id',
26
+ fields: [
27
+ { field: 'id', type: 'text', primaryKey: true, readonly: true },
28
+ { field: 'name', type: 'text', required: true, minLength: 2 },
29
+ { field: 'sku', type: 'text', label: 'SKU', required: true, input: { editorType: 'mask', mask: 'AAA-####', help: 'Stock keeping unit' } },
30
+ { field: 'category', type: 'enum', required: true, options: [
31
+ { value: 'electronics', label: 'Electronics', color: '#6366f1' },
32
+ { value: 'office', label: 'Office', color: '#0ea5e9' },
33
+ { value: 'home', label: 'Home', color: '#10b981' },
34
+ { value: 'tools', label: 'Tools', color: '#f59e0b' },
35
+ ] },
36
+ { field: 'tags', type: 'text', label: 'Tags', input: { editorType: 'chips', help: 'Search and filter keywords' } },
37
+ { field: 'price', type: 'number', label: 'Price ($)', min: 0, required: true },
38
+ { field: 'discount', type: 'number', label: 'Discount (%)', min: 0, max: 100, defaultValue: 0, input: { editorType: 'slider', help: 'Current promotional discount' } },
39
+ { field: 'stock', type: 'number', label: 'In stock', min: 0, defaultValue: 0 },
40
+ { field: 'reorderLevel', type: 'number', label: 'Reorder level', min: 0, defaultValue: 20, input: { help: 'Restock when stock drops below this' } },
41
+ // Derived: value of stock on hand (display-only, never stored).
42
+ { field: 'stockValue', type: 'number', label: 'Stock value ($)', readonly: true, formula: 'price * stock' },
43
+ { field: 'active', type: 'boolean', label: 'Active', defaultValue: true },
44
+ ],
45
+ }
46
+
47
+ const purchaseOrders: EntitySchema = {
48
+ name: 'purchaseOrders',
49
+ label: 'Purchase order',
50
+ idField: 'id',
51
+ fields: [
52
+ { field: 'id', type: 'text', primaryKey: true, readonly: true },
53
+ { field: 'ref', type: 'text', label: 'Ref', required: true, minLength: 2 },
54
+ { field: 'supplierId', type: 'relation', label: 'Supplier', relation: { entity: 'suppliers', foreignKey: 'supplierId', labelField: 'name' } },
55
+ { field: 'productId', type: 'relation', label: 'Product', relation: { entity: 'products', foreignKey: 'productId', labelField: 'name' } },
56
+ { field: 'status', type: 'enum', defaultValue: 'draft', options: [
57
+ { value: 'draft', label: 'Draft', color: '#94a3b8' },
58
+ { value: 'ordered', label: 'Ordered', color: '#0ea5e9' },
59
+ { value: 'received', label: 'Received', color: '#10b981' },
60
+ { value: 'cancelled', label: 'Cancelled', color: '#ef4444' },
61
+ ] },
62
+ { field: 'qty', type: 'number', label: 'Quantity', min: 1, defaultValue: 1, required: true },
63
+ { field: 'unitCost', type: 'number', label: 'Unit cost ($)', min: 0, defaultValue: 0 },
64
+ // Derived: line total from quantity and unit cost (display-only, never stored).
65
+ { field: 'total', type: 'number', label: 'Total ($)', readonly: true, formula: 'qty * unitCost' },
66
+ { field: 'orderedAt', type: 'date', label: 'Ordered at', input: { editorType: 'datetime', help: 'When the order was placed' } },
67
+ ],
68
+ }
69
+
70
+ const seed = {
71
+ suppliers: [
72
+ { id: 'sp1', name: 'Shenzhen Components', country: 'China', email: 'sales@shenzhencomp.com', phone: '+86 755 5550 101', rating: 5, leadDays: 21, color: '#6366f1', active: true },
73
+ { id: 'sp2', name: 'Nordic Office Supply', country: 'Sweden', email: 'orders@nordicoffice.se', phone: '+46 8 5550 102', rating: 4, leadDays: 10, color: '#10b981', active: true },
74
+ { id: 'sp3', name: 'Bavaria Tools', country: 'Germany', email: 'info@bavariatools.de', phone: '+49 89 5550103', rating: 5, leadDays: 14, color: '#f59e0b', active: true },
75
+ { id: 'sp4', name: 'Pacific Home Goods', country: 'United States', email: 'hello@pacifichome.com', phone: '+1 (415) 555-0104', rating: 4, leadDays: 7, color: '#0ea5e9', active: true },
76
+ { id: 'sp5', name: 'Kyoto Electronics', country: 'Japan', email: 'sales@kyotoelec.jp', phone: '+81 75 5550 105', rating: 5, leadDays: 18, color: '#8b5cf6', active: true },
77
+ { id: 'sp6', name: 'Toronto Distributors', country: 'Canada', email: 'orders@torontodist.ca', phone: '+1 (416) 555-0106', rating: 4, leadDays: 12, color: '#ef4444', active: false },
78
+ ],
79
+ products: [
80
+ { id: 'pr1', name: 'USB-C Hub', sku: 'ELE-0001', category: 'electronics', tags: ['usb-c', 'hub', 'charging'], price: 39, discount: 10, stock: 420, reorderLevel: 100, active: true },
81
+ { id: 'pr2', name: 'Standing Desk', sku: 'OFF-0101', category: 'office', tags: ['adjustable', 'ergonomic'], price: 480, discount: 5, stock: 35, reorderLevel: 20, active: true },
82
+ { id: 'pr3', name: 'Ceramic Mug Set', sku: 'HOM-0210', category: 'home', tags: ['kitchen', 'ceramic'], price: 24, discount: 0, stock: 610, reorderLevel: 150, active: true },
83
+ { id: 'pr4', name: 'Cordless Drill', sku: 'TOO-0305', category: 'tools', tags: ['power', 'cordless', '18v'], price: 129, discount: 15, stock: 88, reorderLevel: 40, active: true },
84
+ { id: 'pr5', name: 'Mechanical Keyboard', sku: 'ELE-0002', category: 'electronics', tags: ['mechanical', 'rgb', 'usb'], price: 95, discount: 8, stock: 240, reorderLevel: 80, active: true },
85
+ { id: 'pr6', name: 'Ergonomic Chair', sku: 'OFF-0102', category: 'office', tags: ['ergonomic', 'mesh'], price: 320, discount: 12, stock: 52, reorderLevel: 25, active: true },
86
+ { id: 'pr7', name: 'LED Desk Lamp', sku: 'HOM-0211', category: 'home', tags: ['lighting', 'led', 'dimmable'], price: 45, discount: 0, stock: 175, reorderLevel: 60, active: true },
87
+ ],
88
+ purchaseOrders: [
89
+ { id: 'po1', ref: 'PO-4001', supplierId: 'sp1', productId: 'pr1', status: 'received', qty: 200, unitCost: 28, orderedAt: '2026-01-10T09:30:00.000Z' },
90
+ { id: 'po2', ref: 'PO-4002', supplierId: 'sp2', productId: 'pr2', status: 'ordered', qty: 30, unitCost: 360, orderedAt: '2026-02-04T14:15:00.000Z' },
91
+ { id: 'po3', ref: 'PO-4003', supplierId: 'sp3', productId: 'pr4', status: 'draft', qty: 25, unitCost: 92, orderedAt: '2026-02-18T11:00:00.000Z' },
92
+ { id: 'po4', ref: 'PO-4004', supplierId: 'sp4', productId: 'pr3', status: 'cancelled', qty: 100, unitCost: 15, orderedAt: '2026-01-22T16:45:00.000Z' },
93
+ { id: 'po5', ref: 'PO-4005', supplierId: 'sp5', productId: 'pr5', status: 'received', qty: 150, unitCost: 68, orderedAt: '2026-03-01T08:20:00.000Z' },
94
+ { id: 'po6', ref: 'PO-4006', supplierId: 'sp6', productId: 'pr7', status: 'ordered', qty: 120, unitCost: 30, orderedAt: '2026-03-12T13:10:00.000Z' },
95
+ ],
96
+ }
97
+
98
+ // Product grid formatting: category status pills, a LOW STOCK red-bold threshold
99
+ // (stock under 10 units needs reordering now), and a green highlight on deep
100
+ // promotional discounts - data-driven color, not just status pills.
101
+ const productFormats: FormatRule[] = [
102
+ ...statusPills(products, 'category'),
103
+ { field: 'stock', op: 'lt', value: 10, color: '#dc2626', bold: true },
104
+ { field: 'discount', op: 'gte', value: 15, color: '#16a34a', bold: true },
105
+ ]
106
+
107
+ export const inventory: SampleApp = {
108
+ id: 'inventory',
109
+ name: 'Inventory',
110
+ description: 'Products, suppliers and purchase orders - stock and purchasing dashboards (target KPIs, an order-trend sparkline, a reorder gauge, a category pie, a supplier x status pivot, tabbed breakdowns), a low-stock red grid plus a status-pill order grid with row actions, suppliers master/detail, and rich edit forms (country, phone, supplier rating, SKU mask, tag chips, discount slider, order datetime).',
111
+ emoji: '\u{1F4E6}',
112
+ accent: '#f59e0b',
113
+ build: () => {
114
+ const supplierRows = pad(suppliers, seed.suppliers, 24)
115
+ const productRows = pad(products, seed.products, 60)
116
+ const poRows = pad(purchaseOrders, seed.purchaseOrders, 90, { supplierId: ids(supplierRows), productId: ids(productRows) })
117
+ return project({
118
+ title: 'Warehouse',
119
+ brand: 'Warehouse',
120
+ accent: '#f59e0b',
121
+ preset: 'excel',
122
+ footer: '',
123
+ entities: [suppliers, products, purchaseOrders],
124
+ seed: { suppliers: supplierRows, products: productRows, purchaseOrders: poRows },
125
+ screens: [
126
+ // Stock dashboard: KPI cards (units-in-stock card carries a 5,000-unit
127
+ // target), a stock-level gauge, category breakdowns (bar + pie), a tabbed
128
+ // view, and a status-pill product grid where LOW STOCK rows turn red-bold.
129
+ dashScreen(products, { id: 'overview', title: 'Stock', order: 0 }, [
130
+ { kpi: 'Products', reduce: 'count', span: 1 },
131
+ { kpi: 'Units in stock', measure: 'stock', reduce: 'sum', target: 5000, span: 1 },
132
+ { kpi: 'Avg price', measure: 'price', reduce: 'avg', format: 'currency', span: 1 },
133
+ { gauge: 'Avg stock on hand', measure: 'stock', reduce: 'avg', min: 0, max: 500, span: 1 },
134
+ { chart: 'category', measure: 'stock', reduce: 'sum', type: 'bar', span: 2 },
135
+ { chart: 'category', reduce: 'count', type: 'pie', span: 1 },
136
+ { tabs: [
137
+ { label: 'Stock by category', tiles: [{ chart: 'category', measure: 'stock', reduce: 'sum', type: 'bar' }] },
138
+ { label: 'Avg price by category', tiles: [{ chart: 'category', measure: 'price', reduce: 'avg', type: 'bar' }] },
139
+ ], span: 3 },
140
+ { grid: true, format: productFormats, summaries: true, rowActions: [{ kind: 'edit' }], span: 3 },
141
+ ]),
142
+ // Purchasing dashboard: order-volume + cost KPIs (units-ordered card trends
143
+ // over the order date as a sparkline), an average-unit-cost gauge, status
144
+ // breakdowns, an order-quantity-over-time area trend, a supplier x status
145
+ // pivot, a tabbed view, and a status-pill purchase-order grid.
146
+ dashScreen(purchaseOrders, { id: 'purchasing', title: 'Purchasing', order: 1 }, [
147
+ { kpi: 'Purchase orders', reduce: 'count', span: 1 },
148
+ { kpi: 'Units ordered', measure: 'qty', reduce: 'sum', trendField: 'orderedAt', trendReduce: 'sum', span: 1 },
149
+ { kpi: 'Avg unit cost', measure: 'unitCost', reduce: 'avg', format: 'currency', span: 1 },
150
+ { gauge: 'Avg unit cost', measure: 'unitCost', reduce: 'avg', min: 0, max: 400, unit: '$', span: 1 },
151
+ { chart: 'status', measure: 'qty', reduce: 'sum', type: 'bar', span: 2 },
152
+ { chart: 'status', reduce: 'count', type: 'pie', span: 1 },
153
+ { chart: 'orderedAt', measure: 'qty', reduce: 'sum', type: 'area', span: 3 },
154
+ { pivot: { rows: ['supplierId'], cols: ['status'], measure: 'qty', aggregate: 'sum' }, span: 3 },
155
+ { tabs: [
156
+ { label: 'Qty by status', tiles: [{ chart: 'status', measure: 'qty', reduce: 'sum', type: 'bar' }] },
157
+ { label: 'Orders by status', tiles: [{ chart: 'status', reduce: 'count', type: 'bar' }] },
158
+ ], span: 3 },
159
+ { grid: true, format: statusPills(purchaseOrders, 'status'), summaries: true, rowActions: [{ kind: 'edit' }], span: 3 },
160
+ ]),
161
+ // Product detail: a full record page - header (name + SKU + category pill),
162
+ // stock / price metric tiles, an Overview of pricing and reorder fields, and a
163
+ // Purchase orders timeline of the orders placed for the product.
164
+ detailScreen(products, { id: 'product-detail', title: 'Product detail', order: 2 }, {
165
+ titleField: 'name', subtitleField: 'sku', statusField: 'category',
166
+ metricFields: ['stock', 'price'],
167
+ sections: [
168
+ { label: 'Pricing', fields: ['discount', 'tags'] },
169
+ { label: 'Stock', fields: ['reorderLevel', 'active'] },
170
+ ],
171
+ related: [{ entity: 'purchaseOrders', foreignKey: 'productId', label: 'Purchase orders', titleField: 'ref', subtitleField: 'qty', dateField: 'orderedAt', statusField: 'status' }],
172
+ }),
173
+ screen(suppliers, 'master-detail', { id: 'suppliers', title: 'Suppliers', order: 3, child: purchaseOrders, foreignKey: 'supplierId' }),
174
+ formScreen(products, { id: 'products', title: 'Products', order: 4 }, undefined, { format: productFormats, summaries: true, rowActions: [{ kind: 'edit' }], rowLink: { screen: 'product-detail', sourceField: 'id', targetField: 'id' } }, ['category', 'active']),
175
+ formScreen(purchaseOrders, { id: 'purchaseOrders', title: 'Purchase orders', order: 5 }, undefined, { format: statusPills(purchaseOrders, 'status'), summaries: true, rowActions: [{ kind: 'edit' }] }, ['status', 'supplierId']),
176
+ // Purchasing board: purchase orders as draggable Kanban lanes by status
177
+ // (Draft -> Ordered -> Received), card = ref + order total.
178
+ boardScreen(purchaseOrders, { id: 'board', title: 'Orders board', order: 6 }, { groupBy: 'status', titleField: 'ref', badgeField: 'qty', subtitleField: 'supplierId', filter: ['status', 'supplierId'] }),
179
+ ],
180
+ })
181
+ },
182
+ }
@@ -0,0 +1,162 @@
1
+ import type { EntitySchema } from '../../schema.js'
2
+ import type { FormatRule } from '../project.js'
3
+ import { screen, formScreen, boardScreen, detailScreen, project, dashScreen, statusPills, pad, ids, type SampleApp } from './shared.js'
4
+
5
+ const clients: EntitySchema = {
6
+ name: 'clients',
7
+ label: 'Client',
8
+ idField: 'id',
9
+ fields: [
10
+ { field: 'id', type: 'text', primaryKey: true, readonly: true },
11
+ { field: 'name', type: 'text', required: true, minLength: 2 },
12
+ { field: 'email', type: 'text', format: 'email', required: true, input: { help: 'Billing contact email' } },
13
+ { field: 'phone', type: 'text', input: { editorType: 'phone', help: 'Primary contact number' } },
14
+ { field: 'company', type: 'text', label: 'Company' },
15
+ { field: 'country', type: 'text', label: 'Country', input: { editorType: 'country', help: 'Billing country' } },
16
+ { field: 'website', type: 'text', format: 'url', input: { placeholder: 'https://…' } },
17
+ { field: 'taxId', type: 'text', label: 'Tax ID', input: { editorType: 'mask', mask: '##-#######', help: 'EIN / VAT number' } },
18
+ { field: 'satisfaction', type: 'number', label: 'Satisfaction', min: 1, max: 5, defaultValue: 3, input: { editorType: 'rating', help: '1-5 relationship score' } },
19
+ { field: 'segments', type: 'text', label: 'Segments', input: { editorType: 'chips', help: 'Account tags / segments' } },
20
+ { field: 'onboardedAt', type: 'datetime', label: 'Onboarded', input: { editorType: 'datetime', help: 'When the client signed on' } },
21
+ { field: 'active', type: 'boolean', label: 'Active', defaultValue: true },
22
+ ],
23
+ }
24
+
25
+ const invoices: EntitySchema = {
26
+ name: 'invoices',
27
+ label: 'Invoice',
28
+ idField: 'id',
29
+ fields: [
30
+ { field: 'id', type: 'text', primaryKey: true, readonly: true },
31
+ { field: 'number', type: 'text', label: 'Number', required: true, input: { editorType: 'mask', mask: 'INV-####-###', help: 'Invoice reference' } },
32
+ { field: 'clientId', type: 'relation', label: 'Client', relation: { entity: 'clients', foreignKey: 'clientId', labelField: 'name' } },
33
+ { field: 'status', type: 'enum', required: true, options: [
34
+ { value: 'draft', label: 'Draft', color: '#94a3b8' },
35
+ { value: 'sent', label: 'Sent', color: '#0ea5e9' },
36
+ { value: 'paid', label: 'Paid', color: '#10b981' },
37
+ { value: 'overdue', label: 'Overdue', color: '#ef4444' },
38
+ ] },
39
+ { field: 'subtotal', type: 'number', label: 'Subtotal ($)', required: true, min: 0, input: { help: 'Amount before tax' } },
40
+ { field: 'taxRate', type: 'number', label: 'Tax rate (%)', min: 0, max: 30, defaultValue: 10, input: { editorType: 'slider', help: 'Applied sales tax' } },
41
+ // Derived: subtotal grossed up by the tax rate (display-only, never stored).
42
+ { field: 'total', type: 'number', label: 'Total ($)', readonly: true, formula: 'subtotal + subtotal * taxRate / 100' },
43
+ { field: 'color', type: 'text', label: 'Label color', input: { editorType: 'color', help: 'Swatch used in reports' } },
44
+ { field: 'issueDate', type: 'date', label: 'Issue date' },
45
+ { field: 'dueDate', type: 'date', label: 'Due date' },
46
+ { field: 'notes', type: 'text', label: 'Notes', input: { span: 2, help: 'Internal remarks' } },
47
+ ],
48
+ }
49
+
50
+ // Invoice grid formatting: status pills, plus numeric thresholds - big-ticket
51
+ // invoices bold green, tiny invoices muted red - so the grid reads as a
52
+ // data-driven ledger, not just colored statuses.
53
+ const invoiceFormats: FormatRule[] = [
54
+ ...statusPills(invoices, 'status'),
55
+ { field: 'subtotal', op: 'gte', value: 10000, color: '#16a34a', bold: true },
56
+ { field: 'subtotal', op: 'lt', value: 1000, color: '#dc2626' },
57
+ ]
58
+
59
+ // Client grid formatting: satisfaction thresholds (at-risk red, delighted green).
60
+ const clientFormats: FormatRule[] = [
61
+ { field: 'satisfaction', op: 'lte', value: 2, color: '#dc2626', bold: true },
62
+ { field: 'satisfaction', op: 'gte', value: 5, color: '#16a34a', bold: true },
63
+ ]
64
+
65
+ const seed = {
66
+ clients: [
67
+ { id: 'cl1', name: 'Ada Lovelace', email: 'ada@globex.com', phone: '+1 (415) 555-0101', company: 'Globex', country: 'United States', website: 'https://globex.com', taxId: '12-3456789', satisfaction: 5, segments: ['Enterprise', 'Retainer'], onboardedAt: '2025-09-12T09:30:00.000Z', active: true },
68
+ { id: 'cl2', name: 'Alan Turing', email: 'alan@initech.co', phone: '+44 20 7946 0102', company: 'Initech', country: 'United Kingdom', website: 'https://initech.co', taxId: '98-7654321', satisfaction: 4, segments: ['SMB'], onboardedAt: '2025-11-03T14:15:00.000Z', active: true },
69
+ { id: 'cl3', name: 'Grace Hopper', email: 'grace@umbrella.de', phone: '+49 30 5550103', company: 'Umbrella', country: 'Germany', website: 'https://umbrella.de', taxId: '44-2019876', satisfaction: 5, segments: ['Enterprise', 'Priority'], onboardedAt: '2025-06-21T08:00:00.000Z', active: true },
70
+ { id: 'cl4', name: 'Linus Torvalds', email: 'linus@hooli.com', phone: '+1 (650) 555-0104', company: 'Hooli', country: 'United States', website: 'https://hooli.com', taxId: '31-5558822', satisfaction: 2, segments: ['At risk'], onboardedAt: '2025-03-17T16:45:00.000Z', active: false },
71
+ { id: 'cl5', name: 'Barbara Liskov', email: 'barbara@soylent.ca', phone: '+1 (416) 555-0105', company: 'Soylent', country: 'Canada', website: 'https://soylent.ca', taxId: '77-1002003', satisfaction: 3, segments: ['SMB', 'Trial'], onboardedAt: '2026-01-08T11:20:00.000Z', active: true },
72
+ { id: 'cl6', name: 'Katherine Johnson', email: 'kj@stark.com', phone: '+1 (212) 555-0106', company: 'Stark Industries', country: 'United States', website: 'https://stark.com', taxId: '20-4455667', satisfaction: 5, segments: ['Enterprise'], onboardedAt: '2025-08-29T13:10:00.000Z', active: true },
73
+ ],
74
+ invoices: [
75
+ { id: 'in1', number: 'INV-2026-001', clientId: 'cl1', status: 'paid', subtotal: 4800, taxRate: 8, color: '#10b981', issueDate: '2026-01-12', dueDate: '2026-02-11', notes: 'Q1 platform license' },
76
+ { id: 'in2', number: 'INV-2026-002', clientId: 'cl2', status: 'sent', subtotal: 2600, taxRate: 20, color: '#0ea5e9', issueDate: '2026-02-03', dueDate: '2026-03-05', notes: 'Data pipeline setup' },
77
+ { id: 'in3', number: 'INV-2026-003', clientId: 'cl3', status: 'overdue', subtotal: 9100, taxRate: 19, color: '#ef4444', issueDate: '2026-01-20', dueDate: '2026-02-19', notes: 'Compliance suite - reminder sent' },
78
+ { id: 'in4', number: 'INV-2026-004', clientId: 'cl4', status: 'draft', subtotal: 1500, taxRate: 0, color: '#94a3b8', issueDate: '2026-03-01', dueDate: '2026-03-31', notes: 'Pending scope sign-off' },
79
+ { id: 'in5', number: 'INV-2026-005', clientId: 'cl5', status: 'paid', subtotal: 800, taxRate: 13, color: '#10b981', issueDate: '2026-02-14', dueDate: '2026-03-16', notes: 'Onboarding fee' },
80
+ { id: 'in6', number: 'INV-2026-006', clientId: 'cl6', status: 'sent', subtotal: 13200, taxRate: 8, color: '#0ea5e9', issueDate: '2026-03-08', dueDate: '2026-04-07', notes: 'Annual analytics contract' },
81
+ { id: 'in7', number: 'INV-2026-007', clientId: 'cl1', status: 'overdue', subtotal: 3400, taxRate: 8, color: '#ef4444', issueDate: '2026-01-05', dueDate: '2026-02-04', notes: 'Add-on seats - past due' },
82
+ ],
83
+ }
84
+
85
+ export const invoicing: SampleApp = {
86
+ id: 'invoicing',
87
+ name: 'Invoicing',
88
+ description: 'Clients and invoices - billing + collections + client dashboards (revenue KPI sparkline over issue dates + a target, a revenue gauge, area trend, status pivot, tabbed breakdown), status-pill invoice grids with overdue / big-ticket conditional formatting, drill-through, row actions, master/detail, and rich edit forms.',
89
+ emoji: '\u{1F9FE}',
90
+ accent: '#0ea5e9',
91
+ build: () => {
92
+ const clientRows = pad(clients, seed.clients, 12)
93
+ const pool = ids(clientRows)
94
+ const invoiceRows = pad(invoices, seed.invoices, 30, { clientId: pool })
95
+ return project({
96
+ title: 'Acme Invoicing',
97
+ brand: 'Acme Invoicing',
98
+ accent: '#0ea5e9',
99
+ preset: 'antd',
100
+ footer: '© Acme',
101
+ entities: [clients, invoices],
102
+ seed: { clients: clientRows, invoices: invoiceRows },
103
+ screens: [
104
+ // Billing dashboard: KPI cards (a billed-revenue card with a sparkline over
105
+ // issue dates + a $60k target), a revenue gauge, a status revenue bar, a
106
+ // status pie, a revenue-over-time area trend, a tabbed breakdown, and a
107
+ // status-pill invoice grid with big-ticket / tiny-invoice thresholds.
108
+ dashScreen(invoices, { id: 'overview', title: 'Billing', order: 0 }, [
109
+ { kpi: 'Billed revenue', measure: 'subtotal', reduce: 'sum', format: 'currency', trendField: 'issueDate', trendReduce: 'sum', target: 60000, span: 1 },
110
+ { kpi: 'Invoices', reduce: 'count', span: 1 },
111
+ { kpi: 'Avg invoice', measure: 'subtotal', reduce: 'avg', format: 'currency', span: 1 },
112
+ { gauge: 'Revenue vs $80k target', measure: 'subtotal', reduce: 'sum', min: 0, max: 80000, unit: '$', span: 1 },
113
+ { chart: 'status', measure: 'subtotal', reduce: 'sum', type: 'bar', span: 2 },
114
+ { chart: 'status', reduce: 'count', type: 'pie', span: 1 },
115
+ { chart: 'issueDate', measure: 'subtotal', reduce: 'sum', type: 'area', span: 3 },
116
+ { tabs: [
117
+ { label: 'Revenue by status', tiles: [{ chart: 'status', measure: 'subtotal', reduce: 'sum', type: 'bar' }] },
118
+ { label: 'Invoices by status', tiles: [{ chart: 'status', reduce: 'count', type: 'bar' }] },
119
+ ], span: 3 },
120
+ { grid: true, format: invoiceFormats, summaries: true, rowActions: [{ kind: 'edit' }], span: 3 },
121
+ ]),
122
+ // Collections: outstanding + tax KPIs, a tax-rate gauge, a revenue-over-time
123
+ // area trend, a pivot of revenue by status (rows) x client (columns), and a
124
+ // status-pill grid with inline edit actions.
125
+ // Invoice board: invoices as cards in status columns (draft/sent/paid/overdue).
126
+ boardScreen(invoices, { id: 'board', title: 'Board', order: 1 }, { groupBy: 'status', titleField: 'number', badgeField: 'subtotal', filter: ['status', 'clientId'] }),
127
+ // Client 360: account header + satisfaction tile with a timeline of the
128
+ // client's invoices (by issue date, colored by payment status).
129
+ detailScreen(clients, { id: 'client-360', title: 'Client 360', order: 2 }, {
130
+ titleField: 'name', subtitleField: 'company', metricFields: ['satisfaction'],
131
+ related: [{ entity: 'invoices', foreignKey: 'clientId', label: 'Invoices', titleField: 'number', subtitleField: 'subtotal', dateField: 'issueDate', statusField: 'status' }],
132
+ }),
133
+ dashScreen(invoices, { id: 'collections', title: 'Collections', order: 3 }, [
134
+ { kpi: 'Outstanding', measure: 'subtotal', reduce: 'sum', format: 'currency', span: 1 },
135
+ { kpi: 'Largest invoice', measure: 'subtotal', reduce: 'max', format: 'currency', span: 1 },
136
+ { kpi: 'Avg tax rate', measure: 'taxRate', reduce: 'avg', format: 'percent', span: 1 },
137
+ { gauge: 'Avg tax rate', measure: 'taxRate', reduce: 'avg', min: 0, max: 30, unit: '%', span: 1 },
138
+ { chart: 'issueDate', measure: 'subtotal', reduce: 'sum', type: 'area', span: 3 },
139
+ { pivot: { rows: ['status'], cols: ['clientId'], measure: 'subtotal', aggregate: 'sum' }, span: 3 },
140
+ { grid: true, format: statusPills(invoices, 'status'), summaries: true, rowActions: [{ kind: 'edit' }], span: 3 },
141
+ ]),
142
+ // Clients dashboard: portfolio KPIs, a satisfaction gauge, country + segment
143
+ // breakdowns, a country x active pivot, a faceted filter, and a client grid
144
+ // (satisfaction thresholds) that drills into that client's invoices.
145
+ dashScreen(clients, { id: 'clientsDash', title: 'Clients', order: 4 }, [
146
+ { kpi: 'Clients', reduce: 'count', span: 1 },
147
+ { kpi: 'Avg satisfaction', measure: 'satisfaction', reduce: 'avg', span: 1 },
148
+ { kpi: 'Top satisfaction', measure: 'satisfaction', reduce: 'max', span: 1 },
149
+ { gauge: 'Avg satisfaction', measure: 'satisfaction', reduce: 'avg', min: 0, max: 5, span: 1 },
150
+ { chart: 'country', measure: 'satisfaction', reduce: 'avg', type: 'bar', span: 2 },
151
+ { chart: 'active', reduce: 'count', type: 'pie', span: 1 },
152
+ { pivot: { rows: ['country'], cols: ['active'], measure: 'satisfaction', aggregate: 'avg' }, span: 3 },
153
+ { filter: ['country', 'company', 'active'], span: 3 },
154
+ { grid: true, format: clientFormats, summaries: true, rowLink: { screen: 'invoices', sourceField: 'id', targetField: 'clientId' }, span: 3 },
155
+ ]),
156
+ screen(clients, 'master-detail', { id: 'clients', title: 'Clients book', order: 5, child: invoices, foreignKey: 'clientId', linkScreen: 'client-360' }),
157
+ formScreen(invoices, { id: 'invoices', title: 'Invoices', order: 6 }, undefined, { format: invoiceFormats, summaries: true, rowActions: [{ kind: 'edit' }] }, ['status', 'clientId', 'issueDate']),
158
+ formScreen(clients, { id: 'clientsForm', title: 'Client details', order: 7 }, undefined, { format: clientFormats }, ['country', 'segments', 'active']),
159
+ ],
160
+ })
161
+ },
162
+ }