Skip to content

Conversation

@ricardo-devis-agullo
Copy link
Collaborator

@ricardo-devis-agullo ricardo-devis-agullo commented Sep 17, 2025

Add Selective Metadata Support to Registry API

Overview

This PR enhances the OpenComponents registry's discovery API by introducing selective metadata retrieval capabilities. The changes allow API consumers to request specific component metadata fields instead of receiving either all metadata or just component URLs.

Changes Made

Core Functionality

  • Selective Metadata Query: Added support for comma-separated field selection via the meta query parameter
  • Field Filtering: Implemented exclusion of sensitive fields (dependencies, devDependencies) from metadata responses
  • Backward Compatibility: Maintained existing behavior for meta=true and meta=false parameters

Code Quality Improvements

  • Variable Naming: Improved variable names for better readability (componentNames vs components, processedComponents vs componentsInfo)
  • Type Safety: Enhanced TypeScript type assertions and parameter handling
  • Code Organization: Refactored response building logic into a more structured approach
  • Consistent Naming: Standardized variable naming patterns throughout the function

API Usage

The registry's GET / endpoint now supports three metadata modes:

  1. URLs Only (default): GET / - Returns array of component URLs
  2. Full Metadata: GET /?meta=true - Returns complete component metadata
  3. Selective Metadata: GET /?meta=name,version,author - Returns only specified fields

Example Requests:

# Get only component URLs
GET /registry/

# Get full metadata for all components  
GET /registry/?meta=true

# Get selective metadata (name, version, author, description)
GET /registry/?meta=name,version,author,description

# Get selective metadata excluding sensitive fields
GET /registry/?meta=name,version,keywords,state

Example Response (selective metadata):

{
  "href": "https://registry.example.com/",
  "ocVersion": "0.50.13",
  "type": "oc-registry",
  "components": [
    {
      "href": "https://registry.example.com/my-component/1.0.0",
      "name": "my-component",
      "version": "1.0.0",
      "author": "John Doe"
    }
  ]
}

Security Considerations

The implementation automatically excludes potentially sensitive fields (dependencies, devDependencies) from selective metadata responses, preventing accidental exposure of internal component dependencies while still allowing access to other useful metadata fields.

Motivation

This enhancement addresses the need for more efficient API consumption by allowing clients to request only the metadata they require, reducing payload size and improving performance for applications that don't need complete component information. The selective approach is particularly valuable for:

  • Component listing interfaces that only need basic information
  • Performance-critical applications requiring minimal data transfer
  • Integration scenarios where specific metadata fields are required

The changes maintain full backward compatibility while providing a more flexible and efficient API surface.

@ricardo-devis-agullo ricardo-devis-agullo merged commit 2d98249 into master Sep 17, 2025
3 checks passed
@ricardo-devis-agullo ricardo-devis-agullo deleted the custom-meta branch September 17, 2025 17:42
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