forked from veracity-tech/vtc-lrs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
1 lines (1 loc) · 77.7 KB
/
index.js
1
module.exports=function(e){var t={};function n(r){if(t[r])return t[r].exports;var i=t[r]={i:r,l:!1,exports:{}};return e[r].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get:r})},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=9)}([function(e,t){e.exports=require("express")},function(e,t,n){n(12);const r=n(13),i=new r({format:"full",jsonPointers:!0}),a=n(14),o=new(n(15)),s=n(16);let c={id:"#AnonymousGroup",type:"object",properties:{objectType:{type:"string",enum:["Group"]},name:{type:"string",chance:{name:null}},member:{type:"array",items:{$ref:"#Agent"},minItems:1}},required:["objectType","member"],additionalProperties:!1},l={id:"#AuthorityGroup",properties:{objectType:{type:"string",enum:["Group"]},name:{type:"string",chance:{name:null}},member:{type:"array",items:[{$ref:"#Agent"},{$ref:"#Agent"}],additionalItems:!1,minItems:2}},required:["objectType","member"],additionalProperties:!1},d={id:"#IdentifiedGroupMbox",type:"object",properties:{objectType:{type:"string",enum:["Group"]},name:{type:"string",chance:{name:null}},member:{type:"array",items:{$ref:"#Agent"},minItems:1},mbox:{type:"string",format:"mbox"}},required:["objectType","mbox"],additionalProperties:!1},u={id:"#IdentifiedGroupMboxSum",type:"object",properties:{objectType:{type:"string",enum:["Group"]},name:{type:"string",chance:{name:null}},member:{type:"array",items:{$ref:"#Agent"},minItems:1},mbox_sha1sum:{type:"string",chance:{hash:[]}}},required:["objectType","mbox_sha1sum"],additionalProperties:!1},p={id:"#IdentifiedGroupAccount",type:"object",properties:{objectType:{type:"string",enum:["Group"]},name:{type:"string",chance:{name:null}},member:{type:"array",items:{$ref:"#Agent"},minItems:1},account:{$ref:"#Account"}},required:["objectType","account"],additionalProperties:!1},h={id:"#IdentifiedGroupOpenId",type:"object",properties:{objectType:{type:"string",enum:["Group"]},name:{type:"string",chance:{name:null}},member:{type:"array",items:{$ref:"#Agent"},minItems:1},openid:{type:"string",format:"uri"}},required:["objectType","openid"],additionalProperties:!1},m={id:"#IdentifiedGroup",oneOf:[{$ref:"#IdentifiedGroupOpenId"},{$ref:"#IdentifiedGroupAccount"},{$ref:"#IdentifiedGroupMboxSum"},{$ref:"#IdentifiedGroupMbox"}]},f=["bn-BD","bn-IN","zh-CN","zh-TW","zh-HK","en-GB","en-US","en-CA","en-IN","pt-PT","pt-BR","es-ES","es-MX","es-AR","es-CO","es-CL","ta-LK","de","tlh"];var y="^(((en-GB-oed|i-ami|i-bnn|i-default|i-enochian|i-hak|i-klingon|i-lux|i-mingo|i-navajo|i-pwn|i-tao|i-tay|i-tsu|sgn-BE-FR|sgn-BE-NL|sgn-CH-DE)|(art-lojban|cel-gaulish|no-bok|no-nyn|zh-guoyu|zh-hakka|zh-min|zh-min-nan|zh-xiang))|((([A-Za-z]{2,3}(-([A-Za-z]{3}(-[A-Za-z]{3}){0,2}))?)|[A-Za-z]{4}|[A-Za-z]{5,8})(-([A-Za-z]{4}))?(-([A-Za-z]{2}|[0-9]{3}))?(-([A-Za-z0-9]{5,8}|[0-9][A-Za-z0-9]{3}))*(-([0-9A-WY-Za-wy-z](-[A-Za-z0-9]{2,8})+))*(-(x(-[A-Za-z0-9]{1,8})+))?)|(x(-[A-Za-z0-9]{1,8})+))$";let g={id:"#LanguageMap",type:"object",properties:{"sr-Latn-RS":{type:"string"}},patternProperties:{},minProperties:1,additionalProperties:!1};g.patternProperties[y]={type:"string",chance:{pickone:f}},g.patternProperties["^[a-z]{2,3}$"]={type:"string",chance:{pickone:f}};let b={id:"#Verb",properties:{id:{type:"string",format:"uri"},display:{$ref:"#LanguageMap"}},required:["id"],additionalProperties:!1},v={type:"object",id:"#Account",properties:{homePage:{type:"string",format:"uri"},name:{type:"string",chance:{name:null}}},required:["homePage","name"],additionalProperties:!1},x={id:"#Agent",oneOf:[{$ref:"#AgentOpenId"},{$ref:"#AgentAccount"},{$ref:"#AgentMboxSum"},{$ref:"#AgentMbox"}]},w={id:"#AgentOpenId",type:"object",properties:{objectType:{type:"string",enum:["Agent"]},name:{type:"string",chance:{name:null}},openid:{type:"string",format:"uri"}},required:["openid"],additionalProperties:!1},A={id:"#AgentAccount",type:"object",properties:{objectType:{type:"string",enum:["Agent"]},name:{type:"string",chance:{name:null}},account:{$ref:"#Account"}},required:["account"],additionalProperties:!1},S={id:"#AgentMboxSum",type:"object",properties:{objectType:{type:"string",enum:["Agent"]},name:{type:"string",chance:{name:null}},mbox_sha1sum:{type:"string",chance:{hash:null}}},required:["mbox_sha1sum"],additionalProperties:!1},j={id:"#AgentMbox",type:"object",properties:{objectType:{type:"string",enum:["Agent"]},name:{type:"string",chance:{name:null}},mbox:{type:"string",format:"mbox"}},required:["mbox"],additionalProperties:!1},P={type:"object",id:"#Extensions",patternProperties:{},additionalProperties:!1};P.patternProperties["([A-Za-z][A-Za-z0-9+\\-.]*):(?:(//)(?:((?:[A-Za-z0-9\\-._~!$&'()*+,;=:]|%[0-9A-Fa-f]{2})*)@)?((?:\\[(?:(?:(?:(?:[0-9A-Fa-f]{1,4}:){6}|::(?:[0-9A-Fa-f]{1,4}:){5}|(?:[0-9A-Fa-f]{1,4})?::(?:[0-9A-Fa-f]{1,4}:){4}|(?:(?:[0-9A-Fa-f]{1,4}:){0,1}[0-9A-Fa-f]{1,4})?::(?:[0-9A-Fa-f]{1,4}:){3}|(?:(?:[0-9A-Fa-f]{1,4}:){0,2}[0-9A-Fa-f]{1,4})?::(?:[0-9A-Fa-f]{1,4}:){2}|(?:(?:[0-9A-Fa-f]{1,4}:){0,3}[0-9A-Fa-f]{1,4})?::[0-9A-Fa-f]{1,4}:|(?:(?:[0-9A-Fa-f]{1,4}:){0,4}[0-9A-Fa-f]{1,4})?::)(?:[0-9A-Fa-f]{1,4}:[0-9A-Fa-f]{1,4}|(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))|(?:(?:[0-9A-Fa-f]{1,4}:){0,5}[0-9A-Fa-f]{1,4})?::[0-9A-Fa-f]{1,4}|(?:(?:[0-9A-Fa-f]{1,4}:){0,6}[0-9A-Fa-f]{1,4})?::)|[Vv][0-9A-Fa-f]+\\.[A-Za-z0-9\\-._~!$&'()*+,;=:]+)\\]|(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)|(?:[A-Za-z0-9\\-._~!$&'()*+,;=]|%[0-9A-Fa-f]{2})*))(?::([0-9]*))?((?:/(?:[A-Za-z0-9\\-._~!$&'()*+,;=:@]|%[0-9A-Fa-f]{2})*)*)|/((?:(?:[A-Za-z0-9\\-._~!$&'()*+,;=:@]|%[0-9A-Fa-f]{2})+(?:/(?:[A-Za-z0-9\\-._~!$&'()*+,;=:@]|%[0-9A-Fa-f]{2})*)*)?)|((?:[A-Za-z0-9\\-._~!$&'()*+,;=:@]|%[0-9A-Fa-f]{2})+(?:/(?:[A-Za-z0-9\\-._~!$&'()*+,;=:@]|%[0-9A-Fa-f]{2})*)*)|)(?:\\?((?:[A-Za-z0-9\\-._~!$&'()*+,;=:@/?]|%[0-9A-Fa-f]{2})*))?(?:\\#((?:[A-Za-z0-9\\-._~!$&'()*+,;=:@/?]|%[0-9A-Fa-f]{2})*))?"]={};let I={type:"array",id:"#InteractionData",items:{type:"object",properties:{id:{type:"string",chance:{hash:null}},description:{$ref:"#LanguageMap"}},additionalProperties:!1}},T={id:"#Definition",type:"object",dependencies:{correctResponsesPattern:["interactionType"],choices:["interactionType"],source:["interactionType"],target:["interactionType"],steps:["interactionType"],scale:["interactionType"]},properties:{name:{$ref:"#LanguageMap"},description:{$ref:"#LanguageMap"},type:{type:"string",format:"uri"},moreInfo:{type:"string",format:"uri"},extensions:{$ref:"#Extensions"},interactionType:{type:"string",enum:["true-false","choice","fill-in","long-fill-in","likert","matching","performance","sequencing","numeric","other"]},correctResponsesPattern:{type:"array",items:{type:"string",chance:{word:null}}},choices:{$ref:"#InteractionData"},steps:{$ref:"#InteractionData"},target:{$ref:"#InteractionData"},source:{$ref:"#InteractionData"},scale:{$ref:"#InteractionData"}},additionalProperties:!1},$={id:"#Activity",type:"object",properties:{id:{type:"string",format:"uri"},objectType:{type:"string",enum:["Activity"]},definition:{$ref:"#Definition"}},required:["id"],additionalProperties:!1},q={id:"#StatementRef",type:"object",properties:{objectType:{type:"string",enum:["StatementRef"]},id:{type:"string",format:"uuid"}},required:["objectType","id"],additionalProperties:!1},E={type:"object",id:"#ObjectAgent",allOf:[{$ref:"#Agent"}],properties:{objectType:{type:"string",enum:["Agent"]}},required:["objectType"]},D={type:"object",id:"#ObjectAnonymousGroup",allOf:[{$ref:"#AnonymousGroup"}],properties:{objectType:{type:"string",enum:["Group"]}},required:["objectType"]},O={type:"object",id:"#ObjectIdentifiedGroup",allOf:[{$ref:"#IdentifiedGroup"}],properties:{objectType:{type:"string",enum:["Group"]}},required:["objectType"]},R={id:"#Actor",oneOf:[{$ref:"#Agent"},{$ref:"#AnonymousGroup"},{$ref:"#IdentifiedGroup"}]},L={id:"#Object",oneOf:[{$ref:"#SubStatement"},{$ref:"#Activity"},{$ref:"#ObjectAgent"},{$ref:"#ObjectAnonymousGroup"},{$ref:"#ObjectIdentifiedGroup"},{$ref:"#StatementRef"}]},_={id:"#Score",type:"object",properties:{scaled:{type:"number",minimum:-1,maximum:1},raw:{type:"number"},min:{type:"number"},max:{type:"number"}},additionalProperties:!1},C={id:"#Result",type:"object",minProperties:1,properties:{score:{$ref:"#Score"},success:{type:"boolean"},completion:{type:"boolean"},response:{type:"string",chance:{word:[4]}},duration:{type:"string",format:"iso8601"},extensions:{$ref:"#Extensions"}},additionalProperties:!1},F={id:"#Instructor",oneOf:[{$ref:"#Agent"},{$ref:"#AnonymousGroup"},{$ref:"#IdentifiedGroup"}]},M={id:"#Team",oneOf:[{$ref:"#AnonymousGroup"},{$ref:"#IdentifiedGroup"}]},k={id:"#Context",type:"object",minProperties:1,properties:{registration:{type:"string",format:"uuid"},instructor:{$ref:"#Instructor"},team:{$ref:"#Team"},revision:{type:"string",chance:{word:null}},platform:{type:"string",chance:{company:null}},language:{type:"string",pattern:y},statement:{$ref:"#StatementRef"},extensions:{$ref:"#Extensions"},contextActivities:{type:"object",additionalProperties:!1,properties:{parent:{oneOf:[{type:"array",items:{$ref:"#Activity"},minItems:1,maxItems:10},{$ref:"#Activity"}]},grouping:{oneOf:[{type:"array",items:{$ref:"#Activity"},minItems:1,maxItems:10},{$ref:"#Activity"}]},category:{oneOf:[{type:"array",items:{$ref:"#Activity"},minItems:1,maxItems:10},{$ref:"#Activity"}]},other:{oneOf:[{type:"array",items:{$ref:"#Activity"},minItems:1,maxItems:10},{$ref:"#Activity"}]}}}},additionalProperties:!1},U={type:"object",id:"#Attachment",properties:{usageType:{type:"string",format:"uri"},display:{$ref:"#LanguageMap"},description:{$ref:"#LanguageMap"},contentType:{type:"string",faker:{mimeType:null}},length:{type:"number",minimum:0},sha2:{type:"string",chance:{hash:null}},fileUrl:{type:"string",format:"uri"}},required:["usageType","display","contentType","length","sha2"],additionalProperties:!1},N={id:"#Authority",oneOf:[{$ref:"#Agent"},{$ref:"#AuthorityGroup"}]},z={id:"#Statement",type:"object",properties:{id:{type:"string",format:"uuid"},actor:R,verb:{$ref:"#Verb"},object:{$ref:"#Object"},result:C,context:k,timestamp:{type:"string",format:"date-time"},stored:{type:"string",format:"date-time"},authority:{$ref:"#Authority"},version:{type:"string",pattern:"1\\.0\\.[0-9]+"},attachments:{type:"array",items:{$ref:"#Attachment"}}},additionalProperties:!1,required:["actor","verb","object"]},G={id:"#SubStatementObject",oneOf:[{$ref:"#Activity"},{$ref:"#ObjectAgent"},{$ref:"#ObjectAnonymousGroup"},{$ref:"#ObjectIdentifiedGroup"},{$ref:"#StatementRef"}]},H={id:"#SubStatement",type:"object",properties:{objectType:{type:"string",enum:["SubStatement"]},actor:R,verb:{$ref:"#Verb"},object:{$ref:"#SubStatementObject"},result:C,context:k,timestamp:{type:"string",format:"date-time"},attachments:{type:"array",items:{$ref:"#Attachment"}}},additionalProperties:!1,required:["actor","verb","object","objectType"]},B={id:"#PostedStatement",type:"object",properties:{objectType:{type:"string",enum:["SubStatement"]},id:{type:"string",format:"uuid"},actor:R,verb:{$ref:"#Verb"},stored:{type:"string",format:"date-time"},authority:{$ref:"#Authority"},object:L,result:C,context:k,timestamp:{type:"string",format:"date-time"},version:{oneOf:[{type:"string",pattern:"1.0.[0-9]+"},{type:"string",enum:["1.0"]}]},attachments:{type:"array",items:{$ref:"#Attachment"}}},additionalProperties:!1,required:["actor","verb","object"]},Z={oneOf:[{$ref:"#PostedStatement"},{type:"array",items:{$ref:"#PostedStatement"}}]},V={type:"object",properties:{agent:x},required:["agent"],additionalProperties:!1},J={id:"#QueryStatements",type:"object",properties:{statementId:{type:"string",format:"uuid"},voidedStatementId:{type:"string",format:"uuid"},agent:{oneOf:[{$ref:"#Agent"},{$ref:"#IdentifiedGroup"}]},verb:{type:"string",format:"uri"},activity:{type:"string",format:"uri"},registration:{type:"string",format:"uuid"},related_activities:{type:"boolean",default:!1},related_agents:{type:"boolean",default:!1},since:{type:"string",format:"date-time"},until:{type:"string",format:"date-time"},limit:{type:"integer",minimum:0,default:0},format:{type:"string",enum:["ids","exact","canonical"],default:"exact"},attachments:{type:"boolean"},ascending:{type:"boolean"}},additionalProperties:!1};i.addFormat("mbox",/mailto\:[-_a-zA-Z0-9\.]+@[-_a-zA-Z0-9]+\.[a-zA-Z0-9]{2,20}/),i.addFormat("iso8601",function(e){return new RegExp("^(-?)P(?=\\d|T\\d)(?:(\\d+)Y)?(?:(\\d+)M)?(?:(\\d+)([DW]))?(?:T(?:(\\d+)H)?(?:(\\d+)M)?(?:(\\d+(?:\\.\\d+)?)S)?)?$").test(e)}),i.addSchema(g),i.addSchema(P),i.addSchema(c),i.addSchema(d),i.addSchema(u),i.addSchema(h),i.addSchema(p),i.addSchema(m),i.addSchema(v),i.addSchema(L),i.addSchema(j),i.addSchema(S),i.addSchema(w),i.addSchema(A),i.addSchema(x),i.addSchema(b),i.addSchema(T),i.addSchema($),i.addSchema(q),i.addSchema(_),i.addSchema(C),i.addSchema(k),i.addSchema(U),i.addSchema(z),i.addSchema(B),i.addSchema(J),i.addSchema(I),i.addSchema(H),i.addSchema(E),i.addSchema(O),i.addSchema(D),i.addSchema(l),i.addSchema(F),i.addSchema(M),i.addSchema(N),i.addSchema(G);let X=new r({coerceTypes:!0,format:"full",jsonPointers:!0});X.addSchema(g),X.addSchema(j),X.addSchema(S),X.addSchema(w),X.addSchema(A),X.addSchema(x),X.addSchema(v),X.addSchema(d),X.addSchema(u),X.addSchema(h),X.addSchema(p),X.addSchema(m),X.addSchema(F),X.addSchema(M),X.addSchema(N),X.addSchema(G),X.addFormat("mbox",/mailto\:[-_a-zA-Z0-9\.]+@[-_a-zA-Z0-9]+\.[a-zA-Z0-9]{2,20}/),X.addSchema(L);let W=i.compile(z),Q=i.compile(Z),Y=X.compile(J),K=X.compile({type:"object",properties:{activityId:{type:"string",format:"uri"},stateId:{type:"string"},agent:{type:"object"},registration:{type:"string",format:"uuid"},since:{type:"string",format:"date-time"}},required:["activityId","agent"],additionalProperties:!1}),ee=i.compile({type:"object",properties:{profileId:{type:"string"},agent:{type:"object"},since:{type:"string",format:"date-time"}},required:["agent"],additionalProperties:!1}),te=i.compile({type:"object",properties:{statementId:{type:"string",format:"uuid"}},required:["statementId"],additionalProperties:!1}),ne=i.compile(g),re=i.compile($),ie=i.compile({type:"object",properties:{profileId:{type:"string"},activityId:{type:"string",format:"uri"},since:{type:"string",format:"date-time"}},required:["activityId"],additionalProperties:!1}),ae=i.compile(V),oe=i.compile({type:"object",properties:{activityId:{type:"string",format:"uri"}},required:["activityId"],additionalProperties:!1});function se(e){for(var t in e)if(e[t]&&e[t].trim&&"{"==e[t].trim()[0])try{e[t]=JSON.parse(e[t])}catch(e){}}let ce=s({schema:z,mode:"return",indent:2});e.exports.validateStatement=function(e){return{valid:W(e),error:ce(e,W.errors)}};let le=s({schema:Z,mode:"return",indent:2});e.exports.validatePayload=function(e){return{valid:Q(e),error:le(e,Q.errors)}},e.exports.validateQuery=function(e){return se(e),{valid:Y(e),error:i.errorsText(Y.errors,{verbose:!0})}},e.exports.validateActivityProfile=function(e){return se(e),{valid:ie(e),error:i.errorsText(ie.errors,{verbose:!0})}},e.exports.validateActivityState=function(e){return se(e),{valid:K(e),error:i.errorsText(K.errors,{verbose:!0})}},e.exports.validateAgentQuery=function(e){return se(e),{valid:ae(e),error:i.errorsText(ae.errors,{verbose:!0})}},e.exports.validateActivityQuery=function(e){return se(e),{valid:oe(e),error:i.errorsText(oe.errors,{verbose:!0})}},e.exports.validateAgentProfile=function(e){return se(e),{valid:ee(e),error:i.errorsText(ee.errors,{verbose:!0})}},e.exports.validatePut=function(e){return{valid:te(e),error:i.errorsText(te.errors,{verbose:!0})}},e.exports.isLangMap=function(e){return ne(e)},e.exports.isActivity=function(e){return re(e)};const de=n(17);let ue=[g,P,c,m,v,x,b,T,$,q,_,C,k,U,z,j,S,w,A,L,d,u,h,p,F,M,N,G,B,J,I,H,E,O,D,l];de.format("mbox",function(){return"mailto:"+o.email()}),de.extend("chance",function(){return o}),de.format("uuid",function(){return n(3).v4()}),de.format("uri",function(){return o.url()}),de.format("iso8601",function(){var e=new RegExp("^(-?)P(?=\\d|T\\d)(?:(\\d+)Y)?(?:(\\d+)M)?(?:(\\d+)([DW]))?(?:T(?:(\\d+)H)?(?:(\\d+)M)?(?:(\\d+(?:\\.\\d+)?)S)?)?$");return de.random.randexp(e)});let pe={};for(var he in ue)pe[ue[he].id]=ue[he];function me(e,t){for(let n in t)if(t[n].id==e)return JSON.parse(JSON.stringify(t[n]));console.log("could not deref ",e,t)}function fe(e,t,n){return n.indexOf(e)===t}function ye(e,t,n,r){if("string"!=typeof e){for(var i in e)if("oneOf"==i&&e[i][0].$ref){let t=e[i][Math.floor(Math.random()*e[i].length)];e.$ref=t.$ref,delete e[i]}else ye(e[i],e,i,r);return e}}n(18);e.exports.randomStatement=function(e){let t=ue.map(e=>ye(JSON.parse(JSON.stringify(e))));return new Promise((e,n)=>{let r=ye(JSON.parse(JSON.stringify(z)));(function e(t){if("string"!=typeof t&&t){for(let n in t)e(t[n]);if(t.properties){let e=Object.keys(t.properties);e=o.pickset(e,Math.floor(Math.random()*e.length+.5)),e=(t.required||[]).concat(e).filter(fe),t.required=e}}})(r=function e(t,n,r){if(!t)return t;if("string"==typeof t)return t;for(let r in t.properties)t.properties[r].$ref&&(t.properties[r]=e(me(t.properties[r].$ref,n),n,r)),t.properties[r].oneOf&&(t.properties[r]=t.properties[r].oneOf[0]);for(let r in t)t[r]&&(t[r].$ref&&(t[r]=e(me(t[r].$ref,n),n,r)),t[r].oneOf&&(t[r]=t[r].oneOf[0]),e(t[r],n,r));return t.$ref&&(t=e(me(t.$ref,n),n,"$ref")),t}(r,t)),de.resolve(r,t).then(function(t){(a.get(t,"object.definition.correctResponsesPattern")||a.get(t,"object.definition.choices")||a.get(t,"object.definition.source")||a.get(t,"object.definition.target")||a.get(t,"object.definition.steps")||a.get(t,"object.definition.scale"))&&a.set(t,"object.definition.interactionType",o.pickone(["true-false","choice","fill-in","long-fill-in","likert","matching","performance","sequencing","numeric","other"])),e(t)})})},e.exports.parseJSONQuery=se},function(e,t){e.exports={AccountError:class extends Error{constructor(e){super(e)}},ClientError:class extends Error{constructor(e){super(e),this.err=e}},ConflictError:class extends Error{constructor(e){super(e)}},PreconditionError:class extends Error{constructor(e){super(e)}},ServerError:class extends Error{constructor(e){super(e)}},NotFoundError:class extends Error{constructor(e){super(e)}}}},function(e,t){e.exports=require("uuid")},function(e,t){e.exports=require("mongodb")},function(e,t,n){const r=n(4).MongoClient,i=n(4),a=n(3),{URL:o}=n(6);function s(e,t,r){"use strict";t=t||function(){return null},r=r||function(){return null};var i=n(30);return function e(n){return i(n,function(n,i,a){!1!==t(n,i,a)&&n instanceof Object&&(e(n),r(n,i,a))}),n}(e)}const c=n(1),l=n(31),d=n(32),u=n(7),{ClientError:p,ConflictError:h,PreconditionError:m,ServerError:f,NotFoundError:y}=n(2),g=n(33),b=function(e,t,n){t.indexOf(".")>-1&&(n[t.replace(/\./g,"*`*")]=e,delete n[t])},v=function(e,t,n){t.indexOf("*`*")>-1&&(n[t.replace(/\*`\*/g,".")]=e,delete n[t])},x=function(e){return e.mbox?e.mbox:e.mbox_sha1sum?e.mbox_sha1sum:e.openid?e.openid:e.account?u(e.account):e.member?u(e):void 0},w=function(e){return e.id?e.id:void 0},A=function e(t){let n=[];for(let r in t)void 0!==t[r]&&(x(t[r])&&n.push(x(t[r])),t[r].member&&(n=n.concat(e(t[r].member))));return n},S=function(e){let t=[];for(let n in e)if(void 0!==e[n]){if(w(e[n])&&t.push(w(e[n])),e[n].grouping)for(let r in e[n].grouping)t.push(w(e[n].grouping[r]));if(e[n].parent)for(let r in e[n].parent)t.push(w(e[n].parent[r]));if(e[n].category)for(let r in e[n].category)t.push(w(e[n].category[r]));if(e[n].other)for(let r in e[n].other)t.push(w(e[n].other[r]))}return t},j=function(e){if(e.statementId&&e.voidedStatementId)throw new p("The LRS MUST reject with a 400 Bad Request error any requests to this resource which contain both statementId and voidedStatementId parameters");if(e.statementId||e.voidedStatementId){let t=JSON.parse(JSON.stringify(e));if(delete t.statementId,delete t.voidedStatementId,delete t.attachments,delete t.format,0!==Object.keys(t).length)throw new p('The LRS MUST reject with an 400 Bad Request error any requests to this resource which contain statementId or voidedStatementId parameters, and also contain any other parameter besides "attachments" or "format"')}let t={};return t.voided=!1,t.provisional=!1,this.preferRead||(delete t.voided,delete t.provisional),e.statementId&&(t.id=e.statementId,t.voided=!1),e.voidedStatementId&&(t.id=e.voidedStatementId,t.voided=!0),e.agent&&(e.agent=x(e.agent),t.agent=e.agent),e.verb&&(t.verb=e.verb),e.activity&&(t.activity=e.activity),e.registration&&(t.registration=e.registration),e.related_activities&&(delete t.activity,t.relatedActivities=e.activity),e.related_agents&&(delete t.agent,t.relatedAgents=e.agent),e.since&&e.until?t.$and=[{"statement.stored":{$gt:new Date(e.since)}},{"statement.stored":{$lt:new Date(e.until)}}]:e.since?t["statement.stored"]={$gt:new Date(e.since)}:e.until&&(t["statement.stored"]={$lt:new Date(e.until)}),t},P=function e(t){try{new o(t.verb.id),t.object.verb&&e(t.object)}catch(e){throw new p(e.message+"in Verb ID")}},I=function e(t){if(t.context){if(t.context.revision&&t.object.objectType&&"Activity"!==t.object.objectType)throw new p('A Statement cannot contain both a "revision" property in its "context" property and have the value of the "object" property\'s "objectType" be anything but "Activity"');if(t.context.platform&&t.object.objectType&&"Activity"!==t.object.objectType)throw new p('A Statement cannot contain both a "platform" property in its "context" property and have the value of the "object" property\'s "objectType" be anything but "Activity"');if(t.context.contextActivities){let e=["grouping","parent","category","other"],r=t.context.contextActivities;for(var n in e)r[e[n]]&&r[e[n]].constructor==Object&&(r[e[n]]=[r[e[n]]])}}t.object.context&&e(t.object)},T=function e(t){if(t.result&&t.result.score){let e=t.result.score.min,n=t.result.score.max,r=(t.result.score.scaled,t.result.score.raw);if(void 0!==e&&void 0!==r&&r<e)throw new p("raw is less than min");if(void 0!==n&&void 0!==r&&r>n)throw new p("raw is greater than max");if(void 0!==e&&void 0!==n&&n<e)throw new p("max is less than min");if(void 0!==e&&void 0!==n&&n<e)throw new p("max is less than min")}t.object.result&&e(t.object)},$=function e(t){t.authority,t.object.authority&&e(t.object)},q=function(e){return 0==e.indexOf("http://adlnet.gov/expapi/verbs/voided")},E=function(e,t){for(var n in t)"objectType"!=n&&e[n]&&-1==e[n].indexOf(t[n])&&e[n].push(t[n]);return e};function D(e,t,n){return n.indexOf(e)===t}let O=n(8).EventEmitter;e.exports=class extends O{constructor(e,t=!0,n=!0){super(),this.connectionString=e,this.strict=t,this.preferRead=n,r.connect(e,(e,t)=>{e?console.log(e):(this.db=t,this.statements=t.collection("statements"),this.userLogs=t.collection("userLogs"),this.accessLogs=t.collection("accessLogs"),this.moreLinks=t.collection("moreLinks"),this.state=t.collection("state"),this.activityProfile=t.collection("activityProfile"),this.agentProfile=t.collection("agentProfile"),this.attachments=t.collection("attachments"),this.userLogs.createIndex({id:1}),this.userLogs.createIndex({when:1}),this.userLogs.createIndex({type:1}),this.statements.createIndex({id:1},{unique:!0}),this.statements.createIndex({agent:1}),this.statements.createIndex({verb:1}),this.statements.createIndex({activity:1}),this.statements.createIndex({registration:1}),this.statements.createIndex({relatedActivities:1}),this.statements.createIndex({relatedAgents:1}),this.statements.createIndex({voided:1}),this.statements.createIndex({voids:1}),this.statements.createIndex({provisional:1}),this.statements.createIndex({"statement.stored":1}),this.statements.createIndex({"statement.stored":-1}),this.statements.createIndex({"statement.timestamp":1}),this.statements.createIndex({"statement.object.id":1}),this.statements.createIndex({"statement.object.objectType":1}),this.statements.createIndex({"statement.actor.id":1}),this.statements.createIndex({"statement.actor.mbox":1}),this.statements.createIndex({"statement.registration":1}),this.activityProfile.createIndex({id:1}),this.activityProfile.createIndex({contextID:1}),this.agentProfile.createIndex({id:1}),this.agentProfile.createIndex({contextID:1}),this.state.createIndex({id:1}),this.state.createIndex({contextID:1}),this.attachments.createIndex({xApiHash:1}),this.moreLinks.createIndex({id:1}),this.moreLinks.createIndex({createdOn:1}),this.ready=!0,this.emit("ready"))})}shutdown(){this.db&&this.db.close()}async userLog(e,t,n,r){if(e.constructor!==String)throw new Error("Error in logger");if(t&&t.constructor!==String)throw new Error("Error in logger");if(r&&r.constructor!==String)throw new Error("Error in logger");n&&s(n,b),await this.userLogs.insert({type:e,message:t,context:n,id:r,when:new Date(Date.now())})}async log(e,t,n,r){this.verbose&&this.userLog(e,t,n,r),this.accessLog(e)}async accessLog(e){let t;if("string"!=typeof e&&(e=e.constructor.name),["storeStatements","storeAttachment","storeDocument"].indexOf(e)>-1?t="store":["getStatements","getAttachment","getDocument"].indexOf(e)>-1?t="get":["ClientError","ConflictError","NotFoundError","ServerError","AccountError"].indexOf(e)>-1?t="error":console.log("unknown log type",e),t){let e=new Date;e=new Date(g(e,"mm/dd/yyyy hh:01")),await this.accessLogs.update({when:e,type:t},{$inc:{value:1}},{upsert:!0})}}async getActivity(e){let t=await this.statements.find({activity:e}).limit(100).toArray(),n={objectType:"Activity",id:e};for(let r in t)t[r].statement.object.id==e&&(n=l(n,t[r].statement.object));return s(n,v),this.log("getActivity",null,null,e),n}async getAgentAsPerson(e){let t={},n=x(e),r={objectType:"Person",mbox:[],mbox_sha1sum:[],account:[],openid:[],name:[]};t.agent=n;let i=await this.statements.find(t,{"statement.actor":1}).limit(100).toArray();for(let e in i)if(x(i[e].statement.actor)==n&&(r=E(r,i[e].statement.actor)),i[e].statement.actor.members)for(let t in i[e].statement.actor.members){let a=i[e].statement.actor.members[t];x(a)==n&&(r=E(r,a))}return this.log("getAgent",null,null,n),r}async voidTargets(e){let t=e.filter(e=>q(e.verb.id)).map(e=>e.object.id);t.length>0&&await this.statements.update({id:{$in:t}},{$set:{voided:!0}})}async storeAttachment(e){try{let t={};t.xApiHash=e.xApiHash,t.contentType=e.contentType,t.data=new i.Binary(e.data);await this.attachments.replaceOne({xApiHash:t.xApiHash},t,{upsert:!0});this.log("storeAttachment",null,null,t.xApiHash)}catch(e){throw e}}async getAttachment(e){let t=await this.attachments.find({xApiHash:e}).toArray();return t&&t[0]?(t[0].data=t[0].data.read(0,t[0].data.length),this.log("getAttachment",null,null,e),t[0]):void 0}async testForVoidingRequirements(e){for(let t in e){let n=e[t];if(q(n.verb.id)){if("StatementRef"!==n.object.objectType)throw new p('A Voiding Statements "objectType" field has a value of "StatementRef"');let e=n.object.id,t=await this.statements.find({id:e},{id:1,verb:1}).toArray();if(t&&t.length>0){let e=t[0];if(q(e.verb[0]))throw new p("A Voiding Statement cannot Target another Voiding Statement:should not void a voiding statement");if(e.voided)throw new p("A Voiding Statement cannot Target another Voiding Statement:should not void an already voided statement")}}}}async _updateMongoStatementsWhichRef(e){let t={$push:{agent:{$each:e.agent},verb:e.verb[0]}};e.registration[0]&&(t.$push={registration:e.registration[0]}),e.activity[0]&&(t.$push={activity:e.activity[0]}),await this.statements.update({"statement.object.objectType":"StatementRef","statement.id":e.id},t)}async _getMongoStatementById(e){var t=await this.statements.find({id:e}).toArray();return t[0]}async updateReferences(e){for(let r in e){let i=e[r];if(this.strict&&await this._updateMongoStatementsWhichRef(i),"StatementRef"==i.statement.object.objectType){let e=await this._getMongoStatementById(i.statement.object.id);t=i,(n=e)&&(t.agent=t.agent.concat(n.agent),t.activity=t.activity.concat(n.activity),t.registration=t.registration.concat(n.registration),t.relatedAgents=t.relatedAgents.concat(n.relatedAgents),t.relatedActivities=t.relatedActivities.concat(n.relatedActivities))}}var t,n}statementsToMongoForm(e){let t=[];for(let n in e){let r=e[n],i={};i.statement=r,i.id=r.id,i.agent=A([r.actor]),r.object.objectType&&"Agent"==r.object.objectType&&"Group"==r.object.objectType&&(i.agent=i.agent.concat(A([r.object]))),i.statement.actor.id=i.agent[0],i.verb=[r.verb.id],i.activity=[],c.isActivity(r.object)&&(i.activity=S([r.object])),i.registration=[],r.context&&r.context.registration&&i.registration.push(r.context.registration),i.relatedAgents=A([r.actor,r.object]),i.relatedActivities=S([r.object,r.context]),r.object.objectType&&"SubStatement"==r.object.objectType&&(i.relatedAgents=i.relatedAgents.concat(A([r.object.actor])),i.relatedActivities=i.relatedActivities.concat(S([r.object.object])),r.object&&r.object.context&&r.object.context.contextActivities&&(i.relatedActivities=i.relatedActivities.concat(S([r.object.context.contextActivities]))),r.context&&r.context.team&&(i.relatedAgents=i.relatedAgents.concat(A([r.context.team]))),r.object.context&&r.object.context.instructor&&(i.relatedAgents=i.relatedAgents.concat(A([r.object.context.instructor])))),r.context&&r.context.instructor&&(i.relatedAgents=i.relatedAgents.concat(A([r.context.instructor]))),r.context&&r.context.team&&(i.relatedAgents=i.relatedAgents.concat(A([r.context.team]))),i.voided=!1,i.voids=null,q(r.verb.id)&&(i.voids=r.object.id),t.push(i)}return t}async testIDCollisions(e){let t=e.map(e=>e.id);if(t.length!==t.filter(D).length)throw new p("The statement batch contains duplicate IDs");let n=await this.statements.find({id:{$in:t}},{_id:1}).toArray();if(n.length>0)throw new p(n.length+" of the statements in the batch have ids that are already in the DB")}async rollBackProvisional(e){await this.statements.remove({id:{$in:e.map(e=>e.id)},provisional:!0})}async isAlreadyVoidedByPreviousStatement(e){for(let t in e)for(let n in e)if(e[n].voids===e[t].id){if(e[t].voided)throw new Error("Statement is voided twice by another statement in the same batch");e[t].voided=!0}let t=await this.statements.find({voids:{$in:e.map(e=>e.id)}},{id:1}).toArray();t=t.map(e=>e.id);for(let n in e)if(t.indexOf(e[n].id)>-1){if(e[n].voided)throw new Error("Statement is voided twice by another statement in the same batch");e[n].voided=!0}}async store(e,t,n){try{if(!this.db)throw new p("DB is not ready");if(!e)throw new p("statementArray is null");if(e.constructor!==Array)throw new p("statementArray is not Array");if(0==e.length)throw new p("statementArray is empty");if(!t)throw new p("authority is mandatory");e.forEach(P),e.forEach(T),e.forEach(I),e.forEach($),e.forEach(e=>(function(e,t){for(let n in e.attachments){let r=e.attachments[n];if("http://adlnet.gov/expapi/attachments/signature"==r.usageType){if("application/octet-stream"!==r.contentType)throw new p("rejects a signed statement with a malformed signature - bad content type. Content-type of signatures should be application/octet-stream");for(let i in t)if(t[i].xApiHash==r.sha2){let r=d.decode(t[i].data.toString("binary"),{complete:!0});if(!r)throw new p("Could not parse signature body");if("RS256"!==r.header.alg&&"RS384"!==r.header.alg&&"RS512"!==r.header.alg)throw new p("signature JWT uses invalid signature algorithm ");let a=JSON.parse(JSON.stringify(e));if(a.attachments.splice(0,n+1),0==a.attachments.length&&delete a.attachments,JSON.stringify(a)!==JSON.stringify(r.payload))throw new p("The statement signed by the signature does not match the statement provided")}}}})(e,n)),await this.testIDCollisions(e),e=e.map(e=>(function(e,t){if(!e)throw new p("statement is null");if(e.constructor!==Object)throw new p("statement is not Object");return e.id||(e.id=a.v4()),e.timestamp?e.timestamp=new Date(e.timestamp):e.timestamp=new Date,e.stored=new Date,e.authority=t,s(e,b),e})(e,t));let i=this.statementsToMongoForm(e);this.strict&&await this.isAlreadyVoidedByPreviousStatement(i),await this.testForVoidingRequirements(e),this.strict&&(i.forEach(e=>e.provisional=!0),await this.statements.insertMany(i));try{this.preferRead&&await this.updateReferences(i),this.strict&&await this.statements.remove({id:{$in:i.map(e=>e.id)},provisional:!0}),i.forEach(e=>e.provisional=!1);await this.statements.insertMany(i);if(await this.voidTargets(e),n)for(var r in n)await this.storeAttachment(n[r]);return this.log("storeStatements",null,e.map(e=>e.id)),!0}catch(t){throw console.log("Something has gone really wrong, and we've thrown in a part of the code that does not use expections for validataion",t),this.strict&&await this.rollBackProvisional(e),t}}catch(t){throw this.strict&&await this.rollBackProvisional(e),t}}async recurseForRefs(e,t){if(!e||0==e.length)return e;let n=e.map(e=>e.statement.id),r={};t["statement.stored"]&&(r["statement.stored"]=t["statement.stored"]),r["statement.object.objectType"]="StatementRef",r["statement.object.id"]={$in:n};let i=await this.statements.find(r,{id:1,statement:1,voided:1}).toArray(),a=await this.recurseForRefs(i,t);return e.concat(a)}async countResults(e){let t=j.call(this,e,{statement:1,id:1}),n=this.statements.find(t);return await n.count(t)}async find(e,t){let n=j.call(this,e,{statement:1,id:1}),r=this.statements.find(n,{id:1,statement:1,voided:1});r=e.ascending?r.sort({"statement.stored":1}):r.sort({"statement.stored":-1});let i=100;e.limit&&(i=Math.min(100,e.limit));let a=i+1;r=r.limit(a),e.page||(e.page=0),r.skip(i*e.page);let o=await r.toArray();return this.preferRead||e.voidedStatementId||e.statementId||(o=await this.recurseForRefs(o,n)),this.preferRead||e.voidedStatementId||(o=function(e){for(var t={},n=0;n<e.length;n++)t[e[n].statement.id]=e[n];var r=[];for(var i in t)r.push(t[i]);return r}(o=o.filter(e=>!e.voided)),e.ascending?o.sort((e,t)=>e.statement.stored-t.statement.stored):o.sort((e,t)=>t.statement.stored-e.statement.stored),o.length>a&&(o=o.slice(0,a))),(o=o.map(e=>e.statement)).forEach(e=>s(e,v)),o.forEach(e=>delete e.actor.id),"exact"!==e.format&&(o=await function(e,t,n){if("ids"==t&&e.forEach(e=>s(e,function(e,t,n){"object"==t&&n[t].id?n[t]={id:n[t].id}:"id"!=t&&"mbox_sha1sum"!=t&&"mbox"!=t&&"openid"!=t&&"account"!=t&&"objectType"!=t&&(n[t]&&n[t].constructor!=Boolean&&n[t].constructor!=String&&n[t].constructor!=Number||delete n[t])},function(e,t,n){"id"!=t&&"mbox_sha1sum"!=t&&"mbox"!=t&&"openid"!=t&&"account"!=t&&"objectType"!=t&&n[t]&&n[t].constructor==Object&&0==Object.keys(n[t]).length&&delete n[t]})),"canonical"==t){let t=n["accept-language"]||"en-US";e.forEach(e=>s(e,function(e,n,r){if("extensions"==n)return!1;c.isLangMap(e)&&(r[n]={},r[n][t]=e[t]||"")}))}return e}(o,e.format,t)),o.forEach(e=>{e.timestamp=e.timestamp.toISOString(),e.stored=e.stored.toISOString()}),o.length>=a&&((o=o.slice(0,e.limit)).more=!0),this.log("getStatements",null,e),e.statementId||e.voidedStatementId?o[0]:o}},e.exports.queryToMongo=j,e.exports.prepStatementForDisplay=function(e){return e.statement&&(e=e.statement),s(e,v),delete e.actor.id,e}},function(e,t){e.exports=require("url")},function(e,t){e.exports=require("object-hash")},function(e,t){e.exports=require("events")},function(e,t,n){if(e.exports=n(10),"-start"==process.argv[2]){let t=e.exports,r=new(n(0));n(53).config();let i=new t.LRS;i.on("clientError",function(e){console.log(e)}),i.on("ready",function(e){console.log("LRS ready")}),i.on("statementStored",function(e){console.log("Statement "+e+" stored"),i.getStatement(e).then(e=>{console.log(e)})});let a=new t({lrs:i,getUser:function(e,n,r){return process.env.username&&process.env.password?n==process.env.username&&r==process.env.password?new t.Account(n,!0,!0):null:new t.Account(n,!0,!0)},connectionString:process.env.connectionString||"mongodb://localhost/myLRS",baseUrl:process.env.baseUrl||"/xapi"});r.use(process.env.baseUrl||"/xapi",a),r.use("/ui",a.simpleUI()),r.get("/",function(e,t){t.redirect("/ui/statements/0")}),r.get("/testinsert",function(e,t){i.insertStatement({actor:{mbox:"mailto:[email protected]",name:"Rob Chadwick",objectType:"Agent"},verb:{id:"http://adlnet.gov/expapi/verbs/answered",display:{"en-US":"answered"}},object:{id:"http://adlnet.gov/expapi/activities/example",definition:{name:{"en-US":"Example Activity"},description:{"en-US":"Example activity description"}},objectType:"Activity"},timestamp:"2018-01-10T15:20:10.978Z",authority:{objectType:"Agent",account:{homePage:"https://localhost:3000/users/test",name:"test"}}}).then(()=>{t.send("inserted")}).catch(e=>{t.send(e.message)})}),r.listen(process.env.port||3e3)}},function(e,t,n){const r=n(0),i=(r.Router,n(11)),a=n(20),o=n(21),s=n(22).BasicStrategy,c=n(23),l=n(24),d=n(26),u=n(27),p=n(28),h=n(29),m=n(5),f=n(34),y=n(37),{AccountError:g,ClientError:b,ConflictError:v,PreconditionError:x,ServerError:w,NotFoundError:A}=n(2);class S{constructor(e,t,n){this.name=e,this.read=t,this.write=n}authority(){let e={};return e.objectType="Agent",e.account={homePage:"https://localhost:3000/users/"+this.name,name:this.name},e}}o.use("basic",new s({passReqToCallback:!0},async function(e,t,n,r){let i=await e.getUser(e,t,n);return r(null,i||null)}));const j=function(e,t,n){return t.set("X-Experience-API-Version","1.0.3"),"1.0.3"===e.get("X-Experience-API-Version")||"1.0.2"===e.get("X-Experience-API-Version")||"1.0.1"===e.get("X-Experience-API-Version")?n():e.get("X-Experience-API-Version")?n("X-Experience-API-Version header is not set correctly"):n("X-Experience-API-Version header is not set")};function P(e,t,n){for(var r in e.headers){var i=r.toLowerCase();e.headers[i]=e.headers[r],r!==i&&delete e.headers[r]}n()}async function I(e,t){if(e.DAL){if(e.lrs.emit)try{e.lrs.emit("clientError",{type:t?t.constructor.name:null,message:t.message,body:e.body,query:e.query})}catch(e){}e.lrs.verboseLogs&&await e.DAL.userLog(t.constructor.name,t.message,{body:e.body,query:e.query}),await e.DAL.accessLog(t.constructor.name)}}function T(e,t,n){if(t.___send)return n();t.___send=t.send,t.send=async function(n){n instanceof b?(await I(e,n),this.status(400),this.___send(n.message)):n instanceof x?(await I(e,n),this.status(412),this.___send(n.message)):n instanceof v?(await I(e,n),this.status(409),this.___send(n.message)):n instanceof w?(await I(e,n),this.status(500),this.___send("An unspecified error occured.")):n instanceof A?(await I(e,n),this.status(404),this.___send(n.message)):n instanceof g?(await I(e,n),this.status(401),this.___send(n.message)):n instanceof Error?(await I(e,n),this.status(500),this.___send("An unspecified error occured.")):t.___send(n)},n()}function $(e,t,n){try{if(!e.query.method)return n();{if("POST"!==e.method)return t.send(new b("An LRS rejects an alternate request syntax not issued as a POST"));if(Object.keys(e.query).length>1)return t.send(new b(" An LRS will reject an alternate request syntax which contains any extra information with error code 400 Bad Request"));let n={},a={};if(("PUT"==e.query.method||"POST"==e.query.method)&&!e.body.content)return t.send(new b("Must include the body parameter 'content' when using ARS with method=POST or method=PUT"));let o=["Authorization","X-Experience-API-Version","Content-Type","Content-Length","If-Match","If-None-Match"];for(var r in o){let t=e.body[o[r]]||e.body[o[r].toLowerCase()];t&&(n[o[r].toLowerCase()]=t,delete e.body[o[r]],delete e.body[o[r].toLowerCase()])}let s=e.body.content;s&&(s=JSON.parse(s)),delete e.body.content;for(var r in e.body)a[r]=e.body[r];n.Host=e.get("host"),n["User-Agent"]=e.headers["user-agent"],n["x-experience-api-version"]||(n["x-experience-api-version"]=e.headers["x-experience-api-version"]),n.authorization||(n.authorization=e.headers.authorization);let c=!!s;var i={url:e.xAPIBaseUrl(e)+e.path,headers:n,method:e.query.method,qs:a,body:s,json:c};d(i).pipe(t)}}catch(e){t.send(e)}}async function q(e,t,n){f.get(e.lrs.uuid,e.lrs.strict,e.lrs.preferRead,function(t,r){e.DAL=r,n()})}async function E(e,t,n){if(!e.preAuth){if(("PUT"==e.method||"POST"==e.method)&&!e.user.write)return t.send(new g("The provided user account does not have write permissions"));if("GET"==e.method&&!e.user.read)return t.send(new g("The provided user account does not have read permissions"))}if(!e.lrs.active)return t.send(new g("This LRS is currently offline."));n()}function D(e){return"function"==typeof e?e:function(){return e}}const O={strict:!0,verboseLogs:!0,preferRead:!1,active:!0,uuid:"myLRS",maxStatements:1e7,maxStorage:1e9},R=function(e,t,n){return new S(t,!0,!0)},L="mongodb://localhost/myLRS",_="/xapi";function C(e){return function(t,n,r){return t.preAuth?r():e(t,n,r)}}e.exports=class extends r.Router{constructor(t){super({mergeParams:!0}),t||(t={});let n=t.lrs||O,r=t.getUser||R,s=t.connectionString||L,d=t.baseUrl||_;n instanceof e.exports.LRS&&(console.log("attaching DB to LRS"),async function(e,t){let n=new m(t,e.strict,e.preferRead);if(e.dal=n,e.emit)try{n.on("ready",()=>e.emit("ready"))}catch(e){}}(n,s),this.simpleUI=function(){return new y(f,n())});let f=s;if(!n||!r||!d)throw new Error("invalid parameters in constructor.");if(n=D(n),d=D(d),"function"!=typeof r)throw new Error("the second parameter to the xapi constructor must be a user validation function. Static values not supported for this parameter.");this.use(a()),this.get("/about",function(e,t){t.send({version:["1.0.3"]})}),this.use(T),this.use("/",async function(e,t,i){if(e.getUser=r,e.xAPIBaseUrl=d,e.lrs)return i();e.lrs=await n(e),i()}),this.use(P),this.use(o.initialize()),this.use(C(l)),this.use(C(c.json({limit:"100mb"}))),this.use(C(c.text({limit:"100mb"}))),this.use(C(c.urlencoded({limit:"100mb"}))),this.use(C(c.raw({limit:"100mb"}))),this.use($),this.use(C(j)),t.lrs instanceof e.exports.LRS?this.use(function(e,n,r){e.DAL=t.lrs.dal,r()}):this.use(q.bind(this)),this.use(function(e,t,n){if(e.preAuth)return e.user=new S("Launch System",!0,!0),n();o.authenticate("basic",function(r,i){if(!i)return t.status(401).send("invalid login");e.user=i,n()})(e,t,n)}),this.use(C(E)),this.use("/statements",new i),this.use("/activities/state",new u("state","stateId",["activityId","agent","registration"],"validateActivityState",!1,!1)),this.use("/agents/profile",new u("agentProfile","profileId",["agent"],"validateAgentProfile",!0,!0)),this.use("/activities/profile",new u("activityProfile","profileId",["activityId"],"validateActivityProfile",!0,!0)),this.use("/agents",new p),this.use("/activities",new h),this.use(function(e,t,n,r){n.send(new b(e))}),this.attachDAL=q}},e.exports.Account=S,e.exports.LRS=n(52)},function(e,t,n){let r=n(0),i=(new r.Router,n(1)),a=n(19);const{ClientError:o,ConflictError:s,PreconditionError:c,ServerError:l,NotFoundError:d}=n(2),u=function(e,t){return function(n,r,a){var o=i["validate"+e](n[t]);return o.valid?a():a(o.error)}},p=function(e,t,n){return e.body.constructor===Array?n():(e.body=[e.body],n())},h=function(e,t,n){t.set("X-Experience-API-Consistent-Through",(new Date).toISOString()),n()};e.exports=class extends r.Router{constructor(){return super(),this.putStatements=async function(e,t,n){let r,i=e.query.statementId;if(1!==e.body.length)return t.send(new o("Wrong body in PUT. Should be a single statement"));e.body[0].id=i;try{r=await e.DAL.store(e.body,e.user.authority(),e.attachments)}catch(e){return t.send(e)}if(r){if(e.lrs.emit)try{e.lrs.emit("statementStored",i)}catch(e){}return t.status(204).send("")}return t.send(new o(r.error))},this.postStatements=async function(e,t,r){let i,a=[];for(let r in e.body){if(e.body[r].id||(e.body[r].id=n(3).v4()),a.indexOf(e.body[r].id)>-1)return t.send(new o("Collision between statement ids in the batch"));a.push(e.body[r].id)}try{i=await e.DAL.store(e.body,e.user.authority(),e.attachments)}catch(e){return t.send(e)}if(i){if(e.lrs.emit)for(let t in a)try{e.lrs.emit("statementStored",a[t])}catch(e){}return t.status(200).send(a)}return t.send(new o(i.error))},this.populateMore=async function(e,t,n){let r=e.query.id,i=await e.DAL.moreLinks.find({id:r}).toArray();if(i[0])return e.query=i[0].query,n();t.send(new d)},this.genMore=async function(e,t){var r={},i=n(3).v4();return r.id=i,r.query=e,r.when=new Date,void 0===e.page?e.page=0:e.page+=1,await t.moreLinks.insert(r),await t.moreLinks.remove({when:{$lt:new Date(Date.now()-864e5)}}),i},this.getAttachments=async function(e,t){let n=[];for(let r in e.statements)for(let i in e.statements[r].attachments){let a=await t.getAttachment(e.statements[r].attachments[i].sha2);a&&n.push(a)}return n},this.sendWithAttachments=function(e,t,n){const r="\r\n";var i=new a,o={header:"\r\n--"+i.getBoundary()+r+"Content-Type: application/json"+r+r};i.append("statements",JSON.stringify(e),o);for(var s in t)o={header:"\r\n--"+i.getBoundary()+r+"Content-Type: "+t[s].contentType+r+"Content-Transfer-Encoding: binary"+r+"X-Experience-API-Hash: "+t[s].xApiHash+r+r},i.append(s,t[s].data,o);let c=i.getHeaders();c["content-type"]=c["content-type"].replace("multipart/form-data","multipart/mixed");for(var s in c)n.set(s,c[s]);i.pipe(n)},this.getStatements=async function(e,t,r){let i=e.query.attachments,a=null;try{a=await e.DAL.find(e.query,e.headers)}catch(e){return t.send(e)}if(a&&a.constructor!==Array){if(i){let n=await this.getAttachments({statements:[a]},e.DAL);return this.sendWithAttachments(a,n,t)}return t.send(a)}if(a&&a.constructor===Array){let r={statements:a};if(a.more){let t=e.xAPIBaseUrl(e)+"/statements/more";r.more=n(6).parse(t).path+"?id="+await this.genMore(e.query,e.DAL)}if(i){let n=await this.getAttachments(r,e.DAL);return this.sendWithAttachments(r,n,t)}return t.send(r)}return a?t.send(new l("No statement results returned")):t.send(new d("Statement not found"))},this.use(h),this.get("/",u("Query","query"),this.getStatements.bind(this)),this.post("/",u("Payload","body"),p,this.postStatements.bind(this)),this.put("/",u("Payload","body"),u("Put","query"),p,this.putStatements.bind(this)),this.get("/more",this.populateMore.bind(this),this.getStatements.bind(this)),this}}},function(e,t){e.exports=require("iso8601-duration")},function(e,t){e.exports=require("ajv")},function(e,t){e.exports=require("lodash")},function(e,t){e.exports=require("chance")},function(e,t){e.exports=require("better-ajv-errors")},function(e,t){e.exports=require("json-schema-faker")},function(e,t){e.exports=require("util")},function(e,t){e.exports=require("form-data")},function(e,t){e.exports=require("cors")},function(e,t){e.exports=require("passport")},function(e,t){e.exports=require("passport-http")},function(e,t){e.exports=require("body-parser")},function(e,t,n){let r=n(25);const{ClientError:i,ConflictError:a,PreconditionError:o,ServerError:s,NotFoundError:c}=n(2);e.exports=function(e,t,n){if(e.attachments)return n();if(e.lrs.strict&&e.headers["content-type"]&&e.headers["content-type"].indexOf("multipart/form-data")>-1)return t.send(new i("use multipart/mixed instead of multipart/form-data"));var a=e.headers["content-type"]||"";if(0!=a.trim().indexOf("multipart/mixed")&&0!=a.trim().indexOf("multipart/form-data"))return n();{e.headers["content-type"]=a.replace("multipart/mixed","multipart/form-data");var o=new r.Form;let s=[];o.on("part",function(e){let n={data:[],contentType:e.headers["content-type"]||e.headers["Content-Type"],xApiHash:e.headers["x-experience-api-hash"]||e.headers["X-Experience-API-Hash"],encoding:e.headers["content-transfer-encoding"]||e.headers["Content-Transfer-Encoding"]};e.on("data",function(e){n.data.push(e),n.data.reduce(function(e,t){return e+t.length},0)>1e6&&t.send(new i("Upload too large"))}),e.on("end",function(e){n.data=Buffer.concat(n.data),s.push(n)}),e.on("error",function(t){e.resume()})}),o.on("error",function(e){t.send(new i(e.message))}),o.on("close",function(){if("application/json"!==s[0].contentType)return t.send(new i("the first part of a multipart post should be application/json, and should be a Statement or an array of Statements"));try{e.body=JSON.parse(s[0].data)}catch(e){return t.send(new i("Bad json in multipart part 0"))}e.attachments=[];let r={};for(let n=1;n<s.length;n++){if(!s[n].xApiHash)return t.send(new i("multipart uploads must include the custom field X-Experience-API-Hash"));if("binary"!==s[n].encoding)return console.log(s[n].encoding),t.send(new i(') An LRS rejects with error code 400 Bad Request, a PUT or POST Request which uses Attachments, has a "Content Type" header with value "multipart/mixed", and for any part except the first does not have a Header named "Content-Transfer-Encoding" with a value of "binary"'));e.attachments.push(s[n]),r[s[n].xApiHash]=s[n]}let a=[],o={};a=e.body.constructor==Array?e.body:[e.body];for(let e in a)if(a[e].attachments)for(let t in a[e].attachments)o[a[e].attachments[t].sha2]=a[e].attachments[t];for(let e in r)if(!o[e])return t.send(new i("There are attachment in the multipart post that are not refernced by the statements"));for(let e in o)if(!r[e])return t.send(new i("The statements in the multipart post reference attachments that are not present "));n()}),o.parse(e)}}},function(e,t){e.exports=require("multiparty")},function(e,t){e.exports=require("request")},function(e,t,n){const r=n(0).Router,i=n(7);let a=n(1);const o=n(4),{ClientError:s,ConflictError:c,PreconditionError:l,ServerError:d,NotFoundError:u}=n(2);e.exports=class extends r{constructor(e,t,n,r,d,p){super(),this.type=e,this.contextFields=n,this.idField=t,this.validationKey=r,this.useETAGs=p,this.documentStorageCache={},this.requireIdForDelete=d,this.use(function(e,t,n){if(this.documentStorageCache[e.lrs.uuid])e.documentStorage=this.documentStorageCache[e.lrs.uuid];else{let t=e.documentStorage=this.documentStorageCache[e.lrs.uuid]=new class{constructor(e){this.type=e}collection(e){return e[this.type]}prepDocumentForInsert(e,t){return"application/octet-stream"==t?new o.Binary(e):e}prepDocumentForServe(e,t){return"application/octet-stream"==t?e.read(0,e.length):e}async save(e,t,n,r,a){let o={context:n,contextID:i(n),id:t,document:this.prepDocumentForInsert(r,a["content-type"]),contentType:a["content-type"],lastModified:new Date((new Date).valueOf()-2e3)},c=await this.get(e,t,n);if(c)if("application/json"==c.contentType&&"application/json"==a["content-type"])o.document=this.merge(o.document,c.document);else{if("application/json"!=c.contentType&&"application/json"==a["content-type"])throw new s("If the document being posted to the State Resource does not have a Content-Type of application/json and the existing document does, the LRS MUST respond with HTTP status code 400 Bad Request, and MUST NOT update the target document as a result of the request.");if("application/json"==c.contentType&&"application/json"!=a["content-type"])throw new s("If the existing document does not have a Content-Type of application/json but the document being posted to the State Resource does the LRS MUST respond with HTTP status code 400 Bad Request, and MUST NOT update the target document as a result of the request.")}o.tag=i(r),await this.collection(e).replaceOne({contextID:o.contextID,id:o.id},o,{upsert:!0}),e.log("storeDocument",null,o.contextID,t)}async get(e,t,n,r){let a={contextID:i(n),id:t};r&&(a.lastModified={$gte:new Date(r)});let o=await this.collection(e).find(a).toArray();return e.log("getDocument",null,a.contextID,t),o[0]}merge(e,t){let n=Object.assign({},t,e);return n}async delete(e,t,n){let r={contextID:i(n)};t&&(r.id=t),await this.collection(e).remove(r),e.log("deleteDocument",null,r.contextID,t)}async getIds(e,t,n){let r={contextID:i(t)};n&&(r.lastModified={$gt:new Date(n)});let a=await this.collection(e).find(r).toArray();return e.log("getDocumentIDs",null,r.contextID),a.map(e=>e.id)}}(this.type);this.documentStorageCache[e.lrs.uuid]=t}return n()}.bind(this)),this.buildContext=function(e){let t={};for(var n in this.contextFields)e[this.contextFields[n]]&&(t[n]=e[this.contextFields[n]]);return t},this.validate=function(e,t,n){try{this.useETAGs&&("PUT"==e.method||"POST"==e.method||e.method)}catch(e){return t.send(e)}var r=a[this.validationKey](e.query);return r.valid?n():t.send(new s(r.error))},this.etags=async function(e,t,n,r){if(this.useETAGs){n.headers["if-none-match"]&&"*"!==n.headers["if-none-match"]&&(n.headers["if-none-match"]=JSON.parse(n.headers["if-none-match"])),n.headers["if-match"]&&"*"!==n.headers["if-match"]&&(n.headers["if-match"]=JSON.parse(n.headers["if-match"]));let i=await n.documentStorage.get(n.DAL,e,t);if(!i&&"PUT"==n.method&&!n.headers["if-match"]&&!n.headers["if-none-match"])return r.send(new s('A Client making a PUT or POST request to either the Agent Profile Resource or Activity Profile Resource MUST include the "If-Match" header or the If-None-Match header.')),!1;if("PUT"==n.method&&i&&!n.headers["if-none-match"]&&!n.headers["if-match"])return r.send(new c(" If put request is received without either header for a resource that already exists")),!1;if(i&&"*"==n.headers["if-none-match"])return r.send(new l('An LRS responding to a PUT request MUST handle the "If-None-Match" header as described in RFC2616, HTTP 1.1 if it contains "*", in order to to detect when there is a resource present that the Client is not aware of.')),!1;if(i&&n.headers["if-none-match"]&&"*"!==n.headers["if-none-match"]&&i.tag==n.headers["if-none-match"])return r.send(new l('An LRS responding to a PUT request MUST handle the "If-None-Match" header as described in RFC2616, HTTP 1.1 if it contains "*", in order to to detect when there is a resource present that the Client is not aware of.')),!1;if(i&&"*"!==n.headers["if-match"]&&n.headers["if-match"]!==i.tag&&n.headers["if-match"])return r.send(new l('An LRS responding to a PUT request MUST handle the "If-Match" header as described in RFC2616, HTTP 1.1 if it contains an ETag, in order to detect modifications made after the Client last fetched the document.')),!1}return!0},this.get("/",this.validate.bind(this),async(e,t,n)=>{try{let n=e.query[this.idField],r=this.buildContext(e.query);if(n){let i=await e.documentStorage.get(e.DAL,n,r,e.query.since);return i?(t.set("etag",'"'+i.tag+'"'),t.send(e.documentStorage.prepDocumentForServe(i.document,i.contentType))):t.send(new u)}{let n=await e.documentStorage.getIds(e.DAL,r,e.query.since);return t.send(n)}}catch(e){console.log(e),t.send(e)}});let h=["post","put"];h.forEach(e=>{this[e]("/",this.validate.bind(this),async(e,t,n)=>{try{let n=e.query[this.idField],r=this.buildContext(e.query);if(!await this.etags(n,r,e,t))return;return n?(await e.documentStorage.save(e.DAL,n,r,e.body,e.headers),e.lrs.emit&&e.lrs.emit(this.type+"Stored",{id:n,context:r,document:e.body}),t.status(204).send()):t.send(new s("Did not provide an ID to post"))}catch(e){console.log(e),t.send(e)}})}),this.delete("/",this.validate.bind(this),async(e,t,n)=>{try{let n=e.query[this.idField];if(this.requireIdForDelete&&!n)throw new s(`rejects a DELETE request without "${this.idField}" as a parameter with error code 400 Bad Request `);let r=this.buildContext(e.query);return await e.documentStorage.delete(e.DAL,n,r),e.lrs.emit&&e.lrs.emit(this.type+"Deleted",{id:n,context:r}),t.status(204).send()}catch(e){t.send(e)}})}}},function(e,t,n){const r=n(0).Router;let i=n(1);const{ClientError:a,ConflictError:o,PreconditionError:s,ServerError:c,NotFoundError:l}=n(2);e.exports=class extends r{constructor(){super(),this.validate=function(e,t,n){try{var r=i.validateAgentQuery(e.query);if(!r.valid)throw new a(r.error);n()}catch(e){throw e}},this.concurrency=function(e,t,n){return n()},this.get("/",this.validate.bind(this),this.concurrency.bind(this),async(e,t,n)=>{var r=await e.DAL.getAgentAsPerson(e.query.agent);t.send(r)})}}},function(e,t,n){const r=n(0).Router;let i=n(1);const{ClientError:a,ConflictError:o,PreconditionError:s,ServerError:c,NotFoundError:l}=n(2);e.exports=class extends r{constructor(){super(),this.validate=function(e,t,n){try{var r=i.validateActivityQuery(e.query);if(!r.valid)throw new a(r.error);n()}catch(e){throw e}},this.concurrency=function(e,t,n){return n()},this.get("/",this.validate.bind(this),this.concurrency.bind(this),async(e,t,n)=>{var r=await e.DAL.getActivity(e.query.activityId);t.send(r)})}}},function(e,t){e.exports=require("object-foreach")},function(e,t){e.exports=require("deepmerge")},function(e,t){e.exports=require("jsonwebtoken")},function(e,t){e.exports=require("dateformat")},function(e,t,n){let r=[];const i=n(5);e.exports={get:function(e,t=!0,n=!1,a){let o=r[e];if(o&&o.dal.strict==t&&o.dal.preferRead==n){if(o.when=new Date,o.dal.ready)return a(null,o.dal);o.dal.on("ready",()=>a(null,o.dal))}else{let o=this.getConnectionString(e);console.log("---------\n",o,"\n--------------");let s=new i(o,t,n);r[e]={dal:s,when:new Date},s.on("ready",()=>a(null,s))}},getConnectionString:function(e){return process.parsed_env.mongoServer+"/"+e+"?authSource=admin"},shutdown(){for(let e in r)r[e].dal.shutdown(),delete r[e]}},setInterval(()=>{let e=n(35);n(36);for(let t in r){let n=r[t].when;new Date-n>e(process.env.closeConnectionsAfter||"2 minutes")&&(r[t].dal.shutdown(),delete r[t])}},2e3)},function(e,t){e.exports=require("human-interval")},function(e,t){e.exports=require("interval-to-human")},function(e,t,n){(function(t){const r=n(0),i=(r.Router,n(38)),a=n(4).MongoClient,o=(n(4),n(5),n(1)),s=n(6);e.exports=class extends r{constructor(e,c){super(),this.connectionString=e,this.db=null,this.lrs=c,this.use("/public",r.static("simpleUI/public"));var l=n(39);l.registerHelper("json",n(40)),l.registerHelper("actorDisplay",n(41)),l.registerHelper("verbDisplay",n(42)),l.registerHelper("objectDisplay",n(43)),l.registerHelper("timeAgo",n(44));let d=n(46);var u={defaultLayout:i.join("./simpleUI/views/layouts/layout.html"),layoutsDir:i.join("./simpleUI/views/layouts"),partialsDir:i.join("./simpleUI/views/partials"),extname:"html"};this.set("views",t+"/views");{let e=l.handlebars;e.templates={};for(let t=0;t<d.keys().length;t++){let n=d.keys()[t],r=d(n),a=e.template(r);e.templates[n]=a,e.templates[i.basename(n).replace(".html.compiled.js","")]=a,e.templates[i.basename(n).replace(".compiled.js","")]=a,e.partials[i.basename(n).replace(".html.compiled.js","")]=a,e.partials[i.basename(n).replace(".compiled.js","")]=a}this.use(function(t,n,r){n.render=function(t,i){i=Object.assign({},n.locals,i),/html$/.test(t)||(t+=".html"),t="./"+t+".compiled.js";let a=e.templates[t];if(!a)return r("Template not found");i.layout||(i.layout="layout"),/html$/.test(i.layout)||(i.layout+=".html");let o=e.templates["./layouts/"+i.layout+".compiled.js"],s=a(i);i.body=s,n.send(o(i))},r()})}let p=l.express3(u);this.engine("html",p),this.set("view engine","html"),this.use(function(e,t,n){t.locals.basePath=e.app.path(),n()});let h=this;a.connect(e,(e,t)=>{this.get("/",function(e,t,n){t.redirect(e.app.path()+"/statements/0")}),this.get("/statements/:page",async function(e,t,n){if(o.parseJSONQuery(e.query||{}),!h.lrs||!h.lrs.dal)return t.send("dal not ready");e.query.page=e.params.page;let r=await h.lrs.dal.find(e.query,{}),i="";s.parse(e.url).query&&(i="?"+s.parse(e.url).query),t.render("statementViewer",{statements:r,next:parseInt(e.params.page)+1+i})})})}}}).call(t,"/")},function(e,t){e.exports=require("path")},function(e,t){e.exports=require("express-hbs")},function(e,t){e.exports=function(e){return JSON.stringify(e,null,4)}},function(e,t){e.exports=function(e){return e&&!e.actor&&(e={actor:e}),e.actor.name?e.actor.name:e.actor.account&&e.actor.account.name?e.actor.account.name:e.actor.mbox?e.actor.mbox:"Unknown Actor"}},function(e,t){e.exports=function(e){return e&&!e.verb&&(e={verb:e}),e.verb.display&&e.verb.display["en-US"]?e.verb.display["en-US"]:e.verb.display&&e.verb.display.en?e.verb.display.en:e.verb.id}},function(e,t){e.exports=function e(t){return t&&!t.object&&(t={object:t}),t.object.definition&&t.object.definition.name?t.object.definition.name["en-US"]||t.object.definition.name.en:t.object.definition&&t.object.definition.description?t.object.definition.description["en-US"]||t.object.definition.description.en:"SubStatement"==t.object.objectType?e(t.object)?"Sub-Statement: "+e(t.object):" a sub statement":t.object.id?t.object.id:void 0}},function(e,t,n){let r=new(n(45));e.exports=function(e){return r.ago(new Date(e))}},function(e,t){e.exports=require("time-ago")},function(e,t,n){e.exports=n(47)},function(e,t,n){var r={"./layouts/layout.html.compiled.js":48,"./partials/footer.html.compiled.js":49,"./partials/header.html.compiled.js":50,"./statementViewer.html.compiled.js":51};function i(e){return n(a(e))}function a(e){var t=r[e];if(!(t+1))throw new Error("Cannot find module '"+e+"'.");return t}i.keys=function(){return Object.keys(r)},i.resolve=a,e.exports=i,i.id=47},function(e,t){e.exports={compiler:[7,">= 4.0.0"],main:function(e,t,n,r,i){var a,o,s=null!=t?t:{},c=n.helperMissing,l="function",d=e.escapeExpression;return'<!DOCTYPE html>\r\n<html lang="en">\r\n\r\n<head>\r\n <title>Veracity LRS</title>\r\n <meta charset="utf-8">\r\n <meta name="format-detection" content="telephone=no" />\r\n \r\n <link rel="icon" href="'+d(typeof(o=null!=(o=n.basePath||(null!=t?t.basePath:t))?o:c)===l?o.call(s,{name:"basePath",hash:{},data:i}):o)+'/public/images/favicon.ico" type="image/x-icon">\r\n <link rel="stylesheet" href="'+d(typeof(o=null!=(o=n.basePath||(null!=t?t.basePath:t))?o:c)===l?o.call(s,{name:"basePath",hash:{},data:i}):o)+'/public/bootstrap-3.3.6-dist/css/bootstrap.css">\r\n \x3c!-- link rel="stylesheet" href="/public/css/bootstrap-material-design.min.css" --\x3e\r\n <link rel="stylesheet" href="'+d(typeof(o=null!=(o=n.basePath||(null!=t?t.basePath:t))?o:c)===l?o.call(s,{name:"basePath",hash:{},data:i}):o)+'/public/css/bootstrap-material-design.min.css"></link>\r\n <link href="https://fonts.googleapis.com/css?family=Titillium+Web:400,700" rel="stylesheet">\r\n <link rel="stylesheet" href="'+d(typeof(o=null!=(o=n.basePath||(null!=t?t.basePath:t))?o:c)===l?o.call(s,{name:"basePath",hash:{},data:i}):o)+'/public/css/grid.css">\r\n <link rel="stylesheet" href="'+d(typeof(o=null!=(o=n.basePath||(null!=t?t.basePath:t))?o:c)===l?o.call(s,{name:"basePath",hash:{},data:i}):o)+'/public/css/style.css">\r\n <link rel="stylesheet" href="'+d(typeof(o=null!=(o=n.basePath||(null!=t?t.basePath:t))?o:c)===l?o.call(s,{name:"basePath",hash:{},data:i}):o)+'/public/css/sidebar.css">\r\n <script src="'+d(typeof(o=null!=(o=n.basePath||(null!=t?t.basePath:t))?o:c)===l?o.call(s,{name:"basePath",hash:{},data:i}):o)+'/public/js/jquery.js"><\/script>\r\n <script src="'+d(typeof(o=null!=(o=n.basePath||(null!=t?t.basePath:t))?o:c)===l?o.call(s,{name:"basePath",hash:{},data:i}):o)+'/public/js/material.min.js"><\/script>\r\n <script src="'+d(typeof(o=null!=(o=n.basePath||(null!=t?t.basePath:t))?o:c)===l?o.call(s,{name:"basePath",hash:{},data:i}):o)+'/public/js/ripples.min.js"><\/script>\r\n <script type="text/javascript" src="//cdn.jsdelivr.net/momentjs/latest/moment.min.js"><\/script>\r\n <script src="'+d(typeof(o=null!=(o=n.basePath||(null!=t?t.basePath:t))?o:c)===l?o.call(s,{name:"basePath",hash:{},data:i}):o)+'/public/js/jquery-migrate-1.2.1.js"><\/script>\r\n \x3c!--[if lt IE 9]> \r\n <html class="lt-ie9">\r\n <div style=\' clear: both; text-align:center; position: relative;\'>\r\n <a href="/public/http://windows.microsoft.com/en-US/internet-explorer/..">\r\n <img src="/public/images/ie8-panel/warning_bar_0000_us.jpg" border="0" height="42" width="820"\r\n alt="You are using an outdated browser. For a faster, safer browsing experience, upgrade for free today."/>\r\n </a>\r\n </div>\r\n <script src="/public/js/html5shiv.js"><\/script>\r\n <![endif]--\x3e\r\n <script src=\''+d(typeof(o=null!=(o=n.basePath||(null!=t?t.basePath:t))?o:c)===l?o.call(s,{name:"basePath",hash:{},data:i}):o)+'/public/js/device.min.js\'><\/script>\r\n \r\n</head>\r\n\r\n<body>\r\n <div class="page">\r\n'+(null!=(a=e.invokePartial(r.header,t,{name:"header",hash:{root_path:null!=t?t.root_path:t},data:i,indent:" ",helpers:n,partials:r,decorators:e.decorators}))?a:"")+' \x3c!--========================================================\r\n CONTENT\r\n =========================================================--\x3e\r\n \x3c!-- Sidebar --\x3e\r\n <div class="wrapper">\r\n <nav id="sidebar">\r\n \x3c!-- Sidebar Links --\x3e\r\n <ul class="list-unstyled components">\r\n <li>\r\n \x3c!-- Link with dropdown items --\x3e\r\n <a href="#dataSubmenu" data-toggle="collapse" aria-expanded="true"><i class="fa fa-database"></i>xAPI Data</a>\r\n <ul class="collapse in list-unstyled" id="dataSubmenu">\r\n <li class=""><a href="'+d(typeof(o=null!=(o=n.basePath||(null!=t?t.basePath:t))?o:c)===l?o.call(s,{name:"basePath",hash:{},data:i}):o)+'/statements/0">Statements</a></li>\r\n </ul>\r\n </li>\r\n </ul>\r\n </nav>\r\n <main id="content" class="sidebarOpen" >\r\n \r\n\r\n '+(null!=(a=typeof(o=null!=(o=n.body||(null!=t?t.body:t))?o:c)===l?o.call(s,{name:"body",hash:{},data:i}):o)?a:"")+"\r\n"+(null!=(a=e.invokePartial(r.footer,t,{name:"footer",data:i,indent:" \t",helpers:n,partials:r,decorators:e.decorators}))?a:"")+' </main>\r\n \x3c!--========================================================\r\n FOOTER\r\n =========================================================--\x3e\r\n </div>\r\n </div>\r\n <script src="'+d(typeof(o=null!=(o=n.basePath||(null!=t?t.basePath:t))?o:c)===l?o.call(s,{name:"basePath",hash:{},data:i}):o)+'/public/bootstrap-3.3.6-dist/js/bootstrap.min.js"><\/script>\r\n <script src="'+d(typeof(o=null!=(o=n.basePath||(null!=t?t.basePath:t))?o:c)===l?o.call(s,{name:"basePath",hash:{},data:i}):o)+"/public/js/bootstrap-confirmation.min.js\"><\/script>\r\n \r\n <script type=\"text/javascript\">\r\n $('[data-toggle=\"confirmation\"]').confirmation({\r\n href: function(elem) {\r\n return $(elem).attr('href');\r\n }\r\n });\r\n <\/script>\r\n <script type=\"text/javascript\">\r\n $(document).ready(function() {\r\n $.material.init()\r\n\r\n\r\n \r\n $('#sidebar').find(\"a\").each((j,i)=>{\r\n\r\n if($(i).attr('href') == window.location.pathname)\r\n {\r\n $(i).parent().addClass('active') ;\r\n $(i).parent().parent().addClass('in') ;\r\n }\r\n })\r\n })\r\n <\/script>\r\n</body>\r\n\r\n</html>"},usePartial:!0,useData:!0}},function(e,t){e.exports={compiler:[7,">= 4.0.0"],main:function(e,t,n,r,i){return'<footer>\n <section class="footer-section1">\n <div class="container-fluid">\n <div class="row">\n <div class="col-lg-4 col-md-6 col-sm-6 col-xs-12 wow fadeIn">\n <div class="brand">\n <h1 class="brand_name">\n <a href="https://github.com/veracity-tech/vtc-lrs">VeracityLRS Lite</a>\n </h1>\n </div>\n <p><a href="https://www.veracity.it">VeracityLRS® 2018.</a></p>\n <p>Non-commercial use only.</p>\n </div>\n\n \x3c!-- <div class="col-lg-2 col-md-3 col-sm-3 col-xs-12 wow fadeIn">\n <h3>Navigation</h3>\n <ul class="list2">\n <li><a href="/public/./">Home</a></li>\n <li class="active"><a href="/public/index-1.html">About</a></li>\n <li><a href="/public/index-2.html">Services</a></li>\n <li><a href="/public/index-3.html">News</a></li>\n <li><a href="/public/index-4.html">Contacts</a></li>\n </ul>\n </div>\n\n <div class="col-lg-2 col-md-3 col-sm-3 col-xs-12 wow fadeIn">\n <h3>Services</h3>\n <ul class="list2">\n <li><a href="/public/#">Tablet Repair</a></li>\n <li><a href="/public/#">Computer Repair</a></li>\n <li><a href="/public/#">Laptop Repair</a></li>\n <li><a href="/public/#">Mobile Repair</a></li>\n </ul>\n </div> --\x3e\n\n \n </div>\n\n\n </div>\n \n </div>\n </section>\n\n <section class="footer-section2">\n <div class="container">\n \n </div>\n </section>\n </footer>'},useData:!0}},function(e,t){e.exports={1:function(e,t,n,r,i){return' style="width: 100%" '},compiler:[7,">= 4.0.0"],main:function(e,t,n,r,i){var a,o,s,c=' \x3c!--========================================================\n HEADER\n =========================================================--\x3e\n\n <header style="position: fixed; top:0; width: 100%; z-index: 100000; margin-bottom: 200px">\n\n\n <div id="stuck_container" class="stuck_container" >\n <div class="container-fluid" ';return o=null!=(o=n.wide||(null!=t?t.wide:t))?o:n.helperMissing,s={name:"wide",hash:{},fn:e.program(1,i,0),inverse:e.noop,data:i},a="function"==typeof o?o.call(null!=t?t:{},s):o,n.wide||(a=n.blockHelperMissing.call(t,a,s)),null!=a&&(c+=a),c+'>\n <div class="brand">\n <h1 class="brand_name">\n <a href="/ui/">Veracity <span>LRS Lite</span></a>\n </h1>\n </div>\n \n </div>\n </div>\n </header>\n <div style="height: 94px"></div>'},useData:!0}},function(e,t){e.exports={1:function(e,t,n,r,i){var a,o=null!=t?t:{},s=n.helperMissing,c=e.escapeExpression;return'\r\n <div class="row marTop3 statement">\r\n <div class="col-md-1"><em class="actor"> <a aria-expanded="false" data-toggle="collapse" href="#'+c("function"==typeof(a=null!=(a=n.id||(null!=t?t.id:t))?a:s)?a.call(o,{name:"id",hash:{},data:i}):a)+'" class="btn"></a> </em> </div>\r\n <div class="col-md-2"><em class="actor"> '+c((n.actorDisplay||t&&t.actorDisplay||s).call(o,t,{name:"actorDisplay",hash:{},data:i}))+' </em> </div>\r\n <div class="col-md-2"><em> '+c((n.verbDisplay||t&&t.verbDisplay||s).call(o,t,{name:"verbDisplay",hash:{},data:i}))+' </em> </div>\r\n <div class="col-md-4"><em class="actor"> '+c((n.objectDisplay||t&&t.objectDisplay||s).call(o,t,{name:"objectDisplay",hash:{},data:i}))+' </em></div>\r\n <div class="col-md-3"><em class="">'+c((n.timeAgo||t&&t.timeAgo||s).call(o,null!=t?t.timestamp:t,{name:"timeAgo",hash:{},data:i}))+' </em></div>\r\n </div>\r\n <pre class="collapse" id="'+c("function"==typeof(a=null!=(a=n.id||(null!=t?t.id:t))?a:s)?a.call(o,{name:"id",hash:{},data:i}):a)+'"><code>'+c((n.json||t&&t.json||s).call(o,t,{name:"json",hash:{},data:i}))+"</code></pre> "},compiler:[7,">= 4.0.0"],main:function(e,t,n,r,i){var a,o,s,c=null!=t?t:{},l=n.helperMissing,d="function",u=e.escapeExpression,p=e.lambda,h='\r\n\r\n\t\t\r\n<link rel="stylesheet" type="text/css" href="'+u(typeof(o=null!=(o=n.basePath||(null!=t?t.basePath:t))?o:l)===d?o.call(c,{name:"basePath",hash:{},data:i}):o)+'/public/css/formstyle.css">\r\n<main>\r\n <link rel="stylesheet" type="text/css" href="'+u(typeof(o=null!=(o=n.basePath||(null!=t?t.basePath:t))?o:l)===d?o.call(c,{name:"basePath",hash:{},data:i}):o)+'/public/css/viewer.css">\r\n <section class="well bg0">\r\n <div class="container-fluid">\r\n <div class="row marTop3">\r\n <div class="form-group" for="agent">\r\n <label for="agent" class="col-md-3 control-label">Agent</label>\r\n <div class="col-md-9 ">\r\n <div class="input-group">\r\n <input name="agent" id="agent" type="text" class="form-control" value="'+u(p(null!=(a=null!=t?t.query:t)?a.agent:a,t))+'">\r\n </div>\r\n <p class="help-block ">An Actor identifier in JSON.</p>\r\n </div>\r\n </div>\r\n <div class="form-group" for="related_agents">\r\n <label for="related_agents" class="col-md-3 control-label">Related Agents</label>\r\n <div class="col-md-9 ">\r\n <div class="input-group">\r\n <input name="related_agents" id="related_agents" type="checkbox" class="form-control" value="'+u(p(null!=(a=null!=t?t.query:t)?a.related_agents:a,t))+'">\r\n </div>\r\n <p class="help-block ">Should the LRS return statements related to this agent.</p>\r\n </div>\r\n </div>\r\n <div class="form-group" for="verb">\r\n <label for="verb" class="col-md-3 control-label">Verb</label>\r\n <div class="col-md-9 ">\r\n <div class="input-group">\r\n <input name="verb" id="verb" type="text" class="form-control" value="'+u(p(null!=(a=null!=t?t.query:t)?a.verb:a,t))+'">\r\n </div>\r\n <p class="help-block ">A verb URI</p>\r\n </div>\r\n </div>\r\n <div class="form-group" for="activity">\r\n <label for="activity" class="col-md-3 control-label">Activity</label>\r\n <div class="col-md-9 ">\r\n <div class="input-group">\r\n <input name="activity" id="activity" type="text" class="form-control" value="'+u(p(null!=(a=null!=t?t.query:t)?a.activity:a,t))+'">\r\n </div>\r\n <p class="help-block ">An activity identifier ID.</p>\r\n </div>\r\n </div>\r\n <div class="form-group" for="related_activities">\r\n <label for="related_activities" class="col-md-3 control-label">Related Activities</label>\r\n <div class="col-md-9 ">\r\n <div class="input-group">\r\n <input name="related_activities" id="related_activities" type="checkbox" class="form-control" value="'+u(p(null!=(a=null!=t?t.query:t)?a.related_activities:a,t))+'">\r\n </div>\r\n <p class="help-block ">Should the LRS return statements related to this activity.</p>\r\n </div>\r\n </div>\r\n <div class="form-group" for="registration">\r\n <label for="registration" class="col-md-3 control-label">Registration</label>\r\n <div class="col-md-9 ">\r\n <div class="input-group">\r\n <input name="registration" id="registration" type="text" class="form-control" value="'+u(p(null!=(a=null!=t?t.query:t)?a.registration:a,t))+'">\r\n </div>\r\n <p class="help-block ">An registration identifier UUID.</p>\r\n </div>\r\n </div>\r\n <div class="form-group" for="since">\r\n <label for="since" class="col-md-3 control-label">Since</label>\r\n <div class="col-md-9 ">\r\n <div class="input-group">\r\n <input name="since" id="since" type="date" class="form-control" value="'+u(p(null!=(a=null!=t?t.query:t)?a.since:a,t))+'">\r\n </div>\r\n <p class="help-block ">Only retrieve statements that happened after this date.</p>\r\n </div>\r\n </div>\r\n <div class="form-group" for="until">\r\n <label for="until" class="col-md-3 control-label">Until</label>\r\n <div class="col-md-9 ">\r\n <div class="input-group">\r\n <input name="until" id="until" type="date" class="form-control" value="'+u(p(null!=(a=null!=t?t.query:t)?a.until:a,t))+'">\r\n </div>\r\n <p class="help-block ">Only retrieve statements that happened before this date.</p>\r\n </div>\r\n </div>\r\n <div class="form-group">\r\n <div class="col-md-12 ">\r\n <div class="input-group">\r\n <div id="submit" class="btn btn-block btn-primary">Search</div>\r\n </div>\r\n </div>\r\n </div>\r\n <script type="text/javascript">\r\n $(\'#submit\').click(function() {\r\n let query = {\r\n verb: null || $("#verb").val(),\r\n activity: null || $("#activity").val(),\r\n limit: null || $("#limit").val(),\r\n until: null || $("#until").val(),\r\n since: null || $("#since").val(),\r\n registration: null || $("#registration").val(),\r\n agent: null || $("#agent").val(),\r\n related_agents: $("#related_agents")[0].checked ? true : null,\r\n related_activities: $("#related_activities")[0].checked ? true : null\r\n }\r\n for(let i in query)\r\n {\r\n if(!query[i])\r\n delete query[i];\r\n }\r\n console.log(query)\r\n var loc = window.location;\r\n let location = window.location.pathname.split("/")\r\n location.pop();\r\n \r\n location.push("0")\r\n window.location = location.join("/") + "?" + $.param(query)\r\n\r\n })\r\n <\/script>\r\n </div>\r\n <h2>Statements</h2> ';return o=null!=(o=n.statements||(null!=t?t.statements:t))?o:l,s={name:"statements",hash:{},fn:e.program(1,i,0),inverse:e.noop,data:i},a=typeof o===d?o.call(c,s):o,n.statements||(a=n.blockHelperMissing.call(t,a,s)),null!=a&&(h+=a),h+'\r\n <div class="row marTop3 ">\r\n <div class="col-md-12 col-sm-12 col-xs-12 ">\r\n <a href="./'+u(typeof(o=null!=(o=n.next||(null!=t?t.next:t))?o:l)===d?o.call(c,{name:"next",hash:{},data:i}):o)+'" class="btn" style="width: 100%">More Statements</a>\r\n </div>\r\n </div>\r\n </div>\r\n </section>\r\n</main>\r\n\r\n'},useData:!0}},function(e,t,n){const r=n(8).EventEmitter;let i=n(3),a=n(5),o=n(1).validatePayload;e.exports=class extends r{constructor(e){super(),this.strict=!0,this.verboseLogs=!0,this.preferRead=!1,this.active=!0,this.uuid=e,this.dal=null}async getStatement(e){if(!this.dal)throw new Error("LRS not ready");let t=await this.dal.find({statementId:e});return t&&(t=a.prepStatementForDisplay(t)),t}async insertStatement(e){if(!this.dal)throw new Error("LRS not ready");let t=o(e);if(!t.valid)throw console.log(t.error),new Error(t.error);e.id||(e.id=i.v4());let n=null;try{n=await this.dal.store([e],e.authority,null)}catch(e){throw new Error(e)}if(n)try{this.emit("statementStored",e.id)}catch(e){}return!0}}},function(e,t){e.exports=require("dotenv")}]);