miolo 3.0.0-beta.21 → 3.0.0-beta.210

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 (246) hide show
  1. package/bin/build/build.mjs +53 -0
  2. package/bin/build/build_bin.mjs +17 -0
  3. package/bin/build/cli/client.mjs +52 -0
  4. package/bin/build/cli/css.mjs +22 -0
  5. package/bin/build/cli/index.mjs +40 -0
  6. package/bin/build/cli/ssr.mjs +21 -0
  7. package/bin/build/server/aliases.mjs +112 -0
  8. package/bin/build/server/babel.config.js +24 -0
  9. package/bin/build/server/banner.mjs +20 -0
  10. package/bin/build/server/bundle.mjs +111 -0
  11. package/bin/build/server/fix.mjs +15 -0
  12. package/bin/build/server/index.mjs +69 -0
  13. package/bin/build/server/options.mjs +83 -0
  14. package/bin/create/auth.mjs +23 -0
  15. package/bin/create/copy.mjs +175 -0
  16. package/bin/create/docker.mjs +25 -0
  17. package/bin/create/index.mjs +137 -0
  18. package/bin/create/pkgjson.mjs +72 -0
  19. package/bin/create/prepare-template.mjs +158 -0
  20. package/bin/create/validation.mjs +27 -0
  21. package/bin/dev/dev.mjs +32 -23
  22. package/bin/dev/dev_start.mjs +6 -5
  23. package/bin/index.mjs +94 -52
  24. package/bin/prod-bin/create-bin.mjs +42 -27
  25. package/bin/prod-bin/run.mjs +13 -9
  26. package/bin/{prod-run → run}/pid.mjs +4 -4
  27. package/bin/run/restart.mjs +13 -0
  28. package/bin/run/start.mjs +18 -0
  29. package/bin/run/stop.mjs +20 -0
  30. package/bin/util.mjs +35 -11
  31. package/package.json +59 -39
  32. package/src/config/.env +34 -12
  33. package/src/config/defaults.mjs +253 -185
  34. package/src/config/env.mjs +40 -22
  35. package/src/config/index.mjs +19 -24
  36. package/src/config/util.mjs +25 -10
  37. package/src/db-conn.mjs +34 -0
  38. package/src/engines/cron/emails.mjs +10 -5
  39. package/src/engines/cron/index.mjs +45 -51
  40. package/src/engines/cron/init.mjs +16 -17
  41. package/src/engines/cron/ipsum.mjs +65 -60
  42. package/src/engines/cron/syscheck.mjs +30 -30
  43. package/src/engines/emailer/index.mjs +1 -2
  44. package/src/engines/emailer/queue.mjs +14 -20
  45. package/src/engines/emailer/transporter.mjs +86 -74
  46. package/src/engines/geoip/index.mjs +23 -28
  47. package/src/engines/http/index.mjs +26 -15
  48. package/src/engines/logger/buildErrorEmailBody.mjs +72 -0
  49. package/src/engines/logger/index.mjs +114 -122
  50. package/src/engines/logger/injectStackTrace.mjs +59 -0
  51. package/src/engines/logger/logger_mail.mjs +47 -61
  52. package/src/engines/logger/reopenTransportOnHupSignal.mjs +12 -13
  53. package/src/engines/parser/Parser.mjs +77 -60
  54. package/src/engines/parser/index.mjs +1 -1
  55. package/src/engines/schema/diffObjs.mjs +41 -0
  56. package/src/engines/schema/index.mjs +4 -0
  57. package/src/engines/schema/input.mjs +54 -0
  58. package/src/engines/schema/output.mjs +66 -0
  59. package/src/engines/socket/index.mjs +44 -46
  60. package/src/index.mjs +15 -10
  61. package/src/middleware/auth/basic.mjs +41 -40
  62. package/src/middleware/auth/custom.mjs +10 -13
  63. package/src/middleware/auth/guest.mjs +27 -27
  64. package/src/middleware/auth/passport/index.mjs +374 -0
  65. package/src/middleware/auth/passport/session/index.mjs +43 -0
  66. package/src/middleware/auth/{credentials → passport}/session/store.mjs +35 -15
  67. package/src/middleware/auth/passport/session/store_koa_redis.mjs +3 -0
  68. package/src/middleware/context/cache/index.mjs +78 -33
  69. package/src/middleware/context/cache/options.mjs +19 -21
  70. package/src/middleware/context/db.mjs +45 -20
  71. package/src/middleware/context/index.mjs +12 -12
  72. package/src/middleware/extra.mjs +4 -5
  73. package/src/middleware/http/body.mjs +25 -25
  74. package/src/middleware/http/catcher.mjs +81 -8
  75. package/src/middleware/http/custom_blacklist.mjs +19 -16
  76. package/src/middleware/http/headers.mjs +37 -34
  77. package/src/middleware/http/ratelimit.mjs +16 -23
  78. package/src/middleware/http/request.mjs +60 -65
  79. package/src/middleware/routes/catch_js_error.mjs +30 -23
  80. package/src/middleware/routes/robots.mjs +4 -7
  81. package/src/middleware/routes/router/crud/attachCrudRoutes.mjs +108 -90
  82. package/src/middleware/routes/router/crud/getCrudConfig.mjs +31 -55
  83. package/src/middleware/routes/router/defaults.mjs +6 -19
  84. package/src/middleware/routes/router/index.mjs +17 -21
  85. package/src/middleware/routes/router/queries/attachQueriesRoutes.mjs +227 -50
  86. package/src/middleware/routes/router/queries/getQueriesConfig.mjs +45 -55
  87. package/src/middleware/routes/router/utils.mjs +41 -26
  88. package/src/middleware/ssr/context.mjs +5 -7
  89. package/src/middleware/ssr/html.mjs +66 -43
  90. package/src/middleware/ssr/loader.mjs +11 -14
  91. package/src/middleware/ssr/ssr_render.mjs +39 -22
  92. package/src/middleware/static/index.mjs +33 -14
  93. package/src/middleware/vite/devserver.mjs +38 -22
  94. package/src/middleware/vite/watcher.mjs +12 -14
  95. package/src/server-cron.mjs +13 -8
  96. package/src/server-dev.mjs +13 -16
  97. package/src/server.mjs +49 -51
  98. package/template/.agent/skills/miolo-app-arch/SKILL.md +218 -0
  99. package/template/.agent/skills/miolo-auth/SKILL.md +450 -0
  100. package/template/.agent/skills/miolo-cli-router/SKILL.md +394 -0
  101. package/template/.agent/skills/miolo-database/SKILL.md +358 -0
  102. package/template/.agent/skills/miolo-react-patterns/SKILL.md +426 -0
  103. package/template/.agent/skills/miolo-routing/SKILL.md +326 -0
  104. package/template/.agent/skills/miolo-schemas/SKILL.md +329 -0
  105. package/template/.agent/skills/miolo-session-context/SKILL.md +397 -0
  106. package/template/.agent/skills/miolo-ssr/SKILL.md +433 -0
  107. package/template/.editorconfig +18 -0
  108. package/template/.env +120 -0
  109. package/template/biome.json +63 -0
  110. package/template/components.json +21 -0
  111. package/template/db/init.sh +89 -0
  112. package/template/db/sql/00_drop.sql +2 -0
  113. package/template/db/sql/01_users.sql +31 -0
  114. package/template/db/sql/02_todos.sql +20 -0
  115. package/template/docker/Dockerfile +13 -0
  116. package/template/docker/docker-compose.yaml +79 -0
  117. package/template/gitignore +42 -0
  118. package/template/jsconfig.json +18 -0
  119. package/template/package.json +88 -0
  120. package/template/postcss.config.js +9 -0
  121. package/template/src/cli/App.jsx +25 -0
  122. package/template/src/cli/components/JsonTreeViewer.jsx +128 -0
  123. package/template/src/cli/components/shadcn-io/spinner/index.jsx +232 -0
  124. package/template/src/cli/components/stepper.jsx +408 -0
  125. package/template/src/cli/components/ui/avatar.jsx +36 -0
  126. package/template/src/cli/components/ui/badge.jsx +31 -0
  127. package/template/src/cli/components/ui/breadcrumb.jsx +97 -0
  128. package/template/src/cli/components/ui/card.jsx +73 -0
  129. package/template/src/cli/components/ui/collapsible.jsx +16 -0
  130. package/template/src/cli/components/ui/dropdown-menu.jsx +179 -0
  131. package/template/src/cli/components/ui/field.jsx +217 -0
  132. package/template/src/cli/components/ui/input.jsx +19 -0
  133. package/template/src/cli/components/ui/label.jsx +17 -0
  134. package/template/src/cli/components/ui/pagination.jsx +99 -0
  135. package/template/src/cli/components/ui/patched/alert.jsx +56 -0
  136. package/template/src/cli/components/ui/patched/button.jsx +45 -0
  137. package/template/src/cli/components/ui/patched/dialog.jsx +114 -0
  138. package/template/src/cli/components/ui/patched/sidebar.jsx +660 -0
  139. package/template/src/cli/components/ui/select.jsx +141 -0
  140. package/template/src/cli/components/ui/separator.jsx +21 -0
  141. package/template/src/cli/components/ui/sheet.jsx +115 -0
  142. package/template/src/cli/components/ui/skeleton.jsx +13 -0
  143. package/template/src/cli/components/ui/sonner.jsx +22 -0
  144. package/template/src/cli/components/ui/switch.jsx +25 -0
  145. package/template/src/cli/components/ui/table.jsx +88 -0
  146. package/template/src/cli/components/ui/textarea.jsx +16 -0
  147. package/template/src/cli/components/ui/tooltip.jsx +45 -0
  148. package/template/src/cli/config/store_keys.mjs +2 -0
  149. package/template/src/cli/context/data/DataContext.jsx +5 -0
  150. package/template/src/cli/context/data/DataProvider.jsx +44 -0
  151. package/template/src/cli/context/data/useBreads.mjs +15 -0
  152. package/template/src/cli/context/data/useDataContext.mjs +4 -0
  153. package/template/src/cli/context/session/SessionContext.mjs +4 -0
  154. package/template/src/cli/context/session/SessionProvider.jsx +31 -0
  155. package/template/src/cli/context/session/makePermissioner.mjs +34 -0
  156. package/template/src/cli/context/session/useSessionContext.mjs +6 -0
  157. package/template/src/cli/context/theme/ThemeContext.mjs +4 -0
  158. package/template/src/cli/context/theme/ThemeProvider.jsx +49 -0
  159. package/template/src/cli/context/theme/useThemeContext.mjs +6 -0
  160. package/template/src/cli/context/ui/UIContext.jsx +5 -0
  161. package/template/src/cli/context/ui/UIProvider.jsx +16 -0
  162. package/template/src/cli/context/ui/useUIContext.mjs +4 -0
  163. package/template/src/cli/context/util.mjs +17 -0
  164. package/template/src/cli/entry-cli.jsx +33 -0
  165. package/template/src/cli/hooks/useIsMobile.mjs +19 -0
  166. package/template/src/cli/hooks/useStoragedState.mjs +63 -0
  167. package/template/src/cli/index.html +29 -0
  168. package/template/src/cli/layout/app-sidebar.jsx +25 -0
  169. package/template/src/cli/layout/main-layout.jsx +63 -0
  170. package/template/src/cli/layout/nav-last-todos.jsx +72 -0
  171. package/template/src/cli/layout/nav-main.jsx +39 -0
  172. package/template/src/cli/layout/nav-user.jsx +105 -0
  173. package/template/src/cli/layout/prop-switcher.jsx +93 -0
  174. package/template/src/cli/lib/utils.mjs +10 -0
  175. package/template/src/cli/pages/Index.jsx +13 -0
  176. package/template/src/cli/pages/IndexOffline.jsx +13 -0
  177. package/template/src/cli/pages/IndexOnline.jsx +18 -0
  178. package/template/src/cli/pages/dash/Dashboard.jsx +29 -0
  179. package/template/src/cli/pages/offline/Login.jsx +43 -0
  180. package/template/src/cli/pages/offline/LoginForm.jsx +115 -0
  181. package/template/src/cli/pages/security/Security.jsx +39 -0
  182. package/template/src/cli/pages/security/SecurityForm.jsx +106 -0
  183. package/template/src/cli/pages/todos/TodoActions.jsx +99 -0
  184. package/template/src/cli/pages/todos/TodoAdd.jsx +43 -0
  185. package/template/src/cli/pages/todos/TodoList.jsx +60 -0
  186. package/template/src/cli/pages/todos/Todos.jsx +23 -0
  187. package/template/src/cli/pages/todos/context/TodosContext.jsx +5 -0
  188. package/template/src/cli/pages/todos/context/TodosProvider.jsx +191 -0
  189. package/template/src/cli/pages/todos/context/useTodosContext.mjs +4 -0
  190. package/template/src/ns/models/Todo.mjs +29 -0
  191. package/template/src/ns/models/TodoList.mjs +8 -0
  192. package/template/src/ns/models/User.mjs +40 -0
  193. package/template/src/server/bot/check_today.mjs +10 -0
  194. package/template/src/server/io/cache/base.mjs +21 -0
  195. package/template/src/server/io/db/filter.mjs +92 -0
  196. package/template/src/server/io/db/todos/delete.mjs +29 -0
  197. package/template/src/server/io/db/todos/find.mjs +13 -0
  198. package/template/src/server/io/db/todos/read.mjs +83 -0
  199. package/template/src/server/io/db/todos/toggle.mjs +37 -0
  200. package/template/src/server/io/db/todos/upsave.mjs +32 -0
  201. package/template/src/server/io/db/triggers/user.mjs +13 -0
  202. package/template/src/server/io/db/users/auth.mjs +132 -0
  203. package/template/src/server/io/db/users/pwd.mjs +38 -0
  204. package/template/src/server/io/db/users/save.mjs +17 -0
  205. package/template/src/server/miolo/auth/basic.mjs +15 -0
  206. package/template/src/server/miolo/auth/guest.mjs +3 -0
  207. package/template/src/server/miolo/auth/passport.mjs +73 -0
  208. package/template/src/server/miolo/cache.mjs +11 -0
  209. package/template/src/server/miolo/cron/foo.mjs +7 -0
  210. package/template/src/server/miolo/cron/index.mjs +28 -0
  211. package/template/src/server/miolo/cron/invalidate.mjs +21 -0
  212. package/template/src/server/miolo/db.mjs +36 -0
  213. package/template/src/server/miolo/http.mjs +14 -0
  214. package/template/src/server/miolo/index.mjs +43 -0
  215. package/template/src/server/miolo/routes/crud.mjs +16 -0
  216. package/template/src/server/miolo/routes/index.mjs +8 -0
  217. package/template/src/server/miolo/ssr/entry-server.jsx +13 -0
  218. package/template/src/server/miolo/ssr/loader.mjs +18 -0
  219. package/template/src/server/routes/index.mjs +66 -0
  220. package/template/src/server/routes/todos/mod.mjs +52 -0
  221. package/template/src/server/routes/todos/read.mjs +45 -0
  222. package/template/src/server/routes/todos/special.mjs +47 -0
  223. package/template/src/server/routes/users/user.mjs +54 -0
  224. package/template/src/server/server.mjs +10 -0
  225. package/template/src/server/utils/crypt.mjs +38 -0
  226. package/template/src/server/utils/io.mjs +15 -0
  227. package/template/src/server/utils/pwdfor.mjs +25 -0
  228. package/template/src/server/utils/schema.mjs +22 -0
  229. package/template/src/static/img/default/profile.png +0 -0
  230. package/template/src/static/img/favicon.ico +0 -0
  231. package/template/src/static/img/miolo_logo.png +0 -0
  232. package/template/src/static/img/miolo_name.png +0 -0
  233. package/template/src/static/public/manifest.json +21 -0
  234. package/template/src/static/public/sw.js +79 -0
  235. package/template/src/static/style/globals.css +156 -0
  236. package/template/src/static/style/json-tree.css +54 -0
  237. package/template/src/static/style/skeleton.css +49 -0
  238. package/bin/prod-build/build-client.mjs +0 -67
  239. package/bin/prod-build/build-server.mjs +0 -58
  240. package/bin/prod-run/restart.mjs +0 -9
  241. package/bin/prod-run/start.mjs +0 -15
  242. package/bin/prod-run/stop.mjs +0 -20
  243. package/src/engines/logger/verify.mjs +0 -22
  244. package/src/middleware/auth/credentials/index.mjs +0 -151
  245. package/src/middleware/auth/credentials/session/index.mjs +0 -24
  246. package/src/middleware/auth/credentials/session/store_koa_redis.mjs +0 -3
