@rest-hooks/endpoint
Advanced tools
Comparing version 1.0.1 to 1.0.2
@@ -6,2 +6,11 @@ # Change Log | ||
### [1.0.2](https://github.com/coinbase/rest-hooks/compare/@rest-hooks/endpoint@1.0.1...@rest-hooks/endpoint@1.0.2) (2021-01-30) | ||
### 🐛 Bug Fix | ||
* Ensure Endpoint doesn't trigger CSP ([#505](https://github.com/coinbase/rest-hooks/issues/505)) ([a5a0011](https://github.com/coinbase/rest-hooks/commit/a5a00119c8888ce5c0440d2045febd9985fd2a8e)) | ||
### [1.0.1](https://github.com/coinbase/rest-hooks/compare/@rest-hooks/endpoint@1.0.0...@rest-hooks/endpoint@1.0.1) (2021-01-24) | ||
@@ -8,0 +17,0 @@ |
@@ -122,2 +122,10 @@ 'use strict'; | ||
var CSP = false; | ||
try { | ||
Function(); | ||
} catch (e) { | ||
CSP = true; | ||
} | ||
var Endpoint = /*#__PURE__*/function (_Function) { | ||
@@ -129,14 +137,29 @@ _inheritsLoose(Endpoint, _Function); | ||
_this = _Function.call(this, 'return arguments.callee.fetch.apply(arguments.callee, arguments)') || this; | ||
var _self2; | ||
_this.getFetchKey = function (params) { | ||
return _this.key(params); | ||
if (CSP) { | ||
_self2 = function self() { | ||
var _self; | ||
return (_self = _self2).fetch.apply(_self, arguments); | ||
}; | ||
Object.setPrototypeOf(_self2, (this instanceof Endpoint ? this.constructor : void 0).prototype); | ||
} else { | ||
_this = _Function.call(this, 'return arguments.callee.fetch.apply(arguments.callee, arguments)') || this; | ||
_self2 = _assertThisInitialized(_this); | ||
} | ||
/** The following is for compatibility with FetchShape */ | ||
_self2.getFetchKey = function (params) { | ||
return _self2.key(params); | ||
}; | ||
if (fetchFunction) _this.fetch = fetchFunction; | ||
Object.assign(_assertThisInitialized(_this), options); | ||
if (fetchFunction) _self2.fetch = fetchFunction; | ||
Object.assign(_self2, options); | ||
/** The following is for compatibility with FetchShape */ | ||
runCompat(_assertThisInitialized(_this), options); | ||
return _this; | ||
runCompat(_self2, options); | ||
return _self2 || _assertThisInitialized(_this); | ||
} | ||
@@ -169,5 +192,3 @@ | ||
return instance; | ||
} | ||
/** The following is for compatibility with FetchShape */ | ||
; | ||
}; | ||
@@ -174,0 +195,0 @@ return Endpoint; |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@rest-hooks/normalizr")):"function"==typeof define&&define.amd?define(["exports","@rest-hooks/normalizr"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).restHookCore={},e.normalizr)}(this,(function(e,t){"use strict";function n(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function r(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,e.__proto__=t}function o(e){return(o=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function i(e,t){return(i=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function c(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(e){return!1}}function u(e,t,n){return(u=c()?Reflect.construct:function(e,t,n){var r=[null];r.push.apply(r,t);var o=new(Function.bind.apply(e,r));return n&&i(o,n.prototype),o}).apply(null,arguments)}function f(e){var t="function"==typeof Map?new Map:void 0;return(f=function(e){if(null===e||(n=e,-1===Function.toString.call(n).indexOf("[native code]")))return e;var n;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,r)}function r(){return u(e,arguments,o(this).constructor)}return r.prototype=Object.create(e.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),i(r,e)})(e)}function s(e,t){e.type=e.sideEffect?"mutate":"read",e.options=Object.assign({},t),delete e.options.key,delete e.options.schema,delete e.options.sideEffect,delete e.options.fetch,delete e.options.getFetchKey,delete e.options.options,0===Object.keys(e.options).length&&delete e.options,void 0===e.schema&&(e.schema=null)}var p=function(e){function t(t,r){var o;return(o=e.call(this,"return arguments.callee.fetch.apply(arguments.callee, arguments)")||this).getFetchKey=function(e){return o.key(e)},t&&(o.fetch=t),Object.assign(n(o),r),s(n(o),r),o}r(t,e);var o=t.prototype;return o.key=function(e){return this.fetch.name+" "+JSON.stringify(e)},o.extend=function(e){var t=function(e){function t(){return e.apply(this,arguments)||this}return r(t,e),t}(this.constructor);Object.assign(t.prototype,this);var n=new t(e.fetch,e);return s(n,Object.assign({},this.options,e)),n},t}(f(Function)),a=function(){function e(e,t){var n=this;this.getFetchKey=function(e){return n.key(e)},this.schema=e,t&&(this.key=t)}return e.prototype.key=function(e){return JSON.stringify(e)},e}();Object.defineProperty(e,"DELETED",{enumerable:!0,get:function(){return t.DELETED}}),Object.defineProperty(e,"Entity",{enumerable:!0,get:function(){return t.Entity}}),Object.defineProperty(e,"SimpleRecord",{enumerable:!0,get:function(){return t.SimpleRecord}}),Object.defineProperty(e,"isEntity",{enumerable:!0,get:function(){return t.isEntity}}),Object.defineProperty(e,"schema",{enumerable:!0,get:function(){return t.schema}}),e.Endpoint=p,e.Index=a,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@rest-hooks/normalizr")):"function"==typeof define&&define.amd?define(["exports","@rest-hooks/normalizr"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).restHookCore={},t.normalizr)}(this,(function(t,e){"use strict";function n(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function r(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,t.__proto__=e}function o(t){return(o=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function i(t,e){return(i=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function c(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(t){return!1}}function u(t,e,n){return(u=c()?Reflect.construct:function(t,e,n){var r=[null];r.push.apply(r,e);var o=new(Function.bind.apply(t,r));return n&&i(o,n.prototype),o}).apply(null,arguments)}function f(t){var e="function"==typeof Map?new Map:void 0;return(f=function(t){if(null===t||(n=t,-1===Function.toString.call(n).indexOf("[native code]")))return t;var n;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,r)}function r(){return u(t,arguments,o(this).constructor)}return r.prototype=Object.create(t.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),i(r,t)})(t)}function s(t,e){t.type=t.sideEffect?"mutate":"read",t.options=Object.assign({},e),delete t.options.key,delete t.options.schema,delete t.options.sideEffect,delete t.options.fetch,delete t.options.getFetchKey,delete t.options.options,0===Object.keys(t.options).length&&delete t.options,void 0===t.schema&&(t.schema=null)}var p=!1;try{Function()}catch(t){p=!0}var a=function(t){function e(r,o){var i,c;return p?(c=function(){var t;return(t=c).fetch.apply(t,arguments)},Object.setPrototypeOf(c,(this instanceof e?this.constructor:void 0).prototype)):(i=t.call(this,"return arguments.callee.fetch.apply(arguments.callee, arguments)")||this,c=n(i)),c.getFetchKey=function(t){return c.key(t)},r&&(c.fetch=r),Object.assign(c,o),s(c,o),c||n(i)}r(e,t);var o=e.prototype;return o.key=function(t){return this.fetch.name+" "+JSON.stringify(t)},o.extend=function(t){var e=function(t){function e(){return t.apply(this,arguments)||this}return r(e,t),e}(this.constructor);Object.assign(e.prototype,this);var n=new e(t.fetch,t);return s(n,Object.assign({},this.options,t)),n},e}(f(Function)),l=function(){function t(t,e){var n=this;this.getFetchKey=function(t){return n.key(t)},this.schema=t,e&&(this.key=e)}return t.prototype.key=function(t){return JSON.stringify(t)},t}();Object.defineProperty(t,"DELETED",{enumerable:!0,get:function(){return e.DELETED}}),Object.defineProperty(t,"Entity",{enumerable:!0,get:function(){return e.Entity}}),Object.defineProperty(t,"SimpleRecord",{enumerable:!0,get:function(){return e.SimpleRecord}}),Object.defineProperty(t,"isEntity",{enumerable:!0,get:function(){return e.isEntity}}),Object.defineProperty(t,"schema",{enumerable:!0,get:function(){return e.schema}}),t.Endpoint=a,t.Index=l,Object.defineProperty(t,"__esModule",{value:!0})})); |
@@ -19,15 +19,33 @@ function runCompat(endpoint, options) { | ||
let CSP = false; | ||
try { | ||
Function(); | ||
} catch (e) { | ||
CSP = true; | ||
} | ||
export default class Endpoint extends Function { | ||
constructor(fetchFunction, options) { | ||
super('return arguments.callee.fetch.apply(arguments.callee, arguments)'); | ||
let self; | ||
this.getFetchKey = params => { | ||
return this.key(params); | ||
}; | ||
if (CSP) { | ||
self = (...args) => self.fetch(...args); | ||
if (fetchFunction) this.fetch = fetchFunction; | ||
Object.assign(this, options); | ||
Object.setPrototypeOf(self, new.target.prototype); | ||
} else { | ||
super('return arguments.callee.fetch.apply(arguments.callee, arguments)'); | ||
self = this; | ||
} | ||
/** The following is for compatibility with FetchShape */ | ||
runCompat(this, options); | ||
self.getFetchKey = params => self.key(params); | ||
if (fetchFunction) self.fetch = fetchFunction; | ||
Object.assign(self, options); | ||
/** The following is for compatibility with FetchShape */ | ||
runCompat(self, options); | ||
return self; | ||
} | ||
@@ -53,6 +71,4 @@ | ||
} | ||
/** The following is for compatibility with FetchShape */ | ||
} | ||
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uL3NyYy9lbmRwb2ludC5qcyJdLCJuYW1lcyI6WyJydW5Db21wYXQiLCJlbmRwb2ludCIsIm9wdGlvbnMiLCJ0eXBlIiwic2lkZUVmZmVjdCIsImtleSIsInNjaGVtYSIsImZldGNoIiwiZ2V0RmV0Y2hLZXkiLCJPYmplY3QiLCJrZXlzIiwibGVuZ3RoIiwidW5kZWZpbmVkIiwiRW5kcG9pbnQiLCJGdW5jdG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||
"version": "1.0.2", | ||
"description": "Declarative Network Interface Definitions", | ||
@@ -57,3 +57,3 @@ "sideEffects": false, | ||
}, | ||
"gitHead": "a031da2ace9ba826dd1acc50b50cec4d42cc6a85" | ||
"gitHead": "ebe81d7207573ff57b73b13c9ada494ce88fa731" | ||
} |
@@ -16,9 +16,28 @@ function runCompat(endpoint, options) { | ||
let CSP = false; | ||
try { | ||
Function(); | ||
} catch (e) { | ||
CSP = true; | ||
} | ||
export default class Endpoint extends Function { | ||
constructor(fetchFunction, options) { | ||
super('return arguments.callee.fetch.apply(arguments.callee, arguments)'); | ||
if (fetchFunction) this.fetch = fetchFunction; | ||
Object.assign(this, options); | ||
let self; | ||
if (CSP) { | ||
self = (...args) => self.fetch(...args); | ||
Object.setPrototypeOf(self, new.target.prototype); | ||
} else { | ||
super('return arguments.callee.fetch.apply(arguments.callee, arguments)'); | ||
self = this; | ||
} | ||
/** The following is for compatibility with FetchShape */ | ||
runCompat(this, options); | ||
self.getFetchKey = params => self.key(params); | ||
if (fetchFunction) self.fetch = fetchFunction; | ||
Object.assign(self, options); | ||
/** The following is for compatibility with FetchShape */ | ||
runCompat(self, options); | ||
return self; | ||
} | ||
@@ -34,2 +53,3 @@ | ||
class E extends this.constructor {} | ||
Object.assign(E.prototype, this); | ||
@@ -43,7 +63,2 @@ const instance = new E(options.fetch, options); | ||
} | ||
/** The following is for compatibility with FetchShape */ | ||
getFetchKey = params => { | ||
return this.key(params); | ||
}; | ||
} |
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
99626
1406
2