@contractspec/example.saas-boilerplate 1.46.1 → 1.48.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 (135) hide show
  1. package/.turbo/turbo-build$colon$bundle.log +183 -108
  2. package/.turbo/turbo-build.log +182 -107
  3. package/CHANGELOG.md +64 -0
  4. package/README.md +0 -1
  5. package/dist/billing/billing.event.d.ts +4 -4
  6. package/dist/billing/billing.event.js +1 -1
  7. package/dist/billing/billing.operations.d.ts +5 -5
  8. package/dist/billing/billing.presentation.d.ts +3 -4
  9. package/dist/billing/billing.presentation.d.ts.map +1 -1
  10. package/dist/billing/billing.presentation.js +5 -5
  11. package/dist/billing/billing.presentation.js.map +1 -1
  12. package/dist/dashboard/dashboard.presentation.d.ts +3 -4
  13. package/dist/dashboard/dashboard.presentation.d.ts.map +1 -1
  14. package/dist/dashboard/dashboard.presentation.js +5 -5
  15. package/dist/dashboard/dashboard.presentation.js.map +1 -1
  16. package/dist/example.d.ts +2 -2
  17. package/dist/example.d.ts.map +1 -1
  18. package/dist/example.js +4 -2
  19. package/dist/example.js.map +1 -1
  20. package/dist/handlers/index.d.ts +2 -1
  21. package/dist/handlers/index.js +2 -1
  22. package/dist/handlers/saas.handlers.d.ts +68 -0
  23. package/dist/handlers/saas.handlers.d.ts.map +1 -0
  24. package/dist/handlers/saas.handlers.js +148 -0
  25. package/dist/handlers/saas.handlers.js.map +1 -0
  26. package/dist/index.d.ts +13 -1
  27. package/dist/index.d.ts.map +1 -1
  28. package/dist/index.js +13 -1
  29. package/dist/index.js.map +1 -1
  30. package/dist/project/project.enum.d.ts +3 -3
  31. package/dist/project/project.event.d.ts +22 -22
  32. package/dist/project/project.event.d.ts.map +1 -1
  33. package/dist/project/project.event.js +1 -1
  34. package/dist/project/project.operations.d.ts +103 -103
  35. package/dist/project/project.presentation.d.ts +3 -4
  36. package/dist/project/project.presentation.d.ts.map +1 -1
  37. package/dist/project/project.presentation.js +5 -5
  38. package/dist/project/project.presentation.js.map +1 -1
  39. package/dist/project/project.schema.d.ts +54 -54
  40. package/dist/saas-boilerplate.feature.d.ts +2 -2
  41. package/dist/saas-boilerplate.feature.d.ts.map +1 -1
  42. package/dist/saas-boilerplate.feature.js +9 -2
  43. package/dist/saas-boilerplate.feature.js.map +1 -1
  44. package/dist/seeders/index.d.ts +10 -0
  45. package/dist/seeders/index.d.ts.map +1 -0
  46. package/dist/seeders/index.js +19 -0
  47. package/dist/seeders/index.js.map +1 -0
  48. package/dist/settings/settings.entity.d.ts +24 -24
  49. package/dist/settings/settings.enum.d.ts +2 -2
  50. package/dist/shared/overlay-types.d.ts +34 -0
  51. package/dist/shared/overlay-types.d.ts.map +1 -0
  52. package/dist/shared/overlay-types.js +0 -0
  53. package/dist/tests/operations.test-spec.d.ts +10 -0
  54. package/dist/tests/operations.test-spec.d.ts.map +1 -0
  55. package/dist/tests/operations.test-spec.js +123 -0
  56. package/dist/tests/operations.test-spec.js.map +1 -0
  57. package/dist/ui/SaasDashboard.d.ts +7 -0
  58. package/dist/ui/SaasDashboard.d.ts.map +1 -0
  59. package/dist/ui/SaasDashboard.js +298 -0
  60. package/dist/ui/SaasDashboard.js.map +1 -0
  61. package/dist/ui/SaasProjectList.d.ts +14 -0
  62. package/dist/ui/SaasProjectList.d.ts.map +1 -0
  63. package/dist/ui/SaasProjectList.js +76 -0
  64. package/dist/ui/SaasProjectList.js.map +1 -0
  65. package/dist/ui/SaasSettingsPanel.d.ts +7 -0
  66. package/dist/ui/SaasSettingsPanel.d.ts.map +1 -0
  67. package/dist/ui/SaasSettingsPanel.js +138 -0
  68. package/dist/ui/SaasSettingsPanel.js.map +1 -0
  69. package/dist/ui/hooks/index.d.ts +3 -0
  70. package/dist/ui/hooks/index.js +6 -0
  71. package/dist/ui/hooks/useProjectList.d.ts +34 -0
  72. package/dist/ui/hooks/useProjectList.d.ts.map +1 -0
  73. package/dist/ui/hooks/useProjectList.js +75 -0
  74. package/dist/ui/hooks/useProjectList.js.map +1 -0
  75. package/dist/ui/hooks/useProjectMutations.d.ts +28 -0
  76. package/dist/ui/hooks/useProjectMutations.d.ts.map +1 -0
  77. package/dist/ui/hooks/useProjectMutations.js +146 -0
  78. package/dist/ui/hooks/useProjectMutations.js.map +1 -0
  79. package/dist/ui/index.d.ts +14 -0
  80. package/dist/ui/index.js +15 -0
  81. package/dist/ui/modals/CreateProjectModal.d.ts +23 -0
  82. package/dist/ui/modals/CreateProjectModal.d.ts.map +1 -0
  83. package/dist/ui/modals/CreateProjectModal.js +139 -0
  84. package/dist/ui/modals/CreateProjectModal.js.map +1 -0
  85. package/dist/ui/modals/ProjectActionsModal.d.ts +38 -0
  86. package/dist/ui/modals/ProjectActionsModal.d.ts.map +1 -0
  87. package/dist/ui/modals/ProjectActionsModal.js +292 -0
  88. package/dist/ui/modals/ProjectActionsModal.js.map +1 -0
  89. package/dist/ui/modals/index.d.ts +3 -0
  90. package/dist/ui/modals/index.js +4 -0
  91. package/dist/ui/overlays/demo-overlays.d.ts +19 -0
  92. package/dist/ui/overlays/demo-overlays.d.ts.map +1 -0
  93. package/dist/ui/overlays/demo-overlays.js +70 -0
  94. package/dist/ui/overlays/demo-overlays.js.map +1 -0
  95. package/dist/ui/overlays/index.d.ts +2 -0
  96. package/dist/ui/overlays/index.js +3 -0
  97. package/dist/ui/renderers/index.d.ts +3 -0
  98. package/dist/ui/renderers/index.js +4 -0
  99. package/dist/ui/renderers/project-list.markdown.d.ts +31 -0
  100. package/dist/ui/renderers/project-list.markdown.d.ts.map +1 -0
  101. package/dist/ui/renderers/project-list.markdown.js +148 -0
  102. package/dist/ui/renderers/project-list.markdown.js.map +1 -0
  103. package/dist/ui/renderers/project-list.renderer.d.ts +9 -0
  104. package/dist/ui/renderers/project-list.renderer.d.ts.map +1 -0
  105. package/dist/ui/renderers/project-list.renderer.js +17 -0
  106. package/dist/ui/renderers/project-list.renderer.js.map +1 -0
  107. package/package.json +38 -14
  108. package/src/billing/billing.presentation.ts +5 -6
  109. package/src/dashboard/dashboard.presentation.ts +5 -6
  110. package/src/example.ts +3 -3
  111. package/src/handlers/index.ts +3 -0
  112. package/src/handlers/saas.handlers.ts +300 -0
  113. package/src/index.ts +5 -0
  114. package/src/project/project.presentation.ts +5 -6
  115. package/src/saas-boilerplate.feature.ts +3 -3
  116. package/src/seeders/index.ts +28 -0
  117. package/src/shared/overlay-types.ts +39 -0
  118. package/src/tests/operations.test-spec.ts +109 -0
  119. package/src/ui/SaasDashboard.tsx +325 -0
  120. package/src/ui/SaasProjectList.tsx +113 -0
  121. package/src/ui/SaasSettingsPanel.tsx +96 -0
  122. package/src/ui/hooks/index.ts +10 -0
  123. package/src/ui/hooks/useProjectList.ts +95 -0
  124. package/src/ui/hooks/useProjectMutations.ts +166 -0
  125. package/src/ui/index.ts +18 -0
  126. package/src/ui/modals/CreateProjectModal.tsx +176 -0
  127. package/src/ui/modals/ProjectActionsModal.tsx +346 -0
  128. package/src/ui/modals/index.ts +2 -0
  129. package/src/ui/overlays/demo-overlays.ts +74 -0
  130. package/src/ui/overlays/index.ts +1 -0
  131. package/src/ui/renderers/index.ts +7 -0
  132. package/src/ui/renderers/project-list.markdown.ts +239 -0
  133. package/src/ui/renderers/project-list.renderer.tsx +22 -0
  134. package/tsconfig.json +1 -1
  135. package/tsconfig.tsbuildinfo +1 -1
