@molda-org/orders-fulfillment 0.1.0-next.18 → 0.1.0-next.19
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/index.d.ts +11 -0
- package/dist/index.js +34 -4
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -53,6 +53,7 @@ export declare const OrdersFulfillmentSpecification: {
|
|
|
53
53
|
readonly collection: "orders";
|
|
54
54
|
readonly permission: "place.order";
|
|
55
55
|
readonly event: "place.order";
|
|
56
|
+
readonly confirmation: "required";
|
|
56
57
|
readonly validate: ({ value }: {
|
|
57
58
|
readonly value: import("@molda-org/module-runtime").ModuleEntityValue;
|
|
58
59
|
readonly current: import("@molda-org/module-runtime").ModuleRecord | null;
|
|
@@ -64,12 +65,22 @@ export declare const OrdersFulfillmentSpecification: {
|
|
|
64
65
|
readonly collection: "orders";
|
|
65
66
|
readonly permission: "update.order.status";
|
|
66
67
|
readonly event: "update.order.status";
|
|
68
|
+
readonly validate: ({ value, current }: {
|
|
69
|
+
readonly value: import("@molda-org/module-runtime").ModuleEntityValue;
|
|
70
|
+
readonly current: import("@molda-org/module-runtime").ModuleRecord | null;
|
|
71
|
+
readonly transaction: import("@molda-org/module-runtime").ModuleTransaction;
|
|
72
|
+
}) => void;
|
|
67
73
|
};
|
|
68
74
|
readonly assignFulfillment: {
|
|
69
75
|
readonly kind: "upsert";
|
|
70
76
|
readonly collection: "fulfillment-assignments";
|
|
71
77
|
readonly permission: "assign.fulfillment";
|
|
72
78
|
readonly event: "assign.fulfillment";
|
|
79
|
+
readonly validate: ({ value, transaction }: {
|
|
80
|
+
readonly value: import("@molda-org/module-runtime").ModuleEntityValue;
|
|
81
|
+
readonly current: import("@molda-org/module-runtime").ModuleRecord | null;
|
|
82
|
+
readonly transaction: import("@molda-org/module-runtime").ModuleTransaction;
|
|
83
|
+
}) => Promise<void>;
|
|
73
84
|
};
|
|
74
85
|
readonly confirmHandoff: {
|
|
75
86
|
readonly kind: "transition";
|
package/dist/index.js
CHANGED
|
@@ -7,12 +7,12 @@ export const OrdersFulfillmentSpecification = {
|
|
|
7
7
|
id: 'orders-fulfillment',
|
|
8
8
|
version: '1.0.0',
|
|
9
9
|
collections: {
|
|
10
|
-
'orders': z.object({ customerId: z.string().min(1).max(200), status: z.enum(['draft', 'placed', 'preparing', 'ready', 'handed-off', 'cancelled']), currency: z.string().
|
|
10
|
+
'orders': z.object({ customerId: z.string().min(1).max(200), status: z.enum(['draft', 'placed', 'preparing', 'ready', 'handed-off', 'cancelled']), currency: z.string().regex(/^[A-Z]{3}$/), totalMinor: z.number().int().nonnegative(), lines: z.array(z.object({ itemId: z.string().min(1), name: z.string().min(1), quantity: z.number().int().positive(), unitAmountMinor: z.number().int().nonnegative() }).strict()).min(1).max(200), transitionReason: z.string().max(1_000).optional() }).strict(),
|
|
11
11
|
'fulfillment-assignments': z.object({ orderId: z.string().min(1).max(200), assigneeId: z.string().min(1).max(200), status: z.enum(['assigned', 'accepted', 'completed']) }).strict(),
|
|
12
12
|
},
|
|
13
13
|
actions: {
|
|
14
14
|
placeOrder: {
|
|
15
|
-
kind: 'create', collection: 'orders', permission: 'place.order', event: 'place.order',
|
|
15
|
+
kind: 'create', collection: 'orders', permission: 'place.order', event: 'place.order', confirmation: 'required',
|
|
16
16
|
validate: ({ value }) => {
|
|
17
17
|
const lines = value.lines;
|
|
18
18
|
const calculated = lines.reduce((total, line) => total + line.quantity * line.unitAmountMinor, 0);
|
|
@@ -20,8 +20,38 @@ export const OrdersFulfillmentSpecification = {
|
|
|
20
20
|
throw new ModuleConflictError('Order total does not match immutable line snapshots');
|
|
21
21
|
},
|
|
22
22
|
},
|
|
23
|
-
updateOrderStatus: {
|
|
24
|
-
|
|
23
|
+
updateOrderStatus: {
|
|
24
|
+
kind: 'update', collection: 'orders', permission: 'update.order.status', event: 'update.order.status',
|
|
25
|
+
validate: ({ value, current }) => {
|
|
26
|
+
if (!current)
|
|
27
|
+
throw new ModuleConflictError('Order does not exist');
|
|
28
|
+
for (const field of ['customerId', 'currency', 'totalMinor']) {
|
|
29
|
+
if (value[field] !== current.value[field])
|
|
30
|
+
throw new ModuleConflictError(`Order ${field} is immutable after placement`);
|
|
31
|
+
}
|
|
32
|
+
if (JSON.stringify(value.lines) !== JSON.stringify(current.value.lines)) {
|
|
33
|
+
throw new ModuleConflictError('Order line snapshots are immutable after placement');
|
|
34
|
+
}
|
|
35
|
+
const transitions = {
|
|
36
|
+
draft: ['placed', 'cancelled'], placed: ['preparing', 'cancelled'], preparing: ['ready', 'cancelled'],
|
|
37
|
+
ready: [], 'handed-off': [], cancelled: [],
|
|
38
|
+
};
|
|
39
|
+
const from = String(current.value.status);
|
|
40
|
+
const to = String(value.status);
|
|
41
|
+
if (from !== to && !transitions[from]?.includes(to)) {
|
|
42
|
+
throw new ModuleConflictError(`Cannot update order status from ${from} to ${to}`);
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
assignFulfillment: {
|
|
47
|
+
kind: 'upsert', collection: 'fulfillment-assignments', permission: 'assign.fulfillment', event: 'assign.fulfillment',
|
|
48
|
+
validate: async ({ value, transaction }) => {
|
|
49
|
+
const order = await transaction.require('orders', String(value.orderId));
|
|
50
|
+
if (order.value.status === 'cancelled' || order.value.status === 'handed-off') {
|
|
51
|
+
throw new ModuleConflictError('Fulfillment cannot be assigned to a closed order');
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
},
|
|
25
55
|
confirmHandoff: { kind: 'transition', collection: 'orders', permission: 'confirm.handoff', event: 'confirm.handoff', status: 'handed-off', allowedFrom: ["ready"], confirmation: 'required' },
|
|
26
56
|
},
|
|
27
57
|
views: {
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAA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E,MAAM,EAAE,iBAAiB,EAAE,IAAI,EAAE,iBAAiB,EAAE,QAAQ,EAAE,CAAC,EAAE,eAAe,EAAE,IAAI,EAAE,CAAC,EAAE,EAAE;aACnP,EAAE,CAAC;CAC0C,CAAC;AAEjD,MAAM,CAAC,MAAM,0BAA0B,GAAG,oBAAoB,CAAC,8BAA8B,CAAC,CAAC;AAE/F,MAAM,UAAU,8BAA8B,CAAC,UAA4B;IACzE,OAAO,2BAA2B,CAAC,8BAA8B,EAAE,UAAU,CAAC,CAAC;AACjF,CAAC;AAED,MAAM,UAAU,oCAAoC,CAAC,UAA4B;IAC/E,OAAO,gCAAgC,CAAC,8BAA8B,EAAE,UAAU,CAAC,CAAC;AACtF,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@molda-org/orders-fulfillment",
|
|
3
|
-
"version": "0.1.0-next.
|
|
3
|
+
"version": "0.1.0-next.19",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -17,8 +17,8 @@
|
|
|
17
17
|
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@molda-org/module-contracts": "0.1.0-next.
|
|
21
|
-
"@molda-org/module-runtime": "0.1.0-next.
|
|
20
|
+
"@molda-org/module-contracts": "0.1.0-next.19",
|
|
21
|
+
"@molda-org/module-runtime": "0.1.0-next.19",
|
|
22
22
|
"zod": "4.6.5"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|