@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.
Files changed (143) hide show
  1. package/.turbo/turbo-build.log +39 -27
  2. package/AGENTS.md +50 -27
  3. package/CHANGELOG.md +36 -0
  4. package/README.md +65 -144
  5. package/dist/billing/billing.event.js +1 -1
  6. package/dist/billing/index.d.ts +6 -6
  7. package/dist/billing/index.js +1 -1
  8. package/dist/browser/billing/billing.event.js +1 -1
  9. package/dist/browser/billing/index.js +1 -1
  10. package/dist/browser/index.js +1147 -869
  11. package/dist/browser/project/index.js +209 -209
  12. package/dist/browser/project/project.event.js +1 -1
  13. package/dist/browser/saas-boilerplate.feature.js +208 -0
  14. package/dist/browser/ui/SaasDashboard.js +356 -105
  15. package/dist/browser/ui/SaasDashboard.visualizations.js +249 -0
  16. package/dist/browser/ui/SaasProjectList.js +7 -7
  17. package/dist/browser/ui/SaasSettingsPanel.js +12 -12
  18. package/dist/browser/ui/hooks/index.js +2 -2
  19. package/dist/browser/ui/hooks/useProjectList.js +1 -1
  20. package/dist/browser/ui/hooks/useProjectMutations.js +1 -1
  21. package/dist/browser/ui/index.js +790 -521
  22. package/dist/browser/ui/modals/CreateProjectModal.js +10 -10
  23. package/dist/browser/ui/modals/ProjectActionsModal.js +13 -13
  24. package/dist/browser/ui/modals/index.js +23 -23
  25. package/dist/browser/ui/renderers/index.js +341 -115
  26. package/dist/browser/ui/renderers/project-list.markdown.js +229 -3
  27. package/dist/browser/ui/renderers/project-list.renderer.js +7 -7
  28. package/dist/browser/visualizations/catalog.js +155 -0
  29. package/dist/browser/visualizations/index.js +217 -0
  30. package/dist/browser/visualizations/selectors.js +210 -0
  31. package/dist/handlers/index.d.ts +2 -2
  32. package/dist/index.d.ts +5 -4
  33. package/dist/index.js +1147 -869
  34. package/dist/node/billing/billing.event.js +1 -1
  35. package/dist/node/billing/index.js +1 -1
  36. package/dist/node/index.js +1147 -869
  37. package/dist/node/project/index.js +209 -209
  38. package/dist/node/project/project.event.js +1 -1
  39. package/dist/node/saas-boilerplate.feature.js +208 -0
  40. package/dist/node/ui/SaasDashboard.js +356 -105
  41. package/dist/node/ui/SaasDashboard.visualizations.js +249 -0
  42. package/dist/node/ui/SaasProjectList.js +7 -7
  43. package/dist/node/ui/SaasSettingsPanel.js +12 -12
  44. package/dist/node/ui/hooks/index.js +2 -2
  45. package/dist/node/ui/hooks/useProjectList.js +1 -1
  46. package/dist/node/ui/hooks/useProjectMutations.js +1 -1
  47. package/dist/node/ui/index.js +790 -521
  48. package/dist/node/ui/modals/CreateProjectModal.js +10 -10
  49. package/dist/node/ui/modals/ProjectActionsModal.js +13 -13
  50. package/dist/node/ui/modals/index.js +23 -23
  51. package/dist/node/ui/renderers/index.js +341 -115
  52. package/dist/node/ui/renderers/project-list.markdown.js +229 -3
  53. package/dist/node/ui/renderers/project-list.renderer.js +7 -7
  54. package/dist/node/visualizations/catalog.js +155 -0
  55. package/dist/node/visualizations/index.js +217 -0
  56. package/dist/node/visualizations/selectors.js +210 -0
  57. package/dist/presentations/index.d.ts +1 -1
  58. package/dist/project/index.d.ts +7 -7
  59. package/dist/project/index.js +209 -209
  60. package/dist/project/project.event.js +1 -1
  61. package/dist/saas-boilerplate.feature.js +208 -0
  62. package/dist/settings/index.d.ts +1 -1
  63. package/dist/ui/SaasDashboard.js +356 -105
  64. package/dist/ui/SaasDashboard.visualizations.d.ts +5 -0
  65. package/dist/ui/SaasDashboard.visualizations.js +250 -0
  66. package/dist/ui/SaasProjectList.js +7 -7
  67. package/dist/ui/SaasSettingsPanel.js +12 -12
  68. package/dist/ui/hooks/index.d.ts +2 -2
  69. package/dist/ui/hooks/index.js +2 -2
  70. package/dist/ui/hooks/useProjectList.d.ts +5 -0
  71. package/dist/ui/hooks/useProjectList.js +1 -1
  72. package/dist/ui/hooks/useProjectMutations.d.ts +8 -0
  73. package/dist/ui/hooks/useProjectMutations.js +1 -1
  74. package/dist/ui/index.d.ts +4 -4
  75. package/dist/ui/index.js +790 -521
  76. package/dist/ui/modals/CreateProjectModal.js +10 -10
  77. package/dist/ui/modals/ProjectActionsModal.js +13 -13
  78. package/dist/ui/modals/index.js +23 -23
  79. package/dist/ui/renderers/index.d.ts +1 -1
  80. package/dist/ui/renderers/index.js +341 -115
  81. package/dist/ui/renderers/project-list.markdown.js +229 -3
  82. package/dist/ui/renderers/project-list.renderer.d.ts +1 -1
  83. package/dist/ui/renderers/project-list.renderer.js +7 -7
  84. package/dist/visualizations/catalog.d.ts +11 -0
  85. package/dist/visualizations/catalog.js +156 -0
  86. package/dist/visualizations/index.d.ts +2 -0
  87. package/dist/visualizations/index.js +218 -0
  88. package/dist/visualizations/selectors.d.ts +8 -0
  89. package/dist/visualizations/selectors.js +211 -0
  90. package/dist/visualizations/selectors.test.d.ts +1 -0
  91. package/package.json +70 -14
  92. package/src/billing/billing.entity.ts +132 -132
  93. package/src/billing/billing.enum.ts +9 -9
  94. package/src/billing/billing.event.ts +71 -71
  95. package/src/billing/billing.handler.ts +87 -87
  96. package/src/billing/billing.operations.ts +158 -158
  97. package/src/billing/billing.presentation.ts +45 -45
  98. package/src/billing/billing.schema.ts +76 -76
  99. package/src/billing/index.ts +43 -48
  100. package/src/dashboard/dashboard.presentation.ts +45 -45
  101. package/src/dashboard/index.ts +2 -2
  102. package/src/docs/saas-boilerplate.docblock.ts +43 -43
  103. package/src/example.ts +32 -32
  104. package/src/handlers/index.ts +9 -9
  105. package/src/handlers/saas.handlers.ts +250 -249
  106. package/src/index.ts +41 -41
  107. package/src/presentations/index.ts +18 -20
  108. package/src/project/index.ts +45 -50
  109. package/src/project/project.entity.ts +68 -68
  110. package/src/project/project.enum.ts +8 -8
  111. package/src/project/project.event.ts +79 -79
  112. package/src/project/project.handler.ts +103 -103
  113. package/src/project/project.operations.ts +236 -236
  114. package/src/project/project.presentation.ts +46 -46
  115. package/src/project/project.schema.ts +90 -90
  116. package/src/saas-boilerplate.feature.ts +103 -100
  117. package/src/seeders/index.ts +20 -20
  118. package/src/settings/index.ts +2 -3
  119. package/src/settings/settings.entity.ts +65 -65
  120. package/src/settings/settings.enum.ts +4 -4
  121. package/src/shared/mock-data.ts +92 -92
  122. package/src/shared/overlay-types.ts +23 -23
  123. package/src/tests/operations.test-spec.ts +96 -96
  124. package/src/ui/SaasDashboard.tsx +278 -270
  125. package/src/ui/SaasDashboard.visualizations.tsx +41 -0
  126. package/src/ui/SaasProjectList.tsx +90 -90
  127. package/src/ui/SaasSettingsPanel.tsx +84 -84
  128. package/src/ui/hooks/index.ts +3 -3
  129. package/src/ui/hooks/useProjectList.ts +69 -68
  130. package/src/ui/hooks/useProjectMutations.ts +144 -143
  131. package/src/ui/index.ts +8 -12
  132. package/src/ui/modals/CreateProjectModal.tsx +154 -154
  133. package/src/ui/modals/ProjectActionsModal.tsx +321 -321
  134. package/src/ui/overlays/demo-overlays.ts +49 -49
  135. package/src/ui/renderers/index.ts +5 -4
  136. package/src/ui/renderers/project-list.markdown.ts +229 -205
  137. package/src/ui/renderers/project-list.renderer.tsx +14 -13
  138. package/src/visualizations/catalog.ts +153 -0
  139. package/src/visualizations/index.ts +2 -0
  140. package/src/visualizations/selectors.test.ts +25 -0
  141. package/src/visualizations/selectors.ts +85 -0
  142. package/tsconfig.json +7 -8
  143. package/tsdown.config.js +7 -3
