Member Junction
    Preparing search index...

    Base class for the Component Registry API Server. This class provides a complete implementation of the Component Registry API v1 specification.

    To customize the server behavior, extend this class and override the appropriate methods. Common customization points include:

    • Authentication: Override checkAPIKey() to implement custom authentication
    • Component filtering: Override getComponentFilter() to customize which components are served
    • Response formatting: Override the route handler methods to customize response formats
    class MyCustomRegistryServer extends ComponentRegistryAPIServer {
    protected async checkAPIKey(req: Request): Promise<boolean> {
    const apiKey = req.headers['x-api-key'];
    return await myCustomAuthProvider.validateKey(apiKey);
    }
    }
    Index

    Constructors

    Properties

    app: Application = null
    dataSources: DataSourceInfo[] = []
    feedbackHandler: FeedbackHandler = ...

    Default feedback handler implementation. Simply logs feedback and returns success. Override by calling setFeedbackHandler() with a custom implementation.

    metadata: Metadata
    pool: ConnectionPool = null
    readOnlyPool: ConnectionPool = null
    registry: MJComponentRegistryEntity = null
    router: Router = null

    Accessors

    Methods

    • Protected

      Authentication middleware that calls the checkAPIKey method. This middleware is automatically applied to /api/v1/components routes when requireAuth is true.

      Parameters

      • req: Request
      • res: Response
      • next: NextFunction

      Returns Promise<void>

    • Protected

      Check if the API key in the request is valid. By default, this method always returns true (no authentication).

      Override this method to implement custom authentication logic. Common patterns include:

      • Checking Bearer tokens in Authorization header
      • Validating API keys in custom headers
      • Verifying JWT tokens
      • Checking against a database of valid keys

      Parameters

      • req: Request

        The Express request object

      Returns Promise<boolean>

      Promise - True if the request is authenticated, false otherwise

      protected async checkAPIKey(req: Request): Promise<boolean> {
      const apiKey = req.headers['x-api-key'] as string;
      if (!apiKey) return false;

      // Check against database, cache, or external service
      return await this.validateKeyInDatabase(apiKey);
      }
    • Generate SHA-256 hash of component specification

      Parameters

      • specification: string

        The component specification JSON string

      Returns string

      SHA-256 hash as hex string

    • Protected

      Handler for GET /api/v1/components/:namespace/:name Get a specific component by namespace and name. Optionally specify a version with ?version=x.x.x query parameter. Optionally specify a hash with ?hash=abc123 to enable caching (returns 304 if unchanged).

      Parameters

      • req: Request
      • res: Response

      Returns Promise<void>

    • Protected

      Get the base filter for component queries. By default, this returns components where SourceRegistryID IS NULL (local components only).

      Override this method to customize which components are served by the registry.

      Returns string

      The SQL filter string to apply to all component queries

      protected getComponentFilter(): string {
      // Include both local and specific external registry components
      return "(SourceRegistryID IS NULL OR SourceRegistryID = 'abc-123')";
      }
    • Protected

      Handler for GET /api/v1/health Returns the health status of the registry server.

      Parameters

      • req: Request
      • res: Response

      Returns Promise<void>

    • Protected

      Helper method to get the latest version of each component from a list. Components are grouped by namespace/name and the highest version is selected.

      Parameters

      • components: MJComponentEntity[]

        Array of components potentially containing multiple versions

      Returns MJComponentEntity[]

      Array of components with only the latest version of each

    • Protected

      Handler for GET /api/v1/registry Returns basic information about the registry.

      Parameters

      • req: Request
      • res: Response

      Returns Promise<void>

    • Get the Express Router for mounting on an existing app. Only available in 'router' mode.

      Returns Router

      The Express Router with all registry routes configured

      Error if called in standalone mode

    • Initialize the server, including database connection, middleware, and routes. This method should be called before starting the server.

      Returns Promise<void>

      Promise that resolves when initialization is complete

      Error if database connection fails or registry cannot be loaded

    • Protected

      Handler for GET /api/v1/components Lists all published components in the registry, showing only the latest version of each.

      Parameters

      • req: Request
      • res: Response

      Returns Promise<void>

    • Protected

      Load the registry metadata from the database. This is called automatically if a registryId is provided in the configuration.

      Returns Promise<void>

    • Protected

      Handler for GET /api/v1/components/search Search for components by query string and optional type filter.

      Parameters

      • req: Request
      • res: Response

      Returns Promise<void>

    • Set a custom feedback handler. This allows external code (e.g., Skip) to override feedback handling logic.

      Parameters

      Returns void

      const server = new ComponentRegistryAPIServer();
      server.setFeedbackHandler({
      async submitFeedback(params, context) {
      // Custom logic here
      return { success: true, feedbackID: '...' };
      }
      });
    • Protected

      Set up the database connection using MemberJunction's SQL Server provider. Follows the same pattern as MJServer for consistency.

      Returns Promise<void>

    • Protected

      Set up Express middleware. Override this method to add custom middleware or modify the middleware stack.

      Returns void

    • Protected

      Set up the API routes. Override this method to add custom routes or modify existing ones.

      Returns void

    • Start the Express server on the configured port. Must be called after initialize().

      Returns Promise<void>

      Promise that resolves when the server is listening

    • Protected

      Handler for POST /api/v1/feedback Submit feedback for a component.

      Parameters

      • req: Request
      • res: Response

      Returns Promise<void>