@stacksjs/defaults 0.75.489 → 0.75.490
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/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-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-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 +132 -1
- package/functions/dashboard-list.ts +198 -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/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
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { RequestInstance } from '@stacksjs/types'
|
|
2
|
+
import { Action } from '@stacksjs/actions/runtime'
|
|
3
|
+
import { response } from '@stacksjs/router'
|
|
4
|
+
import { dashboardOperationalError } from '../dashboard-response'
|
|
5
|
+
import { parsePaymentListQuery, readPaymentsForExport } from './commerce-payment-list'
|
|
6
|
+
import { paymentsToCsv } from './payment-records'
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* `GET /api/dashboard/commerce/payments/export` - every payment matching the
|
|
10
|
+
* Payments page's search, filters, time range and sort, as CSV
|
|
11
|
+
* (stacksjs/stacks#3218). The page built the file from the newest 500.
|
|
12
|
+
*/
|
|
13
|
+
export default new Action({
|
|
14
|
+
name: 'CommercePaymentsExportAction',
|
|
15
|
+
description: 'Exports every payment matching the Payments page filters as CSV.',
|
|
16
|
+
method: 'GET',
|
|
17
|
+
apiResponse: false,
|
|
18
|
+
|
|
19
|
+
async handle(request: RequestInstance) {
|
|
20
|
+
const query = parsePaymentListQuery(key => request.get<unknown>(key, ''))
|
|
21
|
+
if ('error' in query)
|
|
22
|
+
return response.json({ message: query.error }, 422)
|
|
23
|
+
|
|
24
|
+
try {
|
|
25
|
+
const csv = `${paymentsToCsv(await readPaymentsForExport(query))}`
|
|
26
|
+
const day = new Date().toISOString().slice(0, 10)
|
|
27
|
+
return new Response(csv, {
|
|
28
|
+
status: 200,
|
|
29
|
+
headers: {
|
|
30
|
+
'Cache-Control': 'private, no-store',
|
|
31
|
+
'Content-Disposition': `attachment; filename="payments-${day}.csv"`,
|
|
32
|
+
'Content-Type': 'text/csv; charset=utf-8',
|
|
33
|
+
'X-Content-Type-Options': 'nosniff',
|
|
34
|
+
},
|
|
35
|
+
})
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
return dashboardOperationalError(error, 'Payments could not be exported.', 'CommercePaymentsExportAction')
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
})
|
|
@@ -1,65 +1,35 @@
|
|
|
1
1
|
import { Action } from '@stacksjs/actions/runtime'
|
|
2
2
|
import { config } from '@stacksjs/config'
|
|
3
|
-
import { Category, Customer, Manufacturer, Product, TaxRate } from '@stacksjs/orm'
|
|
4
3
|
import { dashboardOperationalError } from '../dashboard-response'
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
normalizeCommercePosCustomer,
|
|
8
|
-
normalizeCommercePosProduct,
|
|
9
|
-
selectCommercePosTaxRate,
|
|
10
|
-
} from './commerce-pos'
|
|
11
|
-
import {
|
|
12
|
-
normalizeCommerceProductRecord,
|
|
13
|
-
normalizeCommerceCurrency,
|
|
14
|
-
normalizeManufacturerOption,
|
|
15
|
-
normalizeProductOption,
|
|
16
|
-
} from './commerce-product-records'
|
|
4
|
+
import { readPosSettings } from './commerce-pos-catalog'
|
|
5
|
+
import { normalizeCommerceCurrency } from './commerce-product-records'
|
|
17
6
|
|
|
7
|
+
/**
|
|
8
|
+
* `GET /api/dashboard/commerce/pos` - the point of sale's settings: the
|
|
9
|
+
* categories in use, the tax rate, the currency, the payment methods and the
|
|
10
|
+
* catalogue summary, counted over every product (commerce-pos-catalog.ts,
|
|
11
|
+
* stacksjs/stacks#3218).
|
|
12
|
+
*
|
|
13
|
+
* The catalogue itself is GET /commerce/pos/products, searched and paged, and
|
|
14
|
+
* the checkout searches customers through GET /commerce/customer-choices.
|
|
15
|
+
* This used to send the first 500 products, categories, manufacturers,
|
|
16
|
+
* customers and tax rates.
|
|
17
|
+
*/
|
|
18
18
|
export default new Action({
|
|
19
19
|
name: 'CommercePosAction',
|
|
20
|
-
description: 'Returns
|
|
20
|
+
description: 'Returns the native point of sale settings and catalogue summary.',
|
|
21
21
|
method: 'GET',
|
|
22
22
|
apiResponse: true,
|
|
23
23
|
|
|
24
24
|
async handle() {
|
|
25
25
|
try {
|
|
26
|
-
const
|
|
27
|
-
Product.orderBy('name', 'asc').limit(500).get(),
|
|
28
|
-
Category.orderBy('name', 'asc').limit(500).get(),
|
|
29
|
-
Manufacturer.orderBy('manufacturer', 'asc').limit(500).get(),
|
|
30
|
-
Customer.orderBy('name', 'asc').limit(500).get(),
|
|
31
|
-
TaxRate.orderBy('id', 'asc').limit(500).get(),
|
|
32
|
-
])
|
|
33
|
-
const categoryOptions = categories.map(normalizeProductOption)
|
|
34
|
-
const manufacturerOptions = manufacturers.map(normalizeManufacturerOption)
|
|
35
|
-
const categoryMap = new Map(categoryOptions.map(option => [option.id, option.label]))
|
|
36
|
-
const manufacturerMap = new Map(manufacturerOptions.map(option => [option.id, option.label]))
|
|
37
|
-
const emptyCounts = new Map<string, number>()
|
|
38
|
-
const records = products.map(product => normalizeCommercePosProduct(normalizeCommerceProductRecord(
|
|
39
|
-
product,
|
|
40
|
-
categoryMap,
|
|
41
|
-
manufacturerMap,
|
|
42
|
-
emptyCounts,
|
|
43
|
-
emptyCounts,
|
|
44
|
-
emptyCounts,
|
|
45
|
-
)))
|
|
46
|
-
const sellable = records.filter(record => record.isAvailable && record.inventoryCount > 0)
|
|
47
|
-
const usedCategoryIds = new Set(records.map(record => record.categoryId).filter(Boolean))
|
|
48
|
-
|
|
26
|
+
const settings = await readPosSettings()
|
|
49
27
|
return {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
customers: customers
|
|
53
|
-
.filter(isCommercePosCustomerActive)
|
|
54
|
-
.map(normalizeCommercePosCustomer),
|
|
55
|
-
taxRate: selectCommercePosTaxRate(taxRates),
|
|
28
|
+
categories: settings.categories,
|
|
29
|
+
taxRate: settings.taxRate,
|
|
56
30
|
defaultCurrency: normalizeCommerceCurrency(config.commerce?.currency),
|
|
57
31
|
paymentMethods: [{ id: 'cash', label: 'Cash' }],
|
|
58
|
-
summary:
|
|
59
|
-
products: records.length,
|
|
60
|
-
sellable: sellable.length,
|
|
61
|
-
inventory: records.reduce((sum, record) => sum + record.inventoryCount, 0),
|
|
62
|
-
},
|
|
32
|
+
summary: settings.summary,
|
|
63
33
|
}
|
|
64
34
|
}
|
|
65
35
|
catch (error) {
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { RequestInstance } from '@stacksjs/types'
|
|
2
|
+
import { Action } from '@stacksjs/actions/runtime'
|
|
3
|
+
import { response } from '@stacksjs/router'
|
|
4
|
+
import { dashboardOperationalError } from '../dashboard-response'
|
|
5
|
+
import { parsePosCatalogQuery, parsePosIds, readPosCatalogPage, readPosProducts } from './commerce-pos-catalog'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* `GET /api/dashboard/commerce/pos/products` - the point of sale catalogue,
|
|
9
|
+
* searched and paged by the database (commerce-pos-catalog.ts,
|
|
10
|
+
* stacksjs/stacks#3218): `q`, `category`, `availability` (sellable or
|
|
11
|
+
* unsellable), `page` and `per_page`. With `ids=1,2,3` it answers exactly
|
|
12
|
+
* those products instead, which is how the cart checks its lines.
|
|
13
|
+
*/
|
|
14
|
+
export default new Action({
|
|
15
|
+
name: 'CommercePosProductsAction',
|
|
16
|
+
description: 'Searches and pages the point of sale catalogue, or reads the products a cart holds.',
|
|
17
|
+
method: 'GET',
|
|
18
|
+
apiResponse: true,
|
|
19
|
+
|
|
20
|
+
async handle(request: RequestInstance) {
|
|
21
|
+
const read = (key: string) => request.get<unknown>(key, '')
|
|
22
|
+
const ids = parsePosIds(read)
|
|
23
|
+
if ('error' in ids)
|
|
24
|
+
return response.json({ message: ids.error }, 422)
|
|
25
|
+
const query = parsePosCatalogQuery(read)
|
|
26
|
+
if ('error' in query)
|
|
27
|
+
return response.json({ message: query.error }, 422)
|
|
28
|
+
|
|
29
|
+
try {
|
|
30
|
+
if (ids.length > 0)
|
|
31
|
+
return { records: await readPosProducts(ids) }
|
|
32
|
+
const catalog = await readPosCatalogPage(query)
|
|
33
|
+
return { records: catalog.products, total: catalog.total, page: catalog.page, perPage: query.perPage }
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
return dashboardOperationalError(error, 'Point of sale products could not be read.', 'CommercePosProductsAction')
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
})
|
|
@@ -1,37 +1,15 @@
|
|
|
1
1
|
import type { RequestInstance } from '@stacksjs/types'
|
|
2
2
|
import { Action } from '@stacksjs/actions/runtime'
|
|
3
|
-
import {
|
|
4
|
-
import { formatDate, PrintDevice } from '@stacksjs/orm'
|
|
3
|
+
import { response } from '@stacksjs/router'
|
|
5
4
|
import { dashboardOperationalError } from '../dashboard-response'
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
import { normalizePrintLogRecord, summarizePrintLogs } from './print-log-records'
|
|
15
|
-
|
|
16
|
-
const STATUSES = ['failed', 'success', 'warning'] as const
|
|
17
|
-
const RANGES = ['1', '7', '30', '90', 'all'] as const
|
|
18
|
-
const SORTS = {
|
|
19
|
-
duration: ['duration', 'desc'],
|
|
20
|
-
newest: ['timestamp', 'desc'],
|
|
21
|
-
oldest: ['timestamp', 'asc'],
|
|
22
|
-
printer: ['printer', 'asc'],
|
|
23
|
-
} as const
|
|
24
|
-
|
|
25
|
-
type PrintLogSort = keyof typeof SORTS
|
|
26
|
-
|
|
27
|
-
function queryValue(request: RequestInstance, key: string): string {
|
|
28
|
-
return dashboardRequestValue(request, key)
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function selectedSort(value: string): PrintLogSort {
|
|
32
|
-
return value in SORTS ? value as PrintLogSort : 'newest'
|
|
33
|
-
}
|
|
34
|
-
|
|
5
|
+
import { parsePrintLogListQuery, readPrintLogPage } from './commerce-print-log-list'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* `GET /api/dashboard/commerce/print-logs` - one page of print logs, with the
|
|
9
|
+
* summary and breakdown of every log the search and filters match
|
|
10
|
+
* (commerce-print-log-list.ts, stacksjs/stacks#3218). The summary used to
|
|
11
|
+
* describe the page alone.
|
|
12
|
+
*/
|
|
35
13
|
export default new Action({
|
|
36
14
|
name: 'CommercePrintLogsAction',
|
|
37
15
|
description: 'Returns filtered, sorted, paginated Receipt print logs.',
|
|
@@ -39,80 +17,12 @@ export default new Action({
|
|
|
39
17
|
apiResponse: true,
|
|
40
18
|
|
|
41
19
|
async handle(request: RequestInstance) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
const search = queryValue(request, 'search')
|
|
46
|
-
const printer = queryValue(request, 'printer')
|
|
47
|
-
const requestedStatus = queryValue(request, 'status').toLowerCase()
|
|
48
|
-
const status = STATUSES.includes(requestedStatus as typeof STATUSES[number]) ? requestedStatus : ''
|
|
49
|
-
const requestedRange = queryValue(request, 'range').toLowerCase()
|
|
50
|
-
const range = RANGES.includes(requestedRange as typeof RANGES[number]) ? requestedRange : '30'
|
|
51
|
-
const days = range === 'all' ? 0 : Number(range)
|
|
52
|
-
const sort = selectedSort(queryValue(request, 'sort').toLowerCase())
|
|
53
|
-
const [sortColumn, sortDirection] = SORTS[sort]
|
|
54
|
-
const searchPattern = `%${search}%`
|
|
55
|
-
const cutoff = days ? formatDate(Date.now() - days * 86400000) : ''
|
|
56
|
-
|
|
57
|
-
const applyFilters = <T extends {
|
|
58
|
-
where: (...args: any[]) => T
|
|
59
|
-
whereAny: (columns: string[], operator: string, value: unknown) => T
|
|
60
|
-
}>(query: T): T => {
|
|
61
|
-
let filtered = query
|
|
62
|
-
if (printer)
|
|
63
|
-
filtered = filtered.where('printer', '=', printer)
|
|
64
|
-
if (status)
|
|
65
|
-
filtered = filtered.where('status', '=', status)
|
|
66
|
-
if (cutoff)
|
|
67
|
-
filtered = filtered.where('timestamp', '>=', cutoff)
|
|
68
|
-
if (search)
|
|
69
|
-
filtered = filtered.whereAny(['printer', 'document', 'status'], 'like', searchPattern)
|
|
70
|
-
return filtered
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
const [countRow, printerRows, statusRows, printDevices] = await Promise.all([
|
|
74
|
-
applyFilters(db.selectFrom('receipts').select(db.fn.count('id').as('count')))
|
|
75
|
-
.executeTakeFirst() as Promise<{ count: number | string } | undefined>,
|
|
76
|
-
db.selectFrom('receipts').select('printer').distinct().orderBy('printer', 'asc').limit(500).execute() as Promise<Array<{ printer: string | null }>>,
|
|
77
|
-
db.selectFrom('receipts').select('status').distinct().orderBy('status', 'asc').limit(10).execute() as Promise<Array<{ status: string | null }>>,
|
|
78
|
-
PrintDevice.orderBy('id', 'asc').limit(500).get(),
|
|
79
|
-
])
|
|
20
|
+
const query = parsePrintLogListQuery(key => request.get<unknown>(key, ''))
|
|
21
|
+
if ('error' in query)
|
|
22
|
+
return response.json({ message: query.error }, 422)
|
|
80
23
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
integer: true,
|
|
84
|
-
})
|
|
85
|
-
const totalPages = Math.max(1, Math.ceil(total / perPage))
|
|
86
|
-
const page = Math.min(requestedPage, totalPages)
|
|
87
|
-
const rows = await applyFilters(db.selectFrom('receipts').selectAll())
|
|
88
|
-
.orderBy(sortColumn, sortDirection)
|
|
89
|
-
.orderBy('id', sortDirection)
|
|
90
|
-
.limit(perPage)
|
|
91
|
-
.offset((page - 1) * perPage)
|
|
92
|
-
.execute()
|
|
93
|
-
const printDeviceIds = new Set(printDevices.map(device =>
|
|
94
|
-
commerceIdentifier(commerceValue(device, 'id', 'uuid'), 'PrintDevice'),
|
|
95
|
-
))
|
|
96
|
-
const records = rows.map((row: Record<string, unknown>) => normalizePrintLogRecord(row, printDeviceIds))
|
|
97
|
-
|
|
98
|
-
return {
|
|
99
|
-
records,
|
|
100
|
-
summary: summarizePrintLogs(records),
|
|
101
|
-
pagination: {
|
|
102
|
-
page,
|
|
103
|
-
perPage,
|
|
104
|
-
total,
|
|
105
|
-
totalPages,
|
|
106
|
-
},
|
|
107
|
-
options: {
|
|
108
|
-
printers: printerRows
|
|
109
|
-
.map(row => commerceOptionalString(row.printer, 'Receipt query', 'printer'))
|
|
110
|
-
.filter(Boolean),
|
|
111
|
-
statuses: statusRows.map(row =>
|
|
112
|
-
commerceEnum(row.status, 'Receipt query', 'status', STATUSES),
|
|
113
|
-
),
|
|
114
|
-
},
|
|
115
|
-
}
|
|
24
|
+
try {
|
|
25
|
+
return await readPrintLogPage(query)
|
|
116
26
|
}
|
|
117
27
|
catch (error) {
|
|
118
28
|
return dashboardOperationalError(error, 'Print log records could not be read.', 'CommercePrintLogsAction')
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { RequestInstance } from '@stacksjs/types'
|
|
2
|
+
import { Action } from '@stacksjs/actions/runtime'
|
|
3
|
+
import { response } from '@stacksjs/router'
|
|
4
|
+
import { dashboardOperationalError } from '../dashboard-response'
|
|
5
|
+
import { parsePrintLogListQuery, readPrintLogsForExport } from './commerce-print-log-list'
|
|
6
|
+
import { printLogsToCsv } from './print-log-records'
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* `GET /api/dashboard/commerce/print-logs/export` - every print log matching
|
|
10
|
+
* the page's search, filters and sort, as CSV (stacksjs/stacks#3218). The
|
|
11
|
+
* page could only export the twenty rows it showed.
|
|
12
|
+
*/
|
|
13
|
+
export default new Action({
|
|
14
|
+
name: 'CommercePrintLogsExportAction',
|
|
15
|
+
description: 'Exports every print log matching the Print Logs page filters as CSV.',
|
|
16
|
+
method: 'GET',
|
|
17
|
+
apiResponse: false,
|
|
18
|
+
|
|
19
|
+
async handle(request: RequestInstance) {
|
|
20
|
+
const query = parsePrintLogListQuery(key => request.get<unknown>(key, ''))
|
|
21
|
+
if ('error' in query)
|
|
22
|
+
return response.json({ message: query.error }, 422)
|
|
23
|
+
|
|
24
|
+
try {
|
|
25
|
+
const csv = `${printLogsToCsv(await readPrintLogsForExport(query))}`
|
|
26
|
+
const day = new Date().toISOString().slice(0, 10)
|
|
27
|
+
return new Response(csv, {
|
|
28
|
+
status: 200,
|
|
29
|
+
headers: {
|
|
30
|
+
'Cache-Control': 'private, no-store',
|
|
31
|
+
'Content-Disposition': `attachment; filename="print-logs-${day}.csv"`,
|
|
32
|
+
'Content-Type': 'text/csv; charset=utf-8',
|
|
33
|
+
'X-Content-Type-Options': 'nosniff',
|
|
34
|
+
},
|
|
35
|
+
})
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
return dashboardOperationalError(error, 'Print logs could not be exported.', 'CommercePrintLogsExportAction')
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
})
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { RequestInstance } from '@stacksjs/types'
|
|
2
|
+
import { Action } from '@stacksjs/actions/runtime'
|
|
3
|
+
import { response } from '@stacksjs/router'
|
|
4
|
+
import { dashboardOperationalError } from '../dashboard-response'
|
|
5
|
+
import { parseNamedSearchQuery } from '../named-search'
|
|
6
|
+
import { searchProductChoices } from './commerce-choices'
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* `GET /api/dashboard/commerce/product-choices?q=` - the products a commerce
|
|
10
|
+
* dialog offers, searched by the database (commerce-choices.ts,
|
|
11
|
+
* stacksjs/stacks#3218). The waitlist dialogs were handed the first 500.
|
|
12
|
+
*/
|
|
13
|
+
export default new Action({
|
|
14
|
+
name: 'CommerceProductChoicesAction',
|
|
15
|
+
description: 'Searches products for the commerce dialogs.',
|
|
16
|
+
method: 'GET',
|
|
17
|
+
apiResponse: true,
|
|
18
|
+
|
|
19
|
+
async handle(request: RequestInstance) {
|
|
20
|
+
const query = parseNamedSearchQuery(key => request.get<unknown>(key, ''))
|
|
21
|
+
if ('error' in query)
|
|
22
|
+
return response.json({ message: query.error }, 422)
|
|
23
|
+
|
|
24
|
+
try {
|
|
25
|
+
const { choices, total } = await searchProductChoices(query)
|
|
26
|
+
return { choices, total, limit: query.limit }
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
return dashboardOperationalError(error, 'Products could not be searched.', 'CommerceProductChoicesAction')
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
})
|
|
@@ -1,57 +1,38 @@
|
|
|
1
|
+
import type { RequestInstance } from '@stacksjs/types'
|
|
1
2
|
import { Action } from '@stacksjs/actions/runtime'
|
|
2
3
|
import { config } from '@stacksjs/config'
|
|
3
|
-
import {
|
|
4
|
+
import { response } from '@stacksjs/router'
|
|
4
5
|
import { dashboardOperationalError } from '../dashboard-response'
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
countProductRelations,
|
|
8
|
-
normalizeCommerceCurrency,
|
|
9
|
-
normalizeCommerceProductRecord,
|
|
10
|
-
normalizeManufacturerOption,
|
|
11
|
-
normalizeProductOption,
|
|
12
|
-
summarizeCommerceProducts,
|
|
13
|
-
} from './commerce-product-records'
|
|
6
|
+
import { parseProductListQuery, readProductPage } from './commerce-product-list'
|
|
7
|
+
import { normalizeCommerceCurrency } from './commerce-product-records'
|
|
14
8
|
|
|
9
|
+
/**
|
|
10
|
+
* `GET /api/dashboard/commerce/products` - one page of products, searched,
|
|
11
|
+
* filtered, sorted and counted by the database, with the catalogue summary
|
|
12
|
+
* (commerce-product-list.ts, stacksjs/stacks#3218). It used to return the
|
|
13
|
+
* newest 500 for the browser to do all of that with.
|
|
14
|
+
*/
|
|
15
15
|
export default new Action({
|
|
16
16
|
name: 'CommerceProductsAction',
|
|
17
|
-
description: 'Returns persisted Product records with native relationship context
|
|
17
|
+
description: 'Returns one page of persisted Product records with native relationship context.',
|
|
18
18
|
method: 'GET',
|
|
19
19
|
apiResponse: true,
|
|
20
20
|
|
|
21
|
-
async handle() {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
// Identifiers normalize to strings; `product_id` is numeric.
|
|
26
|
-
const numericProductIds = productIds.map(Number).filter(Number.isSafeInteger)
|
|
27
|
-
const [categories, manufacturers, variants, units, reviews] = await Promise.all([
|
|
28
|
-
Category.orderBy('name', 'asc').limit(500).get(),
|
|
29
|
-
Manufacturer.orderBy('manufacturer', 'asc').limit(500).get(),
|
|
30
|
-
numericProductIds.length > 0 ? ProductVariant.whereIn('product_id', numericProductIds).get() : [],
|
|
31
|
-
numericProductIds.length > 0 ? ProductUnit.whereIn('product_id', numericProductIds).get() : [],
|
|
32
|
-
numericProductIds.length > 0 ? Review.whereIn('product_id', numericProductIds).get() : [],
|
|
33
|
-
])
|
|
34
|
-
const categoryOptions = categories.map(normalizeProductOption)
|
|
35
|
-
const manufacturerOptions = manufacturers.map(normalizeManufacturerOption)
|
|
36
|
-
const categoryMap = new Map(categoryOptions.map(option => [option.id, option.label]))
|
|
37
|
-
const manufacturerMap = new Map(manufacturerOptions.map(option => [option.id, option.label]))
|
|
38
|
-
const variantCounts = countProductRelations(variants)
|
|
39
|
-
const unitCounts = countProductRelations(units)
|
|
40
|
-
const reviewCounts = countProductRelations(reviews)
|
|
41
|
-
const records = products.map(product => normalizeCommerceProductRecord(
|
|
42
|
-
product,
|
|
43
|
-
categoryMap,
|
|
44
|
-
manufacturerMap,
|
|
45
|
-
variantCounts,
|
|
46
|
-
unitCounts,
|
|
47
|
-
reviewCounts,
|
|
48
|
-
))
|
|
21
|
+
async handle(request: RequestInstance) {
|
|
22
|
+
const query = parseProductListQuery(key => request.get<unknown>(key, ''))
|
|
23
|
+
if ('error' in query)
|
|
24
|
+
return response.json({ message: query.error }, 422)
|
|
49
25
|
|
|
26
|
+
try {
|
|
27
|
+
const products = await readProductPage(query)
|
|
50
28
|
return {
|
|
51
|
-
records,
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
29
|
+
records: products.records,
|
|
30
|
+
total: products.total,
|
|
31
|
+
page: products.page,
|
|
32
|
+
perPage: query.perPage,
|
|
33
|
+
summary: products.summary,
|
|
34
|
+
categories: products.categories,
|
|
35
|
+
manufacturers: products.manufacturers,
|
|
55
36
|
defaultCurrency: normalizeCommerceCurrency(config.commerce?.currency),
|
|
56
37
|
}
|
|
57
38
|
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { RequestInstance } from '@stacksjs/types'
|
|
2
|
+
import { Action } from '@stacksjs/actions/runtime'
|
|
3
|
+
import { minorToInput } from '@stacksjs/commerce/money'
|
|
4
|
+
import { config } from '@stacksjs/config'
|
|
5
|
+
import { response } from '@stacksjs/router'
|
|
6
|
+
import { dashboardOperationalError } from '../dashboard-response'
|
|
7
|
+
import { parseProductListQuery, productsCsv, readProductsForExport } from './commerce-product-list'
|
|
8
|
+
import { normalizeCommerceCurrency } from './commerce-product-records'
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* `GET /api/dashboard/commerce/products/export` - every product matching the
|
|
12
|
+
* Products page's search, filters and sort, as CSV (stacksjs/stacks#3218). The
|
|
13
|
+
* page built the file from the newest 500.
|
|
14
|
+
*/
|
|
15
|
+
export default new Action({
|
|
16
|
+
name: 'CommerceProductsExportAction',
|
|
17
|
+
description: 'Exports every product matching the Products page filters as CSV.',
|
|
18
|
+
method: 'GET',
|
|
19
|
+
apiResponse: false,
|
|
20
|
+
|
|
21
|
+
async handle(request: RequestInstance) {
|
|
22
|
+
const query = parseProductListQuery(key => request.get<unknown>(key, ''))
|
|
23
|
+
if ('error' in query)
|
|
24
|
+
return response.json({ message: query.error }, 422)
|
|
25
|
+
|
|
26
|
+
try {
|
|
27
|
+
const currency = normalizeCommerceCurrency(config.commerce?.currency)
|
|
28
|
+
const csv = productsCsv(await readProductsForExport(query), currency, minorToInput)
|
|
29
|
+
const day = new Date().toISOString().slice(0, 10)
|
|
30
|
+
return new Response(csv, {
|
|
31
|
+
status: 200,
|
|
32
|
+
headers: {
|
|
33
|
+
'Cache-Control': 'private, no-store',
|
|
34
|
+
'Content-Disposition': `attachment; filename="products-${day}.csv"`,
|
|
35
|
+
'Content-Type': 'text/csv; charset=utf-8',
|
|
36
|
+
'X-Content-Type-Options': 'nosniff',
|
|
37
|
+
},
|
|
38
|
+
})
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
return dashboardOperationalError(error, 'Products could not be exported.', 'CommerceProductsExportAction')
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
})
|
|
@@ -11,7 +11,9 @@ export default new Action({
|
|
|
11
11
|
|
|
12
12
|
async handle() {
|
|
13
13
|
try {
|
|
14
|
-
|
|
14
|
+
// Read whole: store configuration, which the page searches in full. The
|
|
15
|
+
// first 500 left the rest unlisted and unsearchable (stacksjs/stacks#3218).
|
|
16
|
+
const couriers = await Courier.orderBy('name', 'asc').get()
|
|
15
17
|
const userIds = [...new Set(couriers.map(courier => courier.get('user_id')).filter(Boolean))]
|
|
16
18
|
const users = userIds.length ? await User.whereIn('id', userIds).get() : []
|
|
17
19
|
const usersById = indexCourierUsers(users)
|
|
@@ -1,24 +1,35 @@
|
|
|
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 { dashboardOperationalError } from '../dashboard-response'
|
|
4
|
-
import {
|
|
5
|
-
indexDeliveryRouteCouriers,
|
|
6
|
-
normalizeDeliveryRouteRecord,
|
|
7
|
-
} from './delivery-route-records'
|
|
5
|
+
import { parseDeliveryRouteListQuery, readDeliveryRoutePage } from './commerce-delivery-route-list'
|
|
8
6
|
|
|
7
|
+
/**
|
|
8
|
+
* `GET /api/dashboard/commerce/delivery-routes` - one page of delivery routes,
|
|
9
|
+
* searched, sorted and counted by the database, with the summary of every
|
|
10
|
+
* route (commerce-delivery-route-list.ts, stacksjs/stacks#3218). It used to
|
|
11
|
+
* return the 500 most recently active routes as a bare array.
|
|
12
|
+
*/
|
|
9
13
|
export default new Action({
|
|
10
14
|
name: 'Dashboard Delivery Routes',
|
|
11
|
-
description: 'Returns
|
|
15
|
+
description: 'Returns one page of delivery routes with their linked couriers.',
|
|
12
16
|
method: 'GET',
|
|
13
17
|
apiResponse: true,
|
|
14
18
|
|
|
15
|
-
async handle() {
|
|
19
|
+
async handle(request: RequestInstance) {
|
|
20
|
+
const query = parseDeliveryRouteListQuery(key => request.get<unknown>(key, ''))
|
|
21
|
+
if ('error' in query)
|
|
22
|
+
return response.json({ message: query.error }, 422)
|
|
23
|
+
|
|
16
24
|
try {
|
|
17
|
-
const routes = await
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
25
|
+
const routes = await readDeliveryRoutePage(query)
|
|
26
|
+
return {
|
|
27
|
+
records: routes.records,
|
|
28
|
+
total: routes.total,
|
|
29
|
+
page: routes.page,
|
|
30
|
+
perPage: query.perPage,
|
|
31
|
+
summary: routes.summary,
|
|
32
|
+
}
|
|
22
33
|
}
|
|
23
34
|
catch (error) {
|
|
24
35
|
return dashboardOperationalError(error, 'Delivery route records could not be read.', 'DeliveryRouteIndexAction')
|
|
@@ -11,7 +11,9 @@ export default new Action({
|
|
|
11
11
|
|
|
12
12
|
async handle() {
|
|
13
13
|
try {
|
|
14
|
-
|
|
14
|
+
// Read whole: store configuration, which the page searches in full. The
|
|
15
|
+
// first 500 left the rest unlisted and unsearchable (stacksjs/stacks#3218).
|
|
16
|
+
const records = await DigitalDelivery.orderByDesc('id').get()
|
|
15
17
|
return records.map(normalizeDigitalDeliveryRecord)
|
|
16
18
|
}
|
|
17
19
|
catch (error) {
|
|
@@ -1,34 +1,35 @@
|
|
|
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 { dashboardOperationalError } from '../dashboard-response'
|
|
4
|
-
import {
|
|
5
|
-
indexLicenseKeyOptions,
|
|
6
|
-
normalizeLicenseKeyCustomer,
|
|
7
|
-
normalizeLicenseKeyOrder,
|
|
8
|
-
normalizeLicenseKeyProduct,
|
|
9
|
-
normalizeLicenseKeyRecord,
|
|
10
|
-
} from './license-key-records'
|
|
5
|
+
import { parseLicenseKeyListQuery, readLicenseKeyPage } from './commerce-license-key-list'
|
|
11
6
|
|
|
7
|
+
/**
|
|
8
|
+
* `GET /api/dashboard/commerce/license-keys` - one page of licence keys,
|
|
9
|
+
* searched, sorted and counted by the database, with the summary of every key
|
|
10
|
+
* and each key's customer, product and order (commerce-license-key-list.ts,
|
|
11
|
+
* stacksjs/stacks#3218). It used to return the newest 500 as a bare array.
|
|
12
|
+
*/
|
|
12
13
|
export default new Action({
|
|
13
14
|
name: 'Dashboard License Keys',
|
|
14
|
-
description: 'Returns license keys with lightweight customer, product, and order summaries.',
|
|
15
|
+
description: 'Returns one page of license keys with lightweight customer, product, and order summaries.',
|
|
15
16
|
method: 'GET',
|
|
16
17
|
apiResponse: true,
|
|
17
|
-
|
|
18
|
+
|
|
19
|
+
async handle(request: RequestInstance) {
|
|
20
|
+
const query = parseLicenseKeyListQuery(key => request.get<unknown>(key, ''))
|
|
21
|
+
if ('error' in query)
|
|
22
|
+
return response.json({ message: query.error }, 422)
|
|
23
|
+
|
|
18
24
|
try {
|
|
19
|
-
const keys = await
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
])
|
|
28
|
-
const customerMap = indexLicenseKeyOptions(customers.map(normalizeLicenseKeyCustomer))
|
|
29
|
-
const productMap = indexLicenseKeyOptions(products.map(normalizeLicenseKeyProduct))
|
|
30
|
-
const orderMap = indexLicenseKeyOptions(orders.map(normalizeLicenseKeyOrder))
|
|
31
|
-
return keys.map(key => normalizeLicenseKeyRecord(key, customerMap, productMap, orderMap))
|
|
25
|
+
const keys = await readLicenseKeyPage(query)
|
|
26
|
+
return {
|
|
27
|
+
records: keys.records,
|
|
28
|
+
total: keys.total,
|
|
29
|
+
page: keys.page,
|
|
30
|
+
perPage: query.perPage,
|
|
31
|
+
summary: keys.summary,
|
|
32
|
+
}
|
|
32
33
|
}
|
|
33
34
|
catch (error) {
|
|
34
35
|
return dashboardOperationalError(error, 'License key records could not be read.', 'LicenseKeyIndexAction')
|