@@ -1,108 +1,108 @@
1
- import { ScalarTypeEnum, defineSchemaModel } from '@contractspec/lib.schema';
2
1
  import { defineEvent } from '@contractspec/lib.contracts-spec';
2
+ import { defineSchemaModel, ScalarTypeEnum } from '@contractspec/lib.schema';
3
3
 
4
4
  /**
5
5
  * Payload when feature usage is recorded.
6
6
  */
7
7
  const UsageRecordedPayload = defineSchemaModel({
8
- name: 'UsageRecordedPayload',
9
- description: 'Payload when feature usage is recorded',
10
- fields: {
11
- organizationId: {
12
- type: ScalarTypeEnum.String_unsecure(),
13
- isOptional: false,
14
- },
15
- feature: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
16
- quantity: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },
17
- billingPeriod: {
18
- type: ScalarTypeEnum.String_unsecure(),
19
- isOptional: false,
20
- },
21
- recordedAt: { type: ScalarTypeEnum.DateTime(), isOptional: false },
22
- },
8
+ name: 'UsageRecordedPayload',
9
+ description: 'Payload when feature usage is recorded',
10
+ fields: {
11
+ organizationId: {
12
+ type: ScalarTypeEnum.String_unsecure(),
13
+ isOptional: false,
14
+ },
15
+ feature: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
16
+ quantity: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },
17
+ billingPeriod: {
18
+ type: ScalarTypeEnum.String_unsecure(),
19
+ isOptional: false,
20
+ },
21
+ recordedAt: { type: ScalarTypeEnum.DateTime(), isOptional: false },
22
+ },
23
23
  });
