create-nexwire 4.0.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 (488) hide show
  1. package/README.md +233 -0
  2. package/express/.dockerignore +14 -0
  3. package/express/.env +44 -0
  4. package/express/.env.example +42 -0
  5. package/express/.vscode/settings.json +26 -0
  6. package/express/LICENSE +21 -0
  7. package/express/README.md +211 -0
  8. package/express/biome.json +66 -0
  9. package/express/drizzle.config.ts +25 -0
  10. package/express/gitignore-stub +24 -0
  11. package/express/package.json +108 -0
  12. package/express/public/.gitkeep +0 -0
  13. package/express/src/config/app.ts +41 -0
  14. package/express/src/config/auth.ts +12 -0
  15. package/express/src/config/cache.ts +16 -0
  16. package/express/src/config/cookie.ts +15 -0
  17. package/express/src/config/cors.ts +12 -0
  18. package/express/src/config/database.ts +29 -0
  19. package/express/src/config/index.ts +83 -0
  20. package/express/src/config/jwt.ts +19 -0
  21. package/express/src/config/logging.ts +13 -0
  22. package/express/src/config/mail.ts +24 -0
  23. package/express/src/config/openapi.ts +54 -0
  24. package/express/src/config/queue.ts +30 -0
  25. package/express/src/config/rateLimit.ts +17 -0
  26. package/express/src/config/realtime.ts +15 -0
  27. package/express/src/config/redis.ts +18 -0
  28. package/express/src/config/security.ts +44 -0
  29. package/express/src/config/session.ts +17 -0
  30. package/express/src/config/storage.ts +22 -0
  31. package/express/src/config/validate.ts +40 -0
  32. package/express/src/database/migrations/sqlite/0000_init.sql +61 -0
  33. package/express/src/database/migrations/sqlite/meta/0000_snapshot.json +412 -0
  34. package/express/src/database/migrations/sqlite/meta/_journal.json +13 -0
  35. package/express/src/database/schema.ts +3 -0
  36. package/express/src/env.ts +76 -0
  37. package/express/src/framework/cache/cache.ts +81 -0
  38. package/express/src/framework/circuit-breaker/cb.ts +60 -0
  39. package/express/src/framework/database/connection.ts +196 -0
  40. package/express/src/framework/database/migrate-hooks.ts +87 -0
  41. package/express/src/framework/database/paginate.ts +227 -0
  42. package/express/src/framework/database/schema.ts +20 -0
  43. package/express/src/framework/database/seed.ts +139 -0
  44. package/express/src/framework/events/dispatcher.ts +49 -0
  45. package/express/src/framework/facade.ts +48 -0
  46. package/express/src/framework/http/app.ts +107 -0
  47. package/express/src/framework/http/cors.ts +7 -0
  48. package/express/src/framework/http/logger.ts +69 -0
  49. package/express/src/framework/http/metrics.ts +22 -0
  50. package/express/src/framework/http/openapi.ts +54 -0
  51. package/express/src/framework/http/ratelimiter.ts +16 -0
  52. package/express/src/framework/http/router.ts +178 -0
  53. package/express/src/framework/http/security.ts +23 -0
  54. package/express/src/framework/http/static.ts +23 -0
  55. package/express/src/framework/http/validation.ts +18 -0
  56. package/express/src/framework/kernel.ts +52 -0
  57. package/express/src/framework/maker-cli/db/core.mjs +288 -0
  58. package/express/src/framework/maker-cli/db/index.mjs +204 -0
  59. package/express/src/framework/maker-cli/deploy/core.mjs +1047 -0
  60. package/express/src/framework/maker-cli/deploy/index.mjs +91 -0
  61. package/express/src/framework/maker-cli/index.mjs +53 -0
  62. package/express/src/framework/maker-cli/middleware/core.mjs +47 -0
  63. package/express/src/framework/maker-cli/middleware/index.mjs +17 -0
  64. package/express/src/framework/maker-cli/module/core.mjs +684 -0
  65. package/express/src/framework/maker-cli/module/index.mjs +140 -0
  66. package/express/src/framework/maker-cli/runtime/build-ui.mjs +16 -0
  67. package/express/src/framework/maker-cli/runtime/core.mjs +543 -0
  68. package/express/src/framework/maker-cli/runtime/index.mjs +104 -0
  69. package/express/src/framework/maker-cli/runtime/redis-commander-patch.cjs +20 -0
  70. package/express/src/framework/maker-cli/stubs/controller/openapi.ts.stub +47 -0
  71. package/express/src/framework/maker-cli/stubs/controller/openapi.with-model.ts.stub +48 -0
  72. package/express/src/framework/maker-cli/stubs/controller/plain.ts.stub +54 -0
  73. package/express/src/framework/maker-cli/stubs/controller/schema.plain.ts.stub +14 -0
  74. package/express/src/framework/maker-cli/stubs/controller/schema.ts.stub +33 -0
  75. package/express/src/framework/maker-cli/stubs/deploy/Dockerfile.bun.stub +52 -0
  76. package/express/src/framework/maker-cli/stubs/deploy/Dockerfile.pnpm.stub +55 -0
  77. package/express/src/framework/maker-cli/stubs/deploy/Dockerfile.stub +51 -0
  78. package/express/src/framework/maker-cli/stubs/deploy/Dockerfile.yarn.stub +55 -0
  79. package/express/src/framework/maker-cli/stubs/deploy/README.stub +59 -0
  80. package/express/src/framework/maker-cli/stubs/deploy/compose/mysql.server.stub +45 -0
  81. package/express/src/framework/maker-cli/stubs/deploy/compose/postgres.server.stub +45 -0
  82. package/express/src/framework/maker-cli/stubs/deploy/compose/sqlite.stub +45 -0
  83. package/express/src/framework/maker-cli/stubs/deploy/env/mysql.server.stub +68 -0
  84. package/express/src/framework/maker-cli/stubs/deploy/env/postgres.server.stub +68 -0
  85. package/express/src/framework/maker-cli/stubs/deploy/env/sqlite.stub +67 -0
  86. package/express/src/framework/maker-cli/stubs/deploy/scripts/auto-migrate.sh.stub +41 -0
  87. package/express/src/framework/maker-cli/stubs/deploy/server/README.stub +78 -0
  88. package/express/src/framework/maker-cli/stubs/deploy/server/compose/noredis.stub +120 -0
  89. package/express/src/framework/maker-cli/stubs/deploy/server/compose/redis.dev.stub +133 -0
  90. package/express/src/framework/maker-cli/stubs/deploy/server/compose/redis.stub +131 -0
  91. package/express/src/framework/maker-cli/stubs/deploy/server/env/local.example.stub +11 -0
  92. package/express/src/framework/maker-cli/stubs/deploy/server/env/noredis.stub +25 -0
  93. package/express/src/framework/maker-cli/stubs/deploy/server/env/redis.stub +25 -0
  94. package/express/src/framework/maker-cli/stubs/deploy/server/nginx-vhost/README.stub +16 -0
  95. package/express/src/framework/maker-cli/stubs/deploy/server/nginx-vhost/app.example.com.stub +13 -0
  96. package/express/src/framework/maker-cli/stubs/deploy/server/pgadmin/servers.stub +14 -0
  97. package/express/src/framework/maker-cli/stubs/deploy/server/redis/redis.conf.stub +7 -0
  98. package/express/src/framework/maker-cli/stubs/deploy/supervisor/noredis.stub +54 -0
  99. package/express/src/framework/maker-cli/stubs/deploy/supervisor/redis.stub +70 -0
  100. package/express/src/framework/maker-cli/stubs/deploy/workflow/local.json.stub +25 -0
  101. package/express/src/framework/maker-cli/stubs/deploy/workflow/remote.json.stub +24 -0
  102. package/express/src/framework/maker-cli/stubs/example/console.ts.stub +34 -0
  103. package/express/src/framework/maker-cli/stubs/example/controller.ts.stub +418 -0
  104. package/express/src/framework/maker-cli/stubs/example/job.ts.stub +75 -0
  105. package/express/src/framework/maker-cli/stubs/example/route.api.ts.stub +207 -0
  106. package/express/src/framework/maker-cli/stubs/example/route.plain.ts.stub +18 -0
  107. package/express/src/framework/maker-cli/stubs/example/schema.plain.ts.stub +42 -0
  108. package/express/src/framework/maker-cli/stubs/example/schema.ts.stub +42 -0
  109. package/express/src/framework/maker-cli/stubs/job/name.ts.stub +25 -0
  110. package/express/src/framework/maker-cli/stubs/middleware/name.ts.stub +14 -0
  111. package/express/src/framework/maker-cli/stubs/model/name.mysql.ts.stub +9 -0
  112. package/express/src/framework/maker-cli/stubs/model/name.postgresql.ts.stub +9 -0
  113. package/express/src/framework/maker-cli/stubs/model/name.sqlite.ts.stub +9 -0
  114. package/express/src/framework/maker-cli/stubs/notification/controller.ts.stub +77 -0
  115. package/express/src/framework/maker-cli/stubs/notification/job.ts.stub +13 -0
  116. package/express/src/framework/maker-cli/stubs/notification/route.api.ts.stub +50 -0
  117. package/express/src/framework/maker-cli/stubs/notification/route.plain.ts.stub +12 -0
  118. package/express/src/framework/maker-cli/stubs/notification/schema.plain.ts.stub +26 -0
  119. package/express/src/framework/maker-cli/stubs/notification/schema.ts.stub +26 -0
  120. package/express/src/framework/maker-cli/stubs/route/api.ts.stub +80 -0
  121. package/express/src/framework/maker-cli/stubs/route/plain.ts.stub +11 -0
  122. package/express/src/framework/maker-cli/stubs/schedule/name.ts.stub +36 -0
  123. package/express/src/framework/maker-cli/stubs/seeder/name.ts.stub +20 -0
  124. package/express/src/framework/maker-cli/stubs/test/unit.ts.stub +22 -0
  125. package/express/src/framework/maker-cli/utils/env-config.mjs +44 -0
  126. package/express/src/framework/maker-cli/utils/env-db.mjs +61 -0
  127. package/express/src/framework/maker-cli/utils/file-ops.mjs +30 -0
  128. package/express/src/framework/maker-cli/utils/flags.mjs +14 -0
  129. package/express/src/framework/maker-cli/utils/help.mjs +50 -0
  130. package/express/src/framework/maker-cli/utils/naming.mjs +13 -0
  131. package/express/src/framework/maker-cli/utils/process.mjs +52 -0
  132. package/express/src/framework/modules/discover.ts +54 -0
  133. package/express/src/framework/modules/routes.ts +21 -0
  134. package/express/src/framework/notification/index.ts +116 -0
  135. package/express/src/framework/queue/clear.ts +22 -0
  136. package/express/src/framework/queue/queue.ts +342 -0
  137. package/express/src/framework/queue/ui.ts +187 -0
  138. package/express/src/framework/queue/worker.ts +61 -0
  139. package/express/src/framework/realtime/broadcast.ts +46 -0
  140. package/express/src/framework/realtime/index.ts +2 -0
  141. package/express/src/framework/realtime/socket-cookie.ts +71 -0
  142. package/express/src/framework/realtime/socket.ts +119 -0
  143. package/express/src/framework/realtime/types.ts +6 -0
  144. package/express/src/framework/realtime/ui.ts +16 -0
  145. package/express/src/framework/redis/client.ts +151 -0
  146. package/express/src/framework/runtime/runtime.ts +23 -0
  147. package/express/src/framework/runtime/server-adapter.ts +34 -0
  148. package/express/src/framework/scheduler/lock.ts +116 -0
  149. package/express/src/framework/scheduler/run.ts +48 -0
  150. package/express/src/framework/scheduler/scheduler.ts +155 -0
  151. package/express/src/framework/server.ts +177 -0
  152. package/express/src/framework/session/session.ts +98 -0
  153. package/express/src/framework/storage/storage.ts +785 -0
  154. package/express/src/framework/support/cookie.ts +62 -0
  155. package/express/src/framework/support/jwt.ts +33 -0
  156. package/express/src/framework/support/lifecycle.ts +35 -0
  157. package/express/src/framework/support/logger.ts +148 -0
  158. package/express/src/framework/support/mail.ts +48 -0
  159. package/express/src/framework/support/password.ts +23 -0
  160. package/express/src/framework/support/upload.ts +160 -0
  161. package/express/src/framework/support/url.ts +41 -0
  162. package/express/src/middlewares/auth-middleware.ts +98 -0
  163. package/express/src/middlewares/role-middleware.ts +25 -0
  164. package/express/src/modules/auth/controllers/auth.controller.ts +358 -0
  165. package/express/src/modules/auth/controllers/auth.helpers.ts +104 -0
  166. package/express/src/modules/auth/controllers/auth.schema.ts +102 -0
  167. package/express/src/modules/auth/controllers/role.controller.ts +15 -0
  168. package/express/src/modules/auth/database/models/notifications.ts +24 -0
  169. package/express/src/modules/auth/database/models/role.ts +14 -0
  170. package/express/src/modules/auth/database/models/user.ts +46 -0
  171. package/express/src/modules/auth/database/seeders/role.ts +18 -0
  172. package/express/src/modules/auth/database/seeders/user.ts +35 -0
  173. package/express/src/modules/auth/jobs/forgetpass.ts +20 -0
  174. package/express/src/modules/auth/jobs/registeruser.ts +23 -0
  175. package/express/src/modules/auth/jobs/verifyemail.ts +18 -0
  176. package/express/src/modules/auth/routes/api.ts +150 -0
  177. package/express/src/modules/auth/routes/role.ts +33 -0
  178. package/express/src/resources/index.html +17 -0
  179. package/express/src/resources/src/App.vue +5 -0
  180. package/express/src/resources/src/assets/css/styles.css +14761 -0
  181. package/express/src/resources/src/assets/css/styles.css.map +1 -0
  182. package/express/src/resources/src/assets/fonts/public-sans/public-sans-latin-ext.woff2 +0 -0
  183. package/express/src/resources/src/assets/fonts/public-sans/public-sans-latin.woff2 +0 -0
  184. package/express/src/resources/src/assets/images/favicon/favicon.ico +0 -0
  185. package/express/src/resources/src/assets/images/logo.png +0 -0
  186. package/express/src/resources/src/assets/scss/custom.css +217 -0
  187. package/express/src/resources/src/assets/scss/custom.css.map +1 -0
  188. package/express/src/resources/src/assets/scss/custom.scss +1346 -0
  189. package/express/src/resources/src/components/Button.vue +32 -0
  190. package/express/src/resources/src/components/Checkbox.vue +29 -0
  191. package/express/src/resources/src/components/Datepicker.vue +106 -0
  192. package/express/src/resources/src/components/FeatureButton.vue +53 -0
  193. package/express/src/resources/src/components/FloatButton.vue +33 -0
  194. package/express/src/resources/src/components/Href.vue +32 -0
  195. package/express/src/resources/src/components/Input.vue +223 -0
  196. package/express/src/resources/src/components/InputGroup.vue +145 -0
  197. package/express/src/resources/src/components/InputPasswordToggle.vue +213 -0
  198. package/express/src/resources/src/components/Modal.vue +55 -0
  199. package/express/src/resources/src/components/Pagebar.vue +26 -0
  200. package/express/src/resources/src/components/Select.vue +384 -0
  201. package/express/src/resources/src/components/Spinner.vue +42 -0
  202. package/express/src/resources/src/components/Switch.vue +65 -0
  203. package/express/src/resources/src/components/TextArea.vue +117 -0
  204. package/express/src/resources/src/components/Toast.vue +56 -0
  205. package/express/src/resources/src/components/datatable/DataTableSkeleton.vue +98 -0
  206. package/express/src/resources/src/components/datatable/Pagination.vue +147 -0
  207. package/express/src/resources/src/components/datatable/SelectOpption.vue +64 -0
  208. package/express/src/resources/src/components/datatable/index.vue +199 -0
  209. package/express/src/resources/src/composables/useAuth.ts +52 -0
  210. package/express/src/resources/src/helpers/nformatter.ts +10 -0
  211. package/express/src/resources/src/helpers/utils.ts +75 -0
  212. package/express/src/resources/src/layouts/AuthLayout.vue +20 -0
  213. package/express/src/resources/src/layouts/Layout/Footer.vue +23 -0
  214. package/express/src/resources/src/layouts/Layout/Header.vue +105 -0
  215. package/express/src/resources/src/layouts/Layout/Sidebar.vue +137 -0
  216. package/express/src/resources/src/layouts/Layout/index.vue +87 -0
  217. package/express/src/resources/src/main.ts +26 -0
  218. package/express/src/resources/src/pages/auth/forgetPassword.vue +82 -0
  219. package/express/src/resources/src/pages/auth/login.vue +99 -0
  220. package/express/src/resources/src/pages/auth/register.vue +133 -0
  221. package/express/src/resources/src/pages/auth/resetPassword.vue +118 -0
  222. package/express/src/resources/src/pages/auth/verifyEmail.vue +68 -0
  223. package/express/src/resources/src/pages/dashboard/index.vue +66 -0
  224. package/express/src/resources/src/plugins/axios.ts +31 -0
  225. package/express/src/resources/src/plugins/browserDetect.ts +55 -0
  226. package/express/src/resources/src/plugins/dialog.ts +216 -0
  227. package/express/src/resources/src/plugins/gum.ts +367 -0
  228. package/express/src/resources/src/plugins/pulse.ts +147 -0
  229. package/express/src/resources/src/plugins/routeProgress.ts +87 -0
  230. package/express/src/resources/src/router/index.ts +85 -0
  231. package/express/src/resources/src/stores/admin-ui.ts +148 -0
  232. package/express/src/resources/src/stores/auth.ts +164 -0
  233. package/express/src/resources/tsconfig.json +19 -0
  234. package/express/src/resources/vite.config.ts +46 -0
  235. package/express/src/storage/app/private/.gitkeep +0 -0
  236. package/express/src/storage/app/public/.gitkeep +0 -0
  237. package/express/src/storage/app/tmp/generated/.gitkeep +0 -0
  238. package/express/src/storage/database/nexwire.sqlite +0 -0
  239. package/express/src/storage/logs/.gitkeep +0 -0
  240. package/express/src/storage/tmp/.gitkeep +0 -0
  241. package/express/src/storage/trash/modules/.gitkeep +0 -0
  242. package/express/src/types/global.d.ts +26 -0
  243. package/express/tsconfig.json +19 -0
  244. package/express/vitest.config.ts +23 -0
  245. package/hono/.dockerignore +14 -0
  246. package/hono/.env +44 -0
  247. package/hono/.env.example +42 -0
  248. package/hono/.vscode/settings.json +26 -0
  249. package/hono/LICENSE +21 -0
  250. package/hono/README.md +211 -0
  251. package/hono/biome.json +76 -0
  252. package/hono/drizzle.config.ts +25 -0
  253. package/hono/gitignore-stub +24 -0
  254. package/hono/package.json +99 -0
  255. package/hono/public/.gitkeep +0 -0
  256. package/hono/src/config/app.ts +41 -0
  257. package/hono/src/config/auth.ts +12 -0
  258. package/hono/src/config/cache.ts +16 -0
  259. package/hono/src/config/cookie.ts +15 -0
  260. package/hono/src/config/cors.ts +12 -0
  261. package/hono/src/config/database.ts +29 -0
  262. package/hono/src/config/index.ts +83 -0
  263. package/hono/src/config/jwt.ts +19 -0
  264. package/hono/src/config/logging.ts +13 -0
  265. package/hono/src/config/mail.ts +24 -0
  266. package/hono/src/config/openapi.ts +54 -0
  267. package/hono/src/config/queue.ts +30 -0
  268. package/hono/src/config/rateLimit.ts +17 -0
  269. package/hono/src/config/realtime.ts +15 -0
  270. package/hono/src/config/redis.ts +18 -0
  271. package/hono/src/config/security.ts +44 -0
  272. package/hono/src/config/session.ts +17 -0
  273. package/hono/src/config/storage.ts +22 -0
  274. package/hono/src/config/validate.ts +40 -0
  275. package/hono/src/database/migrations/sqlite/0000_init.sql +61 -0
  276. package/hono/src/database/migrations/sqlite/meta/0000_snapshot.json +412 -0
  277. package/hono/src/database/migrations/sqlite/meta/_journal.json +13 -0
  278. package/hono/src/database/schema.ts +3 -0
  279. package/hono/src/env.ts +76 -0
  280. package/hono/src/framework/cache/cache.ts +81 -0
  281. package/hono/src/framework/circuit-breaker/cb.ts +60 -0
  282. package/hono/src/framework/database/connection.ts +196 -0
  283. package/hono/src/framework/database/migrate-hooks.ts +87 -0
  284. package/hono/src/framework/database/paginate.ts +253 -0
  285. package/hono/src/framework/database/schema.ts +20 -0
  286. package/hono/src/framework/database/seed.ts +139 -0
  287. package/hono/src/framework/events/dispatcher.ts +49 -0
  288. package/hono/src/framework/facade.ts +29 -0
  289. package/hono/src/framework/http/app.ts +109 -0
  290. package/hono/src/framework/http/cors.ts +19 -0
  291. package/hono/src/framework/http/logger.ts +81 -0
  292. package/hono/src/framework/http/metrics.ts +22 -0
  293. package/hono/src/framework/http/openapi.ts +42 -0
  294. package/hono/src/framework/http/ratelimiter.ts +172 -0
  295. package/hono/src/framework/http/router.ts +76 -0
  296. package/hono/src/framework/http/security.ts +23 -0
  297. package/hono/src/framework/http/static.ts +70 -0
  298. package/hono/src/framework/http/validation.ts +21 -0
  299. package/hono/src/framework/kernel.ts +48 -0
  300. package/hono/src/framework/maker-cli/db/core.mjs +288 -0
  301. package/hono/src/framework/maker-cli/db/index.mjs +204 -0
  302. package/hono/src/framework/maker-cli/deploy/core.mjs +1038 -0
  303. package/hono/src/framework/maker-cli/deploy/index.mjs +91 -0
  304. package/hono/src/framework/maker-cli/index.mjs +53 -0
  305. package/hono/src/framework/maker-cli/middleware/core.mjs +47 -0
  306. package/hono/src/framework/maker-cli/middleware/index.mjs +12 -0
  307. package/hono/src/framework/maker-cli/module/core.mjs +684 -0
  308. package/hono/src/framework/maker-cli/module/index.mjs +140 -0
  309. package/hono/src/framework/maker-cli/runtime/build-ui.mjs +17 -0
  310. package/hono/src/framework/maker-cli/runtime/core.mjs +543 -0
  311. package/hono/src/framework/maker-cli/runtime/index.mjs +104 -0
  312. package/hono/src/framework/maker-cli/runtime/redis-commander-patch.cjs +20 -0
  313. package/hono/src/framework/maker-cli/stubs/controller/openapi.ts.stub +57 -0
  314. package/hono/src/framework/maker-cli/stubs/controller/openapi.with-model.ts.stub +58 -0
  315. package/hono/src/framework/maker-cli/stubs/controller/plain.ts.stub +59 -0
  316. package/hono/src/framework/maker-cli/stubs/controller/schema.plain.ts.stub +14 -0
  317. package/hono/src/framework/maker-cli/stubs/controller/schema.ts.stub +33 -0
  318. package/hono/src/framework/maker-cli/stubs/deploy/Dockerfile.bun.stub +52 -0
  319. package/hono/src/framework/maker-cli/stubs/deploy/Dockerfile.pnpm.stub +55 -0
  320. package/hono/src/framework/maker-cli/stubs/deploy/Dockerfile.stub +51 -0
  321. package/hono/src/framework/maker-cli/stubs/deploy/Dockerfile.yarn.stub +55 -0
  322. package/hono/src/framework/maker-cli/stubs/deploy/README.stub +59 -0
  323. package/hono/src/framework/maker-cli/stubs/deploy/compose/mysql.server.stub +45 -0
  324. package/hono/src/framework/maker-cli/stubs/deploy/compose/postgres.server.stub +45 -0
  325. package/hono/src/framework/maker-cli/stubs/deploy/compose/sqlite.stub +45 -0
  326. package/hono/src/framework/maker-cli/stubs/deploy/env/mysql.server.stub +68 -0
  327. package/hono/src/framework/maker-cli/stubs/deploy/env/postgres.server.stub +68 -0
  328. package/hono/src/framework/maker-cli/stubs/deploy/env/sqlite.stub +67 -0
  329. package/hono/src/framework/maker-cli/stubs/deploy/scripts/auto-migrate.sh.stub +41 -0
  330. package/hono/src/framework/maker-cli/stubs/deploy/server/README.stub +78 -0
  331. package/hono/src/framework/maker-cli/stubs/deploy/server/compose/noredis.stub +120 -0
  332. package/hono/src/framework/maker-cli/stubs/deploy/server/compose/redis.dev.stub +133 -0
  333. package/hono/src/framework/maker-cli/stubs/deploy/server/compose/redis.stub +131 -0
  334. package/hono/src/framework/maker-cli/stubs/deploy/server/env/local.example.stub +11 -0
  335. package/hono/src/framework/maker-cli/stubs/deploy/server/env/noredis.stub +25 -0
  336. package/hono/src/framework/maker-cli/stubs/deploy/server/env/redis.stub +25 -0
  337. package/hono/src/framework/maker-cli/stubs/deploy/server/nginx-vhost/README.stub +16 -0
  338. package/hono/src/framework/maker-cli/stubs/deploy/server/nginx-vhost/app.example.com.stub +13 -0
  339. package/hono/src/framework/maker-cli/stubs/deploy/server/pgadmin/servers.stub +14 -0
  340. package/hono/src/framework/maker-cli/stubs/deploy/server/redis/redis.conf.stub +7 -0
  341. package/hono/src/framework/maker-cli/stubs/deploy/supervisor/noredis.stub +54 -0
  342. package/hono/src/framework/maker-cli/stubs/deploy/supervisor/redis.stub +70 -0
  343. package/hono/src/framework/maker-cli/stubs/deploy/workflow/local.json.stub +25 -0
  344. package/hono/src/framework/maker-cli/stubs/deploy/workflow/remote.json.stub +24 -0
  345. package/hono/src/framework/maker-cli/stubs/example/console.ts.stub +34 -0
  346. package/hono/src/framework/maker-cli/stubs/example/controller.ts.stub +505 -0
  347. package/hono/src/framework/maker-cli/stubs/example/job.ts.stub +75 -0
  348. package/hono/src/framework/maker-cli/stubs/example/route.api.ts.stub +207 -0
  349. package/hono/src/framework/maker-cli/stubs/example/route.plain.ts.stub +18 -0
  350. package/hono/src/framework/maker-cli/stubs/example/schema.plain.ts.stub +42 -0
  351. package/hono/src/framework/maker-cli/stubs/example/schema.ts.stub +42 -0
  352. package/hono/src/framework/maker-cli/stubs/job/name.ts.stub +25 -0
  353. package/hono/src/framework/maker-cli/stubs/middleware/name.ts.stub +14 -0
  354. package/hono/src/framework/maker-cli/stubs/model/name.mysql.ts.stub +9 -0
  355. package/hono/src/framework/maker-cli/stubs/model/name.postgresql.ts.stub +9 -0
  356. package/hono/src/framework/maker-cli/stubs/model/name.sqlite.ts.stub +9 -0
  357. package/hono/src/framework/maker-cli/stubs/notification/controller.ts.stub +86 -0
  358. package/hono/src/framework/maker-cli/stubs/notification/job.ts.stub +13 -0
  359. package/hono/src/framework/maker-cli/stubs/notification/route.api.ts.stub +50 -0
  360. package/hono/src/framework/maker-cli/stubs/notification/route.plain.ts.stub +12 -0
  361. package/hono/src/framework/maker-cli/stubs/notification/schema.plain.ts.stub +26 -0
  362. package/hono/src/framework/maker-cli/stubs/notification/schema.ts.stub +26 -0
  363. package/hono/src/framework/maker-cli/stubs/route/api.ts.stub +80 -0
  364. package/hono/src/framework/maker-cli/stubs/route/plain.ts.stub +11 -0
  365. package/hono/src/framework/maker-cli/stubs/schedule/name.ts.stub +36 -0
  366. package/hono/src/framework/maker-cli/stubs/seeder/name.ts.stub +20 -0
  367. package/hono/src/framework/maker-cli/stubs/test/unit.ts.stub +22 -0
  368. package/hono/src/framework/maker-cli/utils/env-config.mjs +44 -0
  369. package/hono/src/framework/maker-cli/utils/env-db.mjs +61 -0
  370. package/hono/src/framework/maker-cli/utils/file-ops.mjs +30 -0
  371. package/hono/src/framework/maker-cli/utils/flags.mjs +14 -0
  372. package/hono/src/framework/maker-cli/utils/help.mjs +50 -0
  373. package/hono/src/framework/maker-cli/utils/naming.mjs +13 -0
  374. package/hono/src/framework/maker-cli/utils/process.mjs +52 -0
  375. package/hono/src/framework/modules/discover.ts +54 -0
  376. package/hono/src/framework/modules/routes.ts +24 -0
  377. package/hono/src/framework/notification/index.ts +116 -0
  378. package/hono/src/framework/queue/clear.ts +22 -0
  379. package/hono/src/framework/queue/queue.ts +342 -0
  380. package/hono/src/framework/queue/ui.ts +214 -0
  381. package/hono/src/framework/queue/worker.ts +61 -0
  382. package/hono/src/framework/realtime/broadcast.ts +46 -0
  383. package/hono/src/framework/realtime/index.ts +2 -0
  384. package/hono/src/framework/realtime/socket-cookie.ts +68 -0
  385. package/hono/src/framework/realtime/socket.ts +196 -0
  386. package/hono/src/framework/realtime/types.ts +6 -0
  387. package/hono/src/framework/realtime/ui.ts +16 -0
  388. package/hono/src/framework/redis/client.ts +151 -0
  389. package/hono/src/framework/runtime/runtime.ts +23 -0
  390. package/hono/src/framework/runtime/server-adapter.ts +94 -0
  391. package/hono/src/framework/scheduler/lock.ts +116 -0
  392. package/hono/src/framework/scheduler/run.ts +48 -0
  393. package/hono/src/framework/scheduler/scheduler.ts +155 -0
  394. package/hono/src/framework/server.ts +183 -0
  395. package/hono/src/framework/session/session.ts +116 -0
  396. package/hono/src/framework/storage/storage.ts +785 -0
  397. package/hono/src/framework/support/cookie.ts +99 -0
  398. package/hono/src/framework/support/jwt.ts +45 -0
  399. package/hono/src/framework/support/lifecycle.ts +35 -0
  400. package/hono/src/framework/support/logger.ts +148 -0
  401. package/hono/src/framework/support/mail.ts +48 -0
  402. package/hono/src/framework/support/password.ts +23 -0
  403. package/hono/src/framework/support/url.ts +41 -0
  404. package/hono/src/middlewares/auth-middleware.ts +98 -0
  405. package/hono/src/middlewares/role-middleware.ts +25 -0
  406. package/hono/src/modules/auth/controllers/auth.controller.ts +413 -0
  407. package/hono/src/modules/auth/controllers/auth.helpers.ts +128 -0
  408. package/hono/src/modules/auth/controllers/auth.schema.ts +102 -0
  409. package/hono/src/modules/auth/controllers/role.controller.ts +25 -0
  410. package/hono/src/modules/auth/database/models/notifications.ts +24 -0
  411. package/hono/src/modules/auth/database/models/role.ts +14 -0
  412. package/hono/src/modules/auth/database/models/user.ts +46 -0
  413. package/hono/src/modules/auth/database/seeders/role.ts +18 -0
  414. package/hono/src/modules/auth/database/seeders/user.ts +35 -0
  415. package/hono/src/modules/auth/jobs/forgetpass.ts +20 -0
  416. package/hono/src/modules/auth/jobs/registeruser.ts +23 -0
  417. package/hono/src/modules/auth/jobs/verifyemail.ts +18 -0
  418. package/hono/src/modules/auth/routes/api.ts +150 -0
  419. package/hono/src/modules/auth/routes/role.ts +33 -0
  420. package/hono/src/resources/index.html +17 -0
  421. package/hono/src/resources/src/App.vue +5 -0
  422. package/hono/src/resources/src/assets/css/styles.css +14913 -0
  423. package/hono/src/resources/src/assets/css/styles.css.map +1 -0
  424. package/hono/src/resources/src/assets/fonts/public-sans/public-sans-latin-ext.woff2 +0 -0
  425. package/hono/src/resources/src/assets/fonts/public-sans/public-sans-latin.woff2 +0 -0
  426. package/hono/src/resources/src/assets/images/favicon/favicon.ico +0 -0
  427. package/hono/src/resources/src/assets/images/logo.png +0 -0
  428. package/hono/src/resources/src/assets/scss/custom.css +217 -0
  429. package/hono/src/resources/src/assets/scss/custom.css.map +1 -0
  430. package/hono/src/resources/src/assets/scss/custom.scss +1346 -0
  431. package/hono/src/resources/src/components/Button.vue +32 -0
  432. package/hono/src/resources/src/components/Checkbox.vue +29 -0
  433. package/hono/src/resources/src/components/Datepicker.vue +106 -0
  434. package/hono/src/resources/src/components/FeatureButton.vue +53 -0
  435. package/hono/src/resources/src/components/FloatButton.vue +33 -0
  436. package/hono/src/resources/src/components/Href.vue +32 -0
  437. package/hono/src/resources/src/components/Input.vue +234 -0
  438. package/hono/src/resources/src/components/InputGroup.vue +149 -0
  439. package/hono/src/resources/src/components/InputPasswordToggle.vue +222 -0
  440. package/hono/src/resources/src/components/Modal.vue +55 -0
  441. package/hono/src/resources/src/components/Pagebar.vue +26 -0
  442. package/hono/src/resources/src/components/Select.vue +415 -0
  443. package/hono/src/resources/src/components/Spinner.vue +42 -0
  444. package/hono/src/resources/src/components/Switch.vue +65 -0
  445. package/hono/src/resources/src/components/TextArea.vue +121 -0
  446. package/hono/src/resources/src/components/Toast.vue +56 -0
  447. package/hono/src/resources/src/components/datatable/DataTableSkeleton.vue +98 -0
  448. package/hono/src/resources/src/components/datatable/Pagination.vue +147 -0
  449. package/hono/src/resources/src/components/datatable/SelectOpption.vue +64 -0
  450. package/hono/src/resources/src/components/datatable/index.vue +199 -0
  451. package/hono/src/resources/src/composables/useAuth.ts +52 -0
  452. package/hono/src/resources/src/helpers/nformatter.ts +10 -0
  453. package/hono/src/resources/src/helpers/utils.ts +75 -0
  454. package/hono/src/resources/src/layouts/AuthLayout.vue +20 -0
  455. package/hono/src/resources/src/layouts/Layout/Footer.vue +23 -0
  456. package/hono/src/resources/src/layouts/Layout/Header.vue +105 -0
  457. package/hono/src/resources/src/layouts/Layout/Sidebar.vue +137 -0
  458. package/hono/src/resources/src/layouts/Layout/index.vue +87 -0
  459. package/hono/src/resources/src/main.ts +26 -0
  460. package/hono/src/resources/src/pages/auth/forgetPassword.vue +82 -0
  461. package/hono/src/resources/src/pages/auth/login.vue +99 -0
  462. package/hono/src/resources/src/pages/auth/register.vue +133 -0
  463. package/hono/src/resources/src/pages/auth/resetPassword.vue +118 -0
  464. package/hono/src/resources/src/pages/auth/verifyEmail.vue +68 -0
  465. package/hono/src/resources/src/pages/dashboard/index.vue +66 -0
  466. package/hono/src/resources/src/plugins/axios.ts +31 -0
  467. package/hono/src/resources/src/plugins/browserDetect.ts +55 -0
  468. package/hono/src/resources/src/plugins/dialog.ts +216 -0
  469. package/hono/src/resources/src/plugins/gum.ts +367 -0
  470. package/hono/src/resources/src/plugins/pulse.ts +147 -0
  471. package/hono/src/resources/src/plugins/routeProgress.ts +87 -0
  472. package/hono/src/resources/src/router/index.ts +85 -0
  473. package/hono/src/resources/src/stores/admin-ui.ts +148 -0
  474. package/hono/src/resources/src/stores/auth.ts +164 -0
  475. package/hono/src/resources/tsconfig.json +19 -0
  476. package/hono/src/resources/vite.config.ts +46 -0
  477. package/hono/src/storage/app/private/.gitkeep +0 -0
  478. package/hono/src/storage/app/public/.gitkeep +0 -0
  479. package/hono/src/storage/app/tmp/generated/.gitkeep +0 -0
  480. package/hono/src/storage/database/nexwire.sqlite +0 -0
  481. package/hono/src/storage/logs/.gitkeep +0 -0
  482. package/hono/src/storage/tmp/.gitkeep +0 -0
  483. package/hono/src/storage/trash/modules/.gitkeep +0 -0
  484. package/hono/src/types/global.d.ts +26 -0
  485. package/hono/tsconfig.json +20 -0
  486. package/hono/vitest.config.ts +23 -0
  487. package/package.json +238 -0
  488. package/src/index.js +204 -0
