@legible-sync/example-eda 1.2.0
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/.eslintrc.js +16 -0
- package/README.md +103 -0
- package/__tests__/integration/ecommerce-flow.test.ts +247 -0
- package/__tests__/unit/EventBus.test.ts +154 -0
- package/__tests__/unit/PluginManager.test.ts +111 -0
- package/__tests__/unit/concepts/User.test.ts +130 -0
- package/dist/core/EventBus.d.ts +16 -0
- package/dist/core/EventBus.d.ts.map +1 -0
- package/dist/core/EventBus.js +44 -0
- package/dist/core/EventBus.js.map +1 -0
- package/dist/core/PluginManager.d.ts +16 -0
- package/dist/core/PluginManager.d.ts.map +1 -0
- package/dist/core/PluginManager.js +37 -0
- package/dist/core/PluginManager.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +145 -0
- package/dist/index.js.map +1 -0
- package/dist/plugins/analytics/concepts/Analytics.d.ts +3 -0
- package/dist/plugins/analytics/concepts/Analytics.d.ts.map +1 -0
- package/dist/plugins/analytics/concepts/Analytics.js +43 -0
- package/dist/plugins/analytics/concepts/Analytics.js.map +1 -0
- package/dist/plugins/analytics/index.d.ts +3 -0
- package/dist/plugins/analytics/index.d.ts.map +1 -0
- package/dist/plugins/analytics/index.js +16 -0
- package/dist/plugins/analytics/index.js.map +1 -0
- package/dist/plugins/analytics/syncs/analytics-events.sync.d.ts +3 -0
- package/dist/plugins/analytics/syncs/analytics-events.sync.d.ts.map +1 -0
- package/dist/plugins/analytics/syncs/analytics-events.sync.js +101 -0
- package/dist/plugins/analytics/syncs/analytics-events.sync.js.map +1 -0
- package/dist/plugins/inventory/concepts/Inventory.d.ts +3 -0
- package/dist/plugins/inventory/concepts/Inventory.d.ts.map +1 -0
- package/dist/plugins/inventory/concepts/Inventory.js +60 -0
- package/dist/plugins/inventory/concepts/Inventory.js.map +1 -0
- package/dist/plugins/inventory/index.d.ts +3 -0
- package/dist/plugins/inventory/index.d.ts.map +1 -0
- package/dist/plugins/inventory/index.js +15 -0
- package/dist/plugins/inventory/index.js.map +1 -0
- package/dist/plugins/notifications/concepts/Notification.d.ts +3 -0
- package/dist/plugins/notifications/concepts/Notification.d.ts.map +1 -0
- package/dist/plugins/notifications/concepts/Notification.js +42 -0
- package/dist/plugins/notifications/concepts/Notification.js.map +1 -0
- package/dist/plugins/notifications/index.d.ts +3 -0
- package/dist/plugins/notifications/index.d.ts.map +1 -0
- package/dist/plugins/notifications/index.js +15 -0
- package/dist/plugins/notifications/index.js.map +1 -0
- package/dist/plugins/orders/concepts/Order.d.ts +3 -0
- package/dist/plugins/orders/concepts/Order.d.ts.map +1 -0
- package/dist/plugins/orders/concepts/Order.js +98 -0
- package/dist/plugins/orders/concepts/Order.js.map +1 -0
- package/dist/plugins/orders/index.d.ts +3 -0
- package/dist/plugins/orders/index.d.ts.map +1 -0
- package/dist/plugins/orders/index.js +16 -0
- package/dist/plugins/orders/index.js.map +1 -0
- package/dist/plugins/orders/syncs/order-workflow.sync.d.ts +3 -0
- package/dist/plugins/orders/syncs/order-workflow.sync.d.ts.map +1 -0
- package/dist/plugins/orders/syncs/order-workflow.sync.js +168 -0
- package/dist/plugins/orders/syncs/order-workflow.sync.js.map +1 -0
- package/dist/plugins/payments/concepts/Payment.d.ts +3 -0
- package/dist/plugins/payments/concepts/Payment.d.ts.map +1 -0
- package/dist/plugins/payments/concepts/Payment.js +156 -0
- package/dist/plugins/payments/concepts/Payment.js.map +1 -0
- package/dist/plugins/payments/index.d.ts +3 -0
- package/dist/plugins/payments/index.d.ts.map +1 -0
- package/dist/plugins/payments/index.js +16 -0
- package/dist/plugins/payments/index.js.map +1 -0
- package/dist/plugins/payments/syncs/payment-workflow.sync.d.ts +3 -0
- package/dist/plugins/payments/syncs/payment-workflow.sync.d.ts.map +1 -0
- package/dist/plugins/payments/syncs/payment-workflow.sync.js +264 -0
- package/dist/plugins/payments/syncs/payment-workflow.sync.js.map +1 -0
- package/dist/plugins/products/concepts/Product.d.ts +3 -0
- package/dist/plugins/products/concepts/Product.d.ts.map +1 -0
- package/dist/plugins/products/concepts/Product.js +85 -0
- package/dist/plugins/products/concepts/Product.js.map +1 -0
- package/dist/plugins/products/index.d.ts +3 -0
- package/dist/plugins/products/index.d.ts.map +1 -0
- package/dist/plugins/products/index.js +16 -0
- package/dist/plugins/products/index.js.map +1 -0
- package/dist/plugins/products/syncs/product-events.sync.d.ts +3 -0
- package/dist/plugins/products/syncs/product-events.sync.d.ts.map +1 -0
- package/dist/plugins/products/syncs/product-events.sync.js +77 -0
- package/dist/plugins/products/syncs/product-events.sync.js.map +1 -0
- package/dist/plugins/users/concepts/User.d.ts +3 -0
- package/dist/plugins/users/concepts/User.d.ts.map +1 -0
- package/dist/plugins/users/concepts/User.js +81 -0
- package/dist/plugins/users/concepts/User.js.map +1 -0
- package/dist/plugins/users/index.d.ts +3 -0
- package/dist/plugins/users/index.d.ts.map +1 -0
- package/dist/plugins/users/index.js +16 -0
- package/dist/plugins/users/index.js.map +1 -0
- package/dist/plugins/users/syncs/user-events.sync.d.ts +3 -0
- package/dist/plugins/users/syncs/user-events.sync.d.ts.map +1 -0
- package/dist/plugins/users/syncs/user-events.sync.js +75 -0
- package/dist/plugins/users/syncs/user-events.sync.js.map +1 -0
- package/package.json +40 -0
- package/src/core/EventBus.ts +55 -0
- package/src/core/PluginManager.ts +51 -0
- package/src/index.ts +169 -0
- package/src/plugins/analytics/concepts/Analytics.ts +53 -0
- package/src/plugins/analytics/index.ts +15 -0
- package/src/plugins/analytics/syncs/analytics-events.sync.ts +103 -0
- package/src/plugins/inventory/concepts/Inventory.ts +73 -0
- package/src/plugins/inventory/index.ts +14 -0
- package/src/plugins/notifications/concepts/Notification.ts +49 -0
- package/src/plugins/notifications/index.ts +14 -0
- package/src/plugins/orders/concepts/Order.ts +118 -0
- package/src/plugins/orders/index.ts +15 -0
- package/src/plugins/orders/syncs/order-workflow.sync.ts +173 -0
- package/src/plugins/payments/concepts/Payment.ts +186 -0
- package/src/plugins/payments/index.ts +15 -0
- package/src/plugins/payments/syncs/payment-workflow.sync.ts +274 -0
- package/src/plugins/products/concepts/Product.ts +102 -0
- package/src/plugins/products/index.ts +15 -0
- package/src/plugins/products/syncs/product-events.sync.ts +78 -0
- package/src/plugins/users/concepts/User.ts +97 -0
- package/src/plugins/users/index.ts +15 -0
- package/src/plugins/users/syncs/user-events.sync.ts +76 -0
- package/tsconfig.json +9 -0
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Payment = void 0;
|
|
4
|
+
const uuid_1 = require("uuid");
|
|
5
|
+
exports.Payment = {
|
|
6
|
+
state: {
|
|
7
|
+
payments: new Map(),
|
|
8
|
+
transactions: new Map(),
|
|
9
|
+
},
|
|
10
|
+
async execute(action, input) {
|
|
11
|
+
const state = this.state;
|
|
12
|
+
switch (action) {
|
|
13
|
+
case 'initiate': {
|
|
14
|
+
const { orderId, amount, method } = input;
|
|
15
|
+
// Validation
|
|
16
|
+
if (!orderId || !amount || amount <= 0) {
|
|
17
|
+
throw new Error('Order ID and positive amount are required');
|
|
18
|
+
}
|
|
19
|
+
// Create payment
|
|
20
|
+
const paymentId = (0, uuid_1.v4)();
|
|
21
|
+
const payment = {
|
|
22
|
+
id: paymentId,
|
|
23
|
+
orderId,
|
|
24
|
+
amount,
|
|
25
|
+
method: method || 'credit_card',
|
|
26
|
+
status: 'pending',
|
|
27
|
+
createdAt: new Date(),
|
|
28
|
+
transactions: []
|
|
29
|
+
};
|
|
30
|
+
state.payments.set(paymentId, payment);
|
|
31
|
+
return { paymentId, payment };
|
|
32
|
+
}
|
|
33
|
+
case 'process': {
|
|
34
|
+
const { paymentId } = input;
|
|
35
|
+
const payment = state.payments.get(paymentId);
|
|
36
|
+
if (!payment) {
|
|
37
|
+
throw new Error('Payment not found');
|
|
38
|
+
}
|
|
39
|
+
if (payment.status !== 'pending') {
|
|
40
|
+
throw new Error('Payment is not in pending status');
|
|
41
|
+
}
|
|
42
|
+
// Simulate payment processing (in real app, integrate with payment gateway)
|
|
43
|
+
const transactionId = (0, uuid_1.v4)();
|
|
44
|
+
const transaction = {
|
|
45
|
+
id: transactionId,
|
|
46
|
+
paymentId,
|
|
47
|
+
type: 'charge',
|
|
48
|
+
amount: payment.amount,
|
|
49
|
+
status: 'processing',
|
|
50
|
+
gatewayResponse: 'Processing payment...',
|
|
51
|
+
createdAt: new Date()
|
|
52
|
+
};
|
|
53
|
+
state.transactions.set(transactionId, transaction);
|
|
54
|
+
payment.transactions.push(transactionId);
|
|
55
|
+
payment.status = 'processing';
|
|
56
|
+
state.payments.set(paymentId, payment);
|
|
57
|
+
return { payment, transaction };
|
|
58
|
+
}
|
|
59
|
+
case 'confirm': {
|
|
60
|
+
const { paymentId, transactionId } = input;
|
|
61
|
+
const payment = state.payments.get(paymentId);
|
|
62
|
+
const transaction = state.transactions.get(transactionId);
|
|
63
|
+
if (!payment || !transaction) {
|
|
64
|
+
throw new Error('Payment or transaction not found');
|
|
65
|
+
}
|
|
66
|
+
if (payment.status !== 'processing') {
|
|
67
|
+
throw new Error('Payment is not in processing status');
|
|
68
|
+
}
|
|
69
|
+
// Confirm payment
|
|
70
|
+
payment.status = 'completed';
|
|
71
|
+
payment.completedAt = new Date();
|
|
72
|
+
transaction.status = 'completed';
|
|
73
|
+
transaction.gatewayResponse = 'Payment successful';
|
|
74
|
+
transaction.completedAt = new Date();
|
|
75
|
+
state.payments.set(paymentId, payment);
|
|
76
|
+
state.transactions.set(transactionId, transaction);
|
|
77
|
+
return { payment, transaction };
|
|
78
|
+
}
|
|
79
|
+
case 'fail': {
|
|
80
|
+
const { paymentId, reason } = input;
|
|
81
|
+
const payment = state.payments.get(paymentId);
|
|
82
|
+
if (!payment) {
|
|
83
|
+
throw new Error('Payment not found');
|
|
84
|
+
}
|
|
85
|
+
payment.status = 'failed';
|
|
86
|
+
payment.failedAt = new Date();
|
|
87
|
+
payment.failureReason = reason;
|
|
88
|
+
state.payments.set(paymentId, payment);
|
|
89
|
+
// Mark any pending transactions as failed
|
|
90
|
+
for (const txId of payment.transactions) {
|
|
91
|
+
const tx = state.transactions.get(txId);
|
|
92
|
+
if (tx && tx.status === 'processing') {
|
|
93
|
+
tx.status = 'failed';
|
|
94
|
+
tx.gatewayResponse = reason;
|
|
95
|
+
state.transactions.set(txId, tx);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
return { payment };
|
|
99
|
+
}
|
|
100
|
+
case 'refund': {
|
|
101
|
+
const { paymentId, amount, reason } = input;
|
|
102
|
+
const payment = state.payments.get(paymentId);
|
|
103
|
+
if (!payment) {
|
|
104
|
+
throw new Error('Payment not found');
|
|
105
|
+
}
|
|
106
|
+
if (payment.status !== 'completed') {
|
|
107
|
+
throw new Error('Can only refund completed payments');
|
|
108
|
+
}
|
|
109
|
+
const refundAmount = amount || payment.amount;
|
|
110
|
+
if (refundAmount > payment.amount) {
|
|
111
|
+
throw new Error('Refund amount cannot exceed payment amount');
|
|
112
|
+
}
|
|
113
|
+
// Create refund transaction
|
|
114
|
+
const transactionId = (0, uuid_1.v4)();
|
|
115
|
+
const transaction = {
|
|
116
|
+
id: transactionId,
|
|
117
|
+
paymentId,
|
|
118
|
+
type: 'refund',
|
|
119
|
+
amount: refundAmount,
|
|
120
|
+
status: 'completed',
|
|
121
|
+
gatewayResponse: 'Refund processed',
|
|
122
|
+
reason,
|
|
123
|
+
createdAt: new Date(),
|
|
124
|
+
completedAt: new Date()
|
|
125
|
+
};
|
|
126
|
+
state.transactions.set(transactionId, transaction);
|
|
127
|
+
payment.transactions.push(transactionId);
|
|
128
|
+
payment.status = refundAmount === payment.amount ? 'refunded' : 'partially_refunded';
|
|
129
|
+
state.payments.set(paymentId, payment);
|
|
130
|
+
return { payment, transaction };
|
|
131
|
+
}
|
|
132
|
+
case 'get': {
|
|
133
|
+
const { paymentId } = input;
|
|
134
|
+
const payment = state.payments.get(paymentId);
|
|
135
|
+
if (!payment) {
|
|
136
|
+
throw new Error('Payment not found');
|
|
137
|
+
}
|
|
138
|
+
const transactions = payment.transactions.map((txId) => state.transactions.get(txId));
|
|
139
|
+
return { payment: { ...payment, transactions } };
|
|
140
|
+
}
|
|
141
|
+
case 'getByOrderId': {
|
|
142
|
+
const { orderId } = input;
|
|
143
|
+
for (const [paymentId, payment] of state.payments) {
|
|
144
|
+
if (payment.orderId === orderId) {
|
|
145
|
+
const transactions = payment.transactions.map((txId) => state.transactions.get(txId));
|
|
146
|
+
return { payment: { ...payment, transactions }, paymentId };
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
throw new Error('Payment not found for order');
|
|
150
|
+
}
|
|
151
|
+
default:
|
|
152
|
+
throw new Error(`Unknown action: ${action}`);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
//# sourceMappingURL=Payment.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Payment.js","sourceRoot":"","sources":["../../../../src/plugins/payments/concepts/Payment.ts"],"names":[],"mappings":";;;AAEA,+BAAoC;AAEvB,QAAA,OAAO,GAAY;IAC9B,KAAK,EAAE;QACL,QAAQ,EAAE,IAAI,GAAG,EAAe;QAChC,YAAY,EAAE,IAAI,GAAG,EAAe;KACrC;IAED,KAAK,CAAC,OAAO,CAAC,MAAc,EAAE,KAAU;QACtC,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;QAEzB,QAAQ,MAAM,EAAE,CAAC;YACf,KAAK,UAAU,CAAC,CAAC,CAAC;gBAChB,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,KAAK,CAAC;gBAE1C,aAAa;gBACb,IAAI,CAAC,OAAO,IAAI,CAAC,MAAM,IAAI,MAAM,IAAI,CAAC,EAAE,CAAC;oBACvC,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAC;gBAC/D,CAAC;gBAED,iBAAiB;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GAAG,OAAO,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,IAAY,EAAE,EAAE,CAAC,KAAK,CAAC,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC;gBAC9F,OAAO,EAAE,OAAO,EAAE,EAAE,GAAG,OAAO,EAAE,YAAY,EAAE,EAAE,CAAC;YACnD,CAAC;YAED,KAAK,cAAc,CAAC,CAAC,CAAC;gBACpB,MAAM,EAAE,OAAO,EAAE,GAAG,KAAK,CAAC;gBAC1B,KAAK,MAAM,CAAC,SAAS,EAAE,OAAO,CAAC,IAAI,KAAK,CAAC,QAAQ,EAAE,CAAC;oBAClD,IAAI,OAAO,CAAC,OAAO,KAAK,OAAO,EAAE,CAAC;wBAChC,MAAM,YAAY,GAAG,OAAO,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,IAAY,EAAE,EAAE,CAAC,KAAK,CAAC,YAAY,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC;wBAC9F,OAAO,EAAE,OAAO,EAAE,EAAE,GAAG,OAAO,EAAE,YAAY,EAAE,EAAE,SAAS,EAAE,CAAC;oBAC9D,CAAC;gBACH,CAAC;gBACD,MAAM,IAAI,KAAK,CAAC,6BAA6B,CAAC,CAAC;YACjD,CAAC;YAED;gBACE,MAAM,IAAI,KAAK,CAAC,mBAAmB,MAAM,EAAE,CAAC,CAAC;QACjD,CAAC;IACH,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/payments/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAIlD,eAAO,MAAM,cAAc,EAAE,MAS5B,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.paymentsPlugin = void 0;
|
|
4
|
+
const Payment_1 = require("./concepts/Payment");
|
|
5
|
+
const payment_workflow_sync_1 = require("./syncs/payment-workflow.sync");
|
|
6
|
+
exports.paymentsPlugin = {
|
|
7
|
+
name: 'payments',
|
|
8
|
+
concepts: {
|
|
9
|
+
Payment: Payment_1.Payment
|
|
10
|
+
},
|
|
11
|
+
syncs: payment_workflow_sync_1.paymentWorkflowSyncs,
|
|
12
|
+
initialize: async (_engine) => {
|
|
13
|
+
console.log('💳 Payments plugin initialized');
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/plugins/payments/index.ts"],"names":[],"mappings":";;;AAEA,gDAA6C;AAC7C,yEAAqE;AAExD,QAAA,cAAc,GAAW;IACpC,IAAI,EAAE,UAAU;IAChB,QAAQ,EAAE;QACR,OAAO,EAAP,iBAAO;KACR;IACD,KAAK,EAAE,4CAAoB;IAC3B,UAAU,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE;QAC5B,OAAO,CAAC,GAAG,CAAC,gCAAgC,CAAC,CAAC;IAChD,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"payment-workflow.sync.d.ts","sourceRoot":"","sources":["../../../../src/plugins/payments/syncs/payment-workflow.sync.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAE9C,eAAO,MAAM,oBAAoB,EAAE,QAAQ,EA8Q1C,CAAC"}
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.paymentWorkflowSyncs = void 0;
|
|
4
|
+
exports.paymentWorkflowSyncs = [
|
|
5
|
+
// When order is confirmed, initiate payment
|
|
6
|
+
{
|
|
7
|
+
name: "InitiatePaymentOnOrderConfirm",
|
|
8
|
+
when: [
|
|
9
|
+
{
|
|
10
|
+
concept: "Order",
|
|
11
|
+
action: "confirm"
|
|
12
|
+
}
|
|
13
|
+
],
|
|
14
|
+
then: [
|
|
15
|
+
{
|
|
16
|
+
concept: "Payment",
|
|
17
|
+
action: "initiate",
|
|
18
|
+
input: {
|
|
19
|
+
orderId: "?orderId",
|
|
20
|
+
amount: "?order.total",
|
|
21
|
+
method: "credit_card"
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
]
|
|
25
|
+
},
|
|
26
|
+
// When payment is initiated, automatically process it
|
|
27
|
+
{
|
|
28
|
+
name: "AutoProcessPayment",
|
|
29
|
+
when: [
|
|
30
|
+
{
|
|
31
|
+
concept: "Payment",
|
|
32
|
+
action: "initiate"
|
|
33
|
+
}
|
|
34
|
+
],
|
|
35
|
+
then: [
|
|
36
|
+
{
|
|
37
|
+
concept: "Payment",
|
|
38
|
+
action: "process",
|
|
39
|
+
input: {
|
|
40
|
+
paymentId: "?paymentId"
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
]
|
|
44
|
+
},
|
|
45
|
+
// When payment processing starts, confirm it (simplified for demo)
|
|
46
|
+
{
|
|
47
|
+
name: "AutoConfirmPayment",
|
|
48
|
+
when: [
|
|
49
|
+
{
|
|
50
|
+
concept: "Payment",
|
|
51
|
+
action: "process"
|
|
52
|
+
}
|
|
53
|
+
],
|
|
54
|
+
then: [
|
|
55
|
+
{
|
|
56
|
+
concept: "Payment",
|
|
57
|
+
action: "confirm",
|
|
58
|
+
input: {
|
|
59
|
+
paymentId: "?paymentId",
|
|
60
|
+
transactionId: "?transaction.id"
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
]
|
|
64
|
+
},
|
|
65
|
+
// When payment is confirmed, get order details first
|
|
66
|
+
{
|
|
67
|
+
name: "GetOrderDetailsAfterPaymentConfirm",
|
|
68
|
+
when: [
|
|
69
|
+
{
|
|
70
|
+
concept: "Payment",
|
|
71
|
+
action: "confirm"
|
|
72
|
+
}
|
|
73
|
+
],
|
|
74
|
+
then: [
|
|
75
|
+
{
|
|
76
|
+
concept: "Order",
|
|
77
|
+
action: "get",
|
|
78
|
+
input: {
|
|
79
|
+
orderId: "?payment.orderId"
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
]
|
|
83
|
+
},
|
|
84
|
+
// When order details are retrieved after payment confirmation, get user details
|
|
85
|
+
{
|
|
86
|
+
name: "GetUserDetailsAfterPaymentConfirm",
|
|
87
|
+
when: [
|
|
88
|
+
{
|
|
89
|
+
concept: "Order",
|
|
90
|
+
action: "get"
|
|
91
|
+
}
|
|
92
|
+
],
|
|
93
|
+
then: [
|
|
94
|
+
{
|
|
95
|
+
concept: "User",
|
|
96
|
+
action: "get",
|
|
97
|
+
input: {
|
|
98
|
+
userId: "?order.userId"
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
]
|
|
102
|
+
},
|
|
103
|
+
// When user details are retrieved after payment confirmation, send notification
|
|
104
|
+
{
|
|
105
|
+
name: "SendPaymentSuccessNotification",
|
|
106
|
+
when: [
|
|
107
|
+
{
|
|
108
|
+
concept: "User",
|
|
109
|
+
action: "get"
|
|
110
|
+
}
|
|
111
|
+
],
|
|
112
|
+
then: [
|
|
113
|
+
{
|
|
114
|
+
concept: "Notification",
|
|
115
|
+
action: "send",
|
|
116
|
+
input: {
|
|
117
|
+
type: "email",
|
|
118
|
+
to: "?user.email",
|
|
119
|
+
template: "payment-success",
|
|
120
|
+
data: {
|
|
121
|
+
orderId: "?payment.orderId",
|
|
122
|
+
amount: "?payment.amount",
|
|
123
|
+
paymentId: "?paymentId"
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
]
|
|
128
|
+
},
|
|
129
|
+
// When payment fails, get order details first
|
|
130
|
+
{
|
|
131
|
+
name: "GetOrderDetailsAfterPaymentFail",
|
|
132
|
+
when: [
|
|
133
|
+
{
|
|
134
|
+
concept: "Payment",
|
|
135
|
+
action: "fail"
|
|
136
|
+
}
|
|
137
|
+
],
|
|
138
|
+
then: [
|
|
139
|
+
{
|
|
140
|
+
concept: "Order",
|
|
141
|
+
action: "get",
|
|
142
|
+
input: {
|
|
143
|
+
orderId: "?payment.orderId"
|
|
144
|
+
}
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
concept: "Order",
|
|
148
|
+
action: "cancel",
|
|
149
|
+
input: {
|
|
150
|
+
orderId: "?payment.orderId"
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
]
|
|
154
|
+
},
|
|
155
|
+
// When order details are retrieved after payment failure, get user details
|
|
156
|
+
{
|
|
157
|
+
name: "GetUserDetailsAfterPaymentFail",
|
|
158
|
+
when: [
|
|
159
|
+
{
|
|
160
|
+
concept: "Order",
|
|
161
|
+
action: "get"
|
|
162
|
+
}
|
|
163
|
+
],
|
|
164
|
+
then: [
|
|
165
|
+
{
|
|
166
|
+
concept: "User",
|
|
167
|
+
action: "get",
|
|
168
|
+
input: {
|
|
169
|
+
userId: "?order.userId"
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
]
|
|
173
|
+
},
|
|
174
|
+
// When user details are retrieved after payment failure, send notification
|
|
175
|
+
{
|
|
176
|
+
name: "SendPaymentFailureNotification",
|
|
177
|
+
when: [
|
|
178
|
+
{
|
|
179
|
+
concept: "User",
|
|
180
|
+
action: "get"
|
|
181
|
+
}
|
|
182
|
+
],
|
|
183
|
+
then: [
|
|
184
|
+
{
|
|
185
|
+
concept: "Notification",
|
|
186
|
+
action: "send",
|
|
187
|
+
input: {
|
|
188
|
+
type: "email",
|
|
189
|
+
to: "?user.email",
|
|
190
|
+
template: "payment-failed",
|
|
191
|
+
data: {
|
|
192
|
+
orderId: "?payment.orderId",
|
|
193
|
+
reason: "?payment.failureReason"
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
]
|
|
198
|
+
},
|
|
199
|
+
// When refund is processed, get order details first
|
|
200
|
+
{
|
|
201
|
+
name: "GetOrderDetailsAfterRefund",
|
|
202
|
+
when: [
|
|
203
|
+
{
|
|
204
|
+
concept: "Payment",
|
|
205
|
+
action: "refund"
|
|
206
|
+
}
|
|
207
|
+
],
|
|
208
|
+
then: [
|
|
209
|
+
{
|
|
210
|
+
concept: "Order",
|
|
211
|
+
action: "get",
|
|
212
|
+
input: {
|
|
213
|
+
orderId: "?payment.orderId"
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
]
|
|
217
|
+
},
|
|
218
|
+
// When order details are retrieved after refund, get user details
|
|
219
|
+
{
|
|
220
|
+
name: "GetUserDetailsAfterRefund",
|
|
221
|
+
when: [
|
|
222
|
+
{
|
|
223
|
+
concept: "Order",
|
|
224
|
+
action: "get"
|
|
225
|
+
}
|
|
226
|
+
],
|
|
227
|
+
then: [
|
|
228
|
+
{
|
|
229
|
+
concept: "User",
|
|
230
|
+
action: "get",
|
|
231
|
+
input: {
|
|
232
|
+
userId: "?order.userId"
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
]
|
|
236
|
+
},
|
|
237
|
+
// When user details are retrieved after refund, send notification
|
|
238
|
+
{
|
|
239
|
+
name: "SendRefundNotification",
|
|
240
|
+
when: [
|
|
241
|
+
{
|
|
242
|
+
concept: "User",
|
|
243
|
+
action: "get"
|
|
244
|
+
}
|
|
245
|
+
],
|
|
246
|
+
then: [
|
|
247
|
+
{
|
|
248
|
+
concept: "Notification",
|
|
249
|
+
action: "send",
|
|
250
|
+
input: {
|
|
251
|
+
type: "email",
|
|
252
|
+
to: "?user.email",
|
|
253
|
+
template: "payment-refund",
|
|
254
|
+
data: {
|
|
255
|
+
orderId: "?payment.orderId",
|
|
256
|
+
amount: "?transaction.amount",
|
|
257
|
+
reason: "?transaction.reason"
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
]
|
|
262
|
+
}
|
|
263
|
+
];
|
|
264
|
+
//# sourceMappingURL=payment-workflow.sync.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"payment-workflow.sync.js","sourceRoot":"","sources":["../../../../src/plugins/payments/syncs/payment-workflow.sync.ts"],"names":[],"mappings":";;;AAGa,QAAA,oBAAoB,GAAe;IAC9C,4CAA4C;IAC5C;QACE,IAAI,EAAE,+BAA+B;QACrC,IAAI,EAAE;YACJ;gBACE,OAAO,EAAE,OAAO;gBAChB,MAAM,EAAE,SAAS;aAClB;SACF;QACD,IAAI,EAAE;YACJ;gBACE,OAAO,EAAE,SAAS;gBAClB,MAAM,EAAE,UAAU;gBAClB,KAAK,EAAE;oBACL,OAAO,EAAE,UAAU;oBACnB,MAAM,EAAE,cAAc;oBACtB,MAAM,EAAE,aAAa;iBACtB;aACF;SACF;KACF;IAED,sDAAsD;IACtD;QACE,IAAI,EAAE,oBAAoB;QAC1B,IAAI,EAAE;YACJ;gBACE,OAAO,EAAE,SAAS;gBAClB,MAAM,EAAE,UAAU;aACnB;SACF;QACD,IAAI,EAAE;YACJ;gBACE,OAAO,EAAE,SAAS;gBAClB,MAAM,EAAE,SAAS;gBACjB,KAAK,EAAE;oBACL,SAAS,EAAE,YAAY;iBACxB;aACF;SACF;KACF;IAED,mEAAmE;IACnE;QACE,IAAI,EAAE,oBAAoB;QAC1B,IAAI,EAAE;YACJ;gBACE,OAAO,EAAE,SAAS;gBAClB,MAAM,EAAE,SAAS;aAClB;SACF;QACD,IAAI,EAAE;YACJ;gBACE,OAAO,EAAE,SAAS;gBAClB,MAAM,EAAE,SAAS;gBACjB,KAAK,EAAE;oBACL,SAAS,EAAE,YAAY;oBACvB,aAAa,EAAE,iBAAiB;iBACjC;aACF;SACF;KACF;IAED,qDAAqD;IACrD;QACE,IAAI,EAAE,oCAAoC;QAC1C,IAAI,EAAE;YACJ;gBACE,OAAO,EAAE,SAAS;gBAClB,MAAM,EAAE,SAAS;aAClB;SACF;QACD,IAAI,EAAE;YACJ;gBACE,OAAO,EAAE,OAAO;gBAChB,MAAM,EAAE,KAAK;gBACb,KAA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;YACJ;gBACE,OAAO,EAAE,cAAc;gBACvB,MAAM,EAAE,MAAM;gBACd,KAAK,EAAE;oBACL,IAAI,EAAE,OAAO;oBACb,EAAE,EAAE,aAAa;oBACjB,QAAQ,EAAE,gBAAgB;oBAC1B,IAAI,EAAE;wBACJ,OAAO,EAAE,kBAAkB;wBAC3B,MAAM,EAAE,qBAAqB;wBAC7B,MAAM,EAAE,qBAAqB;qBAC9B;iBACF;aACF;SACF;KACF;CACF,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Product.d.ts","sourceRoot":"","sources":["../../../../src/plugins/products/concepts/Product.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAG7C,eAAO,MAAM,OAAO,EAAE,OAiGrB,CAAC"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Product = void 0;
|
|
4
|
+
const uuid_1 = require("uuid");
|
|
5
|
+
exports.Product = {
|
|
6
|
+
state: {
|
|
7
|
+
products: new Map(),
|
|
8
|
+
skus: new Set(),
|
|
9
|
+
},
|
|
10
|
+
async execute(action, input) {
|
|
11
|
+
const state = this.state;
|
|
12
|
+
switch (action) {
|
|
13
|
+
case 'create': {
|
|
14
|
+
const { name, sku, price, description, category } = input;
|
|
15
|
+
// Validation
|
|
16
|
+
if (!name || !sku || price === undefined) {
|
|
17
|
+
throw new Error('Name, SKU, and price are required');
|
|
18
|
+
}
|
|
19
|
+
if (state.skus.has(sku)) {
|
|
20
|
+
throw new Error('SKU already exists');
|
|
21
|
+
}
|
|
22
|
+
// Create product
|
|
23
|
+
const productId = (0, uuid_1.v4)();
|
|
24
|
+
const product = {
|
|
25
|
+
id: productId,
|
|
26
|
+
name,
|
|
27
|
+
sku,
|
|
28
|
+
price: Number(price),
|
|
29
|
+
description: description || '',
|
|
30
|
+
category: category || 'general',
|
|
31
|
+
status: 'active',
|
|
32
|
+
createdAt: new Date()
|
|
33
|
+
};
|
|
34
|
+
state.products.set(productId, product);
|
|
35
|
+
state.skus.add(sku);
|
|
36
|
+
return { productId, product };
|
|
37
|
+
}
|
|
38
|
+
case 'get': {
|
|
39
|
+
const { productId } = input;
|
|
40
|
+
const product = state.products.get(productId);
|
|
41
|
+
if (!product) {
|
|
42
|
+
throw new Error('Product not found');
|
|
43
|
+
}
|
|
44
|
+
return { product };
|
|
45
|
+
}
|
|
46
|
+
case 'update': {
|
|
47
|
+
const { productId, updates } = input;
|
|
48
|
+
const product = state.products.get(productId);
|
|
49
|
+
if (!product) {
|
|
50
|
+
throw new Error('Product not found');
|
|
51
|
+
}
|
|
52
|
+
// Update product
|
|
53
|
+
const updatedProduct = { ...product, ...updates, updatedAt: new Date() };
|
|
54
|
+
state.products.set(productId, updatedProduct);
|
|
55
|
+
return { product: updatedProduct };
|
|
56
|
+
}
|
|
57
|
+
case 'deactivate': {
|
|
58
|
+
const { productId } = input;
|
|
59
|
+
const product = state.products.get(productId);
|
|
60
|
+
if (!product) {
|
|
61
|
+
throw new Error('Product not found');
|
|
62
|
+
}
|
|
63
|
+
product.status = 'inactive';
|
|
64
|
+
product.deactivatedAt = new Date();
|
|
65
|
+
state.products.set(productId, product);
|
|
66
|
+
return { product };
|
|
67
|
+
}
|
|
68
|
+
case 'list': {
|
|
69
|
+
const { category, status = 'active' } = input;
|
|
70
|
+
const products = Array.from(state.products.values())
|
|
71
|
+
.filter((p) => p.status === status)
|
|
72
|
+
.filter((p) => !category || p.category === category);
|
|
73
|
+
return { products };
|
|
74
|
+
}
|
|
75
|
+
case 'reset': {
|
|
76
|
+
state.products.clear();
|
|
77
|
+
state.skus.clear();
|
|
78
|
+
return { reset: true };
|
|
79
|
+
}
|
|
80
|
+
default:
|
|
81
|
+
throw new Error(`Unknown action: ${action}`);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
//# sourceMappingURL=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use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.productsPlugin = void 0;
|
|
4
|
+
const Product_1 = require("./concepts/Product");
|
|
5
|
+
const product_events_sync_1 = require("./syncs/product-events.sync");
|
|
6
|
+
exports.productsPlugin = {
|
|
7
|
+
name: 'products',
|
|
8
|
+
concepts: {
|
|
9
|
+
Product: Product_1.Product
|
|
10
|
+
},
|
|
11
|
+
syncs: product_events_sync_1.productEventSyncs,
|
|
12
|
+
initialize: async (_engine) => {
|
|
13
|
+
console.log('📦 Products plugin initialized');
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/plugins/products/index.ts"],"names":[],"mappings":";;;AAEA,gDAA6C;AAC7C,qEAAgE;AAEnD,QAAA,cAAc,GAAW;IACpC,IAAI,EAAE,UAAU;IAChB,QAAQ,EAAE;QACR,OAAO,EAAP,iBAAO;KACR;IACD,KAAK,EAAE,uCAAiB;IACxB,UAAU,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE;QAC5B,OAAO,CAAC,GAAG,CAAC,gCAAgC,CAAC,CAAC;IAChD,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"product-events.sync.d.ts","sourceRoot":"","sources":["../../../../src/plugins/products/syncs/product-events.sync.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAE9C,eAAO,MAAM,iBAAiB,EAAE,QAAQ,EA0EvC,CAAC"}
|