@@ -1,6 +1,7 @@
1
- import path from 'path'
2
- const SESSION_MAX_AGE = 86400 * 10 * 1000
1
+ import path from "node:path"
3
2
 
3
+ const SESSION_MAX_AGE = 86400 * 10 * 1000
4
+ const root = (dir) => path.resolve(process.cwd(), dir)
4
5
 
5
6
  //
6
7
  // Notice `miolo` has support for `.env` files
@@ -8,124 +9,144 @@ const SESSION_MAX_AGE = 86400 * 10 * 1000
8
9
  // and set the variables you want to use.
9
10
  // Then you can configure miolo using process.env.WHATEVER.
10
11
 
11
-
12
12
  export default function make_config_defaults() {
13
-
14
13
  return {
15
- name: process.env.MIOLO_NAME || 'miolo',
14
+ name: process.env.MIOLO_NAME || "miolo",
16
15
  http: {
17
16
  port: process.env?.MIOLO_PORT || 8001,
18
- hostname: process.env?.IS_DOCKER === "true"
19
- ? '0.0.0.0'
20
- : process.env?.MIOLO_HOSTNAME || 'localhost',
17
+ hostname:
18
+ process.env?.IS_DOCKER === "true"
19
+ ? process.env?.MIOLO_HOSTNAME_DOCKER || "0.0.0.0"
20
+ : process.env?.MIOLO_HOSTNAME || "localhost",
21
+
22
+ ssl: undefined,
23
+ //ssl: {
24
+ // key: fs.readFileSync('.../key.pem'),
25
+ // cert: fs.readFileSync('.../cert.pem'),
26
+ // }
27
+
28
+ catcher_url: "/sys/jserror",
21
29
 
22
- catcher_url: '/sys/jserror',
23
-
24
30
  static: {
25
- favicon: '',
26
- folders: {}
31
+ favicon: root("src/static/img/favicon.ico"),
32
+ headers: {
33
+ "/sw.js": {
34
+ "Cache-Control": "no-store, no-cache, must-revalidate, proxy-revalidate, max-age=0"
35
+ }
36
+ //"/index.html": { "Cache-Control": "no-cache, max-age=0" },
37
+ //"/": { "Cache-Control": "no-cache, max-age=0" }
38
+ },
39
+ folders: {
40
+ "/build": root("build"),
41
+ "/static": root("src/static"),
42
+ "/": root("src/static/public")
43
+ }
27
44
  },
28
-
45
+
29
46
  // cors can be:
30
47
  // - false
31
48
  // - simple (just assign Access-Control-Allow-Origin='*' and Access-Control-Expose-Headers='SourceMap,X-SourceMap'
32
49
  // - true enable @koa/cors
33
50
  // - {options} enable @koa/cors and use the custom options
34
51
  //
35
- cors: process.env.MIOLO_HTTP_CORS==='true'
36
- ? true
37
- : process.env.MIOLO_HTTP_CORS==='simple'
38
- ? 'simple'
39
- : false,
52
+ cors:
53
+ process.env.MIOLO_HTTP_CORS === "true"
54
+ ? true
55
+ : process.env.MIOLO_HTTP_CORS === "simple"
56
+ ? "simple"
57
+ : false,
40
58
 
41
59
  // proxy can be:
42
60
  // - false
43
61
  // - true enable koa-proxies and use default options
44
62
  // - {options} enable koa-proxies and use the custom options
45
- proxy: process.env.MIOLO_HTTP_PROXY==='true',
63
+ proxy: process.env.MIOLO_HTTP_PROXY === "true",
46
64
 
47
65
  ratelimit: {
48
- /* eslint-disable no-unused-vars */
49
- max: parseInt(process.env.MIOLO_RATELIMIT_MAX || 1000),
50
- duration: parseInt(process.env.MIOLO_RATELIMIT_DURATION || 60 * 1000), // miliseconds
51
- errorMessage: 'Rate Limit reached',
66
+ max: parseInt(process.env.MIOLO_RATELIMIT_MAX || 1000, 10),
67
+ duration: parseInt(process.env.MIOLO_RATELIMIT_DURATION || 60 * 1000, 10), // miliseconds
68
+ errorMessage: "Rate Limit reached",
52
69
  //whitelist: (ctx) => false,
53
70
  //blacklist: (ctx) => false,
54
- whitelist_ips: process.env.MIOLO_RATELIMIT_WHITELIST_IPS?.split(',') || [],
55
- blacklist_ips: process.env.MIOLO_RATELIMIT_BLACKLIST_IPS?.split(',') || [],
56
- ipsum_folder: '/var/ipsum' // https://github.com/stamparm/ipsum
71
+ whitelist_ips: process.env.MIOLO_RATELIMIT_WHITELIST_IPS?.split(",") || [],
72
+ blacklist_ips: process.env.MIOLO_RATELIMIT_BLACKLIST_IPS?.split(",") || [],
73
+ ipsum_folder: "/var/ipsum" // https://github.com/stamparm/ipsum
57
74
  },
58
75
 
59
76
  request: {
60
- lazy: parseInt(process.env.MIOLO_REQUEST_LAZY || 1), // seconds to consider lazy a request
61
- slow: parseInt(process.env.MIOLO_REQUEST_SLOW || 2), // seconds to consider slow a request
77
+ lazy: parseInt(process.env.MIOLO_REQUEST_LAZY || 1, 10), // seconds to consider lazy a request
78
+ slow: parseInt(process.env.MIOLO_REQUEST_SLOW || 2, 10), // seconds to consider slow a request
62
79
  onStart: undefined,
63
80
  // (ctx, times) => { return begin_result}
64
81
  onDone: undefined,
65
82
  // (ctx, begin_result, times) => {},
66
83
  geoip: {
67
- enabled: process.env.MIOLO_GEOIP_ENABLED==='true',
84
+ enabled: process.env.MIOLO_GEOIP_ENABLED === "true",
68
85
  db: process.env.MIOLO_GEOIP_DB,
69
- local_ips: process.env.MIOLO_GEOIP_LOCAL_IPS?.split(',') || [
70
- '127.0.0.1'
71
- ]
86
+ local_ips: process.env.MIOLO_GEOIP_LOCAL_IPS?.split(",") || ["127.0.0.1"]
72
87
  }
73
88
  }
74
-
75
89
  },
76
90
  session: {
77
- salt: process.env.MIOLO_SESSION_SALT || 'SUPER_SALTY_YES?',
78
- secret: process.env.MIOLO_SESSION_SECRET || 'SUPER_SECRET_KEY_KERE',
91
+ salt: process.env.MIOLO_SESSION_SALT || "SUPER_SALTY_YES?",
92
+ secret: process.env.MIOLO_SESSION_SECRET || "SUPER_SECRET_KEY_KERE",
79
93
  options: {
94
+ /** (string) cookie key (default is koa.sess) */
95
+ key: process.env.MIOLO_SESSION_KEY || `${process.env.MIOLO_NAME || "koa"}.sess`,
80
96
  /** (number || 'session') maxAge in ms (default is 1 days) */
81
97
  /** 'session' will result in a cookie that expires when session/browser is closed */
82
98
  /** Warning: If a session cookie is stolen, this cookie will never expire */
83
- maxAge: parseInt(process.env.MIOLO_SESSION_MAX_AGE || SESSION_MAX_AGE),
84
-
99
+ maxAge: parseInt(process.env.MIOLO_SESSION_MAX_AGE || SESSION_MAX_AGE, 10),
100
+
85
101
  /** (boolean) automatically commit headers (default true) */
86
- //autoCommit: true,
87
-
102
+ //autoCommit: true,
103
+
88
104
  /** (boolean) can overwrite or not (default true) */
89
- //overwrite: true,
90
-
105
+ //overwrite: true,
106
+
91
107
  /** (boolean) httpOnly or not (default true) */
92
- //httpOnly: true,
93
-
108
+ //httpOnly: true,
109
+
94
110
  /** (boolean) signed or not (default true) */
95
- //signed: true,
96
-
111
+ //signed: true,
112
+
97
113
  /** (boolean) Force a session identifier cookie to be set on every response. The expiration is reset to the original maxAge, resetting the expiration countdown. (default is false) */
98
- //rolling: false,
99
-
114
+ //rolling: false,
115
+
100
116
  /** (boolean) renew session when session is nearly expired, so we can always keep user logged in. (default is false)*/
101
- //renew: false,
117
+ renew: process.env?.MIOLO_SESSION_RENEW === "true",
102
118
 
103
119
  /** (boolean) secure cookie*/
104
120
  /** You may want to set it as true in your Production environement,
105
121
  * while false at DEV time.
106
122
  */
107
- secure: process.env?.MIOLO_SESSION_SECURE === 'true',
108
-
123
+ secure: process.env?.MIOLO_SESSION_SECURE === "true",
124
+
109
125
  /** (string) session cookie sameSite options (default null, don't set it) */
110
- sameSite: 'lax', // 'strict',
126
+ /** NOTE: Google Auth requires 'lax' */
127
+ sameSite: process.env.MIOLO_SESSION_SAME_SITE || "lax" // 'strict',
111
128
  }
112
129
  },
113
130
  db: {
114
131
  config: {
115
- dialect: process.env.MIOLO_DB_DIALECT || 'postgres',
116
- host: process.env.MIOLO_DB_HOST || 'localhost',
117
- port: process.env.MIOLO_DB_PORT || 5432,
118
- database: process.env.MIOLO_DB_DATABASE || 'miolo',
119
- user: process.env.MIOLO_DB_USER || 'postgres',
120
- password: process.env.MIOLO_DB_PASSWORD || 'postgres',
121
- // Maximum number of connection in pool
122
- max: parseInt(process.env.MIOLO_DB_POOL_MAX || 5),
123
- // Minimum number of connection in pool
124
- min: parseInt(process.env.MIOLO_DB_POOL_MIN || 0),
125
- // The maximum time, in milliseconds, that a connection can be idle before being released.
126
- // Use with combination of evict for proper working,
127
- // for more details read https://github.com/coopernurse/node-pool/issues/178#issuecomment-327110870,
128
- idleTimeoutMillis: parseInt(process.env.MIOLO_DB_POOL_IDLE_TIMEOUT_MS || 10000),
132
+ dialect: process.env.MIOLO_DB_DIALECT || "postgres",
133
+ host:
134
+ process.env?.IS_DOCKER === "true"
135
+ ? process.env.MIOLO_DB_DOCKER_HOST || "postgres"
136
+ : process.env.MIOLO_DB_HOST || "localhost",
137
+ port: process.env.MIOLO_DB_PORT || 5432,
138
+ database: process.env.MIOLO_DB_DATABASE,
139
+ filename: process.env.MIOLO_DB_FILENAME,
140
+ user: process.env.MIOLO_DB_USER,
141
+ password: process.env.MIOLO_DB_PASSWORD,
142
+ // Maximum number of connection in pool
143
+ max: parseInt(process.env.MIOLO_DB_POOL_MAX || 5, 10),
144
+ // Minimum number of connection in pool
145
+ min: parseInt(process.env.MIOLO_DB_POOL_MIN || 0, 10),
146
+ // The maximum time, in milliseconds, that a connection can be idle before being released.
147
+ // Use with combination of evict for proper working,
148
+ // for more details read https://github.com/coopernurse/node-pool/issues/178#issuecomment-327110870,
149
+ idleTimeoutMillis: parseInt(process.env.MIOLO_DB_POOL_IDLE_TIMEOUT_MS || 10000, 10)
129
150
  },
130
151
  options: {
131
152
  tables: []
@@ -133,28 +154,32 @@ export default function make_config_defaults() {
133
154
  // cache:
134
155
  // Refer to top level cache option
135
156
  // cache: {...}
136
-
157
+
137
158
  // log:
138
159
  // We will pass, on the fly, miolo logger to calustra
139
160
  // But specifying a level here, we can customize the level only for db/calustra actions
140
- // log: 'silly',
161
+ // log: 'silly',
141
162
  }
142
163
  },
143
164
  routes: {
144
165
  bodyField: undefined,
145
-
166
+
146
167
  // auth: {
147
168
  // require: false, // true / false / 'read-only'
148
169
  // action: 'redirect', // 'error'
149
170
  // redirect_url: '/',
150
171
  // error_code: 401
151
- // },
172
+ // },
152
173
  // before: async (ctx) => {return bool} // If bool false, query callback not run
153
- // after : async (ctx, result) => {return modified_result}
154
-
155
- crud: [{
156
- prefix: '',
157
- routes: [/*
174
+ // it can also be an array of functions
175
+ // after : async (ctx, data) => {return modified_data}
176
+ // it can also be an array of functions
177
+
178
+ crud: [
179
+ {
180
+ prefix: "",
181
+ routes: [
182
+ /*
158
183
  name: '',
159
184
  url: '/../..', // default to 'name'
160
185
  mode: 'r/w/rw',
@@ -170,9 +195,12 @@ export default function make_config_defaults() {
170
195
  auth: ...,
171
196
  before: ...,
172
197
  after : ...
173
- */],
174
- }],
175
- queries: [/*
198
+ */
199
+ ]
200
+ }
201
+ ],
202
+ queries: [
203
+ /*
176
204
  {
177
205
  prefix: '',
178
206
  auth: ...,
@@ -183,31 +211,43 @@ export default function make_config_defaults() {
183
211
  {
184
212
  url: '/../..',
185
213
  method: 'GET/POST',
186
- callback: async (ctx) => { ctx.body = result } ,
187
- // or
188
- callback_fn: async (miolo, params) => { return result } ,
214
+ callback: async (ctx, params) => {
215
+ return {ok: true/false, data|error}
216
+ // or:
217
+ // return <anything>
218
+ // and milo will wrap into {ok: true, data: <anything>}
219
+ // or by yourself:
220
+ // ctx.body = {ok: true/false, data|error}
221
+ // (you may want {keep_body: true})
222
+ } ,
189
223
  auth: ...,
190
- before: ...,
191
- after : ...
224
+ before: async (ctx) => { return true/false } or array of functions,
225
+ after : async (ctx, data) => { return data } or array of functions,
226
+ schema: {
227
+ input: a Joi schema for validating input data,
228
+ output: a Joi schema for validating output data,
229
+ }
230
+ keep_body: false by default. If true, miolo wont ensure ctx.body after callback.
192
231
  },
193
232
  ],
194
233
  },
195
- */],
234
+ */
235
+ ]
196
236
  },
