@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,97 @@
|
|
|
1
|
+
// plugins/users/concepts/User.ts
|
|
2
|
+
import { Concept } from '@legible-sync/core';
|
|
3
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
4
|
+
|
|
5
|
+
export const User: Concept = {
|
|
6
|
+
state: {
|
|
7
|
+
users: new Map<string, any>(),
|
|
8
|
+
emails: new Set<string>(),
|
|
9
|
+
usernames: new Set<string>(),
|
|
10
|
+
},
|
|
11
|
+
|
|
12
|
+
async execute(action: string, input: any) {
|
|
13
|
+
const state = this.state;
|
|
14
|
+
|
|
15
|
+
switch (action) {
|
|
16
|
+
case 'register': {
|
|
17
|
+
const { username, email, password } = input;
|
|
18
|
+
|
|
19
|
+
// Validation
|
|
20
|
+
if (!username || !email || !password) {
|
|
21
|
+
throw new Error('Username, email, and password are required');
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (state.emails.has(email)) {
|
|
25
|
+
throw new Error('Email already registered');
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (state.usernames.has(username)) {
|
|
29
|
+
throw new Error('Username already taken');
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Create user
|
|
33
|
+
const userId = uuidv4();
|
|
34
|
+
const user = {
|
|
35
|
+
id: userId,
|
|
36
|
+
username,
|
|
37
|
+
email,
|
|
38
|
+
createdAt: new Date(),
|
|
39
|
+
status: 'active'
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
state.users.set(userId, user);
|
|
43
|
+
state.emails.add(email);
|
|
44
|
+
state.usernames.add(username);
|
|
45
|
+
|
|
46
|
+
return { userId, user };
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
case 'get': {
|
|
50
|
+
const { userId } = input;
|
|
51
|
+
const user = state.users.get(userId);
|
|
52
|
+
if (!user) {
|
|
53
|
+
throw new Error('User not found');
|
|
54
|
+
}
|
|
55
|
+
return { user };
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
case 'update': {
|
|
59
|
+
const { userId, updates } = input;
|
|
60
|
+
const user = state.users.get(userId);
|
|
61
|
+
if (!user) {
|
|
62
|
+
throw new Error('User not found');
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Update user
|
|
66
|
+
const updatedUser = { ...user, ...updates, updatedAt: new Date() };
|
|
67
|
+
state.users.set(userId, updatedUser);
|
|
68
|
+
|
|
69
|
+
return { user: updatedUser };
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
case 'deactivate': {
|
|
73
|
+
const { userId } = input;
|
|
74
|
+
const user = state.users.get(userId);
|
|
75
|
+
if (!user) {
|
|
76
|
+
throw new Error('User not found');
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
user.status = 'inactive';
|
|
80
|
+
user.deactivatedAt = new Date();
|
|
81
|
+
state.users.set(userId, user);
|
|
82
|
+
|
|
83
|
+
return { user };
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
case 'reset': {
|
|
87
|
+
state.users.clear();
|
|
88
|
+
state.emails.clear();
|
|
89
|
+
state.usernames.clear();
|
|
90
|
+
return { reset: true };
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
default:
|
|
94
|
+
throw new Error(`Unknown action: ${action}`);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// plugins/users/index.ts
|
|
2
|
+
import { Plugin } from '../../core/PluginManager';
|
|
3
|
+
import { User } from './concepts/User';
|
|
4
|
+
import { userEventSyncs } from './syncs/user-events.sync';
|
|
5
|
+
|
|
6
|
+
export const usersPlugin: Plugin = {
|
|
7
|
+
name: 'users',
|
|
8
|
+
concepts: {
|
|
9
|
+
User
|
|
10
|
+
},
|
|
11
|
+
syncs: userEventSyncs,
|
|
12
|
+
initialize: async (_engine) => {
|
|
13
|
+
console.log('👤 Users plugin initialized');
|
|
14
|
+
}
|
|
15
|
+
};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
// plugins/users/syncs/user-events.sync.ts
|
|
2
|
+
import { SyncRule } from '@legible-sync/core';
|
|
3
|
+
|
|
4
|
+
export const userEventSyncs: SyncRule[] = [
|
|
5
|
+
// When a user registers, publish user.registered event
|
|
6
|
+
{
|
|
7
|
+
name: "PublishUserRegisteredEvent",
|
|
8
|
+
when: [
|
|
9
|
+
{
|
|
10
|
+
concept: "User",
|
|
11
|
+
action: "register"
|
|
12
|
+
}
|
|
13
|
+
],
|
|
14
|
+
then: [
|
|
15
|
+
{
|
|
16
|
+
concept: "EventBus",
|
|
17
|
+
action: "publish",
|
|
18
|
+
input: {
|
|
19
|
+
event: "user.registered",
|
|
20
|
+
data: {
|
|
21
|
+
userId: "?userId",
|
|
22
|
+
username: "?user.username",
|
|
23
|
+
email: "?user.email"
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
]
|
|
28
|
+
},
|
|
29
|
+
|
|
30
|
+
// When a user is updated, publish user.updated event
|
|
31
|
+
{
|
|
32
|
+
name: "PublishUserUpdatedEvent",
|
|
33
|
+
when: [
|
|
34
|
+
{
|
|
35
|
+
concept: "User",
|
|
36
|
+
action: "update"
|
|
37
|
+
}
|
|
38
|
+
],
|
|
39
|
+
then: [
|
|
40
|
+
{
|
|
41
|
+
concept: "EventBus",
|
|
42
|
+
action: "publish",
|
|
43
|
+
input: {
|
|
44
|
+
event: "user.updated",
|
|
45
|
+
data: {
|
|
46
|
+
userId: "?userId",
|
|
47
|
+
updates: "?updates"
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
]
|
|
52
|
+
},
|
|
53
|
+
|
|
54
|
+
// When a user is deactivated, publish user.deactivated event
|
|
55
|
+
{
|
|
56
|
+
name: "PublishUserDeactivatedEvent",
|
|
57
|
+
when: [
|
|
58
|
+
{
|
|
59
|
+
concept: "User",
|
|
60
|
+
action: "deactivate"
|
|
61
|
+
}
|
|
62
|
+
],
|
|
63
|
+
then: [
|
|
64
|
+
{
|
|
65
|
+
concept: "EventBus",
|
|
66
|
+
action: "publish",
|
|
67
|
+
input: {
|
|
68
|
+
event: "user.deactivated",
|
|
69
|
+
data: {
|
|
70
|
+
userId: "?userId"
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
]
|
|
75
|
+
}
|
|
76
|
+
];
|