UNPKG

34.1 kBJavaScriptView Raw
1!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).h54s=e()}}((function(){return function e(t,s,o){function r(a,i){if(!s[a]){if(!t[a]){var l="function"==typeof require&&require;if(!i&&l)return l(a,!0);if(n)return n(a,!0);var c=new Error("Cannot find module '"+a+"'");throw c.code="MODULE_NOT_FOUND",c}var u=s[a]={exports:{}};t[a][0].call(u.exports,(function(e){return r(t[a][1][e]||e)}),u,u.exports,e,t,s,o)}return s[a].exports}for(var n="function"==typeof require&&require,a=0;a<o.length;a++)r(o[a]);return r}({1:[function(e,t,s){function o(e,t,s){Error.captureStackTrace&&Error.captureStackTrace(this),this.message=t,this.type=e,this.status=s}o.prototype=Object.create(Error.prototype,{constructor:{configurable:!1,enumerable:!1,writable:!1,value:o},name:{configurable:!1,enumerable:!1,writable:!1,value:"h54sError"}}),t.exports=o},{}],2:[function(e,t,s){const o=e("../error.js");function r(e,t){this._files={},r.prototype.add.call(this,e,t)}r.prototype.add=function(e,t){if(!e||!t)throw new o("argumentError","Missing arguments");if(!(e instanceof File||e instanceof Blob))throw new o("argumentError","First argument must be instance of File object");if("string"!=typeof t)throw new o("argumentError","Second argument must be string");if(!isNaN(t[t.length-1]))throw new o("argumentError","Macro name cannot have number at the end");this._files[t]=["FILE",e]},t.exports=r},{"../error.js":1}],3:[function(e,t,s){const o=e("./error.js"),r={v9:{url:"/SASStoredProcess/do",loginUrl:"/SASLogon/login",logoutUrl:"/SASStoredProcess/do?_action=logoff",RESTAuthLoginUrl:"/SASLogon/v1/tickets"},viya:{url:"/SASJobExecution/",loginUrl:"/SASLogon/login.do",logoutUrl:"/SASLogon/logout.do?",RESTAuthLoginUrl:""}},n=t.exports=function(t){if(this.sasVersion=t&&t.sasVersion||"v9",this.debug=t&&t.debug||!1,this.metadataRoot=t&&t.metadataRoot||"",this.url=r[this.sasVersion].url,this.loginUrl=r[this.sasVersion].loginUrl,this.logoutUrl=r[this.sasVersion].logoutUrl,this.RESTauth=!1,this.RESTauthLoginUrl=r[this.sasVersion].RESTAuthLoginUrl,this.retryAfterLogin=!0,this.maxXhrRetries=5,this.ajaxTimeout=t&&t.ajaxTimeout||3e5,this.useMultipartFormData=t&&t.useMultipartFormData||!0,this.csrf="",this.isViya="viya"===this.sasVersion,this.remoteConfigUpdateCallbacks=[],this._pendingCalls=[],this._customPendingCalls=[],this._disableCalls=!1,this._ajax=e("./methods/ajax.js")(),s.call(this,t),t&&t.isRemoteConfig){const e=this;this._disableCalls=!0,this._ajax.get("h54sConfig.json").success((function(o){const r=JSON.parse(o.responseText),n=Object.assign({},t).metadataRoot;for(let e in r)r.hasOwnProperty(e)&&"isRemoteConfig"!==e&&(t[e]=r[e]);s.call(e,t);for(let t=0,s=e.remoteConfigUpdateCallbacks.length;t<s;t++){(0,e.remoteConfigUpdateCallbacks[t])()}for(e._disableCalls=!1;e._pendingCalls.length>0;){const t=e._pendingCalls.shift(),s=t.options.sasProgram,o=t.options.callback,r=t.params;r._debug=e.debug?131:0,e.metadataRoot&&-1===r._program.indexOf(e.metadataRoot)&&(r._program=e.metadataRoot.replace(/\/?$/,"/")+r._program.replace(n,"").replace(/^\//,"")),r._debug=e.debug?131:0,e.call(s,null,o,r)}for(;e._customPendingCalls.length>0;){const t=e._customPendingCalls.shift(),s=t.callMethod,o=t._url,r=t.options;e.metadataRoot&&r.params&&-1===r.params._program.indexOf(e.metadataRoot)&&(r.params._program=e.metadataRoot.replace(/\/?$/,"/")+r.params._program.replace(n,"").replace(/^\//,"")),r.params&&(r.params._debug=e.debug?131:0),e.managedRequest(s,o,r)}})).error((function(e){throw new o("ajaxError","Remote config file cannot be loaded. Http status code: "+e.status)}))}function s(e){if(e){if("object"!=typeof e)throw new o("argumentError","First parameter should be config object");for(let t in e)e.hasOwnProperty(t)&&("url"!==t&&"loginUrl"!==t||"/"===e[t].charAt(0)||(e[t]="/"+e[t]),this[t]=e[t]);e.hostUrl&&("/"===e.hostUrl.charAt(e.hostUrl.length-1)&&(e.hostUrl=e.hostUrl.slice(0,-1)),this.hostUrl=e.hostUrl,this.url.includes(this.hostUrl)||(this.url=e.hostUrl+this.url),this.loginUrl.includes(this.hostUrl)||(this.loginUrl=e.hostUrl+this.loginUrl),this.RESTauthLoginUrl.includes(this.hostUrl)||(this.RESTauthLoginUrl=e.hostUrl+this.RESTauthLoginUrl)),this._ajax.setTimeout(this.ajaxTimeout)}else this._ajax.setTimeout(this.ajaxTimeout)}};n.version="2.2.5",n.prototype=e("./methods"),n.Tables=e("./tables"),n.Files=e("./files"),n.SasData=e("./sasData.js"),n.fromSasDateTime=e("./methods/utils.js").fromSasDateTime,n.toSasDateTime=e("./tables/utils.js").toSasDateTime,e("./ie_polyfills.js")},{"./error.js":1,"./files":2,"./ie_polyfills.js":4,"./methods":7,"./methods/ajax.js":6,"./methods/utils.js":8,"./sasData.js":9,"./tables":10,"./tables/utils.js":11}],4:[function(e,t,s){t.exports=(Object.create||(Object.create=function(e,t){if(void 0!==t)throw"The multiple-argument version of Object.create is not provided by this browser and cannot be shimmed.";function s(){}return s.prototype=e,new s}),Object.keys||(Object.keys=function(){"use strict";var e=Object.prototype.hasOwnProperty,t=!{toString:null}.propertyIsEnumerable("toString"),s=["toString","toLocaleString","valueOf","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","constructor"],o=s.length;return function(r){if("object"!=typeof r&&("function"!=typeof r||null===r))throw new TypeError("Object.keys called on non-object");var n,a,i=[];for(n in r)e.call(r,n)&&i.push(n);if(t)for(a=0;a<o;a++)e.call(r,s[a])&&i.push(s[a]);return i}}()),void(Array.prototype.lastIndexOf||(Array.prototype.lastIndexOf=function(e){"use strict";if(null==this)throw new TypeError;var t,s,o=Object(this),r=o.length>>>0;if(0===r)return-1;for(t=r-1,arguments.length>1&&((t=Number(arguments[1]))!=t?t=0:0!==t&&t!=1/0&&t!=-1/0&&(t=(t>0||-1)*Math.floor(Math.abs(t)))),s=t>=0?Math.min(t,r-1):r-Math.abs(t);s>=0;s--)if(s in o&&o[s]===e)return s;return-1}))),window.NodeList&&!NodeList.prototype.forEach&&(NodeList.prototype.forEach=Array.prototype.forEach)},{}],5:[function(e,t,s){const o={applicationLogs:[],debugData:[],sasErrors:[],failedRequests:[]},r=100,n=20,a=20,i=100;t.exports.get={getSasErrors:function(){return o.sasErrors},getApplicationLogs:function(){return o.applicationLogs},getDebugData:function(){return o.debugData},getFailedRequests:function(){return o.failedRequests},getAllLogs:function(){return{sasErrors:o.sasErrors,applicationLogs:o.applicationLogs,debugData:o.debugData,failedRequests:o.failedRequests}}},t.exports.clear={clearApplicationLogs:function(){o.applicationLogs.splice(0,o.applicationLogs.length)},clearDebugData:function(){o.debugData.splice(0,o.debugData.length)},clearSasErrors:function(){o.sasErrors.splice(0,o.sasErrors.length)},clearFailedRequests:function(){o.failedRequests.splice(0,o.failedRequests.length)},clearAllLogs:function(){this.clearApplicationLogs(),this.clearDebugData(),this.clearSasErrors(),this.clearFailedRequests()}},t.exports.addApplicationLog=function(e,t){if("blank"===e)return;const s={message:e,time:new Date,sasProgram:t};o.applicationLogs.push(s),o.applicationLogs.length>r&&o.applicationLogs.shift()},t.exports.addDebugData=function(e,t,s,r){o.debugData.push({debugHtml:e,debugText:t,sasProgram:s,params:r,time:new Date}),o.debugData.length>n&&o.debugData.shift()},t.exports.addFailedRequest=function(e,t,s){o.failedRequests.push({responseHtml:e,responseText:t,sasProgram:s,time:new Date}),o.failedRequests.length>a&&o.failedRequests.shift()},t.exports.addSasErrors=function(e){for(o.sasErrors=o.sasErrors.concat(e);o.sasErrors.length>i;)o.sasErrors.shift()}},{}],6:[function(e,t,s){t.exports=function(){let e,t=3e4;const s=function(s,o,r,n,a={}){const i={success:function(){},error:function(){}},l=new XMLHttpRequest("MSXML2.XMLHTTP.3.0");return l.open(s,o,!0),n||(a["Content-Type"]?l.setRequestHeader("Content-Type",a["Content-Type"]):l.setRequestHeader("Content-Type","application/x-www-form-urlencoded")),Object.keys(a).forEach(e=>{"Content-Type"!==e&&l.setRequestHeader(e,a[e])}),l.onreadystatechange=function(){4===l.readyState&&(clearTimeout(e),l.status>=200&&l.status<300?i.success.call(i,l):i.error.call(i,l))},t>0&&(e=setTimeout((function(){l.abort()}),t)),l.send(r),{success:function(e){return i.success=e,this},error:function(e){return i.error=e,this}}},o=function(e){const t=[];for(let s in e)if(e.hasOwnProperty(s))if(e[s]instanceof Array)for(let o=0,r=e[s].length;o<r;o++)t.push(encodeURIComponent(s)+"="+encodeURIComponent(e[s][o]));else t.push(encodeURIComponent(s)+"="+encodeURIComponent(e[s]));return t.join("&")},r=function(e){let t=new FormData;for(let s in e)if(e.hasOwnProperty(s))if(e[s]instanceof Array&&"file"!==s)for(let o=0,r=e[s].length;o<r;o++)t.append(s,e[s][o]);else"file"===s?t.append(s,e[s][0],e[s][1]):t.append(s,e[s]);return t};return{get:function(e,t,r,n){let a;"object"==typeof t&&(a=o(t));return s("GET",a?e+"?"+a:e,null,r,n)},post:function(e,t,n,a){let i=t;return"object"==typeof t&&(i=n?r(t):o(t)),s("POST",e,i,n,a)},put:function(e,t,o,n){let a=t;return"object"==typeof t&&o&&(a=r(t)),s("PUT",e,a,o,n)},delete:function(e,t,o,r){return s("DELETE",e,t,null,r)},patch:function(e,t,o,n){let a=t;return"object"==typeof t&&o&&(a=r(t)),s("PATCH",e,a,o,n)},setTimeout:function(e){t=e},serialize:o}}},{}],7:[function(e,t,s){const o=e("../error.js"),r=e("../logs.js"),n=e("../tables"),a=e("../sasData.js"),i=e("../files");function l(e,t,s){const o=this,n={_service:"default",username:e,password:t};for(let e in this._aditionalLoginParams)n[e]=this._aditionalLoginParams[e];function a(e){449!=e.status?(r.addApplicationLog("Login failed with status code: "+e.status),s(e.status)):i(e)}function i(e){if(3==++o._loginAttempts)return s(-2);if(o._utils.needToLogin.call(o,e))if(o._loginChanged||o._isNewLoginPage&&!o._aditionalLoginParams){delete o._loginChanged;const t=e.responseText.match(/<input.*"hidden"[^>]*>/g);t&&t.forEach((function(e){const t=e.match(/name="([^"]*)"\svalue="([^"]*)/);n[t[1]]=t[2]})),o._ajax.post(o.loginUrl,n).success((function(){o._ajax.get(o.url).success(i).error(a)})).error(a)}else r.addApplicationLog("Wrong username or password"),s(-1);else for(o._disableCalls=!1,s(e.status);o._pendingCalls.length>0;){const e=o._pendingCalls.shift(),t=e.method||o.call.bind(o),s=e.options.sasProgram,r=e.options.callback,n=e.params;n._debug=o.debug?131:0,o.retryAfterLogin&&t(s,null,r,n)}}this._loginAttempts=0,this._ajax.post(this.loginUrl,n).success(i).error(a)}function c(e,t,s){const o=this,n={username:e,password:t};this._ajax.post(this.RESTauthLoginUrl,n).success((function(e){const t=e.getResponseHeader("Location");o._ajax.post(t,{service:o.url}).success((function(e){-1===o.url.indexOf("?")?o.url+="?ticket="+e.responseText:-1!==o.url.indexOf("ticket")?o.url=o.url.replace(/ticket=[^&]+/,"ticket="+e.responseText):o.url+="&ticket="+e.responseText,s(e.status)})).error((function(e){r.addApplicationLog("Login failed with status code: "+e.status),s(e.status)}))})).error((function(e){"error.authentication.credentials.bad"===e.responseText?s(-1):(r.addApplicationLog("Login failed with status code: "+e.status),s(e.status))}))}t.exports.call=function(e,t,s,l){const c=this;let u=0;const p=this.debug,g=this.csrf;if(!s||"function"!=typeof s)throw new o("argumentError","You must provide a callback");if(!e)throw new o("argumentError","You must provide Sas program file path");if("string"!=typeof e)throw new o("argumentError","First parameter should be string");if(!1===this.useMultipartFormData&&!(t instanceof n))throw new o("argumentError","Cannot send files using application/x-www-form-urlencoded. Please use Tables or default value for useMultipartFormData");if(l=l?Object.assign({},l,{_csrf:g}):{_program:this._utils.getFullProgramPath(this.metadataRoot,e),_debug:this.debug?131:0,_service:"default",_csrf:g},t){let e,s;for(e in t instanceof n?s=t._tables:t instanceof i||t instanceof a?s=t._files:console.log(new o("argumentError","Wrong type of tables object")),s)s.hasOwnProperty(e)&&(l[e]=s[e])}this._disableCalls?this._pendingCalls.push({params:l,options:{sasProgram:e,dataObj:t,callback:s}}):this._ajax.post(this.url,l,this.useMultipartFormData).success((async function(a){if(c._utils.needToLogin.call(c,a)){if(c._pendingCalls.push({params:l,options:{sasProgram:e,dataObj:t,callback:s}}),c._disableCalls)return;c._disableCalls=!0,s(new o("notLoggedinError","You are not logged in"))}else{let i,g,h,f=!1;if(p)try{i=await c._utils.parseDebugRes(a.responseText,e,l,c.hostUrl,c.isViya),r.addApplicationLog(i.logmessage,e),g=t instanceof n?c._utils.unescapeValues(i):i,"success"!==i.status&&(h=new o("programError",i.errormessage,i.status)),f=!0}catch(t){t instanceof SyntaxError?(h=new o("parseError",t.message),f=!0):t instanceof o?"parseError"===t.type&&u<1?(f=!1,c._ajax.post(c.url,l,c.useMultipartFormData).success(this.success).error(this.error),u++,r.addApplicationLog("Retrying #"+u,e)):(h=t instanceof o?t:new o("parseError","Unable to parse response json"),f=!0):(h=new o("unknownError",t.message),h.stack=t.stack,f=!0)}finally{f&&s(h,g)}else try{i=c._utils.parseRes(a.responseText,e,l),r.addApplicationLog(i.logmessage,e),g=t instanceof n?c._utils.unescapeValues(i):i,"success"!==i.status&&(h=new o("programError",i.errormessage,i.status)),f=!0}catch(t){t instanceof SyntaxError?u<c.maxXhrRetries?(f=!1,c._ajax.post(c.url,l,c.useMultipartFormData).success(this.success).error(this.error),u++,r.addApplicationLog("Retrying #"+u,e)):(c._utils.parseErrorResponse(a.responseText,e),c._utils.addFailedResponse(a.responseText,e),h=new o("parseError","Unable to parse response json"),f=!0):t instanceof o?(c._utils.parseErrorResponse(a.responseText,e),c._utils.addFailedResponse(a.responseText,e),h=t,f=!0):(c._utils.parseErrorResponse(a.responseText,e),c._utils.addFailedResponse(a.responseText,e),h=new o("unknownError",t.message),h.stack=t.stack,f=!0)}finally{f&&s(h,g)}}})).error((function(t){let n;449===t.status||403===t.status&&(t.responseText.includes("_csrf")||"CSRF"===t.getResponseHeader("X-Forbidden-Reason"))&&(n=t.getResponseHeader(t.getResponseHeader("X-CSRF-HEADER")))?(l._csrf=n,c.csrf=n,u<c.maxXhrRetries?(c._ajax.post(c.url,l,!0).success(this.success).error(this.error),u++,r.addApplicationLog("Retrying #"+u,e)):(c._utils.parseErrorResponse(t.responseText,e),c._utils.addFailedResponse(t.responseText,e),s(new o("parseError","Unable to parse response json")))):(r.addApplicationLog("Request failed with status: "+t.status,e),s(new o("httpError",t.statusText)))}))},t.exports.login=function(e,t,s){if(!e||!t)throw new o("argumentError","Credentials not set");if("string"!=typeof e||"string"!=typeof t)throw new o("argumentError","User and pass parameters must be strings");if(!s||"function"!=typeof s)throw new o("argumentError","You must provide callback");this.RESTauth?c.call(this,e,t,s):l.call(this,e,t,s)},t.exports.managedRequest=function(e="get",t,s={callback:()=>console.log("Missing callback function")}){const n=this,a=this.csrf;let i=0;const{useMultipartFormData:l,sasProgram:c,dataObj:u,params:p,callback:g,headers:h}=s;if(c)return n.call(c,u,g,p);let f=t;t.startsWith("http")||(f=n.hostUrl+t);const d=Object.assign({},h,{"X-CSRF-TOKEN":a}),m=Object.assign({},s,{headers:d});this._disableCalls?this._customPendingCalls.push({callMethod:e,_url:t,options:m}):n._ajax[e](f,p,l,d).success((function(s){if(n._utils.needToLogin.call(n,s)){if(n._customPendingCalls.push({callMethod:e,_url:t,options:m}),n._disableCalls)return;n._disableCalls=!0,g(new o("notLoggedinError","You are not logged in"))}else{let e,t,r=!1;try{const o=s.getAllResponseHeaders().split("\r\n").reduce((function(e,t,s){let o=t.split(": ");return e[o[0]]=o[1],e}),{});let n=s.responseText;try{n=JSON.parse(n)}catch(e){console.log("response is not JSON string")}finally{e=Object.assign({},{headers:o,status:s.status,statusText:s.statusText,body:n}),r=!0}}catch(e){t=new o("unknownError",e.message),t.stack=e.stack,r=!0}finally{r&&g(t,e)}}})).error((function(s){let a;if(449==s.status||403==s.status&&(s.responseText.includes("_csrf")||"CSRF"===s.getResponseHeader("X-Forbidden-Reason"))&&(a=s.getResponseHeader(s.getResponseHeader("X-CSRF-HEADER")))){n.csrf=a;const t=Object.assign({},h,{[s.getResponseHeader("X-CSRF-HEADER")]:a});i<n.maxXhrRetries?(n._ajax[e](f,p,l,t).success(this.success).error(this.error),i++):g(new o("parseError","Unable to parse response json"))}else r.addApplicationLog("Managed request failed with status: "+s.status,t),g(new o("httpError",s.responseText,s.status))}))},t.exports.logout=function(e){const t=(this.hostUrl||"")+this.logoutUrl;this._ajax.get(t).success((function(t){this._disableCalls=!0,e()})).error((function(t){r.addApplicationLog("Logout failed with status code: "+t.status),e(t.status)}))},t.exports.setDebugMode=function(){this.debug=!0},t.exports.unsetDebugMode=function(){this.debug=!1};for(let e in r.get)r.get.hasOwnProperty(e)&&(t.exports[e]=r.get[e]);for(let e in r.clear)r.clear.hasOwnProperty(e)&&(t.exports[e]=r.clear[e]);function u(e,t,s){const o=this;let n={_service:"default",username:e,password:t};for(let e in this._aditionalLoginParams)n[e]=this._aditionalLoginParams[e];function a(e){449==e.status?i(e):(r.addApplicationLog("Login failed with status code: "+e.status),s(e.status))}function i(e){if(3==++o._loginAttempts&&s(-2),o._utils.needToLogin.call(o,e))if(o._loginChanged||o._isNewLoginPage&&!o._aditionalLoginParams){delete o._loginChanged;const t=e.responseText.match(/<input.*"hidden"[^>]*>/g);t&&t.forEach((function(e){const t=e.match(/name="([^"]*)"\svalue="([^"]*)/);n[t[1]]=t[2]})),o._ajax.post(o.loginUrl,n).success((function(){i()})).error(a)}else r.addApplicationLog("Wrong username or password"),s(-1);else{for(o._disableCalls=!1,s(e.status);o._customPendingCalls.length>0;){const e=o._customPendingCalls.shift(),t=e.method||o.managedRequest.bind(o),s=e.callMethod,r=e._url,n=e.options;n.params&&(n.params._debug=o.debug?131:0),o.retryAfterLogin&&t(s,r,n)}for(;o._pendingCalls.length>0;){const e=o._pendingCalls.shift(),t=e.method||o.call.bind(o),s=e.options.sasProgram,r=e.options.callback,n=e.params;n._debug=o.debug?131:0,o.retryAfterLogin&&t(s,null,r,n)}}}this._loginAttempts=0,n=this._ajax.serialize(n),this._ajax.post(this.loginUrl,n).success(i).error(a)}function p(e,t,s,o){const n=this,a={username:e,password:t};this._ajax.post(this.RESTauthLoginUrl,a).success((function(e){const t=e.getResponseHeader("Location");n._ajax.post(t,{service:o}).success((function(e){-1===o.indexOf("?")?o+="?ticket="+e.responseText:-1!==o.indexOf("ticket")?o=o.replace(/ticket=[^&]+/,"ticket="+e.responseText):o+="&ticket="+e.responseText,s(e.status)})).error((function(e){r.addApplicationLog("Login failed with status code: "+e.status),s(e.status)}))})).error((function(e){"error.authentication.credentials.bad"===e.responseText?s(-1):(r.addApplicationLog("Login failed with status code: "+e.status),s(e.status))}))}t.exports.onRemoteConfigUpdate=function(e){this.remoteConfigUpdateCallbacks.push(e)},t.exports._utils=e("./utils.js"),t.exports.promiseLogin=function(e,t){return new Promise((s,r)=>{e&&t||r(new o("argumentError","Credentials not set")),"string"==typeof e&&"string"==typeof t||r(new o("argumentError","User and pass parameters must be strings")),this.RESTauth?p.call(this,e,t,s):u.call(this,e,t,s)})},t.exports.getFolderDetails=function(e,t){let s="/folders/folders/@item?path="+e;return this.managedRequest("get",s,t)},t.exports.getFileDetails=function(e,t){return t.cacheBust&&(e+="?cacheBust="+(new Date).getTime()),this.managedRequest("get",e,t)},t.exports.getFileContent=function(e,t){let s=e+"/content";return t.cacheBust&&(s+="?cacheBust="+(new Date).getTime()),this.managedRequest("get",s,t)},t.exports.getFolderContents=async function(e,t){const s=this,{callback:o}=t;let r="/folders/folders/@item?path="+e;const n=Object.assign({},t,{callback:(e,t)=>{if(e)return void o(e,t);let r="/folders/folders/"+t.body.id+"/members/?limit=10000000";return s.managedRequest("get",r,{callback:o})}});this.managedRequest("get",r,n)},t.exports.createNewFolder=function(e,t,s){const o="/folders/folders?parentFolderUri="+e,r={name:t,type:"folder"},n=Object.assign({},s,{params:JSON.stringify(r),headers:{Accept:"application/json, text/javascript, */*; q=0.01","Content-Type":"application/json"},useMultipartFormData:!1});return this.managedRequest("post",o,n)},t.exports.deleteFolderById=function(e,t){const s="/folders/folders/"+e;return this.managedRequest("delete",s,t)},t.exports.createNewFile=function(e,t,s,o){let r={file:[t,e],parentFolderUri:s};const n=Object.assign({},o,{params:r,useMultipartFormData:!0});return this.managedRequest("post","/files/files#multipartUpload",n)},t.exports.deleteItem=function(e,t){return this.managedRequest("delete",e,t)},t.exports.updateFile=function(e,t,s,o){const r=e+"/content";console.log("URL",r);let n={"Content-Type":"application/vnd.sas.file","If-Unmodified-Since":s};const a=!(t instanceof Blob),i=Object.assign({},o,{params:t,headers:n,useMultipartFormData:a});return this.managedRequest("put",r,i)},t.exports.updateFileMetadata=function(e,t,s,o){let r={"Content-Type":"application/vnd.sas.file+json","If-Unmodified-Since":s};const n=!(t instanceof Blob),a=Object.assign({},o,{params:t,headers:r,useMultipartFormData:n});return this.managedRequest("patch",e,a)},t.exports.updateFolderMetadata=function(e,t,s,o){const{partialData:r}=o,n={"Content-Type":"application/vnd.sas.content.folder+json","If-Unmodified-Since":s};if(r){const s=(s,r)=>{if(r){const s=Object.assign({},r.body,t);let a=JSON.stringify(s),i=new Blob([a],{type:"octet/stream"});const l=Object.assign({},o,{params:i,headers:n,useMultipartFormData:!1});return this.managedRequest("put",e,l)}return o.callback(s)},r=Object.assign({},o,{headers:{"Content-Type":"application/vnd.sas.content.folder+json"},callback:s});return this.managedRequest("get",e,r)}{if(!(t instanceof Blob)){let e=JSON.stringify(t);t=new Blob([e],{type:"octet/stream"})}const s=Object.assign({},o,{params:t,headers:n,useMultipartFormData:!1});return this.managedRequest("put",e,s)}}},{"../error.js":1,"../files":2,"../logs.js":5,"../sasData.js":9,"../tables":10,"./utils.js":8}],8:[function(e,t,s){const o=e("../logs.js"),r=e("../error.js"),n=/<title>(Stored Process Error|SASStoredProcess)<\/title>[\s\S]*<h2>(Stored process not found:.*|.*not a valid stored process path.)<\/h2>/;t.exports.parseRes=function(e,t,s){if(e.match(n))throw new r("programNotFound","You have not been granted permission to perform this action, or the STP is missing.");return JSON.parse(e)},t.exports.parseDebugRes=function(e,t,s,a,i){const l=this;let c=e.match(n);if(c)throw new r("programNotFound","Sas program completed with errors");if(i){if(e.match("<h2>Parameter Error <br/>Unable to get job definition.</h2>"))throw new r("programNotFound","Sas program completed with errors. Unable to get job definition.")}let u=i?/^(.?<iframe.*src=")([^"]+)(.*iframe>)/m:/^(.?--h54s-data-start--)([\S\s]*?)(--h54s-data-end--)/m;c=e.match(u);const p=e.replace(u,"").match(/<body.*>([\s\S]*)<\/body>/);let g=p[1].replace(/<[^>]*>/g,"");if(g=this.decodeHTMLEntities(g),o.addDebugData(p[1],g,t,s),i&&this.parseErrorResponse(e,t))throw new r("sasError","Sas program completed with errors");if(!c)throw new r("parseError","Unable to parse response json");return new Promise((function(s,o){let n;if(i){const e=new XMLHttpRequest,t=a||"";e.open("GET",t+c[2]),e.onload=function(){this.status>=200&&this.status<300?s(JSON.parse(e.responseText.replace(/(\r\n|\r|\n)/g,""))):o(new r("fetchError",e.statusText,this.status))},e.onerror=function(){o(new r("fetchError",e.statusText))},e.send()}else{try{n=JSON.parse(c[2])}catch(e){o(new r("parseError","Unable to parse response json"))}n&&n.h54sAbort?s(n):l.parseErrorResponse(e,t)?o(new r("sasError","Sas program completed with errors")):s(n)}}))},t.exports.addFailedResponse=function(e,t){let s=(e=e.replace(/<script([\s\S]*)\/form>/,"").replace(/display\s?:\s?none;?\s?/,"")).replace(/<[^>]*>/g,"");s=this.decodeHTMLEntities(s),o.addFailedRequest(e,s,t)},t.exports.unescapeValues=function(e){for(let t in e)"string"==typeof e[t]?e[t]=decodeURIComponent(e[t]):"object"==typeof e&&this.unescapeValues(e[t]);return e},t.exports.parseErrorResponse=function(e,t){let s,r=e.replace(/(<([^>]+)>)/gi,"").match(/^ERROR(:\s|\s\d\d)(.*\.|.*\n.*\.)/gm);if(r){for(let e=0,o=r.length;e<o;e++)s=r[e].replace(/<[^>]*>/g,"").replace(/(\n|\s{2,})/g," "),s=this.decodeHTMLEntities(s),r[e]={sasProgram:t,message:s,time:new Date};return o.addSasErrors(r),!0}},t.exports.decodeHTMLEntities=function(e){const t=document.createElement("span");return e.replace(/&(#(?:x[0-9a-f]+|\d+)|[a-z]+);/gi,(function(e){return t.innerHTML=e,e=t.textContent||t.innerText}))},t.exports.fromSasDateTime=function(e){const t=new Date("January 1, 1960 00:00:00"),s=e,o=t.getTimezoneOffset(),r=1e3*s+t.getTime(),n=new Date;n.setTime(r);const a=r-60*(o-n.getTimezoneOffset())*1e3;return n.setTime(a),n},t.exports.needToLogin=function(e){if(!1===(e.responseURL&&e.responseURL.includes("SASLogon")))return!1;const t=/<form.+action="(.*Logon[^"]*).*>/.exec(e.responseText);let s;if(t){const o=t[1].replace(/\?.*/,"");if("/"===o.charAt(0))s=this.hostUrl?this.hostUrl+o:o,s!==this.loginUrl&&(this._loginChanged=!0,this.loginUrl=s);else{const t=e.responseURL.lastIndexOf("/")+1,r=e.responseURL.substr(0,t).replace(/.*\/{2}[^\/]*/,"")+o;s=this.hostUrl?this.hostUrl+r:r,s!==this.loginUrl&&(this._loginChanged=!0,this.loginUrl=s)}const r=(new DOMParser).parseFromString(e.responseText,"text/html").querySelectorAll("input[type='hidden']"),n={};return r&&(this._isNewLoginPage=!0,r.forEach((function(e){n[e.name]=e.value})),this._aditionalLoginParams=n),!0}return!1},t.exports.getFullProgramPath=function(e,t){return e?e.replace(/\/?$/,"/")+t.replace(/^\//,""):t},t.exports.getObjOfTable=function(e,t,s=null){const o={};return e.forEach(e=>{o[e[t]]||(o[e[t]]=[]),o[e[t]].push(s?e[s]:e)}),o},t.exports.getSelfUri=function(e){return e.filter(e=>"self"===e.rel).map(e=>e.uri).shift()}},{"../error.js":1,"../logs.js":5}],9:[function(e,t,s){const o=e("./error.js"),r=e("./logs.js"),n=(e("./tables"),e("./files")),a=e("./tables/utils.js").toSasDateTime;function i(e,t,s){if(e instanceof Array)this._files={},this.addTable(e,t,s);else{if(!(e instanceof File||e instanceof Blob))throw new o("argumentError","Data argument wrong type or missing");n.call(this,e,t)}}i.prototype.addTable=function(e,t,s){const n=!!s;if(!e||!t)throw new o("argumentError","Missing arguments");if(!(e instanceof Array))throw new o("argumentError","First argument must be array");if("string"!=typeof t)throw new o("argumentError","Second argument must be string");if(function(e){if(e.length>32)throw new o("argumentError","Table name too long. Maximum is 32 characters");const t=e.charCodeAt(0);if((t<65||t>90)&&(t<97||t>122)&&"_"!==e[0])throw new o("argumentError","Table name starting with number or special characters");for(let t=0;t<e.length;t++){const s=e.charCodeAt(t);if((s<48||s>57)&&(s<65||s>90)&&(s<97||s>122)&&"_"!==e[t])throw new o("argumentError","Table name has unsupported characters")}}(t),"object"!=typeof e||!(e instanceof Array))throw new o("argumentError","Table argument is not an array");let i;if(s){if(s.constructor!==Object)throw new o("argumentError","Specs data type wrong. Object expected.");for(i in e[0])if(!s[i])throw new o("argumentError","Missing columns in specs data.");for(i in s){if(s[i].constructor!==Object)throw new o("argumentError","Wrong column descriptor in specs data.");if(!s[i].colType||!s[i].colLength)throw new o("argumentError","Missing columns in specs descriptor.")}}let l,c,u,p,g,h=[];const f=['"',"\\","/","\n","\t","\f","\r","\b"];if(s)h=Object.keys(s);else for(s={},l=0;l<e.length;l++){if(u=e[l],"object"!=typeof u)throw new o("argumentError","Table item is not an object");for(i in u)u.hasOwnProperty(i)&&(p=u[i],g=typeof p,void 0===s[i]&&(h.push(i),s[i]={},"number"===g?((p<Number.MIN_SAFE_INTEGER||p>Number.MAX_SAFE_INTEGER)&&r.addApplicationLog("Object["+l+"]."+i+" - This value exceeds expected numeric precision."),s[i].colType="num",s[i].colLength=8):"string"!==g||p instanceof Date?p instanceof Date?(s[i].colType="date",s[i].colLength=8):"object"===g&&(s[i].colType="json",s[i].colLength=JSON.stringify(p).length):(s[i].colType="string",s[i].colLength=p.length)))}let d="";for(l=0;l<e.length;l++){for(u=e[l],c=0;c<h.length;c++){if(i=h[c],u.hasOwnProperty(i)){if(p=u[i],g=typeof p,"number"===g&&isNaN(p))throw new o("typeError","NaN value in one of the values (columns) is not allowed");if(p===-1/0||p===1/0)throw new o("typeError",p.toString()+" value in one of the values (columns) is not allowed");if(!0===p||!1===p)throw new o("typeError","Boolean value in one of the values (columns) is not allowed");if("string"===g&&-1!==p.indexOf("\r\n"))throw new o("typeError","New line character is not supported");if(null===p)if("string"===s[i].colType)p="",g="string";else{if("num"!==s[i].colType)throw new o("typeError","Cannot convert null value");p=".",g="number"}if("number"===g&&"num"!==s[i].colType&&"."!==p||"string"===g&&!(p instanceof Date)&&"string"!==s[i].colType&&"string"===g&&"num"==s[i].colType&&"."!==p||p instanceof Date&&"date"!==s[i].colType||"object"===g&&p.constructor!==Date&&"json"!==s[i].colType)throw new o("typeError","There is a specs type mismatch in the array between values (columns) of the same name. type/colType/val = "+g+"/"+s[i].colType+"/"+p);if(!n&&"string"===g&&s[i].colLength<p.length)s[i].colLength=p.length;else if("string"===g&&s[i].colLength<p.length||"string"!==g&&8!==s[i].colLength)throw new o("typeError","There is a specs length mismatch in the array between values (columns) of the same name. type/colType/val = "+g+"/"+s[i].colType+"/"+p);switch(p instanceof Date&&(p=a(p)),s[i].colType){case"num":case"date":d+=p;break;case"string":d+='"'+p.replace(/"/g,'""')+'"';let e=p.length;for(let t=0;t<p.length;t++)if(-1!==f.indexOf(p[t]))e++;else{let s=p.charCodeAt(t);s>65535?e+=3:s>2047?e+=2:s>127&&(e+=1)}s[i].colLength=Math.max(s[i].colLength,e,1);break;case"object":d+='"'+JSON.stringify(p).replace(/"/g,'""')+'"'}}c<h.length-1&&(d+=",")}l<e.length-1&&(d+="\r\n")}const m=h.map((function(e){return e+","+s[e].colType+","+s[e].colLength})).join("|");this._files[t]=[m,new Blob([d],{type:"text/csv;charset=UTF-8"})]},i.prototype.addFile=function(e,t){n.prototype.add.call(this,e,t)},t.exports=i},{"./error.js":1,"./files":2,"./logs.js":5,"./tables":10,"./tables/utils.js":11}],10:[function(e,t,s){const o=e("../error.js");function r(e,t,s){this._tables={},this._parameterThreshold=s||3e4,r.prototype.add.call(this,e,t)}r.prototype.add=function(e,t){if(!e||!t)throw new o("argumentError","Missing arguments");if(!(e instanceof Array))throw new o("argumentError","First argument must be array");if("string"!=typeof t)throw new o("argumentError","Second argument must be string");if(!isNaN(t[t.length-1]))throw new o("argumentError","Macro name cannot have number at the end");const s=this._utils.convertTableObject(e,this._parameterThreshold),r=[];r.push(JSON.stringify(s.spec));for(let e=0;e<s.data.length;e++){const t=JSON.stringify(s.data[e]);r.push(t)}this._tables[t]=r},r.prototype._utils=e("./utils.js"),t.exports=r},{"../error.js":1,"./utils.js":11}],11:[function(e,t,s){const o=e("../error.js"),r=e("../logs.js");t.exports.convertTableObject=function(e,t){if(t>3e4&&console.warn("You should not set threshold larger than 30kb because of the SAS limitations"),"object"!=typeof e)throw new o("argumentError","The parameter passed to checkAndGetTypeObject is not an object");if("number"!=typeof e.length)throw new o("argumentError","The parameter passed to checkAndGetTypeObject does not have a valid length and is most likely not an array");const s={};let n=0;const a=[];let i=0;a[i]=[];let l=0;for(let u=0;u<e.length;u++){a[i][l]={};let p=0;for(let t in e[u]){const n={},g=e[u][t];if(null==g)continue;if("number"==typeof g&&isNaN(g))throw new o("typeError","NaN value in one of the values (columns) is not allowed");if(g===-1/0||g===1/0)throw new o("typeError",g.toString()+" value in one of the values (columns) is not allowed");if(!0===g||!1===g)throw new o("typeError","Boolean value in one of the values (columns) is not allowed");const h=typeof g;if("number"===h)(g<Number.MIN_SAFE_INTEGER||g>Number.MAX_SAFE_INTEGER)&&r.addApplicationLog("Object["+u+"]."+t+" - This value exceeds expected numeric precision."),n.colName=t,n.colType="num",n.colLength=8,n.encodedLength=g.toString().length,a[i][l][t]=g;else if("string"===h)n.colName=t,n.colType="string",n.colLength=g.length,a[i][l][t]=""===g?" ":encodeURIComponent(g).replace(/'/g,"%27"),n.encodedLength=a[i][l][t].length;else{if(g instanceof Date)throw console.log("ERROR VALUE ",g),console.log("TYPEOF VALUE ",typeof g),new o("typeError","Date type not supported. Please use h54s.toSasDateTime function to convert it");"object"==h&&(n.colName=t,n.colType="json",n.colLength=JSON.stringify(g).length,a[i][l][t]=encodeURIComponent(JSON.stringify(g)).replace(/'/g,"%27"),n.encodedLength=a[i][l][t].length)}if(p=p+6+t.length+n.encodedLength,-1==(void 0===s[(c=n).colName]?(s[c.colName]={},s[c.colName].colName=c.colName,s[c.colName].colType=c.colType,s[c.colName].colLength=c.colLength>0?c.colLength:1,0):s[c.colName].colType!==c.colType?-1:s[c.colName].colLength<c.colLength?(s[c.colName].colLength=c.colLength>0?c.colLength:1,0):void 0))throw new o("typeError","There is a type mismatch in the array between values (columns) of the same name.")}if(0!==Object.keys(a[i][l]).length){if(p>t)throw new o("argumentError","Row "+l+" exceeds size limit of 32kb");if(n+p>t){const e=a[i].pop();i++,a[i]=[e],l=0,n=p}else n+=p;l++}else a[i].splice(l,1)}var c;const u=[];for(let e in s)u.push(s[e]);return{spec:u,data:a,jsonLength:n}},t.exports.toSasDateTime=function(e){const t=new Date("January 1, 1960 00:00:00"),s=e,o=t.getTimezoneOffset(),r=60*(s.getTimezoneOffset()-o),n=t.getTime()/1e3,a=s.getTime()/1e3;return Math.round(a-n-r)}},{"../error.js":1,"../logs.js":5}]},{},[3])(3)}));
\No newline at end of file