@octokit/core
Advanced tools
Comparing version 4.2.0 to 4.2.1
@@ -1,18 +0,78 @@ | ||
'use strict'; | ||
"use strict"; | ||
var __defProp = Object.defineProperty; | ||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
var __getOwnPropNames = Object.getOwnPropertyNames; | ||
var __hasOwnProp = Object.prototype.hasOwnProperty; | ||
var __export = (target, all) => { | ||
for (var name in all) | ||
__defProp(target, name, { get: all[name], enumerable: true }); | ||
}; | ||
var __copyProps = (to, from, except, desc) => { | ||
if (from && typeof from === "object" || typeof from === "function") { | ||
for (let key of __getOwnPropNames(from)) | ||
if (!__hasOwnProp.call(to, key) && key !== except) | ||
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); | ||
} | ||
return to; | ||
}; | ||
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
// pkg/dist-src/index.js | ||
var dist_src_exports = {}; | ||
__export(dist_src_exports, { | ||
Octokit: () => Octokit | ||
}); | ||
module.exports = __toCommonJS(dist_src_exports); | ||
var import_universal_user_agent = require("universal-user-agent"); | ||
var import_before_after_hook = require("before-after-hook"); | ||
var import_request = require("@octokit/request"); | ||
var import_graphql = require("@octokit/graphql"); | ||
var import_auth_token = require("@octokit/auth-token"); | ||
var universalUserAgent = require('universal-user-agent'); | ||
var beforeAfterHook = require('before-after-hook'); | ||
var request = require('@octokit/request'); | ||
var graphql = require('@octokit/graphql'); | ||
var authToken = require('@octokit/auth-token'); | ||
// pkg/dist-src/version.js | ||
var VERSION = "4.2.1"; | ||
const VERSION = "4.2.0"; | ||
class Octokit { | ||
// pkg/dist-src/index.js | ||
var Octokit = class { | ||
static defaults(defaults) { | ||
const OctokitWithDefaults = class extends this { | ||
constructor(...args) { | ||
const options = args[0] || {}; | ||
if (typeof defaults === "function") { | ||
super(defaults(options)); | ||
return; | ||
} | ||
super( | ||
Object.assign( | ||
{}, | ||
defaults, | ||
options, | ||
options.userAgent && defaults.userAgent ? { | ||
userAgent: `${options.userAgent} ${defaults.userAgent}` | ||
} : null | ||
) | ||
); | ||
} | ||
}; | ||
return OctokitWithDefaults; | ||
} | ||
/** | ||
* Attach a plugin (or many) to your Octokit instance. | ||
* | ||
* @example | ||
* const API = Octokit.plugin(plugin1, plugin2, plugin3, ...) | ||
*/ | ||
static plugin(...newPlugins) { | ||
var _a; | ||
const currentPlugins = this.plugins; | ||
const NewOctokit = (_a = class extends this { | ||
}, _a.plugins = currentPlugins.concat( | ||
newPlugins.filter((plugin) => !currentPlugins.includes(plugin)) | ||
), _a); | ||
return NewOctokit; | ||
} | ||
constructor(options = {}) { | ||
const hook = new beforeAfterHook.Collection(); | ||
const hook = new import_before_after_hook.Collection(); | ||
const requestDefaults = { | ||
baseUrl: request.request.endpoint.DEFAULTS.baseUrl, | ||
baseUrl: import_request.request.endpoint.DEFAULTS.baseUrl, | ||
headers: {}, | ||
@@ -27,35 +87,32 @@ request: Object.assign({}, options.request, { | ||
} | ||
}; // prepend default user agent with `options.userAgent` if set | ||
requestDefaults.headers["user-agent"] = [options.userAgent, `octokit-core.js/${VERSION} ${universalUserAgent.getUserAgent()}`].filter(Boolean).join(" "); | ||
}; | ||
requestDefaults.headers["user-agent"] = [ | ||
options.userAgent, | ||
`octokit-core.js/${VERSION} ${(0, import_universal_user_agent.getUserAgent)()}` | ||
].filter(Boolean).join(" "); | ||
if (options.baseUrl) { | ||
requestDefaults.baseUrl = options.baseUrl; | ||
} | ||
if (options.previews) { | ||
requestDefaults.mediaType.previews = options.previews; | ||
} | ||
if (options.timeZone) { | ||
requestDefaults.headers["time-zone"] = options.timeZone; | ||
} | ||
this.request = request.request.defaults(requestDefaults); | ||
this.graphql = graphql.withCustomRequest(this.request).defaults(requestDefaults); | ||
this.log = Object.assign({ | ||
debug: () => {}, | ||
info: () => {}, | ||
warn: console.warn.bind(console), | ||
error: console.error.bind(console) | ||
}, options.log); | ||
this.hook = hook; // (1) If neither `options.authStrategy` nor `options.auth` are set, the `octokit` instance | ||
// is unauthenticated. The `this.auth()` method is a no-op and no request hook is registered. | ||
// (2) If only `options.auth` is set, use the default token authentication strategy. | ||
// (3) If `options.authStrategy` is set then use it and pass in `options.auth`. Always pass own request as many strategies accept a custom request instance. | ||
// TODO: type `options.auth` based on `options.authStrategy`. | ||
this.request = import_request.request.defaults(requestDefaults); | ||
this.graphql = (0, import_graphql.withCustomRequest)(this.request).defaults(requestDefaults); | ||
this.log = Object.assign( | ||
{ | ||
debug: () => { | ||
}, | ||
info: () => { | ||
}, | ||
warn: console.warn.bind(console), | ||
error: console.error.bind(console) | ||
}, | ||
options.log | ||
); | ||
this.hook = hook; | ||
if (!options.authStrategy) { | ||
if (!options.auth) { | ||
// (1) | ||
this.auth = async () => ({ | ||
@@ -65,5 +122,3 @@ type: "unauthenticated" | ||
} else { | ||
// (2) | ||
const auth = authToken.createTokenAuth(options.auth); // @ts-ignore ¯\_(ツ)_/¯ | ||
const auth = (0, import_auth_token.createTokenAuth)(options.auth); | ||
hook.wrap("request", auth.hook); | ||
@@ -73,69 +128,33 @@ this.auth = auth; | ||
} else { | ||
const { | ||
authStrategy, | ||
...otherOptions | ||
} = options; | ||
const auth = authStrategy(Object.assign({ | ||
request: this.request, | ||
log: this.log, | ||
// we pass the current octokit instance as well as its constructor options | ||
// to allow for authentication strategies that return a new octokit instance | ||
// that shares the same internal state as the current one. The original | ||
// requirement for this was the "event-octokit" authentication strategy | ||
// of https://github.com/probot/octokit-auth-probot. | ||
octokit: this, | ||
octokitOptions: otherOptions | ||
}, options.auth)); // @ts-ignore ¯\_(ツ)_/¯ | ||
const { authStrategy, ...otherOptions } = options; | ||
const auth = authStrategy( | ||
Object.assign( | ||
{ | ||
request: this.request, | ||
log: this.log, | ||
// we pass the current octokit instance as well as its constructor options | ||
// to allow for authentication strategies that return a new octokit instance | ||
// that shares the same internal state as the current one. The original | ||
// requirement for this was the "event-octokit" authentication strategy | ||
// of https://github.com/probot/octokit-auth-probot. | ||
octokit: this, | ||
octokitOptions: otherOptions | ||
}, | ||
options.auth | ||
) | ||
); | ||
hook.wrap("request", auth.hook); | ||
this.auth = auth; | ||
} // apply plugins | ||
// https://stackoverflow.com/a/16345172 | ||
} | ||
const classConstructor = this.constructor; | ||
classConstructor.plugins.forEach(plugin => { | ||
classConstructor.plugins.forEach((plugin) => { | ||
Object.assign(this, plugin(this, options)); | ||
}); | ||
} | ||
static defaults(defaults) { | ||
const OctokitWithDefaults = class extends this { | ||
constructor(...args) { | ||
const options = args[0] || {}; | ||
if (typeof defaults === "function") { | ||
super(defaults(options)); | ||
return; | ||
} | ||
super(Object.assign({}, defaults, options, options.userAgent && defaults.userAgent ? { | ||
userAgent: `${options.userAgent} ${defaults.userAgent}` | ||
} : null)); | ||
} | ||
}; | ||
return OctokitWithDefaults; | ||
} | ||
/** | ||
* Attach a plugin (or many) to your Octokit instance. | ||
* | ||
* @example | ||
* const API = Octokit.plugin(plugin1, plugin2, plugin3, ...) | ||
*/ | ||
static plugin(...newPlugins) { | ||
var _a; | ||
const currentPlugins = this.plugins; | ||
const NewOctokit = (_a = class extends this {}, _a.plugins = currentPlugins.concat(newPlugins.filter(plugin => !currentPlugins.includes(plugin))), _a); | ||
return NewOctokit; | ||
} | ||
} | ||
}; | ||
Octokit.VERSION = VERSION; | ||
Octokit.plugins = []; | ||
exports.Octokit = Octokit; | ||
//# sourceMappingURL=index.js.map | ||
// Annotate the CommonJS export names for ESM import in node: | ||
0 && (module.exports = { | ||
Octokit | ||
}); |
@@ -7,120 +7,122 @@ import { getUserAgent } from "universal-user-agent"; | ||
import { VERSION } from "./version"; | ||
export class Octokit { | ||
constructor(options = {}) { | ||
const hook = new Collection(); | ||
const requestDefaults = { | ||
baseUrl: request.endpoint.DEFAULTS.baseUrl, | ||
headers: {}, | ||
request: Object.assign({}, options.request, { | ||
// @ts-ignore internal usage only, no need to type | ||
hook: hook.bind(null, "request"), | ||
}), | ||
mediaType: { | ||
previews: [], | ||
format: "", | ||
}, | ||
}; | ||
// prepend default user agent with `options.userAgent` if set | ||
requestDefaults.headers["user-agent"] = [ | ||
options.userAgent, | ||
`octokit-core.js/${VERSION} ${getUserAgent()}`, | ||
] | ||
.filter(Boolean) | ||
.join(" "); | ||
if (options.baseUrl) { | ||
requestDefaults.baseUrl = options.baseUrl; | ||
class Octokit { | ||
static defaults(defaults) { | ||
const OctokitWithDefaults = class extends this { | ||
constructor(...args) { | ||
const options = args[0] || {}; | ||
if (typeof defaults === "function") { | ||
super(defaults(options)); | ||
return; | ||
} | ||
if (options.previews) { | ||
requestDefaults.mediaType.previews = options.previews; | ||
} | ||
if (options.timeZone) { | ||
requestDefaults.headers["time-zone"] = options.timeZone; | ||
} | ||
this.request = request.defaults(requestDefaults); | ||
this.graphql = withCustomRequest(this.request).defaults(requestDefaults); | ||
this.log = Object.assign({ | ||
debug: () => { }, | ||
info: () => { }, | ||
warn: console.warn.bind(console), | ||
error: console.error.bind(console), | ||
}, options.log); | ||
this.hook = hook; | ||
// (1) If neither `options.authStrategy` nor `options.auth` are set, the `octokit` instance | ||
// is unauthenticated. The `this.auth()` method is a no-op and no request hook is registered. | ||
// (2) If only `options.auth` is set, use the default token authentication strategy. | ||
// (3) If `options.authStrategy` is set then use it and pass in `options.auth`. Always pass own request as many strategies accept a custom request instance. | ||
// TODO: type `options.auth` based on `options.authStrategy`. | ||
if (!options.authStrategy) { | ||
if (!options.auth) { | ||
// (1) | ||
this.auth = async () => ({ | ||
type: "unauthenticated", | ||
}); | ||
} | ||
else { | ||
// (2) | ||
const auth = createTokenAuth(options.auth); | ||
// @ts-ignore ¯\_(ツ)_/¯ | ||
hook.wrap("request", auth.hook); | ||
this.auth = auth; | ||
} | ||
} | ||
else { | ||
const { authStrategy, ...otherOptions } = options; | ||
const auth = authStrategy(Object.assign({ | ||
request: this.request, | ||
log: this.log, | ||
// we pass the current octokit instance as well as its constructor options | ||
// to allow for authentication strategies that return a new octokit instance | ||
// that shares the same internal state as the current one. The original | ||
// requirement for this was the "event-octokit" authentication strategy | ||
// of https://github.com/probot/octokit-auth-probot. | ||
octokit: this, | ||
octokitOptions: otherOptions, | ||
}, options.auth)); | ||
// @ts-ignore ¯\_(ツ)_/¯ | ||
hook.wrap("request", auth.hook); | ||
this.auth = auth; | ||
} | ||
// apply plugins | ||
// https://stackoverflow.com/a/16345172 | ||
const classConstructor = this.constructor; | ||
classConstructor.plugins.forEach((plugin) => { | ||
Object.assign(this, plugin(this, options)); | ||
}); | ||
super( | ||
Object.assign( | ||
{}, | ||
defaults, | ||
options, | ||
options.userAgent && defaults.userAgent ? { | ||
userAgent: `${options.userAgent} ${defaults.userAgent}` | ||
} : null | ||
) | ||
); | ||
} | ||
}; | ||
return OctokitWithDefaults; | ||
} | ||
/** | ||
* Attach a plugin (or many) to your Octokit instance. | ||
* | ||
* @example | ||
* const API = Octokit.plugin(plugin1, plugin2, plugin3, ...) | ||
*/ | ||
static plugin(...newPlugins) { | ||
var _a; | ||
const currentPlugins = this.plugins; | ||
const NewOctokit = (_a = class extends this { | ||
}, _a.plugins = currentPlugins.concat( | ||
newPlugins.filter((plugin) => !currentPlugins.includes(plugin)) | ||
), _a); | ||
return NewOctokit; | ||
} | ||
constructor(options = {}) { | ||
const hook = new Collection(); | ||
const requestDefaults = { | ||
baseUrl: request.endpoint.DEFAULTS.baseUrl, | ||
headers: {}, | ||
request: Object.assign({}, options.request, { | ||
// @ts-ignore internal usage only, no need to type | ||
hook: hook.bind(null, "request") | ||
}), | ||
mediaType: { | ||
previews: [], | ||
format: "" | ||
} | ||
}; | ||
requestDefaults.headers["user-agent"] = [ | ||
options.userAgent, | ||
`octokit-core.js/${VERSION} ${getUserAgent()}` | ||
].filter(Boolean).join(" "); | ||
if (options.baseUrl) { | ||
requestDefaults.baseUrl = options.baseUrl; | ||
} | ||
static defaults(defaults) { | ||
const OctokitWithDefaults = class extends this { | ||
constructor(...args) { | ||
const options = args[0] || {}; | ||
if (typeof defaults === "function") { | ||
super(defaults(options)); | ||
return; | ||
} | ||
super(Object.assign({}, defaults, options, options.userAgent && defaults.userAgent | ||
? { | ||
userAgent: `${options.userAgent} ${defaults.userAgent}`, | ||
} | ||
: null)); | ||
} | ||
}; | ||
return OctokitWithDefaults; | ||
if (options.previews) { | ||
requestDefaults.mediaType.previews = options.previews; | ||
} | ||
/** | ||
* Attach a plugin (or many) to your Octokit instance. | ||
* | ||
* @example | ||
* const API = Octokit.plugin(plugin1, plugin2, plugin3, ...) | ||
*/ | ||
static plugin(...newPlugins) { | ||
var _a; | ||
const currentPlugins = this.plugins; | ||
const NewOctokit = (_a = class extends this { | ||
}, | ||
_a.plugins = currentPlugins.concat(newPlugins.filter((plugin) => !currentPlugins.includes(plugin))), | ||
_a); | ||
return NewOctokit; | ||
if (options.timeZone) { | ||
requestDefaults.headers["time-zone"] = options.timeZone; | ||
} | ||
this.request = request.defaults(requestDefaults); | ||
this.graphql = withCustomRequest(this.request).defaults(requestDefaults); | ||
this.log = Object.assign( | ||
{ | ||
debug: () => { | ||
}, | ||
info: () => { | ||
}, | ||
warn: console.warn.bind(console), | ||
error: console.error.bind(console) | ||
}, | ||
options.log | ||
); | ||
this.hook = hook; | ||
if (!options.authStrategy) { | ||
if (!options.auth) { | ||
this.auth = async () => ({ | ||
type: "unauthenticated" | ||
}); | ||
} else { | ||
const auth = createTokenAuth(options.auth); | ||
hook.wrap("request", auth.hook); | ||
this.auth = auth; | ||
} | ||
} else { | ||
const { authStrategy, ...otherOptions } = options; | ||
const auth = authStrategy( | ||
Object.assign( | ||
{ | ||
request: this.request, | ||
log: this.log, | ||
// we pass the current octokit instance as well as its constructor options | ||
// to allow for authentication strategies that return a new octokit instance | ||
// that shares the same internal state as the current one. The original | ||
// requirement for this was the "event-octokit" authentication strategy | ||
// of https://github.com/probot/octokit-auth-probot. | ||
octokit: this, | ||
octokitOptions: otherOptions | ||
}, | ||
options.auth | ||
) | ||
); | ||
hook.wrap("request", auth.hook); | ||
this.auth = auth; | ||
} | ||
const classConstructor = this.constructor; | ||
classConstructor.plugins.forEach((plugin) => { | ||
Object.assign(this, plugin(this, options)); | ||
}); | ||
} | ||
} | ||
Octokit.VERSION = VERSION; | ||
Octokit.plugins = []; | ||
export { | ||
Octokit | ||
}; |
@@ -1,1 +0,4 @@ | ||
export const VERSION = "4.2.0"; | ||
const VERSION = "4.2.1"; | ||
export { | ||
VERSION | ||
}; |
import * as OctokitTypes from "@octokit/types"; | ||
import { RequestError } from "@octokit/request-error"; | ||
import { Octokit } from "."; | ||
export declare type RequestParameters = OctokitTypes.RequestParameters; | ||
export type RequestParameters = OctokitTypes.RequestParameters; | ||
export interface OctokitOptions { | ||
@@ -21,4 +21,4 @@ authStrategy?: any; | ||
} | ||
export declare type Constructor<T> = new (...args: any[]) => T; | ||
export declare type ReturnTypeOf<T extends AnyFunction | AnyFunction[]> = T extends AnyFunction ? ReturnType<T> : T extends AnyFunction[] ? UnionToIntersection<Exclude<ReturnType<T[number]>, void>> : never; | ||
export type Constructor<T> = new (...args: any[]) => T; | ||
export type ReturnTypeOf<T extends AnyFunction | AnyFunction[]> = T extends AnyFunction ? ReturnType<T> : T extends AnyFunction[] ? UnionToIntersection<Exclude<ReturnType<T[number]>, void>> : never; | ||
/** | ||
@@ -28,8 +28,8 @@ * @author https://stackoverflow.com/users/2887218/jcalz | ||
*/ | ||
export declare type UnionToIntersection<Union> = (Union extends any ? (argument: Union) => void : never) extends (argument: infer Intersection) => void ? Intersection : never; | ||
declare type AnyFunction = (...args: any) => any; | ||
export declare type OctokitPlugin = (octokit: Octokit, options: OctokitOptions) => { | ||
export type UnionToIntersection<Union> = (Union extends any ? (argument: Union) => void : never) extends (argument: infer Intersection) => void ? Intersection : never; | ||
type AnyFunction = (...args: any) => any; | ||
export type OctokitPlugin = (octokit: Octokit, options: OctokitOptions) => { | ||
[key: string]: any; | ||
} | void; | ||
export declare type Hooks = { | ||
export type Hooks = { | ||
request: { | ||
@@ -36,0 +36,0 @@ Options: Required<OctokitTypes.EndpointDefaults>; |
@@ -1,1 +0,1 @@ | ||
export declare const VERSION = "4.2.0"; | ||
export declare const VERSION = "4.2.1"; |
@@ -1,130 +0,132 @@ | ||
import { getUserAgent } from 'universal-user-agent'; | ||
import { Collection } from 'before-after-hook'; | ||
import { request } from '@octokit/request'; | ||
import { withCustomRequest } from '@octokit/graphql'; | ||
import { createTokenAuth } from '@octokit/auth-token'; | ||
// pkg/dist-src/index.js | ||
import { getUserAgent } from "universal-user-agent"; | ||
import { Collection } from "before-after-hook"; | ||
import { request } from "@octokit/request"; | ||
import { withCustomRequest } from "@octokit/graphql"; | ||
import { createTokenAuth } from "@octokit/auth-token"; | ||
const VERSION = "4.2.0"; | ||
// pkg/dist-src/version.js | ||
var VERSION = "4.2.1"; | ||
class Octokit { | ||
constructor(options = {}) { | ||
const hook = new Collection(); | ||
const requestDefaults = { | ||
baseUrl: request.endpoint.DEFAULTS.baseUrl, | ||
headers: {}, | ||
request: Object.assign({}, options.request, { | ||
// @ts-ignore internal usage only, no need to type | ||
hook: hook.bind(null, "request"), | ||
}), | ||
mediaType: { | ||
previews: [], | ||
format: "", | ||
}, | ||
}; | ||
// prepend default user agent with `options.userAgent` if set | ||
requestDefaults.headers["user-agent"] = [ | ||
options.userAgent, | ||
`octokit-core.js/${VERSION} ${getUserAgent()}`, | ||
] | ||
.filter(Boolean) | ||
.join(" "); | ||
if (options.baseUrl) { | ||
requestDefaults.baseUrl = options.baseUrl; | ||
// pkg/dist-src/index.js | ||
var Octokit = class { | ||
static defaults(defaults) { | ||
const OctokitWithDefaults = class extends this { | ||
constructor(...args) { | ||
const options = args[0] || {}; | ||
if (typeof defaults === "function") { | ||
super(defaults(options)); | ||
return; | ||
} | ||
if (options.previews) { | ||
requestDefaults.mediaType.previews = options.previews; | ||
} | ||
if (options.timeZone) { | ||
requestDefaults.headers["time-zone"] = options.timeZone; | ||
} | ||
this.request = request.defaults(requestDefaults); | ||
this.graphql = withCustomRequest(this.request).defaults(requestDefaults); | ||
this.log = Object.assign({ | ||
debug: () => { }, | ||
info: () => { }, | ||
warn: console.warn.bind(console), | ||
error: console.error.bind(console), | ||
}, options.log); | ||
this.hook = hook; | ||
// (1) If neither `options.authStrategy` nor `options.auth` are set, the `octokit` instance | ||
// is unauthenticated. The `this.auth()` method is a no-op and no request hook is registered. | ||
// (2) If only `options.auth` is set, use the default token authentication strategy. | ||
// (3) If `options.authStrategy` is set then use it and pass in `options.auth`. Always pass own request as many strategies accept a custom request instance. | ||
// TODO: type `options.auth` based on `options.authStrategy`. | ||
if (!options.authStrategy) { | ||
if (!options.auth) { | ||
// (1) | ||
this.auth = async () => ({ | ||
type: "unauthenticated", | ||
}); | ||
} | ||
else { | ||
// (2) | ||
const auth = createTokenAuth(options.auth); | ||
// @ts-ignore ¯\_(ツ)_/¯ | ||
hook.wrap("request", auth.hook); | ||
this.auth = auth; | ||
} | ||
} | ||
else { | ||
const { authStrategy, ...otherOptions } = options; | ||
const auth = authStrategy(Object.assign({ | ||
request: this.request, | ||
log: this.log, | ||
// we pass the current octokit instance as well as its constructor options | ||
// to allow for authentication strategies that return a new octokit instance | ||
// that shares the same internal state as the current one. The original | ||
// requirement for this was the "event-octokit" authentication strategy | ||
// of https://github.com/probot/octokit-auth-probot. | ||
octokit: this, | ||
octokitOptions: otherOptions, | ||
}, options.auth)); | ||
// @ts-ignore ¯\_(ツ)_/¯ | ||
hook.wrap("request", auth.hook); | ||
this.auth = auth; | ||
} | ||
// apply plugins | ||
// https://stackoverflow.com/a/16345172 | ||
const classConstructor = this.constructor; | ||
classConstructor.plugins.forEach((plugin) => { | ||
Object.assign(this, plugin(this, options)); | ||
}); | ||
super( | ||
Object.assign( | ||
{}, | ||
defaults, | ||
options, | ||
options.userAgent && defaults.userAgent ? { | ||
userAgent: `${options.userAgent} ${defaults.userAgent}` | ||
} : null | ||
) | ||
); | ||
} | ||
}; | ||
return OctokitWithDefaults; | ||
} | ||
/** | ||
* Attach a plugin (or many) to your Octokit instance. | ||
* | ||
* @example | ||
* const API = Octokit.plugin(plugin1, plugin2, plugin3, ...) | ||
*/ | ||
static plugin(...newPlugins) { | ||
var _a; | ||
const currentPlugins = this.plugins; | ||
const NewOctokit = (_a = class extends this { | ||
}, _a.plugins = currentPlugins.concat( | ||
newPlugins.filter((plugin) => !currentPlugins.includes(plugin)) | ||
), _a); | ||
return NewOctokit; | ||
} | ||
constructor(options = {}) { | ||
const hook = new Collection(); | ||
const requestDefaults = { | ||
baseUrl: request.endpoint.DEFAULTS.baseUrl, | ||
headers: {}, | ||
request: Object.assign({}, options.request, { | ||
// @ts-ignore internal usage only, no need to type | ||
hook: hook.bind(null, "request") | ||
}), | ||
mediaType: { | ||
previews: [], | ||
format: "" | ||
} | ||
}; | ||
requestDefaults.headers["user-agent"] = [ | ||
options.userAgent, | ||
`octokit-core.js/${VERSION} ${getUserAgent()}` | ||
].filter(Boolean).join(" "); | ||
if (options.baseUrl) { | ||
requestDefaults.baseUrl = options.baseUrl; | ||
} | ||
static defaults(defaults) { | ||
const OctokitWithDefaults = class extends this { | ||
constructor(...args) { | ||
const options = args[0] || {}; | ||
if (typeof defaults === "function") { | ||
super(defaults(options)); | ||
return; | ||
} | ||
super(Object.assign({}, defaults, options, options.userAgent && defaults.userAgent | ||
? { | ||
userAgent: `${options.userAgent} ${defaults.userAgent}`, | ||
} | ||
: null)); | ||
} | ||
}; | ||
return OctokitWithDefaults; | ||
if (options.previews) { | ||
requestDefaults.mediaType.previews = options.previews; | ||
} | ||
/** | ||
* Attach a plugin (or many) to your Octokit instance. | ||
* | ||
* @example | ||
* const API = Octokit.plugin(plugin1, plugin2, plugin3, ...) | ||
*/ | ||
static plugin(...newPlugins) { | ||
var _a; | ||
const currentPlugins = this.plugins; | ||
const NewOctokit = (_a = class extends this { | ||
}, | ||
_a.plugins = currentPlugins.concat(newPlugins.filter((plugin) => !currentPlugins.includes(plugin))), | ||
_a); | ||
return NewOctokit; | ||
if (options.timeZone) { | ||
requestDefaults.headers["time-zone"] = options.timeZone; | ||
} | ||
} | ||
this.request = request.defaults(requestDefaults); | ||
this.graphql = withCustomRequest(this.request).defaults(requestDefaults); | ||
this.log = Object.assign( | ||
{ | ||
debug: () => { | ||
}, | ||
info: () => { | ||
}, | ||
warn: console.warn.bind(console), | ||
error: console.error.bind(console) | ||
}, | ||
options.log | ||
); | ||
this.hook = hook; | ||
if (!options.authStrategy) { | ||
if (!options.auth) { | ||
this.auth = async () => ({ | ||
type: "unauthenticated" | ||
}); | ||
} else { | ||
const auth = createTokenAuth(options.auth); | ||
hook.wrap("request", auth.hook); | ||
this.auth = auth; | ||
} | ||
} else { | ||
const { authStrategy, ...otherOptions } = options; | ||
const auth = authStrategy( | ||
Object.assign( | ||
{ | ||
request: this.request, | ||
log: this.log, | ||
// we pass the current octokit instance as well as its constructor options | ||
// to allow for authentication strategies that return a new octokit instance | ||
// that shares the same internal state as the current one. The original | ||
// requirement for this was the "event-octokit" authentication strategy | ||
// of https://github.com/probot/octokit-auth-probot. | ||
octokit: this, | ||
octokitOptions: otherOptions | ||
}, | ||
options.auth | ||
) | ||
); | ||
hook.wrap("request", auth.hook); | ||
this.auth = auth; | ||
} | ||
const classConstructor = this.constructor; | ||
classConstructor.plugins.forEach((plugin) => { | ||
Object.assign(this, plugin(this, options)); | ||
}); | ||
} | ||
}; | ||
Octokit.VERSION = VERSION; | ||
Octokit.plugins = []; | ||
export { Octokit }; | ||
//# sourceMappingURL=index.js.map | ||
export { | ||
Octokit | ||
}; |
{ | ||
"name": "@octokit/core", | ||
"version": "4.2.1", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"description": "Extendable client for GitHub's REST & GraphQL APIs", | ||
"version": "4.2.0", | ||
"license": "MIT", | ||
"files": [ | ||
"dist-*/", | ||
"bin/" | ||
], | ||
"source": "dist-src/index.js", | ||
"types": "dist-types/index.d.ts", | ||
"main": "dist-node/index.js", | ||
"module": "dist-web/index.js", | ||
"pika": true, | ||
"sideEffects": false, | ||
"repository": "github:octokit/core.js", | ||
"keywords": [ | ||
@@ -23,3 +16,4 @@ "octokit", | ||
], | ||
"repository": "github:octokit/core.js", | ||
"author": "Gregor Martynus (https://github.com/gr2m)", | ||
"license": "MIT", | ||
"dependencies": { | ||
@@ -36,6 +30,3 @@ "@octokit/auth-token": "^3.0.0", | ||
"@octokit/auth": "^3.0.1", | ||
"@pika/pack": "^0.3.7", | ||
"@pika/plugin-build-node": "^0.9.0", | ||
"@pika/plugin-build-web": "^0.9.0", | ||
"@pika/plugin-ts-standard-pkg": "^0.9.0", | ||
"@octokit/tsconfig": "^1.0.2", | ||
"@types/fetch-mock": "^7.3.1", | ||
@@ -45,12 +36,14 @@ "@types/jest": "^29.0.0", | ||
"@types/node": "^18.0.0", | ||
"esbuild": "^0.17.19", | ||
"fetch-mock": "^9.0.0", | ||
"http-proxy-agent": "^5.0.0", | ||
"glob": "^10.2.5", | ||
"http-proxy-agent": "^6.0.0", | ||
"jest": "^29.0.0", | ||
"lolex": "^6.0.0", | ||
"prettier": "2.8.3", | ||
"proxy": "^1.0.1", | ||
"semantic-release": "^20.0.0", | ||
"prettier": "2.8.8", | ||
"proxy": "^2.0.0", | ||
"semantic-release": "^21.0.0", | ||
"semantic-release-plugin-update-version-in-files": "^1.0.0", | ||
"ts-jest": "^29.0.0", | ||
"typescript": "^4.0.2" | ||
"typescript": "^5.0.0" | ||
}, | ||
@@ -60,5 +53,11 @@ "engines": { | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
} | ||
"files": [ | ||
"dist-*/**", | ||
"bin/**" | ||
], | ||
"main": "dist-node/index.js", | ||
"module": "dist-web/index.js", | ||
"types": "dist-types/index.d.ts", | ||
"source": "dist-src/index.js", | ||
"sideEffects": false | ||
} |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
No contributors or author data
MaintenancePackage does not specify a list of contributors or an author in package.json.
Found 1 instance in 1 package
18
490
1
43707
12
1