@stacksjs/defaults 0.70.355 → 0.70.356

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 (155) hide show
  1. package/ai/skills/stacks-email/SKILL.md +38 -1
  2. package/app/Actions/ContactAction.ts +2 -2
  3. package/app/Actions/Dashboard/Analytics/EventAnalyticsAction.ts +2 -3
  4. package/app/Actions/Dashboard/Analytics/MarketingAnalyticsAction.ts +2 -3
  5. package/app/Actions/Dashboard/Analytics/SalesAnalyticsAction.ts +2 -3
  6. package/app/Actions/Dashboard/Analytics/WebAnalyticsAction.ts +9 -3
  7. package/app/Actions/Dashboard/Auth/MeAction.ts +4 -7
  8. package/app/Actions/Dashboard/Buddy/BuddyChatAction.ts +2 -3
  9. package/app/Actions/Dashboard/Cloud/CloudIndexAction.ts +8 -1
  10. package/app/Actions/Dashboard/Cloud/ServerlessIndexAction.ts +15 -8
  11. package/app/Actions/Dashboard/Commerce/CommerceCategoriesAction.ts +2 -4
  12. package/app/Actions/Dashboard/Commerce/CommerceCouponsAction.ts +2 -4
  13. package/app/Actions/Dashboard/Commerce/CommerceCustomersAction.ts +2 -4
  14. package/app/Actions/Dashboard/Commerce/CommerceDashboardAction.ts +2 -4
  15. package/app/Actions/Dashboard/Commerce/CommerceDeliveryAction.ts +2 -4
  16. package/app/Actions/Dashboard/Commerce/CommerceGiftCardsAction.ts +2 -4
  17. package/app/Actions/Dashboard/Commerce/CommerceOrdersAction.ts +2 -4
  18. package/app/Actions/Dashboard/Commerce/CommercePaymentsAction.ts +2 -4
  19. package/app/Actions/Dashboard/Commerce/CommercePosAction.ts +2 -4
  20. package/app/Actions/Dashboard/Commerce/CommercePosCheckoutAction.ts +75 -61
  21. package/app/Actions/Dashboard/Commerce/CommercePrintDevicesAction.ts +2 -4
  22. package/app/Actions/Dashboard/Commerce/CommercePrintLogsAction.ts +2 -4
  23. package/app/Actions/Dashboard/Commerce/CommerceProductDetailAction.ts +3 -4
  24. package/app/Actions/Dashboard/Commerce/CommerceProductsAction.ts +2 -4
  25. package/app/Actions/Dashboard/Commerce/CommerceTaxesAction.ts +2 -4
  26. package/app/Actions/Dashboard/Commerce/DeliveryRouteIndexAction.ts +2 -4
  27. package/app/Actions/Dashboard/Commerce/DigitalDeliveryIndexAction.ts +2 -4
  28. package/app/Actions/Dashboard/Commerce/DriverIndexAction.ts +2 -4
  29. package/app/Actions/Dashboard/Commerce/LicenseKeyIndexAction.ts +2 -4
  30. package/app/Actions/Dashboard/Commerce/LicenseKeyOptionsAction.ts +2 -4
  31. package/app/Actions/Dashboard/Commerce/ManufacturerIndexAction.ts +2 -4
  32. package/app/Actions/Dashboard/Commerce/ProductUnitIndexAction.ts +2 -4
  33. package/app/Actions/Dashboard/Commerce/ProductVariantIndexAction.ts +2 -4
  34. package/app/Actions/Dashboard/Commerce/ProductWaitlistIndexAction.ts +2 -4
  35. package/app/Actions/Dashboard/Commerce/RestaurantWaitlistIndexAction.ts +2 -4
  36. package/app/Actions/Dashboard/Commerce/ReviewIndexAction.ts +2 -4
  37. package/app/Actions/Dashboard/Commerce/ShippingMethodIndexAction.ts +2 -4
  38. package/app/Actions/Dashboard/Commerce/ShippingRateIndexAction.ts +2 -4
  39. package/app/Actions/Dashboard/Commerce/ShippingZoneIndexAction.ts +2 -4
  40. package/app/Actions/Dashboard/DashboardActivityAction.ts +2 -5
  41. package/app/Actions/Dashboard/Data/ActivityIndexAction.ts +2 -5
  42. package/app/Actions/Dashboard/Data/SubscriberIndexAction.ts +2 -5
  43. package/app/Actions/Dashboard/Data/TeamIndexAction.ts +2 -5
  44. package/app/Actions/Dashboard/Data/UserIndexAction.ts +2 -5
  45. package/app/Actions/Dashboard/Deployments/CreateDeployment.ts +23 -19
  46. package/app/Actions/Dashboard/Deployments/GetAverageDeploymentTime.ts +8 -2
  47. package/app/Actions/Dashboard/Deployments/GetDeployScript.ts +3 -6
  48. package/app/Actions/Dashboard/Deployments/GetDeployment.ts +4 -5
  49. package/app/Actions/Dashboard/Deployments/GetDeploymentCount.ts +7 -1
  50. package/app/Actions/Dashboard/Deployments/GetDeploymentLiveTerminalOutput.ts +10 -9
  51. package/app/Actions/Dashboard/Deployments/GetDeployments.ts +2 -4
  52. package/app/Actions/Dashboard/Deployments/GetRecentDeployments.ts +8 -2
  53. package/app/Actions/Dashboard/Deployments/UpdateDeployScript.ts +18 -5
  54. package/app/Actions/Dashboard/Email/CapturedMailIndexAction.ts +2 -4
  55. package/app/Actions/Dashboard/Email/CapturedMailShowAction.ts +3 -4
  56. package/app/Actions/Dashboard/Infrastructure/InsightsAction.ts +15 -14
  57. package/app/Actions/Dashboard/Infrastructure/LogIndexAction.ts +2 -8
  58. package/app/Actions/Dashboard/Jobs/JobIndexAction.ts +2 -4
  59. package/app/Actions/Dashboard/Jobs/JobShowAction.ts +13 -8
  60. package/app/Actions/Dashboard/Jobs/JobStatsAction.ts +2 -4
  61. package/app/Actions/Dashboard/Kanban/BoardDestroyAction.ts +2 -3
  62. package/app/Actions/Dashboard/Kanban/BoardShowAction.ts +2 -3
  63. package/app/Actions/Dashboard/Kanban/BoardStoreAction.ts +2 -3
  64. package/app/Actions/Dashboard/Kanban/BoardUpdateAction.ts +2 -3
  65. package/app/Actions/Dashboard/Kanban/BoardsIndexAction.ts +2 -3
  66. package/app/Actions/Dashboard/Kanban/BoardsReorderAction.ts +2 -3
  67. package/app/Actions/Dashboard/Kanban/CardAssigneesSyncAction.ts +2 -3
  68. package/app/Actions/Dashboard/Kanban/CardCommentDestroyAction.ts +2 -3
  69. package/app/Actions/Dashboard/Kanban/CardCommentStoreAction.ts +2 -3
  70. package/app/Actions/Dashboard/Kanban/CardCommentUpdateAction.ts +2 -3
  71. package/app/Actions/Dashboard/Kanban/CardDestroyAction.ts +2 -3
  72. package/app/Actions/Dashboard/Kanban/CardLabelsSyncAction.ts +2 -3
  73. package/app/Actions/Dashboard/Kanban/CardShowAction.ts +2 -3
  74. package/app/Actions/Dashboard/Kanban/CardStoreAction.ts +2 -3
  75. package/app/Actions/Dashboard/Kanban/CardUpdateAction.ts +2 -3
  76. package/app/Actions/Dashboard/Kanban/CardsReorderAction.ts +2 -3
  77. package/app/Actions/Dashboard/Kanban/ColumnDestroyAction.ts +2 -3
  78. package/app/Actions/Dashboard/Kanban/ColumnStoreAction.ts +2 -3
  79. package/app/Actions/Dashboard/Kanban/ColumnUpdateAction.ts +2 -3
  80. package/app/Actions/Dashboard/Kanban/ColumnsReorderAction.ts +2 -3
  81. package/app/Actions/Dashboard/Kanban/LabelDestroyAction.ts +2 -3
  82. package/app/Actions/Dashboard/Kanban/LabelStoreAction.ts +2 -3
  83. package/app/Actions/Dashboard/Kanban/LabelUpdateAction.ts +2 -3
  84. package/app/Actions/Dashboard/Kanban/UsersListAction.ts +2 -3
  85. package/app/Actions/Dashboard/Kanban/kanban-response.ts +5 -0
  86. package/app/Actions/Dashboard/Library/CreateComponent.ts +15 -6
  87. package/app/Actions/Dashboard/Library/CreateFunction.ts +15 -6
  88. package/app/Actions/Dashboard/Library/DependencyIndexAction.ts +88 -77
  89. package/app/Actions/Dashboard/Library/GetAverageReleaseTime.ts +21 -15
  90. package/app/Actions/Dashboard/Library/GetComponents.ts +14 -7
  91. package/app/Actions/Dashboard/Library/GetDownloadCount.ts +14 -5
  92. package/app/Actions/Dashboard/Library/GetFunctions.ts +12 -5
  93. package/app/Actions/Dashboard/Library/GetReleaseCount.ts +14 -5
  94. package/app/Actions/Dashboard/Library/GetReleases.ts +17 -10
  95. package/app/Actions/Dashboard/Library/PackageIndexAction.ts +14 -7
  96. package/app/Actions/Dashboard/Models/ModelDestroyAction.ts +7 -5
  97. package/app/Actions/Dashboard/Models/ModelShowAction.ts +82 -174
  98. package/app/Actions/Dashboard/Models/ModelStoreAction.ts +6 -4
  99. package/app/Actions/Dashboard/Models/ModelUpdateAction.ts +9 -7
  100. package/app/Actions/Dashboard/Models/ModelsIndexAction.ts +47 -17
  101. package/app/Actions/Dashboard/Models/model-write.ts +20 -5
  102. package/app/Actions/Dashboard/Notifications/NotificationDeliveryHistoryAction.ts +46 -36
  103. package/app/Actions/Dashboard/Notifications/NotificationDeliveryIndexAction.ts +14 -6
  104. package/app/Actions/Dashboard/Notifications/NotificationDeliveryOverviewAction.ts +96 -84
  105. package/app/Actions/Dashboard/Notifications/NotificationDeliveryRetryAction.ts +34 -21
  106. package/app/Actions/Dashboard/Queries/QueryDashboardAction.ts +2 -4
  107. package/app/Actions/Dashboard/Queries/QueryShowAction.ts +2 -3
  108. package/app/Actions/Dashboard/Queue/QueueStatsAction.ts +2 -4
  109. package/app/Actions/Dashboard/Queue/QueueWorkersAction.ts +2 -4
  110. package/app/Actions/Dashboard/Rbac/PermissionDestroyAction.ts +2 -2
  111. package/app/Actions/Dashboard/Rbac/PermissionStoreAction.ts +2 -2
  112. package/app/Actions/Dashboard/Rbac/PermissionsIndexAction.ts +2 -3
  113. package/app/Actions/Dashboard/Rbac/RoleDestroyAction.ts +2 -2
  114. package/app/Actions/Dashboard/Rbac/RolePermissionsShowAction.ts +2 -2
  115. package/app/Actions/Dashboard/Rbac/RolePermissionsSyncAction.ts +2 -6
  116. package/app/Actions/Dashboard/Rbac/RoleStoreAction.ts +2 -2
  117. package/app/Actions/Dashboard/Rbac/RolesIndexAction.ts +4 -6
  118. package/app/Actions/Dashboard/Rbac/UserRolesShowAction.ts +2 -2
  119. package/app/Actions/Dashboard/Rbac/UserRolesSyncAction.ts +2 -9
  120. package/app/Actions/Dashboard/Rbac/UsersListAction.ts +2 -3
  121. package/app/Actions/Dashboard/Rbac/rbac-response.ts +10 -0
  122. package/app/Actions/Dashboard/Realtime/RealtimeStatsAction.ts +2 -4
  123. package/app/Actions/Dashboard/Search/GlobalSearchAction.ts +68 -55
  124. package/app/Actions/Dashboard/Teams/TeamInvitationDestroyAction.ts +34 -16
  125. package/app/Actions/Dashboard/Teams/TeamInvitationResendAction.ts +52 -29
  126. package/app/Actions/Dashboard/Teams/TeamInviteAction.ts +102 -71
  127. package/app/Actions/Dashboard/Teams/TeamMemberDestroyAction.ts +36 -17
  128. package/app/Actions/Dashboard/Teams/TeamMemberUpdateAction.ts +39 -26
  129. package/app/Actions/Dashboard/Teams/TeamPeopleIndexAction.ts +71 -58
  130. package/app/Actions/Dashboard/Teams/team-invitation-delivery.ts +29 -7
  131. package/app/Actions/Dashboard/Teams/team-member-count.ts +4 -2
  132. package/app/Actions/Dashboard/Teams/team-records.test.ts +2 -0
  133. package/app/Actions/Dashboard/Teams/team-records.ts +2 -0
  134. package/app/Actions/Dashboard/dashboard-response.ts +16 -0
  135. package/app/Actions/SendWelcomeEmail.ts +1 -1
  136. package/app/Actions/Teams/AcceptInvitationAction.ts +74 -51
  137. package/app/Actions/Teams/ShowInvitationAction.ts +21 -14
  138. package/app/Actions/Teams/team-response.ts +23 -0
  139. package/app/Mail/OrderConfirmation.ts +1 -1
  140. package/app/Mail/SubscriptionConfirmation.ts +1 -1
  141. package/app/Mail/TeamInvitation.ts +1 -1
  142. package/app/Models/EmailIdempotency.ts +64 -0
  143. package/app/Models/EmailSuppression.ts +52 -0
  144. package/app/Models/EmailWebhookEvent.ts +51 -0
  145. package/app/Models/TeamInvitation.ts +13 -0
  146. package/functions/data.ts +0 -1
  147. package/functions/jobs.ts +0 -1
  148. package/ide/vscode/package.json +1 -1
  149. package/package.json +1 -1
  150. package/resources/components/Dashboard/Data/DataRecords.stx +0 -4
  151. package/resources/components/Dashboard/Jobs/JobDetail.stx +3 -2
  152. package/resources/components/Dashboard/Models/ModelRecordsDashboard.stx +7 -13
  153. package/resources/components/Dashboard/Models/ModelsOverview.stx +1 -1
  154. package/views/dashboard/.discovered-models.json +30 -0
  155. package/views/dashboard/stores/auth.ts +15 -14
