@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,130 @@
|
|
|
1
|
+
import { User } from '../../../src/plugins/users/concepts/User';
|
|
2
|
+
|
|
3
|
+
describe('User Concept', () => {
|
|
4
|
+
beforeEach(() => {
|
|
5
|
+
// Reset state before each test
|
|
6
|
+
User.state = {
|
|
7
|
+
users: new Map(),
|
|
8
|
+
emails: new Set(),
|
|
9
|
+
usernames: new Set(),
|
|
10
|
+
};
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
describe('User Registration', () => {
|
|
14
|
+
it('should register a new user successfully', async () => {
|
|
15
|
+
const result = await User.execute('register', {
|
|
16
|
+
username: 'testuser',
|
|
17
|
+
email: 'test@example.com',
|
|
18
|
+
password: 'password123'
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
expect(result.userId).toBeDefined();
|
|
22
|
+
expect(result.user.username).toBe('testuser');
|
|
23
|
+
expect(result.user.email).toBe('test@example.com');
|
|
24
|
+
expect(result.user.status).toBe('active');
|
|
25
|
+
expect(result.user.createdAt).toBeInstanceOf(Date);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('should prevent duplicate email registration', async () => {
|
|
29
|
+
await User.execute('register', {
|
|
30
|
+
username: 'user1',
|
|
31
|
+
email: 'same@example.com',
|
|
32
|
+
password: 'pass1'
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
await expect(User.execute('register', {
|
|
36
|
+
username: 'user2',
|
|
37
|
+
email: 'same@example.com',
|
|
38
|
+
password: 'pass2'
|
|
39
|
+
})).rejects.toThrow('Email already registered');
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('should prevent duplicate username registration', async () => {
|
|
43
|
+
await User.execute('register', {
|
|
44
|
+
username: 'sameuser',
|
|
45
|
+
email: 'user1@example.com',
|
|
46
|
+
password: 'pass1'
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
await expect(User.execute('register', {
|
|
50
|
+
username: 'sameuser',
|
|
51
|
+
email: 'user2@example.com',
|
|
52
|
+
password: 'pass2'
|
|
53
|
+
})).rejects.toThrow('Username already taken');
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('should validate required fields', async () => {
|
|
57
|
+
await expect(User.execute('register', {
|
|
58
|
+
username: 'testuser'
|
|
59
|
+
// missing email and password
|
|
60
|
+
})).rejects.toThrow('Username, email, and password are required');
|
|
61
|
+
});
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
describe('User Retrieval', () => {
|
|
65
|
+
it('should get user by ID', async () => {
|
|
66
|
+
const registerResult = await User.execute('register', {
|
|
67
|
+
username: 'testuser',
|
|
68
|
+
email: 'test@example.com',
|
|
69
|
+
password: 'password123'
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
const getResult = await User.execute('get', {
|
|
73
|
+
userId: registerResult.userId
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
expect(getResult.user.id).toBe(registerResult.userId);
|
|
77
|
+
expect(getResult.user.username).toBe('testuser');
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('should throw error for non-existent user', async () => {
|
|
81
|
+
await expect(User.execute('get', {
|
|
82
|
+
userId: 'non-existent-id'
|
|
83
|
+
})).rejects.toThrow('User not found');
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
describe('User Updates', () => {
|
|
88
|
+
it('should update user information', async () => {
|
|
89
|
+
const registerResult = await User.execute('register', {
|
|
90
|
+
username: 'testuser',
|
|
91
|
+
email: 'test@example.com',
|
|
92
|
+
password: 'password123'
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
const updateResult = await User.execute('update', {
|
|
96
|
+
userId: registerResult.userId,
|
|
97
|
+
updates: {
|
|
98
|
+
email: 'newemail@example.com'
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
expect(updateResult.user.email).toBe('newemail@example.com');
|
|
103
|
+
expect(updateResult.user.updatedAt).toBeInstanceOf(Date);
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
describe('User Deactivation', () => {
|
|
108
|
+
it('should deactivate user', async () => {
|
|
109
|
+
const registerResult = await User.execute('register', {
|
|
110
|
+
username: 'testuser',
|
|
111
|
+
email: 'test@example.com',
|
|
112
|
+
password: 'password123'
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
const deactivateResult = await User.execute('deactivate', {
|
|
116
|
+
userId: registerResult.userId
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
expect(deactivateResult.user.status).toBe('inactive');
|
|
120
|
+
expect(deactivateResult.user.deactivatedAt).toBeInstanceOf(Date);
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
describe('Unknown Actions', () => {
|
|
125
|
+
it('should throw error for unknown actions', async () => {
|
|
126
|
+
await expect(User.execute('unknownAction', {}))
|
|
127
|
+
.rejects.toThrow('Unknown action: unknownAction');
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export interface Event {
|
|
2
|
+
type: string;
|
|
3
|
+
payload: Record<string, any>;
|
|
4
|
+
source: string;
|
|
5
|
+
timestamp: Date;
|
|
6
|
+
flowId: string;
|
|
7
|
+
}
|
|
8
|
+
export type EventHandler = (event: Event) => Promise<void>;
|
|
9
|
+
export declare class EventBus {
|
|
10
|
+
private handlers;
|
|
11
|
+
constructor();
|
|
12
|
+
subscribe(eventType: string, handler: EventHandler): void;
|
|
13
|
+
publish(event: Omit<Event, 'timestamp'>): Promise<void>;
|
|
14
|
+
createEventFromAction(concept: string, action: string, input: any, output: any, flowId: string): Event;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=EventBus.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EventBus.d.ts","sourceRoot":"","sources":["../../src/core/EventBus.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,KAAK;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,IAAI,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,MAAM,YAAY,GAAG,CAAC,KAAK,EAAE,KAAK,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;AAE3D,qBAAa,QAAQ;IACnB,OAAO,CAAC,QAAQ,CAA0C;;IAM1D,SAAS,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,YAAY,GAAG,IAAI;IAOnD,OAAO,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,WAAW,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAmB7D,qBAAqB,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,GAAG,KAAK;CASvG"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// core/EventBus.ts
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.EventBus = void 0;
|
|
5
|
+
class EventBus {
|
|
6
|
+
constructor() {
|
|
7
|
+
this.handlers = new Map();
|
|
8
|
+
// EventBus is independent of the LegibleEngine
|
|
9
|
+
}
|
|
10
|
+
subscribe(eventType, handler) {
|
|
11
|
+
if (!this.handlers.has(eventType)) {
|
|
12
|
+
this.handlers.set(eventType, []);
|
|
13
|
+
}
|
|
14
|
+
this.handlers.get(eventType).push(handler);
|
|
15
|
+
}
|
|
16
|
+
async publish(event) {
|
|
17
|
+
const fullEvent = {
|
|
18
|
+
...event,
|
|
19
|
+
timestamp: new Date()
|
|
20
|
+
};
|
|
21
|
+
console.log(`📢 Event: ${fullEvent.type} from ${fullEvent.source}`, fullEvent.payload);
|
|
22
|
+
const handlers = this.handlers.get(event.type) || [];
|
|
23
|
+
for (const handler of handlers) {
|
|
24
|
+
try {
|
|
25
|
+
await handler(fullEvent);
|
|
26
|
+
}
|
|
27
|
+
catch (error) {
|
|
28
|
+
// Handler errors are silently ignored to prevent cascading failures
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
// Helper to create events from engine actions
|
|
33
|
+
createEventFromAction(concept, action, input, output, flowId) {
|
|
34
|
+
return {
|
|
35
|
+
type: `${concept}.${action}`,
|
|
36
|
+
payload: { input, output },
|
|
37
|
+
source: concept,
|
|
38
|
+
timestamp: new Date(),
|
|
39
|
+
flowId
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
exports.EventBus = EventBus;
|
|
44
|
+
//# sourceMappingURL=EventBus.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EventBus.js","sourceRoot":"","sources":["../../src/core/EventBus.ts"],"names":[],"mappings":";AAAA,mBAAmB;;;AAYnB,MAAa,QAAQ;IAGnB;QAFQ,aAAQ,GAAgC,IAAI,GAAG,EAAE,CAAC;QAGxD,+CAA+C;IACjD,CAAC;IAED,SAAS,CAAC,SAAiB,EAAE,OAAqB;QAChD,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,CAAC;YAClC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC;QACnC,CAAC;QACD,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,SAAS,CAAE,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAC9C,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,KAA+B;QAC3C,MAAM,SAAS,GAAU;YACvB,GAAG,KAAK;YACR,SAAS,EAAE,IAAI,IAAI,EAAE;SACtB,CAAC;QAEF,OAAO,CAAC,GAAG,CAAC,aAAa,SAAS,CAAC,IAAI,SAAS,SAAS,CAAC,MAAM,EAAE,EAAE,SAAS,CAAC,OAAO,CAAC,CAAC;QAEvF,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;QACrD,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;YAC/B,IAAI,CAAC;gBACH,MAAM,OAAO,CAAC,SAAS,CAAC,CAAC;YAC3B,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,oEAAoE;YACtE,CAAC;QACH,CAAC;IACH,CAAC;IAED,8CAA8C;IAC9C,qBAAqB,CAAC,OAAe,EAAE,MAAc,EAAE,KAAU,EAAE,MAAW,EAAE,MAAc;QAC5F,OAAO;YACL,IAAI,EAAE,GAAG,OAAO,IAAI,MAAM,EAAE;YAC5B,OAAO,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE;YAC1B,MAAM,EAAE,OAAO;YACf,SAAS,EAAE,IAAI,IAAI,EAAE;YACrB,MAAM;SACP,CAAC;IACJ,CAAC;CACF;AA1CD,4BA0CC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { LegibleEngine, Concept, SyncRule } from '@legible-sync/core';
|
|
2
|
+
export interface Plugin {
|
|
3
|
+
name: string;
|
|
4
|
+
concepts: Record<string, Concept>;
|
|
5
|
+
syncs: SyncRule[];
|
|
6
|
+
initialize?: (engine: LegibleEngine) => Promise<void>;
|
|
7
|
+
}
|
|
8
|
+
export declare class PluginManager {
|
|
9
|
+
private engine;
|
|
10
|
+
private loadedPlugins;
|
|
11
|
+
constructor(engine: LegibleEngine);
|
|
12
|
+
loadPlugin(plugin: Plugin): Promise<void>;
|
|
13
|
+
getLoadedPlugins(): string[];
|
|
14
|
+
getPlugin(name: string): Plugin | undefined;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=PluginManager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PluginManager.d.ts","sourceRoot":"","sources":["../../src/core/PluginManager.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAEtE,MAAM,WAAW,MAAM;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,KAAK,EAAE,QAAQ,EAAE,CAAC;IAClB,UAAU,CAAC,EAAE,CAAC,MAAM,EAAE,aAAa,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACvD;AAED,qBAAa,aAAa;IACxB,OAAO,CAAC,MAAM,CAAgB;IAC9B,OAAO,CAAC,aAAa,CAAkC;gBAE3C,MAAM,EAAE,aAAa;IAI3B,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAyB/C,gBAAgB,IAAI,MAAM,EAAE;IAI5B,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;CAG5C"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PluginManager = void 0;
|
|
4
|
+
class PluginManager {
|
|
5
|
+
constructor(engine) {
|
|
6
|
+
this.loadedPlugins = new Map();
|
|
7
|
+
this.engine = engine;
|
|
8
|
+
}
|
|
9
|
+
async loadPlugin(plugin) {
|
|
10
|
+
console.log(`🔌 Loading plugin: ${plugin.name}`);
|
|
11
|
+
// Register concepts
|
|
12
|
+
for (const [name, concept] of Object.entries(plugin.concepts)) {
|
|
13
|
+
this.engine.registerConcept(name, concept);
|
|
14
|
+
console.log(` ✓ Registered concept: ${name}`);
|
|
15
|
+
}
|
|
16
|
+
// Register sync rules
|
|
17
|
+
for (const sync of plugin.syncs) {
|
|
18
|
+
this.engine.registerSync(sync);
|
|
19
|
+
console.log(` ✓ Registered sync: ${sync.name}`);
|
|
20
|
+
}
|
|
21
|
+
// Initialize plugin if needed
|
|
22
|
+
if (plugin.initialize) {
|
|
23
|
+
await plugin.initialize(this.engine);
|
|
24
|
+
console.log(` ✓ Initialized plugin: ${plugin.name}`);
|
|
25
|
+
}
|
|
26
|
+
this.loadedPlugins.set(plugin.name, plugin);
|
|
27
|
+
console.log(`✅ Plugin ${plugin.name} loaded successfully\n`);
|
|
28
|
+
}
|
|
29
|
+
getLoadedPlugins() {
|
|
30
|
+
return Array.from(this.loadedPlugins.keys());
|
|
31
|
+
}
|
|
32
|
+
getPlugin(name) {
|
|
33
|
+
return this.loadedPlugins.get(name);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.PluginManager = PluginManager;
|
|
37
|
+
//# sourceMappingURL=PluginManager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PluginManager.js","sourceRoot":"","sources":["../../src/core/PluginManager.ts"],"names":[],"mappings":";;;AAUA,MAAa,aAAa;IAIxB,YAAY,MAAqB;QAFzB,kBAAa,GAAwB,IAAI,GAAG,EAAE,CAAC;QAGrD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,MAAc;QAC7B,OAAO,CAAC,GAAG,CAAC,sBAAsB,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;QAEjD,oBAAoB;QACpB,KAAK,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,CAAC;YAC9D,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;YAC3C,OAAO,CAAC,GAAG,CAAC,2BAA2B,IAAI,EAAE,CAAC,CAAC;QACjD,CAAC;QAED,sBAAsB;QACtB,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC;YAChC,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;YAC/B,OAAO,CAAC,GAAG,CAAC,wBAAwB,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;QACnD,CAAC;QAED,8BAA8B;QAC9B,IAAI,MAAM,CAAC,UAAU,EAAE,CAAC;YACtB,MAAM,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YACrC,OAAO,CAAC,GAAG,CAAC,2BAA2B,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;QACxD,CAAC;QAED,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QAC5C,OAAO,CAAC,GAAG,CAAC,YAAY,MAAM,CAAC,IAAI,wBAAwB,CAAC,CAAC;IAC/D,CAAC;IAED,gBAAgB;QACd,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,IAAI,EAAE,CAAC,CAAC;IAC/C,CAAC;IAED,SAAS,CAAC,IAAY;QACpB,OAAO,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACtC,CAAC;CACF;AAxCD,sCAwCC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
// example-eda/src/index.ts
|
|
4
|
+
const core_1 = require("@legible-sync/core");
|
|
5
|
+
const PluginManager_1 = require("./core/PluginManager");
|
|
6
|
+
const EventBus_1 = require("./core/EventBus");
|
|
7
|
+
// Import all plugins
|
|
8
|
+
const users_1 = require("./plugins/users");
|
|
9
|
+
const products_1 = require("./plugins/products");
|
|
10
|
+
const orders_1 = require("./plugins/orders");
|
|
11
|
+
const inventory_1 = require("./plugins/inventory");
|
|
12
|
+
const notifications_1 = require("./plugins/notifications");
|
|
13
|
+
const analytics_1 = require("./plugins/analytics");
|
|
14
|
+
const payments_1 = require("./plugins/payments");
|
|
15
|
+
async function main() {
|
|
16
|
+
console.log('🚀 Starting Event-Driven Architecture Example\n');
|
|
17
|
+
// Initialize core systems
|
|
18
|
+
const engine = new core_1.LegibleEngine();
|
|
19
|
+
const pluginManager = new PluginManager_1.PluginManager(engine);
|
|
20
|
+
const eventBus = new EventBus_1.EventBus();
|
|
21
|
+
// Register EventBus as a concept so plugins can publish events
|
|
22
|
+
engine.registerConcept('EventBus', {
|
|
23
|
+
state: {},
|
|
24
|
+
async execute(action, input) {
|
|
25
|
+
if (action === 'publish') {
|
|
26
|
+
const { event, data } = input;
|
|
27
|
+
await eventBus.publish({
|
|
28
|
+
type: event,
|
|
29
|
+
payload: data,
|
|
30
|
+
source: 'system',
|
|
31
|
+
flowId: input.flowId || 'system'
|
|
32
|
+
});
|
|
33
|
+
return { published: true };
|
|
34
|
+
}
|
|
35
|
+
throw new Error(`Unknown EventBus action: ${action}`);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
// Load all plugins
|
|
39
|
+
const plugins = [
|
|
40
|
+
users_1.usersPlugin,
|
|
41
|
+
products_1.productsPlugin,
|
|
42
|
+
inventory_1.inventoryPlugin,
|
|
43
|
+
orders_1.ordersPlugin,
|
|
44
|
+
payments_1.paymentsPlugin,
|
|
45
|
+
notifications_1.notificationsPlugin,
|
|
46
|
+
analytics_1.analyticsPlugin
|
|
47
|
+
];
|
|
48
|
+
for (const plugin of plugins) {
|
|
49
|
+
await pluginManager.loadPlugin(plugin);
|
|
50
|
+
}
|
|
51
|
+
console.log('\n✅ All plugins loaded successfully!');
|
|
52
|
+
console.log('Loaded plugins:', pluginManager.getLoadedPlugins());
|
|
53
|
+
// Demonstrate the EDA system with a complete e-commerce flow
|
|
54
|
+
console.log('\n🛍️ Demonstrating E-commerce Flow:\n');
|
|
55
|
+
try {
|
|
56
|
+
// 1. Create a user
|
|
57
|
+
console.log('1. 👤 Creating user...');
|
|
58
|
+
const userFlow = 'user-flow-1';
|
|
59
|
+
const userResult = await engine.invoke('User', 'register', {
|
|
60
|
+
username: 'johndoe',
|
|
61
|
+
email: 'john@example.com',
|
|
62
|
+
password: 'password123'
|
|
63
|
+
}, userFlow);
|
|
64
|
+
console.log(' User created:', userResult.user.username);
|
|
65
|
+
// 2. Create a product
|
|
66
|
+
console.log('\n2. 📦 Creating product...');
|
|
67
|
+
const productFlow = 'product-flow-1';
|
|
68
|
+
const productResult = await engine.invoke('Product', 'create', {
|
|
69
|
+
name: 'Wireless Headphones',
|
|
70
|
+
sku: 'WH-001',
|
|
71
|
+
price: 99.99,
|
|
72
|
+
description: 'High-quality wireless headphones',
|
|
73
|
+
category: 'electronics'
|
|
74
|
+
}, productFlow);
|
|
75
|
+
console.log(' Product created:', productResult.product.name);
|
|
76
|
+
// 3. Set inventory for the product
|
|
77
|
+
console.log('\n3. 📊 Setting inventory...');
|
|
78
|
+
await engine.invoke('Inventory', 'setStock', {
|
|
79
|
+
productId: productResult.productId,
|
|
80
|
+
quantity: 10
|
|
81
|
+
}, 'inventory-flow-1');
|
|
82
|
+
console.log(' Inventory set: 10 units');
|
|
83
|
+
// 4. Create an order
|
|
84
|
+
console.log('\n4. 🛒 Creating order...');
|
|
85
|
+
const orderFlow = 'order-flow-1';
|
|
86
|
+
const orderResult = await engine.invoke('Order', 'create', {
|
|
87
|
+
userId: userResult.userId,
|
|
88
|
+
items: [
|
|
89
|
+
{
|
|
90
|
+
productId: productResult.productId,
|
|
91
|
+
quantity: 2,
|
|
92
|
+
price: productResult.product.price
|
|
93
|
+
}
|
|
94
|
+
]
|
|
95
|
+
}, orderFlow);
|
|
96
|
+
console.log(' Order created, checking inventory...');
|
|
97
|
+
// The system should automatically:
|
|
98
|
+
// - Check inventory availability
|
|
99
|
+
// - Confirm the order if available
|
|
100
|
+
// - Initiate and process payment
|
|
101
|
+
// - Deduct inventory
|
|
102
|
+
// - Send confirmation notification
|
|
103
|
+
// - Track analytics events
|
|
104
|
+
// Wait a bit for async operations
|
|
105
|
+
await new Promise(resolve => setTimeout(resolve, 100));
|
|
106
|
+
// 5. Check order status
|
|
107
|
+
console.log('\n5. 📋 Checking order status...');
|
|
108
|
+
const orderStatus = await engine.invoke('Order', 'get', {
|
|
109
|
+
orderId: orderResult.orderId
|
|
110
|
+
}, 'status-flow-1');
|
|
111
|
+
console.log(' Order status:', orderStatus.order.status);
|
|
112
|
+
console.log(' Order total: $' + orderStatus.order.total);
|
|
113
|
+
// 6. Check payment status
|
|
114
|
+
console.log('\n6. 💳 Checking payment status...');
|
|
115
|
+
const paymentStatus = await engine.invoke('Payment', 'getByOrderId', {
|
|
116
|
+
orderId: orderResult.orderId
|
|
117
|
+
}, 'payment-check-flow-1');
|
|
118
|
+
console.log(' Payment status:', paymentStatus.payment.status);
|
|
119
|
+
console.log(' Payment amount: $' + paymentStatus.payment.amount);
|
|
120
|
+
// 7. Check inventory after order
|
|
121
|
+
console.log('\n7. 📊 Checking inventory after order...');
|
|
122
|
+
const inventoryStatus = await engine.invoke('Inventory', 'getStock', {
|
|
123
|
+
productId: productResult.productId
|
|
124
|
+
}, 'inventory-check-flow-1');
|
|
125
|
+
console.log(' Remaining stock:', inventoryStatus.quantity, 'units');
|
|
126
|
+
// 8. Check analytics
|
|
127
|
+
console.log('\n8. 📈 Checking analytics...');
|
|
128
|
+
const analytics = await engine.invoke('Analytics', 'getMetrics', {}, 'analytics-flow-1');
|
|
129
|
+
console.log(' Events tracked:', analytics.metrics);
|
|
130
|
+
console.log('\n🎉 E-commerce flow completed successfully!');
|
|
131
|
+
console.log('The system automatically handled:');
|
|
132
|
+
console.log(' ✓ Inventory validation');
|
|
133
|
+
console.log(' ✓ Order confirmation');
|
|
134
|
+
console.log(' ✓ Payment processing');
|
|
135
|
+
console.log(' ✓ Stock deduction');
|
|
136
|
+
console.log(' ✓ Email notifications');
|
|
137
|
+
console.log(' ✓ Analytics tracking');
|
|
138
|
+
}
|
|
139
|
+
catch (error) {
|
|
140
|
+
console.error('❌ Error in demo:', error);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
// Run the demo
|
|
144
|
+
main().catch(console.error);
|
|
145
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAAA,2BAA2B;AAC3B,6CAAmD;AACnD,wDAAqD;AACrD,8CAA2C;AAE3C,qBAAqB;AACrB,2CAA8C;AAC9C,iDAAoD;AACpD,6CAAgD;AAChD,mDAAsD;AACtD,2DAA8D;AAC9D,mDAAsD;AACtD,iDAAoD;AAEpD,KAAK,UAAU,IAAI;IACjB,OAAO,CAAC,GAAG,CAAC,iDAAiD,CAAC,CAAC;IAEjE,0BAA0B;IAC1B,MAAM,MAAM,GAAG,IAAI,oBAAa,EAAE,CAAC;IACnC,MAAM,aAAa,GAAG,IAAI,6BAAa,CAAC,MAAM,CAAC,CAAC;IAChD,MAAM,QAAQ,GAAG,IAAI,mBAAQ,EAAE,CAAC;IAE9B,+DAA+D;IAC/D,MAAM,CAAC,eAAe,CAAC,UAAU,EAAE;QACjC,KAAK,EAAE,EAAE;QACT,KAAK,CAAC,OAAO,CAAC,MAAc,EAAE,KAAU;YACtC,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;gBACzB,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,KAAK,CAAC;gBAC9B,MAAM,QAAQ,CAAC,OAAO,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M,MAAM,CAAC,MAAM,CAAC,WAAW,EAAE,YAAY,EAAE,EAAE,EAAE,kBAAkB,CAAC,CAAC;QACzF,OAAO,CAAC,GAAG,CAAC,oBAAoB,EAAE,SAAS,CAAC,OAAO,CAAC,CAAC;QAErD,OAAO,CAAC,GAAG,CAAC,8CAA8C,CAAC,CAAC;QAC5D,OAAO,CAAC,GAAG,CAAC,mCAAmC,CAAC,CAAC;QACjD,OAAO,CAAC,GAAG,CAAC,0BAA0B,CAAC,CAAC;QACxC,OAAO,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAC;QACtC,OAAO,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAC;QACtC,OAAO,CAAC,GAAG,CAAC,qBAAqB,CAAC,CAAC;QACnC,OAAO,CAAC,GAAG,CAAC,yBAAyB,CAAC,CAAC;QACvC,OAAO,CAAC,GAAG,CAAC,wBAAwB,CAAC,CAAC;IAExC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,CAAC,KAAK,CAAC,kBAAkB,EAAE,KAAK,CAAC,CAAC;IAC3C,CAAC;AACH,CAAC;AAED,eAAe;AACf,IAAI,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Analytics.d.ts","sourceRoot":"","sources":["../../../../src/plugins/analytics/concepts/Analytics.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAE7C,eAAO,MAAM,SAAS,EAAE,OAiDvB,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Analytics = void 0;
|
|
4
|
+
exports.Analytics = {
|
|
5
|
+
state: {
|
|
6
|
+
events: new Map(),
|
|
7
|
+
metrics: new Map(),
|
|
8
|
+
},
|
|
9
|
+
async execute(action, input) {
|
|
10
|
+
const state = this.state;
|
|
11
|
+
switch (action) {
|
|
12
|
+
case 'track': {
|
|
13
|
+
const { event, data } = input;
|
|
14
|
+
if (!state.events.has(event)) {
|
|
15
|
+
state.events.set(event, []);
|
|
16
|
+
}
|
|
17
|
+
const eventData = {
|
|
18
|
+
...data,
|
|
19
|
+
timestamp: new Date(),
|
|
20
|
+
id: `event_${Date.now()}`
|
|
21
|
+
};
|
|
22
|
+
state.events.get(event).push(eventData);
|
|
23
|
+
// Update metrics
|
|
24
|
+
const count = state.metrics.get(event) || 0;
|
|
25
|
+
state.metrics.set(event, count + 1);
|
|
26
|
+
console.log(`📊 Tracked: ${event}`, data);
|
|
27
|
+
return { eventId: eventData.id };
|
|
28
|
+
}
|
|
29
|
+
case 'getMetrics': {
|
|
30
|
+
const metrics = Object.fromEntries(state.metrics);
|
|
31
|
+
return { metrics };
|
|
32
|
+
}
|
|
33
|
+
case 'getEvents': {
|
|
34
|
+
const { event, limit = 10 } = input;
|
|
35
|
+
const events = state.events.get(event) || [];
|
|
36
|
+
return { events: events.slice(-limit) };
|
|
37
|
+
}
|
|
38
|
+
default:
|
|
39
|
+
throw new Error(`Unknown action: ${action}`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
//# sourceMappingURL=Analytics.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Analytics.js","sourceRoot":"","sources":["../../../../src/plugins/analytics/concepts/Analytics.ts"],"names":[],"mappings":";;;AAGa,QAAA,SAAS,GAAY;IAChC,KAAK,EAAE;QACL,MAAM,EAAE,IAAI,GAAG,EAAiB;QAChC,OAAO,EAAE,IAAI,GAAG,EAAkB;KACnC;IAED,KAAK,CAAC,OAAO,CAAC,MAAc,EAAE,KAAU;QACtC,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;QAEzB,QAAQ,MAAM,EAAE,CAAC;YACf,KAAK,OAAO,CAAC,CAAC,CAAC;gBACb,MAAM,EAAE,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C,EAAE,CAAC;YAC1C,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/analytics/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAC;AAIlD,eAAO,MAAM,eAAe,EAAE,MAS7B,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.analyticsPlugin = void 0;
|
|
4
|
+
const Analytics_1 = require("./concepts/Analytics");
|
|
5
|
+
const analytics_events_sync_1 = require("./syncs/analytics-events.sync");
|
|
6
|
+
exports.analyticsPlugin = {
|
|
7
|
+
name: 'analytics',
|
|
8
|
+
concepts: {
|
|
9
|
+
Analytics: Analytics_1.Analytics
|
|
10
|
+
},
|
|
11
|
+
syncs: analytics_events_sync_1.analyticsEventSyncs,
|
|
12
|
+
initialize: async (_engine) => {
|
|
13
|
+
console.log('📈 Analytics plugin initialized');
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/plugins/analytics/index.ts"],"names":[],"mappings":";;;AAEA,oDAAiD;AACjD,yEAAoE;AAEvD,QAAA,eAAe,GAAW;IACrC,IAAI,EAAE,WAAW;IACjB,QAAQ,EAAE;QACR,SAAS,EAAT,qBAAS;KACV;IACD,KAAK,EAAE,2CAAmB;IAC1B,UAAU,EAAE,KAAK,EAAE,OAAO,EAAE,EAAE;QAC5B,OAAO,CAAC,GAAG,CAAC,iCAAiC,CAAC,CAAC;IACjD,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"analytics-events.sync.d.ts","sourceRoot":"","sources":["../../../../src/plugins/analytics/syncs/analytics-events.sync.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAE9C,eAAO,MAAM,mBAAmB,EAAE,QAAQ,EAmGzC,CAAC"}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.analyticsEventSyncs = void 0;
|
|
4
|
+
exports.analyticsEventSyncs = [
|
|
5
|
+
// Track user registration events
|
|
6
|
+
{
|
|
7
|
+
name: "TrackUserRegistration",
|
|
8
|
+
when: [
|
|
9
|
+
{
|
|
10
|
+
concept: "User",
|
|
11
|
+
action: "register"
|
|
12
|
+
}
|
|
13
|
+
],
|
|
14
|
+
then: [
|
|
15
|
+
{
|
|
16
|
+
concept: "Analytics",
|
|
17
|
+
action: "track",
|
|
18
|
+
input: {
|
|
19
|
+
event: "user_registered",
|
|
20
|
+
data: {
|
|
21
|
+
userId: "?userId",
|
|
22
|
+
username: "?username",
|
|
23
|
+
email: "?email"
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
]
|
|
28
|
+
},
|
|
29
|
+
// Track product creation events
|
|
30
|
+
{
|
|
31
|
+
name: "TrackProductCreation",
|
|
32
|
+
when: [
|
|
33
|
+
{
|
|
34
|
+
concept: "Product",
|
|
35
|
+
action: "create"
|
|
36
|
+
}
|
|
37
|
+
],
|
|
38
|
+
then: [
|
|
39
|
+
{
|
|
40
|
+
concept: "Analytics",
|
|
41
|
+
action: "track",
|
|
42
|
+
input: {
|
|
43
|
+
event: "product_created",
|
|
44
|
+
data: {
|
|
45
|
+
productId: "?productId",
|
|
46
|
+
name: "?name",
|
|
47
|
+
category: "?category",
|
|
48
|
+
price: "?price"
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
]
|
|
53
|
+
},
|
|
54
|
+
// Track order events
|
|
55
|
+
{
|
|
56
|
+
name: "TrackOrderCreation",
|
|
57
|
+
when: [
|
|
58
|
+
{
|
|
59
|
+
concept: "Order",
|
|
60
|
+
action: "create"
|
|
61
|
+
}
|
|
62
|
+
],
|
|
63
|
+
then: [
|
|
64
|
+
{
|
|
65
|
+
concept: "Analytics",
|
|
66
|
+
action: "track",
|
|
67
|
+
input: {
|
|
68
|
+
event: "order_created",
|
|
69
|
+
data: {
|
|
70
|
+
orderId: "?orderId",
|
|
71
|
+
userId: "?userId",
|
|
72
|
+
itemCount: "?items.length"
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
]
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
name: "TrackOrderConfirmation",
|
|
80
|
+
when: [
|
|
81
|
+
{
|
|
82
|
+
concept: "Order",
|
|
83
|
+
action: "confirm"
|
|
84
|
+
}
|
|
85
|
+
],
|
|
86
|
+
then: [
|
|
87
|
+
{
|
|
88
|
+
concept: "Analytics",
|
|
89
|
+
action: "track",
|
|
90
|
+
input: {
|
|
91
|
+
event: "order_confirmed",
|
|
92
|
+
data: {
|
|
93
|
+
orderId: "?orderId",
|
|
94
|
+
total: "?total"
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
]
|
|
99
|
+
}
|
|
100
|
+
];
|
|
101
|
+
//# sourceMappingURL=analytics-events.sync.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"analytics-events.sync.js","sourceRoot":"","sources":["../../../../src/plugins/analytics/syncs/analytics-events.sync.ts"],"names":[],"mappings":";;;AAGa,QAAA,mBAAmB,GAAe;IAC7C,iCAAiC;IACjC;QACE,IAAI,EAAE,uBAAuB;QAC7B,IAAI,EAAE;YACJ;gBACE,OAAO,EAAE,MAAM;gBACf,MAAM,EAAE,UAAU;aACnB;SACF;QACD,IAAI,EAAE;YACJ;g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AE;wBACJ,OAAO,EAAE,UAAU;wBACnB,KAAK,EAAE,QAAQ;qBAChB;iBACF;aACF;SACF;KACF;CACF,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Inventory.d.ts","sourceRoot":"","sources":["../../../../src/plugins/inventory/concepts/Inventory.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAE7C,eAAO,MAAM,SAAS,EAAE,OAqEvB,CAAC"}
|