@@ -0,0 +1,358 @@
1
+ import { and, eq, gt, lt } from "drizzle-orm";
2
+ import type { NextFunction, Request, Response } from "express";
3
+ import { authConfig, jwtConfig } from "@/config/index.js";
4
+ import { cookie, db, dispatchEvent, HttpStatusCodes, jwt, password, urls } from "@/framework/facade.js";
5
+ import { roles } from "@/modules/auth/database/models/role.js";
6
+ import { emailVerificationTokens, passwordResetTokens, refreshTokens, users } from "@/modules/auth/database/models/user.js";
7
+ import {
8
+ hashEmailVerificationToken,
9
+ hashResetToken,
10
+ issueTokens,
11
+ makeEmailVerificationToken,
12
+ makeResetToken,
13
+ revokeCurrentRefreshToken,
14
+ sanitizeUser
15
+ } from "./auth.helpers.js";
16
+
17
+ export const register = async (req: Request, res: Response, _next: NextFunction) => {
18
+ try {
19
+ const body = req.body;
20
+ const defaultRole = await db.query.roles.findFirst({
21
+ where: eq(roles.name, "user")
22
+ });
23
+ const existingUser = await db.query.users.findFirst({
24
+ where: eq(users.email, body.email)
25
+ });
26
+
27
+ if (existingUser) {
28
+ return res.status(HttpStatusCodes.UNPROCESSABLE_ENTITY).json({ message: "Email already exists" });
29
+ }
30
+
31
+ const insertResult = await db.insert(users).values({
32
+ name: body.name,
33
+ email: body.email,
34
+ password: await password.hashPassword(body.password),
35
+ roleId: defaultRole?.id ?? null
36
+ });
37
+
38
+ const insertedId = Number(
39
+ (insertResult as any)[0]?.insertId ?? (insertResult as any).insertId ?? (insertResult as any).lastInsertRowid
40
+ );
41
+ if (!insertedId) {
42
+ throw new Error("Failed to resolve inserted user id");
43
+ }
44
+
45
+ const user = await db.query.users.findFirst({
46
+ where: eq(users.id, insertedId),
47
+ with: { role: true }
48
+ });
49
+
50
+ if (!user) throw new Error("Inserted user not found");
51
+
52
+ if (authConfig.requireEmailVerification) {
53
+ const plainToken = makeEmailVerificationToken();
54
+ const expiresAt = new Date(Date.now() + 24 * 60 * 60 * 1000);
55
+
56
+ await db.delete(emailVerificationTokens).where(eq(emailVerificationTokens.email, user.email));
57
+ await db.insert(emailVerificationTokens).values({
58
+ email: user.email,
59
+ token: hashEmailVerificationToken(plainToken),
60
+ expiresAt,
61
+ createdAt: new Date()
62
+ });
63
+
64
+ const verifyUrl = urls.url(`/verify-email?token=${plainToken}&email=${encodeURIComponent(user.email)}`);
65
+ await dispatchEvent("user:verify-email", { email: user.email, name: user.name, verifyUrl }, { queue: "mail" });
66
+
67
+ return res
68
+ .status(HttpStatusCodes.CREATED)
69
+ .json({ message: "User registered successfully. Please verify your email before logging in." });
70
+ }
71
+
72
+ await revokeCurrentRefreshToken(req, res);
73
+ const tokens = await issueTokens(req, res, user, { remember: !!body.remember });
74
+ await dispatchEvent(
75
+ "user:signup",
76
+ {
77
+ userId: user.id,
78
+ email: user.email,
79
+ name: user.name,
80
+ password: body.password
81
+ },
82
+ { queue: "mail" }
83
+ );
84
+
85
+ return res.status(HttpStatusCodes.CREATED).json({
86
+ message: "User registered successfully",
87
+ data: {
88
+ user: sanitizeUser(user),
89
+ access_token: tokens.accessToken,
90
+ refresh_token: tokens.refreshToken,
91
+ token_type: "Bearer"
92
+ }
93
+ });
94
+ } catch (error) {
95
+ console.error("Register error:", error);
96
+ return res.status(HttpStatusCodes.INTERNAL_SERVER_ERROR).json({ message: "Failed to register user" });
97
+ }
98
+ };
99
+
100
+ export const login = async (req: Request, res: Response, _next: NextFunction) => {
101
+ try {
102
+ const body = req.body;
103
+ const user = await db.query.users.findFirst({ where: eq(users.email, body.email), with: { role: true } });
104
+
105
+ if (!user || !(await password.verifyPassword(body.password, user.password))) {
106
+ return res.status(HttpStatusCodes.UNAUTHORIZED).json({ message: "Invalid credentials" });
107
+ }
108
+
109
+ if (authConfig.requireEmailVerification && !user.emailVerifiedAt) {
110
+ return res.status(HttpStatusCodes.FORBIDDEN).json({ message: "Please verify your email before logging in" });
111
+ }
112
+
113
+ await revokeCurrentRefreshToken(req, res);
114
+ const tokens = await issueTokens(req, res, user, { remember: !!body.remember });
115
+
116
+ return res.status(HttpStatusCodes.OK).json({
117
+ message: "User logged in successfully",
118
+ data: {
119
+ user: sanitizeUser(user),
120
+ access_token: tokens.accessToken,
121
+ refresh_token: tokens.refreshToken,
122
+ token_type: "Bearer"
123
+ }
124
+ });
125
+ } catch (error) {
126
+ console.error("Login error:", error);
127
+ return res.status(HttpStatusCodes.INTERNAL_SERVER_ERROR).json({ message: "Failed to login" });
128
+ }
129
+ };
130
+
131
+ export const me = async (_req: Request, res: Response, _next: NextFunction) => {
132
+ try {
133
+ const auth = res.locals.auth as { id: number } | undefined;
134
+ const user = await db.query.users.findFirst({
135
+ where: eq(users.id, auth.id),
136
+ with: { role: true }
137
+ });
138
+
139
+ if (!user) return res.status(HttpStatusCodes.NOT_FOUND).json({ message: "User not found" });
140
+
141
+ return res.status(HttpStatusCodes.OK).json({
142
+ message: "Authenticated user fetched successfully",
143
+ data: sanitizeUser(user)
144
+ });
145
+ } catch (error) {
146
+ console.error("Me error:", error);
147
+ return res.status(HttpStatusCodes.INTERNAL_SERVER_ERROR).json({ message: "Failed to fetch user" });
148
+ }
149
+ };
150
+
151
+ export const logout = async (req: Request, res: Response, _next: NextFunction) => {
152
+ try {
153
+ await revokeCurrentRefreshToken(req, res);
154
+ cookie.deleteAuth(res);
155
+ cookie.deleteRefresh(res);
156
+ return res.status(HttpStatusCodes.OK).json({ message: "Logged out successfully" });
157
+ } catch (error) {
158
+ console.error("Logout error:", error);
159
+ cookie.deleteAuth(res);
160
+ cookie.deleteRefresh(res);
161
+ return res.status(HttpStatusCodes.INTERNAL_SERVER_ERROR).json({ message: "Failed to logout" });
162
+ }
163
+ };
164
+
165
+ export const forgotPassword = async (req: Request, res: Response, _next: NextFunction) => {
166
+ try {
167
+ const body = req.body;
168
+ await db
169
+ .delete(passwordResetTokens)
170
+ .where(and(eq(passwordResetTokens.email, body.email), lt(passwordResetTokens.expiresAt, new Date())));
171
+
172
+ const user = await db.query.users.findFirst({
173
+ where: eq(users.email, body.email)
174
+ });
175
+
176
+ if (!user) return res.status(HttpStatusCodes.OK).json({ message: "Reset link has been sent" });
177
+
178
+ const plainToken = makeResetToken();
179
+ const expiresAt = new Date(Date.now() + 15 * 60 * 1000);
180
+
181
+ await db.delete(passwordResetTokens).where(eq(passwordResetTokens.email, user.email));
182
+ await db.insert(passwordResetTokens).values({
183
+ email: user.email,
184
+ token: hashResetToken(plainToken),
185
+ expiresAt,
186
+ createdAt: new Date()
187
+ });
188
+
189
+ const resetUrl = urls.url(`/reset-password?token=${plainToken}&email=${encodeURIComponent(user.email)}`);
190
+ await dispatchEvent("user:forget-password", { email: user.email, name: user.name, resetUrl }, { queue: "mail" });
191
+
192
+ return res.status(HttpStatusCodes.OK).json({ message: "Reset link passed" });
193
+ } catch (error) {
194
+ console.error("Forgot password error:", error);
195
+ return res.status(HttpStatusCodes.INTERNAL_SERVER_ERROR).json({ message: "Failed to process forgot password request" });
196
+ }
197
+ };
198
+
199
+ export const resetPassword = async (req: Request, res: Response, _next: NextFunction) => {
200
+ try {
201
+ const body = req.body;
202
+ const record = await db.query.passwordResetTokens.findFirst({
203
+ where: and(
204
+ eq(passwordResetTokens.email, body.email),
205
+ eq(passwordResetTokens.token, hashResetToken(body.token)),
206
+ gt(passwordResetTokens.expiresAt, new Date())
207
+ )
208
+ });
209
+
210
+ if (!record) {
211
+ return res.status(HttpStatusCodes.UNPROCESSABLE_ENTITY).json({ message: "Invalid or expired reset token" });
212
+ }
213
+
214
+ await db
215
+ .update(users)
216
+ .set({
217
+ password: await password.hashPassword(body.password),
218
+ updatedAt: new Date()
219
+ })
220
+ .where(eq(users.email, body.email));
221
+
222
+ await db.delete(passwordResetTokens).where(eq(passwordResetTokens.email, body.email));
223
+
224
+ const user = await db.query.users.findFirst({
225
+ where: eq(users.email, body.email)
226
+ });
227
+ if (user) await db.update(refreshTokens).set({ revoked: 1 }).where(eq(refreshTokens.userId, user.id));
228
+
229
+ return res.status(HttpStatusCodes.OK).json({ message: "Password reset successfully" });
230
+ } catch (error) {
231
+ console.error("Reset password error:", error);
232
+ return res.status(HttpStatusCodes.INTERNAL_SERVER_ERROR).json({ message: "Failed to reset password" });
233
+ }
234
+ };
235
+
236
+ export const verifyEmail = async (req: Request, res: Response, _next: NextFunction) => {
237
+ try {
238
+ const body = req.body;
239
+
240
+ if (!authConfig.requireEmailVerification) {
241
+ return res.status(HttpStatusCodes.OK).json({ message: "Email verification is not required" });
242
+ }
243
+
244
+ const record = await db.query.emailVerificationTokens.findFirst({
245
+ where: and(
246
+ eq(emailVerificationTokens.email, body.email),
247
+ eq(emailVerificationTokens.token, hashEmailVerificationToken(body.token)),
248
+ gt(emailVerificationTokens.expiresAt, new Date())
249
+ )
250
+ });
251
+
252
+ if (!record) {
253
+ return res.status(HttpStatusCodes.UNPROCESSABLE_ENTITY).json({ message: "Invalid or expired verification token" });
254
+ }
255
+
256
+ await db.update(users).set({ emailVerifiedAt: new Date(), updatedAt: new Date() }).where(eq(users.email, body.email));
257
+ await db.delete(emailVerificationTokens).where(eq(emailVerificationTokens.email, body.email));
258
+
259
+ return res.status(HttpStatusCodes.OK).json({ message: "Email verified successfully" });
260
+ } catch (error) {
261
+ console.error("Verify email error:", error);
262
+ return res.status(HttpStatusCodes.INTERNAL_SERVER_ERROR).json({ message: "Failed to verify email" });
263
+ }
264
+ };
265
+
266
+ export const refreshToken = async (req: Request, res: Response, _next: NextFunction) => {
267
+ try {
268
+ const body = req.body;
269
+ const payload = await jwt.verifyToken(body.refresh_token, "refresh");
270
+
271
+ if (!payload?.jti) return res.status(HttpStatusCodes.UNAUTHORIZED).json({ message: "Invalid refresh token" });
272
+
273
+ const storedToken = await db.query.refreshTokens.findFirst({
274
+ where: eq(refreshTokens.jti, payload.jti as string)
275
+ });
276
+
277
+ if (!storedToken || storedToken.revoked === 1) {
278
+ return res.status(HttpStatusCodes.UNAUTHORIZED).json({ message: "Refresh token revoked" });
279
+ }
280
+
281
+ if (storedToken.expiresAt.getTime() < Date.now()) {
282
+ await db.delete(refreshTokens).where(eq(refreshTokens.id, storedToken.id));
283
+ return res.status(HttpStatusCodes.UNAUTHORIZED).json({ message: "Refresh token expired" });
284
+ }
285
+
286
+ const user = await db.query.users.findFirst({
287
+ where: eq(users.id, payload.id as number),
288
+ with: { role: true }
289
+ });
290
+ if (!user) return res.status(HttpStatusCodes.UNAUTHORIZED).json({ message: "User not found" });
291
+
292
+ const remember = !!payload.remember;
293
+ const refreshExpiry = remember ? jwtConfig.refreshRememberExpirySeconds : undefined;
294
+ const accessToken = await jwt.generateToken(
295
+ {
296
+ id: user.id,
297
+ email: user.email,
298
+ roleId: user.role?.id,
299
+ role: user.role?.name,
300
+ remember
301
+ },
302
+ "access"
303
+ );
304
+ const newRefreshToken = await jwt.generateToken(
305
+ {
306
+ id: user.id,
307
+ email: user.email,
308
+ roleId: user.role?.id,
309
+ role: user.role?.name,
310
+ remember
311
+ },
312
+ "refresh",
313
+ refreshExpiry
314
+ );
315
+
316
+ await db
317
+ .update(refreshTokens)
318
+ .set({
319
+ jti: newRefreshToken.jti as string,
320
+ expiresAt: new Date(newRefreshToken.exp * 1000),
321
+ revoked: 0
322
+ })
323
+ .where(eq(refreshTokens.id, storedToken.id));
324
+
325
+ await cookie.setAuth(res, accessToken.token);
326
+ await cookie.setRefresh(res, newRefreshToken.token, refreshExpiry);
327
+
328
+ return res.status(HttpStatusCodes.OK).json({
329
+ message: "Token refreshed successfully",
330
+ data: {
331
+ user: sanitizeUser(user),
332
+ access_token: accessToken.token,
333
+ refresh_token: newRefreshToken.token,
334
+ token_type: "Bearer"
335
+ }
336
+ });
337
+ } catch (error) {
338
+ console.error("Refresh token error:", error);
339
+ return res.status(HttpStatusCodes.UNAUTHORIZED).json({ message: "Invalid or expired refresh token" });
340
+ }
341
+ };
342
+
343
+ export const logoutAllDevices = async (_req: Request, res: Response, _next: NextFunction) => {
344
+ try {
345
+ const auth = res.locals.auth as { id: number } | undefined;
346
+
347
+ if (!auth) return res.status(HttpStatusCodes.UNAUTHORIZED).json({ message: "Unauthorized" });
348
+
349
+ await db.delete(refreshTokens).where(eq(refreshTokens.userId, auth.id));
350
+ cookie.deleteAuth(res);
351
+ cookie.deleteRefresh(res);
352
+
353
+ return res.status(HttpStatusCodes.OK).json({ message: "Logged out from all devices successfully" });
354
+ } catch (error) {
355
+ console.error("Logout all devices error:", error);
356
+ return res.status(HttpStatusCodes.INTERNAL_SERVER_ERROR).json({ message: "Failed to logout from all devices" });
357
+ }
358
+ };
@@ -0,0 +1,104 @@
1
+ import { createHash, randomBytes } from "node:crypto";
2
+ import { eq } from "drizzle-orm";
3
+ import type { Request, Response } from "express";
4
+ import { jwtConfig } from "@/config/index.js";
5
+ import { cookie, db, jwt } from "@/framework/facade.js";
6
+ import { refreshTokens } from "@/modules/auth/database/models/user.js";
7
+ import { users } from "@/modules/auth/database/models/user.js";
8
+
9
+ export function hasRole(auth: any, rolesToMatch: string[]) {
10
+ const role = String(auth?.role || "").toLowerCase();
11
+ return rolesToMatch.includes(role);
12
+ }
13
+
14
+ export async function getCurrentUser(auth: any) {
15
+ if (!auth?.id) return null;
16
+ return db.query.users.findFirst({
17
+ where: eq(users.id, Number(auth.id)),
18
+ with: { role: true },
19
+ columns: {
20
+ password: false,
21
+ rememberToken: false,
22
+ }
23
+ });
24
+ }
25
+
26
+ export function sanitizeUser(user: any) {
27
+ return {
28
+ id: user.id,
29
+ name: user.name,
30
+ email: user.email,
31
+ emailVerifiedAt: user.emailVerifiedAt ? String(user.emailVerifiedAt) : null,
32
+ roleId: user.roleId ?? null,
33
+ role: user.role || null,
34
+ createdAt: user.createdAt ? String(user.createdAt) : null,
35
+ updatedAt: user.updatedAt ? String(user.updatedAt) : null
36
+ };
37
+ }
38
+
39
+ export function makeResetToken() {
40
+ return randomBytes(32).toString("hex");
41
+ }
42
+
43
+ export function makeEmailVerificationToken() {
44
+ return randomBytes(32).toString("hex");
45
+ }
46
+
47
+ export function hashResetToken(token: string) {
48
+ return createHash("sha256").update(token).digest("hex");
49
+ }
50
+
51
+ export function hashEmailVerificationToken(token: string) {
52
+ return createHash("sha256").update(token).digest("hex");
53
+ }
54
+
55
+ export async function revokeCurrentRefreshToken(req: Request, _res: Response) {
56
+ const token = await cookie.getRefresh(req);
57
+ if (!token) return;
58
+
59
+ const payload = await jwt.verifyToken(token, "refresh");
60
+ if (payload?.jti) {
61
+ await db.delete(refreshTokens).where(eq(refreshTokens.jti, payload.jti as string));
62
+ }
63
+ }
64
+
65
+ export async function issueTokens(_req: Request, res: Response, user: any, options?: { remember?: boolean; }) {
66
+ const remember = !!options?.remember;
67
+ const refreshExpiry = remember ? jwtConfig.refreshRememberExpirySeconds : jwtConfig.refreshExpirySeconds;
68
+ const role = user.role || null;
69
+ const accessToken = await jwt.generateToken(
70
+ {
71
+ id: user.id,
72
+ email: user.email,
73
+ roleId: role?.id ?? null,
74
+ role: role?.name ?? null,
75
+ remember
76
+ },
77
+ "access"
78
+ );
79
+ const refreshToken = await jwt.generateToken(
80
+ {
81
+ id: user.id,
82
+ email: user.email,
83
+ roleId: role?.id ?? null,
84
+ role: role?.name ?? null,
85
+ remember
86
+ },
87
+ "refresh",
88
+ refreshExpiry
89
+ );
90
+
91
+ if (refreshToken.jti) {
92
+ await db.insert(refreshTokens).values({
93
+ userId: user.id,
94
+ jti: refreshToken.jti,
95
+ revoked: 0,
96
+ expiresAt: new Date(refreshToken.exp * 1000)
97
+ });
98
+ }
99
+
100
+ await cookie.setAuth(res, accessToken.token);
101
+ await cookie.setRefresh(res, refreshToken.token, refreshExpiry);
102
+
103
+ return { accessToken: accessToken.token, refreshToken: refreshToken.token };
104
+ }
@@ -0,0 +1,102 @@
1
+ import { z } from "@/framework/facade.js";
2
+
3
+ export const MessageSchema = z.object({
4
+ message: z.string()
5
+ });
6
+
7
+ export const RoleSchema = z.object({
8
+ id: z.number(),
9
+ name: z.string(),
10
+ createdAt: z.string().nullable().optional(),
11
+ updatedAt: z.string().nullable().optional()
12
+ });
13
+
14
+ export const UserSchema = z.object({
15
+ id: z.number(),
16
+ name: z.string(),
17
+ email: z.email(),
18
+ roleId: z.number().nullable().optional(),
19
+ role: RoleSchema.nullable().optional(),
20
+ emailVerifiedAt: z.string().nullable().optional(),
21
+ createdAt: z.string().nullable().optional(),
22
+ updatedAt: z.string().nullable().optional()
23
+ });
24
+
25
+ export const RegisterSchema = z
26
+ .object({
27
+ name: z.string().min(2).max(100),
28
+ email: z.email(),
29
+ password: z
30
+ .string()
31
+ .min(6)
32
+ .max(100)
33
+ .regex(/[a-z]/, "Password must contain lowercase letter")
34
+ .regex(/[A-Z]/, "Password must contain uppercase letter")
35
+ .regex(/[^A-Za-z0-9]/, "Password must contain special character"),
36
+ password_confirmation: z.string()
37
+ })
38
+ .superRefine((data, ctx) => {
39
+ if (data.password !== data.password_confirmation) {
40
+ ctx.addIssue({
41
+ code: "custom",
42
+ path: ["password_confirmation"],
43
+ message: "Password confirmation does not match"
44
+ });
45
+ }
46
+ });
47
+
48
+ export const LoginSchema = z.object({
49
+ email: z.email(),
50
+ password: z.string().min(1),
51
+ remember: z.boolean().optional().default(false)
52
+ });
53
+
54
+ export const ForgotPasswordSchema = z.object({
55
+ email: z.email()
56
+ });
57
+
58
+ export const ResetPasswordSchema = z
59
+ .object({
60
+ email: z.email(),
61
+ token: z.string().min(1),
62
+ password: z
63
+ .string()
64
+ .min(6)
65
+ .max(100)
66
+ .regex(/[a-z]/, "Password must contain lowercase letter")
67
+ .regex(/[A-Z]/, "Password must contain uppercase letter")
68
+ .regex(/[^A-Za-z0-9]/, "Password must contain special character"),
69
+ password_confirmation: z.string()
70
+ })
71
+ .superRefine((data, ctx) => {
72
+ if (data.password !== data.password_confirmation) {
73
+ ctx.addIssue({
74
+ code: "custom",
75
+ path: ["password_confirmation"],
76
+ message: "Password confirmation does not match"
77
+ });
78
+ }
79
+ });
80
+
81
+ export const RefreshTokenSchema = z.object({
82
+ refresh_token: z.string().min(1)
83
+ });
84
+
85
+ export const VerifyEmailSchema = z.object({
86
+ email: z.email(),
87
+ token: z.string().min(1)
88
+ });
89
+
90
+ export const AuthResponseSchema = z.object({
91
+ message: z.string(),
92
+ data: z.object({
93
+ user: UserSchema,
94
+ access_token: z.string(),
95
+ refresh_token: z.string(),
96
+ token_type: z.literal("Bearer")
97
+ })
98
+ });
99
+
100
+ export const IdParamsSchema = z.object({
101
+ id: z.coerce.number()
102
+ });
@@ -0,0 +1,15 @@
1
+ import { eq } from "drizzle-orm";
2
+ import type { NextFunction, Request, Response } from "express";
3
+ import { db, HttpStatusCodes } from "@/framework/facade.js";
4
+ import { roles } from "@/modules/auth/database/models/role.js";
5
+
6
+ export const index = async (_req: Request, res: Response, _next: NextFunction) => {
7
+ const result = await db.query.roles.findMany();
8
+ return res.status(HttpStatusCodes.OK).json({ message: "Success", data: result });
9
+ };
10
+
11
+ export const show = async (req: Request, res: Response, _next: NextFunction) => {
12
+ const { id } = req.params;
13
+ const result = await db.query.roles.findFirst({ where: eq(roles.id, Number(id)) });
14
+ return res.status(HttpStatusCodes.OK).json({ message: "Success", data: result });
15
+ };
@@ -0,0 +1,24 @@
1
+ import { relations } from "drizzle-orm";
2
+ import { integer, sqliteTable, text } from "drizzle-orm/sqlite-core";
3
+ import { users } from "@/modules/auth/database/models/user.js";
4
+
5
+ export const notifications = sqliteTable("notifications", {
6
+ id: integer("id").primaryKey({ autoIncrement: true }),
7
+ userId: integer("user_id")
8
+ .notNull()
9
+ .references(() => users.id, { onUpdate: "cascade", onDelete: "cascade" }),
10
+ type: text("type").notNull(),
11
+ title: text("title").notNull(),
12
+ body: text("body"),
13
+ data: text("data"),
14
+ link: text("link"),
15
+ readAt: integer("read_at", { mode: "timestamp" }),
16
+ createdAt: integer("created_at", { mode: "timestamp" }).defaultNow().notNull()
17
+ });
18
+
19
+ export const notificationsRelations = relations(notifications, ({ one }) => ({
20
+ user: one(users, {
21
+ fields: [notifications.userId],
22
+ references: [users.id]
23
+ })
24
+ }));
@@ -0,0 +1,14 @@
1
+ import { relations } from "drizzle-orm";
2
+ import { integer, sqliteTable, text } from "drizzle-orm/sqlite-core";
3
+ import { users } from "@/modules/auth/database/models/user.js";
4
+
5
+ export const roles = sqliteTable("roles", {
6
+ id: integer("id").primaryKey({ autoIncrement: true }),
7
+ name: text("name").notNull().unique(),
8
+ createdAt: integer("created_at", { mode: "timestamp" }).defaultNow().notNull(),
9
+ updatedAt: integer("updated_at", { mode: "timestamp" }).defaultNow().notNull()
10
+ });
11
+
12
+ export const rolesRelations = relations(roles, ({ many }) => ({
13
+ users: many(users)
14
+ }));
@@ -0,0 +1,46 @@
1
+ import { relations } from "drizzle-orm";
2
+ import { integer, sqliteTable, text } from "drizzle-orm/sqlite-core";
3
+ import { roles } from "@/modules/auth/database/models/role.js";
4
+
5
+ export const users = sqliteTable("users", {
6
+ id: integer("id").primaryKey({ autoIncrement: true }),
7
+ name: text("name").notNull(),
8
+ email: text("email").notNull().unique(),
9
+ password: text("password").notNull(),
10
+ roleId: integer("role_id").references(() => roles.id, { onUpdate: "cascade", onDelete: "set null" }),
11
+ emailVerifiedAt: integer("email_verified_at", { mode: "timestamp" }),
12
+ createdAt: integer("created_at", { mode: "timestamp" }).defaultNow().notNull(),
13
+ updatedAt: integer("updated_at", { mode: "timestamp" }).defaultNow().notNull()
14
+ });
15
+
16
+ export const emailVerificationTokens = sqliteTable("email_verification_tokens", {
17
+ id: integer("id").primaryKey({ autoIncrement: true }),
18
+ email: text("email").notNull(),
19
+ token: text("token").notNull(),
20
+ expiresAt: integer("expires_at", { mode: "timestamp" }).notNull(),
21
+ createdAt: integer("created_at", { mode: "timestamp" }).defaultNow().notNull()
22
+ });
23
+
24
+ export const passwordResetTokens = sqliteTable("password_reset_tokens", {
25
+ id: integer("id").primaryKey({ autoIncrement: true }),
26
+ email: text("email").notNull(),
27
+ token: text("token").notNull(),
28
+ expiresAt: integer("expires_at", { mode: "timestamp" }).notNull(),
29
+ createdAt: integer("created_at", { mode: "timestamp" }).defaultNow().notNull()
30
+ });
31
+
32
+ export const refreshTokens = sqliteTable("refresh_tokens", {
33
+ id: integer("id").primaryKey({ autoIncrement: true }),
34
+ userId: integer("user_id").references(() => users.id, { onUpdate: "cascade", onDelete: "set null" }),
35
+ jti: text("jti").notNull().unique(),
36
+ revoked: integer("revoked", { mode: "boolean" }).default(false),
37
+ expiresAt: integer("expires_at", { mode: "timestamp" }).notNull(),
38
+ createdAt: integer("created_at", { mode: "timestamp" }).defaultNow().notNull()
39
+ });
40
+
41
+ export const usersRelations = relations(users, ({ one }) => ({
42
+ role: one(roles, {
43
+ fields: [users.roleId],
44
+ references: [roles.id]
45
+ })
46
+ }));
@@ -0,0 +1,18 @@
1
+ import { eq } from "drizzle-orm";
2
+ import { db } from "@/framework/facade.js";
3
+ import { roles } from "@/modules/auth/database/models/role.js";
4
+
5
+ export const table = roles;
6
+
7
+ export default async function RoleSeeder() {
8
+ const rows = [{ name: "admin" }, { name: "user" }];
9
+
10
+ for (const row of rows) {
11
+ const existing = await db.query.roles.findFirst({ where: eq(roles.name, row.name) });
12
+ if (!existing) {
13
+ await db.insert(roles).values({ name: row.name });
14
+ }
15
+ }
16
+
17
+ console.log("Role seeder completed");
18
+ }