@nextsparkjs/core 0.1.0-beta.81 → 0.1.0-beta.83

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 (376) hide show
  1. package/dist/components/entities/wrappers/EntityDetailWrapper.d.ts.map +1 -1
  2. package/dist/components/entities/wrappers/EntityDetailWrapper.js +11 -39
  3. package/dist/hooks/useEntityQuery.d.ts.map +1 -1
  4. package/dist/hooks/useEntityQuery.js +21 -3
  5. package/dist/lib/theme/get-default-theme-mode.d.ts +11 -0
  6. package/dist/lib/theme/get-default-theme-mode.d.ts.map +1 -1
  7. package/dist/lib/theme/get-default-theme-mode.js +42 -25
  8. package/dist/styles/classes.json +1 -1
  9. package/dist/templates/next.config.mjs +5 -2
  10. package/dist/types/theme.d.ts +2 -0
  11. package/dist/types/theme.d.ts.map +1 -1
  12. package/package.json +16 -16
  13. package/scripts/build/docs-registry.mjs +0 -0
  14. package/scripts/create-theme.mjs +0 -0
  15. package/scripts/deploy/release-version.mjs +0 -0
  16. package/scripts/deploy/vercel-deploy.mjs +0 -0
  17. package/scripts/dev/watch-plugins.mjs +0 -0
  18. package/scripts/maintenance/update-core.mjs +0 -0
  19. package/scripts/setup/npm-postinstall.mjs +0 -0
  20. package/scripts/setup/setup-claude.mjs +0 -0
  21. package/scripts/validation/check-imports.sh +0 -0
  22. package/templates/next.config.mjs +5 -2
  23. package/dist/templates/app/(auth)/forgot-password/page.tsx +0 -216
  24. package/dist/templates/app/(auth)/layout.tsx +0 -51
  25. package/dist/templates/app/(auth)/login/page.tsx +0 -21
  26. package/dist/templates/app/(auth)/reset-password/page.tsx +0 -212
  27. package/dist/templates/app/(auth)/signup/page.tsx +0 -21
  28. package/dist/templates/app/(auth)/verify-email/page.tsx +0 -190
  29. package/dist/templates/app/(public)/[...slug]/page.tsx +0 -378
  30. package/dist/templates/app/(public)/docs/[section]/[page]/page.tsx +0 -90
  31. package/dist/templates/app/(public)/docs/layout.tsx +0 -25
  32. package/dist/templates/app/(public)/docs/page.tsx +0 -81
  33. package/dist/templates/app/(public)/layout.tsx +0 -41
  34. package/dist/templates/app/(public)/page.tsx +0 -19
  35. package/dist/templates/app/403/page.tsx +0 -89
  36. package/dist/templates/app/api/auth/[...all]/route.ts +0 -78
  37. package/dist/templates/app/api/cron/billing/lifecycle/route.ts +0 -98
  38. package/dist/templates/app/api/csp-report/route.ts +0 -175
  39. package/dist/templates/app/api/devtools/config/entities/route.ts +0 -108
  40. package/dist/templates/app/api/devtools/config/theme/route.ts +0 -66
  41. package/dist/templates/app/api/devtools/tests/[...path]/route.ts +0 -130
  42. package/dist/templates/app/api/devtools/tests/route.ts +0 -134
  43. package/dist/templates/app/api/health/route.ts +0 -29
  44. package/dist/templates/app/api/internal/user-metadata/route.ts +0 -36
  45. package/dist/templates/app/api/superadmin/subscriptions/route.ts +0 -310
  46. package/dist/templates/app/api/superadmin/teams/[teamId]/route.ts +0 -286
  47. package/dist/templates/app/api/superadmin/teams/route.ts +0 -188
  48. package/dist/templates/app/api/superadmin/users/[userId]/route.ts +0 -540
  49. package/dist/templates/app/api/superadmin/users/route.ts +0 -323
  50. package/dist/templates/app/api/user/delete-account/route.ts +0 -55
  51. package/dist/templates/app/api/user/plan-flags/route.ts +0 -283
  52. package/dist/templates/app/api/user/profile/route.ts +0 -133
  53. package/dist/templates/app/api/v1/[entity]/[id]/child/[childType]/[childId]/route.ts +0 -210
  54. package/dist/templates/app/api/v1/[entity]/[id]/child/[childType]/route.ts +0 -331
  55. package/dist/templates/app/api/v1/[entity]/[id]/route.ts +0 -35
  56. package/dist/templates/app/api/v1/[entity]/docs.md +0 -369
  57. package/dist/templates/app/api/v1/[entity]/presets.ts +0 -194
  58. package/dist/templates/app/api/v1/[entity]/route.ts +0 -31
  59. package/dist/templates/app/api/v1/api-keys/[id]/route.ts +0 -303
  60. package/dist/templates/app/api/v1/api-keys/docs.md +0 -101
  61. package/dist/templates/app/api/v1/api-keys/presets.ts +0 -31
  62. package/dist/templates/app/api/v1/api-keys/route.ts +0 -250
  63. package/dist/templates/app/api/v1/auth/docs.md +0 -184
  64. package/dist/templates/app/api/v1/auth/presets.ts +0 -44
  65. package/dist/templates/app/api/v1/auth/signup-with-invite/route.ts +0 -227
  66. package/dist/templates/app/api/v1/billing/cancel/route.ts +0 -206
  67. package/dist/templates/app/api/v1/billing/change-plan/route.ts +0 -97
  68. package/dist/templates/app/api/v1/billing/check-action/route.ts +0 -81
  69. package/dist/templates/app/api/v1/billing/checkout/route.ts +0 -124
  70. package/dist/templates/app/api/v1/billing/docs.md +0 -209
  71. package/dist/templates/app/api/v1/billing/plans/route.ts +0 -85
  72. package/dist/templates/app/api/v1/billing/portal/route.ts +0 -90
  73. package/dist/templates/app/api/v1/billing/presets.ts +0 -121
  74. package/dist/templates/app/api/v1/billing/webhooks/stripe/route.ts +0 -428
  75. package/dist/templates/app/api/v1/blocks/[slug]/route.ts +0 -29
  76. package/dist/templates/app/api/v1/blocks/docs.md +0 -173
  77. package/dist/templates/app/api/v1/blocks/presets.ts +0 -121
  78. package/dist/templates/app/api/v1/blocks/route.ts +0 -45
  79. package/dist/templates/app/api/v1/blocks/validate/route.ts +0 -45
  80. package/dist/templates/app/api/v1/cron/docs.md +0 -116
  81. package/dist/templates/app/api/v1/cron/presets.ts +0 -26
  82. package/dist/templates/app/api/v1/cron/process/route.ts +0 -108
  83. package/dist/templates/app/api/v1/devtools/blocks/route.ts +0 -82
  84. package/dist/templates/app/api/v1/devtools/docs/route.ts +0 -150
  85. package/dist/templates/app/api/v1/devtools/docs.md +0 -204
  86. package/dist/templates/app/api/v1/devtools/features/route.ts +0 -61
  87. package/dist/templates/app/api/v1/devtools/flows/route.ts +0 -61
  88. package/dist/templates/app/api/v1/devtools/presets.ts +0 -113
  89. package/dist/templates/app/api/v1/devtools/scheduled-actions/route.ts +0 -120
  90. package/dist/templates/app/api/v1/devtools/testing/route.ts +0 -82
  91. package/dist/templates/app/api/v1/media/docs.md +0 -117
  92. package/dist/templates/app/api/v1/media/presets.ts +0 -24
  93. package/dist/templates/app/api/v1/media/upload/route.ts +0 -150
  94. package/dist/templates/app/api/v1/patterns/[id]/usages/route.ts +0 -116
  95. package/dist/templates/app/api/v1/plugin/[...path]/route.ts +0 -373
  96. package/dist/templates/app/api/v1/plugin/docs.md +0 -79
  97. package/dist/templates/app/api/v1/plugin/presets.ts +0 -21
  98. package/dist/templates/app/api/v1/plugin/route.ts +0 -96
  99. package/dist/templates/app/api/v1/post-categories/[id]/route.ts +0 -255
  100. package/dist/templates/app/api/v1/post-categories/docs.md +0 -134
  101. package/dist/templates/app/api/v1/post-categories/presets.ts +0 -78
  102. package/dist/templates/app/api/v1/post-categories/route.ts +0 -119
  103. package/dist/templates/app/api/v1/team-invitations/[token]/accept/route.ts +0 -179
  104. package/dist/templates/app/api/v1/team-invitations/[token]/decline/route.ts +0 -120
  105. package/dist/templates/app/api/v1/team-invitations/[token]/route.ts +0 -89
  106. package/dist/templates/app/api/v1/team-invitations/docs.md +0 -88
  107. package/dist/templates/app/api/v1/team-invitations/presets.ts +0 -43
  108. package/dist/templates/app/api/v1/team-invitations/route.ts +0 -114
  109. package/dist/templates/app/api/v1/teams/[teamId]/invitations/route.ts +0 -171
  110. package/dist/templates/app/api/v1/teams/[teamId]/invoices/[invoiceNumber]/route.ts +0 -105
  111. package/dist/templates/app/api/v1/teams/[teamId]/invoices/route.ts +0 -125
  112. package/dist/templates/app/api/v1/teams/[teamId]/members/[memberId]/route.ts +0 -263
  113. package/dist/templates/app/api/v1/teams/[teamId]/members/route.ts +0 -358
  114. package/dist/templates/app/api/v1/teams/[teamId]/route.ts +0 -322
  115. package/dist/templates/app/api/v1/teams/[teamId]/subscription/route.ts +0 -50
  116. package/dist/templates/app/api/v1/teams/[teamId]/usage/[limitSlug]/route.ts +0 -91
  117. package/dist/templates/app/api/v1/teams/docs.md +0 -320
  118. package/dist/templates/app/api/v1/teams/presets.ts +0 -178
  119. package/dist/templates/app/api/v1/teams/route.ts +0 -293
  120. package/dist/templates/app/api/v1/teams/switch/route.ts +0 -88
  121. package/dist/templates/app/api/v1/theme/[...path]/route.ts +0 -361
  122. package/dist/templates/app/api/v1/theme/docs.md +0 -74
  123. package/dist/templates/app/api/v1/theme/presets.ts +0 -21
  124. package/dist/templates/app/api/v1/theme/route.ts +0 -96
  125. package/dist/templates/app/api/v1/users/[id]/meta/[key]/route.ts +0 -363
  126. package/dist/templates/app/api/v1/users/[id]/route.ts +0 -302
  127. package/dist/templates/app/api/v1/users/docs.md +0 -93
  128. package/dist/templates/app/api/v1/users/presets.ts +0 -59
  129. package/dist/templates/app/api/v1/users/route.ts +0 -197
  130. package/dist/templates/app/dashboard/(main)/[entity]/[id]/edit/page.tsx +0 -117
  131. package/dist/templates/app/dashboard/(main)/[entity]/[id]/page.tsx +0 -103
  132. package/dist/templates/app/dashboard/(main)/[entity]/create/page.tsx +0 -95
  133. package/dist/templates/app/dashboard/(main)/[entity]/error.tsx +0 -51
  134. package/dist/templates/app/dashboard/(main)/[entity]/layout.tsx +0 -113
  135. package/dist/templates/app/dashboard/(main)/[entity]/loading.tsx +0 -61
  136. package/dist/templates/app/dashboard/(main)/[entity]/page.tsx +0 -90
  137. package/dist/templates/app/dashboard/(main)/layout.tsx +0 -98
  138. package/dist/templates/app/dashboard/(main)/loading.tsx +0 -5
  139. package/dist/templates/app/dashboard/(main)/page.tsx +0 -201
  140. package/dist/templates/app/dashboard/(main)/patterns/[id]/edit/page.tsx +0 -114
  141. package/dist/templates/app/dashboard/(main)/patterns/[id]/page.tsx +0 -20
  142. package/dist/templates/app/dashboard/(main)/patterns/[id]/reports/page.tsx +0 -171
  143. package/dist/templates/app/dashboard/(main)/patterns/create/page.tsx +0 -86
  144. package/dist/templates/app/dashboard/(main)/patterns/page.tsx +0 -444
  145. package/dist/templates/app/dashboard/features/analytics/page.tsx +0 -35
  146. package/dist/templates/app/dashboard/features/automation/page.tsx +0 -35
  147. package/dist/templates/app/dashboard/features/layout.tsx +0 -13
  148. package/dist/templates/app/dashboard/features/loading.tsx +0 -5
  149. package/dist/templates/app/dashboard/features/webhooks/page.tsx +0 -35
  150. package/dist/templates/app/dashboard/layout.tsx +0 -86
  151. package/dist/templates/app/dashboard/permission-denied/page.tsx +0 -29
  152. package/dist/templates/app/dashboard/settings/api-keys/loading.tsx +0 -5
  153. package/dist/templates/app/dashboard/settings/api-keys/page.tsx +0 -513
  154. package/dist/templates/app/dashboard/settings/billing/loading.tsx +0 -5
  155. package/dist/templates/app/dashboard/settings/billing/page.tsx +0 -284
  156. package/dist/templates/app/dashboard/settings/invoices/[invoiceNumber]/page.tsx +0 -222
  157. package/dist/templates/app/dashboard/settings/invoices/loading.tsx +0 -5
  158. package/dist/templates/app/dashboard/settings/invoices/page.tsx +0 -82
  159. package/dist/templates/app/dashboard/settings/layout.tsx +0 -151
  160. package/dist/templates/app/dashboard/settings/loading.tsx +0 -5
  161. package/dist/templates/app/dashboard/settings/notifications/loading.tsx +0 -5
  162. package/dist/templates/app/dashboard/settings/notifications/page.tsx +0 -462
  163. package/dist/templates/app/dashboard/settings/page.tsx +0 -92
  164. package/dist/templates/app/dashboard/settings/password/loading.tsx +0 -5
  165. package/dist/templates/app/dashboard/settings/password/page.tsx +0 -306
  166. package/dist/templates/app/dashboard/settings/plans/loading.tsx +0 -5
  167. package/dist/templates/app/dashboard/settings/plans/page.tsx +0 -40
  168. package/dist/templates/app/dashboard/settings/profile/loading.tsx +0 -5
  169. package/dist/templates/app/dashboard/settings/profile/page.tsx +0 -686
  170. package/dist/templates/app/dashboard/settings/security/loading.tsx +0 -5
  171. package/dist/templates/app/dashboard/settings/security/page.tsx +0 -505
  172. package/dist/templates/app/dashboard/settings/teams/loading.tsx +0 -5
  173. package/dist/templates/app/dashboard/settings/teams/page.tsx +0 -272
  174. package/dist/templates/app/dashboard/settings/teams/permissions/page.tsx +0 -92
  175. package/dist/templates/app/devtools/blocks/[slug]/page.tsx +0 -39
  176. package/dist/templates/app/devtools/blocks/page.tsx +0 -31
  177. package/dist/templates/app/devtools/config/page.tsx +0 -31
  178. package/dist/templates/app/devtools/features/page.tsx +0 -31
  179. package/dist/templates/app/devtools/flows/page.tsx +0 -31
  180. package/dist/templates/app/devtools/layout.tsx +0 -58
  181. package/dist/templates/app/devtools/page.tsx +0 -121
  182. package/dist/templates/app/devtools/scheduled-actions/page.tsx +0 -157
  183. package/dist/templates/app/devtools/style/page.tsx +0 -330
  184. package/dist/templates/app/devtools/tags/page.tsx +0 -31
  185. package/dist/templates/app/devtools/tests/[[...path]]/page.tsx +0 -47
  186. package/dist/templates/app/favicon.ico +0 -0
  187. package/dist/templates/app/globals.css +0 -12
  188. package/dist/templates/app/layout.tsx +0 -96
  189. package/dist/templates/app/public/page.tsx +0 -30
  190. package/dist/templates/app/superadmin/docs/[section]/[page]/page.tsx +0 -92
  191. package/dist/templates/app/superadmin/docs/page.tsx +0 -75
  192. package/dist/templates/app/superadmin/layout.tsx +0 -67
  193. package/dist/templates/app/superadmin/page.tsx +0 -149
  194. package/dist/templates/app/superadmin/subscriptions/page.tsx +0 -655
  195. package/dist/templates/app/superadmin/team-roles/page.tsx +0 -493
  196. package/dist/templates/app/superadmin/teams/[teamId]/page.tsx +0 -687
  197. package/dist/templates/app/superadmin/teams/page.tsx +0 -302
  198. package/dist/templates/app/superadmin/users/[userId]/page.tsx +0 -548
  199. package/dist/templates/app/superadmin/users/page.tsx +0 -528
  200. package/templates/app/(auth)/forgot-password/page.tsx +0 -216
  201. package/templates/app/(auth)/layout.tsx +0 -51
  202. package/templates/app/(auth)/login/page.tsx +0 -21
  203. package/templates/app/(auth)/reset-password/page.tsx +0 -212
  204. package/templates/app/(auth)/signup/page.tsx +0 -21
  205. package/templates/app/(auth)/verify-email/page.tsx +0 -190
  206. package/templates/app/(public)/[...slug]/page.tsx +0 -378
  207. package/templates/app/(public)/docs/[section]/[page]/page.tsx +0 -90
  208. package/templates/app/(public)/docs/layout.tsx +0 -25
  209. package/templates/app/(public)/docs/page.tsx +0 -81
  210. package/templates/app/(public)/layout.tsx +0 -41
  211. package/templates/app/(public)/page.tsx +0 -19
  212. package/templates/app/403/page.tsx +0 -89
  213. package/templates/app/api/auth/[...all]/route.ts +0 -78
  214. package/templates/app/api/cron/billing/lifecycle/route.ts +0 -98
  215. package/templates/app/api/csp-report/route.ts +0 -175
  216. package/templates/app/api/devtools/config/entities/route.ts +0 -108
  217. package/templates/app/api/devtools/config/theme/route.ts +0 -66
  218. package/templates/app/api/devtools/tests/[...path]/route.ts +0 -130
  219. package/templates/app/api/devtools/tests/route.ts +0 -134
  220. package/templates/app/api/health/route.ts +0 -29
  221. package/templates/app/api/internal/user-metadata/route.ts +0 -36
  222. package/templates/app/api/superadmin/subscriptions/route.ts +0 -310
  223. package/templates/app/api/superadmin/teams/[teamId]/route.ts +0 -286
  224. package/templates/app/api/superadmin/teams/route.ts +0 -188
  225. package/templates/app/api/superadmin/users/[userId]/route.ts +0 -540
  226. package/templates/app/api/superadmin/users/route.ts +0 -323
  227. package/templates/app/api/user/delete-account/route.ts +0 -55
  228. package/templates/app/api/user/plan-flags/route.ts +0 -283
  229. package/templates/app/api/user/profile/route.ts +0 -133
  230. package/templates/app/api/v1/[entity]/[id]/child/[childType]/[childId]/route.ts +0 -210
  231. package/templates/app/api/v1/[entity]/[id]/child/[childType]/route.ts +0 -331
  232. package/templates/app/api/v1/[entity]/[id]/route.ts +0 -35
  233. package/templates/app/api/v1/[entity]/docs.md +0 -369
  234. package/templates/app/api/v1/[entity]/presets.ts +0 -194
  235. package/templates/app/api/v1/[entity]/route.ts +0 -31
  236. package/templates/app/api/v1/api-keys/[id]/route.ts +0 -303
  237. package/templates/app/api/v1/api-keys/docs.md +0 -101
  238. package/templates/app/api/v1/api-keys/presets.ts +0 -31
  239. package/templates/app/api/v1/api-keys/route.ts +0 -250
  240. package/templates/app/api/v1/auth/docs.md +0 -184
  241. package/templates/app/api/v1/auth/presets.ts +0 -44
  242. package/templates/app/api/v1/auth/signup-with-invite/route.ts +0 -227
  243. package/templates/app/api/v1/billing/cancel/route.ts +0 -206
  244. package/templates/app/api/v1/billing/change-plan/route.ts +0 -97
  245. package/templates/app/api/v1/billing/check-action/route.ts +0 -81
  246. package/templates/app/api/v1/billing/checkout/route.ts +0 -124
  247. package/templates/app/api/v1/billing/docs.md +0 -209
  248. package/templates/app/api/v1/billing/plans/route.ts +0 -85
  249. package/templates/app/api/v1/billing/portal/route.ts +0 -90
  250. package/templates/app/api/v1/billing/presets.ts +0 -121
  251. package/templates/app/api/v1/billing/webhooks/stripe/route.ts +0 -428
  252. package/templates/app/api/v1/blocks/[slug]/route.ts +0 -29
  253. package/templates/app/api/v1/blocks/docs.md +0 -173
  254. package/templates/app/api/v1/blocks/presets.ts +0 -121
  255. package/templates/app/api/v1/blocks/route.ts +0 -45
  256. package/templates/app/api/v1/blocks/validate/route.ts +0 -45
  257. package/templates/app/api/v1/cron/docs.md +0 -116
  258. package/templates/app/api/v1/cron/presets.ts +0 -26
  259. package/templates/app/api/v1/cron/process/route.ts +0 -108
  260. package/templates/app/api/v1/devtools/blocks/route.ts +0 -82
  261. package/templates/app/api/v1/devtools/docs/route.ts +0 -150
  262. package/templates/app/api/v1/devtools/docs.md +0 -204
  263. package/templates/app/api/v1/devtools/features/route.ts +0 -61
  264. package/templates/app/api/v1/devtools/flows/route.ts +0 -61
  265. package/templates/app/api/v1/devtools/presets.ts +0 -113
  266. package/templates/app/api/v1/devtools/scheduled-actions/route.ts +0 -120
  267. package/templates/app/api/v1/devtools/testing/route.ts +0 -82
  268. package/templates/app/api/v1/media/docs.md +0 -117
  269. package/templates/app/api/v1/media/presets.ts +0 -24
  270. package/templates/app/api/v1/media/upload/route.ts +0 -150
  271. package/templates/app/api/v1/patterns/[id]/usages/route.ts +0 -116
  272. package/templates/app/api/v1/plugin/[...path]/route.ts +0 -373
  273. package/templates/app/api/v1/plugin/docs.md +0 -79
  274. package/templates/app/api/v1/plugin/presets.ts +0 -21
  275. package/templates/app/api/v1/plugin/route.ts +0 -96
  276. package/templates/app/api/v1/post-categories/[id]/route.ts +0 -255
  277. package/templates/app/api/v1/post-categories/docs.md +0 -134
  278. package/templates/app/api/v1/post-categories/presets.ts +0 -78
  279. package/templates/app/api/v1/post-categories/route.ts +0 -119
  280. package/templates/app/api/v1/team-invitations/[token]/accept/route.ts +0 -179
  281. package/templates/app/api/v1/team-invitations/[token]/decline/route.ts +0 -120
  282. package/templates/app/api/v1/team-invitations/[token]/route.ts +0 -89
  283. package/templates/app/api/v1/team-invitations/docs.md +0 -88
  284. package/templates/app/api/v1/team-invitations/presets.ts +0 -43
  285. package/templates/app/api/v1/team-invitations/route.ts +0 -114
  286. package/templates/app/api/v1/teams/[teamId]/invitations/route.ts +0 -171
  287. package/templates/app/api/v1/teams/[teamId]/invoices/[invoiceNumber]/route.ts +0 -105
  288. package/templates/app/api/v1/teams/[teamId]/invoices/route.ts +0 -125
  289. package/templates/app/api/v1/teams/[teamId]/members/[memberId]/route.ts +0 -263
  290. package/templates/app/api/v1/teams/[teamId]/members/route.ts +0 -358
  291. package/templates/app/api/v1/teams/[teamId]/route.ts +0 -322
  292. package/templates/app/api/v1/teams/[teamId]/subscription/route.ts +0 -50
  293. package/templates/app/api/v1/teams/[teamId]/usage/[limitSlug]/route.ts +0 -91
  294. package/templates/app/api/v1/teams/docs.md +0 -320
  295. package/templates/app/api/v1/teams/presets.ts +0 -178
  296. package/templates/app/api/v1/teams/route.ts +0 -293
  297. package/templates/app/api/v1/teams/switch/route.ts +0 -88
  298. package/templates/app/api/v1/theme/[...path]/route.ts +0 -361
  299. package/templates/app/api/v1/theme/docs.md +0 -74
  300. package/templates/app/api/v1/theme/presets.ts +0 -21
  301. package/templates/app/api/v1/theme/route.ts +0 -96
  302. package/templates/app/api/v1/users/[id]/meta/[key]/route.ts +0 -363
  303. package/templates/app/api/v1/users/[id]/route.ts +0 -302
  304. package/templates/app/api/v1/users/docs.md +0 -93
  305. package/templates/app/api/v1/users/presets.ts +0 -59
  306. package/templates/app/api/v1/users/route.ts +0 -197
  307. package/templates/app/dashboard/(main)/[entity]/[id]/edit/page.tsx +0 -117
  308. package/templates/app/dashboard/(main)/[entity]/[id]/page.tsx +0 -103
  309. package/templates/app/dashboard/(main)/[entity]/create/page.tsx +0 -95
  310. package/templates/app/dashboard/(main)/[entity]/error.tsx +0 -51
  311. package/templates/app/dashboard/(main)/[entity]/layout.tsx +0 -113
  312. package/templates/app/dashboard/(main)/[entity]/loading.tsx +0 -61
  313. package/templates/app/dashboard/(main)/[entity]/page.tsx +0 -90
  314. package/templates/app/dashboard/(main)/layout.tsx +0 -98
  315. package/templates/app/dashboard/(main)/loading.tsx +0 -5
  316. package/templates/app/dashboard/(main)/page.tsx +0 -201
  317. package/templates/app/dashboard/(main)/patterns/[id]/edit/page.tsx +0 -114
  318. package/templates/app/dashboard/(main)/patterns/[id]/page.tsx +0 -20
  319. package/templates/app/dashboard/(main)/patterns/[id]/reports/page.tsx +0 -171
  320. package/templates/app/dashboard/(main)/patterns/create/page.tsx +0 -86
  321. package/templates/app/dashboard/(main)/patterns/page.tsx +0 -444
  322. package/templates/app/dashboard/features/analytics/page.tsx +0 -35
  323. package/templates/app/dashboard/features/automation/page.tsx +0 -35
  324. package/templates/app/dashboard/features/layout.tsx +0 -13
  325. package/templates/app/dashboard/features/loading.tsx +0 -5
  326. package/templates/app/dashboard/features/webhooks/page.tsx +0 -35
  327. package/templates/app/dashboard/layout.tsx +0 -86
  328. package/templates/app/dashboard/permission-denied/page.tsx +0 -29
  329. package/templates/app/dashboard/settings/api-keys/loading.tsx +0 -5
  330. package/templates/app/dashboard/settings/api-keys/page.tsx +0 -513
  331. package/templates/app/dashboard/settings/billing/loading.tsx +0 -5
  332. package/templates/app/dashboard/settings/billing/page.tsx +0 -284
  333. package/templates/app/dashboard/settings/invoices/[invoiceNumber]/page.tsx +0 -222
  334. package/templates/app/dashboard/settings/invoices/loading.tsx +0 -5
  335. package/templates/app/dashboard/settings/invoices/page.tsx +0 -82
  336. package/templates/app/dashboard/settings/layout.tsx +0 -151
  337. package/templates/app/dashboard/settings/loading.tsx +0 -5
  338. package/templates/app/dashboard/settings/notifications/loading.tsx +0 -5
  339. package/templates/app/dashboard/settings/notifications/page.tsx +0 -462
  340. package/templates/app/dashboard/settings/page.tsx +0 -92
  341. package/templates/app/dashboard/settings/password/loading.tsx +0 -5
  342. package/templates/app/dashboard/settings/password/page.tsx +0 -306
  343. package/templates/app/dashboard/settings/plans/loading.tsx +0 -5
  344. package/templates/app/dashboard/settings/plans/page.tsx +0 -40
  345. package/templates/app/dashboard/settings/profile/loading.tsx +0 -5
  346. package/templates/app/dashboard/settings/profile/page.tsx +0 -686
  347. package/templates/app/dashboard/settings/security/loading.tsx +0 -5
  348. package/templates/app/dashboard/settings/security/page.tsx +0 -505
  349. package/templates/app/dashboard/settings/teams/loading.tsx +0 -5
  350. package/templates/app/dashboard/settings/teams/page.tsx +0 -272
  351. package/templates/app/dashboard/settings/teams/permissions/page.tsx +0 -92
  352. package/templates/app/devtools/blocks/[slug]/page.tsx +0 -39
  353. package/templates/app/devtools/blocks/page.tsx +0 -31
  354. package/templates/app/devtools/config/page.tsx +0 -31
  355. package/templates/app/devtools/features/page.tsx +0 -31
  356. package/templates/app/devtools/flows/page.tsx +0 -31
  357. package/templates/app/devtools/layout.tsx +0 -58
  358. package/templates/app/devtools/page.tsx +0 -121
  359. package/templates/app/devtools/scheduled-actions/page.tsx +0 -157
  360. package/templates/app/devtools/style/page.tsx +0 -330
  361. package/templates/app/devtools/tags/page.tsx +0 -31
  362. package/templates/app/devtools/tests/[[...path]]/page.tsx +0 -47
  363. package/templates/app/favicon.ico +0 -0
  364. package/templates/app/globals.css +0 -12
  365. package/templates/app/layout.tsx +0 -96
  366. package/templates/app/public/page.tsx +0 -30
  367. package/templates/app/superadmin/docs/[section]/[page]/page.tsx +0 -92
  368. package/templates/app/superadmin/docs/page.tsx +0 -75
  369. package/templates/app/superadmin/layout.tsx +0 -67
  370. package/templates/app/superadmin/page.tsx +0 -149
  371. package/templates/app/superadmin/subscriptions/page.tsx +0 -655
  372. package/templates/app/superadmin/team-roles/page.tsx +0 -493
  373. package/templates/app/superadmin/teams/[teamId]/page.tsx +0 -687
  374. package/templates/app/superadmin/teams/page.tsx +0 -302
  375. package/templates/app/superadmin/users/[userId]/page.tsx +0 -548
  376. package/templates/app/superadmin/users/page.tsx +0 -528
