UNPKG

@hoover-institution/hubspot-lib

Version:

A toolkit for deep integration with HubSpot's Marketing Events API with a plugin-based architecture.

36 lines (33 loc) 1.16 kB
import { defineHooks } from "./hooks.js"; import { getHookMap } from "./pluginRegistry.js"; // required for real bitmask map /** * Resolves a list of plugin names into a single combined bitmask value. * Each plugin is automatically registered via `defineHooks()` if not already defined. * * @param {string[]} names - The plugin names to enable (e.g. ["MONGO_SYNC", "DISCORD_LOG", "ALL"]) * @returns {number} Bitmask representing all requested plugins * * @throws {Error} If a plugin name is not defined in the hook registry * * @example * const mask = resolveHooks(["ALL"]); * if ((flags & mask) === mask) { ... } */ export function resolveHooks(names = []) { // Special case: if "ALL" is in the list, activate all known bitmasks if (names.includes("ALL")) { const allBits = Object.values(getHookMap()).reduce( (acc, bit) => acc | bit, 0 ); return allBits; } const HOOKS = defineHooks(names); return names.reduce((mask, name) => { const bit = HOOKS[name]; if (bit === undefined) { throw new Error(`Unknown hook "${name}" — did you forget to define it?`); } return mask | bit; }, 0); }