synkrokonn-dev
Version:
Plugin-based cross-chain orchestration middleware for Web3 enterprise automation.
38 lines (37 loc) • 1.27 kB
JavaScript
import { ObjectRouter } from "../domain/ObjectRouter.js"; // ✅ Correct path
export class PluginManager {
constructor(plugins = []) {
this.plugins = [];
this.plugins = plugins;
}
register(plugin) {
this.plugins.push(plugin);
}
// Trigger plugin hooks at start of orchestration
async onStart(context) {
for (const plugin of this.plugins) {
if (plugin.onStart)
await plugin.onStart(context);
}
}
// Handle runtime events like ChainEvent, HTLC_CREATE, etc.
async onEvent(eventName, payload) {
for (const plugin of this.plugins) {
if (plugin.onEvent)
await plugin.onEvent(eventName, payload);
}
// Route domain objects if event is from chain
if (eventName === "ChainEvent" && payload?.object) {
const object = payload.object;
console.log(`[PluginManager] Routing object of type '${object.type}'`);
await ObjectRouter.route(object);
}
}
// Handle orchestrator errors centrally
async onError(error, context) {
for (const plugin of this.plugins) {
if (plugin.onError)
await plugin.onError(error, context);
}
}
}