react-gui-builder
Version:
Structor - React UI Builder
1 lines • 6.52 kB
JavaScript
;function _interopRequireDefault(t){return t&&t.__esModule?t:{default:t}}function setAuthenticationToken(t){authenticationToken=t}function post(t,e){return new Promise(function(o,s){var n={uri:t,headers:{Accept:"application/json","Content-Type":"application/json;charset=UTF-8","X-Auth-Token":authenticationToken},method:"POST",json:!0,body:e,followAllRedirects:!1};try{(0,_request2.default)(n,function(n,r,a){if(r)if(200!==r.statusCode)r.statusCode>=301&&r.statusCode<=302?post(r.headers.location,e).then(function(t){o(t)}).catch(function(t){s(t)}):s(413===r.statusCode?"The files content is too large. Make sure that overall size of posted files is less than 1M.":403===r.statusCode?"User account is not signed in. Requested operation is forbidden. Please sign in to Structor Market.":401===r.statusCode?"User account is not authenticated. Please sign in to Structor Market.":502===r.statusCode?"Connection to Structor Market server can not be established. Please try a little bit later.":"Got error code "+r.statusCode+" for "+t+". Status: "+r.statusMessage+". Message: "+JSON.stringify(a));else if(n)s("Error connection to "+t+". "+(n.message?n.message:n));else if(a.error===!0){var i="Error: ";a.errors&&a.errors.length>0&&a.errors.map(function(t){i+=t+", "}),s(i.substr(0,i.length-2))}else o(a);else s("Error connection to "+t)})}catch(t){s(t.message?t.message:t)}})}function get(t){return new Promise(function(e,o){var s={headers:{Accept:"application/json","X-Auth-Token":authenticationToken},uri:t,method:"GET",json:!0,followAllRedirects:!1};try{(0,_request2.default)(s,function(s,n,r){n?200!==n.statusCode?n.statusCode>=301&&n.statusCode<=302?get(n.headers.location).then(function(t){e(t)}).catch(function(t){o(t)}):o(403===n.statusCode?"User account is not signed in. Requested operation is forbidden. Please sign in to Structor Market.":401===n.statusCode?"User account is not authenticated. Please sign in to Structor Market.":502===n.statusCode?"Connection to Structor Market server can not be established. Please try a little bit later.":"Got error code "+n.statusCode+" for "+t+". Status: "+n.statusMessage+". Message: "+JSON.stringify(r)):s?o("Error connection to "+t+". "+(s.message?s.message:s)):e(r):o("Error connection to "+t)})}catch(t){o(t.message?t.message:t)}})}function getText(t){return new Promise(function(e,o){var s={headers:{"X-Auth-Token":authenticationToken},uri:t,method:"GET",json:!1};try{(0,_request2.default)(s,function(s,n,r){n?200!==n.statusCode?n.statusCode>=301&&n.statusCode<=302?getText(n.headers.location).then(function(t){e(t)}).catch(function(t){o(t)}):o(403===n.statusCode?"User account is not signed in. Requested operation is forbidden. Please sign in to Structor Market.":401===n.statusCode?"User account is not authenticated. Please sign in to Structor Market.":502===n.statusCode?"Connection to Structor Market server can not be established. Please try a little bit later.":"Got error code "+n.statusCode+" for "+t+". Status: "+n.statusMessage+". Message: "+JSON.stringify(r)):s?o("Error connection to "+t+". "+(s.message?s.message:s)):e(r):o("Error connection to "+t)})}catch(t){o(t.message?t.message:t)}})}function download(t,e){return new Promise(function(o,s){var n={uri:t,headers:{"Content-type":"application/json","X-Auth-Token":authenticationToken},method:"POST",body:JSON.stringify(e),encoding:null};try{(0,_request2.default)(n,function(n,r,a){r?200!==r.statusCode?r.statusCode>=301&&r.statusCode<=302?download(r.headers.location,e).then(function(t){o(t)}).catch(function(t){s(t)}):s(403===r.statusCode?"User account is not signed in. Requested operation is forbidden. Please sign in to Structor Market.":401===r.statusCode?"User account is not authenticated. Please sign in to Structor Market.":502===r.statusCode?"Connection to Structor Market server can not be established. Please try a little bit later.":"Got error code "+r.statusCode+" for "+t+". Status: "+r.statusMessage+". Message: "+JSON.stringify(a)):n?s("Error connection to "+t+". "+(n.message?n.message:n)):o(a):s("Error connection to "+t)})}catch(t){s(t.message?t.message:t)}})}function downloadGet(t){return new Promise(function(e,o){var s={uri:t,method:"GET",strictSSL:!1,headers:{"User-Agent":"request"},encoding:null};try{(0,_request2.default)(s,function(s,n,r){n?200!==n.statusCode?n.statusCode>=301&&n.statusCode<=302?downloadGet(n.headers.location).then(function(t){e(t)}).catch(function(t){o(t)}):o(403===n.statusCode?"User account is not signed in. Requested operation is forbidden.":401===n.statusCode?"User account is not authenticated.":502===n.statusCode?"Connection to Structor Market server can not be established. Please try a little bit later.":"Got error code "+n.statusCode+" for "+t+". Error: "+n.statusMessage):s?o("Error connection to "+t+". "+(s.message?s.message:s)):e(r):o("Error connection to "+t)})}catch(t){o(t.message?t.message:t)}})}function uploadFile(t,e,o){return new Promise(function(s,n){var r={uri:t,headers:{Accept:"application/json","Content-Type":"application/json;charset=UTF-8","X-Auth-Token":authenticationToken},method:"POST",followAllRedirects:!1,formData:{}};r.formData[o]=_fsExtra2.default.createReadStream(e);try{(0,_request2.default)(r,function(e,o,r){if(o)if(200!==o.statusCode)o.statusCode>=301&&o.statusCode<=302?post(o.headers.location,requestBody).then(function(t){s(t)}).catch(function(t){n(t)}):n(403===o.statusCode?"User account is not signed in. Requested operation is forbidden. Please sign in to Structor Market.":401===o.statusCode?"User account is not authenticated. Please sign in to Structor Market.":502===o.statusCode?"Connection to Structor Market server can not be established. Please try a little bit later.":"Got error code "+o.statusCode+" for "+t+". Status: "+o.statusMessage+". Message: "+JSON.stringify(r));else if(e)n("Error connection to "+t+". "+(e.message?e.message:e));else if(r.error===!0){var a="Error: ";r.errors&&r.errors.length>0&&r.errors.map(function(t){a+=t+", "}),n(a.substr(0,a.length-2))}else s(r);else n("Error connection to "+t)})}catch(t){n(t.message?t.message:t)}})}Object.defineProperty(exports,"__esModule",{value:!0}),exports.setAuthenticationToken=setAuthenticationToken,exports.post=post,exports.get=get,exports.getText=getText,exports.download=download,exports.downloadGet=downloadGet,exports.uploadFile=uploadFile;var _fsExtra=require("fs-extra"),_fsExtra2=_interopRequireDefault(_fsExtra),_request=require("request"),_request2=_interopRequireDefault(_request),authenticationToken=null;