@etus/bhono-app 0.1.5 → 0.1.7

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 (300) hide show
  1. package/dist/index.js +0 -0
  2. package/package.json +7 -2
  3. package/templates/base/.claude/commands/check-skill-rules.md +112 -29
  4. package/templates/base/.claude/commands/linear/implement-issue.md +383 -55
  5. package/templates/base/.claude/commands/ship.md +77 -13
  6. package/templates/base/.claude/hooks/package-lock.json +0 -419
  7. package/templates/base/.claude/hooks/skill-activation-prompt.ts +185 -113
  8. package/templates/base/.claude/hooks/skill-tool-guard.sh +6 -0
  9. package/templates/base/.claude/hooks/skill-tool-guard.ts +198 -0
  10. package/templates/base/.claude/scripts/validate-skill-rules.sh +55 -32
  11. package/templates/base/.claude/settings.json +18 -11
  12. package/templates/base/.claude/skills/skill-rules.json +326 -173
  13. package/templates/base/.env.example +3 -0
  14. package/templates/base/CLAUDE.md +5 -5
  15. package/templates/base/README.md +40 -27
  16. package/templates/base/config/eslint.config.js +1 -0
  17. package/templates/base/config/wrangler.json +16 -17
  18. package/templates/base/docs/SETUP-GUIDE.md +566 -0
  19. package/templates/base/docs/app_spec.txt +13 -10
  20. package/templates/base/docs/architecture/README.md +162 -5
  21. package/templates/base/docs/architecture/api-catalog.md +575 -0
  22. package/templates/base/docs/architecture/c4-component.md +309 -0
  23. package/templates/base/docs/architecture/c4-container.md +183 -0
  24. package/templates/base/docs/architecture/c4-context.md +106 -0
  25. package/templates/base/docs/architecture/data-requirements.md +4 -3
  26. package/templates/base/docs/architecture/db-bootstrap.md +39 -0
  27. package/templates/base/docs/architecture/dependencies.md +327 -0
  28. package/templates/base/docs/architecture/drizzle-migration-plan.md +125 -0
  29. package/templates/base/docs/architecture/erd.md +1 -1
  30. package/templates/base/docs/architecture/sql-standards.md +100 -0
  31. package/templates/base/docs/architecture/tech-debt.md +184 -0
  32. package/templates/base/docs/testing.md +36 -29
  33. package/templates/base/package.json +26 -20
  34. package/templates/base/schema.sql +84 -0
  35. package/templates/base/scripts/capture-prod-session.ts +2 -2
  36. package/templates/base/scripts/init.sh +244 -59
  37. package/templates/base/scripts/sync-template.sh +104 -0
  38. package/templates/base/src/client/hooks/use-auth.ts +5 -0
  39. package/templates/base/src/client/routes/_authenticated/dashboard.tsx +1 -1
  40. package/templates/base/src/client/routes/index.tsx +1 -1
  41. package/templates/base/src/server/db/client.ts +3 -5
  42. package/templates/base/src/server/db/records.ts +81 -0
  43. package/templates/base/src/server/db/seed.ts +3 -2
  44. package/templates/base/src/server/db/sql.ts +116 -0
  45. package/templates/base/src/server/index.ts +17 -2
  46. package/templates/base/src/server/lib/audit.ts +74 -26
  47. package/templates/base/src/server/lib/audited-db.ts +219 -109
  48. package/templates/base/src/server/lib/transaction.ts +10 -16
  49. package/templates/base/src/server/middleware/account.ts +9 -16
  50. package/templates/base/src/server/middleware/auth.ts +102 -38
  51. package/templates/base/src/server/middleware/rate-limit.ts +8 -6
  52. package/templates/base/src/server/routes/accounts/handlers.ts +18 -6
  53. package/templates/base/src/server/routes/audits/handlers.ts +3 -1
  54. package/templates/base/src/server/routes/auth/handlers.ts +15 -10
  55. package/templates/base/src/server/routes/auth/test-login.ts +99 -45
  56. package/templates/base/src/server/routes/health/handlers.ts +4 -4
  57. package/templates/base/src/server/routes/index.ts +9 -0
  58. package/templates/base/src/server/routes/invitations/handlers.ts +9 -6
  59. package/templates/base/src/server/routes/openapi.ts +1 -1
  60. package/templates/base/src/server/routes/users/handlers.ts +21 -14
  61. package/templates/base/src/server/services/accounts.ts +242 -217
  62. package/templates/base/src/server/services/audits.ts +114 -61
  63. package/templates/base/src/server/services/auth.ts +310 -180
  64. package/templates/base/src/server/services/invitations.ts +282 -222
  65. package/templates/base/src/server/services/users.ts +383 -293
  66. package/templates/base/src/server/types/index.ts +1 -2
  67. package/templates/base/src/shared/types/api.ts +66 -198
  68. package/templates/base/tests/e2e/auth.setup.ts +1 -1
  69. package/templates/base/{src/server/__tests__/fixtures.ts → tests/fixtures/server.ts} +3 -3
  70. package/templates/base/{src/client/__tests__/setup-browser.ts → tests/helpers/client-setup-browser.ts} +2 -2
  71. package/templates/base/{src/client/__tests__/setup.ts → tests/helpers/client-setup.ts} +1 -1
  72. package/templates/base/{src/client/__tests__/test-utils.tsx → tests/helpers/client-test-utils.tsx} +2 -2
  73. package/templates/base/{src/server/__tests__/setup.ts → tests/helpers/server.ts} +9 -9
  74. package/templates/base/tests/integration/accounts/crud.test.ts +2 -11
  75. package/templates/base/tests/integration/audits/list.test.ts +2 -11
  76. package/templates/base/tests/integration/auth/auth-service.test.ts +1 -10
  77. package/templates/base/tests/integration/auth/invitation-token.test.ts +2 -11
  78. package/templates/base/tests/integration/auth/logout.test.ts +2 -11
  79. package/templates/base/tests/integration/auth/oauth.test.ts +23 -42
  80. package/templates/base/tests/integration/auth/refresh-token.test.ts +1 -9
  81. package/templates/base/tests/integration/auth/session-expiry.test.ts +1 -9
  82. package/templates/base/tests/integration/auth/session.test.ts +2 -11
  83. package/templates/base/tests/integration/auth/super-admin.test.ts +1 -9
  84. package/templates/base/tests/integration/authorization/analytics-role.test.ts +2 -11
  85. package/templates/base/tests/integration/authorization/billing-role.test.ts +2 -11
  86. package/templates/base/tests/integration/authorization/guards-roles.test.ts +1 -9
  87. package/templates/base/tests/integration/authorization/multi-tenancy.test.ts +2 -11
  88. package/templates/base/tests/integration/authorization/roles.test.ts +2 -11
  89. package/templates/base/tests/integration/config/production-behavior.test.ts +2 -11
  90. package/templates/base/tests/integration/health/health.test.ts +25 -44
  91. package/templates/base/tests/integration/invitations/crud.test.ts +2 -11
  92. package/templates/base/tests/integration/invitations/email.test.ts +1 -9
  93. package/templates/base/tests/integration/middleware/auth.test.ts +3 -12
  94. package/templates/base/tests/integration/middleware/request-logger.test.ts +1 -9
  95. package/templates/base/tests/integration/performance/response-times.test.ts +1 -9
  96. package/templates/base/tests/integration/security/cookie-security.test.ts +2 -11
  97. package/templates/base/tests/integration/security/csrf-protection.test.ts +2 -11
  98. package/templates/base/tests/integration/security/log-sanitization.test.ts +1 -9
  99. package/templates/base/tests/integration/security/rate-limiting.test.ts +1 -9
  100. package/templates/base/tests/integration/security/sql-injection.test.ts +7 -18
  101. package/templates/base/tests/integration/security/xss-prevention.test.ts +2 -11
  102. package/templates/base/tests/integration/setup.ts +13 -90
  103. package/templates/base/tests/integration/smoke.test.ts +3 -2
  104. package/templates/base/tests/integration/storage/upload.test.ts +2 -11
  105. package/templates/base/tests/integration/storage/validation.test.ts +2 -11
  106. package/templates/base/tests/integration/users/crud.test.ts +2 -11
  107. package/templates/base/tests/integration/users/list.test.ts +2 -11
  108. package/templates/base/tests/integration/vitest.config.ts +2 -9
  109. package/templates/base/{src/server/__tests__ → tests}/mocks/db.ts +1 -1
  110. package/templates/base/{src/server/__tests__ → tests}/mocks/index.ts +1 -1
  111. package/templates/base/{src/server/__tests__ → tests}/mocks/kv.ts +1 -1
  112. package/templates/base/{src/server/__tests__ → tests}/mocks/r2.ts +1 -1
  113. package/templates/base/{src/client/components/__tests__ → tests/unit/client/components}/sidebar.test.tsx +1 -1
  114. package/templates/base/{src/client/components/ui/__tests__ → tests/unit/client/components/ui}/avatar.test.tsx +1 -1
  115. package/templates/base/{src/client/__tests__ → tests/unit/client/components/ui}/button.test.tsx +1 -1
  116. package/templates/base/{src/client/components/ui/__tests__ → tests/unit/client/components/ui}/card.test.tsx +1 -1
  117. package/templates/base/{src/client/components/ui/__tests__ → tests/unit/client/components/ui}/dialog.test.tsx +1 -1
  118. package/templates/base/{src/client/components/ui/__tests__ → tests/unit/client/components/ui}/input.test.tsx +1 -1
  119. package/templates/base/{src/client/components/ui/__tests__ → tests/unit/client/components/ui}/loading-skeleton.test.tsx +1 -1
  120. package/templates/base/{src/client/components/ui/__tests__ → tests/unit/client/components/ui}/skeleton.test.tsx +1 -1
  121. package/templates/base/{src/client/components/ui/__tests__ → tests/unit/client/components/ui}/sonner.test.tsx +1 -1
  122. package/templates/base/{src/client/components/ui/__tests__ → tests/unit/client/components/ui}/tabs.test.tsx +1 -1
  123. package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/account.test.tsx +1 -1
  124. package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/integrations.test.tsx +1 -1
  125. package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/settings.test.tsx +1 -1
  126. package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/team.test.tsx +1 -1
  127. package/templates/base/{src/client/__tests__ → tests/unit/client}/routes/authenticated-layout.test.tsx +1 -1
  128. package/templates/base/{src/client/__tests__ → tests/unit/client}/routes/dashboard.test.tsx +1 -1
  129. package/templates/base/{src/client/routes/__tests__ → tests/unit/client/routes}/invite.test.tsx +1 -1
  130. package/templates/base/{src/client/__tests__ → tests/unit/client}/routes/login.test.tsx +1 -1
  131. package/templates/base/{src/client/__tests__ → tests/unit/client}/routes/navigation.test.tsx +1 -1
  132. package/templates/base/{src/client/__tests__ → tests/unit/client}/routes/root-layout.test.tsx +1 -1
  133. package/templates/base/{src/server/auth/__tests__ → tests/unit/server/auth}/guards.test.ts +2 -2
  134. package/templates/base/{src → tests/unit}/server/auth/permissions.test.ts +1 -1
  135. package/templates/base/{src → tests/unit}/server/auth/roles.test.ts +1 -1
  136. package/templates/base/tests/unit/server/db/sql.test.ts +68 -0
  137. package/templates/base/{src → tests/unit}/server/env.test.ts +1 -1
  138. package/templates/base/tests/unit/server/lib/audited-db.test.ts +78 -0
  139. package/templates/base/{src → tests/unit}/server/lib/email.test.ts +1 -1
  140. package/templates/base/{src → tests/unit}/server/lib/errors.test.ts +1 -1
  141. package/templates/base/{src → tests/unit}/server/lib/oauth.test.ts +1 -1
  142. package/templates/base/{src → tests/unit}/server/lib/pagination.test.ts +1 -1
  143. package/templates/base/{src → tests/unit}/server/lib/password.test.ts +1 -1
  144. package/templates/base/{src → tests/unit}/server/lib/providers.test.ts +1 -1
  145. package/templates/base/{src → tests/unit}/server/lib/r2-storage.test.ts +2 -2
  146. package/templates/base/{src → tests/unit}/server/lib/session.test.ts +2 -2
  147. package/templates/base/{src → tests/unit}/server/lib/tokens.test.ts +1 -1
  148. package/templates/base/{src → tests/unit}/server/lib/transaction.test.ts +5 -14
  149. package/templates/base/{src → tests/unit}/server/middleware/account.test.ts +16 -24
  150. package/templates/base/tests/unit/server/middleware/auth.test.ts +647 -0
  151. package/templates/base/{src → tests/unit}/server/middleware/cors.test.ts +1 -1
  152. package/templates/base/{src → tests/unit}/server/middleware/error-handler.test.ts +2 -2
  153. package/templates/base/{src → tests/unit}/server/middleware/rate-limit.test.ts +3 -2
  154. package/templates/base/{src → tests/unit}/server/middleware/request-context.test.ts +1 -1
  155. package/templates/base/{src → tests/unit}/server/middleware/request-logger.test.ts +1 -1
  156. package/templates/base/{src/server/__tests__/mocks/__tests__ → tests/unit/server/mocks}/db.test.ts +1 -1
  157. package/templates/base/{src/server/__tests__/mocks/__tests__ → tests/unit/server/mocks}/kv.test.ts +1 -1
  158. package/templates/base/{src/server/__tests__/mocks/__tests__ → tests/unit/server/mocks}/r2.test.ts +1 -1
  159. package/templates/base/{src/server/routes/accounts/__tests__ → tests/unit/server/routes/accounts}/handlers.test.ts +12 -12
  160. package/templates/base/{src/server/routes/audits/__tests__ → tests/unit/server/routes/audits}/handlers.test.ts +11 -11
  161. package/templates/base/{src/server/routes/auth/__tests__ → tests/unit/server/routes/auth}/handlers.test.ts +124 -13
  162. package/templates/base/{src/server/routes/health/__tests__ → tests/unit/server/routes/health}/handlers.test.ts +27 -23
  163. package/templates/base/{src/server/routes/invitations/__tests__ → tests/unit/server/routes/invitations}/handlers.test.ts +14 -17
  164. package/templates/base/{src/server/routes/storage/__tests__ → tests/unit/server/routes/storage}/handlers.test.ts +6 -6
  165. package/templates/base/{src/server/routes/users/__tests__ → tests/unit/server/routes/users}/handlers.test.ts +81 -17
  166. package/templates/base/tests/unit/server/services/accounts.test.ts +406 -0
  167. package/templates/base/tests/unit/server/services/audits.test.ts +360 -0
  168. package/templates/base/tests/unit/server/services/auth.test.ts +656 -0
  169. package/templates/base/tests/unit/server/services/invitations.test.ts +343 -0
  170. package/templates/base/tests/unit/server/services/users.test.ts +706 -0
  171. package/templates/base/{src/shared/schemas/__tests__ → tests/unit/shared}/schemas.test.ts +1 -1
  172. package/templates/base/tsconfig.json +2 -1
  173. package/templates/base/vite.config.ts +3 -1
  174. package/templates/base/vitest.config.browser.ts +3 -2
  175. package/templates/base/vitest.config.frontend.ts +3 -2
  176. package/templates/base/vitest.config.ts +7 -14
  177. package/templates/base/.claude/settings.local.json +0 -11
  178. package/templates/base/.github/workflows/test.yml +0 -127
  179. package/templates/base/auth-setup-error.png +0 -0
  180. package/templates/base/config/drizzle.config.ts +0 -10
  181. package/templates/base/pnpm-lock.yaml +0 -8175
  182. package/templates/base/src/server/db/schema/accounts.ts +0 -20
  183. package/templates/base/src/server/db/schema/audit-logs.ts +0 -26
  184. package/templates/base/src/server/db/schema/index.ts +0 -7
  185. package/templates/base/src/server/db/schema/invitations.ts +0 -30
  186. package/templates/base/src/server/db/schema/refresh-tokens.ts +0 -22
  187. package/templates/base/src/server/db/schema/user-accounts.ts +0 -25
  188. package/templates/base/src/server/db/schema/users.ts +0 -33
  189. package/templates/base/src/server/lib/audited-db.test.ts +0 -107
  190. package/templates/base/src/server/lib/schema-helpers.ts +0 -16
  191. package/templates/base/src/server/middleware/auth.test.ts +0 -345
  192. package/templates/base/src/server/services/__tests__/accounts.test.ts +0 -764
  193. package/templates/base/src/server/services/__tests__/audits.test.ts +0 -235
  194. package/templates/base/src/server/services/__tests__/auth.test.ts +0 -765
  195. package/templates/base/src/server/services/__tests__/invitations.test.ts +0 -704
  196. package/templates/base/src/server/services/__tests__/users.test.ts +0 -755
  197. package/templates/base/tests/e2e/_auth/.gitkeep +0 -0
  198. package/templates/base/tests/integration/lib/schema-helpers.test.ts +0 -129
  199. package/templates/base/tsconfig.tsbuildinfo +0 -1
  200. /package/templates/base/{src/client/components/__tests__ → tests/unit/client/components}/__screenshots__/sidebar.test.tsx/Sidebar-can-be-collapsed-by-default-1.png +0 -0
  201. /package/templates/base/{src/client/components/__tests__ → tests/unit/client/components}/__screenshots__/sidebar.test.tsx/Sidebar-expands-when-collapsed-and-expand-button-is-clicked-1.png +0 -0
  202. /package/templates/base/{src/client/components/__tests__ → tests/unit/client/components}/__screenshots__/sidebar.test.tsx/Sidebar-handles-logout-button-click-1.png +0 -0
  203. /package/templates/base/{src/client/components/__tests__ → tests/unit/client/components}/__screenshots__/sidebar.test.tsx/Sidebar-handles-navigation-clicks-1.png +0 -0
  204. /package/templates/base/{src/client/components/__tests__ → tests/unit/client/components}/__screenshots__/sidebar.test.tsx/Sidebar-hides-navigation-labels-when-collapsed-1.png +0 -0
  205. /package/templates/base/{src/client/components/__tests__ → tests/unit/client/components}/__screenshots__/sidebar.test.tsx/Sidebar-highlights-active-route-1.png +0 -0
  206. /package/templates/base/{src/client/components/__tests__ → tests/unit/client/components}/__screenshots__/sidebar.test.tsx/Sidebar-renders-sidebar-navigation-items-1.png +0 -0
  207. /package/templates/base/{src/client/components/__tests__ → tests/unit/client/components}/__screenshots__/sidebar.test.tsx/Sidebar-shows-keyboard-shortcut-hint-when-expanded-1.png +0 -0
  208. /package/templates/base/{src/client/components/__tests__ → tests/unit/client/components}/__screenshots__/sidebar.test.tsx/Sidebar-shows-user-info-when-authenticated-1.png +0 -0
  209. /package/templates/base/{src/client/components/__tests__ → tests/unit/client/components}/__screenshots__/sidebar.test.tsx/Sidebar-shows-user-initials-in-avatar-fallback-1.png +0 -0
  210. /package/templates/base/{src/client/components/__tests__ → tests/unit/client/components}/error-boundary.test.tsx +0 -0
  211. /package/templates/base/{src/client/components/ui/__tests__ → tests/unit/client/components/ui}/error-fallback.test.tsx +0 -0
  212. /package/templates/base/{src/client/hooks/__tests__ → tests/unit/client/hooks}/use-auth.test.tsx +0 -0
  213. /package/templates/base/{src/client/hooks/__tests__ → tests/unit/client/hooks}/use-theme.test.tsx +0 -0
  214. /package/templates/base/{src/client/__tests__ → tests/unit/client}/routes/__screenshots__/dashboard.test.tsx/Dashboard-Page-when-authenticated-should-display-dashboard-stats-cards-1.png +0 -0
  215. /package/templates/base/{src/client/__tests__ → tests/unit/client}/routes/__screenshots__/dashboard.test.tsx/Dashboard-Page-when-authenticated-should-display-quick-action-cards-1.png +0 -0
  216. /package/templates/base/{src/client/__tests__ → tests/unit/client}/routes/__screenshots__/dashboard.test.tsx/Dashboard-Page-when-authenticated-should-display-recent-activity-section-1.png +0 -0
  217. /package/templates/base/{src/client/__tests__ → tests/unit/client}/routes/__screenshots__/dashboard.test.tsx/Dashboard-Page-when-authenticated-should-display-user-first-name-in-welcome-message-1.png +0 -0
  218. /package/templates/base/{src/client/__tests__ → tests/unit/client}/routes/__screenshots__/dashboard.test.tsx/Dashboard-Page-when-authenticated-should-display-user-information-in-sidebar-1.png +0 -0
  219. /package/templates/base/{src/client/__tests__ → tests/unit/client}/routes/__screenshots__/dashboard.test.tsx/Dashboard-Page-when-authenticated-should-render-dashboard-when-authenticated-1.png +0 -0
  220. /package/templates/base/{src/client/__tests__ → tests/unit/client}/routes/__screenshots__/dashboard.test.tsx/Dashboard-Page-when-authenticated-should-show-navigation-sidebar-1.png +0 -0
  221. /package/templates/base/{src/client/__tests__ → tests/unit/client}/routes/__screenshots__/dashboard.test.tsx/Dashboard-Page-when-unauthenticated-should-redirect-to-login-when-not-authenticated-1.png +0 -0
  222. /package/templates/base/{src/client/routes/__tests__ → tests/unit/client/routes}/__screenshots__/invite.test.tsx/Invite-Token-Page-pending-invitation-state-should-display-accept-invitation-button-1.png +0 -0
  223. /package/templates/base/{src/client/routes/__tests__ → tests/unit/client/routes}/__screenshots__/invite.test.tsx/Invite-Token-Page-pending-invitation-state-should-display-decline-button-linking-to-homepage-1.png +0 -0
  224. /package/templates/base/{src/client/routes/__tests__ → tests/unit/client/routes}/__screenshots__/invite.test.tsx/Invite-Token-Page-pending-invitation-state-should-display-invitation-details--email--workspace--role--1.png +0 -0
  225. /package/templates/base/{src/client/routes/__tests__ → tests/unit/client/routes}/__screenshots__/invite.test.tsx/Invite-Token-Page-pending-invitation-state-should-have-a-logo-link-to-homepage-1.png +0 -0
  226. /package/templates/base/{src/client/routes/__tests__ → tests/unit/client/routes}/__screenshots__/invite.test.tsx/Invite-Token-Page-pending-invitation-state-should-render-invitation-page-with-inviter-name-and-workspace-1.png +0 -0
  227. /package/templates/base/{src/client/routes/__tests__ → tests/unit/client/routes}/__screenshots__/invite.test.tsx/Invite-Token-Page-pending-invitation-state-should-show-terms-of-service-and-privacy-policy-links-1.png +0 -0
  228. /package/templates/base/{src/client/__tests__ → tests/unit/client}/routes/__screenshots__/login.test.tsx/Login-Page-should-display-Google-OAuth-login-button-1.png +0 -0
  229. /package/templates/base/{src/client/__tests__ → tests/unit/client}/routes/__screenshots__/login.test.tsx/Login-Page-should-have-a-link-back-to-home-page-1.png +0 -0
  230. /package/templates/base/{src/client/__tests__ → tests/unit/client}/routes/__screenshots__/login.test.tsx/Login-Page-should-render-login-content-without-waiting-for-authentication-1.png +0 -0
  231. /package/templates/base/{src/client/__tests__ → tests/unit/client}/routes/__screenshots__/login.test.tsx/Login-Page-should-render-login-page-at--login-route-1.png +0 -0
  232. /package/templates/base/{src/client/__tests__ → tests/unit/client}/routes/__screenshots__/login.test.tsx/Login-Page-should-show-Terms-of-Service-and-Privacy-Policy-links-1.png +0 -0
  233. /package/templates/base/{src/client/__tests__ → tests/unit/client}/routes/__screenshots__/login.test.tsx/Login-Page-should-trigger-OAuth-flow-when-clicking-login-button-1.png +0 -0
  234. /package/templates/base/{src/client/__tests__ → tests/unit/client}/routes/__screenshots__/navigation.test.tsx/Navigation-404-handling-should-display-404-text-on-not-found-page-1.png +0 -0
  235. /package/templates/base/{src/client/__tests__ → tests/unit/client}/routes/__screenshots__/navigation.test.tsx/Navigation-404-handling-should-have-navigation-options-on-404-page-1.png +0 -0
  236. /package/templates/base/{src/client/__tests__ → tests/unit/client}/routes/__screenshots__/navigation.test.tsx/Navigation-404-handling-should-render-404-page-for-unknown-routes-1.png +0 -0
  237. /package/templates/base/{src/client/__tests__ → tests/unit/client}/routes/__screenshots__/navigation.test.tsx/Navigation-authenticated-navigation-should-navigate-from-dashboard-to-account-page-1.png +0 -0
  238. /package/templates/base/{src/client/__tests__ → tests/unit/client}/routes/__screenshots__/navigation.test.tsx/Navigation-authenticated-navigation-should-navigate-from-dashboard-to-integrations-page-1.png +0 -0
  239. /package/templates/base/{src/client/__tests__ → tests/unit/client}/routes/__screenshots__/navigation.test.tsx/Navigation-authenticated-navigation-should-navigate-from-dashboard-to-settings-page-1.png +0 -0
  240. /package/templates/base/{src/client/__tests__ → tests/unit/client}/routes/__screenshots__/navigation.test.tsx/Navigation-authenticated-navigation-should-navigate-from-dashboard-to-team-page-1.png +0 -0
  241. /package/templates/base/{src/client/__tests__ → tests/unit/client}/routes/__screenshots__/navigation.test.tsx/Navigation-home-page-navigation-should-display-navigation-links-on-home-page-1.png +0 -0
  242. /package/templates/base/{src/client/__tests__ → tests/unit/client}/routes/__screenshots__/navigation.test.tsx/Navigation-home-page-navigation-should-have-correct-link-destinations-on-home-page-1.png +0 -0
  243. /package/templates/base/{src/client/__tests__ → tests/unit/client}/routes/__screenshots__/navigation.test.tsx/Navigation-unauthenticated-navigation-should-allow-access-to-home-page-without-authentication-1.png +0 -0
  244. /package/templates/base/{src/client/__tests__ → tests/unit/client}/routes/__screenshots__/navigation.test.tsx/Navigation-unauthenticated-navigation-should-allow-access-to-login-page-without-authentication-1.png +0 -0
  245. /package/templates/base/{src/client/__tests__ → tests/unit/client}/routes/__screenshots__/navigation.test.tsx/Navigation-unauthenticated-navigation-should-redirect-unauthenticated-users-from-dashboard-to-login-1.png +0 -0
  246. /package/templates/base/{src/client/__tests__ → tests/unit/client}/routes/__screenshots__/navigation.test.tsx/Navigation-unauthenticated-navigation-should-redirect-unauthenticated-users-from-settings-to-login-1.png +0 -0
  247. /package/templates/base/{src/client/__tests__ → tests/unit/client}/routes/__screenshots__/navigation.test.tsx/Navigation-unauthenticated-navigation-should-redirect-unauthenticated-users-from-team-to-login-1.png +0 -0
  248. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/account.test.tsx/Account-Page-should-render-Active-Sessions-section-with-session-cards-1.png +0 -0
  249. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/account.test.tsx/Account-Page-should-render-page-with-correct-title--Account--1.png +0 -0
  250. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/account.test.tsx/Account-Page-should-show-API-Access-section-1.png +0 -0
  251. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/account.test.tsx/Account-Page-should-show-Connected-Accounts-section-with-Google-connected-1.png +0 -0
  252. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/account.test.tsx/Account-Page-should-show-Danger-Zone-section-with-delete-button-1.png +0 -0
  253. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/account.test.tsx/Account-Page-should-show-Security-section-with-Two-Factor-Authentication-1.png +0 -0
  254. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/integrations.test.tsx/Integrations-Page-API-documentation-section-should-display-API-documentation-link-section-1.png +0 -0
  255. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/integrations.test.tsx/Integrations-Page-Create-Webhook-Dialog-should-have-Add-Webhook-trigger-button-1.png +0 -0
  256. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/integrations.test.tsx/Integrations-Page-category-filters-should-display-all-category-buttons-1.png +0 -0
  257. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/integrations.test.tsx/Integrations-Page-integration-cards-should-display-all-integration-cards-with-names-1.png +0 -0
  258. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/integrations.test.tsx/Integrations-Page-integration-cards-should-display-category-badges-on-cards-1.png +0 -0
  259. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/integrations.test.tsx/Integrations-Page-integration-cards-should-show-Configure-button-for-connected-integrations-1.png +0 -0
  260. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/integrations.test.tsx/Integrations-Page-integration-cards-should-show-Connect-button-for-not-connected-integrations-1.png +0 -0
  261. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/integrations.test.tsx/Integrations-Page-integration-cards-should-show-Connected-badge-for-connected-integrations-1.png +0 -0
  262. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/integrations.test.tsx/Integrations-Page-page-rendering-should-display-Available-Integrations-section-1.png +0 -0
  263. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/integrations.test.tsx/Integrations-Page-page-rendering-should-display-Webhooks-section-1.png +0 -0
  264. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/integrations.test.tsx/Integrations-Page-page-rendering-should-display-connected-count-1.png +0 -0
  265. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/integrations.test.tsx/Integrations-Page-page-rendering-should-display-page-description-1.png +0 -0
  266. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/integrations.test.tsx/Integrations-Page-page-rendering-should-display-search-input-1.png +0 -0
  267. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/integrations.test.tsx/Integrations-Page-page-rendering-should-render-with-correct-title--Integrations--1.png +0 -0
  268. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/integrations.test.tsx/Integrations-Page-search-functionality-should-filter-integrations-based-on-search-query-1.png +0 -0
  269. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/integrations.test.tsx/Integrations-Page-search-functionality-should-search-by-description-1.png +0 -0
  270. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/integrations.test.tsx/Integrations-Page-search-functionality-should-show-no-results-message-when-search-has-no-matches-1.png +0 -0
  271. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/integrations.test.tsx/Integrations-Page-webhooks-section-should-display-existing-webhook-1.png +0 -0
  272. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/integrations.test.tsx/Integrations-Page-webhooks-section-should-display-webhook-events-1.png +0 -0
  273. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/integrations.test.tsx/Integrations-Page-webhooks-section-should-display-webhook-last-delivery-info-1.png +0 -0
  274. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/integrations.test.tsx/Integrations-Page-webhooks-section-should-display-webhook-success-status-1.png +0 -0
  275. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/integrations.test.tsx/Integrations-Page-webhooks-section-should-have-Add-Webhook-button-1.png +0 -0
  276. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/settings.test.tsx/Settings-Page-Account-tab-should-display-connected-accounts-section-with-Google-provider-1.png +0 -0
  277. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/settings.test.tsx/Settings-Page-Account-tab-should-display-sessions-and-danger-zone-sections-1.png +0 -0
  278. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/settings.test.tsx/Settings-Page-Notifications-tab-should-display-all-notification-toggle-options-1.png +0 -0
  279. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/settings.test.tsx/Settings-Page-Notifications-tab-should-display-email-notifications-section-1.png +0 -0
  280. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/settings.test.tsx/Settings-Page-Notifications-tab-should-display-toggle-switches-for-notification-options-1.png +0 -0
  281. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/settings.test.tsx/Settings-Page-Notifications-tab-should-have-toggles-checked-by-default-1.png +0 -0
  282. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/settings.test.tsx/Settings-Page-Profile-tab-should-display--Save-Changes--button-1.png +0 -0
  283. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/settings.test.tsx/Settings-Page-Profile-tab-should-display-personal-information-form-1.png +0 -0
  284. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/settings.test.tsx/Settings-Page-Profile-tab-should-display-profile-picture-section-1.png +0 -0
  285. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/settings.test.tsx/Settings-Page-Profile-tab-should-display-user-email-in-disabled-email-input-1.png +0 -0
  286. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/settings.test.tsx/Settings-Page-Profile-tab-should-display-user-initials-in-avatar-1.png +0 -0
  287. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/settings.test.tsx/Settings-Page-Profile-tab-should-display-user-name-in-the-name-input-1.png +0 -0
  288. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/settings.test.tsx/Settings-Page-page-rendering-should-display-all-three-tabs-1.png +0 -0
  289. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/settings.test.tsx/Settings-Page-page-rendering-should-display-page-description-1.png +0 -0
  290. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/settings.test.tsx/Settings-Page-page-rendering-should-render-with-correct-title--Settings--1.png +0 -0
  291. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/settings.test.tsx/Settings-Page-tab-navigation-should-show-Profile-tab-as-default-active-tab-1.png +0 -0
  292. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/settings.test.tsx/Settings-Page-tab-navigation-should-switch-to-Account-tab-when-clicked-1.png +0 -0
  293. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/settings.test.tsx/Settings-Page-tab-navigation-should-switch-to-Notifications-tab-when-clicked-1.png +0 -0
  294. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/team.test.tsx/Team-Page-should-display-Active-Members-section-with-member-count-1.png +0 -0
  295. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/team.test.tsx/Team-Page-should-display-Pending-Invitations-section-with-invitation-details-1.png +0 -0
  296. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/team.test.tsx/Team-Page-should-have-invite-member-button-that-can-be-clicked-1.png +0 -0
  297. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/team.test.tsx/Team-Page-should-render-page-with-correct-title-and-description-1.png +0 -0
  298. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/team.test.tsx/Team-Page-should-render-search-input-that-filters-team-members-1.png +0 -0
  299. /package/templates/base/{src/client/routes/_authenticated/__tests__ → tests/unit/client/routes/_authenticated}/__screenshots__/team.test.tsx/Team-Page-should-show-current-user-with---you---indicator-and-role-badge-1.png +0 -0
  300. /package/templates/base/{src/client/__tests__ → tests/unit/client}/routes/error-components.test.tsx +0 -0
