{"name":"@octokit/endpoint","description":"Turns REST API endpoints into generic request options","version":"6.0.4","license":"MIT","pika":true,"sideEffects":false,"keywords":["octokit","github","api","rest"],"homepage":"https://github.com/octokit/endpoint.js#readme","bugs":{"url":"https://github.com/octokit/endpoint.js/issues"},"repository":{"type":"git","url":"git+https://github.com/octokit/endpoint.js.git"},"dependencies":{"@octokit/types":"^5.0.0","is-plain-object":"^3.0.0","universal-user-agent":"^6.0.0"},"devDependencies":{"@pika/pack":"^0.5.0","@pika/plugin-build-node":"^0.9.0","@pika/plugin-build-web":"^0.9.0","@pika/plugin-ts-standard-pkg":"^0.9.0","@types/jest":"^26.0.0","jest":"^26.0.1","prettier":"2.0.5","semantic-release":"^17.0.0","semantic-release-plugin-update-version-in-files":"^1.0.0","ts-jest":"^26.0.0","typescript":"^3.4.5"},"publishConfig":{"access":"public"},"source":"dist-src/index.js","types":"dist-types/index.d.ts","main":"dist-node/index.js","module":"dist-web/index.js","_id":"@octokit/endpoint@6.0.4","_nodeVersion":"12.18.2","_npmVersion":"6.14.6","dist":{"integrity":"sha512-ZJHIsvsClEE+6LaZXskDvWIqD3Ao7+2gc66pRG5Ov4MQtMvCU9wGu1TItw9aGNmRuU9x3Fei1yb+uqGaQnm0nw==","shasum":"da3eafdee1fabd6e5b6ca311efcba26f0dd99848","tarball":"http://registry-npm.ywwl.com/@octokit/endpoint/download/@octokit/endpoint-6.0.4.tgz","fileCount":33,"unpackedSize":113563,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfETb9CRA9TVsSAnZWagAAvVoP/ieqMqmFHr6yE8IO+2kM\njHVrv2q4i71NoTDbAe+kNLN+zK73t9QDrHVj41nSPGM4Mi1PkPdwJlZqSmPx\nQG41ZFk8ef8acUuTNM9ORN6lKolFPlB/Uid7FtbtIaXGChIQn5+op+tZ4dn4\ncvzq++HMrPaw18yQPWLAelLffev42a2dILYYAza/U7L6tclElecNtApJE/M5\n7CrfHk4jgw4JFrE5x6rNEfjERdmEmAgotAp26OIrzf7INH6lfZVPyIV9s6yQ\nGxTVLpUFI1Fc98n4iouB6B6vGiXAbDGFv/O4BL1t+txpFY/YGCpnu1H4Etqe\nyL2xmTUGPyuTdQyfzL+3K624vMJw/kOIi+EIPDBvyI6jca6mHH1hjWdGTIYF\nVpARf6VOQ3aCd0Zfb+J1fVW6fhfTnV5n1SCyznwC8WhVtP9oHExJgNMCrkLg\neLeTj7IEjTogj9qc3kaIcA+iqYhvylFBIwZ35jN0iyV6JgX8GPtdxuRNc91x\ndbi6zmkQLSnF0QtBasojHBaNNWF2hbzS+1nQfP0mHcmSYN6W7NeTUuhSJI8i\nfO0r9l5d2AThNEj3L8qPgVOuNPDthAo9SxClirOuf3hhPC60M5yFGXHr11ze\nmOAJFEJe03PG6jSmITcx2ZtMJBtU6+n3Z2lU0fRW/Y6HCKru+uDLpdfEVZWX\nhzQ7\r\n=BaZI\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDON2bLohSCnzDeeY1ShNBoBF4sNZA7pQsPS0jetXZLZAIgC6Ikb+MsKEYk0f/mDDYgJFUEI2qtBtn3Ht7pjWmN4+Q="}],"size":20982,"noattachment":false,"key":"/@octokit/endpoint/-/@octokit/endpoint-6.0.4.tgz"},"maintainers":[{"name":"bkeepers","email":"brandon@opensoul.org"},{"name":"gr2m","email":"gregor@martynus.net"},{"name":"octokitbot","email":"octokitbot@martynus.net"}],"_npmUser":{"name":"octokitbot","email":"octokitbot@martynus.net"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/endpoint_6.0.4_1594963709463_0.9549565963836049"},"_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":1594963709607,"_cnpm_publish_time":1594963709607,"dist-tags":{"beta":"10.0.0-beta.2","latest":"11.0.5","next":"5.1.6","release-9.x":"9.0.6"}}