niba-api 0.2.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +1 -1
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import e from"http";import t from"koa";import r from"koa-bodyparser";import n from"@babel/runtime/helpers/asyncToGenerator";import a from"@babel/runtime/helpers/typeof";import u from"@babel/runtime/helpers/defineProperty";import i from"@babel/runtime/helpers/slicedToArray";import o from"@babel/runtime/helpers/classCallCheck";import c from"@babel/runtime/helpers/createClass";import s from"@babel/runtime/regenerator";import f from"@babel/runtime/helpers/possibleConstructorReturn";import l from"@babel/runtime/helpers/getPrototypeOf";import p from"@babel/runtime/helpers/inherits";import h from"@babel/runtime/helpers/wrapNativeSuper";import{promisify as v}from"node:util";import{scryptSync as d,createDecipheriv as b,randomBytes as m,createCipheriv as y,scrypt as g}from"node:crypto";import x from"cacache";import w from"path";import k from"os";var O=console;function S(e){O=e}function j(e,t,r){return t=l(t),f(e,C()?Reflect.construct(t,r||[],l(e).constructor):t.apply(e,r))}function C(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(C=function(){return!!e})()}var A=function(e){function t(e){var r,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:500;return o(this,t),(r=j(this,t,[e])).code=n,r}return p(t,e),c(t)}(h(Error)),z=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"Bad Request";return o(this,e),j(this,e,[t,400])}return p(e,A),c(e)}(),P=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"Unauthorized";return o(this,e),j(this,e,[t,401])}return p(e,A),c(e)}(),E=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"Forbidden";return o(this,e),j(this,e,[t,403])}return p(e,A),c(e)}(),B=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"Not Found";return o(this,e),j(this,e,[t,404])}return p(e,A),c(e)}(),I=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"Method Not Allowed";return o(this,e),j(this,e,[t,405])}return p(e,A),c(e)}(),D=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"Not Acceptable";return o(this,e),j(this,e,[t,406])}return p(e,A),c(e)}(),q=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"Proxy Authentication Required";return o(this,e),j(this,e,[t,407])}return p(e,A),c(e)}(),G=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"Time-out";return o(this,e),j(this,e,[t,408])}return p(e,A),c(e)}(),L=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"Conflict";return o(this,e),j(this,e,[t,409])}return p(e,A),c(e)}(),N=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"Internal Server Error";return o(this,e),j(this,e,[t,500])}return p(e,A),c(e)}(),R=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"Not Implemented";return o(this,e),j(this,e,[t,501])}return p(e,A),c(e)}(),T=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"Bad Gateway";return o(this,e),j(this,e,[t,502])}return p(e,A),c(e)}(),M=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"Service Unavailable";return o(this,e),j(this,e,[t,503])}return p(e,A),c(e)}();function U(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function _(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?U(Object(r),!0).forEach(function(t){u(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):U(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}function F(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!r){if(Array.isArray(e)||(r=function(e,t){if(e){if("string"==typeof e)return $(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?$(e,t):void 0}}(e))||t){r&&(e=r);var n=0,a=function(){};return{s:a,n:function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},f:a}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var u,i=!0,o=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return i=e.done,e},e:function(e){o=!0,u=e},f:function(){try{i||null==r.return||r.return()}finally{if(o)throw u}}}}function $(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}var Q=/\((.*?)\)/g,J=/(\(\?)?:\w+/g,W=/\*\w+/g,Y=/[\-{}\[\]+?.,\\\^$|#\s]/g,H={maxSize:1e3,ttl:3e5,enabled:!0},V=function(){return c(function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:H.maxSize,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:H.ttl;o(this,e),this.maxSize=t,this.ttl=r,this.cache=new Map,this.accessOrder=[],this.lastCleanup=Date.now()},[{key:"get",value:function(e){if(!this.cache.has(e))return null;var t=this.cache.get(e);return this.ttl>0&&Date.now()-t.timestamp>this.ttl?(this.delete(e),null):(this.updateAccessOrder(e),t.value)}},{key:"set",value:function(e,t){return this.cleanupIfNeeded(),this.cache.size>=this.maxSize&&!this.cache.has(e)&&this.evictOldest(),this.cache.set(e,{value:t,timestamp:Date.now()}),this.updateAccessOrder(e),t}},{key:"delete",value:function(e){var t=this.accessOrder.indexOf(e);return t>-1&&this.accessOrder.splice(t,1),this.cache.delete(e)}},{key:"clear",value:function(){this.cache.clear(),this.accessOrder=[],this.lastCleanup=Date.now()}},{key:"size",value:function(){return this.cache.size}},{key:"updateAccessOrder",value:function(e){var t=this.accessOrder.indexOf(e);t>-1&&this.accessOrder.splice(t,1),this.accessOrder.push(e)}},{key:"evictOldest",value:function(){for(;this.accessOrder.length>0;){var e=this.accessOrder.shift();if(this.cache.has(e)){this.cache.delete(e);break}}}},{key:"cleanupIfNeeded",value:function(){if(!(this.ttl<=0||this.cache.size<100&&Date.now()-this.lastCleanup<6e4)){var e,t=Date.now(),r=0,n=F(this.cache.entries());try{for(n.s();!(e=n.n()).done;){var a=i(e.value,2),u=a[0];t-a[1].timestamp>this.ttl&&(this.delete(u),r++)}}catch(e){n.e(e)}finally{n.f()}this.lastCleanup=t,r>0&&O.debug("清理了 ".concat(r," 个过期缓存条目"))}}}])}(),X=new V,K=new V,Z=new V;function ee(e){if("string"!=typeof e)return e;var t=e.trim();if(t.length>1e4)throw new A("Input too large",400);return t.indexOf(",")<0?t:t.split(",").map(function(e){var t=e.trim();if(t.length>1e3)throw new A("CSV item too large",400);return/^\d+(\.\d+)?$/g.test(t)?parseFloat(t):t}).filter(function(e){return null!=e&&""!==e})}function te(){var e=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];H.enabled=e}function re(e){H.maxSize=e,X.maxSize=e,K.maxSize=e,Z.maxSize=e}function ne(e){H.ttl=e,X.ttl=e,K.ttl=e,Z.ttl=e}function ae(){X.clear(),K.clear(),Z.clear()}function ue(){return{routeRegexCache:X.size(),routeMatchCache:K.size(),paramExtractCache:Z.size(),config:_({},H)}}function ie(e){var t=e.replace(Y,"\\$&").replace(Q,function(e,t){return"(?:"+t+")?"}).replace(J,function(e,t){return t?e:"([^/?]+)"}).replace(W,"([^?]*?)");return new RegExp("^"+t+"(?:\\?([\\s\\S]*))?$")}function oe(e,t){var r=e.exec(t).slice(1);return r.map(function(e,t){return t===r.length-1?e||null:e?decodeURIComponent(e):null})}function ce(e,t,r){var n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"";if(!H.enabled)return se(e,t,r,n);var a="".concat(t,":").concat(n,":").concat(r),u=K.get(a);if(void 0!==u)return u;var i=se(e,t,r,n);return K.set(a,i)}function se(e,t,r){var n,a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"",i=t.toLowerCase(),o=F(e);try{var c,s=function(){var e=n.value;if(e.method)if(Array.isArray(e.method)){if(!e.method.some(function(e){return e.toLowerCase()===i}))return 0}else{if("string"!=typeof e.method)return 0;if(e.method.toLowerCase()!==i)return 0}var t="".concat(a).concat(e.path),o=function(e){if(!H.enabled)return ie(e);var t=e,r=X.get(t);if(r)return r;var n=ie(e);return X.set(t,n)}(t);if(!o.test(r))return 0;var c={},s=t.match(J);if(!s)return{v:{route:e,patterns:c}};var f=function(e,t){if(!H.enabled)return oe(e,t);var r="".concat(e.source,":").concat(t),n=Z.get(r);if(n)return n;var a=oe(e,t);return Z.set(r,a)}(o,r);return s.forEach(function(e,t){Object.assign(c,u({},e.slice(1),ee(f[t])))}),{v:{route:e,patterns:c}}};for(o.s();!(n=o.n()).done;)if(0!==(c=s())&&c)return c.v}catch(e){o.e(e)}finally{o.f()}return null}function fe(e,t){var r={},n={};Array.isArray(t)?t.forEach(function(e){n[e]=e}):t&&"object"===a(t)&&Object.assign(n,t);var u={};Object.entries(n).forEach(function(e){var t=i(e,2),r=t[0],n=t[1];u[n]=r});for(var o=0,c=Object.entries(e);o<c.length;o++){var s=i(c[o],2),f=s[0],l=ee(s[1]);r[u[f]||f]=l}return r}function le(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";return function(){var r=n(s.mark(function r(n,i){var o,c,f,l,p,h,v,d,b,m,y;return s.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:if(c=n.path,f=ce(e,n.method,c,t)){r.next=1;break}return n.status=404,n.body={error:"Not Found"},r.abrupt("return");case 1:if(l=f.route,p=f.patterns,O.debug("--\x3e route %o, patterns: %o",l,p),h=l.handler,O.debug("--\x3e handler: %o, type: %o",h,a(h)),h&&"function"==typeof h){r.next=2;break}return n.throw(500,"The handler cannot be found"),r.abrupt("return");case 2:if(v=n.state.USER,O.debug("--\x3e current user: %o",v),!l.auth||v){r.next=3;break}return n.throw(401),r.abrupt("return");case 3:if(d=null!==(o=n.state.ACL)&&void 0!==o?o:[],"string"!=typeof l.auth||d.includes(l.auth)){r.next=4;break}return n.throw(403),r.abrupt("return");case 4:return b=_(_({request:n.request,response:n.response},p),{},{_user:v}),"string"==typeof l.body?Object.assign(b,u({},l.body,n.request.body)):Object.assign(b,{body:n.request.body}),l.header&&Object.assign(b,fe(n.request.header,l.header)),l.query&&Object.assign(b,fe(n.request.query,l.query)),m={},r.prev=5,r.next=6,h(b);case 6:m=r.sent,r.next=8;break;case 7:r.prev=7,y=r.catch(5),O.error("Handler error: %s",y.message,{stack:y.stack}),y instanceof A?n.throw(y.code,y.message):n.throw(500,"Internal Server Error");case 8:if(!(n.status>=300&&n.status<400)){r.next=10;break}return r.next=9,i();case 9:return r.abrupt("return");case 10:return null!=m?n.body=m:void 0===n.body&&(n.body=null),r.next=11,i();case 11:case"end":return r.stop()}},r,null,[[5,7]])}));return function(e,t){return r.apply(this,arguments)}}()}var pe="aes-192-cbc",he="bmliYW5pYmFsYW5uaWJhIQ==",ve=new Map;function de(e){return be.apply(this,arguments)}function be(){return(be=n(s.mark(function e(t){var r;return s.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(!ve.has(t)){e.next=1;break}return e.abrupt("return",ve.get(t));case 1:return e.next=2,v(g)(t,he,24);case 2:return r=e.sent,ve.set(t,r),e.abrupt("return",r);case 3:case"end":return e.stop()}},e)}))).apply(this,arguments)}function me(e,t){return ye.apply(this,arguments)}function ye(){return(ye=n(s.mark(function e(t,r){var n,a,u,i,o;return s.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=1,de(r);case 1:return n=e.sent,a=m(16),u=y(pe,n,a),i=u.update(t),o=u.final(),e.abrupt("return",Buffer.concat([a,i,o]));case 2:case"end":return e.stop()}},e)}))).apply(this,arguments)}function ge(e,t){return xe.apply(this,arguments)}function xe(){return(xe=n(s.mark(function e(t,r){var n,a,u,i,o,c;return s.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=1,de(r);case 1:return n=e.sent,a=t.subarray(0,16),u=t.subarray(16),i=b(pe,n,a),o=i.update(u),c=i.final(),e.abrupt("return",Buffer.concat([o,c]));case 2:case"end":return e.stop()}},e)}))).apply(this,arguments)}function we(e,t){return ke.apply(this,arguments)}function ke(){return(ke=n(s.mark(function e(t,r){var n;return s.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=1,me(Buffer.from(t,"utf8"),r);case 1:return n=e.sent,e.abrupt("return",n.toString("base64url"));case 2:case"end":return e.stop()}},e)}))).apply(this,arguments)}function Oe(e,t){return Se.apply(this,arguments)}function Se(){return(Se=n(s.mark(function e(t,r){var n;return s.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=1,ge(Buffer.from(t,"base64url"),r);case 1:return n=e.sent,e.abrupt("return",n.toString("utf8"));case 2:case"end":return e.stop()}},e)}))).apply(this,arguments)}function je(e,t){var r=d(t,he,24),n=m(16),a=y(pe,r,n),u=a.update(e),i=a.final();return Buffer.concat([n,u,i])}function Ce(e,t){var r=d(t,he,24),n=e.subarray(0,16),a=e.subarray(16),u=b(pe,r,n),i=u.update(a),o=u.final();return Buffer.concat([i,o])}function Ae(){return ze.apply(this,arguments)}function ze(){return(ze=n(s.mark(function e(){return s.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:ve.clear();case 1:case"end":return e.stop()}},e)}))).apply(this,arguments)}var Pe=w.resolve(k.tmpdir(),"niba_cache");function Ee(){return(Ee=n(s.mark(function e(){return s.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=1,x.ls(Pe);case 1:return e.abrupt("return",e.sent);case 2:e.prev=2,e.catch(0);case 3:case"end":return e.stop()}},e,null,[[0,2]])}))).apply(this,arguments)}function Be(e){return Ie.apply(this,arguments)}function Ie(){return(Ie=n(s.mark(function e(t){var r,n;return s.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=1,x.get(Pe,t);case 1:return r=e.sent,n=r.data,e.abrupt("return",n.toString("utf-8"));case 2:return e.prev=2,e.catch(0),e.abrupt("return",null);case 3:case"end":return e.stop()}},e,null,[[0,2]])}))).apply(this,arguments)}function De(){return(De=n(s.mark(function e(t){var r;return s.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=1,Be(t);case 1:return r=e.sent,e.prev=2,e.abrupt("return",r&&JSON.parse(r));case 3:return e.prev=3,e.catch(2),e.abrupt("return",null);case 4:case"end":return e.stop()}},e,null,[[2,3]])}))).apply(this,arguments)}function qe(e,t){return Ge.apply(this,arguments)}function Ge(){return(Ge=n(s.mark(function e(t,r){return s.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=1,x.put(Pe,t,r+"");case 1:e.next=3;break;case 2:e.prev=2,e.catch(0);case 3:case"end":return e.stop()}},e,null,[[0,2]])}))).apply(this,arguments)}function Le(){return(Le=n(s.mark(function e(t,r){return s.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=1,qe(t,JSON.stringify(r));case 1:case"end":return e.stop()}},e)}))).apply(this,arguments)}function Ne(){return(Ne=n(s.mark(function e(t){return s.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=1,x.rm.entry(Pe,t);case 1:e.next=3;break;case 2:e.prev=2,e.catch(0);case 3:case"end":return e.stop()}},e,null,[[0,2]])}))).apply(this,arguments)}function Re(){return(Re=n(s.mark(function e(){return s.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=1,x.rm.all(Pe);case 1:e.next=3;break;case 2:e.prev=2,e.catch(0);case 3:case"end":return e.stop()}},e,null,[[0,2]])}))).apply(this,arguments)}var Te=Object.freeze({__proto__:null,clear:function(){return Re.apply(this,arguments)},evict:function(e){return Ne.apply(this,arguments)},getObject:function(e){return De.apply(this,arguments)},getText:Be,ls:function(){return Ee.apply(this,arguments)},setObject:function(e,t){return Le.apply(this,arguments)},setPath:function(e){Pe=e},setText:qe}),Me="eD300Ezu9r4Q3CPM7XQt-Q";function Ue(e){return _e.apply(this,arguments)}function _e(){return(_e=n(s.mark(function e(t){var r,n,a,u,i,o,c,f,l,p,h,d;return s.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return r=t.uid,n=t.device,a=void 0===n?"unknow":n,u=t.key,i=void 0===u?Me:u,o=t.timeout,c=void 0===o?30:o,f=(new Date).getTime(),e.next=1,v(m)(16);case 1:return l=e.sent,p=Buffer.from(f+60*c*1e3+"","ascii"),h=Buffer.concat([p,Buffer.from("".concat(r,"<=>").concat(a,"<=>").concat(f)),l]),e.next=2,me(h,i);case 2:return d=e.sent,e.next=3,qe("".concat(r,"@").concat(a),f);case 3:return e.abrupt("return",d.toString("base64url"));case 4:case"end":return e.stop()}},e)}))).apply(this,arguments)}function Fe(e){return $e.apply(this,arguments)}function $e(){return($e=n(s.mark(function e(t){var r,n,a,u,o,c,f,l,p,h,v,d;return s.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return r=t.token,n=t.key,a=void 0===n?Me:n,u=Buffer.from(r,"base64url"),e.next=1,ge(u,a);case 1:if(o=e.sent,c=o.subarray(0,o.length-16).toString("utf8"),!(parseInt(c.slice(0,13))<(new Date).getTime())){e.next=2;break}return e.abrupt("return",null);case 2:return f=c.slice(13).split("<=>"),l=i(f,3),p=l[0],h=l[1],v=l[2],e.next=3,Be("".concat(p,"@").concat(h));case 3:if(d=e.sent,!(parseInt(v)<parseInt(d))){e.next=4;break}return e.abrupt("return",null);case 4:return e.abrupt("return",{uid:p,device:h});case 5:case"end":return e.stop()}},e)}))).apply(this,arguments)}function Qe(e){var t=e.userGetter,r=e.ACLGetter,a=e.tokenParser,u=void 0===a?Fe:a;return function(){var e=n(s.mark(function e(n,a){var i,o,c,f,l,p,h,v,d;return s.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if((i=null)||(c=null===(o=n.headers)||void 0===o?void 0:o.authorization,i=null==c?void 0:c.substring(7).trim()),i||(i=null===(f=n.query)||void 0===f?void 0:f.token),O.debug("--\x3e token: %s",i),i){e.next=2;break}return e.next=1,a();case 1:return e.abrupt("return");case 2:return e.prev=2,e.next=3,u({token:i});case 3:if(l=e.sent,p=l.uid,h=l.device,O.debug("uid: %s, device: %s",p,h),!t||"function"!=typeof t){e.next=5;break}return e.next=4,t({uid:p,device:h});case 4:v=e.sent,n.state.USER=v;case 5:if(!r||"function"!=typeof r){e.next=7;break}return e.next=6,r({uid:p,device:h});case 6:d=e.sent,n.state.ACL=d;case 7:e.next=9;break;case 8:e.prev=8,e.catch(2),n.throw(401);case 9:return e.next=10,a();case 10:case"end":return e.stop()}},e,null,[[2,8]])}));return function(t,r){return e.apply(this,arguments)}}()}function Je(){return function(){var e=n(s.mark(function e(t,r){var n;return s.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=1,r();case 1:(n=t.accepts("*/*","text/*","application/json"))&&(t.type="".concat(n,"; charset=utf-8"));case 2:case"end":return e.stop()}},e)}));return function(t,r){return e.apply(this,arguments)}}()}function We(n){var a=n.context,u=void 0===a?"":a,i=n.routes,o=void 0===i?[]:i,c=n.plugins,s=void 0===c?[]:c,f=n.userGetter,l=void 0===f?null:f,p=n.ACLGetter,h=void 0===p?null:p,v=n.tokenParser,d=void 0===v?null:v,b=n.logger,m=void 0===b?null:b;m&&S(m);var y=new t;return y.use(r({enableTypes:["json","form","text"]})),y.use(Qe({userGetter:l,ACLGetter:h,tokenParser:d})),y.use(le(o,u)),y.use(Je()),s.forEach(function(e){y.use(e)}),e.createServer(y.callback())}function Ye(e){var t=e.context,r=void 0===t?"":t,n=e.routes,a=void 0===n?[]:n,u=e.plugins,i=void 0===u?[]:u,o=e.hostname,c=void 0===o?"localhost":o,s=e.port,f=void 0===s?9090:s,l=e.userGetter,p=void 0===l?null:l,h=e.ACLGetter,v=void 0===h?null:h,d=e.tokenParser,b=void 0===d?null:d,m=e.logger,y=We({context:r,routes:a,plugins:i,logger:void 0===m?null:m,userGetter:p,ACLGetter:v,tokenParser:b});O.info("--\x3e niba is listening at http://".concat(c,":").concat(f)),y.listen(f,c)}export{T as BadGateway,z as BadRequest,L as Conflict,E as Forbidden,N as InternalServerError,I as MethodNotAllowed,A as NBError,D as NotAcceptable,B as NotFound,R as NotImplemented,q as ProxyAuthenticationRequired,M as ServiceUnavailable,G as Timeout,P as Unauthorized,Qe as authentication,Te as cache,ae as clearCache,Ae as clearKeyCache,We as createServer,Ue as createToken,ge as decrypt,Ce as decryptSync,Oe as decryptText,le as dispatcher,te as enableCache,me as encrypt,je as encryptSync,we as encryptText,ue as getCacheStats,O as logger,Fe as parseToken,Je as rjson,Ye as serve,re as setCacheMaxSize,ne as setCacheTTL,S as setLogger};
|
|
1
|
+
import e from"http";import t from"koa";import r from"koa-bodyparser";import n from"@babel/runtime/helpers/asyncToGenerator";import a from"@babel/runtime/helpers/typeof";import u from"@babel/runtime/helpers/defineProperty";import i from"@babel/runtime/helpers/slicedToArray";import o from"@babel/runtime/helpers/classCallCheck";import c from"@babel/runtime/helpers/createClass";import s from"@babel/runtime/regenerator";import f from"@babel/runtime/helpers/possibleConstructorReturn";import l from"@babel/runtime/helpers/getPrototypeOf";import p from"@babel/runtime/helpers/inherits";import h from"@babel/runtime/helpers/wrapNativeSuper";import{promisify as v}from"node:util";import{scryptSync as d,createDecipheriv as b,randomBytes as m,createCipheriv as y,scrypt as g}from"node:crypto";import x from"cacache";import w from"path";import k from"os";var O=console;function S(e){O=e}function j(e,t,r){return t=l(t),f(e,C()?Reflect.construct(t,r||[],l(e).constructor):t.apply(e,r))}function C(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch(e){}return(C=function(){return!!e})()}var A=function(e){function t(e){var r,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:500;return o(this,t),(r=j(this,t,[e])).code=n,r}return p(t,e),c(t)}(h(Error)),z=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"Bad Request";return o(this,e),j(this,e,[t,400])}return p(e,A),c(e)}(),P=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"Unauthorized";return o(this,e),j(this,e,[t,401])}return p(e,A),c(e)}(),E=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"Forbidden";return o(this,e),j(this,e,[t,403])}return p(e,A),c(e)}(),B=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"Not Found";return o(this,e),j(this,e,[t,404])}return p(e,A),c(e)}(),I=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"Method Not Allowed";return o(this,e),j(this,e,[t,405])}return p(e,A),c(e)}(),D=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"Not Acceptable";return o(this,e),j(this,e,[t,406])}return p(e,A),c(e)}(),q=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"Proxy Authentication Required";return o(this,e),j(this,e,[t,407])}return p(e,A),c(e)}(),G=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"Time-out";return o(this,e),j(this,e,[t,408])}return p(e,A),c(e)}(),L=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"Conflict";return o(this,e),j(this,e,[t,409])}return p(e,A),c(e)}(),N=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"Internal Server Error";return o(this,e),j(this,e,[t,500])}return p(e,A),c(e)}(),R=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"Not Implemented";return o(this,e),j(this,e,[t,501])}return p(e,A),c(e)}(),T=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"Bad Gateway";return o(this,e),j(this,e,[t,502])}return p(e,A),c(e)}(),M=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"Service Unavailable";return o(this,e),j(this,e,[t,503])}return p(e,A),c(e)}();function U(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),r.push.apply(r,n)}return r}function _(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?U(Object(r),!0).forEach(function(t){u(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):U(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}function F(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!r){if(Array.isArray(e)||(r=function(e,t){if(e){if("string"==typeof e)return $(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?$(e,t):void 0}}(e))||t){r&&(e=r);var n=0,a=function(){};return{s:a,n:function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},f:a}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var u,i=!0,o=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return i=e.done,e},e:function(e){o=!0,u=e},f:function(){try{i||null==r.return||r.return()}finally{if(o)throw u}}}}function $(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}var Q=/\((.*?)\)/g,J=/(\(\?)?:\w+/g,W=/\*\w+/g,Y=/[\-{}\[\]+?.,\\\^$|#\s]/g,H={maxSize:1e3,ttl:3e5,enabled:!0},V=function(){return c(function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:H.maxSize,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:H.ttl;o(this,e),this.maxSize=t,this.ttl=r,this.cache=new Map,this.accessOrder=[],this.lastCleanup=Date.now()},[{key:"get",value:function(e){if(!this.cache.has(e))return null;var t=this.cache.get(e);return this.ttl>0&&Date.now()-t.timestamp>this.ttl?(this.delete(e),null):(this.updateAccessOrder(e),t.value)}},{key:"set",value:function(e,t){return this.cleanupIfNeeded(),this.cache.size>=this.maxSize&&!this.cache.has(e)&&this.evictOldest(),this.cache.set(e,{value:t,timestamp:Date.now()}),this.updateAccessOrder(e),t}},{key:"delete",value:function(e){var t=this.accessOrder.indexOf(e);return t>-1&&this.accessOrder.splice(t,1),this.cache.delete(e)}},{key:"clear",value:function(){this.cache.clear(),this.accessOrder=[],this.lastCleanup=Date.now()}},{key:"size",value:function(){return this.cache.size}},{key:"updateAccessOrder",value:function(e){var t=this.accessOrder.indexOf(e);t>-1&&this.accessOrder.splice(t,1),this.accessOrder.push(e)}},{key:"evictOldest",value:function(){for(;this.accessOrder.length>0;){var e=this.accessOrder.shift();if(this.cache.has(e)){this.cache.delete(e);break}}}},{key:"cleanupIfNeeded",value:function(){if(!(this.ttl<=0||this.cache.size<100&&Date.now()-this.lastCleanup<6e4)){var e,t=Date.now(),r=0,n=F(this.cache.entries());try{for(n.s();!(e=n.n()).done;){var a=i(e.value,2),u=a[0];t-a[1].timestamp>this.ttl&&(this.delete(u),r++)}}catch(e){n.e(e)}finally{n.f()}this.lastCleanup=t,r>0&&O.debug("清理了 ".concat(r," 个过期缓存条目"))}}}])}(),X=new V,K=new V,Z=new V;function ee(e){if("string"!=typeof e)return e;var t=e.trim();if(t.length>1e4)throw new A("Input too large",400);return t.indexOf(",")<0?t:t.split(",").map(function(e){var t=e.trim();if(t.length>1e3)throw new A("CSV item too large",400);return/^\d+(\.\d+)?$/g.test(t)?parseFloat(t):t}).filter(function(e){return null!=e&&""!==e})}function te(){var e=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];H.enabled=e}function re(e){H.maxSize=e,X.maxSize=e,K.maxSize=e,Z.maxSize=e}function ne(e){H.ttl=e,X.ttl=e,K.ttl=e,Z.ttl=e}function ae(){X.clear(),K.clear(),Z.clear()}function ue(){return{routeRegexCache:X.size(),routeMatchCache:K.size(),paramExtractCache:Z.size(),config:_({},H)}}function ie(e){var t=e.replace(Y,"\\$&").replace(Q,function(e,t){return"(?:"+t+")?"}).replace(J,function(e,t){return t?e:"([^/?]+)"}).replace(W,"([^?]*?)");return new RegExp("^"+t+"(?:\\?([\\s\\S]*))?$")}function oe(e,t){var r=e.exec(t).slice(1);return r.map(function(e,t){return t===r.length-1?e||null:e?decodeURIComponent(e):null})}function ce(e,t,r){var n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"";if(!H.enabled)return se(e,t,r,n);var a="".concat(t,":").concat(n,":").concat(r),u=K.get(a);if(void 0!==u)return u;var i=se(e,t,r,n);return K.set(a,i)}function se(e,t,r){var n,a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"",i=t.toLowerCase(),o=F(e);try{var c,s=function(){var e=n.value;if(e.method)if(Array.isArray(e.method)){if(!e.method.some(function(e){return e.toLowerCase()===i}))return 0}else{if("string"!=typeof e.method)return 0;if(e.method.toLowerCase()!==i)return 0}var t="".concat(a).concat(e.path),o=function(e){if(!H.enabled)return ie(e);var t=e,r=X.get(t);if(r)return r;var n=ie(e);return X.set(t,n)}(t);if(!o.test(r))return 0;var c={},s=t.match(J);if(!s)return{v:{route:e,patterns:c}};var f=function(e,t){if(!H.enabled)return oe(e,t);var r="".concat(e.source,":").concat(t),n=Z.get(r);if(n)return n;var a=oe(e,t);return Z.set(r,a)}(o,r);return s.forEach(function(e,t){Object.assign(c,u({},e.slice(1),ee(f[t])))}),{v:{route:e,patterns:c}}};for(o.s();!(n=o.n()).done;)if(0!==(c=s())&&c)return c.v}catch(e){o.e(e)}finally{o.f()}return null}function fe(e,t){var r={},n={};Array.isArray(t)?t.forEach(function(e){n[e]=e}):t&&"object"===a(t)&&Object.assign(n,t);var u={};Object.entries(n).forEach(function(e){var t=i(e,2),r=t[0],n=t[1];u[n]=r});for(var o=0,c=Object.entries(e);o<c.length;o++){var s=i(c[o],2),f=s[0],l=ee(s[1]);r[u[f]||f]=l}return r}function le(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";return function(){var r=n(s.mark(function r(n,i){var o,c,f,l,p,h,v,d,b,m,y;return s.wrap(function(r){for(;;)switch(r.prev=r.next){case 0:if(c=n.path,f=ce(e,n.method,c,t)){r.next=1;break}return n.status=404,n.body={error:"Not Found"},r.abrupt("return");case 1:if(l=f.route,p=f.patterns,O.debug("--\x3e route %o, patterns: %o",l,p),h=l.handler,O.debug("--\x3e handler: %o, type: %o",h,a(h)),h&&"function"==typeof h){r.next=2;break}return n.throw(500,"The handler cannot be found"),r.abrupt("return");case 2:if(v=n.state.USER,O.debug("--\x3e current user: %o",v),!l.auth||v){r.next=3;break}return n.throw(401),r.abrupt("return");case 3:if(d=null!==(o=n.state.ACL)&&void 0!==o?o:[],"string"!=typeof l.auth||d.includes(l.auth)){r.next=4;break}return n.throw(403),r.abrupt("return");case 4:return b=_(_({request:n.request,response:n.response},p),{},{_user:v}),"string"==typeof l.body?Object.assign(b,u({},l.body,n.request.body)):Object.assign(b,{body:n.request.body}),l.header&&Object.assign(b,fe(n.request.header,l.header)),l.query&&Object.assign(b,fe(n.request.query,l.query)),m={},r.prev=5,r.next=6,h(b);case 6:m=r.sent,r.next=8;break;case 7:r.prev=7,y=r.catch(5),O.error("Handler error: %s",y.message,{stack:y.stack}),y instanceof A?n.throw(y.code,y.message):n.throw(500,"Internal Server Error");case 8:if(!(n.status>=300&&n.status<400)){r.next=10;break}return r.next=9,i();case 9:return r.abrupt("return");case 10:return null!=m?n.body=m:(n.body=null,200!==n.status&&404!==n.status||(n.status=204)),r.next=11,i();case 11:case"end":return r.stop()}},r,null,[[5,7]])}));return function(e,t){return r.apply(this,arguments)}}()}var pe="aes-192-cbc",he="bmliYW5pYmFsYW5uaWJhIQ==",ve=new Map;function de(e){return be.apply(this,arguments)}function be(){return(be=n(s.mark(function e(t){var r;return s.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(!ve.has(t)){e.next=1;break}return e.abrupt("return",ve.get(t));case 1:return e.next=2,v(g)(t,he,24);case 2:return r=e.sent,ve.set(t,r),e.abrupt("return",r);case 3:case"end":return e.stop()}},e)}))).apply(this,arguments)}function me(e,t){return ye.apply(this,arguments)}function ye(){return(ye=n(s.mark(function e(t,r){var n,a,u,i,o;return s.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=1,de(r);case 1:return n=e.sent,a=m(16),u=y(pe,n,a),i=u.update(t),o=u.final(),e.abrupt("return",Buffer.concat([a,i,o]));case 2:case"end":return e.stop()}},e)}))).apply(this,arguments)}function ge(e,t){return xe.apply(this,arguments)}function xe(){return(xe=n(s.mark(function e(t,r){var n,a,u,i,o,c;return s.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=1,de(r);case 1:return n=e.sent,a=t.subarray(0,16),u=t.subarray(16),i=b(pe,n,a),o=i.update(u),c=i.final(),e.abrupt("return",Buffer.concat([o,c]));case 2:case"end":return e.stop()}},e)}))).apply(this,arguments)}function we(e,t){return ke.apply(this,arguments)}function ke(){return(ke=n(s.mark(function e(t,r){var n;return s.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=1,me(Buffer.from(t,"utf8"),r);case 1:return n=e.sent,e.abrupt("return",n.toString("base64url"));case 2:case"end":return e.stop()}},e)}))).apply(this,arguments)}function Oe(e,t){return Se.apply(this,arguments)}function Se(){return(Se=n(s.mark(function e(t,r){var n;return s.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=1,ge(Buffer.from(t,"base64url"),r);case 1:return n=e.sent,e.abrupt("return",n.toString("utf8"));case 2:case"end":return e.stop()}},e)}))).apply(this,arguments)}function je(e,t){var r=d(t,he,24),n=m(16),a=y(pe,r,n),u=a.update(e),i=a.final();return Buffer.concat([n,u,i])}function Ce(e,t){var r=d(t,he,24),n=e.subarray(0,16),a=e.subarray(16),u=b(pe,r,n),i=u.update(a),o=u.final();return Buffer.concat([i,o])}function Ae(){return ze.apply(this,arguments)}function ze(){return(ze=n(s.mark(function e(){return s.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:ve.clear();case 1:case"end":return e.stop()}},e)}))).apply(this,arguments)}var Pe=w.resolve(k.tmpdir(),"niba_cache");function Ee(){return(Ee=n(s.mark(function e(){return s.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=1,x.ls(Pe);case 1:return e.abrupt("return",e.sent);case 2:e.prev=2,e.catch(0);case 3:case"end":return e.stop()}},e,null,[[0,2]])}))).apply(this,arguments)}function Be(e){return Ie.apply(this,arguments)}function Ie(){return(Ie=n(s.mark(function e(t){var r,n;return s.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=1,x.get(Pe,t);case 1:return r=e.sent,n=r.data,e.abrupt("return",n.toString("utf-8"));case 2:return e.prev=2,e.catch(0),e.abrupt("return",null);case 3:case"end":return e.stop()}},e,null,[[0,2]])}))).apply(this,arguments)}function De(){return(De=n(s.mark(function e(t){var r;return s.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=1,Be(t);case 1:return r=e.sent,e.prev=2,e.abrupt("return",r&&JSON.parse(r));case 3:return e.prev=3,e.catch(2),e.abrupt("return",null);case 4:case"end":return e.stop()}},e,null,[[2,3]])}))).apply(this,arguments)}function qe(e,t){return Ge.apply(this,arguments)}function Ge(){return(Ge=n(s.mark(function e(t,r){return s.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=1,x.put(Pe,t,r+"");case 1:e.next=3;break;case 2:e.prev=2,e.catch(0);case 3:case"end":return e.stop()}},e,null,[[0,2]])}))).apply(this,arguments)}function Le(){return(Le=n(s.mark(function e(t,r){return s.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=1,qe(t,JSON.stringify(r));case 1:case"end":return e.stop()}},e)}))).apply(this,arguments)}function Ne(){return(Ne=n(s.mark(function e(t){return s.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=1,x.rm.entry(Pe,t);case 1:e.next=3;break;case 2:e.prev=2,e.catch(0);case 3:case"end":return e.stop()}},e,null,[[0,2]])}))).apply(this,arguments)}function Re(){return(Re=n(s.mark(function e(){return s.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=1,x.rm.all(Pe);case 1:e.next=3;break;case 2:e.prev=2,e.catch(0);case 3:case"end":return e.stop()}},e,null,[[0,2]])}))).apply(this,arguments)}var Te=Object.freeze({__proto__:null,clear:function(){return Re.apply(this,arguments)},evict:function(e){return Ne.apply(this,arguments)},getObject:function(e){return De.apply(this,arguments)},getText:Be,ls:function(){return Ee.apply(this,arguments)},setObject:function(e,t){return Le.apply(this,arguments)},setPath:function(e){Pe=e},setText:qe}),Me="eD300Ezu9r4Q3CPM7XQt-Q";function Ue(e){return _e.apply(this,arguments)}function _e(){return(_e=n(s.mark(function e(t){var r,n,a,u,i,o,c,f,l,p,h,d;return s.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return r=t.uid,n=t.device,a=void 0===n?"unknow":n,u=t.key,i=void 0===u?Me:u,o=t.timeout,c=void 0===o?30:o,f=(new Date).getTime(),e.next=1,v(m)(16);case 1:return l=e.sent,p=Buffer.from(f+60*c*1e3+"","ascii"),h=Buffer.concat([p,Buffer.from("".concat(r,"<=>").concat(a,"<=>").concat(f)),l]),e.next=2,me(h,i);case 2:return d=e.sent,e.next=3,qe("".concat(r,"@").concat(a),f);case 3:return e.abrupt("return",d.toString("base64url"));case 4:case"end":return e.stop()}},e)}))).apply(this,arguments)}function Fe(e){return $e.apply(this,arguments)}function $e(){return($e=n(s.mark(function e(t){var r,n,a,u,o,c,f,l,p,h,v,d;return s.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return r=t.token,n=t.key,a=void 0===n?Me:n,u=Buffer.from(r,"base64url"),e.next=1,ge(u,a);case 1:if(o=e.sent,c=o.subarray(0,o.length-16).toString("utf8"),!(parseInt(c.slice(0,13))<(new Date).getTime())){e.next=2;break}return e.abrupt("return",null);case 2:return f=c.slice(13).split("<=>"),l=i(f,3),p=l[0],h=l[1],v=l[2],e.next=3,Be("".concat(p,"@").concat(h));case 3:if(d=e.sent,!(parseInt(v)<parseInt(d))){e.next=4;break}return e.abrupt("return",null);case 4:return e.abrupt("return",{uid:p,device:h});case 5:case"end":return e.stop()}},e)}))).apply(this,arguments)}function Qe(e){var t=e.userGetter,r=e.ACLGetter,a=e.tokenParser,u=void 0===a?Fe:a;return function(){var e=n(s.mark(function e(n,a){var i,o,c,f,l,p,h,v,d;return s.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if((i=null)||(c=null===(o=n.headers)||void 0===o?void 0:o.authorization,i=null==c?void 0:c.substring(7).trim()),i||(i=null===(f=n.query)||void 0===f?void 0:f.token),O.debug("--\x3e token: %s",i),i){e.next=2;break}return e.next=1,a();case 1:return e.abrupt("return");case 2:return e.prev=2,e.next=3,u({token:i});case 3:if(l=e.sent,p=l.uid,h=l.device,O.debug("uid: %s, device: %s",p,h),!t||"function"!=typeof t){e.next=5;break}return e.next=4,t({uid:p,device:h});case 4:v=e.sent,n.state.USER=v;case 5:if(!r||"function"!=typeof r){e.next=7;break}return e.next=6,r({uid:p,device:h});case 6:d=e.sent,n.state.ACL=d;case 7:e.next=9;break;case 8:e.prev=8,e.catch(2),n.throw(401);case 9:return e.next=10,a();case 10:case"end":return e.stop()}},e,null,[[2,8]])}));return function(t,r){return e.apply(this,arguments)}}()}function Je(){return function(){var e=n(s.mark(function e(t,r){var n;return s.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=1,r();case 1:(n=t.accepts("*/*","text/*","application/json"))&&(t.type="".concat(n,"; charset=utf-8"));case 2:case"end":return e.stop()}},e)}));return function(t,r){return e.apply(this,arguments)}}()}function We(n){var a=n.context,u=void 0===a?"":a,i=n.routes,o=void 0===i?[]:i,c=n.plugins,s=void 0===c?[]:c,f=n.userGetter,l=void 0===f?null:f,p=n.ACLGetter,h=void 0===p?null:p,v=n.tokenParser,d=void 0===v?null:v,b=n.logger,m=void 0===b?null:b;m&&S(m);var y=new t;return y.use(r({enableTypes:["json","form","text"]})),y.use(Qe({userGetter:l,ACLGetter:h,tokenParser:d})),y.use(le(o,u)),y.use(Je()),s.forEach(function(e){y.use(e)}),e.createServer(y.callback())}function Ye(e){var t=e.context,r=void 0===t?"":t,n=e.routes,a=void 0===n?[]:n,u=e.plugins,i=void 0===u?[]:u,o=e.hostname,c=void 0===o?"localhost":o,s=e.port,f=void 0===s?9090:s,l=e.userGetter,p=void 0===l?null:l,h=e.ACLGetter,v=void 0===h?null:h,d=e.tokenParser,b=void 0===d?null:d,m=e.logger,y=We({context:r,routes:a,plugins:i,logger:void 0===m?null:m,userGetter:p,ACLGetter:v,tokenParser:b});O.info("--\x3e niba is listening at http://".concat(c,":").concat(f)),y.listen(f,c)}export{T as BadGateway,z as BadRequest,L as Conflict,E as Forbidden,N as InternalServerError,I as MethodNotAllowed,A as NBError,D as NotAcceptable,B as NotFound,R as NotImplemented,q as ProxyAuthenticationRequired,M as ServiceUnavailable,G as Timeout,P as Unauthorized,Qe as authentication,Te as cache,ae as clearCache,Ae as clearKeyCache,We as createServer,Ue as createToken,ge as decrypt,Ce as decryptSync,Oe as decryptText,le as dispatcher,te as enableCache,me as encrypt,je as encryptSync,we as encryptText,ue as getCacheStats,O as logger,Fe as parseToken,Je as rjson,Ye as serve,re as setCacheMaxSize,ne as setCacheTTL,S as setLogger};
|