Skip to content

Conversation

@ricardo-devis-agullo
Copy link
Collaborator

Add Component Context Awareness to Registry Plugins

🎯 Summary

This PR introduces a new context property for registry plugins that enables component-aware plugin execution. When context: true is set, plugins receive component information (name and version) and can make security, audit, and logic decisions based on the calling component.

🔧 Key Changes

Core Functionality

  • Plugin Context Support: Added context: boolean property to plugin configuration
  • Higher-Order Plugin Functions: Context-aware plugins now return functions that receive component context
  • Component Information: Plugins can access { name: string, version: string } of the calling component

Type System Updates

  • Enhanced Plugin interface with union types for context-aware vs basic plugins
  • Added PluginContext type with component name and version
  • Updated Plugins interface to include handler, description, and context flag
  • Modified VM interface to use new plugin structure

Registry Implementation

  • Plugin Initializer: Refactored to support context-aware plugin registration
  • Component Router: Added plugin converter that applies context per component request
  • Performance Optimization: Caches plugins without context to avoid unnecessary function creation

CLI & Testing

  • Updated mocked plugins to support context property
  • Enhanced test coverage for context-aware plugin scenarios
  • Updated plugin discovery and UI components

🚀 Use Cases

This feature enables:

  • Security Validation: Restrict component access to specific features
  • Audit Logging: Track which components use which plugins
  • Component-Specific Logic: Different behavior based on component name/version
  • Rate Limiting: Apply limits per component
  • Feature Rollouts: Enable features for specific components/versions

�� Breaking Changes

None. This is a backward-compatible enhancement. Existing plugins continue to work without modification.

�� Example Usage

// Context-aware plugin
module.exports.execute = function (context) {
  return function (featureName) {
    // context = { name: "my-component", version: "1.2.3" }
    if (context.name.startsWith("internal/")) {
      // Special logic for internal components
    }
    return connection.get(featureName);
  };
};
module.exports.context = true;

🧪 Testing

  • Added comprehensive test coverage for context-aware plugins
  • Updated existing plugin tests to maintain compatibility
  • Added integration tests for component context flow

📚 Documentation

Documentation has been updated in the registry configuration guide with:

  • Plugin structure explanation
  • Context-aware plugin examples
  • Use case scenarios
  • Configuration reference

Files Changed: 15 files, +195 insertions, -56 deletions

@ricardo-devis-agullo ricardo-devis-agullo merged commit b232f82 into master Aug 17, 2025
3 checks passed
@ricardo-devis-agullo ricardo-devis-agullo deleted the plugins-with-context branch August 17, 2025 06:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants