{"id":24529277,"url":"https://github.com/opencomponents/oc-client-node","last_synced_at":"2025-04-14T17:11:04.325Z","repository":{"id":22531962,"uuid":"96618129","full_name":"opencomponents/oc-client-node","owner":"opencomponents","description":"The OpenComponents Node client","archived":false,"fork":false,"pushed_at":"2023-03-04T03:49:36.000Z","size":1774,"stargazers_count":13,"open_issues_count":12,"forks_count":12,"subscribers_count":13,"default_branch":"master","last_synced_at":"2024-04-14T07:49:32.483Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/opencomponents.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-07-08T12:37:15.000Z","updated_at":"2024-06-18T21:21:09.199Z","dependencies_parsed_at":"2024-06-18T21:20:46.301Z","dependency_job_id":"f1090b38-bba6-486c-a44e-da184e362d5e","html_url":"https://github.com/opencomponents/oc-client-node","commit_stats":{"total_commits":167,"total_committers":12,"mean_commits":"13.916666666666666","dds":0.6586826347305389,"last_synced_commit":"1ef435ec67ce3672b73e2ebc3e16056f7c946b48"},"previous_names":[],"tags_count":38,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opencomponents%2Foc-client-node","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opencomponents%2Foc-client-node/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opencomponents%2Foc-client-node/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/opencomponents%2Foc-client-node/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/opencomponents","download_url":"https://codeload.github.com/opencomponents/oc-client-node/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248923764,"owners_count":21183954,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-01-22T07:35:43.226Z","updated_at":"2025-04-14T17:11:04.301Z","avatar_url":"https://github.com/opencomponents.png","language":"JavaScript","readme":"oc-client\n=========\n\nNode.js client for [OpenComponents](https://github.com/opentable/oc)\n\n[![NPM](https://nodei.co/npm/oc-client.png?downloads=true)](https://npmjs.org/package/oc-client)\n\nNode.js version: **6** required\n\nBuild status: Linux: [![Build Status](https://secure.travis-ci.org/opencomponents/oc-client-node.png?branch=master)](http://travis-ci.org/opencomponents/oc-client-node) | Windows:[![Build status](https://ci.appveyor.com/api/projects/status/nna1ahayjx5h6d66?svg=true)](https://ci.appveyor.com/project/OpenComponents/oc-client-node)\n\n\nDisclaimer: This project is still under heavy development and the API is likely to change at any time. In case you would find any issues, check the [troubleshooting page](../CONTRIBUTING.md#troubleshooting).\n\n# API\n\n* [new Client()](#new-clientoptions)\n* [Client#init()](#clientinitoptions-callback)\n* [Client#getComponentsInfo()](#clientgetcomponentsinfocomponents-callback)\n* [Client#renderComponent()](#clientrendercomponentcomponentname--options-callback)\n* [Client#renderComponents()](#clientrendercomponentscomponents--options-callback)\n\n### new Client(options)\n\nIt will create an instance of the client. Options:\n\n|Parameter|type|mandatory|description|\n|---------|----|---------|-----------|\n|`cache`|`object`|no|Cache options. If null or empty will use default settings (never flush the cache)|\n|`cache.flushInterval`|`number` (seconds)|no|The interval for flushing the cache|\n|`components`|`object`|yes|The components to consume with versions|\n|`components[name]`|`string`|yes|The component version|\n|`forwardAcceptLanguageToClient`|`boolean`|no|Default false. When true, when doing client-side requests (normal or failover) appends a custom parameter to the browser's component hrefs so that the framework will ignore the browser's Accept-Language in favour of the query-string value|\n|`registries`|`object`|yes|The registries' endpoints|\n|`registries.serverRendering`|`string`|no|The baseUrl for server-side rendering requests|\n|`registries.clientRendering`|`string`|no|The baseUrl for client-side rendering requests|\n|`templates`|`array`|no|The templates available to the client, will extend the default: [require('oc-template-handlebars'), require('oc-template-jade')]|\n\nExample:\n\n```js\nvar Client = require('oc-client');\n\nvar client = new Client({\n  registries: { serverRendering: 'https://myregistry.com/'},\n  components: {\n    hello: '1.2.3',\n    world: '~2.2.5',\n    bla: ''\n  }\n});\n```\n\n### Client#init(options, callback)\n\nIt will warmup the components that have been declared during the instantiation. Options:\n\n|Parameter|type|mandatory|description|\n|---------|----|---------|-----------|\n|`headers`|`object`|no|An object containing all the headers that must be forwarded to the components' requests|\n|`timeout`|`number` (seconds)|no|Default 5. Maximum amount of time to wait during requests|\n|`renderComponents`|`function`|no|A function to renderComponents on warmup. Defaults to client own implementation|\n\nExample:\n\n```js\nvar Client = require('oc-client');\n\nvar client = new Client({\n  registries: { serverRendering: 'https://myregistry.com/'},\n  components: {\n    hello: '1.2.3'\n  }\n});\n\nclient.init({\n  headers: { 'accept-language': 'en-US'}\n}, function(error, responses){\n  console.log(error);\n  // =\u003e something like null or Error making request to registry\n\n  console.log(responses);\n  // =\u003e something like { hello: '\u003cb\u003ehello\u003c/b\u003e'}\n});\n```\n\n### Client#getComponentsInfo(components, callback)\n\nIt will get the components' resolved versions for given requested versions. Useful for polling mechanism and caches management.\n\nExample:\n```js\n...\nclient.getComponentsInfo([{\n  name: 'header',\n  version: '1.X.X'\n}], function(error, infos){\n  console.log(infos);\n  /* =\u003e [{\n    componentName: 'header',\n    requestedVersion: '1.X.X',\n    apiResponse: {\n      name: 'header',\n      requestVersion: '1.X.X',\n      type: 'oc-component',\n      version: '1.2.4'\n    }\n  }] */\n});\n```\n\n### Client#renderComponent(componentName [, options], callback)\n\nIt will resolve a component href, will make a request to the registry, and will render the component. The callback will contain an error (if present), rendered html, and details (which includes headers).\n\nOptions:\n\n|Parameter|type|mandatory|description|\n|---------|----|---------|-----------|\n|`container`|`boolean`|no|Default false, when false, renders a component without its \u003coc-component\u003e container|\n|`disableFailoverRendering`|`boolean`|no|Disables the automatic failover rendering in case the registry times-out (in case configuration.registries.clientRendering contains a valid value.) Default false|\n|`forwardAcceptLanguageToClient`|`boolean`|no|When not specified in config, defaults to false. When true, when doing client-side requests (normal or failover) appends a custom parameter to the browser's component hrefs so that the framework will ignore the browser's Accept-Language in favour of the query-string value|\n|`headers`|`object`|no|An object containing all the headers that must be forwarded to the component|\n|`parameters`|`object`|no|An object containing the parameters for component's request|\n|`registries`|`object`|no|The registries' endpoints (overrides the parameters defined during instantiation)|\n|`registries.serverRendering`|`string`|no|The baseUrl for server-side rendering requests (overrides the parameter defined during instantiation)|\n|`registries.clientRendering`|`string`|no|The baseUrl for client-side rendering requests (overrides the parameter defined during instantiation)|\n|`render`|`string`|no|Default `server`. When `server`, it will return html. When `client` will produce the html to put in the page for post-poning the rendering to the browser|\n|`timeout`|`number` (seconds)|no|Default 5. When request times-out, the callback will be fired with a timeout error and a client-side rendering response (unless `disableFailoverRendering` is set to `true`)|\n\nExample:\n```js\n...\nclient.renderComponent('header', {\n  container: false,\n  headers: {\n    'accept-language': 'en-GB'\n  },\n  parameters: {\n    loggedIn: true\n  },\n  timeout: 2\n}, function(err, html, details){\n  console.log(html, details.headers);\n  // =\u003e \"\u003cdiv\u003eThis is the header. \u003ca\u003eLog-out\u003c/a\u003e\u003c/div\u003e\"\n});\n```\n\n### Client#renderComponents(components [, options], callback)\n\nIt will make a request to the registry, and will render the components. The callback will contain an array of errors (array of `null` in case there aren't any), an array of rendered html snippets, and an array of details. It will follow the same order of the request. This method will make **1** request to the registry + **n** requests for each component to get the views of components that aren't cached yet. After caching the views, this will make just **1** request to the registry.\n\nComponents parameter:\n\n|Parameter|type|mandatory|description|\n|---------|----|---------|-----------|\n|`components`|`array of objects`|yes|The array of components to retrieve and render|\n|`components[index].name`|`string`|yes|The component's name|\n|`components[index].version`|`string`|no|The component's version. When not speficied, it will use globally specified one (doing client initialisation); when not specified and not globally specified, it will default to \"\" (latest)|\n|`components[index].parameters`|`object`|no|The component's parameters|\n|`components[index].container`|`boolean`|no|The component's container option. When not specified, it will be the one specified in the options (for all components); if none is specified in options, it will default to `true`. When false, renders a component without its \u003coc-component\u003e container|\n|`components[index].render`|`string`|no|The component's render mode. When not specified, it will be the one specified in the options (for all components); if none is specified in options, it will default to `server`. When `server`, the rendering will be performed on the server-side and the result will be component's html. If `client`, the html will contain a promise to do the rendering on the browser.|\n\nOptions:\n\n|Parameter|type|mandatory|description|\n|---------|----|---------|-----------|\n|`container`|`boolean`|no|Default true, when false, renders a component without its \u003coc-component\u003e container|\n|`disableFailoverRendering`|`boolean`|no|Disables the automatic failover rendering in case the registry times-out (in case configuration.registries.clientRendering contains a valid value.) Default false|\n|`forwardAcceptLanguageToClient`|`boolean`|no|When not specified in config, defaults to false. When true, when doing client-side requests (normal or failover) appends a custom parameter to the browser's component hrefs so that the framework will ignore the browser's Accept-Language in favour of the query-string value|\n|`headers`|`object`|no|An object containing all the headers that must be forwarded to the component|\n|`ie8`|`boolean`|no|Default false, if true puts in place the necessary polyfills to make all the stuff work with ie8|\n|`parameters`|`object`|no|Global parameters for all components to retrieve. When component has its own parameters, globals will be overwritten|\n|`registries`|`object`|no|The registries' endpoints (overrides the parameters defined during instantiation)|\n|`registries.serverRendering`|`string`|no|The baseUrl for server-side rendering requests (overrides the parameter defined during instantiation)|\n|`registries.clientRendering`|`string`|no|The baseUrl for client-side rendering requests (overrides the parameter defined during instantiation)|\n|`render`|`string`|no|Default `server`. When `server`, it will return html. When `client` will produce the html to put in the page for post-poning the rendering to the browser|\n|`timeout`|`number` (seconds)|no|Default 5. When request times-out, the callback will be fired with a timeout error and a client-side rendering response (unless `disableFailoverRendering` is set to `true`)|\n\nExample:\n```js\n...\nclient.renderComponents([{\n  name: 'header',\n  parameters: { loggedIn: true }\n}, {\n  name: 'footer',\n  version: '4.5.X'\n}, {\n  name: 'advert',\n  parameters: { position: 'left' },\n  render: 'client'\n}], {\n  container: false,\n  headers: {\n    'accept-language': 'en-US'\n  },\n  timeout: 3.0\n}, function(errors, htmls, details){\n  for ( let i; i \u003c htmls.length; i++) {\n    console.log(htmls[i], details[i].headers);\n  }\n  // =\u003e [\"\u003cdiv\u003eHeader\u003c/div\u003e\",\n  //     \"\u003cp\u003eFooter\u003c/p\u003e\",\n  //     \"\u003coc-component href=\\\"\\/\\/registry.com\\/advert\\/?position=left\\\"\u003e\u003c\\/oc-component\u003e\"]\n});\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopencomponents%2Foc-client-node","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fopencomponents%2Foc-client-node","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopencomponents%2Foc-client-node/lists"}