24
24
 
25
25
  /**
26
26
  * Payload when usage limit is reached.
27
27
  */
28
28
  const UsageLimitReachedPayload = defineSchemaModel({
29
- name: 'UsageLimitReachedPayload',
30
- description: 'Payload when usage limit is reached',
31
- fields: {
32
- organizationId: {
33
- type: ScalarTypeEnum.String_unsecure(),
34
- isOptional: false,
35
- },
36
- feature: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
37
- limit: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },
38
- currentUsage: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },
39
- reachedAt: { type: ScalarTypeEnum.DateTime(), isOptional: false },
40
- },
29
+ name: 'UsageLimitReachedPayload',
30
+ description: 'Payload when usage limit is reached',
31
+ fields: {
32
+ organizationId: {
33
+ type: ScalarTypeEnum.String_unsecure(),
34
+ isOptional: false,
35
+ },
36
+ feature: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
37
+ limit: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },
38
+ currentUsage: { type: ScalarTypeEnum.Int_unsecure(), isOptional: false },
39
+ reachedAt: { type: ScalarTypeEnum.DateTime(), isOptional: false },
40
+ },
41
41
  });
42
42
 
43
43
  /**
44
44
  * Payload when subscription status changes.
45
45
  */
46
46
  const SubscriptionChangedPayload = defineSchemaModel({
47
- name: 'SubscriptionChangedPayload',
48
- description: 'Payload when subscription status changes',
49
- fields: {
50
- organizationId: {
51
- type: ScalarTypeEnum.String_unsecure(),
52
- isOptional: false,
53
- },
54
- previousPlan: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
55
- newPlan: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
56
- previousStatus: {
57
- type: ScalarTypeEnum.String_unsecure(),
58
- isOptional: true,
59
- },
60
- newStatus: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
61
- changedAt: { type: ScalarTypeEnum.DateTime(), isOptional: false },
62
- },
47
+ name: 'SubscriptionChangedPayload',
48
+ description: 'Payload when subscription status changes',
49
+ fields: {
50
+ organizationId: {
51
+ type: ScalarTypeEnum.String_unsecure(),
52
+ isOptional: false,
53
+ },
54
+ previousPlan: { type: ScalarTypeEnum.String_unsecure(), isOptional: true },
55
+ newPlan: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
56
+ previousStatus: {
57
+ type: ScalarTypeEnum.String_unsecure(),
58
+ isOptional: true,
59
+ },
60
+ newStatus: { type: ScalarTypeEnum.String_unsecure(), isOptional: false },
61
+ changedAt: { type: ScalarTypeEnum.DateTime(), isOptional: false },
62
+ },
63
63
  });
64
64
 
65
65
  /**
66
66
  * Event: Feature usage has been recorded.
67
67
  */
68
68
  export const UsageRecordedEvent = defineEvent({
69
- meta: {
70
- key: 'billing.usage.recorded',
71
- version: '1.0.0',
72
- description: 'Feature usage has been recorded.',
73
- stability: 'stable',
74
- owners: ['@saas-team'],
75
- tags: ['billing', 'usage', 'recorded'],
76
- },
77
- payload: UsageRecordedPayload,
69
+ meta: {
70
+ key: 'billing.usage.recorded',
71
+ version: '1.0.0',
72
+ description: 'Feature usage has been recorded.',
73
+ stability: 'stable',
74
+ owners: ['@saas-team'],
75
+ tags: ['billing', 'usage', 'recorded'],
76
+ },
77
+ payload: UsageRecordedPayload,
78
78
  });
79
79
 
80
80
  /**
81
81
  * Event: Usage limit has been reached for a feature.
82
82
  */
83
83
  export const UsageLimitReachedEvent = defineEvent({
84
- meta: {
85
- key: 'billing.limit.reached',
86
- version: '1.0.0',
87
- description: 'Usage limit has been reached for a feature.',
88
- stability: 'stable',
89
- owners: ['@saas-team'],
90
- tags: ['billing', 'limit', 'reached'],
91
- },
92
- payload: UsageLimitReachedPayload,
84
+ meta: {
85
+ key: 'billing.limit.reached',
86
+ version: '1.0.0',
87
+ description: 'Usage limit has been reached for a feature.',
88
+ stability: 'stable',
89
+ owners: ['@saas-team'],
90
+ tags: ['billing', 'limit', 'reached'],
91
+ },
92
+ payload: UsageLimitReachedPayload,
93
93
  });
94
94
 
95
95
  /**
96
96
  * Event: Subscription status has changed.
97
97
  */
98
98
  export const SubscriptionChangedEvent = defineEvent({
99
- meta: {
100
- key: 'billing.subscription.changed',
101
- version: '1.0.0',
102
- description: 'Subscription status has changed.',
103
- stability: 'stable',
104
- owners: ['@saas-team'],
105
- tags: ['billing', 'subscription', 'changed'],
106
- },
107
- payload: SubscriptionChangedPayload,
99
+ meta: {
100
+ key: 'billing.subscription.changed',
101
+ version: '1.0.0',
102
+ description: 'Subscription status has changed.',
103
+ stability: 'stable',
104
+ owners: ['@saas-team'],
105
+ tags: ['billing', 'subscription', 'changed'],
106
+ },
107
+ payload: SubscriptionChangedPayload,
108
108
  });
