{"name":"@octokit/app","version":"3.0.1","license":"MIT","_id":"@octokit/app@3.0.1","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":"072e48127eb3c004f9a8ae9c81bfbf8c1850b41d","tarball":"http://registry-npm.ywwl.com/@octokit/app/download/@octokit/app-3.0.1.tgz","fileCount":16,"integrity":"sha512-uUN1XCzHJTqiKbeTKAuTYAiu/IYV5uN606smwGZsg//8xVHvlwdv7x9nwpYAs32addRk+TZB55nitwgQlzt1jw==","signatures":[{"sig":"MEUCIH0Wknp607Pq+ssEZGYUV/0YkfTTYTv/LGAElb6KQC5oAiEA8KlhyZqcCFhxwYUuLF6ED3c0UuBT0vhfL6M9tMZF45g=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":137786,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJdAWrUCRA9TVsSAnZWagAALpUP/iE37dmpjN7YTvDozFNU\nn/lmo6z8Q/K9zpy8hla4NNyLW6LpOuj3PxVj4bFnEd0WcUcoHhS5NZ76cpE6\ny1fq1b7bxhjNi+LIRDlOxK9UATy/1QTZK4l+MU9xEj3htG3qIRxvh57gzWLS\nLADknmdyZXmmJHiSLKIpNL3eugTNTbNnM/4YrUhEIOQOGFJnrtbZ6M6gqohC\nC/1/JIz8+4plPs7U2rAvVFyHTSqeExXGME9hRtB1CDX7qmHFAy6IJwo3sWWX\nJH/J5OSOzRq1sDrfurCStgLbvr8BGCRv4tKfqRJuJwNh7tvjaxRMKgB/5LeN\nZJ1Mk1yDfhU/firm8CKv5U1mTzkGnXoq7doGvlTVEIuodRQw+ZiP96mZ1xRV\nKr99AjdxeCWVcQhFdos7mvBv8+xTDn3VW8i+RW6uw9cj2F0EJS4C9FP8H1sw\ntKcwc0NcibuwAZTVEy4YAAKzZJ3U2Aj76DQNgdodIW1OCQC/OtoFOv+yA2/I\nV/3mWqCzPvIlFLCRYZwdWAZIzOA3q9hm/gYX5NGE5rIBuvlGAW3aotSkW2sN\n0wdZD13UUp+qOB6RUQqF1tW9M8KiaJgg9YwPJbhHrnx21Cs5ndoTTx5jmB0F\nsLKL31uGxkhpFScvZWCeyPahp4op8ahgUP3E4iY62QSpHRVYx3VuwfSFguDg\nLN2x\r\n=F+mm\r\n-----END PGP SIGNATURE-----\r\n","size":31731,"noattachment":false,"key":"/@octokit/app/-/@octokit/app-3.0.1.tgz"},"main":"dist-node/index.js","pika":true,"types":"dist-types/index.d.ts","unpkg":"dist-web/index.bundled.js","module":"dist-web/index.js","source":"dist-src/index.js","_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":{},"sideEffects":false,"_nodeVersion":"10.16.0","dependencies":{"lru-cache":"^5.1.1","jsonwebtoken":"^8.3.0","@octokit/request":"^4.1.0"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"jest":"^24.8.0","nock":"^10.0.2","lolex":"^4.0.1","ts-jest":"^24.0.2","prettier":"^1.17.1","@pika/pack":"^0.3.7","typescript":"^3.4.5","@types/jest":"^24.0.13","@types/nock":"^10.0.3","simple-mock":"^0.8.0","@types/lolex":"^3.1.1","@types/lru-cache":"^5.1.0","semantic-release":"^15.12.1","@types/simple-mock":"^0.8.1","@types/jsonwebtoken":"^8.3.0","@pika/plugin-build-web":"^0.4.0","@pika/plugin-build-node":"^0.4.0","@pika/plugin-bundle-web":"^0.4.0","pika-plugin-unpkg-field":"^1.1.0","@pika/plugin-ts-standard-pkg":"^0.4.0"},"_npmOperationalInternal":{"tmp":"tmp/app_3.0.1_1560373971163_0.5901705270281552","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":1560373971306,"_cnpm_publish_time":1560373971306,"dist-tags":{"beta":"15.0.0-beta.5","latest":"16.1.4","release-12.x":"12.0.7"}}