@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.
- package/ai/skills/stacks-email/SKILL.md +38 -1
- package/app/Actions/ContactAction.ts +2 -2
- package/app/Actions/Dashboard/Analytics/EventAnalyticsAction.ts +2 -3
- package/app/Actions/Dashboard/Analytics/MarketingAnalyticsAction.ts +2 -3
- package/app/Actions/Dashboard/Analytics/SalesAnalyticsAction.ts +2 -3
- package/app/Actions/Dashboard/Analytics/WebAnalyticsAction.ts +9 -3
- package/app/Actions/Dashboard/Auth/MeAction.ts +4 -7
- package/app/Actions/Dashboard/Buddy/BuddyChatAction.ts +2 -3
- package/app/Actions/Dashboard/Cloud/CloudIndexAction.ts +8 -1
- package/app/Actions/Dashboard/Cloud/ServerlessIndexAction.ts +15 -8
- package/app/Actions/Dashboard/Commerce/CommerceCategoriesAction.ts +2 -4
- package/app/Actions/Dashboard/Commerce/CommerceCouponsAction.ts +2 -4
- package/app/Actions/Dashboard/Commerce/CommerceCustomersAction.ts +2 -4
- package/app/Actions/Dashboard/Commerce/CommerceDashboardAction.ts +2 -4
- package/app/Actions/Dashboard/Commerce/CommerceDeliveryAction.ts +2 -4
- package/app/Actions/Dashboard/Commerce/CommerceGiftCardsAction.ts +2 -4
- package/app/Actions/Dashboard/Commerce/CommerceOrdersAction.ts +2 -4
- package/app/Actions/Dashboard/Commerce/CommercePaymentsAction.ts +2 -4
- package/app/Actions/Dashboard/Commerce/CommercePosAction.ts +2 -4
- package/app/Actions/Dashboard/Commerce/CommercePosCheckoutAction.ts +75 -61
- package/app/Actions/Dashboard/Commerce/CommercePrintDevicesAction.ts +2 -4
- package/app/Actions/Dashboard/Commerce/CommercePrintLogsAction.ts +2 -4
- package/app/Actions/Dashboard/Commerce/CommerceProductDetailAction.ts +3 -4
- package/app/Actions/Dashboard/Commerce/CommerceProductsAction.ts +2 -4
- package/app/Actions/Dashboard/Commerce/CommerceTaxesAction.ts +2 -4
- package/app/Actions/Dashboard/Commerce/DeliveryRouteIndexAction.ts +2 -4
- package/app/Actions/Dashboard/Commerce/DigitalDeliveryIndexAction.ts +2 -4
- package/app/Actions/Dashboard/Commerce/DriverIndexAction.ts +2 -4
- package/app/Actions/Dashboard/Commerce/LicenseKeyIndexAction.ts +2 -4
- package/app/Actions/Dashboard/Commerce/LicenseKeyOptionsAction.ts +2 -4
- package/app/Actions/Dashboard/Commerce/ManufacturerIndexAction.ts +2 -4
- package/app/Actions/Dashboard/Commerce/ProductUnitIndexAction.ts +2 -4
- package/app/Actions/Dashboard/Commerce/ProductVariantIndexAction.ts +2 -4
- package/app/Actions/Dashboard/Commerce/ProductWaitlistIndexAction.ts +2 -4
- package/app/Actions/Dashboard/Commerce/RestaurantWaitlistIndexAction.ts +2 -4
- package/app/Actions/Dashboard/Commerce/ReviewIndexAction.ts +2 -4
- package/app/Actions/Dashboard/Commerce/ShippingMethodIndexAction.ts +2 -4
- package/app/Actions/Dashboard/Commerce/ShippingRateIndexAction.ts +2 -4
- package/app/Actions/Dashboard/Commerce/ShippingZoneIndexAction.ts +2 -4
- package/app/Actions/Dashboard/DashboardActivityAction.ts +2 -5
- package/app/Actions/Dashboard/Data/ActivityIndexAction.ts +2 -5
- package/app/Actions/Dashboard/Data/SubscriberIndexAction.ts +2 -5
- package/app/Actions/Dashboard/Data/TeamIndexAction.ts +2 -5
- package/app/Actions/Dashboard/Data/UserIndexAction.ts +2 -5
- package/app/Actions/Dashboard/Deployments/CreateDeployment.ts +23 -19
- package/app/Actions/Dashboard/Deployments/GetAverageDeploymentTime.ts +8 -2
- package/app/Actions/Dashboard/Deployments/GetDeployScript.ts +3 -6
- package/app/Actions/Dashboard/Deployments/GetDeployment.ts +4 -5
- package/app/Actions/Dashboard/Deployments/GetDeploymentCount.ts +7 -1
- package/app/Actions/Dashboard/Deployments/GetDeploymentLiveTerminalOutput.ts +10 -9
- package/app/Actions/Dashboard/Deployments/GetDeployments.ts +2 -4
- package/app/Actions/Dashboard/Deployments/GetRecentDeployments.ts +8 -2
- package/app/Actions/Dashboard/Deployments/UpdateDeployScript.ts +18 -5
- package/app/Actions/Dashboard/Email/CapturedMailIndexAction.ts +2 -4
- package/app/Actions/Dashboard/Email/CapturedMailShowAction.ts +3 -4
- package/app/Actions/Dashboard/Infrastructure/InsightsAction.ts +15 -14
- package/app/Actions/Dashboard/Infrastructure/LogIndexAction.ts +2 -8
- package/app/Actions/Dashboard/Jobs/JobIndexAction.ts +2 -4
- package/app/Actions/Dashboard/Jobs/JobShowAction.ts +13 -8
- package/app/Actions/Dashboard/Jobs/JobStatsAction.ts +2 -4
- package/app/Actions/Dashboard/Kanban/BoardDestroyAction.ts +2 -3
- package/app/Actions/Dashboard/Kanban/BoardShowAction.ts +2 -3
- package/app/Actions/Dashboard/Kanban/BoardStoreAction.ts +2 -3
- package/app/Actions/Dashboard/Kanban/BoardUpdateAction.ts +2 -3
- package/app/Actions/Dashboard/Kanban/BoardsIndexAction.ts +2 -3
- package/app/Actions/Dashboard/Kanban/BoardsReorderAction.ts +2 -3
- package/app/Actions/Dashboard/Kanban/CardAssigneesSyncAction.ts +2 -3
- package/app/Actions/Dashboard/Kanban/CardCommentDestroyAction.ts +2 -3
- package/app/Actions/Dashboard/Kanban/CardCommentStoreAction.ts +2 -3
- package/app/Actions/Dashboard/Kanban/CardCommentUpdateAction.ts +2 -3
- package/app/Actions/Dashboard/Kanban/CardDestroyAction.ts +2 -3
- package/app/Actions/Dashboard/Kanban/CardLabelsSyncAction.ts +2 -3
- package/app/Actions/Dashboard/Kanban/CardShowAction.ts +2 -3
- package/app/Actions/Dashboard/Kanban/CardStoreAction.ts +2 -3
- package/app/Actions/Dashboard/Kanban/CardUpdateAction.ts +2 -3
- package/app/Actions/Dashboard/Kanban/CardsReorderAction.ts +2 -3
- package/app/Actions/Dashboard/Kanban/ColumnDestroyAction.ts +2 -3
- package/app/Actions/Dashboard/Kanban/ColumnStoreAction.ts +2 -3
- package/app/Actions/Dashboard/Kanban/ColumnUpdateAction.ts +2 -3
- package/app/Actions/Dashboard/Kanban/ColumnsReorderAction.ts +2 -3
- package/app/Actions/Dashboard/Kanban/LabelDestroyAction.ts +2 -3
- package/app/Actions/Dashboard/Kanban/LabelStoreAction.ts +2 -3
- package/app/Actions/Dashboard/Kanban/LabelUpdateAction.ts +2 -3
- package/app/Actions/Dashboard/Kanban/UsersListAction.ts +2 -3
- package/app/Actions/Dashboard/Kanban/kanban-response.ts +5 -0
- package/app/Actions/Dashboard/Library/CreateComponent.ts +15 -6
- package/app/Actions/Dashboard/Library/CreateFunction.ts +15 -6
- package/app/Actions/Dashboard/Library/DependencyIndexAction.ts +88 -77
- package/app/Actions/Dashboard/Library/GetAverageReleaseTime.ts +21 -15
- package/app/Actions/Dashboard/Library/GetComponents.ts +14 -7
- package/app/Actions/Dashboard/Library/GetDownloadCount.ts +14 -5
- package/app/Actions/Dashboard/Library/GetFunctions.ts +12 -5
- package/app/Actions/Dashboard/Library/GetReleaseCount.ts +14 -5
- package/app/Actions/Dashboard/Library/GetReleases.ts +17 -10
- package/app/Actions/Dashboard/Library/PackageIndexAction.ts +14 -7
- package/app/Actions/Dashboard/Models/ModelDestroyAction.ts +7 -5
- package/app/Actions/Dashboard/Models/ModelShowAction.ts +82 -174
- package/app/Actions/Dashboard/Models/ModelStoreAction.ts +6 -4
- package/app/Actions/Dashboard/Models/ModelUpdateAction.ts +9 -7
- package/app/Actions/Dashboard/Models/ModelsIndexAction.ts +47 -17
- package/app/Actions/Dashboard/Models/model-write.ts +20 -5
- package/app/Actions/Dashboard/Notifications/NotificationDeliveryHistoryAction.ts +46 -36
- package/app/Actions/Dashboard/Notifications/NotificationDeliveryIndexAction.ts +14 -6
- package/app/Actions/Dashboard/Notifications/NotificationDeliveryOverviewAction.ts +96 -84
- package/app/Actions/Dashboard/Notifications/NotificationDeliveryRetryAction.ts +34 -21
- package/app/Actions/Dashboard/Queries/QueryDashboardAction.ts +2 -4
- package/app/Actions/Dashboard/Queries/QueryShowAction.ts +2 -3
- package/app/Actions/Dashboard/Queue/QueueStatsAction.ts +2 -4
- package/app/Actions/Dashboard/Queue/QueueWorkersAction.ts +2 -4
- package/app/Actions/Dashboard/Rbac/PermissionDestroyAction.ts +2 -2
- package/app/Actions/Dashboard/Rbac/PermissionStoreAction.ts +2 -2
- package/app/Actions/Dashboard/Rbac/PermissionsIndexAction.ts +2 -3
- package/app/Actions/Dashboard/Rbac/RoleDestroyAction.ts +2 -2
- package/app/Actions/Dashboard/Rbac/RolePermissionsShowAction.ts +2 -2
- package/app/Actions/Dashboard/Rbac/RolePermissionsSyncAction.ts +2 -6
- package/app/Actions/Dashboard/Rbac/RoleStoreAction.ts +2 -2
- package/app/Actions/Dashboard/Rbac/RolesIndexAction.ts +4 -6
- package/app/Actions/Dashboard/Rbac/UserRolesShowAction.ts +2 -2
- package/app/Actions/Dashboard/Rbac/UserRolesSyncAction.ts +2 -9
- package/app/Actions/Dashboard/Rbac/UsersListAction.ts +2 -3
- package/app/Actions/Dashboard/Rbac/rbac-response.ts +10 -0
- package/app/Actions/Dashboard/Realtime/RealtimeStatsAction.ts +2 -4
- package/app/Actions/Dashboard/Search/GlobalSearchAction.ts +68 -55
- package/app/Actions/Dashboard/Teams/TeamInvitationDestroyAction.ts +34 -16
- package/app/Actions/Dashboard/Teams/TeamInvitationResendAction.ts +52 -29
- package/app/Actions/Dashboard/Teams/TeamInviteAction.ts +102 -71
- package/app/Actions/Dashboard/Teams/TeamMemberDestroyAction.ts +36 -17
- package/app/Actions/Dashboard/Teams/TeamMemberUpdateAction.ts +39 -26
- package/app/Actions/Dashboard/Teams/TeamPeopleIndexAction.ts +71 -58
- package/app/Actions/Dashboard/Teams/team-invitation-delivery.ts +29 -7
- package/app/Actions/Dashboard/Teams/team-member-count.ts +4 -2
- package/app/Actions/Dashboard/Teams/team-records.test.ts +2 -0
- package/app/Actions/Dashboard/Teams/team-records.ts +2 -0
- package/app/Actions/Dashboard/dashboard-response.ts +16 -0
- package/app/Actions/SendWelcomeEmail.ts +1 -1
- package/app/Actions/Teams/AcceptInvitationAction.ts +74 -51
- package/app/Actions/Teams/ShowInvitationAction.ts +21 -14
- package/app/Actions/Teams/team-response.ts +23 -0
- package/app/Mail/OrderConfirmation.ts +1 -1
- package/app/Mail/SubscriptionConfirmation.ts +1 -1
- package/app/Mail/TeamInvitation.ts +1 -1
- package/app/Models/EmailIdempotency.ts +64 -0
- package/app/Models/EmailSuppression.ts +52 -0
- package/app/Models/EmailWebhookEvent.ts +51 -0
- package/app/Models/TeamInvitation.ts +13 -0
- package/functions/data.ts +0 -1
- package/functions/jobs.ts +0 -1
- package/ide/vscode/package.json +1 -1
- package/package.json +1 -1
- package/resources/components/Dashboard/Data/DataRecords.stx +0 -4
- package/resources/components/Dashboard/Jobs/JobDetail.stx +3 -2
- package/resources/components/Dashboard/Models/ModelRecordsDashboard.stx +7 -13
- package/resources/components/Dashboard/Models/ModelsOverview.stx +1 -1
- package/views/dashboard/.discovered-models.json +30 -0
- 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
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
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
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
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
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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
|
-
|
|
58
|
-
|
|
59
|
-
|
|
55
|
+
const statuses = Object.fromEntries(
|
|
56
|
+
DELIVERY_STATUSES.map(status => [status, 0]),
|
|
57
|
+
) as Record<typeof DELIVERY_STATUSES[number], number>
|
|
60
58
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
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
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
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
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
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
|
-
|
|
102
|
-
|
|
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
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
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.
|
|
23
|
-
return response.json({ message: 'A valid delivery ID is required.' },
|
|
23
|
+
if (!Number.isSafeInteger(id) || id <= 0)
|
|
24
|
+
return response.json({ message: 'A valid delivery ID is required.' }, 400)
|
|
24
25
|
|
|
25
|
-
|
|
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
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
delivery.get('
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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
|
|
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 {
|
|
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
|
|
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
|
|
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 {
|
|
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
|
|
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 {
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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 {
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
})
|