@@ -5,133 +5,133 @@ import { MOCK_SUBSCRIPTION, MOCK_USAGE_SUMMARY } from '../shared/mock-data';
5
5
 
6
6
  // Types inferred from contract schemas
7
7
  export interface Subscription {
8
- id: string;
9
- organizationId: string;
10
- planId: string;
11
- planName: string;
12
- status: 'ACTIVE' | 'TRIALING' | 'PAST_DUE' | 'CANCELED' | 'UNPAID';
13
- currentPeriodStart: Date;
14
- currentPeriodEnd: Date;
15
- limits: {
16
- projects: number;
17
- users: number;
18
- storage: number;
19
- apiCalls: number;
20
- };
21
- usage: {
22
- projects: number;
23
- users: number;
24
- storage: number;
25
- apiCalls: number;
26
- };
8
+ id: string;
9
+ organizationId: string;
10
+ planId: string;
11
+ planName: string;
12
+ status: 'ACTIVE' | 'TRIALING' | 'PAST_DUE' | 'CANCELED' | 'UNPAID';
13
+ currentPeriodStart: Date;
14
+ currentPeriodEnd: Date;
15
+ limits: {
16
+ projects: number;
17
+ users: number;
18
+ storage: number;
19
+ apiCalls: number;
20
+ };
21
+ usage: {
22
+ projects: number;
23
+ users: number;
24
+ storage: number;
25
+ apiCalls: number;
26
+ };
27
27
  }
28
28
 
29
29
  export interface UsageSummary {
30
- organizationId: string;
31
- period: string;
32
- apiCalls: {
33
- total: number;
34
- limit: number;
35
- percentUsed: number;
36
- };
37
- storage: {
38
- totalGb: number;
39
- limitGb: number;
40
- percentUsed: number;
41
- };
42
- activeProjects: number;
43
- activeUsers: number;
44
- breakdown: {
45
- date: string;
46
- apiCalls: number;
47
- storageGb: number;
48
- }[];
30
+ organizationId: string;
31
+ period: string;
32
+ apiCalls: {
33
+ total: number;
34
+ limit: number;
35
+ percentUsed: number;
36
+ };
37
+ storage: {
38
+ totalGb: number;
39
+ limitGb: number;
40
+ percentUsed: number;
41
+ };
42
+ activeProjects: number;
43
+ activeUsers: number;
44
+ breakdown: {
45
+ date: string;
46
+ apiCalls: number;
47
+ storageGb: number;
48
+ }[];
49
49
  }
50
50
 
51
51
  export interface RecordUsageInput {
52
- metric: string;
53
- quantity: number;
54
- timestamp?: Date;
55
- metadata?: Record<string, unknown>;
52
+ metric: string;
53
+ quantity: number;
54
+ timestamp?: Date;
55
+ metadata?: Record<string, unknown>;
56
56
  }
57
57
 
58
58
  export interface CheckFeatureAccessInput {
59
- feature: string;
59
+ feature: string;
60
60
  }
61
61
 
62
62
  export interface CheckFeatureAccessOutput {
63
- allowed: boolean;
64
- reason?:
65
- | 'PLAN_LIMIT'
66
- | 'FEATURE_NOT_INCLUDED'
67
- | 'QUOTA_EXCEEDED'
68
- | 'SUBSCRIPTION_INACTIVE';
69
- currentUsage?: number;
70
- limit?: number;
63
+ allowed: boolean;
64
+ reason?:
65
+ | 'PLAN_LIMIT'
66
+ | 'FEATURE_NOT_INCLUDED'
67
+ | 'QUOTA_EXCEEDED'
68
+ | 'SUBSCRIPTION_INACTIVE';
69
+ currentUsage?: number;
70
+ limit?: number;
71
71
  }
