@stacksjs/defaults 0.75.489 → 0.75.492
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-actions/SKILL.md +1 -1
- package/ai/skills/stacks-dashboard/SKILL.md +20 -2
- package/ai/skills/stacks-native/CATALOG.md +9 -9
- package/ai/skills/stacks-search-engine/SKILL.md +14 -0
- package/app/Actions/Dashboard/Commerce/CommerceCategoriesAction.ts +7 -13
- package/app/Actions/Dashboard/Commerce/CommerceCustomerChoicesAction.ts +34 -0
- package/app/Actions/Dashboard/Commerce/CommerceDeliveryAction.ts +7 -16
- package/app/Actions/Dashboard/Commerce/CommerceGiftCardsAction.ts +21 -15
- package/app/Actions/Dashboard/Commerce/CommerceGiftCardsExportAction.ts +41 -0
- package/app/Actions/Dashboard/Commerce/CommerceOrderCustomersAction.ts +37 -0
- package/app/Actions/Dashboard/Commerce/CommerceOrdersAction.ts +26 -41
- package/app/Actions/Dashboard/Commerce/CommerceOrdersExportAction.ts +43 -0
- package/app/Actions/Dashboard/Commerce/CommercePaymentsAction.ts +24 -21
- package/app/Actions/Dashboard/Commerce/CommercePaymentsExportAction.ts +41 -0
- package/app/Actions/Dashboard/Commerce/CommercePosAction.ts +18 -48
- package/app/Actions/Dashboard/Commerce/CommercePosProductsAction.ts +39 -0
- package/app/Actions/Dashboard/Commerce/CommercePrintLogsAction.ts +14 -104
- package/app/Actions/Dashboard/Commerce/CommercePrintLogsExportAction.ts +41 -0
- package/app/Actions/Dashboard/Commerce/CommerceProductChoicesAction.ts +32 -0
- package/app/Actions/Dashboard/Commerce/CommerceProductsAction.ts +24 -43
- package/app/Actions/Dashboard/Commerce/CommerceProductsExportAction.ts +44 -0
- package/app/Actions/Dashboard/Commerce/CourierIndexAction.ts +3 -1
- package/app/Actions/Dashboard/Commerce/DeliveryRouteIndexAction.ts +23 -12
- package/app/Actions/Dashboard/Commerce/DigitalDeliveryIndexAction.ts +3 -1
- package/app/Actions/Dashboard/Commerce/LicenseKeyIndexAction.ts +24 -23
- package/app/Actions/Dashboard/Commerce/LicenseKeyOptionsAction.ts +35 -16
- package/app/Actions/Dashboard/Commerce/ProductUnitIndexAction.ts +23 -19
- package/app/Actions/Dashboard/Commerce/ProductVariantIndexAction.ts +25 -18
- package/app/Actions/Dashboard/Commerce/ProductWaitlistIndexAction.ts +22 -22
- package/app/Actions/Dashboard/Commerce/RestaurantWaitlistIndexAction.ts +22 -17
- package/app/Actions/Dashboard/Commerce/ReviewIndexAction.ts +22 -31
- package/app/Actions/Dashboard/Commerce/ShippingMethodIndexAction.ts +3 -1
- package/app/Actions/Dashboard/Commerce/ShippingRateIndexAction.ts +3 -1
- package/app/Actions/Dashboard/Commerce/ShippingZoneIndexAction.ts +3 -1
- package/app/Actions/Dashboard/Commerce/commerce-category-list.test.ts +100 -0
- package/app/Actions/Dashboard/Commerce/commerce-category-list.ts +26 -0
- package/app/Actions/Dashboard/Commerce/commerce-choice-records.ts +56 -0
- package/app/Actions/Dashboard/Commerce/commerce-choices.test.ts +88 -0
- package/app/Actions/Dashboard/Commerce/commerce-choices.ts +70 -0
- package/app/Actions/Dashboard/Commerce/commerce-delivery-overview.test.ts +151 -0
- package/app/Actions/Dashboard/Commerce/commerce-delivery-overview.ts +85 -0
- package/app/Actions/Dashboard/Commerce/commerce-delivery-route-list.test.ts +153 -0
- package/app/Actions/Dashboard/Commerce/commerce-delivery-route-list.ts +180 -0
- package/app/Actions/Dashboard/Commerce/commerce-delivery.ts +24 -9
- package/app/Actions/Dashboard/Commerce/commerce-gift-card-list.test.ts +221 -0
- package/app/Actions/Dashboard/Commerce/commerce-gift-card-list.ts +259 -0
- package/app/Actions/Dashboard/Commerce/commerce-license-key-list.test.ts +184 -0
- package/app/Actions/Dashboard/Commerce/commerce-license-key-list.ts +217 -0
- package/app/Actions/Dashboard/Commerce/commerce-order-list.test.ts +183 -0
- package/app/Actions/Dashboard/Commerce/commerce-order-list.ts +278 -0
- package/app/Actions/Dashboard/Commerce/commerce-order-records.test.ts +29 -0
- package/app/Actions/Dashboard/Commerce/commerce-payment-list.test.ts +180 -0
- package/app/Actions/Dashboard/Commerce/commerce-payment-list.ts +272 -0
- package/app/Actions/Dashboard/Commerce/commerce-pos-catalog.test.ts +171 -0
- package/app/Actions/Dashboard/Commerce/commerce-pos-catalog.ts +152 -0
- package/app/Actions/Dashboard/Commerce/commerce-pos.test.ts +1 -12
- package/app/Actions/Dashboard/Commerce/commerce-pos.ts +0 -26
- package/app/Actions/Dashboard/Commerce/commerce-print-log-list.test.ts +202 -0
- package/app/Actions/Dashboard/Commerce/commerce-print-log-list.ts +286 -0
- package/app/Actions/Dashboard/Commerce/commerce-product-list.test.ts +174 -0
- package/app/Actions/Dashboard/Commerce/commerce-product-list.ts +276 -0
- package/app/Actions/Dashboard/Commerce/commerce-product-unit-list.test.ts +146 -0
- package/app/Actions/Dashboard/Commerce/commerce-product-unit-list.ts +178 -0
- package/app/Actions/Dashboard/Commerce/commerce-product-variant-list.test.ts +165 -0
- package/app/Actions/Dashboard/Commerce/commerce-product-variant-list.ts +209 -0
- package/app/Actions/Dashboard/Commerce/commerce-product-waitlist-list.test.ts +183 -0
- package/app/Actions/Dashboard/Commerce/commerce-product-waitlist-list.ts +170 -0
- package/app/Actions/Dashboard/Commerce/commerce-record.ts +21 -0
- package/app/Actions/Dashboard/Commerce/commerce-restaurant-waitlist-list.test.ts +189 -0
- package/app/Actions/Dashboard/Commerce/commerce-restaurant-waitlist-list.ts +177 -0
- package/app/Actions/Dashboard/Commerce/commerce-review-list.test.ts +193 -0
- package/app/Actions/Dashboard/Commerce/commerce-review-list.ts +220 -0
- package/app/Actions/Dashboard/Commerce/commerce-sql.ts +57 -0
- package/app/Actions/Dashboard/Commerce/payment-records.test.ts +16 -0
- package/app/Actions/Dashboard/Commerce/product-unit-records.test.ts +0 -13
- package/app/Actions/Dashboard/Commerce/product-unit-records.ts +0 -17
- package/app/Actions/Dashboard/Commerce/product-variant-records.test.ts +0 -13
- package/app/Actions/Dashboard/Commerce/product-variant-records.ts +0 -17
- package/app/Actions/Dashboard/Commerce/product-waitlist-records.test.ts +6 -5
- package/app/Actions/Dashboard/Commerce/product-waitlist-records.ts +16 -45
- package/app/Actions/Dashboard/Commerce/restaurant-waitlist-records.ts +4 -24
- package/app/Actions/Dashboard/Content/content-list.ts +10 -0
- package/app/Actions/Dashboard/Content/file-listing-metadata.test.ts +46 -0
- package/app/Actions/Dashboard/Content/file-manager.ts +51 -10
- package/app/Actions/Dashboard/DashboardHomeAction.test.ts +13 -9
- package/app/Actions/Dashboard/DashboardHomeAction.ts +42 -21
- package/app/Actions/Dashboard/Jobs/JobStatsAction.ts +5 -2
- package/app/Actions/Dashboard/Kanban/UsersListAction.ts +13 -9
- package/app/Actions/Dashboard/Kanban/kanban-response.test.ts +40 -0
- package/app/Actions/Dashboard/Kanban/kanban-response.ts +53 -1
- package/app/Actions/Dashboard/Kanban/kanban-users.test.ts +114 -0
- package/app/Actions/Dashboard/Kanban/kanban-users.ts +32 -0
- package/app/Actions/Dashboard/Models/ModelShowAction.ts +8 -0
- package/app/Actions/Dashboard/Models/ModelsIndexAction.ts +16 -2
- package/app/Actions/Dashboard/Models/model-migration.test.ts +27 -0
- package/app/Actions/Dashboard/Models/model-migration.ts +23 -0
- package/app/Actions/Dashboard/Queue/QueueStatsAction.ts +5 -3
- package/app/Actions/Dashboard/Queue/QueueWorkersAction.ts +3 -2
- package/app/Actions/Dashboard/Queue/worker-snapshots.test.ts +31 -0
- package/app/Actions/Dashboard/Queue/worker-snapshots.ts +33 -0
- package/app/Actions/Dashboard/named-search.test.ts +36 -0
- package/app/Actions/Dashboard/named-search.ts +80 -0
- package/app/Models/Request.ts +4 -2
- package/functions/commerce/shippings/dashboard-resource.ts +12 -1
- package/functions/commerce/shippings/delivery-routes.ts +1 -0
- package/functions/commerce/shippings/license-keys.ts +1 -0
- package/functions/dashboard-list.test.ts +146 -1
- package/functions/dashboard-list.ts +216 -1
- package/functions/queue.ts +2 -0
- package/ide/vscode/package.json +1 -1
- package/package.json +2 -2
- package/resources/components/Dashboard/Commerce/CommerceGiftCardBreakdown.stx +38 -12
- package/resources/components/Dashboard/Commerce/CommerceGiftCardsDashboard.stx +122 -68
- package/resources/components/Dashboard/Commerce/CommerceGiftCardsTable.stx +29 -6
- package/resources/components/Dashboard/Commerce/CommerceOrderDialog.stx +59 -2
- package/resources/components/Dashboard/Commerce/CommerceOrdersDashboard.stx +126 -80
- package/resources/components/Dashboard/Commerce/CommerceOrdersTable.stx +28 -3
- package/resources/components/Dashboard/Commerce/CommercePaymentsBreakdown.stx +12 -29
- package/resources/components/Dashboard/Commerce/CommercePaymentsDashboard.stx +139 -60
- package/resources/components/Dashboard/Commerce/CommercePaymentsTable.stx +27 -2
- package/resources/components/Dashboard/Commerce/CommercePosCatalog.stx +17 -1
- package/resources/components/Dashboard/Commerce/CommercePosCheckoutDialog.stx +47 -3
- package/resources/components/Dashboard/Commerce/CommercePosDashboard.stx +59 -49
- package/resources/components/Dashboard/Commerce/CommerceProductsDashboard.stx +116 -82
- package/resources/components/Dashboard/Commerce/CommerceProductsTable.stx +28 -4
- package/resources/components/Dashboard/Commerce/CommerceReviewsDashboard.stx +120 -69
- package/resources/components/Dashboard/Commerce/CommerceReviewsTable.stx +29 -6
- package/resources/components/Dashboard/Commerce/CommerceUnitDialog.stx +63 -8
- package/resources/components/Dashboard/Commerce/CommerceUnitsDashboard.stx +48 -60
- package/resources/components/Dashboard/Commerce/CommerceUnitsTable.stx +29 -3
- package/resources/components/Dashboard/Commerce/CommerceVariantDialog.stx +57 -3
- package/resources/components/Dashboard/Commerce/CommerceVariantsDashboard.stx +59 -61
- package/resources/components/Dashboard/Commerce/CommerceVariantsTable.stx +28 -2
- package/resources/components/Dashboard/Commerce/Delivery/DeliveryRoutesDashboard.stx +79 -52
- package/resources/components/Dashboard/Commerce/Delivery/DeliveryRoutesTable.stx +31 -8
- package/resources/components/Dashboard/Commerce/Delivery/LicenseKeyDialog.stx +71 -13
- package/resources/components/Dashboard/Commerce/Delivery/LicenseKeysDashboard.stx +69 -81
- package/resources/components/Dashboard/Commerce/Delivery/LicenseKeysTable.stx +31 -8
- package/resources/components/Dashboard/Commerce/PrintLogBreakdown.stx +21 -17
- package/resources/components/Dashboard/Commerce/PrintLogsDashboard.stx +23 -22
- package/resources/components/Dashboard/Commerce/ProductWaitlistDashboard.stx +116 -20
- package/resources/components/Dashboard/Commerce/ProductWaitlistEntryDialog.stx +100 -12
- package/resources/components/Dashboard/Commerce/ProductWaitlistTable.stx +34 -16
- package/resources/components/Dashboard/Commerce/RestaurantWaitlistDashboard.stx +107 -19
- package/resources/components/Dashboard/Commerce/RestaurantWaitlistEntryDialog.stx +65 -6
- package/resources/components/Dashboard/Commerce/RestaurantWaitlistTable.stx +29 -3
- package/resources/components/Dashboard/Kanban/KanbanBoardsDashboard.stx +10 -1
- package/resources/components/Dashboard/Kanban/KanbanCardDialog.stx +21 -1
- package/resources/components/Dashboard/Models/ModelRecordsDashboard.stx +24 -4
- package/resources/components/Dashboard/Models/ModelsOverview.stx +13 -2
- package/resources/components/Dashboard/Queue/QueueDashboard.stx +7 -1
- package/routes/dashboard-api.ts +11 -0
- package/views/dashboard/stores/kanban.ts +38 -6
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { CustomerChoice, ProductChoice } from './commerce-choice-records'
|
|
1
2
|
import {
|
|
2
3
|
commerceEmail,
|
|
3
4
|
commerceEnum,
|
|
@@ -21,6 +22,8 @@ export interface ProductWaitlistRecord {
|
|
|
21
22
|
notes: string
|
|
22
23
|
status: string
|
|
23
24
|
productId: string
|
|
25
|
+
/** The waitlisted product's name, read with the entry. */
|
|
26
|
+
productName: string
|
|
24
27
|
customerId: string
|
|
25
28
|
createdAt: string
|
|
26
29
|
}
|
|
@@ -33,21 +36,11 @@ export interface ProductWaitlistSummary {
|
|
|
33
36
|
conversionRate: number
|
|
34
37
|
}
|
|
35
38
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
label: string
|
|
39
|
-
detail: string
|
|
40
|
-
}
|
|
39
|
+
/** A product the entry dialog offers (commerce-choice-records.ts). */
|
|
40
|
+
export type ProductWaitlistOption = ProductChoice
|
|
41
41
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
phone: string
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export interface ProductWaitlistOptions {
|
|
48
|
-
products: ProductWaitlistOption[]
|
|
49
|
-
customers: ProductWaitlistCustomerOption[]
|
|
50
|
-
}
|
|
42
|
+
/** A customer the entry dialog offers (commerce-choice-records.ts). */
|
|
43
|
+
export type ProductWaitlistCustomerOption = CustomerChoice
|
|
51
44
|
|
|
52
45
|
export interface ProductWaitlistWritePayload {
|
|
53
46
|
productId: number
|
|
@@ -62,9 +55,14 @@ export interface ProductWaitlistWritePayload {
|
|
|
62
55
|
status: 'waiting' | 'notified' | 'purchased' | 'cancelled'
|
|
63
56
|
}
|
|
64
57
|
|
|
58
|
+
/**
|
|
59
|
+
* An entry as the dashboard shows it. `products` maps each product the entry
|
|
60
|
+
* may reference to its name; an entry for any other product is refused, as is
|
|
61
|
+
* one for a customer outside `customerIds`.
|
|
62
|
+
*/
|
|
65
63
|
export function normalizeProductWaitlistRecord(
|
|
66
64
|
record: any,
|
|
67
|
-
|
|
65
|
+
products?: Map<string, string>,
|
|
68
66
|
customerIds?: Set<string>,
|
|
69
67
|
): ProductWaitlistRecord {
|
|
70
68
|
const id = commerceIdentifier(commerceValue(record, 'id', 'uuid'), 'WaitlistProduct')
|
|
@@ -74,7 +72,7 @@ export function normalizeProductWaitlistRecord(
|
|
|
74
72
|
source,
|
|
75
73
|
'product_id',
|
|
76
74
|
)
|
|
77
|
-
if (
|
|
75
|
+
if (products && !products.has(productId))
|
|
78
76
|
throw new TypeError(`${source}.product_id references missing Product ${productId}.`)
|
|
79
77
|
const customerId = commerceOptionalIdentifier(
|
|
80
78
|
commerceValue(record, 'customer_id', 'customerId'),
|
|
@@ -107,40 +105,13 @@ export function normalizeProductWaitlistRecord(
|
|
|
107
105
|
'cancelled',
|
|
108
106
|
]),
|
|
109
107
|
productId,
|
|
108
|
+
productName: products?.get(productId) ?? '',
|
|
110
109
|
customerId,
|
|
111
110
|
createdAt: commerceTimestamp(commerceValue(record, 'created_at', 'createdAt'), source),
|
|
112
111
|
}
|
|
113
112
|
}
|
|
114
113
|
|
|
115
|
-
export
|
|
116
|
-
const id = commerceIdentifier(commerceValue(record, 'id', 'uuid'), 'Product')
|
|
117
|
-
const source = `Product ${id}`
|
|
118
|
-
const inventory = commerceNumber(
|
|
119
|
-
commerceValue(record, 'inventory_count', 'inventoryCount'),
|
|
120
|
-
source,
|
|
121
|
-
'inventory_count',
|
|
122
|
-
{ min: 0, integer: true },
|
|
123
|
-
)
|
|
124
|
-
return {
|
|
125
|
-
id,
|
|
126
|
-
label: commerceRequiredString(commerceValue(record, 'name'), source, 'name'),
|
|
127
|
-
detail: `${inventory} in inventory`,
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
export function normalizeProductWaitlistCustomerOption(record: any): ProductWaitlistCustomerOption {
|
|
132
|
-
const id = commerceIdentifier(commerceValue(record, 'id', 'uuid'), 'Customer')
|
|
133
|
-
const source = `Customer ${id}`
|
|
134
|
-
const email = commerceEmail(commerceValue(record, 'email'), source)
|
|
135
|
-
const phone = commerceOptionalString(commerceValue(record, 'phone'), source, 'phone')
|
|
136
|
-
return {
|
|
137
|
-
id,
|
|
138
|
-
label: commerceRequiredString(commerceValue(record, 'name'), source, 'name'),
|
|
139
|
-
detail: email || phone,
|
|
140
|
-
email,
|
|
141
|
-
phone,
|
|
142
|
-
}
|
|
143
|
-
}
|
|
114
|
+
export { normalizeCustomerChoice as normalizeProductWaitlistCustomerOption, normalizeProductChoice as normalizeProductWaitlistOption } from './commerce-choice-records'
|
|
144
115
|
|
|
145
116
|
export function summarizeProductWaitlist(records: ProductWaitlistRecord[]): ProductWaitlistSummary {
|
|
146
117
|
const waiting = records.filter(record => record.status === 'waiting').length
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { CustomerChoice } from './commerce-choice-records'
|
|
1
2
|
import {
|
|
2
3
|
commerceEmail,
|
|
3
4
|
commerceEnum,
|
|
@@ -37,17 +38,8 @@ export interface RestaurantWaitlistSummary {
|
|
|
37
38
|
seatingRate: number
|
|
38
39
|
}
|
|
39
40
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
label: string
|
|
43
|
-
detail: string
|
|
44
|
-
email: string
|
|
45
|
-
phone: string
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export interface RestaurantWaitlistOptions {
|
|
49
|
-
customers: RestaurantWaitlistCustomerOption[]
|
|
50
|
-
}
|
|
41
|
+
/** A customer the entry dialog offers (commerce-choice-records.ts). */
|
|
42
|
+
export type RestaurantWaitlistCustomerOption = CustomerChoice
|
|
51
43
|
|
|
52
44
|
export interface RestaurantWaitlistWritePayload {
|
|
53
45
|
customerId: number | null
|
|
@@ -151,19 +143,7 @@ export function normalizeRestaurantWaitlistRecord(
|
|
|
151
143
|
}
|
|
152
144
|
}
|
|
153
145
|
|
|
154
|
-
export
|
|
155
|
-
const id = commerceIdentifier(commerceValue(record, 'id', 'uuid'), 'Customer')
|
|
156
|
-
const source = `Customer ${id}`
|
|
157
|
-
const email = commerceEmail(commerceValue(record, 'email'), source)
|
|
158
|
-
const phone = commerceOptionalString(commerceValue(record, 'phone'), source, 'phone')
|
|
159
|
-
return {
|
|
160
|
-
id,
|
|
161
|
-
label: commerceRequiredString(commerceValue(record, 'name'), source, 'name'),
|
|
162
|
-
detail: email || phone,
|
|
163
|
-
email,
|
|
164
|
-
phone,
|
|
165
|
-
}
|
|
166
|
-
}
|
|
146
|
+
export { normalizeCustomerChoice as normalizeRestaurantWaitlistCustomerOption } from './commerce-choice-records'
|
|
167
147
|
|
|
168
148
|
export function summarizeRestaurantWaitlist(records: RestaurantWaitlistRecord[]): RestaurantWaitlistSummary {
|
|
169
149
|
const waitingRecords = records.filter(record => record.status === 'waiting')
|
|
@@ -67,3 +67,13 @@ export function pageWithin(page: number, total: number, perPage: number): number
|
|
|
67
67
|
export function countOf(value: unknown): number {
|
|
68
68
|
return Number(value ?? 0) || 0
|
|
69
69
|
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* A `LIKE` pattern that matches `term` anywhere, ignoring case, with its own
|
|
73
|
+
* `%` and `_` taken literally. Use it with `ESCAPE '!'`: `!` means the same in
|
|
74
|
+
* every dialect, where SQLite has no default escape and MySQL reads a
|
|
75
|
+
* backslash in a string literal as an escape of its own.
|
|
76
|
+
*/
|
|
77
|
+
export function containsPattern(term: string): string {
|
|
78
|
+
return `%${term.toLowerCase().replace(/[!%_]/g, character => `!${character}`)}%`
|
|
79
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { describe, expect, test } from 'bun:test'
|
|
2
|
+
import type { StorageMetadataStore } from './file-metadata'
|
|
3
|
+
import { createMemoryMetadataStore } from './file-metadata'
|
|
4
|
+
import { readListingMetadata } from './file-manager'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The file listing reads the advisory metadata rows (stars, tags, tasks)
|
|
8
|
+
* before building the tree. A missing table must give an empty answer, not a
|
|
9
|
+
* failed listing (stacksjs/stacks#3211); anything else must still fail.
|
|
10
|
+
*/
|
|
11
|
+
function failingStore(error: Error): StorageMetadataStore {
|
|
12
|
+
const store = createMemoryMetadataStore()
|
|
13
|
+
return { ...store, under: async () => { throw error }, tasksUnder: async () => { throw error } }
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
describe('readListingMetadata', () => {
|
|
17
|
+
test('reads the rows when the tables exist', async () => {
|
|
18
|
+
const store = createMemoryMetadataStore()
|
|
19
|
+
await store.write('public', 'a.txt', { favorite: true, tags: [] })
|
|
20
|
+
const read = await readListingMetadata(store, 'public', async () => { throw new Error('the catalog must not be asked') })
|
|
21
|
+
|
|
22
|
+
expect(read.migrated).toBeTrue()
|
|
23
|
+
expect(read.records.get('a.txt')?.favorite).toBeTrue()
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
test('a missing table lists with no stars, tags or tasks', async () => {
|
|
27
|
+
const asked: string[] = []
|
|
28
|
+
const read = await readListingMetadata(failingStore(new Error('relation "storage_items" does not exist')), 'public', async (table) => {
|
|
29
|
+
asked.push(table)
|
|
30
|
+
return table === 'storage_items'
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
expect(read).toEqual({ records: new Map(), tasks: new Map(), migrated: false })
|
|
34
|
+
expect(asked).toEqual(['storage_items'])
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
test('the tasks table missing on its own counts too', async () => {
|
|
38
|
+
const read = await readListingMetadata(failingStore(new Error('no such table: storage_item_tasks')), 'public', async table => table === 'storage_item_tasks')
|
|
39
|
+
expect(read.migrated).toBeFalse()
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
test('any other failure still fails the listing', async () => {
|
|
43
|
+
const outage = new Error('connection refused')
|
|
44
|
+
await expect(readListingMetadata(failingStore(outage), 'public', async () => false)).rejects.toBe(outage)
|
|
45
|
+
})
|
|
46
|
+
})
|
|
@@ -4,7 +4,7 @@ import { posix } from 'node:path'
|
|
|
4
4
|
import type { JobName } from '@stacksjs/queue'
|
|
5
5
|
import type { StorageAdapter, StorageManager, UploadedFileLike, Visibility } from '@stacksjs/storage'
|
|
6
6
|
import { Storage } from '@stacksjs/storage'
|
|
7
|
-
import type { StorageItemTask, StorageMetadataStore, StorageTaskKind, StorageTaskState } from './file-metadata'
|
|
7
|
+
import type { StorageItemMetadata, StorageItemTask, StorageMetadataStore, StorageTaskKind, StorageTaskState } from './file-metadata'
|
|
8
8
|
import {
|
|
9
9
|
aggregateTaskState,
|
|
10
10
|
dispatchTasks,
|
|
@@ -22,6 +22,7 @@ import {
|
|
|
22
22
|
variantsPathFor,
|
|
23
23
|
} from './file-metadata'
|
|
24
24
|
import { databaseMetadataStore } from './file-metadata-store'
|
|
25
|
+
import { isUnmigratedTable } from '../Models/model-migration'
|
|
25
26
|
import { claimedContentType, hasPreview, previewPathFor, previewPlanFor, previewUrlFor } from './file-preview'
|
|
26
27
|
|
|
27
28
|
const DEFAULT_DISK = 'public'
|
|
@@ -330,6 +331,44 @@ export function normalizeDashboardFileLimit(value: unknown): number {
|
|
|
330
331
|
return normalized
|
|
331
332
|
}
|
|
332
333
|
|
|
334
|
+
/** The tables the advisory file metadata lives in (`app/Models/StorageItem.ts`). */
|
|
335
|
+
const METADATA_TABLES = ['storage_items', 'storage_item_tasks'] as const
|
|
336
|
+
|
|
337
|
+
export const METADATA_NOT_MIGRATED = 'Stars, tags and processing status are off until the storage_items tables exist. Run ./buddy migrate to create them.'
|
|
338
|
+
|
|
339
|
+
/**
|
|
340
|
+
* The stars, tags and tasks recorded for a disk, for a listing.
|
|
341
|
+
*
|
|
342
|
+
* The disk is authoritative and these rows are advisory: a path with no row
|
|
343
|
+
* is a file with no stars, the normal case. So an app that has not migrated
|
|
344
|
+
* the metadata tables still gets its files, without stars, tags or tasks, and
|
|
345
|
+
* a warning that names the command. The listing used to fail outright with
|
|
346
|
+
* "Files could not be loaded" (stacksjs/stacks#3211).
|
|
347
|
+
*
|
|
348
|
+
* Only a missing table is treated that way, and the catalog decides it: any
|
|
349
|
+
* other failure is rethrown, so a database outage still fails the listing.
|
|
350
|
+
*/
|
|
351
|
+
export async function readListingMetadata(
|
|
352
|
+
store: StorageMetadataStore,
|
|
353
|
+
disk: string,
|
|
354
|
+
isMissing: (table: string) => Promise<boolean> = isUnmigratedTable,
|
|
355
|
+
): Promise<{ records: Map<string, StorageItemMetadata>, tasks: Map<string, StorageItemTask[]>, migrated: boolean }> {
|
|
356
|
+
try {
|
|
357
|
+
return {
|
|
358
|
+
records: await metadataUnder(store, disk),
|
|
359
|
+
tasks: await store.tasksUnder(disk, ''),
|
|
360
|
+
migrated: true,
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
catch (error) {
|
|
364
|
+
for (const table of METADATA_TABLES) {
|
|
365
|
+
if (await isMissing(table))
|
|
366
|
+
return { records: new Map(), tasks: new Map(), migrated: false }
|
|
367
|
+
}
|
|
368
|
+
throw error
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
|
|
333
372
|
export async function getDashboardFileSnapshot(
|
|
334
373
|
options: { disk?: string, maxEntries?: number } = {},
|
|
335
374
|
manager: Manager = Storage,
|
|
@@ -354,8 +393,7 @@ export async function getDashboardFileSnapshot(
|
|
|
354
393
|
// One query for the whole subtree, not one per file: a folder of a thousand
|
|
355
394
|
// files would otherwise be a thousand round trips to answer a question about
|
|
356
395
|
// the handful of them anybody starred (stacksjs/stacks#2577).
|
|
357
|
-
const records = await
|
|
358
|
-
const tasks = await store.tasksUnder(selected.name, '')
|
|
396
|
+
const { records, tasks, migrated: metadataMigrated } = await readListingMetadata(store, selected.name)
|
|
359
397
|
|
|
360
398
|
const stated = await mapInBatches(
|
|
361
399
|
entries,
|
|
@@ -509,13 +547,15 @@ export async function getDashboardFileSnapshot(
|
|
|
509
547
|
// this takes the flag: a truncated walk has not shown that a path is absent,
|
|
510
548
|
// only that it stopped before reaching it, and sweeping on that would delete
|
|
511
549
|
// the metadata of every file past the limit (stacksjs/stacks#2577).
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
550
|
+
if (metadataMigrated) {
|
|
551
|
+
await sweepMetadata(
|
|
552
|
+
store,
|
|
553
|
+
selected.name,
|
|
554
|
+
'',
|
|
555
|
+
new Set(stated.map(entry => entry.path)),
|
|
556
|
+
{ truncated },
|
|
557
|
+
)
|
|
558
|
+
}
|
|
519
559
|
|
|
520
560
|
return {
|
|
521
561
|
disk: selected.name,
|
|
@@ -528,6 +568,7 @@ export async function getDashboardFileSnapshot(
|
|
|
528
568
|
truncated,
|
|
529
569
|
warnings: [
|
|
530
570
|
...(capacity.warning ? [capacity.warning] : []),
|
|
571
|
+
...(metadataMigrated ? [] : [METADATA_NOT_MIGRATED]),
|
|
531
572
|
...stated.flatMap(entry => entry.warnings),
|
|
532
573
|
],
|
|
533
574
|
}
|
|
@@ -2,19 +2,23 @@ import { describe, expect, it } from 'bun:test'
|
|
|
2
2
|
import { homeStats, orderActivityStatus, serializeHealthCheck, settleEach, summarizeHttpRequests } from './DashboardHomeAction'
|
|
3
3
|
|
|
4
4
|
describe('dashboard HTTP metrics', () => {
|
|
5
|
-
it('summarizes captured
|
|
6
|
-
const metrics = summarizeHttpRequests(12_345,
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
it('summarizes every captured request, as the database counted them', () => {
|
|
6
|
+
const metrics = summarizeHttpRequests({ total: 12_345, successful: 9_876, failed: 2_469, averageDuration: 24.6 })
|
|
7
|
+
|
|
8
|
+
expect(metrics.map(metric => metric.value)).toEqual(['12,345', '25ms', '80.0%', '20.0%'])
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
it('takes the rates over all requests, not a sample, and says so', () => {
|
|
12
|
+
// A request with no recorded status is neither a success nor a failure,
|
|
13
|
+
// so the two rates need not add up to 100%.
|
|
14
|
+
const metrics = summarizeHttpRequests({ total: 4, successful: 2, failed: 1, averageDuration: 10 })
|
|
12
15
|
|
|
13
|
-
expect(metrics.map(metric => metric.value)).toEqual(['
|
|
16
|
+
expect(metrics.map(metric => metric.value)).toEqual(['4', '10ms', '50.0%', '25.0%'])
|
|
17
|
+
expect(metrics[1]?.detail).toBe('All captured requests')
|
|
14
18
|
})
|
|
15
19
|
|
|
16
20
|
it('returns explicit empty-state metrics', () => {
|
|
17
|
-
expect(summarizeHttpRequests(0,
|
|
21
|
+
expect(summarizeHttpRequests({ total: 0, successful: 0, failed: 0, averageDuration: 0 }).map(metric => metric.value)).toEqual(['0', '0ms', 'N/A', 'N/A'])
|
|
18
22
|
})
|
|
19
23
|
|
|
20
24
|
it('serializes only probed service health', () => {
|
|
@@ -5,23 +5,35 @@ import { checkApplicationHealth, type ApplicationHealthCheck } from '@stacksjs/r
|
|
|
5
5
|
import { formatRelative, safeGet } from '../../../resources/functions/dashboard/data'
|
|
6
6
|
import { dashboardOperationalIssue } from './dashboard-response'
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
/** Totals over every captured request, counted by the database. */
|
|
9
|
+
export interface HttpRequestTotals {
|
|
10
|
+
total: number
|
|
11
|
+
/** 2xx and 3xx responses. */
|
|
12
|
+
successful: number
|
|
13
|
+
/** 4xx and 5xx responses. */
|
|
14
|
+
failed: number
|
|
15
|
+
/** Mean `duration_ms`, or 0 with no requests. */
|
|
16
|
+
averageDuration: number
|
|
11
17
|
}
|
|
12
18
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
+
/**
|
|
20
|
+
* The Home page's request cards, over all captured requests.
|
|
21
|
+
*
|
|
22
|
+
* The rates and the average used to come from the newest 1,000 rows, fetched
|
|
23
|
+
* whole on every visit and averaged here, while the cards beside them said
|
|
24
|
+
* "All captured requests" and the Requests page counted every row. So the two
|
|
25
|
+
* pages disagreed, and the rates' labels did not say they were a sample. Every
|
|
26
|
+
* card now reads the same totals the Requests page does.
|
|
27
|
+
*/
|
|
28
|
+
export function summarizeHttpRequests(totals: HttpRequestTotals) {
|
|
29
|
+
const { total, successful, failed } = totals
|
|
30
|
+
const rate = (count: number) => total > 0 ? `${((count / total) * 100).toFixed(1)}%` : 'N/A'
|
|
19
31
|
|
|
20
32
|
return [
|
|
21
33
|
{ title: 'HTTP Requests', value: total.toLocaleString(), detail: 'All captured requests', icon: 'i-hugeicons-global' },
|
|
22
|
-
{ title: 'Average Response', value: `${averageDuration}ms`, detail:
|
|
23
|
-
{ title: 'Success Rate', value:
|
|
24
|
-
{ title: 'Error Rate', value:
|
|
34
|
+
{ title: 'Average Response', value: `${Math.round(totals.averageDuration)}ms`, detail: 'All captured requests', icon: 'i-hugeicons-clock-01' },
|
|
35
|
+
{ title: 'Success Rate', value: rate(successful), detail: '2xx and 3xx responses', icon: 'i-hugeicons-checkmark-circle-02' },
|
|
36
|
+
{ title: 'Error Rate', value: rate(failed), detail: '4xx and 5xx responses', icon: 'i-hugeicons-alert-02' },
|
|
25
37
|
]
|
|
26
38
|
}
|
|
27
39
|
|
|
@@ -105,7 +117,9 @@ export default new Action({
|
|
|
105
117
|
recentOrders,
|
|
106
118
|
recentUsers,
|
|
107
119
|
requestCount,
|
|
108
|
-
|
|
120
|
+
successfulRequests,
|
|
121
|
+
failedRequests,
|
|
122
|
+
averageDuration,
|
|
109
123
|
] = await settleEach([
|
|
110
124
|
() => User.count(),
|
|
111
125
|
commerce ? () => Product.count() : none,
|
|
@@ -114,18 +128,23 @@ export default new Action({
|
|
|
114
128
|
commerce ? () => Order.orderBy('created_at', 'desc').limit(5).get() : async () => [],
|
|
115
129
|
() => User.orderBy('created_at', 'desc').limit(5).get(),
|
|
116
130
|
() => Request.count(),
|
|
117
|
-
() => Request.
|
|
131
|
+
() => Request.where('status_code', '>=', 200).where('status_code', '<', 400).count(),
|
|
132
|
+
() => Request.where('status_code', '>=', 400).count(),
|
|
133
|
+
() => Request.avg('duration_ms'),
|
|
118
134
|
] as const)
|
|
119
135
|
const healthResult = await Promise.allSettled([checkApplicationHealth()])
|
|
120
136
|
|
|
121
137
|
const stats = homeStats({ users: userCount, products: productCount, revenue: totalRevenue, orders: orderCount }, commerce)
|
|
122
138
|
|
|
123
|
-
const httpMetrics = requestCount.status === 'fulfilled' &&
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
139
|
+
const httpMetrics = requestCount.status === 'fulfilled' && successfulRequests.status === 'fulfilled'
|
|
140
|
+
&& failedRequests.status === 'fulfilled' && averageDuration.status === 'fulfilled'
|
|
141
|
+
? summarizeHttpRequests({
|
|
142
|
+
total: Number(requestCount.value) || 0,
|
|
143
|
+
successful: Number(successfulRequests.value) || 0,
|
|
144
|
+
failed: Number(failedRequests.value) || 0,
|
|
145
|
+
averageDuration: Number(averageDuration.value) || 0,
|
|
146
|
+
})
|
|
147
|
+
: summarizeHttpRequests({ total: 0, successful: 0, failed: 0, averageDuration: 0 })
|
|
129
148
|
|
|
130
149
|
const health = healthResult[0]
|
|
131
150
|
const services = health.status === 'fulfilled'
|
|
@@ -177,7 +196,9 @@ export default new Action({
|
|
|
177
196
|
['Recent orders', recentOrders],
|
|
178
197
|
['Recent users', recentUsers],
|
|
179
198
|
['Request count', requestCount],
|
|
180
|
-
['
|
|
199
|
+
['Successful requests', successfulRequests],
|
|
200
|
+
['Failed requests', failedRequests],
|
|
201
|
+
['Average response', averageDuration],
|
|
181
202
|
]
|
|
182
203
|
const issues = sources
|
|
183
204
|
.map(([source, result]) => issue(source, result))
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Action } from '@stacksjs/actions/runtime'
|
|
2
2
|
import { FailedJob, Job } from '@stacksjs/orm'
|
|
3
|
-
import { aggregateWorkerMetrics
|
|
3
|
+
import { aggregateWorkerMetrics } from '@stacksjs/queue'
|
|
4
4
|
import { dashboardOperationalError } from '../dashboard-response'
|
|
5
|
+
import { readDashboardWorkerSnapshots } from '../Queue/worker-snapshots'
|
|
5
6
|
|
|
6
7
|
export default new Action({
|
|
7
8
|
name: 'JobStatsAction',
|
|
@@ -14,7 +15,8 @@ export default new Action({
|
|
|
14
15
|
FailedJob.count(),
|
|
15
16
|
])
|
|
16
17
|
|
|
17
|
-
const
|
|
18
|
+
const workers = await readDashboardWorkerSnapshots()
|
|
19
|
+
const metrics = aggregateWorkerMetrics(workers.snapshots)
|
|
18
20
|
const completedSeen = metrics.counts.completed
|
|
19
21
|
const failedSeen = metrics.counts.failed
|
|
20
22
|
const totalSeen = completedSeen + failedSeen
|
|
@@ -31,6 +33,7 @@ export default new Action({
|
|
|
31
33
|
avgProcessingTime,
|
|
32
34
|
jobsPerMinute: metrics.throughputPerMinute,
|
|
33
35
|
failureRate,
|
|
36
|
+
workersMigrated: workers.migrated,
|
|
34
37
|
// The composable doesn't render a chart, so we omit the synthetic
|
|
35
38
|
// throughput/waitTime arrays the previous handler returned. If you
|
|
36
39
|
// need historical data, persist completion events and serve them
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
+
import type { RequestInstance } from '@stacksjs/types'
|
|
1
2
|
import { Action } from '@stacksjs/actions/runtime'
|
|
2
|
-
import {
|
|
3
|
+
import { response } from '@stacksjs/router'
|
|
3
4
|
import { kanbanActionError } from './kanban-response'
|
|
5
|
+
import { parseKanbanUserQuery, readKanbanUsers } from './kanban-users'
|
|
4
6
|
|
|
5
7
|
/**
|
|
6
8
|
* `GET /api/dashboard/kanban/users`.
|
|
7
9
|
*
|
|
8
|
-
*
|
|
10
|
+
* Searchable user list for the assignee picker on the card detail
|
|
9
11
|
* modal. Returns `{ id, name, email }` only — no roles, no profile,
|
|
10
12
|
* no avatars. The modal renders initials from `name`, so anything
|
|
11
13
|
* heavier would be wasted bytes.
|
|
@@ -20,14 +22,16 @@ export default new Action({
|
|
|
20
22
|
description: 'Lightweight user list for the kanban assignee picker.',
|
|
21
23
|
method: 'GET',
|
|
22
24
|
apiResponse: true,
|
|
23
|
-
async handle() {
|
|
25
|
+
async handle(request: RequestInstance) {
|
|
26
|
+
const query = parseKanbanUserQuery(key => request.get<unknown>(key, ''))
|
|
27
|
+
if ('error' in query)
|
|
28
|
+
return response.json({ message: query.error }, 422)
|
|
29
|
+
|
|
24
30
|
try {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
return {
|
|
29
|
-
users: (rows ?? []).map(r => ({ id: r.id, name: r.name, email: r.email })),
|
|
30
|
-
}
|
|
31
|
+
// `?q=` searches name and email; `limit` bounds the answer, and `total`
|
|
32
|
+
// says how many matched (kanban-users.ts).
|
|
33
|
+
const { users, total } = await readKanbanUsers(query)
|
|
34
|
+
return { users, total, limit: query.limit }
|
|
31
35
|
}
|
|
32
36
|
catch (err) {
|
|
33
37
|
return kanbanActionError(err, 'UsersListAction')
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { describe, expect, test } from 'bun:test'
|
|
2
|
+
import { KANBAN_TABLES, kanbanActionError, kanbanNotMigratedMessage, missingKanbanTables } from './kanban-response'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A Kanban action that fails on a database without its tables says which
|
|
6
|
+
* tables and the command that creates them, instead of a generic 500
|
|
7
|
+
* (stacksjs/stacks#3217). Anything else keeps the generic answer, with no
|
|
8
|
+
* database error text in it.
|
|
9
|
+
*/
|
|
10
|
+
describe('kanbanActionError', () => {
|
|
11
|
+
test('missing tables answer 503 naming them and ./buddy migrate', async () => {
|
|
12
|
+
const reply = await kanbanActionError(new Error('relation "card_assignees" does not exist'), 'BoardShowAction', async () => ['card_labels', 'card_assignees'])
|
|
13
|
+
expect(reply.status).toBe(503)
|
|
14
|
+
const body = await reply.json() as { error: string, missingTables: string[] }
|
|
15
|
+
expect(body.missingTables).toEqual(['card_labels', 'card_assignees'])
|
|
16
|
+
expect(body.error).toBe('Kanban is not set up yet: the card_labels and card_assignees tables do not exist. Run ./buddy migrate to create them.')
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
test('with every table present it is the generic 500, and the error text stays out', async () => {
|
|
20
|
+
const reply = await kanbanActionError(new Error('deadlock detected on cards'), 'CardUpdateAction', async () => [])
|
|
21
|
+
expect(reply.status).toBe(500)
|
|
22
|
+
const body = await reply.json() as { error: string }
|
|
23
|
+
expect(body.error).toBe('The Kanban request could not be completed.')
|
|
24
|
+
expect(JSON.stringify(body)).not.toContain('deadlock')
|
|
25
|
+
})
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
describe('missingKanbanTables', () => {
|
|
29
|
+
test('asks about every Kanban table and keeps their order', async () => {
|
|
30
|
+
const asked: string[] = []
|
|
31
|
+
const missing = await missingKanbanTables(async (table) => { asked.push(table); return table.startsWith('card_') })
|
|
32
|
+
expect(asked).toEqual([...KANBAN_TABLES])
|
|
33
|
+
expect(missing).toEqual(['card_labels', 'card_assignees', 'card_comments', 'card_attachments'])
|
|
34
|
+
})
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
test('the message reads naturally for one table and for several', () => {
|
|
38
|
+
expect(kanbanNotMigratedMessage(['boards'])).toBe('Kanban is not set up yet: the boards table does not exist. Run ./buddy migrate to create them.')
|
|
39
|
+
expect(kanbanNotMigratedMessage(['a', 'b', 'c'])).toBe('Kanban is not set up yet: the a, b and c tables do not exist. Run ./buddy migrate to create them.')
|
|
40
|
+
})
|
|
@@ -1,11 +1,63 @@
|
|
|
1
1
|
import type { ResponseStatus } from '@stacksjs/bun-router'
|
|
2
2
|
import { response } from '@stacksjs/router'
|
|
3
|
+
import { isUnmigratedTable } from '../Models/model-migration'
|
|
3
4
|
|
|
4
5
|
export function kanbanError(error: string, status: ResponseStatus): Response {
|
|
5
6
|
return response.json({ error }, status)
|
|
6
7
|
}
|
|
7
8
|
|
|
8
|
-
|
|
9
|
+
/**
|
|
10
|
+
* Every table a Kanban board reads or writes. All of them are the dashboard
|
|
11
|
+
* feature's, so one `./buddy migrate` creates the lot. `card_labels` and
|
|
12
|
+
* `card_assignees` are pivots with no model of their own.
|
|
13
|
+
*/
|
|
14
|
+
export const KANBAN_TABLES = [
|
|
15
|
+
'boards',
|
|
16
|
+
'board_columns',
|
|
17
|
+
'cards',
|
|
18
|
+
'labels',
|
|
19
|
+
'card_labels',
|
|
20
|
+
'card_assignees',
|
|
21
|
+
'card_comments',
|
|
22
|
+
'card_attachments',
|
|
23
|
+
'feedback_tokens',
|
|
24
|
+
] as const
|
|
25
|
+
|
|
26
|
+
/** The Kanban tables the catalog says are missing, in `KANBAN_TABLES` order. */
|
|
27
|
+
export async function missingKanbanTables(isMissing: (table: string) => Promise<boolean> = isUnmigratedTable): Promise<string[]> {
|
|
28
|
+
const missing: string[] = []
|
|
29
|
+
for (const table of KANBAN_TABLES) {
|
|
30
|
+
if (await isMissing(table))
|
|
31
|
+
missing.push(table)
|
|
32
|
+
}
|
|
33
|
+
return missing
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function kanbanNotMigratedMessage(tables: string[]): string {
|
|
37
|
+
const list = tables.length === 1 ? `the ${tables[0]} table does not` : `the ${tables.slice(0, -1).join(', ')} and ${tables.at(-1)} tables do not`
|
|
38
|
+
return `Kanban is not set up yet: ${list} exist. Run ./buddy migrate to create them.`
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* The response for a Kanban action that failed.
|
|
43
|
+
*
|
|
44
|
+
* Asked only after a failure: if the catalog reports Kanban tables missing, the
|
|
45
|
+
* answer names them and the command, with status 503, because nothing is wrong
|
|
46
|
+
* that a migration does not fix. A board could be created and then neither
|
|
47
|
+
* opened nor deleted, each saying only "could not be completed"
|
|
48
|
+
* (stacksjs/stacks#3217). Any other failure, including a catalog check that
|
|
49
|
+
* fails too, is logged and answered with the generic 500, so an outage is never
|
|
50
|
+
* relabelled as a migrate hint and no database error text reaches the page.
|
|
51
|
+
*/
|
|
52
|
+
export async function kanbanActionError(
|
|
53
|
+
error: unknown,
|
|
54
|
+
action: string,
|
|
55
|
+
missing: () => Promise<string[]> = missingKanbanTables,
|
|
56
|
+
): Promise<Response> {
|
|
57
|
+
const tables = await missing()
|
|
58
|
+
if (tables.length > 0)
|
|
59
|
+
return response.json({ error: kanbanNotMigratedMessage(tables), missingTables: tables }, 503)
|
|
60
|
+
|
|
9
61
|
console.error(`[dashboard/kanban] ${action} failed:`, error)
|
|
10
62
|
return kanbanError('The Kanban request could not be completed.', 500)
|
|
11
63
|
}
|