@hoover-institution/hubspot-lib
Version:
A toolkit for deep integration with HubSpot's Marketing Events API with a plugin-based architecture.
34 lines (25 loc) • 946 B
JavaScript
import { castHook } from "./pluginSDK.js";
import { defineHooks } from "./hooks.js";
globalThis.__PLUGINS_TEMP ??= {};
/**
* Developer-facing plugin helper: registers a plugin by name + handlers
*
* @param {string} pluginName
* @param {Record<string, function>} eventMap - maps EVENTS.X → handler fn
*/
export function createPlugin(pluginName, eventMap) {
globalThis.__PLUGINS_TEMP[pluginName] = pluginName;
defineHooks([pluginName]);
globalThis.__registeredInlinePlugins ??= {};
const alreadyRegistered = globalThis.__registeredInlinePlugins[pluginName];
globalThis.__registeredInlinePlugins[pluginName] = true;
if (alreadyRegistered) {
console.warn(`⚠️ Plugin "${pluginName}" was registered more than once.`);
return;
}
for (const [eventKey, fn] of Object.entries(eventMap)) {
// @ts-ignore
castHook(pluginName, eventKey, fn);
}
console.log(`🔌 Created CUSTOM plugin: ${pluginName}`);
}