72
72
 
73
73
  /**
74
74
  * Mock handler for GetSubscriptionContract.
75
75
  */
76
76
  export async function mockGetSubscriptionHandler(): Promise<Subscription> {
77
- return MOCK_SUBSCRIPTION;
77
+ return MOCK_SUBSCRIPTION;
78
78
  }
79
79
 
80
80
  /**
81
81
  * Mock handler for GetUsageSummaryContract.
82
82
  */
83
83
  export async function mockGetUsageSummaryHandler(input: {
84
- period?: string;
84
+ period?: string;
85
85
  }): Promise<UsageSummary> {
86
- return {
87
- ...MOCK_USAGE_SUMMARY,
88
- period: input.period ?? 'current_month',
89
- };
86
+ return {
87
+ ...MOCK_USAGE_SUMMARY,
88
+ period: input.period ?? 'current_month',
89
+ };
90
90
  }
91
91
 
92
92
  /**
93
93
  * Mock handler for RecordUsageContract.
94
94
  */
95
95
  export async function mockRecordUsageHandler(
96
- input: RecordUsageInput
96
+ input: RecordUsageInput
97
97
  ): Promise<{ recorded: boolean; newTotal: number }> {
98
- const currentUsage = MOCK_USAGE_SUMMARY.apiCalls.total;
99
- const newTotal = currentUsage + input.quantity;
98
+ const currentUsage = MOCK_USAGE_SUMMARY.apiCalls.total;
99
+ const newTotal = currentUsage + input.quantity;
100
100
 
101
- return {
102
- recorded: true,
103
- newTotal,
104
- };
101
+ return {
102
+ recorded: true,
103
+ newTotal,
104
+ };
105
105
  }
106
106
 
107
107
  /**
108
108
  * Mock handler for CheckFeatureAccessContract.
109
109
  */
110
110
  export async function mockCheckFeatureAccessHandler(
111
- input: CheckFeatureAccessInput
111
+ input: CheckFeatureAccessInput
112
112
  ): Promise<CheckFeatureAccessOutput> {
113
- const { feature } = input;
113
+ const { feature } = input;
114
114
 
115
- const featureMap: Record<string, CheckFeatureAccessOutput> = {
116
- custom_domains: {
117
- allowed: true,
118
- },
119
- api_access: {
120
- allowed: true,
121
- currentUsage: MOCK_USAGE_SUMMARY.apiCalls.total,
122
- limit: MOCK_USAGE_SUMMARY.apiCalls.limit,
123
- },
124
- advanced_analytics: {
125
- allowed: false,
126
- reason: 'FEATURE_NOT_INCLUDED',
127
- },
128
- unlimited_projects: {
129
- allowed: false,
130
- reason: 'PLAN_LIMIT',
131
- currentUsage: MOCK_SUBSCRIPTION.usage.projects,
132
- limit: MOCK_SUBSCRIPTION.limits.projects,
133
- },
134
- };
115
+ const featureMap: Record<string, CheckFeatureAccessOutput> = {
116
+ custom_domains: {
117
+ allowed: true,
118
+ },
119
+ api_access: {
120
+ allowed: true,
121
+ currentUsage: MOCK_USAGE_SUMMARY.apiCalls.total,
122
+ limit: MOCK_USAGE_SUMMARY.apiCalls.limit,
123
+ },
124
+ advanced_analytics: {
125
+ allowed: false,
126
+ reason: 'FEATURE_NOT_INCLUDED',
127
+ },
128
+ unlimited_projects: {
129
+ allowed: false,
130
+ reason: 'PLAN_LIMIT',
131
+ currentUsage: MOCK_SUBSCRIPTION.usage.projects,
132
+ limit: MOCK_SUBSCRIPTION.limits.projects,
133
+ },
134
+ };
135
135
 
136
- return featureMap[feature] ?? { allowed: true };
136
+ return featureMap[feature] ?? { allowed: true };
137
137
  }