{"name":"@octokit/core","version":"6.0.0","publishConfig":{"access":"public"},"type":"module","description":"Extendable client for GitHub's REST & GraphQL APIs","repository":{"type":"git","url":"git+https://github.com/octokit/core.js.git"},"keywords":["octokit","github","api","sdk","toolkit"],"author":{"name":"Gregor Martynus","url":"https://github.com/gr2m"},"license":"MIT","dependencies":{"@octokit/auth-token":"^5.0.0","@octokit/graphql":"^8.0.0","@octokit/request":"^9.0.0","@octokit/request-error":"^6.0.1","@octokit/types":"^12.0.0","before-after-hook":"^3.0.2","universal-user-agent":"^7.0.0"},"devDependencies":{"@octokit/auth-action":"^4.0.0","@octokit/auth-app":"^6.0.0","@octokit/auth-oauth-app":"^7.0.0","@octokit/tsconfig":"^3.0.0","@sinonjs/fake-timers":"^11.2.2","@types/fetch-mock":"^7.3.8","@types/jest":"^29.0.0","@types/lolex":"^5.1.0","@types/node":"^20.0.0","@types/sinonjs__fake-timers":"^8.1.5","esbuild":"^0.20.0","fetch-mock":"npm:@gr2m/fetch-mock@9.11.0-pull-request-644.1","glob":"^10.2.5","http-proxy-agent":"^7.0.0","jest":"^29.0.0","prettier":"3.2.5","proxy":"^2.0.0","semantic-release":"^23.0.0","semantic-release-plugin-update-version-in-files":"^1.0.0","ts-jest":"^29.0.0","typescript":"^5.0.0","undici":"^6.0.0"},"engines":{"node":">= 18"},"exports":{".":{"types":"./dist-types/index.d.ts","import":"./dist-src/index.js"}},"sideEffects":false,"_id":"@octokit/core@6.0.0","gitHead":"77f8a61107a582ccb0a0305510409a4a8cceff29","bugs":{"url":"https://github.com/octokit/core.js/issues"},"homepage":"https://github.com/octokit/core.js#readme","_nodeVersion":"20.11.1","_npmVersion":"10.4.0","dist":{"integrity":"sha512-0JifUnQKGoX83rMhy5bk2QNAPcO5hjD082YZ+wjqUa509RaZIn3F5SeqbKJoc2Zh+ld7rEQmlIeJzhVamSW2Xw==","shasum":"7c4d24cb05168b604ed4b974d89a48560b7b6929","tarball":"http://registry-npm.ywwl.com/@octokit/core/download/@octokit/core-6.0.0.tgz","fileCount":8,"unpackedSize":22518,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDvJnkEQGIClDPrr28AfHaHbGLuxtDTbxXdy+LKbQwFWwIhAKbp3T9k7M0WY/1CHj4Z1ar1uKMrsOYBWdUYdgUhhCbj"}],"size":7677,"noattachment":false,"key":"/@octokit/core/-/@octokit/core-6.0.0.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/core_6.0.0_1708887158812_0.9137494098875312"},"_hasShrinkwrap":false,"readme":"# core.js\n\n> Extendable client for GitHub's REST & GraphQL APIs\n\n[![@latest](https://img.shields.io/npm/v/@octokit/core.svg)](https://www.npmjs.com/package/@octokit/core)\n[![Build Status](https://github.com/octokit/core.js/workflows/Test/badge.svg)](https://github.com/octokit/core.js/actions?query=workflow%3ATest+branch%3Amain)\n\n<!-- toc -->\n\n- [Usage](#usage)\n  - [REST API example](#rest-api-example)\n  - [GraphQL example](#graphql-example)\n- [Options](#options)\n- [Defaults](#defaults)\n- [Authentication](#authentication)\n- [Logging](#logging)\n- [Hooks](#hooks)\n- [Plugins](#plugins)\n- [Build your own Octokit with Plugins and Defaults](#build-your-own-octokit-with-plugins-and-defaults)\n- [LICENSE](#license)\n\n<!-- tocstop -->\n\nIf you need a minimalistic library to utilize GitHub's [REST API](https://developer.github.com/v3/) and [GraphQL API](https://developer.github.com/v4/) which you can extend with plugins as needed, then `@octokit/core` is a great starting point.\n\nIf you don't need the Plugin API then using [`@octokit/request`](https://github.com/octokit/request.js/) or [`@octokit/graphql`](https://github.com/octokit/graphql.js/) directly is a good alternative.\n\n## Usage\n\n<table>\n<tbody valign=top align=left>\n<tr><th>\nBrowsers\n</th><td width=100%>\nLoad <code>@octokit/core</code> directly from <a href=\"https://esm.sh\">esm.sh</a>\n\n```html\n<script type=\"module\">\n  import { Octokit } from \"https://esm.sh/@octokit/core\";\n</script>\n```\n\n</td></tr>\n<tr><th>\nNode\n</th><td>\n\nInstall with <code>npm install @octokit/core</code>\n\n```js\nimport { Octokit } from \"@octokit/core\";\n```\n\n</td></tr>\n</tbody>\n</table>\n\nAs 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### REST API example\n\n```js\n// Create a personal access token at https://github.com/settings/tokens/new?scopes=repo\nconst octokit = new Octokit({ auth: `personal-access-token123` });\n\nconst response = await octokit.request(\"GET /orgs/{org}/repos\", {\n  org: \"octokit\",\n  type: \"private\",\n});\n```\n\nSee [`@octokit/request`](https://github.com/octokit/request.js) for full documentation of the `.request` method.\n\n### GraphQL example\n\n```js\nconst octokit = new Octokit({ auth: `secret123` });\n\nconst response = await octokit.graphql(\n  `query ($login: String!) {\n    organization(login: $login) {\n      repositories(privacy: PRIVATE) {\n        totalCount\n      }\n    }\n  }`,\n  { login: \"octokit\" },\n);\n```\n\nSee [`@octokit/graphql`](https://github.com/octokit/graphql.js) for full documentation of the `.graphql` method.\n\n## 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>options.authStrategy</code>\n      </th>\n      <td>\n        <code>Function<code>\n      </td>\n      <td>\n        Defaults to <a href=\"https://github.com/octokit/auth-token.js#readme\"><code>@octokit/auth-token</code></a>. See <a href=\"#authentication\">Authentication</a> below for examples.\n      </td>\n    </tr>\n    <tr>\n      <th>\n        <code>options.auth</code>\n      </th>\n      <td>\n        <code>String</code> or <code>Object</code>\n      </td>\n      <td>\n        See <a href=\"#authentication\">Authentication</a> below for examples.\n      </td>\n    </tr>\n    <tr>\n      <th>\n        <code>options.baseUrl</code>\n      </th>\n      <td>\n        <code>String</code>\n      </td>\n      <td>\n\nWhen using with GitHub Enterprise Server, set `options.baseUrl` to the root URL of the API. For example, if your GitHub Enterprise Server's hostname is `github.acme-inc.com`, then set `options.baseUrl` to `https://github.acme-inc.com/api/v3`. Example\n\n```js\nconst octokit = new Octokit({\n  baseUrl: \"https://github.acme-inc.com/api/v3\",\n});\n```\n\n</td></tr>\n    <tr>\n      <th>\n        <code>options.previews</code>\n      </th>\n      <td>\n        <code>Array of Strings</code>\n      </td>\n      <td>\n\nSome REST API endpoints require preview headers to be set, or enable\nadditional features. Preview headers can be set on a per-request basis, e.g.\n\n```js\noctokit.request(\"POST /repos/{owner}/{repo}/pulls\", {\n  mediaType: {\n    previews: [\"shadow-cat\"],\n  },\n  owner,\n  repo,\n  title: \"My pull request\",\n  base: \"main\",\n  head: \"my-feature\",\n  draft: true,\n});\n```\n\nYou can also set previews globally, by setting the `options.previews` option on the constructor. Example:\n\n```js\nconst octokit = new Octokit({\n  previews: [\"shadow-cat\"],\n});\n```\n\n</td></tr>\n    <tr>\n      <th>\n        <code>options.request</code>\n      </th>\n      <td>\n        <code>Object</code>\n      </td>\n      <td>\n\nSet a default request timeout (`options.request.timeout`) or an [`http(s).Agent`](https://nodejs.org/api/http.html#http_class_http_agent) e.g. for proxy usage (Node only, `options.request.agent`).\n\nThere are more `options.request.*` options, see [`@octokit/request` options](https://github.com/octokit/request.js#request). `options.request` can also be set on a per-request basis.\n\n</td></tr>\n    <tr>\n      <th>\n        <code>options.timeZone</code>\n      </th>\n      <td>\n        <code>String</code>\n      </td>\n      <td>\n\nSets the `Time-Zone` header which defines a timezone according to the [list of names from the Olson database](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones).\n\n```js\nconst octokit = new Octokit({\n  timeZone: \"America/Los_Angeles\",\n});\n```\n\nThe time zone header will determine the timezone used for generating the timestamp when creating commits. See [GitHub's Timezones documentation](https://developer.github.com/v3/#timezones).\n\n</td></tr>\n    <tr>\n      <th>\n        <code>options.userAgent</code>\n      </th>\n      <td>\n        <code>String</code>\n      </td>\n      <td>\n\nA custom user agent string for your app or library. Example\n\n```js\nconst octokit = new Octokit({\n  userAgent: \"my-app/v1.2.3\",\n});\n```\n\n</td></tr>\n  </tbody>\n</table>\n\n## Defaults\n\nYou can create a new Octokit class with customized default options.\n\n```js\nconst MyOctokit = Octokit.defaults({\n  auth: \"personal-access-token123\",\n  baseUrl: \"https://github.acme-inc.com/api/v3\",\n  userAgent: \"my-app/v1.2.3\",\n});\nconst octokit1 = new MyOctokit();\nconst octokit2 = new MyOctokit();\n```\n\nIf you pass additional options to your new constructor, the options will be merged shallowly.\n\n```js\nconst MyOctokit = Octokit.defaults({\n  foo: {\n    opt1: 1,\n  },\n});\nconst octokit = new MyOctokit({\n  foo: {\n    opt2: 1,\n  },\n});\n// options will be { foo: { opt2: 1 }}\n```\n\nIf you need a deep or conditional merge, you can pass a function instead.\n\n```js\nconst MyOctokit = Octokit.defaults((options) => {\n  return {\n    foo: Object.assign({}, options.foo, { opt1: 1 }),\n  };\n});\nconst octokit = new MyOctokit({\n  foo: { opt2: 1 },\n});\n// options will be { foo: { opt1: 1, opt2: 1 }}\n```\n\nBe careful about mutating the `options` object in the `Octokit.defaults` callback, as it can have unforeseen consequences.\n\n## Authentication\n\nAuthentication is optional for some REST API endpoints accessing public data, but is required for GraphQL queries. Using authentication also increases your [API rate limit](https://developer.github.com/v3/#rate-limiting).\n\nBy default, Octokit authenticates using the [token authentication strategy](https://github.com/octokit/auth-token.js). Pass in a token using `options.auth`. It can be a personal access token, an OAuth token, an installation access token or a JSON Web Token for GitHub App authentication. The `Authorization` header will be set according to the type of token.\n\n```js\nimport { Octokit } from \"@octokit/core\";\n\nconst octokit = new Octokit({\n  auth: \"mypersonalaccesstoken123\",\n});\n\nconst { data } = await octokit.request(\"/user\");\n```\n\nTo use a different authentication strategy, set `options.authStrategy`. A list of authentication strategies is available at [octokit/authentication-strategies.js](https://github.com/octokit/authentication-strategies.js/#readme).\n\nExample\n\n```js\nimport { Octokit } from \"@octokit/core\";\nimport { createAppAuth } from \"@octokit/auth-app\";\n\nconst appOctokit = new Octokit({\n  authStrategy: createAppAuth,\n  auth: {\n    appId: 123,\n    privateKey: process.env.PRIVATE_KEY,\n  },\n});\n\nconst { data } = await appOctokit.request(\"/app\");\n```\n\nThe `.auth()` method returned by the current authentication strategy can be accessed at `octokit.auth()`. Example\n\n```js\nconst { token } = await appOctokit.auth({\n  type: \"installation\",\n  installationId: 123,\n});\n```\n\n## Logging\n\nThere are four built-in log methods\n\n1. `octokit.log.debug(message[, additionalInfo])`\n1. `octokit.log.info(message[, additionalInfo])`\n1. `octokit.log.warn(message[, additionalInfo])`\n1. `octokit.log.error(message[, additionalInfo])`\n\nThey can be configured using the [`log` client option](client-options). By default, `octokit.log.debug()` and `octokit.log.info()` are no-ops, while the other two call `console.warn()` and `console.error()` respectively.\n\nThis is useful if you build reusable [plugins](#plugins).\n\nIf you would like to make the log level configurable using an environment variable or external option, we recommend the [console-log-level](https://github.com/watson/console-log-level) package. Example\n\n```js\nimport consoleLogLevel from \"console-log-level\";\nconst octokit = new Octokit({\n  log: consoleLogLevel({ level: \"info\" }),\n});\n```\n\n## Hooks\n\nYou can customize Octokit's request lifecycle with hooks.\n\n```js\noctokit.hook.before(\"request\", async (options) => {\n  validate(options);\n});\noctokit.hook.after(\"request\", async (response, options) => {\n  console.log(`${options.method} ${options.url}: ${response.status}`);\n});\noctokit.hook.error(\"request\", async (error, options) => {\n  if (error.status === 304) {\n    return findInCache(error.response.headers.etag);\n  }\n\n  throw error;\n});\noctokit.hook.wrap(\"request\", async (request, options) => {\n  // add logic before, after, catch errors or replace the request altogether\n  return request(options);\n});\n```\n\nSee [before-after-hook](https://github.com/gr2m/before-after-hook#readme) for more documentation on hooks.\n\n## Plugins\n\nOctokit’s functionality can be extended using plugins. The `Octokit.plugin()` method accepts a plugin (or many) and returns a new constructor.\n\nA plugin is a function which gets two arguments:\n\n1. the current instance\n2. the options passed to the constructor.\n\nIn order to extend `octokit`'s API, the plugin must return an object with the new methods. Please refrain from adding methods directly to the `octokit` instance, especialy if you depend on keys that do not exist in `@octokit/core`, such as `octokit.rest`.\n\n```js\n// index.js\nimport { Octokit } from \"@octokit/core\";\nimport myPlugin from \"./lib/my-plugin.js\";\nimport octokitPluginExample from \"octokit-plugin-example\";\nconst MyOctokit = Octokit.plugin(\n  myPlugin,\n  octokitPluginExample\n);\n\nconst octokit = new MyOctokit({ greeting: \"Moin moin\" });\noctokit.helloWorld(); // logs \"Moin moin, world!\"\noctokit.request(\"GET /\"); // logs \"GET / - 200 in 123ms\"\n\n// lib/my-plugin.js\nconst plugin = (octokit, options = { greeting: \"Hello\" }) => {\n  // hook into the request lifecycle\n  octokit.hook.wrap(\"request\", async (request, options) => {\n    const time = Date.now();\n    const response = await request(options);\n    console.log(\n      `${options.method} ${options.url} – ${response.status} in ${Date.now() -\n        time}ms`\n    );\n    return response;\n  });\n\n  // add a custom method\n  return {\n    helloWorld: () => console.log(`${options.greeting}, world!`);\n  }\n};\nexport default plugin;\n```\n\n## Build your own Octokit with Plugins and Defaults\n\nYou can build your own Octokit class with preset default options and plugins. In fact, this is mostly how the `@octokit/<context>` modules work, such as [`@octokit/action`](https://github.com/octokit/action.js):\n\n```js\nimport { Octokit } from \"@octokit/core\";\nimport { paginateRest } from \"@octokit/plugin-paginate-rest\";\nimport { throttling } from \"@octokit/plugin-throttling\";\nimport { retry } from \"@octokit/plugin-retry\";\nimport { createActionAuth } from \"@octokit/auth-action\";\nconst MyActionOctokit = Octokit.plugin(\n  paginateRest,\n  throttling,\n  retry,\n).defaults({\n  throttle: {\n    onAbuseLimit: (retryAfter, options) => {\n      /* ... */\n    },\n    onRateLimit: (retryAfter, options) => {\n      /* ... */\n    },\n  },\n  authStrategy: createActionAuth,\n  userAgent: `my-octokit-action/v1.2.3`,\n});\n\nconst octokit = new MyActionOctokit();\nconst installations = await octokit.paginate(\"GET /app/installations\");\n```\n\n## LICENSE\n\n[MIT](LICENSE)\n","publish_time":1708887158973,"_cnpm_publish_time":1708887158973,"dist-tags":{"beta":"6.0.0-beta.5","latest":"7.0.8","release-5.x":"5.2.2","release-6.x":"6.1.6"}}