@@ -1,171 +0,0 @@
1
- import { NextRequest, NextResponse } from 'next/server'
2
- import { queryWithRLS, mutateWithRLS } from '@nextsparkjs/core/lib/db'
3
- import {
4
- createApiResponse,
5
- createApiError,
6
- createPaginationMeta,
7
- withApiLogging,
8
- handleCorsPreflightRequest,
9
- addCorsHeaders,
10
- } from '@nextsparkjs/core/lib/api/helpers'
11
- import { authenticateRequest } from '@nextsparkjs/core/lib/api/auth/dual-auth'
12
- import { TeamMemberService, MembershipService } from '@nextsparkjs/core/lib/services'
13
- import type { TeamInvitation } from '@nextsparkjs/core/lib/teams/types'
14
-
15
- // Handle CORS preflight
16
- export async function OPTIONS() {
17
- return handleCorsPreflightRequest()
18
- }
19
-
20
- // GET /api/v1/teams/:teamId/invitations - List pending invitations for a team
21
- export const GET = withApiLogging(
22
- async (req: NextRequest, { params }: { params: Promise<{ teamId: string }> }): Promise<NextResponse> => {
23
- try {
24
- // Authenticate using dual auth
25
- const authResult = await authenticateRequest(req)
26
-
27
- if (!authResult.success) {
28
- return NextResponse.json(
29
- { success: false, error: 'Authentication required', code: 'AUTHENTICATION_FAILED' },
30
- { status: 401 }
31
- )
32
- }
33
-
34
- if (authResult.rateLimitResponse) {
35
- return authResult.rateLimitResponse as NextResponse
36
- }
37
-
38
- const { teamId } = await params
39
-
40
- // Validate that teamId is not empty
41
- if (!teamId || teamId.trim() === '') {
42
- const response = createApiError('Team ID is required', 400, null, 'MISSING_TEAM_ID')
43
- return addCorsHeaders(response)
44
- }
45
-
46
- // Check if user is a member of the team
47
- const isMember = await TeamMemberService.isMember(teamId, authResult.user!.id)
48
-
49
- if (!isMember) {
50
- const response = createApiError('Team not found or access denied', 404, null, 'TEAM_NOT_FOUND')
51
- return addCorsHeaders(response)
52
- }
53
-
54
- // Parse query parameters
55
- const { searchParams } = new URL(req.url)
56
- const page = parseInt(searchParams.get('page') || '1', 10)
57
- const limit = parseInt(searchParams.get('limit') || '50', 10)
58
- const status = searchParams.get('status') || 'pending'
59
- const offset = (page - 1) * limit
60
-
61
- // Fetch team invitations
62
- const invitations = await queryWithRLS<
63
- TeamInvitation & {
64
- inviterName: string | null
65
- inviterEmail: string
66
- }
67
- >(
68
- `SELECT
69
- ti.*,
70
- u.name as "inviterName",
71
- u.email as "inviterEmail"
72
- FROM "team_invitations" ti
73
- INNER JOIN "users" u ON ti."invitedBy" = u.id
74
- WHERE ti."teamId" = $1 AND ti.status = $2
75
- ORDER BY ti."createdAt" DESC
76
- LIMIT $3 OFFSET $4`,
77
- [teamId, status, limit, offset],
78
- authResult.user!.id
79
- )
80
-
81
- // Get total count for pagination
82
- const totalResult = await queryWithRLS<{ count: string }>(
83
- `SELECT COUNT(*) as count
84
- FROM "team_invitations" ti
85
- WHERE ti."teamId" = $1 AND ti.status = $2`,
86
- [teamId, status],
87
- authResult.user!.id
88
- )
89
-
90
- const total = parseInt(totalResult[0]?.count || '0', 10)
91
- const paginationMeta = createPaginationMeta(page, limit, total)
92
-
93
- const response = createApiResponse(invitations, paginationMeta)
94
- return addCorsHeaders(response)
95
- } catch (error) {
96
- console.error('Error fetching team invitations:', error)
97
- const response = createApiError('Internal server error', 500)
98
- return addCorsHeaders(response)
99
- }
100
- }
101
- )
102
-
103
- // DELETE /api/v1/teams/:teamId/invitations/:invitationId - Cancel/revoke an invitation
104
- export const DELETE = withApiLogging(
105
- async (req: NextRequest, { params }: { params: Promise<{ teamId: string }> }): Promise<NextResponse> => {
106
- try {
107
- // Authenticate using dual auth
108
- const authResult = await authenticateRequest(req)
109
-
110
- if (!authResult.success) {
111
- return NextResponse.json(
112
- { success: false, error: 'Authentication required', code: 'AUTHENTICATION_FAILED' },
113
- { status: 401 }
114
- )
115
- }
116
-
117
- if (authResult.rateLimitResponse) {
118
- return authResult.rateLimitResponse as NextResponse
119
- }
120
-
121
- const { teamId } = await params
122
-
123
- // Get invitation ID from URL
124
- const url = new URL(req.url)
125
- const invitationId = url.searchParams.get('id')
126
-
127
- if (!invitationId) {
128
- const response = createApiError('Invitation ID is required', 400, null, 'MISSING_INVITATION_ID')
129
- return addCorsHeaders(response)
130
- }
131
-
132
- // Check if user has permission to manage invitations using MembershipService
133
- const membership = await MembershipService.get(authResult.user!.id, teamId)
134
- const actionResult = membership.canPerformAction('members.invite')
135
-
136
- if (!actionResult.allowed) {
137
- const response = NextResponse.json(
138
- {
139
- success: false,
140
- error: actionResult.message,
141
- reason: actionResult.reason,
142
- meta: actionResult.meta,
143
- },
144
- { status: 403 }
145
- )
146
- return addCorsHeaders(response)
147
- }
148
-
149
- // Update invitation status to 'cancelled' (or delete it)
150
- const result = await mutateWithRLS(
151
- `DELETE FROM "team_invitations"
152
- WHERE id = $1 AND "teamId" = $2 AND status = 'pending'
153
- RETURNING *`,
154
- [invitationId, teamId],
155
- authResult.user!.id
156
- )
157
-
158
- if (result.rowCount === 0) {
159
- const response = createApiError('Invitation not found or already processed', 404, null, 'INVITATION_NOT_FOUND')
160
- return addCorsHeaders(response)
161
- }
162
-
163
- const response = createApiResponse({ deleted: true, id: invitationId })
164
- return addCorsHeaders(response)
165
- } catch (error) {
166
- console.error('Error cancelling invitation:', error)
167
- const response = createApiError('Internal server error', 500)
168
- return addCorsHeaders(response)
169
- }
170
- }
171
- )
@@ -1,105 +0,0 @@
1
- import { NextRequest, NextResponse } from 'next/server'
2
- import { queryWithRLS } from '@nextsparkjs/core/lib/db'
3
- import {
4
- createApiResponse,
5
- createApiError,
6
- withApiLogging,
7
- handleCorsPreflightRequest,
8
- addCorsHeaders,
9
- } from '@nextsparkjs/core/lib/api/helpers'
10
- import { authenticateRequest } from '@nextsparkjs/core/lib/api/auth/dual-auth'
11
- import { MembershipService } from '@nextsparkjs/core/lib/services'
12
- import type { InvoiceResponse } from '@nextsparkjs/core/lib/validation/invoices'
13
-
14
- // Handle CORS preflight
15
- export async function OPTIONS() {
16
- return handleCorsPreflightRequest()
17
- }
18
-
19
- // GET /api/v1/teams/:teamId/invoices/:invoiceNumber - Get single invoice (owner only)
20
- export const GET = withApiLogging(
21
- async (
22
- req: NextRequest,
23
- { params }: { params: Promise<{ teamId: string; invoiceNumber: string }> }
24
- ): Promise<NextResponse> => {
25
- try {
26
- // Authenticate using dual auth (API key OR session)
27
- const authResult = await authenticateRequest(req)
28
-
29
- if (!authResult.success) {
30
- return NextResponse.json(
31
- { success: false, error: 'Authentication required', code: 'AUTHENTICATION_FAILED' },
32
- { status: 401 }
33
- )
34
- }
35
-
36
- if (authResult.rateLimitResponse) {
37
- return authResult.rateLimitResponse as NextResponse
38
- }
39
-
40
- const { teamId, invoiceNumber } = await params
41
-
42
- // Validate that teamId is not empty
43
- if (!teamId || teamId.trim() === '') {
44
- const response = createApiError('Team ID is required', 400, null, 'MISSING_TEAM_ID')
45
- return addCorsHeaders(response)
46
- }
47
-
48
- // Validate that invoiceNumber is not empty
49
- if (!invoiceNumber || invoiceNumber.trim() === '') {
50
- const response = createApiError('Invoice number is required', 400, null, 'MISSING_INVOICE_NUMBER')
51
- return addCorsHeaders(response)
52
- }
53
-
54
- // Check if user has permission to view invoices using MembershipService
55
- const membership = await MembershipService.get(authResult.user!.id, teamId)
56
- const actionResult = membership.canPerformAction('billing.invoices')
57
-
58
- if (!actionResult.allowed) {
59
- const response = NextResponse.json(
60
- {
61
- success: false,
62
- error: actionResult.message,
63
- reason: actionResult.reason,
64
- meta: actionResult.meta,
65
- },
66
- { status: 403 }
67
- )
68
- return addCorsHeaders(response)
69
- }
70
-
71
- // Query single invoice by invoiceNumber
72
- const invoices = await queryWithRLS<InvoiceResponse>(
73
- `SELECT
74
- id,
75
- "teamId",
76
- "invoiceNumber",
77
- to_char(date, 'YYYY-MM-DD"T"HH24:MI:SS"Z"') as date,
78
- amount::NUMERIC(10,2)::FLOAT as amount,
79
- currency,
80
- status::TEXT as status,
81
- "pdfUrl",
82
- description,
83
- to_char("createdAt", 'YYYY-MM-DD"T"HH24:MI:SS"Z"') as "createdAt",
84
- to_char("updatedAt", 'YYYY-MM-DD"T"HH24:MI:SS"Z"') as "updatedAt"
85
- FROM "invoices"
86
- WHERE "teamId" = $1 AND "invoiceNumber" = $2
87
- LIMIT 1`,
88
- [teamId, decodeURIComponent(invoiceNumber)],
89
- authResult.user!.id
90
- )
91
-
92
- if (invoices.length === 0) {
93
- const response = createApiError('Invoice not found', 404, null, 'INVOICE_NOT_FOUND')
94
- return addCorsHeaders(response)
95
- }
96
-
97
- const response = createApiResponse(invoices[0])
98
- return addCorsHeaders(response)
99
- } catch (error) {
100
- console.error('Error fetching invoice:', error)
101
- const response = createApiError('Internal server error', 500)
102
- return addCorsHeaders(response)
103
- }
104
- }
105
- )
@@ -1,125 +0,0 @@
1
- import { NextRequest, NextResponse } from 'next/server'
2
- import { queryWithRLS } from '@nextsparkjs/core/lib/db'
3
- import {
4
- createApiResponse,
5
- createApiError,
6
- createPaginationMeta,
7
- withApiLogging,
8
- handleCorsPreflightRequest,
9
- addCorsHeaders,
10
- } from '@nextsparkjs/core/lib/api/helpers'
11
- import { authenticateRequest } from '@nextsparkjs/core/lib/api/auth/dual-auth'
12
- import { MembershipService } from '@nextsparkjs/core/lib/services'
13
- import { invoiceQuerySchema } from '@nextsparkjs/core/lib/validation/invoices'
14
- import type { InvoiceResponse } from '@nextsparkjs/core/lib/validation/invoices'
15
-
16
- // Handle CORS preflight
17
- export async function OPTIONS() {
18
- return handleCorsPreflightRequest()
19
- }
20
-
21
- // GET /api/v1/teams/:teamId/invoices - List team invoices (owner only)
22
- export const GET = withApiLogging(
23
- async (req: NextRequest, { params }: { params: Promise<{ teamId: string }> }): Promise<NextResponse> => {
24
- try {
25
- // Authenticate using dual auth (API key OR session)
26
- const authResult = await authenticateRequest(req)
27
-
28
- if (!authResult.success) {
29
- return NextResponse.json(
30
- { success: false, error: 'Authentication required', code: 'AUTHENTICATION_FAILED' },
31
- { status: 401 }
32
- )
33
- }
34
-
35
- if (authResult.rateLimitResponse) {
36
- return authResult.rateLimitResponse as NextResponse
37
- }
38
-
39
- const { teamId } = await params
40
-
41
- // Validate that teamId is not empty
42
- if (!teamId || teamId.trim() === '') {
43
- const response = createApiError('Team ID is required', 400, null, 'MISSING_TEAM_ID')
44
- return addCorsHeaders(response)
45
- }
46
-
47
- // Check if user has permission to view invoices using MembershipService
48
- const membership = await MembershipService.get(authResult.user!.id, teamId)
49
- const actionResult = membership.canPerformAction('billing.invoices')
50
-
51
- if (!actionResult.allowed) {
52
- const response = NextResponse.json(
53
- {
54
- success: false,
55
- error: actionResult.message,
56
- reason: actionResult.reason,
57
- meta: actionResult.meta,
58
- },
59
- { status: 403 }
60
- )
61
- return addCorsHeaders(response)
62
- }
63
-
64
- // Parse query parameters for pagination
65
- const { searchParams } = new URL(req.url)
66
- const queryParams = Object.fromEntries(
67
- Object.entries({
68
- limit: searchParams.get('limit'),
69
- offset: searchParams.get('offset'),
70
- }).filter(([, value]) => value !== null && value !== '')
71
- )
72
-
73
- const validatedQuery = invoiceQuerySchema.parse(queryParams)
74
- const { limit, offset } = validatedQuery
75
-
76
- // Query invoices with pagination (ordered by date DESC)
77
- const invoices = await queryWithRLS<InvoiceResponse>(
78
- `SELECT
79
- id,
80
- "teamId",
81
- "invoiceNumber",
82
- to_char(date, 'YYYY-MM-DD"T"HH24:MI:SS"Z"') as date,
83
- amount::NUMERIC(10,2)::FLOAT as amount,
84
- currency,
85
- status::TEXT as status,
86
- "pdfUrl",
87
- description,
88
- to_char("createdAt", 'YYYY-MM-DD"T"HH24:MI:SS"Z"') as "createdAt",
89
- to_char("updatedAt", 'YYYY-MM-DD"T"HH24:MI:SS"Z"') as "updatedAt"
90
- FROM "invoices"
91
- WHERE "teamId" = $1
92
- ORDER BY date DESC
93
- LIMIT $2 OFFSET $3`,
94
- [teamId, limit, offset],
95
- authResult.user!.id
96
- )
97
-
98
- // Get total count for pagination
99
- const totalResult = await queryWithRLS<{ count: string }>(
100
- `SELECT COUNT(*) as count FROM "invoices" WHERE "teamId" = $1`,
101
- [teamId],
102
- authResult.user!.id
103
- )
104
-
105
- const total = parseInt(totalResult[0]?.count || '0', 10)
106
-
107
- // Calculate pagination metadata
108
- const page = Math.floor(offset / limit) + 1
109
- const paginationMeta = createPaginationMeta(page, limit, total)
110
-
111
- const response = createApiResponse(invoices, paginationMeta)
112
- return addCorsHeaders(response)
113
- } catch (error) {
114
- if (error instanceof Error && error.name === 'ZodError') {
115
- const zodError = error as { issues?: unknown[] }
116
- const response = createApiError('Validation error', 400, zodError.issues, 'VALIDATION_ERROR')
117
- return addCorsHeaders(response)
118
- }
119
-
120
- console.error('Error fetching invoices:', error)
121
- const response = createApiError('Internal server error', 500)
122
- return addCorsHeaders(response)
123
- }
124
- }
125
- )
@@ -1,263 +0,0 @@
1
- import { NextRequest, NextResponse } from 'next/server'
2
- import { queryOneWithRLS, mutateWithRLS } from '@nextsparkjs/core/lib/db'
3
- import {
4
- createApiResponse,
5
- createApiError,
6
- withApiLogging,
7
- handleCorsPreflightRequest,
8
- addCorsHeaders,
9
- } from '@nextsparkjs/core/lib/api/helpers'
10
- import { authenticateRequest } from '@nextsparkjs/core/lib/api/auth/dual-auth'
11
- import { updateMemberRoleSchema } from '@nextsparkjs/core/lib/teams/schema'
12
- import { MembershipService } from '@nextsparkjs/core/lib/services'
13
- import { validateRoleTransition, canManageRole } from '@nextsparkjs/core/lib/teams/permissions'
14
- import type { TeamMember, TeamRole } from '@nextsparkjs/core/lib/teams/types'
15
-
16
- // Handle CORS preflight
17
- export async function OPTIONS() {
18
- return handleCorsPreflightRequest()
19
- }
20
-
21
- // PATCH /api/v1/teams/:teamId/members/:memberId - Update member role
22
- export const PATCH = withApiLogging(
23
- async (
24
- req: NextRequest,
25
- { params }: { params: Promise<{ teamId: string; memberId: string }> }
26
- ): Promise<NextResponse> => {
27
- try {
28
- // Authenticate using dual auth
29
- const authResult = await authenticateRequest(req)
30
-
31
- if (!authResult.success) {
32
- return NextResponse.json(
33
- { success: false, error: 'Authentication required', code: 'AUTHENTICATION_FAILED' },
34
- { status: 401 }
35
- )
36
- }
37
-
38
- if (authResult.rateLimitResponse) {
39
- return authResult.rateLimitResponse as NextResponse
40
- }
41
-
42
- const { teamId, memberId } = await params
43
-
44
- // Validate parameters
45
- if (!teamId || teamId.trim() === '') {
46
- const response = createApiError('Team ID is required', 400, null, 'MISSING_TEAM_ID')
47
- return addCorsHeaders(response)
48
- }
49
-
50
- if (!memberId || memberId.trim() === '') {
51
- const response = createApiError('Member ID is required', 400, null, 'MISSING_MEMBER_ID')
52
- return addCorsHeaders(response)
53
- }
54
-
55
- // Check if user has permission to update member roles using MembershipService
56
- const membership = await MembershipService.get(authResult.user!.id, teamId)
57
- const actionResult = membership.canPerformAction('members.update_role')
58
-
59
- if (!actionResult.allowed) {
60
- const response = NextResponse.json(
61
- {
62
- success: false,
63
- error: actionResult.message,
64
- reason: actionResult.reason,
65
- meta: actionResult.meta,
66
- },
67
- { status: 403 }
68
- )
69
- return addCorsHeaders(response)
70
- }
71
-
72
- // Get user's role for role hierarchy validation
73
- const userRole = membership.role as TeamRole
74
-
75
- // Get target member
76
- const targetMember = await queryOneWithRLS<TeamMember>(
77
- 'SELECT * FROM "team_members" WHERE id = $1 AND "teamId" = $2',
78
- [memberId, teamId],
79
- authResult.user!.id
80
- )
81
-
82
- if (!targetMember) {
83
- const response = createApiError('Member not found', 404, null, 'MEMBER_NOT_FOUND')
84
- return addCorsHeaders(response)
85
- }
86
-
87
- const body = await req.json()
88
- const validatedData = updateMemberRoleSchema.parse(body)
89
-
90
- // Validate role transition
91
- const transitionValidation = validateRoleTransition(targetMember.role, validatedData.role, userRole)
92
-
93
- if (!transitionValidation.allowed) {
94
- const response = createApiError(transitionValidation.reason || 'Invalid role transition', 403, null, 'INVALID_ROLE_TRANSITION')
95
- return addCorsHeaders(response)
96
- }
97
-
98
- // Check if actor can manage the target role
99
- if (!canManageRole(userRole, targetMember.role)) {
100
- const response = createApiError(
101
- 'You do not have permission to change this user\'s role.',
102
- 403,
103
- null,
104
- 'INSUFFICIENT_PERMISSIONS'
105
- )
106
- return addCorsHeaders(response)
107
- }
108
-
109
- // Update member role
110
- const result = await mutateWithRLS(
111
- `UPDATE "team_members"
112
- SET role = $1, "updatedAt" = CURRENT_TIMESTAMP
113
- WHERE id = $2 AND "teamId" = $3
114
- RETURNING *`,
115
- [validatedData.role, memberId, teamId],
116
- authResult.user!.id
117
- )
118
-
119
- if (result.rows.length === 0) {
120
- const response = createApiError('Member not found', 404, null, 'MEMBER_NOT_FOUND')
121
- return addCorsHeaders(response)
122
- }
123
-
124
- // Fetch member with user details
125
- const memberWithUser = await queryOneWithRLS<
126
- TeamMember & {
127
- userName: string | null
128
- userEmail: string
129
- userImage: string | null
130
- }
131
- >(
132
- `SELECT
133
- tm.*,
134
- u.name as "userName",
135
- u.email as "userEmail",
136
- u.image as "userImage"
137
- FROM "team_members" tm
138
- INNER JOIN "users" u ON tm."userId" = u.id
139
- WHERE tm.id = $1`,
140
- [memberId],
141
- authResult.user!.id
142
- )
143
-
144
- const response = createApiResponse(memberWithUser)
145
- return addCorsHeaders(response)
146
- } catch (error) {
147
- if (error instanceof Error && error.name === 'ZodError') {
148
- const zodError = error as { issues?: unknown[] }
149
- const response = createApiError('Validation error', 400, zodError.issues, 'VALIDATION_ERROR')
150
- return addCorsHeaders(response)
151
- }
152
-
153
- console.error('Error updating member role:', error)
154
- const response = createApiError('Internal server error', 500)
155
- return addCorsHeaders(response)
156
- }
157
- }
158
- )
159
-
160
- // DELETE /api/v1/teams/:teamId/members/:memberId - Remove member from team
161
- export const DELETE = withApiLogging(
162
- async (
163
- req: NextRequest,
164
- { params }: { params: Promise<{ teamId: string; memberId: string }> }
165
- ): Promise<NextResponse> => {
166
- try {
167
- // Authenticate using dual auth
168
- const authResult = await authenticateRequest(req)
169
-
170
- if (!authResult.success) {
171
- return NextResponse.json(
172
- { success: false, error: 'Authentication required', code: 'AUTHENTICATION_FAILED' },
173
- { status: 401 }
174
- )
175
- }
176
-
177
- if (authResult.rateLimitResponse) {
178
- return authResult.rateLimitResponse as NextResponse
179
- }
180
-
181
- const { teamId, memberId } = await params
182
-
183
- // Validate parameters
184
- if (!teamId || teamId.trim() === '') {
185
- const response = createApiError('Team ID is required', 400, null, 'MISSING_TEAM_ID')
186
- return addCorsHeaders(response)
187
- }
188
-
189
- if (!memberId || memberId.trim() === '') {
190
- const response = createApiError('Member ID is required', 400, null, 'MISSING_MEMBER_ID')
191
- return addCorsHeaders(response)
192
- }
193
-
194
- // Check if user has permission to remove members using MembershipService
195
- const membership = await MembershipService.get(authResult.user!.id, teamId)
196
- const actionResult = membership.canPerformAction('members.remove')
197
-
198
- if (!actionResult.allowed) {
199
- const response = NextResponse.json(
200
- {
201
- success: false,
202
- error: actionResult.message,
203
- reason: actionResult.reason,
204
- meta: actionResult.meta,
205
- },
206
- { status: 403 }
207
- )
208
- return addCorsHeaders(response)
209
- }
210
-
211
- // Get user's role for role hierarchy validation
212
- const userRole = membership.role as TeamRole
213
-
214
- // Get target member
215
- const targetMember = await queryOneWithRLS<TeamMember>(
216
- 'SELECT * FROM "team_members" WHERE id = $1 AND "teamId" = $2',
217
- [memberId, teamId],
218
- authResult.user!.id
219
- )
220
-
221
- if (!targetMember) {
222
- const response = createApiError('Member not found', 404, null, 'MEMBER_NOT_FOUND')
223
- return addCorsHeaders(response)
224
- }
225
-
226
- // Cannot remove the owner
227
- if (targetMember.role === 'owner') {
228
- const response = createApiError('Cannot remove the team owner', 403, null, 'CANNOT_REMOVE_OWNER')
229
- return addCorsHeaders(response)
230
- }
231
-
232
- // Check if actor can manage the target role
233
- if (!canManageRole(userRole, targetMember.role)) {
234
- const response = createApiError(
235
- 'You do not have permission to remove this user.',
236
- 403,
237
- null,
238
- 'INSUFFICIENT_PERMISSIONS'
239
- )
240
- return addCorsHeaders(response)
241
- }
242
-
243
- // Remove member
244
- const result = await mutateWithRLS(
245
- 'DELETE FROM "team_members" WHERE id = $1 AND "teamId" = $2 RETURNING id',
246
- [memberId, teamId],
247
- authResult.user!.id
248
- )
249
-
250
- if (result.rows.length === 0) {
251
- const response = createApiError('Member not found', 404, null, 'MEMBER_NOT_FOUND')
252
- return addCorsHeaders(response)
253
- }
254
-
255
- const response = createApiResponse({ deleted: true, id: memberId })
256
- return addCorsHeaders(response)
257
- } catch (error) {
258
- console.error('Error removing member:', error)
259
- const response = createApiError('Internal server error', 500)
260
- return addCorsHeaders(response)
261
- }
262
- }
263
- )