miolo 0.2.2 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/README.md +34 -1
  2. package/dist/cli/miolo.cli.iife.bundle.js +374 -0
  3. package/dist/cli/miolo.cli.iife.bundle.js.map +1 -0
  4. package/dist/cli/miolo.cli.iife.bundle.min.js +22 -0
  5. package/dist/cli/miolo.cli.iife.js +76 -0
  6. package/dist/cli/miolo.cli.iife.js.map +1 -0
  7. package/dist/cli/miolo.cli.iife.min.js +11 -0
  8. package/dist/cli/miolo.cli.min.mjs +11 -0
  9. package/dist/cli/miolo.cli.mjs +69 -0
  10. package/dist/cli/miolo.cli.mjs.map +1 -0
  11. package/dist/cli/miolo.cli.umd.bundle.js +375 -0
  12. package/dist/cli/miolo.cli.umd.bundle.js.map +1 -0
  13. package/dist/cli/miolo.cli.umd.bundle.min.js +22 -0
  14. package/dist/cli/miolo.cli.umd.js +77 -0
  15. package/dist/cli/miolo.cli.umd.js.map +1 -0
  16. package/dist/cli/miolo.cli.umd.min.js +11 -0
  17. package/dist/cli-react/miolo.cli-react.iife.bundle.js +1690 -0
  18. package/dist/cli-react/miolo.cli-react.iife.bundle.js.map +1 -0
  19. package/dist/cli-react/miolo.cli-react.iife.bundle.min.js +62 -0
  20. package/dist/cli-react/miolo.cli-react.iife.js +531 -0
  21. package/dist/cli-react/miolo.cli-react.iife.js.map +1 -0
  22. package/dist/cli-react/miolo.cli-react.iife.min.js +11 -0
  23. package/dist/cli-react/miolo.cli-react.min.mjs +11 -0
  24. package/dist/cli-react/miolo.cli-react.mjs +187 -0
  25. package/dist/cli-react/miolo.cli-react.mjs.map +1 -0
  26. package/dist/cli-react/miolo.cli-react.umd.bundle.js +1691 -0
  27. package/dist/cli-react/miolo.cli-react.umd.bundle.js.map +1 -0
  28. package/dist/cli-react/miolo.cli-react.umd.bundle.min.js +62 -0
  29. package/dist/cli-react/miolo.cli-react.umd.js +532 -0
  30. package/dist/cli-react/miolo.cli-react.umd.js.map +1 -0
  31. package/dist/cli-react/miolo.cli-react.umd.min.js +11 -0
  32. package/dist/server/miolo.ico +0 -0
  33. package/dist/{miolo.cjs → server/miolo.server.cjs} +320 -208
  34. package/dist/server/miolo.server.min.mjs +11 -0
  35. package/dist/{miolo.mjs → server/miolo.server.mjs} +292 -159
  36. package/dist/server/miolo.server.mjs.map +1 -0
  37. package/dist/{miolo.node.mjs → server/miolo.server.node.mjs} +321 -208
  38. package/dist/static/img/miolo.ico +0 -0
  39. package/dist/static/robots.txt +2 -0
  40. package/logo/favicon/miolo.ico +0 -0
  41. package/logo/favicon/miolo.png +0 -0
  42. package/logo/favicon/miolo_apple.png +0 -0
  43. package/logo/miolo-logo-name_200.png +0 -0
  44. package/package.json +63 -20
  45. package/dist/miolo.min.mjs +0 -11
  46. package/dist/miolo.mjs.map +0 -1
  47. package/lib/cacher/index.cjs +0 -76
  48. package/lib/cacher/verify.cjs +0 -27
  49. package/lib/config/defaults.cjs +0 -287
  50. package/lib/config/index.cjs +0 -12
  51. package/lib/emailer/index.cjs +0 -56
  52. package/lib/emailer/verify.cjs +0 -11
  53. package/lib/index.cjs +0 -40
  54. package/lib/logger/index.cjs +0 -91
  55. package/lib/logger/logger_mail.cjs +0 -56
  56. package/lib/logger/verify.cjs +0 -22
  57. package/lib/server/engines/cron/index.cjs +0 -12
  58. package/lib/server/engines/cron/syscheck.cjs +0 -41
  59. package/lib/server/engines/socket/index.cjs +0 -40
  60. package/lib/server/index.cjs +0 -134
  61. package/lib/server/middleware/auth/basic.cjs +0 -53
  62. package/lib/server/middleware/auth/guest.cjs +0 -72
  63. package/lib/server/middleware/auth/passport.cjs +0 -123
  64. package/lib/server/middleware/body.cjs +0 -50
  65. package/lib/server/middleware/catcher/index.cjs +0 -58
  66. package/lib/server/middleware/context.cjs +0 -23
  67. package/lib/server/middleware/extra.cjs +0 -27
  68. package/lib/server/middleware/headers.cjs +0 -68
  69. package/lib/server/middleware/request.cjs +0 -68
  70. package/lib/server/middleware/session/index.cjs +0 -26
  71. package/lib/server/middleware/session/store.cjs +0 -10
  72. package/lib/server/middleware/static.cjs +0 -25
  73. package/lib/server/routes/catch_js_error.cjs +0 -35
  74. package/lib/server/routes/html_render.cjs +0 -37
  75. package/lib/server/routes/robots.cjs +0 -27
  76. /package/{lib/server/routes → dist/server}/fallback_index.html +0 -0
  77. /package/{lib/server/static → dist/server}/robots.txt +0 -0
  78. /package/{lib/server/static/img/favicon.ico → dist/static/img/afialapis.ico} +0 -0
