text: (function(){var acts,types,err,checkByConfig,checkByAccess,check;acts=["list","read","write","admin"];types=["token","team","user"];err=function(){var ref$;return ref$=new Error("1012 permission denied"),ref$.id=1012,ref$.name="ldError",ref$.message="permission denied",ref$};checkByConfig=function(arg$){var role,perm,action;role=arg$.role,perm=arg$.perm,action=arg$.action;return new Promise(function(res,rej){var ret,perms,matchedPerms,i$,len$,p,matchedTypes,j$,ref$,len1$,t,cs,type,config,c;ret={};perms=Array.isArray(perm)?perm:[perm];matchedPerms=[];for(i$=0,len$=perms.length;i$<len$;++i$){p=perms[i$];matchedTypes=[];for(j$=0,len1$=(ref$=p.list).length;j$<len1$;++j$){t=ref$[j$];if(!t.type||in$(t.key,role[t.type]||[])){matchedTypes.push(t.type)}}if(matchedTypes.length){matchedPerms.push({types:matchedTypes,config:p.config})}}cs=[];for(i$=0,len$=matchedPerms.length;i$<len$;++i$){p=matchedPerms[i$];for(j$=0,len1$=(ref$=p.types).length;j$<len1$;++j$){type=ref$[j$];cs.push({type:type,config:p.config})}}cs.sort(function(a,b){a=types.indexOf(a.type);b=types.indexOf(b.type);return a-b});config={};for(i$=0,len$=cs.length;i$<len$;++i$){c=cs[i$];import$(config,c.config)}if(!action){return res(config)}if(config[action]){return res(true)}else{return rej(err())}})};checkByAccess=function(arg$){var role,perm,action;role=arg$.role,perm=arg$.perm,action=arg$.action;return new Promise(function(res,rej){var ret,plist,i$,ref$,len$,p,o,act,a,v,idx,k;ret={};if(Array.isArray(perm)){plist=[];perm.map(function(p){return plist=plist.concat(p.list)})}else{plist=perm.list}for(i$=0,len$=(ref$=plist||[]).length;i$<len$;++i$){p=ref$[i$];if(!p.action){continue}if(!p.type){ret[p.action]=true}if(!(o=role[p.type])){continue}if(in$(p.key,o)){ret[p.action]=true}}if(action){act=Array.isArray(action)?action:[action];for(i$=0,len$=act.length;i$<len$;++i$){a=act[i$];if(ret[a]){v=true;break}if(~(idx=acts.indexOf(a))){v=!!acts.slice(idx).map(fn$).reduce(fn1$,false);break}}return v?res(v):rej(err())}return res(function(){var results$=[];for(k in ret){results$.push(k)}return results$}());function fn$(it){return ret[it]}function fn1$(a,b){return a||b}})};check=function(arg$){var role,perm,action;role=arg$.role,perm=arg$.perm,action=arg$.action;if(perm.config||perm[0]&&perm[0].config){return checkByConfig({role:role,perm:perm,action:action})}else{return checkByAccess({role:role,perm:perm,action:action})}};if(typeof module!="undefined"&&module!==null){module.exports=check}if(typeof window!="undefined"&&window!==null){return window.permcheck=check}})();function in$(x,xs){var i=-1,l=xs.length>>>0;while(++i<l)if(x===xs[i])return true;return false}function import$(obj,src){var own={}.hasOwnProperty;for(var key in src)if(own.call(src,key))obj[key]=src[key];return obj}
  