@tokenoftrust/storefront-runner 2.4.52 → 2.4.54
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/apps/storefront/src/lib/admin/services/mock/fulfillment.ts +10 -53
- package/apps/storefront/src/lib/admin/viewmodels/fulfillment.ts +1159 -33
- package/apps/storefront/src/lib/apps/orders/orderForwardReceiver.ts +203 -1
- package/apps/storefront/src/lib/apps/orders/orderMapper.ts +321 -0
- package/apps/storefront/src/lib/apps/orders/ordersStore.ts +331 -1
- package/apps/storefront/src/lib/webhooks/deliveryEngine.ts +110 -1
- package/apps/storefront/src/lib/webhooks/deliveryStore.ts +70 -0
- package/apps/storefront/src/lib/webhooks/getDispatcher.ts +29 -2
- package/package.json +1 -1
|
@@ -1,62 +1,19 @@
|
|
|
1
1
|
import type { AdminTenantEnvelope } from "../../envelope";
|
|
2
2
|
import { memoizeByEnvelope } from "../../memoizeByEnvelope";
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
FulfillmentViewModel,
|
|
9
|
-
ShipmentRow,
|
|
3
|
+
import {
|
|
4
|
+
defaultWorkspaceQuery,
|
|
5
|
+
initialWorkspaceState,
|
|
6
|
+
projectWorkspace,
|
|
7
|
+
type FulfillmentViewModel,
|
|
10
8
|
} from "../../viewmodels/fulfillment";
|
|
11
9
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
{ key: "packed", label: "Packed" },
|
|
17
|
-
{ key: "label_needed", label: "Label needed" },
|
|
18
|
-
{ key: "shipped", label: "Shipped" },
|
|
19
|
-
{ key: "exceptions", label: "Exceptions" },
|
|
20
|
-
];
|
|
21
|
-
|
|
22
|
-
const CARRIERS = ["USPS", "UPS", "FedEx"];
|
|
23
|
-
const DESTINATIONS = ["Minneapolis, MN", "Portland, OR", "Austin, TX", "Columbus, OH", "Denver, CO"];
|
|
10
|
+
/** Initial test-adapter snapshot. Not a seeded queue and not a live order feed. */
|
|
11
|
+
export function readTestAdapterSnapshot(targetTenant: string): FulfillmentViewModel {
|
|
12
|
+
return projectWorkspace(initialWorkspaceState(targetTenant), defaultWorkspaceQuery());
|
|
13
|
+
}
|
|
24
14
|
|
|
25
15
|
function computeFulfillmentViewModel(envelope: AdminTenantEnvelope): FulfillmentViewModel {
|
|
26
|
-
|
|
27
|
-
const rng = seededRandom(`fulfillment:${targetTenant}`);
|
|
28
|
-
|
|
29
|
-
const shipments: ShipmentRow[] = QUEUE_DEFS.flatMap((def) =>
|
|
30
|
-
Array.from({ length: randomInt(rng, 1, 3) }, () => {
|
|
31
|
-
const labelLocked = def.key === "label_needed" || (def.key === "holds" && randomBool(rng, 0.6));
|
|
32
|
-
return {
|
|
33
|
-
orderId: `#${2_200_000_000 + Math.floor(rng() * 90_000_000)}`,
|
|
34
|
-
queue: def.key,
|
|
35
|
-
carrier: pick(rng, CARRIERS),
|
|
36
|
-
destination: pick(rng, DESTINATIONS),
|
|
37
|
-
slaAgeHours: randomInt(rng, 1, 48),
|
|
38
|
-
labelLocked,
|
|
39
|
-
labelLockReason: labelLocked ? pick(rng, ["Shipping restriction on destination", "Payment not yet captured", "Age verification pending"]) : null,
|
|
40
|
-
carrierReady: !labelLocked && randomBool(rng, 0.9),
|
|
41
|
-
destinationReady: randomBool(rng, 0.85),
|
|
42
|
-
};
|
|
43
|
-
}),
|
|
44
|
-
);
|
|
45
|
-
|
|
46
|
-
const queues: FulfillmentQueueSummary[] = QUEUE_DEFS.map((def) => ({
|
|
47
|
-
key: def.key,
|
|
48
|
-
label: def.label,
|
|
49
|
-
count: shipments.filter((s) => s.queue === def.key).length,
|
|
50
|
-
}));
|
|
51
|
-
|
|
52
|
-
const exceptionShipments = shipments.filter((s) => s.queue === "exceptions" || s.labelLocked);
|
|
53
|
-
const assistDrafts: FulfillmentAssistDraft[] = exceptionShipments.map((s) => ({
|
|
54
|
-
orderId: s.orderId,
|
|
55
|
-
kind: "blocker_explanation",
|
|
56
|
-
summary: s.labelLockReason ? `${s.labelLockReason} — resolve to unlock the label for ${s.orderId}.` : `Exception queue: ${s.orderId} needs manual review.`,
|
|
57
|
-
}));
|
|
58
|
-
|
|
59
|
-
return { targetTenant, queues, shipments, assistDrafts };
|
|
16
|
+
return readTestAdapterSnapshot(envelope.targetTenant);
|
|
60
17
|
}
|
|
61
18
|
|
|
62
19
|
export const getFulfillmentViewModel = memoizeByEnvelope(computeFulfillmentViewModel);
|