@@ -1,94 +1,105 @@
1
1
  import { Action } from '@stacksjs/actions'
2
2
  import { existsSync, readFileSync } from 'node:fs'
3
3
  import { join } from 'node:path'
4
+ import { dashboardOperationalError } from '../dashboard-response'
4
5
 
5
- export default new Action({
6
- name: 'DependencyIndexAction',
7
- description: 'Returns dependency data for the dashboard.',
8
- method: 'GET',
9
- async handle() {
10
- const projectRoot = process.cwd()
11
- const lockPath = join(projectRoot, 'bun.lock')
6
+ function dependencySnapshot() {
7
+ const projectRoot = process.cwd()
8
+ const lockPath = join(projectRoot, 'bun.lock')
12
9
 
13
- const declared: Array<Record<string, unknown>> = []
14
- const transitive: Array<Record<string, unknown>> = []
15
- let workspaceCount = 0
16
- let thirdPartyCount = 0
17
- let transitiveCount = 0
18
- let totalCount = 0
10
+ const declared: Array<Record<string, unknown>> = []
11
+ const transitive: Array<Record<string, unknown>> = []
12
+ let workspaceCount = 0
13
+ let thirdPartyCount = 0
14
+ let transitiveCount = 0
15
+ let totalCount = 0
19
16
 
20
- if (!existsSync(lockPath)) {
21
- return {
22
- available: false,
23
- source: 'bun.lock',
24
- declared,
25
- thirdParty: [],
26
- workspace: [],
27
- transitive,
28
- stats: [],
29
- totalCount,
30
- transitiveCount,
31
- workspaceCount,
32
- thirdPartyCount,
33
- }
17
+ if (!existsSync(lockPath)) {
18
+ return {
19
+ available: false,
20
+ source: 'bun.lock',
21
+ declared,
22
+ thirdParty: [],
23
+ workspace: [],
24
+ transitive,
25
+ stats: [],
26
+ totalCount,
27
+ transitiveCount,
28
+ workspaceCount,
29
+ thirdPartyCount,
34
30
  }
31
+ }
35
32
 
36
- const declaredSet: Record<string, boolean> = {}
37
- const lockfile = Bun.JSONC.parse(readFileSync(lockPath, 'utf-8')) as {
38
- workspaces?: Record<string, { name?: string, dependencies?: Record<string, string>, devDependencies?: Record<string, string> }>
39
- packages?: Record<string, [string, ...unknown[]]>
40
- }
41
- const workspaces = lockfile.workspaces || {}
42
- const workspaceNames = new Set(
43
- Object.values(workspaces)
44
- .map(workspace => workspace.name)
45
- .filter((name): name is string => Boolean(name)),
46
- )
33
+ const declaredSet: Record<string, boolean> = {}
34
+ const lockfile = Bun.JSONC.parse(readFileSync(lockPath, 'utf-8')) as {
35
+ workspaces?: Record<string, { name?: string, dependencies?: Record<string, string>, devDependencies?: Record<string, string> }>
36
+ packages?: Record<string, [string, ...unknown[]]>
37
+ }
38
+ const workspaces = lockfile.workspaces || {}
39
+ const workspaceNames = new Set(
40
+ Object.values(workspaces)
41
+ .map(workspace => workspace.name)
42
+ .filter((name): name is string => Boolean(name)),
43
+ )
47
44
 
48
- for (const wsKey of Object.keys(workspaces)) {
49
- const ws = workspaces[wsKey]
50
- const allDeps = { ...ws.dependencies, ...ws.devDependencies }
51
- for (const depName of Object.keys(allDeps)) {
52
- if (declaredSet[depName]) continue
53
- declaredSet[depName] = true
54
- const version = allDeps[depName]
55
- const isWorkspace = workspaceNames.has(depName)
56
- declared.push({ name: depName, version, isWorkspace, isScoped: depName.includes('/') })
57
- }
45
+ for (const wsKey of Object.keys(workspaces)) {
46
+ const ws = workspaces[wsKey]
47
+ const allDeps = { ...ws.dependencies, ...ws.devDependencies }
48
+ for (const depName of Object.keys(allDeps)) {
49
+ if (declaredSet[depName]) continue
50
+ declaredSet[depName] = true
51
+ const version = allDeps[depName]
52
+ const isWorkspace = workspaceNames.has(depName)
53
+ declared.push({ name: depName, version, isWorkspace, isScoped: depName.includes('/') })
58
54
  }
59
- declared.sort((a, b) => String(a.name).localeCompare(String(b.name)))
55
+ }
56
+ declared.sort((a, b) => String(a.name).localeCompare(String(b.name)))
60
57
 
61
- const transitiveSet = new Set<string>()
62
- for (const value of Object.values(lockfile.packages || {})) {
63
- const resolution = value[0]
64
- if (resolution.includes('@workspace:')) continue
65
- const versionSeparator = resolution.startsWith('@')
66
- ? resolution.indexOf('@', 1)
67
- : resolution.lastIndexOf('@')
68
- if (versionSeparator <= 0) continue
69
- const name = resolution.slice(0, versionSeparator)
70
- const version = resolution.slice(versionSeparator + 1)
71
- if (declaredSet[name] || transitiveSet.has(name)) continue
72
- transitiveSet.add(name)
73
- transitive.push({ name, version, isScoped: name.includes('/') })
74
- }
75
- transitive.sort((a, b) => String(a.name).localeCompare(String(b.name)))
58
+ const transitiveSet = new Set<string>()
59
+ for (const value of Object.values(lockfile.packages || {})) {
60
+ const resolution = value[0]
61
+ if (resolution.includes('@workspace:')) continue
62
+ const versionSeparator = resolution.startsWith('@')
63
+ ? resolution.indexOf('@', 1)
64
+ : resolution.lastIndexOf('@')
65
+ if (versionSeparator <= 0) continue
66
+ const name = resolution.slice(0, versionSeparator)
67
+ const version = resolution.slice(versionSeparator + 1)
68
+ if (declaredSet[name] || transitiveSet.has(name)) continue
69
+ transitiveSet.add(name)
70
+ transitive.push({ name, version, isScoped: name.includes('/') })
71
+ }
72
+ transitive.sort((a, b) => String(a.name).localeCompare(String(b.name)))
73
+
74
+ workspaceCount = declared.filter(p => p.isWorkspace).length
75
+ thirdPartyCount = declared.length - workspaceCount
76
+ transitiveCount = transitive.length
77
+ totalCount = declared.length + transitiveCount
76
78
 
77
- workspaceCount = declared.filter(p => p.isWorkspace).length
78
- thirdPartyCount = declared.length - workspaceCount
79
- transitiveCount = transitive.length
80
- totalCount = declared.length + transitiveCount
79
+ const thirdParty = declared.filter(p => !p.isWorkspace)
80
+ const workspace = declared.filter(p => p.isWorkspace)
81
81
 
82
- const thirdParty = declared.filter(p => !p.isWorkspace)
83
- const workspace = declared.filter(p => p.isWorkspace)
82
+ const stats = [
83
+ { label: 'Declared', value: String(declared.length) },
84
+ { label: 'Third-Party', value: String(thirdPartyCount) },
85
+ { label: 'Workspace', value: String(workspaceCount) },
86
+ { label: 'Transitive', value: String(transitiveCount) },
87
+ ]
84
88
 
85
- const stats = [
86
- { label: 'Declared', value: String(declared.length) },
87
- { label: 'Third-Party', value: String(thirdPartyCount) },
88
- { label: 'Workspace', value: String(workspaceCount) },
89
- { label: 'Transitive', value: String(transitiveCount) },
90
- ]
89
+ return { available: true, source: 'bun.lock', declared, thirdParty, workspace, transitive, stats, totalCount, transitiveCount, workspaceCount, thirdPartyCount }
90
+ }
91
91
 
92
- return { available: true, source: 'bun.lock', declared, thirdParty, workspace, transitive, stats, totalCount, transitiveCount, workspaceCount, thirdPartyCount }
92
+ export default new Action({
93
+ name: 'DependencyIndexAction',
94
+ description: 'Returns dependency data for the dashboard.',
95
+ method: 'GET',
96
+ apiResponse: true,
97
+ async handle() {
98
+ try {
99
+ return dependencySnapshot()
100
+ }
101
+ catch (error) {
102
+ return dashboardOperationalError(error, 'Dependency data could not be loaded.', 'DependencyIndexAction')
103
+ }
93
104
  },
94
105
  })
@@ -1,5 +1,6 @@
1
1
  import { Action } from '@stacksjs/actions'
2
2
  import { db } from '@stacksjs/database'
3
+ import { dashboardOperationalError } from '../dashboard-response'
3
4
 
4
5
  export default new Action({
5
6
  name: 'GetAverageReleaseTime',
@@ -7,24 +8,29 @@ export default new Action({
7
8
  apiResponse: true,
8
9
 
9
10
  async handle() {
10
- const rows = await db
11
- .selectFrom('releases')
12
- .select(['created_at'])
13
- .whereNotNull('created_at')
14
- .orderBy('created_at')
15
- .execute() as unknown as Array<{ created_at: string }>
11
+ try {
12
+ const rows = await db
13
+ .selectFrom('releases')
14
+ .select(['created_at'])
15
+ .whereNotNull('created_at')
16
+ .orderBy('created_at')
17
+ .execute() as unknown as Array<{ created_at: string }>
16
18
 
17
- const timestamps = rows
18
- .map(row => new Date(row.created_at).getTime())
19
- .filter(Number.isFinite)
19
+ const timestamps = rows
20
+ .map(row => new Date(row.created_at).getTime())
21
+ .filter(Number.isFinite)
20
22
 
21
- if (timestamps.length < 2)
22
- return { averageSeconds: null, intervals: 0 }
23
+ if (timestamps.length < 2)
24
+ return { averageSeconds: null, intervals: 0 }
23
25
 
24
- const elapsed = timestamps.slice(1).reduce((total, value, index) => total + value - timestamps[index]!, 0)
25
- return {
26
- averageSeconds: Math.round(elapsed / (timestamps.length - 1) / 1000),
27
- intervals: timestamps.length - 1,
26
+ const elapsed = timestamps.slice(1).reduce((total, value, index) => total + value - timestamps[index]!, 0)
27
+ return {
28
+ averageSeconds: Math.round(elapsed / (timestamps.length - 1) / 1000),
29
+ intervals: timestamps.length - 1,
30
+ }
31
+ }
32
+ catch (error) {
33
+ return dashboardOperationalError(error, 'Average release time could not be loaded.', 'GetAverageReleaseTime')
28
34
  }
29
35
  },
30
36
  })
@@ -1,20 +1,27 @@
1
1
  import { Action } from '@stacksjs/actions'
2
+ import { dashboardOperationalError } from '../dashboard-response'
2
3
  import { componentSourceRows } from './library-source'
3
4
 
4
5
  export default new Action({
5
6
  name: 'GetComponents',
6
7
  description: 'Gets your UI components.',
7
8
  method: 'GET',
9
+ apiResponse: true,
8
10
 
9
11
  async handle() {
10
- const components = componentSourceRows()
11
- const categories = ['All', ...new Set(components.map(component => component.category))]
12
+ try {
13
+ const components = componentSourceRows()
14
+ const categories = ['All', ...new Set(components.map(component => component.category))]
12
15
 
13
- return {
14
- components,
15
- categories,
16
- totalBytes: components.reduce((sum, component) => sum + component.bytes, 0),
17
- sourceRoot: 'resources/components',
16
+ return {
17
+ components,
18
+ categories,
19
+ totalBytes: components.reduce((sum, component) => sum + component.bytes, 0),
20
+ sourceRoot: 'resources/components',
21
+ }
22
+ }
23
+ catch (error) {
24
+ return dashboardOperationalError(error, 'Component library could not be loaded.', 'GetComponents')
18
25
  }
19
26
  },
20
27
  })
@@ -1,5 +1,6 @@
1
1
  import { Action } from '@stacksjs/actions'
2
2
  import { db } from '@stacksjs/database'
3
+ import { dashboardOperationalError } from '../dashboard-response'
3
4
 
4
5
  export default new Action({
5
6
  name: 'GetDownloadCount',
@@ -7,11 +8,19 @@ export default new Action({
7
8
  apiResponse: true,
8
9
 
9
10
  async handle() {
10
- const row = await db
11
- .selectFrom('releases')
12
- .select(db.fn.sum('downloads').as('downloads'))
13
- .executeTakeFirst() as { downloads?: number | string | null } | undefined
11
+ try {
12
+ const row = await db
13
+ .selectFrom('releases')
14
+ .select(db.fn.sum('downloads').as('downloads'))
15
+ .executeTakeFirst() as { downloads?: number | string | null } | undefined
16
+ const downloads = Number(row?.downloads || 0)
17
+ if (!Number.isSafeInteger(downloads) || downloads < 0)
18
+ throw new TypeError('Release download total must be a non-negative integer.')
14
19
 
15
- return { downloads: Number(row?.downloads || 0), source: 'releases.downloads' }
20
+ return { downloads, source: 'releases.downloads' }
21
+ }
22
+ catch (error) {
23
+ return dashboardOperationalError(error, 'Release download count could not be loaded.', 'GetDownloadCount')
24
+ }
16
25
  },
17
26
  })
@@ -1,18 +1,25 @@
1
1
  import { Action } from '@stacksjs/actions'
2
+ import { dashboardOperationalError } from '../dashboard-response'
2
3
  import { functionSourceRows } from './library-source'
3
4
 
4
5
  export default new Action({
5
6
  name: 'GetFunctions',
6
7
  description: 'Gets your utility functions.',
7
8
  method: 'GET',
9
+ apiResponse: true,
8
10
 
9
11
  async handle() {
10
- const functions = functionSourceRows()
12
+ try {
13
+ const functions = functionSourceRows()
11
14
 
12
- return {
13
- functions,
14
- totalBytes: functions.reduce((sum, fn) => sum + fn.bytes, 0),
15
- sourceRoot: 'resources/functions',
15
+ return {
16
+ functions,
17
+ totalBytes: functions.reduce((sum, fn) => sum + fn.bytes, 0),
18
+ sourceRoot: 'resources/functions',
19
+ }
20
+ }
21
+ catch (error) {
22
+ return dashboardOperationalError(error, 'Function library could not be loaded.', 'GetFunctions')
16
23
  }
17
24
  },
18
25
  })
@@ -1,5 +1,6 @@
1
1
  import { Action } from '@stacksjs/actions'
2
2
  import { db } from '@stacksjs/database'
3
+ import { dashboardOperationalError } from '../dashboard-response'
3
4
 
4
5
  export default new Action({
5
6
  name: 'GetReleaseCount',
@@ -7,11 +8,19 @@ export default new Action({
7
8
  apiResponse: true,
8
9
 
9
10
  async handle() {
10
- const row = await db
11
- .selectFrom('releases')
12
- .select(db.fn.count('id').as('count'))
13
- .executeTakeFirst() as { count?: number | string } | undefined
11
+ try {
12
+ const row = await db
13
+ .selectFrom('releases')
14
+ .select(db.fn.count('id').as('count'))
15
+ .executeTakeFirst() as { count?: number | string } | undefined
16
+ const count = Number(row?.count || 0)
17
+ if (!Number.isSafeInteger(count) || count < 0)
18
+ throw new TypeError('Release count must be a non-negative integer.')
14
19
 
15
- return { count: Number(row?.count || 0) }
20
+ return { count }
21
+ }
22
+ catch (error) {
23
+ return dashboardOperationalError(error, 'Release count could not be loaded.', 'GetReleaseCount')
24
+ }
16
25
  },
17
26
  })
@@ -1,23 +1,30 @@
1
1
  import { Action } from '@stacksjs/actions'
2
2
  import { Release } from '@stacksjs/orm'
3
+ import { dashboardOperationalError } from '../dashboard-response'
3
4
 
4
5
  export default new Action({
5
6
  name: 'GetReleases',
6
7
  description: 'Gets your releases.',
7
8
  method: 'GET',
9
+ apiResponse: true,
8
10
 
9
11
  async handle() {
10
- const allReleases = await Release.orderByDesc('id').get()
12
+ try {
13
+ const allReleases = await Release.orderByDesc('id').limit(500).get()
11
14
 
12
- const releases = allReleases.map(r => ({
13
- version: String(r.get('version') || ''),
14
- date: String(r.get('created_at') || r.get('released_at') || ''),
15
- type: String(r.get('type') || 'patch'),
16
- status: String(r.get('status') || 'previous'),
17
- changes: Number(r.get('changes') || r.get('change_count') || 0),
18
- breaking: Boolean(r.get('breaking') || false),
19
- }))
15
+ const releases = allReleases.map(r => ({
16
+ version: String(r.get('version') || ''),
17
+ date: String(r.get('created_at') || r.get('released_at') || ''),
18
+ type: String(r.get('type') || 'patch'),
19
+ status: String(r.get('status') || 'previous'),
20
+ changes: Number(r.get('changes') || r.get('change_count') || 0),
21
+ breaking: Boolean(r.get('breaking') || false),
22
+ }))
20
23
 
21
- return { releases }
24
+ return { releases }
25
+ }
26
+ catch (error) {
27
+ return dashboardOperationalError(error, 'Releases could not be loaded.', 'GetReleases')
28
+ }
22
29
  },
23
30
  })
@@ -1,19 +1,26 @@
1
1
  import { Action } from '@stacksjs/actions'
2
+ import { dashboardOperationalError } from '../dashboard-response'
2
3
  import { workspacePackageRows } from './library-source'
3
4
 
4
5
  export default new Action({
5
6
  name: 'PackageIndexAction',
6
7
  description: 'Returns package data for the dashboard.',
7
8
  method: 'GET',
9
+ apiResponse: true,
8
10
  async handle() {
9
- const packages = workspacePackageRows()
11
+ try {
12
+ const packages = workspacePackageRows()
10
13
 
11
- return {
12
- packages,
13
- publicCount: packages.filter(pkg => !pkg.private).length,
14
- privateCount: packages.filter(pkg => pkg.private).length,
15
- dependencyCount: packages.reduce((sum, pkg) => sum + pkg.dependencyCount, 0),
16
- source: 'bun.lock',
14
+ return {
15
+ packages,
16
+ publicCount: packages.filter(pkg => !pkg.private).length,
17
+ privateCount: packages.filter(pkg => pkg.private).length,
18
+ dependencyCount: packages.reduce((sum, pkg) => sum + pkg.dependencyCount, 0),
19
+ source: 'bun.lock',
20
+ }
21
+ }
22
+ catch (error) {
23
+ return dashboardOperationalError(error, 'Workspace packages could not be loaded.', 'PackageIndexAction')
17
24
  }
18
25
  },
19
26
  })
@@ -1,5 +1,7 @@
1
1
  import type { RequestInstance } from '@stacksjs/types'
2
2
  import { Action } from '@stacksjs/actions'
3
+ import { response } from '@stacksjs/router'
4
+ import { dashboardOperationalError } from '../dashboard-response'
3
5
  import { parseRowId, resolveWritableModel } from './model-write'
4
6
 
5
7
  /**
@@ -17,21 +19,21 @@ export default new Action({
17
19
  async handle(request: RequestInstance) {
18
20
  const resolved = await resolveWritableModel(request.getParam('slug'), 'destroy')
19
21
  if ('error' in resolved)
20
- return { ok: false, error: resolved.error }
22
+ return response.json({ message: resolved.error }, resolved.status)
21
23
 
22
24
  const id = parseRowId(request.getParam('id'))
23
25
  if (id === null)
24
- return { ok: false, error: 'A numeric row id is required.' }
26
+ return response.json({ message: 'A numeric row id is required.' }, 400)
25
27
 
26
28
  try {
27
29
  const row = await resolved.Model.find(id)
28
30
  if (!row)
29
- return { ok: false, error: `${resolved.modelName} ${id} not found.` }
31
+ return response.json({ message: `${resolved.modelName} ${id} not found.` }, 404)
30
32
  await row.delete()
31
33
  return { ok: true, id }
32
34
  }
33
- catch (e) {
34
- return { ok: false, error: e instanceof Error ? e.message : String(e) }
35
+ catch (error) {
36
+ return dashboardOperationalError(error, 'The model record could not be deleted.', 'ModelDestroyAction', 500)
35
37
  }
36
38
  },
37
39
  })