@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
@@ -2,6 +2,7 @@ import type { RequestInstance } from '@stacksjs/types'
2
2
  import { Action } from '@stacksjs/actions'
3
3
  import { db } from '@stacksjs/database'
4
4
  import { response } from '@stacksjs/router'
5
+ import { dashboardOperationalError } from '../dashboard-response'
5
6
  import { dashboardRequestValue } from '../dashboard-request'
6
7
  import {
7
8
  type NotificationDeliveryRow,
@@ -30,13 +31,15 @@ export default new Action({
30
31
  method: 'GET',
31
32
  apiResponse: true,
32
33
  async handle(request: RequestInstance) {
33
- const page = Math.max(1, Number.parseInt(queryValue(request, 'page') || '1', 10) || 1)
34
+ const page = Math.min(1_000_000, Math.max(1, Number.parseInt(queryValue(request, 'page') || '1', 10) || 1))
34
35
  const perPage = Math.min(100, Math.max(1, Number.parseInt(queryValue(request, 'per_page') || '20', 10) || 20))
35
36
  const channel = allowedValue(queryValue(request, 'channel').toLowerCase(), CHANNELS)
36
37
  const status = allowedValue(queryValue(request, 'status').toLowerCase(), STATUSES)
37
38
  const sort = allowedValue(queryValue(request, 'sort').toLowerCase(), SORTS) || 'sent_at'
38
39
  const direction = queryValue(request, 'direction').toLowerCase() === 'asc' ? 'asc' : 'desc'
39
40
  const search = queryValue(request, 'search')
41
+ if (search.length > 200)
42
+ return response.json({ message: 'Notification delivery search must be 200 characters or fewer.' }, 422)
40
43
  const searchPattern = `%${search}%`
41
44
 
42
45
  const applyFilters = <T extends {
@@ -58,42 +61,49 @@ export default new Action({
58
61
  return filtered
59
62
  }
60
63
 
61
- const countQuery = applyFilters(
62
- db
63
- .selectFrom('notification_deliveries')
64
- .select(db.fn.count('id').as('count')),
65
- )
66
- const rowsQuery = applyFilters(
67
- db
68
- .selectFrom('notification_deliveries')
69
- .selectAll(),
70
- )
64
+ try {
65
+ const countQuery = applyFilters(
66
+ db
67
+ .selectFrom('notification_deliveries')
68
+ .select(db.fn.count('id').as('count')),
69
+ )
70
+ const rowsQuery = applyFilters(
71
+ db
72
+ .selectFrom('notification_deliveries')
73
+ .selectAll(),
74
+ )
71
75
 
72
- const [countRow, rows] = await Promise.all([
73
- countQuery.executeTakeFirst() as Promise<{ count: number | string } | undefined>,
74
- rowsQuery
75
- .orderBy(sort as DeliverySort, direction)
76
- .limit(perPage)
77
- .offset((page - 1) * perPage)
78
- .execute() as Promise<NotificationDeliveryRow[]>,
79
- ])
76
+ const [countRow, rows] = await Promise.all([
77
+ countQuery.executeTakeFirst() as Promise<{ count: number | string } | undefined>,
78
+ rowsQuery
79
+ .orderBy(sort as DeliverySort, direction)
80
+ .limit(perPage)
81
+ .offset((page - 1) * perPage)
82
+ .execute() as Promise<NotificationDeliveryRow[]>,
83
+ ])
80
84
 
81
- const total = Number(countRow?.count || 0)
82
- return response.json({
83
- deliveries: rows.map(serializeNotificationDelivery),
84
- pagination: {
85
- page,
86
- per_page: perPage,
87
- total,
88
- total_pages: Math.max(1, Math.ceil(total / perPage)),
89
- },
90
- filters: {
91
- channel: channel as DeliveryChannel | null,
92
- status: status as DeliveryStatus | null,
93
- search,
94
- sort,
95
- direction,
96
- },
97
- })
85
+ const total = Number(countRow?.count || 0)
86
+ if (!Number.isSafeInteger(total) || total < 0)
87
+ throw new TypeError('Notification delivery count must be a non-negative integer.')
88
+ return response.json({
89
+ deliveries: rows.map(serializeNotificationDelivery),
90
+ pagination: {
91
+ page,
92
+ per_page: perPage,
93
+ total,
94
+ total_pages: Math.max(1, Math.ceil(total / perPage)),
95
+ },
96
+ filters: {
97
+ channel: channel as DeliveryChannel | null,
98
+ status: status as DeliveryStatus | null,
99
+ search,
100
+ sort,
101
+ direction,
102
+ },
103
+ })
104
+ }
105
+ catch (error) {
106
+ return dashboardOperationalError(error, 'Notification delivery history could not be loaded.', 'NotificationDeliveryHistoryAction')
107
+ }
98
108
  },
99
109
  })
@@ -2,6 +2,7 @@ import type { RequestInstance } from '@stacksjs/types'
2
2
  import { Action } from '@stacksjs/actions'
3
3
  import { NotificationDelivery } from '@stacksjs/orm'
4
4
  import { response } from '@stacksjs/router'
5
+ import { dashboardOperationalError } from '../dashboard-response'
5
6
  import { dashboardRequestValue } from '../dashboard-request'
6
7
  import { parseDeliveryMetadata } from './notification-delivery'
7
8
 
@@ -37,9 +38,14 @@ export default new Action({
37
38
  if (!channel)
38
39
  return response.json({ message: 'Channel must be email or sms.' }, 422)
39
40
 
40
- const records = await NotificationDelivery.where('channel', '=', channel).get()
41
- const deliveries = records
42
- .map(record => ({
41
+ try {
42
+ const records = await NotificationDelivery
43
+ .where('channel', '=', channel)
44
+ .orderByDesc('sent_at')
45
+ .orderByDesc('created_at')
46
+ .limit(500)
47
+ .get()
48
+ const deliveries = records.map(record => ({
43
49
  id: Number(record.get('id')),
44
50
  user_id: record.get('user_id') ? Number(record.get('user_id')) : null,
45
51
  channel,
@@ -55,9 +61,11 @@ export default new Action({
55
61
  sent_at: String(record.get('sent_at') || record.get('created_at') || ''),
56
62
  created_at: String(record.get('created_at') || ''),
57
63
  }))
58
- .sort((a, b) => new Date(b.sent_at).getTime() - new Date(a.sent_at).getTime())
59
- .slice(0, 500)
60
64
 
61
- return response.json(deliveries)
65
+ return response.json(deliveries)
66
+ }
67
+ catch (error) {
68
+ return dashboardOperationalError(error, 'Notification deliveries could not be loaded.', 'NotificationDeliveryIndexAction')
69
+ }
62
70
  },
63
71
  })
@@ -1,6 +1,7 @@
1
1
  import { Action } from '@stacksjs/actions'
2
2
  import { db } from '@stacksjs/database'
3
3
  import { response } from '@stacksjs/router'
4
+ import { dashboardOperationalError } from '../dashboard-response'
4
5
  import {
5
6
  type NotificationDeliveryRow,
6
7
  serializeNotificationDelivery,
@@ -22,99 +23,110 @@ const DELIVERY_STATUSES = ['sent', 'delivered', 'failed', 'pending'] as const
22
23
 
23
24
  function numericCount(value: number | string | undefined): number {
24
25
  const count = Number(value || 0)
25
- return Number.isFinite(count) ? count : 0
26
+ if (!Number.isSafeInteger(count) || count < 0)
27
+ throw new TypeError('Notification delivery count must be a non-negative integer.')
28
+ return count
26
29
  }
27
30
 
28
- export default new Action({
29
- name: 'Notification Delivery Overview',
30
- description: 'Returns aggregate transport health and recent notification delivery attempts.',
31
- method: 'GET',
32
- apiResponse: true,
33
- async handle() {
34
- const [totalRow, statusRows, channelRows, recentRows] = await Promise.all([
35
- db
36
- .selectFrom('notification_deliveries')
37
- .select(db.fn.count('id').as('count'))
38
- .executeTakeFirst() as Promise<CountRow | undefined>,
39
- db
40
- .selectFrom('notification_deliveries')
41
- .select(['status', db.fn.count('id').as('count')])
42
- .groupBy('status')
43
- .execute() as Promise<StatusCountRow[]>,
44
- db
45
- .selectFrom('notification_deliveries')
46
- .select(['channel', 'status', db.fn.count('id').as('count')])
47
- .groupBy(['channel', 'status'])
48
- .execute() as Promise<ChannelStatusCountRow[]>,
49
- db
50
- .selectFrom('notification_deliveries')
51
- .selectAll()
52
- .orderBy('sent_at', 'desc')
53
- .limit(8)
54
- .execute() as Promise<NotificationDeliveryRow[]>,
55
- ])
31
+ async function notificationDeliveryOverview() {
32
+ const [totalRow, statusRows, channelRows, recentRows] = await Promise.all([
33
+ db
34
+ .selectFrom('notification_deliveries')
35
+ .select(db.fn.count('id').as('count'))
36
+ .executeTakeFirst() as Promise<CountRow | undefined>,
37
+ db
38
+ .selectFrom('notification_deliveries')
39
+ .select(['status', db.fn.count('id').as('count')])
40
+ .groupBy('status')
41
+ .execute() as Promise<StatusCountRow[]>,
42
+ db
43
+ .selectFrom('notification_deliveries')
44
+ .select(['channel', 'status', db.fn.count('id').as('count')])
45
+ .groupBy(['channel', 'status'])
46
+ .execute() as Promise<ChannelStatusCountRow[]>,
47
+ db
48
+ .selectFrom('notification_deliveries')
49
+ .selectAll()
50
+ .orderBy('sent_at', 'desc')
51
+ .limit(8)
52
+ .execute() as Promise<NotificationDeliveryRow[]>,
53
+ ])
56
54
 
57
- const statuses = Object.fromEntries(
58
- DELIVERY_STATUSES.map(status => [status, 0]),
59
- ) as Record<typeof DELIVERY_STATUSES[number], number>
55
+ const statuses = Object.fromEntries(
56
+ DELIVERY_STATUSES.map(status => [status, 0]),
57
+ ) as Record<typeof DELIVERY_STATUSES[number], number>
60
58
 
61
- for (const row of statusRows) {
62
- if (DELIVERY_STATUSES.includes(row.status as typeof DELIVERY_STATUSES[number]))
63
- statuses[row.status as typeof DELIVERY_STATUSES[number]] = numericCount(row.count)
64
- }
59
+ for (const row of statusRows) {
60
+ if (DELIVERY_STATUSES.includes(row.status as typeof DELIVERY_STATUSES[number]))
61
+ statuses[row.status as typeof DELIVERY_STATUSES[number]] = numericCount(row.count)
62
+ }
65
63
 
66
- const channelMap = new Map<string, {
67
- channel: string
68
- total: number
69
- sent: number
70
- delivered: number
71
- failed: number
72
- pending: number
73
- }>()
64
+ const channelMap = new Map<string, {
65
+ channel: string
66
+ total: number
67
+ sent: number
68
+ delivered: number
69
+ failed: number
70
+ pending: number
71
+ }>()
74
72
 
75
- for (const row of channelRows) {
76
- const channel = String(row.channel || 'unknown')
77
- const entry = channelMap.get(channel) || {
78
- channel,
79
- total: 0,
80
- sent: 0,
81
- delivered: 0,
82
- failed: 0,
83
- pending: 0,
84
- }
85
- const count = numericCount(row.count)
86
- entry.total += count
87
- if (DELIVERY_STATUSES.includes(row.status as typeof DELIVERY_STATUSES[number]))
88
- entry[row.status as typeof DELIVERY_STATUSES[number]] += count
89
- channelMap.set(channel, entry)
73
+ for (const row of channelRows) {
74
+ const channel = String(row.channel || 'unknown')
75
+ const entry = channelMap.get(channel) || {
76
+ channel,
77
+ total: 0,
78
+ sent: 0,
79
+ delivered: 0,
80
+ failed: 0,
81
+ pending: 0,
90
82
  }
83
+ const count = numericCount(row.count)
84
+ entry.total += count
85
+ if (DELIVERY_STATUSES.includes(row.status as typeof DELIVERY_STATUSES[number]))
86
+ entry[row.status as typeof DELIVERY_STATUSES[number]] += count
87
+ channelMap.set(channel, entry)
88
+ }
91
89
 
92
- const channels = [...channelMap.values()]
93
- .map(channel => ({
94
- ...channel,
95
- success_rate: channel.total > 0
96
- ? Number((((channel.sent + channel.delivered) / channel.total) * 100).toFixed(1))
97
- : 0,
98
- }))
99
- .sort((a, b) => b.total - a.total || a.channel.localeCompare(b.channel))
90
+ const channels = [...channelMap.values()]
91
+ .map(channel => ({
92
+ ...channel,
93
+ success_rate: channel.total > 0
94
+ ? Number((((channel.sent + channel.delivered) / channel.total) * 100).toFixed(1))
95
+ : 0,
96
+ }))
97
+ .sort((a, b) => b.total - a.total || a.channel.localeCompare(b.channel))
100
98
 
101
- const total = numericCount(totalRow?.count)
102
- const successful = statuses.sent + statuses.delivered
99
+ const total = numericCount(totalRow?.count)
100
+ const successful = statuses.sent + statuses.delivered
101
+
102
+ return {
103
+ stats: {
104
+ total,
105
+ successful,
106
+ failed: statuses.failed,
107
+ pending: statuses.pending,
108
+ success_rate: total > 0
109
+ ? Number(((successful / total) * 100).toFixed(1))
110
+ : 0,
111
+ active_channels: channels.length,
112
+ },
113
+ statuses,
114
+ channels,
115
+ recent: recentRows.map(serializeNotificationDelivery),
116
+ }
117
+ }
103
118
 
104
- return response.json({
105
- stats: {
106
- total,
107
- successful,
108
- failed: statuses.failed,
109
- pending: statuses.pending,
110
- success_rate: total > 0
111
- ? Number(((successful / total) * 100).toFixed(1))
112
- : 0,
113
- active_channels: channels.length,
114
- },
115
- statuses,
116
- channels,
117
- recent: recentRows.map(serializeNotificationDelivery),
118
- })
119
+ export default new Action({
120
+ name: 'Notification Delivery Overview',
121
+ description: 'Returns aggregate transport health and recent notification delivery attempts.',
122
+ method: 'GET',
123
+ apiResponse: true,
124
+ async handle() {
125
+ try {
126
+ return response.json(await notificationDeliveryOverview())
127
+ }
128
+ catch (error) {
129
+ return dashboardOperationalError(error, 'Notification delivery overview could not be loaded.', 'NotificationDeliveryOverviewAction')
130
+ }
119
131
  },
120
132
  })
@@ -4,6 +4,7 @@ import { Action } from '@stacksjs/actions'
4
4
  import { notify } from '@stacksjs/notifications'
5
5
  import { NotificationDelivery } from '@stacksjs/orm'
6
6
  import { response } from '@stacksjs/router'
7
+ import { dashboardOperationalError } from '../dashboard-response'
7
8
  import { parseDeliveryMetadata } from './notification-delivery'
8
9
 
9
10
  type RetryChannel = 'email' | 'sms'
@@ -19,10 +20,16 @@ export default new Action({
19
20
  apiResponse: true,
20
21
  async handle(request: RequestInstance) {
21
22
  const id = Number(request.getParam('id'))
22
- if (!Number.isFinite(id) || id <= 0)
23
- return response.json({ message: 'A valid delivery ID is required.' }, 422)
23
+ if (!Number.isSafeInteger(id) || id <= 0)
24
+ return response.json({ message: 'A valid delivery ID is required.' }, 400)
24
25
 
25
- const delivery = await NotificationDelivery.find(id)
26
+ let delivery: Awaited<ReturnType<typeof NotificationDelivery.find>>
27
+ try {
28
+ delivery = await NotificationDelivery.find(id)
29
+ }
30
+ catch (error) {
31
+ return dashboardOperationalError(error, 'Notification delivery could not be loaded.', 'NotificationDeliveryRetryAction.lookup')
32
+ }
26
33
  if (!delivery)
27
34
  return response.json({ message: 'Notification delivery not found.' }, 404)
28
35
 
@@ -34,27 +41,33 @@ export default new Action({
34
41
  if (!recipientValue)
35
42
  return response.json({ message: 'The original delivery has no recipient.' }, 422)
36
43
 
37
- const channels: NotificationChannel[] = [channel]
38
- const results = await notify(
39
- {
40
- userId: delivery.get('user_id') ? Number(delivery.get('user_id')) : undefined,
41
- ...(channel === 'email' ? { email: recipientValue } : { phone: recipientValue }),
42
- },
43
- {
44
- subject: String(delivery.get('subject') || ''),
45
- body: String(delivery.get('body') || ''),
46
- data: parseDeliveryMetadata(
47
- delivery.get('metadata'),
48
- `notification delivery ${id} metadata`,
49
- ),
50
- },
51
- channels,
52
- { ignorePreferences: true },
53
- )
44
+ let results: Awaited<ReturnType<typeof notify>>
45
+ try {
46
+ const channels: NotificationChannel[] = [channel]
47
+ results = await notify(
48
+ {
49
+ userId: delivery.get('user_id') ? Number(delivery.get('user_id')) : undefined,
50
+ ...(channel === 'email' ? { email: recipientValue } : { phone: recipientValue }),
51
+ },
52
+ {
53
+ subject: String(delivery.get('subject') || ''),
54
+ body: String(delivery.get('body') || ''),
55
+ data: parseDeliveryMetadata(
56
+ delivery.get('metadata'),
57
+ `notification delivery ${id} metadata`,
58
+ ),
59
+ },
60
+ channels,
61
+ { ignorePreferences: true },
62
+ )
63
+ }
64
+ catch (error) {
65
+ return dashboardOperationalError(error, 'The notification retry could not be completed.', 'NotificationDeliveryRetryAction.provider', 502)
66
+ }
54
67
 
55
68
  const result = results[0]
56
69
  if (!result?.success)
57
- return response.json({ message: result?.error?.message || 'The retry failed.' }, 502)
70
+ return dashboardOperationalError(result?.error, 'The notification retry failed.', 'NotificationDeliveryRetryAction.result', 502)
58
71
 
59
72
  return response.json({ success: true })
60
73
  },
@@ -1,7 +1,7 @@
1
1
  import { Action } from '@stacksjs/actions'
2
2
  import { config } from '@stacksjs/config'
3
3
  import { db } from '@stacksjs/database'
4
- import { response } from '@stacksjs/router'
4
+ import { dashboardOperationalError } from '../dashboard-response'
5
5
  import { dashboardQueryColumns, mapDashboardQueryLog, type QueryLogSourceRow } from './query-dashboard'
6
6
 
7
7
  export default new Action({
@@ -27,9 +27,7 @@ export default new Action({
27
27
  }
28
28
  }
29
29
  catch (error) {
30
- return response.json({
31
- message: error instanceof Error ? error.message : 'Query logs could not be loaded.',
32
- }, 503)
30
+ return dashboardOperationalError(error, 'Query logs could not be loaded.', 'QueryDashboardAction')
33
31
  }
34
32
  },
35
33
  })
@@ -2,6 +2,7 @@ import type { RequestInstance } from '@stacksjs/types'
2
2
  import { Action } from '@stacksjs/actions'
3
3
  import { db } from '@stacksjs/database'
4
4
  import { response } from '@stacksjs/router'
5
+ import { dashboardOperationalError } from '../dashboard-response'
5
6
  import { dashboardQueryColumns, mapDashboardQueryLog, type QueryLogSourceRow } from './query-dashboard'
6
7
 
7
8
  export default new Action({
@@ -28,9 +29,7 @@ export default new Action({
28
29
  return { query: mapDashboardQueryLog(row as QueryLogSourceRow) }
29
30
  }
30
31
  catch (error) {
31
- return response.json({
32
- message: error instanceof Error ? error.message : 'Query log could not be loaded.',
33
- }, 503)
32
+ return dashboardOperationalError(error, 'Query log could not be loaded.', 'QueryShowAction')
34
33
  }
35
34
  },
36
35
  })
@@ -1,7 +1,7 @@
1
1
  import { Action } from '@stacksjs/actions'
2
2
  import { FailedJob, Job } from '@stacksjs/orm'
3
3
  import { getGlobalMetrics } from '@stacksjs/queue'
4
- import { response } from '@stacksjs/router'
4
+ import { dashboardOperationalError } from '../dashboard-response'
5
5
 
6
6
  interface QueueBucket {
7
7
  pending: number
@@ -81,9 +81,7 @@ export default new Action({
81
81
  return { queues, stats, queueConnected: true }
82
82
  }
83
83
  catch (error) {
84
- return response.json({
85
- message: error instanceof Error ? error.message : 'Queue statistics could not be loaded.',
86
- }, 503)
84
+ return dashboardOperationalError(error, 'Queue statistics could not be loaded.', 'QueueStatsAction')
87
85
  }
88
86
  },
89
87
  })
@@ -1,6 +1,6 @@
1
1
  import { Action } from '@stacksjs/actions'
2
2
  import { getActiveJobCount, getWorkerTracker, isWorkerRunning } from '@stacksjs/queue'
3
- import { response } from '@stacksjs/router'
3
+ import { dashboardOperationalError } from '../dashboard-response'
4
4
 
5
5
  export default new Action({
6
6
  name: 'QueueWorkersAction',
@@ -41,9 +41,7 @@ export default new Action({
41
41
  }
42
42
  }
43
43
  catch (error) {
44
- return response.json({
45
- message: error instanceof Error ? error.message : 'Queue workers could not be loaded.',
46
- }, 503)
44
+ return dashboardOperationalError(error, 'Queue workers could not be loaded.', 'QueueWorkersAction')
47
45
  }
48
46
  },
49
47
  })
@@ -2,6 +2,7 @@ import type { RequestInstance } from '@stacksjs/types'
2
2
  import { Action } from '@stacksjs/actions'
3
3
  import { deletePermission } from '@stacksjs/auth'
4
4
  import { response } from '@stacksjs/router'
5
+ import { rbacActionError } from './rbac-response'
5
6
 
6
7
  /**
7
8
  * `DELETE /api/dashboard/rbac/permissions/:name` (stacksjs/stacks#1845).
@@ -30,8 +31,7 @@ export default new Action({
30
31
  return { deleted: true, name, guardName }
31
32
  }
32
33
  catch (err) {
33
- console.error('[dashboard/rbac] PermissionDestroyAction failed:', err)
34
- return response.json({ error: err instanceof Error ? err.message : 'unknown error' }, 500)
34
+ return rbacActionError(err, 'The permission could not be deleted.', 'PermissionDestroyAction')
35
35
  }
36
36
  },
37
37
  })
@@ -2,6 +2,7 @@ import type { RequestInstance } from '@stacksjs/types'
2
2
  import { Action } from '@stacksjs/actions'
3
3
  import { createPermission, findPermission } from '@stacksjs/auth'
4
4
  import { response } from '@stacksjs/router'
5
+ import { rbacActionError } from './rbac-response'
5
6
 
6
7
  interface PermissionInput {
7
8
  name?: unknown
@@ -54,8 +55,7 @@ export default new Action({
54
55
  }
55
56
  }
56
57
  catch (err) {
57
- console.error('[dashboard/rbac] PermissionStoreAction failed:', err)
58
- return response.json({ error: err instanceof Error ? err.message : 'unknown error' }, 500)
58
+ return rbacActionError(err, 'The permission could not be created.', 'PermissionStoreAction')
59
59
  }
60
60
  },
61
61
  })
@@ -1,6 +1,6 @@
1
1
  import { Action } from '@stacksjs/actions'
2
2
  import { getAllPermissions } from '@stacksjs/auth'
3
- import { response } from '@stacksjs/router'
3
+ import { rbacActionError } from './rbac-response'
4
4
 
5
5
  /**
6
6
  * `GET /api/dashboard/rbac/permissions` (stacksjs/stacks#1845).
@@ -28,8 +28,7 @@ export default new Action({
28
28
  }
29
29
  }
30
30
  catch (err) {
31
- console.error('[dashboard/rbac] PermissionsIndexAction failed:', err)
32
- return response.json({ permissions: [], error: err instanceof Error ? err.message : 'unknown error' }, 500)
31
+ return rbacActionError(err, 'Permissions could not be loaded.', 'PermissionsIndexAction')
33
32
  }
34
33
  },
35
34
  })
@@ -2,6 +2,7 @@ import type { RequestInstance } from '@stacksjs/types'
2
2
  import { Action } from '@stacksjs/actions'
3
3
  import { deleteRole } from '@stacksjs/auth'
4
4
  import { response } from '@stacksjs/router'
5
+ import { rbacActionError } from './rbac-response'
5
6
 
6
7
  /**
7
8
  * `DELETE /api/dashboard/rbac/roles/:name` (stacksjs/stacks#1845).
@@ -32,8 +33,7 @@ export default new Action({
32
33
  return { deleted: true, name, guardName }
33
34
  }
34
35
  catch (err) {
35
- console.error('[dashboard/rbac] RoleDestroyAction failed:', err)
36
- return response.json({ error: err instanceof Error ? err.message : 'unknown error' }, 500)
36
+ return rbacActionError(err, 'The role could not be deleted.', 'RoleDestroyAction')
37
37
  }
38
38
  },
39
39
  })
@@ -2,6 +2,7 @@ import type { RequestInstance } from '@stacksjs/types'
2
2
  import { Action } from '@stacksjs/actions'
3
3
  import { findRole, getRolePermissions } from '@stacksjs/auth'
4
4
  import { response } from '@stacksjs/router'
5
+ import { rbacActionError } from './rbac-response'
5
6
 
6
7
  /**
7
8
  * `GET /api/dashboard/rbac/roles/:name/permissions` (stacksjs/stacks#1845).
@@ -42,8 +43,7 @@ export default new Action({
42
43
  }
43
44
  }
44
45
  catch (err) {
45
- console.error('[dashboard/rbac] RolePermissionsShowAction failed:', err)
46
- return response.json({ permissions: [], error: err instanceof Error ? err.message : 'unknown error' }, 500)
46
+ return rbacActionError(err, 'Role permissions could not be loaded.', 'RolePermissionsShowAction')
47
47
  }
48
48
  },
49
49
  })
@@ -2,6 +2,7 @@ import type { RequestInstance } from '@stacksjs/types'
2
2
  import { Action } from '@stacksjs/actions'
3
3
  import { getRolePermissions, findRole, syncRolePermissions } from '@stacksjs/auth'
4
4
  import { response } from '@stacksjs/router'
5
+ import { rbacActionError } from './rbac-response'
5
6
 
6
7
  interface SyncInput {
7
8
  permissions?: unknown
@@ -57,12 +58,7 @@ export default new Action({
57
58
  }
58
59
  }
59
60
  catch (err) {
60
- const msg = err instanceof Error ? err.message : 'unknown error'
61
- if (msg.includes('not found')) {
62
- return response.json({ error: msg }, 400)
63
- }
64
- console.error('[dashboard/rbac] RolePermissionsSyncAction failed:', err)
65
- return response.json({ error: msg }, 500)
61
+ return rbacActionError(err, 'Role permissions could not be updated.', 'RolePermissionsSyncAction')
66
62
  }
67
63
  },
68
64
  })
@@ -2,6 +2,7 @@ import type { RequestInstance } from '@stacksjs/types'
2
2
  import { Action } from '@stacksjs/actions'
3
3
  import { createRole, findRole } from '@stacksjs/auth'
4
4
  import { response } from '@stacksjs/router'
5
+ import { rbacActionError } from './rbac-response'
5
6
 
6
7
  interface RoleInput {
7
8
  name?: unknown
@@ -59,8 +60,7 @@ export default new Action({
59
60
  }
60
61
  }
61
62
  catch (err) {
62
- console.error('[dashboard/rbac] RoleStoreAction failed:', err)
63
- return response.json({ error: err instanceof Error ? err.message : 'unknown error' }, 500)
63
+ return rbacActionError(err, 'The role could not be created.', 'RoleStoreAction')
64
64
  }
65
65
  },
66
66
  })