{"name":"@octokit/request","description":"Send parameterized requests to GitHub's APIs with sensible defaults in browsers and Node","version":"6.1.0","license":"MIT","pika":true,"sideEffects":false,"keywords":["octokit","github","api","request"],"repository":{"type":"git","url":"git+https://github.com/octokit/request.js.git"},"dependencies":{"@octokit/endpoint":"^7.0.0","@octokit/request-error":"^3.0.0","@octokit/types":"^6.16.1","is-plain-object":"^5.0.0","node-fetch":"^2.6.7","universal-user-agent":"^6.0.0"},"devDependencies":{"@octokit/auth-app":"^4.0.0","@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/fetch-mock":"^7.2.4","@types/jest":"^28.0.0","@types/lolex":"^5.1.0","@types/node":"^16.0.0","@types/node-fetch":"^2.3.3","@types/once":"^1.4.0","fetch-mock":"^9.3.1","jest":"^28.0.0","lolex":"^6.0.0","prettier":"2.7.1","semantic-release-plugin-update-version-in-files":"^1.0.0","string-to-arraybuffer":"^1.0.2","ts-jest":"^28.0.0","typescript":"^4.0.2"},"engines":{"node":">= 14"},"publishConfig":{"access":"public"},"source":"dist-src/index.js","types":"dist-types/index.d.ts","main":"dist-node/index.js","module":"dist-web/index.js","gitHead":"d000a0ab58b6b60872190d26e4952d3e0a863499","bugs":{"url":"https://github.com/octokit/request.js/issues"},"homepage":"https://github.com/octokit/request.js#readme","_id":"@octokit/request@6.1.0","_nodeVersion":"16.16.0","_npmVersion":"8.11.0","dist":{"integrity":"sha512-36V+sP4bJli31TRq8sea3d/Q1XGgZ9cnqpsegkLCnvpu+hoYephSkxGlWg4KB6dyUM1IWPXVrLFOKYzObQ+MZg==","shasum":"80bdac78dff583a8fa0978baeda139a71d98d10c","tarball":"http://registry-npm.ywwl.com/@octokit/request/download/@octokit/request-6.1.0.tgz","fileCount":17,"unpackedSize":57552,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDgqww6vjyCw4KshCaJNAfB7KDjswvySs5DlAXw8NHF9QIhAJ6pER5zNqhqIJa1JzFo1D29goK5mNJKXANMVxzTv/fK"}],"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJizC3cACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2VmqOQxAAhav44v1TjWo4oDiTPI5pOI9NiiD+bTCh2rZgmlD76UFDA+DR\r\ntswsPXx2yfh33Bprpvvw4Ul6zY8LGP67iUnFopVaf6AXQMMIJdCfm5Ti9jcc\r\nulZYCG5tmNZe1XUjf6511DTFLHyF8jPnJcw7Aur5VywBaKpI0vAg9+7EqMhH\r\nFyfXvDougzyglCoDs9jKNZ81WnKTSL4VLkgQK7/wT2t2t9G8pWoRyA/q0qGd\r\nxvGByKkdWdDdwAq9wVqpZZB3DEgNfUynSrf+EUY7R1Hq/p/fr2iHKE8qoE2R\r\ni22oQp1AV0YQeaGotp923prjXwVFGNJ+CMG62wFWGmgma0uRjFw2mhKsLgAA\r\nBQwaEkkH0gCXqszfCLpyRtDQAKpUeRe1oMYG//WFo99jbYqdngDM3TmblGXJ\r\n4hRvXtwp8XttyPo6S3l5E5sE6G8rJ66W1Xzr8b0Dp/2kqqwlZ8+8CHO/0BAo\r\nHqFUkuEARwWmm+TqFBvcp8Stbzx/+O1xHMIFZU3cwKaQUJLlhyT2eKlVFDta\r\nSuciygOxcbrqU2XkBGj5X4VmuMqhpyejQSGntiuROsGKZX6EThRfIIFFNyjb\r\nHCheBcUbLAaTQQUF4R803LY4PM732/RmCBDyC4IKPhej8MzmuoHHwOiPq3m9\r\ngemxwMTbJiNHneOyXhNaUw1v2Nd5FmOgv1U=\r\n=2rWb\r\n-----END PGP SIGNATURE-----\r\n","size":13099,"noattachment":false,"key":"/@octokit/request/-/@octokit/request-6.1.0.tgz"},"_npmUser":{"name":"octokitbot","email":"security+octokitbot@github.com"},"directories":{},"maintainers":[{"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/request_6.1.0_1657548252435_0.01666822720741501"},"_hasShrinkwrap":false,"readme":"# request.js\n\n> Send parameterized requests to GitHub’s APIs with sensible defaults in browsers and Node\n\n[![@latest](https://img.shields.io/npm/v/@octokit/request.svg)](https://www.npmjs.com/package/@octokit/request)\n[![Build Status](https://github.com/octokit/request.js/workflows/Test/badge.svg)](https://github.com/octokit/request.js/actions?query=workflow%3ATest+branch%3Amain)\n\n`@octokit/request` is a request library for browsers & node that makes it easier\nto interact with [GitHub’s REST API](https://developer.github.com/v3/) and\n[GitHub’s GraphQL API](https://developer.github.com/v4/guides/forming-calls/#the-graphql-endpoint).\n\nIt uses [`@octokit/endpoint`](https://github.com/octokit/endpoint.js) to parse\nthe passed options and sends the request using [fetch](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API). You can pass a custom `fetch` function using the `options.request.fetch` option, see below.\n\n<!-- update table of contents by running `npx markdown-toc README.md -i` -->\n\n<!-- toc -->\n\n- [request.js](#requestjs)\n  - [Features](#features)\n  - [Usage](#usage)\n    - [REST API example](#rest-api-example)\n    - [GraphQL example](#graphql-example)\n    - [Alternative: pass `method` \\& `url` as part of options](#alternative-pass-method--url-as-part-of-options)\n  - [Authentication](#authentication)\n  - [request()](#request)\n  - [`request.defaults()`](#requestdefaults)\n  - [`request.endpoint`](#requestendpoint)\n  - [Special cases](#special-cases)\n    - [The `data` parameter – set request body directly](#the-data-parameter--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    - [Set a custom Agent to your requests](#set-a-custom-agent-to-your-requests)\n  - [LICENSE](#license)\n\n<!-- tocstop -->\n\n## Features\n\n🤩 1:1 mapping of REST API endpoint documentation, e.g. [Add labels to an issue](https://developer.github.com/v3/issues/labels/#add-labels-to-an-issue) becomes\n\n```js\nrequest(\"POST /repos/{owner}/{repo}/issues/{number}/labels\", {\n  mediaType: {\n    previews: [\"symmetra\"],\n  },\n  owner: \"octokit\",\n  repo: \"request.js\",\n  number: 1,\n  labels: [\"🐛 bug\"],\n});\n```\n\n👶 [Small bundle size](https://bundlephobia.com/result?p=@octokit/request@5.0.3) (\\<4kb minified + gzipped)\n\n😎 [Authenticate](#authentication) with any of [GitHubs Authentication Strategies](https://github.com/octokit/auth.js).\n\n👍 Sensible defaults\n\n- `baseUrl`: `https://api.github.com`\n- `headers.accept`: `application/vnd.github.v3+json`\n- `headers['user-agent']`: `octokit-request.js/<current version> <OS information>`, e.g. `octokit-request.js/1.2.3 Node.js/10.15.0 (macOS Mojave; x64)`\n\n👌 Simple to test: mock requests by passing a custom fetch method.\n\n🧐 Simple to debug: Sets `error.request` to request options causing the error (with redacted credentials).\n\n## Usage\n\n<table>\n<tbody valign=top align=left>\n<tr><th>\nBrowsers\n</th><td width=100%>\nLoad <code>@octokit/request</code> directly from <a href=\"https://esm.sh\">esm.sh</a>\n\n```html\n<script type=\"module\">\n  import { request } from \"https://esm.sh/@octokit/request\";\n</script>\n```\n\n</td></tr>\n<tr><th>\nNode\n</th><td>\n\nInstall with <code>npm install @octokit/request</code>\n\n```js\nimport { request } from \"@octokit/request\";\n```\n\n</td></tr>\n</tbody>\n</table>\n\n### REST API example\n\n```js\n// Following GitHub docs formatting:\n// https://developer.github.com/v3/repos/#list-organization-repositories\nconst result = await request(\"GET /orgs/{org}/repos\", {\n  headers: {\n    authorization: \"token 0000000000000000000000000000000000000001\",\n  },\n  org: \"octokit\",\n  type: \"private\",\n});\n\nconsole.log(`${result.data.length} repos found.`);\n```\n\n### GraphQL example\n\nFor GraphQL request we recommend using [`@octokit/graphql`](https://github.com/octokit/graphql.js#readme)\n\n```js\nconst result = await request(\"POST /graphql\", {\n  headers: {\n    authorization: \"token 0000000000000000000000000000000000000001\",\n  },\n  query: `query ($login: String!) {\n    organization(login: $login) {\n      repositories(privacy: PRIVATE) {\n        totalCount\n      }\n    }\n  }`,\n  variables: {\n    login: \"octokit\",\n  },\n});\n```\n\n### Alternative: pass `method` & `url` as part of options\n\nAlternatively, pass in a method and a url\n\n```js\nconst result = await request({\n  method: \"GET\",\n  url: \"/orgs/{org}/repos\",\n  headers: {\n    authorization: \"token 0000000000000000000000000000000000000001\",\n  },\n  org: \"octokit\",\n  type: \"private\",\n});\n```\n\n## Authentication\n\nThe simplest way to authenticate a request is to set the `Authorization` header directly, e.g. to a [personal access token](https://github.com/settings/tokens/).\n\n```js\nconst requestWithAuth = request.defaults({\n  headers: {\n    authorization: \"token 0000000000000000000000000000000000000001\",\n  },\n});\nconst result = await requestWithAuth(\"GET /user\");\n```\n\nFor more complex authentication strategies such as GitHub Apps or Basic, we recommend the according authentication library exported by [`@octokit/auth`](https://github.com/octokit/auth.js).\n\n```js\nimport { createAppAuth } from \"@octokit/auth-app\";\nconst auth = createAppAuth({\n  appId: process.env.APP_ID,\n  privateKey: process.env.PRIVATE_KEY,\n  installationId: 123,\n});\nconst requestWithAuth = request.defaults({\n  request: {\n    hook: auth.hook,\n  },\n  mediaType: {\n    previews: [\"machine-man\"],\n  },\n});\n\nconst { data: app } = await requestWithAuth(\"GET /app\");\nconst { data: app } = await requestWithAuth(\n  \"POST /repos/{owner}/{repo}/issues\",\n  {\n    owner: \"octocat\",\n    repo: \"hello-world\",\n    title: \"Hello from the engine room\",\n  },\n);\n```\n\n## request()\n\n`request(route, options)` or `request(options)`.\n\n**Options**\n\n<table>\n  <thead>\n    <tr>\n      <th align=left>\n        name\n      </th>\n      <th align=left>\n        type\n      </th>\n      <th align=left>\n        description\n      </th>\n    </tr>\n  </thead>\n  <tr>\n    <th align=left>\n      <code>route</code>\n    </th>\n    <td>\n      String\n    </td>\n    <td>\n      **Required**. If <code>route</code> is set it has to be a string consisting of the request method and URL, e.g. <code>GET /orgs/{org}</code>\n    </td>\n  </tr>\n  <tr>\n    <th align=left>\n      <code>options.baseUrl</code>\n    </th>\n    <td>\n      String\n    </td>\n    <td>\n      The base URL that <code>route</code> or <code>url</code> will be prefixed with, if they use relative paths. <em>Defaults to <code>https://api.github.com</code></em>.\n    </td>\n  </tr>\n    <th align=left>\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-rest.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>.<br> Use <code>options.mediaType.{format,previews}</code> to request API previews and custom media types.\n    </td>\n  </tr>\n  <tr>\n    <th align=left>\n      <code>options.method</code>\n    </th>\n    <td>\n      String\n    </td>\n    <td>\n      Any supported <a href=\"https://developer.github.com/v3/#http-verbs\">http verb</a>, case-insensitive. <em>Defaults to <code>Get</code></em>.\n    </td>\n  </tr>\n  <tr>\n    <th align=left>\n      <code>options.mediaType.format</code>\n    </th>\n    <td>\n      String\n    </td>\n    <td>\n      Media type param, such as `raw`, `html`, or `full`. See <a href=\"https://developer.github.com/v3/media/\">Media Types</a>.\n    </td>\n  </tr>\n  <tr>\n    <th align=left>\n      <code>options.mediaType.previews</code>\n    </th>\n    <td>\n      Array of strings\n    </td>\n    <td>\n      Name of previews, such as `mercy`, `symmetra`, or `scarlet-witch`. See <a href=\"https://docs.github.com/graphql/overview/schema-previews\">GraphQL Schema Previews</a>.\n      Note that these only apply to GraphQL requests and have no effect on REST routes.\n    </td>\n  </tr>\n  <tr>\n    <th align=left>\n      <code>options.url</code>\n    </th>\n    <td>\n      String\n    </td>\n    <td>\n      **Required**. 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 align=left>\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 `data` parameter\"</a> below.\n    </td>\n  </tr>\n\n  <tr>\n    <th align=left>\n      <code>options.request.fetch</code>\n    </th>\n    <td>\n      Function\n    </td>\n    <td>\n     Custom replacement for <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API\">fetch</a>. Useful for testing or request hooks.\n    </td>\n  </tr>\n  <tr>\n    <th align=left>\n      <code>options.request.hook</code>\n    </th>\n    <td>\n      Function\n    </td>\n    <td>\n     Function with the signature <code>hook(request, endpointOptions)</code>, where <code>endpointOptions</code> are the parsed options as returned by <a href=\"https://github.com/octokit/endpoint.js#endpointmergeroute-options-or-endpointmergeoptions\"><code>endpoint.merge()</code></a>, and <code>request</code> is <a href=\"https://github.com/octokit/request.js#request\"><code>request()</code></a>. This option works great in conjunction with <a href=\"https://github.com/gr2m/before-after-hook\">before-after-hook</a>.\n    </td>\n  </tr>\n  <tr>\n    <th align=left>\n      <a name=\"options-request-signal\"></a><code>options.request.signal</code>\n    </th>\n    <td>\n      <a href=\"https://github.com/bitinn/node-fetch/tree/e996bdab73baf996cf2dbf25643c8fe2698c3249#request-cancellation-with-abortsignal\">new AbortController().signal</a>\n    </td>\n    <td>\n      Use an <code>AbortController</code> instance to cancel a request. In node you can only cancel streamed requests.\n    </td>\n  </tr>\n    <th align=left>\n      <code>options.request.log</code>\n    </th>\n    <td>\n      <code>object</code>\n    </td>\n    <td>\n      Used for internal logging. Defaults to <a href=\"https://developer.mozilla.org/en-US/docs/Web/API/console\"><code>console</code></a>.\n    </td>\n  </tr>\n  </tr>\n    <th align=left>\n      <code>options.request.parseSuccessResponseBody</code>\n    </th>\n    <td>\n      <code>boolean</code>\n    </td>\n    <td>\n      If set to <code>false</code> the returned `response` will be passed through from `fetch`. This is useful to stream response.body when downloading files from the GitHub API.\n    </td>\n  </tr>\n</table>\n\nAll other options except `options.request.*` will be passed depending on the `method` and `url` options.\n\n1. If the option key is a placeholder in the `url`, it will be used as 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 query parameter\n3. Otherwise the parameter is passed in the request body as JSON key.\n\n**Result**\n\n`request` returns a promise. If the request was successful, the promise resolves with an object containing 4 keys:\n\n<table>\n  <thead>\n    <tr>\n      <th align=left>\n        key\n      </th>\n      <th align=left>\n        type\n      </th>\n      <th align=left>\n        description\n      </th>\n    </tr>\n  </thead>\n  <tr>\n    <th align=left><code>status</code></th>\n    <td>Integer</td>\n    <td>Response status status</td>\n  </tr>\n  <tr>\n    <th align=left><code>url</code></th>\n    <td>String</td>\n    <td>URL of response. If a request results in redirects, this is the final URL. You can send a <code>HEAD</code> request to retrieve it without loading the full response body.</td>\n  </tr>\n  <tr>\n    <th align=left><code>headers</code></th>\n    <td>Object</td>\n    <td>All response headers</td>\n  </tr>\n  <tr>\n    <th align=left><code>data</code></th>\n    <td>Any</td>\n    <td>The response body as returned from server. If the response is JSON then it will be parsed into an object</td>\n  </tr>\n</table>\n\nIf an error occurs, the promise is rejected with an `error` object containing 3 keys to help with debugging:\n\n- `error.status` The http response status code\n- `error.request` The request options such as `method`, `url` and `data`\n- `error.response` The http response object with `url`, `headers`, and `data`\n\nIf the error is due to an `AbortSignal` being used, the resulting `AbortError` is bubbled up to the caller.\n\n## `request.defaults()`\n\nOverride or set default options. Example:\n\n```js\nimport { request } from \"@octokit/request\";\nconst myrequest = request.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\nmyrequest(`GET /orgs/{org}/repos`);\n```\n\nYou can call `.defaults()` again on the returned method, the defaults will cascade.\n\n```js\nconst myProjectRequest = request.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 myProjectRequestWithAuth = myProjectRequest.defaults({\n  headers: {\n    authorization: `token 0000000000000000000000000000000000000001`,\n  },\n});\n```\n\n`myProjectRequest` 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## `request.endpoint`\n\nSee https://github.com/octokit/endpoint.js. Example\n\n```js\nconst options = request.endpoint(\"GET /orgs/{org}/repos\", {\n  org: \"my-project\",\n  type: \"private\",\n});\n\n// {\n//   method: 'GET',\n//   url: 'https://api.github.com/orgs/my-project/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\nAll of the [`@octokit/endpoint`](https://github.com/octokit/endpoint.js) API can be used:\n\n- [`octokitRequest.endpoint()`](#endpoint)\n- [`octokitRequest.endpoint.defaults()`](#endpointdefaults)\n- [`octokitRequest.endpoint.merge()`](#endpointdefaults)\n- [`octokitRequest.endpoint.parse()`](#endpointmerge)\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 response = await request(\"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// Request is sent as\n//\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// not as\n//\n//     {\n//       ...\n//       body: '{\"data\": \"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\nrequest(\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### Set a custom Agent to your requests\n\nThe way to pass a custom `Agent` to requests is by creating a custom `fetch` function and pass it as `options.request.fetch`. A good example can be [undici's `fetch` implementation](https://undici.nodejs.org/#/?id=undicifetchinput-init-promise).\n\nExample ([See example in CodeSandbox](https://codesandbox.io/p/sandbox/nifty-stitch-wdlwlf))\n\n```js\nimport { request } from \"@octokit/request\";\nimport { fetch as undiciFetch, Agent } from \"undici\";\n\n/** @type {typeof import(\"undici\").fetch} */\nconst myFetch = (url, options) => {\n  return undiciFetch(url, {\n    ...options,\n    dispatcher: new Agent({\n      keepAliveTimeout: 10,\n      keepAliveMaxTimeout: 10,\n    }),\n  });\n};\n\nconst { data } = await request(\"GET /users/{username}\", {\n  username: \"octocat\",\n  headers: {\n    \"X-GitHub-Api-Version\": \"2022-11-28\",\n  },\n  options: {\n    request: {\n      fetch: myFetch,\n    },\n  },\n});\n```\n\n## LICENSE\n\n[MIT](LICENSE)\n","publish_time":1657548252555,"_cnpm_publish_time":1657548252555,"dist-tags":{"beta":"9.0.0-beta.1","latest":"10.0.16","release-6.x":"6.2.8","release-8.x":"8.4.1","release-9.x":"9.2.4"}}