{"name":"@octokit-next/request","version":"1.13.1","description":"Simplified version of `@octokit/request` to experiment with ESM and types","publishConfig":{"access":"public"},"type":"module","exports":"./index.js","types":"./index.d.ts","repository":{"type":"git","url":"git+https://github.com/octokit/octokit-next.js.git","directory":"packages/core"},"homepage":"https://github.com/octokit/octokit-next.js/tree/main/packages/request#readme","author":{"name":"Gregor Martynus","url":"https://twitter.com/gr2m"},"license":"MIT","dependencies":{"@octokit-next/types":"1.13.1","node-fetch":"3.0.0","type-fest":"^2.0.0"},"gitHead":"d667e4444eaf97f814e7adefe0d7576679fd5fb8","bugs":{"url":"https://github.com/octokit/octokit-next.js/issues"},"_id":"@octokit-next/request@1.13.1","_nodeVersion":"16.10.0","_npmVersion":"7.24.2","dist":{"integrity":"sha512-ZOeIZRsuSWZPusJVzCAD3k8pT7p3pUQMkfeDR5NDZ2ndVOUsiSrrI4Y5LvJw0AVlf5wqYGGGMwKRR0Af6xB4qA==","shasum":"16d6f318069f45a308464ccdabce30442c8db90d","tarball":"http://registry-npm.ywwl.com/@octokit-next/request/download/@octokit-next/request-1.13.1.tgz","fileCount":4,"unpackedSize":2284,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQC20JGlpnIhKp04/ZW7frC2LF/0llrhe0HYTuhFxF0TfQIgYvk9bF5MiiSUaZYZriuepUxS7ysHtJKIeQZcAdXPMiQ="}],"size":1189,"noattachment":false,"key":"/@octokit-next/request/-/@octokit-next/request-1.13.1.tgz"},"_npmUser":{"name":"octokitbot","email":"security+octokitbot@github.com"},"directories":{},"maintainers":[{"name":"gr2m","email":"gregor@martynus.net"},{"name":"octokitbot","email":"security+octokitbot@github.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/request_1.13.1_1633411185593_0.8392642121621698"},"_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-next/request.svg)](https://www.npmjs.com/package/@octokit-next/request)\n[![Build Status](https://github.com/octokit-next/request.js/workflows/Test/badge.svg)](https://github.com/octokit-next/request.js/actions?query=workflow%3ATest+branch%3Amaster)\n\n`@octokit-next/request` is a request library for modern JavaScript runtime environments (e.g. Browsers, Node, or Deno) 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)\n([node-fetch](https://github.com/bitinn/node-fetch) when the runtime has no native `fetch` API).\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  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-next/request) (\\<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.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-next/request</code> directly from <a href=\"https://cdn.skypack.dev\">cdn.skypack.dev</a>\n        \n```html\n<script type=\"module\">\nimport { request } from \"https://cdn.skypack.dev/@octokit-next/request\";\n</script>\n```\n\n</td></tr>\n<tr><th>\nNode\n</th><td>\n\nInstall with <code>npm install @octokit-next/request</code>\n\n```js\nimport { request } from \"@octokit-next/request\";\n```\n\n</td></tr>\n<tr><th>\nDeno\n</th><td>\n\nLoad <code>@octokit-next/request</code> directly from <a href=\"https://cdn.skypack.dev\">cdn.skypack.dev</a>, including types.\n\n```js\nimport { request } from \"https://cdn.skypack.dev/@octokit-next/request?dts\";\n```\n\n</td></tr>\n</tbody>\n</table>\n\n### REST API example\n\n```js\n// Following GitHub docs formatting:\n// https://docs.github.com/en/rest/repos/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). But in the end a GraphQL query is just a `POST /graphql` request:\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, we recommend an [authentication strategy plugin](https://github.com/octokit/authentication-strategies.js#readme).\n\n```js\n// expects `APP_ID` and `PRIVATE_KEY` to be set.\nimport { createAppAuth } from \"@octokit/auth-app\";\nconst auth = createAppAuth({\n  appId: APP_ID,\n  privateKey: PRIVATE_KEY,\n  installationId: 123,\n});\nconst requestWithAuth = request.defaults({\n  request: {\n    hook: auth.hook,\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.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 GraphQL schema preview, e.g. `package-deletes` or `flash`. See <a href=\"https://docs.github.com/en/graphql/overview/schema-previews\">Schema previews</a>.\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.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  <tr>\n    <th align=left>\n      <code>options.request.agent</code>\n    </th>\n    <td>\n      <a href=\"https://nodejs.org/api/http.html#http_class_http_agent\">http(s).Agent</a> instance\n    </td>\n    <td>\n     Node only. Useful for custom proxy, certificate, or dns lookup.\n    </td>\n  </tr>\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://github.com/bitinn/node-fetch\">built-in fetch method</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-next/request.js#request\"><code>request()</code></a>. This option works great in conjuction 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.timeout</code>\n    </th>\n    <td>\n      Number\n    </td>\n    <td>\n     Node only. Request/response timeout in ms, it resets on redirect. 0 to disable (OS limit applies). <a href=\"#options-request-signal\">options.request.signal</a> is recommended instead.\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-next/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## LICENSE\n\n[MIT](LICENSE)\n","publish_time":1633411185729,"_cnpm_publish_time":1633411185729,"dist-tags":{"latest":"3.0.0"}}