@octokit/core
Advanced tools
Comparing version 1.0.0 to 1.1.0
@@ -53,3 +53,8 @@ 'use strict'; | ||
if (options.auth) { | ||
requestDefaults.headers.authorization = withAuthorizationPrefix(options.auth); | ||
if (typeof options.auth === "string") { | ||
requestDefaults.headers.authorization = withAuthorizationPrefix(options.auth); | ||
} else { | ||
// @ts-ignore | ||
hook.wrap("request", options.auth.hook); | ||
} | ||
} | ||
@@ -56,0 +61,0 @@ |
@@ -35,3 +35,9 @@ import getUserAgent from "universal-user-agent"; | ||
if (options.auth) { | ||
requestDefaults.headers.authorization = withAuthorizationPrefix(options.auth); | ||
if (typeof options.auth === "string") { | ||
requestDefaults.headers.authorization = withAuthorizationPrefix(options.auth); | ||
} | ||
else { | ||
// @ts-ignore | ||
hook.wrap("request", options.auth.hook); | ||
} | ||
} | ||
@@ -38,0 +44,0 @@ this.request = request.defaults(requestDefaults); |
/// <reference types="node" /> | ||
import { Agent } from "http"; | ||
import { request as Request } from "@octokit/request"; | ||
import { Octokit } from "."; | ||
export declare type OctokitOptions = { | ||
auth?: string; | ||
auth?: string | AutenticationHook; | ||
request?: OctokitRequestOptions; | ||
[option: string]: any; | ||
}; | ||
interface AutenticationHook { | ||
(options?: any): any; | ||
hook: (request: typeof Request, options: Endpoint) => ReturnType<typeof Request>; | ||
} | ||
export declare type Plugin = (octokit: Octokit, options?: OctokitOptions) => void; | ||
@@ -52,2 +57,14 @@ /** | ||
}; | ||
/** | ||
* Relative or absolute URL. Examples: `'/orgs/:org'`, `https://example.com/foo/bar` | ||
*/ | ||
export declare type Url = string; | ||
/** | ||
* Request method | ||
*/ | ||
export declare type Method = "DELETE" | "GET" | "HEAD" | "PATCH" | "POST" | "PUT"; | ||
export declare type Endpoint = Parameters & { | ||
method: Method; | ||
url: Url; | ||
}; | ||
export declare type RequestHeaders = { | ||
@@ -89,1 +106,2 @@ /** | ||
}; | ||
export {}; |
@@ -47,3 +47,9 @@ import getUserAgent from 'universal-user-agent'; | ||
if (options.auth) { | ||
requestDefaults.headers.authorization = withAuthorizationPrefix(options.auth); | ||
if (typeof options.auth === "string") { | ||
requestDefaults.headers.authorization = withAuthorizationPrefix(options.auth); | ||
} | ||
else { | ||
// @ts-ignore | ||
hook.wrap("request", options.auth.hook); | ||
} | ||
} | ||
@@ -50,0 +56,0 @@ this.request = request.defaults(requestDefaults); |
{ | ||
"name": "@octokit/core", | ||
"description": "Extendable client for GitHub's REST & GraphQL APIs", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"license": "MIT", | ||
@@ -34,2 +34,3 @@ "files": [ | ||
"devDependencies": { | ||
"@octokit/auth": "^1.1.0", | ||
"@pika/pack": "^0.5.0", | ||
@@ -41,6 +42,9 @@ "@pika/plugin-build-node": "^0.6.0", | ||
"@types/jest": "^24.0.17", | ||
"@types/lolex": "^3.1.1", | ||
"@types/node": "^12.7.1", | ||
"@types/node-fetch": "^2.5.0", | ||
"fetch-mock": "^7.3.9", | ||
"http-proxy-agent": "^2.1.0", | ||
"jest": "^24.8.0", | ||
"lolex": "^4.2.0", | ||
"prettier": "^1.18.2", | ||
@@ -47,0 +51,0 @@ "proxy": "^0.2.4", |
@@ -21,2 +21,6 @@ # core.js | ||
If 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, than `@octokit/core` is a great starting point. | ||
If 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. | ||
## Usage | ||
@@ -87,12 +91,30 @@ | ||
The `auth` option is a string and can be one of | ||
You can set `options.auth` to a token, which will be used to correctly set the `Authorization` header for the requests you do with `octokit.request()` and `octokit.graphql()`. Example | ||
1. A personal access token | ||
1. An OAuth token | ||
1. A GitHub App installation token | ||
1. A GitHub App JSON Web Token | ||
1. A GitHub Action token (`GITHUB_TOKEN` environment variable) | ||
```js | ||
import { Octokit } from "@octokit/core"; | ||
More complex authentication strategies will be supported by passing an [@octokit/auth](https://github.com/octokit/auth.js) instance (🚧 currently work in progress). | ||
const octokit = new Octokit({ | ||
auth: "mypersonalaccesstoken123" | ||
}); | ||
octokit.request("/user").then(response => console.log(response.data)); | ||
``` | ||
All other authentication strategies are supported using [`@octokit/auth`](@octokit/auth-app.js#readme), just pass the `auth()` method returned by any of the strategies as `options.auth`. Example | ||
```js | ||
import { Octokit } from "@octokit/core"; | ||
import { createAppAuth } from "@octokit/auth-app"; | ||
const octokit = new Octokit({ | ||
auth: createAppAuth({ | ||
id: 123, | ||
privateKey: process.env.PRIVATE_KEY | ||
)} | ||
}) | ||
octokit.request('/app').then(response => console.log(response.data)) | ||
``` | ||
## Hooks | ||
@@ -99,0 +121,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
30587
337
185
20