@etus/bhono-app 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (688) hide show
  1. package/dist/cli.d.ts +13 -0
  2. package/dist/cli.js +46 -0
  3. package/dist/cli.js.map +1 -0
  4. package/dist/cli.test.d.ts +1 -0
  5. package/dist/cli.test.js +26 -0
  6. package/dist/cli.test.js.map +1 -0
  7. package/dist/generator.d.ts +14 -0
  8. package/dist/generator.js +142 -0
  9. package/dist/generator.js.map +1 -0
  10. package/dist/generator.test.d.ts +1 -0
  11. package/dist/generator.test.js +127 -0
  12. package/dist/generator.test.js.map +1 -0
  13. package/dist/index.d.ts +2 -0
  14. package/dist/index.js +97 -0
  15. package/dist/index.js.map +1 -0
  16. package/dist/prompts.d.ts +25 -0
  17. package/dist/prompts.js +83 -0
  18. package/dist/prompts.js.map +1 -0
  19. package/dist/prompts.test.d.ts +1 -0
  20. package/dist/prompts.test.js +24 -0
  21. package/dist/prompts.test.js.map +1 -0
  22. package/dist/providers/cloudflare.d.ts +37 -0
  23. package/dist/providers/cloudflare.js +61 -0
  24. package/dist/providers/cloudflare.js.map +1 -0
  25. package/dist/providers/cloudflare.test.d.ts +1 -0
  26. package/dist/providers/cloudflare.test.js +29 -0
  27. package/dist/providers/cloudflare.test.js.map +1 -0
  28. package/dist/providers/github.d.ts +16 -0
  29. package/dist/providers/github.js +57 -0
  30. package/dist/providers/github.js.map +1 -0
  31. package/dist/providers/github.test.d.ts +1 -0
  32. package/dist/providers/github.test.js +16 -0
  33. package/dist/providers/github.test.js.map +1 -0
  34. package/dist/templates.d.ts +8 -0
  35. package/dist/templates.js +88 -0
  36. package/dist/templates.js.map +1 -0
  37. package/dist/templates.test.d.ts +1 -0
  38. package/dist/templates.test.js +26 -0
  39. package/dist/templates.test.js.map +1 -0
  40. package/package.json +36 -0
  41. package/templates/base/.claude/agents/architect-review.md +160 -0
  42. package/templates/base/.claude/agents/backend-architect.md +308 -0
  43. package/templates/base/.claude/agents/code-reviewer.md +170 -0
  44. package/templates/base/.claude/agents/performance-engineer.md +166 -0
  45. package/templates/base/.claude/agents/test-automator.md +219 -0
  46. package/templates/base/.claude/commands/check-skill-rules.md +53 -0
  47. package/templates/base/.claude/commands/claude-md.md +250 -0
  48. package/templates/base/.claude/commands/code-prompt.md +212 -0
  49. package/templates/base/.claude/commands/explain-code.md +194 -0
  50. package/templates/base/.claude/commands/init-projec.md +89 -0
  51. package/templates/base/.claude/commands/linear/README.md +297 -0
  52. package/templates/base/.claude/commands/linear/create-issue.md +190 -0
  53. package/templates/base/.claude/commands/linear/implement-issue.md +248 -0
  54. package/templates/base/.claude/commands/linear/process-triage.md +399 -0
  55. package/templates/base/.claude/commands/linear/setup.md +180 -0
  56. package/templates/base/.claude/commands/prime.md +9 -0
  57. package/templates/base/.claude/commands/review-gap.md +10 -0
  58. package/templates/base/.claude/commands/setup-aa.md +311 -0
  59. package/templates/base/.claude/commands/ship.md +262 -0
  60. package/templates/base/.claude/commands/tools.md +3 -0
  61. package/templates/base/.claude/docs/claude-progress.txt +107 -0
  62. package/templates/base/.claude/hooks/package-lock.json +556 -0
  63. package/templates/base/.claude/hooks/package.json +16 -0
  64. package/templates/base/.claude/hooks/skill-activation-prompt.sh +7 -0
  65. package/templates/base/.claude/hooks/skill-activation-prompt.ts +142 -0
  66. package/templates/base/.claude/hooks/tsconfig.json +19 -0
  67. package/templates/base/.claude/scripts/check-updates.sh +85 -0
  68. package/templates/base/.claude/scripts/install_pkgs.sh +66 -0
  69. package/templates/base/.claude/scripts/setup-project.sh +177 -0
  70. package/templates/base/.claude/scripts/validate-skill-rules.sh +94 -0
  71. package/templates/base/.claude/settings.json +113 -0
  72. package/templates/base/.claude/settings.local.json +11 -0
  73. package/templates/base/.claude/skills/architecture-analyzer/SKILL.md +531 -0
  74. package/templates/base/.claude/skills/architecture-analyzer/assets/report-template.md +215 -0
  75. package/templates/base/.claude/skills/architecture-analyzer/references/c4-templates.md +234 -0
  76. package/templates/base/.claude/skills/architecture-analyzer/references/confidence-levels.md +203 -0
  77. package/templates/base/.claude/skills/architecture-analyzer/scripts/analyze_structure.py +266 -0
  78. package/templates/base/.claude/skills/architecture-analyzer/scripts/analyze_tech_debt.py +776 -0
  79. package/templates/base/.claude/skills/architecture-analyzer/scripts/extract_apis.py +338 -0
  80. package/templates/base/.claude/skills/architecture-analyzer/scripts/generate_c4.py +283 -0
  81. package/templates/base/.claude/skills/architecture-analyzer/scripts/generate_erd.py +935 -0
  82. package/templates/base/.claude/skills/architecture-analyzer/scripts/map_dependencies.py +555 -0
  83. package/templates/base/.claude/skills/dev-browser/SKILL.md +318 -0
  84. package/templates/base/.claude/skills/dev-browser/bun.lock +443 -0
  85. package/templates/base/.claude/skills/dev-browser/package-lock.json +2927 -0
  86. package/templates/base/.claude/skills/dev-browser/package.json +27 -0
  87. package/templates/base/.claude/skills/dev-browser/scripts/start-server.ts +117 -0
  88. package/templates/base/.claude/skills/dev-browser/server.sh +24 -0
  89. package/templates/base/.claude/skills/dev-browser/src/client.ts +403 -0
  90. package/templates/base/.claude/skills/dev-browser/src/index.ts +281 -0
  91. package/templates/base/.claude/skills/dev-browser/src/snapshot/__tests__/snapshot.test.ts +223 -0
  92. package/templates/base/.claude/skills/dev-browser/src/snapshot/browser-script.ts +877 -0
  93. package/templates/base/.claude/skills/dev-browser/src/snapshot/index.ts +14 -0
  94. package/templates/base/.claude/skills/dev-browser/src/snapshot/inject.ts +13 -0
  95. package/templates/base/.claude/skills/dev-browser/src/types.ts +27 -0
  96. package/templates/base/.claude/skills/dev-browser/tsconfig.json +36 -0
  97. package/templates/base/.claude/skills/dev-browser/vitest.config.ts +12 -0
  98. package/templates/base/.claude/skills/linear/SKILL.md +440 -0
  99. package/templates/base/.claude/skills/linear/examples.md +262 -0
  100. package/templates/base/.claude/skills/linear/lib/client.ts +51 -0
  101. package/templates/base/.claude/skills/linear/lib/config.ts +106 -0
  102. package/templates/base/.claude/skills/linear/lib/output.ts +34 -0
  103. package/templates/base/.claude/skills/linear/package-lock.json +698 -0
  104. package/templates/base/.claude/skills/linear/package.json +27 -0
  105. package/templates/base/.claude/skills/linear/reference.md +263 -0
  106. package/templates/base/.claude/skills/linear/scripts/comments/create.ts +47 -0
  107. package/templates/base/.claude/skills/linear/scripts/comments/list.ts +47 -0
  108. package/templates/base/.claude/skills/linear/scripts/issues/archive.ts +30 -0
  109. package/templates/base/.claude/skills/linear/scripts/issues/create.ts +279 -0
  110. package/templates/base/.claude/skills/linear/scripts/issues/get.ts +68 -0
  111. package/templates/base/.claude/skills/linear/scripts/issues/list.ts +67 -0
  112. package/templates/base/.claude/skills/linear/scripts/issues/update.ts +281 -0
  113. package/templates/base/.claude/skills/linear/scripts/labels/add-to-issue.ts +63 -0
  114. package/templates/base/.claude/skills/linear/scripts/labels/create.ts +45 -0
  115. package/templates/base/.claude/skills/linear/scripts/labels/list.ts +30 -0
  116. package/templates/base/.claude/skills/linear/scripts/list-teams.ts +52 -0
  117. package/templates/base/.claude/skills/linear/scripts/setup/setup-credentials.ts +96 -0
  118. package/templates/base/.claude/skills/linear/scripts/status/list.ts +31 -0
  119. package/templates/base/.claude/skills/linear/scripts/status/set-by-name.ts +78 -0
  120. package/templates/base/.claude/skills/linear/scripts/status/update.ts +44 -0
  121. package/templates/base/.claude/skills/linear/scripts/users/list.ts +59 -0
  122. package/templates/base/.claude/skills/linear/scripts/users/me.ts +20 -0
  123. package/templates/base/.claude/skills/linear/templates/README.md +203 -0
  124. package/templates/base/.claude/skills/linear/templates/api-reference.md +258 -0
  125. package/templates/base/.claude/skills/linear/templates/bug-report.md +99 -0
  126. package/templates/base/.claude/skills/linear/templates/feature-request.md +118 -0
  127. package/templates/base/.claude/skills/linear/templates/security-issue.md +162 -0
  128. package/templates/base/.claude/skills/linear/templates/sprint-task.md +175 -0
  129. package/templates/base/.claude/skills/linear/templates/tech-debt.md +137 -0
  130. package/templates/base/.claude/skills/linear/tsconfig.json +17 -0
  131. package/templates/base/.claude/skills/linear/workflows/issue-lifecycle.md +317 -0
  132. package/templates/base/.claude/skills/playwright-e2e-testing/SKILL.md +113 -0
  133. package/templates/base/.claude/skills/playwright-e2e-testing/assets/global-setup.template.js +97 -0
  134. package/templates/base/.claude/skills/playwright-e2e-testing/assets/playwright.config.template.js +171 -0
  135. package/templates/base/.claude/skills/playwright-e2e-testing/assets/test-template.spec.js +163 -0
  136. package/templates/base/.claude/skills/playwright-e2e-testing/examples/README.md +26 -0
  137. package/templates/base/.claude/skills/playwright-e2e-testing/examples/ads.email-deeplink.spec.ts +12 -0
  138. package/templates/base/.claude/skills/playwright-e2e-testing/examples/mobile.realism.spec.ts +16 -0
  139. package/templates/base/.claude/skills/playwright-e2e-testing/examples/smoke.home.spec.ts +6 -0
  140. package/templates/base/.claude/skills/playwright-e2e-testing/references/architecture.md +578 -0
  141. package/templates/base/.claude/skills/playwright-e2e-testing/references/best-practices.md +260 -0
  142. package/templates/base/.claude/skills/playwright-e2e-testing/references/ci-reporting.md +86 -0
  143. package/templates/base/.claude/skills/playwright-e2e-testing/references/debugging.md +629 -0
  144. package/templates/base/.claude/skills/playwright-e2e-testing/references/mobile-realism.md +50 -0
  145. package/templates/base/.claude/skills/playwright-e2e-testing/references/optimization.md +488 -0
  146. package/templates/base/.claude/skills/playwright-e2e-testing/references/patterns.md +513 -0
  147. package/templates/base/.claude/skills/playwright-e2e-testing/references/resources.md +44 -0
  148. package/templates/base/.claude/skills/playwright-e2e-testing/references/visual-a11y.md +66 -0
  149. package/templates/base/.claude/skills/playwright-e2e-testing/scripts/auth-setup.js +202 -0
  150. package/templates/base/.claude/skills/playwright-e2e-testing/scripts/performance-analyzer.js +240 -0
  151. package/templates/base/.claude/skills/playwright-e2e-testing/scripts/trace-url.js +132 -0
  152. package/templates/base/.claude/skills/playwright-e2e-testing/templates/ci/github-actions.playwright.yml +78 -0
  153. package/templates/base/.claude/skills/playwright-e2e-testing/templates/fixtures.ts +44 -0
  154. package/templates/base/.claude/skills/playwright-e2e-testing/templates/global-setup.template.js +97 -0
  155. package/templates/base/.claude/skills/playwright-e2e-testing/templates/global.setup.ts +35 -0
  156. package/templates/base/.claude/skills/playwright-e2e-testing/templates/helpers/ad-gpt-observer.ts +80 -0
  157. package/templates/base/.claude/skills/playwright-e2e-testing/templates/helpers/chromium-mobile-profile.ts +93 -0
  158. package/templates/base/.claude/skills/playwright-e2e-testing/templates/playwright.config.template.js +171 -0
  159. package/templates/base/.claude/skills/playwright-e2e-testing/templates/playwright.config.ts +126 -0
  160. package/templates/base/.claude/skills/playwright-e2e-testing/templates/test-template.spec.js +163 -0
  161. package/templates/base/.claude/skills/playwright-e2e-testing/templates/tests/email-deeplink.ads.spec.ts +44 -0
  162. package/templates/base/.claude/skills/skill-rules.json +184 -0
  163. package/templates/base/.claude/skills/wrangler/SKILL.md +209 -0
  164. package/templates/base/.claude/skills/wrangler/resources/api.md +494 -0
  165. package/templates/base/.claude/skills/wrangler/resources/bundling.md +83 -0
  166. package/templates/base/.claude/skills/wrangler/resources/commands/cert.md +64 -0
  167. package/templates/base/.claude/skills/wrangler/resources/commands/check.md +66 -0
  168. package/templates/base/.claude/skills/wrangler/resources/commands/containers.md +157 -0
  169. package/templates/base/.claude/skills/wrangler/resources/commands/d1.md +843 -0
  170. package/templates/base/.claude/skills/wrangler/resources/commands/delete.md +27 -0
  171. package/templates/base/.claude/skills/wrangler/resources/commands/deploy.md +139 -0
  172. package/templates/base/.claude/skills/wrangler/resources/commands/deployments.md +56 -0
  173. package/templates/base/.claude/skills/wrangler/resources/commands/dev.md +157 -0
  174. package/templates/base/.claude/skills/wrangler/resources/commands/dispatch-namespace.md +69 -0
  175. package/templates/base/.claude/skills/wrangler/resources/commands/docs.md +61 -0
  176. package/templates/base/.claude/skills/wrangler/resources/commands/how-to-run.md +62 -0
  177. package/templates/base/.claude/skills/wrangler/resources/commands/hyperdrive.md +425 -0
  178. package/templates/base/.claude/skills/wrangler/resources/commands/init.md +31 -0
  179. package/templates/base/.claude/skills/wrangler/resources/commands/kv-bulk.md +265 -0
  180. package/templates/base/.claude/skills/wrangler/resources/commands/kv-key.md +353 -0
  181. package/templates/base/.claude/skills/wrangler/resources/commands/kv-namespace.md +265 -0
  182. package/templates/base/.claude/skills/wrangler/resources/commands/login.md +23 -0
  183. package/templates/base/.claude/skills/wrangler/resources/commands/logout.md +19 -0
  184. package/templates/base/.claude/skills/wrangler/resources/commands/mtls-certificate.md +69 -0
  185. package/templates/base/.claude/skills/wrangler/resources/commands/pages.md +175 -0
  186. package/templates/base/.claude/skills/wrangler/resources/commands/pipelines.md +76 -0
  187. package/templates/base/.claude/skills/wrangler/resources/commands/queues.md +132 -0
  188. package/templates/base/.claude/skills/wrangler/resources/commands/r2-bucket.md +342 -0
  189. package/templates/base/.claude/skills/wrangler/resources/commands/r2-object.md +267 -0
  190. package/templates/base/.claude/skills/wrangler/resources/commands/r2-sql.md +65 -0
  191. package/templates/base/.claude/skills/wrangler/resources/commands/rollback.md +40 -0
  192. package/templates/base/.claude/skills/wrangler/resources/commands/secret.md +308 -0
  193. package/templates/base/.claude/skills/wrangler/resources/commands/secrets-store-secret.md +100 -0
  194. package/templates/base/.claude/skills/wrangler/resources/commands/secrets-store-store.md +60 -0
  195. package/templates/base/.claude/skills/wrangler/resources/commands/setup.md +67 -0
  196. package/templates/base/.claude/skills/wrangler/resources/commands/tail.md +37 -0
  197. package/templates/base/.claude/skills/wrangler/resources/commands/telemetry.md +64 -0
  198. package/templates/base/.claude/skills/wrangler/resources/commands/triggers.md +39 -0
  199. package/templates/base/.claude/skills/wrangler/resources/commands/types.md +73 -0
  200. package/templates/base/.claude/skills/wrangler/resources/commands/vectorize.md +941 -0
  201. package/templates/base/.claude/skills/wrangler/resources/commands/versions.md +95 -0
  202. package/templates/base/.claude/skills/wrangler/resources/commands/whoami.md +49 -0
  203. package/templates/base/.claude/skills/wrangler/resources/commands/workflows.md +117 -0
  204. package/templates/base/.claude/skills/wrangler/resources/commands.md +138 -0
  205. package/templates/base/.claude/skills/wrangler/resources/configuration.md +2176 -0
  206. package/templates/base/.claude/skills/wrangler/resources/custom-builds.md +55 -0
  207. package/templates/base/.claude/skills/wrangler/resources/deprecations.md +279 -0
  208. package/templates/base/.claude/skills/wrangler/resources/enviroments.md +416 -0
  209. package/templates/base/.claude/skills/wrangler/resources/extract_sections.py +119 -0
  210. package/templates/base/.claude/skills/wrangler/resources/process_content.py +94 -0
  211. package/templates/base/.claude/skills/wrangler/resources/system-enviroments-variables.md +120 -0
  212. package/templates/base/.dev.vars.example +15 -0
  213. package/templates/base/.env.example +29 -0
  214. package/templates/base/.github/workflows/test.yml +127 -0
  215. package/templates/base/.nycrc.json +16 -0
  216. package/templates/base/CLAUDE.md +218 -0
  217. package/templates/base/README.md +670 -0
  218. package/templates/base/auth-setup-error.png +0 -0
  219. package/templates/base/config/drizzle.config.ts +10 -0
  220. package/templates/base/config/eslint.config.js +364 -0
  221. package/templates/base/config/wrangler.json +76 -0
  222. package/templates/base/docs/app_spec.txt +879 -0
  223. package/templates/base/docs/app_spec_template.md +681 -0
  224. package/templates/base/docs/architecture/README.md +8 -0
  225. package/templates/base/docs/architecture/data-requirements.md +109 -0
  226. package/templates/base/docs/architecture/erd.md +91 -0
  227. package/templates/base/docs/features/feature_list.json +3128 -0
  228. package/templates/base/docs/hono-boilerplate-plan.md +1774 -0
  229. package/templates/base/docs/test-coverage-gap-analysis.md +242 -0
  230. package/templates/base/docs/testing.md +188 -0
  231. package/templates/base/index.html +16 -0
  232. package/templates/base/package.json +115 -0
  233. package/templates/base/playwright.config.ts +158 -0
  234. package/templates/base/pnpm-lock.yaml +8175 -0
  235. package/templates/base/scripts/capture-prod-session.ts +250 -0
  236. package/templates/base/scripts/generate-openapi.ts +23 -0
  237. package/templates/base/scripts/init.sh +121 -0
  238. package/templates/base/src/client/__tests__/button.test.tsx +30 -0
  239. package/templates/base/src/client/__tests__/routes/__screenshots__/dashboard.test.tsx/Dashboard-Page-when-authenticated-should-display-dashboard-stats-cards-1.png +0 -0
  240. package/templates/base/src/client/__tests__/routes/__screenshots__/dashboard.test.tsx/Dashboard-Page-when-authenticated-should-display-quick-action-cards-1.png +0 -0
  241. package/templates/base/src/client/__tests__/routes/__screenshots__/dashboard.test.tsx/Dashboard-Page-when-authenticated-should-display-recent-activity-section-1.png +0 -0
  242. package/templates/base/src/client/__tests__/routes/__screenshots__/dashboard.test.tsx/Dashboard-Page-when-authenticated-should-display-user-first-name-in-welcome-message-1.png +0 -0
  243. package/templates/base/src/client/__tests__/routes/__screenshots__/dashboard.test.tsx/Dashboard-Page-when-authenticated-should-display-user-information-in-sidebar-1.png +0 -0
  244. package/templates/base/src/client/__tests__/routes/__screenshots__/dashboard.test.tsx/Dashboard-Page-when-authenticated-should-render-dashboard-when-authenticated-1.png +0 -0
  245. package/templates/base/src/client/__tests__/routes/__screenshots__/dashboard.test.tsx/Dashboard-Page-when-authenticated-should-show-navigation-sidebar-1.png +0 -0
  246. package/templates/base/src/client/__tests__/routes/__screenshots__/dashboard.test.tsx/Dashboard-Page-when-unauthenticated-should-redirect-to-login-when-not-authenticated-1.png +0 -0
  247. package/templates/base/src/client/__tests__/routes/__screenshots__/login.test.tsx/Login-Page-should-display-Google-OAuth-login-button-1.png +0 -0
  248. package/templates/base/src/client/__tests__/routes/__screenshots__/login.test.tsx/Login-Page-should-have-a-link-back-to-home-page-1.png +0 -0
  249. package/templates/base/src/client/__tests__/routes/__screenshots__/login.test.tsx/Login-Page-should-render-login-content-without-waiting-for-authentication-1.png +0 -0
  250. package/templates/base/src/client/__tests__/routes/__screenshots__/login.test.tsx/Login-Page-should-render-login-page-at--login-route-1.png +0 -0
  251. package/templates/base/src/client/__tests__/routes/__screenshots__/login.test.tsx/Login-Page-should-show-Terms-of-Service-and-Privacy-Policy-links-1.png +0 -0
  252. package/templates/base/src/client/__tests__/routes/__screenshots__/login.test.tsx/Login-Page-should-trigger-OAuth-flow-when-clicking-login-button-1.png +0 -0
  253. package/templates/base/src/client/__tests__/routes/__screenshots__/navigation.test.tsx/Navigation-404-handling-should-display-404-text-on-not-found-page-1.png +0 -0
  254. package/templates/base/src/client/__tests__/routes/__screenshots__/navigation.test.tsx/Navigation-404-handling-should-have-navigation-options-on-404-page-1.png +0 -0
  255. package/templates/base/src/client/__tests__/routes/__screenshots__/navigation.test.tsx/Navigation-404-handling-should-render-404-page-for-unknown-routes-1.png +0 -0
  256. package/templates/base/src/client/__tests__/routes/__screenshots__/navigation.test.tsx/Navigation-authenticated-navigation-should-navigate-from-dashboard-to-account-page-1.png +0 -0
  257. package/templates/base/src/client/__tests__/routes/__screenshots__/navigation.test.tsx/Navigation-authenticated-navigation-should-navigate-from-dashboard-to-integrations-page-1.png +0 -0
  258. package/templates/base/src/client/__tests__/routes/__screenshots__/navigation.test.tsx/Navigation-authenticated-navigation-should-navigate-from-dashboard-to-settings-page-1.png +0 -0
  259. package/templates/base/src/client/__tests__/routes/__screenshots__/navigation.test.tsx/Navigation-authenticated-navigation-should-navigate-from-dashboard-to-team-page-1.png +0 -0
  260. package/templates/base/src/client/__tests__/routes/__screenshots__/navigation.test.tsx/Navigation-home-page-navigation-should-display-navigation-links-on-home-page-1.png +0 -0
  261. package/templates/base/src/client/__tests__/routes/__screenshots__/navigation.test.tsx/Navigation-home-page-navigation-should-have-correct-link-destinations-on-home-page-1.png +0 -0
  262. package/templates/base/src/client/__tests__/routes/__screenshots__/navigation.test.tsx/Navigation-unauthenticated-navigation-should-allow-access-to-home-page-without-authentication-1.png +0 -0
  263. package/templates/base/src/client/__tests__/routes/__screenshots__/navigation.test.tsx/Navigation-unauthenticated-navigation-should-allow-access-to-login-page-without-authentication-1.png +0 -0
  264. package/templates/base/src/client/__tests__/routes/__screenshots__/navigation.test.tsx/Navigation-unauthenticated-navigation-should-redirect-unauthenticated-users-from-dashboard-to-login-1.png +0 -0
  265. package/templates/base/src/client/__tests__/routes/__screenshots__/navigation.test.tsx/Navigation-unauthenticated-navigation-should-redirect-unauthenticated-users-from-settings-to-login-1.png +0 -0
  266. package/templates/base/src/client/__tests__/routes/__screenshots__/navigation.test.tsx/Navigation-unauthenticated-navigation-should-redirect-unauthenticated-users-from-team-to-login-1.png +0 -0
  267. package/templates/base/src/client/__tests__/routes/authenticated-layout.test.tsx +252 -0
  268. package/templates/base/src/client/__tests__/routes/dashboard.test.tsx +136 -0
  269. package/templates/base/src/client/__tests__/routes/error-components.test.tsx +186 -0
  270. package/templates/base/src/client/__tests__/routes/login.test.tsx +112 -0
  271. package/templates/base/src/client/__tests__/routes/navigation.test.tsx +272 -0
  272. package/templates/base/src/client/__tests__/routes/root-layout.test.tsx +65 -0
  273. package/templates/base/src/client/__tests__/setup-browser.ts +15 -0
  274. package/templates/base/src/client/__tests__/setup.ts +32 -0
  275. package/templates/base/src/client/__tests__/test-utils.tsx +135 -0
  276. package/templates/base/src/client/api/.gitkeep +0 -0
  277. package/templates/base/src/client/components/__tests__/__screenshots__/sidebar.test.tsx/Sidebar-can-be-collapsed-by-default-1.png +0 -0
  278. package/templates/base/src/client/components/__tests__/__screenshots__/sidebar.test.tsx/Sidebar-expands-when-collapsed-and-expand-button-is-clicked-1.png +0 -0
  279. package/templates/base/src/client/components/__tests__/__screenshots__/sidebar.test.tsx/Sidebar-handles-logout-button-click-1.png +0 -0
  280. package/templates/base/src/client/components/__tests__/__screenshots__/sidebar.test.tsx/Sidebar-handles-navigation-clicks-1.png +0 -0
  281. package/templates/base/src/client/components/__tests__/__screenshots__/sidebar.test.tsx/Sidebar-hides-navigation-labels-when-collapsed-1.png +0 -0
  282. package/templates/base/src/client/components/__tests__/__screenshots__/sidebar.test.tsx/Sidebar-highlights-active-route-1.png +0 -0
  283. package/templates/base/src/client/components/__tests__/__screenshots__/sidebar.test.tsx/Sidebar-renders-sidebar-navigation-items-1.png +0 -0
  284. package/templates/base/src/client/components/__tests__/__screenshots__/sidebar.test.tsx/Sidebar-shows-keyboard-shortcut-hint-when-expanded-1.png +0 -0
  285. package/templates/base/src/client/components/__tests__/__screenshots__/sidebar.test.tsx/Sidebar-shows-user-info-when-authenticated-1.png +0 -0
  286. package/templates/base/src/client/components/__tests__/__screenshots__/sidebar.test.tsx/Sidebar-shows-user-initials-in-avatar-fallback-1.png +0 -0
  287. package/templates/base/src/client/components/__tests__/error-boundary.test.tsx +97 -0
  288. package/templates/base/src/client/components/__tests__/sidebar.test.tsx +281 -0
  289. package/templates/base/src/client/components/error-boundary.tsx +68 -0
  290. package/templates/base/src/client/components/icons.tsx +106 -0
  291. package/templates/base/src/client/components/layout/.gitkeep +0 -0
  292. package/templates/base/src/client/components/sidebar.tsx +267 -0
  293. package/templates/base/src/client/components/ui/.gitkeep +0 -0
  294. package/templates/base/src/client/components/ui/__tests__/avatar.test.tsx +308 -0
  295. package/templates/base/src/client/components/ui/__tests__/card.test.tsx +214 -0
  296. package/templates/base/src/client/components/ui/__tests__/dialog.test.tsx +297 -0
  297. package/templates/base/src/client/components/ui/__tests__/error-fallback.test.tsx +145 -0
  298. package/templates/base/src/client/components/ui/__tests__/input.test.tsx +98 -0
  299. package/templates/base/src/client/components/ui/__tests__/loading-skeleton.test.tsx +139 -0
  300. package/templates/base/src/client/components/ui/__tests__/skeleton.test.tsx +44 -0
  301. package/templates/base/src/client/components/ui/__tests__/sonner.test.tsx +28 -0
  302. package/templates/base/src/client/components/ui/__tests__/tabs.test.tsx +233 -0
  303. package/templates/base/src/client/components/ui/avatar.tsx +101 -0
  304. package/templates/base/src/client/components/ui/badge.tsx +46 -0
  305. package/templates/base/src/client/components/ui/button.tsx +72 -0
  306. package/templates/base/src/client/components/ui/card.tsx +86 -0
  307. package/templates/base/src/client/components/ui/dialog.tsx +140 -0
  308. package/templates/base/src/client/components/ui/error-fallback.tsx +179 -0
  309. package/templates/base/src/client/components/ui/form.tsx +172 -0
  310. package/templates/base/src/client/components/ui/input.tsx +24 -0
  311. package/templates/base/src/client/components/ui/label.tsx +22 -0
  312. package/templates/base/src/client/components/ui/loading-skeleton.tsx +154 -0
  313. package/templates/base/src/client/components/ui/separator.tsx +33 -0
  314. package/templates/base/src/client/components/ui/skeleton.tsx +16 -0
  315. package/templates/base/src/client/components/ui/sonner.tsx +29 -0
  316. package/templates/base/src/client/components/ui/tabs.tsx +121 -0
  317. package/templates/base/src/client/hooks/.gitkeep +0 -0
  318. package/templates/base/src/client/hooks/__tests__/use-auth.test.tsx +306 -0
  319. package/templates/base/src/client/hooks/__tests__/use-theme.test.tsx +172 -0
  320. package/templates/base/src/client/hooks/use-auth.ts +53 -0
  321. package/templates/base/src/client/hooks/use-theme.tsx +78 -0
  322. package/templates/base/src/client/index.css +881 -0
  323. package/templates/base/src/client/lib/query-client.ts +11 -0
  324. package/templates/base/src/client/lib/utils.ts +7 -0
  325. package/templates/base/src/client/main.tsx +26 -0
  326. package/templates/base/src/client/routeTree.gen.ts +258 -0
  327. package/templates/base/src/client/router.ts +15 -0
  328. package/templates/base/src/client/routes/$.tsx +77 -0
  329. package/templates/base/src/client/routes/.gitkeep +0 -0
  330. package/templates/base/src/client/routes/__root.tsx +34 -0
  331. package/templates/base/src/client/routes/__tests__/__screenshots__/invite.test.tsx/Invite-Token-Page-pending-invitation-state-should-display-accept-invitation-button-1.png +0 -0
  332. package/templates/base/src/client/routes/__tests__/__screenshots__/invite.test.tsx/Invite-Token-Page-pending-invitation-state-should-display-decline-button-linking-to-homepage-1.png +0 -0
  333. package/templates/base/src/client/routes/__tests__/__screenshots__/invite.test.tsx/Invite-Token-Page-pending-invitation-state-should-display-invitation-details--email--workspace--role--1.png +0 -0
  334. package/templates/base/src/client/routes/__tests__/__screenshots__/invite.test.tsx/Invite-Token-Page-pending-invitation-state-should-have-a-logo-link-to-homepage-1.png +0 -0
  335. package/templates/base/src/client/routes/__tests__/__screenshots__/invite.test.tsx/Invite-Token-Page-pending-invitation-state-should-render-invitation-page-with-inviter-name-and-workspace-1.png +0 -0
  336. package/templates/base/src/client/routes/__tests__/__screenshots__/invite.test.tsx/Invite-Token-Page-pending-invitation-state-should-show-terms-of-service-and-privacy-policy-links-1.png +0 -0
  337. package/templates/base/src/client/routes/__tests__/invite.test.tsx +138 -0
  338. package/templates/base/src/client/routes/_authenticated/__tests__/__screenshots__/account.test.tsx/Account-Page-should-render-Active-Sessions-section-with-session-cards-1.png +0 -0
  339. package/templates/base/src/client/routes/_authenticated/__tests__/__screenshots__/account.test.tsx/Account-Page-should-render-page-with-correct-title--Account--1.png +0 -0
  340. package/templates/base/src/client/routes/_authenticated/__tests__/__screenshots__/account.test.tsx/Account-Page-should-show-API-Access-section-1.png +0 -0
  341. package/templates/base/src/client/routes/_authenticated/__tests__/__screenshots__/account.test.tsx/Account-Page-should-show-Connected-Accounts-section-with-Google-connected-1.png +0 -0
  342. package/templates/base/src/client/routes/_authenticated/__tests__/__screenshots__/account.test.tsx/Account-Page-should-show-Danger-Zone-section-with-delete-button-1.png +0 -0
  343. package/templates/base/src/client/routes/_authenticated/__tests__/__screenshots__/account.test.tsx/Account-Page-should-show-Security-section-with-Two-Factor-Authentication-1.png +0 -0
  344. package/templates/base/src/client/routes/_authenticated/__tests__/__screenshots__/integrations.test.tsx/Integrations-Page-API-documentation-section-should-display-API-documentation-link-section-1.png +0 -0
  345. package/templates/base/src/client/routes/_authenticated/__tests__/__screenshots__/integrations.test.tsx/Integrations-Page-Create-Webhook-Dialog-should-have-Add-Webhook-trigger-button-1.png +0 -0
  346. package/templates/base/src/client/routes/_authenticated/__tests__/__screenshots__/integrations.test.tsx/Integrations-Page-category-filters-should-display-all-category-buttons-1.png +0 -0
  347. package/templates/base/src/client/routes/_authenticated/__tests__/__screenshots__/integrations.test.tsx/Integrations-Page-integration-cards-should-display-all-integration-cards-with-names-1.png +0 -0
  348. package/templates/base/src/client/routes/_authenticated/__tests__/__screenshots__/integrations.test.tsx/Integrations-Page-integration-cards-should-display-category-badges-on-cards-1.png +0 -0
  349. package/templates/base/src/client/routes/_authenticated/__tests__/__screenshots__/integrations.test.tsx/Integrations-Page-integration-cards-should-show-Configure-button-for-connected-integrations-1.png +0 -0
  350. package/templates/base/src/client/routes/_authenticated/__tests__/__screenshots__/integrations.test.tsx/Integrations-Page-integration-cards-should-show-Connect-button-for-not-connected-integrations-1.png +0 -0
  351. package/templates/base/src/client/routes/_authenticated/__tests__/__screenshots__/integrations.test.tsx/Integrations-Page-integration-cards-should-show-Connected-badge-for-connected-integrations-1.png +0 -0
  352. package/templates/base/src/client/routes/_authenticated/__tests__/__screenshots__/integrations.test.tsx/Integrations-Page-page-rendering-should-display-Available-Integrations-section-1.png +0 -0
  353. package/templates/base/src/client/routes/_authenticated/__tests__/__screenshots__/integrations.test.tsx/Integrations-Page-page-rendering-should-display-Webhooks-section-1.png +0 -0
  354. package/templates/base/src/client/routes/_authenticated/__tests__/__screenshots__/integrations.test.tsx/Integrations-Page-page-rendering-should-display-connected-count-1.png +0 -0
  355. package/templates/base/src/client/routes/_authenticated/__tests__/__screenshots__/integrations.test.tsx/Integrations-Page-page-rendering-should-display-page-description-1.png +0 -0
  356. package/templates/base/src/client/routes/_authenticated/__tests__/__screenshots__/integrations.test.tsx/Integrations-Page-page-rendering-should-display-search-input-1.png +0 -0
  357. package/templates/base/src/client/routes/_authenticated/__tests__/__screenshots__/integrations.test.tsx/Integrations-Page-page-rendering-should-render-with-correct-title--Integrations--1.png +0 -0
  358. package/templates/base/src/client/routes/_authenticated/__tests__/__screenshots__/integrations.test.tsx/Integrations-Page-search-functionality-should-filter-integrations-based-on-search-query-1.png +0 -0
  359. package/templates/base/src/client/routes/_authenticated/__tests__/__screenshots__/integrations.test.tsx/Integrations-Page-search-functionality-should-search-by-description-1.png +0 -0
  360. package/templates/base/src/client/routes/_authenticated/__tests__/__screenshots__/integrations.test.tsx/Integrations-Page-search-functionality-should-show-no-results-message-when-search-has-no-matches-1.png +0 -0
  361. package/templates/base/src/client/routes/_authenticated/__tests__/__screenshots__/integrations.test.tsx/Integrations-Page-webhooks-section-should-display-existing-webhook-1.png +0 -0
  362. package/templates/base/src/client/routes/_authenticated/__tests__/__screenshots__/integrations.test.tsx/Integrations-Page-webhooks-section-should-display-webhook-events-1.png +0 -0
  363. package/templates/base/src/client/routes/_authenticated/__tests__/__screenshots__/integrations.test.tsx/Integrations-Page-webhooks-section-should-display-webhook-last-delivery-info-1.png +0 -0
  364. package/templates/base/src/client/routes/_authenticated/__tests__/__screenshots__/integrations.test.tsx/Integrations-Page-webhooks-section-should-display-webhook-success-status-1.png +0 -0
  365. package/templates/base/src/client/routes/_authenticated/__tests__/__screenshots__/integrations.test.tsx/Integrations-Page-webhooks-section-should-have-Add-Webhook-button-1.png +0 -0
  366. package/templates/base/src/client/routes/_authenticated/__tests__/__screenshots__/settings.test.tsx/Settings-Page-Account-tab-should-display-connected-accounts-section-with-Google-provider-1.png +0 -0
  367. package/templates/base/src/client/routes/_authenticated/__tests__/__screenshots__/settings.test.tsx/Settings-Page-Account-tab-should-display-sessions-and-danger-zone-sections-1.png +0 -0
  368. package/templates/base/src/client/routes/_authenticated/__tests__/__screenshots__/settings.test.tsx/Settings-Page-Notifications-tab-should-display-all-notification-toggle-options-1.png +0 -0
  369. package/templates/base/src/client/routes/_authenticated/__tests__/__screenshots__/settings.test.tsx/Settings-Page-Notifications-tab-should-display-email-notifications-section-1.png +0 -0
  370. package/templates/base/src/client/routes/_authenticated/__tests__/__screenshots__/settings.test.tsx/Settings-Page-Notifications-tab-should-display-toggle-switches-for-notification-options-1.png +0 -0
  371. package/templates/base/src/client/routes/_authenticated/__tests__/__screenshots__/settings.test.tsx/Settings-Page-Notifications-tab-should-have-toggles-checked-by-default-1.png +0 -0
  372. package/templates/base/src/client/routes/_authenticated/__tests__/__screenshots__/settings.test.tsx/Settings-Page-Profile-tab-should-display--Save-Changes--button-1.png +0 -0
  373. package/templates/base/src/client/routes/_authenticated/__tests__/__screenshots__/settings.test.tsx/Settings-Page-Profile-tab-should-display-personal-information-form-1.png +0 -0
  374. package/templates/base/src/client/routes/_authenticated/__tests__/__screenshots__/settings.test.tsx/Settings-Page-Profile-tab-should-display-profile-picture-section-1.png +0 -0
  375. package/templates/base/src/client/routes/_authenticated/__tests__/__screenshots__/settings.test.tsx/Settings-Page-Profile-tab-should-display-user-email-in-disabled-email-input-1.png +0 -0
  376. package/templates/base/src/client/routes/_authenticated/__tests__/__screenshots__/settings.test.tsx/Settings-Page-Profile-tab-should-display-user-initials-in-avatar-1.png +0 -0
  377. package/templates/base/src/client/routes/_authenticated/__tests__/__screenshots__/settings.test.tsx/Settings-Page-Profile-tab-should-display-user-name-in-the-name-input-1.png +0 -0
  378. package/templates/base/src/client/routes/_authenticated/__tests__/__screenshots__/settings.test.tsx/Settings-Page-page-rendering-should-display-all-three-tabs-1.png +0 -0
  379. package/templates/base/src/client/routes/_authenticated/__tests__/__screenshots__/settings.test.tsx/Settings-Page-page-rendering-should-display-page-description-1.png +0 -0
  380. package/templates/base/src/client/routes/_authenticated/__tests__/__screenshots__/settings.test.tsx/Settings-Page-page-rendering-should-render-with-correct-title--Settings--1.png +0 -0
  381. package/templates/base/src/client/routes/_authenticated/__tests__/__screenshots__/settings.test.tsx/Settings-Page-tab-navigation-should-show-Profile-tab-as-default-active-tab-1.png +0 -0
  382. package/templates/base/src/client/routes/_authenticated/__tests__/__screenshots__/settings.test.tsx/Settings-Page-tab-navigation-should-switch-to-Account-tab-when-clicked-1.png +0 -0
  383. package/templates/base/src/client/routes/_authenticated/__tests__/__screenshots__/settings.test.tsx/Settings-Page-tab-navigation-should-switch-to-Notifications-tab-when-clicked-1.png +0 -0
  384. package/templates/base/src/client/routes/_authenticated/__tests__/__screenshots__/team.test.tsx/Team-Page-should-display-Active-Members-section-with-member-count-1.png +0 -0
  385. package/templates/base/src/client/routes/_authenticated/__tests__/__screenshots__/team.test.tsx/Team-Page-should-display-Pending-Invitations-section-with-invitation-details-1.png +0 -0
  386. package/templates/base/src/client/routes/_authenticated/__tests__/__screenshots__/team.test.tsx/Team-Page-should-have-invite-member-button-that-can-be-clicked-1.png +0 -0
  387. package/templates/base/src/client/routes/_authenticated/__tests__/__screenshots__/team.test.tsx/Team-Page-should-render-page-with-correct-title-and-description-1.png +0 -0
  388. package/templates/base/src/client/routes/_authenticated/__tests__/__screenshots__/team.test.tsx/Team-Page-should-render-search-input-that-filters-team-members-1.png +0 -0
  389. package/templates/base/src/client/routes/_authenticated/__tests__/__screenshots__/team.test.tsx/Team-Page-should-show-current-user-with---you---indicator-and-role-badge-1.png +0 -0
  390. package/templates/base/src/client/routes/_authenticated/__tests__/account.test.tsx +324 -0
  391. package/templates/base/src/client/routes/_authenticated/__tests__/integrations.test.tsx +520 -0
  392. package/templates/base/src/client/routes/_authenticated/__tests__/settings.test.tsx +414 -0
  393. package/templates/base/src/client/routes/_authenticated/__tests__/team.test.tsx +374 -0
  394. package/templates/base/src/client/routes/_authenticated/account.tsx +416 -0
  395. package/templates/base/src/client/routes/_authenticated/dashboard.tsx +151 -0
  396. package/templates/base/src/client/routes/_authenticated/integrations.tsx +553 -0
  397. package/templates/base/src/client/routes/_authenticated/settings.tsx +310 -0
  398. package/templates/base/src/client/routes/_authenticated/team.tsx +395 -0
  399. package/templates/base/src/client/routes/_authenticated.tsx +69 -0
  400. package/templates/base/src/client/routes/index.tsx +155 -0
  401. package/templates/base/src/client/routes/invite.$token.tsx +191 -0
  402. package/templates/base/src/client/routes/login.tsx +92 -0
  403. package/templates/base/src/server/__tests__/fixtures.ts +461 -0
  404. package/templates/base/src/server/__tests__/mocks/__tests__/db.test.ts +239 -0
  405. package/templates/base/src/server/__tests__/mocks/__tests__/kv.test.ts +293 -0
  406. package/templates/base/src/server/__tests__/mocks/__tests__/r2.test.ts +363 -0
  407. package/templates/base/src/server/__tests__/mocks/db.ts +186 -0
  408. package/templates/base/src/server/__tests__/mocks/index.ts +33 -0
  409. package/templates/base/src/server/__tests__/mocks/kv.ts +286 -0
  410. package/templates/base/src/server/__tests__/mocks/r2.ts +397 -0
  411. package/templates/base/src/server/__tests__/setup.ts +281 -0
  412. package/templates/base/src/server/auth/__tests__/guards.test.ts +162 -0
  413. package/templates/base/src/server/auth/guards.ts +92 -0
  414. package/templates/base/src/server/auth/permissions.test.ts +45 -0
  415. package/templates/base/src/server/auth/permissions.ts +139 -0
  416. package/templates/base/src/server/auth/roles.test.ts +169 -0
  417. package/templates/base/src/server/auth/roles.ts +141 -0
  418. package/templates/base/src/server/db/client.ts +12 -0
  419. package/templates/base/src/server/db/schema/accounts.ts +20 -0
  420. package/templates/base/src/server/db/schema/audit-logs.ts +26 -0
  421. package/templates/base/src/server/db/schema/index.ts +7 -0
  422. package/templates/base/src/server/db/schema/invitations.ts +30 -0
  423. package/templates/base/src/server/db/schema/refresh-tokens.ts +22 -0
  424. package/templates/base/src/server/db/schema/user-accounts.ts +25 -0
  425. package/templates/base/src/server/db/schema/users.ts +33 -0
  426. package/templates/base/src/server/db/seed.ts +267 -0
  427. package/templates/base/src/server/env.test.ts +84 -0
  428. package/templates/base/src/server/env.ts +78 -0
  429. package/templates/base/src/server/index.ts +82 -0
  430. package/templates/base/src/server/lib/audit.ts +73 -0
  431. package/templates/base/src/server/lib/audited-db.test.ts +107 -0
  432. package/templates/base/src/server/lib/audited-db.ts +154 -0
  433. package/templates/base/src/server/lib/email.test.ts +116 -0
  434. package/templates/base/src/server/lib/email.ts +82 -0
  435. package/templates/base/src/server/lib/errors.test.ts +49 -0
  436. package/templates/base/src/server/lib/errors.ts +64 -0
  437. package/templates/base/src/server/lib/oauth.test.ts +238 -0
  438. package/templates/base/src/server/lib/oauth.ts +113 -0
  439. package/templates/base/src/server/lib/pagination.test.ts +52 -0
  440. package/templates/base/src/server/lib/pagination.ts +32 -0
  441. package/templates/base/src/server/lib/password.test.ts +151 -0
  442. package/templates/base/src/server/lib/password.ts +151 -0
  443. package/templates/base/src/server/lib/providers.test.ts +105 -0
  444. package/templates/base/src/server/lib/providers.ts +62 -0
  445. package/templates/base/src/server/lib/r2-storage.test.ts +202 -0
  446. package/templates/base/src/server/lib/r2-storage.ts +107 -0
  447. package/templates/base/src/server/lib/schema-helpers.ts +16 -0
  448. package/templates/base/src/server/lib/session.test.ts +758 -0
  449. package/templates/base/src/server/lib/session.ts +267 -0
  450. package/templates/base/src/server/lib/tokens.test.ts +208 -0
  451. package/templates/base/src/server/lib/tokens.ts +65 -0
  452. package/templates/base/src/server/lib/transaction.test.ts +45 -0
  453. package/templates/base/src/server/lib/transaction.ts +24 -0
  454. package/templates/base/src/server/middleware/account.test.ts +201 -0
  455. package/templates/base/src/server/middleware/account.ts +66 -0
  456. package/templates/base/src/server/middleware/auth.test.ts +345 -0
  457. package/templates/base/src/server/middleware/auth.ts +146 -0
  458. package/templates/base/src/server/middleware/cors.test.ts +88 -0
  459. package/templates/base/src/server/middleware/cors.ts +26 -0
  460. package/templates/base/src/server/middleware/error-handler.test.ts +69 -0
  461. package/templates/base/src/server/middleware/error-handler.ts +43 -0
  462. package/templates/base/src/server/middleware/index.ts +8 -0
  463. package/templates/base/src/server/middleware/rate-limit.test.ts +472 -0
  464. package/templates/base/src/server/middleware/rate-limit.ts +294 -0
  465. package/templates/base/src/server/middleware/request-context.test.ts +175 -0
  466. package/templates/base/src/server/middleware/request-context.ts +28 -0
  467. package/templates/base/src/server/middleware/request-logger.test.ts +92 -0
  468. package/templates/base/src/server/middleware/request-logger.ts +50 -0
  469. package/templates/base/src/server/routes/accounts/__tests__/handlers.test.ts +460 -0
  470. package/templates/base/src/server/routes/accounts/handlers.ts +179 -0
  471. package/templates/base/src/server/routes/accounts/index.ts +55 -0
  472. package/templates/base/src/server/routes/accounts/routes.ts +205 -0
  473. package/templates/base/src/server/routes/accounts/schemas.ts +31 -0
  474. package/templates/base/src/server/routes/api.ts +37 -0
  475. package/templates/base/src/server/routes/audits/__tests__/handlers.test.ts +349 -0
  476. package/templates/base/src/server/routes/audits/handlers.ts +37 -0
  477. package/templates/base/src/server/routes/audits/index.ts +14 -0
  478. package/templates/base/src/server/routes/audits/routes.ts +29 -0
  479. package/templates/base/src/server/routes/audits/schemas.ts +43 -0
  480. package/templates/base/src/server/routes/auth/__tests__/handlers.test.ts +381 -0
  481. package/templates/base/src/server/routes/auth/handlers.ts +222 -0
  482. package/templates/base/src/server/routes/auth/index.ts +37 -0
  483. package/templates/base/src/server/routes/auth/routes.ts +136 -0
  484. package/templates/base/src/server/routes/auth/schemas.ts +48 -0
  485. package/templates/base/src/server/routes/auth/test-login.ts +156 -0
  486. package/templates/base/src/server/routes/health/__tests__/handlers.test.ts +237 -0
  487. package/templates/base/src/server/routes/health/handlers.ts +83 -0
  488. package/templates/base/src/server/routes/health/index.ts +13 -0
  489. package/templates/base/src/server/routes/health/routes.ts +90 -0
  490. package/templates/base/src/server/routes/index.ts +53 -0
  491. package/templates/base/src/server/routes/invitations/__tests__/handlers.test.ts +473 -0
  492. package/templates/base/src/server/routes/invitations/handlers.ts +71 -0
  493. package/templates/base/src/server/routes/invitations/index.ts +25 -0
  494. package/templates/base/src/server/routes/invitations/routes.ts +69 -0
  495. package/templates/base/src/server/routes/invitations/schemas.ts +39 -0
  496. package/templates/base/src/server/routes/openapi.ts +14 -0
  497. package/templates/base/src/server/routes/schemas.ts +53 -0
  498. package/templates/base/src/server/routes/storage/__tests__/handlers.test.ts +408 -0
  499. package/templates/base/src/server/routes/storage/handlers.ts +100 -0
  500. package/templates/base/src/server/routes/storage/index.ts +42 -0
  501. package/templates/base/src/server/routes/storage/routes.ts +91 -0
  502. package/templates/base/src/server/routes/storage/schemas.ts +56 -0
  503. package/templates/base/src/server/routes/users/__tests__/handlers.test.ts +526 -0
  504. package/templates/base/src/server/routes/users/handlers.ts +228 -0
  505. package/templates/base/src/server/routes/users/index.ts +67 -0
  506. package/templates/base/src/server/routes/users/routes.ts +265 -0
  507. package/templates/base/src/server/routes/users/schemas.ts +67 -0
  508. package/templates/base/src/server/services/__tests__/accounts.test.ts +764 -0
  509. package/templates/base/src/server/services/__tests__/audits.test.ts +235 -0
  510. package/templates/base/src/server/services/__tests__/auth.test.ts +765 -0
  511. package/templates/base/src/server/services/__tests__/invitations.test.ts +704 -0
  512. package/templates/base/src/server/services/__tests__/users.test.ts +755 -0
  513. package/templates/base/src/server/services/accounts.ts +269 -0
  514. package/templates/base/src/server/services/audits.ts +82 -0
  515. package/templates/base/src/server/services/auth.ts +225 -0
  516. package/templates/base/src/server/services/index.ts +6 -0
  517. package/templates/base/src/server/services/invitations.ts +306 -0
  518. package/templates/base/src/server/services/users.ts +350 -0
  519. package/templates/base/src/server/types/auth.ts +36 -0
  520. package/templates/base/src/server/types/index.ts +117 -0
  521. package/templates/base/src/shared/schemas/.gitkeep +0 -0
  522. package/templates/base/src/shared/schemas/__tests__/schemas.test.ts +547 -0
  523. package/templates/base/src/shared/schemas/account.ts +15 -0
  524. package/templates/base/src/shared/schemas/index.ts +6 -0
  525. package/templates/base/src/shared/schemas/invitation.ts +9 -0
  526. package/templates/base/src/shared/schemas/profile.ts +10 -0
  527. package/templates/base/src/shared/schemas/user.ts +16 -0
  528. package/templates/base/src/shared/schemas/webhook.ts +12 -0
  529. package/templates/base/src/shared/types/.gitkeep +0 -0
  530. package/templates/base/src/shared/types/account.ts +12 -0
  531. package/templates/base/src/shared/types/api.ts +1399 -0
  532. package/templates/base/src/shared/types/auth.ts +24 -0
  533. package/templates/base/src/shared/types/index.ts +5 -0
  534. package/templates/base/src/shared/types/user.ts +31 -0
  535. package/templates/base/src/test/vitest-zod-matcher.ts +37 -0
  536. package/templates/base/src/test/vitest.d.ts +19 -0
  537. package/templates/base/tests/e2e/README.md +141 -0
  538. package/templates/base/tests/e2e/a11y/accessibility.spec.ts +925 -0
  539. package/templates/base/tests/e2e/a11y/keyboard-navigation.spec.ts +610 -0
  540. package/templates/base/tests/e2e/api/accounts.spec.ts +148 -0
  541. package/templates/base/tests/e2e/api/audit-logs.spec.ts +130 -0
  542. package/templates/base/tests/e2e/api/authenticated-api.spec.ts +311 -0
  543. package/templates/base/tests/e2e/api/storage.spec.ts +109 -0
  544. package/templates/base/tests/e2e/auth-flows.unauth.spec.ts +117 -0
  545. package/templates/base/tests/e2e/auth-logout.unauth.spec.ts +103 -0
  546. package/templates/base/tests/e2e/auth.setup.ts +115 -0
  547. package/templates/base/tests/e2e/auth.spec.ts +146 -0
  548. package/templates/base/tests/e2e/compatibility/cross-browser.spec.ts +152 -0
  549. package/templates/base/tests/e2e/compatibility/cross-browser.spec.ts-snapshots/login-chromium-chromium-darwin.png +0 -0
  550. package/templates/base/tests/e2e/crud/account.spec.ts +356 -0
  551. package/templates/base/tests/e2e/crud/integrations.spec.ts +419 -0
  552. package/templates/base/tests/e2e/crud/team.spec.ts +287 -0
  553. package/templates/base/tests/e2e/crud/users.spec.ts +239 -0
  554. package/templates/base/tests/e2e/errors/error-boundary.spec.ts +428 -0
  555. package/templates/base/tests/e2e/errors/error-handling.spec.ts +47 -0
  556. package/templates/base/tests/e2e/errors/error-handling.unauth.spec.ts +205 -0
  557. package/templates/base/tests/e2e/fixtures.ts +266 -0
  558. package/templates/base/tests/e2e/forms/validation.spec.ts +569 -0
  559. package/templates/base/tests/e2e/invitations/invite-flow.unauth.spec.ts +204 -0
  560. package/templates/base/tests/e2e/journeys/account-lifecycle.spec.ts +314 -0
  561. package/templates/base/tests/e2e/journeys/audit-investigation.spec.ts +299 -0
  562. package/templates/base/tests/e2e/journeys/auth-onboarding.spec.ts +232 -0
  563. package/templates/base/tests/e2e/journeys/critical-flows.spec.ts +281 -0
  564. package/templates/base/tests/e2e/journeys/error-recovery.spec.ts +354 -0
  565. package/templates/base/tests/e2e/journeys/file-management.spec.ts +307 -0
  566. package/templates/base/tests/e2e/journeys/integrations.spec.ts +372 -0
  567. package/templates/base/tests/e2e/journeys/multi-account.spec.ts +317 -0
  568. package/templates/base/tests/e2e/journeys/rbac-enforcement.spec.ts +389 -0
  569. package/templates/base/tests/e2e/journeys/settings-profile.spec.ts +400 -0
  570. package/templates/base/tests/e2e/journeys/team-collaboration.spec.ts +410 -0
  571. package/templates/base/tests/e2e/mobile/responsive.spec.ts +178 -0
  572. package/templates/base/tests/e2e/navigation/routing.spec.ts +371 -0
  573. package/templates/base/tests/e2e/navigation/sidebar.spec.ts +425 -0
  574. package/templates/base/tests/e2e/pages/ui-features.spec.ts +393 -0
  575. package/templates/base/tests/e2e/performance/baselines.spec.ts +162 -0
  576. package/templates/base/tests/e2e/performance/benchmarks.spec.ts +371 -0
  577. package/templates/base/tests/e2e/smoke.unauth.spec.ts +196 -0
  578. package/templates/base/tests/e2e/visual/components.spec.ts +650 -0
  579. package/templates/base/tests/e2e/visual/components.spec.ts-snapshots/confirmation-dialog-visual-darwin.png +0 -0
  580. package/templates/base/tests/e2e/visual/components.spec.ts-snapshots/dark-mode-background-visual-darwin.png +0 -0
  581. package/templates/base/tests/e2e/visual/components.spec.ts-snapshots/dark-mode-card-visual-darwin.png +0 -0
  582. package/templates/base/tests/e2e/visual/components.spec.ts-snapshots/dark-mode-sidebar-visual-darwin.png +0 -0
  583. package/templates/base/tests/e2e/visual/components.spec.ts-snapshots/dashboard-card-single-visual-darwin.png +0 -0
  584. package/templates/base/tests/e2e/visual/components.spec.ts-snapshots/dialog-content-visual-darwin.png +0 -0
  585. package/templates/base/tests/e2e/visual/components.spec.ts-snapshots/dialog-with-backdrop-visual-darwin.png +0 -0
  586. package/templates/base/tests/e2e/visual/components.spec.ts-snapshots/empty-search-results-visual-darwin.png +0 -0
  587. package/templates/base/tests/e2e/visual/components.spec.ts-snapshots/input-default-visual-darwin.png +0 -0
  588. package/templates/base/tests/e2e/visual/components.spec.ts-snapshots/input-focus-ring-visual-darwin.png +0 -0
  589. package/templates/base/tests/e2e/visual/components.spec.ts-snapshots/primary-button-focus-visual-darwin.png +0 -0
  590. package/templates/base/tests/e2e/visual/components.spec.ts-snapshots/primary-button-hover-visual-darwin.png +0 -0
  591. package/templates/base/tests/e2e/visual/components.spec.ts-snapshots/primary-button-visual-darwin.png +0 -0
  592. package/templates/base/tests/e2e/visual/components.spec.ts-snapshots/sidebar-active-nav-item-visual-darwin.png +0 -0
  593. package/templates/base/tests/e2e/visual/components.spec.ts-snapshots/sidebar-collapsed-visual-darwin.png +0 -0
  594. package/templates/base/tests/e2e/visual/components.spec.ts-snapshots/sidebar-navigation-visual-darwin.png +0 -0
  595. package/templates/base/tests/e2e/visual/core-components.spec.ts +192 -0
  596. package/templates/base/tests/e2e/visual/core-components.spec.ts-snapshots/account-page-visual-darwin.png +0 -0
  597. package/templates/base/tests/e2e/visual/core-components.spec.ts-snapshots/create-webhook-dialog-visual-darwin.png +0 -0
  598. package/templates/base/tests/e2e/visual/core-components.spec.ts-snapshots/dashboard-page-visual-darwin.png +0 -0
  599. package/templates/base/tests/e2e/visual/core-components.spec.ts-snapshots/delete-account-dialog-visual-darwin.png +0 -0
  600. package/templates/base/tests/e2e/visual/core-components.spec.ts-snapshots/integrations-page-visual-darwin.png +0 -0
  601. package/templates/base/tests/e2e/visual/core-components.spec.ts-snapshots/invite-member-dialog-visual-darwin.png +0 -0
  602. package/templates/base/tests/e2e/visual/core-components.spec.ts-snapshots/login-page-visual-darwin.png +0 -0
  603. package/templates/base/tests/e2e/visual/core-components.spec.ts-snapshots/settings-account-tab-visual-darwin.png +0 -0
  604. package/templates/base/tests/e2e/visual/core-components.spec.ts-snapshots/settings-profile-tab-visual-darwin.png +0 -0
  605. package/templates/base/tests/e2e/visual/core-components.spec.ts-snapshots/sidebar-navigation-visual-darwin.png +0 -0
  606. package/templates/base/tests/e2e/visual/core-components.spec.ts-snapshots/team-page-visual-darwin.png +0 -0
  607. package/templates/base/tests/e2e/visual/screenshots.spec.ts +230 -0
  608. package/templates/base/tests/e2e/visual/screenshots.spec.ts-snapshots/404-page-chromium-darwin.png +0 -0
  609. package/templates/base/tests/e2e/visual/screenshots.spec.ts-snapshots/404-page-visual-darwin.png +0 -0
  610. package/templates/base/tests/e2e/visual/screenshots.spec.ts-snapshots/account-page-visual-darwin.png +0 -0
  611. package/templates/base/tests/e2e/visual/screenshots.spec.ts-snapshots/login-page-chromium-darwin.png +0 -0
  612. package/templates/base/tests/e2e/visual/screenshots.spec.ts-snapshots/login-page-visual-darwin.png +0 -0
  613. package/templates/base/tests/e2e/visual/screenshots.spec.ts-snapshots/settings-page-visual-darwin.png +0 -0
  614. package/templates/base/tests/e2e/visual/screenshots.spec.ts-snapshots/team-invite-dialog-visual-darwin.png +0 -0
  615. package/templates/base/tests/e2e/visual/screenshots.spec.ts-snapshots/team-page-visual-darwin.png +0 -0
  616. package/templates/base/tests/e2e/visual/screenshots.spec.ts-snapshots/webhook-create-dialog-visual-darwin.png +0 -0
  617. package/templates/base/tests/e2e/visual/theme-colors.spec.ts +293 -0
  618. package/templates/base/tests/e2e/visual/ui-components.spec.ts +502 -0
  619. package/templates/base/tests/integration/accounts/crud.test.ts +1402 -0
  620. package/templates/base/tests/integration/audits/list.test.ts +1133 -0
  621. package/templates/base/tests/integration/auth/auth-service.test.ts +415 -0
  622. package/templates/base/tests/integration/auth/invitation-token.test.ts +529 -0
  623. package/templates/base/tests/integration/auth/logout.test.ts +524 -0
  624. package/templates/base/tests/integration/auth/oauth.test.ts +768 -0
  625. package/templates/base/tests/integration/auth/refresh-token.test.ts +364 -0
  626. package/templates/base/tests/integration/auth/session-expiry.test.ts +569 -0
  627. package/templates/base/tests/integration/auth/session.test.ts +520 -0
  628. package/templates/base/tests/integration/auth/super-admin.test.ts +451 -0
  629. package/templates/base/tests/integration/authorization/analytics-role.test.ts +1026 -0
  630. package/templates/base/tests/integration/authorization/billing-role.test.ts +776 -0
  631. package/templates/base/tests/integration/authorization/guards-roles.test.ts +539 -0
  632. package/templates/base/tests/integration/authorization/multi-tenancy.test.ts +1112 -0
  633. package/templates/base/tests/integration/authorization/role-hierarchy.test.ts +931 -0
  634. package/templates/base/tests/integration/authorization/roles.test.ts +1347 -0
  635. package/templates/base/tests/integration/config/production-behavior.test.ts +536 -0
  636. package/templates/base/tests/integration/db/constraints.test.ts +695 -0
  637. package/templates/base/tests/integration/fixtures/accounts.ts +136 -0
  638. package/templates/base/tests/integration/fixtures/index.ts +232 -0
  639. package/templates/base/tests/integration/fixtures/invitations.ts +195 -0
  640. package/templates/base/tests/integration/fixtures/users.ts +144 -0
  641. package/templates/base/tests/integration/health/health.test.ts +351 -0
  642. package/templates/base/tests/integration/invitations/crud.test.ts +1457 -0
  643. package/templates/base/tests/integration/invitations/email.test.ts +506 -0
  644. package/templates/base/tests/integration/lib/email.test.ts +174 -0
  645. package/templates/base/tests/integration/lib/oauth.test.ts +368 -0
  646. package/templates/base/tests/integration/lib/password.test.ts +192 -0
  647. package/templates/base/tests/integration/lib/schema-helpers.test.ts +129 -0
  648. package/templates/base/tests/integration/lib/tokens.test.ts +304 -0
  649. package/templates/base/tests/integration/middleware/auth.test.ts +499 -0
  650. package/templates/base/tests/integration/middleware/cors.test.ts +334 -0
  651. package/templates/base/tests/integration/middleware/request-context.test.ts +156 -0
  652. package/templates/base/tests/integration/middleware/request-logger.test.ts +313 -0
  653. package/templates/base/tests/integration/performance/response-times.test.ts +509 -0
  654. package/templates/base/tests/integration/security/cookie-security.test.ts +567 -0
  655. package/templates/base/tests/integration/security/csrf-protection.test.ts +542 -0
  656. package/templates/base/tests/integration/security/jwt-validation.test.ts +209 -0
  657. package/templates/base/tests/integration/security/log-sanitization.test.ts +658 -0
  658. package/templates/base/tests/integration/security/rate-limiting.test.ts +1251 -0
  659. package/templates/base/tests/integration/security/sql-injection.test.ts +663 -0
  660. package/templates/base/tests/integration/security/token-hashing.test.ts +371 -0
  661. package/templates/base/tests/integration/security/xss-prevention.test.ts +541 -0
  662. package/templates/base/tests/integration/setup.ts +834 -0
  663. package/templates/base/tests/integration/smoke.test.ts +288 -0
  664. package/templates/base/tests/integration/storage/upload.test.ts +1162 -0
  665. package/templates/base/tests/integration/storage/validation.test.ts +746 -0
  666. package/templates/base/tests/integration/users/crud.test.ts +1297 -0
  667. package/templates/base/tests/integration/users/list.test.ts +698 -0
  668. package/templates/base/tests/integration/vitest.config.ts +80 -0
  669. package/templates/base/tsconfig.app.json +18 -0
  670. package/templates/base/tsconfig.json +39 -0
  671. package/templates/base/tsconfig.node.json +16 -0
  672. package/templates/base/tsconfig.server.json +26 -0
  673. package/templates/base/tsconfig.tsbuildinfo +1 -0
  674. package/templates/base/vite.config.ts +46 -0
  675. package/templates/base/vitest.config.browser.ts +47 -0
  676. package/templates/base/vitest.config.frontend.ts +47 -0
  677. package/templates/base/vitest.config.ts +82 -0
  678. package/templates/base/vitest.workspace.ts +22 -0
  679. package/templates/modules/audit-logs/.gitkeep +0 -0
  680. package/templates/modules/billing/.gitkeep +0 -0
  681. package/templates/modules/invitations/.gitkeep +0 -0
  682. package/templates/modules/storage/.gitkeep +0 -0
  683. package/templates/modules/webhooks/.gitkeep +0 -0
  684. package/templates/providers/auth-email/.gitkeep +0 -0
  685. package/templates/providers/auth-github/.gitkeep +0 -0
  686. package/templates/providers/auth-google/.gitkeep +0 -0
  687. package/templates/providers/email-resend/.gitkeep +0 -0
  688. package/templates/providers/email-sendgrid/.gitkeep +0 -0