@@ -1,20 +0,0 @@
1
- // src/db/schema/accounts.ts
2
- import { sqliteTable, text } from 'drizzle-orm/sqlite-core'
3
- import { sql } from 'drizzle-orm'
4
-
5
- export const accounts = sqliteTable('accounts', {
6
- id: text('id')
7
- .primaryKey()
8
- .$defaultFn(() => crypto.randomUUID()),
9
- name: text('name').notNull(),
10
- description: text('description'),
11
- domain: text('domain').unique(),
12
-
13
- // Soft delete fields
14
- createdAt: text('created_at').default(sql`(datetime('now'))`).notNull(),
15
- updatedAt: text('updated_at').default(sql`(datetime('now'))`).notNull(),
16
- deletedAt: text('deleted_at'),
17
- })
18
-
19
- export type AccountRecord = typeof accounts.$inferSelect
20
- export type NewAccount = typeof accounts.$inferInsert
@@ -1,26 +0,0 @@
1
- // src/db/schema/audit-logs.ts
2
- import { sqliteTable, text } from 'drizzle-orm/sqlite-core'
3
- import { sql } from 'drizzle-orm'
4
- import { users } from './users'
5
- import { accounts } from './accounts'
6
-
7
- export const auditLogs = sqliteTable('audit_logs', {
8
- id: text('id')
9
- .primaryKey()
10
- .$defaultFn(() => crypto.randomUUID()),
11
- transactionId: text('transaction_id').notNull(),
12
- accountId: text('account_id').references(() => accounts.id),
13
- userId: text('user_id').references(() => users.id),
14
- entity: text('entity').notNull(),
15
- entityId: text('entity_id').notNull(),
16
- action: text('action', {
17
- enum: ['INSERT', 'UPDATE', 'DELETE', 'LOGIN', 'LOGOUT', 'SIGNUP', 'TOKEN_REFRESH', 'LOGIN_FAILED']
18
- }).notNull(),
19
- changes: text('changes', { mode: 'json' }).$type<Record<string, unknown>>(),
20
- ipAddress: text('ip_address'),
21
- userAgent: text('user_agent'),
22
- timestamp: text('timestamp').default(sql`(datetime('now'))`).notNull(),
23
- })
24
-
25
- export type AuditLogRecord = typeof auditLogs.$inferSelect
26
- export type NewAuditLog = typeof auditLogs.$inferInsert
@@ -1,7 +0,0 @@
1
- // src/db/schema/index.ts
2
- export * from './users'
3
- export * from './accounts'
4
- export * from './user-accounts'
5
- export * from './audit-logs'
6
- export * from './refresh-tokens'
7
- export * from './invitations'
@@ -1,30 +0,0 @@
1
- // src/db/schema/invitations.ts
2
- import { sqliteTable, text, uniqueIndex } from 'drizzle-orm/sqlite-core'
3
- import { sql } from 'drizzle-orm'
4
- import { accounts } from './accounts'
5
- import { users } from './users'
6
-
7
- export const invitations = sqliteTable('invitations', {
8
- id: text('id')
9
- .primaryKey()
10
- .$defaultFn(() => crypto.randomUUID()),
11
- accountId: text('account_id')
12
- .notNull()
13
- .references(() => accounts.id, { onDelete: 'cascade' }),
14
- email: text('email').notNull(),
15
- role: text('role', {
16
- enum: ['ADMIN', 'MANAGER', 'EDITOR', 'AUTHOR', 'VIEWER', 'BILLING', 'ANALYTICS'],
17
- }).notNull(),
18
- token: text('token').notNull().unique(),
19
- invitedById: text('invited_by_id')
20
- .notNull()
21
- .references(() => users.id),
22
- expiresAt: text('expires_at').notNull(),
23
- acceptedAt: text('accepted_at'),
24
- createdAt: text('created_at').default(sql`(datetime('now'))`).notNull(),
25
- }, (table) => [
26
- uniqueIndex('account_email_idx').on(table.accountId, table.email),
27
- ])
28
-
29
- export type InvitationRecord = typeof invitations.$inferSelect
30
- export type NewInvitation = typeof invitations.$inferInsert
@@ -1,22 +0,0 @@
1
- // src/db/schema/refresh-tokens.ts
2
- import { sqliteTable, text, integer } from 'drizzle-orm/sqlite-core'
3
- import { sql } from 'drizzle-orm'
4
- import { users } from './users'
5
-
6
- export const refreshTokens = sqliteTable('refresh_tokens', {
7
- id: text('id')
8
- .primaryKey()
9
- .$defaultFn(() => crypto.randomUUID()),
10
- userId: text('user_id')
11
- .notNull()
12
- .references(() => users.id, { onDelete: 'cascade' }),
13
- tokenHash: text('token_hash').notNull(),
14
- expiresAt: integer('expires_at', { mode: 'timestamp' }).notNull(),
15
- createdAt: integer('created_at', { mode: 'timestamp' })
16
- .notNull()
17
- .default(sql`(unixepoch())`),
18
- revokedAt: integer('revoked_at', { mode: 'timestamp' }),
19
- })
20
-
21
- export type RefreshTokenRecord = typeof refreshTokens.$inferSelect
22
- export type NewRefreshToken = typeof refreshTokens.$inferInsert
@@ -1,25 +0,0 @@
1
- // src/db/schema/user-accounts.ts
2
- import { sqliteTable, text, primaryKey } from 'drizzle-orm/sqlite-core'
3
- import { users } from './users'
4
- import { accounts } from './accounts'
5
-
6
- export const userAccounts = sqliteTable(
7
- 'user_accounts',
8
- {
9
- userId: text('user_id')
10
- .notNull()
11
- .references(() => users.id, { onDelete: 'cascade' }),
12
- accountId: text('account_id')
13
- .notNull()
14
- .references(() => accounts.id, { onDelete: 'cascade' }),
15
- role: text('role', {
16
- enum: ['ADMIN', 'MANAGER', 'EDITOR', 'AUTHOR', 'VIEWER', 'BILLING', 'ANALYTICS'],
17
- }).notNull(),
18
- },
19
- (table) => [
20
- primaryKey({ columns: [table.userId, table.accountId] }),
21
- ]
22
- )
23
-
24
- export type UserAccountRecord = typeof userAccounts.$inferSelect
25
- export type NewUserAccount = typeof userAccounts.$inferInsert
@@ -1,33 +0,0 @@
1
- // src/db/schema/users.ts
2
- import { sqliteTable, text, integer, type AnySQLiteColumn } from 'drizzle-orm/sqlite-core'
3
- import { sql } from 'drizzle-orm'
4
-
5
- export const users = sqliteTable('users', {
6
- id: text('id')
7
- .primaryKey()
8
- .$defaultFn(() => crypto.randomUUID()),
9
- googleId: text('google_id').notNull().unique(),
10
- email: text('email').notNull(),
11
- name: text('name').notNull(),
12
- avatarUrl: text('avatar_url'),
13
- status: text('status', { enum: ['active', 'inactive'] })
14
- .default('active')
15
- .notNull(),
16
- providerIds: text('provider_ids', { mode: 'json' })
17
- .$type<string[]>()
18
- .default([]),
19
- isSuperAdmin: integer('is_super_admin', { mode: 'boolean' })
20
- .default(false)
21
- .notNull(),
22
-
23
- // Soft delete + audit fields
24
- createdAt: text('created_at').default(sql`(datetime('now'))`).notNull(),
25
- updatedAt: text('updated_at').default(sql`(datetime('now'))`).notNull(),
26
- deletedAt: text('deleted_at'),
27
- createdById: text('created_by_id').references((): AnySQLiteColumn => users.id),
28
- updatedById: text('updated_by_id').references((): AnySQLiteColumn => users.id),
29
- deletedById: text('deleted_by_id').references((): AnySQLiteColumn => users.id),
30
- })
31
-
32
- export type UserRecord = typeof users.$inferSelect
33
- export type NewUser = typeof users.$inferInsert
@@ -1,107 +0,0 @@
1
- // src/server/lib/audited-db.test.ts
2
- import { describe, it, expect, vi, beforeEach } from 'vitest'
3
- import { auditedInsert, auditedUpdate, auditedDelete } from './audited-db'
4
- import type { ServiceContext } from '../types'
5
-
6
- // Mock database and table
7
- const mockDb = {
8
- insert: vi.fn(),
9
- update: vi.fn(),
10
- delete: vi.fn(),
11
- select: vi.fn(),
12
- }
13
-
14
- const mockTable = {
15
- _: { name: 'users' },
16
- } as any
17
-
18
- const mockCtx: ServiceContext = {
19
- accountId: 'account-123',
20
- user: {
21
- id: 'user-123',
22
- email: 'test@example.com',
23
- name: 'Test User',
24
- status: 'active',
25
- providerIds: [],
26
- isSuperAdmin: false,
27
- createdAt: '2024-01-01',
28
- updatedAt: '2024-01-01',
29
- deletedAt: null,
30
- },
31
- transactionId: 'tx-123',
32
- ip: '127.0.0.1',
33
- userAgent: 'test-agent',
34
- }
35
-
36
- describe('audited-db', () => {
37
- beforeEach(() => {
38
- vi.clearAllMocks()
39
- })
40
-
41
- describe('auditedInsert', () => {
42
- it('should insert data and return result', async () => {
43
- const insertedData = { id: 'new-123', name: 'Test' }
44
- const mockReturning = vi.fn().mockResolvedValue([insertedData])
45
- const mockValues = vi.fn().mockReturnValue({ returning: mockReturning })
46
- mockDb.insert.mockReturnValue({ values: mockValues })
47
-
48
- const result = await auditedInsert(mockDb as any, mockCtx, mockTable, { name: 'Test' })
49
-
50
- expect(result).toEqual([insertedData])
51
- expect(mockDb.insert).toHaveBeenCalledWith(mockTable)
52
- })
53
-
54
- it('should log audit after insert', async () => {
55
- const insertedData = { id: 'new-123', name: 'Test' }
56
- const mockReturning = vi.fn().mockResolvedValue([insertedData])
57
- const mockValues = vi.fn().mockReturnValue({ returning: mockReturning })
58
- mockDb.insert.mockReturnValue({ values: mockValues })
59
-
60
- await auditedInsert(mockDb as any, mockCtx, mockTable, { name: 'Test' })
61
-
62
- // Verify insert was called (audit logging happens internally)
63
- expect(mockDb.insert).toHaveBeenCalled()
64
- })
65
- })
66
-
67
- describe('auditedUpdate', () => {
68
- it('should update data and return result', async () => {
69
- const updatedData = { id: 'existing-123', name: 'Updated' }
70
- const mockReturning = vi.fn().mockResolvedValue([updatedData])
71
- const mockWhere = vi.fn().mockReturnValue({ returning: mockReturning })
72
- const mockSet = vi.fn().mockReturnValue({ where: mockWhere })
73
- mockDb.update.mockReturnValue({ set: mockSet })
74
-
75
- // Mock select for getting old data
76
- const mockLimit = vi.fn().mockResolvedValue([{ id: 'existing-123', name: 'Old' }])
77
- const mockSelectWhere = vi.fn().mockReturnValue({ limit: mockLimit })
78
- const mockFrom = vi.fn().mockReturnValue({ where: mockSelectWhere })
79
- mockDb.select.mockReturnValue({ from: mockFrom })
80
-
81
- const whereClause = {} as any
82
- const result = await auditedUpdate(
83
- mockDb as any,
84
- mockCtx,
85
- mockTable,
86
- { name: 'Updated' },
87
- whereClause
88
- )
89
-
90
- expect(result).toEqual([updatedData])
91
- })
92
- })
93
-
94
- describe('auditedDelete', () => {
95
- it('should soft delete and return void', async () => {
96
- const mockReturning = vi.fn().mockResolvedValue([{ id: 'deleted-123' }])
97
- const mockWhere = vi.fn().mockReturnValue({ returning: mockReturning })
98
- const mockSet = vi.fn().mockReturnValue({ where: mockWhere })
99
- mockDb.update.mockReturnValue({ set: mockSet })
100
-
101
- const whereClause = {} as any
102
- await auditedDelete(mockDb as any, mockCtx, mockTable, whereClause)
103
-
104
- expect(mockDb.update).toHaveBeenCalledWith(mockTable)
105
- })
106
- })
107
- })
@@ -1,16 +0,0 @@
1
- // src/lib/schema-helpers.ts
2
- import { text, type AnySQLiteColumn } from 'drizzle-orm/sqlite-core'
3
- import { sql } from 'drizzle-orm'
4
-
5
- export const softDeleteFields = {
6
- createdAt: text('created_at').default(sql`(datetime('now'))`).notNull(),
7
- updatedAt: text('updated_at').default(sql`(datetime('now'))`).notNull(),
8
- deletedAt: text('deleted_at'),
9
- }
10
-
11
- export const createInteractiveFields = (usersTableRef: () => AnySQLiteColumn) => ({
12
- ...softDeleteFields,
13
- createdById: text('created_by_id').references(usersTableRef),
14
- updatedById: text('updated_by_id').references(usersTableRef),
15
- deletedById: text('deleted_by_id').references(usersTableRef),
16
- })
@@ -1,345 +0,0 @@
1
- // src/server/middleware/auth.test.ts
2
- import { describe, it, expect, vi, beforeEach } from 'vitest'
3
- import { Hono } from 'hono'
4
- import { sessionAuth, jwtAuth } from './auth'
5
- import { createUserFixture, createInactiveUserFixture } from '../__tests__/fixtures'
6
-
7
- // Mock the session module
8
- vi.mock('../lib/session', () => ({
9
- getSession: vi.fn(),
10
- }))
11
-
12
- // Mock hono/jwt
13
- vi.mock('hono/jwt', () => ({
14
- verify: vi.fn(),
15
- }))
16
-
17
- import { getSession } from '../lib/session'
18
- import { verify } from 'hono/jwt'
19
-
20
- describe('sessionAuth', () => {
21
- beforeEach(() => {
22
- vi.clearAllMocks()
23
- })
24
-
25
- const createApp = () => {
26
- const app = new Hono()
27
- // Setup mock db in context
28
- app.use('*', async (c, next) => {
29
- c.set('db', mockDb)
30
- await next()
31
- })
32
- app.use('*', sessionAuth)
33
- app.get('/test', (c) => {
34
- const user = c.get('user')
35
- return c.json({ success: true, user })
36
- })
37
- return app
38
- }
39
-
40
- // Create mock database
41
- let mockDb: any
42
-
43
- beforeEach(() => {
44
- mockDb = {
45
- select: vi.fn().mockReturnThis(),
46
- from: vi.fn().mockReturnThis(),
47
- where: vi.fn().mockReturnThis(),
48
- limit: vi.fn(),
49
- }
50
- })
51
-
52
- it('calls next() when valid session exists', async () => {
53
- const testUser = createUserFixture({ id: 'user-123', email: 'test@example.com' })
54
-
55
- // Mock session exists
56
- vi.mocked(getSession).mockReturnValue({
57
- userId: 'user-123',
58
- email: 'test@example.com',
59
- name: 'Test User',
60
- isSuperAdmin: false,
61
- })
62
-
63
- // Mock db returns user
64
- mockDb.limit.mockResolvedValue([testUser])
65
-
66
- const app = createApp()
67
- const res = await app.request('/test')
68
- const body = await res.json()
69
-
70
- expect(res.status).toBe(200)
71
- expect(body.success).toBe(true)
72
- expect(body.user.id).toBe('user-123')
73
- })
74
-
75
- it('throws 401 when no session', async () => {
76
- vi.mocked(getSession).mockReturnValue(null)
77
-
78
- const app = createApp()
79
- const res = await app.request('/test')
80
-
81
- expect(res.status).toBe(401)
82
- })
83
-
84
- it('throws 401 when user not found', async () => {
85
- vi.mocked(getSession).mockReturnValue({
86
- userId: 'nonexistent-user',
87
- email: 'test@example.com',
88
- name: 'Test User',
89
- isSuperAdmin: false,
90
- })
91
-
92
- // Mock db returns empty array (user not found)
93
- mockDb.limit.mockResolvedValue([])
94
-
95
- const app = createApp()
96
- const res = await app.request('/test')
97
-
98
- expect(res.status).toBe(401)
99
- })
100
-
101
- it('throws 401 when user is inactive', async () => {
102
- const inactiveUser = createInactiveUserFixture({ id: 'user-123' })
103
-
104
- vi.mocked(getSession).mockReturnValue({
105
- userId: 'user-123',
106
- email: 'test@example.com',
107
- name: 'Test User',
108
- isSuperAdmin: false,
109
- })
110
-
111
- // Mock db returns inactive user
112
- mockDb.limit.mockResolvedValue([inactiveUser])
113
-
114
- const app = createApp()
115
- const res = await app.request('/test')
116
-
117
- expect(res.status).toBe(401)
118
- })
119
-
120
- it('sets user in context with correct fields', async () => {
121
- const testUser = createUserFixture({
122
- id: 'user-123',
123
- email: 'test@example.com',
124
- name: 'Test User',
125
- status: 'active',
126
- providerIds: ['google', 'github'],
127
- isSuperAdmin: true,
128
- })
129
-
130
- vi.mocked(getSession).mockReturnValue({
131
- userId: 'user-123',
132
- email: 'test@example.com',
133
- name: 'Test User',
134
- isSuperAdmin: true,
135
- })
136
-
137
- mockDb.limit.mockResolvedValue([testUser])
138
-
139
- const app = createApp()
140
- const res = await app.request('/test')
141
- const body = await res.json()
142
-
143
- expect(res.status).toBe(200)
144
- expect(body.user).toMatchObject({
145
- id: 'user-123',
146
- email: 'test@example.com',
147
- name: 'Test User',
148
- status: 'active',
149
- providerIds: ['google', 'github'],
150
- isSuperAdmin: true,
151
- })
152
- })
153
- })
154
-
155
- describe('jwtAuth', () => {
156
- beforeEach(() => {
157
- vi.clearAllMocks()
158
- })
159
-
160
- // Create mock database
161
- let mockDb: any
162
-
163
- beforeEach(() => {
164
- mockDb = {
165
- select: vi.fn().mockReturnThis(),
166
- from: vi.fn().mockReturnThis(),
167
- where: vi.fn().mockReturnThis(),
168
- limit: vi.fn(),
169
- }
170
- })
171
-
172
- const createApp = () => {
173
- const app = new Hono<{ Bindings: { JWT_SECRET: string } }>()
174
- // Setup mock db and env in context
175
- app.use('*', async (c, next) => {
176
- c.set('db', mockDb)
177
- ;(c.env as any) = { JWT_SECRET: 'test-secret' }
178
- await next()
179
- })
180
- app.use('*', jwtAuth)
181
- app.get('/test', (c) => {
182
- const user = c.get('user')
183
- return c.json({ success: true, user })
184
- })
185
- return app
186
- }
187
-
188
- it('calls next() when valid JWT provided', async () => {
189
- const testUser = createUserFixture({ id: 'user-123', email: 'test@example.com' })
190
-
191
- // Mock JWT verification
192
- vi.mocked(verify).mockResolvedValue({
193
- sub: 'user-123',
194
- email: 'test@example.com',
195
- iat: Date.now(),
196
- exp: Date.now() + 3600000,
197
- })
198
-
199
- // Mock db returns user
200
- mockDb.limit.mockResolvedValue([testUser])
201
-
202
- const app = createApp()
203
- const res = await app.request('/test', {
204
- headers: { Authorization: 'Bearer valid-token' },
205
- })
206
- const body = await res.json()
207
-
208
- expect(res.status).toBe(200)
209
- expect(body.success).toBe(true)
210
- expect(body.user.id).toBe('user-123')
211
- })
212
-
213
- it('throws 401 when Authorization header missing', async () => {
214
- const app = createApp()
215
- const res = await app.request('/test')
216
-
217
- expect(res.status).toBe(401)
218
- })
219
-
220
- it('throws 401 when Authorization header format invalid', async () => {
221
- const app = createApp()
222
-
223
- // Test with wrong scheme
224
- const res1 = await app.request('/test', {
225
- headers: { Authorization: 'Basic some-token' },
226
- })
227
- expect(res1.status).toBe(401)
228
-
229
- // Test with no token
230
- const res2 = await app.request('/test', {
231
- headers: { Authorization: 'Bearer ' },
232
- })
233
- expect(res2.status).toBe(401)
234
-
235
- // Test with Bearer only
236
- const res3 = await app.request('/test', {
237
- headers: { Authorization: 'Bearer' },
238
- })
239
- expect(res3.status).toBe(401)
240
- })
241
-
242
- it('throws 401 when JWT invalid/expired', async () => {
243
- // Mock JWT verification to throw error
244
- vi.mocked(verify).mockRejectedValue(new Error('Invalid token'))
245
-
246
- const app = createApp()
247
- const res = await app.request('/test', {
248
- headers: { Authorization: 'Bearer invalid-token' },
249
- })
250
-
251
- expect(res.status).toBe(401)
252
- })
253
-
254
- it('throws 401 when payload missing sub', async () => {
255
- // Mock JWT verification without sub claim
256
- vi.mocked(verify).mockResolvedValue({
257
- email: 'test@example.com',
258
- iat: Date.now(),
259
- exp: Date.now() + 3600000,
260
- })
261
-
262
- const app = createApp()
263
- const res = await app.request('/test', {
264
- headers: { Authorization: 'Bearer token-without-sub' },
265
- })
266
-
267
- expect(res.status).toBe(401)
268
- })
269
-
270
- it('throws 401 when user not found', async () => {
271
- vi.mocked(verify).mockResolvedValue({
272
- sub: 'nonexistent-user',
273
- email: 'test@example.com',
274
- iat: Date.now(),
275
- exp: Date.now() + 3600000,
276
- })
277
-
278
- // Mock db returns empty array
279
- mockDb.limit.mockResolvedValue([])
280
-
281
- const app = createApp()
282
- const res = await app.request('/test', {
283
- headers: { Authorization: 'Bearer valid-token' },
284
- })
285
-
286
- expect(res.status).toBe(401)
287
- })
288
-
289
- it('throws 401 when user is inactive', async () => {
290
- const inactiveUser = createInactiveUserFixture({ id: 'user-123' })
291
-
292
- vi.mocked(verify).mockResolvedValue({
293
- sub: 'user-123',
294
- email: 'test@example.com',
295
- iat: Date.now(),
296
- exp: Date.now() + 3600000,
297
- })
298
-
299
- // Mock db returns inactive user
300
- mockDb.limit.mockResolvedValue([inactiveUser])
301
-
302
- const app = createApp()
303
- const res = await app.request('/test', {
304
- headers: { Authorization: 'Bearer valid-token' },
305
- })
306
-
307
- expect(res.status).toBe(401)
308
- })
309
-
310
- it('sets user in context with correct fields', async () => {
311
- const testUser = createUserFixture({
312
- id: 'user-123',
313
- email: 'test@example.com',
314
- name: 'Test User',
315
- status: 'active',
316
- providerIds: ['google'],
317
- isSuperAdmin: false,
318
- })
319
-
320
- vi.mocked(verify).mockResolvedValue({
321
- sub: 'user-123',
322
- email: 'test@example.com',
323
- iat: Date.now(),
324
- exp: Date.now() + 3600000,
325
- })
326
-
327
- mockDb.limit.mockResolvedValue([testUser])
328
-
329
- const app = createApp()
330
- const res = await app.request('/test', {
331
- headers: { Authorization: 'Bearer valid-token' },
332
- })
333
- const body = await res.json()
334
-
335
- expect(res.status).toBe(200)
336
- expect(body.user).toMatchObject({
337
- id: 'user-123',
338
- email: 'test@example.com',
339
- name: 'Test User',
340
- status: 'active',
341
- providerIds: ['google'],
342
- isSuperAdmin: false,
343
- })
344
- })
345
- })