{"name":"@octokit/endpoint","description":"Turns REST API endpoints into generic request options","version":"7.0.5","license":"MIT","source":"dist-src/index.js","types":"dist-types/index.d.ts","main":"dist-node/index.js","module":"dist-web/index.js","pika":true,"sideEffects":false,"keywords":["octokit","github","api","rest"],"repository":{"type":"git","url":"git+https://github.com/octokit/endpoint.js.git"},"dependencies":{"@octokit/types":"^9.0.0","is-plain-object":"^5.0.0","universal-user-agent":"^6.0.0"},"devDependencies":{"@pika/pack":"^0.3.7","@pika/plugin-build-node":"^0.9.0","@pika/plugin-build-web":"^0.9.0","@pika/plugin-ts-standard-pkg":"^0.9.0","@types/jest":"^29.0.0","jest":"^29.0.0","prettier":"2.8.3","semantic-release":"^20.0.0","semantic-release-plugin-update-version-in-files":"^1.0.0","ts-jest":"^29.0.0","typescript":"^4.0.2"},"engines":{"node":">= 14"},"publishConfig":{"access":"public"},"gitHead":"90b6705a0b828f3db7285b96fd5123e2b1b34d0a","bugs":{"url":"https://github.com/octokit/endpoint.js/issues"},"homepage":"https://github.com/octokit/endpoint.js#readme","_id":"@octokit/endpoint@7.0.5","_nodeVersion":"18.13.0","_npmVersion":"8.19.3","dist":{"integrity":"sha512-LG4o4HMY1Xoaec87IqQ41TQ+glvIeTKqfjkCEmt5AIwDZJwQeVZFIEYXrYY6yLwK+pAScb9Gj4q+Nz2qSw1roA==","shasum":"2bb2a911c12c50f10014183f5d596ce30ac67dd1","tarball":"http://registry-npm.ywwl.com/@octokit/endpoint/download/@octokit/endpoint-7.0.5.tgz","fileCount":35,"unpackedSize":114577,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCICG2QzIXfFsVO49Y5PFardReZgpwdAtXS/OOx1mElPEdAiEA3I2SzjL7cFYZkwkTg7JRGkVATSH4VZ8gRN+5I2Unvoo="}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjzw/dACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmp2ow//Wk+ISCyNnfwoKklASpA83WhJI0bg8t80vbJMzDTX1mk2sRNm\r\nVdGp/jruYyB8JNlO7R+C656VDuAqlOw/w8YCkm8kIN0ub7RNU/ll1prHZFKr\r\nRQt3XupmcCKyMZ2LsbecJIZtAiR8HoIvHPP8jm5AwTQUqgTSGu1QL2mI6/wd\r\n/YmtD/Ic0kEQrawoS4OvxQTVPrl4nu2BFdlaKaQ7BL4TCuBiqW6YxS/GwIzd\r\nCaZy6aa3KkSXZri/ppyWDqCSiG0Vi/a39QG/D7Vq6Yi7iJ3npktoLlBd+TFX\r\nFFt4HEiSDIxZ89tQS3Y2p7/zzAIoDBPeTl244B8ChW/V7JftFfZaX58BOmIr\r\nmSl/10HulG1z108AmDebpwiIoSif7h5/CnZ2+Crtj19UDxcdZbmIML4VXL3y\r\n2HD7xavEATBskAPYFxq887eGDBxNBWHYAf2+Pr4jwXdfqEhxM2k66Pwy2z06\r\nkoRu1R+qGJt2/ydx8rIHPL45YjUlXdFQVy3co4Y/x8awALw6NC4Moi3c7Y4B\r\nDqLEpHfvMrttSXrnr4+Y2HywxAZHCqke/CpBTs0M+VZz2ZEc/k9M+aoqE+0g\r\nKxmYCemvTmiRhDKITqOQibo4ZGH7yhMn6T92dq+iAoauFqqq9eGGqHviQ6w3\r\nHfNGVXd9UjVajqWuK/K6ApEY2gHlGj887LQ=\r\n=MEI9\r\n-----END PGP SIGNATURE-----\r\n","size":19570,"noattachment":false,"key":"/@octokit/endpoint/-/@octokit/endpoint-7.0.5.tgz"},"_npmUser":{"name":"octokitbot","email":"security+octokitbot@github.com"},"directories":{},"maintainers":[{"name":"kfcampbell","email":"kfcampbell@github.com"},{"name":"nickfloyd","email":"nicholas.floyd.info@gmail.com"},{"name":"gr2m","email":"gregor@martynus.net"},{"name":"octokitbot","email":"security+octokitbot@github.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/endpoint_7.0.5_1674514397290_0.432477920636007"},"_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":1674514397446,"_cnpm_publish_time":1674514397446,"dist-tags":{"beta":"10.0.0-beta.2","latest":"11.0.5","next":"5.1.6","release-9.x":"9.0.6"}}