@@ -0,0 +1,1133 @@
1
+ /**
2
+ * Audit Logs Integration Tests
3
+ *
4
+ * Tests the audit logs API:
5
+ * - GET /api/audits - List audit logs with filters and pagination
6
+ */
7
+
8
+ import { describe, it, expect, beforeAll } from 'vitest'
9
+ import { Hono } from 'hono'
10
+ import { getEnv, getDb, getSqlite, type TestEnv } from '../setup'
11
+ import {
12
+ createUser,
13
+ createUserSession,
14
+ createTestScenario,
15
+ createMultiUserScenario,
16
+ createAccount,
17
+ addUserToAccount,
18
+ } from '../fixtures'
19
+ import type { HonoEnv } from '../../../src/server/types'
20
+ import { api } from '../../../src/server/routes'
21
+ import { errorHandler } from '../../../src/server/middleware/error-handler'
22
+ import { sessionMiddleware } from '../../../src/server/lib/session'
23
+
24
+ /**
25
+ * Creates a database wrapper that adds the `execute` method
26
+ * The better-sqlite3 drizzle doesn't have execute, but D1 does
27
+ */
28
+ function createTestDb() {
29
+ const db = getDb()
30
+ return new Proxy(db, {
31
+ get(target, prop) {
32
+ if (prop === 'execute') {
33
+ return target.run.bind(target)
34
+ }
35
+ return (target as any)[prop]
36
+ },
37
+ })
38
+ }
39
+
40
+ /**
41
+ * Helper to create an audit log entry directly in the database
42
+ */
43
+ function createAuditLog(options: {
44
+ accountId: string
45
+ userId: string
46
+ entity: string
47
+ entityId: string
48
+ action: 'INSERT' | 'UPDATE' | 'DELETE' | 'LOGIN' | 'LOGOUT' | 'SIGNUP' | 'TOKEN_REFRESH' | 'LOGIN_FAILED'
49
+ changes?: Record<string, unknown> | null
50
+ timestamp?: string
51
+ }) {
52
+ const sqlite = getSqlite()
53
+ const id = crypto.randomUUID()
54
+ const transactionId = crypto.randomUUID()
55
+ const timestamp = options.timestamp ?? new Date().toISOString()
56
+
57
+ sqlite.prepare(`
58
+ INSERT INTO audit_logs (id, transaction_id, account_id, user_id, entity, entity_id, action, changes, ip_address, user_agent, timestamp)
59
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
60
+ `).run(
61
+ id,
62
+ transactionId,
63
+ options.accountId,
64
+ options.userId,
65
+ options.entity,
66
+ options.entityId,
67
+ options.action,
68
+ options.changes ? JSON.stringify(options.changes) : null,
69
+ '127.0.0.1',
70
+ 'IntegrationTest/1.0',
71
+ timestamp
72
+ )
73
+
74
+ return { id, transactionId, timestamp }
75
+ }
76
+
77
+ describe('Audit Logs Integration', () => {
78
+ let app: Hono<HonoEnv>
79
+ let env: TestEnv
80
+
81
+ beforeAll(() => {
82
+ env = getEnv()
83
+ app = new Hono<HonoEnv>()
84
+
85
+ // Set up error handler
86
+ app.onError(errorHandler)
87
+
88
+ // Set up middleware to inject test environment
89
+ app.use('*', async (c, next) => {
90
+ // Inject environment bindings
91
+ ;(c as any).env = env
92
+
93
+ // Set up database
94
+ const db = createTestDb()
95
+ c.set('db', db)
96
+
97
+ // Set up request context variables
98
+ c.set('transactionId', crypto.randomUUID())
99
+ c.set('ip', '127.0.0.1')
100
+ c.set('userAgent', 'IntegrationTest/1.0')
101
+
102
+ await next()
103
+ })
104
+
105
+ // Session middleware - reads session from KV and sets sessionData in context
106
+ app.use('*', sessionMiddleware())
107
+
108
+ // Mount API routes (includes sessionAuth and accountMiddleware)
109
+ app.route('/api', api)
110
+ })
111
+
112
+ // ============================================================================
113
+ // GET /api/audits
114
+ // ============================================================================
115
+
116
+ describe('GET /api/audits', () => {
117
+ describe('Authentication (401)', () => {
118
+ it('should return 401 without session cookie', async () => {
119
+ const res = await app.request('/api/audits', {
120
+ method: 'GET',
121
+ })
122
+
123
+ expect(res.status).toBe(401)
124
+
125
+ const body = await res.json()
126
+ expect(body).toHaveProperty('error')
127
+ expect(body.error.message).toBe('Not authenticated')
128
+ })
129
+
130
+ it('should return 401 with invalid session ID', async () => {
131
+ const res = await app.request('/api/audits', {
132
+ method: 'GET',
133
+ headers: {
134
+ Cookie: 'sid=invalid-session-id-that-does-not-exist',
135
+ 'account-id': crypto.randomUUID(),
136
+ },
137
+ })
138
+
139
+ expect(res.status).toBe(401)
140
+
141
+ const body = await res.json()
142
+ expect(body.error.message).toBe('Not authenticated')
143
+ })
144
+ })
145
+
146
+ describe('Authorization (403)', () => {
147
+ it('should return 403 if user lacks permission to view audits (VIEWER role)', async () => {
148
+ const scenario = await createTestScenario({
149
+ userName: 'Viewer User',
150
+ userEmail: 'viewer-audit@example.com',
151
+ role: 'VIEWER',
152
+ })
153
+
154
+ const res = await app.request('/api/audits', {
155
+ method: 'GET',
156
+ headers: {
157
+ ...scenario.headers,
158
+ 'User-Agent': 'IntegrationTest/1.0',
159
+ 'account-id': scenario.account.id,
160
+ },
161
+ })
162
+
163
+ expect(res.status).toBe(403)
164
+ })
165
+
166
+ it('should return 403 if user lacks permission to view audits (MANAGER role)', async () => {
167
+ const scenario = await createTestScenario({
168
+ userName: 'Manager User',
169
+ userEmail: 'manager-audit@example.com',
170
+ role: 'MANAGER',
171
+ })
172
+
173
+ const res = await app.request('/api/audits', {
174
+ method: 'GET',
175
+ headers: {
176
+ ...scenario.headers,
177
+ 'User-Agent': 'IntegrationTest/1.0',
178
+ 'account-id': scenario.account.id,
179
+ },
180
+ })
181
+
182
+ expect(res.status).toBe(403)
183
+ })
184
+
185
+ it('should return 403 if user lacks permission to view audits (EDITOR role)', async () => {
186
+ const scenario = await createTestScenario({
187
+ userName: 'Editor User',
188
+ userEmail: 'editor-audit@example.com',
189
+ role: 'EDITOR',
190
+ })
191
+
192
+ const res = await app.request('/api/audits', {
193
+ method: 'GET',
194
+ headers: {
195
+ ...scenario.headers,
196
+ 'User-Agent': 'IntegrationTest/1.0',
197
+ 'account-id': scenario.account.id,
198
+ },
199
+ })
200
+
201
+ expect(res.status).toBe(403)
202
+ })
203
+
204
+ it('should return 403 if user lacks permission to view audits (BILLING role)', async () => {
205
+ const scenario = await createTestScenario({
206
+ userName: 'Billing User',
207
+ userEmail: 'billing-audit@example.com',
208
+ role: 'BILLING',
209
+ })
210
+
211
+ const res = await app.request('/api/audits', {
212
+ method: 'GET',
213
+ headers: {
214
+ ...scenario.headers,
215
+ 'User-Agent': 'IntegrationTest/1.0',
216
+ 'account-id': scenario.account.id,
217
+ },
218
+ })
219
+
220
+ expect(res.status).toBe(403)
221
+ })
222
+ })
223
+
224
+ describe('Successful List (200)', () => {
225
+ it('should return 200 with empty array when no audit logs', async () => {
226
+ const scenario = await createTestScenario({
227
+ userName: 'Admin User',
228
+ userEmail: 'admin-audit1@example.com',
229
+ role: 'ADMIN',
230
+ })
231
+
232
+ const res = await app.request('/api/audits', {
233
+ method: 'GET',
234
+ headers: {
235
+ ...scenario.headers,
236
+ 'User-Agent': 'IntegrationTest/1.0',
237
+ 'account-id': scenario.account.id,
238
+ },
239
+ })
240
+
241
+ expect(res.status).toBe(200)
242
+
243
+ const body = await res.json()
244
+ expect(body).toHaveProperty('data')
245
+ expect(Array.isArray(body.data)).toBe(true)
246
+ expect(body).toHaveProperty('meta')
247
+ expect(body.meta).toHaveProperty('totalItems')
248
+ expect(body.meta).toHaveProperty('currentPage')
249
+ expect(body.meta).toHaveProperty('limit')
250
+ })
251
+
252
+ it('should return 200 with audit logs array for ADMIN role', async () => {
253
+ const scenario = await createTestScenario({
254
+ userName: 'Admin User',
255
+ userEmail: 'admin-audit2@example.com',
256
+ role: 'ADMIN',
257
+ })
258
+
259
+ // Create some audit logs
260
+ createAuditLog({
261
+ accountId: scenario.account.id,
262
+ userId: scenario.user.id,
263
+ entity: 'User',
264
+ entityId: crypto.randomUUID(),
265
+ action: 'INSERT',
266
+ changes: { name: 'New User' },
267
+ })
268
+
269
+ createAuditLog({
270
+ accountId: scenario.account.id,
271
+ userId: scenario.user.id,
272
+ entity: 'User',
273
+ entityId: crypto.randomUUID(),
274
+ action: 'UPDATE',
275
+ changes: { name: { old: 'Old Name', new: 'New Name' } },
276
+ })
277
+
278
+ const res = await app.request('/api/audits', {
279
+ method: 'GET',
280
+ headers: {
281
+ ...scenario.headers,
282
+ 'User-Agent': 'IntegrationTest/1.0',
283
+ 'account-id': scenario.account.id,
284
+ },
285
+ })
286
+
287
+ expect(res.status).toBe(200)
288
+
289
+ const body = await res.json()
290
+ expect(body.data.length).toBe(2)
291
+ })
292
+
293
+ it('should return 200 with audit logs for ANALYTICS role', async () => {
294
+ const scenario = await createTestScenario({
295
+ userName: 'Analytics User',
296
+ userEmail: 'analytics-audit@example.com',
297
+ role: 'ANALYTICS',
298
+ })
299
+
300
+ // Create an audit log
301
+ createAuditLog({
302
+ accountId: scenario.account.id,
303
+ userId: scenario.user.id,
304
+ entity: 'Account',
305
+ entityId: scenario.account.id,
306
+ action: 'UPDATE',
307
+ changes: { name: { old: 'Old Name', new: 'New Name' } },
308
+ })
309
+
310
+ const res = await app.request('/api/audits', {
311
+ method: 'GET',
312
+ headers: {
313
+ ...scenario.headers,
314
+ 'User-Agent': 'IntegrationTest/1.0',
315
+ 'account-id': scenario.account.id,
316
+ },
317
+ })
318
+
319
+ expect(res.status).toBe(200)
320
+
321
+ const body = await res.json()
322
+ expect(body.data.length).toBeGreaterThanOrEqual(1)
323
+ })
324
+
325
+ it('should return only audit logs for the current account', async () => {
326
+ const scenario = await createTestScenario({
327
+ userName: 'Admin User',
328
+ userEmail: 'admin-audit3@example.com',
329
+ role: 'ADMIN',
330
+ })
331
+
332
+ // Create another account
333
+ const otherAccount = await createAccount({ name: 'Other Account' })
334
+ const otherUser = await createUser({
335
+ email: 'otheraudit@example.com',
336
+ name: 'Other User',
337
+ })
338
+ await addUserToAccount(otherUser.id, otherAccount.id, 'ADMIN')
339
+
340
+ // Create audit logs in both accounts
341
+ createAuditLog({
342
+ accountId: scenario.account.id,
343
+ userId: scenario.user.id,
344
+ entity: 'User',
345
+ entityId: scenario.user.id,
346
+ action: 'UPDATE',
347
+ changes: { name: 'My Account Log' },
348
+ })
349
+
350
+ createAuditLog({
351
+ accountId: otherAccount.id,
352
+ userId: otherUser.id,
353
+ entity: 'User',
354
+ entityId: otherUser.id,
355
+ action: 'UPDATE',
356
+ changes: { name: 'Other Account Log' },
357
+ })
358
+
359
+ const res = await app.request('/api/audits', {
360
+ method: 'GET',
361
+ headers: {
362
+ ...scenario.headers,
363
+ 'User-Agent': 'IntegrationTest/1.0',
364
+ 'account-id': scenario.account.id,
365
+ },
366
+ })
367
+
368
+ expect(res.status).toBe(200)
369
+
370
+ const body = await res.json()
371
+ expect(body.data.length).toBe(1)
372
+ expect(body.data[0].accountId).toBe(scenario.account.id)
373
+ })
374
+
375
+ it('should include all audit log fields in response', async () => {
376
+ const scenario = await createTestScenario({
377
+ userName: 'Admin User',
378
+ userEmail: 'admin-audit4@example.com',
379
+ role: 'ADMIN',
380
+ })
381
+
382
+ const entityId = crypto.randomUUID()
383
+ const auditLog = createAuditLog({
384
+ accountId: scenario.account.id,
385
+ userId: scenario.user.id,
386
+ entity: 'User',
387
+ entityId,
388
+ action: 'INSERT',
389
+ changes: { name: 'Test User', email: 'test@example.com' },
390
+ })
391
+
392
+ const res = await app.request('/api/audits', {
393
+ method: 'GET',
394
+ headers: {
395
+ ...scenario.headers,
396
+ 'User-Agent': 'IntegrationTest/1.0',
397
+ 'account-id': scenario.account.id,
398
+ },
399
+ })
400
+
401
+ expect(res.status).toBe(200)
402
+
403
+ const body = await res.json()
404
+ expect(body.data.length).toBe(1)
405
+
406
+ const log = body.data[0]
407
+ expect(log).toHaveProperty('id')
408
+ expect(log).toHaveProperty('transactionId')
409
+ expect(log).toHaveProperty('accountId', scenario.account.id)
410
+ expect(log).toHaveProperty('userId', scenario.user.id)
411
+ expect(log).toHaveProperty('entity', 'User')
412
+ expect(log).toHaveProperty('entityId', entityId)
413
+ expect(log).toHaveProperty('action', 'INSERT')
414
+ expect(log).toHaveProperty('changes')
415
+ expect(log).toHaveProperty('ipAddress')
416
+ expect(log).toHaveProperty('userAgent')
417
+ expect(log).toHaveProperty('timestamp')
418
+ })
419
+ })
420
+
421
+ describe('Audit Log Entry Verification', () => {
422
+ it('should record INSERT action for user creation', async () => {
423
+ const scenario = await createTestScenario({
424
+ userName: 'Admin User',
425
+ userEmail: 'admin-verify1@example.com',
426
+ role: 'ADMIN',
427
+ })
428
+
429
+ const entityId = crypto.randomUUID()
430
+ createAuditLog({
431
+ accountId: scenario.account.id,
432
+ userId: scenario.user.id,
433
+ entity: 'User',
434
+ entityId,
435
+ action: 'INSERT',
436
+ changes: { name: 'New User', email: 'newuser@example.com' },
437
+ })
438
+
439
+ const res = await app.request('/api/audits?entity=User&action=INSERT', {
440
+ method: 'GET',
441
+ headers: {
442
+ ...scenario.headers,
443
+ 'User-Agent': 'IntegrationTest/1.0',
444
+ 'account-id': scenario.account.id,
445
+ },
446
+ })
447
+
448
+ expect(res.status).toBe(200)
449
+
450
+ const body = await res.json()
451
+ expect(body.data.length).toBeGreaterThanOrEqual(1)
452
+
453
+ const log = body.data.find((l: any) => l.entityId === entityId)
454
+ expect(log).toBeDefined()
455
+ expect(log.action).toBe('INSERT')
456
+ expect(log.entity).toBe('User')
457
+ })
458
+
459
+ it('should record UPDATE action with changes for user update', async () => {
460
+ const scenario = await createTestScenario({
461
+ userName: 'Admin User',
462
+ userEmail: 'admin-verify2@example.com',
463
+ role: 'ADMIN',
464
+ })
465
+
466
+ const entityId = crypto.randomUUID()
467
+ createAuditLog({
468
+ accountId: scenario.account.id,
469
+ userId: scenario.user.id,
470
+ entity: 'User',
471
+ entityId,
472
+ action: 'UPDATE',
473
+ changes: {
474
+ name: { old: 'Old Name', new: 'New Name' },
475
+ status: { old: 'active', new: 'inactive' },
476
+ },
477
+ })
478
+
479
+ const res = await app.request(`/api/audits?entityId=${entityId}`, {
480
+ method: 'GET',
481
+ headers: {
482
+ ...scenario.headers,
483
+ 'User-Agent': 'IntegrationTest/1.0',
484
+ 'account-id': scenario.account.id,
485
+ },
486
+ })
487
+
488
+ expect(res.status).toBe(200)
489
+
490
+ const body = await res.json()
491
+ expect(body.data.length).toBe(1)
492
+
493
+ const log = body.data[0]
494
+ expect(log.action).toBe('UPDATE')
495
+ expect(log.changes).toBeDefined()
496
+ expect(log.changes.name).toEqual({ old: 'Old Name', new: 'New Name' })
497
+ })
498
+
499
+ it('should record DELETE action for user deletion', async () => {
500
+ const scenario = await createTestScenario({
501
+ userName: 'Admin User',
502
+ userEmail: 'admin-verify3@example.com',
503
+ role: 'ADMIN',
504
+ })
505
+
506
+ const entityId = crypto.randomUUID()
507
+ createAuditLog({
508
+ accountId: scenario.account.id,
509
+ userId: scenario.user.id,
510
+ entity: 'User',
511
+ entityId,
512
+ action: 'DELETE',
513
+ changes: { deleted: true },
514
+ })
515
+
516
+ const res = await app.request('/api/audits?action=DELETE', {
517
+ method: 'GET',
518
+ headers: {
519
+ ...scenario.headers,
520
+ 'User-Agent': 'IntegrationTest/1.0',
521
+ 'account-id': scenario.account.id,
522
+ },
523
+ })
524
+
525
+ expect(res.status).toBe(200)
526
+
527
+ const body = await res.json()
528
+ expect(body.data.length).toBeGreaterThanOrEqual(1)
529
+
530
+ const log = body.data.find((l: any) => l.entityId === entityId)
531
+ expect(log).toBeDefined()
532
+ expect(log.action).toBe('DELETE')
533
+ })
534
+
535
+ it('should record audit logs for Account entity', async () => {
536
+ const scenario = await createTestScenario({
537
+ userName: 'Admin User',
538
+ userEmail: 'admin-verify4@example.com',
539
+ role: 'ADMIN',
540
+ })
541
+
542
+ createAuditLog({
543
+ accountId: scenario.account.id,
544
+ userId: scenario.user.id,
545
+ entity: 'Account',
546
+ entityId: scenario.account.id,
547
+ action: 'UPDATE',
548
+ changes: { name: { old: 'Old Account', new: 'New Account' } },
549
+ })
550
+
551
+ const res = await app.request('/api/audits?entity=Account', {
552
+ method: 'GET',
553
+ headers: {
554
+ ...scenario.headers,
555
+ 'User-Agent': 'IntegrationTest/1.0',
556
+ 'account-id': scenario.account.id,
557
+ },
558
+ })
559
+
560
+ expect(res.status).toBe(200)
561
+
562
+ const body = await res.json()
563
+ expect(body.data.length).toBeGreaterThanOrEqual(1)
564
+ expect(body.data[0].entity).toBe('Account')
565
+ })
566
+
567
+ it('should record audit logs for Invitation entity', async () => {
568
+ const scenario = await createTestScenario({
569
+ userName: 'Admin User',
570
+ userEmail: 'admin-verify5@example.com',
571
+ role: 'ADMIN',
572
+ })
573
+
574
+ const invitationId = crypto.randomUUID()
575
+ createAuditLog({
576
+ accountId: scenario.account.id,
577
+ userId: scenario.user.id,
578
+ entity: 'Invitation',
579
+ entityId: invitationId,
580
+ action: 'INSERT',
581
+ changes: { email: 'invited@example.com', role: 'VIEWER' },
582
+ })
583
+
584
+ createAuditLog({
585
+ accountId: scenario.account.id,
586
+ userId: scenario.user.id,
587
+ entity: 'Invitation',
588
+ entityId: invitationId,
589
+ action: 'DELETE',
590
+ changes: { revoked: true },
591
+ })
592
+
593
+ const res = await app.request('/api/audits?entity=Invitation', {
594
+ method: 'GET',
595
+ headers: {
596
+ ...scenario.headers,
597
+ 'User-Agent': 'IntegrationTest/1.0',
598
+ 'account-id': scenario.account.id,
599
+ },
600
+ })
601
+
602
+ expect(res.status).toBe(200)
603
+
604
+ const body = await res.json()
605
+ expect(body.data.length).toBe(2)
606
+ expect(body.data.every((l: any) => l.entity === 'Invitation')).toBe(true)
607
+ })
608
+
609
+ it('should record LOGIN action', async () => {
610
+ const scenario = await createTestScenario({
611
+ userName: 'Admin User',
612
+ userEmail: 'admin-verify6@example.com',
613
+ role: 'ADMIN',
614
+ })
615
+
616
+ createAuditLog({
617
+ accountId: scenario.account.id,
618
+ userId: scenario.user.id,
619
+ entity: 'Session',
620
+ entityId: scenario.user.id,
621
+ action: 'LOGIN',
622
+ changes: null,
623
+ })
624
+
625
+ const res = await app.request('/api/audits?action=LOGIN', {
626
+ method: 'GET',
627
+ headers: {
628
+ ...scenario.headers,
629
+ 'User-Agent': 'IntegrationTest/1.0',
630
+ 'account-id': scenario.account.id,
631
+ },
632
+ })
633
+
634
+ expect(res.status).toBe(200)
635
+
636
+ const body = await res.json()
637
+ expect(body.data.length).toBeGreaterThanOrEqual(1)
638
+ expect(body.data[0].action).toBe('LOGIN')
639
+ })
640
+ })
641
+
642
+ describe('Filtering', () => {
643
+ it('should filter by entity type', async () => {
644
+ const scenario = await createTestScenario({
645
+ userName: 'Admin User',
646
+ userEmail: 'admin-filter1@example.com',
647
+ role: 'ADMIN',
648
+ })
649
+
650
+ // Create audit logs for different entities
651
+ createAuditLog({
652
+ accountId: scenario.account.id,
653
+ userId: scenario.user.id,
654
+ entity: 'User',
655
+ entityId: crypto.randomUUID(),
656
+ action: 'INSERT',
657
+ })
658
+
659
+ createAuditLog({
660
+ accountId: scenario.account.id,
661
+ userId: scenario.user.id,
662
+ entity: 'Account',
663
+ entityId: scenario.account.id,
664
+ action: 'UPDATE',
665
+ })
666
+
667
+ createAuditLog({
668
+ accountId: scenario.account.id,
669
+ userId: scenario.user.id,
670
+ entity: 'User',
671
+ entityId: crypto.randomUUID(),
672
+ action: 'UPDATE',
673
+ })
674
+
675
+ const res = await app.request('/api/audits?entity=User', {
676
+ method: 'GET',
677
+ headers: {
678
+ ...scenario.headers,
679
+ 'User-Agent': 'IntegrationTest/1.0',
680
+ 'account-id': scenario.account.id,
681
+ },
682
+ })
683
+
684
+ expect(res.status).toBe(200)
685
+
686
+ const body = await res.json()
687
+ expect(body.data.length).toBe(2)
688
+ expect(body.data.every((l: any) => l.entity === 'User')).toBe(true)
689
+ })
690
+
691
+ it('should filter by action type', async () => {
692
+ const scenario = await createTestScenario({
693
+ userName: 'Admin User',
694
+ userEmail: 'admin-filter2@example.com',
695
+ role: 'ADMIN',
696
+ })
697
+
698
+ // Create audit logs with different actions
699
+ createAuditLog({
700
+ accountId: scenario.account.id,
701
+ userId: scenario.user.id,
702
+ entity: 'User',
703
+ entityId: crypto.randomUUID(),
704
+ action: 'INSERT',
705
+ })
706
+
707
+ createAuditLog({
708
+ accountId: scenario.account.id,
709
+ userId: scenario.user.id,
710
+ entity: 'User',
711
+ entityId: crypto.randomUUID(),
712
+ action: 'UPDATE',
713
+ })
714
+
715
+ createAuditLog({
716
+ accountId: scenario.account.id,
717
+ userId: scenario.user.id,
718
+ entity: 'User',
719
+ entityId: crypto.randomUUID(),
720
+ action: 'DELETE',
721
+ })
722
+
723
+ const res = await app.request('/api/audits?action=UPDATE', {
724
+ method: 'GET',
725
+ headers: {
726
+ ...scenario.headers,
727
+ 'User-Agent': 'IntegrationTest/1.0',
728
+ 'account-id': scenario.account.id,
729
+ },
730
+ })
731
+
732
+ expect(res.status).toBe(200)
733
+
734
+ const body = await res.json()
735
+ expect(body.data.length).toBe(1)
736
+ expect(body.data[0].action).toBe('UPDATE')
737
+ })
738
+
739
+ it('should filter by entityId', async () => {
740
+ const scenario = await createTestScenario({
741
+ userName: 'Admin User',
742
+ userEmail: 'admin-filter3@example.com',
743
+ role: 'ADMIN',
744
+ })
745
+
746
+ const targetEntityId = crypto.randomUUID()
747
+
748
+ // Create audit logs for different entities
749
+ createAuditLog({
750
+ accountId: scenario.account.id,
751
+ userId: scenario.user.id,
752
+ entity: 'User',
753
+ entityId: targetEntityId,
754
+ action: 'INSERT',
755
+ })
756
+
757
+ createAuditLog({
758
+ accountId: scenario.account.id,
759
+ userId: scenario.user.id,
760
+ entity: 'User',
761
+ entityId: targetEntityId,
762
+ action: 'UPDATE',
763
+ })
764
+
765
+ createAuditLog({
766
+ accountId: scenario.account.id,
767
+ userId: scenario.user.id,
768
+ entity: 'User',
769
+ entityId: crypto.randomUUID(),
770
+ action: 'INSERT',
771
+ })
772
+
773
+ const res = await app.request(`/api/audits?entityId=${targetEntityId}`, {
774
+ method: 'GET',
775
+ headers: {
776
+ ...scenario.headers,
777
+ 'User-Agent': 'IntegrationTest/1.0',
778
+ 'account-id': scenario.account.id,
779
+ },
780
+ })
781
+
782
+ expect(res.status).toBe(200)
783
+
784
+ const body = await res.json()
785
+ expect(body.data.length).toBe(2)
786
+ expect(body.data.every((l: any) => l.entityId === targetEntityId)).toBe(true)
787
+ })
788
+
789
+ it('should combine multiple filters', async () => {
790
+ const scenario = await createTestScenario({
791
+ userName: 'Admin User',
792
+ userEmail: 'admin-filter4@example.com',
793
+ role: 'ADMIN',
794
+ })
795
+
796
+ // Create various audit logs
797
+ createAuditLog({
798
+ accountId: scenario.account.id,
799
+ userId: scenario.user.id,
800
+ entity: 'User',
801
+ entityId: crypto.randomUUID(),
802
+ action: 'INSERT',
803
+ })
804
+
805
+ createAuditLog({
806
+ accountId: scenario.account.id,
807
+ userId: scenario.user.id,
808
+ entity: 'User',
809
+ entityId: crypto.randomUUID(),
810
+ action: 'UPDATE',
811
+ })
812
+
813
+ createAuditLog({
814
+ accountId: scenario.account.id,
815
+ userId: scenario.user.id,
816
+ entity: 'Account',
817
+ entityId: scenario.account.id,
818
+ action: 'INSERT',
819
+ })
820
+
821
+ const res = await app.request('/api/audits?entity=User&action=INSERT', {
822
+ method: 'GET',
823
+ headers: {
824
+ ...scenario.headers,
825
+ 'User-Agent': 'IntegrationTest/1.0',
826
+ 'account-id': scenario.account.id,
827
+ },
828
+ })
829
+
830
+ expect(res.status).toBe(200)
831
+
832
+ const body = await res.json()
833
+ expect(body.data.length).toBe(1)
834
+ expect(body.data[0].entity).toBe('User')
835
+ expect(body.data[0].action).toBe('INSERT')
836
+ })
837
+ })
838
+
839
+ describe('Pagination', () => {
840
+ it('should support page parameter', async () => {
841
+ const scenario = await createTestScenario({
842
+ userName: 'Admin User',
843
+ userEmail: 'admin-page1@example.com',
844
+ role: 'ADMIN',
845
+ })
846
+
847
+ // Create 15 audit logs
848
+ for (let i = 0; i < 15; i++) {
849
+ createAuditLog({
850
+ accountId: scenario.account.id,
851
+ userId: scenario.user.id,
852
+ entity: 'User',
853
+ entityId: crypto.randomUUID(),
854
+ action: 'INSERT',
855
+ timestamp: new Date(Date.now() - i * 1000).toISOString(), // Different timestamps
856
+ })
857
+ }
858
+
859
+ const res = await app.request('/api/audits?page=1&limit=10', {
860
+ method: 'GET',
861
+ headers: {
862
+ ...scenario.headers,
863
+ 'User-Agent': 'IntegrationTest/1.0',
864
+ 'account-id': scenario.account.id,
865
+ },
866
+ })
867
+
868
+ expect(res.status).toBe(200)
869
+
870
+ const body = await res.json()
871
+ expect(body.data.length).toBe(10)
872
+ expect(body.meta.currentPage).toBe(1)
873
+ expect(body.meta.totalItems).toBe(15)
874
+ })
875
+
876
+ it('should support limit parameter', async () => {
877
+ const scenario = await createTestScenario({
878
+ userName: 'Admin User',
879
+ userEmail: 'admin-limit1@example.com',
880
+ role: 'ADMIN',
881
+ })
882
+
883
+ // Create 10 audit logs
884
+ for (let i = 0; i < 10; i++) {
885
+ createAuditLog({
886
+ accountId: scenario.account.id,
887
+ userId: scenario.user.id,
888
+ entity: 'User',
889
+ entityId: crypto.randomUUID(),
890
+ action: 'UPDATE',
891
+ })
892
+ }
893
+
894
+ const res = await app.request('/api/audits?limit=5', {
895
+ method: 'GET',
896
+ headers: {
897
+ ...scenario.headers,
898
+ 'User-Agent': 'IntegrationTest/1.0',
899
+ 'account-id': scenario.account.id,
900
+ },
901
+ })
902
+
903
+ expect(res.status).toBe(200)
904
+
905
+ const body = await res.json()
906
+ expect(body.data.length).toBe(5)
907
+ expect(body.meta.limit).toBe(5)
908
+ })
909
+
910
+ it('should return correct meta for pagination', async () => {
911
+ const scenario = await createTestScenario({
912
+ userName: 'Admin User',
913
+ userEmail: 'admin-meta1@example.com',
914
+ role: 'ADMIN',
915
+ })
916
+
917
+ // Create 25 audit logs
918
+ for (let i = 0; i < 25; i++) {
919
+ createAuditLog({
920
+ accountId: scenario.account.id,
921
+ userId: scenario.user.id,
922
+ entity: 'User',
923
+ entityId: crypto.randomUUID(),
924
+ action: 'INSERT',
925
+ })
926
+ }
927
+
928
+ const res = await app.request('/api/audits?page=2&limit=10', {
929
+ method: 'GET',
930
+ headers: {
931
+ ...scenario.headers,
932
+ 'User-Agent': 'IntegrationTest/1.0',
933
+ 'account-id': scenario.account.id,
934
+ },
935
+ })
936
+
937
+ expect(res.status).toBe(200)
938
+
939
+ const body = await res.json()
940
+ expect(body.data.length).toBe(10)
941
+ expect(body.meta.currentPage).toBe(2)
942
+ expect(body.meta.totalItems).toBe(25)
943
+ expect(body.meta.totalPages).toBe(3)
944
+ expect(body.meta.limit).toBe(10)
945
+ })
946
+
947
+ it('should return empty array for page beyond available data', async () => {
948
+ const scenario = await createTestScenario({
949
+ userName: 'Admin User',
950
+ userEmail: 'admin-empty@example.com',
951
+ role: 'ADMIN',
952
+ })
953
+
954
+ // Create 5 audit logs
955
+ for (let i = 0; i < 5; i++) {
956
+ createAuditLog({
957
+ accountId: scenario.account.id,
958
+ userId: scenario.user.id,
959
+ entity: 'User',
960
+ entityId: crypto.randomUUID(),
961
+ action: 'INSERT',
962
+ })
963
+ }
964
+
965
+ const res = await app.request('/api/audits?page=10&limit=10', {
966
+ method: 'GET',
967
+ headers: {
968
+ ...scenario.headers,
969
+ 'User-Agent': 'IntegrationTest/1.0',
970
+ 'account-id': scenario.account.id,
971
+ },
972
+ })
973
+
974
+ expect(res.status).toBe(200)
975
+
976
+ const body = await res.json()
977
+ expect(body.data.length).toBe(0)
978
+ expect(body.meta.totalItems).toBe(5)
979
+ })
980
+
981
+ it('should use default pagination when not specified', async () => {
982
+ const scenario = await createTestScenario({
983
+ userName: 'Admin User',
984
+ userEmail: 'admin-default@example.com',
985
+ role: 'ADMIN',
986
+ })
987
+
988
+ // Create a few audit logs
989
+ for (let i = 0; i < 3; i++) {
990
+ createAuditLog({
991
+ accountId: scenario.account.id,
992
+ userId: scenario.user.id,
993
+ entity: 'User',
994
+ entityId: crypto.randomUUID(),
995
+ action: 'INSERT',
996
+ })
997
+ }
998
+
999
+ const res = await app.request('/api/audits', {
1000
+ method: 'GET',
1001
+ headers: {
1002
+ ...scenario.headers,
1003
+ 'User-Agent': 'IntegrationTest/1.0',
1004
+ 'account-id': scenario.account.id,
1005
+ },
1006
+ })
1007
+
1008
+ expect(res.status).toBe(200)
1009
+
1010
+ const body = await res.json()
1011
+ expect(body.meta.currentPage).toBe(1)
1012
+ expect(body.meta.limit).toBe(50) // Default limit from schema
1013
+ })
1014
+ })
1015
+
1016
+ describe('Super Admin Access', () => {
1017
+ it('should allow super admin to see all audit logs across accounts', async () => {
1018
+ // Create a super admin
1019
+ const superAdmin = await createUser({
1020
+ email: 'superadmin-audit@example.com',
1021
+ name: 'Super Admin',
1022
+ isSuperAdmin: true,
1023
+ })
1024
+
1025
+ // Create two accounts with audit logs
1026
+ const account1 = await createAccount({ name: 'Account 1' })
1027
+ const account2 = await createAccount({ name: 'Account 2' })
1028
+
1029
+ await addUserToAccount(superAdmin.id, account1.id, 'ADMIN')
1030
+
1031
+ // Create audit logs in both accounts
1032
+ createAuditLog({
1033
+ accountId: account1.id,
1034
+ userId: superAdmin.id,
1035
+ entity: 'User',
1036
+ entityId: crypto.randomUUID(),
1037
+ action: 'INSERT',
1038
+ })
1039
+
1040
+ createAuditLog({
1041
+ accountId: account2.id,
1042
+ userId: superAdmin.id,
1043
+ entity: 'User',
1044
+ entityId: crypto.randomUUID(),
1045
+ action: 'INSERT',
1046
+ })
1047
+
1048
+ const { headers } = await createUserSession(superAdmin.id, {
1049
+ email: superAdmin.email,
1050
+ name: superAdmin.name,
1051
+ isSuperAdmin: true,
1052
+ })
1053
+
1054
+ const res = await app.request('/api/audits', {
1055
+ method: 'GET',
1056
+ headers: {
1057
+ ...headers,
1058
+ 'User-Agent': 'IntegrationTest/1.0',
1059
+ 'account-id': account1.id,
1060
+ },
1061
+ })
1062
+
1063
+ expect(res.status).toBe(200)
1064
+
1065
+ const body = await res.json()
1066
+ // Super admin should see logs from both accounts
1067
+ expect(body.data.length).toBeGreaterThanOrEqual(2)
1068
+
1069
+ const accountIds = new Set(body.data.map((l: any) => l.accountId))
1070
+ expect(accountIds.has(account1.id)).toBe(true)
1071
+ expect(accountIds.has(account2.id)).toBe(true)
1072
+ })
1073
+ })
1074
+
1075
+ describe('Ordering', () => {
1076
+ it('should return audit logs ordered by timestamp descending (newest first)', async () => {
1077
+ const scenario = await createTestScenario({
1078
+ userName: 'Admin User',
1079
+ userEmail: 'admin-order1@example.com',
1080
+ role: 'ADMIN',
1081
+ })
1082
+
1083
+ // Create audit logs with specific timestamps
1084
+ const now = Date.now()
1085
+ createAuditLog({
1086
+ accountId: scenario.account.id,
1087
+ userId: scenario.user.id,
1088
+ entity: 'User',
1089
+ entityId: crypto.randomUUID(),
1090
+ action: 'INSERT',
1091
+ timestamp: new Date(now - 2000).toISOString(), // Oldest
1092
+ })
1093
+
1094
+ createAuditLog({
1095
+ accountId: scenario.account.id,
1096
+ userId: scenario.user.id,
1097
+ entity: 'User',
1098
+ entityId: crypto.randomUUID(),
1099
+ action: 'UPDATE',
1100
+ timestamp: new Date(now - 1000).toISOString(), // Middle
1101
+ })
1102
+
1103
+ createAuditLog({
1104
+ accountId: scenario.account.id,
1105
+ userId: scenario.user.id,
1106
+ entity: 'User',
1107
+ entityId: crypto.randomUUID(),
1108
+ action: 'DELETE',
1109
+ timestamp: new Date(now).toISOString(), // Newest
1110
+ })
1111
+
1112
+ const res = await app.request('/api/audits', {
1113
+ method: 'GET',
1114
+ headers: {
1115
+ ...scenario.headers,
1116
+ 'User-Agent': 'IntegrationTest/1.0',
1117
+ 'account-id': scenario.account.id,
1118
+ },
1119
+ })
1120
+
1121
+ expect(res.status).toBe(200)
1122
+
1123
+ const body = await res.json()
1124
+ expect(body.data.length).toBe(3)
1125
+
1126
+ // Verify order is newest first
1127
+ expect(body.data[0].action).toBe('DELETE')
1128
+ expect(body.data[1].action).toBe('UPDATE')
1129
+ expect(body.data[2].action).toBe('INSERT')
1130
+ })
1131
+ })
1132
+ })
1133
+ })