197
237
  log: {
198
- level: process.env.MIOLO_LOG_LEVEL || 'debug',
238
+ level: process.env.MIOLO_LOG_LEVEL || "debug",
199
239
  format: {
200
- locale: 'en-GB'
240
+ locale: "en-GB"
201
241
  },
202
242
  console: {
203
- enabled: process.env.MIOLO_LOG_CONSOLE_ENABLED === 'true',
204
- level: process.env.MIOLO_LOG_CONSOLE_LEVEL || process.env.MIOLO_LOG_LEVEL || 'debug',
243
+ enabled: process.env.MIOLO_LOG_CONSOLE_ENABLED === "true",
244
+ level: process.env.MIOLO_LOG_CONSOLE_LEVEL || process.env.MIOLO_LOG_LEVEL || "debug"
205
245
  },
206
246
  file: {
207
- enabled: process.env.MIOLO_LOG_FILE_ENABLED === 'true',
208
- level: process.env.MIOLO_LOG_FILE_LEVEL || process.env.MIOLO_LOG_LEVEL || 'debug',
209
- filename: process.env.MIOLO_LOG_FILE_PATH || '/var/log/afialapis/%MIOLO%.log',
210
-
247
+ enabled: process.env.MIOLO_LOG_FILE_ENABLED === "true",
248
+ level: process.env.MIOLO_LOG_FILE_LEVEL || process.env.MIOLO_LOG_LEVEL || "debug",
249
+ filename: process.env.MIOLO_LOG_FILE_PATH || "/var/log/afialapis/%MIOLO%.log",
250
+
211
251
  //frequency: undefined,
212
252
  //datePattern: 'YYYY-MM-DD',
213
253
  zippedArchive: true,
@@ -226,45 +266,45 @@ export default function make_config_defaults() {
226
266
  hup_patch: false
227
267
  },
228
268
  mail: {
229
- enabled: process.env.MIOLO_LOG_MAIL_ENABLED
230
- ? process.env.MIOLO_LOG_MAIL_ENABLED === 'true'
231
- : false,
232
- level: process.env.MIOLO_LOG_MAIL_LEVEL || process.env.MIOLO_LOG_LEVEL || 'warn',
233
- name: process.env.MIOLO_NAME || 'miolo',
234
- from: process.env.MIOLO_LOG_MAIL_FROM || 'noreply@mail.com',
235
- to: process.env.MIOLO_LOG_MAIL_TO || 'noreply@mail.com'
269
+ enabled: process.env.MIOLO_LOG_MAIL_ENABLED
270
+ ? process.env.MIOLO_LOG_MAIL_ENABLED === "true"
271
+ : false,
272
+ level: process.env.MIOLO_LOG_MAIL_LEVEL || process.env.MIOLO_LOG_LEVEL || "warn",
273
+ name: process.env.MIOLO_NAME || "miolo",
274
+ from: process.env.MIOLO_LOG_MAIL_FROM || "noreply@mail.com",
275
+ to: process.env.MIOLO_LOG_MAIL_TO || "noreply@mail.com"
236
276
  }
237
277
  },
238
278
  mail: {
239
- silent: process.env.MIOLO_MAILER_SILENT === 'true',
279
+ silent: process.env.MIOLO_MAILER_SILENT === "true",
240
280
  options: {
241
281
  //
242
282
  // General options
243
283
  //
244
284
  // port – is the port to connect to (defaults to 587 is secure is false or 465 if true)
245
- port: parseInt(process.env.MIOLO_MAILER_PORT || 25),
285
+ port: parseInt(process.env.MIOLO_MAILER_PORT || 25, 10),
246
286
  // host – is the hostname or IP address to connect to (defaults to ‘localhost’)
247
- host: process.env.MIOLO_MAILER_HOST || 'mail.com',
248
- // auth – defines authentication data
249
- // If authentication data is not present, the connection is considered authenticated from the start.
287
+ host: process.env.MIOLO_MAILER_HOST || "mail.com",
288
+ // auth – defines authentication data
289
+ // If authentication data is not present, the connection is considered authenticated from the start.
250
290
  // Otherwise you would need to provide the authentication options object.
251
291
  // - type indicates the authetication type, defaults to ‘login’, other option is ‘oauth2’
252
292
  // - user is the username
253
293
  // - pass is the password for the user if normal login is used
254
294
  // authMethod – defines preferred authentication method, defaults to ‘PLAIN’
255
- authMethod: process.env.MIOLO_MAILER_AUTH_METHOD || 'PLAIN',
256
- ... process.env.MIOLO_MAILER_AUTH_METHOD === 'LOGIN'
295
+ authMethod: process.env.MIOLO_MAILER_AUTH_METHOD || "PLAIN",
296
+ ...(process.env.MIOLO_MAILER_AUTH_METHOD === "LOGIN"
257
297
  ? {
258
- auth: {
259
- user: process.env.MIOLO_MAILER_SMTP_USER || 'noreply@mail.com',
260
- pass: process.env.MIOLO_MAILER_SMTP_PASS || '****',
261
- type: 'login',
262
- },
263
- secure: true,
264
- }
298
+ auth: {
299
+ user: process.env.MIOLO_MAILER_SMTP_USER || "noreply@mail.com",
300
+ pass: process.env.MIOLO_MAILER_SMTP_PASS || "****",
301
+ type: "login"
302
+ },
303
+ secure: true
304
+ }
265
305
  : {
266
- secure: false
267
- },
306
+ secure: false
307
+ }),
268
308
 
269
309
  //
270
310
  // TLS options
@@ -272,18 +312,17 @@ export default function make_config_defaults() {
272
312
  // secure – if true the connection will use TLS when connecting to server.
273
313
  // If false (the default) then TLS is used if server supports the STARTTLS extension.
274
314
  // In most cases set this value to true if you are connecting to port 465. For port 587 or 25 keep it false
275
- // ** Setting secure to false does not mean that you would not use an encrypted connection. Most SMTP servers allow
315
+ // ** Setting secure to false does not mean that you would not use an encrypted connection. Most SMTP servers allow
276
316
  // connection upgrade via STARTTLS command but to use this you have to connect using plaintext first
277
-
278
-
317
+
279
318
  // tls – defines additional node.js TLSSocket options to be passed to the socket constructor, eg. {rejectUnauthorized: true}.
280
319
  tls: {
281
- // do not fail on invalid certs
282
- rejectUnauthorized: false
283
- } ,
320
+ // do not fail on invalid certs
321
+ rejectUnauthorized: false
322
+ },
284
323
  // ignoreTLS – if this is true and secure is false then TLS is not used even if the server supports STARTTLS extension
285
324
  // ** ignoreTLS: false,
286
- // requireTLS – if this is true and secure is false then Nodemailer tries to use STARTTLS even
325
+ // requireTLS – if this is true and secure is false then Nodemailer tries to use STARTTLS even
287
326
  // if the server does not advertise support for it. If the connection can not be encrypted then message is not sent
288
327
  // ** requireTLS: true,
289
328
  //
@@ -302,15 +341,15 @@ export default function make_config_defaults() {
302
341
  //
303
342
  // Debug options
304
343
  //
305
- // logger – optional bunyan compatible logger instance. If set to true then logs to console.
344
+ // logger – optional bunyan compatible logger instance. If set to true then logs to console.
306
345
  // If value is not set or is false then nothing is logged
307
346
  logger: false,
308
347
  // debug – if set to true, then logs SMTP traffic, otherwise logs only transaction events
309
- debug: false,
348
+ debug: false
310
349
  //
311
350
  // Security options
312
351
  //
313
- // disableFileAccess – if true, then does not allow to use files as content.
352
+ // disableFileAccess – if true, then does not allow to use files as content.
314
353
  // Use it when you want to use JSON data from untrusted source as the email.
315
354
  // If an attachment or message node tries to fetch something from a file the sending returns an error
316
355
  ////disableFileAccess: ,
@@ -328,9 +367,9 @@ export default function make_config_defaults() {
328
367
  // Read about proxy support in Nodemailer from here: https://nodemailer.com/smtp/proxies/
329
368
  },
330
369
  defaults: {
331
- name: process.env.MIOLO_NAME || 'miolo',
332
- from: process.env.MIOLO_MAILER_FROM || 'noreply@mail.com',
333
- to: process.env.MIOLO_MAILER_TO || 'noreply@mail.com'
370
+ name: process.env.MIOLO_NAME || "miolo",
371
+ from: process.env.MIOLO_MAILER_FROM || "noreply@mail.com",
372
+ to: process.env.MIOLO_MAILER_TO || "noreply@mail.com"
334
373
  }
335
374
  },
336
375
  auth: {
@@ -339,29 +378,32 @@ export default function make_config_defaults() {
339
378
  // realm: '',
340
379
  // paths: [],
341
380
  //},
342
- //credentials: {
343
- // get_user_id: (user, done, miolo) => done(null, user.id), // default
344
- // find_user_by_id: (id, done, miolo) => done(null, {id: 1}), // ok=> done(null, user) err=> done(error, null)
345
- // local_auth_user: (username, password, done, miolo) => done(null, {id: 1})
346
- // // auth=> done(null, user) noauth=> done(null, false, {message: ''}) err=> done(error, null)
347
- // url_login : '/login',
348
- // url_logout: '/logout',
349
- // url_login_redirect: undefined
350
- // url_logout_redirect: '/'
351
- //}
352
381
  //guest: {
353
382
  // make_guest_token: undefined // (session) => ''
354
383
  //},
355
- //custom: callback,
356
- // here callback receives (app)
357
- // and returns:
358
- // - a middleware function
359
- // or
360
- // - an array like [{
361
- // method: 'GET' // POST,...
362
- // url: '/aa/bb',
363
- // callback: a middleware function
364
- // }, ...]
384
+ //passport: {
385
+ // get_user_id: (user, done, ctx) => done(null, user.id), // default
386
+ // find_user_by_id: (id, done, ctx) => done(null, {id: 1}), // ok=> done(null, user) err=> done(error, null)
387
+ // local_auth_user: (username, password, done, ctx) => done(null, {id: 1})
388
+ // auth => done(null, user)
389
+ // noauth=> done(null, false, {message: ''})
390
+ // err => done(error, null)
391
+ // local_url_login : '/login',
392
+ // local_url_logout: '/logout',
393
+ // local_url_login_redirect: '/
394
+ // local_url_logout_redirect: '/'
395
+ // google_auth_user: (accessToken, refreshToken, profile, done, ctx) => done(null, {id: 1})
396
+ // auth => done(null, user)
397
+ // noauth=> done(null, false, {message: ''})
398
+ // err => done(error, null)
399
+ // google_client_id: 'your-google-client-id',
400
+ // google_client_secret: 'your-google-client-secret',
401
+ // google_url_login : '/auth/google',
402
+ // google_url_callback : '/auth/google/callback',
403
+ // google_url_logout: '/logout',
404
+ // google_url_login_redirect: undefined
405
+ // google_url_logout_redirect: '/'
406
+ //}
365
407
  },
366
408
 
367
409
  middlewares: [
@@ -371,7 +413,7 @@ export default function make_config_defaults() {
371
413
  cron: [
372
414
  // {
373
415
  // name,
374
- // cronTime,
416
+ // cronTime,
375
417
  // onTick: async (miolo, onComplete),
376
418
  // Notice that if task runs too fast, you may see that
377
419
  // onTick is actually never run, but onComplete is.
@@ -388,44 +430,59 @@ export default function make_config_defaults() {
388
430
  // Default options passed to cacheiro for
389
431
  // every other cache
390
432
  default: {
391
- type: 'combined',
433
+ type: process.env.MIOLO_CACHE_TYPE || "combined",
392
434
  redis: {
393
- host: '127.0.0.1',
394
- port: 6379
435
+ host:
436
+ process.env?.IS_DOCKER === "true"
437
+ ? process.env.MIOLO_REDIS_HOSTNAME_DOCKER || "redis"
438
+ : process.env.MIOLO_REDIS_HOSTNAME || "127.0.0.1",
439
+ port: parseInt(process.env.MIOLO_REDIS_PORT || 6379, 10)
395
440
  },
396
- version: parseInt(process.env.MIOLO_CACHE_VERSION || 1),
397
- clean: false,
441
+ version: parseInt(process.env.MIOLO_CACHE_VERSION || 1, 10),
442
+ clean: false
398
443
  },
399
-
444
+
400
445
  // specific cache options for calustra
401
446
  calustra: {
402
- namespace: 'miolo-calustra',
403
- ttl: parseInt(process.env.MIOLO_CACHE_CALUSTRA_TTL || 86400*1000),
404
- version: parseInt(process.env.MIOLO_CACHE_CALUSTRA_VERSION || process.env.MIOLO_CACHE_VERSION || 1)
447
+ namespace: "miolo-calustra",
448
+ ttl: parseInt(process.env.MIOLO_CACHE_CALUSTRA_TTL || 86400 * 1000, 10),
449
+ version: parseInt(
450
+ process.env.MIOLO_CACHE_CALUSTRA_VERSION || process.env.MIOLO_CACHE_VERSION || 1,
451
+ 10
452
+ )
405
453
  },
406
454
 
407
455
  // specific cache options for koa-session
408
456
  session: {
409
- namespace: 'miolo-session',
410
- ttl: parseInt(process.env.MIOLO_CACHE_SESSION_TTL || process.env.MIOLO_SESSION_MAX_AGE || SESSION_MAX_AGE),
411
- version: parseInt(process.env.MIOLO_CACHE_SESSION_VERSION || process.env.MIOLO_CACHE_VERSION || 1)
457
+ namespace: "miolo-session",
458
+ ttl: parseInt(
459
+ process.env.MIOLO_CACHE_SESSION_TTL ||
460
+ process.env.MIOLO_SESSION_MAX_AGE ||
461
+ SESSION_MAX_AGE,
462
+ 10
463
+ ),
464
+ version: parseInt(
465
+ process.env.MIOLO_CACHE_SESSION_VERSION || process.env.MIOLO_CACHE_VERSION || 1,
466
+ 10
467
+ )
412
468
  },
413
-
469
+
414
470
  // custom cache instances
415
471
  // will be inited by miolo, and available through ctx.miolo.cache.get_cache('name')
416
472
  custom: {
417
- // <name>: {options}
473
+ // <name>: {options}
418
474
  }
419
-
420
-
421
475
  },
422
476
 
423
477
  socket: {
424
478
  enabled: false,
479
+ // Auto create rooms based on sessions
480
+ // To be able to do like: app.context.miolo.io.to('user_<id>').emit('ns', newData);
481
+ userRooms: true,
425
482
  cli: {
426
483
  /**
427
- domain: '',
428
- options: {}
484
+ url: '',
485
+ options: {}
429
486
  */
430
487
  }
431
488
  /*
@@ -439,39 +496,50 @@ export default function make_config_defaults() {
439
496
  },
440
497
 
441
498
  build: {
442
-
443
- client: process.env.NODE_ENV === 'production'
444
- ? `${process.env.MIOLO_BUILD_CLIENT_DEST || './dist/cli'}/${process.env.MIOLO_NAME || 'miolo'}.${process.env.MIOLO_BUILD_CLIENT_SUFFIX || 'iife.bundle.min'}.js`
445
- : process.env.MIOLO_BUILD_CLIENT_ENTRY,
446
-
447
- html: process.env.MIOLO_BUILD_HTML_FILE || './src/cli/index.html',
499
+ client:
500
+ process.env.NODE_ENV === "production"
501
+ ? `${process.env.MIOLO_BUILD_CLIENT_DEST || "./build/cli"}/${process.env.MIOLO_NAME || "miolo"}.${process.env.MIOLO_BUILD_CLIENT_SUFFIX || "iife.bundle.min"}.js`
502
+ : process.env.MIOLO_BUILD_CLIENT_ENTRY,
503
+
504
+ html:
505
+ process.env.MIOLO_BUILD_HTML_FILE === "false"
506
+ ? ""
507
+ : process.env.MIOLO_BUILD_HTML_FILE || "./src/cli/index.html",
448
508
 
449
509
  vite: {
450
- base: '/',
451
- root: '',
510
+ base: "/",
511
+ root: "",
452
512
  watch: {
453
513
  // During tests we edit the files too fast and sometimes chokidar
454
514
  // misses change events, so enforce polling for consistency
455
515
  usePolling: true,
456
- interval: 100,
457
- },
516
+ interval: 100
517
+ },
518
+ ssr: {
519
+ noExternal: ["miolo-react"]
520
+ }
458
521
  },
459
-
522
+
460
523
  ssr: {
461
- server: process.env.NODE_ENV === 'production'
462
- ? path.join(process.cwd(), `${process.env.MIOLO_BUILD_SERVER_DEST || './dist/server'}/entry-server.js`)
463
- : process.env.MIOLO_BUILD_SERVER_SSR_ENTRY || './src/server/ssr/entry-server.jsx',
524
+ server:
525
+ process.env.NODE_ENV === "production"
526
+ ? path.join(
527
+ process.cwd(),
528
+ `${process.env.MIOLO_BUILD_SERVER_DEST || "./build/server"}/entry-server.js`
529
+ )
530
+ : process.env.MIOLO_BUILD_SERVER_SSR_ENTRY || "./src/server/ssr/entry-server.jsx"
464
531
  // loader: async (ctx) => {}
465
532
  },
466
533
 
467
534
  dev: {
468
535
  watcher: {
469
- enabled: process.env.MIOLO_DEV_WATCH_ENABLED==='true',
470
- dirs: process.env.MIOLO_DEV_WATCH_DIRS?.split(',')?.map(dir => path.join(process.cwd(), dir)) || [],
471
- },
536
+ enabled: process.env.MIOLO_DEV_WATCH_ENABLED === "true",
537
+ dirs:
538
+ process.env.MIOLO_DEV_WATCH_DIRS?.split(",")?.map((dir) =>
539
+ path.join(process.cwd(), dir)
540
+ ) || []
541
+ }
472
542
  }
473
543
  }
474
544
  }
475
545
  }
476
-
477
-