miolo 1.0.0 → 1.0.1

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/README.md CHANGED
@@ -6,18 +6,18 @@
6
6
 
7
7
  ---
8
8
 
9
- > **miolo**. substantivo masculino plural:
9
+ > **[miolo](https://academia.gal/dicionario/-/termo/miolo)**. substantivo masculino plural:
10
10
 
11
11
  > **1.** popular **Encéfalo.**
12
12
 
13
13
  > _Disque aínda se vían os miolos esparexidos polo chan._
14
14
 
15
+ > substantivo masculino:
15
16
 
16
17
  > **2. Parte interior do pan.**
17
18
 
18
19
  > _Prefiro o miolo á codia._
19
20
 
20
-
21
21
  > **4.** figurado **Parte fundamental ou máis importante de algo.**
22
22
 
23
23
  > _O miolo da cuestión non é ese._
@@ -1,5 +1,5 @@
1
1
  /**
2
- * miolo v1.0.0
2
+ * miolo v1.0.1
3
3
  *
4
4
  * https://www.afialapis.com/os/miolo
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * miolo v1.0.0
2
+ * miolo v1.0.1
3
3
  *
4
4
  * https://www.afialapis.com/os/miolo
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * miolo v1.0.0
2
+ * miolo v1.0.1
3
3
  *
4
4
  * https://www.afialapis.com/os/miolo
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * miolo v1.0.0
2
+ * miolo v1.0.1
3
3
  *
4
4
  * https://www.afialapis.com/os/miolo
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * miolo v1.0.0
2
+ * miolo v1.0.1
3
3
  *
4
4
  * https://www.afialapis.com/os/miolo
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * miolo v1.0.0
2
+ * miolo v1.0.1
3
3
  *
4
4
  * https://www.afialapis.com/os/miolo
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * miolo v1.0.0
2
+ * miolo v1.0.1
3
3
  *
4
4
  * https://www.afialapis.com/os/miolo
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * miolo v1.0.0
2
+ * miolo v1.0.1
3
3
  *
4
4
  * https://www.afialapis.com/os/miolo
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * miolo v1.0.0
2
+ * miolo v1.0.1
3
3
  *
4
4
  * https://www.afialapis.com/os/miolo
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * miolo v1.0.0
2
+ * miolo v1.0.1
3
3
  *
4
4
  * https://www.afialapis.com/os/miolo
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * miolo v1.0.0
2
+ * miolo v1.0.1
3
3
  *
4
4
  * https://www.afialapis.com/os/miolo
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * miolo v1.0.0
2
+ * miolo v1.0.1
3
3
  *
4
4
  * https://www.afialapis.com/os/miolo
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * miolo v1.0.0
2
+ * miolo v1.0.1
3
3
  *
4
4
  * https://www.afialapis.com/os/miolo
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * miolo v1.0.0
2
+ * miolo v1.0.1
3
3
  *
4
4
  * https://www.afialapis.com/os/miolo
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * miolo v1.0.0
2
+ * miolo v1.0.1
3
3
  *
4
4
  * https://www.afialapis.com/os/miolo
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * miolo v1.0.0
2
+ * miolo v1.0.1
3
3
  *
4
4
  * https://www.afialapis.com/os/miolo
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * miolo v1.0.0
2
+ * miolo v1.0.1
3
3
  *
4
4
  * https://www.afialapis.com/os/miolo
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * miolo v1.0.0
2
+ * miolo v1.0.1
3
3
  *
4
4
  * https://www.afialapis.com/os/miolo
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * miolo v1.0.0
2
+ * miolo v1.0.1
3
3
  *
4
4
  * https://www.afialapis.com/os/miolo
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * miolo v1.0.0
2
+ * miolo v1.0.1
3
3
  *
4
4
  * https://www.afialapis.com/os/miolo
5
5
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * miolo v1.0.0
2
+ * miolo v1.0.1
3
3
  *
4
4
  * https://www.afialapis.com/os/miolo
5
5
  *
@@ -2366,18 +2366,20 @@ function init_request_middleware(app, config) {
2366
2366
  tcolor = elapsed < reqConfig.lazy ? tinguir.green : elapsed < reqConfig.slow ? tinguir.yellow : tinguir.red;
2367
2367
  tname = elapsed < reqConfig.lazy ? 'Ok' : elapsed < reqConfig.slow ? 'lazy' : 'slow';
2368
2368
  ssession = ctx.session != undefined ? JSON.stringify(ctx.session) : '';
2369
- logger.debug(sreq + " - Session: " + ssession);
2369
+ logger.debug(sreq + " - Session: " + ssession.slice(0, 150) + "...");
2370
+ logger.silly(sreq + " - Session: " + ssession);
2370
2371
  rbody = ctx.body != undefined ? JSON.stringify(ctx.body) : '';
2371
- logger.debug(sreq + " - Response: " + rbody);
2372
- _context3.next = 39;
2372
+ logger.debug(sreq + " - Response: " + rbody.slice(0, 150) + "...");
2373
+ logger.silly(sreq + " - Response: " + rbody);
2374
+ _context3.next = 41;
2373
2375
  return reqConfig.onDone(ctx, begin_result, {
2374
2376
  started: started,
2375
2377
  elapsed: elapsed,
2376
2378
  description: tname
2377
2379
  });
2378
- case 39:
2380
+ case 41:
2379
2381
  logger.info(sreq + " - DONE " + stdesc + uid_desc + " (" + tcolor(tname) + ": " + tcolor(elapsed) + ")");
2380
- case 40:
2382
+ case 42:
2381
2383
  case "end":
2382
2384
  return _context3.stop();
2383
2385
  }
@@ -1,5 +1,5 @@
1
1
  /**
2
- * miolo v1.0.0
2
+ * miolo v1.0.1
3
3
  *
4
4
  * https://www.afialapis.com/os/miolo
5
5
  *
@@ -10,4 +10,4 @@
10
10
  *
11
11
  * @license MIT
12
12
  */
13
- import e from"koa";import r from"deepmerge";import t from"node:path";import{fileURLToPath as o}from"node:url";import n from"nodemailer";import i,{readFileSync as a}from"node:fs";import{uncolor as l,red as c,red_light as u,yellow as s,cyan as d,magenta as f,gray as v,green as p,cyan_light as m,blue as h,green_bold as g,yellow_bold as y}from"tinguir";import b from"node:util";import _,{format as w,transports as x,createLogger as S}from"winston";import{intre_now as k}from"intre";import{dropConnections as O,getConnection as E}from"calustra";export{getConnection as miolo_db_connection}from"calustra";import{cacheiro as j}from"cacheiro";export{cacheiro as miolo_cacher}from"cacheiro";import q from"koa-better-body";import C from"koa-convert";import N from"koa-compress";import{constants as P}from"node:zlib";import I from"node:http";import R from"koa-ratelimit";import M from"node:https";import J from"koa-mount";import L from"koa-static";import F from"koa-favicon";import{performance as T}from"node:perf_hooks";import{Reader as A}from"@maxmind/geoip2-node";import U from"@koa/router";import z from"jwt-simple";import B from"koa-passport";import G from"passport-local";import{createSession as D}from"koa-session";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 Z from"node:os";import Q from"diskspace";import{createHttpTerminator as X}from"http-terminator";function $(e,r,t,o,n,i,a){try{var l=e[i](a),c=l.value}catch(e){return void t(e)}l.done?r(c):Promise.resolve(c).then(o,n)}function ee(e){return function(){var r=this,t=arguments;return new Promise((function(o,n){var i=e.apply(r,t);function a(e){$(i,o,n,a,l,"next",e)}function l(e){$(i,o,n,a,l,"throw",e)}a(void 0)}))}}function re(e,r,t){return(r=function(e){var r=function(e,r){if("object"!=typeof e||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var o=t.call(e,r);if("object"!=typeof o)return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(e)}(e,"string");return"symbol"==typeof r?r:r+""}(r))in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}function te(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);r&&(o=o.filter((function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable}))),t.push.apply(t,o)}return t}function oe(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{};r%2?te(Object(t),!0).forEach((function(r){re(e,r,t[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):te(Object(t)).forEach((function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))}))}return e}var ne=o(import.meta.url),ie=t.dirname(ne),ae=864e6,le={name:"miolo",http:{port:8001,hostname:"localhost",catcher_url:"/sys/jserror",static:{favicon:t.resolve(ie,"../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:ae,secure:!0,sameSite:"lax"}},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:[],cache:{default:{type:"combined",redis:{host:"127.0.0.1",port:6379},version:1,clean:!1},calustra:{namespace:"miolo-calustra",ttl:864e5},session:{namespace:"miolo-session",ttl:ae},custom:{}},socket:{enabled:!1,cli:{}}};function ce(e){var{options:r,defaults:t,silent:o}=e,i=n.createTransport(r,t);function a(){return(a=ee((function*(e){if(!0===o)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=i.sendMail(e);return r.ok=!(null==r||!r.messageId),r}catch(t){return{error:t,ok:!1}}}))).apply(this,arguments)}var l={send:function(e){return a.apply(this,arguments)},verify:function(){console.info("[miolo][Verify][MAILER] Verifying..."),i.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:t,silent:o};return l}var{combine:ue,timestamp:se,_label:de,printf:fe,errors:ve}=w,pe=function(e,r){var o,n,a,p,m=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"miolo",h={silly:v,debug:f,verbose:d,info:s,warn:u,error:c},g={silly:"sly",debug:"dbg",verbose:"vbs",info:"inf",warn:"wrn",error:"err"},y=0,w=r=>{var t,o=h[r.level],n=new Date(r.timestamp).toLocaleString((null==e||null===(t=e.format)||void 0===t?void 0:t.locale)||"en"),i="".padStart(y," "),a="[".concat(m,"] ").concat(o(n)," ").concat(o(g[r.level])," ").concat(i).concat(r.message);return r.stack?"".concat(a,"\n").concat(r.stack):a},O=[];!0===(null==e||null===(o=e.console)||void 0===o?void 0:o.enabled)&&O.push(new x.Console({humanReadableUnhandledException:!0,level:(null==e||null===(p=e.console)||void 0===p?void 0:p.level)||(null==e?void 0:e.level)||"silly",handleExceptions:!0}));if(!0===(null==e||null===(n=e.file)||void 0===n?void 0:n.enabled)){var E,j,q=new x.File({filename:null!=e&&null!==(E=e.file)&&void 0!==E&&E.filename?e.file.filename.replace("%MIOLO%",m):"/var/log/afialapis/miolo.log",level:(null==e||null===(j=e.file)||void 0===j?void 0:j.level)||(null==e?void 0:e.level)||"info",humanReadableUnhandledException:!0,handleExceptions:!0,maxRetries:10});!function(e){process.on("SIGHUP",(function(){var r=t.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 t=i.createWriteStream(r,e.options);t.setMaxListeners(1/0),e._size=0,e._stream=t,e.opening=!1,e.emit("open",r),console.log("[miolo][file-logger] Reopened ".concat(r," successfully"))}catch(o){console.error("[miolo][file-logger] Error reopening ".concat(r,": ").concat(o.toString()))}}()}))}(q),O.push(q);var C=r=>{var o,n,a=t.join(q.dirname,q.filename),l=w({level:"info",message:"[logger][file-rotate] ".concat(r,"\n"),timestamp:k()});try{i.accessSync(a,i.constants.F_OK),i.appendFileSync(a,l)}catch(c){i.writeFileSync(a,l,{encoding:"utf-8"})}!0===(null==e||null===(o=e.console)||void 0===o?void 0:o.enabled)&&(q.levels[(null==e||null===(n=e.console)||void 0===n?void 0:n.level)||(null==e?void 0:e.level)||"error"]>=q.levels.info&&console.log(l))};q.on("finish",(function(e){C("Log done")})),q.on("error",(function(e){C(c("Error: ".concat(e)))}))}if(!0===(null==e||null===(a=e.mail)||void 0===a?void 0:a.enabled)){var N=function(e,r){var t=function(t){_.Transport.call(this,t),t=t||{},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=t.humanReadableUnhandledException||!0,this.handleExceptions=t.handleExceptions||!0,this.json=t.json||!1,this.colorize=t.colorize||!1};return b.inherits(t,_.Transport),t.prototype.name="MailerLogger",t.prototype.log=function(t,o){var n=this,i="",a="";try{try{i=t.message.split("\n")[0]}catch(s){i=t.message.toString()}i=l(i)}catch(d){i="Could not create a title for the error (".concat(d.toString(),")")}try{try{a=l(t.message)}catch(d){a=t.message.toString()}}catch(d){a="Could not create a body for the error (".concat(d.toString(),")")}var c="".concat(null==e?void 0:e.name," [").concat(t.level.toUpperCase(),"] ").concat(i),u={from:this.from,to:this.to,subject:c,text:a};r.send(u,(function(){n.emit("logged"),o(null,!0)}))},t}(e.mail,r);x.MailerLogger=N,O.push(new x.MailerLogger({humanReadableUnhandledException:!0,handleExceptions:!0}))}var P=S({level:(null==e?void 0:e.level)||"silly",format:ue(ve({stack:!0}),se(),fe(w)),transports:O}),I=(e,r)=>{var t=(r,t)=>{if(isNaN(null==t?void 0:t.indent))e(r,t);else{var o=Math.max(y+parseInt(null==t?void 0:t.indent),0);t.indent>0?(e(r,t),y=o):(y=o,e(r,t))}};return Object.defineProperty(t,"name",{value:r}),t};P.error=I(P.error,"error"),P.warn=I(P.warn,"warn"),P.info=I(P.info,"info"),P.http=I(P.http,"http"),P.verbose=I(P.verbose,"verbose"),P.debug=I(P.debug,"debug"),P.silly=I(P.silly,"silly");try{P.debug("[logger] Inited for ".concat(P.transports.map((e=>"".concat(e.name," (").concat(e.level,")").concat(e.silent?c(" SILENT!"):""))).join(",")))}catch(R){}return P};class me{parse_value_str(e){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:void 0;if(null==e||null==e){if(arguments.length>1&&void 0!==arguments[1]&&arguments[1])throw"Wrong str value passed: ".concat(e);return r}return e.toString()}parse_field_str(e,r){var t=arguments.length>2&&void 0!==arguments[2]&&arguments[2],o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:void 0;if(!(r in e)){if(t)throw"Expected str value not passed for ".concat(r);return o}return this.parse_value_str(e[r],t,o)}parse_value_int(e){var r=arguments.length>1&&void 0!==arguments[1]&&arguments[1],t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:void 0,o=parseInt(e);if(null==o||isNaN(o)){if(r)throw"Wrong int value passed: ".concat(e);return t}return o}parse_field_int(e,r){var t=arguments.length>2&&void 0!==arguments[2]&&arguments[2],o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:void 0;if(!(r in e)){if(t)throw"Expected int value not passed for ".concat(r);return o}return this.parse_value_int(e[r],t,o)}parse_value_float(e){var r=arguments.length>1&&void 0!==arguments[1]&&arguments[1],t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:void 0,o=parseFloat(e);if(null==o||isNaN(o)){if(r)throw"Wrong float value passed: ".concat(e);return t}return e}parse_field_float(e,r){var t=arguments.length>2&&void 0!==arguments[2]&&arguments[2],o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:void 0;if(!(r in e)){if(t)throw"Expected float value not passed for ".concat(r);return o}return this.parse_value_float(e[r],t,o)}parse_value_bool(e){if(null!=e&&null!=e)return!0===e||"true"===e||"True"===e||1===e||"1"===e||!1!==e&&"false"!==e&&"False"!==e&&0!==e&&"0"!==e&&(arguments.length>2&&void 0!==arguments[2]?arguments[2]:void 0);if(arguments.length>1&&void 0!==arguments[1]&&arguments[1])throw"Wrong bool value passed for ".concat(name)}parse_field_bool(e,r){var t=arguments.length>2&&void 0!==arguments[2]&&arguments[2],o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:void 0;if(!(r in e)){if(t)throw"Expected bool value not passed for ".concat(r);return o}return this.parse_value_bool(e[r],t,o)}parse_value_obj(e){var r=arguments.length>1&&void 0!==arguments[1]&&arguments[1],t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:void 0;if(null==e||null==e){if(r)throw"Wrong obj value passed: ".concat(e);return t}if(0==Object.keys(e).length){if(r)throw"Empty obj value passed: ".concat(e);return t}if("object"!=typeof e)throw"Wrong obj value passed: ".concat(e);return e}parse_field_obj(e,r){var t=arguments.length>2&&void 0!==arguments[2]&&arguments[2],o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:void 0;if(!(r in e)){if(t)throw"Expected obj value not passed for ".concat(r);return o}return this.parse_value_obj(e[r],t,o)}}var he=()=>new me;function ge(e,r,t){return{type:(null==r?void 0:r.type)||(null==e?void 0:e.type),redis:(null==r?void 0:r.redis)||(null==e?void 0:e.redis),namespace:(null==r?void 0:r.namespace)||(null==e?void 0:e.namespace),version:(null==r?void 0:r.version)||(null==e?void 0:e.version),clean:!0===(null==r?void 0:r.clean)||!0===(null==e?void 0:e.clean),ttl:(null==r?void 0:r.ttl)||(null==e?void 0:e.ttl),log:t}}function ye(e,r){return ge(e.cache.default,e.cache.calustra,r)}var be=void 0;function _e(e,r){var t=function(){var t=ee((function*(){if(null==be){be={};var t=function(e,r){var t=e.cache.default,o=e.cache.custom||{},n={};for(var[i,a]of Object.entries(o)){var l=ge(t,a,r);l.namespace=l.namespace||"miolo-".concat(i),n[i]=l}return n}(e,r);for(var[o,n]of Object.entries(t)){var i=yield j(n);be[o]=i}}return be}));return function(){return t.apply(this,arguments)}}(),o=function(){var e=ee((function*(e){return(yield t())[e]}));return function(r){return e.apply(this,arguments)}}(),n=function(){var e=ee((function*(){var e=yield t();return Object.keys(e)}));return function(){return e.apply(this,arguments)}}(),i=function(){var e=ee((function*(e,r){var n=yield t();r&&(yield o(e)).unsetAll();delete n[e]}));return function(r,t){return e.apply(this,arguments)}}(),a=function(){var e=ee((function*(e){if(e){var r=yield t();for(var[o,n]of Object.entries(r))yield n.unsetAll()}be={}}));return function(r){return e.apply(this,arguments)}}();return{get_cache:o,get_cache_names:n,drop_cache:i,drop_caches:a}}var we=(e,r)=>{var t=ce(r.mail),o=pe(r.log,t,null==r?void 0:r.name),n=he(),i=function(e,r){var t,o,n=function(){var t=ee((function*(t){var o=oe(oe(oe({},e.db.options),t||{}),{},{log:r,cache:ye(e,r)}),n=yield E(e.db.config,o);return n.get_model=n.getModel,n}));return function(e){return t.apply(this,arguments)}}(),i=function(){var t=ee((function*(t,o){var n=oe(oe(oe({},e.db.options),o||{}),{},{log:r});return(yield E(e.db.config,n)).get_model(t)}));return function(e,r){return t.apply(this,arguments)}}(),a={init_connection:(o=ee((function*(){return yield n({reset:!0})})),function(){return o.apply(this,arguments)}),fly_connection:(t=ee((function*(){return yield n({cache:!1})})),function(){return t.apply(this,arguments)}),get_connection:n,get_model:i,drop_connections:O};return a}(r,o),a=_e(r,o),l={config:oe({},r),emailer:t,logger:o,parser:n,db:i,cache:a};function c(){return(c=ee((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},xe=[401,403];var Se="/var/ipsum",ke="ipsum.txt";function Oe(e,r){var t=r?r.error:console.error;if(!e)return[];try{var o=[];return e.split("\n").filter((e=>e.indexOf("#")<0)).map((e=>{var[r,t]=e.split("\t");parseInt(t)>=1&&o.push(r)})),o}catch(n){return t("[cron][".concat(d("IPsum"),"] Error getting IPs from content")),[]}}function Ee(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:Se,r=arguments.length>1?arguments[1]:void 0,o=arguments.length>2?arguments[2]:void 0,n=o?o.error:console.error,a=o?o.debug:console.log;if(i.existsSync(e))try{a("[cron][".concat(d("IPsum"),"] Updating file...")),function(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"https://raw.githubusercontent.com/stamparm/ipsum/master/ipsum.txt",t=arguments.length>2?arguments[2]:void 0,o=t?t.error:console.error;M.get(r,(r=>{var t=[];r.on("data",(e=>{t.push(e)})).on("end",(()=>{var r=Buffer.concat(t).toString();e(r)}))})).on("error",(r=>{o("[cron][".concat(d("IPsum"),"] Error downloading remote file (").concat(r.toString(),")")),e("")}))}((n=>{var l=t.join(e,ke);i.writeFileSync(l,n,{encoding:"utf8",flag:"w"});var c=n.split("\n").length,u=Oe(n,o),s=u.length;a("[cron][".concat(d("IPsum"),"] File downloaded. ").concat(c," ips on the list (").concat(s," appearing in ").concat(1," or more lists)")),r&&r(u)}))}catch(l){n("[cron][".concat(d("IPsum"),"] Error ").concat(l," updating the file"))}else n("[cron][".concat(d("IPsum"),"] Folder ").concat(e," does not exist"))}function je(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:Se,r=arguments.length>1?arguments[1]:void 0,o=arguments.length>2?arguments[2]:void 0,n=o?o.debug:console.log,a=o?o.warn:console.log,l=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:Se,r=arguments.length>1?arguments[1]:void 0,o=r?r.error:console.error;if(!i.existsSync(e))return r&&o("[cron][".concat(d("IPsum"),"] Folder ").concat(e," does not exist")),[];var n=t.join(e,ke);return i.existsSync(n)?Oe(i.readFileSync(n,{encoding:"utf8"}),r):(r&&o("[cron][".concat(d("IPsum"),"] File ").concat(n," does not exist")),[])}(e,o);return l.length>0?(r&&r(l),n("[cron][".concat(d("IPsum"),"] File contains ").concat(l.length," ips")),l):(a("[cron][".concat(d("IPsum"),"] File is empty. Launching update...")),Ee(e,r,o),[])}var qe=["52.212.247.108","54.218.32.58","170.106.82.193","110.166.71.39","39.107.54.8","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 Ce=o(import.meta.url),Ne=t.dirname(Ce),Pe=t.resolve(Ne,"./miolo.ico"),Ie=t.resolve(Ne,"../../../.."),Re=void 0,Me=["127.0.0.1","::1:"];var Je=function(e,r){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:console;if(function(e){return[...Me,...(arguments.length>1&&void 0!==arguments[1]?arguments[1]:[])||[]].indexOf(e)>=0}(e,null==r?void 0:r.local_ips))return{local:!0,country:"",city:""};try{var o,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]:console;try{if(null!=Re)return Re;var t=i.readFileSync(e);return Re=A.openBuffer(t)}catch(o){return r.error("[geoip] Error initing:"),void r.error(o)}}(null==r?void 0:r.db,t),a=n.city(e);return{country:a.country.isoCode,city:null===(o=a.city)||void 0===o||null===(o=o.names)||void 0===o?void 0:o.en}}catch(l){t.error("[geoip] Error localizing IP ".concat(e,":")),t.error(l)}return{country:"",city:""}},Le={total:0};var Fe=o(import.meta.url),Te=t.dirname(Fe),Ae=a(t.resolve(Te,"./robots.txt"),"utf8");var Ue=(e,r,t)=>{var o=e.context.miolo.logger,n=()=>{try{var{make_guest_token:e}=r;if(null!=e)return e(t||{})}catch(n){}return function(e,r){var t=Math.random().toString(),o=null==e?void 0:e.secret;o||(o="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:t};return z.encode(n,o)}(t||{},o)};function i(){return i=ee((function*(e,r){var i=e.cookies.get("token")||e.headers.token;void 0!==i&&0!=i.length||(i=yield n(),o.debug("Guest token conceeded"));var a=function(e){var r,t=null==e||null===(r=e.options)||void 0===r?void 0:r.maxAge;isNaN(t)&&(t=86400);var o=new Date;return o.setSeconds(o.getSeconds()+t),{expires:o,httpOnly:!1}}(t);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)}))},ze=(e,r)=>{var{auth_user:t,realm:o,paths:n}=r;function i(e,r){return a.apply(this,arguments)}function a(){return(a=ee((function*(r,n){var i;try{i=(e=>{var r,t=null==e||null===(r=e.headers)||void 0===r?void 0:r.authorization;if(t)try{t=t.replace("Basic ","");try{t=Buffer.from(t,"base64").toString()}catch(i){t=atob(t)}var[o,n]=t.split(":");return{username:o,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="'+o.replace(/"/g,'\\"')+'"'};if(!i)return a();var l=yield t(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)}o||(o="Secure Area"),null==n||0==n.length?e.use(i):n.map((r=>e.use(J(r,i))))};class Be{constructor(e,r){this.options=e,this.logger=r,this._cache=void 0}init_cache(){var e=this;return ee((function*(){return null==e._cache&&(e.logger.silly("[session-store] Initing store"),e._cache=yield j(e.options)),e._cache}))()}get(e,r,t){var o=this;return ee((function*(){var{rolling:r,ctx:n}=t,i=yield o.init_cache(),a=yield i.getItem(e);try{var l=JSON.parse(a);return o.logger.silly("[session-store] Get session for ".concat(e,": ").concat(JSON.stringify(l))),l}catch(c){return void o.logger.silly("[session-store] No session for ".concat(e))}}))()}set(e,r,t,o){var n=this;return ee((function*(){var{rolling:t,changed:i,ctx:a}=o;n.logger.silly("[session-store] Set session for ".concat(e));var l=yield n.init_cache(),c=void 0;try{c=JSON.stringify(r)}catch(u){}yield l.setItem(e,c)}))()}destroy(e,r){var t=this;return ee((function*(){var{ctx:o}=r;t.logger.silly("[session-store] Destroy session for ".concat(e));var n=yield t.init_cache();yield n.unsetItem(e)}))()}}function Ge(e,r){var t=function(e,r){return ge(e.cache.default,e.cache.session,r)}({cache:e},r);return new Be(t,r)}var De=(e,r,t)=>r(null,e.id),We=(e,r,t)=>{r(Error("You need to define auth.passport.find_user_by_id"),null)},He=(e,r,t,o)=>{t(Error("You need to define auth.passport.local_auth_user"),null)},Ye=(e,r,t,o)=>{var{get_user_id:n,find_user_by_id:i,local_auth_user:a,url_login:l,url_logout:c,url_login_redirect:u,url_logout_redirect:s}=r,d=n||De,f=i||We,v=a||He,p=l||"/login",m=c||"/logout",h=new G.Strategy(((r,t,o)=>{v(r,t,o,e.context.miolo)}));function g(){return(g=ee((function*(e,r){try{e.session.authenticated&&(e.session.user=e.state.user)}catch(t){}yield r()}))).apply(this,arguments)}!function(e,r,t){var o=Ge(t,e.context.miolo.logger);e.keys=[r.secret||"*secret*"];var n=oe({store:o},r.options||{});e.use(D(n,e))}(e,t,o),B.serializeUser(((r,t)=>{process.nextTick((function(){d(r,t,e.context.miolo)}))})),B.deserializeUser(((r,t)=>{process.nextTick((function(){f(r,t,e.context.miolo)}))})),B.use(h),e.use(B.initialize()),e.use(B.session()),e.use((function(e,r){return g.apply(this,arguments)}));var y=function(){var e=ee((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!=s&&e.redirect(s)):(e.body={user:void 0,authenticated:!1},e.response.status=401)}));return function(r,t){return e.apply(this,arguments)}}(),b=new U;b.post(p,((e,r)=>B.authenticate("local",function(){var r=ee((function*(r,t,o,n){if(!1!==t)return e.session.user=e.state.user,e.session.authenticated=!0,e.body={user:t,authenticated:!0},null!=u&&e.redirect(u),yield e.login(t);e.session.user=void 0,e.session.authenticated=!1,e.body={user:void 0,authenticated:!1,info:o,error:r},e.response.status=401}));return function(e,t,o,n){return r.apply(this,arguments)}}())(e))),b.get(m,y),b.post(m,y),e.use(b.routes())},Ke=(e,r,t)=>{try{var o=e[r];if(null!=o&&0!=o)return t(o)}catch(n){}},Ve=(e,r)=>{var t=e.context.miolo.logger;Ke(r,"cors",(r=>{if("simple"==r)t.debug("[http] Setting CORS the simple way"),e.use(function(){var e=ee((function*(e,r){e.set("[http] Access-Control-Allow-Origin","*"),e.set("[http] Access-Control-Expose-Headers","SourceMap,X-SourceMap"),yield r()}));return function(r,t){return e.apply(this,arguments)}}());else{var o=(e=>"object"==typeof e?e:{})(r);t.debug("[http] Setting CORS headers for ".concat(JSON.stringify(o))),e.use(W(o))}})),Ke(r,"proxy",(r=>{var[o,n]=(e=>{var r,t,o,n;return null==e&&(e={}),[(null===(r=e)||void 0===r?void 0:r.path)||"/",{target:(null===(t=e)||void 0===t?void 0:t.target)||"https://proxy.miolo.com",changeOrigin:null==(null===(o=e)||void 0===o?void 0:o.changeOrigin)||e.changeOrigin,logs:null==(null===(n=e)||void 0===n?void 0:n.logs)||e.logs}]})(r);t.debug("[http] Setting Proxy for ".concat(o," to ").concat(n.target," ")),e.use(H(o,n))}))},Ze=function(){var e=ee((function*(e){return!0}));return function(r){return e.apply(this,arguments)}}(),Qe=function(){var e=ee((function*(e,r){return r}));return function(r,t){return e.apply(this,arguments)}}(),Xe={require:!1,action:"redirect",redirect_url:"/",error_code:401},$e={use:!1,fieldNames:{created_by:"created_by",last_update_by:"last_update_by"}};function er(e){var r=e.indexOf("?")>=0?e.substr(e.indexOf("?")+1):"";return r?Y.parse(r):{}}function rr(e,r){function t(e){return o.apply(this,arguments)}function o(){return(o=ee((function*(r){var t=r.request.fields;try{r.miolo.logger.debug("[router] ".concat(e.name,"() Calling with params ").concat(JSON.stringify(t)))}catch(n){r.miolo.logger.debug("[router] ".concat(e.name,"()Calling with params (?)"))}var o=yield e(r.miolo,t);try{r.miolo.logger.debug("[router] ".concat(e.name,"() Called with result ").concat(JSON.stringify(o)))}catch(n){r.miolo.logger.debug("[router] ".concat(e.name,"() Called with result (?)"))}r.body=o}))).apply(this,arguments)}return Object.defineProperty(t,"name",{value:e.name,writable:!1}),t}function tr(e,r,t){r.map((r=>{var o=r.prefix;r.routes.map((r=>{for(var n=function(){var e=ee((function*(e,t){var o,n=!0===(null==e||null===(o=e.session)||void 0===o?void 0:o.authenticated),i=r.auth;return!(!0===i.require||"read-only"===i.require&&"w"===t)||(n||("error"==i.action?(e.miolo.logger.error("[router] Unauthorized access. Throwing error ".concat(i.error_code)),e.throw(i.error_code,null,{})):"redirect"==i.action?(e.miolo.logger.warn("[router] Unauthorized access. Redirecting to ".concat(i.redirect_url)),e.redirect(i.redirect_url)):(e.miolo.logger.error("[router] Crud path ".concat(r.url," specified auth but no action")),e.body={})),n)}));return function(r,t){return e.apply(this,arguments)}}(),i=function(){var e=ee((function*(e,t,o){var i=yield e.miolo.db.get_model(r.name);if(!i)throw e.miolo.logger.error("[router] Could not get model for ".concat(r.name)),new Error("[router] Could not get model for ".concat(r.name));var a,l={};try{var c;if(!(yield n(e,t)))return void(e.body={});var u=!0;if(null!=r&&r.before&&(u=yield r.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===r.useUserFields.use&&(d=r.useUserFields.fieldNames);var f={uid:s,fieldNames:d};l=yield o(i,f),null!=r&&r.after&&(l=yield r.after(e,l))}catch(v){e.miolo.logger.error("[router] Unexpected error on CRUD ".concat(r.name,"-").concat(t)),e.miolo.logger.error(v)}a=l,l=null==r.bodyField?a:{[r.bodyField]:a},e.body=l}));return function(r,t,o){return e.apply(this,arguments)}}(),a=function(){var e=ee((function*(e){yield i(e,"r",function(){var r=ee((function*(r,t){var o=er(e.request.url),n={transaction:void 0};return yield r.read(o,n)}));return function(e,t){return r.apply(this,arguments)}}())}));return function(r){return e.apply(this,arguments)}}(),l=function(){var e=ee((function*(e){yield i(e,"r",function(){var r=ee((function*(r,t){var o=er(e.request.url),n={transaction:void 0};return yield r.keyList(o,n)}));return function(e,t){return r.apply(this,arguments)}}())}));return function(r){return e.apply(this,arguments)}}(),c=function(){var e=ee((function*(e){yield i(e,"r",function(){var r=ee((function*(r,t){var o=er(e.request.url),n={transaction:void 0};return yield r.find(o.id,n)}));return function(e,t){return r.apply(this,arguments)}}())}));return function(r){return e.apply(this,arguments)}}(),u=function(){var e=ee((function*(e){yield i(e,"r",function(){var r=ee((function*(r,t){var o=er(e.request.url),n={transaction:void 0};return yield r.distinct(o.distinct_field,o,n)}));return function(e,t){return r.apply(this,arguments)}}())}));return function(r){return e.apply(this,arguments)}}(),s=function(){var e=ee((function*(e){yield i(e,"w",function(){var r=ee((function*(r,t){var o,n=e.request.fields;null!=t&&null!==(o=t.fieldNames)&&void 0!==o&&o.created_by&&(n[t.fieldNames.created_by]=t.uid);var i={transaction:void 0};return yield r.insert(n,i)}));return function(e,t){return r.apply(this,arguments)}}())}));return function(r){return e.apply(this,arguments)}}(),d=function(){var e=ee((function*(e){yield i(e,"w",function(){var r=ee((function*(r,t){var o,n=e.request.fields;null!=t&&null!==(o=t.fieldNames)&&void 0!==o&&o.last_update_by&&(n[t.fieldNames.last_update_by]=t.uid);var i={transaction:void 0};return yield r.update(n,{id:n.id},i)}));return function(e,t){return r.apply(this,arguments)}}())}));return function(r){return e.apply(this,arguments)}}(),f=function(){var e=ee((function*(e){yield i(e,"w",function(){var r=ee((function*(r,t){var o=e.request.fields,n={transaction:void 0};return yield r.delete({id:o.id},n)}));return function(e,t){return r.apply(this,arguments)}}())}));return function(r){return e.apply(this,arguments)}}(),v=o?"/".concat(o,"/").concat(r.url):"/".concat(r.url);v.indexOf("//")>=0;)v=v.replace(/\/\//g,"/");t.debug("[router] Routing table ".concat(r.name," to ").concat(v));var p=r.mode.indexOf("r")>=0,m=r.mode.indexOf("w")>=0,h=r.mode.indexOf("u")>=0||m;p&&(e.get("".concat(v,"/find"),(e=>c(e))),e.get("".concat(v,"/read"),(e=>a(e))),e.get("".concat(v,"/distinct"),(e=>u(e))),e.get("".concat(v,"/key_list"),(e=>l(e)))),h&&(e.post("".concat(v,"/save"),(e=>s(e))),e.post("".concat(v,"/update"),(e=>d(e)))),m&&e.post("".concat(v,"/delete"),(e=>f(e)))}))}))}function or(e,t){var o=e.context.miolo.logger,n=new U;try{var i=(e=>{var t=(null==e?void 0:e.crud)||[];if(!t)return[];if(!Array.isArray(t))return[];var o=[];return t.map((t=>{var n=null==t?void 0:t.routes;if(n&&Array.isArray(n)){var i=(null==t?void 0:t.bodyField)||(null==e?void 0:e.bodyField),a=(null==t?void 0:t.before)||(null==e?void 0:e.before)||Ze,l=(null==t?void 0:t.after)||(null==e?void 0:e.after)||Qe,c=r.all([Xe,(null==e?void 0:e.auth)||{},(null==t?void 0:t.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:r.all([$e,(null==d?void 0:d.useUserFields)||{}]),auth:r.all([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==t?void 0:t.prefix)||"",routes:u})}})),o})(t),a=(e=>{var t=(null==e?void 0:e.queries)||[];if(!t)return[];if(!Array.isArray(t))return[];var o=[];return t.map((t=>{var n=null==t?void 0:t.routes;if(n&&Array.isArray(n)){var i=(null==t?void 0:t.before)||(null==e?void 0:e.before)||Ze,a=(null==t?void 0:t.after)||(null==e?void 0:e.after)||Qe,l=r.all([Xe,(null==t?void 0:t.auth)||{},(null==e?void 0:e.auth)||{}]),c=[];for(var u of n)if(u.url){var s=void 0;if(u.callback||u.callback_fn){s=u.callback||rr(u.callback_fn);var d={url:u.url,method:(null==u?void 0:u.method)||"GET",callback:s,auth:r.all([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(d)}}o.push({prefix:(null==t?void 0:t.prefix)||"",routes:c})}})),o})(t),l=i.length>0,c=a.length>0;if(!l&&!c)throw"[router] Could not get any route from the passed <routes> param";l&&tr(n,i,o),c&&function(e,r,t){r.map((r=>{var o=r.prefix;r.routes.map((r=>{for(var n,i=o?"/".concat(o,"/").concat(r.url):"/".concat(r.url);i.indexOf("//")>=0;)i=i.replace(/\/\//g,"/");var a=r.auth,l=!0===a.require||"read-only"===a.require&&"POST"===r.method;t.debug("[router] Routing ".concat((null===(n=r.callback)||void 0===n?void 0:n.name)||"callback"," to ").concat(r.method," ").concat(i).concat(l?" (auth)":""));var c=function(){var e=ee((function*(e){if(l){var t,o=!0===(null==e||null===(t=e.session)||void 0===t?void 0:t.authenticated);return o||("error"==a.action?(e.miolo.logger.error("Unauthorized access. Throwing error ".concat(a.error_code)),e.throw(a.error_code,null,{})):"redirect"==a.action?(e.miolo.logger.warn("Unauthorized access. Redirecting to ".concat(a.redirect_url)),e.redirect(a.redirect_url)):(e.miolo.logger.error("Route path ".concat(r.url," specified auth but no action")),e.body={})),o}return!0}));return function(r){return e.apply(this,arguments)}}(),u=function(){var e=ee((function*(e){var t={};try{try{var o;if("GET"==r.method&&(null===(o=e.request)||void 0===o||!o.fields)&&e.request.url.indexOf("?")>0){var n=er(e.request.url);n&&(e.request.fields=n)}}catch(u){e.miolo.logger.error("[router] Error while trying to qet query params for ".concat(e.request.url))}if(!(yield c(e)))return;var a=!0;if(null!=r&&r.before&&(a=yield r.before(e)),!a)return;t=yield r.callback(e),null!=r&&r.after&&(t=yield r.after(e,t))}catch(s){var l;e.miolo.logger.error("[router] Unexpected error on Query ".concat(null===(l=r.callback)||void 0===l?void 0:l.name," at ").concat(i)),e.miolo.logger.error(s)}return t}));return function(r){return e.apply(this,arguments)}}(),s=r.method.toLowerCase();e[s](i,(e=>u(e,r)))}))}))}(n,a,o)}catch(u){o.error("[router] Error initing the router."),o.error("[router] routes:"),o.error(t),o.error(u)}e.use(n.routes())}var nr=o(import.meta.url),ir=t.dirname(nr),ar=a(t.resolve(ir,"fallback_index.html"),"utf8");function lr(e,r,t,o,n){var i=(null==r?void 0:r.html)||ar;i.indexOf("{context}")<0&&e.context.miolo.logger.error("Provided HTML for rendering has no {context} template variable"),i.indexOf("{children}")<0&&e.context.miolo.logger.error("Provided HTML for rendering has no {children} template variable");var a=function(){var e=ee((function*(e){var t={};try{var o;null!=r&&null!==(o=r.ssr)&&void 0!==o&&o.loader&&(t=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 t}));return function(r){return e.apply(this,arguments)}}();function l(){return(l=ee((function*(e){var n,l,c=((e,r,t)=>{var o,n,i=!0===(null==e||null===(o=e.session)||void 0===o?void 0:o.authenticated);return{config:r,user:null==e||null===(n=e.session)||void 0===n?void 0:n.user,authenticated:i,ssr_data:t,extra:null==e?void 0:e.extra}})(e,{hostname:null==t?void 0:t.hostname,port:null==t?void 0:t.port,catcher_url:null==t?void 0:t.catcher_url,login_url:null==o||null===(n=o.credentials)||void 0===n?void 0:n.url_login,logout_url:null==o||null===(l=o.credentials)||void 0===l?void 0:l.url_logout},yield a(e)),u=((e,t)=>{var o="";try{var n;null!=r&&null!==(n=r.ssr)&&void 0!==n&&n.renderer?o=K(r.ssr.renderer(e,t)):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())),o="\n <div>\n MIOLO: Error SSR renderer: ".concat(a.toString(),"\n </div> \n ")}return i.replace("{context}",JSON.stringify(t,null,2)).replace("{children}",o)})(e,c);e.miolo.logger.debug("[render-ssr] Returned body is ".concat(Buffer.byteLength(u,"utf8")," bytes")),e.body=u}))).apply(this,arguments)}e.use((function(e){return l.apply(this,arguments)}))}function cr(e){return e?e/1e6:0}function ur(e){return e?e/1e6:0}function sr(){return{name:"SysCheck",cronTime:"0,15,30,45 * * * *",onTick:(e,r)=>{var t,o,n,i;t=e.logger,o=Math.round(cr(Z.freemem()),2),n=Math.round(cr(Z.totalmem()),2),(i=Math.round(100*o/n,2))>80?t.error("[cron][".concat(d("SysCheck"),"] RAM ").concat(s(o)," MB used of ").concat(p(n)," MB (").concat(s(i)," %)")):t.info("[cron][".concat(d("SysCheck"),"] RAM ").concat(s(o)," MB used of ").concat(p(n)," MB (").concat(s(i)," %)")),Q.check("/",(function(e,r){var o=Math.round(ur(r.used),2),n=Math.round(ur(r.total),2),i=Math.round(ur(r.free),2);i<1?t.error("[cron][".concat(d("SysCheck"),"] DISK ").concat(s(o)," GB used of ").concat(p(n)," GB (").concat(s(i)," GB free)")):t.info("[cron][".concat(d("SysCheck"),"] DISK ").concat(s(o)," GB used of ").concat(p(n)," GB (").concat(s(i)," GB free)"))}))},start:!0}}function dr(e,r){var t=e.context.miolo,o=t.logger,n=[sr(),{name:"IPsum",cronTime:"0 0 * * *",onTick:(e,r)=>{Ee(e.config.http.ratelimit.ipsum_folder||Se,(r=>{e.logger.debug("[cron][".concat(d("IPsum"),"] File downloaded. ").concat(p(r.length)," ips will be ").concat(s("blacklisted"),"!"))}),e.logger)},start:!0},...r||[]],i=[];n.map((e=>{var r=e.name,o=function(e,r){var t,o=e.logger,n=null!=r&&null!==(t=r.onTick)&&void 0!==t&&t.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 * * * *",(t=>{try{o.silly("[cron][Custom Job ".concat(d(i),"] ").concat(g("ticks!"))),r.onTick(e,t)}catch(n){o.error("[cron][Custom Job ".concat(d(i),"] Error at onTick()")),o.error(n)}}),(()=>{if(o.silly("[cron][Custom Job ".concat(d(i),"] ").concat(g("completed!"))),null!=r&&r.onComplete)try{r.onComplete(e)}catch(t){o.error("[cron][Custom Job ".concat(d(i),"] Error at onComplete()")),o.error(t)}}),!1,(null==r?void 0:r.timezone)||"Europe/Madrid")}(t,e);i.push({name:r,job:o,running:!1})}));var a=e=>{var r;return(r="number"==typeof e?i[e]:i.filter((r=>r.name==e))[0])||o.error("[cron] Job ".concat(d(e)," Not Found")),r},l=e=>{try{return e.job.start(),e.running=!0,o.debug("[cron][Job ".concat(d(e.name),"] ").concat(g("started!"))),1}catch(r){return o.error("[cron][Job ".concat(d(e.name),"] Error starting it")),o.error(r),0}},c=e=>{try{return e.job.stop(),e.running=!1,o.debug("[cron][Job ".concat(d(e.name),"] ").concat(y("stopped!"))),1}catch(r){return o.error("[cron][Job ".concat(d(e.name),"] Error stopping it")),o.error(r),0}};return e.cron={jobs:i,start_one:e=>{var r=a(e);return r?[l(r),r.name]:[0,""]},start:()=>{try{var e=[],r=[];i.map((t=>{1==l(t)?e.push(t.name):r.push(t.name)})),e.length>0&&o.info("[cron] Started ".concat(e.length," jobs: ").concat(e)),r.length>0&&o.warn("[cron] Could not start ".concat(r.length," jobs: ").concat(r))}catch(t){o.error("[cron] start() error: ".concat(t))}},stop_one:e=>{var r=a(e);return r?[c(r),r.name]:[0,""]},stop:()=>{try{var e=[],r=[];i.map((t=>{1==c(t)?e.push(t.name):r.push(t.name)})),e.length>0&&o.info("[cron] Stopped ".concat(e.length," jobs: ").concat(e)),r.length>0&&o.warn("[cron] Could not stop ".concat(r.length," jobs: ").concat(r))}catch(t){o.error("[cron] stop() error: ".concat(t))}}},e}function fr(e,r){var t,o=e.context.miolo.logger,n=function(){var t=ee((function*(){try{var t,n,i;if(null!=(null===(t=e.http)||void 0===t?void 0:t.server))return void o.warn("[http][start] Server already running on ".concat(null==e||null===(n=e.http)||void 0===n?void 0:n.hostname,":").concat(null==e||null===(i=e.http)||void 0===i?void 0:i.port));var a=I.createServer(e.callback()),l=X({server:a}),c=function(){var t=ee((function*(){try{yield l.terminate(),delete e.http.server,o.info("[http][stop] miolo has been shutdowned from ".concat(r.hostname,":").concat(r.port))}catch(t){o.error("[http][stop] error: ".concat(t))}}));return function(){return t.apply(this,arguments)}}();e.http.server=a,e.http.stop=c,yield((e,r,t)=>new Promise(((o,n)=>{e.listen(r,t,(e=>{e?n(e):o()}))})))(a,r.port,r.hostname),o.info("[http][start] miolo is listening on ".concat(r.hostname,":").concat(r.port))}catch(u){o.error("[http][start] error: ".concat(u))}}));return function(){return t.apply(this,arguments)}}();return e.http={server:void 0,start:n,stop:(t=ee((function*(){o.warn("[http] stop() stop() function still not attached. Is server running?")})),function(){return t.apply(this,arguments)}),hostname:r.hostname,port:r.port},e}function vr(t,o){var n,i,a,l=new e,u=function(e){var t,o=r(le,e);return o.auth_type=function(e){var r,t,o;return null!=e&&null!==(r=e.auth)&&void 0!==r&&r.basic?"basic":null!=e&&null!==(t=e.auth)&&void 0!==t&&t.credentials?"credentials":null!=e&&null!==(o=e.auth)&&void 0!==o&&o.custom?"custom":"guest"}(e),o.use_catcher=!(null==o||null===(t=o.http)||void 0===t||!t.catcher_url),o}(t);we(l,u),Ve(l,u.http),(e=>{e.use(N({filter:function(e){return"application/json"==e||"text/html"==e},gzip:{flush:P.Z_SYNC_FLUSH},deflate:{flush:P.Z_SYNC_FLUSH},br:!1})),e.use(C(q({formLimit:"100mb",jsonLimit:"100mb",bufferLimit:"100mb"})))})(l),function(e){var r=e.context.miolo.logger;function t(){return(t=ee((function*(e){if(e){if(!(e instanceof Error)){var t=e;if("object"==typeof e)try{t=JSON.stringify(e)}catch(a){}var o=new Error("non-error thrown: "+t);e&&(e.name&&(o.name=e.name),e.message&&(o.message=e.message),e.stack&&(o.stack=e.stack),e.status&&(o.status=e.status),e.headers&&(o.headers=e.headers)),e=o}(this.headerSent||!this.writable)&&(e.headerSent=!0),this.app.emit("error",e,this),"ENOENT"===e.code&&(e.status=404);var n=e.status||400;this.accepts(["text","json","html"])?"number"==typeof e.status&&I.STATUS_CODES[e.status]||(e.status=500):(n=406,e.message="Unsupported type"),this.status=n;var i=this.headers["x-real-ip"]||this.headers["x-orig-ip"]||this.ip||"127.0.0.1";xe.indexOf(n)>=0?r.warn("[".concat(i,"] ").concat(this.method," ").concat(this.url," - ").concat(n,": ").concat(e.message)):r.error(e),e.headerSent?r.warn("headers were already sent, returning early"):(this.type="json",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 t.apply(this,arguments)}}(l),function(e,r){var t=e.context.miolo,o=je(null==r?void 0:r.ipsum_folder,void 0,t.logger),n={driver:"memory",db:new Map,id:e=>e.request.ip,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 t=(null==r?void 0:r.whitelist_ips)||[];return!!t&&t.indexOf(e.request.ip)>=0}),blacklist:(null==r?void 0:r.blacklist)||(e=>{var t=e.request.ip,n=[...o,...qe,...(null==r?void 0:r.blacklist_ips)||[]].indexOf(t)>=0;return n&&e.miolo.logger.debug("Rejecting ".concat(s("blacklisted")," ").concat(f(t))),n})};e.use(R(n))}(l,null===(n=u.http)||void 0===n?void 0:n.ratelimit),((e,r)=>{var{favicon:t,folders:o}=r,n=t||Pe;for(var[i,a]of(e.context.miolo.logger.debug("[static] Serving favicon from ".concat(n.replace(Ie,""))),e.use(F(n)),Object.entries(o)))e.context.miolo.logger.debug("[static] Mounting static folder ".concat(i," => ").concat(a.replace(Ie,""))),e.use(J(i,L(a,{index:!1})))})(l,null===(i=u.http)||void 0===i?void 0:i.static),function(e,r){var t=function(){var e=ee((function*(e,r){return{}}));return function(r,t){return e.apply(this,arguments)}}(),o=function(){var e=ee((function*(e,r,t){}));return function(r,t,o){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)||t,onDone:(null==r?void 0:r.onDone)||o,geoip:(null==r?void 0:r.geoip)||{enabled:!1}};function i(){return(i=ee((function*(e,r){var t,o,i,a,l,u,v=e.miolo.logger,h=(e=>{var r=[e.headers["x-real-ip"],e.headers["x-orig-ip"],e.ip,"127.0.0.1"];for(var t of r)if(/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(t))return t})(e),g=T.now();e.request.body=oe(oe({},e.request.fields),e.request.files),Le.total+=1,Le[h]=(Le[h]||0)+1,e.requestId=Le.total,e.request.ip=h;var y=!0===(null==n||null===(t=n.geoip)||void 0===t?void 0:t.enabled),b={};y&&(b=Je(h,n.geoip,v)),e.request.geoip=b;var _=e.request.url.indexOf("?")>=0?e.request.url.substr(0,e.request.url.indexOf("?")):e.request.url,w=y?!0===(null===(o=b)||void 0===o?void 0:o.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,")"):"":"",x="".concat(f(h)).concat(w," ").concat(d(e.request.method)," ").concat(d(_)," [").concat(m(Le[h]),"/").concat(m(e.requestId),"]"),S=null!=e.request.body?JSON.stringify(e.request.body):"";v.info("".concat(x," - START")),v.debug("".concat(x," - Body: ").concat(S));var k=yield n.onStart(e,{started:g,description:"pending"});yield r();var O=null==e||null===(u=e.session)||void 0===u?void 0:u.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 j,q=e.response.status,C=q;200==q?j=p:q>200&&q<=299?(j=s,e.response.redirected&&e.response.url&&(C+=" -> ".concat(e.response.url))):j=c;var N="[".concat(j(C),"]"),P=parseFloat((T.now()-g)/1e3).toFixed(2),I=P<n.lazy?p:P<n.slow?s:c,R=P<n.lazy?"Ok":P<n.slow?"lazy":"slow",M=null!=e.session?JSON.stringify(e.session):"";v.debug("".concat(x," - Session: ").concat(M));var J=null!=e.body?JSON.stringify(e.body):"";v.debug("".concat(x," - Response: ").concat(J)),yield n.onDone(e,k,{started:g,elapsed:P,description:R}),v.info("".concat(x," - DONE ").concat(N).concat(E," (").concat(I(R),": ").concat(I(P),")"))}))).apply(this,arguments)}e.use((function(e,r){return i.apply(this,arguments)}))}(l,null==u||null===(a=u.http)||void 0===a?void 0:a.request),function(e){function r(){return(r=ee((function*(e){e.body=Ae}))).apply(this,arguments)}var t=new U;t.get("/robots.txt",(function(e){return r.apply(this,arguments)})),e.use(t.routes())}(l),u.use_catcher&&function(e,r){function t(){return t=ee((function*(e){var{error:r,warning:t,path:o,agent:n}=e.request.body,i=e.miolo.logger;if(t){var a="".concat(s("[JS Warning]")," on ").concat(h(o),": ").concat(JSON.stringify(t.msg),"\n")+"".concat(s("[JS Warning]")," File => ").concat(t.file,"\n")+"".concat(s("[JS Warning]")," Line => ").concat(t.line,"\n")+"".concat(s("[JS Warning]")," Col => ").concat(t.col,"\n")+"".concat(s("[JS Warning]")," Error => ").concat(JSON.stringify(t.error),"\n")+"".concat(s("[JS Warning]")," Agent => ").concat(n);i.warn(a)}else{var l="".concat(c("[JS Error]")," on ").concat(h(o),": ").concat(JSON.stringify(r.msg),"\n")+"".concat(c("[JS Error]")," File => ").concat(r.file,"\n")+"".concat(c("[JS Error]")," Line => ").concat(r.line,"\n")+"".concat(c("[JS Error]")," Col => ").concat(r.col,"\n")+"".concat(c("[JS Error]")," Error => ").concat(JSON.stringify(r.error),"\n")+"".concat(c("[JS Error]")," Agent => ").concat(n);i.error(l)}e.body={result:1}})),t.apply(this,arguments)}var o=new U;o.post(r,(function(e){return t.apply(this,arguments)})),e.use(o.routes())}(l,u.http.catcher_url),"guest"==u.auth_type&&Ue(l,u.auth.guest,null==u?void 0:u.session),"basic"==u.auth_type&&ze(l,u.auth.basic),"credentials"==u.auth_type&&Ye(l,u.auth.credentials,null==u?void 0:u.session,null==u?void 0:u.cache),"custom"==u.auth_type&&((e,r)=>{var t=e.context.miolo.logger;try{var o=r(e);if("function"==typeof o)e.use(o);else if(Array.isArray(o)){var n=new U;o.map((e=>{var r=e.method.toLowerCase();n[r](e.url,e.callback)})),e.use(n.routes())}}catch(i){t.error("Custom auth error: ".concat(i,"'"))}})(l,u.auth.custom);var v=null==u?void 0:u.middlewares;return v&&((e,r)=>{null!=r&&0!=r.length&&r.map((r=>{e.use(r)}))})(l,v),null!=u&&u.routes&&or(l,u.routes),null!=(null==o?void 0:o.middleware)?l.use(o.middleware):lr(l,o,u.http,null==u?void 0:u.auth,null==u||u.socket),dr(l,null==u?void 0:u.cron),fr(l,null==u?void 0:u.http),l.start=ee((function*(){yield l.context.miolo.db.init_connection(),yield l.http.start(),l.cron.start()})),l.stop=ee((function*(){l.context.miolo.db.drop_connections(),yield l.http.stop(),l.cron.stop()})),l.restart=ee((function*(){yield l.stop(),yield l.start()})),l}export{vr as miolo,ce as miolo_emailer,pe as miolo_logger,he as miolo_parser};
13
+ import e from"koa";import r from"deepmerge";import t from"node:path";import{fileURLToPath as o}from"node:url";import n from"nodemailer";import i,{readFileSync as a}from"node:fs";import{uncolor as l,red as c,red_light as u,yellow as s,cyan as d,magenta as f,gray as v,green as p,cyan_light as m,blue as h,green_bold as g,yellow_bold as y}from"tinguir";import b from"node:util";import _,{format as w,transports as x,createLogger as S}from"winston";import{intre_now as k}from"intre";import{dropConnections as O,getConnection as E}from"calustra";export{getConnection as miolo_db_connection}from"calustra";import{cacheiro as j}from"cacheiro";export{cacheiro as miolo_cacher}from"cacheiro";import q from"koa-better-body";import C from"koa-convert";import N from"koa-compress";import{constants as P}from"node:zlib";import R from"node:http";import I from"koa-ratelimit";import M from"node:https";import J from"koa-mount";import L from"koa-static";import F from"koa-favicon";import{performance as T}from"node:perf_hooks";import{Reader as A}from"@maxmind/geoip2-node";import U from"@koa/router";import z from"jwt-simple";import B from"koa-passport";import G from"passport-local";import{createSession as D}from"koa-session";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 Z from"node:os";import Q from"diskspace";import{createHttpTerminator as X}from"http-terminator";function $(e,r,t,o,n,i,a){try{var l=e[i](a),c=l.value}catch(e){return void t(e)}l.done?r(c):Promise.resolve(c).then(o,n)}function ee(e){return function(){var r=this,t=arguments;return new Promise((function(o,n){var i=e.apply(r,t);function a(e){$(i,o,n,a,l,"next",e)}function l(e){$(i,o,n,a,l,"throw",e)}a(void 0)}))}}function re(e,r,t){return(r=function(e){var r=function(e,r){if("object"!=typeof e||!e)return e;var t=e[Symbol.toPrimitive];if(void 0!==t){var o=t.call(e,r);if("object"!=typeof o)return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(e)}(e,"string");return"symbol"==typeof r?r:r+""}(r))in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}function te(e,r){var t=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);r&&(o=o.filter((function(r){return Object.getOwnPropertyDescriptor(e,r).enumerable}))),t.push.apply(t,o)}return t}function oe(e){for(var r=1;r<arguments.length;r++){var t=null!=arguments[r]?arguments[r]:{};r%2?te(Object(t),!0).forEach((function(r){re(e,r,t[r])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(t)):te(Object(t)).forEach((function(r){Object.defineProperty(e,r,Object.getOwnPropertyDescriptor(t,r))}))}return e}var ne=o(import.meta.url),ie=t.dirname(ne),ae=864e6,le={name:"miolo",http:{port:8001,hostname:"localhost",catcher_url:"/sys/jserror",static:{favicon:t.resolve(ie,"../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:ae,secure:!0,sameSite:"lax"}},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:[],cache:{default:{type:"combined",redis:{host:"127.0.0.1",port:6379},version:1,clean:!1},calustra:{namespace:"miolo-calustra",ttl:864e5},session:{namespace:"miolo-session",ttl:ae},custom:{}},socket:{enabled:!1,cli:{}}};function ce(e){var{options:r,defaults:t,silent:o}=e,i=n.createTransport(r,t);function a(){return(a=ee((function*(e){if(!0===o)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=i.sendMail(e);return r.ok=!(null==r||!r.messageId),r}catch(t){return{error:t,ok:!1}}}))).apply(this,arguments)}var l={send:function(e){return a.apply(this,arguments)},verify:function(){console.info("[miolo][Verify][MAILER] Verifying..."),i.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:t,silent:o};return l}var{combine:ue,timestamp:se,_label:de,printf:fe,errors:ve}=w,pe=function(e,r){var o,n,a,p,m=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"miolo",h={silly:v,debug:f,verbose:d,info:s,warn:u,error:c},g={silly:"sly",debug:"dbg",verbose:"vbs",info:"inf",warn:"wrn",error:"err"},y=0,w=r=>{var t,o=h[r.level],n=new Date(r.timestamp).toLocaleString((null==e||null===(t=e.format)||void 0===t?void 0:t.locale)||"en"),i="".padStart(y," "),a="[".concat(m,"] ").concat(o(n)," ").concat(o(g[r.level])," ").concat(i).concat(r.message);return r.stack?"".concat(a,"\n").concat(r.stack):a},O=[];!0===(null==e||null===(o=e.console)||void 0===o?void 0:o.enabled)&&O.push(new x.Console({humanReadableUnhandledException:!0,level:(null==e||null===(p=e.console)||void 0===p?void 0:p.level)||(null==e?void 0:e.level)||"silly",handleExceptions:!0}));if(!0===(null==e||null===(n=e.file)||void 0===n?void 0:n.enabled)){var E,j,q=new x.File({filename:null!=e&&null!==(E=e.file)&&void 0!==E&&E.filename?e.file.filename.replace("%MIOLO%",m):"/var/log/afialapis/miolo.log",level:(null==e||null===(j=e.file)||void 0===j?void 0:j.level)||(null==e?void 0:e.level)||"info",humanReadableUnhandledException:!0,handleExceptions:!0,maxRetries:10});!function(e){process.on("SIGHUP",(function(){var r=t.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 t=i.createWriteStream(r,e.options);t.setMaxListeners(1/0),e._size=0,e._stream=t,e.opening=!1,e.emit("open",r),console.log("[miolo][file-logger] Reopened ".concat(r," successfully"))}catch(o){console.error("[miolo][file-logger] Error reopening ".concat(r,": ").concat(o.toString()))}}()}))}(q),O.push(q);var C=r=>{var o,n,a=t.join(q.dirname,q.filename),l=w({level:"info",message:"[logger][file-rotate] ".concat(r,"\n"),timestamp:k()});try{i.accessSync(a,i.constants.F_OK),i.appendFileSync(a,l)}catch(c){i.writeFileSync(a,l,{encoding:"utf-8"})}!0===(null==e||null===(o=e.console)||void 0===o?void 0:o.enabled)&&(q.levels[(null==e||null===(n=e.console)||void 0===n?void 0:n.level)||(null==e?void 0:e.level)||"error"]>=q.levels.info&&console.log(l))};q.on("finish",(function(e){C("Log done")})),q.on("error",(function(e){C(c("Error: ".concat(e)))}))}if(!0===(null==e||null===(a=e.mail)||void 0===a?void 0:a.enabled)){var N=function(e,r){var t=function(t){_.Transport.call(this,t),t=t||{},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=t.humanReadableUnhandledException||!0,this.handleExceptions=t.handleExceptions||!0,this.json=t.json||!1,this.colorize=t.colorize||!1};return b.inherits(t,_.Transport),t.prototype.name="MailerLogger",t.prototype.log=function(t,o){var n=this,i="",a="";try{try{i=t.message.split("\n")[0]}catch(s){i=t.message.toString()}i=l(i)}catch(d){i="Could not create a title for the error (".concat(d.toString(),")")}try{try{a=l(t.message)}catch(d){a=t.message.toString()}}catch(d){a="Could not create a body for the error (".concat(d.toString(),")")}var c="".concat(null==e?void 0:e.name," [").concat(t.level.toUpperCase(),"] ").concat(i),u={from:this.from,to:this.to,subject:c,text:a};r.send(u,(function(){n.emit("logged"),o(null,!0)}))},t}(e.mail,r);x.MailerLogger=N,O.push(new x.MailerLogger({humanReadableUnhandledException:!0,handleExceptions:!0}))}var P=S({level:(null==e?void 0:e.level)||"silly",format:ue(ve({stack:!0}),se(),fe(w)),transports:O}),R=(e,r)=>{var t=(r,t)=>{if(isNaN(null==t?void 0:t.indent))e(r,t);else{var o=Math.max(y+parseInt(null==t?void 0:t.indent),0);t.indent>0?(e(r,t),y=o):(y=o,e(r,t))}};return Object.defineProperty(t,"name",{value:r}),t};P.error=R(P.error,"error"),P.warn=R(P.warn,"warn"),P.info=R(P.info,"info"),P.http=R(P.http,"http"),P.verbose=R(P.verbose,"verbose"),P.debug=R(P.debug,"debug"),P.silly=R(P.silly,"silly");try{P.debug("[logger] Inited for ".concat(P.transports.map((e=>"".concat(e.name," (").concat(e.level,")").concat(e.silent?c(" SILENT!"):""))).join(",")))}catch(I){}return P};class me{parse_value_str(e){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:void 0;if(null==e||null==e){if(arguments.length>1&&void 0!==arguments[1]&&arguments[1])throw"Wrong str value passed: ".concat(e);return r}return e.toString()}parse_field_str(e,r){var t=arguments.length>2&&void 0!==arguments[2]&&arguments[2],o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:void 0;if(!(r in e)){if(t)throw"Expected str value not passed for ".concat(r);return o}return this.parse_value_str(e[r],t,o)}parse_value_int(e){var r=arguments.length>1&&void 0!==arguments[1]&&arguments[1],t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:void 0,o=parseInt(e);if(null==o||isNaN(o)){if(r)throw"Wrong int value passed: ".concat(e);return t}return o}parse_field_int(e,r){var t=arguments.length>2&&void 0!==arguments[2]&&arguments[2],o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:void 0;if(!(r in e)){if(t)throw"Expected int value not passed for ".concat(r);return o}return this.parse_value_int(e[r],t,o)}parse_value_float(e){var r=arguments.length>1&&void 0!==arguments[1]&&arguments[1],t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:void 0,o=parseFloat(e);if(null==o||isNaN(o)){if(r)throw"Wrong float value passed: ".concat(e);return t}return e}parse_field_float(e,r){var t=arguments.length>2&&void 0!==arguments[2]&&arguments[2],o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:void 0;if(!(r in e)){if(t)throw"Expected float value not passed for ".concat(r);return o}return this.parse_value_float(e[r],t,o)}parse_value_bool(e){if(null!=e&&null!=e)return!0===e||"true"===e||"True"===e||1===e||"1"===e||!1!==e&&"false"!==e&&"False"!==e&&0!==e&&"0"!==e&&(arguments.length>2&&void 0!==arguments[2]?arguments[2]:void 0);if(arguments.length>1&&void 0!==arguments[1]&&arguments[1])throw"Wrong bool value passed for ".concat(name)}parse_field_bool(e,r){var t=arguments.length>2&&void 0!==arguments[2]&&arguments[2],o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:void 0;if(!(r in e)){if(t)throw"Expected bool value not passed for ".concat(r);return o}return this.parse_value_bool(e[r],t,o)}parse_value_obj(e){var r=arguments.length>1&&void 0!==arguments[1]&&arguments[1],t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:void 0;if(null==e||null==e){if(r)throw"Wrong obj value passed: ".concat(e);return t}if(0==Object.keys(e).length){if(r)throw"Empty obj value passed: ".concat(e);return t}if("object"!=typeof e)throw"Wrong obj value passed: ".concat(e);return e}parse_field_obj(e,r){var t=arguments.length>2&&void 0!==arguments[2]&&arguments[2],o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:void 0;if(!(r in e)){if(t)throw"Expected obj value not passed for ".concat(r);return o}return this.parse_value_obj(e[r],t,o)}}var he=()=>new me;function ge(e,r,t){return{type:(null==r?void 0:r.type)||(null==e?void 0:e.type),redis:(null==r?void 0:r.redis)||(null==e?void 0:e.redis),namespace:(null==r?void 0:r.namespace)||(null==e?void 0:e.namespace),version:(null==r?void 0:r.version)||(null==e?void 0:e.version),clean:!0===(null==r?void 0:r.clean)||!0===(null==e?void 0:e.clean),ttl:(null==r?void 0:r.ttl)||(null==e?void 0:e.ttl),log:t}}function ye(e,r){return ge(e.cache.default,e.cache.calustra,r)}var be=void 0;function _e(e,r){var t=function(){var t=ee((function*(){if(null==be){be={};var t=function(e,r){var t=e.cache.default,o=e.cache.custom||{},n={};for(var[i,a]of Object.entries(o)){var l=ge(t,a,r);l.namespace=l.namespace||"miolo-".concat(i),n[i]=l}return n}(e,r);for(var[o,n]of Object.entries(t)){var i=yield j(n);be[o]=i}}return be}));return function(){return t.apply(this,arguments)}}(),o=function(){var e=ee((function*(e){return(yield t())[e]}));return function(r){return e.apply(this,arguments)}}(),n=function(){var e=ee((function*(){var e=yield t();return Object.keys(e)}));return function(){return e.apply(this,arguments)}}(),i=function(){var e=ee((function*(e,r){var n=yield t();r&&(yield o(e)).unsetAll();delete n[e]}));return function(r,t){return e.apply(this,arguments)}}(),a=function(){var e=ee((function*(e){if(e){var r=yield t();for(var[o,n]of Object.entries(r))yield n.unsetAll()}be={}}));return function(r){return e.apply(this,arguments)}}();return{get_cache:o,get_cache_names:n,drop_cache:i,drop_caches:a}}var we=(e,r)=>{var t=ce(r.mail),o=pe(r.log,t,null==r?void 0:r.name),n=he(),i=function(e,r){var t,o,n=function(){var t=ee((function*(t){var o=oe(oe(oe({},e.db.options),t||{}),{},{log:r,cache:ye(e,r)}),n=yield E(e.db.config,o);return n.get_model=n.getModel,n}));return function(e){return t.apply(this,arguments)}}(),i=function(){var t=ee((function*(t,o){var n=oe(oe(oe({},e.db.options),o||{}),{},{log:r});return(yield E(e.db.config,n)).get_model(t)}));return function(e,r){return t.apply(this,arguments)}}(),a={init_connection:(o=ee((function*(){return yield n({reset:!0})})),function(){return o.apply(this,arguments)}),fly_connection:(t=ee((function*(){return yield n({cache:!1})})),function(){return t.apply(this,arguments)}),get_connection:n,get_model:i,drop_connections:O};return a}(r,o),a=_e(r,o),l={config:oe({},r),emailer:t,logger:o,parser:n,db:i,cache:a};function c(){return(c=ee((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},xe=[401,403];var Se="/var/ipsum",ke="ipsum.txt";function Oe(e,r){var t=r?r.error:console.error;if(!e)return[];try{var o=[];return e.split("\n").filter((e=>e.indexOf("#")<0)).map((e=>{var[r,t]=e.split("\t");parseInt(t)>=1&&o.push(r)})),o}catch(n){return t("[cron][".concat(d("IPsum"),"] Error getting IPs from content")),[]}}function Ee(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:Se,r=arguments.length>1?arguments[1]:void 0,o=arguments.length>2?arguments[2]:void 0,n=o?o.error:console.error,a=o?o.debug:console.log;if(i.existsSync(e))try{a("[cron][".concat(d("IPsum"),"] Updating file...")),function(e){var r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"https://raw.githubusercontent.com/stamparm/ipsum/master/ipsum.txt",t=arguments.length>2?arguments[2]:void 0,o=t?t.error:console.error;M.get(r,(r=>{var t=[];r.on("data",(e=>{t.push(e)})).on("end",(()=>{var r=Buffer.concat(t).toString();e(r)}))})).on("error",(r=>{o("[cron][".concat(d("IPsum"),"] Error downloading remote file (").concat(r.toString(),")")),e("")}))}((n=>{var l=t.join(e,ke);i.writeFileSync(l,n,{encoding:"utf8",flag:"w"});var c=n.split("\n").length,u=Oe(n,o),s=u.length;a("[cron][".concat(d("IPsum"),"] File downloaded. ").concat(c," ips on the list (").concat(s," appearing in ").concat(1," or more lists)")),r&&r(u)}))}catch(l){n("[cron][".concat(d("IPsum"),"] Error ").concat(l," updating the file"))}else n("[cron][".concat(d("IPsum"),"] Folder ").concat(e," does not exist"))}function je(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:Se,r=arguments.length>1?arguments[1]:void 0,o=arguments.length>2?arguments[2]:void 0,n=o?o.debug:console.log,a=o?o.warn:console.log,l=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:Se,r=arguments.length>1?arguments[1]:void 0,o=r?r.error:console.error;if(!i.existsSync(e))return r&&o("[cron][".concat(d("IPsum"),"] Folder ").concat(e," does not exist")),[];var n=t.join(e,ke);return i.existsSync(n)?Oe(i.readFileSync(n,{encoding:"utf8"}),r):(r&&o("[cron][".concat(d("IPsum"),"] File ").concat(n," does not exist")),[])}(e,o);return l.length>0?(r&&r(l),n("[cron][".concat(d("IPsum"),"] File contains ").concat(l.length," ips")),l):(a("[cron][".concat(d("IPsum"),"] File is empty. Launching update...")),Ee(e,r,o),[])}var qe=["52.212.247.108","54.218.32.58","170.106.82.193","110.166.71.39","39.107.54.8","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 Ce=o(import.meta.url),Ne=t.dirname(Ce),Pe=t.resolve(Ne,"./miolo.ico"),Re=t.resolve(Ne,"../../../.."),Ie=void 0,Me=["127.0.0.1","::1:"];var Je=function(e,r){var t=arguments.length>2&&void 0!==arguments[2]?arguments[2]:console;if(function(e){return[...Me,...(arguments.length>1&&void 0!==arguments[1]?arguments[1]:[])||[]].indexOf(e)>=0}(e,null==r?void 0:r.local_ips))return{local:!0,country:"",city:""};try{var o,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]:console;try{if(null!=Ie)return Ie;var t=i.readFileSync(e);return Ie=A.openBuffer(t)}catch(o){return r.error("[geoip] Error initing:"),void r.error(o)}}(null==r?void 0:r.db,t),a=n.city(e);return{country:a.country.isoCode,city:null===(o=a.city)||void 0===o||null===(o=o.names)||void 0===o?void 0:o.en}}catch(l){t.error("[geoip] Error localizing IP ".concat(e,":")),t.error(l)}return{country:"",city:""}},Le={total:0};var Fe=o(import.meta.url),Te=t.dirname(Fe),Ae=a(t.resolve(Te,"./robots.txt"),"utf8");var Ue=(e,r,t)=>{var o=e.context.miolo.logger,n=()=>{try{var{make_guest_token:e}=r;if(null!=e)return e(t||{})}catch(n){}return function(e,r){var t=Math.random().toString(),o=null==e?void 0:e.secret;o||(o="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:t};return z.encode(n,o)}(t||{},o)};function i(){return i=ee((function*(e,r){var i=e.cookies.get("token")||e.headers.token;void 0!==i&&0!=i.length||(i=yield n(),o.debug("Guest token conceeded"));var a=function(e){var r,t=null==e||null===(r=e.options)||void 0===r?void 0:r.maxAge;isNaN(t)&&(t=86400);var o=new Date;return o.setSeconds(o.getSeconds()+t),{expires:o,httpOnly:!1}}(t);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)}))},ze=(e,r)=>{var{auth_user:t,realm:o,paths:n}=r;function i(e,r){return a.apply(this,arguments)}function a(){return(a=ee((function*(r,n){var i;try{i=(e=>{var r,t=null==e||null===(r=e.headers)||void 0===r?void 0:r.authorization;if(t)try{t=t.replace("Basic ","");try{t=Buffer.from(t,"base64").toString()}catch(i){t=atob(t)}var[o,n]=t.split(":");return{username:o,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="'+o.replace(/"/g,'\\"')+'"'};if(!i)return a();var l=yield t(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)}o||(o="Secure Area"),null==n||0==n.length?e.use(i):n.map((r=>e.use(J(r,i))))};class Be{constructor(e,r){this.options=e,this.logger=r,this._cache=void 0}init_cache(){var e=this;return ee((function*(){return null==e._cache&&(e.logger.silly("[session-store] Initing store"),e._cache=yield j(e.options)),e._cache}))()}get(e,r,t){var o=this;return ee((function*(){var{rolling:r,ctx:n}=t,i=yield o.init_cache(),a=yield i.getItem(e);try{var l=JSON.parse(a);return o.logger.silly("[session-store] Get session for ".concat(e,": ").concat(JSON.stringify(l))),l}catch(c){return void o.logger.silly("[session-store] No session for ".concat(e))}}))()}set(e,r,t,o){var n=this;return ee((function*(){var{rolling:t,changed:i,ctx:a}=o;n.logger.silly("[session-store] Set session for ".concat(e));var l=yield n.init_cache(),c=void 0;try{c=JSON.stringify(r)}catch(u){}yield l.setItem(e,c)}))()}destroy(e,r){var t=this;return ee((function*(){var{ctx:o}=r;t.logger.silly("[session-store] Destroy session for ".concat(e));var n=yield t.init_cache();yield n.unsetItem(e)}))()}}function Ge(e,r){var t=function(e,r){return ge(e.cache.default,e.cache.session,r)}({cache:e},r);return new Be(t,r)}var De=(e,r,t)=>r(null,e.id),We=(e,r,t)=>{r(Error("You need to define auth.passport.find_user_by_id"),null)},He=(e,r,t,o)=>{t(Error("You need to define auth.passport.local_auth_user"),null)},Ye=(e,r,t,o)=>{var{get_user_id:n,find_user_by_id:i,local_auth_user:a,url_login:l,url_logout:c,url_login_redirect:u,url_logout_redirect:s}=r,d=n||De,f=i||We,v=a||He,p=l||"/login",m=c||"/logout",h=new G.Strategy(((r,t,o)=>{v(r,t,o,e.context.miolo)}));function g(){return(g=ee((function*(e,r){try{e.session.authenticated&&(e.session.user=e.state.user)}catch(t){}yield r()}))).apply(this,arguments)}!function(e,r,t){var o=Ge(t,e.context.miolo.logger);e.keys=[r.secret||"*secret*"];var n=oe({store:o},r.options||{});e.use(D(n,e))}(e,t,o),B.serializeUser(((r,t)=>{process.nextTick((function(){d(r,t,e.context.miolo)}))})),B.deserializeUser(((r,t)=>{process.nextTick((function(){f(r,t,e.context.miolo)}))})),B.use(h),e.use(B.initialize()),e.use(B.session()),e.use((function(e,r){return g.apply(this,arguments)}));var y=function(){var e=ee((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!=s&&e.redirect(s)):(e.body={user:void 0,authenticated:!1},e.response.status=401)}));return function(r,t){return e.apply(this,arguments)}}(),b=new U;b.post(p,((e,r)=>B.authenticate("local",function(){var r=ee((function*(r,t,o,n){if(!1!==t)return e.session.user=e.state.user,e.session.authenticated=!0,e.body={user:t,authenticated:!0},null!=u&&e.redirect(u),yield e.login(t);e.session.user=void 0,e.session.authenticated=!1,e.body={user:void 0,authenticated:!1,info:o,error:r},e.response.status=401}));return function(e,t,o,n){return r.apply(this,arguments)}}())(e))),b.get(m,y),b.post(m,y),e.use(b.routes())},Ke=(e,r,t)=>{try{var o=e[r];if(null!=o&&0!=o)return t(o)}catch(n){}},Ve=(e,r)=>{var t=e.context.miolo.logger;Ke(r,"cors",(r=>{if("simple"==r)t.debug("[http] Setting CORS the simple way"),e.use(function(){var e=ee((function*(e,r){e.set("[http] Access-Control-Allow-Origin","*"),e.set("[http] Access-Control-Expose-Headers","SourceMap,X-SourceMap"),yield r()}));return function(r,t){return e.apply(this,arguments)}}());else{var o=(e=>"object"==typeof e?e:{})(r);t.debug("[http] Setting CORS headers for ".concat(JSON.stringify(o))),e.use(W(o))}})),Ke(r,"proxy",(r=>{var[o,n]=(e=>{var r,t,o,n;return null==e&&(e={}),[(null===(r=e)||void 0===r?void 0:r.path)||"/",{target:(null===(t=e)||void 0===t?void 0:t.target)||"https://proxy.miolo.com",changeOrigin:null==(null===(o=e)||void 0===o?void 0:o.changeOrigin)||e.changeOrigin,logs:null==(null===(n=e)||void 0===n?void 0:n.logs)||e.logs}]})(r);t.debug("[http] Setting Proxy for ".concat(o," to ").concat(n.target," ")),e.use(H(o,n))}))},Ze=function(){var e=ee((function*(e){return!0}));return function(r){return e.apply(this,arguments)}}(),Qe=function(){var e=ee((function*(e,r){return r}));return function(r,t){return e.apply(this,arguments)}}(),Xe={require:!1,action:"redirect",redirect_url:"/",error_code:401},$e={use:!1,fieldNames:{created_by:"created_by",last_update_by:"last_update_by"}};function er(e){var r=e.indexOf("?")>=0?e.substr(e.indexOf("?")+1):"";return r?Y.parse(r):{}}function rr(e,r){function t(e){return o.apply(this,arguments)}function o(){return(o=ee((function*(r){var t=r.request.fields;try{r.miolo.logger.debug("[router] ".concat(e.name,"() Calling with params ").concat(JSON.stringify(t)))}catch(n){r.miolo.logger.debug("[router] ".concat(e.name,"()Calling with params (?)"))}var o=yield e(r.miolo,t);try{r.miolo.logger.debug("[router] ".concat(e.name,"() Called with result ").concat(JSON.stringify(o)))}catch(n){r.miolo.logger.debug("[router] ".concat(e.name,"() Called with result (?)"))}r.body=o}))).apply(this,arguments)}return Object.defineProperty(t,"name",{value:e.name,writable:!1}),t}function tr(e,r,t){r.map((r=>{var o=r.prefix;r.routes.map((r=>{for(var n=function(){var e=ee((function*(e,t){var o,n=!0===(null==e||null===(o=e.session)||void 0===o?void 0:o.authenticated),i=r.auth;return!(!0===i.require||"read-only"===i.require&&"w"===t)||(n||("error"==i.action?(e.miolo.logger.error("[router] Unauthorized access. Throwing error ".concat(i.error_code)),e.throw(i.error_code,null,{})):"redirect"==i.action?(e.miolo.logger.warn("[router] Unauthorized access. Redirecting to ".concat(i.redirect_url)),e.redirect(i.redirect_url)):(e.miolo.logger.error("[router] Crud path ".concat(r.url," specified auth but no action")),e.body={})),n)}));return function(r,t){return e.apply(this,arguments)}}(),i=function(){var e=ee((function*(e,t,o){var i=yield e.miolo.db.get_model(r.name);if(!i)throw e.miolo.logger.error("[router] Could not get model for ".concat(r.name)),new Error("[router] Could not get model for ".concat(r.name));var a,l={};try{var c;if(!(yield n(e,t)))return void(e.body={});var u=!0;if(null!=r&&r.before&&(u=yield r.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===r.useUserFields.use&&(d=r.useUserFields.fieldNames);var f={uid:s,fieldNames:d};l=yield o(i,f),null!=r&&r.after&&(l=yield r.after(e,l))}catch(v){e.miolo.logger.error("[router] Unexpected error on CRUD ".concat(r.name,"-").concat(t)),e.miolo.logger.error(v)}a=l,l=null==r.bodyField?a:{[r.bodyField]:a},e.body=l}));return function(r,t,o){return e.apply(this,arguments)}}(),a=function(){var e=ee((function*(e){yield i(e,"r",function(){var r=ee((function*(r,t){var o=er(e.request.url),n={transaction:void 0};return yield r.read(o,n)}));return function(e,t){return r.apply(this,arguments)}}())}));return function(r){return e.apply(this,arguments)}}(),l=function(){var e=ee((function*(e){yield i(e,"r",function(){var r=ee((function*(r,t){var o=er(e.request.url),n={transaction:void 0};return yield r.keyList(o,n)}));return function(e,t){return r.apply(this,arguments)}}())}));return function(r){return e.apply(this,arguments)}}(),c=function(){var e=ee((function*(e){yield i(e,"r",function(){var r=ee((function*(r,t){var o=er(e.request.url),n={transaction:void 0};return yield r.find(o.id,n)}));return function(e,t){return r.apply(this,arguments)}}())}));return function(r){return e.apply(this,arguments)}}(),u=function(){var e=ee((function*(e){yield i(e,"r",function(){var r=ee((function*(r,t){var o=er(e.request.url),n={transaction:void 0};return yield r.distinct(o.distinct_field,o,n)}));return function(e,t){return r.apply(this,arguments)}}())}));return function(r){return e.apply(this,arguments)}}(),s=function(){var e=ee((function*(e){yield i(e,"w",function(){var r=ee((function*(r,t){var o,n=e.request.fields;null!=t&&null!==(o=t.fieldNames)&&void 0!==o&&o.created_by&&(n[t.fieldNames.created_by]=t.uid);var i={transaction:void 0};return yield r.insert(n,i)}));return function(e,t){return r.apply(this,arguments)}}())}));return function(r){return e.apply(this,arguments)}}(),d=function(){var e=ee((function*(e){yield i(e,"w",function(){var r=ee((function*(r,t){var o,n=e.request.fields;null!=t&&null!==(o=t.fieldNames)&&void 0!==o&&o.last_update_by&&(n[t.fieldNames.last_update_by]=t.uid);var i={transaction:void 0};return yield r.update(n,{id:n.id},i)}));return function(e,t){return r.apply(this,arguments)}}())}));return function(r){return e.apply(this,arguments)}}(),f=function(){var e=ee((function*(e){yield i(e,"w",function(){var r=ee((function*(r,t){var o=e.request.fields,n={transaction:void 0};return yield r.delete({id:o.id},n)}));return function(e,t){return r.apply(this,arguments)}}())}));return function(r){return e.apply(this,arguments)}}(),v=o?"/".concat(o,"/").concat(r.url):"/".concat(r.url);v.indexOf("//")>=0;)v=v.replace(/\/\//g,"/");t.debug("[router] Routing table ".concat(r.name," to ").concat(v));var p=r.mode.indexOf("r")>=0,m=r.mode.indexOf("w")>=0,h=r.mode.indexOf("u")>=0||m;p&&(e.get("".concat(v,"/find"),(e=>c(e))),e.get("".concat(v,"/read"),(e=>a(e))),e.get("".concat(v,"/distinct"),(e=>u(e))),e.get("".concat(v,"/key_list"),(e=>l(e)))),h&&(e.post("".concat(v,"/save"),(e=>s(e))),e.post("".concat(v,"/update"),(e=>d(e)))),m&&e.post("".concat(v,"/delete"),(e=>f(e)))}))}))}function or(e,t){var o=e.context.miolo.logger,n=new U;try{var i=(e=>{var t=(null==e?void 0:e.crud)||[];if(!t)return[];if(!Array.isArray(t))return[];var o=[];return t.map((t=>{var n=null==t?void 0:t.routes;if(n&&Array.isArray(n)){var i=(null==t?void 0:t.bodyField)||(null==e?void 0:e.bodyField),a=(null==t?void 0:t.before)||(null==e?void 0:e.before)||Ze,l=(null==t?void 0:t.after)||(null==e?void 0:e.after)||Qe,c=r.all([Xe,(null==e?void 0:e.auth)||{},(null==t?void 0:t.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:r.all([$e,(null==d?void 0:d.useUserFields)||{}]),auth:r.all([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==t?void 0:t.prefix)||"",routes:u})}})),o})(t),a=(e=>{var t=(null==e?void 0:e.queries)||[];if(!t)return[];if(!Array.isArray(t))return[];var o=[];return t.map((t=>{var n=null==t?void 0:t.routes;if(n&&Array.isArray(n)){var i=(null==t?void 0:t.before)||(null==e?void 0:e.before)||Ze,a=(null==t?void 0:t.after)||(null==e?void 0:e.after)||Qe,l=r.all([Xe,(null==t?void 0:t.auth)||{},(null==e?void 0:e.auth)||{}]),c=[];for(var u of n)if(u.url){var s=void 0;if(u.callback||u.callback_fn){s=u.callback||rr(u.callback_fn);var d={url:u.url,method:(null==u?void 0:u.method)||"GET",callback:s,auth:r.all([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(d)}}o.push({prefix:(null==t?void 0:t.prefix)||"",routes:c})}})),o})(t),l=i.length>0,c=a.length>0;if(!l&&!c)throw"[router] Could not get any route from the passed <routes> param";l&&tr(n,i,o),c&&function(e,r,t){r.map((r=>{var o=r.prefix;r.routes.map((r=>{for(var n,i=o?"/".concat(o,"/").concat(r.url):"/".concat(r.url);i.indexOf("//")>=0;)i=i.replace(/\/\//g,"/");var a=r.auth,l=!0===a.require||"read-only"===a.require&&"POST"===r.method;t.debug("[router] Routing ".concat((null===(n=r.callback)||void 0===n?void 0:n.name)||"callback"," to ").concat(r.method," ").concat(i).concat(l?" (auth)":""));var c=function(){var e=ee((function*(e){if(l){var t,o=!0===(null==e||null===(t=e.session)||void 0===t?void 0:t.authenticated);return o||("error"==a.action?(e.miolo.logger.error("Unauthorized access. Throwing error ".concat(a.error_code)),e.throw(a.error_code,null,{})):"redirect"==a.action?(e.miolo.logger.warn("Unauthorized access. Redirecting to ".concat(a.redirect_url)),e.redirect(a.redirect_url)):(e.miolo.logger.error("Route path ".concat(r.url," specified auth but no action")),e.body={})),o}return!0}));return function(r){return e.apply(this,arguments)}}(),u=function(){var e=ee((function*(e){var t={};try{try{var o;if("GET"==r.method&&(null===(o=e.request)||void 0===o||!o.fields)&&e.request.url.indexOf("?")>0){var n=er(e.request.url);n&&(e.request.fields=n)}}catch(u){e.miolo.logger.error("[router] Error while trying to qet query params for ".concat(e.request.url))}if(!(yield c(e)))return;var a=!0;if(null!=r&&r.before&&(a=yield r.before(e)),!a)return;t=yield r.callback(e),null!=r&&r.after&&(t=yield r.after(e,t))}catch(s){var l;e.miolo.logger.error("[router] Unexpected error on Query ".concat(null===(l=r.callback)||void 0===l?void 0:l.name," at ").concat(i)),e.miolo.logger.error(s)}return t}));return function(r){return e.apply(this,arguments)}}(),s=r.method.toLowerCase();e[s](i,(e=>u(e,r)))}))}))}(n,a,o)}catch(u){o.error("[router] Error initing the router."),o.error("[router] routes:"),o.error(t),o.error(u)}e.use(n.routes())}var nr=o(import.meta.url),ir=t.dirname(nr),ar=a(t.resolve(ir,"fallback_index.html"),"utf8");function lr(e,r,t,o,n){var i=(null==r?void 0:r.html)||ar;i.indexOf("{context}")<0&&e.context.miolo.logger.error("Provided HTML for rendering has no {context} template variable"),i.indexOf("{children}")<0&&e.context.miolo.logger.error("Provided HTML for rendering has no {children} template variable");var a=function(){var e=ee((function*(e){var t={};try{var o;null!=r&&null!==(o=r.ssr)&&void 0!==o&&o.loader&&(t=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 t}));return function(r){return e.apply(this,arguments)}}();function l(){return(l=ee((function*(e){var n,l,c=((e,r,t)=>{var o,n,i=!0===(null==e||null===(o=e.session)||void 0===o?void 0:o.authenticated);return{config:r,user:null==e||null===(n=e.session)||void 0===n?void 0:n.user,authenticated:i,ssr_data:t,extra:null==e?void 0:e.extra}})(e,{hostname:null==t?void 0:t.hostname,port:null==t?void 0:t.port,catcher_url:null==t?void 0:t.catcher_url,login_url:null==o||null===(n=o.credentials)||void 0===n?void 0:n.url_login,logout_url:null==o||null===(l=o.credentials)||void 0===l?void 0:l.url_logout},yield a(e)),u=((e,t)=>{var o="";try{var n;null!=r&&null!==(n=r.ssr)&&void 0!==n&&n.renderer?o=K(r.ssr.renderer(e,t)):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())),o="\n <div>\n MIOLO: Error SSR renderer: ".concat(a.toString(),"\n </div> \n ")}return i.replace("{context}",JSON.stringify(t,null,2)).replace("{children}",o)})(e,c);e.miolo.logger.debug("[render-ssr] Returned body is ".concat(Buffer.byteLength(u,"utf8")," bytes")),e.body=u}))).apply(this,arguments)}e.use((function(e){return l.apply(this,arguments)}))}function cr(e){return e?e/1e6:0}function ur(e){return e?e/1e6:0}function sr(){return{name:"SysCheck",cronTime:"0,15,30,45 * * * *",onTick:(e,r)=>{var t,o,n,i;t=e.logger,o=Math.round(cr(Z.freemem()),2),n=Math.round(cr(Z.totalmem()),2),(i=Math.round(100*o/n,2))>80?t.error("[cron][".concat(d("SysCheck"),"] RAM ").concat(s(o)," MB used of ").concat(p(n)," MB (").concat(s(i)," %)")):t.info("[cron][".concat(d("SysCheck"),"] RAM ").concat(s(o)," MB used of ").concat(p(n)," MB (").concat(s(i)," %)")),Q.check("/",(function(e,r){var o=Math.round(ur(r.used),2),n=Math.round(ur(r.total),2),i=Math.round(ur(r.free),2);i<1?t.error("[cron][".concat(d("SysCheck"),"] DISK ").concat(s(o)," GB used of ").concat(p(n)," GB (").concat(s(i)," GB free)")):t.info("[cron][".concat(d("SysCheck"),"] DISK ").concat(s(o)," GB used of ").concat(p(n)," GB (").concat(s(i)," GB free)"))}))},start:!0}}function dr(e,r){var t=e.context.miolo,o=t.logger,n=[sr(),{name:"IPsum",cronTime:"0 0 * * *",onTick:(e,r)=>{Ee(e.config.http.ratelimit.ipsum_folder||Se,(r=>{e.logger.debug("[cron][".concat(d("IPsum"),"] File downloaded. ").concat(p(r.length)," ips will be ").concat(s("blacklisted"),"!"))}),e.logger)},start:!0},...r||[]],i=[];n.map((e=>{var r=e.name,o=function(e,r){var t,o=e.logger,n=null!=r&&null!==(t=r.onTick)&&void 0!==t&&t.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 * * * *",(t=>{try{o.silly("[cron][Custom Job ".concat(d(i),"] ").concat(g("ticks!"))),r.onTick(e,t)}catch(n){o.error("[cron][Custom Job ".concat(d(i),"] Error at onTick()")),o.error(n)}}),(()=>{if(o.silly("[cron][Custom Job ".concat(d(i),"] ").concat(g("completed!"))),null!=r&&r.onComplete)try{r.onComplete(e)}catch(t){o.error("[cron][Custom Job ".concat(d(i),"] Error at onComplete()")),o.error(t)}}),!1,(null==r?void 0:r.timezone)||"Europe/Madrid")}(t,e);i.push({name:r,job:o,running:!1})}));var a=e=>{var r;return(r="number"==typeof e?i[e]:i.filter((r=>r.name==e))[0])||o.error("[cron] Job ".concat(d(e)," Not Found")),r},l=e=>{try{return e.job.start(),e.running=!0,o.debug("[cron][Job ".concat(d(e.name),"] ").concat(g("started!"))),1}catch(r){return o.error("[cron][Job ".concat(d(e.name),"] Error starting it")),o.error(r),0}},c=e=>{try{return e.job.stop(),e.running=!1,o.debug("[cron][Job ".concat(d(e.name),"] ").concat(y("stopped!"))),1}catch(r){return o.error("[cron][Job ".concat(d(e.name),"] Error stopping it")),o.error(r),0}};return e.cron={jobs:i,start_one:e=>{var r=a(e);return r?[l(r),r.name]:[0,""]},start:()=>{try{var e=[],r=[];i.map((t=>{1==l(t)?e.push(t.name):r.push(t.name)})),e.length>0&&o.info("[cron] Started ".concat(e.length," jobs: ").concat(e)),r.length>0&&o.warn("[cron] Could not start ".concat(r.length," jobs: ").concat(r))}catch(t){o.error("[cron] start() error: ".concat(t))}},stop_one:e=>{var r=a(e);return r?[c(r),r.name]:[0,""]},stop:()=>{try{var e=[],r=[];i.map((t=>{1==c(t)?e.push(t.name):r.push(t.name)})),e.length>0&&o.info("[cron] Stopped ".concat(e.length," jobs: ").concat(e)),r.length>0&&o.warn("[cron] Could not stop ".concat(r.length," jobs: ").concat(r))}catch(t){o.error("[cron] stop() error: ".concat(t))}}},e}function fr(e,r){var t,o=e.context.miolo.logger,n=function(){var t=ee((function*(){try{var t,n,i;if(null!=(null===(t=e.http)||void 0===t?void 0:t.server))return void o.warn("[http][start] Server already running on ".concat(null==e||null===(n=e.http)||void 0===n?void 0:n.hostname,":").concat(null==e||null===(i=e.http)||void 0===i?void 0:i.port));var a=R.createServer(e.callback()),l=X({server:a}),c=function(){var t=ee((function*(){try{yield l.terminate(),delete e.http.server,o.info("[http][stop] miolo has been shutdowned from ".concat(r.hostname,":").concat(r.port))}catch(t){o.error("[http][stop] error: ".concat(t))}}));return function(){return t.apply(this,arguments)}}();e.http.server=a,e.http.stop=c,yield((e,r,t)=>new Promise(((o,n)=>{e.listen(r,t,(e=>{e?n(e):o()}))})))(a,r.port,r.hostname),o.info("[http][start] miolo is listening on ".concat(r.hostname,":").concat(r.port))}catch(u){o.error("[http][start] error: ".concat(u))}}));return function(){return t.apply(this,arguments)}}();return e.http={server:void 0,start:n,stop:(t=ee((function*(){o.warn("[http] stop() stop() function still not attached. Is server running?")})),function(){return t.apply(this,arguments)}),hostname:r.hostname,port:r.port},e}function vr(t,o){var n,i,a,l=new e,u=function(e){var t,o=r(le,e);return o.auth_type=function(e){var r,t,o;return null!=e&&null!==(r=e.auth)&&void 0!==r&&r.basic?"basic":null!=e&&null!==(t=e.auth)&&void 0!==t&&t.credentials?"credentials":null!=e&&null!==(o=e.auth)&&void 0!==o&&o.custom?"custom":"guest"}(e),o.use_catcher=!(null==o||null===(t=o.http)||void 0===t||!t.catcher_url),o}(t);we(l,u),Ve(l,u.http),(e=>{e.use(N({filter:function(e){return"application/json"==e||"text/html"==e},gzip:{flush:P.Z_SYNC_FLUSH},deflate:{flush:P.Z_SYNC_FLUSH},br:!1})),e.use(C(q({formLimit:"100mb",jsonLimit:"100mb",bufferLimit:"100mb"})))})(l),function(e){var r=e.context.miolo.logger;function t(){return(t=ee((function*(e){if(e){if(!(e instanceof Error)){var t=e;if("object"==typeof e)try{t=JSON.stringify(e)}catch(a){}var o=new Error("non-error thrown: "+t);e&&(e.name&&(o.name=e.name),e.message&&(o.message=e.message),e.stack&&(o.stack=e.stack),e.status&&(o.status=e.status),e.headers&&(o.headers=e.headers)),e=o}(this.headerSent||!this.writable)&&(e.headerSent=!0),this.app.emit("error",e,this),"ENOENT"===e.code&&(e.status=404);var n=e.status||400;this.accepts(["text","json","html"])?"number"==typeof e.status&&R.STATUS_CODES[e.status]||(e.status=500):(n=406,e.message="Unsupported type"),this.status=n;var i=this.headers["x-real-ip"]||this.headers["x-orig-ip"]||this.ip||"127.0.0.1";xe.indexOf(n)>=0?r.warn("[".concat(i,"] ").concat(this.method," ").concat(this.url," - ").concat(n,": ").concat(e.message)):r.error(e),e.headerSent?r.warn("headers were already sent, returning early"):(this.type="json",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 t.apply(this,arguments)}}(l),function(e,r){var t=e.context.miolo,o=je(null==r?void 0:r.ipsum_folder,void 0,t.logger),n={driver:"memory",db:new Map,id:e=>e.request.ip,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 t=(null==r?void 0:r.whitelist_ips)||[];return!!t&&t.indexOf(e.request.ip)>=0}),blacklist:(null==r?void 0:r.blacklist)||(e=>{var t=e.request.ip,n=[...o,...qe,...(null==r?void 0:r.blacklist_ips)||[]].indexOf(t)>=0;return n&&e.miolo.logger.debug("Rejecting ".concat(s("blacklisted")," ").concat(f(t))),n})};e.use(I(n))}(l,null===(n=u.http)||void 0===n?void 0:n.ratelimit),((e,r)=>{var{favicon:t,folders:o}=r,n=t||Pe;for(var[i,a]of(e.context.miolo.logger.debug("[static] Serving favicon from ".concat(n.replace(Re,""))),e.use(F(n)),Object.entries(o)))e.context.miolo.logger.debug("[static] Mounting static folder ".concat(i," => ").concat(a.replace(Re,""))),e.use(J(i,L(a,{index:!1})))})(l,null===(i=u.http)||void 0===i?void 0:i.static),function(e,r){var t=function(){var e=ee((function*(e,r){return{}}));return function(r,t){return e.apply(this,arguments)}}(),o=function(){var e=ee((function*(e,r,t){}));return function(r,t,o){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)||t,onDone:(null==r?void 0:r.onDone)||o,geoip:(null==r?void 0:r.geoip)||{enabled:!1}};function i(){return(i=ee((function*(e,r){var t,o,i,a,l,u,v=e.miolo.logger,h=(e=>{var r=[e.headers["x-real-ip"],e.headers["x-orig-ip"],e.ip,"127.0.0.1"];for(var t of r)if(/^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test(t))return t})(e),g=T.now();e.request.body=oe(oe({},e.request.fields),e.request.files),Le.total+=1,Le[h]=(Le[h]||0)+1,e.requestId=Le.total,e.request.ip=h;var y=!0===(null==n||null===(t=n.geoip)||void 0===t?void 0:t.enabled),b={};y&&(b=Je(h,n.geoip,v)),e.request.geoip=b;var _=e.request.url.indexOf("?")>=0?e.request.url.substr(0,e.request.url.indexOf("?")):e.request.url,w=y?!0===(null===(o=b)||void 0===o?void 0:o.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,")"):"":"",x="".concat(f(h)).concat(w," ").concat(d(e.request.method)," ").concat(d(_)," [").concat(m(Le[h]),"/").concat(m(e.requestId),"]"),S=null!=e.request.body?JSON.stringify(e.request.body):"";v.info("".concat(x," - START")),v.debug("".concat(x," - Body: ").concat(S));var k=yield n.onStart(e,{started:g,description:"pending"});yield r();var O=null==e||null===(u=e.session)||void 0===u?void 0:u.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 j,q=e.response.status,C=q;200==q?j=p:q>200&&q<=299?(j=s,e.response.redirected&&e.response.url&&(C+=" -> ".concat(e.response.url))):j=c;var N="[".concat(j(C),"]"),P=parseFloat((T.now()-g)/1e3).toFixed(2),R=P<n.lazy?p:P<n.slow?s:c,I=P<n.lazy?"Ok":P<n.slow?"lazy":"slow",M=null!=e.session?JSON.stringify(e.session):"";v.debug("".concat(x," - Session: ").concat(M.slice(0,150),"...")),v.silly("".concat(x," - Session: ").concat(M));var J=null!=e.body?JSON.stringify(e.body):"";v.debug("".concat(x," - Response: ").concat(J.slice(0,150),"...")),v.silly("".concat(x," - Response: ").concat(J)),yield n.onDone(e,k,{started:g,elapsed:P,description:I}),v.info("".concat(x," - DONE ").concat(N).concat(E," (").concat(R(I),": ").concat(R(P),")"))}))).apply(this,arguments)}e.use((function(e,r){return i.apply(this,arguments)}))}(l,null==u||null===(a=u.http)||void 0===a?void 0:a.request),function(e){function r(){return(r=ee((function*(e){e.body=Ae}))).apply(this,arguments)}var t=new U;t.get("/robots.txt",(function(e){return r.apply(this,arguments)})),e.use(t.routes())}(l),u.use_catcher&&function(e,r){function t(){return t=ee((function*(e){var{error:r,warning:t,path:o,agent:n}=e.request.body,i=e.miolo.logger;if(t){var a="".concat(s("[JS Warning]")," on ").concat(h(o),": ").concat(JSON.stringify(t.msg),"\n")+"".concat(s("[JS Warning]")," File => ").concat(t.file,"\n")+"".concat(s("[JS Warning]")," Line => ").concat(t.line,"\n")+"".concat(s("[JS Warning]")," Col => ").concat(t.col,"\n")+"".concat(s("[JS Warning]")," Error => ").concat(JSON.stringify(t.error),"\n")+"".concat(s("[JS Warning]")," Agent => ").concat(n);i.warn(a)}else{var l="".concat(c("[JS Error]")," on ").concat(h(o),": ").concat(JSON.stringify(r.msg),"\n")+"".concat(c("[JS Error]")," File => ").concat(r.file,"\n")+"".concat(c("[JS Error]")," Line => ").concat(r.line,"\n")+"".concat(c("[JS Error]")," Col => ").concat(r.col,"\n")+"".concat(c("[JS Error]")," Error => ").concat(JSON.stringify(r.error),"\n")+"".concat(c("[JS Error]")," Agent => ").concat(n);i.error(l)}e.body={result:1}})),t.apply(this,arguments)}var o=new U;o.post(r,(function(e){return t.apply(this,arguments)})),e.use(o.routes())}(l,u.http.catcher_url),"guest"==u.auth_type&&Ue(l,u.auth.guest,null==u?void 0:u.session),"basic"==u.auth_type&&ze(l,u.auth.basic),"credentials"==u.auth_type&&Ye(l,u.auth.credentials,null==u?void 0:u.session,null==u?void 0:u.cache),"custom"==u.auth_type&&((e,r)=>{var t=e.context.miolo.logger;try{var o=r(e);if("function"==typeof o)e.use(o);else if(Array.isArray(o)){var n=new U;o.map((e=>{var r=e.method.toLowerCase();n[r](e.url,e.callback)})),e.use(n.routes())}}catch(i){t.error("Custom auth error: ".concat(i,"'"))}})(l,u.auth.custom);var v=null==u?void 0:u.middlewares;return v&&((e,r)=>{null!=r&&0!=r.length&&r.map((r=>{e.use(r)}))})(l,v),null!=u&&u.routes&&or(l,u.routes),null!=(null==o?void 0:o.middleware)?l.use(o.middleware):lr(l,o,u.http,null==u?void 0:u.auth,null==u||u.socket),dr(l,null==u?void 0:u.cron),fr(l,null==u?void 0:u.http),l.start=ee((function*(){yield l.context.miolo.db.init_connection(),yield l.http.start(),l.cron.start()})),l.stop=ee((function*(){l.context.miolo.db.drop_connections(),yield l.http.stop(),l.cron.stop()})),l.restart=ee((function*(){yield l.stop(),yield l.start()})),l}export{vr as miolo,ce as miolo_emailer,pe as miolo_logger,he as miolo_parser};
@@ -1,5 +1,5 @@
1
1
  /**
2
- * miolo v1.0.0
2
+ * miolo v1.0.1
3
3
  *
4
4
  * https://www.afialapis.com/os/miolo
5
5
  *
@@ -1813,9 +1813,11 @@ function init_request_middleware(app, config) {
1813
1813
  var tcolor = elapsed < reqConfig.lazy ? green : elapsed < reqConfig.slow ? yellow : red;
1814
1814
  var tname = elapsed < reqConfig.lazy ? 'Ok' : elapsed < reqConfig.slow ? 'lazy' : 'slow';
1815
1815
  var ssession = ctx.session != undefined ? JSON.stringify(ctx.session) : '';
1816
- logger.debug("".concat(sreq, " - Session: ").concat(ssession));
1816
+ logger.debug("".concat(sreq, " - Session: ").concat(ssession.slice(0, 150), "..."));
1817
+ logger.silly("".concat(sreq, " - Session: ").concat(ssession));
1817
1818
  var rbody = ctx.body != undefined ? JSON.stringify(ctx.body) : '';
1818
- logger.debug("".concat(sreq, " - Response: ").concat(rbody));
1819
+ logger.debug("".concat(sreq, " - Response: ").concat(rbody.slice(0, 150), "..."));
1820
+ logger.silly("".concat(sreq, " - Response: ").concat(rbody));
1819
1821
  yield reqConfig.onDone(ctx, begin_result, {
1820
1822
  started,
1821
1823
  elapsed,