{"name":"@octokit/endpoint","version":"2.1.0","publishConfig":{"access":"public","tag":"latest"},"description":"Turns REST API endpoints into generic request options","main":"index.js","directories":{"test":"test"},"scripts":{"prebuild":"mkdirp dist/","build":"npm-run-all build:*","build:development":"webpack --mode development --entry . --output-library=Octokit --output=./dist/octokit-endpoint.js --profile --json > dist/bundle-stats.json","build:production":"webpack --mode production --entry . --plugin=compression-webpack-plugin --output-library=Octokit --output-path=./dist --output-filename=octokit-endpoint.min.js --devtool source-map","bundle-report":"webpack-bundle-analyzer dist/bundle-stats.json --mode=static --no-open --report dist/bundle-report.html","coverage":"nyc report --reporter=html && open coverage/index.html","coverage:upload":"nyc report --reporter=text-lcov | coveralls","pretest":"standard && standard-markdown *.md","test":"nyc mocha test/*-test.js","test:browser":"cypress run --browser chrome","semantic-release":"semantic-release"},"repository":{"type":"git","url":"git+https://github.com/octokit/endpoint.js.git"},"keywords":["octokit","github","api","rest"],"author":{"name":"Gregor Martynus","url":"https://github.com/gr2m"},"license":"MIT","bugs":{"url":"https://github.com/octokit/endpoint.js/issues"},"homepage":"https://github.com/octokit/endpoint.js#readme","devDependencies":{"chai":"^4.2.0","compression-webpack-plugin":"^2.0.0","coveralls":"^3.0.2","cypress":"^3.1.0","mkdirp":"^0.5.1","mocha":"^5.2.0","npm-run-all":"^4.1.3","nyc":"^13.1.0","semantic-release":"^15.10.3","sinon-chai":"^3.2.0","standard":"^12.0.1","standard-markdown":"^5.0.1","webpack":"^4.21.0","webpack-bundle-analyzer":"^3.0.3","webpack-cli":"^3.1.2"},"dependencies":{"deepmerge":"2.2.1","is-plain-object":"^2.0.4","universal-user-agent":"^2.0.1","url-template":"^2.0.8"},"bundlesize":[{"path":"./dist/octokit-endpoint.min.js.gz","maxSize":"3KB"}],"release":{"publish":["@semantic-release/npm",{"path":"@semantic-release/github","assets":["dist/*","!dist/*.map.gz"]}]},"standard":{"globals":["describe","before","beforeEach","afterEach","after","it","expect"]},"gitHead":"ca9b6c9ca90e31dcb17a54fea998559ce1064563","_id":"@octokit/endpoint@2.1.0","_npmVersion":"6.4.1","_nodeVersion":"10.13.0","_npmUser":{"name":"octokitbot","email":"octokitbot@martynus.net"},"dist":{"integrity":"sha512-AXvbJueOLVqYo77ujUCu3o21nvgjqyLkC08gmGL96vXuK8DZxXWJQO+GxS+YxTQLc52DkZVDF5upNkUk8Umf3Q==","shasum":"c41a143017f8c12ffffac3cc6a3073715c7ad113","tarball":"http://registry-npm.ywwl.com/@octokit/endpoint/download/@octokit/endpoint-2.1.0.tgz","fileCount":20,"unpackedSize":35983,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJb2UpwCRA9TVsSAnZWagAA1sMQAI9WqWcTABQqx+hDHwc4\n97pAtnVp39Pz0/yrL3dJ0f26EHxZv4QY0EXNOHKVKUnZTesN4TEnCs6AsS+V\nHbODDN2IRwvPQqDn5qZOtTTXRKxLKbdxfsjJDYBVXuOBB49VEuGSawDQDHMx\nBSBVf49WUI3M4ELzFYb06XCNVweWqxNbZxoHI5CWuB2ZW9GAs5fmjGvEQHJM\nrT1wrHMLjLSAvo2tCM7Mdno4OmYs5wZivEDBGR+3IEv1slxs7wWuwSpocW/m\nC6mKIBjx4wY4t7zKAeVo9FB9b0cGomPsxmZLQeXIbqPodlwuNjt2+kmSGsP2\n0ltxaejGasU96l5pO/INLTrAkSgpFZzfUyNCynX9GRoeA0dVpVhYoGIYcOsE\nJMnGnyfXXBw66H5KZcpyb2iMstYCcw3UfrF0Q94Ojxw5wF05eDakG4eZcssv\nPQaHECU2KGFB9rce2oecNhyUVHMG7xbBebsi3dvdJy5ugGnzl5o2Aa3N5LGD\n/fWpbU7V7Yfn2d+XsS2/GVmRiXn252UyGYdNfyNqwD6SO9F/CJD6hjaenTkW\nwGigxVcjLW4tuiS2wQQuoc4WyiZq42XZz78vDoVSwz6VHaER6usZiyVoJvQc\nkLhxr7VSno2hm7Q16Cr2O+RGXDlU2ojC6GnKcqk7GAeOzcixH1RXcvqnjxc9\nFv/A\r\n=Pqhr\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDS7i5pVxBE/59DV9PESewlfOEXhLAAKOR35lzphq1/WAIgS/+kZZx/tp78QTXct8qF5w8NKkFhlV3QvgSdV+uorSo="}],"size":9926,"noattachment":false,"key":"/@octokit/endpoint/-/@octokit/endpoint-2.1.0.tgz"},"maintainers":[{"name":"bkeepers","email":"brandon@opensoul.org"},{"name":"gr2m","email":"gregor@martynus.net"},{"name":"octokitbot","email":"octokitbot@martynus.net"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/endpoint_2.1.0_1540967023639_0.8208036325661769"},"_hasShrinkwrap":false,"readme":"# endpoint.js\n\n> Turns GitHub REST API endpoints into generic request options\n\n[![@latest](https://img.shields.io/npm/v/@octokit/endpoint.svg)](https://www.npmjs.com/package/@octokit/endpoint)\n[![Build Status](https://github.com/octokit/endpoint.js/workflows/Test/badge.svg)](https://github.com/octokit/endpoint.js/actions/workflows/test.yml?query=branch%3Amain)\n\n`@octokit/endpoint` combines [GitHub REST API routes](https://developer.github.com/v3/) with your parameters and turns them into generic request options that can be used in any request library.\n\n<!-- update table of contents by running `npx markdown-toc README.md -i` -->\n\n<!-- toc -->\n\n- [Usage](#usage)\n- [API](#api)\n  - [`endpoint(route, options)` or `endpoint(options)`](#endpointroute-options-or-endpointoptions)\n  - [`endpoint.defaults()`](#endpointdefaults)\n  - [`endpoint.DEFAULTS`](#endpointdefaults)\n  - [`endpoint.merge(route, options)` or `endpoint.merge(options)`](#endpointmergeroute-options-or-endpointmergeoptions)\n  - [`endpoint.parse()`](#endpointparse)\n- [Special cases](#special-cases)\n  - [The `data` parameter – set request body directly](#the-data-parameter-%E2%80%93-set-request-body-directly)\n  - [Set parameters for both the URL/query and the request body](#set-parameters-for-both-the-urlquery-and-the-request-body)\n- [LICENSE](#license)\n\n<!-- tocstop -->\n\n## Usage\n\n<table>\n<tbody valign=top align=left>\n<tr><th>\nBrowsers\n</th><td width=100%>\nLoad <code>@octokit/endpoint</code> directly from <a href=\"https://esm.sh\">esm.sh</a>\n\n```html\n<script type=\"module\">\n  import { endpoint } from \"https://esm.sh/@octokit/endpoint\";\n</script>\n```\n\n</td></tr>\n<tr><th>\nNode\n</th><td>\n\nInstall with <code>npm install @octokit/endpoint</code>\n\n```js\nimport { endpoint } from \"@octokit/endpoint\";\n```\n\n</td></tr>\n</tbody>\n</table>\n\nExample for [List organization repositories](https://developer.github.com/v3/repos/#list-organization-repositories)\n\n```js\nconst requestOptions = endpoint(\"GET /orgs/{org}/repos\", {\n  headers: {\n    authorization: \"token 0000000000000000000000000000000000000001\",\n  },\n  org: \"octokit\",\n  type: \"private\",\n});\n```\n\nThe resulting `requestOptions` looks as follows\n\n```json\n{\n  \"method\": \"GET\",\n  \"url\": \"https://api.github.com/orgs/octokit/repos?type=private\",\n  \"headers\": {\n    \"accept\": \"application/vnd.github.v3+json\",\n    \"authorization\": \"token 0000000000000000000000000000000000000001\",\n    \"user-agent\": \"octokit/endpoint.js v1.2.3\"\n  }\n}\n```\n\nYou can pass `requestOptions` to common request libraries\n\n```js\nconst { url, ...options } = requestOptions;\n// using with fetch (https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API)\nfetch(url, options);\n// using with request (https://github.com/request/request)\nrequest(requestOptions);\n// using with got (https://github.com/sindresorhus/got)\ngot[options.method](url, options);\n// using with axios\naxios(requestOptions);\n```\n\n> [!IMPORTANT]\n> As we use [conditional exports](https://nodejs.org/api/packages.html#conditional-exports), you will need to adapt your `tsconfig.json`. See the TypeScript docs on [package.json \"exports\"](https://www.typescriptlang.org/docs/handbook/modules/reference.html#packagejson-exports).\n\n## API\n\n### `endpoint(route, options)` or `endpoint(options)`\n\n<table>\n  <thead align=left>\n    <tr>\n      <th>\n        name\n      </th>\n      <th>\n        type\n      </th>\n      <th width=100%>\n        description\n      </th>\n    </tr>\n  </thead>\n  <tbody align=left valign=top>\n    <tr>\n      <th>\n        <code>route</code>\n      </th>\n      <td>\n        String\n      </td>\n      <td>\n        If set, it has to be a string consisting of URL and the request method, e.g., <code>GET /orgs/{org}</code>. If it’s set to a URL, only the method defaults to <code>GET</code>.\n      </td>\n    </tr>\n    <tr>\n      <th>\n        <code>options.method</code>\n      </th>\n      <td>\n        String\n      </td>\n      <td>\n        <strong>Required unless <code>route</code> is set.</strong> Any supported <a href=\"https://developer.github.com/v3/#http-verbs\">http verb</a>. <em>Defaults to <code>GET</code></em>.\n      </td>\n    </tr>\n    <tr>\n      <th>\n        <code>options.url</code>\n      </th>\n      <td>\n        String\n      </td>\n      <td>\n        <strong>Required unless <code>route</code> is set.</strong> A path or full URL which may contain <code>:variable</code> or <code>{variable}</code> placeholders,\n        e.g., <code>/orgs/{org}/repos</code>. The <code>url</code> is parsed using <a href=\"https://github.com/bramstein/url-template\">url-template</a>.\n      </td>\n    </tr>\n    <tr>\n      <th>\n        <code>options.baseUrl</code>\n      </th>\n      <td>\n        String\n      </td>\n      <td>\n        <em>Defaults to <code>https://api.github.com</code></em>.\n      </td>\n    </tr>\n    <tr>\n      <th>\n        <code>options.headers</code>\n      </th>\n      <td>\n        Object\n      </td>\n      <td>\n        Custom headers. Passed headers are merged with defaults:<br>\n        <em><code>headers['user-agent']</code> defaults to <code>octokit-endpoint.js/1.2.3</code> (where <code>1.2.3</code> is the released version)</em>.<br>\n        <em><code>headers['accept']</code> defaults to <code>application/vnd.github.v3+json</code></em>.<br>\n      </td>\n    </tr>\n    <tr>\n      <th>\n        <code>options.mediaType.format</code>\n      </th>\n      <td>\n        String\n      </td>\n      <td>\n        Media type param, such as <code>raw</code>, <code>diff</code>, or <code>text+json</code>. See <a href=\"https://developer.github.com/v3/media/\">Media Types</a>. Setting <code>options.mediaType.format</code> will amend the <code>headers.accept</code> value.\n      </td>\n    </tr>\n    <tr>\n      <th>\n        <code>options.data</code>\n      </th>\n      <td>\n        Any\n      </td>\n      <td>\n        Set request body directly instead of setting it to JSON based on additional parameters. See <a href=\"#data-parameter\">\"The <code>data</code> parameter\"</a> below.\n      </td>\n    </tr>\n    <tr>\n      <th>\n        <code>options.request</code>\n      </th>\n      <td>\n        Object\n      </td>\n      <td>\n        Pass custom meta information for the request. The <code>request</code> object will be returned as is.\n      </td>\n    </tr>\n  </tbody>\n</table>\n\nAll other options will be passed depending on the `method` and `url` options.\n\n1. If the option key has a placeholder in the `url`, it will be used as the replacement. For example, if the passed options are `{url: '/orgs/{org}/repos', org: 'foo'}` the returned `options.url` is `https://api.github.com/orgs/foo/repos`.\n2. If the `method` is `GET` or `HEAD`, the option is passed as a query parameter.\n3. Otherwise, the parameter is passed in the request body as a JSON key.\n\n**Result**\n\n`endpoint()` is a synchronous method and returns an object with the following keys:\n\n<table>\n  <thead align=left>\n    <tr>\n      <th>\n        key\n      </th>\n      <th>\n        type\n      </th>\n      <th width=100%>\n        description\n      </th>\n    </tr>\n  </thead>\n  <tbody align=left valign=top>\n    <tr>\n      <th><code>method</code></th>\n      <td>String</td>\n      <td>The http method. Always lowercase.</td>\n    </tr>\n    <tr>\n      <th><code>url</code></th>\n      <td>String</td>\n      <td>The url with placeholders replaced with passed parameters.</td>\n    </tr>\n    <tr>\n      <th><code>headers</code></th>\n      <td>Object</td>\n      <td>All header names are lowercased.</td>\n    </tr>\n    <tr>\n      <th><code>body</code></th>\n      <td>Any</td>\n      <td>The request body if one is present. Only for <code>PATCH</code>, <code>POST</code>, <code>PUT</code>, <code>DELETE</code> requests.</td>\n    </tr>\n    <tr>\n      <th><code>request</code></th>\n      <td>Object</td>\n      <td>Request meta option, it will be returned as it was passed into <code>endpoint()</code></td>\n    </tr>\n  </tbody>\n</table>\n\n### `endpoint.defaults()`\n\nOverride or set default options. Example:\n\n```js\nconst request = require(\"request\");\nconst myEndpoint = require(\"@octokit/endpoint\").defaults({\n  baseUrl: \"https://github-enterprise.acme-inc.com/api/v3\",\n  headers: {\n    \"user-agent\": \"myApp/1.2.3\",\n    authorization: `token 0000000000000000000000000000000000000001`,\n  },\n  org: \"my-project\",\n  per_page: 100,\n});\n\nrequest(myEndpoint(`GET /orgs/{org}/repos`));\n```\n\nYou can call `.defaults()` again on the returned method, the defaults will cascade.\n\n```js\nconst myProjectEndpoint = endpoint.defaults({\n  baseUrl: \"https://github-enterprise.acme-inc.com/api/v3\",\n  headers: {\n    \"user-agent\": \"myApp/1.2.3\",\n  },\n  org: \"my-project\",\n});\nconst myProjectEndpointWithAuth = myProjectEndpoint.defaults({\n  headers: {\n    authorization: `token 0000000000000000000000000000000000000001`,\n  },\n});\n```\n\n`myProjectEndpointWithAuth` now defaults the `baseUrl`, `headers['user-agent']`,\n`org` and `headers['authorization']` on top of `headers['accept']` that is set\nby the global default.\n\n### `endpoint.DEFAULTS`\n\nThe current default options.\n\n```js\nendpoint.DEFAULTS.baseUrl; // https://api.github.com\nconst myEndpoint = endpoint.defaults({\n  baseUrl: \"https://github-enterprise.acme-inc.com/api/v3\",\n});\nmyEndpoint.DEFAULTS.baseUrl; // https://github-enterprise.acme-inc.com/api/v3\n```\n\n### `endpoint.merge(route, options)` or `endpoint.merge(options)`\n\nGet the defaulted endpoint options, but without parsing them into request options:\n\n```js\nconst myProjectEndpoint = endpoint.defaults({\n  baseUrl: \"https://github-enterprise.acme-inc.com/api/v3\",\n  headers: {\n    \"user-agent\": \"myApp/1.2.3\",\n  },\n  org: \"my-project\",\n});\nmyProjectEndpoint.merge(\"GET /orgs/{org}/repos\", {\n  headers: {\n    authorization: `token 0000000000000000000000000000000000000001`,\n  },\n  org: \"my-secret-project\",\n  type: \"private\",\n});\n\n// {\n//   baseUrl: 'https://github-enterprise.acme-inc.com/api/v3',\n//   method: 'GET',\n//   url: '/orgs/{org}/repos',\n//   headers: {\n//     accept: 'application/vnd.github.v3+json',\n//     authorization: `token 0000000000000000000000000000000000000001`,\n//     'user-agent': 'myApp/1.2.3'\n//   },\n//   org: 'my-secret-project',\n//   type: 'private'\n// }\n```\n\n### `endpoint.parse()`\n\nStateless method to turn endpoint options into request options. Calling\n`endpoint(options)` is the same as calling `endpoint.parse(endpoint.merge(options))`.\n\n## Special cases\n\n<a name=\"data-parameter\"></a>\n\n### The `data` parameter – set request body directly\n\nSome endpoints such as [Render a Markdown document in raw mode](https://developer.github.com/v3/markdown/#render-a-markdown-document-in-raw-mode) don’t have parameters that are sent as request body keys, instead, the request body needs to be set directly. In these cases, set the `data` parameter.\n\n```js\nconst options = endpoint(\"POST /markdown/raw\", {\n  data: \"Hello world github/linguist#1 **cool**, and #1!\",\n  headers: {\n    accept: \"text/html;charset=utf-8\",\n    \"content-type\": \"text/plain\",\n  },\n});\n\n// options is\n// {\n//   method: 'post',\n//   url: 'https://api.github.com/markdown/raw',\n//   headers: {\n//     accept: 'text/html;charset=utf-8',\n//     'content-type': 'text/plain',\n//     'user-agent': userAgent\n//   },\n//   body: 'Hello world github/linguist#1 **cool**, and #1!'\n// }\n```\n\n### Set parameters for both the URL/query and the request body\n\nThere are API endpoints that accept both query parameters as well as a body. In that case, you need to add the query parameters as templates to `options.url`, as defined in the [RFC 6570 URI Template specification](https://tools.ietf.org/html/rfc6570).\n\nExample\n\n```js\nendpoint(\n  \"POST https://uploads.github.com/repos/octocat/Hello-World/releases/1/assets{?name,label}\",\n  {\n    name: \"example.zip\",\n    label: \"short description\",\n    headers: {\n      \"content-type\": \"text/plain\",\n      \"content-length\": 14,\n      authorization: `token 0000000000000000000000000000000000000001`,\n    },\n    data: \"Hello, world!\",\n  },\n);\n```\n\n## LICENSE\n\n[MIT](LICENSE)\n","publish_time":1540967023810,"_cnpm_publish_time":1540967023810,"dist-tags":{"beta":"10.0.0-beta.2","latest":"11.0.5","next":"5.1.6","release-9.x":"9.0.6"}}