{"library":"oc-client","title":"OC Client Node.js","description":"The `oc-client` package serves as a robust Node.js client for the OpenComponents micro-frontend framework, primarily facilitating server-side rendering of web components. It enables applications to consume, render, and manage distributed components from one or more registries. Key functionalities include instantiating a client with specific component versions and registry endpoints, warming up component caches, retrieving component metadata, and rendering components both individually and in batches. The current stable version is 4.0.2. The project is actively maintained and explicitly states it is under \"heavy development,\" indicating a potentially rapid release cadence and a higher likelihood of API changes between minor versions. Its core differentiator lies in providing a streamlined way to integrate OpenComponents into Node.js applications, offering features like cache management, request header forwarding, and flexible component versioning to efficiently display dynamic content.","language":"javascript","status":"active","last_verified":"Thu Apr 23","install":{"commands":["npm install oc-client"],"cli":null},"imports":["const Client = require('oc-client');","import Client from 'oc-client';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"const Client = require('oc-client');\n\nconst client = new Client({\n  registries: { serverRendering: 'https://myregistry.com/' }, // IMPORTANT: Replace with your actual OpenComponents registry URL\n  components: {\n    // Define components your application will consume with desired versions\n    headerComponent: '1.2.3',\n    footerComponent: '~2.2.5'\n  },\n  cache: {\n    flushInterval: 60 * 5 // Optional: Cache invalidation interval in seconds (e.g., 5 minutes)\n  }\n});\n\nclient.init({\n  // Optional: Headers to forward during component warm-up requests\n  headers: {\n    'accept-language': 'en-US,en;q=0.9',\n    'user-agent': 'Mozilla/5.0 (Node.js) oc-client-app'\n  },\n  timeout: 10 // Optional: Maximum request time in seconds\n}, function(error, responses){\n  if (error) {\n    console.error('oc-client initialization failed:', error);\n    // Implement robust error handling, e.g., serve a fallback or retry\n  } else {\n    console.log('oc-client initialized successfully. Warm-up responses:', responses);\n  }\n\n  // Example: Render a single component\n  client.renderComponent('headerComponent', {\n    headers: { 'x-trace-id': 'req-123' },\n    parameters: { title: 'Welcome to My App' }\n  }, function(err, htmlResponse) {\n    if (err) {\n      console.error('Failed to render headerComponent:', err);\n    } else {\n      console.log('Successfully rendered headerComponent:', htmlResponse.html);\n      // htmlResponse.html contains the rendered HTML string\n      // htmlResponse.assets contains client-side assets (CSS, JS) if any\n    }\n  });\n});","lang":"javascript","description":"Demonstrates initializing the `oc-client` with registry and component configurations, warming up components, and rendering a single component.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}