@legible-sync/example-eda 1.2.0 → 1.3.1
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/CHANGELOG.md +30 -0
- package/LICENSE +24 -0
- package/__tests__/integration/ecommerce-flow.test.ts +1 -0
- package/__tests__/integration/syncs.test.ts +438 -0
- package/dist/plugins/analytics/concepts/Analytics.d.ts.map +1 -1
- package/dist/plugins/analytics/concepts/Analytics.js +5 -0
- package/dist/plugins/analytics/concepts/Analytics.js.map +1 -1
- package/dist/plugins/inventory/concepts/Inventory.d.ts.map +1 -1
- package/dist/plugins/inventory/concepts/Inventory.js +15 -5
- package/dist/plugins/inventory/concepts/Inventory.js.map +1 -1
- package/dist/plugins/notifications/concepts/Notification.d.ts.map +1 -1
- package/dist/plugins/notifications/concepts/Notification.js +4 -0
- package/dist/plugins/notifications/concepts/Notification.js.map +1 -1
- package/dist/plugins/orders/concepts/Order.d.ts.map +1 -1
- package/dist/plugins/orders/concepts/Order.js +8 -3
- package/dist/plugins/orders/concepts/Order.js.map +1 -1
- package/dist/plugins/payments/concepts/Payment.d.ts.map +1 -1
- package/dist/plugins/payments/concepts/Payment.js +5 -0
- package/dist/plugins/payments/concepts/Payment.js.map +1 -1
- package/eda_output.txt +3963 -0
- package/jest.config.js +18 -0
- package/package.json +3 -3
- package/src/plugins/analytics/concepts/Analytics.ts +6 -0
- package/src/plugins/analytics/syncs/analytics-events.sync.ts +2 -1
- package/src/plugins/inventory/concepts/Inventory.ts +16 -5
- package/src/plugins/notifications/concepts/Notification.ts +5 -0
- package/src/plugins/orders/concepts/Order.ts +9 -3
- package/src/plugins/payments/concepts/Payment.ts +6 -0
package/jest.config.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
preset: 'ts-jest',
|
|
3
|
+
testEnvironment: 'node',
|
|
4
|
+
roots: ['<rootDir>/src', '<rootDir>/__tests__'],
|
|
5
|
+
testMatch: [
|
|
6
|
+
'**/__tests__/**/*.test.ts',
|
|
7
|
+
'**/?(*.)+(spec|test).ts'
|
|
8
|
+
],
|
|
9
|
+
collectCoverageFrom: [
|
|
10
|
+
'src/**/*.ts',
|
|
11
|
+
'!src/**/*.d.ts',
|
|
12
|
+
],
|
|
13
|
+
coverageDirectory: 'coverage',
|
|
14
|
+
coverageReporters: ['text', 'lcov', 'html'],
|
|
15
|
+
moduleNameMapper: {
|
|
16
|
+
'^@legible-sync/core$': '<rootDir>/../core/src/index.ts'
|
|
17
|
+
}
|
|
18
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@legible-sync/example-eda",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.1",
|
|
4
4
|
"description": "Event-Driven Architecture example with plugin-based modules",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"test:coverage": "jest --coverage"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@legible-sync/core": "^1.
|
|
17
|
+
"@legible-sync/core": "^1.3.1"
|
|
18
18
|
},
|
|
19
19
|
"repository": {
|
|
20
20
|
"type": "git",
|
|
@@ -36,5 +36,5 @@
|
|
|
36
36
|
"engines": {
|
|
37
37
|
"node": ">=18.0.0"
|
|
38
38
|
},
|
|
39
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "df679d07b929740ff34e4b4e23095446acb69a67"
|
|
40
40
|
}
|
|
@@ -46,6 +46,12 @@ export const Analytics: Concept = {
|
|
|
46
46
|
return { events: events.slice(-limit) };
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
+
case 'reset': {
|
|
50
|
+
state.events.clear();
|
|
51
|
+
state.metrics.clear();
|
|
52
|
+
return { success: true };
|
|
53
|
+
}
|
|
54
|
+
|
|
49
55
|
default:
|
|
50
56
|
throw new Error(`Unknown action: ${action}`);
|
|
51
57
|
}
|
|
@@ -29,16 +29,21 @@ export const Inventory: Concept = {
|
|
|
29
29
|
const unavailable: any[] = [];
|
|
30
30
|
|
|
31
31
|
for (const item of items) {
|
|
32
|
+
console.log(`[Inventory.checkAvailability] Processing item: productId=${item.productId}, quantity=${item.quantity}, price=${item.price}`);
|
|
33
|
+
const parsedQuantity = parseFloat(item.quantity) || 0;
|
|
34
|
+
console.log(`[Inventory.checkAvailability] Parsed quantity: ${parsedQuantity}`);
|
|
35
|
+
const parsedPrice = parseFloat(item.price) || 0;
|
|
36
|
+
console.log(`[Inventory.checkAvailability] Parsed price: ${parsedPrice}`);
|
|
32
37
|
const stock = state.stock.get(item.productId) || 0;
|
|
33
|
-
if (stock <
|
|
38
|
+
if (stock < parsedQuantity) {
|
|
34
39
|
unavailable.push({
|
|
35
40
|
productId: item.productId,
|
|
36
|
-
requested:
|
|
41
|
+
requested: parsedQuantity,
|
|
37
42
|
available: stock
|
|
38
43
|
});
|
|
39
44
|
}
|
|
40
45
|
// Calculate total from input items (prices should be provided)
|
|
41
|
-
total +=
|
|
46
|
+
total += parsedQuantity * parsedPrice;
|
|
42
47
|
}
|
|
43
48
|
|
|
44
49
|
const available = unavailable.length === 0;
|
|
@@ -49,12 +54,13 @@ export const Inventory: Concept = {
|
|
|
49
54
|
const { orderId, items } = input;
|
|
50
55
|
|
|
51
56
|
for (const item of items) {
|
|
57
|
+
const parsedQuantity = parseFloat(item.quantity) || 0;
|
|
52
58
|
const currentStock = state.stock.get(item.productId) || 0;
|
|
53
|
-
if (currentStock <
|
|
59
|
+
if (currentStock < parsedQuantity) {
|
|
54
60
|
throw new Error(`Insufficient stock for product ${item.productId}`);
|
|
55
61
|
}
|
|
56
62
|
|
|
57
|
-
state.stock.set(item.productId, currentStock -
|
|
63
|
+
state.stock.set(item.productId, currentStock - parsedQuantity);
|
|
58
64
|
}
|
|
59
65
|
|
|
60
66
|
return { success: true };
|
|
@@ -66,6 +72,11 @@ export const Inventory: Concept = {
|
|
|
66
72
|
return { productId, quantity };
|
|
67
73
|
}
|
|
68
74
|
|
|
75
|
+
case 'reset': {
|
|
76
|
+
state.stock.clear();
|
|
77
|
+
return { reset: true };
|
|
78
|
+
}
|
|
79
|
+
|
|
69
80
|
default:
|
|
70
81
|
throw new Error(`Unknown action: ${action}`);
|
|
71
82
|
}
|
|
@@ -37,8 +37,8 @@ export const Order: Concept = {
|
|
|
37
37
|
createdAt: new Date(),
|
|
38
38
|
items: items.map((item: any) => ({
|
|
39
39
|
productId: item.productId,
|
|
40
|
-
quantity: item.quantity,
|
|
41
|
-
price: item.price || 0
|
|
40
|
+
quantity: parseFloat(item.quantity) || 0,
|
|
41
|
+
price: parseFloat(item.price) || 0
|
|
42
42
|
}))
|
|
43
43
|
};
|
|
44
44
|
|
|
@@ -60,7 +60,7 @@ export const Order: Concept = {
|
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
order.status = 'confirmed';
|
|
63
|
-
order.total = total;
|
|
63
|
+
order.total = parseFloat(total);
|
|
64
64
|
order.confirmedAt = new Date();
|
|
65
65
|
state.orders.set(orderId, order);
|
|
66
66
|
|
|
@@ -111,6 +111,12 @@ export const Order: Concept = {
|
|
|
111
111
|
return { order: { ...order, items } };
|
|
112
112
|
}
|
|
113
113
|
|
|
114
|
+
case 'reset': {
|
|
115
|
+
state.orders.clear();
|
|
116
|
+
state.orderItems.clear();
|
|
117
|
+
return { reset: true };
|
|
118
|
+
}
|
|
119
|
+
|
|
114
120
|
default:
|
|
115
121
|
throw new Error(`Unknown action: ${action}`);
|
|
116
122
|
}
|
|
@@ -179,6 +179,12 @@ export const Payment: Concept = {
|
|
|
179
179
|
throw new Error('Payment not found for order');
|
|
180
180
|
}
|
|
181
181
|
|
|
182
|
+
case 'reset': {
|
|
183
|
+
state.payments.clear();
|
|
184
|
+
state.transactions.clear();
|
|
185
|
+
return { reset: true };
|
|
186
|
+
}
|
|
187
|
+
|
|
182
188
|
default:
|
|
183
189
|
throw new Error(`Unknown action: ${action}`);
|
|
184
190
|
}
|