@@ -0,0 +1,95 @@
1
+ /**
2
+ * Hook for fetching and managing project list data
3
+ *
4
+ * Uses runtime-local database-backed handlers.
5
+ */
6
+ import { useCallback, useEffect, useMemo, useState } from 'react';
7
+ import { useTemplateRuntime } from '@contractspec/lib.example-shared-ui';
8
+ import type {
9
+ Project as RuntimeProject,
10
+ Subscription as RuntimeSubscription,
11
+ SaasHandlers,
12
+ } from '../../handlers/saas.handlers';
13
+
14
+ // Re-export types for convenience
15
+ export type Project = RuntimeProject;
16
+ export type Subscription = RuntimeSubscription;
17
+
18
+ export interface ListProjectsOutput {
19
+ items: Project[];
20
+ total: number;
21
+ }
22
+
23
+ export interface UseProjectListOptions {
24
+ status?: 'DRAFT' | 'ACTIVE' | 'ARCHIVED' | 'all';
25
+ search?: string;
26
+ limit?: number;
27
+ }
28
+
29
+ export function useProjectList(options: UseProjectListOptions = {}) {
30
+ const { handlers, projectId } = useTemplateRuntime<{ saas: SaasHandlers }>();
31
+ const { saas } = handlers;
32
+
33
+ const [data, setData] = useState<ListProjectsOutput | null>(null);
34
+ const [subscription, setSubscription] = useState<Subscription | null>(null);
35
+ const [loading, setLoading] = useState(true);
36
+ const [error, setError] = useState<Error | null>(null);
37
+ const [page, setPage] = useState(1);
38
+
39
+ const fetchData = useCallback(async () => {
40
+ setLoading(true);
41
+ setError(null);
42
+
43
+ try {
44
+ const [projectsResult, subscriptionResult] = await Promise.all([
45
+ saas.listProjects({
46
+ projectId,
47
+ status: options.status === 'all' ? undefined : options.status,
48
+ search: options.search,
49
+ limit: options.limit ?? 20,
50
+ offset: (page - 1) * (options.limit ?? 20),
51
+ }),
52
+ saas.getSubscription({ projectId }),
53
+ ]);
54
+ setData({
55
+ items: projectsResult.items,
56
+ total: projectsResult.total,
57
+ });
58
+ setSubscription(subscriptionResult);
59
+ } catch (err) {
60
+ setError(err instanceof Error ? err : new Error('Unknown error'));
61
+ } finally {
62
+ setLoading(false);
63
+ }
64
+ }, [saas, projectId, options.status, options.search, options.limit, page]);
65
+
66
+ useEffect(() => {
67
+ fetchData();
68
+ }, [fetchData]);
69
+
70
+ // Calculate stats
71
+ const stats = useMemo(() => {
72
+ if (!data) return null;
73
+ const items = data.items;
74
+ return {
75
+ total: data.total,
76
+ activeCount: items.filter((p) => p.status === 'ACTIVE').length,
77
+ draftCount: items.filter((p) => p.status === 'DRAFT').length,
78
+ // Subscription stats are optional since they may not be seeded
79
+ projectLimit: 10, // Default limit for demo
80
+ usagePercent: Math.min((data.total / 10) * 100, 100),
81
+ };
82
+ }, [data]);
83
+
84
+ return {
85
+ data,
86
+ subscription,
87
+ loading,
88
+ error,
89
+ stats,
90
+ page,
91
+ refetch: fetchData,
92
+ nextPage: () => setPage((p) => p + 1),
93
+ prevPage: () => page > 1 && setPage((p) => p - 1),
94
+ };
95
+ }
@@ -0,0 +1,166 @@
1
+ /**
2
+ * Hook for SaaS project mutations (commands)
3
+ *
4
+ * Uses runtime-local database-backed handlers for:
5
+ * - CreateProjectContract
6
+ * - UpdateProjectContract
7
+ * - DeleteProjectContract
8
+ */
9
+ import { useCallback, useState } from 'react';
10
+ import { useTemplateRuntime } from '@contractspec/lib.example-shared-ui';
11
+ import type {
12
+ CreateProjectInput,
13
+ Project,
14
+ UpdateProjectInput,
15
+ SaasHandlers,
16
+ } from '../../handlers/saas.handlers';
17
+
18
+ export interface MutationState<T> {
19
+ loading: boolean;
20
+ error: Error | null;
21
+ data: T | null;
22
+ }
23
+
24
+ export interface UseProjectMutationsOptions {
25
+ onSuccess?: () => void;
26
+ onError?: (error: Error) => void;
27
+ }
28
+
29
+ export function useProjectMutations(options: UseProjectMutationsOptions = {}) {
30
+ const { handlers, projectId } = useTemplateRuntime<{ saas: SaasHandlers }>();
31
+ const { saas } = handlers;
32
+
33
+ const [createState, setCreateState] = useState<MutationState<Project>>({
34
+ loading: false,
35
+ error: null,
36
+ data: null,
37
+ });
38
+
39
+ const [updateState, setUpdateState] = useState<MutationState<Project>>({
40
+ loading: false,
41
+ error: null,
42
+ data: null,
43
+ });
44
+
45
+ const [deleteState, setDeleteState] = useState<
46
+ MutationState<{ success: boolean }>
47
+ >({
48
+ loading: false,
49
+ error: null,
50
+ data: null,
51
+ });
52
+
53
+ /**
54
+ * Create a new project
55
+ */
56
+ const createProject = useCallback(
57
+ async (input: CreateProjectInput): Promise<Project | null> => {
58
+ setCreateState({ loading: true, error: null, data: null });
59
+ try {
60
+ const result = await saas.createProject(input, {
61
+ projectId,
62
+ organizationId: 'demo-org',
63
+ });
64
+ setCreateState({ loading: false, error: null, data: result });
65
+ options.onSuccess?.();
66
+ return result;
67
+ } catch (err) {
68
+ const error =
69
+ err instanceof Error ? err : new Error('Failed to create project');
70
+ setCreateState({ loading: false, error, data: null });
71
+ options.onError?.(error);
72
+ return null;
73
+ }
74
+ },
75
+ [saas, projectId, options]
76
+ );
77
+
78
+ /**
79
+ * Update a project
80
+ */
81
+ const updateProject = useCallback(
82
+ async (input: UpdateProjectInput): Promise<Project | null> => {
83
+ setUpdateState({ loading: true, error: null, data: null });
84
+ try {
85
+ const result = await saas.updateProject(input);
86
+ setUpdateState({ loading: false, error: null, data: result });
87
+ options.onSuccess?.();
88
+ return result;
89
+ } catch (err) {
90
+ const error =
91
+ err instanceof Error ? err : new Error('Failed to update project');
92
+ setUpdateState({ loading: false, error, data: null });
93
+ options.onError?.(error);
94
+ return null;
95
+ }
96
+ },
97
+ [saas, options]
98
+ );
99
+
100
+ /**
101
+ * Delete a project (soft delete)
102
+ */
103
+ const deleteProject = useCallback(
104
+ async (id: string): Promise<boolean> => {
105
+ setDeleteState({ loading: true, error: null, data: null });
106
+ try {
107
+ await saas.deleteProject(id);
108
+ setDeleteState({
109
+ loading: false,
110
+ error: null,
111
+ data: { success: true },
112
+ });
113
+ options.onSuccess?.();
114
+ return true;
115
+ } catch (err) {
116
+ const error =
117
+ err instanceof Error ? err : new Error('Failed to delete project');
118
+ setDeleteState({ loading: false, error, data: null });
119
+ options.onError?.(error);
120
+ return false;
121
+ }
122
+ },
123
+ [saas, options]
124
+ );
125
+
126
+ /**
127
+ * Archive a project (status change)
128
+ */
129
+ const archiveProject = useCallback(
130
+ async (id: string): Promise<Project | null> => {
131
+ return updateProject({ id, status: 'ARCHIVED' });
132
+ },
133
+ [updateProject]
134
+ );
135
+
136
+ /**
137
+ * Activate a project (status change)
138
+ */
139
+ const activateProject = useCallback(
140
+ async (id: string): Promise<Project | null> => {
141
+ return updateProject({ id, status: 'ACTIVE' });
142
+ },
143
+ [updateProject]
144
+ );
145
+
146
+ return {
147
+ // Mutations
148
+ createProject,
149
+ updateProject,
150
+ deleteProject,
151
+ archiveProject,
152
+ activateProject,
153
+
154
+ // State
155
+ createState,
156
+ updateState,
157
+ deleteState,
158
+
159
+ // Convenience
160
+ isLoading:
161
+ createState.loading || updateState.loading || deleteState.loading,
162
+ };
163
+ }
164
+
165
+ // Note: Types are re-exported from the handlers package
166
+ // Consumers should import types directly from '@contractspec/example.saas-boilerplate/handlers'
@@ -0,0 +1,18 @@
1
+ // Main dashboard
2
+ export * from './SaasDashboard';
3
+
4
+ // Standalone components
5
+ export * from './SaasProjectList';
6
+ export * from './SaasSettingsPanel';
7
+
8
+ // Modals
9
+ export * from './modals';
10
+
11
+ // Hooks
12
+ export * from './hooks';
13
+
14
+ // Renderers
15
+ export * from './renderers';
16
+
17
+ // Overlays
18
+ export * from './overlays';
@@ -0,0 +1,176 @@
1
+ 'use client';
2
+
3
+ /**
4
+ * CreateProjectModal - Form for creating a new project
5
+ *
6
+ * Wires to CreateProjectContract via useProjectMutations hook.
7
+ */
8
+ import { useState } from 'react';
9
+ import { Button, Input } from '@contractspec/lib.design-system';
10
+
11
+ // Local type definition for modal props
12
+ export interface CreateProjectInput {
13
+ name: string;
14
+ description?: string;
15
+ tier: 'FREE' | 'PRO' | 'ENTERPRISE';
16
+ }
17
+
18
+ interface CreateProjectModalProps {
19
+ isOpen: boolean;
20
+ onClose: () => void;
21
+ onSubmit: (input: CreateProjectInput) => Promise<void>;
22
+ isLoading?: boolean;
23
+ }
24
+
25
+ const TIERS: { value: CreateProjectInput['tier']; label: string }[] = [
26
+ { value: 'FREE', label: 'Free' },
27
+ { value: 'PRO', label: 'Pro' },
28
+ { value: 'ENTERPRISE', label: 'Enterprise' },
29
+ ];
30
+
31
+ export function CreateProjectModal({
32
+ isOpen,
33
+ onClose,
34
+ onSubmit,
35
+ isLoading = false,
36
+ }: CreateProjectModalProps) {
37
+ const [name, setName] = useState('');
38
+ const [description, setDescription] = useState('');
39
+ const [tier, setTier] = useState<CreateProjectInput['tier']>('FREE');
40
+ const [error, setError] = useState<string | null>(null);
41
+
42
+ const handleSubmit = async (e: React.FormEvent) => {
43
+ e.preventDefault();
44
+ setError(null);
45
+
46
+ // Validation
47
+ if (!name.trim()) {
48
+ setError('Project name is required');
49
+ return;
50
+ }
51
+
52
+ try {
53
+ await onSubmit({
54
+ name: name.trim(),
55
+ description: description.trim() || undefined,
56
+ tier,
57
+ });
58
+
59
+ // Reset form
60
+ setName('');
61
+ setDescription('');
62
+ setTier('FREE');
63
+ onClose();
64
+ } catch (err) {
65
+ setError(err instanceof Error ? err.message : 'Failed to create project');
66
+ }
67
+ };
68
+
69
+ if (!isOpen) return null;
70
+
71
+ return (
72
+ <div className="fixed inset-0 z-50 flex items-center justify-center">
73
+ {/* Backdrop */}
74
+ <div
75
+ className="bg-background/80 absolute inset-0 backdrop-blur-sm"
76
+ onClick={onClose}
77
+ role="button"
78
+ tabIndex={0}
79
+ onKeyDown={(e) => {
80
+ if (e.key === 'Enter' || e.key === ' ') onClose();
81
+ }}
82
+ aria-label="Close modal"
83
+ />
84
+
85
+ {/* Modal */}
86
+ <div className="bg-card border-border relative z-10 w-full max-w-md rounded-xl border p-6 shadow-xl">
87
+ <h2 className="mb-4 text-xl font-semibold">Create New Project</h2>
88
+
89
+ <form onSubmit={handleSubmit} className="space-y-4">
90
+ {/* Project Name */}
91
+ <div>
92
+ <label
93
+ htmlFor="project-name"
94
+ className="text-muted-foreground mb-1 block text-sm font-medium"
95
+ >
96
+ Project Name *
97
+ </label>
98
+ <Input
99
+ id="project-name"
100
+ value={name}
101
+ onChange={(e) => setName(e.target.value)}
102
+ placeholder="e.g., My Awesome Project"
103
+ disabled={isLoading}
104
+ />
105
+ </div>
106
+
107
+ {/* Description */}
108
+ <div>
109
+ <label
110
+ htmlFor="project-description"
111
+ className="text-muted-foreground mb-1 block text-sm font-medium"
112
+ >
113
+ Description
114
+ </label>
115
+ <textarea
116
+ id="project-description"
117
+ value={description}
118
+ onChange={(e) => setDescription(e.target.value)}
119
+ placeholder="Describe what this project is about..."
120
+ rows={3}
121
+ disabled={isLoading}
122
+ className="border-input bg-background focus:ring-ring w-full rounded-md border px-3 py-2 text-sm focus:ring-2 focus:outline-none disabled:opacity-50"
123
+ />
124
+ </div>
125
+
126
+ {/* Tier */}
127
+ <div>
128
+ <label
129
+ htmlFor="project-tier"
130
+ className="text-muted-foreground mb-1 block text-sm font-medium"
131
+ >
132
+ Tier
133
+ </label>
134
+ <select
135
+ id="project-tier"
136
+ value={tier}
137
+ onChange={(e) =>
138
+ setTier(e.target.value as CreateProjectInput['tier'])
139
+ }
140
+ disabled={isLoading}
141
+ className="border-input bg-background focus:ring-ring h-10 w-full rounded-md border px-3 py-2 text-sm focus:ring-2 focus:outline-none disabled:opacity-50"
142
+ >
143
+ {TIERS.map((t) => (
144
+ <option key={t.value} value={t.value}>
145
+ {t.label}
146
+ </option>
147
+ ))}
148
+ </select>
149
+ </div>
150
+
151
+ {/* Error Message */}
152
+ {error && (
153
+ <div className="bg-destructive/10 text-destructive rounded-md p-3 text-sm">
154
+ {error}
155
+ </div>
156
+ )}
157
+
158
+ {/* Actions */}
159
+ <div className="flex justify-end gap-3 pt-2">
160
+ <Button
161
+ type="button"
162
+ variant="ghost"
163
+ onPress={onClose}
164
+ disabled={isLoading}
165
+ >
166
+ Cancel
167
+ </Button>
168
+ <Button type="submit" disabled={isLoading}>
169
+ {isLoading ? 'Creating...' : 'Create Project'}
170
+ </Button>
171
+ </div>
172
+ </form>
173
+ </div>
174
+ </div>
175
+ );
176
+ }