@jarwizz/create-jarshop 0.1.3 → 0.1.5
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/dist/template/src/email-smoke.ts +1 -0
- package/dist/template/src/migrations/1787800000000-jarshop-order-email-event-key.ts +60 -0
- package/dist/template/src/migrations/1787900000000-jarshop-email-brand-configuration.ts +32 -0
- package/dist/template/src/plugins/jarshop-checkout/confirmation.ts +13 -0
- package/dist/template/src/plugins/jarshop-checkout/dashboard/index.tsx +213 -32
- package/dist/template/src/plugins/jarshop-checkout/dashboard/order-email-delivery-status.ts +17 -0
- package/dist/template/src/plugins/jarshop-checkout/index.ts +49 -1
- package/dist/template/src/plugins/jarshop-checkout/jarshop-checkout.plugin.ts +160 -12
- package/dist/template/src/plugins/jarshop-checkout/order-email-configuration.entity.ts +61 -0
- package/dist/template/src/plugins/jarshop-checkout/order-email-configuration.ts +190 -0
- package/dist/template/src/plugins/jarshop-checkout/order-email-delivery-core.ts +321 -13
- package/dist/template/src/plugins/jarshop-checkout/order-email-delivery-status.ts +3 -1
- package/dist/template/src/plugins/jarshop-checkout/order-email-delivery.entity.ts +15 -4
- package/dist/template/src/plugins/jarshop-checkout/order-email-lifecycle.ts +335 -0
- package/dist/template/src/plugins/jarshop-checkout/order-email-outbox.ts +308 -15
- package/dist/template/src/plugins/jarshop-checkout/order-email-worker.ts +86 -8
- package/dist/template/src/plugins/jarshop-checkout/order-lifecycle-core.ts +131 -0
- package/dist/template/src/plugins/jarshop-checkout/order-lifecycle-process.ts +102 -0
- package/dist/template-manifest.json +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import {
|
|
2
|
+
defaultFulfillmentProcess,
|
|
3
|
+
Order,
|
|
4
|
+
TransactionalConnection,
|
|
5
|
+
type FulfillmentProcess,
|
|
6
|
+
type VendureConfig,
|
|
7
|
+
} from "@vendure/core";
|
|
8
|
+
import {
|
|
9
|
+
resolveShippingMethodCodeForOrderLines,
|
|
10
|
+
validateFulfillmentTransition,
|
|
11
|
+
} from "./order-lifecycle-core.js";
|
|
12
|
+
|
|
13
|
+
declare module "@vendure/core" {
|
|
14
|
+
interface CustomFulfillmentStates {
|
|
15
|
+
ReadyForPickup: never;
|
|
16
|
+
PickedUp: never;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
type PickupFulfillmentState = "ReadyForPickup" | "PickedUp";
|
|
21
|
+
|
|
22
|
+
let connection: TransactionalConnection;
|
|
23
|
+
|
|
24
|
+
export const jarShopFulfillmentProcess: FulfillmentProcess<PickupFulfillmentState> =
|
|
25
|
+
{
|
|
26
|
+
transitions: {
|
|
27
|
+
Pending: {
|
|
28
|
+
to: ["ReadyForPickup"],
|
|
29
|
+
},
|
|
30
|
+
ReadyForPickup: {
|
|
31
|
+
to: ["PickedUp", "Cancelled"],
|
|
32
|
+
},
|
|
33
|
+
PickedUp: {
|
|
34
|
+
to: ["Cancelled"],
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
init(injector) {
|
|
38
|
+
connection = injector.get(TransactionalConnection);
|
|
39
|
+
},
|
|
40
|
+
async onTransitionStart(_fromState, toState, { ctx, fulfillment, orders }) {
|
|
41
|
+
if (
|
|
42
|
+
!["ReadyForPickup", "PickedUp", "Shipped", "Delivered"].includes(
|
|
43
|
+
toState,
|
|
44
|
+
)
|
|
45
|
+
) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const orderFacts = await Promise.all(
|
|
49
|
+
orders.map((order) =>
|
|
50
|
+
loadOrderLifecycleFacts(
|
|
51
|
+
ctx,
|
|
52
|
+
order.id,
|
|
53
|
+
fulfillment.lines.map((line) => line.orderLineId),
|
|
54
|
+
),
|
|
55
|
+
),
|
|
56
|
+
);
|
|
57
|
+
return validateFulfillmentTransition({
|
|
58
|
+
toState,
|
|
59
|
+
shippingMethodCodes: orderFacts.flatMap(
|
|
60
|
+
(order) => order.shippingMethodCodes,
|
|
61
|
+
),
|
|
62
|
+
paymentStates: orderFacts.flatMap((order) => order.paymentStates),
|
|
63
|
+
});
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
export function registerJarShopOrderLifecycle<Config extends VendureConfig>(
|
|
68
|
+
config: Config,
|
|
69
|
+
): Config {
|
|
70
|
+
config.shippingOptions ??= {};
|
|
71
|
+
config.shippingOptions.process ??= [defaultFulfillmentProcess];
|
|
72
|
+
if (!config.shippingOptions.process.includes(jarShopFulfillmentProcess)) {
|
|
73
|
+
config.shippingOptions.process.push(jarShopFulfillmentProcess);
|
|
74
|
+
}
|
|
75
|
+
return config;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
async function loadOrderLifecycleFacts(
|
|
79
|
+
ctx: Parameters<TransactionalConnection["getEntityOrThrow"]>[0],
|
|
80
|
+
orderId: Order["id"],
|
|
81
|
+
fulfillmentOrderLineIds: readonly (string | number)[],
|
|
82
|
+
) {
|
|
83
|
+
const order = await connection.getEntityOrThrow(ctx, Order, orderId, {
|
|
84
|
+
relations: [
|
|
85
|
+
"shippingLines.shippingMethod",
|
|
86
|
+
"shippingLines.orderLines",
|
|
87
|
+
"payments",
|
|
88
|
+
],
|
|
89
|
+
});
|
|
90
|
+
return {
|
|
91
|
+
shippingMethodCodes: [
|
|
92
|
+
resolveShippingMethodCodeForOrderLines(
|
|
93
|
+
order.shippingLines.map((line) => ({
|
|
94
|
+
code: line.shippingMethod.code,
|
|
95
|
+
orderLineIds: line.orderLines.map((orderLine) => orderLine.id),
|
|
96
|
+
})),
|
|
97
|
+
fulfillmentOrderLineIds,
|
|
98
|
+
),
|
|
99
|
+
],
|
|
100
|
+
paymentStates: order.payments.map((payment) => payment.state),
|
|
101
|
+
};
|
|
102
|
+
}
|