miolo 0.9.32 → 0.9.34
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/dist/cli/miolo.cli.iife.bundle.js +1 -1
- package/dist/cli/miolo.cli.iife.bundle.min.js +1 -1
- package/dist/cli/miolo.cli.iife.js +1 -1
- package/dist/cli/miolo.cli.iife.min.js +1 -1
- package/dist/cli/miolo.cli.min.mjs +1 -1
- package/dist/cli/miolo.cli.mjs +1 -1
- package/dist/cli/miolo.cli.umd.bundle.js +1 -1
- package/dist/cli/miolo.cli.umd.bundle.min.js +1 -1
- package/dist/cli/miolo.cli.umd.js +1 -1
- package/dist/cli/miolo.cli.umd.min.js +1 -1
- package/dist/cli-react/miolo.cli-react.iife.bundle.js +1 -1
- package/dist/cli-react/miolo.cli-react.iife.bundle.min.js +1 -1
- package/dist/cli-react/miolo.cli-react.iife.js +1 -1
- package/dist/cli-react/miolo.cli-react.iife.min.js +1 -1
- package/dist/cli-react/miolo.cli-react.min.mjs +1 -1
- package/dist/cli-react/miolo.cli-react.mjs +1 -1
- package/dist/cli-react/miolo.cli-react.umd.bundle.js +1 -1
- package/dist/cli-react/miolo.cli-react.umd.bundle.min.js +1 -1
- package/dist/cli-react/miolo.cli-react.umd.js +1 -1
- package/dist/cli-react/miolo.cli-react.umd.min.js +1 -1
- package/dist/server/miolo.server.cjs +10 -7
- package/dist/server/miolo.server.min.mjs +2 -2
- package/dist/server/miolo.server.mjs +10 -7
- package/dist/server/miolo.server.mjs.map +1 -1
- package/dist/server/miolo.server.node.mjs +10 -7
- package/package.json +1 -1
package/dist/cli/miolo.cli.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* miolo v0.9.
|
|
2
|
+
* miolo v0.9.34
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Donato Lorenzo <donato@afialapis.com>
|
|
5
5
|
*
|
|
@@ -929,17 +929,20 @@ function reopenTransportOnHupSignal(fileTransport) {
|
|
|
929
929
|
try {
|
|
930
930
|
if (fileTransport._stream) {
|
|
931
931
|
fileTransport._stream.end();
|
|
932
|
-
fileTransport._stream.
|
|
932
|
+
fileTransport._stream.destroy(); // Soon()
|
|
933
933
|
}
|
|
934
934
|
var stream = fs.createWriteStream(fullname, fileTransport.options);
|
|
935
935
|
stream.setMaxListeners(Infinity);
|
|
936
936
|
fileTransport._size = 0;
|
|
937
937
|
fileTransport._stream = stream;
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
938
|
+
|
|
939
|
+
//fileTransport.once('flush', function () {
|
|
940
|
+
fileTransport.opening = false;
|
|
941
|
+
fileTransport.emit('open', fullname);
|
|
942
|
+
//})
|
|
943
|
+
|
|
944
|
+
//fileTransport.flush()
|
|
945
|
+
|
|
943
946
|
console.log("[miolo][file-logger] Reopened " + fullname + " successfully");
|
|
944
947
|
} catch (error) {
|
|
945
948
|
console.error("[miolo][file-logger] Error reopening " + fullname + ": " + error.toString());
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* miolo v0.9.
|
|
2
|
+
* miolo v0.9.34
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Donato Lorenzo <donato@afialapis.com>
|
|
5
5
|
*
|
|
@@ -8,4 +8,4 @@
|
|
|
8
8
|
*
|
|
9
9
|
* @license MIT
|
|
10
10
|
*/
|
|
11
|
-
import e from"node:http";import r from"koa";import{createHttpTerminator as o}from"http-terminator";import t from"deepmerge";import n from"node:path";import{fileURLToPath as i}from"node:url";import{getConnection as a}from"calustra";export{getConnection as miolo_db_connection}from"calustra";import l from"nodemailer";import{uncolor as c,red as u,gray as s,magenta as d,cyan as f,yellow as v,red_light as p,green as m,cyan_light as h,blue as g,green_bold as y,yellow_bold as b}from"tinguir";import x,{promisify as S}from"node:util";import _,{transports as w,createLogger as k,format as O}from"winston";import E,{readFileSync as R}from"node:fs";import C from"koa-better-body";import q from"koa-convert";import P from"koa-compress";import{constants as M}from"node:zlib";import I from"koa-ratelimit";import j from"node:https";import L from"koa-mount";import F from"koa-static";import T from"koa-favicon";import{performance as J}from"node:perf_hooks";import{Reader as U}from"@maxmind/geoip2-node";import A from"@koa/router";import N from"jwt-simple";import z from"koa-passport";import B from"passport-local";import D from"koa-session";import G from"koa-redis";import W from"@koa/cors";import H from"koa-proxies";import Y from"qs";import{renderToString as K}from"react-dom/server";import{CronJob as V}from"cron";import X from"node:os";import Z from"diskspace";import Q from"redis";function $(e,r){var o=Object.keys(e);if(Object.getOwnPropertySymbols){var t=Object.getOwnPropertySymbols(e);r&&(t=t.filter((function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable}))),o.push.apply(o,t)}return o}function ee(e){for(var r=1;r<arguments.length;r++){var o=null!=arguments[r]?arguments[r]:{};r%2?$(Object(o),!0).forEach((function(r){ne(e,r,o[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(o)):$(Object(o)).forEach((function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(o,r))}))}return e}function re(e){var r=function(e,r){if("object"!=typeof e||!e)return e;var o=e[Symbol.toPrimitive];if(void 0!==o){var t=o.call(e,r||"default");if("object"!=typeof t)return t;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(e)}(e,"string");return"symbol"==typeof r?r:String(r)}function oe(e,r,o,t,n,i,a){try{var l=e[i](a),c=l.value}catch(u){return void o(u)}l.done?r(c):Promise.resolve(c).then(t,n)}function te(e){return function(){var r=this,o=arguments;return new Promise((function(t,n){var i=e.apply(r,o);function a(e){oe(i,t,n,a,l,"next",e)}function l(e){oe(i,t,n,a,l,"throw",e)}a(void 0)}))}}function ne(e,r,o){return(r=re(r))in e?Object.defineProperty(e,r,{value:o,enumerable:!0,configurable:!0,writable:!0}):e[r]=o,e}var ie=i(import.meta.url),ae=n.dirname(ie),le={name:"miolo",http:{port:8001,hostname:"localhost",catcher_url:"/sys/jserror",static:{favicon:n.resolve(ae,"../static/img/miolo.ico"),folders:{}},cors:!1,proxy:!1,ratelimit:{max:1e3,duration:6e4,errorMessage:"Rate Limit reached",whitelist_ips:[],blacklist_ips:[],ipsum_folder:"/var/ipsum"},request:{lazy:1,slow:2,onStart:void 0,onDone:void 0,geoip:{enabled:!1,db:"/var/lib/GeoIP/GeoLite2-City.mmdb",local_ips:["127.0.0.1"]}}},session:{salt:"SUPER_SALTY_YES?",secret:"SUPER_SECRET_KEY_KERE",options:{maxAge:864e5,secure:!0,sameSite:null}},db:{config:{dialect:"postgres",host:"localhost",port:5432,database:"miolo",user:"postgres",password:"postgres",max:5,min:0,idleTimeoutMillis:1e4},options:{tables:[]}},routes:{bodyField:void 0,crud:[{prefix:"",routes:[]}],queries:[]},log:{level:"debug",format:{locale:"en-GB"},console:{enabled:!0,level:"silly"},file:{enabled:!0,level:"silly",filename:"/var/log/afialapis/%MIOLO%.log",zippedArchive:!0,maxsize:20971520,maxFiles:20},mail:{enabled:!1,level:"warn",name:"miolo",from:"miolo@mail.com",to:"errors@mail.com"}},mail:{silent:!0,options:{port:25,host:"mail.com",authMethod:"PLAIN",secure:!1,tls:{rejectUnauthorized:!1},logger:!1,debug:!1},defaults:{name:"miolo",from:"miolo@mail.com",to:"errors@mail.com"}},auth:{},render:{},middlewares:[],cron:[]};function ce(e){var{options:r,defaults:o,silent:t}=e,n=l.createTransport(r,o);function i(){return(i=te((function*(e){if(!0===t)return console.info("*********************************"),console.info("This mail will not be send (emailing is disabled):"),console.info(e),console.info("*********************************"),{ok:!0,silent:!0,error:void 0,messageId:void 0};try{var r=n.sendMail(e);return r.ok=!(null==r||!r.messageId),r}catch(o){return{error:o,ok:!1}}}))).apply(this,arguments)}var a={send:function(e){return i.apply(this,arguments)},verify:function(){console.info("[miolo][Verify][MAILER] Verifying..."),n.verify((function(e,r){e?(console.error("[miolo][Verify][MAILER] Verifying ERROR"),console.error(e)):console.info("[miolo][Verify][MAILER] Verifyed OK: Server is ready to take our messages")}))},options:r,defaults:o,silent:t};return a}var{combine:ue,timestamp:se,_label:de,printf:fe,errors:ve}=O,pe=function(e,r){var o,t,i,a,l=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"miolo",m={silly:s,debug:d,verbose:f,info:v,warn:p,error:u},h={silly:"sly",debug:"dbg",verbose:"vbs",info:"inf",warn:"wrn",error:"err"},g=[];!0===(null==e||null===(o=e.console)||void 0===o?void 0:o.enabled)&&g.push(new w.Console({humanReadableUnhandledException:!0,level:(null==e||null===(a=e.console)||void 0===a?void 0:a.level)||(null==e?void 0:e.level)||"silly",handleExceptions:!0}));if(!0===(null==e||null===(t=e.file)||void 0===t?void 0:t.enabled)){var y,b,S=new w.File({filename:null!=e&&null!==(y=e.file)&&void 0!==y&&y.filename?e.file.filename.replace("%MIOLO%",l):"/var/log/afialapis/miolo.log",level:(null==e||null===(b=e.file)||void 0===b?void 0:b.level)||(null==e?void 0:e.level)||"info",humanReadableUnhandledException:!0,handleExceptions:!0});!function(e){process.on("SIGHUP",(function(){var r=n.join(e.dirname,e._getFile(!1));return function(){console.log("[miolo][file-logger] SIGHUP received. Reopening ".concat(r,"..."));try{e._stream&&(e._stream.end(),e._stream.destroySoon());var o=E.createWriteStream(r,e.options);o.setMaxListeners(1/0),e._size=0,e._stream=o,e.once("flush",(function(){e.opening=!1,e.emit("open",r)})),e.flush(),console.log("[miolo][file-logger] Reopened ".concat(r," successfully"))}catch(t){console.error("[miolo][file-logger] Error reopening ".concat(r,": ").concat(t.toString()))}}()}))}(S),g.push(S)}if(!0===(null==e||null===(i=e.mail)||void 0===i?void 0:i.enabled)){var O=function(e,r){var o=function(o){_.Transport.call(this,o),o=o||{},this.level=e.level||"info",this.ename=(null==e?void 0:e.name)||r.defaults.name,this.to=e.to||r.defaults.to,this.from=e.from||r.defaults.from,this.humanReadableUnhandledException=o.humanReadableUnhandledException||!0,this.handleExceptions=o.handleExceptions||!0,this.json=o.json||!1,this.colorize=o.colorize||!1};return x.inherits(o,_.Transport),o.prototype.name="MailerLogger",o.prototype.log=function(o,t){var n=this,i="",a="";try{try{i=o.message.split("\n")[0]}catch(s){i=o.message.toString()}i=c(i)}catch(d){i="Could not create a title for the error (".concat(d.toString(),")")}try{try{a=c(o.message)}catch(d){a=o.message.toString()}}catch(d){a="Could not create a body for the error (".concat(d.toString(),")")}var l="".concat(null==e?void 0:e.name," [").concat(o.level.toUpperCase(),"] ").concat(i),u={from:this.from,to:this.to,subject:l,text:a};r.send(u,(function(){n.emit("logged"),t(null,!0)}))},o}(e.mail,r);w.MailerLogger=O,g.push(new w.MailerLogger({humanReadableUnhandledException:!0,handleExceptions:!0}))}var R=k({level:(null==e?void 0:e.level)||"silly",format:ue(ve({stack:!0}),se(),fe((r=>{var o,t=m[r.level],n=new Date(r.timestamp).toLocaleString((null==e||null===(o=e.format)||void 0===o?void 0:o.locale)||"en"),i="[".concat(l,"] ").concat(t(n)," ").concat(t(h[r.level])," ").concat(r.message);return r.stack?"".concat(i,"\n").concat(r.stack):i}))),transports:g});try{R.info("[logger] Inited for ".concat(R.transports.map((e=>"".concat(e.name," (").concat(e.level,")").concat(e.silent?u(" SILENT!"):""))).join(", ")))}catch(C){}return R},me=(e,r)=>{var o=ce(r.mail),t=pe(r.log,o,null==r?void 0:r.name),n=ee(ee({},r.db.options),{},{log:t}),i={getConnection:()=>a(r.db.config,n),getModel:e=>a(r.db.config,n).getModel(e)},l={config:ee({},r),emailer:o,logger:t,db:i};function c(){return(c=te((function*(e,r){e.miolo=l,yield r()}))).apply(this,arguments)}e.use((function(e,r){return c.apply(this,arguments)})),e.context.miolo=l},he=[401,403];var ge="/var/ipsum",ye="ipsum.txt",be="https://raw.githubusercontent.com/stamparm/ipsum/master/ipsum.txt",xe=1;function Se(e,r){var o=r?r.error:console.error;if(!e)return[];try{var t=[];return e.split("\n").filter((e=>e.indexOf("#")<0)).map((e=>{var[r,o]=e.split("\t");parseInt(o)>=xe&&t.push(r)})),t}catch(n){return o("[cron][".concat(f("IPsum"),"] Error getting IPs from content")),[]}}function _e(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:ge,r=arguments.length>1?arguments[1]:void 0,o=arguments.length>2?arguments[2]:void 0,t=o?o.error:console.error,i=o?o.debug:console.log;if(E.existsSync(e))try{i("[cron][".concat(f("IPsum"),"] Updating file...")),function(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:be,o=arguments.length>2?arguments[2]:void 0,t=o?o.error:console.error;j.get(r,(r=>{var o=[];r.on("data",(e=>{o.push(e)})).on("end",(()=>{var r=Buffer.concat(o).toString();e(r)}))})).on("error",(r=>{t("[cron][".concat(f("IPsum"),"] Error downloading remote file (").concat(r.toString(),")")),e("")}))}((t=>{var a=n.join(e,ye);E.writeFileSync(a,t,{encoding:"utf8",flag:"w"});var l=t.split("\n").length,c=Se(t,o),u=c.length;i("[cron][".concat(f("IPsum"),"] File downloaded. ").concat(l," ips on the list (").concat(u," appearing in ").concat(xe," or more lists)")),r&&r(c)}))}catch(a){t("[cron][".concat(f("IPsum"),"] Error ").concat(a," updating the file"))}else t("[cron][".concat(f("IPsum"),"] Folder ").concat(e," does not exist"))}function we(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:ge,r=arguments.length>1?arguments[1]:void 0,o=arguments.length>2?arguments[2]:void 0,t=o?o.debug:console.log,i=o?o.warn:console.log,a=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:ge,r=arguments.length>1?arguments[1]:void 0,o=r?r.error:console.error;if(!E.existsSync(e))return r&&o("[cron][".concat(f("IPsum"),"] Folder ").concat(e," does not exist")),[];var t=n.join(e,ye);return E.existsSync(t)?Se(E.readFileSync(t,{encoding:"utf8"}),r):(r&&o("[cron][".concat(f("IPsum"),"] File ").concat(t," does not exist")),[])}(e,o);return a.length>0?(r&&r(a),t("[cron][".concat(f("IPsum"),"] File contains ").concat(a.length," ips")),a):(i("[cron][".concat(f("IPsum"),"] File is empty. Launching update...")),_e(e,r,o),[])}var ke=["52.212.247.108","54.218.32.58","170.106.82.193","110.166.71.39","205.210.31.240 ","134.122.52.203","165.232.105.25","66.249.73.200","35.206.153.204","199.244.88.227","198.12.222.107","212.128.118.10"];var Oe=i(import.meta.url),Ee=n.dirname(Oe),Re=n.resolve(Ee,"./miolo.ico"),Ce=n.resolve(Ee,"../../../.."),qe=void 0,Pe=["127.0.0.1"];var Me=function(e,r){var o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:console;if(Pe.indexOf(e)>=0)return{local:!0,country:"",city:""};try{var t,n=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"/var/lib/GeoIP/GeoLite2-City.mmdb",r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:["127.0.0.1"],o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:console;try{if(null!=qe)return qe;Pe=[...Pe,...r||[]];var t=E.readFileSync(e);return qe=U.openBuffer(t)}catch(n){return o.error("[geoip] Error initing:"),void o.error(n)}}(null==r?void 0:r.db,null==r?void 0:r.local_ipds,o),i=n.city(e);return{country:i.country.isoCode,city:null===(t=i.city)||void 0===t||null===(t=t.names)||void 0===t?void 0:t.en}}catch(a){o.error("[geoip] Error localizing IP ".concat(e,":")),o.error(a)}return{country:"",city:""}},Ie={total:0};var je=i(import.meta.url),Le=n.dirname(je),Fe=R(n.resolve(Le,"./robots.txt"),"utf8");var Te=(e,r,o)=>{var t=e.context.miolo.logger,n=()=>{try{var{make_guest_token:e}=r;if(null!=e)return e(o||{})}catch(n){}return function(e,r){var o=Math.random().toString(),t=null==e?void 0:e.secret;t||(t="miolo_unsafe_secret",r.error("Guest token made with an unsafe secret string. Please, configure your own through session.secret."));var n={admin:!1,buid:o};return N.encode(n,t)}(o||{},t)};function i(){return i=te((function*(e,r){var i=e.cookies.get("token")||e.headers.token;void 0!==i&&0!=i.length||(i=yield n(),t.debug("Guest token conceeded"));var a=function(e){var r,o=null==e||null===(r=e.options)||void 0===r?void 0:r.maxAge;isNaN(o)&&(o=86400);var t=new Date;return t.setSeconds(t.getSeconds()+o),{expires:t,httpOnly:!1}}(o);e.cookies.set("token",i,a),e.session={user:{name:"guest"},authenticated:!0,token:i},yield r()})),i.apply(this,arguments)}e.use((function(e,r){return i.apply(this,arguments)}))},Je=(e,r)=>{var{auth_user:o,realm:t,paths:n}=r;function i(e,r){return a.apply(this,arguments)}function a(){return(a=te((function*(r,n){var i;try{i=(e=>{var r,o=null==e||null===(r=e.headers)||void 0===r?void 0:r.authorization;if(o)try{o=o.replace("Basic ","");try{o=Buffer.from(o,"base64").toString()}catch(i){o=atob(o)}var[t,n]=o.split(":");return{username:t,password:n}}catch(i){return}})(r.request)}catch(c){}var a=()=>{r.session={user:void 0,authenticated:!1},r.body={user:void 0,authenticated:!1},r.response.status=401,r.response.headers["WWW-Authenticate"]='Basic realm="'+t.replace(/"/g,'\\"')+'"'};if(!i)return a();var l=yield o(i.username,i.password,e.context.miolo);if(!1===l||null==l)return a();r.session={user:l,authenticated:!0},yield n()}))).apply(this,arguments)}t||(t="Secure Area"),null==n||0==n.length?e.use(i):n.map((r=>e.use(L(r,i))))},Ue=new G;var Ae=(e,r,o)=>r(null,e.id),Ne=(e,r,o)=>{r(Error("You need to define auth.passport.find_user_by_id"),null)},ze=(e,r,o,t)=>{o(Error("You need to define auth.passport.local_auth_user"),null)},Be=(e,r,o)=>{var{get_user_id:t,find_user_by_id:n,local_auth_user:i,url_login:a,url_logout:l,url_login_redirect:c,url_logout_redirect:u}=r,s=t||Ae,d=n||Ne,f=i||ze,v=a||"/login",p=l||"/logout",m=new B.Strategy(((r,o,t)=>{f(r,o,t,e.context.miolo)}));function h(){return(h=te((function*(e,r){try{e.session.authenticated&&(e.session.user=e.state.user)}catch(o){}yield r()}))).apply(this,arguments)}!function(e,r){e.keys=[r.secret||"*secret*"];var o=ee({store:Ue},r.options||{});e.use(D(o,e))}(e,o),z.serializeUser(((r,o)=>{process.nextTick((function(){s(r,o,e.context.miolo)}))})),z.deserializeUser(((r,o)=>{process.nextTick((function(){d(r,o,e.context.miolo)}))})),z.use(m),e.use(z.initialize()),e.use(z.session()),e.use((function(e,r){return h.apply(this,arguments)}));var g=function(){var e=te((function*(e,r){e.session.authenticated?(e.session.user=void 0,e.session.authenticated=!1,yield e.logout(),e.body={user:void 0,authenticated:!1},null!=u&&e.redirect(u)):(e.body={user:void 0,authenticated:!1},e.response.status=401)}));return function(r,o){return e.apply(this,arguments)}}(),y=new A;y.post(v,((e,r)=>z.authenticate("local",function(){var r=te((function*(r,o,t,n){if(!1!==o)return e.session.user=e.state.user,e.session.authenticated=!0,e.body={user:o,authenticated:!0},null!=c&&e.redirect(c),yield e.login(o);e.session.user=void 0,e.session.authenticated=!1,e.body={user:void 0,authenticated:!1,info:t,error:r},e.response.status=401}));return function(e,o,t,n){return r.apply(this,arguments)}}())(e))),y.get(p,g),y.post(p,g),e.use(y.routes())},De=(e,r,o)=>{try{var t=e[r];if(null!=t&&0!=t)return o(t)}catch(n){}},Ge=(e,r)=>{var o=e.context.miolo.logger;De(r,"cors",(r=>{if("simple"==r)o.debug("Setting CORS the simple way"),e.use(function(){var e=te((function*(e,r){e.set("Access-Control-Allow-Origin","*"),e.set("Access-Control-Expose-Headers","SourceMap,X-SourceMap"),yield r()}));return function(r,o){return e.apply(this,arguments)}}());else{var t=(e=>"object"==typeof e?e:{})(r);o.debug("Setting CORS headers for ".concat(JSON.stringify(t))),e.use(W(t))}})),De(r,"proxy",(r=>{var[t,n]=(e=>{var r,o,t,n;return null==e&&(e={}),[(null===(r=e)||void 0===r?void 0:r.path)||"/",{target:(null===(o=e)||void 0===o?void 0:o.target)||"https://proxy.miolo.com",changeOrigin:null==(null===(t=e)||void 0===t?void 0:t.changeOrigin)||e.changeOrigin,logs:null==(null===(n=e)||void 0===n?void 0:n.logs)||e.logs}]})(r);o.debug("Setting Proxy for ".concat(t," to ").concat(n.target," ")),e.use(H(t,n))}))},We=function(){var e=te((function*(e){return!0}));return function(r){return e.apply(this,arguments)}}(),He=function(){var e=te((function*(e,r){return r}));return function(r,o){return e.apply(this,arguments)}}(),Ye={require:!1,action:"redirect",redirect_url:"/",error_code:401},Ke={use:!1,fieldNames:{created_by:"created_by",last_update_by:"last_update_by"}},Ve=e=>{var r=(null==e?void 0:e.crud)||[];if(!r)return[];if(!Array.isArray(r))return[];var o=[];return r.map((r=>{var n=null==r?void 0:r.routes;if(n&&Array.isArray(n)){var i=(null==r?void 0:r.bodyField)||(null==e?void 0:e.bodyField),a=(null==r?void 0:r.before)||(null==e?void 0:e.before)||We,l=(null==r?void 0:r.after)||(null==e?void 0:e.after)||He,c=t(Ye,(null==e?void 0:e.auth)||{},(null==r?void 0:r.auth)||{}),u=[];for(var s of n){var d="string"==typeof s?{name:s}:s;if(d.name){var f={name:d.name,url:(null==d?void 0:d.url)||d.name,mode:(null==d?void 0:d.mode)||"rw",bodyField:(null==d?void 0:d.bodyField)||i,useUserFields:t(Ke,(null==d?void 0:d.useUserFields)||{}),auth:t(c,(null==d?void 0:d.auth)||{}),before:(null==d?void 0:d.before)||a,after:(null==d?void 0:d.after)||l};u.push(f)}}u.length>0&&o.push({prefix:(null==r?void 0:r.prefix)||"",routes:u})}})),o};function Xe(e){var r=e.indexOf("?")>=0?e.substr(e.indexOf("?")+1):"";return r?Y.parse(r):{}}function Ze(e,r,o,t){o.map((o=>{var n=o.prefix;o.routes.map((o=>{var i=e.getModel(o.name);if(i){for(var a=function(){var e=te((function*(e,r){var n,i=!0===(null==e||null===(n=e.session)||void 0===n?void 0:n.authenticated),a=o.auth;return!(!0===a.require||"read-only"===a.require&&"w"===r)||(i||("error"==a.action?(t.error("[miolo-router] Unauthorized access. Throwing error ".concat(a.error_code)),e.throw(a.error_code,null,{})):"redirect"==a.action?(t.warn("[miolo-router] Unauthorized access. Redirecting to ".concat(a.redirect_url)),e.redirect(a.redirect_url)):(t.error("[miolo-router] Crud path ".concat(o.url," specified auth but no action")),e.body={})),i)}));return function(r,o){return e.apply(this,arguments)}}(),l=function(){var e=te((function*(e,r,n){var i,l={};try{var c;if(!(yield a(e,r)))return void(e.body={});var u=!0;if(null!=o&&o.before&&(u=yield o.before(e)),!u)return void(e.body={});var s=null==e||null===(c=e.session)||void 0===c||null===(c=c.user)||void 0===c?void 0:c.id,d={};!0===o.useUserFields.use&&(d=o.useUserFields.fieldNames);var f={uid:s,fieldNames:d};l=yield n(f),null!=o&&o.after&&(l=yield o.after(e,l))}catch(v){t.error("[miolo-router] Unexpected error on CRUD ".concat(o.name,"-").concat(r)),t.error(v)}i=l,l=null==o.bodyField?i:{[o.bodyField]:i},e.body=l}));return function(r,o,t){return e.apply(this,arguments)}}(),c=function(){var e=te((function*(e){yield l(e,"r",function(){var r=te((function*(r){var o=Xe(e.request.url),t={transaction:void 0};return yield i.read(o,t)}));return function(e){return r.apply(this,arguments)}}())}));return function(r){return e.apply(this,arguments)}}(),u=function(){var e=te((function*(e){yield l(e,"r",function(){var r=te((function*(r){var o=Xe(e.request.url),t={transaction:void 0};return yield i.keyList(o,t)}));return function(e){return r.apply(this,arguments)}}())}));return function(r){return e.apply(this,arguments)}}(),s=function(){var e=te((function*(e){yield l(e,"r",function(){var r=te((function*(r){var o=Xe(e.request.url),t={transaction:void 0};return yield i.find(o.id,t)}));return function(e){return r.apply(this,arguments)}}())}));return function(r){return e.apply(this,arguments)}}(),d=function(){var e=te((function*(e){yield l(e,"r",function(){var r=te((function*(r){var o=Xe(e.request.url),t={transaction:void 0};return yield i.distinct(o.distinct_field,o,t)}));return function(e){return r.apply(this,arguments)}}())}));return function(r){return e.apply(this,arguments)}}(),f=function(){var e=te((function*(e){yield l(e,"w",function(){var r=te((function*(r){var o,t=e.request.fields;null!=r&&null!==(o=r.fieldNames)&&void 0!==o&&o.created_by&&(t[r.fieldNames.created_by]=r.uid);var n={transaction:void 0};return yield i.insert(t,n)}));return function(e){return r.apply(this,arguments)}}())}));return function(r){return e.apply(this,arguments)}}(),v=function(){var e=te((function*(e){yield l(e,"w",function(){var r=te((function*(r){var o,t=e.request.fields;null!=r&&null!==(o=r.fieldNames)&&void 0!==o&&o.last_update_by&&(t[r.fieldNames.last_update_by]=r.uid);var n={transaction:void 0};return yield i.update(t,{id:t.id},n)}));return function(e){return r.apply(this,arguments)}}())}));return function(r){return e.apply(this,arguments)}}(),p=function(){var e=te((function*(e){yield l(e,"w",function(){var r=te((function*(r){var o=e.request.fields,t={transaction:void 0};return yield i.delete({id:o.id},t)}));return function(e){return r.apply(this,arguments)}}())}));return function(r){return e.apply(this,arguments)}}(),m=n?"/".concat(n,"/").concat(o.url):"/".concat(o.url);m.indexOf("//")>=0;)m=m.replace(/\/\//g,"/");t.info("[miolo-router] Routing table ".concat(o.name," to ").concat(m));var h=o.mode.indexOf("r")>=0,g=o.mode.indexOf("w")>=0,y=o.mode.indexOf("u")>=0||g;h&&(r.get("".concat(m,"/find"),(e=>s(e))),r.get("".concat(m,"/read"),(e=>c(e))),r.get("".concat(m,"/distinct"),(e=>d(e))),r.get("".concat(m,"/key_list"),(e=>u(e)))),y&&(r.post("".concat(m,"/save"),(e=>f(e))),r.post("".concat(m,"/update"),(e=>v(e)))),g&&r.post("".concat(m,"/delete"),(e=>p(e)))}else t.error("[miolo-router] Could not get model for ".concat(o.name))}))}))}var Qe=e=>{var r=(null==e?void 0:e.queries)||[];if(!r)return[];if(!Array.isArray(r))return[];var o=[];return r.map((r=>{var n=null==r?void 0:r.routes;if(n&&Array.isArray(n)){var i=(null==r?void 0:r.before)||(null==e?void 0:e.before)||We,a=(null==r?void 0:r.after)||(null==e?void 0:e.after)||He,l=t(Ye,(null==r?void 0:r.auth)||{},(null==e?void 0:e.auth)||{}),c=[];for(var u of n)if(u.url&&u.callback){var s={url:u.url,method:(null==u?void 0:u.method)||"GET",callback:u.callback,auth:t(l,(null==u?void 0:u.auth)||{}),before:(null==u?void 0:u.before)||i,after:(null==u?void 0:u.after)||a};c.push(s)}o.push({prefix:(null==r?void 0:r.prefix)||"",routes:c})}})),o};function $e(e,r,o){var t=e.context.miolo.logger,n=new A;try{var i=Ve(o),a=Qe(o),l=i.length>0,c=a.length>0;if(!l&&!c)throw"[miolo-router] Could not get any route from the passed <routes> param";l&&Ze(r,n,i,t),c&&function(e,r,o){r.map((r=>{var t=r.prefix;r.routes.map((r=>{for(var n,i=t?"/".concat(t,"/").concat(r.url):"/".concat(r.url);i.indexOf("//")>=0;)i=i.replace(/\/\//g,"/");o.info("[miolo-router] Routing ".concat((null===(n=r.callback)||void 0===n?void 0:n.name)||"callback"," to ").concat(r.method," ").concat(i));var a=function(){var e=te((function*(e){var t,n=!0===(null==e||null===(t=e.session)||void 0===t?void 0:t.authenticated),i=r.auth;return!(!0===i.require||"read-only"===i.require&&"POST"===r.method)||(n||("error"==i.action?(o.error("Unauthorized access. Throwing error ".concat(i.error_code)),e.throw(i.error_code,null,{})):"redirect"==i.action?(o.warn("Unauthorized access. Redirecting to ".concat(i.redirect_url)),e.redirect(i.redirect_url)):(o.error("Route path ".concat(r.url," specified auth but no action")),e.body={})),n)}));return function(r){return e.apply(this,arguments)}}(),l=function(){var e=te((function*(e){var t={};try{try{var n;if("GET"==r.method&&(null===(n=e.request)||void 0===n||!n.fields)&&e.request.url.indexOf("?")>0){var i=Xe(e.request.url);i&&(e.request.fields=i)}}catch(c){o.error("[miolo-router] Error while trying to qet query params for ".concat(e.request.url))}if(!(yield a(e)))return;var l=!0;if(null!=r&&r.before&&(l=yield r.before(e)),!l)return;t=yield r.callback(e),null!=r&&r.after&&(t=yield r.after(e,t))}catch(u){o.error("[miolo-router] Unexpected error on Query ".concat(r.name)),o.error(u)}return t}));return function(r){return e.apply(this,arguments)}}(),c=r.method.toLowerCase();e[c](i,(e=>l(e,r)))}))}))}(n,a,t)}catch(u){t.error(u),t.error("[miolo-router] Error initing the router. Probably config objects are not ok"),t.error("[miolo-router] connOrConfig:"),t.error(null==r?void 0:r.config),t.error("[miolo-router] routes:"),t.error(o)}e.use(n.routes())}var er=i(import.meta.url),rr=n.dirname(er),or=R(n.resolve(rr,"fallback_index.html"),"utf8");function tr(e){return e?e/1e6:0}function nr(e){return e?e/1e6:0}function ir(){return{name:"SysCheck",cronTime:"0,15,30,45 * * * *",onTick:(e,r)=>{var o,t,n,i;o=e.logger,t=Math.round(tr(X.freemem()),2),n=Math.round(tr(X.totalmem()),2),(i=Math.round(100*t/n,2))>80?o.error("[cron][".concat(f("SysCheck"),"] RAM ").concat(v(t)," MB used of ").concat(m(n)," MB (").concat(v(i)," %)")):o.info("[cron][".concat(f("SysCheck"),"] RAM ").concat(v(t)," MB used of ").concat(m(n)," MB (").concat(v(i)," %)")),Z.check("/",(function(e,r){var t=Math.round(nr(r.used),2),n=Math.round(nr(r.total),2),i=Math.round(nr(r.free),2);i<1?o.error("[cron][".concat(f("SysCheck"),"] DISK ").concat(v(t)," GB used of ").concat(m(n)," GB (").concat(v(i)," GB free)")):o.info("[cron][".concat(f("SysCheck"),"] DISK ").concat(v(t)," GB used of ").concat(m(n)," GB (").concat(v(i)," GB free)"))}))},start:!0}}function ar(e,r){var o=e.context.miolo,t=o.logger,n=[ir(),{name:"IPsum",cronTime:"0 0 * * *",onTick:(e,r)=>{_e(e.config.http.ratelimit.ipsum_folder||ge,(r=>{e.logger.info("[cron][".concat(f("IPsum"),"] File downloaded. ").concat(m(r.length)," ips will be ").concat(v("blacklisted"),"!"))}),e.logger)},start:!0},...r||[]],i=[];n.map((e=>{var r=e.name,t=function(e,r){var o,t=e.logger,n=null!=r&&null!==(o=r.onTick)&&void 0!==o&&o.name&&"onTick"!=r.onTick.name?r.onTick.name:"custom",i=(null==r?void 0:r.name)||n;return new V((null==r?void 0:r.cronTime)||"*/5 * * * *",(o=>{try{t.silly("[cron][Custom Job ".concat(f(i),"] ").concat(y("ticks!"))),r.onTick(e,o)}catch(n){t.error("[cron][Custom Job ".concat(f(i),"] Error at onTick()")),t.error(n)}}),(()=>{if(t.silly("[cron][Custom Job ".concat(f(i),"] ").concat(y("completed!"))),null!=r&&r.onComplete)try{r.onComplete(e)}catch(o){t.error("[cron][Custom Job ".concat(f(i),"] Error at onComplete()")),t.error(o)}}),!0===(null==r?void 0:r.start),(null==r?void 0:r.timezone)||"Europe/Madrid")}(o,e);i.push({name:r,job:t,running:!0===(null==e?void 0:e.start)})}));var a=e=>{var r;return(r="number"==typeof e?i[e]:i.filter((r=>r.name==e))[0])||t.error("[cron] Cannot stop job ".concat(f(e),": Not Found")),r},l=e=>{try{e.job.stop(),e.running=!1,t.debug("[cron][Job ".concat(f(e.name),"] ").concat(b("manually stopped!")))}catch(r){t.error("[cron][Job ".concat(f(e.name),"] Error manually stopping it")),t.error(r)}};e.cron={jobs:i,start:e=>{var r=a(e);r&&(e=>{try{e.job.stop(),e.running=!0,t.debug("[cron][Job ".concat(f(e.name),"] ").concat(y("manually started!")))}catch(r){t.error("[cron][Job ".concat(f(e.name),"] Error manually starting it")),t.error(r)}})(r)},stop:e=>{var r=a(e);r&&l(r)},stop_all:()=>{i.map((e=>{l(e)}))}}}function lr(n,i){var a,l,c,s=new r,p=function(e){var r,o=t(le,e);return o.auth_type=function(e){var r,o,t;return null!=e&&null!==(r=e.auth)&&void 0!==r&&r.basic?"basic":null!=e&&null!==(o=e.auth)&&void 0!==o&&o.credentials?"credentials":null!=e&&null!==(t=e.auth)&&void 0!==t&&t.custom?"custom":"guest"}(e),o.use_catcher=!(null==o||null===(r=o.http)||void 0===r||!r.catcher_url),o}(n);me(s,p),Ge(s,p.http),(e=>{e.use(P({filter:function(e){return"application/json"==e||"text/html"==e},gzip:{flush:M.Z_SYNC_FLUSH},deflate:{flush:M.Z_SYNC_FLUSH},br:!1})),e.use(q(C({formLimit:"100mb",jsonLimit:"100mb",bufferLimit:"100mb"})))})(s),function(e){var r=e.context.miolo.logger;function o(){return(o=te((function*(e){if(e){var o=e.status||400;if(this.accepts(["text","json","html"])?"number"!=typeof o&&(o=500):(o=406,e.message="Unsupported type"),he.indexOf(o)>=0?r.warn("".concat(this.method," ").concat(this.url," - ").concat(o,": ").concat(e.message)):r.error(e),this.headerSent||!this.writable)return r.debug("headers were already sent, returning early"),void(e.headerSent=!0);this.type="json",this.status=o,this.body=JSON.stringify(this.body||"",null,2),this.length=Buffer.byteLength(this.body),this.res.end(this.body)}}))).apply(this,arguments)}e.context.onerror=function(e){return o.apply(this,arguments)}}(s),function(e,r){var o=e.context.miolo,t=e=>e.headers["x-real-ip"]||e.ip||"127.0.0.1",n=we(null==r?void 0:r.ipsum_folder,void 0,o.logger),i={driver:"memory",db:new Map,id:t,headers:{remaining:"Rate-Limit-Remaining",reset:"Rate-Limit-Reset",total:"Rate-Limit-Total"},disableHeader:!1,max:(null==r?void 0:r.max)||1e3,duration:(null==r?void 0:r.duration)||6e4,errorMessage:(null==r?void 0:r.errorMessage)||"Rate Limit reached",whitelist:(null==r?void 0:r.whitelist)||(e=>{var o=(null==r?void 0:r.whitelist_ips)||[];return!!o&&o.indexOf(t(e))>=0}),blacklist:(null==r?void 0:r.blacklist)||(e=>{var o=t(e),i=[...n,...ke,...(null==r?void 0:r.blacklist_ips)||[]].indexOf(o)>=0;return i&&e.miolo.logger.info("Rejecting ".concat(v("blacklisted")," ").concat(d(o))),i})};e.use(I(i))}(s,null===(a=p.http)||void 0===a?void 0:a.ratelimit),((e,r)=>{var{favicon:o,folders:t}=r,n=o||Re;for(var[i,a]of(e.context.miolo.logger.debug("[static] Serving favicon from ".concat(n.replace(Ce,""))),e.use(T(n)),Object.entries(t)))e.context.miolo.logger.debug("[static] Mounting static folder ".concat(i," => ").concat(a.replace(Ce,""))),e.use(L(i,F(a,{index:!1})))})(s,null===(l=p.http)||void 0===l?void 0:l.static),function(e,r){var o=function(){var e=te((function*(e,r){return{}}));return function(r,o){return e.apply(this,arguments)}}(),t=function(){var e=te((function*(e,r,o){}));return function(r,o,t){return e.apply(this,arguments)}}(),n={lazy:(null==r?void 0:r.lazy)||1,slow:(null==r?void 0:r.slow)||2,onStart:(null==r?void 0:r.onStart)||o,onDone:(null==r?void 0:r.onDone)||t,geoip:(null==r?void 0:r.geoip)||{enabled:!1}};function i(){return(i=te((function*(e,r){var o,t,i,a,l,c,s=e.miolo.logger,p=e.headers["x-real-ip"]||"127.0.0.1",g=J.now();e.request.body=ee(ee({},e.request.fields),e.request.files),Ie.total+=1,Ie[p]=(Ie[p]||0)+1,e.requestId=Ie.total,e.request.ip=p;var y=!0===(null==n||null===(o=n.geoip)||void 0===o?void 0:o.enabled),b={};y&&(b=Me(p,n.geoip,s)),e.request.geoip=b;var x=e.request.url.indexOf("?")>=0?e.request.url.substr(0,e.request.url.indexOf("?")):e.request.url,S=y?!0===(null===(t=b)||void 0===t?void 0:t.local)?"":null!==(i=b)&&void 0!==i&&i.country?null!==(a=b)&&void 0!==a&&a.city?" (".concat(null===(l=b)||void 0===l?void 0:l.city,", ").concat(b.country,")"):" (".concat(b.country,")"):"":"",_="".concat(d(p)).concat(S," ").concat(f(e.request.method)," ").concat(f(x)," [").concat(h(Ie[p]),"/").concat(h(e.requestId),"]"),w=null!=e.request.body?JSON.stringify(e.request.body):"";s.info("".concat(_," - START")),s.debug("".concat(_," - Body: ").concat(w));var k=yield n.onStart(e,{started:g,description:"pending"});yield r();var O=null==e||null===(c=e.session)||void 0===c?void 0:c.user,E="";null!=O&&(null!=O&&O.id?E=" - uid ".concat(null==O?void 0:O.id):null!=O&&O.token&&(E=" - token ".concat(null==O?void 0:O.token)));var R,C=e.response.status,q=C;200==C?R=m:C>200&&C<=299?(R=v,e.response.redirected&&e.response.url&&(q+=" -> ".concat(e.response.url))):R=u;var P="[".concat(R(q),"]"),M=parseFloat((J.now()-g)/1e3).toFixed(2),I=M<n.lazy?m:M<n.slow?v:u,j=M<n.lazy?"Ok":M<n.slow?"lazy":"slow",L=null!=e.session?JSON.stringify(e.session):"";s.debug("".concat(_," - Session: ").concat(L));var F=null!=e.body?JSON.stringify(e.body):"";s.debug("".concat(_," - Response: ").concat(F)),yield n.onDone(e,k,{started:g,elapsed:M,description:j}),s.info("".concat(_," - DONE ").concat(P).concat(E," (").concat(I(j),": ").concat(I(M),")"))}))).apply(this,arguments)}e.use((function(e,r){return i.apply(this,arguments)}))}(s,null==p||null===(c=p.http)||void 0===c?void 0:c.request),function(e){function r(){return(r=te((function*(e){e.body=Fe}))).apply(this,arguments)}var o=new A;o.get("/robots.txt",(function(e){return r.apply(this,arguments)})),e.use(o.routes())}(s),p.use_catcher&&function(e,r){function o(){return o=te((function*(e){var{error:r,warning:o,path:t,agent:n}=e.request.body,i=e.miolo.logger;if(o){var a="".concat(v("[JS Warning]")," on ").concat(g(t),": ").concat(JSON.stringify(o.msg),"\n")+"".concat(v("[JS Warning]")," File => ").concat(o.file,"\n")+"".concat(v("[JS Warning]")," Line => ").concat(o.line,"\n")+"".concat(v("[JS Warning]")," Col => ").concat(o.col,"\n")+"".concat(v("[JS Warning]")," Error => ").concat(JSON.stringify(o.error),"\n")+"".concat(v("[JS Warning]")," Agent => ").concat(n);i.warn(a)}else{var l="".concat(u("[JS Error]")," on ").concat(g(t),": ").concat(JSON.stringify(r.msg),"\n")+"".concat(u("[JS Error]")," File => ").concat(r.file,"\n")+"".concat(u("[JS Error]")," Line => ").concat(r.line,"\n")+"".concat(u("[JS Error]")," Col => ").concat(r.col,"\n")+"".concat(u("[JS Error]")," Error => ").concat(JSON.stringify(r.error),"\n")+"".concat(u("[JS Error]")," Agent => ").concat(n);i.error(l)}e.body={result:1}})),o.apply(this,arguments)}var t=new A;t.post(r,(function(e){return o.apply(this,arguments)})),e.use(t.routes())}(s,p.http.catcher_url),"guest"==p.auth_type&&Te(s,p.auth.guest,null==p?void 0:p.session),"basic"==p.auth_type&&Je(s,p.auth.basic),"credentials"==p.auth_type&&Be(s,p.auth.credentials,null==p?void 0:p.session),"custom"==p.auth_type&&((e,r)=>{var o=e.context.miolo.logger;try{var t=r(e);if("function"==typeof t)e.use(t);else if(Array.isArray(t)){var n=new A;t.map((e=>{var r=e.method.toLowerCase();n[r](e.url,e.callback)})),e.use(n.routes())}}catch(i){o.error("Custom auth error: ".concat(i,"'"))}})(s,p.auth.custom);var y=null==p?void 0:p.middlewares;if(y&&((e,r)=>{null!=r&&0!=r.length&&r.map((r=>{e.use(r)}))})(s,y),null!=p&&p.routes){var b=s.context.miolo.db.getConnection();$e(s,b,p.routes)}null!=(null==i?void 0:i.middleware)?s.use(i.middleware):function(e,r,o,t){var n=(null==r?void 0:r.html)||or;n.indexOf("{context}")<0&&e.context.miolo.logger.error("Provided HTML for rendering has no {context} template variable"),n.indexOf("{children}")<0&&e.context.miolo.logger.error("Provided HTML for rendering has no {children} template variable");var i=function(){var e=te((function*(e){var o={};try{var t;null!=r&&null!==(t=r.ssr)&&void 0!==t&&t.loader&&(o=yield r.ssr.loader(e))}catch(c){var n,i="URL: ".concat(e.request.url,"\nFields: ").concat(JSON.stringify((null===(n=e.request)||void 0===n?void 0:n.fields)||{})),a=null!=c&&c.stack?"".concat(c.toString(),"\n").concat(c.stack):c.toString(),l="".concat("Error produced by loader in render.ssr middleware","\n").concat(i,"\n").concat(a);e.miolo.logger.error(l)}return o}));return function(r){return e.apply(this,arguments)}}(),a=(e,r,o)=>{var t,n,i=!0===(null==e||null===(t=e.session)||void 0===t?void 0:t.authenticated);return{config:r,user:null==e||null===(n=e.session)||void 0===n?void 0:n.user,authenticated:i,ssr_data:o,extra:null==e?void 0:e.extra}},l=(e,o)=>{var t="";try{var i;null!=r&&null!==(i=r.ssr)&&void 0!==i&&i.renderer?t=K(r.ssr.renderer(e,o)):e.miolo.logger.warn("Missing renderer in render.ssr middleware")}catch(a){e.miolo.logger.error("Error in renderer (render.ssr middleware):\n".concat(a.toString())),t="\n <div>\n MIOLO: Error SSR renderer: ".concat(a.toString(),"\n </div> \n ")}return n.replace("{context}",JSON.stringify(o,null,2)).replace("{children}",t)};function c(){return(c=te((function*(e){var r,n,c={hostname:null==o?void 0:o.hostname,port:null==o?void 0:o.port,catcher_url:null==o?void 0:o.catcher_url,login_url:null==t||null===(r=t.credentials)||void 0===r?void 0:r.url_login,logout_url:null==t||null===(n=t.credentials)||void 0===n?void 0:n.url_logout},u=yield i(e),s=a(e,c,u),d=l(e,s);e.miolo.logger.debug("[render-ssr] Returned body is ".concat(Buffer.byteLength(d,"utf8")," bytes")),e.body=d}))).apply(this,arguments)}e.use((function(e){return c.apply(this,arguments)}))}(s,i,p.http,null==p?void 0:p.auth);var x=function(){var r=te((function*(){var r=e.createServer(s.callback());yield((e,r,o)=>new Promise(((t,n)=>{e.listen(r,o,(e=>{e?n(e):t()}))})))(r,p.http.port,p.http.hostname),s.context.miolo.logger.info("[http] miolo is listening on ".concat(p.http.hostname,":").concat(p.http.port)),s.server=r;var t=o({server:r});return s.stop_server=te((function*(){yield t.terminate(),s.context.miolo.logger.info("[http] miolo has been shutdowned from ".concat(p.http.hostname,":").concat(p.http.port))})),ar(s,null==p?void 0:p.cron),s}));return function(){return r.apply(this,arguments)}}();return s.run=x,s}function cr(e){var r=Q.createClient(e.redis.port,e.redis.host).on("connect",(function(){console.info("".concat(d("REDIS")," Connection established!"))})).on("error",(function(e){var r;try{r=e instanceof Q.ReplyError?"".concat(d("REDIS")," ").concat(u("Error "+e.code)," Command: ").concat(e.command," ").concat(e.toString()):"".concat(d("REDIS")," ").concat(u("Error "+e.code)," ").concat(e.toString())}catch(o){r="".concat(d("REDIS")," ").concat(u("Error ")," ").concat(o)}console.error(r)})),o=S(r.get).bind(r),t=S(r.exists).bind(r),n=S(r.set).bind(r),i=S(r.del).bind(r);function a(){return(a=te((function*(e){return yield o(e)}))).apply(this,arguments)}function l(){return(l=te((function*(e){return 1==(yield t(e))}))).apply(this,arguments)}function c(){return c=te((function*(e,r){var o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:86400;return"OK"==(yield n(e,r,"EX",o))})),c.apply(this,arguments)}function s(){return(s=te((function*(e){return(yield i(e))>=1}))).apply(this,arguments)}var f={get:function(e){return a.apply(this,arguments)},exists:function(e){return l.apply(this,arguments)},set:function(e,r){return c.apply(this,arguments)},del:function(e){return s.apply(this,arguments)}};return f}export{lr as miolo,cr as miolo_cacher,ce as miolo_emailer,pe as miolo_logger};
|
|
11
|
+
import e from"node:http";import r from"koa";import{createHttpTerminator as o}from"http-terminator";import t from"deepmerge";import n from"node:path";import{fileURLToPath as i}from"node:url";import{getConnection as a}from"calustra";export{getConnection as miolo_db_connection}from"calustra";import l from"nodemailer";import{uncolor as c,red as u,gray as s,magenta as d,cyan as f,yellow as v,red_light as p,green as m,cyan_light as h,blue as g,green_bold as y,yellow_bold as b}from"tinguir";import x,{promisify as S}from"node:util";import _,{transports as w,createLogger as k,format as O}from"winston";import E,{readFileSync as R}from"node:fs";import C from"koa-better-body";import q from"koa-convert";import P from"koa-compress";import{constants as M}from"node:zlib";import I from"koa-ratelimit";import j from"node:https";import L from"koa-mount";import F from"koa-static";import T from"koa-favicon";import{performance as J}from"node:perf_hooks";import{Reader as U}from"@maxmind/geoip2-node";import A from"@koa/router";import N from"jwt-simple";import z from"koa-passport";import B from"passport-local";import D from"koa-session";import G from"koa-redis";import W from"@koa/cors";import H from"koa-proxies";import Y from"qs";import{renderToString as K}from"react-dom/server";import{CronJob as V}from"cron";import X from"node:os";import Z from"diskspace";import Q from"redis";function $(e,r){var o=Object.keys(e);if(Object.getOwnPropertySymbols){var t=Object.getOwnPropertySymbols(e);r&&(t=t.filter((function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable}))),o.push.apply(o,t)}return o}function ee(e){for(var r=1;r<arguments.length;r++){var o=null!=arguments[r]?arguments[r]:{};r%2?$(Object(o),!0).forEach((function(r){ne(e,r,o[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(o)):$(Object(o)).forEach((function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(o,r))}))}return e}function re(e){var r=function(e,r){if("object"!=typeof e||!e)return e;var o=e[Symbol.toPrimitive];if(void 0!==o){var t=o.call(e,r||"default");if("object"!=typeof t)return t;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(e)}(e,"string");return"symbol"==typeof r?r:String(r)}function oe(e,r,o,t,n,i,a){try{var l=e[i](a),c=l.value}catch(u){return void o(u)}l.done?r(c):Promise.resolve(c).then(t,n)}function te(e){return function(){var r=this,o=arguments;return new Promise((function(t,n){var i=e.apply(r,o);function a(e){oe(i,t,n,a,l,"next",e)}function l(e){oe(i,t,n,a,l,"throw",e)}a(void 0)}))}}function ne(e,r,o){return(r=re(r))in e?Object.defineProperty(e,r,{value:o,enumerable:!0,configurable:!0,writable:!0}):e[r]=o,e}var ie=i(import.meta.url),ae=n.dirname(ie),le={name:"miolo",http:{port:8001,hostname:"localhost",catcher_url:"/sys/jserror",static:{favicon:n.resolve(ae,"../static/img/miolo.ico"),folders:{}},cors:!1,proxy:!1,ratelimit:{max:1e3,duration:6e4,errorMessage:"Rate Limit reached",whitelist_ips:[],blacklist_ips:[],ipsum_folder:"/var/ipsum"},request:{lazy:1,slow:2,onStart:void 0,onDone:void 0,geoip:{enabled:!1,db:"/var/lib/GeoIP/GeoLite2-City.mmdb",local_ips:["127.0.0.1"]}}},session:{salt:"SUPER_SALTY_YES?",secret:"SUPER_SECRET_KEY_KERE",options:{maxAge:864e5,secure:!0,sameSite:null}},db:{config:{dialect:"postgres",host:"localhost",port:5432,database:"miolo",user:"postgres",password:"postgres",max:5,min:0,idleTimeoutMillis:1e4},options:{tables:[]}},routes:{bodyField:void 0,crud:[{prefix:"",routes:[]}],queries:[]},log:{level:"debug",format:{locale:"en-GB"},console:{enabled:!0,level:"silly"},file:{enabled:!0,level:"silly",filename:"/var/log/afialapis/%MIOLO%.log",zippedArchive:!0,maxsize:20971520,maxFiles:20},mail:{enabled:!1,level:"warn",name:"miolo",from:"miolo@mail.com",to:"errors@mail.com"}},mail:{silent:!0,options:{port:25,host:"mail.com",authMethod:"PLAIN",secure:!1,tls:{rejectUnauthorized:!1},logger:!1,debug:!1},defaults:{name:"miolo",from:"miolo@mail.com",to:"errors@mail.com"}},auth:{},render:{},middlewares:[],cron:[]};function ce(e){var{options:r,defaults:o,silent:t}=e,n=l.createTransport(r,o);function i(){return(i=te((function*(e){if(!0===t)return console.info("*********************************"),console.info("This mail will not be send (emailing is disabled):"),console.info(e),console.info("*********************************"),{ok:!0,silent:!0,error:void 0,messageId:void 0};try{var r=n.sendMail(e);return r.ok=!(null==r||!r.messageId),r}catch(o){return{error:o,ok:!1}}}))).apply(this,arguments)}var a={send:function(e){return i.apply(this,arguments)},verify:function(){console.info("[miolo][Verify][MAILER] Verifying..."),n.verify((function(e,r){e?(console.error("[miolo][Verify][MAILER] Verifying ERROR"),console.error(e)):console.info("[miolo][Verify][MAILER] Verifyed OK: Server is ready to take our messages")}))},options:r,defaults:o,silent:t};return a}var{combine:ue,timestamp:se,_label:de,printf:fe,errors:ve}=O,pe=function(e,r){var o,t,i,a,l=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"miolo",m={silly:s,debug:d,verbose:f,info:v,warn:p,error:u},h={silly:"sly",debug:"dbg",verbose:"vbs",info:"inf",warn:"wrn",error:"err"},g=[];!0===(null==e||null===(o=e.console)||void 0===o?void 0:o.enabled)&&g.push(new w.Console({humanReadableUnhandledException:!0,level:(null==e||null===(a=e.console)||void 0===a?void 0:a.level)||(null==e?void 0:e.level)||"silly",handleExceptions:!0}));if(!0===(null==e||null===(t=e.file)||void 0===t?void 0:t.enabled)){var y,b,S=new w.File({filename:null!=e&&null!==(y=e.file)&&void 0!==y&&y.filename?e.file.filename.replace("%MIOLO%",l):"/var/log/afialapis/miolo.log",level:(null==e||null===(b=e.file)||void 0===b?void 0:b.level)||(null==e?void 0:e.level)||"info",humanReadableUnhandledException:!0,handleExceptions:!0});!function(e){process.on("SIGHUP",(function(){var r=n.join(e.dirname,e._getFile(!1));return function(){console.log("[miolo][file-logger] SIGHUP received. Reopening ".concat(r,"..."));try{e._stream&&(e._stream.end(),e._stream.destroy());var o=E.createWriteStream(r,e.options);o.setMaxListeners(1/0),e._size=0,e._stream=o,e.opening=!1,e.emit("open",r),console.log("[miolo][file-logger] Reopened ".concat(r," successfully"))}catch(t){console.error("[miolo][file-logger] Error reopening ".concat(r,": ").concat(t.toString()))}}()}))}(S),g.push(S)}if(!0===(null==e||null===(i=e.mail)||void 0===i?void 0:i.enabled)){var O=function(e,r){var o=function(o){_.Transport.call(this,o),o=o||{},this.level=e.level||"info",this.ename=(null==e?void 0:e.name)||r.defaults.name,this.to=e.to||r.defaults.to,this.from=e.from||r.defaults.from,this.humanReadableUnhandledException=o.humanReadableUnhandledException||!0,this.handleExceptions=o.handleExceptions||!0,this.json=o.json||!1,this.colorize=o.colorize||!1};return x.inherits(o,_.Transport),o.prototype.name="MailerLogger",o.prototype.log=function(o,t){var n=this,i="",a="";try{try{i=o.message.split("\n")[0]}catch(s){i=o.message.toString()}i=c(i)}catch(d){i="Could not create a title for the error (".concat(d.toString(),")")}try{try{a=c(o.message)}catch(d){a=o.message.toString()}}catch(d){a="Could not create a body for the error (".concat(d.toString(),")")}var l="".concat(null==e?void 0:e.name," [").concat(o.level.toUpperCase(),"] ").concat(i),u={from:this.from,to:this.to,subject:l,text:a};r.send(u,(function(){n.emit("logged"),t(null,!0)}))},o}(e.mail,r);w.MailerLogger=O,g.push(new w.MailerLogger({humanReadableUnhandledException:!0,handleExceptions:!0}))}var R=k({level:(null==e?void 0:e.level)||"silly",format:ue(ve({stack:!0}),se(),fe((r=>{var o,t=m[r.level],n=new Date(r.timestamp).toLocaleString((null==e||null===(o=e.format)||void 0===o?void 0:o.locale)||"en"),i="[".concat(l,"] ").concat(t(n)," ").concat(t(h[r.level])," ").concat(r.message);return r.stack?"".concat(i,"\n").concat(r.stack):i}))),transports:g});try{R.info("[logger] Inited for ".concat(R.transports.map((e=>"".concat(e.name," (").concat(e.level,")").concat(e.silent?u(" SILENT!"):""))).join(", ")))}catch(C){}return R},me=(e,r)=>{var o=ce(r.mail),t=pe(r.log,o,null==r?void 0:r.name),n=ee(ee({},r.db.options),{},{log:t}),i={getConnection:()=>a(r.db.config,n),getModel:e=>a(r.db.config,n).getModel(e)},l={config:ee({},r),emailer:o,logger:t,db:i};function c(){return(c=te((function*(e,r){e.miolo=l,yield r()}))).apply(this,arguments)}e.use((function(e,r){return c.apply(this,arguments)})),e.context.miolo=l},he=[401,403];var ge="/var/ipsum",ye="ipsum.txt",be="https://raw.githubusercontent.com/stamparm/ipsum/master/ipsum.txt",xe=1;function Se(e,r){var o=r?r.error:console.error;if(!e)return[];try{var t=[];return e.split("\n").filter((e=>e.indexOf("#")<0)).map((e=>{var[r,o]=e.split("\t");parseInt(o)>=xe&&t.push(r)})),t}catch(n){return o("[cron][".concat(f("IPsum"),"] Error getting IPs from content")),[]}}function _e(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:ge,r=arguments.length>1?arguments[1]:void 0,o=arguments.length>2?arguments[2]:void 0,t=o?o.error:console.error,i=o?o.debug:console.log;if(E.existsSync(e))try{i("[cron][".concat(f("IPsum"),"] Updating file...")),function(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:be,o=arguments.length>2?arguments[2]:void 0,t=o?o.error:console.error;j.get(r,(r=>{var o=[];r.on("data",(e=>{o.push(e)})).on("end",(()=>{var r=Buffer.concat(o).toString();e(r)}))})).on("error",(r=>{t("[cron][".concat(f("IPsum"),"] Error downloading remote file (").concat(r.toString(),")")),e("")}))}((t=>{var a=n.join(e,ye);E.writeFileSync(a,t,{encoding:"utf8",flag:"w"});var l=t.split("\n").length,c=Se(t,o),u=c.length;i("[cron][".concat(f("IPsum"),"] File downloaded. ").concat(l," ips on the list (").concat(u," appearing in ").concat(xe," or more lists)")),r&&r(c)}))}catch(a){t("[cron][".concat(f("IPsum"),"] Error ").concat(a," updating the file"))}else t("[cron][".concat(f("IPsum"),"] Folder ").concat(e," does not exist"))}function we(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:ge,r=arguments.length>1?arguments[1]:void 0,o=arguments.length>2?arguments[2]:void 0,t=o?o.debug:console.log,i=o?o.warn:console.log,a=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:ge,r=arguments.length>1?arguments[1]:void 0,o=r?r.error:console.error;if(!E.existsSync(e))return r&&o("[cron][".concat(f("IPsum"),"] Folder ").concat(e," does not exist")),[];var t=n.join(e,ye);return E.existsSync(t)?Se(E.readFileSync(t,{encoding:"utf8"}),r):(r&&o("[cron][".concat(f("IPsum"),"] File ").concat(t," does not exist")),[])}(e,o);return a.length>0?(r&&r(a),t("[cron][".concat(f("IPsum"),"] File contains ").concat(a.length," ips")),a):(i("[cron][".concat(f("IPsum"),"] File is empty. Launching update...")),_e(e,r,o),[])}var ke=["52.212.247.108","54.218.32.58","170.106.82.193","110.166.71.39","205.210.31.240 ","134.122.52.203","165.232.105.25","66.249.73.200","35.206.153.204","199.244.88.227","198.12.222.107","212.128.118.10"];var Oe=i(import.meta.url),Ee=n.dirname(Oe),Re=n.resolve(Ee,"./miolo.ico"),Ce=n.resolve(Ee,"../../../.."),qe=void 0,Pe=["127.0.0.1"];var Me=function(e,r){var o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:console;if(Pe.indexOf(e)>=0)return{local:!0,country:"",city:""};try{var t,n=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"/var/lib/GeoIP/GeoLite2-City.mmdb",r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:["127.0.0.1"],o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:console;try{if(null!=qe)return qe;Pe=[...Pe,...r||[]];var t=E.readFileSync(e);return qe=U.openBuffer(t)}catch(n){return o.error("[geoip] Error initing:"),void o.error(n)}}(null==r?void 0:r.db,null==r?void 0:r.local_ipds,o),i=n.city(e);return{country:i.country.isoCode,city:null===(t=i.city)||void 0===t||null===(t=t.names)||void 0===t?void 0:t.en}}catch(a){o.error("[geoip] Error localizing IP ".concat(e,":")),o.error(a)}return{country:"",city:""}},Ie={total:0};var je=i(import.meta.url),Le=n.dirname(je),Fe=R(n.resolve(Le,"./robots.txt"),"utf8");var Te=(e,r,o)=>{var t=e.context.miolo.logger,n=()=>{try{var{make_guest_token:e}=r;if(null!=e)return e(o||{})}catch(n){}return function(e,r){var o=Math.random().toString(),t=null==e?void 0:e.secret;t||(t="miolo_unsafe_secret",r.error("Guest token made with an unsafe secret string. Please, configure your own through session.secret."));var n={admin:!1,buid:o};return N.encode(n,t)}(o||{},t)};function i(){return i=te((function*(e,r){var i=e.cookies.get("token")||e.headers.token;void 0!==i&&0!=i.length||(i=yield n(),t.debug("Guest token conceeded"));var a=function(e){var r,o=null==e||null===(r=e.options)||void 0===r?void 0:r.maxAge;isNaN(o)&&(o=86400);var t=new Date;return t.setSeconds(t.getSeconds()+o),{expires:t,httpOnly:!1}}(o);e.cookies.set("token",i,a),e.session={user:{name:"guest"},authenticated:!0,token:i},yield r()})),i.apply(this,arguments)}e.use((function(e,r){return i.apply(this,arguments)}))},Je=(e,r)=>{var{auth_user:o,realm:t,paths:n}=r;function i(e,r){return a.apply(this,arguments)}function a(){return(a=te((function*(r,n){var i;try{i=(e=>{var r,o=null==e||null===(r=e.headers)||void 0===r?void 0:r.authorization;if(o)try{o=o.replace("Basic ","");try{o=Buffer.from(o,"base64").toString()}catch(i){o=atob(o)}var[t,n]=o.split(":");return{username:t,password:n}}catch(i){return}})(r.request)}catch(c){}var a=()=>{r.session={user:void 0,authenticated:!1},r.body={user:void 0,authenticated:!1},r.response.status=401,r.response.headers["WWW-Authenticate"]='Basic realm="'+t.replace(/"/g,'\\"')+'"'};if(!i)return a();var l=yield o(i.username,i.password,e.context.miolo);if(!1===l||null==l)return a();r.session={user:l,authenticated:!0},yield n()}))).apply(this,arguments)}t||(t="Secure Area"),null==n||0==n.length?e.use(i):n.map((r=>e.use(L(r,i))))},Ue=new G;var Ae=(e,r,o)=>r(null,e.id),Ne=(e,r,o)=>{r(Error("You need to define auth.passport.find_user_by_id"),null)},ze=(e,r,o,t)=>{o(Error("You need to define auth.passport.local_auth_user"),null)},Be=(e,r,o)=>{var{get_user_id:t,find_user_by_id:n,local_auth_user:i,url_login:a,url_logout:l,url_login_redirect:c,url_logout_redirect:u}=r,s=t||Ae,d=n||Ne,f=i||ze,v=a||"/login",p=l||"/logout",m=new B.Strategy(((r,o,t)=>{f(r,o,t,e.context.miolo)}));function h(){return(h=te((function*(e,r){try{e.session.authenticated&&(e.session.user=e.state.user)}catch(o){}yield r()}))).apply(this,arguments)}!function(e,r){e.keys=[r.secret||"*secret*"];var o=ee({store:Ue},r.options||{});e.use(D(o,e))}(e,o),z.serializeUser(((r,o)=>{process.nextTick((function(){s(r,o,e.context.miolo)}))})),z.deserializeUser(((r,o)=>{process.nextTick((function(){d(r,o,e.context.miolo)}))})),z.use(m),e.use(z.initialize()),e.use(z.session()),e.use((function(e,r){return h.apply(this,arguments)}));var g=function(){var e=te((function*(e,r){e.session.authenticated?(e.session.user=void 0,e.session.authenticated=!1,yield e.logout(),e.body={user:void 0,authenticated:!1},null!=u&&e.redirect(u)):(e.body={user:void 0,authenticated:!1},e.response.status=401)}));return function(r,o){return e.apply(this,arguments)}}(),y=new A;y.post(v,((e,r)=>z.authenticate("local",function(){var r=te((function*(r,o,t,n){if(!1!==o)return e.session.user=e.state.user,e.session.authenticated=!0,e.body={user:o,authenticated:!0},null!=c&&e.redirect(c),yield e.login(o);e.session.user=void 0,e.session.authenticated=!1,e.body={user:void 0,authenticated:!1,info:t,error:r},e.response.status=401}));return function(e,o,t,n){return r.apply(this,arguments)}}())(e))),y.get(p,g),y.post(p,g),e.use(y.routes())},De=(e,r,o)=>{try{var t=e[r];if(null!=t&&0!=t)return o(t)}catch(n){}},Ge=(e,r)=>{var o=e.context.miolo.logger;De(r,"cors",(r=>{if("simple"==r)o.debug("Setting CORS the simple way"),e.use(function(){var e=te((function*(e,r){e.set("Access-Control-Allow-Origin","*"),e.set("Access-Control-Expose-Headers","SourceMap,X-SourceMap"),yield r()}));return function(r,o){return e.apply(this,arguments)}}());else{var t=(e=>"object"==typeof e?e:{})(r);o.debug("Setting CORS headers for ".concat(JSON.stringify(t))),e.use(W(t))}})),De(r,"proxy",(r=>{var[t,n]=(e=>{var r,o,t,n;return null==e&&(e={}),[(null===(r=e)||void 0===r?void 0:r.path)||"/",{target:(null===(o=e)||void 0===o?void 0:o.target)||"https://proxy.miolo.com",changeOrigin:null==(null===(t=e)||void 0===t?void 0:t.changeOrigin)||e.changeOrigin,logs:null==(null===(n=e)||void 0===n?void 0:n.logs)||e.logs}]})(r);o.debug("Setting Proxy for ".concat(t," to ").concat(n.target," ")),e.use(H(t,n))}))},We=function(){var e=te((function*(e){return!0}));return function(r){return e.apply(this,arguments)}}(),He=function(){var e=te((function*(e,r){return r}));return function(r,o){return e.apply(this,arguments)}}(),Ye={require:!1,action:"redirect",redirect_url:"/",error_code:401},Ke={use:!1,fieldNames:{created_by:"created_by",last_update_by:"last_update_by"}},Ve=e=>{var r=(null==e?void 0:e.crud)||[];if(!r)return[];if(!Array.isArray(r))return[];var o=[];return r.map((r=>{var n=null==r?void 0:r.routes;if(n&&Array.isArray(n)){var i=(null==r?void 0:r.bodyField)||(null==e?void 0:e.bodyField),a=(null==r?void 0:r.before)||(null==e?void 0:e.before)||We,l=(null==r?void 0:r.after)||(null==e?void 0:e.after)||He,c=t(Ye,(null==e?void 0:e.auth)||{},(null==r?void 0:r.auth)||{}),u=[];for(var s of n){var d="string"==typeof s?{name:s}:s;if(d.name){var f={name:d.name,url:(null==d?void 0:d.url)||d.name,mode:(null==d?void 0:d.mode)||"rw",bodyField:(null==d?void 0:d.bodyField)||i,useUserFields:t(Ke,(null==d?void 0:d.useUserFields)||{}),auth:t(c,(null==d?void 0:d.auth)||{}),before:(null==d?void 0:d.before)||a,after:(null==d?void 0:d.after)||l};u.push(f)}}u.length>0&&o.push({prefix:(null==r?void 0:r.prefix)||"",routes:u})}})),o};function Xe(e){var r=e.indexOf("?")>=0?e.substr(e.indexOf("?")+1):"";return r?Y.parse(r):{}}function Ze(e,r,o,t){o.map((o=>{var n=o.prefix;o.routes.map((o=>{var i=e.getModel(o.name);if(i){for(var a=function(){var e=te((function*(e,r){var n,i=!0===(null==e||null===(n=e.session)||void 0===n?void 0:n.authenticated),a=o.auth;return!(!0===a.require||"read-only"===a.require&&"w"===r)||(i||("error"==a.action?(t.error("[miolo-router] Unauthorized access. Throwing error ".concat(a.error_code)),e.throw(a.error_code,null,{})):"redirect"==a.action?(t.warn("[miolo-router] Unauthorized access. Redirecting to ".concat(a.redirect_url)),e.redirect(a.redirect_url)):(t.error("[miolo-router] Crud path ".concat(o.url," specified auth but no action")),e.body={})),i)}));return function(r,o){return e.apply(this,arguments)}}(),l=function(){var e=te((function*(e,r,n){var i,l={};try{var c;if(!(yield a(e,r)))return void(e.body={});var u=!0;if(null!=o&&o.before&&(u=yield o.before(e)),!u)return void(e.body={});var s=null==e||null===(c=e.session)||void 0===c||null===(c=c.user)||void 0===c?void 0:c.id,d={};!0===o.useUserFields.use&&(d=o.useUserFields.fieldNames);var f={uid:s,fieldNames:d};l=yield n(f),null!=o&&o.after&&(l=yield o.after(e,l))}catch(v){t.error("[miolo-router] Unexpected error on CRUD ".concat(o.name,"-").concat(r)),t.error(v)}i=l,l=null==o.bodyField?i:{[o.bodyField]:i},e.body=l}));return function(r,o,t){return e.apply(this,arguments)}}(),c=function(){var e=te((function*(e){yield l(e,"r",function(){var r=te((function*(r){var o=Xe(e.request.url),t={transaction:void 0};return yield i.read(o,t)}));return function(e){return r.apply(this,arguments)}}())}));return function(r){return e.apply(this,arguments)}}(),u=function(){var e=te((function*(e){yield l(e,"r",function(){var r=te((function*(r){var o=Xe(e.request.url),t={transaction:void 0};return yield i.keyList(o,t)}));return function(e){return r.apply(this,arguments)}}())}));return function(r){return e.apply(this,arguments)}}(),s=function(){var e=te((function*(e){yield l(e,"r",function(){var r=te((function*(r){var o=Xe(e.request.url),t={transaction:void 0};return yield i.find(o.id,t)}));return function(e){return r.apply(this,arguments)}}())}));return function(r){return e.apply(this,arguments)}}(),d=function(){var e=te((function*(e){yield l(e,"r",function(){var r=te((function*(r){var o=Xe(e.request.url),t={transaction:void 0};return yield i.distinct(o.distinct_field,o,t)}));return function(e){return r.apply(this,arguments)}}())}));return function(r){return e.apply(this,arguments)}}(),f=function(){var e=te((function*(e){yield l(e,"w",function(){var r=te((function*(r){var o,t=e.request.fields;null!=r&&null!==(o=r.fieldNames)&&void 0!==o&&o.created_by&&(t[r.fieldNames.created_by]=r.uid);var n={transaction:void 0};return yield i.insert(t,n)}));return function(e){return r.apply(this,arguments)}}())}));return function(r){return e.apply(this,arguments)}}(),v=function(){var e=te((function*(e){yield l(e,"w",function(){var r=te((function*(r){var o,t=e.request.fields;null!=r&&null!==(o=r.fieldNames)&&void 0!==o&&o.last_update_by&&(t[r.fieldNames.last_update_by]=r.uid);var n={transaction:void 0};return yield i.update(t,{id:t.id},n)}));return function(e){return r.apply(this,arguments)}}())}));return function(r){return e.apply(this,arguments)}}(),p=function(){var e=te((function*(e){yield l(e,"w",function(){var r=te((function*(r){var o=e.request.fields,t={transaction:void 0};return yield i.delete({id:o.id},t)}));return function(e){return r.apply(this,arguments)}}())}));return function(r){return e.apply(this,arguments)}}(),m=n?"/".concat(n,"/").concat(o.url):"/".concat(o.url);m.indexOf("//")>=0;)m=m.replace(/\/\//g,"/");t.info("[miolo-router] Routing table ".concat(o.name," to ").concat(m));var h=o.mode.indexOf("r")>=0,g=o.mode.indexOf("w")>=0,y=o.mode.indexOf("u")>=0||g;h&&(r.get("".concat(m,"/find"),(e=>s(e))),r.get("".concat(m,"/read"),(e=>c(e))),r.get("".concat(m,"/distinct"),(e=>d(e))),r.get("".concat(m,"/key_list"),(e=>u(e)))),y&&(r.post("".concat(m,"/save"),(e=>f(e))),r.post("".concat(m,"/update"),(e=>v(e)))),g&&r.post("".concat(m,"/delete"),(e=>p(e)))}else t.error("[miolo-router] Could not get model for ".concat(o.name))}))}))}var Qe=e=>{var r=(null==e?void 0:e.queries)||[];if(!r)return[];if(!Array.isArray(r))return[];var o=[];return r.map((r=>{var n=null==r?void 0:r.routes;if(n&&Array.isArray(n)){var i=(null==r?void 0:r.before)||(null==e?void 0:e.before)||We,a=(null==r?void 0:r.after)||(null==e?void 0:e.after)||He,l=t(Ye,(null==r?void 0:r.auth)||{},(null==e?void 0:e.auth)||{}),c=[];for(var u of n)if(u.url&&u.callback){var s={url:u.url,method:(null==u?void 0:u.method)||"GET",callback:u.callback,auth:t(l,(null==u?void 0:u.auth)||{}),before:(null==u?void 0:u.before)||i,after:(null==u?void 0:u.after)||a};c.push(s)}o.push({prefix:(null==r?void 0:r.prefix)||"",routes:c})}})),o};function $e(e,r,o){var t=e.context.miolo.logger,n=new A;try{var i=Ve(o),a=Qe(o),l=i.length>0,c=a.length>0;if(!l&&!c)throw"[miolo-router] Could not get any route from the passed <routes> param";l&&Ze(r,n,i,t),c&&function(e,r,o){r.map((r=>{var t=r.prefix;r.routes.map((r=>{for(var n,i=t?"/".concat(t,"/").concat(r.url):"/".concat(r.url);i.indexOf("//")>=0;)i=i.replace(/\/\//g,"/");o.info("[miolo-router] Routing ".concat((null===(n=r.callback)||void 0===n?void 0:n.name)||"callback"," to ").concat(r.method," ").concat(i));var a=function(){var e=te((function*(e){var t,n=!0===(null==e||null===(t=e.session)||void 0===t?void 0:t.authenticated),i=r.auth;return!(!0===i.require||"read-only"===i.require&&"POST"===r.method)||(n||("error"==i.action?(o.error("Unauthorized access. Throwing error ".concat(i.error_code)),e.throw(i.error_code,null,{})):"redirect"==i.action?(o.warn("Unauthorized access. Redirecting to ".concat(i.redirect_url)),e.redirect(i.redirect_url)):(o.error("Route path ".concat(r.url," specified auth but no action")),e.body={})),n)}));return function(r){return e.apply(this,arguments)}}(),l=function(){var e=te((function*(e){var t={};try{try{var n;if("GET"==r.method&&(null===(n=e.request)||void 0===n||!n.fields)&&e.request.url.indexOf("?")>0){var i=Xe(e.request.url);i&&(e.request.fields=i)}}catch(c){o.error("[miolo-router] Error while trying to qet query params for ".concat(e.request.url))}if(!(yield a(e)))return;var l=!0;if(null!=r&&r.before&&(l=yield r.before(e)),!l)return;t=yield r.callback(e),null!=r&&r.after&&(t=yield r.after(e,t))}catch(u){o.error("[miolo-router] Unexpected error on Query ".concat(r.name)),o.error(u)}return t}));return function(r){return e.apply(this,arguments)}}(),c=r.method.toLowerCase();e[c](i,(e=>l(e,r)))}))}))}(n,a,t)}catch(u){t.error(u),t.error("[miolo-router] Error initing the router. Probably config objects are not ok"),t.error("[miolo-router] connOrConfig:"),t.error(null==r?void 0:r.config),t.error("[miolo-router] routes:"),t.error(o)}e.use(n.routes())}var er=i(import.meta.url),rr=n.dirname(er),or=R(n.resolve(rr,"fallback_index.html"),"utf8");function tr(e){return e?e/1e6:0}function nr(e){return e?e/1e6:0}function ir(){return{name:"SysCheck",cronTime:"0,15,30,45 * * * *",onTick:(e,r)=>{var o,t,n,i;o=e.logger,t=Math.round(tr(X.freemem()),2),n=Math.round(tr(X.totalmem()),2),(i=Math.round(100*t/n,2))>80?o.error("[cron][".concat(f("SysCheck"),"] RAM ").concat(v(t)," MB used of ").concat(m(n)," MB (").concat(v(i)," %)")):o.info("[cron][".concat(f("SysCheck"),"] RAM ").concat(v(t)," MB used of ").concat(m(n)," MB (").concat(v(i)," %)")),Z.check("/",(function(e,r){var t=Math.round(nr(r.used),2),n=Math.round(nr(r.total),2),i=Math.round(nr(r.free),2);i<1?o.error("[cron][".concat(f("SysCheck"),"] DISK ").concat(v(t)," GB used of ").concat(m(n)," GB (").concat(v(i)," GB free)")):o.info("[cron][".concat(f("SysCheck"),"] DISK ").concat(v(t)," GB used of ").concat(m(n)," GB (").concat(v(i)," GB free)"))}))},start:!0}}function ar(e,r){var o=e.context.miolo,t=o.logger,n=[ir(),{name:"IPsum",cronTime:"0 0 * * *",onTick:(e,r)=>{_e(e.config.http.ratelimit.ipsum_folder||ge,(r=>{e.logger.info("[cron][".concat(f("IPsum"),"] File downloaded. ").concat(m(r.length)," ips will be ").concat(v("blacklisted"),"!"))}),e.logger)},start:!0},...r||[]],i=[];n.map((e=>{var r=e.name,t=function(e,r){var o,t=e.logger,n=null!=r&&null!==(o=r.onTick)&&void 0!==o&&o.name&&"onTick"!=r.onTick.name?r.onTick.name:"custom",i=(null==r?void 0:r.name)||n;return new V((null==r?void 0:r.cronTime)||"*/5 * * * *",(o=>{try{t.silly("[cron][Custom Job ".concat(f(i),"] ").concat(y("ticks!"))),r.onTick(e,o)}catch(n){t.error("[cron][Custom Job ".concat(f(i),"] Error at onTick()")),t.error(n)}}),(()=>{if(t.silly("[cron][Custom Job ".concat(f(i),"] ").concat(y("completed!"))),null!=r&&r.onComplete)try{r.onComplete(e)}catch(o){t.error("[cron][Custom Job ".concat(f(i),"] Error at onComplete()")),t.error(o)}}),!0===(null==r?void 0:r.start),(null==r?void 0:r.timezone)||"Europe/Madrid")}(o,e);i.push({name:r,job:t,running:!0===(null==e?void 0:e.start)})}));var a=e=>{var r;return(r="number"==typeof e?i[e]:i.filter((r=>r.name==e))[0])||t.error("[cron] Cannot stop job ".concat(f(e),": Not Found")),r},l=e=>{try{e.job.stop(),e.running=!1,t.debug("[cron][Job ".concat(f(e.name),"] ").concat(b("manually stopped!")))}catch(r){t.error("[cron][Job ".concat(f(e.name),"] Error manually stopping it")),t.error(r)}};e.cron={jobs:i,start:e=>{var r=a(e);r&&(e=>{try{e.job.stop(),e.running=!0,t.debug("[cron][Job ".concat(f(e.name),"] ").concat(y("manually started!")))}catch(r){t.error("[cron][Job ".concat(f(e.name),"] Error manually starting it")),t.error(r)}})(r)},stop:e=>{var r=a(e);r&&l(r)},stop_all:()=>{i.map((e=>{l(e)}))}}}function lr(n,i){var a,l,c,s=new r,p=function(e){var r,o=t(le,e);return o.auth_type=function(e){var r,o,t;return null!=e&&null!==(r=e.auth)&&void 0!==r&&r.basic?"basic":null!=e&&null!==(o=e.auth)&&void 0!==o&&o.credentials?"credentials":null!=e&&null!==(t=e.auth)&&void 0!==t&&t.custom?"custom":"guest"}(e),o.use_catcher=!(null==o||null===(r=o.http)||void 0===r||!r.catcher_url),o}(n);me(s,p),Ge(s,p.http),(e=>{e.use(P({filter:function(e){return"application/json"==e||"text/html"==e},gzip:{flush:M.Z_SYNC_FLUSH},deflate:{flush:M.Z_SYNC_FLUSH},br:!1})),e.use(q(C({formLimit:"100mb",jsonLimit:"100mb",bufferLimit:"100mb"})))})(s),function(e){var r=e.context.miolo.logger;function o(){return(o=te((function*(e){if(e){var o=e.status||400;if(this.accepts(["text","json","html"])?"number"!=typeof o&&(o=500):(o=406,e.message="Unsupported type"),he.indexOf(o)>=0?r.warn("".concat(this.method," ").concat(this.url," - ").concat(o,": ").concat(e.message)):r.error(e),this.headerSent||!this.writable)return r.debug("headers were already sent, returning early"),void(e.headerSent=!0);this.type="json",this.status=o,this.body=JSON.stringify(this.body||"",null,2),this.length=Buffer.byteLength(this.body),this.res.end(this.body)}}))).apply(this,arguments)}e.context.onerror=function(e){return o.apply(this,arguments)}}(s),function(e,r){var o=e.context.miolo,t=e=>e.headers["x-real-ip"]||e.ip||"127.0.0.1",n=we(null==r?void 0:r.ipsum_folder,void 0,o.logger),i={driver:"memory",db:new Map,id:t,headers:{remaining:"Rate-Limit-Remaining",reset:"Rate-Limit-Reset",total:"Rate-Limit-Total"},disableHeader:!1,max:(null==r?void 0:r.max)||1e3,duration:(null==r?void 0:r.duration)||6e4,errorMessage:(null==r?void 0:r.errorMessage)||"Rate Limit reached",whitelist:(null==r?void 0:r.whitelist)||(e=>{var o=(null==r?void 0:r.whitelist_ips)||[];return!!o&&o.indexOf(t(e))>=0}),blacklist:(null==r?void 0:r.blacklist)||(e=>{var o=t(e),i=[...n,...ke,...(null==r?void 0:r.blacklist_ips)||[]].indexOf(o)>=0;return i&&e.miolo.logger.info("Rejecting ".concat(v("blacklisted")," ").concat(d(o))),i})};e.use(I(i))}(s,null===(a=p.http)||void 0===a?void 0:a.ratelimit),((e,r)=>{var{favicon:o,folders:t}=r,n=o||Re;for(var[i,a]of(e.context.miolo.logger.debug("[static] Serving favicon from ".concat(n.replace(Ce,""))),e.use(T(n)),Object.entries(t)))e.context.miolo.logger.debug("[static] Mounting static folder ".concat(i," => ").concat(a.replace(Ce,""))),e.use(L(i,F(a,{index:!1})))})(s,null===(l=p.http)||void 0===l?void 0:l.static),function(e,r){var o=function(){var e=te((function*(e,r){return{}}));return function(r,o){return e.apply(this,arguments)}}(),t=function(){var e=te((function*(e,r,o){}));return function(r,o,t){return e.apply(this,arguments)}}(),n={lazy:(null==r?void 0:r.lazy)||1,slow:(null==r?void 0:r.slow)||2,onStart:(null==r?void 0:r.onStart)||o,onDone:(null==r?void 0:r.onDone)||t,geoip:(null==r?void 0:r.geoip)||{enabled:!1}};function i(){return(i=te((function*(e,r){var o,t,i,a,l,c,s=e.miolo.logger,p=e.headers["x-real-ip"]||"127.0.0.1",g=J.now();e.request.body=ee(ee({},e.request.fields),e.request.files),Ie.total+=1,Ie[p]=(Ie[p]||0)+1,e.requestId=Ie.total,e.request.ip=p;var y=!0===(null==n||null===(o=n.geoip)||void 0===o?void 0:o.enabled),b={};y&&(b=Me(p,n.geoip,s)),e.request.geoip=b;var x=e.request.url.indexOf("?")>=0?e.request.url.substr(0,e.request.url.indexOf("?")):e.request.url,S=y?!0===(null===(t=b)||void 0===t?void 0:t.local)?"":null!==(i=b)&&void 0!==i&&i.country?null!==(a=b)&&void 0!==a&&a.city?" (".concat(null===(l=b)||void 0===l?void 0:l.city,", ").concat(b.country,")"):" (".concat(b.country,")"):"":"",_="".concat(d(p)).concat(S," ").concat(f(e.request.method)," ").concat(f(x)," [").concat(h(Ie[p]),"/").concat(h(e.requestId),"]"),w=null!=e.request.body?JSON.stringify(e.request.body):"";s.info("".concat(_," - START")),s.debug("".concat(_," - Body: ").concat(w));var k=yield n.onStart(e,{started:g,description:"pending"});yield r();var O=null==e||null===(c=e.session)||void 0===c?void 0:c.user,E="";null!=O&&(null!=O&&O.id?E=" - uid ".concat(null==O?void 0:O.id):null!=O&&O.token&&(E=" - token ".concat(null==O?void 0:O.token)));var R,C=e.response.status,q=C;200==C?R=m:C>200&&C<=299?(R=v,e.response.redirected&&e.response.url&&(q+=" -> ".concat(e.response.url))):R=u;var P="[".concat(R(q),"]"),M=parseFloat((J.now()-g)/1e3).toFixed(2),I=M<n.lazy?m:M<n.slow?v:u,j=M<n.lazy?"Ok":M<n.slow?"lazy":"slow",L=null!=e.session?JSON.stringify(e.session):"";s.debug("".concat(_," - Session: ").concat(L));var F=null!=e.body?JSON.stringify(e.body):"";s.debug("".concat(_," - Response: ").concat(F)),yield n.onDone(e,k,{started:g,elapsed:M,description:j}),s.info("".concat(_," - DONE ").concat(P).concat(E," (").concat(I(j),": ").concat(I(M),")"))}))).apply(this,arguments)}e.use((function(e,r){return i.apply(this,arguments)}))}(s,null==p||null===(c=p.http)||void 0===c?void 0:c.request),function(e){function r(){return(r=te((function*(e){e.body=Fe}))).apply(this,arguments)}var o=new A;o.get("/robots.txt",(function(e){return r.apply(this,arguments)})),e.use(o.routes())}(s),p.use_catcher&&function(e,r){function o(){return o=te((function*(e){var{error:r,warning:o,path:t,agent:n}=e.request.body,i=e.miolo.logger;if(o){var a="".concat(v("[JS Warning]")," on ").concat(g(t),": ").concat(JSON.stringify(o.msg),"\n")+"".concat(v("[JS Warning]")," File => ").concat(o.file,"\n")+"".concat(v("[JS Warning]")," Line => ").concat(o.line,"\n")+"".concat(v("[JS Warning]")," Col => ").concat(o.col,"\n")+"".concat(v("[JS Warning]")," Error => ").concat(JSON.stringify(o.error),"\n")+"".concat(v("[JS Warning]")," Agent => ").concat(n);i.warn(a)}else{var l="".concat(u("[JS Error]")," on ").concat(g(t),": ").concat(JSON.stringify(r.msg),"\n")+"".concat(u("[JS Error]")," File => ").concat(r.file,"\n")+"".concat(u("[JS Error]")," Line => ").concat(r.line,"\n")+"".concat(u("[JS Error]")," Col => ").concat(r.col,"\n")+"".concat(u("[JS Error]")," Error => ").concat(JSON.stringify(r.error),"\n")+"".concat(u("[JS Error]")," Agent => ").concat(n);i.error(l)}e.body={result:1}})),o.apply(this,arguments)}var t=new A;t.post(r,(function(e){return o.apply(this,arguments)})),e.use(t.routes())}(s,p.http.catcher_url),"guest"==p.auth_type&&Te(s,p.auth.guest,null==p?void 0:p.session),"basic"==p.auth_type&&Je(s,p.auth.basic),"credentials"==p.auth_type&&Be(s,p.auth.credentials,null==p?void 0:p.session),"custom"==p.auth_type&&((e,r)=>{var o=e.context.miolo.logger;try{var t=r(e);if("function"==typeof t)e.use(t);else if(Array.isArray(t)){var n=new A;t.map((e=>{var r=e.method.toLowerCase();n[r](e.url,e.callback)})),e.use(n.routes())}}catch(i){o.error("Custom auth error: ".concat(i,"'"))}})(s,p.auth.custom);var y=null==p?void 0:p.middlewares;if(y&&((e,r)=>{null!=r&&0!=r.length&&r.map((r=>{e.use(r)}))})(s,y),null!=p&&p.routes){var b=s.context.miolo.db.getConnection();$e(s,b,p.routes)}null!=(null==i?void 0:i.middleware)?s.use(i.middleware):function(e,r,o,t){var n=(null==r?void 0:r.html)||or;n.indexOf("{context}")<0&&e.context.miolo.logger.error("Provided HTML for rendering has no {context} template variable"),n.indexOf("{children}")<0&&e.context.miolo.logger.error("Provided HTML for rendering has no {children} template variable");var i=function(){var e=te((function*(e){var o={};try{var t;null!=r&&null!==(t=r.ssr)&&void 0!==t&&t.loader&&(o=yield r.ssr.loader(e))}catch(c){var n,i="URL: ".concat(e.request.url,"\nFields: ").concat(JSON.stringify((null===(n=e.request)||void 0===n?void 0:n.fields)||{})),a=null!=c&&c.stack?"".concat(c.toString(),"\n").concat(c.stack):c.toString(),l="".concat("Error produced by loader in render.ssr middleware","\n").concat(i,"\n").concat(a);e.miolo.logger.error(l)}return o}));return function(r){return e.apply(this,arguments)}}(),a=(e,r,o)=>{var t,n,i=!0===(null==e||null===(t=e.session)||void 0===t?void 0:t.authenticated);return{config:r,user:null==e||null===(n=e.session)||void 0===n?void 0:n.user,authenticated:i,ssr_data:o,extra:null==e?void 0:e.extra}},l=(e,o)=>{var t="";try{var i;null!=r&&null!==(i=r.ssr)&&void 0!==i&&i.renderer?t=K(r.ssr.renderer(e,o)):e.miolo.logger.warn("Missing renderer in render.ssr middleware")}catch(a){e.miolo.logger.error("Error in renderer (render.ssr middleware):\n".concat(a.toString())),t="\n <div>\n MIOLO: Error SSR renderer: ".concat(a.toString(),"\n </div> \n ")}return n.replace("{context}",JSON.stringify(o,null,2)).replace("{children}",t)};function c(){return(c=te((function*(e){var r,n,c={hostname:null==o?void 0:o.hostname,port:null==o?void 0:o.port,catcher_url:null==o?void 0:o.catcher_url,login_url:null==t||null===(r=t.credentials)||void 0===r?void 0:r.url_login,logout_url:null==t||null===(n=t.credentials)||void 0===n?void 0:n.url_logout},u=yield i(e),s=a(e,c,u),d=l(e,s);e.miolo.logger.debug("[render-ssr] Returned body is ".concat(Buffer.byteLength(d,"utf8")," bytes")),e.body=d}))).apply(this,arguments)}e.use((function(e){return c.apply(this,arguments)}))}(s,i,p.http,null==p?void 0:p.auth);var x=function(){var r=te((function*(){var r=e.createServer(s.callback());yield((e,r,o)=>new Promise(((t,n)=>{e.listen(r,o,(e=>{e?n(e):t()}))})))(r,p.http.port,p.http.hostname),s.context.miolo.logger.info("[http] miolo is listening on ".concat(p.http.hostname,":").concat(p.http.port)),s.server=r;var t=o({server:r});return s.stop_server=te((function*(){yield t.terminate(),s.context.miolo.logger.info("[http] miolo has been shutdowned from ".concat(p.http.hostname,":").concat(p.http.port))})),ar(s,null==p?void 0:p.cron),s}));return function(){return r.apply(this,arguments)}}();return s.run=x,s}function cr(e){var r=Q.createClient(e.redis.port,e.redis.host).on("connect",(function(){console.info("".concat(d("REDIS")," Connection established!"))})).on("error",(function(e){var r;try{r=e instanceof Q.ReplyError?"".concat(d("REDIS")," ").concat(u("Error "+e.code)," Command: ").concat(e.command," ").concat(e.toString()):"".concat(d("REDIS")," ").concat(u("Error "+e.code)," ").concat(e.toString())}catch(o){r="".concat(d("REDIS")," ").concat(u("Error ")," ").concat(o)}console.error(r)})),o=S(r.get).bind(r),t=S(r.exists).bind(r),n=S(r.set).bind(r),i=S(r.del).bind(r);function a(){return(a=te((function*(e){return yield o(e)}))).apply(this,arguments)}function l(){return(l=te((function*(e){return 1==(yield t(e))}))).apply(this,arguments)}function c(){return c=te((function*(e,r){var o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:86400;return"OK"==(yield n(e,r,"EX",o))})),c.apply(this,arguments)}function s(){return(s=te((function*(e){return(yield i(e))>=1}))).apply(this,arguments)}var f={get:function(e){return a.apply(this,arguments)},exists:function(e){return l.apply(this,arguments)},set:function(e,r){return c.apply(this,arguments)},del:function(e){return s.apply(this,arguments)}};return f}export{lr as miolo,cr as miolo_cacher,ce as miolo_emailer,pe as miolo_logger};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* miolo v0.9.
|
|
2
|
+
* miolo v0.9.34
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) Donato Lorenzo <donato@afialapis.com>
|
|
5
5
|
*
|
|
@@ -621,17 +621,20 @@ function reopenTransportOnHupSignal(fileTransport) {
|
|
|
621
621
|
try {
|
|
622
622
|
if (fileTransport._stream) {
|
|
623
623
|
fileTransport._stream.end();
|
|
624
|
-
fileTransport._stream.
|
|
624
|
+
fileTransport._stream.destroy(); // Soon()
|
|
625
625
|
}
|
|
626
626
|
var stream = fs.createWriteStream(fullname, fileTransport.options);
|
|
627
627
|
stream.setMaxListeners(Infinity);
|
|
628
628
|
fileTransport._size = 0;
|
|
629
629
|
fileTransport._stream = stream;
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
630
|
+
|
|
631
|
+
//fileTransport.once('flush', function () {
|
|
632
|
+
fileTransport.opening = false;
|
|
633
|
+
fileTransport.emit('open', fullname);
|
|
634
|
+
//})
|
|
635
|
+
|
|
636
|
+
//fileTransport.flush()
|
|
637
|
+
|
|
635
638
|
console.log("[miolo][file-logger] Reopened ".concat(fullname, " successfully"));
|
|
636
639
|
} catch (error) {
|
|
637
640
|
console.error("[miolo][file-logger] Error reopening ".concat(fullname, ": ").concat(error.toString()));
|