{"name":"@octokit/app","version":"13.1.0","license":"MIT","_id":"@octokit/app@13.1.0","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"}],"homepage":"https://github.com/octokit/app.js#readme","bugs":{"url":"https://github.com/octokit/app.js/issues"},"dist":{"shasum":"b9965fc0d913ce731837422c55c9385bef8b2a6c","tarball":"http://registry-npm.ywwl.com/@octokit/app/download/@octokit/app-13.1.0.tgz","fileCount":23,"integrity":"sha512-w0DCS/+bvrIL0iva89VSSa9YhIy1YHATSXMYrHQtgsBHpbuAnMn7QEknYhuMn/4h2dGg9cNjU+3XeAF5eyNmEA==","signatures":[{"sig":"MEUCIBgqMdz4RFOlNUJ0Su+dbG84QaBjAEa3GEoVYH/89r0eAiEAwF97SwfEv+chT1pqn61pD0O6lWUe3g1JOUNu6EZ6Zo4=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":77382,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJjiT0iACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmp7dxAAk1IZRDdO3lx93B2kcKUzjYhLIJ8sCWkLZkiFP00eJh62KjpS\r\nexnVr0el4RIdKpmR8LlUw6yzqhm6QkFDcMlOYSeZpXpkko6TGRpaokqx1+rG\r\nAjN5IJeACDiCzxYG+twuvnt3oeCJWQfujmKe3ajnBQTOMtw+0UAQZjDWLFqi\r\nKNsk7uPxtDuZWkKIp1GmHZALI+tUyZYf3p/2QY3IZct8rIqtK8NGI3yAsNap\r\nGE2Chl+a4yTNjfv9hEj1C/wH6WZjF2zCDg1WUW2/JzC5wMyWspvOwGmBijDw\r\nHm8seH3yVq8cPM0cVe+OraTht2Pq0pibIBXQdSRddx7xu9zBobcvCZTUDST/\r\nxmq6NKKnb1zDfWb1q8Lq7ZzmY/2LJZQK6+SHKj8DGlMf1bRx5M91MqRYjGJ7\r\n44YklHk3KQnmSwSOLiZU9fCI3rqcsLu5qpIIQOd4Vt+D03G7LNii/og68wzh\r\nu9lsJJuYmPIv0WAnqUhz60R1Aka9fuLH6ynOgLVwJVlGBX9KubRcwXMirqLb\r\nzwuwl5I2+ODFEiwwytj5JJFJ/OvtxwQBMbONsRsT0Kk6Q6PlSpehySV/2P+E\r\nBcfIqnGVzGZUDIDcpKZGDIqLgBm2R3DXgIvYyeyJ7spJlCXUYmCP1ktim9N6\r\niJgqE10isoxX4hbLhTs+m/8c1DUMlaYeUvs=\r\n=KNF4\r\n-----END PGP SIGNATURE-----\r\n","size":15323,"noattachment":false,"key":"/@octokit/app/-/@octokit/app-13.1.0.tgz"},"main":"dist-node/index.js","pika":true,"types":"dist-types/index.d.ts","source":"dist-src/index.js","engines":{"node":">= 14"},"gitHead":"3e44c5d6ee9e3bd346afc01979953ca7848625b2","_npmUser":{"name":"octokitbot","email":"security+octokitbot@github.com"},"repository":{"url":"git+https://github.com/octokit/app.js.git","type":"git"},"_npmVersion":"8.19.2","description":"GitHub Apps toolset for Node.js","directories":{},"sideEffects":false,"_nodeVersion":"16.18.1","dependencies":{"@octokit/core":"^4.0.0","@octokit/types":"^8.0.0","@octokit/auth-app":"^4.0.0","@octokit/webhooks":"^10.0.0","@octokit/oauth-app":"^4.0.7","@octokit/auth-unauthenticated":"^3.0.0","@octokit/plugin-paginate-rest":"^5.0.0"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"jest":"^29.0.0","express":"^4.17.1","ts-jest":"^29.0.0","mockdate":"^3.0.2","prettier":"2.8.0","@pika/pack":"^0.3.7","fetch-mock":"^9.10.7","node-fetch":"^2.6.7","typescript":"^4.0.5","@types/jest":"^29.0.0","@types/node":"^18.0.0","@types/node-fetch":"^2.5.8","@pika/plugin-build-node":"^0.9.1","@pika/plugin-ts-standard-pkg":"^0.9.1","semantic-release-plugin-update-version-in-files":"^1.0.0"},"_npmOperationalInternal":{"tmp":"tmp/app_13.1.0_1669938466301_0.977177893563641","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":1669938466502,"_cnpm_publish_time":1669938466502,"dist-tags":{"beta":"15.0.0-beta.5","latest":"16.1.4","release-12.x":"12.0.7"}}