@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,97 +0,0 @@
1
- /**
2
- * Change Plan Endpoint
3
- *
4
- * Allows users to upgrade or downgrade their subscription plan.
5
- * Handles proration via Stripe automatically.
6
- *
7
- * P1-3: Plan Change con Proration
8
- */
9
-
10
- import { NextRequest } from 'next/server'
11
- import { z } from 'zod'
12
- import { authenticateRequest, createAuthError } from '@nextsparkjs/core/lib/api/auth/dual-auth'
13
- import { SubscriptionService, MembershipService } from '@nextsparkjs/core/lib/services'
14
-
15
- const changePlanSchema = z.object({
16
- planSlug: z.string().min(1, 'Plan slug is required'),
17
- billingInterval: z.enum(['monthly', 'yearly']).default('monthly'),
18
- })
19
-
20
- /**
21
- * POST /api/v1/billing/change-plan
22
- * Change the team's subscription plan (upgrade or downgrade)
23
- *
24
- * Body:
25
- * - planSlug: string - Target plan slug
26
- * - billingInterval: 'monthly' | 'yearly' (default: monthly)
27
- */
28
- export async function POST(request: NextRequest) {
29
- // 1. Dual authentication
30
- const authResult = await authenticateRequest(request)
31
-
32
- if (!authResult.success || !authResult.user) {
33
- return createAuthError('Unauthorized', 401)
34
- }
35
-
36
- // 2. Get team context
37
- const teamId = request.headers.get('x-team-id') || authResult.user.defaultTeamId
38
-
39
- if (!teamId) {
40
- return Response.json(
41
- {
42
- success: false,
43
- error: 'No team context available. Please provide x-team-id header.',
44
- },
45
- { status: 400 }
46
- )
47
- }
48
-
49
- // 3. Permission check using MembershipService
50
- const membership = await MembershipService.get(authResult.user.id, teamId)
51
- const actionResult = membership.canPerformAction('billing.change-plan')
52
-
53
- if (!actionResult.allowed) {
54
- return Response.json(
55
- {
56
- success: false,
57
- error: actionResult.message,
58
- reason: actionResult.reason,
59
- meta: actionResult.meta,
60
- },
61
- { status: 403 }
62
- )
63
- }
64
-
65
- // 4. Parse and validate request body
66
- let body: Record<string, unknown>
67
- try {
68
- body = await request.json()
69
- } catch {
70
- return Response.json({ success: false, error: 'Invalid JSON body' }, { status: 400 })
71
- }
72
-
73
- const parseResult = changePlanSchema.safeParse(body)
74
- if (!parseResult.success) {
75
- return Response.json(
76
- { success: false, error: 'Invalid request body', details: parseResult.error.issues },
77
- { status: 400 }
78
- )
79
- }
80
-
81
- const { planSlug, billingInterval } = parseResult.data
82
-
83
- // 5. Execute plan change
84
- const result = await SubscriptionService.changePlan(teamId, planSlug, billingInterval)
85
-
86
- if (!result.success) {
87
- return Response.json({ success: false, error: result.error }, { status: 400 })
88
- }
89
-
90
- return Response.json({
91
- success: true,
92
- data: {
93
- subscription: result.subscription,
94
- warnings: result.downgradeWarnings,
95
- },
96
- })
97
- }
@@ -1,81 +0,0 @@
1
- /**
2
- * Check Action Endpoint
3
- *
4
- * Verifies if a user can perform a specific action by checking:
5
- * 1. RBAC permissions (role-based access control)
6
- * 2. Plan features (subscription-based access)
7
- * 3. Quota limits (usage-based access)
8
- *
9
- * FIX1: This endpoint was missing, causing useMembership.canDo() to fail
10
- */
11
-
12
- import { NextRequest } from 'next/server'
13
- import { authenticateRequest, createAuthError } from '@nextsparkjs/core/lib/api/auth/dual-auth'
14
- import { MembershipService } from '@nextsparkjs/core/lib/services'
15
- import { z } from 'zod'
16
-
17
- const checkActionSchema = z.object({
18
- action: z.string().min(1, 'Action is required'),
19
- teamId: z.string().uuid().optional()
20
- })
21
-
22
- export async function POST(request: NextRequest) {
23
- // 1. Dual authentication (API Key OR Session)
24
- const authResult = await authenticateRequest(request)
25
-
26
- if (!authResult.success || !authResult.user) {
27
- return createAuthError('Unauthorized', 401)
28
- }
29
-
30
- // 2. Parse and validate request body
31
- let body
32
- try {
33
- body = await request.json()
34
- } catch {
35
- return Response.json(
36
- { success: false, error: 'Invalid JSON body' },
37
- { status: 400 }
38
- )
39
- }
40
-
41
- const parseResult = checkActionSchema.safeParse(body)
42
- if (!parseResult.success) {
43
- return Response.json(
44
- {
45
- success: false,
46
- error: 'Validation failed',
47
- details: parseResult.error.issues
48
- },
49
- { status: 400 }
50
- )
51
- }
52
-
53
- const { action, teamId: bodyTeamId } = parseResult.data
54
-
55
- // 3. Get team context (from body, header, or user's default)
56
- const teamId =
57
- bodyTeamId ||
58
- request.headers.get('x-team-id') ||
59
- authResult.user.defaultTeamId
60
-
61
- if (!teamId) {
62
- return Response.json(
63
- {
64
- success: false,
65
- error: 'No team context available. Please provide teamId in body or x-team-id header.'
66
- },
67
- { status: 400 }
68
- )
69
- }
70
-
71
- // 4. Check action permission using MembershipService
72
- // Note: MembershipService.get() does NOT throw for non-members
73
- // It returns TeamMembership with role: null
74
- const membership = await MembershipService.get(authResult.user.id, teamId)
75
- const result = membership.canPerformAction(action)
76
-
77
- return Response.json({
78
- success: true,
79
- data: result
80
- })
81
- }
@@ -1,124 +0,0 @@
1
- /**
2
- * Stripe Checkout Endpoint
3
- *
4
- * Creates a Stripe Checkout session for subscription upgrade.
5
- * Redirects user to Stripe-hosted checkout page.
6
- *
7
- * Security: Requires team owner/admin permission (team.billing.manage)
8
- *
9
- * P2: Stripe Integration
10
- */
11
-
12
- import { NextRequest } from 'next/server'
13
- import { authenticateRequest, createAuthError } from '@nextsparkjs/core/lib/api/auth/dual-auth'
14
- import { createCheckoutSession } from '@nextsparkjs/core/lib/billing/gateways/stripe'
15
- import { SubscriptionService, MembershipService } from '@nextsparkjs/core/lib/services'
16
- import { z } from 'zod'
17
-
18
- const checkoutSchema = z.object({
19
- planSlug: z.string().min(1, 'Plan slug is required'),
20
- billingPeriod: z.enum(['monthly', 'yearly']).default('monthly')
21
- })
22
-
23
- export async function POST(request: NextRequest) {
24
- // 1. Dual authentication
25
- const authResult = await authenticateRequest(request)
26
-
27
- if (!authResult.success || !authResult.user) {
28
- return createAuthError('Unauthorized', 401)
29
- }
30
-
31
- // 2. Parse and validate request body
32
- let body
33
- try {
34
- body = await request.json()
35
- } catch {
36
- return Response.json(
37
- { success: false, error: 'Invalid JSON body' },
38
- { status: 400 }
39
- )
40
- }
41
-
42
- const parseResult = checkoutSchema.safeParse(body)
43
- if (!parseResult.success) {
44
- return Response.json(
45
- {
46
- success: false,
47
- error: 'Validation failed',
48
- details: parseResult.error.issues
49
- },
50
- { status: 400 }
51
- )
52
- }
53
-
54
- const { planSlug, billingPeriod } = parseResult.data
55
-
56
- // 3. Get team context
57
- const teamId =
58
- request.headers.get('x-team-id') ||
59
- authResult.user.defaultTeamId
60
-
61
- if (!teamId) {
62
- return Response.json(
63
- {
64
- success: false,
65
- error: 'No team context available. Please provide x-team-id header.'
66
- },
67
- { status: 400 }
68
- )
69
- }
70
-
71
- // 4. Permission check using MembershipService
72
- const membership = await MembershipService.get(authResult.user.id, teamId)
73
- const actionResult = membership.canPerformAction('billing.checkout')
74
-
75
- if (!actionResult.allowed) {
76
- return Response.json(
77
- {
78
- success: false,
79
- error: actionResult.message,
80
- reason: actionResult.reason,
81
- meta: actionResult.meta,
82
- },
83
- { status: 403 }
84
- )
85
- }
86
-
87
- // 5. Check existing subscription for customer ID
88
- try {
89
- const subscription = await SubscriptionService.getActive(teamId)
90
-
91
- // Build URLs
92
- const appUrl = process.env.NEXT_PUBLIC_APP_URL || 'http://localhost:5173'
93
- const successUrl = `${appUrl}/dashboard/settings/billing?success=true`
94
- const cancelUrl = `${appUrl}/dashboard/settings/billing?canceled=true`
95
-
96
- // Create Stripe Checkout session
97
- const session = await createCheckoutSession({
98
- teamId,
99
- planSlug,
100
- billingPeriod,
101
- successUrl,
102
- cancelUrl,
103
- customerEmail: authResult.user.email,
104
- customerId: subscription?.externalCustomerId || undefined
105
- })
106
-
107
- return Response.json({
108
- success: true,
109
- data: {
110
- url: session.url,
111
- sessionId: session.id
112
- }
113
- })
114
- } catch (error) {
115
- console.error('[checkout] Error creating checkout session:', error)
116
- return Response.json(
117
- {
118
- success: false,
119
- error: error instanceof Error ? error.message : 'Failed to create checkout session'
120
- },
121
- { status: 500 }
122
- )
123
- }
124
- }
@@ -1,209 +0,0 @@
1
- # Billing API
2
-
3
- Manage subscriptions, plans, and billing operations for teams.
4
-
5
- ## Overview
6
-
7
- The Billing API integrates with Stripe to handle subscription management, checkout sessions, plan changes, and customer portal access. All billing operations are scoped to teams.
8
-
9
- ## Authentication
10
-
11
- All endpoints require authentication via:
12
- - **Session cookie** (for browser-based requests)
13
- - **API Key** header (for server-to-server requests)
14
-
15
- The `x-team-id` header or user's default team is used for team context.
16
-
17
- ## Endpoints
18
-
19
- ### List Plans
20
- `GET /api/v1/billing/plans`
21
-
22
- Returns available subscription plans. Public plans visible to all, hidden plans only to superadmin.
23
-
24
- **Example Response:**
25
- ```json
26
- {
27
- "data": [
28
- {
29
- "id": "plan_123",
30
- "slug": "pro",
31
- "name": "Pro Plan",
32
- "description": "For growing teams",
33
- "priceMonthly": 29,
34
- "priceYearly": 290,
35
- "currency": "USD",
36
- "features": ["unlimited_projects", "api_access"],
37
- "limits": {
38
- "team_members": 10,
39
- "storage_gb": 100
40
- }
41
- }
42
- ]
43
- }
44
- ```
45
-
46
- ### Create Checkout Session
47
- `POST /api/v1/billing/checkout`
48
-
49
- Creates a Stripe Checkout session for subscription upgrade. Returns a URL to redirect the user.
50
-
51
- **Required Permission:** `billing.checkout` (team owner/admin)
52
-
53
- **Request Body:**
54
- ```json
55
- {
56
- "planSlug": "pro",
57
- "billingPeriod": "monthly"
58
- }
59
- ```
60
-
61
- **Parameters:**
62
- - `planSlug` (string, required): The plan to subscribe to
63
- - `billingPeriod` (string): "monthly" or "yearly" (default: "monthly")
64
-
65
- **Response:**
66
- ```json
67
- {
68
- "success": true,
69
- "data": {
70
- "url": "https://checkout.stripe.com/...",
71
- "sessionId": "cs_live_..."
72
- }
73
- }
74
- ```
75
-
76
- ### Open Customer Portal
77
- `GET /api/v1/billing/portal`
78
-
79
- Creates a Stripe Customer Portal session for managing payment methods and viewing invoices.
80
-
81
- **Required Permission:** `billing.portal` (team owner/admin)
82
-
83
- **Response:**
84
- ```json
85
- {
86
- "success": true,
87
- "data": {
88
- "url": "https://billing.stripe.com/..."
89
- }
90
- }
91
- ```
92
-
93
- ### Change Plan
94
- `POST /api/v1/billing/change-plan`
95
-
96
- Change the current subscription to a different plan.
97
-
98
- **Required Permission:** `billing.change_plan` (team owner/admin)
99
-
100
- **Request Body:**
101
- ```json
102
- {
103
- "planSlug": "enterprise",
104
- "billingPeriod": "yearly"
105
- }
106
- ```
107
-
108
- ### Cancel Subscription
109
- `POST /api/v1/billing/cancel`
110
-
111
- Cancel the current subscription. Cancellation takes effect at the end of the billing period.
112
-
113
- **Required Permission:** `billing.cancel` (team owner/admin)
114
-
115
- **Response:**
116
- ```json
117
- {
118
- "success": true,
119
- "data": {
120
- "canceledAt": "2024-02-01T00:00:00Z",
121
- "effectiveDate": "2024-02-28T23:59:59Z"
122
- }
123
- }
124
- ```
125
-
126
- ### Check Action Permission
127
- `POST /api/v1/billing/check-action`
128
-
129
- Verify if the current user can perform a specific action based on RBAC, plan features, and quotas.
130
-
131
- **Request Body:**
132
- ```json
133
- {
134
- "action": "team.invite_member",
135
- "teamId": "team_123"
136
- }
137
- ```
138
-
139
- **Response:**
140
- ```json
141
- {
142
- "success": true,
143
- "data": {
144
- "allowed": true,
145
- "reason": null
146
- }
147
- }
148
- ```
149
-
150
- Or if not allowed:
151
- ```json
152
- {
153
- "success": true,
154
- "data": {
155
- "allowed": false,
156
- "reason": "quota_exceeded",
157
- "message": "Team member limit reached",
158
- "meta": {
159
- "limit": 5,
160
- "current": 5
161
- }
162
- }
163
- }
164
- ```
165
-
166
- ### Stripe Webhook
167
- `POST /api/v1/billing/webhooks/stripe`
168
-
169
- Handles Stripe webhook events for subscription lifecycle management.
170
-
171
- **Note:** This endpoint is called by Stripe, not by your application. It requires Stripe signature verification.
172
-
173
- **Handled Events:**
174
- - `checkout.session.completed` - New subscription created
175
- - `customer.subscription.updated` - Plan changed
176
- - `customer.subscription.deleted` - Subscription canceled
177
- - `invoice.paid` - Payment successful
178
- - `invoice.payment_failed` - Payment failed
179
-
180
- ## Error Responses
181
-
182
- | Status | Description |
183
- |--------|-------------|
184
- | 400 | Bad Request - Invalid parameters or missing required fields |
185
- | 401 | Unauthorized - Authentication required |
186
- | 403 | Forbidden - Insufficient permissions or plan doesn't allow action |
187
- | 404 | Not Found - Plan or subscription not found |
188
- | 500 | Server Error - Stripe API error or internal error |
189
-
190
- ## Billing Period Proration
191
-
192
- When changing plans mid-cycle:
193
- - **Upgrade:** Prorated charge for the difference
194
- - **Downgrade:** Credit applied to next invoice
195
- - **Same price:** No proration
196
-
197
- ## Test Mode
198
-
199
- In development, Stripe test mode is used. Test card numbers:
200
- - Success: `4242 4242 4242 4242`
201
- - Decline: `4000 0000 0000 0002`
202
- - 3D Secure: `4000 0025 0000 3155`
203
-
204
- ## Related APIs
205
-
206
- - **[Teams](/api/v1/teams)** - Team subscription and usage endpoints
207
- - **[Teams Subscription](/api/v1/teams/{teamId}/subscription)** - View team's current subscription
208
- - **[Teams Usage](/api/v1/teams/{teamId}/usage/{limit})** - Check quota usage
209
- - **[Teams Invoices](/api/v1/teams/{teamId}/invoices)** - View billing invoices
@@ -1,85 +0,0 @@
1
- /**
2
- * Plans API - Billing system
3
- *
4
- * GET /api/v1/billing/plans - List all plans (public can see public plans)
5
- * POST /api/v1/billing/plans - Create a plan (superadmin only)
6
- */
7
-
8
- import { NextRequest } from 'next/server'
9
- import { validateAndAuthenticateRequest, createApiResponse, createApiError } from '@nextsparkjs/core/lib/api/helpers'
10
- import { PlanService } from '@nextsparkjs/core/lib/services'
11
- import { createPlanSchema } from '@nextsparkjs/core/lib/billing/schema'
12
- import { mutateWithRLS } from '@nextsparkjs/core/lib/db'
13
-
14
- export async function GET(request: NextRequest) {
15
- // Plans list is partially public (public plans visible to all, hidden plans only to superadmin)
16
- let includeHidden = false
17
-
18
- try {
19
- const { auth } = await validateAndAuthenticateRequest(request)
20
- // Check if user is superadmin (for full access including hidden plans)
21
- includeHidden = auth.scopes.includes('*') || auth.scopes.includes('superadmin:all')
22
- } catch {
23
- // Not authenticated, only show public plans
24
- includeHidden = false
25
- }
26
-
27
- try {
28
- const plans = await PlanService.list({ includeHidden })
29
- return createApiResponse(plans)
30
- } catch (error) {
31
- console.error('[Billing API] Error fetching plans:', error)
32
- return createApiError('Failed to fetch plans', 500)
33
- }
34
- }
35
-
36
- export async function POST(request: NextRequest) {
37
- // Authenticate request
38
- const { auth, rateLimitResponse } = await validateAndAuthenticateRequest(request)
39
- if (rateLimitResponse) return rateLimitResponse
40
-
41
- // Check superadmin permission
42
- if (!auth.scopes.includes('*') && !auth.scopes.includes('superadmin:all')) {
43
- return createApiError('Only superadmin can create plans', 403)
44
- }
45
-
46
- try {
47
- const body = await request.json()
48
- const data = createPlanSchema.parse(body)
49
-
50
- const { rows } = await mutateWithRLS(
51
- `
52
- INSERT INTO plans (
53
- slug, name, description, type, visibility,
54
- "priceMonthly", "priceYearly", currency, "trialDays",
55
- features, limits, metadata, "sortOrder"
56
- ) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13)
57
- RETURNING *
58
- `,
59
- [
60
- data.slug,
61
- data.name,
62
- data.description,
63
- data.type,
64
- data.visibility,
65
- data.priceMonthly,
66
- data.priceYearly,
67
- data.currency,
68
- data.trialDays,
69
- JSON.stringify(data.features),
70
- JSON.stringify(data.limits),
71
- JSON.stringify(data.metadata),
72
- data.sortOrder,
73
- ]
74
- )
75
-
76
- return createApiResponse(rows[0], { created: true }, 201)
77
- } catch (error: unknown) {
78
- const errorMessage = error instanceof Error ? error.message : ''
79
- if (errorMessage.includes('duplicate') || errorMessage.includes('unique')) {
80
- return createApiError('Plan slug already exists', 400)
81
- }
82
- console.error('[Billing API] Error creating plan:', error)
83
- return createApiError('Failed to create plan', 500)
84
- }
85
- }
@@ -1,90 +0,0 @@
1
- /**
2
- * Stripe Customer Portal Endpoint
3
- *
4
- * Creates a Stripe Customer Portal session for self-service billing management.
5
- * Users can update payment methods, view invoices, and cancel subscriptions.
6
- *
7
- * P6: Customer Portal
8
- */
9
-
10
- import { NextRequest } from 'next/server'
11
- import { authenticateRequest, createAuthError } from '@nextsparkjs/core/lib/api/auth/dual-auth'
12
- import { createPortalSession } from '@nextsparkjs/core/lib/billing/gateways/stripe'
13
- import { SubscriptionService, MembershipService } from '@nextsparkjs/core/lib/services'
14
-
15
- export async function POST(request: NextRequest) {
16
- // 1. Dual authentication
17
- const authResult = await authenticateRequest(request)
18
-
19
- if (!authResult.success || !authResult.user) {
20
- return createAuthError('Unauthorized', 401)
21
- }
22
-
23
- // 2. Get team context
24
- const teamId =
25
- request.headers.get('x-team-id') ||
26
- authResult.user.defaultTeamId
27
-
28
- if (!teamId) {
29
- return Response.json(
30
- {
31
- success: false,
32
- error: 'No team context available. Please provide x-team-id header.'
33
- },
34
- { status: 400 }
35
- )
36
- }
37
-
38
- // 3. Permission check using MembershipService
39
- const membership = await MembershipService.get(authResult.user.id, teamId)
40
- const actionResult = membership.canPerformAction('billing.portal')
41
-
42
- if (!actionResult.allowed) {
43
- return Response.json(
44
- {
45
- success: false,
46
- error: actionResult.message,
47
- reason: actionResult.reason,
48
- meta: actionResult.meta,
49
- },
50
- { status: 403 }
51
- )
52
- }
53
-
54
- // 4. Get subscription with Stripe customer ID
55
- try {
56
- const subscription = await SubscriptionService.getActive(teamId)
57
-
58
- if (!subscription?.externalCustomerId) {
59
- return Response.json(
60
- {
61
- success: false,
62
- error: 'No billing account found. Please upgrade to a paid plan first.'
63
- },
64
- { status: 400 }
65
- )
66
- }
67
-
68
- const appUrl = process.env.NEXT_PUBLIC_APP_URL || 'http://localhost:5173'
69
- const returnUrl = `${appUrl}/dashboard/settings/billing`
70
-
71
- const session = await createPortalSession({
72
- customerId: subscription.externalCustomerId,
73
- returnUrl
74
- })
75
-
76
- return Response.json({
77
- success: true,
78
- data: { url: session.url }
79
- })
80
- } catch (error) {
81
- console.error('[portal] Error creating portal session:', error)
82
- return Response.json(
83
- {
84
- success: false,
85
- error: error instanceof Error ? error.message : 'Failed to create portal session'
86
- },
87
- { status: 500 }
88
- )
89
- }
90
- }