{"name":"@octokit/app","version":"2.2.2","author":{"name":"Bex Warner"},"license":"MIT","_id":"@octokit/app@2.2.2","maintainers":[{"name":"bkeepers","email":"brandon@opensoul.org"},{"name":"gr2m","email":"gregor@martynus.net"},{"name":"octokitbot","email":"octokitbot@martynus.net"}],"contributors":[{"url":"https://github.com/gr2m","name":"Gregor Martynus"}],"homepage":"https://github.com/octokit/app.js#readme","bugs":{"url":"https://github.com/octokit/app.js/issues"},"dist":{"shasum":"a1b8248f64159eeccbe4000d888fdae4163c4ad8","tarball":"http://registry-npm.ywwl.com/@octokit/app/download/@octokit/app-2.2.2.tgz","fileCount":11,"integrity":"sha512-nUwS8jW107ROGuI0Tq4Ga+Zno6CovwaS+Oen6BOKJmoFMLqqB3oXeGZ6InkidtdmUNiYhMtNq2lydb0WVLT8Zg==","signatures":[{"sig":"MEQCICWczsigE2j/ROKzWokY8yXol5mGpyHYUbdifopyGNDHAiAA9nDgVOLkGprNCcUqcwVjcfBCj5/PXU2/Ibx012uHVQ==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":20168,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJcjHh6CRA9TVsSAnZWagAAmJsP/2Ja0ZxSPNBhtVpVaoVw\n1blThKm2VWnrvc1z38ikjaaVn0B1P85WL5f5PwDSv6OW+qCt8tV//OcJqXXl\napdPOHuox385PgA4gvX4QQvrkiOktTDv59H7oh1oTEyfyVpBQQEy+CBBE4hC\nWbJjKxjN6GAnkYTsCLcCANXZRdhDNmrMWUqdp/TZ4cZrtbCgD5S2J76nP32j\nad4rgMiLOjnzlgadmDnj+ZUS3wKGDq/VcLiu18QzwgstoNZvz7qgGVVLpHdJ\nDaU3NaAnhh+efl/MGy+6lGnWwvUUlfWn6phfYBDvU+GBcNMBOD2avfUU8MeR\n7nn4EOmP4fT7+jmCr6JgIXT2Vqo5pUK3u5u3my1MSSvdLTtJtifRWDk5hpx5\nlSLS+jAnrGEnhgG6dESIeUXflhRLkHwNGWUfClfIvab6oTtUMwzCZ7JYs1ZY\n3QIwC+bVq41oUYeps+xVQOfvGIfkjkJav81krhiMhd0qWXOE/PZBd5zX8K3A\ncX4ZgL0RS0JVMiCpzl28vV+JFYHo54OcSbIL6hdIpJ/A9pNFYqCbN+cdU9p6\nvGdJz/SLW5VSAHPtYxYAZH7AExStHs1PReF5QPBNiTPeU6mt3D2lwhNfJa1c\nN0dFsfU2uvIMpnvRfOkA7hWIYbTiaEG+BzX5rn4+tsfkfA5bgvOsblF8Q6dW\nKcNv\r\n=DDUs\r\n-----END PGP SIGNATURE-----\r\n","size":8297,"noattachment":false,"key":"/@octokit/app/-/@octokit/app-2.2.2.tgz"},"main":"index.js","types":"index.d.ts","gitHead":"4cca5cb76c2564acaeca3dd5dabcd63256c18000","scripts":{"test":"nyc mocha","pretest":"standard","coverage":"nyc report --reporter=html && open coverage/index.html","validate:ts":"tsc --target es6 --noImplicitAny index.d.ts","coverage:upload":"nyc report --reporter=text-lcov | coveralls"},"_npmUser":{"name":"octokitbot","email":"octokitbot@martynus.net"},"deprecated":"'@octokit/app' will be repurposed in future. Use '@octokit/auth-app' instead","repository":{"url":"git+https://github.com/octokit/app.js.git","type":"git"},"_npmVersion":"6.4.1","description":"GitHub Apps toolset for Node.js","directories":{},"_nodeVersion":"10.15.3","dependencies":{"lru-cache":"^5.1.1","jsonwebtoken":"^8.3.0","@octokit/request":"^2.1.2","@types/lru-cache":"^5.1.0"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"nyc":"^13.1.0","chai":"^4.1.2","nock":"^10.0.2","lolex":"^3.0.0","mocha":"^6.0.0","standard":"^12.0.1","coveralls":"^3.0.2","typescript":"^3.3.3333","simple-mock":"^0.8.0","semantic-release":"^15.12.1"},"_npmOperationalInternal":{"tmp":"tmp/app_2.2.2_1552709753277_0.21364129846143776","host":"s3://npm-registry-packages"},"readme":"# app.js\n\n> GitHub App toolset for Node.js\n\n[![@latest](https://img.shields.io/npm/v/@octokit/app.svg)](https://www.npmjs.com/package/@octokit/app)\n[![Build Status](https://github.com/octokit/app.js/workflows/Test/badge.svg)](https://github.com/octokit/app.js/actions?workflow=Test)\n\n<!-- toc -->\n\n- [Usage](#usage)\n- [`App.defaults(options)`](#appdefaultsoptions)\n- [Constructor](#constructor)\n- [API](#api)\n  - [`app.octokit`](#appoctokit)\n  - [`app.log`](#applog)\n  - [`app.getInstallationOctokit`](#appgetinstallationoctokit)\n  - [`app.eachInstallation`](#appeachinstallation)\n  - [`app.eachRepository`](#appeachrepository)\n  - [`app.getInstallationUrl`](#appgetinstallationurl)\n  - [`app.webhooks`](#appwebhooks)\n  - [`app.oauth`](#appoauth)\n- [Middlewares](#middlewares)\n  - [`createNodeMiddleware(app, options)`](#createnodemiddlewareapp-options)\n- [Contributing](#contributing)\n- [License](#license)\n\n<!-- tocstop -->\n\n## Usage\n\n<table>\n<tbody valign=top align=left>\n<tr><th>\n\nBrowsers\n\n</th><td width=100%>\n\n`@octokit/app` is not meant for browser usage.\n\n</td></tr>\n<tr><th>\n\nNode\n\n</th><td>\n\nInstall with `npm install @octokit/app`\n\n```js\nconst { App, createNodeMiddleware } = require(\"@octokit/app\");\n```\n\n</td></tr>\n</tbody>\n</table>\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` by setting `\"moduleResolution\": \"node16\", \"module\": \"node16\"`.\n>\n> See the TypeScript docs on [package.json \"exports\"](https://www.typescriptlang.org/docs/handbook/modules/reference.html#packagejson-exports).<br>\n> See this [helpful guide on transitioning to ESM](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c) from [@sindresorhus](https://github.com/sindresorhus)\n\n```js\nconst app = new App({\n  appId: 123,\n  privateKey: \"-----BEGIN PRIVATE KEY-----\\n...\",\n  oauth: {\n    clientId: \"0123\",\n    clientSecret: \"0123secret\",\n  },\n  webhooks: {\n    secret: \"secret\",\n  },\n});\n\nconst { data } = await app.octokit.request(\"/app\");\nconsole.log(\"authenticated as %s\", data.name);\nfor await (const { installation } of app.eachInstallation.iterator()) {\n  for await (const { octokit, repository } of app.eachRepository.iterator({\n    installationId: installation.id,\n  })) {\n    await octokit.request(\"POST /repos/{owner}/{repo}/dispatches\", {\n      owner: repository.owner.login,\n      repo: repository.name,\n      event_type: \"my_event\",\n    });\n  }\n}\n\napp.webhooks.on(\"issues.opened\", async ({ octokit, payload }) => {\n  await octokit.request(\n    \"POST /repos/{owner}/{repo}/issues/{issue_number}/comments\",\n    {\n      owner: payload.repository.owner.login,\n      repo: payload.repository.name,\n      issue_number: payload.issue.number,\n      body: \"Hello World!\",\n    },\n  );\n});\n\napp.oauth.on(\"token\", async ({ token, octokit }) => {\n  const { data } = await octokit.request(\"GET /user\");\n  console.log(`Token retrieved for ${data.login}`);\n});\n\nrequire(\"http\").createServer(createNodeMiddleware(app)).listen(3000);\n// can now receive requests at /api/github/*\n```\n\n## `App.defaults(options)`\n\nCreate a new `App` with custom defaults for the [constructor options](#constructor-options)\n\n```js\nconst MyApp = App.defaults({\n  Octokit: MyOctokit,\n});\nconst app = new MyApp({ clientId, clientSecret });\n// app.octokit is now an instance of MyOctokit\n```\n\n## Constructor\n\n<table width=\"100%\">\n  <thead align=left>\n    <tr>\n      <th width=150>\n        name\n      </th>\n      <th width=70>\n        type\n      </th>\n      <th>\n        description\n      </th>\n    </tr>\n  </thead>\n  <tbody align=left valign=top>\n    <tr>\n      <th>\n        <code>appId</code>\n      </th>\n      <th>\n        <code>number</code>\n      </th>\n      <td>\n        <strong>Required</strong>. Find the <strong>App ID</strong> on the app’s about page in settings.\n      </td>\n    </tr>\n    <tr>\n      <th>\n        <code>privateKey</code>\n      </th>\n      <th>\n        <code>string</code>\n      </th>\n      <td>\n        <strong>Required</strong>. Content of the <code>*.pem</code> file you downloaded from the app’s about page. You can generate a new private key if needed.\n      </td>\n    </tr>\n    <tr id=\"constructor-option-octokit\">\n      <th>\n        <code>Octokit</code>\n      </th>\n      <th>\n        <code>Constructor</code>\n      </th>\n      <td>\n\nYou can pass in your own Octokit constructor with custom defaults and plugins. Note that `authStrategy` will be always be set to `createAppAuth` from [`@octokit/auth-app`](https://github.com/octokit/auth-app.js).\n\nFor usage with enterprise, set `baseUrl` to the hostname + `/api/v3`. Example:\n\n```js\nconst { Octokit } = require(\"@octokit/core\");\nnew App({\n  appId: 123,\n  privateKey: \"-----BEGIN PRIVATE KEY-----\\n...\",\n  oauth: {\n    clientId: 123,\n    clientSecret: \"secret\",\n  },\n  webhooks: {\n    secret: \"secret\",\n  },\n  Octokit: Octokit.defaults({\n    baseUrl: \"https://ghe.my-company.com/api/v3\",\n  }),\n});\n```\n\nDefaults to [`@octokit/core`](https://github.com/octokit/core.js).\n\n</td></tr>\n    <tr id=\"constructor-option-log\">\n      <th>\n        <code>log</code>\n      </th>\n      <th>\n        <code>object</code>\n      </th>\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>\n        <code>webhooks.secret</code>\n      </th>\n      <th>\n        <code>string</code>\n      </th>\n      <td>\n        <strong>Required.</strong> Secret as configured in the GitHub App's settings.\n      </td>\n    </tr>\n    <tr>\n      <th>\n        <code>webhooks.transform</code>\n      </th>\n      <th>\n        <code>function</code>\n      </th>\n      <td>\n        Only relevant for `app.webhooks.on`. Transform emitted event before calling handlers. Can be asynchronous. \n      </td>\n    </tr>\n    <tr>\n      <th>\n        <code>oauth.clientId</code>\n      </th>\n      <th>\n        <code>number</code>\n      </th>\n      <td>\n        Find the OAuth <strong>Client ID</strong> on the app’s about page in settings.\n      </td>\n    </tr>\n    <tr>\n      <th>\n        <code>oauth.clientSecret</code>\n      </th>\n      <th>\n        <code>number</code>\n      </th>\n      <td>\n        Find the OAuth  <strong>Client Secret</strong> on the app’s about page in settings.\n      </td>\n    </tr>\n    <tr>\n      <th>\n        <code>oauth.allowSignup</code>\n      </th>\n      <th>\n        <code>boolean</code>\n      </th>\n      <td>\n        Sets the default value for <code>app.oauth.getAuthorizationUrl(options)</code>.\n      </td>\n    </tr>\n  </tbody>\n</table>\n\n## API\n\n### `app.octokit`\n\nOctokit instance. Uses the [`Octokit` constructor option](#constructor-option-octokit) if passed.\n\n### `app.log`\n\nSee https://github.com/octokit/core.js#logging. Customize using the [`log` constructor option](#constructor-option-log).\n\n### `app.getInstallationOctokit`\n\n```js\nconst octokit = await app.getInstallationOctokit(123);\n```\n\n### `app.eachInstallation`\n\n```js\nfor await (const { octokit, installation } of app.eachInstallation.iterator()) { /* ... */ }\nawait app.eachInstallation(({ octokit, installation }) => /* ... */)\n```\n\n### `app.eachRepository`\n\n```js\nfor await (const { octokit, repository } of app.eachRepository.iterator()) { /* ... */ }\nawait app.eachRepository(({ octokit, repository }) => /* ... */)\n```\n\nOptionally pass installation ID to iterate through all repositories in one installation\n\n```js\nfor await (const { octokit, repository } of app.eachRepository.iterator({ installationId })) { /* ... */ }\nawait app.eachRepository({ installationId }, ({ octokit, repository }) => /* ... */)\n```\n\n### `app.getInstallationUrl`\n\n```js\nconst installationUrl = await app.getInstallationUrl();\nreturn res.redirect(installationUrl);\n```\n\nOptionally pass the ID of a GitHub organization or user to request installation on that specific target.\n\nIf the user will be sent to a redirect URL after installation (such as if you request user authorization during installation), you can also supply a `state` string that will be included in the query of the post-install redirect.\n\n```js\nconst installationUrl = await app.getInstallationUrl({ state, target_id });\nreturn res.redirect(installationUrl);\n```\n\n### `app.webhooks`\n\nAn [`@octokit/webhooks` instance](https://github.com/octokit/webhooks.js/#readme)\n\n### `app.oauth`\n\nAn [`@octokit/oauth-app` instance](https://github.com/octokit/oauth-app.js/#readme)\n\n## Middlewares\n\nA middleware is a method or set of methods to handle requests for common environments.\n\nBy default, all middlewares expose the following routes\n\n| Route                            | Route Description                                                                                                                                                                                                                                               |\n| -------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |\n| `POST /api/github/webhooks`      | Endpoint to receive GitHub Webhook Event requests                                                                                                                                                                                                               |\n| `GET /api/github/oauth/login`    | Redirects to GitHub's authorization endpoint. Accepts optional `?state` query parameter.                                                                                                                                                                        |\n| `GET /api/github/oauth/callback` | The client's redirect endpoint. This is where the `token` event gets triggered                                                                                                                                                                                  |\n| `POST /api/github/oauth/token`   | Exchange an authorization code for an OAuth Access token. If successful, the `token` event gets triggered.                                                                                                                                                      |\n| `GET /api/github/oauth/token`    | Check if token is valid. Must authenticate using token in `Authorization` header. Uses GitHub's [`POST /applications/{client_id}/token`](https://developer.github.com/v3/apps/oauth_applications/#check-a-token) endpoint                                       |\n| `PATCH /api/github/oauth/token`  | Resets a token (invalidates current one, returns new token). Must authenticate using token in `Authorization` header. Uses GitHub's [`PATCH /applications/{client_id}/token`](https://developer.github.com/v3/apps/oauth_applications/#reset-a-token) endpoint. |\n| `DELETE /api/github/oauth/token` | Invalidates current token, basically the equivalent of a logout. Must authenticate using token in `Authorization` header.                                                                                                                                       |\n| `DELETE /api/github/oauth/grant` | Revokes the user's grant, basically the equivalent of an uninstall. must authenticate using token in `Authorization` header.                                                                                                                                    |\n\n### `createNodeMiddleware(app, options)`\n\nMiddleware for Node's built in http server or [`express`](https://expressjs.com/).\n\n```js\nconst { App, createNodeMiddleware } = require(\"@octokit/app\");\n\nconst app = new App({\n  appId: 123,\n  privateKey: \"-----BEGIN PRIVATE KEY-----\\n...\",\n  oauth: {\n    clientId: \"0123\",\n    clientSecret: \"0123secret\",\n  },\n  webhooks: {\n    secret: \"secret\",\n  },\n});\n\nconst middleware = createNodeMiddleware(app);\nrequire(\"http\")\n  .createServer(async (req, res) => {\n    // `middleware` returns `false` when `req` is unhandled (beyond `/api/github`)\n    if (await middleware(req, res)) return;\n    res.writeHead(404);\n    res.end();\n  })\n  .listen(3000);\n// can now receive user authorization callbacks at /api/github/*\n```\n\nThe middleware returned from `createNodeMiddleware` can also serve as an\n`Express.js` middleware directly.\n\n<table width=\"100%\">\n  <thead align=left>\n    <tr>\n      <th width=150>\n        name\n      </th>\n      <th width=70>\n        type\n      </th>\n      <th>\n        description\n      </th>\n    </tr>\n  </thead>\n  <tbody align=left valign=top>\n    <tr>\n      <th>\n        <code>app</code>\n      </th>\n      <th>\n        <code>App instance</code>\n      </th>\n      <td>\n        <strong>Required</strong>.\n      </td>\n    </tr>\n    <tr>\n      <th>\n        <code>options.pathPrefix</code>\n      </th>\n      <th>\n        <code>string</code>\n      </th>\n      <td>\n\nAll exposed paths will be prefixed with the provided prefix. Defaults to `\"/api/github\"`\n\n</td>\n    </tr>\n    <tr>\n      <td>\n        <code>log</code>\n        <em>\n          object\n        </em>\n      </td>\n      <td>\n\nUsed for internal logging. Defaults to [`console`](https://developer.mozilla.org/en-US/docs/Web/API/console) with `debug` and `info` doing nothing.\n\n      </td>\n    </tr>\n\n  </tbody>\n</table>\n\n## Contributing\n\nSee [CONTRIBUTING.md](CONTRIBUTING.md)\n\n## License\n\n[MIT](LICENSE)\n","publish_time":1552709753528,"_cnpm_publish_time":1552709753528,"dist-tags":{"beta":"15.0.0-beta.5","latest":"16.1.4","release-12.x":"12.0.7"}}