Socket
Socket
Sign inDemoInstall

crex

Package Overview
Dependencies
Maintainers
1
Versions
60
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

crex - npm Package Compare versions

Comparing version 0.3.0 to 0.4.0

test/test.zip

2

dist/crex.browser.min.js

@@ -1,1 +0,1 @@

var CrEx=function(){"use strict";function t(t,e){return e={exports:{}},t(e,e.exports),e.exports}function e(t){return null!==t&&"object"==typeof t}function r(t){if(t)return i(t)}function i(t){for(var e in r.prototype)t[e]=r.prototype[e];return t}function s(t){return"[object Function]"===(h(t)?Object.prototype.toString.call(t):"")}function n(t){if(t)return o(t)}function o(t){for(var e in n.prototype)t[e]=n.prototype[e];return t}var a="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},u=t(function(t){function e(t){if(t)return r(t)}function r(t){for(var r in e.prototype)t[r]=e.prototype[r];return t}t.exports=e,e.prototype.on=e.prototype.addEventListener=function(t,e){return this._callbacks=this._callbacks||{},(this._callbacks["$"+t]=this._callbacks["$"+t]||[]).push(e),this},e.prototype.once=function(t,e){function r(){this.off(t,r),e.apply(this,arguments)}return r.fn=e,this.on(t,r),this},e.prototype.off=e.prototype.removeListener=e.prototype.removeAllListeners=e.prototype.removeEventListener=function(t,e){if(this._callbacks=this._callbacks||{},0==arguments.length)return this._callbacks={},this;var r=this._callbacks["$"+t];if(!r)return this;if(1==arguments.length)return delete this._callbacks["$"+t],this;for(var i,s=0;s<r.length;s++)if((i=r[s])===e||i.fn===e){r.splice(s,1);break}return this},e.prototype.emit=function(t){this._callbacks=this._callbacks||{};var e=[].slice.call(arguments,1),r=this._callbacks["$"+t];if(r){r=r.slice(0);for(var i=0,s=r.length;i<s;++i)r[i].apply(this,e)}return this},e.prototype.listeners=function(t){return this._callbacks=this._callbacks||{},this._callbacks["$"+t]||[]},e.prototype.hasListeners=function(t){return!!this.listeners(t).length}}),h=e,p=r;r.prototype.clearTimeout=function(){return clearTimeout(this._timer),clearTimeout(this._responseTimeoutTimer),delete this._timer,delete this._responseTimeoutTimer,this},r.prototype.parse=function(t){return this._parser=t,this},r.prototype.responseType=function(t){return this._responseType=t,this},r.prototype.serialize=function(t){return this._serializer=t,this},r.prototype.timeout=function(t){if(!t||"object"!=typeof t)return this._timeout=t,this._responseTimeout=0,this;for(var e in t)switch(e){case"deadline":this._timeout=t.deadline;break;case"response":this._responseTimeout=t.response;break;default:console.warn("Unknown timeout option",e)}return this},r.prototype.retry=function(t){return 0!==arguments.length&&!0!==t||(t=1),t<=0&&(t=0),this._maxRetries=t,this._retries=0,this},r.prototype._retry=function(){return this.clearTimeout(),this.req&&(this.req=null,this.req=this.request()),this._aborted=!1,this.timedout=!1,this._end()},r.prototype.then=function(t,e){if(!this._fullfilledPromise){var r=this;this._endCalled&&console.warn("Warning: superagent request was sent twice, because both .end() and .then() were called. Never call .end() if you use promises"),this._fullfilledPromise=new Promise(function(t,e){r.end(function(r,i){r?e(r):t(i)})})}return this._fullfilledPromise.then(t,e)},r.prototype.catch=function(t){return this.then(void 0,t)},r.prototype.use=function(t){return t(this),this},r.prototype.ok=function(t){if("function"!=typeof t)throw Error("Callback required");return this._okCallback=t,this},r.prototype._isResponseOK=function(t){return!!t&&(this._okCallback?this._okCallback(t):t.status>=200&&t.status<300)},r.prototype.get=function(t){return this._header[t.toLowerCase()]},r.prototype.getHeader=r.prototype.get,r.prototype.set=function(t,e){if(h(t)){for(var r in t)this.set(r,t[r]);return this}return this._header[t.toLowerCase()]=e,this.header[t]=e,this},r.prototype.unset=function(t){return delete this._header[t.toLowerCase()],delete this.header[t],this},r.prototype.field=function(t,e){if(null===t||void 0===t)throw new Error(".field(name, val) name can not be empty");if(this._data&&console.error(".field() can't be used if .send() is used. Please use only .send() or only .field() & .attach()"),h(t)){for(var r in t)this.field(r,t[r]);return this}if(Array.isArray(e)){for(var i in e)this.field(t,e[i]);return this}if(null===e||void 0===e)throw new Error(".field(name, val) val can not be empty");return"boolean"==typeof e&&(e=""+e),this._getFormData().append(t,e),this},r.prototype.abort=function(){return this._aborted?this:(this._aborted=!0,this.xhr&&this.xhr.abort(),this.req&&this.req.abort(),this.clearTimeout(),this.emit("abort"),this)},r.prototype.withCredentials=function(t){return void 0==t&&(t=!0),this._withCredentials=t,this},r.prototype.redirects=function(t){return this._maxRedirects=t,this},r.prototype.toJSON=function(){return{method:this.method,url:this.url,data:this._data,headers:this._header}},r.prototype.send=function(t){var e=h(t),r=this._header["content-type"];if(this._formData&&console.error(".send() can't be used if .attach() or .field() is used. Please use only .send() or only .field() & .attach()"),e&&!this._data)Array.isArray(t)?this._data=[]:this._isHost(t)||(this._data={});else if(t&&this._data&&this._isHost(this._data))throw Error("Can't merge these send calls");if(e&&h(this._data))for(var i in t)this._data[i]=t[i];else"string"==typeof t?(r||this.type("form"),r=this._header["content-type"],this._data="application/x-www-form-urlencoded"==r?this._data?this._data+"&"+t:t:(this._data||"")+t):this._data=t;return!e||this._isHost(t)?this:(r||this.type("json"),this)},r.prototype.sortQuery=function(t){return this._sort=void 0===t||t,this},r.prototype._timeoutError=function(t,e,r){if(!this._aborted){var i=new Error(t+e+"ms exceeded");i.timeout=e,i.code="ECONNABORTED",i.errno=r,this.timedout=!0,this.abort(),this.callback(i)}},r.prototype._setTimeouts=function(){var t=this;this._timeout&&!this._timer&&(this._timer=setTimeout(function(){t._timeoutError("Timeout of ",t._timeout,"ETIME")},this._timeout)),this._responseTimeout&&!this._responseTimeoutTimer&&(this._responseTimeoutTimer=setTimeout(function(){t._timeoutError("Response timeout of ",t._responseTimeout,"ETIMEDOUT")},this._responseTimeout))};var c=s,l=function(t){return t.split(/ *; */).shift()},f=function(t){return t.split(/ *; */).reduce(function(t,e){var r=e.split(/ *= */),i=r.shift(),s=r.shift();return i&&s&&(t[i]=s),t},{})},d=function(t){return t.split(/ *, */).reduce(function(t,e){var r=e.split(/ *; */),i=r[0].slice(1,-1);return t[r[1].split(/ *= */)[1].slice(1,-1)]=i,t},{})},y=function(t,e){return delete t["content-type"],delete t["content-length"],delete t["transfer-encoding"],delete t.host,e&&delete t.cookie,t},m={type:l,params:f,parseLinks:d,cleanHeader:y},_=n;n.prototype.get=function(t){return this.header[t.toLowerCase()]},n.prototype._setHeaderProperties=function(t){var e=t["content-type"]||"";this.type=m.type(e);var r=m.params(e);for(var i in r)this[i]=r[i];this.links={};try{t.link&&(this.links=m.parseLinks(t.link))}catch(t){}},n.prototype._setStatusProperties=function(t){var e=t/100|0;this.status=this.statusCode=t,this.statusType=e,this.info=1==e,this.ok=2==e,this.redirect=3==e,this.clientError=4==e,this.serverError=5==e,this.error=(4==e||5==e)&&this.toError(),this.accepted=202==t,this.noContent=204==t,this.badRequest=400==t,this.unauthorized=401==t,this.notAcceptable=406==t,this.forbidden=403==t,this.notFound=404==t};var v=["ECONNRESET","ETIMEDOUT","EADDRINFO","ESOCKETTIMEDOUT"],b=function(t,e){return!!(t&&t.code&&~v.indexOf(t.code))||(!!(e&&e.status&&e.status>=500)||(!!(t&&"timeout"in t&&"ECONNABORTED"==t.code)||!!(t&&"crossDomain"in t)))},w=t(function(t,e){function r(){}function i(t){if(!h(t))return t;var e=[];for(var r in t)s(e,r,t[r]);return e.join("&")}function s(t,e,r){if(null!=r)if(Array.isArray(r))r.forEach(function(r){s(t,e,r)});else if(h(r))for(var i in r)s(t,e+"["+i+"]",r[i]);else t.push(encodeURIComponent(e)+"="+encodeURIComponent(r));else null===r&&t.push(encodeURIComponent(e))}function n(t){for(var e,r,i={},s=t.split("&"),n=0,o=s.length;n<o;++n)e=s[n],r=e.indexOf("="),-1==r?i[decodeURIComponent(e)]="":i[decodeURIComponent(e.slice(0,r))]=decodeURIComponent(e.slice(r+1));return i}function o(t){var e,r,i,s,n=t.split(/\r?\n/),o={};n.pop();for(var a=0,u=n.length;a<u;++a)r=n[a],e=r.indexOf(":"),i=r.slice(0,e).toLowerCase(),s=w(r.slice(e+1)),o[i]=s;return o}function l(t){return/[\/+]json\b/.test(t)}function f(t){this.req=t,this.xhr=this.req.xhr,this.text="HEAD"!=this.req.method&&(""===this.xhr.responseType||"text"===this.xhr.responseType)||void 0===this.xhr.responseType?this.xhr.responseText:null,this.statusText=this.req.xhr.statusText;var e=this.xhr.status;1223===e&&(e=204),this._setStatusProperties(e),this.header=this.headers=o(this.xhr.getAllResponseHeaders()),this.header["content-type"]=this.xhr.getResponseHeader("content-type"),this._setHeaderProperties(this.header),null===this.text&&t._responseType?this.body=this.xhr.response:this.body="HEAD"!=this.req.method?this._parseBody(this.text?this.text:this.xhr.response):null}function d(t,e){var r=this;this._query=this._query||[],this.method=t,this.url=e,this.header={},this._header={},this.on("end",function(){var t=null,e=null;try{e=new f(r)}catch(e){return t=new Error("Parser is unable to parse the response"),t.parse=!0,t.original=e,r.xhr?(t.rawResponse=void 0===r.xhr.responseType?r.xhr.responseText:r.xhr.response,t.status=r.xhr.status?r.xhr.status:null,t.statusCode=t.status):(t.rawResponse=null,t.status=null),r.callback(t)}r.emit("response",e);var i;try{r._isResponseOK(e)||(i=new Error(e.statusText||"Unsuccessful HTTP response"),i.original=t,i.response=e,i.status=e.status)}catch(t){i=t}i?r.callback(i,e):r.callback(null,e)})}function y(t,e,r){var i=v("DELETE",t);return"function"==typeof e&&(r=e,e=null),e&&i.send(e),r&&i.end(r),i}var m;"undefined"!=typeof window?m=window:"undefined"!=typeof self?m=self:(console.warn("Using browser-only version of superagent in non-browser environment"),m=a);var v=e=t.exports=function(t,r){return"function"==typeof r?new e.Request("GET",t).end(r):1==arguments.length?new e.Request("GET",t):new e.Request(t,r)};e.Request=d,v.getXHR=function(){if(!(!m.XMLHttpRequest||m.location&&"file:"==m.location.protocol&&m.ActiveXObject))return new XMLHttpRequest;try{return new ActiveXObject("Microsoft.XMLHTTP")}catch(t){}try{return new ActiveXObject("Msxml2.XMLHTTP.6.0")}catch(t){}try{return new ActiveXObject("Msxml2.XMLHTTP.3.0")}catch(t){}try{return new ActiveXObject("Msxml2.XMLHTTP")}catch(t){}throw Error("Browser-only verison of superagent could not find XHR")};var w="".trim?function(t){return t.trim()}:function(t){return t.replace(/(^\s*|\s*$)/g,"")};v.serializeObject=i,v.parseString=n,v.types={html:"text/html",json:"application/json",xml:"application/xml",urlencoded:"application/x-www-form-urlencoded",form:"application/x-www-form-urlencoded","form-data":"application/x-www-form-urlencoded"},v.serialize={"application/x-www-form-urlencoded":i,"application/json":JSON.stringify},v.parse={"application/x-www-form-urlencoded":n,"application/json":JSON.parse},_(f.prototype),f.prototype._parseBody=function(t){var e=v.parse[this.type];return this.req._parser?this.req._parser(this,t):(!e&&l(this.type)&&(e=v.parse["application/json"]),e&&t&&(t.length||t instanceof Object)?e(t):null)},f.prototype.toError=function(){var t=this.req,e=t.method,r=t.url,i="cannot "+e+" "+r+" ("+this.status+")",s=new Error(i);return s.status=this.status,s.method=e,s.url=r,s},v.Response=f,u(d.prototype),p(d.prototype),d.prototype.type=function(t){return this.set("Content-Type",v.types[t]||t),this},d.prototype.accept=function(t){return this.set("Accept",v.types[t]||t),this},d.prototype.auth=function(t,e,r){switch("object"==typeof e&&null!==e&&(r=e),r||(r={type:"function"==typeof btoa?"basic":"auto"}),r.type){case"basic":this.set("Authorization","Basic "+btoa(t+":"+e));break;case"auto":this.username=t,this.password=e;break;case"bearer":this.set("Authorization","Bearer "+t)}return this},d.prototype.query=function(t){return"string"!=typeof t&&(t=i(t)),t&&this._query.push(t),this},d.prototype.attach=function(t,e,r){if(e){if(this._data)throw Error("superagent can't mix .send() and .attach()");this._getFormData().append(t,e,r||e.name)}return this},d.prototype._getFormData=function(){return this._formData||(this._formData=new m.FormData),this._formData},d.prototype.callback=function(t,e){if(this._maxRetries&&this._retries++<this._maxRetries&&b(t,e))return this._retry();var r=this._callback;this.clearTimeout(),t&&(this._maxRetries&&(t.retries=this._retries-1),this.emit("error",t)),r(t,e)},d.prototype.crossDomainError=function(){var t=new Error("Request has been terminated\nPossible causes: the network is offline, Origin is not allowed by Access-Control-Allow-Origin, the page is being unloaded, etc.");t.crossDomain=!0,t.status=this.status,t.method=this.method,t.url=this.url,this.callback(t)},d.prototype.buffer=d.prototype.ca=d.prototype.agent=function(){return console.warn("This is not supported in browser version of superagent"),this},d.prototype.pipe=d.prototype.write=function(){throw Error("Streaming is not supported in browser version of superagent")},d.prototype._appendQueryString=function(){var t=this._query.join("&");if(t&&(this.url+=(this.url.indexOf("?")>=0?"&":"?")+t),this._sort){var e=this.url.indexOf("?");if(e>=0){var r=this.url.substring(e+1).split("&");c(this._sort)?r.sort(this._sort):r.sort(),this.url=this.url.substring(0,e)+"?"+r.join("&")}}},d.prototype._isHost=function(t){return t&&"object"==typeof t&&!Array.isArray(t)&&"[object Object]"!==Object.prototype.toString.call(t)},d.prototype.end=function(t){return this._endCalled&&console.warn("Warning: .end() was called twice. This is not supported in superagent"),this._endCalled=!0,this._callback=t||r,this._appendQueryString(),this._end()},d.prototype._end=function(){var t=this,e=this.xhr=v.getXHR(),r=this._formData||this._data;this._setTimeouts(),e.onreadystatechange=function(){var r=e.readyState;if(r>=2&&t._responseTimeoutTimer&&clearTimeout(t._responseTimeoutTimer),4==r){var i;try{i=e.status}catch(t){i=0}if(!i){if(t.timedout||t._aborted)return;return t.crossDomainError()}t.emit("end")}};var i=function(e,r){r.total>0&&(r.percent=r.loaded/r.total*100),r.direction=e,t.emit("progress",r)};if(this.hasListeners("progress"))try{e.onprogress=i.bind(null,"download"),e.upload&&(e.upload.onprogress=i.bind(null,"upload"))}catch(t){}try{this.username&&this.password?e.open(this.method,this.url,!0,this.username,this.password):e.open(this.method,this.url,!0)}catch(t){return this.callback(t)}if(this._withCredentials&&(e.withCredentials=!0),!this._formData&&"GET"!=this.method&&"HEAD"!=this.method&&"string"!=typeof r&&!this._isHost(r)){var s=this._header["content-type"],n=this._serializer||v.serialize[s?s.split(";")[0]:""];!n&&l(s)&&(n=v.serialize["application/json"]),n&&(r=n(r))}for(var o in this.header)null!=this.header[o]&&this.header.hasOwnProperty(o)&&e.setRequestHeader(o,this.header[o]);return this._responseType&&(e.responseType=this._responseType),this.emit("request",this),e.send(void 0!==r?r:null),this},v.get=function(t,e,r){var i=v("GET",t);return"function"==typeof e&&(r=e,e=null),e&&i.query(e),r&&i.end(r),i},v.head=function(t,e,r){var i=v("HEAD",t);return"function"==typeof e&&(r=e,e=null),e&&i.send(e),r&&i.end(r),i},v.options=function(t,e,r){var i=v("OPTIONS",t);return"function"==typeof e&&(r=e,e=null),e&&i.send(e),r&&i.end(r),i},v.del=y,v.delete=y,v.patch=function(t,e,r){var i=v("PATCH",t);return"function"==typeof e&&(r=e,e=null),e&&i.send(e),r&&i.end(r),i},v.post=function(t,e,r){var i=v("POST",t);return"function"==typeof e&&(r=e,e=null),e&&i.send(e),r&&i.end(r),i},v.put=function(t,e,r){var i=v("PUT",t);return"function"==typeof e&&(r=e,e=null),e&&i.send(e),r&&i.end(r),i}}),g=function(t,e){return new Promise(function(r,i){w.get(t).query(e).end(function(t,e){t&&i(t),r(e.body)})})},T=function(t,e){return new Promise(function(r,i){w.post(t).type("form").send(e).end(function(t,e){t&&i(t),r(e.body)})})},x=function(t,e){return new Promise(function(r,i){w.delete(t).query(e).end(function(t,e){t&&i(t),r(e.body)})})},E={doGet:g,doPost:T,doDelete:x},k={};k.exportGetAllPackages=function(){return this.request("GET","/etc/creativeExchange/export/api.packages.json")},k.exportGetPackageStatus=function(t){return this.request("GET","/etc/creativeExchange/export/api.status.json",t)},k.exportDownloadPackage=function(t){return this.request("GET","/etc/creativeExchange/export/api.package.zip",t)},k.exportCreatePackage=function(t){return this.request("POST","/etc/creativeExchange/export/api.create.json",t)},k.exportRemovePackage=function(t){return this.request("DELETE","/etc/creativeExchange/export/api.packages.json",t)},k.importGetAllPackages=function(){return this.request("GET","/etc/creativeExchange/import/api.packages.json")},k.importGetPackageStatus=function(t){return this.request("GET","/etc/creativeExchange/import/api.status.json",t)},k.importUploadPackage=function(t){return this.request("UPLOAD","/etc/creativeExchange/import/api.upload.json",t)},k.importInspectPackage=function(t){return this.request("POST","/etc/creativeExchange/import/api.inspect.json",t)},k.importDryRunPackage=function(t){return this.request("POST","/etc/creativeExchange/import/api.dry_run.json",t)},k.importInstallPackage=function(t){return this.request("POST","/etc/creativeExchange/import/api.install.json",t)},k.importRemovePackage=function(t){return this.request("DELETE","/etc/creativeExchange/import/api.packages.json",t)},k.themeGetAllThemes=function(t){return this.request("GET","/etc/creativeExchange/themes/api.json",t)};var q=k,P=function(t){t=t||{},this.user=t.user,this.password=t.password,this.url=t.url,this.port=t.port};return P.prototype.getUrl=function(){return this.user+":"+this.password+"@"+this.url+":"+this.port},P.prototype.request=function(t,e,r){var i=null;switch(e=this.getUrl()+e,t){case"GET":i=E.doGet;break;case"POST":i=E.doPost;break;case"DELETE":i=E.doDelete}return i(e,r)},P.prototype=Object.assign(P.prototype,q),P}();
var CrEx=function(){"use strict";function t(t,e){return e={exports:{}},t(e,e.exports),e.exports}function e(t){return null!==t&&"object"==typeof t}function r(t){if(t)return i(t)}function i(t){for(var e in r.prototype)t[e]=r.prototype[e];return t}function s(t){return"[object Function]"===(h(t)?Object.prototype.toString.call(t):"")}function n(t){if(t)return o(t)}function o(t){for(var e in n.prototype)t[e]=n.prototype[e];return t}var a="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},u=t(function(t){function e(t){if(t)return r(t)}function r(t){for(var r in e.prototype)t[r]=e.prototype[r];return t}t.exports=e,e.prototype.on=e.prototype.addEventListener=function(t,e){return this._callbacks=this._callbacks||{},(this._callbacks["$"+t]=this._callbacks["$"+t]||[]).push(e),this},e.prototype.once=function(t,e){function r(){this.off(t,r),e.apply(this,arguments)}return r.fn=e,this.on(t,r),this},e.prototype.off=e.prototype.removeListener=e.prototype.removeAllListeners=e.prototype.removeEventListener=function(t,e){if(this._callbacks=this._callbacks||{},0==arguments.length)return this._callbacks={},this;var r=this._callbacks["$"+t];if(!r)return this;if(1==arguments.length)return delete this._callbacks["$"+t],this;for(var i,s=0;s<r.length;s++)if((i=r[s])===e||i.fn===e){r.splice(s,1);break}return this},e.prototype.emit=function(t){this._callbacks=this._callbacks||{};var e=[].slice.call(arguments,1),r=this._callbacks["$"+t];if(r){r=r.slice(0);for(var i=0,s=r.length;i<s;++i)r[i].apply(this,e)}return this},e.prototype.listeners=function(t){return this._callbacks=this._callbacks||{},this._callbacks["$"+t]||[]},e.prototype.hasListeners=function(t){return!!this.listeners(t).length}}),h=e,c=r;r.prototype.clearTimeout=function(){return clearTimeout(this._timer),clearTimeout(this._responseTimeoutTimer),delete this._timer,delete this._responseTimeoutTimer,this},r.prototype.parse=function(t){return this._parser=t,this},r.prototype.responseType=function(t){return this._responseType=t,this},r.prototype.serialize=function(t){return this._serializer=t,this},r.prototype.timeout=function(t){if(!t||"object"!=typeof t)return this._timeout=t,this._responseTimeout=0,this;for(var e in t)switch(e){case"deadline":this._timeout=t.deadline;break;case"response":this._responseTimeout=t.response;break;default:console.warn("Unknown timeout option",e)}return this},r.prototype.retry=function(t){return 0!==arguments.length&&!0!==t||(t=1),t<=0&&(t=0),this._maxRetries=t,this._retries=0,this},r.prototype._retry=function(){return this.clearTimeout(),this.req&&(this.req=null,this.req=this.request()),this._aborted=!1,this.timedout=!1,this._end()},r.prototype.then=function(t,e){if(!this._fullfilledPromise){var r=this;this._endCalled&&console.warn("Warning: superagent request was sent twice, because both .end() and .then() were called. Never call .end() if you use promises"),this._fullfilledPromise=new Promise(function(t,e){r.end(function(r,i){r?e(r):t(i)})})}return this._fullfilledPromise.then(t,e)},r.prototype.catch=function(t){return this.then(void 0,t)},r.prototype.use=function(t){return t(this),this},r.prototype.ok=function(t){if("function"!=typeof t)throw Error("Callback required");return this._okCallback=t,this},r.prototype._isResponseOK=function(t){return!!t&&(this._okCallback?this._okCallback(t):t.status>=200&&t.status<300)},r.prototype.get=function(t){return this._header[t.toLowerCase()]},r.prototype.getHeader=r.prototype.get,r.prototype.set=function(t,e){if(h(t)){for(var r in t)this.set(r,t[r]);return this}return this._header[t.toLowerCase()]=e,this.header[t]=e,this},r.prototype.unset=function(t){return delete this._header[t.toLowerCase()],delete this.header[t],this},r.prototype.field=function(t,e){if(null===t||void 0===t)throw new Error(".field(name, val) name can not be empty");if(this._data&&console.error(".field() can't be used if .send() is used. Please use only .send() or only .field() & .attach()"),h(t)){for(var r in t)this.field(r,t[r]);return this}if(Array.isArray(e)){for(var i in e)this.field(t,e[i]);return this}if(null===e||void 0===e)throw new Error(".field(name, val) val can not be empty");return"boolean"==typeof e&&(e=""+e),this._getFormData().append(t,e),this},r.prototype.abort=function(){return this._aborted?this:(this._aborted=!0,this.xhr&&this.xhr.abort(),this.req&&this.req.abort(),this.clearTimeout(),this.emit("abort"),this)},r.prototype.withCredentials=function(t){return void 0==t&&(t=!0),this._withCredentials=t,this},r.prototype.redirects=function(t){return this._maxRedirects=t,this},r.prototype.toJSON=function(){return{method:this.method,url:this.url,data:this._data,headers:this._header}},r.prototype.send=function(t){var e=h(t),r=this._header["content-type"];if(this._formData&&console.error(".send() can't be used if .attach() or .field() is used. Please use only .send() or only .field() & .attach()"),e&&!this._data)Array.isArray(t)?this._data=[]:this._isHost(t)||(this._data={});else if(t&&this._data&&this._isHost(this._data))throw Error("Can't merge these send calls");if(e&&h(this._data))for(var i in t)this._data[i]=t[i];else"string"==typeof t?(r||this.type("form"),r=this._header["content-type"],this._data="application/x-www-form-urlencoded"==r?this._data?this._data+"&"+t:t:(this._data||"")+t):this._data=t;return!e||this._isHost(t)?this:(r||this.type("json"),this)},r.prototype.sortQuery=function(t){return this._sort=void 0===t||t,this},r.prototype._timeoutError=function(t,e,r){if(!this._aborted){var i=new Error(t+e+"ms exceeded");i.timeout=e,i.code="ECONNABORTED",i.errno=r,this.timedout=!0,this.abort(),this.callback(i)}},r.prototype._setTimeouts=function(){var t=this;this._timeout&&!this._timer&&(this._timer=setTimeout(function(){t._timeoutError("Timeout of ",t._timeout,"ETIME")},this._timeout)),this._responseTimeout&&!this._responseTimeoutTimer&&(this._responseTimeoutTimer=setTimeout(function(){t._timeoutError("Response timeout of ",t._responseTimeout,"ETIMEDOUT")},this._responseTimeout))};var p=s,l=function(t){return t.split(/ *; */).shift()},f=function(t){return t.split(/ *; */).reduce(function(t,e){var r=e.split(/ *= */),i=r.shift(),s=r.shift();return i&&s&&(t[i]=s),t},{})},d=function(t){return t.split(/ *, */).reduce(function(t,e){var r=e.split(/ *; */),i=r[0].slice(1,-1);return t[r[1].split(/ *= */)[1].slice(1,-1)]=i,t},{})},y=function(t,e){return delete t["content-type"],delete t["content-length"],delete t["transfer-encoding"],delete t.host,e&&delete t.cookie,t},m={type:l,params:f,parseLinks:d,cleanHeader:y},_=n;n.prototype.get=function(t){return this.header[t.toLowerCase()]},n.prototype._setHeaderProperties=function(t){var e=t["content-type"]||"";this.type=m.type(e);var r=m.params(e);for(var i in r)this[i]=r[i];this.links={};try{t.link&&(this.links=m.parseLinks(t.link))}catch(t){}},n.prototype._setStatusProperties=function(t){var e=t/100|0;this.status=this.statusCode=t,this.statusType=e,this.info=1==e,this.ok=2==e,this.redirect=3==e,this.clientError=4==e,this.serverError=5==e,this.error=(4==e||5==e)&&this.toError(),this.accepted=202==t,this.noContent=204==t,this.badRequest=400==t,this.unauthorized=401==t,this.notAcceptable=406==t,this.forbidden=403==t,this.notFound=404==t};var v=["ECONNRESET","ETIMEDOUT","EADDRINFO","ESOCKETTIMEDOUT"],b=function(t,e){return!!(t&&t.code&&~v.indexOf(t.code))||(!!(e&&e.status&&e.status>=500)||(!!(t&&"timeout"in t&&"ECONNABORTED"==t.code)||!!(t&&"crossDomain"in t)))},g=t(function(t,e){function r(){}function i(t){if(!h(t))return t;var e=[];for(var r in t)s(e,r,t[r]);return e.join("&")}function s(t,e,r){if(null!=r)if(Array.isArray(r))r.forEach(function(r){s(t,e,r)});else if(h(r))for(var i in r)s(t,e+"["+i+"]",r[i]);else t.push(encodeURIComponent(e)+"="+encodeURIComponent(r));else null===r&&t.push(encodeURIComponent(e))}function n(t){for(var e,r,i={},s=t.split("&"),n=0,o=s.length;n<o;++n)e=s[n],r=e.indexOf("="),-1==r?i[decodeURIComponent(e)]="":i[decodeURIComponent(e.slice(0,r))]=decodeURIComponent(e.slice(r+1));return i}function o(t){var e,r,i,s,n=t.split(/\r?\n/),o={};n.pop();for(var a=0,u=n.length;a<u;++a)r=n[a],e=r.indexOf(":"),i=r.slice(0,e).toLowerCase(),s=g(r.slice(e+1)),o[i]=s;return o}function l(t){return/[\/+]json\b/.test(t)}function f(t){this.req=t,this.xhr=this.req.xhr,this.text="HEAD"!=this.req.method&&(""===this.xhr.responseType||"text"===this.xhr.responseType)||void 0===this.xhr.responseType?this.xhr.responseText:null,this.statusText=this.req.xhr.statusText;var e=this.xhr.status;1223===e&&(e=204),this._setStatusProperties(e),this.header=this.headers=o(this.xhr.getAllResponseHeaders()),this.header["content-type"]=this.xhr.getResponseHeader("content-type"),this._setHeaderProperties(this.header),null===this.text&&t._responseType?this.body=this.xhr.response:this.body="HEAD"!=this.req.method?this._parseBody(this.text?this.text:this.xhr.response):null}function d(t,e){var r=this;this._query=this._query||[],this.method=t,this.url=e,this.header={},this._header={},this.on("end",function(){var t=null,e=null;try{e=new f(r)}catch(e){return t=new Error("Parser is unable to parse the response"),t.parse=!0,t.original=e,r.xhr?(t.rawResponse=void 0===r.xhr.responseType?r.xhr.responseText:r.xhr.response,t.status=r.xhr.status?r.xhr.status:null,t.statusCode=t.status):(t.rawResponse=null,t.status=null),r.callback(t)}r.emit("response",e);var i;try{r._isResponseOK(e)||(i=new Error(e.statusText||"Unsuccessful HTTP response"),i.original=t,i.response=e,i.status=e.status)}catch(t){i=t}i?r.callback(i,e):r.callback(null,e)})}function y(t,e,r){var i=v("DELETE",t);return"function"==typeof e&&(r=e,e=null),e&&i.send(e),r&&i.end(r),i}var m;"undefined"!=typeof window?m=window:"undefined"!=typeof self?m=self:(console.warn("Using browser-only version of superagent in non-browser environment"),m=a);var v=e=t.exports=function(t,r){return"function"==typeof r?new e.Request("GET",t).end(r):1==arguments.length?new e.Request("GET",t):new e.Request(t,r)};e.Request=d,v.getXHR=function(){if(!(!m.XMLHttpRequest||m.location&&"file:"==m.location.protocol&&m.ActiveXObject))return new XMLHttpRequest;try{return new ActiveXObject("Microsoft.XMLHTTP")}catch(t){}try{return new ActiveXObject("Msxml2.XMLHTTP.6.0")}catch(t){}try{return new ActiveXObject("Msxml2.XMLHTTP.3.0")}catch(t){}try{return new ActiveXObject("Msxml2.XMLHTTP")}catch(t){}throw Error("Browser-only verison of superagent could not find XHR")};var g="".trim?function(t){return t.trim()}:function(t){return t.replace(/(^\s*|\s*$)/g,"")};v.serializeObject=i,v.parseString=n,v.types={html:"text/html",json:"application/json",xml:"application/xml",urlencoded:"application/x-www-form-urlencoded",form:"application/x-www-form-urlencoded","form-data":"application/x-www-form-urlencoded"},v.serialize={"application/x-www-form-urlencoded":i,"application/json":JSON.stringify},v.parse={"application/x-www-form-urlencoded":n,"application/json":JSON.parse},_(f.prototype),f.prototype._parseBody=function(t){var e=v.parse[this.type];return this.req._parser?this.req._parser(this,t):(!e&&l(this.type)&&(e=v.parse["application/json"]),e&&t&&(t.length||t instanceof Object)?e(t):null)},f.prototype.toError=function(){var t=this.req,e=t.method,r=t.url,i="cannot "+e+" "+r+" ("+this.status+")",s=new Error(i);return s.status=this.status,s.method=e,s.url=r,s},v.Response=f,u(d.prototype),c(d.prototype),d.prototype.type=function(t){return this.set("Content-Type",v.types[t]||t),this},d.prototype.accept=function(t){return this.set("Accept",v.types[t]||t),this},d.prototype.auth=function(t,e,r){switch("object"==typeof e&&null!==e&&(r=e),r||(r={type:"function"==typeof btoa?"basic":"auto"}),r.type){case"basic":this.set("Authorization","Basic "+btoa(t+":"+e));break;case"auto":this.username=t,this.password=e;break;case"bearer":this.set("Authorization","Bearer "+t)}return this},d.prototype.query=function(t){return"string"!=typeof t&&(t=i(t)),t&&this._query.push(t),this},d.prototype.attach=function(t,e,r){if(e){if(this._data)throw Error("superagent can't mix .send() and .attach()");this._getFormData().append(t,e,r||e.name)}return this},d.prototype._getFormData=function(){return this._formData||(this._formData=new m.FormData),this._formData},d.prototype.callback=function(t,e){if(this._maxRetries&&this._retries++<this._maxRetries&&b(t,e))return this._retry();var r=this._callback;this.clearTimeout(),t&&(this._maxRetries&&(t.retries=this._retries-1),this.emit("error",t)),r(t,e)},d.prototype.crossDomainError=function(){var t=new Error("Request has been terminated\nPossible causes: the network is offline, Origin is not allowed by Access-Control-Allow-Origin, the page is being unloaded, etc.");t.crossDomain=!0,t.status=this.status,t.method=this.method,t.url=this.url,this.callback(t)},d.prototype.buffer=d.prototype.ca=d.prototype.agent=function(){return console.warn("This is not supported in browser version of superagent"),this},d.prototype.pipe=d.prototype.write=function(){throw Error("Streaming is not supported in browser version of superagent")},d.prototype._appendQueryString=function(){var t=this._query.join("&");if(t&&(this.url+=(this.url.indexOf("?")>=0?"&":"?")+t),this._sort){var e=this.url.indexOf("?");if(e>=0){var r=this.url.substring(e+1).split("&");p(this._sort)?r.sort(this._sort):r.sort(),this.url=this.url.substring(0,e)+"?"+r.join("&")}}},d.prototype._isHost=function(t){return t&&"object"==typeof t&&!Array.isArray(t)&&"[object Object]"!==Object.prototype.toString.call(t)},d.prototype.end=function(t){return this._endCalled&&console.warn("Warning: .end() was called twice. This is not supported in superagent"),this._endCalled=!0,this._callback=t||r,this._appendQueryString(),this._end()},d.prototype._end=function(){var t=this,e=this.xhr=v.getXHR(),r=this._formData||this._data;this._setTimeouts(),e.onreadystatechange=function(){var r=e.readyState;if(r>=2&&t._responseTimeoutTimer&&clearTimeout(t._responseTimeoutTimer),4==r){var i;try{i=e.status}catch(t){i=0}if(!i){if(t.timedout||t._aborted)return;return t.crossDomainError()}t.emit("end")}};var i=function(e,r){r.total>0&&(r.percent=r.loaded/r.total*100),r.direction=e,t.emit("progress",r)};if(this.hasListeners("progress"))try{e.onprogress=i.bind(null,"download"),e.upload&&(e.upload.onprogress=i.bind(null,"upload"))}catch(t){}try{this.username&&this.password?e.open(this.method,this.url,!0,this.username,this.password):e.open(this.method,this.url,!0)}catch(t){return this.callback(t)}if(this._withCredentials&&(e.withCredentials=!0),!this._formData&&"GET"!=this.method&&"HEAD"!=this.method&&"string"!=typeof r&&!this._isHost(r)){var s=this._header["content-type"],n=this._serializer||v.serialize[s?s.split(";")[0]:""];!n&&l(s)&&(n=v.serialize["application/json"]),n&&(r=n(r))}for(var o in this.header)null!=this.header[o]&&this.header.hasOwnProperty(o)&&e.setRequestHeader(o,this.header[o]);return this._responseType&&(e.responseType=this._responseType),this.emit("request",this),e.send(void 0!==r?r:null),this},v.get=function(t,e,r){var i=v("GET",t);return"function"==typeof e&&(r=e,e=null),e&&i.query(e),r&&i.end(r),i},v.head=function(t,e,r){var i=v("HEAD",t);return"function"==typeof e&&(r=e,e=null),e&&i.send(e),r&&i.end(r),i},v.options=function(t,e,r){var i=v("OPTIONS",t);return"function"==typeof e&&(r=e,e=null),e&&i.send(e),r&&i.end(r),i},v.del=y,v.delete=y,v.patch=function(t,e,r){var i=v("PATCH",t);return"function"==typeof e&&(r=e,e=null),e&&i.send(e),r&&i.end(r),i},v.post=function(t,e,r){var i=v("POST",t);return"function"==typeof e&&(r=e,e=null),e&&i.send(e),r&&i.end(r),i},v.put=function(t,e,r){var i=v("PUT",t);return"function"==typeof e&&(r=e,e=null),e&&i.send(e),r&&i.end(r),i}}),w=function(t,e){return new Promise(function(r,i){g.get(t).query(e).buffer(!0).end(function(t,e){console.log(e.text),t&&i(t),r(e.body)})})},T=function(t,e){return new Promise(function(r,i){g.post(t).type("form").send(e).end(function(t,e){t&&i(t),r(e.body)})})},x=function(t,e){return new Promise(function(r,i){g.delete(t).query(e).end(function(t,e){t&&i(t),r(e.body)})})},E=function(t,e){return new Promise(function(r,i){g.post(t).attach("file",e.file).end(function(t,e){t&&i(t),r(e.body)})})},k={doGet:w,doPost:T,doDelete:x,doUpload:E},q={};q.exportGetAllPackages=function(){return this.request("GET","/etc/creativeExchange/export/api.packages.json")},q.exportGetPackageStatus=function(t){return this.request("GET","/etc/creativeExchange/export/api.status.json",t)},q.exportDownloadPackage=function(t){return this.request("GET","/etc/creativeExchange/export/api.package.zip",t)},q.exportCreatePackage=function(t){return this.request("POST","/etc/creativeExchange/export/api.create.json",t)},q.exportRemovePackage=function(t){return this.request("DELETE","/etc/creativeExchange/export/api.packages.json",t)},q.importGetAllPackages=function(){return this.request("GET","/etc/creativeExchange/import/api.packages.json")},q.importGetPackageStatus=function(t){return this.request("GET","/etc/creativeExchange/import/api.status.json",t)},q.importUploadPackage=function(t){return this.request("UPLOAD","/etc/creativeExchange/import/api.upload.json",t)},q.importDownloadPackage=function(t){return this.request("GET","/etc/creativeExchange/import/api.package.zip",t)},q.importInspectPackage=function(t){return this.request("POST","/etc/creativeExchange/import/api.inspect.json",t)},q.importDryRunPackage=function(t){return this.request("POST","/etc/creativeExchange/import/api.dry_run.json",t)},q.importInstallPackage=function(t){return this.request("POST","/etc/creativeExchange/import/api.install.json",t)},q.importRemovePackage=function(t){return this.request("DELETE","/etc/creativeExchange/import/api.packages.json",t)},q.themesGetAllThemes=function(t){return this.request("GET","/etc/creativeExchange/themes/api.json",t)},q.themesCheckProgress=function(t){return this.request("GET","/etc/creativeExchange/themes/api.json",t)};var P=q,O=function(t){t=t||{},this.user=t.user,this.password=t.password,this.url=t.url,this.port=t.port};return O.prototype.getUrl=function(){return this.user+":"+this.password+"@"+this.url+":"+this.port},O.prototype.request=function(t,e,r){var i=null;switch(e=this.getUrl()+e,t){case"GET":i=k.doGet;break;case"POST":i=k.doPost;break;case"DELETE":i=k.doDelete;break;case"UPLOAD":i=k.doUpload}return i(e,r)},O.prototype=Object.assign(O.prototype,P),O}();

@@ -36,2 +36,6 @@ var request = require('./request');

api.importDownloadPackage = function (args) {
return this.request('GET', '/etc/creativeExchange/import/api.package.zip', args);
};
api.importInspectPackage = function (args) {

@@ -52,4 +56,8 @@ return this.request('POST', '/etc/creativeExchange/import/api.inspect.json', args);

};
gi
api.themesGetAllThemes = function (args) {
return this.request('GET', '/etc/creativeExchange/themes/api.json', args);
};
api.themeGetAllThemes = function (args) {
api.themesCheckProgress = function (args) {
return this.request('GET', '/etc/creativeExchange/themes/api.json', args);

@@ -56,0 +64,0 @@ };

@@ -30,2 +30,5 @@ var api = require('./api');

break;
case 'UPLOAD':
req = request.doUpload;
break;
}

@@ -32,0 +35,0 @@

@@ -8,3 +8,5 @@ var request = require('superagent');

.query(args)
.buffer(true)
.end(function (err, res) {
console.log(res.text);
if (err) reject(err);

@@ -41,6 +43,19 @@ resolve(res.body);

var doUpload = function(url, args) {
return new Promise(function (resolve, reject) {
request
.post(url)
.attach('file', args['file'])
.end(function (err, res) {
if (err) reject(err);
resolve(res.body);
});
});
}
module.exports = {
doGet: doGet,
doPost: doPost,
doDelete: doDelete
doDelete: doDelete,
doUpload: doUpload
};
{
"name": "crex",
"version": "0.3.0",
"version": "0.4.0",
"description": "Creative Exchange SDK for Javascript",

@@ -14,3 +14,3 @@ "author": "Mateusz Luczak <mateusz.luczak@outlook.com>",

"build:browser": "rollup -c rollup.config.browser.js",
"test": "mocha test/**"
"test": "mocha test/**/*.js"
},

@@ -17,0 +17,0 @@ "devDependencies": {

@@ -0,1 +1,3 @@

var fs = require('fs');
var path = require('path');
var chai = require('chai');

@@ -48,2 +50,18 @@ var chaiAsPromised = require("chai-as-promised");

describe('#uploadPackage', function() {
it('should upload status', function() {
return expect(crex.importUploadPackage({
'file': fs.createReadStream(path.resolve(__dirname, 'test.zip'))
})).to.eventually.be.a('object');
});
});
describe('#downloadPackage', function() {
it('should upload status', function() {
return expect(crex.importDownloadPackage({
'id': '3eeb6fb2-df64-4764-8d5d-7ee6746dbbdd'
})).to.eventually.be.a('object');
});
});
describe('#deletePackage', function() {

@@ -50,0 +68,0 @@ it('should remove package', function() {

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