Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@octokit/request

Package Overview
Dependencies
Maintainers
3
Versions
104
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@octokit/request - npm Package Compare versions

Comparing version 5.0.1 to 5.0.2

12

dist-node/index.js

@@ -120,5 +120,11 @@ 'use strict';

return endpointOptions.request.hook(options => {
return fetchWrapper(endpoint.parse(options));
}, endpointOptions);
const request = (route, parameters) => {
return fetchWrapper(endpoint.parse(endpoint.merge(route, parameters)));
};
Object.assign(request, {
endpoint,
defaults: withDefaults.bind(null, endpoint)
});
return endpointOptions.request.hook(request, endpointOptions);
};

@@ -125,0 +131,0 @@

@@ -9,5 +9,10 @@ import fetchWrapper from "./fetch-wrapper";

}
return endpointOptions.request.hook((options) => {
return fetchWrapper(endpoint.parse(options));
}, endpointOptions);
const request = (route, parameters) => {
return fetchWrapper(endpoint.parse(endpoint.merge(route, parameters)));
};
Object.assign(request, {
endpoint,
defaults: withDefaults.bind(null, endpoint)
});
return endpointOptions.request.hook(request, endpointOptions);
};

@@ -14,0 +19,0 @@ return Object.assign(newApi, {

@@ -10,123 +10,118 @@ import { endpoint } from '@octokit/endpoint';

function getBufferResponse(response) {
return response.arrayBuffer();
return response.arrayBuffer();
}
function fetchWrapper(requestOptions) {
if (isPlainObject(requestOptions.body) || Array.isArray(requestOptions.body)) {
requestOptions.body = JSON.stringify(requestOptions.body);
}
let headers = {};
let status;
let url;
const fetch = requestOptions.request && requestOptions.request.fetch || nodeFetch;
return fetch(requestOptions.url, Object.assign({
method: requestOptions.method,
body: requestOptions.body,
headers: requestOptions.headers,
redirect: requestOptions.redirect
}, requestOptions.request)).then(response => {
url = response.url;
status = response.status;
for (const keyAndValue of response.headers) {
headers[keyAndValue[0]] = keyAndValue[1];
if (isPlainObject(requestOptions.body) ||
Array.isArray(requestOptions.body)) {
requestOptions.body = JSON.stringify(requestOptions.body);
}
if (status === 204 || status === 205) {
return;
} // GitHub API returns 200 for HEAD requsets
if (requestOptions.method === "HEAD") {
if (status < 400) {
return;
}
throw new RequestError(response.statusText, status, {
headers,
request: requestOptions
});
}
if (status === 304) {
throw new RequestError("Not modified", status, {
headers,
request: requestOptions
});
}
if (status >= 400) {
return response.text().then(message => {
const error = new RequestError(message, status, {
headers,
request: requestOptions
let headers = {};
let status;
let url;
const fetch = (requestOptions.request && requestOptions.request.fetch) || nodeFetch;
return fetch(requestOptions.url, Object.assign({
method: requestOptions.method,
body: requestOptions.body,
headers: requestOptions.headers,
redirect: requestOptions.redirect
}, requestOptions.request))
.then(response => {
url = response.url;
status = response.status;
for (const keyAndValue of response.headers) {
headers[keyAndValue[0]] = keyAndValue[1];
}
if (status === 204 || status === 205) {
return;
}
// GitHub API returns 200 for HEAD requsets
if (requestOptions.method === "HEAD") {
if (status < 400) {
return;
}
throw new RequestError(response.statusText, status, {
headers,
request: requestOptions
});
}
if (status === 304) {
throw new RequestError("Not modified", status, {
headers,
request: requestOptions
});
}
if (status >= 400) {
return response
.text()
.then(message => {
const error = new RequestError(message, status, {
headers,
request: requestOptions
});
try {
Object.assign(error, JSON.parse(error.message));
}
catch (e) {
// ignore, see octokit/rest.js#684
}
throw error;
});
}
const contentType = response.headers.get("content-type");
if (/application\/json/.test(contentType)) {
return response.json();
}
if (!contentType || /^text\/|charset=utf-8$/.test(contentType)) {
return response.text();
}
return getBufferResponse(response);
})
.then(data => {
return {
status,
url,
headers,
data
};
})
.catch(error => {
if (error instanceof RequestError) {
throw error;
}
throw new RequestError(error.message, 500, {
headers,
request: requestOptions
});
});
}
try {
Object.assign(error, JSON.parse(error.message));
} catch (e) {// ignore, see octokit/rest.js#684
function withDefaults(oldEndpoint, newDefaults) {
const endpoint = oldEndpoint.defaults(newDefaults);
const newApi = function (route, parameters) {
const endpointOptions = endpoint.merge(route, parameters);
if (!endpointOptions.request || !endpointOptions.request.hook) {
return fetchWrapper(endpoint.parse(endpointOptions));
}
throw error;
});
}
const contentType = response.headers.get("content-type");
if (/application\/json/.test(contentType)) {
return response.json();
}
if (!contentType || /^text\/|charset=utf-8$/.test(contentType)) {
return response.text();
}
return getBufferResponse(response);
}).then(data => {
return {
status,
url,
headers,
data
const request = (route, parameters) => {
return fetchWrapper(endpoint.parse(endpoint.merge(route, parameters)));
};
Object.assign(request, {
endpoint,
defaults: withDefaults.bind(null, endpoint)
});
return endpointOptions.request.hook(request, endpointOptions);
};
}).catch(error => {
if (error instanceof RequestError) {
throw error;
}
throw new RequestError(error.message, 500, {
headers,
request: requestOptions
return Object.assign(newApi, {
endpoint,
defaults: withDefaults.bind(null, endpoint)
});
});
}
function withDefaults(oldEndpoint, newDefaults) {
const endpoint = oldEndpoint.defaults(newDefaults);
const newApi = function newApi(route, parameters) {
const endpointOptions = endpoint.merge(route, parameters);
if (!endpointOptions.request || !endpointOptions.request.hook) {
return fetchWrapper(endpoint.parse(endpointOptions));
const request = withDefaults(endpoint, {
headers: {
"user-agent": `octokit-request.js/${VERSION} ${getUserAgent()}`
}
return endpointOptions.request.hook(options => {
return fetchWrapper(endpoint.parse(options));
}, endpointOptions);
};
return Object.assign(newApi, {
endpoint,
defaults: withDefaults.bind(null, endpoint)
});
}
const request = withDefaults(endpoint, {
headers: {
"user-agent": "octokit-request.js/".concat(VERSION, " ").concat(getUserAgent())
}
});
export { request };
{
"name": "@octokit/request",
"description": "Send parameterized requests to GitHub’s APIs with sensible defaults in browsers and Node",
"version": "5.0.1",
"version": "5.0.2",
"license": "MIT",

@@ -37,5 +37,5 @@ "files": [

"@pika/pack": "^0.4.0",
"@pika/plugin-build-node": "^0.4.0",
"@pika/plugin-build-web": "^0.4.0",
"@pika/plugin-ts-standard-pkg": "^0.4.0",
"@pika/plugin-build-node": "^0.5.1",
"@pika/plugin-build-web": "^0.5.1",
"@pika/plugin-ts-standard-pkg": "^0.5.1",
"@types/fetch-mock": "^7.2.4",

@@ -42,0 +42,0 @@ "@types/jest": "^24.0.12",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc