diff --git a/dist/xapiwrapper.min.js b/dist/xapiwrapper.min.js index 8ea1c22..90217df 100644 --- a/dist/xapiwrapper.min.js +++ b/dist/xapiwrapper.min.js @@ -1,2 +1,2 @@ -/*! xAPIWrapper v 1.10.0 | Built on 2016-12-02 09:15:06-0500 */ +/*! xAPIWrapper v 1.10.1 | Built on 2016-12-02 09:18:50-0500 */ function toBase64(a){return CryptoJS&&CryptoJS.enc.Base64?CryptoJS.enc.Base64.stringify(CryptoJS.enc.Latin1.parse(a)):Base64.encode(a)}function toSHA1(a){return CryptoJS&&CryptoJS.SHA1?CryptoJS.SHA1(a).toString():Crypto.util.bytesToHex(Crypto.SHA1(a,{asBytes:!0}))}function isDate(a){if("[object Date]"===Object.prototype.toString.call(a))var b=a;else var b=new Date(a);return"[object Date]"===Object.prototype.toString.call(b)?isNaN(b.valueOf())?(ADL.XAPIWrapper.log("Invalid date String passed"),null):b:(ADL.XAPIWrapper.log("Invalid date object"),null)}var CryptoJS=CryptoJS||function(a,b){var c={},d=c.lib={},e=d.Base=function(){function a(){}return{extend:function(b){a.prototype=this;var c=new a;return b&&c.mixIn(b),c.hasOwnProperty("init")||(c.init=function(){c.$super.init.apply(this,arguments)}),c.init.prototype=c,c.$super=this,c},create:function(){var a=this.extend();return a.init.apply(a,arguments),a},init:function(){},mixIn:function(a){for(var b in a)a.hasOwnProperty(b)&&(this[b]=a[b]);a.hasOwnProperty("toString")&&(this.toString=a.toString)},clone:function(){return this.init.prototype.extend(this)}}}(),f=d.WordArray=e.extend({init:function(a,c){a=this.words=a||[],this.sigBytes=c!=b?c:4*a.length},toString:function(a){return(a||h).stringify(this)},concat:function(a){var b=this.words,c=a.words,d=this.sigBytes,e=a.sigBytes;if(this.clamp(),d%4)for(var f=0;e>f;f++){var g=c[f>>>2]>>>24-f%4*8&255;b[d+f>>>2]|=g<<24-(d+f)%4*8}else if(c.length>65535)for(var f=0;e>f;f+=4)b[d+f>>>2]=c[f>>>2];else b.push.apply(b,c);return this.sigBytes+=e,this},clamp:function(){var b=this.words,c=this.sigBytes;b[c>>>2]&=4294967295<<32-c%4*8,b.length=a.ceil(c/4)},clone:function(){var a=e.clone.call(this);return a.words=this.words.slice(0),a},random:function(b){for(var c=[],d=0;b>d;d+=4)c.push(4294967296*a.random()|0);return new f.init(c,b)}}),g=c.enc={},h=g.Hex={stringify:function(a){for(var b=a.words,c=a.sigBytes,d=[],e=0;c>e;e++){var f=b[e>>>2]>>>24-e%4*8&255;d.push((f>>>4).toString(16)),d.push((15&f).toString(16))}return d.join("")},parse:function(a){for(var b=a.length,c=[],d=0;b>d;d+=2)c[d>>>3]|=parseInt(a.substr(d,2),16)<<24-d%8*4;return new f.init(c,b/2)}},i=g.Latin1={stringify:function(a){for(var b=a.words,c=a.sigBytes,d=[],e=0;c>e;e++){var f=b[e>>>2]>>>24-e%4*8&255;d.push(String.fromCharCode(f))}return d.join("")},parse:function(a){for(var b=a.length,c=[],d=0;b>d;d++)c[d>>>2]|=(255&a.charCodeAt(d))<<24-d%4*8;return new f.init(c,b)}},j=g.Utf8={stringify:function(a){try{return decodeURIComponent(escape(i.stringify(a)))}catch(b){throw new Error("Malformed UTF-8 data")}},parse:function(a){return i.parse(unescape(encodeURIComponent(a)))}},k=(g.Base64={stringify:function(a){var b=a.words,c=a.sigBytes,d=this._map;a.clamp();for(var e=[],f=0;c>f;f+=3)for(var g=b[f>>>2]>>>24-f%4*8&255,h=b[f+1>>>2]>>>24-(f+1)%4*8&255,i=b[f+2>>>2]>>>24-(f+2)%4*8&255,j=g<<16|h<<8|i,k=0;4>k&&c>f+.75*k;k++)e.push(d.charAt(j>>>6*(3-k)&63));var l=d.charAt(64);if(l)for(;e.length%4;)e.push(l);return e.join("")},parse:function(a){var b=a.length,c=this._map,d=c.charAt(64);if(d){var e=a.indexOf(d);-1!=e&&(b=e)}for(var g=[],h=0,i=0;b>i;i++)if(i%4){var j=c.indexOf(a.charAt(i-1))<>>6-i%4*2;g[h>>>2]|=(j|k)<<24-h%4*8,h++}return f.create(g,h)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="},d.BufferedBlockAlgorithm=e.extend({reset:function(){this._data=new f.init,this._nDataBytes=0},_append:function(a){"string"==typeof a&&(a=j.parse(a)),this._data.concat(a),this._nDataBytes+=a.sigBytes},_process:function(b){var c=this._data,d=c.words,e=c.sigBytes,g=this.blockSize,h=4*g,i=e/h;i=b?a.ceil(i):a.max((0|i)-this._minBufferSize,0);var j=i*g,k=a.min(4*j,e);if(j){for(var l=0;j>l;l+=g)this._doProcessBlock(d,l);var m=d.splice(0,j);c.sigBytes-=k}return new f.init(m,k)},clone:function(){var a=e.clone.call(this);return a._data=this._data.clone(),a},_minBufferSize:0})),l=d.Hasher=k.extend({cfg:e.extend(),init:function(a){this.cfg=this.cfg.extend(a),this.reset()},reset:function(){k.reset.call(this),this._doReset()},update:function(a){return this._append(a),this._process(),this},finalize:function(a){a&&this._append(a);var b=this._doFinalize();return b},blockSize:16,_createHelper:function(a){return function(b,c){return new a.init(c).finalize(b)}},_createHmacHelper:function(a){return function(b,c){return new m.HMAC.init(a,c).finalize(b)}}}),m=c.algo={},n=[],o=m.SHA1=l.extend({_doReset:function(){this._hash=new f.init([1732584193,4023233417,2562383102,271733878,3285377520])},_doProcessBlock:function(a,b){for(var c=this._hash.words,d=c[0],e=c[1],f=c[2],g=c[3],h=c[4],i=0;80>i;i++){if(16>i)n[i]=0|a[b+i];else{var j=n[i-3]^n[i-8]^n[i-14]^n[i-16];n[i]=j<<1|j>>>31}var k=(d<<5|d>>>27)+h+n[i];k+=20>i?(e&f|~e&g)+1518500249:40>i?(e^f^g)+1859775393:60>i?(e&f|e&g|f&g)-1894007588:(e^f^g)-899497514,h=g,g=f,f=e<<30|e>>>2,e=d,d=k}c[0]=c[0]+d|0,c[1]=c[1]+e|0,c[2]=c[2]+f|0,c[3]=c[3]+g|0,c[4]=c[4]+h|0},_doFinalize:function(){var b=this._data,c=b.words,d=8*this._nDataBytes,e=8*b.sigBytes;return c[e>>>5]|=128<<24-e%32,c[(e+64>>>9<<4)+14]=a.floor(d/4294967296),c[(e+64>>>9<<4)+15]=d,b.sigBytes=4*c.length,this._process(),this._hash},clone:function(){var a=l.clone.call(this);return a._hash=this._hash.clone(),a}});return c.SHA1=l._createHelper(o),c.HmacSHA1=l._createHmacHelper(o),c}(Math);!function(a){a.verbs={abandoned:{id:"https://w3id.org/xapi/adl/verbs/abandoned",display:{"en-US":"abandoned"}},answered:{id:"http://adlnet.gov/expapi/verbs/answered",display:{"de-DE":"beantwortete","en-US":"answered","fr-FR":"a répondu","es-ES":"contestó"}},asked:{id:"http://adlnet.gov/expapi/verbs/asked",display:{"de-DE":"fragte","en-US":"asked","fr-FR":"a demandé","es-ES":"preguntó"}},attempted:{id:"http://adlnet.gov/expapi/verbs/attempted",display:{"de-DE":"versuchte","en-US":"attempted","fr-FR":"a essayé","es-ES":"intentó"}},attended:{id:"http://adlnet.gov/expapi/verbs/attended",display:{"de-DE":"nahm teil an","en-US":"attended","fr-FR":"a suivi","es-ES":"asistió"}},commented:{id:"http://adlnet.gov/expapi/verbs/commented",display:{"de-DE":"kommentierte","en-US":"commented","fr-FR":"a commenté","es-ES":"comentó"}},completed:{id:"http://adlnet.gov/expapi/verbs/completed",display:{"de-DE":"beendete","en-US":"completed","fr-FR":"a terminé","es-ES":"completó"}},exited:{id:"http://adlnet.gov/expapi/verbs/exited",display:{"de-DE":"verließ","en-US":"exited","fr-FR":"a quitté","es-ES":"salió"}},experienced:{id:"http://adlnet.gov/expapi/verbs/experienced",display:{"de-DE":"erlebte","en-US":"experienced","fr-FR":"a éprouvé","es-ES":"experimentó"}},failed:{id:"http://adlnet.gov/expapi/verbs/failed",display:{"de-DE":"verfehlte","en-US":"failed","fr-FR":"a échoué","es-ES":"fracasó"}},imported:{id:"http://adlnet.gov/expapi/verbs/imported",display:{"de-DE":"importierte","en-US":"imported","fr-FR":"a importé","es-ES":"importó"}},initialized:{id:"http://adlnet.gov/expapi/verbs/initialized",display:{"de-DE":"initialisierte","en-US":"initialized","fr-FR":"a initialisé","es-ES":"inicializó"}},interacted:{id:"http://adlnet.gov/expapi/verbs/interacted",display:{"de-DE":"interagierte","en-US":"interacted","fr-FR":"a interagi","es-ES":"interactuó"}},launched:{id:"http://adlnet.gov/expapi/verbs/launched",display:{"de-DE":"startete","en-US":"launched","fr-FR":"a lancé","es-ES":"lanzó"}},mastered:{id:"http://adlnet.gov/expapi/verbs/mastered",display:{"de-DE":"meisterte","en-US":"mastered","fr-FR":"a maîtrisé","es-ES":"dominó"}},passed:{id:"http://adlnet.gov/expapi/verbs/passed",display:{"de-DE":"bestand","en-US":"passed","fr-FR":"a réussi","es-ES":"aprobó"}},preferred:{id:"http://adlnet.gov/expapi/verbs/preferred",display:{"de-DE":"bevorzugte","en-US":"preferred","fr-FR":"a préféré","es-ES":"prefirió"}},progressed:{id:"http://adlnet.gov/expapi/verbs/progressed",display:{"de-DE":"machte Fortschritt mit","en-US":"progressed","fr-FR":"a progressé","es-ES":"progresó"}},registered:{id:"http://adlnet.gov/expapi/verbs/registered",display:{"de-DE":"registrierte","en-US":"registered","fr-FR":"a enregistré","es-ES":"registró"}},responded:{id:"http://adlnet.gov/expapi/verbs/responded",display:{"de-DE":"reagierte","en-US":"responded","fr-FR":"a répondu","es-ES":"respondió"}},resumed:{id:"http://adlnet.gov/expapi/verbs/resumed",display:{"de-DE":"setzte fort","en-US":"resumed","fr-FR":"a repris","es-ES":"continuó"}},satisfied:{id:"https://w3id.org/xapi/adl/verbs/satisfied",display:{"en-US":"satisfied"}},scored:{id:"http://adlnet.gov/expapi/verbs/scored",display:{"de-DE":"erreichte","en-US":"scored","fr-FR":"a marqué","es-ES":"anotó"}},shared:{id:"http://adlnet.gov/expapi/verbs/shared",display:{"de-DE":"teilte","en-US":"shared","fr-FR":"a partagé","es-ES":"compartió"}},suspended:{id:"http://adlnet.gov/expapi/verbs/suspended",display:{"de-DE":"pausierte","en-US":"suspended","fr-FR":"a suspendu","es-ES":"aplazó"}},terminated:{id:"http://adlnet.gov/expapi/verbs/terminated",display:{"de-DE":"beendete","en-US":"terminated","fr-FR":"a terminé","es-ES":"terminó"}},voided:{id:"http://adlnet.gov/expapi/verbs/voided",display:{"de-DE":"entwertete","en-US":"voided","fr-FR":"a annulé","es-ES":"anuló"}},waived:{id:"https://w3id.org/xapi/adl/verbs/waived",display:{"en-US":"waived"}}}}(window.ADL=window.ADL||{}),Date.prototype.toISOString||!function(){function a(a){var b=String(a);return 1===b.length&&(b="0"+b),b}Date.prototype.toISOString=function(){return this.getUTCFullYear()+"-"+a(this.getUTCMonth()+1)+"-"+a(this.getUTCDate())+"T"+a(this.getUTCHours())+":"+a(this.getUTCMinutes())+":"+a(this.getUTCSeconds())+"."+String((this.getUTCMilliseconds()/1e3).toFixed(3)).slice(2,5)+"Z"}}(),function(a){function b(){try{return void 0!=this.lrs.endpoint&&""!=this.lrs.endpoint}catch(a){return!1}}function c(a){if(!c.debug)return!1;try{return console.log(a),!0}catch(b){return!1}}function d(a,b){for(var e in b){prop=b[e],c(e+" : "+prop);try{b[e].constructor==Object?a[e]=d(a[e],b[e]):(void 0==a&&(a=new Object),a[e]=b[e])}catch(f){void 0==a&&(a=new Object),a[e]=b[e]}}return a}function e(a){var b,c,e=["endpoint","auth","actor","registration","activity_id","grouping","activity_platform"],g=new Object;if(b=f(),void 0!==b&&0!==Object.keys(b).length){for(var h=0;h0&&(f.push(e.substr(g+1)),e=e.substr(0,g)),e=e+"?method="+a,null!==c)for(var h in c)f.push(h+"="+encodeURIComponent(c[h]));return null!==d&&f.push("content="+encodeURIComponent(d)),{method:"POST",url:e,headers:{},data:f.join("&")}}c.debug=!1;var i=function(){var a={};a.endpoint="http://localhost:8000/xapi/";try{a.auth="Basic "+toBase64("tom:1234")}catch(b){c("Exception in Config trying to encode auth: "+b)}return a}();XAPIWrapper=function(c,f){function g(b){var c=document.createElement("a");return c.href=b,c.protocol&&c.host?c.protocol+"//"+c.host:void a.XAPIWrapper.log("Couldn't create base url from endpoint: "+this.lrs.endpoint)}function h(a,b,c){a.auth="Basic "+toBase64(b+":"+c)}this.lrs=e(c||{}),this.lrs.user&&this.lrs.password&&h(this.lrs,this.lrs.user,this.lrs.password),this.base=g(this.lrs.endpoint),this.withCredentials=!1,this.withCredentials=c&&c.withCredentials,f&&b.call(this)&&window.ADL.XHR_request(this.lrs,this.lrs.endpoint+"about","GET",null,null,function(b){if(200==b.status)try{var c=JSON.parse(b.response),d=!1;for(var e in c.version)if(c.version[e]==a.XAPIWrapper.xapiVersion){d=!0;break}d||a.XAPIWrapper.log("The lrs version ["+c.version+"] does not match this wrapper's XAPI version ["+a.XAPIWrapper.xapiVersion+"]")}catch(f){a.XAPIWrapper.log("The response was not an about object")}else a.XAPIWrapper.log("The request to get information about the LRS failed: "+b)},null,!1,null,this.withCredentials),this.searchParams=function(){var a={format:"exact"};return a},this.hash=function(b){if(!b)return null;try{return toSHA1(b)}catch(c){return a.XAPIWrapper.log("Error trying to hash -- "+c),null}},this.changeConfig=function(b){try{a.XAPIWrapper.log("updating lrs object with new configuration"),this.lrs=d(this.lrs,b),b.user&&b.password&&this.updateAuth(this.lrs,b.user,b.password),this.base=g(this.lrs.endpoint),this.withCredentials=b.withCredentials}catch(c){a.XAPIWrapper.log("error while changing configuration -- "+c)}},this.updateAuth=h},XAPIWrapper.prototype.xapiVersion="1.0.1",XAPIWrapper.prototype.prepareStatement=function(a){void 0===a.actor?a.actor=JSON.parse(this.lrs.actor):"string"==typeof a.actor&&(a.actor=JSON.parse(a.actor)),(this.lrs.grouping||this.lrs.registration||this.lrs.activity_platform)&&(a.context||(a.context={})),this.lrs.grouping&&(a.context.contextActivities||(a.context.contextActivities={}),a.context.contextActivities.grouping=[{id:this.lrs.grouping}]),this.lrs.registration&&(a.context.registration=this.lrs.registration),this.lrs.activity_platform&&(a.context.platform=this.lrs.activity_platform)},XAPIWrapper.prototype.testConfig=b,XAPIWrapper.prototype.log=c,XAPIWrapper.prototype.sendStatement=function(b,c){if(this.testConfig()){this.prepareStatement(b);var d;b.id?d=b.id:(d=a.ruuid(),b.id=d);var e=a.XHR_request(this.lrs,this.lrs.endpoint+"statements","POST",JSON.stringify(b),this.lrs.auth,c,{id:d},null,!1,this.withCredentials);if(!c)return{xhr:e,id:d}}},XAPIWrapper.prototype.sendStatements=function(b,c){if(this.testConfig()){for(var d in b)this.prepareStatement(b[d]);var e=a.XHR_request(this.lrs,this.lrs.endpoint+"statements","POST",JSON.stringify(b),this.lrs.auth,c,null,!1,null,this.withCredentials);if(!c)return e}},XAPIWrapper.prototype.getStatements=function(b,c,d){if(this.testConfig()){var e=this.lrs.endpoint+"statements";if(c)e=this.base+c;else{var f=new Array;for(s in b)if("until"==s||"since"==s){var g=new Date(b[s]);f.push(s+"="+encodeURIComponent(g.toISOString()))}else f.push(s+"="+encodeURIComponent(b[s]));f.length>0&&(e=e+"?"+f.join("&"))}var h=a.XHR_request(this.lrs,e,"GET",null,this.lrs.auth,d,null,!1,null,this.withCredentials);if(void 0===h||404==h.status)return null;try{return JSON.parse(h.response)}catch(i){return h.response}}},XAPIWrapper.prototype.getActivities=function(b,c){if(this.testConfig()){var d=this.lrs.endpoint+"activities?activityId=";d=d.replace("",encodeURIComponent(b));var e=a.XHR_request(this.lrs,d,"GET",null,this.lrs.auth,c,null,!0,null,this.withCredentials);if(void 0===e||404==e.status)return null;try{return JSON.parse(e.response)}catch(f){return e.response}}},XAPIWrapper.prototype.sendState=function(b,d,e,f,g,h,i,j){if(this.testConfig()){var k=this.lrs.endpoint+"activities/state?activityId=&agent=&stateId=";k=k.replace("",encodeURIComponent(b)),k=k.replace("",encodeURIComponent(JSON.stringify(d))),k=k.replace("",encodeURIComponent(e)),f&&(k+="®istration="+encodeURIComponent(f));var l=null;h&&i?c("Can't have both If-Match and If-None-Match"):h?l={"If-Match":'"'+h+'"'}:i&&(l={"If-None-Match":'"'+i+'"'});var m="PUT";if(!g)return this.log("No activity state was included."),!1;g instanceof Array?(g=JSON.stringify(g),l=l||{},l["Content-Type"]="application/json"):g instanceof Object?(g=JSON.stringify(g),l=l||{},l["Content-Type"]="application/json",m="POST"):(l=l||{},l["Content-Type"]="application/octet-stream"),a.XHR_request(this.lrs,k,m,g,this.lrs.auth,j,null,null,l,this.withCredentials)}},XAPIWrapper.prototype.getState=function(b,c,d,e,f,g){if(this.testConfig()){var h=this.lrs.endpoint+"activities/state?activityId=&agent=";h=h.replace("",encodeURIComponent(b)),h=h.replace("",encodeURIComponent(JSON.stringify(c))),d&&(h+="&stateId="+encodeURIComponent(d)),e&&(h+="®istration="+encodeURIComponent(e)),f&&(f=isDate(f),null!=f&&(h+="&since="+encodeURIComponent(f.toISOString())));var i=a.XHR_request(this.lrs,h,"GET",null,this.lrs.auth,g,null,!0,this.withCredentials);if(void 0===i||404==i.status)return null;try{return JSON.parse(i.response)}catch(j){return i.response}}},XAPIWrapper.prototype.deleteState=function(b,d,e,f,g,h,i){if(this.testConfig()){var j=this.lrs.endpoint+"activities/state?activityId=&agent=&stateId=";j=j.replace("",encodeURIComponent(b)),j=j.replace("",encodeURIComponent(JSON.stringify(d))),j=j.replace("",encodeURIComponent(e)),f&&(j+="®istration="+encodeURIComponent(f));var k=null;g&&h?c("Can't have both If-Match and If-None-Match"):g?k={"If-Match":'"'+g+'"'}:h&&(k={"If-None-Match":'"'+h+'"'});var l=a.XHR_request(this.lrs,j,"DELETE",null,this.lrs.auth,i,null,k,this.withCredentials);if(void 0===l||404==l.status)return null;try{return JSON.parse(l.response)}catch(m){return l}}},XAPIWrapper.prototype.sendActivityProfile=function(b,d,e,f,g,h){if(this.testConfig()){var i=this.lrs.endpoint+"activities/profile?activityId=&profileId=";i=i.replace("",encodeURIComponent(b)),i=i.replace("",encodeURIComponent(d));var j=null;f&&g?c("Can't have both If-Match and If-None-Match"):f?j={"If-Match":'"'+f+'"'}:g&&(j={"If-None-Match":'"'+g+'"'});var k="PUT";if(!e)return this.log("No activity profile was included."),!1;e instanceof Array?(e=JSON.stringify(e),j=j||{},j["Content-Type"]="application/json"):e instanceof Object?(e=JSON.stringify(e),j=j||{},j["Content-Type"]="application/json",k="POST"):(j=j||{},j["Content-Type"]="application/octet-stream"),a.XHR_request(this.lrs,i,k,e,this.lrs.auth,h,null,!1,j,this.withCredentials)}},XAPIWrapper.prototype.getActivityProfile=function(b,c,d,e){if(this.testConfig()){var f=this.lrs.endpoint+"activities/profile?activityId=";f=f.replace("",encodeURIComponent(b)),c&&(f+="&profileId="+encodeURIComponent(c)),d&&(d=isDate(d),null!=d&&(f+="&since="+encodeURIComponent(d.toISOString())));var g=a.XHR_request(this.lrs,f,"GET",null,this.lrs.auth,e,null,!0,null,this.withCredentials);if(void 0===g||404==g.status)return null;try{return JSON.parse(g.response)}catch(h){return g.response}}},XAPIWrapper.prototype.deleteActivityProfile=function(b,d,e,f,g){if(this.testConfig()){var h=this.lrs.endpoint+"activities/profile?activityId=&profileId=";h=h.replace("",encodeURIComponent(b)),h=h.replace("",encodeURIComponent(d));var i=null;e&&f?c("Can't have both If-Match and If-None-Match"):e?i={"If-Match":'"'+e+'"'}:f&&(i={"If-None-Match":'"'+f+'"'});var j=a.XHR_request(this.lrs,h,"DELETE",null,this.lrs.auth,g,null,!1,i,this.withCredentials);if(void 0===j||404==j.status)return null;try{return JSON.parse(j.response)}catch(k){return j}}},XAPIWrapper.prototype.getAgents=function(b,c){if(this.testConfig()){var d=this.lrs.endpoint+"agents?agent=";d=d.replace("",encodeURIComponent(JSON.stringify(b)));var e=a.XHR_request(this.lrs,d,"GET",null,this.lrs.auth,c,null,!0,null,this.withCredentials);if(void 0===e||404==e.status)return null;try{return JSON.parse(e.response)}catch(f){return e.response}}},XAPIWrapper.prototype.sendAgentProfile=function(b,d,e,f,g,h){if(this.testConfig()){var i=this.lrs.endpoint+"agents/profile?agent=&profileId=";i=i.replace("",encodeURIComponent(JSON.stringify(b))),i=i.replace("",encodeURIComponent(d));var j=null;f&&g?c("Can't have both If-Match and If-None-Match"):f?j={"If-Match":'"'+f+'"'}:g&&(j={"If-None-Match":'"'+g+'"'});var k="PUT";if(!e)return this.log("No agent profile was included."),!1;e instanceof Array?(e=JSON.stringify(e),j=j||{},j["Content-Type"]="application/json"):e instanceof Object?(e=JSON.stringify(e),j=j||{},j["Content-Type"]="application/json",k="POST"):(j=j||{},j["Content-Type"]="application/octet-stream"),a.XHR_request(this.lrs,i,k,e,this.lrs.auth,h,null,!1,j,this.withCredentials)}},XAPIWrapper.prototype.getAgentProfile=function(b,c,d,e){if(this.testConfig()){var f=this.lrs.endpoint+"agents/profile?agent=";f=f.replace("",encodeURIComponent(JSON.stringify(b))),f=f.replace("",encodeURIComponent(c)),c&&(f+="&profileId="+encodeURIComponent(c)),d&&(d=isDate(d),null!=d&&(f+="&since="+encodeURIComponent(d.toISOString())));var g=a.XHR_request(this.lrs,f,"GET",null,this.lrs.auth,e,null,!0,null,this.withCredentials);if(void 0===g||404==g.status)return null;try{return JSON.parse(g.response)}catch(h){return g.response}}},XAPIWrapper.prototype.deleteAgentProfile=function(b,d,e,f,g){if(this.testConfig()){var h=this.lrs.endpoint+"agents/profile?agent=&profileId=";h=h.replace("",encodeURIComponent(JSON.stringify(b))),h=h.replace("",encodeURIComponent(d));var i=null;e&&f?c("Can't have both If-Match and If-None-Match"):e?i={"If-Match":'"'+e+'"'}:f&&(i={"If-None-Match":'"'+f+'"'});var j=a.XHR_request(this.lrs,h,"DELETE",null,this.lrs.auth,g,null,!1,i,this.withCredentials);if(void 0===j||404==j.status)return null;try{return JSON.parse(j.response)}catch(k){return j}}},a.ruuid=function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(a){var b=16*Math.random()|0,c="x"==a?b:3&b|8;return c.toString(16)})},a.dateFromISOString=function(a){var b="([0-9]{4})(-([0-9]{2})(-([0-9]{2})([T| ]([0-9]{2}):([0-9]{2})(:([0-9]{2})(.([0-9]+))?)?(Z|(([-+])([0-9]{2}):([0-9]{2})))?)?)?)?",c=a.match(new RegExp(b)),d=0,e=new Date(c[1],0,1);c[3]&&e.setMonth(c[3]-1),c[5]&&e.setDate(c[5]),c[7]&&e.setHours(c[7]),c[8]&&e.setMinutes(c[8]),c[10]&&e.setSeconds(c[10]),c[12]&&e.setMilliseconds(1e3*Number("0."+c[12])),c[14]&&(d=60*Number(c[16])+Number(c[17]),d*="-"==c[15]?1:-1),d-=e.getTimezoneOffset(),time=Number(e)+60*d*1e3;var f=new Date;return f.setTime(Number(time)),f},a.XHR_request=function(b,c,d,e,f,i,j,k,l,m){"use strict";function n(){if(t)return r;t=!0;var b=k&&404===o.status;if(!(void 0===o.status||o.status>=200&&o.status<400||b)){var e;try{e="There was a problem communicating with the Learning Record Store. ( "+o.status+" | "+o.response+" )"+c}catch(f){e=f.toString()}return a.XAPIWrapper.log(e),a.xhrRequestOnError(o,d,c,i,j),r=o,o}if(!i)return r=o,o;if(j)i(o,j);else try{var g=JSON.parse(o.responseText);i(o,g)}catch(h){i(o,o.responseText)}}var o,p,q,r,s,t=!1,u=!1,v=!1,w=c.toLowerCase().match(/^(.+):\/\/([^:\/]*):?(\d+)?(\/.*)?$/),x=window.location,y={};if(y["Content-Type"]="application/json",y.Authorization=f,y["X-Experience-API-Version"]=a.XAPIWrapper.xapiVersion,null!==l)for(var z in l)y[z]=l[z];u=x.protocol.toLowerCase()!==w[1]||x.hostname.toLowerCase()!==w[2],u||(q=null===w[3]?"http"===w[1]?"80":"443":w[3],u=q===x.port);var A=window.XDomainRequest&&window.XMLHttpRequest&&void 0===(new XMLHttpRequest).responseType;if(u&&void 0!==A&&A!==!1)v=!0,p=h(d,c,y,e),o=new XDomainRequest,o.open(p.method,p.url);else{o=new XMLHttpRequest,o.withCredentials=m,o.open(d,c,null!=i);for(var z in y)o.setRequestHeader(z,y[z])}if(o.onreadystatechange=function(){return 4===o.readyState?n():void 0},o.onload=n,o.onerror=n,o.send(v?p.data:e),!i){if(v)for(s=1e3+new Date;new Date-1?i+"&"+f:i+"?"+f,h.href=i)}}function f(a,f){a=c(a);try{{var h=b("xAPILaunchKey"),i=b("xAPILaunchService");b("encrypted")}if(!h||!i)return a("invalid launch parameters");var j=new URL(i);j.pathname+="launch/"+h;var k=new XMLHttpRequest;k.withCredentials=!0,k.crossDomain=!0,k.onerror=function(b){window.setTimeout(function(){return a(b)})},k.onload=function(){if(200!==k.status)return k.onerror(k.responseText);var b=JSON.parse(k.responseText),c=b,j={};j.endpoint=c.endpoint,j.actor=c.actor,j.withCredentials=!0,window.onunload=function(){if(f){var a=new URL(i);a.pathname+="launch/"+h+"/terminate";var b=new XMLHttpRequest;b.withCredentials=!0,b.crossDomain=!0,b.open("POST",a.toString(),!1),b.setRequestHeader("Content-type","application/json"),b.send('{"code":0,"description":"User closed content"}')}};var l=new g.XAPIWrapper.constructor;return l.changeConfig(j),e(document.body.querySelectorAll("a")),d(),a(null,b,l)},k.open("POST",j.toString(),!0),k.send()}catch(l){a(l)}}var g=a;g.launch=f}(window.ADL=window.ADL||{}); \ No newline at end of file diff --git a/package.json b/package.json index 63e2659..0970708 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "xAPIWrapper", "description": "An easier way to build, send, and retrieve xAPI statements", - "version": "1.10.0", + "version": "1.10.1", "repository": { "type": "git", "url": "https://github.com/adlnet/xAPIWrapper.git"