@zeyolabs/shopping 2026.11.16 → 2026.11.17
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.
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import { resolve } from '$app/paths';
|
|
4
4
|
import { page } from '$app/state';
|
|
5
5
|
import { BULK_DISPATCH_LIMIT, FILTER_LABELS, ORDER_FILTERS, type OrderFilter } from '../filters';
|
|
6
|
-
import { dispatchOrders, getOrderCounts, getOrders } from '../admin.remote';
|
|
6
|
+
import { dispatchOrders, getOrderCounts, getOrders, getReadyByService } from '../admin.remote';
|
|
7
7
|
import { ErrorMessage } from '../../utils/errors';
|
|
8
8
|
import { toast } from 'svelte-sonner';
|
|
9
9
|
import Button from '@zeyolabs/ui/form/Button.svelte';
|
|
@@ -97,6 +97,11 @@
|
|
|
97
97
|
</a>
|
|
98
98
|
<!-- eslint-enable svelte/no-navigation-without-resolve -->
|
|
99
99
|
{/each}
|
|
100
|
+
<Boundary message="Could not load ready counts.">
|
|
101
|
+
{#each Object.entries(await getReadyByService()) as [service, n] (service)}
|
|
102
|
+
<span class="text-sm text-[var(--muted)]">{service}: {n} ready</span>
|
|
103
|
+
{/each}
|
|
104
|
+
</Boundary>
|
|
100
105
|
<form
|
|
101
106
|
class="ml-auto"
|
|
102
107
|
onsubmit={(event) => {
|
|
@@ -17,6 +17,7 @@ export const getOrders = Remote.Query(OrderListSchema, ({ filter, q }) =>
|
|
|
17
17
|
);
|
|
18
18
|
|
|
19
19
|
export const getOrderCounts = Remote.Query(() => FulfilmentManager.counts());
|
|
20
|
+
export const getReadyByService = Remote.Query(() => FulfilmentManager.readyByService());
|
|
20
21
|
|
|
21
22
|
export const getOrder = Remote.Query(OrderNumber, (number) => FulfilmentManager.find(number));
|
|
22
23
|
|
|
@@ -24,7 +25,11 @@ export const shipForm = Remote.Form(ShipSchema, async ({ number, skipEmail, trac
|
|
|
24
25
|
const { emailed, skipped } = await FulfilmentManager.markShipped(number, trackingNumber || null, {
|
|
25
26
|
email: !skipEmail,
|
|
26
27
|
});
|
|
27
|
-
await Promise.all([
|
|
28
|
+
await Promise.all([
|
|
29
|
+
getOrder(number).refresh(),
|
|
30
|
+
getOrderCounts().refresh(),
|
|
31
|
+
getReadyByService().refresh(),
|
|
32
|
+
]);
|
|
28
33
|
if (skipped) return FormResult.ok('Marked as dispatched. The customer was not emailed.');
|
|
29
34
|
return emailed
|
|
30
35
|
? FormResult.ok('Marked as dispatched and the customer has been emailed.')
|
|
@@ -84,6 +89,6 @@ export const refundForm = Remote.Form(RefundSchema, async ({ amount, number }) =
|
|
|
84
89
|
*/
|
|
85
90
|
export const dispatchOrders = Remote.Cmd(BulkDispatchSchema, async ({ numbers, sendEmail }) => {
|
|
86
91
|
const results = await FulfilmentManager.markShippedMany(numbers, { email: sendEmail });
|
|
87
|
-
await getOrderCounts().refresh();
|
|
92
|
+
await Promise.all([getOrderCounts().refresh(), getReadyByService().refresh()]);
|
|
88
93
|
return results;
|
|
89
94
|
});
|
package/fulfilment/filters.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export const ORDER_FILTERS = ['to-ship', 'ready', 'on-hold', 'shipped', 'all'] as const;
|
|
1
|
+
export const ORDER_FILTERS = ['to-ship', 'ready', 'on-hold', 'unpaid', 'shipped', 'all'] as const;
|
|
2
2
|
export type OrderFilter = (typeof ORDER_FILTERS)[number];
|
|
3
3
|
|
|
4
4
|
export const FILTER_LABELS: Record<OrderFilter, string> = {
|
|
@@ -7,6 +7,7 @@ export const FILTER_LABELS: Record<OrderFilter, string> = {
|
|
|
7
7
|
ready: 'Ready to dispatch',
|
|
8
8
|
shipped: 'Shipped',
|
|
9
9
|
'to-ship': 'To ship',
|
|
10
|
+
unpaid: 'Unpaid',
|
|
10
11
|
};
|
|
11
12
|
|
|
12
13
|
/** Orders one bulk dispatch may carry, to stay inside a Worker's subrequest budget. */
|
|
@@ -38,6 +38,11 @@ export const FulfilmentManager = {
|
|
|
38
38
|
return fulfilment.counts();
|
|
39
39
|
},
|
|
40
40
|
|
|
41
|
+
readyByService() {
|
|
42
|
+
const fulfilment = service();
|
|
43
|
+
return fulfilment.readyByService();
|
|
44
|
+
},
|
|
45
|
+
|
|
41
46
|
/**
|
|
42
47
|
* Makes sure Click & Drop holds this order with the parcel as packed, so its label is right.
|
|
43
48
|
* Click & Drop cannot edit an order, so until a label exists the old one is removed and
|
|
@@ -35,6 +35,8 @@ function filterCondition(filter: OrderFilter) {
|
|
|
35
35
|
return eq(orders.status, 'shipped');
|
|
36
36
|
case 'to-ship':
|
|
37
37
|
return eq(orders.status, 'paid');
|
|
38
|
+
case 'unpaid':
|
|
39
|
+
return eq(orders.status, 'pending');
|
|
38
40
|
}
|
|
39
41
|
}
|
|
40
42
|
|
|
@@ -51,6 +53,7 @@ export class FulfilmentService {
|
|
|
51
53
|
ready: sql<number>`coalesce(sum(${orders.status} = 'paid' and ${orders.heldAt} is null and ${orders.labelCreatedAt} is not null), 0)`,
|
|
52
54
|
shipped: sql<number>`coalesce(sum(${orders.status} = 'shipped'), 0)`,
|
|
53
55
|
toShip: sql<number>`coalesce(sum(${orders.status} = 'paid'), 0)`,
|
|
56
|
+
unpaid: sql<number>`coalesce(sum(${orders.status} = 'pending'), 0)`,
|
|
54
57
|
})
|
|
55
58
|
.from(orders);
|
|
56
59
|
return {
|
|
@@ -59,6 +62,7 @@ export class FulfilmentService {
|
|
|
59
62
|
ready: Number(row.ready),
|
|
60
63
|
shipped: Number(row.shipped),
|
|
61
64
|
'to-ship': Number(row.toShip),
|
|
65
|
+
unpaid: Number(row.unpaid),
|
|
62
66
|
};
|
|
63
67
|
}
|
|
64
68
|
|
|
@@ -134,6 +138,16 @@ export class FulfilmentService {
|
|
|
134
138
|
return order;
|
|
135
139
|
}
|
|
136
140
|
|
|
141
|
+
/** Orders ready to dispatch (paid, not held, labelled), counted per postage service. */
|
|
142
|
+
async readyByService(): Promise<Record<string, number>> {
|
|
143
|
+
const rows = await this.db
|
|
144
|
+
.select({ n: count(), service: orders.shippingService })
|
|
145
|
+
.from(orders)
|
|
146
|
+
.where(filterCondition('ready'))
|
|
147
|
+
.groupBy(orders.shippingService);
|
|
148
|
+
return Object.fromEntries(rows.map((r) => [r.service ?? 'No service', r.n]));
|
|
149
|
+
}
|
|
150
|
+
|
|
137
151
|
async saveParcel(number: string, parcel: Parcel) {
|
|
138
152
|
const order = await this.packable(number);
|
|
139
153
|
await this.update(order.id, {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zeyolabs/shopping",
|
|
3
|
-
"version": "2026.11.
|
|
3
|
+
"version": "2026.11.17",
|
|
4
4
|
"description": "Shop and order fulfilment for SvelteKit 3 on Cloudflare: catalogue, basket, Stripe Checkout, orders, Royal Mail Click & Drop, order emails, packing, pages and admin.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "UNLICENSED",
|