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

xhr-shaper

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

xhr-shaper - npm Package Compare versions

Comparing version 2.2.0 to 2.2.1

149

dist/XHRShaper.this.js

@@ -134,16 +134,16 @@ this["XHRShaper"] =

}, {
key: "dispatchEvent",
value: function dispatchEvent(type) {
return this._xhr.dispatchEvent(type);
}
}, {
key: "addEventListener",
value: function addEventListener(type, handler) {
return this._xhr.addEventListener(type, handler);
value: function addEventListener(type, listener, optionsOrUseCapture, wantsUntrusted) {
return this._xhr.addEventListener(type, listener, optionsOrUseCapture, wantsUntrusted);
}
}, {
key: "removeEventListener",
value: function removeEventListener(type, handler) {
return this._xhr.removeEventListener(type, handler);
value: function removeEventListener(type, listener, optionsOrUseCapture) {
return this._xhr.removeEventListener(type, listener, optionsOrUseCapture);
}
}, {
key: "dispatchEvent",
value: function dispatchEvent(event) {
return this._xhr.dispatchEvent(event);
}

@@ -301,2 +301,4 @@ // Read-only properties

var _get = function get(object, property, receiver) { if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } };
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

@@ -312,5 +314,5 @@

var _initThrottledXhr = __webpack_require__(3);
var _setupThrottledXhr = __webpack_require__(3);
var _initThrottledXhr2 = _interopRequireDefault(_initThrottledXhr);
var _setupThrottledXhr2 = _interopRequireDefault(_setupThrottledXhr);

@@ -325,2 +327,10 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var PASSTHROUGH_EVENTS = ['loadstart', 'timeout', 'abort', 'error'];
var createListenerWrapper = function createListenerWrapper(type, listener, dispatchedEventsList) {
return function (event) {
dispatchedEventsList.push({ type: type, listener: listener, event: event, propagated: false });
};
};
var ThrottledXHR = function (_XHRProxy) {

@@ -342,4 +352,6 @@ _inherits(ThrottledXHR, _XHRProxy);

_this._shaper = new _shaper2.default();
_this._listenersMap = new Map();
_this._dispatchedEventsList = [];
(0, _initThrottledXhr2.default)(_this._xhr, _this);
(0, _setupThrottledXhr2.default)(_this._xhr, _this);
return _this;

@@ -349,15 +361,48 @@ }

_createClass(ThrottledXHR, [{
key: '_dispatchWrappedEventType',
value: function _dispatchWrappedEventType(type) {
var _this2 = this;
// it needs to run on the next tick since this is actually
// triggered from our throttler listeners on the proxy's inner XHR
setTimeout(function () {
_this2._dispatchedEventsList.filter(function (dispatchedEvent) {
return dispatchedEvent.type === type && !dispatchedEvent.propagated;
}).forEach(function (dispatchedEvent) {
dispatchedEvent.propagated = true;
dispatchedEvent.listener(dispatchedEvent.event);
});
}, 0);
}
}, {
key: 'addEventListener',
value: function addEventListener() {
throw new Error('EventTarget API not implemented');
value: function addEventListener(type, listener, optionsOrUseCapture, wantsUntrusted) {
if (PASSTHROUGH_EVENTS.includes(type)) {
return _get(ThrottledXHR.prototype.__proto__ || Object.getPrototypeOf(ThrottledXHR.prototype), 'addEventListener', this).call(this, type, listener, optionsOrUseCapture, wantsUntrusted);
}
var listenerWrapper = createListenerWrapper(type, listener, this._dispatchedEventsList);
this._listenersMap.set(listener, listenerWrapper);
return _get(ThrottledXHR.prototype.__proto__ || Object.getPrototypeOf(ThrottledXHR.prototype), 'addEventListener', this).call(this, type, listenerWrapper, optionsOrUseCapture, wantsUntrusted);
}
}, {
key: 'removeEventListener',
value: function removeEventListener() {
throw new Error('EventTarget API not implemented');
value: function removeEventListener(type, listener, optionsOrUseCapture) {
if (PASSTHROUGH_EVENTS.includes(type)) {
return _get(ThrottledXHR.prototype.__proto__ || Object.getPrototypeOf(ThrottledXHR.prototype), 'removeEventListener', this).call(this, type, listener, optionsOrUseCapture);
}
var listenerWrapper = this._listenersMap.get(listener);
if (!listenerWrapper) {
return;
}
this._listenersMap.delete(listener);
return _get(ThrottledXHR.prototype.__proto__ || Object.getPrototypeOf(ThrottledXHR.prototype), 'removeEventListener', this).call(this, type, listenerWrapper, optionsOrUseCapture);
}
}, {
key: 'dispatchEvent',
value: function dispatchEvent() {
throw new Error('EventTarget API not implemented');
value: function dispatchEvent(event) {
return _get(ThrottledXHR.prototype.__proto__ || Object.getPrototypeOf(ThrottledXHR.prototype), 'dispatchEvent', this).call(this, event);
}

@@ -449,8 +494,4 @@ }, {

});
function initThrottledXhr(xhr, xhrProxy) {
var shaper = xhrProxy.shaper,
_onload = xhrProxy._onload,
_onloadend = xhrProxy._onloadend,
_onreadystatechange = xhrProxy._onreadystatechange,
_onprogress = xhrProxy._onprogress;
function setupThrottledXhr(xhr, xhrProxy) {
var shaper = xhrProxy.shaper;

@@ -473,7 +514,3 @@

xhr.onloadend = function (event) {
var shaper = xhrProxy.shaper,
_onload = xhrProxy._onload,
_onloadend = xhrProxy._onloadend,
_onreadystatechange = xhrProxy._onreadystatechange,
_onprogress = xhrProxy._onprogress;
var _onloadend = xhrProxy._onloadend;

@@ -483,4 +520,5 @@ //console.log('native loadend');

loadEndEvent = event;
if (done && _onloadend) {
_onloadend(event);
if (done) {
_onloadend && _onloadend(event);
xhrProxy._dispatchWrappedEventType('loadend');
}

@@ -490,7 +528,3 @@ };

xhr.onload = function (event) {
var shaper = xhrProxy.shaper,
_onload = xhrProxy._onload,
_onloadend = xhrProxy._onloadend,
_onreadystatechange = xhrProxy._onreadystatechange,
_onprogress = xhrProxy._onprogress;
var _onload = xhrProxy._onload;

@@ -500,4 +534,5 @@ //console.log('native load');

loadEvent = event;
if (done && _onload && xhr.readyState === 4) {
_onload(event);
if (done && xhr.readyState === 4) {
_onload && _onload(event);
xhrProxy._dispatchWrappedEventType('load');
}

@@ -507,13 +542,11 @@ };

xhr.onreadystatechange = function (event) {
var shaper = xhrProxy.shaper,
var _onreadystatechange = xhrProxy._onreadystatechange,
_onprogress = xhrProxy._onprogress,
_onload = xhrProxy._onload,
_onloadend = xhrProxy._onloadend,
_onreadystatechange = xhrProxy._onreadystatechange,
_onprogress = xhrProxy._onprogress;
_onloadend = xhrProxy._onloadend;
function triggerStateChange(e) {
if (_onreadystatechange) {
_onreadystatechange(e);
}
_onreadystatechange && _onreadystatechange(e);
xhrProxy._dispatchWrappedEventType('readystatechange');
}

@@ -558,3 +591,4 @@

clearTimeout(progressTimer);
_onprogress(progressEvents[progressEvents.length - 1]);
_onprogress && _onprogress(progressEvents[progressEvents.length - 1]);
xhrProxy._dispatchWrappedEventType('progress');
}

@@ -566,9 +600,11 @@

if (loadEvent && _onload) {
_onload(loadEvent);
if (loadEvent) {
_onload && _onload(loadEvent);
xhrProxy._dispatchWrappedEventType('load');
loadEvent = null;
}
if (loadEndEvent && _onloadend) {
_onloadend(loadEndEvent);
if (loadEndEvent) {
_onloadend && _onloadend(loadEndEvent);
xhrProxy._dispatchWrappedEventType('loadend');
loadEndEvent = null;

@@ -587,7 +623,3 @@ }

xhr.onprogress = function (event) {
var shaper = xhrProxy.shaper,
_onload = xhrProxy._onload,
_onloadend = xhrProxy._onloadend,
_onreadystatechange = xhrProxy._onreadystatechange,
_onprogress = xhrProxy._onprogress;
var _onprogress = xhrProxy._onprogress;

@@ -601,5 +633,4 @@

if (_onprogress) {
_onprogress(e);
}
_onprogress && _onprogress(e);
xhrProxy._dispatchWrappedEventType('progress');
}

@@ -636,3 +667,3 @@

exports.default = initThrottledXhr;
exports.default = setupThrottledXhr;

@@ -639,0 +670,0 @@ /***/ }),

@@ -143,16 +143,16 @@ (function webpackUniversalModuleDefinition(root, factory) {

}, {
key: "dispatchEvent",
value: function dispatchEvent(type) {
return this._xhr.dispatchEvent(type);
}
}, {
key: "addEventListener",
value: function addEventListener(type, handler) {
return this._xhr.addEventListener(type, handler);
value: function addEventListener(type, listener, optionsOrUseCapture, wantsUntrusted) {
return this._xhr.addEventListener(type, listener, optionsOrUseCapture, wantsUntrusted);
}
}, {
key: "removeEventListener",
value: function removeEventListener(type, handler) {
return this._xhr.removeEventListener(type, handler);
value: function removeEventListener(type, listener, optionsOrUseCapture) {
return this._xhr.removeEventListener(type, listener, optionsOrUseCapture);
}
}, {
key: "dispatchEvent",
value: function dispatchEvent(event) {
return this._xhr.dispatchEvent(event);
}

@@ -310,2 +310,4 @@ // Read-only properties

var _get = function get(object, property, receiver) { if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } };
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();

@@ -321,5 +323,5 @@

var _initThrottledXhr = __webpack_require__(3);
var _setupThrottledXhr = __webpack_require__(3);
var _initThrottledXhr2 = _interopRequireDefault(_initThrottledXhr);
var _setupThrottledXhr2 = _interopRequireDefault(_setupThrottledXhr);

@@ -334,2 +336,10 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var PASSTHROUGH_EVENTS = ['loadstart', 'timeout', 'abort', 'error'];
var createListenerWrapper = function createListenerWrapper(type, listener, dispatchedEventsList) {
return function (event) {
dispatchedEventsList.push({ type: type, listener: listener, event: event, propagated: false });
};
};
var ThrottledXHR = function (_XHRProxy) {

@@ -351,4 +361,6 @@ _inherits(ThrottledXHR, _XHRProxy);

_this._shaper = new _shaper2.default();
_this._listenersMap = new Map();
_this._dispatchedEventsList = [];
(0, _initThrottledXhr2.default)(_this._xhr, _this);
(0, _setupThrottledXhr2.default)(_this._xhr, _this);
return _this;

@@ -358,15 +370,48 @@ }

_createClass(ThrottledXHR, [{
key: '_dispatchWrappedEventType',
value: function _dispatchWrappedEventType(type) {
var _this2 = this;
// it needs to run on the next tick since this is actually
// triggered from our throttler listeners on the proxy's inner XHR
setTimeout(function () {
_this2._dispatchedEventsList.filter(function (dispatchedEvent) {
return dispatchedEvent.type === type && !dispatchedEvent.propagated;
}).forEach(function (dispatchedEvent) {
dispatchedEvent.propagated = true;
dispatchedEvent.listener(dispatchedEvent.event);
});
}, 0);
}
}, {
key: 'addEventListener',
value: function addEventListener() {
throw new Error('EventTarget API not implemented');
value: function addEventListener(type, listener, optionsOrUseCapture, wantsUntrusted) {
if (PASSTHROUGH_EVENTS.includes(type)) {
return _get(ThrottledXHR.prototype.__proto__ || Object.getPrototypeOf(ThrottledXHR.prototype), 'addEventListener', this).call(this, type, listener, optionsOrUseCapture, wantsUntrusted);
}
var listenerWrapper = createListenerWrapper(type, listener, this._dispatchedEventsList);
this._listenersMap.set(listener, listenerWrapper);
return _get(ThrottledXHR.prototype.__proto__ || Object.getPrototypeOf(ThrottledXHR.prototype), 'addEventListener', this).call(this, type, listenerWrapper, optionsOrUseCapture, wantsUntrusted);
}
}, {
key: 'removeEventListener',
value: function removeEventListener() {
throw new Error('EventTarget API not implemented');
value: function removeEventListener(type, listener, optionsOrUseCapture) {
if (PASSTHROUGH_EVENTS.includes(type)) {
return _get(ThrottledXHR.prototype.__proto__ || Object.getPrototypeOf(ThrottledXHR.prototype), 'removeEventListener', this).call(this, type, listener, optionsOrUseCapture);
}
var listenerWrapper = this._listenersMap.get(listener);
if (!listenerWrapper) {
return;
}
this._listenersMap.delete(listener);
return _get(ThrottledXHR.prototype.__proto__ || Object.getPrototypeOf(ThrottledXHR.prototype), 'removeEventListener', this).call(this, type, listenerWrapper, optionsOrUseCapture);
}
}, {
key: 'dispatchEvent',
value: function dispatchEvent() {
throw new Error('EventTarget API not implemented');
value: function dispatchEvent(event) {
return _get(ThrottledXHR.prototype.__proto__ || Object.getPrototypeOf(ThrottledXHR.prototype), 'dispatchEvent', this).call(this, event);
}

@@ -458,8 +503,4 @@ }, {

});
function initThrottledXhr(xhr, xhrProxy) {
var shaper = xhrProxy.shaper,
_onload = xhrProxy._onload,
_onloadend = xhrProxy._onloadend,
_onreadystatechange = xhrProxy._onreadystatechange,
_onprogress = xhrProxy._onprogress;
function setupThrottledXhr(xhr, xhrProxy) {
var shaper = xhrProxy.shaper;

@@ -482,7 +523,3 @@

xhr.onloadend = function (event) {
var shaper = xhrProxy.shaper,
_onload = xhrProxy._onload,
_onloadend = xhrProxy._onloadend,
_onreadystatechange = xhrProxy._onreadystatechange,
_onprogress = xhrProxy._onprogress;
var _onloadend = xhrProxy._onloadend;

@@ -492,4 +529,5 @@ //console.log('native loadend');

loadEndEvent = event;
if (done && _onloadend) {
_onloadend(event);
if (done) {
_onloadend && _onloadend(event);
xhrProxy._dispatchWrappedEventType('loadend');
}

@@ -499,7 +537,3 @@ };

xhr.onload = function (event) {
var shaper = xhrProxy.shaper,
_onload = xhrProxy._onload,
_onloadend = xhrProxy._onloadend,
_onreadystatechange = xhrProxy._onreadystatechange,
_onprogress = xhrProxy._onprogress;
var _onload = xhrProxy._onload;

@@ -509,4 +543,5 @@ //console.log('native load');

loadEvent = event;
if (done && _onload && xhr.readyState === 4) {
_onload(event);
if (done && xhr.readyState === 4) {
_onload && _onload(event);
xhrProxy._dispatchWrappedEventType('load');
}

@@ -516,13 +551,11 @@ };

xhr.onreadystatechange = function (event) {
var shaper = xhrProxy.shaper,
var _onreadystatechange = xhrProxy._onreadystatechange,
_onprogress = xhrProxy._onprogress,
_onload = xhrProxy._onload,
_onloadend = xhrProxy._onloadend,
_onreadystatechange = xhrProxy._onreadystatechange,
_onprogress = xhrProxy._onprogress;
_onloadend = xhrProxy._onloadend;
function triggerStateChange(e) {
if (_onreadystatechange) {
_onreadystatechange(e);
}
_onreadystatechange && _onreadystatechange(e);
xhrProxy._dispatchWrappedEventType('readystatechange');
}

@@ -567,3 +600,4 @@

clearTimeout(progressTimer);
_onprogress(progressEvents[progressEvents.length - 1]);
_onprogress && _onprogress(progressEvents[progressEvents.length - 1]);
xhrProxy._dispatchWrappedEventType('progress');
}

@@ -575,9 +609,11 @@

if (loadEvent && _onload) {
_onload(loadEvent);
if (loadEvent) {
_onload && _onload(loadEvent);
xhrProxy._dispatchWrappedEventType('load');
loadEvent = null;
}
if (loadEndEvent && _onloadend) {
_onloadend(loadEndEvent);
if (loadEndEvent) {
_onloadend && _onloadend(loadEndEvent);
xhrProxy._dispatchWrappedEventType('loadend');
loadEndEvent = null;

@@ -596,7 +632,3 @@ }

xhr.onprogress = function (event) {
var shaper = xhrProxy.shaper,
_onload = xhrProxy._onload,
_onloadend = xhrProxy._onloadend,
_onreadystatechange = xhrProxy._onreadystatechange,
_onprogress = xhrProxy._onprogress;
var _onprogress = xhrProxy._onprogress;

@@ -610,5 +642,4 @@

if (_onprogress) {
_onprogress(e);
}
_onprogress && _onprogress(e);
xhrProxy._dispatchWrappedEventType('progress');
}

@@ -645,3 +676,3 @@

exports.default = initThrottledXhr;
exports.default = setupThrottledXhr;

@@ -648,0 +679,0 @@ /***/ }),

{
"name": "xhr-shaper",
"version": "2.2.0",
"version": "2.2.1",
"description": "Shapes your XHR requests to a max emulated bandwidth and latency, randomizes frequency of progress events",

@@ -12,3 +12,4 @@ "main": "index.js",

"lint": "./node_modules/.bin/eslint .",
"start": "npm run dev"
"start": "npm run dev",
"prepublish": "npm run build"
},

@@ -15,0 +16,0 @@ "keywords": [

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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