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

@cloudflare/util-http

Package Overview
Dependencies
Maintainers
26
Versions
47
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cloudflare/util-http - npm Package Compare versions

Comparing version 1.0.11 to 1.0.12

12

CHANGELOG.md

@@ -6,3 +6,11 @@ # Change Log

<a name="1.0.11"></a>
<a name="1.0.12"></a>
## [1.0.12](http://stash.cfops.it:7999/fe/stratus/compare/@cloudflare/util-http@1.0.11...@cloudflare/util-http@1.0.12) (2018-09-21)
**Note:** Version bump only for package @cloudflare/util-http
<a name="1.0.11"></a>
## [1.0.11](http://stash.cfops.it:7999/fe/stratus/compare/@cloudflare/util-http@1.0.10...@cloudflare/util-http@1.0.11) (2018-08-24)

@@ -18,3 +26,3 @@

<a name="1.0.10"></a>
<a name="1.0.10"></a>
## [1.0.10](http://stash.cfops.it:7999/fe/stratus/compare/@cloudflare/util-http@1.0.9...@cloudflare/util-http@1.0.10) (2018-07-25)

@@ -21,0 +29,0 @@

173

es/http.js

@@ -0,8 +1,18 @@

function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
function _iterableToArrayLimit(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
import 'isomorphic-fetch';
import createLogger from '@cloudflare/util-logger';
const logRequest = createLogger('http:request');
const logError = createLogger('http:error');
const logSuccess = createLogger('http:success');
var logRequest = createLogger('http:request');
var logError = createLogger('http:error');
var logSuccess = createLogger('http:success');
// Store beforeSend callbacks.
let beforeSendCallbacks = [];
var beforeSendCallbacks = [];
/**

@@ -33,10 +43,33 @@ * Modify request options before they are sent.

function toQueryParams(kvs) {
const queryParams = []; // Clones the input
var queryParams = []; // Clones the input
if (Array.isArray(kvs) || kvs instanceof Map) {
for (let [k, v] of kvs) {
queryParams.push([k, v]);
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = kvs[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var _step$value = _slicedToArray(_step.value, 2),
k = _step$value[0],
v = _step$value[1];
queryParams.push([k, v]);
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return != null) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
} else {
for (let k in kvs) {
for (var k in kvs) {
if (kvs.hasOwnProperty(k)) {

@@ -48,11 +81,17 @@ queryParams.push([k, kvs[k]]);

return queryParams.map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(v)}`).join('&');
return queryParams.map(function (_ref) {
var _ref2 = _slicedToArray(_ref, 2),
k = _ref2[0],
v = _ref2[1];
return "".concat(encodeURIComponent(k), "=").concat(encodeURIComponent(v));
}).join('&');
}
function toHash(headers) {
const hash = Object.create(null);
var hash = Object.create(null);
if (headers._headers) {
Object.keys(headers._headers).forEach(key => {
const value = Array.isArray(headers._headers[key]) ? headers._headers[key][0] : headers._headers[key];
Object.keys(headers._headers).forEach(function (key) {
var value = Array.isArray(headers._headers[key]) ? headers._headers[key][0] : headers._headers[key];
hash[key] = value;

@@ -63,7 +102,29 @@ hash[key.toLowerCase()] = value;

// converting to Map allows for .. of in Edge
const headersMap = new Map(headers);
var headersMap = new Map(headers);
var _iteratorNormalCompletion2 = true;
var _didIteratorError2 = false;
var _iteratorError2 = undefined;
for (let [k, v] of headersMap) {
hash[k] = v;
hash[k.toLowerCase()] = v;
try {
for (var _iterator2 = headersMap[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
var _step2$value = _slicedToArray(_step2.value, 2),
k = _step2$value[0],
v = _step2$value[1];
hash[k] = v;
hash[k.toLowerCase()] = v;
}
} catch (err) {
_didIteratorError2 = true;
_iteratorError2 = err;
} finally {
try {
if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
_iterator2.return();
}
} finally {
if (_didIteratorError2) {
throw _iteratorError2;
}
}
}

@@ -83,11 +144,11 @@ }

return {
headers,
status,
body,
text,
response
headers: headers,
status: status,
body: body,
text: text,
response: response
};
}
const BODYLESS_METHODS = ['GET', 'HEAD'];
var BODYLESS_METHODS = ['GET', 'HEAD'];
/**

@@ -142,3 +203,5 @@ * Perform an http request. This method uses WHATWG's fetch API and returns a

beforeSendCallbacks.forEach(cb => cb(opts));
beforeSendCallbacks.forEach(function (cb) {
return cb(opts);
});
method = opts.method;

@@ -154,3 +217,3 @@ url = opts.url;

for (const h in opts.headers) {
for (var h in opts.headers) {
// @ts-ignore: this is technically supported by the headers TS Api

@@ -166,3 +229,5 @@ if (opts.headers[h] === null || typeof opts.headers[h] === 'undefined') {

if (!opts.skipBodyTransform && BODYLESS_METHODS.every(m => method.toUpperCase() !== m) && opts.body && typeof opts.body === 'object') {
if (!opts.skipBodyTransform && BODYLESS_METHODS.every(function (m) {
return method.toUpperCase() !== m;
}) && opts.body && _typeof(opts.body) === 'object') {
opts.body = JSON.stringify(opts.body);

@@ -176,14 +241,14 @@

if (opts.parameters) {
url += `${url.indexOf('?') === -1 ? '?' : '&'}${toQueryParams(opts.parameters)}`;
url += "".concat(url.indexOf('?') === -1 ? '?' : '&').concat(toQueryParams(opts.parameters));
}
let logMessage = `${method} ${url}`;
var logMessage = "".concat(method, " ").concat(url);
logRequest(logMessage);
return fetch(url, opts) // eslint-disable-line compat/compat
.then(response => {
const headers = toHash(response.headers);
const status = response.status;
logMessage = `${logMessage} (${status} ${response.statusText})`;
return response.text().then(text => {
const wrappedResponse = wrapResponse(headers, status, text, response);
.then(function (response) {
var headers = toHash(response.headers);
var status = response.status;
logMessage = "".concat(logMessage, " (").concat(status, " ").concat(response.statusText, ")");
return response.text().then(function (text) {
var wrappedResponse = wrapResponse(headers, status, text, response);

@@ -198,3 +263,3 @@ if (response.ok) {

});
}).catch(err => {
}).catch(function (err) {
logError(logMessage);

@@ -209,4 +274,8 @@ callback && callback(err);

export function get(...args) {
return request('GET', ...args);
export function get() {
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return request.apply(void 0, ['GET'].concat(args));
}

@@ -217,4 +286,8 @@ /**

export function post(...args) {
return request('POST', ...args);
export function post() {
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
args[_key2] = arguments[_key2];
}
return request.apply(void 0, ['POST'].concat(args));
}

@@ -225,4 +298,8 @@ /**

export function put(...args) {
return request('PUT', ...args);
export function put() {
for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
args[_key3] = arguments[_key3];
}
return request.apply(void 0, ['PUT'].concat(args));
}

@@ -233,4 +310,8 @@ /**

export function patch(...args) {
return request('PATCH', ...args);
export function patch() {
for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
args[_key4] = arguments[_key4];
}
return request.apply(void 0, ['PATCH'].concat(args));
}

@@ -241,4 +322,8 @@ /**

export function del(...args) {
return request('DELETE', ...args);
export function del() {
for (var _len5 = arguments.length, args = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
args[_key5] = arguments[_key5];
}
return request.apply(void 0, ['DELETE'].concat(args));
}

@@ -21,7 +21,17 @@ "use strict";

const logRequest = (0, _utilLogger.default)('http:request');
const logError = (0, _utilLogger.default)('http:error');
const logSuccess = (0, _utilLogger.default)('http:success');
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
function _iterableToArrayLimit(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
var logRequest = (0, _utilLogger.default)('http:request');
var logError = (0, _utilLogger.default)('http:error');
var logSuccess = (0, _utilLogger.default)('http:success');
// Store beforeSend callbacks.
let beforeSendCallbacks = [];
var beforeSendCallbacks = [];
/**

@@ -53,10 +63,33 @@ * Modify request options before they are sent.

function toQueryParams(kvs) {
const queryParams = []; // Clones the input
var queryParams = []; // Clones the input
if (Array.isArray(kvs) || kvs instanceof Map) {
for (let [k, v] of kvs) {
queryParams.push([k, v]);
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
for (var _iterator = kvs[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
var _step$value = _slicedToArray(_step.value, 2),
k = _step$value[0],
v = _step$value[1];
queryParams.push([k, v]);
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return != null) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
} else {
for (let k in kvs) {
for (var k in kvs) {
if (kvs.hasOwnProperty(k)) {

@@ -68,11 +101,17 @@ queryParams.push([k, kvs[k]]);

return queryParams.map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(v)}`).join('&');
return queryParams.map(function (_ref) {
var _ref2 = _slicedToArray(_ref, 2),
k = _ref2[0],
v = _ref2[1];
return "".concat(encodeURIComponent(k), "=").concat(encodeURIComponent(v));
}).join('&');
}
function toHash(headers) {
const hash = Object.create(null);
var hash = Object.create(null);
if (headers._headers) {
Object.keys(headers._headers).forEach(key => {
const value = Array.isArray(headers._headers[key]) ? headers._headers[key][0] : headers._headers[key];
Object.keys(headers._headers).forEach(function (key) {
var value = Array.isArray(headers._headers[key]) ? headers._headers[key][0] : headers._headers[key];
hash[key] = value;

@@ -83,7 +122,29 @@ hash[key.toLowerCase()] = value;

// converting to Map allows for .. of in Edge
const headersMap = new Map(headers);
var headersMap = new Map(headers);
var _iteratorNormalCompletion2 = true;
var _didIteratorError2 = false;
var _iteratorError2 = undefined;
for (let [k, v] of headersMap) {
hash[k] = v;
hash[k.toLowerCase()] = v;
try {
for (var _iterator2 = headersMap[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
var _step2$value = _slicedToArray(_step2.value, 2),
k = _step2$value[0],
v = _step2$value[1];
hash[k] = v;
hash[k.toLowerCase()] = v;
}
} catch (err) {
_didIteratorError2 = true;
_iteratorError2 = err;
} finally {
try {
if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
_iterator2.return();
}
} finally {
if (_didIteratorError2) {
throw _iteratorError2;
}
}
}

@@ -103,11 +164,11 @@ }

return {
headers,
status,
body,
text,
response
headers: headers,
status: status,
body: body,
text: text,
response: response
};
}
const BODYLESS_METHODS = ['GET', 'HEAD'];
var BODYLESS_METHODS = ['GET', 'HEAD'];
/**

@@ -162,3 +223,5 @@ * Perform an http request. This method uses WHATWG's fetch API and returns a

beforeSendCallbacks.forEach(cb => cb(opts));
beforeSendCallbacks.forEach(function (cb) {
return cb(opts);
});
method = opts.method;

@@ -174,3 +237,3 @@ url = opts.url;

for (const h in opts.headers) {
for (var h in opts.headers) {
// @ts-ignore: this is technically supported by the headers TS Api

@@ -186,3 +249,5 @@ if (opts.headers[h] === null || typeof opts.headers[h] === 'undefined') {

if (!opts.skipBodyTransform && BODYLESS_METHODS.every(m => method.toUpperCase() !== m) && opts.body && typeof opts.body === 'object') {
if (!opts.skipBodyTransform && BODYLESS_METHODS.every(function (m) {
return method.toUpperCase() !== m;
}) && opts.body && _typeof(opts.body) === 'object') {
opts.body = JSON.stringify(opts.body);

@@ -196,14 +261,14 @@

if (opts.parameters) {
url += `${url.indexOf('?') === -1 ? '?' : '&'}${toQueryParams(opts.parameters)}`;
url += "".concat(url.indexOf('?') === -1 ? '?' : '&').concat(toQueryParams(opts.parameters));
}
let logMessage = `${method} ${url}`;
var logMessage = "".concat(method, " ").concat(url);
logRequest(logMessage);
return fetch(url, opts) // eslint-disable-line compat/compat
.then(response => {
const headers = toHash(response.headers);
const status = response.status;
logMessage = `${logMessage} (${status} ${response.statusText})`;
return response.text().then(text => {
const wrappedResponse = wrapResponse(headers, status, text, response);
.then(function (response) {
var headers = toHash(response.headers);
var status = response.status;
logMessage = "".concat(logMessage, " (").concat(status, " ").concat(response.statusText, ")");
return response.text().then(function (text) {
var wrappedResponse = wrapResponse(headers, status, text, response);

@@ -218,3 +283,3 @@ if (response.ok) {

});
}).catch(err => {
}).catch(function (err) {
logError(logMessage);

@@ -230,4 +295,8 @@ callback && callback(err);

function get(...args) {
return request('GET', ...args);
function get() {
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return request.apply(void 0, ['GET'].concat(args));
}

@@ -239,4 +308,8 @@ /**

function post(...args) {
return request('POST', ...args);
function post() {
for (var _len2 = arguments.length, args = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
args[_key2] = arguments[_key2];
}
return request.apply(void 0, ['POST'].concat(args));
}

@@ -248,4 +321,8 @@ /**

function put(...args) {
return request('PUT', ...args);
function put() {
for (var _len3 = arguments.length, args = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
args[_key3] = arguments[_key3];
}
return request.apply(void 0, ['PUT'].concat(args));
}

@@ -257,4 +334,8 @@ /**

function patch(...args) {
return request('PATCH', ...args);
function patch() {
for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
args[_key4] = arguments[_key4];
}
return request.apply(void 0, ['PATCH'].concat(args));
}

@@ -266,4 +347,8 @@ /**

function del(...args) {
return request('DELETE', ...args);
function del() {
for (var _len5 = arguments.length, args = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
args[_key5] = arguments[_key5];
}
return request.apply(void 0, ['DELETE'].concat(args));
}

@@ -13,3 +13,3 @@ "use strict";

enumerable: true,
get: function () {
get: function get() {
return _http[key];

@@ -16,0 +16,0 @@ }

{
"name": "@cloudflare/util-http",
"description": "Cloudflare HTTP Util",
"version": "1.0.11",
"version": "1.0.12",
"main": "lib/index.js",

@@ -15,3 +15,3 @@ "module": "es/index.js",

"dependencies": {
"@cloudflare/util-logger": "^1.0.10",
"@cloudflare/util-logger": "^1.0.11",
"isomorphic-fetch": "^2.2.1"

@@ -18,0 +18,0 @@ },

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