@@ -0,0 +1,11 @@
1
+ /**
2
+ * miolo v0.3.0
3
+ *
4
+ * Copyright (c) Donato Lorenzo <donato@afialapis.com>
5
+ *
6
+ * This source code is licensed under the MIT license found in the
7
+ * LICENSE.md file in the root directory of this source tree.
8
+ *
9
+ * @license MIT
10
+ */
11
+ import e from"koa";import{initCalustraRouter as t}from"calustra/router";import o from"assign-deep";import r from"node:path";import{fileURLToPath as n}from"node:url";import i from"node:os";import l from"diskspace";import{cyan as a,yellow as s,green as c,uncolor as u,gray as d,magenta as f,red_light as m,red as p,blue as h}from"tinguir";import{CronJob as v}from"cron";import{getConnection as g}from"calustra";export{getConnection}from"calustra";import y from"nodemailer";import b from"node:util";import _,{transports as x,createLogger as S,format as w}from"winston";import E from"@koa/cors";import k from"koa-proxies";import O from"koa-better-body";import R from"koa-convert";import M from"koa-compress";import{constants as j}from"node:zlib";import q from"koa-mount";import C from"koa-static";import L from"koa-favicon";import{performance as P}from"node:perf_hooks";import U from"koa-session";import A from"koa-redis";import T from"@koa/router";import{readFileSync as I}from"node:fs";import N,{useState as z,useEffect as B}from"react";import{StaticRouter as F}from"react-router-dom/server";import{renderToString as J}from"react-dom/server";import V from"jwt-simple";import D from"basic-auth";import G from"koa-passport";import Y from"passport-local";function K(e,t){var o=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),o.push.apply(o,r)}return o}function H(e){for(var t=1;t<arguments.length;t++){var o=null!=arguments[t]?arguments[t]:{};t%2?K(Object(o),!0).forEach((function(t){Z(e,t,o[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(o)):K(Object(o)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(o,t))}))}return e}function W(e,t,o,r,n,i,l){try{var a=e[i](l),s=a.value}catch(c){return void o(c)}a.done?t(s):Promise.resolve(s).then(r,n)}function X(e){return function(){var t=this,o=arguments;return new Promise((function(r,n){var i=e.apply(t,o);function l(e){W(i,r,n,l,a,"next",e)}function a(e){W(i,r,n,l,a,"throw",e)}l(void 0)}))}}function Z(e,t,o){return(t=function(e){var t=function(e,t){if("object"!=typeof e||null===e)return e;var o=e[Symbol.toPrimitive];if(void 0!==o){var r=o.call(e,t||"default");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}(e,"string");return"symbol"==typeof t?t:String(t)}(t))in e?Object.defineProperty(e,t,{value:o,enumerable:!0,configurable:!0,writable:!0}):e[t]=o,e}var Q=n(require("url").pathToFileURL(__filename).toString()),$=r.dirname(Q),ee={name:"miolo",http:{port:8001,hostname:"localhost",static:{favicon:r.resolve($,"../static/img/miolo.ico"),folders:{}},cors:!1,proxy:!1},session:{salt:"SUPER_SALTY_YES?",secret:"SUPER_SECRET_KEY_KERE",options:{maxAge:864e5,secure:!0,sameSite:null}},db:{config:{dialect:"postgres",host:"localhost",port:5432,database:"miolo",user:"postgres",password:"postgres",max:5,min:0,idleTimeoutMillis:1e4},options:{log:"silly",tables:[]}},routes:{bodyField:void 0,getUserId:e=>{try{var t=e.state.user.id;if(null!=t)return t}catch(i){}try{var o=e.user.id;if(null!=o)return o}catch(i){}try{if("guest"==e.user.name){var r=e.user.token;if(null!=r)return r}}catch(i){}var n=e.headers["user-id"];if(null!=n)return n},crud:{prefix:"",routes:[]},queries:void 0},catcher:"/sys/jserror",log:{level:"debug",format:{locale:"en-GB"},console:{enabled:!0,level:"silly"},file:{enabled:!0,level:"silly",filename:"/var/log/afialapis/miolo.log"},mail:{enabled:!1,level:"warn",name:"miolo",from:"miolo@afialapis.com",to:"devel@afialapis.com"}},mail:{silent:!0,options:{port:25,host:"mail.afialapis.com",authMethod:"PLAIN",secure:!1,tls:{rejectUnauthorized:!1},logger:!1,debug:!1},defaults:{name:"miolo",from:"miolo@afialapis.com",to:"devel@afialapis.com"}},auth:{},middlewares:[]};function te(e){var t=function(e){function t(e){return e?e/1e6:0}function o(e){return e?e/1e6:0}return function(){var r=Math.round(t(i.freemem()),2),n=Math.round(t(i.totalmem()),2),u=Math.round(100*r/n,2);u>80?e.error("[SERVER][".concat(a("SysCheck"),"] RAM ").concat(s(r)," MB used of ").concat(c(n)," MB (").concat(s(u)," %)")):e.info("[SERVER][".concat(a("SysCheck"),"] RAM ").concat(s(r)," MB used of ").concat(c(n)," MB (").concat(s(u)," %)")),l.check("/",(function(t,r){var n=Math.round(o(r.used),2),i=Math.round(o(r.total),2),l=Math.round(o(r.free),2);l<1?e.error("[SERVER][".concat(a("SysCheck"),"] DISK ").concat(s(n)," GB used of ").concat(c(i)," GB (").concat(s(l)," GB free)")):e.info("[SERVER][".concat(a("SysCheck"),"] DISK ").concat(s(n)," GB used of ").concat(c(i)," GB (").concat(s(l)," GB free)"))}))}}(e);new v("30 * * * *",t,null,!0,"Europe/Madrid")}var{combine:oe,timestamp:re,_label:ne,printf:ie,errors:le}=w,ae=(e,t)=>{var o,r,n={silly:d,debug:f,verbose:a,info:s,warn:m,error:p},i=ie((t=>{var o,r=n[t.level],i=new Date(t.timestamp).toLocaleString((null==e||null===(o=e.format)||void 0===o?void 0:o.locale)||"en"),l="[miolo] ".concat(r(i)," ").concat(r(t.level)," ").concat(t.message);return t.stack?"".concat(l,"\n").concat(t.stack):l})),l=[];e.console.enabled&&l.push(new x.Console({humanReadableUnhandledException:!0,level:(null==e||null===(o=e.console)||void 0===o?void 0:o.level)||(null==e?void 0:e.level)||"silly",handleExceptions:!0}));e.file.enabled&&l.push(new x.File({filename:e.file.filename,level:(null==e||null===(r=e.file)||void 0===r?void 0:r.level)||(null==e?void 0:e.level)||"info",humanReadableUnhandledException:!0,handleExceptions:!0}));if(e.mail.enabled){var c=function(e,t){var o=function(o){_.Transport.call(this,o),o=o||{},this.level=e.level||"info",this.ename=(null==e?void 0:e.name)||t.defaults.name,this.to=e.to||t.defaults.to,this.from=e.from||t.defaults.from,this.humanReadableUnhandledException=o.humanReadableUnhandledException||!0,this.handleExceptions=o.handleExceptions||!0,this.json=o.json||!1,this.colorize=o.colorize||!1};return b.inherits(o,_.Transport),o.prototype.name="MailerLogger",o.prototype.log=function(o,r){var n=this,i="";try{i=o.message.split("\n")[0]}catch(s){i=o.message.toString()}i=u(i);var l=e.name+": ["+o.level.toUpperCase()+"] "+i,a={from:this.from,to:this.to,subject:l,text:u(o.message)};t.send(a,(function(){n.emit("logged"),r(null,!0)}))},o}(e.mail,t);x.MailerLogger=c,l.push(new x.MailerLogger({humanReadableUnhandledException:!0,handleExceptions:!0}))}return S({level:(null==e?void 0:e.level)||"silly",format:oe(le({stack:!0}),re(),i),transports:l})},se=(e,t)=>{var o=function(e,t){var o=arguments.length>2&&void 0!==arguments[2]&&arguments[2],r=y.createTransport(e,t);return{send:function(e,t){o?(console.info("*********************************"),console.info("This mail will not be send (emailing is disabled):"),console.info(e),console.info("*********************************")):(t||(t=function(e,t){e&&(console.error("NodeMailer error:"),console.error(e)),t&&(console.log("NodeMailer sent mail:"),console.log(t))}),r.sendMail(e,t))},verify:function(){console.info("[miolo][Verify][MAILER] Verifying..."),r.verify((function(e,t){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:e,defaults:t,silent:o}}(t.mail.options,t.mail.defaults),r=ae(t.log,o);t.db.options.log=r;var n={getConnection:()=>g(t.db.config,t.db.options),getModel:e=>g(t.db.config,t.db.options).getModel(e)},i={config:H({},t),emailer:o,logger:r,db:n};function l(){return(l=X((function*(e,t){e.miolo=i,yield t()}))).apply(this,arguments)}e.use((function(e,t){return l.apply(this,arguments)})),e.context.miolo=i},ce=(e,t,o)=>{try{var r=e[t];if(null!=r&&0!=r)return o(r)}catch(n){}},ue=(e,t)=>{var o=e.context.miolo.logger;ce(t,"cors",(t=>{if("simple"==t)o.debug("Setting CORS the simple way"),e.use(function(){var e=X((function*(e,t){e.set("Access-Control-Allow-Origin","*"),e.set("Access-Control-Expose-Headers","SourceMap,X-SourceMap"),yield t()}));return function(t,o){return e.apply(this,arguments)}}());else{var r=(e=>"object"==typeof e?e:{})(t);o.debug("Setting CORS headers for ".concat(JSON.stringify(r))),e.use(E(r))}})),ce(t,"proxy",(t=>{var[r,n]=(e=>{var t,o,r,n;return null==e&&(e={}),[(null===(t=e)||void 0===t?void 0:t.path)||"/",{target:(null===(o=e)||void 0===o?void 0:o.target)||"https://proxy.miolo.com",changeOrigin:null==(null===(r=e)||void 0===r?void 0:r.changeOrigin)||e.changeOrigin,logs:null==(null===(n=e)||void 0===n?void 0:n.logs)||e.logs}]})(t);o.debug("Setting Proxy for ".concat(r," to ").concat(n.target," ")),e.use(k(r,n))}))},de=e=>{e.use(M({filter:function(e){return"application/json"==e||"text/html"==e},gzip:{flush:j.Z_SYNC_FLUSH},deflate:{flush:j.Z_SYNC_FLUSH},br:!1})),e.use(R(O({formLimit:"100mb",jsonLimit:"100mb",bufferLimit:"100mb"})))},fe=[401];var me=n(require("url").pathToFileURL(__filename).toString()),pe=r.dirname(me),he=r.resolve(pe,"./miolo.ico"),ve=(e,t)=>{var{favicon:o,folders:r}=t;for(var[n,i]of(e.use(L(o||he)),Object.entries(r)))e.use(q(n,C(i,{index:!1})))},ge=(e,t)=>{null!=t&&0!=t.length&&t.map((t=>{function o(){return(o=X((function*(e,o){yield t(e),yield o()}))).apply(this,arguments)}e.use((function(e,t){return o.apply(this,arguments)}))}))},ye=1;var be=new A;var _e=n(require("url").pathToFileURL(__filename).toString()),xe=r.dirname(_e),Se=I(r.resolve(xe,"./robots.txt"),"utf8");var we=n(require("url").pathToFileURL(__filename).toString()),Ee=r.dirname(we),ke=I(r.resolve(Ee,"fallback_index.html"),"utf8");function Oe(e,t,o){return Re.apply(this,arguments)}function Re(){return Re=X((function*(r,n,i){var l,u,d,f,m=new e,v=function(e){return o(ee,e)}(r);se(m,v),de(m),function(e){var t=e.context.miolo.logger;function o(){return(o=X((function*(e){if(e){var o=e.status||400;if(this.accepts(["text","json","html"])?"number"!=typeof o&&(o=500):(o=406,e.message="Unsupported type"),fe.indexOf(o)>=0?t.warn("".concat(this.method," ").concat(this.url," - ").concat(o,": ").concat(e.message)):t.error(e),this.headerSent||!this.writable)return t.debug("headers were already sent, returning early"),void(e.headerSent=!0);this.type="json",this.status=o,this.body=JSON.stringify(this.body||"",null,2),this.length=Buffer.byteLength(this.body),this.res.end(this.body)}}))).apply(this,arguments)}e.context.onerror=function(e){return o.apply(this,arguments)}}(m),ve(m,null===(l=v.http)||void 0===l?void 0:l.static),function(e){function t(){return(t=X((function*(e,t){var o=e.miolo.logger;ye+=1,e.requestId=ye,e.request.body=H(H({},e.request.fields),e.request.files);var r=P.now(),n=e.headers["x-real-ip"]||"127.0.0.1";e.request.ip=n,o.info("req begin ".concat(e.requestId," - ip ").concat(n," - ").concat(a(e.request.method)," ").concat(a(e.request.url)," ").concat(null!=e.request.body?JSON.stringify(e.request.body):"")),yield t();var i=void 0;try{null!=e.state.user&&(i=e.state.user)}catch(g){}try{null!=e.user&&(i=e.user)}catch(g){}var l,u,d,f="";if(null!=i)if(null!==(l=i)&&void 0!==l&&l.id)f=" - uid ".concat(null===(d=i)||void 0===d?void 0:d.id);else if(null!==(u=i)&&void 0!==u&&u.token){var m;f=" - token ".concat(null===(m=i)||void 0===m?void 0:m.token)}var h=parseFloat((P.now()-r)/1e3).toFixed(2),v=h<1?c:h<2?s:p;o.info("req end ".concat(e.requestId).concat(f," => ").concat(v("DONE in ".concat(h," seconds"))))}))).apply(this,arguments)}e.use((function(e,o){return t.apply(this,arguments)}))}(m),function(e,t){e.keys=[t.secret||"*secret*"];var o=H({store:be},t.options||{});e.use(U(o,e))}(m,null==v?void 0:v.session),function(e){function t(){return(t=X((function*(e){e.body=Se}))).apply(this,arguments)}var o=new T;o.get("/robots.txt",(function(e){return t.apply(this,arguments)})),e.use(o.routes())}(m);var g=null==v?void 0:v.catcher;if(g&&function(e,t){function o(){return o=X((function*(e){var{error:t,path:o,agent:r}=e.request.body,n=e.miolo.logger,i="".concat(p("[JS Error]")," on ").concat(h(o),": ").concat(t.msg,"\n")+"".concat(p("[JS Error]")," File => ").concat(t.file,"\n")+"".concat(p("[JS Error]")," Line => ").concat(t.line,"\n")+"".concat(p("[JS Error]")," Col => ").concat(t.col,"\n")+"".concat(p("[JS Error]")," Error => ").concat(JSON.stringify(t.error),"\n")+"".concat(p("[JS Error]")," Agent => ").concat(r);n.error(i),e.body={result:1}})),o.apply(this,arguments)}var r=new T;r.post(t,(function(e){return o.apply(this,arguments)})),e.use(r.routes())}(m,g),null!=v&&null!==(u=v.auth)&&void 0!==u&&u.guest){var{init_guest_auth_middleware:y}=yield Promise.resolve().then((function(){return Le}));y(m,v.auth.guest,null==v?void 0:v.session)}if(null!=v&&null!==(d=v.auth)&&void 0!==d&&d.basic){var{init_basic_auth_middleware:b}=yield Promise.resolve().then((function(){return Pe}));b(m,v.auth.basic)}if(null!=v&&null!==(f=v.auth)&&void 0!==f&&f.passport){var{init_passport_auth_middleware:_}=yield Promise.resolve().then((function(){return Ie}));_(m,v.auth.passport)}if(null!=v&&v.routes){var x=m.context.miolo.db.getConnection();t(m,x,v.routes)}var S=null==v?void 0:v.middlewares;return S&&ge(m,S),ue(m,v.http),null==n||null!=n.html?function(e,t){function o(){return(o=X((function*(e){var o=e.miolo.logger,r=e.requestId,n=e.headers["x-real-ip"]||"127.0.0.1",i=e.request.method,l=e.request.url,s=null!=t?"provided html":"fallback page";o.info("".concat(r," - ").concat(n," : ").concat(a(i)," ").concat(a(l)," => Rendering ").concat(s)),e.body=t||ke}))).apply(this,arguments)}var r=new T;r.get("/",(function(e){return o.apply(this,arguments)})),e.use(r.routes())}(m,null==n?void 0:n.html):null!=n.middleware&&m.use(n.middleware),m.listen(v.http.port,v.http.hostname,(function(){m.context.miolo.logger.info("miolo is listening on ".concat(v.http.hostname,":").concat(v.http.port)),te(m.context.miolo.logger),null!=i&&i()})),m})),Re.apply(this,arguments)}var Me=N.createContext(),je=e=>{var{context:t,children:o}=e,[r,n]=z(t);return B((()=>{n(t)}),[t]),N.createElement(Me.Provider,{value:{context:r,setContext:n}},o)},qe=e=>{var{url:t,context:o,children:r}=e;return N.createElement(F,{location:t},N.createElement(je,{context:o},r))};function Ce(e,t,o){var r='\n\t\t<!DOCTYPE html>\n\t\t<html lang="en">\n\t\t<head>\n\t\t\t<meta charset="utf-8">\n\t\t\t<meta http-equiv="X-UA-Compatible" content="IE=edge">\n\t\t\t<title>miolo</title>\n\t\t\t<meta name="viewport" content="width=device-width, initial-scale=1">\n\t\t\t<meta name="description" content="miolo" />\n\t\t\t<meta name="keywords" content="miolo web" />\n\t\t\t<meta name="author" content="miolo.afialapis.com" />\n\n\t\t\t\x3c!-- Touch Icons - iOS and Android 2.1+ 180x180 pixels in size. --\x3e \n\t\t\t\x3c!--<link rel="apple-touch-icon-precomposed" href="/favicon.ico"/>--\x3e\n\t\t\t\x3c!-- Firefox, Chrome, Safari, IE 11+ and Opera. 196x196 pixels in size. --\x3e\n\t\t\t<link rel="icon" href="/favicon.ico"/>\n\n\t\t\t{styles}\n\n\t\t\t<script>\n\t\t\t\twindow.__CONTEXT = {context}\n\t\t\t<\/script>\t\t\n\t\t</head>\n\n\t\t<body>\n\t\t\t<div id="root">{children}</div>\n\t\t\t{bundle}\n\t\t</body>\n\t\t</html>\n ';try{null!=(null==o?void 0:o.html)&&(r=o.html)}catch(c){}try{null!=(null==o?void 0:o.port)&&(isNaN(parseInt(o.port))||parseInt(o.port))}catch(c){}try{!1!==(null==o?void 0:o.css)}catch(c){}var n="",i="",l=e=>{try{return t(e)}catch(o){return e.miolo.logger.error("Missing renderer in the render middleware"),(e=>{var{ctx:t,error:o}=e;return N.createElement("div",null,"[MIOLO-SERVER_TOOLS] Missing SSR renderer: ".concat(o.toString()))})({ctx:e,error:o})}},a=function(){var t=X((function*(t){var o={};try{o=yield e(t)}catch(r){t.miolo.logger.error("Error produced by loader in the render middleware"),t.miolo.logger.error(r)}return o}));return function(e){return t.apply(this,arguments)}}();function s(){return(s=X((function*(e){var t=yield a(e),o=!1;try{o=!0===(null==e?void 0:e.isAuthenticated())}catch(m){}try{o||(o="guest"===e.user.name&&null!=e.user.token)}catch(m){}var s=void 0;try{null!=e.state.user&&(s=e.state.user)}catch(c){}try{null!=e.user&&(s=e.user)}catch(c){}var u={user:s,authenticated:o,ssr_data:t,extra:null==e?void 0:e.extra},d=J(N.createElement(qe,{url:e.url,context:u},(()=>l(e)))),f=r.replace("{context}",JSON.stringify(u,null,2)).replace(/{bundleURL}/g,n).replace("{children}",d).replace("{styles}",i).replace("{bundle}",n);e.body=f}))).apply(this,arguments)}return function(e){return s.apply(this,arguments)}}var Le=Object.freeze({__proto__:null,init_guest_auth_middleware:(e,t,o)=>{var r=e.context.miolo.logger,n=()=>{try{var{make_guest_token:e}=t;if(null!=e)return e(o||{})}catch(n){}return function(e,t){var o=Math.random().toString(),r=null==e?void 0:e.secret;r||(r="miolo_unsafe_secret",t.error("Guest token made with an unsafe secret string. Please, configure your own through session.secret."));var n={admin:!1,buid:o};return V.encode(n,r)}(o||{},r)};function i(){return i=X((function*(e,t){var i=e.cookies.get("token")||e.headers.token;void 0!==i&&0!=i.length||(i=yield n(),r.debug("Guest token conceeded"));var l=function(e){var t,o=null==e||null===(t=e.options)||void 0===t?void 0:t.maxAge;isNaN(o)&&(o=86400);var r=new Date;return r.setSeconds(r.getSeconds()+o),{expires:r,httpOnly:!1}}(o);e.cookies.set("token",i,l),e.user={name:"guest",token:i},yield t()})),i.apply(this,arguments)}e.use((function(e,t){return i.apply(this,arguments)}))}}),Pe=Object.freeze({__proto__:null,init_basic_auth_middleware:(e,t)=>{var{auth_user:o,realm:r,paths:n}=t;function i(e,t){return l.apply(this,arguments)}function l(){return(l=X((function*(e,t){e.user=null;var n=D(e),i=()=>e.throw(401,null,{headers:{"WWW-Authenticate":'Basic realm="'+r.replace(/"/g,'\\"')+'"'}});if(!n)return i();var l=yield o(n.name,n.pass);if(!1===l||null==l)return i();e.user=l,yield t()}))).apply(this,arguments)}r||(r="Secure Area"),null==n||0==n.length?e.use(i):n.map((t=>e.use(q(t,i))))}}),Ue=(e,t,o)=>t(null,e.id),Ae=(e,t,o)=>{t(Error("You need to define auth.passport.find_user_by_id"),null)},Te=(e,t,o,r)=>{o(Error("You need to define auth.passport.local_auth_user"),null)},Ie=Object.freeze({__proto__:null,init_passport_auth_middleware:(e,t)=>{var{get_user_id:o,find_user_by_id:r,local_auth_user:n,url_login:i,url_logout:l,url_login_redirect:a,url_logout_redirect:s}=t,c=o||Ue,u=r||Ae,d=n||Te,f=i||"/login",m=l||"/logout",p=new Y.Strategy(((t,o,r)=>{d(t,o,r,e.context.miolo)}));G.serializeUser(((t,o)=>{process.nextTick((function(){c(t,o,e.context.miolo)}))})),G.deserializeUser(((t,o)=>{process.nextTick((function(){u(t,o,e.context.miolo)}))})),G.use(p),e.use(G.initialize()),e.use(G.session());var h=function(){var e=X((function*(e,t){e.isAuthenticated()?(e.logout(),e.body={success:!0},null!=s&&e.redirect(s)):(e.body={success:!1},e.throw(401))}));return function(t,o){return e.apply(this,arguments)}}(),v=new T;v.post(f,((e,t)=>G.authenticate("local",(function(t,o,r,n){if(!1!==o)return e.body={success:!0,user:o,authenticated:!0},null!=a&&e.redirect(a),e.login(o);e.body={success:!1,user:void 0,authenticated:!1,info:r,error:t},e.throw(401)}))(e))),v.get(m,h),v.post(m,h),e.use(v.routes())}});export{qe as AppSsr,Ce as init_render_middleware,Oe as miolo};